@live-codes/browser-compilers 0.4.11 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/autoprefixer/autoprefixer.js +42 -42
  2. package/dist/babel-preset-solid/babel-preset-solid.js +67 -17
  3. package/dist/gnuplot/gnuplot.js +4675 -0
  4. package/dist/gnuplot/gnuplot_api.js +99 -0
  5. package/dist/mdx/mdx.js +48 -2348
  6. package/dist/postcss/postcss.js +18 -18
  7. package/dist/postcss-preset-env/postcss-preset-env.js +131 -1440
  8. package/dist/prettier/parser-pug.js +105 -105
  9. package/dist/remark-gfm/remark-gfm.js +14 -0
  10. package/dist/sass/sass.js +253 -0
  11. package/dist/svgbob-wasm/svgbob-wasm.js +119 -0
  12. package/package.json +16 -12
  13. package/scripts/patch.js +25 -0
  14. package/scripts/vendors-module.mjs +21 -0
  15. package/scripts/vendors.js +66 -19
  16. package/vendor-licenses.md +8 -0
  17. package/vendor_modules/imports/babel-preset-solid.js +1 -1
  18. package/vendor_modules/imports/mdx.ts +1 -2
  19. package/vendor_modules/imports/remark-gfm.js +3 -0
  20. package/vendor_modules/imports/sass.ts +16 -0
  21. package/vendor_modules/src/gnuplot-JS/LICENSE +21 -0
  22. package/vendor_modules/src/gnuplot-JS/README +55 -0
  23. package/vendor_modules/src/gnuplot-JS/gnuplot-4.6.3/em_make +7 -0
  24. package/vendor_modules/src/gnuplot-JS/gnuplot-4.6.3/gnuplot-4.6.3.patch +13 -0
  25. package/vendor_modules/src/gnuplot-JS/gnuplot-4.6.3/post.js +17 -0
  26. package/vendor_modules/src/gnuplot-JS/gnuplot-4.6.3/pre.js +62 -0
  27. package/vendor_modules/src/gnuplot-JS/www/gnuplot.js +4675 -0
  28. package/vendor_modules/src/gnuplot-JS/www/gnuplot_api.js +99 -0
  29. package/vendor_modules/src/gnuplot-JS/www/index.html +182 -0
  30. package/vendor_modules/src/stylus/readme.md +1 -0
  31. package/vendor_modules/src/svgbob-wasm/readme.md +1 -0
  32. package/vendor_modules/src/svgbob-wasm/svgbob-wasm.js +119 -0
