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