gnu: Add js-requirejs.
[jackhill/guix/guix.git] / gnu / packages / javascript.scm
CommitLineData
a3d3b7a4
AI
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Arun Isaac <arunisaac@systemreboot.net>
4112ff7e 3;;; Copyright © 2017, 2019 Ricardo Wurmus <rekado@elephly.net>
99863166 4;;; Copyright © 2017, 2018 Tobias Geerinckx-Rice <me@tobias.gr>
cb5b5149 5;;; Copyright © 2017, 2018, 2019 Efraim Flashner <efraim@flashner.co.il>
11b43f99 6;;; Copyright © 2018 Nicolas Goaziou <mail@nicolasgoaziou.fr>
a3d3b7a4
AI
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)
a3d3b7a4 28 #:use-module (gnu packages lisp)
99863166 29 #:use-module (gnu packages readline)
a3d3b7a4
AI
30 #:use-module (guix packages)
31 #:use-module (guix download)
68ffb6c5 32 #:use-module (guix git-download)
89ba894e 33 #:use-module (guix build-system gnu)
68ffb6c5
RW
34 #:use-module (guix build-system trivial)
35 #:use-module (guix build-system minify))
a3d3b7a4 36
649c438c
LC
37(define-public font-mathjax
38 (package
39 (name "font-mathjax")
d6a7268b 40 (version "2.7.2")
649c438c
LC
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
d6a7268b 50 "1r72di4pg4i6pfhcskkxqmf1158m81ki6a7lbw6nz4zh7xw23hy4"))))
649c438c
LC
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)
e3cfef22
MW
65 (invoke "tar" "-C" install-directory "-xvf"
66 (assoc-ref %build-inputs "source")
67 ,(string-append "MathJax-" version "/fonts")
68 "--strip" "2")))))
649c438c
LC
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
a3d3b7a4
AI
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")))
e3cfef22
MW
99 (invoke "tar" "xvf" (assoc-ref %build-inputs "source")
100 ,(string-append "MathJax-" (package-version font-mathjax)
101 "/unpacked")
102 "--strip" "2")
a3d3b7a4
AI
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)
9da2dd90
LC
120 (dump-port minified port)))
121
122 (let ((exit (close-pipe minified)))
123 (unless (zero? exit)
124 (error "dear, uglify-js failed" exit)))))
a3d3b7a4
AI
125 (else
126 (install-file file (dirname installed))))))
e3cfef22
MW
127 (find-files "."))
128
129 #t))))
a3d3b7a4
AI
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,
137and AsciiMath notation that works in all modern browsers. It requires no
138plugins or software to be installed on the browser. So the page author can
139write web documents that include mathematics and be confident that readers will
140be able to view it naturally and easily.")))
b37b48f8
RW
141
142(define-public js-respond
143 (package
144 (name "js-respond")
145 (version "1.4.2")
146 (source (origin
97f6004c
EF
147 (method git-fetch)
148 (uri (git-reference
149 (url "https://github.com/scottjehl/Respond")
150 (commit version)))
151 (file-name (git-file-name name version))
b37b48f8
RW
152 (sha256
153 (base32
97f6004c 154 "00xid731rirc7sdy1gc8qal3v9g0agr2qx15hm4x97l1lcbylyn2"))))
367d0833 155 (build-system minify-build-system)
b37b48f8 156 (arguments
367d0833
EF
157 `(#:javascript-files '("src/matchmedia.addListener.js"
158 "src/matchmedia.polyfill.js"
159 "src/respond.js")))
b37b48f8 160 (home-page "https://github.com/scottjehl/Respond")
b37b48f8
RW
161 (synopsis "Polyfill for min/max-width CSS3 Media Queries")
162 (description "The goal of this script is to provide a fast and lightweight
163script to enable responsive web designs in browsers that don't support CSS3
164Media Queries.")
165 (license license:expat)))
ed69963b
RW
166
167(define-public js-html5shiv
168 (package
169 (name "js-html5shiv")
170 (version "3.7.3")
171 (source (origin
8a35e58a
EF
172 (method git-fetch)
173 (uri (git-reference
174 (url "https://github.com/aFarkas/html5shiv")
175 (commit version)))
176 (file-name (git-file-name name version))
ed69963b
RW
177 (sha256
178 (base32
8a35e58a 179 "0y1c5nyq0brl9fjdihhax33vks4s1ij9iv113879sg3zflmgqpd0"))))
ed69963b
RW
180 (build-system minify-build-system)
181 (home-page "https://github.com/aFarkas/html5shiv")
182 (synopsis "Enable HTML5 sectioning elements in legacy browsers")
183 (description "The HTML5 Shiv enables use of HTML5 sectioning elements in
184legacy Internet Explorer and provides basic HTML5 styling for Internet
185Explorer 6-9, Safari 4.x (and iPhone 3.x), and Firefox 3.x.")
186 ;; From the file "MIT and GPL2 licenses.md":
187 ;;
188 ;; This software is licensed under a dual license system (MIT or GPL
189 ;; version 2). This means you are free to choose with which of both
190 ;; licenses (MIT or GPL version 2) you want to use this library.
191 (license (list license:expat license:gpl2))))
68ffb6c5
RW
192
193(define-public js-json2
194 (let ((commit "031b1d9e6971bd4c433ca85e216cc853f5a867bd")
195 (revision "1"))
196 (package
197 (name "js-json2")
198 (version (string-append "2016-10-28." revision "-" (string-take commit 7)))
199 (source (origin
200 (method git-fetch)
201 (uri (git-reference
202 (url "https://github.com/douglascrockford/JSON-js.git")
203 (commit commit)))
204 (file-name (string-append name "-" version "-checkout"))
205 (sha256
206 (base32
207 "1fvb6b2y5sd3sqdgcj683sdxcbxdii34q0ysc9wg0dq1sy81l11v"))))
208 (build-system minify-build-system)
209 (arguments
210 `(#:javascript-files '("json2.js"
211 "json_parse.js"
212 "json_parse_state.js"
213 "cycle.js")))
214 (home-page "https://github.com/douglascrockford/JSON-js")
215 (synopsis "JSON encoders and decoders")
216 (description "The files in this collection implement JSON
217encoders/decoders in JavaScript.
218
219@code{json2.js}: This file creates a JSON property in the global object, if
220there isn't already one, setting its value to an object containing a stringify
221method and a parse method. The @code{parse} method uses the @code{eval}
222method to do the parsing, guarding it with several regular expressions to
223defend against accidental code execution hazards. On current browsers, this
224file does nothing, preferring the built-in JSON object.
225
226@code{json_parse.js}: This file contains an alternative JSON @code{parse}
227function that uses recursive descent instead of @code{eval}.
228
229@code{json_parse_state.js}: This files contains an alternative JSON
230@code{parse} function that uses a state machine instead of @code{eval}.
231
232@code{cycle.js}: This file contains two functions, @code{JSON.decycle} and
233@code{JSON.retrocycle}, which make it possible to encode cyclical structures
234and DAGs in JSON, and to then recover them. This is a capability that is not
235provided by ES5. @code{JSONPath} is used to represent the links.")
236 (license license:public-domain))))
3f48403a
RW
237
238(define-public js-strftime
239 (package
240 (name "js-strftime")
241 (version "0.10.0")
242 (source (origin
16df2914
EF
243 (method git-fetch)
244 (uri (git-reference
245 (url"https://github.com/samsonjs/strftime")
246 (commit (string-append "v" version))))
247 (file-name (git-file-name name version))
3f48403a
RW
248 (sha256
249 (base32
16df2914 250 "131nmlivazwxyba25kh9lda99749fq4xsyin6lzfalaaydviby4p"))))
3f48403a
RW
251 (build-system minify-build-system)
252 (arguments
253 `(#:javascript-files '("strftime.js")))
254 (home-page "https://github.com/samsonjs/strftime")
255 (synopsis "Implementation of strftime to JavaScript")
256 (description "This is an implementation of the @code{strftime} procedure
257for JavaScript. It works in (at least) node.js and browsers. It supports
258localization and timezones. Most standard specifiers from C are supported as
259well as some other extensions from Ruby.")
260 (license license:expat)))
a6bbb2a0
RW
261
262(define-public js-highlight
263 (package
264 (name "js-highlight")
265 (version "9.12.0")
266 (source (origin
778f4430
EF
267 (method git-fetch)
268 (uri (git-reference
269 (url "https://github.com/isagalaev/highlight.js")
270 (commit version)))
271 (file-name (git-file-name name version))
a6bbb2a0
RW
272 (sha256
273 (base32
778f4430 274 "12qz22qjpd6svj58pwgcwg2x2rzhihfdrxg6lgj39nfpaln6dris"))))
a6bbb2a0
RW
275 (build-system minify-build-system)
276 (arguments
277 `(#:javascript-files '("src/highlight.js")))
278 (home-page "https://github.com/isagalaev/highlight.js")
279 (synopsis "Syntax highlighting for JavaScript")
280 (description "Highlight.js is a syntax highlighter written in JavaScript.
281It works in the browser as well as on the server. It works with pretty much
282any markup, doesn’t depend on any framework and has automatic language
283detection.")
284 (license license:bsd-3)))
c4abc94d
RW
285
286(define-public js-datatables
287 (package
288 (name "js-datatables")
289 (version "1.10.15")
290 (source (origin
291 (method url-fetch)
292 (uri (string-append "https://datatables.net/releases/DataTables-"
293 version ".zip"))
294 (sha256
295 (base32
296 "1y9xqyqyz7x1ls3ska71pshl2hpiy3qnw1f7wygyslbhy4ssgf57"))))
297 (build-system minify-build-system)
298 (arguments
299 `(#:javascript-files '("media/js/dataTables.bootstrap.js"
300 "media/js/jquery.dataTables.js")))
301 (native-inputs
302 `(("unzip" ,unzip)))
303 (home-page "https://datatables.net")
304 (synopsis "DataTables plug-in for jQuery")
305 (description "DataTables is a table enhancing plug-in for the jQuery
306Javascript library, adding sorting, paging and filtering abilities to plain
307HTML tables with minimal effort.")
308 (license license:expat)))
4f65067b 309
4112ff7e
RW
310(define-public js-requirejs
311 (package
312 (name "js-requirejs")
313 (version "2.3.6")
314 (source (origin
315 (method git-fetch)
316 (uri (git-reference
317 (url "https://github.com/requirejs/requirejs.git")
318 (commit version)))
319 (file-name (git-file-name name version))
320 (sha256
321 (base32
322 "0cvd5y2mb3h6yil3niqn3gjqrzixdsxcz4rvc2f0hg4kzp5y0w86"))))
323 (build-system minify-build-system)
324 (arguments `(#:javascript-files '("require.js")))
325 (home-page "https://github.com/requirejs/requirejs/")
326 (synopsis "File and module loader for JavaScript")
327 (description "RequireJS loads plain JavaScript files as well as more
328defined modules. It is optimized for in-browser use, including in a Web
329Worker, but it can be used in other JavaScript environments.")
330 (license license:expat)))
331
4f65067b
RW
332(define-public js-selectize
333 (package
334 (name "js-selectize")
3500cb58 335 (version "0.12.6")
4f65067b 336 (source (origin
41514478
EF
337 (method git-fetch)
338 (uri (git-reference
339 (url "https://github.com/selectize/selectize.js")
340 (commit (string-append "v" version))))
341 (file-name (git-file-name name version))
4f65067b
RW
342 (sha256
343 (base32
3500cb58 344 "15gichl8wi6yxag2ps723nxrgyan15976dzsnvw9h9py8sbyyzjn"))))
4f65067b
RW
345 (build-system minify-build-system)
346 (arguments `(#:javascript-files '("src/selectize.js")))
347 (home-page "http://selectize.github.io/selectize.js/")
348 (synopsis "Hybrid widget between a textbox and <select> box")
349 (description "Selectize is the hybrid of a textbox and @code{<select>}
350box. It's jQuery based and it has autocomplete and native-feeling keyboard
351navigation; it is useful for tagging, contact lists, etc.")
352 (license license:asl2.0)))
0b0aa76f
RW
353
354(define-public js-es5-shim
355 (package
356 (name "js-es5-shim")
9cf60dec 357 (version "4.5.13")
0b0aa76f 358 (source (origin
2209a447
EF
359 (method git-fetch)
360 (uri (git-reference
361 (url "https://github.com/es-shims/es5-shim")
362 (commit (string-append "v" version))))
363 (file-name (git-file-name name version))
0b0aa76f
RW
364 (sha256
365 (base32
9cf60dec 366 "142w384fbyllq4yggv173g82lw3wix4jqcg6hkhx1ymq89vvnpmh"))))
0b0aa76f
RW
367 (build-system minify-build-system)
368 (arguments `(#:javascript-files
369 '("es5-sham.js"
370 "es5-shim.js")))
371 (home-page "https://github.com/es-shims/es5-shim")
372 (synopsis "ECMAScript 5 compatibility shims for legacy JavaScript engines")
373 (description "@code{es5-shim.js} patches a JavaScript context to contain
374all ECMAScript 5 methods that can be faithfully emulated with a legacy
375JavaScript engine. @code{es5-sham.js} patches other ES5 methods as closely as
376possible. Many of these shams are intended only to allow code to be written
377to ES5 without causing run-time errors in older engines. In many cases, this
378means that these shams cause many ES5 methods to silently fail.")
379 (license license:expat)))
89ba894e 380
11b43f99
NG
381(define-public js-filesaver
382 (package
383 (name "js-filesaver")
384 (version "1.3.8")
385 (source (origin
e452c69a
EF
386 (method git-fetch)
387 (uri (git-reference
388 (url "https://github.com/eligrey/FileSaver.js")
389 (commit version)))
390 (file-name (git-file-name name version))
11b43f99
NG
391 (sha256
392 (base32
e452c69a 393 "0gvqk0hnr8fig0n4da7vj7q6z31bcyv52916xz3rbmdj3pgpiv1d"))))
11b43f99
NG
394 (build-system minify-build-system)
395 (arguments
396 `(#:phases
397 (modify-phases %standard-phases
398 (add-after 'unpack 'fix-uglification
399 ;; Remove "export" keyword which prevents the file from being
400 ;; uglified by uglify-js. Moreover, that keyword is not present in
401 ;; the minified version of the library some projects are using,
402 ;; e.g.,
403 ;; <https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/blob/master/FileSaver.min.js>
404 (lambda _
405 (substitute* "src/FileSaver.js"
406 (("export ") ""))
407 #t)))))
408 (home-page
409 "https://eligrey.com/blog/saving-generated-files-on-the-client-side/")
410 (synopsis "HTML5 saveAs() FileSaver implementation")
411 (description "@file{FileSaver.js} implements the @code{saveAs()}
412FileSaver interface in browsers that do not natively support it.
413
414@file{FileSaver.js} is the solution to saving files on the
415client-side, and is perfect for webapps that need to generate files,
416or for saving sensitive information that shouldn't be sent to an
417external server.")
418 (license license:expat)))
419
89ba894e
EF
420(define-public mujs
421 (package
422 (name "mujs")
cb5b5149 423 (version "1.0.6")
89ba894e 424 (source (origin
cb5b5149
EF
425 (method url-fetch)
426 (uri (string-append "https://mujs.com/downloads/mujs-"
427 version ".tar.xz"))
89ba894e
EF
428 (sha256
429 (base32
cb5b5149 430 "1q9w2dcspfp580pzx7sw7x9gbn8j0ak6dvj75wd1ml3f3q3i43df"))))
89ba894e
EF
431 (build-system gnu-build-system)
432 (arguments
f8ddf719
EF
433 '(#:phases
434 (modify-phases %standard-phases
435 (delete 'configure) ; no configure
436 (add-after 'install 'install-shared-library
cb5b5149
EF
437 (lambda* (#:key (make-flags '()) #:allow-other-keys)
438 (apply invoke "make" "install-shared" make-flags))))
89ba894e
EF
439 #:make-flags (list (string-append "prefix=" (assoc-ref %outputs "out"))
440 (string-append "CC=gcc"))
99863166
TGR
441 #:tests? #f)) ; no tests
442 (inputs
443 `(("readline" ,readline)))
cb5b5149 444 (home-page "https://mujs.com/")
89ba894e
EF
445 (synopsis "JavaScript interpreter written in C")
446 (description "MuJS is a lightweight Javascript interpreter designed for
447embedding in other software to extend them with scripting capabilities. MuJS
448was designed with a focus on small size, correctness, and simplicity. It is
449written in portable C and implements ECMAScript as specified by ECMA-262. The
450interface for binding with native code is designed to be as simple as possible
451to use, and is very similar to Lua. There is no need to interact with byzantine
452C++ template mechanisms, or worry about marking and unmarking garbage collection
453roots, or wrestle with obscure build systems.")
454 (license license:isc)))