clarusjs 0.1.0 → 0.3.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.
@@ -0,0 +1,56 @@
1
+ // Attribute values, shared by server rendering and browser updates so both apply the same rules.
2
+ // Attributes whose value is a URL.
3
+ const URL_ATTRS = new Set([
4
+ 'href', 'src', 'action', 'formaction', 'poster', 'cite', 'background', 'xlink:href',
5
+ 'data', 'codebase', 'ping', 'manifest', 'longdesc',
6
+ ]);
7
+ // SVG animation values can set an href, but only on animation elements; elsewhere these are ordinary data.
8
+ const ANIMATION_ATTRS = new Set(['to', 'from', 'values', 'by']);
9
+ const ANIMATION_ELEMENTS = new Set(['animate', 'set', 'animatemotion', 'animatetransform']);
10
+ // Attributes that load an image, where a raster data: URL is fine.
11
+ const IMAGE_ATTRS = new Set(['src', 'srcset', 'poster']);
12
+ const SAFE_SCHEMES = new Set(['http', 'https', 'mailto', 'tel']);
13
+ const RASTER_DATA = /^data:image\/(png|gif|jpe?g|webp|avif|bmp);/i;
14
+ export const UNSAFE_URL = 'about:invalid#unsafe';
15
+ /**
16
+ * Allowlist: a relative URL, a safe scheme, or (for image attributes) a raster data: image.
17
+ * Browsers ignore control characters and whitespace around and inside the scheme, so the check does too.
18
+ */
19
+ function safeUrl(url, image) {
20
+ const compact = url.replace(/[\u0000- ]/g, '');
21
+ const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(compact)?.[1]?.toLowerCase();
22
+ if (!scheme)
23
+ return true; // relative: /x, ../x, #x, ?x
24
+ if (SAFE_SCHEMES.has(scheme))
25
+ return true;
26
+ return image && RASTER_DATA.test(compact);
27
+ }
28
+ /**
29
+ * What an attribute should become: `null` removes it, `true` makes it a bare boolean attribute, a string is its value.
30
+ */
31
+ export function attrValue(name, value, tag) {
32
+ if (value === false || value == null)
33
+ return null;
34
+ if (value === true)
35
+ return true;
36
+ const s = String(value);
37
+ const n = name.toLowerCase();
38
+ // List-valued URL attributes: every entry must be safe, not just the first.
39
+ if (n === 'srcset') {
40
+ // "url 1x, url 2x"
41
+ const ok = s.split(',').every((candidate) => safeUrl(candidate.trim().split(/\s+/)[0] ?? '', true));
42
+ return ok ? s : UNSAFE_URL;
43
+ }
44
+ if (ANIMATION_ATTRS.has(n)) {
45
+ // The compiler passes the tag for these; without one, check them to stay on the safe side.
46
+ if (tag !== undefined && !ANIMATION_ELEMENTS.has(tag.toLowerCase()))
47
+ return s;
48
+ const entries = n === 'values' ? s.split(';') : [s];
49
+ return entries.every((entry) => safeUrl(entry.trim(), false)) ? s : UNSAFE_URL;
50
+ }
51
+ if (n === 'ping')
52
+ return s.split(/\s+/).filter(Boolean).every((url) => safeUrl(url, false)) ? s : UNSAFE_URL;
53
+ if (URL_ATTRS.has(n) && !safeUrl(s, IMAGE_ATTRS.has(n)))
54
+ return UNSAFE_URL;
55
+ return s;
56
+ }
@@ -1,14 +1,70 @@
1
+ import { type Signal } from './signals.ts';
1
2
  export type Hole = {
2
3
  start: Comment;
3
4
  end: Comment;
4
5
  };
