react-native-live-widgets 1.2.0 → 1.2.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.
Files changed (87) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +129 -50
  3. package/android/src/main/AndroidManifest.xml +12 -0
  4. package/android/src/main/assets/fonts/MaterialIcons-Regular.ttf +0 -0
  5. package/android/src/main/java/com/reactnativeliveactivity/bridge/LiveActivityModule.kt +61 -1
  6. package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityNotifier.kt +153 -17
  7. package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityReceiver.kt +1 -1
  8. package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +529 -59
  9. package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetImageCache.kt +53 -0
  10. package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +684 -83
  11. package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +129 -57
  12. package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicQuickSettingsTileService.kt +120 -0
  13. package/android/src/main/res/layout/rn_live_widget_hit_zone.xml +16 -0
  14. package/android/src/main/res/layout/rn_live_widget_host.xml +16 -87
  15. package/app.plugin.js +36 -0
  16. package/assets/MaterialIcons.json +2236 -0
  17. package/cli/codegen.js +789 -0
  18. package/cli/setup.js +323 -63
  19. package/docs/EXPO-GUIDE-EN.md +21 -3
  20. package/docs/EXPO-GUIDE-VI.md +21 -3
  21. package/docs/GUIDE-EN.md +444 -21
  22. package/docs/GUIDE-VI.md +473 -22
  23. package/docs/index.html +2263 -265
  24. package/docs/llms-full.txt +41 -0
  25. package/docs/llms.txt +24 -7
  26. package/ios/Bridge/LiveActivityModule.swift +333 -44
  27. package/ios/Intents/DynamicWidgetActionIntent.swift +57 -2
  28. package/ios/Models/DynamicLayoutModels.swift +120 -5
  29. package/ios/Renderer/DynamicNodeView.swift +184 -20
  30. package/ios/Storage/DynamicWidgetStateStore.swift +649 -38
  31. package/ios/Widgets/DynamicControlWidget.swift +63 -0
  32. package/ios/Widgets/DynamicHomeScreenWidget.swift +104 -26
  33. package/ios/Widgets/DynamicLiveActivityWidget.swift +25 -4
  34. package/lib/builder.d.ts +50 -7
  35. package/lib/builder.d.ts.map +1 -1
  36. package/lib/builder.js +391 -29
  37. package/lib/builder.js.map +1 -1
  38. package/lib/dispatcher.js +16 -10
  39. package/lib/dispatcher.js.map +1 -1
  40. package/lib/hooks.d.ts +13 -9
  41. package/lib/hooks.d.ts.map +1 -1
  42. package/lib/hooks.js +105 -42
  43. package/lib/hooks.js.map +1 -1
  44. package/lib/index.d.ts +96 -8
  45. package/lib/index.d.ts.map +1 -1
  46. package/lib/index.js +415 -97
  47. package/lib/index.js.map +1 -1
  48. package/lib/ir.d.ts +15 -0
  49. package/lib/ir.d.ts.map +1 -0
  50. package/lib/ir.js +386 -0
  51. package/lib/ir.js.map +1 -0
  52. package/lib/jsx.d.ts +19 -7
  53. package/lib/jsx.d.ts.map +1 -1
  54. package/lib/jsx.js +179 -95
  55. package/lib/jsx.js.map +1 -1
  56. package/lib/material-icons.generated.d.ts +8 -0
  57. package/lib/material-icons.generated.d.ts.map +1 -0
  58. package/lib/material-icons.generated.js +9 -0
  59. package/lib/material-icons.generated.js.map +1 -0
  60. package/lib/preview.d.ts +11 -27
  61. package/lib/preview.d.ts.map +1 -1
  62. package/lib/preview.js +456 -119
  63. package/lib/preview.js.map +1 -1
  64. package/lib/sf-symbols.generated.d.ts +8 -0
  65. package/lib/sf-symbols.generated.d.ts.map +1 -0
  66. package/lib/sf-symbols.generated.js +9 -0
  67. package/lib/sf-symbols.generated.js.map +1 -0
  68. package/lib/types.d.ts +506 -30
  69. package/lib/types.d.ts.map +1 -1
  70. package/lib/types.js +2 -1
  71. package/lib/types.js.map +1 -1
  72. package/package.json +7 -2
  73. package/scripts/build.js +98 -0
  74. package/scripts/generate-material-icons.js +93 -0
  75. package/scripts/generate-sf-symbols.js +95 -0
  76. package/scripts/release.js +115 -0
  77. package/scripts/test-ir-semantic.js +314 -0
  78. package/src/builder.ts +439 -26
  79. package/src/hooks.ts +88 -12
  80. package/src/index.ts +385 -57
  81. package/src/ir.ts +436 -0
  82. package/src/jsx.tsx +99 -21
  83. package/src/material-icons.generated.ts +3844 -0
  84. package/src/preview.tsx +533 -55
  85. package/src/react-native-env.d.ts +1 -0
  86. package/src/sf-symbols.generated.ts +9533 -0
  87. package/src/types.ts +601 -31
package/lib/preview.js CHANGED
@@ -1,126 +1,439 @@
1
- import React, { useState } from 'react';
2
- import { View, Text as RNText, Image as RNImage, TouchableOpacity, StyleSheet, } from 'react-native';
3
- import { renderToWidget, extractPropsAndStyle } from './jsx';
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.VoltraWidgetPreview = exports.WidgetPreview = void 0;
37
+ const react_1 = __importStar(require("react"));
38
+ const react_native_1 = require("react-native");
39
+ const jsx_1 = require("./jsx");
40
+ const dispatcher_1 = require("./dispatcher");
41
+ const builder_1 = require("./builder");
4
42
  const SIZE_DIMENSIONS = {
5
43
  small: { width: 158, height: 158, label: 'Small • 158×158' },
6
44
  medium: { width: 338, height: 158, label: 'Medium • 338×158' },
7
45
  large: { width: 338, height: 354, label: 'Large • 338×354' },
46
+ extraLarge: { width: 338, height: 420, label: 'Extra Large • 338×420' },
47
+ standBy: { width: 310, height: 158, label: 'StandBy • 310×158' },
8
48
  lockScreen: { width: 350, height: 80, label: 'Lock Screen • 350×80' },
9
49
  dynamicIsland: { width: 350, height: 160, label: 'Dynamic Island' },
50
+ control: { width: 170, height: 76, label: 'Control • iOS 18 / QS Tile' },
10
51
  };
