kerfjs 5.0.0-beta.12 → 5.0.0-beta.121
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 +2987 -107
- package/README.md +96 -37
- package/ai/cursorrules +111 -62
- package/ai/manifest.json +30 -7
- package/ai/skill.md +149 -77
- package/ai/ui-skill.md +18 -0
- package/dist/actions.d.ts +1 -1
- package/dist/actions.js +10 -6
- package/dist/actions.js.map +1 -1
- package/dist/array-signal.js +1 -1
- package/dist/async.js +24 -21
- package/dist/async.js.map +1 -1
- package/dist/attach.js +1 -66
- package/dist/attach.js.map +1 -1
- package/dist/{chunk-HW7KSM2Y.js → chunk-3C6F6NM4.js} +1 -1
- package/dist/{chunk-HW7KSM2Y.js.map → chunk-3C6F6NM4.js.map} +1 -1
- package/dist/{chunk-GY4XV2UV.js → chunk-4TX6YJDM.js} +10 -3
- package/dist/chunk-4TX6YJDM.js.map +1 -0
- package/dist/{chunk-QIP723L4.js → chunk-5WRGJZV6.js} +3 -2
- package/dist/chunk-5WRGJZV6.js.map +1 -0
- package/dist/{chunk-V46JKE44.js → chunk-6LXUC4ZY.js} +29 -2
- package/dist/chunk-6LXUC4ZY.js.map +1 -0
- package/dist/{chunk-KZJXHFIB.js → chunk-BI4HGICV.js} +3 -3
- package/dist/chunk-BI4HGICV.js.map +1 -0
- package/dist/chunk-FM6N2B4N.js +70 -0
- package/dist/chunk-FM6N2B4N.js.map +1 -0
- package/dist/{chunk-LVH3GC6B.js → chunk-H7WTRM6F.js} +3 -3
- package/dist/chunk-H7WTRM6F.js.map +1 -0
- package/dist/{chunk-U6FK33SG.js → chunk-IHMDBBUJ.js} +2 -2
- package/dist/chunk-IHMDBBUJ.js.map +1 -0
- package/dist/chunk-JN7EJM3B.js +86 -0
- package/dist/chunk-JN7EJM3B.js.map +1 -0
- package/dist/{chunk-UZJ6I4T6.js → chunk-MK42GLPV.js} +1 -1
- package/dist/chunk-MK42GLPV.js.map +1 -0
- package/dist/{chunk-ZDCJZCNO.js → chunk-VX3RCRGG.js} +161 -90
- package/dist/chunk-VX3RCRGG.js.map +1 -0
- package/dist/{chunk-SVATPF5R.js → chunk-YVBK73GU.js} +612 -178
- package/dist/chunk-YVBK73GU.js.map +1 -0
- package/dist/{delegate-CL9VTZFb.d.ts → delegate--CrfgYtC.d.ts} +0 -34
- package/dist/dev.d.ts +31 -13
- package/dist/dev.js +101 -35
- package/dist/dev.js.map +1 -1
- package/dist/html.js +20 -8
- package/dist/html.js.map +1 -1
- package/dist/index.d.ts +14 -9
- package/dist/index.js +29 -20
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime.d.ts +22 -7
- package/dist/jsx-runtime.js +1 -1
- package/dist/list.d.ts +7 -3
- package/dist/list.js +153 -46
- package/dist/list.js.map +1 -1
- package/dist/overlay.d.ts +278 -133
- package/dist/overlay.js +1034 -368
- package/dist/overlay.js.map +1 -1
- package/dist/remount.js +2 -2
- package/dist/router.d.ts +13 -4
- package/dist/router.js +37 -10
- package/dist/router.js.map +1 -1
- package/dist/scope.d.ts +35 -8
- package/dist/scope.js +61 -30
- package/dist/scope.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/timing.d.ts +3 -2
- package/dist/timing.js +1 -1
- package/dist/timing.js.map +1 -1
- package/llms.txt +14 -6
- package/package.json +44 -12
- package/setup/cli.mjs +94 -0
- package/setup/index.d.mts +38 -0
- package/setup/index.mjs +1553 -0
- package/setup/jsonc.mjs +201 -0
- package/setup/state.schema.json +57 -0
- package/setup/ui-baseline.mjs +210 -0
- package/dist/chunk-GY4XV2UV.js.map +0 -1
- package/dist/chunk-KPXIOG2C.js +0 -54
- package/dist/chunk-KPXIOG2C.js.map +0 -1
- package/dist/chunk-KZJXHFIB.js.map +0 -1
- package/dist/chunk-LVH3GC6B.js.map +0 -1
- package/dist/chunk-QIP723L4.js.map +0 -1
- package/dist/chunk-SVATPF5R.js.map +0 -1
- package/dist/chunk-U6FK33SG.js.map +0 -1
- package/dist/chunk-UZJ6I4T6.js.map +0 -1
- package/dist/chunk-V46JKE44.js.map +0 -1
- package/dist/chunk-ZDCJZCNO.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/array-signal.ts"],"names":[],"mappings":";;;;AA6CO,IAAM,kBAAA,mBAAqB,MAAA,CAAO,GAAA,CAAI,oBAAoB;AAEjE,SAAS,YAAA,CACP,KAAA,EACA,MAAA,EACA,QAAA,GAAW,KAAA,EACF;AACT,EAAA,OACE,MAAA,CAAO,UAAU,KAAK,CAAA,IACtB,SAAS,CAAA,KACR,QAAA,GAAW,KAAA,IAAS,MAAA,GAAS,KAAA,GAAQ,MAAA,CAAA;AAE1C;AAEO,IAAM,cAAN,MAAqB;AAAA,EAClB,MAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA;AAAA,EAER,CAAU,kBAAkB,IAAI,IAAA;AAAA,EAEhC,WAAA,CAAY,OAAA,GAAwB,EAAC,EAAG;AACtC,IAAA,IAAA,CAAK,MAAA,GAAS,CAAC,GAAG,OAAO,CAAA;AACzB,IAAA,IAAA,CAAK,QAAA,GAAW,OAAO,CAAC,CAAA;AACxB,IAAA,IAAA,CAAK,WAAW,EAAC;AAAA,EACnB;AAAA;AAAA,EAGA,IAAI,KAAA,GAAsB;AAExB,IAAA,KAAK,KAAK,QAAA,CAAS,KAAA;AACnB,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAA,CAAO,OAAe,EAAA,EAA0B;AAC9C,IAAA,IAAI,CAAC,YAAA,CAAa,KAAA,EAAO,IAAA,CAAK,MAAA,CAAO,MAAM,CAAA,EAAG;AAC5C,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,0BAAA,EAA6B,KAAK,CAAA,mBAAA,EAAsB,IAAA,CAAK,OAAO,MAAM,CAAA,EAAA;AAAA,OAC5E;AAAA,IACF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Q,CAAA;AAC1D,IAAA,IAAA,CAAK,QAAA,CAAS,KAAA,EAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,eAAA,GAAmC;AACjC,IAAA,MAAM,MAAM,IAAA,CAAK,QAAA;AACjB,IAAA,IAAA,CAAK,WAAW,EAAC;AACjB,IAAA,OAAO,GAAA;AAAA,EACT;AACF;AAGO,SAAS,WAAA,CAAe,OAAA,GAAwB,EAAC,EAAmB;AACzE,EAAA,OAAO,IAAI,YAAY,OAAO,CAAA;AAChC","file":"chunk-H7WTRM6F.js","sourcesContent":["/**\n * `arraySignal(initial)` — granular collection signal.\n *\n * A keyed-list-friendly variant of `signal()` that emits typed patch events\n * for every mutation (update / insert / remove / move / replace). When such\n * a signal is bound to `each(...)` inside a `mount()`, the keyed list\n * reconciler applies just the patches against the live DOM — no per-item\n * iteration, no `classifyItems` Map build, no LIS pass over unchanged rows.\n *\n * const rows = arraySignal<Row>([]);\n *\n * rows.update(42, (r) => ({ ...r, label: 'changed' })); // 1 update event\n * rows.insert(0, { id: 'x', ... }); // 1 insert event\n * rows.remove(7); // 1 remove event\n * rows.move(3, 0); // 1 move event\n * rows.replace([...]); // falls back to snapshot reconcile\n *\n * Read-side semantics match a regular signal: `arraySig.value` is a\n * snapshot, and reads inside `effect()` / `computed()` register as\n * dependencies, so derived values keep working.\n */\n\nimport { bumpItemVersion } from './item-version.js';\nimport type { Signal } from './reactive.js';\nimport { signal } from './reactive.js';\n\n/** A single granular mutation event. */\nexport type ArrayPatch<T> =\n | { type: 'update'; index: number; item: T }\n | { type: 'insert'; index: number; item: T }\n | { type: 'remove'; index: number }\n | { type: 'move'; from: number; to: number }\n | { type: 'replace'; items: readonly T[] };\n\n/**\n * Cross-bundle brand for `ArraySignal` instances. `each()` and the\n * granular reconciler check for this brand instead of `instanceof\n * ArraySignal`, so the main `kerfjs` barrel can detect arraySignal\n * inputs without importing the class at runtime — the class lives\n * only in the `kerfjs/array-signal` subpath, so apps that don't need\n * granular collections shed ~1 KB.\n *\n * Same `Symbol.for(...)`-based pattern as `SafeHtml` (KF-14): cross-\n * bundle-safe, zero-cost runtime check.\n */\nexport const ARRAY_SIGNAL_BRAND = Symbol.for('kerfjs.ArraySignal');\n\nfunction isValidIndex(\n index: number,\n length: number,\n allowEnd = false,\n): boolean {\n return (\n Number.isInteger(index) &&\n index >= 0 &&\n (allowEnd ? index <= length : index < length)\n );\n}\n\nexport class ArraySignal<T> {\n private _items: T[];\n private _version: Signal<number>;\n private _patches: ArrayPatch<T>[];\n // Branded so `isArraySignal()` recognizes instances from any copy of this module.\n readonly [ARRAY_SIGNAL_BRAND] = true as const;\n\n constructor(initial: readonly T[] = []) {\n this._items = [...initial];\n this._version = signal(0);\n this._patches = [];\n }\n\n /** Read-only snapshot. Reads inside an effect/computed register a dependency. */\n get value(): readonly T[] {\n // Touch the version signal so signals-core treats reads as tracked.\n void this._version.value;\n return this._items;\n }\n\n /**\n * Replace the item at `index` with `fn(currentItem)`. Emits one `update`\n * patch. Both styles work: returning a fresh object (idiomatic) invalidates\n * the row by identity, and mutating `item` in place and returning it works\n * too — a per-item content version (KF-418) makes the same-ref change visible\n * to every consumer's row memo.\n */\n update(index: number, fn: (item: T) => T): void {\n if (!isValidIndex(index, this._items.length)) {\n throw new Error(\n `arraySignal.update: index ${index} out of bounds [0, ${this._items.length}).`,\n );\n }\n const next = fn(this._items[index]);\n this._items[index] = next;\n this._patches.push({ type: 'update', index, item: next });\n // KF-418: a same-ref update (fn mutates and returns the same object) is\n // invisible to the row memo, which is keyed on object identity. Bump the\n // item's content version so every consumer — this list, another list over\n // this signal, a second mount, a plain-array filter() view — re-renders it.\n // Non-object items (an arraySignal<number> used as a plain signal) are\n // skipped by bumpItemVersion — they can't be each() rows (KF-419).\n bumpItemVersion(next);\n this._version.value++;\n }\n\n /** Insert `item` at `index`. Existing items at index..N shift right. Emits one `insert` patch. */\n insert(index: number, item: T): void {\n if (!isValidIndex(index, this._items.length, true)) {\n throw new Error(\n `arraySignal.insert: index ${index} out of bounds [0, ${this._items.length}].`,\n );\n }\n this._items.splice(index, 0, item);\n this._patches.push({ type: 'insert', index, item });\n this._version.value++;\n }\n\n /** Append `item` at the end. Sugar for `insert(items.length, item)`. */\n push(item: T): void {\n this.insert(this._items.length, item);\n }\n\n /** Remove and return the item at `index`. Emits one `remove` patch. */\n remove(index: number): T {\n if (!isValidIndex(index, this._items.length)) {\n throw new Error(\n `arraySignal.remove: index ${index} out of bounds [0, ${this._items.length}).`,\n );\n }\n const [removed] = this._items.splice(index, 1);\n this._patches.push({ type: 'remove', index });\n this._version.value++;\n return removed;\n }\n\n /** Move the item at `from` to position `to`. Emits one `move` patch (no-op when from === to). */\n move(from: number, to: number): void {\n if (\n !isValidIndex(from, this._items.length) ||\n !isValidIndex(to, this._items.length)\n ) {\n throw new Error(\n `arraySignal.move: indices out of bounds (from=${from}, to=${to}, length=${this._items.length}).`,\n );\n }\n if (from === to) return;\n const [item] = this._items.splice(from, 1);\n this._items.splice(to, 0, item);\n this._patches.push({ type: 'move', from, to });\n this._version.value++;\n }\n\n /** Replace every item. Emits one `replace` patch — the granular reconciler falls back to a full keyed diff for this case. */\n replace(items: readonly T[]): void {\n this._items = [...items];\n this._patches.push({ type: 'replace', items: this._items });\n this._version.value++;\n }\n\n /**\n * @internal Used by `each()` when binding this signal to a list. Returns\n * the queue of granular patches issued since the previous call, then\n * clears the queue. Best paired with a single binding — a second consumer\n * in the same render gets an empty array (which forces the snapshot\n * fall-back path, which is correct but slower).\n */\n _consumePatches(): ArrayPatch<T>[] {\n const out = this._patches;\n this._patches = [];\n return out;\n }\n}\n\n/** Construct an array signal seeded with `initial`. */\nexport function arraySignal<T>(initial: readonly T[] = []): ArraySignal<T> {\n return new ArraySignal(initial);\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { devHooks } from './chunk-
|
|
1
|
+
import { devHooks } from './chunk-3C6F6NM4.js';
|
|
2
2
|
import { Signal, signal as signal$1, effect as effect$1 } from '@preact/signals-core';
|
|
3
3
|
export { batch, computed } from '@preact/signals-core';
|
|
4
4
|
|
|
@@ -17,4 +17,4 @@ function effect(fn) {
|
|
|
17
17
|
|
|
18
18
|
export { effect, isSignal, signal };
|
|
19
19
|
|
|
20
|
-
//# sourceMappingURL=chunk-
|
|
20
|
+
//# sourceMappingURL=chunk-IHMDBBUJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/reactive.ts"],"names":["coreSignal","coreEffect"],"mappings":";;;;AAgDO,SAAS,SAAS,KAAA,EAA0C;AACjE,EAAA,OAAO,KAAA,YAAiB,MAAA;AAC1B;AAEO,SAAS,OAAU,KAAA,EAAsB;AAC9C,EAAA,MAAM,UAAU,QAAA,CAAS,aAAA;AACzB,EAAA,IAAI,OAAA,EAAS,OAAO,OAAA,CAAW,KAAU,CAAA;AACzC,EAAA,OAAOA,SAAW,KAAU,CAAA;AAC9B;AAEO,SAAS,OAAO,EAAA,EAA2C;AAChE,EAAA,MAAM,OAAO,QAAA,CAAS,UAAA;AACtB,EAAA,OAAOC,QAAA,CAAW,IAAA,GAAO,IAAA,CAAK,EAAE,IAAI,EAAE,CAAA;AACxC","file":"chunk-IHMDBBUJ.js","sourcesContent":["/**\n * Re-exports of `@preact/signals-core`. Lets the rest of the codebase depend\n * on `'./reactive.js'` without naming the underlying lib, so swapping it out\n * later (or fronting it with a hand-rolled implementation) is a one-file\n * change.\n *\n * Two dev hook slots sit in front of the bare re-exports:\n *\n * - `signalFactory` replaces the constructor so writes to never-subscribed\n * signals can warn (`KERF_DEV_WARN_UNTRACKED_SIGNALS=1`).\n *\n * - `wrapEffect` wraps the user body so `delegate()` can detect that it's\n * running inside an effect (`KERF_DEV_WARN_DELEGATE_IN_EFFECT=1`).\n *\n * Both are `undefined` unless the consumer imported `kerfjs/dev`, so production\n * sees the bare `@preact/signals-core` exports behind one property read.\n *\n * ORDERING: both slots are resolved at CREATION time. A signal created before\n * `kerfjs/dev` is installed (or before `untrackedSignals` is switched on) stays\n * plain, and an effect created before the install (or before\n * `delegateInEffect` is switched on) is never wrapped. Static imports hoist\n * above a `await import()`, so module-scope signals and effects in imported\n * modules are created first. `mount()`'s `listenerRebuild` hook is the third\n * creation-time boundary. See docs/11-dev-warnings.md §11.3.6.\n */\n\nimport {\n effect as coreEffect,\n Signal,\n signal as coreSignal,\n} from '@preact/signals-core';\n\nimport { devHooks } from './dev-hooks.js';\n\nexport {\n batch,\n computed,\n type ReadonlySignal,\n Signal,\n} from '@preact/signals-core';\n\n/**\n * Runtime type guard for a `@preact/signals-core` signal (both `signal()`\n * values and `computed()` values are `Signal` instances). Used by the JSX\n * runtime (KF-294) to detect a signal handed straight into an attribute or\n * text hole — the trigger for a fine-grained binding rather than a snapshot\n * stringify.\n */\nexport function isSignal(value: unknown): value is Signal<unknown> {\n return value instanceof Signal;\n}\n\nexport function signal<T>(value?: T): Signal<T> {\n const factory = devHooks.signalFactory;\n if (factory) return factory<T>(value as T);\n return coreSignal(value as T);\n}\n\nexport function effect(fn: () => void | (() => void)): () => void {\n const wrap = devHooks.wrapEffect;\n return coreEffect(wrap ? wrap(fn) : fn);\n}\n"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { devHooks } from './chunk-3C6F6NM4.js';
|
|
2
|
+
|
|
3
|
+
// src/delegate.ts
|
|
4
|
+
var NON_BUBBLING = /* @__PURE__ */ new Set([
|
|
5
|
+
"focus",
|
|
6
|
+
"blur",
|
|
7
|
+
"scroll",
|
|
8
|
+
"load",
|
|
9
|
+
"error",
|
|
10
|
+
"mouseenter",
|
|
11
|
+
"mouseleave"
|
|
12
|
+
]);
|
|
13
|
+
function assertValidSelector(selector, fn) {
|
|
14
|
+
try {
|
|
15
|
+
document.createElement("div").matches(selector);
|
|
16
|
+
} catch {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`${fn}: invalid selector "${selector}". Pass a valid CSS selector (e.g. '[data-action="add"]', '.btn', 'input').`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
var KEY = /* @__PURE__ */ Symbol();
|
|
23
|
+
function _delegate(rootEl, type, selector, bind, options, capture, fn) {
|
|
24
|
+
assertValidSelector(selector, fn);
|
|
25
|
+
devHooks.delegateInEffect?.(fn);
|
|
26
|
+
const direct = options?.match === "direct";
|
|
27
|
+
const resolve = (event) => {
|
|
28
|
+
const target = event.target;
|
|
29
|
+
if (event.type === type && target instanceof Element) {
|
|
30
|
+
const matched = direct ? target.matches(selector) ? target : null : target.closest(selector);
|
|
31
|
+
if (matched !== null) {
|
|
32
|
+
const run = bind(event, matched);
|
|
33
|
+
return () => {
|
|
34
|
+
if (rootEl.contains(matched)) run();
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return void 0;
|
|
39
|
+
};
|
|
40
|
+
const listener = (event) => {
|
|
41
|
+
let snap = event[KEY];
|
|
42
|
+
if (!snap?.has(resolve)) {
|
|
43
|
+
snap = event[KEY] = /* @__PURE__ */ new Map();
|
|
44
|
+
for (const node of event.composedPath()) {
|
|
45
|
+
for (const other of node[KEY] ?? []) {
|
|
46
|
+
snap.set(other, other(event));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const run = snap.get(resolve);
|
|
51
|
+
snap.delete(resolve);
|
|
52
|
+
run?.();
|
|
53
|
+
};
|
|
54
|
+
const registry = (rootEl[KEY] ??= /* @__PURE__ */ new Set()).add(resolve);
|
|
55
|
+
rootEl.addEventListener(type, listener, capture);
|
|
56
|
+
return () => {
|
|
57
|
+
registry.delete(resolve);
|
|
58
|
+
rootEl.removeEventListener(type, listener, capture);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function delegate(rootEl, type, selector, handler, options) {
|
|
62
|
+
return _delegate(
|
|
63
|
+
rootEl,
|
|
64
|
+
type,
|
|
65
|
+
selector,
|
|
66
|
+
(event, matched) => () => handler(event, matched),
|
|
67
|
+
options,
|
|
68
|
+
NON_BUBBLING.has(type),
|
|
69
|
+
"delegate"
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
function delegateCapture(rootEl, type, selector, handler, options) {
|
|
73
|
+
return _delegate(
|
|
74
|
+
rootEl,
|
|
75
|
+
type,
|
|
76
|
+
selector,
|
|
77
|
+
(event, matched) => () => handler(event, matched),
|
|
78
|
+
options,
|
|
79
|
+
true,
|
|
80
|
+
"delegateCapture"
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { NON_BUBBLING, _delegate, delegate, delegateCapture };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=chunk-JN7EJM3B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/delegate.ts"],"names":[],"mappings":";;;AA+CO,IAAM,YAAA,uBAAmB,GAAA,CAAY;AAAA,EAC1C,OAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,YAAA;AAAA,EACA;AACF,CAAC;AAqBD,SAAS,mBAAA,CAAoB,UAAkB,EAAA,EAAkB;AAC/D,EAAA,IAAI;AACF,IAAA,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA,CAAE,OAAA,CAAQ,QAAQ,CAAA;AAAA,EAChD,CAAA,CAAA,MAAQ;AACN,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,EAAG,EAAE,CAAA,oBAAA,EAAuB,QAAQ,CAAA,2EAAA;AAAA,KAEtC;AAAA,EACF;AACF;AASA,IAAM,sBAAM,MAAA,EAAO;AAiDZ,SAAS,UACd,MAAA,EACA,IAAA,EACA,UACA,IAAA,EACA,OAAA,EACA,SACA,EAAA,EACY;AACZ,EAAA,mBAAA,CAAoB,UAAU,EAAE,CAAA;AAChC,EAAA,QAAA,CAAS,mBAAmB,EAAE,CAAA;AAC9B,EAAA,MAAM,MAAA,GAAS,SAAS,KA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AA,IAAM;AAAA,EACR,CAAA;AACA,EAAA,MAAM,QAAA,GAAA,CAAa,OAAsB,GAAG,CAAA,yBAAU,GAAA,EAAI,EAAG,IAAI,OAAO,CAAA;AACxE,EAAA,MAAA,CAAO,gBAAA,CAAiB,IAAA,EAAM,QAAA,EAAU,OAAO,CAAA;AAC/C,EAAA,OAAO,MAAM;AACX,IAAA,QAAA,CAAS,OAAO,OAAO,CAAA;AACvB,IAAA,MAAA,CAAO,mBAAA,CAAoB,IAAA,EAAM,QAAA,EAAU,OAAO,CAAA;AAAA,EACpD,CAAA;AACF;AAuBO,SAAS,QAAA,CACd,MAAA,EACA,IAAA,EACA,QAAA,EACA,SACA,OAAA,EACY;AACZ,EAAA,OAAO,SAAA;AAAA,IACL,MAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,CAAC,KAAA,EAAO,OAAA,KAAY,MAAM,OAAA,CAAQ,OAAO,OAAY,CAAA;AAAA,IACrD,OAAA;AAAA,IACA,YAAA,CAAa,IAAI,IAAI,CAAA;AAAA,IACrB;AAAA,GACF;AACF;AAuBO,SAAS,eAAA,CACd,MAAA,EACA,IAAA,EACA,QAAA,EACA,SACA,OAAA,EACY;AACZ,EAAA,OAAO,SAAA;AAAA,IACL,MAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,CAAC,KAAA,EAAO,OAAA,KAAY,MAAM,OAAA,CAAQ,OAAO,OAAY,CAAA;AAAA,IACrD,OAAA;AAAA,IACA,IAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-JN7EJM3B.js","sourcesContent":["/**\n * Tiny event-delegation helpers. Replace per-element `addEventListener` calls\n * (which don't survive morph re-renders for nodes the diff creates) with one\n * listener at the morph-root that dispatches via `closest()`.\n *\n * Three-tier listener model:\n *\n * - Tier 1 (bubbling events) — use `delegate()`.\n * click, input, change, submit, mousedown/up, keydown/up, pointerdown/up/move,\n * drag*, drop, contextmenu, wheel, copy/paste/cut, focusin/focusout.\n *\n * `delegate()` also auto-promotes the well-known non-bubbling event\n * types (`focus`, `blur`, `scroll`, `load`, `error`, `mouseenter`,\n * `mouseleave`) to the capture phase under the hood, so the call site\n * looks identical for \"interactive thing happens on a descendant\"\n * regardless of whether that event bubbles. Selector matching stays\n * `closest()`-style — the same as for bubbling events — so a wrapper\n * selector like `'.field-row'` still matches when the event fires on\n * a descendant `<input>`.\n *\n * - Tier 2 (explicit capture) — use `delegateCapture()`.\n * The escape hatch for cases the auto-promotion list doesn't cover\n * (custom non-bubbling events) or when you want capture-phase\n * interception. Selector matching is `closest()`-style by default —\n * the same walk-up as `delegate()`, and it passes the matched ancestor\n * (not the raw target) to the handler — so a click on any descendant of\n * the selected element climbs to it. Pass `{ match: 'direct' }` to opt\n * into strict `matches()`-style matching (fire only when the event lands\n * on the exact element the selector identifies).\n *\n * - Tier 3 (per-element instances / library-owned subtrees) — mark the\n * host element with `data-morph-skip` and manage the library's\n * lifecycle directly. No delegation helper applies.\n */\n\nimport { devHooks } from './dev-hooks.js';\n\n/**\n * Event types that don't bubble and so wouldn't reach a root-level\n * bubble-phase listener. `delegate()` flips to capture for these; the\n * caller doesn't need to know or care.\n *\n * Membership is conservative — it covers the cases that \"should obviously\n * work\" with delegate() but otherwise don't. For exotic non-bubbling events\n * (custom events, less-common DOM events) the explicit `delegateCapture()`\n * remains the escape hatch.\n */\nexport const NON_BUBBLING = new Set<string>([\n 'focus',\n 'blur',\n 'scroll',\n 'load',\n 'error',\n 'mouseenter',\n 'mouseleave',\n]);\n\n/**\n * How the selector is matched against the event's target:\n *\n * - `'closest'` (the default for both helpers) — walk UP from `event.target`\n * via `closest(selector)`, firing for the nearest matching ancestor inside\n * `rootEl`. This is the delegation behavior you almost always want: a click\n * on an icon inside a button fires the button's handler.\n * - `'direct'` — strict `matches()` match: fire only when `event.target`\n * itself matches the selector, with no walk-up.\n */\nexport interface DelegateOptions {\n match?: 'closest' | 'direct';\n}\n\n/**\n * Validate a CSS selector at registration time, so a typo throws immediately\n * with the bad selector quoted instead of producing a cryptic DOMException\n * the first time a matching event fires.\n */\nfunction assertValidSelector(selector: string, fn: string): void {\n try {\n document.createElement('div').matches(selector);\n } catch {\n throw new Error(\n `${fn}: invalid selector \"${selector}\". ` +\n \"Pass a valid CSS selector (e.g. '[data-action=\\\"add\\\"]', '.btn', 'input').\",\n );\n }\n}\n\n/**\n * Per-root registry of the delegates installed on that root, and the per-event\n * dispatch snapshot. Both live ON the DOM objects, under one symbol key (a\n * root and an event are never the same object), rather than in module-level\n * maps — so they are collected with the root / event and add no module-level\n * mutable state (Design rule 5).\n */\nconst KEY = Symbol();\n\n/**\n * Resolves one delegate's selector against an event's target: the bound\n * handler call for a match, `undefined` otherwise.\n */\ntype Resolve = (event: Event) => (() => void) | undefined;\n\ninterface Registered {\n [KEY]?: Set<Resolve>;\n}\n\ninterface Snapshotted {\n [KEY]?: Map<Resolve, (() => void) | undefined>;\n}\n\n/**\n * Install one root-level delegate — the shared core of `delegate()`,\n * `delegateCapture()`, and `kerfjs/actions`' `delegateActions()`.\n *\n * The listener resolves the event's target to a matched element (walk-up\n * `closest()` or strict `matches()`, per `options.match`) that must lie inside\n * `rootEl`, then runs the call `bind(event, matched)` prepared. `bind` runs at\n * RESOLUTION time, so a caller can read matched-element state there (such as\n * `delegateActions`' action attribute) before any handler has mutated it.\n *\n * **Dispatch snapshot.** A handler that writes a signal makes `mount()` morph\n * synchronously, inside the same dispatch, and the morph can recycle the\n * clicked element in place into a control with a different selector identity\n * (same tag, same position, new `data-action`). Resolving later delegates\n * against that live DOM would fire one the user never clicked — typically one\n * that immediately undoes the first handler's state change. So the FIRST kerf\n * delegate listener to see an event resolves every kerf delegate on the\n * event's propagation path (fixed at dispatch start, per the DOM spec, and\n * listed by `composedPath()`) before any delegated handler runs, and stores\n * the results on the event; each listener then consumes its own entry. The\n * set of delegates an event reaches is fixed when it starts dispatching, like\n * per-element listeners. The matched element must also still be inside\n * `rootEl` when the listener runs: a handler that removed the target still\n * suppresses the later delegates, as before.\n *\n * A missing entry (a re-dispatch of the same event object, a delegate added\n * mid-dispatch, or a root hidden from the first listener by a closed shadow\n * boundary) takes a fresh snapshot. Accepted residuals: a same-path\n * re-dispatch after a stopped dispatch can reuse an unconsumed entry if all\n * earlier kerf listeners were disposed, and a closed shadow boundary can\n * hide delegates from the first listener's path view. See docs/5 §5.2.1.\n * Internal — exported for `kerfjs/actions`.\n */\nexport function _delegate(\n rootEl: HTMLElement,\n type: string,\n selector: string,\n bind: (event: Event, matched: Element) => () => void,\n options: DelegateOptions | undefined,\n capture: boolean,\n fn: 'delegate' | 'delegateCapture',\n): () => void {\n assertValidSelector(selector, fn);\n devHooks.delegateInEffect?.(fn);\n const direct = options?.match === 'direct';\n const resolve: Resolve = (event) => {\n const target = event.target;\n if (event.type === type && target instanceof Element) {\n const matched = direct\n ? target.matches(selector)\n ? target\n : null\n : target.closest(selector);\n if (matched !== null) {\n const run = bind(event, matched);\n // Checked when the handler would run, not at resolution: a match\n // outside `rootEl` never fires, and neither does one an earlier\n // handler removed from `rootEl`.\n return () => {\n if (rootEl.contains(matched)) run();\n };\n }\n }\n return undefined;\n };\n const listener = (event: Event): void => {\n let snap = (event as Snapshotted)[KEY];\n if (!snap?.has(resolve)) {\n snap = (event as Snapshotted)[KEY] = new Map();\n for (const node of event.composedPath()) {\n for (const other of (node as Registered)[KEY] ?? []) {\n snap.set(other, other(event));\n }\n }\n }\n const run = snap.get(resolve);\n snap.delete(resolve);\n run?.();\n };\n const registry = ((rootEl as Registered)[KEY] ??= new Set()).add(resolve);\n rootEl.addEventListener(type, listener, capture);\n return () => {\n registry.delete(resolve);\n rootEl.removeEventListener(type, listener, capture);\n };\n}\n\n/**\n * Delegation that \"just works\" for both bubbling and the common non-bubbling\n * events. Installs ONE listener on `rootEl`; for known non-bubblers (see\n * `NON_BUBBLING` above) the listener is registered on the capture phase so\n * it actually reaches the target, otherwise on the bubble phase. Either way,\n * matching walks up from `event.target` via `closest(selector)` and fires\n * `handler(event, matched)` if the match is inside `rootEl`.\n *\n * Pass `{ match: 'direct' }` to fire only when `event.target` itself matches\n * the selector (no walk-up); the default is `'closest'`.\n *\n * The generic `T` narrows the second handler argument to the expected element\n * type — `delegate<HTMLButtonElement>(root, 'click', 'button', (e, btn) => btn.value)`\n * — so consumers can avoid casts. Defaults to `Element` for untyped calls.\n *\n * Returns a disposer that removes the listener.\n *\n * Usage (pseudo-code — see examples for live ones):\n * delegate(rootEl, 'click', '[data-action=\"add\"]', handlerFn);\n * delegate(rootEl, 'focus', 'input', handlerFn); // auto-capture\n */\nexport function delegate<T extends Element = Element>(\n rootEl: HTMLElement,\n type: string,\n selector: string,\n handler: (event: Event, target: T) => void,\n options?: DelegateOptions,\n): () => void {\n return _delegate(\n rootEl,\n type,\n selector,\n (event, matched) => () => handler(event, matched as T),\n options,\n NON_BUBBLING.has(type),\n 'delegate',\n );\n}\n\n/**\n * Capture-phase delegation — the escape hatch for custom non-bubbling events\n * (ones `delegate()`'s auto-promotion list doesn't know about) and for\n * capture-phase interception (run before any descendant's bubble-phase\n * handler). Reaches descendants of `rootEl` that match `selector` regardless\n * of how many times the diff has rebuilt them.\n *\n * Selector matching is `closest()`-style by default — the same walk-up as\n * `delegate()`, and it passes the matched ancestor (not the raw target) to\n * the handler — so a click on any descendant of the selected element climbs\n * to it. Pass `{ match: 'direct' }` to opt into strict `matches()`-style\n * matching (fire only when the event lands on the exact element the selector\n * identifies, with no walk-up).\n *\n * The generic `T` narrows the second handler argument to the expected element\n * type, mirroring `delegate<T>()`. Defaults to `Element` for untyped calls.\n *\n * Usage (pseudo-code — see examples for live ones):\n * delegateCapture(rootEl, 'focus', 'input, textarea', handlerFn);\n * delegateCapture(rootEl, 'click', '.exact', handlerFn, { match: 'direct' });\n */\nexport function delegateCapture<T extends Element = Element>(\n rootEl: HTMLElement,\n type: string,\n selector: string,\n handler: (event: Event, target: T) => void,\n options?: DelegateOptions,\n): () => void {\n return _delegate(\n rootEl,\n type,\n selector,\n (event, matched) => ()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IAAA,CACd,MACA,KAAA,EACqE;AACrE,EAAA,MAAM,WAAA,GAAc,eAAe,IAAI,CAAA;AACvC,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,MAAM,WAAW,CAAA,CAAA,EAAI,WAAW,CAAA,EAAA,EAAK,eAAA,CAAgB,KAAK,CAAC,CAAA,EAAA,CAAA;AAC3D,IAAA,OAAO,OAAO,MAAA,CAAO;AAAA,MACnB,IAAA;AAAA,MACA,KAAA;AAAA,MACA,QAAA;AAAA,MACA,KAAA,EAAO,OAAO,MAAA,CAAO,EAAE,CAAC,IAAI,GAAG,OAAO;AAAA,KACvC,CAAA;AAAA,EACH;AACA,EAAA,OAAO,CAAC,MACN,MAAA,CAAO,MAAA,CAAO,EAAE,CAAC,IAAI,GAAG,CAAA,EAAG,CAAA;AAC/B","file":"chunk-MK42GLPV.js","sourcesContent":["/**\n * `attr(name, value)` — create a pre-computed attribute descriptor (static form).\n * `attr(name)` — create a per-render factory for dynamic attribute values (dynamic form).\n *\n * **Static form** — best for fixed action names, filter keys, role values, etc.\n * Escapes once at module-load time; produces a full {@link AttrSpec} with\n * `.name`, `.value`, `.selector`, and `.attrs`.\n *\n * const ACTIONS = {\n * toggle: attr('data-action', 'toggle'),\n * remove: attr('data-action', 'remove'),\n * } as const satisfies Record<string, AttrSpec<'data-action'>>;\n *\n * // In JSX — spread .attrs (rename-safe; no hardcoded attribute name):\n * <button {...ACTIONS.toggle.attrs}>Toggle</button>\n *\n * // In delegate — use the pre-computed selector:\n * delegate(root, 'click', ACTIONS.toggle.selector, handler);\n *\n * **Dynamic form** — best for per-row data like `data-id`, where the value\n * changes per item but the attribute name is constant.\n * The name is validated and pre-escaped at definition time; calling the\n * returned factory is cheap (it just freezes a one-key object — the value is\n * escaped later by the JSX attribute renderer when the result is spread).\n *\n * const ITEM = { id: attr('data-id') } as const;\n *\n * // In JSX — call the factory inline:\n * <li {...ITEM.id(String(item.id))}>…</li>\n *\n * For ad-hoc compound selectors, concatenate `.selector` strings:\n *\n * delegate(root, 'click',\n * ACTIONS.toggle.selector + attr('data-id', id).selector,\n * handler);\n *\n * Escaping:\n * - Attribute name: escaped as a CSS identifier via `cssEscapeIdent`, which is\n * an SSR-safe (no `CSS.escape`) adaptation of the Mathias Bynens polyfill\n * (https://github.com/mathiasbynens/CSS.escape, MIT licensed — see the\n * Acknowledgements section of LICENSE). Handles\n * control chars, leading digits, non-ASCII, and CSS metacharacters.\n * - Attribute value: embedded in double quotes as a CSS string. Backslashes and\n * double-quote characters are backslash-escaped; control characters are\n * hex-escaped per CSS Syntax Level 3 §3.4.\n *\n * Throws on an empty attribute name (not a valid CSS identifier).\n */\n\n/** Descriptor created by the static {@link attr} overload. */\nexport interface AttrSpec<\n N extends string = string,\n V extends string = string,\n> {\n /** The raw attribute name passed to `attr()`. */\n readonly name: N;\n /** The raw attribute value passed to `attr()`. */\n readonly value: V;\n /** Pre-computed `[name=\"value\"]` CSS selector string, safe to pass to `delegate()`. */\n readonly selector: string;\n /** Spreadable JSX object — `{ [name]: value }` — keeps the attribute name out of JSX literals. */\n readonly attrs: { readonly [K in N]: V };\n}\n\n/**\n * Escape `value` as a CSS identifier (for attribute names, id fragments, etc.).\n * Adapted from the CSS.escape polyfill by Mathias Bynens (MIT).\n */\nfunction cssEscapeIdent(value: string): string {\n if (value === '') {\n throw new Error('attr: attribute name must not be empty');\n }\n const str = String(value);\n let result = '';\n for (let i = 0; i < str.length; i++) {\n const cp = str.charCodeAt(i);\n const ch = str.charAt(i);\n\n // U+0000 NULL → replacement character\n if (cp === 0x0000) {\n result += '�';\n continue;\n }\n // Control characters and DEL: hex-escape\n if ((cp >= 0x0001 && cp <= 0x001f) || cp === 0x007f) {\n result += '\\\\' + cp.toString(16) + ' ';\n continue;\n }\n // Leading digit: hex-escape to avoid \"-NN\" / \"3px\"-style ambiguity\n if (i === 0 && cp >= 0x0030 && cp <= 0x0039) {\n result += '\\\\' + cp.toString(16) + ' ';\n continue;\n }\n // Second char is a digit when first is '-' (e.g. \"-3foo\"): hex-escape digit\n if (\n i === 1 &&\n cp >= 0x0030 &&\n cp <= 0x0039 &&\n str.charCodeAt(0) === 0x002d\n ) {\n result += '\\\\' + cp.toString(16) + ' ';\n continue;\n }\n // Non-ASCII, safe identifier chars (letters, digits, underscore, hyphen)\n if (\n cp >= 0x0080 ||\n cp === 0x002d || // `-`\n cp === 0x005f || // `_`\n (cp >= 0x0030 && cp <= 0x0039) || // 0-9\n (cp >= 0x0041 && cp <= 0x005a) || // A-Z\n (cp >= 0x0061 && cp <= 0x007a) // a-z\n ) {\n result += ch;\n continue;\n }\n // Everything else: backslash-escape\n result += '\\\\' + ch;\n }\n return result;\n}\n\n/**\n * Escape `value` as a CSS double-quoted string (for attribute values in\n * `[attr=\"value\"]` selectors).\n */\nfunction escapeCSSString(value: string): string {\n let result = '';\n for (let i = 0; i < value.length; i++) {\n const cp = value.charCodeAt(i);\n const ch = value.charAt(i);\n if (cp === 0x0000) {\n result += '�';\n } else if ((cp >= 0x0001 && cp <= 0x001f) || cp === 0x007f) {\n // Control chars: hex-escape\n result += '\\\\' + cp.toString(16) + ' ';\n } else if (cp === 0x005c) {\n // Backslash\n result += '\\\\\\\\';\n } else if (cp === 0x0022) {\n // Double quote (the string delimiter we use)\n result += '\\\\\"';\n } else {\n result += ch;\n }\n }\n return result;\n}\n\n/**\n * Static overload — pre-computes the full descriptor at definition time.\n * Returns an {@link AttrSpec} with `.name`, `.value`, `.selector`, and `.attrs`.\n */\nexport function attr<N extends string, V extends string>(\n name: N,\n value: V,\n): AttrSpec<N, V>;\n\n/**\n * Dynamic overload — pre-validates and pre-escapes the attribute name, returns a\n * factory that accepts a per-render value and produces a frozen spreadable object.\n * Use for per-row attributes like `data-id` where the value changes per item.\n * The optional `V` generic constrains which values the factory accepts:\n * `attr<'data-id', 'a'|'b'>('data-id')` → `(value: 'a'|'b') => { 'data-id': 'a'|'b' }`.\n * Leaving both generics off infers `N` from the argument and defaults `V` to `string`.\n */\nexport function attr<N extends string, V extends string = string>(\n name: N,\n): (value: V) => { readonly [K in N]: V };\n\nexport function attr<N extends string, V extends string>(\n name: N,\n value?: V,\n): AttrSpec<N, V> | ((value: string) => { readonly [K in N]: string }) {\n const escapedName = cssEscapeIdent(name); // validates + pre-escapes name in both paths\n if (value !== undefined) {\n const selector = `[${escapedName}=\"${escapeCSSString(value)}\"]`;\n return Object.freeze({\n name,\n value,\n selector,\n attrs: Object.freeze({ [name]: value }) as { readonly [K in N]: V },\n }) as AttrSpec<N, V>;\n }\n return (v: string): { readonly [K in N]: string } =>\n Object.freeze({ [name]: v }) as { readonly [K in N]: string };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { effect, isSignal } from './chunk-
|
|
2
|
-
import { flatten, wrapWithTags, mergeChildSegments } from './chunk-
|
|
3
|
-
import { devHooks } from './chunk-
|
|
1
|
+
import { effect, isSignal } from './chunk-IHMDBBUJ.js';
|
|
2
|
+
import { isOverlayHost, flatten, wrapWithTags, mergeChildSegments } from './chunk-4TX6YJDM.js';
|
|
3
|
+
import { devHooks } from './chunk-3C6F6NM4.js';
|
|
4
4
|
|
|
5
5
|
// src/utils/syncFormProp.ts
|
|
6
6
|
function syncFormProp(el, name, value, present) {
|
|
@@ -17,7 +17,14 @@ function syncFormProp(el, name, value, present) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// src/utils/url-screen.ts
|
|
20
|
-
var URL_ATTRS = /* @__PURE__ */ new Set([
|
|
20
|
+
var URL_ATTRS = /* @__PURE__ */ new Set([
|
|
21
|
+
"href",
|
|
22
|
+
"src",
|
|
23
|
+
"xlink:href",
|
|
24
|
+
"formaction",
|
|
25
|
+
"action",
|
|
26
|
+
"data"
|
|
27
|
+
]);
|
|
21
28
|
var DANGEROUS_SCHEMES = /* @__PURE__ */ new Set(["javascript", "vbscript"]);
|
|
22
29
|
var INERT_JAVASCRIPT_URLS = /* @__PURE__ */ new Set([
|
|
23
30
|
"javascript:",
|
|
@@ -36,24 +43,35 @@ function schemeOf(normalized) {
|
|
|
36
43
|
const m = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(normalized);
|
|
37
44
|
return m ? m[1].toLowerCase() : null;
|
|
38
45
|
}
|
|
39
|
-
function isDangerousDataUrl(normalized) {
|
|
46
|
+
function isDangerousDataUrl(normalized, imageSink) {
|
|
40
47
|
const media = /^data:([^;,]*)/.exec(normalized.toLowerCase())?.[1].trim() ?? "";
|
|
41
|
-
if (media === "" || media === "text/plain" || media === "text/css")
|
|
42
|
-
|
|
48
|
+
if (media === "" || media === "text/plain" || media === "text/css")
|
|
49
|
+
return false;
|
|
50
|
+
if (media === "image/svg+xml") return !imageSink;
|
|
43
51
|
if (media.startsWith("image/")) return false;
|
|
44
|
-
if (media.startsWith("font/") || media.startsWith("application/font"))
|
|
52
|
+
if (media.startsWith("font/") || media.startsWith("application/font"))
|
|
53
|
+
return false;
|
|
45
54
|
if (media.startsWith("audio/") || media.startsWith("video/")) return false;
|
|
46
55
|
return true;
|
|
47
56
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
57
|
+
function isUrlAttrName(name) {
|
|
58
|
+
return URL_ATTRS.has(/[A-Z]/.test(name) ? name.toLowerCase() : name);
|
|
59
|
+
}
|
|
60
|
+
function isImageUrlSink(tag, name) {
|
|
61
|
+
return /^(?:img:src|image:(?:xlink:)?href)$/i.test(`${tag}:${name}`);
|
|
62
|
+
}
|
|
63
|
+
function isDangerousUrlValue(name, value, tag = "") {
|
|
64
|
+
return isUrlAttrName(name) && isDangerousUrl(value, isImageUrlSink(tag, name));
|
|
65
|
+
}
|
|
66
|
+
function isDangerousUrl(value, imageSink = false) {
|
|
67
|
+
if (!value.includes(":")) return false;
|
|
50
68
|
const normalized = normalizeUrl(value);
|
|
51
69
|
const scheme = schemeOf(normalized);
|
|
52
70
|
if (scheme === null) return false;
|
|
53
71
|
if (DANGEROUS_SCHEMES.has(scheme)) {
|
|
54
72
|
return !INERT_JAVASCRIPT_URLS.has(normalized.trimEnd().toLowerCase());
|
|
55
73
|
}
|
|
56
|
-
return scheme === "data" && isDangerousDataUrl(normalized);
|
|
74
|
+
return scheme === "data" && isDangerousDataUrl(normalized, imageSink);
|
|
57
75
|
}
|
|
58
76
|
function dangerousUrlWarning(name, value) {
|
|
59
77
|
return `dropped dangerous URL value for ${name}=${JSON.stringify(value.slice(0, DANGEROUS_URL_DIAGNOSTIC_VALUE_LENGTH))}. kerf blocks javascript:, vbscript:, and script-executing data: URLs (text/html, image/svg+xml, xml) in href/src/data/formaction/action/xlink:href by default. Wrap in raw() if this is intentional (e.g. bookmarklets), or sanitize upstream.`;
|
|
@@ -121,49 +139,54 @@ function bindText(signal) {
|
|
|
121
139
|
}
|
|
122
140
|
return null;
|
|
123
141
|
}
|
|
124
|
-
function wireBindings(rootEl, ctx, prevDisposers) {
|
|
142
|
+
function wireBindings(rootEl, ctx, prevDisposers, rows) {
|
|
125
143
|
for (const d of prevDisposers) d();
|
|
126
144
|
if (ctx.list.length === 0) return NO_DISPOSERS;
|
|
127
145
|
const disposers = [];
|
|
128
|
-
|
|
146
|
+
try {
|
|
147
|
+
wireInto(rootEl, ctx.list, disposers, rows);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
for (const d of disposers) d();
|
|
150
|
+
throw err;
|
|
151
|
+
}
|
|
129
152
|
return disposers;
|
|
130
153
|
}
|
|
131
154
|
function wireRowBindings(rowNode, bindings) {
|
|
132
|
-
const disposers =
|
|
155
|
+
const disposers = [];
|
|
133
156
|
const rootIds = rowNode.getAttribute(BIND_ATTR_ROW);
|
|
134
157
|
let rootIdSet = null;
|
|
135
|
-
let
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (rootIds
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
158
|
+
let markers = null;
|
|
159
|
+
const rowMarkers = () => markers ??= indexMarkers(rowNode, BIND_ATTR_ROW, ROW_TEXT_PREFIX);
|
|
160
|
+
try {
|
|
161
|
+
for (let i = 0; i < bindings.length; i++) {
|
|
162
|
+
const b = bindings[i];
|
|
163
|
+
if (b.kind === "attr") {
|
|
164
|
+
let onRoot = false;
|
|
165
|
+
if (rootIds !== null) {
|
|
166
|
+
if (rootIds === b.id) {
|
|
167
|
+
onRoot = true;
|
|
168
|
+
} else if (rootIds.indexOf(",") !== -1) {
|
|
169
|
+
rootIdSet ??= new Set(rootIds.split(","));
|
|
170
|
+
onRoot = rootIdSet.has(b.id);
|
|
171
|
+
}
|
|
147
172
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
173
|
+
let el;
|
|
174
|
+
if (onRoot) {
|
|
175
|
+
el = rowNode;
|
|
176
|
+
} else {
|
|
177
|
+
el = rowMarkers().attrs.get(b.id);
|
|
178
|
+
}
|
|
179
|
+
if (el === void 0) continue;
|
|
180
|
+
disposers.push(attachAttrEffect(el, b.attr, b.signal));
|
|
152
181
|
} else {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (el === void 0) continue;
|
|
157
|
-
disposers[i] = attachAttrEffect(el, b.attr, b.signal);
|
|
158
|
-
} else {
|
|
159
|
-
if (textMarkers === null) {
|
|
160
|
-
textMarkers = /* @__PURE__ */ new Map();
|
|
161
|
-
collectComments(rowNode, ROW_TEXT_PREFIX, textMarkers);
|
|
182
|
+
const marker = rowMarkers().texts.get(b.id);
|
|
183
|
+
if (marker === void 0) continue;
|
|
184
|
+
disposers.push(attachTextEffect(marker, b.signal));
|
|
162
185
|
}
|
|
163
|
-
const marker = textMarkers.get(b.id);
|
|
164
|
-
if (marker === void 0) continue;
|
|
165
|
-
disposers[i] = attachTextEffect(marker, b.signal);
|
|
166
186
|
}
|
|
187
|
+
} catch (err) {
|
|
188
|
+
for (const d of disposers) d();
|
|
189
|
+
throw err;
|
|
167
190
|
}
|
|
168
191
|
return disposers;
|
|
169
192
|
}
|
|
@@ -190,28 +213,35 @@ function carryOrRewireRowBindings(node, oldBindings, oldDisposers, newBindings)
|
|
|
190
213
|
bindingDisposers: newLen > 0 ? wireRowBindings(node, newBindings) : void 0
|
|
191
214
|
};
|
|
192
215
|
}
|
|
193
|
-
function wireInto(scope, bindings, disposers) {
|
|
194
|
-
const
|
|
195
|
-
const textMarkers = /* @__PURE__ */ new Map();
|
|
196
|
-
collectComments(scope, TEXT_MARKER_PREFIX, textMarkers);
|
|
216
|
+
function wireInto(scope, bindings, disposers, rows) {
|
|
217
|
+
const markers = indexMarkers(scope, BIND_ATTR, TEXT_MARKER_PREFIX, rows);
|
|
197
218
|
for (const b of bindings) {
|
|
198
219
|
if (b.kind === "attr") {
|
|
199
|
-
const el =
|
|
220
|
+
const el = markers.attrs.get(b.id);
|
|
200
221
|
if (el === void 0) continue;
|
|
201
222
|
disposers.push(attachAttrEffect(el, b.attr, b.signal));
|
|
202
223
|
} else {
|
|
203
|
-
const marker =
|
|
224
|
+
const marker = markers.texts.get(b.id);
|
|
204
225
|
if (marker === void 0) continue;
|
|
205
226
|
disposers.push(attachTextEffect(marker, b.signal));
|
|
206
227
|
}
|
|
207
228
|
}
|
|
208
229
|
}
|
|
209
|
-
function
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
230
|
+
function indexMarkers(node, attrName, textPrefix, skip, out = { attrs: /* @__PURE__ */ new Map(), texts: /* @__PURE__ */ new Map() }) {
|
|
231
|
+
for (let c = node.firstChild; c !== null; c = c.nextSibling) {
|
|
232
|
+
if (c.nodeType === Node.COMMENT_NODE) {
|
|
233
|
+
const data = c.data;
|
|
234
|
+
if (data.startsWith(textPrefix))
|
|
235
|
+
out.texts.set(data.slice(textPrefix.length), c);
|
|
236
|
+
} else if (c.nodeType === Node.ELEMENT_NODE) {
|
|
237
|
+
const el = c;
|
|
238
|
+
if (skip?.has(el) || isOverlayHost(el)) continue;
|
|
239
|
+
const ids = el.getAttribute(attrName);
|
|
240
|
+
if (ids !== null) for (const id of ids.split(",")) out.attrs.set(id, el);
|
|
241
|
+
indexMarkers(el, attrName, textPrefix, skip, out);
|
|
242
|
+
}
|
|
213
243
|
}
|
|
214
|
-
return
|
|
244
|
+
return out;
|
|
215
245
|
}
|
|
216
246
|
function attachAttrEffect(el, attr, signal) {
|
|
217
247
|
return effect(() => setBoundAttr(el, attr, signal.value));
|
|
@@ -250,7 +280,7 @@ function setBoundAttr(el, name, value) {
|
|
|
250
280
|
return;
|
|
251
281
|
}
|
|
252
282
|
const str = String(value);
|
|
253
|
-
if (isDangerousUrlValue(name, str)) {
|
|
283
|
+
if (isDangerousUrlValue(name, str, el.localName)) {
|
|
254
284
|
reportDangerousUrl("kerf binding", name, str);
|
|
255
285
|
el.removeAttribute(name);
|
|
256
286
|
return;
|
|
@@ -266,23 +296,33 @@ function coerceText(value) {
|
|
|
266
296
|
if (value == null || typeof value === "boolean") return "";
|
|
267
297
|
return String(value);
|
|
268
298
|
}
|
|
269
|
-
function collectComments(node, prefix, out) {
|
|
270
|
-
for (let c = node.firstChild; c !== null; c = c.nextSibling) {
|
|
271
|
-
if (c.nodeType === Node.COMMENT_NODE) {
|
|
272
|
-
const data = c.data;
|
|
273
|
-
if (data.startsWith(prefix)) out.set(data.slice(prefix.length), c);
|
|
274
|
-
} else if (c.nodeType === Node.ELEMENT_NODE) {
|
|
275
|
-
collectComments(c, prefix, out);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
299
|
|
|
280
300
|
// src/utils/escapeHtml.ts
|
|
301
|
+
var ENTITIES = {
|
|
302
|
+
"&": "&",
|
|
303
|
+
"<": "<",
|
|
304
|
+
">": ">",
|
|
305
|
+
'"': """,
|
|
306
|
+
"'": "'"
|
|
307
|
+
};
|
|
308
|
+
function escapeWith(str, special) {
|
|
309
|
+
special.lastIndex = 0;
|
|
310
|
+
let out = "";
|
|
311
|
+
let last = 0;
|
|
312
|
+
let match;
|
|
313
|
+
while (match = special.exec(str)) {
|
|
314
|
+
out += str.slice(last, match.index) + ENTITIES[match[0]];
|
|
315
|
+
last = special.lastIndex;
|
|
316
|
+
}
|
|
317
|
+
return last ? out + str.slice(last) : str;
|
|
318
|
+
}
|
|
319
|
+
var HTML_SPECIAL = /[&<>"]/g;
|
|
320
|
+
var ATTR_SPECIAL = /[&"'<>]/g;
|
|
281
321
|
function escapeHtml(str) {
|
|
282
|
-
return str
|
|
322
|
+
return escapeWith(str, HTML_SPECIAL);
|
|
283
323
|
}
|
|
284
324
|
function escapeAttr(str) {
|
|
285
|
-
return str
|
|
325
|
+
return escapeWith(str, ATTR_SPECIAL);
|
|
286
326
|
}
|
|
287
327
|
|
|
288
328
|
// src/utils/jsx-attr-aliases.ts
|
|
@@ -386,19 +426,27 @@ var ATTR_ALIASES = {
|
|
|
386
426
|
// src/jsx-runtime.ts
|
|
387
427
|
var SAFE_HTML_BRAND2 = /* @__PURE__ */ Symbol.for("kerfjs.SafeHtml");
|
|
388
428
|
var SafeHtml = class {
|
|
389
|
-
__html;
|
|
390
429
|
__segment;
|
|
391
430
|
// Branded so `isSafeHtml()` recognizes instances from any copy of this module.
|
|
392
431
|
[SAFE_HTML_BRAND2] = true;
|
|
432
|
+
// The flattened HTML, computed on first read. A structured segment wraps its
|
|
433
|
+
// children's segments rather than their strings, so flattening eagerly made
|
|
434
|
+
// every element above an `each()` copy all of the list's row HTML again —
|
|
435
|
+
// O(depth × rows) per render, while `mount()` reads only the segment.
|
|
436
|
+
#html;
|
|
393
437
|
constructor(input) {
|
|
394
438
|
if (typeof input === "string") {
|
|
395
439
|
this.__segment = { kind: "static", html: input };
|
|
396
|
-
this
|
|
440
|
+
this.#html = input;
|
|
397
441
|
} else {
|
|
398
442
|
this.__segment = input;
|
|
399
|
-
|
|
443
|
+
if (input.kind === "static") this.#html = input.html;
|
|
400
444
|
}
|
|
401
445
|
}
|
|
446
|
+
/** The flattened HTML string (what `toString()` returns). */
|
|
447
|
+
get __html() {
|
|
448
|
+
return this.#html ??= flatten(this.__segment, false);
|
|
449
|
+
}
|
|
402
450
|
toString() {
|
|
403
451
|
return this.__html;
|
|
404
452
|
}
|
|
@@ -431,17 +479,22 @@ var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
|
431
479
|
"wbr"
|
|
432
480
|
]);
|
|
433
481
|
function toSegment(child) {
|
|
434
|
-
if (child == null || typeof child === "boolean")
|
|
482
|
+
if (child == null || typeof child === "boolean")
|
|
483
|
+
return { kind: "static", html: "" };
|
|
435
484
|
if (isSignal(child)) {
|
|
436
485
|
const marker = bindText(child);
|
|
437
486
|
if (marker !== null) return { kind: "static", html: marker };
|
|
438
487
|
const v = child.value;
|
|
439
|
-
return {
|
|
488
|
+
return {
|
|
489
|
+
kind: "static",
|
|
490
|
+
html: v == null || typeof v === "boolean" ? "" : escapeHtml(String(v))
|
|
491
|
+
};
|
|
440
492
|
}
|
|
441
493
|
if (isSafeHtml(child)) {
|
|
442
494
|
return child.__segment ?? { kind: "static", html: child.__html };
|
|
443
495
|
}
|
|
444
|
-
if (typeof child === "string")
|
|
496
|
+
if (typeof child === "string")
|
|
497
|
+
return { kind: "static", html: escapeHtml(child) };
|
|
445
498
|
if (typeof child === "number") return { kind: "static", html: String(child) };
|
|
446
499
|
if (Array.isArray(child)) return mergeChildSegments(child.map(toSegment));
|
|
447
500
|
const maybeNode = child;
|
|
@@ -451,7 +504,7 @@ function toSegment(child) {
|
|
|
451
504
|
);
|
|
452
505
|
}
|
|
453
506
|
throw new Error(
|
|
454
|
-
`JSX: unsupported child of type ${describeValue(child)}. Children must be SafeHtml, string, number, boolean, null, undefined, or
|
|
507
|
+
`JSX: unsupported child of type ${describeValue(child)}. Children must be SafeHtml, string, number, boolean, null, undefined, a signal/computed, or a nested array of those. Common mistakes: passing a Store object directly (use store.state.value), passing a function (call it first), or passing a Promise (await it before render).`
|
|
455
508
|
);
|
|
456
509
|
}
|
|
457
510
|
function describeValue(v) {
|
|
@@ -485,12 +538,23 @@ See docs/5-event-delegation.md for the tier-1/tier-2/tier-3 model.`
|
|
|
485
538
|
);
|
|
486
539
|
}
|
|
487
540
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
541
|
+
var VALIDATED_ATTR_NAMES = /* @__PURE__ */ new Map();
|
|
542
|
+
var VALIDATED_ATTR_NAMES_MAX = 1024;
|
|
543
|
+
function checkAttrName(key, name, isFn) {
|
|
544
|
+
const cached = VALIDATED_ATTR_NAMES.get(name);
|
|
545
|
+
if (cached !== void 0) return cached;
|
|
546
|
+
assertEmittableAttrName(key, name, isFn);
|
|
547
|
+
const isUrl = isUrlAttrName(name);
|
|
548
|
+
if (VALIDATED_ATTR_NAMES.size < VALIDATED_ATTR_NAMES_MAX)
|
|
549
|
+
VALIDATED_ATTR_NAMES.set(name, isUrl);
|
|
550
|
+
return isUrl;
|
|
551
|
+
}
|
|
552
|
+
function renderAttr(key, value, tag) {
|
|
553
|
+
return renderAttrNamed(key, ATTR_ALIASES[key] ?? key, value, tag);
|
|
554
|
+
}
|
|
555
|
+
function renderAttrNamed(key, name, value, tag) {
|
|
492
556
|
if (value == null || value === false) return "";
|
|
493
|
-
|
|
557
|
+
const isUrlAttr = checkAttrName(key, name, typeof value === "function");
|
|
494
558
|
if (value === true) return ` ${name}`;
|
|
495
559
|
let strValue;
|
|
496
560
|
if (isSafeHtml(value)) {
|
|
@@ -498,7 +562,7 @@ function renderAttrNamed(key, name, value) {
|
|
|
498
562
|
} else if (typeof value === "number") {
|
|
499
563
|
strValue = String(value);
|
|
500
564
|
} else if (typeof value === "string") {
|
|
501
|
-
if (
|
|
565
|
+
if (isUrlAttr && isDangerousUrl(value, isImageUrlSink(tag, name))) {
|
|
502
566
|
reportDangerousUrl("JSX", name, value);
|
|
503
567
|
return "";
|
|
504
568
|
}
|
|
@@ -512,38 +576,45 @@ function renderAttrNamed(key, name, value) {
|
|
|
512
576
|
}
|
|
513
577
|
function jsx(tag, props) {
|
|
514
578
|
if (typeof tag === "function") return tag(props);
|
|
515
|
-
const
|
|
579
|
+
const children = props.children;
|
|
516
580
|
let attrStr = "";
|
|
517
581
|
let bindIds = null;
|
|
518
|
-
for (const
|
|
582
|
+
for (const k in props) {
|
|
583
|
+
if (k === "children" || !Object.hasOwn(props, k)) continue;
|
|
584
|
+
const v = props[k];
|
|
519
585
|
if (isSignal(v)) {
|
|
520
586
|
const name = ATTR_ALIASES[k] ?? k;
|
|
521
|
-
|
|
587
|
+
checkAttrName(k, name, false);
|
|
522
588
|
const id = bindAttr(name, v);
|
|
523
589
|
if (id !== null) {
|
|
524
590
|
(bindIds ??= []).push(id);
|
|
525
591
|
continue;
|
|
526
592
|
}
|
|
527
|
-
attrStr += renderAttr(k, v.value);
|
|
593
|
+
attrStr += renderAttr(k, v.value, tag);
|
|
528
594
|
continue;
|
|
529
595
|
}
|
|
530
|
-
attrStr += renderAttr(k, v);
|
|
596
|
+
attrStr += renderAttr(k, v, tag);
|
|
531
597
|
}
|
|
532
|
-
if (bindIds !== null)
|
|
598
|
+
if (bindIds !== null)
|
|
599
|
+
attrStr += ` ${bindMarkerAttr()}="${bindIds.join(",")}"`;
|
|
533
600
|
if (VOID_TAGS.has(tag)) return new SafeHtml(`<${tag}${attrStr}>`);
|
|
534
601
|
const childSegment = children != null ? toSegment(children) : { kind: "static", html: "" };
|
|
535
|
-
return new SafeHtml(
|
|
602
|
+
return new SafeHtml(
|
|
603
|
+
wrapWithTags(childSegment, `<${tag}${attrStr}>`, `</${tag}>`)
|
|
604
|
+
);
|
|
536
605
|
}
|
|
537
606
|
function Fragment({ children }) {
|
|
538
|
-
return new SafeHtml(
|
|
607
|
+
return new SafeHtml(
|
|
608
|
+
children != null ? toSegment(children) : { kind: "static", html: "" }
|
|
609
|
+
);
|
|
539
610
|
}
|
|
540
611
|
function _toSegment(child) {
|
|
541
612
|
return toSegment(child);
|
|
542
613
|
}
|
|
543
|
-
function _renderAttrVerbatim(name, value) {
|
|
544
|
-
return renderAttrNamed(name, name, value);
|
|
614
|
+
function _renderAttrVerbatim(name, value, tag) {
|
|
615
|
+
return renderAttrNamed(name, name, value, tag);
|
|
545
616
|
}
|
|
546
617
|
|
|
547
618
|
export { Fragment, ROW_TEXT_PREFIX, SafeHtml, TEXT_MARKER_PREFIX, _renderAttrVerbatim, _setBindingContext, _toSegment, assertEmittableAttrName, bindAttr, bindMarkerAttr, boundTextNodeOf, captureRowBindings, carryOrRewireRowBindings, disposeRowBindings, escapeHtml, granularListSafeHtml, isSafeHtml, jsx, listSafeHtml, newBindingContext, raw, syncFormProp, wireBindings, wireRowBindings };
|
|
548
619
|
|
|
549
|
-
//# sourceMappingURL=chunk-
|
|
620
|
+
//# sourceMappingURL=chunk-VX3RCRGG.js.map
|