@zoijs/core 1.2.0 → 1.3.1

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.
package/CHANGELOG.md CHANGED
@@ -1,70 +1,93 @@
1
- # Changelog
2
-
3
- All notable changes to Zoijs are documented here. The format is based on
4
- [Keep a Changelog](https://keepachangelog.com/), and Zoijs follows
5
- [Semantic Versioning](https://semver.org/) (see `VERSIONING.md`).
6
-
7
- ## [1.2.0] — 2026-06-26
8
-
9
- ### Added
10
- - **`effect(fn)`.** A public reactive effect runs a side effect immediately and
11
- re-runs whenever a reactive value it reads changes (automatic dependency
12
- tracking, microtask-batched). The function may return a cleanup that runs before
13
- the next run and on dispose (same convention as a `ref`); `effect` auto-disposes
14
- with its owner (component / list item) and returns `{ dispose }` for early
15
- teardown. This is the public completion of the reactive trio (`createState` /
16
- `computed` / `effect`) — the engine already used it internally for bindings. Use
17
- it for side effects *outside* the view (persist on change, sync `document.title`,
18
- drive a non-Zoijs widget); for on-screen content, keep using a binding
19
- (`${() => …}`). The public surface is now **eight** functions (additive MINOR per
20
- `VERSIONING.md`). See [RFC 0003](docs/rfcs/0003-effect-and-svg.md).
21
-
22
- ### Notes
23
- - The **`svg`** helper considered alongside `effect` was **deferred**: templates
24
- rooted at `<svg>` already render correctly, and only dynamic-SVG *composition* is
25
- affected a minority need. See [RFC 0003](docs/rfcs/0003-effect-and-svg.md) §6.
26
-
27
- ## [1.1.0] 2026-06-25
28
-
29
- ### Added
30
- - **Element refs.** A new `ref` binding gives you the rendered DOM element:
31
- `html\`<input ref=${(el) => el.focus()} />\``. The callback runs once, just after
32
- the element is inserted (so `focus`/`scroll`/`measure`/`canvas` work), is not
33
- reactive, and may return a cleanup function that runs on unmount or list-item
34
- removal. Works inside keyed `each` lists. Non-function values are ignored with a
35
- dev-mode warning and never become a DOM attribute. No new export — `ref` is a
36
- binding semantic, so the seven-function public surface is unchanged (additive
37
- MINOR per `VERSIONING.md`). See [Element refs](docs/concepts/refs.md) and
38
- [RFC 0001](docs/rfcs/0001-element-refs.md).
39
-
40
- ## [1.0.0] 2026-06-24
41
-
42
- First stable release. The public API is frozen at seven functions.
43
-
44
- ### Public API
45
- - `html` — tagged-template renderer (no JSX, no build step).
46
- - `mount(component, target)` `unmount()`.
47
- - `createState(value)` `{ get, set, peek }`.
48
- - `computed(fn)` `{ get, peek }` — lazy, cached, value-gated.
49
- - `each(items, keyFn, renderFn)` — keyed list reconciliation.
50
- - `configure({ dev })` development/production mode.
51
- - `onCleanup(fn)` — teardown for components and list items.
52
-
53
- ### Features
54
- - Fine-grained, direct DOM updates (no Virtual DOM); setup runs once.
55
- - Push-pull reactive core with automatic dependency tracking and microtask batching.
56
- - Owner-scoped cleanup; deterministic teardown on unmount and list-item removal.
57
- - Context-aware template parser (quoted/unquoted/partial/multi-hole attributes,
58
- boolean/URL/aria/data attributes, SVG, nested templates and lists).
59
- - Secure by default: inert text, URL-scheme allowlist (control-char resistant),
60
- `data:` raster-image rules, `on*`/`srcdoc` blocked, function-only handlers,
61
- no `eval`, CSP- and Trusted-Types-friendly.
62
- - TypeScript definitions with generics for state/computed/lists.
63
-
64
- ### Tooling
65
- - 100+ unit/DOM tests (jsdom), real-browser tests on Chromium/Firefox/WebKit
66
- (Playwright), and TypeScript type tests.
67
- - No build step required at any point.
68
-
69
- [1.1.0]: https://github.com/Zoijs/zoijs/releases/tag/core-v1.1.0
70
- [1.0.0]: https://github.com/Zoijs/zoijs/releases/tag/core-v1.0.0
1
+ # Changelog
2
+
3
+ All notable changes to Zoijs are documented here. The format is based on
4
+ [Keep a Changelog](https://keepachangelog.com/), and Zoijs follows
5
+ [Semantic Versioning](https://semver.org/) (see `VERSIONING.md`).
6
+
7
+ ## [1.3.1] — 2026-06-26
8
+
9
+ ### Performance
10
+ - **Minimal DOM moves in `each`.** Keyed-list reconciliation now uses a
11
+ longest-increasing-subsequence pass, so a reorder moves the **fewest nodes
12
+ possible** moving one item across a list is a single DOM move (it could be up
13
+ to N before). No API or behavior change; the final order is identical and reused
14
+ nodes keep their identity (focus, input values, and scroll survive reorders).
15
+ Proven by move-count tests (`tests/lis.test.js`); numbers in `bench/`.
16
+
17
+ ## [1.3.0] 2026-06-26
18
+
19
+ ### Added
20
+ - **`boundary(child, fallback)`.** A render-time error boundary: it renders
21
+ `child`, and if `child` throws **synchronously while building its markup** (a
22
+ setup/render error that would otherwise break the whole `mount`), it disposes the
23
+ partial work so an `effect` created before the throw can't leak — and renders
24
+ `fallback` (a value, or `(error) => value`) instead. Catches synchronous
25
+ setup/render throws only; errors in reactive *updates* are already contained per
26
+ binding, and *async* errors belong to `@zoijs/resource` / `@zoijs/action`'s
27
+ `error()` state. Logs in dev, silent in production. The public surface is now
28
+ **nine** functions (additive MINOR). See [RFC 0004](docs/rfcs/0004-error-boundary.md).
29
+
30
+ ## [1.2.0] 2026-06-26
31
+
32
+ ### Added
33
+ - **`effect(fn)`.** A public reactive effect runs a side effect immediately and
34
+ re-runs whenever a reactive value it reads changes (automatic dependency
35
+ tracking, microtask-batched). The function may return a cleanup that runs before
36
+ the next run and on dispose (same convention as a `ref`); `effect` auto-disposes
37
+ with its owner (component / list item) and returns `{ dispose }` for early
38
+ teardown. This is the public completion of the reactive trio (`createState` /
39
+ `computed` / `effect`) — the engine already used it internally for bindings. Use
40
+ it for side effects *outside* the view (persist on change, sync `document.title`,
41
+ drive a non-Zoijs widget); for on-screen content, keep using a binding
42
+ (`${() => …}`). The public surface is now **eight** functions (additive MINOR per
43
+ `VERSIONING.md`). See [RFC 0003](docs/rfcs/0003-effect-and-svg.md).
44
+
45
+ ### Notes
46
+ - The **`svg`** helper considered alongside `effect` was **deferred**: templates
47
+ rooted at `<svg>` already render correctly, and only dynamic-SVG *composition* is
48
+ affected a minority need. See [RFC 0003](docs/rfcs/0003-effect-and-svg.md) §6.
49
+
50
+ ## [1.1.0]2026-06-25
51
+
52
+ ### Added
53
+ - **Element refs.** A new `ref` binding gives you the rendered DOM element:
54
+ `html\`<input ref=${(el) => el.focus()} />\``. The callback runs once, just after
55
+ the element is inserted (so `focus`/`scroll`/`measure`/`canvas` work), is not
56
+ reactive, and may return a cleanup function that runs on unmount or list-item
57
+ removal. Works inside keyed `each` lists. Non-function values are ignored with a
58
+ dev-mode warning and never become a DOM attribute. No new export — `ref` is a
59
+ binding semantic, so the seven-function public surface is unchanged (additive
60
+ MINOR per `VERSIONING.md`). See [Element refs](docs/concepts/refs.md) and
61
+ [RFC 0001](docs/rfcs/0001-element-refs.md).
62
+
63
+ ## [1.0.0] — 2026-06-24
64
+
65
+ First stable release. The public API is frozen at seven functions.
66
+
67
+ ### Public API
68
+ - `html` — tagged-template renderer (no JSX, no build step).
69
+ - `mount(component, target)` → `unmount()`.
70
+ - `createState(value)` → `{ get, set, peek }`.
71
+ - `computed(fn)` → `{ get, peek }` — lazy, cached, value-gated.
72
+ - `each(items, keyFn, renderFn)` — keyed list reconciliation.
73
+ - `configure({ dev })` — development/production mode.
74
+ - `onCleanup(fn)` — teardown for components and list items.
75
+
76
+ ### Features
77
+ - Fine-grained, direct DOM updates (no Virtual DOM); setup runs once.
78
+ - Push-pull reactive core with automatic dependency tracking and microtask batching.
79
+ - Owner-scoped cleanup; deterministic teardown on unmount and list-item removal.
80
+ - Context-aware template parser (quoted/unquoted/partial/multi-hole attributes,
81
+ boolean/URL/aria/data attributes, SVG, nested templates and lists).
82
+ - Secure by default: inert text, URL-scheme allowlist (control-char resistant),
83
+ `data:` raster-image rules, `on*`/`srcdoc` blocked, function-only handlers,
84
+ no `eval`, CSP- and Trusted-Types-friendly.
85
+ - TypeScript definitions with generics for state/computed/lists.
86
+
87
+ ### Tooling
88
+ - 100+ unit/DOM tests (jsdom), real-browser tests on Chromium/Firefox/WebKit
89
+ (Playwright), and TypeScript type tests.
90
+ - No build step required at any point.
91
+
92
+ [1.1.0]: https://github.com/Zoijs/zoijs/releases/tag/core-v1.1.0
93
+ [1.0.0]: https://github.com/Zoijs/zoijs/releases/tag/core-v1.0.0
package/README.md CHANGED
@@ -1,154 +1,154 @@
1
- # Zoijs
2
-
3
- A lightweight frontend framework you don't have to learn before you use it — **plain HTML, CSS, and JavaScript**, no JSX, no build step, no Virtual DOM.
4
-
5
- **[Documentation](https://zoijs.dev)** · **[GitHub](https://github.com/Zoijs)** · **[npm](https://www.npmjs.com/package/@zoijs/core)**
6
-
7
- ```bash
8
- npm install @zoijs/core
9
- ```
10
-
11
- ```js
12
- import { html, mount, createState } from "@zoijs/core";
13
-
14
- function Counter() {
15
- const count = createState(0);
16
- return html`<button onclick=${() => count.set(count.get() + 1)}>${() => count.get()}</button>`;
17
- }
18
- mount(Counter, "#app");
19
- ```
20
-
21
- ## 📚 Documentation
22
-
23
- **New here? Start at [zoijs.dev](https://zoijs.dev) (or the [docs folder](docs/README.md)) — designed to get you productive in under 30 minutes.**
24
-
25
- - [Installation](docs/installation.md) · [Your First App](docs/first-app.md) · [Core Concepts](docs/concepts/core-concepts.md)
26
- - [Tutorials](docs/README.md#tutorials-build-something) · [API Reference](docs/api-reference.md) · [Examples](docs/examples.md)
27
- - [Troubleshooting](docs/troubleshooting.md) · [FAQ](docs/faq.md) · [Migrating from React/Vue/Solid/Lit/vanilla](docs/README.md#coming-from-another-framework)
28
-
29
- ---
30
-
31
- ## Mission
32
-
33
- Make building modern web applications feel as approachable as writing plain HTML, CSS, and JavaScript — so that any developer, on day one, can ship real software without first learning a framework.
34
-
35
- The framework should disappear into the skills developers already have. The whole mental model is three verbs: **write a function that returns `html`, put `createState` values in it, `mount` it.**
36
-
37
- ## Goals
38
-
39
- - **Beginner-friendly** — concepts you already know from vanilla JS/HTML/CSS.
40
- - **No build step** — runs from a single `<script type="module">`.
41
- - **No Virtual DOM** — fine-grained, direct DOM updates; only what changed is touched.
42
- - **Minimal runtime** — the browser does the heavy lifting (native `<template>`, `cloneNode`, events).
43
- - **Secure by default** — inert text rendering, URL-scheme guards, handler references (never strings), no `eval`.
44
- - **Small & readable** — a junior developer can read the source.
45
-
46
- See [`docs/Phase-1-MVP-Spec.md`](docs/Phase-1-MVP-Spec.md) for the full specification.
47
-
48
- ## Setup
49
-
50
- No build step is required — the framework is plain ES modules.
51
-
52
- ```bash
53
- # from the framework/ directory
54
-
55
- # run the counter example (serves the project root over http so ES modules resolve)
56
- npm run dev
57
- # then open: http://localhost:7310/examples/counter/ (keep the trailing slash)
58
-
59
- # run the tests (DOM tests run automatically via jsdom)
60
- npm test
61
- ```
62
-
63
- > Tips:
64
- > - ES module imports need to be served over `http://`, not opened as a `file://` path. `npm run dev` handles that.
65
- > - Use the **trailing slash** on the example URL (`/examples/counter/`). Without it, some static servers resolve `./app.js` against the wrong directory and the app won't load.
66
-
67
- ## Testing
68
-
69
- | Command | What it runs |
70
- |---|---|
71
- | `npm test` | Unit + DOM tests via jsdom (fast, no browser) |
72
- | `npm run test:unit` | Pure-logic tests only (no DOM) |
73
- | `npm run test:types` | TypeScript type-checks (`tsc --noEmit`) |
74
- | `npm run test:browser` | Real-browser tests in Chromium, Firefox, WebKit (Playwright) |
75
-
76
- Browser tests live in `browser-tests/` and run the example apps plus framework regressions against real engines. First-time setup downloads the browsers:
77
-
78
- ```bash
79
- npm install
80
- npx playwright install chromium firefox webkit
81
- npm run test:browser
82
- ```
83
-
84
- Playwright starts a static server automatically (`npx serve` on port 7310) — still no build step.
85
-
86
- ## Browser support
87
-
88
- Modern evergreen browsers. Verified automatically (Playwright) in:
89
-
90
- | Browser | Engine | Status |
91
- |---|---|---|
92
- | Chrome / Edge | Chromium | ✅ tested |
93
- | Firefox | Gecko | ✅ tested |
94
- | Safari | WebKit | ✅ tested |
95
-
96
- Relies on baseline-modern platform APIs: ES modules, `<template>`, `TreeWalker`, `Proxy`, `queueMicrotask`, `replaceChildren`, `addEventListener`, `setAttributeNS`. No IE support, no transpilation, no polyfills.
97
-
98
- ## Public API
99
-
100
- ```js
101
- import { html, mount, createState, computed, each, configure, onCleanup } from "@zoijs/core";
102
- ```
103
-
104
- - `html` — tagged template; parsed once, cached.
105
- - `mount(component, target)` — render a component; returns `unmount()`.
106
- - `createState(value)` — a reactive value (`get` / `set` / `peek`).
107
- - `computed(fn)` — a lazy, cached, **value-gated** derived value (`get` / `peek`).
108
- - `each(itemsFn, keyFn, renderFn)` — keyed list rendering (reuse / move / remove nodes).
109
- - `configure({ dev })` — toggle development warnings (default `dev: true`).
110
- - `onCleanup(fn)` — register teardown for a component or list item (timers, subscriptions).
111
-
112
- See the [Documentation site](docs/README.md) for the full guide, tutorials, and API reference.
113
-
114
- **TypeScript:** ships type definitions ([`src/index.d.ts`](src/index.d.ts)) for autocomplete and optional type-checking — JS-first, no build step required. `createState<T>`, `computed<T>`, and `each<T>` are generic. Type-check with `npm run test:types`.
115
-
116
- ## What's built
117
-
118
- - Fine-grained text/attribute bindings — `${() => state.get()}` updates one node in place; setup runs once (no re-render).
119
- - Native events, secure-by-default rendering (inert text, URL-scheme guards, no `eval`).
120
- - `computed()` derived values — lazy, cached, nestable, and **value-gated** (unchanged results don't wake downstream).
121
- - `each()` keyed list reconciliation — preserves focus / input / scroll on reorder.
122
- - Microtask batching, push-pull dependency tracking, **owner-scoped cleanup** (unmount and removed items dispose their subscriptions).
123
- - Production mode via `configure({ dev: false })` — no build step.
124
- - Safety: self-triggering effects are warned + stopped; a throwing binding doesn't break others.
125
-
126
- **Out of scope (by design):** router, CLI, plugins, SSR, global store, TypeScript-first setup, Virtual DOM.
127
-
128
- ## Project Structure
129
-
130
- ```
131
- framework/
132
- package.json
133
- README.md
134
- src/
135
- core/
136
- html.js # html() — parse template into a cached blueprint
137
- mount.js # mount() — entry point; instantiate + attach + cleanup
138
- renderer.js # internal: bind dynamic slots, apply fine-grained updates
139
- reactivity/
140
- state.js # createState() + internal dependency tracking
141
- utils/
142
- dom.js # small native-DOM helpers
143
- security.js # escaping, URL-scheme allowlist, attribute-name guards
144
- index.js # public entry — re-exports html, mount, createState
145
- examples/
146
- counter/ # the first working app
147
- tests/ # basic unit tests (node --test)
148
- docs/
149
- Phase-1-MVP-Spec.md
150
- ```
151
-
152
- ## License
153
-
154
- MIT
1
+ # Zoijs
2
+
3
+ A lightweight frontend framework you don't have to learn before you use it — **plain HTML, CSS, and JavaScript**, no JSX, no build step, no Virtual DOM.
4
+
5
+ **[Documentation](https://zoijs.dev)** · **[GitHub](https://github.com/Zoijs)** · **[npm](https://www.npmjs.com/package/@zoijs/core)**
6
+
7
+ ```bash
8
+ npm install @zoijs/core
9
+ ```
10
+
11
+ ```js
12
+ import { html, mount, createState } from "@zoijs/core";
13
+
14
+ function Counter() {
15
+ const count = createState(0);
16
+ return html`<button onclick=${() => count.set(count.get() + 1)}>${() => count.get()}</button>`;
17
+ }
18
+ mount(Counter, "#app");
19
+ ```
20
+
21
+ ## 📚 Documentation
22
+
23
+ **New here? Start at [zoijs.dev](https://zoijs.dev) (or the [docs folder](docs/README.md)) — designed to get you productive in under 30 minutes.**
24
+
25
+ - [Installation](docs/installation.md) · [Your First App](docs/first-app.md) · [Core Concepts](docs/concepts/core-concepts.md)
26
+ - [Tutorials](docs/README.md#tutorials-build-something) · [API Reference](docs/api-reference.md) · [Examples](docs/examples.md)
27
+ - [Troubleshooting](docs/troubleshooting.md) · [FAQ](docs/faq.md) · [Migrating from React/Vue/Solid/Lit/vanilla](docs/README.md#coming-from-another-framework)
28
+
29
+ ---
30
+
31
+ ## Mission
32
+
33
+ Make building modern web applications feel as approachable as writing plain HTML, CSS, and JavaScript — so that any developer, on day one, can ship real software without first learning a framework.
34
+
35
+ The framework should disappear into the skills developers already have. The whole mental model is three verbs: **write a function that returns `html`, put `createState` values in it, `mount` it.**
36
+
37
+ ## Goals
38
+
39
+ - **Beginner-friendly** — concepts you already know from vanilla JS/HTML/CSS.
40
+ - **No build step** — runs from a single `<script type="module">`.
41
+ - **No Virtual DOM** — fine-grained, direct DOM updates; only what changed is touched.
42
+ - **Minimal runtime** — the browser does the heavy lifting (native `<template>`, `cloneNode`, events).
43
+ - **Secure by default** — inert text rendering, URL-scheme guards, handler references (never strings), no `eval`.
44
+ - **Small & readable** — a junior developer can read the source.
45
+
46
+ See [`docs/Phase-1-MVP-Spec.md`](docs/Phase-1-MVP-Spec.md) for the full specification.
47
+
48
+ ## Setup
49
+
50
+ No build step is required — the framework is plain ES modules.
51
+
52
+ ```bash
53
+ # from the framework/ directory
54
+
55
+ # run the counter example (serves the project root over http so ES modules resolve)
56
+ npm run dev
57
+ # then open: http://localhost:7310/examples/counter/ (keep the trailing slash)
58
+
59
+ # run the tests (DOM tests run automatically via jsdom)
60
+ npm test
61
+ ```
62
+
63
+ > Tips:
64
+ > - ES module imports need to be served over `http://`, not opened as a `file://` path. `npm run dev` handles that.
65
+ > - Use the **trailing slash** on the example URL (`/examples/counter/`). Without it, some static servers resolve `./app.js` against the wrong directory and the app won't load.
66
+
67
+ ## Testing
68
+
69
+ | Command | What it runs |
70
+ |---|---|
71
+ | `npm test` | Unit + DOM tests via jsdom (fast, no browser) |
72
+ | `npm run test:unit` | Pure-logic tests only (no DOM) |
73
+ | `npm run test:types` | TypeScript type-checks (`tsc --noEmit`) |
74
+ | `npm run test:browser` | Real-browser tests in Chromium, Firefox, WebKit (Playwright) |
75
+
76
+ Browser tests live in `browser-tests/` and run the example apps plus framework regressions against real engines. First-time setup downloads the browsers:
77
+
78
+ ```bash
79
+ npm install
80
+ npx playwright install chromium firefox webkit
81
+ npm run test:browser
82
+ ```
83
+
84
+ Playwright starts a static server automatically (`npx serve` on port 7310) — still no build step.
85
+
86
+ ## Browser support
87
+
88
+ Modern evergreen browsers. Verified automatically (Playwright) in:
89
+
90
+ | Browser | Engine | Status |
91
+ |---|---|---|
92
+ | Chrome / Edge | Chromium | ✅ tested |
93
+ | Firefox | Gecko | ✅ tested |
94
+ | Safari | WebKit | ✅ tested |
95
+
96
+ Relies on baseline-modern platform APIs: ES modules, `<template>`, `TreeWalker`, `Proxy`, `queueMicrotask`, `replaceChildren`, `addEventListener`, `setAttributeNS`. No IE support, no transpilation, no polyfills.
97
+
98
+ ## Public API
99
+
100
+ ```js
101
+ import { html, mount, createState, computed, each, configure, onCleanup } from "@zoijs/core";
102
+ ```
103
+
104
+ - `html` — tagged template; parsed once, cached.
105
+ - `mount(component, target)` — render a component; returns `unmount()`.
106
+ - `createState(value)` — a reactive value (`get` / `set` / `peek`).
107
+ - `computed(fn)` — a lazy, cached, **value-gated** derived value (`get` / `peek`).
108
+ - `each(itemsFn, keyFn, renderFn)` — keyed list rendering (reuse / move / remove nodes).
109
+ - `configure({ dev })` — toggle development warnings (default `dev: true`).
110
+ - `onCleanup(fn)` — register teardown for a component or list item (timers, subscriptions).
111
+
112
+ See the [Documentation site](docs/README.md) for the full guide, tutorials, and API reference.
113
+
114
+ **TypeScript:** ships type definitions ([`src/index.d.ts`](src/index.d.ts)) for autocomplete and optional type-checking — JS-first, no build step required. `createState<T>`, `computed<T>`, and `each<T>` are generic. Type-check with `npm run test:types`.
115
+
116
+ ## What's built
117
+
118
+ - Fine-grained text/attribute bindings — `${() => state.get()}` updates one node in place; setup runs once (no re-render).
119
+ - Native events, secure-by-default rendering (inert text, URL-scheme guards, no `eval`).
120
+ - `computed()` derived values — lazy, cached, nestable, and **value-gated** (unchanged results don't wake downstream).
121
+ - `each()` keyed list reconciliation — preserves focus / input / scroll on reorder.
122
+ - Microtask batching, push-pull dependency tracking, **owner-scoped cleanup** (unmount and removed items dispose their subscriptions).
123
+ - Production mode via `configure({ dev: false })` — no build step.
124
+ - Safety: self-triggering effects are warned + stopped; a throwing binding doesn't break others.
125
+
126
+ **Out of scope (by design):** router, CLI, plugins, SSR, global store, TypeScript-first setup, Virtual DOM.
127
+
128
+ ## Project Structure
129
+
130
+ ```
131
+ framework/
132
+ package.json
133
+ README.md
134
+ src/
135
+ core/
136
+ html.js # html() — parse template into a cached blueprint
137
+ mount.js # mount() — entry point; instantiate + attach + cleanup
138
+ renderer.js # internal: bind dynamic slots, apply fine-grained updates
139
+ reactivity/
140
+ state.js # createState() + internal dependency tracking
141
+ utils/
142
+ dom.js # small native-DOM helpers
143
+ security.js # escaping, URL-scheme allowlist, attribute-name guards
144
+ index.js # public entry — re-exports html, mount, createState
145
+ examples/
146
+ counter/ # the first working app
147
+ tests/ # basic unit tests (node --test)
148
+ docs/
149
+ Phase-1-MVP-Spec.md
150
+ ```
151
+
152
+ ## License
153
+
154
+ MIT
package/package.json CHANGED
@@ -1,63 +1,63 @@
1
- {
2
- "name": "@zoijs/core",
3
- "version": "1.2.0",
4
- "description": "Zoijs — a beginner-friendly, no-build, no-Virtual-DOM frontend framework. Plain HTML, CSS, and JavaScript.",
5
- "type": "module",
6
- "main": "src/index.js",
7
- "types": "src/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./src/index.d.ts",
11
- "default": "./src/index.js"
12
- }
13
- },
14
- "files": [
15
- "src",
16
- "README.md",
17
- "LICENSE",
18
- "CHANGELOG.md"
19
- ],
20
- "sideEffects": false,
21
- "engines": {
22
- "node": ">=18"
23
- },
24
- "author": "Zoijs contributors (https://zoijs.dev)",
25
- "license": "MIT",
26
- "homepage": "https://zoijs.dev",
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/Zoijs/zoijs.git",
30
- "directory": "framework"
31
- },
32
- "bugs": {
33
- "url": "https://github.com/Zoijs/zoijs/issues"
34
- },
35
- "keywords": [
36
- "zoijs",
37
- "framework",
38
- "frontend",
39
- "ui",
40
- "reactive",
41
- "reactivity",
42
- "signals",
43
- "no-build",
44
- "no-jsx",
45
- "no-virtual-dom",
46
- "fine-grained",
47
- "beginner-friendly",
48
- "html",
49
- "spa"
50
- ],
51
- "scripts": {
52
- "test": "node --test --import ./tests/setup-dom.js",
53
- "test:unit": "node --test",
54
- "test:types": "tsc --noEmit -p tsconfig.json",
55
- "test:browser": "playwright test",
56
- "dev": "npx serve -l 7310 ."
57
- },
58
- "devDependencies": {
59
- "@playwright/test": "^1.61.1",
60
- "jsdom": "^29.1.1",
61
- "typescript": "^5.9.3"
62
- }
63
- }
1
+ {
2
+ "name": "@zoijs/core",
3
+ "version": "1.3.1",
4
+ "description": "Zoijs — a beginner-friendly, no-build, no-Virtual-DOM frontend framework. Plain HTML, CSS, and JavaScript.",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "types": "src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./src/index.d.ts",
11
+ "default": "./src/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "src",
16
+ "README.md",
17
+ "LICENSE",
18
+ "CHANGELOG.md"
19
+ ],
20
+ "sideEffects": false,
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "author": "Zoijs contributors (https://zoijs.dev)",
25
+ "license": "MIT",
26
+ "homepage": "https://zoijs.dev",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/Zoijs/zoijs.git",
30
+ "directory": "framework"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/Zoijs/zoijs/issues"
34
+ },
35
+ "keywords": [
36
+ "zoijs",
37
+ "framework",
38
+ "frontend",
39
+ "ui",
40
+ "reactive",
41
+ "reactivity",
42
+ "signals",
43
+ "no-build",
44
+ "no-jsx",
45
+ "no-virtual-dom",
46
+ "fine-grained",
47
+ "beginner-friendly",
48
+ "html",
49
+ "spa"
50
+ ],
51
+ "scripts": {
52
+ "test": "node --test --import ./tests/setup-dom.js",
53
+ "test:unit": "node --test",
54
+ "test:types": "tsc --noEmit -p tsconfig.json",
55
+ "test:browser": "playwright test",
56
+ "dev": "npx serve -l 7310 ."
57
+ },
58
+ "devDependencies": {
59
+ "@playwright/test": "^1.61.1",
60
+ "jsdom": "^29.1.1",
61
+ "typescript": "^5.9.3"
62
+ }
63
+ }
@@ -0,0 +1,34 @@
1
+ // boundary.js — render-time error containment (RFC 0004).
2
+ //
3
+ // boundary(child, fallback) renders `child`; if it throws SYNCHRONOUSLY while
4
+ // building its markup (a setup/render throw that would otherwise break the whole
5
+ // mount), the partial work is torn down and `fallback(error)` is rendered instead.
6
+ //
7
+ // Errors in reactive UPDATES are already contained per-binding by the core; async
8
+ // errors belong to @zoijs/resource / @zoijs/action. This catches the one
9
+ // remaining case — the synchronous setup/render throw.
10
+
11
+ import { createOwner, runWithOwner, disposeOwner } from "../reactivity/owner.js";
12
+ import { isDev } from "../reactivity/env.js";
13
+
14
+ /**
15
+ * @template C, F
16
+ * @param {(() => C) | C} child a component (or value) to render
17
+ * @param {((error: unknown) => F) | F} fallback a value, or (error) => value, shown if child throws
18
+ * @returns {C | F} the child's result, or the fallback's, for a template slot
19
+ */
20
+ export function boundary(child, fallback) {
21
+ // Run setup in a child scope so anything it creates before a throw (notably an
22
+ // effect, which runs immediately) can be disposed — no zombies. On success the
23
+ // scope nests under the surrounding owner and is disposed with it.
24
+ const owner = createOwner();
25
+ try {
26
+ return runWithOwner(owner, () => (typeof child === "function" ? child() : child));
27
+ } catch (err) {
28
+ disposeOwner(owner);
29
+ if (isDev()) {
30
+ console.error("Zoijs: boundary caught an error during render; showing fallback.", err);
31
+ }
32
+ return typeof fallback === "function" ? fallback(err) : fallback;
33
+ }
34
+ }