@jseeio/jsee 0.3.8 → 0.4.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.
@@ -3,7 +3,11 @@
3
3
  "allow": [
4
4
  "Bash(npm run test:basic:*)",
5
5
  "Bash(npm run build-dev:*)",
6
- "Bash(npm run test:unit:*)"
6
+ "Bash(npm run test:unit:*)",
7
+ "Bash(find:*)",
8
+ "Bash(npx eslint:*)",
9
+ "Bash(npm run test:python:*)",
10
+ "Bash(npm run build:*)"
7
11
  ]
8
12
  }
9
13
  }
package/.eslintrc.js ADDED
@@ -0,0 +1,38 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ node: true,
5
+ es2020: true,
6
+ jest: true,
7
+ },
8
+ parserOptions: {
9
+ ecmaVersion: 2020,
10
+ sourceType: 'module',
11
+ },
12
+ rules: {
13
+ // Match existing style: no semicolons, single quotes, 2-space indent
14
+ semi: ['warn', 'never'],
15
+ quotes: ['warn', 'single', { avoidEscape: true, allowTemplateLiterals: true }],
16
+ indent: ['warn', 2, { SwitchCase: 1, ignoredNodes: ['TemplateLiteral *'] }],
17
+ 'no-unused-vars': ['warn', { args: 'none', varsIgnorePattern: '^_' }],
18
+ 'no-undef': 'error',
19
+ eqeqeq: ['warn', 'smart'],
20
+ 'no-eval': 'off', // intentional eval usage in main.js
21
+ },
22
+ globals: {
23
+ VERSION: 'readonly',
24
+ importScripts: 'readonly',
25
+ JSEE: 'readonly',
26
+ loadPyodide: 'readonly',
27
+ },
28
+ overrides: [
29
+ {
30
+ // Puppeteer tests use global `page` from jest-puppeteer
31
+ files: ['test/**/*.test.js'],
32
+ globals: {
33
+ page: 'readonly',
34
+ },
35
+ },
36
+ ],
37
+ ignorePatterns: ['dist/', 'node_modules/', 'apps/', 'tmp/', 'load/'],
38
+ }
package/AGENTS.md CHANGED
@@ -13,14 +13,41 @@ Use **2-space indentation** and **semicolon-free** syntax. Use **single quotes**
13
13
 
14
14
  ## Quick start
15
15
 
16
+ ```bash
17
+ npm install # install dependencies
18
+ npm run build-dev # fast dev build (no tests, no minification)
19
+ npm run build # production build + full test suite
20
+ npm run test:unit # unit tests only (fast, no browser)
21
+ npm run test:basic # E2E tests (auto-starts http-server on 8484)
22
+ ```
16
23
 
17
24
  ## Repo map
18
25
 
26
+ ```
27
+ src/
28
+ main.js # JSEE class — schema parsing, model/worker init, run loop
29
+ app.js # Vue 3 app factory — creates reactive GUI from schema inputs/outputs
30
+ worker.js # Web Worker entry — receives model config, runs importScripts + model code
31
+ utils.js # Shared helpers — URL resolution, script loading, serialization, validation
32
+ cli.js # CLI (`npx jsee`) — HTML generation, --fetch bundling, dev server
33
+ overlay.js # Loading/progress overlay component
34
+ constants.js # Shared defaults (container selector, timeouts, chunk sizes)
35
+ templates/ # Vue SFC templates (bulma-app, bulma-input, bulma-output, file-picker)
36
+ test/
37
+ unit/ # Jest unit tests (no browser): utils.test.js, cli-fetch.test.js
38
+ test-basic.test.js # Puppeteer E2E tests against built dist/
39
+ test-python.test.js # Pyodide integration test
40
+ fixtures/ # Test fixtures (lodash-like.js, upload-sample.csv)
41
+ dist/ # Build output: jsee.js (dev), jsee.runtime.js (production)
42
+ apps/ # Example apps (hashr, detect, qrcode, etc.)
43
+ webpack.config.js # Two build targets: full (jsee.js) and runtime (jsee.runtime.js)
44
+ ```
45
+
19
46
 
