@bquery/bquery 1.6.0 → 1.8.1
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 +192 -18
- 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-DVBCy09c.js +421 -0
- package/dist/a11y-DVBCy09c.js.map +1 -0
- package/dist/a11y.es.mjs +14 -0
- package/dist/component/component.d.ts.map +1 -1
- package/dist/component/html.d.ts.map +1 -1
- package/dist/component/index.d.ts +2 -1
- 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 +53 -1
- package/dist/component/types.d.ts.map +1 -1
- package/dist/component-L3-JfOFz.js +684 -0
- package/dist/component-L3-JfOFz.js.map +1 -0
- package/dist/component.es.mjs +9 -6
- package/dist/{config-DRmZZno3.js → config-DhT9auRm.js} +4 -4
- package/dist/{config-DRmZZno3.js.map → config-DhT9auRm.js.map} +1 -1
- package/dist/constraints-D5RHQLmP.js +100 -0
- package/dist/constraints-D5RHQLmP.js.map +1 -0
- package/dist/core/collection.d.ts +134 -0
- package/dist/core/collection.d.ts.map +1 -1
- package/dist/core/element.d.ts +120 -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 +14 -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-DdtZHzsS.js +168 -0
- package/dist/core-DdtZHzsS.js.map +1 -0
- package/dist/{core-CCEabVHl.js → core-EMYSLzaT.js} +293 -194
- package/dist/core-EMYSLzaT.js.map +1 -0
- package/dist/core.es.mjs +48 -46
- package/dist/custom-directives-Dr4C5lVV.js +9 -0
- package/dist/custom-directives-Dr4C5lVV.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-BhB2iDPT.js +122 -0
- package/dist/devtools-BhB2iDPT.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-NwZBYh4l.js +244 -0
- package/dist/dnd-NwZBYh4l.js.map +1 -0
- package/dist/dnd.es.mjs +6 -0
- package/dist/env-CTdvLaH2.js +19 -0
- package/dist/env-CTdvLaH2.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 +40 -0
- package/dist/forms/index.d.ts.map +1 -0
- package/dist/forms/types.d.ts +185 -0
- package/dist/forms/types.d.ts.map +1 -0
- package/dist/forms/use-field.d.ts +34 -0
- package/dist/forms/use-field.d.ts.map +1 -0
- package/dist/forms/validators.d.ts +204 -0
- package/dist/forms/validators.d.ts.map +1 -0
- package/dist/forms-UcRHsYxC.js +227 -0
- package/dist/forms-UcRHsYxC.js.map +1 -0
- package/dist/forms.es.mjs +16 -0
- package/dist/full.d.ts +30 -11
- package/dist/full.d.ts.map +1 -1
- package/dist/full.es.mjs +209 -93
- 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/function-Cybd57JV.js +33 -0
- package/dist/function-Cybd57JV.js.map +1 -0
- 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-kuF6Ekj6.js +89 -0
- package/dist/i18n-kuF6Ekj6.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 +257 -143
- 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-i-fB5WxI.js +340 -0
- package/dist/media-i-fB5WxI.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-BJsAuULb.js +530 -0
- package/dist/motion-BJsAuULb.js.map +1 -0
- package/dist/motion.es.mjs +27 -23
- package/dist/{view-C70lA3vf.js → mount-B4Y8bk8Z.js} +166 -160
- package/dist/mount-B4Y8bk8Z.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-Dr9b6fsq.js → platform-Dw2gE3zI.js} +21 -22
- package/dist/{platform-Dr9b6fsq.js.map → platform-Dw2gE3zI.js.map} +1 -1
- 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-C2WuC8SF.js +66 -0
- package/dist/plugin-C2WuC8SF.js.map +1 -0
- package/dist/plugin.es.mjs +9 -0
- package/dist/reactive/async-data.d.ts +28 -3
- package/dist/reactive/async-data.d.ts.map +1 -1
- package/dist/reactive/computed.d.ts +10 -0
- package/dist/reactive/computed.d.ts.map +1 -1
- package/dist/reactive/effect.d.ts +3 -0
- package/dist/reactive/effect.d.ts.map +1 -1
- package/dist/reactive/http.d.ts +194 -0
- package/dist/reactive/http.d.ts.map +1 -0
- package/dist/reactive/index.d.ts +2 -2
- package/dist/reactive/index.d.ts.map +1 -1
- package/dist/reactive/pagination.d.ts +126 -0
- package/dist/reactive/pagination.d.ts.map +1 -0
- package/dist/reactive/polling.d.ts +55 -0
- package/dist/reactive/polling.d.ts.map +1 -0
- package/dist/reactive/readonly.d.ts +20 -1
- package/dist/reactive/readonly.d.ts.map +1 -1
- package/dist/reactive/rest.d.ts +293 -0
- package/dist/reactive/rest.d.ts.map +1 -0
- package/dist/reactive/scope.d.ts +140 -0
- package/dist/reactive/scope.d.ts.map +1 -0
- package/dist/reactive/signal.d.ts +16 -2
- package/dist/reactive/signal.d.ts.map +1 -1
- package/dist/reactive/to-value.d.ts +57 -0
- package/dist/reactive/to-value.d.ts.map +1 -0
- package/dist/reactive/websocket.d.ts +285 -0
- package/dist/reactive/websocket.d.ts.map +1 -0
- package/dist/reactive-DwkhUJfP.js +1148 -0
- package/dist/reactive-DwkhUJfP.js.map +1 -0
- package/dist/reactive.es.mjs +38 -20
- package/dist/registry-B08iilIh.js +26 -0
- package/dist/registry-B08iilIh.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 +15 -7
- 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/state.d.ts +25 -2
- package/dist/router/state.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-CQikC9Ed.js +492 -0
- package/dist/router-CQikC9Ed.js.map +1 -0
- package/dist/router.es.mjs +14 -10
- package/dist/{sanitize-Bs2dkMby.js → sanitize-B1V4JswB.js} +2 -1
- package/dist/{sanitize-Bs2dkMby.js.map → sanitize-B1V4JswB.js.map} +1 -1
- package/dist/security/index.d.ts +2 -2
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security.es.mjs +1 -1
- 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-_dAcGdzu.js +248 -0
- package/dist/ssr-_dAcGdzu.js.map +1 -0
- package/dist/ssr.es.mjs +9 -0
- package/dist/store/create-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/persisted.d.ts +38 -4
- package/dist/store/persisted.d.ts.map +1 -1
- package/dist/store/types.d.ts +138 -1
- 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-Cb3gPRve.js +338 -0
- package/dist/store-Cb3gPRve.js.map +1 -0
- package/dist/store.es.mjs +11 -10
- package/dist/storybook/index.d.ts.map +1 -1
- package/dist/storybook.es.mjs +1 -1
- package/dist/storybook.es.mjs.map +1 -1
- 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-C5Sjfsna.js +224 -0
- package/dist/testing-C5Sjfsna.js.map +1 -0
- package/dist/testing.es.mjs +9 -0
- package/dist/type-guards-BMX2c0LP.js +44 -0
- package/dist/type-guards-BMX2c0LP.js.map +1 -0
- package/dist/untrack-D0fnO5k2.js +36 -0
- package/dist/untrack-D0fnO5k2.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 +9 -9
- package/package.json +47 -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 +599 -524
- package/src/component/html.ts +153 -153
- package/src/component/index.ts +52 -50
- package/src/component/library.ts +540 -518
- package/src/component/scope.ts +212 -0
- package/src/component/types.ts +310 -256
- package/src/core/collection.ts +249 -1
- package/src/core/element.ts +252 -11
- package/src/core/env.ts +60 -0
- package/src/core/index.ts +1 -0
- package/src/core/shared.ts +64 -0
- package/src/core/utils/index.ts +66 -1
- 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 +320 -0
- package/src/forms/index.ts +70 -0
- package/src/forms/types.ts +203 -0
- package/src/forms/use-field.ts +231 -0
- package/src/forms/validators.ts +294 -0
- package/src/full.ts +554 -229
- 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 +72 -0
- package/src/media/battery.ts +116 -0
- package/src/media/breakpoints.ts +129 -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 +11 -2
- package/src/motion/morph.ts +151 -0
- package/src/motion/parallax.ts +120 -0
- package/src/motion/reduced-motion.ts +52 -3
- package/src/motion/types.ts +63 -0
- package/src/motion/typewriter.ts +164 -0
- package/src/plugin/index.ts +37 -0
- package/src/plugin/registry.ts +284 -0
- package/src/plugin/types.ts +137 -0
- package/src/reactive/async-data.ts +250 -29
- package/src/reactive/computed.ts +53 -1
- package/src/reactive/effect.ts +29 -6
- package/src/reactive/http.ts +790 -0
- package/src/reactive/index.ts +60 -0
- package/src/reactive/pagination.ts +317 -0
- package/src/reactive/polling.ts +179 -0
- package/src/reactive/readonly.ts +52 -8
- package/src/reactive/rest.ts +859 -0
- package/src/reactive/scope.ts +276 -0
- package/src/reactive/signal.ts +61 -1
- package/src/reactive/to-value.ts +71 -0
- package/src/reactive/websocket.ts +849 -0
- package/src/router/bq-link.ts +279 -0
- package/src/router/constraints.ts +204 -0
- package/src/router/index.ts +15 -7
- package/src/router/match.ts +255 -49
- package/src/router/path-pattern.ts +52 -0
- package/src/router/query.ts +3 -0
- package/src/router/router.ts +258 -48
- package/src/router/state.ts +51 -3
- package/src/router/types.ts +50 -4
- package/src/router/use-route.ts +68 -0
- package/src/router/utils.ts +44 -3
- package/src/security/index.ts +12 -17
- package/src/security/sanitize.ts +70 -70
- package/src/security/trusted-html.ts +71 -71
- package/src/ssr/hydrate.ts +84 -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 +146 -8
- package/src/store/define-store.ts +49 -49
- package/src/store/index.ts +5 -0
- package/src/store/mapping.ts +74 -74
- package/src/store/persisted.ts +245 -62
- package/src/store/types.ts +247 -92
- package/src/store/utils.ts +4 -10
- package/src/store/watch.ts +53 -53
- package/src/storybook/index.ts +480 -479
- 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 +28 -0
- package/src/view/evaluate.ts +2 -0
- package/src/view/process.ts +19 -3
- package/dist/component-BEQgt5hl.js +0 -600
- package/dist/component-BEQgt5hl.js.map +0 -1
- package/dist/core-BGQJVw0-.js +0 -35
- package/dist/core-BGQJVw0-.js.map +0 -1
- package/dist/core-CCEabVHl.js.map +0 -1
- package/dist/effect-AFRW_Plg.js +0 -84
- package/dist/effect-AFRW_Plg.js.map +0 -1
- package/dist/motion-D9TcHxOF.js +0 -415
- package/dist/motion-D9TcHxOF.js.map +0 -1
- package/dist/reactive-DSkct0dO.js +0 -254
- package/dist/reactive-DSkct0dO.js.map +0 -1
- package/dist/router-CbDhl8rS.js +0 -188
- package/dist/router-CbDhl8rS.js.map +0 -1
- package/dist/store-BwDvI45q.js +0 -263
- package/dist/store-BwDvI45q.js.map +0 -1
- package/dist/untrack-B0rVscTc.js +0 -7
- package/dist/untrack-B0rVscTc.js.map +0 -1
- package/dist/view-C70lA3vf.js.map +0 -1
package/src/security/sanitize.ts
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Security utilities for HTML sanitization.
|
|
3
|
-
* All DOM writes are sanitized by default to prevent XSS attacks.
|
|
4
|
-
*
|
|
5
|
-
* @module bquery/security
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { sanitizeHtmlCore } from './sanitize-core';
|
|
9
|
-
import { toSanitizedHtml } from './trusted-html';
|
|
10
|
-
import type { SanitizedHtml } from './trusted-html';
|
|
11
|
-
import type { SanitizeOptions } from './types';
|
|
12
|
-
export { generateNonce } from './csp';
|
|
13
|
-
export { isTrustedTypesSupported } from './trusted-types';
|
|
14
|
-
export { trusted } from './trusted-html';
|
|
15
|
-
export type { SanitizedHtml, TrustedHtml } from './trusted-html';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Sanitize HTML string, removing dangerous elements and attributes.
|
|
19
|
-
* Uses Trusted Types when available for CSP compliance.
|
|
20
|
-
*
|
|
21
|
-
* @param html - The HTML string to sanitize
|
|
22
|
-
* @param options - Sanitization options
|
|
23
|
-
* @returns Sanitized HTML string
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* const safe = sanitizeHtml('<div onclick="alert(1)">Hello</div>');
|
|
28
|
-
* // Returns: '<div>Hello</div>'
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export const sanitizeHtml = (html: string, options: SanitizeOptions = {}): SanitizedHtml => {
|
|
32
|
-
return toSanitizedHtml(sanitizeHtmlCore(html, options));
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Escape HTML entities to prevent XSS.
|
|
37
|
-
* Use this for displaying user content as text.
|
|
38
|
-
*
|
|
39
|
-
* @param text - The text to escape
|
|
40
|
-
* @returns Escaped HTML string
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* escapeHtml('<script>alert(1)</script>');
|
|
45
|
-
* // Returns: '<script>alert(1)</script>'
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export const escapeHtml = (text: string): string => {
|
|
49
|
-
const escapeMap: Record<string, string> = {
|
|
50
|
-
'&': '&',
|
|
51
|
-
'<': '<',
|
|
52
|
-
'>': '>',
|
|
53
|
-
'"': '"',
|
|
54
|
-
"'": ''',
|
|
55
|
-
'`': '`',
|
|
56
|
-
};
|
|
57
|
-
return text.replace(/[&<>"'`]/g, (char) => escapeMap[char]);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Strip all HTML tags and return plain text.
|
|
62
|
-
*
|
|
63
|
-
* @param html - The HTML string to strip
|
|
64
|
-
* @returns Plain text content
|
|
65
|
-
*/
|
|
66
|
-
export const stripTags = (html: string): string => {
|
|
67
|
-
return sanitizeHtmlCore(html, { stripAllTags: true });
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export type { SanitizeOptions } from './types';
|
|
1
|
+
/**
|
|
2
|
+
* Security utilities for HTML sanitization.
|
|
3
|
+
* All DOM writes are sanitized by default to prevent XSS attacks.
|
|
4
|
+
*
|
|
5
|
+
* @module bquery/security
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { sanitizeHtmlCore } from './sanitize-core';
|
|
9
|
+
import { toSanitizedHtml } from './trusted-html';
|
|
10
|
+
import type { SanitizedHtml } from './trusted-html';
|
|
11
|
+
import type { SanitizeOptions } from './types';
|
|
12
|
+
export { generateNonce } from './csp';
|
|
13
|
+
export { isTrustedTypesSupported } from './trusted-types';
|
|
14
|
+
export { trusted } from './trusted-html';
|
|
15
|
+
export type { SanitizedHtml, TrustedHtml } from './trusted-html';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Sanitize HTML string, removing dangerous elements and attributes.
|
|
19
|
+
* Uses Trusted Types when available for CSP compliance.
|
|
20
|
+
*
|
|
21
|
+
* @param html - The HTML string to sanitize
|
|
22
|
+
* @param options - Sanitization options
|
|
23
|
+
* @returns Sanitized HTML string
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const safe = sanitizeHtml('<div onclick="alert(1)">Hello</div>');
|
|
28
|
+
* // Returns: '<div>Hello</div>'
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const sanitizeHtml = (html: string, options: SanitizeOptions = {}): SanitizedHtml => {
|
|
32
|
+
return toSanitizedHtml(sanitizeHtmlCore(html, options));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Escape HTML entities to prevent XSS.
|
|
37
|
+
* Use this for displaying user content as text.
|
|
38
|
+
*
|
|
39
|
+
* @param text - The text to escape
|
|
40
|
+
* @returns Escaped HTML string
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* escapeHtml('<script>alert(1)</script>');
|
|
45
|
+
* // Returns: '<script>alert(1)</script>'
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export const escapeHtml = (text: string): string => {
|
|
49
|
+
const escapeMap: Record<string, string> = {
|
|
50
|
+
'&': '&',
|
|
51
|
+
'<': '<',
|
|
52
|
+
'>': '>',
|
|
53
|
+
'"': '"',
|
|
54
|
+
"'": ''',
|
|
55
|
+
'`': '`',
|
|
56
|
+
};
|
|
57
|
+
return text.replace(/[&<>"'`]/g, (char) => escapeMap[char]);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Strip all HTML tags and return plain text.
|
|
62
|
+
*
|
|
63
|
+
* @param html - The HTML string to strip
|
|
64
|
+
* @returns Plain text content
|
|
65
|
+
*/
|
|
66
|
+
export const stripTags = (html: string): string => {
|
|
67
|
+
return sanitizeHtmlCore(html, { stripAllTags: true });
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type { SanitizeOptions } from './types';
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
declare const sanitizedHtmlBrand: unique symbol;
|
|
2
|
-
const trustedHtmlBrand: unique symbol = Symbol('bquery.trusted-html.brand');
|
|
3
|
-
const TRUSTED_HTML_VALUE = Symbol('bquery.trusted-html');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Branded HTML string produced by bQuery's sanitization or escaping template helpers.
|
|
7
|
-
*
|
|
8
|
-
* Values returned from {@link sanitizeHtml} carry sanitized markup. Values returned from
|
|
9
|
-
* {@link safeHtml} preserve the template's static markup while escaping normal interpolations
|
|
10
|
-
* and splicing {@link trusted} fragments verbatim. This brand is not intended for arbitrary
|
|
11
|
-
* strings or manual concatenation outside those helpers.
|
|
12
|
-
*/
|
|
13
|
-
export type SanitizedHtml = string & { readonly [sanitizedHtmlBrand]: true };
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Marker object that safeHtml can splice into templates without escaping again.
|
|
17
|
-
*/
|
|
18
|
-
export type TrustedHtml = { readonly [trustedHtmlBrand]: true; toString(): string };
|
|
19
|
-
|
|
20
|
-
type TrustedHtmlValue = TrustedHtml & { readonly [TRUSTED_HTML_VALUE]: string };
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Apply the internal {@link SanitizedHtml} brand to helper output.
|
|
24
|
-
*
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
export const toSanitizedHtml = (html: string): SanitizedHtml => html as SanitizedHtml;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Mark a sanitized HTML string for verbatim splicing into safeHtml templates.
|
|
31
|
-
*
|
|
32
|
-
* @param html - HTML previously produced by sanitizeHtml, safeHtml, or another trusted bQuery helper
|
|
33
|
-
* @returns Trusted HTML marker object for safeHtml interpolations
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* const badge = trusted(sanitizeHtml('<strong onclick="alert(1)">New</strong>'));
|
|
38
|
-
* const markup = safeHtml`<span>${badge}</span>`;
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export const trusted = (html: SanitizedHtml): TrustedHtml => {
|
|
42
|
-
const value = String(html);
|
|
43
|
-
return Object.freeze({
|
|
44
|
-
[trustedHtmlBrand]: true as const,
|
|
45
|
-
[TRUSTED_HTML_VALUE]: value,
|
|
46
|
-
toString: () => value,
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Check whether a value is a trusted HTML marker created by trusted().
|
|
52
|
-
*
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
export const isTrustedHtml = (value: unknown): value is TrustedHtml => {
|
|
56
|
-
return (
|
|
57
|
-
typeof value === 'object' &&
|
|
58
|
-
value !== null &&
|
|
59
|
-
trustedHtmlBrand in value &&
|
|
60
|
-
TRUSTED_HTML_VALUE in value
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Unwrap the raw HTML string stored inside a trusted HTML marker.
|
|
66
|
-
*
|
|
67
|
-
* @internal
|
|
68
|
-
*/
|
|
69
|
-
export const unwrapTrustedHtml = (value: TrustedHtml): string => {
|
|
70
|
-
return (value as TrustedHtmlValue)[TRUSTED_HTML_VALUE];
|
|
71
|
-
};
|
|
1
|
+
declare const sanitizedHtmlBrand: unique symbol;
|
|
2
|
+
const trustedHtmlBrand: unique symbol = Symbol('bquery.trusted-html.brand');
|
|
3
|
+
const TRUSTED_HTML_VALUE = Symbol('bquery.trusted-html');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Branded HTML string produced by bQuery's sanitization or escaping template helpers.
|
|
7
|
+
*
|
|
8
|
+
* Values returned from {@link sanitizeHtml} carry sanitized markup. Values returned from
|
|
9
|
+
* {@link safeHtml} preserve the template's static markup while escaping normal interpolations
|
|
10
|
+
* and splicing {@link trusted} fragments verbatim. This brand is not intended for arbitrary
|
|
11
|
+
* strings or manual concatenation outside those helpers.
|
|
12
|
+
*/
|
|
13
|
+
export type SanitizedHtml = string & { readonly [sanitizedHtmlBrand]: true };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Marker object that safeHtml can splice into templates without escaping again.
|
|
17
|
+
*/
|
|
18
|
+
export type TrustedHtml = { readonly [trustedHtmlBrand]: true; toString(): string };
|
|
19
|
+
|
|
20
|
+
type TrustedHtmlValue = TrustedHtml & { readonly [TRUSTED_HTML_VALUE]: string };
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Apply the internal {@link SanitizedHtml} brand to helper output.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export const toSanitizedHtml = (html: string): SanitizedHtml => html as SanitizedHtml;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Mark a sanitized HTML string for verbatim splicing into safeHtml templates.
|
|
31
|
+
*
|
|
32
|
+
* @param html - HTML previously produced by sanitizeHtml, safeHtml, or another trusted bQuery helper
|
|
33
|
+
* @returns Trusted HTML marker object for safeHtml interpolations
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const badge = trusted(sanitizeHtml('<strong onclick="alert(1)">New</strong>'));
|
|
38
|
+
* const markup = safeHtml`<span>${badge}</span>`;
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const trusted = (html: SanitizedHtml): TrustedHtml => {
|
|
42
|
+
const value = String(html);
|
|
43
|
+
return Object.freeze({
|
|
44
|
+
[trustedHtmlBrand]: true as const,
|
|
45
|
+
[TRUSTED_HTML_VALUE]: value,
|
|
46
|
+
toString: () => value,
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Check whether a value is a trusted HTML marker created by trusted().
|
|
52
|
+
*
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
export const isTrustedHtml = (value: unknown): value is TrustedHtml => {
|
|
56
|
+
return (
|
|
57
|
+
typeof value === 'object' &&
|
|
58
|
+
value !== null &&
|
|
59
|
+
trustedHtmlBrand in value &&
|
|
60
|
+
TRUSTED_HTML_VALUE in value
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Unwrap the raw HTML string stored inside a trusted HTML marker.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export const unwrapTrustedHtml = (value: TrustedHtml): string => {
|
|
70
|
+
return (value as TrustedHtmlValue)[TRUSTED_HTML_VALUE];
|
|
71
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hydration support for server-rendered DOM.
|
|
3
|
+
*
|
|
4
|
+
* Enables the client-side view system to reuse existing server-rendered DOM
|
|
5
|
+
* elements instead of re-rendering them, by attaching reactive bindings
|
|
6
|
+
* to the pre-existing DOM structure.
|
|
7
|
+
*
|
|
8
|
+
* @module bquery/ssr
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { BindingContext, MountOptions, View } from '../view/types';
|
|
12
|
+
import { mount } from '../view/mount';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Extended mount options that include hydration mode.
|
|
16
|
+
*/
|
|
17
|
+
export type HydrateMountOptions = MountOptions & {
|
|
18
|
+
/**
|
|
19
|
+
* When present, must be `true` so the mount operation reuses existing DOM elements
|
|
20
|
+
* instead of re-rendering them. Reactive bindings (effects) are
|
|
21
|
+
* still attached so the DOM updates reactively from that point on.
|
|
22
|
+
*
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
hydrate?: true;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Mounts a reactive view with optional hydration support.
|
|
30
|
+
*
|
|
31
|
+
* When `hydrate: true` is set, the existing server-rendered DOM is preserved
|
|
32
|
+
* and reactive bindings are attached on top. The DOM is NOT re-rendered;
|
|
33
|
+
* instead, effects begin tracking signals so future changes update the DOM.
|
|
34
|
+
*
|
|
35
|
+
* This is the client-side counterpart to `renderToString()`. The typical flow:
|
|
36
|
+
* 1. Server: `renderToString(template, data)` → send HTML to client
|
|
37
|
+
* 2. Client: `hydrateMount('#app', reactiveContext, { hydrate: true })`
|
|
38
|
+
*
|
|
39
|
+
* Under the hood, `hydrateMount` simply delegates to the standard `mount()`
|
|
40
|
+
* function. The `mount()` function already processes existing DOM elements
|
|
41
|
+
* and attaches reactive effects to them — it does not clear/replace content.
|
|
42
|
+
* The `hydrate` flag is a semantic marker indicating developer intent and
|
|
43
|
+
* ensures the existing DOM structure is preserved.
|
|
44
|
+
*
|
|
45
|
+
* @param selector - CSS selector or Element to hydrate
|
|
46
|
+
* @param context - Binding context with signals, computed values, and functions
|
|
47
|
+
* @param options - Mount options with `hydrate: true`
|
|
48
|
+
* @returns The mounted View instance
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { hydrateMount } from '@bquery/bquery/ssr';
|
|
53
|
+
* import { signal, computed } from '@bquery/bquery/reactive';
|
|
54
|
+
*
|
|
55
|
+
* // Server rendered:
|
|
56
|
+
* // <div id="app"><h1>Welcome</h1><p>Hello, World!</p></div>
|
|
57
|
+
*
|
|
58
|
+
* // Client hydration — attaches reactivity to existing DOM:
|
|
59
|
+
* const name = signal('World');
|
|
60
|
+
* const greeting = computed(() => `Hello, ${name.value}!`);
|
|
61
|
+
*
|
|
62
|
+
* const view = hydrateMount('#app', { name, greeting }, { hydrate: true });
|
|
63
|
+
*
|
|
64
|
+
* // Now updating `name.value` will reactively update the DOM
|
|
65
|
+
* name.value = 'Alice'; // <p> updates to "Hello, Alice!"
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export const hydrateMount = (
|
|
69
|
+
selector: string | Element,
|
|
70
|
+
context: BindingContext,
|
|
71
|
+
options: HydrateMountOptions = {}
|
|
72
|
+
): View => {
|
|
73
|
+
const { hydrate = true, ...mountOptions } = options;
|
|
74
|
+
|
|
75
|
+
if (!hydrate) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
'bQuery ssr: hydrateMount() requires { hydrate: true } when options are provided.'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Hydration uses the standard mount which processes existing DOM
|
|
82
|
+
// and attaches reactive effects without clearing content.
|
|
83
|
+
return mount(selector, context, mountOptions);
|
|
84
|
+
};
|
package/src/ssr/index.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSR / Pre-rendering module for bQuery.js.
|
|
3
|
+
*
|
|
4
|
+
* Provides server-side rendering, hydration, and store state serialization
|
|
5
|
+
* utilities for bQuery applications. Enables rendering bQuery templates
|
|
6
|
+
* to HTML strings on the server, serializing store state for client pickup,
|
|
7
|
+
* and hydrating the pre-rendered DOM on the client.
|
|
8
|
+
*
|
|
9
|
+
* ## Features
|
|
10
|
+
*
|
|
11
|
+
* - **`renderToString(template, data)`** — Server-side render a bQuery
|
|
12
|
+
* template to an `SSRResult` containing an `html` string with directive evaluation.
|
|
13
|
+
* - **`hydrateMount(selector, context, { hydrate: true })`** — Reuse
|
|
14
|
+
* existing server-rendered DOM and attach reactive bindings.
|
|
15
|
+
* - **`serializeStoreState(options?)`** — Serialize store state into a
|
|
16
|
+
* `<script>` tag for client-side pickup.
|
|
17
|
+
* - **`deserializeStoreState()`** — Read serialized state on the client.
|
|
18
|
+
* - **`hydrateStore(id, state)` / `hydrateStores(stateMap)`** — Apply
|
|
19
|
+
* server state to client stores.
|
|
20
|
+
*
|
|
21
|
+
* ## Usage
|
|
22
|
+
*
|
|
23
|
+
* ### Server
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { renderToString, serializeStoreState } from '@bquery/bquery/ssr';
|
|
26
|
+
*
|
|
27
|
+
* const { html } = renderToString(
|
|
28
|
+
* '<div id="app"><h1 bq-text="title"></h1></div>',
|
|
29
|
+
* { title: 'Welcome' }
|
|
30
|
+
* );
|
|
31
|
+
*
|
|
32
|
+
* const { scriptTag } = serializeStoreState();
|
|
33
|
+
*
|
|
34
|
+
* // Send to client: html + scriptTag
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* ### Client
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { hydrateMount, deserializeStoreState, hydrateStores } from '@bquery/bquery/ssr';
|
|
40
|
+
* import { signal } from '@bquery/bquery/reactive';
|
|
41
|
+
*
|
|
42
|
+
* // Restore store state from SSR
|
|
43
|
+
* const ssrState = deserializeStoreState();
|
|
44
|
+
* hydrateStores(ssrState);
|
|
45
|
+
*
|
|
46
|
+
* // Hydrate the DOM with reactive bindings
|
|
47
|
+
* const title = signal('Welcome');
|
|
48
|
+
* hydrateMount('#app', { title }, { hydrate: true });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @module bquery/ssr
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
export { hydrateMount } from './hydrate';
|
|
55
|
+
export type { HydrateMountOptions } from './hydrate';
|
|
56
|
+
export { renderToString } from './render';
|
|
57
|
+
export {
|
|
58
|
+
deserializeStoreState,
|
|
59
|
+
hydrateStore,
|
|
60
|
+
hydrateStores,
|
|
61
|
+
serializeStoreState,
|
|
62
|
+
} from './serialize';
|
|
63
|
+
export type { SerializeResult } from './serialize';
|
|
64
|
+
export type {
|
|
65
|
+
DeserializedStoreState,
|
|
66
|
+
HydrationOptions,
|
|
67
|
+
RenderOptions,
|
|
68
|
+
SSRResult,
|
|
69
|
+
SerializeOptions,
|
|
70
|
+
} from './types';
|