@@ -0,0 +1,119 @@
1
+ export const svgbobWasm = async (wasmUrl) => {
2
+ var svgbob_wasm_bg_default =
3
+ wasmUrl || 'https://cdn.jsdelivr.net/npm/svgbob-wasm/svgbob_wasm_bg.wasm';
4
+
5
+ var imports = {};
6
+ async function loadWasm(module3, imports2) {
7
+ if (typeof module3 === 'string') {
8
+ const moduleRequest = await fetch(module3);
9
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
10
+ try {
11
+ return await WebAssembly.instantiateStreaming(moduleRequest, imports2);
12
+ } catch (e) {
13
+ if (moduleRequest.headers.get('Content-Type') != 'application/wasm') {
14
+ console.warn(e);
15
+ } else {
16
+ throw e;
17
+ }
18
+ }
19
+ }
20
+ module3 = await moduleRequest.arrayBuffer();
21
+ }
22
+ return await WebAssembly.instantiate(module3, imports2);
23
+ }
24
+ var { instance, module: module2 } = await loadWasm(svgbob_wasm_bg_default, imports);
25
+ var memory = instance.exports.memory;
26
+ var convert_string = instance.exports.convert_string;
27
+ var __wbindgen_export_0 = instance.exports.__wbindgen_export_0;
28
+ var __wbindgen_malloc = instance.exports.__wbindgen_malloc;
29
+ var __wbindgen_realloc = instance.exports.__wbindgen_realloc;
30
+ var __wbindgen_free = instance.exports.__wbindgen_free;
31
+
32
+ var WASM_VECTOR_LEN = 0;
33
+ var cachegetUint8Memory0 = null;
34
+ function getUint8Memory0() {
35
+ if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== memory.buffer) {
36
+ cachegetUint8Memory0 = new Uint8Array(memory.buffer);
37
+ }
38
+ return cachegetUint8Memory0;
39
+ }
40
+ var lTextEncoder =
41
+ typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
42
+ var cachedTextEncoder = new lTextEncoder('utf-8');
43
+ var encodeString =
44
+ typeof cachedTextEncoder.encodeInto === 'function'
45
+ ? function (arg, view) {
46
+ return cachedTextEncoder.encodeInto(arg, view);
47
+ }
48
+ : function (arg, view) {
49
+ const buf = cachedTextEncoder.encode(arg);
50
+ view.set(buf);
51
+ return {
52
+ read: arg.length,
53
+ written: buf.length,
54
+ };
55
+ };
56
+ function passStringToWasm0(arg, malloc, realloc) {
57
+ if (realloc === void 0) {
58
+ const buf = cachedTextEncoder.encode(arg);
59
+ const ptr2 = malloc(buf.length);
60
+ getUint8Memory0()
61
+ .subarray(ptr2, ptr2 + buf.length)
62
+ .set(buf);
63
+ WASM_VECTOR_LEN = buf.length;
64
+ return ptr2;
65
+ }
66
+ let len = arg.length;
67
+ let ptr = malloc(len);
68
+ const mem = getUint8Memory0();
69
+ let offset = 0;
70
+ for (; offset < len; offset++) {
71
+ const code = arg.charCodeAt(offset);
72
+ if (code > 127) break;
73
+ mem[ptr + offset] = code;
74
+ }
75
+ if (offset !== len) {
76
+ if (offset !== 0) {
77
+ arg = arg.slice(offset);
78
+ }
79
+ ptr = realloc(ptr, len, (len = offset + arg.length * 3));
80
+ const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
81
+ const ret = encodeString(arg, view);
82
+ offset += ret.written;
83
+ }
84
+ WASM_VECTOR_LEN = offset;
85
+ return ptr;
86
+ }
87
+ var cachegetInt32Memory0 = null;
88
+ function getInt32Memory0() {
89
+ if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== memory.buffer) {
90
+ cachegetInt32Memory0 = new Int32Array(memory.buffer);
91
+ }
92
+ return cachegetInt32Memory0;
93
+ }
94
+ var lTextDecoder =
95
+ typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
96
+ var cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
97
+ cachedTextDecoder.decode();
98
+ function getStringFromWasm0(ptr, len) {
99
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
100
+ }
101
+ function convert_string2(data) {
102
+ try {
103
+ const retptr = __wbindgen_export_0.value - 16;
104
+ __wbindgen_export_0.value = retptr;
105
+ var ptr0 = passStringToWasm0(data, __wbindgen_malloc, __wbindgen_realloc);
106
+ var len0 = WASM_VECTOR_LEN;
107
+ convert_string(retptr, ptr0, len0);
108
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
109
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
110
+ return getStringFromWasm0(r0, r1);
111
+ } finally {
112
+ __wbindgen_export_0.value += 16;
113
+ __wbindgen_free(r0, r1);
114
+ }
115
+ }
116
+ return {
117
+ convert_string: convert_string2,
118
+ };
119
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-codes/browser-compilers",
3
- "version": "0.4.11",
3
+ "version": "0.5.0",
4
4
  "description": "Compilers that run in the browser, for use in livecodes.io",
5
5
  "author": "Hatem Hosny",
6
6
  "license": "MIT",
@@ -9,9 +9,9 @@
9
9
  "url": "https://github.com/live-codes/browser-compilers"
10
10
  },
11
11
  "scripts": {
12
- "start": "live-server dist --cors",
12
+ "start": "live-server dist --port=8081 --no-browser --cors",
13
13
  "build": "run-s clean build:vendors copy:types",
14
- "build:vendors": "node ./scripts/vendors.js",
14
+ "build:vendors": "node ./scripts/vendors.js && node ./scripts/vendors-module.mjs",
15
15
  "copy:types": "recursive-copy vendor_modules/types dist/types",
16
16
  "gh-pages": "gh-pages -m \"[ci skip] Updates\" -d dist",
17
17
  "fix": "run-s fix:*",
@@ -26,19 +26,23 @@
26
26
  "prepush": "run-s fix build"
27
27
  },
