sigmx 0.1.0 → 0.2.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.
- package/README.md +54 -43
- package/dist/cli.js +3 -1
- package/dist/cli.js.map +2 -2
- package/dist/kernel/compile.d.ts +8 -9
- package/dist/kernel/compile.js +102 -67
- package/dist/kernel/compile.js.map +2 -2
- package/dist/kernel/contracts.d.ts +12 -13
- package/dist/kernel/index.d.ts +11 -12
- package/dist/kernel/index.js +14 -12
- package/dist/kernel/index.js.map +3 -3
- package/dist/kernel/precompile.d.ts +8 -12
- package/dist/kernel/precompile.js +33 -76
- package/dist/kernel/precompile.js.map +2 -2
- package/dist/kernel/precompiled.d.ts +7 -4
- package/dist/kernel/precompiled.js +5 -5
- package/dist/kernel/precompiled.js.map +2 -2
- package/dist/kernel/reactive.d.ts +13 -11
- package/dist/kernel/reactive.js +96 -71
- package/dist/kernel/reactive.js.map +3 -3
- package/dist/kernel/runtime.js +85 -63
- package/dist/kernel/runtime.js.map +3 -3
- package/dist/kernel/scan.d.ts +2 -11
- package/dist/kernel/scan.js +26 -9
- package/dist/kernel/scan.js.map +2 -2
- package/dist/kernel/state.d.ts +5 -8
- package/dist/kernel/state.js +114 -76
- package/dist/kernel/state.js.map +2 -2
- package/dist/kernel/strict-csp.d.ts +0 -5
- package/dist/kernel/strict-csp.js +2 -2
- package/dist/kernel/strict-csp.js.map +2 -2
- package/dist/lib/casing.d.ts +4 -1
- package/dist/lib/casing.js +8 -1
- package/dist/lib/casing.js.map +2 -2
- package/dist/lib/objects.d.ts +5 -4
- package/dist/lib/objects.js +13 -5
- package/dist/lib/objects.js.map +2 -2
- package/dist/lib/schedule.d.ts +3 -5
- package/dist/lib/schedule.js +12 -10
- package/dist/lib/schedule.js.map +2 -2
- package/dist/lib/sse.d.ts +10 -1
- package/dist/lib/sse.js +32 -28
- package/dist/lib/sse.js.map +2 -2
- package/dist/plugins/def.d.ts +5 -0
- package/dist/plugins/def.js +22 -0
- package/dist/plugins/def.js.map +7 -0
- package/dist/plugins/directives/attribute-sync.js +8 -12
- package/dist/plugins/directives/attribute-sync.js.map +2 -2
- package/dist/plugins/directives/boost.d.ts +1 -1
- package/dist/plugins/directives/boost.js +34 -30
- package/dist/plugins/directives/boost.js.map +2 -2
- package/dist/plugins/directives/busy-flag.js +13 -16
- package/dist/plugins/directives/busy-flag.js.map +2 -2
- package/dist/plugins/directives/class-toggle.js +17 -16
- package/dist/plugins/directives/class-toggle.js.map +2 -2
- package/dist/plugins/directives/cloak.js +2 -7
- package/dist/plugins/directives/cloak.js.map +2 -2
- package/dist/plugins/directives/collapse.js +36 -37
- package/dist/plugins/directives/collapse.js.map +2 -2
- package/dist/plugins/directives/declare.js +5 -8
- package/dist/plugins/directives/declare.js.map +2 -2
- package/dist/plugins/directives/derive.js +9 -15
- package/dist/plugins/directives/derive.js.map +2 -2
- package/dist/plugins/directives/element-ref.js +8 -8
- package/dist/plugins/directives/element-ref.js.map +2 -2
- package/dist/plugins/directives/event-listener.js +18 -23
- package/dist/plugins/directives/event-listener.js.map +2 -2
- package/dist/plugins/directives/frame-loop.js +9 -14
- package/dist/plugins/directives/frame-loop.js.map +2 -2
- package/dist/plugins/directives/html.js +6 -7
- package/dist/plugins/directives/html.js.map +2 -2
- package/dist/plugins/directives/inline-style.js +17 -20
- package/dist/plugins/directives/inline-style.js.map +2 -2
- package/dist/plugins/directives/mask.js +19 -23
- package/dist/plugins/directives/mask.js.map +2 -2
- package/dist/plugins/directives/media-query.d.ts +4 -1
- package/dist/plugins/directives/media-query.js +13 -12
- package/dist/plugins/directives/media-query.js.map +2 -2
- package/dist/plugins/directives/on-mount.js +4 -9
- package/dist/plugins/directives/on-mount.js.map +2 -2
- package/dist/plugins/directives/patch-listener.js +24 -19
- package/dist/plugins/directives/patch-listener.js.map +2 -2
- package/dist/plugins/directives/remove-me.js +7 -8
- package/dist/plugins/directives/remove-me.js.map +2 -2
- package/dist/plugins/directives/scroll-to.d.ts +4 -1
- package/dist/plugins/directives/scroll-to.js +8 -14
- package/dist/plugins/directives/scroll-to.js.map +2 -2
- package/dist/plugins/directives/size-watch.js +7 -12
- package/dist/plugins/directives/size-watch.js.map +2 -2
- package/dist/plugins/directives/state-dump.js +6 -10
- package/dist/plugins/directives/state-dump.js.map +2 -2
- package/dist/plugins/directives/storage-sync.js +13 -9
- package/dist/plugins/directives/storage-sync.js.map +2 -2
- package/dist/plugins/directives/teleport.js +8 -14
- package/dist/plugins/directives/teleport.js.map +2 -2
- package/dist/plugins/directives/text-content.js +6 -7
- package/dist/plugins/directives/text-content.js.map +2 -2
- package/dist/plugins/directives/timer.js +7 -13
- package/dist/plugins/directives/timer.js.map +2 -2
- package/dist/plugins/directives/transition.d.ts +1 -2
- package/dist/plugins/directives/transition.js +32 -34
- package/dist/plugins/directives/transition.js.map +2 -2
- package/dist/plugins/directives/tween.d.ts +2 -2
- package/dist/plugins/directives/tween.js +34 -50
- package/dist/plugins/directives/tween.js.map +2 -2
- package/dist/plugins/directives/two-way-bind.d.ts +1 -1
- package/dist/plugins/directives/two-way-bind.js +70 -67
- package/dist/plugins/directives/two-way-bind.js.map +2 -2
- package/dist/plugins/directives/url-params.js +36 -59
- package/dist/plugins/directives/url-params.js.map +3 -3
- package/dist/plugins/directives/url-replace.js +6 -7
- package/dist/plugins/directives/url-replace.js.map +2 -2
- package/dist/plugins/directives/validity.js +6 -9
- package/dist/plugins/directives/validity.js.map +2 -2
- package/dist/plugins/directives/viewport.js +18 -23
- package/dist/plugins/directives/viewport.js.map +2 -2
- package/dist/plugins/directives/visibility.js +9 -14
- package/dist/plugins/directives/visibility.js.map +2 -2
- package/dist/plugins/directives/watch.d.ts +0 -1
- package/dist/plugins/directives/watch.js +2 -8
- package/dist/plugins/directives/watch.js.map +2 -2
- package/dist/plugins/functions/bulk-set.js +10 -7
- package/dist/plugins/functions/bulk-set.js.map +2 -2
- package/dist/plugins/functions/bulk-toggle.js +10 -7
- package/dist/plugins/functions/bulk-toggle.js.map +2 -2
- package/dist/plugins/functions/confirm.js +2 -2
- package/dist/plugins/functions/confirm.js.map +2 -2
- package/dist/plugins/functions/copy-text.js +5 -5
- package/dist/plugins/functions/copy-text.js.map +2 -2
- package/dist/plugins/functions/dispatch.js +5 -5
- package/dist/plugins/functions/dispatch.js.map +2 -2
- package/dist/plugins/functions/locale-format.d.ts +4 -1
- package/dist/plugins/functions/locale-format.js +9 -16
- package/dist/plugins/functions/locale-format.js.map +2 -2
- package/dist/plugins/functions/range-map.js +6 -6
- package/dist/plugins/functions/range-map.js.map +2 -2
- package/dist/plugins/functions/request.d.ts +7 -3
- package/dist/plugins/functions/request.js +85 -80
- package/dist/plugins/functions/request.js.map +2 -2
- package/dist/plugins/functions/untracked-read.js +3 -2
- package/dist/plugins/functions/untracked-read.js.map +2 -2
- package/dist/plugins/functions/websocket.d.ts +3 -3
- package/dist/plugins/functions/websocket.js +18 -25
- package/dist/plugins/functions/websocket.js.map +2 -2
- package/dist/plugins/index.d.ts +34 -36
- package/dist/plugins/index.js +31 -35
- package/dist/plugins/index.js.map +2 -2
- package/dist/plugins/server-events/apply-elements.d.ts +1 -1
- package/dist/plugins/server-events/apply-elements.js +41 -40
- package/dist/plugins/server-events/apply-elements.js.map +2 -2
- package/dist/plugins/server-events/apply-state.js +9 -12
- package/dist/plugins/server-events/apply-state.js.map +2 -2
- package/dist/plugins/server-events/morph.d.ts +0 -2
- package/dist/plugins/server-events/morph.js +58 -55
- package/dist/plugins/server-events/morph.js.map +3 -3
- package/dist/presets/all.d.ts +0 -1
- package/dist/presets/all.js +22 -26
- package/dist/presets/all.js.map +2 -2
- package/dist/presets/essentials.d.ts +0 -1
- package/dist/presets/essentials.js +27 -9
- package/dist/presets/essentials.js.map +2 -2
- package/dist/presets/minimal.d.ts +0 -1
- package/dist/presets/minimal.js +2 -2
- package/dist/presets/minimal.js.map +2 -2
- package/dist/server.d.ts +108 -0
- package/dist/server.js +218 -0
- package/dist/server.js.map +7 -0
- package/dist/sigmx.standalone.js +1 -1
- package/dist/standalone.js.map +2 -2
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +48 -15
- package/dist/vite.js.map +2 -2
- package/package.json +21 -2
- package/dist/auto.d.ts +0 -1
- package/dist/auto.js +0 -7
- package/dist/auto.js.map +0 -7
- package/dist/core/csp.d.ts +0 -7
- package/dist/core/csp.js +0 -20
- package/dist/core/csp.js.map +0 -7
- package/dist/core/engine.d.ts +0 -10
- package/dist/core/engine.js +0 -200
- package/dist/core/engine.js.map +0 -7
- package/dist/core/expr.d.ts +0 -12
- package/dist/core/expr.js +0 -94
- package/dist/core/expr.js.map +0 -7
- package/dist/core/index.d.ts +0 -16
- package/dist/core/index.js +0 -46
- package/dist/core/index.js.map +0 -7
- package/dist/core/signals.d.ts +0 -42
- package/dist/core/signals.js +0 -195
- package/dist/core/signals.js.map +0 -7
- package/dist/core/store.d.ts +0 -32
- package/dist/core/store.js +0 -185
- package/dist/core/store.js.map +0 -7
- package/dist/core/types.d.ts +0 -101
- package/dist/core/types.js +0 -1
- package/dist/core/types.js.map +0 -7
- package/dist/plugins/actions/clipboard.d.ts +0 -2
- package/dist/plugins/actions/clipboard.js +0 -11
- package/dist/plugins/actions/clipboard.js.map +0 -7
- package/dist/plugins/actions/fit.d.ts +0 -2
- package/dist/plugins/actions/fit.js +0 -14
- package/dist/plugins/actions/fit.js.map +0 -7
- package/dist/plugins/actions/intl.d.ts +0 -2
- package/dist/plugins/actions/intl.js +0 -21
- package/dist/plugins/actions/intl.js.map +0 -7
- package/dist/plugins/actions/peek.d.ts +0 -2
- package/dist/plugins/actions/peek.js +0 -6
- package/dist/plugins/actions/peek.js.map +0 -7
- package/dist/plugins/actions/setAll.d.ts +0 -2
- package/dist/plugins/actions/setAll.js +0 -11
- package/dist/plugins/actions/setAll.js.map +0 -7
- package/dist/plugins/actions/toggleAll.d.ts +0 -2
- package/dist/plugins/actions/toggleAll.js +0 -11
- package/dist/plugins/actions/toggleAll.js.map +0 -7
- package/dist/plugins/attributes/attr.d.ts +0 -2
- package/dist/plugins/attributes/attr.js +0 -20
- package/dist/plugins/attributes/attr.js.map +0 -7
- package/dist/plugins/attributes/bind.d.ts +0 -6
- package/dist/plugins/attributes/bind.js +0 -81
- package/dist/plugins/attributes/bind.js.map +0 -7
- package/dist/plugins/attributes/class.d.ts +0 -2
- package/dist/plugins/attributes/class.js +0 -22
- package/dist/plugins/attributes/class.js.map +0 -7
- package/dist/plugins/attributes/computed.d.ts +0 -2
- package/dist/plugins/attributes/computed.js +0 -20
- package/dist/plugins/attributes/computed.js.map +0 -7
- package/dist/plugins/attributes/customValidity.d.ts +0 -2
- package/dist/plugins/attributes/customValidity.js +0 -14
- package/dist/plugins/attributes/customValidity.js.map +0 -7
- package/dist/plugins/attributes/effect.d.ts +0 -2
- package/dist/plugins/attributes/effect.js +0 -12
- package/dist/plugins/attributes/effect.js.map +0 -7
- package/dist/plugins/attributes/indicator.d.ts +0 -2
- package/dist/plugins/attributes/indicator.js +0 -20
- package/dist/plugins/attributes/indicator.js.map +0 -7
- package/dist/plugins/attributes/init.d.ts +0 -2
- package/dist/plugins/attributes/init.js +0 -14
- package/dist/plugins/attributes/init.js.map +0 -7
- package/dist/plugins/attributes/jsonSignals.d.ts +0 -2
- package/dist/plugins/attributes/jsonSignals.js +0 -15
- package/dist/plugins/attributes/jsonSignals.js.map +0 -7
- package/dist/plugins/attributes/matchMedia.d.ts +0 -2
- package/dist/plugins/attributes/matchMedia.js +0 -19
- package/dist/plugins/attributes/matchMedia.js.map +0 -7
- package/dist/plugins/attributes/on.d.ts +0 -5
- package/dist/plugins/attributes/on.js +0 -28
- package/dist/plugins/attributes/on.js.map +0 -7
- package/dist/plugins/attributes/onIntersect.d.ts +0 -2
- package/dist/plugins/attributes/onIntersect.js +0 -28
- package/dist/plugins/attributes/onIntersect.js.map +0 -7
- package/dist/plugins/attributes/onInterval.d.ts +0 -2
- package/dist/plugins/attributes/onInterval.js +0 -18
- package/dist/plugins/attributes/onInterval.js.map +0 -7
- package/dist/plugins/attributes/onRaf.d.ts +0 -1
- package/dist/plugins/attributes/onRaf.js +0 -19
- package/dist/plugins/attributes/onRaf.js.map +0 -7
- package/dist/plugins/attributes/onResize.d.ts +0 -1
- package/dist/plugins/attributes/onResize.js +0 -17
- package/dist/plugins/attributes/onResize.js.map +0 -7
- package/dist/plugins/attributes/onSignalPatch.d.ts +0 -5
- package/dist/plugins/attributes/onSignalPatch.js +0 -35
- package/dist/plugins/attributes/onSignalPatch.js.map +0 -7
- package/dist/plugins/attributes/persist.d.ts +0 -6
- package/dist/plugins/attributes/persist.js +0 -16
- package/dist/plugins/attributes/persist.js.map +0 -7
- package/dist/plugins/attributes/queryString.d.ts +0 -5
- package/dist/plugins/attributes/queryString.js +0 -54
- package/dist/plugins/attributes/queryString.js.map +0 -7
- package/dist/plugins/attributes/ref.d.ts +0 -2
- package/dist/plugins/attributes/ref.js +0 -13
- package/dist/plugins/attributes/ref.js.map +0 -7
- package/dist/plugins/attributes/replaceUrl.d.ts +0 -1
- package/dist/plugins/attributes/replaceUrl.js +0 -11
- package/dist/plugins/attributes/replaceUrl.js.map +0 -7
- package/dist/plugins/attributes/scrollIntoView.d.ts +0 -2
- package/dist/plugins/attributes/scrollIntoView.js +0 -19
- package/dist/plugins/attributes/scrollIntoView.js.map +0 -7
- package/dist/plugins/attributes/show.d.ts +0 -2
- package/dist/plugins/attributes/show.js +0 -19
- package/dist/plugins/attributes/show.js.map +0 -7
- package/dist/plugins/attributes/signals.d.ts +0 -2
- package/dist/plugins/attributes/signals.js +0 -13
- package/dist/plugins/attributes/signals.js.map +0 -7
- package/dist/plugins/attributes/style.d.ts +0 -2
- package/dist/plugins/attributes/style.js +0 -25
- package/dist/plugins/attributes/style.js.map +0 -7
- package/dist/plugins/attributes/text.d.ts +0 -1
- package/dist/plugins/attributes/text.js +0 -13
- package/dist/plugins/attributes/text.js.map +0 -7
- package/dist/plugins/attributes/viewTransition.d.ts +0 -1
- package/dist/plugins/attributes/viewTransition.js +0 -11
- package/dist/plugins/attributes/viewTransition.js.map +0 -7
- package/dist/plugins/directives/transition-name.d.ts +0 -1
- package/dist/plugins/directives/transition-name.js +0 -11
- package/dist/plugins/directives/transition-name.js.map +0 -7
- package/dist/plugins/directives/trap.d.ts +0 -5
- package/dist/plugins/directives/trap.js +0 -48
- package/dist/plugins/directives/trap.js.map +0 -7
- package/dist/sigmx.auto.js +0 -5
- package/dist/utils/object.d.ts +0 -9
- package/dist/utils/object.js +0 -26
- package/dist/utils/object.js.map +0 -7
- package/dist/utils/text.d.ts +0 -7
- package/dist/utils/text.js +0 -15
- package/dist/utils/text.js.map +0 -7
- package/dist/utils/timing.d.ts +0 -14
- package/dist/utils/timing.js +0 -58
- package/dist/utils/timing.js.map +0 -7
package/dist/kernel/state.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/kernel/state.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { expand, type Filter, isPlain, safeKey, toPredicate } from '../lib/objects.js';\nimport { batch, Computed, onSettled, Signal } from './reactive.js';\n\nexport type Patch = Record<string, any>;\n\nexport interface Store {\n /** Value at a dotted path: a leaf value, a namespace proxy, or undefined. Reads subscribe. */\n get(path: string): any;\n /** Replace the value at a path. Plain objects become namespaces; null/undefined removes. */\n set(path: string, value: any): void;\n /** JSON merge-patch (RFC 7396): objects merge, null removes, everything else replaces. */\n merge(patch: Patch, options?: { at?: string; ifMissing?: boolean }): void;\n remove(path: string): void;\n has(path: string): boolean;\n define(path: string, node: Signal<any>): void;\n /** Leaf paths, filtered; `computed: false` leaves out computed signals. */\n paths(filter?: Filter, options?: { computed?: boolean }): string[];\n snapshot(filter?: Filter, options?: { at?: string; computed?: boolean }): Patch;\n /** Called after each settled batch with the nested object of changed paths (null = removed). */\n onPatch(fn: (patch: Patch) => void): () => void;\n readonly $: any;\n}\n\n/** 'a.b.c' \u2192 ['a.b', 'c']; 'a' \u2192 ['', 'a']. */\nconst split = (p: string): [string, string] => {\n const i = p.lastIndexOf('.');\n return [i < 0 ? '' : p.slice(0, i), p.slice(i + 1)];\n};\nconst join = (a: string, b: string): string => (a ? `${a}.${b}` : b);\nconst under = (p: string, at: string): boolean => !at || p.startsWith(`${at}.`);\nconst str = (k: unknown): k is string => typeof k === 'string';\n/** Proxy \u2192 the raw array or object behind it, so a proxied value can be stored or compared. */\nconst rawOf = new WeakMap<object, object>();\n\nexport const createStore = (): Store => {\n const leaves = new Map<string, Signal<any>>();\n const kids = new Map<string, Set<string>>([['', new Set()]]);\n const shape = new Signal(0); // bumped on any structural change; enumerations subscribe to it\n const pending = new Map<string, any>();\n const listeners = new Set<(p: Patch) => void>();\n const nsCache = new Map<string, any>();\n /** Per leaf signal, per raw object: its reactive proxy. */\n const proxies = new WeakMap<Signal<any>, WeakMap<object, any>>();\n\n /** Register `p` under its parent namespace (creating the namespace chain) and mark the shape changed. */\n const link = (p: string): void => {\n const [parent, name] = split(p);\n ensureNs(parent).add(name);\n shape.bump();\n };\n const unlink = (p: string): void => {\n const [parent, name] = split(p);\n kids.get(parent)?.delete(name);\n shape.bump();\n };\n\n const ensureNs = (p: string): Set<string> => {\n let set = kids.get(p);\n if (!set) {\n if (leaves.has(p)) dropLeaf(p);\n set = new Set();\n kids.set(p, set);\n link(p);\n }\n return set;\n };\n\n const dropLeaf = (p: string): void => {\n const s = leaves.get(p);\n if (!s) return;\n leaves.delete(p);\n unlink(p);\n pending.set(p, null);\n s.bump();\n if (s instanceof Computed) s.dispose();\n };\n\n const dropNs = (p: string): void => {\n const set = kids.get(p);\n if (!set) return;\n for (const k of [...set]) remove(join(p, k));\n if (p) {\n kids.delete(p);\n nsCache.delete(p);\n unlink(p);\n }\n };\n\n const remove = (p: string): void =>\n batch(() => {\n dropLeaf(p);\n dropNs(p);\n });\n\n const define = (p: string, node: Signal<any>): void =>\n batch(() => {\n dropNs(p);\n const old = leaves.get(p);\n leaves.set(p, node);\n link(p);\n if (old) {\n old.bump();\n if (old instanceof Computed) old.dispose();\n }\n });\n\n const set = (p: string, v: any): void =>\n batch(() => {\n if (v == null) return remove(p);\n v = (v && rawOf.get(v)) ?? v;\n if (isPlain(v)) {\n for (const k of [...ensureNs(p)]) if (!(k in v)) remove(join(p, k));\n for (const k in v) if (safeKey(k)) set(join(p, k), v[k]);\n return;\n }\n dropNs(p);\n const s = leaves.get(p);\n if (s instanceof Computed) throw new Error(`computed \"${p}\" is read-only`);\n if (s) {\n if (Object.is(s.peek(), v)) return;\n s.value = v;\n } else {\n define(p, new Signal(v));\n }\n pending.set(p, v);\n });\n\n const merge = (patch: Patch, { at = '', ifMissing = false } = {}): void =>\n batch(() => {\n if (!isPlain(patch)) return;\n const keys = Object.keys(patch).filter(safeKey);\n if (keys.length) ensureNs(at);\n for (const k of keys) {\n const p = join(at, k);\n const v = patch[k];\n const leaf = leaves.get(p);\n // Existing values win under ifMissing, and computed leaves are never overwritten by a patch.\n if (leaf && (ifMissing || leaf instanceof Computed)) continue;\n if (v === null) {\n if (!ifMissing) remove(p);\n } else if (isPlain(v)) merge(v, { at: p, ifMissing });\n else if (!(ifMissing && kids.has(p))) set(p, v);\n }\n });\n\n const has = (p: string): boolean => leaves.has(p) || kids.has(p);\n\n /**\n * Arrays are returned through a proxy so in-place mutation notifies the leaf: writes anywhere\n * inside (nested objects and arrays included) bump the leaf, and array methods run as one batch.\n * Proxies are cached per leaf, so the same object under two paths notifies both.\n */\n const wrapArray = (raw: any[], s: Signal<any>, p: string): any => {\n let cache = proxies.get(s);\n if (!cache) {\n cache = new WeakMap();\n proxies.set(s, cache);\n }\n const touch = () => {\n pending.set(p, raw);\n s.bump();\n return true;\n };\n const wrap = (target: object): any => {\n let px = cache?.get(target);\n if (!px) {\n px = new Proxy(target, {\n get: (t, k, r) => {\n const v = Reflect.get(t, k, r);\n if (typeof v === 'function' && Array.isArray(t)) return (...a: any[]) => batch(() => v.apply(r, a));\n if (!v || typeof v !== 'object' || !(Array.isArray(v) || isPlain(v))) return v;\n const d = Object.getOwnPropertyDescriptor(t, k);\n return d && !d.configurable && !d.writable ? v : wrap(v); // frozen data: the proxy invariant forbids wrapping\n },\n set: (t, k, v) => {\n (t as any)[k] = (v && rawOf.get(v)) ?? v;\n return touch();\n },\n deleteProperty: (t, k) => {\n delete (t as any)[k];\n return touch();\n },\n });\n cache?.set(target, px);\n rawOf.set(px, target);\n }\n return px;\n };\n return wrap(raw);\n };\n\n const get = (p: string): any => {\n const s = leaves.get(p);\n if (s) {\n const v = s.value;\n return Array.isArray(v) ? wrapArray(v, s, p) : v;\n }\n shape.value; // subscribe: a namespace may become a leaf, and a missing path may appear\n if (kids.has(p)) return ns(p);\n };\n\n const ns = (p: string): any => {\n let px = nsCache.get(p);\n if (!px) {\n const names = (k: unknown): k is string => {\n shape.value; // read so the effect tracks shape changes\n return str(k) && !!kids.get(p)?.has(k);\n };\n px = new Proxy(\n {},\n {\n get: (_, k) =>\n !str(k) ? undefined : k === 'toJSON' ? () => snapshot(undefined, { at: p }) : get(join(p, k)),\n set: (_, k, v) => {\n if (str(k)) set(join(p, k), v);\n return true;\n },\n deleteProperty: (_, k) => {\n if (str(k)) remove(join(p, k));\n return true;\n },\n has: (_, k) => names(k),\n ownKeys: () => {\n shape.value;\n return [...(kids.get(p) ?? [])];\n },\n getOwnPropertyDescriptor: (_, k) =>\n names(k) ? { enumerable: true, configurable: true, writable: true, value: get(join(p, k)) } : undefined,\n },\n );\n nsCache.set(p, px);\n }\n return px;\n };\n\n const paths = (filter?: Filter, { computed = true } = {}): string[] => {\n shape.value;\n const ok = toPredicate(filter);\n return [...leaves].filter(([p, s]) => ok(p) && (computed || !(s instanceof Computed))).map(([p]) => p);\n };\n\n const snapshot = (filter?: Filter, { at = '', computed = true } = {}): Patch => {\n const out: Patch = {};\n for (const p of paths(filter, { computed }))\n if (under(p, at)) expand(out, at ? p.slice(at.length + 1) : p, leaves.get(p)?.value);\n return out;\n };\n\n onSettled(() => {\n if (!pending.size) return;\n const patch: Patch = {};\n for (const [p, v] of pending) expand(patch, p, v);\n pending.clear();\n for (const fn of listeners) fn(patch);\n });\n\n return {\n get,\n set,\n merge,\n remove,\n has,\n define,\n paths,\n snapshot,\n onPatch: (fn) => {\n listeners.add(fn);\n return () => listeners.delete(fn);\n },\n get $() {\n return ns('');\n },\n };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,QAAqB,SAAS,SAAS,mBAAmB;AACnE,SAAS,OAAO,UAAU,WAAW,cAAc;AAuBnD,MAAM,QAAQ,CAAC,MAAgC;AAC7C,QAAM,IAAI,EAAE,YAAY,GAAG;AAC3B,SAAO,CAAC,IAAI,IAAI,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,MAAM,IAAI,CAAC,CAAC;AACpD;AACA,MAAM,OAAO,CAAC,GAAW,MAAuB,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK;AAClE,MAAM,QAAQ,CAAC,GAAW,OAAwB,CAAC,MAAM,EAAE,WAAW,GAAG,EAAE,GAAG;AAC9E,MAAM,MAAM,CAAC,MAA4B,OAAO,MAAM;AAEtD,MAAM,QAAQ,oBAAI,QAAwB;AAEnC,MAAM,cAAc,MAAa;AACtC,QAAM,SAAS,oBAAI,IAAyB;AAC5C,QAAM,OAAO,oBAAI,IAAyB,CAAC,CAAC,IAAI,oBAAI,IAAI,CAAC,CAAC,CAAC;AAC3D,QAAM,QAAQ,IAAI,OAAO,CAAC;AAC1B,QAAM,UAAU,oBAAI,IAAiB;AACrC,QAAM,YAAY,oBAAI,IAAwB;AAC9C,QAAM,UAAU,oBAAI,IAAiB;AAErC,QAAM,UAAU,oBAAI,QAA2C;AAG/D,QAAM,OAAO,CAAC,MAAoB;AAChC,UAAM,CAAC,QAAQ,IAAI,IAAI,MAAM,CAAC;AAC9B,aAAS,MAAM,EAAE,IAAI,IAAI;AACzB,UAAM,KAAK;AAAA,EACb;AACA,QAAM,SAAS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OAAO,EAAE;AAAA,IAClC;AAAA,IACA,IAAI,IAAI;AACN,aAAO,GAAG,EAAE;AAAA,IACd;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["set"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,2 @@
|
|
|
1
1
|
import type { Compiler } from './compile.js';
|
|
2
|
-
/**
|
|
3
|
-
* Compiler for pages with a strict Content-Security-Policy: compiles through a nonce-bearing
|
|
4
|
-
* inline `<script>` (and a Trusted Types policy when present) instead of `new Function`.
|
|
5
|
-
* Pass as `createSigmx({ compile: cspCompiler(nonce) })`.
|
|
6
|
-
*/
|
|
7
2
|
export declare const cspCompiler: (nonce: string) => Compiler;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
let policy;
|
|
1
2
|
const cspCompiler = (nonce) => {
|
|
2
3
|
if (!nonce) throw new Error("cspCompiler needs the page nonce");
|
|
3
|
-
|
|
4
|
-
const policy = tt?.createPolicy("sigmx", { createScript: (s) => s });
|
|
4
|
+
policy ??= window.trustedTypes?.createPolicy("sigmx", { createScript: (s) => s });
|
|
5
5
|
return (params, body) => {
|
|
6
6
|
const script = document.createElement("script");
|
|
7
7
|
script.nonce = nonce;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/kernel/strict-csp.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Compiler } from './compile.js'
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { Compiler } from './compile.js';\n\n/**\n * Compiler for pages with a strict Content-Security-Policy: compiles through a nonce-bearing\n * inline `<script>` (and a Trusted Types policy when present) instead of `new Function`.\n * Pass as `createSigmx({ compile: cspCompiler(nonce) })`.\n */\nlet policy: { createScript(s: string): any } | undefined;\n\nexport const cspCompiler = (nonce: string): Compiler => {\n if (!nonce) throw new Error('cspCompiler needs the page nonce');\n // One Trusted Types policy per page: creating a second one with the same name throws under a strict CSP.\n policy ??= (window as any).trustedTypes?.createPolicy('sigmx', { createScript: (s: string) => s });\n return (params, body) => {\n const script = document.createElement('script');\n script.nonce = nonce;\n const text = `document.currentScript.f=function(${params.join(',')}){${body}}`;\n script.text = policy ? policy.createScript(text) : text;\n document.head.append(script);\n script.remove();\n const fn = (script as any).f;\n if (!fn) throw new Error('the Content-Security-Policy blocked expression compilation');\n return fn;\n };\n};\n"],
|
|
5
|
+
"mappings": "AAOA,IAAI;AAEG,MAAM,cAAc,CAAC,UAA4B;AACtD,MAAI,CAAC,MAAO,OAAM,IAAI,MAAM,kCAAkC;AAE9D,aAAY,OAAe,cAAc,aAAa,SAAS,EAAE,cAAc,CAAC,MAAc,EAAE,CAAC;AACjG,SAAO,CAAC,QAAQ,SAAS;AACvB,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,QAAQ;AACf,UAAM,OAAO,qCAAqC,OAAO,KAAK,GAAG,CAAC,KAAK,IAAI;AAC3E,WAAO,OAAO,SAAS,OAAO,aAAa,IAAI,IAAI;AACnD,aAAS,KAAK,OAAO,MAAM;AAC3B,WAAO,OAAO;AACd,UAAM,KAAM,OAAe;AAC3B,QAAI,CAAC,GAAI,OAAM,IAAI,MAAM,4DAA4D;AACrF,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/casing.d.ts
CHANGED
|
@@ -3,5 +3,8 @@ export declare const kebab: (s: string) => string;
|
|
|
3
3
|
export declare const snake: (s: string) => string;
|
|
4
4
|
export declare const camel: (s: string) => string;
|
|
5
5
|
export declare const pascal: (s: string) => string;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Recase a dotted path segment by segment so `user.first-name` becomes `user.firstName`. Leading
|
|
8
|
+
* underscores survive (`_draft` stays `_draft`); an unknown style is an error.
|
|
9
|
+
*/
|
|
7
10
|
export declare const recase: (path: string, style: CaseStyle) => string;
|
package/dist/lib/casing.js
CHANGED
|
@@ -5,7 +5,14 @@ const snake = (s) => words(s).join("_");
|
|
|
5
5
|
const camel = (s) => words(s).map((w, i) => i ? cap(w) : w).join("");
|
|
6
6
|
const pascal = (s) => words(s).map(cap).join("");
|
|
7
7
|
const styles = { camel, kebab, snake, pascal };
|
|
8
|
-
const recase = (path, style) =>
|
|
8
|
+
const recase = (path, style) => {
|
|
9
|
+
const f = styles[style];
|
|
10
|
+
if (!f) throw new Error(`unknown case "${style}"`);
|
|
11
|
+
return path.split(".").map((seg) => {
|
|
12
|
+
const u = /^_+/.exec(seg)?.[0] ?? "";
|
|
13
|
+
return u + f(seg.slice(u.length));
|
|
14
|
+
}).join(".");
|
|
15
|
+
};
|
|
9
16
|
export {
|
|
10
17
|
camel,
|
|
11
18
|
kebab,
|
package/dist/lib/casing.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/casing.ts"],
|
|
4
|
-
"sourcesContent": ["export type CaseStyle = 'camel' | 'kebab' | 'snake' | 'pascal'
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export type CaseStyle = 'camel' | 'kebab' | 'snake' | 'pascal';\n\nconst words = (s: string): string[] =>\n s\n .replace(/([a-z0-9])([A-Z])|([A-Z]+)([A-Z][a-z])/g, '$1$3 $2$4')\n .split(/[^A-Za-z0-9]+/)\n .filter(Boolean)\n .map((w) => w.toLowerCase());\n\nconst cap = (w: string): string => w[0].toUpperCase() + w.slice(1);\n\nexport const kebab = (s: string): string => words(s).join('-');\nexport const snake = (s: string): string => words(s).join('_');\nexport const camel = (s: string): string =>\n words(s)\n .map((w, i) => (i ? cap(w) : w))\n .join('');\nexport const pascal = (s: string): string => words(s).map(cap).join('');\n\nconst styles = { camel, kebab, snake, pascal };\n\n/**\n * Recase a dotted path segment by segment so `user.first-name` becomes `user.firstName`. Leading\n * underscores survive (`_draft` stays `_draft`); an unknown style is an error.\n */\nexport const recase = (path: string, style: CaseStyle): string => {\n const f = styles[style];\n if (!f) throw new Error(`unknown case \"${style}\"`);\n return path\n .split('.')\n .map((seg) => {\n const u = /^_+/.exec(seg)?.[0] ?? '';\n return u + f(seg.slice(u.length));\n })\n .join('.');\n};\n"],
|
|
5
|
+
"mappings": "AAEA,MAAM,QAAQ,CAAC,MACb,EACG,QAAQ,2CAA2C,WAAW,EAC9D,MAAM,eAAe,EACrB,OAAO,OAAO,EACd,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC;AAE/B,MAAM,MAAM,CAAC,MAAsB,EAAE,CAAC,EAAE,YAAY,IAAI,EAAE,MAAM,CAAC;AAE1D,MAAM,QAAQ,CAAC,MAAsB,MAAM,CAAC,EAAE,KAAK,GAAG;AACtD,MAAM,QAAQ,CAAC,MAAsB,MAAM,CAAC,EAAE,KAAK,GAAG;AACtD,MAAM,QAAQ,CAAC,MACpB,MAAM,CAAC,EACJ,IAAI,CAAC,GAAG,MAAO,IAAI,IAAI,CAAC,IAAI,CAAE,EAC9B,KAAK,EAAE;AACL,MAAM,SAAS,CAAC,MAAsB,MAAM,CAAC,EAAE,IAAI,GAAG,EAAE,KAAK,EAAE;AAEtE,MAAM,SAAS,EAAE,OAAO,OAAO,OAAO,OAAO;AAMtC,MAAM,SAAS,CAAC,MAAc,UAA6B;AAChE,QAAM,IAAI,OAAO,KAAK;AACtB,MAAI,CAAC,EAAG,OAAM,IAAI,MAAM,iBAAiB,KAAK,GAAG;AACjD,SAAO,KACJ,MAAM,GAAG,EACT,IAAI,CAAC,QAAQ;AACZ,UAAM,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK;AAClC,WAAO,IAAI,EAAE,IAAI,MAAM,EAAE,MAAM,CAAC;AAAA,EAClC,CAAC,EACA,KAAK,GAAG;AACb;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/objects.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export declare const isPlain: (v: unknown) => v is Record<string, any>;
|
|
2
|
-
/**
|
|
2
|
+
/** Keys that would walk into Object.prototype are never written: patches can come from a network. */
|
|
3
|
+
export declare const safeKey: (k: string) => boolean;
|
|
3
4
|
export declare const expand: (out: Record<string, any>, path: string, value: any) => Record<string, any>;
|
|
4
5
|
export type Filter = {
|
|
5
|
-
include?: RegExp
|
|
6
|
-
exclude?: RegExp
|
|
6
|
+
include?: RegExp;
|
|
7
|
+
exclude?: RegExp;
|
|
7
8
|
} | ((path: string) => boolean);
|
|
8
|
-
/** Turn `{ include, exclude }`
|
|
9
|
+
/** Turn `{ include, exclude }` regexes or a predicate into a path predicate. */
|
|
9
10
|
export declare const toPredicate: (f?: Filter) => ((path: string) => boolean);
|
package/dist/lib/objects.js
CHANGED
|
@@ -3,24 +3,32 @@ const isPlain = (v) => {
|
|
|
3
3
|
const proto = Object.getPrototypeOf(v);
|
|
4
4
|
return proto === Object.prototype || proto === null;
|
|
5
5
|
};
|
|
6
|
+
const safeKey = (k) => k !== "__proto__" && k !== "constructor" && k !== "prototype";
|
|
6
7
|
const expand = (out, path, value) => {
|
|
7
8
|
const keys = path.split(".");
|
|
9
|
+
if (!keys.every(safeKey)) return out;
|
|
8
10
|
const last = keys.pop();
|
|
9
11
|
let cur = out;
|
|
10
|
-
for (const k of keys)
|
|
12
|
+
for (const k of keys) {
|
|
13
|
+
if (!isPlain(cur[k]) || !Object.hasOwn(cur, k)) cur[k] = {};
|
|
14
|
+
cur = cur[k];
|
|
15
|
+
}
|
|
11
16
|
cur[last] = value;
|
|
12
17
|
return out;
|
|
13
18
|
};
|
|
14
|
-
const re = (v, fallback) => v === void 0 ? fallback : typeof v === "string" ? new RegExp(v.replace(/^\/|\/$/g, "")) : v;
|
|
15
19
|
const toPredicate = (f) => {
|
|
16
20
|
if (typeof f === "function") return f;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
const test = (re, p) => {
|
|
22
|
+
if (!re) return void 0;
|
|
23
|
+
re.lastIndex = 0;
|
|
24
|
+
return re.test(p);
|
|
25
|
+
};
|
|
26
|
+
return (p) => (test(f?.include, p) ?? true) && !test(f?.exclude, p);
|
|
20
27
|
};
|
|
21
28
|
export {
|
|
22
29
|
expand,
|
|
23
30
|
isPlain,
|
|
31
|
+
safeKey,
|
|
24
32
|
toPredicate
|
|
25
33
|
};
|
|
26
34
|
//# sourceMappingURL=objects.js.map
|
package/dist/lib/objects.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/objects.ts"],
|
|
4
|
-
"sourcesContent": ["export const isPlain = (v: unknown): v is Record<string, any> => {\n if (v === null || typeof v !== 'object') return false
|
|
5
|
-
"mappings": "AAAO,MAAM,UAAU,CAAC,MAAyC;AAC/D,MAAI,MAAM,QAAQ,OAAO,MAAM,SAAU,QAAO;AAChD,QAAM,QAAQ,OAAO,eAAe,CAAC;AACrC,SAAO,UAAU,OAAO,aAAa,UAAU;AACjD;AAGO,MAAM,SAAS,CAAC,KAA0B,MAAc,UAAoC;AACjG,QAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,QAAM,OAAO,KAAK,IAAI;AACtB,MAAI,MAAM;AACV,aAAW,KAAK,
|
|
4
|
+
"sourcesContent": ["export const isPlain = (v: unknown): v is Record<string, any> => {\n if (v === null || typeof v !== 'object') return false;\n const proto = Object.getPrototypeOf(v);\n return proto === Object.prototype || proto === null;\n};\n\n/** Keys that would walk into Object.prototype are never written: patches can come from a network. */\nexport const safeKey = (k: string): boolean => k !== '__proto__' && k !== 'constructor' && k !== 'prototype';\n\nexport const expand = (out: Record<string, any>, path: string, value: any): Record<string, any> => {\n const keys = path.split('.');\n if (!keys.every(safeKey)) return out;\n const last = keys.pop() as string;\n let cur = out;\n for (const k of keys) {\n if (!isPlain(cur[k]) || !Object.hasOwn(cur, k)) cur[k] = {};\n cur = cur[k];\n }\n cur[last] = value;\n return out;\n};\n\nexport type Filter = { include?: RegExp; exclude?: RegExp } | ((path: string) => boolean);\n\n/** Turn `{ include, exclude }` regexes or a predicate into a path predicate. */\nexport const toPredicate = (f?: Filter): ((path: string) => boolean) => {\n if (typeof f === 'function') return f;\n // Reset lastIndex so a /g or /y regex gives the same answer for every path.\n const test = (re: RegExp | undefined, p: string) => {\n if (!re) return undefined;\n re.lastIndex = 0;\n return re.test(p);\n };\n return (p) => (test(f?.include, p) ?? true) && !test(f?.exclude, p);\n};\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,UAAU,CAAC,MAAyC;AAC/D,MAAI,MAAM,QAAQ,OAAO,MAAM,SAAU,QAAO;AAChD,QAAM,QAAQ,OAAO,eAAe,CAAC;AACrC,SAAO,UAAU,OAAO,aAAa,UAAU;AACjD;AAGO,MAAM,UAAU,CAAC,MAAuB,MAAM,eAAe,MAAM,iBAAiB,MAAM;AAE1F,MAAM,SAAS,CAAC,KAA0B,MAAc,UAAoC;AACjG,QAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,MAAI,CAAC,KAAK,MAAM,OAAO,EAAG,QAAO;AACjC,QAAM,OAAO,KAAK,IAAI;AACtB,MAAI,MAAM;AACV,aAAW,KAAK,MAAM;AACpB,QAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,OAAO,KAAK,CAAC,EAAG,KAAI,CAAC,IAAI,CAAC;AAC1D,UAAM,IAAI,CAAC;AAAA,EACb;AACA,MAAI,IAAI,IAAI;AACZ,SAAO;AACT;AAKO,MAAM,cAAc,CAAC,MAA4C;AACtE,MAAI,OAAO,MAAM,WAAY,QAAO;AAEpC,QAAM,OAAO,CAAC,IAAwB,MAAc;AAClD,QAAI,CAAC,GAAI,QAAO;AAChB,OAAG,YAAY;AACf,WAAO,GAAG,KAAK,CAAC;AAAA,EAClB;AACA,SAAO,CAAC,OAAO,KAAK,GAAG,SAAS,CAAC,KAAK,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC;AACpE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/schedule.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
export type Mods = Map<string, string[]>;
|
|
2
2
|
type Fn = (...args: any[]) => void;
|
|
3
|
-
/** '300ms' → 300, '2s' → 2000, '150' → 150. */
|
|
3
|
+
/** '300ms' → 300, '2s' → 2000, '150' → 150; `__x.1.5s` arrives split on the dot and is joined back first. */
|
|
4
4
|
export declare const toMs: (args: string[] | undefined, fallback?: number) => number;
|
|
5
5
|
export declare const delay: (fn: Fn, ms: number) => Fn;
|
|
6
6
|
/** Debounce: wait for a quiet period. `leading` fires on the first call, `trailing` on the last. */
|
|
7
7
|
export declare const debounce: (fn: Fn, ms: number, leading?: boolean, trailing?: boolean) => Fn;
|
|
8
8
|
/** Throttle: at most one call per window. `leading` fires immediately, `trailing` fires once at the end. */
|
|
9
9
|
export declare const throttle: (fn: Fn, ms: number, leading?: boolean, trailing?: boolean) => Fn;
|
|
10
|
-
/** Apply `
|
|
11
|
-
export declare const withTiming: (fn: Fn, mods: Mods) => Fn;
|
|
12
|
-
/** Wrap a callback in `document.startViewTransition` when `__viewtransition` is present and supported. */
|
|
13
|
-
export declare const withViewTransition: (fn: Fn, mods: Mods) => Fn;
|
|
10
|
+
/** Apply `__debounce` / `__throttle`; `cleanup` cancels a pending trailing call when the attribute unmounts. */
|
|
11
|
+
export declare const withTiming: (fn: Fn, mods: Mods, cleanup?: (f: () => void) => unknown) => Fn;
|
|
14
12
|
export {};
|
package/dist/lib/schedule.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const toMs = (args, fallback = 0) => {
|
|
2
|
-
for (const a of args
|
|
2
|
+
for (const a of args?.length ? [args.join("."), ...args] : []) {
|
|
3
3
|
const m = /^(\d+(?:\.\d+)?)(ms|s)?$/.exec(a);
|
|
4
4
|
if (m) return +m[1] * (m[2] === "s" ? 1e3 : 1);
|
|
5
5
|
}
|
|
@@ -14,7 +14,7 @@ const limit = (fn, ms, leading, trailing, restart) => {
|
|
|
14
14
|
if (trailing && last) fn(...last);
|
|
15
15
|
last = void 0;
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
const limited = (...args) => {
|
|
18
18
|
if (timer) {
|
|
19
19
|
last = args;
|
|
20
20
|
if (restart) {
|
|
@@ -27,25 +27,27 @@ const limit = (fn, ms, leading, trailing, restart) => {
|
|
|
27
27
|
else last = args;
|
|
28
28
|
timer = setTimeout(fire, ms);
|
|
29
29
|
};
|
|
30
|
+
limited.cancel = () => {
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
timer = last = void 0;
|
|
33
|
+
};
|
|
34
|
+
return limited;
|
|
30
35
|
};
|
|
31
36
|
const debounce = (fn, ms, leading = false, trailing = true) => limit(fn, ms, leading, trailing, true);
|
|
32
37
|
const throttle = (fn, ms, leading = true, trailing = false) => limit(fn, ms, leading, trailing, false);
|
|
33
|
-
const withTiming = (fn, mods) => {
|
|
34
|
-
const d = mods.get("delay");
|
|
35
|
-
if (d) fn = delay(fn, toMs(d));
|
|
38
|
+
const withTiming = (fn, mods, cleanup) => {
|
|
36
39
|
const db = mods.get("debounce");
|
|
37
|
-
if (db) fn = debounce(fn, toMs(db, 300), db.includes("leading"), !db.includes("notrailing"));
|
|
38
40
|
const th = mods.get("throttle");
|
|
39
|
-
if (
|
|
41
|
+
if (db) fn = limit(fn, toMs(db, 300), db.includes("leading"), !db.includes("notrailing"), true);
|
|
42
|
+
if (th) fn = limit(fn, toMs(th, 300), !th.includes("noleading"), th.includes("trailing"), false);
|
|
43
|
+
if (db || th) cleanup?.(fn.cancel);
|
|
40
44
|
return fn;
|
|
41
45
|
};
|
|
42
|
-
const withViewTransition = (fn, mods) => mods.has("viewtransition") && "startViewTransition" in document ? (...args) => void document.startViewTransition(() => fn(...args)) : fn;
|
|
43
46
|
export {
|
|
44
47
|
debounce,
|
|
45
48
|
delay,
|
|
46
49
|
throttle,
|
|
47
50
|
toMs,
|
|
48
|
-
withTiming
|
|
49
|
-
withViewTransition
|
|
51
|
+
withTiming
|
|
50
52
|
};
|
|
51
53
|
//# sourceMappingURL=schedule.js.map
|
package/dist/lib/schedule.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/schedule.ts"],
|
|
4
|
-
"sourcesContent": ["export type Mods = Map<string, string[]
|
|
5
|
-
"mappings": "AAIO,MAAM,OAAO,CAAC,MAA4B,WAAW,MAAc;AACxE,aAAW,KAAK,
|
|
4
|
+
"sourcesContent": ["export type Mods = Map<string, string[]>;\ntype Fn = (...args: any[]) => void;\n\n/** '300ms' \u2192 300, '2s' \u2192 2000, '150' \u2192 150; `__x.1.5s` arrives split on the dot and is joined back first. */\nexport const toMs = (args: string[] | undefined, fallback = 0): number => {\n for (const a of args?.length ? [args.join('.'), ...args] : []) {\n const m = /^(\\d+(?:\\.\\d+)?)(ms|s)?$/.exec(a);\n if (m) return +m[1] * (m[2] === 's' ? 1000 : 1);\n }\n return fallback;\n};\n\nexport const delay =\n (fn: Fn, ms: number): Fn =>\n (...args) =>\n void setTimeout(fn, ms, ...args);\n\n/** Shared rate limiter. `restart` makes it a debounce (the window restarts on every call). */\ntype Limited = Fn & { cancel(): void };\nconst limit = (fn: Fn, ms: number, leading: boolean, trailing: boolean, restart: boolean): Limited => {\n let timer: ReturnType<typeof setTimeout> | undefined;\n let last: any[] | undefined;\n const fire = () => {\n timer = undefined;\n if (trailing && last) fn(...last);\n last = undefined;\n };\n const limited: Limited = (...args) => {\n if (timer) {\n last = args;\n if (restart) {\n clearTimeout(timer);\n timer = setTimeout(fire, ms);\n }\n return;\n }\n if (leading) fn(...args);\n else last = args;\n timer = setTimeout(fire, ms);\n };\n limited.cancel = () => {\n clearTimeout(timer);\n timer = last = undefined;\n };\n return limited;\n};\n\n/** Debounce: wait for a quiet period. `leading` fires on the first call, `trailing` on the last. */\nexport const debounce = (fn: Fn, ms: number, leading = false, trailing = true): Fn =>\n limit(fn, ms, leading, trailing, true);\n\n/** Throttle: at most one call per window. `leading` fires immediately, `trailing` fires once at the end. */\nexport const throttle = (fn: Fn, ms: number, leading = true, trailing = false): Fn =>\n limit(fn, ms, leading, trailing, false);\n\n/** Apply `__debounce` / `__throttle`; `cleanup` cancels a pending trailing call when the attribute unmounts. */\nexport const withTiming = (fn: Fn, mods: Mods, cleanup?: (f: () => void) => unknown): Fn => {\n const db = mods.get('debounce');\n const th = mods.get('throttle');\n if (db) fn = limit(fn, toMs(db, 300), db.includes('leading'), !db.includes('notrailing'), true);\n if (th) fn = limit(fn, toMs(th, 300), !th.includes('noleading'), th.includes('trailing'), false);\n if (db || th) cleanup?.((fn as Limited).cancel);\n return fn;\n};\n"],
|
|
5
|
+
"mappings": "AAIO,MAAM,OAAO,CAAC,MAA4B,WAAW,MAAc;AACxE,aAAW,KAAK,MAAM,SAAS,CAAC,KAAK,KAAK,GAAG,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG;AAC7D,UAAM,IAAI,2BAA2B,KAAK,CAAC;AAC3C,QAAI,EAAG,QAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,MAAM,MAAM,MAAO;AAAA,EAC/C;AACA,SAAO;AACT;AAEO,MAAM,QACX,CAAC,IAAQ,OACT,IAAI,SACF,KAAK,WAAW,IAAI,IAAI,GAAG,IAAI;AAInC,MAAM,QAAQ,CAAC,IAAQ,IAAY,SAAkB,UAAmB,YAA8B;AACpG,MAAI;AACJ,MAAI;AACJ,QAAM,OAAO,MAAM;AACjB,YAAQ;AACR,QAAI,YAAY,KAAM,IAAG,GAAG,IAAI;AAChC,WAAO;AAAA,EACT;AACA,QAAM,UAAmB,IAAI,SAAS;AACpC,QAAI,OAAO;AACT,aAAO;AACP,UAAI,SAAS;AACX,qBAAa,KAAK;AAClB,gBAAQ,WAAW,MAAM,EAAE;AAAA,MAC7B;AACA;AAAA,IACF;AACA,QAAI,QAAS,IAAG,GAAG,IAAI;AAAA,QAClB,QAAO;AACZ,YAAQ,WAAW,MAAM,EAAE;AAAA,EAC7B;AACA,UAAQ,SAAS,MAAM;AACrB,iBAAa,KAAK;AAClB,YAAQ,OAAO;AAAA,EACjB;AACA,SAAO;AACT;AAGO,MAAM,WAAW,CAAC,IAAQ,IAAY,UAAU,OAAO,WAAW,SACvE,MAAM,IAAI,IAAI,SAAS,UAAU,IAAI;AAGhC,MAAM,WAAW,CAAC,IAAQ,IAAY,UAAU,MAAM,WAAW,UACtE,MAAM,IAAI,IAAI,SAAS,UAAU,KAAK;AAGjC,MAAM,aAAa,CAAC,IAAQ,MAAY,YAA6C;AAC1F,QAAM,KAAK,KAAK,IAAI,UAAU;AAC9B,QAAM,KAAK,KAAK,IAAI,UAAU;AAC9B,MAAI,GAAI,MAAK,MAAM,IAAI,KAAK,IAAI,GAAG,GAAG,GAAG,SAAS,SAAS,GAAG,CAAC,GAAG,SAAS,YAAY,GAAG,IAAI;AAC9F,MAAI,GAAI,MAAK,MAAM,IAAI,KAAK,IAAI,GAAG,GAAG,CAAC,GAAG,SAAS,WAAW,GAAG,GAAG,SAAS,UAAU,GAAG,KAAK;AAC/F,MAAI,MAAM,GAAI,WAAW,GAAe,MAAM;AAC9C,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/sse.d.ts
CHANGED
|
@@ -4,7 +4,16 @@ export type ServerEvent = {
|
|
|
4
4
|
id?: string;
|
|
5
5
|
retry?: number;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
type StreamState = {
|
|
8
|
+
id?: string;
|
|
9
|
+
retry?: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Parse one blank-line-delimited block of `field: value` lines (the SSE wire format). `id` and
|
|
13
|
+
* `retry` persist in `state` across blocks; comments start with `:`. Undefined without data lines.
|
|
14
|
+
*/
|
|
15
|
+
export declare const parseBlock: (block: string, state?: StreamState) => ServerEvent | undefined;
|
|
8
16
|
export declare const readEvents: (body: ReadableStream<Uint8Array>, onEvent: (e: ServerEvent) => void) => Promise<void>;
|
|
9
17
|
/** Event payloads: each data line is `key value`; repeated keys join with newlines. */
|
|
10
18
|
export declare const parseFields: (data: string) => Record<string, string>;
|
|
19
|
+
export {};
|
package/dist/lib/sse.js
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
const
|
|
2
|
-
const reader = body.getReader();
|
|
3
|
-
const decoder = new TextDecoder();
|
|
4
|
-
let buffer = "";
|
|
1
|
+
const parseBlock = (block, state = {}) => {
|
|
5
2
|
let event = "";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let retry;
|
|
9
|
-
const flush = () => {
|
|
10
|
-
if (data.length) onEvent({ event: event || "message", data: data.join("\n"), id, retry });
|
|
11
|
-
event = "";
|
|
12
|
-
data = [];
|
|
13
|
-
};
|
|
14
|
-
const line = (l) => {
|
|
15
|
-
if (!l) return flush();
|
|
16
|
-
if (l[0] === ":") return;
|
|
3
|
+
const data = [];
|
|
4
|
+
for (const l of block.split(/\r?\n/)) {
|
|
17
5
|
const c = l.indexOf(":");
|
|
6
|
+
if (!c) continue;
|
|
18
7
|
const field = c < 0 ? l : l.slice(0, c);
|
|
19
|
-
|
|
20
|
-
if (v[0] === " ") v = v.slice(1);
|
|
8
|
+
const v = (c < 0 ? "" : l.slice(c + 1)).replace(/^ /, "");
|
|
21
9
|
if (field === "event") event = v;
|
|
22
10
|
else if (field === "data") data.push(v);
|
|
23
|
-
else if (field === "id") id = v;
|
|
24
|
-
else if (field === "retry" && /^\d+$/.test(v)) retry = +v;
|
|
11
|
+
else if (field === "id") state.id = v;
|
|
12
|
+
else if (field === "retry" && /^\d+$/.test(v)) state.retry = +v;
|
|
13
|
+
}
|
|
14
|
+
if (data.length) return { event: event || "message", data: data.join("\n"), id: state.id, retry: state.retry };
|
|
15
|
+
};
|
|
16
|
+
const readEvents = async (body, onEvent) => {
|
|
17
|
+
const reader = body.getReader();
|
|
18
|
+
const decoder = new TextDecoder();
|
|
19
|
+
const state = {};
|
|
20
|
+
let buffer = "";
|
|
21
|
+
let scan = 0;
|
|
22
|
+
const dispatch = (block) => {
|
|
23
|
+
const e = parseBlock(block, state);
|
|
24
|
+
if (e) onEvent(e);
|
|
25
25
|
};
|
|
26
26
|
for (; ; ) {
|
|
27
27
|
const { value, done } = await reader.read();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
buffer = buffer.slice(
|
|
34
|
-
|
|
28
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
29
|
+
const sep = /\r?\n\r?\n/g;
|
|
30
|
+
sep.lastIndex = scan;
|
|
31
|
+
for (let m = sep.exec(buffer); m; m = sep.exec(buffer)) {
|
|
32
|
+
dispatch(buffer.slice(0, m.index));
|
|
33
|
+
buffer = buffer.slice(m.index + m[0].length);
|
|
34
|
+
sep.lastIndex = 0;
|
|
35
|
+
}
|
|
36
|
+
scan = Math.max(0, buffer.length - 3);
|
|
37
|
+
if (done) {
|
|
38
|
+
dispatch(buffer);
|
|
39
|
+
break;
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
|
-
if (buffer) line(buffer);
|
|
38
|
-
flush();
|
|
39
42
|
};
|
|
40
43
|
const parseFields = (data) => {
|
|
41
44
|
const out = {};
|
|
@@ -49,6 +52,7 @@ ${v}` : v;
|
|
|
49
52
|
return out;
|
|
50
53
|
};
|
|
51
54
|
export {
|
|
55
|
+
parseBlock,
|
|
52
56
|
parseFields,
|
|
53
57
|
readEvents
|
|
54
58
|
};
|
package/dist/lib/sse.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/sse.ts"],
|
|
4
|
-
"sourcesContent": ["export type ServerEvent = { event: string; data: string; id?: string; retry?: number }
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export type ServerEvent = { event: string; data: string; id?: string; retry?: number };\ntype StreamState = { id?: string; retry?: number };\n\n/**\n * Parse one blank-line-delimited block of `field: value` lines (the SSE wire format). `id` and\n * `retry` persist in `state` across blocks; comments start with `:`. Undefined without data lines.\n */\nexport const parseBlock = (block: string, state: StreamState = {}): ServerEvent | undefined => {\n let event = '';\n const data: string[] = [];\n for (const l of block.split(/\\r?\\n/)) {\n const c = l.indexOf(':');\n if (!c) continue;\n const field = c < 0 ? l : l.slice(0, c);\n const v = (c < 0 ? '' : l.slice(c + 1)).replace(/^ /, '');\n if (field === 'event') event = v;\n else if (field === 'data') data.push(v);\n else if (field === 'id') state.id = v;\n else if (field === 'retry' && /^\\d+$/.test(v)) state.retry = +v;\n }\n if (data.length) return { event: event || 'message', data: data.join('\\n'), id: state.id, retry: state.retry };\n};\n\nexport const readEvents = async (\n body: ReadableStream<Uint8Array>,\n onEvent: (e: ServerEvent) => void,\n): Promise<void> => {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n const state: StreamState = {};\n let buffer = '';\n let scan = 0; // where the next separator search starts: no rescanning of a large partial event\n const dispatch = (block: string) => {\n const e = parseBlock(block, state);\n if (e) onEvent(e);\n };\n for (;;) {\n const { value, done } = await reader.read();\n buffer += decoder.decode(value, { stream: !done });\n const sep = /\\r?\\n\\r?\\n/g;\n sep.lastIndex = scan;\n for (let m = sep.exec(buffer); m; m = sep.exec(buffer)) {\n dispatch(buffer.slice(0, m.index));\n buffer = buffer.slice(m.index + m[0].length);\n sep.lastIndex = 0;\n }\n scan = Math.max(0, buffer.length - 3);\n if (done) {\n dispatch(buffer);\n break;\n }\n }\n};\n\n/** Event payloads: each data line is `key value`; repeated keys join with newlines. */\nexport const parseFields = (data: string): Record<string, string> => {\n const out: Record<string, string> = {};\n for (const l of data.split('\\n')) {\n const i = l.indexOf(' ');\n const k = i < 0 ? l : l.slice(0, i);\n const v = i < 0 ? '' : l.slice(i + 1);\n out[k] = k in out ? `${out[k]}\\n${v}` : v;\n }\n return out;\n};\n"],
|
|
5
|
+
"mappings": "AAOO,MAAM,aAAa,CAAC,OAAe,QAAqB,CAAC,MAA+B;AAC7F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3C,UAAI,YAAY;AAAA,IAClB;AACA,WAAO,KAAK,IAAI,GAAG,OAAO,SAAS,CAAC;AACpC,QAAI,MAAM;AACR,eAAS,MAAM;AACf;AAAA,IACF;AAAA,EACF;AACF;AAGO,MAAM,cAAc,CAAC,SAAyC;AACnE,QAAM,MAA8B,CAAC;AACrC,aAAW,KAAK,KAAK,MAAM,IAAI,GAAG;AAChC,UAAM,IAAI,EAAE,QAAQ,GAAG;AACvB,UAAM,IAAI,IAAI,IAAI,IAAI,EAAE,MAAM,GAAG,CAAC;AAClC,UAAM,IAAI,IAAI,IAAI,KAAK,EAAE,MAAM,IAAI,CAAC;AACpC,QAAI,CAAC,IAAI,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC;AAAA,EAAK,CAAC,KAAK;AAAA,EAC1C;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ActionPlugin, AttributePlugin, HandlerPlugin } from '../kernel/contracts.js';
|
|
2
|
+
/** Flags: 1 key required, 2 key forbidden, 4 value required, 8 value forbidden, 32 the value is a literal (`__dynamic` opts into an expression). */
|
|
3
|
+
export declare const dir: (name: string, flags: number, mount: AttributePlugin["mount"], args?: string[]) => AttributePlugin;
|
|
4
|
+
export declare const act: (name: string, call: ActionPlugin["call"]) => ActionPlugin;
|
|
5
|
+
export declare const srv: (name: string, handle: HandlerPlugin["handle"]) => HandlerPlugin;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const rule = (flags, required, forbidden) => flags & required ? "required" : flags & forbidden ? "forbidden" : void 0;
|
|
2
|
+
const dir = (name, flags, mount, args) => ({
|
|
3
|
+
type: "attribute",
|
|
4
|
+
name,
|
|
5
|
+
key: rule(flags, 1, 2),
|
|
6
|
+
value: rule(flags, 4, 8),
|
|
7
|
+
literal: !!(flags & 32),
|
|
8
|
+
args,
|
|
9
|
+
mount
|
|
10
|
+
});
|
|
11
|
+
const act = (name, call) => ({ type: "action", name, call });
|
|
12
|
+
const srv = (name, handle) => ({
|
|
13
|
+
type: "handler",
|
|
14
|
+
name,
|
|
15
|
+
handle
|
|
16
|
+
});
|
|
17
|
+
export {
|
|
18
|
+
act,
|
|
19
|
+
dir,
|
|
20
|
+
srv
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=def.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/plugins/def.ts"],
|
|
4
|
+
"sourcesContent": ["// Compact constructors for the built-in plugins. They build the same objects as `attribute()`,\n// `action()` and `handler()` from the kernel; the numeric flags keep the bundle small.\nimport type { ActionPlugin, AttributePlugin, HandlerPlugin } from '../kernel/contracts.js';\n\ntype Rule = 'required' | 'forbidden' | undefined;\nconst rule = (flags: number, required: number, forbidden: number): Rule =>\n flags & required ? 'required' : flags & forbidden ? 'forbidden' : undefined;\n\n/** Flags: 1 key required, 2 key forbidden, 4 value required, 8 value forbidden, 32 the value is a literal (`__dynamic` opts into an expression). */\nexport const dir = (\n name: string,\n flags: number,\n mount: AttributePlugin['mount'],\n args?: string[],\n): AttributePlugin => ({\n type: 'attribute',\n name,\n key: rule(flags, 1, 2),\n value: rule(flags, 4, 8),\n literal: !!(flags & 32),\n args,\n mount,\n});\nexport const act = (name: string, call: ActionPlugin['call']): ActionPlugin => ({ type: 'action', name, call });\nexport const srv = (name: string, handle: HandlerPlugin['handle']): HandlerPlugin => ({\n type: 'handler',\n name,\n handle,\n});\n"],
|
|
5
|
+
"mappings": "AAKA,MAAM,OAAO,CAAC,OAAe,UAAkB,cAC7C,QAAQ,WAAW,aAAa,QAAQ,YAAY,cAAc;AAG7D,MAAM,MAAM,CACjB,MACA,OACA,OACA,UACqB;AAAA,EACrB,MAAM;AAAA,EACN;AAAA,EACA,KAAK,KAAK,OAAO,GAAG,CAAC;AAAA,EACrB,OAAO,KAAK,OAAO,GAAG,CAAC;AAAA,EACvB,SAAS,CAAC,EAAE,QAAQ;AAAA,EACpB;AAAA,EACA;AACF;AACO,MAAM,MAAM,CAAC,MAAc,UAA8C,EAAE,MAAM,UAAU,MAAM,KAAK;AACtG,MAAM,MAAM,CAAC,MAAc,YAAoD;AAAA,EACpF,MAAM;AAAA,EACN;AAAA,EACA;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dir } from "../def.js";
|
|
2
2
|
const put = (el, name, v) => {
|
|
3
3
|
if (v === false || v == null) el.removeAttribute(name);
|
|
4
|
-
else el.setAttribute(name, v === true ? "" :
|
|
4
|
+
else el.setAttribute(name, v === true ? "" : String(v));
|
|
5
5
|
};
|
|
6
|
-
const attr =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const map = evaluate();
|
|
13
|
-
for (const k in map) put(el, k, map[k]);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
6
|
+
const attr = dir("attr", 4, ({ el, key, cased, evaluate, effect }) => {
|
|
7
|
+
effect(() => {
|
|
8
|
+
if (key) return put(el, cased("kebab"), evaluate());
|
|
9
|
+
const map = evaluate();
|
|
10
|
+
for (const k in map) put(el, k, map[k]);
|
|
11
|
+
});
|
|
16
12
|
});
|
|
17
13
|
export {
|
|
18
14
|
attr
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/plugins/directives/attribute-sync.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { dir } from '../def.js';\n\nconst put = (el: Element, name: string, v: unknown) => {\n if (v === false || v == null) el.removeAttribute(name);\n else el.setAttribute(name, v === true ? '' : String(v));\n};\n\n/** `attr:title=\"expr\"` or `attr=\"{ title: expr }\"`. true \u2192 present, false/null \u2192 removed. */\nexport const attr = dir('attr', 4, ({ el, key, cased, evaluate, effect }) => {\n effect(() => {\n if (key) return put(el, cased('kebab'), evaluate());\n const map = evaluate();\n for (const k in map) put(el, k, map[k]);\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW;AAEpB,MAAM,MAAM,CAAC,IAAa,MAAc,MAAe;AACrD,MAAI,MAAM,SAAS,KAAK,KAAM,IAAG,gBAAgB,IAAI;AAAA,MAChD,IAAG,aAAa,MAAM,MAAM,OAAO,KAAK,OAAO,CAAC,CAAC;AACxD;AAGO,MAAM,OAAO,IAAI,QAAQ,GAAG,CAAC,EAAE,IAAI,KAAK,OAAO,UAAU,OAAO,MAAM;AAC3E,SAAO,MAAM;AACX,QAAI,IAAK,QAAO,IAAI,IAAI,MAAM,OAAO,GAAG,SAAS,CAAC;AAClD,UAAM,MAAM,SAAS;AACrB,eAAW,KAAK,IAAK,KAAI,IAAI,GAAG,IAAI,CAAC,CAAC;AAAA,EACxC,CAAC;AACH,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Turns same-origin links and forms inside the element into requests whose full-document response
|
|
3
3
|
* is morphed into the current page, with history entries: `boost` on a container (or `body`).
|
|
4
|
-
* Needs `httpGet`, `httpPost` and `applyElements`.
|
|
4
|
+
* Needs `httpGet`, `httpPost` and `applyElements`.
|
|
5
5
|
*/
|
|
6
6
|
export declare const boost: import("../../kernel/contracts.js").AttributePlugin;
|