Merge branch 'master' into staging
[jackhill/guix/guix.git] / gnu / packages / javascript.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Arun Isaac <arunisaac@systemreboot.net>
3 ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
4 ;;; Copyright © 2017, 2018 Tobias Geerinckx-Rice <me@tobias.gr>
5 ;;; Copyright © 2017, 2018 Efraim Flashner <efraim@flashner.co.il>
6 ;;; Copyright © 2018 Nicolas Goaziou <mail@nicolasgoaziou.fr>
7 ;;;
8 ;;; This file is part of GNU Guix.
9 ;;;
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
14 ;;;
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23 (define-module (gnu packages javascript)
24 #:use-module ((guix licenses) #:prefix license:)
25 #:use-module (gnu packages)
26 #:use-module (gnu packages base)
27 #:use-module (gnu packages compression)
28 #:use-module (gnu packages lisp)
29 #:use-module (gnu packages readline)
30 #:use-module (guix packages)
31 #:use-module (guix download)
32 #:use-module (guix git-download)
33 #:use-module (guix build-system gnu)
34 #:use-module (guix build-system trivial)
35 #:use-module (guix build-system minify))
36
37 (define-public font-mathjax
38 (package
39 (name "font-mathjax")
40 (version "2.7.2")
41 (source
42 (origin
43 (method url-fetch)
44 (uri (string-append
45 "https://github.com/mathjax/MathJax/archive/"
46 version ".tar.gz"))
47 (file-name (string-append name "-" version ".tar.gz"))
48 (sha256
49 (base32
50 "1r72di4pg4i6pfhcskkxqmf1158m81ki6a7lbw6nz4zh7xw23hy4"))))
51 (build-system trivial-build-system)
52 (arguments
53 `(#:modules ((guix build utils))
54 #:builder
55 (begin
56 (use-modules (guix build utils)
57 (ice-9 match))
58 (set-path-environment-variable
59 "PATH" '("bin") (map (match-lambda
60 ((_ . input)
61 input))
62 %build-inputs))
63 (let ((install-directory (string-append %output "/share/fonts/mathjax")))
64 (mkdir-p install-directory)
65 (invoke "tar" "-C" install-directory "-xvf"
66 (assoc-ref %build-inputs "source")
67 ,(string-append "MathJax-" version "/fonts")
68 "--strip" "2")))))
69 (native-inputs
70 `(("gzip" ,gzip)
71 ("tar" ,tar)))
72 (home-page "https://www.mathjax.org/")
73 (synopsis "Fonts for MathJax")
74 (description "This package contains the fonts required for MathJax.")
75 (license license:asl2.0)))
76
77 (define-public js-mathjax
78 (package
79 (inherit font-mathjax)
80 (name "js-mathjax")
81 (arguments
82 `(#:modules ((guix build utils))
83 #:builder
84 (begin
85 (use-modules (guix build utils)
86 (ice-9 match)
87 (ice-9 popen)
88 (ice-9 regex))
89 (set-path-environment-variable
90 "PATH" '("bin") (map (match-lambda
91 ((_ . input)
92 input))
93 %build-inputs))
94 (set-path-environment-variable
95 "GUIX_LOCPATH" '("lib/locale")
96 (list (assoc-ref %build-inputs "glibc-utf8-locales")))
97 (setenv "LANG" "en_US.UTF-8")
98 (let ((install-directory (string-append %output "/share/javascript/mathjax")))
99 (invoke "tar" "xvf" (assoc-ref %build-inputs "source")
100 ,(string-append "MathJax-" (package-version font-mathjax)
101 "/unpacked")
102 "--strip" "2")
103 (mkdir-p install-directory)
104 (symlink (string-append (assoc-ref %build-inputs "font-mathjax")
105 "/share/fonts/mathjax")
106 (string-append install-directory "/fonts"))
107
108 (for-each
109 (lambda (file)
110 (let ((installed (string-append install-directory
111 ;; remove prefix "."
112 (string-drop file 1))))
113 (format #t "~a -> ~a~%" file installed)
114 (cond
115 ((string-match "\\.js$" file)
116 (mkdir-p (dirname installed))
117 (let ((minified (open-pipe* OPEN_READ "uglify-js" file)))
118 (call-with-output-file installed
119 (lambda (port)
120 (dump-port minified port)))
121
122 (let ((exit (close-pipe minified)))
123 (unless (zero? exit)
124 (error "dear, uglify-js failed" exit)))))
125 (else
126 (install-file file (dirname installed))))))
127 (find-files "."))
128
129 #t))))
130 (native-inputs
131 `(("font-mathjax" ,font-mathjax)
132 ("glibc-utf8-locales" ,glibc-utf8-locales)
133 ("uglify-js" ,uglify-js)
134 ,@(package-native-inputs font-mathjax)))
135 (synopsis "JavaScript display engine for LaTeX, MathML, and AsciiMath")
136 (description "MathJax is a JavaScript display engine for LaTeX, MathML,
137 and AsciiMath notation that works in all modern browsers. It requires no
138 plugins or software to be installed on the browser. So the page author can
139 write web documents that include mathematics and be confident that readers will
140 be able to view it naturally and easily.")))
141
142 (define-public js-respond
143 (package
144 (name "js-respond")
145 (version "1.4.2")
146 (source (origin
147 (method url-fetch)
148 (uri (string-append "https://github.com/scottjehl/Respond/"
149 "archive/" version ".tar.gz"))
150 (file-name (string-append name "-" version ".tar.gz"))
151 (sha256
152 (base32
153 "0ds1ya2a185jp93mdn07159c2x8zczwi960ykrawpp62bwk2n93d"))))
154 (build-system trivial-build-system)
155 (arguments
156 `(#:modules ((guix build utils))
157 #:builder
158 (begin
159 (use-modules (guix build utils)
160 (ice-9 match)
161 (ice-9 popen)
162 (srfi srfi-26))
163 (set-path-environment-variable
164 "PATH" '("bin") (map (match-lambda
165 ((_ . input)
166 input))
167 %build-inputs))
168 (let ((install-directory (string-append %output
169 "/share/javascript/respond/")))
170 (invoke "tar" "xvf"
171 (assoc-ref %build-inputs "source")
172 "--strip" "1")
173 (mkdir-p install-directory)
174 (let* ((file "src/respond.js")
175 (installed (string-append install-directory "respond.min.js")))
176 (let ((minified (open-pipe* OPEN_READ "uglify-js" file)))
177 (call-with-output-file installed
178 (cut dump-port minified <>)))))
179 #t)))
180 (home-page "https://github.com/scottjehl/Respond")
181 (native-inputs
182 `(("uglify-js" ,uglify-js)
183 ("source" ,source)
184 ("gzip" ,gzip)
185 ("tar" ,tar)))
186 (synopsis "Polyfill for min/max-width CSS3 Media Queries")
187 (description "The goal of this script is to provide a fast and lightweight
188 script to enable responsive web designs in browsers that don't support CSS3
189 Media Queries.")
190 (license license:expat)))
191
192 (define-public js-html5shiv
193 (package
194 (name "js-html5shiv")
195 (version "3.7.3")
196 (source (origin
197 (method url-fetch)
198 (uri (string-append "https://github.com/aFarkas/html5shiv/"
199 "archive/" version ".tar.gz"))
200 (file-name (string-append name "-" version ".tar.gz"))
201 (sha256
202 (base32
203 "0inlbpxpqzdyi24lqagzf7l24zxg0y02xcpqs2h4npjscazzw7hg"))))
204 (build-system minify-build-system)
205 (home-page "https://github.com/aFarkas/html5shiv")
206 (synopsis "Enable HTML5 sectioning elements in legacy browsers")
207 (description "The HTML5 Shiv enables use of HTML5 sectioning elements in
208 legacy Internet Explorer and provides basic HTML5 styling for Internet
209 Explorer 6-9, Safari 4.x (and iPhone 3.x), and Firefox 3.x.")
210 ;; From the file "MIT and GPL2 licenses.md":
211 ;;
212 ;; This software is licensed under a dual license system (MIT or GPL
213 ;; version 2). This means you are free to choose with which of both
214 ;; licenses (MIT or GPL version 2) you want to use this library.
215 (license (list license:expat license:gpl2))))
216
217 (define-public js-json2
218 (let ((commit "031b1d9e6971bd4c433ca85e216cc853f5a867bd")
219 (revision "1"))
220 (package
221 (name "js-json2")
222 (version (string-append "2016-10-28." revision "-" (string-take commit 7)))
223 (source (origin
224 (method git-fetch)
225 (uri (git-reference
226 (url "https://github.com/douglascrockford/JSON-js.git")
227 (commit commit)))
228 (file-name (string-append name "-" version "-checkout"))
229 (sha256
230 (base32
231 "1fvb6b2y5sd3sqdgcj683sdxcbxdii34q0ysc9wg0dq1sy81l11v"))))
232 (build-system minify-build-system)
233 (arguments
234 `(#:javascript-files '("json2.js"
235 "json_parse.js"
236 "json_parse_state.js"
237 "cycle.js")))
238 (home-page "https://github.com/douglascrockford/JSON-js")
239 (synopsis "JSON encoders and decoders")
240 (description "The files in this collection implement JSON
241 encoders/decoders in JavaScript.
242
243 @code{json2.js}: This file creates a JSON property in the global object, if
244 there isn't already one, setting its value to an object containing a stringify
245 method and a parse method. The @code{parse} method uses the @code{eval}
246 method to do the parsing, guarding it with several regular expressions to
247 defend against accidental code execution hazards. On current browsers, this
248 file does nothing, preferring the built-in JSON object.
249
250 @code{json_parse.js}: This file contains an alternative JSON @code{parse}
251 function that uses recursive descent instead of @code{eval}.
252
253 @code{json_parse_state.js}: This files contains an alternative JSON
254 @code{parse} function that uses a state machine instead of @code{eval}.
255
256 @code{cycle.js}: This file contains two functions, @code{JSON.decycle} and
257 @code{JSON.retrocycle}, which make it possible to encode cyclical structures
258 and DAGs in JSON, and to then recover them. This is a capability that is not
259 provided by ES5. @code{JSONPath} is used to represent the links.")
260 (license license:public-domain))))
261
262 (define-public js-strftime
263 (package
264 (name "js-strftime")
265 (version "0.10.0")
266 (source (origin
267 (method url-fetch)
268 (uri (string-append "https://github.com/samsonjs/strftime/"
269 "archive/v" version ".tar.gz"))
270 (file-name (string-append name "-" version ".tar.gz"))
271 (sha256
272 (base32
273 "1iya43w7y26y2dp9l4d40bhjc4scb5a9mng5ng5c8hsqr82f1375"))))
274 (build-system minify-build-system)
275 (arguments
276 `(#:javascript-files '("strftime.js")))
277 (home-page "https://github.com/samsonjs/strftime")
278 (synopsis "Implementation of strftime to JavaScript")
279 (description "This is an implementation of the @code{strftime} procedure
280 for JavaScript. It works in (at least) node.js and browsers. It supports
281 localization and timezones. Most standard specifiers from C are supported as
282 well as some other extensions from Ruby.")
283 (license license:expat)))
284
285 (define-public js-highlight
286 (package
287 (name "js-highlight")
288 (version "9.12.0")
289 (source (origin
290 (method url-fetch)
291 (uri (string-append "https://github.com/isagalaev/highlight.js/"
292 "archive/" version ".tar.gz"))
293 (file-name (string-append name "-" version ".tar.gz"))
294 (sha256
295 (base32
296 "1jjn9mj7fwq4zpr6is438bscf03b3q8jkj0k5c3fc6pkmjnhw939"))))
297 (build-system minify-build-system)
298 (arguments
299 `(#:javascript-files '("src/highlight.js")))
300 (home-page "https://github.com/isagalaev/highlight.js")
301 (synopsis "Syntax highlighting for JavaScript")
302 (description "Highlight.js is a syntax highlighter written in JavaScript.
303 It works in the browser as well as on the server. It works with pretty much
304 any markup, doesn’t depend on any framework and has automatic language
305 detection.")
306 (license license:bsd-3)))
307
308 (define-public js-datatables
309 (package
310 (name "js-datatables")
311 (version "1.10.15")
312 (source (origin
313 (method url-fetch)
314 (uri (string-append "https://datatables.net/releases/DataTables-"
315 version ".zip"))
316 (sha256
317 (base32
318 "1y9xqyqyz7x1ls3ska71pshl2hpiy3qnw1f7wygyslbhy4ssgf57"))))
319 (build-system minify-build-system)
320 (arguments
321 `(#:javascript-files '("media/js/dataTables.bootstrap.js"
322 "media/js/jquery.dataTables.js")))
323 (native-inputs
324 `(("unzip" ,unzip)))
325 (home-page "https://datatables.net")
326 (synopsis "DataTables plug-in for jQuery")
327 (description "DataTables is a table enhancing plug-in for the jQuery
328 Javascript library, adding sorting, paging and filtering abilities to plain
329 HTML tables with minimal effort.")
330 (license license:expat)))
331
332 (define-public js-selectize
333 (package
334 (name "js-selectize")
335 (version "0.12.4")
336 (source (origin
337 (method url-fetch)
338 (uri (string-append "https://github.com/selectize/selectize.js/"
339 "archive/v" version ".tar.gz"))
340 (file-name (string-append name "-" version ".tar.gz"))
341 (sha256
342 (base32
343 "0756p49aaz34mw2dx8k1gxf210mngfrri25vkba0j7wihd2af8gn"))))
344 (build-system minify-build-system)
345 (arguments `(#:javascript-files '("src/selectize.js")))
346 (home-page "http://selectize.github.io/selectize.js/")
347 (synopsis "Hybrid widget between a textbox and <select> box")
348 (description "Selectize is the hybrid of a textbox and @code{<select>}
349 box. It's jQuery based and it has autocomplete and native-feeling keyboard
350 navigation; it is useful for tagging, contact lists, etc.")
351 (license license:asl2.0)))
352
353 (define-public js-es5-shim
354 (package
355 (name "js-es5-shim")
356 (version "4.5.9")
357 (source (origin
358 (method url-fetch)
359 (uri (string-append "https://github.com/es-shims/es5-shim/"
360 "archive/v" version ".tar.gz"))
361 (file-name (string-append name "-" version ".tar.gz"))
362 (sha256
363 (base32
364 "0yfndyijz0ykddzprpvfjb2453gzpn528klmwycwbqc1bqd3m1hl"))))
365 (build-system minify-build-system)
366 (arguments `(#:javascript-files
367 '("es5-sham.js"
368 "es5-shim.js")))
369 (home-page "https://github.com/es-shims/es5-shim")
370 (synopsis "ECMAScript 5 compatibility shims for legacy JavaScript engines")
371 (description "@code{es5-shim.js} patches a JavaScript context to contain
372 all ECMAScript 5 methods that can be faithfully emulated with a legacy
373 JavaScript engine. @code{es5-sham.js} patches other ES5 methods as closely as
374 possible. Many of these shams are intended only to allow code to be written
375 to ES5 without causing run-time errors in older engines. In many cases, this
376 means that these shams cause many ES5 methods to silently fail.")
377 (license license:expat)))
378
379 (define-public js-filesaver
380 (package
381 (name "js-filesaver")
382 (version "1.3.8")
383 (source (origin
384 (method url-fetch)
385 (uri (string-append "https://github.com/eligrey/FileSaver.js/"
386 "archive/" version ".tar.gz"))
387 (file-name (string-append name "-" version))
388 (sha256
389 (base32
390 "1rkhfqs5plaj628kzj7qgm5qahy4v7ihygifidqr6g6265mil97h"))))
391 (build-system minify-build-system)
392 (arguments
393 `(#:phases
394 (modify-phases %standard-phases
395 (add-after 'unpack 'fix-uglification
396 ;; Remove "export" keyword which prevents the file from being
397 ;; uglified by uglify-js. Moreover, that keyword is not present in
398 ;; the minified version of the library some projects are using,
399 ;; e.g.,
400 ;; <https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/blob/master/FileSaver.min.js>
401 (lambda _
402 (substitute* "src/FileSaver.js"
403 (("export ") ""))
404 #t)))))
405 (home-page
406 "https://eligrey.com/blog/saving-generated-files-on-the-client-side/")
407 (synopsis "HTML5 saveAs() FileSaver implementation")
408 (description "@file{FileSaver.js} implements the @code{saveAs()}
409 FileSaver interface in browsers that do not natively support it.
410
411 @file{FileSaver.js} is the solution to saving files on the
412 client-side, and is perfect for webapps that need to generate files,
413 or for saving sensitive information that shouldn't be sent to an
414 external server.")
415 (license license:expat)))
416
417 (define-public mujs
418 (package
419 (name "mujs")
420 (version "1.0.5")
421 (source (origin
422 (method git-fetch)
423 (uri (git-reference
424 (url "https://git.ghostscript.com/mujs.git")
425 (commit version)))
426 (file-name (string-append name "-" version "-checkout"))
427 (sha256
428 (base32
429 "0pkv26jxwgv5ax0ylfmi4h96h79hj4gvr95218ns8wngnmgr1ny6"))))
430 (build-system gnu-build-system)
431 (arguments
432 '(#:phases
433 (modify-phases %standard-phases
434 (delete 'configure) ; no configure
435 (add-after 'install 'install-shared-library
436 (lambda* (#:key outputs #:allow-other-keys)
437 (let ((out (assoc-ref outputs "out")))
438 (install-file "build/release/libmujs.so"
439 (string-append out "/lib"))))))
440 #:make-flags (list (string-append "prefix=" (assoc-ref %outputs "out"))
441 (string-append "CC=gcc"))
442 #:tests? #f)) ; no tests
443 (inputs
444 `(("readline" ,readline)))
445 (home-page "https://artifex.com/mujs/")
446 (synopsis "JavaScript interpreter written in C")
447 (description "MuJS is a lightweight Javascript interpreter designed for
448 embedding in other software to extend them with scripting capabilities. MuJS
449 was designed with a focus on small size, correctness, and simplicity. It is
450 written in portable C and implements ECMAScript as specified by ECMA-262. The
451 interface for binding with native code is designed to be as simple as possible
452 to use, and is very similar to Lua. There is no need to interact with byzantine
453 C++ template mechanisms, or worry about marking and unmarking garbage collection
454 roots, or wrestle with obscure build systems.")
455 (license license:isc)))