react-native-live-widgets 1.2.0 → 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 (50) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +40 -1
  3. package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +443 -46
  4. package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +86 -28
  5. package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +126 -56
  6. package/android/src/main/res/layout/rn_live_widget_hit_zone.xml +16 -0
  7. package/android/src/main/res/layout/rn_live_widget_host.xml +16 -87
  8. package/docs/GUIDE-EN.md +241 -0
  9. package/docs/GUIDE-VI.md +266 -0
  10. package/docs/index.html +1140 -259
  11. package/docs/llms-full.txt +26 -0
  12. package/docs/llms.txt +8 -0
  13. package/ios/Models/DynamicLayoutModels.swift +6 -1
  14. package/ios/Renderer/DynamicNodeView.swift +169 -14
  15. package/ios/Widgets/DynamicHomeScreenWidget.swift +5 -0
  16. package/lib/builder.d.ts.map +1 -1
  17. package/lib/builder.js +65 -11
  18. package/lib/builder.js.map +1 -1
  19. package/lib/dispatcher.js +16 -10
  20. package/lib/dispatcher.js.map +1 -1
  21. package/lib/hooks.js +36 -31
  22. package/lib/hooks.js.map +1 -1
  23. package/lib/index.d.ts +17 -2
  24. package/lib/index.d.ts.map +1 -1
  25. package/lib/index.js +124 -50
  26. package/lib/index.js.map +1 -1
  27. package/lib/ir.d.ts +15 -0
  28. package/lib/ir.d.ts.map +1 -0
  29. package/lib/ir.js +379 -0
  30. package/lib/ir.js.map +1 -0
  31. package/lib/jsx.d.ts +9 -1
  32. package/lib/jsx.d.ts.map +1 -1
  33. package/lib/jsx.js +131 -84
  34. package/lib/jsx.js.map +1 -1
  35. package/lib/preview.d.ts +0 -23
  36. package/lib/preview.d.ts.map +1 -1
  37. package/lib/preview.js +373 -104
  38. package/lib/preview.js.map +1 -1
  39. package/lib/types.d.ts +204 -12
  40. package/lib/types.d.ts.map +1 -1
  41. package/lib/types.js +2 -1
  42. package/lib/types.js.map +1 -1
  43. package/package.json +2 -1
  44. package/src/builder.ts +57 -2
  45. package/src/index.ts +66 -1
  46. package/src/ir.ts +430 -0
  47. package/src/jsx.tsx +30 -0
  48. package/src/preview.tsx +356 -32
  49. package/src/react-native-env.d.ts +1 -0
  50. package/src/types.ts +253 -13
package/lib/preview.js CHANGED
@@ -1,6 +1,43 @@
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");
4
41
  const SIZE_DIMENSIONS = {
5
42
  small: { width: 158, height: 158, label: 'Small • 158×158' },
6
43
  medium: { width: 338, height: 158, label: 'Medium • 338×158' },
@@ -8,53 +45,89 @@ const SIZE_DIMENSIONS = {
8
45
  lockScreen: { width: 350, height: 80, label: 'Lock Screen • 350×80' },
9
46
  dynamicIsland: { width: 350, height: 160, label: 'Dynamic Island' },
10
47
  };
11
- function parseDynamicColor(c) {
48
+ function parseDynamicColor(c, mode = 'dark') {
12
49
  if (!c)
13
50
  return undefined;
14
51
  if (typeof c === 'string')
15
52
  return c;
16
- if (typeof c === 'object')
17
- return c.dark || c.light;
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
+ }
18
60
  return undefined;
19
61
  }
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);
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]);
45
103
  // Trích xuất LayoutNode từ props hoặc JSX children
46
104
  let rootNode = null;
47
105
  let rawTarget = null;
106
+ const currentPageKey = pageConfigObj && pageConfigObj.pages
107
+ ? pageConfigObj.pages[activePage]
108
+ ? activePage
109
+ : defaultPage
110
+ : '';
48
111
  if (children) {
49
112
  rawTarget = children;
50
113
  }
