@tenphi/tasty 0.0.0-snapshot.fafcbfe → 0.0.0-snapshot.ffe00e9
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/_virtual/_rolldown/runtime.js +1 -2
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +17 -10
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.d.ts +1 -1
- package/dist/chunks/definitions.js +3 -5
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +32 -34
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +357 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +116 -30
- package/dist/config.js +144 -45
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +12 -11
- package/dist/core/index.js +11 -10
- 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 +357 -637
- 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/index.d.ts +7 -0
- package/dist/hooks/useCounterStyle.d.ts +50 -0
- package/dist/hooks/useCounterStyle.js +45 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +43 -0
- package/dist/hooks/useFontFace.js +69 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +3 -0
- package/dist/hooks/useGlobalStyles.js +23 -2
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.js +13 -4
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.js +31 -14
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.js +8 -2
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +4 -4
- package/dist/hooks/useStyles.js +7 -147
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +23 -12
- package/dist/index.js +14 -11
- package/dist/injector/index.d.ts +41 -11
- package/dist/injector/index.js +48 -11
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +58 -3
- package/dist/injector/injector.js +204 -41
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +18 -17
- package/dist/injector/sheet-manager.js +45 -73
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +119 -19
- package/dist/keyframes/index.js +1 -1
- package/dist/parser/classify.js +6 -6
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/const.js +30 -3
- package/dist/parser/const.js.map +1 -1
- package/dist/parser/lru.js +1 -1
- package/dist/parser/lru.js.map +1 -1
- package/dist/parser/parser.js +2 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/types.js +1 -1
- package/dist/parser/types.js.map +1 -1
- package/dist/pipeline/conditions.js +15 -9
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/exclusive.js +1 -2
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +139 -72
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +405 -210
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +1 -1
- package/dist/pipeline/parseStateKey.js +38 -22
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +112 -154
- 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/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.js +3 -277
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +9 -2
- package/dist/properties/index.js +83 -19
- 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 +90 -0
- package/dist/properties/property-type-resolver.js.map +1 -0
- package/dist/ssr/astro.d.ts +29 -0
- package/dist/ssr/astro.js +64 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +34 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +39 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +102 -0
- package/dist/ssr/collector.js +219 -0
- package/dist/ssr/collector.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 +69 -0
- package/dist/ssr/format-keyframes.js.map +1 -0
- package/dist/ssr/format-property.js +49 -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 +49 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/index.d.ts +4 -0
- package/dist/ssr/index.js +10 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +43 -0
- package/dist/ssr/next.js +74 -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 +13 -259
- package/dist/states/index.js.map +1 -1
- package/dist/static/index.js +1 -2
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/static/tastyStatic.js +1 -2
- package/dist/static/tastyStatic.js.map +1 -1
- package/dist/static/types.js +1 -1
- package/dist/styles/border.d.ts +2 -2
- package/dist/styles/border.js +30 -24
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +3 -3
- package/dist/styles/color.js +11 -8
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +29 -27
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/dimension.js +15 -3
- package/dist/styles/dimension.js.map +1 -1
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +3 -10
- package/dist/styles/display.js +45 -39
- package/dist/styles/display.js.map +1 -1
- package/dist/styles/fade.d.ts +2 -2
- package/dist/styles/fade.js +9 -5
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +15 -17
- package/dist/styles/fill.js +9 -9
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.d.ts +3 -3
- package/dist/styles/flow.js +1 -1
- package/dist/styles/flow.js.map +1 -1
- package/dist/styles/gap.d.ts +1 -1
- package/dist/styles/gap.js +4 -3
- package/dist/styles/gap.js.map +1 -1
- package/dist/styles/height.d.ts +1 -1
- package/dist/styles/height.js +1 -2
- package/dist/styles/height.js.map +1 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +3 -4
- package/dist/styles/index.js.map +1 -1
- package/dist/styles/inset.d.ts +1 -29
- package/dist/styles/inset.js +19 -135
- package/dist/styles/inset.js.map +1 -1
- package/dist/styles/list.d.ts +5 -5
- package/dist/styles/list.js +4 -2
- package/dist/styles/list.js.map +1 -1
- package/dist/styles/margin.d.ts +1 -1
- package/dist/styles/margin.js +17 -89
- package/dist/styles/margin.js.map +1 -1
- package/dist/styles/outline.d.ts +1 -1
- package/dist/styles/outline.js +6 -16
- package/dist/styles/outline.js.map +1 -1
- package/dist/styles/padding.d.ts +1 -1
- package/dist/styles/padding.js +17 -89
- package/dist/styles/padding.js.map +1 -1
- package/dist/styles/placement.d.ts +37 -0
- package/dist/styles/placement.js +74 -0
- package/dist/styles/placement.js.map +1 -0
- package/dist/styles/predefined.d.ts +4 -6
- package/dist/styles/predefined.js +9 -13
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.d.ts +6 -1
- package/dist/styles/preset.js +54 -53
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/radius.d.ts +2 -4
- package/dist/styles/radius.js +38 -6
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollMargin.d.ts +24 -0
- package/dist/styles/scrollMargin.js +32 -0
- package/dist/styles/scrollMargin.js.map +1 -0
- package/dist/styles/scrollbar.d.ts +9 -5
- package/dist/styles/scrollbar.js +31 -85
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +3 -3
- package/dist/styles/shadow.js +4 -3
- package/dist/styles/shadow.js.map +1 -1
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +2 -2
- package/dist/styles/transition.js +6 -5
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +94 -28
- package/dist/styles/width.d.ts +1 -1
- package/dist/styles/width.js +1 -2
- package/dist/styles/width.js.map +1 -1
- package/dist/tasty.d.ts +46 -894
- package/dist/tasty.js +112 -60
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/utils/cache-wrapper.js +4 -9
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/case-converter.js +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 +228 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.d.ts +1 -1
- package/dist/utils/colors.js +3 -2
- 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/dotize.js +1 -1
- package/dist/utils/dotize.js.map +1 -1
- package/dist/utils/filter-base-props.js +1 -1
- package/dist/utils/get-display-name.js +1 -1
- package/dist/utils/has-keys.js +13 -0
- package/dist/utils/has-keys.js.map +1 -0
- package/dist/utils/is-dev-env.js +1 -1
- package/dist/utils/is-dev-env.js.map +1 -1
- package/dist/utils/is-valid-element-type.js +1 -1
- package/dist/utils/merge-styles.js +1 -2
- package/dist/utils/merge-styles.js.map +1 -1
- package/dist/utils/mod-attrs.d.ts +0 -2
- package/dist/utils/mod-attrs.js +3 -4
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +3 -17
- package/dist/utils/process-tokens.js +19 -107
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/resolve-recipes.js +1 -2
- package/dist/utils/resolve-recipes.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 +1 -1
- package/dist/utils/string.js.map +1 -1
- package/dist/utils/styles.d.ts +5 -89
- package/dist/utils/styles.js +35 -400
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +24 -13
- package/dist/utils/typography.js +15 -17
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +84 -10
- package/dist/zero/babel.js +193 -37
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/css-writer.js +1 -2
- package/dist/zero/css-writer.js.map +1 -1
- package/dist/zero/extractor.js +119 -3
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/index.js +1 -2
- package/dist/zero/next.d.ts +56 -30
- package/dist/zero/next.js +105 -40
- 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 +543 -0
- package/docs/methodology.md +616 -0
- package/docs/runtime.md +572 -0
- package/docs/ssr.md +354 -0
- package/docs/styles.md +596 -0
- package/docs/tasty-static.md +520 -0
- package/package.json +106 -31
- package/dist/styles/align.d.ts +0 -15
- package/dist/styles/align.js +0 -14
- package/dist/styles/align.js.map +0 -1
- package/dist/styles/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.js.map +0 -1
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exclusive.js","names":[],"sources":["../../src/pipeline/exclusive.ts"],"sourcesContent":["/**\n * Exclusive Condition Builder\n *\n * Transforms parsed style entries into exclusive conditions.\n * Each entry's condition is ANDed with the negation of all higher-priority conditions,\n * ensuring exactly one condition matches at any given time.\n */\n\nimport type { StyleValue } from '../utils/styles';\n\nimport type { ConditionNode } from './conditions';\nimport { and, isCompoundCondition, not, trueCondition } from './conditions';\nimport { simplifyCondition } from './simplify';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Parsed style entry with condition\n */\nexport interface ParsedStyleEntry {\n styleKey: string; // e.g., 'padding', 'fill'\n stateKey: string; // Original key: '', 'compact', '@media(w < 768px)'\n value: StyleValue; // The style value (before handler processing)\n condition: ConditionNode; // Parsed condition tree\n priority: number; // Order in original object (higher = higher priority)\n}\n\n/**\n * Style entry with exclusive condition\n */\nexport interface ExclusiveStyleEntry extends ParsedStyleEntry {\n exclusiveCondition: ConditionNode; // condition & !higherPriorityConditions\n}\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Build exclusive conditions for a list of parsed style entries.\n *\n * The entries should be ordered by priority (highest priority first).\n *\n * For each entry, we compute:\n * exclusiveCondition = condition & !prior[0] & !prior[1] & ...\n *\n * This ensures exactly one condition matches at any time.\n *\n * Example:\n * Input (ordered highest to lowest priority):\n * A: value1 (priority 2)\n * B: value2 (priority 1)\n * C: value3 (priority 0)\n *\n * Output:\n * A: A\n * B: B & !A\n * C: C & !A & !B\n *\n * @param entries Parsed style entries ordered by priority (highest first)\n * @returns Entries with exclusive conditions, filtered to remove impossible ones\n */\nexport function buildExclusiveConditions(\n entries: ParsedStyleEntry[],\n): ExclusiveStyleEntry[] {\n const result: ExclusiveStyleEntry[] = [];\n const priorConditions: ConditionNode[] = [];\n\n for (const entry of entries) {\n // Build: condition & !prior[0] & !prior[1] & ...\n let exclusive: ConditionNode = entry.condition;\n\n for (const prior of priorConditions) {\n // Skip negating \"always true\" (default state) - it would become \"always false\"\n if (prior.kind !== 'true') {\n exclusive = and(exclusive, not(prior));\n }\n }\n\n // Simplify the exclusive condition\n const simplified = simplifyCondition(exclusive);\n\n // Skip impossible conditions (simplified to FALSE)\n if (simplified.kind === 'false') {\n continue;\n }\n\n result.push({\n ...entry,\n exclusiveCondition: simplified,\n });\n\n // Add non-default conditions to prior list for subsequent entries\n if (entry.condition.kind !== 'true') {\n priorConditions.push(entry.condition);\n }\n }\n\n return result;\n}\n\n/**\n * Parse style entries from a value mapping object.\n *\n * @param styleKey The style key (e.g., 'padding')\n * @param valueMap The value mapping { '': '2x', 'compact': '1x', '@media(w < 768px)': '0.5x' }\n * @param parseCondition Function to parse state keys into conditions\n * @returns Parsed entries ordered by priority (highest first)\n */\nexport function parseStyleEntries(\n styleKey: string,\n valueMap: Record<string, StyleValue>,\n parseCondition: (stateKey: string) => ConditionNode,\n): ParsedStyleEntry[] {\n const entries: ParsedStyleEntry[] = [];\n const keys = Object.keys(valueMap);\n\n keys.forEach((stateKey, index) => {\n const value = valueMap[stateKey];\n const condition =\n stateKey === '' ? trueCondition() : parseCondition(stateKey);\n\n entries.push({\n styleKey,\n stateKey,\n value,\n condition,\n priority: index,\n });\n });\n\n // Reverse so highest priority (last in object) comes first for exclusive building\n // buildExclusiveConditions expects highest priority first\n entries.reverse();\n\n return entries;\n}\n\n/**\n * Check if a value is a style value mapping (object with state keys)\n */\nexport function isValueMapping(\n value: StyleValue | Record<string, StyleValue>,\n): value is Record<string, StyleValue> {\n return (\n value !== null &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n !(value instanceof Date)\n );\n}\n\n// ============================================================================\n// OR Expansion\n// ============================================================================\n\n/**\n * Expand OR conditions in parsed entries into multiple exclusive entries.\n *\n * For an entry with condition `A | B | C`, this creates 3 entries:\n * - condition: A\n * - condition: B & !A\n * - condition: C & !A & !B\n *\n * This ensures OR branches are mutually exclusive BEFORE the main\n * exclusive condition building pass.\n *\n * @param entries Parsed entries (may contain OR conditions)\n * @returns Expanded entries with OR branches made exclusive\n */\nexport function expandOrConditions(\n entries: ParsedStyleEntry[],\n): ParsedStyleEntry[] {\n const result: ParsedStyleEntry[] = [];\n\n for (const entry of entries) {\n const expanded = expandSingleEntry(entry);\n result.push(...expanded);\n }\n\n return result;\n}\n\n/**\n * Expand a single entry's OR condition into multiple exclusive entries\n */\nfunction expandSingleEntry(entry: ParsedStyleEntry): ParsedStyleEntry[] {\n const orBranches = collectOrBranches(entry.condition);\n\n // If no OR (single branch), return as-is\n if (orBranches.length <= 1) {\n return [entry];\n }\n\n // Make each OR branch exclusive from prior branches\n const result: ParsedStyleEntry[] = [];\n const priorBranches: ConditionNode[] = [];\n\n for (let i = 0; i < orBranches.length; i++) {\n const branch = orBranches[i];\n\n // Build: branch & !prior[0] & !prior[1] & ...\n let exclusiveBranch: ConditionNode = branch;\n for (const prior of priorBranches) {\n exclusiveBranch = and(exclusiveBranch, not(prior));\n }\n\n // Simplify to detect impossible combinations\n const simplified = simplifyCondition(exclusiveBranch);\n\n // Skip impossible branches\n if (simplified.kind === 'false') {\n priorBranches.push(branch);\n continue;\n }\n\n result.push({\n ...entry,\n stateKey: `${entry.stateKey}[${i}]`, // Mark as expanded branch\n condition: simplified,\n // Keep same priority - all branches from same entry have same priority\n });\n\n priorBranches.push(branch);\n }\n\n return result;\n}\n\n/**\n * Collect top-level OR branches from a condition.\n *\n * For `A | B | C`, returns [A, B, C]\n * For `A & B`, returns [A & B] (single branch)\n * For `A | (B & C)`, returns [A, B & C]\n */\nfunction collectOrBranches(condition: ConditionNode): ConditionNode[] {\n if (condition.kind === 'true' || condition.kind === 'false') {\n return [condition];\n }\n\n if (isCompoundCondition(condition) && condition.operator === 'OR') {\n // Flatten nested ORs\n const branches: ConditionNode[] = [];\n for (const child of condition.children) {\n branches.push(...collectOrBranches(child));\n }\n return branches;\n }\n\n // Not an OR - return as single branch\n return [condition];\n}\n\n// ============================================================================\n// Post-Build OR Expansion (for De Morgan ORs)\n// ============================================================================\n\n/**\n * Expand OR conditions in exclusive entries AFTER buildExclusiveConditions.\n *\n * This handles ORs that arise from De Morgan expansion during negation:\n * !(A & B) = !A | !B\n *\n * These ORs need to be made exclusive to avoid overlapping CSS rules:\n * !A | !B → !A | (A & !B)\n *\n * This is logically equivalent but ensures each branch has proper context.\n *\n * Example:\n * Input: { \"\": V1, \"@supports(...) & :has()\": V2 }\n * V2's exclusive = @supports & :has\n * V1's exclusive = !(@supports & :has) = !@supports | !:has\n *\n * Without this fix: V1 gets two rules:\n * - @supports (not ...) → V1 ✓\n * - :not(:has()) → V1 ✗ (missing @supports context!)\n *\n * With this fix: V1 gets two exclusive rules:\n * - @supports (not ...) → V1 ✓\n * - @supports (...) { :not(:has()) } → V1 ✓ (proper context!)\n */\nexport function expandExclusiveOrs(\n entries: ExclusiveStyleEntry[],\n): ExclusiveStyleEntry[] {\n const result: ExclusiveStyleEntry[] = [];\n\n for (const entry of entries) {\n const expanded = expandExclusiveConditionOrs(entry);\n result.push(...expanded);\n }\n\n return result;\n}\n\n/**\n * Check if a condition involves at-rules (media, container, supports, starting)\n */\nfunction hasAtRuleContext(node: ConditionNode): boolean {\n if (node.kind === 'true' || node.kind === 'false') {\n return false;\n }\n\n if (node.kind === 'state') {\n // These condition types generate at-rules\n return (\n node.type === 'media' ||\n node.type === 'container' ||\n node.type === 'supports' ||\n node.type === 'starting'\n );\n }\n\n if (node.kind === 'compound') {\n return node.children.some(hasAtRuleContext);\n }\n\n return false;\n}\n\n/**\n * Sort OR branches to prioritize at-rule conditions first.\n *\n * This is critical for correct CSS generation. For `!A | !B` where A is at-rule\n * and B is modifier, we want:\n * - Branch 0: !A (at-rule negation - covers \"no @supports/media\" case)\n * - Branch 1: A & !B (modifier negation with at-rule context)\n *\n * If we process in wrong order (!B first), we'd get:\n * - Branch 0: !B (modifier negation WITHOUT at-rule context - WRONG!)\n * - Branch 1: B & !A (at-rule negation with modifier - incomplete coverage)\n */\nfunction sortOrBranchesForExpansion(\n branches: ConditionNode[],\n): ConditionNode[] {\n return [...branches].sort((a, b) => {\n const aHasAtRule = hasAtRuleContext(a);\n const bHasAtRule = hasAtRuleContext(b);\n\n // At-rule conditions come first\n if (aHasAtRule && !bHasAtRule) return -1;\n if (!aHasAtRule && bHasAtRule) return 1;\n\n // Same type - keep original order (stable sort)\n return 0;\n });\n}\n\n/**\n * Expand ORs in a single entry's exclusive condition\n */\nfunction expandExclusiveConditionOrs(\n entry: ExclusiveStyleEntry,\n): ExclusiveStyleEntry[] {\n let orBranches = collectOrBranches(entry.exclusiveCondition);\n\n // If no OR (single branch), return as-is\n if (orBranches.length <= 1) {\n return [entry];\n }\n\n // Sort branches so at-rule conditions come first\n // This ensures proper context inheritance during expansion\n orBranches = sortOrBranchesForExpansion(orBranches);\n\n // Make each OR branch exclusive from prior branches\n const result: ExclusiveStyleEntry[] = [];\n const priorBranches: ConditionNode[] = [];\n\n for (let i = 0; i < orBranches.length; i++) {\n const branch = orBranches[i];\n\n // Build: branch & !prior[0] & !prior[1] & ...\n // This transforms: !A | !B → !A, !B & !!A = !A, (A & !B)\n let exclusiveBranch: ConditionNode = branch;\n for (const prior of priorBranches) {\n exclusiveBranch = and(exclusiveBranch, not(prior));\n }\n\n // Simplify to detect impossible combinations and clean up double negations\n const simplified = simplifyCondition(exclusiveBranch);\n\n // Skip impossible branches\n if (simplified.kind === 'false') {\n priorBranches.push(branch);\n continue;\n }\n\n result.push({\n ...entry,\n stateKey: `${entry.stateKey}[or:${i}]`, // Mark as expanded OR branch\n exclusiveCondition: simplified,\n });\n\n priorBranches.push(branch);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,yBACd,SACuB;CACvB,MAAM,SAAgC,EAAE;CACxC,MAAM,kBAAmC,EAAE;AAE3C,MAAK,MAAM,SAAS,SAAS;EAE3B,IAAI,YAA2B,MAAM;AAErC,OAAK,MAAM,SAAS,gBAElB,KAAI,MAAM,SAAS,OACjB,aAAY,IAAI,WAAW,IAAI,MAAM,CAAC;EAK1C,MAAM,aAAa,kBAAkB,UAAU;AAG/C,MAAI,WAAW,SAAS,QACtB;AAGF,SAAO,KAAK;GACV,GAAG;GACH,oBAAoB;GACrB,CAAC;AAGF,MAAI,MAAM,UAAU,SAAS,OAC3B,iBAAgB,KAAK,MAAM,UAAU;;AAIzC,QAAO;;;;;;;;;;AAWT,SAAgB,kBACd,UACA,UACA,gBACoB;CACpB,MAAM,UAA8B,EAAE;AAGtC,CAFa,OAAO,KAAK,SAAS,CAE7B,SAAS,UAAU,UAAU;EAChC,MAAM,QAAQ,SAAS;EACvB,MAAM,YACJ,aAAa,KAAK,eAAe,GAAG,eAAe,SAAS;AAE9D,UAAQ,KAAK;GACX;GACA;GACA;GACA;GACA,UAAU;GACX,CAAC;GACF;AAIF,SAAQ,SAAS;AAEjB,QAAO;;;;;AA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OAAO;;AAG5B,QAAO"}
|
|
1
|
+
{"version":3,"file":"exclusive.js","names":[],"sources":["../../src/pipeline/exclusive.ts"],"sourcesContent":["/**\n * Exclusive Condition Builder\n *\n * Transforms parsed style entries into exclusive conditions.\n * Each entry's condition is ANDed with the negation of all higher-priority conditions,\n * ensuring exactly one condition matches at any given time.\n */\n\nimport type { StyleValue } from '../utils/styles';\n\nimport type { ConditionNode } from './conditions';\nimport { and, isCompoundCondition, not, trueCondition } from './conditions';\nimport { simplifyCondition } from './simplify';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Parsed style entry with condition\n */\nexport interface ParsedStyleEntry {\n styleKey: string; // e.g., 'padding', 'fill'\n stateKey: string; // Original key: '', 'compact', '@media(w < 768px)'\n value: StyleValue; // The style value (before handler processing)\n condition: ConditionNode; // Parsed condition tree\n priority: number; // Order in original object (higher = higher priority)\n}\n\n/**\n * Style entry with exclusive condition\n */\nexport interface ExclusiveStyleEntry extends ParsedStyleEntry {\n exclusiveCondition: ConditionNode; // condition & !higherPriorityConditions\n}\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Build exclusive conditions for a list of parsed style entries.\n *\n * The entries should be ordered by priority (highest priority first).\n *\n * For each entry, we compute:\n * exclusiveCondition = condition & !prior[0] & !prior[1] & ...\n *\n * This ensures exactly one condition matches at any time.\n *\n * Example:\n * Input (ordered highest to lowest priority):\n * A: value1 (priority 2)\n * B: value2 (priority 1)\n * C: value3 (priority 0)\n *\n * Output:\n * A: A\n * B: B & !A\n * C: C & !A & !B\n *\n * @param entries Parsed style entries ordered by priority (highest first)\n * @returns Entries with exclusive conditions, filtered to remove impossible ones\n */\nexport function buildExclusiveConditions(\n entries: ParsedStyleEntry[],\n): ExclusiveStyleEntry[] {\n const result: ExclusiveStyleEntry[] = [];\n const priorConditions: ConditionNode[] = [];\n\n for (const entry of entries) {\n // Build: condition & !prior[0] & !prior[1] & ...\n let exclusive: ConditionNode = entry.condition;\n\n for (const prior of priorConditions) {\n // Skip negating \"always true\" (default state) - it would become \"always false\"\n if (prior.kind !== 'true') {\n exclusive = and(exclusive, not(prior));\n }\n }\n\n // Simplify the exclusive condition\n const simplified = simplifyCondition(exclusive);\n\n // Skip impossible conditions (simplified to FALSE)\n if (simplified.kind === 'false') {\n continue;\n }\n\n result.push({\n ...entry,\n exclusiveCondition: simplified,\n });\n\n // Add non-default conditions to prior list for subsequent entries\n if (entry.condition.kind !== 'true') {\n priorConditions.push(entry.condition);\n }\n }\n\n return result;\n}\n\n/**\n * Parse style entries from a value mapping object.\n *\n * @param styleKey The style key (e.g., 'padding')\n * @param valueMap The value mapping { '': '2x', 'compact': '1x', '@media(w < 768px)': '0.5x' }\n * @param parseCondition Function to parse state keys into conditions\n * @returns Parsed entries ordered by priority (highest first)\n */\nexport function parseStyleEntries(\n styleKey: string,\n valueMap: Record<string, StyleValue>,\n parseCondition: (stateKey: string) => ConditionNode,\n): ParsedStyleEntry[] {\n const entries: ParsedStyleEntry[] = [];\n const keys = Object.keys(valueMap);\n\n keys.forEach((stateKey, index) => {\n const value = valueMap[stateKey];\n const condition =\n stateKey === '' ? trueCondition() : parseCondition(stateKey);\n\n entries.push({\n styleKey,\n stateKey,\n value,\n condition,\n priority: index,\n });\n });\n\n // Reverse so highest priority (last in object) comes first for exclusive building\n // buildExclusiveConditions expects highest priority first\n entries.reverse();\n\n return entries;\n}\n\n/**\n * Check if a value is a style value mapping (object with state keys)\n */\nexport function isValueMapping(\n value: StyleValue | Record<string, StyleValue>,\n): value is Record<string, StyleValue> {\n return (\n value !== null &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n !(value instanceof Date)\n );\n}\n\n// ============================================================================\n// OR Expansion\n// ============================================================================\n\n/**\n * Expand OR conditions in parsed entries into multiple exclusive entries.\n *\n * For an entry with condition `A | B | C`, this creates 3 entries:\n * - condition: A\n * - condition: B & !A\n * - condition: C & !A & !B\n *\n * This ensures OR branches are mutually exclusive BEFORE the main\n * exclusive condition building pass.\n *\n * @param entries Parsed entries (may contain OR conditions)\n * @returns Expanded entries with OR branches made exclusive\n */\nexport function expandOrConditions(\n entries: ParsedStyleEntry[],\n): ParsedStyleEntry[] {\n const result: ParsedStyleEntry[] = [];\n\n for (const entry of entries) {\n const expanded = expandSingleEntry(entry);\n result.push(...expanded);\n }\n\n return result;\n}\n\n/**\n * Expand a single entry's OR condition into multiple exclusive entries\n */\nfunction expandSingleEntry(entry: ParsedStyleEntry): ParsedStyleEntry[] {\n const orBranches = collectOrBranches(entry.condition);\n\n // If no OR (single branch), return as-is\n if (orBranches.length <= 1) {\n return [entry];\n }\n\n // Make each OR branch exclusive from prior branches\n const result: ParsedStyleEntry[] = [];\n const priorBranches: ConditionNode[] = [];\n\n for (let i = 0; i < orBranches.length; i++) {\n const branch = orBranches[i];\n\n // Build: branch & !prior[0] & !prior[1] & ...\n let exclusiveBranch: ConditionNode = branch;\n for (const prior of priorBranches) {\n exclusiveBranch = and(exclusiveBranch, not(prior));\n }\n\n // Simplify to detect impossible combinations\n const simplified = simplifyCondition(exclusiveBranch);\n\n // Skip impossible branches\n if (simplified.kind === 'false') {\n priorBranches.push(branch);\n continue;\n }\n\n result.push({\n ...entry,\n stateKey: `${entry.stateKey}[${i}]`, // Mark as expanded branch\n condition: simplified,\n // Keep same priority - all branches from same entry have same priority\n });\n\n priorBranches.push(branch);\n }\n\n return result;\n}\n\n/**\n * Collect top-level OR branches from a condition.\n *\n * For `A | B | C`, returns [A, B, C]\n * For `A & B`, returns [A & B] (single branch)\n * For `A | (B & C)`, returns [A, B & C]\n */\nfunction collectOrBranches(condition: ConditionNode): ConditionNode[] {\n if (condition.kind === 'true' || condition.kind === 'false') {\n return [condition];\n }\n\n if (isCompoundCondition(condition) && condition.operator === 'OR') {\n // Flatten nested ORs\n const branches: ConditionNode[] = [];\n for (const child of condition.children) {\n branches.push(...collectOrBranches(child));\n }\n return branches;\n }\n\n // Not an OR - return as single branch\n return [condition];\n}\n\n// ============================================================================\n// Post-Build OR Expansion (for De Morgan ORs)\n// ============================================================================\n\n/**\n * Expand OR conditions in exclusive entries AFTER buildExclusiveConditions.\n *\n * This handles ORs that arise from De Morgan expansion during negation:\n * !(A & B) = !A | !B\n *\n * These ORs need to be made exclusive to avoid overlapping CSS rules:\n * !A | !B → !A | (A & !B)\n *\n * This is logically equivalent but ensures each branch has proper context.\n *\n * Example:\n * Input: { \"\": V1, \"@supports(...) & :has()\": V2 }\n * V2's exclusive = @supports & :has\n * V1's exclusive = !(@supports & :has) = !@supports | !:has\n *\n * Without this fix: V1 gets two rules:\n * - @supports (not ...) → V1 ✓\n * - :not(:has()) → V1 ✗ (missing @supports context!)\n *\n * With this fix: V1 gets two exclusive rules:\n * - @supports (not ...) → V1 ✓\n * - @supports (...) { :not(:has()) } → V1 ✓ (proper context!)\n */\nexport function expandExclusiveOrs(\n entries: ExclusiveStyleEntry[],\n): ExclusiveStyleEntry[] {\n const result: ExclusiveStyleEntry[] = [];\n\n for (const entry of entries) {\n const expanded = expandExclusiveConditionOrs(entry);\n result.push(...expanded);\n }\n\n return result;\n}\n\n/**\n * Check if a condition involves at-rules (media, container, supports, starting)\n */\nfunction hasAtRuleContext(node: ConditionNode): boolean {\n if (node.kind === 'true' || node.kind === 'false') {\n return false;\n }\n\n if (node.kind === 'state') {\n // These condition types generate at-rules\n return (\n node.type === 'media' ||\n node.type === 'container' ||\n node.type === 'supports' ||\n node.type === 'starting'\n );\n }\n\n if (node.kind === 'compound') {\n return node.children.some(hasAtRuleContext);\n }\n\n return false;\n}\n\n/**\n * Sort OR branches to prioritize at-rule conditions first.\n *\n * This is critical for correct CSS generation. For `!A | !B` where A is at-rule\n * and B is modifier, we want:\n * - Branch 0: !A (at-rule negation - covers \"no @supports/media\" case)\n * - Branch 1: A & !B (modifier negation with at-rule context)\n *\n * If we process in wrong order (!B first), we'd get:\n * - Branch 0: !B (modifier negation WITHOUT at-rule context - WRONG!)\n * - Branch 1: B & !A (at-rule negation with modifier - incomplete coverage)\n */\nfunction sortOrBranchesForExpansion(\n branches: ConditionNode[],\n): ConditionNode[] {\n return [...branches].sort((a, b) => {\n const aHasAtRule = hasAtRuleContext(a);\n const bHasAtRule = hasAtRuleContext(b);\n\n // At-rule conditions come first\n if (aHasAtRule && !bHasAtRule) return -1;\n if (!aHasAtRule && bHasAtRule) return 1;\n\n // Same type - keep original order (stable sort)\n return 0;\n });\n}\n\n/**\n * Expand ORs in a single entry's exclusive condition\n */\nfunction expandExclusiveConditionOrs(\n entry: ExclusiveStyleEntry,\n): ExclusiveStyleEntry[] {\n let orBranches = collectOrBranches(entry.exclusiveCondition);\n\n // If no OR (single branch), return as-is\n if (orBranches.length <= 1) {\n return [entry];\n }\n\n // Sort branches so at-rule conditions come first\n // This ensures proper context inheritance during expansion\n orBranches = sortOrBranchesForExpansion(orBranches);\n\n // Make each OR branch exclusive from prior branches\n const result: ExclusiveStyleEntry[] = [];\n const priorBranches: ConditionNode[] = [];\n\n for (let i = 0; i < orBranches.length; i++) {\n const branch = orBranches[i];\n\n // Build: branch & !prior[0] & !prior[1] & ...\n // This transforms: !A | !B → !A, !B & !!A = !A, (A & !B)\n let exclusiveBranch: ConditionNode = branch;\n for (const prior of priorBranches) {\n exclusiveBranch = and(exclusiveBranch, not(prior));\n }\n\n // Simplify to detect impossible combinations and clean up double negations\n const simplified = simplifyCondition(exclusiveBranch);\n\n // Skip impossible branches\n if (simplified.kind === 'false') {\n priorBranches.push(branch);\n continue;\n }\n\n result.push({\n ...entry,\n stateKey: `${entry.stateKey}[or:${i}]`, // Mark as expanded OR branch\n exclusiveCondition: simplified,\n });\n\n priorBranches.push(branch);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,yBACd,SACuB;CACvB,MAAM,SAAgC,EAAE;CACxC,MAAM,kBAAmC,EAAE;AAE3C,MAAK,MAAM,SAAS,SAAS;EAE3B,IAAI,YAA2B,MAAM;AAErC,OAAK,MAAM,SAAS,gBAElB,KAAI,MAAM,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,aAAa,kBAAkB,MAAM,mBAAmB;AAG5D,KAAI,WAAW,UAAU,EACvB,QAAO,CAAC,MAAM;AAKhB,cAAa,2BAA2B,WAAW;CAGnD,MAAM,SAAgC,EAAE;CACxC,MAAM,gBAAiC,EAAE;AAEzC,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;EAC1C,MAAM,SAAS,WAAW;EAI1B,IAAI,kBAAiC;AACrC,OAAK,MAAM,SAAS,cAClB,mBAAkB,IAAI,iBAAiB,IAAI,MAAM,CAAC;EAIpD,MAAM,aAAa,kBAAkB,gBAAgB;AAGrD,MAAI,WAAW,SAAS,SAAS;AAC/B,iBAAc,KAAK,OAAO;AAC1B;;AAGF,SAAO,KAAK;GACV,GAAG;GACH,UAAU,GAAG,MAAM,SAAS,MAAM,EAAE;GACpC,oBAAoB;GACrB,CAAC;AAEF,gBAAc,KAAK,OAAO;;AAG5B,QAAO"}
|
package/dist/pipeline/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ interface StyleResult {
|
|
|
12
12
|
atRules?: string[];
|
|
13
13
|
needsClassName?: boolean;
|
|
14
14
|
rootPrefix?: string;
|
|
15
|
+
/** When true, declarations are wrapped in @starting-style { ... } inside the selector rule */
|
|
16
|
+
startingStyle?: boolean;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Matches the old RenderResult interface for backward compatibility
|
|
@@ -46,7 +48,7 @@ interface RenderStylesOptions {
|
|
|
46
48
|
* When called without classNameOrSelector, returns RenderResult with needsClassName=true.
|
|
47
49
|
* When called with a selector/className string, returns StyleResult[] for direct injection.
|
|
48
50
|
*/
|
|
49
|
-
declare function renderStyles(styles?: Styles): RenderResult;
|
|
51
|
+
declare function renderStyles(styles?: Styles, classNameOrSelector?: undefined, options?: undefined, pipelineCacheKey?: string): RenderResult;
|
|
50
52
|
declare function renderStyles(styles: Styles | undefined, classNameOrSelector: string, options?: RenderStylesOptions): StyleResult[];
|
|
51
53
|
//#endregion
|
|
52
54
|
export { RenderResult, StyleResult, isSelector, renderStyles };
|
package/dist/pipeline/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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";
|
|
6
|
-
import {
|
|
5
|
+
import { createStateParserContext, extractLocalPredefinedStates } from "../states/index.js";
|
|
6
|
+
import { and, 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
|
//#region src/pipeline/index.ts
|
|
13
13
|
/**
|
|
14
14
|
* Tasty Style Rendering Pipeline
|
|
@@ -27,6 +27,13 @@ import { parseStateKey } from "./parseStateKey.js";
|
|
|
27
27
|
*/
|
|
28
28
|
const pipelineCache = new Lru(5e3);
|
|
29
29
|
/**
|
|
30
|
+
* Check if a cache key exists in the pipeline cache.
|
|
31
|
+
* Used by renderStylesForChunk to avoid building filtered styles on cache hit.
|
|
32
|
+
*/
|
|
33
|
+
function hasPipelineCacheEntry(cacheKey) {
|
|
34
|
+
return pipelineCache.get(cacheKey) !== void 0;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
30
37
|
* Clear the pipeline cache (for testing)
|
|
31
38
|
*/
|
|
32
39
|
function clearPipelineCache() {
|
|
@@ -36,12 +43,17 @@ function runPipeline(styles, parserContext) {
|
|
|
36
43
|
const allRules = [];
|
|
37
44
|
processStyles(styles, "", parserContext, allRules);
|
|
38
45
|
const seen = /* @__PURE__ */ new Set();
|
|
39
|
-
|
|
40
|
-
const key = `${rule.selector}|${rule.declarations}|${
|
|
46
|
+
const dedupedRules = allRules.filter((rule) => {
|
|
47
|
+
const key = `${rule.selector}|${rule.declarations}|${rule.atRules?.join("|") ?? ""}|${rule.rootPrefix || ""}|${rule.startingStyle ? "1" : "0"}`;
|
|
41
48
|
if (seen.has(key)) return false;
|
|
42
49
|
seen.add(key);
|
|
43
50
|
return true;
|
|
44
51
|
});
|
|
52
|
+
const normal = [];
|
|
53
|
+
const starting = [];
|
|
54
|
+
for (const rule of dedupedRules) if (rule.startingStyle) starting.push(rule);
|
|
55
|
+
else normal.push(rule);
|
|
56
|
+
return normal.concat(starting);
|
|
45
57
|
}
|
|
46
58
|
/**
|
|
47
59
|
* Process styles at a given nesting level
|
|
@@ -147,7 +159,7 @@ function getAllSelectors(key, styles) {
|
|
|
147
159
|
if (affix !== void 0) {
|
|
148
160
|
const result = processAffix(String(affix), key);
|
|
149
161
|
if (!result.valid) {
|
|
150
|
-
|
|
162
|
+
emitWarning("INVALID_SELECTOR_AFFIX", result.reason);
|
|
151
163
|
return null;
|
|
152
164
|
}
|
|
153
165
|
return result.selectors;
|
|
@@ -162,7 +174,8 @@ function getAllSelectors(key, styles) {
|
|
|
162
174
|
* Supports:
|
|
163
175
|
* - Direct child: '>'
|
|
164
176
|
* - Chained elements: '>Body>Row>'
|
|
165
|
-
* - HTML tags: '
|
|
177
|
+
* - HTML tags (no key injection): 'h1', '>ul>li', 'button:hover'
|
|
178
|
+
* - Universal selector: '*', 'h1 *'
|
|
166
179
|
* - Pseudo-elements on root: '::before'
|
|
167
180
|
* - Pseudo on sub-element: '@::before', '>@:hover'
|
|
168
181
|
* - Classes: '.active', '>@.active'
|
|
@@ -199,6 +212,7 @@ function processAffix(affix, key) {
|
|
|
199
212
|
*/
|
|
200
213
|
const VALID_TOKEN_PATTERNS = [
|
|
201
214
|
/^[>+~]/,
|
|
215
|
+
/^\*/,
|
|
202
216
|
/^[A-Z][a-zA-Z0-9]*/,
|
|
203
217
|
/^@/,
|
|
204
218
|
/^::?[a-z][a-z0-9-]*(?:\([^)]*\))?/,
|
|
@@ -333,12 +347,13 @@ function processSinglePattern(pattern, key) {
|
|
|
333
347
|
* The tokenizer handles these token types in order:
|
|
334
348
|
* 1. Whitespace (skipped)
|
|
335
349
|
* 2. Combinators: >, +, ~ (add surrounding spaces)
|
|
336
|
-
* 3.
|
|
337
|
-
* 4.
|
|
338
|
-
* 5.
|
|
339
|
-
* 6.
|
|
340
|
-
* 7.
|
|
341
|
-
* 8.
|
|
350
|
+
* 3. Universal selector: * (keep as-is with spacing)
|
|
351
|
+
* 4. Uppercase names: Body, Row (convert to [data-element="..."])
|
|
352
|
+
* 5. @ placeholder (keep for later replacement)
|
|
353
|
+
* 6. Pseudo: :hover, ::before (attach to previous token)
|
|
354
|
+
* 7. Tags: a, div, button (keep as-is with spacing)
|
|
355
|
+
* 8. Classes: .active (attach to previous element/tag/placeholder)
|
|
356
|
+
* 9. Attributes: [type="text"] (keep as-is)
|
|
342
357
|
*
|
|
343
358
|
* @param pattern - The raw selector pattern to transform
|
|
344
359
|
* @returns Transformed pattern with proper CSS selector syntax
|
|
@@ -352,6 +367,7 @@ function processSinglePattern(pattern, key) {
|
|
|
352
367
|
*/
|
|
353
368
|
function transformPattern(pattern) {
|
|
354
369
|
let result = "";
|
|
370
|
+
let lastCh = "";
|
|
355
371
|
let i = 0;
|
|
356
372
|
while (i < pattern.length) {
|
|
357
373
|
const char = pattern[i];
|
|
@@ -360,76 +376,80 @@ function transformPattern(pattern) {
|
|
|
360
376
|
continue;
|
|
361
377
|
}
|
|
362
378
|
if (/[>+~]/.test(char)) {
|
|
363
|
-
if (result &&
|
|
379
|
+
if (result && lastCh !== " ") result += " ";
|
|
364
380
|
result += char;
|
|
381
|
+
lastCh = char;
|
|
382
|
+
i++;
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (char === "*") {
|
|
386
|
+
if (result && lastCh !== " ") result += " ";
|
|
387
|
+
result += "*";
|
|
388
|
+
lastCh = "*";
|
|
365
389
|
i++;
|
|
366
390
|
continue;
|
|
367
391
|
}
|
|
368
392
|
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}"]`;
|
|
393
|
+
const nameStart = i;
|
|
394
|
+
while (i < pattern.length && /[a-zA-Z0-9]/.test(pattern[i])) i++;
|
|
395
|
+
if (result && lastCh !== " ") result += " ";
|
|
396
|
+
const segment = `[data-element="${pattern.slice(nameStart, i)}"]`;
|
|
397
|
+
result += segment;
|
|
398
|
+
lastCh = "]";
|
|
376
399
|
continue;
|
|
377
400
|
}
|
|
378
401
|
if (char === "@") {
|
|
379
|
-
if (result &&
|
|
402
|
+
if (result && lastCh !== " ") result += " ";
|
|
380
403
|
result += "@";
|
|
404
|
+
lastCh = "@";
|
|
381
405
|
i++;
|
|
382
406
|
continue;
|
|
383
407
|
}
|
|
384
408
|
if (char === ":") {
|
|
385
|
-
|
|
386
|
-
while (i < pattern.length && !/[\s>+~,@]/.test(pattern[i]) && !/[A-Z]/.test(pattern[i]))
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
result += pseudo;
|
|
409
|
+
const pseudoStart = i;
|
|
410
|
+
while (i < pattern.length && !/[\s>+~,@]/.test(pattern[i]) && !/[A-Z]/.test(pattern[i])) i++;
|
|
411
|
+
const segment = pattern.slice(pseudoStart, i);
|
|
412
|
+
result += segment;
|
|
413
|
+
lastCh = segment[segment.length - 1] || lastCh;
|
|
391
414
|
continue;
|
|
392
415
|
}
|
|
393
416
|
if (/[a-z]/.test(char)) {
|
|
394
|
-
|
|
395
|
-
while (i < pattern.length && /[a-z0-9-]/.test(pattern[i]))
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
result += tag;
|
|
417
|
+
const tagStart = i;
|
|
418
|
+
while (i < pattern.length && /[a-z0-9-]/.test(pattern[i])) i++;
|
|
419
|
+
if (result && lastCh !== " ") result += " ";
|
|
420
|
+
const segment = pattern.slice(tagStart, i);
|
|
421
|
+
result += segment;
|
|
422
|
+
lastCh = segment[segment.length - 1] || lastCh;
|
|
401
423
|
continue;
|
|
402
424
|
}
|
|
403
425
|
if (char === ".") {
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
let cls = ".";
|
|
426
|
+
const attachToLast = lastCh === "]" || lastCh === "@" || /[a-zA-Z0-9-]/.test(lastCh);
|
|
427
|
+
if (result && !attachToLast && lastCh !== " ") result += " ";
|
|
428
|
+
const clsStart = i;
|
|
408
429
|
i++;
|
|
409
|
-
while (i < pattern.length && /[a-zA-Z0-9_-]/.test(pattern[i]))
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
result += cls;
|
|
430
|
+
while (i < pattern.length && /[a-zA-Z0-9_-]/.test(pattern[i])) i++;
|
|
431
|
+
const segment = pattern.slice(clsStart, i);
|
|
432
|
+
result += segment;
|
|
433
|
+
lastCh = segment[segment.length - 1] || lastCh;
|
|
414
434
|
continue;
|
|
415
435
|
}
|
|
416
436
|
if (char === "[") {
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
let attr = "";
|
|
437
|
+
const attachToLast = lastCh === "]" || lastCh === "@" || /[a-zA-Z0-9-]/.test(lastCh);
|
|
438
|
+
if (result && !attachToLast && lastCh !== " ") result += " ";
|
|
439
|
+
const attrStart = i;
|
|
421
440
|
let depth = 0;
|
|
422
441
|
while (i < pattern.length) {
|
|
423
|
-
attr += pattern[i];
|
|
424
442
|
if (pattern[i] === "[") depth++;
|
|
425
443
|
if (pattern[i] === "]") depth--;
|
|
426
444
|
i++;
|
|
427
445
|
if (depth === 0) break;
|
|
428
446
|
}
|
|
429
|
-
result +=
|
|
447
|
+
result += pattern.slice(attrStart, i);
|
|
448
|
+
lastCh = "]";
|
|
430
449
|
continue;
|
|
431
450
|
}
|
|
432
451
|
result += char;
|
|
452
|
+
lastCh = char;
|
|
433
453
|
i++;
|
|
434
454
|
}
|
|
435
455
|
return result;
|
|
@@ -443,7 +463,8 @@ function transformPattern(pattern) {
|
|
|
443
463
|
* |----------------|-------------|---------|--------|
|
|
444
464
|
* | Combinator (>, +, ~) | Yes | `'>Body>'` | `> [data-element="Body"] > [el]` |
|
|
445
465
|
* | Uppercase element | Yes | `'>Body>Row'` | `> [el1] > [el2] [key]` |
|
|
446
|
-
* | Lowercase tag |
|
|
466
|
+
* | Lowercase tag | No | `'h1'` | ` h1` |
|
|
467
|
+
* | Universal (*) | No | `'h1 *'` | ` h1 *` |
|
|
447
468
|
* | Pseudo (:hover, ::before) | No | `'::before'` | `::before` |
|
|
448
469
|
* | Class (.active) | No | `'.active'` | `.active` |
|
|
449
470
|
* | Attribute ([type]) | No | `'[type="text"]'` | `[type="text"]` |
|
|
@@ -454,7 +475,8 @@ function transformPattern(pattern) {
|
|
|
454
475
|
* @example
|
|
455
476
|
* shouldInjectKey('>') // → true (trailing combinator)
|
|
456
477
|
* shouldInjectKey('>Body>Row') // → true (ends with element)
|
|
457
|
-
* shouldInjectKey('
|
|
478
|
+
* shouldInjectKey('h1') // → false (ends with tag)
|
|
479
|
+
* shouldInjectKey('*') // → false (universal selector)
|
|
458
480
|
* shouldInjectKey('::before') // → false (ends with pseudo)
|
|
459
481
|
* shouldInjectKey('.active') // → false (ends with class)
|
|
460
482
|
* shouldInjectKey('a:hover') // → false (ends with pseudo)
|
|
@@ -464,7 +486,6 @@ function shouldInjectKey(pattern) {
|
|
|
464
486
|
const trimmed = pattern.trim();
|
|
465
487
|
if (/[>+~]$/.test(trimmed)) return true;
|
|
466
488
|
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
489
|
return false;
|
|
469
490
|
}
|
|
470
491
|
/**
|
|
@@ -525,7 +546,27 @@ function cartesianProduct(arrays) {
|
|
|
525
546
|
if (arrays.length === 0) return [[]];
|
|
526
547
|
const nonEmpty = arrays.filter((a) => a.length > 0);
|
|
527
548
|
if (nonEmpty.length === 0) return [[]];
|
|
528
|
-
|
|
549
|
+
let result = [[]];
|
|
550
|
+
for (const arr of nonEmpty) {
|
|
551
|
+
const next = [];
|
|
552
|
+
for (const combo of result) for (const item of arr) {
|
|
553
|
+
const newCombo = new Array(combo.length + 1);
|
|
554
|
+
for (let i = 0; i < combo.length; i++) newCombo[i] = combo[i];
|
|
555
|
+
newCombo[combo.length] = item;
|
|
556
|
+
next.push(newCombo);
|
|
557
|
+
}
|
|
558
|
+
result = next;
|
|
559
|
+
}
|
|
560
|
+
return result;
|
|
561
|
+
}
|
|
562
|
+
const declStringCache = /* @__PURE__ */ new WeakMap();
|
|
563
|
+
function stringifyDeclarations(decl) {
|
|
564
|
+
let cached = declStringCache.get(decl);
|
|
565
|
+
if (cached === void 0) {
|
|
566
|
+
cached = JSON.stringify(decl);
|
|
567
|
+
declStringCache.set(decl, cached);
|
|
568
|
+
}
|
|
569
|
+
return cached;
|
|
529
570
|
}
|
|
530
571
|
/**
|
|
531
572
|
* Merge rules with identical CSS output
|
|
@@ -533,7 +574,7 @@ function cartesianProduct(arrays) {
|
|
|
533
574
|
function mergeByValue(rules) {
|
|
534
575
|
const groups = /* @__PURE__ */ new Map();
|
|
535
576
|
for (const rule of rules) {
|
|
536
|
-
const key = `${rule.selectorSuffix}|${
|
|
577
|
+
const key = `${rule.selectorSuffix}|${stringifyDeclarations(rule.declarations)}`;
|
|
537
578
|
if (!groups.has(key)) groups.set(key, []);
|
|
538
579
|
groups.get(key).push(rule);
|
|
539
580
|
}
|
|
@@ -554,11 +595,12 @@ function mergeByValue(rules) {
|
|
|
554
595
|
*/
|
|
555
596
|
function buildSelectorFromVariant(variant, selectorSuffix) {
|
|
556
597
|
let selector = "";
|
|
557
|
-
|
|
558
|
-
for (const
|
|
598
|
+
selector += branchToCSS([...variant.modifierConditions, ...variant.pseudoConditions]);
|
|
599
|
+
for (const group of variant.selectorGroups) selector += selectorGroupToCSS(group);
|
|
559
600
|
if (variant.parentGroups.length > 0) selector += parentGroupsToCSS(variant.parentGroups);
|
|
560
601
|
selector += selectorSuffix;
|
|
561
|
-
|
|
602
|
+
const ownOptimized = optimizeGroups(variant.ownGroups);
|
|
603
|
+
for (const group of ownOptimized) selector += selectorGroupToCSS(group);
|
|
562
604
|
return selector;
|
|
563
605
|
}
|
|
564
606
|
/**
|
|
@@ -572,45 +614,68 @@ function materializeComputedRule(rule) {
|
|
|
572
614
|
if (components.isImpossible || components.variants.length === 0) return [];
|
|
573
615
|
const declarations = Object.entries(rule.declarations).map(([prop, value]) => `${prop}: ${value};`).join(" ");
|
|
574
616
|
const getRootPrefixKey = (variant) => {
|
|
575
|
-
return variant.
|
|
617
|
+
return rootGroupsToCSS(variant.rootGroups) || "";
|
|
576
618
|
};
|
|
577
619
|
const byAtRules = /* @__PURE__ */ new Map();
|
|
578
620
|
for (const variant of components.variants) {
|
|
579
621
|
const atRules = buildAtRulesFromVariant(variant);
|
|
580
|
-
const
|
|
622
|
+
const startingStyle = variant.startingStyle;
|
|
623
|
+
const key = atRules.sort().join("|||") + "###" + getRootPrefixKey(variant) + "###" + (startingStyle ? "1" : "0");
|
|
581
624
|
const group = byAtRules.get(key);
|
|
582
625
|
if (group) group.variants.push(variant);
|
|
583
626
|
else byAtRules.set(key, {
|
|
584
627
|
variants: [variant],
|
|
585
628
|
atRules,
|
|
586
|
-
rootPrefix:
|
|
629
|
+
rootPrefix: rootGroupsToCSS(variant.rootGroups),
|
|
630
|
+
startingStyle: startingStyle || void 0
|
|
587
631
|
});
|
|
588
632
|
}
|
|
589
633
|
const rules = [];
|
|
590
634
|
for (const [, group] of byAtRules) {
|
|
591
|
-
const selectorFragments = group.variants.map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
|
|
635
|
+
const selectorFragments = mergeVariantsIntoSelectorGroups(group.variants).map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
|
|
592
636
|
const cssRule = {
|
|
593
637
|
selector: selectorFragments.length === 1 ? selectorFragments[0] : selectorFragments,
|
|
594
638
|
declarations
|
|
595
639
|
};
|
|
596
640
|
if (group.atRules.length > 0) cssRule.atRules = group.atRules;
|
|
597
641
|
if (group.rootPrefix) cssRule.rootPrefix = group.rootPrefix;
|
|
642
|
+
if (group.startingStyle) cssRule.startingStyle = true;
|
|
598
643
|
rules.push(cssRule);
|
|
599
644
|
}
|
|
600
645
|
return rules;
|
|
601
646
|
}
|
|
602
|
-
|
|
647
|
+
/**
|
|
648
|
+
* Merge StyleResult entries that share the same selector and at-rules,
|
|
649
|
+
* concatenating their declarations into a single rule.
|
|
650
|
+
*
|
|
651
|
+
* This reduces CSS output size when many style keys (e.g. design tokens)
|
|
652
|
+
* resolve to the same selector/state combination.
|
|
653
|
+
*/
|
|
654
|
+
function mergeStyleResults(results) {
|
|
655
|
+
if (results.length <= 1) return results;
|
|
656
|
+
const groups = /* @__PURE__ */ new Map();
|
|
657
|
+
for (const result of results) {
|
|
658
|
+
const key = `${result.atRules?.join("|") ?? ""}||${result.selector}||${result.startingStyle ? "1" : "0"}`;
|
|
659
|
+
const existing = groups.get(key);
|
|
660
|
+
if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${result.declarations}` : result.declarations;
|
|
661
|
+
else groups.set(key, { ...result });
|
|
662
|
+
}
|
|
663
|
+
return Array.from(groups.values());
|
|
664
|
+
}
|
|
665
|
+
function renderStyles(styles, classNameOrSelector, options, pipelineCacheKey) {
|
|
603
666
|
const directSelector = !!classNameOrSelector;
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
667
|
+
let rules;
|
|
668
|
+
if (pipelineCacheKey) rules = pipelineCache.get(pipelineCacheKey);
|
|
669
|
+
if (!rules && !styles) return directSelector ? [] : { rules: [] };
|
|
670
|
+
const cacheKey = pipelineCacheKey || stringifyStyles(styles);
|
|
671
|
+
if (!rules) rules = pipelineCache.get(cacheKey);
|
|
607
672
|
if (!rules) {
|
|
608
673
|
rules = runPipeline(styles, createStateParserContext(styles));
|
|
609
674
|
pipelineCache.set(cacheKey, rules);
|
|
610
675
|
}
|
|
611
676
|
if (directSelector) {
|
|
612
677
|
const shouldDouble = options?.doubleSelector ?? false;
|
|
613
|
-
return rules.map((rule) => {
|
|
678
|
+
return mergeStyleResults(rules.map((rule) => {
|
|
614
679
|
const result = {
|
|
615
680
|
selector: (Array.isArray(rule.selector) ? rule.selector : rule.selector ? [rule.selector] : [""]).map((part) => {
|
|
616
681
|
let sel = part ? `${classNameOrSelector}${part}` : classNameOrSelector;
|
|
@@ -624,18 +689,20 @@ function renderStyles(styles, classNameOrSelector, options) {
|
|
|
624
689
|
declarations: rule.declarations
|
|
625
690
|
};
|
|
626
691
|
if (rule.atRules && rule.atRules.length > 0) result.atRules = rule.atRules;
|
|
692
|
+
if (rule.startingStyle) result.startingStyle = true;
|
|
627
693
|
return result;
|
|
628
|
-
});
|
|
694
|
+
}));
|
|
629
695
|
}
|
|
630
696
|
return { rules: rules.map((r) => ({
|
|
631
697
|
selector: Array.isArray(r.selector) ? r.selector.join("|||") : r.selector,
|
|
632
698
|
declarations: r.declarations,
|
|
633
699
|
atRules: r.atRules,
|
|
634
700
|
needsClassName: true,
|
|
635
|
-
rootPrefix: r.rootPrefix
|
|
701
|
+
rootPrefix: r.rootPrefix,
|
|
702
|
+
startingStyle: r.startingStyle
|
|
636
703
|
})) };
|
|
637
704
|
}
|
|
638
|
-
|
|
639
705
|
//#endregion
|
|
640
|
-
export { clearPipelineCache, isSelector, renderStyles };
|
|
706
|
+
export { clearPipelineCache, hasPipelineCacheEntry, isSelector, renderStyles };
|
|
707
|
+
|
|
641
708
|
//# sourceMappingURL=index.js.map
|