@vielzeug/craftit 1.0.1 → 2.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 +112 -401
- package/dist/core/component.cjs +2 -0
- package/dist/core/component.cjs.map +1 -0
- package/dist/core/component.d.ts +172 -0
- package/dist/core/component.d.ts.map +1 -0
- package/dist/core/component.js +2 -0
- package/dist/core/component.js.map +1 -0
- package/dist/core/host.cjs +2 -0
- package/dist/core/host.cjs.map +1 -0
- package/dist/core/host.d.ts +77 -0
- package/dist/core/host.d.ts.map +1 -0
- package/dist/core/host.js +2 -0
- package/dist/core/host.js.map +1 -0
- package/dist/core/internal.cjs +2 -0
- package/dist/core/internal.cjs.map +1 -0
- package/dist/core/internal.d.ts +107 -0
- package/dist/core/internal.d.ts.map +1 -0
- package/dist/core/internal.js +2 -0
- package/dist/core/internal.js.map +1 -0
- package/dist/core/runtime-bindings.cjs +2 -0
- package/dist/core/runtime-bindings.cjs.map +1 -0
- package/dist/core/runtime-bindings.d.ts +6 -0
- package/dist/core/runtime-bindings.d.ts.map +1 -0
- package/dist/core/runtime-bindings.js +2 -0
- package/dist/core/runtime-bindings.js.map +1 -0
- package/dist/core/runtime-lifecycle.cjs +2 -0
- package/dist/core/runtime-lifecycle.cjs.map +1 -0
- package/dist/core/runtime-lifecycle.d.ts +116 -0
- package/dist/core/runtime-lifecycle.d.ts.map +1 -0
- package/dist/core/runtime-lifecycle.js +2 -0
- package/dist/core/runtime-lifecycle.js.map +1 -0
- package/dist/core/runtime.cjs +1 -0
- package/dist/core/runtime.d.ts +3 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +1 -0
- package/dist/core/template-bindings.cjs +2 -0
- package/dist/core/template-bindings.cjs.map +1 -0
- package/dist/core/template-bindings.d.ts +59 -0
- package/dist/core/template-bindings.d.ts.map +1 -0
- package/dist/core/template-bindings.js +2 -0
- package/dist/core/template-bindings.js.map +1 -0
- package/dist/core/template-compiler.cjs +2 -0
- package/dist/core/template-compiler.cjs.map +1 -0
- package/dist/core/template-compiler.d.ts +25 -0
- package/dist/core/template-compiler.d.ts.map +1 -0
- package/dist/core/template-compiler.js +2 -0
- package/dist/core/template-compiler.js.map +1 -0
- package/dist/core/template-dom.cjs +2 -0
- package/dist/core/template-dom.cjs.map +1 -0
- package/dist/core/template-dom.d.ts +13 -0
- package/dist/core/template-dom.d.ts.map +1 -0
- package/dist/core/template-dom.js +2 -0
- package/dist/core/template-dom.js.map +1 -0
- package/dist/core/template-html.cjs +2 -0
- package/dist/core/template-html.cjs.map +1 -0
- package/dist/core/template-html.d.ts +26 -0
- package/dist/core/template-html.d.ts.map +1 -0
- package/dist/core/template-html.js +2 -0
- package/dist/core/template-html.js.map +1 -0
- package/dist/core/template.cjs +2 -0
- package/dist/core/template.cjs.map +1 -0
- package/dist/core/template.d.ts +11 -0
- package/dist/core/template.d.ts.map +1 -0
- package/dist/core/template.js +2 -0
- package/dist/core/template.js.map +1 -0
- package/dist/core/utilities.cjs +2 -0
- package/dist/core/utilities.cjs.map +1 -0
- package/dist/core/utilities.d.ts +68 -0
- package/dist/core/utilities.d.ts.map +1 -0
- package/dist/core/utilities.js +2 -0
- package/dist/core/utilities.js.map +1 -0
- package/dist/craftit.cjs +2 -18
- package/dist/craftit.cjs.map +1 -1
- package/dist/craftit.js +2 -580
- package/dist/craftit.js.map +1 -1
- package/dist/directives/attr.cjs +2 -0
- package/dist/directives/attr.cjs.map +1 -0
- package/dist/directives/attr.d.ts +14 -0
- package/dist/directives/attr.d.ts.map +1 -0
- package/dist/directives/attr.js +2 -0
- package/dist/directives/attr.js.map +1 -0
- package/dist/directives/bind.cjs +2 -0
- package/dist/directives/bind.cjs.map +1 -0
- package/dist/directives/bind.d.ts +30 -0
- package/dist/directives/bind.d.ts.map +1 -0
- package/dist/directives/bind.js +2 -0
- package/dist/directives/bind.js.map +1 -0
- package/dist/directives/choose.cjs +2 -0
- package/dist/directives/choose.cjs.map +1 -0
- package/dist/directives/choose.d.ts +34 -0
- package/dist/directives/choose.d.ts.map +1 -0
- package/dist/directives/choose.js +2 -0
- package/dist/directives/choose.js.map +1 -0
- package/dist/directives/classes.cjs +2 -0
- package/dist/directives/classes.cjs.map +1 -0
- package/dist/directives/classes.d.ts +20 -0
- package/dist/directives/classes.d.ts.map +1 -0
- package/dist/directives/classes.js +2 -0
- package/dist/directives/classes.js.map +1 -0
- package/dist/directives/each.cjs +2 -0
- package/dist/directives/each.cjs.map +1 -0
- package/dist/directives/each.d.ts +68 -0
- package/dist/directives/each.d.ts.map +1 -0
- package/dist/directives/each.js +2 -0
- package/dist/directives/each.js.map +1 -0
- package/dist/directives/index.cjs +1 -0
- package/dist/directives/index.d.ts +14 -0
- package/dist/directives/index.d.ts.map +1 -0
- package/dist/directives/index.js +1 -0
- package/dist/directives/match.cjs +2 -0
- package/dist/directives/match.cjs.map +1 -0
- package/dist/directives/match.d.ts +31 -0
- package/dist/directives/match.d.ts.map +1 -0
- package/dist/directives/match.js +2 -0
- package/dist/directives/match.js.map +1 -0
- package/dist/directives/memo.cjs +2 -0
- package/dist/directives/memo.cjs.map +1 -0
- package/dist/directives/memo.d.ts +23 -0
- package/dist/directives/memo.d.ts.map +1 -0
- package/dist/directives/memo.js +2 -0
- package/dist/directives/memo.js.map +1 -0
- package/dist/directives/on.cjs +2 -0
- package/dist/directives/on.cjs.map +1 -0
- package/dist/directives/on.d.ts +25 -0
- package/dist/directives/on.d.ts.map +1 -0
- package/dist/directives/on.js +2 -0
- package/dist/directives/on.js.map +1 -0
- package/dist/directives/raw.cjs +2 -0
- package/dist/directives/raw.cjs.map +1 -0
- package/dist/directives/raw.d.ts +25 -0
- package/dist/directives/raw.d.ts.map +1 -0
- package/dist/directives/raw.js +2 -0
- package/dist/directives/raw.js.map +1 -0
- package/dist/directives/spread.cjs +2 -0
- package/dist/directives/spread.cjs.map +1 -0
- package/dist/directives/spread.d.ts +14 -0
- package/dist/directives/spread.d.ts.map +1 -0
- package/dist/directives/spread.js +2 -0
- package/dist/directives/spread.js.map +1 -0
- package/dist/directives/style.cjs +2 -0
- package/dist/directives/style.cjs.map +1 -0
- package/dist/directives/style.d.ts +22 -0
- package/dist/directives/style.d.ts.map +1 -0
- package/dist/directives/style.js +2 -0
- package/dist/directives/style.js.map +1 -0
- package/dist/directives/until.cjs +2 -0
- package/dist/directives/until.cjs.map +1 -0
- package/dist/directives/until.d.ts +26 -0
- package/dist/directives/until.d.ts.map +1 -0
- package/dist/directives/until.js +2 -0
- package/dist/directives/until.js.map +1 -0
- package/dist/directives/when.cjs +2 -0
- package/dist/directives/when.cjs.map +1 -0
- package/dist/directives/when.d.ts +17 -0
- package/dist/directives/when.d.ts.map +1 -0
- package/dist/directives/when.js +2 -0
- package/dist/directives/when.js.map +1 -0
- package/dist/index.cjs +1 -2
- package/dist/index.d.ts +10 -265
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -13
- package/dist/labs/a11y.cjs +2 -0
- package/dist/labs/a11y.cjs.map +1 -0
- package/dist/labs/a11y.d.ts +61 -0
- package/dist/labs/a11y.d.ts.map +1 -0
- package/dist/labs/a11y.js +2 -0
- package/dist/labs/a11y.js.map +1 -0
- package/dist/labs/index.d.ts +8 -0
- package/dist/labs/index.d.ts.map +1 -0
- package/dist/labs/list.cjs +2 -0
- package/dist/labs/list.cjs.map +1 -0
- package/dist/labs/list.d.ts +26 -0
- package/dist/labs/list.d.ts.map +1 -0
- package/dist/labs/list.js +2 -0
- package/dist/labs/list.js.map +1 -0
- package/dist/labs/observers.cjs +2 -0
- package/dist/labs/observers.cjs.map +1 -0
- package/dist/labs/observers.d.ts +42 -0
- package/dist/labs/observers.d.ts.map +1 -0
- package/dist/labs/observers.js +2 -0
- package/dist/labs/observers.js.map +1 -0
- package/dist/labs/overlay.cjs +2 -0
- package/dist/labs/overlay.cjs.map +1 -0
- package/dist/labs/overlay.d.ts +35 -0
- package/dist/labs/overlay.d.ts.map +1 -0
- package/dist/labs/overlay.js +2 -0
- package/dist/labs/overlay.js.map +1 -0
- package/dist/labs/selectable.cjs +2 -0
- package/dist/labs/selectable.cjs.map +1 -0
- package/dist/labs/selectable.d.ts +70 -0
- package/dist/labs/selectable.d.ts.map +1 -0
- package/dist/labs/selectable.js +2 -0
- package/dist/labs/selectable.js.map +1 -0
- package/dist/labs/selection.cjs +2 -0
- package/dist/labs/selection.cjs.map +1 -0
- package/dist/labs/selection.d.ts +68 -0
- package/dist/labs/selection.d.ts.map +1 -0
- package/dist/labs/selection.js +2 -0
- package/dist/labs/selection.js.map +1 -0
- package/dist/labs.cjs +1 -0
- package/dist/labs.js +1 -0
- package/dist/test/index.d.ts +2 -0
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/test.cjs +2 -0
- package/dist/test/test.cjs.map +1 -0
- package/dist/test/test.d.ts +198 -0
- package/dist/test/test.d.ts.map +1 -0
- package/dist/test/test.js +2 -0
- package/dist/test/test.js.map +1 -0
- package/dist/test.cjs +1 -0
- package/dist/test.js +1 -0
- package/package.json +37 -9
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component authoring API — define, props, lifecycle, and form field functionality.
|
|
3
|
+
*
|
|
4
|
+
* - defineComponent: Main API for building typed custom elements
|
|
5
|
+
* - prop/typed/createProps: Reactive property definitions
|
|
6
|
+
* - defineField: Form field integration
|
|
7
|
+
*/
|
|
8
|
+
import { type ComputedSignal, type ReadonlySignal, type Signal } from '@vielzeug/stateit';
|
|
9
|
+
import { type Slots, type ReflectConfig } from './host';
|
|
10
|
+
import { type HTMLResult } from './internal';
|
|
11
|
+
import { type EmitFn, type CSSResult } from './utilities';
|
|
12
|
+
/** @internal */
|
|
13
|
+
export declare const formCallbackRegistry: WeakMap<HTMLElement, FormFieldCallbacks>;
|
|
14
|
+
/** @internal */
|
|
15
|
+
export declare const internalsRegistry: WeakMap<HTMLElement, ElementInternals>;
|
|
16
|
+
/**
|
|
17
|
+
* Callbacks that hook into form lifecycle events. Can be passed directly to {@link defineField}
|
|
18
|
+
* as a second argument to keep all form logic co-located.
|
|
19
|
+
*/
|
|
20
|
+
export type FormFieldCallbacks = {
|
|
21
|
+
onAssociated?: (form: HTMLFormElement | null) => void;
|
|
22
|
+
onDisabled?: (disabled: boolean) => void;
|
|
23
|
+
onReset?: () => void;
|
|
24
|
+
onStateRestore?: (state: unknown, mode: 'autocomplete' | 'restore') => void;
|
|
25
|
+
};
|
|
26
|
+
export type FormFieldOptions<T = unknown> = {
|
|
27
|
+
disabled?: Signal<boolean> | ReadonlySignal<boolean> | ComputedSignal<boolean>;
|
|
28
|
+
toFormValue?: (value: T) => File | FormData | string | null;
|
|
29
|
+
value: Signal<T> | ReadonlySignal<T>;
|
|
30
|
+
};
|
|
31
|
+
export type FormFieldHandle = {
|
|
32
|
+
checkValidity: () => boolean;
|
|
33
|
+
readonly internals: ElementInternals;
|
|
34
|
+
reportValidity: () => boolean;
|
|
35
|
+
setCustomValidity: (message: string) => void;
|
|
36
|
+
setValidity: ElementInternals['setValidity'];
|
|
37
|
+
};
|
|
38
|
+
export declare const defineField: <T = unknown>(options: FormFieldOptions<T>, callbacks?: FormFieldCallbacks) => FormFieldHandle;
|
|
39
|
+
type PropType<T> = T extends string ? StringConstructor : T extends number ? NumberConstructor : T extends boolean ? BooleanConstructor : T extends unknown[] ? ArrayConstructor : ObjectConstructor;
|
|
40
|
+
export type PropOptions<T> = {
|
|
41
|
+
/** When `true`, removes the host attribute instead of setting it to `""` when the value is an empty string. */
|
|
42
|
+
omit?: boolean;
|
|
43
|
+
parse?: (value: string | null) => T;
|
|
44
|
+
reflect?: boolean;
|
|
45
|
+
type?: PropType<T>;
|
|
46
|
+
};
|
|
47
|
+
export type PropDef<T> = PropOptions<T> & {
|
|
48
|
+
default: T;
|
|
49
|
+
};
|
|
50
|
+
export type PropInputDefs = Record<string, unknown | PropDef<unknown>>;
|
|
51
|
+
type PropMeta<T = unknown> = {
|
|
52
|
+
parse: (value: string | null) => T;
|
|
53
|
+
reflect: boolean;
|
|
54
|
+
signal: Signal<T>;
|
|
55
|
+
};
|
|
56
|
+
export declare const propRegistry: WeakMap<object, Map<string, PropMeta<unknown>>>;
|
|
57
|
+
export declare const prop: <T>(name: string, defaultValue: T, options?: PropOptions<T>) => Signal<T>;
|
|
58
|
+
type InferPropValue<T> = T extends object ? Exclude<keyof T, keyof PropDef<unknown>> extends never ? T extends PropDef<infer U> ? U : T : T : T;
|
|
59
|
+
export type InferPropsSignals<T extends PropInputDefs> = {
|
|
60
|
+
[K in keyof T]: Signal<InferPropValue<T[K]>>;
|
|
61
|
+
};
|
|
62
|
+
export declare function createProps<D extends PropInputDefs>(defs: D): InferPropsSignals<D>;
|
|
63
|
+
/**
|
|
64
|
+
* Forces TypeScript to infer the prop signal type from `T` rather than the default
|
|
65
|
+
* value's literal type. Use in `defineComponent({ props: ... })` when the default
|
|
66
|
+
* is `undefined` or when you want an explicit union type.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* defineComponent<ButtonProps>({
|
|
70
|
+
* props: {
|
|
71
|
+
* color: typed<ThemeColor | undefined>(undefined),
|
|
72
|
+
* disabled: { default: false },
|
|
73
|
+
* },
|
|
74
|
+
* setup({ props }) {
|
|
75
|
+
* return html`<button>${props.color}</button>`;
|
|
76
|
+
* },
|
|
77
|
+
* tag: 'x-button',
|
|
78
|
+
* });
|
|
79
|
+
*/
|
|
80
|
+
export declare const typed: <T>(defaultValue: T, options?: PropOptions<T>) => PropDef<T>;
|
|
81
|
+
export type ComponentSetupContext = {
|
|
82
|
+
/** The host `HTMLElement` instance for this component. */
|
|
83
|
+
host: HTMLElement;
|
|
84
|
+
/** Shorthand for `host.shadowRoot` — the component's open shadow root. */
|
|
85
|
+
shadow: ShadowRoot;
|
|
86
|
+
};
|
|
87
|
+
export type ComponentRegistrationOptions = {
|
|
88
|
+
/** Indicates if this should be a form-associated element */
|
|
89
|
+
formAssociated?: boolean;
|
|
90
|
+
/** Custom options for host element (e.g. for aria-*) */
|
|
91
|
+
host?: Record<string, string | boolean | number>;
|
|
92
|
+
/** @internal — list of attribute names to observe via attributeChangedCallback */
|
|
93
|
+
observedAttrs?: string[];
|
|
94
|
+
/** Shadow root init options (mode is always 'open') — use e.g. `{ delegatesFocus: true }` for form controls */
|
|
95
|
+
shadow?: Omit<ShadowRootInit, 'mode'>;
|
|
96
|
+
/** Component styles applied to the shadow root. Static — set at definition time, not per-render. */
|
|
97
|
+
styles?: (string | CSSStyleSheet | CSSResult)[];
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Helper type to build a prop schema from a props interface type.
|
|
101
|
+
* Each property maps to a PropOptions shape with a `default` value.
|
|
102
|
+
*/
|
|
103
|
+
export type BuildPropSchema<T> = {
|
|
104
|
+
[K in keyof T]-?: PropDef<T[K]>;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Unified setup context passed to `defineComponent` setup function.
|
|
108
|
+
* Both Props and Events generics flow through to give full type safety.
|
|
109
|
+
*/
|
|
110
|
+
export type DefineComponentSetupContext<P extends Record<string, PropOptions<any>> = Record<string, never>, E extends Record<string, unknown> = Record<string, never>> = {
|
|
111
|
+
/** Typed emit function — fully inferred from the Events generic */
|
|
112
|
+
emit: EmitFn<E>;
|
|
113
|
+
/** Host element */
|
|
114
|
+
host: HTMLElement;
|
|
115
|
+
/** Reactive props as signals — fully inferred from the Props generic */
|
|
116
|
+
props: InferPropsSignals<P>;
|
|
117
|
+
/** Reflect reactive attributes, events and classes to the host */
|
|
118
|
+
reflect: (config: ReflectConfig) => void;
|
|
119
|
+
/** Shadow root */
|
|
120
|
+
shadow: ShadowRoot;
|
|
121
|
+
/** Slots helper */
|
|
122
|
+
slots: Slots<any>;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Configuration object for `defineComponent()`.
|
|
126
|
+
* Note: no `emits` field — declare events via the Events generic instead.
|
|
127
|
+
*/
|
|
128
|
+
export type DefineComponentOptions<PropsSchema extends Record<string, PropDef<any>> = Record<string, never>, Emits extends Record<string, unknown> = Record<string, never>> = {
|
|
129
|
+
/** Whether this element is form-associated */
|
|
130
|
+
formAssociated?: boolean;
|
|
131
|
+
/** Host element attributes */
|
|
132
|
+
host?: Record<string, string | boolean | number>;
|
|
133
|
+
/** Property definitions */
|
|
134
|
+
props?: PropsSchema;
|
|
135
|
+
/** Setup function — returns a template */
|
|
136
|
+
setup: (ctx: DefineComponentSetupContext<PropsSchema, Emits>) => string | HTMLResult;
|
|
137
|
+
/** Shadow root init options */
|
|
138
|
+
shadow?: Omit<ShadowRootInit, 'mode'>;
|
|
139
|
+
/** Component styles */
|
|
140
|
+
styles?: (string | CSSStyleSheet | CSSResult)[];
|
|
141
|
+
/** Custom element tag name (must include a hyphen) */
|
|
142
|
+
tag: string;
|
|
143
|
+
};
|
|
144
|
+
/** @internal — use `defineComponent` instead. */
|
|
145
|
+
export declare function registerComponent(tag: string, setup: (ctx: ComponentSetupContext) => string | HTMLResult, options?: ComponentRegistrationOptions): string;
|
|
146
|
+
/**
|
|
147
|
+
* Defines a custom element with a cohesive, type-safe API.
|
|
148
|
+
*
|
|
149
|
+
* Pass your Props and Events interfaces as generics — everything in `setup`
|
|
150
|
+
* is fully typed with zero boilerplate.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* type MyProps = { checked?: boolean; disabled?: boolean };
|
|
155
|
+
* type MyEvents = { change: { checked: boolean } };
|
|
156
|
+
*
|
|
157
|
+
* defineComponent<MyProps, MyEvents>({
|
|
158
|
+
* tag: 'my-checkbox',
|
|
159
|
+
* props: {
|
|
160
|
+
* checked: { default: false },
|
|
161
|
+
* disabled: { default: false },
|
|
162
|
+
* },
|
|
163
|
+
* setup({ props, emit }) {
|
|
164
|
+
* // props.checked → Signal<boolean> ✅
|
|
165
|
+
* // emit('change', { checked: true }) ✅
|
|
166
|
+
* },
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function defineComponent<PropsType = Record<string, never>, EventsType extends Record<string, unknown> = Record<string, never>>(options: DefineComponentOptions<BuildPropSchema<PropsType>, EventsType>): string;
|
|
171
|
+
export {};
|
|
172
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/core/component.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,MAAM,EAGZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAe,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;AAErE,OAAO,EAAE,KAAK,UAAU,EAAc,MAAM,YAAY,CAAC;AAMzD,OAAO,EAAgB,KAAK,MAAM,EAA4C,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAMlH,gBAAgB;AAChB,eAAO,MAAM,oBAAoB,0CAAiD,CAAC;AACnF,gBAAgB;AAChB,eAAO,MAAM,iBAAiB,wCAA+C,CAAC;AAE9E;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,KAAK,IAAI,CAAC;IACtD,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IACzC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAC;CAC7E,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,OAAO,IAAI;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,cAAc,CAAC,OAAO,C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,CAAC,EAClE,OAAO,EAAE,sBAAsB,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC,GAAG,MAAM,CA2BjF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{htmlResult as e}from"./internal.js";import{currentRuntime as t,runtimeStack as n}from"./runtime-lifecycle.js";import{createEmitFn as r,loadStylesheet as i,runAll as a,setAttr as o,toKebab as s}from"./utilities.js";import{createSlots as c,reflect as l}from"./host.js";import{parseHTML as u}from"./template-dom.js";import"./template-bindings.js";import"./template-html.js";import{applyBindingsInContainer as d,applyHtmlBinding as f}from"./template.js";import{effect as p,signal as m}from"@vielzeug/stateit";var h=new WeakMap,g=new WeakMap,_=(e,n)=>{let r=t().el;if(!r.constructor.formAssociated)throw Error(`[craftit:E8] defineField() requires defineComponent({ formAssociated: true })`);let i=g.get(r)??r.attachInternals();g.set(r,i);let a=e.toFormValue??(e=>e==null?``:String(e));return p(()=>{i.setFormValue(a(e.value.value))}),e.disabled&&p(()=>{e.disabled.value?i.states.add(`disabled`):i.states.delete(`disabled`)}),n&&h.set(r,{...h.get(r),...n}),{checkValidity:()=>i.checkValidity(),internals:i,reportValidity:()=>i.reportValidity(),setCustomValidity:e=>e?i.setValidity({customError:!0},e):i.setValidity({}),setValidity:i.setValidity.bind(i)}},v=new Set([`default`,`omit`,`parse`,`reflect`,`type`]),y=e=>typeof e!=`object`||!e||!(`default`in e)?!1:Object.keys(e).every(e=>v.has(e)),b=new WeakMap,x=(e,n,r)=>{let i=t(),a=i.el;b.has(a)||b.set(a,new Map);let s=r?.parse??(e=>r?.type===Boolean?e===``||e===`true`:typeof n==`boolean`?e!==null&&e!==`false`:e==null?n:r?.type===Number||typeof n==`number`?Number(e):e),c=m(n),l=Object.prototype.hasOwnProperty.call(a,e),u=l?a[e]:void 0,d={parse:s,reflect:r?.reflect??!0,signal:c};if(l?(delete a[e],c.value=u):a.hasAttribute(e)&&(c.value=s(a.getAttribute(e))),b.get(a).set(e,d),Object.defineProperty(a,e,{configurable:!0,enumerable:!0,get:()=>c.value,set:e=>{c.value=e}}),r?.reflect??!0){let t=r?.omit??!1;i.onMount.push(()=>{i.cleanups.push(p(()=>{let n=c.value;n==null||n===!1||t&&n===``?a.removeAttribute(e):o(a,e,n)}))})}return c};function S(e){let t={};for(let[n,r]of Object.entries(e)){let e=y(r)?r:{default:r},i={reflect:!(typeof e.default==`object`&&e.default!==null||Array.isArray(e.default)),...e};t[n]=x(s(n),e.default,i)}return t}var C=(e,t)=>({...t,default:e}),w=class extends HTMLElement{static _setup;static _options;static formAssociated=!1;static observedAttributes=[];shadow;_keyedStates=new Map;_mountFns=[];_template=null;_appliedHtmlBindings=new Set;_setupDone=!1;_runtime;constructor(){super();let e=this.constructor._options;this.shadow=this.attachShadow({mode:`open`,...e?.shadow}),this._runtime={cleanups:[],el:this,errorHandlers:[],onMount:[],styles:e?.styles}}connectedCallback(){this._setupDone||this._runSetup(),this._init()}attributeChangedCallback(e,t,n){if(t===n)return;let r=b.get(this)?.get(e);if(!r)return;let i=r.parse(n);Object.is(r.signal.peek(),i)||(r.signal.value=i)}disconnectedCallback(){a(this._runtime.cleanups),this._runtime.cleanups=[],this._runtime.onMount=this._mountFns.slice(),this._appliedHtmlBindings.clear(),this._keyedStates.clear()}formAssociatedCallback(e){h.get(this)?.onAssociated?.(e)}formDisabledCallback(e){h.get(this)?.onDisabled?.(e)}formResetCallback(){h.get(this)?.onReset?.()}formStateRestoreCallback(e,t){h.get(this)?.onStateRestore?.(e,t)}_handleError(e){if(this._runtime.errorHandlers.length>0)for(let t of this._runtime.errorHandlers)t(e);else console.error(`[craftit:E3] <${this.localName}>`,e)}_runSetup(){this._setupDone=!0,n.push(this._runtime);try{let{host:e}=this.constructor._options??{};if(e)for(let[t,n]of Object.entries(e))typeof n==`boolean`?n?this.setAttribute(t,``):this.removeAttribute(t):this.setAttribute(t,String(n));let t=this.constructor._setup({host:this,shadow:this.shadow});(typeof t==`string`||typeof t==`object`&&t&&`__html`in t)&&(this._template=t)}catch(e){this._handleError(e)}finally{n.pop()}}_init(){let{styles:t}=this._runtime;if(t?.length&&(this.shadow.adoptedStyleSheets=t.map(i)),this._template){let t=typeof this._template==`string`?e(this._template):this._template;if(this.shadow.replaceChildren(u(t.__html)),t.__bindings.length){let e=e=>this._runtime.cleanups.push(e);d(this.shadow,t.__bindings,e,{onHtml:t=>{this._appliedHtmlBindings.has(t.uid)||(this._appliedHtmlBindings.add(t.uid),f(this.shadow,t,e,this._keyedStates))}})}}queueMicrotask(()=>{n.push(this._runtime);try{let e=this._runtime.onMount;this._mountFns=e.slice();for(let t of e){let e=t();typeof e==`function`&&this._runtime.cleanups.push(e)}}catch(e){this._handleError(e)}finally{n.pop(),this._runtime.onMount=[]}})}};function T(e,t,n={}){if(!e)throw Error(`[craftit:E4] registerComponent(tag, ...) requires a tag name`);if(customElements.get(e))throw Error(`[craftit:E9] custom element already defined: ${e}`);class r extends w{static _setup=t;static _options=n;static formAssociated=n.formAssociated??!1;static observedAttributes=n.observedAttrs??[]}return customElements.define(e,r),e}function E(e){let{formAssociated:t,host:n,props:i,setup:a,shadow:o,styles:u,tag:d}=e;return T(d,e=>{let t=i?S(i):{},n=r(),o=c();return a({emit:n,host:e.host,props:t,reflect:t=>l(e.host,t),shadow:e.shadow,slots:o})},{formAssociated:t,host:n,observedAttrs:i?Object.keys(i).map(s):[],shadow:o,styles:u})}export{E as defineComponent,_ as defineField,x as prop,b as propRegistry,C as typed};
|
|
2
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","names":[],"sources":["../../src/core/component.ts"],"sourcesContent":["/**\n * Component authoring API — define, props, lifecycle, and form field functionality.\n *\n * - defineComponent: Main API for building typed custom elements\n * - prop/typed/createProps: Reactive property definitions\n * - defineField: Form field integration\n */\n\nimport {\n type CleanupFn,\n type ComputedSignal,\n type ReadonlySignal,\n type Signal,\n signal,\n effect,\n} from '@vielzeug/stateit';\n\nimport { createSlots, type Slots, type ReflectConfig } from './host';\nimport { reflect } from './host';\nimport { type HTMLResult, htmlResult } from './internal';\nimport { currentRuntime, runtimeStack } from './runtime-lifecycle';\nimport { applyBindingsInContainer, applyHtmlBinding } from './template';\nimport { type RegisterCleanup } from './template-bindings';\nimport { parseHTML } from './template-dom';\nimport { type KeyedNode } from './template-html';\nimport { createEmitFn, type EmitFn, setAttr, toKebab, runAll, loadStylesheet, type CSSResult } from './utilities';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// FORM FIELD API\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** @internal */\nexport const formCallbackRegistry = new WeakMap<HTMLElement, FormFieldCallbacks>();\n/** @internal */\nexport const internalsRegistry = new WeakMap<HTMLElement, ElementInternals>();\n\n/**\n * Callbacks that hook into form lifecycle events. Can be passed directly to {@link defineField}\n * as a second argument to keep all form logic co-located.\n */\nexport type FormFieldCallbacks = {\n onAssociated?: (form: HTMLFormElement | null) => void;\n onDisabled?: (disabled: boolean) => void;\n onReset?: () => void;\n onStateRestore?: (state: unknown, mode: 'autocomplete' | 'restore') => void;\n};\n\nexport type FormFieldOptions<T = unknown> = {\n disabled?: Signal<boolean> | ReadonlySignal<boolean> | ComputedSignal<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>(\n options: FormFieldOptions<T>,\n callbacks?: FormFieldCallbacks,\n): FormFieldHandle => {\n const rt = currentRuntime();\n const host = rt.el;\n const ctor = host.constructor as typeof HTMLElement & { formAssociated?: boolean };\n\n if (!ctor.formAssociated) {\n throw new Error('[craftit:E8] defineField() requires defineComponent({ formAssociated: true })');\n }\n\n const internals = internalsRegistry.get(host) ?? host.attachInternals();\n\n internalsRegistry.set(host, internals);\n\n const toFormValue = options.toFormValue ?? ((v: T) => (v == null ? '' : String(v)));\n\n effect(() => {\n internals.setFormValue(toFormValue(options.value.value));\n });\n\n if (options.disabled) {\n effect(() => {\n if (options.disabled!.value) {\n internals.states.add('disabled');\n } else {\n internals.states.delete('disabled');\n }\n });\n }\n\n if (callbacks) {\n formCallbackRegistry.set(host, { ...formCallbackRegistry.get(host), ...callbacks });\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\n// ─────────────────────────────────────────────────────────────────────────────\n// PROP SYSTEM\n// ─────────────────────────────────────────────────────────────────────────────\n\ntype PropType<T> = T extends string\n ? StringConstructor\n : T extends number\n ? NumberConstructor\n : T extends boolean\n ? BooleanConstructor\n : T extends unknown[]\n ? ArrayConstructor\n : ObjectConstructor;\n\nexport type PropOptions<T> = {\n /** When `true`, removes the host attribute instead of setting it to `\"\"` when the value is an empty string. */\n omit?: boolean;\n parse?: (value: string | null) => T;\n reflect?: boolean;\n type?: PropType<T>;\n};\n\nexport type PropDef<T> = PropOptions<T> & { default: T };\nexport type PropInputDefs = Record<string, unknown | PropDef<unknown>>;\n\ntype PropMeta<T = unknown> = {\n parse: (value: string | null) => T;\n reflect: boolean;\n signal: Signal<T>;\n};\n\nconst PROP_DEF_KEYS = new Set(['default', 'omit', 'parse', 'reflect', 'type']);\nconst isPropDef = (value: unknown): value is PropDef<unknown> => {\n if (typeof value !== 'object' || value === null || !('default' in value)) return false;\n\n return Object.keys(value).every((key) => PROP_DEF_KEYS.has(key));\n};\n\nexport const propRegistry = new WeakMap<object, Map<string, PropMeta<unknown>>>();\n\nexport const prop = <T>(name: string, defaultValue: T, options?: PropOptions<T>): Signal<T> => {\n const rt = currentRuntime();\n const el = rt.el;\n\n if (!propRegistry.has(el)) propRegistry.set(el, new Map());\n\n const parse =\n options?.parse ??\n ((v: string | null): T => {\n // Explicit Boolean type: string values 'true' / '' → boolean\n if (options?.type === Boolean) return (v === '' || v === 'true') as T;\n\n // Boolean default: treat absent or explicit \"false\" as false, anything else as true.\n // This handles frameworks (e.g. Vue) that set the attribute to the string \"false\"\n // when a reactive binding evaluates to false, rather than removing the attribute.\n if (typeof defaultValue === 'boolean') return (v !== null && v !== 'false') as T;\n\n if (v == null) return defaultValue;\n\n // Numeric — inferred from an explicit type option or default value type\n if (options?.type === Number || typeof defaultValue === 'number') return Number(v) as T;\n\n return v as unknown as T;\n });\n const s = signal<T>(defaultValue);\n const hasPreUpgradeProperty = Object.prototype.hasOwnProperty.call(el, name);\n const preUpgradeValue = hasPreUpgradeProperty ? (el as unknown as Record<string, unknown>)[name] : undefined;\n\n const meta = {\n parse,\n reflect: options?.reflect ?? true,\n signal: s as Signal<unknown>,\n };\n\n // Prefer pre-upgrade property values set before defineProperty() (common for\n // framework/host property bindings), then fall back to attributes.\n if (hasPreUpgradeProperty) {\n delete (el as unknown as Record<string, unknown>)[name];\n s.value = preUpgradeValue as T;\n } else if (el.hasAttribute(name)) {\n s.value = parse(el.getAttribute(name)) as T;\n }\n\n propRegistry.get(el)!.set(name, meta);\n\n Object.defineProperty(el, name, {\n configurable: true,\n enumerable: true,\n get: () => s.value,\n set: (value: T) => {\n s.value = value;\n },\n });\n\n if (options?.reflect ?? true) {\n const omit = options?.omit ?? false;\n\n rt.onMount.push(() => {\n rt.cleanups.push(\n effect(() => {\n const v = s.value;\n\n if (v == null || v === false || (omit && v === '')) {\n el.removeAttribute(name);\n } else {\n setAttr(el, name, v);\n }\n }),\n );\n });\n }\n\n return s;\n};\n\ntype InferPropValue<T> = T extends object\n ? Exclude<keyof T, keyof PropDef<unknown>> extends never\n ? T extends PropDef<infer U>\n ? U\n : T\n : T\n : T;\n\nexport type InferPropsSignals<T extends PropInputDefs> = {\n [K in keyof T]: Signal<InferPropValue<T[K]>>;\n};\n\nexport function createProps<D extends PropInputDefs>(defs: D): InferPropsSignals<D> {\n const result = {} as Record<string, Signal<unknown>>;\n\n for (const [name, def] of Object.entries(defs)) {\n const descriptor = isPropDef(def) ? (def as PropDef<unknown>) : { default: def };\n const hasStructuredDefault =\n (typeof descriptor.default === 'object' && descriptor.default !== null) || Array.isArray(descriptor.default);\n const propDef: PropOptions<unknown> = { reflect: !hasStructuredDefault, ...descriptor };\n\n result[name] = prop(toKebab(name), descriptor.default, propDef);\n }\n\n return result as InferPropsSignals<D>;\n}\n\n/**\n * Forces TypeScript to infer the prop signal type from `T` rather than the default\n * value's literal type. Use in `defineComponent({ props: ... })` when the default\n * is `undefined` or when you want an explicit union type.\n *\n * @example\n * defineComponent<ButtonProps>({\n * props: {\n * color: typed<ThemeColor | undefined>(undefined),\n * disabled: { default: false },\n * },\n * setup({ props }) {\n * return html`<button>${props.color}</button>`;\n * },\n * tag: 'x-button',\n * });\n */\nexport const typed = <T>(defaultValue: T, options?: PropOptions<T>): PropDef<T> => ({\n ...options,\n default: defaultValue,\n});\n\n// ─────────────────────────────────────────────────────────────────────────────\n// COMPONENT SETUP & REGISTRATION\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport type ComponentSetupContext = {\n /** The host `HTMLElement` instance for this component. */\n host: HTMLElement;\n /** Shorthand for `host.shadowRoot` — the component's open shadow root. */\n shadow: ShadowRoot;\n};\n\nexport type ComponentRegistrationOptions = {\n /** Indicates if this should be a form-associated element */\n formAssociated?: boolean;\n /** Custom options for host element (e.g. for aria-*) */\n host?: Record<string, string | boolean | number>;\n /** @internal — list of attribute names to observe via attributeChangedCallback */\n observedAttrs?: string[];\n /** Shadow root init options (mode is always 'open') — use e.g. `{ delegatesFocus: true }` for form controls */\n shadow?: Omit<ShadowRootInit, 'mode'>;\n /** Component styles applied to the shadow root. Static — set at definition time, not per-render. */\n styles?: (string | CSSStyleSheet | CSSResult)[];\n};\n\n/**\n * Helper type to build a prop schema from a props interface type.\n * Each property maps to a PropOptions shape with a `default` value.\n */\nexport type BuildPropSchema<T> = {\n [K in keyof T]-?: PropDef<T[K]>;\n};\n\n/**\n * Unified setup context passed to `defineComponent` setup function.\n * Both Props and Events generics flow through to give full type safety.\n */\nexport type DefineComponentSetupContext<\n P extends Record<string, PropOptions<any>> = Record<string, never>,\n E extends Record<string, unknown> = Record<string, never>,\n> = {\n /** Typed emit function — fully inferred from the Events generic */\n emit: EmitFn<E>;\n /** Host element */\n host: HTMLElement;\n /** Reactive props as signals — fully inferred from the Props generic */\n props: InferPropsSignals<P>;\n /** Reflect reactive attributes, events and classes to the host */\n reflect: (config: ReflectConfig) => void;\n /** Shadow root */\n shadow: ShadowRoot;\n /** Slots helper */\n slots: Slots<any>;\n};\n\n/**\n * Configuration object for `defineComponent()`.\n * Note: no `emits` field — declare events via the Events generic instead.\n */\nexport type DefineComponentOptions<\n PropsSchema extends Record<string, PropDef<any>> = Record<string, never>,\n Emits extends Record<string, unknown> = Record<string, never>,\n> = {\n /** Whether this element is form-associated */\n formAssociated?: boolean;\n /** Host element attributes */\n host?: Record<string, string | boolean | number>;\n /** Property definitions */\n props?: PropsSchema;\n /** Setup function — returns a template */\n setup: (ctx: DefineComponentSetupContext<PropsSchema, Emits>) => string | HTMLResult;\n /** Shadow root init options */\n shadow?: Omit<ShadowRootInit, 'mode'>;\n /** Component styles */\n styles?: (string | CSSStyleSheet | CSSResult)[];\n /** Custom element tag name (must include a hyphen) */\n tag: string;\n};\n\n// ─── Base custom element ──────────────────────────────────────────────────────\n\ntype ComponentRuntime = {\n cleanups: CleanupFn[];\n el: HTMLElement;\n errorHandlers: Array<(err: unknown) => void>;\n onMount: Array<() => CleanupFn | undefined | void>;\n styles?: (string | CSSStyleSheet | CSSResult)[];\n};\n\n// Lifecycle methods (connectedCallback, attributeChangedCallback, …) are invoked\n// by the browser runtime, not TypeScript code — suppress false-positive lint warnings.\n\nclass BaseElement extends HTMLElement {\n static _setup: (ctx: ComponentSetupContext) => string | HTMLResult;\n static _options?: ComponentRegistrationOptions;\n static formAssociated = false;\n static observedAttributes: string[] = [];\n\n shadow: ShadowRoot;\n private _keyedStates = new Map<string, Map<string | number, KeyedNode>>();\n private _mountFns: (() => CleanupFn | undefined | void)[] = [];\n private _template: string | HTMLResult | null = null;\n private _appliedHtmlBindings = new Set<string>();\n private _setupDone = false;\n private _runtime: ComponentRuntime;\n\n constructor() {\n super();\n\n const options = (this.constructor as typeof BaseElement)._options;\n\n this.shadow = this.attachShadow({ mode: 'open', ...options?.shadow });\n this._runtime = {\n cleanups: [],\n el: this,\n errorHandlers: [],\n onMount: [],\n styles: options?.styles,\n };\n }\n\n connectedCallback(): void {\n if (!this._setupDone) this._runSetup();\n\n this._init();\n }\n\n // Fires synchronously on observed attribute change — no MutationObserver needed.\n // observedAttributes is set at class-definition time from the prop schema.\n attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void {\n if (oldValue === newValue) return;\n\n const meta = propRegistry.get(this)?.get(name);\n\n if (!meta) return;\n\n const parsed = meta.parse(newValue);\n\n if (!Object.is(meta.signal.peek(), parsed)) meta.signal.value = parsed as never;\n }\n\n disconnectedCallback(): void {\n runAll(this._runtime.cleanups);\n this._runtime.cleanups = [];\n this._runtime.onMount = this._mountFns.slice(); // restore for reconnect\n this._appliedHtmlBindings.clear();\n this._keyedStates.clear();\n }\n\n formAssociatedCallback(form: HTMLFormElement | null): void {\n formCallbackRegistry.get(this)?.onAssociated?.(form);\n }\n\n formDisabledCallback(disabled: boolean): void {\n formCallbackRegistry.get(this)?.onDisabled?.(disabled);\n }\n\n formResetCallback(): void {\n formCallbackRegistry.get(this)?.onReset?.();\n }\n\n formStateRestoreCallback(state: unknown, mode: 'autocomplete' | 'restore'): void {\n formCallbackRegistry.get(this)?.onStateRestore?.(state, mode);\n }\n\n private _handleError(err: unknown): void {\n if (this._runtime.errorHandlers.length > 0) {\n for (const fn of this._runtime.errorHandlers) fn(err);\n } else {\n console.error(`[craftit:E3] <${this.localName}>`, err);\n }\n }\n\n private _runSetup(): void {\n this._setupDone = true;\n runtimeStack.push(this._runtime as any);\n\n try {\n const { host: hostOptions } = (this.constructor as typeof BaseElement)._options ?? {};\n\n if (hostOptions) {\n for (const [name, value] of Object.entries(hostOptions)) {\n if (typeof value === 'boolean') {\n if (value) {\n this.setAttribute(name, '');\n } else {\n this.removeAttribute(name);\n }\n } else {\n this.setAttribute(name, String(value));\n }\n }\n }\n\n const res = (this.constructor as typeof BaseElement)._setup({ host: this, shadow: this.shadow });\n\n if (typeof res === 'string' || (typeof res === 'object' && res !== null && '__html' in res)) {\n this._template = res as string | HTMLResult;\n }\n } catch (err) {\n this._handleError(err);\n } finally {\n runtimeStack.pop();\n }\n }\n\n private _init(): void {\n const { styles } = this._runtime;\n\n // Apply styles synchronously before rendering to prevent FOUC.\n if (styles?.length) this.shadow.adoptedStyleSheets = styles.map(loadStylesheet);\n\n if (this._template) {\n const result: HTMLResult = typeof this._template === 'string' ? htmlResult(this._template) : this._template;\n\n this.shadow.replaceChildren(parseHTML(result.__html));\n\n if (result.__bindings.length) {\n const registerCleanup: RegisterCleanup = (fn) => this._runtime.cleanups.push(fn);\n\n applyBindingsInContainer(this.shadow, result.__bindings, registerCleanup, {\n onHtml: (b) => {\n if (!this._appliedHtmlBindings.has(b.uid)) {\n this._appliedHtmlBindings.add(b.uid);\n applyHtmlBinding(this.shadow, b, registerCleanup, this._keyedStates);\n }\n },\n });\n }\n }\n\n // Defer onMount callbacks to a microtask for deterministic timing.\n // Components that depend on layout/paint should schedule rAF inside onMount.\n queueMicrotask(() => {\n runtimeStack.push(this._runtime as any);\n\n try {\n const fns = this._runtime.onMount;\n\n this._mountFns = fns.slice(); // snapshot for reconnect\n\n for (const fn of fns) {\n const cleanup = fn();\n\n if (typeof cleanup === 'function') this._runtime.cleanups.push(cleanup);\n }\n } catch (err) {\n this._handleError(err);\n } finally {\n runtimeStack.pop();\n this._runtime.onMount = [];\n }\n });\n }\n}\n\n// ─── Component registration ───────────────────────────────────────────────────\n\n/** @internal — use `defineComponent` instead. */\nexport function registerComponent(\n tag: string,\n setup: (ctx: ComponentSetupContext) => string | HTMLResult,\n options: ComponentRegistrationOptions = {},\n): string {\n if (!tag) throw new Error('[craftit:E4] registerComponent(tag, ...) requires a tag name');\n\n if (customElements.get(tag)) {\n throw new Error(`[craftit:E9] custom element already defined: ${tag}`);\n }\n\n class Element extends BaseElement {\n static override _setup = setup;\n static override _options = options;\n static override formAssociated = options.formAssociated ?? false;\n static override observedAttributes = options.observedAttrs ?? [];\n }\n\n customElements.define(tag, Element);\n\n return tag;\n}\n\n/**\n * Defines a custom element with a cohesive, type-safe API.\n *\n * Pass your Props and Events interfaces as generics — everything in `setup`\n * is fully typed with zero boilerplate.\n *\n * @example\n * ```ts\n * type MyProps = { checked?: boolean; disabled?: boolean };\n * type MyEvents = { change: { checked: boolean } };\n *\n * defineComponent<MyProps, MyEvents>({\n * tag: 'my-checkbox',\n * props: {\n * checked: { default: false },\n * disabled: { default: false },\n * },\n * setup({ props, emit }) {\n * // props.checked → Signal<boolean> ✅\n * // emit('change', { checked: true }) ✅\n * },\n * });\n * ```\n */\nexport function defineComponent<\n PropsType = Record<string, never>,\n EventsType extends Record<string, unknown> = Record<string, never>,\n>(options: DefineComponentOptions<BuildPropSchema<PropsType>, EventsType>): string {\n const { formAssociated, host: hostOptions, props: propDefs, setup, shadow: shadowOptions, styles, tag } = options;\n\n // Derive observed attribute names from prop schema at definition time so\n // attributeChangedCallback fires correctly — no MutationObserver needed.\n const observedAttrs = propDefs ? Object.keys(propDefs).map(toKebab) : [];\n\n return registerComponent(\n tag,\n (ctx) => {\n const props = propDefs\n ? createProps(propDefs as BuildPropSchema<PropsType>)\n : ({} as InferPropsSignals<BuildPropSchema<PropsType>>);\n const emit = createEmitFn<EventsType>();\n const slots = createSlots<any>();\n\n return setup({\n emit: emit as EmitFn<EventsType>,\n host: ctx.host,\n props,\n reflect: (config: ReflectConfig) => reflect(ctx.host, config),\n shadow: ctx.shadow,\n slots,\n } as DefineComponentSetupContext<BuildPropSchema<PropsType>, EventsType>);\n },\n { formAssociated, host: hostOptions, observedAttrs, shadow: shadowOptions, styles },\n );\n}\n"],"mappings":"ggBAgCA,IAAa,EAAuB,IAAI,QAE3B,EAAoB,IAAI,QA2BxB,GACX,EACA,IACoB,CAEpB,IAAM,EADK,GAAgB,CACX,GAGhB,GAAI,CAFS,EAAK,YAER,eACR,MAAU,MAAM,gFAAgF,CAGlG,IAAM,EAAY,EAAkB,IAAI,EAAK,EAAI,EAAK,iBAAiB,CAEvE,EAAkB,IAAI,EAAM,EAAU,CAEtC,IAAM,EAAc,EAAQ,cAAiB,GAAU,GAAK,KAAO,GAAK,OAAO,EAAE,EAyBjF,OAvBA,MAAa,CACX,EAAU,aAAa,EAAY,EAAQ,MAAM,MAAM,CAAC,EACxD,CAEE,EAAQ,UACV,MAAa,CACP,EAAQ,SAAU,MACpB,EAAU,OAAO,IAAI,WAAW,CAEhC,EAAU,OAAO,OAAO,WAAW,EAErC,CAGA,GACF,EAAqB,IAAI,EAAM,CAAE,GAAG,EAAqB,IAAI,EAAK,CAAE,GAAG,EAAW,CAAC,CAQ9E,CACL,kBAN0B,EAAU,eAAe,CAOnD,YACA,mBAP2B,EAAU,gBAAgB,CAQrD,kBAPyB,GACzB,EAAU,EAAU,YAAY,CAAE,YAAa,GAAM,CAAE,EAAQ,CAAG,EAAU,YAAY,EAAE,CAAC,CAO3F,YAAa,EAAU,YAAY,KAAK,EAAU,CACnD,EAkCG,EAAgB,IAAI,IAAI,CAAC,UAAW,OAAQ,QAAS,UAAW,OAAO,CAAC,CACxE,EAAa,GACb,OAAO,GAAU,WAAY,GAAkB,EAAE,YAAa,GAAe,GAE1E,OAAO,KAAK,EAAM,CAAC,MAAO,GAAQ,EAAc,IAAI,EAAI,CAAC,CAGrD,EAAe,IAAI,QAEnB,GAAW,EAAc,EAAiB,IAAwC,CAC7F,IAAM,EAAK,GAAgB,CACrB,EAAK,EAAG,GAET,EAAa,IAAI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BjB,EAAW,OAAO,KAAK,EAAS,CAAC,IAAI,EAAQ,CAAG,EAAE,CAoBlB,OAAQ,EAAe,SAAQ,CACpF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`./runtime-lifecycle.cjs`),t=require(`./utilities.cjs`);let n=require(`@vielzeug/stateit`);var r=new WeakMap,i=(t,n)=>{let i=e.currentRuntime().el;r.has(i)||r.set(i,new Map),r.get(i).set(t,n)};function a(t,...n){let i=e.currentRuntime().el;for(;i;){if(i instanceof HTMLElement){let e=r.get(i)?.get(t);if(e!==void 0)return e}let e=i.getRootNode();i=i.parentElement??(e instanceof ShadowRoot?e.host:null)}return n.length>0?n[0]:void 0}function o(e){return Symbol(e)}var s=(t,n,r)=>{t&&e.onMount(()=>{e.effect(()=>{for(let e of r){let r=t[e]?.value;r!==void 0&&(n[e].value=r)}})})},c=new Set,l=(e,t,n)=>{let r=`${n}:${e.localName}:${t||`default`}`;c.has(r)||(c.add(r),console.warn(`[craftit:E10] ${n} could not find a matching <slot${t?` name="${t}"`:``}> in <${e.localName}>. Render the slot before using ${n}.`))},u=(t,n)=>{let r=e.currentRuntime().el,i=t===`default`?``:t,a=i?`slot[name="${i}"]`:`slot:not([name])`,o=r.shadowRoot?.querySelector(a);if(!o){l(r,i,`onSlotChange()`);return}let s=()=>n(o.assignedElements({flatten:!0}));s(),o.addEventListener(`slotchange`,s),e.onCleanup(()=>o.removeEventListener(`slotchange`,s))},d=()=>{let t=e.currentRuntime().el,r=new Map,i=i=>{if(r.has(i))return r.get(i);let a=(0,n.signal)(!1);return r.set(i,a),e.onMount(()=>{let e=i?`slot[name="${i}"]`:`slot:not([name])`,n=t.shadowRoot?.querySelector(e);if(!n){l(t,i,`slots.has()`);return}let r=()=>{a.value=n.assignedNodes().length>0};return r(),n.addEventListener(`slotchange`,r),()=>n.removeEventListener(`slotchange`,r)}),a};return{has(e){return i(e===`default`?``:String(e))}}};function f(t,n){for(let[r,i]of Object.entries(n))if(r===`classMap`)m(t,i);else if(r.startsWith(`on`)&&r.length>2&&typeof i==`function`){let n=r.slice(2);e.handle(t,n[0].toLowerCase()+n.slice(1),i)}else p(t,r,i)}function p(n,r,i){typeof i==`function`?e.effect(()=>t.setAttr(n,r,i())):t.setAttr(n,r,i)}function m(t,n){let r=new Set;e.effect(()=>{let e=new Set(Object.entries(n()).filter(([,e])=>e).map(([e])=>e));for(let n of r)e.has(n)||t.classList.remove(n);for(let n of e)r.has(n)||t.classList.add(n);r=e})}exports.createContext=o,exports.createSlots=d,exports.inject=a,exports.onSlotChange=u,exports.provide=i,exports.reflect=f,exports.syncContextProps=s;
|
|
2
|
+
//# sourceMappingURL=host.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.cjs","names":[],"sources":["../../src/core/host.ts"],"sourcesContent":["/**\n * Host utilities — component context injection, slot observation, and attribute/class reflection.\n *\n * - Context API (provide, inject, createContext, syncContextProps)\n * - Slot observation and detection (Slots type, createSlots, onSlotChange)\n * - Host element binding (reflect) for attributes, events, and classes\n */\n\nimport { type ReadonlySignal, type Signal, signal } from '@vielzeug/stateit';\n\n// Use the wrapped effect from runtime-lifecycle so reactive bindings are\n// automatically cleaned up on unmount — raw stateit effect has no lifecycle awareness.\nimport { currentRuntime, effect, handle, onCleanup, onMount } from './runtime-lifecycle';\nimport { setAttr } from './utilities';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// CONTEXT API\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst contextRegistry = new WeakMap<HTMLElement, Map<InjectionKey<unknown> | string | symbol, unknown>>();\n\nexport type InjectionKey<T> = symbol & {\n readonly __craftit_injection_key?: T;\n};\n\nexport const provide = <T>(key: InjectionKey<T> | string | symbol, value: T): void => {\n const el = currentRuntime().el;\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> | string | symbol): T | undefined;\nexport function inject<T>(key: InjectionKey<T> | string | symbol, fallback: T): T;\nexport function inject<T>(key: InjectionKey<T> | string | symbol, ...rest: [T?]): T | undefined {\n let node: Node | null = currentRuntime().el;\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 function createContext<T>(description?: string): InjectionKey<T> {\n return Symbol(description) as InjectionKey<T>;\n}\n\n/**\n * Reactively inherits prop values from a context object provided by an ancestor component.\n * For each key, when the context value is not `undefined`, it is written into the matching prop signal.\n * The effect is automatically cleaned up when the component unmounts.\n *\n * Deferred to `onMount` so context values win over HTML attribute values set on the child.\n *\n * @example\n * syncContextProps(inject(BUTTON_GROUP_CTX), props, ['color', 'size', 'variant']);\n */\nexport const syncContextProps = <\n K extends string,\n Ctx extends Partial<Record<K, ReadonlySignal<unknown>>>,\n Props extends Record<K, Signal<unknown>>,\n>(\n ctx: Ctx | undefined,\n props: Props,\n keys: K[],\n): void => {\n if (!ctx) return;\n\n onMount(() => {\n effect(() => {\n for (const k of keys) {\n const v = ctx[k]?.value;\n\n if (v !== undefined) props[k].value = v;\n }\n });\n });\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// SLOTS API\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst missingSlotWarnings = new Set<string>();\n\nconst warnMissingSlot = (el: HTMLElement, slotName: string, source: 'onSlotChange()' | 'slots.has()'): void => {\n const key = `${source}:${el.localName}:${slotName || 'default'}`;\n\n if (missingSlotWarnings.has(key)) return;\n\n missingSlotWarnings.add(key);\n console.warn(\n `[craftit:E10] ${source} could not find a matching <slot${slotName ? ` name=\"${slotName}\"` : ''}> in <${el.localName}>. Render the slot before using ${source}.`,\n );\n};\n\nexport type Slots<T extends Record<string, unknown> = Record<string, unknown>> = {\n /**\n * Returns a `ReadonlySignal<boolean>` that is `true` when the slot has assigned content.\n * Reactive — use the signal directly in templates, computed(), or effects.\n * @example const hasIcon = slots.has('icon'); // ReadonlySignal<boolean>\n */\n has(name: keyof T): ReadonlySignal<boolean>;\n};\n\n/**\n * Observes a slot and calls `callback` with assigned elements whenever they change.\n * Must be called inside an {@link onMount} callback.\n *\n * @example\n * onMount(() => {\n * onSlotChange('icon', (nodes) => setHasIcon(nodes.length > 0));\n * });\n */\nexport const onSlotChange = (slotName: string, callback: (elements: Element[]) => void): void => {\n const el = currentRuntime().el;\n const name = slotName === 'default' ? '' : slotName;\n const selector = name ? `slot[name=\"${name}\"]` : 'slot:not([name])';\n const slot = el.shadowRoot?.querySelector<HTMLSlotElement>(selector);\n\n if (!slot) {\n warnMissingSlot(el, name, 'onSlotChange()');\n\n return;\n }\n\n const handler = () => callback(slot.assignedElements({ flatten: true }));\n\n handler();\n slot.addEventListener('slotchange', handler);\n onCleanup(() => slot.removeEventListener('slotchange', handler));\n};\n\nexport const createSlots = <T extends Record<string, unknown> = Record<string, unknown>>(): Slots<T> => {\n const el = currentRuntime().el;\n const sigs = new Map<string, Signal<boolean>>();\n\n const get = (slotName: string): Signal<boolean> => {\n if (sigs.has(slotName)) return sigs.get(slotName)!;\n\n const s = signal(false);\n\n sigs.set(slotName, s);\n\n onMount(() => {\n const selector = slotName ? `slot[name=\"${slotName}\"]` : 'slot:not([name])';\n const slot = el.shadowRoot?.querySelector<HTMLSlotElement>(selector);\n\n if (!slot) {\n warnMissingSlot(el, slotName, 'slots.has()');\n\n return;\n }\n\n const update = () => {\n s.value = slot.assignedNodes().length > 0;\n };\n\n update();\n slot.addEventListener('slotchange', update);\n\n return () => slot.removeEventListener('slotchange', update);\n });\n\n return s;\n };\n\n return {\n has(name: keyof T): ReadonlySignal<boolean> {\n return get(name === 'default' ? '' : String(name));\n },\n };\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// REFLECT API (HOST ATTRIBUTE/EVENT/CLASS BINDING)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Describes a reactive or static host binding (attribute, event, class).\n */\nexport type HostBindingValue =\n | (() => string | number | boolean | null | undefined)\n | string\n | number\n | boolean\n | null\n | undefined;\n\n/**\n * Configuration for `reflect()`.\n */\nexport type ReflectConfig = {\n [key: string]: HostBindingValue | ((e: Event) => void);\n classMap?: () => Record<string, boolean>;\n};\n\n/**\n * Reflect reactive attributes, events, and classes to a host element.\n * Must be called within a component setup context.\n *\n * - `on*` keys map to event listeners: `onClick` → `'click'`, `onValueChanged` → `'valueChanged'`\n * - `classMap` maps to a reactive class object\n * - all other keys map to attributes (static or reactive getter)\n *\n * @example\n * setup({ reflect }) {\n * reflect({\n * role: 'checkbox',\n * tabindex: () => props.disabled.value ? undefined : 0,\n * checked: () => props.checked.value,\n * classMap: () => ({ checked: props.checked.value }),\n * onClick: handleToggle,\n * });\n * }\n */\nexport function reflect(host: HTMLElement, config: ReflectConfig): void {\n for (const [key, value] of Object.entries(config)) {\n if (key === 'classMap') {\n applyClassMap(host, value as () => Record<string, boolean>);\n } else if (key.startsWith('on') && key.length > 2 && typeof value === 'function') {\n // onClick → 'click', onValueChanged → 'valueChanged', onKeydown → 'keydown'\n const raw = key.slice(2);\n\n handle(host, raw[0].toLowerCase() + raw.slice(1), value as (e: Event) => void);\n } else {\n applyAttribute(host, key, value as HostBindingValue);\n }\n }\n}\n\nfunction applyAttribute(host: HTMLElement, name: string, value: HostBindingValue): void {\n if (typeof value === 'function') {\n effect(() => setAttr(host, name, (value as () => HostBindingValue)()));\n } else {\n setAttr(host, name, value);\n }\n}\n\nfunction applyClassMap(host: HTMLElement, getter: () => Record<string, boolean>): void {\n let prev = new Set<string>();\n\n effect(() => {\n const next = new Set(\n Object.entries(getter())\n .filter(([, active]) => active)\n .map(([cls]) => cls),\n );\n\n for (const cls of prev) if (!next.has(cls)) host.classList.remove(cls);\n for (const cls of next) if (!prev.has(cls)) host.classList.add(cls);\n\n prev = next;\n });\n}\n"],"mappings":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9E,EAAe,EAAM,EAAK,EAA0B,CAK1D,SAAS,EAAe,EAAmB,EAAc,EAA+B,CAClF,OAAO,GAAU,WACnB,EAAA,WAAa,EAAA,QAAQ,EAAM,EAAO,GAAkC,CAAC,CAAC,CAEtE,EAAA,QAAQ,EAAM,EAAM,EAAM,CAI9B,SAAS,EAAc,EAAmB,EAA6C,CACrF,IAAI,EAAO,IAAI,IAEf,EAAA,WAAa,CACX,IAAM,EAAO,IAAI,IACf,OAAO,QAAQ,GAAQ,CAAC,CACrB,QAAQ,EAAG,KAAY,EAAO,CAC9B,KAAK,CAAC,KAAS,EAAI,CACvB,CAED,IAAK,IAAM,KAAO,EAAW,EAAK,IAAI,EAAI,EAAE,EAAK,UAAU,OAAO,EAAI,CACtE,IAAK,IAAM,KAAO,EAAW,EAAK,IAAI,EAAI,EAAE,EAAK,UAAU,IAAI,EAAI,CAEnE,EAAO,GACP"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host utilities — component context injection, slot observation, and attribute/class reflection.
|
|
3
|
+
*
|
|
4
|
+
* - Context API (provide, inject, createContext, syncContextProps)
|
|
5
|
+
* - Slot observation and detection (Slots type, createSlots, onSlotChange)
|
|
6
|
+
* - Host element binding (reflect) for attributes, events, and classes
|
|
7
|
+
*/
|
|
8
|
+
import { type ReadonlySignal, type Signal } 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> | string | symbol, value: T) => void;
|
|
13
|
+
export declare function inject<T>(key: InjectionKey<T> | string | symbol): T | undefined;
|
|
14
|
+
export declare function inject<T>(key: InjectionKey<T> | string | symbol, fallback: T): T;
|
|
15
|
+
export declare function createContext<T>(description?: string): InjectionKey<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Reactively inherits prop values from a context object provided by an ancestor component.
|
|
18
|
+
* For each key, when the context value is not `undefined`, it is written into the matching prop signal.
|
|
19
|
+
* The effect is automatically cleaned up when the component unmounts.
|
|
20
|
+
*
|
|
21
|
+
* Deferred to `onMount` so context values win over HTML attribute values set on the child.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* syncContextProps(inject(BUTTON_GROUP_CTX), props, ['color', 'size', 'variant']);
|
|
25
|
+
*/
|
|
26
|
+
export declare const syncContextProps: <K extends string, Ctx extends Partial<Record<K, ReadonlySignal<unknown>>>, Props extends Record<K, Signal<unknown>>>(ctx: Ctx | undefined, props: Props, keys: K[]) => void;
|
|
27
|
+
export type Slots<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
28
|
+
/**
|
|
29
|
+
* Returns a `ReadonlySignal<boolean>` that is `true` when the slot has assigned content.
|
|
30
|
+
* Reactive — use the signal directly in templates, computed(), or effects.
|
|
31
|
+
* @example const hasIcon = slots.has('icon'); // ReadonlySignal<boolean>
|
|
32
|
+
*/
|
|
33
|
+
has(name: keyof T): ReadonlySignal<boolean>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Observes a slot and calls `callback` with assigned elements whenever they change.
|
|
37
|
+
* Must be called inside an {@link onMount} callback.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* onMount(() => {
|
|
41
|
+
* onSlotChange('icon', (nodes) => setHasIcon(nodes.length > 0));
|
|
42
|
+
* });
|
|
43
|
+
*/
|
|
44
|
+
export declare const onSlotChange: (slotName: string, callback: (elements: Element[]) => void) => void;
|
|
45
|
+
export declare const createSlots: <T extends Record<string, unknown> = Record<string, unknown>>() => Slots<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Describes a reactive or static host binding (attribute, event, class).
|
|
48
|
+
*/
|
|
49
|
+
export type HostBindingValue = (() => string | number | boolean | null | undefined) | string | number | boolean | null | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Configuration for `reflect()`.
|
|
52
|
+
*/
|
|
53
|
+
export type ReflectConfig = {
|
|
54
|
+
[key: string]: HostBindingValue | ((e: Event) => void);
|
|
55
|
+
classMap?: () => Record<string, boolean>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Reflect reactive attributes, events, and classes to a host element.
|
|
59
|
+
* Must be called within a component setup context.
|
|
60
|
+
*
|
|
61
|
+
* - `on*` keys map to event listeners: `onClick` → `'click'`, `onValueChanged` → `'valueChanged'`
|
|
62
|
+
* - `classMap` maps to a reactive class object
|
|
63
|
+
* - all other keys map to attributes (static or reactive getter)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* setup({ reflect }) {
|
|
67
|
+
* reflect({
|
|
68
|
+
* role: 'checkbox',
|
|
69
|
+
* tabindex: () => props.disabled.value ? undefined : 0,
|
|
70
|
+
* checked: () => props.checked.value,
|
|
71
|
+
* classMap: () => ({ checked: props.checked.value }),
|
|
72
|
+
* onClick: handleToggle,
|
|
73
|
+
* });
|
|
74
|
+
* }
|
|
75
|
+
*/
|
|
76
|
+
export declare function reflect(host: HTMLElement, config: ReflectConfig): void;
|
|
77
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/core/host.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,EAAU,MAAM,mBAAmB,CAAC;AAa7E,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,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,KAAG,IAM7E,CAAC;AAEF,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,MAAM,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AS,CAAC,GACpD,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC;IACvD,QAAQ,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAatE"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{currentRuntime as e,effect as t,handle as n,onCleanup as r,onMount as i}from"./runtime-lifecycle.js";import{setAttr as a}from"./utilities.js";import{signal as o}from"@vielzeug/stateit";var s=new WeakMap,c=(t,n)=>{let r=e().el;s.has(r)||s.set(r,new Map),s.get(r).set(t,n)};function l(t,...n){let r=e().el;for(;r;){if(r instanceof HTMLElement){let e=s.get(r)?.get(t);if(e!==void 0)return e}let e=r.getRootNode();r=r.parentElement??(e instanceof ShadowRoot?e.host:null)}return n.length>0?n[0]:void 0}function u(e){return Symbol(e)}var d=(e,n,r)=>{e&&i(()=>{t(()=>{for(let t of r){let r=e[t]?.value;r!==void 0&&(n[t].value=r)}})})},f=new Set,p=(e,t,n)=>{let r=`${n}:${e.localName}:${t||`default`}`;f.has(r)||(f.add(r),console.warn(`[craftit:E10] ${n} could not find a matching <slot${t?` name="${t}"`:``}> in <${e.localName}>. Render the slot before using ${n}.`))},m=(t,n)=>{let i=e().el,a=t===`default`?``:t,o=a?`slot[name="${a}"]`:`slot:not([name])`,s=i.shadowRoot?.querySelector(o);if(!s){p(i,a,`onSlotChange()`);return}let c=()=>n(s.assignedElements({flatten:!0}));c(),s.addEventListener(`slotchange`,c),r(()=>s.removeEventListener(`slotchange`,c))},h=()=>{let t=e().el,n=new Map,r=e=>{if(n.has(e))return n.get(e);let r=o(!1);return n.set(e,r),i(()=>{let n=e?`slot[name="${e}"]`:`slot:not([name])`,i=t.shadowRoot?.querySelector(n);if(!i){p(t,e,`slots.has()`);return}let a=()=>{r.value=i.assignedNodes().length>0};return a(),i.addEventListener(`slotchange`,a),()=>i.removeEventListener(`slotchange`,a)}),r};return{has(e){return r(e===`default`?``:String(e))}}};function g(e,t){for(let[r,i]of Object.entries(t))if(r===`classMap`)v(e,i);else if(r.startsWith(`on`)&&r.length>2&&typeof i==`function`){let t=r.slice(2);n(e,t[0].toLowerCase()+t.slice(1),i)}else _(e,r,i)}function _(e,n,r){typeof r==`function`?t(()=>a(e,n,r())):a(e,n,r)}function v(e,n){let r=new Set;t(()=>{let t=new Set(Object.entries(n()).filter(([,e])=>e).map(([e])=>e));for(let n of r)t.has(n)||e.classList.remove(n);for(let n of t)r.has(n)||e.classList.add(n);r=t})}export{u as createContext,h as createSlots,l as inject,m as onSlotChange,c as provide,g as reflect,d as syncContextProps};
|
|
2
|
+
//# sourceMappingURL=host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","names":[],"sources":["../../src/core/host.ts"],"sourcesContent":["/**\n * Host utilities — component context injection, slot observation, and attribute/class reflection.\n *\n * - Context API (provide, inject, createContext, syncContextProps)\n * - Slot observation and detection (Slots type, createSlots, onSlotChange)\n * - Host element binding (reflect) for attributes, events, and classes\n */\n\nimport { type ReadonlySignal, type Signal, signal } from '@vielzeug/stateit';\n\n// Use the wrapped effect from runtime-lifecycle so reactive bindings are\n// automatically cleaned up on unmount — raw stateit effect has no lifecycle awareness.\nimport { currentRuntime, effect, handle, onCleanup, onMount } from './runtime-lifecycle';\nimport { setAttr } from './utilities';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// CONTEXT API\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst contextRegistry = new WeakMap<HTMLElement, Map<InjectionKey<unknown> | string | symbol, unknown>>();\n\nexport type InjectionKey<T> = symbol & {\n readonly __craftit_injection_key?: T;\n};\n\nexport const provide = <T>(key: InjectionKey<T> | string | symbol, value: T): void => {\n const el = currentRuntime().el;\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> | string | symbol): T | undefined;\nexport function inject<T>(key: InjectionKey<T> | string | symbol, fallback: T): T;\nexport function inject<T>(key: InjectionKey<T> | string | symbol, ...rest: [T?]): T | undefined {\n let node: Node | null = currentRuntime().el;\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 function createContext<T>(description?: string): InjectionKey<T> {\n return Symbol(description) as InjectionKey<T>;\n}\n\n/**\n * Reactively inherits prop values from a context object provided by an ancestor component.\n * For each key, when the context value is not `undefined`, it is written into the matching prop signal.\n * The effect is automatically cleaned up when the component unmounts.\n *\n * Deferred to `onMount` so context values win over HTML attribute values set on the child.\n *\n * @example\n * syncContextProps(inject(BUTTON_GROUP_CTX), props, ['color', 'size', 'variant']);\n */\nexport const syncContextProps = <\n K extends string,\n Ctx extends Partial<Record<K, ReadonlySignal<unknown>>>,\n Props extends Record<K, Signal<unknown>>,\n>(\n ctx: Ctx | undefined,\n props: Props,\n keys: K[],\n): void => {\n if (!ctx) return;\n\n onMount(() => {\n effect(() => {\n for (const k of keys) {\n const v = ctx[k]?.value;\n\n if (v !== undefined) props[k].value = v;\n }\n });\n });\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// SLOTS API\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst missingSlotWarnings = new Set<string>();\n\nconst warnMissingSlot = (el: HTMLElement, slotName: string, source: 'onSlotChange()' | 'slots.has()'): void => {\n const key = `${source}:${el.localName}:${slotName || 'default'}`;\n\n if (missingSlotWarnings.has(key)) return;\n\n missingSlotWarnings.add(key);\n console.warn(\n `[craftit:E10] ${source} could not find a matching <slot${slotName ? ` name=\"${slotName}\"` : ''}> in <${el.localName}>. Render the slot before using ${source}.`,\n );\n};\n\nexport type Slots<T extends Record<string, unknown> = Record<string, unknown>> = {\n /**\n * Returns a `ReadonlySignal<boolean>` that is `true` when the slot has assigned content.\n * Reactive — use the signal directly in templates, computed(), or effects.\n * @example const hasIcon = slots.has('icon'); // ReadonlySignal<boolean>\n */\n has(name: keyof T): ReadonlySignal<boolean>;\n};\n\n/**\n * Observes a slot and calls `callback` with assigned elements whenever they change.\n * Must be called inside an {@link onMount} callback.\n *\n * @example\n * onMount(() => {\n * onSlotChange('icon', (nodes) => setHasIcon(nodes.length > 0));\n * });\n */\nexport const onSlotChange = (slotName: string, callback: (elements: Element[]) => void): void => {\n const el = currentRuntime().el;\n const name = slotName === 'default' ? '' : slotName;\n const selector = name ? `slot[name=\"${name}\"]` : 'slot:not([name])';\n const slot = el.shadowRoot?.querySelector<HTMLSlotElement>(selector);\n\n if (!slot) {\n warnMissingSlot(el, name, 'onSlotChange()');\n\n return;\n }\n\n const handler = () => callback(slot.assignedElements({ flatten: true }));\n\n handler();\n slot.addEventListener('slotchange', handler);\n onCleanup(() => slot.removeEventListener('slotchange', handler));\n};\n\nexport const createSlots = <T extends Record<string, unknown> = Record<string, unknown>>(): Slots<T> => {\n const el = currentRuntime().el;\n const sigs = new Map<string, Signal<boolean>>();\n\n const get = (slotName: string): Signal<boolean> => {\n if (sigs.has(slotName)) return sigs.get(slotName)!;\n\n const s = signal(false);\n\n sigs.set(slotName, s);\n\n onMount(() => {\n const selector = slotName ? `slot[name=\"${slotName}\"]` : 'slot:not([name])';\n const slot = el.shadowRoot?.querySelector<HTMLSlotElement>(selector);\n\n if (!slot) {\n warnMissingSlot(el, slotName, 'slots.has()');\n\n return;\n }\n\n const update = () => {\n s.value = slot.assignedNodes().length > 0;\n };\n\n update();\n slot.addEventListener('slotchange', update);\n\n return () => slot.removeEventListener('slotchange', update);\n });\n\n return s;\n };\n\n return {\n has(name: keyof T): ReadonlySignal<boolean> {\n return get(name === 'default' ? '' : String(name));\n },\n };\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// REFLECT API (HOST ATTRIBUTE/EVENT/CLASS BINDING)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Describes a reactive or static host binding (attribute, event, class).\n */\nexport type HostBindingValue =\n | (() => string | number | boolean | null | undefined)\n | string\n | number\n | boolean\n | null\n | undefined;\n\n/**\n * Configuration for `reflect()`.\n */\nexport type ReflectConfig = {\n [key: string]: HostBindingValue | ((e: Event) => void);\n classMap?: () => Record<string, boolean>;\n};\n\n/**\n * Reflect reactive attributes, events, and classes to a host element.\n * Must be called within a component setup context.\n *\n * - `on*` keys map to event listeners: `onClick` → `'click'`, `onValueChanged` → `'valueChanged'`\n * - `classMap` maps to a reactive class object\n * - all other keys map to attributes (static or reactive getter)\n *\n * @example\n * setup({ reflect }) {\n * reflect({\n * role: 'checkbox',\n * tabindex: () => props.disabled.value ? undefined : 0,\n * checked: () => props.checked.value,\n * classMap: () => ({ checked: props.checked.value }),\n * onClick: handleToggle,\n * });\n * }\n */\nexport function reflect(host: HTMLElement, config: ReflectConfig): void {\n for (const [key, value] of Object.entries(config)) {\n if (key === 'classMap') {\n applyClassMap(host, value as () => Record<string, boolean>);\n } else if (key.startsWith('on') && key.length > 2 && typeof value === 'function') {\n // onClick → 'click', onValueChanged → 'valueChanged', onKeydown → 'keydown'\n const raw = key.slice(2);\n\n handle(host, raw[0].toLowerCase() + raw.slice(1), value as (e: Event) => void);\n } else {\n applyAttribute(host, key, value as HostBindingValue);\n }\n }\n}\n\nfunction applyAttribute(host: HTMLElement, name: string, value: HostBindingValue): void {\n if (typeof value === 'function') {\n effect(() => setAttr(host, name, (value as () => HostBindingValue)()));\n } else {\n setAttr(host, name, value);\n }\n}\n\nfunction applyClassMap(host: HTMLElement, getter: () => Record<string, boolean>): void {\n let prev = new Set<string>();\n\n effect(() => {\n const next = new Set(\n Object.entries(getter())\n .filter(([, active]) => active)\n .map(([cls]) => cls),\n );\n\n for (const cls of prev) if (!next.has(cls)) host.classList.remove(cls);\n for (const cls of next) if (!prev.has(cls)) host.classList.add(cls);\n\n prev = next;\n });\n}\n"],"mappings":"gMAmBA,IAAM,EAAkB,IAAI,QAMf,GAAc,EAAwC,IAAmB,CACpF,IAAM,EAAK,GAAgB,CAAC,GAEvB,EAAgB,IAAI,EAAG,EAAE,EAAgB,IAAI,EAAI,IAAI,IAAM,CAEhE,EAAgB,IAAI,EAAG,CAAE,IAAI,EAAK,EAAM,EAK1C,SAAgB,EAAU,EAAwC,GAAG,EAA2B,CAC9F,IAAI,EAAoB,GAAgB,CAAC,GAEzC,KAAO,GAAM,CACX,GAAI,aAAgB,YAAa,CAC/B,IAAM,EAAI,EAAgB,IAAI,EAAK,EAAE,IAAI,EAAI,CAE7C,GAAI,IAAM,IAAA,GAAW,OAAO,EAG9B,IAAM,EAAO,EAAK,aAAa,CAE/B,EAAQ,EAAqB,gBAAkB,aAAgB,WAAa,EAAK,KAAO,MAG1F,OAAO,EAAK,OAAS,EAAI,EAAK,GAAK,IAAA,GAGrC,SAAgB,EAAiB,EAAuC,CACtE,OAAO,OAAO,EAAY,CAa5B,IAAa,GAKX,EACA,EACA,IACS,CACJ,GAEL,MAAc,CACZ,MAAa,CACX,IAAK,IAAM,KAAK,EAAM,CACpB,IAAM,EAAI,EAAI,IAAI,MAEd,IAAM,IAAA,KAAW,EAAM,GAAG,MAAQ,KAExC,EACF,EAOE,EAAsB,IAAI,IAE1B,GAAmB,EAAiB,EAAkB,IAAmD,CAC7G,IAAM,EAAM,GAAG,EAAO,GAAG,EAAG,UAAU,GAAG,GAAY,YAEjD,EAAoB,IAAI,EAAI,GAEhC,EAAoB,IAAI,EAAI,CAC5B,QAAQ,KACN,iBAAiB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AAuC,SAClD,EAAI,WAAW,KAAK,EAAI,EAAI,OAAS,GAAK,OAAO,GAAU,WAAY,CAEhF,IAAM,EAAM,EAAI,MAAM,EAAE,CAExB,EAAO,EAAM,EAAI,GAAG,aAAa,CAAG,EAAI,MAAM,EAAE,CAAE,EAA4B,MAE9E,EAAe,EAAM,EAAK,EAA0B,CAK1D,SAAS,EAAe,EAAmB,EAAc,EAA+B,CAClF,OAAO,GAAU,WACnB,MAAa,EAAQ,EAAM,EAAO,GAAkC,CAAC,CAAC,CAEtE,EAAQ,EAAM,EAAM,EAAM,CAI9B,SAAS,EAAc,EAAmB,EAA6C,CACrF,IAAI,EAAO,IAAI,IAEf,MAAa,CACX,IAAM,EAAO,IAAI,IACf,OAAO,QAAQ,GAAQ,CAAC,CACrB,QAAQ,EAAG,KAAY,EAAO,CAC9B,KAAK,CAAC,KAAS,EAAI,CACvB,CAED,IAAK,IAAM,KAAO,EAAW,EAAK,IAAI,EAAI,EAAE,EAAK,UAAU,OAAO,EAAI,CACtE,IAAK,IAAM,KAAO,EAAW,EAAK,IAAI,EAAI,EAAE,EAAK,UAAU,IAAI,EAAI,CAEnE,EAAO,GACP"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
require(`@vielzeug/stateit`);var e=Symbol(`craftit.htmlResultBrand`);function t(){return{value:null}}function n(){return[]}function r(t,n=[]){let r={__bindings:n,__html:t,toString(){return t}};return Object.defineProperty(r,e,{configurable:!1,enumerable:!1,value:!0,writable:!1}),r}var i=t=>typeof t==`object`&&!!t&&t[e]===!0;function a(e){return typeof e==`string`?{bindings:[],html:e}:{bindings:e.__bindings,html:e.__html}}var o=Symbol(`craftit.eachSignal`);exports.EACH_SIGNAL=o,exports.extractResult=a,exports.htmlResult=r,exports.isHtmlResult=i,exports.ref=t,exports.refs=n;
|
|
2
|
+
//# sourceMappingURL=internal.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.cjs","names":[],"sources":["../../src/core/internal.ts"],"sourcesContent":["/**\n * @internal — Binding type system and engine internals.\n *\n * These types define the contract between the template compiler and binding engine.\n * They are NOT part of the public API and importing directly is an unstable contract.\n *\n * Public-facing types (HTMLResult, Directive, Ref, RefCallback, Refs) are\n * re-exported from the main entry point.\n */\n\nimport { type ReadonlySignal, type Signal } from '@vielzeug/stateit';\n\nconst HTML_RESULT_BRAND: unique symbol = Symbol('craftit.htmlResultBrand');\n\n// ─────────────────────────────────────────────────────────────────────────────\n// REF TYPES\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface Ref<T extends Element> {\n value: T | null;\n}\n\nexport function ref<T extends Element>(): Ref<T> {\n return { value: 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\n// ─────────────────────────────────────────────────────────────────────────────\n// HTML RESULT\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface HTMLResult {\n __bindings: Binding[];\n __html: string;\n toString(): string;\n}\n\n/** @internal — construct an HTMLResult from a pre-built html string and bindings. */\nexport function htmlResult(html: string, bindings: Binding[] = []): HTMLResult {\n const result = {\n __bindings: bindings,\n __html: html,\n toString() {\n return html;\n },\n };\n\n Object.defineProperty(result, HTML_RESULT_BRAND, {\n configurable: false,\n enumerable: false,\n value: true,\n writable: false,\n });\n\n return result as HTMLResult;\n}\n\n/** @internal — strict HTMLResult runtime type guard. */\nexport const isHtmlResult = (value: unknown): value is HTMLResult =>\n typeof value === 'object' && !!value && (value as Record<symbol, unknown>)[HTML_RESULT_BRAND] === true;\n\n/** @internal — extract html and bindings from a string or HTMLResult. */\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\n// ─────────────────────────────────────────────────────────────────────────────\n// DIRECTIVES\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface DirectiveContext {\n /** The cleanup registration function for the component. */\n registerCleanup: (fn: () => void) => void;\n}\n\nexport interface Directive {\n /** Invoked when the element is mounted in the DOM. */\n mount?(el: HTMLElement, context: DirectiveContext): void;\n /** Invoked by the template engine to render content (interpolation directives). */\n render?(): HTMLResult | string;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// BINDING TYPES\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport type TextBinding = {\n signal: ReadonlySignal<unknown>;\n type: 'text';\n uid: string;\n};\n\nexport type AttrBinding = {\n mode: 'bool' | 'attr';\n name: string;\n signal?: ReadonlySignal<unknown>;\n type: 'attr';\n uid: string;\n value?: unknown;\n};\n\nexport type PropBinding = {\n /** Optional writable source used for native two-way bridge (.value/.checked). */\n model?: Signal<unknown>;\n name: string;\n signal?: ReadonlySignal<unknown>;\n type: 'prop';\n uid: string;\n value?: unknown;\n};\n\nexport type EventBinding = {\n handler: (e: Event) => void;\n modifiers?: {\n capture?: boolean;\n once?: boolean;\n passive?: boolean;\n prevent?: boolean;\n self?: boolean;\n stop?: boolean;\n };\n name: string;\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 CallbackBinding = {\n apply: (el: HTMLElement, registerCleanup: (fn: () => void) => void) => void;\n type: 'callback';\n uid: string;\n};\n\nexport type HtmlBinding = {\n keyed?: boolean;\n signal: ReadonlySignal<{\n bindings: Binding[];\n html: string;\n items?: Array<{ bindings: Binding[]; html: string }>;\n keys?: (string | number)[];\n }>;\n type: 'html';\n uid: string;\n};\n\nexport type Binding =\n | TextBinding\n | AttrBinding\n | PropBinding\n | EventBinding\n | RefBinding\n | CallbackBinding\n | HtmlBinding;\n\n// ─────────────────────────────────────────────────────────────────────────────\n// INTERNAL MARKERS & CONSTANTS\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** @internal — opaque marker for each() reactive results. */\nexport const EACH_SIGNAL: unique symbol = Symbol('craftit.eachSignal');\n\n/** @internal — binding element identifier attribute. */\nexport const CF_ID_ATTR = 'u';\n"],"mappings":"6BAYA,IAAM,EAAmC,OAAO,0BAA0B,CAU1E,SAAgB,GAAiC,CAC/C,MAAO,CAAE,MAAO,KAAM,CAKxB,SAAgB,GAAmC,CACjD,MAAO,EAAE,CAgBX,SAAgB,EAAW,EAAc,EAAsB,EAAE,CAAc,CAC7E,IAAM,EAAS,CACb,WAAY,EACZ,OAAQ,EACR,UAAW,CACT,OAAO,GAEV,CASD,OAPA,OAAO,eAAe,EAAQ,EAAmB,CAC/C,aAAc,GACd,WAAY,GACZ,MAAO,GACP,SAAU,GACX,CAAC,CAEK,EAIT,IAAa,EAAgB,GAC3B,OAAO,GAAU,UAAY,CAAC,CAAC,GAAU,EAAkC,KAAuB,GAGpG,SAAgB,EAAc,EAA+D,CAC3F,OAAO,OAAO,GAAM,SAAW,CAAE,SAAU,EAAE,CAAE,KAAM,EAAG,CAAG,CAAE,SAAU,EAAE,WAAY,KAAM,EAAE,OAAQ,CAqGvG,IAAa,EAA6B,OAAO,qBAAqB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal — Binding type system and engine internals.
|
|
3
|
+
*
|
|
4
|
+
* These types define the contract between the template compiler and binding engine.
|
|
5
|
+
* They are NOT part of the public API and importing directly is an unstable contract.
|
|
6
|
+
*
|
|
7
|
+
* Public-facing types (HTMLResult, Directive, Ref, RefCallback, Refs) are
|
|
8
|
+
* re-exported from the main entry point.
|
|
9
|
+
*/
|
|
10
|
+
import { type ReadonlySignal, type Signal } from '@vielzeug/stateit';
|
|
11
|
+
export interface Ref<T extends Element> {
|
|
12
|
+
value: T | null;
|
|
13
|
+
}
|
|
14
|
+
export declare function ref<T extends Element>(): Ref<T>;
|
|
15
|
+
export type Refs<T extends Element> = T[];
|
|
16
|
+
export declare function refs<T extends Element>(): Refs<T>;
|
|
17
|
+
export type RefCallback<T extends Element> = (el: T | null) => void;
|
|
18
|
+
export interface HTMLResult {
|
|
19
|
+
__bindings: Binding[];
|
|
20
|
+
__html: string;
|
|
21
|
+
toString(): string;
|
|
22
|
+
}
|
|
23
|
+
/** @internal — construct an HTMLResult from a pre-built html string and bindings. */
|
|
24
|
+
export declare function htmlResult(html: string, bindings?: Binding[]): HTMLResult;
|
|
25
|
+
/** @internal — strict HTMLResult runtime type guard. */
|
|
26
|
+
export declare const isHtmlResult: (value: unknown) => value is HTMLResult;
|
|
27
|
+
/** @internal — extract html and bindings from a string or HTMLResult. */
|
|
28
|
+
export declare function extractResult(v: string | HTMLResult): {
|
|
29
|
+
bindings: Binding[];
|
|
30
|
+
html: string;
|
|
31
|
+
};
|
|
32
|
+
export interface DirectiveContext {
|
|
33
|
+
/** The cleanup registration function for the component. */
|
|
34
|
+
registerCleanup: (fn: () => void) => void;
|
|
35
|
+
}
|
|
36
|
+
export interface Directive {
|
|
37
|
+
/** Invoked when the element is mounted in the DOM. */
|
|
38
|
+
mount?(el: HTMLElement, context: DirectiveContext): void;
|
|
39
|
+
/** Invoked by the template engine to render content (interpolation directives). */
|
|
40
|
+
render?(): HTMLResult | string;
|
|
41
|
+
}
|
|
42
|
+
export type TextBinding = {
|
|
43
|
+
signal: ReadonlySignal<unknown>;
|
|
44
|
+
type: 'text';
|
|
45
|
+
uid: string;
|
|
46
|
+
};
|
|
47
|
+
export type AttrBinding = {
|
|
48
|
+
mode: 'bool' | 'attr';
|
|
49
|
+
name: string;
|
|
50
|
+
signal?: ReadonlySignal<unknown>;
|
|
51
|
+
type: 'attr';
|
|
52
|
+
uid: string;
|
|
53
|
+
value?: unknown;
|
|
54
|
+
};
|
|
55
|
+
export type PropBinding = {
|
|
56
|
+
/** Optional writable source used for native two-way bridge (.value/.checked). */
|
|
57
|
+
model?: Signal<unknown>;
|
|
58
|
+
name: string;
|
|
59
|
+
signal?: ReadonlySignal<unknown>;
|
|
60
|
+
type: 'prop';
|
|
61
|
+
uid: string;
|
|
62
|
+
value?: unknown;
|
|
63
|
+
};
|
|
64
|
+
export type EventBinding = {
|
|
65
|
+
handler: (e: Event) => void;
|
|
66
|
+
modifiers?: {
|
|
67
|
+
capture?: boolean;
|
|
68
|
+
once?: boolean;
|
|
69
|
+
passive?: boolean;
|
|
70
|
+
prevent?: boolean;
|
|
71
|
+
self?: boolean;
|
|
72
|
+
stop?: boolean;
|
|
73
|
+
};
|
|
74
|
+
name: string;
|
|
75
|
+
type: 'event';
|
|
76
|
+
uid: string;
|
|
77
|
+
};
|
|
78
|
+
export type RefBinding = {
|
|
79
|
+
ref: Ref<Element> | Refs<Element> | RefCallback<Element>;
|
|
80
|
+
type: 'ref';
|
|
81
|
+
uid: string;
|
|
82
|
+
};
|
|
83
|
+
export type CallbackBinding = {
|
|
84
|
+
apply: (el: HTMLElement, registerCleanup: (fn: () => void) => void) => void;
|
|
85
|
+
type: 'callback';
|
|
86
|
+
uid: string;
|
|
87
|
+
};
|
|
88
|
+
export type HtmlBinding = {
|
|
89
|
+
keyed?: boolean;
|
|
90
|
+
signal: ReadonlySignal<{
|
|
91
|
+
bindings: Binding[];
|
|
92
|
+
html: string;
|
|
93
|
+
items?: Array<{
|
|
94
|
+
bindings: Binding[];
|
|
95
|
+
html: string;
|
|
96
|
+
}>;
|
|
97
|
+
keys?: (string | number)[];
|
|
98
|
+
}>;
|
|
99
|
+
type: 'html';
|
|
100
|
+
uid: string;
|
|
101
|
+
};
|
|
102
|
+
export type Binding = TextBinding | AttrBinding | PropBinding | EventBinding | RefBinding | CallbackBinding | HtmlBinding;
|
|
103
|
+
/** @internal — opaque marker for each() reactive results. */
|
|
104
|
+
export declare const EACH_SIGNAL: unique symbol;
|
|
105
|
+
/** @internal — binding element identifier attribute. */
|
|
106
|
+
export declare const CF_ID_ATTR = "u";
|
|
107
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/core/internal.ts"],"names":[],"mappings":"AAAA;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AM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,KAAK,IAAI,CAAC;IAC5E,IAAI,EAAE,UAAU,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,cAAc,CAAC;QACrB,QAAQ,EAAE,OAAO,EAAE,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,KAAK,CAAC;YAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACrD,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;KAC5B,CAAC,CAAC;IACH,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,OAAO,GACf,WAAW,GACX,WAAW,GACX,WAAW,GACX,YAAY,GACZ,UAAU,GACV,eAAe,GACf,WAAW,CAAC;AAMhB,6DAA6D;AAC7D,eAAO,MAAM,WAAW,EAAE,OAAO,MAAqC,CAAC;AAEvE,wDAAwD;AACxD,eAAO,MAAM,UAAU,MAAM,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"@vielzeug/stateit";var e=Symbol(`craftit.htmlResultBrand`);function t(){return{value:null}}function n(){return[]}function r(t,n=[]){let r={__bindings:n,__html:t,toString(){return t}};return Object.defineProperty(r,e,{configurable:!1,enumerable:!1,value:!0,writable:!1}),r}var i=t=>typeof t==`object`&&!!t&&t[e]===!0;function a(e){return typeof e==`string`?{bindings:[],html:e}:{bindings:e.__bindings,html:e.__html}}var o=Symbol(`craftit.eachSignal`);export{o as EACH_SIGNAL,a as extractResult,r as htmlResult,i as isHtmlResult,t as ref,n as refs};
|
|
2
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","names":[],"sources":["../../src/core/internal.ts"],"sourcesContent":["/**\n * @internal — Binding type system and engine internals.\n *\n * These types define the contract between the template compiler and binding engine.\n * They are NOT part of the public API and importing directly is an unstable contract.\n *\n * Public-facing types (HTMLResult, Directive, Ref, RefCallback, Refs) are\n * re-exported from the main entry point.\n */\n\nimport { type ReadonlySignal, type Signal } from '@vielzeug/stateit';\n\nconst HTML_RESULT_BRAND: unique symbol = Symbol('craftit.htmlResultBrand');\n\n// ─────────────────────────────────────────────────────────────────────────────\n// REF TYPES\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface Ref<T extends Element> {\n value: T | null;\n}\n\nexport function ref<T extends Element>(): Ref<T> {\n return { value: 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\n// ─────────────────────────────────────────────────────────────────────────────\n// HTML RESULT\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface HTMLResult {\n __bindings: Binding[];\n __html: string;\n toString(): string;\n}\n\n/** @internal — construct an HTMLResult from a pre-built html string and bindings. */\nexport function htmlResult(html: string, bindings: Binding[] = []): HTMLResult {\n const result = {\n __bindings: bindings,\n __html: html,\n toString() {\n return html;\n },\n };\n\n Object.defineProperty(result, HTML_RESULT_BRAND, {\n configurable: false,\n enumerable: false,\n value: true,\n writable: false,\n });\n\n return result as HTMLResult;\n}\n\n/** @internal — strict HTMLResult runtime type guard. */\nexport const isHtmlResult = (value: unknown): value is HTMLResult =>\n typeof value === 'object' && !!value && (value as Record<symbol, unknown>)[HTML_RESULT_BRAND] === true;\n\n/** @internal — extract html and bindings from a string or HTMLResult. */\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\n// ─────────────────────────────────────────────────────────────────────────────\n// DIRECTIVES\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface DirectiveContext {\n /** The cleanup registration function for the component. */\n registerCleanup: (fn: () => void) => void;\n}\n\nexport interface Directive {\n /** Invoked when the element is mounted in the DOM. */\n mount?(el: HTMLElement, context: DirectiveContext): void;\n /** Invoked by the template engine to render content (interpolation directives). */\n render?(): HTMLResult | string;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// BINDING TYPES\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport type TextBinding = {\n signal: ReadonlySignal<unknown>;\n type: 'text';\n uid: string;\n};\n\nexport type AttrBinding = {\n mode: 'bool' | 'attr';\n name: string;\n signal?: ReadonlySignal<unknown>;\n type: 'attr';\n uid: string;\n value?: unknown;\n};\n\nexport type PropBinding = {\n /** Optional writable source used for native two-way bridge (.value/.checked). */\n model?: Signal<unknown>;\n name: string;\n signal?: ReadonlySignal<unknown>;\n type: 'prop';\n uid: string;\n value?: unknown;\n};\n\nexport type EventBinding = {\n handler: (e: Event) => void;\n modifiers?: {\n capture?: boolean;\n once?: boolean;\n passive?: boolean;\n prevent?: boolean;\n self?: boolean;\n stop?: boolean;\n };\n name: string;\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 CallbackBinding = {\n apply: (el: HTMLElement, registerCleanup: (fn: () => void) => void) => void;\n type: 'callback';\n uid: string;\n};\n\nexport type HtmlBinding = {\n keyed?: boolean;\n signal: ReadonlySignal<{\n bindings: Binding[];\n html: string;\n items?: Array<{ bindings: Binding[]; html: string }>;\n keys?: (string | number)[];\n }>;\n type: 'html';\n uid: string;\n};\n\nexport type Binding =\n | TextBinding\n | AttrBinding\n | PropBinding\n | EventBinding\n | RefBinding\n | CallbackBinding\n | HtmlBinding;\n\n// ─────────────────────────────────────────────────────────────────────────────\n// INTERNAL MARKERS & CONSTANTS\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** @internal — opaque marker for each() reactive results. */\nexport const EACH_SIGNAL: unique symbol = Symbol('craftit.eachSignal');\n\n/** @internal — binding element identifier attribute. */\nexport const CF_ID_ATTR = 'u';\n"],"mappings":"0BAYA,IAAM,EAAmC,OAAO,0BAA0B,CAU1E,SAAgB,GAAiC,CAC/C,MAAO,CAAE,MAAO,KAAM,CAKxB,SAAgB,GAAmC,CACjD,MAAO,EAAE,CAgBX,SAAgB,EAAW,EAAc,EAAsB,EAAE,CAAc,CAC7E,IAAM,EAAS,CACb,WAAY,EACZ,OAAQ,EACR,UAAW,CACT,OAAO,GAEV,CASD,OAPA,OAAO,eAAe,EAAQ,EAAmB,CAC/C,aAAc,GACd,WAAY,GACZ,MAAO,GACP,SAAU,GACX,CAAC,CAEK,EAIT,IAAa,EAAgB,GAC3B,OAAO,GAAU,UAAY,CAAC,CAAC,GAAU,EAAkC,KAAuB,GAGpG,SAAgB,EAAc,EAA+D,CAC3F,OAAO,OAAO,GAAM,SAAW,CAAE,SAAU,EAAE,CAAE,KAAM,EAAG,CAAG,CAAE,SAAU,EAAE,WAAY,KAAM,EAAE,OAAQ,CAqGvG,IAAa,EAA6B,OAAO,qBAAqB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`./utilities.cjs`);let t=require(`@vielzeug/stateit`);var n=e=>{if((0,t.isSignal)(e))return e;if(typeof e==`function`)return(0,t.computed)(e)},r=e=>{if(!(0,t.isSignal)(e))return!1;let n=Object.getPrototypeOf(e);for(;n;){let e=Object.getOwnPropertyDescriptor(n,`value`);if(e)return typeof e.set==`function`;n=Object.getPrototypeOf(n)}return!1},i=(e,t)=>{if(!Object.is(e.value,t))try{e.value=t}catch{}},a=(t,n,r,a)=>{if(r){if(n===`value`){(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&a(e.listen(t,t instanceof HTMLSelectElement?`change`:`input`,()=>{i(r,t.value)}));return}n===`checked`&&t instanceof HTMLInputElement&&a(e.listen(t,`change`,()=>{i(r,t.checked)}))}};exports.bindPropertyModel=a,exports.hasWritableValueSetter=r,exports.toReactiveBindingSource=n;
|
|
2
|
+
//# sourceMappingURL=runtime-bindings.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-bindings.cjs","names":[],"sources":["../../src/core/runtime-bindings.ts"],"sourcesContent":["import { computed, isSignal, type ReadonlySignal, type Signal } from '@vielzeug/stateit';\n\nimport { listen } from './utilities';\n\nexport type RegisterPropertyCleanup = (fn: () => void) => void;\n\nexport const toReactiveBindingSource = (value: unknown): ReadonlySignal<unknown> | undefined => {\n if (isSignal(value)) return value as ReadonlySignal<unknown>;\n\n if (typeof value === 'function') return computed(value as () => unknown);\n\n return undefined;\n};\n\nexport const hasWritableValueSetter = (value: unknown): value is Signal<unknown> => {\n if (!isSignal(value)) return false;\n\n let proto: object | null = Object.getPrototypeOf(value);\n\n while (proto) {\n const descriptor = Object.getOwnPropertyDescriptor(proto, 'value');\n\n if (descriptor) return typeof descriptor.set === 'function';\n\n proto = Object.getPrototypeOf(proto);\n }\n\n return false;\n};\n\nconst updateModelValue = (model: Signal<unknown>, next: unknown): void => {\n if (Object.is(model.value, next)) return;\n\n try {\n model.value = next;\n } catch {\n // Readonly signal/computed source: keep one-way behavior.\n }\n};\n\nexport const bindPropertyModel = (\n el: HTMLElement,\n name: string,\n model: Signal<unknown> | undefined,\n registerCleanup: RegisterPropertyCleanup,\n): void => {\n if (!model) return;\n\n if (name === 'value') {\n if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) {\n const eventName = el instanceof HTMLSelectElement ? 'change' : 'input';\n\n registerCleanup(\n listen(el, eventName, () => {\n updateModelValue(model, el.value);\n }),\n );\n }\n\n return;\n }\n\n if (name === 'checked' && el instanceof HTMLInputElement) {\n registerCleanup(\n listen(el, 'change', () => {\n updateModelValue(model, el.checked);\n }),\n );\n }\n};\n"],"mappings":"sEAMA,IAAa,EAA2B,GAAwD,CAC9F,IAAA,EAAA,EAAA,UAAa,EAAM,CAAE,OAAO,EAE5B,GAAI,OAAO,GAAU,WAAY,OAAA,EAAA,EAAA,UAAgB,EAAuB,EAK7D,EAA0B,GAA6C,CAClF,GAAI,EAAA,EAAA,EAAA,UAAU,EAAM,CAAE,MAAO,GAE7B,IAAI,EAAuB,OAAO,eAAe,EAAM,CAEvD,KAAO,GAAO,CACZ,IAAM,EAAa,OAAO,yBAAyB,EAAO,QAAQ,CAElE,GAAI,EAAY,OAAO,OAAO,EAAW,KAAQ,WAEjD,EAAQ,OAAO,eAAe,EAAM,CAGtC,MAAO,IAGH,GAAoB,EAAwB,IAAwB,CACpE,WAAO,GAAG,EAAM,MAAO,EAAK,CAEhC,GAAI,CACF,EAAM,MAAQ,OACR,IAKG,GACX,EACA,EACA,EACA,IACS,CACJ,KAEL,IAAI,IAAS,QAAS,EAChB,aAAc,kBAAoB,aAAc,qBAAuB,aAAc,oBAGvF,EACE,EAAA,OAAO,EAHS,aAAc,kBAAoB,SAAW,YAGjC,CAC1B,EAAiB,EAAO,EAAG,MAAM,EACjC,CACH,CAGH,OAGE,IAAS,WAAa,aAAc,kBACtC,EACE,EAAA,OAAO,EAAI,aAAgB,CACzB,EAAiB,EAAO,EAAG,QAAQ,EACnC,CACH"}
|