@allternit/ix 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +6 -6
  2. package/dist/adapters/json-render.d.ts +5 -5
  3. package/dist/adapters/json-render.js +12 -12
  4. package/dist/collab/visual-editor.d.ts +1 -1
  5. package/dist/collab/visual-editor.js +4 -4
  6. package/dist/collab/visual-editor.js.map +1 -1
  7. package/dist/collab/yjs-adapter.d.ts +1 -1
  8. package/dist/collab/yjs-adapter.js +2 -2
  9. package/dist/collab/yjs-adapter.js.map +1 -1
  10. package/dist/collab/yjs-client.js +1 -1
  11. package/dist/collab/yjs-client.js.map +1 -1
  12. package/dist/collab/yjs-types.js +1 -1
  13. package/dist/collab/yjs-types.js.map +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/pipeline/llm-to-ix.d.ts +5 -5
  17. package/dist/pipeline/llm-to-ix.d.ts.map +1 -1
  18. package/dist/pipeline/llm-to-ix.js +6 -6
  19. package/dist/react/renderer.d.ts +2 -2
  20. package/dist/react/renderer.js +3 -3
  21. package/dist/react/renderer.js.map +1 -1
  22. package/dist/renderer/renderer.d.ts +1 -1
  23. package/dist/renderer/renderer.js +1 -1
  24. package/dist/runtime/capsule-runtime.d.ts +1 -1
  25. package/dist/runtime/capsule-runtime.js +1 -1
  26. package/dist/sdk/api.d.ts +3 -3
  27. package/dist/sdk/api.js +3 -3
  28. package/dist/sdk/index.d.ts +2 -2
  29. package/dist/sdk/index.js +2 -2
  30. package/dist/sdk/react.d.ts +2 -2
  31. package/dist/sdk/react.js +2 -2
  32. package/dist/state/index.d.ts +1 -1
  33. package/dist/state/index.js +1 -1
  34. package/dist/state/store.d.ts +1 -1
  35. package/dist/state/store.js +3 -3
  36. package/dist/state/store.js.map +1 -1
  37. package/dist/svelte/index.d.ts +1 -1
  38. package/dist/svelte/index.js +1 -1
  39. package/dist/svelte/renderer.d.ts +3 -3
  40. package/dist/svelte/renderer.js +4 -4
  41. package/dist/svelte/renderer.js.map +1 -1
  42. package/dist/types/index.d.ts +1 -1
  43. package/dist/types/index.js +1 -1
  44. package/dist/vue/renderer.d.ts +3 -3
  45. package/dist/vue/renderer.js +5 -5
  46. package/dist/vue/renderer.js.map +1 -1
  47. package/package.json +8 -8
  48. package/dist/adapters/json-render.d.ts.bak +0 -211
  49. package/dist/adapters/json-render.js.bak +0 -576
  50. package/dist/catalog/registry.d.ts.bak +0 -65
  51. package/dist/catalog/registry.js.bak +0 -388
  52. package/dist/collab/capsule-registry.d.ts.bak +0 -114
  53. package/dist/collab/capsule-registry.js.bak +0 -271
  54. package/dist/collab/index.d.ts.bak +0 -21
  55. package/dist/collab/index.js.bak +0 -32
  56. package/dist/collab/visual-editor.d.ts.bak +0 -199
  57. package/dist/collab/visual-editor.js.bak +0 -259
  58. package/dist/collab/yjs-adapter.d.ts.bak +0 -95
  59. package/dist/collab/yjs-adapter.js.bak +0 -282
  60. package/dist/collab/yjs-client.d.ts.bak +0 -101
  61. package/dist/collab/yjs-client.js.bak +0 -193
  62. package/dist/collab/yjs-protocols.d.ts.bak +0 -128
  63. package/dist/collab/yjs-protocols.js.bak +0 -245
  64. package/dist/collab/yjs-types.d.ts.bak +0 -201
  65. package/dist/collab/yjs-types.js.bak +0 -45
  66. package/dist/index.d.ts.bak +0 -38
  67. package/dist/index.js.bak +0 -48
  68. package/dist/pipeline/llm-to-ix.d.ts.bak +0 -249
  69. package/dist/pipeline/llm-to-ix.js.bak +0 -992
  70. package/dist/react/index.d.ts.bak +0 -18
  71. package/dist/react/index.js.bak +0 -18
  72. package/dist/react/renderer.d.ts.bak +0 -47
  73. package/dist/react/renderer.js.bak +0 -420
  74. package/dist/renderer/renderer.d.ts.bak +0 -55
  75. package/dist/renderer/renderer.js.bak +0 -232
  76. package/dist/runtime/capsule-runtime.d.ts.bak +0 -227
  77. package/dist/runtime/capsule-runtime.js.bak +0 -563
  78. package/dist/runtime/policy-gates.d.ts.bak +0 -116
  79. package/dist/runtime/policy-gates.js.bak +0 -317
  80. package/dist/schema/ui-ir.d.ts.bak +0 -26
  81. package/dist/schema/ui-ir.js.bak +0 -51
  82. package/dist/sdk/api.d.ts.bak +0 -101
  83. package/dist/sdk/api.js.bak +0 -177
  84. package/dist/sdk/index.d.ts.bak +0 -9
  85. package/dist/sdk/index.js.bak +0 -10
  86. package/dist/sdk/react.d.ts.bak +0 -63
  87. package/dist/sdk/react.js.bak +0 -161
  88. package/dist/state/index.d.ts.bak +0 -8
  89. package/dist/state/index.js.bak +0 -8
  90. package/dist/state/patch.d.ts.bak +0 -73
  91. package/dist/state/patch.js.bak +0 -437
  92. package/dist/state/store.d.ts.bak +0 -50
  93. package/dist/state/store.js.bak +0 -246
  94. package/dist/svelte/index.d.ts.bak +0 -15
  95. package/dist/svelte/index.js.bak +0 -15
  96. package/dist/svelte/renderer.d.ts.bak +0 -35
  97. package/dist/svelte/renderer.js.bak +0 -317
  98. package/dist/types/index.d.ts.bak +0 -349
  99. package/dist/types/index.js.bak +0 -152
  100. package/dist/vue/index.d.ts.bak +0 -18
  101. package/dist/vue/index.js.bak +0 -18
  102. package/dist/vue/renderer.d.ts.bak +0 -46
  103. package/dist/vue/renderer.js.bak +0 -302
