@tenphi/tasty 0.5.1 → 0.5.3

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 CHANGED
@@ -27,7 +27,7 @@ On top of that foundation, Tasty gives you a concise, CSS-like DSL with design t
27
27
  - **AI-friendly by design** — Style definitions are declarative, self-contained, and structurally consistent. AI tools can read, understand, and refactor even advanced state bindings as confidently as a human — because there's no hidden cascade logic or implicit ordering to second-guess.
28
28
  - **DSL that feels like CSS** — Property names you already know (`padding`, `color`, `display`) with syntax sugar that removes boilerplate. Learn the DSL in minutes, not days.
29
29
  - **Design-system native** — Color tokens (`#primary`), spacing units (`2x`), typography presets (`h1`, `t2`), border radius (`1r`), and recipes are first-class primitives, not afterthoughts.
30
- - **Full modern CSS coverage** — Media queries, container queries, `@supports`, `:has()`, `@starting-style`, `@property`, keyframes, boolean state logic with `&`, `|`, `!` operators. If CSS can do it, Tasty can express it concisely.
30
+ - **Near-complete modern CSS coverage** — Media queries, container queries, `@supports`, `:has()`, `@starting-style`, `@property`, `@keyframes`, etc. Some features that don't fit Tasty's component model (such as `@layer` and `!important`) are intentionally omitted, but real-world use cases are covered almost completely.
31
31
  - **Runtime or zero-runtime — your call** — Use `tasty()` for dynamic React components with runtime injection, or `tastyStatic()` with the Babel plugin for zero-runtime CSS extraction. Same DSL, same tokens, same output.
32
32
  - **Only generate what is used** — In runtime mode, Tasty injects CSS on demand for mounted components/variants, so your app avoids shipping style rules for UI states that are never rendered.
33
33
  - **Runtime performance that holds at scale** — The runtime path is tested against enterprise-scale applications and tuned with multi-level caching, chunk-level style reuse, style garbage collection, and a dedicated injector.
@@ -134,9 +134,13 @@ Predefined states turn complex selector logic into single tokens. Use `@mobile`
134
134
 
135
135
  This is the core idea that makes everything else possible.
136
136
 
137
- Traditional CSS uses the cascade to resolve conflicts: when multiple selectors match, the one with the highest specificity wins, or — if specificity is equal — the last one in source order wins. This makes styles inherently fragile. Reordering imports, adding a new media query, or composing components from different libraries can silently break styling.
137
+ Traditional CSS has two structural problems.
138
138
 
139
- Tasty takes a fundamentally different approach: **every state mapping compiles into selectors that are guaranteed to never overlap.**
139
+ First, the **cascade** resolves conflicts by specificity and source order: when multiple selectors match, the one with the highest specificity wins, or — if specificity is equal — the last one in source order wins. That makes styles inherently fragile. Reordering imports, adding a media query, or composing components from different libraries can silently break styling.
140
+
141
+ Second, **authoring selectors that capture real-world state logic is fundamentally hard.** A single state like "dark mode" may depend on a root attribute, an OS preference, or both — each branch needing its own selector, proper negation of competing branches, and correct `@media` nesting. The example below shows the CSS you'd write by hand for just *one* property with *one* state. Scale that across dozens of properties, then add breakpoints and container queries, and the selector logic quickly becomes unmanageable.
142
+
143
+ Tasty solves both problems at once: **every state mapping compiles into mutually exclusive selectors.**
140
144
 
