@rippling/pebble-sdui-mobile 1.1.3 → 1.1.6

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.
@@ -32,9 +32,9 @@ export interface TemplateRef {
32
32
  }
33
33
  /**
34
34
  * Valid interpolation value inside a $template tagged template.
35
- * Accepts any expression ref that can be stringified at runtime.
35
+ * Runtime templates resolve state paths, not repeat item or index refs.
36
36
  */
37
- export type TemplateInterpolation = StateRef<unknown> | ItemRef<unknown> | IndexRef | null | undefined;
37
+ export type TemplateInterpolation = StateRef<unknown> | null | undefined;
38
38
  /** Conditional expression with typed branches. Uses T directly to avoid circular PropValue recursion. */
39
39
  export interface CondRef<T> {
40
40
  readonly $cond: unknown;
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function I($,w){const p={},m=new Map,h=new WeakMap,b=new WeakSet,f=new Set;let S=0;function t(n,s=new WeakSet){var l;const o=n;if(s.has(o))return;s.add(o);const e=n;if(e.id!==void 0){const r=m.get(e.id);if(r&&r!==o)throw new Error(`Duplicate element id: ${e.id}`);m.set(e.id,o),f.add(e.id)}(l=e.children)==null||l.forEach(r=>t(r,s)),Object.values(e.slots??{}).forEach(r=>r.forEach(u=>t(u,s)))}function a(){let n;do n=`element-${S}`,S+=1;while(f.has(n));return f.add(n),n}function c(n){const s=n,o=h.get(s);if(o)return o;const l=n.id??a();return h.set(s,l),l}function d(n){const s=n,o=c(n);if(b.has(s))return o;b.add(s);const e=n,l=e.children?e.children.map(u=>d(u)):[],r={type:e.type,props:e.props,children:l};return e.slots&&(r.slots=Object.fromEntries(Object.entries(e.slots).map(([u,g])=>[u,g.map(x=>d(x))]))),e.visible!==void 0&&(r.visible=e.visible),e.on&&(r.on=e.on),e.watch&&(r.watch=e.watch),e.repeat&&(r.repeat=e.repeat),p[o]=r,o}t($);const i=d($);return JSON.parse(JSON.stringify({root:i,elements:p,state:w}))}function E($){const w=$.state;function p(t){return{$state:t}}function m(t){return{$bindState:t}}function h(t,...a){let c=t[0];for(let d=0;d<a.length;d+=1){const i=a[d];!i||typeof i!="object"?c+="":"$state"in i?c+=`\${${i.$state}}`:"$item"in i?c+=`\${$item.${i.$item}}`:"$index"in i&&(c+="${$index}"),c+=t[d+1]}return{$template:c}}function b(t,a,c){return{$cond:t,$then:a,$else:c}}function f(t,a){return[{statePath:t,key:a},{$(i){return{$item:i}},$bind(i){return{$bindItem:i}},$index(){return{$index:!0}}}]}function S(t){return I(t,w)}return{$state:p,$bindState:m,$template:h,$cond:b,repeat:f,render:S}}exports.createSpec=E;exports.renderElementTree=I;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(p,S){const $={},m=new Map,h=new WeakMap,b=new WeakSet,u=new Set;let w=0;function t(n,c=new WeakSet){var l;const o=n;if(c.has(o))return;c.add(o);const e=n;if(e.id!==void 0){const r=m.get(e.id);if(r&&r!==o)throw new Error(`Duplicate element id: ${e.id}`);m.set(e.id,o),u.add(e.id)}(l=e.children)==null||l.forEach(r=>t(r,c)),Object.values(e.slots??{}).forEach(r=>r.forEach(f=>t(f,c)))}function a(){let n;do n=`element-${w}`,w+=1;while(u.has(n));return u.add(n),n}function s(n){const c=n,o=h.get(c);if(o)return o;const l=n.id??a();return h.set(c,l),l}function d(n){const c=n,o=s(n);if(b.has(c))return o;b.add(c);const e=n,l=e.children?e.children.map(f=>d(f)):[],r={type:e.type,props:e.props,children:l};return e.slots&&(r.slots=Object.fromEntries(Object.entries(e.slots).map(([f,E])=>[f,E.map(I=>d(I))]))),e.visible!==void 0&&(r.visible=e.visible),e.on&&(r.on=e.on),e.watch&&(r.watch=e.watch),e.repeat&&(r.repeat=e.repeat),$[o]=r,o}t(p);const i=d(p);return JSON.parse(JSON.stringify({root:i,elements:$,state:S}))}function y(p){const S=p.state;function $(t){return{$state:t}}function m(t){return{$bindState:t}}function h(t,...a){let s=t[0];for(let d=0;d<a.length;d+=1){const i=a[d];if(i==null)s+="";else if(typeof i=="object"&&"$state"in i&&typeof i.$state=="string")s+=`\${${i.$state}}`;else throw new TypeError("$template only supports state refs, null, and undefined");s+=t[d+1]}return{$template:s}}function b(t,a,s){return{$cond:t,$then:a,$else:s}}function u(t,a){return[{statePath:t,key:a},{$(i){return{$item:i}},$bind(i){return{$bindItem:i}},$index(){return{$index:!0}}}]}function w(t){return g(t,S)}return{$state:$,$bindState:m,$template:h,$cond:b,repeat:u,render:w}}exports.createSpec=y;exports.renderElementTree=g;
2
2
  //# sourceMappingURL=spec.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"spec.cjs","sources":["../../../sdui-core/src/spec.ts"],"sourcesContent":["/**\n * createSpec - Factory for state-bound expression helpers + render\n *\n * Mirrors Python SDK's StateHandle + render module.\n */\n\nimport type {\n StatePaths,\n ValueAt,\n ArrayPaths,\n ArrayItemAt,\n ItemPaths,\n ItemValueAt,\n} from './paths';\nimport type {\n StateRef,\n BindStateRef,\n ItemRef,\n BindItemRef,\n IndexRef,\n TemplateRef,\n TemplateInterpolation,\n CondRef,\n PropValue,\n} from './expressions';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\nimport type { InternalElementNode } from './component-utils';\n\n/** Typed accessor for repeat item fields. */\nexport interface ItemAccessor<TItem> {\n /** Read a field from the current repeat item. */\n $<P extends ItemPaths<TItem>>(path: P): ItemRef<ItemValueAt<TItem, P>>;\n /** Two-way bind to a field on the current repeat item. */\n $bind<P extends ItemPaths<TItem>>(\n path: P\n ): BindItemRef<ItemValueAt<TItem, P>>;\n /** Current repeat index (number). */\n $index(): IndexRef;\n}\n\nexport interface FlatUIElement {\n type: string;\n props: Record<string, unknown>;\n children?: string[];\n slots?: Record<string, string[]>;\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\nexport interface FlatSpec {\n root: string;\n elements: Record<string, FlatUIElement>;\n state?: Record<string, unknown>;\n}\n\nexport type Spec = FlatSpec;\nexport type CoreSpec = FlatSpec;\n\n/**\n * Flatten an element tree into a flat spec format.\n * Uses JSON round-trip to strip Symbol properties and undefined values,\n * ensuring clean serialization.\n */\nexport function renderElementTree(root: ElementNode, state?: object): FlatSpec {\n const elements: Record<string, FlatUIElement> = {};\n const explicitIds = new Map<string, object>();\n const elementIds = new WeakMap<object, string>();\n const emitted = new WeakSet<object>();\n const usedIds = new Set<string>();\n let nextGeneratedId = 0;\n\n function collectExplicitIds(\n node: ElementNode,\n seen = new WeakSet<object>()\n ): void {\n const nodeObject = node as unknown as object;\n if (seen.has(nodeObject)) {\n return;\n }\n seen.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n if (n.id !== undefined) {\n const existing = explicitIds.get(n.id);\n if (existing && existing !== nodeObject) {\n throw new Error(`Duplicate element id: ${n.id}`);\n }\n explicitIds.set(n.id, nodeObject);\n usedIds.add(n.id);\n }\n\n n.children?.forEach(child => collectExplicitIds(child, seen));\n Object.values(n.slots ?? {}).forEach(slotChildren =>\n slotChildren.forEach(child => collectExplicitIds(child, seen))\n );\n }\n\n function allocateGeneratedId(): string {\n let id: string;\n do {\n id = `element-${nextGeneratedId}`;\n nextGeneratedId += 1;\n } while (usedIds.has(id));\n\n usedIds.add(id);\n return id;\n }\n\n function elementId(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const existing = elementIds.get(nodeObject);\n if (existing) {\n return existing;\n }\n\n const n = node as unknown as InternalElementNode;\n const id = n.id ?? allocateGeneratedId();\n elementIds.set(nodeObject, id);\n return id;\n }\n\n function flatten(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const id = elementId(node);\n if (emitted.has(nodeObject)) {\n return id;\n }\n emitted.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n const childIds: string[] = n.children\n ? n.children.map(child => flatten(child))\n : [];\n\n const flatElement: FlatUIElement = {\n type: n.type,\n props: n.props,\n children: childIds,\n };\n if (n.slots) {\n flatElement.slots = Object.fromEntries(\n Object.entries(n.slots).map(([name, slotChildren]) => [\n name,\n slotChildren.map(child => flatten(child)),\n ])\n );\n }\n\n if (n.visible !== undefined) {\n flatElement.visible = n.visible;\n }\n if (n.on) {\n flatElement.on = n.on;\n }\n if (n.watch) {\n flatElement.watch = n.watch;\n }\n if (n.repeat) {\n flatElement.repeat = n.repeat;\n }\n\n elements[id] = flatElement;\n return id;\n }\n\n collectExplicitIds(root);\n const rootId = flatten(root);\n\n return JSON.parse(\n JSON.stringify({\n root: rootId,\n elements,\n state,\n })\n ) as FlatSpec;\n}\n\nexport interface SpecContext<TState> {\n /** Read-only reference to a state path. */\n $state<P extends StatePaths<TState>>(path: P): StateRef<ValueAt<TState, P>>;\n\n /** Two-way binding to a state path. */\n $bindState<P extends StatePaths<TState>>(\n path: P\n ): BindStateRef<ValueAt<TState, P>>;\n\n /** String template expression (tagged template literal). */\n $template(\n strings: TemplateStringsArray,\n ...values: TemplateInterpolation[]\n ): TemplateRef;\n\n /** Conditional expression with typed branches. */\n $cond<T>(\n condition: VisibilityBinding | boolean,\n then: PropValue<T>,\n else_: PropValue<T>\n ): CondRef<T>;\n\n /**\n * Create a repeat binding for an array state path.\n * Returns [RepeatBinding, ItemAccessor<T>].\n */\n repeat<P extends ArrayPaths<TState>>(\n statePath: P,\n key?: string\n ): [RepeatBinding, ItemAccessor<ArrayItemAt<TState, P>>];\n\n /** Flatten an element tree into the flat spec format. */\n render(root: ElementNode): FlatSpec;\n}\n\nexport function createSpec<TState extends object>(config: {\n state: TState;\n}): SpecContext<TState> {\n const initialState = config.state;\n\n function $state(path: string): unknown {\n return { $state: path };\n }\n\n function $bindState(path: string): unknown {\n return { $bindState: path };\n }\n\n /**\n * Build a template string from a tagged template literal.\n * Converts expression refs ($state, $item, $index) into template variables.\n */\n function $template(\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): unknown {\n let result = strings[0];\n for (let i = 0; i < values.length; i += 1) {\n const val = values[i];\n if (!val || typeof val !== 'object') {\n result += '';\n } else if ('$state' in val) {\n result += `\\${${val.$state}}`;\n } else if ('$item' in val) {\n result += `\\${$item.${val.$item}}`;\n } else if ('$index' in val) {\n result += '${$index}';\n }\n result += strings[i + 1];\n }\n return { $template: result };\n }\n\n function $cond(condition: unknown, then: unknown, else_: unknown): unknown {\n return { $cond: condition, $then: then, $else: else_ };\n }\n\n /**\n * Create a repeat binding for array iteration.\n * Returns [RepeatBinding, ItemAccessor] tuple.\n *\n * Type safety is enforced at the createSpec boundary through type parameters.\n * Internal implementations use `any` to work with the opaque branded types.\n */\n function repeat(\n statePath: string,\n key?: string\n ): [unknown, ItemAccessor<unknown>] {\n const repeatBinding = { statePath, key } as unknown as RepeatBinding;\n\n const itemAccessor: ItemAccessor<unknown> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $(path: string): any {\n return { $item: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $bind(path: string): any {\n return { $bindItem: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $index(): any {\n return { $index: true };\n },\n };\n\n return [repeatBinding, itemAccessor];\n }\n\n function render(root: ElementNode): FlatSpec {\n return renderElementTree(root, initialState);\n }\n\n return {\n $state,\n $bindState,\n $template,\n $cond,\n repeat,\n render,\n } as unknown as SpecContext<TState>;\n}\n"],"names":["renderElementTree","root","state","elements","explicitIds","elementIds","emitted","usedIds","nextGeneratedId","collectExplicitIds","node","seen","nodeObject","n","existing","_a","child","slotChildren","allocateGeneratedId","id","elementId","flatten","childIds","flatElement","name","rootId","createSpec","config","initialState","$state","path","$bindState","$template","strings","values","result","i","val","$cond","condition","then","else_","repeat","statePath","key","render"],"mappings":"gFAkEO,SAASA,EAAkBC,EAAmBC,EAA0B,CAC7E,MAAMC,EAA0C,CAAA,EAC1CC,MAAkB,IAClBC,MAAiB,QACjBC,MAAc,QACdC,MAAc,IACpB,IAAIC,EAAkB,EAEtB,SAASC,EACPC,EACAC,EAAO,IAAI,QACL,OACN,MAAMC,EAAaF,EACn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UAAAD,EAAW,IAAAC,CAAA,EAES,CAE1C,EAAEd,EAAmB,CACnB,MAAO,CAAE,MAAOA,CAAA,CAClB,EAEA,MAAMA,EAAmB,CACvB,MAAO,CAAE,UAAWA,CAAA,CACtB,EAEA,QAAc,CACZ,MAAO,CAAE,OAAQ,EAAA,CACnB,CAAA,CAGiC,CACrC,CAEA,SAASe,EAAO5C,EAA6B,CAC3C,OAAOD,EAAkBC,EAAM2B,CAAY,CAC7C,CAEA,MAAO,CACL,OAAAC,EACA,WAAAE,EACA,UAAAC,EACA,MAAAM,EACA,OAAAI,EACA,OAAAG,CAAA,CAEJ"}
1
+ {"version":3,"file":"spec.cjs","sources":["../../../sdui-core/src/spec.ts"],"sourcesContent":["/**\n * createSpec - Factory for state-bound expression helpers + render\n *\n * Mirrors Python SDK's StateHandle + render module.\n */\n\nimport type {\n StatePaths,\n ValueAt,\n ArrayPaths,\n ArrayItemAt,\n ItemPaths,\n ItemValueAt,\n} from './paths';\nimport type {\n StateRef,\n BindStateRef,\n ItemRef,\n BindItemRef,\n IndexRef,\n TemplateRef,\n TemplateInterpolation,\n CondRef,\n PropValue,\n} from './expressions';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\nimport type { InternalElementNode } from './component-utils';\n\n/** Typed accessor for repeat item fields. */\nexport interface ItemAccessor<TItem> {\n /** Read a field from the current repeat item. */\n $<P extends ItemPaths<TItem>>(path: P): ItemRef<ItemValueAt<TItem, P>>;\n /** Two-way bind to a field on the current repeat item. */\n $bind<P extends ItemPaths<TItem>>(\n path: P\n ): BindItemRef<ItemValueAt<TItem, P>>;\n /** Current repeat index (number). */\n $index(): IndexRef;\n}\n\nexport interface FlatUIElement {\n type: string;\n props: Record<string, unknown>;\n children?: string[];\n slots?: Record<string, string[]>;\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\nexport interface FlatSpec {\n root: string;\n elements: Record<string, FlatUIElement>;\n state?: Record<string, unknown>;\n}\n\nexport type Spec = FlatSpec;\nexport type CoreSpec = FlatSpec;\n\n/**\n * Flatten an element tree into a flat spec format.\n * Uses JSON round-trip to strip Symbol properties and undefined values,\n * ensuring clean serialization.\n */\nexport function renderElementTree(root: ElementNode, state?: object): FlatSpec {\n const elements: Record<string, FlatUIElement> = {};\n const explicitIds = new Map<string, object>();\n const elementIds = new WeakMap<object, string>();\n const emitted = new WeakSet<object>();\n const usedIds = new Set<string>();\n let nextGeneratedId = 0;\n\n function collectExplicitIds(\n node: ElementNode,\n seen = new WeakSet<object>()\n ): void {\n const nodeObject = node as unknown as object;\n if (seen.has(nodeObject)) {\n return;\n }\n seen.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n if (n.id !== undefined) {\n const existing = explicitIds.get(n.id);\n if (existing && existing !== nodeObject) {\n throw new Error(`Duplicate element id: ${n.id}`);\n }\n explicitIds.set(n.id, nodeObject);\n usedIds.add(n.id);\n }\n\n n.children?.forEach(child => collectExplicitIds(child, seen));\n Object.values(n.slots ?? {}).forEach(slotChildren =>\n slotChildren.forEach(child => collectExplicitIds(child, seen))\n );\n }\n\n function allocateGeneratedId(): string {\n let id: string;\n do {\n id = `element-${nextGeneratedId}`;\n nextGeneratedId += 1;\n } while (usedIds.has(id));\n\n usedIds.add(id);\n return id;\n }\n\n function elementId(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const existing = elementIds.get(nodeObject);\n if (existing) {\n return existing;\n }\n\n const n = node as unknown as InternalElementNode;\n const id = n.id ?? allocateGeneratedId();\n elementIds.set(nodeObject, id);\n return id;\n }\n\n function flatten(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const id = elementId(node);\n if (emitted.has(nodeObject)) {\n return id;\n }\n emitted.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n const childIds: string[] = n.children\n ? n.children.map(child => flatten(child))\n : [];\n\n const flatElement: FlatUIElement = {\n type: n.type,\n props: n.props,\n children: childIds,\n };\n if (n.slots) {\n flatElement.slots = Object.fromEntries(\n Object.entries(n.slots).map(([name, slotChildren]) => [\n name,\n slotChildren.map(child => flatten(child)),\n ])\n );\n }\n\n if (n.visible !== undefined) {\n flatElement.visible = n.visible;\n }\n if (n.on) {\n flatElement.on = n.on;\n }\n if (n.watch) {\n flatElement.watch = n.watch;\n }\n if (n.repeat) {\n flatElement.repeat = n.repeat;\n }\n\n elements[id] = flatElement;\n return id;\n }\n\n collectExplicitIds(root);\n const rootId = flatten(root);\n\n return JSON.parse(\n JSON.stringify({\n root: rootId,\n elements,\n state,\n })\n ) as FlatSpec;\n}\n\nexport interface SpecContext<TState> {\n /** Read-only reference to a state path. */\n $state<P extends StatePaths<TState>>(path: P): StateRef<ValueAt<TState, P>>;\n\n /** Two-way binding to a state path. */\n $bindState<P extends StatePaths<TState>>(\n path: P\n ): BindStateRef<ValueAt<TState, P>>;\n\n /** String template expression (tagged template literal). */\n $template(\n strings: TemplateStringsArray,\n ...values: TemplateInterpolation[]\n ): TemplateRef;\n\n /** Conditional expression with typed branches. */\n $cond<T>(\n condition: VisibilityBinding | boolean,\n then: PropValue<T>,\n else_: PropValue<T>\n ): CondRef<T>;\n\n /**\n * Create a repeat binding for an array state path.\n * Returns [RepeatBinding, ItemAccessor<T>].\n */\n repeat<P extends ArrayPaths<TState>>(\n statePath: P,\n key?: string\n ): [RepeatBinding, ItemAccessor<ArrayItemAt<TState, P>>];\n\n /** Flatten an element tree into the flat spec format. */\n render(root: ElementNode): FlatSpec;\n}\n\nexport function createSpec<TState extends object>(config: {\n state: TState;\n}): SpecContext<TState> {\n const initialState = config.state;\n\n function $state(path: string): unknown {\n return { $state: path };\n }\n\n function $bindState(path: string): unknown {\n return { $bindState: path };\n }\n\n /**\n * Build a template string from a tagged template literal.\n * Converts state refs into runtime template variables.\n */\n function $template(\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): unknown {\n let result = strings[0];\n for (let i = 0; i < values.length; i += 1) {\n const val = values[i];\n if (val === null || val === undefined) {\n result += '';\n } else if (\n typeof val === 'object' &&\n '$state' in val &&\n typeof val.$state === 'string'\n ) {\n result += `\\${${val.$state}}`;\n } else {\n throw new TypeError(\n '$template only supports state refs, null, and undefined'\n );\n }\n result += strings[i + 1];\n }\n return { $template: result };\n }\n\n function $cond(condition: unknown, then: unknown, else_: unknown): unknown {\n return { $cond: condition, $then: then, $else: else_ };\n }\n\n /**\n * Create a repeat binding for array iteration.\n * Returns [RepeatBinding, ItemAccessor] tuple.\n *\n * Type safety is enforced at the createSpec boundary through type parameters.\n * Internal implementations use `any` to work with the opaque branded types.\n */\n function repeat(\n statePath: string,\n key?: string\n ): [unknown, ItemAccessor<unknown>] {\n const repeatBinding = { statePath, key } as unknown as RepeatBinding;\n\n const itemAccessor: ItemAccessor<unknown> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $(path: string): any {\n return { $item: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $bind(path: string): any {\n return { $bindItem: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $index(): any {\n return { $index: true };\n },\n };\n\n return [repeatBinding, itemAccessor];\n }\n\n function render(root: ElementNode): FlatSpec {\n return renderElementTree(root, initialState);\n }\n\n return {\n $state,\n $bindState,\n $template,\n $cond,\n repeat,\n render,\n } as unknown as SpecContext<TState>;\n}\n"],"names":["renderElementTree","root","state","elements","explicitIds","elementIds","emitted","usedIds","nextGeneratedId","collectExplicitIds","node","seen","nodeObject","n","existing","_a","child","slotChildren","allocateGeneratedId","id","elementId","flatten","childIds","flatElement","name","rootId","createSpec","config","initialState","$state","path","$bindState","$template","strings","values","result","i","val","$cond","condition","then","else_","repeat","statePath","key","render"],"mappings":"gFAkEO,SAASA,EAAkBC,EAAmBC,EAA0B,CAC7E,MAAMC,EAA0C,CAAA,EAC1CC,MAAkB,IAClBC,MAAiB,QACjBC,MAAc,QACdC,MAAc,IACpB,IAAIC,EAAkB,EAEtB,SAASC,EACPC,EACAC,EAAO,IA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BlC,MAAO,CAjBe,CAAE,UAAAD,EAAW,IAAAC,CAAA,EAES,CAE1C,EAAEd,EAAmB,CACnB,MAAO,CAAE,MAAOA,CAAA,CAClB,EAEA,MAAMA,EAAmB,CACvB,MAAO,CAAE,UAAWA,CAAA,CACtB,EAEA,QAAc,CACZ,MAAO,CAAE,OAAQ,EAAA,CACnB,CAAA,CAGiC,CACrC,CAEA,SAASe,EAAO5C,EAA6B,CAC3C,OAAOD,EAAkBC,EAAM2B,CAAY,CAC7C,CAEA,MAAO,CACL,OAAAC,EACA,WAAAE,EACA,UAAAC,EACA,MAAAM,EACA,OAAAI,EACA,OAAAG,CAAA,CAEJ"}
package/dist/core/spec.js CHANGED
@@ -1,92 +1,100 @@
1
- function E($, x) {
2
- const p = {}, m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakSet(), f = /* @__PURE__ */ new Set();
1
+ function g(p, I) {
2
+ const $ = {}, h = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakSet(), u = /* @__PURE__ */ new Set();
3
3
  let w = 0;
4
- function t(n, s = /* @__PURE__ */ new WeakSet()) {
4
+ function e(n, s = /* @__PURE__ */ new WeakSet()) {
5
5
  var l;
6
6
  const o = n;
7
7
  if (s.has(o))
8
8
  return;
9
9
  s.add(o);
10
- const e = n;
11
- if (e.id !== void 0) {
12
- const r = m.get(e.id);
13
- if (r && r !== o)
14
- throw new Error(`Duplicate element id: ${e.id}`);
15
- m.set(e.id, o), f.add(e.id);
10
+ const t = n;
11
+ if (t.id !== void 0) {
12
+ const i = h.get(t.id);
13
+ if (i && i !== o)
14
+ throw new Error(`Duplicate element id: ${t.id}`);
15
+ h.set(t.id, o), u.add(t.id);
16
16
  }
17
- (l = e.children) == null || l.forEach((r) => t(r, s)), Object.values(e.slots ?? {}).forEach(
18
- (r) => r.forEach((u) => t(u, s))
17
+ (l = t.children) == null || l.forEach((i) => e(i, s)), Object.values(t.slots ?? {}).forEach(
18
+ (i) => i.forEach((f) => e(f, s))
19
19
  );
20
20
  }
21
21
  function a() {
22
22
  let n;
23
23
  do
24
24
  n = `element-${w}`, w += 1;
25
- while (f.has(n));
26
- return f.add(n), n;
25
+ while (u.has(n));
26
+ return u.add(n), n;
27
27
  }
28
28
  function c(n) {
29
- const s = n, o = h.get(s);
29
+ const s = n, o = m.get(s);
30
30
  if (o)
31
31
  return o;
32
32
  const l = n.id ?? a();
33
- return h.set(s, l), l;
33
+ return m.set(s, l), l;
34
34
  }
35
35
  function d(n) {
36
36
  const s = n, o = c(n);
37
37
  if (b.has(s))
38
38
  return o;
39
39
  b.add(s);
40
- const e = n, l = e.children ? e.children.map((u) => d(u)) : [], r = {
41
- type: e.type,
42
- props: e.props,
40
+ const t = n, l = t.children ? t.children.map((f) => d(f)) : [], i = {
41
+ type: t.type,
42
+ props: t.props,
43
43
  children: l
44
44
  };
45
- return e.slots && (r.slots = Object.fromEntries(
46
- Object.entries(e.slots).map(([u, I]) => [
47
- u,
48
- I.map((S) => d(S))
45
+ return t.slots && (i.slots = Object.fromEntries(
46
+ Object.entries(t.slots).map(([f, E]) => [
47
+ f,
48
+ E.map((S) => d(S))
49
49
  ])
50
- )), e.visible !== void 0 && (r.visible = e.visible), e.on && (r.on = e.on), e.watch && (r.watch = e.watch), e.repeat && (r.repeat = e.repeat), p[o] = r, o;
50
+ )), t.visible !== void 0 && (i.visible = t.visible), t.on && (i.on = t.on), t.watch && (i.watch = t.watch), t.repeat && (i.repeat = t.repeat), $[o] = i, o;
51
51
  }
52
- t($);
53
- const i = d($);
52
+ e(p);
53
+ const r = d(p);
54
54
  return JSON.parse(
55
55
  JSON.stringify({
56
- root: i,
57
- elements: p,
58
- state: x
56
+ root: r,
57
+ elements: $,
58
+ state: I
59
59
  })
60
60
  );
61
61
  }
62
- function O($) {
63
- const x = $.state;
64
- function p(t) {
65
- return { $state: t };
62
+ function x(p) {
63
+ const I = p.state;
64
+ function $(e) {
65
+ return { $state: e };
66
66
  }
67
- function m(t) {
68
- return { $bindState: t };
67
+ function h(e) {
68
+ return { $bindState: e };
69
69
  }
70
- function h(t, ...a) {
71
- let c = t[0];
70
+ function m(e, ...a) {
71
+ let c = e[0];
72
72
  for (let d = 0; d < a.length; d += 1) {
73
- const i = a[d];
74
- !i || typeof i != "object" ? c += "" : "$state" in i ? c += `\${${i.$state}}` : "$item" in i ? c += `\${$item.${i.$item}}` : "$index" in i && (c += "${$index}"), c += t[d + 1];
73
+ const r = a[d];
74
+ if (r == null)
75
+ c += "";
76
+ else if (typeof r == "object" && "$state" in r && typeof r.$state == "string")
77
+ c += `\${${r.$state}}`;
78
+ else
79
+ throw new TypeError(
80
+ "$template only supports state refs, null, and undefined"
81
+ );
82
+ c += e[d + 1];
75
83
  }
76
84
  return { $template: c };
77
85
  }
78
- function b(t, a, c) {
79
- return { $cond: t, $then: a, $else: c };
86
+ function b(e, a, c) {
87
+ return { $cond: e, $then: a, $else: c };
80
88
  }
81
- function f(t, a) {
82
- return [{ statePath: t, key: a }, {
89
+ function u(e, a) {
90
+ return [{ statePath: e, key: a }, {
83
91
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
- $(i) {
85
- return { $item: i };
92
+ $(r) {
93
+ return { $item: r };
86
94
  },
87
95
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
- $bind(i) {
89
- return { $bindItem: i };
96
+ $bind(r) {
97
+ return { $bindItem: r };
90
98
  },
91
99
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
100
  $index() {
@@ -94,20 +102,20 @@ function O($) {
94
102
  }
95
103
  }];
96
104
  }
97
- function w(t) {
98
- return E(t, x);
105
+ function w(e) {
106
+ return g(e, I);
99
107
  }
100
108
  return {
101
- $state: p,
102
- $bindState: m,
103
- $template: h,
109
+ $state: $,
110
+ $bindState: h,
111
+ $template: m,
104
112
  $cond: b,
105
- repeat: f,
113
+ repeat: u,
106
114
  render: w
107
115
  };
108
116
  }
109
117
  export {
110
- O as createSpec,
111
- E as renderElementTree
118
+ x as createSpec,
119
+ g as renderElementTree
112
120
  };
113
121
  //# sourceMappingURL=spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spec.js","sources":["../../../sdui-core/src/spec.ts"],"sourcesContent":["/**\n * createSpec - Factory for state-bound expression helpers + render\n *\n * Mirrors Python SDK's StateHandle + render module.\n */\n\nimport type {\n StatePaths,\n ValueAt,\n ArrayPaths,\n ArrayItemAt,\n ItemPaths,\n ItemValueAt,\n} from './paths';\nimport type {\n StateRef,\n BindStateRef,\n ItemRef,\n BindItemRef,\n IndexRef,\n TemplateRef,\n TemplateInterpolation,\n CondRef,\n PropValue,\n} from './expressions';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\nimport type { InternalElementNode } from './component-utils';\n\n/** Typed accessor for repeat item fields. */\nexport interface ItemAccessor<TItem> {\n /** Read a field from the current repeat item. */\n $<P extends ItemPaths<TItem>>(path: P): ItemRef<ItemValueAt<TItem, P>>;\n /** Two-way bind to a field on the current repeat item. */\n $bind<P extends ItemPaths<TItem>>(\n path: P\n ): BindItemRef<ItemValueAt<TItem, P>>;\n /** Current repeat index (number). */\n $index(): IndexRef;\n}\n\nexport interface FlatUIElement {\n type: string;\n props: Record<string, unknown>;\n children?: string[];\n slots?: Record<string, string[]>;\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\nexport interface FlatSpec {\n root: string;\n elements: Record<string, FlatUIElement>;\n state?: Record<string, unknown>;\n}\n\nexport type Spec = FlatSpec;\nexport type CoreSpec = FlatSpec;\n\n/**\n * Flatten an element tree into a flat spec format.\n * Uses JSON round-trip to strip Symbol properties and undefined values,\n * ensuring clean serialization.\n */\nexport function renderElementTree(root: ElementNode, state?: object): FlatSpec {\n const elements: Record<string, FlatUIElement> = {};\n const explicitIds = new Map<string, object>();\n const elementIds = new WeakMap<object, string>();\n const emitted = new WeakSet<object>();\n const usedIds = new Set<string>();\n let nextGeneratedId = 0;\n\n function collectExplicitIds(\n node: ElementNode,\n seen = new WeakSet<object>()\n ): void {\n const nodeObject = node as unknown as object;\n if (seen.has(nodeObject)) {\n return;\n }\n seen.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n if (n.id !== undefined) {\n const existing = explicitIds.get(n.id);\n if (existing && existing !== nodeObject) {\n throw new Error(`Duplicate element id: ${n.id}`);\n }\n explicitIds.set(n.id, nodeObject);\n usedIds.add(n.id);\n }\n\n n.children?.forEach(child => collectExplicitIds(child, seen));\n Object.values(n.slots ?? {}).forEach(slotChildren =>\n slotChildren.forEach(child => collectExplicitIds(child, seen))\n );\n }\n\n function allocateGeneratedId(): string {\n let id: string;\n do {\n id = `element-${nextGeneratedId}`;\n nextGeneratedId += 1;\n } while (usedIds.has(id));\n\n usedIds.add(id);\n return id;\n }\n\n function elementId(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const existing = elementIds.get(nodeObject);\n if (existing) {\n return existing;\n }\n\n const n = node as unknown as InternalElementNode;\n const id = n.id ?? allocateGeneratedId();\n elementIds.set(nodeObject, id);\n return id;\n }\n\n function flatten(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const id = elementId(node);\n if (emitted.has(nodeObject)) {\n return id;\n }\n emitted.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n const childIds: string[] = n.children\n ? n.children.map(child => flatten(child))\n : [];\n\n const flatElement: FlatUIElement = {\n type: n.type,\n props: n.props,\n children: childIds,\n };\n if (n.slots) {\n flatElement.slots = Object.fromEntries(\n Object.entries(n.slots).map(([name, slotChildren]) => [\n name,\n slotChildren.map(child => flatten(child)),\n ])\n );\n }\n\n if (n.visible !== undefined) {\n flatElement.visible = n.visible;\n }\n if (n.on) {\n flatElement.on = n.on;\n }\n if (n.watch) {\n flatElement.watch = n.watch;\n }\n if (n.repeat) {\n flatElement.repeat = n.repeat;\n }\n\n elements[id] = flatElement;\n return id;\n }\n\n collectExplicitIds(root);\n const rootId = flatten(root);\n\n return JSON.parse(\n JSON.stringify({\n root: rootId,\n elements,\n state,\n })\n ) as FlatSpec;\n}\n\nexport interface SpecContext<TState> {\n /** Read-only reference to a state path. */\n $state<P extends StatePaths<TState>>(path: P): StateRef<ValueAt<TState, P>>;\n\n /** Two-way binding to a state path. */\n $bindState<P extends StatePaths<TState>>(\n path: P\n ): BindStateRef<ValueAt<TState, P>>;\n\n /** String template expression (tagged template literal). */\n $template(\n strings: TemplateStringsArray,\n ...values: TemplateInterpolation[]\n ): TemplateRef;\n\n /** Conditional expression with typed branches. */\n $cond<T>(\n condition: VisibilityBinding | boolean,\n then: PropValue<T>,\n else_: PropValue<T>\n ): CondRef<T>;\n\n /**\n * Create a repeat binding for an array state path.\n * Returns [RepeatBinding, ItemAccessor<T>].\n */\n repeat<P extends ArrayPaths<TState>>(\n statePath: P,\n key?: string\n ): [RepeatBinding, ItemAccessor<ArrayItemAt<TState, P>>];\n\n /** Flatten an element tree into the flat spec format. */\n render(root: ElementNode): FlatSpec;\n}\n\nexport function createSpec<TState extends object>(config: {\n state: TState;\n}): SpecContext<TState> {\n const initialState = config.state;\n\n function $state(path: string): unknown {\n return { $state: path };\n }\n\n function $bindState(path: string): unknown {\n return { $bindState: path };\n }\n\n /**\n * Build a template string from a tagged template literal.\n * Converts expression refs ($state, $item, $index) into template variables.\n */\n function $template(\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): unknown {\n let result = strings[0];\n for (let i = 0; i < values.length; i += 1) {\n const val = values[i];\n if (!val || typeof val !== 'object') {\n result += '';\n } else if ('$state' in val) {\n result += `\\${${val.$state}}`;\n } else if ('$item' in val) {\n result += `\\${$item.${val.$item}}`;\n } else if ('$index' in val) {\n result += '${$index}';\n }\n result += strings[i + 1];\n }\n return { $template: result };\n }\n\n function $cond(condition: unknown, then: unknown, else_: unknown): unknown {\n return { $cond: condition, $then: then, $else: else_ };\n }\n\n /**\n * Create a repeat binding for array iteration.\n * Returns [RepeatBinding, ItemAccessor] tuple.\n *\n * Type safety is enforced at the createSpec boundary through type parameters.\n * Internal implementations use `any` to work with the opaque branded types.\n */\n function repeat(\n statePath: string,\n key?: string\n ): [unknown, ItemAccessor<unknown>] {\n const repeatBinding = { statePath, key } as unknown as RepeatBinding;\n\n const itemAccessor: ItemAccessor<unknown> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $(path: string): any {\n return { $item: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $bind(path: string): any {\n return { $bindItem: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $index(): any {\n return { $index: true };\n },\n };\n\n return [repeatBinding, itemAccessor];\n }\n\n function render(root: ElementNode): FlatSpec {\n return renderElementTree(root, initialState);\n }\n\n return {\n $state,\n $bindState,\n $template,\n $cond,\n repeat,\n render,\n } as unknown as SpecContext<TState>;\n}\n"],"names":["renderElementTree","root","state","elements","explicitIds","elementIds","emitted","usedIds","nextGeneratedId","collectExplicitIds","node","seen","_a","nodeObject","n","existing","child","slotChildren","allocateGeneratedId","id","elementId","flatten","childIds","flatElement","name","rootId","createSpec","config","initialState","$state","path","$bindState","$template","strings","values","result","i","val","$cond","condition","then","else_","repeat","statePath","key","render"],"mappings":"AAkEO,SAASA,EAAkBC,GAAmBC,GAA0B;AAC7E,QAAMC,IAA0C,CAAA,GAC1CC,wBAAkB,IAAA,GAClBC,wBAAiB,QAAA,GACjBC,wBAAc,QAAA,GACdC,wBAAc,IAAA;AACpB,MAAIC,IAAkB;AAEtB,WAASC,EACPC,GACAC,IAAO,oBAAI,WACL;AAXH,QAAAC;AAYH,UAAMC,IAAaH;AACnB,QAAIC,EAAK,IAAIE,CAAU;AACrB;AAEF,IAAAF,EAAK,IAAIE,CAAU;AAEnB,UAAMC,IAAIJ;AACV,QAAII,EAAE,OAAO,QAAW;AACtB,YAAMC,IAAWX,EAAY,IAAIU,EAAE,EAAE;AACrC,UAAIC,KAAYA,MAAaF;AAC3B,cAAM,IAAI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ACAC,GACkC;AAkBlC,WAAO,CAjBe,EAAE,WAAAD,GAAW,KAAAC,EAAA,GAES;AAAA;AAAA,MAE1C,EAAEd,GAAmB;AACnB,eAAO,EAAE,OAAOA,EAAA;AAAA,MAClB;AAAA;AAAA,MAEA,MAAMA,GAAmB;AACvB,eAAO,EAAE,WAAWA,EAAA;AAAA,MACtB;AAAA;AAAA,MAEA,SAAc;AACZ,eAAO,EAAE,QAAQ,GAAA;AAAA,MACnB;AAAA,IAAA,CAGiC;AAAA,EACrC;AAEA,WAASe,EAAO5C,GAA6B;AAC3C,WAAOD,EAAkBC,GAAM2B,CAAY;AAAA,EAC7C;AAEA,SAAO;AAAA,IACL,QAAAC;AAAA,IACA,YAAAE;AAAA,IACA,WAAAC;AAAA,IACA,OAAAM;AAAA,IACA,QAAAI;AAAA,IACA,QAAAG;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"spec.js","sources":["../../../sdui-core/src/spec.ts"],"sourcesContent":["/**\n * createSpec - Factory for state-bound expression helpers + render\n *\n * Mirrors Python SDK's StateHandle + render module.\n */\n\nimport type {\n StatePaths,\n ValueAt,\n ArrayPaths,\n ArrayItemAt,\n ItemPaths,\n ItemValueAt,\n} from './paths';\nimport type {\n StateRef,\n BindStateRef,\n ItemRef,\n BindItemRef,\n IndexRef,\n TemplateRef,\n TemplateInterpolation,\n CondRef,\n PropValue,\n} from './expressions';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\nimport type { InternalElementNode } from './component-utils';\n\n/** Typed accessor for repeat item fields. */\nexport interface ItemAccessor<TItem> {\n /** Read a field from the current repeat item. */\n $<P extends ItemPaths<TItem>>(path: P): ItemRef<ItemValueAt<TItem, P>>;\n /** Two-way bind to a field on the current repeat item. */\n $bind<P extends ItemPaths<TItem>>(\n path: P\n ): BindItemRef<ItemValueAt<TItem, P>>;\n /** Current repeat index (number). */\n $index(): IndexRef;\n}\n\nexport interface FlatUIElement {\n type: string;\n props: Record<string, unknown>;\n children?: string[];\n slots?: Record<string, string[]>;\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\nexport interface FlatSpec {\n root: string;\n elements: Record<string, FlatUIElement>;\n state?: Record<string, unknown>;\n}\n\nexport type Spec = FlatSpec;\nexport type CoreSpec = FlatSpec;\n\n/**\n * Flatten an element tree into a flat spec format.\n * Uses JSON round-trip to strip Symbol properties and undefined values,\n * ensuring clean serialization.\n */\nexport function renderElementTree(root: ElementNode, state?: object): FlatSpec {\n const elements: Record<string, FlatUIElement> = {};\n const explicitIds = new Map<string, object>();\n const elementIds = new WeakMap<object, string>();\n const emitted = new WeakSet<object>();\n const usedIds = new Set<string>();\n let nextGeneratedId = 0;\n\n function collectExplicitIds(\n node: ElementNode,\n seen = new WeakSet<object>()\n ): void {\n const nodeObject = node as unknown as object;\n if (seen.has(nodeObject)) {\n return;\n }\n seen.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n if (n.id !== undefined) {\n const existing = explicitIds.get(n.id);\n if (existing && existing !== nodeObject) {\n throw new Error(`Duplicate element id: ${n.id}`);\n }\n explicitIds.set(n.id, nodeObject);\n usedIds.add(n.id);\n }\n\n n.children?.forEach(child => collectExplicitIds(child, seen));\n Object.values(n.slots ?? {}).forEach(slotChildren =>\n slotChildren.forEach(child => collectExplicitIds(child, seen))\n );\n }\n\n function allocateGeneratedId(): string {\n let id: string;\n do {\n id = `element-${nextGeneratedId}`;\n nextGeneratedId += 1;\n } while (usedIds.has(id));\n\n usedIds.add(id);\n return id;\n }\n\n function elementId(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const existing = elementIds.get(nodeObject);\n if (existing) {\n return existing;\n }\n\n const n = node as unknown as InternalElementNode;\n const id = n.id ?? allocateGeneratedId();\n elementIds.set(nodeObject, id);\n return id;\n }\n\n function flatten(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const id = elementId(node);\n if (emitted.has(nodeObject)) {\n return id;\n }\n emitted.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n const childIds: string[] = n.children\n ? n.children.map(child => flatten(child))\n : [];\n\n const flatElement: FlatUIElement = {\n type: n.type,\n props: n.props,\n children: childIds,\n };\n if (n.slots) {\n flatElement.slots = Object.fromEntries(\n Object.entries(n.slots).map(([name, slotChildren]) => [\n name,\n slotChildren.map(child => flatten(child)),\n ])\n );\n }\n\n if (n.visible !== undefined) {\n flatElement.visible = n.visible;\n }\n if (n.on) {\n flatElement.on = n.on;\n }\n if (n.watch) {\n flatElement.watch = n.watch;\n }\n if (n.repeat) {\n flatElement.repeat = n.repeat;\n }\n\n elements[id] = flatElement;\n return id;\n }\n\n collectExplicitIds(root);\n const rootId = flatten(root);\n\n return JSON.parse(\n JSON.stringify({\n root: rootId,\n elements,\n state,\n })\n ) as FlatSpec;\n}\n\nexport interface SpecContext<TState> {\n /** Read-only reference to a state path. */\n $state<P extends StatePaths<TState>>(path: P): StateRef<ValueAt<TState, P>>;\n\n /** Two-way binding to a state path. */\n $bindState<P extends StatePaths<TState>>(\n path: P\n ): BindStateRef<ValueAt<TState, P>>;\n\n /** String template expression (tagged template literal). */\n $template(\n strings: TemplateStringsArray,\n ...values: TemplateInterpolation[]\n ): TemplateRef;\n\n /** Conditional expression with typed branches. */\n $cond<T>(\n condition: VisibilityBinding | boolean,\n then: PropValue<T>,\n else_: PropValue<T>\n ): CondRef<T>;\n\n /**\n * Create a repeat binding for an array state path.\n * Returns [RepeatBinding, ItemAccessor<T>].\n */\n repeat<P extends ArrayPaths<TState>>(\n statePath: P,\n key?: string\n ): [RepeatBinding, ItemAccessor<ArrayItemAt<TState, P>>];\n\n /** Flatten an element tree into the flat spec format. */\n render(root: ElementNode): FlatSpec;\n}\n\nexport function createSpec<TState extends object>(config: {\n state: TState;\n}): SpecContext<TState> {\n const initialState = config.state;\n\n function $state(path: string): unknown {\n return { $state: path };\n }\n\n function $bindState(path: string): unknown {\n return { $bindState: path };\n }\n\n /**\n * Build a template string from a tagged template literal.\n * Converts state refs into runtime template variables.\n */\n function $template(\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): unknown {\n let result = strings[0];\n for (let i = 0; i < values.length; i += 1) {\n const val = values[i];\n if (val === null || val === undefined) {\n result += '';\n } else if (\n typeof val === 'object' &&\n '$state' in val &&\n typeof val.$state === 'string'\n ) {\n result += `\\${${val.$state}}`;\n } else {\n throw new TypeError(\n '$template only supports state refs, null, and undefined'\n );\n }\n result += strings[i + 1];\n }\n return { $template: result };\n }\n\n function $cond(condition: unknown, then: unknown, else_: unknown): unknown {\n return { $cond: condition, $then: then, $else: else_ };\n }\n\n /**\n * Create a repeat binding for array iteration.\n * Returns [RepeatBinding, ItemAccessor] tuple.\n *\n * Type safety is enforced at the createSpec boundary through type parameters.\n * Internal implementations use `any` to work with the opaque branded types.\n */\n function repeat(\n statePath: string,\n key?: string\n ): [unknown, ItemAccessor<unknown>] {\n const repeatBinding = { statePath, key } as unknown as RepeatBinding;\n\n const itemAccessor: ItemAccessor<unknown> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $(path: string): any {\n return { $item: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $bind(path: string): any {\n return { $bindItem: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $index(): any {\n return { $index: true };\n },\n };\n\n return [repeatBinding, itemAccessor];\n }\n\n function render(root: ElementNode): FlatSpec {\n return renderElementTree(root, initialState);\n }\n\n return {\n $state,\n $bindState,\n $template,\n $cond,\n repeat,\n render,\n } as unknown as SpecContext<TState>;\n}\n"],"names":["renderElementTree","root","state","elements","explicitIds","elementIds","emitted","usedIds","nextGeneratedId","collectExplicitIds","node","seen","_a","nodeObject","n","existing","child","slotChildren","allocateGeneratedId","id","elementId","flatten","childIds","flatElement","name","rootId","createSpec","config","initialState","$state","path","$bindState","$template","strings","values","result","i","val","$cond","condition","then","else_","repeat","statePath","key","render"],"mappings":"AAkEO,SAASA,EAAkBC,GA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AAQE,KAAK,GAAG;AACzC,YAAMC,IAAMH,EAAOE,CAAC;AACpB,UAAIC,KAAQ;AACV,QAAAF,KAAU;AAAA,eAEV,OAAOE,KAAQ,YACf,YAAYA,KACZ,OAAOA,EAAI,UAAW;AAEtB,QAAAF,KAAU,MAAME,EAAI,MAAM;AAAA;AAE1B,cAAM,IAAI;AAAA,UACR;AAAA,QAAA;AAGJ,MAAAF,KAAUF,EAAQG,IAAI,CAAC;AAAA,IACzB;AACA,WAAO,EAAE,WAAWD,EAAA;AAAA,EACtB;AAEA,WAASG,EAAMC,GAAoBC,GAAeC,GAAyB;AACzE,WAAO,EAAE,OAAOF,GAAW,OAAOC,GAAM,OAAOC,EAAA;AAAA,EACjD;AASA,WAASC,EACPC,GACAC,GACkC;AAkBlC,WAAO,CAjBe,EAAE,WAAAD,GAAW,KAAAC,EAAA,GAES;AAAA;AAAA,MAE1C,EAAEd,GAAmB;AACnB,eAAO,EAAE,OAAOA,EAAA;AAAA,MAClB;AAAA;AAAA,MAEA,MAAMA,GAAmB;AACvB,eAAO,EAAE,WAAWA,EAAA;AAAA,MACtB;AAAA;AAAA,MAEA,SAAc;AACZ,eAAO,EAAE,QAAQ,GAAA;AAAA,MACnB;AAAA,IAAA,CAGiC;AAAA,EACrC;AAEA,WAASe,EAAO5C,GAA6B;AAC3C,WAAOD,EAAkBC,GAAM2B,CAAY;AAAA,EAC7C;AAEA,SAAO;AAAA,IACL,QAAAC;AAAA,IACA,YAAAE;AAAA,IACA,WAAAC;AAAA,IACA,OAAAM;AAAA,IACA,QAAAI;AAAA,IACA,QAAAG;AAAA,EAAA;AAEJ;"}
@@ -308,28 +308,27 @@ Example:
308
308
  }
309
309
  ```
310
310
 
311
- Use templates when a string prop needs runtime interpolation from state, repeated item fields, or indexes.
311
+ Use templates when a string prop needs runtime interpolation from state. Use `$item` and `$index` as separate expressions in compatible repeated-child props; combine them with text only through a composition expression supported by the target runtime.
312
312
 
313
313
  ## Repeat
314
314
 
315
- Repeat renders an element once per item in an array state path.
316
-
317
- Conceptually, a repeated element says:
318
-
319
- - which array state path to iterate
320
- - which field identifies each item, if a key is provided
321
- - which item fields the repeated element reads or binds
315
+ Repeat keeps the bound container in place and renders its children once per item in an array state path. Put item references on those children.
322
316
 
323
317
  Example shape:
324
318
 
325
319
  ```json
326
320
  {
327
- "repeat": {
328
- "statePath": "/todos",
329
- "key": "id"
330
- },
331
- "props": {
332
- "text": { "$item": "title" }
321
+ "root": "todo-list",
322
+ "elements": {
323
+ "todo-list": {
324
+ "type": "VStack",
325
+ "repeat": { "statePath": "/todos", "key": "id" },
326
+ "children": ["todo-title"]
327
+ },
328
+ "todo-title": {
329
+ "type": "Text",
330
+ "props": { "text": { "$item": "title" } }
331
+ }
333
332
  }
334
333
  }
335
334
  ```
@@ -110,7 +110,7 @@ Creates a string expression from refs.
110
110
 
111
111
  Purpose:
112
112
 
113
- - build runtime strings from state, repeat item refs, or repeat indexes
113
+ - build runtime strings from state refs
114
114
  - serialize as a JSON-renderer `$template` expression
115
115
 
116
116
  ✅ Correct:
@@ -133,7 +133,7 @@ Text({
133
133
  });
134
134
  ```
135
135
 
136
- Why it fails: template interpolations accept expression refs, `null`, or `undefined`; plain literal interpolation is not part of the typed surface.
136
+ Why it fails: template interpolations accept state refs, `null`, or `undefined`. Plain literals, item refs, and index refs are not supported inside `$template`.
137
137
 
138
138
  ## `$cond(condition, thenValue, elseValue)`
139
139
 
@@ -172,7 +172,7 @@ Creates a repeat binding and item accessor for an array state path.
172
172
 
173
173
  Purpose:
174
174
 
175
- - render one element per item in a runtime array
175
+ - render a container's children once per item in a runtime array
176
176
  - access repeated item fields with `item.$()`
177
177
  - bind repeated item fields with `item.$bind()`
178
178
  - access repeat index with `item.$index()`
@@ -186,11 +186,10 @@ interface AppState {
186
186
 
187
187
  const [todoRepeat, todo] = repeat('/todos', 'id');
188
188
 
189
- Text({
189
+ VStack({
190
190
  repeat: todoRepeat,
191
- props: {
192
- text: todo.$('title'),
193
- },
191
+ props: { gap: 'space300' },
192
+ children: [Text({ props: { text: todo.$('title') } })],
194
193
  });
195
194
  ```
196
195
 
@@ -243,7 +243,7 @@ Events: `change`, `blur`
243
243
  | `checks` | no | [CheckboxCheck](./types.md#checkboxcheck)[] | Array of {type, message, args?} validation rule objects. Requires validateOn to be set |
244
244
  | `defaultValue` | no | boolean | Initial value for uncontrolled mode. Default: false |
245
245
  | `disabled` | no | boolean | Disables the checkbox. Default: false |
246
- | `error` | no | boolean \| string | Error state or error message |
246
+ | `error` | no | unknown | Error state or error message |
247
247
  | `haptic` | no | boolean | Enables haptic feedback on toggle. Default: true |
248
248
  | `helperText` | no | string | Help text shown below the checkbox |
249
249
  | `indeterminate` | no | boolean | Sets the checkbox to an indeterminate state. Default: false |
@@ -277,7 +277,7 @@ Events: `change`
277
277
  |---|---:|---|---|
278
278
  | `defaultValue` | no | string[] | Initial selected ids for uncontrolled mode |
279
279
  | `disabled` | no | boolean | Disables all options. Default: false |
280
- | `error` | no | boolean \| string | Error state or error message shown below the group |
280
+ | `error` | no | unknown | Error state or error message shown below the group |
281
281
  | `helperText` | no | string | Help text shown below the group |
282
282
  | `options` | yes | [CheckboxGroupOption](./types.md#checkboxgroupoption)[] | Array of checkbox options: [{ id, label?, tag?, disabled? }] |
283
283
  | `testID` | no | string | Sets testid on CheckboxGroup (used for testing purposes) |
@@ -351,7 +351,7 @@ Events: `change`, `blur`
351
351
  | `decimalPlaces` | no | number | Number of decimal places allowed |
352
352
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
353
353
  | `disabled` | no | boolean | Disables the input. Default: false |
354
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
354
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
355
355
  | `helperText` | no | string | Help text shown below the input |
356
356
  | `label` | no | string | Label shown above the input |
357
357
  | `placeholder` | no | string | Placeholder text shown when the field is empty |
@@ -384,7 +384,7 @@ Events: `change`, `blur`
384
384
  | `clearable` | no | boolean | Shows a clear button to reset the value. Default: false |
385
385
  | `defaultValue` | no | string | Default ISO date string for uncontrolled mode |
386
386
  | `disabled` | no | boolean | Disables the date input. Default: false |
387
- | `error` | no | string \| boolean | Error state or error message |
387
+ | `error` | no | unknown | Error state or error message |
388
388
  | `format` | no | string | Date format string e.g. "YYYY-MM-DD". Default: ISO string |
389
389
  | `helperText` | no | string | Help text shown below the date input |
390
390
  | `label` | yes | string | Label shown above the date input |
@@ -491,7 +491,7 @@ Events: `change`, `blur`
491
491
  | `clearable` | no | boolean | Shows a clear button when the field has a value. Default: false |
492
492
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
493
493
  | `disabled` | no | boolean | Disables the input. Default: false |
494
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
494
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
495
495
  | `helperText` | no | string | Help text shown below the input |
496
496
  | `label` | no | string | Label shown above the input |
497
497
  | `placeholder` | no | string | Placeholder text shown when the field is empty |
@@ -650,7 +650,7 @@ Events: _none_
650
650
  | Name | Required | Type | Description |
651
651
  |---|---:|---|---|
652
652
  | `disabled` | no | boolean | Disables all inputs in the group. Default: false |
653
- | `error` | no | string \| boolean | Error state or error message for the group |
653
+ | `error` | no | unknown | Error state or error message for the group |
654
654
  | `helperText` | no | string | Helper text shown below the grouped inputs |
655
655
  | `required` | no | boolean | Marks the group as required. Default: false |
656
656
  | `testID` | no | string | Sets testid on Group (used for testing purposes) |
@@ -729,7 +729,7 @@ Events: _none_
729
729
  | `radius` | no | [HStackRadius](./definitions.md#hstackradius) | Border radius on all corners — shape corner token (e.g. shapeCornerSm, shapeCornerMd, shapeCornerLg) |
730
730
  | `reverse` | no | boolean | Reverses the row direction. Default: false |
731
731
  | `right` | no | [HStackBottom](./definitions.md#hstackbottom) | Right offset — space token |
732
- | `scrollView` | no | boolean | If true, wraps children in a horizontal ScrollView instead of a View |
732
+ | `scrollView` | no | boolean \| [ScrollView](./types.md#scrollview) | Wraps children in a horizontal ScrollView when true or configured with ScrollView props |
733
733
  | `shrink` | no | number | Flex shrink factor |
734
734
  | `testID` | no | string | Sets testid on HStack (used for testing purposes) |
735
735
  | `top` | no | [HStackBottom](./definitions.md#hstackbottom) | Top offset — space token |
@@ -809,7 +809,7 @@ Events: `change`, `blur`
809
809
  | `clearable` | no | boolean | Shows a clear button when the field has a value. Default: false |
810
810
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
811
811
  | `disabled` | no | boolean | Disables the input. Default: false |
812
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
812
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
813
813
  | `helperText` | no | string | Help text shown below the input |
814
814
  | `label` | no | string | Label shown above the input |
815
815
  | `placeholder` | no | string | Placeholder text shown when the field is empty |
@@ -970,7 +970,7 @@ Events: `change`, `blur`
970
970
  | `decimalPlaces` | no | number | Number of decimal places allowed. Mutually exclusive with isIntegerOnly. |
971
971
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
972
972
  | `disabled` | no | boolean | Disables the input. Default: false |
973
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
973
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
974
974
  | `helperText` | no | string | Help text shown below the input |
975
975
  | `isIntegerOnly` | no | boolean | Restrict to integer values only. Takes precedence over decimalPlaces. |
976
976
  | `label` | no | string | Label shown above the input |
@@ -1262,7 +1262,7 @@ Events: `change`, `blur`
1262
1262
  | `clearable` | no | boolean | Shows a clear button when the field has a value. Default: false |
1263
1263
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
1264
1264
  | `disabled` | no | boolean | Disables the input. Default: false |
1265
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
1265
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
1266
1266
  | `helperText` | no | string | Help text shown below the input |
1267
1267
  | `label` | no | string | Label shown above the input |
1268
1268
  | `readOnly` | no | boolean | Shows value without allowing edits. Default: false |
@@ -1297,7 +1297,7 @@ Events: `change`, `blur`
1297
1297
  | `decimalPlaces` | no | number | Number of decimal places allowed |
1298
1298
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
1299
1299
  | `disabled` | no | boolean | Disables the input. Default: false |
1300
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
1300
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
1301
1301
  | `helperText` | no | string | Help text shown below the input |
1302
1302
  | `label` | no | string | Label shown above the input |
1303
1303
  | `placeholder` | no | string | Placeholder text shown when the field is empty |
@@ -1330,7 +1330,7 @@ Events: `change`, `blur`
1330
1330
  | `checks` | no | [PhoneCheck](./types.md#phonecheck)[] | Array of {type, message, args?} validation rule objects. Requires validateOn to be set |
1331
1331
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
1332
1332
  | `disabled` | no | boolean | Disables the input. Default: false |
1333
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
1333
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
1334
1334
  | `helperText` | no | string | Help text shown below the input |
1335
1335
  | `inputWithCountryCode` | no | boolean | If true, country code will be included as part of the value. Default: false |
1336
1336
  | `label` | no | string | Label shown above the input |
@@ -1419,7 +1419,7 @@ Events: `change`, `blur`
1419
1419
  | `checks` | no | [RadioCheck](./types.md#radiocheck)[] | Array of {type, message, args?} validation rule objects. Requires validateOn to be set |
1420
1420
  | `defaultValue` | no | boolean | Initial value for uncontrolled mode. Default: false |
1421
1421
  | `disabled` | no | boolean | Disables the radio button. Default: false |
1422
- | `error` | no | boolean \| string | Error state or error message |
1422
+ | `error` | no | unknown | Error state or error message |
1423
1423
  | `haptic` | no | boolean | Enables haptic feedback on selection. Default: true |
1424
1424
  | `helperText` | no | string | Help text shown below the radio group |
1425
1425
  | `label` | no | string | Label text shown beside the radio |
@@ -1451,7 +1451,7 @@ Events: `change`
1451
1451
  |---|---:|---|---|
1452
1452
  | `defaultValue` | no | string | Initial selected id for uncontrolled mode |
1453
1453
  | `disabled` | no | boolean | Disables all options. Default: false |
1454
- | `error` | no | boolean \| string | Error state or error message shown below the group |
1454
+ | `error` | no | unknown | Error state or error message shown below the group |
1455
1455
  | `helperText` | no | string | Help text shown below the group |
1456
1456
  | `options` | yes | [RadioGroupOption](./types.md#radiogroupoption)[] | Array of radio options: [{ id, label?, tag?, disabled? }] |
1457
1457
  | `testID` | no | string | Sets testid on RadioGroup (used for testing purposes) |
@@ -1528,7 +1528,7 @@ Events: `change`
1528
1528
  | `defaultValue` | no | string | Default selected option id for uncontrolled mode |
1529
1529
  | `descriptionNumberOfLines` | no | number | Max lines for option description text in the picker. Default: 1 |
1530
1530
  | `disabled` | no | boolean | Disables the select input. Default: false |
1531
- | `error` | no | boolean \| string | Error state or error message |
1531
+ | `error` | no | unknown | Error state or error message |
1532
1532
  | `helperText` | no | string | Help text shown below the select input |
1533
1533
  | `hideDismissButton` | no | boolean | Hides the dismiss button in the picker sheet header. Default: false |
1534
1534
  | `label` | yes | string | Label shown above the select input |
@@ -1564,7 +1564,7 @@ Events: `change`
1564
1564
  |---|---:|---|---|
1565
1565
  | `defaultValue` | no | string \| string[] | Initial value for uncontrolled mode |
1566
1566
  | `disabled` | no | boolean | Disables the chips. Default: false |
1567
- | `error` | no | string \| boolean | Error state or error message |
1567
+ | `error` | no | unknown | Error state or error message |
1568
1568
  | `helperText` | no | string | Help text shown below the chips |
1569
1569
  | `multiple` | no | boolean | Allow multiple selection. Default: true |
1570
1570
  | `options` | yes | [SelectChipsOption](./types.md#selectchipsoption)[] | Array of selectable chip options |
@@ -1593,7 +1593,7 @@ Events: `change`
1593
1593
  |---|---:|---|---|
1594
1594
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
1595
1595
  | `disabled` | no | boolean | Disables the input. Default: false |
1596
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
1596
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
1597
1597
  | `readOnly` | no | boolean | Shows value without allowing edits. Default: false |
1598
1598
  | `required` | no | boolean | Marks the field as required. Default: false |
1599
1599
  | `testID` | no | string | Sets testid on InputSignature (used for testing purposes) |
@@ -1621,7 +1621,7 @@ Events: `change`, `blur`
1621
1621
  | `checks` | no | [SinCheck](./types.md#sincheck)[] | Array of {type, message, args?} validation rule objects. Requires validateOn to be set |
1622
1622
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
1623
1623
  | `disabled` | no | boolean | Disables the input. Default: false |
1624
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
1624
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
1625
1625
  | `helperText` | no | string | Help text shown below the input |
1626
1626
  | `label` | no | string | Label shown above the input |
1627
1627
  | `placeholder` | no | string | Placeholder text shown when the field is empty |
@@ -1777,7 +1777,7 @@ Events: `change`, `blur`
1777
1777
  | `checks` | no | [SsnCheck](./types.md#ssncheck)[] | Array of {type, message, args?} validation rule objects. Requires validateOn to be set |
1778
1778
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
1779
1779
  | `disabled` | no | boolean | Disables the input. Default: false |
1780
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
1780
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
1781
1781
  | `helperText` | no | string | Help text shown below the input |
1782
1782
  | `label` | no | string | Label shown above the input |
1783
1783
  | `placeholder` | no | string | Placeholder text shown when the field is empty |
@@ -1933,7 +1933,7 @@ Events: `change`, `blur`
1933
1933
  | `checks` | no | [TextareaCheck](./types.md#textareacheck)[] | Array of {type, message, args?} validation rule objects. Requires validateOn to be set |
1934
1934
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
1935
1935
  | `disabled` | no | boolean | Disables the textarea. Default: false |
1936
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
1936
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
1937
1937
  | `height` | no | number | Fixed height of the textarea in points |
1938
1938
  | `helperText` | no | string | Help text shown below the textarea |
1939
1939
  | `label` | no | string | Label shown above the textarea |
@@ -1964,7 +1964,7 @@ Events: `change`, `blur`
1964
1964
  |---|---:|---|---|
1965
1965
  | `defaultValue` | no | string | Default ISO time string for uncontrolled mode |
1966
1966
  | `disabled` | no | boolean | Disables the time input. Default: false |
1967
- | `error` | no | string \| boolean | Error state or error message |
1967
+ | `error` | no | unknown | Error state or error message |
1968
1968
  | `format` | no | [TimeFormat](./definitions.md#timeformat) | Time format. Default: isoString |
1969
1969
  | `helperText` | no | string | Help text shown below the time input |
1970
1970
  | `label` | yes | string | Label shown above the time input |
@@ -2137,7 +2137,7 @@ Events: `change`, `blur`
2137
2137
  | `defaultValue` | no | string | Initial value for uncontrolled mode |
2138
2138
  | `disabled` | no | boolean | Disables the input. Default: false |
2139
2139
  | `domainList` | no | string \| string \| [DomainList](./types.md#domainlist) \| [DomainListVariant2](./types.md#domainlistvariant2)[] | Allowed domains. When set, the user types only the username and picks a domain. |
2140
- | `error` | no | boolean \| string | Error state — true for generic error highlight, string for error message |
2140
+ | `error` | no | unknown | Error state — true for generic error highlight, string for error message |
2141
2141
  | `helperText` | no | string | Help text shown below the input |
2142
2142
  | `label` | no | string | Label shown above the input |
2143
2143
  | `placeholder` | no | string | Placeholder text shown when the field is empty |