@bquery/bquery 1.5.0 → 1.7.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 +193 -23
- package/dist/a11y/announce.d.ts +43 -0
- package/dist/a11y/announce.d.ts.map +1 -0
- package/dist/a11y/audit.d.ts +42 -0
- package/dist/a11y/audit.d.ts.map +1 -0
- package/dist/a11y/index.d.ts +53 -0
- package/dist/a11y/index.d.ts.map +1 -0
- package/dist/a11y/media-preferences.d.ts +77 -0
- package/dist/a11y/media-preferences.d.ts.map +1 -0
- package/dist/a11y/roving-tab-index.d.ts +38 -0
- package/dist/a11y/roving-tab-index.d.ts.map +1 -0
- package/dist/a11y/skip-link.d.ts +37 -0
- package/dist/a11y/skip-link.d.ts.map +1 -0
- package/dist/a11y/trap-focus.d.ts +49 -0
- package/dist/a11y/trap-focus.d.ts.map +1 -0
- package/dist/a11y/types.d.ts +152 -0
- package/dist/a11y/types.d.ts.map +1 -0
- package/dist/a11y-C5QOVvRn.js +421 -0
- package/dist/a11y-C5QOVvRn.js.map +1 -0
- package/dist/a11y.es.mjs +14 -0
- package/dist/component/component.d.ts +13 -5
- package/dist/component/component.d.ts.map +1 -1
- package/dist/component/html.d.ts +40 -3
- package/dist/component/html.d.ts.map +1 -1
- package/dist/component/index.d.ts +3 -2
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/library.d.ts.map +1 -1
- package/dist/component/scope.d.ts +138 -0
- package/dist/component/scope.d.ts.map +1 -0
- package/dist/component/types.d.ts +184 -17
- package/dist/component/types.d.ts.map +1 -1
- package/dist/component-CuuTijA6.js +684 -0
- package/dist/component-CuuTijA6.js.map +1 -0
- package/dist/component.es.mjs +10 -6
- package/dist/{config-DRmZZno3.js → config-BW35FKuA.js} +4 -4
- package/dist/config-BW35FKuA.js.map +1 -0
- package/dist/constraints-3lV9yyBw.js +100 -0
- package/dist/constraints-3lV9yyBw.js.map +1 -0
- package/dist/core/collection.d.ts +48 -0
- package/dist/core/collection.d.ts.map +1 -1
- package/dist/core/element.d.ts +92 -0
- package/dist/core/element.d.ts.map +1 -1
- package/dist/core/env.d.ts +18 -0
- package/dist/core/env.d.ts.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/shared.d.ts +8 -0
- package/dist/core/shared.d.ts.map +1 -1
- package/dist/core/utils/index.d.ts +52 -41
- package/dist/core/utils/index.d.ts.map +1 -1
- package/dist/core-Cjl7GUu8.js +717 -0
- package/dist/core-Cjl7GUu8.js.map +1 -0
- package/dist/{core-DPdbItcq.js → core-DnlyjbF2.js} +1 -1
- package/dist/{core-DPdbItcq.js.map → core-DnlyjbF2.js.map} +1 -1
- package/dist/core.es.mjs +45 -44
- package/dist/custom-directives-7wAShnnd.js +9 -0
- package/dist/custom-directives-7wAShnnd.js.map +1 -0
- package/dist/devtools/devtools.d.ts +212 -0
- package/dist/devtools/devtools.d.ts.map +1 -0
- package/dist/devtools/index.d.ts +20 -0
- package/dist/devtools/index.d.ts.map +1 -0
- package/dist/devtools/types.d.ts +69 -0
- package/dist/devtools/types.d.ts.map +1 -0
- package/dist/devtools-D2fQLhDN.js +122 -0
- package/dist/devtools-D2fQLhDN.js.map +1 -0
- package/dist/devtools.es.mjs +19 -0
- package/dist/dnd/draggable.d.ts +51 -0
- package/dist/dnd/draggable.d.ts.map +1 -0
- package/dist/dnd/droppable.d.ts +38 -0
- package/dist/dnd/droppable.d.ts.map +1 -0
- package/dist/dnd/index.d.ts +47 -0
- package/dist/dnd/index.d.ts.map +1 -0
- package/dist/dnd/sortable.d.ts +43 -0
- package/dist/dnd/sortable.d.ts.map +1 -0
- package/dist/dnd/types.d.ts +250 -0
- package/dist/dnd/types.d.ts.map +1 -0
- package/dist/dnd-B8EgyzaI.js +244 -0
- package/dist/dnd-B8EgyzaI.js.map +1 -0
- package/dist/dnd.es.mjs +6 -0
- package/dist/env-NeVmr4Gf.js +19 -0
- package/dist/env-NeVmr4Gf.js.map +1 -0
- package/dist/forms/create-form.d.ts +49 -0
- package/dist/forms/create-form.d.ts.map +1 -0
- package/dist/forms/index.d.ts +39 -0
- package/dist/forms/index.d.ts.map +1 -0
- package/dist/forms/types.d.ts +139 -0
- package/dist/forms/types.d.ts.map +1 -0
- package/dist/forms/validators.d.ts +179 -0
- package/dist/forms/validators.d.ts.map +1 -0
- package/dist/forms-C3yovgH9.js +141 -0
- package/dist/forms-C3yovgH9.js.map +1 -0
- package/dist/forms.es.mjs +14 -0
- package/dist/full.d.ts +37 -9
- package/dist/full.d.ts.map +1 -1
- package/dist/full.es.mjs +186 -91
- package/dist/full.iife.js +47 -31
- package/dist/full.iife.js.map +1 -1
- package/dist/full.umd.js +47 -31
- package/dist/full.umd.js.map +1 -1
- package/dist/i18n/formatting.d.ts +40 -0
- package/dist/i18n/formatting.d.ts.map +1 -0
- package/dist/i18n/i18n.d.ts +48 -0
- package/dist/i18n/i18n.d.ts.map +1 -0
- package/dist/i18n/index.d.ts +57 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/translate.d.ts +83 -0
- package/dist/i18n/translate.d.ts.map +1 -0
- package/dist/i18n/types.d.ts +156 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n-BnnhTFOS.js +89 -0
- package/dist/i18n-BnnhTFOS.js.map +1 -0
- package/dist/i18n.es.mjs +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.mjs +233 -138
- package/dist/media/battery.d.ts +35 -0
- package/dist/media/battery.d.ts.map +1 -0
- package/dist/media/breakpoints.d.ts +51 -0
- package/dist/media/breakpoints.d.ts.map +1 -0
- package/dist/media/clipboard.d.ts +30 -0
- package/dist/media/clipboard.d.ts.map +1 -0
- package/dist/media/device-sensors.d.ts +54 -0
- package/dist/media/device-sensors.d.ts.map +1 -0
- package/dist/media/geolocation.d.ts +38 -0
- package/dist/media/geolocation.d.ts.map +1 -0
- package/dist/media/index.d.ts +42 -0
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media/media-query.d.ts +36 -0
- package/dist/media/media-query.d.ts.map +1 -0
- package/dist/media/network.d.ts +35 -0
- package/dist/media/network.d.ts.map +1 -0
- package/dist/media/types.d.ts +173 -0
- package/dist/media/types.d.ts.map +1 -0
- package/dist/media/viewport.d.ts +32 -0
- package/dist/media/viewport.d.ts.map +1 -0
- package/dist/media-Di2Ta22s.js +340 -0
- package/dist/media-Di2Ta22s.js.map +1 -0
- package/dist/media.es.mjs +12 -0
- package/dist/motion/index.d.ts +7 -3
- package/dist/motion/index.d.ts.map +1 -1
- package/dist/motion/morph.d.ts +27 -0
- package/dist/motion/morph.d.ts.map +1 -0
- package/dist/motion/parallax.d.ts +30 -0
- package/dist/motion/parallax.d.ts.map +1 -0
- package/dist/motion/reduced-motion.d.ts +36 -3
- package/dist/motion/reduced-motion.d.ts.map +1 -1
- package/dist/motion/types.d.ts +58 -0
- package/dist/motion/types.d.ts.map +1 -1
- package/dist/motion/typewriter.d.ts +31 -0
- package/dist/motion/typewriter.d.ts.map +1 -0
- package/dist/motion-qPj_TYGv.js +530 -0
- package/dist/motion-qPj_TYGv.js.map +1 -0
- package/dist/motion.es.mjs +27 -23
- package/dist/mount-SM07RUa6.js +403 -0
- package/dist/mount-SM07RUa6.js.map +1 -0
- package/dist/{object-qGpWr6-J.js → object-BCk-1c8T.js} +5 -4
- package/dist/{object-qGpWr6-J.js.map → object-BCk-1c8T.js.map} +1 -1
- package/dist/{platform-B7JhGBc7.js → platform-CPbCprb6.js} +3 -3
- package/dist/platform-CPbCprb6.js.map +1 -0
- package/dist/platform.es.mjs +2 -2
- package/dist/plugin/index.d.ts +22 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/registry.d.ts +108 -0
- package/dist/plugin/registry.d.ts.map +1 -0
- package/dist/plugin/types.d.ts +110 -0
- package/dist/plugin/types.d.ts.map +1 -0
- package/dist/plugin-cPoOHFLY.js +64 -0
- package/dist/plugin-cPoOHFLY.js.map +1 -0
- package/dist/plugin.es.mjs +9 -0
- package/dist/reactive/computed.d.ts +7 -0
- package/dist/reactive/computed.d.ts.map +1 -1
- package/dist/reactive-Cfv0RK6x.js +233 -0
- package/dist/reactive-Cfv0RK6x.js.map +1 -0
- package/dist/reactive.es.mjs +18 -17
- package/dist/registry-CWf368tT.js +26 -0
- package/dist/registry-CWf368tT.js.map +1 -0
- package/dist/router/bq-link.d.ts +112 -0
- package/dist/router/bq-link.d.ts.map +1 -0
- package/dist/router/constraints.d.ts +9 -0
- package/dist/router/constraints.d.ts.map +1 -0
- package/dist/router/index.d.ts +14 -6
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/match.d.ts +0 -1
- package/dist/router/match.d.ts.map +1 -1
- package/dist/router/path-pattern.d.ts +14 -0
- package/dist/router/path-pattern.d.ts.map +1 -0
- package/dist/router/query.d.ts.map +1 -1
- package/dist/router/router.d.ts +3 -1
- package/dist/router/router.d.ts.map +1 -1
- package/dist/router/types.d.ts +48 -4
- package/dist/router/types.d.ts.map +1 -1
- package/dist/router/use-route.d.ts +50 -0
- package/dist/router/use-route.d.ts.map +1 -0
- package/dist/router/utils.d.ts +3 -0
- package/dist/router/utils.d.ts.map +1 -1
- package/dist/router-BrthaP_z.js +473 -0
- package/dist/router-BrthaP_z.js.map +1 -0
- package/dist/router.es.mjs +13 -10
- package/dist/{sanitize-jyJ2ryE2.js → sanitize-B1V4JswB.js} +95 -83
- package/dist/sanitize-B1V4JswB.js.map +1 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/sanitize.d.ts +4 -1
- package/dist/security/sanitize.d.ts.map +1 -1
- package/dist/security/trusted-html.d.ts +53 -0
- package/dist/security/trusted-html.d.ts.map +1 -0
- package/dist/security.es.mjs +10 -9
- package/dist/ssr/hydrate.d.ts +65 -0
- package/dist/ssr/hydrate.d.ts.map +1 -0
- package/dist/ssr/index.d.ts +59 -0
- package/dist/ssr/index.d.ts.map +1 -0
- package/dist/ssr/render.d.ts +62 -0
- package/dist/ssr/render.d.ts.map +1 -0
- package/dist/ssr/serialize.d.ts +118 -0
- package/dist/ssr/serialize.d.ts.map +1 -0
- package/dist/ssr/types.d.ts +70 -0
- package/dist/ssr/types.d.ts.map +1 -0
- package/dist/ssr-B2qd_WBB.js +248 -0
- package/dist/ssr-B2qd_WBB.js.map +1 -0
- package/dist/ssr.es.mjs +9 -0
- package/dist/store/create-store.d.ts.map +1 -1
- package/dist/store/define-store.d.ts +1 -1
- package/dist/store/define-store.d.ts.map +1 -1
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/mapping.d.ts +1 -1
- package/dist/store/mapping.d.ts.map +1 -1
- package/dist/store/persisted.d.ts +38 -4
- package/dist/store/persisted.d.ts.map +1 -1
- package/dist/store/types.d.ts +140 -3
- package/dist/store/types.d.ts.map +1 -1
- package/dist/store/utils.d.ts +2 -2
- package/dist/store/utils.d.ts.map +1 -1
- package/dist/store/watch.d.ts +1 -1
- package/dist/store/watch.d.ts.map +1 -1
- package/dist/store-DWpyH6p5.js +338 -0
- package/dist/store-DWpyH6p5.js.map +1 -0
- package/dist/store.es.mjs +11 -10
- package/dist/storybook/index.d.ts +37 -0
- package/dist/storybook/index.d.ts.map +1 -0
- package/dist/storybook.es.mjs +151 -0
- package/dist/storybook.es.mjs.map +1 -0
- package/dist/testing/index.d.ts +23 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/testing.d.ts +156 -0
- package/dist/testing/testing.d.ts.map +1 -0
- package/dist/testing/types.d.ts +134 -0
- package/dist/testing/types.d.ts.map +1 -0
- package/dist/testing-CsqjNUyy.js +224 -0
- package/dist/testing-CsqjNUyy.js.map +1 -0
- package/dist/testing.es.mjs +9 -0
- package/dist/type-guards-Do9DWgNp.js +44 -0
- package/dist/type-guards-Do9DWgNp.js.map +1 -0
- package/dist/untrack-DJVQQ2WM.js +33 -0
- package/dist/untrack-DJVQQ2WM.js.map +1 -0
- package/dist/view/custom-directives.d.ts +20 -0
- package/dist/view/custom-directives.d.ts.map +1 -0
- package/dist/view/evaluate.d.ts.map +1 -1
- package/dist/view/process.d.ts.map +1 -1
- package/dist/view.es.mjs +11 -10
- package/package.json +52 -11
- package/src/a11y/announce.ts +131 -0
- package/src/a11y/audit.ts +314 -0
- package/src/a11y/index.ts +68 -0
- package/src/a11y/media-preferences.ts +255 -0
- package/src/a11y/roving-tab-index.ts +164 -0
- package/src/a11y/skip-link.ts +255 -0
- package/src/a11y/trap-focus.ts +184 -0
- package/src/a11y/types.ts +183 -0
- package/src/component/component.ts +345 -65
- package/src/component/html.ts +153 -53
- package/src/component/index.ts +12 -2
- package/src/component/library.ts +66 -28
- package/src/component/scope.ts +212 -0
- package/src/component/types.ts +238 -19
- package/src/core/collection.ts +707 -628
- package/src/core/element.ts +981 -774
- package/src/core/env.ts +60 -0
- package/src/core/index.ts +49 -48
- package/src/core/shared.ts +62 -13
- package/src/core/utils/index.ts +148 -83
- package/src/devtools/devtools.ts +410 -0
- package/src/devtools/index.ts +48 -0
- package/src/devtools/types.ts +104 -0
- package/src/dnd/draggable.ts +296 -0
- package/src/dnd/droppable.ts +228 -0
- package/src/dnd/index.ts +62 -0
- package/src/dnd/sortable.ts +307 -0
- package/src/dnd/types.ts +293 -0
- package/src/forms/create-form.ts +278 -0
- package/src/forms/index.ts +65 -0
- package/src/forms/types.ts +154 -0
- package/src/forms/validators.ts +265 -0
- package/src/full.ts +260 -3
- package/src/i18n/formatting.ts +67 -0
- package/src/i18n/i18n.ts +200 -0
- package/src/i18n/index.ts +67 -0
- package/src/i18n/translate.ts +182 -0
- package/src/i18n/types.ts +171 -0
- package/src/index.ts +108 -36
- package/src/media/battery.ts +116 -0
- package/src/media/breakpoints.ts +131 -0
- package/src/media/clipboard.ts +80 -0
- package/src/media/device-sensors.ts +158 -0
- package/src/media/geolocation.ts +119 -0
- package/src/media/index.ts +76 -0
- package/src/media/media-query.ts +92 -0
- package/src/media/network.ts +115 -0
- package/src/media/types.ts +177 -0
- package/src/media/viewport.ts +84 -0
- package/src/motion/index.ts +57 -48
- package/src/motion/morph.ts +151 -0
- package/src/motion/parallax.ts +120 -0
- package/src/motion/reduced-motion.ts +66 -17
- package/src/motion/transition.ts +97 -97
- package/src/motion/types.ts +63 -0
- package/src/motion/typewriter.ts +164 -0
- package/src/platform/announcer.ts +208 -208
- package/src/platform/config.ts +163 -163
- package/src/platform/cookies.ts +165 -165
- package/src/platform/index.ts +39 -39
- package/src/platform/meta.ts +168 -168
- package/src/plugin/index.ts +37 -0
- package/src/plugin/registry.ts +269 -0
- package/src/plugin/types.ts +137 -0
- package/src/reactive/async-data.ts +486 -486
- package/src/reactive/computed.ts +130 -92
- package/src/reactive/index.ts +37 -37
- package/src/reactive/signal.ts +29 -29
- package/src/router/bq-link.ts +279 -0
- package/src/router/constraints.ts +201 -0
- package/src/router/index.ts +49 -41
- package/src/router/match.ts +312 -106
- package/src/router/path-pattern.ts +52 -0
- package/src/router/query.ts +38 -35
- package/src/router/router.ts +402 -211
- package/src/router/types.ts +139 -93
- package/src/router/use-route.ts +68 -0
- package/src/router/utils.ts +157 -116
- package/src/security/constants.ts +211 -211
- package/src/security/index.ts +12 -10
- package/src/security/sanitize.ts +6 -2
- package/src/security/trusted-html.ts +71 -0
- package/src/ssr/hydrate.ts +82 -0
- package/src/ssr/index.ts +70 -0
- package/src/ssr/render.ts +508 -0
- package/src/ssr/serialize.ts +296 -0
- package/src/ssr/types.ts +81 -0
- package/src/store/create-store.ts +467 -329
- package/src/store/define-store.ts +2 -1
- package/src/store/index.ts +27 -22
- package/src/store/mapping.ts +2 -1
- package/src/store/persisted.ts +249 -61
- package/src/store/types.ts +247 -94
- package/src/store/utils.ts +135 -141
- package/src/store/watch.ts +2 -1
- package/src/storybook/index.ts +480 -0
- package/src/testing/index.ts +42 -0
- package/src/testing/testing.ts +593 -0
- package/src/testing/types.ts +170 -0
- package/src/view/custom-directives.ts +30 -0
- package/src/view/evaluate.ts +292 -290
- package/src/view/process.ts +108 -92
- package/dist/component-CY5MVoYN.js +0 -531
- package/dist/component-CY5MVoYN.js.map +0 -1
- package/dist/config-DRmZZno3.js.map +0 -1
- package/dist/core-CK2Mfpf4.js +0 -648
- package/dist/core-CK2Mfpf4.js.map +0 -1
- package/dist/motion-C5DRdPnO.js +0 -415
- package/dist/motion-C5DRdPnO.js.map +0 -1
- package/dist/platform-B7JhGBc7.js.map +0 -1
- package/dist/reactive-BDya-ia8.js +0 -253
- package/dist/reactive-BDya-ia8.js.map +0 -1
- package/dist/router-CijiICxt.js +0 -188
- package/dist/router-CijiICxt.js.map +0 -1
- package/dist/sanitize-jyJ2ryE2.js.map +0 -1
- package/dist/store-CPK9E62U.js +0 -262
- package/dist/store-CPK9E62U.js.map +0 -1
- package/dist/view-Cdi0g-qo.js +0 -396
- package/dist/view-Cdi0g-qo.js.map +0 -1
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { n as I, p as R } from "./sanitize-B1V4JswB.js";
|
|
2
|
+
import { i as S } from "./object-BCk-1c8T.js";
|
|
3
|
+
import { n as C, r as L } from "./reactive-Cfv0RK6x.js";
|
|
4
|
+
import { i as F, n as _ } from "./registry-CWf368tT.js";
|
|
5
|
+
import { n as j } from "./mount-SM07RUa6.js";
|
|
6
|
+
var X = (t, r, e = {}) => {
|
|
7
|
+
const { hydrate: o = !0, ...i } = e;
|
|
8
|
+
if (!o) throw new Error("bQuery ssr: hydrateMount() requires { hydrate: true } when options are provided.");
|
|
9
|
+
return j(t, r, i);
|
|
10
|
+
}, b = (t) => typeof t == "object" && t !== null && !Array.isArray(t), A = (t) => {
|
|
11
|
+
const r = {};
|
|
12
|
+
for (const [e, o] of Object.entries(t))
|
|
13
|
+
S(e) || (r[e] = o);
|
|
14
|
+
return r;
|
|
15
|
+
}, N = (t) => t.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\//g, "\\u002f").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029"), D = (t) => t.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">"), M = (t = {}) => {
|
|
16
|
+
const { scriptId: r = "__BQUERY_STORE_STATE__", globalKey: e = "__BQUERY_INITIAL_STATE__", storeIds: o, serialize: i = JSON.stringify } = t;
|
|
17
|
+
if (S(e)) throw new Error(`serializeStoreState: invalid globalKey "${e}" - prototype-pollution keys are not allowed.`);
|
|
18
|
+
if (S(r)) throw new Error(`serializeStoreState: invalid scriptId "${r}" - prototype-pollution keys are not allowed.`);
|
|
19
|
+
const s = o ?? F(), c = /* @__PURE__ */ Object.create(null);
|
|
20
|
+
for (const f of s) {
|
|
21
|
+
if (S(f)) continue;
|
|
22
|
+
const g = _(f);
|
|
23
|
+
g && (c[f] = A(g.$state));
|
|
24
|
+
}
|
|
25
|
+
const u = i(c);
|
|
26
|
+
if (typeof u != "string") throw new Error("serializeStoreState: custom serialize function must return a string.");
|
|
27
|
+
if (i !== JSON.stringify) {
|
|
28
|
+
let f;
|
|
29
|
+
try {
|
|
30
|
+
f = JSON.parse(u);
|
|
31
|
+
} catch {
|
|
32
|
+
throw new Error("serializeStoreState: custom serialize function returned invalid JSON.");
|
|
33
|
+
}
|
|
34
|
+
if (!b(f)) throw new Error("serializeStoreState: custom serialize function must return a JSON object string.");
|
|
35
|
+
}
|
|
36
|
+
const p = N(u), y = N(JSON.stringify(e));
|
|
37
|
+
return {
|
|
38
|
+
stateJson: u,
|
|
39
|
+
scriptTag: `<script id="${D(r)}">window[${y}]=${p}<\/script>`
|
|
40
|
+
};
|
|
41
|
+
}, Z = (t = "__BQUERY_INITIAL_STATE__", r = "__BQUERY_STORE_STATE__") => {
|
|
42
|
+
if (S(t)) throw new Error(`deserializeStoreState: invalid globalKey "${t}" - prototype-pollution keys are not allowed.`);
|
|
43
|
+
if (S(r)) throw new Error(`deserializeStoreState: invalid scriptId "${r}" - prototype-pollution keys are not allowed.`);
|
|
44
|
+
if (typeof window > "u") return {};
|
|
45
|
+
const e = window[t];
|
|
46
|
+
if (!e) return {};
|
|
47
|
+
try {
|
|
48
|
+
delete window[t];
|
|
49
|
+
} catch {
|
|
50
|
+
window[t] = void 0;
|
|
51
|
+
}
|
|
52
|
+
if (typeof document < "u" && typeof document.getElementById == "function") {
|
|
53
|
+
const i = document.getElementById(r);
|
|
54
|
+
i && i.remove();
|
|
55
|
+
}
|
|
56
|
+
if (!b(e)) return {};
|
|
57
|
+
for (const i of Object.values(e)) if (!b(i)) return {};
|
|
58
|
+
const o = /* @__PURE__ */ Object.create(null);
|
|
59
|
+
for (const [i, s] of Object.entries(e))
|
|
60
|
+
S(i) || !b(s) || (o[i] = A(s));
|
|
61
|
+
return o;
|
|
62
|
+
}, P = (t, r) => {
|
|
63
|
+
const e = _(t);
|
|
64
|
+
e && typeof e.$patch == "function" && e.$patch(A(r));
|
|
65
|
+
}, x = (t) => {
|
|
66
|
+
for (const [r, e] of Object.entries(t)) P(r, e);
|
|
67
|
+
}, W = /* @__PURE__ */ new Set([
|
|
68
|
+
"area",
|
|
69
|
+
"base",
|
|
70
|
+
"br",
|
|
71
|
+
"col",
|
|
72
|
+
"embed",
|
|
73
|
+
"hr",
|
|
74
|
+
"img",
|
|
75
|
+
"input",
|
|
76
|
+
"link",
|
|
77
|
+
"meta",
|
|
78
|
+
"param",
|
|
79
|
+
"source",
|
|
80
|
+
"track",
|
|
81
|
+
"wbr"
|
|
82
|
+
]), T = (t) => t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"), B = (t) => T(t).replace(/"/g, """), J = (t) => {
|
|
83
|
+
const r = t.toLowerCase();
|
|
84
|
+
return r === "href" || r === "src" || r === "xlink:href" || r === "formaction" || r === "action" || r === "poster" || r === "background" || r === "cite" || r === "data";
|
|
85
|
+
}, U = (t) => t.trim().replace(/[\u0000-\u001F\u007F]+/g, "").replace(/[\u200B-\u200D\uFEFF\u2028\u2029]+/g, "").replace(/\\u[\da-fA-F]{4}/g, "").replace(/\s+/g, "").toLowerCase(), Q = (t) => {
|
|
86
|
+
const r = U(t);
|
|
87
|
+
return R.some((e) => r.startsWith(e));
|
|
88
|
+
}, z = (t) => {
|
|
89
|
+
if (t.nodeType === Node.TEXT_NODE) return T(t.textContent ?? "");
|
|
90
|
+
if (t.nodeType !== Node.ELEMENT_NODE) return "";
|
|
91
|
+
const r = t, e = r.tagName.toLowerCase();
|
|
92
|
+
if (e === "script") return "";
|
|
93
|
+
let o = "";
|
|
94
|
+
for (const s of r.attributes) {
|
|
95
|
+
const c = s.name.toLowerCase();
|
|
96
|
+
c.startsWith("on") || J(c) && Q(s.value) || (o += ` ${s.name}="${B(s.value)}"`);
|
|
97
|
+
}
|
|
98
|
+
if (W.has(e)) return `<${e}${o}>`;
|
|
99
|
+
let i = "";
|
|
100
|
+
for (const s of r.childNodes) i += z(s);
|
|
101
|
+
return `<${e}${o}>${i}</${e}>`;
|
|
102
|
+
}, O = (t) => L(t) || C(t) ? t.value : t, m = (t, r) => {
|
|
103
|
+
const e = t.trim();
|
|
104
|
+
if (e.startsWith("!")) return !m(e.slice(1).trim(), r);
|
|
105
|
+
if (e.startsWith("'") && e.endsWith("'") || e.startsWith('"') && e.endsWith('"')) return e.slice(1, -1);
|
|
106
|
+
if (/^-?\d+(\.\d+)?$/.test(e)) return Number(e);
|
|
107
|
+
if (e === "true") return !0;
|
|
108
|
+
if (e === "false") return !1;
|
|
109
|
+
if (e === "null") return null;
|
|
110
|
+
if (e !== "undefined") {
|
|
111
|
+
if (/^[\w$]+(?:\.[\w$]+)*$/.test(e)) {
|
|
112
|
+
const o = e.split(".");
|
|
113
|
+
let i = r;
|
|
114
|
+
for (const s of o) {
|
|
115
|
+
if (i == null) return;
|
|
116
|
+
i === r ? i = O(i[s]) : i = i[s];
|
|
117
|
+
}
|
|
118
|
+
return i;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const o = Object.keys(r), i = o.map((s) => O(r[s]));
|
|
122
|
+
return new Function(...o, `return (${e});`)(...i);
|
|
123
|
+
} catch {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}, H = (t) => {
|
|
128
|
+
const r = t.match(/^\(?(\w+)(?:\s*,\s*(\w+))?\)?\s+in\s+(\S.*)$/);
|
|
129
|
+
return r ? {
|
|
130
|
+
itemName: r[1],
|
|
131
|
+
indexName: r[2] || void 0,
|
|
132
|
+
listExpr: r[3].trim()
|
|
133
|
+
} : null;
|
|
134
|
+
}, E = (t, r, e, o) => {
|
|
135
|
+
const i = t.getAttribute(`${e}-if`);
|
|
136
|
+
if (i !== null && !m(i, r))
|
|
137
|
+
return !1;
|
|
138
|
+
const s = t.getAttribute(`${e}-show`);
|
|
139
|
+
if (s !== null && !m(s, r)) {
|
|
140
|
+
const n = t;
|
|
141
|
+
n.style ? n.style.display = "none" : t.setAttribute("style", "display: none;");
|
|
142
|
+
}
|
|
143
|
+
const c = t.getAttribute(`${e}-text`);
|
|
144
|
+
if (c !== null) {
|
|
145
|
+
const n = m(c, r);
|
|
146
|
+
t.textContent = String(n ?? "");
|
|
147
|
+
}
|
|
148
|
+
const u = t.getAttribute(`${e}-html`);
|
|
149
|
+
if (u !== null) {
|
|
150
|
+
const n = m(u, r);
|
|
151
|
+
t.innerHTML = String(I(String(n ?? "")));
|
|
152
|
+
}
|
|
153
|
+
const p = t.getAttribute(`${e}-class`);
|
|
154
|
+
if (p !== null) {
|
|
155
|
+
const n = p.trim();
|
|
156
|
+
if (n.startsWith("{")) {
|
|
157
|
+
const l = n.slice(1, -1).trim().split(",");
|
|
158
|
+
for (const a of l) {
|
|
159
|
+
const d = a.indexOf(":");
|
|
160
|
+
if (d > -1) {
|
|
161
|
+
const v = a.slice(0, d).trim().replace(/^['"]|['"]$/g, "");
|
|
162
|
+
m(a.slice(d + 1).trim(), r) && t.classList.add(v);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
const l = m(p, r);
|
|
167
|
+
typeof l == "string" ? l.split(/\s+/).filter(Boolean).forEach((a) => t.classList.add(a)) : Array.isArray(l) && l.filter(Boolean).forEach((a) => t.classList.add(a));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const y = t.getAttribute(`${e}-style`);
|
|
171
|
+
if (y !== null) {
|
|
172
|
+
const n = m(y, r);
|
|
173
|
+
if (n && typeof n == "object") {
|
|
174
|
+
const l = t;
|
|
175
|
+
for (const [a, d] of Object.entries(n)) {
|
|
176
|
+
const v = a.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
177
|
+
l.style.setProperty(v, String(d));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const f = Array.from(t.attributes);
|
|
182
|
+
for (const n of f) if (n.name.startsWith(`${e}-bind:`)) {
|
|
183
|
+
const l = n.name.slice(`${e}-bind:`.length), a = m(n.value, r);
|
|
184
|
+
a === !1 || a === null || a === void 0 ? t.removeAttribute(l) : a === !0 ? t.setAttribute(l, "") : t.setAttribute(l, String(a));
|
|
185
|
+
}
|
|
186
|
+
const g = t.getAttribute(`${e}-for`);
|
|
187
|
+
if (g !== null) {
|
|
188
|
+
const n = H(g);
|
|
189
|
+
if (n) {
|
|
190
|
+
const l = m(n.listExpr, r);
|
|
191
|
+
if (Array.isArray(l) && t.parentNode) {
|
|
192
|
+
const a = t.parentNode;
|
|
193
|
+
for (let d = 0; d < l.length; d++) {
|
|
194
|
+
const v = l[d], h = t.cloneNode(!0);
|
|
195
|
+
h.removeAttribute(`${e}-for`), h.removeAttribute(":key"), h.removeAttribute(`${e}-key`);
|
|
196
|
+
const w = {
|
|
197
|
+
...r,
|
|
198
|
+
[n.itemName]: v
|
|
199
|
+
};
|
|
200
|
+
n.indexName && (w[n.indexName] = d), E(h, w, e, o), $(h, w, e, o), a.insertBefore(h, t);
|
|
201
|
+
}
|
|
202
|
+
return a.removeChild(t), !0;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return !0;
|
|
207
|
+
}, $ = (t, r, e, o) => {
|
|
208
|
+
const i = Array.from(t.children);
|
|
209
|
+
for (const s of i) {
|
|
210
|
+
if (s.hasAttribute(`${e}-for`)) {
|
|
211
|
+
E(s, r, e, o) || s.remove();
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (!E(s, r, e, o)) {
|
|
215
|
+
s.remove();
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
$(s, r, e, o);
|
|
219
|
+
}
|
|
220
|
+
}, k = (t, r) => {
|
|
221
|
+
const e = Array.from(t.attributes);
|
|
222
|
+
for (const o of e) (o.name.startsWith(`${r}-`) || o.name.startsWith(":") || o.name === ":key") && t.removeAttribute(o.name);
|
|
223
|
+
for (const o of Array.from(t.children)) k(o, r);
|
|
224
|
+
}, tt = (t, r, e = {}) => {
|
|
225
|
+
const { prefix: o = "bq", stripDirectives: i = !1, includeStoreState: s = !1 } = e;
|
|
226
|
+
if (!t || typeof t != "string") throw new Error("bQuery SSR: template must be a non-empty string.");
|
|
227
|
+
if (typeof DOMParser > "u") throw new Error("bQuery SSR: DOMParser is not available in this environment. Provide a DOMParser-compatible implementation before calling renderToString().");
|
|
228
|
+
const c = new DOMParser().parseFromString(t.trim(), "text/html"), u = c.body || c.documentElement;
|
|
229
|
+
if (!u) throw new Error("bQuery SSR: Failed to parse template.");
|
|
230
|
+
if ($(u, r, o, c), i) for (const f of Array.from(u.children)) k(f, o);
|
|
231
|
+
let p = "";
|
|
232
|
+
for (const f of u.childNodes) p += z(f);
|
|
233
|
+
let y;
|
|
234
|
+
return s && (y = M({ storeIds: Array.isArray(s) ? s : void 0 }).stateJson), {
|
|
235
|
+
html: p,
|
|
236
|
+
storeState: y
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
export {
|
|
240
|
+
M as a,
|
|
241
|
+
x as i,
|
|
242
|
+
Z as n,
|
|
243
|
+
X as o,
|
|
244
|
+
P as r,
|
|
245
|
+
tt as t
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
//# sourceMappingURL=ssr-B2qd_WBB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssr-B2qd_WBB.js","names":[],"sources":["../src/ssr/hydrate.ts","../src/ssr/serialize.ts","../src/ssr/render.ts"],"sourcesContent":["/**\r\n * Hydration support for server-rendered DOM.\r\n *\r\n * Enables the client-side view system to reuse existing server-rendered DOM\r\n * elements instead of re-rendering them, by attaching reactive bindings\r\n * to the pre-existing DOM structure.\r\n *\r\n * @module bquery/ssr\r\n */\r\n\r\nimport type { BindingContext, MountOptions, View } from '../view/types';\r\nimport { mount } from '../view/mount';\r\n\r\n/**\r\n * Extended mount options that include hydration mode.\r\n */\r\nexport type HydrateMountOptions = MountOptions & {\r\n /**\r\n * When present, must be `true` so the mount operation reuses existing DOM elements\r\n * instead of re-rendering them. Reactive bindings (effects) are\r\n * still attached so the DOM updates reactively from that point on.\r\n *\r\n * @default true\r\n */\r\n hydrate?: true;\r\n};\r\n\r\n/**\r\n * Mounts a reactive view with optional hydration support.\r\n *\r\n * When `hydrate: true` is set, the existing server-rendered DOM is preserved\r\n * and reactive bindings are attached on top. The DOM is NOT re-rendered;\r\n * instead, effects begin tracking signals so future changes update the DOM.\r\n *\r\n * This is the client-side counterpart to `renderToString()`. The typical flow:\r\n * 1. Server: `renderToString(template, data)` → send HTML to client\r\n * 2. Client: `hydrateMount('#app', reactiveContext, { hydrate: true })`\r\n *\r\n * Under the hood, `hydrateMount` simply delegates to the standard `mount()`\r\n * function. The `mount()` function already processes existing DOM elements\r\n * and attaches reactive effects to them — it does not clear/replace content.\r\n * The `hydrate` flag is a semantic marker indicating developer intent and\r\n * ensures the existing DOM structure is preserved.\r\n *\r\n * @param selector - CSS selector or Element to hydrate\r\n * @param context - Binding context with signals, computed values, and functions\r\n * @param options - Mount options with `hydrate: true`\r\n * @returns The mounted View instance\r\n *\r\n * @example\r\n * ```ts\r\n * import { hydrateMount } from '@bquery/bquery/ssr';\r\n * import { signal, computed } from '@bquery/bquery/reactive';\r\n *\r\n * // Server rendered:\r\n * // <div id=\"app\"><h1>Welcome</h1><p>Hello, World!</p></div>\r\n *\r\n * // Client hydration — attaches reactivity to existing DOM:\r\n * const name = signal('World');\r\n * const greeting = computed(() => `Hello, ${name.value}!`);\r\n *\r\n * const view = hydrateMount('#app', { name, greeting }, { hydrate: true });\r\n *\r\n * // Now updating `name.value` will reactively update the DOM\r\n * name.value = 'Alice'; // <p> updates to \"Hello, Alice!\"\r\n * ```\r\n */\r\nexport const hydrateMount = (\r\n selector: string | Element,\r\n context: BindingContext,\r\n options: HydrateMountOptions = {}\r\n): View => {\r\n const { hydrate = true, ...mountOptions } = options;\r\n\r\n if (!hydrate) {\r\n throw new Error('bQuery ssr: hydrateMount() requires { hydrate: true } when options are provided.');\r\n }\r\n\r\n // Hydration uses the standard mount which processes existing DOM\r\n // and attaches reactive effects without clearing content.\r\n return mount(selector, context, mountOptions);\r\n};\r\n","/**\r\n * Store state serialization for SSR.\r\n *\r\n * Provides utilities to serialize store state into a `<script>` tag\r\n * for client-side hydration, and to deserialize state on the client.\r\n *\r\n * @module bquery/ssr\r\n */\r\n\r\nimport { getStore, listStores } from '../store/index';\r\nimport { isPrototypePollutionKey } from '../core/utils/object';\r\nimport type { DeserializedStoreState, SerializeOptions } from './types';\r\n\r\nconst isStoreStateObject = (value: unknown): value is Record<string, unknown> =>\r\n typeof value === 'object' && value !== null && !Array.isArray(value);\r\n\r\nconst sanitizeHydrationState = (value: Record<string, unknown>): Record<string, unknown> => {\r\n const sanitized: Record<string, unknown> = {};\r\n for (const [key, entryValue] of Object.entries(value)) {\r\n if (isPrototypePollutionKey(key)) continue;\r\n sanitized[key] = entryValue;\r\n }\r\n return sanitized;\r\n};\r\n\r\n/**\r\n * Result of store state serialization.\r\n */\r\nexport type SerializeResult = {\r\n /** JSON string of the state map */\r\n stateJson: string;\r\n /** Complete `<script>` tag ready to embed in HTML */\r\n scriptTag: string;\r\n};\r\n\r\n/**\r\n * Escapes a string for safe embedding in a `<script>` tag.\r\n * Prevents XSS via `</script>` injection and HTML entities.\r\n *\r\n * @internal\r\n */\r\nconst escapeForScript = (str: string): string => {\r\n return str\r\n .replace(/</g, '\\\\u003c')\r\n .replace(/>/g, '\\\\u003e')\r\n .replace(/\\//g, '\\\\u002f')\r\n .replace(/\\u2028/g, '\\\\u2028')\r\n .replace(/\\u2029/g, '\\\\u2029');\r\n};\r\n\r\n/**\r\n * Escapes a string for safe embedding in an HTML attribute value.\r\n * @internal\r\n */\r\nconst escapeForHtmlAttribute = (str: string): string => {\r\n return str\r\n .replace(/&/g, '&')\r\n .replace(/\"/g, '"')\r\n .replace(/</g, '<')\r\n .replace(/>/g, '>');\r\n};\r\n\r\n/**\r\n * Serializes the state of registered stores into a JSON string and\r\n * a `<script>` tag suitable for embedding in server-rendered HTML.\r\n *\r\n * The serialized state can be picked up on the client using\r\n * `deserializeStoreState()` to restore stores to their server-side values.\r\n *\r\n * @param options - Serialization options\r\n * @returns Object with JSON string and ready-to-use script tag\r\n *\r\n * @example\r\n * ```ts\r\n * import { serializeStoreState } from '@bquery/bquery/ssr';\r\n * import { createStore } from '@bquery/bquery/store';\r\n *\r\n * const store = createStore({\r\n * id: 'counter',\r\n * state: () => ({ count: 42 }),\r\n * });\r\n *\r\n * const { scriptTag } = serializeStoreState();\r\n * // '<script id=\"__BQUERY_STORE_STATE__\">window.__BQUERY_INITIAL_STATE__={\"counter\":{\"count\":42}}</script>'\r\n * ```\r\n *\r\n * @example\r\n * ```ts\r\n * // Serialize only specific stores\r\n * const { scriptTag } = serializeStoreState({ storeIds: ['counter'] });\r\n * ```\r\n */\r\nexport const serializeStoreState = (options: SerializeOptions = {}): SerializeResult => {\r\n const {\r\n scriptId = '__BQUERY_STORE_STATE__',\r\n globalKey = '__BQUERY_INITIAL_STATE__',\r\n storeIds,\r\n serialize = JSON.stringify,\r\n } = options;\r\n\r\n if (isPrototypePollutionKey(globalKey)) {\r\n throw new Error(\r\n `serializeStoreState: invalid globalKey \"${globalKey}\" - prototype-pollution keys are not allowed.`\r\n );\r\n }\r\n\r\n if (isPrototypePollutionKey(scriptId)) {\r\n throw new Error(\r\n `serializeStoreState: invalid scriptId \"${scriptId}\" - prototype-pollution keys are not allowed.`\r\n );\r\n }\r\n\r\n const ids = storeIds ?? listStores();\r\n const stateMap = Object.create(null) as Record<string, Record<string, unknown>>;\r\n\r\n for (const id of ids) {\r\n if (isPrototypePollutionKey(id)) {\r\n continue;\r\n }\r\n\r\n const store = getStore<{ $state: Record<string, unknown> }>(id);\r\n if (store) {\r\n stateMap[id] = sanitizeHydrationState(store.$state);\r\n }\r\n }\r\n\r\n const stateJson = serialize(stateMap);\r\n if (typeof stateJson !== 'string') {\r\n throw new Error('serializeStoreState: custom serialize function must return a string.');\r\n }\r\n\r\n if (serialize !== JSON.stringify) {\r\n let parsedStateJson: unknown;\r\n try {\r\n parsedStateJson = JSON.parse(stateJson);\r\n } catch {\r\n throw new Error('serializeStoreState: custom serialize function returned invalid JSON.');\r\n }\r\n\r\n if (!isStoreStateObject(parsedStateJson)) {\r\n throw new Error(\r\n 'serializeStoreState: custom serialize function must return a JSON object string.'\r\n );\r\n }\r\n }\r\n\r\n const escapedJson = escapeForScript(stateJson);\r\n const escapedGlobalKey = escapeForScript(JSON.stringify(globalKey));\r\n const escapedScriptId = escapeForHtmlAttribute(scriptId);\r\n const scriptTag = `<script id=\"${escapedScriptId}\">window[${escapedGlobalKey}]=${escapedJson}</script>`;\r\n\r\n return { stateJson, scriptTag };\r\n};\r\n\r\n/**\r\n * Deserializes store state from the global variable set by the SSR script tag.\r\n *\r\n * Call this on the client before creating stores to pre-populate them with\r\n * server-rendered state. After deserialization, the script tag and global\r\n * variable are cleaned up automatically.\r\n *\r\n * @param globalKey - The global variable name where state was serialized\r\n * @param scriptId - The ID of the SSR script tag to remove after hydration\r\n * @returns The deserialized state map, or an empty object if not found\r\n *\r\n * @example\r\n * ```ts\r\n * import { deserializeStoreState } from '@bquery/bquery/ssr';\r\n *\r\n * // Call before creating stores\r\n * const state = deserializeStoreState();\r\n * // state = { counter: { count: 42 } }\r\n * ```\r\n */\r\nexport const deserializeStoreState = (\r\n globalKey = '__BQUERY_INITIAL_STATE__',\r\n scriptId = '__BQUERY_STORE_STATE__'\r\n): DeserializedStoreState => {\r\n if (isPrototypePollutionKey(globalKey)) {\r\n throw new Error(\r\n `deserializeStoreState: invalid globalKey \"${globalKey}\" - prototype-pollution keys are not allowed.`\r\n );\r\n }\r\n\r\n if (isPrototypePollutionKey(scriptId)) {\r\n throw new Error(\r\n `deserializeStoreState: invalid scriptId \"${scriptId}\" - prototype-pollution keys are not allowed.`\r\n );\r\n }\r\n\r\n if (typeof window === 'undefined') {\r\n return {};\r\n }\r\n\r\n const state = (window as unknown as Record<string, unknown>)[globalKey];\r\n if (!state) {\r\n return {};\r\n }\r\n\r\n // Clean up global variable\r\n try {\r\n delete (window as unknown as Record<string, unknown>)[globalKey];\r\n } catch {\r\n // In strict mode on some environments, delete may fail\r\n (window as unknown as Record<string, unknown>)[globalKey] = undefined;\r\n }\r\n\r\n // Clean up script tag\r\n if (typeof document !== 'undefined' && typeof document.getElementById === 'function') {\r\n const scriptEl = document.getElementById(scriptId);\r\n if (scriptEl) {\r\n scriptEl.remove();\r\n }\r\n }\r\n\r\n if (!isStoreStateObject(state)) {\r\n return {};\r\n }\r\n\r\n for (const value of Object.values(state)) {\r\n if (!isStoreStateObject(value)) {\r\n return {};\r\n }\r\n }\r\n\r\n const sanitizedStateMap = Object.create(null) as DeserializedStoreState;\r\n\r\n for (const [storeId, storeState] of Object.entries(state)) {\r\n if (isPrototypePollutionKey(storeId) || !isStoreStateObject(storeState)) {\r\n continue;\r\n }\r\n\r\n sanitizedStateMap[storeId] = sanitizeHydrationState(storeState);\r\n }\r\n\r\n return sanitizedStateMap;\r\n};\r\n\r\n/**\r\n * Hydrates a store with pre-serialized state from SSR.\r\n *\r\n * If the store exists and has a `$patch` method, this applies the\r\n * deserialized state as a patch. Otherwise, the state is ignored.\r\n *\r\n * @param storeId - The store ID to hydrate\r\n * @param state - The plain state object to apply\r\n *\r\n * @example\r\n * ```ts\r\n * import { hydrateStore, deserializeStoreState } from '@bquery/bquery/ssr';\r\n * import { createStore } from '@bquery/bquery/store';\r\n *\r\n * // 1. Deserialize state from SSR script tag\r\n * const ssrState = deserializeStoreState();\r\n *\r\n * // 2. Create store (gets initial values from factory)\r\n * const store = createStore({\r\n * id: 'counter',\r\n * state: () => ({ count: 0 }),\r\n * });\r\n *\r\n * // 3. Apply SSR state\r\n * if (ssrState.counter) {\r\n * hydrateStore('counter', ssrState.counter);\r\n * }\r\n * // store.count is now 42 (from SSR)\r\n * ```\r\n */\r\nexport const hydrateStore = (storeId: string, state: Record<string, unknown>): void => {\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n const store = getStore<{ $patch?: (partial: any) => void }>(storeId);\r\n if (store && typeof store.$patch === 'function') {\r\n store.$patch(sanitizeHydrationState(state));\r\n }\r\n};\r\n\r\n/**\r\n * Hydrates all stores at once from a deserialized state map.\r\n *\r\n * Convenience wrapper that calls `hydrateStore` for each entry in the state map.\r\n *\r\n * @param stateMap - Map of store IDs to their state objects\r\n *\r\n * @example\r\n * ```ts\r\n * import { hydrateStores, deserializeStoreState } from '@bquery/bquery/ssr';\r\n *\r\n * const ssrState = deserializeStoreState();\r\n * hydrateStores(ssrState);\r\n * ```\r\n */\r\nexport const hydrateStores = (stateMap: DeserializedStoreState): void => {\r\n for (const [storeId, state] of Object.entries(stateMap)) {\r\n hydrateStore(storeId, state);\r\n }\r\n};\r\n","/**\r\n * SSR rendering utilities.\r\n *\r\n * Server-side renders bQuery templates to HTML strings by evaluating\r\n * directive attributes against a plain data context. Uses a lightweight\r\n * DOM implementation to process templates without a browser.\r\n *\r\n * @module bquery/ssr\r\n */\r\n\r\nimport { isComputed, isSignal, type Signal } from '../reactive/index';\r\nimport { DANGEROUS_PROTOCOLS } from '../security/constants';\r\nimport { sanitizeHtml } from '../security/sanitize';\r\nimport type { BindingContext } from '../view/types';\r\nimport type { RenderOptions, SSRResult } from './types';\r\nimport { serializeStoreState } from './serialize';\r\n\r\nconst VOID_ELEMENTS = new Set([\r\n 'area',\r\n 'base',\r\n 'br',\r\n 'col',\r\n 'embed',\r\n 'hr',\r\n 'img',\r\n 'input',\r\n 'link',\r\n 'meta',\r\n 'param',\r\n 'source',\r\n 'track',\r\n 'wbr',\r\n]);\r\n\r\nconst escapeHtmlText = (value: string): string =>\r\n value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\r\n\r\nconst escapeHtmlAttribute = (value: string): string =>\r\n escapeHtmlText(value).replace(/\"/g, '"');\r\n\r\nconst isUnsafeUrlAttribute = (name: string): boolean => {\r\n const normalized = name.toLowerCase();\r\n return (\r\n normalized === 'href' ||\r\n normalized === 'src' ||\r\n normalized === 'xlink:href' ||\r\n normalized === 'formaction' ||\r\n normalized === 'action' ||\r\n normalized === 'poster' ||\r\n normalized === 'background' ||\r\n normalized === 'cite' ||\r\n normalized === 'data'\r\n );\r\n};\r\n\r\nconst sanitizeUrlForProtocolCheck = (value: string): string =>\r\n value\r\n .trim()\r\n .replace(/[\\u0000-\\u001F\\u007F]+/g, '')\r\n .replace(/[\\u200B-\\u200D\\uFEFF\\u2028\\u2029]+/g, '')\r\n .replace(/\\\\u[\\da-fA-F]{4}/g, '')\r\n .replace(/\\s+/g, '')\r\n .toLowerCase();\r\n\r\nconst isUnsafeUrlValue = (value: string): boolean => {\r\n const normalized = sanitizeUrlForProtocolCheck(value);\r\n return DANGEROUS_PROTOCOLS.some((protocol) => normalized.startsWith(protocol));\r\n};\r\n\r\nconst serializeSSRNode = (node: Node): string => {\r\n if (node.nodeType === Node.TEXT_NODE) {\r\n return escapeHtmlText(node.textContent ?? '');\r\n }\r\n\r\n if (node.nodeType !== Node.ELEMENT_NODE) {\r\n return '';\r\n }\r\n\r\n const el = node as Element;\r\n const tagName = el.tagName.toLowerCase();\r\n\r\n if (tagName === 'script') {\r\n return '';\r\n }\r\n\r\n let attrs = '';\r\n for (const attr of el.attributes) {\r\n const attrName = attr.name.toLowerCase();\r\n if (attrName.startsWith('on')) {\r\n continue;\r\n }\r\n if (isUnsafeUrlAttribute(attrName) && isUnsafeUrlValue(attr.value)) {\r\n continue;\r\n }\r\n attrs += ` ${attr.name}=\"${escapeHtmlAttribute(attr.value)}\"`;\r\n }\r\n\r\n if (VOID_ELEMENTS.has(tagName)) {\r\n return `<${tagName}${attrs}>`;\r\n }\r\n\r\n let childrenHtml = '';\r\n for (const child of el.childNodes) {\r\n childrenHtml += serializeSSRNode(child);\r\n }\r\n\r\n return `<${tagName}${attrs}>${childrenHtml}</${tagName}>`;\r\n};\r\n\r\n/**\r\n * Unwraps a value — if it's a signal/computed, returns `.value`, otherwise returns as-is.\r\n * @internal\r\n */\r\nconst unwrap = (value: unknown): unknown => {\r\n if (isSignal(value) || isComputed(value)) {\r\n return (value as Signal<unknown>).value;\r\n }\r\n return value;\r\n};\r\n\r\n/**\r\n * Evaluates a simple expression against a context.\r\n * Supports dot-notation property access, negation, ternary, and basic comparisons.\r\n * Unlike the view module's `evaluate()`, this does NOT use `new Function()` —\r\n * it uses a safe subset for SSR to avoid `unsafe-eval` in server environments.\r\n *\r\n * Falls back to `new Function()` for complex expressions.\r\n *\r\n * @internal\r\n */\r\nconst evaluateSSR = <T = unknown>(expression: string, context: BindingContext): T => {\r\n const trimmed = expression.trim();\r\n\r\n // Handle negation: !expr\r\n if (trimmed.startsWith('!')) {\r\n return !evaluateSSR(trimmed.slice(1).trim(), context) as T;\r\n }\r\n\r\n // Handle string literals\r\n if (\r\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\")) ||\r\n (trimmed.startsWith('\"') && trimmed.endsWith('\"'))\r\n ) {\r\n return trimmed.slice(1, -1) as T;\r\n }\r\n\r\n // Handle numeric literals\r\n if (/^-?\\d+(\\.\\d+)?$/.test(trimmed)) {\r\n return Number(trimmed) as T;\r\n }\r\n\r\n // Handle boolean literals\r\n if (trimmed === 'true') return true as T;\r\n if (trimmed === 'false') return false as T;\r\n if (trimmed === 'null') return null as T;\r\n if (trimmed === 'undefined') return undefined as T;\r\n\r\n // Handle dot-notation property access: a.b.c\r\n if (/^[\\w$]+(?:\\.[\\w$]+)*$/.test(trimmed)) {\r\n const parts = trimmed.split('.');\r\n let current: unknown = context;\r\n for (const part of parts) {\r\n if (current == null) return undefined as T;\r\n // First level: unwrap signals\r\n if (current === context) {\r\n current = unwrap((current as Record<string, unknown>)[part]);\r\n } else {\r\n current = (current as Record<string, unknown>)[part];\r\n }\r\n }\r\n return current as T;\r\n }\r\n\r\n // For complex expressions, fall back to Function-based evaluation\r\n try {\r\n const keys = Object.keys(context);\r\n const values = keys.map((k) => unwrap(context[k]));\r\n const fn = new Function(...keys, `return (${trimmed});`);\r\n return fn(...values) as T;\r\n } catch {\r\n return undefined as T;\r\n }\r\n};\r\n\r\n/**\r\n * Parses a `bq-for` expression like `item in items` or `(item, index) in items`.\r\n * @internal\r\n */\r\nconst parseForExpression = (\r\n expression: string\r\n): { itemName: string; indexName?: string; listExpr: string } | null => {\r\n const match = expression.match(/^\\(?(\\w+)(?:\\s*,\\s*(\\w+))?\\)?\\s+in\\s+(\\S.*)$/);\r\n if (!match) return null;\r\n return {\r\n itemName: match[1],\r\n indexName: match[2] || undefined,\r\n listExpr: match[3].trim(),\r\n };\r\n};\r\n\r\n/**\r\n * Processes an element's SSR directives, modifying it in place.\r\n * Returns `false` if the element should be removed from output (bq-if = false).\r\n * @internal\r\n */\r\nconst processSSRElement = (\r\n el: Element,\r\n context: BindingContext,\r\n prefix: string,\r\n doc: Document\r\n): boolean => {\r\n // Handle bq-if: remove element if condition is falsy\r\n const ifExpr = el.getAttribute(`${prefix}-if`);\r\n if (ifExpr !== null) {\r\n const condition = evaluateSSR<boolean>(ifExpr, context);\r\n if (!condition) {\r\n return false; // Signal to remove this element\r\n }\r\n }\r\n\r\n // Handle bq-show: set display:none if falsy\r\n const showExpr = el.getAttribute(`${prefix}-show`);\r\n if (showExpr !== null) {\r\n const condition = evaluateSSR<boolean>(showExpr, context);\r\n if (!condition) {\r\n const htmlEl = el as unknown as { style?: { display?: string } };\r\n if (htmlEl.style) {\r\n htmlEl.style.display = 'none';\r\n } else {\r\n el.setAttribute('style', 'display: none;');\r\n }\r\n }\r\n }\r\n\r\n // Handle bq-text: set text content\r\n const textExpr = el.getAttribute(`${prefix}-text`);\r\n if (textExpr !== null) {\r\n const value = evaluateSSR(textExpr, context);\r\n el.textContent = String(value ?? '');\r\n }\r\n\r\n // Handle bq-html: sanitize to match client-side default behavior\r\n const htmlExpr = el.getAttribute(`${prefix}-html`);\r\n if (htmlExpr !== null) {\r\n const value = evaluateSSR(htmlExpr, context);\r\n el.innerHTML = String(sanitizeHtml(String(value ?? '')));\r\n }\r\n\r\n // Handle bq-class: add classes\r\n const classExpr = el.getAttribute(`${prefix}-class`);\r\n if (classExpr !== null) {\r\n const trimmedClass = classExpr.trim();\r\n if (trimmedClass.startsWith('{')) {\r\n // Object syntax: { active: isActive, disabled: !enabled }\r\n const inner = trimmedClass.slice(1, -1).trim();\r\n const pairs = inner.split(',');\r\n for (const pair of pairs) {\r\n const colonIdx = pair.indexOf(':');\r\n if (colonIdx > -1) {\r\n const className = pair\r\n .slice(0, colonIdx)\r\n .trim()\r\n .replace(/^['\"]|['\"]$/g, '');\r\n const condExpr = pair.slice(colonIdx + 1).trim();\r\n const condition = evaluateSSR<boolean>(condExpr, context);\r\n if (condition) {\r\n el.classList.add(className);\r\n }\r\n }\r\n }\r\n } else {\r\n const result = evaluateSSR<string | string[]>(classExpr, context);\r\n if (typeof result === 'string') {\r\n result\r\n .split(/\\s+/)\r\n .filter(Boolean)\r\n .forEach((cls) => el.classList.add(cls));\r\n } else if (Array.isArray(result)) {\r\n result.filter(Boolean).forEach((cls) => el.classList.add(cls));\r\n }\r\n }\r\n }\r\n\r\n // Handle bq-style: set inline styles\r\n const styleExpr = el.getAttribute(`${prefix}-style`);\r\n if (styleExpr !== null) {\r\n const result = evaluateSSR<Record<string, string>>(styleExpr, context);\r\n if (result && typeof result === 'object') {\r\n const htmlEl = el as HTMLElement;\r\n for (const [prop, val] of Object.entries(result)) {\r\n // Convert camelCase to kebab-case\r\n const cssProp = prop.replace(/([A-Z])/g, '-$1').toLowerCase();\r\n htmlEl.style.setProperty(cssProp, String(val));\r\n }\r\n }\r\n }\r\n\r\n // Handle bq-bind:attr — set arbitrary attributes\r\n const attrs = Array.from(el.attributes);\r\n for (const attr of attrs) {\r\n if (attr.name.startsWith(`${prefix}-bind:`)) {\r\n const attrName = attr.name.slice(`${prefix}-bind:`.length);\r\n const value = evaluateSSR(attr.value, context);\r\n if (value === false || value === null || value === undefined) {\r\n el.removeAttribute(attrName);\r\n } else if (value === true) {\r\n el.setAttribute(attrName, '');\r\n } else {\r\n el.setAttribute(attrName, String(value));\r\n }\r\n }\r\n }\r\n\r\n // Handle bq-for: list rendering\r\n const forExpr = el.getAttribute(`${prefix}-for`);\r\n if (forExpr !== null) {\r\n const parsed = parseForExpression(forExpr);\r\n if (parsed) {\r\n const list = evaluateSSR<unknown[]>(parsed.listExpr, context);\r\n if (Array.isArray(list) && el.parentNode) {\r\n const parent = el.parentNode;\r\n for (let i = 0; i < list.length; i++) {\r\n const item = list[i];\r\n const clone = el.cloneNode(true) as Element;\r\n\r\n // Remove the bq-for attribute from clones\r\n clone.removeAttribute(`${prefix}-for`);\r\n clone.removeAttribute(':key');\r\n clone.removeAttribute(`${prefix}-key`);\r\n\r\n // Create item context\r\n const itemContext: BindingContext = {\r\n ...context,\r\n [parsed.itemName]: item,\r\n };\r\n if (parsed.indexName) {\r\n itemContext[parsed.indexName] = i;\r\n }\r\n\r\n // Recursively process the clone\r\n processSSRElement(clone, itemContext, prefix, doc);\r\n processSSRChildren(clone, itemContext, prefix, doc);\r\n\r\n parent.insertBefore(clone, el);\r\n }\r\n\r\n // Remove the original template element\r\n parent.removeChild(el);\r\n return true; // Already handled children\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n};\r\n\r\n/**\r\n * Recursively processes children of an element for SSR.\r\n * @internal\r\n */\r\nconst processSSRChildren = (\r\n parent: Element,\r\n context: BindingContext,\r\n prefix: string,\r\n doc: Document\r\n): void => {\r\n // Process children in reverse to handle removals safely\r\n const children = Array.from(parent.children);\r\n for (const child of children) {\r\n // Skip bq-for elements — they're handled by parent\r\n if (child.hasAttribute(`${prefix}-for`)) {\r\n // Process the for directive on this element\r\n const keep = processSSRElement(child, context, prefix, doc);\r\n if (!keep) {\r\n child.remove();\r\n }\r\n continue;\r\n }\r\n\r\n const keep = processSSRElement(child, context, prefix, doc);\r\n if (!keep) {\r\n child.remove();\r\n continue;\r\n }\r\n\r\n // Recurse into children\r\n processSSRChildren(child, context, prefix, doc);\r\n }\r\n};\r\n\r\n/**\r\n * Strips all directive attributes (bq-*) from an element and its descendants.\r\n * @internal\r\n */\r\nconst stripDirectiveAttributes = (el: Element, prefix: string): void => {\r\n // Remove directive attributes from this element\r\n const attrs = Array.from(el.attributes);\r\n for (const attr of attrs) {\r\n if (attr.name.startsWith(`${prefix}-`) || attr.name.startsWith(':') || attr.name === ':key') {\r\n el.removeAttribute(attr.name);\r\n }\r\n }\r\n\r\n // Recurse into children\r\n for (const child of Array.from(el.children)) {\r\n stripDirectiveAttributes(child, prefix);\r\n }\r\n};\r\n\r\n/**\r\n * Server-side renders a bQuery template to an HTML string.\r\n *\r\n * Takes an HTML template with bQuery directives (bq-text, bq-if, bq-for, etc.)\r\n * and a data context, then evaluates the directives to produce a static HTML string.\r\n * This HTML can be sent to the client and later hydrated with `mount()` using\r\n * `{ hydrate: true }`.\r\n *\r\n * Supported directives:\r\n * - `bq-text` — Sets text content\r\n * - `bq-html` — Sets innerHTML\r\n * - `bq-if` — Conditional rendering (removes element if falsy)\r\n * - `bq-show` — Toggle visibility via `display: none`\r\n * - `bq-class` — Dynamic class binding (object or expression syntax)\r\n * - `bq-style` — Dynamic inline styles\r\n * - `bq-for` — List rendering\r\n * - `bq-bind:attr` — Dynamic attribute binding\r\n *\r\n * @param template - HTML template string with bq-* directives\r\n * @param data - Plain data object (signals will be unwrapped automatically)\r\n * @param options - Rendering options\r\n * @returns SSR result with HTML string and optional store state\r\n *\r\n * @example\r\n * ```ts\r\n * import { renderToString } from '@bquery/bquery/ssr';\r\n * import { signal } from '@bquery/bquery/reactive';\r\n *\r\n * const result = renderToString(\r\n * '<div><h1 bq-text=\"title\"></h1><p bq-if=\"showBody\">Hello!</p></div>',\r\n * { title: 'Welcome', showBody: true }\r\n * );\r\n *\r\n * console.log(result.html);\r\n * // '<div><h1>Welcome</h1><p>Hello!</p></div>'\r\n * ```\r\n *\r\n * @example\r\n * ```ts\r\n * // With bq-for list rendering\r\n * const result = renderToString(\r\n * '<ul><li bq-for=\"item in items\" bq-text=\"item.name\"></li></ul>',\r\n * { items: [{ name: 'Alice' }, { name: 'Bob' }] }\r\n * );\r\n *\r\n * console.log(result.html);\r\n * // '<ul><li>Alice</li><li>Bob</li></ul>'\r\n * ```\r\n */\r\nexport const renderToString = (\r\n template: string,\r\n data: BindingContext,\r\n options: RenderOptions = {}\r\n): SSRResult => {\r\n const { prefix = 'bq', stripDirectives = false, includeStoreState = false } = options;\r\n\r\n if (!template || typeof template !== 'string') {\r\n throw new Error('bQuery SSR: template must be a non-empty string.');\r\n }\r\n\r\n if (typeof DOMParser === 'undefined') {\r\n throw new Error(\r\n 'bQuery SSR: DOMParser is not available in this environment. Provide a DOMParser-compatible implementation before calling renderToString().'\r\n );\r\n }\r\n\r\n // Create a DOM document for processing\r\n const parser = new DOMParser();\r\n const doc = parser.parseFromString(template.trim(), 'text/html');\r\n const body = doc.body || doc.documentElement;\r\n\r\n if (!body) {\r\n throw new Error('bQuery SSR: Failed to parse template.');\r\n }\r\n\r\n // Process all children of the body\r\n processSSRChildren(body, data, prefix, doc);\r\n\r\n // Strip directive attributes if requested\r\n if (stripDirectives) {\r\n for (const child of Array.from(body.children)) {\r\n stripDirectiveAttributes(child, prefix);\r\n }\r\n }\r\n\r\n let html = '';\r\n for (const child of body.childNodes) {\r\n html += serializeSSRNode(child);\r\n }\r\n\r\n // Handle store state serialization\r\n let storeState: string | undefined;\r\n if (includeStoreState) {\r\n const storeIds = Array.isArray(includeStoreState) ? includeStoreState : undefined;\r\n storeState = serializeStoreState({ storeIds }).stateJson;\r\n }\r\n\r\n return { html, storeState };\r\n};\r\n"],"mappings":";;;;;AAmEA,IAAa,IAAA,CACX,GACA,GACA,IAA+B,CAAA,MACtB;AACT,QAAM,EAAE,SAAA,IAAU,IAAM,GAAG,EAAA,IAAiB;AAE5C,MAAI,CAAC,EACH,OAAM,IAAI,MAAM,kFAAA;AAKlB,SAAO,EAAM,GAAU,GAAS,CAAA;GCnE5B,IAAA,CAAsB,MAC1B,OAAO,KAAU,YAAY,MAAU,QAAQ,CAAC,MAAM,QAAQ,CAAA,GAE1D,IAAA,CAA0B,MAA4D;AAC1F,QAAM,IAAqC,CAAA;AAC3C,aAAW,CAAC,GAAK,CAAA,KAAe,OAAO,QAAQ,CAAA;AAC7C,IAAI,EAAwB,CAAA,MAC5B,EAAU,CAAA,IAAO;AAEnB,SAAO;GAmBH,IAAA,CAAmB,MAChB,EACJ,QAAQ,MAAM,SAAA,EACd,QAAQ,MAAM,SAAA,EACd,QAAQ,OAAO,SAAA,EACf,QAAQ,WAAW,SAAA,EACnB,QAAQ,WAAW,SAAA,GAOlB,IAAA,CAA0B,MACvB,EACJ,QAAQ,MAAM,OAAA,EACd,QAAQ,MAAM,QAAA,EACd,QAAQ,MAAM,MAAA,EACd,QAAQ,MAAM,MAAA,GAiCN,IAAA,CAAuB,IAA4B,CAAA,MAAwB;AACtF,QAAM,EACJ,UAAA,IAAW,0BACX,WAAA,IAAY,4BACZ,UAAA,GACA,WAAA,IAAY,KAAK,UAAA,IACf;AAEJ,MAAI,EAAwB,CAAA,EAC1B,OAAM,IAAI,MACR,2CAA2C,CAAA,+CAAU;AAIzD,MAAI,EAAwB,CAAA,EA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AA,EAClC,CAAA,EAAyB,GAAO,CAAA;AAIpC,MAAI,IAAO;AACX,aAAW,KAAS,EAAK,WACvB,CAAA,KAAQ,EAAiB,CAAA;AAI3B,MAAI;AACJ,SAAI,MAEF,IAAa,EAAoB,EAAE,UADlB,MAAM,QAAQ,CAAA,IAAqB,IAAoB,OAAA,CAC3B,EAAE,YAG1C;AAAA,IAAE,MAAA;AAAA,IAAM,YAAA;AAAA"}
|
package/dist/ssr.es.mjs
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-store.d.ts","sourceRoot":"","sources":["../../src/store/create-store.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"create-store.d.ts","sourceRoot":"","sources":["../../src/store/create-store.ts"],"names":[],"mappings":"AAAA;;GAEG;AAcH,OAAO,KAAK,EAIV,KAAK,EACL,eAAe,EAEhB,MAAM,SAAS,CAAC;AAGjB;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,GACtB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEzD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEzE,YAAY,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KACnC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAwaf,CAAC"}
|
|
@@ -24,5 +24,5 @@ import type { Store, StoreDefinition } from './types';
|
|
|
24
24
|
* counter.increment();
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
|
-
export declare const defineStore: <S extends Record<string, unknown>, G extends Record<string, unknown> = Record<string, never>, A extends Record<string, (...args:
|
|
27
|
+
export declare const defineStore: <S extends Record<string, unknown>, G extends Record<string, unknown> = Record<string, never>, A extends Record<string, (...args: any[]) => any> = Record<string, never>>(id: string, definition: Omit<StoreDefinition<S, G, A>, "id">) => (() => Store<S, G, A>);
|
|
28
28
|
//# sourceMappingURL=define-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-store.d.ts","sourceRoot":"","sources":["../../src/store/define-store.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,WAAW,GACtB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"define-store.d.ts","sourceRoot":"","sources":["../../src/store/define-store.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,WAAW,GACtB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEzD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEzE,IAAI,MAAM,EACV,YAAY,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,KAC/C,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAUvB,CAAC"}
|
package/dist/store/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Store module exports.
|
|
3
3
|
*/
|
|
4
|
-
export type { Actions, Getters, StateFactory, Store, StoreDefinition, StorePatch, StorePlugin, StoreSubscriber, } from './types';
|
|
4
|
+
export type { ActionContext, Actions, Getters, OnActionCallback, PersistedStoreOptions, StateFactory, StorageBackend, Store, StoreDefinition, StorePatch, StorePlugin, StoreSerializer, StoreSubscriber, } from './types';
|
|
5
5
|
export { createStore } from './create-store';
|
|
6
6
|
export { defineStore } from './define-store';
|
|
7
7
|
export { mapActions, mapGetters, mapState } from './mapping';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EACV,OAAO,EACP,OAAO,EACP,YAAY,EACZ,KAAK,EACL,eAAe,EACf,UAAU,EACV,WAAW,EACX,eAAe,GAChB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EACV,aAAa,EACb,OAAO,EACP,OAAO,EACP,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACd,KAAK,EACL,eAAe,EACf,UAAU,EACV,WAAW,EACX,eAAe,EACf,eAAe,GAChB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/store/mapping.d.ts
CHANGED
|
@@ -24,5 +24,5 @@ export declare const mapGetters: <G extends Record<string, unknown>, K extends k
|
|
|
24
24
|
* @param keys - Action keys to map
|
|
25
25
|
* @returns Object with mapped actions
|
|
26
26
|
*/
|
|
27
|
-
export declare const mapActions: <A extends Record<string, (...args:
|
|
27
|
+
export declare const mapActions: <A extends Record<string, (...args: any[]) => any>, K extends keyof A>(store: A, keys: K[]) => Pick<A, K>;
|
|
28
28
|
//# sourceMappingURL=mapping.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../src/store/mapping.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAC3E,OAAO,CAAC,EACR,MAAM,CAAC,EAAE,KACR,IAAI,CAAC,CAAC,EAAE,CAAC,CAWX,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAC7E,OAAO,CAAC,EACR,MAAM,CAAC,EAAE,KACR,IAAI,CAAC,CAAC,EAAE,CAAC,CAWX,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../src/store/mapping.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAC3E,OAAO,CAAC,EACR,MAAM,CAAC,EAAE,KACR,IAAI,CAAC,CAAC,EAAE,CAAC,CAWX,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAC7E,OAAO,CAAC,EACR,MAAM,CAAC,EAAE,KACR,IAAI,CAAC,CAAC,EAAE,CAAC,CAWX,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAErB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,EACjD,CAAC,SAAS,MAAM,CAAC,EAEjB,OAAO,CAAC,EACR,MAAM,CAAC,EAAE,KACR,IAAI,CAAC,CAAC,EAAE,CAAC,CASX,CAAC"}
|
|
@@ -1,13 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Store persistence helpers.
|
|
3
3
|
*/
|
|
4
|
-
import type { Store, StoreDefinition } from './types';
|
|
4
|
+
import type { PersistedStoreOptions, Store, StoreDefinition } from './types';
|
|
5
5
|
/**
|
|
6
|
-
* Creates a store with automatic persistence
|
|
6
|
+
* Creates a store with automatic persistence.
|
|
7
|
+
*
|
|
8
|
+
* Supports configurable storage backends, custom serializers, and schema
|
|
9
|
+
* versioning with migration functions. All options are optional and
|
|
10
|
+
* backward-compatible with the simple `(definition, storageKey?)` signature.
|
|
7
11
|
*
|
|
8
12
|
* @param definition - Store definition
|
|
9
|
-
* @param
|
|
13
|
+
* @param options - Persistence options or a plain string storage key for backward compatibility
|
|
10
14
|
* @returns The reactive store instance
|
|
15
|
+
*
|
|
16
|
+
* @example Basic usage (localStorage + JSON)
|
|
17
|
+
* ```ts
|
|
18
|
+
* const store = createPersistedStore({
|
|
19
|
+
* id: 'settings',
|
|
20
|
+
* state: () => ({ theme: 'dark' }),
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example With sessionStorage and custom key
|
|
25
|
+
* ```ts
|
|
26
|
+
* const store = createPersistedStore(
|
|
27
|
+
* { id: 'session', state: () => ({ token: '' }) },
|
|
28
|
+
* { key: 'my-session', storage: sessionStorage },
|
|
29
|
+
* );
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example With versioning and migration
|
|
33
|
+
* ```ts
|
|
34
|
+
* const store = createPersistedStore(
|
|
35
|
+
* { id: 'app', state: () => ({ name: '', theme: 'auto' }) },
|
|
36
|
+
* {
|
|
37
|
+
* version: 2,
|
|
38
|
+
* migrate: (old, v) => {
|
|
39
|
+
* if (v < 2) return { ...old, theme: 'auto' };
|
|
40
|
+
* return old;
|
|
41
|
+
* },
|
|
42
|
+
* },
|
|
43
|
+
* );
|
|
44
|
+
* ```
|
|
11
45
|
*/
|
|
12
|
-
export declare const createPersistedStore: <S extends Record<string, unknown>, G extends Record<string, unknown> = Record<string, never>, A extends Record<string, (...args:
|
|
46
|
+
export declare const createPersistedStore: <S extends Record<string, unknown>, G extends Record<string, unknown> = Record<string, never>, A extends Record<string, (...args: any[]) => any> = Record<string, never>>(definition: StoreDefinition<S, G, A>, options?: PersistedStoreOptions | string) => Store<S, G, A>;
|
|
13
47
|
//# sourceMappingURL=persisted.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persisted.d.ts","sourceRoot":"","sources":["../../src/store/persisted.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"persisted.d.ts","sourceRoot":"","sources":["../../src/store/persisted.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,qBAAqB,EAAkB,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA+C7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,oBAAoB,GAC/B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEzD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEzE,YAAY,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACpC,UAAU,qBAAqB,GAAG,MAAM,KACvC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAiJf,CAAC"}
|
package/dist/store/types.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ export type Getters<S, G> = {
|
|
|
17
17
|
* The `this` context includes state, getters, and other actions.
|
|
18
18
|
*/
|
|
19
19
|
export type Actions<S, G, A> = {
|
|
20
|
-
[K in keyof A]: A[K]
|
|
21
|
-
}
|
|
20
|
+
[K in keyof A]: A[K];
|
|
21
|
+
} & ThisType<S & G & A>;
|
|
22
22
|
/**
|
|
23
23
|
* Store definition for createStore.
|
|
24
24
|
*/
|
|
@@ -40,10 +40,55 @@ export type StoreSubscriber<S> = (state: S) => void;
|
|
|
40
40
|
* Patch payload for store updates.
|
|
41
41
|
*/
|
|
42
42
|
export type StorePatch<S> = Partial<S> | ((state: S) => void);
|
|
43
|
+
/**
|
|
44
|
+
* Action function record used by store definitions and lifecycle hooks.
|
|
45
|
+
*/
|
|
46
|
+
export type StoreActionRecord = Record<string, (...args: any[]) => any>;
|
|
47
|
+
type ActionName<A extends StoreActionRecord> = keyof A & string;
|
|
48
|
+
type ActionArgs<A extends StoreActionRecord, K extends ActionName<A>> = Parameters<A[K]>;
|
|
49
|
+
type ActionResult<A extends StoreActionRecord, K extends ActionName<A>> = Awaited<ReturnType<A[K]>>;
|
|
50
|
+
/**
|
|
51
|
+
* Context provided to `$onAction` callbacks.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* store.$onAction(({ name, args, after, onError }) => {
|
|
56
|
+
* console.log(`Action "${name}" called with`, args);
|
|
57
|
+
* after((result) => console.log(`Returned:`, result));
|
|
58
|
+
* onError((err) => console.error(`Failed:`, err));
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* Hook registration is synchronous: call `after()` and `onError()` before the
|
|
63
|
+
* callback returns. Promise-returning listeners may still observe errors, but
|
|
64
|
+
* any hooks registered after an `await` will not affect the current action.
|
|
65
|
+
*/
|
|
66
|
+
export type ActionContext<S extends Record<string, unknown>, G extends Record<string, unknown>, A extends StoreActionRecord, K extends ActionName<A> = ActionName<A>> = {
|
|
67
|
+
/** The name of the action being called */
|
|
68
|
+
name: K;
|
|
69
|
+
/** The store instance */
|
|
70
|
+
store: Store<S, G, A>;
|
|
71
|
+
/** The arguments passed to the action */
|
|
72
|
+
args: ActionArgs<A, K>;
|
|
73
|
+
/**
|
|
74
|
+
* Register a callback to run after the action completes successfully.
|
|
75
|
+
* For async actions, runs after the returned promise resolves.
|
|
76
|
+
*/
|
|
77
|
+
after: (callback: (result: ActionResult<A, K>) => void) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Register a callback to run if the action throws or the returned
|
|
80
|
+
* promise rejects.
|
|
81
|
+
*/
|
|
82
|
+
onError: (callback: (error: unknown) => void) => void;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Callback for `$onAction`.
|
|
86
|
+
*/
|
|
87
|
+
export type OnActionCallback<S extends Record<string, unknown>, G extends Record<string, unknown>, A extends StoreActionRecord> = <K extends ActionName<A>>(context: ActionContext<S, G, A, K>) => void;
|
|
43
88
|
/**
|
|
44
89
|
* The returned store instance with state, getters, and actions merged.
|
|
45
90
|
*/
|
|
46
|
-
export type Store<S extends Record<string, unknown>, G extends Record<string, unknown>, A extends
|
|
91
|
+
export type Store<S extends Record<string, unknown>, G extends Record<string, unknown>, A extends StoreActionRecord> = S & G & A & {
|
|
47
92
|
/** Store identifier */
|
|
48
93
|
$id: string;
|
|
49
94
|
/** Reset state to initial values */
|
|
@@ -60,6 +105,27 @@ export type Store<S extends Record<string, unknown>, G extends Record<string, un
|
|
|
60
105
|
$patchDeep: (partial: StorePatch<S>) => void;
|
|
61
106
|
/** Get raw state object (non-reactive snapshot) */
|
|
62
107
|
$state: S;
|
|
108
|
+
/**
|
|
109
|
+
* Hook into action calls. The callback receives an {@link ActionContext}
|
|
110
|
+
* with `after` and `onError` hooks for the full action lifecycle.
|
|
111
|
+
*
|
|
112
|
+
* @param callback - Invoked before each action execution
|
|
113
|
+
* @returns A function to remove the hook
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const unsub = store.$onAction(({ name, args, after, onError }) => {
|
|
118
|
+
* const start = Date.now();
|
|
119
|
+
* after(() => console.log(`${name} took ${Date.now() - start}ms`));
|
|
120
|
+
* onError((e) => console.error(`${name} failed`, e));
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* Register hooks synchronously before the callback returns. Async listeners
|
|
125
|
+
* that await before calling `after()` or `onError()` cannot affect the
|
|
126
|
+
* current action invocation.
|
|
127
|
+
*/
|
|
128
|
+
$onAction: (callback: OnActionCallback<S, G, A>) => () => void;
|
|
63
129
|
};
|
|
64
130
|
/**
|
|
65
131
|
* Plugin that can extend store functionality.
|
|
@@ -68,4 +134,75 @@ export type StorePlugin<S = unknown> = (context: {
|
|
|
68
134
|
store: Store<any, any, any>;
|
|
69
135
|
options: StoreDefinition<any, any, any>;
|
|
70
136
|
}) => Partial<S> | void;
|
|
137
|
+
/**
|
|
138
|
+
* Serializer interface for persisted stores.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const dateSerializer: StoreSerializer = {
|
|
143
|
+
* serialize: (state) => JSON.stringify(state, (_, v) =>
|
|
144
|
+
* v instanceof Date ? v.toISOString() : v),
|
|
145
|
+
* deserialize: (raw) => JSON.parse(raw),
|
|
146
|
+
* };
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export type StoreSerializer = {
|
|
150
|
+
/** Convert state to a string for storage */
|
|
151
|
+
serialize: (state: unknown) => string;
|
|
152
|
+
/** Convert a stored string back to state */
|
|
153
|
+
deserialize: (raw: string) => unknown;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Storage backend interface for persisted stores.
|
|
157
|
+
* Compatible with `localStorage`, `sessionStorage`, or any custom adapter.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* createPersistedStore(definition, {
|
|
162
|
+
* storage: sessionStorage,
|
|
163
|
+
* });
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export type StorageBackend = {
|
|
167
|
+
getItem: (key: string) => string | null;
|
|
168
|
+
setItem: (key: string, value: string) => void;
|
|
169
|
+
removeItem: (key: string) => void;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Options for `createPersistedStore`.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* createPersistedStore(definition, {
|
|
177
|
+
* key: 'my-store',
|
|
178
|
+
* storage: sessionStorage,
|
|
179
|
+
* serializer: { serialize: JSON.stringify, deserialize: JSON.parse },
|
|
180
|
+
* version: 2,
|
|
181
|
+
* migrate: (persisted, version) => {
|
|
182
|
+
* if (version < 2) return { ...persisted, newField: 'default' };
|
|
183
|
+
* return persisted;
|
|
184
|
+
* },
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export type PersistedStoreOptions = {
|
|
189
|
+
/** Custom storage key. Defaults to `"bquery-store-${id}"`. */
|
|
190
|
+
key?: string;
|
|
191
|
+
/** Storage backend. Defaults to `localStorage`. */
|
|
192
|
+
storage?: StorageBackend;
|
|
193
|
+
/** Custom serializer/deserializer. Defaults to JSON. */
|
|
194
|
+
serializer?: StoreSerializer;
|
|
195
|
+
/**
|
|
196
|
+
* Schema version number. When this changes and `migrate` is provided,
|
|
197
|
+
* the migration function is called with the old state and version.
|
|
198
|
+
*/
|
|
199
|
+
version?: number;
|
|
200
|
+
/**
|
|
201
|
+
* Migration function called when the persisted version differs from
|
|
202
|
+
* the current `version`. Receives the deserialized state and the old
|
|
203
|
+
* version number. Must return the migrated state object.
|
|
204
|
+
*/
|
|
205
|
+
migrate?: (persistedState: Record<string, unknown>, oldVersion: number) => Record<string, unknown>;
|
|
206
|
+
};
|
|
207
|
+
export {};
|
|
71
208
|
//# sourceMappingURL=types.d.ts.map
|