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