@@ -1,18 +0,0 @@
1
- /**
2
- * React Renderer
3
- *
4
- * @example
5
- * ```tsx
6
- * import { createReactRenderer, createDefaultCatalog } from '@allternit/ix/react';
7
- *
8
- * const renderer = createReactRenderer({
9
- * catalog: createDefaultCatalog(),
10
- * });
11
- *
12
- * function App() {
13
- * return <renderer.UIRoot root={uiDefinition} />;
14
- * }
15
- * ```
16
- */
17
- export { createReactRenderer, type ReactRenderer, type ReactRendererConfig, } from './renderer';
18
- //# sourceMappingURL=index.d.ts.map
@@ -1,18 +0,0 @@
1
- /**
2
- * React Renderer
3
- *
4
- * @example
5
- * ```tsx
6
- * import { createReactRenderer, createDefaultCatalog } from '@allternit/ix/react';
7
- *
8
- * const renderer = createReactRenderer({
9
- * catalog: createDefaultCatalog(),
10
- * });
11
- *
12
- * function App() {
13
- * return <renderer.UIRoot root={uiDefinition} />;
14
- * }
15
- * ```
16
- */
17
- export { createReactRenderer, } from './renderer';
18
- //# sourceMappingURL=index.js.map
@@ -1,47 +0,0 @@
1
- /**
2
- * React Renderer for A2R-IX
3
- *
4
- * Renders A2R-IX UI IR to React components.
5
- */
6
- import React from 'react';
7
- import type { UIRoot, UIComponent } from '../types';
8
- import type { StateStore } from '../state/store';
9
- import type { ComponentCatalog } from '../catalog/registry';
10
- import type { JSONPatch } from '../state/patch';
11
- export interface ReactRendererConfig {
12
- /** Component catalog */
13
- catalog?: ComponentCatalog;
14
- /** Initial state store */
15
- stateStore?: StateStore;
16
- /** Component mapping (type -> React component) */
17
- components?: Record<string, React.ComponentType<unknown>>;
18
- /** Event handler */
19
- onEvent?: (name: string, payload: unknown) => void;
20
- /** Error handler */
21
- onError?: (error: Error, componentId?: string) => void;
22
- /** Debug mode */
23
- debug?: boolean;
24
- }
25
- export interface ReactRenderer {
26
- /** Render UI root */
27
- UIRoot: React.FC<{
28
- root: UIRoot;
29
- }>;
30
- /** Render single component */
31
- UIComponent: React.FC<{
32
- component: UIComponent;
33
- }>;
34
- /** Get state value */
35
- getState: (path: string) => unknown;
36
- /** Set state value */
37
- setState: (path: string, value: unknown) => void;
38
- /** Apply patch */
39
- applyPatch: (patch: JSONPatch) => void;
40
- /** Dispatch action */
41
- dispatch: (actionId: string, params?: Record<string, unknown>) => void;
42
- }
43
- /**
44
- * Create React renderer
45
- */
46
- export declare function createReactRenderer(config: ReactRendererConfig): ReactRenderer;
47
- //# sourceMappingURL=renderer.d.ts.map
@@ -1,420 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- /**
3
- * React Renderer for A2R-IX
4
- *
5
- * Renders A2R-IX UI IR to React components.
6
- */
7
- import React, { useState, useEffect, useCallback, useMemo } from 'react';
8
- import { createStateStore } from '../state/store';
9
- import { createDefaultCatalog } from '../catalog/registry';
10
- import { applyPatchToStore } from '../state/patch';
11
- import { evaluateExpression } from '../types';
12
- /**
13
- * Create React renderer
14
- */
15
- export function createReactRenderer(config) {
16
- const catalog = config.catalog ?? createDefaultCatalog();
17
- const customComponents = config.components ?? {};
18
- // Context for state store
19
- const StoreContext = React.createContext(null);
20
- /**
21
- * Hook to use state from store
22
- */
23
- function useStoreState(path) {
24
- const store = React.useContext(StoreContext);
25
- if (!store)
26
- throw new Error('Store not available');
27
- const [value, setValue] = useState(() => store.get(path));
28
- useEffect(() => {
29
- const unsubscribe = store.subscribe(path, (newValue) => {
30
- setValue(newValue);
31
- });
32
- return unsubscribe;
33
- }, [store, path]);
34
- const updateValue = useCallback((newValue) => {
35
- store.set(path, newValue);
36
- }, [store, path]);
37
- return [value, updateValue];
38
- }
39
- /**
40
- * Hook to evaluate expression
41
- */
42
- function useExpression(expr, localContext = {}) {
43
- const store = React.useContext(StoreContext);
44
- return useMemo(() => {
45
- if (expr === undefined)
46
- return undefined;
47
- const context = { ...store?.snapshot(), ...localContext };
48
- return evaluateExpression(expr, context);
49
- }, [expr, store, localContext]);
50
- }
51
- /**
52
- * Component renderer
53
- */
54
- const UIComponentRenderer = ({ component, localContext = {} }) => {
55
- const store = React.useContext(StoreContext);
56
- const [error, setError] = useState(null);
57
- // Handle errors
58
- if (error) {
59
- config.onError?.(error, component.id);
60
- return _jsx(ErrorFallback, { error: error, componentId: component.id });
61
- }
62
- try {
63
- // Evaluate condition
64
- if (component.condition) {
65
- const conditionValue = evaluateExpression(component.condition, {
66
- ...store?.snapshot(),
67
- ...localContext,
68
- });
69
- if (!conditionValue)
70
- return null;
71
- }
72
- // Handle repeat
73
- if (component.repeat) {
74
- return _jsx(RepeatComponent, { component: component, localContext: localContext });
75
- }
76
- return _jsx(SingleComponent, { component: component, localContext: localContext });
77
- }
78
- catch (err) {
79
- setError(err);
80
- return null;
81
- }
82
- };
83
- /**
84
- * Repeat component renderer
85
- */
86
- const RepeatComponent = ({ component, localContext }) => {
87
- const store = React.useContext(StoreContext);
88
- const repeat = component.repeat;
89
- const items = store?.get(repeat.items) ?? [];
90
- // Apply filter if specified
91
- let filteredItems = items;
92
- if (repeat.filter) {
93
- filteredItems = items.filter((item, index) => {
94
- const ctx = { ...localContext, [repeat.as]: item, ...(repeat.indexAs ? { [repeat.indexAs]: index } : {}) };
95
- return evaluateExpression(repeat.filter, { ...store?.snapshot(), ...ctx });
96
- });
97
- }
98
- // Apply sort if specified
99
- if (repeat.sort) {
100
- filteredItems = [...filteredItems].sort((a, b) => {
101
- const ctxA = { ...localContext, [repeat.as]: a };
102
- const ctxB = { ...localContext, [repeat.as]: b };
103
- const valA = evaluateExpression(repeat.sort, { ...store?.snapshot(), ...ctxA });
104
- const valB = evaluateExpression(repeat.sort, { ...store?.snapshot(), ...ctxB });
105
- if (valA < valB)
106
- return -1;
107
- if (valA > valB)
108
- return 1;
109
- return 0;
110
- });
111
- }
112
- return (_jsx(_Fragment, { children: filteredItems.map((item, index) => {
113
- const itemContext = {
114
- ...localContext,
115
- [repeat.as]: item,
116
- ...(repeat.indexAs ? { [repeat.indexAs]: index } : {}),
117
- };
118
- return (_jsx(SingleComponent, { component: { ...component, id: `${component.id}-${index}` }, localContext: itemContext }, `${component.id}-${index}`));
119
- }) }));
120
- };
121
- /**
122
- * Single component renderer
123
- */
124
- const SingleComponent = ({ component, localContext }) => {
125
- const store = React.useContext(StoreContext);
126
- const [props, setProps] = useState({});
127
- // Build props with bindings
128
- useEffect(() => {
129
- const newProps = { ...component.props };
130
- // Apply bindings
131
- component.bindings?.forEach((binding) => {
132
- const value = store?.get(binding.statePath);
133
- newProps[binding.prop] = value;
134
- });
135
- setProps(newProps);
136
- }, [component, store]);
137
- // Subscribe to binding changes
138
- useEffect(() => {
139
- if (!component.bindings || !store)
140
- return;
141
- const unsubscribes = component.bindings.map((binding) => store.subscribe(binding.statePath, (value) => {
142
- setProps((prev) => ({ ...prev, [binding.prop]: value }));
143
- }));
144
- return () => unsubscribes.forEach((unsub) => unsub());
145
- }, [component.bindings, store]);
146
- // Handle events
147
- const handleEvent = useCallback((eventName, actionId, params) => {
148
- return (...eventArgs) => {
149
- const fullContext = {
150
- ...store?.snapshot(),
151
- ...localContext,
152
- event: eventArgs[0],
153
- };
154
- dispatchAction(actionId, params, fullContext);
155
- };
156
- }, [store, localContext]);
157
- // Get component type
158
- const Component = customComponents[component.type] || getBuiltinComponent(component.type);
159
- if (!Component) {
160
- config.onError?.(new Error(`Unknown component type: ${component.type}`), component.id);
161
- return null;
162
- }
163
- // Build final props
164
- const finalProps = { ...props };
165
- // Add event handlers
166
- component.events?.forEach((event) => {
167
- finalProps[event.event] = handleEvent(event.event, event.action, event.params);
168
- });
169
- // Add two-way binding handlers
170
- component.bindings?.forEach((binding) => {
171
- if (binding.direction === 'two-way') {
172
- const changeHandlerName = `on${capitalize(binding.prop)}Change`;
173
- finalProps[changeHandlerName] = (value) => {
174
- store?.set(binding.statePath, value);
175
- };
176
- }
177
- });
178
- // Render children
179
- const children = component.children?.map((child) => (_jsx(UIComponentRenderer, { component: child, localContext: localContext }, child.id)));
180
- // Use createElement for dynamic component rendering
181
- return React.createElement(Component, { ...finalProps, key: component.id }, children?.length ? children : null);
182
- };
183
- /**
184
- * Error fallback component
185
- */
186
- const ErrorFallback = ({ error, componentId }) => {
187
- if (process.env.NODE_ENV === 'production') {
188
- return null;
189
- }
190
- return (_jsxs("div", { style: {
191
- padding: '12px',
192
- background: '#fef2f2',
193
- border: '1px solid #fecaca',
194
- borderRadius: '4px',
195
- color: '#dc2626',
196
- fontSize: '12px',
197
- }, children: [_jsxs("strong", { children: ["Component Error", componentId ? ` (${componentId})` : ''] }), _jsx("pre", { style: { margin: '8px 0 0', whiteSpace: 'pre-wrap' }, children: error.message })] }));
198
- };
199
- /**
200
- * Root component
201
- */
202
- const UIRootComponent = ({ root }) => {
203
- const [store, setStore] = useState(null);
204
- useEffect(() => {
205
- const newStore = config.stateStore ?? createStateStore({
206
- initial: root.state.initial,
207
- variables: root.state.variables,
208
- });
209
- // Initialize state
210
- if (root.state.initial) {
211
- Object.entries(root.state.initial).forEach(([path, value]) => {
212
- newStore.set(path, value);
213
- });
214
- }
215
- setStore(newStore);
216
- }, [root]);
217
- if (!store)
218
- return null;
219
- return (_jsxs(StoreContext.Provider, { value: store, children: [_jsx("div", { className: "a2r-ix-root", "data-version": root.version, children: root.components.map((component) => (_jsx(UIComponentRenderer, { component: component }, component.id))) }), root.css && _jsx("style", { children: root.css })] }));
220
- };
221
- /**
222
- * Get builtin component
223
- */
224
- function getBuiltinComponent(type) {
225
- const builtins = {
226
- Box: (({ children, ...props }) => _jsx("div", { style: convertBoxProps(props), children: children })),
227
- Stack: (({ children, direction = 'vertical', spacing = 0, ...props }) => (_jsx("div", { style: {
228
- display: 'flex',
229
- flexDirection: direction === 'horizontal' ? 'row' : 'column',
230
- gap: `${spacing * 4}px`,
231
- ...convertBoxProps(props),
232
- }, children: children }))),
233
- Text: (({ children, size = 'md', weight = 'normal', color, align, ...props }) => (_jsx("span", { style: {
234
- fontSize: getTextSize(size),
235
- fontWeight: getFontWeight(weight),
236
- color,
237
- textAlign: align,
238
- ...props.style,
239
- }, children: children }))),
240
- Heading: (({ children, level = 1, color, ...props }) => {
241
- const Tag = `h${level}`;
242
- return (_jsx(Tag, { style: {
243
- fontSize: getHeadingSize(level),
244
- fontWeight: 'bold',
245
- color,
246
- margin: '0 0 16px',
247
- ...props.style,
248
- }, children: children }));
249
- }),
250
- Paragraph: ({ children, size = 'md', color, ...props }) => (_jsx("p", { style: {
251
- fontSize: getTextSize(size),
252
- color,
253
- margin: '0 0 12px',
254
- lineHeight: 1.6,
255
- ...props.style,
256
- }, children: children })),
257
- Button: ({ children, variant = 'primary', size = 'md', disabled, loading, onClick, ...props }) => (_jsx("button", { onClick: onClick, disabled: disabled || loading, style: {
258
- padding: size === 'sm' ? '6px 12px' : size === 'lg' ? '12px 24px' : '8px 16px',
259
- fontSize: size === 'sm' ? '14px' : size === 'lg' ? '18px' : '16px',
260
- background: getButtonColor(variant),
261
- color: '#fff',
262
- border: 'none',
263
- borderRadius: '6px',
264
- cursor: disabled ? 'not-allowed' : 'pointer',
265
- opacity: disabled ? 0.6 : 1,
266
- ...props.style,
267
- }, children: loading ? 'Loading...' : children })),
268
- Input: ({ value, placeholder, type = 'text', disabled, required, onChange, onBlur, onFocus, ...props }) => (_jsx("input", { type: type, value: value, placeholder: placeholder, disabled: disabled, required: required, onChange: (e) => onChange?.(e.target.value), onBlur: onBlur, onFocus: onFocus, style: {
269
- padding: '8px 12px',
270
- fontSize: '16px',
271
- border: '1px solid #d1d5db',
272
- borderRadius: '6px',
273
- width: '100%',
274
- ...props.style,
275
- } })),
276
- TextArea: ({ value, placeholder, rows = 3, disabled, onChange, ...props }) => (_jsx("textarea", { value: value, placeholder: placeholder, rows: rows, disabled: disabled, onChange: (e) => onChange?.(e.target.value), style: {
277
- padding: '8px 12px',
278
- fontSize: '16px',
279
- border: '1px solid #d1d5db',
280
- borderRadius: '6px',
281
- width: '100%',
282
- resize: 'vertical',
283
- ...props.style,
284
- } })),
285
- Select: ({ value, options, placeholder, disabled, onChange, ...props }) => (_jsxs("select", { value: value, disabled: disabled, onChange: (e) => onChange?.(e.target.value), style: {
286
- padding: '8px 12px',
287
- fontSize: '16px',
288
- border: '1px solid #d1d5db',
289
- borderRadius: '6px',
290
- width: '100%',
291
- ...props.style,
292
- }, children: [placeholder && _jsx("option", { value: "", children: placeholder }), options?.map((opt) => (_jsx("option", { value: opt.value, children: opt.label }, opt.value)))] })),
293
- Card: ({ children, padding = 16, elevation = 1, borderRadius = 8, ...props }) => (_jsx("div", { style: {
294
- padding: `${padding}px`,
295
- background: '#fff',
296
- borderRadius: `${borderRadius}px`,
297
- boxShadow: getElevation(elevation),
298
- ...props.style,
299
- }, children: children })),
300
- Badge: ({ children, variant = 'default', size = 'md' }) => (_jsx("span", { style: {
301
- display: 'inline-flex',
302
- alignItems: 'center',
303
- padding: size === 'sm' ? '2px 6px' : '4px 10px',
304
- fontSize: size === 'sm' ? '12px' : '14px',
305
- fontWeight: 500,
306
- background: getBadgeColor(variant),
307
- color: '#fff',
308
- borderRadius: '9999px',
309
- }, children: children })),
310
- Image: ({ src, alt = '', width, height, objectFit, ...props }) => (_jsx("img", { src: src, alt: alt, width: width, height: height, style: {
311
- objectFit: objectFit,
312
- maxWidth: '100%',
313
- ...props.style,
314
- } })),
315
- Icon: ({ name, size = 16, color }) => (_jsx("span", { style: {
316
- width: `${size}px`,
317
- height: `${size}px`,
318
- display: 'inline-flex',
319
- alignItems: 'center',
320
- justifyContent: 'center',
321
- color,
322
- }, children: name })),
323
- List: ({ items, renderItem, emptyText = 'No items' }) => {
324
- if (!items || items.length === 0) {
325
- return _jsx("div", { style: { color: '#6b7280', fontStyle: 'italic' }, children: emptyText });
326
- }
327
- return (_jsx("ul", { style: { listStyle: 'none', padding: 0, margin: 0 }, children: items.map((item, index) => (_jsx("li", { children: renderItem(item, index) }, index))) }));
328
- },
329
- Table: ({ data, columns, onRowClick, emptyText = 'No data' }) => {
330
- if (!data || data.length === 0) {
331
- return _jsx("div", { style: { color: '#6b7280', fontStyle: 'italic' }, children: emptyText });
332
- }
333
- return (_jsxs("table", { style: { width: '100%', borderCollapse: 'collapse' }, children: [_jsx("thead", { children: _jsx("tr", { children: columns.map((col) => (_jsx("th", { style: { textAlign: 'left', padding: '8px', borderBottom: '1px solid #e5e7eb' }, children: col.title }, col.key))) }) }), _jsx("tbody", { children: data.map((row, index) => (_jsx("tr", { onClick: () => onRowClick?.(row, index), style: { cursor: onRowClick ? 'pointer' : undefined }, children: columns.map((col) => (_jsx("td", { style: { padding: '8px', borderBottom: '1px solid #e5e7eb' }, children: col.render ? col.render(row[col.key], row) : row[col.key] }, col.key))) }, index))) })] }));
334
- },
335
- };
336
- return builtins[type];
337
- }
338
- /**
339
- * Dispatch action
340
- */
341
- function dispatchAction(actionId, params, context) {
342
- config.onEvent?.(actionId, { params, context });
343
- }
344
- // Public API
345
- return {
346
- UIRoot: UIRootComponent,
347
- UIComponent: UIComponentRenderer,
348
- getState: (path) => config.stateStore?.get(path),
349
- setState: (path, value) => config.stateStore?.set(path, value),
350
- applyPatch: (patch) => {
351
- if (config.stateStore) {
352
- applyPatchToStore(config.stateStore, patch);
353
- }
354
- },
355
- dispatch: (actionId, params) => {
356
- const context = config.stateStore?.snapshot() ?? {};
357
- dispatchAction(actionId, params, context);
358
- },
359
- };
360
- }
361
- // Helper functions
362
- function capitalize(str) {
363
- return str.charAt(0).toUpperCase() + str.slice(1);
364
- }
365
- function convertBoxProps(props) {
366
- return {
367
- padding: props.padding !== undefined ? `${props.padding * 4}px` : undefined,
368
- margin: props.margin !== undefined ? `${props.margin * 4}px` : undefined,
369
- width: props.width,
370
- height: props.height,
371
- display: props.display,
372
- flexDirection: props.flexDirection,
373
- justifyContent: props.justifyContent,
374
- alignItems: props.alignItems,
375
- gap: props.gap !== undefined ? `${props.gap * 4}px` : undefined,
376
- backgroundColor: props.backgroundColor,
377
- borderRadius: props.borderRadius !== undefined ? `${props.borderRadius}px` : undefined,
378
- };
379
- }
380
- function getTextSize(size) {
381
- const sizes = { xs: '12px', sm: '14px', md: '16px', lg: '18px', xl: '20px' };
382
- return sizes[size] || sizes.md;
383
- }
384
- function getHeadingSize(level) {
385
- const sizes = { 1: '32px', 2: '24px', 3: '20px', 4: '18px', 5: '16px', 6: '14px' };
386
- return sizes[level] || sizes[1];
387
- }
388
- function getFontWeight(weight) {
389
- const weights = { normal: 400, medium: 500, semibold: 600, bold: 700 };
390
- return weights[weight] || weights.normal;
391
- }
392
- function getButtonColor(variant) {
393
- const colors = {
394
- primary: '#3b82f6',
395
- secondary: '#6b7280',
396
- ghost: 'transparent',
397
- danger: '#ef4444',
398
- };
399
- return colors[variant] || colors.primary;
400
- }
401
- function getBadgeColor(variant) {
402
- const colors = {
403
- default: '#6b7280',
404
- success: '#22c55e',
405
- warning: '#f59e0b',
406
- error: '#ef4444',
407
- info: '#3b82f6',
408
- };
409
- return colors[variant] || colors.default;
410
- }
411
- function getElevation(level) {
412
- const shadows = {
413
- 0: 'none',
414
- 1: '0 1px 3px rgba(0,0,0,0.1)',
415
- 2: '0 4px 6px rgba(0,0,0,0.1)',
416
- 3: '0 10px 15px rgba(0,0,0,0.1)',
417
- };
418
- return shadows[level] || shadows[1];
419
- }
420
- //# sourceMappingURL=renderer.js.map
@@ -1,55 +0,0 @@
1
- /**
2
- * UI Renderer
3
- *
4
- * Core renderer for A2R-IX UI IR. Platform-agnostic base that delegates
5
- to platform-specific renderers (React, Vue, etc.).
6
- */
7
- import type { UIRoot } from '../types';
8
- import type { StateStore } from '../state/store';
9
- import type { ComponentCatalog } from '../catalog/registry';
10
- import type { JSONPatch } from '../state/patch';
11
- export interface UIRendererConfig {
12
- /** Component catalog */
13
- catalog?: ComponentCatalog;
14
- /** Platform renderer */
15
- platform: PlatformRenderer;
16
- /** State store instance */
17
- stateStore?: StateStore;
18
- /** Event handler */
19
- onEvent?: (name: string, payload: unknown) => void;
20
- /** Error handler */
21
- onError?: (error: Error, componentId?: string) => void;
22
- /** Debug mode */
23
- debug?: boolean;
24
- }
25
- export interface PlatformRenderer {
26
- /** Create element */
27
- createElement(type: string, props: Record<string, unknown>, children: unknown[]): unknown;
28
- /** Create text node */
29
- createTextNode(text: string): unknown;
30
- /** Render to container */
31
- render(element: unknown, container: unknown): void;
32
- /** Unmount */
33
- unmount(container: unknown): void;
34
- }
35
- export interface UIRenderer {
36
- /** Render UI to container */
37
- render(root: UIRoot, container: unknown): void;
38
- /** Update UI with patch */
39
- update(patch: JSONPatch): void;
40
- /** Dispatch action */
41
- dispatch(actionId: string, params?: Record<string, unknown>): void;
42
- /** Get state */
43
- getState(path?: string): unknown;
44
- /** Set state */
45
- setState(path: string, value: unknown): void;
46
- /** Subscribe to state changes */
47
- subscribe(path: string, callback: (value: unknown) => void): () => void;
48
- /** Destroy renderer */
49
- destroy(): void;
50
- }
51
- /**
52
- * Create UI renderer
53
- */
54
- export declare function createUIRenderer(config: UIRendererConfig): UIRenderer;
55
- //# sourceMappingURL=renderer.d.ts.map