11
- function parseDynamicColor(c) {
52
+ function parseDynamicColor(c, mode = 'dark') {
12
53
  if (!c)
13
54
  return undefined;
14
55
  if (typeof c === 'string')
15
56
  return c;
16
- if (typeof c === 'object')
17
- return c.dark || c.light;
57
+ if (typeof c === 'object') {
58
+ if (mode === 'tinted' && c.tinted)
59
+ return c.tinted;
60
+ if (mode === 'light' && c.light)
61
+ return c.light;
62
+ return c.dark || c.light || c.tinted;
63
+ }
18
64
  return undefined;
19
65
  }
20
- /**
21
- * 📱 Bộ Component xem trước tiện ích trực tiếp trong ứng dụng React Native (In-App Widget Preview).
22
- * Cho phép lập trình viên và người dùng trải nghiệm giao diện & bấm thử tương tác của Widget
23
- * ngay trong màn hình App mà không cần ra ngoài Home Screen.
24
- *
25
- * Cách dùng 1 (Truyền layout prop):
26
- * ```tsx
27
- * <WidgetPreview size="medium" layout={myLayout} onAction={(act) => alert(act)} />
28
- * ```
29
- *
30
- * Cách dùng 2 (Truyền JSX children trực tiếp):
31
- * ```tsx
32
- * <WidgetPreview size="medium">
33
- * <VStack padding={16} backgroundColor="#0F172A" borderRadius={16}>
34
- * <HStack justifyContent="spaceBetween">
35
- * <Text fontSize={14} fontWeight="bold" color="#FFFFFF">Vào ca sáng</Text>
36
- * <Badge text="07:54" backgroundColor="#064E3B" textColor="#6EE7B7" />
37
- * </HStack>
38
- * <Button title="Làm mới" actionId="refresh" />
39
- * </VStack>
40
- * </WidgetPreview>
41
- * ```
42
- */
43
- export const WidgetPreview = ({ size: initialSize = 'medium', layout, children, onAction, showBadge = true, interactiveSizeSwitch = false, style, }) => {
44
- const [activeSize, setActiveSize] = useState(initialSize);
66
+ function extractShadowStyle(p) {
67
+ if (!p)
68
+ return {};
69
+ const shadowColor = parseDynamicColor(p.shadowColor);
70
+ if (!shadowColor)
71
+ return {};
72
+ const rad = p.shadowRadius ?? 4;
73
+ return {
74
+ shadowColor,
75
+ shadowOffset: p.shadowOffset
76
+ ? { width: p.shadowOffset.x ?? 0, height: p.shadowOffset.y ?? 2 }
77
+ : { width: 0, height: 2 },
78
+ shadowOpacity: p.shadowOpacity ?? 0.35,
79
+ shadowRadius: rad,
80
+ elevation: Math.min(8, Math.max(1, Math.round(rad))),
81
+ };
82
+ }
83
+ const WidgetPreview = ({ size: initialSizeProp, layout, data, controlConfig, children, onAction, showBadge = true, interactiveSizeSwitch = false, style, }) => {
84
+ const initialSize = initialSizeProp ?? (controlConfig ? 'control' : 'medium');
85
+ const [activeSize, setActiveSize] = (0, react_1.useState)(initialSize);
86
+ const pageConfigObj = !children && layout && typeof layout === 'object' && layout.pages
87
+ ? layout
88
+ : null;
89
+ const pageOrder = pageConfigObj
90
+ ? Array.isArray(pageConfigObj.pageOrder) && pageConfigObj.pageOrder.length > 0
91
+ ? pageConfigObj.pageOrder
92
+ : Object.keys(pageConfigObj.pages)
93
+ : [];
94
+ const defaultPage = pageConfigObj
95
+ ? pageConfigObj.initialPage || pageOrder[0] || ''
96
+ : '';
97
+ const [activePage, setActivePage] = (0, react_1.useState)(defaultPage);
98
+ const [syncVars, setSyncVars] = (0, react_1.useState)(() => ({
99
+ _lastSyncTime: new Date().toLocaleTimeString('en-GB', { hour12: false }),
100
+ id: '2026',
101
+ title: 'Hoàn thành kế hoạch quý 4',
102
+ }));
103
+ (0, react_1.useEffect)(() => {
104
+ if (defaultPage) {
105
+ setActivePage((prev) => (pageConfigObj?.pages?.[prev] ? prev : defaultPage));
106
+ }
107
+ }, [defaultPage, pageConfigObj]);
45
108
  // Trích xuất LayoutNode từ props hoặc JSX children
46
109
  let rootNode = null;
47
110
  let rawTarget = null;
111
+ const currentPageKey = pageConfigObj && pageConfigObj.pages
112
+ ? pageConfigObj.pages[activePage]
113
+ ? activePage
114
+ : defaultPage
115
+ : '';
48
116
  if (children) {
49
117
  rawTarget = children;
50
118
  }
51
119
  else if (layout) {
52
- if (React.isValidElement(layout) || layout?.$$typeof) {
120
+ if (react_1.default.isValidElement(layout) || layout?.$$typeof) {
53
121
  rawTarget = layout;
54
122
  }
55
123
  else if (layout.type && typeof layout.type === 'string' && layout.props !== undefined) {
56
124
  rawTarget = layout;
57
125
  }
58
126
  else {
59
- const pageConfig = layout;
60
- rawTarget =
61
- pageConfig[activeSize] ||
62
- pageConfig.medium ||
63
- pageConfig.large ||
64
- pageConfig.small ||
65
- pageConfig.accessoryRectangular ||
66
- null;
127
+ const pageConfig = pageConfigObj && currentPageKey
128
+ ? pageConfigObj.pages[currentPageKey] || {}
129
+ : layout;
130
+ const primary = pageConfig?.[activeSize];
131
+ if (primary) {
132
+ rawTarget = primary;
133
+ }
134
+ else if (activeSize === 'extraLarge') {
135
+ rawTarget = pageConfig?.large || pageConfig?.medium || pageConfig?.small || null;
136
+ }
137
+ else if (activeSize === 'standBy') {
138
+ rawTarget = pageConfig?.small || pageConfig?.medium || pageConfig?.large || null;
139
+ }
140
+ else {
141
+ rawTarget =
142
+ pageConfig?.medium ||
143
+ pageConfig?.large ||
144
+ pageConfig?.small ||
145
+ pageConfig?.accessoryRectangular ||
146
+ null;
147
+ }
67
148
  }
68
149
  }
150
+ const handlePreviewAction = (actionId) => {
151
+ if (actionId.startsWith('page:') && pageConfigObj && pageOrder.length > 0) {
152
+ const target = actionId.slice('page:'.length);
153
+ if (target === 'next') {
154
+ const idx = pageOrder.indexOf(currentPageKey);
155
+ const nextPage = idx >= 0 ? pageOrder[(idx + 1) % pageOrder.length] : pageOrder[0];
156
+ setActivePage(nextPage);
157
+ }
158
+ else if (target === 'prev') {
159
+ const idx = pageOrder.indexOf(currentPageKey);
160
+ const prevPage = idx >= 0 ? pageOrder[(idx - 1 + pageOrder.length) % pageOrder.length] : pageOrder[0];
161
+ setActivePage(prevPage);
162
+ }
163
+ else if (pageConfigObj.pages[target]) {
164
+ setActivePage(target);
165
+ }
166
+ }
167
+ else if (actionId === 'refresh' || actionId.startsWith('refresh:')) {
168
+ const nowTime = new Date().toLocaleTimeString('en-GB', { hour12: false });
169
+ const sampleNotes = [
170
+ 'Đồng bộ báo cáo tiến độ OKRs',
171
+ 'Kiểm tra chấm công ca hành chính',
172
+ 'Rà soát task Sprint tuần này',
173
+ 'Cập nhật số liệu Realtime API',
174
+ ];
175
+ const nextId = String(Math.floor(Math.random() * 90) + 10);
176
+ setSyncVars({
177
+ _lastSyncTime: nowTime,
178
+ id: nextId,
179
+ title: sampleNotes[Number(nextId) % sampleNotes.length],
180
+ });
181
+ }
182
+ if (onAction) {
183
+ onAction(actionId);
184
+ }
185
+ };
69
186
  if (rawTarget) {
70
- if (React.isValidElement(rawTarget) || rawTarget?.$$typeof || typeof rawTarget?.type === 'function') {
71
- rootNode = renderToWidget(rawTarget);
187
+ if (react_1.default.isValidElement(rawTarget) || rawTarget?.$$typeof || typeof rawTarget?.type === 'function') {
188
+ rootNode = (0, jsx_1.renderToWidget)(rawTarget);
72
189
  }
73
190
  else {
74
191
  rootNode = rawTarget;
75
192
  }
76
193
  }
77
194
  const dim = SIZE_DIMENSIONS[activeSize || 'medium'] || SIZE_DIMENSIONS.medium;
78
- return (React.createElement(View, { style: [styles.container, style] },
79
- interactiveSizeSwitch && (React.createElement(View, { style: styles.tabBar }, ['small', 'medium', 'large'].map((s) => (React.createElement(TouchableOpacity, { key: s, onPress: () => setActiveSize(s), style: [styles.tabItem, activeSize === s && styles.tabItemActive] },
80
- React.createElement(RNText, { style: [styles.tabText, activeSize === s && styles.tabTextActive] }, s.toUpperCase())))))),
81
- showBadge && (React.createElement(View, { style: styles.badgeRow },
82
- React.createElement(View, { style: styles.specBadge },
83
- React.createElement(RNText, { style: styles.specBadgeText }, dim.label)))),
84
- React.createElement(View, { style: [
195
+ const anyLayout = layout;
196
+ const effectiveControlConfig = controlConfig ||
197
+ anyLayout?.control ||
198
+ (activeSize === 'control' && anyLayout && !anyLayout.type && typeof anyLayout.title === 'string' && typeof anyLayout.actionId === 'string'
199
+ ? anyLayout
200
+ : null);
201
+ const switchSizes = ['small', 'medium', 'large'];
202
+ if (initialSize === 'extraLarge' ||
203
+ anyLayout?.extraLarge ||
204
+ (currentPageKey && pageConfigObj?.pages?.[currentPageKey]?.extraLarge)) {
205
+ switchSizes.push('extraLarge');
206
+ }
207
+ if (initialSize === 'standBy' ||
208
+ anyLayout?.standBy ||
209
+ (currentPageKey && pageConfigObj?.pages?.[currentPageKey]?.standBy)) {
210
+ switchSizes.push('standBy');
211
+ }
212
+ if (initialSize === 'control' || effectiveControlConfig) {
213
+ switchSizes.push('control');
214
+ }
215
+ const effectiveSyncVars = {
216
+ ...syncVars,
217
+ ...(data ? (0, builder_1.flattenDataObject)(data) : {}),
218
+ };
219
+ return (react_1.default.createElement(react_native_1.View, { style: [styles.container, style] },
220
+ interactiveSizeSwitch && (react_1.default.createElement(react_native_1.View, { style: styles.tabBar }, switchSizes.map((s) => (react_1.default.createElement(react_native_1.TouchableOpacity, { key: s, onPress: () => setActiveSize(s), style: [styles.tabItem, activeSize === s && styles.tabItemActive] },
221
+ react_1.default.createElement(react_native_1.Text, { style: [styles.tabText, activeSize === s && styles.tabTextActive] }, s === 'extraLarge' ? 'XLARGE' : s === 'control' ? 'CONTROL' : s.toUpperCase())))))),
222
+ showBadge && (react_1.default.createElement(react_native_1.View, { style: styles.badgeRow },
223
+ react_1.default.createElement(react_native_1.View, { style: styles.specBadge },
224
+ react_1.default.createElement(react_native_1.Text, { style: styles.specBadgeText }, dim.label)))),
225
+ react_1.default.createElement(react_native_1.View, { style: [
85
226
  styles.widgetFrame,
86
227
  {
87
228
  width: dim.width,
88
229
  height: dim.height,
89
230
  },
90
- ] }, rootNode ? (renderPreviewNode(rootNode, onAction, true, 'column')) : (React.createElement(View, { style: styles.emptyContainer },
91
- React.createElement(RNText, { style: styles.emptyText },
231
+ ] }, activeSize === 'control' ? (react_1.default.createElement(PreviewControlTile, { config: effectiveControlConfig || {
232
+ type: 'button',
233
+ title: 'Live Control',
234
+ subtitle: 'Nhấn để kích hoạt',
235
+ actionId: 'control_action_main',
236
+ }, onAction: handlePreviewAction })) : rootNode ? (renderPreviewNode(rootNode, handlePreviewAction, true, 'column', effectiveSyncVars)) : (react_1.default.createElement(react_native_1.View, { style: styles.emptyContainer },
237
+ react_1.default.createElement(react_native_1.Text, { style: styles.emptyText },
92
238
  "Ch\u01B0a c\u00F3 c\u1EA5u h\u00ECnh layout cho k\u00EDch th\u01B0\u1EDBc ",
93
239
  activeSize))))));
94
240
  };
241
+ exports.WidgetPreview = WidgetPreview;
95
242
  /** Alias tương thích */
96
- export const VoltraWidgetPreview = WidgetPreview;
243
+ exports.VoltraWidgetPreview = exports.WidgetPreview;
97
244
  // ─── RECURSIVE NODE RENDERER ─────────────────────────────────────────────────
98
- function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'column') {
245
+ function dispatchPreviewAction(actionId, onAction, extraPayload) {
246
+ if (!actionId)
247
+ return;
248
+ if (onAction) {
249
+ onAction(actionId);
250
+ }
251
+ const payload = { actionId, ...extraPayload };
252
+ const registered = dispatcher_1.actionHandlers.get(actionId);
253
+ if (registered) {
254
+ try {
255
+ registered(payload);
256
+ }
257
+ catch (e) {
258
+ console.warn(`[WidgetPreview] Action '${actionId}' error:`, e);
259
+ }
260
+ }
261
+ for (const globalHandler of dispatcher_1.globalActionHandlers) {
262
+ try {
263
+ globalHandler(actionId, extraPayload);
264
+ }
265
+ catch (e) {
266
+ console.warn(`[WidgetPreview] Global action handler error:`, e);
267
+ }
268
+ }
269
+ }
270
+ const PreviewControlTile = ({ config, onAction }) => {
271
+ const [isOn, setIsOn] = (0, react_1.useState)(Boolean(config.checked));
272
+ (0, react_1.useEffect)(() => {
273
+ setIsOn(Boolean(config.checked));
274
+ }, [config.checked]);
275
+ const isToggle = config.type === 'toggle' || Boolean(config.actionId?.startsWith('toggle:'));
276
+ const active = isToggle && isOn;
277
+ const tint = config.tintColor || '#2563EB';
278
+ const title = active ? config.checkedTitle || config.title : config.title;
279
+ const subtitle = active
280
+ ? config.checkedSubtitle ?? config.subtitle ?? 'Đang bật'
281
+ : config.subtitle ?? (isToggle ? 'Tạm tắt' : config.systemName || 'Control');
282
+ return (react_1.default.createElement(react_native_1.TouchableOpacity, { accessible: true, accessibilityRole: isToggle ? 'switch' : 'button', accessibilityLabel: title, accessibilityValue: isToggle ? { text: active ? 'Bật' : 'Tắt' } : undefined, activeOpacity: 0.75, onPress: () => {
283
+ const nextVal = isToggle ? !isOn : undefined;
284
+ if (isToggle) {
285
+ setIsOn(Boolean(nextVal));
286
+ }
287
+ dispatchPreviewAction(config.actionId, onAction, isToggle ? { isChecked: nextVal } : undefined);
288
+ }, style: {
289
+ width: '100%',
290
+ height: '100%',
291
+ flexDirection: 'row',
292
+ alignItems: 'center',
293
+ paddingHorizontal: 12,
294
+ gap: 10,
295
+ backgroundColor: active ? '#1E293B' : '#0F172A',
296
+ borderWidth: active ? 1.5 : 1,
297
+ borderColor: active ? tint : 'rgba(148, 163, 184, 0.2)',
298
+ borderRadius: 20,
299
+ } },
300
+ react_1.default.createElement(react_native_1.View, { style: {
301
+ width: 34,
302
+ height: 34,
303
+ borderRadius: 17,
304
+ backgroundColor: active ? tint : 'rgba(255, 255, 255, 0.1)',
305
+ alignItems: 'center',
306
+ justifyContent: 'center',
307
+ } },
308
+ react_1.default.createElement(react_native_1.Text, { style: { color: '#FFFFFF', fontSize: 14, fontWeight: 'bold' } }, active ? '✓' : '⚡')),
309
+ react_1.default.createElement(react_native_1.View, { style: { flex: 1 } },
310
+ react_1.default.createElement(react_native_1.Text, { numberOfLines: 1, style: { color: '#F8FAFC', fontSize: 12, fontWeight: '700' } }, title),
311
+ react_1.default.createElement(react_native_1.Text, { numberOfLines: 1, style: { color: active ? '#93C5FD' : '#94A3B8', fontSize: 10, marginTop: 1 } }, subtitle))));
312
+ };
313
+ const PreviewToggleItem = ({ node, onAction }) => {
314
+ const p = node.props || {};
315
+ const [isChecked, setIsChecked] = (0, react_1.useState)(!!p.checked || !!p.isChecked);
316
+ const tint = parseDynamicColor(p.tintColor) || '#38BDF8';
317
+ const isSwitch = p.style === 'switch';
318
+ const handlePress = () => {
319
+ const nextVal = !isChecked;
320
+ setIsChecked(nextVal);
321
+ dispatchPreviewAction(p.actionId, onAction, { isChecked: nextVal });
322
+ };
323
+ return (react_1.default.createElement(react_native_1.TouchableOpacity, { accessible: p.accessible !== false, accessibilityLabel: p.accessibilityLabel || p.label, accessibilityHint: p.accessibilityHint, accessibilityRole: "switch", accessibilityValue: { text: isChecked ? 'Đã chọn' : 'Chưa chọn' }, activeOpacity: 0.7, onPress: handlePress, style: {
324
+ flexDirection: 'row',
325
+ alignItems: 'center',
326
+ gap: 8,
327
+ paddingVertical: 6,
328
+ paddingHorizontal: 2,
329
+ width: '100%',
330
+ alignSelf: 'stretch',
331
+ } },
332
+ isSwitch ? (react_1.default.createElement(react_native_1.View, { style: {
333
+ width: 34,
334
+ height: 20,
335
+ borderRadius: 10,
336
+ backgroundColor: isChecked ? tint : '#475569',
337
+ justifyContent: 'center',
338
+ paddingHorizontal: 3,
339
+ } },
340
+ react_1.default.createElement(react_native_1.View, { style: {
341
+ width: 14,
342
+ height: 14,
343
+ borderRadius: 7,
344
+ backgroundColor: '#FFFFFF',
345
+ alignSelf: isChecked ? 'flex-end' : 'flex-start',
346
+ } }))) : (react_1.default.createElement(react_native_1.View, { style: {
347
+ width: 18,
348
+ height: 18,
349
+ borderRadius: 4,
350
+ borderWidth: 1.5,
351
+ borderColor: isChecked ? tint : '#64748B',
352
+ backgroundColor: isChecked ? tint : 'transparent',
353
+ alignItems: 'center',
354
+ justifyContent: 'center',
355
+ } }, isChecked && (react_1.default.createElement(react_native_1.Text, { style: { color: '#FFFFFF', fontSize: 11, fontWeight: 'bold' } }, "\u2713")))),
356
+ react_1.default.createElement(react_native_1.Text, { style: {
357
+ flex: 1,
358
+ color: isChecked && p.strikethroughOnCheck
359
+ ? '#64748B'
360
+ : parseDynamicColor(p.textColor) || '#F8FAFC',
361
+ fontSize: p.fontSize ?? 13,
362
+ textDecorationLine: isChecked && p.strikethroughOnCheck ? 'line-through' : 'none',
363
+ } }, p.label)));
364
+ };
365
+ const PreviewTimerText = ({ nodeProps: p, parentDirection }) => {
366
+ const formatRemaining = () => {
367
+ const target = Number(p.targetTimestamp ?? 0);
368
+ if (!target)
369
+ return '00:00';
370
+ const diff = Math.max(0, Math.round(Math.abs(target - Date.now() / 1000)));
371
+ const hrs = Math.floor(diff / 3600);
372
+ const mins = Math.floor((diff % 3600) / 60);
373
+ const secs = diff % 60;
374
+ const pad = (n) => (n < 10 ? `0${n}` : `${n}`);
375
+ return hrs > 0 ? `${hrs}:${pad(mins)}:${pad(secs)}` : `${pad(mins)}:${pad(secs)}`;
376
+ };
377
+ const [display, setDisplay] = (0, react_1.useState)(formatRemaining);
378
+ (0, react_1.useEffect)(() => {
379
+ setDisplay(formatRemaining());
380
+ const id = setInterval(() => {
381
+ setDisplay(formatRemaining());
382
+ }, 1000);
383
+ return () => clearInterval(id);
384
+ }, [p.targetTimestamp, p.mode]);
385
+ return (react_1.default.createElement(react_native_1.Text, { style: [
386
+ { color: parseDynamicColor(p.color) || '#2563EB', fontSize: p.fontSize ?? 14, fontWeight: 'bold' },
387
+ parentDirection === 'row' ? { flexShrink: 0 } : undefined,
388
+ ] },
389
+ p.prefix || '',
390
+ display,
391
+ p.suffix || ''));
392
+ };
393
+ function resolvePreviewText(raw, syncVars) {
394
+ const str = String(raw ?? '');
395
+ return syncVars ? (0, builder_1.resolveTemplateString)(str, syncVars) : str;
396
+ }
397
+ function resolvePreviewNumber(raw, fallback, syncVars) {
398
+ if (typeof raw === 'number' && !Number.isNaN(raw))
399
+ return raw;
400
+ if (typeof raw === 'string') {
401
+ const resolved = syncVars ? (0, builder_1.resolveTemplateString)(raw, syncVars) : raw;
402
+ const num = parseFloat(resolved);
403
+ return Number.isNaN(num) ? fallback : num;
404
+ }
405
+ return fallback;
406
+ }
407
+ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'column', syncVars) {
99
408
  if (!node)
100
409
  return null;
101
- if (React.isValidElement(node) || node?.$$typeof || typeof node?.type === 'function') {
102
- const converted = renderToWidget(node);
410
+ if (react_1.default.isValidElement(node) || node?.$$typeof || typeof node?.type === 'function') {
411
+ const converted = (0, jsx_1.renderToWidget)(node);
103
412
  if (!converted)
104
413
  return null;
105
- return renderPreviewNode(converted, onAction, isRoot, parentDirection);
414
+ return renderPreviewNode(converted, onAction, isRoot, parentDirection, syncVars);
106
415
  }
107
416
  switch (node.type) {
108
417
  case 'VStack': {
109
418
  const vnode = node;
110
- const p = extractPropsAndStyle(vnode.props);
419
+ const p = (0, jsx_1.extractPropsAndStyle)(vnode.props);
420
+ const bg = p.gradient?.colors?.[0]
421
+ ? parseDynamicColor(p.gradient.colors[0])
422
+ : parseDynamicColor(p.backgroundColor) || 'transparent';
111
423
  const containerStyle = {
112
424
  flexDirection: 'column',
113
425
  padding: p.padding ?? (p.paddingHorizontal || p.paddingVertical ? undefined : 0),
114
426
  paddingHorizontal: p.paddingHorizontal,
115
427
  paddingVertical: p.paddingVertical,
116
- backgroundColor: parseDynamicColor(p.backgroundColor) || 'transparent',
428
+ backgroundColor: bg,
117
429
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 0,
118
430
  borderWidth: p.borderWidth,
119
431
  borderColor: parseDynamicColor(p.borderColor),
432
+ borderStyle: p.borderStyle || 'solid',
120
433
  rowGap: p.spacing ?? 0,
121
434
  alignItems: p.alignment === 'center'
122
435
  ? 'center'
123
- : p.alignment === 'trailing'
436
+ : p.alignment === 'trailing' || p.alignment === 'end'
124
437
  ? 'flex-end'
125
438
  : 'flex-start',
126
439
  justifyContent: p.justifyContent === 'center'
@@ -129,9 +442,12 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
129
442
  ? 'space-between'
130
443
  : p.justifyContent === 'spaceAround'
131
444
  ? 'space-around'
132
- : p.justifyContent === 'flexEnd'
133
- ? 'flex-end'
134
- : 'flex-start',
445
+ : p.justifyContent === 'spaceEvenly'
446
+ ? 'space-evenly'
447
+ : p.justifyContent === 'flexEnd'
448
+ ? 'flex-end'
449
+ : 'flex-start',
450
+ ...extractShadowStyle(p),
135
451
  };
136
452
  if (isRoot) {
137
453
  containerStyle.width = '100%';
@@ -146,24 +462,29 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
146
462
  else {
147
463
  containerStyle.alignSelf = 'stretch';
148
464
  }
149
- return (React.createElement(View, { style: containerStyle }, vnode.children?.map((child, idx) => (React.createElement(React.Fragment, { key: idx }, renderPreviewNode(child, onAction, false, 'column'))))));
465
+ return (react_1.default.createElement(react_native_1.View, { style: containerStyle }, vnode.children?.map((child, idx) => (react_1.default.createElement(react_1.default.Fragment, { key: idx }, renderPreviewNode(child, onAction, false, 'column', syncVars))))));
150
466
  }
151
467
  case 'HStack': {
152
468
  const hnode = node;
153
- const p = extractPropsAndStyle(hnode.props);
469
+ const p = (0, jsx_1.extractPropsAndStyle)(hnode.props);
470
+ const isRtl = p.direction === 'rtl' || p.isRTL;
471
+ const bg = p.gradient?.colors?.[0]
472
+ ? parseDynamicColor(p.gradient.colors[0])
473
+ : parseDynamicColor(p.backgroundColor) || 'transparent';
154
474
  const containerStyle = {
155
- flexDirection: 'row',
475
+ flexDirection: isRtl ? 'row-reverse' : 'row',
156
476
  padding: p.padding,
157
477
  paddingHorizontal: p.paddingHorizontal,
158
478
  paddingVertical: p.paddingVertical,
159
- backgroundColor: parseDynamicColor(p.backgroundColor) || 'transparent',
479
+ backgroundColor: bg,
160
480
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 0,
161
481
  borderWidth: p.borderWidth,
162
482
  borderColor: parseDynamicColor(p.borderColor),
483
+ borderStyle: p.borderStyle || 'solid',
163
484
  columnGap: p.spacing ?? 0,
164
485
  alignItems: p.alignment === 'center'
165
486
  ? 'center'
166
- : p.alignment === 'trailing'
487
+ : p.alignment === 'trailing' || p.alignment === 'bottom'
167
488
  ? 'flex-end'
168
489
  : p.alignment === 'top'
169
490
  ? 'flex-start'
@@ -174,9 +495,12 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
174
495
  ? 'space-between'
175
496
  : p.justifyContent === 'spaceAround'
176
497
  ? 'space-around'
177
- : p.justifyContent === 'flexEnd'
178
- ? 'flex-end'
179
- : 'flex-start',
498
+ : p.justifyContent === 'spaceEvenly'
499
+ ? 'space-evenly'
500
+ : p.justifyContent === 'flexEnd'
501
+ ? 'flex-end'
502
+ : 'flex-start',
503
+ ...extractShadowStyle(p),
180
504
  };
181
505
  if (isRoot) {
182
506
  containerStyle.width = '100%';
@@ -188,12 +512,12 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
188
512
  else if (p.flex !== undefined) {
189
513
  containerStyle.flex = p.flex;
190
514
  }
191
- return (React.createElement(View, { style: containerStyle }, hnode.children?.map((child, idx) => (React.createElement(React.Fragment, { key: idx }, renderPreviewNode(child, onAction, false, 'row'))))));
515
+ return (react_1.default.createElement(react_native_1.View, { style: containerStyle }, hnode.children?.map((child, idx) => (react_1.default.createElement(react_1.default.Fragment, { key: idx }, renderPreviewNode(child, onAction, false, 'row', syncVars))))));
192
516
  }
193
517
  case 'ZStack': {
194
518
  const znode = node;
195
- const p = extractPropsAndStyle(znode.props);
196
- return (React.createElement(View, { style: {
519
+ const p = (0, jsx_1.extractPropsAndStyle)(znode.props);
520
+ return (react_1.default.createElement(react_native_1.View, { style: {
197
521
  position: 'relative',
198
522
  width: isRoot ? '100%' : undefined,
199
523
  height: isRoot ? '100%' : undefined,
@@ -202,25 +526,29 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
202
526
  justifyContent: 'center',
203
527
  backgroundColor: parseDynamicColor(p.backgroundColor) || 'transparent',
204
528
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 0,
205
- } }, znode.children?.map((child, idx) => (React.createElement(View, { key: idx, style: idx === 0
529
+ } }, znode.children?.map((child, idx) => (react_1.default.createElement(react_native_1.View, { key: idx, style: idx === 0
206
530
  ? { width: '100%', height: '100%' }
207
- : { ...StyleSheet.absoluteFillObject, alignItems: 'center', justifyContent: 'center' } }, renderPreviewNode(child, onAction, false, parentDirection))))));
531
+ : { ...react_native_1.StyleSheet.absoluteFillObject, alignItems: 'center', justifyContent: 'center' } }, renderPreviewNode(child, onAction, false, parentDirection, syncVars))))));
208
532
  }
209
533
  case 'Grid': {
210
534
  const gnode = node;
211
- const p = extractPropsAndStyle(gnode.props);
535
+ const p = (0, jsx_1.extractPropsAndStyle)(gnode.props);
212
536
  const cols = p.columns ?? 2;
213
- return (React.createElement(View, { style: {
537
+ return (react_1.default.createElement(react_native_1.View, { style: {
214
538
  flexDirection: 'row',
215
539
  flexWrap: 'wrap',
216
540
  gap: p.spacing ?? 6,
217
541
  width: '100%',
218
542
  alignSelf: 'stretch',
219
- } }, gnode.children?.map((child, idx) => (React.createElement(View, { key: idx, style: { flexBasis: `${Math.floor(100 / cols) - 3}%` } }, renderPreviewNode(child, onAction, false, 'column'))))));
543
+ } }, gnode.children?.map((child, idx) => (react_1.default.createElement(react_native_1.View, { key: idx, style: { flexBasis: `${Math.floor(100 / cols) - 3}%` } }, renderPreviewNode(child, onAction, false, 'column', syncVars))))));
220
544
  }
221
545
  case 'Text': {
222
546
  const tnode = node;
223
- const p = extractPropsAndStyle(tnode.props);
547
+ const p = (0, jsx_1.extractPropsAndStyle)(tnode.props);
548
+ const isRtl = p.direction === 'rtl' || p.isRTL;
549
+ const shadowColor = parseDynamicColor(p.shadowColor);
550
+ const resolvedText = resolvePreviewText(p.text, syncVars);
551
+ const isRedacted = Boolean(p.redacted);
224
552
  const textStyle = {
225
553
  color: parseDynamicColor(p.color) || '#FFFFFF',
226
554
  fontSize: p.fontSize ?? 14,
@@ -231,42 +559,56 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
231
559
  : p.fontWeight === 'medium'
232
560
  ? '500'
233
561
  : 'normal',
234
- textAlign: p.textAlign ?? 'left',
562
+ fontFamily: p.fontDesign === 'monospaced' ? 'monospace' : undefined,
563
+ textAlign: p.textAlign ?? (isRtl ? 'right' : 'left'),
564
+ lineHeight: p.lineHeight,
565
+ letterSpacing: p.letterSpacing,
566
+ opacity: isRedacted ? 0.45 : undefined,
567
+ textShadowColor: shadowColor,
568
+ textShadowOffset: p.shadowOffset
569
+ ? { width: p.shadowOffset.x ?? 0, height: p.shadowOffset.y ?? 1 }
570
+ : undefined,
571
+ textShadowRadius: p.shadowRadius,
235
572
  };
236
- return (React.createElement(RNText, { numberOfLines: p.numberOfLines, style: [
573
+ return (react_1.default.createElement(react_native_1.Text, { accessible: p.accessible !== false, accessibilityLabel: p.accessibilityLabel || resolvedText, accessibilityHint: p.accessibilityHint, accessibilityRole: p.accessibilityRole, numberOfLines: p.numberOfLines, style: [
237
574
  textStyle,
238
575
  parentDirection === 'row' ? { flexShrink: 1 } : undefined,
239
- ] }, p.text));
576
+ ] }, isRedacted ? '••••••••' : resolvedText));
240
577
  }
241
578
  case 'Button': {
242
579
  const bnode = node;
243
580
  const p = bnode.props;
581
+ const bg = p.gradient?.colors?.[0]
582
+ ? parseDynamicColor(p.gradient.colors[0])
583
+ : parseDynamicColor(p.backgroundColor) || '#2563EB';
244
584
  const btnStyle = {
245
- backgroundColor: parseDynamicColor(p.backgroundColor) || '#2563EB',
585
+ backgroundColor: bg,
246
586
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 8,
587
+ borderWidth: p.borderWidth,
588
+ borderColor: parseDynamicColor(p.borderColor),
589
+ borderStyle: p.borderStyle || 'solid',
247
590
  paddingHorizontal: p.paddingHorizontal ?? p.padding ?? 12,
248
591
  paddingVertical: p.paddingVertical ?? p.padding ?? 6,
249
592
  alignItems: 'center',
250
593
  justifyContent: 'center',
251
594
  alignSelf: p.fullWidth ? 'stretch' : 'auto',
252
- width: p.fullWidth ? '100%' : undefined,
595
+ ...(p.fullWidth ? (parentDirection === 'row' ? { flex: 1 } : { width: '100%' }) : {}),
596
+ ...extractShadowStyle(p),
253
597
  };
254
598
  const textStyle = {
255
599
  color: parseDynamicColor(p.textColor) || '#FFFFFF',
256
600
  fontSize: p.fontSize ?? 12,
257
601
  fontWeight: p.fontWeight ?? '600',
602
+ fontFamily: p.fontDesign === 'monospaced' ? 'monospace' : undefined,
258
603
  };
259
- return (React.createElement(TouchableOpacity, { activeOpacity: 0.7, onPress: () => {
260
- if (p.actionId && onAction) {
261
- onAction(p.actionId);
262
- }
263
- }, style: btnStyle },
264
- React.createElement(RNText, { numberOfLines: 1, style: textStyle }, p.title)));
604
+ const btnTitle = resolvePreviewText(p.title, syncVars);
605
+ return (react_1.default.createElement(react_native_1.TouchableOpacity, { accessible: p.accessible !== false, accessibilityLabel: p.accessibilityLabel || btnTitle, accessibilityHint: p.accessibilityHint, accessibilityRole: "button", activeOpacity: 0.7, onPress: () => dispatchPreviewAction(p.actionId, onAction), style: btnStyle },
606
+ react_1.default.createElement(react_native_1.Text, { numberOfLines: 1, style: textStyle }, btnTitle)));
265
607
  }
266
608
  case 'Badge': {
267
609
  const bnode = node;
268
610
  const p = bnode.props;
269
- return (React.createElement(View, { style: {
611
+ return (react_1.default.createElement(react_native_1.View, { style: {
270
612
  backgroundColor: parseDynamicColor(p.backgroundColor) || '#064E3B',
271
613
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 6,
272
614
  paddingHorizontal: p.paddingHorizontal ?? 6,
@@ -274,31 +616,31 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
274
616
  flexShrink: 0,
275
617
  alignSelf: 'center',
276
618
  } },
277
- React.createElement(RNText, { numberOfLines: 1, style: {
619
+ react_1.default.createElement(react_native_1.Text, { numberOfLines: 1, style: {
278
620
  color: parseDynamicColor(p.textColor) || '#6EE7B7',
279
621
  fontSize: p.fontSize ?? 10,
280
622
  fontWeight: '600',
281
- } }, p.text)));
623
+ } }, resolvePreviewText(p.text, syncVars))));
282
624
  }
283
625
  case 'Progress': {
284
626
  const pnode = node;
285
627
  const p = pnode.props || {};
286
- const val = Math.max(0, Math.min(1, p.value ?? 0.5));
628
+ const val = Math.max(0, Math.min(1, resolvePreviewNumber(p.value, 0.5, syncVars)));
287
629
  const height = p.height ?? 6;
288
630
  const tint = parseDynamicColor(p.tintColor) || '#2563EB';
289
631
  const track = parseDynamicColor(p.trackColor) || '#334155';
290
632
  if (p.style === 'segmented' && (p.segments ?? 4) > 1) {
291
633
  const segs = p.segments ?? 4;
292
634
  const filled = Math.round(val * segs);
293
- return (React.createElement(View, { style: { flexDirection: 'row', gap: 4, width: '100%', height, alignSelf: 'stretch' } }, Array.from({ length: segs }).map((_, idx) => (React.createElement(View, { key: idx, style: {
635
+ return (react_1.default.createElement(react_native_1.View, { style: { flexDirection: 'row', gap: 4, width: '100%', height, alignSelf: 'stretch' } }, Array.from({ length: segs }).map((_, idx) => (react_1.default.createElement(react_native_1.View, { key: idx, style: {
294
636
  flex: 1,
295
637
  height,
296
638
  backgroundColor: idx < filled ? tint : track,
297
639
  borderRadius: height / 2,
298
640
  } })))));
299
641
  }
300
- return (React.createElement(View, { style: { width: '100%', height, backgroundColor: track, borderRadius: height / 2, alignSelf: 'stretch' } },
301
- React.createElement(View, { style: {
642
+ return (react_1.default.createElement(react_native_1.View, { style: { width: '100%', height, backgroundColor: track, borderRadius: height / 2, alignSelf: 'stretch' } },
643
+ react_1.default.createElement(react_native_1.View, { style: {
302
644
  width: `${val * 100}%`,
303
645
  height,
304
646
  backgroundColor: tint,
@@ -308,13 +650,7 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
308
650
  case 'Timer': {
309
651
  const tnode = node;
310
652
  const p = tnode.props || {};
311
- return (React.createElement(RNText, { style: [
312
- { color: parseDynamicColor(p.color) || '#2563EB', fontSize: p.fontSize ?? 14, fontWeight: 'bold' },
313
- parentDirection === 'row' ? { flexShrink: 0 } : undefined,
314
- ] },
315
- p.prefix || '',
316
- "1:29:55",
317
- p.suffix || ''));
653
+ return react_1.default.createElement(PreviewTimerText, { nodeProps: p, parentDirection: parentDirection });
318
654
  }
319
655
  case 'Image': {
320
656
  const inode = node;
@@ -323,13 +659,13 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
323
659
  const height = p.height ?? 32;
324
660
  const uri = p.url || (p.base64 ? `data:image/png;base64,${p.base64}` : null);
325
661
  if (uri) {
326
- return (React.createElement(RNImage, { source: { uri }, style: {
662
+ return (react_1.default.createElement(react_native_1.Image, { source: { uri }, style: {
327
663
  width,
328
664
  height,
329
665
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 0,
330
666
  } }));
331
667
  }
332
- return (React.createElement(View, { style: {
668
+ return (react_1.default.createElement(react_native_1.View, { style: {
333
669
  width,
334
670
  height,
335
671
  backgroundColor: '#334155',
@@ -337,46 +673,44 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
337
673
  alignItems: 'center',
338
674
  justifyContent: 'center',
339
675
  } },
340
- React.createElement(RNText, { style: { color: '#94A3B8', fontSize: 10 } }, "IMG")));
676
+ react_1.default.createElement(react_native_1.Text, { style: { color: '#94A3B8', fontSize: 10 } }, "IMG")));
341
677
  }
342
678
  case 'Spacer': {
343
679
  const snode = node;
344
680
  const p = snode.props || {};
345
681
  const minLen = p?.minLength ?? 4;
346
- return (React.createElement(View, { style: parentDirection === 'row'
682
+ return (react_1.default.createElement(react_native_1.View, { style: parentDirection === 'row'
347
683
  ? { minWidth: minLen, flex: 1 }
348
684
  : { minHeight: minLen, flex: 1 } }));
349
685
  }
350
686
  case 'Divider': {
351
687
  const p = node.props || {};
352
688
  const color = parseDynamicColor(p.color) || '#334155';
353
- return (React.createElement(View, { style: parentDirection === 'row'
689
+ return (react_1.default.createElement(react_native_1.View, { style: parentDirection === 'row'
354
690
  ? { width: 1, height: '100%', backgroundColor: color }
355
691
  : { width: '100%', height: 1, backgroundColor: color, alignSelf: 'stretch' } }));
356
692
  }
357
693
  case 'Link': {
358
694
  const lnode = node;
359
695
  const p = lnode.props || {};
360
- return (React.createElement(TouchableOpacity, { activeOpacity: 0.7, onPress: () => {
696
+ return (react_1.default.createElement(react_native_1.TouchableOpacity, { activeOpacity: 0.7, onPress: () => {
361
697
  if (p.url && onAction)
362
698
  onAction(p.url);
363
- }, style: { flexDirection: 'row', alignItems: 'center' } }, lnode.children?.map((child, idx) => (React.createElement(React.Fragment, { key: idx }, renderPreviewNode(child, onAction, false, parentDirection))))));
699
+ }, style: { flexDirection: 'row', alignItems: 'center' } }, lnode.children?.map((child, idx) => (react_1.default.createElement(react_1.default.Fragment, { key: idx }, renderPreviewNode(child, onAction, false, parentDirection, syncVars))))));
364
700
  }
365
701
  case 'Equalizer': {
366
702
  const enode = node;
367
703
  const p = enode.props || {};
368
704
  const tint = parseDynamicColor(p.color) || '#38BDF8';
369
- return (React.createElement(View, { style: { flexDirection: 'row', gap: 3, alignItems: 'flex-end', height: 16 } }, [12, 16, 8, 14].map((h, i) => (React.createElement(View, { key: i, style: { width: 3, height: h, backgroundColor: tint, borderRadius: 1.5 } })))));
705
+ return (react_1.default.createElement(react_native_1.View, { style: { flexDirection: 'row', gap: 3, alignItems: 'flex-end', height: 16 } }, [12, 16, 8, 14].map((h, i) => (react_1.default.createElement(react_native_1.View, { key: i, style: { width: 3, height: h, backgroundColor: tint, borderRadius: 1.5 } })))));
370
706
  }
371
707
  case 'Gauge': {
372
708
  const gnode = node;
373
709
  const p = gnode.props || {};
374
- const val = Math.round((p.value ?? 0.75) * 100);
710
+ const val = Math.round(resolvePreviewNumber(p.value, 0.75, syncVars) * 100);
375
711
  const tint = parseDynamicColor(p.tintColor) || '#10B981';
376
- return (React.createElement(View, { style: { alignItems: 'center', justifyContent: 'center' } },
377
- React.createElement(RNText, { style: { color: tint, fontSize: 13, fontWeight: 'bold' } },
378
- val,
379
- "%")));
712
+ return (react_1.default.createElement(react_native_1.View, { style: { alignItems: 'center', justifyContent: 'center' } },
713
+ react_1.default.createElement(react_native_1.Text, { style: { color: tint, fontSize: 13, fontWeight: 'bold' } }, p.valueText ? resolvePreviewText(p.valueText, syncVars) : `${val}%`)));
380
714
  }
381
715
  case 'Chart': {
382
716
  const cnode = node;
@@ -384,18 +718,21 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
384
718
  const values = Array.isArray(p.values) ? p.values : [20, 45, 60, 80, 50];
385
719
  const maxVal = Math.max(...values, 1);
386
720
  const tint = parseDynamicColor(p.color) || '#38BDF8';
387
- return (React.createElement(View, { style: { flexDirection: 'row', gap: 4, alignItems: 'flex-end', height: 28, width: '100%', alignSelf: 'stretch' } }, values.map((v, i) => (React.createElement(View, { key: i, style: {
721
+ return (react_1.default.createElement(react_native_1.View, { style: { flexDirection: 'row', gap: 4, alignItems: 'flex-end', height: 28, width: '100%', alignSelf: 'stretch' } }, values.map((v, i) => (react_1.default.createElement(react_native_1.View, { key: i, style: {
388
722
  flex: 1,
389
723
  height: `${Math.max(15, (v / maxVal) * 100)}%`,
390
724
  backgroundColor: tint,
391
725
  borderRadius: 2,
392
726
  } })))));
393
727
  }
728
+ case 'Toggle': {
729
+ return (react_1.default.createElement(PreviewToggleItem, { key: `toggle-${node.id || node.props?.actionId || Math.random()}`, node: node, onAction: onAction }));
730
+ }
394
731
  default:
395
732
  return null;
396
733
  }
397
734
  }
398
- const styles = StyleSheet.create({
735
+ const styles = react_native_1.StyleSheet.create({
399
736
  container: {
400
737
  alignItems: 'center',
401
738
  marginVertical: 12,