51
114
  else if (layout) {
52
- if (React.isValidElement(layout) || layout?.$$typeof) {
115
+ if (react_1.default.isValidElement(layout) || layout?.$$typeof) {
53
116
  rawTarget = layout;
54
117
  }
55
118
  else if (layout.type && typeof layout.type === 'string' && layout.props !== undefined) {
56
119
  rawTarget = layout;
57
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
+ }
58
131
  else {
59
132
  const pageConfig = layout;
60
133
  rawTarget =
@@ -66,61 +139,203 @@ export const WidgetPreview = ({ size: initialSize = 'medium', layout, children,
66
139
  null;
67
140
  }
68
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
+ };
69
178
  if (rawTarget) {
70
- if (React.isValidElement(rawTarget) || rawTarget?.$$typeof || typeof rawTarget?.type === 'function') {
71
- rootNode = renderToWidget(rawTarget);
179
+ if (react_1.default.isValidElement(rawTarget) || rawTarget?.$$typeof || typeof rawTarget?.type === 'function') {
180
+ rootNode = (0, jsx_1.renderToWidget)(rawTarget);
72
181
  }
73
182
  else {
74
183
  rootNode = rawTarget;
75
184
  }
76
185
  }
77
186
  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: [
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: [
85
194
  styles.widgetFrame,
86
195
  {
87
196
  width: dim.width,
88
197
  height: dim.height,
89
198
  },
90
- ] }, rootNode ? (renderPreviewNode(rootNode, onAction, true, 'column')) : (React.createElement(View, { style: styles.emptyContainer },
91
- React.createElement(RNText, { style: styles.emptyText },
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 },
92
201
  "Ch\u01B0a c\u00F3 c\u1EA5u h\u00ECnh layout cho k\u00EDch th\u01B0\u1EDBc ",
93
202
  activeSize))))));
94
203
  };
204
+ exports.WidgetPreview = WidgetPreview;
95
205
  /** Alias tương thích */
96
- export const VoltraWidgetPreview = WidgetPreview;
206
+ exports.VoltraWidgetPreview = exports.WidgetPreview;
97
207
  // ─── RECURSIVE NODE RENDERER ─────────────────────────────────────────────────
98
- function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'column') {
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) {
99
310
  if (!node)
100
311
  return null;
101
- if (React.isValidElement(node) || node?.$$typeof || typeof node?.type === 'function') {
102
- const converted = renderToWidget(node);
312
+ if (react_1.default.isValidElement(node) || node?.$$typeof || typeof node?.type === 'function') {
313
+ const converted = (0, jsx_1.renderToWidget)(node);
103
314
  if (!converted)
104
315
  return null;
105
- return renderPreviewNode(converted, onAction, isRoot, parentDirection);
316
+ return renderPreviewNode(converted, onAction, isRoot, parentDirection, syncVars);
106
317
  }
107
318
  switch (node.type) {
108
319
  case 'VStack': {
109
320
  const vnode = node;
110
- const p = extractPropsAndStyle(vnode.props);
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';
111
325
  const containerStyle = {
112
326
  flexDirection: 'column',
113
327
  padding: p.padding ?? (p.paddingHorizontal || p.paddingVertical ? undefined : 0),
114
328
  paddingHorizontal: p.paddingHorizontal,
115
329
  paddingVertical: p.paddingVertical,
116
- backgroundColor: parseDynamicColor(p.backgroundColor) || 'transparent',
330
+ backgroundColor: bg,
117
331
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 0,
118
332
  borderWidth: p.borderWidth,
119
333
  borderColor: parseDynamicColor(p.borderColor),
334
+ borderStyle: p.borderStyle || 'solid',
120
335
  rowGap: p.spacing ?? 0,
121
336
  alignItems: p.alignment === 'center'
122
337
  ? 'center'
123
- : p.alignment === 'trailing'
338
+ : p.alignment === 'trailing' || p.alignment === 'end'
124
339
  ? 'flex-end'
125
340
  : 'flex-start',
126
341
  justifyContent: p.justifyContent === 'center'
@@ -129,9 +344,12 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
129
344
  ? 'space-between'
130
345
  : p.justifyContent === 'spaceAround'
131
346
  ? 'space-around'
132
- : p.justifyContent === 'flexEnd'
133
- ? 'flex-end'
134
- : 'flex-start',
347
+ : p.justifyContent === 'spaceEvenly'
348
+ ? 'space-evenly'
349
+ : p.justifyContent === 'flexEnd'
350
+ ? 'flex-end'
351
+ : 'flex-start',
352
+ ...extractShadowStyle(p),
135
353
  };
136
354
  if (isRoot) {
137
355
  containerStyle.width = '100%';
@@ -146,24 +364,29 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
146
364
  else {
147
365
  containerStyle.alignSelf = 'stretch';
148
366
  }
149
- return (React.createElement(View, { style: containerStyle }, vnode.children?.map((child, idx) => (React.createElement(React.Fragment, { key: idx }, renderPreviewNode(child, onAction, false, 'column'))))));
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))))));
150
368
  }
