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/core/engine.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { compile, functionCompiler } from "./expr.js";
|
|
2
|
-
import { effect } from "./signals.js";
|
|
3
|
-
import { createStore } from "./store.js";
|
|
4
|
-
import { recase } from "../utils/text.js";
|
|
5
|
-
const isEl = (n) => n instanceof HTMLElement || n instanceof SVGElement || n instanceof MathMLElement;
|
|
6
|
-
const parsed = /* @__PURE__ */ new Map();
|
|
7
|
-
const parseAttr = (raw) => {
|
|
8
|
-
let p = parsed.get(raw);
|
|
9
|
-
if (!p) {
|
|
10
|
-
const [head, ...modParts] = raw.split("__");
|
|
11
|
-
const i = head.indexOf(":");
|
|
12
|
-
const mods = /* @__PURE__ */ new Map();
|
|
13
|
-
for (const m of modParts) {
|
|
14
|
-
const [name, ...args] = m.split(".");
|
|
15
|
-
mods.set(name, args);
|
|
16
|
-
}
|
|
17
|
-
p = { plugin: i < 0 ? head : head.slice(0, i), key: i < 0 ? void 0 : head.slice(i + 1), mods };
|
|
18
|
-
parsed.set(raw, p);
|
|
19
|
-
}
|
|
20
|
-
return p;
|
|
21
|
-
};
|
|
22
|
-
const fail = (message, info) => Object.assign(new Error(message), { info });
|
|
23
|
-
const createSigmx = (options = {}) => {
|
|
24
|
-
const prefixes = [].concat(options.prefix ?? "data-");
|
|
25
|
-
const store = options.store ?? createStore();
|
|
26
|
-
const compiler = options.compile ?? functionCompiler;
|
|
27
|
-
const onError = options.onError ?? ((e, info) => console.error(e, info));
|
|
28
|
-
const attributes = /* @__PURE__ */ Object.create(null);
|
|
29
|
-
const actions = /* @__PURE__ */ Object.create(null);
|
|
30
|
-
const handlers = /* @__PURE__ */ Object.create(null);
|
|
31
|
-
const runtime = {
|
|
32
|
-
prefixes,
|
|
33
|
-
attr: (name) => prefixes[0] + name,
|
|
34
|
-
store,
|
|
35
|
-
compiler,
|
|
36
|
-
emit: (type, detail) => document.dispatchEvent(new CustomEvent(`sigmx-${type}`, { detail })),
|
|
37
|
-
call: (name, ctx, args) => {
|
|
38
|
-
const a = actions[name];
|
|
39
|
-
if (!a) throw ctx.error(`unknown action @${name}`);
|
|
40
|
-
return a.call(ctx, ...args);
|
|
41
|
-
},
|
|
42
|
-
attributes,
|
|
43
|
-
actions,
|
|
44
|
-
handlers
|
|
45
|
-
};
|
|
46
|
-
const mounted = /* @__PURE__ */ new Map();
|
|
47
|
-
const roots = /* @__PURE__ */ new Set();
|
|
48
|
-
const ignoreSelf = prefixes.map((p) => `[${p}ignore__self]`).join();
|
|
49
|
-
const ignoreAny = prefixes.map((p) => `[${p}ignore]`).join();
|
|
50
|
-
const ignored = (el) => el.matches(ignoreSelf) || !!el.closest(ignoreAny);
|
|
51
|
-
const strip = (attr) => {
|
|
52
|
-
for (const p of prefixes) if (attr.startsWith(p)) return attr.slice(p.length);
|
|
53
|
-
};
|
|
54
|
-
const unmount = (els) => {
|
|
55
|
-
for (const el of els) {
|
|
56
|
-
const m = mounted.get(el);
|
|
57
|
-
if (m && mounted.delete(el)) for (const d of m.values()) d();
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const unmountAttr = (el, attr) => {
|
|
61
|
-
const m = mounted.get(el);
|
|
62
|
-
m?.get(attr)?.();
|
|
63
|
-
m?.delete(attr);
|
|
64
|
-
};
|
|
65
|
-
const actionsFor = (el, evt, error) => {
|
|
66
|
-
const ctx = { el, evt, store, runtime, error };
|
|
67
|
-
return new Proxy(/* @__PURE__ */ Object.create(null), { get: (_, name) => (...args) => runtime.call(name, ctx, args) });
|
|
68
|
-
};
|
|
69
|
-
const mount = (el, attr, raw, value, only) => {
|
|
70
|
-
const { plugin: name, key, mods } = parseAttr(raw);
|
|
71
|
-
const plugin = attributes[name];
|
|
72
|
-
if (!plugin || only && !only.has(name)) return;
|
|
73
|
-
unmountAttr(el, attr);
|
|
74
|
-
const disposers = [];
|
|
75
|
-
const info = { plugin: name, el, attr };
|
|
76
|
-
const error = (message, extra) => fail(`${prefixes[0]}${name}: ${message}`, { ...info, ...extra });
|
|
77
|
-
const report = (e) => onError(e, info);
|
|
78
|
-
let fn;
|
|
79
|
-
const ctx = {
|
|
80
|
-
el,
|
|
81
|
-
plugin: name,
|
|
82
|
-
attr,
|
|
83
|
-
key,
|
|
84
|
-
value,
|
|
85
|
-
mods,
|
|
86
|
-
cased: (style = "camel") => recase(key ?? "", mods.get("case")?.[0] || style),
|
|
87
|
-
evaluate: (evt, ...args) => {
|
|
88
|
-
fn ??= compile(compiler, value, ["el", "evt", ...plugin.args ?? []], plugin.returns ?? true);
|
|
89
|
-
return fn(store.scope, actionsFor(el, evt, error), el, evt, ...args);
|
|
90
|
-
},
|
|
91
|
-
effect: (f) => disposers.push(effect(f, report)),
|
|
92
|
-
listen: (target, type, f, opts) => {
|
|
93
|
-
const h = (e) => {
|
|
94
|
-
try {
|
|
95
|
-
f(e);
|
|
96
|
-
} catch (err) {
|
|
97
|
-
report(err);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
target.addEventListener(type, h, opts);
|
|
101
|
-
disposers.push(() => target.removeEventListener(type, h, opts));
|
|
102
|
-
},
|
|
103
|
-
cleanup: (f) => disposers.push(f),
|
|
104
|
-
error,
|
|
105
|
-
store,
|
|
106
|
-
runtime
|
|
107
|
-
};
|
|
108
|
-
let m = mounted.get(el);
|
|
109
|
-
if (!m) mounted.set(el, m = /* @__PURE__ */ new Map());
|
|
110
|
-
m.set(attr, () => {
|
|
111
|
-
for (const d of disposers.splice(0)) d();
|
|
112
|
-
});
|
|
113
|
-
try {
|
|
114
|
-
if (plugin.key === "required" && !key) throw error("needs a key, e.g. :name");
|
|
115
|
-
if (plugin.key === "forbidden" && key) throw error("does not take a key");
|
|
116
|
-
if (plugin.value === "required" && !value) throw error("needs a value");
|
|
117
|
-
if (plugin.value === "forbidden" && value) throw error("does not take a value");
|
|
118
|
-
const r = plugin.mount(ctx);
|
|
119
|
-
if (typeof r === "function") disposers.push(r);
|
|
120
|
-
} catch (e) {
|
|
121
|
-
report(e);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const mountEls = (els, only) => {
|
|
125
|
-
for (const el of els) {
|
|
126
|
-
if (ignored(el)) continue;
|
|
127
|
-
for (const { name, value } of [...el.attributes]) {
|
|
128
|
-
const raw = strip(name);
|
|
129
|
-
if (raw) mount(el, name, raw, value, only);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
const observer = new MutationObserver((records) => {
|
|
134
|
-
for (const { type, target, attributeName, addedNodes, removedNodes } of records) {
|
|
135
|
-
if (type === "childList") {
|
|
136
|
-
for (const n of removedNodes) if (isEl(n)) unmount([n, ...n.querySelectorAll("*")]);
|
|
137
|
-
for (const n of addedNodes) if (isEl(n)) mountEls([n, ...n.querySelectorAll("*")]);
|
|
138
|
-
} else if (attributeName && isEl(target) && !ignored(target)) {
|
|
139
|
-
const raw = strip(attributeName);
|
|
140
|
-
if (!raw) continue;
|
|
141
|
-
const value = target.getAttribute(attributeName);
|
|
142
|
-
if (value === null) unmountAttr(target, attributeName);
|
|
143
|
-
else mount(target, attributeName, raw, value);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
let ready = false;
|
|
148
|
-
const apply = (root = document.documentElement, observe = true, only) => {
|
|
149
|
-
mountEls([...isEl(root) ? [root] : [], ...root.querySelectorAll("*")], only);
|
|
150
|
-
if (observe && !roots.has(root)) {
|
|
151
|
-
observer.observe(root, { subtree: true, childList: true, attributes: true });
|
|
152
|
-
roots.add(root);
|
|
153
|
-
}
|
|
154
|
-
if (!ready && roots.has(document.documentElement)) {
|
|
155
|
-
ready = true;
|
|
156
|
-
runtime.emit("ready");
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const use = (...plugins) => {
|
|
160
|
-
const added = /* @__PURE__ */ new Set();
|
|
161
|
-
for (const p of plugins) {
|
|
162
|
-
if (p.type === "attribute") {
|
|
163
|
-
attributes[p.name] = p;
|
|
164
|
-
added.add(p.name);
|
|
165
|
-
} else if (p.type === "action") actions[p.name] = p;
|
|
166
|
-
else handlers[p.name] = p;
|
|
167
|
-
}
|
|
168
|
-
if (added.size) for (const r of roots) apply(r, false, added);
|
|
169
|
-
};
|
|
170
|
-
const stopPatches = store.onPatch((patch) => runtime.emit("signal-patch", patch));
|
|
171
|
-
use(...options.plugins ?? []);
|
|
172
|
-
const sigmx = {
|
|
173
|
-
runtime,
|
|
174
|
-
store,
|
|
175
|
-
get $() {
|
|
176
|
-
return store.$;
|
|
177
|
-
},
|
|
178
|
-
apply: (root, observe) => apply(root, observe),
|
|
179
|
-
use,
|
|
180
|
-
destroy: () => {
|
|
181
|
-
observer.disconnect();
|
|
182
|
-
stopPatches();
|
|
183
|
-
unmount([...mounted.keys()]);
|
|
184
|
-
roots.clear();
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
if (options.autoStart ?? true) {
|
|
188
|
-
if (document.readyState === "loading") {
|
|
189
|
-
document.addEventListener("DOMContentLoaded", () => sigmx.apply(), { once: true });
|
|
190
|
-
} else {
|
|
191
|
-
sigmx.apply();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return sigmx;
|
|
195
|
-
};
|
|
196
|
-
export {
|
|
197
|
-
createSigmx,
|
|
198
|
-
parseAttr
|
|
199
|
-
};
|
|
200
|
-
//# sourceMappingURL=engine.js.map
|
package/dist/core/engine.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/core/engine.ts"],
|
|
4
|
-
"sourcesContent": ["import { compile, functionCompiler } from './expr.js'\nimport { effect } from './signals.js'\nimport { createStore } from './store.js'\nimport type { ActionCtx, AttributePlugin, Ctx, El, Mods, Plugin, Runtime, Sigmx, SigmxOptions } from './types.js'\nimport { recase, type CaseStyle } from '../utils/text.js'\n\nconst isEl = (n: Node): n is El => n instanceof HTMLElement || n instanceof SVGElement || n instanceof MathMLElement\n\ntype Parsed = { plugin: string; key: string | undefined; mods: Mods }\nconst parsed = new Map<string, Parsed>()\n\n/** 'on:click__debounce.300ms__prevent' \u2192 { plugin: 'on', key: 'click', mods: {debounce: ['300ms'], prevent: []} } */\nexport const parseAttr = (raw: string): Parsed => {\n let p = parsed.get(raw)\n if (!p) {\n const [head, ...modParts] = raw.split('__')\n const i = head.indexOf(':')\n const mods: Mods = new Map()\n for (const m of modParts) {\n const [name, ...args] = m.split('.')\n mods.set(name, args)\n }\n p = { plugin: i < 0 ? head : head.slice(0, i), key: i < 0 ? undefined : head.slice(i + 1), mods }\n parsed.set(raw, p)\n }\n return p\n}\n\nconst fail = (message: string, info: Record<string, unknown>): Error =>\n Object.assign(new Error(message), { info })\n\nexport const createSigmx = (options: SigmxOptions = {}): Sigmx => {\n const prefixes = ([] as string[]).concat(options.prefix ?? 'data-')\n const store = options.store ?? createStore()\n const compiler = options.compile ?? functionCompiler\n const onError = options.onError ?? ((e, info) => console.error(e, info))\n const attributes: Record<string, AttributePlugin> = Object.create(null)\n const actions: Runtime['actions'] = Object.create(null)\n const handlers: Runtime['handlers'] = Object.create(null)\n\n const runtime: Runtime = {\n prefixes,\n attr: (name) => prefixes[0] + name,\n store,\n compiler,\n emit: (type, detail) => document.dispatchEvent(new CustomEvent(`sigmx-${type}`, { detail })),\n call: (name, ctx, args) => {\n const a = actions[name]\n if (!a) throw ctx.error(`unknown action @${name}`)\n return a.call(ctx, ...args)\n },\n attributes,\n actions,\n handlers,\n }\n\n // element \u2192 attribute name \u2192 dispose\n const mounted = new Map<El, Map<string, () => void>>()\n const roots = new Set<El | ShadowRoot>()\n const ignoreSelf = prefixes.map((p) => `[${p}ignore__self]`).join()\n const ignoreAny = prefixes.map((p) => `[${p}ignore]`).join()\n const ignored = (el: El) => el.matches(ignoreSelf) || !!el.closest(ignoreAny)\n\n const strip = (attr: string): string | undefined => {\n for (const p of prefixes) if (attr.startsWith(p)) return attr.slice(p.length)\n }\n\n const unmount = (els: Iterable<El>): void => {\n for (const el of els) {\n const m = mounted.get(el)\n if (m && mounted.delete(el)) for (const d of m.values()) d()\n }\n }\n\n const unmountAttr = (el: El, attr: string): void => {\n const m = mounted.get(el)\n m?.get(attr)?.()\n m?.delete(attr)\n }\n\n const actionsFor = (el: El, evt: Event | undefined, error: Ctx['error']) => {\n const ctx: ActionCtx = { el, evt, store, runtime, error }\n return new Proxy(Object.create(null), { get: (_, name: string) => (...args: any[]) => runtime.call(name, ctx, args) })\n }\n\n const mount = (el: El, attr: string, raw: string, value: string, only?: Set<string>): void => {\n const { plugin: name, key, mods } = parseAttr(raw)\n const plugin = attributes[name]\n if (!plugin || (only && !only.has(name))) return\n unmountAttr(el, attr)\n\n const disposers: (() => void)[] = []\n const info = { plugin: name, el, attr }\n const error: Ctx['error'] = (message, extra) => fail(`${prefixes[0]}${name}: ${message}`, { ...info, ...extra })\n const report = (e: unknown) => onError(e, info)\n let fn: ((...args: any[]) => any) | undefined\n const ctx: Ctx = {\n el,\n plugin: name,\n attr,\n key,\n value,\n mods,\n cased: (style = 'camel') => recase(key ?? '', (mods.get('case')?.[0] as CaseStyle) || style),\n evaluate: (evt, ...args) => {\n fn ??= compile(compiler, value, ['el', 'evt', ...(plugin.args ?? [])], plugin.returns ?? true)\n return fn(store.scope, actionsFor(el, evt, error), el, evt, ...args)\n },\n effect: (f) => disposers.push(effect(f, report)),\n listen: (target, type, f, opts) => {\n const h = (e: Event) => {\n try {\n f(e)\n } catch (err) {\n report(err)\n }\n }\n target.addEventListener(type, h, opts)\n disposers.push(() => target.removeEventListener(type, h, opts))\n },\n cleanup: (f) => disposers.push(f),\n error,\n store,\n runtime,\n }\n\n let m = mounted.get(el)\n if (!m) mounted.set(el, (m = new Map()))\n m.set(attr, () => {\n for (const d of disposers.splice(0)) d()\n })\n\n try {\n if (plugin.key === 'required' && !key) throw error('needs a key, e.g. :name')\n if (plugin.key === 'forbidden' && key) throw error('does not take a key')\n if (plugin.value === 'required' && !value) throw error('needs a value')\n if (plugin.value === 'forbidden' && value) throw error('does not take a value')\n const r = plugin.mount(ctx)\n if (typeof r === 'function') disposers.push(r)\n } catch (e) {\n report(e)\n }\n }\n\n const mountEls = (els: Iterable<El>, only?: Set<string>): void => {\n for (const el of els) {\n if (ignored(el)) continue\n for (const { name, value } of [...el.attributes]) {\n const raw = strip(name)\n if (raw) mount(el, name, raw, value, only)\n }\n }\n }\n\n const observer = new MutationObserver((records) => {\n for (const { type, target, attributeName, addedNodes, removedNodes } of records) {\n if (type === 'childList') {\n for (const n of removedNodes) if (isEl(n)) unmount([n, ...n.querySelectorAll<El>('*')])\n for (const n of addedNodes) if (isEl(n)) mountEls([n, ...n.querySelectorAll<El>('*')])\n } else if (attributeName && isEl(target) && !ignored(target)) {\n const raw = strip(attributeName)\n if (!raw) continue\n const value = target.getAttribute(attributeName)\n if (value === null) unmountAttr(target, attributeName)\n else mount(target, attributeName, raw, value)\n }\n }\n })\n\n let ready = false\n const apply = (root: El | ShadowRoot = document.documentElement, observe = true, only?: Set<string>) => {\n mountEls([...(isEl(root) ? [root] : []), ...root.querySelectorAll<El>('*')], only)\n if (observe && !roots.has(root)) {\n observer.observe(root, { subtree: true, childList: true, attributes: true })\n roots.add(root)\n }\n if (!ready && roots.has(document.documentElement)) {\n ready = true\n runtime.emit('ready')\n }\n }\n\n const use = (...plugins: Plugin[]): void => {\n const added = new Set<string>()\n for (const p of plugins) {\n if (p.type === 'attribute') {\n attributes[p.name] = p\n added.add(p.name)\n } else if (p.type === 'action') actions[p.name] = p\n else handlers[p.name] = p\n }\n if (added.size) for (const r of roots) apply(r, false, added)\n }\n\n const stopPatches = store.onPatch((patch) => runtime.emit('signal-patch', patch))\n use(...(options.plugins ?? []))\n\n const sigmx: Sigmx = {\n runtime,\n store,\n get $() {\n return store.$\n },\n apply: (root, observe) => apply(root, observe),\n use,\n destroy: () => {\n observer.disconnect()\n stopPatches()\n unmount([...mounted.keys()])\n roots.clear()\n },\n }\n\n if (options.autoStart ?? true) {\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', () => sigmx.apply(), { once: true })\n } else {\n sigmx.apply()\n }\n }\n return sigmx\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS,wBAAwB;AAC1C,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAE5B,SAAS,cAA8B;AAEvC,MAAM,OAAO,CAAC,MAAqB,aAAa,eAAe,aAAa,cAAc,aAAa;AAGvG,MAAM,SAAS,oBAAI,IAAoB;AAGhC,MAAM,YAAY,CAAC,QAAwB;AAChD,MAAI,IAAI,OAAO,IAAI,GAAG;AACtB,MAAI,CAAC,GAAG;AACN,UAAM,CAAC,MAAM,GAAG,QAAQ,IAAI,IAAI,MAAM,IAAI;AAC1C,UAAM,IAAI,KAAK,QAAQ,GAAG;AAC1B,UAAM,OAAa,oBAAI,IAAI;AAC3B,eAAW,KAAK,UAAU;AACxB,YAAM,CAAC,MAAM,GAAG,IAAI,IAAI,EAAE,MAAM,GAAG;AACnC,WAAK,IAAI,MAAM,IAAI;AAAA,IACrB;AACA,QAAI,EAAE,QAAQ,IAAI,IAAI,OAAO,KAAK,MAAM,GAAG,CAAC,GAAG,KAAK,IAAI,IAAI,SAAY,KAAK,MAAM,IAAI,CAAC,GAAG,KAAK;AAChG,WAA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,MAAM;AAC7B,QAAI,SAAS,eAAe,WAAW;AACrC,eAAS,iBAAiB,oBAAoB,MAAM,MAAM,MAAM,GAAG,EAAE,MAAM,KAAK,CAAC;AAAA,IACnF,OAAO;AACL,YAAM,MAAM;AAAA,IACd;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/core/expr.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type Compiler = (params: string[], body: string) => (...args: any[]) => any;
|
|
2
|
-
/** Default compiler: `new Function`. Not usable under a strict CSP; see `cspCompiler`. */
|
|
3
|
-
export declare const functionCompiler: Compiler;
|
|
4
|
-
/** Replace `@name(` with `__a.name(` outside strings and comments. */
|
|
5
|
-
export declare const rewriteActions: (src: string) => string;
|
|
6
|
-
/** Split on top-level semicolons. */
|
|
7
|
-
export declare const splitStatements: (src: string) => string[];
|
|
8
|
-
/**
|
|
9
|
-
* Compile an expression to `(scope, actions, ...params) => any`. With `returns`, the value of the
|
|
10
|
-
* last statement is returned, so `$a = 1; $a * 2` works. Compiled functions are cached by source.
|
|
11
|
-
*/
|
|
12
|
-
export declare const compile: (compiler: Compiler, src: string, params: string[], returns: boolean) => ((...args: any[]) => any);
|
package/dist/core/expr.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
const functionCompiler = (params, body) => Function(...params, body);
|
|
2
|
-
const cache = /* @__PURE__ */ new Map();
|
|
3
|
-
const isIdent = (c) => /[A-Za-z0-9_$]/.test(c);
|
|
4
|
-
const scan = (src, onCode) => {
|
|
5
|
-
let i = 0;
|
|
6
|
-
const n = src.length;
|
|
7
|
-
while (i < n) {
|
|
8
|
-
const c = src[i];
|
|
9
|
-
const next = src[i + 1];
|
|
10
|
-
if (c === '"' || c === "'" || c === "`") {
|
|
11
|
-
let j = i + 1;
|
|
12
|
-
while (j < n && src[j] !== c) j += src[j] === "\\" ? 2 : 1;
|
|
13
|
-
onCode(src.slice(i, j + 1), i);
|
|
14
|
-
i = j + 1;
|
|
15
|
-
} else if (c === "/" && next === "/") {
|
|
16
|
-
const j = src.indexOf("\n", i);
|
|
17
|
-
i = j < 0 ? n : j;
|
|
18
|
-
} else if (c === "/" && next === "*") {
|
|
19
|
-
const j = src.indexOf("*/", i + 2);
|
|
20
|
-
i = j < 0 ? n : j + 2;
|
|
21
|
-
} else {
|
|
22
|
-
const skip = onCode(c, i);
|
|
23
|
-
i += skip || 1;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const rewriteActions = (src) => {
|
|
28
|
-
let out = "";
|
|
29
|
-
scan(src, (c, i) => {
|
|
30
|
-
if (c === "@") {
|
|
31
|
-
let j = i + 1;
|
|
32
|
-
while (j < src.length && isIdent(src[j])) j++;
|
|
33
|
-
let k = j;
|
|
34
|
-
while (k < src.length && /\s/.test(src[k])) k++;
|
|
35
|
-
if (j > i + 1 && src[k] === "(") {
|
|
36
|
-
out += `__a.${src.slice(i + 1, j)}(`;
|
|
37
|
-
return k + 1 - i;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
out += c;
|
|
41
|
-
});
|
|
42
|
-
return out;
|
|
43
|
-
};
|
|
44
|
-
const splitStatements = (src) => {
|
|
45
|
-
const parts = [];
|
|
46
|
-
let depth = 0;
|
|
47
|
-
let start = 0;
|
|
48
|
-
scan(src, (c, i) => {
|
|
49
|
-
if (c.length > 1) return;
|
|
50
|
-
if ("([{".includes(c)) depth++;
|
|
51
|
-
else if (")]}".includes(c)) depth--;
|
|
52
|
-
else if (c === ";" && !depth) {
|
|
53
|
-
parts.push(src.slice(start, i));
|
|
54
|
-
start = i + 1;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
parts.push(src.slice(start));
|
|
58
|
-
return parts.filter((p) => p.trim());
|
|
59
|
-
};
|
|
60
|
-
const compile = (compiler, src, params, returns) => {
|
|
61
|
-
const key = `${+returns}|${params.join()}|${src}`;
|
|
62
|
-
const hit = cache.get(key);
|
|
63
|
-
if (hit) return hit;
|
|
64
|
-
const code = rewriteActions(src.trim());
|
|
65
|
-
const make = (body) => compiler(["$", "__a", ...params], `with($){${body}
|
|
66
|
-
}`);
|
|
67
|
-
let fn;
|
|
68
|
-
if (!returns) {
|
|
69
|
-
fn = make(code);
|
|
70
|
-
} else {
|
|
71
|
-
try {
|
|
72
|
-
fn = make(`return(${code}
|
|
73
|
-
)`);
|
|
74
|
-
} catch {
|
|
75
|
-
const parts = splitStatements(code);
|
|
76
|
-
const last = parts.pop() ?? "";
|
|
77
|
-
try {
|
|
78
|
-
fn = make(`${parts.join(";")};return(${last}
|
|
79
|
-
)`);
|
|
80
|
-
} catch {
|
|
81
|
-
fn = make(code);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
cache.set(key, fn);
|
|
86
|
-
return fn;
|
|
87
|
-
};
|
|
88
|
-
export {
|
|
89
|
-
compile,
|
|
90
|
-
functionCompiler,
|
|
91
|
-
rewriteActions,
|
|
92
|
-
splitStatements
|
|
93
|
-
};
|
|
94
|
-
//# sourceMappingURL=expr.js.map
|
package/dist/core/expr.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/core/expr.ts"],
|
|
4
|
-
"sourcesContent": ["// Expression compiler. Signals need no rewriting: the body runs inside `with (scope)`, where\n// `$count`, `$user.name` and `$` resolve through the store's scope proxy. Only `@action(` is\n// rewritten, into a call on the per-evaluation actions object.\n\nexport type Compiler = (params: string[], body: string) => (...args: any[]) => any\n\n/** Default compiler: `new Function`. Not usable under a strict CSP; see `cspCompiler`. */\nexport const functionCompiler: Compiler = (params, body) => Function(...params, body) as (...args: any[]) => any\n\nconst cache = new Map<string, (...args: any[]) => any>()\n\nconst isIdent = (c: string): boolean => /[A-Za-z0-9_$]/.test(c)\n\n/** Walk source text, skipping string, template and comment contents; `emit` receives code chars. */\nconst scan = (src: string, onCode: (c: string, i: number) => number | void): void => {\n let i = 0\n const n = src.length\n while (i < n) {\n const c = src[i]\n const next = src[i + 1]\n if (c === '\"' || c === \"'\" || c === '`') {\n let j = i + 1\n while (j < n && src[j] !== c) j += src[j] === '\\\\' ? 2 : 1\n onCode(src.slice(i, j + 1), i)\n i = j + 1\n } else if (c === '/' && next === '/') {\n const j = src.indexOf('\\n', i)\n i = j < 0 ? n : j\n } else if (c === '/' && next === '*') {\n const j = src.indexOf('*/', i + 2)\n i = j < 0 ? n : j + 2\n } else {\n const skip = onCode(c, i)\n i += skip || 1\n }\n }\n}\n\n/** Replace `@name(` with `__a.name(` outside strings and comments. */\nexport const rewriteActions = (src: string): string => {\n let out = ''\n scan(src, (c, i) => {\n if (c === '@') {\n let j = i + 1\n while (j < src.length && isIdent(src[j])) j++\n let k = j\n while (k < src.length && /\\s/.test(src[k])) k++\n if (j > i + 1 && src[k] === '(') {\n out += `__a.${src.slice(i + 1, j)}(`\n return k + 1 - i\n }\n }\n out += c\n })\n return out\n}\n\n/** Split on top-level semicolons. */\nexport const splitStatements = (src: string): string[] => {\n const parts: string[] = []\n let depth = 0\n let start = 0\n scan(src, (c, i) => {\n if (c.length > 1) return\n if ('([{'.includes(c)) depth++\n else if (')]}'.includes(c)) depth--\n else if (c === ';' && !depth) {\n parts.push(src.slice(start, i))\n start = i + 1\n }\n })\n parts.push(src.slice(start))\n return parts.filter((p) => p.trim())\n}\n\n/**\n * Compile an expression to `(scope, actions, ...params) => any`. With `returns`, the value of the\n * last statement is returned, so `$a = 1; $a * 2` works. Compiled functions are cached by source.\n */\nexport const compile = (\n compiler: Compiler,\n src: string,\n params: string[],\n returns: boolean,\n): ((...args: any[]) => any) => {\n const key = `${+returns}|${params.join()}|${src}`\n const hit = cache.get(key)\n if (hit) return hit\n const code = rewriteActions(src.trim())\n const make = (body: string) => compiler(['$', '__a', ...params], `with($){${body}\\n}`)\n let fn: (...args: any[]) => any\n if (!returns) {\n fn = make(code)\n } else {\n try {\n fn = make(`return(${code}\\n)`)\n } catch {\n const parts = splitStatements(code)\n const last = parts.pop() ?? ''\n try {\n fn = make(`${parts.join(';')};return(${last}\\n)`)\n } catch {\n fn = make(code)\n }\n }\n }\n cache.set(key, fn)\n return fn\n}\n"],
|
|
5
|
-
"mappings": "AAOO,MAAM,mBAA6B,CAAC,QAAQ,SAAS,SAAS,GAAG,QAAQ,IAAI;AAEpF,MAAM,QAAQ,oBAAI,IAAqC;AAEvD,MAAM,UAAU,CAAC,MAAuB,gBAAgB,KAAK,CAAC;AAG9D,MAAM,OAAO,CAAC,KAAa,WAA0D;AACnF,MAAI,IAAI;AACR,QAAM,IAAI,IAAI;AACd,SAAO,IAAI,GAAG;AACZ,UAAM,IAAI,IAAI,CAAC;AACf,UAAM,OAAO,IAAI,IAAI,CAAC;AACtB,QAAI,MAAM,OAAO,MAAM,OAAO,MAAM,KAAK;AACvC,UAAI,IAAI,IAAI;AACZ,aAAO,IAAI,KAAK,IAAI,CAAC,MAAM,EAAG,MAAK,IAAI,CAAC,MAAM,OAAO,IAAI;AACzD,aAAO,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;AAC7B,UAAI,IAAI;AAAA,IACV,WAAW,MAAM,OAAO,SAAS,KAAK;AACpC,YAAM,IAAI,IAAI,QAAQ,MAAM,CAAC;AAC7B,UAAI,IAAI,IAAI,IAAI;AAAA,IAClB,WAAW,MAAM,OAAO,SAAS,KAAK;AACpC,YAAM,IAAI,IAAI,QAAQ,MAAM,IAAI,CAAC;AACjC,UAAI,IAAI,IAAI,IAAI,IAAI;AAAA,IACtB,OAAO;AACL,YAAM,OAAO,OAAO,GAAG,CAAC;AACxB,WAAK,QAAQ;AAAA,IACf;AAAA,EACF;AACF;AAGO,MAAM,iBAAiB,CAAC,QAAwB;AACrD,MAAI,MAAM;AACV,OAAK,KAAK,CAAC,GAAG,MAAM;AAClB,QAAI,MAAM,KAAK;AACb,UAAI,IAAI,IAAI;AACZ,aAAO,IAAI,IAAI,UAAU,QAAQ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AAAA,IAC/B,QAAQ;AACN,YAAM,QAAQ,gBAAgB,IAAI;AAClC,YAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAI;AACF,aAAK,KAAK,GAAG,MAAM,KAAK,GAAG,CAAC,WAAW,IAAI;AAAA,EAAK;AAAA,MAClD,QAAQ;AACN,aAAK,KAAK,IAAI;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACA,QAAM,IAAI,KAAK,EAAE;AACjB,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/core/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { createSigmx, parseAttr } from './engine.js';
|
|
2
|
-
export { compile, functionCompiler, rewriteActions, splitStatements } from './expr.js';
|
|
3
|
-
export type { Compiler } from './expr.js';
|
|
4
|
-
export { Computed, Signal, batch, computed, effect, flush, onSettled, signal, untracked } from './signals.js';
|
|
5
|
-
export { createStore } from './store.js';
|
|
6
|
-
export type { Patch, Store } from './store.js';
|
|
7
|
-
export type * from './types.js';
|
|
8
|
-
export { expand, isPlain, toPredicate } from '../utils/object.js';
|
|
9
|
-
export type { Filter } from '../utils/object.js';
|
|
10
|
-
export { camel, kebab, pascal, recase, snake } from '../utils/text.js';
|
|
11
|
-
export { debounce, delay, throttle, toMs, withTiming, withViewTransition } from '../utils/timing.js';
|
|
12
|
-
import type { ActionPlugin, AttributePlugin, HandlerPlugin } from './types.js';
|
|
13
|
-
/** Type a plugin definition. Pure: registration is `createSigmx({ plugins })` or `sigmx.use()`. */
|
|
14
|
-
export declare const attribute: (p: Omit<AttributePlugin, "type">) => AttributePlugin;
|
|
15
|
-
export declare const action: (p: Omit<ActionPlugin, "type">) => ActionPlugin;
|
|
16
|
-
export declare const handler: (p: Omit<HandlerPlugin, "type">) => HandlerPlugin;
|
package/dist/core/index.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { createSigmx, parseAttr } from "./engine.js";
|
|
2
|
-
import { compile, functionCompiler, rewriteActions, splitStatements } from "./expr.js";
|
|
3
|
-
import { Computed, Signal, batch, computed, effect, flush, onSettled, signal, untracked } from "./signals.js";
|
|
4
|
-
import { createStore } from "./store.js";
|
|
5
|
-
import { expand, isPlain, toPredicate } from "../utils/object.js";
|
|
6
|
-
import { camel, kebab, pascal, recase, snake } from "../utils/text.js";
|
|
7
|
-
import { debounce, delay, throttle, toMs, withTiming, withViewTransition } from "../utils/timing.js";
|
|
8
|
-
const attribute = (p) => ({ type: "attribute", ...p });
|
|
9
|
-
const action = (p) => ({ type: "action", ...p });
|
|
10
|
-
const handler = (p) => ({ type: "handler", ...p });
|
|
11
|
-
export {
|
|
12
|
-
Computed,
|
|
13
|
-
Signal,
|
|
14
|
-
action,
|
|
15
|
-
attribute,
|
|
16
|
-
batch,
|
|
17
|
-
camel,
|
|
18
|
-
compile,
|
|
19
|
-
computed,
|
|
20
|
-
createSigmx,
|
|
21
|
-
createStore,
|
|
22
|
-
debounce,
|
|
23
|
-
delay,
|
|
24
|
-
effect,
|
|
25
|
-
expand,
|
|
26
|
-
flush,
|
|
27
|
-
functionCompiler,
|
|
28
|
-
handler,
|
|
29
|
-
isPlain,
|
|
30
|
-
kebab,
|
|
31
|
-
onSettled,
|
|
32
|
-
parseAttr,
|
|
33
|
-
pascal,
|
|
34
|
-
recase,
|
|
35
|
-
rewriteActions,
|
|
36
|
-
signal,
|
|
37
|
-
snake,
|
|
38
|
-
splitStatements,
|
|
39
|
-
throttle,
|
|
40
|
-
toMs,
|
|
41
|
-
toPredicate,
|
|
42
|
-
untracked,
|
|
43
|
-
withTiming,
|
|
44
|
-
withViewTransition
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/core/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { createSigmx, parseAttr } from './engine.js'\nexport { compile, functionCompiler, rewriteActions, splitStatements } from './expr.js'\nexport type { Compiler } from './expr.js'\nexport { Computed, Signal, batch, computed, effect, flush, onSettled, signal, untracked } from './signals.js'\nexport { createStore } from './store.js'\nexport type { Patch, Store } from './store.js'\nexport type * from './types.js'\nexport { expand, isPlain, toPredicate } from '../utils/object.js'\nexport type { Filter } from '../utils/object.js'\nexport { camel, kebab, pascal, recase, snake } from '../utils/text.js'\nexport { debounce, delay, throttle, toMs, withTiming, withViewTransition } from '../utils/timing.js'\n\nimport type { ActionPlugin, AttributePlugin, HandlerPlugin } from './types.js'\n\n/** Type a plugin definition. Pure: registration is `createSigmx({ plugins })` or `sigmx.use()`. */\nexport const attribute = (p: Omit<AttributePlugin, 'type'>): AttributePlugin => ({ type: 'attribute', ...p })\nexport const action = (p: Omit<ActionPlugin, 'type'>): ActionPlugin => ({ type: 'action', ...p })\nexport const handler = (p: Omit<HandlerPlugin, 'type'>): HandlerPlugin => ({ type: 'handler', ...p })\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,aAAa,iBAAiB;AACvC,SAAS,SAAS,kBAAkB,gBAAgB,uBAAuB;AAE3E,SAAS,UAAU,QAAQ,OAAO,UAAU,QAAQ,OAAO,WAAW,QAAQ,iBAAiB;AAC/F,SAAS,mBAAmB;AAG5B,SAAS,QAAQ,SAAS,mBAAmB;AAE7C,SAAS,OAAO,OAAO,QAAQ,QAAQ,aAAa;AACpD,SAAS,UAAU,OAAO,UAAU,MAAM,YAAY,0BAA0B;AAKzE,MAAM,YAAY,CAAC,OAAuD,EAAE,MAAM,aAAa,GAAG,EAAE;AACpG,MAAM,SAAS,CAAC,OAAiD,EAAE,MAAM,UAAU,GAAG,EAAE;AACxF,MAAM,UAAU,CAAC,OAAmD,EAAE,MAAM,WAAW,GAAG,EAAE;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/core/signals.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
interface Tracker {
|
|
2
|
-
_deps: Map<Signal<any>, number>;
|
|
3
|
-
_invalidate(): void;
|
|
4
|
-
}
|
|
5
|
-
export declare class Signal<T> {
|
|
6
|
-
/** @internal */ _v: T;
|
|
7
|
-
/** @internal */ _ver: number;
|
|
8
|
-
/** @internal */ _subs: Set<Tracker>;
|
|
9
|
-
constructor(v: T);
|
|
10
|
-
get value(): T;
|
|
11
|
-
set value(x: T);
|
|
12
|
-
/** Read without subscribing. */
|
|
13
|
-
peek(): T;
|
|
14
|
-
/** Notify subscribers without replacing the value (after mutating an array or object in place). */
|
|
15
|
-
bump(): void;
|
|
16
|
-
}
|
|
17
|
-
export declare class Computed<T> extends Signal<T> implements Tracker {
|
|
18
|
-
_deps: Map<Signal<any>, number>;
|
|
19
|
-
/** @internal */ _dirty: boolean;
|
|
20
|
-
/** @internal */ _fn: () => T;
|
|
21
|
-
constructor(fn: () => T);
|
|
22
|
-
/** @internal */ _refresh(): void;
|
|
23
|
-
get value(): T;
|
|
24
|
-
set value(_: T);
|
|
25
|
-
peek(): T;
|
|
26
|
-
_invalidate(): void;
|
|
27
|
-
}
|
|
28
|
-
export declare const signal: <T>(value: T) => Signal<T>;
|
|
29
|
-
export declare const computed: <T>(fn: () => T) => Computed<T>;
|
|
30
|
-
/**
|
|
31
|
-
* Run `fn` now and again whenever a signal it read changes. Effects created inside another
|
|
32
|
-
* effect are disposed when the parent re-runs. Returns a disposer.
|
|
33
|
-
*/
|
|
34
|
-
export declare const effect: (fn: () => void, onError?: (e: unknown) => void) => (() => void);
|
|
35
|
-
/** Coalesce many writes into one round of effect runs. */
|
|
36
|
-
export declare const batch: <R>(fn: () => R) => R;
|
|
37
|
-
/** Read signals inside `fn` without subscribing the current effect to them. */
|
|
38
|
-
export declare const untracked: <R>(fn: () => R) => R;
|
|
39
|
-
/** Called after each flush once every queued effect has run. */
|
|
40
|
-
export declare const onSettled: (fn: () => void) => (() => void);
|
|
41
|
-
export declare const flush: () => void;
|
|
42
|
-
export {};
|
package/dist/core/signals.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
let active;
|
|
2
|
-
let owner;
|
|
3
|
-
let depth = 0;
|
|
4
|
-
let flushing = false;
|
|
5
|
-
const queue = /* @__PURE__ */ new Set();
|
|
6
|
-
const settled = /* @__PURE__ */ new Set();
|
|
7
|
-
class Signal {
|
|
8
|
-
constructor(v) {
|
|
9
|
-
/** @internal */
|
|
10
|
-
this.e = 0;
|
|
11
|
-
/** @internal */
|
|
12
|
-
this.f = /* @__PURE__ */ new Set();
|
|
13
|
-
this.a = v;
|
|
14
|
-
}
|
|
15
|
-
get value() {
|
|
16
|
-
if (active) {
|
|
17
|
-
active.b.set(this, this.e);
|
|
18
|
-
this.f.add(active);
|
|
19
|
-
}
|
|
20
|
-
return this.a;
|
|
21
|
-
}
|
|
22
|
-
set value(x) {
|
|
23
|
-
if (!Object.is(x, this.a)) {
|
|
24
|
-
this.a = x;
|
|
25
|
-
this.bump();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/** Read without subscribing. */
|
|
29
|
-
peek() {
|
|
30
|
-
return this.a;
|
|
31
|
-
}
|
|
32
|
-
/** Notify subscribers without replacing the value (after mutating an array or object in place). */
|
|
33
|
-
bump() {
|
|
34
|
-
this.e++;
|
|
35
|
-
for (const s of [...this.f]) s.h();
|
|
36
|
-
if (!depth) flush();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const release = (t) => {
|
|
40
|
-
for (const d of t.b.keys()) d.f.delete(t);
|
|
41
|
-
t.b.clear();
|
|
42
|
-
};
|
|
43
|
-
const stale = (t) => {
|
|
44
|
-
for (const [d, seen] of t.b) {
|
|
45
|
-
if (d instanceof Computed) d.i();
|
|
46
|
-
if (d.e !== seen) return true;
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
49
|
-
};
|
|
50
|
-
const capture = (t, fn) => {
|
|
51
|
-
release(t);
|
|
52
|
-
const prev = active;
|
|
53
|
-
active = t;
|
|
54
|
-
try {
|
|
55
|
-
return fn();
|
|
56
|
-
} finally {
|
|
57
|
-
active = prev;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
class Computed extends Signal {
|
|
61
|
-
constructor(fn) {
|
|
62
|
-
super(void 0);
|
|
63
|
-
this.b = /* @__PURE__ */ new Map();
|
|
64
|
-
/** @internal */
|
|
65
|
-
this.g = true;
|
|
66
|
-
this.c = fn;
|
|
67
|
-
}
|
|
68
|
-
/** @internal */
|
|
69
|
-
i() {
|
|
70
|
-
if (!this.g) return;
|
|
71
|
-
this.g = false;
|
|
72
|
-
if (this.b.size && !stale(this)) return;
|
|
73
|
-
const x = capture(this, this.c);
|
|
74
|
-
if (!Object.is(x, this.a)) {
|
|
75
|
-
this.a = x;
|
|
76
|
-
this.e++;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
get value() {
|
|
80
|
-
this.i();
|
|
81
|
-
return super.value;
|
|
82
|
-
}
|
|
83
|
-
set value(_) {
|
|
84
|
-
throw new Error("computed signals are read-only");
|
|
85
|
-
}
|
|
86
|
-
peek() {
|
|
87
|
-
this.i();
|
|
88
|
-
return this.a;
|
|
89
|
-
}
|
|
90
|
-
h() {
|
|
91
|
-
if (!this.g) {
|
|
92
|
-
this.g = true;
|
|
93
|
-
for (const s of this.f) s.h();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
class Effect {
|
|
98
|
-
constructor(fn, onError) {
|
|
99
|
-
this.b = /* @__PURE__ */ new Map();
|
|
100
|
-
this.j = false;
|
|
101
|
-
this.k = false;
|
|
102
|
-
this.d = /* @__PURE__ */ new Set();
|
|
103
|
-
this.c = fn;
|
|
104
|
-
this.l = onError;
|
|
105
|
-
}
|
|
106
|
-
h() {
|
|
107
|
-
if (!this.k && !this.j) {
|
|
108
|
-
this.j = true;
|
|
109
|
-
queue.add(this);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
n() {
|
|
113
|
-
this.j = false;
|
|
114
|
-
if (this.k || this.b.size && !stale(this)) return;
|
|
115
|
-
for (const c of this.d) c.m();
|
|
116
|
-
this.d.clear();
|
|
117
|
-
const prevOwner = owner;
|
|
118
|
-
owner = this;
|
|
119
|
-
depth++;
|
|
120
|
-
try {
|
|
121
|
-
capture(this, this.c);
|
|
122
|
-
} catch (e) {
|
|
123
|
-
if (!this.l) throw e;
|
|
124
|
-
this.l(e);
|
|
125
|
-
} finally {
|
|
126
|
-
depth--;
|
|
127
|
-
owner = prevOwner;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
m() {
|
|
131
|
-
this.k = true;
|
|
132
|
-
release(this);
|
|
133
|
-
for (const c of this.d) c.m();
|
|
134
|
-
this.d.clear();
|
|
135
|
-
queue.delete(this);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
const signal = (value) => new Signal(value);
|
|
139
|
-
const computed = (fn) => new Computed(fn);
|
|
140
|
-
const effect = (fn, onError) => {
|
|
141
|
-
const e = new Effect(fn, onError);
|
|
142
|
-
owner?.d.add(e);
|
|
143
|
-
e.n();
|
|
144
|
-
if (!depth) flush();
|
|
145
|
-
return () => e.m();
|
|
146
|
-
};
|
|
147
|
-
const batch = (fn) => {
|
|
148
|
-
depth++;
|
|
149
|
-
try {
|
|
150
|
-
return fn();
|
|
151
|
-
} finally {
|
|
152
|
-
if (!--depth) flush();
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
const untracked = (fn) => {
|
|
156
|
-
const prev = active;
|
|
157
|
-
active = void 0;
|
|
158
|
-
try {
|
|
159
|
-
return fn();
|
|
160
|
-
} finally {
|
|
161
|
-
active = prev;
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
const onSettled = (fn) => {
|
|
165
|
-
settled.add(fn);
|
|
166
|
-
return () => settled.delete(fn);
|
|
167
|
-
};
|
|
168
|
-
const flush = () => {
|
|
169
|
-
if (flushing || depth) return;
|
|
170
|
-
flushing = true;
|
|
171
|
-
try {
|
|
172
|
-
let guard = 0;
|
|
173
|
-
while (queue.size) {
|
|
174
|
-
if (++guard > 1e5) throw new Error("effect loop: a signal is written by an effect that reads it");
|
|
175
|
-
const e = queue.values().next().value;
|
|
176
|
-
queue.delete(e);
|
|
177
|
-
e.n();
|
|
178
|
-
}
|
|
179
|
-
} finally {
|
|
180
|
-
flushing = false;
|
|
181
|
-
}
|
|
182
|
-
for (const fn of settled) fn();
|
|
183
|
-
};
|
|
184
|
-
export {
|
|
185
|
-
Computed,
|
|
186
|
-
Signal,
|
|
187
|
-
batch,
|
|
188
|
-
computed,
|
|
189
|
-
effect,
|
|
190
|
-
flush,
|
|
191
|
-
onSettled,
|
|
192
|
-
signal,
|
|
193
|
-
untracked
|
|
194
|
-
};
|
|
195
|
-
//# sourceMappingURL=signals.js.map
|