@jseeio/jsee 0.4.0 → 0.4.2

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.
@@ -7,7 +7,9 @@
7
7
  "Bash(find:*)",
8
8
  "Bash(npx eslint:*)",
9
9
  "Bash(npm run test:python:*)",
10
- "Bash(npm run build:*)"
10
+ "Bash(npm run build:*)",
11
+ "Bash(npx webpack:*)",
12
+ "Bash(git -C /home/anton/projects/jseeio/jsee diff README.md)"
11
13
  ]
12
14
  }
13
15
  }
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Changelog
2
2
 
3
- ## 0.4.0
3
+ ## 0.4.1
4
4
  ### Bug fixes:
5
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
6
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
@@ -9,6 +9,7 @@
9
9
  - Move `showdown-katex` and `katex` to runtime `dependencies` so `npx jsee` works without dev installs
10
10
  - Fix `--fetch` bundling to include `schema.view` and `schema.render` blocks in addition to `schema.model`
11
11
  - Fix `--fetch` import resolution for local relative JS imports and support object import entries (`{ url, ... }`)
12
+ - Fix `--fetch` bundling for bare-relative imports (e.g. `dist/core.js`, `css/app.css`) — use filesystem existence check instead of prefix heuristics, and fix `data-src` key mismatch by keeping raw import paths so `loadFromDOM` finds bundled code at runtime
12
13
  - Fix CLI output path handling for absolute/relative `--outputs` values and remove duplicate final HTML write
13
14
  - Fix `download()` method referencing undeclared `env` variable — now correctly uses `this`
14
15
  - Fix `outputAsync()` referencing undeclared `delay` — now correctly uses `utils.delay`
package/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # JSEE
1
+ # JSEE. Computational Documents for the Web
2
+
3
+ Turn code into a shareable, offline-capable web app. Describe inputs/outputs once (JSON), run JS/Python in a Worker or via API, and ship as a single HTML file.
2
4
 
3
5
  Minimal example:
4
6
  ```html
@@ -35,59 +37,83 @@ npx @jseeio/jsee schema.json -o app.html
35
37
 
36
38
  Run `jsee --help` for all CLI options.
37
39
 
38
- ## JavaScript Execution Environment
39
-
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).
41
-
42
40
  ## Inputs and outputs
43
41
 
44
42
  JSEE works best with functional tasks and one-way flow from inputs to outputs (i.e., inputs → processing → outputs). You can also extend it to more complex scenarios, like inputs → preprocessing → updated inputs → processing → outputs or inputs → processing → outputs → custom renderer. Even though many computational tasks have a functional form, some problems require more complex interactions between a user interface and code. For such cases, JSEE is probably too constrained. That makes it not as universal as R's [shiny](https://shiny.rstudio.com/) or Python's [streamlit](https://streamlit.io/).
45
43
 
46
44
  ## How it works
47
45
 
48
- Instead of dealing with raw HTML tags, input elements or charts, JSEE makes it possible to work on a higher level and describe only `inputs` and `outputs` in a JSON schema. It similarly handles code execution, by checking the `model` part of that JSON object. Those three parts are the most important for the future app. In many cases JSEE can generate a new schema automatically by analyzing the code alone. For example, it's possible to extract a list function arguments and use them as model inputs. When JSEE receives the JSON schema it creates a new Vue app based on it and initializes a new worker for code execution. The final app can take inputs from a user, parse files, load needed libraries, orchestrate communication between code and GUI, use Web Workers to run everything smoothly
46
+ JSEE turns a JSON schema into a working web app. Instead of writing HTML, event handlers and output renderers, you describe `inputs`, `outputs` and a `model` in a single JSON object. JSEE reads that schema, generates a reactive Vue 3 GUI, loads dependencies, and runs your code in a Web Worker (or on the main thread, or as an API call). In many cases it can build the schema automatically by analysing a function's arguments.
49
47
 
50
48
  ```text