5
- /** Find `<!--[N-->…<!--]-->` pairs inside `root`, skipping nested islands. Returns holes indexed by N. */
6
- export declare function holes(root: Element): Hole[];
6
+ export type Block = {
7
+ start: Comment;
8
+ end: Comment;
9
+ k: number;
10
+ };
11
+ type Range = {
12
+ start: Comment;
13
+ end: Comment;
14
+ };
15
+ export type For = Range & {
16
+ rows: Range[];
17
+ empty: Range | null;
18
+ };
19
+ /**
20
+ * Where wiring looks for its markers: a whole island, or one @for row inside it. A row template repeats its marker
21
+ * numbers once per row, so code wiring a row only looks between that row's markers.
22
+ */
23
+ export type Ctx = Element | {
24
+ root: Element;
25
+ start: Comment;
26
+ end: Comment;
27
+ };
28
+ /** Hole markers in `ctx`, by index. */
29
+ export declare function holes(ctx: Ctx): Hole[];
30
+ /** @if block markers in `ctx`, by index. */
31
+ export declare function blocks(ctx: Ctx): Block[];
32
+ /**
33
+ * An @if block. `which()` picks the branch (-1 for none). The server-rendered branch is wired in place; a change
34
+ * removes the old branch (disposing its effects and handlers), inserts the new branch's HTML and wires it.
35
+ */
36
+ export declare function block(ctx: Ctx, index: number, which: () => number, branches: {
37
+ html: () => string;
38
+ wire: () => void;
39
+ }[]): void;
40
+ /**
41
+ * A child component inside an island whose props or content read state. `html()` renders it with the current
42
+ * values; when anything it read changes, the old HTML is disposed and replaced, and `wire()` wires the island's own
43
+ * holes and events in the child's slot content again. A stateful child is remounted with its new props.
44
+ */
45
+ export declare function region(ctx: Ctx, index: number, html: () => string, wire: () => void): void;
46
+ /**
47
+ * A @for list. Rows the server rendered are adopted in place. When the list changes, rows are matched by key:
48
+ * kept rows keep their DOM nodes (moved only when out of order) and get the new item and index through their
49
+ * signals; new rows are rendered and wired; removed rows are disposed and removed. `@empty` content is shown while
50
+ * the list is empty.
51
+ */
52
+ export declare function forBlock(ctx: Ctx, index: number, list: () => unknown, keyOf: (item: any, i: number) => unknown, row: {
53
+ html: (item: any, i: number) => string;
54
+ wire: (ctx: Ctx, item: Signal<any>, index: Signal<number>) => void;
55
+ }, empty: {
56
+ html: () => string;
57
+ wire: (ctx: Ctx) => void;
58
+ } | null): void;
7
59
  /** Keep exactly one text node between the hole's markers, set to `fn()`. */
8
60
  export declare function text(hole: Hole, fn: () => unknown): void;
9
61
  /**
10
- * Register a handler for elements marked `data-cl-e="index"` inside this island.
62
+ * Register a handler for elements marked `data-cl-e="index"` inside `ctx`.
11
63
  * One listener per island per event type; it walks from the target up to the island root, running handlers
12
- * innermost first and stopping when one calls `stopPropagation()`.
64
+ * innermost first and stopping when one calls `stopPropagation()`. A handler registered for a @for row only fires
65
+ * for elements in that row.
13
66
  */