151
369
  case 'HStack': {
152
370
  const hnode = node;
153
- const p = extractPropsAndStyle(hnode.props);
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';
154
376
  const containerStyle = {
155
- flexDirection: 'row',
377
+ flexDirection: isRtl ? 'row-reverse' : 'row',
156
378
  padding: p.padding,
157
379
  paddingHorizontal: p.paddingHorizontal,
158
380
  paddingVertical: p.paddingVertical,
159
- backgroundColor: parseDynamicColor(p.backgroundColor) || 'transparent',
381
+ backgroundColor: bg,
160
382
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 0,
161
383
  borderWidth: p.borderWidth,
162
384
  borderColor: parseDynamicColor(p.borderColor),
385
+ borderStyle: p.borderStyle || 'solid',
163
386
  columnGap: p.spacing ?? 0,
164
387
  alignItems: p.alignment === 'center'
165
388
  ? 'center'
166
- : p.alignment === 'trailing'
389
+ : p.alignment === 'trailing' || p.alignment === 'bottom'
167
390
  ? 'flex-end'
168
391
  : p.alignment === 'top'
169
392
  ? 'flex-start'
@@ -174,9 +397,12 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
174
397
  ? 'space-between'
175
398
  : p.justifyContent === 'spaceAround'
176
399
  ? 'space-around'
177
- : p.justifyContent === 'flexEnd'
178
- ? 'flex-end'
179
- : 'flex-start',
400
+ : p.justifyContent === 'spaceEvenly'
401
+ ? 'space-evenly'
402
+ : p.justifyContent === 'flexEnd'
403
+ ? 'flex-end'
404
+ : 'flex-start',
405
+ ...extractShadowStyle(p),
180
406
  };
181
407
  if (isRoot) {
182
408
  containerStyle.width = '100%';
@@ -188,12 +414,12 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
188
414
  else if (p.flex !== undefined) {
189
415
  containerStyle.flex = p.flex;
190
416
  }
191
- return (React.createElement(View, { style: containerStyle }, hnode.children?.map((child, idx) => (React.createElement(React.Fragment, { key: idx }, renderPreviewNode(child, onAction, false, 'row'))))));
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))))));
192
418
  }
193
419
  case 'ZStack': {
194
420
  const znode = node;
195
- const p = extractPropsAndStyle(znode.props);
196
- return (React.createElement(View, { style: {
421
+ const p = (0, jsx_1.extractPropsAndStyle)(znode.props);
422
+ return (react_1.default.createElement(react_native_1.View, { style: {
197
423
  position: 'relative',
198
424
  width: isRoot ? '100%' : undefined,
199
425
  height: isRoot ? '100%' : undefined,
@@ -202,25 +428,35 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
202
428
  justifyContent: 'center',
203
429
  backgroundColor: parseDynamicColor(p.backgroundColor) || 'transparent',
204
430
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 0,
205
- } }, znode.children?.map((child, idx) => (React.createElement(View, { key: idx, style: idx === 0
431
+ } }, znode.children?.map((child, idx) => (react_1.default.createElement(react_native_1.View, { key: idx, style: idx === 0
206
432
  ? { width: '100%', height: '100%' }
207
- : { ...StyleSheet.absoluteFillObject, alignItems: 'center', justifyContent: 'center' } }, renderPreviewNode(child, onAction, false, parentDirection))))));
433
+ : { ...react_native_1.StyleSheet.absoluteFillObject, alignItems: 'center', justifyContent: 'center' } }, renderPreviewNode(child, onAction, false, parentDirection, syncVars))))));
208
434
  }
