sigmx 0.1.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/LICENSE +21 -0
- package/README.md +173 -0
- package/dist/auto.d.ts +1 -0
- package/dist/auto.js +7 -0
- package/dist/auto.js.map +7 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +26 -0
- package/dist/cli.js.map +7 -0
- package/dist/core/csp.d.ts +7 -0
- package/dist/core/csp.js +20 -0
- package/dist/core/csp.js.map +7 -0
- package/dist/core/engine.d.ts +10 -0
- package/dist/core/engine.js +200 -0
- package/dist/core/engine.js.map +7 -0
- package/dist/core/expr.d.ts +12 -0
- package/dist/core/expr.js +94 -0
- package/dist/core/expr.js.map +7 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.js +46 -0
- package/dist/core/index.js.map +7 -0
- package/dist/core/signals.d.ts +42 -0
- package/dist/core/signals.js +195 -0
- package/dist/core/signals.js.map +7 -0
- package/dist/core/store.d.ts +32 -0
- package/dist/core/store.js +185 -0
- package/dist/core/store.js.map +7 -0
- package/dist/core/types.d.ts +101 -0
- package/dist/core/types.js +1 -0
- package/dist/core/types.js.map +7 -0
- package/dist/kernel/compile.d.ts +16 -0
- package/dist/kernel/compile.js +96 -0
- package/dist/kernel/compile.js.map +7 -0
- package/dist/kernel/contracts.d.ts +121 -0
- package/dist/kernel/contracts.js +1 -0
- package/dist/kernel/contracts.js.map +7 -0
- package/dist/kernel/index.d.ts +20 -0
- package/dist/kernel/index.js +54 -0
- package/dist/kernel/index.js.map +7 -0
- package/dist/kernel/precompile.d.ts +25 -0
- package/dist/kernel/precompile.js +111 -0
- package/dist/kernel/precompile.js.map +7 -0
- package/dist/kernel/precompiled.d.ts +11 -0
- package/dist/kernel/precompiled.js +13 -0
- package/dist/kernel/precompiled.js.map +7 -0
- package/dist/kernel/reactive.d.ts +42 -0
- package/dist/kernel/reactive.js +201 -0
- package/dist/kernel/reactive.js.map +7 -0
- package/dist/kernel/runtime.d.ts +11 -0
- package/dist/kernel/runtime.js +210 -0
- package/dist/kernel/runtime.js.map +7 -0
- package/dist/kernel/scan.d.ts +42 -0
- package/dist/kernel/scan.js +68 -0
- package/dist/kernel/scan.js.map +7 -0
- package/dist/kernel/state.d.ts +32 -0
- package/dist/kernel/state.js +186 -0
- package/dist/kernel/state.js.map +7 -0
- package/dist/kernel/strict-csp.d.ts +7 -0
- package/dist/kernel/strict-csp.js +20 -0
- package/dist/kernel/strict-csp.js.map +7 -0
- package/dist/lib/casing.d.ts +7 -0
- package/dist/lib/casing.js +16 -0
- package/dist/lib/casing.js.map +7 -0
- package/dist/lib/objects.d.ts +9 -0
- package/dist/lib/objects.js +26 -0
- package/dist/lib/objects.js.map +7 -0
- package/dist/lib/schedule.d.ts +14 -0
- package/dist/lib/schedule.js +51 -0
- package/dist/lib/schedule.js.map +7 -0
- package/dist/lib/sse.d.ts +10 -0
- package/dist/lib/sse.js +55 -0
- package/dist/lib/sse.js.map +7 -0
- package/dist/plugins/actions/clipboard.d.ts +2 -0
- package/dist/plugins/actions/clipboard.js +11 -0
- package/dist/plugins/actions/clipboard.js.map +7 -0
- package/dist/plugins/actions/fit.d.ts +2 -0
- package/dist/plugins/actions/fit.js +14 -0
- package/dist/plugins/actions/fit.js.map +7 -0
- package/dist/plugins/actions/intl.d.ts +2 -0
- package/dist/plugins/actions/intl.js +21 -0
- package/dist/plugins/actions/intl.js.map +7 -0
- package/dist/plugins/actions/peek.d.ts +2 -0
- package/dist/plugins/actions/peek.js +6 -0
- package/dist/plugins/actions/peek.js.map +7 -0
- package/dist/plugins/actions/setAll.d.ts +2 -0
- package/dist/plugins/actions/setAll.js +11 -0
- package/dist/plugins/actions/setAll.js.map +7 -0
- package/dist/plugins/actions/toggleAll.d.ts +2 -0
- package/dist/plugins/actions/toggleAll.js +11 -0
- package/dist/plugins/actions/toggleAll.js.map +7 -0
- package/dist/plugins/attributes/attr.d.ts +2 -0
- package/dist/plugins/attributes/attr.js +20 -0
- package/dist/plugins/attributes/attr.js.map +7 -0
- package/dist/plugins/attributes/bind.d.ts +6 -0
- package/dist/plugins/attributes/bind.js +81 -0
- package/dist/plugins/attributes/bind.js.map +7 -0
- package/dist/plugins/attributes/class.d.ts +2 -0
- package/dist/plugins/attributes/class.js +22 -0
- package/dist/plugins/attributes/class.js.map +7 -0
- package/dist/plugins/attributes/computed.d.ts +2 -0
- package/dist/plugins/attributes/computed.js +20 -0
- package/dist/plugins/attributes/computed.js.map +7 -0
- package/dist/plugins/attributes/customValidity.d.ts +2 -0
- package/dist/plugins/attributes/customValidity.js +14 -0
- package/dist/plugins/attributes/customValidity.js.map +7 -0
- package/dist/plugins/attributes/effect.d.ts +2 -0
- package/dist/plugins/attributes/effect.js +12 -0
- package/dist/plugins/attributes/effect.js.map +7 -0
- package/dist/plugins/attributes/indicator.d.ts +2 -0
- package/dist/plugins/attributes/indicator.js +20 -0
- package/dist/plugins/attributes/indicator.js.map +7 -0
- package/dist/plugins/attributes/init.d.ts +2 -0
- package/dist/plugins/attributes/init.js +14 -0
- package/dist/plugins/attributes/init.js.map +7 -0
- package/dist/plugins/attributes/jsonSignals.d.ts +2 -0
- package/dist/plugins/attributes/jsonSignals.js +15 -0
- package/dist/plugins/attributes/jsonSignals.js.map +7 -0
- package/dist/plugins/attributes/matchMedia.d.ts +2 -0
- package/dist/plugins/attributes/matchMedia.js +19 -0
- package/dist/plugins/attributes/matchMedia.js.map +7 -0
- package/dist/plugins/attributes/on.d.ts +5 -0
- package/dist/plugins/attributes/on.js +28 -0
- package/dist/plugins/attributes/on.js.map +7 -0
- package/dist/plugins/attributes/onIntersect.d.ts +2 -0
- package/dist/plugins/attributes/onIntersect.js +28 -0
- package/dist/plugins/attributes/onIntersect.js.map +7 -0
- package/dist/plugins/attributes/onInterval.d.ts +2 -0
- package/dist/plugins/attributes/onInterval.js +18 -0
- package/dist/plugins/attributes/onInterval.js.map +7 -0
- package/dist/plugins/attributes/onRaf.d.ts +1 -0
- package/dist/plugins/attributes/onRaf.js +19 -0
- package/dist/plugins/attributes/onRaf.js.map +7 -0
- package/dist/plugins/attributes/onResize.d.ts +1 -0
- package/dist/plugins/attributes/onResize.js +17 -0
- package/dist/plugins/attributes/onResize.js.map +7 -0
- package/dist/plugins/attributes/onSignalPatch.d.ts +5 -0
- package/dist/plugins/attributes/onSignalPatch.js +35 -0
- package/dist/plugins/attributes/onSignalPatch.js.map +7 -0
- package/dist/plugins/attributes/persist.d.ts +6 -0
- package/dist/plugins/attributes/persist.js +16 -0
- package/dist/plugins/attributes/persist.js.map +7 -0
- package/dist/plugins/attributes/queryString.d.ts +5 -0
- package/dist/plugins/attributes/queryString.js +54 -0
- package/dist/plugins/attributes/queryString.js.map +7 -0
- package/dist/plugins/attributes/ref.d.ts +2 -0
- package/dist/plugins/attributes/ref.js +13 -0
- package/dist/plugins/attributes/ref.js.map +7 -0
- package/dist/plugins/attributes/replaceUrl.d.ts +1 -0
- package/dist/plugins/attributes/replaceUrl.js +11 -0
- package/dist/plugins/attributes/replaceUrl.js.map +7 -0
- package/dist/plugins/attributes/scrollIntoView.d.ts +2 -0
- package/dist/plugins/attributes/scrollIntoView.js +19 -0
- package/dist/plugins/attributes/scrollIntoView.js.map +7 -0
- package/dist/plugins/attributes/show.d.ts +2 -0
- package/dist/plugins/attributes/show.js +19 -0
- package/dist/plugins/attributes/show.js.map +7 -0
- package/dist/plugins/attributes/signals.d.ts +2 -0
- package/dist/plugins/attributes/signals.js +13 -0
- package/dist/plugins/attributes/signals.js.map +7 -0
- package/dist/plugins/attributes/style.d.ts +2 -0
- package/dist/plugins/attributes/style.js +25 -0
- package/dist/plugins/attributes/style.js.map +7 -0
- package/dist/plugins/attributes/text.d.ts +1 -0
- package/dist/plugins/attributes/text.js +13 -0
- package/dist/plugins/attributes/text.js.map +7 -0
- package/dist/plugins/attributes/viewTransition.d.ts +1 -0
- package/dist/plugins/attributes/viewTransition.js +11 -0
- package/dist/plugins/attributes/viewTransition.js.map +7 -0
- package/dist/plugins/directives/attribute-sync.d.ts +2 -0
- package/dist/plugins/directives/attribute-sync.js +20 -0
- package/dist/plugins/directives/attribute-sync.js.map +7 -0
- package/dist/plugins/directives/boost.d.ts +6 -0
- package/dist/plugins/directives/boost.js +35 -0
- package/dist/plugins/directives/boost.js.map +7 -0
- package/dist/plugins/directives/busy-flag.d.ts +2 -0
- package/dist/plugins/directives/busy-flag.js +21 -0
- package/dist/plugins/directives/busy-flag.js.map +7 -0
- package/dist/plugins/directives/class-toggle.d.ts +2 -0
- package/dist/plugins/directives/class-toggle.js +22 -0
- package/dist/plugins/directives/class-toggle.js.map +7 -0
- package/dist/plugins/directives/cloak.d.ts +5 -0
- package/dist/plugins/directives/cloak.js +11 -0
- package/dist/plugins/directives/cloak.js.map +7 -0
- package/dist/plugins/directives/collapse.d.ts +5 -0
- package/dist/plugins/directives/collapse.js +42 -0
- package/dist/plugins/directives/collapse.js.map +7 -0
- package/dist/plugins/directives/declare.d.ts +2 -0
- package/dist/plugins/directives/declare.js +13 -0
- package/dist/plugins/directives/declare.js.map +7 -0
- package/dist/plugins/directives/derive.d.ts +2 -0
- package/dist/plugins/directives/derive.js +20 -0
- package/dist/plugins/directives/derive.js.map +7 -0
- package/dist/plugins/directives/element-ref.d.ts +2 -0
- package/dist/plugins/directives/element-ref.js +13 -0
- package/dist/plugins/directives/element-ref.js.map +7 -0
- package/dist/plugins/directives/event-listener.d.ts +5 -0
- package/dist/plugins/directives/event-listener.js +28 -0
- package/dist/plugins/directives/event-listener.js.map +7 -0
- package/dist/plugins/directives/frame-loop.d.ts +1 -0
- package/dist/plugins/directives/frame-loop.js +19 -0
- package/dist/plugins/directives/frame-loop.js.map +7 -0
- package/dist/plugins/directives/html.d.ts +2 -0
- package/dist/plugins/directives/html.js +13 -0
- package/dist/plugins/directives/html.js.map +7 -0
- package/dist/plugins/directives/inline-style.d.ts +2 -0
- package/dist/plugins/directives/inline-style.js +25 -0
- package/dist/plugins/directives/inline-style.js.map +7 -0
- package/dist/plugins/directives/mask.d.ts +7 -0
- package/dist/plugins/directives/mask.js +47 -0
- package/dist/plugins/directives/mask.js.map +7 -0
- package/dist/plugins/directives/media-query.d.ts +2 -0
- package/dist/plugins/directives/media-query.js +19 -0
- package/dist/plugins/directives/media-query.js.map +7 -0
- package/dist/plugins/directives/on-mount.d.ts +2 -0
- package/dist/plugins/directives/on-mount.js +14 -0
- package/dist/plugins/directives/on-mount.js.map +7 -0
- package/dist/plugins/directives/patch-listener.d.ts +5 -0
- package/dist/plugins/directives/patch-listener.js +35 -0
- package/dist/plugins/directives/patch-listener.js.map +7 -0
- package/dist/plugins/directives/remove-me.d.ts +2 -0
- package/dist/plugins/directives/remove-me.js +13 -0
- package/dist/plugins/directives/remove-me.js.map +7 -0
- package/dist/plugins/directives/scroll-to.d.ts +2 -0
- package/dist/plugins/directives/scroll-to.js +19 -0
- package/dist/plugins/directives/scroll-to.js.map +7 -0
- package/dist/plugins/directives/size-watch.d.ts +1 -0
- package/dist/plugins/directives/size-watch.js +17 -0
- package/dist/plugins/directives/size-watch.js.map +7 -0
- package/dist/plugins/directives/state-dump.d.ts +2 -0
- package/dist/plugins/directives/state-dump.js +15 -0
- package/dist/plugins/directives/state-dump.js.map +7 -0
- package/dist/plugins/directives/storage-sync.d.ts +6 -0
- package/dist/plugins/directives/storage-sync.js +16 -0
- package/dist/plugins/directives/storage-sync.js.map +7 -0
- package/dist/plugins/directives/teleport.d.ts +5 -0
- package/dist/plugins/directives/teleport.js +19 -0
- package/dist/plugins/directives/teleport.js.map +7 -0
- package/dist/plugins/directives/text-content.d.ts +1 -0
- package/dist/plugins/directives/text-content.js +13 -0
- package/dist/plugins/directives/text-content.js.map +7 -0
- package/dist/plugins/directives/timer.d.ts +2 -0
- package/dist/plugins/directives/timer.js +18 -0
- package/dist/plugins/directives/timer.js.map +7 -0
- package/dist/plugins/directives/transition-name.d.ts +1 -0
- package/dist/plugins/directives/transition-name.js +11 -0
- package/dist/plugins/directives/transition-name.js.map +7 -0
- package/dist/plugins/directives/transition.d.ts +5 -0
- package/dist/plugins/directives/transition.js +40 -0
- package/dist/plugins/directives/transition.js.map +7 -0
- package/dist/plugins/directives/trap.d.ts +5 -0
- package/dist/plugins/directives/trap.js +48 -0
- package/dist/plugins/directives/trap.js.map +7 -0
- package/dist/plugins/directives/tween.d.ts +6 -0
- package/dist/plugins/directives/tween.js +58 -0
- package/dist/plugins/directives/tween.js.map +7 -0
- package/dist/plugins/directives/two-way-bind.d.ts +6 -0
- package/dist/plugins/directives/two-way-bind.js +82 -0
- package/dist/plugins/directives/two-way-bind.js.map +7 -0
- package/dist/plugins/directives/url-params.d.ts +13 -0
- package/dist/plugins/directives/url-params.js +76 -0
- package/dist/plugins/directives/url-params.js.map +7 -0
- package/dist/plugins/directives/url-replace.d.ts +1 -0
- package/dist/plugins/directives/url-replace.js +11 -0
- package/dist/plugins/directives/url-replace.js.map +7 -0
- package/dist/plugins/directives/validity.d.ts +2 -0
- package/dist/plugins/directives/validity.js +14 -0
- package/dist/plugins/directives/validity.js.map +7 -0
- package/dist/plugins/directives/viewport.d.ts +2 -0
- package/dist/plugins/directives/viewport.js +28 -0
- package/dist/plugins/directives/viewport.js.map +7 -0
- package/dist/plugins/directives/visibility.d.ts +2 -0
- package/dist/plugins/directives/visibility.js +19 -0
- package/dist/plugins/directives/visibility.js.map +7 -0
- package/dist/plugins/directives/watch.d.ts +2 -0
- package/dist/plugins/directives/watch.js +12 -0
- package/dist/plugins/directives/watch.js.map +7 -0
- package/dist/plugins/functions/bulk-set.d.ts +2 -0
- package/dist/plugins/functions/bulk-set.js +11 -0
- package/dist/plugins/functions/bulk-set.js.map +7 -0
- package/dist/plugins/functions/bulk-toggle.d.ts +2 -0
- package/dist/plugins/functions/bulk-toggle.js +11 -0
- package/dist/plugins/functions/bulk-toggle.js.map +7 -0
- package/dist/plugins/functions/confirm.d.ts +2 -0
- package/dist/plugins/functions/confirm.js +6 -0
- package/dist/plugins/functions/confirm.js.map +7 -0
- package/dist/plugins/functions/copy-text.d.ts +2 -0
- package/dist/plugins/functions/copy-text.js +11 -0
- package/dist/plugins/functions/copy-text.js.map +7 -0
- package/dist/plugins/functions/dispatch.d.ts +2 -0
- package/dist/plugins/functions/dispatch.js +9 -0
- package/dist/plugins/functions/dispatch.js.map +7 -0
- package/dist/plugins/functions/locale-format.d.ts +2 -0
- package/dist/plugins/functions/locale-format.js +21 -0
- package/dist/plugins/functions/locale-format.js.map +7 -0
- package/dist/plugins/functions/range-map.d.ts +2 -0
- package/dist/plugins/functions/range-map.js +14 -0
- package/dist/plugins/functions/range-map.js.map +7 -0
- package/dist/plugins/functions/request.d.ts +30 -0
- package/dist/plugins/functions/request.js +152 -0
- package/dist/plugins/functions/request.js.map +7 -0
- package/dist/plugins/functions/untracked-read.d.ts +2 -0
- package/dist/plugins/functions/untracked-read.js +6 -0
- package/dist/plugins/functions/untracked-read.js.map +7 -0
- package/dist/plugins/functions/websocket.d.ts +11 -0
- package/dist/plugins/functions/websocket.js +35 -0
- package/dist/plugins/functions/websocket.js.map +7 -0
- package/dist/plugins/index.d.ts +52 -0
- package/dist/plugins/index.js +108 -0
- package/dist/plugins/index.js.map +7 -0
- package/dist/plugins/server-events/apply-elements.d.ts +2 -0
- package/dist/plugins/server-events/apply-elements.js +62 -0
- package/dist/plugins/server-events/apply-elements.js.map +7 -0
- package/dist/plugins/server-events/apply-state.d.ts +2 -0
- package/dist/plugins/server-events/apply-state.js +18 -0
- package/dist/plugins/server-events/apply-state.js.map +7 -0
- package/dist/plugins/server-events/morph.d.ts +12 -0
- package/dist/plugins/server-events/morph.js +124 -0
- package/dist/plugins/server-events/morph.js.map +7 -0
- package/dist/presets/all.d.ts +3 -0
- package/dist/presets/all.js +112 -0
- package/dist/presets/all.js.map +7 -0
- package/dist/presets/essentials.d.ts +3 -0
- package/dist/presets/essentials.js +18 -0
- package/dist/presets/essentials.js.map +7 -0
- package/dist/presets/minimal.d.ts +3 -0
- package/dist/presets/minimal.js +9 -0
- package/dist/presets/minimal.js.map +7 -0
- package/dist/sigmx.auto.js +5 -0
- package/dist/sigmx.standalone.js +1 -0
- package/dist/standalone.d.ts +1 -0
- package/dist/standalone.js +8 -0
- package/dist/standalone.js.map +7 -0
- package/dist/utils/object.d.ts +9 -0
- package/dist/utils/object.js +26 -0
- package/dist/utils/object.js.map +7 -0
- package/dist/utils/text.d.ts +7 -0
- package/dist/utils/text.js +15 -0
- package/dist/utils/text.js.map +7 -0
- package/dist/utils/timing.d.ts +14 -0
- package/dist/utils/timing.js +58 -0
- package/dist/utils/timing.js.map +7 -0
- package/dist/vite.d.ts +42 -0
- package/dist/vite.js +79 -0
- package/dist/vite.js.map +7 -0
- package/package.json +111 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { attribute } from "../../kernel/index.js";
|
|
2
|
+
const pick = (mods, names, fallback) => names.find((n) => mods.has(n)) ?? fallback;
|
|
3
|
+
const scrollIntoView = attribute({
|
|
4
|
+
name: "scroll-into-view",
|
|
5
|
+
key: "forbidden",
|
|
6
|
+
value: "forbidden",
|
|
7
|
+
mount({ el, mods }) {
|
|
8
|
+
el.scrollIntoView({
|
|
9
|
+
behavior: pick(mods, ["smooth", "instant", "auto"], "smooth"),
|
|
10
|
+
block: pick(mods, ["vstart", "vcenter", "vend", "vnearest"], "vcenter").slice(1),
|
|
11
|
+
inline: pick(mods, ["hstart", "hcenter", "hend", "hnearest"], "hcenter").slice(1)
|
|
12
|
+
});
|
|
13
|
+
if (mods.has("focus")) el.focus?.();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
export {
|
|
17
|
+
scrollIntoView
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=scroll-to.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/scroll-to.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute } from '../../kernel/index.js'\n\nconst pick = (mods: Map<string, string[]>, names: string[], fallback: string) =>\n names.find((n) => mods.has(n)) ?? fallback\n\n/** Scrolls the element into view on mount. Modifiers: smooth/instant/auto, vstart..vnearest, hstart..hnearest, focus. */\nexport const scrollIntoView = attribute({\n name: 'scroll-into-view',\n key: 'forbidden',\n value: 'forbidden',\n mount({ el, mods }) {\n el.scrollIntoView({\n behavior: pick(mods, ['smooth', 'instant', 'auto'], 'smooth') as ScrollBehavior,\n block: pick(mods, ['vstart', 'vcenter', 'vend', 'vnearest'], 'vcenter').slice(1) as ScrollLogicalPosition,\n inline: pick(mods, ['hstart', 'hcenter', 'hend', 'hnearest'], 'hcenter').slice(1) as ScrollLogicalPosition,\n })\n if (mods.has('focus')) (el as HTMLElement).focus?.()\n },\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAE1B,MAAM,OAAO,CAAC,MAA6B,OAAiB,aAC1D,MAAM,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,KAAK;AAG7B,MAAM,iBAAiB,UAAU;AAAA,EACtC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,MAAM,EAAE,IAAI,KAAK,GAAG;AAClB,OAAG,eAAe;AAAA,MAChB,UAAU,KAAK,MAAM,CAAC,UAAU,WAAW,MAAM,GAAG,QAAQ;AAAA,MAC5D,OAAO,KAAK,MAAM,CAAC,UAAU,WAAW,QAAQ,UAAU,GAAG,SAAS,EAAE,MAAM,CAAC;AAAA,MAC/E,QAAQ,KAAK,MAAM,CAAC,UAAU,WAAW,QAAQ,UAAU,GAAG,SAAS,EAAE,MAAM,CAAC;AAAA,IAClF,CAAC;AACD,QAAI,KAAK,IAAI,OAAO,EAAG,CAAC,GAAmB,QAAQ;AAAA,EACrD;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const onResize: import("../../kernel/contracts.js").AttributePlugin;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { attribute, withTiming } from "../../kernel/index.js";
|
|
2
|
+
const onResize = attribute({
|
|
3
|
+
name: "on-resize",
|
|
4
|
+
key: "forbidden",
|
|
5
|
+
value: "required",
|
|
6
|
+
returns: false,
|
|
7
|
+
mount({ el, mods, evaluate }) {
|
|
8
|
+
const run = withTiming(() => evaluate(), mods);
|
|
9
|
+
const ro = new ResizeObserver(() => run());
|
|
10
|
+
ro.observe(el);
|
|
11
|
+
return () => ro.disconnect();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
export {
|
|
15
|
+
onResize
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=size-watch.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/size-watch.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute, withTiming } from '../../kernel/index.js'\n\nexport const onResize = attribute({\n name: 'on-resize',\n key: 'forbidden',\n value: 'required',\n returns: false,\n mount({ el, mods, evaluate }) {\n const run = withTiming(() => evaluate(), mods)\n const ro = new ResizeObserver(() => run())\n ro.observe(el)\n return () => ro.disconnect()\n },\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW,kBAAkB;AAE/B,MAAM,WAAW,UAAU;AAAA,EAChC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM,EAAE,IAAI,MAAM,SAAS,GAAG;AAC5B,UAAM,MAAM,WAAW,MAAM,SAAS,GAAG,IAAI;AAC7C,UAAM,KAAK,IAAI,eAAe,MAAM,IAAI,CAAC;AACzC,OAAG,QAAQ,EAAE;AACb,WAAO,MAAM,GAAG,WAAW;AAAA,EAC7B;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { attribute } from "../../kernel/index.js";
|
|
2
|
+
const jsonSignals = attribute({
|
|
3
|
+
name: "json-signals",
|
|
4
|
+
key: "forbidden",
|
|
5
|
+
mount({ el, value, mods, evaluate, effect, store }) {
|
|
6
|
+
const filter = value ? evaluate() : void 0;
|
|
7
|
+
effect(() => {
|
|
8
|
+
el.textContent = JSON.stringify(store.snapshot(filter), null, mods.has("terse") ? 0 : 2);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
export {
|
|
13
|
+
jsonSignals
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=state-dump.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/state-dump.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute } from '../../kernel/index.js'\n\n/** Renders the store (or a filtered part) as JSON. `__terse` for single-line output. */\nexport const jsonSignals = attribute({\n name: 'json-signals',\n key: 'forbidden',\n mount({ el, value, mods, evaluate, effect, store }) {\n const filter = value ? evaluate() : undefined\n effect(() => {\n el.textContent = JSON.stringify(store.snapshot(filter), null, mods.has('terse') ? 0 : 2)\n })\n },\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAGnB,MAAM,cAAc,UAAU;AAAA,EACnC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM,EAAE,IAAI,OAAO,MAAM,UAAU,QAAQ,MAAM,GAAG;AAClD,UAAM,SAAS,QAAQ,SAAS,IAAI;AACpC,WAAO,MAAM;AACX,SAAG,cAAc,KAAK,UAAU,MAAM,SAAS,MAAM,GAAG,MAAM,KAAK,IAAI,OAAO,IAAI,IAAI,CAAC;AAAA,IACzF,CAAC;AAAA,EACH;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Saves matching signals to localStorage (`__session` for sessionStorage) and restores them on
|
|
3
|
+
* mount. `persist:key` sets the storage key; the value is an optional `{ include, exclude }` filter.
|
|
4
|
+
* Declare defaults with `signals:x__ifmissing` so restored values are not overwritten.
|
|
5
|
+
*/
|
|
6
|
+
export declare const persist: import("../../kernel/contracts.js").AttributePlugin;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { attribute } from "../../kernel/index.js";
|
|
2
|
+
const persist = attribute({
|
|
3
|
+
name: "persist",
|
|
4
|
+
mount({ key, value, mods, evaluate, store, effect }) {
|
|
5
|
+
const storage = mods.has("session") ? sessionStorage : localStorage;
|
|
6
|
+
const name = key || "sigmx";
|
|
7
|
+
const filter = value ? evaluate() : void 0;
|
|
8
|
+
const saved = storage.getItem(name);
|
|
9
|
+
if (saved) store.merge(JSON.parse(saved));
|
|
10
|
+
effect(() => storage.setItem(name, JSON.stringify(store.snapshot(filter, { computed: false }))));
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export {
|
|
14
|
+
persist
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=storage-sync.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/storage-sync.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute } from '../../kernel/index.js'\n\n/**\n * Saves matching signals to localStorage (`__session` for sessionStorage) and restores them on\n * mount. `persist:key` sets the storage key; the value is an optional `{ include, exclude }` filter.\n * Declare defaults with `signals:x__ifmissing` so restored values are not overwritten.\n */\nexport const persist = attribute({\n name: 'persist',\n mount({ key, value, mods, evaluate, store, effect }) {\n const storage = mods.has('session') ? sessionStorage : localStorage\n const name = key || 'sigmx'\n const filter = value ? evaluate() : undefined\n const saved = storage.getItem(name)\n if (saved) store.merge(JSON.parse(saved))\n effect(() => storage.setItem(name, JSON.stringify(store.snapshot(filter, { computed: false }))))\n },\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAOnB,MAAM,UAAU,UAAU;AAAA,EAC/B,MAAM;AAAA,EACN,MAAM,EAAE,KAAK,OAAO,MAAM,UAAU,OAAO,OAAO,GAAG;AACnD,UAAM,UAAU,KAAK,IAAI,SAAS,IAAI,iBAAiB;AACvD,UAAM,OAAO,OAAO;AACpB,UAAM,SAAS,QAAQ,SAAS,IAAI;AACpC,UAAM,QAAQ,QAAQ,QAAQ,IAAI;AAClC,QAAI,MAAO,OAAM,MAAM,KAAK,MAAM,KAAK,CAAC;AACxC,WAAO,MAAM,QAAQ,QAAQ,MAAM,KAAK,UAAU,MAAM,SAAS,QAAQ,EAAE,UAAU,MAAM,CAAC,CAAC,CAAC,CAAC;AAAA,EACjG;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moves the element to another place in the document: `teleport="body"` (a selector).
|
|
3
|
+
* `__prepend` inserts at the start. The element and its signals keep working where it lands.
|
|
4
|
+
*/
|
|
5
|
+
export declare const teleport: import("../../kernel/contracts.js").AttributePlugin;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { attribute } from "../../kernel/index.js";
|
|
2
|
+
const teleport = attribute({
|
|
3
|
+
name: "teleport",
|
|
4
|
+
key: "forbidden",
|
|
5
|
+
value: "required",
|
|
6
|
+
mount({ el, value, mods, error }) {
|
|
7
|
+
const target = document.querySelector(value);
|
|
8
|
+
if (!target) throw error(`no element matches "${value}"`);
|
|
9
|
+
if (el.parentElement === target) return;
|
|
10
|
+
const before = mods.has("prepend") ? target.firstChild : null;
|
|
11
|
+
const t = target;
|
|
12
|
+
if (t.moveBefore) t.moveBefore(el, before);
|
|
13
|
+
else target.insertBefore(el, before);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
export {
|
|
17
|
+
teleport
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=teleport.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/teleport.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute } from '../../kernel/index.js'\n\n/**\n * Moves the element to another place in the document: `teleport=\"body\"` (a selector).\n * `__prepend` inserts at the start. The element and its signals keep working where it lands.\n */\nexport const teleport = attribute({\n name: 'teleport',\n key: 'forbidden',\n value: 'required',\n mount({ el, value, mods, error }) {\n const target = document.querySelector(value)\n if (!target) throw error(`no element matches \"${value}\"`)\n if (el.parentElement === target) return\n const before = mods.has('prepend') ? target.firstChild : null\n const t = target as Node & { moveBefore?: (n: Node, b: Node | null) => void }\n // `moveBefore` keeps state and avoids an unmount/remount; fall back to a plain move.\n if (t.moveBefore) t.moveBefore(el, before)\n else target.insertBefore(el, before)\n },\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAMnB,MAAM,WAAW,UAAU;AAAA,EAChC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,MAAM,EAAE,IAAI,OAAO,MAAM,MAAM,GAAG;AAChC,UAAM,SAAS,SAAS,cAAc,KAAK;AAC3C,QAAI,CAAC,OAAQ,OAAM,MAAM,uBAAuB,KAAK,GAAG;AACxD,QAAI,GAAG,kBAAkB,OAAQ;AACjC,UAAM,SAAS,KAAK,IAAI,SAAS,IAAI,OAAO,aAAa;AACzD,UAAM,IAAI;AAEV,QAAI,EAAE,WAAY,GAAE,WAAW,IAAI,MAAM;AAAA,QACpC,QAAO,aAAa,IAAI,MAAM;AAAA,EACrC;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const text: import("../../kernel/contracts.js").AttributePlugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { attribute } from "../../kernel/index.js";
|
|
2
|
+
const text = attribute({
|
|
3
|
+
name: "text",
|
|
4
|
+
key: "forbidden",
|
|
5
|
+
value: "required",
|
|
6
|
+
mount: ({ el, evaluate, effect }) => effect(() => {
|
|
7
|
+
el.textContent = String(evaluate() ?? "");
|
|
8
|
+
})
|
|
9
|
+
});
|
|
10
|
+
export {
|
|
11
|
+
text
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=text-content.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/text-content.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute } from '../../kernel/index.js'\n\nexport const text = attribute({\n name: 'text',\n key: 'forbidden',\n value: 'required',\n mount: ({ el, evaluate, effect }) =>\n effect(() => {\n el.textContent = String(evaluate() ?? '')\n }),\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAEnB,MAAM,OAAO,UAAU;AAAA,EAC5B,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,OAAO,CAAC,EAAE,IAAI,UAAU,OAAO,MAC7B,OAAO,MAAM;AACX,OAAG,cAAc,OAAO,SAAS,KAAK,EAAE;AAAA,EAC1C,CAAC;AACL,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { attribute, toMs, withViewTransition } from "../../kernel/index.js";
|
|
2
|
+
const onInterval = attribute({
|
|
3
|
+
name: "on-interval",
|
|
4
|
+
key: "forbidden",
|
|
5
|
+
value: "required",
|
|
6
|
+
returns: false,
|
|
7
|
+
mount({ mods, evaluate }) {
|
|
8
|
+
const d = mods.get("duration");
|
|
9
|
+
const run = withViewTransition(() => evaluate(), mods);
|
|
10
|
+
if (d?.includes("leading")) run();
|
|
11
|
+
const id = setInterval(run, toMs(d, 1e3));
|
|
12
|
+
return () => clearInterval(id);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
export {
|
|
16
|
+
onInterval
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=timer.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/timer.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute, toMs, withViewTransition } from '../../kernel/index.js'\n\n/** `on-interval__duration.5s.leading=\"expr\"`. Default one second. */\nexport const onInterval = attribute({\n name: 'on-interval',\n key: 'forbidden',\n value: 'required',\n returns: false,\n mount({ mods, evaluate }) {\n const d = mods.get('duration')\n const run = withViewTransition(() => evaluate(), mods)\n if (d?.includes('leading')) run()\n const id = setInterval(run, toMs(d, 1000))\n return () => clearInterval(id)\n },\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW,MAAM,0BAA0B;AAG7C,MAAM,aAAa,UAAU;AAAA,EAClC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM,EAAE,MAAM,SAAS,GAAG;AACxB,UAAM,IAAI,KAAK,IAAI,UAAU;AAC7B,UAAM,MAAM,mBAAmB,MAAM,SAAS,GAAG,IAAI;AACrD,QAAI,GAAG,SAAS,SAAS,EAAG,KAAI;AAChC,UAAM,KAAK,YAAY,KAAK,KAAK,GAAG,GAAI,CAAC;AACzC,WAAO,MAAM,cAAc,EAAE;AAAA,EAC/B;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const viewTransition: import("../../kernel/contracts.js").AttributePlugin;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { attribute } from "../../kernel/index.js";
|
|
2
|
+
const viewTransition = attribute({
|
|
3
|
+
name: "view-transition",
|
|
4
|
+
key: "forbidden",
|
|
5
|
+
value: "required",
|
|
6
|
+
mount: ({ el, evaluate, effect }) => effect(() => el.style.setProperty("view-transition-name", String(evaluate())))
|
|
7
|
+
});
|
|
8
|
+
export {
|
|
9
|
+
viewTransition
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=transition-name.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/transition-name.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute } from '../../kernel/index.js'\n\nexport const viewTransition = attribute({\n name: 'view-transition',\n key: 'forbidden',\n value: 'required',\n mount: ({ el, evaluate, effect }) => effect(() => el.style.setProperty('view-transition-name', String(evaluate()))),\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAEnB,MAAM,iBAAiB,UAAU;AAAA,EACtC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,OAAO,CAAC,EAAE,IAAI,UAAU,OAAO,MAAM,OAAO,MAAM,GAAG,MAAM,YAAY,wBAAwB,OAAO,SAAS,CAAC,CAAC,CAAC;AACpH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { attribute, toMs } from "../../kernel/index.js";
|
|
2
|
+
const transition = attribute({
|
|
3
|
+
name: "transition",
|
|
4
|
+
key: "forbidden",
|
|
5
|
+
value: "required",
|
|
6
|
+
mount({ el, mods, evaluate, effect }) {
|
|
7
|
+
const style = el.style;
|
|
8
|
+
const duration = matchMedia("(prefers-reduced-motion: reduce)").matches ? 0 : toMs(mods.get("duration"), 200);
|
|
9
|
+
const scale = mods.has("scale") ? +(mods.get("scale")?.[0] ?? 95) / 100 : 1;
|
|
10
|
+
const origin = mods.get("origin")?.join(" ");
|
|
11
|
+
if (origin) style.transformOrigin = origin;
|
|
12
|
+
const hidden = { opacity: 0, transform: `scale(${scale})` };
|
|
13
|
+
const shown = { opacity: 1, transform: "scale(1)" };
|
|
14
|
+
const initial = style.display === "none" ? "" : style.display;
|
|
15
|
+
let anim;
|
|
16
|
+
let first = true;
|
|
17
|
+
let last;
|
|
18
|
+
effect(() => {
|
|
19
|
+
const open = !!evaluate();
|
|
20
|
+
if (open === last) return;
|
|
21
|
+
last = open;
|
|
22
|
+
anim?.cancel();
|
|
23
|
+
if (first) {
|
|
24
|
+
first = false;
|
|
25
|
+
style.display = open ? initial : "none";
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (open) style.display = initial;
|
|
29
|
+
anim = el.animate(open ? [hidden, shown] : [shown, hidden], { duration, easing: "ease-out", fill: "forwards" });
|
|
30
|
+
anim.onfinish = () => {
|
|
31
|
+
anim?.cancel();
|
|
32
|
+
if (!open) style.display = "none";
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
export {
|
|
38
|
+
transition
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=transition.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/transition.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute, toMs } from '../../kernel/index.js'\n\n/**\n * Shows and hides with a fade (and optional scale): `transition=\"$open\"`.\n * Modifiers: `__duration.200ms`, `__scale` (from 95%) or `__scale.90`, `__origin.top`.\n */\nexport const transition = attribute({\n name: 'transition',\n key: 'forbidden',\n value: 'required',\n mount({ el, mods, evaluate, effect }) {\n const style = (el as HTMLElement).style\n const duration = matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : toMs(mods.get('duration'), 200)\n const scale = mods.has('scale') ? +(mods.get('scale')?.[0] ?? 95) / 100 : 1\n const origin = mods.get('origin')?.join(' ')\n if (origin) style.transformOrigin = origin\n const hidden = { opacity: 0, transform: `scale(${scale})` }\n const shown = { opacity: 1, transform: 'scale(1)' }\n const initial = style.display === 'none' ? '' : style.display\n let anim: Animation | undefined\n let first = true\n let last: boolean | undefined\n effect(() => {\n const open = !!evaluate()\n if (open === last) return // a dependency changed but the outcome did not: leave the element alone\n last = open\n anim?.cancel()\n if (first) {\n first = false\n style.display = open ? initial : 'none'\n return\n }\n if (open) style.display = initial\n anim = el.animate(open ? [hidden, shown] : [shown,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AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps keyboard focus inside the element while the expression is true and restores the previously
|
|
3
|
+
* focused element when it turns false: `trap="$open"`. `__inert` also makes the rest of the page inert.
|
|
4
|
+
*/
|
|
5
|
+
export declare const trap: import("../../kernel/contracts.js").AttributePlugin;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { attribute } from "../../kernel/index.js";
|
|
2
|
+
const FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]):not([type=hidden]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"]),[contenteditable]';
|
|
3
|
+
const trap = attribute({
|
|
4
|
+
name: "trap",
|
|
5
|
+
key: "forbidden",
|
|
6
|
+
value: "required",
|
|
7
|
+
mount({ el, mods, evaluate, effect, listen, cleanup }) {
|
|
8
|
+
let previous = null;
|
|
9
|
+
let active = false;
|
|
10
|
+
const inerted = [];
|
|
11
|
+
const focusables = () => [...el.querySelectorAll(FOCUSABLE)].filter((e) => e.offsetParent !== null || e === document.activeElement);
|
|
12
|
+
const release = () => {
|
|
13
|
+
if (!active) return;
|
|
14
|
+
active = false;
|
|
15
|
+
for (const e of inerted.splice(0)) e.removeAttribute("inert");
|
|
16
|
+
previous?.focus?.();
|
|
17
|
+
};
|
|
18
|
+
listen(document, "keydown", (e) => {
|
|
19
|
+
if (!active || e.key !== "Tab") return;
|
|
20
|
+
const items = focusables();
|
|
21
|
+
if (!items.length) return e.preventDefault();
|
|
22
|
+
const i = items.indexOf(document.activeElement);
|
|
23
|
+
const next = e.shiftKey ? i <= 0 ? items.length - 1 : i - 1 : i === items.length - 1 ? 0 : i + 1;
|
|
24
|
+
if (i < 0 || next !== i + (e.shiftKey ? -1 : 1)) {
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
items[next].focus();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
effect(() => {
|
|
30
|
+
if (evaluate()) {
|
|
31
|
+
if (active) return;
|
|
32
|
+
active = true;
|
|
33
|
+
previous = document.activeElement;
|
|
34
|
+
if (mods.has("inert")) {
|
|
35
|
+
for (let n = el; n && n !== document.body; n = n.parentElement) {
|
|
36
|
+
for (const sib of n.parentElement?.children ?? []) if (sib !== n && !sib.hasAttribute("inert")) sib.setAttribute("inert", ""), inerted.push(sib);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
queueMicrotask(() => (focusables()[0] ?? el).focus?.());
|
|
40
|
+
} else release();
|
|
41
|
+
});
|
|
42
|
+
cleanup(release);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
export {
|
|
46
|
+
trap
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=trap.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/trap.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute } from '../../kernel/index.js'\n\nconst FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]):not([type=hidden]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"]),[contenteditable]'\n\n/**\n * Keeps keyboard focus inside the element while the expression is true and restores the previously\n * focused element when it turns false: `trap=\"$open\"`. `__inert` also makes the rest of the page inert.\n */\nexport const trap = attribute({\n name: 'trap',\n key: 'forbidden',\n value: 'required',\n mount({ el, mods, evaluate, effect, listen, cleanup }) {\n let previous: Element | null = null\n let active = false\n const inerted: Element[] = []\n const focusables = () => [...el.querySelectorAll<HTMLElement>(FOCUSABLE)].filter((e) => e.offsetParent !== null || e === document.activeElement)\n const release = () => {\n if (!active) return\n active = false\n for (const e of inerted.splice(0)) e.removeAttribute('inert')\n ;(previous as HTMLElement | null)?.focus?.()\n }\n listen(document, 'keydown', (e: KeyboardEvent) => {\n if (!active || e.key !== 'Tab') return\n const items = focusables()\n if (!items.length) return e.preventDefault()\n const i = items.indexOf(document.activeElement as HTMLElement)\n const next = e.shiftKey ? (i <= 0 ? items.length - 1 : i - 1) : i === items.length - 1 ? 0 : i + 1\n if (i < 0 || next !== i + (e.shiftKey ? -1 : 1)) {\n e.preventDefault()\n items[next].focus()\n }\n })\n effect(() => {\n if (evaluate()) {\n if (active) return\n active = true\n previous = document.activeElement\n if (mods.has('inert')) {\n for (let n: Element | null = el; n && n !== document.body; n = n.parentElement) {\n for (const sib of n.parentElement?.children ?? []) if (sib !== n && !sib.hasAttribute('inert')) (sib.setAttribute('inert', ''), inerted.push(sib))\n }\n }\n queueMicrotask(() => (focusables()[0] ?? (el as HTMLElement)).focus?.())\n } else release()\n })\n cleanup(release)\n },\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAE1B,MAAM,YAAY;AAMX,MAAM,OAAO,UAAU;AAAA,EAC5B,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,MAAM,EAAE,IAAI,MAAM,UAAU,QAAQ,QAAQ,QAAQ,GAAG;AACrD,QAAI,WAA2B;AAC/B,QAAI,SAAS;AACb,UAAM,UAAqB,CAAC;AAC5B,UAAM,aAAa,MAAM,CAAC,GAAG,GAAG,iBAA8B,SAAS,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,iBAAiB,QAAQ,MAAM,SAAS,aAAa;AAC/I,UAAM,UAAU,MAAM;AACpB,UAAI,CAAC,OAAQ;AACb,eAAS;AACT,iBAAW,KAAK,QAAQ,OAAO,CAAC,EAAG,GAAE,gBAAgB,OAAO;AAC3D,MAAC,UAAiC,QAAQ;AAAA,IAC7C;AACA,WAAO,UAAU,WAAW,CAAC,MAAqB;AAChD,UAAI,CAAC,UAAU,EAAE,QAAQ,MAAO;AAChC,YAAM,QAAQ,WAAW;AACzB,UAAI,CAAC,MAAM,OAAQ,QAAO,EAAE,eAAe;AAC3C,YAAM,IAAI,MAAM,QAAQ,SAAS,aAA4B;AAC7D,YAAM,OAAO,EAAE,WAAY,KAAK,IAAI,MAAM,SAAS,IAAI,IAAI,IAAK,MAAM,MAAM,SAAS,IAAI,IAAI,IAAI;AACjG,UAAI,IAAI,KAAK,SAAS,KAAK,EAAE,WAAW,KAAK,IAAI;AAC/C,UAAE,eAAe;AACjB,cAAM,IAAI,EAAE,MAAM;AAAA,MACpB;AAAA,IACF,CAAC;AACD,WAAO,MAAM;AACX,UAAI,SAAS,GAAG;AACd,YAAI,OAAQ;AACZ,iBAAS;AACT,mBAAW,SAAS;AACpB,YAAI,KAAK,IAAI,OAAO,GAAG;AACrB,mBAAS,IAAoB,IAAI,KAAK,MAAM,SAAS,MAAM,IAAI,EAAE,eAAe;AAC9E,uBAAW,OAAO,EAAE,eAAe,YAAY,CAAC,EAAG,KAAI,QAAQ,KAAK,CAAC,IAAI,aAAa,OAAO,EAAG,CAAC,IAAI,aAAa,SAAS,EAAE,GAAG,QAAQ,KAAK,GAAG;AAAA,UAClJ;AAAA,QACF;AACA,uBAAe,OAAO,WAAW,EAAE,CAAC,KAAM,IAAoB,QAAQ,CAAC;AAAA,MACzE,MAAO,SAAQ;AAAA,IACjB,CAAC;AACD,YAAQ,OAAO;AAAA,EACjB;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `animate:opacity="$open ? 1 : 0"` tweens a numeric CSS property (or attribute, for SVG) from its
|
|
3
|
+
* current value to the expression's value whenever the expression changes.
|
|
4
|
+
* Modifiers: `__duration.300ms`, `__easing.ease-in-out`. Non-numeric values apply immediately.
|
|
5
|
+
*/
|
|
6
|
+
export declare const animate: import("../../kernel/contracts.js").AttributePlugin;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { attribute, toMs } from "../../kernel/index.js";
|
|
2
|
+
const easings = {
|
|
3
|
+
linear: (t) => t,
|
|
4
|
+
"ease-in": (t) => t * t,
|
|
5
|
+
"ease-out": (t) => 1 - (1 - t) * (1 - t),
|
|
6
|
+
"ease-in-out": (t) => t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2
|
|
7
|
+
};
|
|
8
|
+
const num = (s) => {
|
|
9
|
+
const m = /^\s*(-?\d*\.?\d+)([a-z%]*)\s*$/i.exec(s);
|
|
10
|
+
return m ? { n: +m[1], unit: m[2] } : void 0;
|
|
11
|
+
};
|
|
12
|
+
const animate = attribute({
|
|
13
|
+
name: "animate",
|
|
14
|
+
key: "required",
|
|
15
|
+
value: "required",
|
|
16
|
+
mount({ el, mods, cased, evaluate, effect, cleanup }) {
|
|
17
|
+
const prop = cased("kebab");
|
|
18
|
+
const css = CSS.supports(prop, "inherit");
|
|
19
|
+
const duration = toMs(mods.get("duration"), 300);
|
|
20
|
+
const ease = easings[mods.get("easing")?.[0] ?? "ease-out"] ?? easings["ease-out"];
|
|
21
|
+
const instant = matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
22
|
+
const read = () => css ? el.style.getPropertyValue(prop) || getComputedStyle(el).getPropertyValue(prop) : el.getAttribute(prop) ?? "";
|
|
23
|
+
const write = (v) => css ? el.style.setProperty(prop, v) : el.setAttribute(prop, v);
|
|
24
|
+
let frame = 0;
|
|
25
|
+
let first = true;
|
|
26
|
+
let last;
|
|
27
|
+
effect(() => {
|
|
28
|
+
const to = String(evaluate());
|
|
29
|
+
if (to === last) return;
|
|
30
|
+
last = to;
|
|
31
|
+
cancelAnimationFrame(frame);
|
|
32
|
+
let from = num(read());
|
|
33
|
+
const target = num(to);
|
|
34
|
+
if (from && target && from.unit === "px" && target.unit === "%" && (prop === "width" || prop === "height") && el.parentElement) {
|
|
35
|
+
const size = prop === "width" ? el.parentElement.clientWidth : el.parentElement.clientHeight;
|
|
36
|
+
if (size) from = { n: from.n / size * 100, unit: "%" };
|
|
37
|
+
}
|
|
38
|
+
if (first || instant || !from || !target || from.unit !== target.unit) {
|
|
39
|
+
first = false;
|
|
40
|
+
return write(to);
|
|
41
|
+
}
|
|
42
|
+
const a = from.n;
|
|
43
|
+
const b = target.n;
|
|
44
|
+
const start = performance.now();
|
|
45
|
+
const tick = (now) => {
|
|
46
|
+
const p = Math.min(1, (now - start) / duration);
|
|
47
|
+
write(`${a + (b - a) * ease(p)}${target.unit}`);
|
|
48
|
+
if (p < 1) frame = requestAnimationFrame(tick);
|
|
49
|
+
};
|
|
50
|
+
frame = requestAnimationFrame(tick);
|
|
51
|
+
});
|
|
52
|
+
cleanup(() => cancelAnimationFrame(frame));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
export {
|
|
56
|
+
animate
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=tween.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/tween.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute, toMs } from '../../kernel/index.js'\n\nconst easings: Record<string, (t: number) => number> = {\n linear: (t) => t,\n 'ease-in': (t) => t * t,\n 'ease-out': (t) => 1 - (1 - t) * (1 - t),\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2),\n}\nconst num = (s: string): { n: number; unit: string } | undefined => {\n const m = /^\\s*(-?\\d*\\.?\\d+)([a-z%]*)\\s*$/i.exec(s)\n return m ? { n: +m[1], unit: m[2] } : undefined\n}\n\n/**\n * `animate:opacity=\"$open ? 1 : 0\"` tweens a numeric CSS property (or attribute, for SVG) from its\n * current value to the expression's value whenever the expression changes.\n * Modifiers: `__duration.300ms`, `__easing.ease-in-out`. Non-numeric values apply immediately.\n */\nexport const animate = attribute({\n name: 'animate',\n key: 'required',\n value: 'required',\n mount({ el, mods, cased, evaluate, effect, cleanup }) {\n const prop = cased('kebab')\n const css = CSS.supports(prop, 'inherit')\n const duration = toMs(mods.get('duration'), 300)\n const ease = easings[mods.get('easing')?.[0] ?? 'ease-out'] ?? easings['ease-out']\n const instant = matchMedia('(prefers-reduced-motion: reduce)').matches\n // Prefer the inline value (which this directive wrote last time); computed styles report px only.\n const read = () => (css ? el.style.getPropertyValue(prop) || getComputedStyle(el).getPropertyValue(prop) : (el.getAttribute(prop) ?? ''))\n const write = (v: string) => (css ? el.style.setProperty(prop, v) : el.setAttribute(prop, v))\n let frame = 0\n let first = true\n let last: string | undefined\n effect(() => {\n const to = String(evaluate())\n if (to === last) return\n last = to\n cancelAnimationFrame(frame)\n let from = num(read())\n const target = num(to)\n // A px start and a % target are common for width/height: convert against the parent box.\n if (from && target && from.unit === 'px' && target.unit === '%' && (prop === 'width' || prop === 'height') && el.parentElement) {\n const size = prop === 'width' ? el.parentElement.clientWidth : el.parentElement.clientHeight\n if (size) from = { n: (from.n / size) * 100, unit: '%' }\n }\n if (first || instant || !from || !target || from.unit !== target.unit) {\n first = false\n return write(to)\n }\n const a = from.n\n const b = target.n\n const start = performance.now()\n const tick = (now: number) => {\n const p = Math.min(1, (now - start) / duration)\n write(`${a + (b - a) * ease(p)}${target.unit}`)\n if (p < 1) frame = requestAnimationFrame(tick)\n }\n frame = requestAnimationFrame(tick)\n })\n cleanup(() => cancelAnimationFrame(frame))\n },\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW,YAAY;AAEhC,MAAM,UAAiD;AAAA,EACrD,QAAQ,CAAC,MAAM;AAAA,EACf,WAAW,CAAC,MAAM,IAAI;AAAA,EACtB,YAAY,CAAC,MAAM,KAAK,IAAI,MAAM,IAAI;AAAA,EACtC,eAAe,CAAC,MAAO,IAAI,MAAM,IAAI,IAAI,IAAI,KAAK,KAAK,IAAI,MAAM,IAAI;AACvE;AACA,MAAM,MAAM,CAAC,MAAuD;AAClE,QAAM,IAAI,kCAAkC,KAAK,CAAC;AAClD,SAAO,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,IAAI;AACxC;AAOO,MAAM,UAAU,UAAU;AAAA,EAC/B,MAAM;AAAA,EACN,KAAK;AAA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AI;AAC9B,YAAM,OAAO,CAAC,QAAgB;AAC5B,cAAM,IAAI,KAAK,IAAI,IAAI,MAAM,SAAS,QAAQ;AAC9C,cAAM,GAAG,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,GAAG,OAAO,IAAI,EAAE;AAC9C,YAAI,IAAI,EAAG,SAAQ,sBAAsB,IAAI;AAAA,MAC/C;AACA,cAAQ,sBAAsB,IAAI;AAAA,IACpC,CAAC;AACD,YAAQ,MAAM,qBAAqB,KAAK,CAAC;AAAA,EAC3C;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two-way binding: `bind:name` or `bind="name"`. Creates the signal from the element when missing.
|
|
3
|
+
* Checkbox groups bind to arrays, radios to the checked value, `select multiple` to arrays.
|
|
4
|
+
* `__prop.value` binds a custom element property; `__event.change` picks the events to listen for.
|
|
5
|
+
*/
|
|
6
|
+
export declare const bind: import("../../kernel/contracts.js").AttributePlugin;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { attribute } from "../../kernel/index.js";
|
|
2
|
+
const adapter = (_read, _write, ..._events) => ({ a: _read, b: _write, c: _events });
|
|
3
|
+
const readFiles = (input) => Promise.all(
|
|
4
|
+
[...input.files ?? []].map(
|
|
5
|
+
(f) => new Promise((resolve) => {
|
|
6
|
+
const r = new FileReader();
|
|
7
|
+
r.onloadend = () => resolve({ name: f.name, type: f.type, size: f.size, contents: String(r.result).split(",")[1] ?? "" });
|
|
8
|
+
r.readAsDataURL(f);
|
|
9
|
+
})
|
|
10
|
+
)
|
|
11
|
+
);
|
|
12
|
+
const bind = attribute({
|
|
13
|
+
name: "bind",
|
|
14
|
+
mount({ el, key, value, cased, mods, store, listen, effect }) {
|
|
15
|
+
const path = key ? cased() : value.trim();
|
|
16
|
+
const current = () => store.get(path);
|
|
17
|
+
const asNumber = (s) => typeof current() === "number" ? +s : s;
|
|
18
|
+
let a;
|
|
19
|
+
const prop = mods.get("prop")?.[0];
|
|
20
|
+
if (prop) {
|
|
21
|
+
a = adapter(() => el[prop], (v) => el[prop] = v, "input", "change");
|
|
22
|
+
} else if (el instanceof HTMLInputElement) {
|
|
23
|
+
const t = el.type;
|
|
24
|
+
if (t === "checkbox") {
|
|
25
|
+
const own = el.hasAttribute("value") && el.value !== "on";
|
|
26
|
+
a = {
|
|
27
|
+
a: () => {
|
|
28
|
+
const cur = current();
|
|
29
|
+
if (Array.isArray(cur)) {
|
|
30
|
+
const set = new Set(cur);
|
|
31
|
+
el.checked ? set.add(el.value) : set.delete(el.value);
|
|
32
|
+
return [...set];
|
|
33
|
+
}
|
|
34
|
+
return own ? el.checked ? el.value : "" : el.checked;
|
|
35
|
+
},
|
|
36
|
+
b: (v) => {
|
|
37
|
+
el.checked = Array.isArray(v) ? v.includes(el.value) : own ? v === el.value : !!v;
|
|
38
|
+
},
|
|
39
|
+
c: ["input"]
|
|
40
|
+
};
|
|
41
|
+
} else if (t === "radio") {
|
|
42
|
+
if (!el.name) el.name = path;
|
|
43
|
+
a = adapter(() => el.checked ? asNumber(el.value) : current(), (v) => el.checked = String(v) === el.value, "input");
|
|
44
|
+
} else if (t === "file") {
|
|
45
|
+
listen(el, "change", () => readFiles(el).then((files) => store.set(path, files)));
|
|
46
|
+
return;
|
|
47
|
+
} else if (t === "number" || t === "range") {
|
|
48
|
+
a = adapter(() => el.value === "" ? "" : +el.value, (v) => el.value = String(v ?? ""), "input");
|
|
49
|
+
} else {
|
|
50
|
+
a = adapter(() => el.value, (v) => el.value = String(v ?? ""), "input");
|
|
51
|
+
}
|
|
52
|
+
} else if (el instanceof HTMLSelectElement) {
|
|
53
|
+
a = {
|
|
54
|
+
a: () => el.multiple ? [...el.selectedOptions].map((o) => asNumber(o.value)) : asNumber(el.value),
|
|
55
|
+
b: (v) => {
|
|
56
|
+
if (el.multiple) for (const o of el.options) o.selected = Array.isArray(v) && v.map(String).includes(o.value);
|
|
57
|
+
else el.value = String(v ?? "");
|
|
58
|
+
},
|
|
59
|
+
c: ["change"]
|
|
60
|
+
};
|
|
61
|
+
} else if (el instanceof HTMLTextAreaElement || "value" in el) {
|
|
62
|
+
a = adapter(() => el.value, (v) => el.value = String(v ?? ""), "input", "change");
|
|
63
|
+
} else {
|
|
64
|
+
a = adapter(() => el.getAttribute("value"), (v) => el.setAttribute("value", String(v ?? "")), "change");
|
|
65
|
+
}
|
|
66
|
+
if (!store.has(path)) {
|
|
67
|
+
const initial = a.a();
|
|
68
|
+
if (initial !== void 0 && initial !== "") store.set(path, initial);
|
|
69
|
+
}
|
|
70
|
+
const sync = () => store.set(path, a.a());
|
|
71
|
+
for (const type of mods.get("event") ?? a.c) listen(el, type, sync);
|
|
72
|
+
listen(el, "sigmx-prop-change", sync);
|
|
73
|
+
effect(() => {
|
|
74
|
+
const v = current();
|
|
75
|
+
if (v !== void 0) a.b(v);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
export {
|
|
80
|
+
bind
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=two-way-bind.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/directives/two-way-bind.ts"],
|
|
4
|
+
"sourcesContent": ["import { attribute } from '../../kernel/index.js'\n\ntype Adapter = { _read(): unknown; _write(v: unknown): void; _events: string[] }\nconst adapter = (_read: () => unknown, _write: (v: any) => void, ..._events: string[]): Adapter => ({ _read, _write, _events })\n\nconst readFiles = (input: HTMLInputElement) =>\n Promise.all(\n [...(input.files ?? [])].map(\n (f) =>\n new Promise<{ name: string; type: string; size: number; contents: string }>((resolve) => {\n const r = new FileReader()\n r.onloadend = () =>\n resolve({ name: f.name, type: f.type, size: f.size, contents: String(r.result).split(',')[1] ?? '' })\n r.readAsDataURL(f)\n }),\n ),\n )\n\n/**\n * Two-way binding: `bind:name` or `bind=\"name\"`. Creates the signal from the element when missing.\n * Checkbox groups bind to arrays, radios to the checked value, `select multiple` to arrays.\n * `__prop.value` binds a custom element property; `__event.change` picks the events to listen for.\n */\nexport const bind = attribute({\n name: 'bind',\n mount({ el, key, value, cased, mods, store, listen, effect }) {\n const path = key ? cased() : value.trim()\n const current = () => store.get(path)\n const asNumber = (s: string) => (typeof current() === 'number' ? +s : s)\n let a: Adapter\n const prop = mods.get('prop')?.[0]\n\n if (prop) {\n a = adapter(() => (el as any)[prop], (v) => ((el as any)[prop] = v), 'input', 'change')\n } else if (el instanceof HTMLInputElement) {\n const t = el.type\n if (t === 'checkbox') {\n const own = el.hasAttribute('value') && el.value !== 'on'\n a = {\n _read: () => {\n const cur = current()\n if (Array.isArray(cur)) {\n const set = new Set(cur)\n el.checked ? set.add(el.value) : set.delete(el.value)\n return [...set]\n }\n return own ? (el.checked ? el.value : '') : el.checked\n },\n _write: (v) => {\n el.checked = Array.isArray(v) ? v.includes(el.value) : own ? v === el.value : !!v\n },\n _events: ['input'],\n }\n } else if (t === 'radio') {\n if (!el.name) el.name = path\n a = adapter(() => (el.checked ? asNumber(el.value) : current()), (v) => (el.checked = String(v) === el.value), 'input')\n } else if (t === 'file') {\n listen(el, 'change', () => readFiles(el).then((files) => store.set(path, files)))\n return\n } else if (t === 'number' || t === 'range') {\n a = adapter(() => (el.value === '' ? '' : +el.value), (v) => (el.value = String(v ?? '')), 'input')\n } else {\n a = adapter(() => el.value, (v) => (el.value = String(v ?? '')), 'input')\n }\n } else if (el instanceof HTMLSelectElement) {\n a = {\n _read: () => (el.multiple ? [...el.selectedOptions].map((o) => asNumber(o.value)) : asNumber(el.value)),\n _write: (v) => {\n if (el.multiple) for (const o of el.options) o.selected = Array.isArray(v) && v.map(String).includes(o.value)\n else el.value = String(v ?? '')\n },\n _events: ['change'],\n }\n } else if (el instanceof HTMLTextAreaElement || 'value' in el) {\n a = adapter(() => (el as any).value, (v) => ((el as any).value = String(v ?? '')), 'input', 'change')\n } else {\n a = adapter(() => el.getAttribute('value'), (v) => el.setAttribute('value', String(v ?? '')), 'change')\n }\n\n if (!store.has(path)) {\n const initial = a._read()\n if (initial !== undefined && initial !== '') store.set(path, initial)\n }\n const sync = () => store.set(path, a._read())\n for (const type of mods.get('event') ?? a._events) listen(el, type, sync)\n listen(el, 'sigmx-prop-change', sync)\n effect(() => {\n const v = current()\n if (v !== undefined) a._write(v)\n })\n },\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAG1B,MAAM,UAAU,CAAC,OAAsB,WAA6B,aAAgC,EAAEA,GAAA,OAAOC,GAAA,QAAQC,GAAA,QAAQ;AAE7H,MAAM,YAAY,CAAC,UACjB,QAAQ;AAAA,EACN,CAAC,GAAI,MAAM,SAAS,CAAC,CAAE,EAAE;AAAA,IACvB,CAAC,MACC,IAAI,QAAwE,CAAC,YAAY;AACvF,YAAM,IAAI,IAAI,WAAW;AACzB,QAAE,YAAY,MACZ,QAAQ,EAAE,MAAM,EAAE,MAAM,MAAM,EAAE,MAAM,MAAM,EAAE,MAAM,UAAU,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC;AACtG,QAAE,cAAc,CAAC;AAAA,IACnB,CAAC;AAAA,EACL;AACF;AAOK,MAAM,OAAO,UAAU;AAAA,EAC5B,MAAM;AAAA,EACN,MAAM,EAAE,IAAI,KAAK,OAAO,OAAO,MAAM,OAAO,QAAQ,OAAO,GAAG;AAC5D,UAAM,OAAO,MAAM,MAAM,IAAI,MAAM,KAAK;AACxC,UAAM,UAAU,MAAM,MAAM,IAAI,IAAI;AACpC,UAAM,WAAW,CAAC,MAAe,OAAO,QAAQ,MAAM,WAAW,CAAC,IAAI;AACtE,QAAI;AACJ,UAAM,OAAO,KAAK,IAAI,MAAM,IAAI,CAAC;AAEjC,QAAI,MAAM;AACR,UAAI,QAAQ,MAAO,GAAW,IAAI,GAAG,CAAC,MAAQ,GAAW,IAAI,IAAI,GAAI,SAAS,QAAQ;AAAA,IAC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["_read", "_write", "_events"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps signals and the URL query string in step.
|
|
3
|
+
*
|
|
4
|
+
* Keyed form declares one signal with a default: `query-string:page="1"` creates `page`, reads
|
|
5
|
+
* `?page=` on load when present (otherwise uses the default), writes it whenever it changes, and
|
|
6
|
+
* drops the parameter again when the value is back at the default. The parameter name is the key
|
|
7
|
+
* as written; the signal name is recased as usual.
|
|
8
|
+
*
|
|
9
|
+
* Bare form syncs existing signals: `query-string="{ include: /^(q|sort)$/ }"` mirrors matching
|
|
10
|
+
* paths both ways. `__history` pushes an entry per change and restores on back/forward;
|
|
11
|
+
* `__filter` drops empty values from the URL.
|
|
12
|
+
*/
|
|
13
|
+
export declare const queryString: import("../../kernel/contracts.js").AttributePlugin;
|