14
- export declare function on(root: Element, index: number, type: string, fn: (e: Event) => void): void;
67
+ export declare function on(ctx: Ctx, index: number, type: string, fn: (e: Event) => void): void;
68
+ /** Keep attribute `name` of the element marked `data-cl-a="index"` in `ctx` in sync with `fn()`. */
69
+ export declare function attr(ctx: Ctx, index: number, name: string, fn: () => unknown, tag?: string): void;
70
+ export {};
@@ -1,8 +1,26 @@
1
- // Attach helpers: find hole markers in server HTML and keep them updated. Browser only. Never re-renders.
2
- import { effect } from './signals.js';
3
- /** Find `<!--[N-->…<!--]-->` pairs inside `root`, skipping nested islands. Returns holes indexed by N. */
4
- export function holes(root) {
5
- const found = [];
1
+ // Attach helpers: find markers in server HTML and keep them updated. Browser only. Never re-renders existing HTML;
2
+ // only @if branches and @for rows that did not exist on the server are rendered here.
3
+ import { attrValue } from './attrs.js';
4
+ import { effect, onDispose, scope, state, untrack } from './signals.js';
5
+ const rootOf = (ctx) => ('root' in ctx ? ctx.root : ctx);
6
+ /** Is `node` inside `ctx` (always true for a whole island)? */
7
+ function inside(ctx, node) {
8
+ if (!('root' in ctx))
9
+ return true;
10
+ return !!(ctx.start.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING) &&
11
+ !!(ctx.end.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_PRECEDING);
12
+ }
13
+ /**
14
+ * Find every marker in `ctx`, skipping nested islands:
15
+ * holes `<!--[N-->`, @if blocks `<!--[bN:K-->`, @for lists `<!--[fN-->` with rows `<!--[r-->` and `<!--[e-->`,
16
+ * all closed by `<!--]-->`.
17
+ */
18
+ function scan(ctx) {
19
+ const root = rootOf(ctx);
20
+ const holes = [];
21
+ const blocks = [];
22
+ const fors = [];
23
+ const regions = [];
6
24
  const open = [];
7
25
  const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT, {
8
26
  acceptNode: (n) => n.nodeType === 8 ? NodeFilter.FILTER_ACCEPT
@@ -10,15 +28,216 @@ export function holes(root) {
10
28
  : NodeFilter.FILTER_SKIP,
11
29
  });
12
30
  for (let n = walker.nextNode(); n; n = walker.nextNode()) {
13
- const data = n.data;
14
- if (/^\[\d+$/.test(data))
15
- open.push({ index: Number(data.slice(1)), start: n });
31
+ if (!inside(ctx, n))
32
+ continue;
33
+ const c = n;
34
+ const data = c.data;
35
+ let m;
36
+ const push = (kind, index = 0, k = 0) => open.push({ kind, index, k, start: c, rows: [], empty: null });
37
+ if ((m = /^\[(\d+)$/.exec(data)))
38
+ push('hole', Number(m[1]));
39
+ else if ((m = /^\[b(\d+):(-?\d+)$/.exec(data)))
40
+ push('block', Number(m[1]), Number(m[2]));
41
+ else if ((m = /^\[f(\d+)$/.exec(data)))
42
+ push('for', Number(m[1]));
43
+ else if ((m = /^\[c(\d+)$/.exec(data)))
44
+ push('region', Number(m[1]));
45
+ else if (data === '[r')
46
+ push('row');
47
+ else if (data === '[e')
48
+ push('empty');
16
49
  else if (data === ']' && open.length) {
17
- const { index, start } = open.pop();
18
- found[index] = { start, end: n };
50
+ const o = open.pop();
51
+ const parent = open[open.length - 1];
52
+ if (o.kind === 'hole')
53
+ holes[o.index] = { start: o.start, end: c };
54
+ else if (o.kind === 'block')
55
+ blocks[o.index] = { start: o.start, end: c, k: o.k };
56
+ else if (o.kind === 'for')
57
+ fors[o.index] = { start: o.start, end: c, rows: o.rows, empty: o.empty };
58
+ else if (o.kind === 'region')
59
+ regions[o.index] = { start: o.start, end: c };
60
+ else if (parent?.kind === 'for') {
61
+ if (o.kind === 'row')
62
+ parent.rows.push({ start: o.start, end: c });
63
+ else
64
+ parent.empty = { start: o.start, end: c };
65
+ }
19
66
  }
20
67
  }
21
- return found;
68
+ return { holes, blocks, fors, regions };
69
+ }
70
+ /** Hole markers in `ctx`, by index. */
71
+ export function holes(ctx) {
72
+ return scan(ctx).holes;
73
+ }
74
+ /** @if block markers in `ctx`, by index. */
75
+ export function blocks(ctx) {
76
+ return scan(ctx).blocks;
77
+ }
78
+ /** Turn HTML into nodes and put them before `end`; returns the first and last inserted node. */
79
+ function insertHtml(html, end) {
80
+ const t = document.createElement('template');
81
+ t.innerHTML = html;
82
+ const first = t.content.firstChild;
83
+ const last = t.content.lastChild;
84
+ end.parentNode.insertBefore(t.content, end);
85
+ // Child islands in the new HTML attach like the ones on the page (the loader registers this hook).
86
+ const attachIslands = globalThis.__clAttach;
87
+ if (attachIslands && end.parentNode)
88
+ attachIslands(end.parentNode);
89
+ return { first, last };
90
+ }
91
+ /** The nodes from `start` to `end`, both included. */
92
+ function rangeNodes(start, end) {
93
+ const nodes = [];
94
+ for (let n = start; n; n = n.nextSibling) {
95
+ nodes.push(n);
96
+ if (n === end)
97
+ break;
98
+ }
99
+ return nodes;
100
+ }
101
+ /**
102
+ * An @if block. `which()` picks the branch (-1 for none). The server-rendered branch is wired in place; a change
103
+ * removes the old branch (disposing its effects and handlers), inserts the new branch's HTML and wires it.
104
+ */
105
+ export function block(ctx, index, which, branches) {
106
+ const b = blocks(ctx)[index];
107
+ if (!b)
108
+ return;
109
+ let current = b.k;
110
+ let dispose = null;
111
+ let first = true;
112
+ onDispose(() => dispose?.()); // removing the enclosing branch or row removes this one's too
113
+ effect(() => {
114
+ const k = which();
115
+ untrack(() => {
116
+ if (!first && k === current)
117
+ return;
118
+ if (k !== current) {
119
+ dispose?.();
120
+ while (b.start.nextSibling && b.start.nextSibling !== b.end)
121
+ b.start.nextSibling.remove();
122
+ if (k >= 0)
123
+ insertHtml(branches[k].html(), b.end);
124
+ current = k;
125
+ }
126
+ first = false;
127
+ dispose = k >= 0 ? scope(() => branches[k].wire()) : null;
128
+ });
129
+ });
130
+ }
131
+ /**
132
+ * A child component inside an island whose props or content read state. `html()` renders it with the current
133
+ * values; when anything it read changes, the old HTML is disposed and replaced, and `wire()` wires the island's own
134
+ * holes and events in the child's slot content again. A stateful child is remounted with its new props.
135
+ */
136
+ export function region(ctx, index, html, wire) {
137
+ const r = scan(ctx).regions[index];
138
+ if (!r)
139
+ return;
140
+ let dispose = null;
141
+ let first = true;
142
+ onDispose(() => dispose?.());
143
+ effect(() => {
144
+ const next = html();
145
+ untrack(() => {
146
+ if (!first) {
147
+ dispose?.();
148
+ while (r.start.nextSibling && r.start.nextSibling !== r.end)
149
+ r.start.nextSibling.remove();
150
+ insertHtml(next, r.end);
151
+ }
152
+ first = false;
153
+ dispose = scope(wire);
154
+ });
155
+ });
156
+ }
157
+ /**
158
+ * A @for list. Rows the server rendered are adopted in place. When the list changes, rows are matched by key:
159
+ * kept rows keep their DOM nodes (moved only when out of order) and get the new item and index through their
160
+ * signals; new rows are rendered and wired; removed rows are disposed and removed. `@empty` content is shown while
161
+ * the list is empty.
162
+ */
163
+ export function forBlock(ctx, index, list, keyOf, row, empty) {
164
+ const f = scan(ctx).fors[index];
165
+ if (!f)
166
+ return;
167
+ const root = rootOf(ctx);
168
+ let rows = [];
169
+ let emptyRange = null;
170
+ let first = true;
171
+ const wireRow = (range, key, item, i) => {
172
+ const itemS = state(item);
173
+ const indexS = state(i);
174
+ const dispose = scope(() => row.wire({ root, ...range }, itemS, indexS));
175
+ return { ...range, key, item: itemS, index: indexS, dispose };
176
+ };
177
+ const wireEmpty = (range) => ({ ...range, dispose: empty ? scope(() => empty.wire({ root, ...range })) : () => { } });
178
+ onDispose(() => {
179
+ for (const r of rows)
180
+ r.dispose();
181
+ emptyRange?.dispose();
182
+ });
183
+ effect(() => {
184
+ const items = [...(list() ?? [])];
185
+ untrack(() => {
186
+ // Keys, made unique: a repeated key would make two rows share one identity.
187
+ const seen = new Set();
188
+ const keys = items.map((item, i) => {
189
+ let key = keyOf(item, i);
190
+ if (seen.has(key)) {
191
+ console.warn(`[clarusjs] @for: duplicate key ${String(key)}; rows with repeated keys are matched by position`);
192
+ key = `${String(key)}\u0000${i}`;
193
+ }
194
+ seen.add(key);
195
+ return key;
196
+ });
197
+ if (first) {
198
+ first = false;
199
+ rows = f.rows.map((range, i) => wireRow(range, keys[i], items[i], i));
200
+ if (f.empty)
201
+ emptyRange = wireEmpty(f.empty);
202
+ return;
203
+ }
204
+ const old = new Map(rows.map((r) => [r.key, r]));
205
+ const next = items.map((item, i) => {
206
+ const kept = old.get(keys[i]);
207
+ if (kept) {
208
+ old.delete(keys[i]);
209
+ kept.item.set(item);
210
+ kept.index.set(i);
211
+ return kept;
212
+ }
213
+ const { first: start, last: end } = insertHtml(`<!--[r-->${row.html(item, i)}<!--]-->`, f.end);
214
+ return wireRow({ start: start, end: end }, keys[i], item, i);
215
+ });
216
+ for (const r of old.values()) {
217
+ r.dispose();
218
+ for (const n of rangeNodes(r.start, r.end))
219
+ n.parentNode?.removeChild(n);
220
+ }
221
+ // Put rows in order, moving only those that are not already right after the previous one.
222
+ let anchor = f.start;
223
+ for (const r of next) {
224
+ if (anchor.nextSibling !== r.start)
225
+ anchor.after(...rangeNodes(r.start, r.end));
226
+ anchor = r.end;
227
+ }
228
+ rows = next;
229
+ if (items.length && emptyRange) {
230
+ emptyRange.dispose();
231
+ for (const n of rangeNodes(emptyRange.start, emptyRange.end))
232
+ n.parentNode?.removeChild(n);
233
+ emptyRange = null;
234
+ }
235
+ else if (!items.length && !emptyRange && empty) {
236
+ const { first: start, last: end } = insertHtml(`<!--[e-->${empty.html()}<!--]-->`, f.end);
237
+ emptyRange = wireEmpty({ start: start, end: end });
238
+ }
239
+ });
240
+ });
22
241
  }
23
242
  /** Keep exactly one text node between the hole's markers, set to `fn()`. */
24
243
  export function text(hole, fn) {
@@ -40,11 +259,13 @@ const registry = new WeakMap();
40
259
  // These don't bubble, so they are caught on the way down instead.
41
260
  const CAPTURE = new Set(['focus', 'blur']);
42
261
  /**
43
- * Register a handler for elements marked `data-cl-e="index"` inside this island.
262
+ * Register a handler for elements marked `data-cl-e="index"` inside `ctx`.
44
263
  * One listener per island per event type; it walks from the target up to the island root, running handlers
45
- * innermost first and stopping when one calls `stopPropagation()`.
264
+ * innermost first and stopping when one calls `stopPropagation()`. A handler registered for a @for row only fires
265
+ * for elements in that row.
46
266
  */
47
- export function on(root, index, type, fn) {
267
+ export function on(ctx, index, type, fn) {
268
+ const root = rootOf(ctx);
48
269
  let types = registry.get(root);
49
270
  if (!types)
50
271
  registry.set(root, (types = new Map()));
@@ -57,8 +278,9 @@ export function on(root, index, type, fn) {
57
278
  const i = el.getAttribute?.('data-cl-e');
58
279
  if (i === null || i === undefined || el.closest('cl-island') !== root)
59
280
  continue;
60
- for (const h of own.get(Number(i)) ?? [])
61
- h(e);
281
+ for (const h of [...(own.get(Number(i)) ?? [])])
282
+ if (inside(h.ctx, el))
283
+ h.fn(e);
62
284
  if (e.cancelBubble)
63
285
  break;
64
286
  }
@@ -66,5 +288,23 @@ export function on(root, index, type, fn) {
66
288
  }
67
289
  if (!handlers.has(index))
68
290
  handlers.set(index, []);
69
- handlers.get(index).push(fn);
291
+ const list = handlers.get(index);
292
+ const handler = { fn, ctx };
293
+ list.push(handler);
294
+ onDispose(() => { const at = list.indexOf(handler); if (at !== -1)
295
+ list.splice(at, 1); }); // a removed branch or row stops listening
296
+ }
297
+ /** Keep attribute `name` of the element marked `data-cl-a="index"` in `ctx` in sync with `fn()`. */
298
+ export function attr(ctx, index, name, fn, tag) {
299
+ const root = rootOf(ctx);
300
+ const el = [...root.querySelectorAll(`[data-cl-a="${index}"]`)].find((e) => e.closest('cl-island') === root && inside(ctx, e));
301
+ if (!el)
302
+ return;
303
+ effect(() => {
304
+ const v = attrValue(name, fn(), tag);
305
+ if (v === null)
306
+ el.removeAttribute(name);
307
+ else
308
+ el.setAttribute(name, v === true ? '' : v);
309
+ });
70
310
  }
@@ -0,0 +1,10 @@
1
+ /** Escape a value for HTML text or a double-quoted attribute. null/undefined render as ''. */
2
+ export declare function escape(value: unknown): string;
3
+ /** ` name="value"`, ` name` (true) or '' (false/null/undefined), escaped and URL-checked. */
4
+ export declare function attrHtml(name: string, value: unknown, tag?: string): string;
5
+ /** An @if block inside an island: markers record which branch (k, or -1 for none) was rendered. */
6
+ export declare function blockHtml(index: number, k: number, branches: (() => string)[]): string;
7
+ /** A @for list inside an island: one marker pair around the list, one per row, one around @empty content. */
8
+ export declare function forHtml(index: number, list: unknown, row: (item: any, i: number) => string, empty: (() => string) | null): string;
9
+ /** A child component inside an island that the browser may re-render: markers around its HTML. */
10
+ export declare function regionHtml(index: number, html: () => string): string;
@@ -0,0 +1,30 @@
1
+ // HTML-string helpers used by compiled code on the server (render) and in the browser (branch HTML for @if).
2
+ import { attrValue } from './attrs.js';
3
+ const ENTITIES = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
4
+ /** Escape a value for HTML text or a double-quoted attribute. null/undefined render as ''. */
5
+ export function escape(value) {
6
+ if (value == null)
7
+ return '';
8
+ return String(value).replace(/[&<>"']/g, (ch) => ENTITIES[ch]);
9
+ }
10
+ /** ` name="value"`, ` name` (true) or '' (false/null/undefined), escaped and URL-checked. */
11
+ export function attrHtml(name, value, tag) {
12
+ const v = attrValue(name, value, tag);
13
+ return v === null ? '' : v === true ? ` ${name}` : ` ${name}="${escape(v)}"`;
14
+ }
15
+ /** An @if block inside an island: markers record which branch (k, or -1 for none) was rendered. */
16
+ export function blockHtml(index, k, branches) {
17
+ return `<!--[b${index}:${k}-->${k >= 0 ? branches[k]() : ''}<!--]-->`;
18
+ }
19
+ /** A @for list inside an island: one marker pair around the list, one per row, one around @empty content. */
20
+ export function forHtml(index, list, row, empty) {
21
+ const items = [...(list ?? [])];
22
+ const body = items.length
23
+ ? items.map((item, i) => `<!--[r-->${row(item, i)}<!--]-->`).join('')
24
+ : empty ? `<!--[e-->${empty()}<!--]-->` : '';
25
+ return `<!--[f${index}-->${body}<!--]-->`;
26
+ }
27
+ /** A child component inside an island that the browser may re-render: markers around its HTML. */
28
+ export function regionHtml(index, html) {
29
+ return `<!--[c${index}-->${html()}<!--]-->`;
30
+ }
@@ -1,2 +1,4 @@
1
- export { state, derived, effect, type Signal, type ReadSignal } from './signals.ts';
2
- export { holes, text, on, type Hole } from './dom.ts';
1
+ export { state, derived, shared, effect, scope, onDispose, untrack, type Signal, type ReadSignal } from './signals.ts';
2
+ export { holes, blocks, text, on, attr, block, forBlock, region, type Hole, type Block, type Ctx } from './dom.ts';
3
+ export { escape, attrHtml, blockHtml, forHtml, regionHtml } from './html.ts';
4
+ export { parse as parseIslandData } from './serialize.ts';
@@ -1,3 +1,5 @@
1
1
  // Browser runtime used by compiled attach() functions.
2
- export { state, derived, effect } from './signals.js';
3
- export { holes, text, on } from './dom.js';
2
+ export { state, derived, shared, effect, scope, onDispose, untrack } from './signals.js';
3
+ export { holes, blocks, text, on, attr, block, forBlock, region } from './dom.js';
4
+ export { escape, attrHtml, blockHtml, forHtml, regionHtml } from './html.js';
5
+ export { parse as parseIslandData } from './serialize.js';
@@ -1,5 +1,10 @@
1
1
  type IslandModule = {
2
- attach(root: Element, props: Record<string, unknown>): void;
2
+ attach(root: Element, props: Record<string, unknown>, state?: Record<string, unknown>): void;
3
3
  };
4
- export declare function attachAll(root?: ParentNode, load?: (src: string) => Promise<IslandModule>): Promise<void>;
4
+ type Load = (src: string) => Promise<IslandModule>;
5
+ /**
6
+ * Attach every island under `root` that isn't attached yet. Resolves once the islands that attach right away
7
+ * (the default, attach="load") are done; idle, visible and interaction islands attach later on their own.
8
+ */
9
+ export declare function attachAll(root?: ParentNode, load?: Load): Promise<void>;
5
10
  export {};