51
- Schema Model Render*
52
- DEV -► json js/py js
53
- | | |
54
- ┌──▼────────▼────────▼───┐
55
- new JSEE (...)
56
- └────────────────────────┘
57
- | |
58
- ┌──▼──┐ ┌──────▼─────┐ ◄~ tf.js
59
- USER ◄-► │ GUI │ ◄-► │ Model │ ◄~ pyodide
60
- └─────┘ └────────────┘ ◄~ wasm
61
- Vue³ WebWorker*
49
+ Schema Model View/Render* Imports*
50
+ DEV -► json js/py js js/css
51
+ | | | |
52
+ ┌──▼───────▼──────────▼────────────▼──┐
53
+ new JSEE(schema)
54
+ │ ┌──────────────┐ ┌──────────────┐ │
55
+ │ │ Import loader │ │Schema parser │ │
56
+ │ └──────┬───────┘ └──────┬───────┘
57
+ └─────────┼─────────────────┼─────────┘
58
+ | |
59
+ ┌──────▼──┐ ┌──────▼──────┐ ◄~ pyodide
60
+ USER ◄-► │ GUI │ ◄--► │ Pipeline │ ◄~ tf.js
61
+ │ Vue 3 │ │ Model(s) │ ◄~ wasm
62
+ └─────────┘ └─────────────┘
63
+ WebWorker*
62
64
 
63
65
  * - optional
64
66
  ```
65
67
 
68
+ ### Initialization
69
+
70
+ 1. **Schema** is loaded from a URL, DOM element, function, or JS object
71
+ 2. **Validation** checks schema structure and logs warnings for issues
72
+ 3. **Imports** are resolved — JS scripts are loaded in sequence, CSS files are injected as `<link>` tags. In the browser, relative paths resolve against the page URL. In `--fetch` mode, the CLI checks the local filesystem first
73
+ 4. **Models** initialize — code is loaded from `url`, `code`, or a hidden DOM cache (`data-src` elements used by `--fetch` bundles and `download()`)
74
+ 5. **GUI** is created — a Vue 3 app with reactive inputs, output cards, run/stop buttons and progress bar
75
+ 6. **URL params** are applied — query string values (`?name=value`) set matching inputs, including `alias` matches. File URL params auto-load on init
76
+
77
+ ### Execution
78
+
79
+ - **Run**: user clicks Run (or autorun/reactive triggers it). Inputs are collected and sent to the model
80
+ - **Pipeline**: when `model` is an array, models execute sequentially — each receives the merged output of the previous one. Return `{ stop: true }` to halt early
81
+ - **Worker context**: worker models receive a runtime context (`ctx`) with `ctx.log()`, `ctx.progress(value)` (0–100 or `null` for indeterminate), and `ctx.isCancelled()` for cooperative cancellation
82
+ - **Cancellation**: `jsee.cancelCurrentRun()` or the Stop button sets a flag that workers and stream readers check
83
+ - **Output**: results flow to the output cards — JSON trees, HTML, SVG, code blocks, or custom render functions
84
+
85
+ ### Offline & bundling
86
+
87
+ - **`jsee --fetch`** bundles everything into a single HTML file: the JSEE runtime, model/view/render code, and all imports are stored in hidden `<script data-src="...">` elements. The result works with no network
88
+ - **`jsee.download(title)`** does the same at runtime — exports the current app as a self-contained HTML file
89
+
90
+ ## Schema blocks
91
+
66
92
  JSEE takes a schema object that contains three main blocks:
67
93
 
68
- - `model` - describes a model/script/API (its location, is it a function or class, should it be called automatically on every GUI change or not)
69
- - `inputs` - list of inputs and their descriptions
70
- - `outputs` - list of outputs and their descriptions
94
+ - `model` describes a model/script/API (its location, is it a function or class, should it be called automatically on every GUI change or not)
95
+ - `inputs` list of inputs and their descriptions
96
+ - `outputs` list of outputs and their descriptions
71
97
 
72
- Extra blocks can be provided for further customization
98
+ Extra blocks can be provided for further customization:
73
99
 
74
- - `render` - visualization part (optional). Defines custom rendering code.
75
- - `design` - overall appearance (optional). Defines how the app looks overwriting defaults.
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.
100
+ - `render` / `view` — visualization part (optional). Defines custom rendering code
101
+ - `design` overall appearance (optional). Defines how the app looks overwriting defaults
102
+ - `imports` 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. In the browser, relative paths (e.g. `dist/core.js`, `./lib.js`) resolve against the page URL. With `--fetch`, the CLI resolves imports by checking the local filesystem first — if a file exists on disk it is bundled; otherwise it is fetched from CDN
77
103
 
78
104
  ```json
79
105
  "imports": [
80
106
  "https://cdn.jsdelivr.net/npm/@tensorflow/tfjs",
81
- "https://cdn.jsdelivr.net/pyodide/v0.17.0/full/pyodide.js",
107
+ "dist/my-lib.js",
82
108
  "styles/app.css"
83
109
  ]