209
435
  case 'Grid': {
210
436
  const gnode = node;
211
- const p = extractPropsAndStyle(gnode.props);
437
+ const p = (0, jsx_1.extractPropsAndStyle)(gnode.props);
212
438
  const cols = p.columns ?? 2;
213
- return (React.createElement(View, { style: {
439
+ return (react_1.default.createElement(react_native_1.View, { style: {
214
440
  flexDirection: 'row',
215
441
  flexWrap: 'wrap',
216
442
  gap: p.spacing ?? 6,
217
443
  width: '100%',
218
444
  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'))))));
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))))));
220
446
  }
221
447
  case 'Text': {
222
448
  const tnode = node;
223
- const p = extractPropsAndStyle(tnode.props);
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);
224
460
  const textStyle = {
225
461
  color: parseDynamicColor(p.color) || '#FFFFFF',
226
462
  fontSize: p.fontSize ?? 14,
@@ -231,42 +467,78 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
231
467
  : p.fontWeight === 'medium'
232
468
  ? '500'
233
469
  : 'normal',
234
- textAlign: p.textAlign ?? 'left',
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,
235
480
  };
236
- return (React.createElement(RNText, { numberOfLines: p.numberOfLines, style: [
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: [
237
482
  textStyle,
238
483
  parentDirection === 'row' ? { flexShrink: 1 } : undefined,
239
- ] }, p.text));
484
+ ] }, isRedacted ? '••••••••' : resolvedText));
240
485
  }
241
486
  case 'Button': {
242
487
  const bnode = node;
243
488
  const p = bnode.props;
489
+ const bg = p.gradient?.colors?.[0]
490
+ ? parseDynamicColor(p.gradient.colors[0])
491
+ : parseDynamicColor(p.backgroundColor) || '#2563EB';
244
492
  const btnStyle = {
245
- backgroundColor: parseDynamicColor(p.backgroundColor) || '#2563EB',
493
+ backgroundColor: bg,
246
494
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 8,
495
+ borderWidth: p.borderWidth,
496
+ borderColor: parseDynamicColor(p.borderColor),
497
+ borderStyle: p.borderStyle || 'solid',
247
498
  paddingHorizontal: p.paddingHorizontal ?? p.padding ?? 12,
248
499
  paddingVertical: p.paddingVertical ?? p.padding ?? 6,
249
500
  alignItems: 'center',
250
501
  justifyContent: 'center',
251
502
  alignSelf: p.fullWidth ? 'stretch' : 'auto',
252
- width: p.fullWidth ? '100%' : undefined,
503
+ ...(p.fullWidth ? (parentDirection === 'row' ? { flex: 1 } : { width: '100%' }) : {}),
504
+ ...extractShadowStyle(p),
253
505
  };
254
506
  const textStyle = {
255
507
  color: parseDynamicColor(p.textColor) || '#FFFFFF',
256
508
  fontSize: p.fontSize ?? 12,
257
509
  fontWeight: p.fontWeight ?? '600',
510
+ fontFamily: p.fontDesign === 'monospaced' ? 'monospace' : undefined,
258
511
  };
259
- return (React.createElement(TouchableOpacity, { activeOpacity: 0.7, onPress: () => {
260
- if (p.actionId && onAction) {
261
- onAction(p.actionId);
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
+ }
262
534
  }
263
535
  }, style: btnStyle },
264
- React.createElement(RNText, { numberOfLines: 1, style: textStyle }, p.title)));
536
+ react_1.default.createElement(react_native_1.Text, { numberOfLines: 1, style: textStyle }, p.title)));
265
537
  }
