@tenphi/tasty 0.0.0-snapshot.26b4630 → 0.0.0-snapshot.2705ab9
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/README.md +315 -159
- package/dist/chunks/cacheKey.js +16 -8
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.d.ts +1 -1
- package/dist/chunks/definitions.js +2 -3
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/renderChunk.js +31 -32
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/config.d.ts +98 -12
- package/dist/config.js +134 -33
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +11 -10
- package/dist/core/index.js +8 -7
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +26 -141
- package/dist/debug.js +356 -635
- package/dist/debug.js.map +1 -1
- package/dist/font-face/index.js +63 -0
- package/dist/font-face/index.js.map +1 -0
- package/dist/hooks/resolve-ssr-collector.js +15 -0
- package/dist/hooks/resolve-ssr-collector.js.map +1 -0
- package/dist/hooks/useCounterStyle.d.ts +50 -0
- package/dist/hooks/useCounterStyle.js +47 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +43 -0
- package/dist/hooks/useFontFace.js +71 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +3 -0
- package/dist/hooks/useGlobalStyles.js +24 -1
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.js +14 -3
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.js +32 -13
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.js +9 -1
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +5 -0
- package/dist/hooks/useStyles.js +115 -46
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +22 -11
- package/dist/index.js +10 -7
- package/dist/injector/index.d.ts +28 -2
- package/dist/injector/index.js +27 -1
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +28 -1
- package/dist/injector/injector.js +93 -32
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +16 -7
- package/dist/injector/sheet-manager.js +31 -11
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +70 -1
- package/dist/parser/classify.js +5 -4
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/const.js +17 -1
- package/dist/parser/const.js.map +1 -1
- package/dist/parser/parser.js +1 -1
- package/dist/pipeline/conditions.js +14 -8
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +137 -69
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +404 -208
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +1 -1
- package/dist/pipeline/parseStateKey.js +37 -20
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +111 -152
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/pipeline/warnings.js +18 -0
- package/dist/pipeline/warnings.js.map +1 -0
- package/dist/plugins/okhsl-plugin.js +2 -275
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +9 -2
- package/dist/properties/index.js +82 -17
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.d.ts +24 -0
- package/dist/properties/property-type-resolver.js +91 -0
- package/dist/properties/property-type-resolver.js.map +1 -0
- package/dist/ssr/astro.d.ts +29 -0
- package/dist/ssr/astro.js +65 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +35 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +40 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +102 -0
- package/dist/ssr/collector.js +227 -0
- package/dist/ssr/collector.js.map +1 -0
- package/dist/ssr/context.d.ts +8 -0
- package/dist/ssr/context.js +14 -0
- package/dist/ssr/context.js.map +1 -0
- package/dist/ssr/format-global-rules.js +22 -0
- package/dist/ssr/format-global-rules.js.map +1 -0
- package/dist/ssr/format-keyframes.js +70 -0
- package/dist/ssr/format-keyframes.js.map +1 -0
- package/dist/ssr/format-property.js +50 -0
- package/dist/ssr/format-property.js.map +1 -0
- package/dist/ssr/format-rules.js +73 -0
- package/dist/ssr/format-rules.js.map +1 -0
- package/dist/ssr/hydrate.d.ts +22 -0
- package/dist/ssr/hydrate.js +50 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/index.d.ts +5 -0
- package/dist/ssr/index.js +12 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +45 -0
- package/dist/ssr/next.js +71 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/ssr/ssr-collector-ref.js +12 -0
- package/dist/ssr/ssr-collector-ref.js.map +1 -0
- package/dist/states/index.js +12 -257
- package/dist/states/index.js.map +1 -1
- package/dist/styles/align.d.ts +1 -1
- package/dist/styles/align.js.map +1 -1
- package/dist/styles/border.d.ts +1 -1
- package/dist/styles/border.js +2 -2
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +2 -2
- package/dist/styles/color.js +9 -5
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/createStyle.js +25 -22
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/fade.d.ts +1 -1
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +14 -16
- package/dist/styles/fill.js +6 -5
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.d.ts +3 -3
- package/dist/styles/flow.js.map +1 -1
- package/dist/styles/index.js +1 -1
- package/dist/styles/justify.d.ts +1 -1
- package/dist/styles/justify.js.map +1 -1
- package/dist/styles/predefined.d.ts +0 -2
- package/dist/styles/predefined.js +1 -4
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.d.ts +5 -0
- package/dist/styles/preset.js +48 -47
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/radius.d.ts +1 -1
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollbar.d.ts +9 -5
- package/dist/styles/scrollbar.js +25 -82
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +2 -2
- package/dist/styles/shadow.js.map +1 -1
- package/dist/styles/transition.d.ts +1 -1
- package/dist/styles/transition.js +1 -1
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +70 -21
- package/dist/tasty.d.ts +30 -893
- package/dist/tasty.js +60 -19
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/utils/cache-wrapper.js +4 -8
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/color-math.d.ts +46 -0
- package/dist/utils/color-math.js +749 -0
- package/dist/utils/color-math.js.map +1 -0
- package/dist/utils/color-space.d.ts +5 -0
- package/dist/utils/color-space.js +229 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.d.ts +1 -1
- package/dist/utils/colors.js +3 -1
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/css-types.d.ts +1 -1
- package/dist/utils/dotize.d.ts +1 -1
- package/dist/utils/has-keys.js +13 -0
- package/dist/utils/has-keys.js.map +1 -0
- package/dist/utils/mod-attrs.js +2 -2
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +3 -13
- package/dist/utils/process-tokens.js +18 -98
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/string.js.map +1 -1
- package/dist/utils/styles.d.ts +4 -88
- package/dist/utils/styles.js +34 -398
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +24 -13
- package/dist/utils/typography.js +14 -16
- package/dist/utils/typography.js.map +1 -1
- package/dist/zero/babel.d.ts +67 -8
- package/dist/zero/babel.js +109 -17
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/extractor.js +118 -1
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/next.d.ts +44 -30
- package/dist/zero/next.js +102 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/PIPELINE.md +519 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +296 -0
- package/docs/comparison.md +420 -0
- package/docs/configuration.md +326 -0
- package/docs/debug.md +318 -0
- package/docs/design-system.md +424 -0
- package/docs/dsl.md +673 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +528 -0
- package/docs/methodology.md +567 -0
- package/docs/runtime.md +485 -0
- package/docs/ssr.md +384 -0
- package/docs/styles.md +579 -0
- package/docs/tasty-static.md +433 -0
- package/package.json +98 -28
- package/dist/styles/styledScrollbar.d.ts +0 -47
- package/dist/styles/styledScrollbar.js +0 -38
- package/dist/styles/styledScrollbar.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
package/dist/pipeline/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Lru } from "../parser/lru.js";
|
|
2
|
-
import { createStateParserContext, extractLocalPredefinedStates } from "../states/index.js";
|
|
3
2
|
import { stringifyStyles } from "../utils/styles.js";
|
|
4
3
|
import { createStyle } from "../styles/createStyle.js";
|
|
5
4
|
import { STYLE_HANDLER_MAP } from "../styles/index.js";
|
|
5
|
+
import { createStateParserContext, extractLocalPredefinedStates } from "../states/index.js";
|
|
6
6
|
import { and, falseCondition, not, or, trueCondition } from "./conditions.js";
|
|
7
7
|
import { simplifyCondition } from "./simplify.js";
|
|
8
8
|
import { buildExclusiveConditions, expandExclusiveOrs, expandOrConditions, isValueMapping, parseStyleEntries } from "./exclusive.js";
|
|
9
|
-
import { buildAtRulesFromVariant, conditionToCSS,
|
|
9
|
+
import { branchToCSS, buildAtRulesFromVariant, conditionToCSS, mergeVariantsIntoSelectorGroups, optimizeGroups, parentGroupsToCSS, rootGroupsToCSS, selectorGroupToCSS } from "./materialize.js";
|
|
10
|
+
import { emitWarning } from "./warnings.js";
|
|
10
11
|
import { parseStateKey } from "./parseStateKey.js";
|
|
11
12
|
|
|
12
13
|
//#region src/pipeline/index.ts
|
|
@@ -27,6 +28,13 @@ import { parseStateKey } from "./parseStateKey.js";
|
|
|
27
28
|
*/
|
|
28
29
|
const pipelineCache = new Lru(5e3);
|
|
29
30
|
/**
|
|
31
|
+
* Check if a cache key exists in the pipeline cache.
|
|
32
|
+
* Used by renderStylesForChunk to avoid building filtered styles on cache hit.
|
|
33
|
+
*/
|
|
34
|
+
function hasPipelineCacheEntry(cacheKey) {
|
|
35
|
+
return pipelineCache.get(cacheKey) !== void 0;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
30
38
|
* Clear the pipeline cache (for testing)
|
|
31
39
|
*/
|
|
32
40
|
function clearPipelineCache() {
|
|
@@ -36,12 +44,17 @@ function runPipeline(styles, parserContext) {
|
|
|
36
44
|
const allRules = [];
|
|
37
45
|
processStyles(styles, "", parserContext, allRules);
|
|
38
46
|
const seen = /* @__PURE__ */ new Set();
|
|
39
|
-
|
|
40
|
-
const key = `${rule.selector}|${rule.declarations}|${
|
|
47
|
+
const dedupedRules = allRules.filter((rule) => {
|
|
48
|
+
const key = `${rule.selector}|${rule.declarations}|${rule.atRules?.join("|") ?? ""}|${rule.rootPrefix || ""}|${rule.startingStyle ? "1" : "0"}`;
|
|
41
49
|
if (seen.has(key)) return false;
|
|
42
50
|
seen.add(key);
|
|
43
51
|
return true;
|
|
44
52
|
});
|
|
53
|
+
const normal = [];
|
|
54
|
+
const starting = [];
|
|
55
|
+
for (const rule of dedupedRules) if (rule.startingStyle) starting.push(rule);
|
|
56
|
+
else normal.push(rule);
|
|
57
|
+
return normal.concat(starting);
|
|
45
58
|
}
|
|
46
59
|
/**
|
|
47
60
|
* Process styles at a given nesting level
|
|
@@ -147,7 +160,7 @@ function getAllSelectors(key, styles) {
|
|
|
147
160
|
if (affix !== void 0) {
|
|
148
161
|
const result = processAffix(String(affix), key);
|
|
149
162
|
if (!result.valid) {
|
|
150
|
-
|
|
163
|
+
emitWarning("INVALID_SELECTOR_AFFIX", result.reason);
|
|
151
164
|
return null;
|
|
152
165
|
}
|
|
153
166
|
return result.selectors;
|
|
@@ -162,7 +175,8 @@ function getAllSelectors(key, styles) {
|
|
|
162
175
|
* Supports:
|
|
163
176
|
* - Direct child: '>'
|
|
164
177
|
* - Chained elements: '>Body>Row>'
|
|
165
|
-
* - HTML tags: '
|
|
178
|
+
* - HTML tags (no key injection): 'h1', '>ul>li', 'button:hover'
|
|
179
|
+
* - Universal selector: '*', 'h1 *'
|
|
166
180
|
* - Pseudo-elements on root: '::before'
|
|
167
181
|
* - Pseudo on sub-element: '@::before', '>@:hover'
|
|
168
182
|
* - Classes: '.active', '>@.active'
|
|
@@ -199,6 +213,7 @@ function processAffix(affix, key) {
|
|
|
199
213
|
*/
|
|
200
214
|
const VALID_TOKEN_PATTERNS = [
|
|
201
215
|
/^[>+~]/,
|
|
216
|
+
/^\*/,
|
|
202
217
|
/^[A-Z][a-zA-Z0-9]*/,
|
|
203
218
|
/^@/,
|
|
204
219
|
/^::?[a-z][a-z0-9-]*(?:\([^)]*\))?/,
|
|
@@ -333,12 +348,13 @@ function processSinglePattern(pattern, key) {
|
|
|
333
348
|
* The tokenizer handles these token types in order:
|
|
334
349
|
* 1. Whitespace (skipped)
|
|
335
350
|
* 2. Combinators: >, +, ~ (add surrounding spaces)
|
|
336
|
-
* 3.
|
|
337
|
-
* 4.
|
|
338
|
-
* 5.
|
|
339
|
-
* 6.
|
|
340
|
-
* 7.
|
|
341
|
-
* 8.
|
|
351
|
+
* 3. Universal selector: * (keep as-is with spacing)
|
|
352
|
+
* 4. Uppercase names: Body, Row (convert to [data-element="..."])
|
|
353
|
+
* 5. @ placeholder (keep for later replacement)
|
|
354
|
+
* 6. Pseudo: :hover, ::before (attach to previous token)
|
|
355
|
+
* 7. Tags: a, div, button (keep as-is with spacing)
|
|
356
|
+
* 8. Classes: .active (attach to previous element/tag/placeholder)
|
|
357
|
+
* 9. Attributes: [type="text"] (keep as-is)
|
|
342
358
|
*
|
|
343
359
|
* @param pattern - The raw selector pattern to transform
|
|
344
360
|
* @returns Transformed pattern with proper CSS selector syntax
|
|
@@ -352,6 +368,7 @@ function processSinglePattern(pattern, key) {
|
|
|
352
368
|
*/
|
|
353
369
|
function transformPattern(pattern) {
|
|
354
370
|
let result = "";
|
|
371
|
+
let lastCh = "";
|
|
355
372
|
let i = 0;
|
|
356
373
|
while (i < pattern.length) {
|
|
357
374
|
const char = pattern[i];
|
|
@@ -360,76 +377,80 @@ function transformPattern(pattern) {
|
|
|
360
377
|
continue;
|
|
361
378
|
}
|
|
362
379
|
if (/[>+~]/.test(char)) {
|
|
363
|
-
if (result &&
|
|
380
|
+
if (result && lastCh !== " ") result += " ";
|
|
364
381
|
result += char;
|
|
382
|
+
lastCh = char;
|
|
383
|
+
i++;
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
if (char === "*") {
|
|
387
|
+
if (result && lastCh !== " ") result += " ";
|
|
388
|
+
result += "*";
|
|
389
|
+
lastCh = "*";
|
|
365
390
|
i++;
|
|
366
391
|
continue;
|
|
367
392
|
}
|
|
368
393
|
if (/[A-Z]/.test(char)) {
|
|
369
|
-
|
|
370
|
-
while (i < pattern.length && /[a-zA-Z0-9]/.test(pattern[i]))
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
result += `[data-element="${name}"]`;
|
|
394
|
+
const nameStart = i;
|
|
395
|
+
while (i < pattern.length && /[a-zA-Z0-9]/.test(pattern[i])) i++;
|
|
396
|
+
if (result && lastCh !== " ") result += " ";
|
|
397
|
+
const segment = `[data-element="${pattern.slice(nameStart, i)}"]`;
|
|
398
|
+
result += segment;
|
|
399
|
+
lastCh = "]";
|
|
376
400
|
continue;
|
|
377
401
|
}
|
|
378
402
|
if (char === "@") {
|
|
379
|
-
if (result &&
|
|
403
|
+
if (result && lastCh !== " ") result += " ";
|
|
380
404
|
result += "@";
|
|
405
|
+
lastCh = "@";
|
|
381
406
|
i++;
|
|
382
407
|
continue;
|
|
383
408
|
}
|
|
384
409
|
if (char === ":") {
|
|
385
|
-
|
|
386
|
-
while (i < pattern.length && !/[\s>+~,@]/.test(pattern[i]) && !/[A-Z]/.test(pattern[i]))
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
result += pseudo;
|
|
410
|
+
const pseudoStart = i;
|
|
411
|
+
while (i < pattern.length && !/[\s>+~,@]/.test(pattern[i]) && !/[A-Z]/.test(pattern[i])) i++;
|
|
412
|
+
const segment = pattern.slice(pseudoStart, i);
|
|
413
|
+
result += segment;
|
|
414
|
+
lastCh = segment[segment.length - 1] || lastCh;
|
|
391
415
|
continue;
|
|
392
416
|
}
|
|
393
417
|
if (/[a-z]/.test(char)) {
|
|
394
|
-
|
|
395
|
-
while (i < pattern.length && /[a-z0-9-]/.test(pattern[i]))
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
result += tag;
|
|
418
|
+
const tagStart = i;
|
|
419
|
+
while (i < pattern.length && /[a-z0-9-]/.test(pattern[i])) i++;
|
|
420
|
+
if (result && lastCh !== " ") result += " ";
|
|
421
|
+
const segment = pattern.slice(tagStart, i);
|
|
422
|
+
result += segment;
|
|
423
|
+
lastCh = segment[segment.length - 1] || lastCh;
|
|
401
424
|
continue;
|
|
402
425
|
}
|
|
403
426
|
if (char === ".") {
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
let cls = ".";
|
|
427
|
+
const attachToLast = lastCh === "]" || lastCh === "@" || /[a-zA-Z0-9-]/.test(lastCh);
|
|
428
|
+
if (result && !attachToLast && lastCh !== " ") result += " ";
|
|
429
|
+
const clsStart = i;
|
|
408
430
|
i++;
|
|
409
|
-
while (i < pattern.length && /[a-zA-Z0-9_-]/.test(pattern[i]))
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
result += cls;
|
|
431
|
+
while (i < pattern.length && /[a-zA-Z0-9_-]/.test(pattern[i])) i++;
|
|
432
|
+
const segment = pattern.slice(clsStart, i);
|
|
433
|
+
result += segment;
|
|
434
|
+
lastCh = segment[segment.length - 1] || lastCh;
|
|
414
435
|
continue;
|
|
415
436
|
}
|
|
416
437
|
if (char === "[") {
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
let attr = "";
|
|
438
|
+
const attachToLast = lastCh === "]" || lastCh === "@" || /[a-zA-Z0-9-]/.test(lastCh);
|
|
439
|
+
if (result && !attachToLast && lastCh !== " ") result += " ";
|
|
440
|
+
const attrStart = i;
|
|
421
441
|
let depth = 0;
|
|
422
442
|
while (i < pattern.length) {
|
|
423
|
-
attr += pattern[i];
|
|
424
443
|
if (pattern[i] === "[") depth++;
|
|
425
444
|
if (pattern[i] === "]") depth--;
|
|
426
445
|
i++;
|
|
427
446
|
if (depth === 0) break;
|
|
428
447
|
}
|
|
429
|
-
result +=
|
|
448
|
+
result += pattern.slice(attrStart, i);
|
|
449
|
+
lastCh = "]";
|
|
430
450
|
continue;
|
|
431
451
|
}
|
|
432
452
|
result += char;
|
|
453
|
+
lastCh = char;
|
|
433
454
|
i++;
|
|
434
455
|
}
|
|
435
456
|
return result;
|
|
@@ -443,7 +464,8 @@ function transformPattern(pattern) {
|
|
|
443
464
|
* |----------------|-------------|---------|--------|
|
|
444
465
|
* | Combinator (>, +, ~) | Yes | `'>Body>'` | `> [data-element="Body"] > [el]` |
|
|
445
466
|
* | Uppercase element | Yes | `'>Body>Row'` | `> [el1] > [el2] [key]` |
|
|
446
|
-
* | Lowercase tag |
|
|
467
|
+
* | Lowercase tag | No | `'h1'` | ` h1` |
|
|
468
|
+
* | Universal (*) | No | `'h1 *'` | ` h1 *` |
|
|
447
469
|
* | Pseudo (:hover, ::before) | No | `'::before'` | `::before` |
|
|
448
470
|
* | Class (.active) | No | `'.active'` | `.active` |
|
|
449
471
|
* | Attribute ([type]) | No | `'[type="text"]'` | `[type="text"]` |
|
|
@@ -454,7 +476,8 @@ function transformPattern(pattern) {
|
|
|
454
476
|
* @example
|
|
455
477
|
* shouldInjectKey('>') // → true (trailing combinator)
|
|
456
478
|
* shouldInjectKey('>Body>Row') // → true (ends with element)
|
|
457
|
-
* shouldInjectKey('
|
|
479
|
+
* shouldInjectKey('h1') // → false (ends with tag)
|
|
480
|
+
* shouldInjectKey('*') // → false (universal selector)
|
|
458
481
|
* shouldInjectKey('::before') // → false (ends with pseudo)
|
|
459
482
|
* shouldInjectKey('.active') // → false (ends with class)
|
|
460
483
|
* shouldInjectKey('a:hover') // → false (ends with pseudo)
|
|
@@ -464,7 +487,6 @@ function shouldInjectKey(pattern) {
|
|
|
464
487
|
const trimmed = pattern.trim();
|
|
465
488
|
if (/[>+~]$/.test(trimmed)) return true;
|
|
466
489
|
if (/(?:^|[\s>+~\]:])[A-Z][a-zA-Z0-9]*$/.test(trimmed)) return true;
|
|
467
|
-
if (/(?<![:.])(?:^|[\s>+~])[a-z][a-z0-9-]*$/.test(trimmed)) return true;
|
|
468
490
|
return false;
|
|
469
491
|
}
|
|
470
492
|
/**
|
|
@@ -525,7 +547,27 @@ function cartesianProduct(arrays) {
|
|
|
525
547
|
if (arrays.length === 0) return [[]];
|
|
526
548
|
const nonEmpty = arrays.filter((a) => a.length > 0);
|
|
527
549
|
if (nonEmpty.length === 0) return [[]];
|
|
528
|
-
|
|
550
|
+
let result = [[]];
|
|
551
|
+
for (const arr of nonEmpty) {
|
|
552
|
+
const next = [];
|
|
553
|
+
for (const combo of result) for (const item of arr) {
|
|
554
|
+
const newCombo = new Array(combo.length + 1);
|
|
555
|
+
for (let i = 0; i < combo.length; i++) newCombo[i] = combo[i];
|
|
556
|
+
newCombo[combo.length] = item;
|
|
557
|
+
next.push(newCombo);
|
|
558
|
+
}
|
|
559
|
+
result = next;
|
|
560
|
+
}
|
|
561
|
+
return result;
|
|
562
|
+
}
|
|
563
|
+
const declStringCache = /* @__PURE__ */ new WeakMap();
|
|
564
|
+
function stringifyDeclarations(decl) {
|
|
565
|
+
let cached = declStringCache.get(decl);
|
|
566
|
+
if (cached === void 0) {
|
|
567
|
+
cached = JSON.stringify(decl);
|
|
568
|
+
declStringCache.set(decl, cached);
|
|
569
|
+
}
|
|
570
|
+
return cached;
|
|
529
571
|
}
|
|
530
572
|
/**
|
|
531
573
|
* Merge rules with identical CSS output
|
|
@@ -533,7 +575,7 @@ function cartesianProduct(arrays) {
|
|
|
533
575
|
function mergeByValue(rules) {
|
|
534
576
|
const groups = /* @__PURE__ */ new Map();
|
|
535
577
|
for (const rule of rules) {
|
|
536
|
-
const key = `${rule.selectorSuffix}|${
|
|
578
|
+
const key = `${rule.selectorSuffix}|${stringifyDeclarations(rule.declarations)}`;
|
|
537
579
|
if (!groups.has(key)) groups.set(key, []);
|
|
538
580
|
groups.get(key).push(rule);
|
|
539
581
|
}
|
|
@@ -554,11 +596,12 @@ function mergeByValue(rules) {
|
|
|
554
596
|
*/
|
|
555
597
|
function buildSelectorFromVariant(variant, selectorSuffix) {
|
|
556
598
|
let selector = "";
|
|
557
|
-
|
|
558
|
-
for (const
|
|
599
|
+
selector += branchToCSS([...variant.modifierConditions, ...variant.pseudoConditions]);
|
|
600
|
+
for (const group of variant.selectorGroups) selector += selectorGroupToCSS(group);
|
|
559
601
|
if (variant.parentGroups.length > 0) selector += parentGroupsToCSS(variant.parentGroups);
|
|
560
602
|
selector += selectorSuffix;
|
|
561
|
-
|
|
603
|
+
const ownOptimized = optimizeGroups(variant.ownGroups);
|
|
604
|
+
for (const group of ownOptimized) selector += selectorGroupToCSS(group);
|
|
562
605
|
return selector;
|
|
563
606
|
}
|
|
564
607
|
/**
|
|
@@ -572,45 +615,68 @@ function materializeComputedRule(rule) {
|
|
|
572
615
|
if (components.isImpossible || components.variants.length === 0) return [];
|
|
573
616
|
const declarations = Object.entries(rule.declarations).map(([prop, value]) => `${prop}: ${value};`).join(" ");
|
|
574
617
|
const getRootPrefixKey = (variant) => {
|
|
575
|
-
return variant.
|
|
618
|
+
return rootGroupsToCSS(variant.rootGroups) || "";
|
|
576
619
|
};
|
|
577
620
|
const byAtRules = /* @__PURE__ */ new Map();
|
|
578
621
|
for (const variant of components.variants) {
|
|
579
622
|
const atRules = buildAtRulesFromVariant(variant);
|
|
580
|
-
const
|
|
623
|
+
const startingStyle = variant.startingStyle;
|
|
624
|
+
const key = atRules.sort().join("|||") + "###" + getRootPrefixKey(variant) + "###" + (startingStyle ? "1" : "0");
|
|
581
625
|
const group = byAtRules.get(key);
|
|
582
626
|
if (group) group.variants.push(variant);
|
|
583
627
|
else byAtRules.set(key, {
|
|
584
628
|
variants: [variant],
|
|
585
629
|
atRules,
|
|
586
|
-
rootPrefix:
|
|
630
|
+
rootPrefix: rootGroupsToCSS(variant.rootGroups),
|
|
631
|
+
startingStyle: startingStyle || void 0
|
|
587
632
|
});
|
|
588
633
|
}
|
|
589
634
|
const rules = [];
|
|
590
635
|
for (const [, group] of byAtRules) {
|
|
591
|
-
const selectorFragments = group.variants.map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
|
|
636
|
+
const selectorFragments = mergeVariantsIntoSelectorGroups(group.variants).map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
|
|
592
637
|
const cssRule = {
|
|
593
638
|
selector: selectorFragments.length === 1 ? selectorFragments[0] : selectorFragments,
|
|
594
639
|
declarations
|
|
595
640
|
};
|
|
596
641
|
if (group.atRules.length > 0) cssRule.atRules = group.atRules;
|
|
597
642
|
if (group.rootPrefix) cssRule.rootPrefix = group.rootPrefix;
|
|
643
|
+
if (group.startingStyle) cssRule.startingStyle = true;
|
|
598
644
|
rules.push(cssRule);
|
|
599
645
|
}
|
|
600
646
|
return rules;
|
|
601
647
|
}
|
|
602
|
-
|
|
648
|
+
/**
|
|
649
|
+
* Merge StyleResult entries that share the same selector and at-rules,
|
|
650
|
+
* concatenating their declarations into a single rule.
|
|
651
|
+
*
|
|
652
|
+
* This reduces CSS output size when many style keys (e.g. design tokens)
|
|
653
|
+
* resolve to the same selector/state combination.
|
|
654
|
+
*/
|
|
655
|
+
function mergeStyleResults(results) {
|
|
656
|
+
if (results.length <= 1) return results;
|
|
657
|
+
const groups = /* @__PURE__ */ new Map();
|
|
658
|
+
for (const result of results) {
|
|
659
|
+
const key = `${result.atRules?.join("|") ?? ""}||${result.selector}||${result.startingStyle ? "1" : "0"}`;
|
|
660
|
+
const existing = groups.get(key);
|
|
661
|
+
if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${result.declarations}` : result.declarations;
|
|
662
|
+
else groups.set(key, { ...result });
|
|
663
|
+
}
|
|
664
|
+
return Array.from(groups.values());
|
|
665
|
+
}
|
|
666
|
+
function renderStyles(styles, classNameOrSelector, options, pipelineCacheKey) {
|
|
603
667
|
const directSelector = !!classNameOrSelector;
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
668
|
+
let rules;
|
|
669
|
+
if (pipelineCacheKey) rules = pipelineCache.get(pipelineCacheKey);
|
|
670
|
+
if (!rules && !styles) return directSelector ? [] : { rules: [] };
|
|
671
|
+
const cacheKey = pipelineCacheKey || stringifyStyles(styles);
|
|
672
|
+
if (!rules) rules = pipelineCache.get(cacheKey);
|
|
607
673
|
if (!rules) {
|
|
608
674
|
rules = runPipeline(styles, createStateParserContext(styles));
|
|
609
675
|
pipelineCache.set(cacheKey, rules);
|
|
610
676
|
}
|
|
611
677
|
if (directSelector) {
|
|
612
678
|
const shouldDouble = options?.doubleSelector ?? false;
|
|
613
|
-
return rules.map((rule) => {
|
|
679
|
+
return mergeStyleResults(rules.map((rule) => {
|
|
614
680
|
const result = {
|
|
615
681
|
selector: (Array.isArray(rule.selector) ? rule.selector : rule.selector ? [rule.selector] : [""]).map((part) => {
|
|
616
682
|
let sel = part ? `${classNameOrSelector}${part}` : classNameOrSelector;
|
|
@@ -624,18 +690,20 @@ function renderStyles(styles, classNameOrSelector, options) {
|
|
|
624
690
|
declarations: rule.declarations
|
|
625
691
|
};
|
|
626
692
|
if (rule.atRules && rule.atRules.length > 0) result.atRules = rule.atRules;
|
|
693
|
+
if (rule.startingStyle) result.startingStyle = true;
|
|
627
694
|
return result;
|
|
628
|
-
});
|
|
695
|
+
}));
|
|
629
696
|
}
|
|
630
697
|
return { rules: rules.map((r) => ({
|
|
631
698
|
selector: Array.isArray(r.selector) ? r.selector.join("|||") : r.selector,
|
|
632
699
|
declarations: r.declarations,
|
|
633
700
|
atRules: r.atRules,
|
|
634
701
|
needsClassName: true,
|
|
635
|
-
rootPrefix: r.rootPrefix
|
|
702
|
+
rootPrefix: r.rootPrefix,
|
|
703
|
+
startingStyle: r.startingStyle
|
|
636
704
|
})) };
|
|
637
705
|
}
|
|
638
706
|
|
|
639
707
|
//#endregion
|
|
640
|
-
export { clearPipelineCache, isSelector, renderStyles };
|
|
708
|
+
export { clearPipelineCache, hasPipelineCacheEntry, isSelector, renderStyles };
|
|
641
709
|
//# sourceMappingURL=index.js.map
|