@supersoniks/concorde 4.9.98-visual-stack.1 → 4.9.98-visual-stack.3
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/.gitlab-ci.yml +0 -13
- package/build-infos.json +1 -1
- package/concorde-3d.bundle.js +1 -1
- package/concorde-3d.es.js +2 -2
- package/concorde-core.bundle.js +557 -622
- package/concorde-core.es.js +6025 -5575
- package/concorde-hugging-face-infer.bundle.js +1 -1
- package/concorde-hugging-face-infer.es.js +1 -1
- package/concorde-interactive.bundle.js +1162 -0
- package/concorde-interactive.es.js +10723 -0
- package/concorde-shader.bundle.js +1 -1
- package/concorde-shader.es.js +2 -2
- package/concorde-webgpu.bundle.js +1 -1
- package/concorde-webgpu.es.js +2 -2
- package/dist/concorde-3d.bundle.js +1 -1
- package/dist/concorde-3d.es.js +2 -2
- package/dist/concorde-core.bundle.js +557 -622
- package/dist/concorde-core.es.js +6025 -5575
- package/dist/concorde-hugging-face-infer.bundle.js +1 -1
- package/dist/concorde-hugging-face-infer.es.js +1 -1
- package/dist/concorde-interactive.bundle.js +1162 -0
- package/dist/concorde-interactive.es.js +10723 -0
- package/dist/concorde-shader.bundle.js +1 -1
- package/dist/concorde-shader.es.js +2 -2
- package/dist/concorde-webgpu.bundle.js +1 -1
- package/dist/concorde-webgpu.es.js +2 -2
- package/dist/docs-mock-api-sw.js +5 -1
- package/dist/docs-mock-api-sw.js.map +2 -2
- package/dist/js/addons/interactive.js +6 -0
- package/dist/js/addons/interactive.js.map +1 -0
- package/dist/js/core/components/functional/if/if.js +65 -7
- package/dist/js/core/components/functional/if/if.js.map +1 -1
- package/dist/js/core/components/functional/interactive/action.js +96 -0
- package/dist/js/core/components/functional/interactive/action.js.map +1 -0
- package/dist/js/core/components/functional/interactive/gamepad.js +206 -0
- package/dist/js/core/components/functional/interactive/gamepad.js.map +1 -0
- package/dist/js/core/components/functional/interactive/gesture.js +148 -0
- package/dist/js/core/components/functional/interactive/gesture.js.map +1 -0
- package/dist/js/core/components/functional/interactive/helpers.js +82 -0
- package/dist/js/core/components/functional/interactive/helpers.js.map +1 -0
- package/dist/js/core/components/functional/interactive/index.js +20 -0
- package/dist/js/core/components/functional/interactive/index.js.map +1 -0
- package/dist/js/core/components/functional/interactive/keyboard.js +183 -0
- package/dist/js/core/components/functional/interactive/keyboard.js.map +1 -0
- package/dist/js/core/components/functional/interactive/matrix.js +201 -0
- package/dist/js/core/components/functional/interactive/matrix.js.map +1 -0
- package/dist/js/core/components/functional/interactive/registry.js +28 -0
- package/dist/js/core/components/functional/interactive/registry.js.map +1 -0
- package/dist/js/core/components/functional/interactive/store.js +264 -0
- package/dist/js/core/components/functional/interactive/store.js.map +1 -0
- package/dist/js/core/components/functional/interactive/ticker.js +182 -0
- package/dist/js/core/components/functional/interactive/ticker.js.map +1 -0
- package/dist/js/core/components/functional/value/value.js +49 -4
- package/dist/js/core/components/functional/value/value.js.map +1 -1
- package/dist/js/core/components/ui/_css/rounded.js +34 -0
- package/dist/js/core/components/ui/_css/rounded.js.map +1 -0
- package/dist/js/core/components/ui/_css/type.js +44 -0
- package/dist/js/core/components/ui/_css/type.js.map +1 -1
- package/dist/js/core/components/ui/_i18n/ui-aria-labels.js +95 -0
- package/dist/js/core/components/ui/_i18n/ui-aria-labels.js.map +1 -0
- package/dist/js/core/components/ui/alert/alert.js +72 -87
- package/dist/js/core/components/ui/alert/alert.js.map +1 -1
- package/dist/js/core/components/ui/alert-messages/alert-messages.js +1 -0
- package/dist/js/core/components/ui/alert-messages/alert-messages.js.map +1 -1
- package/dist/js/core/components/ui/badge/badge.js +29 -80
- package/dist/js/core/components/ui/badge/badge.js.map +1 -1
- package/dist/js/core/components/ui/button/button.js +8 -7
- package/dist/js/core/components/ui/button/button.js.map +1 -1
- package/dist/js/core/components/ui/card/card-header.js +7 -2
- package/dist/js/core/components/ui/card/card-header.js.map +1 -1
- package/dist/js/core/components/ui/divider/divider.js +1 -1
- package/dist/js/core/components/ui/divider/divider.js.map +1 -1
- package/dist/js/core/components/ui/form/checkbox/checkbox.js +4 -20
- package/dist/js/core/components/ui/form/checkbox/checkbox.js.map +1 -1
- package/dist/js/core/components/ui/form/fieldset/legend-description.js +1 -1
- package/dist/js/core/components/ui/form/fieldset/legend.js +1 -1
- package/dist/js/core/components/ui/form/input/input.js +12 -15
- package/dist/js/core/components/ui/form/input/input.js.map +1 -1
- package/dist/js/core/components/ui/form/input-autocomplete/input-autocomplete.js +363 -158
- package/dist/js/core/components/ui/form/input-autocomplete/input-autocomplete.js.map +1 -1
- package/dist/js/core/components/ui/form/radio/radio.js +1 -1
- package/dist/js/core/components/ui/form/select/select.js +3 -6
- package/dist/js/core/components/ui/form/select/select.js.map +1 -1
- package/dist/js/core/components/ui/form/textarea/textarea.js +1 -2
- package/dist/js/core/components/ui/form/textarea/textarea.js.map +1 -1
- package/dist/js/core/components/ui/image/image.js +9 -37
- package/dist/js/core/components/ui/image/image.js.map +1 -1
- package/dist/js/core/components/ui/link/link.js +25 -26
- package/dist/js/core/components/ui/link/link.js.map +1 -1
- package/dist/js/core/components/ui/modal/modal-close.js +3 -12
- package/dist/js/core/components/ui/modal/modal-close.js.map +1 -1
- package/dist/js/core/components/ui/modal/modal.js +18 -18
- package/dist/js/core/components/ui/modal/modal.js.map +1 -1
- package/dist/js/core/components/ui/pop/pop.js +131 -112
- package/dist/js/core/components/ui/pop/pop.js.map +1 -1
- package/dist/js/core/components/ui/table/table.js.map +1 -1
- package/dist/js/core/components/ui/theme/theme.js +1 -1
- package/dist/js/core/components/ui/toast/dismissed.js +9 -0
- package/dist/js/core/components/ui/toast/dismissed.js.map +1 -0
- package/dist/js/core/components/ui/toast/render-content.js +14 -0
- package/dist/js/core/components/ui/toast/render-content.js.map +1 -0
- package/dist/js/core/components/ui/toast/toast-item.js +150 -96
- package/dist/js/core/components/ui/toast/toast-item.js.map +1 -1
- package/dist/js/core/components/ui/toast/toast.js +41 -13
- package/dist/js/core/components/ui/toast/toast.js.map +1 -1
- package/dist/js/core/components/ui/tooltip/tooltip.js +144 -143
- package/dist/js/core/components/ui/tooltip/tooltip.js.map +1 -1
- package/dist/js/core/decorators/subscriber/ancestorAttribute.js.map +1 -1
- package/dist/js/core/decorators/subscriber/derive.js +3 -1
- package/dist/js/core/decorators/subscriber/derive.js.map +1 -1
- package/dist/js/core/mixins/Fetcher.js.map +1 -1
- package/dist/js/core/mixins/FormCheckable.js +1 -8
- package/dist/js/core/mixins/FormCheckable.js.map +1 -1
- package/dist/js/core/mixins/FormElement.js +26 -53
- package/dist/js/core/mixins/FormElement.js.map +1 -1
- package/dist/js/core/utils/AncestorAttributeObserver.js +130 -55
- package/dist/js/core/utils/AncestorAttributeObserver.js.map +1 -1
- package/dist/js/core/utils/LocationHandler.js +1 -1
- package/dist/js/core/utils/LocationHandler.js.map +1 -1
- package/dist/js/core/utils/dismissed.js +23 -0
- package/dist/js/core/utils/dismissed.js.map +1 -0
- package/dist/js/core/utils/positioning.js +110 -0
- package/dist/js/core/utils/positioning.js.map +1 -0
- package/dist/js/directives.js +1 -2
- package/dist/js/directives.js.map +1 -1
- package/dist/types/addons/interactive.d.ts +6 -0
- package/dist/types/addons/interactive.d.ts.map +1 -0
- package/dist/types/core/components/functional/if/if.d.ts +14 -5
- package/dist/types/core/components/functional/if/if.d.ts.map +1 -1
- package/dist/types/core/components/functional/interactive/action.d.ts +22 -0
- package/dist/types/core/components/functional/interactive/action.d.ts.map +1 -0
- package/dist/types/core/components/functional/interactive/gamepad.d.ts +37 -0
- package/dist/types/core/components/functional/interactive/gamepad.d.ts.map +1 -0
- package/dist/types/core/components/functional/interactive/gesture.d.ts +26 -0
- package/dist/types/core/components/functional/interactive/gesture.d.ts.map +1 -0
- package/dist/types/core/components/functional/interactive/helpers.d.ts +23 -0
- package/dist/types/core/components/functional/interactive/helpers.d.ts.map +1 -0
- package/dist/types/core/components/functional/interactive/index.d.ts +20 -0
- package/dist/types/core/components/functional/interactive/index.d.ts.map +1 -0
- package/dist/types/core/components/functional/interactive/keyboard.d.ts +37 -0
- package/dist/types/core/components/functional/interactive/keyboard.d.ts.map +1 -0
- package/dist/types/core/components/functional/interactive/matrix.d.ts +31 -0
- package/dist/types/core/components/functional/interactive/matrix.d.ts.map +1 -0
- package/dist/types/core/components/functional/interactive/registry.d.ts +23 -0
- package/dist/types/core/components/functional/interactive/registry.d.ts.map +1 -0
- package/dist/types/core/components/functional/interactive/store.d.ts +46 -0
- package/dist/types/core/components/functional/interactive/store.d.ts.map +1 -0
- package/dist/types/core/components/functional/interactive/ticker.d.ts +33 -0
- package/dist/types/core/components/functional/interactive/ticker.d.ts.map +1 -0
- package/dist/types/core/components/functional/value/value.d.ts +6 -0
- package/dist/types/core/components/functional/value/value.d.ts.map +1 -1
- package/dist/types/core/components/ui/_css/rounded.d.ts +3 -0
- package/dist/types/core/components/ui/_css/rounded.d.ts.map +1 -0
- package/dist/types/core/components/ui/_css/type.d.ts +13 -0
- package/dist/types/core/components/ui/_css/type.d.ts.map +1 -1
- package/dist/types/core/components/ui/_i18n/ui-aria-labels.d.ts +83 -0
- package/dist/types/core/components/ui/_i18n/ui-aria-labels.d.ts.map +1 -0
- package/dist/types/core/components/ui/alert/alert.d.ts +14 -12
- package/dist/types/core/components/ui/alert/alert.d.ts.map +1 -1
- package/dist/types/core/components/ui/alert-messages/alert-messages.d.ts.map +1 -1
- package/dist/types/core/components/ui/badge/badge.d.ts +1 -1
- package/dist/types/core/components/ui/badge/badge.d.ts.map +1 -1
- package/dist/types/core/components/ui/button/button.d.ts +13 -29
- package/dist/types/core/components/ui/button/button.d.ts.map +1 -1
- package/dist/types/core/components/ui/card/card-header.d.ts.map +1 -1
- package/dist/types/core/components/ui/divider/divider.d.ts +2 -1
- package/dist/types/core/components/ui/divider/divider.d.ts.map +1 -1
- package/dist/types/core/components/ui/form/checkbox/checkbox.d.ts +25 -73
- package/dist/types/core/components/ui/form/checkbox/checkbox.d.ts.map +1 -1
- package/dist/types/core/components/ui/form/input/input.d.ts +14 -29
- package/dist/types/core/components/ui/form/input/input.d.ts.map +1 -1
- package/dist/types/core/components/ui/form/input-autocomplete/input-autocomplete.d.ts +63 -65
- package/dist/types/core/components/ui/form/input-autocomplete/input-autocomplete.d.ts.map +1 -1
- package/dist/types/core/components/ui/form/radio/radio.d.ts +1 -1
- package/dist/types/core/components/ui/form/select/select.d.ts +3 -5
- package/dist/types/core/components/ui/form/select/select.d.ts.map +1 -1
- package/dist/types/core/components/ui/form/textarea/textarea.d.ts +12 -28
- package/dist/types/core/components/ui/form/textarea/textarea.d.ts.map +1 -1
- package/dist/types/core/components/ui/image/image.d.ts +2 -1
- package/dist/types/core/components/ui/image/image.d.ts.map +1 -1
- package/dist/types/core/components/ui/link/link.d.ts +10 -9
- package/dist/types/core/components/ui/link/link.d.ts.map +1 -1
- package/dist/types/core/components/ui/modal/modal-close.d.ts +2 -2
- package/dist/types/core/components/ui/modal/modal-close.d.ts.map +1 -1
- package/dist/types/core/components/ui/pop/pop.d.ts +12 -4
- package/dist/types/core/components/ui/pop/pop.d.ts.map +1 -1
- package/dist/types/core/components/ui/table/table.d.ts +2 -1
- package/dist/types/core/components/ui/table/table.d.ts.map +1 -1
- package/dist/types/core/components/ui/toast/dismissed.d.ts +3 -0
- package/dist/types/core/components/ui/toast/dismissed.d.ts.map +1 -0
- package/dist/types/core/components/ui/toast/render-content.d.ts +7 -0
- package/dist/types/core/components/ui/toast/render-content.d.ts.map +1 -0
- package/dist/types/core/components/ui/toast/toast-item.d.ts +26 -9
- package/dist/types/core/components/ui/toast/toast-item.d.ts.map +1 -1
- package/dist/types/core/components/ui/toast/toast.d.ts +6 -3
- package/dist/types/core/components/ui/toast/toast.d.ts.map +1 -1
- package/dist/types/core/components/ui/toast/types.d.ts +12 -2
- package/dist/types/core/components/ui/toast/types.d.ts.map +1 -1
- package/dist/types/core/components/ui/tooltip/tooltip.d.ts +19 -11
- package/dist/types/core/components/ui/tooltip/tooltip.d.ts.map +1 -1
- package/dist/types/core/decorators/subscriber/ancestorAttribute.d.ts +3 -4
- package/dist/types/core/decorators/subscriber/ancestorAttribute.d.ts.map +1 -1
- package/dist/types/core/decorators/subscriber/derive.d.ts.map +1 -1
- package/dist/types/core/mixins/FormCheckable.d.ts +10 -27
- package/dist/types/core/mixins/FormCheckable.d.ts.map +1 -1
- package/dist/types/core/mixins/FormElement.d.ts +21 -10
- package/dist/types/core/mixins/FormElement.d.ts.map +1 -1
- package/dist/types/core/mixins/FormInput.d.ts +11 -27
- package/dist/types/core/mixins/FormInput.d.ts.map +1 -1
- package/dist/types/core/utils/AncestorAttributeObserver.d.ts +17 -9
- package/dist/types/core/utils/AncestorAttributeObserver.d.ts.map +1 -1
- package/dist/types/core/utils/LocationHandler.d.ts +3 -2
- package/dist/types/core/utils/LocationHandler.d.ts.map +1 -1
- package/dist/types/core/utils/dismissed.d.ts +3 -0
- package/dist/types/core/utils/dismissed.d.ts.map +1 -0
- package/dist/types/core/utils/positioning.d.ts +44 -0
- package/dist/types/core/utils/positioning.d.ts.map +1 -0
- package/dist/types/directives.d.ts +1 -3
- package/dist/types/directives.d.ts.map +1 -1
- package/dist/types/mixins.d.ts +22 -55
- package/dist/types/mixins.d.ts.map +1 -1
- package/docs/assets/{index-FmK4JaIM.js → index-D8MVWqY6.js} +946 -687
- package/docs/assets/index-DiD0qYvE.css +1 -0
- package/docs/crawl/core/components/ui/form/input-autocomplete/input-autocomplete.html +17 -85
- package/docs/crawl/docs/_misc/formelement-subscriber-removal.html +1 -1
- package/docs/crawl/hubs/form-components.html +13 -11
- package/docs/docs-mock-api-sw.js +5 -1
- package/docs/docs-mock-api-sw.js.map +2 -2
- package/docs/index.html +2 -2
- package/docs/llms-full.txt +12 -38
- package/docs/llms.txt +1 -1
- package/docs/src/core/components/functional/sdui/sdui.md +0 -0
- package/docs/src/core/components/ui/form/checkbox/checkbox.md +0 -0
- package/docs/src/core/components/ui/form/input-autocomplete/input-autocomplete.md +14 -118
- package/docs/src/docs/_getting-started/create-a-component.md +0 -0
- package/docs/src/docs/_misc/formelement-subscriber-removal.md +1 -1
- package/docs/src/docs/search/docs-search.json +195 -200
- package/docs/src/tsconfig.json +324 -0
- package/gitlab/job_tests.sh +25 -12
- package/index.html +3 -3
- package/package.json +182 -10
- package/public/docs-mock-api-sw.js +5 -1
- package/public/docs-mock-api-sw.js.map +2 -2
- package/scripts/build-addons.mjs +2 -2
- package/scripts/post-build.mjs +9 -0
- package/src/addons/interactive.ts +5 -0
- package/src/core/components/functional/if/if.ts +54 -7
- package/src/core/components/functional/interactive/action.ts +84 -0
- package/src/core/components/functional/interactive/gamepad.ts +197 -0
- package/src/core/components/functional/interactive/gesture.ts +136 -0
- package/src/core/components/functional/interactive/helpers.spec.ts +50 -0
- package/src/core/components/functional/interactive/helpers.ts +97 -0
- package/src/core/components/functional/interactive/index.ts +25 -0
- package/src/core/components/functional/interactive/interactive.md +33 -0
- package/src/core/components/functional/interactive/keyboard.ts +171 -0
- package/src/core/components/functional/interactive/matrix.ts +185 -0
- package/src/core/components/functional/interactive/registry.ts +46 -0
- package/src/core/components/functional/interactive/store.ts +270 -0
- package/src/core/components/functional/interactive/ticker.ts +171 -0
- package/src/core/components/functional/list/list.ts +0 -0
- package/src/core/components/functional/subscriber/subscriber.ts +0 -0
- package/src/core/components/functional/value/value.ts +44 -4
- package/src/core/components/ui/_css/rounded.ts +36 -0
- package/src/core/components/ui/_css/type.ts +49 -0
- package/src/core/components/ui/_i18n/ui-aria-labels.ts +104 -0
- package/src/core/components/ui/alert/alert.md +128 -72
- package/src/core/components/ui/alert/alert.spec.ts +145 -0
- package/src/core/components/ui/alert/alert.ts +86 -91
- package/src/core/components/ui/alert-messages/alert-messages.ts +1 -1
- package/src/core/components/ui/badge/badge.md +126 -78
- package/src/core/components/ui/badge/badge.ts +29 -81
- package/src/core/components/ui/button/button.md +1 -0
- package/src/core/components/ui/button/button.ts +12 -10
- package/src/core/components/ui/card/card-header.ts +7 -2
- package/src/core/components/ui/card/card.md +120 -65
- package/src/core/components/ui/divider/divider.ts +4 -9
- package/src/core/components/ui/form/checkbox/checkbox.md +1 -1
- package/src/core/components/ui/form/checkbox/checkbox.ts +4 -20
- package/src/core/components/ui/form/fieldset/legend-description.ts +1 -1
- package/src/core/components/ui/form/fieldset/legend.ts +1 -1
- package/src/core/components/ui/form/input/input.md +1 -1
- package/src/core/components/ui/form/input/input.ts +25 -27
- package/src/core/components/ui/form/input-autocomplete/input-autocomplete.md +14 -118
- package/src/core/components/ui/form/input-autocomplete/input-autocomplete.ts +419 -187
- package/src/core/components/ui/form/radio/radio.ts +1 -1
- package/src/core/components/ui/form/select/select.ts +3 -6
- package/src/core/components/ui/form/textarea/textarea.md +1 -1
- package/src/core/components/ui/form/textarea/textarea.ts +1 -2
- package/src/core/components/ui/image/image.md +147 -53
- package/src/core/components/ui/image/image.ts +10 -44
- package/src/core/components/ui/link/link.md +2 -2
- package/src/core/components/ui/link/link.ts +42 -37
- package/src/core/components/ui/modal/modal-close.ts +8 -12
- package/src/core/components/ui/modal/modal.ts +18 -18
- package/src/core/components/ui/pop/pop.md +105 -1
- package/src/core/components/ui/pop/pop.ts +145 -141
- package/src/core/components/ui/table/table.ts +2 -8
- package/src/core/components/ui/theme/theme.ts +1 -1
- package/src/core/components/ui/toast/dismissed.ts +14 -0
- package/src/core/components/ui/toast/render-content.ts +13 -0
- package/src/core/components/ui/toast/toast-item.ts +179 -103
- package/src/core/components/ui/toast/toast.ts +58 -21
- package/src/core/components/ui/toast/types.ts +14 -2
- package/src/core/components/ui/tooltip/tooltip.ts +176 -154
- package/src/core/decorators/subscriber/ancestorAttribute.spec.ts +26 -0
- package/src/core/decorators/subscriber/ancestorAttribute.ts +3 -4
- package/src/core/decorators/subscriber/derive.ts +3 -3
- package/src/core/mixins/Fetcher.ts +1 -1
- package/src/core/mixins/FormCheckable.ts +1 -8
- package/src/core/mixins/FormElement.ts +74 -76
- package/src/core/mixins/Subscriber.ts +5 -1
- package/src/core/utils/AncestorAttributeObserver.ts +183 -70
- package/src/core/utils/DataBindObserver.ts +0 -0
- package/src/core/utils/LocationHandler.ts +12 -5
- package/src/core/utils/Objects.ts +0 -0
- package/src/core/utils/dismissed.ts +22 -0
- package/src/core/utils/positioning.spec.ts +208 -0
- package/src/core/utils/positioning.ts +183 -0
- package/src/directives.ts +1 -3
- package/src/docs/_core-concept/dataFlow.md +1 -1
- package/src/docs/_decorators/ancestor-attribute.md +3 -2
- package/src/docs/_getting-started/cdn-addons.md +1 -0
- package/src/docs/_getting-started/concorde-outside.md +3 -3
- package/src/docs/_misc/formelement-subscriber-removal.md +115 -0
- package/src/docs/_misc/html-integration.md +2 -0
- package/src/docs/code.ts +3 -1
- package/src/docs/components/docs-demo-sources.ts +60 -0
- package/src/docs/docs.ts +1 -0
- package/src/docs/example/docs-input-autocomplete-demos.ts +110 -0
- package/src/docs/mock-api/router.ts +17 -1
- package/src/docs/navigation/navigation.ts +8 -0
- package/src/docs/search/docs-search.json +956 -243
- package/src/docs/tailwind/css/tailwind.css +13 -6
- package/src/tsconfig.json +135 -6
- package/src/tsconfig.tsbuildinfo +1 -1
- package/tailwind.config.js +50 -3
- package/vite/config.js +23 -35
- package/vite.config.mts +5 -0
- package/vitest.setup.ts +49 -13
- package/docs/assets/index-BZiZXMU-.css +0 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { LitElement, css, html } from "lit";
|
|
2
|
+
import { customElement, property } from "lit/decorators.js";
|
|
3
|
+
import { dispatch, type SonicActionMessage } from "./registry";
|
|
4
|
+
|
|
5
|
+
const tagName = "sonic-keyboard";
|
|
6
|
+
|
|
7
|
+
type KeymapValue = string | { type: string; payload?: unknown };
|
|
8
|
+
type Keymap = Record<string, KeymapValue>;
|
|
9
|
+
type RepeatCfg = Record<string, [number, number]>;
|
|
10
|
+
type HeldKey = { type: string; payload?: unknown; timer?: number; interval?: number };
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Source d’actions clavier → store (`target`).
|
|
14
|
+
* Opt-in `@supersoniks/concorde/interactive`.
|
|
15
|
+
*/
|
|
16
|
+
@customElement(tagName)
|
|
17
|
+
export class SonicKeyboard extends LitElement {
|
|
18
|
+
static styles = css`
|
|
19
|
+
:host {
|
|
20
|
+
display: contents;
|
|
21
|
+
}
|
|
22
|
+
:host([scope="focus"]) {
|
|
23
|
+
display: block;
|
|
24
|
+
outline: none;
|
|
25
|
+
}
|
|
26
|
+
:host([scope="focus"]:focus) {
|
|
27
|
+
outline: 2px solid var(--sc-primary, #3b82f6);
|
|
28
|
+
outline-offset: 2px;
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
@property({ type: String })
|
|
33
|
+
target = "";
|
|
34
|
+
|
|
35
|
+
@property({ type: Object })
|
|
36
|
+
keymap: Keymap = {};
|
|
37
|
+
|
|
38
|
+
/** `document` | `focus` */
|
|
39
|
+
@property({ type: String })
|
|
40
|
+
scope: "document" | "focus" = "document";
|
|
41
|
+
|
|
42
|
+
/** `{ "left": [delayMs, intervalMs] }` */
|
|
43
|
+
@property({ type: Object })
|
|
44
|
+
repeat: RepeatCfg = {};
|
|
45
|
+
|
|
46
|
+
@property({ type: Boolean })
|
|
47
|
+
keyup = false;
|
|
48
|
+
|
|
49
|
+
@property({ type: Boolean, attribute: "dispatch-event" })
|
|
50
|
+
dispatchEventFlag = false;
|
|
51
|
+
|
|
52
|
+
private held = new Map<string, HeldKey>();
|
|
53
|
+
|
|
54
|
+
connectedCallback(): void {
|
|
55
|
+
super.connectedCallback();
|
|
56
|
+
if (this.scope === "focus") {
|
|
57
|
+
if (!this.hasAttribute("tabindex")) this.tabIndex = 0;
|
|
58
|
+
}
|
|
59
|
+
this.bindTarget().addEventListener("keydown", this.onKeyDown);
|
|
60
|
+
this.bindTarget().addEventListener("keyup", this.onKeyUp);
|
|
61
|
+
window.addEventListener("blur", this.releaseAll);
|
|
62
|
+
document.addEventListener("visibilitychange", this.onVis);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
disconnectedCallback(): void {
|
|
66
|
+
this.bindTarget().removeEventListener("keydown", this.onKeyDown);
|
|
67
|
+
this.bindTarget().removeEventListener("keyup", this.onKeyUp);
|
|
68
|
+
window.removeEventListener("blur", this.releaseAll);
|
|
69
|
+
document.removeEventListener("visibilitychange", this.onVis);
|
|
70
|
+
this.releaseAll();
|
|
71
|
+
super.disconnectedCallback();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
protected updated(changed: Map<string | number | symbol, unknown>): void {
|
|
75
|
+
if (changed.has("scope")) {
|
|
76
|
+
// rebind would need disconnect/connect; keep simple: focus ring attrs
|
|
77
|
+
if (this.scope === "focus" && !this.hasAttribute("tabindex")) this.tabIndex = 0;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private bindTarget(): EventTarget {
|
|
82
|
+
return this.scope === "focus" ? this : window;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private onVis = () => {
|
|
86
|
+
if (document.hidden) this.releaseAll();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
private onKeyDown = (ev: Event) => {
|
|
90
|
+
const e = ev as KeyboardEvent;
|
|
91
|
+
if (e.repeat) return; // handled via our DAS/ARR
|
|
92
|
+
if (this.isEditableTarget(e.target)) return;
|
|
93
|
+
const code = e.code || e.key;
|
|
94
|
+
const mapped = this.keymap?.[code] ?? this.keymap?.[e.key];
|
|
95
|
+
if (!mapped) return;
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
const action = this.toAction(mapped);
|
|
98
|
+
this.emit(action);
|
|
99
|
+
const rep = this.repeat?.[action.type];
|
|
100
|
+
if (rep) {
|
|
101
|
+
const [delay, interval] = rep;
|
|
102
|
+
const entry: HeldKey = {
|
|
103
|
+
type: action.type,
|
|
104
|
+
payload: action.payload,
|
|
105
|
+
timer: window.setTimeout(() => {
|
|
106
|
+
this.emit({ type: action.type, payload: action.payload });
|
|
107
|
+
entry.interval = window.setInterval(() => {
|
|
108
|
+
this.emit({ type: action.type, payload: action.payload });
|
|
109
|
+
}, Math.max(16, interval));
|
|
110
|
+
}, Math.max(0, delay)),
|
|
111
|
+
};
|
|
112
|
+
this.held.set(code, entry);
|
|
113
|
+
} else {
|
|
114
|
+
this.held.set(code, { type: action.type, payload: action.payload });
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
private onKeyUp = (ev: Event) => {
|
|
119
|
+
const e = ev as KeyboardEvent;
|
|
120
|
+
const code = e.code || e.key;
|
|
121
|
+
const held = this.held.get(code);
|
|
122
|
+
if (held) {
|
|
123
|
+
if (held.timer) clearTimeout(held.timer);
|
|
124
|
+
if (held.interval) clearInterval(held.interval);
|
|
125
|
+
this.held.delete(code);
|
|
126
|
+
if (this.keyup) {
|
|
127
|
+
this.emit({ type: `${held.type}:up`, payload: held.payload });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
private releaseAll = () => {
|
|
133
|
+
for (const [, held] of this.held) {
|
|
134
|
+
if (held.timer) clearTimeout(held.timer);
|
|
135
|
+
if (held.interval) clearInterval(held.interval);
|
|
136
|
+
}
|
|
137
|
+
this.held.clear();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
private isEditableTarget(t: EventTarget | null): boolean {
|
|
141
|
+
if (!(t instanceof HTMLElement)) return false;
|
|
142
|
+
const tag = t.tagName;
|
|
143
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
144
|
+
if (t.isContentEditable) return true;
|
|
145
|
+
return Boolean(t.closest("input,textarea,select,[contenteditable=true]"));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private toAction(mapped: KeymapValue): SonicActionMessage {
|
|
149
|
+
if (typeof mapped === "string") return { type: mapped };
|
|
150
|
+
return { type: mapped.type, payload: mapped.payload };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private emit(action: SonicActionMessage): void {
|
|
154
|
+
if (this.target) dispatch(this.target, action);
|
|
155
|
+
if (this.dispatchEventFlag) {
|
|
156
|
+
this.dispatchEvent(
|
|
157
|
+
new CustomEvent("sonic-action", {
|
|
158
|
+
detail: action,
|
|
159
|
+
bubbles: true,
|
|
160
|
+
composed: true,
|
|
161
|
+
}),
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
render() {
|
|
167
|
+
return this.scope === "focus" ? html`<slot></slot>` : html``;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export default SonicKeyboard;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { LitElement, css, html } from "lit";
|
|
2
|
+
import { customElement, property, query } from "lit/decorators.js";
|
|
3
|
+
import { Subscriber } from "@supersoniks/concorde/mixins";
|
|
4
|
+
|
|
5
|
+
const tagName = "sonic-matrix";
|
|
6
|
+
|
|
7
|
+
type Palette = Record<string, string>;
|
|
8
|
+
|
|
9
|
+
function pathGet(obj: unknown, path: string): unknown {
|
|
10
|
+
if (!path) return obj;
|
|
11
|
+
let cur: any = obj;
|
|
12
|
+
for (const p of path.split(".").filter(Boolean)) {
|
|
13
|
+
if (cur == null) return undefined;
|
|
14
|
+
cur = cur[p];
|
|
15
|
+
}
|
|
16
|
+
return cur;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Rendu canvas d’une grille 2D (number[][] ou flat + cols) depuis dataProvider.
|
|
21
|
+
*/
|
|
22
|
+
@customElement(tagName)
|
|
23
|
+
export class SonicMatrix extends Subscriber(LitElement) {
|
|
24
|
+
static styles = css`
|
|
25
|
+
:host {
|
|
26
|
+
display: block;
|
|
27
|
+
width: 100%;
|
|
28
|
+
max-width: 100%;
|
|
29
|
+
line-height: 0;
|
|
30
|
+
}
|
|
31
|
+
canvas {
|
|
32
|
+
display: block;
|
|
33
|
+
width: 100%;
|
|
34
|
+
height: auto;
|
|
35
|
+
image-rendering: pixelated;
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
/** Clé vers la matrice dans le DP. */
|
|
40
|
+
@property({ type: String })
|
|
41
|
+
key = "grid";
|
|
42
|
+
|
|
43
|
+
@property({ type: Number })
|
|
44
|
+
cols = 0;
|
|
45
|
+
|
|
46
|
+
@property({ type: Object })
|
|
47
|
+
palette: Palette = {
|
|
48
|
+
"0": "transparent",
|
|
49
|
+
"1": "#00f0f0",
|
|
50
|
+
"2": "#0000f0",
|
|
51
|
+
"3": "#f0a000",
|
|
52
|
+
"4": "#f0f000",
|
|
53
|
+
"5": "#00f000",
|
|
54
|
+
"6": "#a000f0",
|
|
55
|
+
"7": "#f00000",
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** Taille cellule px, ou `auto`. */
|
|
59
|
+
@property({ type: String })
|
|
60
|
+
cell = "24";
|
|
61
|
+
|
|
62
|
+
@property({ type: Number })
|
|
63
|
+
gap = 1;
|
|
64
|
+
|
|
65
|
+
@property({ type: Number })
|
|
66
|
+
radius = 2;
|
|
67
|
+
|
|
68
|
+
/** Clé couche fantôme optionnelle. */
|
|
69
|
+
@property({ type: String, attribute: "ghost-key" })
|
|
70
|
+
ghostKey = "";
|
|
71
|
+
|
|
72
|
+
@property({ type: String, attribute: "label-key" })
|
|
73
|
+
labelKey = "";
|
|
74
|
+
|
|
75
|
+
@query("canvas") private canvas!: HTMLCanvasElement;
|
|
76
|
+
|
|
77
|
+
private lastSig = "";
|
|
78
|
+
|
|
79
|
+
connectedCallback(): void {
|
|
80
|
+
super.connectedCallback();
|
|
81
|
+
this.setAttribute("role", "img");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected updated(): void {
|
|
85
|
+
this.draw();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private readGrid(): number[][] {
|
|
89
|
+
const props = this.props as Record<string, unknown> | undefined;
|
|
90
|
+
const raw = props ? pathGet(props, this.key) : undefined;
|
|
91
|
+
if (Array.isArray(raw) && Array.isArray(raw[0])) {
|
|
92
|
+
return raw as number[][];
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(raw) && this.cols > 0) {
|
|
95
|
+
const flat = raw as number[];
|
|
96
|
+
const out: number[][] = [];
|
|
97
|
+
for (let i = 0; i < flat.length; i += this.cols) {
|
|
98
|
+
out.push(flat.slice(i, i + this.cols).map((n) => Number(n) || 0));
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private readGhost(): number[][] | null {
|
|
106
|
+
if (!this.ghostKey) return null;
|
|
107
|
+
const props = this.props as Record<string, unknown> | undefined;
|
|
108
|
+
const raw = props ? pathGet(props, this.ghostKey) : undefined;
|
|
109
|
+
if (Array.isArray(raw) && Array.isArray(raw[0])) return raw as number[][];
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private colorFor(v: number, ghost = false): string {
|
|
114
|
+
const c = this.palette?.[String(v)] ?? this.palette?.[v] ?? "#888";
|
|
115
|
+
if (!ghost) return c;
|
|
116
|
+
if (c === "transparent") return c;
|
|
117
|
+
return c.startsWith("var(") ? c : `${c}66`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private draw(): void {
|
|
121
|
+
const grid = this.readGrid();
|
|
122
|
+
const ghost = this.readGhost();
|
|
123
|
+
const h = grid.length;
|
|
124
|
+
const w = h ? grid[0].length : 0;
|
|
125
|
+
if (!w || !h || !this.canvas) return;
|
|
126
|
+
|
|
127
|
+
const sig = JSON.stringify({ grid, ghost, palette: this.palette, cell: this.cell, gap: this.gap });
|
|
128
|
+
if (sig === this.lastSig) return;
|
|
129
|
+
this.lastSig = sig;
|
|
130
|
+
|
|
131
|
+
const hostW = this.clientWidth || w * 24;
|
|
132
|
+
const cellPx =
|
|
133
|
+
this.cell === "auto" ? Math.max(1, Math.floor(hostW / w)) : Math.max(1, Number(this.cell) || 24);
|
|
134
|
+
const gap = Math.max(0, this.gap);
|
|
135
|
+
const dpr = Math.min(2, window.devicePixelRatio || 1);
|
|
136
|
+
const cssW = w * cellPx;
|
|
137
|
+
const cssH = h * cellPx;
|
|
138
|
+
this.canvas.width = Math.floor(cssW * dpr);
|
|
139
|
+
this.canvas.height = Math.floor(cssH * dpr);
|
|
140
|
+
this.canvas.style.width = `${cssW}px`;
|
|
141
|
+
this.canvas.style.height = `${cssH}px`;
|
|
142
|
+
const ctx = this.canvas.getContext("2d");
|
|
143
|
+
if (!ctx) return;
|
|
144
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
145
|
+
ctx.clearRect(0, 0, cssW, cssH);
|
|
146
|
+
|
|
147
|
+
const paint = (mat: number[][], ghostLayer: boolean) => {
|
|
148
|
+
for (let y = 0; y < mat.length; y++) {
|
|
149
|
+
const row = mat[y];
|
|
150
|
+
for (let x = 0; x < row.length; x++) {
|
|
151
|
+
const v = Number(row[x]) || 0;
|
|
152
|
+
if (!v && !ghostLayer) continue;
|
|
153
|
+
if (!v) continue;
|
|
154
|
+
ctx.fillStyle = this.colorFor(v, ghostLayer);
|
|
155
|
+
const px = x * cellPx + gap;
|
|
156
|
+
const py = y * cellPx + gap;
|
|
157
|
+
const s = cellPx - gap * 2;
|
|
158
|
+
if (this.radius > 0) {
|
|
159
|
+
const r = Math.min(this.radius, s / 2);
|
|
160
|
+
ctx.beginPath();
|
|
161
|
+
ctx.roundRect(px, py, s, s, r);
|
|
162
|
+
ctx.fill();
|
|
163
|
+
} else {
|
|
164
|
+
ctx.fillRect(px, py, s, s);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
if (ghost) paint(ghost, true);
|
|
171
|
+
paint(grid, false);
|
|
172
|
+
|
|
173
|
+
if (this.labelKey) {
|
|
174
|
+
const props = this.props as Record<string, unknown> | undefined;
|
|
175
|
+
const label = props ? pathGet(props, this.labelKey) : undefined;
|
|
176
|
+
if (label != null) this.setAttribute("aria-label", String(label));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
render() {
|
|
181
|
+
return html`<canvas></canvas>`;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export default SonicMatrix;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registre global des sonic-store + dispatch typé.
|
|
3
|
+
* Utilisé par keyboard / gamepad / gesture / action / ticker.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type SonicActionMessage = {
|
|
7
|
+
type: string;
|
|
8
|
+
payload?: unknown;
|
|
9
|
+
t?: number;
|
|
10
|
+
dt?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type StoreHandle = {
|
|
14
|
+
id: string;
|
|
15
|
+
dispatch: (action: SonicActionMessage) => void;
|
|
16
|
+
getState: () => unknown;
|
|
17
|
+
reset: () => void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const stores = new Map<string, StoreHandle>();
|
|
21
|
+
|
|
22
|
+
export function registerStore(handle: StoreHandle): void {
|
|
23
|
+
stores.set(handle.id, handle);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function unregisterStore(id: string): void {
|
|
27
|
+
stores.delete(id);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getStore(id: string): StoreHandle | undefined {
|
|
31
|
+
return stores.get(id);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Dispatch une action vers un store enregistré. No-op si absent. */
|
|
35
|
+
export function dispatch(storeId: string, action: SonicActionMessage): void {
|
|
36
|
+
const store = stores.get(storeId);
|
|
37
|
+
if (!store) return;
|
|
38
|
+
store.dispatch({
|
|
39
|
+
...action,
|
|
40
|
+
t: action.t ?? performance.now(),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function listStoreIds(): string[] {
|
|
45
|
+
return [...stores.keys()];
|
|
46
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { LitElement, css, html } from "lit";
|
|
2
|
+
import { customElement, property } from "lit/decorators.js";
|
|
3
|
+
import jsonata from "jsonata";
|
|
4
|
+
import { set } from "@supersoniks/concorde/core/utils/PublisherProxy";
|
|
5
|
+
import { registerInteractiveHelpers } from "./helpers";
|
|
6
|
+
import {
|
|
7
|
+
dispatch as registryDispatch,
|
|
8
|
+
registerStore,
|
|
9
|
+
unregisterStore,
|
|
10
|
+
type SonicActionMessage,
|
|
11
|
+
type StoreHandle,
|
|
12
|
+
} from "./registry";
|
|
13
|
+
|
|
14
|
+
const tagName = "sonic-store";
|
|
15
|
+
|
|
16
|
+
const DEFAULT_MAX_STATE_BYTES = 256 * 1024;
|
|
17
|
+
const DEFAULT_BUDGET_MS = 8;
|
|
18
|
+
|
|
19
|
+
type HistoryEntry = unknown;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Store déclaratif : state' = reducer($state, $action, $env) via JSONata.
|
|
23
|
+
* Opt-in : `@supersoniks/concorde/interactive`.
|
|
24
|
+
*/
|
|
25
|
+
@customElement(tagName)
|
|
26
|
+
export class SonicStore extends LitElement {
|
|
27
|
+
static styles = css`
|
|
28
|
+
:host {
|
|
29
|
+
display: contents;
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
/** Identifiant du store (obligatoire pour dispatch). */
|
|
34
|
+
@property({ type: String })
|
|
35
|
+
id = "";
|
|
36
|
+
|
|
37
|
+
/** DataProvider où publier l’état (défaut = id). */
|
|
38
|
+
@property({ type: String })
|
|
39
|
+
dataProvider = "";
|
|
40
|
+
|
|
41
|
+
/** État initial (JSON attribut / objet). */
|
|
42
|
+
@property({ type: Object })
|
|
43
|
+
initial: unknown = null;
|
|
44
|
+
|
|
45
|
+
/** Expression JSONata du reducer. */
|
|
46
|
+
@property({ type: String })
|
|
47
|
+
reducer = "";
|
|
48
|
+
|
|
49
|
+
@property({ type: Number, attribute: "max-state-bytes" })
|
|
50
|
+
maxStateBytes = DEFAULT_MAX_STATE_BYTES;
|
|
51
|
+
|
|
52
|
+
@property({ type: Number, attribute: "budget-ms" })
|
|
53
|
+
budgetMs = DEFAULT_BUDGET_MS;
|
|
54
|
+
|
|
55
|
+
/** Taille max de l’historique undo (0 = off). */
|
|
56
|
+
@property({ type: Number })
|
|
57
|
+
history = 0;
|
|
58
|
+
|
|
59
|
+
private state: unknown = null;
|
|
60
|
+
private queue: SonicActionMessage[] = [];
|
|
61
|
+
private draining = false;
|
|
62
|
+
private compiled: ReturnType<typeof jsonata> | null = null;
|
|
63
|
+
private historyStack: HistoryEntry[] = [];
|
|
64
|
+
private lastError: string | null = null;
|
|
65
|
+
|
|
66
|
+
connectedCallback(): void {
|
|
67
|
+
super.connectedCallback();
|
|
68
|
+
this.bootstrap();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
disconnectedCallback(): void {
|
|
72
|
+
if (this.id) unregisterStore(this.id);
|
|
73
|
+
super.disconnectedCallback();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
protected updated(changed: Map<string | number | symbol, unknown>): void {
|
|
77
|
+
if (
|
|
78
|
+
changed.has("id") ||
|
|
79
|
+
changed.has("reducer") ||
|
|
80
|
+
changed.has("initial") ||
|
|
81
|
+
changed.has("dataProvider")
|
|
82
|
+
) {
|
|
83
|
+
const prevId = changed.get("id");
|
|
84
|
+
if (typeof prevId === "string" && prevId && prevId !== this.id) {
|
|
85
|
+
unregisterStore(prevId);
|
|
86
|
+
}
|
|
87
|
+
this.bootstrap();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private dpId(): string {
|
|
92
|
+
return (this.dataProvider || this.id || "").trim();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Action optionnelle après bootstrap (ex. `view` pour peindre la grille). */
|
|
96
|
+
@property({ type: String, attribute: "boot-action" })
|
|
97
|
+
bootAction = "";
|
|
98
|
+
|
|
99
|
+
private bootstrap(): void {
|
|
100
|
+
if (!this.id) return;
|
|
101
|
+
this.compileReducer();
|
|
102
|
+
this.state = this.clone(this.initial);
|
|
103
|
+
this.historyStack = [];
|
|
104
|
+
this.lastError = null;
|
|
105
|
+
this.publish();
|
|
106
|
+
const handle: StoreHandle = {
|
|
107
|
+
id: this.id,
|
|
108
|
+
dispatch: (action) => this.enqueue(action),
|
|
109
|
+
getState: () => this.state,
|
|
110
|
+
reset: () => this.reset(),
|
|
111
|
+
};
|
|
112
|
+
registerStore(handle);
|
|
113
|
+
const boot = (this.bootAction || "").trim();
|
|
114
|
+
if (boot) this.enqueue({ type: boot, t: performance.now() });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private compileReducer(): void {
|
|
118
|
+
this.compiled = null;
|
|
119
|
+
const src = (this.reducer || "").trim();
|
|
120
|
+
if (!src) return;
|
|
121
|
+
if (src.length > 32_768) {
|
|
122
|
+
this.fail("reducer trop long (max 32 Ko)");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
const expr = jsonata(src);
|
|
127
|
+
registerInteractiveHelpers(expr);
|
|
128
|
+
// Désactiver impureté
|
|
129
|
+
expr.assign("random", () => {
|
|
130
|
+
throw new Error("$random interdit dans un reducer (utiliser $rand)");
|
|
131
|
+
});
|
|
132
|
+
expr.assign("now", () => {
|
|
133
|
+
throw new Error("$now interdit dans un reducer (utiliser $action.t)");
|
|
134
|
+
});
|
|
135
|
+
this.compiled = expr;
|
|
136
|
+
} catch (err) {
|
|
137
|
+
this.fail(err instanceof Error ? err.message : String(err));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private enqueue(action: SonicActionMessage): void {
|
|
142
|
+
if (action.type === "@reset") {
|
|
143
|
+
this.reset();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (action.type === "@undo") {
|
|
147
|
+
this.undo();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
this.queue.push(action);
|
|
151
|
+
void this.drain();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private async drain(): Promise<void> {
|
|
155
|
+
if (this.draining) return;
|
|
156
|
+
this.draining = true;
|
|
157
|
+
try {
|
|
158
|
+
while (this.queue.length) {
|
|
159
|
+
const action = this.queue.shift()!;
|
|
160
|
+
await this.apply(action);
|
|
161
|
+
}
|
|
162
|
+
} finally {
|
|
163
|
+
this.draining = false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private async apply(action: SonicActionMessage): Promise<void> {
|
|
168
|
+
if (!this.compiled) return;
|
|
169
|
+
const started = performance.now();
|
|
170
|
+
const env = {
|
|
171
|
+
width: typeof window !== "undefined" ? window.innerWidth : 0,
|
|
172
|
+
height: typeof window !== "undefined" ? window.innerHeight : 0,
|
|
173
|
+
now: action.t ?? started,
|
|
174
|
+
};
|
|
175
|
+
const bindings = {
|
|
176
|
+
state: this.state,
|
|
177
|
+
action: {
|
|
178
|
+
type: action.type,
|
|
179
|
+
payload: action.payload ?? null,
|
|
180
|
+
t: action.t ?? started,
|
|
181
|
+
dt: action.dt ?? null,
|
|
182
|
+
},
|
|
183
|
+
env,
|
|
184
|
+
};
|
|
185
|
+
try {
|
|
186
|
+
const expr = this.compiled;
|
|
187
|
+
// Bindings → $state, $action, $env (purs ; pas de $random / $now)
|
|
188
|
+
const result = await expr.evaluate(this.state, {
|
|
189
|
+
state: this.state,
|
|
190
|
+
action: bindings.action,
|
|
191
|
+
env,
|
|
192
|
+
});
|
|
193
|
+
const elapsed = performance.now() - started;
|
|
194
|
+
if (elapsed > this.budgetMs) {
|
|
195
|
+
this.fail(`budget ${this.budgetMs}ms dépassé (${elapsed.toFixed(1)}ms)`);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (result === undefined) return;
|
|
199
|
+
const encoded = JSON.stringify(result);
|
|
200
|
+
if (encoded !== undefined && encoded.length > this.maxStateBytes) {
|
|
201
|
+
this.fail(`état trop gros (max ${this.maxStateBytes} octets)`);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (this.history > 0) {
|
|
205
|
+
this.historyStack.push(this.clone(this.state));
|
|
206
|
+
if (this.historyStack.length > this.history) this.historyStack.shift();
|
|
207
|
+
}
|
|
208
|
+
this.state = result;
|
|
209
|
+
this.lastError = null;
|
|
210
|
+
this.publish();
|
|
211
|
+
} catch (err) {
|
|
212
|
+
this.fail(err instanceof Error ? err.message : String(err));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private reset(): void {
|
|
217
|
+
this.state = this.clone(this.initial);
|
|
218
|
+
this.historyStack = [];
|
|
219
|
+
this.lastError = null;
|
|
220
|
+
this.publish();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private undo(): void {
|
|
224
|
+
if (!this.historyStack.length) return;
|
|
225
|
+
this.state = this.historyStack.pop();
|
|
226
|
+
this.publish();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private publish(): void {
|
|
230
|
+
const id = this.dpId();
|
|
231
|
+
if (!id) return;
|
|
232
|
+
const payload =
|
|
233
|
+
this.state && typeof this.state === "object"
|
|
234
|
+
? { ...(this.state as object), lastError: this.lastError }
|
|
235
|
+
: { value: this.state, lastError: this.lastError };
|
|
236
|
+
set(id, payload as never);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private fail(message: string): void {
|
|
240
|
+
this.lastError = message;
|
|
241
|
+
this.dispatchEvent(
|
|
242
|
+
new CustomEvent("error", {
|
|
243
|
+
detail: { message },
|
|
244
|
+
bubbles: true,
|
|
245
|
+
composed: true,
|
|
246
|
+
}),
|
|
247
|
+
);
|
|
248
|
+
this.publish();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private clone(v: unknown): unknown {
|
|
252
|
+
if (v === null || typeof v !== "object") return v;
|
|
253
|
+
try {
|
|
254
|
+
return JSON.parse(JSON.stringify(v));
|
|
255
|
+
} catch {
|
|
256
|
+
return v;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** API élément : dispatch manuel. */
|
|
261
|
+
dispatchAction(action: SonicActionMessage): void {
|
|
262
|
+
registryDispatch(this.id, action);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
render() {
|
|
266
|
+
return html``;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export default SonicStore;
|