84
110
  ```
85
111
 
86
- - `examples` - a list of examples (optional). Defines a list of examples that can be used to overwrite inputs.
112
+ - `examples` a list of examples (optional). Defines a list of examples that can be used to overwrite inputs
87
113
 
88
114
  ```json
89
115
  "examples": [
90
- { "input": "My name is Anton and I am" },
116
+ { "input": "My name is Anton and I am" }
91
117
  ]
92
118
  ```
93
119
 
@@ -97,11 +123,11 @@ Extra blocks can be provided for further customization
97
123
 
98
124
  ## Schema
99
125
 
100
- - `model` - Contains main parameters of the model/script
101
- - `url` (string) - URL of a JS/Python script or POST/GET API
102
- - `code` (function) - It's possible to pass code directly to JSEE instead of using an URL
103
- - `name` (string) - Name of the executed object. Default value is taken from `url` or `code`
104
- - `type` (string, default - `function`) - What kind of script is loaded. Influences how the code is initializated. Possible values:
126
+ - `model` Contains main parameters of the model/script
127
+ - `url` (string) URL of a JS/Python script or POST/GET API
128
+ - `code` (function) It's possible to pass code directly to JSEE instead of using an URL
129
+ - `name` (string) Name of the executed object. Default value is taken from `url` or `code`
130
+ - `type` (string, default `function`) What kind of script is loaded. Influences how the code is initialized. Possible values:
105
131
  - `function`
106
132
  - `class`
107
133
  - `async-function`
@@ -109,74 +135,82 @@ Extra blocks can be provided for further customization
109
135
  - `py`
110
136
  - `tf`
111
137
  - Inference note: when `code` is present (including code loaded from a `.js` URL), JSEE treats the model as `function` unless `type` is explicitly set
112
- - `method` (string) - If `type` is `class`, `method` defines the name of the class method to call during evaluation
113
- - `container` (string) - How input values are passed to the function/method:
114
- - `object` (default) - Pass inputs wrapped in an object, i.e. `{'x': 1, 'y': 2}`
115
- - `args` - Pass inputs as separate arguments
116
- - `worker` (boolean) - If `true`, JSEE initializes a Web Worker to run the script
138
+ - `method` (string) If `type` is `class`, `method` defines the name of the class method to call during evaluation
139
+ - `container` (string) How input values are passed to the function/method:
140
+ - `object` (default) Pass inputs wrapped in an object, i.e. `{'x': 1, 'y': 2}`
141
+ - `args` Pass inputs as separate arguments
142
+ - `worker` (boolean) If `true`, JSEE initializes a Web Worker to run the script
117
143
  - For `container: 'object'`, model functions receive a second runtime context argument (`ctx`)
118
- - `ctx.log(...args)` - Write runtime logs
119
- - `ctx.progress(value)` - Report progress (`0..100` or `null` for indeterminate)
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
144
+ - `ctx.log(...args)` Write runtime logs
145
+ - `ctx.progress(value)` Report progress (`0..100` or `null` for indeterminate)
146
+ - `ctx.isCancelled()` Check cooperative cancellation state (useful in long loops/streams)
147
+ - `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
148
+ - `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
149
  - `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
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.
125
- - `design` - Design parameters
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.
127
- - `framework` - Design framework to use. If a JavaScript object with the same name is present in a global context, JSEE loads it too (using Vue's `use` method).
128
- - `inputs` - Inputs definition.
129
- - `name`* - Name of the input
130
- - `type`* - Type. Possible types:
131
- - `int`, `float` or `number` - Number
132
- - `string` - String
133
- - `text` - Textarea
134
- - `checkbox` or `bool` - Checkbox
135
- - `select` or `categorical` - Select (one of many `options`)
136
- - `file` - File Input
137
- - `action` or `button` - Button (its `name` will be passed as a `caller` to the model)
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)
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)
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.
150
+ - `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
151
+ - `design` Design parameters
152
+ - `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
153
+ - `framework` Design framework to use. If a JavaScript object with the same name is present in a global context, JSEE loads it too (using Vue's `use` method)
154
+ - `inputs` Inputs definition
155
+ - `name`* Name of the input
156
+ - `type`* Type. Possible types:
157
+ - `int`, `float` or `number` Number
158
+ - `string` String
159
+ - `text` Textarea
160
+ - `checkbox` or `bool` Checkbox
161
+ - `select` or `categorical` Select (one of many `options`)
162
+ - `file` File Input
163
+ - `action` or `button` Button (its `name` will be passed as a `caller` to the model)
164
+ - `default` Default value
165
+ - `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
166
+ - `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
167
+ - `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)
168
+ - `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)
169
+ - `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
170
  - 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
146
- - `name`* - Name of the output
147
- - `type`* - Type. Possible types:
148
- - `file` - File output (not displayer, but downloaded)
149
- - `object` - JavaScript Object
150
- - `html` or `svg` - SVG element
151
- - `code` - Code block
152
- - `function` - Render function. Rather than returning a value, a model returns a function that JSEE will call passing the container element.
153
- - `blank` - Blank block (can be alternative to `function` and useful for custom renderers)
154
- - `examples` - List of examples
155
- - `autorun` (boolean, default: `false`) - Run the model automatically on first load
156
- - `reactive` (boolean, default: `false`) - Re-run the model on any input change (debounced). For per-input reactivity, set `reactive: true` on individual inputs instead
157
- - `interval` (number, default: `0`) - Defines the interval between script evaluations (in milliseconds). If set to `0`, the script is evaluated only once.
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.
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`
171
+ - `outputs` Outputs definition. Outputs also support `alias` (string) for matching model result keys by alternative names
172
+ - `name`* Name of the output
173
+ - `type`* Type. Possible types:
174
+ - `file` File output (not displayer, but downloaded)
175
+ - `object` JavaScript Object
176
+ - `html` or `svg` SVG element
177
+ - `code` Code block
178
+ - `function` Render function. Rather than returning a value, a model returns a function that JSEE will call passing the container element
179
+ - `blank` Blank block (can be alternative to `function` and useful for custom renderers)
180
+ - `examples` List of examples
181
+ - `autorun` (boolean, default: `false`) Run the model automatically on first load
182
+ - `reactive` (boolean, default: `false`) Re-run the model on any input change (debounced). For per-input reactivity, set `reactive: true` on individual inputs instead
183
+ - `interval` (number, default: `0`) Defines the interval between script evaluations (in milliseconds). If set to `0`, the script is evaluated only once
184
+ - 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
185
+ - Schema validation JSEE validates schema structure during initialization and logs warnings for non-critical issues (e.g. unknown input types, malformed aliases)
186
+ - `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'`
187
+ - `page` (CLI only) Page metadata for generated HTML:
188
+ - `title` (string) Page title
189
+ - `url` (string) Page URL
190
+ - `ga` (string) Google Analytics measurement ID (e.g. `"G-XXXXXXXXXX"`)
191
+ - `social` (object) Social media links: `twitter`, `github`, `facebook`, `linkedin`, `instagram`, `youtube` (values are usernames/handles)
192
+ - `org` (object) Organization footer: `name`, `url`, `description`
167
193
 
