zelune 1.5.4 → 1.5.6
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.
- package/CHANGELOG.md +26 -0
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/plugins/viteReactNativeFallbackPlugin.ts +13 -53
- package/src/canvas/CanvasApp.tsx +165 -57
- package/src/canvas/FlowArrowsLayer.tsx +2 -2
- package/src/canvas/ScreenArtboard.tsx +17 -3
- package/src/main.tsx +1 -0
- package/src/runtime/MockNavigationContext.tsx +577 -56
- package/src/runtime/nativewindShim.ts +972 -0
- package/src/runtime/reactNativeShim.ts +99 -0
- package/vite.config.ts +58 -0
|
@@ -0,0 +1,972 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export interface TailwindThemeConfig {
|
|
4
|
+
colors?: Record<string, unknown>;
|
|
5
|
+
fontSize?: Record<string, unknown>;
|
|
6
|
+
borderRadius?: Record<string, unknown>;
|
|
7
|
+
spacing?: Record<string, unknown>;
|
|
8
|
+
opacity?: Record<string, unknown>;
|
|
9
|
+
fontFamily?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare global {
|
|
13
|
+
interface Window {
|
|
14
|
+
__ZELUNE_TAILWIND_THEME__?: TailwindThemeConfig;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Built-in fallback palette combining standard Tailwind v3 colors + M3 / NativeWind semantic tokens
|
|
19
|
+
const DEFAULT_COLORS: Record<string, unknown> = {
|
|
20
|
+
transparent: 'transparent',
|
|
21
|
+
current: 'currentColor',
|
|
22
|
+
black: '#000000',
|
|
23
|
+
white: '#FFFFFF',
|
|
24
|
+
surface: {
|
|
25
|
+
DEFAULT: '#FAFAFA',
|
|
26
|
+
dim: '#F2F2F2',
|
|
27
|
+
bright: '#FFFFFF',
|
|
28
|
+
'container-lowest': '#F9FAFB',
|
|
29
|
+
'container-low': '#F3F4F6',
|
|
30
|
+
container: '#FFFFFF',
|
|
31
|
+
'container-high': '#F3F4F6',
|
|
32
|
+
'container-highest': '#E5E7EB',
|
|
33
|
+
},
|
|
34
|
+
'on-surface': {
|
|
35
|
+
DEFAULT: '#1A1A2E',
|
|
36
|
+
variant: '#6B7280',
|
|
37
|
+
},
|
|
38
|
+
primary: {
|
|
39
|
+
DEFAULT: '#0F3460',
|
|
40
|
+
container: '#E8F0FF',
|
|
41
|
+
fixed: '#E8F0FF',
|
|
42
|
+
'fixed-dim': '#C5D5F0',
|
|
43
|
+
'on-primary': '#FFFFFF',
|
|
44
|
+
'on-container': '#0F3460',
|
|
45
|
+
},
|
|
46
|
+
secondary: {
|
|
47
|
+
DEFAULT: '#4B5563',
|
|
48
|
+
container: '#F3F4F6',
|
|
49
|
+
'on-secondary': '#FFFFFF',
|
|
50
|
+
'on-container': '#1A1A2E',
|
|
51
|
+
},
|
|
52
|
+
tertiary: {
|
|
53
|
+
DEFAULT: '#0D9488',
|
|
54
|
+
container: '#CCFBF1',
|
|
55
|
+
'on-tertiary': '#FFFFFF',
|
|
56
|
+
'on-container': '#134E4A',
|
|
57
|
+
},
|
|
58
|
+
outline: {
|
|
59
|
+
DEFAULT: '#E5E7EB',
|
|
60
|
+
variant: '#F3F4F6',
|
|
61
|
+
},
|
|
62
|
+
inverse: {
|
|
63
|
+
surface: '#1A1A2E',
|
|
64
|
+
'on-surface': '#FAFAFA',
|
|
65
|
+
primary: '#C5D5F0',
|
|
66
|
+
},
|
|
67
|
+
error: {
|
|
68
|
+
DEFAULT: '#DC2626',
|
|
69
|
+
container: '#FEE2E2',
|
|
70
|
+
},
|
|
71
|
+
slate: {
|
|
72
|
+
50: '#F8FAFC',
|
|
73
|
+
100: '#F1F5F9',
|
|
74
|
+
200: '#E2E8F0',
|
|
75
|
+
300: '#CBD5E1',
|
|
76
|
+
400: '#94A3B8',
|
|
77
|
+
500: '#64748B',
|
|
78
|
+
600: '#475569',
|
|
79
|
+
700: '#334155',
|
|
80
|
+
800: '#1E293B',
|
|
81
|
+
900: '#0F172A',
|
|
82
|
+
},
|
|
83
|
+
gray: {
|
|
84
|
+
50: '#F9FAFB',
|
|
85
|
+
100: '#F3F4F6',
|
|
86
|
+
200: '#E5E7EB',
|
|
87
|
+
300: '#D1D5DB',
|
|
88
|
+
400: '#9CA3AF',
|
|
89
|
+
500: '#6B7280',
|
|
90
|
+
600: '#4B5563',
|
|
91
|
+
700: '#374151',
|
|
92
|
+
800: '#1F2937',
|
|
93
|
+
900: '#111827',
|
|
94
|
+
},
|
|
95
|
+
zinc: {
|
|
96
|
+
50: '#FAFAFA',
|
|
97
|
+
100: '#F4F4F5',
|
|
98
|
+
200: '#E4E4E7',
|
|
99
|
+
300: '#D4D4D8',
|
|
100
|
+
400: '#A1A1AA',
|
|
101
|
+
500: '#71717A',
|
|
102
|
+
600: '#52525B',
|
|
103
|
+
700: '#3F3F46',
|
|
104
|
+
800: '#27272A',
|
|
105
|
+
900: '#18181B',
|
|
106
|
+
},
|
|
107
|
+
red: {
|
|
108
|
+
50: '#FEF2F2',
|
|
109
|
+
100: '#FEE2E2',
|
|
110
|
+
200: '#FECACA',
|
|
111
|
+
400: '#F87171',
|
|
112
|
+
500: '#EF4444',
|
|
113
|
+
600: '#DC2626',
|
|
114
|
+
700: '#B91C1C',
|
|
115
|
+
},
|
|
116
|
+
amber: {
|
|
117
|
+
50: '#FFFBEB',
|
|
118
|
+
100: '#FEF3C7',
|
|
119
|
+
200: '#FDE68A',
|
|
120
|
+
400: '#FBBF24',
|
|
121
|
+
500: '#F59E0B',
|
|
122
|
+
600: '#D97706',
|
|
123
|
+
700: '#B45309',
|
|
124
|
+
},
|
|
125
|
+
yellow: {
|
|
126
|
+
50: '#FEFCE8',
|
|
127
|
+
100: '#FEF9C3',
|
|
128
|
+
400: '#FACC15',
|
|
129
|
+
500: '#EAB308',
|
|
130
|
+
600: '#CA8A04',
|
|
131
|
+
},
|
|
132
|
+
green: {
|
|
133
|
+
50: '#F0FDF4',
|
|
134
|
+
100: '#DCFCE7',
|
|
135
|
+
400: '#4ADE80',
|
|
136
|
+
500: '#22C55E',
|
|
137
|
+
600: '#16A34A',
|
|
138
|
+
700: '#15803D',
|
|
139
|
+
},
|
|
140
|
+
emerald: {
|
|
141
|
+
50: '#ECFDF5',
|
|
142
|
+
100: '#D1FAE5',
|
|
143
|
+
400: '#34D399',
|
|
144
|
+
500: '#10B981',
|
|
145
|
+
600: '#059669',
|
|
146
|
+
700: '#047857',
|
|
147
|
+
},
|
|
148
|
+
teal: {
|
|
149
|
+
50: '#F0FDFA',
|
|
150
|
+
100: '#CCFBF1',
|
|
151
|
+
400: '#2DD4BF',
|
|
152
|
+
500: '#14B8A6',
|
|
153
|
+
600: '#0D9488',
|
|
154
|
+
700: '#0F766E',
|
|
155
|
+
},
|
|
156
|
+
sky: {
|
|
157
|
+
50: '#F0F9FF',
|
|
158
|
+
100: '#E0F2FE',
|
|
159
|
+
400: '#38BDF8',
|
|
160
|
+
500: '#0EA5E9',
|
|
161
|
+
600: '#0284C7',
|
|
162
|
+
},
|
|
163
|
+
blue: {
|
|
164
|
+
50: '#EFF6FF',
|
|
165
|
+
100: '#DBEAFE',
|
|
166
|
+
200: '#BFDBFE',
|
|
167
|
+
400: '#60A5FA',
|
|
168
|
+
500: '#3B82F6',
|
|
169
|
+
600: '#2563EB',
|
|
170
|
+
700: '#1D4ED8',
|
|
171
|
+
},
|
|
172
|
+
indigo: {
|
|
173
|
+
50: '#EEF2FF',
|
|
174
|
+
100: '#E0E7FF',
|
|
175
|
+
400: '#818CF8',
|
|
176
|
+
500: '#6366F1',
|
|
177
|
+
600: '#4F46E5',
|
|
178
|
+
700: '#4338CA',
|
|
179
|
+
},
|
|
180
|
+
purple: {
|
|
181
|
+
50: '#FAF5FF',
|
|
182
|
+
100: '#F3E8FF',
|
|
183
|
+
500: '#A855F7',
|
|
184
|
+
600: '#9333EA',
|
|
185
|
+
},
|
|
186
|
+
pink: {
|
|
187
|
+
50: '#FDF2F8',
|
|
188
|
+
100: '#FCE7F3',
|
|
189
|
+
500: '#EC4899',
|
|
190
|
+
600: '#DB2777',
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const DEFAULT_FONT_SIZES: Record<string, [number, { lineHeight?: number; letterSpacing?: number; fontWeight?: string }]> = {
|
|
195
|
+
xs: [12, { lineHeight: 16 }],
|
|
196
|
+
sm: [14, { lineHeight: 20 }],
|
|
197
|
+
base: [16, { lineHeight: 24 }],
|
|
198
|
+
lg: [18, { lineHeight: 28 }],
|
|
199
|
+
xl: [20, { lineHeight: 28 }],
|
|
200
|
+
'2xl': [24, { lineHeight: 32 }],
|
|
201
|
+
'3xl': [30, { lineHeight: 36 }],
|
|
202
|
+
'4xl': [36, { lineHeight: 40 }],
|
|
203
|
+
'5xl': [48, { lineHeight: 52 }],
|
|
204
|
+
'display-lg': [57, { lineHeight: 64, letterSpacing: -0.25 }],
|
|
205
|
+
'display-md': [45, { lineHeight: 52 }],
|
|
206
|
+
'display-sm': [36, { lineHeight: 44 }],
|
|
207
|
+
'headline-lg': [32, { lineHeight: 40 }],
|
|
208
|
+
'headline-md': [28, { lineHeight: 36 }],
|
|
209
|
+
'headline-sm': [24, { lineHeight: 32 }],
|
|
210
|
+
'title-lg': [22, { lineHeight: 28 }],
|
|
211
|
+
'title-md': [16, { lineHeight: 24, letterSpacing: 0.15, fontWeight: '500' }],
|
|
212
|
+
'title-sm': [14, { lineHeight: 20, letterSpacing: 0.1, fontWeight: '500' }],
|
|
213
|
+
'body-lg': [16, { lineHeight: 24, letterSpacing: 0.5 }],
|
|
214
|
+
'body-md': [14, { lineHeight: 20, letterSpacing: 0.25 }],
|
|
215
|
+
'body-sm': [12, { lineHeight: 16, letterSpacing: 0.4 }],
|
|
216
|
+
'label-lg': [14, { lineHeight: 20, letterSpacing: 0.1, fontWeight: '500' }],
|
|
217
|
+
'label-md': [12, { lineHeight: 16, letterSpacing: 0.5, fontWeight: '500' }],
|
|
218
|
+
'label-sm': [11, { lineHeight: 16, letterSpacing: 0.5, fontWeight: '500' }],
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const DEFAULT_RADII: Record<string, number> = {
|
|
222
|
+
none: 0,
|
|
223
|
+
sm: 4,
|
|
224
|
+
DEFAULT: 6,
|
|
225
|
+
md: 8,
|
|
226
|
+
lg: 12,
|
|
227
|
+
xl: 16,
|
|
228
|
+
'2xl': 24,
|
|
229
|
+
'3xl': 28,
|
|
230
|
+
full: 9999,
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
function parsePxNumber(val: unknown): number | undefined {
|
|
234
|
+
if (typeof val === 'number' && Number.isFinite(val)) return val;
|
|
235
|
+
if (typeof val === 'string') {
|
|
236
|
+
const trimmed = val.trim();
|
|
237
|
+
if (trimmed.endsWith('rem')) {
|
|
238
|
+
const n = Number.parseFloat(trimmed);
|
|
239
|
+
return Number.isFinite(n) ? n * 16 : undefined;
|
|
240
|
+
}
|
|
241
|
+
const n = Number.parseFloat(trimmed.replace(/px$/i, ''));
|
|
242
|
+
return Number.isFinite(n) ? n : undefined;
|
|
243
|
+
}
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function applyColorAlpha(colorStr: string, alphaRatio: number): string {
|
|
248
|
+
if (!Number.isFinite(alphaRatio) || alphaRatio >= 1) return colorStr;
|
|
249
|
+
const clamped = Math.max(0, Math.min(1, alphaRatio));
|
|
250
|
+
const hexMatch = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(colorStr.trim());
|
|
251
|
+
if (hexMatch) {
|
|
252
|
+
let hex = hexMatch[1];
|
|
253
|
+
if (hex.length === 3) {
|
|
254
|
+
hex = hex
|
|
255
|
+
.split('')
|
|
256
|
+
.map((c) => c + c)
|
|
257
|
+
.join('');
|
|
258
|
+
}
|
|
259
|
+
const r = Number.parseInt(hex.slice(0, 2), 16);
|
|
260
|
+
const g = Number.parseInt(hex.slice(2, 4), 16);
|
|
261
|
+
const b = Number.parseInt(hex.slice(4, 6), 16);
|
|
262
|
+
return `rgba(${r}, ${g}, ${b}, ${Number(clamped.toFixed(3))})`;
|
|
263
|
+
}
|
|
264
|
+
const rgbMatch = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i.exec(colorStr.trim());
|
|
265
|
+
if (rgbMatch) {
|
|
266
|
+
return `rgba(${rgbMatch[1]}, ${rgbMatch[2]}, ${rgbMatch[3]}, ${Number(clamped.toFixed(3))})`;
|
|
267
|
+
}
|
|
268
|
+
return colorStr;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function lookupColorToken(rawToken: string, themeColors: Record<string, unknown>): string | undefined {
|
|
272
|
+
// Arbitrary value e.g. [#0F3460] or [rgba(0,0,0,0.5)]
|
|
273
|
+
if (rawToken.startsWith('[') && rawToken.endsWith(']')) {
|
|
274
|
+
return rawToken.slice(1, -1);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const [colorPath, alphaPart] = rawToken.split('/');
|
|
278
|
+
let resolvedHex: string | undefined;
|
|
279
|
+
|
|
280
|
+
// 1. Direct match in themeColors or DEFAULT_COLORS
|
|
281
|
+
const sources = [themeColors, DEFAULT_COLORS];
|
|
282
|
+
for (const src of sources) {
|
|
283
|
+
if (!src || typeof src !== 'object') continue;
|
|
284
|
+
const direct = src[colorPath];
|
|
285
|
+
if (typeof direct === 'string') {
|
|
286
|
+
resolvedHex = direct;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
if (direct && typeof direct === 'object' && 'DEFAULT' in direct) {
|
|
290
|
+
const defVal = (direct as Record<string, unknown>).DEFAULT;
|
|
291
|
+
if (typeof defVal === 'string') {
|
|
292
|
+
resolvedHex = defVal;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Try splitting hyphenated prefixes e.g. 'surface-container-high' -> src['surface']['container-high']
|
|
298
|
+
// or 'on-surface-variant' -> src['on-surface']['variant']
|
|
299
|
+
const parts = colorPath.split('-');
|
|
300
|
+
for (let splitIdx = parts.length - 1; splitIdx >= 1; splitIdx--) {
|
|
301
|
+
const groupKey = parts.slice(0, splitIdx).join('-');
|
|
302
|
+
const shadeKey = parts.slice(splitIdx).join('-');
|
|
303
|
+
const groupObj = src[groupKey];
|
|
304
|
+
if (groupObj && typeof groupObj === 'object') {
|
|
305
|
+
const shadeVal = (groupObj as Record<string, unknown>)[shadeKey];
|
|
306
|
+
if (typeof shadeVal === 'string') {
|
|
307
|
+
resolvedHex = shadeVal;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (resolvedHex) break;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (!resolvedHex) return undefined;
|
|
316
|
+
|
|
317
|
+
if (alphaPart !== undefined) {
|
|
318
|
+
const customOpacity =
|
|
319
|
+
typeof window !== 'undefined' ? window.__ZELUNE_TAILWIND_THEME__?.opacity?.[alphaPart] : undefined;
|
|
320
|
+
let alphaRatio =
|
|
321
|
+
typeof customOpacity === 'string' || typeof customOpacity === 'number'
|
|
322
|
+
? Number.parseFloat(String(customOpacity))
|
|
323
|
+
: Number.NaN;
|
|
324
|
+
if (!Number.isFinite(alphaRatio)) {
|
|
325
|
+
const numeric = Number.parseFloat(alphaPart);
|
|
326
|
+
if (Number.isFinite(numeric)) {
|
|
327
|
+
alphaRatio = numeric <= 1 ? numeric : numeric / 100;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (Number.isFinite(alphaRatio)) {
|
|
331
|
+
return applyColorAlpha(resolvedHex, alphaRatio);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return resolvedHex;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function resolveSpacingToken(rawVal: string, themeSpacing: Record<string, unknown>): number | string | undefined {
|
|
339
|
+
if (rawVal === 'auto') return 'auto';
|
|
340
|
+
if (rawVal === 'px') return 1;
|
|
341
|
+
if (rawVal === 'full') return '100%';
|
|
342
|
+
if (rawVal.startsWith('[') && rawVal.endsWith(']')) {
|
|
343
|
+
const inner = rawVal.slice(1, -1);
|
|
344
|
+
if (inner.endsWith('%')) return inner;
|
|
345
|
+
const px = parsePxNumber(inner);
|
|
346
|
+
return px !== undefined ? px : inner;
|
|
347
|
+
}
|
|
348
|
+
if (rawVal.includes('/')) {
|
|
349
|
+
const [num, den] = rawVal.split('/').map(Number);
|
|
350
|
+
if (Number.isFinite(num) && Number.isFinite(den) && den !== 0) {
|
|
351
|
+
return `${Number(((num / den) * 100).toFixed(4))}%`;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (themeSpacing && rawVal in themeSpacing) {
|
|
355
|
+
const customPx = parsePxNumber(themeSpacing[rawVal]);
|
|
356
|
+
if (customPx !== undefined) return customPx;
|
|
357
|
+
}
|
|
358
|
+
const num = Number.parseFloat(rawVal);
|
|
359
|
+
if (Number.isFinite(num)) {
|
|
360
|
+
return num * 4;
|
|
361
|
+
}
|
|
362
|
+
return undefined;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const classStyleCache = new Map<string, Record<string, unknown>>();
|
|
366
|
+
|
|
367
|
+
export function resolveTailwindClassNameToStyle(className?: string): Record<string, unknown> | null {
|
|
368
|
+
if (!className || typeof className !== 'string') return null;
|
|
369
|
+
const normalized = className.replace(/\s+/g, ' ').trim();
|
|
370
|
+
if (!normalized) return null;
|
|
371
|
+
|
|
372
|
+
const cached = classStyleCache.get(normalized);
|
|
373
|
+
if (cached) return cached;
|
|
374
|
+
|
|
375
|
+
const projectTheme: TailwindThemeConfig =
|
|
376
|
+
(typeof window !== 'undefined' && window.__ZELUNE_TAILWIND_THEME__) || {};
|
|
377
|
+
const themeColors = (projectTheme.colors ?? {}) as Record<string, unknown>;
|
|
378
|
+
const themeFontSizes = (projectTheme.fontSize ?? {}) as Record<string, unknown>;
|
|
379
|
+
const themeRadii = (projectTheme.borderRadius ?? {}) as Record<string, unknown>;
|
|
380
|
+
const themeSpacing = (projectTheme.spacing ?? {}) as Record<string, unknown>;
|
|
381
|
+
|
|
382
|
+
const style: Record<string, unknown> = {};
|
|
383
|
+
const tokens = normalized.split(' ');
|
|
384
|
+
|
|
385
|
+
for (const rawToken of tokens) {
|
|
386
|
+
if (!rawToken) continue;
|
|
387
|
+
// Strip responsive/state prefixes like sm:, md:, active:, focus:, dark:
|
|
388
|
+
const token = rawToken.includes(':') ? rawToken.slice(rawToken.lastIndexOf(':') + 1) : rawToken;
|
|
389
|
+
if (!token) continue;
|
|
390
|
+
|
|
391
|
+
// 1. Flexbox & Layout
|
|
392
|
+
if (token === 'flex-1') {
|
|
393
|
+
style.flex = 1;
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (token === 'flex-auto') {
|
|
397
|
+
style.flex = 1;
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (token === 'flex-none') {
|
|
401
|
+
style.flex = 0;
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (token === 'flex-grow' || token === 'grow') {
|
|
405
|
+
style.flexGrow = 1;
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (token === 'flex-shrink' || token === 'shrink') {
|
|
409
|
+
style.flexShrink = 1;
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (token === 'flex-shrink-0' || token === 'shrink-0') {
|
|
413
|
+
style.flexShrink = 0;
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (token === 'flex-row') {
|
|
417
|
+
style.flexDirection = 'row';
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
if (token === 'flex-row-reverse') {
|
|
421
|
+
style.flexDirection = 'row-reverse';
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (token === 'flex-col') {
|
|
425
|
+
style.flexDirection = 'column';
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
if (token === 'flex-col-reverse') {
|
|
429
|
+
style.flexDirection = 'column-reverse';
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
if (token === 'flex-wrap') {
|
|
433
|
+
style.flexWrap = 'wrap';
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
if (token === 'flex-nowrap') {
|
|
437
|
+
style.flexWrap = 'nowrap';
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (token === 'hidden') {
|
|
441
|
+
style.display = 'none';
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Align Items & Self & Content
|
|
446
|
+
if (token === 'items-start') {
|
|
447
|
+
style.alignItems = 'flex-start';
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (token === 'items-center') {
|
|
451
|
+
style.alignItems = 'center';
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
if (token === 'items-end') {
|
|
455
|
+
style.alignItems = 'flex-end';
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
if (token === 'items-stretch') {
|
|
459
|
+
style.alignItems = 'stretch';
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (token === 'items-baseline') {
|
|
463
|
+
style.alignItems = 'baseline';
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
if (token === 'self-start') {
|
|
467
|
+
style.alignSelf = 'flex-start';
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
if (token === 'self-center') {
|
|
471
|
+
style.alignSelf = 'center';
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
if (token === 'self-end') {
|
|
475
|
+
style.alignSelf = 'flex-end';
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
if (token === 'self-stretch') {
|
|
479
|
+
style.alignSelf = 'stretch';
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
if (token === 'self-auto') {
|
|
483
|
+
style.alignSelf = 'auto';
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// Justify Content
|
|
488
|
+
if (token === 'justify-start') {
|
|
489
|
+
style.justifyContent = 'flex-start';
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
if (token === 'justify-center') {
|
|
493
|
+
style.justifyContent = 'center';
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
if (token === 'justify-end') {
|
|
497
|
+
style.justifyContent = 'flex-end';
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
if (token === 'justify-between') {
|
|
501
|
+
style.justifyContent = 'space-between';
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
if (token === 'justify-around') {
|
|
505
|
+
style.justifyContent = 'space-around';
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
if (token === 'justify-evenly') {
|
|
509
|
+
style.justifyContent = 'space-evenly';
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// Position & Overflow
|
|
514
|
+
if (token === 'relative') {
|
|
515
|
+
style.position = 'relative';
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
if (token === 'absolute') {
|
|
519
|
+
style.position = 'absolute';
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
if (token === 'inset-0') {
|
|
523
|
+
style.top = 0;
|
|
524
|
+
style.right = 0;
|
|
525
|
+
style.bottom = 0;
|
|
526
|
+
style.left = 0;
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
if (token === 'overflow-hidden') {
|
|
530
|
+
style.overflow = 'hidden';
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (token === 'overflow-visible') {
|
|
534
|
+
style.overflow = 'visible';
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
if (token === 'overflow-scroll') {
|
|
538
|
+
style.overflow = 'scroll';
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const posMatch = /^(-?)(top|right|bottom|left)-(.+)$/.exec(token);
|
|
543
|
+
if (posMatch) {
|
|
544
|
+
const sign = posMatch[1] === '-' ? -1 : 1;
|
|
545
|
+
const prop = posMatch[2];
|
|
546
|
+
const val = resolveSpacingToken(posMatch[3], themeSpacing);
|
|
547
|
+
if (typeof val === 'number') style[prop] = val * sign;
|
|
548
|
+
else if (val !== undefined) style[prop] = val;
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (token.startsWith('z-')) {
|
|
553
|
+
const zVal = Number.parseInt(token.slice(2), 10);
|
|
554
|
+
if (Number.isFinite(zVal)) style.zIndex = zVal;
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// 2. Gap
|
|
559
|
+
if (token.startsWith('gap-x-')) {
|
|
560
|
+
const v = resolveSpacingToken(token.slice(6), themeSpacing);
|
|
561
|
+
if (typeof v === 'number') style.columnGap = v;
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
if (token.startsWith('gap-y-')) {
|
|
565
|
+
const v = resolveSpacingToken(token.slice(6), themeSpacing);
|
|
566
|
+
if (typeof v === 'number') style.rowGap = v;
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
if (token.startsWith('gap-')) {
|
|
570
|
+
const v = resolveSpacingToken(token.slice(4), themeSpacing);
|
|
571
|
+
if (typeof v === 'number') style.gap = v;
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// 3. Padding & Margin
|
|
576
|
+
const spacingMatch = /^(-?)(p|px|py|pt|pr|pb|pl|m|mx|my|mt|mr|mb|ml)-(.+)$/.exec(token);
|
|
577
|
+
if (spacingMatch) {
|
|
578
|
+
const sign = spacingMatch[1] === '-' ? -1 : 1;
|
|
579
|
+
const dir = spacingMatch[2];
|
|
580
|
+
const rawVal = resolveSpacingToken(spacingMatch[3], themeSpacing);
|
|
581
|
+
if (rawVal !== undefined) {
|
|
582
|
+
const val = typeof rawVal === 'number' ? rawVal * sign : rawVal;
|
|
583
|
+
const propMap: Record<string, string> = {
|
|
584
|
+
p: 'padding',
|
|
585
|
+
px: 'paddingHorizontal',
|
|
586
|
+
py: 'paddingVertical',
|
|
587
|
+
pt: 'paddingTop',
|
|
588
|
+
pr: 'paddingRight',
|
|
589
|
+
pb: 'paddingBottom',
|
|
590
|
+
pl: 'paddingLeft',
|
|
591
|
+
m: 'margin',
|
|
592
|
+
mx: 'marginHorizontal',
|
|
593
|
+
my: 'marginVertical',
|
|
594
|
+
mt: 'marginTop',
|
|
595
|
+
mr: 'marginRight',
|
|
596
|
+
mb: 'marginBottom',
|
|
597
|
+
ml: 'marginLeft',
|
|
598
|
+
};
|
|
599
|
+
style[propMap[dir]] = val;
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// 4. Width & Height
|
|
605
|
+
if (token === 'w-screen') {
|
|
606
|
+
style.width = 393;
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
if (token === 'h-screen') {
|
|
610
|
+
style.height = 852;
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
if (token.startsWith('w-')) {
|
|
614
|
+
const v = resolveSpacingToken(token.slice(2), themeSpacing);
|
|
615
|
+
if (v !== undefined) {
|
|
616
|
+
style.width = v;
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
if (token.startsWith('h-')) {
|
|
621
|
+
const v = resolveSpacingToken(token.slice(2), themeSpacing);
|
|
622
|
+
if (v !== undefined) {
|
|
623
|
+
style.height = v;
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (token.startsWith('size-')) {
|
|
628
|
+
const v = resolveSpacingToken(token.slice(5), themeSpacing);
|
|
629
|
+
if (v !== undefined) {
|
|
630
|
+
style.width = v;
|
|
631
|
+
style.height = v;
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (token.startsWith('min-w-')) {
|
|
636
|
+
const v = resolveSpacingToken(token.slice(6), themeSpacing);
|
|
637
|
+
if (v !== undefined) {
|
|
638
|
+
style.minWidth = v;
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
if (token.startsWith('min-h-')) {
|
|
643
|
+
const v = resolveSpacingToken(token.slice(6), themeSpacing);
|
|
644
|
+
if (v !== undefined) {
|
|
645
|
+
style.minHeight = v;
|
|
646
|
+
continue;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
if (token.startsWith('max-w-')) {
|
|
650
|
+
const v = resolveSpacingToken(token.slice(6), themeSpacing);
|
|
651
|
+
if (v !== undefined) {
|
|
652
|
+
style.maxWidth = v;
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (token.startsWith('max-h-')) {
|
|
657
|
+
const v = resolveSpacingToken(token.slice(6), themeSpacing);
|
|
658
|
+
if (v !== undefined) {
|
|
659
|
+
style.maxHeight = v;
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// 5. Border Radius
|
|
665
|
+
if (token === 'rounded' || token.startsWith('rounded-')) {
|
|
666
|
+
const suffix = token === 'rounded' ? 'DEFAULT' : token.slice(8);
|
|
667
|
+
const customR = parsePxNumber(themeRadii[suffix]);
|
|
668
|
+
const radiusVal = customR ?? DEFAULT_RADII[suffix];
|
|
669
|
+
if (radiusVal !== undefined) {
|
|
670
|
+
style.borderRadius = radiusVal;
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
const cornerMatch = /^(t|b|l|r|tl|tr|bl|br)-(.+)$/.exec(suffix);
|
|
674
|
+
if (cornerMatch) {
|
|
675
|
+
const cDir = cornerMatch[1];
|
|
676
|
+
const cKey = cornerMatch[2];
|
|
677
|
+
const r = parsePxNumber(themeRadii[cKey]) ?? DEFAULT_RADII[cKey];
|
|
678
|
+
if (r !== undefined) {
|
|
679
|
+
if (cDir === 't' || cDir === 'tl') style.borderTopLeftRadius = r;
|
|
680
|
+
if (cDir === 't' || cDir === 'tr') style.borderTopRightRadius = r;
|
|
681
|
+
if (cDir === 'b' || cDir === 'bl') style.borderBottomLeftRadius = r;
|
|
682
|
+
if (cDir === 'b' || cDir === 'br') style.borderBottomRightRadius = r;
|
|
683
|
+
if (cDir === 'l') {
|
|
684
|
+
style.borderTopLeftRadius = r;
|
|
685
|
+
style.borderBottomLeftRadius = r;
|
|
686
|
+
}
|
|
687
|
+
if (cDir === 'r') {
|
|
688
|
+
style.borderTopRightRadius = r;
|
|
689
|
+
style.borderBottomRightRadius = r;
|
|
690
|
+
}
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// 6. Borders
|
|
697
|
+
if (token === 'border') {
|
|
698
|
+
style.borderWidth = 1;
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
const borderWidthMatch = /^border-(0|2|4|8)$/.exec(token);
|
|
702
|
+
if (borderWidthMatch) {
|
|
703
|
+
style.borderWidth = Number.parseInt(borderWidthMatch[1], 10);
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
706
|
+
const borderSideMatch = /^border-(t|r|b|l)(?:-(0|2|4|8))?$/.exec(token);
|
|
707
|
+
if (borderSideMatch) {
|
|
708
|
+
const sideMap: Record<string, string> = {
|
|
709
|
+
t: 'borderTopWidth',
|
|
710
|
+
r: 'borderRightWidth',
|
|
711
|
+
b: 'borderBottomWidth',
|
|
712
|
+
l: 'borderLeftWidth',
|
|
713
|
+
};
|
|
714
|
+
style[sideMap[borderSideMatch[1]]] = borderSideMatch[2]
|
|
715
|
+
? Number.parseInt(borderSideMatch[2], 10)
|
|
716
|
+
: 1;
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
if (token.startsWith('border-')) {
|
|
720
|
+
const bColor = lookupColorToken(token.slice(7), themeColors);
|
|
721
|
+
if (bColor) {
|
|
722
|
+
style.borderColor = bColor;
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// 7. Background Color (bg-*)
|
|
728
|
+
if (token.startsWith('bg-')) {
|
|
729
|
+
const bgColor = lookupColorToken(token.slice(3), themeColors);
|
|
730
|
+
if (bgColor) {
|
|
731
|
+
style.backgroundColor = bgColor;
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// 8. Typography & Text Color (text-*, font-*, tracking-*, leading-*, etc.)
|
|
737
|
+
if (token === 'italic') {
|
|
738
|
+
style.fontStyle = 'italic';
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
if (token === 'not-italic') {
|
|
742
|
+
style.fontStyle = 'normal';
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
if (token === 'uppercase') {
|
|
746
|
+
style.textTransform = 'uppercase';
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
if (token === 'lowercase') {
|
|
750
|
+
style.textTransform = 'lowercase';
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
if (token === 'capitalize') {
|
|
754
|
+
style.textTransform = 'capitalize';
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
if (token === 'underline') {
|
|
758
|
+
style.textDecorationLine = 'underline';
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
if (token === 'line-through') {
|
|
762
|
+
style.textDecorationLine = 'line-through';
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
if (token === 'text-left') {
|
|
766
|
+
style.textAlign = 'left';
|
|
767
|
+
continue;
|
|
768
|
+
}
|
|
769
|
+
if (token === 'text-center') {
|
|
770
|
+
style.textAlign = 'center';
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
if (token === 'text-right') {
|
|
774
|
+
style.textAlign = 'right';
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// Font family / weight shorthands (both standard Tailwind and custom M3 font tokens)
|
|
779
|
+
if (token === 'font-headline' || token === 'font-bold') {
|
|
780
|
+
style.fontWeight = '700';
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
783
|
+
if (
|
|
784
|
+
token === 'font-headline-medium' ||
|
|
785
|
+
token === 'font-body-semibold' ||
|
|
786
|
+
token === 'font-semibold'
|
|
787
|
+
) {
|
|
788
|
+
style.fontWeight = '600';
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
if (token === 'font-body-medium' || token === 'font-medium') {
|
|
792
|
+
style.fontWeight = '500';
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
if (token === 'font-body' || token === 'font-normal') {
|
|
796
|
+
style.fontWeight = '400';
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
if (token === 'font-light') {
|
|
800
|
+
style.fontWeight = '300';
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
if (token === 'font-extrabold' || token === 'font-black') {
|
|
804
|
+
style.fontWeight = '800';
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
if (token === 'font-mono') {
|
|
808
|
+
style.fontFamily = 'monospace';
|
|
809
|
+
continue;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// Letter spacing (tracking-*)
|
|
813
|
+
if (token === 'tracking-tighter') {
|
|
814
|
+
style.letterSpacing = -0.8;
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
if (token === 'tracking-tight') {
|
|
818
|
+
style.letterSpacing = -0.4;
|
|
819
|
+
continue;
|
|
820
|
+
}
|
|
821
|
+
if (token === 'tracking-normal') {
|
|
822
|
+
style.letterSpacing = 0;
|
|
823
|
+
continue;
|
|
824
|
+
}
|
|
825
|
+
if (token === 'tracking-wide') {
|
|
826
|
+
style.letterSpacing = 0.4;
|
|
827
|
+
continue;
|
|
828
|
+
}
|
|
829
|
+
if (token === 'tracking-wider') {
|
|
830
|
+
style.letterSpacing = 0.8;
|
|
831
|
+
continue;
|
|
832
|
+
}
|
|
833
|
+
if (token === 'tracking-widest') {
|
|
834
|
+
style.letterSpacing = 1.4;
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
if (token.startsWith('text-')) {
|
|
839
|
+
const textSuffix = token.slice(5);
|
|
840
|
+
|
|
841
|
+
// Check custom theme fontSize first
|
|
842
|
+
const customFs = themeFontSizes[textSuffix];
|
|
843
|
+
if (customFs !== undefined) {
|
|
844
|
+
if (Array.isArray(customFs)) {
|
|
845
|
+
const sz = parsePxNumber(customFs[0]);
|
|
846
|
+
if (sz !== undefined) style.fontSize = sz;
|
|
847
|
+
const meta = customFs[1];
|
|
848
|
+
if (meta && typeof meta === 'object') {
|
|
849
|
+
const lh = parsePxNumber((meta as Record<string, unknown>).lineHeight);
|
|
850
|
+
const ls = parsePxNumber((meta as Record<string, unknown>).letterSpacing);
|
|
851
|
+
const fw = (meta as Record<string, unknown>).fontWeight;
|
|
852
|
+
if (lh !== undefined) style.lineHeight = lh;
|
|
853
|
+
if (ls !== undefined) style.letterSpacing = ls;
|
|
854
|
+
if (typeof fw === 'string' || typeof fw === 'number') style.fontWeight = String(fw);
|
|
855
|
+
}
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
const singleSz = parsePxNumber(customFs);
|
|
859
|
+
if (singleSz !== undefined) {
|
|
860
|
+
style.fontSize = singleSz;
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// Check built-in fontSize scale (including M3 type scale: headline-md, title-lg, body-sm, label-md, etc.)
|
|
866
|
+
const builtinFs = DEFAULT_FONT_SIZES[textSuffix];
|
|
867
|
+
if (builtinFs) {
|
|
868
|
+
style.fontSize = builtinFs[0];
|
|
869
|
+
if (builtinFs[1].lineHeight !== undefined) style.lineHeight = builtinFs[1].lineHeight;
|
|
870
|
+
if (builtinFs[1].letterSpacing !== undefined) style.letterSpacing = builtinFs[1].letterSpacing;
|
|
871
|
+
if (builtinFs[1].fontWeight !== undefined && !style.fontWeight) {
|
|
872
|
+
style.fontWeight = builtinFs[1].fontWeight;
|
|
873
|
+
}
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// Arbitrary font size e.g. text-[15px]
|
|
878
|
+
if (textSuffix.startsWith('[') && textSuffix.endsWith(']')) {
|
|
879
|
+
const inner = textSuffix.slice(1, -1);
|
|
880
|
+
const px = parsePxNumber(inner);
|
|
881
|
+
if (px !== undefined && !inner.startsWith('#') && !inner.startsWith('rgb')) {
|
|
882
|
+
style.fontSize = px;
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// Otherwise resolve as text color
|
|
888
|
+
const tColor = lookupColorToken(textSuffix, themeColors);
|
|
889
|
+
if (tColor) {
|
|
890
|
+
style.color = tColor;
|
|
891
|
+
continue;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// 9. Opacity & Shadows
|
|
896
|
+
if (token.startsWith('opacity-')) {
|
|
897
|
+
const opVal = Number.parseFloat(token.slice(8));
|
|
898
|
+
if (Number.isFinite(opVal)) {
|
|
899
|
+
style.opacity = opVal <= 1 ? opVal : opVal / 100;
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
if (token === 'shadow-sm' || token === 'shadow') {
|
|
904
|
+
style.shadowColor = '#0F172A';
|
|
905
|
+
style.shadowOffset = { width: 0, height: 2 };
|
|
906
|
+
style.shadowOpacity = 0.06;
|
|
907
|
+
style.shadowRadius = 6;
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
if (token === 'shadow-md' || token === 'shadow-lg' || token === 'shadow-xl') {
|
|
911
|
+
style.shadowColor = '#0F172A';
|
|
912
|
+
style.shadowOffset = { width: 0, height: 6 };
|
|
913
|
+
style.shadowOpacity = 0.1;
|
|
914
|
+
style.shadowRadius = 14;
|
|
915
|
+
continue;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
classStyleCache.set(normalized, style);
|
|
920
|
+
return style;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
export function withNativeWind<P extends Record<string, unknown>>(
|
|
924
|
+
BaseComponent: React.ComponentType<P>,
|
|
925
|
+
displayName?: string
|
|
926
|
+
): React.ComponentType<P> {
|
|
927
|
+
const Wrapped = React.forwardRef<unknown, P>((props, ref) => {
|
|
928
|
+
const rawClassName = props?.className as string | undefined;
|
|
929
|
+
const rawContentClassName = props?.contentContainerClassName as string | undefined;
|
|
930
|
+
|
|
931
|
+
if (!rawClassName && !rawContentClassName) {
|
|
932
|
+
return React.createElement(BaseComponent, { ...props, ref } as unknown as P);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
const twStyle = resolveTailwindClassNameToStyle(rawClassName);
|
|
936
|
+
const twContentStyle = resolveTailwindClassNameToStyle(rawContentClassName);
|
|
937
|
+
|
|
938
|
+
const nextProps: Record<string, unknown> = { ...props, ref };
|
|
939
|
+
delete nextProps.className;
|
|
940
|
+
delete nextProps.contentContainerClassName;
|
|
941
|
+
|
|
942
|
+
if (twStyle) {
|
|
943
|
+
const origStyle = props.style;
|
|
944
|
+
if (typeof origStyle === 'function') {
|
|
945
|
+
nextProps.style = (state: unknown) => [twStyle, (origStyle as (s: unknown) => unknown)(state)];
|
|
946
|
+
} else if (origStyle !== undefined) {
|
|
947
|
+
nextProps.style = [twStyle, origStyle];
|
|
948
|
+
} else {
|
|
949
|
+
nextProps.style = twStyle;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
if (twContentStyle) {
|
|
954
|
+
const origContentStyle = props.contentContainerStyle;
|
|
955
|
+
nextProps.contentContainerStyle =
|
|
956
|
+
origContentStyle !== undefined ? [twContentStyle, origContentStyle] : twContentStyle;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
return React.createElement(BaseComponent, nextProps as unknown as P);
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
Wrapped.displayName = displayName ?? BaseComponent.displayName ?? BaseComponent.name ?? 'RNComponent';
|
|
963
|
+
// Copy static properties (e.g., Image.getSize, Image.prefetch, Animated.*)
|
|
964
|
+
for (const key of Object.keys(BaseComponent)) {
|
|
965
|
+
if (!(key in Wrapped)) {
|
|
966
|
+
(Wrapped as unknown as Record<string, unknown>)[key] = (
|
|
967
|
+
BaseComponent as unknown as Record<string, unknown>
|
|
968
|
+
)[key];
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
return Wrapped as unknown as React.ComponentType<P>;
|
|
972
|
+
}
|