20
47
  ## Definition of done
21
48
  - Run: `npm run build` (or `npm run build-dev` during iteration)
22
49
  - Run unit tests: `npm run test:unit` (fast, no browser needed)
23
- - Run E2E tests: `npm run test:basic` (requires `http-server -p 8080` running)
50
+ - Run E2E tests: `npm run test:basic` (auto-starts http-server on port 8484)
24
51
  - Add/adjust unit tests for core logic in `test/unit/`
25
52
 
26
53
  ## Constraints
@@ -30,6 +57,7 @@ Use **2-space indentation** and **semicolon-free** syntax. Use **single quotes**
30
57
  - Each change: for non-trivial changes, add comments, update docs (new features that can be used by users should be represented in `README.md` and `CHANGELOG.md`), run tests, commit with a clear message. For trivial changes (e.g., fixing typos), you can skip some steps but still ensure the change is well-documented in the commit message.
31
58
  - A lot of apps depend on JSEE, so be mindful of backward compatibility. If a change is breaking, stop and ask for help. If you need to make a breaking change, update the version in `package.json` and clearly document the change in `CHANGELOG.md`.
32
59
  - Ask for confirmation before each commit
60
+ - Commit changes one at a time, with clear messages. Avoid large commits that combine multiple changes.
33
61
 
34
62
  ## Conventions
35
63
  - Formatting: no formatter is configured; preserve existing style (2-space indentation, semicolon-free, single quotes)
package/CHANGELOG.md CHANGED
@@ -1,16 +1,33 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.4.0
4
4
  ### Bug fixes:
5
+ - Fix relative import URLs (e.g. `dist/core.js`) resolving against CDN instead of page URL — now resolves against `window.location.href` so blob workers can load them correctly
5
6
  - Gate worker initialization with an `initialized` flag: only the first `{url|code}` payload initializes the worker, all later payloads are treated as execution input
7
+ - Fix model type inference for URL-loaded JS: when `code` is present, infer `function` instead of treating `url` as API `post`
8
+ - Improve worker payload fallback diagnostics: if `postMessage` fails with File/Blob/binary payloads, throw a descriptive error instead of silently dropping data via JSON fallback
9
+ - Move `showdown-katex` and `katex` to runtime `dependencies` so `npx jsee` works without dev installs
10
+ - Fix `--fetch` bundling to include `schema.view` and `schema.render` blocks in addition to `schema.model`
11
+ - Fix `--fetch` import resolution for local relative JS imports and support object import entries (`{ url, ... }`)
12
+ - Fix CLI output path handling for absolute/relative `--outputs` values and remove duplicate final HTML write
13
+ - Fix `download()` method referencing undeclared `env` variable — now correctly uses `this`
14
+ - Fix `outputAsync()` referencing undeclared `delay` — now correctly uses `utils.delay`
15
+ - Fix CLI social links default case referencing undeclared `s` variable
16
+ - Remove dead `title` assignment in CLI `gen` function (already handled in `genHead`)
6
17
  ### Features:
7
18
  - Allow `progress(null)` to render an indeterminate top progress bar for stream-like tasks where total size is unknown
8
19
  - Add `cancelCurrentRun()` runtime entrypoint and wire overlay Stop button with proper `click` handling for any active run
9
20
  - Add worker cooperative cancel signal: `_cmd: 'cancel'` updates worker state and JS model context now exposes `ctx.isCancelled()`
10
21
  - Add end-to-end `raw` file input mode: schema `inputs[].raw` now passes `File` objects / URL handles instead of loading full text into memory
11
22
  - Add file input stream mode (`inputs[].stream: true`) that wraps raw file/URL sources into async iterable `ChunkedReader` objects (zero-dep, supports `for await`, `.text()`, `.bytes()`, `.lines()`) in both worker and main-thread execution
