nitrowind 0.0.0-stage → 0.1.0
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 +23 -0
- package/LICENSE +21 -0
- package/README.md +44 -2
- package/css.d.ts +6 -0
- package/dist/color.d.ts +24 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +158 -0
- package/dist/color.js.map +1 -0
- package/dist/core.d.ts +121 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +1026 -0
- package/dist/core.js.map +1 -0
- package/dist/css/compile.d.ts +18 -0
- package/dist/css/compile.d.ts.map +1 -0
- package/dist/css/compile.js +1018 -0
- package/dist/css/compile.js.map +1 -0
- package/dist/css/declarations.d.ts +18 -0
- package/dist/css/declarations.d.ts.map +1 -0
- package/dist/css/declarations.js +1173 -0
- package/dist/css/declarations.js.map +1 -0
- package/dist/css/index.d.ts +7 -0
- package/dist/css/index.d.ts.map +1 -0
- package/dist/css/index.js +7 -0
- package/dist/css/index.js.map +1 -0
- package/dist/css/parser.d.ts +9 -0
- package/dist/css/parser.d.ts.map +1 -0
- package/dist/css/parser.js +188 -0
- package/dist/css/parser.js.map +1 -0
- package/dist/css/tokenizer.d.ts +14 -0
- package/dist/css/tokenizer.d.ts.map +1 -0
- package/dist/css/tokenizer.js +200 -0
- package/dist/css/tokenizer.js.map +1 -0
- package/dist/css/types.d.ts +128 -0
- package/dist/css/types.d.ts.map +1 -0
- package/dist/css/types.js +19 -0
- package/dist/css/types.js.map +1 -0
- package/dist/css/values.d.ts +37 -0
- package/dist/css/values.d.ts.map +1 -0
- package/dist/css/values.js +343 -0
- package/dist/css/values.js.map +1 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +99 -0
- package/dist/environment.js.map +1 -0
- package/dist/hooks.d.ts +22 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +140 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +17 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +12 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-namespace.d.ts +29 -0
- package/dist/jsx-namespace.d.ts.map +1 -0
- package/dist/jsx-namespace.js +2 -0
- package/dist/jsx-namespace.js.map +1 -0
- package/dist/jsx-runtime.d.ts +22 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +21 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/math.d.ts +50 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +442 -0
- package/dist/math.js.map +1 -0
- package/dist/plugin.d.ts +45 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +172 -0
- package/dist/plugin.js.map +1 -0
- package/dist/props.d.ts +29 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +163 -0
- package/dist/props.js.map +1 -0
- package/dist/scope.d.ts +99 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +228 -0
- package/dist/scope.js.map +1 -0
- package/dist/store.d.ts +18 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +244 -0
- package/dist/store.js.map +1 -0
- package/dist/tokens/index.d.ts +12 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +237 -0
- package/dist/tokens/index.js.map +1 -0
- package/dist/tokens/tailwind.generated.d.ts +3 -0
- package/dist/tokens/tailwind.generated.d.ts.map +1 -0
- package/dist/tokens/tailwind.generated.js +610 -0
- package/dist/tokens/tailwind.generated.js.map +1 -0
- package/dist/tokens/types.d.ts +95 -0
- package/dist/tokens/types.d.ts.map +1 -0
- package/dist/tokens/types.js +2 -0
- package/dist/tokens/types.js.map +1 -0
- package/dist/transform.d.ts +22 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +79 -0
- package/dist/transform.js.map +1 -0
- package/dist/transition.d.ts +7 -0
- package/dist/transition.d.ts.map +1 -0
- package/dist/transition.js +355 -0
- package/dist/transition.js.map +1 -0
- package/dist/types.d.ts +214 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities.d.ts +109 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +2000 -0
- package/dist/utilities.js.map +1 -0
- package/dist/variables.d.ts +65 -0
- package/dist/variables.d.ts.map +1 -0
- package/dist/variables.js +408 -0
- package/dist/variables.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/withNitroWind.d.ts +11 -0
- package/dist/withNitroWind.d.ts.map +1 -0
- package/dist/withNitroWind.js +27 -0
- package/dist/withNitroWind.js.map +1 -0
- package/package.json +89 -4
- package/src/color.ts +164 -0
- package/src/core.ts +1248 -0
- package/src/css/compile.ts +1198 -0
- package/src/css/declarations.ts +1141 -0
- package/src/css/index.ts +22 -0
- package/src/css/parser.ts +196 -0
- package/src/css/tokenizer.ts +227 -0
- package/src/css/types.ts +178 -0
- package/src/css/values.ts +330 -0
- package/src/environment.ts +112 -0
- package/src/hooks.ts +190 -0
- package/src/index.ts +61 -0
- package/src/jsx-dev-runtime.ts +43 -0
- package/src/jsx-namespace.ts +23 -0
- package/src/jsx-runtime.ts +39 -0
- package/src/math.ts +488 -0
- package/src/plugin.ts +230 -0
- package/src/props.ts +173 -0
- package/src/scope.ts +331 -0
- package/src/store.ts +288 -0
- package/src/tokens/index.ts +252 -0
- package/src/tokens/tailwind.generated.ts +613 -0
- package/src/tokens/types.ts +99 -0
- package/src/transform.ts +115 -0
- package/src/transition.ts +414 -0
- package/src/types.ts +248 -0
- package/src/utilities.ts +1992 -0
- package/src/variables.ts +509 -0
- package/src/version.ts +2 -0
- package/src/withNitroWind.ts +36 -0
|
@@ -0,0 +1,2000 @@
|
|
|
1
|
+
import { multiplyAlpha, parseColor, withAlpha } from './color';
|
|
2
|
+
import { hasMathFunction, hasViewportUnit, isMathExpression } from './math';
|
|
3
|
+
import { extractVariableNames, hasVarCall, parseDynamicValue } from './variables';
|
|
4
|
+
const MISSING_VIEWPORT = Symbol('missing-viewport');
|
|
5
|
+
export function createDraft() {
|
|
6
|
+
return { layout: {}, style: {}, text: {} };
|
|
7
|
+
}
|
|
8
|
+
/** Resolves `(--x)`, `(color:--x)`, `(length:--x)`, `[var(--x)]`, or `[...]` values. */
|
|
9
|
+
function resolveDynamic(value, vars) {
|
|
10
|
+
const parsed = parseDynamicValue(value);
|
|
11
|
+
if (parsed === null)
|
|
12
|
+
return null;
|
|
13
|
+
if (vars !== undefined) {
|
|
14
|
+
if (parsed.isVar || hasMathFunction(parsed.expr)) {
|
|
15
|
+
const expanded = vars.expand(parsed.expr);
|
|
16
|
+
if (expanded === null)
|
|
17
|
+
return null;
|
|
18
|
+
return {
|
|
19
|
+
raw: expanded.value,
|
|
20
|
+
hint: parsed.hint,
|
|
21
|
+
isVar: parsed.isVar,
|
|
22
|
+
variable: expanded.variables[0],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (parsed.isVar) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return { raw: parsed.expr, hint: parsed.hint, isVar: false };
|
|
30
|
+
}
|
|
31
|
+
function roundPoints(n) {
|
|
32
|
+
const rounded = Math.round(n * 1e4) / 1e4;
|
|
33
|
+
return rounded === 0 ? 0 : rounded;
|
|
34
|
+
}
|
|
35
|
+
/** Parses a CSS length into points or a percentage. */
|
|
36
|
+
function parseLength(raw, viewport) {
|
|
37
|
+
const match = /^(-?\d*\.?\d+)(px|rem|em|pt|vw|vh|%)?$/.exec(raw.trim());
|
|
38
|
+
if (!match)
|
|
39
|
+
return null;
|
|
40
|
+
const value = Number(match[1]);
|
|
41
|
+
switch (match[2]) {
|
|
42
|
+
case '%':
|
|
43
|
+
return `${value}%`;
|
|
44
|
+
case 'rem':
|
|
45
|
+
case 'em':
|
|
46
|
+
return value * 16;
|
|
47
|
+
case 'vw':
|
|
48
|
+
return viewport === undefined ? MISSING_VIEWPORT : roundPoints((value / 100) * viewport.width);
|
|
49
|
+
case 'vh':
|
|
50
|
+
return viewport === undefined ? MISSING_VIEWPORT : roundPoints((value / 100) * viewport.height);
|
|
51
|
+
default:
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function negate(length, negative) {
|
|
56
|
+
if (!negative)
|
|
57
|
+
return length;
|
|
58
|
+
if (typeof length === 'number')
|
|
59
|
+
return length === 0 ? 0 : -length;
|
|
60
|
+
return length.startsWith('-') ? length.slice(1) : `-${length}`;
|
|
61
|
+
}
|
|
62
|
+
function isNumeric(value) {
|
|
63
|
+
return /^\d*\.?\d+$/.test(value);
|
|
64
|
+
}
|
|
65
|
+
function resolveBaseSpacing(spacing, vars, viewport) {
|
|
66
|
+
if (typeof spacing === 'number')
|
|
67
|
+
return spacing;
|
|
68
|
+
const expanded = vars?.expand(spacing);
|
|
69
|
+
if (vars?.hasError())
|
|
70
|
+
return null;
|
|
71
|
+
if (vars?.isMissingViewport?.())
|
|
72
|
+
return MISSING_VIEWPORT;
|
|
73
|
+
if (!expanded)
|
|
74
|
+
return null;
|
|
75
|
+
const length = parseLength(expanded.value, viewport);
|
|
76
|
+
if (length === MISSING_VIEWPORT)
|
|
77
|
+
return MISSING_VIEWPORT;
|
|
78
|
+
if (typeof length !== 'number') {
|
|
79
|
+
vars?.reportError({
|
|
80
|
+
kind: 'invalid',
|
|
81
|
+
variable: expanded.variables[0],
|
|
82
|
+
value: expanded.value,
|
|
83
|
+
expected: 'length',
|
|
84
|
+
});
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return length;
|
|
88
|
+
}
|
|
89
|
+
/** Resolves a spacing-scale value: `4`, `px`, `full`, `screen`, `1/2`, `[13px]`, `(--space)`, `md`, or `--spacing-*`. */
|
|
90
|
+
function spacingValue(value, tokens, negative, options = {}, vars, viewport) {
|
|
91
|
+
const dyn = resolveDynamic(value, vars);
|
|
92
|
+
if (vars?.hasError())
|
|
93
|
+
return null;
|
|
94
|
+
if (vars?.isMissingViewport?.())
|
|
95
|
+
return MISSING_VIEWPORT;
|
|
96
|
+
if (dyn !== null) {
|
|
97
|
+
if (dyn.hint === 'color')
|
|
98
|
+
return null;
|
|
99
|
+
const length = parseLength(dyn.raw, viewport);
|
|
100
|
+
if (length === MISSING_VIEWPORT)
|
|
101
|
+
return MISSING_VIEWPORT;
|
|
102
|
+
if (length === null) {
|
|
103
|
+
if (dyn.isVar)
|
|
104
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'length' });
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return negate(length, negative);
|
|
108
|
+
}
|
|
109
|
+
const scaleOverride = tokens.spacingScale !== undefined ? own(tokens.spacingScale, value) : undefined;
|
|
110
|
+
if (scaleOverride !== undefined) {
|
|
111
|
+
if (typeof scaleOverride === 'number')
|
|
112
|
+
return negate(scaleOverride, negative);
|
|
113
|
+
if (hasVarCall(scaleOverride)) {
|
|
114
|
+
const expanded = vars?.expand(scaleOverride);
|
|
115
|
+
if (vars?.hasError())
|
|
116
|
+
return null;
|
|
117
|
+
if (vars?.isMissingViewport?.())
|
|
118
|
+
return MISSING_VIEWPORT;
|
|
119
|
+
if (!expanded)
|
|
120
|
+
return null;
|
|
121
|
+
const length = parseLength(expanded.value, viewport);
|
|
122
|
+
if (length === MISSING_VIEWPORT)
|
|
123
|
+
return MISSING_VIEWPORT;
|
|
124
|
+
if (length === null) {
|
|
125
|
+
vars?.reportError({
|
|
126
|
+
kind: 'invalid',
|
|
127
|
+
variable: expanded.variables[0],
|
|
128
|
+
value: expanded.value,
|
|
129
|
+
expected: 'length',
|
|
130
|
+
});
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
return negate(length, negative);
|
|
134
|
+
}
|
|
135
|
+
const length = parseLength(scaleOverride, viewport);
|
|
136
|
+
if (length === MISSING_VIEWPORT)
|
|
137
|
+
return MISSING_VIEWPORT;
|
|
138
|
+
return length === null ? null : negate(length, negative);
|
|
139
|
+
}
|
|
140
|
+
if (value === 'px')
|
|
141
|
+
return negate(1, negative);
|
|
142
|
+
if (value === '0')
|
|
143
|
+
return 0;
|
|
144
|
+
if (isNumeric(value)) {
|
|
145
|
+
const step = resolveBaseSpacing(tokens.spacing, vars, viewport);
|
|
146
|
+
if (step === MISSING_VIEWPORT)
|
|
147
|
+
return MISSING_VIEWPORT;
|
|
148
|
+
if (step === null)
|
|
149
|
+
return null;
|
|
150
|
+
return negate(Number(value) * step, negative);
|
|
151
|
+
}
|
|
152
|
+
if (value === 'full')
|
|
153
|
+
return negate('100%', negative);
|
|
154
|
+
if (options.screen !== undefined && value === 'screen') {
|
|
155
|
+
if (viewport === undefined)
|
|
156
|
+
return MISSING_VIEWPORT;
|
|
157
|
+
return negate(viewport[options.screen], negative);
|
|
158
|
+
}
|
|
159
|
+
if (options.fraction !== false) {
|
|
160
|
+
const fraction = /^(\d+)\/(\d+)$/.exec(value);
|
|
161
|
+
if (fraction) {
|
|
162
|
+
const percent = (Number(fraction[1]) / Number(fraction[2])) * 100;
|
|
163
|
+
return negate(`${Math.round(percent * 1e4) / 1e4}%`, negative);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (options.container) {
|
|
167
|
+
const size = own(tokens.container, value);
|
|
168
|
+
if (size !== undefined) {
|
|
169
|
+
if (typeof size === 'number')
|
|
170
|
+
return size;
|
|
171
|
+
const expanded = vars?.expand(size);
|
|
172
|
+
if (vars?.hasError())
|
|
173
|
+
return null;
|
|
174
|
+
if (vars?.isMissingViewport?.())
|
|
175
|
+
return MISSING_VIEWPORT;
|
|
176
|
+
if (!expanded)
|
|
177
|
+
return null;
|
|
178
|
+
const length = parseLength(expanded.value, viewport);
|
|
179
|
+
if (length === MISSING_VIEWPORT)
|
|
180
|
+
return MISSING_VIEWPORT;
|
|
181
|
+
if (length === null) {
|
|
182
|
+
vars?.reportError({
|
|
183
|
+
kind: 'invalid',
|
|
184
|
+
variable: expanded.variables[0],
|
|
185
|
+
value: expanded.value,
|
|
186
|
+
expected: 'length',
|
|
187
|
+
});
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
return length;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (isValidTokenSuffix(value)) {
|
|
194
|
+
const varName = `--spacing-${value}`;
|
|
195
|
+
const ns = vars?.tryVariable(varName);
|
|
196
|
+
if (vars?.hasError())
|
|
197
|
+
return null;
|
|
198
|
+
if (vars?.isMissingViewport?.())
|
|
199
|
+
return MISSING_VIEWPORT;
|
|
200
|
+
if (ns) {
|
|
201
|
+
const length = parseLength(ns.value, viewport);
|
|
202
|
+
if (length === MISSING_VIEWPORT)
|
|
203
|
+
return MISSING_VIEWPORT;
|
|
204
|
+
if (length === null) {
|
|
205
|
+
vars?.reportError({
|
|
206
|
+
kind: 'invalid',
|
|
207
|
+
variable: ns.variables[0] ?? varName,
|
|
208
|
+
value: ns.value,
|
|
209
|
+
expected: 'length',
|
|
210
|
+
});
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
return negate(length, negative);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
/** Splits `red-500/50` into the color and its opacity modifier, ignoring `/` inside brackets or parentheses. */
|
|
219
|
+
function splitModifier(value) {
|
|
220
|
+
let bracketDepth = 0;
|
|
221
|
+
let parenDepth = 0;
|
|
222
|
+
for (let i = value.length - 1; i >= 0; i--) {
|
|
223
|
+
const char = value[i];
|
|
224
|
+
if (char === ']')
|
|
225
|
+
bracketDepth++;
|
|
226
|
+
else if (char === '[')
|
|
227
|
+
bracketDepth--;
|
|
228
|
+
else if (char === ')')
|
|
229
|
+
parenDepth++;
|
|
230
|
+
else if (char === '(')
|
|
231
|
+
parenDepth--;
|
|
232
|
+
else if (char === '/' && bracketDepth === 0 && parenDepth === 0) {
|
|
233
|
+
return [value.slice(0, i), value.slice(i + 1)];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return [value, undefined];
|
|
237
|
+
}
|
|
238
|
+
function parseAlpha(modifier, vars) {
|
|
239
|
+
const dyn = resolveDynamic(modifier, vars);
|
|
240
|
+
if (vars?.hasError())
|
|
241
|
+
return null;
|
|
242
|
+
if (dyn !== null) {
|
|
243
|
+
const raw = dyn.raw.trim();
|
|
244
|
+
const value = raw.endsWith('%') ? Number(raw.slice(0, -1)) / 100 : Number(raw);
|
|
245
|
+
if (raw === '' || !Number.isFinite(value)) {
|
|
246
|
+
if (dyn.isVar)
|
|
247
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'opacity' });
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
return value;
|
|
251
|
+
}
|
|
252
|
+
return isNumeric(modifier) ? Number(modifier) / 100 : null;
|
|
253
|
+
}
|
|
254
|
+
function own(record, key) {
|
|
255
|
+
return Object.prototype.hasOwnProperty.call(record, key) ? record[key] : undefined;
|
|
256
|
+
}
|
|
257
|
+
function isValidTokenSuffix(suffix) {
|
|
258
|
+
return suffix.length > 0 && !/[\s,()[\]/]/.test(suffix);
|
|
259
|
+
}
|
|
260
|
+
const NITRO_FONT_WEIGHTS = new Set(['regular', 'medium', 'semibold', 'bold']);
|
|
261
|
+
function parseFontWeightValue(raw, tokens) {
|
|
262
|
+
const trimmed = raw.trim();
|
|
263
|
+
if (NITRO_FONT_WEIGHTS.has(trimmed))
|
|
264
|
+
return trimmed;
|
|
265
|
+
const mapped = own(tokens.fontWeight, trimmed);
|
|
266
|
+
if (mapped !== undefined && !hasVarCall(mapped))
|
|
267
|
+
return mapped;
|
|
268
|
+
if (/^[1-9]00$/.test(trimmed))
|
|
269
|
+
return Number(trimmed);
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
function parseLeadingRaw(raw, viewport) {
|
|
273
|
+
const trimmed = raw.trim();
|
|
274
|
+
const length = parseLength(trimmed, viewport);
|
|
275
|
+
if (length === MISSING_VIEWPORT)
|
|
276
|
+
return MISSING_VIEWPORT;
|
|
277
|
+
// A unitless value is a multiplier, as in CSS: `leading-[1.3]` or `--leading-copy: 1.5`.
|
|
278
|
+
if (typeof length === 'number')
|
|
279
|
+
return /\d$/.test(trimmed) ? { multiplier: length } : { points: length };
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
/** Resolves `red-500`, `red-500/50`, `[#ff0]`, `(--brand)/(--o)`, `[rgb(0_0_0)]/25`, `brand`. */
|
|
283
|
+
function colorValue(value, tokens, vars) {
|
|
284
|
+
const [base, modifier] = splitModifier(value);
|
|
285
|
+
const dyn = resolveDynamic(base, vars);
|
|
286
|
+
if (vars?.hasError())
|
|
287
|
+
return null;
|
|
288
|
+
let color;
|
|
289
|
+
if (dyn !== null) {
|
|
290
|
+
if (dyn.hint === 'length')
|
|
291
|
+
return null;
|
|
292
|
+
color = parseColor(dyn.raw);
|
|
293
|
+
if (color === null && dyn.isVar) {
|
|
294
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'color' });
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
const token = own(tokens.colors, base);
|
|
300
|
+
if (token !== undefined) {
|
|
301
|
+
if (typeof token === 'number') {
|
|
302
|
+
color = token;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
const expanded = vars?.expand(token);
|
|
306
|
+
if (!expanded)
|
|
307
|
+
return null;
|
|
308
|
+
color = parseColor(expanded.value);
|
|
309
|
+
if (color === null) {
|
|
310
|
+
vars?.reportError({
|
|
311
|
+
kind: 'invalid',
|
|
312
|
+
variable: expanded.variables[0],
|
|
313
|
+
value: expanded.value,
|
|
314
|
+
expected: 'color',
|
|
315
|
+
});
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
else if (isValidTokenSuffix(base)) {
|
|
321
|
+
const varName = `--color-${base}`;
|
|
322
|
+
const ns = vars?.tryVariable(varName);
|
|
323
|
+
if (vars?.hasError())
|
|
324
|
+
return null;
|
|
325
|
+
if (ns) {
|
|
326
|
+
color = parseColor(ns.value);
|
|
327
|
+
if (color === null) {
|
|
328
|
+
vars?.reportError({
|
|
329
|
+
kind: 'invalid',
|
|
330
|
+
variable: ns.variables[0] ?? varName,
|
|
331
|
+
value: ns.value,
|
|
332
|
+
expected: 'color',
|
|
333
|
+
});
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (color == null)
|
|
340
|
+
return null;
|
|
341
|
+
if (modifier === undefined)
|
|
342
|
+
return { color, explicitAlpha: false };
|
|
343
|
+
const alpha = parseAlpha(modifier, vars);
|
|
344
|
+
if (alpha === null)
|
|
345
|
+
return null;
|
|
346
|
+
return { color: multiplyAlpha(color, alpha), explicitAlpha: true };
|
|
347
|
+
}
|
|
348
|
+
function numberValue(value, vars) {
|
|
349
|
+
const dyn = resolveDynamic(value, vars);
|
|
350
|
+
if (vars?.hasError())
|
|
351
|
+
return null;
|
|
352
|
+
if (dyn !== null) {
|
|
353
|
+
const raw = dyn.raw.trim();
|
|
354
|
+
const number = Number(raw.replace(/deg$/, ''));
|
|
355
|
+
if (raw === '' || !Number.isFinite(number)) {
|
|
356
|
+
if (dyn.isVar)
|
|
357
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'number' });
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
return number;
|
|
361
|
+
}
|
|
362
|
+
const number = Number(value.replace(/deg$/, ''));
|
|
363
|
+
return value !== '' && Number.isFinite(number) ? number : null;
|
|
364
|
+
}
|
|
365
|
+
// ---------------------------------------------------------------------------
|
|
366
|
+
// Handler factories
|
|
367
|
+
function spacingProps(target, keys, options) {
|
|
368
|
+
return (value, draft, tokens, negative, vars, viewport) => {
|
|
369
|
+
const length = options?.auto && value === 'auto' ? 'auto' : spacingValue(value, tokens, negative, options, vars, viewport);
|
|
370
|
+
if (length === MISSING_VIEWPORT)
|
|
371
|
+
return true;
|
|
372
|
+
if (length === null)
|
|
373
|
+
return false;
|
|
374
|
+
if (options?.clears) {
|
|
375
|
+
for (const key of options.clears)
|
|
376
|
+
delete draft[target][key];
|
|
377
|
+
}
|
|
378
|
+
for (const key of keys)
|
|
379
|
+
draft[target][key] = length;
|
|
380
|
+
return true;
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
const SIDE_CORNERS = {
|
|
384
|
+
t: ['topLeft', 'topRight'],
|
|
385
|
+
b: ['bottomLeft', 'bottomRight'],
|
|
386
|
+
l: ['topLeft', 'bottomLeft'],
|
|
387
|
+
r: ['topRight', 'bottomRight'],
|
|
388
|
+
s: ['topLeft', 'bottomLeft'],
|
|
389
|
+
e: ['topRight', 'bottomRight'],
|
|
390
|
+
tl: ['topLeft'],
|
|
391
|
+
tr: ['topRight'],
|
|
392
|
+
bl: ['bottomLeft'],
|
|
393
|
+
br: ['bottomRight'],
|
|
394
|
+
ss: ['topLeft'],
|
|
395
|
+
se: ['topRight'],
|
|
396
|
+
es: ['bottomLeft'],
|
|
397
|
+
ee: ['bottomRight'],
|
|
398
|
+
};
|
|
399
|
+
function rounded(side) {
|
|
400
|
+
return (value, draft, tokens, _negative, vars, viewport) => {
|
|
401
|
+
const dyn = resolveDynamic(value, vars);
|
|
402
|
+
if (vars?.hasError())
|
|
403
|
+
return false;
|
|
404
|
+
if (vars?.isMissingViewport?.())
|
|
405
|
+
return true;
|
|
406
|
+
let radius;
|
|
407
|
+
if (dyn !== null) {
|
|
408
|
+
if (dyn.hint === 'color')
|
|
409
|
+
return false;
|
|
410
|
+
radius = parseLength(dyn.raw, viewport);
|
|
411
|
+
if (radius === MISSING_VIEWPORT)
|
|
412
|
+
return true;
|
|
413
|
+
if (typeof radius !== 'number') {
|
|
414
|
+
if (dyn.isVar) {
|
|
415
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'length' });
|
|
416
|
+
}
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
const token = own(tokens.radius, value);
|
|
422
|
+
if (token !== undefined) {
|
|
423
|
+
if (typeof token === 'number') {
|
|
424
|
+
radius = token;
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
const expanded = vars?.expand(token);
|
|
428
|
+
if (vars?.isMissingViewport?.())
|
|
429
|
+
return true;
|
|
430
|
+
if (!expanded)
|
|
431
|
+
return false;
|
|
432
|
+
radius = parseLength(expanded.value, viewport);
|
|
433
|
+
if (radius === MISSING_VIEWPORT)
|
|
434
|
+
return true;
|
|
435
|
+
if (typeof radius !== 'number') {
|
|
436
|
+
vars?.reportError({
|
|
437
|
+
kind: 'invalid',
|
|
438
|
+
variable: expanded.variables[0],
|
|
439
|
+
value: expanded.value,
|
|
440
|
+
expected: 'length',
|
|
441
|
+
});
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
else if (isValidTokenSuffix(value)) {
|
|
447
|
+
const varName = `--radius-${value}`;
|
|
448
|
+
const ns = vars?.tryVariable(varName);
|
|
449
|
+
if (vars?.hasError())
|
|
450
|
+
return false;
|
|
451
|
+
if (vars?.isMissingViewport?.())
|
|
452
|
+
return true;
|
|
453
|
+
if (ns) {
|
|
454
|
+
radius = parseLength(ns.value, viewport);
|
|
455
|
+
if (radius === MISSING_VIEWPORT)
|
|
456
|
+
return true;
|
|
457
|
+
if (typeof radius !== 'number') {
|
|
458
|
+
vars?.reportError({
|
|
459
|
+
kind: 'invalid',
|
|
460
|
+
variable: ns.variables[0] ?? varName,
|
|
461
|
+
value: ns.value,
|
|
462
|
+
expected: 'length',
|
|
463
|
+
});
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if (typeof radius !== 'number')
|
|
470
|
+
return false;
|
|
471
|
+
draft.style.cornerRadius = radius;
|
|
472
|
+
if (side !== undefined) {
|
|
473
|
+
draft.corners ??= new Set();
|
|
474
|
+
for (const corner of SIDE_CORNERS[side])
|
|
475
|
+
draft.corners.add(corner);
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
draft.corners = undefined;
|
|
479
|
+
}
|
|
480
|
+
return true;
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
function transformNumber(key, scale, clears) {
|
|
484
|
+
return (value, draft, _tokens, negative, vars) => {
|
|
485
|
+
const number = numberValue(value, vars);
|
|
486
|
+
if (number === null)
|
|
487
|
+
return false;
|
|
488
|
+
if (clears) {
|
|
489
|
+
for (const cleared of clears)
|
|
490
|
+
delete draft.style[cleared];
|
|
491
|
+
}
|
|
492
|
+
const result = scale(number);
|
|
493
|
+
draft.style[key] = negative ? -result : result;
|
|
494
|
+
return true;
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function translate(keys) {
|
|
498
|
+
return (value, draft, tokens, negative, vars, viewport) => {
|
|
499
|
+
const length = spacingValue(value, tokens, negative, { fraction: false }, vars, viewport);
|
|
500
|
+
if (length === MISSING_VIEWPORT)
|
|
501
|
+
return true;
|
|
502
|
+
// NitroUI translations are in points; percentages of the view's own size aren't supported.
|
|
503
|
+
if (typeof length !== 'number')
|
|
504
|
+
return false;
|
|
505
|
+
for (const key of keys)
|
|
506
|
+
draft.style[key] = length;
|
|
507
|
+
return true;
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
/** Gradient directions in normalized view coordinates. */
|
|
511
|
+
const GRADIENT_DIRECTIONS = {
|
|
512
|
+
t: [0.5, 1, 0.5, 0],
|
|
513
|
+
tr: [0, 1, 1, 0],
|
|
514
|
+
r: [0, 0.5, 1, 0.5],
|
|
515
|
+
br: [0, 0, 1, 1],
|
|
516
|
+
b: [0.5, 0, 0.5, 1],
|
|
517
|
+
bl: [1, 0, 0, 1],
|
|
518
|
+
l: [1, 0.5, 0, 0.5],
|
|
519
|
+
tl: [1, 1, 0, 0],
|
|
520
|
+
};
|
|
521
|
+
const linearGradient = (value, draft, _tokens, negative, vars) => {
|
|
522
|
+
let points = value.startsWith('to-') ? GRADIENT_DIRECTIONS[value.slice(3)] : undefined;
|
|
523
|
+
if (!points) {
|
|
524
|
+
// `bg-linear-45` / `bg-linear-[30deg]`: CSS angles, 0deg points up, clockwise.
|
|
525
|
+
const angle = numberValue(value, vars);
|
|
526
|
+
if (angle === null)
|
|
527
|
+
return false;
|
|
528
|
+
const radians = ((negative ? -angle : angle) * Math.PI) / 180;
|
|
529
|
+
const dx = Math.sin(radians) / 2;
|
|
530
|
+
const dy = -Math.cos(radians) / 2;
|
|
531
|
+
points = [0.5 - dx, 0.5 - dy, 0.5 + dx, 0.5 + dy];
|
|
532
|
+
}
|
|
533
|
+
const [x1, y1, x2, y2] = points.map((n) => Math.round(n * 1e4) / 1e4);
|
|
534
|
+
draft.gradient = { ...draft.gradient, start: { x: x1, y: y1 }, end: { x: x2, y: y2 } };
|
|
535
|
+
return true;
|
|
536
|
+
};
|
|
537
|
+
function gradientStop(stop) {
|
|
538
|
+
return (value, draft, tokens, _negative, vars) => {
|
|
539
|
+
const color = colorValue(value, tokens, vars);
|
|
540
|
+
if (color === null)
|
|
541
|
+
return false;
|
|
542
|
+
draft.gradient = { ...draft.gradient, [stop]: color.color };
|
|
543
|
+
return true;
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
function shadowHandler(kind) {
|
|
547
|
+
return (value, draft, tokens, _negative, vars, viewport) => {
|
|
548
|
+
if (kind === 'shadow') {
|
|
549
|
+
const token = own(tokens.shadow, value);
|
|
550
|
+
if (token !== undefined) {
|
|
551
|
+
if (typeof token === 'string') {
|
|
552
|
+
const expanded = vars?.expand(token);
|
|
553
|
+
if (vars?.isMissingViewport?.())
|
|
554
|
+
return true;
|
|
555
|
+
if (!expanded)
|
|
556
|
+
return false;
|
|
557
|
+
const parsed = parseShadowList(expanded.value, false, viewport);
|
|
558
|
+
if (parsed === MISSING_VIEWPORT)
|
|
559
|
+
return true;
|
|
560
|
+
if (parsed === null) {
|
|
561
|
+
vars?.reportError({
|
|
562
|
+
kind: 'invalid',
|
|
563
|
+
variable: expanded.variables[0],
|
|
564
|
+
value: expanded.value,
|
|
565
|
+
expected: 'shadow',
|
|
566
|
+
});
|
|
567
|
+
return false;
|
|
568
|
+
}
|
|
569
|
+
draft.shadow = parsed;
|
|
570
|
+
return true;
|
|
571
|
+
}
|
|
572
|
+
draft.shadow = token;
|
|
573
|
+
return true;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
const layers = own(tokens.insetShadow, value);
|
|
578
|
+
if (layers !== undefined) {
|
|
579
|
+
if (typeof layers === 'string') {
|
|
580
|
+
const expanded = vars?.expand(layers);
|
|
581
|
+
if (vars?.isMissingViewport?.())
|
|
582
|
+
return true;
|
|
583
|
+
if (!expanded)
|
|
584
|
+
return false;
|
|
585
|
+
const parsed = parseShadowList(expanded.value, true, viewport);
|
|
586
|
+
if (parsed === MISSING_VIEWPORT)
|
|
587
|
+
return true;
|
|
588
|
+
if (parsed === null) {
|
|
589
|
+
vars?.reportError({
|
|
590
|
+
kind: 'invalid',
|
|
591
|
+
variable: expanded.variables[0],
|
|
592
|
+
value: expanded.value,
|
|
593
|
+
expected: 'shadow',
|
|
594
|
+
});
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
draft.insetShadow = parsed;
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
draft.insetShadow = layers;
|
|
601
|
+
return true;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const [base, modifier] = splitModifier(value);
|
|
605
|
+
const parsedDyn = parseDynamicValue(base);
|
|
606
|
+
if (parsedDyn !== null && parsedDyn.hint !== 'color') {
|
|
607
|
+
const dyn = resolveDynamic(value, vars);
|
|
608
|
+
if (vars?.hasError())
|
|
609
|
+
return false;
|
|
610
|
+
if (vars?.isMissingViewport?.())
|
|
611
|
+
return true;
|
|
612
|
+
if (dyn !== null) {
|
|
613
|
+
// `shadow-[0_4px_12px_rgb(0_0_0/0.2)]` or `shadow-(--my-shadow)`
|
|
614
|
+
const parsed = parseShadowList(dyn.raw, kind === 'insetShadow', viewport);
|
|
615
|
+
if (parsed === MISSING_VIEWPORT)
|
|
616
|
+
return true;
|
|
617
|
+
if (parsed !== null) {
|
|
618
|
+
draft[kind] = parsed;
|
|
619
|
+
return true;
|
|
620
|
+
}
|
|
621
|
+
if (dyn.hint === 'length') {
|
|
622
|
+
if (dyn.isVar) {
|
|
623
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'shadow' });
|
|
624
|
+
}
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
else if (parsedDyn === null && modifier === undefined && isValidTokenSuffix(value)) {
|
|
630
|
+
const varName = kind === 'shadow' ? `--shadow-${value}` : `--inset-shadow-${value}`;
|
|
631
|
+
const ns = vars?.tryVariable(varName);
|
|
632
|
+
if (vars?.hasError())
|
|
633
|
+
return false;
|
|
634
|
+
if (vars?.isMissingViewport?.())
|
|
635
|
+
return true;
|
|
636
|
+
if (ns) {
|
|
637
|
+
const parsed = parseShadowList(ns.value, kind === 'insetShadow', viewport);
|
|
638
|
+
if (parsed === MISSING_VIEWPORT)
|
|
639
|
+
return true;
|
|
640
|
+
if (parsed === null) {
|
|
641
|
+
vars?.reportError({
|
|
642
|
+
kind: 'invalid',
|
|
643
|
+
variable: ns.variables[0] ?? varName,
|
|
644
|
+
value: ns.value,
|
|
645
|
+
expected: 'shadow',
|
|
646
|
+
});
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
draft[kind] = parsed;
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const color = colorValue(value, tokens, vars);
|
|
654
|
+
if (color === null)
|
|
655
|
+
return false;
|
|
656
|
+
draft[kind === 'shadow' ? 'shadowColor' : 'insetShadowColor'] = color;
|
|
657
|
+
return true;
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
function splitTopLevelCommas(raw) {
|
|
661
|
+
const parts = [];
|
|
662
|
+
let depth = 0;
|
|
663
|
+
let start = 0;
|
|
664
|
+
for (let i = 0; i < raw.length; i++) {
|
|
665
|
+
const ch = raw[i];
|
|
666
|
+
if (ch === '(')
|
|
667
|
+
depth++;
|
|
668
|
+
else if (ch === ')')
|
|
669
|
+
depth = Math.max(0, depth - 1);
|
|
670
|
+
else if (ch === ',' && depth === 0) {
|
|
671
|
+
parts.push(raw.slice(start, i).trim());
|
|
672
|
+
start = i + 1;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
parts.push(raw.slice(start).trim());
|
|
676
|
+
return parts.filter(Boolean);
|
|
677
|
+
}
|
|
678
|
+
function parseShadowList(raw, inset, viewport) {
|
|
679
|
+
const trimmed = raw.trim();
|
|
680
|
+
if (trimmed === 'none')
|
|
681
|
+
return [];
|
|
682
|
+
const parts = splitTopLevelCommas(trimmed);
|
|
683
|
+
if (parts.length === 0)
|
|
684
|
+
return null;
|
|
685
|
+
const out = [];
|
|
686
|
+
for (const part of parts) {
|
|
687
|
+
const layer = parseShadow(part, inset, viewport);
|
|
688
|
+
if (layer === MISSING_VIEWPORT)
|
|
689
|
+
return MISSING_VIEWPORT;
|
|
690
|
+
if (layer === null)
|
|
691
|
+
return null;
|
|
692
|
+
out.push(layer);
|
|
693
|
+
}
|
|
694
|
+
return out;
|
|
695
|
+
}
|
|
696
|
+
function parseShadow(raw, inset, viewport) {
|
|
697
|
+
const colorStart = raw.search(/(rgb|hsl|oklch|#|black|white|transparent)/);
|
|
698
|
+
const head = (colorStart === -1 ? raw : raw.slice(0, colorStart)).trim().split(/\s+/).filter(Boolean);
|
|
699
|
+
const isInset = head[0] === 'inset';
|
|
700
|
+
const lengths = head.slice(isInset ? 1 : 0).map((part) => parseLength(part, viewport));
|
|
701
|
+
if (lengths.some((length) => length === MISSING_VIEWPORT))
|
|
702
|
+
return MISSING_VIEWPORT;
|
|
703
|
+
if (lengths.length < 2 || lengths.some((length) => typeof length !== 'number'))
|
|
704
|
+
return null;
|
|
705
|
+
const [offsetX, offsetY, blurRadius = 0, spreadDistance = 0] = lengths;
|
|
706
|
+
const color = colorStart === -1 ? 0x00000040 : parseColor(raw.slice(colorStart));
|
|
707
|
+
if (color === null)
|
|
708
|
+
return null;
|
|
709
|
+
return { offsetX: offsetX, offsetY: offsetY, blurRadius, spreadDistance, inset: inset || isInset, color };
|
|
710
|
+
}
|
|
711
|
+
function parseDropShadow(raw, viewport) {
|
|
712
|
+
let inner = raw.trim();
|
|
713
|
+
if (inner.toLowerCase().startsWith('drop-shadow(') && inner.endsWith(')')) {
|
|
714
|
+
inner = inner.slice('drop-shadow('.length, -1).trim();
|
|
715
|
+
}
|
|
716
|
+
const colorStart = inner.search(/(rgb|hsl|oklch|#|black|white|transparent)/);
|
|
717
|
+
const head = (colorStart === -1 ? inner : inner.slice(0, colorStart)).trim().split(/\s+/).filter(Boolean);
|
|
718
|
+
const lengths = head.map((part) => parseLength(part, viewport));
|
|
719
|
+
if (lengths.some((length) => length === MISSING_VIEWPORT))
|
|
720
|
+
return MISSING_VIEWPORT;
|
|
721
|
+
if (lengths.length < 2 || lengths.length > 3 || lengths.some((length) => typeof length !== 'number'))
|
|
722
|
+
return null;
|
|
723
|
+
const [offsetX, offsetY, blur = 0] = lengths;
|
|
724
|
+
const color = colorStart === -1 ? 0x00000040 : parseColor(inner.slice(colorStart));
|
|
725
|
+
if (color === null)
|
|
726
|
+
return null;
|
|
727
|
+
// CSS drop-shadow blur is twice the Gaussian standard deviation.
|
|
728
|
+
return { offsetX: offsetX, offsetY: offsetY, standardDeviation: blur / 2, color };
|
|
729
|
+
}
|
|
730
|
+
function parseDropShadowList(raw, viewport) {
|
|
731
|
+
const trimmed = raw.trim();
|
|
732
|
+
if (trimmed === 'none')
|
|
733
|
+
return [];
|
|
734
|
+
const parts = splitTopLevelCommas(trimmed);
|
|
735
|
+
if (parts.length === 0)
|
|
736
|
+
return null;
|
|
737
|
+
const out = [];
|
|
738
|
+
for (const part of parts) {
|
|
739
|
+
const layer = parseDropShadow(part, viewport);
|
|
740
|
+
if (layer === MISSING_VIEWPORT)
|
|
741
|
+
return MISSING_VIEWPORT;
|
|
742
|
+
if (layer === null)
|
|
743
|
+
return null;
|
|
744
|
+
out.push(layer);
|
|
745
|
+
}
|
|
746
|
+
return out;
|
|
747
|
+
}
|
|
748
|
+
const dropShadow = (value, draft, tokens, _negative, vars, viewport) => {
|
|
749
|
+
const layers = own(tokens.dropShadow, value);
|
|
750
|
+
if (layers !== undefined) {
|
|
751
|
+
if (typeof layers === 'string') {
|
|
752
|
+
const expanded = vars?.expand(layers);
|
|
753
|
+
if (vars?.isMissingViewport?.())
|
|
754
|
+
return true;
|
|
755
|
+
if (!expanded)
|
|
756
|
+
return false;
|
|
757
|
+
const parsed = parseDropShadowList(expanded.value, viewport);
|
|
758
|
+
if (parsed === MISSING_VIEWPORT)
|
|
759
|
+
return true;
|
|
760
|
+
if (parsed === null) {
|
|
761
|
+
vars?.reportError({
|
|
762
|
+
kind: 'invalid',
|
|
763
|
+
variable: expanded.variables[0],
|
|
764
|
+
value: expanded.value,
|
|
765
|
+
expected: 'drop-shadow',
|
|
766
|
+
});
|
|
767
|
+
return false;
|
|
768
|
+
}
|
|
769
|
+
draft.dropShadow = parsed;
|
|
770
|
+
return true;
|
|
771
|
+
}
|
|
772
|
+
draft.dropShadow = layers;
|
|
773
|
+
return true;
|
|
774
|
+
}
|
|
775
|
+
const dyn = resolveDynamic(value, vars);
|
|
776
|
+
if (vars?.hasError())
|
|
777
|
+
return false;
|
|
778
|
+
if (vars?.isMissingViewport?.())
|
|
779
|
+
return true;
|
|
780
|
+
if (dyn !== null) {
|
|
781
|
+
if (dyn.hint === 'color')
|
|
782
|
+
return false;
|
|
783
|
+
const parsed = parseDropShadowList(dyn.raw, viewport);
|
|
784
|
+
if (parsed === MISSING_VIEWPORT)
|
|
785
|
+
return true;
|
|
786
|
+
if (parsed !== null) {
|
|
787
|
+
draft.dropShadow = parsed;
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
if (dyn.isVar) {
|
|
791
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'drop-shadow' });
|
|
792
|
+
}
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
if (isValidTokenSuffix(value)) {
|
|
796
|
+
const varName = `--drop-shadow-${value}`;
|
|
797
|
+
const ns = vars?.tryVariable(varName);
|
|
798
|
+
if (vars?.hasError())
|
|
799
|
+
return false;
|
|
800
|
+
if (vars?.isMissingViewport?.())
|
|
801
|
+
return true;
|
|
802
|
+
if (ns) {
|
|
803
|
+
const parsed = parseDropShadowList(ns.value, viewport);
|
|
804
|
+
if (parsed === MISSING_VIEWPORT)
|
|
805
|
+
return true;
|
|
806
|
+
if (parsed === null) {
|
|
807
|
+
vars?.reportError({
|
|
808
|
+
kind: 'invalid',
|
|
809
|
+
variable: ns.variables[0] ?? varName,
|
|
810
|
+
value: ns.value,
|
|
811
|
+
expected: 'drop-shadow',
|
|
812
|
+
});
|
|
813
|
+
return false;
|
|
814
|
+
}
|
|
815
|
+
draft.dropShadow = parsed;
|
|
816
|
+
return true;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return false;
|
|
820
|
+
};
|
|
821
|
+
function colorProp(target, key) {
|
|
822
|
+
return (value, draft, tokens, _negative, vars) => {
|
|
823
|
+
const color = colorValue(value, tokens, vars);
|
|
824
|
+
if (color === null)
|
|
825
|
+
return false;
|
|
826
|
+
draft[target][key] = color.color;
|
|
827
|
+
return true;
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
function applyFontSize(draft, fontSize, sizeLineHeight, leadingModifier, tokens, vars, viewport) {
|
|
831
|
+
if (leadingModifier !== undefined) {
|
|
832
|
+
const result = leadingValue(leadingModifier, tokens, vars, viewport);
|
|
833
|
+
if (result === MISSING_VIEWPORT) {
|
|
834
|
+
draft.text.fontSize = fontSize;
|
|
835
|
+
draft.sizeLineHeight = sizeLineHeight;
|
|
836
|
+
return true;
|
|
837
|
+
}
|
|
838
|
+
if (result === null)
|
|
839
|
+
return false;
|
|
840
|
+
draft.text.fontSize = fontSize;
|
|
841
|
+
draft.sizeLineHeight = sizeLineHeight;
|
|
842
|
+
draft.leading = result;
|
|
843
|
+
return true;
|
|
844
|
+
}
|
|
845
|
+
draft.text.fontSize = fontSize;
|
|
846
|
+
draft.sizeLineHeight = sizeLineHeight;
|
|
847
|
+
delete draft.leading;
|
|
848
|
+
return true;
|
|
849
|
+
}
|
|
850
|
+
const textUtility = (value, draft, tokens, _negative, vars, viewport) => {
|
|
851
|
+
// `text-lg`, `text-lg/7`, `text-[15px]`, `text-(length:--size)`, `text-(color:--ink)`, `text-(--x)` (color default).
|
|
852
|
+
const [size, leadingModifier] = splitModifier(value);
|
|
853
|
+
const parsedDyn = parseDynamicValue(size);
|
|
854
|
+
if (parsedDyn !== null) {
|
|
855
|
+
if (parsedDyn.hint === 'color' ||
|
|
856
|
+
(parsedDyn.hint === null && parsedDyn.isVar && !isMathExpression(parsedDyn.expr))) {
|
|
857
|
+
return colorProp('text', 'color')(value, draft, tokens, false, vars, viewport);
|
|
858
|
+
}
|
|
859
|
+
const dyn = resolveDynamic(size, vars);
|
|
860
|
+
if (vars?.hasError())
|
|
861
|
+
return false;
|
|
862
|
+
if (vars?.isMissingViewport?.())
|
|
863
|
+
return true;
|
|
864
|
+
if (dyn !== null) {
|
|
865
|
+
const rawLength = parseLength(dyn.raw, viewport);
|
|
866
|
+
if (rawLength === MISSING_VIEWPORT)
|
|
867
|
+
return true;
|
|
868
|
+
if (typeof rawLength === 'number') {
|
|
869
|
+
return applyFontSize(draft, rawLength, undefined, leadingModifier, tokens, vars, viewport);
|
|
870
|
+
}
|
|
871
|
+
if (dyn.hint === 'length') {
|
|
872
|
+
if (dyn.isVar) {
|
|
873
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'length' });
|
|
874
|
+
}
|
|
875
|
+
return false;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
return colorProp('text', 'color')(value, draft, tokens, false, vars, viewport);
|
|
879
|
+
}
|
|
880
|
+
const tokenSize = own(tokens.fontSize, size);
|
|
881
|
+
if (tokenSize !== undefined) {
|
|
882
|
+
if (typeof tokenSize === 'string') {
|
|
883
|
+
const expanded = vars?.expand(tokenSize);
|
|
884
|
+
if (vars?.isMissingViewport?.())
|
|
885
|
+
return true;
|
|
886
|
+
if (!expanded)
|
|
887
|
+
return false;
|
|
888
|
+
const rawLength = parseLength(expanded.value, viewport);
|
|
889
|
+
if (rawLength === MISSING_VIEWPORT)
|
|
890
|
+
return true;
|
|
891
|
+
if (typeof rawLength !== 'number') {
|
|
892
|
+
vars?.reportError({
|
|
893
|
+
kind: 'invalid',
|
|
894
|
+
variable: expanded.variables[0],
|
|
895
|
+
value: expanded.value,
|
|
896
|
+
expected: 'length',
|
|
897
|
+
});
|
|
898
|
+
return false;
|
|
899
|
+
}
|
|
900
|
+
return applyFontSize(draft, rawLength, undefined, leadingModifier, tokens, vars, viewport);
|
|
901
|
+
}
|
|
902
|
+
let resolvedFontSize;
|
|
903
|
+
if (typeof tokenSize.fontSize === 'string') {
|
|
904
|
+
const expanded = vars?.expand(tokenSize.fontSize);
|
|
905
|
+
if (vars?.isMissingViewport?.())
|
|
906
|
+
return true;
|
|
907
|
+
if (!expanded)
|
|
908
|
+
return false;
|
|
909
|
+
const rawLength = parseLength(expanded.value, viewport);
|
|
910
|
+
if (rawLength === MISSING_VIEWPORT)
|
|
911
|
+
return true;
|
|
912
|
+
if (typeof rawLength !== 'number') {
|
|
913
|
+
vars?.reportError({
|
|
914
|
+
kind: 'invalid',
|
|
915
|
+
variable: expanded.variables[0],
|
|
916
|
+
value: expanded.value,
|
|
917
|
+
expected: 'length',
|
|
918
|
+
});
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
921
|
+
resolvedFontSize = rawLength;
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
924
|
+
resolvedFontSize = tokenSize.fontSize;
|
|
925
|
+
}
|
|
926
|
+
let resolvedLineHeight;
|
|
927
|
+
if (leadingModifier === undefined && tokenSize.lineHeight !== undefined) {
|
|
928
|
+
if (typeof tokenSize.lineHeight === 'string') {
|
|
929
|
+
const expanded = vars?.expand(tokenSize.lineHeight);
|
|
930
|
+
if (vars?.isMissingViewport?.())
|
|
931
|
+
return true;
|
|
932
|
+
if (!expanded)
|
|
933
|
+
return false;
|
|
934
|
+
const parsed = parseLeadingRaw(expanded.value, viewport);
|
|
935
|
+
if (parsed === MISSING_VIEWPORT)
|
|
936
|
+
return true;
|
|
937
|
+
if (parsed === null) {
|
|
938
|
+
vars?.reportError({
|
|
939
|
+
kind: 'invalid',
|
|
940
|
+
variable: expanded.variables[0],
|
|
941
|
+
value: expanded.value,
|
|
942
|
+
expected: 'length',
|
|
943
|
+
});
|
|
944
|
+
return false;
|
|
945
|
+
}
|
|
946
|
+
resolvedLineHeight =
|
|
947
|
+
'points' in parsed ? parsed.points : Math.round(resolvedFontSize * parsed.multiplier * 1000) / 1000;
|
|
948
|
+
}
|
|
949
|
+
else {
|
|
950
|
+
resolvedLineHeight = tokenSize.lineHeight;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
return applyFontSize(draft, resolvedFontSize, resolvedLineHeight, leadingModifier, tokens, vars, viewport);
|
|
954
|
+
}
|
|
955
|
+
if (isValidTokenSuffix(size)) {
|
|
956
|
+
const varName = `--text-${size}`;
|
|
957
|
+
const ns = vars?.tryVariable(varName);
|
|
958
|
+
if (vars?.hasError())
|
|
959
|
+
return false;
|
|
960
|
+
if (vars?.isMissingViewport?.())
|
|
961
|
+
return true;
|
|
962
|
+
if (ns) {
|
|
963
|
+
const rawLength = parseLength(ns.value, viewport);
|
|
964
|
+
if (rawLength === MISSING_VIEWPORT)
|
|
965
|
+
return true;
|
|
966
|
+
if (typeof rawLength !== 'number') {
|
|
967
|
+
vars?.reportError({
|
|
968
|
+
kind: 'invalid',
|
|
969
|
+
variable: ns.variables[0] ?? varName,
|
|
970
|
+
value: ns.value,
|
|
971
|
+
expected: 'length',
|
|
972
|
+
});
|
|
973
|
+
return false;
|
|
974
|
+
}
|
|
975
|
+
return applyFontSize(draft, rawLength, undefined, leadingModifier, tokens, vars, viewport);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return colorProp('text', 'color')(value, draft, tokens, false, vars, viewport);
|
|
979
|
+
};
|
|
980
|
+
function leadingValue(value, tokens, vars, viewport) {
|
|
981
|
+
const named = own(tokens.leading, value);
|
|
982
|
+
if (named !== undefined) {
|
|
983
|
+
if (typeof named === 'number')
|
|
984
|
+
return { multiplier: named };
|
|
985
|
+
if (typeof named === 'object')
|
|
986
|
+
return { points: named.points };
|
|
987
|
+
const expanded = vars?.expand(named);
|
|
988
|
+
if (vars?.isMissingViewport?.())
|
|
989
|
+
return MISSING_VIEWPORT;
|
|
990
|
+
if (!expanded)
|
|
991
|
+
return null;
|
|
992
|
+
const parsed = parseLeadingRaw(expanded.value, viewport);
|
|
993
|
+
if (parsed === MISSING_VIEWPORT)
|
|
994
|
+
return MISSING_VIEWPORT;
|
|
995
|
+
if (parsed === null) {
|
|
996
|
+
vars?.reportError({ kind: 'invalid', variable: expanded.variables[0], value: expanded.value, expected: 'length' });
|
|
997
|
+
return null;
|
|
998
|
+
}
|
|
999
|
+
return parsed;
|
|
1000
|
+
}
|
|
1001
|
+
if (value === 'none')
|
|
1002
|
+
return { multiplier: 1 };
|
|
1003
|
+
if (isNumeric(value)) {
|
|
1004
|
+
const step = resolveBaseSpacing(tokens.spacing, vars, viewport);
|
|
1005
|
+
if (step === MISSING_VIEWPORT)
|
|
1006
|
+
return MISSING_VIEWPORT;
|
|
1007
|
+
if (step === null)
|
|
1008
|
+
return null;
|
|
1009
|
+
return { points: Number(value) * step };
|
|
1010
|
+
}
|
|
1011
|
+
const dyn = resolveDynamic(value, vars);
|
|
1012
|
+
if (vars?.hasError())
|
|
1013
|
+
return null;
|
|
1014
|
+
if (vars?.isMissingViewport?.())
|
|
1015
|
+
return MISSING_VIEWPORT;
|
|
1016
|
+
if (dyn !== null) {
|
|
1017
|
+
if (dyn.hint === 'color')
|
|
1018
|
+
return null;
|
|
1019
|
+
const parsed = parseLeadingRaw(dyn.raw, viewport);
|
|
1020
|
+
if (parsed === MISSING_VIEWPORT)
|
|
1021
|
+
return MISSING_VIEWPORT;
|
|
1022
|
+
if (parsed !== null)
|
|
1023
|
+
return parsed;
|
|
1024
|
+
if (dyn.isVar)
|
|
1025
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'length' });
|
|
1026
|
+
return null;
|
|
1027
|
+
}
|
|
1028
|
+
if (isValidTokenSuffix(value)) {
|
|
1029
|
+
const varName = `--leading-${value}`;
|
|
1030
|
+
const ns = vars?.tryVariable(varName);
|
|
1031
|
+
if (vars?.hasError())
|
|
1032
|
+
return null;
|
|
1033
|
+
if (vars?.isMissingViewport?.())
|
|
1034
|
+
return MISSING_VIEWPORT;
|
|
1035
|
+
if (ns) {
|
|
1036
|
+
const parsed = parseLeadingRaw(ns.value, viewport);
|
|
1037
|
+
if (parsed === MISSING_VIEWPORT)
|
|
1038
|
+
return MISSING_VIEWPORT;
|
|
1039
|
+
if (parsed !== null)
|
|
1040
|
+
return parsed;
|
|
1041
|
+
vars?.reportError({ kind: 'invalid', variable: ns.variables[0] ?? varName, value: ns.value, expected: 'length' });
|
|
1042
|
+
return null;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
return null;
|
|
1046
|
+
}
|
|
1047
|
+
const leading = (value, draft, tokens, _negative, vars, viewport) => {
|
|
1048
|
+
const result = leadingValue(value, tokens, vars, viewport);
|
|
1049
|
+
if (result === MISSING_VIEWPORT)
|
|
1050
|
+
return true;
|
|
1051
|
+
if (result === null)
|
|
1052
|
+
return false;
|
|
1053
|
+
draft.leading = result;
|
|
1054
|
+
return true;
|
|
1055
|
+
};
|
|
1056
|
+
const border = (value, draft, tokens, _negative, vars, viewport) => {
|
|
1057
|
+
const [base] = splitModifier(value);
|
|
1058
|
+
const parsedDyn = parseDynamicValue(base);
|
|
1059
|
+
if (parsedDyn !== null) {
|
|
1060
|
+
if (parsedDyn.hint === 'color' ||
|
|
1061
|
+
(parsedDyn.hint === null && parsedDyn.isVar && !isMathExpression(parsedDyn.expr))) {
|
|
1062
|
+
return colorProp('style', 'borderColor')(value, draft, tokens, false, vars, viewport);
|
|
1063
|
+
}
|
|
1064
|
+
const dyn = resolveDynamic(value, vars);
|
|
1065
|
+
if (vars?.hasError())
|
|
1066
|
+
return false;
|
|
1067
|
+
if (vars?.isMissingViewport?.())
|
|
1068
|
+
return true;
|
|
1069
|
+
if (dyn !== null) {
|
|
1070
|
+
const width = parseLength(dyn.raw, viewport);
|
|
1071
|
+
if (width === MISSING_VIEWPORT)
|
|
1072
|
+
return true;
|
|
1073
|
+
if (typeof width === 'number') {
|
|
1074
|
+
draft.layout.borderWidth = width;
|
|
1075
|
+
return true;
|
|
1076
|
+
}
|
|
1077
|
+
if (dyn.hint === 'length') {
|
|
1078
|
+
if (dyn.isVar) {
|
|
1079
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'length' });
|
|
1080
|
+
}
|
|
1081
|
+
return false;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
return colorProp('style', 'borderColor')(value, draft, tokens, false, vars, viewport);
|
|
1085
|
+
}
|
|
1086
|
+
if (isNumeric(value)) {
|
|
1087
|
+
draft.layout.borderWidth = Number(value);
|
|
1088
|
+
return true;
|
|
1089
|
+
}
|
|
1090
|
+
return colorProp('style', 'borderColor')(value, draft, tokens, false, vars, viewport);
|
|
1091
|
+
};
|
|
1092
|
+
function numberProp(target, key, scale = (n) => n, clears) {
|
|
1093
|
+
return (value, draft, _tokens, _negative, vars) => {
|
|
1094
|
+
const number = numberValue(value, vars);
|
|
1095
|
+
if (number === null)
|
|
1096
|
+
return false;
|
|
1097
|
+
if (clears) {
|
|
1098
|
+
for (const cleared of clears)
|
|
1099
|
+
delete draft[target][cleared];
|
|
1100
|
+
}
|
|
1101
|
+
draft[target][key] = scale(number);
|
|
1102
|
+
return true;
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
const opacityHandler = (value, draft, _tokens, _negative, vars) => {
|
|
1106
|
+
if (parseDynamicValue(value) !== null) {
|
|
1107
|
+
const alpha = parseAlpha(value, vars);
|
|
1108
|
+
if (alpha === null)
|
|
1109
|
+
return false;
|
|
1110
|
+
draft.style.opacity = alpha;
|
|
1111
|
+
return true;
|
|
1112
|
+
}
|
|
1113
|
+
const number = numberValue(value, vars);
|
|
1114
|
+
if (number === null)
|
|
1115
|
+
return false;
|
|
1116
|
+
draft.style.opacity = number / 100;
|
|
1117
|
+
return true;
|
|
1118
|
+
};
|
|
1119
|
+
const aspect = (value, draft, tokens, _negative, vars) => {
|
|
1120
|
+
const named = own(tokens.aspect, value);
|
|
1121
|
+
if (named !== undefined) {
|
|
1122
|
+
if (typeof named === 'number') {
|
|
1123
|
+
draft.layout.aspectRatio = named;
|
|
1124
|
+
return true;
|
|
1125
|
+
}
|
|
1126
|
+
const expanded = vars?.expand(named);
|
|
1127
|
+
if (!expanded)
|
|
1128
|
+
return false;
|
|
1129
|
+
const raw = expanded.value.trim();
|
|
1130
|
+
const ratio = /^(\d*\.?\d+)\s*\/\s*(\d*\.?\d+)$/.exec(raw);
|
|
1131
|
+
const result = ratio ? Number(ratio[1]) / Number(ratio[2]) : Number(raw);
|
|
1132
|
+
if (raw === '' || !Number.isFinite(result)) {
|
|
1133
|
+
vars?.reportError({
|
|
1134
|
+
kind: 'invalid',
|
|
1135
|
+
variable: expanded.variables[0],
|
|
1136
|
+
value: expanded.value,
|
|
1137
|
+
expected: 'aspect ratio',
|
|
1138
|
+
});
|
|
1139
|
+
return false;
|
|
1140
|
+
}
|
|
1141
|
+
draft.layout.aspectRatio = result;
|
|
1142
|
+
return true;
|
|
1143
|
+
}
|
|
1144
|
+
const dyn = resolveDynamic(value, vars);
|
|
1145
|
+
if (vars?.hasError())
|
|
1146
|
+
return false;
|
|
1147
|
+
const raw = dyn !== null ? dyn.raw.trim() : value;
|
|
1148
|
+
const ratio = /^(\d*\.?\d+)\s*\/\s*(\d*\.?\d+)$/.exec(raw);
|
|
1149
|
+
const result = ratio ? Number(ratio[1]) / Number(ratio[2]) : Number(raw);
|
|
1150
|
+
if (raw === '' || !Number.isFinite(result)) {
|
|
1151
|
+
if (dyn?.isVar) {
|
|
1152
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'aspect ratio' });
|
|
1153
|
+
}
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
draft.layout.aspectRatio = result;
|
|
1157
|
+
return true;
|
|
1158
|
+
};
|
|
1159
|
+
const fontWeight = (value, draft, tokens, _negative, vars) => {
|
|
1160
|
+
const weight = own(tokens.fontWeight, value);
|
|
1161
|
+
if (weight !== undefined) {
|
|
1162
|
+
if (!hasVarCall(weight)) {
|
|
1163
|
+
draft.text.fontWeight = weight;
|
|
1164
|
+
return true;
|
|
1165
|
+
}
|
|
1166
|
+
const expanded = vars?.expand(weight);
|
|
1167
|
+
if (!expanded)
|
|
1168
|
+
return false;
|
|
1169
|
+
const parsed = parseFontWeightValue(expanded.value, tokens);
|
|
1170
|
+
if (parsed === null) {
|
|
1171
|
+
vars?.reportError({
|
|
1172
|
+
kind: 'invalid',
|
|
1173
|
+
variable: expanded.variables[0],
|
|
1174
|
+
value: expanded.value,
|
|
1175
|
+
expected: 'fontWeight',
|
|
1176
|
+
});
|
|
1177
|
+
return false;
|
|
1178
|
+
}
|
|
1179
|
+
draft.text.fontWeight = parsed;
|
|
1180
|
+
return true;
|
|
1181
|
+
}
|
|
1182
|
+
const dyn = resolveDynamic(value, vars);
|
|
1183
|
+
if (vars?.hasError())
|
|
1184
|
+
return false;
|
|
1185
|
+
if (dyn !== null) {
|
|
1186
|
+
const parsed = parseFontWeightValue(dyn.raw, tokens);
|
|
1187
|
+
if (parsed !== null) {
|
|
1188
|
+
draft.text.fontWeight = parsed;
|
|
1189
|
+
return true;
|
|
1190
|
+
}
|
|
1191
|
+
if (dyn.isVar) {
|
|
1192
|
+
vars?.reportError({ kind: 'invalid', variable: dyn.variable, value: dyn.raw, expected: 'fontWeight' });
|
|
1193
|
+
}
|
|
1194
|
+
return false;
|
|
1195
|
+
}
|
|
1196
|
+
if (isValidTokenSuffix(value)) {
|
|
1197
|
+
const varName = `--font-weight-${value}`;
|
|
1198
|
+
const ns = vars?.tryVariable(varName);
|
|
1199
|
+
if (vars?.hasError())
|
|
1200
|
+
return false;
|
|
1201
|
+
if (ns) {
|
|
1202
|
+
const parsed = parseFontWeightValue(ns.value, tokens);
|
|
1203
|
+
if (parsed !== null) {
|
|
1204
|
+
draft.text.fontWeight = parsed;
|
|
1205
|
+
return true;
|
|
1206
|
+
}
|
|
1207
|
+
vars?.reportError({
|
|
1208
|
+
kind: 'invalid',
|
|
1209
|
+
variable: ns.variables[0] ?? varName,
|
|
1210
|
+
value: ns.value,
|
|
1211
|
+
expected: 'fontWeight',
|
|
1212
|
+
});
|
|
1213
|
+
return false;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
return false;
|
|
1217
|
+
};
|
|
1218
|
+
const lineClamp = (value, draft, _tokens, _negative, vars) => {
|
|
1219
|
+
if (value === 'none') {
|
|
1220
|
+
draft.text.numberOfLines = 0;
|
|
1221
|
+
return true;
|
|
1222
|
+
}
|
|
1223
|
+
const lines = numberValue(value, vars);
|
|
1224
|
+
if (lines === null)
|
|
1225
|
+
return false;
|
|
1226
|
+
draft.text.numberOfLines = lines;
|
|
1227
|
+
draft.text.ellipsizeMode = 'tail';
|
|
1228
|
+
return true;
|
|
1229
|
+
};
|
|
1230
|
+
const set = (target, values, clears) => (draft) => {
|
|
1231
|
+
if (clears) {
|
|
1232
|
+
for (const key of clears)
|
|
1233
|
+
delete draft[target][key];
|
|
1234
|
+
}
|
|
1235
|
+
Object.assign(draft[target], values);
|
|
1236
|
+
};
|
|
1237
|
+
/** Classes that take no value. */
|
|
1238
|
+
export const staticUtilities = {
|
|
1239
|
+
// Every NitroUI view is a flex container, so `flex` itself has nothing to do.
|
|
1240
|
+
flex: () => { },
|
|
1241
|
+
'flex-row': set('layout', { flexDirection: 'row' }),
|
|
1242
|
+
'flex-row-reverse': set('layout', { flexDirection: 'row-reverse' }),
|
|
1243
|
+
'flex-col': set('layout', { flexDirection: 'column' }),
|
|
1244
|
+
'flex-col-reverse': set('layout', { flexDirection: 'column-reverse' }),
|
|
1245
|
+
'flex-wrap': set('layout', { flexWrap: 'wrap' }),
|
|
1246
|
+
'flex-wrap-reverse': set('layout', { flexWrap: 'wrap-reverse' }),
|
|
1247
|
+
'flex-nowrap': set('layout', { flexWrap: 'nowrap' }),
|
|
1248
|
+
'flex-auto': set('layout', { flexGrow: 1, flexShrink: 1 }, ['flex']),
|
|
1249
|
+
'flex-initial': set('layout', { flexGrow: 0, flexShrink: 1 }, ['flex']),
|
|
1250
|
+
'flex-none': set('layout', { flexGrow: 0, flexShrink: 0 }, ['flex']),
|
|
1251
|
+
grow: set('layout', { flexGrow: 1 }),
|
|
1252
|
+
shrink: set('layout', { flexShrink: 1 }),
|
|
1253
|
+
'justify-start': set('layout', { justifyContent: 'flex-start' }),
|
|
1254
|
+
'justify-end': set('layout', { justifyContent: 'flex-end' }),
|
|
1255
|
+
'justify-center': set('layout', { justifyContent: 'center' }),
|
|
1256
|
+
'justify-between': set('layout', { justifyContent: 'space-between' }),
|
|
1257
|
+
'justify-around': set('layout', { justifyContent: 'space-around' }),
|
|
1258
|
+
'justify-evenly': set('layout', { justifyContent: 'space-evenly' }),
|
|
1259
|
+
'items-start': set('layout', { alignItems: 'flex-start' }),
|
|
1260
|
+
'items-end': set('layout', { alignItems: 'flex-end' }),
|
|
1261
|
+
'items-center': set('layout', { alignItems: 'center' }),
|
|
1262
|
+
'items-stretch': set('layout', { alignItems: 'stretch' }),
|
|
1263
|
+
'items-baseline': set('layout', { alignItems: 'baseline' }),
|
|
1264
|
+
'self-auto': set('layout', { alignSelf: 'auto' }),
|
|
1265
|
+
'self-start': set('layout', { alignSelf: 'flex-start' }),
|
|
1266
|
+
'self-end': set('layout', { alignSelf: 'flex-end' }),
|
|
1267
|
+
'self-center': set('layout', { alignSelf: 'center' }),
|
|
1268
|
+
'self-stretch': set('layout', { alignSelf: 'stretch' }),
|
|
1269
|
+
'self-baseline': set('layout', { alignSelf: 'baseline' }),
|
|
1270
|
+
absolute: set('layout', { position: 'absolute' }),
|
|
1271
|
+
relative: set('layout', { position: 'relative' }),
|
|
1272
|
+
static: set('layout', { position: 'static' }),
|
|
1273
|
+
'overflow-visible': set('layout', { overflow: 'visible' }),
|
|
1274
|
+
'overflow-hidden': set('layout', { overflow: 'hidden' }),
|
|
1275
|
+
'overflow-clip': set('layout', { overflow: 'hidden' }),
|
|
1276
|
+
'overflow-scroll': set('layout', { overflow: 'scroll' }),
|
|
1277
|
+
// Corner curve (NitroWind addition): `continuous` is the iOS squircle.
|
|
1278
|
+
'corner-continuous': set('style', { cornerCurve: 'continuous' }),
|
|
1279
|
+
'corner-circular': set('style', { cornerCurve: 'circular' }),
|
|
1280
|
+
squircle: set('style', { cornerCurve: 'continuous' }),
|
|
1281
|
+
'text-left': set('text', { textAlign: 'start' }),
|
|
1282
|
+
'text-start': set('text', { textAlign: 'start' }),
|
|
1283
|
+
'text-center': set('text', { textAlign: 'center' }),
|
|
1284
|
+
'text-right': set('text', { textAlign: 'end' }),
|
|
1285
|
+
'text-end': set('text', { textAlign: 'end' }),
|
|
1286
|
+
'text-justify': set('text', { textAlign: 'justify' }),
|
|
1287
|
+
truncate: set('text', { numberOfLines: 1, ellipsizeMode: 'tail' }),
|
|
1288
|
+
'text-ellipsis': set('text', { ellipsizeMode: 'tail' }),
|
|
1289
|
+
'text-clip': set('text', { ellipsizeMode: 'clip' }),
|
|
1290
|
+
};
|
|
1291
|
+
/** Classes that take a value, keyed by prefix (`p` in `p-4`). The empty value is the bare class (`rounded`). */
|
|
1292
|
+
export const functionalUtilities = {
|
|
1293
|
+
// Spacing
|
|
1294
|
+
p: spacingProps('layout', ['padding'], {
|
|
1295
|
+
clears: ['paddingHorizontal', 'paddingVertical', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'],
|
|
1296
|
+
}),
|
|
1297
|
+
px: spacingProps('layout', ['paddingHorizontal'], { clears: ['paddingLeft', 'paddingRight'] }),
|
|
1298
|
+
py: spacingProps('layout', ['paddingVertical'], { clears: ['paddingTop', 'paddingBottom'] }),
|
|
1299
|
+
pt: spacingProps('layout', ['paddingTop']),
|
|
1300
|
+
pr: spacingProps('layout', ['paddingRight']),
|
|
1301
|
+
pb: spacingProps('layout', ['paddingBottom']),
|
|
1302
|
+
pl: spacingProps('layout', ['paddingLeft']),
|
|
1303
|
+
m: spacingProps('layout', ['margin'], {
|
|
1304
|
+
auto: true,
|
|
1305
|
+
clears: ['marginHorizontal', 'marginVertical', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft'],
|
|
1306
|
+
}),
|
|
1307
|
+
mx: spacingProps('layout', ['marginHorizontal'], { auto: true, clears: ['marginLeft', 'marginRight'] }),
|
|
1308
|
+
my: spacingProps('layout', ['marginVertical'], { auto: true, clears: ['marginTop', 'marginBottom'] }),
|
|
1309
|
+
mt: spacingProps('layout', ['marginTop'], { auto: true }),
|
|
1310
|
+
mr: spacingProps('layout', ['marginRight'], { auto: true }),
|
|
1311
|
+
mb: spacingProps('layout', ['marginBottom'], { auto: true }),
|
|
1312
|
+
ml: spacingProps('layout', ['marginLeft'], { auto: true }),
|
|
1313
|
+
gap: spacingProps('layout', ['gap'], { clears: ['columnGap', 'rowGap'] }),
|
|
1314
|
+
'gap-x': spacingProps('layout', ['columnGap']),
|
|
1315
|
+
'gap-y': spacingProps('layout', ['rowGap']),
|
|
1316
|
+
// Sizing
|
|
1317
|
+
w: spacingProps('layout', ['width'], { container: true, screen: 'width' }),
|
|
1318
|
+
h: spacingProps('layout', ['height'], { screen: 'height' }),
|
|
1319
|
+
size: spacingProps('layout', ['width', 'height']),
|
|
1320
|
+
'min-w': spacingProps('layout', ['minWidth'], { container: true, screen: 'width' }),
|
|
1321
|
+
'min-h': spacingProps('layout', ['minHeight'], { screen: 'height' }),
|
|
1322
|
+
'max-w': spacingProps('layout', ['maxWidth'], { container: true, screen: 'width' }),
|
|
1323
|
+
'max-h': spacingProps('layout', ['maxHeight'], { screen: 'height' }),
|
|
1324
|
+
aspect,
|
|
1325
|
+
// Positioning
|
|
1326
|
+
inset: spacingProps('layout', ['top', 'right', 'bottom', 'left']),
|
|
1327
|
+
'inset-x': spacingProps('layout', ['left', 'right']),
|
|
1328
|
+
'inset-y': spacingProps('layout', ['top', 'bottom']),
|
|
1329
|
+
top: spacingProps('layout', ['top']),
|
|
1330
|
+
right: spacingProps('layout', ['right']),
|
|
1331
|
+
bottom: spacingProps('layout', ['bottom']),
|
|
1332
|
+
left: spacingProps('layout', ['left']),
|
|
1333
|
+
// Flexbox
|
|
1334
|
+
flex: numberProp('layout', 'flex', undefined, ['flexGrow', 'flexShrink']),
|
|
1335
|
+
grow: numberProp('layout', 'flexGrow'),
|
|
1336
|
+
shrink: numberProp('layout', 'flexShrink'),
|
|
1337
|
+
// Borders and corners
|
|
1338
|
+
border,
|
|
1339
|
+
rounded: rounded(),
|
|
1340
|
+
...Object.fromEntries(Object.keys(SIDE_CORNERS).map((side) => [`rounded-${side}`, rounded(side)])),
|
|
1341
|
+
// Backgrounds
|
|
1342
|
+
bg: (value, draft, tokens, negative, vars) => {
|
|
1343
|
+
if (value.startsWith('linear-'))
|
|
1344
|
+
return linearGradient(value.slice(7), draft, tokens, negative, vars);
|
|
1345
|
+
// Tailwind v3 spelling.
|
|
1346
|
+
if (value.startsWith('gradient-'))
|
|
1347
|
+
return linearGradient(value.slice(9), draft, tokens, negative, vars);
|
|
1348
|
+
if (!colorProp('style', 'background')(value, draft, tokens, negative, vars))
|
|
1349
|
+
return false;
|
|
1350
|
+
delete draft.gradient;
|
|
1351
|
+
return true;
|
|
1352
|
+
},
|
|
1353
|
+
from: gradientStop('from'),
|
|
1354
|
+
via: gradientStop('via'),
|
|
1355
|
+
to: gradientStop('to'),
|
|
1356
|
+
// Effects
|
|
1357
|
+
opacity: opacityHandler,
|
|
1358
|
+
shadow: shadowHandler('shadow'),
|
|
1359
|
+
'inset-shadow': shadowHandler('insetShadow'),
|
|
1360
|
+
'drop-shadow': dropShadow,
|
|
1361
|
+
tint: colorProp('style', 'tintColor'),
|
|
1362
|
+
// Transforms
|
|
1363
|
+
'translate-x': translate(['translateX']),
|
|
1364
|
+
'translate-y': translate(['translateY']),
|
|
1365
|
+
'translate-z': translate(['translateZ']),
|
|
1366
|
+
translate: translate(['translateX', 'translateY']),
|
|
1367
|
+
scale: transformNumber('scale', (n) => n / 100, ['scaleX', 'scaleY']),
|
|
1368
|
+
'scale-x': transformNumber('scaleX', (n) => n / 100),
|
|
1369
|
+
'scale-y': transformNumber('scaleY', (n) => n / 100),
|
|
1370
|
+
rotate: transformNumber('rotate', (n) => n),
|
|
1371
|
+
// Typography
|
|
1372
|
+
text: textUtility,
|
|
1373
|
+
font: fontWeight,
|
|
1374
|
+
leading,
|
|
1375
|
+
'line-clamp': lineClamp,
|
|
1376
|
+
};
|
|
1377
|
+
/** Bare classes that are functional utilities with an empty value. */
|
|
1378
|
+
const BARE_DEFAULTS = {
|
|
1379
|
+
border: '1',
|
|
1380
|
+
rounded: '',
|
|
1381
|
+
shadow: '',
|
|
1382
|
+
grow: '1',
|
|
1383
|
+
shrink: '1',
|
|
1384
|
+
};
|
|
1385
|
+
for (const side of Object.keys(SIDE_CORNERS))
|
|
1386
|
+
BARE_DEFAULTS[`rounded-${side}`] = '';
|
|
1387
|
+
/**
|
|
1388
|
+
* Extracts all CSS variable names a utility depends on:
|
|
1389
|
+
* - explicit `var(--x)` / `(--x)` references (including opacity/leading modifiers),
|
|
1390
|
+
* - variables referenced by matching config tokens (e.g. `tokens.extend.colors.primary = 'var(--x)'`),
|
|
1391
|
+
* - implicit namespace variables (`--color-*`, `--radius-*`, `--text-*`, `--font-weight-*`,
|
|
1392
|
+
* `--leading-*`, `--shadow-*`) when a token lookup finds nothing in `tokens`.
|
|
1393
|
+
*/
|
|
1394
|
+
export function extractUtilityVariableNames(utility, tokens) {
|
|
1395
|
+
const names = new Set(extractVariableNames(utility));
|
|
1396
|
+
const addFromExpr = (expr) => {
|
|
1397
|
+
for (const v of extractVariableNames(expr))
|
|
1398
|
+
names.add(v);
|
|
1399
|
+
};
|
|
1400
|
+
const addTokenOrNamespace = (tokenValue, namespacePrefix, suffix) => {
|
|
1401
|
+
if (tokenValue !== undefined) {
|
|
1402
|
+
if (typeof tokenValue === 'string' && hasVarCall(tokenValue))
|
|
1403
|
+
addFromExpr(tokenValue);
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
if (isValidTokenSuffix(suffix))
|
|
1407
|
+
names.add(`${namespacePrefix}${suffix}`);
|
|
1408
|
+
};
|
|
1409
|
+
const addLeadingDep = (modifier) => {
|
|
1410
|
+
if (parseDynamicValue(modifier) !== null || modifier === 'none')
|
|
1411
|
+
return;
|
|
1412
|
+
if (isNumeric(modifier)) {
|
|
1413
|
+
if (typeof tokens.spacing === 'string' && hasVarCall(tokens.spacing))
|
|
1414
|
+
addFromExpr(tokens.spacing);
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
addTokenOrNamespace(own(tokens.leading, modifier), '--leading-', modifier);
|
|
1418
|
+
};
|
|
1419
|
+
const negative = utility.startsWith('-');
|
|
1420
|
+
const name = negative ? utility.slice(1) : utility;
|
|
1421
|
+
if (!negative && own(staticUtilities, name) !== undefined)
|
|
1422
|
+
return [...names];
|
|
1423
|
+
const bare = own(BARE_DEFAULTS, name);
|
|
1424
|
+
if (bare !== undefined) {
|
|
1425
|
+
if (name === 'rounded' || name.startsWith('rounded-')) {
|
|
1426
|
+
const token = own(tokens.radius, '');
|
|
1427
|
+
if (typeof token === 'string' && hasVarCall(token))
|
|
1428
|
+
addFromExpr(token);
|
|
1429
|
+
}
|
|
1430
|
+
else if (name === 'shadow') {
|
|
1431
|
+
const token = own(tokens.shadow, '');
|
|
1432
|
+
if (typeof token === 'string' && hasVarCall(token))
|
|
1433
|
+
addFromExpr(token);
|
|
1434
|
+
}
|
|
1435
|
+
return [...names];
|
|
1436
|
+
}
|
|
1437
|
+
const bracket = name.indexOf('[');
|
|
1438
|
+
const paren = name.indexOf('(');
|
|
1439
|
+
const searchEnd = bracket === -1 ? (paren === -1 ? name.length : paren) : paren === -1 ? bracket : Math.min(bracket, paren);
|
|
1440
|
+
let prefix;
|
|
1441
|
+
let value = '';
|
|
1442
|
+
for (let i = searchEnd - 1; i > 0; i--) {
|
|
1443
|
+
if (name[i] !== '-')
|
|
1444
|
+
continue;
|
|
1445
|
+
const candidate = name.slice(0, i);
|
|
1446
|
+
if (own(functionalUtilities, candidate) !== undefined) {
|
|
1447
|
+
prefix = candidate;
|
|
1448
|
+
value = name.slice(i + 1);
|
|
1449
|
+
break;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
if (prefix === undefined)
|
|
1453
|
+
return [...names];
|
|
1454
|
+
if (prefix === 'bg') {
|
|
1455
|
+
if (value.startsWith('linear-') || value.startsWith('gradient-'))
|
|
1456
|
+
return [...names];
|
|
1457
|
+
const [base] = splitModifier(value);
|
|
1458
|
+
if (parseDynamicValue(base) === null)
|
|
1459
|
+
addTokenOrNamespace(own(tokens.colors, base), '--color-', base);
|
|
1460
|
+
}
|
|
1461
|
+
else if (prefix === 'from' || prefix === 'via' || prefix === 'to' || prefix === 'tint') {
|
|
1462
|
+
const [base] = splitModifier(value);
|
|
1463
|
+
if (parseDynamicValue(base) === null)
|
|
1464
|
+
addTokenOrNamespace(own(tokens.colors, base), '--color-', base);
|
|
1465
|
+
}
|
|
1466
|
+
else if (prefix === 'border') {
|
|
1467
|
+
const [base] = splitModifier(value);
|
|
1468
|
+
if (parseDynamicValue(base) === null && !isNumeric(value)) {
|
|
1469
|
+
addTokenOrNamespace(own(tokens.colors, base), '--color-', base);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
else if (prefix === 'rounded' || prefix.startsWith('rounded-')) {
|
|
1473
|
+
if (parseDynamicValue(value) === null)
|
|
1474
|
+
addTokenOrNamespace(own(tokens.radius, value), '--radius-', value);
|
|
1475
|
+
}
|
|
1476
|
+
else if (prefix === 'font') {
|
|
1477
|
+
if (parseDynamicValue(value) === null)
|
|
1478
|
+
addTokenOrNamespace(own(tokens.fontWeight, value), '--font-weight-', value);
|
|
1479
|
+
}
|
|
1480
|
+
else if (prefix === 'leading') {
|
|
1481
|
+
addLeadingDep(value);
|
|
1482
|
+
}
|
|
1483
|
+
else if (prefix === 'text') {
|
|
1484
|
+
const [base, modifier] = splitModifier(value);
|
|
1485
|
+
if (parseDynamicValue(base) === null) {
|
|
1486
|
+
const fontSizeToken = own(tokens.fontSize, base);
|
|
1487
|
+
if (fontSizeToken !== undefined) {
|
|
1488
|
+
if (typeof fontSizeToken === 'string') {
|
|
1489
|
+
if (hasVarCall(fontSizeToken))
|
|
1490
|
+
addFromExpr(fontSizeToken);
|
|
1491
|
+
}
|
|
1492
|
+
else {
|
|
1493
|
+
if (typeof fontSizeToken.fontSize === 'string' && hasVarCall(fontSizeToken.fontSize)) {
|
|
1494
|
+
addFromExpr(fontSizeToken.fontSize);
|
|
1495
|
+
}
|
|
1496
|
+
if (modifier === undefined &&
|
|
1497
|
+
typeof fontSizeToken.lineHeight === 'string' &&
|
|
1498
|
+
hasVarCall(fontSizeToken.lineHeight)) {
|
|
1499
|
+
addFromExpr(fontSizeToken.lineHeight);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
if (modifier !== undefined)
|
|
1503
|
+
addLeadingDep(modifier);
|
|
1504
|
+
}
|
|
1505
|
+
else {
|
|
1506
|
+
const colorToken = own(tokens.colors, base);
|
|
1507
|
+
if (colorToken !== undefined) {
|
|
1508
|
+
if (typeof colorToken === 'string' && hasVarCall(colorToken))
|
|
1509
|
+
addFromExpr(colorToken);
|
|
1510
|
+
}
|
|
1511
|
+
else if (isValidTokenSuffix(base)) {
|
|
1512
|
+
names.add(`--text-${base}`);
|
|
1513
|
+
names.add(`--color-${base}`);
|
|
1514
|
+
if (modifier !== undefined)
|
|
1515
|
+
addLeadingDep(modifier);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
else if (modifier !== undefined) {
|
|
1520
|
+
addLeadingDep(modifier);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
else if (prefix === 'shadow') {
|
|
1524
|
+
const [base, modifier] = splitModifier(value);
|
|
1525
|
+
if (parseDynamicValue(base) === null) {
|
|
1526
|
+
const shadowToken = own(tokens.shadow, value);
|
|
1527
|
+
if (shadowToken !== undefined) {
|
|
1528
|
+
if (typeof shadowToken === 'string' && hasVarCall(shadowToken))
|
|
1529
|
+
addFromExpr(shadowToken);
|
|
1530
|
+
}
|
|
1531
|
+
else {
|
|
1532
|
+
const colorToken = own(tokens.colors, base);
|
|
1533
|
+
if (colorToken !== undefined) {
|
|
1534
|
+
if (typeof colorToken === 'string' && hasVarCall(colorToken))
|
|
1535
|
+
addFromExpr(colorToken);
|
|
1536
|
+
}
|
|
1537
|
+
else {
|
|
1538
|
+
if (modifier === undefined && isValidTokenSuffix(value))
|
|
1539
|
+
names.add(`--shadow-${value}`);
|
|
1540
|
+
if (isValidTokenSuffix(base))
|
|
1541
|
+
names.add(`--color-${base}`);
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
else if (prefix === 'inset-shadow') {
|
|
1547
|
+
const [base, modifier] = splitModifier(value);
|
|
1548
|
+
if (parseDynamicValue(base) === null) {
|
|
1549
|
+
const insetShadowToken = own(tokens.insetShadow, value);
|
|
1550
|
+
if (insetShadowToken !== undefined) {
|
|
1551
|
+
if (typeof insetShadowToken === 'string' && hasVarCall(insetShadowToken))
|
|
1552
|
+
addFromExpr(insetShadowToken);
|
|
1553
|
+
}
|
|
1554
|
+
else {
|
|
1555
|
+
const colorToken = own(tokens.colors, base);
|
|
1556
|
+
if (colorToken !== undefined) {
|
|
1557
|
+
if (typeof colorToken === 'string' && hasVarCall(colorToken))
|
|
1558
|
+
addFromExpr(colorToken);
|
|
1559
|
+
}
|
|
1560
|
+
else {
|
|
1561
|
+
if (modifier === undefined && isValidTokenSuffix(value))
|
|
1562
|
+
names.add(`--inset-shadow-${value}`);
|
|
1563
|
+
if (isValidTokenSuffix(base))
|
|
1564
|
+
names.add(`--color-${base}`);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
else if (prefix === 'drop-shadow') {
|
|
1570
|
+
if (parseDynamicValue(value) === null)
|
|
1571
|
+
addTokenOrNamespace(own(tokens.dropShadow, value), '--drop-shadow-', value);
|
|
1572
|
+
}
|
|
1573
|
+
else if (prefix === 'aspect') {
|
|
1574
|
+
if (parseDynamicValue(value) === null) {
|
|
1575
|
+
const aspectToken = own(tokens.aspect, value);
|
|
1576
|
+
if (typeof aspectToken === 'string' && hasVarCall(aspectToken))
|
|
1577
|
+
addFromExpr(aspectToken);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
else {
|
|
1581
|
+
const spacing = own(SPACING_CONFLICTS, prefix);
|
|
1582
|
+
if (spacing !== undefined && parseDynamicValue(value) === null) {
|
|
1583
|
+
const scaleOverride = tokens.spacingScale !== undefined ? own(tokens.spacingScale, value) : undefined;
|
|
1584
|
+
if (scaleOverride !== undefined) {
|
|
1585
|
+
if (typeof scaleOverride === 'string' && hasVarCall(scaleOverride))
|
|
1586
|
+
addFromExpr(scaleOverride);
|
|
1587
|
+
}
|
|
1588
|
+
else if (isNumeric(value) && value !== '0') {
|
|
1589
|
+
if (typeof tokens.spacing === 'string' && hasVarCall(tokens.spacing))
|
|
1590
|
+
addFromExpr(tokens.spacing);
|
|
1591
|
+
}
|
|
1592
|
+
else if (spacing.options?.container && own(tokens.container, value) !== undefined) {
|
|
1593
|
+
const containerToken = own(tokens.container, value);
|
|
1594
|
+
if (typeof containerToken === 'string' && hasVarCall(containerToken))
|
|
1595
|
+
addFromExpr(containerToken);
|
|
1596
|
+
}
|
|
1597
|
+
else if (!isSpacingLike(value, tokens, spacing.options) && isValidTokenSuffix(value)) {
|
|
1598
|
+
names.add(`--spacing-${value}`);
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
return [...names];
|
|
1603
|
+
}
|
|
1604
|
+
const SCREEN_UTILITIES = new Set([
|
|
1605
|
+
'w-screen',
|
|
1606
|
+
'h-screen',
|
|
1607
|
+
'min-w-screen',
|
|
1608
|
+
'min-h-screen',
|
|
1609
|
+
'max-w-screen',
|
|
1610
|
+
'max-h-screen',
|
|
1611
|
+
]);
|
|
1612
|
+
/** Returns true when `utility` directly references viewport dimensions (`*-screen` or `vw`/`vh`). */
|
|
1613
|
+
export function utilityUsesViewport(utility) {
|
|
1614
|
+
const name = utility.startsWith('-') ? utility.slice(1) : utility;
|
|
1615
|
+
if (SCREEN_UTILITIES.has(name))
|
|
1616
|
+
return true;
|
|
1617
|
+
const bracket = name.indexOf('[');
|
|
1618
|
+
if (bracket === -1)
|
|
1619
|
+
return false;
|
|
1620
|
+
return hasViewportUnit(name.slice(bracket));
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Applies one utility (no variants) to the draft. Returns false when the class is unknown.
|
|
1624
|
+
*/
|
|
1625
|
+
export function applyUtility(utility, draft, tokens, vars, viewport) {
|
|
1626
|
+
const negative = utility.startsWith('-');
|
|
1627
|
+
const name = negative ? utility.slice(1) : utility;
|
|
1628
|
+
if (!negative) {
|
|
1629
|
+
const fixed = staticUtilities[name];
|
|
1630
|
+
if (fixed) {
|
|
1631
|
+
fixed(draft);
|
|
1632
|
+
return true;
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
const bare = BARE_DEFAULTS[name];
|
|
1636
|
+
if (bare !== undefined)
|
|
1637
|
+
return functionalUtilities[name](bare, draft, tokens, negative, vars, viewport);
|
|
1638
|
+
// Try the longest prefix first, splitting only before an arbitrary `[...]` or `(...)` value.
|
|
1639
|
+
const bracket = name.indexOf('[');
|
|
1640
|
+
const paren = name.indexOf('(');
|
|
1641
|
+
const searchEnd = bracket === -1 ? (paren === -1 ? name.length : paren) : paren === -1 ? bracket : Math.min(bracket, paren);
|
|
1642
|
+
for (let i = searchEnd - 1; i > 0; i--) {
|
|
1643
|
+
if (name[i] !== '-')
|
|
1644
|
+
continue;
|
|
1645
|
+
const handler = functionalUtilities[name.slice(0, i)];
|
|
1646
|
+
if (handler) {
|
|
1647
|
+
if (handler(name.slice(i + 1), draft, tokens, negative, vars, viewport))
|
|
1648
|
+
return true;
|
|
1649
|
+
if (vars?.hasError() || vars?.isMissingViewport?.())
|
|
1650
|
+
return false;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
return false;
|
|
1654
|
+
}
|
|
1655
|
+
/** Turns the draft into NitroUI props, resolving classes that depend on each other. */
|
|
1656
|
+
export function finalizeDraft(draft) {
|
|
1657
|
+
if (draft.corners)
|
|
1658
|
+
draft.style.maskedCorners = [...draft.corners];
|
|
1659
|
+
const gradient = draft.gradient;
|
|
1660
|
+
if (gradient?.start && gradient.end && (gradient.from !== undefined || gradient.to !== undefined)) {
|
|
1661
|
+
const from = gradient.from ?? withAlpha(gradient.to, 0);
|
|
1662
|
+
const to = gradient.to ?? withAlpha(from, 0);
|
|
1663
|
+
const colors = gradient.via === undefined ? [from, to] : [from, gradient.via, to];
|
|
1664
|
+
draft.style.background = { type: 'linear-gradient', colors, start: gradient.start, end: gradient.end };
|
|
1665
|
+
}
|
|
1666
|
+
const tint = (layers, tintColor) => tintColor === undefined
|
|
1667
|
+
? layers
|
|
1668
|
+
: layers.map((layer) => ({
|
|
1669
|
+
...layer,
|
|
1670
|
+
// Like Tailwind, a shadow color keeps each layer's alpha unless it has its own opacity modifier.
|
|
1671
|
+
color: tintColor.explicitAlpha
|
|
1672
|
+
? tintColor.color
|
|
1673
|
+
: multiplyAlpha(withAlpha(tintColor.color, 1), (layer.color & 0xff) / 255),
|
|
1674
|
+
}));
|
|
1675
|
+
const shadows = [
|
|
1676
|
+
...tint(draft.insetShadow ?? [], draft.insetShadowColor),
|
|
1677
|
+
...tint(draft.shadow ?? [], draft.shadowColor),
|
|
1678
|
+
];
|
|
1679
|
+
if (draft.shadow !== undefined || draft.insetShadow !== undefined)
|
|
1680
|
+
draft.style.boxShadow = shadows;
|
|
1681
|
+
if (draft.dropShadow !== undefined) {
|
|
1682
|
+
draft.style.filter = draft.dropShadow.map((dropShadow) => ({ dropShadow }));
|
|
1683
|
+
}
|
|
1684
|
+
const fontSize = draft.text.fontSize ?? 17;
|
|
1685
|
+
if (draft.leading !== undefined) {
|
|
1686
|
+
draft.text.lineHeight =
|
|
1687
|
+
'points' in draft.leading
|
|
1688
|
+
? draft.leading.points
|
|
1689
|
+
: // Without a font size class this scales NitroUI's default Text size of 17.
|
|
1690
|
+
Math.round(fontSize * draft.leading.multiplier * 1000) / 1000;
|
|
1691
|
+
}
|
|
1692
|
+
else if (draft.sizeLineHeight !== undefined) {
|
|
1693
|
+
draft.text.lineHeight = draft.sizeLineHeight;
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
const ROUNDED_SIDE_GROUPS = Object.keys(SIDE_CORNERS).map((side) => `rounded-${side}`);
|
|
1697
|
+
const FLEX_CONFLICT = { group: 'flex', overrides: ['flex-grow', 'flex-shrink'] };
|
|
1698
|
+
const ROUNDED_CONFLICT = { group: 'rounded', overrides: ROUNDED_SIDE_GROUPS };
|
|
1699
|
+
const FONT_SIZE_CONFLICT = { group: 'font-size', overrides: ['leading'] };
|
|
1700
|
+
const BG_COLOR_CONFLICT = { group: 'bg-color', overrides: ['bg-gradient', 'from', 'via', 'to'] };
|
|
1701
|
+
const BG_GRADIENT_CONFLICT = { group: 'bg-gradient', overrides: ['bg-color'] };
|
|
1702
|
+
const STATIC_CONFLICTS = {
|
|
1703
|
+
flex: { group: 'display-flex' },
|
|
1704
|
+
'flex-row': { group: 'flex-direction' },
|
|
1705
|
+
'flex-row-reverse': { group: 'flex-direction' },
|
|
1706
|
+
'flex-col': { group: 'flex-direction' },
|
|
1707
|
+
'flex-col-reverse': { group: 'flex-direction' },
|
|
1708
|
+
'flex-wrap': { group: 'flex-wrap' },
|
|
1709
|
+
'flex-wrap-reverse': { group: 'flex-wrap' },
|
|
1710
|
+
'flex-nowrap': { group: 'flex-wrap' },
|
|
1711
|
+
'flex-auto': FLEX_CONFLICT,
|
|
1712
|
+
'flex-initial': FLEX_CONFLICT,
|
|
1713
|
+
'flex-none': FLEX_CONFLICT,
|
|
1714
|
+
grow: { group: 'flex-grow' },
|
|
1715
|
+
shrink: { group: 'flex-shrink' },
|
|
1716
|
+
'justify-start': { group: 'justify-content' },
|
|
1717
|
+
'justify-end': { group: 'justify-content' },
|
|
1718
|
+
'justify-center': { group: 'justify-content' },
|
|
1719
|
+
'justify-between': { group: 'justify-content' },
|
|
1720
|
+
'justify-around': { group: 'justify-content' },
|
|
1721
|
+
'justify-evenly': { group: 'justify-content' },
|
|
1722
|
+
'items-start': { group: 'align-items' },
|
|
1723
|
+
'items-end': { group: 'align-items' },
|
|
1724
|
+
'items-center': { group: 'align-items' },
|
|
1725
|
+
'items-stretch': { group: 'align-items' },
|
|
1726
|
+
'items-baseline': { group: 'align-items' },
|
|
1727
|
+
'self-auto': { group: 'align-self' },
|
|
1728
|
+
'self-start': { group: 'align-self' },
|
|
1729
|
+
'self-end': { group: 'align-self' },
|
|
1730
|
+
'self-center': { group: 'align-self' },
|
|
1731
|
+
'self-stretch': { group: 'align-self' },
|
|
1732
|
+
'self-baseline': { group: 'align-self' },
|
|
1733
|
+
absolute: { group: 'position' },
|
|
1734
|
+
relative: { group: 'position' },
|
|
1735
|
+
static: { group: 'position' },
|
|
1736
|
+
'overflow-visible': { group: 'overflow' },
|
|
1737
|
+
'overflow-hidden': { group: 'overflow' },
|
|
1738
|
+
'overflow-clip': { group: 'overflow' },
|
|
1739
|
+
'overflow-scroll': { group: 'overflow' },
|
|
1740
|
+
'corner-continuous': { group: 'corner-curve' },
|
|
1741
|
+
'corner-circular': { group: 'corner-curve' },
|
|
1742
|
+
squircle: { group: 'corner-curve' },
|
|
1743
|
+
'text-left': { group: 'text-align' },
|
|
1744
|
+
'text-start': { group: 'text-align' },
|
|
1745
|
+
'text-center': { group: 'text-align' },
|
|
1746
|
+
'text-right': { group: 'text-align' },
|
|
1747
|
+
'text-end': { group: 'text-align' },
|
|
1748
|
+
'text-justify': { group: 'text-align' },
|
|
1749
|
+
truncate: { group: 'line-clamp', overrides: ['text-overflow'] },
|
|
1750
|
+
'text-ellipsis': { group: 'text-overflow' },
|
|
1751
|
+
'text-clip': { group: 'text-overflow' },
|
|
1752
|
+
};
|
|
1753
|
+
const SPACING_CONFLICTS = {
|
|
1754
|
+
p: { conflict: { group: 'p', overrides: ['px', 'py', 'pt', 'pr', 'pb', 'pl'] } },
|
|
1755
|
+
px: { conflict: { group: 'px', overrides: ['pl', 'pr'] } },
|
|
1756
|
+
py: { conflict: { group: 'py', overrides: ['pt', 'pb'] } },
|
|
1757
|
+
pt: { conflict: { group: 'pt' } },
|
|
1758
|
+
pr: { conflict: { group: 'pr' } },
|
|
1759
|
+
pb: { conflict: { group: 'pb' } },
|
|
1760
|
+
pl: { conflict: { group: 'pl' } },
|
|
1761
|
+
m: { conflict: { group: 'm', overrides: ['mx', 'my', 'mt', 'mr', 'mb', 'ml'] }, options: { auto: true } },
|
|
1762
|
+
mx: { conflict: { group: 'mx', overrides: ['ml', 'mr'] }, options: { auto: true } },
|
|
1763
|
+
my: { conflict: { group: 'my', overrides: ['mt', 'mb'] }, options: { auto: true } },
|
|
1764
|
+
mt: { conflict: { group: 'mt' }, options: { auto: true } },
|
|
1765
|
+
mr: { conflict: { group: 'mr' }, options: { auto: true } },
|
|
1766
|
+
mb: { conflict: { group: 'mb' }, options: { auto: true } },
|
|
1767
|
+
ml: { conflict: { group: 'ml' }, options: { auto: true } },
|
|
1768
|
+
gap: { conflict: { group: 'gap', overrides: ['gap-x', 'gap-y'] } },
|
|
1769
|
+
'gap-x': { conflict: { group: 'gap-x' } },
|
|
1770
|
+
'gap-y': { conflict: { group: 'gap-y' } },
|
|
1771
|
+
w: { conflict: { group: 'w' }, options: { container: true, screen: 'width' } },
|
|
1772
|
+
h: { conflict: { group: 'h' }, options: { screen: 'height' } },
|
|
1773
|
+
size: { conflict: { group: 'size', overrides: ['w', 'h'] } },
|
|
1774
|
+
'min-w': { conflict: { group: 'min-w' }, options: { container: true, screen: 'width' } },
|
|
1775
|
+
'min-h': { conflict: { group: 'min-h' }, options: { screen: 'height' } },
|
|
1776
|
+
'max-w': { conflict: { group: 'max-w' }, options: { container: true, screen: 'width' } },
|
|
1777
|
+
'max-h': { conflict: { group: 'max-h' }, options: { screen: 'height' } },
|
|
1778
|
+
inset: { conflict: { group: 'inset', overrides: ['inset-x', 'inset-y', 'top', 'right', 'bottom', 'left'] } },
|
|
1779
|
+
'inset-x': { conflict: { group: 'inset-x', overrides: ['left', 'right'] } },
|
|
1780
|
+
'inset-y': { conflict: { group: 'inset-y', overrides: ['top', 'bottom'] } },
|
|
1781
|
+
top: { conflict: { group: 'top' } },
|
|
1782
|
+
right: { conflict: { group: 'right' } },
|
|
1783
|
+
bottom: { conflict: { group: 'bottom' } },
|
|
1784
|
+
left: { conflict: { group: 'left' } },
|
|
1785
|
+
translate: {
|
|
1786
|
+
conflict: { group: 'translate', overrides: ['translate-x', 'translate-y'] },
|
|
1787
|
+
options: { fraction: false },
|
|
1788
|
+
},
|
|
1789
|
+
'translate-x': { conflict: { group: 'translate-x' }, options: { fraction: false } },
|
|
1790
|
+
'translate-y': { conflict: { group: 'translate-y' }, options: { fraction: false } },
|
|
1791
|
+
'translate-z': { conflict: { group: 'translate-z' }, options: { fraction: false } },
|
|
1792
|
+
};
|
|
1793
|
+
function isSpacingLike(value, tokens, options) {
|
|
1794
|
+
const dyn = parseDynamicValue(value);
|
|
1795
|
+
if (dyn !== null)
|
|
1796
|
+
return dyn.hint !== 'color';
|
|
1797
|
+
if (tokens.spacingScale !== undefined && own(tokens.spacingScale, value) !== undefined)
|
|
1798
|
+
return true;
|
|
1799
|
+
if (options?.auto && value === 'auto')
|
|
1800
|
+
return true;
|
|
1801
|
+
if (options?.screen !== undefined && value === 'screen')
|
|
1802
|
+
return true;
|
|
1803
|
+
if (value === 'px' || value === '0' || value === 'full' || isNumeric(value))
|
|
1804
|
+
return true;
|
|
1805
|
+
if (options?.fraction !== false && /^\d+\/\d+$/.test(value))
|
|
1806
|
+
return true;
|
|
1807
|
+
if (options?.container && own(tokens.container, value) !== undefined)
|
|
1808
|
+
return true;
|
|
1809
|
+
return false;
|
|
1810
|
+
}
|
|
1811
|
+
function isNumberLike(value) {
|
|
1812
|
+
if (parseDynamicValue(value) !== null)
|
|
1813
|
+
return true;
|
|
1814
|
+
const stripped = value.replace(/deg$/, '');
|
|
1815
|
+
return stripped !== '' && Number.isFinite(Number(stripped));
|
|
1816
|
+
}
|
|
1817
|
+
function isColorLike(value, tokens) {
|
|
1818
|
+
const [base, modifier] = splitModifier(value);
|
|
1819
|
+
if (modifier !== undefined && parseDynamicValue(modifier) === null && !isNumeric(modifier))
|
|
1820
|
+
return false;
|
|
1821
|
+
const dyn = parseDynamicValue(base);
|
|
1822
|
+
if (dyn !== null) {
|
|
1823
|
+
if (dyn.hint === 'length')
|
|
1824
|
+
return false;
|
|
1825
|
+
if (dyn.isVar || dyn.hint === 'color')
|
|
1826
|
+
return true;
|
|
1827
|
+
return parseColor(dyn.expr) !== null;
|
|
1828
|
+
}
|
|
1829
|
+
return own(tokens.colors, base) !== undefined;
|
|
1830
|
+
}
|
|
1831
|
+
/**
|
|
1832
|
+
* Classifies one utility (without variants or `!`) into its conflict group and
|
|
1833
|
+
* any sub-groups it overrides, or returns `null` for unknown/unrecognized tokens.
|
|
1834
|
+
*/
|
|
1835
|
+
export function classifyUtility(utility, tokens) {
|
|
1836
|
+
const negative = utility.startsWith('-');
|
|
1837
|
+
const name = negative ? utility.slice(1) : utility;
|
|
1838
|
+
if (!negative) {
|
|
1839
|
+
const fixed = own(STATIC_CONFLICTS, name);
|
|
1840
|
+
if (fixed !== undefined)
|
|
1841
|
+
return fixed;
|
|
1842
|
+
}
|
|
1843
|
+
if (own(BARE_DEFAULTS, name) !== undefined) {
|
|
1844
|
+
if (name === 'border')
|
|
1845
|
+
return { group: 'border-width' };
|
|
1846
|
+
if (name === 'rounded')
|
|
1847
|
+
return ROUNDED_CONFLICT;
|
|
1848
|
+
if (name.startsWith('rounded-'))
|
|
1849
|
+
return { group: name };
|
|
1850
|
+
if (name === 'shadow')
|
|
1851
|
+
return { group: 'shadow' };
|
|
1852
|
+
if (name === 'grow')
|
|
1853
|
+
return { group: 'flex-grow' };
|
|
1854
|
+
if (name === 'shrink')
|
|
1855
|
+
return { group: 'flex-shrink' };
|
|
1856
|
+
}
|
|
1857
|
+
const bracket = name.indexOf('[');
|
|
1858
|
+
const paren = name.indexOf('(');
|
|
1859
|
+
const searchEnd = bracket === -1 ? (paren === -1 ? name.length : paren) : paren === -1 ? bracket : Math.min(bracket, paren);
|
|
1860
|
+
let prefix;
|
|
1861
|
+
let value = '';
|
|
1862
|
+
for (let i = searchEnd - 1; i > 0; i--) {
|
|
1863
|
+
if (name[i] !== '-')
|
|
1864
|
+
continue;
|
|
1865
|
+
const candidate = name.slice(0, i);
|
|
1866
|
+
if (own(functionalUtilities, candidate) !== undefined) {
|
|
1867
|
+
prefix = candidate;
|
|
1868
|
+
value = name.slice(i + 1);
|
|
1869
|
+
break;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
if (prefix === undefined)
|
|
1873
|
+
return null;
|
|
1874
|
+
const spacing = own(SPACING_CONFLICTS, prefix);
|
|
1875
|
+
if (spacing !== undefined) {
|
|
1876
|
+
return isSpacingLike(value, tokens, spacing.options) ? spacing.conflict : null;
|
|
1877
|
+
}
|
|
1878
|
+
switch (prefix) {
|
|
1879
|
+
case 'aspect':
|
|
1880
|
+
return own(tokens.aspect, value) !== undefined ||
|
|
1881
|
+
parseDynamicValue(value) !== null ||
|
|
1882
|
+
/^\d*\.?\d+\s*\/\s*\d*\.?\d+$/.test(value) ||
|
|
1883
|
+
isNumeric(value)
|
|
1884
|
+
? { group: 'aspect' }
|
|
1885
|
+
: null;
|
|
1886
|
+
case 'flex':
|
|
1887
|
+
return isNumberLike(value) ? FLEX_CONFLICT : null;
|
|
1888
|
+
case 'grow':
|
|
1889
|
+
return isNumberLike(value) ? { group: 'flex-grow' } : null;
|
|
1890
|
+
case 'shrink':
|
|
1891
|
+
return isNumberLike(value) ? { group: 'flex-shrink' } : null;
|
|
1892
|
+
case 'border': {
|
|
1893
|
+
if (isNumeric(value))
|
|
1894
|
+
return { group: 'border-width' };
|
|
1895
|
+
const [base] = splitModifier(value);
|
|
1896
|
+
const dyn = parseDynamicValue(base);
|
|
1897
|
+
if (dyn !== null) {
|
|
1898
|
+
if (dyn.hint === 'color' || (dyn.hint === null && dyn.isVar && !isMathExpression(dyn.expr))) {
|
|
1899
|
+
return { group: 'border-color' };
|
|
1900
|
+
}
|
|
1901
|
+
const len = parseLength(dyn.expr);
|
|
1902
|
+
if (dyn.hint === 'length' ||
|
|
1903
|
+
typeof len === 'number' ||
|
|
1904
|
+
len === MISSING_VIEWPORT ||
|
|
1905
|
+
isMathExpression(dyn.expr)) {
|
|
1906
|
+
return { group: 'border-width' };
|
|
1907
|
+
}
|
|
1908
|
+
return isColorLike(value, tokens) ? { group: 'border-color' } : null;
|
|
1909
|
+
}
|
|
1910
|
+
return isColorLike(value, tokens) ? { group: 'border-color' } : null;
|
|
1911
|
+
}
|
|
1912
|
+
case 'rounded':
|
|
1913
|
+
return parseDynamicValue(value) !== null || own(tokens.radius, value) !== undefined ? ROUNDED_CONFLICT : null;
|
|
1914
|
+
case 'bg': {
|
|
1915
|
+
if (value.startsWith('linear-') || value.startsWith('gradient-'))
|
|
1916
|
+
return BG_GRADIENT_CONFLICT;
|
|
1917
|
+
return isColorLike(value, tokens) ? BG_COLOR_CONFLICT : null;
|
|
1918
|
+
}
|
|
1919
|
+
case 'from':
|
|
1920
|
+
case 'via':
|
|
1921
|
+
case 'to':
|
|
1922
|
+
case 'tint':
|
|
1923
|
+
return isColorLike(value, tokens) ? { group: prefix } : null;
|
|
1924
|
+
case 'opacity':
|
|
1925
|
+
return parseDynamicValue(value) !== null || isNumberLike(value) ? { group: 'opacity' } : null;
|
|
1926
|
+
case 'shadow': {
|
|
1927
|
+
if (own(tokens.shadow, value) !== undefined)
|
|
1928
|
+
return { group: 'shadow' };
|
|
1929
|
+
const [base] = splitModifier(value);
|
|
1930
|
+
const dyn = parseDynamicValue(base);
|
|
1931
|
+
if (dyn !== null && dyn.hint !== 'color') {
|
|
1932
|
+
if (dyn.hint === 'length' || (!dyn.isVar && parseShadowList(dyn.expr, false) !== null)) {
|
|
1933
|
+
return { group: 'shadow' };
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
return isColorLike(value, tokens) ? { group: 'shadow-color' } : null;
|
|
1937
|
+
}
|
|
1938
|
+
case 'inset-shadow': {
|
|
1939
|
+
if (own(tokens.insetShadow, value) !== undefined)
|
|
1940
|
+
return { group: 'inset-shadow' };
|
|
1941
|
+
const [base] = splitModifier(value);
|
|
1942
|
+
const dyn = parseDynamicValue(base);
|
|
1943
|
+
if (dyn !== null && dyn.hint !== 'color') {
|
|
1944
|
+
if (dyn.hint === 'length' || (!dyn.isVar && parseShadowList(dyn.expr, true) !== null)) {
|
|
1945
|
+
return { group: 'inset-shadow' };
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
return isColorLike(value, tokens) ? { group: 'inset-shadow-color' } : null;
|
|
1949
|
+
}
|
|
1950
|
+
case 'drop-shadow':
|
|
1951
|
+
return own(tokens.dropShadow, value) !== undefined || parseDynamicValue(value) !== null
|
|
1952
|
+
? { group: 'drop-shadow' }
|
|
1953
|
+
: null;
|
|
1954
|
+
case 'scale':
|
|
1955
|
+
return isNumberLike(value) ? { group: 'scale', overrides: ['scale-x', 'scale-y'] } : null;
|
|
1956
|
+
case 'scale-x':
|
|
1957
|
+
case 'scale-y':
|
|
1958
|
+
case 'rotate':
|
|
1959
|
+
return isNumberLike(value) ? { group: prefix } : null;
|
|
1960
|
+
case 'text': {
|
|
1961
|
+
const [base] = splitModifier(value);
|
|
1962
|
+
const dyn = parseDynamicValue(base);
|
|
1963
|
+
if (dyn !== null) {
|
|
1964
|
+
if (dyn.hint === 'color' || (dyn.hint === null && dyn.isVar && !isMathExpression(dyn.expr))) {
|
|
1965
|
+
return { group: 'text-color' };
|
|
1966
|
+
}
|
|
1967
|
+
const len = parseLength(dyn.expr);
|
|
1968
|
+
if (dyn.hint === 'length' ||
|
|
1969
|
+
typeof len === 'number' ||
|
|
1970
|
+
len === MISSING_VIEWPORT ||
|
|
1971
|
+
isMathExpression(dyn.expr)) {
|
|
1972
|
+
return FONT_SIZE_CONFLICT;
|
|
1973
|
+
}
|
|
1974
|
+
return isColorLike(value, tokens) ? { group: 'text-color' } : null;
|
|
1975
|
+
}
|
|
1976
|
+
if (own(tokens.fontSize, base) !== undefined)
|
|
1977
|
+
return FONT_SIZE_CONFLICT;
|
|
1978
|
+
return isColorLike(value, tokens) ? { group: 'text-color' } : null;
|
|
1979
|
+
}
|
|
1980
|
+
case 'font':
|
|
1981
|
+
return own(tokens.fontWeight, value) !== undefined || parseDynamicValue(value) !== null
|
|
1982
|
+
? { group: 'font-weight' }
|
|
1983
|
+
: null;
|
|
1984
|
+
case 'leading':
|
|
1985
|
+
return own(tokens.leading, value) !== undefined ||
|
|
1986
|
+
value === 'none' ||
|
|
1987
|
+
isNumeric(value) ||
|
|
1988
|
+
parseDynamicValue(value) !== null
|
|
1989
|
+
? { group: 'leading' }
|
|
1990
|
+
: null;
|
|
1991
|
+
case 'line-clamp':
|
|
1992
|
+
return value === 'none' || isNumberLike(value) ? { group: 'line-clamp' } : null;
|
|
1993
|
+
default:
|
|
1994
|
+
if (prefix.startsWith('rounded-')) {
|
|
1995
|
+
return parseDynamicValue(value) !== null || own(tokens.radius, value) !== undefined ? { group: prefix } : null;
|
|
1996
|
+
}
|
|
1997
|
+
return null;
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
//# sourceMappingURL=utilities.js.map
|