gnu: js-respond: Use minify-build-system.
[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, 2019 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 minify-build-system)
155 (arguments
156 `(#:javascript-files '("src/matchmedia.addListener.js"
157 "src/matchmedia.polyfill.js"
158 "src/respond.js")))
159 (home-page "https://github.com/scottjehl/Respond")
160 (synopsis "Polyfill for min/max-width CSS3 Media Queries")
161 (description "The goal of this script is to provide a fast and lightweight
162 script to enable responsive web designs in browsers that don't support CSS3
163 Media Queries.")
164 (license license:expat)))
165
166 (define-public js-html5shiv
167 (package
168 (name "js-html5shiv")
169 (version "3.7.3")
170 (source (origin
171 (method git-fetch)
172 (uri (git-reference
173 (url "https://github.com/aFarkas/html5shiv")
174 (commit version)))
175 (file-name (git-file-name name version))
176 (sha256
177 (base32
178 "0y1c5nyq0brl9fjdihhax33vks4s1ij9iv113879sg3zflmgqpd0"))))
179 (build-system minify-build-system)
180 (home-page "https://github.com/aFarkas/html5shiv")
181 (synopsis "Enable HTML5 sectioning elements in legacy browsers")
182 (description "The HTML5 Shiv enables use of HTML5 sectioning elements in
183 legacy Internet Explorer and provides basic HTML5 styling for Internet
184 Explorer 6-9, Safari 4.x (and iPhone 3.x), and Firefox 3.x.")
185 ;; From the file "MIT and GPL2 licenses.md":
186 ;;
187 ;; This software is licensed under a dual license system (MIT or GPL
188 ;; version 2). This means you are free to choose with which of both
189 ;; licenses (MIT or GPL version 2) you want to use this library.
190 (license (list license:expat license:gpl2))))
191
192 (define-public js-json2
193 (let ((commit "031b1d9e6971bd4c433ca85e216cc853f5a867bd")
194 (revision "1"))
195 (package
196 (name "js-json2")
197 (version (string-append "2016-10-28." revision "-" (string-take commit 7)))
198 (source (origin
199 (method git-fetch)
200 (uri (git-reference
201 (url "https://github.com/douglascrockford/JSON-js.git")
202 (commit commit)))
203 (file-name (string-append name "-" version "-checkout"))
204 (sha256
205 (base32
206 "1fvb6b2y5sd3sqdgcj683sdxcbxdii34q0ysc9wg0dq1sy81l11v"))))
207 (build-system minify-build-system)
208 (arguments
209 `(#:javascript-files '("json2.js"
210 "json_parse.js"
211 "json_parse_state.js"
212 "cycle.js")))
213 (home-page "https://github.com/douglascrockford/JSON-js")
214 (synopsis "JSON encoders and decoders")
215 (description "The files in this collection implement JSON
216 encoders/decoders in JavaScript.
217
218 @code{json2.js}: This file creates a JSON property in the global object, if
219 there isn't already one, setting its value to an object containing a stringify
220 method and a parse method. The @code{parse} method uses the @code{eval}
221 method to do the parsing, guarding it with several regular expressions to
222 defend against accidental code execution hazards. On current browsers, this
223 file does nothing, preferring the built-in JSON object.
224
225 @code{json_parse.js}: This file contains an alternative JSON @code{parse}
226 function that uses recursive descent instead of @code{eval}.
227
228 @code{json_parse_state.js}: This files contains an alternative JSON
229 @code{parse} function that uses a state machine instead of @code{eval}.
230
231 @code{cycle.js}: This file contains two functions, @code{JSON.decycle} and
232 @code{JSON.retrocycle}, which make it possible to encode cyclical structures
233 and DAGs in JSON, and to then recover them. This is a capability that is not
234 provided by ES5. @code{JSONPath} is used to represent the links.")
235 (license license:public-domain))))
236
237 (define-public js-strftime
238 (package
239 (name "js-strftime")
240 (version "0.10.0")
241 (source (origin
242 (method git-fetch)
243 (uri (git-reference
244 (url"https://github.com/samsonjs/strftime")
245 (commit (string-append "v" version))))
246 (file-name (git-file-name name version))
247 (sha256
248 (base32
249 "131nmlivazwxyba25kh9lda99749fq4xsyin6lzfalaaydviby4p"))))
250 (build-system minify-build-system)
251 (arguments
252 `(#:javascript-files '("strftime.js")))
253 (home-page "https://github.com/samsonjs/strftime")
254 (synopsis "Implementation of strftime to JavaScript")
255 (description "This is an implementation of the @code{strftime} procedure
256 for JavaScript. It works in (at least) node.js and browsers. It supports
257 localization and timezones. Most standard specifiers from C are supported as
258 well as some other extensions from Ruby.")
259 (license license:expat)))
260
261 (define-public js-highlight
262 (package
263 (name "js-highlight")
264 (version "9.12.0")
265 (source (origin
266 (method git-fetch)
267 (uri (git-reference
268 (url "https://github.com/isagalaev/highlight.js")
269 (commit version)))
270 (file-name (git-file-name name version))
271 (sha256
272 (base32
273 "12qz22qjpd6svj58pwgcwg2x2rzhihfdrxg6lgj39nfpaln6dris"))))
274 (build-system minify-build-system)
275 (arguments
276 `(#:javascript-files '("src/highlight.js")))
277 (home-page "https://github.com/isagalaev/highlight.js")
278 (synopsis "Syntax highlighting for JavaScript")
279 (description "Highlight.js is a syntax highlighter written in JavaScript.
280 It works in the browser as well as on the server. It works with pretty much
281 any markup, doesn’t depend on any framework and has automatic language
282 detection.")
283 (license license:bsd-3)))
284
285 (define-public js-datatables
286 (package
287 (name "js-datatables")
288 (version "1.10.15")
289 (source (origin
290 (method url-fetch)
291 (uri (string-append "https://datatables.net/releases/DataTables-"
292 version ".zip"))
293 (sha256
294 (base32
295 "1y9xqyqyz7x1ls3ska71pshl2hpiy3qnw1f7wygyslbhy4ssgf57"))))
296 (build-system minify-build-system)
297 (arguments
298 `(#:javascript-files '("media/js/dataTables.bootstrap.js"
299 "media/js/jquery.dataTables.js")))
300 (native-inputs
301 `(("unzip" ,unzip)))
302 (home-page "https://datatables.net")
303 (synopsis "DataTables plug-in for jQuery")
304 (description "DataTables is a table enhancing plug-in for the jQuery
305 Javascript library, adding sorting, paging and filtering abilities to plain
306 HTML tables with minimal effort.")
307 (license license:expat)))
308
309 (define-public js-selectize
310 (package
311 (name "js-selectize")
312 (version "0.12.6")
313 (source (origin
314 (method git-fetch)
315 (uri (git-reference
316 (url "https://github.com/selectize/selectize.js")
317 (commit (string-append "v" version))))
318 (file-name (git-file-name name version))
319 (sha256
320 (base32
321 "15gichl8wi6yxag2ps723nxrgyan15976dzsnvw9h9py8sbyyzjn"))))
322 (build-system minify-build-system)
323 (arguments `(#:javascript-files '("src/selectize.js")))
324 (home-page "http://selectize.github.io/selectize.js/")
325 (synopsis "Hybrid widget between a textbox and <select> box")
326 (description "Selectize is the hybrid of a textbox and @code{<select>}
327 box. It's jQuery based and it has autocomplete and native-feeling keyboard
328 navigation; it is useful for tagging, contact lists, etc.")
329 (license license:asl2.0)))
330
331 (define-public js-es5-shim
332 (package
333 (name "js-es5-shim")
334 (version "4.5.13")
335 (source (origin
336 (method git-fetch)
337 (uri (git-reference
338 (url "https://github.com/es-shims/es5-shim")
339 (commit (string-append "v" version))))
340 (file-name (git-file-name name version))
341 (sha256
342 (base32
343 "142w384fbyllq4yggv173g82lw3wix4jqcg6hkhx1ymq89vvnpmh"))))
344 (build-system minify-build-system)
345 (arguments `(#:javascript-files
346 '("es5-sham.js"
347 "es5-shim.js")))
348 (home-page "https://github.com/es-shims/es5-shim")
349 (synopsis "ECMAScript 5 compatibility shims for legacy JavaScript engines")
350 (description "@code{es5-shim.js} patches a JavaScript context to contain
351 all ECMAScript 5 methods that can be faithfully emulated with a legacy
352 JavaScript engine. @code{es5-sham.js} patches other ES5 methods as closely as
353 possible. Many of these shams are intended only to allow code to be written
354 to ES5 without causing run-time errors in older engines. In many cases, this
355 means that these shams cause many ES5 methods to silently fail.")
356 (license license:expat)))
357
358 (define-public js-filesaver
359 (package
360 (name "js-filesaver")
361 (version "1.3.8")
362 (source (origin
363 (method git-fetch)
364 (uri (git-reference
365 (url "https://github.com/eligrey/FileSaver.js")
366 (commit version)))
367 (file-name (git-file-name name version))
368 (sha256
369 (base32
370 "0gvqk0hnr8fig0n4da7vj7q6z31bcyv52916xz3rbmdj3pgpiv1d"))))
371 (build-system minify-build-system)
372 (arguments
373 `(#:phases
374 (modify-phases %standard-phases
375 (add-after 'unpack 'fix-uglification
376 ;; Remove "export" keyword which prevents the file from being
377 ;; uglified by uglify-js. Moreover, that keyword is not present in
378 ;; the minified version of the library some projects are using,
379 ;; e.g.,
380 ;; <https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/blob/master/FileSaver.min.js>
381 (lambda _
382 (substitute* "src/FileSaver.js"
383 (("export ") ""))
384 #t)))))
385 (home-page
386 "https://eligrey.com/blog/saving-generated-files-on-the-client-side/")
387 (synopsis "HTML5 saveAs() FileSaver implementation")
388 (description "@file{FileSaver.js} implements the @code{saveAs()}
389 FileSaver interface in browsers that do not natively support it.
390
391 @file{FileSaver.js} is the solution to saving files on the
392 client-side, and is perfect for webapps that need to generate files,
393 or for saving sensitive information that shouldn't be sent to an
394 external server.")
395 (license license:expat)))
396
397 (define-public mujs
398 (package
399 (name "mujs")
400 (version "1.0.6")
401 (source (origin
402 (method url-fetch)
403 (uri (string-append "https://mujs.com/downloads/mujs-"
404 version ".tar.xz"))
405 (sha256
406 (base32
407 "1q9w2dcspfp580pzx7sw7x9gbn8j0ak6dvj75wd1ml3f3q3i43df"))))
408 (build-system gnu-build-system)
409 (arguments
410 '(#:phases
411 (modify-phases %standard-phases
412 (delete 'configure) ; no configure
413 (add-after 'install 'install-shared-library
414 (lambda* (#:key (make-flags '()) #:allow-other-keys)
415 (apply invoke "make" "install-shared" make-flags))))
416 #:make-flags (list (string-append "prefix=" (assoc-ref %outputs "out"))
417 (string-append "CC=gcc"))
418 #:tests? #f)) ; no tests
419 (inputs
420 `(("readline" ,readline)))
421 (home-page "https://mujs.com/")
422 (synopsis "JavaScript interpreter written in C")
423 (description "MuJS is a lightweight Javascript interpreter designed for
424 embedding in other software to extend them with scripting capabilities. MuJS
425 was designed with a focus on small size, correctness, and simplicity. It is
426 written in portable C and implements ECMAScript as specified by ECMA-262. The
427 interface for binding with native code is designed to be as simple as possible
428 to use, and is very similar to Lua. There is no need to interact with byzantine
429 C++ template mechanisms, or worry about marking and unmarking garbage collection
430 roots, or wrestle with obscure build systems.")
431 (license license:isc)))