141
145
  ```tsx
142
146
  const Text = tasty({
@@ -181,7 +185,9 @@ If `@dark` expands to `@root(schema=dark) | (!@root(schema) & @media(prefers-col
181
185
  }
182
186
  ```
183
187
 
184
- Every rule is guarded by the negation of all higher-priority rules. No two rules can ever match simultaneously. No specificity arithmetic. No source-order dependence. Components compose and extend without ever colliding.
188
+ Every rule is guarded by the negation of higher-priority rules. No two rules can match at the same time. No specificity arithmetic. No source-order dependence. Components compose and extend without collisions.
189
+
190
+ By absorbing selector complexity, Tasty makes advanced CSS patterns practical again — nested container queries, multi-condition `@supports` gates, and combined root-state/media branches. You stay in pure CSS instead of relying on JavaScript workarounds, so the browser can optimize layout, painting, and transitions natively. Tasty doesn't limit CSS; it unlocks its full potential by removing the complexity that held teams back.
185
191
 
186
192
  ## Capabilities
187
193
 
@@ -413,11 +419,12 @@ If you choose the runtime approach, performance is usually a non-issue in practi
413
419
 
414
420
  | Import | Description | Platform |
415
421
  |--------|-------------|----------|
416
- | `@tenphi/tasty` | Runtime style engine | Browser |
417
- | `@tenphi/tasty/static` | Zero-runtime static styles | Browser |
418
- | `@tenphi/tasty/babel-plugin` | Babel plugin for CSS extraction | Node |
422
+ | `@tenphi/tasty` | Runtime style engine (`tasty`, hooks, `configure`) | Browser |
423
+ | `@tenphi/tasty/static` | Zero-runtime static styles (`tastyStatic`) | Browser |
424
+ | `@tenphi/tasty/core` | Lower-level internals (config, parser, pipeline, injector, style handlers) for tooling and advanced use | Browser / Node |
425
+ | `@tenphi/tasty/babel-plugin` | Babel plugin for zero-runtime CSS extraction | Node |
419
426
  | `@tenphi/tasty/zero` | Programmatic extraction API | Node |
420
- | `@tenphi/tasty/next` | Next.js integration | Node |
427
+ | `@tenphi/tasty/next` | Next.js integration wrapper | Node |
421
428
 
422
429
  ## Ecosystem
423
430
 
@@ -456,13 +463,18 @@ const tokens = theme.tasty(); // Ready-to-use Tasty tokens
456
463
 
457
464
  Syntax highlighting for Tasty styles in TypeScript, TSX, JavaScript, and JSX. Highlights color tokens, custom units, state keys, presets, and style properties inside `tasty()`, `tastyStatic()`, and related APIs.
458
465
 
466
+ <p align="center">
467
+ <img src="assets/tasty-vscode-highlight.png" width="512" alt="Tasty VS Code syntax highlighting example">
468
+ </p>
469
+
459
470
  ### [Cube UI Kit](https://github.com/cube-js/cube-ui-kit)
460
471
 
461
472
  Open-source React UI kit built on Tasty + React Aria. 100+ production components proving Tasty works at design-system scale. A reference implementation and a ready-to-use component library.
462
473
 
463
474
  ## Documentation
464
475
 
465
- - **[Runtime API (tasty)](docs/tasty.md)** — Full runtime styling documentation: component creation, state mappings, sub-elements, variants, hooks, configuration, and style property reference
476
+ - **[Runtime API (tasty)](docs/tasty.md)** — Full runtime styling documentation: component creation, state mappings, sub-elements, variants, hooks, and configuration
477
+ - **[Style Properties](docs/styles.md)** — Complete reference for all enhanced style properties: syntax, values, modifiers, and recommendations
466
478
  - **[Zero Runtime (tastyStatic)](docs/tasty-static.md)** — Build-time static styling: Babel plugin setup, Next.js integration, and static style patterns
467
479
  - **[Style Injector](docs/injector.md)** — Internal CSS injection engine: `inject()`, `injectGlobal()`, `injectRawCSS()`, `keyframes()`, deduplication, reference counting, cleanup, SSR support, and Shadow DOM
468
480
  - **[Debug Utilities](docs/debug.md)** — Runtime CSS inspection via `tastyDebug`: CSS extraction, element inspection, cache metrics, chunk breakdown, and performance monitoring
package/dist/index.d.ts CHANGED
@@ -37,4 +37,12 @@ import { TypographyPreset } from "./tokens/typography.js";
37
37
  import { generateTypographyTokens } from "./utils/typography.js";
38
38
  import { tastyDebug } from "./debug.js";
39
39
  import "./core/index.js";
40
- export { type AllBaseProps, type AllBasePropsWithMods, AtRuleContext, BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, type BaseProps, type BasePropsWithoutChildren, BaseStyleProps, BlockInnerStyleProps, BlockOuterStyleProps, BlockStyleProps, Bucket, CHUNK_NAMES, COLOR_STYLES, COMPUTE_FUNC_MAP, CONTAINER_STYLES, CSSMap, CSSProperties, CUSTOM_UNITS, CacheMetrics, ChunkInfo, ChunkName, ColorStyleProps, ComputeModel, ConditionNode, ContainerStyleProps, DIMENSION_STYLES, DIRECTIONS, DimensionStyleProps, DisposeFunction, Element, type ElementsDefinition, FLOW_STYLES, FlowStyleProps, GlobalStyledProps, INNER_STYLES, InjectResult, InnerStyleProps, KeyframesCacheEntry, KeyframesInfo, KeyframesResult, KeyframesSteps, ModValue, Mods, NoType, NotSelector, OUTER_STYLES, OuterStyleProps, POSITION_STYLES, ParseStateKeyOptions, ParsedAdvancedState, ParsedColor, ParserOptions, PositionStyleProps, ProcessedStyle, PropertyDefinition, PropertyOptions, Props, RawCSSResult, RawStyleHandler, RecipeStyles, RenderResult, RootRegistry, RuleInfo, STATE_OPERATORS, STATE_OPERATOR_LIST, STYLE_TO_CHUNK, Selector, SheetInfo, SheetManager, ShortGridStyles, StateParserContext, StyleDetails, StyleDetailsPart, StyleHandler, StyleHandlerDefinition, StyleHandlerResult, StyleInjector, StyleInjectorConfig, StyleMap, StyleParser, StylePropValue, StyleResult, StyleRule, StyleStateData, StyleStateDataList, StyleStateDataListMap, StyleStateMap, StyleValue, StyleValueStateMap, Styles, StylesInterface, StylesWithoutSelectors, type SubElementDefinition, type SubElementProps, SuffixForSelector, TEXT_STYLES, TagName, TastyConfig, type TastyElementOptions, type TastyElementProps, TastyExtensionConfig, TastyNamedColors, TastyPlugin, TastyPluginFactory, TastyPresetNames, type TastyProps, TastyThemeNames, TextStyleProps, TokenValue, Tokens, TypographyPreset, UnitHandler, type UsePropertyOptions, type UseStylesOptions, type UseStylesResult, type VariantMap, type WithVariant, allocateClassName, buildAtRuleContext, categorizeStyleKeys, cleanup, color, computeState, configure, createInjector, createStateParserContext, customFunc, deprecationWarning, destroy, dotize, extendStyles, extractStyles, filterBaseProps, filterMods, generateTypographyTokens, getConfig, getCssText, getCssTextForNode, getDisplayName, getGlobalFuncs, getGlobalKeyframes, getGlobalParser, getGlobalPredefinedStates, getGlobalPredefinedTokens, getGlobalRecipes, getIsTestEnvironment, getModSelector, getRawCSSText, getRgbValuesFromRgbaString, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, hexToRgb, hslToRgbValues, inject, injectGlobal, injectRawCSS, injector, isAdvancedStateToken, isConfigLocked, isPropertyDefined, isSelector, isTestEnvironment, keyframes, mergeStyles, _modAttrs as modAttrs, normalizeColorTokenValue, okhslFunc, okhslPlugin, parseColor, parseStateKey, parseStateNotation, parseStyle, processTokens, property, renderStyles, resetConfig, resetGlobalPredefinedTokens, resolveRecipes, setGlobalPredefinedStates, setGlobalPredefinedTokens, strToRgb, stringifyStyles, stringifyTokens, styleHandlers, styleStateMapToStyleStateDataList, tasty, tastyDebug, useGlobalStyles, useKeyframes, useProperty, useRawCSS, useStyles, warn };
40
+ import { CSSProperties as CSSProperties$1 } from "react";
41
+
42
+ //#region src/index.d.ts
43
+ declare module './utils/css-types' {
44
+ interface CSSProperties extends CSSProperties$1 {}
45
+ }
46
+ //#endregion
47
+ export { type AllBaseProps, type AllBasePropsWithMods, AtRuleContext, BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, type BaseProps, type BasePropsWithoutChildren, BaseStyleProps, BlockInnerStyleProps, BlockOuterStyleProps, BlockStyleProps, Bucket, CHUNK_NAMES, COLOR_STYLES, COMPUTE_FUNC_MAP, CONTAINER_STYLES, CSSMap, CSSProperties, CUSTOM_UNITS, CacheMetrics, ChunkInfo, ChunkName, ColorStyleProps, ComputeModel, ConditionNode, ContainerStyleProps, DIMENSION_STYLES, DIRECTIONS, DimensionStyleProps, DisposeFunction, Element, type ElementsDefinition, FLOW_STYLES, FlowStyleProps, GlobalStyledProps, INNER_STYLES, InjectResult, InnerStyleProps, KeyframesCacheEntry, KeyframesInfo, KeyframesResult, KeyframesSteps, ModValue, Mods, NoType, NotSelector, OUTER_STYLES, OuterStyleProps, POSITION_STYLES, ParseStateKeyOptions, ParsedAdvancedState, ParsedColor, ParserOptions, PositionStyleProps, ProcessedStyle, PropertyDefinition, PropertyOptions, Props, RawCSSResult, RawStyleHandler, RecipeStyles, RenderResult, RootRegistry, RuleInfo, STATE_OPERATORS, STATE_OPERATOR_LIST, STYLE_TO_CHUNK, Selector, SheetInfo, SheetManager, ShortGridStyles, StateParserContext, StyleDetails, StyleDetailsPart, StyleHandler, StyleHandlerDefinition, StyleHandlerResult, StyleInjector, StyleInjectorConfig, StyleMap, StyleParser, StylePropValue, StyleResult, StyleRule, StyleStateData, StyleStateDataList, StyleStateDataListMap, StyleStateMap, StyleValue, StyleValueStateMap, Styles, StylesInterface, StylesWithoutSelectors, type SubElementDefinition, type SubElementProps, SuffixForSelector, TEXT_STYLES, TagName, TastyConfig, type TastyElementOptions, type TastyElementProps, TastyExtensionConfig, TastyNamedColors, TastyPlugin, TastyPluginFactory, TastyPresetNames, type TastyProps, TastyThemeNames, TextStyleProps, TokenValue, Tokens, TypographyPreset, UnitHandler, type UsePropertyOptions, type UseStylesOptions, type UseStylesResult, type VariantMap, type WithVariant, allocateClassName, buildAtRuleContext, categorizeStyleKeys, cleanup, color, computeState, configure, createInjector, createStateParserContext, customFunc, deprecationWarning, destroy, dotize, extendStyles, extractStyles, filterBaseProps, filterMods, generateTypographyTokens, getConfig, getCssText, getCssTextForNode, getDisplayName, getGlobalFuncs, getGlobalKeyframes, getGlobalParser, getGlobalPredefinedStates, getGlobalPredefinedTokens, getGlobalRecipes, getIsTestEnvironment, getModSelector, getRawCSSText, getRgbValuesFromRgbaString, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, hexToRgb, hslToRgbValues, inject, injectGlobal, injectRawCSS, injector, isAdvancedStateToken, isConfigLocked, isPropertyDefined, isSelector, isTestEnvironment, keyframes, mergeStyles, _modAttrs as modAttrs, normalizeColorTokenValue, okhslFunc, okhslPlugin, parseColor, parseStateKey, parseStateNotation, parseStyle, processTokens, property, renderStyles, resetConfig, resetGlobalPredefinedTokens, resolveRecipes, setGlobalPredefinedStates, setGlobalPredefinedTokens, strToRgb, stringifyStyles, stringifyTokens, styleHandlers, styleStateMapToStyleStateDataList, tasty, tastyDebug, useGlobalStyles, useKeyframes, useProperty, useRawCSS, useStyles, warn };
48
+ //# sourceMappingURL=index.d.ts.map
@@ -41,7 +41,9 @@ declare function insetStyle({
41
41
  right?: string | number | boolean;
42
42
  bottom?: string | number | boolean;
43
43
  left?: string | number | boolean;
44
- }): Record<string, string>;
44
+ }): Record<string, string> | {
45
+ inset: string;
46
+ };
45
47
  declare namespace insetStyle {
46
48
  var __lookupStyles: string[];
47
49
  }
@@ -12,25 +12,39 @@ function parseInsetValue(value) {
12
12
  return values[0] || "0";
13
13
  }
14
14
  /**
15
- * Parse inset value with optional directions (like "1x top" or "2x left right")
15
+ * Extract values and directions from a single parsed group.
16
16
  */
17
- function parseDirectionalInset(value) {
18
- if (typeof value === "number") return {
19
- values: [`${value}px`],
20
- directions: []
21
- };
22
- if (!value) return {
23
- values: [],
24
- directions: []
25
- };
26
- if (value === true) value = "0";
27
- const { values = [], mods = [] } = parseStyle(value).groups[0] ?? {};
17
+ function extractGroupData(group) {
18
+ const { values = [], mods = [] } = group;
28
19
  return {
29
20
  values: values.length ? values : ["0"],
30
21
  directions: filterMods(mods, DIRECTIONS)
31
22
  };
32
23
  }
33
24
  /**
25
+ * Apply a single group's values and directions onto a direction map.
26
+ */
27
+ function applyGroup(dirs, values, directions) {
28
+ if (!values.length) return;
29
+ if (directions.length === 0) {
30
+ dirs.top = values[0];
31
+ dirs.right = values[1] || values[0];
32
+ dirs.bottom = values[2] || values[0];
33
+ dirs.left = values[3] || values[1] || values[0];
34
+ } else directions.forEach((dir, i) => {
35
+ dirs[dir] = values[i] ?? values[0];
36
+ });
37
+ }
38
+ /**
39
+ * Optimize inset output shorthand.
40
+ */
41
+ function optimizeInset(dirs) {
42
+ const { top, right, bottom, left } = dirs;
43
+ if (top === right && right === bottom && bottom === left) return { inset: top };
44
+ if (top === bottom && left === right) return { inset: `${top} ${left}` };
45
+ return { inset: `${top} ${right} ${bottom} ${left}` };
46
+ }
47
+ /**
34
48
  * Inset style handler.
35
49
  *
36
50
  * IMPORTANT: This handler uses individual CSS properties (top, right, bottom, left)
@@ -78,54 +92,48 @@ function insetStyle({ inset, insetBlock, insetInline, top, right, bottom, left }
78
92
  }
79
93
  return result;
80
94
  }
81
- let [topVal, rightVal, bottomVal, leftVal] = [
82
- "auto",
83
- "auto",
84
- "auto",
85
- "auto"
86
- ];
95
+ const dirs = {
96
+ top: "auto",
97
+ right: "auto",
98
+ bottom: "auto",
99
+ left: "auto"
100
+ };
87
101
  if (inset != null) {
88
- const { values, directions } = parseDirectionalInset(inset);
89
- if (values.length) if (directions.length === 0) {
90
- topVal = values[0];
91
- rightVal = values[1] || values[0];
92
- bottomVal = values[2] || values[0];
93
- leftVal = values[3] || values[1] || values[0];
94
- } else directions.forEach((dir, i) => {
95
- const val = values[i] ?? values[0];
96
- if (dir === "top") topVal = val;
97
- else if (dir === "right") rightVal = val;
98
- else if (dir === "bottom") bottomVal = val;
99
- else if (dir === "left") leftVal = val;
100
- });
102
+ if (typeof inset === "number") dirs.top = dirs.right = dirs.bottom = dirs.left = `${inset}px`;
103
+ else if (inset === true) inset = "0";
104
+ if (typeof inset === "string" && inset) {
105
+ const groups = parseStyle(inset).groups ?? [];
106
+ for (const group of groups) {
107
+ const { values, directions } = extractGroupData(group);
108
+ applyGroup(dirs, values, directions);
109
+ }
110
+ }
101
111
  }
102
112
  if (insetBlock != null) {
103
113
  const val = parseInsetValue(insetBlock);
104
- if (val) topVal = bottomVal = val;
114
+ if (val) dirs.top = dirs.bottom = val;
105
115
  }
106
116
  if (insetInline != null) {
107
117
  const val = parseInsetValue(insetInline);
108
- if (val) leftVal = rightVal = val;
118
+ if (val) dirs.left = dirs.right = val;
109
119
  }
110
120
  if (top != null) {
111
121
  const val = parseInsetValue(top);
112
- if (val) topVal = val;
122
+ if (val) dirs.top = val;
113
123
  }
114
124
  if (right != null) {
115
125
  const val = parseInsetValue(right);
116
- if (val) rightVal = val;
126
+ if (val) dirs.right = val;
117
127
  }
118
128
  if (bottom != null) {
119
129
  const val = parseInsetValue(bottom);
120
- if (val) bottomVal = val;
130
+ if (val) dirs.bottom = val;
121
131
  }
122
132
  if (left != null) {
123
133
  const val = parseInsetValue(left);
124
- if (val) leftVal = val;
134
+ if (val) dirs.left = val;
125
135
  }
126
- if (topVal === rightVal && rightVal === bottomVal && bottomVal === leftVal) return { inset: topVal };
127
- if (topVal === bottomVal && leftVal === rightVal) return { inset: `${topVal} ${leftVal}` };
128
- return { inset: `${topVal} ${rightVal} ${bottomVal} ${leftVal}` };
136
+ return optimizeInset(dirs);
129
137
  }
130
138
  insetStyle.__lookupStyles = [
131
139
  "inset",
@@ -1 +1 @@
1
- {"version":3,"file":"inset.js","names":[],"sources":["../../src/styles/inset.ts"],"sourcesContent":["import { DIRECTIONS, filterMods, parseStyle } from '../utils/styles';\n\n/**\n * Parse an inset value and return the first processed value\n */\nfunction parseInsetValue(value: string | number | boolean): string | null {\n if (typeof value === 'number') return `${value}px`;\n if (!value) return null;\n if (value === true) value = '0';\n\n const { values } = parseStyle(value).groups[0] ?? { values: [] };\n\n return values[0] || '0';\n}\n\n/**\n * Parse inset value with optional directions (like \"1x top\" or \"2x left right\")\n */\nfunction parseDirectionalInset(value: string | number | boolean): {\n values: string[];\n directions: string[];\n} {\n if (typeof value === 'number') {\n return { values: [`${value}px`], directions: [] };\n }\n if (!value) return { values: [], directions: [] };\n if (value === true) value = '0';\n\n const { values = [], mods = [] } = parseStyle(value).groups[0] ?? {};\n\n return {\n values: values.length ? values : ['0'],\n directions: filterMods(mods, DIRECTIONS),\n };\n}\n\n/**\n * Inset style handler.\n *\n * IMPORTANT: This handler uses individual CSS properties (top, right, bottom, left)\n * when only individual direction props are specified. This allows CSS cascade to work\n * correctly when modifiers override only some directions.\n *\n * Example problem with using `inset` shorthand everywhere:\n * styles: {\n * top: { '': 0, 'side=bottom': 'initial' },\n * right: { '': 0, 'side=left': 'initial' },\n * bottom: { '': 0, 'side=top': 'initial' },\n * left: { '': 0, 'side=right': 'initial' },\n * }\n *\n * If we output `inset` for both cases:\n * - Default: inset: 0 0 0 0\n * - side=bottom: inset: initial auto auto auto ← WRONG! Overrides all 4 directions\n *\n * With individual properties:\n * - Default: top: 0; right: 0; bottom: 0; left: 0\n * - side=bottom: top: initial ← CORRECT! Only overrides top\n *\n * The `inset` shorthand is only used when the base `inset` prop is specified\n * OR when `insetBlock`/`insetInline` are used (which imply setting pairs).\n */\nexport function insetStyle({\n inset,\n insetBlock,\n insetInline,\n top,\n right,\n bottom,\n left,\n}: {\n inset?: string | number | boolean;\n insetBlock?: string | number | boolean;\n insetInline?: string | number | boolean;\n top?: string | number | boolean;\n right?: string | number | boolean;\n bottom?: string | number | boolean;\n left?: string | number | boolean;\n}) {\n // If no props are defined, return empty object\n if (\n inset == null &&\n insetBlock == null &&\n insetInline == null &&\n top == null &&\n right == null &&\n bottom == null &&\n left == null\n ) {\n return {};\n }\n\n // When only individual direction props are used (no inset, insetBlock, insetInline),\n // output individual CSS properties to allow proper CSS cascade with modifiers\n const onlyIndividualProps =\n inset == null && insetBlock == null && insetInline == null;\n\n if (onlyIndividualProps) {\n const result: Record<string, string> = {};\n\n if (top != null) {\n const val = parseInsetValue(top);\n if (val) result['top'] = val;\n }\n if (right != null) {\n const val = parseInsetValue(right);\n if (val) result['right'] = val;\n }\n if (bottom != null) {\n const val = parseInsetValue(bottom);\n if (val) result['bottom'] = val;\n }\n if (left != null) {\n const val = parseInsetValue(left);\n if (val) result['left'] = val;\n }\n\n return result;\n }\n\n // When inset, insetBlock, or insetInline is used, use the shorthand approach\n // Initialize all directions to auto\n let [topVal, rightVal, bottomVal, leftVal] = ['auto', 'auto', 'auto', 'auto'];\n\n // Priority 1 (lowest): inset\n if (inset != null) {\n const { values, directions } = parseDirectionalInset(inset);\n\n if (values.length) {\n if (directions.length === 0) {\n topVal = values[0];\n rightVal = values[1] || values[0];\n bottomVal = values[2] || values[0];\n leftVal = values[3] || values[1] || values[0];\n } else {\n // Assign values to directions in the order they appear\n // e.g., 'right 1x top 0' right: 1x, top: 0\n directions.forEach((dir, i) => {\n const val = values[i] ?? values[0];\n if (dir === 'top') topVal = val;\n else if (dir === 'right') rightVal = val;\n else if (dir === 'bottom') bottomVal = val;\n else if (dir === 'left') leftVal = val;\n });\n }\n }\n }\n\n // Priority 2 (medium): insetBlock/insetInline\n if (insetBlock != null) {\n const val = parseInsetValue(insetBlock);\n if (val) topVal = bottomVal = val;\n }\n if (insetInline != null) {\n const val = parseInsetValue(insetInline);\n if (val) leftVal = rightVal = val;\n }\n\n // Priority 3 (highest): individual directions\n if (top != null) {\n const val = parseInsetValue(top);\n if (val) topVal = val;\n }\n if (right != null) {\n const val = parseInsetValue(right);\n if (val) rightVal = val;\n }\n if (bottom != null) {\n const val = parseInsetValue(bottom);\n if (val) bottomVal = val;\n }\n if (left != null) {\n const val = parseInsetValue(left);\n if (val) leftVal = val;\n }\n\n // Optimize output: 1 value if all same, 2 values if top==bottom && left==right\n if (topVal === rightVal && rightVal === bottomVal && bottomVal === leftVal) {\n return { inset: topVal };\n }\n if (topVal === bottomVal && leftVal === rightVal) {\n return { inset: `${topVal} ${leftVal}` };\n }\n\n return { inset: `${topVal} ${rightVal} ${bottomVal} ${leftVal}` };\n}\n\ninsetStyle.__lookupStyles = [\n 'inset',\n 'insetBlock',\n 'insetInline',\n 'top',\n 'right',\n 'bottom',\n 'left',\n];\n"],"mappings":";;;;;;AAKA,SAAS,gBAAgB,OAAiD;AACxE,KAAI,OAAO,UAAU,SAAU,QAAO,GAAG,MAAM;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,UAAU,KAAM,SAAQ;CAE5B,MAAM,EAAE,WAAW,WAAW,MAAM,CAAC,OAAO,MAAM,EAAE,QAAQ,EAAE,EAAE;AAEhE,QAAO,OAAO,MAAM;;;;;AAMtB,SAAS,sBAAsB,OAG7B;AACA,KAAI,OAAO,UAAU,SACnB,QAAO;EAAE,QAAQ,CAAC,GAAG,MAAM,IAAI;EAAE,YAAY,EAAE;EAAE;AAEnD,KAAI,CAAC,MAAO,QAAO;EAAE,QAAQ,EAAE;EAAE,YAAY,EAAE;EAAE;AACjD,KAAI,UAAU,KAAM,SAAQ;CAE5B,MAAM,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,WAAW,MAAM,CAAC,OAAO,MAAM,EAAE;AAEpE,QAAO;EACL,QAAQ,OAAO,SAAS,SAAS,CAAC,IAAI;EACtC,YAAY,WAAW,MAAM,WAAW;EACzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BH,SAAgB,WAAW,EACzB,OACA,YACA,aACA,KACA,OACA,QACA,QASC;AAED,KACE,SAAS,QACT,cAAc,QACd,eAAe,QACf,OAAO,QACP,SAAS,QACT,UAAU,QACV,QAAQ,KAER,QAAO,EAAE;AAQX,KAFE,SAAS,QAAQ,cAAc,QAAQ,eAAe,MAE/B;EACvB,MAAM,SAAiC,EAAE;AAEzC,MAAI,OAAO,MAAM;GACf,MAAM,MAAM,gBAAgB,IAAI;AAChC,OAAI,IAAK,QAAO,SAAS;;AAE3B,MAAI,SA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AM,MAAM,gBAAgB,KAAK;AACjC,MAAI,IAAK,WAAU;;AAIrB,KAAI,WAAW,YAAY,aAAa,aAAa,cAAc,QACjE,QAAO,EAAE,OAAO,QAAQ;AAE1B,KAAI,WAAW,aAAa,YAAY,SACtC,QAAO,EAAE,OAAO,GAAG,OAAO,GAAG,WAAW;AAG1C,QAAO,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW;;AAGnE,WAAW,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
1
+ {"version":3,"file":"inset.js","names":[],"sources":["../../src/styles/inset.ts"],"sourcesContent":["import type { StyleDetails } from '../parser/types';\nimport { DIRECTIONS, filterMods, parseStyle } from '../utils/styles';\n\ntype Direction = (typeof DIRECTIONS)[number];\n\n/**\n * Parse an inset value and return the first processed value\n */\nfunction parseInsetValue(value: string | number | boolean): string | null {\n if (typeof value === 'number') return `${value}px`;\n if (!value) return null;\n if (value === true) value = '0';\n\n const { values } = parseStyle(value).groups[0] ?? { values: [] };\n\n return values[0] || '0';\n}\n\n/**\n * Extract values and directions from a single parsed group.\n */\nfunction extractGroupData(group: StyleDetails): {\n values: string[];\n directions: Direction[];\n} {\n const { values = [], mods = [] } = group;\n return {\n values: values.length ? values : ['0'],\n directions: filterMods(mods, DIRECTIONS) as Direction[],\n };\n}\n\n/**\n * Apply a single group's values and directions onto a direction map.\n */\nfunction applyGroup(\n dirs: Record<Direction, string>,\n values: string[],\n directions: Direction[],\n): void {\n if (!values.length) return;\n\n if (directions.length === 0) {\n dirs.top = values[0];\n dirs.right = values[1] || values[0];\n dirs.bottom = values[2] || values[0];\n dirs.left = values[3] || values[1] || values[0];\n } else {\n directions.forEach((dir, i) => {\n dirs[dir] = values[i] ?? values[0];\n });\n }\n}\n\n/**\n * Optimize inset output shorthand.\n */\nfunction optimizeInset(dirs: Record<Direction, string>): { inset: string } {\n const { top, right, bottom, left } = dirs;\n if (top === right && right === bottom && bottom === left) {\n return { inset: top };\n }\n if (top === bottom && left === right) {\n return { inset: `${top} ${left}` };\n }\n return { inset: `${top} ${right} ${bottom} ${left}` };\n}\n\n/**\n * Inset style handler.\n *\n * IMPORTANT: This handler uses individual CSS properties (top, right, bottom, left)\n * when only individual direction props are specified. This allows CSS cascade to work\n * correctly when modifiers override only some directions.\n *\n * Example problem with using `inset` shorthand everywhere:\n * styles: {\n * top: { '': 0, 'side=bottom': 'initial' },\n * right: { '': 0, 'side=left': 'initial' },\n * bottom: { '': 0, 'side=top': 'initial' },\n * left: { '': 0, 'side=right': 'initial' },\n * }\n *\n * If we output `inset` for both cases:\n * - Default: inset: 0 0 0 0\n * - side=bottom: inset: initial auto auto auto ← WRONG! Overrides all 4 directions\n *\n * With individual properties:\n * - Default: top: 0; right: 0; bottom: 0; left: 0\n * - side=bottom: top: initial ← CORRECT! Only overrides top\n *\n * The `inset` shorthand is only used when the base `inset` prop is specified\n * OR when `insetBlock`/`insetInline` are used (which imply setting pairs).\n */\nexport function insetStyle({\n inset,\n insetBlock,\n insetInline,\n top,\n right,\n bottom,\n left,\n}: {\n inset?: string | number | boolean;\n insetBlock?: string | number | boolean;\n insetInline?: string | number | boolean;\n top?: string | number | boolean;\n right?: string | number | boolean;\n bottom?: string | number | boolean;\n left?: string | number | boolean;\n}) {\n if (\n inset == null &&\n insetBlock == null &&\n insetInline == null &&\n top == null &&\n right == null &&\n bottom == null &&\n left == null\n ) {\n return {};\n }\n\n // When only individual direction props are used (no inset, insetBlock, insetInline),\n // output individual CSS properties to allow proper CSS cascade with modifiers\n const onlyIndividualProps =\n inset == null && insetBlock == null && insetInline == null;\n\n if (onlyIndividualProps) {\n const result: Record<string, string> = {};\n\n if (top != null) {\n const val = parseInsetValue(top);\n if (val) result['top'] = val;\n }\n if (right != null) {\n const val = parseInsetValue(right);\n if (val) result['right'] = val;\n }\n if (bottom != null) {\n const val = parseInsetValue(bottom);\n if (val) result['bottom'] = val;\n }\n if (left != null) {\n const val = parseInsetValue(left);\n if (val) result['left'] = val;\n }\n\n return result;\n }\n\n const dirs: Record<Direction, string> = {\n top: 'auto',\n right: 'auto',\n bottom: 'auto',\n left: 'auto',\n };\n\n // Priority 1 (lowest): inset\n if (inset != null) {\n if (typeof inset === 'number') {\n const v = `${inset}px`;\n dirs.top = dirs.right = dirs.bottom = dirs.left = v;\n } else if (inset === true) {\n inset = '0';\n }\n\n if (typeof inset === 'string' && inset) {\n const processed = parseStyle(inset);\n const groups = processed.groups ?? [];\n\n for (const group of groups) {\n const { values, directions } = extractGroupData(group);\n applyGroup(dirs, values, directions);\n }\n }\n }\n\n // Priority 2 (medium): insetBlock/insetInline\n if (insetBlock != null) {\n const val = parseInsetValue(insetBlock);\n if (val) dirs.top = dirs.bottom = val;\n }\n if (insetInline != null) {\n const val = parseInsetValue(insetInline);\n if (val) dirs.left = dirs.right = val;\n }\n\n // Priority 3 (highest): individual directions\n if (top != null) {\n const val = parseInsetValue(top);\n if (val) dirs.top = val;\n }\n if (right != null) {\n const val = parseInsetValue(right);\n if (val) dirs.right = val;\n }\n if (bottom != null) {\n const val = parseInsetValue(bottom);\n if (val) dirs.bottom = val;\n }\n if (left != null) {\n const val = parseInsetValue(left);\n if (val) dirs.left = val;\n }\n\n return optimizeInset(dirs);\n}\n\ninsetStyle.__lookupStyles = [\n 'inset',\n 'insetBlock',\n 'insetInline',\n 'top',\n 'right',\n 'bottom',\n 'left',\n];\n"],"mappings":";;;;;;AAQA,SAAS,gBAAgB,OAAiD;AACxE,KAAI,OAAO,UAAU,SAAU,QAAO,GAAG,MAAM;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,UAAU,KAAM,SAAQ;CAE5B,MAAM,EAAE,WAAW,WAAW,MAAM,CAAC,OAAO,MAAM,EAAE,QAAQ,EAAE,EAAE;AAEhE,QAAO,OAAO,MAAM;;;;;AAMtB,SAAS,iBAAiB,OAGxB;CACA,MAAM,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK;AACnC,QAAO;E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om?: string | number | boolean;
17
17
  marginLeft?: string | number | boolean;
18
- }): {
19
- margin?: undefined;
20
- } | {
21
- margin: string;
22
- };
18
+ }): {};
23
19
  declare namespace marginStyle {
24
20
  var __lookupStyles: string[];
25
21
  }
@@ -12,74 +12,82 @@ function parseMarginValue(value) {
12
12
  return values[0] || "var(--gap)";
13
13
  }
14
14
  /**
15
- * Parse margin value with optional directions (like "1x top" or "2x left right")
15
+ * Extract values and directions from a single parsed group.
16
16
  */
17
- function parseDirectionalMargin(value) {
18
- if (typeof value === "number") return {
19
- values: [`${value}px`],
20
- directions: []
21
- };
22
- if (!value) return {
23
- values: [],
24
- directions: []
25
- };
26
- if (value === true) value = "1x";
27
- const { values = [], mods = [] } = parseStyle(value).groups[0] ?? {};
17
+ function extractGroupData(group) {
18
+ const { values = [], mods = [] } = group;
28
19
  return {
29
20
  values: values.length ? values : ["var(--gap)"],
30
21
  directions: filterMods(mods, DIRECTIONS)
31
22
  };
32
23
  }
24
+ /**
25
+ * Apply a single group's values and directions onto a direction map.
26
+ */
27
+ function applyGroup(dirs, values, directions) {
28
+ if (!values.length) return;
29
+ if (directions.length === 0) {
30
+ dirs.top = values[0];
31
+ dirs.right = values[1] || values[0];
32
+ dirs.bottom = values[2] || values[0];
33
+ dirs.left = values[3] || values[1] || values[0];
34
+ } else directions.forEach((dir, i) => {
35
+ dirs[dir] = values[i] ?? values[0];
36
+ });
37
+ }
38
+ /**
39
+ * Optimize margin output shorthand.
40
+ */
41
+ function optimizeMargin(dirs) {
42
+ const { top, right, bottom, left } = dirs;
43
+ if (top === right && right === bottom && bottom === left) return { margin: top };
44
+ if (top === bottom && left === right) return { margin: `${top} ${left}` };
45
+ return { margin: `${top} ${right} ${bottom} ${left}` };
46
+ }
33
47
  function marginStyle({ margin, marginBlock, marginInline, marginTop, marginRight, marginBottom, marginLeft }) {
34
48
  if (margin == null && marginBlock == null && marginInline == null && marginTop == null && marginRight == null && marginBottom == null && marginLeft == null) return {};
35
- let [top, right, bottom, left] = [
36
- "0",
37
- "0",
38
- "0",
39
- "0"
40
- ];
49
+ const dirs = {
50
+ top: "0",
51
+ right: "0",
52
+ bottom: "0",
53
+ left: "0"
54
+ };
41
55
  if (margin != null) {
42
- const { values, directions } = parseDirectionalMargin(margin);
43
- if (values.length) if (directions.length === 0) {
44
- top = values[0];
45
- right = values[1] || values[0];
46
- bottom = values[2] || values[0];
47
- left = values[3] || values[1] || values[0];
48
- } else directions.forEach((dir, i) => {
49
- const val = values[i] ?? values[0];
50
- if (dir === "top") top = val;
51
- else if (dir === "right") right = val;
52
- else if (dir === "bottom") bottom = val;
53
- else if (dir === "left") left = val;
54
- });
56
+ if (typeof margin === "number") dirs.top = dirs.right = dirs.bottom = dirs.left = `${margin}px`;
57
+ else if (margin === true) margin = "1x";
58
+ if (typeof margin === "string" && margin) {
59
+ const groups = parseStyle(margin).groups ?? [];
60
+ for (const group of groups) {
61
+ const { values, directions } = extractGroupData(group);
62
+ applyGroup(dirs, values, directions);
63
+ }
64
+ }
55
65
  }
56
66
  if (marginBlock != null) {
57
67
  const val = parseMarginValue(marginBlock);
58
- if (val) top = bottom = val;
68
+ if (val) dirs.top = dirs.bottom = val;
59
69
  }
60
70
  if (marginInline != null) {
61
71
  const val = parseMarginValue(marginInline);
62
- if (val) left = right = val;
72
+ if (val) dirs.left = dirs.right = val;
63
73
  }
64
74
  if (marginTop != null) {
65
75
  const val = parseMarginValue(marginTop);
66
- if (val) top = val;
76
+ if (val) dirs.top = val;
67
77
  }
68
78
  if (marginRight != null) {
69
79
  const val = parseMarginValue(marginRight);
70
- if (val) right = val;
80
+ if (val) dirs.right = val;
71
81
  }
72
82
  if (marginBottom != null) {
73
83
  const val = parseMarginValue(marginBottom);
74
- if (val) bottom = val;
84
+ if (val) dirs.bottom = val;
75
85
  }
76
86
  if (marginLeft != null) {
77
87
  const val = parseMarginValue(marginLeft);
78
- if (val) left = val;
88
+ if (val) dirs.left = val;
79
89
  }
80
- if (top === right && right === bottom && bottom === left) return { margin: top };
81
- if (top === bottom && left === right) return { margin: `${top} ${left}` };
82
- return { margin: `${top} ${right} ${bottom} ${left}` };
90
+ return optimizeMargin(dirs);
83
91
  }
84
92
  marginStyle.__lookupStyles = [
85
93
  "margin",
@@ -1 +1 @@
1
- {"version":3,"file":"margin.js","names":[],"sources":["../../src/styles/margin.ts"],"sourcesContent":["import { DIRECTIONS, filterMods, parseStyle } from '../utils/styles';\n\n/**\n * Parse a margin value and return the first processed value\n */\nfunction parseMarginValue(value: string | number | boolean): string | null {\n if (typeof value === 'number') return `${value}px`;\n if (!value) return null;\n if (value === true) value = '1x';\n\n const { values } = parseStyle(value).groups[0] ?? { values: [] };\n\n return values[0] || 'var(--gap)';\n}\n\n/**\n * Parse margin value with optional directions (like \"1x top\" or \"2x left right\")\n */\nfunction parseDirectionalMargin(value: string | number | boolean): {\n values: string[];\n directions: string[];\n} {\n if (typeof value === 'number') {\n return { values: [`${value}px`], directions: [] };\n }\n if (!value) return { values: [], directions: [] };\n if (value === true) value = '1x';\n\n const { values = [], mods = [] } = parseStyle(value).groups[0] ?? {};\n\n return {\n values: values.length ? values : ['var(--gap)'],\n directions: filterMods(mods, DIRECTIONS),\n };\n}\n\nexport function marginStyle({\n margin,\n marginBlock,\n marginInline,\n marginTop,\n marginRight,\n marginBottom,\n marginLeft,\n}: {\n margin?: string | number | boolean;\n marginBlock?: string | number | boolean;\n marginInline?: string | number | boolean;\n marginTop?: string | number | boolean;\n marginRight?: string | number | boolean;\n marginBottom?: string | number | boolean;\n marginLeft?: string | number | boolean;\n}) {\n // If no margin is defined, return empty object\n if (\n margin == null &&\n marginBlock == null &&\n marginInline == null &&\n marginTop == null &&\n marginRight == null &&\n marginBottom == null &&\n marginLeft == null\n ) {\n return {};\n }\n\n // Initialize all directions to 0\n let [top, right, bottom, left] = ['0', '0', '0', '0'];\n\n // Priority 1 (lowest): margin\n if (margin != null) {\n const { values, directions } = parseDirectionalMargin(margin);\n\n if (values.length) {\n if (directions.length === 0) {\n top = values[0];\n right = values[1] || values[0];\n bottom = values[2] || values[0];\n left = values[3] || values[1] || values[0];\n } else {\n // Assign values to directions in the order they appear\n // e.g., 'right 1x top 2x' right: 1x, top: 2x\n directions.forEach((dir, i) => {\n const val = values[i] ?? values[0];\n if (dir === 'top') top = val;\n else if (dir === 'right') right = val;\n else if (dir === 'bottom') bottom = val;\n else if (dir === 'left') left = val;\n });\n }\n }\n }\n\n // Priority 2 (medium): marginBlock/marginInline\n if (marginBlock != null) {\n const val = parseMarginValue(marginBlock);\n if (val) top = bottom = val;\n }\n if (marginInline != null) {\n const val = parseMarginValue(marginInline);\n if (val) left = right = val;\n }\n\n // Priority 3 (highest): individual directions\n if (marginTop != null) {\n const val = parseMarginValue(marginTop);\n if (val) top = val;\n }\n if (marginRight != null) {\n const val = parseMarginValue(marginRight);\n if (val) right = val;\n }\n if (marginBottom != null) {\n const val = parseMarginValue(marginBottom);\n if (val) bottom = val;\n }\n if (marginLeft != null) {\n const val = parseMarginValue(marginLeft);\n if (val) left = val;\n }\n\n // Optimize output: 1 value if all same, 2 values if top==bottom && left==right\n if (top === right && right === bottom && bottom === left) {\n return { margin: top };\n }\n if (top === bottom && left === right) {\n return { margin: `${top} ${left}` };\n }\n\n return { margin: `${top} ${right} ${bottom} ${left}` };\n}\n\nmarginStyle.__lookupStyles = [\n 'margin',\n 'marginTop',\n 'marginRight',\n 'marginBottom',\n 'marginLeft',\n 'marginBlock',\n 'marginInline',\n];\n"],"mappings":";;;;;;AAKA,SAAS,iBAAiB,OAAiD;AACzE,KAAI,OAAO,UAAU,SAAU,QAAO,GAAG,MAAM;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,UAAU,KAAM,SAAQ;CAE5B,MAAM,EAAE,WAAW,WAAW,MAAM,CAAC,OAAO,MAAM,EAAE,QAAQ,EAAE,EAAE;AAEhE,QAAO,OAAO,MAAM;;;;;AAMtB,SAAS,uBAAuB,OAG9B;AACA,KAAI,OAAO,UAAU,SACnB,QAAO;EAA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MAAM,MAAM,iBAAiB,UAAU;AACvC,MAAI,IAAK,OAAM;;AAEjB,KAAI,eAAe,MAAM;EACvB,MAAM,MAAM,iBAAiB,YAAY;AACzC,MAAI,IAAK,SAAQ;;AAEnB,KAAI,gBAAgB,MAAM;EACxB,MAAM,MAAM,iBAAiB,aAAa;AAC1C,MAAI,IAAK,UAAS;;AAEpB,KAAI,cAAc,MAAM;EACtB,MAAM,MAAM,iBAAiB,WAAW;AACxC,MAAI,IAAK,QAAO;;AAIlB,KAAI,QAAQ,SAAS,UAAU,UAAU,WAAW,KAClD,QAAO,EAAE,QAAQ,KAAK;AAExB,KAAI,QAAQ,UAAU,SAAS,MAC7B,QAAO,EAAE,QAAQ,GAAG,IAAI,GAAG,QAAQ;AAGrC,QAAO,EAAE,QAAQ,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ;;AAGxD,YAAY,iBAAiB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
1
+ {"version":3,"file":"margin.js","names":[],"sources":["../../src/styles/margin.ts"],"sourcesContent":["import type { StyleDetails } from '../parser/types';\nimport { DIRECTIONS, filterMods, parseStyle } from '../utils/styles';\n\ntype Direction = (typeof DIRECTIONS)[number];\n\n/**\n * Parse a margin value and return the first processed value\n */\nfunction parseMarginValue(value: string | number | boolean): string | null {\n if (typeof value === 'number') return `${value}px`;\n if (!value) return null;\n if (value === true) value = '1x';\n\n const { values } = parseStyle(value).groups[0] ?? { values: [] };\n\n return values[0] || 'var(--gap)';\n}\n\n/**\n * Extract values and directions from a single parsed group.\n */\nfunction extractGroupData(group: StyleDetails): {\n values: string[];\n directions: Direction[];\n} {\n const { values = [], mods = [] } = group;\n return {\n values: values.length ? values : ['var(--gap)'],\n directions: filterMods(mods, DIRECTIONS) as Direction[],\n };\n}\n\n/**\n * Apply a single group's values and directions onto a direction map.\n */\nfunction applyGroup(\n dirs: Record<Direction, string>,\n values: string[],\n directions: Direction[],\n): void {\n if (!values.length) return;\n\n if (directions.length === 0) {\n dirs.top = values[0];\n dirs.right = values[1] || values[0];\n dirs.bottom = values[2] || values[0];\n dirs.left = values[3] || values[1] || values[0];\n } else {\n directions.forEach((dir, i) => {\n dirs[dir] = values[i] ?? values[0];\n });\n }\n}\n\n/**\n * Optimize margin output shorthand.\n */\nfunction optimizeMargin(dirs: Record<Direction, string>): {\n margin: string;\n} {\n const { top, right, bottom, left } = dirs;\n if (top === right && right === bottom && bottom === left) {\n return { margin: top };\n }\n if (top === bottom && left === right) {\n return { margin: `${top} ${left}` };\n }\n return { margin: `${top} ${right} ${bottom} ${left}` };\n}\n\nexport function marginStyle({\n margin,\n marginBlock,\n marginInline,\n marginTop,\n marginRight,\n marginBottom,\n marginLeft,\n}: {\n margin?: string | number | boolean;\n marginBlock?: string | number | boolean;\n marginInline?: string | number | boolean;\n marginTop?: string | number | boolean;\n marginRight?: string | number | boolean;\n marginBottom?: string | number | boolean;\n marginLeft?: string | number | boolean;\n}) {\n if (\n margin == null &&\n marginBlock == null &&\n marginInline == null &&\n marginTop == null &&\n marginRight == null &&\n marginBottom == null &&\n marginLeft == null\n ) {\n return {};\n }\n\n const dirs: Record<Direction, string> = {\n top: '0',\n right: '0',\n bottom: '0',\n left: '0',\n };\n\n // Priority 1 (lowest): margin\n if (margin != null) {\n if (typeof margin === 'number') {\n const v = `${margin}px`;\n dirs.top = dirs.right = dirs.bottom = dirs.left = v;\n } else if (margin === true) {\n margin = '1x';\n }\n\n if (typeof margin === 'string' && margin) {\n const processed = parseStyle(margin);\n const groups = processed.groups ?? [];\n\n for (const group of groups) {\n const { values, directions } = extractGroupData(group);\n applyGroup(dirs, values, directions);\n }\n }\n }\n\n // Priority 2 (medium): marginBlock/marginInline\n if (marginBlock != null) {\n const val = parseMarginValue(marginBlock);\n if (val) dirs.top = dirs.bottom = val;\n }\n if (marginInline != null) {\n const val = parseMarginValue(marginInline);\n if (val) dirs.left = dirs.right = val;\n }\n\n // Priority 3 (highest): individual directions\n if (marginTop != null) {\n const val = parseMarginValue(marginTop);\n if (val) dirs.top = val;\n }\n if (marginRight != null) {\n const val = parseMarginValue(marginRight);\n if (val) dirs.right = val;\n }\n if (marginBottom != null) {\n const val = parseMarginValue(marginBottom);\n if (val) dirs.bottom = val;\n }\n if (marginLeft != null) {\n const val = parseMarginValue(marginLeft);\n if (val) dirs.left = val;\n }\n\n return optimizeMargin(dirs);\n}\n\nmarginStyle.__lookupStyles = [\n 'margin',\n 'marginTop',\n 'marginRight',\n 'marginBottom',\n 'marginLeft',\n 'marginBlock',\n 'marginInline',\n];\n"],"mappings":";;;;;;AAQA,SAAS,iBAAiB,OAAiD;AACzE,KAAI,OAAO,UAAU,SAAU,QAAO,GAAG,MAAM;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,UAAU,KAAM,SAAQ;CAE5B,MAAM,EAAE,WAAW,WAAW,MAAM,CAAC,OAAO,MAAM,EAAE,QAAQ,EAAE,EAAE;AAEhE,QAAO,OAAO,MAAM;;;;;AAMtB,SAAS,iBAAiB,OAGxB;CACA,MAAM,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK;AACnC,QAAO;EACL,QAAQ,OAAO,SAAS,SAAS,CAAC,aAAa;EAC/C,YAAY,WAAW,MAAM,WAAW;EACzC;;;;;AAMH,SAAS,WACP,MACA,QACA,YACM;AACN,KAAI,CAAC,OAAO,OAAQ;AAEpB,KAAI,WAAW,WAAW,GAAG;AAC3B,OAAK,MAAM,OAAO;AAClB,OAAK,QAAQ,OAAO,MAAM,OAAO;AACjC,OAAK,SAAS,OAAO,MAAM,OAAO;AAClC,OAAK,OAAO,OAAO,MAAM,OAAO,MAAM,OAAO;OAE7C,YAAW,SAAS,KAAK,MAAM;AAC7B,OAAK,OAAO,OAAO,MAAM,OAAO;GAChC;;;;;AAON,SAAS,eAAe,MAEtB;CACA,MAAM,EAAE,KAAK,OAAO,QAAQ,SAAS;AACrC,KAAI,QAAQ,SAAS,UAAU,UAAU,WAAW,KAClD,QAAO,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EzB,KAAI,cAAc,MAAM;EACtB,MAAM,MAAM,iBAAiB,WAAW;AACxC,MAAI,IAAK,MAAK,OAAO;;AAGvB,QAAO,eAAe,KAAK;;AAG7B,YAAY,iBAAiB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
@@ -15,11 +15,7 @@ declare function paddingStyle({
15
15
  paddingRight?: string | number | boolean;
16
16
  paddingBottom?: string | number | boolean;
17
17
  paddingLeft?: string | number | boolean;
18
- }): {
19
- padding?: undefined;
20
- } | {
21
- padding: string;
22
- };
18
+ }): {};
23
19
  declare namespace paddingStyle {
24
20
  var __lookupStyles: string[];
25
21
  }
@@ -12,74 +12,82 @@ function parsePaddingValue(value) {
12
12
  return values[0] || "var(--gap)";
13
13
  }
14
14
  /**
15
- * Parse padding value with optional directions (like "1x top" or "2x left right")
15
+ * Extract values and directions from a single parsed group.
16
16
  */
17
- function parseDirectionalPadding(value) {
18
- if (typeof value === "number") return {
19
- values: [`${value}px`],
20
- directions: []
21
- };
22
- if (!value) return {
23
- values: [],
24
- directions: []
25
- };
26
- if (value === true) value = "1x";
27
- const { values = [], mods = [] } = parseStyle(value).groups[0] ?? {};
17
+ function extractGroupData(group) {
18
+ const { values = [], mods = [] } = group;
28
19
  return {
29
20
  values: values.length ? values : ["var(--gap)"],
30
21
  directions: filterMods(mods, DIRECTIONS)
31
22
  };
32
23
  }
24
+ /**
25
+ * Apply a single group's values and directions onto a direction map.
26
+ */
27
+ function applyGroup(dirs, values, directions) {
28
+ if (!values.length) return;
29
+ if (directions.length === 0) {
30
+ dirs.top = values[0];
31
+ dirs.right = values[1] || values[0];
32
+ dirs.bottom = values[2] || values[0];
33
+ dirs.left = values[3] || values[1] || values[0];
34
+ } else directions.forEach((dir, i) => {
35
+ dirs[dir] = values[i] ?? values[0];
36
+ });
37
+ }
38
+ /**
39
+ * Optimize padding output shorthand.
40
+ */
41
+ function optimizePadding(dirs) {
42
+ const { top, right, bottom, left } = dirs;
43
+ if (top === right && right === bottom && bottom === left) return { padding: top };
44
+ if (top === bottom && left === right) return { padding: `${top} ${left}` };
45
+ return { padding: `${top} ${right} ${bottom} ${left}` };
46
+ }
33
47
  function paddingStyle({ padding, paddingBlock, paddingInline, paddingTop, paddingRight, paddingBottom, paddingLeft }) {
34
48
  if (padding == null && paddingBlock == null && paddingInline == null && paddingTop == null && paddingRight == null && paddingBottom == null && paddingLeft == null) return {};
35
- let [top, right, bottom, left] = [
36
- "0",
37
- "0",
38
- "0",
39
- "0"
40
- ];
49
+ const dirs = {
50
+ top: "0",
51
+ right: "0",
52
+ bottom: "0",
53
+ left: "0"
54
+ };
41
55
  if (padding != null) {
42
- const { values, directions } = parseDirectionalPadding(padding);
43
- if (values.length) if (directions.length === 0) {
44
- top = values[0];
45
- right = values[1] || values[0];
46
- bottom = values[2] || values[0];
47
- left = values[3] || values[1] || values[0];
48
- } else directions.forEach((dir, i) => {
49
- const val = values[i] ?? values[0];
50
- if (dir === "top") top = val;
51
- else if (dir === "right") right = val;
52
- else if (dir === "bottom") bottom = val;
53
- else if (dir === "left") left = val;
54
- });
56
+ if (typeof padding === "number") dirs.top = dirs.right = dirs.bottom = dirs.left = `${padding}px`;
57
+ else if (padding === true) padding = "1x";
58
+ if (typeof padding === "string" && padding) {
59
+ const groups = parseStyle(padding).groups ?? [];
60
+ for (const group of groups) {
61
+ const { values, directions } = extractGroupData(group);
62
+ applyGroup(dirs, values, directions);
63
+ }
64
+ }
55
65
  }
56
66
  if (paddingBlock != null) {
57
67
  const val = parsePaddingValue(paddingBlock);
58
- if (val) top = bottom = val;
68
+ if (val) dirs.top = dirs.bottom = val;
59
69
  }
60
70
  if (paddingInline != null) {
61
71
  const val = parsePaddingValue(paddingInline);
62
- if (val) left = right = val;
72
+ if (val) dirs.left = dirs.right = val;
63
73
  }
64
74
  if (paddingTop != null) {
65
75
  const val = parsePaddingValue(paddingTop);
66
- if (val) top = val;
76
+ if (val) dirs.top = val;
67
77
  }
68
78
  if (paddingRight != null) {
69
79
  const val = parsePaddingValue(paddingRight);
70
- if (val) right = val;
80
+ if (val) dirs.right = val;
71
81
  }
72
82
  if (paddingBottom != null) {
73
83
  const val = parsePaddingValue(paddingBottom);
74
- if (val) bottom = val;
84
+ if (val) dirs.bottom = val;
75
85
  }
76
86
  if (paddingLeft != null) {
77
87
  const val = parsePaddingValue(paddingLeft);
78
- if (val) left = val;
88
+ if (val) dirs.left = val;
79
89
  }
80
- if (top === right && right === bottom && bottom === left) return { padding: top };
81
- if (top === bottom && left === right) return { padding: `${top} ${left}` };
82
- return { padding: `${top} ${right} ${bottom} ${left}` };
90
+ return optimizePadding(dirs);
83
91
  }
84
92
  paddingStyle.__lookupStyles = [
85
93
  "padding",
@@ -1 +1 @@
1
- {"version":3,"file":"padding.js","names":[],"sources":["../../src/styles/padding.ts"],"sourcesContent":["import { DIRECTIONS, filterMods, parseStyle } from '../utils/styles';\n\n/**\n * Parse a padding value and return the first processed value\n */\nfunction parsePaddingValue(value: string | number | boolean): string | null {\n if (typeof value === 'number') return `${value}px`;\n if (!value) return null;\n if (value === true) value = '1x';\n\n const { values } = parseStyle(value).groups[0] ?? { values: [] };\n\n return values[0] || 'var(--gap)';\n}\n\n/**\n * Parse padding value with optional directions (like \"1x top\" or \"2x left right\")\n */\nfunction parseDirectionalPadding(value: string | number | boolean): {\n values: string[];\n directions: string[];\n} {\n if (typeof value === 'number') {\n return { values: [`${value}px`], directions: [] };\n }\n if (!value) return { values: [], directions: [] };\n if (value === true) value = '1x';\n\n const { values = [], mods = [] } = parseStyle(value).groups[0] ?? {};\n\n return {\n values: values.length ? values : ['var(--gap)'],\n directions: filterMods(mods, DIRECTIONS),\n };\n}\n\nexport function paddingStyle({\n padding,\n paddingBlock,\n paddingInline,\n paddingTop,\n paddingRight,\n paddingBottom,\n paddingLeft,\n}: {\n padding?: string | number | boolean;\n paddingBlock?: string | number | boolean;\n paddingInline?: string | number | boolean;\n paddingTop?: string | number | boolean;\n paddingRight?: string | number | boolean;\n paddingBottom?: string | number | boolean;\n paddingLeft?: string | number | boolean;\n}) {\n // If no padding is defined, return empty object\n if (\n padding == null &&\n paddingBlock == null &&\n paddingInline == null &&\n paddingTop == null &&\n paddingRight == null &&\n paddingBottom == null &&\n paddingLeft == null\n ) {\n return {};\n }\n\n // Initialize all directions to 0\n let [top, right, bottom, left] = ['0', '0', '0', '0'];\n\n // Priority 1 (lowest): padding\n if (padding != null) {\n const { values, directions } = parseDirectionalPadding(padding);\n\n if (values.length) {\n if (directions.length === 0) {\n top = values[0];\n right = values[1] || values[0];\n bottom = values[2] || values[0];\n left = values[3] || values[1] || values[0];\n } else {\n // Assign values to directions in the order they appear\n // e.g., 'right 1x top 2x' right: 1x, top: 2x\n directions.forEach((dir, i) => {\n const val = values[i] ?? values[0];\n if (dir === 'top') top = val;\n else if (dir === 'right') right = val;\n else if (dir === 'bottom') bottom = val;\n else if (dir === 'left') left = val;\n });\n }\n }\n }\n\n // Priority 2 (medium): paddingBlock/paddingInline\n if (paddingBlock != null) {\n const val = parsePaddingValue(paddingBlock);\n if (val) top = bottom = val;\n }\n if (paddingInline != null) {\n const val = parsePaddingValue(paddingInline);\n if (val) left = right = val;\n }\n\n // Priority 3 (highest): individual directions\n if (paddingTop != null) {\n const val = parsePaddingValue(paddingTop);\n if (val) top = val;\n }\n if (paddingRight != null) {\n const val = parsePaddingValue(paddingRight);\n if (val) right = val;\n }\n if (paddingBottom != null) {\n const val = parsePaddingValue(paddingBottom);\n if (val) bottom = val;\n }\n if (paddingLeft != null) {\n const val = parsePaddingValue(paddingLeft);\n if (val) left = val;\n }\n\n // Optimize output: 1 value if all same, 2 values if top==bottom && left==right\n if (top === right && right === bottom && bottom === left) {\n return { padding: top };\n }\n if (top === bottom && left === right) {\n return { padding: `${top} ${left}` };\n }\n\n return { padding: `${top} ${right} ${bottom} ${left}` };\n}\n\npaddingStyle.__lookupStyles = [\n 'padding',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n 'paddingBlock',\n 'padd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AM,OAAO,MAAM,OAAO;AAChC,OAAI,QAAQ,MAAO,OAAM;YAChB,QAAQ,QAAS,SAAQ;YACzB,QAAQ,SAAU,UAAS;YAC3B,QAAQ,OAAQ,QAAO;IAChC;;AAMR,KAAI,gBAAgB,MAAM;EACxB,MAAM,MAAM,kBAAkB,aAAa;AAC3C,MAAI,IAAK,OAAM,SAAS;;AAE1B,KAAI,iBAAiB,MAAM;EACzB,MAAM,MAAM,kBAAkB,cAAc;AAC5C,MAAI,IAAK,QAAO,QAAQ;;AAI1B,KAAI,cAAc,MAAM;EACtB,MAAM,MAAM,kBAAkB,WAAW;AACzC,MAAI,IAAK,OAAM;;AAEjB,KAAI,gBAAgB,MAAM;EACxB,MAAM,MAAM,kBAAkB,aAAa;AAC3C,MAAI,IAAK,SAAQ;;AAEnB,KAAI,iBAAiB,MAAM;EACzB,MAAM,MAAM,kBAAkB,cAAc;AAC5C,MAAI,IAAK,UAAS;;AAEpB,KAAI,eAAe,MAAM;EACvB,MAAM,MAAM,kBAAkB,YAAY;AAC1C,MAAI,IAAK,QAAO;;AAIlB,KAAI,QAAQ,SAAS,UAAU,UAAU,WAAW,KAClD,QAAO,EAAE,SAAS,KAAK;AAEzB,KAAI,QAAQ,UAAU,SAAS,MAC7B,QAAO,EAAE,SAAS,GAAG,IAAI,GAAG,QAAQ;AAGtC,QAAO,EAAE,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ;;AAGzD,aAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
1
+ {"version":3,"file":"padding.js","names":[],"sources":["../../src/styles/padding.ts"],"sourcesContent":["import type { StyleDetails } from '../parser/types';\nimport { DIRECTIONS, filterMods, parseStyle } from '../utils/styles';\n\ntype Direction = (typeof DIRECTIONS)[number];\n\n/**\n * Parse a padding value and return the first processed value\n */\nfunction parsePaddingValue(value: string | number | boolean): string | null {\n if (typeof value === 'number') return `${value}px`;\n if (!value) return null;\n if (value === true) value = '1x';\n\n const { values } = parseStyle(value).groups[0] ?? { values: [] };\n\n return values[0] || 'var(--gap)';\n}\n\n/**\n * Extract values and directions from a single parsed group.\n */\nfunction extractGroupData(group: StyleDetails): {\n values: string[];\n directions: Direction[];\n} {\n const { values = [], mods = [] } = group;\n return {\n values: values.length ? values : ['var(--gap)'],\n directions: filterMods(mods, DIRECTIONS) as Direction[],\n };\n}\n\n/**\n * Apply a single group's values and directions onto a direction map.\n */\nfunction applyGroup(\n dirs: Record<Direction, string>,\n values: string[],\n directions: Direction[],\n): void {\n if (!values.length) return;\n\n if (directions.length === 0) {\n dirs.top = values[0];\n dirs.right = values[1] || values[0];\n dirs.bottom = values[2] || values[0];\n dirs.left = values[3] || values[1] || values[0];\n } else {\n directions.forEach((dir, i) => {\n dirs[dir] = values[i] ?? values[0];\n });\n }\n}\n\n/**\n * Optimize padding output shorthand.\n */\nfunction optimizePadding(dirs: Record<Direction, string>): {\n padding: string;\n} {\n const { top, right, bottom, left } = dirs;\n if (top === right && right === bottom && bottom === left) {\n return { padding: top };\n }\n if (top === bottom && left === right) {\n return { padding: `${top} ${left}` };\n }\n return { padding: `${top} ${right} ${bottom} ${left}` };\n}\n\nexport function paddingStyle({\n padding,\n paddingBlock,\n paddingInline,\n paddingTop,\n paddingRight,\n paddingBottom,\n paddingLeft,\n}: {\n padding?: string | number | boolean;\n paddingBlock?: string | number | boolean;\n paddingInline?: string | number | boolean;\n paddingTop?: string | number | boolean;\n paddingRight?: string | number | boolean;\n paddingBottom?: string | number | boolean;\n paddingLeft?: string | number | boolean;\n}) {\n if (\n padding == null &&\n paddingBlock == null &&\n paddingInline == null &&\n paddingTop == null &&\n paddingRight == null &&\n paddingBottom == null &&\n paddingLeft == null\n ) {\n return {};\n }\n\n const dirs: Record<Direction, string> = {\n top: '0',\n right: '0',\n bottom: '0',\n left: '0',\n };\n\n // Priority 1 (lowest): padding\n if (padding != null) {\n if (typeof padding === 'number') {\n const v = `${padding}px`;\n dirs.top = dirs.right = dirs.bottom = dirs.left = v;\n } else if (padding === true) {\n padding = '1x';\n }\n\n if (typeof padding === 'string' && padding) {\n const processed = parseStyle(padding);\n const groups = processed.groups ?? [];\n\n for (const group of groups) {\n const { values, directions } = extractGroupData(group);\n applyGroup(dirs, values, directions);\n }\n }\n }\n\n // Priority 2 (medium): paddingBlock/paddingInline\n if (paddingBlock != null) {\n const val = parsePaddingValue(paddingBlock);\n if (val) dirs.top = dirs.bottom = val;\n }\n if (paddingInline != null) {\n const val = parsePaddingValue(paddingInline);\n if (val) dirs.left = dirs.right = val;\n }\n\n // Priority 3 (highest): individual directions\n if (paddingTop != null) {\n const val = parsePaddingValue(paddingTop);\n if (val) dirs.top = val;\n }\n if (paddingRight != null) {\n const val = parsePaddingValue(paddingRight);\n if (val) dirs.right = val;\n }\n if (paddingBottom != null) {\n const val = parsePaddingValue(paddingBottom);\n if (val) dirs.bottom = val;\n }\n if (paddingLeft != null) {\n const val = parsePaddingValue(paddingLeft);\n if (val) dirs.left = val;\n }\n\n return optimizePadding(dirs);\n}\n\npaddingStyle.__lookupStyles = [\n 'padding',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n 'paddingBlock',\n 'paddingInline',\n];\n"],"mappings":";;;;;;AAQA,SAAS,kBAAkB,OAAiD;AAC1E,KAAI,OAAO,UAAU,SAAU,QAAO,GAAG,MAAM;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,UAAU,KAAM,SAAQ;CAE5B,MAAM,EAAE,WAAW,WAAW,MAAM,CAAC,OAAO,MAAM,EAAE,QAAQ,EAAE,EAAE;AAEhE,QAAO,OAAO,MAAM;;;;;AAMtB,SAAS,iBAAiB,OAGxB;CACA,MAAM,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK;AACnC,QAAO;EACL,QAAQ,OAAO,SAAS,SAAS,CAAC,aAAa;EAC/C,YAAY,WAAW,MAAM,WAAW;EACzC;;;;;AAMH,SAAS,WACP,MACA,QACA,Y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aAAa;AAC3C,MAAI,IAAK,MAAK,MAAM,KAAK,SAAS;;AAEpC,KAAI,iBAAiB,MAAM;EACzB,MAAM,MAAM,kBAAkB,cAAc;AAC5C,MAAI,IAAK,MAAK,OAAO,KAAK,QAAQ;;AAIpC,KAAI,cAAc,MAAM;EACtB,MAAM,MAAM,kBAAkB,WAAW;AACzC,MAAI,IAAK,MAAK,MAAM;;AAEtB,KAAI,gBAAgB,MAAM;EACxB,MAAM,MAAM,kBAAkB,aAAa;AAC3C,MAAI,IAAK,MAAK,QAAQ;;AAExB,KAAI,iBAAiB,MAAM;EACzB,MAAM,MAAM,kBAAkB,cAAc;AAC5C,MAAI,IAAK,MAAK,SAAS;;AAEzB,KAAI,eAAe,MAAM;EACvB,MAAM,MAAM,kBAAkB,YAAY;AAC1C,MAAI,IAAK,MAAK,OAAO;;AAGvB,QAAO,gBAAgB,KAAK;;AAG9B,aAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
@@ -86,6 +86,18 @@ const MAP = {
86
86
  ]
87
87
  };
88
88
  const DEFAULT_EASING = "linear";
89
+ const EASING_KEYWORDS = new Set([
90
+ "ease",
91
+ "ease-in",
92
+ "ease-out",
93
+ "ease-in-out",
94
+ "linear",
95
+ "step-start",
96
+ "step-end"
97
+ ]);
98
+ function isEasing(token) {
99
+ return EASING_KEYWORDS.has(token) || token.startsWith("cubic-bezier(") || token.startsWith("steps(") || token.startsWith("linear(");
100
+ }
89
101
  function getTiming(name) {
90
102
  return `var(--${name}-transition, var(--transition))`;
91
103
  }
@@ -97,24 +109,32 @@ function transitionStyle({ transition }) {
97
109
  tokens.push(...g.all);
98
110
  if (idx < processed.groups.length - 1) tokens.push(",");
99
111
  });
100
- if (!tokens) return;
112
+ if (tokens.length === 0) return;
101
113
  let tempTransition = [];
102
114
  const transitions = [];
103
115
  tokens.forEach((token) => {
104
116
  if (token === ",") {
105
- if (tempTransition) {
117
+ if (tempTransition.length) {
106
118
  transitions.push(tempTransition);
107
119
  tempTransition = [];
108
120
  }
109
121
  } else tempTransition.push(token);
110
122
  });
111
- if (tempTransition) transitions.push(tempTransition);
123
+ if (tempTransition.length) transitions.push(tempTransition);
112
124
  const map = {};
113
125
  transitions.forEach((transition) => {
114
126
  const name = transition[0];
115
- const timing = transition[1];
116
- const easing = transition[2];
117
- const delay = transition[3];
127
+ let timing;
128
+ let easing;
129
+ let delay;
130
+ if (transition[1] && isEasing(transition[1])) {
131
+ easing = transition[1];
132
+ delay = transition[2];
133
+ } else {
134
+ timing = transition[1];
135
+ easing = transition[2];
136
+ delay = transition[3];
137
+ }
118
138
  (MAP[name] || [name]).forEach((style) => {
119
139
  map[style] = [
120
140
  name,
@@ -1 +1 @@
1
- {"version":3,"file":"transition.js","names":[],"sources":["../../src/styles/transition.ts"],"sourcesContent":["import { parseStyle } from '../utils/styles';\n\nconst SECOND_FILL_COLOR_PROPERTY = '--tasty-second-fill-color';\n\nconst MAP = {\n fade: ['mask', 'mask-composite'],\n translate: ['transform', 'translate'],\n rotate: ['transform', 'rotate'],\n scale: ['transform', 'scale'],\n fill: ['background-color', 'background-image', SECOND_FILL_COLOR_PROPERTY],\n image: [\n 'background-image',\n 'background-position',\n 'background-size',\n 'background-repeat',\n 'background-attachment',\n 'background-origin',\n 'background-clip',\n SECOND_FILL_COLOR_PROPERTY,\n ],\n background: [\n 'background-color',\n 'background-image',\n 'background-position',\n 'background-size',\n 'background-repeat',\n 'background-attachment',\n 'background-origin',\n 'background-clip',\n SECOND_FILL_COLOR_PROPERTY,\n ],\n border: [\n 'border',\n 'border-top',\n 'border-right',\n 'border-bottom',\n 'border-left',\n ],\n filter: ['filter', 'backdrop-filter'],\n radius: ['border-radius'],\n shadow: ['box-shadow'],\n outline: ['outline', 'outline-offset'],\n preset: [\n 'font-size',\n 'line-height',\n 'letter-spacing',\n 'font-weight',\n 'font-style',\n ],\n text: ['font-weight', 'text-decoration-color'],\n color: ['color'],\n opacity: ['opacity'],\n theme: [\n 'color',\n 'background-color',\n 'background-image',\n 'box-shadow',\n 'border',\n 'border-radius',\n 'outline',\n 'opacity',\n SECOND_FILL_COLOR_PROPERTY,\n ],\n width: ['max-width', 'min-width', 'width'],\n height: ['max-height', 'min-height', 'height'],\n gap: ['gap', 'margin'],\n zIndex: ['z-index'],\n inset: ['inset', 'top', 'right', 'bottom', 'left'],\n};\n\nexport const DEFAULT_TIMING = 'var(--transition)';\nconst DEFAULT_EASING = 'linear';\n\nfunction getTiming(name) {\n return `var(--${name}-transition, var(--transition))`;\n}\n\nexport function transitionStyle({ transition }) {\n if (!transition) return;\n\n const processed = parseStyle(transition);\n const tokens: string[] = [];\n processed.groups.forEach((g, idx) => {\n tokens.push(...g.all);\n if (idx < processed.groups.length - 1) tokens.push(',');\n });\n\n if (!tokens) return;\n\n let tempTransition: string[] = [];\n const transitions: string[][] = [];\n\n tokens.forEach((token) => {\n if (token === ',') {\n if (tempTransition) {\n transitions.push(tempTransition);\n tempTransition = [];\n }\n } else {\n tempTransition.push(token);\n }\n });\n\n if (tempTransition) {\n transitions.push(tempTransition);\n }\n\n const map: {\n name?: string;\n easing?: string;\n timing?: string;\n delay?: string;\n } = {};\n\n transitions.forEach((transition) => {\n const name = transition[0];\n const timing = transition[1];\n const easing = transition[2];\n const delay = transition[3];\n\n const styles = MAP[name] || [name];\n\n styles.forEach((style) => {\n map[style] = [name, easing, timing, delay];\n });\n });\n\n const result = Object.entries(map)\n .map(([style, [name, easing, timing, delay]]) => {\n let value = `${style} ${timing || getTiming(name)}`;\n if (easing || delay) {\n value += ` ${easing || DEFAULT_EASING}`;\n }\n if (delay) {\n value += ` ${delay}`;\n }\n return value;\n })\n .join(', ');\n\n return { transition: result };\n}\n\ntransitionStyle.__lookupStyles = ['transition'];\n"],"mappings":";;;AAEA,MAAM,6BAA6B;AAEnC,MAAM,MAAM;CACV,MAAM,CAAC,QAAQ,iBAAiB;CAChC,WAAW,CAAC,aAAa,YAAY;CACrC,QAAQ,CAAC,aAAa,SAAS;CAC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rB,gBAAe,KAAK,MAAM;GAE5B;AAEF,KAAI,eACF,aAAY,KAAK,eAAe;CAGlC,MAAM,MAKF,EAAE;AAEN,aAAY,SAAS,eAAe;EAClC,MAAM,OAAO,WAAW;EACxB,MAAM,SAAS,WAAW;EAC1B,MAAM,SAAS,WAAW;EAC1B,MAAM,QAAQ,WAAW;AAIzB,GAFe,IAAI,SAAS,CAAC,KAAK,EAE3B,SAAS,UAAU;AACxB,OAAI,SAAS;IAAC;IAAM;IAAQ;IAAQ;IAAM;IAC1C;GACF;AAeF,QAAO,EAAE,YAbM,OAAO,QAAQ,IAAI,CAC/B,KAAK,CAAC,OAAO,CAAC,MAAM,QAAQ,QAAQ,YAAY;EAC/C,IAAI,QAAQ,GAAG,MAAM,GAAG,UAAU,UAAU,KAAK;AACjD,MAAI,UAAU,MACZ,UAAS,IAAI,UAAU;AAEzB,MAAI,MACF,UAAS,IAAI;AAEf,SAAO;GACP,CACD,KAAK,KAAK,EAEgB;;AAG/B,gBAAgB,iBAAiB,CAAC,aAAa"}
1
+ {"version":3,"file":"transition.js","names":[],"sources":["../../src/styles/transition.ts"],"sourcesContent":["import { parseStyle } from '../utils/styles';\n\nconst SECOND_FILL_COLOR_PROPERTY = '--tasty-second-fill-color';\n\nconst MAP: Record<string, string[]> = {\n fade: ['mask', 'mask-composite'],\n translate: ['transform', 'translate'],\n rotate: ['transform', 'rotate'],\n scale: ['transform', 'scale'],\n fill: ['background-color', 'background-image', SECOND_FILL_COLOR_PROPERTY],\n image: [\n 'background-image',\n 'background-position',\n 'background-size',\n 'background-repeat',\n 'background-attachment',\n 'background-origin',\n 'background-clip',\n SECOND_FILL_COLOR_PROPERTY,\n ],\n background: [\n 'background-color',\n 'background-image',\n 'background-position',\n 'background-size',\n 'background-repeat',\n 'background-attachment',\n 'background-origin',\n 'background-clip',\n SECOND_FILL_COLOR_PROPERTY,\n ],\n border: [\n 'border',\n 'border-top',\n 'border-right',\n 'border-bottom',\n 'border-left',\n ],\n filter: ['filter', 'backdrop-filter'],\n radius: ['border-radius'],\n shadow: ['box-shadow'],\n outline: ['outline', 'outline-offset'],\n preset: [\n 'font-size',\n 'line-height',\n 'letter-spacing',\n 'font-weight',\n 'font-style',\n ],\n text: ['font-weight', 'text-decoration-color'],\n color: ['color'],\n opacity: ['opacity'],\n theme: [\n 'color',\n 'background-color',\n 'background-image',\n 'box-shadow',\n 'border',\n 'border-radius',\n 'outline',\n 'opacity',\n SECOND_FILL_COLOR_PROPERTY,\n ],\n width: ['max-width', 'min-width', 'width'],\n height: ['max-height', 'min-height', 'height'],\n gap: ['gap', 'margin'],\n zIndex: ['z-index'],\n inset: ['inset', 'top', 'right', 'bottom', 'left'],\n};\n\nexport const DEFAULT_TIMING = 'var(--transition)';\nconst DEFAULT_EASING = 'linear';\n\nconst EASING_KEYWORDS = new Set([\n 'ease',\n 'ease-in',\n 'ease-out',\n 'ease-in-out',\n 'linear',\n 'step-start',\n 'step-end',\n]);\n\nfunction isEasing(token: string): boolean {\n return (\n EASING_KEYWORDS.has(token) ||\n token.startsWith('cubic-bezier(') ||\n token.startsWith('steps(') ||\n token.startsWith('linear(')\n );\n}\n\nfunction getTiming(name: string): string {\n return `var(--${name}-transition, var(--transition))`;\n}\n\ntype TransitionEntry = [\n name: string,\n easing: string | undefined,\n timing: string | undefined,\n delay: string | undefined,\n];\n\nexport function transitionStyle({ transition }) {\n if (!transition) return;\n\n const processed = parseStyle(transition);\n const tokens: string[] = [];\n processed.groups.forEach((g, idx) => {\n tokens.push(...g.all);\n if (idx < processed.groups.length - 1) tokens.push(',');\n });\n\n if (tokens.length === 0) return;\n\n let tempTransition: string[] = [];\n const transitions: string[][] = [];\n\n tokens.forEach((token) => {\n if (token === ',') {\n if (tempTransition.length) {\n transitions.push(tempTransition);\n tempTransition = [];\n }\n } else {\n tempTransition.push(token);\n }\n });\n\n if (tempTransition.length) {\n transitions.push(tempTransition);\n }\n\n const map: Record<string, TransitionEntry> = {};\n\n transitions.forEach((transition) => {\n const name = transition[0];\n\n let timing: string | undefined;\n let easing: string | undefined;\n let delay: string | undefined;\n\n if (transition[1] && isEasing(transition[1])) {\n easing = transition[1];\n delay = transition[2];\n } else {\n timing = transition[1];\n easing = transition[2];\n delay = transition[3];\n }\n\n const styles = MAP[name] || [name];\n\n styles.forEach((style) => {\n map[style] = [name, easing, timing, delay];\n });\n });\n\n const result = Object.entries(map)\n .map(([style, [name, easing, timing, delay]]) => {\n let value = `${style} ${timing || getTiming(name)}`;\n if (easing || delay) {\n value += ` ${easing || DEFAULT_EASING}`;\n }\n if (delay) {\n value += ` ${delay}`;\n }\n return value;\n })\n .join(', ');\n\n return { transition: result };\n}\n\ntransitionStyle.__lookupStyles = ['transition'];\n"],"mappings":";;;AAEA,MAAM,6BAA6B;AAEnC,MAAM,MAAgC;CACpC,MAAM,CAAC,QAAQ,iBAAiB;CAChC,WAAW,CAAC,aAAa,YAAY;CACrC,QAAQ,CAAC,aAAa,SAAS;CAC/B,OAAO,CAAC,aAAa,QAAQ;CAC7B,MAAM;EAAC;EAAoB;EAAoB;EAA2B;CAC1E,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;CACD,YAAY;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;CACD,QAAQ;EACN;EACA;EACA;EACA;EACA;EACD;CACD,QAAQ,CAAC,UAAU,kBAAkB;CACrC,QAAQ,CAAC,gBAAgB;CACzB,QAAQ,CAAC,aAAa;CACtB,SAAS,CAAC,WAAW,iBAAiB;CACtC,QAAQ;EACN;EACA;EACA;EACA;EACA;EACD;CACD,MAAM,CAAC,eAAe,wBAAwB;CAC9C,OAAO,CAAC,QAAQ;CAChB,SAAS,CAAC,UAAU;CACpB,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;CACD,OAAO;EAAC;EAAa;EAAa;EAAQ;CAC1C,QAAQ;EAAC;EAAc;EAAc;EAAS;CAC9C,KAAK,CAAC,OAAO,SAAS;CACtB,Q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AAM;IAAQ;IAAQ;IAAM;IAC1C;GACF;AAeF,QAAO,EAAE,YAbM,OAAO,QAAQ,IAAI,CAC/B,KAAK,CAAC,OAAO,CAAC,MAAM,QAAQ,QAAQ,YAAY;EAC/C,IAAI,QAAQ,GAAG,MAAM,GAAG,UAAU,UAAU,KAAK;AACjD,MAAI,UAAU,MACZ,UAAS,IAAI,UAAU;AAEzB,MAAI,MACF,UAAS,IAAI;AAEf,SAAO;GACP,CACD,KAAK,KAAK,EAEgB;;AAG/B,gBAAgB,iBAAiB,CAAC,aAAa"}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CSSProperties } from "./utils/css-types.js";
1
+ import { CSSProperties as CSSProperties$1 } from "./utils/css-types.js";
2
2
  import { Styles } from "./styles/types.js";
3
3
  import { BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, COLOR_STYLES, CONTAINER_STYLES, DIMENSION_STYLES, FLOW_STYLES, INNER_STYLES, OUTER_STYLES, POSITION_STYLES, TEXT_STYLES } from "./styles/list.js";
4
4
  import { AllHTMLAttributes, ComponentType } from "react";
@@ -76,7 +76,7 @@ interface BasePropsWithoutChildren<K extends TagName = TagName> extends Pick<All
76
76
  /** Plain css for the element */
77
77
  css?: string;
78
78
  /** The CSS style map */
79
- style?: CSSProperties | (CSSProperties & Record<string, string | number | null | undefined>);
79
+ style?: CSSProperties$1 | (CSSProperties$1 & Record<string, string | number | null | undefined>);
80
80
  /** User-defined theme for the element. Mapped to `data-theme` attribute. Augment `TastyThemeNames` to register project-specific themes for autocomplete. */
81
81
  theme?: ThemeName | (string & {});
82
82
  /** CSS custom property tokens rendered as inline styles */
@@ -1,7 +1,7 @@
1
1
  import { Properties } from "csstype";
2
2
 
3
3
  //#region src/utils/css-types.d.ts
4
- type CSSProperties = Properties<string | number>;
4
+ interface CSSProperties extends Properties<string | number> {}
5
5
  //#endregion
6
6
  export { CSSProperties };
7
7
  //# sourceMappingURL=css-types.d.ts.map
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@tenphi/tasty",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "A design-system-integrated styling system and DSL for concise, state-aware UI styling",
5
5
  "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
6
9
  "exports": {
7
10
  ".": {
8
11
  "import": {