@rippling/pebble-sdui-web 0.18.1 → 0.18.2

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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function i(d,e){const o={type:d,props:e.props??{}};return e.id!==void 0&&(o.id=e.id),e.visible!==void 0&&(o.visible=e.visible),e.on&&(o.on=e.on),e.children&&(o.children=e.children),e.repeat&&(o.repeat=e.repeat),o}exports.buildNode=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function i(d,e){const o={type:d,props:e.props??{}};return e.id!==void 0&&(o.id=e.id),e.visible!==void 0&&(o.visible=e.visible),e.on&&(o.on=e.on),e.children&&(o.children=e.children),e.slots&&(o.slots=e.slots),e.repeat&&(o.repeat=e.repeat),o}exports.buildNode=i;
2
2
  //# sourceMappingURL=component-utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"component-utils.cjs","sources":["../../../sdui-core/src/component-utils.ts"],"sourcesContent":["/**\n * Component Utilities\n *\n * Generic types and helpers used by generated component builders.\n * Mirrors Python SDK's elements.py Element base class.\n */\n\nimport type { WrapWithPropValue } from './expressions';\nimport type { ActionBinding } from './action-utils';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\n\nexport type EventAction = ActionBinding | ActionBinding[];\n\n/**\n * The actual runtime shape behind the branded ElementNode.\n * Only used internally by buildNode() and render().\n */\nexport interface InternalElementNode {\n id?: string;\n type: string;\n props: Record<string, unknown>;\n children?: ElementNode[];\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\n/**\n * Standard input shape for a component builder.\n *\n * - `Props`: plain prop types — automatically wrapped with PropValue\n * - `Events`: string union of supported event names (use `never` for none)\n * - `HasChildren`: whether this component accepts children\n *\n * The conditional types ensure `on` is only available when events exist,\n * and `children` is only available when HasChildren is true.\n */\nexport type ComponentInputs<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n> = {\n id?: string;\n props: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never });\n\n/**\n * Variant where props is optional (for components with all-optional props).\n */\nexport type ComponentInputsOptionalProps<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n> = {\n id?: string;\n props?: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never });\n\n/**\n * Creates an ElementNode from builder input. Used by generated component builders.\n */\nexport function buildNode<\n TPlatform extends string = string,\n TCatalog extends string = string,\n>(\n type: string,\n input: {\n id?: string;\n props?: unknown;\n visible?: unknown;\n on?: unknown;\n children?: unknown;\n repeat?: unknown;\n }\n): ElementNode<TPlatform, TCatalog> {\n const node: InternalElementNode = {\n type,\n props: (input.props ?? {}) as Record<string, unknown>,\n };\n if (input.id !== undefined) node.id = input.id;\n if (input.visible !== undefined) node.visible = input.visible;\n if (input.on) node.on = input.on as Record<string, unknown>;\n if (input.children) node.children = input.children as ElementNode[];\n if (input.repeat)\n node.repeat = input.repeat as unknown as {\n statePath: string;\n key?: string;\n };\n return node as unknown as ElementNode<TPlatform, TCatalog>;\n}\n"],"names":["buildNode","type","input","node"],"mappings":"gFA6EO,SAASA,EAIdC,EACAC,EAQkC,CAClC,MAAMC,EAA4B,CAChC,KAAAF,EACA,MAAQC,EAAM,OAAS,CAAA,CAAC,EAE1B,OAAIA,EAAM,KAAO,SAAWC,EAAK,GAAKD,EAAM,IACxCA,EAAM,UAAY,SAAWC,EAAK,QAAUD,EAAM,SAClDA,EAAM,KAAIC,EAAK,GAAKD,EAAM,IAC1BA,EAAM,WAAUC,EAAK,SAAWD,EAAM,UACtCA,EAAM,SACRC,EAAK,OAASD,EAAM,QAIfC,CACT"}