28
28
  "dependencies": {
29
- "@esbuild-plugins/node-globals-polyfill": "0.1.0",
30
- "@esbuild-plugins/node-modules-polyfill": "0.1.1",
31
- "@mdx-js/mdx": "1.6.22",
32
- "@prettier/plugin-pug": "1.17.3",
29
+ "@esbuild-plugins/node-globals-polyfill": "0.1.1",
30
+ "@esbuild-plugins/node-modules-polyfill": "0.1.4",
31
+ "@mdx-js/mdx": "2.0.0",
32
+ "@prettier/plugin-pug": "1.19.2",
33
33
  "@webassemblyjs/wast-refmt": "1.11.1",
34
- "babel-preset-solid": "1.2.1",
34
+ "babel-preset-solid": "1.3.5",
35
+ "esbuild-plugin-cache": "0.2.9",
36
+ "esbuild-plugin-velcro": "0.1.1",
35
37
  "less": "4.1.2",
36
38
  "monaco-editor": "0.29.1",
37
- "postcss": "8.3.11",
38
- "postcss-preset-env": "6.7.0",
39
+ "postcss": "8.4.6",
40
+ "postcss-preset-env": "7.3.1",
39
41
  "react": "17.0.2",
40
42
  "react-dom": "17.0.2",
41
43
  "react-native-web": "0.17.5",
44
+ "remark-gfm": "3.0.1",
45
+ "sass": "1.49.7",
42
46
  "svelte": "3.44.1",
43
47
  "windicss": "3.2.1"
44
48
  },
@@ -48,10 +52,10 @@
48
52
  "@types/prettier": "2.1.6",
49
53
  "@typescript-eslint/eslint-plugin": "4.8.2",
50
54
  "@typescript-eslint/parser": "4.8.2",
51
- "autoprefixer": "10.4.0",
55
+ "autoprefixer": "10.4.2",
52
56
  "cz-conventional-changelog": "3.2.0",
53
57
  "esbuild": "0.11.12",
54
- "esbuild-plugin-replace": "1.0.6",
58
+ "esbuild-plugin-node-polyfills": "1.0.2",
55
59
  "eslint": "7.32.0",
56
60
  "eslint-config-prettier": "6.11.0",
57
61
  "eslint-plugin-import": "2.20.2",
@@ -0,0 +1,25 @@
1
+ var fs = require('fs');
2
+ var path = require('path');
3
+
4
+ const patch = (
5
+ /** @type {string} */ filePath,
6
+ /** @type {Record<string, string>} */ replacements = {},
7
+ ) =>
8
+ new Promise((resolve, reject) => {
9
+ fs.readFile(path.resolve(filePath), 'utf8', function (err, data) {
10
+ if (err) return reject(err);
11
+
12
+ var result = data;
13
+ for (const key of Object.keys(replacements)) {
14
+ result = result.replace(key, replacements[key]);
15
+ }
16
+
17
+ fs.writeFile(path.resolve(filePath), result, 'utf8', function (err) {
18
+ if (err) return reject(err);
19
+
20
+ resolve();
21
+ });
22
+ });
23
+ });
24
+
25
+ module.exports = { patch };
@@ -0,0 +1,21 @@
1
+ import esbuild from 'esbuild';
2
+ import { cache } from 'esbuild-plugin-cache';
3
+
4
+ /** @type {Partial<esbuild.BuildOptions>} */
5
+ const baseOptions = {
6
+ bundle: true,
7
+ minify: true,
8
+ format: 'iife',
9
+ define: { global: 'window', 'process.env.NODE_ENV': '"production"' },
10
+ };
11
+
12
+ // solid
13
+ esbuild.build({
14
+ ...baseOptions,
15
+ entryPoints: ['vendor_modules/imports/babel-preset-solid.js'],
16
+ outfile: 'dist/babel-preset-solid/babel-preset-solid.js',
17
+ globalName: 'babelPresetSolid',
18
+ define: { global: 'window', 'process.env': '{}' },
19
+
20
+ plugins: [cache({})],
21
+ });
@@ -4,8 +4,13 @@ var path = require('path');
4
4
  const esbuild = require('esbuild');