23
+ - Preserve stream reader metadata (`name`, `size`, `type`) for file/URL sources and keep it available across downstream pipeline stages
24
+ - Auto-load file input URL query params on init (no extra Load click required)
25
+ - Add CSS-aware imports: `.css` entries in `imports` arrays are injected as `<link rel="stylesheet">` on the main thread and skipped in workers
26
+ - Add CLI `--runtime` to control runtime source: supports `auto|local|cdn|inline` modes plus custom URL/path values (e.g. `./node_modules/@jseeio/jsee/dist/jsee.js`)
27
+ - Add CLI `--help` flag with usage information and examples
28
+ - Add ESLint config matching project style (no semicolons, single quotes, 2-space indent)
12
29
 
13
- ## 0.3.8
30
+ ## 0.3.8 (2026-02-08)
14
31
  ### Bug fixes:
15
32
  - Fix `run()` error handling: wrap in try/catch/finally so overlay and running state always reset on failure
16
33
  - Add `.catch()` to fire-and-forget `run()` callers to prevent unhandled rejections
@@ -30,7 +47,7 @@
30
47
  - Add unit tests for utils.js: `isObject`, `sanitizeName`, `getUrl`, `delay`, `debounce`, `getName`, `getModelFuncJS`, `getModelFuncAPI`, `validateSchema`
31
48
  - Add `npm run test:unit` script
32
49
 
33
- ## 0.3.4
50
+ ## 0.3.4 (2024-11-19)
34
51
  ### JSEE:
35
52
  - [x] Add `columns` parameter to the `inputs`, `outputs` blocks (making it possible to create multi-column layouts, like simple dashboards)
36
53
  - [x] Add `function` output type (for custom renderers which take a container element as an argument)
@@ -43,11 +60,11 @@
43
60
  - [x] Update `social`, `org`, `ga` blocks
44
61
  - [x] Small layout fixes
45
62
 
46
- ## 0.3.1
63
+ ## 0.3.1 (2024-04-10)
47
64
  - [x] Add `download` method to jsee object
48
65
  - [x] Add `bin` folder with `cmd.js` for easier project building
49
66
 
50
- ## 0.2.9
67
+ ## 0.2.9 (2023-12-11)
51
68
  - [x] Add examples
52
69
  - [x] Add imports
53
70
  - [x] Add `caller` field to the model input (can be: `run`, `autorun` or a button name)
@@ -55,14 +72,14 @@
55
72
  - [x] If `display` field is `false` the input is not shown
56
73
  - [x] If `autorun` is true, then actually autorun the model initially
57
74
 
58
- ## 0.2.8
75
+ ## 0.2.8 (2021-12-29)
59
76
  - [x] Fix no input case
60
77
 
61
- ## 0.2.7
78
+ ## 0.2.7 (2021-12-29)
62
79
  - [x] Show output when result is `0`
63
80
  - [x] Updated style for buttons and inputs
64
81
 
65
- ## 0.2.6
82
+ ## 0.2.6 (2021-12-27)
66
83
  - [x] Tests
67
84
  - [x] Load schema from query (loader)
68
85
  - [x] Reset button appears only after data change
package/README.md CHANGED
@@ -16,6 +16,25 @@ Minimal example:
16
16
 
