@vielzeug/craftit 2.0.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -108
- package/dist/controls/a11y-control.cjs +2 -0
- package/dist/controls/a11y-control.cjs.map +1 -0
- package/dist/controls/a11y-control.d.ts +16 -0
- package/dist/controls/a11y-control.d.ts.map +1 -0
- package/dist/controls/a11y-control.js +2 -0
- package/dist/controls/a11y-control.js.map +1 -0
- package/dist/controls/checkable-control.cjs +2 -0
- package/dist/controls/checkable-control.cjs.map +1 -0
- package/dist/controls/checkable-control.d.ts +15 -0
- package/dist/controls/checkable-control.d.ts.map +1 -0
- package/dist/controls/checkable-control.js +2 -0
- package/dist/controls/checkable-control.js.map +1 -0
- package/dist/controls/choice-field-control.cjs +2 -0
- package/dist/controls/choice-field-control.cjs.map +1 -0
- package/dist/controls/choice-field-control.d.ts +3 -0
- package/dist/controls/choice-field-control.d.ts.map +1 -0
- package/dist/controls/choice-field-control.js +2 -0
- package/dist/controls/choice-field-control.js.map +1 -0
- package/dist/controls/field-control.cjs +2 -0
- package/dist/controls/field-control.cjs.map +1 -0
- package/dist/controls/field-control.d.ts +111 -0
- package/dist/controls/field-control.d.ts.map +1 -0
- package/dist/controls/field-control.js +2 -0
- package/dist/controls/field-control.js.map +1 -0
- package/dist/controls/index.d.ts +12 -0
- package/dist/controls/index.d.ts.map +1 -0
- package/dist/controls/internal/control-state.cjs +2 -0
- package/dist/controls/internal/control-state.cjs.map +1 -0
- package/dist/controls/internal/control-state.d.ts +21 -0
- package/dist/controls/internal/control-state.d.ts.map +1 -0
- package/dist/controls/internal/control-state.js +2 -0
- package/dist/controls/internal/control-state.js.map +1 -0
- package/dist/controls/internal/keyboard-utils.cjs +2 -0
- package/dist/controls/internal/keyboard-utils.cjs.map +1 -0
- package/dist/controls/internal/keyboard-utils.d.ts +7 -0
- package/dist/controls/internal/keyboard-utils.d.ts.map +1 -0
- package/dist/controls/internal/keyboard-utils.js +2 -0
- package/dist/controls/internal/keyboard-utils.js.map +1 -0
- package/dist/controls/internal/number-utils.cjs +2 -0
- package/dist/controls/internal/number-utils.cjs.map +1 -0
- package/dist/controls/internal/number-utils.d.ts +6 -0
- package/dist/controls/internal/number-utils.d.ts.map +1 -0
- package/dist/controls/internal/number-utils.js +2 -0
- package/dist/controls/internal/number-utils.js.map +1 -0
- package/dist/controls/internal/validation-utils.cjs +2 -0
- package/dist/controls/internal/validation-utils.cjs.map +1 -0
- package/dist/controls/internal/validation-utils.d.ts +13 -0
- package/dist/controls/internal/validation-utils.d.ts.map +1 -0
- package/dist/controls/internal/validation-utils.js +2 -0
- package/dist/controls/internal/validation-utils.js.map +1 -0
- package/dist/controls/list-control.cjs +2 -0
- package/dist/controls/list-control.cjs.map +1 -0
- package/dist/controls/list-control.d.ts +23 -0
- package/dist/controls/list-control.d.ts.map +1 -0
- package/dist/controls/list-control.js +2 -0
- package/dist/controls/list-control.js.map +1 -0
- package/dist/controls/overlay-control.cjs +2 -0
- package/dist/controls/overlay-control.cjs.map +1 -0
- package/dist/{labs/overlay.d.ts → controls/overlay-control.d.ts} +19 -14
- package/dist/controls/overlay-control.d.ts.map +1 -0
- package/dist/controls/overlay-control.js +2 -0
- package/dist/controls/overlay-control.js.map +1 -0
- package/dist/controls/popup-list-control.cjs +2 -0
- package/dist/controls/popup-list-control.cjs.map +1 -0
- package/dist/controls/popup-list-control.d.ts +160 -0
- package/dist/controls/popup-list-control.d.ts.map +1 -0
- package/dist/controls/popup-list-control.js +2 -0
- package/dist/controls/popup-list-control.js.map +1 -0
- package/dist/controls/press-control.cjs +2 -0
- package/dist/controls/press-control.cjs.map +1 -0
- package/dist/controls/press-control.d.ts +12 -0
- package/dist/controls/press-control.d.ts.map +1 -0
- package/dist/controls/press-control.js +2 -0
- package/dist/controls/press-control.js.map +1 -0
- package/dist/controls/slider-control.cjs +2 -0
- package/dist/controls/slider-control.cjs.map +1 -0
- package/dist/controls/slider-control.d.ts +19 -0
- package/dist/controls/slider-control.d.ts.map +1 -0
- package/dist/controls/slider-control.js +2 -0
- package/dist/controls/slider-control.js.map +1 -0
- package/dist/controls/spinner-control.cjs +2 -0
- package/dist/controls/spinner-control.cjs.map +1 -0
- package/dist/controls/spinner-control.d.ts +18 -0
- package/dist/controls/spinner-control.d.ts.map +1 -0
- package/dist/controls/spinner-control.js +2 -0
- package/dist/controls/spinner-control.js.map +1 -0
- package/dist/controls/swipe-control.cjs +2 -0
- package/dist/controls/swipe-control.cjs.map +1 -0
- package/dist/controls/swipe-control.d.ts +32 -0
- package/dist/controls/swipe-control.d.ts.map +1 -0
- package/dist/controls/swipe-control.js +2 -0
- package/dist/controls/swipe-control.js.map +1 -0
- package/dist/controls/text-field-control.cjs +2 -0
- package/dist/controls/text-field-control.cjs.map +1 -0
- package/dist/controls/text-field-control.d.ts +3 -0
- package/dist/controls/text-field-control.d.ts.map +1 -0
- package/dist/controls/text-field-control.js +2 -0
- package/dist/controls/text-field-control.js.map +1 -0
- package/dist/controls.cjs +1 -0
- package/dist/controls.js +1 -0
- package/dist/craftit.cjs +1 -1
- package/dist/craftit.cjs.map +1 -1
- package/dist/craftit.js +1 -1
- package/dist/craftit.js.map +1 -1
- package/dist/directives/classMap.cjs +2 -0
- package/dist/directives/classMap.cjs.map +1 -0
- package/dist/directives/classMap.d.ts +19 -0
- package/dist/directives/classMap.d.ts.map +1 -0
- package/dist/directives/classMap.js +2 -0
- package/dist/directives/classMap.js.map +1 -0
- package/dist/directives/each.cjs +1 -1
- package/dist/directives/each.cjs.map +1 -1
- package/dist/directives/each.d.ts +12 -49
- package/dist/directives/each.d.ts.map +1 -1
- package/dist/directives/each.js +1 -1
- package/dist/directives/each.js.map +1 -1
- package/dist/directives/guard.cjs +2 -0
- package/dist/directives/guard.cjs.map +1 -0
- package/dist/directives/guard.d.ts +10 -0
- package/dist/directives/guard.d.ts.map +1 -0
- package/dist/directives/guard.js +2 -0
- package/dist/directives/guard.js.map +1 -0
- package/dist/directives/live.cjs +2 -0
- package/dist/directives/live.cjs.map +1 -0
- package/dist/directives/live.d.ts +23 -0
- package/dist/directives/live.d.ts.map +1 -0
- package/dist/directives/live.js +2 -0
- package/dist/directives/live.js.map +1 -0
- package/dist/directives/raw.cjs +1 -1
- package/dist/directives/raw.cjs.map +1 -1
- package/dist/directives/raw.d.ts +4 -6
- package/dist/directives/raw.d.ts.map +1 -1
- package/dist/directives/raw.js +1 -1
- package/dist/directives/raw.js.map +1 -1
- package/dist/directives/resource.cjs +2 -0
- package/dist/directives/resource.cjs.map +1 -0
- package/dist/directives/resource.d.ts +32 -0
- package/dist/directives/resource.d.ts.map +1 -0
- package/dist/directives/resource.js +2 -0
- package/dist/directives/resource.js.map +1 -0
- package/dist/directives/styleMap.cjs +2 -0
- package/dist/directives/styleMap.cjs.map +1 -0
- package/dist/directives/styleMap.d.ts +11 -0
- package/dist/directives/styleMap.d.ts.map +1 -0
- package/dist/directives/styleMap.js +2 -0
- package/dist/directives/styleMap.js.map +1 -0
- package/dist/directives/when.cjs +1 -1
- package/dist/directives/when.cjs.map +1 -1
- package/dist/directives/when.d.ts +7 -14
- package/dist/directives/when.d.ts.map +1 -1
- package/dist/directives/when.js +1 -1
- package/dist/directives/when.js.map +1 -1
- package/dist/errors.cjs +2 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -0
- package/dist/form.cjs +2 -0
- package/dist/form.cjs.map +1 -0
- package/dist/form.d.ts +15 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +2 -0
- package/dist/form.js.map +1 -0
- package/dist/host.cjs +2 -0
- package/dist/host.cjs.map +1 -0
- package/dist/host.d.ts +78 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +2 -0
- package/dist/host.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +16 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/internal.cjs +2 -0
- package/dist/internal.cjs.map +1 -0
- package/dist/internal.d.ts +111 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +2 -0
- package/dist/internal.js.map +1 -0
- package/dist/observers/index.d.ts +5 -0
- package/dist/observers/index.d.ts.map +1 -0
- package/dist/observers/intersection-observe.cjs +2 -0
- package/dist/observers/intersection-observe.cjs.map +1 -0
- package/dist/observers/intersection-observe.d.ts +9 -0
- package/dist/observers/intersection-observe.d.ts.map +1 -0
- package/dist/observers/intersection-observe.js +2 -0
- package/dist/observers/intersection-observe.js.map +1 -0
- package/dist/observers/media-observe.cjs +2 -0
- package/dist/observers/media-observe.cjs.map +1 -0
- package/dist/observers/media-observe.d.ts +8 -0
- package/dist/observers/media-observe.d.ts.map +1 -0
- package/dist/observers/media-observe.js +2 -0
- package/dist/observers/media-observe.js.map +1 -0
- package/dist/observers/mutation-observe.cjs +2 -0
- package/dist/observers/mutation-observe.cjs.map +1 -0
- package/dist/observers/mutation-observe.d.ts +10 -0
- package/dist/observers/mutation-observe.d.ts.map +1 -0
- package/dist/observers/mutation-observe.js +2 -0
- package/dist/observers/mutation-observe.js.map +1 -0
- package/dist/observers/resize-observe.cjs +2 -0
- package/dist/observers/resize-observe.cjs.map +1 -0
- package/dist/observers/resize-observe.d.ts +11 -0
- package/dist/observers/resize-observe.d.ts.map +1 -0
- package/dist/observers/resize-observe.js +2 -0
- package/dist/observers/resize-observe.js.map +1 -0
- package/dist/observers.cjs +1 -0
- package/dist/observers.js +1 -0
- package/dist/props.cjs +2 -0
- package/dist/props.cjs.map +1 -0
- package/dist/props.d.ts +39 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +2 -0
- package/dist/props.js.map +1 -0
- package/dist/registration.cjs +2 -0
- package/dist/registration.cjs.map +1 -0
- package/dist/registration.d.ts +38 -0
- package/dist/registration.d.ts.map +1 -0
- package/dist/registration.js +2 -0
- package/dist/registration.js.map +1 -0
- package/dist/runtime.cjs +2 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.ts +33 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +2 -0
- package/dist/runtime.js.map +1 -0
- package/dist/template-bindings.cjs +2 -0
- package/dist/template-bindings.cjs.map +1 -0
- package/dist/template-bindings.d.ts +25 -0
- package/dist/template-bindings.d.ts.map +1 -0
- package/dist/template-bindings.js +2 -0
- package/dist/template-bindings.js.map +1 -0
- package/dist/template-compiler.cjs +2 -0
- package/dist/template-compiler.cjs.map +1 -0
- package/dist/template-compiler.d.ts +4 -0
- package/dist/template-compiler.d.ts.map +1 -0
- package/dist/template-compiler.js +2 -0
- package/dist/template-compiler.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/testing.cjs +2 -0
- package/dist/testing/testing.cjs.map +1 -0
- package/dist/{test/test.d.ts → testing/testing.d.ts} +18 -11
- package/dist/testing/testing.d.ts.map +1 -0
- package/dist/testing/testing.js +2 -0
- package/dist/testing/testing.js.map +1 -0
- package/dist/testing.cjs +1 -0
- package/dist/testing.js +1 -0
- package/package.json +21 -22
- package/dist/core/component.cjs +0 -2
- package/dist/core/component.cjs.map +0 -1
- package/dist/core/component.d.ts +0 -172
- package/dist/core/component.d.ts.map +0 -1
- package/dist/core/component.js +0 -2
- package/dist/core/component.js.map +0 -1
- package/dist/core/host.cjs +0 -2
- package/dist/core/host.cjs.map +0 -1
- package/dist/core/host.d.ts +0 -77
- package/dist/core/host.d.ts.map +0 -1
- package/dist/core/host.js +0 -2
- package/dist/core/host.js.map +0 -1
- package/dist/core/internal.cjs +0 -2
- package/dist/core/internal.cjs.map +0 -1
- package/dist/core/internal.d.ts +0 -107
- package/dist/core/internal.d.ts.map +0 -1
- package/dist/core/internal.js +0 -2
- package/dist/core/internal.js.map +0 -1
- package/dist/core/runtime-bindings.cjs +0 -2
- package/dist/core/runtime-bindings.cjs.map +0 -1
- package/dist/core/runtime-bindings.d.ts +0 -6
- package/dist/core/runtime-bindings.d.ts.map +0 -1
- package/dist/core/runtime-bindings.js +0 -2
- package/dist/core/runtime-bindings.js.map +0 -1
- package/dist/core/runtime-lifecycle.cjs +0 -2
- package/dist/core/runtime-lifecycle.cjs.map +0 -1
- package/dist/core/runtime-lifecycle.d.ts +0 -116
- package/dist/core/runtime-lifecycle.d.ts.map +0 -1
- package/dist/core/runtime-lifecycle.js +0 -2
- package/dist/core/runtime-lifecycle.js.map +0 -1
- package/dist/core/runtime.cjs +0 -1
- package/dist/core/runtime.d.ts +0 -3
- package/dist/core/runtime.d.ts.map +0 -1
- package/dist/core/runtime.js +0 -1
- package/dist/core/template-bindings.cjs +0 -2
- package/dist/core/template-bindings.cjs.map +0 -1
- package/dist/core/template-bindings.d.ts +0 -59
- package/dist/core/template-bindings.d.ts.map +0 -1
- package/dist/core/template-bindings.js +0 -2
- package/dist/core/template-bindings.js.map +0 -1
- package/dist/core/template-compiler.cjs +0 -2
- package/dist/core/template-compiler.cjs.map +0 -1
- package/dist/core/template-compiler.d.ts +0 -25
- package/dist/core/template-compiler.d.ts.map +0 -1
- package/dist/core/template-compiler.js +0 -2
- package/dist/core/template-compiler.js.map +0 -1
- package/dist/core/template-dom.cjs +0 -2
- package/dist/core/template-dom.cjs.map +0 -1
- package/dist/core/template-dom.d.ts +0 -13
- package/dist/core/template-dom.d.ts.map +0 -1
- package/dist/core/template-dom.js +0 -2
- package/dist/core/template-dom.js.map +0 -1
- package/dist/core/template-html.cjs +0 -2
- package/dist/core/template-html.cjs.map +0 -1
- package/dist/core/template-html.d.ts +0 -26
- package/dist/core/template-html.d.ts.map +0 -1
- package/dist/core/template-html.js +0 -2
- package/dist/core/template-html.js.map +0 -1
- package/dist/core/template.cjs +0 -2
- package/dist/core/template.cjs.map +0 -1
- package/dist/core/template.d.ts +0 -11
- package/dist/core/template.d.ts.map +0 -1
- package/dist/core/template.js +0 -2
- package/dist/core/template.js.map +0 -1
- package/dist/core/utilities.cjs +0 -2
- package/dist/core/utilities.cjs.map +0 -1
- package/dist/core/utilities.d.ts +0 -68
- package/dist/core/utilities.d.ts.map +0 -1
- package/dist/core/utilities.js +0 -2
- package/dist/core/utilities.js.map +0 -1
- package/dist/directives/attr.cjs +0 -2
- package/dist/directives/attr.cjs.map +0 -1
- package/dist/directives/attr.d.ts +0 -14
- package/dist/directives/attr.d.ts.map +0 -1
- package/dist/directives/attr.js +0 -2
- package/dist/directives/attr.js.map +0 -1
- package/dist/directives/bind.cjs +0 -2
- package/dist/directives/bind.cjs.map +0 -1
- package/dist/directives/bind.d.ts +0 -30
- package/dist/directives/bind.d.ts.map +0 -1
- package/dist/directives/bind.js +0 -2
- package/dist/directives/bind.js.map +0 -1
- package/dist/directives/choose.cjs +0 -2
- package/dist/directives/choose.cjs.map +0 -1
- package/dist/directives/choose.d.ts +0 -34
- package/dist/directives/choose.d.ts.map +0 -1
- package/dist/directives/choose.js +0 -2
- package/dist/directives/choose.js.map +0 -1
- package/dist/directives/classes.cjs +0 -2
- package/dist/directives/classes.cjs.map +0 -1
- package/dist/directives/classes.d.ts +0 -20
- package/dist/directives/classes.d.ts.map +0 -1
- package/dist/directives/classes.js +0 -2
- package/dist/directives/classes.js.map +0 -1
- package/dist/directives/index.cjs +0 -1
- package/dist/directives/index.d.ts +0 -14
- package/dist/directives/index.d.ts.map +0 -1
- package/dist/directives/index.js +0 -1
- package/dist/directives/match.cjs +0 -2
- package/dist/directives/match.cjs.map +0 -1
- package/dist/directives/match.d.ts +0 -31
- package/dist/directives/match.d.ts.map +0 -1
- package/dist/directives/match.js +0 -2
- package/dist/directives/match.js.map +0 -1
- package/dist/directives/memo.cjs +0 -2
- package/dist/directives/memo.cjs.map +0 -1
- package/dist/directives/memo.d.ts +0 -23
- package/dist/directives/memo.d.ts.map +0 -1
- package/dist/directives/memo.js +0 -2
- package/dist/directives/memo.js.map +0 -1
- package/dist/directives/on.cjs +0 -2
- package/dist/directives/on.cjs.map +0 -1
- package/dist/directives/on.d.ts +0 -25
- package/dist/directives/on.d.ts.map +0 -1
- package/dist/directives/on.js +0 -2
- package/dist/directives/on.js.map +0 -1
- package/dist/directives/spread.cjs +0 -2
- package/dist/directives/spread.cjs.map +0 -1
- package/dist/directives/spread.d.ts +0 -14
- package/dist/directives/spread.d.ts.map +0 -1
- package/dist/directives/spread.js +0 -2
- package/dist/directives/spread.js.map +0 -1
- package/dist/directives/style.cjs +0 -2
- package/dist/directives/style.cjs.map +0 -1
- package/dist/directives/style.d.ts +0 -22
- package/dist/directives/style.d.ts.map +0 -1
- package/dist/directives/style.js +0 -2
- package/dist/directives/style.js.map +0 -1
- package/dist/directives/until.cjs +0 -2
- package/dist/directives/until.cjs.map +0 -1
- package/dist/directives/until.d.ts +0 -26
- package/dist/directives/until.d.ts.map +0 -1
- package/dist/directives/until.js +0 -2
- package/dist/directives/until.js.map +0 -1
- package/dist/labs/a11y.cjs +0 -2
- package/dist/labs/a11y.cjs.map +0 -1
- package/dist/labs/a11y.d.ts +0 -61
- package/dist/labs/a11y.d.ts.map +0 -1
- package/dist/labs/a11y.js +0 -2
- package/dist/labs/a11y.js.map +0 -1
- package/dist/labs/index.d.ts +0 -8
- package/dist/labs/index.d.ts.map +0 -1
- package/dist/labs/list.cjs +0 -2
- package/dist/labs/list.cjs.map +0 -1
- package/dist/labs/list.d.ts +0 -26
- package/dist/labs/list.d.ts.map +0 -1
- package/dist/labs/list.js +0 -2
- package/dist/labs/list.js.map +0 -1
- package/dist/labs/observers.cjs +0 -2
- package/dist/labs/observers.cjs.map +0 -1
- package/dist/labs/observers.d.ts +0 -42
- package/dist/labs/observers.d.ts.map +0 -1
- package/dist/labs/observers.js +0 -2
- package/dist/labs/observers.js.map +0 -1
- package/dist/labs/overlay.cjs +0 -2
- package/dist/labs/overlay.cjs.map +0 -1
- package/dist/labs/overlay.d.ts.map +0 -1
- package/dist/labs/overlay.js +0 -2
- package/dist/labs/overlay.js.map +0 -1
- package/dist/labs/selectable.cjs +0 -2
- package/dist/labs/selectable.cjs.map +0 -1
- package/dist/labs/selectable.d.ts +0 -70
- package/dist/labs/selectable.d.ts.map +0 -1
- package/dist/labs/selectable.js +0 -2
- package/dist/labs/selectable.js.map +0 -1
- package/dist/labs/selection.cjs +0 -2
- package/dist/labs/selection.cjs.map +0 -1
- package/dist/labs/selection.d.ts +0 -68
- package/dist/labs/selection.d.ts.map +0 -1
- package/dist/labs/selection.js +0 -2
- package/dist/labs/selection.js.map +0 -1
- package/dist/labs.cjs +0 -1
- package/dist/labs.js +0 -1
- package/dist/test/index.d.ts +0 -2
- package/dist/test/index.d.ts.map +0 -1
- package/dist/test/test.cjs +0 -2
- package/dist/test/test.cjs.map +0 -1
- package/dist/test/test.d.ts.map +0 -1
- package/dist/test/test.js +0 -2
- package/dist/test/test.js.map +0 -1
- package/dist/test.cjs +0 -1
- package/dist/test.js +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReadonlySignal } from '@vielzeug/stateit';
|
|
2
|
+
type StyleInput = string | number | null | undefined | false | (() => string | number | null | undefined | false) | ReadonlySignal<string | number | null | undefined | false>;
|
|
3
|
+
/**
|
|
4
|
+
* Builds a reactive inline style string from a style object.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* html`<div :style=${styleMap({ backgroundColor: color, width: () => `${size.value}px` })}></div>`
|
|
8
|
+
*/
|
|
9
|
+
export declare const styleMap: (record: Record<string, StyleInput>) => ReadonlySignal<string>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=styleMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styleMap.d.ts","sourceRoot":"","sources":["../../src/directives/styleMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE5E,KAAK,UAAU,GACX,MAAM,GACN,MAAM,GACN,IAAI,GACJ,SAAS,GACT,KAAK,GACL,CAAC,MAAM,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,GAClD,cAAc,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,CAAC;AAY/D;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,KAAG,cAAc,CAAC,MAAM,CAclF,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{computed as e,isSignal as t}from"@vielzeug/stateit";var n=e=>{let n=typeof e==`function`?e():t(e)?e.value:e;return n==null||n===!1?``:String(n)},r=e=>e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),i=t=>e(()=>{let e=[];for(let[i,a]of Object.entries(t)){let t=n(a);t&&e.push(`${r(i)}:${t}`)}return e.join(`;`)});export{i as styleMap};
|
|
2
|
+
//# sourceMappingURL=styleMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styleMap.js","names":[],"sources":["../../src/directives/styleMap.ts"],"sourcesContent":["import { computed, isSignal, type ReadonlySignal } from '@vielzeug/stateit';\n\ntype StyleInput =\n | string\n | number\n | null\n | undefined\n | false\n | (() => string | number | null | undefined | false)\n | ReadonlySignal<string | number | null | undefined | false>;\n\nconst toStyleValue = (value: StyleInput): string => {\n const resolved = typeof value === 'function' ? value() : isSignal(value) ? value.value : value;\n\n if (resolved == null || resolved === false) return '';\n\n return String(resolved);\n};\n\nconst toKebabCase = (name: string): string => name.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);\n\n/**\n * Builds a reactive inline style string from a style object.\n *\n * @example\n * html`<div :style=${styleMap({ backgroundColor: color, width: () => `${size.value}px` })}></div>`\n */\nexport const styleMap = (record: Record<string, StyleInput>): ReadonlySignal<string> => {\n return computed(() => {\n const declarations: string[] = [];\n\n for (const [name, input] of Object.entries(record)) {\n const value = toStyleValue(input);\n\n if (!value) continue;\n\n declarations.push(`${toKebabCase(name)}:${value}`);\n }\n\n return declarations.join(';');\n });\n};\n"],"mappings":"2DAWA,IAAM,EAAgB,GAA8B,CAClD,IAAM,EAAW,OAAO,GAAU,WAAa,EAAM,EAAI,EAAS,CAAK,EAAI,EAAM,MAAQ,EAIzF,OAFI,GAAY,MAAQ,IAAa,GAAc,GAE5C,OAAO,CAAQ,CACxB,EAEM,EAAe,GAAyB,EAAK,QAAQ,SAAW,GAAS,IAAI,EAAK,YAAY,GAAG,EAQ1F,EAAY,GAChB,MAAe,CACpB,IAAM,EAAyB,CAAC,EAEhC,IAAK,GAAM,CAAC,EAAM,KAAU,OAAO,QAAQ,CAAM,EAAG,CAClD,IAAM,EAAQ,EAAa,CAAK,EAE3B,GAEL,EAAa,KAAK,GAAG,EAAY,CAAI,EAAE,GAAG,GAAO,CACnD,CAEA,OAAO,EAAa,KAAK,GAAG,CAC9B,CAAC"}
|
package/dist/directives/when.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let e=require(`@vielzeug/stateit`);
|
|
1
|
+
let e=require(`@vielzeug/stateit`);var t=t=>typeof t==`function`?t():(0,e.isSignal)(t)?t.value:t;function n(n,r,i){return(0,e.computed)(()=>t(n)?r():i?i():``)}exports.when=n;
|
|
2
2
|
//# sourceMappingURL=when.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when.cjs","names":[],"sources":["../../src/directives/when.ts"],"sourcesContent":["import { isSignal, type ReadonlySignal
|
|
1
|
+
{"version":3,"file":"when.cjs","names":[],"sources":["../../src/directives/when.ts"],"sourcesContent":["import { computed, isSignal, type ReadonlySignal } from '@vielzeug/stateit';\n\nimport type { HTMLResult } from '../internal';\n\ntype MaybeReactive<T> = T | (() => T) | ReadonlySignal<T>;\n\ntype WhenRenderable = string | HTMLResult;\n\nconst resolve = <T>(value: MaybeReactive<T>): T => {\n if (typeof value === 'function') return (value as () => T)();\n\n if (isSignal(value)) return value.value;\n\n return value;\n};\n\n/**\n * Conditionally renders one of two branches.\n */\nexport function when(\n condition: MaybeReactive<boolean>,\n truthy: () => WhenRenderable,\n falsy?: () => WhenRenderable,\n): ReadonlySignal<WhenRenderable> {\n return computed(() => {\n if (resolve(condition)) return truthy();\n\n return falsy ? falsy() : '';\n });\n} // Note: when returns HtmlResult (not DirectiveResult)\n"],"mappings":"mCAQA,IAAM,EAAc,GACd,OAAO,GAAU,WAAoB,EAAkB,GAE3D,EAAA,EAAA,UAAa,CAAK,EAAU,EAAM,MAE3B,EAMT,SAAgB,EACd,EACA,EACA,EACgC,CAChC,OAAA,EAAA,EAAA,cACM,EAAQ,CAAS,EAAU,EAAO,EAE/B,EAAQ,EAAM,EAAI,EAC1B,CACH"}
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import { type ReadonlySignal
|
|
2
|
-
import type {
|
|
1
|
+
import { type ReadonlySignal } from '@vielzeug/stateit';
|
|
2
|
+
import type { HTMLResult } from '../internal';
|
|
3
|
+
type MaybeReactive<T> = T | (() => T) | ReadonlySignal<T>;
|
|
4
|
+
type WhenRenderable = string | HTMLResult;
|
|
3
5
|
/**
|
|
4
|
-
* Conditionally renders one of two
|
|
5
|
-
*
|
|
6
|
-
* - **Signal or getter** — returns a reactive function the engine re-runs automatically.
|
|
7
|
-
* - **Static value** — evaluated once at call time, returns the result directly.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* import { when } from '@vielzeug/craftit/directives';
|
|
11
|
-
*
|
|
12
|
-
* html`${when(isLoggedIn, () => html`<user-panel>`, () => html`<login-form>`)}`
|
|
13
|
-
* html`${when(() => count.value > 0, () => html`<span>${count}</span>`)}`
|
|
6
|
+
* Conditionally renders one of two branches.
|
|
14
7
|
*/
|
|
15
|
-
export declare function when
|
|
16
|
-
export
|
|
8
|
+
export declare function when(condition: MaybeReactive<boolean>, truthy: () => WhenRenderable, falsy?: () => WhenRenderable): ReadonlySignal<WhenRenderable>;
|
|
9
|
+
export {};
|
|
17
10
|
//# sourceMappingURL=when.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when.d.ts","sourceRoot":"","sources":["../../src/directives/when.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"when.d.ts","sourceRoot":"","sources":["../../src/directives/when.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;AAE1D,KAAK,cAAc,GAAG,MAAM,GAAG,UAAU,CAAC;AAU1C;;GAEG;AACH,wBAAgB,IAAI,CAClB,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,EACjC,MAAM,EAAE,MAAM,cAAc,EAC5B,KAAK,CAAC,EAAE,MAAM,cAAc,GAC3B,cAAc,CAAC,cAAc,CAAC,CAMhC"}
|
package/dist/directives/when.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{isSignal as
|
|
1
|
+
import{computed as e,isSignal as t}from"@vielzeug/stateit";var n=e=>typeof e==`function`?e():t(e)?e.value:e;function r(t,r,i){return e(()=>n(t)?r():i?i():``)}export{r as when};
|
|
2
2
|
//# sourceMappingURL=when.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when.js","names":[],"sources":["../../src/directives/when.ts"],"sourcesContent":["import { isSignal, type ReadonlySignal
|
|
1
|
+
{"version":3,"file":"when.js","names":[],"sources":["../../src/directives/when.ts"],"sourcesContent":["import { computed, isSignal, type ReadonlySignal } from '@vielzeug/stateit';\n\nimport type { HTMLResult } from '../internal';\n\ntype MaybeReactive<T> = T | (() => T) | ReadonlySignal<T>;\n\ntype WhenRenderable = string | HTMLResult;\n\nconst resolve = <T>(value: MaybeReactive<T>): T => {\n if (typeof value === 'function') return (value as () => T)();\n\n if (isSignal(value)) return value.value;\n\n return value;\n};\n\n/**\n * Conditionally renders one of two branches.\n */\nexport function when(\n condition: MaybeReactive<boolean>,\n truthy: () => WhenRenderable,\n falsy?: () => WhenRenderable,\n): ReadonlySignal<WhenRenderable> {\n return computed(() => {\n if (resolve(condition)) return truthy();\n\n return falsy ? falsy() : '';\n });\n} // Note: when returns HtmlResult (not DirectiveResult)\n"],"mappings":"2DAQA,IAAM,EAAc,GACd,OAAO,GAAU,WAAoB,EAAkB,EAEvD,EAAS,CAAK,EAAU,EAAM,MAE3B,EAMT,SAAgB,EACd,EACA,EACA,EACgC,CAChC,OAAO,MACD,EAAQ,CAAS,EAAU,EAAO,EAE/B,EAAQ,EAAM,EAAI,EAC1B,CACH"}
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e={cleanupFailed:`One or more cleanup callbacks failed during dispose`,defineDuplicate:e=>`define('${e}') was called more than once`,defineFieldRequiresFormAssociated:e=>`defineField() requires define('${e}', { formAssociated: true })`,defineRequiresTag:`define() requires a non-empty tag name`,eachDuplicateKey:(e,t)=>`each() received duplicate key "${e}" at index ${t}`,injectStrictFailed:(e,t)=>`injectStrict() could not resolve key "${e}" in <${t}>`,lifecycleOutsideSetup:`Lifecycle hooks must be called synchronously during component setup`,styleReplaceFailed:`Style sheet replace failed`,unhandledComponentError:e=>`<${e}> threw an unhandled error during setup`};exports.CRAFTIT_ERRORS=e;
|
|
2
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export const CRAFTIT_ERRORS = {\n cleanupFailed: 'One or more cleanup callbacks failed during dispose',\n defineDuplicate: (tag: string): string => `define('${tag}') was called more than once`,\n defineFieldRequiresFormAssociated: (tag: string): string =>\n `defineField() requires define('${tag}', { formAssociated: true })`,\n defineRequiresTag: 'define() requires a non-empty tag name',\n eachDuplicateKey: (key: string, index: number): string => `each() received duplicate key \"${key}\" at index ${index}`,\n injectStrictFailed: (key: string, tag: string): string => `injectStrict() could not resolve key \"${key}\" in <${tag}>`,\n lifecycleOutsideSetup: 'Lifecycle hooks must be called synchronously during component setup',\n styleReplaceFailed: 'Style sheet replace failed',\n unhandledComponentError: (tag: string): string => `<${tag}> threw an unhandled error during setup`,\n} as const;\n"],"mappings":"AAAA,IAAa,EAAiB,CAC5B,cAAe,sDACf,gBAAkB,GAAwB,WAAW,EAAI,8BACzD,kCAAoC,GAClC,kCAAkC,EAAI,8BACxC,kBAAmB,yCACnB,kBAAmB,EAAa,IAA0B,kCAAkC,EAAI,aAAa,IAC7G,oBAAqB,EAAa,IAAwB,yCAAyC,EAAI,QAAQ,EAAI,GACnH,sBAAuB,sEACvB,mBAAoB,6BACpB,wBAA0B,GAAwB,IAAI,EAAI,wCAC5D"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const CRAFTIT_ERRORS: {
|
|
2
|
+
readonly cleanupFailed: "One or more cleanup callbacks failed during dispose";
|
|
3
|
+
readonly defineDuplicate: (tag: string) => string;
|
|
4
|
+
readonly defineFieldRequiresFormAssociated: (tag: string) => string;
|
|
5
|
+
readonly defineRequiresTag: "define() requires a non-empty tag name";
|
|
6
|
+
readonly eachDuplicateKey: (key: string, index: number) => string;
|
|
7
|
+
readonly injectStrictFailed: (key: string, tag: string) => string;
|
|
8
|
+
readonly lifecycleOutsideSetup: "Lifecycle hooks must be called synchronously during component setup";
|
|
9
|
+
readonly styleReplaceFailed: "Style sheet replace failed";
|
|
10
|
+
readonly unhandledComponentError: (tag: string) => string;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc;;oCAEF,MAAM,KAAG,MAAM;sDACG,MAAM,KAAG,MAAM;;qCAGhC,MAAM,SAAS,MAAM,KAAG,MAAM;uCAC5B,MAAM,OAAO,MAAM,KAAG,MAAM;;;4CAGvB,MAAM,KAAG,MAAM;CACtC,CAAC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e={cleanupFailed:`One or more cleanup callbacks failed during dispose`,defineDuplicate:e=>`define('${e}') was called more than once`,defineFieldRequiresFormAssociated:e=>`defineField() requires define('${e}', { formAssociated: true })`,defineRequiresTag:`define() requires a non-empty tag name`,eachDuplicateKey:(e,t)=>`each() received duplicate key "${e}" at index ${t}`,injectStrictFailed:(e,t)=>`injectStrict() could not resolve key "${e}" in <${t}>`,lifecycleOutsideSetup:`Lifecycle hooks must be called synchronously during component setup`,styleReplaceFailed:`Style sheet replace failed`,unhandledComponentError:e=>`<${e}> threw an unhandled error during setup`};export{e as CRAFTIT_ERRORS};
|
|
2
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export const CRAFTIT_ERRORS = {\n cleanupFailed: 'One or more cleanup callbacks failed during dispose',\n defineDuplicate: (tag: string): string => `define('${tag}') was called more than once`,\n defineFieldRequiresFormAssociated: (tag: string): string =>\n `defineField() requires define('${tag}', { formAssociated: true })`,\n defineRequiresTag: 'define() requires a non-empty tag name',\n eachDuplicateKey: (key: string, index: number): string => `each() received duplicate key \"${key}\" at index ${index}`,\n injectStrictFailed: (key: string, tag: string): string => `injectStrict() could not resolve key \"${key}\" in <${tag}>`,\n lifecycleOutsideSetup: 'Lifecycle hooks must be called synchronously during component setup',\n styleReplaceFailed: 'Style sheet replace failed',\n unhandledComponentError: (tag: string): string => `<${tag}> threw an unhandled error during setup`,\n} as const;\n"],"mappings":"AAAA,IAAa,EAAiB,CAC5B,cAAe,sDACf,gBAAkB,GAAwB,WAAW,EAAI,8BACzD,kCAAoC,GAClC,kCAAkC,EAAI,8BACxC,kBAAmB,yCACnB,kBAAmB,EAAa,IAA0B,kCAAkC,EAAI,aAAa,IAC7G,oBAAqB,EAAa,IAAwB,yCAAyC,EAAI,QAAQ,EAAI,GACnH,sBAAuB,sEACvB,mBAAoB,6BACpB,wBAA0B,GAAwB,IAAI,EAAI,wCAC5D"}
|
package/dist/form.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`./errors.cjs`),t=require(`./runtime.cjs`);require(`@vielzeug/stateit`);var n=new WeakMap,r=r=>{let i=t.currentElementOrThrow();if(!i.constructor.formAssociated)throw Error(e.CRAFTIT_ERRORS.defineFieldRequiresFormAssociated(i.localName));let a=n.get(i)??i.attachInternals();n.set(i,a);let o=r.toFormValue??(e=>e==null?null:e instanceof File||e instanceof FormData?e:String(e));t.effect(()=>{a.setFormValue(o(r.value.value))});let s=r.disabled;if(s){let e=a.states;t.effect(()=>{s.value?e.add(`disabled`):e.delete(`disabled`)})}return{checkValidity:()=>a.checkValidity(),internals:a,reportValidity:()=>a.reportValidity(),setCustomValidity:e=>e?a.setValidity({customError:!0},e):a.setValidity({}),setValidity:a.setValidity.bind(a)}};exports.defineField=r;
|
|
2
|
+
//# sourceMappingURL=form.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.cjs","names":[],"sources":["../src/form.ts"],"sourcesContent":["import { type ReadonlySignal, type Signal } from '@vielzeug/stateit';\n\nimport { CRAFTIT_ERRORS } from './errors';\nimport { currentElementOrThrow, effect } from './runtime';\n\n/** @internal */\nconst internalsRegistry = new WeakMap<HTMLElement, ElementInternals>();\n\nexport type FormFieldOptions<T = unknown> = {\n disabled?: ReadonlySignal<boolean>;\n toFormValue?: (value: T) => File | FormData | string | null;\n value: Signal<T> | ReadonlySignal<T>;\n};\n\nexport type FormFieldHandle = {\n checkValidity: () => boolean;\n readonly internals: ElementInternals;\n reportValidity: () => boolean;\n setCustomValidity: (message: string) => void;\n setValidity: ElementInternals['setValidity'];\n};\n\nexport const defineField = <T = unknown>(options: FormFieldOptions<T>): FormFieldHandle => {\n const host = currentElementOrThrow();\n const ctor = host.constructor as typeof HTMLElement & { formAssociated?: boolean };\n\n if (!ctor.formAssociated) {\n throw new Error(CRAFTIT_ERRORS.defineFieldRequiresFormAssociated(host.localName));\n }\n\n const internals = internalsRegistry.get(host) ?? host.attachInternals();\n\n internalsRegistry.set(host, internals);\n\n const toFormValue =\n options.toFormValue ??\n ((v: T): File | FormData | string | null => {\n if (v == null) return null;\n\n if (v instanceof File || v instanceof FormData) return v;\n\n return String(v);\n });\n\n effect(() => {\n internals.setFormValue(toFormValue(options.value.value));\n });\n\n const disabled = options.disabled;\n\n if (disabled) {\n const states = internals.states as CustomStateSet;\n\n effect(() => {\n if (disabled.value) states.add('disabled');\n else states.delete('disabled');\n });\n }\n\n const checkValidity = () => internals.checkValidity();\n const reportValidity = () => internals.reportValidity();\n const setCustomValidity = (message: string) =>\n message ? internals.setValidity({ customError: true }, message) : internals.setValidity({});\n\n return {\n checkValidity,\n internals,\n reportValidity,\n setCustomValidity,\n setValidity: internals.setValidity.bind(internals),\n };\n};\n"],"mappings":"wFAMA,IAAM,EAAoB,IAAI,QAgBjB,EAA4B,GAAkD,CACzF,IAAM,EAAO,EAAA,sBAAsB,EAGnC,GAAI,CAFS,EAAK,YAER,eACR,MAAU,MAAM,EAAA,eAAe,kCAAkC,EAAK,SAAS,CAAC,EAGlF,IAAM,EAAY,EAAkB,IAAI,CAAI,GAAK,EAAK,gBAAgB,EAEtE,EAAkB,IAAI,EAAM,CAAS,EAErC,IAAM,EACJ,EAAQ,cACN,GACI,GAAK,KAAa,KAElB,aAAa,MAAQ,aAAa,SAAiB,EAEhD,OAAO,CAAC,GAGnB,EAAA,WAAa,CACX,EAAU,aAAa,EAAY,EAAQ,MAAM,KAAK,CAAC,CACzD,CAAC,EAED,IAAM,EAAW,EAAQ,SAEzB,GAAI,EAAU,CACZ,IAAM,EAAS,EAAU,OAEzB,EAAA,WAAa,CACP,EAAS,MAAO,EAAO,IAAI,UAAU,EACpC,EAAO,OAAO,UAAU,CAC/B,CAAC,CACH,CAOA,MAAO,CACL,kBAN0B,EAAU,cAAc,EAOlD,YACA,mBAP2B,EAAU,eAAe,EAQpD,kBAPyB,GACzB,EAAU,EAAU,YAAY,CAAE,YAAa,EAAK,EAAG,CAAO,EAAI,EAAU,YAAY,CAAC,CAAC,EAO1F,YAAa,EAAU,YAAY,KAAK,CAAS,CACnD,CACF"}
|
package/dist/form.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ReadonlySignal, type Signal } from '@vielzeug/stateit';
|
|
2
|
+
export type FormFieldOptions<T = unknown> = {
|
|
3
|
+
disabled?: ReadonlySignal<boolean>;
|
|
4
|
+
toFormValue?: (value: T) => File | FormData | string | null;
|
|
5
|
+
value: Signal<T> | ReadonlySignal<T>;
|
|
6
|
+
};
|
|
7
|
+
export type FormFieldHandle = {
|
|
8
|
+
checkValidity: () => boolean;
|
|
9
|
+
readonly internals: ElementInternals;
|
|
10
|
+
reportValidity: () => boolean;
|
|
11
|
+
setCustomValidity: (message: string) => void;
|
|
12
|
+
setValidity: ElementInternals['setValidity'];
|
|
13
|
+
};
|
|
14
|
+
export declare const defineField: <T = unknown>(options: FormFieldOptions<T>) => FormFieldHandle;
|
|
15
|
+
//# sourceMappingURL=form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAQrE,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,OAAO,IAAI;IAC1C,QAAQ,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IACnC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5D,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,EAAE,MAAM,OAAO,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;IACrC,cAAc,EAAE,MAAM,OAAO,CAAC;IAC9B,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,WAAW,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC9C,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,CAAC,GAAG,OAAO,EAAE,SAAS,gBAAgB,CAAC,CAAC,CAAC,KAAG,eAiDvE,CAAC"}
|
package/dist/form.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{CRAFTIT_ERRORS as e}from"./errors.js";import{currentElementOrThrow as t,effect as n}from"./runtime.js";import"@vielzeug/stateit";var r=new WeakMap,i=i=>{let a=t();if(!a.constructor.formAssociated)throw Error(e.defineFieldRequiresFormAssociated(a.localName));let o=r.get(a)??a.attachInternals();r.set(a,o);let s=i.toFormValue??(e=>e==null?null:e instanceof File||e instanceof FormData?e:String(e));n(()=>{o.setFormValue(s(i.value.value))});let c=i.disabled;if(c){let e=o.states;n(()=>{c.value?e.add(`disabled`):e.delete(`disabled`)})}return{checkValidity:()=>o.checkValidity(),internals:o,reportValidity:()=>o.reportValidity(),setCustomValidity:e=>e?o.setValidity({customError:!0},e):o.setValidity({}),setValidity:o.setValidity.bind(o)}};export{i as defineField};
|
|
2
|
+
//# sourceMappingURL=form.js.map
|
package/dist/form.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.js","names":[],"sources":["../src/form.ts"],"sourcesContent":["import { type ReadonlySignal, type Signal } from '@vielzeug/stateit';\n\nimport { CRAFTIT_ERRORS } from './errors';\nimport { currentElementOrThrow, effect } from './runtime';\n\n/** @internal */\nconst internalsRegistry = new WeakMap<HTMLElement, ElementInternals>();\n\nexport type FormFieldOptions<T = unknown> = {\n disabled?: ReadonlySignal<boolean>;\n toFormValue?: (value: T) => File | FormData | string | null;\n value: Signal<T> | ReadonlySignal<T>;\n};\n\nexport type FormFieldHandle = {\n checkValidity: () => boolean;\n readonly internals: ElementInternals;\n reportValidity: () => boolean;\n setCustomValidity: (message: string) => void;\n setValidity: ElementInternals['setValidity'];\n};\n\nexport const defineField = <T = unknown>(options: FormFieldOptions<T>): FormFieldHandle => {\n const host = currentElementOrThrow();\n const ctor = host.constructor as typeof HTMLElement & { formAssociated?: boolean };\n\n if (!ctor.formAssociated) {\n throw new Error(CRAFTIT_ERRORS.defineFieldRequiresFormAssociated(host.localName));\n }\n\n const internals = internalsRegistry.get(host) ?? host.attachInternals();\n\n internalsRegistry.set(host, internals);\n\n const toFormValue =\n options.toFormValue ??\n ((v: T): File | FormData | string | null => {\n if (v == null) return null;\n\n if (v instanceof File || v instanceof FormData) return v;\n\n return String(v);\n });\n\n effect(() => {\n internals.setFormValue(toFormValue(options.value.value));\n });\n\n const disabled = options.disabled;\n\n if (disabled) {\n const states = internals.states as CustomStateSet;\n\n effect(() => {\n if (disabled.value) states.add('disabled');\n else states.delete('disabled');\n });\n }\n\n const checkValidity = () => internals.checkValidity();\n const reportValidity = () => internals.reportValidity();\n const setCustomValidity = (message: string) =>\n message ? internals.setValidity({ customError: true }, message) : internals.setValidity({});\n\n return {\n checkValidity,\n internals,\n reportValidity,\n setCustomValidity,\n setValidity: internals.setValidity.bind(internals),\n };\n};\n"],"mappings":"wIAMA,IAAM,EAAoB,IAAI,QAgBjB,EAA4B,GAAkD,CACzF,IAAM,EAAO,EAAsB,EAGnC,GAAI,CAFS,EAAK,YAER,eACR,MAAU,MAAM,EAAe,kCAAkC,EAAK,SAAS,CAAC,EAGlF,IAAM,EAAY,EAAkB,IAAI,CAAI,GAAK,EAAK,gBAAgB,EAEtE,EAAkB,IAAI,EAAM,CAAS,EAErC,IAAM,EACJ,EAAQ,cACN,GACI,GAAK,KAAa,KAElB,aAAa,MAAQ,aAAa,SAAiB,EAEhD,OAAO,CAAC,GAGnB,MAAa,CACX,EAAU,aAAa,EAAY,EAAQ,MAAM,KAAK,CAAC,CACzD,CAAC,EAED,IAAM,EAAW,EAAQ,SAEzB,GAAI,EAAU,CACZ,IAAM,EAAS,EAAU,OAEzB,MAAa,CACP,EAAS,MAAO,EAAO,IAAI,UAAU,EACpC,EAAO,OAAO,UAAU,CAC/B,CAAC,CACH,CAOA,MAAO,CACL,kBAN0B,EAAU,cAAc,EAOlD,YACA,mBAP2B,EAAU,eAAe,EAQpD,kBAPyB,GACzB,EAAU,EAAU,YAAY,CAAE,YAAa,EAAK,EAAG,CAAO,EAAI,EAAU,YAAY,CAAC,CAAC,EAO1F,YAAa,EAAU,YAAY,KAAK,CAAS,CACnD,CACF"}
|
package/dist/host.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`./errors.cjs`),t=require(`./runtime.cjs`),n=require(`./internal.cjs`);let r=require(`@vielzeug/stateit`);var i=new WeakMap,a=(e,n)=>{let r=t.currentElementOrThrow();i.has(r)||i.set(r,new Map),i.get(r).set(e,n)};function o(e,...n){let r=t.currentElementOrThrow();for(;r;){if(r instanceof HTMLElement){let t=i.get(r)?.get(e);if(t!==void 0)return t}let t=r.getRootNode();r=r.parentElement??(t instanceof ShadowRoot?t.host:null)}return n.length>0?n[0]:void 0}var s=n=>{let r=o(n);if(r!==void 0)return r;let i=t.currentElementOrThrow();throw Error(e.CRAFTIT_ERRORS.injectStrictFailed(String(n),i.localName))};function c(e){return Symbol(e)}var l=e=>e===`role`||e.startsWith(`aria-`)?e:e.startsWith(`aria`)?`aria-${e.slice(4).toLowerCase()}`:`aria-${e}`,u=e=>e===`role`||e.startsWith(`aria-`)?e:e.startsWith(`aria`)?`aria-${e.slice(4).toLowerCase()}`:e,d=(e,t,n)=>{if(n==null||n===!1){e.removeAttribute(t);return}e.setAttribute(t,n===!0?`true`:String(n))},f=(e,n,i={})=>{let{autoCleanup:a=!0}=i,o=[];for(let[t,i]of Object.entries(n)){let n=l(t);if(typeof i==`function`){let t=i;o.push((0,r.effect)(()=>{d(e,n,t())}));continue}d(e,n,i)}let s=()=>{for(;o.length>0;)o.pop()?.()};return a&&t.tryRegisterCleanup(s),s},p=`default`,m=e=>e||p,h=()=>{let e=t.currentElementOrThrow(),n=new Map,i=new Map,a=new Map,o=e=>{let t=n.get(e);return t||(t={elements:(0,r.signal)([]),presence:(0,r.signal)(!1)},n.set(e,t)),t},s=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0},c=e=>{let t=m(e),n=i.get(t),r=[];if(n)for(let e of n)r.push(...e.assignedElements({flatten:!0}));let a=o(t);s(a.elements.value,r)||(a.elements.value=r);let c=r.length>0;a.presence.value!==c&&(a.presence.value=c)},l=e=>{if(a.has(e))return;let t=m(e.getAttribute(`name`)),n=i.get(t)??new Set;n.add(e),i.set(t,n);let r=()=>c(t);e.addEventListener(`slotchange`,r),a.set(e,()=>{e.removeEventListener(`slotchange`,r)}),c(t)},u=()=>{e.shadowRoot?.querySelectorAll(`slot`).forEach(e=>l(e))},d=()=>{for(let e of i.keys())c(e)};return u(),t.onMounted(()=>{u(),d()}),t.onCleanup(()=>{for(let e of a.values())e();a.clear(),i.clear()}),{elements:e=>o(m(e)).elements,has:e=>o(m(e)).presence}},g=()=>{let e=t.currentElementOrThrow();return{bind:(r,i)=>{let a=[];if(r.attr)for(let[t,n]of Object.entries(r.attr)){let r=v(e,u(t),n);r&&a.push(r)}if(r.class&&a.push(b(e,r.class)),r.prop)for(let[t,n]of Object.entries(r.prop)){let{get:r,set:i}=n;Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get:r,...i?{set:i}:{}}),a.push(()=>{let n=Object.getOwnPropertyDescriptor(e,t);!n||n.get!==r||n.set!==i||delete e[t]})}if(r.on)for(let t of Object.keys(r.on)){let o=r.on[t];o&&a.push(n.listen(e,t,o,i))}if(r.style)for(let[t,n]of Object.entries(r.style)){let r=y(e,t,n);r&&a.push(r)}let o=()=>{for(;a.length>0;)a.pop()?.()};return t.onCleanup(o),o},el:e}},_=(e,n)=>{if(typeof e==`function`)return t.effect(()=>n(e()));if((0,r.isSignal)(e))return t.effect(()=>n(e.value));n(e)};function v(e,t,r){return _(r,r=>n.setAttr(e,t,r))}function y(e,t,r){let i=t.startsWith(`--`)?t:n.toKebab(t),a=!1;return _(r,t=>{t!=null&&t!==``?(a=!0,e.style.setProperty(i,String(t))):a&&e.style.removeProperty(i)})}function b(e,n){let i=typeof n==`function`?n:()=>{let e={};for(let[t,i]of Object.entries(n))e[t]=typeof i==`function`?i():(0,r.isSignal)(i)?i.value:!!i;return e},a=new Set;return t.effect(()=>{let t=new Set;for(let[n,r]of Object.entries(i()))r&&(t.add(n),a.has(n)||e.classList.add(n));for(let n of a)t.has(n)||e.classList.remove(n);a=t})}exports.createContext=c,exports.createHost=g,exports.createSlots=h,exports.inject=o,exports.injectStrict=s,exports.provide=a,exports.syncAria=f;
|
|
2
|
+
//# sourceMappingURL=host.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.cjs","names":[],"sources":["../src/host.ts"],"sourcesContent":["/**\n * Host utilities — component context injection, slot observation, and attribute/class reflection.\n *\n * - Context API (provide, inject, createContext)\n * - Slot observation and detection (setup slots)\n * - Host element binding (reflect) for attributes, classes, and host listeners\n */\n\nimport { effect as rawEffect, type ReadonlySignal, type Signal, isSignal, signal } from '@vielzeug/stateit';\n\nimport { CRAFTIT_ERRORS } from './errors';\nimport { listen, setAttr, toKebab } from './internal';\nimport { currentElementOrThrow, effect, onCleanup, onMounted, tryRegisterCleanup } from './runtime';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// CONTEXT API\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst contextRegistry = new WeakMap<HTMLElement, Map<InjectionKey<unknown>, unknown>>();\n\nexport type InjectionKey<T> = symbol & {\n readonly __craftit_injection_key?: T;\n};\n\nexport const provide = <T>(key: InjectionKey<T>, value: T): void => {\n const el = currentElementOrThrow();\n\n if (!contextRegistry.has(el)) contextRegistry.set(el, new Map());\n\n contextRegistry.get(el)!.set(key, value);\n};\n\nexport function inject<T>(key: InjectionKey<T>): T | undefined;\nexport function inject<T>(key: InjectionKey<T>, fallback: T): T;\nexport function inject<T>(key: InjectionKey<T>, ...rest: [T?]): T | undefined {\n let node: Node | null = currentElementOrThrow();\n\n while (node) {\n if (node instanceof HTMLElement) {\n const v = contextRegistry.get(node)?.get(key);\n\n if (v !== undefined) return v as T;\n }\n\n const root = node.getRootNode() as Node;\n\n node = (node as HTMLElement).parentElement ?? (root instanceof ShadowRoot ? root.host : null);\n }\n\n return rest.length > 0 ? rest[0] : undefined;\n}\n\nexport const injectStrict = <T>(key: InjectionKey<T>): T => {\n const resolved = inject<T>(key);\n\n if (resolved !== undefined) return resolved;\n\n const host = currentElementOrThrow();\n\n throw new Error(CRAFTIT_ERRORS.injectStrictFailed(String(key), host.localName));\n};\n\nexport function createContext<T>(description?: string): InjectionKey<T> {\n return Symbol(description) as InjectionKey<T>;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ARIA SYNC\n// ─────────────────────────────────────────────────────────────────────────────\n\ntype AriaValue = string | number | boolean | null | undefined | (() => string | number | boolean | null | undefined);\n\ntype AriaConfig = Record<string, AriaValue>;\n\ntype SyncAriaOptions = {\n autoCleanup?: boolean;\n};\n\nconst toAriaAttr = (key: string): string => {\n if (key === 'role' || key.startsWith('aria-')) return key;\n\n return key.startsWith('aria') ? `aria-${key.slice(4).toLowerCase()}` : `aria-${key}`;\n};\n\nconst toHostAttr = (key: string): string => {\n if (key === 'role' || key.startsWith('aria-')) return key;\n\n return key.startsWith('aria') ? `aria-${key.slice(4).toLowerCase()}` : key;\n};\n\nconst setA11yAttr = (target: Element, key: string, value: string | number | boolean | null | undefined): void => {\n if (value == null || value === false) {\n target.removeAttribute(key);\n\n return;\n }\n\n target.setAttribute(key, value === true ? 'true' : String(value));\n};\n\n/**\n * Reactively syncs ARIA attributes to a target element.\n * Static values are set immediately; getter functions are tracked as effects.\n * Returns a cleanup function that removes all reactive bindings.\n *\n * @example\n * syncAria(element, {\n * role: 'button',\n * expanded: () => isOpen.value,\n * disabled: () => isDisabled.value,\n * });\n */\nexport const syncAria = (target: Element, config: AriaConfig, options: SyncAriaOptions = {}): (() => void) => {\n const { autoCleanup = true } = options;\n const disposers: Array<() => void> = [];\n\n for (const [rawKey, rawValue] of Object.entries(config)) {\n const key = toAriaAttr(rawKey);\n\n if (typeof rawValue === 'function') {\n const getter = rawValue as () => string | number | boolean | null | undefined;\n\n disposers.push(\n rawEffect(() => {\n setA11yAttr(target, key, getter());\n }),\n );\n\n continue;\n }\n\n setA11yAttr(target, key, rawValue as string | number | boolean | null | undefined);\n }\n\n const cleanup = () => {\n while (disposers.length > 0) disposers.pop()?.();\n };\n\n if (autoCleanup) tryRegisterCleanup(cleanup);\n\n return cleanup;\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// SLOTS API\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst SLOT_DEFAULT = 'default';\nconst normalizeSlotName = (slotName: string | null | undefined): string => slotName || SLOT_DEFAULT;\n\nexport type ComponentSlots = {\n elements: (name?: string) => ReadonlySignal<Element[]>;\n has: (name?: string) => ReadonlySignal<boolean>;\n};\n\n/**\n * Creates first-class slot signals for setup context.\n *\n * - `slots.has(name?)`: whether a slot has assigned elements\n * - `slots.elements(name?)`: assigned elements for a slot (flattened)\n */\nexport const createSlots = (): ComponentSlots => {\n const host = currentElementOrThrow();\n\n type SlotEntry = {\n elements: Signal<Element[]>;\n presence: Signal<boolean>;\n };\n\n const slotSignals = new Map<string, SlotEntry>();\n const slotNodesByName = new Map<string, Set<HTMLSlotElement>>();\n const slotCleanupMap = new Map<HTMLSlotElement, () => void>();\n\n const ensureSlotEntry = (normalizedName: string): SlotEntry => {\n let entry = slotSignals.get(normalizedName);\n\n if (!entry) {\n entry = {\n elements: signal<Element[]>([]),\n presence: signal(false),\n };\n slotSignals.set(normalizedName, entry);\n }\n\n return entry;\n };\n\n const areElementsEqual = (prev: Element[], next: Element[]): boolean => {\n if (prev.length !== next.length) return false;\n\n for (let i = 0; i < prev.length; i++) {\n if (prev[i] !== next[i]) return false;\n }\n\n return true;\n };\n\n const recomputeSlot = (name: string): void => {\n const normalized = normalizeSlotName(name);\n const slotsForName = slotNodesByName.get(normalized);\n const assigned: Element[] = [];\n\n if (slotsForName) {\n for (const slotEl of slotsForName) {\n assigned.push(...slotEl.assignedElements({ flatten: true }));\n }\n }\n\n const entry = ensureSlotEntry(normalized);\n\n if (!areElementsEqual(entry.elements.value, assigned)) entry.elements.value = assigned;\n\n const hasElements = assigned.length > 0;\n\n if (entry.presence.value !== hasElements) entry.presence.value = hasElements;\n };\n\n const bindSlot = (slotEl: HTMLSlotElement): void => {\n if (slotCleanupMap.has(slotEl)) return;\n\n const name = normalizeSlotName(slotEl.getAttribute('name'));\n const setForName = slotNodesByName.get(name) ?? new Set<HTMLSlotElement>();\n\n setForName.add(slotEl);\n slotNodesByName.set(name, setForName);\n\n const onChange = () => recomputeSlot(name);\n\n slotEl.addEventListener('slotchange', onChange);\n\n slotCleanupMap.set(slotEl, () => {\n slotEl.removeEventListener('slotchange', onChange);\n });\n\n recomputeSlot(name);\n };\n\n const bindAllSlots = (): void => {\n host.shadowRoot?.querySelectorAll('slot').forEach((slotEl) => bindSlot(slotEl));\n };\n\n const recomputeAllSlots = (): void => {\n for (const name of slotNodesByName.keys()) {\n recomputeSlot(name);\n }\n };\n\n // setup() runs before the template is rendered, so bind once now (if any slots\n // already exist) and schedule another pass after first render.\n bindAllSlots();\n onMounted(() => {\n bindAllSlots();\n recomputeAllSlots();\n });\n\n onCleanup(() => {\n for (const cleanup of slotCleanupMap.values()) cleanup();\n\n slotCleanupMap.clear();\n slotNodesByName.clear();\n });\n\n return {\n elements: (name?: string) => ensureSlotEntry(normalizeSlotName(name)).elements,\n has: (name?: string) => ensureSlotEntry(normalizeSlotName(name)).presence,\n };\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// REFLECT API (HOST ATTRIBUTE/EVENT/CLASS BINDING)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Describes a reactive or static host binding value.\n */\nexport type HostBindingValue =\n | (() => string | number | boolean | null | undefined)\n | ReadonlySignal<string | number | boolean | null | undefined>\n | string\n | number\n | boolean\n | null\n | undefined;\n\n/**\n * Configuration for host attribute bindings.\n */\nexport type ReflectConfig = Record<string, HostBindingValue>;\n\n/**\n * Describes a reactive property accessor binding on the host element.\n * The getter is called lazily; the optional setter is used when external code\n * assigns `element.propName = value`.\n */\nexport type HostPropDescriptor<T = unknown> = {\n get: () => T;\n set?: (value: T) => void;\n};\n\ntype HostClassBindingValue = ReadonlySignal<boolean> | (() => boolean) | boolean;\ntype HostEventListener = (event: any) => void;\n\nexport type HostBindConfig = {\n attr?: ReflectConfig;\n class?: (() => Record<string, boolean>) | Record<string, HostClassBindingValue>;\n on?: Record<string, HostEventListener | undefined>;\n prop?: Record<string, HostPropDescriptor>;\n style?: Record<string, HostBindingValue>;\n};\n\nexport type ComponentHost = {\n bind: (config: HostBindConfig, options?: AddEventListenerOptions) => () => void;\n el: HTMLElement;\n};\n\nexport const createHost = (): ComponentHost => {\n const el = currentElementOrThrow();\n\n const bind = (config: HostBindConfig, options?: AddEventListenerOptions): (() => void) => {\n const disposers: Array<() => void> = [];\n\n if (config.attr) {\n for (const [key, value] of Object.entries(config.attr)) {\n const name = toHostAttr(key);\n const dispose = applyAttribute(el, name, value);\n\n if (dispose) disposers.push(dispose);\n }\n }\n\n if (config.class) {\n disposers.push(applyClassMap(el, config.class));\n }\n\n if (config.prop) {\n for (const [key, descriptor] of Object.entries(config.prop)) {\n const { get, set } = descriptor;\n\n Object.defineProperty(el, key, {\n configurable: true,\n enumerable: true,\n get,\n ...(set ? { set } : {}),\n });\n\n disposers.push(() => {\n const descriptor = Object.getOwnPropertyDescriptor(el, key);\n\n if (!descriptor || descriptor.get !== get || descriptor.set !== set) return;\n\n delete (el as unknown as Record<string, unknown>)[key];\n });\n }\n }\n\n if (config.on) {\n for (const event of Object.keys(config.on) as Array<keyof typeof config.on>) {\n const listener = config.on[event];\n\n if (!listener) continue;\n\n disposers.push(listen(el, event as string, listener as EventListener, options));\n }\n }\n\n if (config.style) {\n for (const [key, value] of Object.entries(config.style)) {\n const dispose = applyStyle(el, key, value);\n\n if (dispose) disposers.push(dispose);\n }\n }\n\n const cleanup = () => {\n while (disposers.length > 0) disposers.pop()?.();\n };\n\n onCleanup(cleanup);\n\n return cleanup;\n };\n\n return {\n bind,\n el,\n };\n};\n\nconst applyReactiveBinding = (\n value: HostBindingValue,\n updater: (next: string | number | boolean | null | undefined) => void,\n): (() => void) | void => {\n if (typeof value === 'function') {\n return effect(() => updater(value()));\n }\n\n if (isSignal(value)) {\n return effect(() => updater(value.value));\n }\n\n updater(value);\n};\n\nfunction applyAttribute(host: HTMLElement, name: string, value: HostBindingValue): (() => void) | void {\n return applyReactiveBinding(value, (next) => setAttr(host, name, next));\n}\n\nfunction applyStyle(host: HTMLElement, name: string, value: HostBindingValue): (() => void) | void {\n // Normalize camelCase property names to kebab-case for CSS setProperty.\n // CSS custom properties (--foo) are already kebab-case, so leave them as-is.\n const cssName = name.startsWith('--') ? name : toKebab(name);\n\n // Track whether this binding has ever written a value to the inline style.\n // This prevents removeProperty() from wiping an external inline style that\n // the component never set (e.g. user-authored style=\"grid-area: main;\").\n let owned = false;\n\n const setStyle = (v: any) => {\n if (v != null && v !== '') {\n owned = true;\n host.style.setProperty(cssName, String(v));\n } else if (owned) {\n host.style.removeProperty(cssName);\n }\n };\n\n return applyReactiveBinding(value, setStyle);\n}\n\nfunction applyClassMap(\n host: HTMLElement,\n value: (() => Record<string, boolean>) | Record<string, HostClassBindingValue>,\n): () => void {\n const getMap =\n typeof value === 'function'\n ? value\n : (): Record<string, boolean> => {\n const result: Record<string, boolean> = {};\n\n for (const [cls, entry] of Object.entries(value)) {\n result[cls] = typeof entry === 'function' ? entry() : isSignal(entry) ? entry.value : Boolean(entry);\n }\n\n return result;\n };\n\n let prev = new Set<string>();\n\n return effect(() => {\n const next = new Set<string>();\n\n for (const [cls, active] of Object.entries(getMap())) {\n if (!active) continue;\n\n next.add(cls);\n\n if (!prev.has(cls)) host.classList.add(cls);\n }\n\n for (const cls of prev) {\n if (!next.has(cls)) host.classList.remove(cls);\n }\n\n prev = next;\n });\n}\n"],"mappings":"0HAkBA,IAAM,EAAkB,IAAI,QAMf,GAAc,EAAsB,IAAmB,CAClE,IAAM,EAAK,EAAA,sBAAsB,EAE5B,EAAgB,IAAI,CAAE,GAAG,EAAgB,IAAI,EAAI,IAAI,GAAK,EAE/D,EAAgB,IAAI,CAAE,EAAG,IAAI,EAAK,CAAK,CACzC,EAIA,SAAgB,EAAU,EAAsB,GAAG,EAA2B,CAC5E,IAAI,EAAoB,EAAA,sBAAsB,EAE9C,KAAO,GAAM,CACX,GAAI,aAAgB,YAAa,CAC/B,IAAM,EAAI,EAAgB,IAAI,CAAI,GAAG,IAAI,CAAG,EAE5C,GAAI,IAAM,IAAA,GAAW,OAAO,CAC9B,CAEA,IAAM,EAAO,EAAK,YAAY,EAE9B,EAAQ,EAAqB,gBAAkB,aAAgB,WAAa,EAAK,KAAO,KAC1F,CAEA,OAAO,EAAK,OAAS,EAAI,EAAK,GAAK,IAAA,EACrC,CAEA,IAAa,EAAmB,GAA4B,CAC1D,IAAM,EAAW,EAAU,CAAG,EAE9B,GAAI,IAAa,IAAA,GAAW,OAAO,EAEnC,IAAM,EAAO,EAAA,sBAAsB,EAEnC,MAAU,MAAM,EAAA,eAAe,mBAAmB,OAAO,CAAG,EAAG,EAAK,SAAS,CAAC,CAChF,EAEA,SAA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,IAEjB,IAAK,GAAM,CAAC,EAAK,KAAW,OAAO,QAAQ,EAAO,CAAC,EAC5C,IAEL,EAAK,IAAI,CAAG,EAEP,EAAK,IAAI,CAAG,GAAG,EAAK,UAAU,IAAI,CAAG,GAG5C,IAAK,IAAM,KAAO,EACX,EAAK,IAAI,CAAG,GAAG,EAAK,UAAU,OAAO,CAAG,EAG/C,EAAO,CACT,CAAC,CACH"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host utilities — component context injection, slot observation, and attribute/class reflection.
|
|
3
|
+
*
|
|
4
|
+
* - Context API (provide, inject, createContext)
|
|
5
|
+
* - Slot observation and detection (setup slots)
|
|
6
|
+
* - Host element binding (reflect) for attributes, classes, and host listeners
|
|
7
|
+
*/
|
|
8
|
+
import { type ReadonlySignal } from '@vielzeug/stateit';
|
|
9
|
+
export type InjectionKey<T> = symbol & {
|
|
10
|
+
readonly __craftit_injection_key?: T;
|
|
11
|
+
};
|
|
12
|
+
export declare const provide: <T>(key: InjectionKey<T>, value: T) => void;
|
|
13
|
+
export declare function inject<T>(key: InjectionKey<T>): T | undefined;
|
|
14
|
+
export declare function inject<T>(key: InjectionKey<T>, fallback: T): T;
|
|
15
|
+
export declare const injectStrict: <T>(key: InjectionKey<T>) => T;
|
|
16
|
+
export declare function createContext<T>(description?: string): InjectionKey<T>;
|
|
17
|
+
type AriaValue = string | number | boolean | null | undefined | (() => string | number | boolean | null | undefined);
|
|
18
|
+
type AriaConfig = Record<string, AriaValue>;
|
|
19
|
+
type SyncAriaOptions = {
|
|
20
|
+
autoCleanup?: boolean;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Reactively syncs ARIA attributes to a target element.
|
|
24
|
+
* Static values are set immediately; getter functions are tracked as effects.
|
|
25
|
+
* Returns a cleanup function that removes all reactive bindings.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* syncAria(element, {
|
|
29
|
+
* role: 'button',
|
|
30
|
+
* expanded: () => isOpen.value,
|
|
31
|
+
* disabled: () => isDisabled.value,
|
|
32
|
+
* });
|
|
33
|
+
*/
|
|
34
|
+
export declare const syncAria: (target: Element, config: AriaConfig, options?: SyncAriaOptions) => (() => void);
|
|
35
|
+
export type ComponentSlots = {
|
|
36
|
+
elements: (name?: string) => ReadonlySignal<Element[]>;
|
|
37
|
+
has: (name?: string) => ReadonlySignal<boolean>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Creates first-class slot signals for setup context.
|
|
41
|
+
*
|
|
42
|
+
* - `slots.has(name?)`: whether a slot has assigned elements
|
|
43
|
+
* - `slots.elements(name?)`: assigned elements for a slot (flattened)
|
|
44
|
+
*/
|
|
45
|
+
export declare const createSlots: () => ComponentSlots;
|
|
46
|
+
/**
|
|
47
|
+
* Describes a reactive or static host binding value.
|
|
48
|
+
*/
|
|
49
|
+
export type HostBindingValue = (() => string | number | boolean | null | undefined) | ReadonlySignal<string | number | boolean | null | undefined> | string | number | boolean | null | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Configuration for host attribute bindings.
|
|
52
|
+
*/
|
|
53
|
+
export type ReflectConfig = Record<string, HostBindingValue>;
|
|
54
|
+
/**
|
|
55
|
+
* Describes a reactive property accessor binding on the host element.
|
|
56
|
+
* The getter is called lazily; the optional setter is used when external code
|
|
57
|
+
* assigns `element.propName = value`.
|
|
58
|
+
*/
|
|
59
|
+
export type HostPropDescriptor<T = unknown> = {
|
|
60
|
+
get: () => T;
|
|
61
|
+
set?: (value: T) => void;
|
|
62
|
+
};
|
|
63
|
+
type HostClassBindingValue = ReadonlySignal<boolean> | (() => boolean) | boolean;
|
|
64
|
+
type HostEventListener = (event: any) => void;
|
|
65
|
+
export type HostBindConfig = {
|
|
66
|
+
attr?: ReflectConfig;
|
|
67
|
+
class?: (() => Record<string, boolean>) | Record<string, HostClassBindingValue>;
|
|
68
|
+
on?: Record<string, HostEventListener | undefined>;
|
|
69
|
+
prop?: Record<string, HostPropDescriptor>;
|
|
70
|
+
style?: Record<string, HostBindingValue>;
|
|
71
|
+
};
|
|
72
|
+
export type ComponentHost = {
|
|
73
|
+
bind: (config: HostBindConfig, options?: AddEventListenerOptions) => () => void;
|
|
74
|
+
el: HTMLElement;
|
|
75
|
+
};
|
|
76
|
+
export declare const createHost: () => ComponentHost;
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAuB,KAAK,cAAc,EAAiC,MAAM,mBAAmB,CAAC;AAY5G,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,MAAM,GAAG;IACrC,QAAQ,CAAC,uBAAuB,CAAC,EAAE,CAAC,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,KAAK,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,KAAG,IAM3D,CAAC;AAEF,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;AAC/D,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;AAmBhE,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,KAAK,YAAY,CAAC,CAAC,CAAC,KAAG,CAQtD,CAAC;AAEF,wBAAgB,aAAa,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAEtE;AAMD,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,MAAM,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IA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K,iBAAiB,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;AAE9C,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,KAAK,CAAC,EAAE,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAChF,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAC,CAAC;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,uBAAuB,KAAK,MAAM,IAAI,CAAC;IAChF,EAAE,EAAE,WAAW,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,UAAU,QAAO,aAuE7B,CAAC"}
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{CRAFTIT_ERRORS as e}from"./errors.js";import{currentElementOrThrow as t,effect as n,onCleanup as r,onMounted as i,tryRegisterCleanup as a}from"./runtime.js";import{listen as o,setAttr as s,toKebab as c}from"./internal.js";import{effect as l,isSignal as u,signal as d}from"@vielzeug/stateit";var f=new WeakMap,p=(e,n)=>{let r=t();f.has(r)||f.set(r,new Map),f.get(r).set(e,n)};function m(e,...n){let r=t();for(;r;){if(r instanceof HTMLElement){let t=f.get(r)?.get(e);if(t!==void 0)return t}let t=r.getRootNode();r=r.parentElement??(t instanceof ShadowRoot?t.host:null)}return n.length>0?n[0]:void 0}var h=n=>{let r=m(n);if(r!==void 0)return r;let i=t();throw Error(e.injectStrictFailed(String(n),i.localName))};function g(e){return Symbol(e)}var _=e=>e===`role`||e.startsWith(`aria-`)?e:e.startsWith(`aria`)?`aria-${e.slice(4).toLowerCase()}`:`aria-${e}`,v=e=>e===`role`||e.startsWith(`aria-`)?e:e.startsWith(`aria`)?`aria-${e.slice(4).toLowerCase()}`:e,y=(e,t,n)=>{if(n==null||n===!1){e.removeAttribute(t);return}e.setAttribute(t,n===!0?`true`:String(n))},b=(e,t,n={})=>{let{autoCleanup:r=!0}=n,i=[];for(let[n,r]of Object.entries(t)){let t=_(n);if(typeof r==`function`){let n=r;i.push(l(()=>{y(e,t,n())}));continue}y(e,t,r)}let o=()=>{for(;i.length>0;)i.pop()?.()};return r&&a(o),o},x=`default`,S=e=>e||x,C=()=>{let e=t(),n=new Map,a=new Map,o=new Map,s=e=>{let t=n.get(e);return t||(t={elements:d([]),presence:d(!1)},n.set(e,t)),t},c=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0},l=e=>{let t=S(e),n=a.get(t),r=[];if(n)for(let e of n)r.push(...e.assignedElements({flatten:!0}));let i=s(t);c(i.elements.value,r)||(i.elements.value=r);let o=r.length>0;i.presence.value!==o&&(i.presence.value=o)},u=e=>{if(o.has(e))return;let t=S(e.getAttribute(`name`)),n=a.get(t)??new Set;n.add(e),a.set(t,n);let r=()=>l(t);e.addEventListener(`slotchange`,r),o.set(e,()=>{e.removeEventListener(`slotchange`,r)}),l(t)},f=()=>{e.shadowRoot?.querySelectorAll(`slot`).forEach(e=>u(e))},p=()=>{for(let e of a.keys())l(e)};return f(),i(()=>{f(),p()}),r(()=>{for(let e of o.values())e();o.clear(),a.clear()}),{elements:e=>s(S(e)).elements,has:e=>s(S(e)).presence}},w=()=>{let e=t();return{bind:(t,n)=>{let i=[];if(t.attr)for(let[n,r]of Object.entries(t.attr)){let t=E(e,v(n),r);t&&i.push(t)}if(t.class&&i.push(O(e,t.class)),t.prop)for(let[n,r]of Object.entries(t.prop)){let{get:t,set:a}=r;Object.defineProperty(e,n,{configurable:!0,enumerable:!0,get:t,...a?{set:a}:{}}),i.push(()=>{let r=Object.getOwnPropertyDescriptor(e,n);!r||r.get!==t||r.set!==a||delete e[n]})}if(t.on)for(let r of Object.keys(t.on)){let a=t.on[r];a&&i.push(o(e,r,a,n))}if(t.style)for(let[n,r]of Object.entries(t.style)){let t=D(e,n,r);t&&i.push(t)}let a=()=>{for(;i.length>0;)i.pop()?.()};return r(a),a},el:e}},T=(e,t)=>{if(typeof e==`function`)return n(()=>t(e()));if(u(e))return n(()=>t(e.value));t(e)};function E(e,t,n){return T(n,n=>s(e,t,n))}function D(e,t,n){let r=t.startsWith(`--`)?t:c(t),i=!1;return T(n,t=>{t!=null&&t!==``?(i=!0,e.style.setProperty(r,String(t))):i&&e.style.removeProperty(r)})}function O(e,t){let r=typeof t==`function`?t:()=>{let e={};for(let[n,r]of Object.entries(t))e[n]=typeof r==`function`?r():u(r)?r.value:!!r;return e},i=new Set;return n(()=>{let t=new Set;for(let[n,a]of Object.entries(r()))a&&(t.add(n),i.has(n)||e.classList.add(n));for(let n of i)t.has(n)||e.classList.remove(n);i=t})}export{g as createContext,w as createHost,C as createSlots,m as inject,h as injectStrict,p as provide,b as syncAria};
|
|
2
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","names":[],"sources":["../src/host.ts"],"sourcesContent":["/**\n * Host utilities — component context injection, slot observation, and attribute/class reflection.\n *\n * - Context API (provide, inject, createContext)\n * - Slot observation and detection (setup slots)\n * - Host element binding (reflect) for attributes, classes, and host listeners\n */\n\nimport { effect as rawEffect, type ReadonlySignal, type Signal, isSignal, signal } from '@vielzeug/stateit';\n\nimport { CRAFTIT_ERRORS } from './errors';\nimport { listen, setAttr, toKebab } from './internal';\nimport { currentElementOrThrow, effect, onCleanup, onMounted, tryRegisterCleanup } from './runtime';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// CONTEXT API\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst contextRegistry = new WeakMap<HTMLElement, Map<InjectionKey<unknown>, unknown>>();\n\nexport type InjectionKey<T> = symbol & {\n readonly __craftit_injection_key?: T;\n};\n\nexport const provide = <T>(key: InjectionKey<T>, value: T): void => {\n const el = currentElementOrThrow();\n\n if (!contextRegistry.has(el)) contextRegistry.set(el, new Map());\n\n contextRegistry.get(el)!.set(key, value);\n};\n\nexport function inject<T>(key: InjectionKey<T>): T | undefined;\nexport function inject<T>(key: InjectionKey<T>, fallback: T): T;\nexport function inject<T>(key: InjectionKey<T>, ...rest: [T?]): T | undefined {\n let node: Node | null = currentElementOrThrow();\n\n while (node) {\n if (node instanceof HTMLElement) {\n const v = contextRegistry.get(node)?.get(key);\n\n if (v !== undefined) return v as T;\n }\n\n const root = node.getRootNode() as Node;\n\n node = (node as HTMLElement).parentElement ?? (root instanceof ShadowRoot ? root.host : null);\n }\n\n return rest.length > 0 ? rest[0] : undefined;\n}\n\nexport const injectStrict = <T>(key: InjectionKey<T>): T => {\n const resolved = inject<T>(key);\n\n if (resolved !== undefined) return resolved;\n\n const host = currentElementOrThrow();\n\n throw new Error(CRAFTIT_ERRORS.injectStrictFailed(String(key), host.localName));\n};\n\nexport function createContext<T>(description?: string): InjectionKey<T> {\n return Symbol(description) as InjectionKey<T>;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ARIA SYNC\n// ─────────────────────────────────────────────────────────────────────────────\n\ntype AriaValue = string | number | boolean | null | undefined | (() => string | number | boolean | null | undefined);\n\ntype AriaConfig = Record<string, AriaValue>;\n\ntype SyncAriaOptions = {\n autoCleanup?: boolean;\n};\n\nconst toAriaAttr = (key: string): string => {\n if (key === 'role' || key.startsWith('aria-')) return key;\n\n return key.startsWith('aria') ? `aria-${key.slice(4).toLowerCase()}` : `aria-${key}`;\n};\n\nconst toHostAttr = (key: string): string => {\n if (key === 'role' || key.startsWith('aria-')) return key;\n\n return key.startsWith('aria') ? `aria-${key.slice(4).toLowerCase()}` : key;\n};\n\nconst setA11yAttr = (target: Element, key: string, value: string | number | boolean | null | undefined): void => {\n if (value == null || value === false) {\n target.removeAttribute(key);\n\n return;\n }\n\n target.setAttribute(key, value === true ? 'true' : String(value));\n};\n\n/**\n * Reactively syncs ARIA attributes to a target element.\n * Static values are set immediately; getter functions are tracked as effects.\n * Returns a cleanup function that removes all reactive bindings.\n *\n * @example\n * syncAria(element, {\n * role: 'button',\n * expanded: () => isOpen.value,\n * disabled: () => isDisabled.value,\n * });\n */\nexport const syncAria = (target: Element, config: AriaConfig, options: SyncAriaOptions = {}): (() => void) => {\n const { autoCleanup = true } = options;\n const disposers: Array<() => void> = [];\n\n for (const [rawKey, rawValue] of Object.entries(config)) {\n const key = toAriaAttr(rawKey);\n\n if (typeof rawValue === 'function') {\n const getter = rawValue as () => string | number | boolean | null | undefined;\n\n disposers.push(\n rawEffect(() => {\n setA11yAttr(target, key, getter());\n }),\n );\n\n continue;\n }\n\n setA11yAttr(target, key, rawValue as string | number | boolean | null | undefined);\n }\n\n const cleanup = () => {\n while (disposers.length > 0) disposers.pop()?.();\n };\n\n if (autoCleanup) tryRegisterCleanup(cleanup);\n\n return cleanup;\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// SLOTS API\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst SLOT_DEFAULT = 'default';\nconst normalizeSlotName = (slotName: string | null | undefined): string => slotName || SLOT_DEFAULT;\n\nexport type ComponentSlots = {\n elements: (name?: string) => ReadonlySignal<Element[]>;\n has: (name?: string) => ReadonlySignal<boolean>;\n};\n\n/**\n * Creates first-class slot signals for setup context.\n *\n * - `slots.has(name?)`: whether a slot has assigned elements\n * - `slots.elements(name?)`: assigned elements for a slot (flattened)\n */\nexport const createSlots = (): ComponentSlots => {\n const host = currentElementOrThrow();\n\n type SlotEntry = {\n elements: Signal<Element[]>;\n presence: Signal<boolean>;\n };\n\n const slotSignals = new Map<string, SlotEntry>();\n const slotNodesByName = new Map<string, Set<HTMLSlotElement>>();\n const slotCleanupMap = new Map<HTMLSlotElement, () => void>();\n\n const ensureSlotEntry = (normalizedName: string): SlotEntry => {\n let entry = slotSignals.get(normalizedName);\n\n if (!entry) {\n entry = {\n elements: signal<Element[]>([]),\n presence: signal(false),\n };\n slotSignals.set(normalizedName, entry);\n }\n\n return entry;\n };\n\n const areElementsEqual = (prev: Element[], next: Element[]): boolean => {\n if (prev.length !== next.length) return false;\n\n for (let i = 0; i < prev.length; i++) {\n if (prev[i] !== next[i]) return false;\n }\n\n return true;\n };\n\n const recomputeSlot = (name: string): void => {\n const normalized = normalizeSlotName(name);\n const slotsForName = slotNodesByName.get(normalized);\n const assigned: Element[] = [];\n\n if (slotsForName) {\n for (const slotEl of slotsForName) {\n assigned.push(...slotEl.assignedElements({ flatten: true }));\n }\n }\n\n const entry = ensureSlotEntry(normalized);\n\n if (!areElementsEqual(entry.elements.value, assigned)) entry.elements.value = assigned;\n\n const hasElements = assigned.length > 0;\n\n if (entry.presence.value !== hasElements) entry.presence.value = hasElements;\n };\n\n const bindSlot = (slotEl: HTMLSlotElement): void => {\n if (slotCleanupMap.has(slotEl)) return;\n\n const name = normalizeSlotName(slotEl.getAttribute('name'));\n const setForName = slotNodesByName.get(name) ?? new Set<HTMLSlotElement>();\n\n setForName.add(slotEl);\n slotNodesByName.set(name, setForName);\n\n const onChange = () => recomputeSlot(name);\n\n slotEl.addEventListener('slotchange', onChange);\n\n slotCleanupMap.set(slotEl, () => {\n slotEl.removeEventListener('slotchange', onChange);\n });\n\n recomputeSlot(name);\n };\n\n const bindAllSlots = (): void => {\n host.shadowRoot?.querySelectorAll('slot').forEach((slotEl) => bindSlot(slotEl));\n };\n\n const recomputeAllSlots = (): void => {\n for (const name of slotNodesByName.keys()) {\n recomputeSlot(name);\n }\n };\n\n // setup() runs before the template is rendered, so bind once now (if any slots\n // already exist) and schedule another pass after first render.\n bindAllSlots();\n onMounted(() => {\n bindAllSlots();\n recomputeAllSlots();\n });\n\n onCleanup(() => {\n for (const cleanup of slotCleanupMap.values()) cleanup();\n\n slotCleanupMap.clear();\n slotNodesByName.clear();\n });\n\n return {\n elements: (name?: string) => ensureSlotEntry(normalizeSlotName(name)).elements,\n has: (name?: string) => ensureSlotEntry(normalizeSlotName(name)).presence,\n };\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// REFLECT API (HOST ATTRIBUTE/EVENT/CLASS BINDING)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Describes a reactive or static host binding value.\n */\nexport type HostBindingValue =\n | (() => string | number | boolean | null | undefined)\n | ReadonlySignal<string | number | boolean | null | undefined>\n | string\n | number\n | boolean\n | null\n | undefined;\n\n/**\n * Configuration for host attribute bindings.\n */\nexport type ReflectConfig = Record<string, HostBindingValue>;\n\n/**\n * Describes a reactive property accessor binding on the host element.\n * The getter is called lazily; the optional setter is used when external code\n * assigns `element.propName = value`.\n */\nexport type HostPropDescriptor<T = unknown> = {\n get: () => T;\n set?: (value: T) => void;\n};\n\ntype HostClassBindingValue = ReadonlySignal<boolean> | (() => boolean) | boolean;\ntype HostEventListener = (event: any) => void;\n\nexport type HostBindConfig = {\n attr?: ReflectConfig;\n class?: (() => Record<string, boolean>) | Record<string, HostClassBindingValue>;\n on?: Record<string, HostEventListener | undefined>;\n prop?: Record<string, HostPropDescriptor>;\n style?: Record<string, HostBindingValue>;\n};\n\nexport type ComponentHost = {\n bind: (config: HostBindConfig, options?: AddEventListenerOptions) => () => void;\n el: HTMLElement;\n};\n\nexport const createHost = (): ComponentHost => {\n const el = currentElementOrThrow();\n\n const bind = (config: HostBindConfig, options?: AddEventListenerOptions): (() => void) => {\n const disposers: Array<() => void> = [];\n\n if (config.attr) {\n for (const [key, value] of Object.entries(config.attr)) {\n const name = toHostAttr(key);\n const dispose = applyAttribute(el, name, value);\n\n if (dispose) disposers.push(dispose);\n }\n }\n\n if (config.class) {\n disposers.push(applyClassMap(el, config.class));\n }\n\n if (config.prop) {\n for (const [key, descriptor] of Object.entries(config.prop)) {\n const { get, set } = descriptor;\n\n Object.defineProperty(el, key, {\n configurable: true,\n enumerable: true,\n get,\n ...(set ? { set } : {}),\n });\n\n disposers.push(() => {\n const descriptor = Object.getOwnPropertyDescriptor(el, key);\n\n if (!descriptor || descriptor.get !== get || descriptor.set !== set) return;\n\n delete (el as unknown as Record<string, unknown>)[key];\n });\n }\n }\n\n if (config.on) {\n for (const event of Object.keys(config.on) as Array<keyof typeof config.on>) {\n const listener = config.on[event];\n\n if (!listener) continue;\n\n disposers.push(listen(el, event as string, listener as EventListener, options));\n }\n }\n\n if (config.style) {\n for (const [key, value] of Object.entries(config.style)) {\n const dispose = applyStyle(el, key, value);\n\n if (dispose) disposers.push(dispose);\n }\n }\n\n const cleanup = () => {\n while (disposers.length > 0) disposers.pop()?.();\n };\n\n onCleanup(cleanup);\n\n return cleanup;\n };\n\n return {\n bind,\n el,\n };\n};\n\nconst applyReactiveBinding = (\n value: HostBindingValue,\n updater: (next: string | number | boolean | null | undefined) => void,\n): (() => void) | void => {\n if (typeof value === 'function') {\n return effect(() => updater(value()));\n }\n\n if (isSignal(value)) {\n return effect(() => updater(value.value));\n }\n\n updater(value);\n};\n\nfunction applyAttribute(host: HTMLElement, name: string, value: HostBindingValue): (() => void) | void {\n return applyReactiveBinding(value, (next) => setAttr(host, name, next));\n}\n\nfunction applyStyle(host: HTMLElement, name: string, value: HostBindingValue): (() => void) | void {\n // Normalize camelCase property names to kebab-case for CSS setProperty.\n // CSS custom properties (--foo) are already kebab-case, so leave them as-is.\n const cssName = name.startsWith('--') ? name : toKebab(name);\n\n // Track whether this binding has ever written a value to the inline style.\n // This prevents removeProperty() from wiping an external inline style that\n // the component never set (e.g. user-authored style=\"grid-area: main;\").\n let owned = false;\n\n const setStyle = (v: any) => {\n if (v != null && v !== '') {\n owned = true;\n host.style.setProperty(cssName, String(v));\n } else if (owned) {\n host.style.removeProperty(cssName);\n }\n };\n\n return applyReactiveBinding(value, setStyle);\n}\n\nfunction applyClassMap(\n host: HTMLElement,\n value: (() => Record<string, boolean>) | Record<string, HostClassBindingValue>,\n): () => void {\n const getMap =\n typeof value === 'function'\n ? value\n : (): Record<string, boolean> => {\n const result: Record<string, boolean> = {};\n\n for (const [cls, entry] of Object.entries(value)) {\n result[cls] = typeof entry === 'function' ? entry() : isSignal(entry) ? entry.value : Boolean(entry);\n }\n\n return result;\n };\n\n let prev = new Set<string>();\n\n return effect(() => {\n const next = new Set<string>();\n\n for (const [cls, active] of Object.entries(getMap())) {\n if (!active) continue;\n\n next.add(cls);\n\n if (!prev.has(cls)) host.classList.add(cls);\n }\n\n for (const cls of prev) {\n if (!next.has(cls)) host.classList.remove(cls);\n }\n\n prev = next;\n });\n}\n"],"mappings":"0SAkBA,IAAM,EAAkB,IAAI,QAMf,GAAc,EAAsB,IAAmB,CAClE,IAAM,EAAK,EAAsB,EAE5B,EAAgB,IAAI,CAAE,GAAG,EAAgB,IAAI,EAAI,IAAI,GAAK,EAE/D,EAAgB,IAAI,CAAE,EAAG,IAAI,EAAK,CAAK,CACzC,EAIA,SAAgB,EAAU,EAAsB,GAAG,EAA2B,CAC5E,IAAI,EAAoB,EAAsB,EAE9C,KAAO,GAAM,CACX,GAAI,aAAgB,YAAa,CAC/B,IAAM,EAAI,EAAgB,IAAI,CAAI,GAAG,IAAI,CAAG,EAE5C,GAAI,IAAM,IAAA,GAAW,OAAO,CAC9B,CAEA,IAAM,EAAO,EAAK,YAAY,EAE9B,EAAQ,EAAqB,gBAAkB,aAAgB,WAAa,EAAK,KAAO,KAC1F,CAEA,OAAO,EAAK,OAAS,EAAI,EAAK,GAAK,IAAA,EACrC,CAEA,IAAa,EAAmB,GAA4B,CAC1D,IAAM,EAAW,EAAU,CAAG,EAE9B,GAAI,IAAa,IAAA,GAAW,OAAO,EAEnC,IAAM,EAAO,EAAsB,EAEnC,MAAU,MAAM,EAAe,mBAAmB,OAAO,CAAG,EAAG,EAAK,SAAS,CAAC,CAChF,EAEA,SAAgB,EAAiB,EAAuC,CACtE,OAAO,OAAO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O,EACX,EAAK,IAAI,CAAG,GAAG,EAAK,UAAU,OAAO,CAAG,EAG/C,EAAO,CACT,CAAC,CACH"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./runtime.cjs`),t=require(`./internal.cjs`),n=require(`./form.cjs`),r=require(`./host.cjs`),i=require(`./props.cjs`),a=require(`./directives/live.cjs`),o=require(`./registration.cjs`),s=require(`./template-compiler.cjs`),c=require(`./directives/each.cjs`),l=require(`./directives/classMap.cjs`),u=require(`./directives/styleMap.cjs`),d=require(`./directives/when.cjs`),f=require(`./directives/guard.cjs`),p=require(`./directives/resource.cjs`),m=require(`./directives/raw.cjs`);let h=require(`@vielzeug/stateit`);Object.defineProperty(exports,`batch`,{enumerable:!0,get:function(){return h.batch}}),exports.classMap=l.classMap,Object.defineProperty(exports,`computed`,{enumerable:!0,get:function(){return h.computed}}),exports.createContext=r.createContext,exports.createId=t.createId,exports.css=t.css,exports.define=o.define,exports.defineField=n.defineField,exports.each=c.each,exports.effect=e.effect,exports.guard=f.guard,exports.html=s.html,exports.inject=r.inject,exports.injectStrict=r.injectStrict,Object.defineProperty(exports,`isSignal`,{enumerable:!0,get:function(){return h.isSignal}}),exports.listen=e.listen,exports.live=a.live,exports.on=e.on,exports.onCleanup=e.onCleanup,exports.onElement=e.onElement,exports.onMounted=e.onMounted,exports.prop=i.prop,exports.provide=r.provide,exports.raw=m.raw,exports.ref=t.ref,exports.refs=t.refs,exports.resource=p.resource,Object.defineProperty(exports,`scope`,{enumerable:!0,get:function(){return h.scope}}),Object.defineProperty(exports,`signal`,{enumerable:!0,get:function(){return h.signal}}),exports.styleMap=u.styleMap,exports.syncAria=r.syncAria,Object.defineProperty(exports,`untrack`,{enumerable:!0,get:function(){return h.untrack}}),Object.defineProperty(exports,`watch`,{enumerable:!0,get:function(){return h.watch}}),exports.when=d.when;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
1
|
+
export { batch, computed, isSignal, scope, signal, untrack, watch, type ReadonlySignal, type Scope, type Signal, type WatchOptions, } from '@vielzeug/stateit';
|
|
2
|
+
export { effect, listen, on, onCleanup, onElement, onMounted } from './runtime';
|
|
3
|
+
export { define, type ComponentDefinition, type InferPropsFromDefs, type InferPropsSignals, prop, type PropDef, type PropInputDefs, type PropsDef, type PropOptions, type SetupContextBag, } from './registration';
|
|
4
|
+
export type { ComponentTemplate } from './registration';
|
|
5
|
+
export { defineField, type FormFieldHandle, type FormFieldOptions } from './form';
|
|
6
|
+
export { createContext, inject, injectStrict, provide, syncAria, type ComponentHost, type ComponentSlots, type HostBindingValue, type HostPropDescriptor, type InjectionKey, type ReflectConfig, } from './host';
|
|
7
|
+
export { html } from './template-compiler';
|
|
8
|
+
export { each } from './directives/each';
|
|
9
|
+
export { classMap } from './directives/classMap';
|
|
10
|
+
export { styleMap } from './directives/styleMap';
|
|
11
|
+
export { when } from './directives/when';
|
|
12
|
+
export { guard } from './directives/guard';
|
|
13
|
+
export { live } from './directives/live';
|
|
14
|
+
export { resource, type ResourceState } from './directives/resource';
|
|
15
|
+
export { raw } from './directives/raw';
|
|
16
|
+
export { css, createId, ref, refs, type CSSResult, type EmitFn, type HTMLResult, type Ref, type RefCallback, type Refs, } from './internal';
|
|
10
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","s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MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEvC,OAAO,EACL,GAAG,EACH,QAAQ,EACR,GAAG,EACH,IAAI,EACJ,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,GAAG,EACR,KAAK,WAAW,EAChB,KAAK,IAAI,GACV,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{effect as e,listen as t,on as n,onCleanup as r,onElement as i,onMounted as a}from"./runtime.js";import{createId as o,css as s,ref as c,refs as l}from"./internal.js";import{defineField as u}from"./form.js";import{createContext as d,inject as f,injectStrict as p,provide as m,syncAria as h}from"./host.js";import{prop as g}from"./props.js";import{live as _}from"./directives/live.js";import{define as v}from"./registration.js";import{html as y}from"./template-compiler.js";import{each as b}from"./directives/each.js";import{classMap as x}from"./directives/classMap.js";import{styleMap as S}from"./directives/styleMap.js";import{when as C}from"./directives/when.js";import{guard as w}from"./directives/guard.js";import{resource as T}from"./directives/resource.js";import{raw as E}from"./directives/raw.js";import{batch as D,computed as O,isSignal as k,scope as A,signal as j,untrack as M,watch as N}from"@vielzeug/stateit";export{D as batch,x as classMap,O as computed,d as createContext,o as createId,s as css,v as define,u as defineField,b as each,e as effect,w as guard,y as html,f as inject,p as injectStrict,k as isSignal,t as listen,_ as live,n as on,r as onCleanup,i as onElement,a as onMounted,g as prop,m as provide,E as raw,c as ref,l as refs,T as resource,A as scope,j as signal,S as styleMap,h as syncAria,M as untrack,N as watch,C as when};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`./errors.cjs`),t=require(`./runtime.cjs`);let n=require(`@vielzeug/stateit`);function r(){return(0,n.signal)(null)}function i(){return[]}var a=e=>typeof e==`object`&&!!e&&e.__craftitDirective===!0&&typeof e.mount==`function`;function o(e,t=[]){return{__bindings:t,__craftitHtmlResult:!0,__html:e,toString(){return e}}}var s=e=>typeof e==`object`&&!!e&&e.__craftitHtmlResult===!0;function c(e){return typeof e==`string`?{bindings:[],html:e}:{bindings:e.__bindings,html:e.__html}}var l=e=>typeof e==`object`&&!!e&&e.__craftitCssResult===!0,u=t=>{let n=[];for(let e=t.length-1;e>=0;e--)try{t[e]()}catch(e){n.push(e)}if(n.length>0)throw AggregateError(n,e.CRAFTIT_ERRORS.cleanupFailed)},d=e=>{for(let t of e)t.remove()},f=(e,t,n)=>{if(/^on/i.test(t)){e.removeAttribute(t);return}n==null||n===!1?e.removeAttribute(t):e.setAttribute(t,n===!0?`true`:String(n))},p=(e,t,n,r)=>{if(!e)return()=>{};let i=n;return e.addEventListener(t,i,r),()=>e.removeEventListener(t,i,r)},m=e=>e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),h={"'":`'`,'"':`"`,"&":`&`,"<":`<`,">":`>`},g=e=>String(e).replace(/[&<>"']/g,e=>h[e]),_=()=>{let e=t.currentElementOrThrow();return((t,...n)=>{y.custom(e,String(t),n.length>0?{detail:n[0]}:void 0)})},v={bubbles:!0,cancelable:!0,composed:!0},y={custom(e,t,n={}){return e.dispatchEvent(new CustomEvent(t,{...v,...n}))},event(e,t){return e.dispatchEvent(t)},focus(e,t,n={}){return e.dispatchEvent(new FocusEvent(t,{...v,...n}))},keyboard(e,t,n={}){return e.dispatchEvent(new KeyboardEvent(t,{...v,...n}))},mouse(e,t,n={}){return e.dispatchEvent(new MouseEvent(t,{...v,...n}))},touch(e,t,n={}){return typeof TouchEvent<`u`?e.dispatchEvent(new TouchEvent(t,{...v,...n})):e.dispatchEvent(new CustomEvent(t,{...v,...n}))}},b=0,x=()=>{b=0},S=e=>`${e?`${e}-`:`cft-`}${++b}`,C=RegExp(`u="([^"]+)"`,`g`),w=()=>{let e=0;return()=>String(e++)},T=(e,t)=>{let n=new Map,r=e=>{let r=n.get(e);if(r)return r;let i=t();return n.set(e,i),i};return{bindings:e.__bindings.map(e=>({...e,uid:r(e.uid)})),html:e.__html.replace(C,(e,t)=>`u="${r(t)}"`).replace(/<!--(\d+)-->/g,(e,t)=>`<!--${r(t)}-->`)}},E=function(){return this.content},D=(e,...t)=>{let n=``;for(let r=0;r<e.length;r++)if(n+=e[r],r<t.length){let e=t[r];n+=l(e)?e.content:e??``}return{__craftitCssResult:!0,content:n.trim(),toString:E}},O=new Map,k=t=>{if(t instanceof CSSStyleSheet)return t;let n=typeof t==`string`?t:t.content,r=O.get(n);if(r)return r;let i=new CSSStyleSheet;try{i.replaceSync(n)}catch(t){console.error(e.CRAFTIT_ERRORS.styleReplaceFailed,t)}return O.set(n,i),i};exports._resetIdCounter=x,exports.createEmitFn=_,exports.createId=S,exports.createMarkerIdFactory=w,exports.css=D,exports.escapeHtml=g,exports.extractResult=c,exports.fire=y,exports.htmlResult=o,exports.isDirectiveResult=a,exports.isHtmlResult=s,exports.listen=p,exports.loadStylesheet=k,exports.ref=r,exports.refs=i,exports.rekeyHtmlResult=T,exports.removeNodes=d,exports.runAll=u,exports.setAttr=f,exports.toKebab=m;
|
|
2
|
+
//# sourceMappingURL=internal.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.cjs","names":[],"sources":["../src/internal.ts"],"sourcesContent":["import { signal, type ReadonlySignal, type Signal } from '@vielzeug/stateit';\n\nimport { CRAFTIT_ERRORS } from './errors';\nimport { currentElementOrThrow } from './runtime';\n\nexport type Ref<T extends Element> = Signal<T | null>;\n\nexport function ref<T extends Element>(): Ref<T> {\n return signal<T | null>(null);\n}\n\nexport type Refs<T extends Element> = T[];\n\nexport function refs<T extends Element>(): Refs<T> {\n return [];\n}\n\nexport type RefCallback<T extends Element> = (el: T | null) => void;\n\nexport type TextBinding = {\n signal: ReadonlySignal<unknown>;\n type: 'text';\n uid: string;\n};\n\nexport type AttrBinding = {\n /** When true the binding uses live-write semantics: stale app-state writes are\n * skipped if the DOM value has diverged from the last programmatic write. */\n live?: true;\n mode: 'bool' | 'attr';\n name: string;\n signal?: ReadonlySignal<unknown>;\n type: 'attr';\n uid: string;\n value?: unknown;\n};\n\nexport type EventBinding = {\n handler: (e: Event) => void;\n name: string;\n options?: AddEventListenerOptions;\n type: 'event';\n uid: string;\n};\n\nexport type RefBinding = {\n ref: Ref<Element> | Refs<Element> | RefCallback<Element>;\n type: 'ref';\n uid: string;\n};\n\nexport type HtmlBindingPayload = {\n bindings: Binding[];\n html: string;\n};\n\nexport type RuntimeDirective = {\n __craftitDirective: true;\n mount: (anchor: Comment, registerCleanup: (fn: () => void) => void) => void;\n};\n\nexport type DirectiveResult = RuntimeDirective;\n\nexport const isDirectiveResult = (value: unknown): value is DirectiveResult =>\n typeof value === 'object' &&\n value !== null &&\n (value as RuntimeDirective).__craftitDirective === true &&\n typeof (value as RuntimeDirective).mount === 'function';\n\nexport type HtmlBinding = {\n signal: ReadonlySignal<HtmlBindingPayload>;\n type: 'html';\n uid: string;\n};\n\nexport type DirectiveBinding = {\n directive: RuntimeDirective;\n type: 'directive';\n uid: string;\n};\n\nexport type Binding = TextBinding | AttrBinding | EventBinding | RefBinding | HtmlBinding | DirectiveBinding;\n\nexport interface HTMLResult {\n __bindings: Binding[];\n __craftitHtmlResult: true;\n __html: string;\n toString(): string;\n}\n\nexport function htmlResult(html: string, bindings: Binding[] = []): HTMLResult {\n return {\n __bindings: bindings,\n __craftitHtmlResult: true,\n __html: html,\n toString() {\n return html;\n },\n };\n}\n\nexport const isHtmlResult = (value: unknown): value is HTMLResult =>\n typeof value === 'object' && value !== null && (value as HTMLResult).__craftitHtmlResult === true;\n\nexport function extractResult(v: string | HTMLResult): { bindings: Binding[]; html: string } {\n return typeof v === 'string' ? { bindings: [], html: v } : { bindings: v.__bindings, html: v.__html };\n}\n\nexport type CSSResult = {\n __craftitCssResult: true;\n content: string;\n toString(): string;\n};\n\nexport const isCssResult = (value: unknown): value is CSSResult =>\n typeof value === 'object' && !!value && (value as CSSResult).__craftitCssResult === true;\n\n// ─────────────────────────────────────────────────────────────────────────────\n// DOM UTILITIES\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport const runAll = (fns: (() => void)[]): void => {\n const errors: unknown[] = [];\n\n for (let i = fns.length - 1; i >= 0; i--) {\n try {\n fns[i]();\n } catch (err) {\n errors.push(err);\n }\n }\n\n if (errors.length > 0) {\n throw new AggregateError(errors, CRAFTIT_ERRORS.cleanupFailed);\n }\n};\n\nexport const removeNodes = (nodes: Node[]): void => {\n for (const node of nodes) {\n (node as ChildNode).remove();\n }\n};\n\nexport const setAttr = (el: Element, name: string, val: unknown): void => {\n if (/^on/i.test(name)) {\n el.removeAttribute(name);\n\n return;\n }\n\n if (val == null || val === false) {\n el.removeAttribute(name);\n } else {\n el.setAttribute(name, val === true ? 'true' : String(val));\n }\n};\n\nexport const listen = (\n el: EventTarget | null | undefined,\n name: string,\n handler: (e: any) => void,\n options?: AddEventListenerOptions,\n): (() => void) => {\n if (!el) return () => {};\n\n const listener: EventListener = handler as EventListener;\n\n el.addEventListener(name, listener, options);\n\n return () => el.removeEventListener(name, listener, options);\n};\n\nexport const toKebab = (str: string): string => str.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);\n\nconst ESC: Record<string, string> = { \"'\": ''', '\"': '"', '&': '&', '<': '<', '>': '>' };\n\nexport const escapeHtml = (value: unknown): string => String(value).replace(/[&<>\"']/g, (c) => ESC[c]);\n\n// ─────────────────────────────────────────────────────────────────────────────\n// EMIT UTILITIES\n// ─────────────────────────────────────────────────────────────────────────────\n\ntype NoDetail = void | undefined | never;\ntype KeysWithoutDetail<T extends Record<string, unknown>> = {\n [P in keyof T]: [T[P]] extends [NoDetail] ? P : never;\n}[keyof T];\n\ntype StrictEmitFn<T extends Record<string, unknown>> = {\n <K extends KeysWithoutDetail<T>>(event: K): void;\n <K extends Exclude<keyof T, KeysWithoutDetail<T>>>(event: K, detail: T[K]): void;\n};\n\ntype LooseEmitFn = (event: string, detail?: unknown) => void;\n\nexport type EmitFn<T extends Record<string, unknown>> = StrictEmitFn<T> & LooseEmitFn;\n\nexport const createEmitFn = <T extends Record<string, unknown>>(): EmitFn<T> => {\n const el = currentElementOrThrow();\n\n return ((event: keyof T, ...rest: unknown[]) => {\n fire.custom(el, String(event), rest.length > 0 ? { detail: rest[0] } : undefined);\n }) as EmitFn<T>;\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// FIRE UTILITIES\n// ─────────────────────────────────────────────────────────────────────────────\n\ntype FireDefaults = Pick<EventInit, 'bubbles' | 'cancelable' | 'composed'>;\n\nexport type FireApi = {\n custom<Detail = unknown>(target: EventTarget, type: string, options?: CustomEventInit<Detail>): boolean;\n event(target: EventTarget, event: Event): boolean;\n focus(target: EventTarget, type: string, options?: FocusEventInit): boolean;\n keyboard(target: EventTarget, type: string, options?: KeyboardEventInit): boolean;\n mouse(target: EventTarget, type: string, options?: MouseEventInit): boolean;\n touch(target: EventTarget, type: string, options?: TouchEventInit): boolean;\n};\n\nconst DEFAULT_FIRE_OPTIONS: FireDefaults = { bubbles: true, cancelable: true, composed: true };\n\nexport const fire: FireApi = {\n custom<Detail = unknown>(target: EventTarget, type: string, options: CustomEventInit<Detail> = {}) {\n return target.dispatchEvent(new CustomEvent<Detail>(type, { ...DEFAULT_FIRE_OPTIONS, ...options }));\n },\n event(target, event) {\n return target.dispatchEvent(event);\n },\n focus(target, type, options = {}) {\n return target.dispatchEvent(new FocusEvent(type, { ...DEFAULT_FIRE_OPTIONS, ...options }));\n },\n keyboard(target, type, options = {}) {\n return target.dispatchEvent(new KeyboardEvent(type, { ...DEFAULT_FIRE_OPTIONS, ...options }));\n },\n mouse(target, type, options = {}) {\n return target.dispatchEvent(new MouseEvent(type, { ...DEFAULT_FIRE_OPTIONS, ...options }));\n },\n touch(target, type, options = {}) {\n if (typeof TouchEvent !== 'undefined') {\n return target.dispatchEvent(new TouchEvent(type, { ...DEFAULT_FIRE_OPTIONS, ...options }));\n }\n\n return target.dispatchEvent(new CustomEvent(type, { ...DEFAULT_FIRE_OPTIONS, ...options }));\n },\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ID UTILITIES\n// ─────────────────────────────────────────────────────────────────────────────\n\nlet _idCounter = 0;\n\nexport const _resetIdCounter = (): void => {\n _idCounter = 0;\n};\n\nexport const createId = (prefix?: string): string => `${prefix ? `${prefix}-` : 'cft-'}${++_idCounter}`;\n\nexport const CF_ID_ATTR = 'u';\n\nconst ATTR_ID_RE = new RegExp(`${CF_ID_ATTR}=\"([^\"]+)\"`, 'g');\n\nexport const createMarkerIdFactory = (): (() => string) => {\n let n = 0;\n\n return () => String(n++);\n};\n\nexport const rekeyHtmlResult = (result: HTMLResult, getNextId: () => string): { bindings: Binding[]; html: string } => {\n const idMap = new Map<string, string>();\n const getMappedId = (id: string): string => {\n const mapped = idMap.get(id);\n\n if (mapped) return mapped;\n\n const next = getNextId();\n\n idMap.set(id, next);\n\n return next;\n };\n\n return {\n bindings: result.__bindings.map((binding) => ({ ...binding, uid: getMappedId(binding.uid) }) as Binding),\n html: result.__html\n .replace(ATTR_ID_RE, (_, id: string) => `${CF_ID_ATTR}=\"${getMappedId(id)}\"`)\n .replace(/<!--(\\d+)-->/g, (_, id: string) => `<!--${getMappedId(id)}-->`),\n };\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// CSS UTILITIES\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst cssResultToString = function (this: CSSResult): string {\n return this.content;\n};\n\nexport const css = (strings: TemplateStringsArray, ...values: unknown[]): CSSResult => {\n let content = '';\n\n for (let i = 0; i < strings.length; i++) {\n content += strings[i];\n\n if (i < values.length) {\n const v = values[i];\n\n content += isCssResult(v) ? v.content : (v ?? '');\n }\n }\n\n return { __craftitCssResult: true as const, content: content.trim(), toString: cssResultToString };\n};\n\nconst stylesheetStringCache = new Map<string, CSSStyleSheet>();\n\nexport const loadStylesheet = (style: string | CSSStyleSheet | CSSResult): CSSStyleSheet => {\n if (style instanceof CSSStyleSheet) return style;\n\n const cssText = typeof style === 'string' ? style : style.content;\n const cached = stylesheetStringCache.get(cssText);\n\n if (cached) return cached;\n\n const sheet = new CSSStyleSheet();\n\n try {\n sheet.replaceSync(cssText);\n } catch (err) {\n console.error(CRAFTIT_ERRORS.styleReplaceFailed, err);\n }\n\n stylesheetStringCache.set(cssText, sheet);\n\n return sheet;\n};\n"],"mappings":"8FAOA,SAAgB,GAAiC,CAC/C,OAAA,EAAA,EAAA,QAAwB,IAAI,CAC9B,CAIA,SAAgB,GAAmC,CACjD,MAAO,CAAC,CACV,CAgDA,IAAa,EAAqB,GAChC,OAAO,GAAU,YACjB,GACC,EAA2B,qBAAuB,IACnD,OAAQ,EAA2B,OAAU,WAuB/C,SAAgB,EAAW,EAAc,EAAsB,CAAC,EAAe,CAC7E,MAAO,CACL,WAAY,EACZ,oBAAqB,GACrB,OAAQ,EACR,UAAW,CACT,OAAO,CACT,CACF,CACF,CAEA,IAAa,EAAgB,GAC3B,OAAO,GAAU,YAAY,GAAmB,EAAqB,sBAAwB,GAE/F,SAAgB,EAAc,EAA+D,CAC3F,OAAO,OAAO,GAAM,SAAW,CAAE,SAAU,CAAC,EAAG,KAAM,CAAE,EAAI,CAAE,SAAU,EAAE,WAAY,KAAM,EAAE,MAAO,CACtG,CAQA,IAAa,EAAe,GAC1B,OAAO,GAAU,UAAY,CAAC,CAAC,GAAU,EAAoB,qBAAuB,GAMzE,EAAU,GAA8B,CACnD,IAAM,EAAoB,CAAC,EAE3B,IAAK,IAAI,EAAI,EAAI,OAAS,EAAG,GAAK,EAAG,IACnC,GAAI,CACF,EAAI,GAAG,CACT,OAAS,EAAK,CACZ,EAAO,KAAK,CAAG,CACjB,CAGF,GAAI,EAAO,OAAS,EAClB,MAAU,eAAe,EAAQ,EAAA,eAAe,aAAa,CAEjE,EAEa,EAAe,GAAwB,CAClD,IAAK,IAAM,KAAQ,EACjB,EAAoB,OAAO,CAE/B,EAEa,GAAW,EAAa,EAA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