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