168
194
  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.
169
195
 
170
196
  # CLI
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
197
+
198
+ - `--inputs`, `-i` Input schema JSON file (default: `schema.json`)
199
+ - `--outputs`, `-o` — Output file path(s), comma-separated (HTML, JSON, or both)
200
+ - `--description`, `-d` — Markdown file to include as app description
201
+ - `--port`, `-p` — Dev server port (default: `3000`)
202
+ - `--version`, `-v` — JSEE runtime version (`latest`, `dev`, or semver)
203
+ - `--fetch`, `-f` — Bundle everything into a single offline HTML: fetches the JSEE runtime, reads `model`/`view`/`render` code from disk, and resolves imports. Local files are detected by checking the filesystem (so bare paths like `dist/core.js` work alongside `./relative.js`); anything not found locally is fetched from CDN. All code is stored in hidden `<script data-src="...">` elements
204
+ - `--runtime`, `-r` — Select runtime source for generated HTML:
173
205
  - `auto` (default): `inline` when `--fetch` is used, otherwise `cdn` for file output and `local` for dev server mode
174
206
  - `local`: use `http://localhost:<port>/dist/...`
175
207
  - `cdn`: use jsdelivr runtime URL
176
208
  - `inline`: embed runtime code directly in HTML
177
209
  - Any other value is used as a custom `<script src="...">` path/URL (e.g. `./node_modules/@jseeio/jsee/dist/jsee.js`)
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).
179
- - `--execute` - Executes the model code on the server-side
210
+ - `--cdn`, `-c` Rewrite model URLs for CDN deployment (can be a base URL string or boolean to infer from `package.json`)
211
+ - `--execute`, `-e` Run models server-side (see below)
212
+ - `--verbose` — Enable verbose logging
213
+ - `--help`, `-h` — Show usage info
180
214
 
181
215
  # Server-side execution
182
216