@zeix/le-truc 0.15.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/.ai-context.md +234 -0
- package/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +111 -0
- package/.editorconfig +12 -0
- package/.github/copilot-instructions.md +62 -0
- package/.github/workflows/codeql.yml +108 -0
- package/.github/workflows/static.yml +43 -0
- package/.prettierrc +17 -0
- package/CLAUDE.md +215 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +160 -0
- package/LICENSE +21 -0
- package/README.md +474 -0
- package/biome.json +295 -0
- package/bun.lock +239 -0
- package/docs/about.html +105 -0
- package/docs/assets/main.css +1 -0
- package/docs/assets/main.js +10 -0
- package/docs/assets/main.js.map +66 -0
- package/docs/components.html +293 -0
- package/docs/data-flow.html +308 -0
- package/docs/examples/basic-button.html +367 -0
- package/docs/examples/basic-counter.html +188 -0
- package/docs/examples/basic-hello.html +138 -0
- package/docs/examples/basic-number.html +271 -0
- package/docs/examples/basic-pluralize.html +214 -0
- package/docs/examples/card-callout.html +152 -0
- package/docs/examples/card-mediaqueries.html +138 -0
- package/docs/examples/context-media.html +198 -0
- package/docs/examples/empty.html +37 -0
- package/docs/examples/form-checkbox.html +233 -0
- package/docs/examples/form-combobox.html +420 -0
- package/docs/examples/form-listbox.html +434 -0
- package/docs/examples/form-radiogroup.html +296 -0
- package/docs/examples/form-spinbutton.html +402 -0
- package/docs/examples/form-textbox.html +361 -0
- package/docs/examples/layout.html +67 -0
- package/docs/examples/module-carousel.html +552 -0
- package/docs/examples/module-catalog.html +241 -0
- package/docs/examples/module-codeblock.html +270 -0
- package/docs/examples/module-dialog.html +343 -0
- package/docs/examples/module-lazyload.html +289 -0
- package/docs/examples/module-list.html +197 -0
- package/docs/examples/module-pagination.html +283 -0
- package/docs/examples/module-scrollarea.html +447 -0
- package/docs/examples/module-tabgroup.html +526 -0
- package/docs/examples/module-todo.html +367 -0
- package/docs/examples/module-with-type.html +63 -0
- package/docs/examples/nested-components.html +88 -0
- package/docs/examples/recursive.html +56 -0
- package/docs/examples/simple-text.html +39 -0
- package/docs/examples/snippet.html +93 -0
- package/docs/examples/with-styles.html +75 -0
- package/docs/getting-started.html +143 -0
- package/docs/index.html +112 -0
- package/docs/sitemap.xml +28 -0
- package/docs/styling.html +160 -0
- package/docs/sw.js +112 -0
- package/docs-src/api/README.md +478 -0
- package/docs-src/api/_media/LICENSE +21 -0
- package/docs-src/api/classes/CircularDependencyError.md +299 -0
- package/docs-src/api/classes/CircularMutationError.md +301 -0
- package/docs-src/api/classes/ContextRequestEvent.md +590 -0
- package/docs-src/api/classes/DependencyTimeoutError.md +301 -0
- package/docs-src/api/classes/InvalidCallbackError.md +303 -0
- package/docs-src/api/classes/InvalidComponentNameError.md +295 -0
- package/docs-src/api/classes/InvalidCustomElementError.md +301 -0
- package/docs-src/api/classes/InvalidEffectsError.md +301 -0
- package/docs-src/api/classes/InvalidPropertyNameError.md +307 -0
- package/docs-src/api/classes/InvalidReactivesError.md +307 -0
- package/docs-src/api/classes/InvalidSignalValueError.md +303 -0
- package/docs-src/api/classes/MissingElementError.md +307 -0
- package/docs-src/api/classes/NullishSignalValueError.md +299 -0
- package/docs-src/api/classes/StoreKeyExistsError.md +303 -0
- package/docs-src/api/classes/StoreKeyRangeError.md +299 -0
- package/docs-src/api/classes/StoreKeyReadonlyError.md +303 -0
- package/docs-src/api/functions/asBoolean.md +21 -0
- package/docs-src/api/functions/asEnum.md +31 -0
- package/docs-src/api/functions/asInteger.md +39 -0
- package/docs-src/api/functions/asJSON.md +49 -0
- package/docs-src/api/functions/asNumber.md +37 -0
- package/docs-src/api/functions/asString.md +37 -0
- package/docs-src/api/functions/createCollection.md +83 -0
- package/docs-src/api/functions/createSensor.md +71 -0
- package/docs-src/api/functions/dangerouslySetInnerHTML.md +48 -0
- package/docs-src/api/functions/defineComponent.md +65 -0
- package/docs-src/api/functions/isCollection.md +37 -0
- package/docs-src/api/functions/isParser.md +41 -0
- package/docs-src/api/functions/match.md +47 -0
- package/docs-src/api/functions/on.md +58 -0
- package/docs-src/api/functions/pass.md +53 -0
- package/docs-src/api/functions/provideContexts.md +47 -0
- package/docs-src/api/functions/read.md +47 -0
- package/docs-src/api/functions/requestContext.md +51 -0
- package/docs-src/api/functions/resolve.md +40 -0
- package/docs-src/api/functions/runEffects.md +51 -0
- package/docs-src/api/functions/runElementEffects.md +57 -0
- package/docs-src/api/functions/schedule.md +33 -0
- package/docs-src/api/functions/setAttribute.md +48 -0
- package/docs-src/api/functions/setProperty.md +52 -0
- package/docs-src/api/functions/setStyle.md +48 -0
- package/docs-src/api/functions/setText.md +42 -0
- package/docs-src/api/functions/show.md +42 -0
- package/docs-src/api/functions/toSignal.md +37 -0
- package/docs-src/api/functions/toggleAttribute.md +48 -0
- package/docs-src/api/functions/toggleClass.md +48 -0
- package/docs-src/api/functions/updateElement.md +53 -0
- package/docs-src/api/globals.md +131 -0
- package/docs-src/api/type-aliases/Cleanup.md +27 -0
- package/docs-src/api/type-aliases/Collection.md +91 -0
- package/docs-src/api/type-aliases/CollectionListener.md +27 -0
- package/docs-src/api/type-aliases/Component.md +17 -0
- package/docs-src/api/type-aliases/ComponentProp.md +11 -0
- package/docs-src/api/type-aliases/ComponentProps.md +11 -0
- package/docs-src/api/type-aliases/ComponentSetup.md +31 -0
- package/docs-src/api/type-aliases/ComponentUI.md +27 -0
- package/docs-src/api/type-aliases/Computed.md +49 -0
- package/docs-src/api/type-aliases/ComputedCallback.md +29 -0
- package/docs-src/api/type-aliases/Context.md +33 -0
- package/docs-src/api/type-aliases/ContextType.md +19 -0
- package/docs-src/api/type-aliases/DangerouslySetInnerHTMLOptions.md +27 -0
- package/docs-src/api/type-aliases/DiffResult.md +61 -0
- package/docs-src/api/type-aliases/Effect.md +35 -0
- package/docs-src/api/type-aliases/EffectCallback.md +23 -0
- package/docs-src/api/type-aliases/Effects.md +21 -0
- package/docs-src/api/type-aliases/ElementEffects.md +21 -0
- package/docs-src/api/type-aliases/ElementFromKey.md +21 -0
- package/docs-src/api/type-aliases/ElementQueries.md +27 -0
- package/docs-src/api/type-aliases/ElementUpdater.md +131 -0
- package/docs-src/api/type-aliases/EventHandler.md +31 -0
- package/docs-src/api/type-aliases/EventType.md +17 -0
- package/docs-src/api/type-aliases/Fallback.md +21 -0
- package/docs-src/api/type-aliases/Initializers.md +21 -0
- package/docs-src/api/type-aliases/LooseReader.md +31 -0
- package/docs-src/api/type-aliases/MatchHandlers.md +77 -0
- package/docs-src/api/type-aliases/MaybeCleanup.md +23 -0
- package/docs-src/api/type-aliases/MaybeSignal.md +17 -0
- package/docs-src/api/type-aliases/Parser.md +39 -0
- package/docs-src/api/type-aliases/ParserOrFallback.md +21 -0
- package/docs-src/api/type-aliases/PassedProp.md +25 -0
- package/docs-src/api/type-aliases/PassedProps.md +21 -0
- package/docs-src/api/type-aliases/Reactive.md +25 -0
- package/docs-src/api/type-aliases/Reader.md +31 -0
- package/docs-src/api/type-aliases/ReservedWords.md +11 -0
- package/docs-src/api/type-aliases/ResolveResult.md +29 -0
- package/docs-src/api/type-aliases/SensorEvents.md +25 -0
- package/docs-src/api/type-aliases/Signal.md +41 -0
- package/docs-src/api/type-aliases/State.md +85 -0
- package/docs-src/api/type-aliases/Store.md +29 -0
- package/docs-src/api/type-aliases/UI.md +11 -0
- package/docs-src/api/type-aliases/UnknownContext.md +13 -0
- package/docs-src/api/variables/CONTEXT_REQUEST.md +11 -0
- package/docs-src/api/variables/UNSET.md +23 -0
- package/docs-src/api/variables/batch.md +25 -0
- package/docs-src/api/variables/createComputed.md +41 -0
- package/docs-src/api/variables/createEffect.md +35 -0
- package/docs-src/api/variables/createState.md +37 -0
- package/docs-src/api/variables/createStore.md +42 -0
- package/docs-src/api/variables/diff.md +43 -0
- package/docs-src/api/variables/isAbortError.md +33 -0
- package/docs-src/api/variables/isAsyncFunction.md +39 -0
- package/docs-src/api/variables/isComputed.md +37 -0
- package/docs-src/api/variables/isEqual.md +49 -0
- package/docs-src/api/variables/isFunction.md +39 -0
- package/docs-src/api/variables/isMutableSignal.md +37 -0
- package/docs-src/api/variables/isNumber.md +33 -0
- package/docs-src/api/variables/isRecord.md +39 -0
- package/docs-src/api/variables/isRecordOrArray.md +39 -0
- package/docs-src/api/variables/isSignal.md +37 -0
- package/docs-src/api/variables/isState.md +37 -0
- package/docs-src/api/variables/isStore.md +37 -0
- package/docs-src/api/variables/isString.md +33 -0
- package/docs-src/api/variables/isSymbol.md +33 -0
- package/docs-src/api/variables/toError.md +33 -0
- package/docs-src/api/variables/valueString.md +33 -0
- package/docs-src/includes/menu.html +44 -0
- package/docs-src/pages/about.md +89 -0
- package/docs-src/pages/components.md +437 -0
- package/docs-src/pages/data-flow.md +449 -0
- package/docs-src/pages/getting-started.md +170 -0
- package/docs-src/pages/index.md +98 -0
- package/docs-src/pages/styling.md +165 -0
- package/eslint.config.js +64 -0
- package/examples/_common/clear.ts +49 -0
- package/examples/_common/fetch.ts +160 -0
- package/examples/_common/focus.ts +45 -0
- package/examples/_common/highlight.ts +5 -0
- package/examples/_global.css +463 -0
- package/examples/basic-button/basic-button.css +176 -0
- package/examples/basic-button/basic-button.html +46 -0
- package/examples/basic-button/basic-button.spec.ts +160 -0
- package/examples/basic-button/basic-button.ts +45 -0
- package/examples/basic-button/copyToClipboard.ts +37 -0
- package/examples/basic-counter/basic-counter.css +21 -0
- package/examples/basic-counter/basic-counter.html +24 -0
- package/examples/basic-counter/basic-counter.spec.ts +85 -0
- package/examples/basic-counter/basic-counter.ts +43 -0
- package/examples/basic-hello/basic-hello.html +34 -0
- package/examples/basic-hello/basic-hello.spec.ts +110 -0
- package/examples/basic-hello/basic-hello.ts +36 -0
- package/examples/basic-number/basic-number.html +79 -0
- package/examples/basic-number/basic-number.spec.ts +175 -0
- package/examples/basic-number/basic-number.ts +124 -0
- package/examples/basic-pluralize/basic-pluralize.html +64 -0
- package/examples/basic-pluralize/basic-pluralize.spec.ts +258 -0
- package/examples/basic-pluralize/basic-pluralize.ts +82 -0
- package/examples/card-callout/card-callout.css +79 -0
- package/examples/card-callout/card-callout.html +5 -0
- package/examples/card-mediaqueries/card-mediaqueries.html +29 -0
- package/examples/card-mediaqueries/card-mediaqueries.spec.ts +300 -0
- package/examples/card-mediaqueries/card-mediaqueries.ts +41 -0
- package/examples/context-media/context-media.html +3 -0
- package/examples/context-media/context-media.ts +127 -0
- package/examples/form-checkbox/form-checkbox.css +70 -0
- package/examples/form-checkbox/form-checkbox.html +13 -0
- package/examples/form-checkbox/form-checkbox.spec.ts +357 -0
- package/examples/form-checkbox/form-checkbox.ts +50 -0
- package/examples/form-checkbox/vanilla-checkbox.ts +101 -0
- package/examples/form-combobox/form-combobox.css +118 -0
- package/examples/form-combobox/form-combobox.html +74 -0
- package/examples/form-combobox/form-combobox.spec.ts +977 -0
- package/examples/form-combobox/form-combobox.ts +128 -0
- package/examples/form-listbox/form-listbox.css +71 -0
- package/examples/form-listbox/form-listbox.html +67 -0
- package/examples/form-listbox/form-listbox.spec.ts +1050 -0
- package/examples/form-listbox/form-listbox.ts +196 -0
- package/examples/form-listbox/mocks/timezones.json +495 -0
- package/examples/form-radiogroup/form-radiogroup.css +87 -0
- package/examples/form-radiogroup/form-radiogroup.html +51 -0
- package/examples/form-radiogroup/form-radiogroup.spec.ts +515 -0
- package/examples/form-radiogroup/form-radiogroup.ts +58 -0
- package/examples/form-spinbutton/form-spinbutton.css +95 -0
- package/examples/form-spinbutton/form-spinbutton.html +96 -0
- package/examples/form-spinbutton/form-spinbutton.spec.ts +688 -0
- package/examples/form-spinbutton/form-spinbutton.ts +111 -0
- package/examples/form-textbox/form-textbox.css +104 -0
- package/examples/form-textbox/form-textbox.html +53 -0
- package/examples/form-textbox/form-textbox.spec.ts +542 -0
- package/examples/form-textbox/form-textbox.ts +104 -0
- package/examples/main.css +22 -0
- package/examples/main.ts +23 -0
- package/examples/module-carousel/module-carousel.css +113 -0
- package/examples/module-carousel/module-carousel.html +208 -0
- package/examples/module-carousel/module-carousel.spec.ts +523 -0
- package/examples/module-carousel/module-carousel.ts +131 -0
- package/examples/module-catalog/module-catalog.css +22 -0
- package/examples/module-catalog/module-catalog.html +82 -0
- package/examples/module-catalog/module-catalog.spec.ts +396 -0
- package/examples/module-catalog/module-catalog.ts +37 -0
- package/examples/module-codeblock/module-codeblock.css +95 -0
- package/examples/module-codeblock/module-codeblock.html +28 -0
- package/examples/module-codeblock/module-codeblock.ts +47 -0
- package/examples/module-demo/module-demo.css +13 -0
- package/examples/module-dialog/module-dialog.css +96 -0
- package/examples/module-dialog/module-dialog.html +66 -0
- package/examples/module-dialog/module-dialog.spec.ts +557 -0
- package/examples/module-dialog/module-dialog.ts +81 -0
- package/examples/module-lazyload/mocks/empty.html +1 -0
- package/examples/module-lazyload/mocks/module-with-type.html +27 -0
- package/examples/module-lazyload/mocks/nested-components.html +52 -0
- package/examples/module-lazyload/mocks/recursive.html +20 -0
- package/examples/module-lazyload/mocks/simple-text.html +3 -0
- package/examples/module-lazyload/mocks/snippet.html +57 -0
- package/examples/module-lazyload/mocks/with-styles.html +39 -0
- package/examples/module-lazyload/module-lazyload.html +132 -0
- package/examples/module-lazyload/module-lazyload.spec.ts +734 -0
- package/examples/module-lazyload/module-lazyload.ts +89 -0
- package/examples/module-list/module-list.html +30 -0
- package/examples/module-list/module-list.spec.ts +592 -0
- package/examples/module-list/module-list.ts +99 -0
- package/examples/module-pagination/module-pagination.css +79 -0
- package/examples/module-pagination/module-pagination.html +16 -0
- package/examples/module-pagination/module-pagination.spec.ts +701 -0
- package/examples/module-pagination/module-pagination.ts +88 -0
- package/examples/module-scrollarea/module-scrollarea.css +77 -0
- package/examples/module-scrollarea/module-scrollarea.html +189 -0
- package/examples/module-scrollarea/module-scrollarea.spec.ts +445 -0
- package/examples/module-scrollarea/module-scrollarea.ts +81 -0
- package/examples/module-tabgroup/module-tabgroup.css +55 -0
- package/examples/module-tabgroup/module-tabgroup.html +269 -0
- package/examples/module-tabgroup/module-tabgroup.spec.ts +631 -0
- package/examples/module-tabgroup/module-tabgroup.ts +102 -0
- package/examples/module-toc/module-toc.css +34 -0
- package/examples/module-todo/module-todo.css +84 -0
- package/examples/module-todo/module-todo.html +92 -0
- package/examples/module-todo/module-todo.spec.ts +528 -0
- package/examples/module-todo/module-todo.ts +91 -0
- package/examples/section-hero/section-hero.css +37 -0
- package/examples/section-menu/section-menu.css +81 -0
- package/examples/server.ts +95 -0
- package/examples/test-setup.md +314 -0
- package/index.dev.js +1688 -0
- package/index.dev.ts +127 -0
- package/index.js +3 -0
- package/index.js.map +42 -0
- package/index.ts +127 -0
- package/package.json +64 -0
- package/playwright.config.ts +31 -0
- package/server/BUILD_SYSTEM.md +428 -0
- package/server/SERVER.md +286 -0
- package/server/build.ts +91 -0
- package/server/config.ts +130 -0
- package/server/effects/api.ts +28 -0
- package/server/effects/css.ts +31 -0
- package/server/effects/examples.ts +109 -0
- package/server/effects/js.ts +32 -0
- package/server/effects/menu.ts +34 -0
- package/server/effects/pages.ts +178 -0
- package/server/effects/service-worker.ts +57 -0
- package/server/effects/sitemap.ts +27 -0
- package/server/file-signals.ts +361 -0
- package/server/file-watcher.ts +77 -0
- package/server/io.ts +174 -0
- package/server/layout-engine.ts +470 -0
- package/server/layout-utils.ts +615 -0
- package/server/layouts/api.html +76 -0
- package/server/layouts/base.html +37 -0
- package/server/layouts/blog.html +115 -0
- package/server/layouts/example.html +104 -0
- package/server/layouts/overview.html +165 -0
- package/server/layouts/page.html +36 -0
- package/server/layouts/test.html +24 -0
- package/server/markdoc-helpers.ts +217 -0
- package/server/markdoc.config.ts +29 -0
- package/server/schema/callout.markdoc.ts +17 -0
- package/server/schema/carousel.markdoc.ts +118 -0
- package/server/schema/demo.markdoc.ts +74 -0
- package/server/schema/fence.markdoc.ts +84 -0
- package/server/schema/heading.markdoc.ts +23 -0
- package/server/schema/hero.markdoc.ts +59 -0
- package/server/schema/section.markdoc.ts +10 -0
- package/server/schema/slide.markdoc.ts +17 -0
- package/server/schema/source.markdoc.ts +53 -0
- package/server/schema/tabgroup.markdoc.ts +102 -0
- package/server/serve.ts +635 -0
- package/server/templates/README.md +352 -0
- package/server/templates/constants.ts +236 -0
- package/server/templates/fragments.ts +159 -0
- package/server/templates/hmr.ts +269 -0
- package/server/templates/menu.ts +33 -0
- package/server/templates/performance-hints.ts +94 -0
- package/server/templates/service-worker.ts +403 -0
- package/server/templates/sitemap.ts +57 -0
- package/server/templates/toc.ts +41 -0
- package/server/templates/utils.ts +378 -0
- package/src/component.ts +215 -0
- package/src/context.ts +156 -0
- package/src/effects/attribute.ts +82 -0
- package/src/effects/class.ts +28 -0
- package/src/effects/event.ts +67 -0
- package/src/effects/html.ts +60 -0
- package/src/effects/method.ts +57 -0
- package/src/effects/pass.ts +103 -0
- package/src/effects/property.ts +57 -0
- package/src/effects/style.ts +34 -0
- package/src/effects/text.ts +28 -0
- package/src/effects.ts +412 -0
- package/src/errors.ts +160 -0
- package/src/parsers/boolean.ts +14 -0
- package/src/parsers/json.ts +33 -0
- package/src/parsers/number.ts +55 -0
- package/src/parsers/string.ts +32 -0
- package/src/parsers.ts +90 -0
- package/src/scheduler.ts +47 -0
- package/src/signals/collection.ts +253 -0
- package/src/signals/sensor.ts +131 -0
- package/src/ui.ts +236 -0
- package/src/util.ts +187 -0
- package/tsconfig.json +34 -0
- package/types/examples/basic-button/basic-button.d.ts +16 -0
- package/types/examples/basic-hello/basic-hello.d.ts +18 -0
- package/types/index.d.ts +27 -0
- package/types/index.dev.d.ts +27 -0
- package/types/src/collection.d.ts +27 -0
- package/types/src/component.d.ts +32 -0
- package/types/src/context.d.ts +85 -0
- package/types/src/effects/attribute.d.ts +23 -0
- package/types/src/effects/callMethod.d.ts +23 -0
- package/types/src/effects/class.d.ts +13 -0
- package/types/src/effects/dangerouslySetInnerHTML.d.ts +18 -0
- package/types/src/effects/event.d.ts +18 -0
- package/types/src/effects/html.d.ts +17 -0
- package/types/src/effects/method.d.ts +22 -0
- package/types/src/effects/pass.d.ts +18 -0
- package/types/src/effects/property.d.ts +22 -0
- package/types/src/effects/setAttribute.d.ts +24 -0
- package/types/src/effects/setProperty.d.ts +23 -0
- package/types/src/effects/setStyle.d.ts +14 -0
- package/types/src/effects/setText.d.ts +13 -0
- package/types/src/effects/style.d.ts +13 -0
- package/types/src/effects/text.d.ts +12 -0
- package/types/src/effects/toggleClass.d.ts +14 -0
- package/types/src/effects.d.ts +153 -0
- package/types/src/errors.d.ts +99 -0
- package/types/src/events.d.ts +27 -0
- package/types/src/extractors.d.ts +23 -0
- package/types/src/parsers/boolean.d.ts +10 -0
- package/types/src/parsers/json.d.ts +13 -0
- package/types/src/parsers/number.d.ts +21 -0
- package/types/src/parsers/string.d.ts +19 -0
- package/types/src/parsers.d.ts +41 -0
- package/types/src/scheduler.d.ts +11 -0
- package/types/src/sensor.d.ts +27 -0
- package/types/src/signals/collection.d.ts +32 -0
- package/types/src/signals/sensor.d.ts +27 -0
- package/types/src/ui.d.ts +37 -0
- package/types/src/util.d.ts +65 -0
package/index.dev.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name Le Truc
|
|
3
|
+
* @version 0.15.0
|
|
4
|
+
* @author Esther Brunner
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// From Cause & Effect
|
|
8
|
+
export {
|
|
9
|
+
batch,
|
|
10
|
+
CircularDependencyError,
|
|
11
|
+
type Cleanup,
|
|
12
|
+
type Computed,
|
|
13
|
+
type ComputedCallback,
|
|
14
|
+
createComputed,
|
|
15
|
+
createEffect,
|
|
16
|
+
createState,
|
|
17
|
+
createStore,
|
|
18
|
+
type DiffResult,
|
|
19
|
+
diff,
|
|
20
|
+
type EffectCallback,
|
|
21
|
+
InvalidCallbackError,
|
|
22
|
+
InvalidSignalValueError,
|
|
23
|
+
isAbortError,
|
|
24
|
+
isAsyncFunction,
|
|
25
|
+
isComputed,
|
|
26
|
+
isEqual,
|
|
27
|
+
isFunction,
|
|
28
|
+
isMutableSignal,
|
|
29
|
+
isNumber,
|
|
30
|
+
isRecord,
|
|
31
|
+
isRecordOrArray,
|
|
32
|
+
isSignal,
|
|
33
|
+
isState,
|
|
34
|
+
isStore,
|
|
35
|
+
isString,
|
|
36
|
+
isSymbol,
|
|
37
|
+
type MatchHandlers,
|
|
38
|
+
type MaybeCleanup,
|
|
39
|
+
match,
|
|
40
|
+
NullishSignalValueError,
|
|
41
|
+
type ResolveResult,
|
|
42
|
+
resolve,
|
|
43
|
+
type Signal,
|
|
44
|
+
type State,
|
|
45
|
+
type Store,
|
|
46
|
+
StoreKeyExistsError,
|
|
47
|
+
StoreKeyRangeError,
|
|
48
|
+
StoreKeyReadonlyError,
|
|
49
|
+
toError,
|
|
50
|
+
toSignal,
|
|
51
|
+
UNSET,
|
|
52
|
+
valueString,
|
|
53
|
+
} from '@zeix/cause-effect'
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
type Component,
|
|
57
|
+
type ComponentProp,
|
|
58
|
+
type ComponentProps,
|
|
59
|
+
type ComponentSetup,
|
|
60
|
+
type ComponentUI,
|
|
61
|
+
defineComponent,
|
|
62
|
+
type Initializers,
|
|
63
|
+
type MaybeSignal,
|
|
64
|
+
type ReservedWords,
|
|
65
|
+
} from './src/component'
|
|
66
|
+
export {
|
|
67
|
+
CONTEXT_REQUEST,
|
|
68
|
+
type Context,
|
|
69
|
+
ContextRequestEvent,
|
|
70
|
+
type ContextType,
|
|
71
|
+
provideContexts,
|
|
72
|
+
requestContext,
|
|
73
|
+
type UnknownContext,
|
|
74
|
+
} from './src/context'
|
|
75
|
+
export {
|
|
76
|
+
type Effect,
|
|
77
|
+
type Effects,
|
|
78
|
+
type ElementEffects,
|
|
79
|
+
type ElementUpdater,
|
|
80
|
+
type Reactive,
|
|
81
|
+
runEffects,
|
|
82
|
+
runElementEffects,
|
|
83
|
+
updateElement,
|
|
84
|
+
} from './src/effects'
|
|
85
|
+
export { setAttribute, toggleAttribute } from './src/effects/attribute'
|
|
86
|
+
export { toggleClass } from './src/effects/class'
|
|
87
|
+
export { type EventHandler, type EventType, on } from './src/effects/event'
|
|
88
|
+
export {
|
|
89
|
+
type DangerouslySetInnerHTMLOptions,
|
|
90
|
+
dangerouslySetInnerHTML,
|
|
91
|
+
} from './src/effects/html'
|
|
92
|
+
export { type PassedProp, type PassedProps, pass } from './src/effects/pass'
|
|
93
|
+
export { setProperty, show } from './src/effects/property'
|
|
94
|
+
export { setStyle } from './src/effects/style'
|
|
95
|
+
export { setText } from './src/effects/text'
|
|
96
|
+
export {
|
|
97
|
+
CircularMutationError,
|
|
98
|
+
DependencyTimeoutError,
|
|
99
|
+
InvalidComponentNameError,
|
|
100
|
+
InvalidCustomElementError,
|
|
101
|
+
InvalidEffectsError,
|
|
102
|
+
InvalidPropertyNameError,
|
|
103
|
+
InvalidReactivesError,
|
|
104
|
+
MissingElementError,
|
|
105
|
+
} from './src/errors'
|
|
106
|
+
export {
|
|
107
|
+
type Fallback,
|
|
108
|
+
isParser,
|
|
109
|
+
type LooseReader,
|
|
110
|
+
type Parser,
|
|
111
|
+
type ParserOrFallback,
|
|
112
|
+
type Reader,
|
|
113
|
+
read,
|
|
114
|
+
} from './src/parsers'
|
|
115
|
+
export { asBoolean } from './src/parsers/boolean'
|
|
116
|
+
export { asJSON } from './src/parsers/json'
|
|
117
|
+
export { asInteger, asNumber } from './src/parsers/number'
|
|
118
|
+
export { asEnum, asString } from './src/parsers/string'
|
|
119
|
+
export { schedule } from './src/scheduler'
|
|
120
|
+
export {
|
|
121
|
+
type Collection,
|
|
122
|
+
type CollectionListener,
|
|
123
|
+
createCollection,
|
|
124
|
+
isCollection,
|
|
125
|
+
} from './src/signals/collection'
|
|
126
|
+
export { createSensor, type SensorEvents } from './src/signals/sensor'
|
|
127
|
+
export type { ElementFromKey, ElementQueries, UI } from './src/ui'
|
package/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
class E extends Error{constructor($){super(`Circular dependency detected in ${$}`);this.name="CircularDependencyError"}}class k extends TypeError{constructor($,B){super(`Invalid ${$} callback ${B}`);this.name="InvalidCallbackError"}}class J$ extends TypeError{constructor($,B){super(`Invalid signal value ${B} in ${$}`);this.name="InvalidSignalValueError"}}class S extends TypeError{constructor($){super(`Nullish signal values are not allowed in ${$}`);this.name="NullishSignalValueError"}}class Q$ extends Error{constructor($,B){super(`Could not add store key "${$}" with value ${B} because it already exists`);this.name="StoreKeyExistsError"}}class X$ extends RangeError{constructor($){super(`Could not remove store index ${String($)} because it is out of range`);this.name="StoreKeyRangeError"}}class H$ extends Error{constructor($,B){super(`Could not set store key "${$}" to ${B} because it is readonly`);this.name="StoreKeyReadonlyError"}}var L=Symbol(),V=($)=>typeof $==="string",T$=($)=>typeof $==="number",c=($)=>typeof $==="symbol",U=($)=>typeof $==="function",r=($)=>U($)&&$.constructor.name==="AsyncFunction",m=($,B)=>Object.prototype.toString.call($)===`[object ${B}]`,R=($)=>m($,"Object"),K$=($)=>R($)||Array.isArray($),l$=($)=>{if(!$.length)return null;let B=$.map((Z)=>V(Z)?parseInt(Z,10):T$(Z)?Z:NaN);return B.every((Z)=>Number.isFinite(Z)&&Z>=0)?B.sort((Z,J)=>Z-J):null};var n=($)=>$ instanceof DOMException&&$.name==="AbortError",y=($)=>$ instanceof Error?$:Error(String($));var z$=($)=>{let B=l$(Object.keys($));if(B===null)return $;let Z=[];for(let J of B)Z.push($[String(J)]);return Z},P=($)=>V($)?`"${$}"`:!!$&&typeof $==="object"?JSON.stringify($):String($);var b=($,B,Z)=>{if(Object.is($,B))return!0;if(typeof $!==typeof B)return!1;if(typeof $!=="object"||$===null||B===null)return!1;if(!Z)Z=new WeakSet;if(Z.has($)||Z.has(B))throw new E("isEqual");Z.add($),Z.add(B);try{if(Array.isArray($)&&Array.isArray(B)){if($.length!==B.length)return!1;for(let J=0;J<$.length;J++)if(!b($[J],B[J],Z))return!1;return!0}if(Array.isArray($)!==Array.isArray(B))return!1;if(R($)&&R(B)){let J=Object.keys($),X=Object.keys(B);if(J.length!==X.length)return!1;for(let Q of J){if(!(Q in B))return!1;if(!b($[Q],B[Q],Z))return!1}return!0}return!1}finally{Z.delete($),Z.delete(B)}},A$=($,B)=>{let Z=K$($),J=K$(B);if(!Z||!J){let q=!Object.is($,B);return{changed:q,add:q&&J?B:{},change:{},remove:q&&Z?$:{}}}let X=new WeakSet,Q={},H={},Y={},W=Object.keys($),I=Object.keys(B),z=new Set([...W,...I]);for(let q of z){let D=q in $,K=q in B;if(!D&&K){Q[q]=B[q];continue}else if(D&&!K){Y[q]=L;continue}let G=$[q],A=B[q];if(!b(G,A,X))H[q]=A}return{changed:Object.keys(Q).length>0||Object.keys(H).length>0||Object.keys(Y).length>0,add:Q,change:H,remove:Y}};var t,x$=new Set,O$=0,s=($)=>{let B=new Set,Z=$;return Z.unwatch=(J)=>{B.add(J)},Z.cleanup=()=>{for(let J of B)J();B.clear()},Z},N=($)=>{if(t&&!$.has(t)){let B=t;B.unwatch(()=>{$.delete(B)}),$.add(B)}},C=($)=>{for(let B of $)if(O$)x$.add(B);else B()},I$=()=>{while(x$.size){let $=Array.from(x$);x$.clear();for(let B of $)B()}},a=($)=>{O$++;try{$()}finally{I$(),O$--}},i=($,B)=>{let Z=t;t=B;try{$()}finally{t=Z}};var Y$="Computed",w=($,B=L)=>{if(!p($))throw new k("computed",P($));if(B==null)throw new S("computed");let Z=new Set,J=B,X,Q,H=!0,Y=!1,W=!1,I=(A)=>{if(!b(A,J))J=A,Y=!0;X=void 0,H=!1},z=()=>{Y=L!==J,J=L,X=void 0},x=(A)=>{let M=y(A);Y=!X||M.name!==X.name||M.message!==X.message,J=L,X=M},q=(A)=>(M)=>{if(W=!1,Q=void 0,A(M),Y)C(Z)},D=s(()=>{if(H=!0,Q?.abort(),Z.size)C(Z);else D.cleanup()});D.unwatch(()=>{Q?.abort()});let K=()=>i(()=>{if(W)throw new E("computed");if(Y=!1,r($)){if(Q)return J;Q=new AbortController,Q.signal.addEventListener("abort",()=>{W=!1,Q=void 0,K()},{once:!0})}let A;W=!0;try{A=Q?$(J,Q.signal):$(J)}catch(M){if(n(M))z();else x(M);W=!1;return}if(A instanceof Promise)A.then(q(I),q(x));else if(A==null||L===A)z();else I(A);W=!1},D),G={};return Object.defineProperties(G,{[Symbol.toStringTag]:{value:Y$},get:{value:()=>{if(N(Z),I$(),H)K();if(X)throw X;return J}}}),G},d=($)=>m($,Y$),p=($)=>U($)&&$.length<3;var M$=($)=>{if(!U($)||$.length>1)throw new k("effect",P($));let B=r($),Z=!1,J,X=s(()=>i(()=>{if(Z)throw new E("effect");Z=!0,J?.abort(),J=void 0;let Q;try{if(B){J=new AbortController;let H=J;$(J.signal).then((Y)=>{if(U(Y)&&J===H)X.unwatch(Y)}).catch((Y)=>{if(!n(Y))console.error("Async effect error:",Y)})}else if(Q=$(),U(Q))X.unwatch(Q)}catch(H){if(!n(H))console.error("Effect callback error:",H)}Z=!1},X));return X(),()=>{J?.abort(),X.cleanup()}};function v$($,B){try{if($.pending)B.nil?.();else if($.errors)B.err?.($.errors);else if($.ok)B.ok($.values)}catch(Z){if(B.err&&(!$.errors||!$.errors.includes(y(Z))))B.err($.errors?[...$.errors,y(Z)]:[y(Z)]);else throw Z}}function u$($){let B=[],Z=!1,J={};for(let[X,Q]of Object.entries($))try{let H=Q.get();if(H===L)Z=!0;else J[X]=H}catch(H){B.push(y(H))}if(Z)return{ok:!1,pending:!0};if(B.length>0)return{ok:!1,errors:B};return{ok:!0,values:J}}var V$="State",v=($)=>{if($==null)throw new S("state");let B=new Set,Z=$,J=(Q)=>{if(Q==null)throw new S("state");if(b(Z,Q))return;if(Z=Q,C(B),L===Z)B.clear()},X={};return Object.defineProperties(X,{[Symbol.toStringTag]:{value:V$},get:{value:()=>{return N(B),Z}},set:{value:(Q)=>{J(Q)}},update:{value:(Q)=>{if(!U(Q))throw new k("state update",P(Q));J(Q(Z))}}}),X},f=($)=>m($,V$);var N$="Store",G$=($)=>{if($==null)throw new S("store");let B=new Set,Z={add:new Set,change:new Set,remove:new Set,sort:new Set},J=new Map,X=new Map,Q=Array.isArray($),H=()=>{let K={};for(let[G,A]of J)K[G]=A.get();return K},Y=(K,G)=>{Object.freeze(G);for(let A of Z[K])A(G)},W=()=>Array.from(J.keys()).map((K)=>Number(K)).filter((K)=>Number.isInteger(K)).sort((K,G)=>K-G),I=(K,G)=>{if(G==null)throw new S(`store for key "${K}"`);if(G===L)return!0;if(c(G)||U(G)||d(G))throw new J$(`store for key "${K}"`,P(G));return!0},z=(K,G,A=!1)=>{if(!I(K,G))return!1;let M=f(G)||u(G)?G:R(G)||Array.isArray(G)?G$(G):v(G);J.set(K,M);let j=s(()=>i(()=>{Y("change",{[K]:M.get()})},j));if(j(),X.set(K,j),A)C(B),Y("add",{[K]:G});return!0},x=(K,G=!1)=>{let A=J.delete(K);if(A){let M=X.get(K);if(M)M.cleanup();X.delete(K)}if(G)C(B),Y("remove",{[K]:L});return A},q=(K,G,A)=>{let M=A$(K,G);return a(()=>{if(Object.keys(M.add).length){for(let j in M.add)z(j,M.add[j]??L);if(A)setTimeout(()=>{Y("add",M.add)},0);else Y("add",M.add)}if(Object.keys(M.change).length){for(let j in M.change){let _=M.change[j];if(!I(j,_))continue;let o=J.get(j);if(e(o))o.set(_);else throw new H$(j,P(_))}Y("change",M.change)}if(Object.keys(M.remove).length){for(let j in M.remove)x(j);Y("remove",M.remove)}}),M.changed};q({},$,!0);let D={};return Object.defineProperties(D,{[Symbol.toStringTag]:{value:N$},[Symbol.isConcatSpreadable]:{value:Q},[Symbol.iterator]:{value:Q?function*(){let K=W();for(let G of K){let A=J.get(String(G));if(A)yield A}}:function*(){for(let[K,G]of J)yield[K,G]}},add:{value:Q?(K)=>{z(String(J.size),K,!0)}:(K,G)=>{if(!J.has(K))z(K,G,!0);else throw new Q$(K,P(G))}},get:{value:()=>{return N(B),z$(H())}},remove:{value:Q?(K)=>{let G=z$(H()),A=J.size;if(!Array.isArray(G)||K<=-A||K>=A)throw new X$(K);let M=[...G];if(M.splice(K,1),q(G,M))C(B)}:(K)=>{if(J.has(K))x(K,!0)}},set:{value:(K)=>{if(q(H(),K)){if(C(B),L===K)B.clear()}}},update:{value:(K)=>{let G=H(),A=K(z$(G));if(q(G,A)){if(C(B),L===A)B.clear()}}},sort:{value:(K)=>{let G=Array.from(J.entries()).map(([j,_])=>[j,_.get()]).sort(K?(j,_)=>K(j[1],_[1]):(j,_)=>String(j[1]).localeCompare(String(_[1]))),A=G.map(([j])=>String(j)),M=new Map;G.forEach(([j],_)=>{let o=String(j),g=Q?String(_):String(j),p$=J.get(o);if(p$)M.set(g,p$)}),J.clear(),M.forEach((j,_)=>J.set(_,j)),C(B),Y("sort",A)}},on:{value:(K,G)=>{return Z[K].add(G),()=>Z[K].delete(G)}},length:{get(){return N(B),J.size}}}),new Proxy(D,{get(K,G){if(G in K)return Reflect.get(K,G);if(c(G))return;return J.get(G)},has(K,G){if(G in K)return!0;return J.has(String(G))},ownKeys(K){let G=Reflect.ownKeys(K),A=Q?W().map((M)=>String(M)):Array.from(J.keys());return[...new Set([...A,...G])]},getOwnPropertyDescriptor(K,G){if(G in K)return Reflect.getOwnPropertyDescriptor(K,G);let A=J.get(String(G));return A?{enumerable:!0,configurable:!0,writable:!0,value:A}:void 0}})},u=($)=>m($,N$);var h=($)=>f($)||d($)||u($),e=($)=>f($)||u($);function o$($){if(h($))return $;if(p($))return w($);if(Array.isArray($)||R($))return G$($);return v($)}var S$=!1,r$="debug";var t$="warn",$$="error",a$=new Set(["constructor","prototype"]),e$=new Set(["id","class","className","title","role","style","dataset","lang","dir","hidden","children","innerHTML","outerHTML","textContent","innerText"]),$B=($)=>$?`#${$}`:"",BB=($)=>$?.length?`.${Array.from($).join(".")}`:"";var y$=($)=>$.nodeType===Node.ELEMENT_NODE,w$=($)=>$.localName.includes("-"),E$=($)=>w$($)&&$.matches(":not(:defined)"),F=($)=>$?`<${$.localName}${$B($.id)}${BB($.classList)}>`:"<unknown>";var B$=($,B,Z=r$)=>{if(S$||[$$,t$].includes(Z))console[Z](B,$);return $},c$=($)=>{if(a$.has($))return`Property name "${$}" is a reserved word`;if(e$.has($))return`Property name "${$}" conflicts with inherited HTMLElement property`;return null};class n$ extends Error{constructor($,B){super(`Circular dependency detected in selection signal for component ${F($)} with selector "${B}"`);this.name="CircularMutationError"}}class D$ extends TypeError{constructor($){super(`Invalid component name "${$}". Custom element names must contain a hyphen, start with a lowercase letter, and contain only lowercase letters, numbers, and hyphens.`);this.name="InvalidComponentNameError"}}class j$ extends TypeError{constructor($,B,Z){super(`Invalid property name "${B}" for component <${$}>. ${Z}`);this.name="InvalidPropertyNameError"}}class L$ extends TypeError{constructor($,B){super(`Invalid effects in component ${F($)}. Effects must be a record of effects for UI elements or the component, or a Promise that resolves to effects.`);if(this.name="InvalidEffectsError",B)this.cause=B}}class W$ extends Error{constructor($,B,Z){super(`Missing required element <${B}> in component ${F($)}. ${Z}`);this.name="MissingElementError"}}class U$ extends Error{constructor($,B){super(`Timeout waiting for: [${B.join(", ")}] in component ${F($)}.`);this.name="DependencyTimeoutError"}}class F$ extends TypeError{constructor($,B,Z){super(`Expected reactives passed from ${F($)} to ${F(B)} to be a record of signals, reactive property names or functions. Got ${P(Z)}.`);this.name="InvalidReactivesError"}}class C$ extends TypeError{constructor($,B){super(`Target ${F($)} is not a custom element in ${B}.`);this.name="InvalidCustomElementError"}}var ZB="Collection",JB=($)=>{let B=new Set;if($.includes("."))B.add("class");if($.includes("#"))B.add("id");if($.includes("[")){let Z=$.split("[");for(let J=1;J<Z.length;J++){let X=Z[J];if(!X.includes("]"))continue;let Q=X.split("=")[0].trim().replace(/[^a-zA-Z0-9_-]/g,"");if(Q)B.add(Q)}}return[...B]};function k$($,B){let Z=new Set,J={add:new Set,remove:new Set},X=[],Q,H=(z)=>{let x=Array.from(z).filter(y$),q=[];for(let D of x){if(D.matches(B))q.push(D);q.push(...Array.from(D.querySelectorAll(B)))}return q},Y=(z,x)=>{Object.freeze(x);for(let q of z)q(x)},W=()=>{X=Array.from($.querySelectorAll(B)),Q=new MutationObserver((q)=>{let D=[],K=[];for(let G of q)if(G.type==="childList"){if(G.addedNodes.length)D.push(...H(G.addedNodes));if(G.removedNodes.length)K.push(...H(G.removedNodes))}else if(G.type==="attributes"){let A=G.target;if(y$(A)){let M=X.includes(A),j=A.matches(B);if(M&&!j)K.push(A);else if(!M&&j)D.push(A)}}if(D.length||K.length)X=Array.from($.querySelectorAll(B)),C(Z);if(D.length)Y(J.add,D);if(K.length)Y(J.remove,K)});let z={childList:!0,subtree:!0},x=JB(B);if(x.length)z.attributes=!0,z.attributeFilter=x;Q.observe($,z)},I={};return Object.defineProperties(I,{[Symbol.toStringTag]:{value:ZB},[Symbol.isConcatSpreadable]:{value:!0},[Symbol.iterator]:{value:function*(){for(let z of X)yield z}},get:{value:()=>{if(N(Z),!Q)W();return X}},on:{value:(z,x)=>{let q=J[z];if(!q)throw TypeError(`Invalid change notification type: ${z}`);if(q.add(x),!Q)W();return()=>q.delete(x)}},length:{get:()=>{if(N(Z),!Q)W();return X.length}}}),new Proxy(I,{get(z,x){if(x in z)return Reflect.get(z,x);if(c(x))return;let q=Number(x);if(Number.isInteger(q))return X[q];return},has(z,x){if(x in z)return!0;if(Number.isInteger(Number(x)))return!!X[Number(x)];return!1},ownKeys(z){let x=Reflect.ownKeys(z),q=Object.keys(X).map((D)=>String(D));return[...new Set([...q,...x])]},getOwnPropertyDescriptor(z,x){if(x in z)return Reflect.getOwnPropertyDescriptor(z,x);let q=X[Number(x)];return q?{enumerable:!0,configurable:!0,writable:!0,value:q}:void 0}})}var q$=($)=>Object.prototype.toString.call($)==="[object Collection]";var b$=Symbol("RESET"),QB=($,B="")=>{return{a:"attribute ",c:"class ",d:"dataset ",h:"inner HTML",m:"method call ",p:"property ",s:"style property ",t:"text content"}[$]+B},f$=($,B,Z)=>{let J=[],X=(Q)=>{let H=Q($,B);if(H)J.push(H)};if(Array.isArray(Z))for(let Q of Z)X(Q);else X(Z);return()=>{J.forEach((Q)=>Q()),J.length=0}},XB=($,B,Z)=>{let J=new Map,X=(H)=>{for(let Y of H){let W=f$($,Y,Z);if(W)J.set(Y,W)}},Q=(H)=>{for(let Y of H)J.get(Y)?.(),J.delete(Y)};return B.on("add",X),B.on("remove",Q),X(B.get()),()=>{for(let H of J.values())H();J.clear()}},h$=($,B)=>{if(!R(B))throw new L$($.host);let Z=[],J=Object.keys(B);for(let X of J){let Q=X;if(!B[Q])continue;let H=Array.isArray(B[Q])?B[Q]:[B[Q]];if(q$($[Q]))Z.push(XB($.host,$[Q],H));else if($[Q]){let Y=f$($.host,$[Q],H);if(Y)Z.push(Y)}}return()=>{for(let X of Z)X();Z.length=0}},HB=($,B,Z,J)=>{try{return V($)?B[$]:h($)?$.get():U($)?$(Z):b$}catch(X){if(J)B$(X,`Failed to resolve value of ${P($)}${J?` for ${J}`:""} in ${F(Z)}${B!==Z?` in ${F(B)}`:""}`,$$);return b$}},T=($,B)=>(Z,J)=>{let{op:X,name:Q="",read:H,update:Y}=B,W=QB(X,Q),I=(q)=>()=>{if(S$&&Z.debug)B$(J,`${q} ${W} of ${F(J)} in ${F(Z)}`);B.resolve?.(J)},z=(q)=>(D)=>{B$(D,`Failed to ${q} ${W} of ${F(J)} in ${F(Z)}`,$$),B.reject?.(D)},x=H(J);return M$(()=>{let q=HB($,Z,J,W),D=q===b$?x:q===L?B.delete?null:x:q;if(B.delete&&D===null)try{B.delete(J),I("delete")()}catch(K){z("delete")(K)}else if(D!=null){let K=H(J);if(Object.is(D,K))return;try{Y(J,D),I("update")()}catch(G){z("update")(G)}}})};var Z$=($)=>U($)&&$.length>=2,KB=($)=>U($),O=($,B)=>KB(B)?B($):B,YB=($,B)=>(Z)=>{let J=$(Z);return V(J)&&Z$(B)?B(Z,J):J??O(Z,B)};var GB=50,s$=($)=>{let B=$.shadowRoot??$,Z=new Set;function J(H,Y){let W=B.querySelector(H);if(Y!=null&&!W)throw new W$($,H,Y);if(W&&E$(W))Z.add(W.localName);return W??void 0}function X(H,Y){let W=k$(B,H),I=W.get();if(Y!=null&&!I.length)throw new W$($,H,Y);if(I.length)I.forEach((z)=>{if(E$(z))Z.add(z.localName)});return W}return[{first:J,all:X},(H)=>{if(Z.size){let Y=Array.from(Z);Promise.race([Promise.all(Y.map((W)=>customElements.whenDefined(W))),new Promise((W,I)=>{setTimeout(()=>{I(new U$($,Y.filter((z)=>!customElements.get(z))))},GB)})]).then(H).catch(()=>{H()})}else H()}]};function WB($,B={},Z=()=>({}),J=()=>({})){if(!$.includes("-")||!$.match(/^[a-z][a-z0-9-]*$/))throw new D$($);for(let Q of Object.keys(B)){let H=c$(Q);if(H)throw new j$($,Q,H)}class X extends HTMLElement{debug;#$;#B={};#Z;static observedAttributes=Object.entries(B)?.filter(([,Q])=>Z$(Q)).map(([Q])=>Q)??[];connectedCallback(){let[Q,H]=s$(this),Y={...Z(Q),host:this};this.#$=Y,Object.freeze(this.#$);let W=(z)=>{return U(z)},I=(z,x)=>{let q=Z$(x)?x(Y,this.getAttribute(z)):W(x)?x(Y):x;if(q!=null)this.#J(z,q)};for(let[z,x]of Object.entries(B)){if(x==null||z in this)continue;I(z,x)}H(()=>{this.#Z=h$(Y,J(Y))})}disconnectedCallback(){if(U(this.#Z))this.#Z()}attributeChangedCallback(Q,H,Y){if(!this.#$||Y===H||d(this.#B[Q]))return;let W=B[Q];if(!Z$(W))return;let I=W(this.#$,Y,H);if(Q in this)this[Q]=I;else this.#J(Q,I)}#J(Q,H){let Y=h(H)?H:p(H)?w(H):v(H),W=this.#B[Q],I=e(Y);if(this.#B[Q]=Y,Object.defineProperty(this,Q,{get:Y.get,set:I?Y.set:void 0,enumerable:!0,configurable:I}),W&&f(W)||u(W))W.set(L)}}return customElements.define($,X),customElements.get($)}var _$="context-request";class g$ extends Event{context;callback;subscribe;constructor($,B,Z=!1){super(_$,{bubbles:!0,composed:!0});this.context=$,this.callback=B,this.subscribe=Z}}var qB=($)=>(B)=>{let Z=(J)=>{let{context:X,callback:Q}=J;if(V(X)&&$.includes(X)&&U(Q))J.stopImmediatePropagation(),Q(()=>B[X])};return B.addEventListener(_$,Z),()=>B.removeEventListener(_$,Z)},zB=($,B)=>(Z)=>{let J=()=>O(Z,B);return Z.host.dispatchEvent(new g$($,(X)=>{J=X})),w(J)};var AB=($)=>{if(/^(mailto|tel):/i.test($))return!0;if($.includes("://"))try{let B=new URL($,window.location.origin);return["http:","https:","ftp:"].includes(B.protocol)}catch{return!1}return!0},xB=($,B,Z)=>{if(/^on/i.test(B))throw Error(`Unsafe attribute: ${B}`);if(Z=String(Z).trim(),!AB(Z))throw Error(`Unsafe URL for ${B}: ${Z}`);$.setAttribute(B,Z)},IB=($,B=$)=>T(B,{op:"a",name:$,read:(Z)=>Z.getAttribute($),update:(Z,J)=>{xB(Z,$,J)},delete:(Z)=>{Z.removeAttribute($)}}),MB=($,B=$)=>T(B,{op:"a",name:$,read:(Z)=>Z.hasAttribute($),update:(Z,J)=>{Z.toggleAttribute($,J)}});var DB=($,B=$)=>T(B,{op:"c",name:$,read:(Z)=>Z.classList.contains($),update:(Z,J)=>{Z.classList.toggle($,J)}});var P$=new Set(["scroll","resize","mousewheel","touchstart","touchmove","wheel"]),m$=new Set,i$=new WeakMap,R$,jB=()=>{R$=void 0;let $=Array.from(m$);m$.clear();for(let B of $)i$.get(B)?.()},LB=()=>{if(R$)cancelAnimationFrame(R$);R$=requestAnimationFrame(jB)},l=($,B)=>{i$.set($,B),m$.add($),LB()};var UB=($,B,Z={})=>(J,X)=>{if(!("passive"in Z))Z={...Z,passive:P$.has($)};let Q=(H)=>{let Y=()=>{let W=B(H);if(!R(W))return;a(()=>{for(let[I,z]of Object.entries(W))try{J[I]=z}catch(x){B$(x,`Reactive property "${I}" on ${F(J)} from event ${$} on ${F(X)} could not be set, because it is read-only.`,$$)}})};if(Z.passive)l(X,Y);else Y()};return X.addEventListener($,Q,Z),()=>X.removeEventListener($,Q)};var FB=($,B={})=>T($,{op:"h",read:(Z)=>(Z.shadowRoot||!B.shadowRootMode?Z:null)?.innerHTML??"",update:(Z,J)=>{let{shadowRootMode:X,allowScripts:Q}=B;if(!J){if(Z.shadowRoot)Z.shadowRoot.innerHTML="<slot></slot>";return""}if(X&&!Z.shadowRoot)Z.attachShadow({mode:X});let H=Z.shadowRoot||Z;return l(Z,()=>{if(H.innerHTML=J,Q)H.querySelectorAll("script").forEach((Y)=>{let W=document.createElement("script");W.appendChild(document.createTextNode(Y.textContent??""));let I=Y.getAttribute("type");if(I)W.setAttribute("type",I);H.appendChild(W),Y.remove()})}),Q?" with scripts":""}});var CB=($)=>(B,Z)=>{if(!w$(Z))throw new C$(Z,`pass from ${F(B)}`);let J=U($)?$(Z):$;if(!R(J))throw new F$(B,Z,J);let X={},Q=(H)=>{if(h(H))return H.get;let Y=V(H)&&H in B?()=>B[H]:p(H)?H:void 0;return Y?w(Y).get:void 0};for(let[H,Y]of Object.entries(J)){if(Y==null)continue;let W=Object.getOwnPropertyDescriptor(Z,H);if(!(H in Z)||!W?.configurable)continue;let I=U(Y)&&Y.length===1?Y(Z):Y,z=Array.isArray(I)&&I.length===2,x=Q(z?I[0]:I),q=z&&U(I[1])?I[1]:void 0;if(!x)continue;X[H]=W,Object.defineProperty(Z,H,{configurable:!0,enumerable:!0,get:x,set:q}),W.set?.call(Z,L)}return()=>{Object.defineProperties(Z,X)}};var _B=($,B=$)=>T(B,{op:"p",name:$,read:(Z)=>($ in Z)?Z[$]:L,update:(Z,J)=>{Z[$]=J}}),RB=($)=>T($,{op:"p",name:"hidden",read:(B)=>!B.hidden,update:(B,Z)=>{B.hidden=!Z}});var PB=($,B=$)=>T(B,{op:"s",name:$,read:(Z)=>Z.style.getPropertyValue($),update:(Z,J)=>{Z.style.setProperty($,J)},delete:(Z)=>{Z.style.removeProperty($)}});var TB=($)=>T($,{op:"t",read:(B)=>B.textContent,update:(B,Z)=>{Array.from(B.childNodes).filter((J)=>J.nodeType!==Node.COMMENT_NODE).forEach((J)=>J.remove()),B.append(document.createTextNode(Z))}});var OB=()=>($,B)=>B!=null&&B!=="false";var VB=($)=>(B,Z)=>{if((Z??$)==null)throw TypeError("asJSON: Value and fallback are both null or undefined");if(Z==null)return O(B,$);if(Z==="")throw TypeError("Empty string is not valid JSON");let J;try{J=JSON.parse(Z)}catch(X){throw SyntaxError(`Failed to parse JSON: ${String(X)}`,{cause:X})}return J??O(B,$)};var d$=($,B)=>{if(B==null)return;let Z=$(B);return Number.isFinite(Z)?Z:void 0},NB=($=0)=>(B,Z)=>{if(Z==null)return O(B,$);let J=Z.trim();if(J.toLowerCase().startsWith("0x"))return d$((Q)=>parseInt(Q,16),J)??O(B,$);let X=d$(parseFloat,Z);return X!=null?Math.trunc(X):O(B,$)},SB=($=0)=>(B,Z)=>d$(parseFloat,Z)??O(B,$);var yB=($="")=>(B,Z)=>Z??O(B,$),wB=($)=>(B,Z)=>{if(Z==null)return $[0];let J=Z.toLowerCase();return $.find((Q)=>Q.toLowerCase()===J)?Z:$[0]};var EB=($,B,Z)=>(J)=>{let{host:X}=J,Q=new Set,H=O(J,$),Y=q$(J[B])?J[B].get():[J[B]],W=new Map,I,z=(D)=>{for(let K of Y)if(K.contains(D))return K},x=()=>{for(let[D,K]of Object.entries(Z)){let G={passive:P$.has(D)},A=(M)=>{let j=M.target;if(!j)return;let _=z(j);if(!_)return;M.stopPropagation();let o=()=>{try{let g=K({event:M,ui:J,target:_,prev:H});if(g==null||g instanceof Promise)return;if(!Object.is(g,H)){if(H=g,Q.size)C(Q);else if(I)I()}}catch(g){throw M.stopImmediatePropagation(),g}};if(G.passive)l(X,o);else o()};W.set(D,A),X.addEventListener(D,A,G)}I=()=>{if(W.size){for(let[D,K]of W)X.removeEventListener(D,K);W.clear()}I=void 0}},q={};return Object.defineProperties(q,{[Symbol.toStringTag]:{value:Y$},get:{value:()=>{if(N(Q),Q.size&&!W.size)x();return H}}}),q};export{P as valueString,T as updateElement,DB as toggleClass,MB as toggleAttribute,o$ as toSignal,y as toError,RB as show,TB as setText,PB as setStyle,_B as setProperty,IB as setAttribute,l as schedule,f$ as runElementEffects,h$ as runEffects,u$ as resolve,zB as requestContext,YB as read,qB as provideContexts,CB as pass,UB as on,v$ as match,c as isSymbol,V as isString,u as isStore,f as isState,h as isSignal,K$ as isRecordOrArray,R as isRecord,Z$ as isParser,T$ as isNumber,e as isMutableSignal,U as isFunction,b as isEqual,d as isComputed,q$ as isCollection,r as isAsyncFunction,n as isAbortError,A$ as diff,WB as defineComponent,FB as dangerouslySetInnerHTML,G$ as createStore,v as createState,EB as createSensor,M$ as createEffect,w as createComputed,k$ as createCollection,a as batch,yB as asString,SB as asNumber,VB as asJSON,NB as asInteger,wB as asEnum,OB as asBoolean,L as UNSET,H$ as StoreKeyReadonlyError,X$ as StoreKeyRangeError,Q$ as StoreKeyExistsError,S as NullishSignalValueError,W$ as MissingElementError,J$ as InvalidSignalValueError,F$ as InvalidReactivesError,j$ as InvalidPropertyNameError,L$ as InvalidEffectsError,C$ as InvalidCustomElementError,D$ as InvalidComponentNameError,k as InvalidCallbackError,U$ as DependencyTimeoutError,g$ as ContextRequestEvent,n$ as CircularMutationError,E as CircularDependencyError,_$ as CONTEXT_REQUEST};
|
|
2
|
+
|
|
3
|
+
//# debugId=134762A4A421085564756E2164756E21
|
package/index.js.map
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["node_modules/@zeix/cause-effect/src/errors.ts", "node_modules/@zeix/cause-effect/src/util.ts", "node_modules/@zeix/cause-effect/src/diff.ts", "node_modules/@zeix/cause-effect/src/system.ts", "node_modules/@zeix/cause-effect/src/computed.ts", "node_modules/@zeix/cause-effect/src/effect.ts", "node_modules/@zeix/cause-effect/src/match.ts", "node_modules/@zeix/cause-effect/src/resolve.ts", "node_modules/@zeix/cause-effect/src/state.ts", "node_modules/@zeix/cause-effect/src/store.ts", "node_modules/@zeix/cause-effect/src/signal.ts", "src/util.ts", "src/errors.ts", "src/signals/collection.ts", "src/effects.ts", "src/parsers.ts", "src/ui.ts", "src/component.ts", "src/context.ts", "src/effects/attribute.ts", "src/effects/class.ts", "src/scheduler.ts", "src/effects/event.ts", "src/effects/html.ts", "src/effects/pass.ts", "src/effects/property.ts", "src/effects/style.ts", "src/effects/text.ts", "src/parsers/boolean.ts", "src/parsers/json.ts", "src/parsers/number.ts", "src/parsers/string.ts", "src/signals/sensor.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"class CircularDependencyError extends Error {\n\tconstructor(where: string) {\n\t\tsuper(`Circular dependency detected in ${where}`)\n\t\tthis.name = 'CircularDependencyError'\n\t}\n}\n\nclass InvalidCallbackError extends TypeError {\n\tconstructor(where: string, value: string) {\n\t\tsuper(`Invalid ${where} callback ${value}`)\n\t\tthis.name = 'InvalidCallbackError'\n\t}\n}\n\nclass InvalidSignalValueError extends TypeError {\n\tconstructor(where: string, value: string) {\n\t\tsuper(`Invalid signal value ${value} in ${where}`)\n\t\tthis.name = 'InvalidSignalValueError'\n\t}\n}\n\nclass NullishSignalValueError extends TypeError {\n\tconstructor(where: string) {\n\t\tsuper(`Nullish signal values are not allowed in ${where}`)\n\t\tthis.name = 'NullishSignalValueError'\n\t}\n}\n\nclass StoreKeyExistsError extends Error {\n\tconstructor(key: string, value: string) {\n\t\tsuper(\n\t\t\t`Could not add store key \"${key}\" with value ${value} because it already exists`,\n\t\t)\n\t\tthis.name = 'StoreKeyExistsError'\n\t}\n}\n\nclass StoreKeyRangeError extends RangeError {\n\tconstructor(index: number) {\n\t\tsuper(\n\t\t\t`Could not remove store index ${String(index)} because it is out of range`,\n\t\t)\n\t\tthis.name = 'StoreKeyRangeError'\n\t}\n}\n\nclass StoreKeyReadonlyError extends Error {\n\tconstructor(key: string, value: string) {\n\t\tsuper(\n\t\t\t`Could not set store key \"${key}\" to ${value} because it is readonly`,\n\t\t)\n\t\tthis.name = 'StoreKeyReadonlyError'\n\t}\n}\n\nexport {\n\tCircularDependencyError,\n\tInvalidCallbackError,\n\tInvalidSignalValueError,\n\tNullishSignalValueError,\n\tStoreKeyExistsError,\n\tStoreKeyRangeError,\n\tStoreKeyReadonlyError,\n}\n",
|
|
6
|
+
"/* === Constants === */\n\n// biome-ignore lint/suspicious/noExplicitAny: Deliberately using any to be used as a placeholder value in any signal\nconst UNSET: any = Symbol()\n\n/* === Utility Functions === */\n\nconst isString = /*#__PURE__*/ (value: unknown): value is string =>\n\ttypeof value === 'string'\n\nconst isNumber = /*#__PURE__*/ (value: unknown): value is number =>\n\ttypeof value === 'number'\n\nconst isSymbol = /*#__PURE__*/ (value: unknown): value is symbol =>\n\ttypeof value === 'symbol'\n\nconst isFunction = /*#__PURE__*/ <T>(\n\tfn: unknown,\n): fn is (...args: unknown[]) => T => typeof fn === 'function'\n\nconst isAsyncFunction = /*#__PURE__*/ <T>(\n\tfn: unknown,\n): fn is (...args: unknown[]) => Promise<T> =>\n\tisFunction(fn) && fn.constructor.name === 'AsyncFunction'\n\nconst isObjectOfType = /*#__PURE__*/ <T>(\n\tvalue: unknown,\n\ttype: string,\n): value is T => Object.prototype.toString.call(value) === `[object ${type}]`\n\nconst isRecord = /*#__PURE__*/ <T extends Record<string, unknown>>(\n\tvalue: unknown,\n): value is T => isObjectOfType(value, 'Object')\n\nconst isRecordOrArray = /*#__PURE__*/ <\n\tT extends Record<string | number, unknown> | ReadonlyArray<unknown>,\n>(\n\tvalue: unknown,\n): value is T => isRecord(value) || Array.isArray(value)\n\nconst validArrayIndexes = /*#__PURE__*/ (\n\tkeys: Array<PropertyKey>,\n): number[] | null => {\n\tif (!keys.length) return null\n\tconst indexes = keys.map(k =>\n\t\tisString(k) ? parseInt(k, 10) : isNumber(k) ? k : NaN,\n\t)\n\treturn indexes.every(index => Number.isFinite(index) && index >= 0)\n\t\t? indexes.sort((a, b) => a - b)\n\t\t: null\n}\n\nconst hasMethod = /*#__PURE__*/ <\n\tT extends object & Record<string, (...args: unknown[]) => unknown>,\n>(\n\tobj: T,\n\tmethodName: string,\n): obj is T & Record<string, (...args: unknown[]) => unknown> =>\n\tmethodName in obj && isFunction(obj[methodName])\n\nconst isAbortError = /*#__PURE__*/ (error: unknown): boolean =>\n\terror instanceof DOMException && error.name === 'AbortError'\n\nconst toError = /*#__PURE__*/ (reason: unknown): Error =>\n\treason instanceof Error ? reason : Error(String(reason))\n\nconst arrayToRecord = /*#__PURE__*/ <T>(array: T[]): Record<string, T> => {\n\tconst record: Record<string, T> = {}\n\tfor (let i = 0; i < array.length; i++) record[String(i)] = array[i]\n\treturn record\n}\n\nconst recordToArray = /*#__PURE__*/ <T>(\n\trecord: Record<string | number, T>,\n): Record<string, T> | T[] => {\n\tconst indexes = validArrayIndexes(Object.keys(record))\n\tif (indexes === null) return record\n\n\tconst array: T[] = []\n\tfor (const index of indexes) array.push(record[String(index)])\n\treturn array\n}\n\nconst valueString = /*#__PURE__*/ (value: unknown): string =>\n\tisString(value)\n\t\t? `\"${value}\"`\n\t\t: !!value && typeof value === 'object'\n\t\t\t? JSON.stringify(value)\n\t\t\t: String(value)\n\n/* === Exports === */\n\nexport {\n\tUNSET,\n\tisString,\n\tisNumber,\n\tisSymbol,\n\tisFunction,\n\tisAsyncFunction,\n\tisObjectOfType,\n\tisRecord,\n\tisRecordOrArray,\n\thasMethod,\n\tisAbortError,\n\ttoError,\n\tarrayToRecord,\n\trecordToArray,\n\tvalueString,\n}\n",
|
|
7
|
+
"import { CircularDependencyError } from './errors'\nimport { isRecord, isRecordOrArray, UNSET } from './util'\n\n/* === Types === */\n\ntype UnknownRecord = Record<string, unknown & {}>\ntype UnknownArray = ReadonlyArray<unknown & {}>\n\ntype ArrayToRecord<T extends UnknownArray> = {\n\t[key: string]: T extends Array<infer U extends {}> ? U : never\n}\n\ntype PartialRecord<T> = T extends UnknownArray\n\t? Partial<ArrayToRecord<T>>\n\t: Partial<T>\n\ntype DiffResult<T extends UnknownRecord | UnknownArray = UnknownRecord> = {\n\tchanged: boolean\n\tadd: PartialRecord<T>\n\tchange: PartialRecord<T>\n\tremove: PartialRecord<T>\n}\n\n/* === Functions === */\n\n/**\n * Checks if two values are equal with cycle detection\n *\n * @since 0.15.0\n * @param {T} a - First value to compare\n * @param {T} b - Second value to compare\n * @param {WeakSet<object>} visited - Set to track visited objects for cycle detection\n * @returns {boolean} Whether the two values are equal\n */\nconst isEqual = <T>(a: T, b: T, visited?: WeakSet<object>): boolean => {\n\t// Fast paths\n\tif (Object.is(a, b)) return true\n\tif (typeof a !== typeof b) return false\n\tif (typeof a !== 'object' || a === null || b === null) return false\n\n\t// Cycle detection\n\tif (!visited) visited = new WeakSet()\n\tif (visited.has(a as object) || visited.has(b as object))\n\t\tthrow new CircularDependencyError('isEqual')\n\tvisited.add(a as object)\n\tvisited.add(b as object)\n\n\ttry {\n\t\tif (Array.isArray(a) && Array.isArray(b)) {\n\t\t\tif (a.length !== b.length) return false\n\t\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\t\tif (!isEqual(a[i], b[i], visited)) return false\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\n\t\tif (Array.isArray(a) !== Array.isArray(b)) return false\n\n\t\tif (isRecord(a) && isRecord(b)) {\n\t\t\tconst aKeys = Object.keys(a)\n\t\t\tconst bKeys = Object.keys(b)\n\n\t\t\tif (aKeys.length !== bKeys.length) return false\n\t\t\tfor (const key of aKeys) {\n\t\t\t\tif (!(key in b)) return false\n\t\t\t\tif (\n\t\t\t\t\t!isEqual(\n\t\t\t\t\t\t(a as Record<string, unknown>)[key],\n\t\t\t\t\t\t(b as Record<string, unknown>)[key],\n\t\t\t\t\t\tvisited,\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\n\t\t// For non-records/non-arrays, they are only equal if they are the same reference\n\t\t// (which would have been caught by Object.is at the beginning)\n\t\treturn false\n\t} finally {\n\t\tvisited.delete(a as object)\n\t\tvisited.delete(b as object)\n\t}\n}\n\n/**\n * Compares two records and returns a result object containing the differences.\n *\n * @since 0.15.0\n * @param {T} oldObj - The old record to compare\n * @param {T} newObj - The new record to compare\n * @returns {DiffResult<T>} The result of the comparison\n */\nconst diff = <T extends UnknownRecord | UnknownArray>(\n\toldObj: T extends UnknownArray ? ArrayToRecord<T> : T,\n\tnewObj: T extends UnknownArray ? ArrayToRecord<T> : T,\n): DiffResult<T> => {\n\t// Guard against non-objects that can't be diffed properly with Object.keys and 'in' operator\n\tconst oldValid = isRecordOrArray(oldObj)\n\tconst newValid = isRecordOrArray(newObj)\n\tif (!oldValid || !newValid) {\n\t\t// For non-objects or non-plain objects, treat as complete change if different\n\t\tconst changed = !Object.is(oldObj, newObj)\n\t\treturn {\n\t\t\tchanged,\n\t\t\tadd: changed && newValid ? newObj : ({} as PartialRecord<T>),\n\t\t\tchange: {} as PartialRecord<T>,\n\t\t\tremove: changed && oldValid ? oldObj : ({} as PartialRecord<T>),\n\t\t}\n\t}\n\n\tconst visited = new WeakSet()\n\n\tconst add = {} as PartialRecord<T>\n\tconst change = {} as PartialRecord<T>\n\tconst remove = {} as PartialRecord<T>\n\n\tconst oldKeys = Object.keys(oldObj)\n\tconst newKeys = Object.keys(newObj)\n\tconst allKeys = new Set([...oldKeys, ...newKeys])\n\n\tfor (const key of allKeys) {\n\t\tconst oldHas = key in oldObj\n\t\tconst newHas = key in newObj\n\n\t\tif (!oldHas && newHas) {\n\t\t\tadd[key] = newObj[key]\n\t\t\tcontinue\n\t\t} else if (oldHas && !newHas) {\n\t\t\tremove[key] = UNSET\n\t\t\tcontinue\n\t\t}\n\n\t\tconst oldValue = oldObj[key]\n\t\tconst newValue = newObj[key]\n\n\t\tif (!isEqual(oldValue, newValue, visited)) change[key] = newValue\n\t}\n\n\tconst changed =\n\t\tObject.keys(add).length > 0 ||\n\t\tObject.keys(change).length > 0 ||\n\t\tObject.keys(remove).length > 0\n\n\treturn {\n\t\tchanged,\n\t\tadd,\n\t\tchange,\n\t\tremove,\n\t}\n}\n\n/* === Exports === */\n\nexport {\n\ttype ArrayToRecord,\n\ttype DiffResult,\n\tdiff,\n\tisEqual,\n\ttype UnknownRecord,\n\ttype UnknownArray,\n\ttype PartialRecord,\n}\n",
|
|
8
|
+
"/* === Types === */\n\ntype Cleanup = () => void\n\ntype Watcher = {\n\t(): void\n\tunwatch(cleanup: Cleanup): void\n\tcleanup(): void\n}\n\n/* === Internal === */\n\n// Currently active watcher\nlet activeWatcher: Watcher | undefined\n\n// Pending queue for batched change notifications\nconst pendingWatchers = new Set<Watcher>()\nlet batchDepth = 0\n\n/* === Functions === */\n\n/**\n * Create a watcher that can be used to observe changes to a signal\n *\n * @since 0.14.1\n * @param {() => void} watch - Function to be called when the state changes\n * @returns {Watcher} - Watcher object with off and cleanup methods\n */\nconst createWatcher = (watch: () => void): Watcher => {\n\tconst cleanups = new Set<Cleanup>()\n\tconst w = watch as Partial<Watcher>\n\tw.unwatch = (cleanup: Cleanup) => {\n\t\tcleanups.add(cleanup)\n\t}\n\tw.cleanup = () => {\n\t\tfor (const cleanup of cleanups) cleanup()\n\t\tcleanups.clear()\n\t}\n\treturn w as Watcher\n}\n\n/**\n * Add active watcher to the Set of watchers\n *\n * @param {Set<Watcher>} watchers - watchers of the signal\n */\nconst subscribe = (watchers: Set<Watcher>) => {\n\tif (activeWatcher && !watchers.has(activeWatcher)) {\n\t\tconst watcher = activeWatcher\n\t\twatcher.unwatch(() => {\n\t\t\twatchers.delete(watcher)\n\t\t})\n\t\twatchers.add(watcher)\n\t}\n}\n\n/**\n * Add watchers to the pending set of change notifications\n *\n * @param {Set<Watcher>} watchers - watchers of the signal\n */\nconst notify = (watchers: Set<Watcher>) => {\n\tfor (const watcher of watchers) {\n\t\tif (batchDepth) pendingWatchers.add(watcher)\n\t\telse watcher()\n\t}\n}\n\n/**\n * Flush all pending changes to notify watchers\n */\nconst flush = () => {\n\twhile (pendingWatchers.size) {\n\t\tconst watchers = Array.from(pendingWatchers)\n\t\tpendingWatchers.clear()\n\t\tfor (const watcher of watchers) watcher()\n\t}\n}\n\n/**\n * Batch multiple changes in a single signal graph and DOM update cycle\n *\n * @param {() => void} fn - function with multiple signal writes to be batched\n */\nconst batch = (fn: () => void) => {\n\tbatchDepth++\n\ttry {\n\t\tfn()\n\t} finally {\n\t\tflush()\n\t\tbatchDepth--\n\t}\n}\n\n/**\n * Run a function in a reactive context\n *\n * @param {() => void} run - function to run the computation or effect\n * @param {Watcher} watcher - function to be called when the state changes or undefined for temporary unwatching while inserting auto-hydrating DOM nodes that might read signals (e.g., web components)\n */\nconst observe = (run: () => void, watcher?: Watcher): void => {\n\tconst prev = activeWatcher\n\tactiveWatcher = watcher\n\ttry {\n\t\trun()\n\t} finally {\n\t\tactiveWatcher = prev\n\t}\n}\n\n/* === Exports === */\n\nexport {\n\ttype Cleanup,\n\ttype Watcher,\n\tsubscribe,\n\tnotify,\n\tflush,\n\tbatch,\n\tcreateWatcher,\n\tobserve,\n}\n",
|
|
9
|
+
"import { isEqual } from './diff'\nimport {\n\tCircularDependencyError,\n\tInvalidCallbackError,\n\tNullishSignalValueError,\n} from './errors'\nimport {\n\tcreateWatcher,\n\tflush,\n\tnotify,\n\tobserve,\n\tsubscribe,\n\ttype Watcher,\n} from './system'\nimport {\n\tisAbortError,\n\tisAsyncFunction,\n\tisFunction,\n\tisObjectOfType,\n\ttoError,\n\tUNSET,\n\tvalueString,\n} from './util'\n\n/* === Types === */\n\ntype Computed<T extends {}> = {\n\treadonly [Symbol.toStringTag]: 'Computed'\n\tget(): T\n}\ntype ComputedCallback<T extends {} & { then?: undefined }> =\n\t| ((oldValue: T, abort: AbortSignal) => Promise<T>)\n\t| ((oldValue: T) => T)\n\n/* === Constants === */\n\nconst TYPE_COMPUTED = 'Computed'\n\n/* === Functions === */\n\n/**\n * Create a derived signal from existing signals\n *\n * @since 0.9.0\n * @param {ComputedCallback<T>} callback - Computation callback function\n * @returns {Computed<T>} - Computed signal\n */\nconst createComputed = <T extends {}>(\n\tcallback: ComputedCallback<T>,\n\tinitialValue: T = UNSET,\n): Computed<T> => {\n\tif (!isComputedCallback(callback))\n\t\tthrow new InvalidCallbackError('computed', valueString(callback))\n\tif (initialValue == null) throw new NullishSignalValueError('computed')\n\n\tconst watchers: Set<Watcher> = new Set()\n\n\t// Internal state\n\tlet value: T = initialValue\n\tlet error: Error | undefined\n\tlet controller: AbortController | undefined\n\tlet dirty = true\n\tlet changed = false\n\tlet computing = false\n\n\t// Functions to update internal state\n\tconst ok = (v: T): undefined => {\n\t\tif (!isEqual(v, value)) {\n\t\t\tvalue = v\n\t\t\tchanged = true\n\t\t}\n\t\terror = undefined\n\t\tdirty = false\n\t}\n\tconst nil = (): undefined => {\n\t\tchanged = UNSET !== value\n\t\tvalue = UNSET\n\t\terror = undefined\n\t}\n\tconst err = (e: unknown): undefined => {\n\t\tconst newError = toError(e)\n\t\tchanged =\n\t\t\t!error ||\n\t\t\tnewError.name !== error.name ||\n\t\t\tnewError.message !== error.message\n\t\tvalue = UNSET\n\t\terror = newError\n\t}\n\tconst settle =\n\t\t<T>(fn: (arg: T) => void) =>\n\t\t(arg: T) => {\n\t\t\tcomputing = false\n\t\t\tcontroller = undefined\n\t\t\tfn(arg)\n\t\t\tif (changed) notify(watchers)\n\t\t}\n\n\t// Own watcher: called when notified from sources (push)\n\tconst watcher = createWatcher(() => {\n\t\tdirty = true\n\t\tcontroller?.abort()\n\t\tif (watchers.size) notify(watchers)\n\t\telse watcher.cleanup()\n\t})\n\twatcher.unwatch(() => {\n\t\tcontroller?.abort()\n\t})\n\n\t// Called when requested by dependencies (pull)\n\tconst compute = () =>\n\t\tobserve(() => {\n\t\t\tif (computing) throw new CircularDependencyError('computed')\n\t\t\tchanged = false\n\t\t\tif (isAsyncFunction(callback)) {\n\t\t\t\t// Return current value until promise resolves\n\t\t\t\tif (controller) return value\n\t\t\t\tcontroller = new AbortController()\n\t\t\t\tcontroller.signal.addEventListener(\n\t\t\t\t\t'abort',\n\t\t\t\t\t() => {\n\t\t\t\t\t\tcomputing = false\n\t\t\t\t\t\tcontroller = undefined\n\t\t\t\t\t\tcompute() // Retry computation with updated state\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tonce: true,\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t}\n\t\t\tlet result: T | Promise<T>\n\t\t\tcomputing = true\n\t\t\ttry {\n\t\t\t\tresult = controller\n\t\t\t\t\t? callback(value, controller.signal)\n\t\t\t\t\t: (callback as (oldValue: T) => T)(value)\n\t\t\t} catch (e) {\n\t\t\t\tif (isAbortError(e)) nil()\n\t\t\t\telse err(e)\n\t\t\t\tcomputing = false\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (result instanceof Promise) result.then(settle(ok), settle(err))\n\t\t\telse if (null == result || UNSET === result) nil()\n\t\t\telse ok(result)\n\t\t\tcomputing = false\n\t\t}, watcher)\n\n\tconst computed: Record<PropertyKey, unknown> = {}\n\tObject.defineProperties(computed, {\n\t\t[Symbol.toStringTag]: {\n\t\t\tvalue: TYPE_COMPUTED,\n\t\t},\n\t\tget: {\n\t\t\tvalue: (): T => {\n\t\t\t\tsubscribe(watchers)\n\t\t\t\tflush()\n\t\t\t\tif (dirty) compute()\n\t\t\t\tif (error) throw error\n\t\t\t\treturn value\n\t\t\t},\n\t\t},\n\t})\n\treturn computed as Computed<T>\n}\n\n/**\n * Check if a value is a computed signal\n *\n * @since 0.9.0\n * @param {unknown} value - Value to check\n * @returns {boolean} - true if value is a computed signal, false otherwise\n */\nconst isComputed = /*#__PURE__*/ <T extends {}>(\n\tvalue: unknown,\n): value is Computed<T> => isObjectOfType(value, TYPE_COMPUTED)\n\n/**\n * Check if the provided value is a callback that may be used as input for toSignal() to derive a computed state\n *\n * @since 0.12.0\n * @param {unknown} value - Value to check\n * @returns {boolean} - true if value is a callback or callbacks object, false otherwise\n */\nconst isComputedCallback = /*#__PURE__*/ <T extends {}>(\n\tvalue: unknown,\n): value is ComputedCallback<T> => isFunction(value) && value.length < 3\n\n/* === Exports === */\n\nexport {\n\tTYPE_COMPUTED,\n\tcreateComputed,\n\tisComputed,\n\tisComputedCallback,\n\ttype Computed,\n\ttype ComputedCallback,\n}\n",
|
|
10
|
+
"import { CircularDependencyError, InvalidCallbackError } from './errors'\nimport { type Cleanup, createWatcher, observe } from './system'\nimport { isAbortError, isAsyncFunction, isFunction, valueString } from './util'\n\n/* === Types === */\n\n// biome-ignore lint/suspicious/noConfusingVoidType: optional Cleanup return type\ntype MaybeCleanup = Cleanup | undefined | void\n\ntype EffectCallback =\n\t| (() => MaybeCleanup)\n\t| ((abort: AbortSignal) => Promise<MaybeCleanup>)\n\n/* === Functions === */\n\n/**\n * Define what happens when a reactive state changes\n *\n * The callback can be synchronous or asynchronous. Async callbacks receive\n * an AbortSignal parameter, which is automatically aborted when the effect\n * re-runs or is cleaned up, preventing stale async operations.\n *\n * @since 0.1.0\n * @param {EffectCallback} callback - Synchronous or asynchronous effect callback\n * @returns {Cleanup} - Cleanup function for the effect\n */\nconst createEffect = (callback: EffectCallback): Cleanup => {\n\tif (!isFunction(callback) || callback.length > 1)\n\t\tthrow new InvalidCallbackError('effect', valueString(callback))\n\n\tconst isAsync = isAsyncFunction(callback)\n\tlet running = false\n\tlet controller: AbortController | undefined\n\n\tconst watcher = createWatcher(() =>\n\t\tobserve(() => {\n\t\t\tif (running) throw new CircularDependencyError('effect')\n\t\t\trunning = true\n\n\t\t\t// Abort any previous async operations\n\t\t\tcontroller?.abort()\n\t\t\tcontroller = undefined\n\n\t\t\tlet cleanup: MaybeCleanup | Promise<MaybeCleanup>\n\n\t\t\ttry {\n\t\t\t\tif (isAsync) {\n\t\t\t\t\t// Create AbortController for async callback\n\t\t\t\t\tcontroller = new AbortController()\n\t\t\t\t\tconst currentController = controller\n\t\t\t\t\tcallback(controller.signal)\n\t\t\t\t\t\t.then(cleanup => {\n\t\t\t\t\t\t\t// Only register cleanup if this is still the current controller\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tisFunction(cleanup) &&\n\t\t\t\t\t\t\t\tcontroller === currentController\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\twatcher.unwatch(cleanup)\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.catch(error => {\n\t\t\t\t\t\t\tif (!isAbortError(error))\n\t\t\t\t\t\t\t\tconsole.error('Async effect error:', error)\n\t\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tcleanup = (callback as () => MaybeCleanup)()\n\t\t\t\t\tif (isFunction(cleanup)) watcher.unwatch(cleanup)\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (!isAbortError(error))\n\t\t\t\t\tconsole.error('Effect callback error:', error)\n\t\t\t}\n\n\t\t\trunning = false\n\t\t}, watcher),\n\t)\n\n\twatcher()\n\treturn () => {\n\t\tcontroller?.abort()\n\t\twatcher.cleanup()\n\t}\n}\n\n/* === Exports === */\n\nexport { type MaybeCleanup, type EffectCallback, createEffect }\n",
|
|
11
|
+
"import type { ResolveResult } from './resolve'\nimport type { SignalValues, UnknownSignalRecord } from './signal'\nimport { toError } from './util'\n\n/* === Types === */\n\ntype MatchHandlers<S extends UnknownSignalRecord> = {\n\tok: (values: SignalValues<S>) => void\n\terr?: (errors: readonly Error[]) => void\n\tnil?: () => void\n}\n\n/* === Functions === */\n\n/**\n * Match on resolve result and call appropriate handler for side effects\n *\n * This is a utility function for those who prefer the handler pattern.\n * All handlers are for side effects only and return void. If you need\n * cleanup logic, use a hoisted let variable in your effect.\n *\n * @since 0.15.0\n * @param {ResolveResult<S>} result - Result from resolve()\n * @param {MatchHandlers<S>} handlers - Handlers for different states (side effects only)\n * @returns {void} - Always returns void\n */\nfunction match<S extends UnknownSignalRecord>(\n\tresult: ResolveResult<S>,\n\thandlers: MatchHandlers<S>,\n): void {\n\ttry {\n\t\tif (result.pending) handlers.nil?.()\n\t\telse if (result.errors) handlers.err?.(result.errors)\n\t\telse if (result.ok) handlers.ok(result.values)\n\t} catch (error) {\n\t\t// If handler throws, try error handler, otherwise rethrow\n\t\tif (\n\t\t\thandlers.err &&\n\t\t\t(!result.errors || !result.errors.includes(toError(error)))\n\t\t)\n\t\t\thandlers.err(\n\t\t\t\tresult.errors\n\t\t\t\t\t? [...result.errors, toError(error)]\n\t\t\t\t\t: [toError(error)],\n\t\t\t)\n\t\telse throw error\n\t}\n}\n\n/* === Exports === */\n\nexport { match, type MatchHandlers }\n",
|
|
12
|
+
"import type { UnknownRecord } from './diff'\nimport type { SignalValues, UnknownSignalRecord } from './signal'\nimport { toError, UNSET } from './util'\n\n/* === Types === */\n\ntype ResolveResult<S extends UnknownSignalRecord> =\n\t| { ok: true; values: SignalValues<S>; errors?: never; pending?: never }\n\t| { ok: false; errors: readonly Error[]; values?: never; pending?: never }\n\t| { ok: false; pending: true; values?: never; errors?: never }\n\n/* === Functions === */\n\n/**\n * Resolve signal values with perfect type inference\n *\n * Always returns a discriminated union result, regardless of whether\n * handlers are provided or not. This ensures a predictable API.\n *\n * @since 0.15.0\n * @param {S} signals - Signals to resolve\n * @returns {ResolveResult<S>} - Discriminated union result\n */\nfunction resolve<S extends UnknownSignalRecord>(signals: S): ResolveResult<S> {\n\tconst errors: Error[] = []\n\tlet pending = false\n\tconst values: UnknownRecord = {}\n\n\t// Collect values and errors\n\tfor (const [key, signal] of Object.entries(signals)) {\n\t\ttry {\n\t\t\tconst value = signal.get()\n\t\t\tif (value === UNSET) pending = true\n\t\t\telse values[key] = value\n\t\t} catch (e) {\n\t\t\terrors.push(toError(e))\n\t\t}\n\t}\n\n\t// Return discriminated union\n\tif (pending) return { ok: false, pending: true }\n\tif (errors.length > 0) return { ok: false, errors }\n\treturn { ok: true, values: values as SignalValues<S> }\n}\n\n/* === Exports === */\n\nexport { resolve, type ResolveResult }\n",
|
|
13
|
+
"import { isEqual } from './diff'\nimport { InvalidCallbackError, NullishSignalValueError } from './errors'\nimport { notify, subscribe, type Watcher } from './system'\nimport { isFunction, isObjectOfType, UNSET, valueString } from './util'\n\n/* === Types === */\n\ntype State<T extends {}> = {\n\treadonly [Symbol.toStringTag]: 'State'\n\tget(): T\n\tset(newValue: T): void\n\tupdate(updater: (oldValue: T) => T): void\n}\n\n/* === Constants === */\n\nconst TYPE_STATE = 'State'\n\n/* === Functions === */\n\n/**\n * Create a new state signal\n *\n * @since 0.9.0\n * @param {T} initialValue - initial value of the state\n * @returns {State<T>} - new state signal\n */\nconst createState = /*#__PURE__*/ <T extends {}>(initialValue: T): State<T> => {\n\tif (initialValue == null) throw new NullishSignalValueError('state')\n\n\tconst watchers: Set<Watcher> = new Set()\n\tlet value: T = initialValue\n\n\tconst setValue = (newValue: T) => {\n\t\tif (newValue == null) throw new NullishSignalValueError('state')\n\t\tif (isEqual(value, newValue)) return\n\t\tvalue = newValue\n\t\tnotify(watchers)\n\n\t\t// Setting to UNSET clears the watchers so the signal can be garbage collected\n\t\tif (UNSET === value) watchers.clear()\n\t}\n\n\tconst state: Record<PropertyKey, unknown> = {}\n\tObject.defineProperties(state, {\n\t\t[Symbol.toStringTag]: {\n\t\t\tvalue: TYPE_STATE,\n\t\t},\n\t\tget: {\n\t\t\tvalue: () => {\n\t\t\t\tsubscribe(watchers)\n\t\t\t\treturn value\n\t\t\t},\n\t\t},\n\t\tset: {\n\t\t\tvalue: (newValue: T) => {\n\t\t\t\tsetValue(newValue)\n\t\t\t},\n\t\t},\n\t\tupdate: {\n\t\t\tvalue: (updater: (oldValue: T) => T) => {\n\t\t\t\tif (!isFunction(updater))\n\t\t\t\t\tthrow new InvalidCallbackError(\n\t\t\t\t\t\t'state update',\n\t\t\t\t\t\tvalueString(updater),\n\t\t\t\t\t)\n\t\t\t\tsetValue(updater(value))\n\t\t\t},\n\t\t},\n\t})\n\treturn state as State<T>\n}\n\n/**\n * Check if the provided value is a State instance\n *\n * @since 0.9.0\n * @param {unknown} value - value to check\n * @returns {boolean} - true if the value is a State instance, false otherwise\n */\nconst isState = /*#__PURE__*/ <T extends {}>(\n\tvalue: unknown,\n): value is State<T> => isObjectOfType(value, TYPE_STATE)\n\n/* === Exports === */\n\nexport { TYPE_STATE, isState, createState, type State }\n",
|
|
14
|
+
"import { isComputed } from './computed'\nimport {\n\ttype ArrayToRecord,\n\tdiff,\n\ttype PartialRecord,\n\ttype UnknownArray,\n\ttype UnknownRecord,\n} from './diff'\nimport {\n\tInvalidSignalValueError,\n\tNullishSignalValueError,\n\tStoreKeyExistsError,\n\tStoreKeyRangeError,\n\tStoreKeyReadonlyError,\n} from './errors'\nimport { isMutableSignal, type Signal } from './signal'\nimport { createState, isState, type State } from './state'\nimport {\n\tbatch,\n\ttype Cleanup,\n\tcreateWatcher,\n\tnotify,\n\tobserve,\n\tsubscribe,\n\ttype Watcher,\n} from './system'\nimport {\n\tisFunction,\n\tisObjectOfType,\n\tisRecord,\n\tisSymbol,\n\trecordToArray,\n\tUNSET,\n\tvalueString,\n} from './util'\n\n/* === Types === */\n\ntype ArrayItem<T> = T extends readonly (infer U extends {})[] ? U : never\n\ntype StoreChanges<T> = {\n\tadd: PartialRecord<T>\n\tchange: PartialRecord<T>\n\tremove: PartialRecord<T>\n\tsort: string[]\n}\n\ntype StoreListeners<T> = {\n\t[K in keyof StoreChanges<T>]: Set<(change: StoreChanges<T>[K]) => void>\n}\n\ninterface BaseStore {\n\treadonly [Symbol.toStringTag]: 'Store'\n\treadonly length: number\n}\n\ntype RecordStore<T extends UnknownRecord> = BaseStore & {\n\t[K in keyof T]: T[K] extends readonly unknown[] | Record<string, unknown>\n\t\t? Store<T[K]>\n\t\t: State<T[K]>\n} & {\n\t[Symbol.iterator](): IterableIterator<\n\t\t[\n\t\t\tExtract<keyof T, string>,\n\t\t\tT[Extract<keyof T, string>] extends\n\t\t\t\t| readonly unknown[]\n\t\t\t\t| Record<string, unknown>\n\t\t\t\t? Store<T[Extract<keyof T, string>]>\n\t\t\t\t: State<T[Extract<keyof T, string>]>,\n\t\t]\n\t>\n\tadd<K extends Extract<keyof T, string>>(key: K, value: T[K]): void\n\tget(): T\n\tset(value: T): void\n\tupdate(fn: (value: T) => T): void\n\tsort<U = T[Extract<keyof T, string>]>(\n\t\tcompareFn?: (a: U, b: U) => number,\n\t): void\n\ton<K extends keyof StoreChanges<T>>(\n\t\ttype: K,\n\t\tlistener: (change: StoreChanges<T>[K]) => void,\n\t): Cleanup\n\tremove<K extends Extract<keyof T, string>>(key: K): void\n}\n\ntype ArrayStore<T extends UnknownArray> = BaseStore & {\n\t[Symbol.iterator](): IterableIterator<\n\t\tArrayItem<T> extends readonly unknown[] | Record<string, unknown>\n\t\t\t? Store<ArrayItem<T>>\n\t\t\t: State<ArrayItem<T>>\n\t>\n\treadonly [Symbol.isConcatSpreadable]: boolean\n\t[n: number]: ArrayItem<T> extends\n\t\t| readonly unknown[]\n\t\t| Record<string, unknown>\n\t\t? Store<ArrayItem<T>>\n\t\t: State<ArrayItem<T>>\n\tadd(value: ArrayItem<T>): void\n\tget(): T\n\tset(value: T): void\n\tupdate(fn: (value: T) => T): void\n\tsort<U = ArrayItem<T>>(compareFn?: (a: U, b: U) => number): void\n\ton<K extends keyof StoreChanges<T>>(\n\t\ttype: K,\n\t\tlistener: (change: StoreChanges<T>[K]) => void,\n\t): Cleanup\n\tremove(index: number): void\n}\n\ntype Store<T extends UnknownRecord | UnknownArray> = T extends UnknownRecord\n\t? RecordStore<T>\n\t: T extends UnknownArray\n\t\t? ArrayStore<T>\n\t\t: never\n\n/* === Constants === */\n\nconst TYPE_STORE = 'Store'\n\n/* === Functions === */\n\n/**\n * Create a new store with deeply nested reactive properties\n *\n * Supports both objects and arrays as initial values. Arrays are converted\n * to records internally for storage but maintain their array type through\n * the .get() method, which automatically converts objects with consecutive\n * numeric keys back to arrays.\n *\n * @since 0.15.0\n * @param {T} initialValue - initial object or array value of the store\n * @returns {Store<T>} - new store with reactive properties that preserves the original type T\n */\nconst createStore = <T extends UnknownRecord | UnknownArray>(\n\tinitialValue: T,\n): Store<T> => {\n\tif (initialValue == null) throw new NullishSignalValueError('store')\n\n\tconst watchers = new Set<Watcher>()\n\tconst listeners: StoreListeners<T> = {\n\t\tadd: new Set<(change: PartialRecord<T>) => void>(),\n\t\tchange: new Set<(change: PartialRecord<T>) => void>(),\n\t\tremove: new Set<(change: PartialRecord<T>) => void>(),\n\t\tsort: new Set<(change: string[]) => void>(),\n\t}\n\tconst signals = new Map<string, Signal<T[Extract<keyof T, string>] & {}>>()\n\tconst signalWatchers = new Map<string, Watcher>()\n\n\t// Determine if this is an array-like store at creation time\n\tconst isArrayLike = Array.isArray(initialValue)\n\n\t// Get current record\n\tconst current = () => {\n\t\tconst record: Record<string, unknown> = {}\n\t\tfor (const [key, signal] of signals) record[key] = signal.get()\n\t\treturn record\n\t}\n\n\t// Emit change notifications\n\tconst emit = <K extends keyof StoreChanges<T>>(\n\t\tkey: K,\n\t\tchanges: StoreChanges<T>[K],\n\t) => {\n\t\tObject.freeze(changes)\n\t\tfor (const listener of listeners[key]) listener(changes)\n\t}\n\n\t// Get sorted indexes\n\tconst getSortedIndexes = () =>\n\t\tArray.from(signals.keys())\n\t\t\t.map(k => Number(k))\n\t\t\t.filter(n => Number.isInteger(n))\n\t\t\t.sort((a, b) => a - b)\n\n\t// Validate input\n\tconst isValidValue = <T>(\n\t\tkey: string,\n\t\tvalue: T,\n\t): value is NonNullable<T> => {\n\t\tif (value == null)\n\t\t\tthrow new NullishSignalValueError(`store for key \"${key}\"`)\n\t\tif (value === UNSET) return true\n\t\tif (isSymbol(value) || isFunction(value) || isComputed(value))\n\t\t\tthrow new InvalidSignalValueError(\n\t\t\t\t`store for key \"${key}\"`,\n\t\t\t\tvalueString(value),\n\t\t\t)\n\t\treturn true\n\t}\n\n\t// Add nested signal and effect\n\tconst addProperty = (\n\t\tkey: string,\n\t\tvalue: ArrayItem<T> | T[keyof T],\n\t\tsingle = false,\n\t): boolean => {\n\t\tif (!isValidValue(key, value)) return false\n\t\tconst signal =\n\t\t\tisState(value) || isStore(value)\n\t\t\t\t? value\n\t\t\t\t: isRecord(value) || Array.isArray(value)\n\t\t\t\t\t? createStore(value)\n\t\t\t\t\t: createState(value)\n\t\t// @ts-expect-error non-matching signal types\n\t\tsignals.set(key, signal)\n\t\tconst watcher = createWatcher(() =>\n\t\t\tobserve(() => {\n\t\t\t\temit('change', { [key]: signal.get() } as PartialRecord<T>)\n\t\t\t}, watcher),\n\t\t)\n\t\twatcher()\n\t\tsignalWatchers.set(key, watcher)\n\n\t\tif (single) {\n\t\t\tnotify(watchers)\n\t\t\temit('add', { [key]: value } as PartialRecord<T>)\n\t\t}\n\t\treturn true\n\t}\n\n\t// Remove nested signal and effect\n\tconst removeProperty = (key: string, single = false) => {\n\t\tconst ok = signals.delete(key)\n\t\tif (ok) {\n\t\t\tconst watcher = signalWatchers.get(key)\n\t\t\tif (watcher) watcher.cleanup()\n\t\t\tsignalWatchers.delete(key)\n\t\t}\n\n\t\tif (single) {\n\t\t\tnotify(watchers)\n\t\t\temit('remove', { [key]: UNSET } as PartialRecord<T>)\n\t\t}\n\t\treturn ok\n\t}\n\n\t// Reconcile data and dispatch events\n\tconst reconcile = (\n\t\toldValue: T,\n\t\tnewValue: T,\n\t\tinitialRun?: boolean,\n\t): boolean => {\n\t\tconst changes = diff(\n\t\t\toldValue as T extends UnknownArray ? ArrayToRecord<T> : T,\n\t\t\tnewValue as T extends UnknownArray ? ArrayToRecord<T> : T,\n\t\t)\n\n\t\tbatch(() => {\n\t\t\t// Additions\n\t\t\tif (Object.keys(changes.add).length) {\n\t\t\t\tfor (const key in changes.add)\n\t\t\t\t\taddProperty(key, changes.add[key] ?? UNSET)\n\n\t\t\t\t// Queue initial additions event to allow listeners to be added first\n\t\t\t\tif (initialRun) {\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\temit('add', changes.add)\n\t\t\t\t\t}, 0)\n\t\t\t\t} else {\n\t\t\t\t\temit('add', changes.add)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Changes\n\t\t\tif (Object.keys(changes.change).length) {\n\t\t\t\tfor (const key in changes.change) {\n\t\t\t\t\tconst value = changes.change[key]\n\t\t\t\t\tif (!isValidValue(key, value)) continue\n\t\t\t\t\tconst signal = signals.get(key as Extract<keyof T, string>)\n\t\t\t\t\tif (isMutableSignal(signal)) signal.set(value)\n\t\t\t\t\telse\n\t\t\t\t\t\tthrow new StoreKeyReadonlyError(key, valueString(value))\n\t\t\t\t}\n\t\t\t\temit('change', changes.change)\n\t\t\t}\n\n\t\t\t// Removals\n\t\t\tif (Object.keys(changes.remove).length) {\n\t\t\t\tfor (const key in changes.remove) removeProperty(key)\n\t\t\t\temit('remove', changes.remove)\n\t\t\t}\n\t\t})\n\n\t\treturn changes.changed\n\t}\n\n\t// Initialize data\n\treconcile({} as T, initialValue, true)\n\n\t// Methods and Properties\n\tconst store: Record<PropertyKey, unknown> = {}\n\tObject.defineProperties(store, {\n\t\t[Symbol.toStringTag]: {\n\t\t\tvalue: TYPE_STORE,\n\t\t},\n\t\t[Symbol.isConcatSpreadable]: {\n\t\t\tvalue: isArrayLike,\n\t\t},\n\t\t[Symbol.iterator]: {\n\t\t\tvalue: isArrayLike\n\t\t\t\t? function* () {\n\t\t\t\t\t\tconst indexes = getSortedIndexes()\n\t\t\t\t\t\tfor (const index of indexes) {\n\t\t\t\t\t\t\tconst signal = signals.get(String(index))\n\t\t\t\t\t\t\tif (signal) yield signal\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t: function* () {\n\t\t\t\t\t\tfor (const [key, signal] of signals) yield [key, signal]\n\t\t\t\t\t},\n\t\t},\n\t\tadd: {\n\t\t\tvalue: isArrayLike\n\t\t\t\t? (v: ArrayItem<T>): void => {\n\t\t\t\t\t\taddProperty(String(signals.size), v, true)\n\t\t\t\t\t}\n\t\t\t\t: <K extends Extract<keyof T, string>>(k: K, v: T[K]): void => {\n\t\t\t\t\t\tif (!signals.has(k)) addProperty(k, v, true)\n\t\t\t\t\t\telse throw new StoreKeyExistsError(k, valueString(v))\n\t\t\t\t\t},\n\t\t},\n\t\tget: {\n\t\t\tvalue: (): T => {\n\t\t\t\tsubscribe(watchers)\n\t\t\t\treturn recordToArray(current()) as T\n\t\t\t},\n\t\t},\n\t\tremove: {\n\t\t\tvalue: isArrayLike\n\t\t\t\t? (index: number): void => {\n\t\t\t\t\t\tconst currentArray = recordToArray(current()) as T\n\t\t\t\t\t\tconst currentLength = signals.size\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!Array.isArray(currentArray) ||\n\t\t\t\t\t\t\tindex <= -currentLength ||\n\t\t\t\t\t\t\tindex >= currentLength\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthrow new StoreKeyRangeError(index)\n\t\t\t\t\t\tconst newArray = [...currentArray]\n\t\t\t\t\t\tnewArray.splice(index, 1)\n\n\t\t\t\t\t\tif (reconcile(currentArray, newArray as unknown as T))\n\t\t\t\t\t\t\tnotify(watchers)\n\t\t\t\t\t}\n\t\t\t\t: (k: string): void => {\n\t\t\t\t\t\tif (signals.has(k)) removeProperty(k, true)\n\t\t\t\t\t},\n\t\t},\n\t\tset: {\n\t\t\tvalue: (v: T): void => {\n\t\t\t\tif (reconcile(current() as T, v)) {\n\t\t\t\t\tnotify(watchers)\n\t\t\t\t\tif (UNSET === v) watchers.clear()\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tupdate: {\n\t\t\tvalue: (fn: (v: T) => T): void => {\n\t\t\t\tconst oldValue = current()\n\t\t\t\tconst newValue = fn(recordToArray(oldValue) as T)\n\t\t\t\tif (reconcile(oldValue as T, newValue)) {\n\t\t\t\t\tnotify(watchers)\n\t\t\t\t\tif (UNSET === newValue) watchers.clear()\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tsort: {\n\t\t\tvalue: (\n\t\t\t\tcompareFn?: <\n\t\t\t\t\tU = T extends UnknownArray\n\t\t\t\t\t\t? ArrayItem<T>\n\t\t\t\t\t\t: T[Extract<keyof T, string>],\n\t\t\t\t>(\n\t\t\t\t\ta: U,\n\t\t\t\t\tb: U,\n\t\t\t\t) => number,\n\t\t\t): void => {\n\t\t\t\t// Get all entries as [key, value] pairs\n\t\t\t\tconst entries = Array.from(signals.entries())\n\t\t\t\t\t.map(([key, signal]) => [key, signal.get()])\n\t\t\t\t\t.sort(\n\t\t\t\t\t\tcompareFn\n\t\t\t\t\t\t\t? (a, b) => compareFn(a[1], b[1])\n\t\t\t\t\t\t\t: (a, b) =>\n\t\t\t\t\t\t\t\t\tString(a[1]).localeCompare(String(b[1])),\n\t\t\t\t\t)\n\n\t\t\t\t// Create array of original keys in their new sorted order\n\t\t\t\tconst newOrder: string[] = entries.map(([key]) => String(key))\n\t\t\t\tconst newSignals = new Map<\n\t\t\t\t\tstring,\n\t\t\t\t\tSignal<T[Extract<keyof T, string>] & {}>\n\t\t\t\t>()\n\n\t\t\t\tentries.forEach(([key], newIndex) => {\n\t\t\t\t\tconst oldKey = String(key)\n\t\t\t\t\tconst newKey = isArrayLike ? String(newIndex) : String(key)\n\t\t\t\t\tconst signal = signals.get(oldKey)\n\t\t\t\t\tif (signal) newSignals.set(newKey, signal)\n\t\t\t\t})\n\n\t\t\t\t// Replace signals map\n\t\t\t\tsignals.clear()\n\t\t\t\tnewSignals.forEach((signal, key) => signals.set(key, signal))\n\t\t\t\tnotify(watchers)\n\t\t\t\temit('sort', newOrder)\n\t\t\t},\n\t\t},\n\t\ton: {\n\t\t\tvalue: <K extends keyof StoreChanges<T>>(\n\t\t\t\ttype: K,\n\t\t\t\tlistener: (change: StoreChanges<T>[K]) => void,\n\t\t\t): Cleanup => {\n\t\t\t\tlisteners[type].add(listener)\n\t\t\t\treturn () => listeners[type].delete(listener)\n\t\t\t},\n\t\t},\n\t\tlength: {\n\t\t\tget(): number {\n\t\t\t\tsubscribe(watchers)\n\t\t\t\treturn signals.size\n\t\t\t},\n\t\t},\n\t})\n\n\t// Return proxy directly with integrated signal methods\n\treturn new Proxy(store as Store<T>, {\n\t\tget(target, prop) {\n\t\t\tif (prop in target) return Reflect.get(target, prop)\n\t\t\tif (isSymbol(prop)) return undefined\n\t\t\treturn signals.get(prop)\n\t\t},\n\t\thas(target, prop) {\n\t\t\tif (prop in target) return true\n\t\t\treturn signals.has(String(prop))\n\t\t},\n\t\townKeys(target) {\n\t\t\tconst staticKeys = Reflect.ownKeys(target)\n\t\t\tconst signalKeys = isArrayLike\n\t\t\t\t? getSortedIndexes().map(key => String(key))\n\t\t\t\t: Array.from(signals.keys())\n\t\t\treturn [...new Set([...signalKeys, ...staticKeys])]\n\t\t},\n\t\tgetOwnPropertyDescriptor(target, prop) {\n\t\t\tif (prop in target)\n\t\t\t\treturn Reflect.getOwnPropertyDescriptor(target, prop)\n\n\t\t\tconst signal = signals.get(String(prop))\n\t\t\treturn signal\n\t\t\t\t? {\n\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\tconfigurable: true,\n\t\t\t\t\t\twritable: true,\n\t\t\t\t\t\tvalue: signal,\n\t\t\t\t\t}\n\t\t\t\t: undefined\n\t\t},\n\t})\n}\n\n/**\n * Check if the provided value is a Store instance\n *\n * @since 0.15.0\n * @param {unknown} value - value to check\n * @returns {boolean} - true if the value is a Store instance, false otherwise\n */\nconst isStore = <T extends UnknownRecord | UnknownArray>(\n\tvalue: unknown,\n): value is Store<T> => isObjectOfType(value, TYPE_STORE)\n\n/* === Exports === */\n\nexport { TYPE_STORE, isStore, createStore, type Store, type StoreChanges }\n",
|
|
15
|
+
"import {\n\ttype Computed,\n\ttype ComputedCallback,\n\tcreateComputed,\n\tisComputed,\n\tisComputedCallback,\n} from './computed'\nimport { createState, isState, type State } from './state'\nimport { createStore, isStore, type Store } from './store'\nimport { isRecord } from './util'\n\n/* === Types === */\n\ntype Signal<T extends {}> = {\n\tget(): T\n}\n\ntype UnknownSignalRecord = Record<string, Signal<unknown & {}>>\n\ntype SignalValues<S extends UnknownSignalRecord> = {\n\t[K in keyof S]: S[K] extends Signal<infer T> ? T : never\n}\n\n/* === Functions === */\n\n/**\n * Check whether a value is a Signal\n *\n * @since 0.9.0\n * @param {unknown} value - value to check\n * @returns {boolean} - true if value is a Signal, false otherwise\n */\nconst isSignal = /*#__PURE__*/ <T extends {}>(\n\tvalue: unknown,\n): value is Signal<T> => isState(value) || isComputed(value) || isStore(value)\n\n/**\n * Check whether a value is a State or Store\n *\n * @since 0.15.2\n * @param {unknown} value - value to check\n * @returns {boolean} - true if value is a State or Store, false otherwise\n */\nconst isMutableSignal = /*#__PURE__*/ <T extends {}>(\n\tvalue: unknown,\n): value is State<T> | Store<T> => isState(value) || isStore(value)\n\n/**\n * Convert a value to a Signal if it's not already a Signal\n *\n * @since 0.9.6\n * @param {T} value - value to convert\n * @returns {Signal<T>} - Signal instance\n */\nfunction toSignal<T extends {}>(\n\tvalue: T,\n): T extends Store<infer U>\n\t? Store<U>\n\t: T extends State<infer U>\n\t\t? State<U>\n\t\t: T extends Computed<infer U>\n\t\t\t? Computed<U>\n\t\t\t: T extends Signal<infer U>\n\t\t\t\t? Signal<U>\n\t\t\t\t: T extends ReadonlyArray<infer U extends {}>\n\t\t\t\t\t? Store<U[]>\n\t\t\t\t\t: T extends Record<string, unknown & {}>\n\t\t\t\t\t\t? Store<{ [K in keyof T]: T[K] }>\n\t\t\t\t\t\t: T extends ComputedCallback<infer U extends {}>\n\t\t\t\t\t\t\t? Computed<U>\n\t\t\t\t\t\t\t: State<T>\nfunction toSignal<T extends {}>(value: T) {\n\tif (isSignal<T>(value)) return value\n\tif (isComputedCallback(value)) return createComputed(value)\n\tif (Array.isArray(value) || isRecord(value)) return createStore(value)\n\treturn createState(value)\n}\n\n/* === Exports === */\n\nexport {\n\ttype Signal,\n\ttype UnknownSignalRecord,\n\ttype SignalValues,\n\tisSignal,\n\tisMutableSignal,\n\ttoSignal,\n}\n",
|
|
16
|
+
"import { isFunction, isString } from '@zeix/cause-effect'\n\n/* === Types === */\n\ntype LogLevel = 'debug' | 'info' | 'warn' | 'error'\n\n/* === Constants === */\n\nconst DEV_MODE = process.env.DEV_MODE\n\nconst LOG_DEBUG: LogLevel = 'debug'\nconst LOG_INFO: LogLevel = 'info'\nconst LOG_WARN: LogLevel = 'warn'\nconst LOG_ERROR: LogLevel = 'error'\n\n// Reserved words that should never be used as property names\n// These are fundamental JavaScript/Object properties that cause serious issues\nconst RESERVED_WORDS = new Set([\n\t'constructor',\n\t'prototype',\n\t// Expand this list based on user feedback for other reserved words like:\n\t// '__proto__', 'toString', 'valueOf', 'hasOwnProperty', etc.\n])\n\n// HTMLElement properties that commonly cause conflicts\n// These are properties that exist on HTMLElement and cause confusion when overridden\n// in our reactive components because we use the same name for both attributes and properties\nconst HTML_ELEMENT_PROPS = new Set([\n\t'id', // DOM selector conflicts\n\t'class', // CSS class management conflicts (note: property is 'className')\n\t'className', // CSS class management conflicts (note: HTML attribute is 'class')\n\t'title', // Conflicts with tooltip behavior\n\t'role', // ARIA/accessibility conflicts\n\t'style', // Conflicts with style object\n\t'dataset', // Conflicts with data-* attribute access\n\t'lang', // Language/i18n conflicts\n\t'dir', // Text direction conflicts\n\t'hidden', // Visibility control conflicts\n\t'children', // DOM manipulation conflicts\n\t'innerHTML', // DOM manipulation conflicts\n\t'outerHTML', // Full element HTML conflicts\n\t'textContent', // Text manipulation conflicts\n\t'innerText', // Text manipulation conflicts\n\t// TO EXPAND: Add properties based on user feedback and common mistakes\n\t// 'tabindex', 'tabIndex', 'slot', 'part', etc.\n])\n\n/* === Internal Functions === */\n\n/**\n * Return selector string for the id of the element\n *\n * @since 0.7.0\n * @param {string | undefined | null} id\n * @returns {string} - id string for the element with '#' prefix\n */\nconst idString = (id: string | undefined | null): string => (id ? `#${id}` : '')\n\n/**\n * Return a selector string for classes of the element\n *\n * @since 0.7.0\n * @param {DOMTokenList | undefined | null} classList - DOMTokenList to convert to a string\n * @returns {string} - class string for the DOMTokenList with '.' prefix if any\n */\nconst classString = (classList: DOMTokenList | undefined | null): string =>\n\tclassList?.length ? `.${Array.from(classList).join('.')}` : ''\n\n/* === Exported Functions === */\n\nconst hasMethod = /*#__PURE__*/ <T extends object, K extends PropertyKey, R>(\n\tobj: T,\n\tmethodName: K,\n): obj is T & Record<K, (...args: any[]) => R> =>\n\tisString(methodName) &&\n\tmethodName in obj &&\n\tisFunction<R>((obj as any)[methodName])\n\n/**\n * Check if a node is an Element\n *\n * @param {Node} node - node to check\n * @returns {boolean} - `true` if node is an element node, otherwise `false`\n */\nconst isElement = /*#__PURE__*/ (node: Node): node is Element =>\n\tnode.nodeType === Node.ELEMENT_NODE\n\n/**\n * Check whether an element is a custom element\n *\n * @param {E} element - Element to check\n * @returns {boolean} - True if the element is a custom element\n */\nconst isCustomElement = /*#__PURE__*/ <E extends Element>(\n\telement: E,\n): boolean => element.localName.includes('-')\n\n/**\n * Check whether a custom element is not yet defined\n *\n * @param {Element} element - Element to check\n * @returns {boolean} - True if the element is a custom element and not yet defined\n */\nconst isNotYetDefinedComponent = /*#__PURE__*/ (element: Element): boolean =>\n\tisCustomElement(element) && element.matches(':not(:defined)')\n\n/**\n * Return a string representation of the Element instance\n *\n * @since 0.7.0\n * @param {Element | undefined | null} el\n * @returns {string}\n */\nconst elementName = /*#__PURE__*/ (el: Element | undefined | null): string =>\n\tel\n\t\t? `<${el.localName}${idString(el.id)}${classString(el.classList)}>`\n\t\t: '<unknown>'\n\n/**\n * Return a detailed type of a JavaScript variable\n *\n * @since 0.11.0\n * @param {unknown} value\n * @returns {string}\n */\nconst typeString = /*#__PURE__*/ (value: unknown): string => {\n\tif (value === null) return 'null'\n\tif (typeof value !== 'object') return typeof value\n\tif (Array.isArray(value)) return 'Array'\n\n\t// Check for Symbol.toStringTag\n\tif (Symbol.toStringTag in Object(value)) {\n\t\treturn (value as any)[Symbol.toStringTag]\n\t}\n\n\t// For other objects, return the constructor name if available\n\treturn value.constructor?.name || 'Object'\n}\n\n/**\n * Log a message to the console with the specified level\n *\n * @since 0.7.0\n * @param {T} value - value to inspect\n * @param {string} msg - message to log\n * @param {LogLevel} level - log level\n * @returns {T} - value passed through\n */\nconst log = <T>(value: T, msg: string, level: LogLevel = LOG_DEBUG): T => {\n\tif (DEV_MODE || ([LOG_ERROR, LOG_WARN] as LogLevel[]).includes(level))\n\t\tconsole[level](msg, value)\n\treturn value\n}\n\n/**\n * Simple fail-fast validation that checks for specific problematic cases\n *\n * This validation prevents common mistakes where developers accidentally\n * use property names that conflict with native HTMLElement functionality.\n *\n * @param {string} prop - Property name to validate\n * @returns {string | null} - Error message or null if valid\n */\nconst validatePropertyName = (prop: string): string | null => {\n\tif (RESERVED_WORDS.has(prop))\n\t\treturn `Property name \"${prop}\" is a reserved word`\n\tif (HTML_ELEMENT_PROPS.has(prop))\n\t\treturn `Property name \"${prop}\" conflicts with inherited HTMLElement property`\n\treturn null\n}\n\nexport {\n\ttype LogLevel,\n\thasMethod,\n\tisElement,\n\tisCustomElement,\n\tisNotYetDefinedComponent,\n\tlog,\n\telementName,\n\ttypeString,\n\tvalidatePropertyName,\n\tDEV_MODE,\n\tLOG_DEBUG,\n\tLOG_INFO,\n\tLOG_WARN,\n\tLOG_ERROR,\n}\n",
|
|
17
|
+
"import { valueString } from '@zeix/cause-effect'\nimport { elementName } from './util'\n\n/* === Error Classes === */\n\n/**\n * Error thrown when a circular dependency is detected in a selection signal\n *\n * @since 0.14.0\n */\nclass CircularMutationError extends Error {\n\t/**\n\t * @param {HTMLElement} host - Host component\n\t * @param {string} selector - Selector used to find the elements\n\t */\n\tconstructor(host: HTMLElement, selector: string) {\n\t\tsuper(\n\t\t\t`Circular dependency detected in selection signal for component ${elementName(host)} with selector \"${selector}\"`,\n\t\t)\n\t\tthis.name = 'CircularMutationError'\n\t}\n}\n\n/**\n * Error thrown when component name violates rules for custom element names\n *\n * @since 0.14.0\n */\nclass InvalidComponentNameError extends TypeError {\n\t/**\n\t * @param {string} component - Component name\n\t */\n\tconstructor(component: string) {\n\t\tsuper(\n\t\t\t`Invalid component name \"${component}\". Custom element names must contain a hyphen, start with a lowercase letter, and contain only lowercase letters, numbers, and hyphens.`,\n\t\t)\n\t\tthis.name = 'InvalidComponentNameError'\n\t}\n}\n\n/**\n * Error thrown when trying to assign a property name that conflicts with reserved words or inherited HTMLElement properties\n *\n * @since 0.14.0\n */\nclass InvalidPropertyNameError extends TypeError {\n\t/**\n\t * @param {string} component - Component name\n\t * @param {string} prop - Property name\n\t * @param {string} reason - Explanation why the property is invalid\n\t */\n\tconstructor(component: string, prop: string, reason: string) {\n\t\tsuper(\n\t\t\t`Invalid property name \"${prop}\" for component <${component}>. ${reason}`,\n\t\t)\n\t\tthis.name = 'InvalidPropertyNameError'\n\t}\n}\n\n/**\n * Error thrown when setup function does not return effects\n *\n * @since 0.14.0\n */\nclass InvalidEffectsError extends TypeError {\n\t/**\n\t * @param {HTMLElement} host - Host component\n\t * @param {Error} cause - Error that caused the invalid effects\n\t */\n\tconstructor(host: HTMLElement, cause?: Error) {\n\t\tsuper(\n\t\t\t`Invalid effects in component ${elementName(host)}. Effects must be a record of effects for UI elements or the component, or a Promise that resolves to effects.`,\n\t\t)\n\t\tthis.name = 'InvalidEffectsError'\n\t\tif (cause) this.cause = cause\n\t}\n}\n\n/**\n * Error thrown when a required desacendent element does not exist in a component's DOM subtree\n *\n * @since 0.14.0\n */\nclass MissingElementError extends Error {\n\t/**\n\t * @param {HTMLElement} host - Host component\n\t * @param {string} selector - Selector used to find the elements\n\t * @param {string} required - Explanation why the element is required\n\t */\n\tconstructor(host: HTMLElement, selector: string, required: string) {\n\t\tsuper(\n\t\t\t`Missing required element <${selector}> in component ${elementName(host)}. ${required}`,\n\t\t)\n\t\tthis.name = 'MissingElementError'\n\t}\n}\n\n/**\n * Error when a component's dependencies are not met within a specified timeout\n *\n * @since 0.14.0\n */\nclass DependencyTimeoutError extends Error {\n\t/**\n\t * @param {HTMLElement} host - Host component\n\t * @param {string[]} missing - List of missing dependencies\n\t */\n\tconstructor(host: HTMLElement, missing: string[]) {\n\t\tsuper(\n\t\t\t`Timeout waiting for: [${missing.join(', ')}] in component ${elementName(host)}.`,\n\t\t)\n\t\tthis.name = 'DependencyTimeoutError'\n\t}\n}\n\n/**\n * Error thrown when reactives passed to a component are invalid\n *\n * @since 0.15.0\n */\nclass InvalidReactivesError extends TypeError {\n\t/**\n\t * @param {HTMLElement} host - Host component\n\t * @param {HTMLElement} target - Target component\n\t * @param {unknown} reactives - Reactives passed to the component\n\t */\n\tconstructor(host: HTMLElement, target: HTMLElement, reactives: unknown) {\n\t\tsuper(\n\t\t\t`Expected reactives passed from ${elementName(host)} to ${elementName(target)} to be a record of signals, reactive property names or functions. Got ${valueString(reactives)}.`,\n\t\t)\n\t\tthis.name = 'InvalidReactivesError'\n\t}\n}\n\n/**\n * Error thrown when target element is not a custom element as expected\n *\n * @since 0.15.0\n */\nclass InvalidCustomElementError extends TypeError {\n\t/**\n\t * @param {HTMLElement} target - Target component\n\t * @param {string} where - Location where the error occurred\n\t */\n\tconstructor(target: HTMLElement, where: string) {\n\t\tsuper(`Target ${elementName(target)} is not a custom element in ${where}.`)\n\t\tthis.name = 'InvalidCustomElementError'\n\t}\n}\n\nexport {\n\tCircularMutationError,\n\tDependencyTimeoutError,\n\tInvalidComponentNameError,\n\tInvalidCustomElementError,\n\tInvalidPropertyNameError,\n\tInvalidEffectsError,\n\tInvalidReactivesError,\n\tMissingElementError,\n}\n",
|
|
18
|
+
"import {\n\ttype Cleanup,\n\tisSymbol,\n\tnotify,\n\tsubscribe,\n\ttype Watcher,\n} from '@zeix/cause-effect'\nimport type { ElementFromSelector } from '../ui'\nimport { isElement } from '../util'\n\n/* === Types === */\n\ntype CollectionListener<E extends Element> = (changes: readonly E[]) => void\n\ntype Collection<E extends Element> = {\n\treadonly [Symbol.toStringTag]: 'Collection'\n\treadonly [Symbol.isConcatSpreadable]: true\n\t[Symbol.iterator](): IterableIterator<E>\n\t[n: number]: E\n\tget(): E[]\n\ton(type: 'add' | 'remove', listener: CollectionListener<E>): Cleanup\n\treadonly length: number\n}\n\n/* === Constants === */\n\nconst TYPE_COLLECTION = 'Collection'\n\n/* === Internal Functions === */\n\n/**\n * Extract attribute names from a CSS selector\n * Handles various attribute selector formats: .class, #id, [attr], [attr=value], [attr^=value], etc.\n *\n * @param {string} selector - CSS selector to parse\n * @returns {string[]} - Array of attribute names found in the selector\n */\nconst extractAttributes = (selector: string): string[] => {\n\tconst attributes = new Set<string>()\n\tif (selector.includes('.')) attributes.add('class')\n\tif (selector.includes('#')) attributes.add('id')\n\tif (selector.includes('[')) {\n\t\tconst parts = selector.split('[')\n\t\tfor (let i = 1; i < parts.length; i++) {\n\t\t\tconst part = parts[i]\n\t\t\tif (!part.includes(']')) continue\n\t\t\tconst attrName = part\n\t\t\t\t.split('=')[0]\n\t\t\t\t.trim()\n\t\t\t\t.replace(/[^a-zA-Z0-9_-]/g, '')\n\t\t\tif (attrName) attributes.add(attrName)\n\t\t}\n\t}\n\treturn [...attributes]\n}\n\n/* === Exported Functions === */\n\n/**\n * Create a collection of elements from a parent node and a CSS selector.\n *\n * @since 0.15.0\n * @param parent - The parent node to search within\n * @param selector - The CSS selector to match elements\n * @returns A collection signal of elements\n */\nfunction createCollection<S extends string>(\n\tparent: ParentNode,\n\tselector: S,\n): Collection<ElementFromSelector<S>>\nfunction createCollection<E extends Element>(\n\tparent: ParentNode,\n\tselector: string,\n): Collection<E>\nfunction createCollection<S extends string>(\n\tparent: ParentNode,\n\tselector: S,\n): Collection<ElementFromSelector<S>> {\n\tconst watchers: Set<Watcher> = new Set()\n\tconst listeners = {\n\t\tadd: new Set<CollectionListener<ElementFromSelector<S>>>(),\n\t\tremove: new Set<CollectionListener<ElementFromSelector<S>>>(),\n\t}\n\tlet elements: ElementFromSelector<S>[] = []\n\tlet observer: MutationObserver | undefined\n\n\tconst findMatches = (nodes: NodeList) => {\n\t\tconst elements = Array.from(nodes).filter(isElement)\n\t\tconst found: ElementFromSelector<S>[] = []\n\t\tfor (const element of elements) {\n\t\t\tif (element.matches(selector))\n\t\t\t\tfound.push(element as ElementFromSelector<S>)\n\t\t\tfound.push(\n\t\t\t\t...Array.from(\n\t\t\t\t\telement.querySelectorAll<ElementFromSelector<S>>(selector),\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t\treturn found\n\t}\n\n\tconst notifyListeners = (\n\t\tlisteners: Set<CollectionListener<ElementFromSelector<S>>>,\n\t\telements: ElementFromSelector<S>[],\n\t) => {\n\t\tObject.freeze(elements)\n\t\tfor (const listener of listeners) listener(elements)\n\t}\n\n\tconst observe = () => {\n\t\telements = Array.from(\n\t\t\tparent.querySelectorAll<ElementFromSelector<S>>(selector),\n\t\t)\n\n\t\tobserver = new MutationObserver(mutations => {\n\t\t\tconst added: ElementFromSelector<S>[] = []\n\t\t\tconst removed: ElementFromSelector<S>[] = []\n\n\t\t\tfor (const mutation of mutations) {\n\t\t\t\tif (mutation.type === 'childList') {\n\t\t\t\t\tif (mutation.addedNodes.length)\n\t\t\t\t\t\tadded.push(...findMatches(mutation.addedNodes))\n\t\t\t\t\tif (mutation.removedNodes.length)\n\t\t\t\t\t\tremoved.push(...findMatches(mutation.removedNodes))\n\t\t\t\t} else if (mutation.type === 'attributes') {\n\t\t\t\t\tconst target = mutation.target as ElementFromSelector<S>\n\t\t\t\t\tif (isElement(target)) {\n\t\t\t\t\t\tconst wasMatching = elements.includes(target)\n\t\t\t\t\t\tconst isMatching = target.matches(selector)\n\t\t\t\t\t\tif (wasMatching && !isMatching) removed.push(target)\n\t\t\t\t\t\telse if (!wasMatching && isMatching) added.push(target)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (added.length || removed.length) {\n\t\t\t\telements = Array.from(\n\t\t\t\t\tparent.querySelectorAll<ElementFromSelector<S>>(selector),\n\t\t\t\t)\n\t\t\t\tnotify(watchers)\n\t\t\t}\n\t\t\tif (added.length) notifyListeners(listeners.add, added)\n\t\t\tif (removed.length) notifyListeners(listeners.remove, removed)\n\t\t})\n\t\tconst observerConfig: MutationObserverInit = {\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t}\n\t\tconst observedAttributes = extractAttributes(selector)\n\t\tif (observedAttributes.length) {\n\t\t\tobserverConfig.attributes = true\n\t\t\tobserverConfig.attributeFilter = observedAttributes\n\t\t}\n\t\tobserver.observe(parent, observerConfig)\n\t}\n\n\tconst collection = {} as Collection<ElementFromSelector<S>>\n\tObject.defineProperties(collection, {\n\t\t[Symbol.toStringTag]: {\n\t\t\tvalue: TYPE_COLLECTION,\n\t\t},\n\t\t[Symbol.isConcatSpreadable]: {\n\t\t\tvalue: true,\n\t\t},\n\t\t[Symbol.iterator]: {\n\t\t\tvalue: function* () {\n\t\t\t\tfor (const element of elements) yield element\n\t\t\t},\n\t\t},\n\t\tget: {\n\t\t\tvalue: () => {\n\t\t\t\tsubscribe(watchers)\n\t\t\t\tif (!observer) observe()\n\t\t\t\treturn elements\n\t\t\t},\n\t\t},\n\t\ton: {\n\t\t\tvalue: (\n\t\t\t\ttype: 'add' | 'remove',\n\t\t\t\tlistener: CollectionListener<ElementFromSelector<S>>,\n\t\t\t) => {\n\t\t\t\tconst listenerSet = listeners[type]\n\t\t\t\tif (!listenerSet)\n\t\t\t\t\tthrow new TypeError(`Invalid change notification type: ${type}`)\n\t\t\t\tlistenerSet.add(listener)\n\t\t\t\tif (!observer) observe()\n\t\t\t\treturn () => listenerSet.delete(listener)\n\t\t\t},\n\t\t},\n\t\tlength: {\n\t\t\tget: () => {\n\t\t\t\tsubscribe(watchers)\n\t\t\t\tif (!observer) observe()\n\t\t\t\treturn elements.length\n\t\t\t},\n\t\t},\n\t})\n\n\treturn new Proxy(collection, {\n\t\tget(target, prop) {\n\t\t\tif (prop in target) return Reflect.get(target, prop)\n\t\t\tif (isSymbol(prop)) return undefined\n\n\t\t\tconst index = Number(prop)\n\t\t\tif (Number.isInteger(index)) return elements[index]\n\n\t\t\treturn undefined\n\t\t},\n\t\thas(target, prop) {\n\t\t\tif (prop in target) return true\n\t\t\tif (Number.isInteger(Number(prop))) return !!elements[Number(prop)]\n\t\t\treturn false\n\t\t},\n\t\townKeys(target) {\n\t\t\tconst staticKeys = Reflect.ownKeys(target)\n\t\t\tconst indexes = Object.keys(elements).map(key => String(key))\n\t\t\treturn [...new Set([...indexes, ...staticKeys])]\n\t\t},\n\t\tgetOwnPropertyDescriptor(target, prop) {\n\t\t\tif (prop in target) return Reflect.getOwnPropertyDescriptor(target, prop)\n\n\t\t\tconst element = elements[Number(prop)]\n\t\t\treturn element\n\t\t\t\t? {\n\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\tconfigurable: true,\n\t\t\t\t\t\twritable: true,\n\t\t\t\t\t\tvalue: element,\n\t\t\t\t\t}\n\t\t\t\t: undefined\n\t\t},\n\t})\n}\n\n/**\n * Check if a value is a collection signal\n *\n * @since 0.15.0\n * @param {unknown} value - Value to check\n * @returns {boolean} - True if value is a collection signal, false otherwise\n */\nconst isCollection = <E extends Element = Element>(\n\tvalue: unknown,\n): value is Collection<E> =>\n\tObject.prototype.toString.call(value) === `[object Collection]`\n\nexport {\n\ttype Collection,\n\ttype CollectionListener,\n\tTYPE_COLLECTION,\n\tcreateCollection,\n\tisCollection,\n}\n",
|
|
19
|
+
"import {\n\ttype Cleanup,\n\tcreateEffect,\n\tisFunction,\n\tisRecord,\n\tisSignal,\n\tisString,\n\ttype MaybeCleanup,\n\ttype Signal,\n\ttoError,\n\tUNSET,\n\tvalueString,\n} from '@zeix/cause-effect'\nimport type { Component, ComponentProps } from './component'\nimport { InvalidEffectsError } from './errors'\nimport { type Collection, isCollection } from './signals/collection'\nimport type { ElementFromKey, UI } from './ui'\nimport { DEV_MODE, elementName, LOG_ERROR, log } from './util'\n\n/* === Types === */\n\ntype Effect<P extends ComponentProps, E extends Element> = (\n\thost: Component<P>,\n\ttarget: E,\n) => MaybeCleanup\n\ntype ElementEffects<P extends ComponentProps, E extends Element> =\n\t| Effect<P, E>\n\t| Effect<P, E>[]\n\ntype Effects<\n\tP extends ComponentProps,\n\tU extends UI & { host: Component<P> },\n> = {\n\t[K in keyof U]?: ElementEffects<P, ElementFromKey<U, K>>\n}\n\ntype Reactive<T, P extends ComponentProps, E extends Element> =\n\t| keyof P\n\t| Signal<T & {}>\n\t| ((target: E) => T | null | undefined)\n\ntype UpdateOperation = 'a' | 'c' | 'd' | 'h' | 'm' | 'p' | 's' | 't'\n\ntype ElementUpdater<E extends Element, T> = {\n\top: UpdateOperation\n\tname?: string\n\tread: (element: E) => T | null\n\tupdate: (element: E, value: T) => void\n\tdelete?: (element: E) => void\n\tresolve?: (element: E) => void\n\treject?: (error: unknown) => void\n}\n\n/* type ElementInserter<E extends Element> = {\n\tposition?: InsertPosition\n\tcreate: (parent: E) => Element | null\n\tresolve?: (parent: E) => void\n\treject?: (error: unknown) => void\n} */\n\n/* === Constants === */\n\n// Special value explicitly marked as any so it can be used as signal value of any type\nconst RESET: any = Symbol('RESET')\n\n/* === Internal Functions === */\n\nconst getUpdateDescription = (\n\top: UpdateOperation,\n\tname: string = '',\n): string => {\n\tconst ops: Record<UpdateOperation, string> = {\n\t\ta: 'attribute ',\n\t\tc: 'class ',\n\t\td: 'dataset ',\n\t\th: 'inner HTML',\n\t\tm: 'method call ',\n\t\tp: 'property ',\n\t\ts: 'style property ',\n\t\tt: 'text content',\n\t}\n\treturn ops[op] + name\n}\n\n/* === Exported Functions === */\n\n/**\n * Run element effects\n *\n * @since 0.15.0\n * @param {U} host - Host component\n * @param {E} target - Target element\n * @param {ElementEffects<P, E>} effects - Effect functions to run\n * @returns {MaybeCleanup} - Cleanup function that runs collected cleanup functions\n * @throws {InvalidEffectsError} - If the effects are invalid\n */\nconst runElementEffects = <P extends ComponentProps, E extends Element>(\n\thost: Component<P>,\n\ttarget: E,\n\teffects: ElementEffects<P, E>,\n): MaybeCleanup => {\n\tconst cleanups: Cleanup[] = []\n\n\tconst run = (fn: Effect<P, E>) => {\n\t\tconst cleanup = fn(host, target)\n\t\tif (cleanup) cleanups.push(cleanup)\n\t}\n\n\tif (Array.isArray(effects)) for (const fn of effects) run(fn)\n\telse run(effects)\n\n\treturn () => {\n\t\tcleanups.forEach(cleanup => cleanup())\n\t\tcleanups.length = 0\n\t}\n}\n\n/**\n * Run collection effects\n *\n * @since 0.15.0\n * @param {Component<P>} host - Host component\n * @param {Collection<E>} collection - Collection of elements\n * @param {ElementEffects<P, E>} effects - Element effects\n * @returns {Cleanup} - Cleanup function that runs collected cleanup functions\n * @throws {InvalidEffectsError} - If the effects are invalid\n */\nconst runCollectionEffects = <P extends ComponentProps, E extends Element>(\n\thost: Component<P>,\n\tcollection: Collection<E>,\n\teffects: ElementEffects<P, E>,\n): Cleanup => {\n\tconst cleanups: Map<E, Cleanup> = new Map()\n\n\tconst attach = (targets: readonly E[]) => {\n\t\tfor (const target of targets) {\n\t\t\tconst cleanup = runElementEffects(host, target, effects)\n\t\t\tif (cleanup) cleanups.set(target, cleanup)\n\t\t}\n\t}\n\tconst detach = (targets: readonly E[]) => {\n\t\tfor (const target of targets) {\n\t\t\tcleanups.get(target)?.()\n\t\t\tcleanups.delete(target)\n\t\t}\n\t}\n\n\tcollection.on('add', attach)\n\tcollection.on('remove', detach)\n\tattach(collection.get())\n\treturn () => {\n\t\tfor (const cleanup of cleanups.values()) cleanup()\n\t\tcleanups.clear()\n\t}\n}\n\n/**\n * Run component effects\n *\n * @since 0.15.0\n * @param {ComponentUI<P, U>} ui - Component UI\n * @param {Effects<P, U>} effects - Effect functions to run\n * @returns {Cleanup} - Cleanup function that runs collected cleanup functions\n * @throws {InvalidEffectsError} - If the effects are invalid\n */\nconst runEffects = <\n\tP extends ComponentProps,\n\tU extends UI & { host: Component<P> },\n>(\n\tui: U,\n\teffects: Effects<P, U>,\n): Cleanup => {\n\tif (!isRecord(effects)) throw new InvalidEffectsError(ui.host)\n\n\tconst cleanups: Cleanup[] = []\n\tconst keys = Object.keys(effects)\n\tfor (const key of keys) {\n\t\tconst k = key as keyof U\n\t\tif (!effects[k]) continue\n\n\t\tconst elementEffects = Array.isArray(effects[k]) ? effects[k] : [effects[k]]\n\t\tif (isCollection<ElementFromKey<U, typeof k>>(ui[k])) {\n\t\t\tcleanups.push(runCollectionEffects(ui.host, ui[k], elementEffects))\n\t\t} else if (ui[k]) {\n\t\t\tconst cleanup = runElementEffects(\n\t\t\t\tui.host,\n\t\t\t\tui[k] as ElementFromKey<U, typeof k>,\n\t\t\t\telementEffects,\n\t\t\t)\n\t\t\tif (cleanup) cleanups.push(cleanup)\n\t\t}\n\t}\n\treturn () => {\n\t\tfor (const cleanup of cleanups) cleanup()\n\t\tcleanups.length = 0\n\t}\n}\n\n/**\n * Resolve reactive property name, reader function or signal\n *\n * @param {Reactive<T, P, E>} reactive - Reactive property name, reader function or signal\n * @param {Component<P, U>} host - Component host element\n * @param {E} target - Element to resolve reactive value for\n * @param {string} [context] - Context for error logging\n * @returns {T} - Resolved reactive value\n */\nconst resolveReactive = <\n\tT extends {},\n\tP extends ComponentProps,\n\tE extends Element,\n>(\n\treactive: Reactive<T, P, E>,\n\thost: Component<P>,\n\ttarget: E,\n\tcontext?: string,\n): T => {\n\ttry {\n\t\treturn isString(reactive)\n\t\t\t? (host[reactive] as unknown as T)\n\t\t\t: isSignal(reactive)\n\t\t\t\t? reactive.get()\n\t\t\t\t: isFunction(reactive)\n\t\t\t\t\t? (reactive(target) as unknown as T)\n\t\t\t\t\t: RESET\n\t} catch (error) {\n\t\tif (context) {\n\t\t\tlog(\n\t\t\t\terror,\n\t\t\t\t`Failed to resolve value of ${valueString(reactive)}${\n\t\t\t\t\tcontext ? ` for ${context}` : ''\n\t\t\t\t} in ${elementName(target)}${\n\t\t\t\t\t(host as unknown as E) !== target ? ` in ${elementName(host)}` : ''\n\t\t\t\t}`,\n\t\t\t\tLOG_ERROR,\n\t\t\t)\n\t\t}\n\t\treturn RESET\n\t}\n}\n\n/**\n * Core effect function for updating element properties based on reactive values.\n * This function handles the lifecycle of reading, updating, and deleting element properties\n * while providing proper error handling and debugging support.\n *\n * @since 0.9.0\n * @param {Reactive<T, P, E>} reactive - The reactive value that drives the element updates\n * @param {ElementUpdater<E, T>} updater - Configuration object defining how to read, update, and delete the element property\n * @returns {Effect<P, E>} Effect function that manages the element property updates\n */\nconst updateElement =\n\t<T extends {}, P extends ComponentProps, E extends Element>(\n\t\treactive: Reactive<T, P, E>,\n\t\tupdater: ElementUpdater<E, T>,\n\t): Effect<P, E> =>\n\t(host, target): Cleanup => {\n\t\tconst { op, name = '', read, update } = updater\n\t\tconst operationDesc = getUpdateDescription(op, name)\n\n\t\tconst ok = (verb: string) => () => {\n\t\t\tif (DEV_MODE && host.debug) {\n\t\t\t\tlog(\n\t\t\t\t\ttarget,\n\t\t\t\t\t`${verb} ${operationDesc} of ${elementName(target)} in ${elementName(host)}`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tupdater.resolve?.(target)\n\t\t}\n\n\t\tconst err = (verb: string) => (error: unknown) => {\n\t\t\tlog(\n\t\t\t\terror,\n\t\t\t\t`Failed to ${verb} ${operationDesc} of ${elementName(target)} in ${elementName(host)}`,\n\t\t\t\tLOG_ERROR,\n\t\t\t)\n\t\t\tupdater.reject?.(error)\n\t\t}\n\n\t\tconst fallback = read(target)\n\n\t\treturn createEffect(() => {\n\t\t\tconst value = resolveReactive(reactive, host, target, operationDesc)\n\t\t\tconst resolvedValue =\n\t\t\t\tvalue === RESET\n\t\t\t\t\t? fallback\n\t\t\t\t\t: value === UNSET\n\t\t\t\t\t\t? updater.delete\n\t\t\t\t\t\t\t? null\n\t\t\t\t\t\t\t: fallback\n\t\t\t\t\t\t: value\n\n\t\t\tif (updater.delete && resolvedValue === null) {\n\t\t\t\ttry {\n\t\t\t\t\tupdater.delete!(target)\n\t\t\t\t\tok('delete')()\n\t\t\t\t} catch (error) {\n\t\t\t\t\terr('delete')(error)\n\t\t\t\t}\n\t\t\t} else if (resolvedValue != null) {\n\t\t\t\tconst current = read(target)\n\t\t\t\tif (Object.is(resolvedValue, current)) return\n\t\t\t\ttry {\n\t\t\t\t\tupdate(target, resolvedValue)\n\t\t\t\t\tok('update')()\n\t\t\t\t} catch (error) {\n\t\t\t\t\terr('update')(error)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n/**\n * Effect for dynamically inserting or removing elements based on a reactive numeric value.\n * Positive values insert elements, negative values remove them.\n *\n * @since 0.12.1\n * @param {Reactive<number, P, E>} reactive - Reactive value determining number of elements to insert (positive) or remove (negative)\n * @param {ElementInserter<E>} inserter - Configuration object defining how to create and position elements\n * @returns {Effect<P, E>} Effect function that manages element insertion and removal\n * /\nconst insertOrRemoveElement =\n\t<P extends ComponentProps, E extends Element = HTMLElement>(\n\t\treactive: Reactive<number, P, E>,\n\t\tinserter?: ElementInserter<E>,\n\t): Effect<P, E> =>\n\t(host, target) => {\n\t\tconst ok = (verb: string) => () => {\n\t\t\tif (DEV_MODE && host.debug) {\n\t\t\t\tlog(\n\t\t\t\t\ttarget,\n\t\t\t\t\t`${verb} element in ${elementName(target)} in ${elementName(host)}`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (isFunction(inserter?.resolve)) {\n\t\t\t\tinserter.resolve(target)\n\t\t\t} else {\n\t\t\t\tconst signal = isSignal<number>(reactive) ? reactive : undefined\n\t\t\t\tif (isState(signal)) signal.set(0)\n\t\t\t}\n\t\t}\n\n\t\tconst err = (verb: string) => (error: unknown) => {\n\t\t\tlog(\n\t\t\t\terror,\n\t\t\t\t`Failed to ${verb} element in ${elementName(target)} in ${elementName(host)}`,\n\t\t\t\tLOG_ERROR,\n\t\t\t)\n\t\t\tinserter?.reject?.(error)\n\t\t}\n\n\t\treturn createEffect(() => {\n\t\t\tconst diff = resolveReactive(\n\t\t\t\treactive,\n\t\t\t\thost,\n\t\t\t\ttarget,\n\t\t\t\t'insertion or deletion',\n\t\t\t)\n\t\t\tconst resolvedDiff = diff === RESET ? 0 : diff\n\n\t\t\tif (resolvedDiff > 0) {\n\t\t\t\t// Positive diff => insert element\n\t\t\t\tif (!inserter) throw new TypeError(`No inserter provided`)\n\t\t\t\ttry {\n\t\t\t\t\tfor (let i = 0; i < resolvedDiff; i++) {\n\t\t\t\t\t\tconst element = inserter.create(target)\n\t\t\t\t\t\tif (!element) continue\n\t\t\t\t\t\ttarget.insertAdjacentElement(\n\t\t\t\t\t\t\tinserter.position ?? 'beforeend',\n\t\t\t\t\t\t\telement,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tok('insert')()\n\t\t\t\t} catch (error) {\n\t\t\t\t\terr('insert')(error)\n\t\t\t\t}\n\t\t\t} else if (resolvedDiff < 0) {\n\t\t\t\ttry {\n\t\t\t\t\tif (\n\t\t\t\t\t\tinserter &&\n\t\t\t\t\t\t(inserter.position === 'afterbegin' ||\n\t\t\t\t\t\t\tinserter.position === 'beforeend')\n\t\t\t\t\t) {\n\t\t\t\t\t\tfor (let i = 0; i > resolvedDiff; i--) {\n\t\t\t\t\t\t\tif (inserter.position === 'afterbegin')\n\t\t\t\t\t\t\t\ttarget.firstElementChild?.remove()\n\t\t\t\t\t\t\telse target.lastElementChild?.remove()\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttarget.remove()\n\t\t\t\t\t}\n\t\t\t\t\tok('remove')()\n\t\t\t\t} catch (error) {\n\t\t\t\t\terr('remove')(error)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t} */\n\nexport {\n\ttype Effect,\n\ttype Effects,\n\ttype ElementEffects,\n\ttype ElementUpdater,\n\ttype Reactive,\n\trunEffects,\n\trunElementEffects,\n\tresolveReactive,\n\tupdateElement,\n\tRESET,\n}\n",
|
|
20
|
+
"import { isFunction, isString } from '@zeix/cause-effect'\nimport type { UI } from './ui'\n\n/* === Types === */\n\ntype Parser<T extends {}, U extends UI> = (\n\tui: U,\n\tvalue: string | null | undefined,\n\told?: string | null,\n) => T\n\ntype LooseReader<T extends {}, U extends UI> = (\n\tui: U,\n) => T | string | null | undefined\ntype Reader<T extends {}, U extends UI> = (ui: U) => T\n\ntype Fallback<T extends {}, U extends UI> = T | Reader<T, U>\n\ntype ParserOrFallback<T extends {}, U extends UI> =\n\t| Parser<T, U>\n\t| Fallback<T, U>\n\n/* === Exported Functions === */\n\n/**\n * Check if a value is a parser\n *\n * @since 0.14.0\n * @param {unknown} value - Value to check if it is a parser\n * @returns {boolean} True if the value is a parser, false otherwise\n */\nconst isParser = <T extends {}, U extends UI>(\n\tvalue: unknown,\n): value is Parser<T, U> => isFunction<T>(value) && value.length >= 2\n\n/**\n * Check if a value is a reader\n *\n * @since 0.15.0\n * @param {unknown} value - Value to check if it is a reader\n * @returns {boolean} True if the value is a reader, false otherwise\n */\nconst isReader = <T extends {}, U extends UI>(\n\tvalue: unknown,\n): value is Reader<T, U> => isFunction<T>(value)\n\n/**\n * Get a fallback value for an element\n *\n * @since 0.14.0\n * @param {U} ui - Component UI\n * @param {ParserOrFallback<T, U>} fallback - Fallback value or parser function\n * @returns {T} Fallback value or parsed value\n */\nconst getFallback = <T extends {}, U extends UI>(\n\tui: U,\n\tfallback: ParserOrFallback<T, U>,\n): T => (isReader<T, U>(fallback) ? fallback(ui) : (fallback as T))\n\n/**\n * Read a value from a UI element\n *\n * @since 0.15.0\n * @param {LooseReader<T, U>} reader - Reader function returning T | string | null | undefined\n * @param {ParserOrFallback<T, U>} fallback - Fallback value or parser function\n * @returns {Reader<T, U>} Parsed value or fallback value\n */\nconst read =\n\t<T extends {}, U extends UI>(\n\t\treader: LooseReader<T, U>,\n\t\tfallback: ParserOrFallback<T, U>,\n\t): Reader<T, U> =>\n\t(ui: U): T => {\n\t\tconst value = reader(ui)\n\t\treturn isString(value) && isParser<T, U>(fallback)\n\t\t\t? fallback(ui, value)\n\t\t\t: ((value as T) ?? getFallback(ui, fallback))\n\t}\n\nexport {\n\ttype Parser,\n\ttype LooseReader,\n\ttype Reader,\n\ttype Fallback,\n\ttype ParserOrFallback,\n\tisParser,\n\tisReader,\n\tgetFallback,\n\tread,\n}\n",
|
|
21
|
+
"import { DependencyTimeoutError, MissingElementError } from './errors'\nimport { type Collection, createCollection } from './signals/collection'\nimport { isNotYetDefinedComponent } from './util'\n\n/* === Types === */\n\n// Split a comma-separated selector into individual selectors\ntype SplitByComma<S extends string> = S extends `${infer First},${infer Rest}`\n\t? [TrimWhitespace<First>, ...SplitByComma<Rest>]\n\t: [TrimWhitespace<S>]\n\n// Trim leading/trailing whitespace from a string\ntype TrimWhitespace<S extends string> = S extends ` ${infer Rest}`\n\t? TrimWhitespace<Rest>\n\t: S extends `${infer Rest} `\n\t\t? TrimWhitespace<Rest>\n\t\t: S\n\n// Extract the rightmost selector part from combinator selectors (space, >, +, ~)\ntype ExtractRightmostSelector<S extends string> =\n\tS extends `${string} ${infer Rest}`\n\t\t? ExtractRightmostSelector<Rest>\n\t\t: S extends `${string}>${infer Rest}`\n\t\t\t? ExtractRightmostSelector<Rest>\n\t\t\t: S extends `${string}+${infer Rest}`\n\t\t\t\t? ExtractRightmostSelector<Rest>\n\t\t\t\t: S extends `${string}~${infer Rest}`\n\t\t\t\t\t? ExtractRightmostSelector<Rest>\n\t\t\t\t\t: S\n\n// Extract tag name from a simple selector (without combinators)\ntype ExtractTagFromSimpleSelector<S extends string> =\n\tS extends `${infer T}.${string}`\n\t\t? T\n\t\t: S extends `${infer T}#${string}`\n\t\t\t? T\n\t\t\t: S extends `${infer T}:${string}`\n\t\t\t\t? T\n\t\t\t\t: S extends `${infer T}[${string}`\n\t\t\t\t\t? T\n\t\t\t\t\t: S\n\n// Main extraction logic for a single selector\ntype ExtractTag<S extends string> = ExtractTagFromSimpleSelector<\n\tExtractRightmostSelector<S>\n>\n\n// Normalize to lowercase and ensure it's a known HTML tag\ntype KnownTag<S extends string> =\n\tLowercase<ExtractTag<S>> extends\n\t\t| keyof HTMLElementTagNameMap\n\t\t| keyof SVGElementTagNameMap\n\t\t| keyof MathMLElementTagNameMap\n\t\t? Lowercase<ExtractTag<S>>\n\t\t: never\n\n// Get element type from a single selector\ntype ElementFromSingleSelector<S extends string> =\n\tKnownTag<S> extends never\n\t\t? HTMLElement\n\t\t: KnownTag<S> extends keyof HTMLElementTagNameMap\n\t\t\t? HTMLElementTagNameMap[KnownTag<S>]\n\t\t\t: KnownTag<S> extends keyof SVGElementTagNameMap\n\t\t\t\t? SVGElementTagNameMap[KnownTag<S>]\n\t\t\t\t: KnownTag<S> extends keyof MathMLElementTagNameMap\n\t\t\t\t\t? MathMLElementTagNameMap[KnownTag<S>]\n\t\t\t\t\t: HTMLElement\n\n// Map a tuple of selectors to a union of their element types\ntype ElementsFromSelectorArray<Selectors extends readonly string[]> = {\n\t[K in keyof Selectors]: Selectors[K] extends string\n\t\t? ElementFromSingleSelector<Selectors[K]>\n\t\t: never\n}[number]\n\n// Main type: handle both single selectors and comma-separated selectors\ntype ElementFromSelector<S extends string> = S extends `${string},${string}`\n\t? ElementsFromSelectorArray<SplitByComma<S>>\n\t: ElementFromSingleSelector<S>\n\ntype FirstElement = {\n\t<S extends string>(selector: S, required: string): ElementFromSelector<S>\n\t<S extends string>(selector: S): ElementFromSelector<S> | undefined\n\t<E extends Element>(selector: string, required: string): E\n\t<E extends Element>(selector: string): E | undefined\n}\n\ntype AllElements = {\n\t<S extends string>(\n\t\tselector: S,\n\t\trequired?: string,\n\t): Collection<ElementFromSelector<S>>\n\t<E extends Element>(selector: string, required?: string): Collection<E>\n}\ntype UI = Record<string, Element | Collection<Element>>\n\ntype ElementFromKey<U extends UI, K extends keyof U> = NonNullable<\n\tU[K] extends Collection<infer E extends Element>\n\t\t? E\n\t\t: U[K] extends Element\n\t\t\t? U[K]\n\t\t\t: never\n>\n\ntype ElementQueries = {\n\tfirst: FirstElement\n\tall: AllElements\n}\n\n/* === Constants === */\n\nconst DEPENDENCY_TIMEOUT = 50\n\n/* === Exported Functions === */\n\n/**\n * Create partially applied helper functions to get descendants and run effects on them\n *\n * @since 0.14.0\n * @param {HTMLElement} host - Host component\n * @returns {ElementSelectors<P>} - Helper functions for selecting descendants\n */\nconst getHelpers = (\n\thost: HTMLElement,\n): [ElementQueries, (run: () => void) => void] => {\n\tconst root = host.shadowRoot ?? host\n\tconst dependencies: Set<string> = new Set()\n\n\t/**\n\t * Get the first descendant element matching a selector\n\t * If the element is a custom elements it will be added to dependencies\n\t *\n\t * @since 0.15.0\n\t * @param {S} selector - Selector for element to check for\n\t * @param {string} [required] - Optional reason for the assertion; if provided, throws on missing element\n\t * @returns {ElementFromSelector<S> | undefined} First matching descendant element, or void if not found and not required\n\t * @throws {MissingElementError} - Thrown when the element is required but not found\n\t */\n\tfunction first<S extends string>(\n\t\tselector: S,\n\t\trequired: string,\n\t): ElementFromSelector<S>\n\tfunction first<S extends string>(\n\t\tselector: S,\n\t): ElementFromSelector<S> | undefined\n\tfunction first<E extends Element>(selector: string, required: string): E\n\tfunction first<E extends Element>(selector: string): E | undefined\n\tfunction first<S extends string>(\n\t\tselector: S,\n\t\trequired?: string,\n\t): ElementFromSelector<S> | undefined {\n\t\tconst target = root.querySelector<ElementFromSelector<S>>(selector)\n\t\tif (required != null && !target)\n\t\t\tthrow new MissingElementError(host, selector, required)\n\n\t\t// Only add to dependencies if element is a custom element that's not yet defined\n\t\tif (target && isNotYetDefinedComponent(target))\n\t\t\tdependencies.add(target.localName)\n\t\treturn target ?? undefined\n\t}\n\n\t/**\n\t * Get all descendant elements matching a selector\n\t * If any element is a custom element it will be added to dependencies\n\t *\n\t * @since 0.15.0\n\t * @param {S} selector - Selector for elements to check for\n\t * @param {string} [required] - Optional reason for the assertion; if provided, throws on missing elements\n\t * @returns {ElementFromSelector<S>[]} All matching descendant elements\n\t * @throws {MissingElementError} - Thrown when elements are required but not found\n\t */\n\tfunction all<S extends string>(\n\t\tselector: S,\n\t\trequired?: string,\n\t): Collection<ElementFromSelector<S>>\n\tfunction all<E extends Element>(\n\t\tselector: string,\n\t\trequired?: string,\n\t): Collection<E>\n\tfunction all<S extends string>(\n\t\tselector: S,\n\t\trequired?: string,\n\t): Collection<ElementFromSelector<S>> {\n\t\tconst collection = createCollection(root, selector)\n\t\tconst targets = collection.get()\n\t\tif (required != null && !targets.length)\n\t\t\tthrow new MissingElementError(host, selector, required)\n\t\tif (targets.length)\n\t\t\ttargets.forEach(target => {\n\t\t\t\t// Only add to dependencies if element is a custom element that's not yet defined\n\t\t\t\tif (isNotYetDefinedComponent(target)) dependencies.add(target.localName)\n\t\t\t})\n\t\treturn collection\n\t}\n\n\t/**\n\t * Resolve dependencies and thereafter run the provided function\n\t *\n\t * @param {() => void} callback - Function to run after resolving dependencies\n\t */\n\tconst resolveDependencies = (callback: () => void) => {\n\t\tif (dependencies.size) {\n\t\t\tconst deps = Array.from(dependencies)\n\t\t\tPromise.race([\n\t\t\t\tPromise.all(deps.map(dep => customElements.whenDefined(dep))),\n\t\t\t\tnew Promise((_, reject) => {\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\treject(\n\t\t\t\t\t\t\tnew DependencyTimeoutError(\n\t\t\t\t\t\t\t\thost,\n\t\t\t\t\t\t\t\tdeps.filter(dep => !customElements.get(dep)),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t}, DEPENDENCY_TIMEOUT)\n\t\t\t\t}),\n\t\t\t])\n\t\t\t\t.then(callback)\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// Error during setup of <${name}>. Trying to run effects anyway.\n\t\t\t\t\tcallback()\n\t\t\t\t})\n\t\t} else {\n\t\t\tcallback()\n\t\t}\n\t}\n\n\treturn [{ first, all }, resolveDependencies]\n}\n\nexport {\n\ttype ElementFromKey,\n\ttype ElementFromSelector,\n\ttype ElementQueries,\n\tgetHelpers,\n\ttype UI,\n}\n",
|
|
22
|
+
"import {\n\ttype ComputedCallback,\n\tcreateComputed,\n\tcreateState,\n\tisComputed,\n\tisComputedCallback,\n\tisFunction,\n\tisMutableSignal,\n\tisSignal,\n\tisState,\n\tisStore,\n\ttype MaybeCleanup,\n\ttype Signal,\n\tUNSET,\n} from '@zeix/cause-effect'\n\nimport { type Effects, runEffects } from './effects'\nimport { InvalidComponentNameError, InvalidPropertyNameError } from './errors'\nimport { isParser, type Parser, type Reader } from './parsers'\nimport { type ElementQueries, getHelpers, type UI } from './ui'\nimport { validatePropertyName } from './util'\n\n/* === Types === */\n\ntype ReservedWords =\n\t| 'constructor'\n\t| 'prototype'\n\t| '__proto__'\n\t| 'toString'\n\t| 'valueOf'\n\t| 'hasOwnProperty'\n\t| 'isPrototypeOf'\n\t| 'propertyIsEnumerable'\n\t| 'toLocaleString'\n\ntype ComponentProp = Exclude<string, keyof HTMLElement | ReservedWords>\ntype ComponentProps = Record<ComponentProp, NonNullable<unknown>>\n\ntype Component<P extends ComponentProps> = HTMLElement & P\ntype ComponentUI<P extends ComponentProps, U extends UI> = U & {\n\thost: Component<P>\n}\n\ntype ComponentSetup<P extends ComponentProps, U extends UI> = (\n\tui: ComponentUI<P, U>,\n) => Effects<P, ComponentUI<P, U>>\n\ntype MethodProducer<P extends ComponentProps, U extends UI> = (\n\tui: U & { host: Component<P> },\n) => void\n\ntype Initializers<P extends ComponentProps, U extends UI> = {\n\t[K in keyof P]?:\n\t\t| P[K]\n\t\t| Signal<P[K]>\n\t\t| Parser<P[K], ComponentUI<P, U>>\n\t\t| Reader<MaybeSignal<P[K]>, ComponentUI<P, U>>\n\t\t| MethodProducer<P, ComponentUI<P, U>>\n}\n\ntype MaybeSignal<T extends {}> = T | Signal<T> | ComputedCallback<T>\n\n/* === Exported Functions === */\n\n/**\n * Define a component with dependency resolution and setup function (connectedCallback)\n *\n * @since 0.15.0\n * @param {string} name - Custom element name\n * @param {object} props - Component properties\n * @param {function} select - Function to select UI elements\n * @param {function} setup - Setup function\n * @throws {InvalidComponentNameError} If component name is invalid\n * @throws {InvalidPropertyNameError} If property name is invalid\n */\nfunction defineComponent<P extends ComponentProps, U extends UI = {}>(\n\tname: string,\n\tprops: Initializers<P, U> = {} as Initializers<P, U>,\n\tselect: (elementQueries: ElementQueries) => U = () => ({}) as U,\n\tsetup: (ui: ComponentUI<P, U>) => Effects<P, ComponentUI<P, U>> = () => ({}),\n): Component<P> {\n\tif (!name.includes('-') || !name.match(/^[a-z][a-z0-9-]*$/))\n\t\tthrow new InvalidComponentNameError(name)\n\tfor (const prop of Object.keys(props)) {\n\t\tconst error = validatePropertyName(prop)\n\t\tif (error) throw new InvalidPropertyNameError(name, prop, error)\n\t}\n\n\tclass Truc extends HTMLElement {\n\t\tdebug?: boolean\n\t\t#ui: ComponentUI<P, U> | undefined\n\t\t#signals = {} as { [K in keyof P]: Signal<P[K]> }\n\t\t#cleanup: MaybeCleanup\n\n\t\tstatic observedAttributes =\n\t\t\tObject.entries(props)\n\t\t\t\t?.filter(([, initializer]) => isParser(initializer))\n\t\t\t\t.map(([prop]) => prop) ?? []\n\n\t\t/**\n\t\t * Native callback when the custom element is first connected to the document\n\t\t */\n\t\tconnectedCallback() {\n\t\t\t// Initialize UI\n\t\t\tconst [elementQueries, resolveDependencies] = getHelpers(this)\n\t\t\tconst ui = {\n\t\t\t\t...select(elementQueries),\n\t\t\t\thost: this as unknown as Component<P>,\n\t\t\t}\n\t\t\tthis.#ui = ui\n\t\t\tObject.freeze(this.#ui)\n\n\t\t\t// Initialize signals\n\t\t\tconst isReaderOrMethodProducer = <K extends keyof P & string>(\n\t\t\t\tvalue: unknown,\n\t\t\t): value is\n\t\t\t\t| Reader<P[K], ComponentUI<P, U>>\n\t\t\t\t| MethodProducer<P, ComponentUI<P, U>> => {\n\t\t\t\treturn isFunction(value)\n\t\t\t}\n\t\t\tconst createSignal = <K extends keyof P & string>(\n\t\t\t\tkey: K,\n\t\t\t\tinitializer: Initializers<P, U>[K],\n\t\t\t) => {\n\t\t\t\tconst result = isParser<P[K], ComponentUI<P, U>>(initializer)\n\t\t\t\t\t? initializer(ui, this.getAttribute(key))\n\t\t\t\t\t: isReaderOrMethodProducer<K>(initializer)\n\t\t\t\t\t\t? initializer(ui)\n\t\t\t\t\t\t: (initializer as MaybeSignal<P[K]>)\n\t\t\t\tif (result != null) this.#setAccessor(key, result)\n\t\t\t}\n\t\t\tfor (const [prop, initializer] of Object.entries(props)) {\n\t\t\t\tif (initializer == null || prop in this) continue\n\t\t\t\tcreateSignal(prop, initializer)\n\t\t\t}\n\n\t\t\t// Resolve dependencies and run setup function\n\t\t\tresolveDependencies(() => {\n\t\t\t\tthis.#cleanup = runEffects(ui, setup(ui))\n\t\t\t})\n\t\t}\n\n\t\t/**\n\t\t * Native callback when the custom element is disconnected from the document\n\t\t */\n\t\tdisconnectedCallback() {\n\t\t\tif (isFunction(this.#cleanup)) this.#cleanup()\n\t\t}\n\n\t\t/**\n\t\t * Native callback when an observed attribute of the custom element changes\n\t\t *\n\t\t * @param {K} name - Name of the modified attribute\n\t\t * @param {string | null} oldValue - Old value of the modified attribute\n\t\t * @param {string | null} newValue - New value of the modified attribute\n\t\t */\n\t\tattributeChangedCallback<K extends keyof P>(\n\t\t\tname: K,\n\t\t\toldValue: string | null,\n\t\t\tnewValue: string | null,\n\t\t) {\n\t\t\t// Not connected yet, unchanged value or controlled by computed\n\t\t\tif (!this.#ui || newValue === oldValue || isComputed(this.#signals[name]))\n\t\t\t\treturn\n\n\t\t\t// Check whether we have a parser for the attribute\n\t\t\tconst parser = props[name]\n\t\t\tif (!isParser<P[K], ComponentUI<P, U>>(parser)) return\n\n\t\t\tconst parsed = parser(this.#ui, newValue, oldValue)\n\t\t\tif (name in this) (this as unknown as P)[name] = parsed\n\t\t\telse this.#setAccessor(name, parsed)\n\t\t}\n\n\t\t/**\n\t\t * Set the signal for a given key\n\t\t *\n\t\t * @since 0.15.0\n\t\t * @param {K} key - Key to set accessor for\n\t\t * @param {MaybeSignal<P[K]>} value - Initial value, signal or computed callback to create signal\n\t\t */\n\t\t#setAccessor<K extends keyof P>(key: K, value: MaybeSignal<P[K]>): void {\n\t\t\tconst signal = isSignal(value)\n\t\t\t\t? value\n\t\t\t\t: isComputedCallback(value)\n\t\t\t\t\t? createComputed(value)\n\t\t\t\t\t: createState(value)\n\t\t\tconst prev = this.#signals[key]\n\t\t\tconst mutable = isMutableSignal(signal)\n\t\t\tthis.#signals[key] = signal as Signal<P[K]>\n\t\t\tObject.defineProperty(this, key, {\n\t\t\t\tget: signal.get,\n\t\t\t\tset: mutable ? signal.set : undefined,\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: mutable,\n\t\t\t})\n\t\t\tif ((prev && isState(prev)) || isStore(prev)) prev.set(UNSET)\n\t\t}\n\t}\n\n\tcustomElements.define(name, Truc)\n\treturn customElements.get(name) as unknown as Component<P>\n}\n\nexport {\n\ttype Component,\n\ttype ComponentProp,\n\ttype ComponentProps,\n\ttype ComponentUI,\n\ttype ComponentSetup,\n\ttype MaybeSignal,\n\ttype ReservedWords,\n\ttype Initializers,\n\tdefineComponent,\n}\n",
|
|
23
|
+
"import {\n\ttype Cleanup,\n\ttype Computed,\n\tcreateComputed,\n\tisFunction,\n\tisString,\n} from '@zeix/cause-effect'\n\nimport type { Component, ComponentProps } from './component'\nimport { type Fallback, getFallback, type Reader } from './parsers'\nimport type { UI } from './ui'\n\n/** @see https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md */\n\n/* === Types === */\n\n/**\n * A context key.\n *\n * A context key can be any type of object, including strings and symbols. The\n * Context type brands the key type with the `__context__` property that\n * carries the type of the value the context references.\n */\ntype Context<K, V> = K & { __context__: V }\n\n/**\n * An unknown context type\n */\ntype UnknownContext = Context<unknown, unknown>\n\n/**\n * A helper type which can extract a Context value type from a Context type\n */\ntype ContextType<T extends UnknownContext> =\n\tT extends Context<infer _, infer V> ? V : never\n\n/**\n * A callback which is provided by a context requester and is called with the value satisfying the request.\n * This callback can be called multiple times by context providers as the requested value is changed.\n */\ntype ContextCallback<V> = (value: V, unsubscribe?: () => void) => void\n\ndeclare global {\n\tinterface HTMLElementEventMap {\n\t\t/**\n\t\t * A 'context-request' event can be emitted by any element which desires\n\t\t * a context value to be injected by an external provider.\n\t\t */\n\t\t'context-request': ContextRequestEvent<UnknownContext>\n\t}\n}\n\n/* === Constants === */\n\nconst CONTEXT_REQUEST = 'context-request'\n\n/* === Exported class === */\n\n/**\n * Class for context-request events\n *\n * An event fired by a context requester to signal it desires a named context.\n *\n * A provider should inspect the `context` property of the event to determine if it has a value that can\n * satisfy the request, calling the `callback` with the requested value if so.\n *\n * If the requested context event contains a truthy `subscribe` value, then a provider can call the callback\n * multiple times if the value is changed, if this is the case the provider should pass an `unsubscribe`\n * function to the callback which requesters can invoke to indicate they no longer wish to receive these updates.\n *\n * @class ContextRequestEvent\n * @extends {Event}\n *\n * @property {T} context - context key\n * @property {ContextCallback<ContextType<T>>} callback - callback function for value getter and unsubscribe function\n * @property {boolean} [subscribe=false] - whether to subscribe to context changes\n */\nclass ContextRequestEvent<T extends UnknownContext> extends Event {\n\treadonly context: T\n\treadonly callback: ContextCallback<ContextType<T>>\n\treadonly subscribe: boolean\n\n\tconstructor(\n\t\tcontext: T,\n\t\tcallback: ContextCallback<ContextType<T>>,\n\t\tsubscribe: boolean = false,\n\t) {\n\t\tsuper(CONTEXT_REQUEST, {\n\t\t\tbubbles: true,\n\t\t\tcomposed: true,\n\t\t})\n\t\tthis.context = context\n\t\tthis.callback = callback\n\t\tthis.subscribe = subscribe\n\t}\n}\n\n/**\n * Provide a context for descendant component consumers\n *\n * @since 0.13.3\n * @param {Context<string, P[K]>[]} contexts - Array of contexts to provide\n * @returns {(host: Component<P>) => Cleanup} Function to add an event listener for ContextRequestEvent returning a cleanup function to remove the event listener\n */\nconst provideContexts =\n\t<P extends ComponentProps>(\n\t\tcontexts: Array<keyof P>,\n\t): ((host: Component<P>) => Cleanup) =>\n\t(host: Component<P>) => {\n\t\tconst listener = (e: ContextRequestEvent<UnknownContext>) => {\n\t\t\tconst { context, callback } = e\n\t\t\tif (\n\t\t\t\tisString(context) &&\n\t\t\t\tcontexts.includes(context as unknown as Extract<keyof P, string>) &&\n\t\t\t\tisFunction(callback)\n\t\t\t) {\n\t\t\t\te.stopImmediatePropagation()\n\t\t\t\tcallback(() => host[context])\n\t\t\t}\n\t\t}\n\t\thost.addEventListener(CONTEXT_REQUEST, listener)\n\t\treturn () => host.removeEventListener(CONTEXT_REQUEST, listener)\n\t}\n\n/**\n * Consume a context value for a component\n *\n * @since 0.15.0\n * @param {Context<string, () => T>} context - Context key to consume\n * @param {Fallback<T, U>} fallback - Fallback value or reader function for fallback\n * @returns {Reader<Computed<T>, U>} Computed signal that returns the consumed context the fallback value\n */\nconst requestContext =\n\t<T extends {}, P extends ComponentProps, U extends UI>(\n\t\tcontext: Context<string, () => T>,\n\t\tfallback: Fallback<T, U & { host: Component<P> }>,\n\t): Reader<Computed<T>, U & { host: Component<P> }> =>\n\t(ui: U & { host: Component<P> }) => {\n\t\tlet consumed = () => getFallback(ui, fallback)\n\t\tui.host.dispatchEvent(\n\t\t\tnew ContextRequestEvent(context, (getter: () => T) => {\n\t\t\t\tconsumed = getter\n\t\t\t}),\n\t\t)\n\t\treturn createComputed(consumed)\n\t}\n\nexport {\n\ttype Context,\n\ttype UnknownContext,\n\ttype ContextType,\n\tCONTEXT_REQUEST,\n\tContextRequestEvent,\n\tprovideContexts,\n\trequestContext,\n}\n",
|
|
24
|
+
"import type { ComponentProps } from '../component'\nimport { type Effect, type Reactive, updateElement } from '../effects'\n\n/* === Internal Functions === */\n\nconst isSafeURL = (value: string): boolean => {\n\tif (/^(mailto|tel):/i.test(value)) return true\n\tif (value.includes('://')) {\n\t\ttry {\n\t\t\tconst url = new URL(value, window.location.origin)\n\t\t\treturn ['http:', 'https:', 'ftp:'].includes(url.protocol)\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\nconst safeSetAttribute = (\n\telement: Element,\n\tattr: string,\n\tvalue: string,\n): void => {\n\tif (/^on/i.test(attr)) throw new Error(`Unsafe attribute: ${attr}`)\n\tvalue = String(value).trim()\n\tif (!isSafeURL(value)) throw new Error(`Unsafe URL for ${attr}: ${value}`)\n\telement.setAttribute(attr, value)\n}\n\n/* === Exported Functions === */\n\n/**\n * Effect for setting an attribute on an element.\n * Sets the specified attribute with security validation for unsafe values.\n *\n * @since 0.8.0\n * @param {string} name - Name of the attribute to set\n * @param {Reactive<string, P, E>} reactive - Reactive value bound to the attribute value (defaults to attribute name)\n * @returns {Effect<P, E>} Effect function that sets the attribute on the element\n */\nconst setAttribute = <P extends ComponentProps, E extends Element>(\n\tname: string,\n\treactive: Reactive<string, P, E> = name as Reactive<string, P, E>,\n): Effect<P, E> =>\n\tupdateElement(reactive, {\n\t\top: 'a',\n\t\tname,\n\t\tread: el => el.getAttribute(name),\n\t\tupdate: (el, value) => {\n\t\t\tsafeSetAttribute(el, name, value)\n\t\t},\n\t\tdelete: el => {\n\t\t\tel.removeAttribute(name)\n\t\t},\n\t})\n\n/**\n * Effect for toggling a boolean attribute on an element.\n * When the reactive value is true, the attribute is present; when false, it's absent.\n *\n * @since 0.8.0\n * @param {string} name - Name of the attribute to toggle\n * @param {Reactive<boolean, P, E>} reactive - Reactive value bound to the attribute presence (defaults to attribute name)\n * @returns {Effect<P, E>} Effect function that toggles the attribute on the element\n */\nconst toggleAttribute = <\n\tP extends ComponentProps,\n\tE extends Element = HTMLElement,\n>(\n\tname: string,\n\treactive: Reactive<boolean, P, E> = name as Reactive<boolean, P, E>,\n): Effect<P, E> =>\n\tupdateElement(reactive, {\n\t\top: 'a',\n\t\tname,\n\t\tread: el => el.hasAttribute(name),\n\t\tupdate: (el, value) => {\n\t\t\tel.toggleAttribute(name, value)\n\t\t},\n\t})\n\nexport { setAttribute, toggleAttribute }\n",
|
|
25
|
+
"import type { ComponentProps } from '../component'\nimport { type Effect, type Reactive, updateElement } from '../effects'\n\n/* === Exported Function === */\n\n/**\n * Effect for toggling a CSS class token on an element.\n * When the reactive value is true, the class is added; when false, it's removed.\n *\n * @since 0.8.0\n * @param {string} token - CSS class token to toggle\n * @param {Reactive<boolean, P, E>} reactive - Reactive value bound to the class presence (defaults to class name)\n * @returns {Effect<P, U, E>} Effect function that toggles the class on the element\n */\nconst toggleClass = <P extends ComponentProps, E extends Element>(\n\ttoken: string,\n\treactive: Reactive<boolean, P, E> = token as Reactive<boolean, P, E>,\n): Effect<P, E> =>\n\tupdateElement(reactive, {\n\t\top: 'c',\n\t\tname: token,\n\t\tread: el => el.classList.contains(token),\n\t\tupdate: (el, value) => {\n\t\t\tel.classList.toggle(token, value)\n\t\t},\n\t})\n\nexport { toggleClass }\n",
|
|
26
|
+
"/* === Constants === */\n\n// High-frequency events that are passive by default and should be scheduled\nconst PASSIVE_EVENTS = new Set([\n\t'scroll',\n\t'resize',\n\t'mousewheel',\n\t'touchstart',\n\t'touchmove',\n\t'wheel',\n])\n\n/* === Internal === */\n\nconst pendingElements = new Set<Element>()\nconst tasks = new WeakMap<Element, () => void>()\nlet requestId: number | undefined\n\nconst runTasks = () => {\n\trequestId = undefined\n\tconst elements = Array.from(pendingElements)\n\tpendingElements.clear()\n\tfor (const element of elements) tasks.get(element)?.()\n}\n\nconst requestTick = () => {\n\tif (requestId) cancelAnimationFrame(requestId)\n\trequestId = requestAnimationFrame(runTasks)\n}\n\n/* === Exported Function === */\n\n/**\n * Schedule a task to be executed on the next animation frame, with automatic\n * deduplication per component. If the same component schedules multiple tasks\n * before the next frame, only the latest task will be executed.\n *\n * @param element - Element for deduplication\n * @param task - Function to execute (typically calls batch() or sets a signal)\n */\nconst schedule = (element: Element, task: () => void) => {\n\ttasks.set(element, task)\n\tpendingElements.add(element)\n\trequestTick()\n}\n\nexport { PASSIVE_EVENTS, schedule }\n",
|
|
27
|
+
"import { batch, type Cleanup, isRecord } from '@zeix/cause-effect'\nimport type { ComponentProps } from '../component'\nimport { type Effect } from '../effects'\nimport { PASSIVE_EVENTS, schedule } from '../scheduler'\nimport { elementName, LOG_ERROR, log } from '../util'\n\n/* === Types === */\n\ntype EventType<K extends string> = K extends keyof HTMLElementEventMap\n\t? HTMLElementEventMap[K]\n\t: Event\n\ntype EventHandler<P extends ComponentProps, Evt extends Event> = (\n\tevent: Evt,\n) => { [K in keyof P]?: P[K] } | void | Promise<void>\n\n/* === Exported Function === */\n\n/**\n * Effect for attaching an event listener to an element.\n * Provides proper cleanup when the effect is disposed.\n *\n * @since 0.14.0\n * @param {K} type - Event type\n * @param {EventHandler<P, E, EventType<K>>} handler - Event handler function\n * @param {AddEventListenerOptions | boolean} options - Event listener options\n * @returns {Effect<ComponentProps, E>} Effect function that manages the event listener\n */\nconst on =\n\t<\n\t\tK extends keyof HTMLElementEventMap | string,\n\t\tP extends ComponentProps,\n\t\tE extends Element = HTMLElement,\n\t>(\n\t\ttype: K,\n\t\thandler: EventHandler<P, EventType<K>>,\n\t\toptions: AddEventListenerOptions = {},\n\t): Effect<P, E> =>\n\t(host, target): Cleanup => {\n\t\tif (!('passive' in options))\n\t\t\toptions = { ...options, passive: PASSIVE_EVENTS.has(type) }\n\t\tconst listener = (e: Event) => {\n\t\t\tconst task = () => {\n\t\t\t\tconst result = handler(e as EventType<K>)\n\t\t\t\tif (!isRecord(result)) return\n\t\t\t\tbatch(() => {\n\t\t\t\t\tfor (const [key, value] of Object.entries(result)) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\thost[key as keyof P] = value\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tlog(\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\t`Reactive property \"${key}\" on ${elementName(host)} from event ${type} on ${elementName(target)} could not be set, because it is read-only.`,\n\t\t\t\t\t\t\t\tLOG_ERROR,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t\tif (options.passive) schedule(target, task)\n\t\t\telse task()\n\t\t}\n\t\ttarget.addEventListener(type, listener, options)\n\t\treturn () => target.removeEventListener(type, listener)\n\t}\n\nexport { type EventHandler, type EventType, on }\n",
|
|
28
|
+
"import type { ComponentProps } from '../component'\nimport { type Effect, type Reactive, updateElement } from '../effects'\nimport { schedule } from '../scheduler'\n\n/* === Types === */\n\ntype DangerouslySetInnerHTMLOptions = {\n\tshadowRootMode?: ShadowRootMode\n\tallowScripts?: boolean\n}\n\n/* === Exported Function === */\n\n/**\n * Effect for setting the inner HTML of an element with optional Shadow DOM support.\n * Provides security options for script execution and shadow root creation.\n *\n * @since 0.11.0\n * @param {Reactive<string, P, E>} reactive - Reactive value bound to the inner HTML content\n * @param {DangerouslySetInnerHTMLOptions} options - Configuration options: shadowRootMode, allowScripts\n * @returns {Effect<P, E>} Effect function that sets the inner HTML of the element\n */\nconst dangerouslySetInnerHTML = <P extends ComponentProps, E extends Element>(\n\treactive: Reactive<string, P, E>,\n\toptions: DangerouslySetInnerHTMLOptions = {},\n): Effect<P, E> =>\n\tupdateElement(reactive, {\n\t\top: 'h',\n\t\tread: el =>\n\t\t\t(el.shadowRoot || !options.shadowRootMode ? el : null)?.innerHTML ?? '',\n\t\tupdate: (el, html) => {\n\t\t\tconst { shadowRootMode, allowScripts } = options\n\t\t\tif (!html) {\n\t\t\t\tif (el.shadowRoot) el.shadowRoot.innerHTML = '<slot></slot>'\n\t\t\t\treturn ''\n\t\t\t}\n\t\t\tif (shadowRootMode && !el.shadowRoot)\n\t\t\t\tel.attachShadow({ mode: shadowRootMode })\n\t\t\tconst target = el.shadowRoot || el\n\t\t\tschedule(el, () => {\n\t\t\t\ttarget.innerHTML = html\n\t\t\t\tif (allowScripts) {\n\t\t\t\t\ttarget.querySelectorAll('script').forEach(script => {\n\t\t\t\t\t\tconst newScript = document.createElement('script')\n\t\t\t\t\t\tnewScript.appendChild(\n\t\t\t\t\t\t\tdocument.createTextNode(script.textContent ?? ''),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t// Safely copy only the type attribute to preserve module/MIME type info\n\t\t\t\t\t\tconst typeAttr = script.getAttribute('type')\n\t\t\t\t\t\tif (typeAttr) newScript.setAttribute('type', typeAttr)\n\t\t\t\t\t\ttarget.appendChild(newScript)\n\t\t\t\t\t\tscript.remove()\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t})\n\t\t\treturn allowScripts ? ' with scripts' : ''\n\t\t},\n\t})\n\nexport { type DangerouslySetInnerHTMLOptions, dangerouslySetInnerHTML }\n",
|
|
29
|
+
"import {\n\tcreateComputed,\n\tisComputedCallback,\n\tisFunction,\n\tisRecord,\n\tisSignal,\n\tisString,\n\ttype MaybeCleanup,\n\tUNSET,\n} from '@zeix/cause-effect'\nimport type { Component, ComponentProps } from '../component'\nimport type { Effect, Reactive } from '../effects'\nimport { InvalidCustomElementError, InvalidReactivesError } from '../errors'\nimport { elementName, isCustomElement } from '../util'\n\n/* === Types === */\n\ntype PassedProp<T, P extends ComponentProps, E extends HTMLElement> =\n\t| Reactive<T, P, E>\n\t| [Reactive<T, P, E>, (value: T) => void]\n\ntype PassedProps<P extends ComponentProps, Q extends ComponentProps> = {\n\t[K in keyof Q & string]?: PassedProp<Q[K], P, Component<Q>>\n}\n\n/* === Exported Function === */\n\n/**\n * Effect for passing reactive values to a descendant Le Truc component.\n *\n * @since 0.15.0\n * @param {MutableReactives<Component<Q>, P>} props - Reactive values to pass\n * @returns {Effect<P, Component<Q>>} Effect function that passes reactive values to the descendant component\n * @throws {InvalidCustomElementError} When the target element is not a valid custom element\n * @throws {InvalidReactivesError} When the provided reactives is not a record of signals, reactive property names or functions\n * @throws {Error} When passing signals failed for some other reason\n */\nconst pass =\n\t<P extends ComponentProps, Q extends ComponentProps>(\n\t\tprops: PassedProps<P, Q> | ((target: Component<Q>) => PassedProps<P, Q>),\n\t): Effect<P, Component<Q>> =>\n\t(host, target): MaybeCleanup => {\n\t\tif (!isCustomElement(target))\n\t\t\tthrow new InvalidCustomElementError(\n\t\t\t\ttarget,\n\t\t\t\t`pass from ${elementName(host)}`,\n\t\t\t)\n\t\tconst reactives = isFunction(props) ? props(target) : props\n\t\tif (!isRecord(reactives))\n\t\t\tthrow new InvalidReactivesError(host, target, reactives)\n\n\t\tconst resetProperties: PropertyDescriptorMap = {}\n\n\t\t// Return getter from signal, reactive property name or function\n\t\tconst getGetter = (value: unknown) => {\n\t\t\tif (isSignal(value)) return value.get\n\t\t\tconst fn =\n\t\t\t\tisString(value) && value in host\n\t\t\t\t\t? () => host[value as keyof typeof host]\n\t\t\t\t\t: isComputedCallback(value)\n\t\t\t\t\t\t? value\n\t\t\t\t\t\t: undefined\n\t\t\treturn fn ? createComputed(fn).get : undefined\n\t\t}\n\n\t\t// Iterate through reactives\n\t\tfor (const [prop, reactive] of Object.entries(reactives)) {\n\t\t\tif (reactive == null) continue\n\n\t\t\t// Ensure target has configurable property\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(target, prop)\n\t\t\tif (!(prop in target) || !descriptor?.configurable) continue\n\n\t\t\t// Determine getter\tand setter\n\t\t\tconst applied =\n\t\t\t\tisFunction(reactive) && reactive.length === 1\n\t\t\t\t\t? reactive(target)\n\t\t\t\t\t: reactive\n\t\t\tconst isArray = Array.isArray(applied) && applied.length === 2\n\t\t\tconst getter = getGetter(isArray ? applied[0] : applied)\n\t\t\tconst setter = isArray && isFunction(applied[1]) ? applied[1] : undefined\n\t\t\tif (!getter) continue\n\n\t\t\t// Store original descriptor for reset and assign new descriptor\n\t\t\tresetProperties[prop] = descriptor\n\t\t\tObject.defineProperty(target, prop, {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tget: getter,\n\t\t\t\tset: setter,\n\t\t\t})\n\n\t\t\t// Unset previous value so subscribers are notified\n\t\t\tdescriptor.set?.call(target, UNSET)\n\t\t}\n\n\t\t// Reset to original descriptors on cleanup\n\t\treturn () => {\n\t\t\tObject.defineProperties(target, resetProperties)\n\t\t}\n\t}\n\nexport { type PassedProp, type PassedProps, pass }\n",
|
|
30
|
+
"import { UNSET } from '@zeix/cause-effect'\nimport type { ComponentProps } from '../component'\nimport { type Effect, type Reactive, updateElement } from '../effects'\n\n/* === Exported Functions === */\n\n/**\n * Effect for setting a property on an element.\n * Sets the specified property directly on the element object.\n *\n * @since 0.8.0\n * @param {K} key - Name of the property to set\n * @param {Reactive<E[K], P, E>} reactive - Reactive value bound to the property value (defaults to property name)\n * @returns {Effect<P, E>} Effect function that sets the property on the element\n */\nconst setProperty = <\n\tP extends ComponentProps,\n\tE extends Element,\n\tK extends keyof E & string,\n>(\n\tkey: K,\n\treactive: Reactive<E[K] & {}, P, E> = key as unknown as Reactive<\n\t\tE[K] & {},\n\t\tP,\n\t\tE\n\t>,\n): Effect<P, E> =>\n\tupdateElement(reactive, {\n\t\top: 'p',\n\t\tname: key,\n\t\tread: el => (key in el ? el[key] : UNSET),\n\t\tupdate: (el, value) => {\n\t\t\tel[key] = value\n\t\t},\n\t})\n\n/**\n * Effect for controlling element visibility by setting the 'hidden' property.\n * When the reactive value is true, the element is shown; when false, it's hidden.\n *\n * @since 0.13.1\n * @param {Reactive<boolean, P, E>} reactive - Reactive value bound to the visibility state\n * @returns {Effect<P, E>} Effect function that controls element visibility\n */\nconst show = <P extends ComponentProps, E extends HTMLElement = HTMLElement>(\n\treactive: Reactive<boolean, P, E>,\n): Effect<P, E> =>\n\tupdateElement(reactive, {\n\t\top: 'p',\n\t\tname: 'hidden',\n\t\tread: el => !el.hidden,\n\t\tupdate: (el, value) => {\n\t\t\tel.hidden = !value\n\t\t},\n\t})\n\nexport { setProperty, show }\n",
|
|
31
|
+
"import type { ComponentProps } from '../component'\nimport { type Effect, type Reactive, updateElement } from '../effects'\n\n/* === Exported Function === */\n\n/**\n * Effect for setting a CSS style property on an element.\n * Sets the specified style property with support for deletion via UNSET.\n *\n * @since 0.8.0\n * @param {string} prop - Name of the CSS style property to set\n * @param {Reactive<string, P, E>} reactive - Reactive value bound to the style property value (defaults to property name)\n * @returns {Effect<P, E>} Effect function that sets the style property on the element\n */\nconst setStyle = <\n\tP extends ComponentProps,\n\tE extends HTMLElement | SVGElement | MathMLElement,\n>(\n\tprop: string,\n\treactive: Reactive<string, P, E> = prop as Reactive<string, P, E>,\n): Effect<P, E> =>\n\tupdateElement(reactive, {\n\t\top: 's',\n\t\tname: prop,\n\t\tread: el => el.style.getPropertyValue(prop),\n\t\tupdate: (el, value) => {\n\t\t\tel.style.setProperty(prop, value)\n\t\t},\n\t\tdelete: el => {\n\t\t\tel.style.removeProperty(prop)\n\t\t},\n\t})\n\nexport { setStyle }\n",
|
|
32
|
+
"import type { ComponentProps } from '../component'\nimport { type Effect, type Reactive, updateElement } from '../effects'\n\n/* === Exported Function === */\n\n/**\n * Effect for setting the text content of an element.\n * Replaces all child nodes (except comments) with a single text node.\n *\n * @since 0.8.0\n * @param {Reactive<string, P, E>} reactive - Reactive value bound to the text content\n * @returns {Effect<P, E>} Effect function that sets the text content of the element\n */\nconst setText = <P extends ComponentProps, E extends Element>(\n\treactive: Reactive<string, P, E>,\n): Effect<P, E> =>\n\tupdateElement(reactive, {\n\t\top: 't',\n\t\tread: el => el.textContent,\n\t\tupdate: (el, value) => {\n\t\t\tArray.from(el.childNodes)\n\t\t\t\t.filter(node => node.nodeType !== Node.COMMENT_NODE)\n\t\t\t\t.forEach(node => node.remove())\n\t\t\tel.append(document.createTextNode(value))\n\t\t},\n\t})\n\nexport { setText }\n",
|
|
33
|
+
"import type { Parser } from '../parsers'\nimport type { UI } from '../ui'\n\n/**\n * Parse a boolean attribute as an actual boolean value\n *\n * @since 0.13.1\n * @returns {Parser<boolean, UI>}\n */\nconst asBoolean =\n\t(): Parser<boolean, UI> => (_: UI, value: string | null | undefined) =>\n\t\tvalue != null && value !== 'false'\n\nexport { asBoolean }\n",
|
|
34
|
+
"import { type Fallback, getFallback, type Parser } from '../parsers'\nimport type { UI } from '../ui'\n\n/**\n * Parse a string as a JSON serialized object with a fallback\n *\n * @since 0.11.0\n * @param {Fallback<T, U>} fallback - Fallback value or reader function\n * @returns {Parser<T, U>} Parser function\n * @throws {TypeError} If the value and fallback are both null or undefined\n * @throws {SyntaxError} If value is not a valid JSON string\n */\nconst asJSON =\n\t<T extends {}, U extends UI>(fallback: Fallback<T, U>): Parser<T, U> =>\n\t(ui: U, value: string | null | undefined) => {\n\t\tif ((value ?? fallback) == null)\n\t\t\tthrow new TypeError(\n\t\t\t\t'asJSON: Value and fallback are both null or undefined',\n\t\t\t)\n\t\tif (value == null) return getFallback(ui, fallback)\n\t\tif (value === '') throw new TypeError('Empty string is not valid JSON')\n\t\tlet result: T | undefined\n\t\ttry {\n\t\t\tresult = JSON.parse(value)\n\t\t} catch (error) {\n\t\t\tthrow new SyntaxError(`Failed to parse JSON: ${String(error)}`, {\n\t\t\t\tcause: error,\n\t\t\t})\n\t\t}\n\t\treturn result ?? getFallback(ui, fallback)\n\t}\n\nexport { asJSON }\n",
|
|
35
|
+
"import { type Fallback, getFallback, type Parser } from '../parsers'\nimport type { UI } from '../ui'\n\n/* === Internal Functions === */\n\nconst parseNumber = (\n\tparseFn: (v: string) => number,\n\tvalue: string | null | undefined,\n) => {\n\tif (value == null) return\n\tconst parsed = parseFn(value)\n\treturn Number.isFinite(parsed) ? parsed : undefined\n}\n\n/* === Exported Functions === */\n\n/**\n * Parse a string as a number forced to integer with a fallback\n *\n * Supports hexadecimal and scientific notation\n *\n * @since 0.11.0\n * @param {Fallback<number, U>} [fallback=0] - Fallback value or reader function\n * @returns {Parser<number, U>} Parser function\n */\nconst asInteger =\n\t<U extends UI>(fallback: Fallback<number, U> = 0): Parser<number, U> =>\n\t(ui: U, value: string | null | undefined) => {\n\t\tif (value == null) return getFallback(ui, fallback)\n\n\t\t// Handle hexadecimal notation\n\t\tconst trimmed = value.trim()\n\t\tif (trimmed.toLowerCase().startsWith('0x'))\n\t\t\treturn (\n\t\t\t\tparseNumber(v => parseInt(v, 16), trimmed) ?? getFallback(ui, fallback)\n\t\t\t)\n\n\t\t// Handle other formats (including scientific notation)\n\t\tconst parsed = parseNumber(parseFloat, value)\n\t\treturn parsed != null ? Math.trunc(parsed) : getFallback(ui, fallback)\n\t}\n\n/**\n * Parse a string as a number with a fallback\n *\n * @since 0.11.0\n * @param {Fallback<number, U>} [fallback=0] - Fallback value or reader function\n * @returns {Parser<number, U>} Parser function\n */\nconst asNumber =\n\t<U extends UI>(fallback: Fallback<number, U> = 0): Parser<number, U> =>\n\t(ui: U, value: string | null | undefined) =>\n\t\tparseNumber(parseFloat, value) ?? getFallback(ui, fallback)\n\nexport { asInteger, asNumber }\n",
|
|
36
|
+
"import { type Fallback, getFallback, type Parser } from '../parsers'\nimport type { UI } from '../ui'\n\n/**\n * Pass through string with a fallback\n *\n * @since 0.11.0\n * @param {Fallback<string, U>} [fallback=''] - Fallback value or reader function\n * @returns {Parser<string, U>} Parser function\n */\nconst asString =\n\t<U extends UI>(fallback: Fallback<string, U> = ''): Parser<string, U> =>\n\t(ui: U, value: string | null | undefined) =>\n\t\tvalue ?? getFallback(ui, fallback)\n\n/**\n * Parse a string as a multi-state value (for example: ['true', 'false', 'mixed'], defaulting to the first valid option\n *\n * @since 0.9.0\n * @param {[string, ...string[]]} valid - Array of valid values\n * @returns {Parser<string, UI>} Parser function\n */\nconst asEnum =\n\t(valid: [string, ...string[]]): Parser<string, UI> =>\n\t(_: UI, value: string | null | undefined) => {\n\t\tif (value == null) return valid[0]\n\t\tconst lowerValue = value.toLowerCase()\n\t\tconst matchingValid = valid.find(v => v.toLowerCase() === lowerValue)\n\t\treturn matchingValid ? value : valid[0]\n\t}\n\nexport { asString, asEnum }\n",
|
|
37
|
+
"import {\n\ttype Computed,\n\ttype MaybeCleanup,\n\tnotify,\n\tsubscribe,\n\tTYPE_COMPUTED,\n\ttype Watcher,\n} from '@zeix/cause-effect'\nimport type { Component, ComponentProps } from '../component'\nimport { getFallback, type ParserOrFallback } from '../parsers'\nimport { PASSIVE_EVENTS, schedule } from '../scheduler'\nimport type { ElementFromKey, UI } from '../ui'\nimport { isCollection } from './collection'\n\n/* === Types === */\n\ntype EventType<K extends string> = K extends keyof HTMLElementEventMap\n\t? HTMLElementEventMap[K]\n\t: Event\n\ntype SensorHandler<\n\tT extends {},\n\tEvt extends Event,\n\tU extends UI,\n\tE extends Element,\n> = (context: {\n\tevent: Evt\n\tui: U\n\ttarget: E\n\tprev: T\n}) => T | void | Promise<void>\n\ntype SensorEvents<T extends {}, U extends UI, E extends Element> = {\n\t[K in keyof HTMLElementEventMap]?: SensorHandler<T, EventType<K>, U, E>\n}\n\n/* === Exported Functions === */\n\n/**\n * Produce a computed signal from transformed event data\n *\n * @since 0.14.0\n * @param {S} key - name of UI key\n * @param {ParserOrFallback<T>} init - Initial value, reader or parser\n * @param {SensorEvents<T, ElementFromSelector<S>, C>} events - Transformation functions for events\n * @returns {Extractor<Computed<T>, C>} Extractor function for value from event\n */\nconst createSensor =\n\t<T extends {}, P extends ComponentProps, U extends UI, K extends keyof U>(\n\t\tinit: ParserOrFallback<T, U>,\n\t\tkey: K,\n\t\tevents: SensorEvents<T, U, ElementFromKey<U, K>>,\n\t): ((ui: U & { host: Component<P> }) => Computed<T>) =>\n\t(ui: U & { host: Component<P> }) => {\n\t\tconst { host } = ui\n\t\tconst watchers: Set<Watcher> = new Set()\n\t\tlet value: T = getFallback(ui, init)\n\t\tconst targets = isCollection(ui[key])\n\t\t\t? ui[key].get()\n\t\t\t: [ui[key] as ElementFromKey<U & { host: Component<P> }, K>]\n\t\tconst eventMap = new Map<string, EventListener>()\n\t\tlet cleanup: MaybeCleanup\n\n\t\tconst getTarget = (eventTarget: Node): ElementFromKey<U, K> | undefined => {\n\t\t\tfor (const t of targets) {\n\t\t\t\tif (t.contains(eventTarget)) return t as ElementFromKey<U, K>\n\t\t\t}\n\t\t}\n\n\t\tconst listen = () => {\n\t\t\tfor (const [type, handler] of Object.entries(events)) {\n\t\t\t\tconst options = { passive: PASSIVE_EVENTS.has(type) }\n\t\t\t\tconst listener = (e: Event) => {\n\t\t\t\t\tconst eventTarget = e.target as Node\n\t\t\t\t\tif (!eventTarget) return\n\t\t\t\t\tconst target = getTarget(eventTarget)\n\t\t\t\t\tif (!target) return\n\t\t\t\t\te.stopPropagation()\n\n\t\t\t\t\tconst task = () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst next = handler({\n\t\t\t\t\t\t\t\tevent: e as any,\n\t\t\t\t\t\t\t\tui,\n\t\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\t\tprev: value,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tif (next == null || next instanceof Promise) return\n\t\t\t\t\t\t\tif (!Object.is(next, value)) {\n\t\t\t\t\t\t\t\tvalue = next\n\t\t\t\t\t\t\t\tif (watchers.size) notify(watchers)\n\t\t\t\t\t\t\t\telse if (cleanup) cleanup()\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\te.stopImmediatePropagation()\n\t\t\t\t\t\t\tthrow error\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (options.passive) schedule(host, task)\n\t\t\t\t\telse task()\n\t\t\t\t}\n\t\t\t\teventMap.set(type, listener)\n\t\t\t\thost.addEventListener(type, listener, options)\n\t\t\t}\n\t\t\tcleanup = () => {\n\t\t\t\tif (eventMap.size) {\n\t\t\t\t\tfor (const [type, listener] of eventMap)\n\t\t\t\t\t\thost.removeEventListener(type, listener)\n\t\t\t\t\teventMap.clear()\n\t\t\t\t}\n\t\t\t\tcleanup = undefined\n\t\t\t}\n\t\t}\n\n\t\tconst sensor = {} as Computed<T>\n\t\tObject.defineProperties(sensor, {\n\t\t\t[Symbol.toStringTag]: {\n\t\t\t\tvalue: TYPE_COMPUTED,\n\t\t\t},\n\t\t\tget: {\n\t\t\t\tvalue: () => {\n\t\t\t\t\tsubscribe(watchers)\n\t\t\t\t\tif (watchers.size && !eventMap.size) listen()\n\t\t\t\t\treturn value\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\t\treturn sensor\n\t}\n\nexport { createSensor, type SensorEvents }\n"
|
|
38
|
+
],
|
|
39
|
+
"mappings": "AAAA,MAAM,UAAgC,KAAM,CAC3C,WAAW,CAAC,EAAe,CAC1B,MAAM,mCAAmC,GAAO,EAChD,KAAK,KAAO,0BAEd,CAEA,MAAM,UAA6B,SAAU,CAC5C,WAAW,CAAC,EAAe,EAAe,CACzC,MAAM,WAAW,cAAkB,GAAO,EAC1C,KAAK,KAAO,uBAEd,CAEA,MAAM,WAAgC,SAAU,CAC/C,WAAW,CAAC,EAAe,EAAe,CACzC,MAAM,wBAAwB,QAAY,GAAO,EACjD,KAAK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