@upsoftware_tech/svarium 1.0.7 → 1.0.8
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/dist/svarium.css +1 -1
- package/package.json +3 -2
- package/src/lib/appearance.ts +748 -0
- package/src/lib/block.ts +51 -0
- package/src/lib/utils.ts +7 -0
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
type AppearanceLike = {
|
|
2
|
+
class?: unknown;
|
|
3
|
+
style?: unknown;
|
|
4
|
+
fontWeight?: unknown;
|
|
5
|
+
fontSize?: unknown;
|
|
6
|
+
textColor?: unknown;
|
|
7
|
+
fontColor?: unknown;
|
|
8
|
+
bgColor?: unknown;
|
|
9
|
+
borderWidth?: unknown;
|
|
10
|
+
borderRadius?: unknown;
|
|
11
|
+
borderColor?: unknown;
|
|
12
|
+
borderStyle?: unknown;
|
|
13
|
+
outlineWidth?: unknown;
|
|
14
|
+
outlineColor?: unknown;
|
|
15
|
+
outlineStyle?: unknown;
|
|
16
|
+
outlineOffset?: unknown;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const fontWeightToClass: Record<string, string> = {
|
|
21
|
+
'100': 'font-thin',
|
|
22
|
+
'200': 'font-extralight',
|
|
23
|
+
'300': 'font-light',
|
|
24
|
+
'400': 'font-normal',
|
|
25
|
+
'500': 'font-medium',
|
|
26
|
+
'600': 'font-semibold',
|
|
27
|
+
'700': 'font-bold',
|
|
28
|
+
'800': 'font-extrabold',
|
|
29
|
+
'900': 'font-black',
|
|
30
|
+
thin: 'font-thin',
|
|
31
|
+
extralight: 'font-extralight',
|
|
32
|
+
'extra-light': 'font-extralight',
|
|
33
|
+
light: 'font-light',
|
|
34
|
+
normal: 'font-normal',
|
|
35
|
+
regular: 'font-normal',
|
|
36
|
+
medium: 'font-medium',
|
|
37
|
+
semibold: 'font-semibold',
|
|
38
|
+
'semi-bold': 'font-semibold',
|
|
39
|
+
bold: 'font-bold',
|
|
40
|
+
extrabold: 'font-extrabold',
|
|
41
|
+
'extra-bold': 'font-extrabold',
|
|
42
|
+
black: 'font-black',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const fontSizeToClass: Record<string, string> = {
|
|
46
|
+
xs: 'text-xs',
|
|
47
|
+
sm: 'text-sm',
|
|
48
|
+
base: 'text-base',
|
|
49
|
+
lg: 'text-lg',
|
|
50
|
+
xl: 'text-xl',
|
|
51
|
+
'2xl': 'text-2xl',
|
|
52
|
+
'3xl': 'text-3xl',
|
|
53
|
+
'4xl': 'text-4xl',
|
|
54
|
+
'5xl': 'text-5xl',
|
|
55
|
+
'6xl': 'text-6xl',
|
|
56
|
+
'7xl': 'text-7xl',
|
|
57
|
+
'8xl': 'text-8xl',
|
|
58
|
+
'9xl': 'text-9xl',
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const fontColorToClass: Record<string, string> = {
|
|
62
|
+
slate: 'text-slate-500',
|
|
63
|
+
gray: 'text-gray-500',
|
|
64
|
+
zinc: 'text-zinc-500',
|
|
65
|
+
neutral: 'text-neutral-500',
|
|
66
|
+
stone: 'text-stone-500',
|
|
67
|
+
red: 'text-red-500',
|
|
68
|
+
orange: 'text-orange-500',
|
|
69
|
+
amber: 'text-amber-500',
|
|
70
|
+
yellow: 'text-yellow-500',
|
|
71
|
+
lime: 'text-lime-500',
|
|
72
|
+
green: 'text-green-500',
|
|
73
|
+
emerald: 'text-emerald-500',
|
|
74
|
+
teal: 'text-teal-500',
|
|
75
|
+
cyan: 'text-cyan-500',
|
|
76
|
+
sky: 'text-sky-500',
|
|
77
|
+
blue: 'text-blue-500',
|
|
78
|
+
indigo: 'text-indigo-500',
|
|
79
|
+
violet: 'text-violet-500',
|
|
80
|
+
purple: 'text-purple-500',
|
|
81
|
+
fuchsia: 'text-fuchsia-500',
|
|
82
|
+
pink: 'text-pink-500',
|
|
83
|
+
rose: 'text-rose-500',
|
|
84
|
+
white: 'text-white',
|
|
85
|
+
black: 'text-black',
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const backgroundColorToClass: Record<string, string> = {
|
|
89
|
+
slate: 'bg-slate-500',
|
|
90
|
+
gray: 'bg-gray-500',
|
|
91
|
+
zinc: 'bg-zinc-500',
|
|
92
|
+
neutral: 'bg-neutral-500',
|
|
93
|
+
stone: 'bg-stone-500',
|
|
94
|
+
red: 'bg-red-500',
|
|
95
|
+
'red-200': 'bg-red-200',
|
|
96
|
+
orange: 'bg-orange-500',
|
|
97
|
+
amber: 'bg-amber-500',
|
|
98
|
+
yellow: 'bg-yellow-500',
|
|
99
|
+
lime: 'bg-lime-500',
|
|
100
|
+
green: 'bg-green-500',
|
|
101
|
+
emerald: 'bg-emerald-500',
|
|
102
|
+
teal: 'bg-teal-500',
|
|
103
|
+
cyan: 'bg-cyan-500',
|
|
104
|
+
sky: 'bg-sky-500',
|
|
105
|
+
blue: 'bg-blue-500',
|
|
106
|
+
indigo: 'bg-indigo-500',
|
|
107
|
+
violet: 'bg-violet-500',
|
|
108
|
+
purple: 'bg-purple-500',
|
|
109
|
+
fuchsia: 'bg-fuchsia-500',
|
|
110
|
+
pink: 'bg-pink-500',
|
|
111
|
+
rose: 'bg-rose-500',
|
|
112
|
+
white: 'bg-white',
|
|
113
|
+
black: 'bg-black',
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const borderColorToClass: Record<string, string> = {
|
|
117
|
+
slate: 'border-slate-500',
|
|
118
|
+
gray: 'border-gray-500',
|
|
119
|
+
zinc: 'border-zinc-500',
|
|
120
|
+
neutral: 'border-neutral-500',
|
|
121
|
+
stone: 'border-stone-500',
|
|
122
|
+
red: 'border-red-500',
|
|
123
|
+
orange: 'border-orange-500',
|
|
124
|
+
amber: 'border-amber-500',
|
|
125
|
+
yellow: 'border-yellow-500',
|
|
126
|
+
lime: 'border-lime-500',
|
|
127
|
+
green: 'border-green-500',
|
|
128
|
+
emerald: 'border-emerald-500',
|
|
129
|
+
teal: 'border-teal-500',
|
|
130
|
+
cyan: 'border-cyan-500',
|
|
131
|
+
sky: 'border-sky-500',
|
|
132
|
+
blue: 'border-blue-500',
|
|
133
|
+
indigo: 'border-indigo-500',
|
|
134
|
+
violet: 'border-violet-500',
|
|
135
|
+
purple: 'border-purple-500',
|
|
136
|
+
fuchsia: 'border-fuchsia-500',
|
|
137
|
+
pink: 'border-pink-500',
|
|
138
|
+
rose: 'border-rose-500',
|
|
139
|
+
white: 'border-white',
|
|
140
|
+
black: 'border-black',
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const outlineColorToClass: Record<string, string> = {
|
|
144
|
+
slate: 'outline-slate-500',
|
|
145
|
+
gray: 'outline-gray-500',
|
|
146
|
+
zinc: 'outline-zinc-500',
|
|
147
|
+
neutral: 'outline-neutral-500',
|
|
148
|
+
stone: 'outline-stone-500',
|
|
149
|
+
red: 'outline-red-500',
|
|
150
|
+
orange: 'outline-orange-500',
|
|
151
|
+
amber: 'outline-amber-500',
|
|
152
|
+
yellow: 'outline-yellow-500',
|
|
153
|
+
lime: 'outline-lime-500',
|
|
154
|
+
green: 'outline-green-500',
|
|
155
|
+
emerald: 'outline-emerald-500',
|
|
156
|
+
teal: 'outline-teal-500',
|
|
157
|
+
cyan: 'outline-cyan-500',
|
|
158
|
+
sky: 'outline-sky-500',
|
|
159
|
+
blue: 'outline-blue-500',
|
|
160
|
+
indigo: 'outline-indigo-500',
|
|
161
|
+
violet: 'outline-violet-500',
|
|
162
|
+
purple: 'outline-purple-500',
|
|
163
|
+
fuchsia: 'outline-fuchsia-500',
|
|
164
|
+
pink: 'outline-pink-500',
|
|
165
|
+
rose: 'outline-rose-500',
|
|
166
|
+
white: 'outline-white',
|
|
167
|
+
black: 'outline-black',
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
function getColorParts(value: unknown): { light?: unknown; dark?: unknown } {
|
|
171
|
+
if (Array.isArray(value)) {
|
|
172
|
+
return {
|
|
173
|
+
light: value[0],
|
|
174
|
+
dark: value[1],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (value && typeof value === 'object') {
|
|
179
|
+
const record = value as Record<string, unknown>;
|
|
180
|
+
if ('light' in record || 'dark' in record) {
|
|
181
|
+
return {
|
|
182
|
+
light: record.light,
|
|
183
|
+
dark: record.dark,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (value !== undefined) {
|
|
189
|
+
return { light: value };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return {};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function appendTextColor(
|
|
196
|
+
value: unknown,
|
|
197
|
+
classTokens: string[],
|
|
198
|
+
style: Record<string, string>,
|
|
199
|
+
dark = false,
|
|
200
|
+
): void {
|
|
201
|
+
const raw = value !== undefined && value !== null ? String(value).trim() : '';
|
|
202
|
+
if (raw === '') {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const normalized = raw.toLowerCase();
|
|
207
|
+
let token = '';
|
|
208
|
+
|
|
209
|
+
if (normalized.startsWith('text-')) {
|
|
210
|
+
token = normalized;
|
|
211
|
+
} else if (fontColorToClass[normalized]) {
|
|
212
|
+
token = fontColorToClass[normalized];
|
|
213
|
+
} else if (/^[a-z]+-(50|[1-9]00)$/.test(normalized)) {
|
|
214
|
+
token = `text-${normalized}`;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (token !== '') {
|
|
218
|
+
classTokens.push(dark ? `dark:${token}` : token);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (dark) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (/^(#|rgb\(|rgba\(|hsl\(|hsla\(|var\()/.test(raw)) {
|
|
227
|
+
style.color = raw;
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
style.color = raw;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function appendBackgroundColor(
|
|
235
|
+
value: unknown,
|
|
236
|
+
classTokens: string[],
|
|
237
|
+
style: Record<string, string>,
|
|
238
|
+
dark = false,
|
|
239
|
+
): void {
|
|
240
|
+
const raw = value !== undefined && value !== null ? String(value).trim() : '';
|
|
241
|
+
if (raw === '') {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const normalized = raw.toLowerCase();
|
|
246
|
+
let token = '';
|
|
247
|
+
|
|
248
|
+
if (normalized.startsWith('bg-')) {
|
|
249
|
+
token = normalized;
|
|
250
|
+
} else if (backgroundColorToClass[normalized]) {
|
|
251
|
+
token = backgroundColorToClass[normalized];
|
|
252
|
+
} else if (/^[a-z]+-(50|[1-9]00)$/.test(normalized)) {
|
|
253
|
+
token = `bg-${normalized}`;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (token !== '') {
|
|
257
|
+
classTokens.push(dark ? `dark:${token}` : token);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (dark) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (/^(#|rgb\(|rgba\(|hsl\(|hsla\(|var\()/.test(raw)) {
|
|
266
|
+
style.backgroundColor = raw;
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
style.backgroundColor = raw;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function appendBorderWidth(
|
|
274
|
+
value: unknown,
|
|
275
|
+
classTokens: string[],
|
|
276
|
+
style: Record<string, string>,
|
|
277
|
+
): void {
|
|
278
|
+
const raw = value !== undefined && value !== null ? String(value).trim() : '';
|
|
279
|
+
if (raw === '') {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const normalized = raw.toLowerCase();
|
|
284
|
+
const normalizedNumber = normalized.endsWith('.')
|
|
285
|
+
? normalized.slice(0, -1)
|
|
286
|
+
: normalized;
|
|
287
|
+
|
|
288
|
+
if (normalized === 'border' || normalized.startsWith('border-')) {
|
|
289
|
+
classTokens.push(normalized);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (/^(x|y|t|r|b|l)-.+$/.test(normalized)) {
|
|
294
|
+
classTokens.push(`border-${normalized}`);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (/^\d+$/.test(normalizedNumber)) {
|
|
299
|
+
if (normalizedNumber === '0') {
|
|
300
|
+
classTokens.push('border-0');
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (normalizedNumber === '1') {
|
|
305
|
+
classTokens.push('border');
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
classTokens.push(`border-${normalizedNumber}`);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (/^\d+(\.\d+)?(px|rem|em|%)$/.test(normalized)) {
|
|
314
|
+
style.borderWidth = normalized;
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (/^\d+(\.\d+)?$/.test(normalizedNumber)) {
|
|
319
|
+
style.borderWidth = `${normalizedNumber}px`;
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
style.borderWidth = raw;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function appendBorderRadius(
|
|
327
|
+
value: unknown,
|
|
328
|
+
classTokens: string[],
|
|
329
|
+
style: Record<string, string>,
|
|
330
|
+
): void {
|
|
331
|
+
const raw = value !== undefined && value !== null ? String(value).trim() : '';
|
|
332
|
+
if (raw === '') {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const normalized = raw.toLowerCase();
|
|
337
|
+
|
|
338
|
+
if (normalized.startsWith('rounded')) {
|
|
339
|
+
classTokens.push(normalized);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (normalized === 'base' || normalized === 'default') {
|
|
344
|
+
classTokens.push('rounded');
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (/^[a-z]{1,2}-.+$/.test(normalized)) {
|
|
349
|
+
classTokens.push(`rounded-${normalized}`);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (/^(none|sm|md|lg|xl|2xl|3xl|full)$/.test(normalized)) {
|
|
354
|
+
classTokens.push(`rounded-${normalized}`);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (/^\d+(\.\d+)?(px|rem|em|%)$/.test(normalized)) {
|
|
359
|
+
style.borderRadius = normalized;
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (/^\d+(\.\d+)?$/.test(normalized)) {
|
|
364
|
+
style.borderRadius = `${normalized}px`;
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
style.borderRadius = raw;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function appendBorderColor(
|
|
372
|
+
value: unknown,
|
|
373
|
+
classTokens: string[],
|
|
374
|
+
style: Record<string, string>,
|
|
375
|
+
dark = false,
|
|
376
|
+
): void {
|
|
377
|
+
const raw = value !== undefined && value !== null ? String(value).trim() : '';
|
|
378
|
+
if (raw === '') {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const normalized = raw.toLowerCase();
|
|
383
|
+
let token = '';
|
|
384
|
+
|
|
385
|
+
if (normalized.startsWith('border-')) {
|
|
386
|
+
token = normalized;
|
|
387
|
+
} else if (borderColorToClass[normalized]) {
|
|
388
|
+
token = borderColorToClass[normalized];
|
|
389
|
+
} else if (/^[a-z]+-(50|[1-9]00)$/.test(normalized)) {
|
|
390
|
+
token = `border-${normalized}`;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (token !== '') {
|
|
394
|
+
classTokens.push(dark ? `dark:${token}` : token);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (dark) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (/^(#|rgb\(|rgba\(|hsl\(|hsla\(|var\()/.test(raw)) {
|
|
403
|
+
style.borderColor = raw;
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
style.borderColor = raw;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function appendBorderStyle(
|
|
411
|
+
value: unknown,
|
|
412
|
+
classTokens: string[],
|
|
413
|
+
style: Record<string, string>,
|
|
414
|
+
): void {
|
|
415
|
+
const raw = value !== undefined && value !== null ? String(value).trim() : '';
|
|
416
|
+
if (raw === '') {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const normalized = raw.toLowerCase();
|
|
421
|
+
|
|
422
|
+
if (normalized.startsWith('border-')) {
|
|
423
|
+
classTokens.push(normalized);
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const styleMap: Record<string, string> = {
|
|
428
|
+
solid: 'border-solid',
|
|
429
|
+
dashed: 'border-dashed',
|
|
430
|
+
dotted: 'border-dotted',
|
|
431
|
+
double: 'border-double',
|
|
432
|
+
none: 'border-none',
|
|
433
|
+
hidden: 'border-hidden',
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
if (styleMap[normalized]) {
|
|
437
|
+
classTokens.push(styleMap[normalized]);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
style.borderStyle = raw;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function appendOutlineWidth(
|
|
445
|
+
value: unknown,
|
|
446
|
+
classTokens: string[],
|
|
447
|
+
style: Record<string, string>,
|
|
448
|
+
): void {
|
|
449
|
+
const raw = value !== undefined && value !== null ? String(value).trim() : '';
|
|
450
|
+
if (raw === '') {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const normalized = raw.toLowerCase();
|
|
455
|
+
|
|
456
|
+
if (normalized === 'outline' || normalized.startsWith('outline-')) {
|
|
457
|
+
classTokens.push(normalized);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (/^\d+$/.test(normalized)) {
|
|
462
|
+
if (normalized === '1') {
|
|
463
|
+
classTokens.push('outline');
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
classTokens.push(`outline-${normalized}`);
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (/^\d+(\.\d+)?(px|rem|em|%)$/.test(normalized)) {
|
|
472
|
+
style.outlineWidth = normalized;
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (/^\d+(\.\d+)?$/.test(normalized)) {
|
|
477
|
+
style.outlineWidth = `${normalized}px`;
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
style.outlineWidth = raw;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function appendOutlineColor(
|
|
485
|
+
value: unknown,
|
|
486
|
+
classTokens: string[],
|
|
487
|
+
style: Record<string, string>,
|
|
488
|
+
dark = false,
|
|
489
|
+
): void {
|
|
490
|
+
const raw = value !== undefined && value !== null ? String(value).trim() : '';
|
|
491
|
+
if (raw === '') {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const normalized = raw.toLowerCase();
|
|
496
|
+
let token = '';
|
|
497
|
+
|
|
498
|
+
if (normalized.startsWith('outline-')) {
|
|
499
|
+
token = normalized;
|
|
500
|
+
} else if (outlineColorToClass[normalized]) {
|
|
501
|
+
token = outlineColorToClass[normalized];
|
|
502
|
+
} else if (/^[a-z]+-(50|[1-9]00)$/.test(normalized)) {
|
|
503
|
+
token = `outline-${normalized}`;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (token !== '') {
|
|
507
|
+
classTokens.push(dark ? `dark:${token}` : token);
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (dark) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
if (/^(#|rgb\(|rgba\(|hsl\(|hsla\(|var\()/.test(raw)) {
|
|
516
|
+
style.outlineColor = raw;
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
style.outlineColor = raw;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function appendOutlineStyle(
|
|
524
|
+
value: unknown,
|
|
525
|
+
classTokens: string[],
|
|
526
|
+
style: Record<string, string>,
|
|
527
|
+
): void {
|
|
528
|
+
const raw = value !== undefined && value !== null ? String(value).trim() : '';
|
|
529
|
+
if (raw === '') {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const normalized = raw.toLowerCase();
|
|
534
|
+
|
|
535
|
+
if (normalized.startsWith('outline-')) {
|
|
536
|
+
classTokens.push(normalized);
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const styleMap: Record<string, string> = {
|
|
541
|
+
solid: 'outline-solid',
|
|
542
|
+
dashed: 'outline-dashed',
|
|
543
|
+
dotted: 'outline-dotted',
|
|
544
|
+
double: 'outline-double',
|
|
545
|
+
none: 'outline-none',
|
|
546
|
+
hidden: 'outline-hidden',
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
if (styleMap[normalized]) {
|
|
550
|
+
classTokens.push(styleMap[normalized]);
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
style.outlineStyle = raw;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function appendOutlineOffset(
|
|
558
|
+
value: unknown,
|
|
559
|
+
classTokens: string[],
|
|
560
|
+
style: Record<string, string>,
|
|
561
|
+
): void {
|
|
562
|
+
const raw = value !== undefined && value !== null ? String(value).trim() : '';
|
|
563
|
+
if (raw === '') {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const normalized = raw.toLowerCase();
|
|
568
|
+
|
|
569
|
+
if (normalized.startsWith('outline-offset-')) {
|
|
570
|
+
classTokens.push(normalized);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (/^\d+$/.test(normalized)) {
|
|
575
|
+
classTokens.push(`outline-offset-${normalized}`);
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (/^\d+(\.\d+)?(px|rem|em|%)$/.test(normalized)) {
|
|
580
|
+
style.outlineOffset = normalized;
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
if (/^\d+(\.\d+)?$/.test(normalized)) {
|
|
585
|
+
style.outlineOffset = `${normalized}px`;
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
style.outlineOffset = raw;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function normalizeClassTokens(input: unknown): string[] {
|
|
593
|
+
if (typeof input === 'string') {
|
|
594
|
+
return input.split(/\s+/).map((token) => token.trim()).filter(Boolean);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if (Array.isArray(input)) {
|
|
598
|
+
return input.flatMap((entry) => normalizeClassTokens(entry));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
if (input && typeof input === 'object') {
|
|
602
|
+
return Object.entries(input as Record<string, unknown>)
|
|
603
|
+
.filter(([, enabled]) => Boolean(enabled))
|
|
604
|
+
.map(([token]) => token);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
return [];
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function uniqueTokens(tokens: string[]): string[] {
|
|
611
|
+
return Array.from(new Set(tokens.filter(Boolean)));
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function mergeStyle(base: unknown, extra: Record<string, string>): unknown {
|
|
615
|
+
if (Object.keys(extra).length === 0) {
|
|
616
|
+
return base;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if (base === undefined || base === null || base === '') {
|
|
620
|
+
return extra;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (Array.isArray(base)) {
|
|
624
|
+
return [...base, extra];
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if (typeof base === 'object') {
|
|
628
|
+
return { ...(base as Record<string, unknown>), ...extra };
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
return [base, extra];
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
function normalizeAppearance(appearance: AppearanceLike): {
|
|
635
|
+
classTokens: string[];
|
|
636
|
+
style: Record<string, string>;
|
|
637
|
+
appearance: AppearanceLike;
|
|
638
|
+
} {
|
|
639
|
+
const classTokens = normalizeClassTokens(appearance.class);
|
|
640
|
+
const style: Record<string, string> = {};
|
|
641
|
+
|
|
642
|
+
const weight = appearance.fontWeight !== undefined
|
|
643
|
+
? String(appearance.fontWeight).trim().toLowerCase()
|
|
644
|
+
: '';
|
|
645
|
+
|
|
646
|
+
if (weight !== '' && fontWeightToClass[weight]) {
|
|
647
|
+
classTokens.push(fontWeightToClass[weight]);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const fontSize = appearance.fontSize !== undefined
|
|
651
|
+
? String(appearance.fontSize).trim().toLowerCase()
|
|
652
|
+
: '';
|
|
653
|
+
|
|
654
|
+
if (fontSize !== '') {
|
|
655
|
+
if (fontSizeToClass[fontSize]) {
|
|
656
|
+
classTokens.push(fontSizeToClass[fontSize]);
|
|
657
|
+
} else if (fontSize.startsWith('text-')) {
|
|
658
|
+
classTokens.push(fontSize);
|
|
659
|
+
} else if (/^\d+(\.\d+)?$/.test(fontSize)) {
|
|
660
|
+
style.fontSize = `${fontSize}px`;
|
|
661
|
+
} else if (/^\d+(\.\d+)?(px|rem|em|%)$/.test(fontSize)) {
|
|
662
|
+
style.fontSize = fontSize;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
const textColorValue = appearance.textColor !== undefined
|
|
667
|
+
? appearance.textColor
|
|
668
|
+
: appearance.fontColor;
|
|
669
|
+
const { light: lightTextColor, dark: darkTextColor } = getColorParts(textColorValue);
|
|
670
|
+
appendTextColor(lightTextColor, classTokens, style);
|
|
671
|
+
appendTextColor(darkTextColor, classTokens, style, true);
|
|
672
|
+
|
|
673
|
+
const { light: lightBgColor, dark: darkBgColor } = getColorParts(appearance.bgColor);
|
|
674
|
+
appendBackgroundColor(lightBgColor, classTokens, style);
|
|
675
|
+
appendBackgroundColor(darkBgColor, classTokens, style, true);
|
|
676
|
+
|
|
677
|
+
appendBorderWidth(appearance.borderWidth, classTokens, style);
|
|
678
|
+
appendBorderRadius(appearance.borderRadius, classTokens, style);
|
|
679
|
+
|
|
680
|
+
const { light: lightBorderColor, dark: darkBorderColor } = getColorParts(appearance.borderColor);
|
|
681
|
+
appendBorderColor(lightBorderColor, classTokens, style);
|
|
682
|
+
appendBorderColor(darkBorderColor, classTokens, style, true);
|
|
683
|
+
|
|
684
|
+
appendBorderStyle(appearance.borderStyle, classTokens, style);
|
|
685
|
+
|
|
686
|
+
appendOutlineWidth(appearance.outlineWidth, classTokens, style);
|
|
687
|
+
|
|
688
|
+
const { light: lightOutlineColor, dark: darkOutlineColor } = getColorParts(appearance.outlineColor);
|
|
689
|
+
appendOutlineColor(lightOutlineColor, classTokens, style);
|
|
690
|
+
appendOutlineColor(darkOutlineColor, classTokens, style, true);
|
|
691
|
+
|
|
692
|
+
appendOutlineStyle(appearance.outlineStyle, classTokens, style);
|
|
693
|
+
appendOutlineOffset(appearance.outlineOffset, classTokens, style);
|
|
694
|
+
|
|
695
|
+
const nextAppearance: AppearanceLike = {
|
|
696
|
+
...appearance,
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
delete nextAppearance.fontWeight;
|
|
700
|
+
delete nextAppearance.fontSize;
|
|
701
|
+
delete nextAppearance.textColor;
|
|
702
|
+
delete nextAppearance.fontColor;
|
|
703
|
+
delete nextAppearance.bgColor;
|
|
704
|
+
delete nextAppearance.borderWidth;
|
|
705
|
+
delete nextAppearance.borderRadius;
|
|
706
|
+
delete nextAppearance.borderColor;
|
|
707
|
+
delete nextAppearance.borderStyle;
|
|
708
|
+
delete nextAppearance.outlineWidth;
|
|
709
|
+
delete nextAppearance.outlineColor;
|
|
710
|
+
delete nextAppearance.outlineStyle;
|
|
711
|
+
delete nextAppearance.outlineOffset;
|
|
712
|
+
|
|
713
|
+
if (classTokens.length > 0) {
|
|
714
|
+
nextAppearance.class = uniqueTokens(classTokens).join(' ');
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (Object.keys(style).length > 0) {
|
|
718
|
+
nextAppearance.style = mergeStyle(appearance.style, style);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
return {
|
|
722
|
+
classTokens: uniqueTokens(classTokens),
|
|
723
|
+
style,
|
|
724
|
+
appearance: nextAppearance,
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
export function normalizeNodeProps(nodeProps: Record<string, any>): Record<string, any> {
|
|
729
|
+
const resolved = { ...nodeProps };
|
|
730
|
+
const appearance = resolved.appearance;
|
|
731
|
+
|
|
732
|
+
if (appearance && typeof appearance === 'object' && !Array.isArray(appearance)) {
|
|
733
|
+
const normalized = normalizeAppearance(appearance as AppearanceLike);
|
|
734
|
+
const combinedClass = uniqueTokens([
|
|
735
|
+
...normalizeClassTokens(resolved.class),
|
|
736
|
+
...normalized.classTokens,
|
|
737
|
+
]);
|
|
738
|
+
|
|
739
|
+
if (combinedClass.length > 0) {
|
|
740
|
+
resolved.class = combinedClass.join(' ');
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
resolved.style = mergeStyle(resolved.style, normalized.style);
|
|
744
|
+
resolved.appearance = normalized.appearance;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
return resolved;
|
|
748
|
+
}
|