5
5
  const NodeModulesPolyfills = require('@esbuild-plugins/node-modules-polyfill').default;
6
6
  const GlobalsPolyfills = require('@esbuild-plugins/node-globals-polyfill').default;
7
+ // const ESBuildNodePolyfillsPlugin = require('esbuild-plugin-node-polyfills');
8
+ // const { createPlugin } = require('esbuild-plugin-velcro');
9
+
7
10
  const Bundler = require('parcel-bundler');
8
11
 
12
+ const { patch } = require('./patch');
13
+
9
14
  const nodePolyfills = [
10
15
  NodeModulesPolyfills(),
11
16
  GlobalsPolyfills({
@@ -64,6 +69,19 @@ entryFiles.forEach(async (file) => {
64
69
  await parcelBundler.bundle();
65
70
  });
66
71
 
72
+ // sass
73
+ patch('node_modules/sass/sass.dart.js', {
74
+ 'var self = Object.create(dartNodePreambleSelf);': 'var self = window;',
75
+ }).then(() => {
76
+ esbuild.build({
77
+ ...baseOptions,
78
+ entryPoints: ['vendor_modules/imports/sass.ts'],
79
+ outfile: 'dist/sass/sass.js',
80
+ globalName: 'sass',
81
+ plugins: nodePolyfills,
82
+ });
83
+ });
84
+
67
85
  // Less
68
86
  esbuild.buildSync({
69
87
  ...baseOptions,
@@ -112,14 +130,21 @@ esbuild.build({
112
130
  });
113
131
 
114
132
  // postcss-preset-env
115
- esbuild.build({
116
- ...baseOptions,
117
- entryPoints: ['vendor_modules/imports/postcss-preset-env.ts'],
118
- outfile: 'dist/postcss-preset-env/postcss-preset-env.js',
119
- globalName: 'postcssPresetEnv',
120
- plugins: nodePolyfills,
133
+ patch('node_modules/postcss-custom-properties/dist/index.mjs', {
134
+ 'import{pathToFileURL as r}from"url";': 'const r = (path) => new URL(path, "file:");',
135
+ 'import{promises as s}from"fs";':
136
+ 'const s = { writeFile: async () => {}, readFile: async () => "" };',
137
+ }).then(() => {
138
+ esbuild.build({
139
+ ...baseOptions,
140
+ entryPoints: ['vendor_modules/imports/postcss-preset-env.ts'],
141
+ outfile: 'dist/postcss-preset-env/postcss-preset-env.js',
142
+ globalName: 'postcssPresetEnv',
143
+ plugins: nodePolyfills,
144
+ });
121
145
  });
122
146
 
147
+ // @prettier/plugin-pug
123
148
  esbuild.buildSync({
124
149
  ...baseOptions,
125
150
  entryPoints: ['node_modules/@prettier/plugin-pug/dist/index.js'],
@@ -127,15 +152,6 @@ esbuild.buildSync({
127
152
  globalName: 'pluginPug',
128
153
  });
129
154
 
130
- // solid
131
- esbuild.build({
132
- ...baseOptions,
133
- entryPoints: ['vendor_modules/imports/babel-preset-solid.js'],
134
- outfile: 'dist/babel-preset-solid/babel-preset-solid.js',
135
- globalName: 'babelPresetSolid',
136
- plugins: nodePolyfills,
137
- });
138
-
139
155
  // svelte
140
156
  esbuild.buildSync({
141
157
  ...baseOptions,
@@ -152,12 +168,25 @@ fs.copyFileSync(
152
168
  );
153
169
 
154
170
  // MDX
171
+ patch('node_modules/@mdx-js/mdx/lib/plugin/recma-document.js', {
172
+ "import {URL} from 'url'": '',
173
+ }).then(() => {
174
+ esbuild.build({
175
+ ...baseOptions,
176
+ entryPoints: ['vendor_modules/imports/mdx.ts'],
177
+ outfile: 'dist/mdx/mdx.js',
178
+ format: 'esm',
179
+ define: { window: 'globalThis' },
180
+ plugins: nodePolyfills,
181
+ });
182
+ });
183
+
184
+ // remark-gfm
155
185
  esbuild.build({
156
186
  ...baseOptions,
157
- entryPoints: ['vendor_modules/imports/mdx.ts'],
158
- outfile: 'dist/mdx/mdx.js',
159
- globalName: 'MDX',
160
- plugins: nodePolyfills,
187
+ entryPoints: ['vendor_modules/imports/remark-gfm.js'],
188
+ outfile: 'dist/remark-gfm/remark-gfm.js',
189
+ format: 'esm',
161
190
  });
162
191
 
163
192
  // livescript
@@ -238,3 +267,21 @@ fs.copyFileSync(
238
267
  path.resolve(vendor_modules_src + '/turbopascal/turbopascal.js'),
239
268
  path.resolve(targetDir + '/turbopascal/turbopascal.js'),
240
269
  );
270
+
271
+ // gnuplot
272
+ mkdirp(targetDir + '/gnuplot');
273
+ fs.copyFileSync(
274
+ path.resolve(vendor_modules_src + '/gnuplot-JS/www/gnuplot.js'),
275
+ path.resolve(targetDir + '/gnuplot/gnuplot.js'),
276
+ );
277
+ fs.copyFileSync(
278
+ path.resolve(vendor_modules_src + '/gnuplot-JS/www/gnuplot_api.js'),
279
+ path.resolve(targetDir + '/gnuplot/gnuplot_api.js'),
280
+ );
281
+
282
+ // svgbob-wasm
283
+ mkdirp(targetDir + '/svgbob-wasm');
284
+ fs.copyFileSync(
285
+ path.resolve(vendor_modules_src + '/svgbob-wasm/svgbob-wasm.js'),
286
+ path.resolve(targetDir + '/svgbob-wasm/svgbob-wasm.js'),
287
+ );
@@ -10,6 +10,10 @@ clientside-haml-js: [MIT License](https://github.com/uglyog/clientside-haml-js/b
10
10
 
11
11
  CoffeeScript: [MIT License](https://github.com/jashkenas/coffeescript/tree/07f644c39223e016aceedd2cd71b5941579b5659)
12
12
 
13
+ dart-sass: [MIT License](https://github.com/sass/dart-sass/blob/e3bf3eb3a3a8708877a86a08c7e3bee92160ac1f/LICENSE)
14
+
15
+ gnuplot-JS: [MIT License](https://github.com/chhu/gnuplot-JS/blob/62a3c8488ad00c97807ba48ae75738ca3af607fe/LICENSE)
16
+
13
17
  JSCPP: [MIT License](https://github.com/felixhao28/JSCPP/blob/befbd6b48666007151c259c5dd291ab028ad4c04/LICENSE)
14
18
 
15
19
  Less: [Apache License 2.0](https://github.com/less/less.js/blob/870f9b2d8136bfbcdc9e1293bb0def51b54f9276/LICENSE)
@@ -46,6 +50,10 @@ Stylus: [MIT License](https://github.com/stylus/stylus/blob/59bc665db295981d4e3f
46
50
 
47
51
  Svelte: [MIT License](https://github.com/sveltejs/svelte/blob/dafbdc286eef3de2243088a9a826e6899e20465c/LICENSE)
48
52
 
53
+ svgbob: [Apache License 2.0](https://github.com/ivanceras/svgbob/blob/277f28b337a2d00a61cf342247060cf5fbf88d50/LICENSE)
54
+
55
+ svgbob-wasm: [Apache License 2.0](https://github.com/agoose77/svgbob-wasm/blob/45e280096ee7f7a07981de2ce95aba343bc94123/LICENSE_APACHE)
56
+
49
57
  turbopascal: [BSD 2-Clause License](https://github.com/MikeRalphson/turbopascal/blob/cfcc5ee6d93f32664bb6127aa751c68841ca5c1d/LICENSE)
50
58
 
51
59
  wacl: [BSD 3-Clause License](https://github.com/ecky-l/wacl/blob/9daacabb0102a9986f33263261350edfeebdd83b/LICENSE)
@@ -1,2 +1,2 @@
1
- import solid from 'babel-preset-solid';
1
+ import solid from 'https://esm.sh/babel-preset-solid@1.3.5';
2
2
  export { solid };
@@ -1,2 +1 @@
1
- import mdx from '@mdx-js/mdx';
2
- export { mdx };
1
+ export { compile } from '@mdx-js/mdx';
@@ -0,0 +1,3 @@
1
+ import remarkGfm from 'remark-gfm';
2
+
3
+ export default remarkGfm;
@@ -0,0 +1,16 @@
1
+ import sass from 'sass';
2
+
3
+ window.process = {
4
+ ...window.process,
5
+ stdout: {
6
+ write: (...data) => console.log(...data),
7
+ isTTY: false,
8
+ },
9
+ stderr: {
10
+ write: (...data) => console.warn(...data),
11
+ },
12
+ env: {},
13
+ };
14
+
15
+ export const compileString = sass.compileString;
16
+ export const compileStringAsync = sass.compileStringAsync;
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Christian Huettig
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,55 @@
1
+ Portable JS Gnuplot
2
+ *******************
3
+
4
+ This is the result of compiling gnuplot with emscripten, combined with an API so it is usable straight out of the box in your browser.
5
+ The www directory contains the necessary files and a compiled version of gnuplot 4.6.3. The gnuplot-4.6.3 directory contains everything to
6
+ build the gnuplot sources with emscripten.
7
+
8
+ How to compile gnuplot
9
+ **********************
10
+
11
+ - Install llvm / emscripten, follow instructions at http://emscripten.org
12
+ - Download the gnuplot-4.6.3.tar.gz sources at http://gnuplot.info and untar.
13
+ - Copy the contents of this repo's gnuplot-4.6.3 into the folder where you unpacked the sources (should be the same name).
14
+ - [optional] adjust src/term.h and remove unneeded terminals to reduce final size
15
+ - [optional] patch src/axis.c with the patch file to fix axis descriptions: cd src;patch <../gnuplot-4.6.3.patch
16
+ - Run em_make to configure and build, you should have a gnuplot.js in your directory. WAIT at the end! The final step takes long.
17
+
18
+ How the API works
19
+ *****************
20
+
21
+ The gnuplot API (gnuplot_api.js) creates a worker (JS-thread) that loads gnuplot.js and handles all the work. No browser checks are done to check for HTML5 features.
22
+ The API lets you interact with the worker to "upload" or "download" files. Emscripten uses a mock-up for file I/O, so keep in mind that files are kept in memory as arrays
23
+ and that you need to push / pull any file-content to / from the fake file system within the worker. The API provides some convenience functions for this.
24
+
25
+ The demo site from the www directory is online at http://gnuplot.respawned.com
26
+
27
+ A minimal implementation should look like this (untested! see index.html for working version):
28
+
29
+ <img id="result"/>
30
+ <script src='gnuplot_api.js'></script>
31
+ <script>
32
+ gnuplot = new Gnuplot('gnuplot.js');
33
+ //gnuplot.putFile("myData.dat", "1 2 3 4 5 6 7 8 9 0"); // No callback needed here
34
+ gnuplot.run("my gnuplot script as a string", function(e) {
35
+ gnuplot.getFile('out.svg', function(e) {
36
+ if (!e.content) {
37
+ alert("Output file out.svg not found!");
38
+ return;
39
+ }
40
+ var img = document.getElementById('result');
41
+ try {
42
+ var ab = new Uint8Array(e.content);
43
+ var blob = new Blob([ab], {"type": "image\/svg+xml"});
44
+ window.URL = window.URL || window.webkitURL;
45
+ img.src = window.URL.createObjectURL(blob);
46
+ } catch (err) { // in case blob / URL missing, fallback to data-uri
47
+ var rstr = '';
48
+ for (var i = 0; i < e.content.length; i++)
49
+ rstr += String.fromCharCode(e.content[i]);
50
+ img.src = 'data:image\/svg+xml;base64,' + btoa(rstr);
51
+ }
52
+ });
53
+ });
54
+ </script>
55
+
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ emconfigure ./configure --without-readline --without-x --disable-h3d-quadtree --disable-wxwidgets
3
+ #emmake make clean
4
+ emmake make
5
+ rm gnuplot.o
6
+ mv src/gnuplot ./gnuplot.o
7
+ em++ -s INVOKE_RUN=0 -O2 -s ASM_JS=1 gnuplot.o -o gnuplot.js --post-js post.js --pre-js pre.js
@@ -0,0 +1,13 @@
1
+ --- gnuplot-4.6.3/src/axis.c 2012-11-08 18:13:08.000000000 +0100
2
+ +++ gnuplot-4.6.3_mod/src/axis.c 2013-05-11 11:08:08.791587160 +0200
3
+ @@ -467,8 +467,9 @@ copy_or_invent_formatstring(AXIS_INDEX a
4
+ int precision = (ceil(-log10(fabs(axmax-axmin))));
5
+ if ((axmin*axmax > 0) && precision > 4)
6
+ sprintf(ticfmt[axis],"%%.%df", (precision>14) ? 14 : precision);
7
+ + else
8
+ + strcpy(ticfmt[axis], "%g");
9
+ }
10
+ -
11
+ return ticfmt[axis];
12
+ }
13
+
@@ -0,0 +1,17 @@
1
+ shouldRunNow = true;
2
+ self['Runtime'] = Runtime;
3
+ self['FS'] = FS;
4
+ };
5
+ gnuplot_create();
6
+ // This is to avoid name mangling from closure compilers
7
+ self['FS'] = FS;
8
+ self['FS']['root'] = FS.root;
9
+ self['FS']['deleteFile'] = FS.deleteFile;
10
+ self['FS']['findObject'] = FS.findObject;
11
+ self['FS']['createDataFile'] = FS.createDataFile;
12
+ self['FS']['getFileContents'] = function(name) {
13
+ var file = FS.findObject(name);
14
+ if (!file) return null;
15
+ return file.contents;
16
+ };
17
+
@@ -0,0 +1,62 @@
1
+ self.addEventListener('message', function(e) {
2
+ var data = e.data;
3
+ if (!data) return;
4
+ var cmd = data['cmd'];
5
+ var transaction = data['transaction'];
6
+ var name = data['name'];
7
+ var content = data['content'];
8
+ var result = {
9
+ transaction: transaction
10
+ };
11
+ switch (cmd) {
12
+ case 'run':
13
+ try {
14
+ shouldRunNow = true;
15
+ if (content)
16
+ Module.run(content);
17
+ else
18
+ Module.run();
19
+ } catch(err) {
20
+
21
+ Module.printErr('Exit called, reset state.');
22
+ gnuplot_create();
23
+ };
24
+ result['content'] = 'FINISH';
25
+ self.postMessage(result);
26
+ break;
27
+
28
+ case 'putFile':
29
+ if (FS.findObject(name))
30
+ FS.deleteFile(name);
31
+ var arrc = content;
32
+ if (typeof(content) == "string")
33
+ arrc = Module['intArrayFromString'](content, true);
34
+ FS.createDataFile('/', name, arrc);
35
+ result['content'] = 'OK';
36
+ self.postMessage(result);
37
+ break;
38
+
39
+ case 'getFile':
40
+ var file = FS.findObject(name);
41
+ result['content'] = file.contents || 0;
42
+ self.postMessage(result);
43
+ break;
44
+
45
+ default:
46
+ result['content'] = 'unknown cmd';
47
+ self.postMessage(result);
48
+ };
49
+ }, false);
50
+
51
+
52
+ var Module = {
53
+ 'noInitialRun': true,
54
+ print: function(text) {
55
+ self.postMessage({'transaction': -1, 'content': text});
56
+ },
57
+ printErr: function(text) {
58
+ self.postMessage({'transaction': -2, 'content': text});
59
+ },
60
+
61
+ };
62
+ function gnuplot_create() {