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