1
+ {"version":3,"file":"component-utils.cjs","sources":["../../../sdui-core/src/component-utils.ts"],"sourcesContent":["/**\n * Component Utilities\n *\n * Generic types and helpers used by generated component builders.\n * Mirrors Python SDK's elements.py Element base class.\n */\n\nimport type { WrapWithPropValue } from './expressions';\nimport type { ActionBinding } from './action-utils';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\n\nexport type EventAction = ActionBinding | ActionBinding[];\n\n/**\n * The actual runtime shape behind the branded ElementNode.\n * Only used internally by buildNode() and render().\n */\nexport interface InternalElementNode {\n id?: string;\n type: string;\n props: Record<string, unknown>;\n children?: ElementNode[];\n slots?: Record<string, ElementNode[]>;\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\n/**\n * Standard input shape for a component builder.\n *\n * - `Props`: plain prop types — automatically wrapped with PropValue\n * - `Events`: string union of supported event names (use `never` for none)\n * - `HasChildren`: whether this component accepts children\n *\n * The conditional types ensure `on` is only available when events exist,\n * and `children` is only available when HasChildren is true.\n */\nexport type ComponentInputs<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n Slots extends string = never,\n> = {\n id?: string;\n props: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never }) &\n ([Slots] extends [never]\n ? { slots?: never }\n : { slots?: { [K in Slots]?: ElementNode[] } });\n\n/**\n * Variant where props is optional (for components with all-optional props).\n */\nexport type ComponentInputsOptionalProps<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n Slots extends string = never,\n> = {\n id?: string;\n props?: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never }) &\n ([Slots] extends [never]\n ? { slots?: never }\n : { slots?: { [K in Slots]?: ElementNode[] } });\n\n/**\n * Creates an ElementNode from builder input. Used by generated component builders.\n */\nexport function buildNode<\n TPlatform extends string = string,\n TCatalog extends string = string,\n>(\n type: string,\n input: {\n id?: string;\n props?: unknown;\n visible?: unknown;\n on?: unknown;\n children?: unknown;\n slots?: unknown;\n repeat?: unknown;\n }\n): ElementNode<TPlatform, TCatalog> {\n const node: InternalElementNode = {\n type,\n props: (input.props ?? {}) as Record<string, unknown>,\n };\n if (input.id !== undefined) node.id = input.id;\n if (input.visible !== undefined) node.visible = input.visible;\n if (input.on) node.on = input.on as Record<string, unknown>;\n if (input.children) node.children = input.children as ElementNode[];\n if (input.slots) node.slots = input.slots as Record<string, ElementNode[]>;\n if (input.repeat)\n node.repeat = input.repeat as unknown as {\n statePath: string;\n key?: string;\n };\n return node as unknown as ElementNode<TPlatform, TCatalog>;\n}\n"],"names":["buildNode","type","input","node"],"mappings":"gFAsFO,SAASA,EAIdC,EACAC,EASkC,CAClC,MAAMC,EAA4B,CAChC,KAAAF,EACA,MAAQC,EAAM,OAAS,CAAA,CAAC,EAE1B,OAAIA,EAAM,KAAO,SAAWC,EAAK,GAAKD,EAAM,IACxCA,EAAM,UAAY,SAAWC,EAAK,QAAUD,EAAM,SAClDA,EAAM,KAAIC,EAAK,GAAKD,EAAM,IAC1BA,EAAM,WAAUC,EAAK,SAAWD,EAAM,UACtCA,EAAM,QAAOC,EAAK,MAAQD,EAAM,OAChCA,EAAM,SACRC,EAAK,OAASD,EAAM,QAIfC,CACT"}
@@ -12,6 +12,7 @@ export interface InternalElementNode {
12
12
  type: string;
13
13
  props: Record<string, unknown>;
14
14
  children?: ElementNode[];
15
+ slots?: Record<string, ElementNode[]>;
15
16
  visible?: unknown;
16
17
  on?: Record<string, unknown>;
17
18
  watch?: Record<string, unknown>;
@@ -30,7 +31,7 @@ export interface InternalElementNode {
30
31
  * The conditional types ensure `on` is only available when events exist,
31
32
  * and `children` is only available when HasChildren is true.
32
33
  */
33
- export type ComponentInputs<Props, Events extends string = never, HasChildren extends boolean = false> = {
34
+ export type ComponentInputs<Props, Events extends string = never, HasChildren extends boolean = false, Slots extends string = never> = {
34
35
  id?: string;
35
36
  props: WrapWithPropValue<Props>;
36
37
  visible?: VisibilityBinding | boolean;
@@ -45,11 +46,17 @@ export type ComponentInputs<Props, Events extends string = never, HasChildren ex
45
46
  children?: ElementNode[];
46
47
  } : {
47
48
  children?: never;
49
+ }) & ([Slots] extends [never] ? {
50
+ slots?: never;
51
+ } : {
52
+ slots?: {
53
+ [K in Slots]?: ElementNode[];
54
+ };
48
55
  });
49
56
  /**
50
57
  * Variant where props is optional (for components with all-optional props).
51
58
  */
52
- export type ComponentInputsOptionalProps<Props, Events extends string = never, HasChildren extends boolean = false> = {
59
+ export type ComponentInputsOptionalProps<Props, Events extends string = never, HasChildren extends boolean = false, Slots extends string = never> = {
53
60
  id?: string;
54
61
  props?: WrapWithPropValue<Props>;
55
62
  visible?: VisibilityBinding | boolean;
@@ -64,6 +71,12 @@ export type ComponentInputsOptionalProps<Props, Events extends string = never, H
64
71
  children?: ElementNode[];
65
72
  } : {
66
73
  children?: never;
74
+ }) & ([Slots] extends [never] ? {
75
+ slots?: never;
76
+ } : {
77
+ slots?: {
78
+ [K in Slots]?: ElementNode[];
79
+ };
67
80
  });
68
81
  /**
69
82
  * Creates an ElementNode from builder input. Used by generated component builders.
@@ -74,5 +87,6 @@ export declare function buildNode<TPlatform extends string = string, TCatalog ex
74
87
  visible?: unknown;
75
88
  on?: unknown;
76
89
  children?: unknown;
90
+ slots?: unknown;
77
91
  repeat?: unknown;
78
92
  }): ElementNode<TPlatform, TCatalog>;
@@ -1,11 +1,11 @@
1
- function i(d, e) {
1
+ function d(s, e) {
2
2
  const o = {
3
- type: d,
3
+ type: s,
4
4
  props: e.props ?? {}
5
5
  };
6
- return e.id !== void 0 && (o.id = e.id), e.visible !== void 0 && (o.visible = e.visible), e.on && (o.on = e.on), e.children && (o.children = e.children), e.repeat && (o.repeat = e.repeat), o;
6
+ return e.id !== void 0 && (o.id = e.id), e.visible !== void 0 && (o.visible = e.visible), e.on && (o.on = e.on), e.children && (o.children = e.children), e.slots && (o.slots = e.slots), e.repeat && (o.repeat = e.repeat), o;
7
7
  }
8
8
  export {
9
- i as buildNode
9
+ d as buildNode
10
10
  };
11
11
  //# sourceMappingURL=component-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"component-utils.js","sources":["../../../sdui-core/src/component-utils.ts"],"sourcesContent":["/**\n * Component Utilities\n *\n * Generic types and helpers used by generated component builders.\n * Mirrors Python SDK's elements.py Element base class.\n */\n\nimport type { WrapWithPropValue } from './expressions';\nimport type { ActionBinding } from './action-utils';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\n\nexport type EventAction = ActionBinding | ActionBinding[];\n\n/**\n * The actual runtime shape behind the branded ElementNode.\n * Only used internally by buildNode() and render().\n */\nexport interface InternalElementNode {\n id?: string;\n type: string;\n props: Record<string, unknown>;\n children?: ElementNode[];\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\n/**\n * Standard input shape for a component builder.\n *\n * - `Props`: plain prop types — automatically wrapped with PropValue\n * - `Events`: string union of supported event names (use `never` for none)\n * - `HasChildren`: whether this component accepts children\n *\n * The conditional types ensure `on` is only available when events exist,\n * and `children` is only available when HasChildren is true.\n */\nexport type ComponentInputs<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n> = {\n id?: string;\n props: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never });\n\n/**\n * Variant where props is optional (for components with all-optional props).\n */\nexport type ComponentInputsOptionalProps<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n> = {\n id?: string;\n props?: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never });\n\n/**\n * Creates an ElementNode from builder input. Used by generated component builders.\n */\nexport function buildNode<\n TPlatform extends string = string,\n TCatalog extends string = string,\n>(\n type: string,\n input: {\n id?: string;\n props?: unknown;\n visible?: unknown;\n on?: unknown;\n children?: unknown;\n repeat?: unknown;\n }\n): ElementNode<TPlatform, TCatalog> {\n const node: InternalElementNode = {\n type,\n props: (input.props ?? {}) as Record<string, unknown>,\n };\n if (input.id !== undefined) node.id = input.id;\n if (input.visible !== undefined) node.visible = input.visible;\n if (input.on) node.on = input.on as Record<string, unknown>;\n if (input.children) node.children = input.children as ElementNode[];\n if (input.repeat)\n node.repeat = input.repeat as unknown as {\n statePath: string;\n key?: string;\n };\n return node as unknown as ElementNode<TPlatform, TCatalog>;\n}\n"],"names":["buildNode","type","input","node"],"mappings":"AA6EO,SAASA,EAIdC,GACAC,GAQkC;AAClC,QAAMC,IAA4B;AAAA,IAChC,MAAAF;AAAA,IACA,OAAQC,EAAM,SAAS,CAAA;AAAA,EAAC;AAE1B,SAAIA,EAAM,OAAO,WAAWC,EAAK,KAAKD,EAAM,KACxCA,EAAM,YAAY,WAAWC,EAAK,UAAUD,EAAM,UAClDA,EAAM,OAAIC,EAAK,KAAKD,EAAM,KAC1BA,EAAM,aAAUC,EAAK,WAAWD,EAAM,WACtCA,EAAM,WACRC,EAAK,SAASD,EAAM,SAIfC;AACT;"}
1
+ {"version":3,"file":"component-utils.js","sources":["../../../sdui-core/src/component-utils.ts"],"sourcesContent":["/**\n * Component Utilities\n *\n * Generic types and helpers used by generated component builders.\n * Mirrors Python SDK's elements.py Element base class.\n */\n\nimport type { WrapWithPropValue } from './expressions';\nimport type { ActionBinding } from './action-utils';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\n\nexport type EventAction = ActionBinding | ActionBinding[];\n\n/**\n * The actual runtime shape behind the branded ElementNode.\n * Only used internally by buildNode() and render().\n */\nexport interface InternalElementNode {\n id?: string;\n type: string;\n props: Record<string, unknown>;\n children?: ElementNode[];\n slots?: Record<string, ElementNode[]>;\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\n/**\n * Standard input shape for a component builder.\n *\n * - `Props`: plain prop types — automatically wrapped with PropValue\n * - `Events`: string union of supported event names (use `never` for none)\n * - `HasChildren`: whether this component accepts children\n *\n * The conditional types ensure `on` is only available when events exist,\n * and `children` is only available when HasChildren is true.\n */\nexport type ComponentInputs<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n Slots extends string = never,\n> = {\n id?: string;\n props: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never }) &\n ([Slots] extends [never]\n ? { slots?: never }\n : { slots?: { [K in Slots]?: ElementNode[] } });\n\n/**\n * Variant where props is optional (for components with all-optional props).\n */\nexport type ComponentInputsOptionalProps<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n Slots extends string = never,\n> = {\n id?: string;\n props?: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never }) &\n ([Slots] extends [never]\n ? { slots?: never }\n : { slots?: { [K in Slots]?: ElementNode[] } });\n\n/**\n * Creates an ElementNode from builder input. Used by generated component builders.\n */\nexport function buildNode<\n TPlatform extends string = string,\n TCatalog extends string = string,\n>(\n type: string,\n input: {\n id?: string;\n props?: unknown;\n visible?: unknown;\n on?: unknown;\n children?: unknown;\n slots?: unknown;\n repeat?: unknown;\n }\n): ElementNode<TPlatform, TCatalog> {\n const node: InternalElementNode = {\n type,\n props: (input.props ?? {}) as Record<string, unknown>,\n };\n if (input.id !== undefined) node.id = input.id;\n if (input.visible !== undefined) node.visible = input.visible;\n if (input.on) node.on = input.on as Record<string, unknown>;\n if (input.children) node.children = input.children as ElementNode[];\n if (input.slots) node.slots = input.slots as Record<string, ElementNode[]>;\n if (input.repeat)\n node.repeat = input.repeat as unknown as {\n statePath: string;\n key?: string;\n };\n return node as unknown as ElementNode<TPlatform, TCatalog>;\n}\n"],"names":["buildNode","type","input","node"],"mappings":"AAsFO,SAASA,EAIdC,GACAC,GASkC;AAClC,QAAMC,IAA4B;AAAA,IAChC,MAAAF;AAAA,IACA,OAAQC,EAAM,SAAS,CAAA;AAAA,EAAC;AAE1B,SAAIA,EAAM,OAAO,WAAWC,EAAK,KAAKD,EAAM,KACxCA,EAAM,YAAY,WAAWC,EAAK,UAAUD,EAAM,UAClDA,EAAM,OAAIC,EAAK,KAAKD,EAAM,KAC1BA,EAAM,aAAUC,EAAK,WAAWD,EAAM,WACtCA,EAAM,UAAOC,EAAK,QAAQD,EAAM,QAChCA,EAAM,WACRC,EAAK,SAASD,EAAM,SAIfC;AACT;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function w(f,S){const $={},p=new Map,m=new WeakMap,h=new WeakSet,u=new Set;let b=0;function t(n,d=new WeakSet){var l;const c=n;if(d.has(c))return;d.add(c);const e=n;if(e.id!==void 0){const o=p.get(e.id);if(o&&o!==c)throw new Error(`Duplicate element id: ${e.id}`);p.set(e.id,c),u.add(e.id)}(l=e.children)==null||l.forEach(o=>t(o,d))}function s(){let n;do n=`element-${b}`,b+=1;while(u.has(n));return u.add(n),n}function r(n){const d=n,c=m.get(d);if(c)return c;const l=n.id??s();return m.set(d,l),l}function a(n){const d=n,c=r(n);if(h.has(d))return c;h.add(d);const e=n,l=e.children?e.children.map(I=>a(I)):[],o={type:e.type,props:e.props,children:l};return e.visible!==void 0&&(o.visible=e.visible),e.on&&(o.on=e.on),e.watch&&(o.watch=e.watch),e.repeat&&(o.repeat=e.repeat),$[c]=o,c}t(f);const i=a(f);return JSON.parse(JSON.stringify({root:i,elements:$,state:S}))}function g(f){const S=f.state;function $(t){return{$state:t}}function p(t){return{$bindState:t}}function m(t,...s){let r=t[0];for(let a=0;a<s.length;a+=1){const i=s[a];!i||typeof i!="object"?r+="":"$state"in i?r+=`\${${i.$state}}`:"$item"in i?r+=`\${$item.${i.$item}}`:"$index"in i&&(r+="${$index}"),r+=t[a+1]}return{$template:r}}function h(t,s,r){return{$cond:t,$then:s,$else:r}}function u(t,s){return[{statePath:t,key:s},{$(i){return{$item:i}},$bind(i){return{$bindItem:i}},$index(){return{$index:!0}}}]}function b(t){return w(t,S)}return{$state:$,$bindState:p,$template:m,$cond:h,repeat:u,render:b}}exports.createSpec=g;exports.renderElementTree=w;
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;
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 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 }\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\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","allocateGeneratedId","id","elementId","flatten","childIds","flatElement","rootId","createSpec","config","initialState","$state","path","$bindState","$template","strings","values","result","i","val","$cond","condition","then","else_","repeat","statePath","key","render"],"mappings":"gF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CAClB,EAEA,MAAMA,EAAmB,CACvB,MAAO,CAAE,UAAWA,CAAA,CACtB,EAEA,QAAc,CACZ,MAAO,CAAE,OAAQ,EAAA,CACnB,CAAA,CAGiC,CACrC,CAEA,SAASe,EAAO1C,EAA6B,CAC3C,OAAOD,EAAkBC,EAAMyB,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 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,EACnB,GAAIC,EAAK,IAAIC,CAAU,EACrB,OAEFD,EAAK,IAAIC,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nB,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"}
@@ -15,6 +15,7 @@ export interface FlatUIElement {
15
15
  type: string;
16
16
  props: Record<string, unknown>;
17
17
  children?: string[];
18
+ slots?: Record<string, string[]>;
18
19
  visible?: unknown;
19
20
  on?: Record<string, unknown>;
20
21
  watch?: Record<string, unknown>;
package/dist/core/spec.js CHANGED
@@ -1,78 +1,85 @@
1
- function I(f, w) {
2
- const $ = {}, p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakSet(), u = /* @__PURE__ */ new Set();
3
- let b = 0;
4
- function t(n, d = /* @__PURE__ */ new WeakSet()) {
1
+ function E($, x) {
2
+ const p = {}, m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakSet(), f = /* @__PURE__ */ new Set();
3
+ let w = 0;
4
+ function t(n, s = /* @__PURE__ */ new WeakSet()) {
5
5
  var l;
6
- const c = n;
7
- if (d.has(c))
6
+ const o = n;
7
+ if (s.has(o))
8
8
  return;
9
- d.add(c);
9
+ s.add(o);
10
10
  const e = n;
11
11
  if (e.id !== void 0) {
12
- const o = p.get(e.id);
13
- if (o && o !== c)
12
+ const r = m.get(e.id);
13
+ if (r && r !== o)
14
14
  throw new Error(`Duplicate element id: ${e.id}`);
15
- p.set(e.id, c), u.add(e.id);
15
+ m.set(e.id, o), f.add(e.id);
16
16
  }
17
- (l = e.children) == null || l.forEach((o) => t(o, d));
17
+ (l = e.children) == null || l.forEach((r) => t(r, s)), Object.values(e.slots ?? {}).forEach(
18
+ (r) => r.forEach((u) => t(u, s))
19
+ );
18
20
  }
19
- function s() {
21
+ function a() {
20
22
  let n;
21
23
  do
22
- n = `element-${b}`, b += 1;
23
- while (u.has(n));
24
- return u.add(n), n;
24
+ n = `element-${w}`, w += 1;
25
+ while (f.has(n));
26
+ return f.add(n), n;
25
27
  }
26
- function r(n) {
27
- const d = n, c = m.get(d);
28
- if (c)
29
- return c;
30
- const l = n.id ?? s();
31
- return m.set(d, l), l;
28
+ function c(n) {
29
+ const s = n, o = h.get(s);
30
+ if (o)
31
+ return o;
32
+ const l = n.id ?? a();
33
+ return h.set(s, l), l;
32
34
  }
33
- function a(n) {
34
- const d = n, c = r(n);
35
- if (h.has(d))
36
- return c;
37
- h.add(d);
38
- const e = n, l = e.children ? e.children.map((x) => a(x)) : [], o = {
35
+ function d(n) {
36
+ const s = n, o = c(n);
37
+ if (b.has(s))
38
+ return o;
39
+ b.add(s);
40
+ const e = n, l = e.children ? e.children.map((u) => d(u)) : [], r = {
39
41
  type: e.type,
40
42
  props: e.props,
41
43
  children: l
42
44
  };
43
- return e.visible !== void 0 && (o.visible = e.visible), e.on && (o.on = e.on), e.watch && (o.watch = e.watch), e.repeat && (o.repeat = e.repeat), $[c] = o, c;
45
+ return e.slots && (r.slots = Object.fromEntries(
46
+ Object.entries(e.slots).map(([u, I]) => [
47
+ u,
48
+ I.map((S) => d(S))
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;
44
51
  }
45
- t(f);
46
- const i = a(f);
52
+ t($);
53
+ const i = d($);
47
54
  return JSON.parse(
48
55
  JSON.stringify({
49
56
  root: i,
50
- elements: $,
51
- state: w
57
+ elements: p,
58
+ state: x
52
59
  })
53
60
  );
54
61
  }
55
- function S(f) {
56
- const w = f.state;
57
- function $(t) {
62
+ function O($) {
63
+ const x = $.state;
64
+ function p(t) {
58
65
  return { $state: t };
59
66
  }
60
- function p(t) {
67
+ function m(t) {
61
68
  return { $bindState: t };
62
69
  }
63
- function m(t, ...s) {
64
- let r = t[0];
65
- for (let a = 0; a < s.length; a += 1) {
66
- const i = s[a];
67
- !i || typeof i != "object" ? r += "" : "$state" in i ? r += `\${${i.$state}}` : "$item" in i ? r += `\${$item.${i.$item}}` : "$index" in i && (r += "${$index}"), r += t[a + 1];
70
+ function h(t, ...a) {
71
+ let c = t[0];
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];
68
75
  }
69
- return { $template: r };
76
+ return { $template: c };
70
77
  }
71
- function h(t, s, r) {
72
- return { $cond: t, $then: s, $else: r };
78
+ function b(t, a, c) {
79
+ return { $cond: t, $then: a, $else: c };
73
80
  }
74
- function u(t, s) {
75
- return [{ statePath: t, key: s }, {
81
+ function f(t, a) {
82
+ return [{ statePath: t, key: a }, {
76
83
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
84
  $(i) {
78
85
  return { $item: i };
@@ -87,20 +94,20 @@ function S(f) {
87
94
  }
88
95
  }];
89
96
  }
90
- function b(t) {
91
- return I(t, w);
97
+ function w(t) {
98
+ return E(t, x);
92
99
  }
93
100
  return {
94
- $state: $,
95
- $bindState: p,
96
- $template: m,
97
- $cond: h,
98
- repeat: u,
99
- render: b
101
+ $state: p,
102
+ $bindState: m,
103
+ $template: h,
104
+ $cond: b,
105
+ repeat: f,
106
+ render: w
100
107
  };
101
108
  }
102
109
  export {
103
- S as createSpec,
104
- I as renderElementTree
110
+ O as createSpec,
111
+ E as renderElementTree
105
112
  };
106
113
  //# 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 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 }\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\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","allocateGeneratedId","id","elementId","flatten","childIds","flatElement","rootId","createSpec","config","initialState","$state","path","$bindState","$template","strings","values","result","i","val","$cond","condition","then","else_","repeat","statePath","key","render"],"mappings":"AAiEO,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,MAAM,yBAAyBC,EAAE,EAAE,EAAE;AAEjD,MAAAV,EAAY,IAAIU,EAAE,IAAID,CAAU,GAChCN,EAAQ,IAAIO,EAAE,EAAE;AAAA,IAClB;AAEA,KAAAF,IAAAE,EAAE,aAAF,QAAAF,EAAY,QAAQ,CAAAI,MAASP,EAAmBO,GAAOL,CAAI;AAAA,EAC7D;AAEA,WAASM,IAA8B;AACrC,QAAIC;AACJ;AACE,MAAAA,IAAK,WAAWV,CAAe,IAC/BA,KAAmB;AAAA,WACZD,EAAQ,IAAIW,CAAE;AAEvB,WAAAX,EAAQ,IAAIW,CAA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AACT,QAAIC,IAASF,EAAQ,CAAC;AACtB,aAASG,IAAI,GAAGA,IAAIF,EAAO,QAAQE,KAAK,GAAG;AACzC,YAAMC,IAAMH,EAAOE,CAAC;AACpB,MAAI,CAACC,KAAO,OAAOA,KAAQ,WACzBF,KAAU,KACD,YAAYE,IACrBF,KAAU,MAAME,EAAI,MAAM,MACjB,WAAWA,IACpBF,KAAU,YAAYE,EAAI,KAAK,MACtB,YAAYA,MACrBF,KAAU,cAEZA,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,EAAO1C,GAA6B;AAC3C,WAAOD,EAAkBC,GAAMyB,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 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,MAAM,yBAAyBC,EAAE,EAAE,EAAE;AAEjD,MAAAV,EAAY,IAAIU,EAAE,IAAID,CAAU,GAChCN,EAAQ,IAAIO,EAAE,EAAE;AAAA,IAClB;AAEA,KAAAF,IAAAE,EAAE,aAAF,QAAAF,EAAY,QAAQ,CAAAI,MAASP,EAAmBO,GAAOL,CAAI,IAC3D,OAAO,OAAOG,EAAE,SAAS,CAAA,CAAE,EAAE;AAAA,MAAQ,OACnCG,EAAa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