17
17
  ↳ [Result](https://jsee.org/test/minimal1.html)
18
18
 
19
+ ## Installation
20
+
21
+ **Browser (CDN):**
22
+ ```html
23
+ <script src="https://cdn.jsdelivr.net/npm/@jseeio/jsee@latest/dist/jsee.runtime.js"></script>
24
+ ```
25
+
26
+ **npm (for CLI or Node.js projects):**
27
+ ```bash
28
+ npm install @jseeio/jsee
29
+ ```
30
+
31
+ **CLI (generate standalone apps):**
32
+ ```bash
33
+ npx @jseeio/jsee schema.json -o app.html
34
+ ```
35
+
36
+ Run `jsee --help` for all CLI options.
37
+
19
38
  ## JavaScript Execution Environment
20
39
 
21
40
  JSEE is a browser-based environment for processing tasks. It creates a graphical interface, executes code in a web worker or via API, bridges all pieces together into a user-friendly web app. In some cases, JSEE does all of that automatically, without any configuration. And when the configuration is required, it's just one JSON file with an [intuitive structure](#schema).
@@ -54,12 +73,13 @@ Extra blocks can be provided for further customization
54
73
 
55
74
  - `render` - visualization part (optional). Defines custom rendering code.
56
75
  - `design` - overall appearance (optional). Defines how the app looks overwriting defaults.
57
- - `imports` - a list of urls (optional). Defines a list of scripts to load before the model is initialized.
76
+ - `imports` - a list of urls (optional). Defines a list of scripts and stylesheets to load before the model is initialized. CSS files (`.css` extension) are injected as `<link rel="stylesheet">` in `<head>`, JS files are loaded as scripts. Relative paths are resolved against the page URL.
58
77
 
59
78
  ```json
60
79
  "imports": [
61
80
  "https://cdn.jsdelivr.net/npm/@tensorflow/tfjs",
62
- "https://cdn.jsdelivr.net/pyodide/v0.17.0/full/pyodide.js"
81
+ "https://cdn.jsdelivr.net/pyodide/v0.17.0/full/pyodide.js",
82
+ "styles/app.css"
63
83
  ]
64
84
  ```
65
85
 
@@ -88,6 +108,7 @@ Extra blocks can be provided for further customization
88
108
  - `async-init`
89
109
  - `py`
90
110
  - `tf`
111
+ - Inference note: when `code` is present (including code loaded from a `.js` URL), JSEE treats the model as `function` unless `type` is explicitly set
91
112
  - `method` (string) - If `type` is `class`, `method` defines the name of the class method to call during evaluation
92
113
  - `container` (string) - How input values are passed to the function/method:
93
114
  - `object` (default) - Pass inputs wrapped in an object, i.e. `{'x': 1, 'y': 2}`
@@ -97,6 +118,9 @@ Extra blocks can be provided for further customization
97
118
  - `ctx.log(...args)` - Write runtime logs
98
119
  - `ctx.progress(value)` - Report progress (`0..100` or `null` for indeterminate)
99
120
  - `ctx.isCancelled()` - Check cooperative cancellation state (useful in long loops/streams)
121
+ - `timeout` (number, default: `30000`) - Worker execution timeout in milliseconds. Only applies when `worker: true`. Does not apply during model initialization (loading can be slow). If exceeded, the worker is terminated with an error
122
+ - `imports` (array) - Per-model imports loaded before this model's code executes. Accepts URLs as strings or objects `{ url: "..." }`. Top-level `imports` are moved to the first model internally
123
+ - `model` can also be an **array of model objects** to create a pipeline. Models execute sequentially — each receives the merged output of the previous one. First model defaults to `worker: true`, others to `worker: false`. Return `{ stop: true }` from any model to halt the pipeline early
100
124
  - `render` - Custom rendering script. Instead of relying on JSEE for output visualization, you can provide a custom script that visualizes the results. That can be useful if you rely on custom libs for plotting.
101
125
  - `design` - Design parameters
102
126
  - `layout` - Layout for the model/input/output blocks. If it's empty and the JSEE container is not, JSEE uses inner HTML as a template. If the container is empty too, it uses the default `blocks` template.
@@ -112,9 +136,13 @@ Extra blocks can be provided for further customization
112
136
  - `file` - File Input
113
137
  - `action` or `button` - Button (its `name` will be passed as a `caller` to the model)
114
138
  - `default` - Default value
139
+ - `alias` (string or array of strings) - Alternative names for URL parameter matching. E.g. `"alias": ["f", "file"]` allows `?f=value` or `?file=value` to set this input
140
+ - `display` (string) - Filtrex expression to conditionally show/hide this input. Evaluated against current input values. E.g. `"display": "mode == 'advanced'"` shows the input only when `mode` is `"advanced"`. Supports `len()` for string length
141
+ - `disabled` (boolean) - Disables the input in the UI. When combined with `reactive: true`, triggers an initial model run on page load (useful for server-populated values)
115
142
  - `raw` (boolean, file input only) - If `true`, pass the raw source to the model instead of reading text in the UI (`File` object for disk files or `{ kind: 'url', url: '...' }` for URL input)
116
- - `stream` (boolean, file input only) - If `true`, pass an async iterable `ChunkedReader` to the model instead of raw source handles. Supports `for await (const chunk of reader)`, `await reader.text()`, `await reader.bytes()`, and `for await (const line of reader.lines())`. Works in both main-thread and worker execution.
117
- - `outputs` - Outputs definition
143
+ - `stream` (boolean, file input only) - If `true`, pass an async iterable `ChunkedReader` to the model instead of raw source handles. Supports `for await (const chunk of reader)`, `await reader.text()`, `await reader.bytes()`, and `for await (const line of reader.lines())`. Works in both main-thread and worker execution. Reader metadata (`reader.name`, `reader.size`, `reader.type`) is preserved and remains available in downstream pipeline models.
144
+ - URL params for file inputs (e.g. `?file=https://...`) auto-load on init, so bookmarkable links run without an extra Load click
145
+ - `outputs` - Outputs definition. Outputs also support `alias` (string) for matching model result keys by alternative names
118
146
  - `name`* - Name of the output
119
147
  - `type`* - Type. Possible types:
120
148
  - `file` - File output (not displayer, but downloaded)
@@ -129,15 +157,35 @@ Extra blocks can be provided for further customization
129
157
  - `interval` (number, default: `0`) - Defines the interval between script evaluations (in milliseconds). If set to `0`, the script is evaluated only once.
130
158
  - Runtime cancellation: call `jsee.cancelCurrentRun()` on the JSEE instance to request stop of the active run. Long-running models should check `ctx.isCancelled()` and return early.
131
159
  - Schema validation - JSEE validates schema structure during initialization and logs warnings for non-critical issues (e.g. unknown input types, malformed aliases)
160
+ - `jsee.download(title)` - Downloads a self-contained HTML file that works offline. All external scripts are inlined and the schema/model/imports are cached. `title` defaults to `'output'`
161
+ - `page` (CLI only) - Page metadata for generated HTML:
162
+ - `title` (string) - Page title
163
+ - `url` (string) - Page URL
164
+ - `ga` (string) - Google Analytics measurement ID (e.g. `"G-XXXXXXXXXX"`)
165
+ - `social` (object) - Social media links: `twitter`, `github`, `facebook`, `linkedin`, `instagram`, `youtube` (values are usernames/handles)
166
+ - `org` (object) - Organization footer: `name`, `url`, `description`
132
167
 
133
168
  JSEE is a reactive branch of [StatSim](https://statsim.com)'s [Port](https://github.com/statsim/port). It's still work in progress. Expect API changes.
134
169
 
135
170
  # CLI
136
- - `--fetch` - Fetches JSEE code, models and their imports and generates a bundled HTML file
171
+ - `--fetch` - Fetches JSEE runtime and bundles `model`/`view`/`render` blocks plus their imports into generated HTML
172
+ - `--runtime <mode|path|url>` - Select runtime source for generated HTML
173
+ - `auto` (default): `inline` when `--fetch` is used, otherwise `cdn` for file output and `local` for dev server mode
174
+ - `local`: use `http://localhost:<port>/dist/...`
175
+ - `cdn`: use jsdelivr runtime URL
176
+ - `inline`: embed runtime code directly in HTML
177
+ - Any other value is used as a custom `<script src="...">` path/URL (e.g. `./node_modules/@jseeio/jsee/dist/jsee.js`)
137
178
  - `--cdn` - Use CDN for models (can be string with a base URL or boolean to infer from package.json). Model urls will be prefixed with the CDN URL. This helps with deployment to static hosts (e.g. GitHub Pages).
138
- - `--execute` - Executes the model code on the server-side.
179
+ - `--execute` - Executes the model code on the server-side
180
+
139
181
  # Server-side execution
140
182
 
183
+ With `--execute` (`-e`), JSEE loads each model's JS file on the server (via `require()`), rewrites the schema to point at a POST endpoint, and starts an Express server. The browser GUI sends inputs to the server, which runs the model and returns results as JSON. This is useful for models that need Node.js APIs or heavy computation that shouldn't run in the browser.
184
+
185
+ ```bash
186
+ jsee schema.json -e -p 3000
187
+ ```
188
+
141
189
  # Changelog
142
190
 
143
191
  See `CHANGELOG.md`.