266
538
  case 'Badge': {
267
539
  const bnode = node;
268
540
  const p = bnode.props;
269
- return (React.createElement(View, { style: {
541
+ return (react_1.default.createElement(react_native_1.View, { style: {
270
542
  backgroundColor: parseDynamicColor(p.backgroundColor) || '#064E3B',
271
543
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 6,
272
544
  paddingHorizontal: p.paddingHorizontal ?? 6,
@@ -274,7 +546,7 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
274
546
  flexShrink: 0,
275
547
  alignSelf: 'center',
276
548
  } },
277
- React.createElement(RNText, { numberOfLines: 1, style: {
549
+ react_1.default.createElement(react_native_1.Text, { numberOfLines: 1, style: {
278
550
  color: parseDynamicColor(p.textColor) || '#6EE7B7',
279
551
  fontSize: p.fontSize ?? 10,
280
552
  fontWeight: '600',
@@ -290,15 +562,15 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
290
562
  if (p.style === 'segmented' && (p.segments ?? 4) > 1) {
291
563
  const segs = p.segments ?? 4;
292
564
  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: {
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: {
294
566
  flex: 1,
295
567
  height,
296
568
  backgroundColor: idx < filled ? tint : track,
297
569
  borderRadius: height / 2,
298
570
  } })))));
299
571
  }
300
- return (React.createElement(View, { style: { width: '100%', height, backgroundColor: track, borderRadius: height / 2, alignSelf: 'stretch' } },
301
- React.createElement(View, { style: {
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: {
302
574
  width: `${val * 100}%`,
303
575
  height,
304
576
  backgroundColor: tint,
@@ -308,13 +580,7 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
308
580
  case 'Timer': {
309
581
  const tnode = node;
310
582
  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 || ''));
583
+ return react_1.default.createElement(PreviewTimerText, { nodeProps: p, parentDirection: parentDirection });
318
584
  }
319
585
  case 'Image': {
320
586
  const inode = node;
@@ -323,13 +589,13 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
323
589
  const height = p.height ?? 32;
324
590
  const uri = p.url || (p.base64 ? `data:image/png;base64,${p.base64}` : null);
325
591
  if (uri) {
326
- return (React.createElement(RNImage, { source: { uri }, style: {
592
+ return (react_1.default.createElement(react_native_1.Image, { source: { uri }, style: {
327
593
  width,
328
594
  height,
329
595
  borderRadius: p.borderRadius ?? p.cornerRadius ?? 0,
330
596
  } }));
331
597
  }
332
- return (React.createElement(View, { style: {
598
+ return (react_1.default.createElement(react_native_1.View, { style: {
333
599
  width,
334
600
  height,
335
601
  backgroundColor: '#334155',
@@ -337,44 +603,44 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
337
603
  alignItems: 'center',
338
604
  justifyContent: 'center',
339
605
  } },
340
- React.createElement(RNText, { style: { color: '#94A3B8', fontSize: 10 } }, "IMG")));
606
+ react_1.default.createElement(react_native_1.Text, { style: { color: '#94A3B8', fontSize: 10 } }, "IMG")));
341
607
  }
342
608
  case 'Spacer': {
343
609
  const snode = node;
344
610
  const p = snode.props || {};
345
611
  const minLen = p?.minLength ?? 4;
346
- return (React.createElement(View, { style: parentDirection === 'row'
612
+ return (react_1.default.createElement(react_native_1.View, { style: parentDirection === 'row'
347
613
  ? { minWidth: minLen, flex: 1 }
348
614
  : { minHeight: minLen, flex: 1 } }));
349
615
  }
350
616
  case 'Divider': {
351
617
  const p = node.props || {};
352
618
  const color = parseDynamicColor(p.color) || '#334155';
353
- return (React.createElement(View, { style: parentDirection === 'row'
619
+ return (react_1.default.createElement(react_native_1.View, { style: parentDirection === 'row'
354
620
  ? { width: 1, height: '100%', backgroundColor: color }
355
621
  : { width: '100%', height: 1, backgroundColor: color, alignSelf: 'stretch' } }));
356
622
  }
357
623
  case 'Link': {
358
624
  const lnode = node;
359
625
  const p = lnode.props || {};
360
- return (React.createElement(TouchableOpacity, { activeOpacity: 0.7, onPress: () => {
626
+ return (react_1.default.createElement(react_native_1.TouchableOpacity, { activeOpacity: 0.7, onPress: () => {
361
627
  if (p.url && onAction)
362
628
  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))))));
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))))));
364
630
  }
365
631
  case 'Equalizer': {
366
632
  const enode = node;
367
633
  const p = enode.props || {};
368
634
  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 } })))));
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 } })))));
370
636
  }
371
637
  case 'Gauge': {
372
638
  const gnode = node;
373
639
  const p = gnode.props || {};
374
640
  const val = Math.round((p.value ?? 0.75) * 100);
375
641
  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' } },
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' } },
378
644
  val,
379
645
  "%")));
380
646
  }
@@ -384,18 +650,21 @@ function renderPreviewNode(node, onAction, isRoot = false, parentDirection = 'co
384
650
  const values = Array.isArray(p.values) ? p.values : [20, 45, 60, 80, 50];
385
651
  const maxVal = Math.max(...values, 1);
386
652
  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: {
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: {
388
654
  flex: 1,
389
655
  height: `${Math.max(15, (v / maxVal) * 100)}%`,
390
656
  backgroundColor: tint,
391
657
  borderRadius: 2,
392
658
  } })))));
393
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
+ }
394
663
  default:
395
664
  return null;
396
665
  }
397
666
  }
398
- const styles = StyleSheet.create({
667
+ const styles = react_native_1.StyleSheet.create({
399
668
  container: {
400
669
  alignItems: 'center',
401
670
  marginVertical: 12,