@tenphi/tasty 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { KeyframesSteps, PropertyDefinition } from "../injector/types.js";
2
+ import { CSSProperties } from "../utils/css-types.js";
2
3
  import { StyleValue, StyleValueStateMap } from "../utils/styles.js";
3
- import { CSSProperties } from "react";
4
4
 
5
5
  //#region src/styles/types.d.ts
6
6
  /**
@@ -441,13 +441,15 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
441
441
  /**
442
442
  * Apply one or more predefined style recipes by name.
443
443
  * Recipes are defined globally via `configure({ recipes: { ... } })`.
444
- * Multiple recipes are space-separated. Use `|` to separate base recipes
444
+ * Multiple recipes are space-separated. Use `/` to separate base recipes
445
445
  * (applied before component styles) from post recipes (applied after, via mergeStyles).
446
+ * Use `none` to explicitly skip base recipes.
446
447
  *
447
448
  * Examples:
448
449
  * - `recipe: 'card'` // Apply the 'card' recipe
449
450
  * - `recipe: 'card elevated'` // Apply 'card' then 'elevated', then component styles
450
- * - `recipe: 'reset input | input-autofill'` // Base recipes, then post recipe
451
+ * - `recipe: 'reset input / input-autofill'` // Base recipes, then post recipe
452
+ * - `recipe: 'none / disabled'` // No base recipes, only post recipe
451
453
  * - `recipe: ''` // Clear recipes from base styles when extending
452
454
  */
453
455
  recipe?: string;
package/dist/tasty.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { KeyframesSteps, PropertyDefinition } from "./injector/types.js";
2
2
  import { StyleValue, StyleValueStateMap } from "./utils/styles.js";
3
3
  import { Styles, StylesInterface } from "./styles/types.js";
4
- import "./injector/index.js";
5
4
  import { AllBaseProps, BaseProps, BaseStyleProps, Mods, Props, Tokens } from "./types.js";
6
5
  import * as react from "react";
7
6
  import { AllHTMLAttributes, ComponentType, ForwardRefExoticComponent, JSX, PropsWithoutRef, RefAttributes } from "react";
package/dist/tasty.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { processTokens, stringifyTokens } from "./utils/process-tokens.js";
2
+ import { BASE_STYLES } from "./styles/list.js";
3
+ import { _modAttrs } from "./utils/mod-attrs.js";
2
4
  import { mergeStyles } from "./utils/merge-styles.js";
3
5
  import { useStyles } from "./hooks/useStyles.js";
4
- import { BASE_STYLES } from "./styles/list.js";
5
6
  import { getDisplayName } from "./utils/get-display-name.js";
6
- import { _modAttrs } from "./utils/mod-attrs.js";
7
7
  import { createElement, forwardRef, useMemo } from "react";
8
8
  import { isValidElementType } from "react-is";
9
9
 
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { CSSProperties } from "./utils/css-types.js";
1
2
  import { Styles } from "./styles/types.js";
2
- import { BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, COLOR_STYLES, CONTAINER_STYLES, DIMENSION_STYLES, FLOW_STYLES, OUTER_STYLES, POSITION_STYLES, TEXT_STYLES } from "./styles/list.js";
3
- import { AllHTMLAttributes, CSSProperties, ComponentType } from "react";
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
+ import { AllHTMLAttributes, ComponentType } from "react";
4
5
 
5
6
  //#region src/types.d.ts
6
7
  interface GlobalStyledProps {
@@ -94,6 +95,7 @@ type DimensionStyleProps = Pick<Styles, (typeof DIMENSION_STYLES)[number]>;
94
95
  type FlowStyleProps = Pick<Styles, (typeof FLOW_STYLES)[number]>;
95
96
  type ContainerStyleProps = Pick<Styles, (typeof CONTAINER_STYLES)[number]>;
96
97
  type OuterStyleProps = Pick<Styles, (typeof OUTER_STYLES)[number]>;
98
+ type InnerStyleProps = Pick<Styles, (typeof INNER_STYLES)[number]>;
97
99
  interface ShortGridStyles {
98
100
  template?: Styles['gridTemplate'];
99
101
  columns?: Styles['gridColumns'];
@@ -178,5 +180,5 @@ interface TastyExtensionConfig {
178
180
  stateDescriptions?: Record<string, string>;
179
181
  }
180
182
  //#endregion
181
- export { AllBaseProps, BaseProps, BasePropsWithoutChildren, BaseStyleProps, BlockInnerStyleProps, BlockOuterStyleProps, BlockStyleProps, ColorStyleProps, ContainerStyleProps, DimensionStyleProps, FlowStyleProps, GlobalStyledProps, ModValue, Mods, OuterStyleProps, PositionStyleProps, Props, ShortGridStyles, TagName, TastyExtensionConfig, TastyThemeNames, TextStyleProps, TokenValue, Tokens };
183
+ export { AllBaseProps, BaseProps, BasePropsWithoutChildren, BaseStyleProps, BlockInnerStyleProps, BlockOuterStyleProps, BlockStyleProps, ColorStyleProps, ContainerStyleProps, DimensionStyleProps, FlowStyleProps, GlobalStyledProps, InnerStyleProps, ModValue, Mods, OuterStyleProps, PositionStyleProps, Props, ShortGridStyles, TagName, TastyExtensionConfig, TastyThemeNames, TextStyleProps, TokenValue, Tokens };
182
184
  //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { Properties } from "csstype";
2
+
3
+ //#region src/utils/css-types.d.ts
4
+ type CSSProperties = Properties<string | number>;
5
+ //#endregion
6
+ export { CSSProperties };
7
+ //# sourceMappingURL=css-types.d.ts.map
@@ -1,5 +1,5 @@
1
+ import { CSSProperties } from "./css-types.js";
1
2
  import { Tokens } from "../types.js";
2
- import { CSSProperties } from "react";
3
3
 
4
4
  //#region src/utils/process-tokens.d.ts
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"process-tokens.js","names":[],"sources":["../../src/utils/process-tokens.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nimport type { Tokens, TokenValue } from '../types';\n\nimport { okhslToRgb } from './okhsl-to-rgb';\nimport {\n getRgbValuesFromRgbaString,\n hexToRgb,\n normalizeColorTokenValue,\n parseStyle,\n} from './styles';\n\nconst devMode = process.env.NODE_ENV !== 'production';\n\n/**\n * Parse HSL values from an hsl()/hsla() string.\n * Supports both comma-separated (legacy) and space-separated (modern) syntax:\n * hsl(200, 40%, 50%)\n * hsl(200 40% 50%)\n * hsl(200 40% 50% / 0.5)\n *\n * Returns [h, s, l] where h is 0-360, s and l are 0-1, or null if parsing fails.\n */\nfunction parseHslValues(str: string): [number, number, number] | null {\n const match = str.match(/hsla?\\(([^)]+)\\)/i);\n if (!match) return null;\n\n const inner = match[1].trim();\n // Split by slash first (for alpha), then handle color components\n const [colorPart] = inner.split('/');\n // Split by comma or whitespace\n const parts = colorPart\n .trim()\n .split(/[,\\s]+/)\n .filter(Boolean);\n\n if (parts.length < 3) return null;\n\n // Parse hue (can be unitless degrees, deg, turn, rad, or grad)\n let h = parseFloat(parts[0]);\n const hueStr = parts[0].toLowerCase();\n if (hueStr.endsWith('turn')) {\n h = parseFloat(hueStr) * 360;\n } else if (hueStr.endsWith('rad')) {\n h = (parseFloat(hueStr) * 180) / Math.PI;\n } else if (hueStr.endsWith('grad')) {\n h = parseFloat(hueStr) * 0.9; // 400 grad = 360 deg\n }\n // deg or unitless are already in degrees\n\n // Normalize hue to 0-360 range\n h = h % 360;\n if (h < 0) h += 360;\n\n // Parse saturation and lightness (percentages)\n const parsePercent = (val: string): number => {\n const num = parseFloat(val);\n return val.includes('%') ? num / 100 : num;\n };\n\n const s = Math.max(0, Math.min(1, parsePercent(parts[1])));\n const l = Math.max(0, Math.min(1, parsePercent(parts[2])));\n\n return [h, s, l];\n}\n\n/**\n * Convert HSL to RGB (sRGB).\n * Algorithm from: https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative\n * Same as used in CSS Color 4 spec.\n *\n * @param h - Hue in degrees (0-360)\n * @param s - Saturation (0-1)\n * @param l - Lightness (0-1)\n * @returns RGB values in 0-255 range (may have fractional values)\n */\nexport function hslToRgbValues(\n h: number,\n s: number,\n l: number,\n): [number, number, number] {\n const a = s * Math.min(l, 1 - l);\n\n const f = (n: number): number => {\n const k = (n + h / 30) % 12;\n return l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));\n };\n\n // Convert 0-1 range to 0-255\n return [f(0) * 255, f(8) * 255, f(4) * 255];\n}\n\n/**\n * Format a number to a string with up to 1 decimal place, removing trailing zeros.\n */\nfunction formatRgbComponent(n: number): string {\n return parseFloat(n.toFixed(1)).toString();\n}\n\n/**\n * Extract RGB triplet from a color value.\n * Returns the RGB values as a space-separated string (e.g., \"255 128 0\")\n * or a CSS variable reference for token colors.\n */\nfunction extractRgbValue(colorValue: string, parsedOutput: string): string {\n // If the parsed output references a color variable, use the -rgb variant\n const varMatch = parsedOutput.match(/var\\(--([a-z0-9-]+)-color\\)/);\n if (varMatch) {\n return `var(--${varMatch[1]}-color-rgb)`;\n }\n\n // For rgb(...) values, extract the triplet\n if (parsedOutput.startsWith('rgb(')) {\n const rgbValues = getRgbValuesFromRgbaString(parsedOutput);\n if (rgbValues && rgbValues.length >= 3) {\n return rgbValues.join(' ');\n }\n }\n\n // For hsl(...) values, convert to RGB triplet\n if (\n parsedOutput.startsWith('hsl(') ||\n parsedOutput.startsWith('hsla(') ||\n colorValue.startsWith('hsl(') ||\n colorValue.startsWith('hsla(')\n ) {\n // Try parsedOutput first, then original colorValue\n const hslValues =\n parseHslValues(parsedOutput) || parseHslValues(colorValue);\n if (hslValues) {\n const [r, g, b] = hslToRgbValues(\n hslValues[0],\n hslValues[1],\n hslValues[2],\n );\n return `${formatRgbComponent(r)} ${formatRgbComponent(g)} ${formatRgbComponent(b)}`;\n }\n }\n\n // For okhsl(...) values, convert to RGB triplet\n if (parsedOutput.startsWith('okhsl(') || colorValue.startsWith('okhsl(')) {\n // Try parsedOutput first, then original colorValue\n const rgbResult = okhslToRgb(parsedOutput) || okhslToRgb(colorValue);\n if (rgbResult) {\n const rgbValues = getRgbValuesFromRgbaString(rgbResult);\n if (rgbValues && rgbValues.length >= 3) {\n return rgbValues.join(' ');\n }\n }\n }\n\n // For hex values, convert to RGB triplet\n if (colorValue.startsWith('#') && /^#[0-9a-fA-F]{3,8}$/.test(colorValue)) {\n const rgbResult = hexToRgb(colorValue);\n if (rgbResult) {\n const rgbValues = getRgbValuesFromRgbaString(rgbResult);\n if (rgbValues && rgbValues.length >= 3) {\n return rgbValues.join(' ');\n }\n }\n }\n\n // Fallback: return the parsed output (may not be ideal but covers edge cases)\n return parsedOutput;\n}\n\n/**\n * Check if a value is a valid token value (string, number, or boolean - not object).\n * Returns false for `false` values (they mean \"skip this token\").\n */\nfunction isValidTokenValue(\n value: unknown,\n): value is Exclude<TokenValue, undefined | null | false> {\n if (value === undefined || value === null || value === false) {\n return false;\n }\n\n if (typeof value === 'object') {\n if (devMode) {\n console.warn(\n 'CubeUIKit: Object values are not allowed in tokens prop. ' +\n 'Tokens do not support state-based styling. Use a primitive value instead.',\n );\n }\n return false;\n }\n\n return (\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n );\n}\n\n/**\n * Process a single token value through the tasty parser.\n * Numbers are converted to strings; 0 stays as \"0\".\n */\nfunction processTokenValue(value: string | number): string {\n if (typeof value === 'number') {\n // 0 should remain as \"0\", not converted to any unit\n if (value === 0) {\n return '0';\n }\n return parseStyle(String(value)).output;\n }\n return parseStyle(value).output;\n}\n\n/**\n * Process tokens object into inline style properties.\n * - $name -> --name with parsed value\n * - #name -> --name-color AND --name-color-rgb with parsed values\n *\n * @param tokens - The tokens object to process\n * @returns CSSProperties object or undefined if no tokens to process\n */\nexport function processTokens(\n tokens: Tokens | undefined,\n): CSSProperties | undefined {\n if (!tokens) {\n return undefined;\n }\n\n const keys = Object.keys(tokens);\n if (keys.length === 0) {\n return undefined;\n }\n\n let result: Record<string, string> | undefined;\n\n for (const key of keys) {\n const value = tokens[key as keyof Tokens];\n\n // Skip undefined/null values\n if (!isValidTokenValue(value)) {\n continue;\n }\n\n if (key.startsWith('$')) {\n // Custom property token: $name -> --name\n const propName = `--${key.slice(1)}`;\n // Boolean true for custom properties converts to empty string (valid CSS value)\n const effectiveValue = value === true ? '' : value;\n const processedValue = processTokenValue(effectiveValue);\n\n if (!result) result = {};\n result[propName] = processedValue;\n } else if (key.startsWith('#')) {\n // Color token: #name -> --name-color and --name-color-rgb\n const colorName = key.slice(1);\n\n // Normalize color token value (true → 'transparent', false is already filtered by isValidTokenValue)\n const effectiveValue = normalizeColorTokenValue(value);\n // Skip if normalized to null (shouldn't happen since false is filtered by isValidTokenValue)\n if (effectiveValue === null) continue;\n\n const originalValue =\n typeof effectiveValue === 'number'\n ? String(effectiveValue)\n : effectiveValue;\n const lowerValue = originalValue.toLowerCase();\n const processedValue = processTokenValue(effectiveValue);\n\n if (!result) result = {};\n result[`--${colorName}-color`] = processedValue;\n\n // Skip RGB generation for #current values (currentcolor is dynamic, cannot extract RGB)\n // Match only #current or #current.opacity, not #current-theme or #currently-used\n if (/^#current(?:\\.|$)/i.test(lowerValue)) {\n continue;\n }\n\n result[`--${colorName}-color-rgb`] = extractRgbValue(\n originalValue,\n processedValue,\n );\n }\n }\n\n return result as CSSProperties | undefined;\n}\n\n/**\n * Stringify tokens for memoization key.\n */\nexport function stringifyTokens(tokens: Tokens | undefined): string {\n if (!tokens) return '';\n return JSON.stringify(tokens);\n}\n"],"mappings":";;;;;;;;;;;;;AAuBA,SAAS,eAAe,KAA8C;CACpE,MAAM,QAAQ,IAAI,MAAM,oBAAoB;AAC5C,KAAI,CAAC,MAAO,QAAO;CAInB,MAAM,CAAC,aAFO,MAAM,GAAG,MAAM,CAEH,MAAM,IAAI;CAEpC,MAAM,QAAQ,UACX,MAAM,CACN,MAAM,SAAS,CACf,OAAO,QAAQ;AAElB,KAAI,MAAM,SAAS,EAAG,QAAO;CAG7B,IAAI,IAAI,WAAW,MAAM,GAAG;CAC5B,MAAM,SAAS,MAAM,GAAG,aAAa;AACrC,KAAI,OAAO,SAAS,OAAO,CACzB,KAAI,WAAW,OAAO,GAAG;UAChB,OAAO,SAAS,MAAM,CAC/B,KAAK,WAAW,OAAO,GAAG,MAAO,KAA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MAAM,QAAQ,OAAO;AAGrB,MAAI,CAAC,kBAAkB,MAAM,CAC3B;AAGF,MAAI,IAAI,WAAW,IAAI,EAAE;GAEvB,MAAM,WAAW,KAAK,IAAI,MAAM,EAAE;GAGlC,MAAM,iBAAiB,kBADA,UAAU,OAAO,KAAK,MACW;AAExD,OAAI,CAAC,OAAQ,UAAS,EAAE;AACxB,UAAO,YAAY;aACV,IAAI,WAAW,IAAI,EAAE;GAE9B,MAAM,YAAY,IAAI,MAAM,EAAE;GAG9B,MAAM,iBAAiB,yBAAyB,MAAM;AAEtD,OAAI,mBAAmB,KAAM;GAE7B,MAAM,gBACJ,OAAO,mBAAmB,WACtB,OAAO,eAAe,GACtB;GACN,MAAM,aAAa,cAAc,aAAa;GAC9C,MAAM,iBAAiB,kBAAkB,eAAe;AAExD,OAAI,CAAC,OAAQ,UAAS,EAAE;AACxB,UAAO,KAAK,UAAU,WAAW;AAIjC,OAAI,qBAAqB,KAAK,WAAW,CACvC;AAGF,UAAO,KAAK,UAAU,eAAe,gBACnC,eACA,eACD;;;AAIL,QAAO;;;;;AAMT,SAAgB,gBAAgB,QAAoC;AAClE,KAAI,CAAC,OAAQ,QAAO;AACpB,QAAO,KAAK,UAAU,OAAO"}
1
+ {"version":3,"file":"process-tokens.js","names":[],"sources":["../../src/utils/process-tokens.ts"],"sourcesContent":["import type { Tokens, TokenValue } from '../types';\n\nimport type { CSSProperties } from './css-types';\n\nimport { okhslToRgb } from './okhsl-to-rgb';\nimport {\n getRgbValuesFromRgbaString,\n hexToRgb,\n normalizeColorTokenValue,\n parseStyle,\n} from './styles';\n\nconst devMode = process.env.NODE_ENV !== 'production';\n\n/**\n * Parse HSL values from an hsl()/hsla() string.\n * Supports both comma-separated (legacy) and space-separated (modern) syntax:\n * hsl(200, 40%, 50%)\n * hsl(200 40% 50%)\n * hsl(200 40% 50% / 0.5)\n *\n * Returns [h, s, l] where h is 0-360, s and l are 0-1, or null if parsing fails.\n */\nfunction parseHslValues(str: string): [number, number, number] | null {\n const match = str.match(/hsla?\\(([^)]+)\\)/i);\n if (!match) return null;\n\n const inner = match[1].trim();\n // Split by slash first (for alpha), then handle color components\n const [colorPart] = inner.split('/');\n // Split by comma or whitespace\n const parts = colorPart\n .trim()\n .split(/[,\\s]+/)\n .filter(Boolean);\n\n if (parts.length < 3) return null;\n\n // Parse hue (can be unitless degrees, deg, turn, rad, or grad)\n let h = parseFloat(parts[0]);\n const hueStr = parts[0].toLowerCase();\n if (hueStr.endsWith('turn')) {\n h = parseFloat(hueStr) * 360;\n } else if (hueStr.endsWith('rad')) {\n h = (parseFloat(hueStr) * 180) / Math.PI;\n } else if (hueStr.endsWith('grad')) {\n h = parseFloat(hueStr) * 0.9; // 400 grad = 360 deg\n }\n // deg or unitless are already in degrees\n\n // Normalize hue to 0-360 range\n h = h % 360;\n if (h < 0) h += 360;\n\n // Parse saturation and lightness (percentages)\n const parsePercent = (val: string): number => {\n const num = parseFloat(val);\n return val.includes('%') ? num / 100 : num;\n };\n\n const s = Math.max(0, Math.min(1, parsePercent(parts[1])));\n const l = Math.max(0, Math.min(1, parsePercent(parts[2])));\n\n return [h, s, l];\n}\n\n/**\n * Convert HSL to RGB (sRGB).\n * Algorithm from: https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative\n * Same as used in CSS Color 4 spec.\n *\n * @param h - Hue in degrees (0-360)\n * @param s - Saturation (0-1)\n * @param l - Lightness (0-1)\n * @returns RGB values in 0-255 range (may have fractional values)\n */\nexport function hslToRgbValues(\n h: number,\n s: number,\n l: number,\n): [number, number, number] {\n const a = s * Math.min(l, 1 - l);\n\n const f = (n: number): number => {\n const k = (n + h / 30) % 12;\n return l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));\n };\n\n // Convert 0-1 range to 0-255\n return [f(0) * 255, f(8) * 255, f(4) * 255];\n}\n\n/**\n * Format a number to a string with up to 1 decimal place, removing trailing zeros.\n */\nfunction formatRgbComponent(n: number): string {\n return parseFloat(n.toFixed(1)).toString();\n}\n\n/**\n * Extract RGB triplet from a color value.\n * Returns the RGB values as a space-separated string (e.g., \"255 128 0\")\n * or a CSS variable reference for token colors.\n */\nfunction extractRgbValue(colorValue: string, parsedOutput: string): string {\n // If the parsed output references a color variable, use the -rgb variant\n const varMatch = parsedOutput.match(/var\\(--([a-z0-9-]+)-color\\)/);\n if (varMatch) {\n return `var(--${varMatch[1]}-color-rgb)`;\n }\n\n // For rgb(...) values, extract the triplet\n if (parsedOutput.startsWith('rgb(')) {\n const rgbValues = getRgbValuesFromRgbaString(parsedOutput);\n if (rgbValues && rgbValues.length >= 3) {\n return rgbValues.join(' ');\n }\n }\n\n // For hsl(...) values, convert to RGB triplet\n if (\n parsedOutput.startsWith('hsl(') ||\n parsedOutput.startsWith('hsla(') ||\n colorValue.startsWith('hsl(') ||\n colorValue.startsWith('hsla(')\n ) {\n // Try parsedOutput first, then original colorValue\n const hslValues =\n parseHslValues(parsedOutput) || parseHslValues(colorValue);\n if (hslValues) {\n const [r, g, b] = hslToRgbValues(\n hslValues[0],\n hslValues[1],\n hslValues[2],\n );\n return `${formatRgbComponent(r)} ${formatRgbComponent(g)} ${formatRgbComponent(b)}`;\n }\n }\n\n // For okhsl(...) values, convert to RGB triplet\n if (parsedOutput.startsWith('okhsl(') || colorValue.startsWith('okhsl(')) {\n // Try parsedOutput first, then original colorValue\n const rgbResult = okhslToRgb(parsedOutput) || okhslToRgb(colorValue);\n if (rgbResult) {\n const rgbValues = getRgbValuesFromRgbaString(rgbResult);\n if (rgbValues && rgbValues.length >= 3) {\n return rgbValues.join(' ');\n }\n }\n }\n\n // For hex values, convert to RGB triplet\n if (colorValue.startsWith('#') && /^#[0-9a-fA-F]{3,8}$/.test(colorValue)) {\n const rgbResult = hexToRgb(colorValue);\n if (rgbResult) {\n const rgbValues = getRgbValuesFromRgbaString(rgbResult);\n if (rgbValues && rgbValues.length >= 3) {\n return rgbValues.join(' ');\n }\n }\n }\n\n // Fallback: return the parsed output (may not be ideal but covers edge cases)\n return parsedOutput;\n}\n\n/**\n * Check if a value is a valid token value (string, number, or boolean - not object).\n * Returns false for `false` values (they mean \"skip this token\").\n */\nfunction isValidTokenValue(\n value: unknown,\n): value is Exclude<TokenValue, undefined | null | false> {\n if (value === undefined || value === null || value === false) {\n return false;\n }\n\n if (typeof value === 'object') {\n if (devMode) {\n console.warn(\n 'CubeUIKit: Object values are not allowed in tokens prop. ' +\n 'Tokens do not support state-based styling. Use a primitive value instead.',\n );\n }\n return false;\n }\n\n return (\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n );\n}\n\n/**\n * Process a single token value through the tasty parser.\n * Numbers are converted to strings; 0 stays as \"0\".\n */\nfunction processTokenValue(value: string | number): string {\n if (typeof value === 'number') {\n // 0 should remain as \"0\", not converted to any unit\n if (value === 0) {\n return '0';\n }\n return parseStyle(String(value)).output;\n }\n return parseStyle(value).output;\n}\n\n/**\n * Process tokens object into inline style properties.\n * - $name -> --name with parsed value\n * - #name -> --name-color AND --name-color-rgb with parsed values\n *\n * @param tokens - The tokens object to process\n * @returns CSSProperties object or undefined if no tokens to process\n */\nexport function processTokens(\n tokens: Tokens | undefined,\n): CSSProperties | undefined {\n if (!tokens) {\n return undefined;\n }\n\n const keys = Object.keys(tokens);\n if (keys.length === 0) {\n return undefined;\n }\n\n let result: Record<string, string> | undefined;\n\n for (const key of keys) {\n const value = tokens[key as keyof Tokens];\n\n // Skip undefined/null values\n if (!isValidTokenValue(value)) {\n continue;\n }\n\n if (key.startsWith('$')) {\n // Custom property token: $name -> --name\n const propName = `--${key.slice(1)}`;\n // Boolean true for custom properties converts to empty string (valid CSS value)\n const effectiveValue = value === true ? '' : value;\n const processedValue = processTokenValue(effectiveValue);\n\n if (!result) result = {};\n result[propName] = processedValue;\n } else if (key.startsWith('#')) {\n // Color token: #name -> --name-color and --name-color-rgb\n const colorName = key.slice(1);\n\n // Normalize color token value (true → 'transparent', false is already filtered by isValidTokenValue)\n const effectiveValue = normalizeColorTokenValue(value);\n // Skip if normalized to null (shouldn't happen since false is filtered by isValidTokenValue)\n if (effectiveValue === null) continue;\n\n const originalValue =\n typeof effectiveValue === 'number'\n ? String(effectiveValue)\n : effectiveValue;\n const lowerValue = originalValue.toLowerCase();\n const processedValue = processTokenValue(effectiveValue);\n\n if (!result) result = {};\n result[`--${colorName}-color`] = processedValue;\n\n // Skip RGB generation for #current values (currentcolor is dynamic, cannot extract RGB)\n // Match only #current or #current.opacity, not #current-theme or #currently-used\n if (/^#current(?:\\.|$)/i.test(lowerValue)) {\n continue;\n }\n\n result[`--${colorName}-color-rgb`] = extractRgbValue(\n originalValue,\n processedValue,\n );\n }\n }\n\n return result as CSSProperties | undefined;\n}\n\n/**\n * Stringify tokens for memoization key.\n */\nexport function stringifyTokens(tokens: Tokens | undefined): string {\n if (!tokens) return '';\n return JSON.stringify(tokens);\n}\n"],"mappings":";;;;;;;;;;;;;AAuBA,SAAS,eAAe,KAA8C;CACpE,MAAM,QAAQ,IAAI,MAAM,oBAAoB;AAC5C,KAAI,CAAC,MAAO,QAAO;CAInB,MAAM,CAAC,aAFO,MAAM,GAAG,MAAM,CAEH,MAAM,IAAI;CAEpC,MAAM,QAAQ,UACX,MAAM,CACN,MAAM,SAAS,CACf,OAAO,QAAQ;AAElB,KAAI,MAAM,SAAS,EAAG,QAAO;CAG7B,IAAI,IAAI,WAAW,MAAM,GAAG;CAC5B,MAAM,SAAS,MAAM,GAAG,aAAa;AACrC,KAAI,OAAO,SAAS,OAAO,CACzB,KAAI,WAAW,OAAO,GAAG;UAChB,OAAO,SAAS,MAAM,CAC/B,KAAK,WAAW,OAAO,GAAG,MAAO,KAAK;UAC7B,OAAO,SAAS,OAAO,CAChC,KAAI,WAAW,OAAO,GAAG;AAK3B,KAAI,IAAI;AACR,KAAI,IAAI,EAAG,MAAK;CAGhB,MAAM,gBAAgB,QAAwB;EAC5C,MAAM,MAAM,WAAW,IAAI;AAC3B,SAAO,IAAI,SAAS,IAAI,GAAG,MAAM,MA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Q,UAAS,EAAE;AACxB,UAAO,YAAY;aACV,IAAI,WAAW,IAAI,EAAE;GAE9B,MAAM,YAAY,IAAI,MAAM,EAAE;GAG9B,MAAM,iBAAiB,yBAAyB,MAAM;AAEtD,OAAI,mBAAmB,KAAM;GAE7B,MAAM,gBACJ,OAAO,mBAAmB,WACtB,OAAO,eAAe,GACtB;GACN,MAAM,aAAa,cAAc,aAAa;GAC9C,MAAM,iBAAiB,kBAAkB,eAAe;AAExD,OAAI,CAAC,OAAQ,UAAS,EAAE;AACxB,UAAO,KAAK,UAAU,WAAW;AAIjC,OAAI,qBAAqB,KAAK,WAAW,CACvC;AAGF,UAAO,KAAK,UAAU,eAAe,gBACnC,eACA,eACD;;;AAIL,QAAO;;;;;AAMT,SAAgB,gBAAgB,QAAoC;AAClE,KAAI,CAAC,OAAQ,QAAO;AACpB,QAAO,KAAK,UAAU,OAAO"}
@@ -1,6 +1,6 @@
1
1
  import { isDevEnv } from "./is-dev-env.js";
2
- import { getGlobalRecipes } from "../config.js";
3
2
  import { isSelector } from "../pipeline/index.js";
3
+ import { getGlobalRecipes } from "../config.js";
4
4
  import { mergeStyles } from "./merge-styles.js";
5
5
 
6
6
  //#region src/utils/resolve-recipes.ts
@@ -13,7 +13,7 @@ import { mergeStyles } from "./merge-styles.js";
13
13
  * Resolution order per level (top-level and each sub-element independently):
14
14
  * base_recipe_1 base_recipe_2 → component styles → post_recipe_1 post_recipe_2
15
15
  *
16
- * The `|` separator splits base recipes (before component styles)
16
+ * The `/` separator splits base recipes (before component styles)
17
17
  * from post recipes (after component styles). All merges use mergeStyles
18
18
  * semantics: primitives and state maps with '' key fully replace;
19
19
  * state maps without '' key extend the existing value.
@@ -24,10 +24,11 @@ const devMode = isDevEnv();
24
24
  /**
25
25
  * Parse a recipe string into base and post recipe name groups.
26
26
  *
27
- * Syntax: `'base1 base2 | post1 post2'`
27
+ * Syntax: `'base1 base2 / post1 post2'`
28
28
  * - Names are space-separated within each group
29
- * - `|` separates base (before component) from post (after component) groups
30
- * - `|` is optional; if absent, all names are base
29
+ * - `/` separates base (before component) from post (after component) groups
30
+ * - `/` is optional; if absent, all names are base
31
+ * - `none` as the sole base value means "no base recipes"
31
32
  *
32
33
  * Returns `{ base: null, post: null }` if the string is empty or invalid.
33
34
  */
@@ -39,15 +40,18 @@ function parseRecipeNames(value) {
39
40
  if (typeof value !== "string") return empty;
40
41
  const trimmed = value.trim();
41
42
  if (trimmed === "") return empty;
42
- const pipeIndex = trimmed.indexOf("|");
43
- if (pipeIndex === -1) return {
44
- base: splitNames(trimmed),
45
- post: null
46
- };
47
- const basePart = trimmed.slice(0, pipeIndex);
48
- const postPart = trimmed.slice(pipeIndex + 1);
43
+ const slashIndex = trimmed.indexOf("/");
44
+ if (slashIndex === -1) {
45
+ if (trimmed === "none") return empty;
46
+ return {
47
+ base: splitNames(trimmed),
48
+ post: null
49
+ };
50
+ }
51
+ const basePart = trimmed.slice(0, slashIndex);
52
+ const postPart = trimmed.slice(slashIndex + 1);
49
53
  return {
50
- base: splitNames(basePart),
54
+ base: basePart.trim() === "none" ? null : splitNames(basePart),
51
55
  post: splitNames(postPart)
52
56
  };
53
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-recipes.js","names":[],"sources":["../../src/utils/resolve-recipes.ts"],"sourcesContent":["/**\n * Recipe resolution utility.\n *\n * Resolves `recipe` style properties by looking up predefined recipe styles\n * from global configuration and merging them with the component's own styles.\n *\n * Resolution order per level (top-level and each sub-element independently):\n * base_recipe_1 base_recipe_2 → component styles → post_recipe_1 post_recipe_2\n *\n * The `|` separator splits base recipes (before component styles)\n * from post recipes (after component styles). All merges use mergeStyles\n * semantics: primitives and state maps with '' key fully replace;\n * state maps without '' key extend the existing value.\n *\n * Returns the same object reference if no recipes are present (zero overhead).\n */\n\nimport { getGlobalRecipes } from '../config';\nimport { isSelector } from '../pipeline';\nimport type { RecipeStyles, Styles } from '../styles/types';\n\nimport { isDevEnv } from './is-dev-env';\nimport { mergeStyles } from './merge-styles';\n\nconst devMode = isDevEnv();\n\ninterface ParsedRecipeGroups {\n base: string[] | null;\n post: string[] | null;\n}\n\n/**\n * Parse a recipe string into base and post recipe name groups.\n *\n * Syntax: `'base1 base2 | post1 post2'`\n * - Names are space-separated within each group\n * - `|` separates base (before component) from post (after component) groups\n * - `|` is optional; if absent, all names are base\n *\n * Returns `{ base: null, post: null }` if the string is empty or invalid.\n */\nfunction parseRecipeNames(value: unknown): ParsedRecipeGroups {\n const empty: ParsedRecipeGroups = { base: null, post: null };\n\n if (typeof value !== 'string') return empty;\n const trimmed = value.trim();\n if (trimmed === '') return empty;\n\n const pipeIndex = trimmed.indexOf('|');\n\n if (pipeIndex === -1) {\n const names = splitNames(trimmed);\n return { base: names, post: null };\n }\n\n const basePart = trimmed.slice(0, pipeIndex);\n const postPart = trimmed.slice(pipeIndex + 1);\n\n return {\n base: splitNames(basePart),\n post: splitNames(postPart),\n };\n}\n\nfunction splitNames(s: string): string[] | null {\n const names = s.split(/\\s+/).filter(Boolean);\n return names.length > 0 ? names : null;\n}\n\n/**\n * Collect merged styles for a list of recipe names.\n * Each recipe is flat-spread on top of the previous.\n */\nfunction collectRecipeStyles(\n names: string[],\n recipes: Record<string, RecipeStyles>,\n): Record<string, unknown> {\n let merged: Record<string, unknown> = {};\n\n for (const name of names) {\n const recipeStyles = recipes[name];\n\n if (!recipeStyles) {\n if (devMode) {\n console.warn(\n `[Tasty] Recipe \"${name}\" not found. ` +\n `Make sure it is defined in configure({ recipes: { ... } }).`,\n );\n }\n continue;\n }\n\n merged = { ...merged, ...(recipeStyles as Record<string, unknown>) };\n }\n\n return merged;\n}\n\n/**\n * Resolve recipe references in a flat styles object (no sub-elements).\n * Returns null if no `recipe` key is present.\n *\n * Resolution: base recipes → component styles → post recipes (all via mergeStyles)\n */\nfunction resolveRecipesForLevel(\n styles: Record<string, unknown>,\n recipes: Record<string, RecipeStyles>,\n): Record<string, unknown> | null {\n if (!('recipe' in styles)) return null;\n\n const { base, post } = parseRecipeNames(styles.recipe);\n\n // Separate selector keys (sub-elements) from flat style properties.\n // mergeStyles handles selectors with its own semantics (e.g. false = delete),\n // but at this level we only want recipe merging on flat properties.\n\n const { recipe: _recipe, ...allRest } = styles;\n const flatStyles: Record<string, unknown> = {};\n const selectorStyles: Record<string, unknown> = {};\n\n for (const key of Object.keys(allRest)) {\n if (isSelector(key)) {\n selectorStyles[key] = allRest[key];\n } else {\n flatStyles[key] = allRest[key];\n }\n }\n\n if (!base && !post) {\n return allRest;\n }\n\n // 1. Merge base recipes, then component styles on top (via mergeStyles)\n let result: Record<string, unknown>;\n\n if (base) {\n const baseStyles = collectRecipeStyles(base, recipes);\n result = mergeStyles(baseStyles as Styles, flatStyles as Styles) as Record<\n string,\n unknown\n >;\n } else {\n result = { ...flatStyles };\n }\n\n // 2. Apply post recipes via mergeStyles (state map extend semantics)\n if (post) {\n const postStyles = collectRecipeStyles(post, recipes);\n result = mergeStyles(result as Styles, postStyles as Styles) as Record<\n string,\n unknown\n >;\n }\n\n // Re-attach selector keys unchanged\n for (const key of Object.keys(selectorStyles)) {\n result[key] = selectorStyles[key];\n }\n\n return result;\n}\n\n/**\n * Resolve all `recipe` style properties in a styles object.\n *\n * Handles both top-level and sub-element recipe references.\n * Returns the same object reference if no recipes are present anywhere\n * (zero overhead for the common case).\n *\n * @param styles - The styles object potentially containing `recipe` keys\n * @returns Resolved styles with recipe values merged in, or the original object if unchanged\n */\nexport function resolveRecipes(styles: Styles): Styles {\n const recipes = getGlobalRecipes();\n\n // Fast path: no recipes configured globally\n if (!recipes) return styles;\n\n let changed = false;\n\n // Resolve top-level recipe\n const topResolved = resolveRecipesForLevel(\n styles as Record<string, unknown>,\n recipes,\n );\n\n let result: Record<string, unknown>;\n\n if (topResolved) {\n changed = true;\n result = topResolved;\n } else {\n // Keep reference; a shallow copy is deferred until a sub-element actually changes\n result = styles as Record<string, unknown>;\n }\n\n // Resolve sub-element recipes\n const keys = Object.keys(result);\n\n for (const key of keys) {\n if (!isSelector(key)) continue;\n\n const subStyles = result[key];\n\n if (\n !subStyles ||\n typeof subStyles !== 'object' ||\n Array.isArray(subStyles)\n ) {\n continue;\n }\n\n const subRecord = subStyles as Record<string, unknown>;\n\n if (!('recipe' in subRecord)) continue;\n\n const subResolved = resolveRecipesForLevel(subRecord, recipes);\n\n if (subResolved) {\n if (!changed) {\n // First change in sub-elements -- need to shallow-copy the top level\n changed = true;\n result = { ...(styles as Record<string, unknown>) };\n }\n result[key] = subResolved;\n }\n }\n\n return changed ? (result as Styles) : styles;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,UAAU,UAAU;;;;;;;;;;;AAiB1B,SAAS,iBAAiB,OAAoC;CAC5D,MAAM,QAA4B;EAAE,MAAM;EAAM,MAAM;EAAM;AAE5D,KAAI,OAAO,UAAU,SAAU,QAAO;CACtC,MAAM,UAAU,MAAM,MAAM;AAC5B,KAAI,YAAY,GAAI,QAAO;CAE3B,MAAM,YAAY,QAAQ,QAAQ,IAAI;AAEtC,KAAI,cAAc,GAEhB,QAAO;EAAE,MADK,WAAW,QAAQ;EACX,MAAM;EAAM;CAGpC,MAAM,WAAW,QAAQ,MAAM,GAAG,UAAU;CAC5C,MAAM,WAAW,QAAQ,MAAM,YAAY,EAAE;AAE7C,QAAO;EACL,MAAM,WAAW,SAAS;EAC1B,MAAM,WAAW,SAAS;EAC3B;;AAGH,SAAS,WAAW,GAA4B;CAC9C,MAAM,QAAQ,EAAE,MAAM,MAAM,CAAC,OAAO,QAAQ;AAC5C,QAAO,MAAM,SAAS,IAAI,QAAQ;;;;;;AAOpC,SAAS,oBACP,OACA,SACyB;CACzB,IAAI,SAAkC,EAAE;AAExC,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,eAAe,QAAQ;AAE7B,MAAI,CAAC,cAAc;AACjB,OAAI,QACF,SAAQ,KACN,mBAAmB,KAAK,0EAEzB;AAEH;;AAGF,WAAS;GAAE,GAAG;GAAQ,GAAI;GAA0C;;A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ACV,aAAS,EAAE,GAAI,QAAoC;;AAErD,UAAO,OAAO;;;AAIlB,QAAO,UAAW,SAAoB"}
1
+ {"version":3,"file":"resolve-recipes.js","names":[],"sources":["../../src/utils/resolve-recipes.ts"],"sourcesContent":["/**\n * Recipe resolution utility.\n *\n * Resolves `recipe` style properties by looking up predefined recipe styles\n * from global configuration and merging them with the component's own styles.\n *\n * Resolution order per level (top-level and each sub-element independently):\n * base_recipe_1 base_recipe_2 → component styles → post_recipe_1 post_recipe_2\n *\n * The `/` separator splits base recipes (before component styles)\n * from post recipes (after component styles). All merges use mergeStyles\n * semantics: primitives and state maps with '' key fully replace;\n * state maps without '' key extend the existing value.\n *\n * Returns the same object reference if no recipes are present (zero overhead).\n */\n\nimport { getGlobalRecipes } from '../config';\nimport { isSelector } from '../pipeline';\nimport type { RecipeStyles, Styles } from '../styles/types';\n\nimport { isDevEnv } from './is-dev-env';\nimport { mergeStyles } from './merge-styles';\n\nconst devMode = isDevEnv();\n\ninterface ParsedRecipeGroups {\n base: string[] | null;\n post: string[] | null;\n}\n\n/**\n * Parse a recipe string into base and post recipe name groups.\n *\n * Syntax: `'base1 base2 / post1 post2'`\n * - Names are space-separated within each group\n * - `/` separates base (before component) from post (after component) groups\n * - `/` is optional; if absent, all names are base\n * - `none` as the sole base value means \"no base recipes\"\n *\n * Returns `{ base: null, post: null }` if the string is empty or invalid.\n */\nfunction parseRecipeNames(value: unknown): ParsedRecipeGroups {\n const empty: ParsedRecipeGroups = { base: null, post: null };\n\n if (typeof value !== 'string') return empty;\n const trimmed = value.trim();\n if (trimmed === '') return empty;\n\n const slashIndex = trimmed.indexOf('/');\n\n if (slashIndex === -1) {\n if (trimmed === 'none') return empty;\n const names = splitNames(trimmed);\n return { base: names, post: null };\n }\n\n const basePart = trimmed.slice(0, slashIndex);\n const postPart = trimmed.slice(slashIndex + 1);\n\n return {\n base: basePart.trim() === 'none' ? null : splitNames(basePart),\n post: splitNames(postPart),\n };\n}\n\nfunction splitNames(s: string): string[] | null {\n const names = s.split(/\\s+/).filter(Boolean);\n return names.length > 0 ? names : null;\n}\n\n/**\n * Collect merged styles for a list of recipe names.\n * Each recipe is flat-spread on top of the previous.\n */\nfunction collectRecipeStyles(\n names: string[],\n recipes: Record<string, RecipeStyles>,\n): Record<string, unknown> {\n let merged: Record<string, unknown> = {};\n\n for (const name of names) {\n const recipeStyles = recipes[name];\n\n if (!recipeStyles) {\n if (devMode) {\n console.warn(\n `[Tasty] Recipe \"${name}\" not found. ` +\n `Make sure it is defined in configure({ recipes: { ... } }).`,\n );\n }\n continue;\n }\n\n merged = { ...merged, ...(recipeStyles as Record<string, unknown>) };\n }\n\n return merged;\n}\n\n/**\n * Resolve recipe references in a flat styles object (no sub-elements).\n * Returns null if no `recipe` key is present.\n *\n * Resolution: base recipes → component styles → post recipes (all via mergeStyles)\n */\nfunction resolveRecipesForLevel(\n styles: Record<string, unknown>,\n recipes: Record<string, RecipeStyles>,\n): Record<string, unknown> | null {\n if (!('recipe' in styles)) return null;\n\n const { base, post } = parseRecipeNames(styles.recipe);\n\n // Separate selector keys (sub-elements) from flat style properties.\n // mergeStyles handles selectors with its own semantics (e.g. false = delete),\n // but at this level we only want recipe merging on flat properties.\n\n const { recipe: _recipe, ...allRest } = styles;\n const flatStyles: Record<string, unknown> = {};\n const selectorStyles: Record<string, unknown> = {};\n\n for (const key of Object.keys(allRest)) {\n if (isSelector(key)) {\n selectorStyles[key] = allRest[key];\n } else {\n flatStyles[key] = allRest[key];\n }\n }\n\n if (!base && !post) {\n return allRest;\n }\n\n // 1. Merge base recipes, then component styles on top (via mergeStyles)\n let result: Record<string, unknown>;\n\n if (base) {\n const baseStyles = collectRecipeStyles(base, recipes);\n result = mergeStyles(baseStyles as Styles, flatStyles as Styles) as Record<\n string,\n unknown\n >;\n } else {\n result = { ...flatStyles };\n }\n\n // 2. Apply post recipes via mergeStyles (state map extend semantics)\n if (post) {\n const postStyles = collectRecipeStyles(post, recipes);\n result = mergeStyles(result as Styles, postStyles as Styles) as Record<\n string,\n unknown\n >;\n }\n\n // Re-attach selector keys unchanged\n for (const key of Object.keys(selectorStyles)) {\n result[key] = selectorStyles[key];\n }\n\n return result;\n}\n\n/**\n * Resolve all `recipe` style properties in a styles object.\n *\n * Handles both top-level and sub-element recipe references.\n * Returns the same object reference if no recipes are present anywhere\n * (zero overhead for the common case).\n *\n * @param styles - The styles object potentially containing `recipe` keys\n * @returns Resolved styles with recipe values merged in, or the original object if unchanged\n */\nexport function resolveRecipes(styles: Styles): Styles {\n const recipes = getGlobalRecipes();\n\n // Fast path: no recipes configured globally\n if (!recipes) return styles;\n\n let changed = false;\n\n // Resolve top-level recipe\n const topResolved = resolveRecipesForLevel(\n styles as Record<string, unknown>,\n recipes,\n );\n\n let result: Record<string, unknown>;\n\n if (topResolved) {\n changed = true;\n result = topResolved;\n } else {\n // Keep reference; a shallow copy is deferred until a sub-element actually changes\n result = styles as Record<string, unknown>;\n }\n\n // Resolve sub-element recipes\n const keys = Object.keys(result);\n\n for (const key of keys) {\n if (!isSelector(key)) continue;\n\n const subStyles = result[key];\n\n if (\n !subStyles ||\n typeof subStyles !== 'object' ||\n Array.isArray(subStyles)\n ) {\n continue;\n }\n\n const subRecord = subStyles as Record<string, unknown>;\n\n if (!('recipe' in subRecord)) continue;\n\n const subResolved = resolveRecipesForLevel(subRecord, recipes);\n\n if (subResolved) {\n if (!changed) {\n // First change in sub-elements -- need to shallow-copy the top level\n changed = true;\n result = { ...(styles as Record<string, unknown>) };\n }\n result[key] = subResolved;\n }\n }\n\n return changed ? (result as Styles) : styles;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,UAAU,UAAU;;;;;;;;;;;;AAkB1B,SAAS,iBAAiB,OAAoC;CAC5D,MAAM,QAA4B;EAAE,MAAM;EAAM,MAAM;EAAM;AAE5D,KAAI,OAAO,UAAU,SAAU,QAAO;CACtC,MAAM,UAAU,MAAM,MAAM;AAC5B,KAAI,YAAY,GAAI,QAAO;CA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EACR,MAAM,aAAa,oBAAoB,MAAM,QAAQ;AACrD,WAAS,YAAY,QAAkB,WAAqB;;AAO9D,MAAK,MAAM,OAAO,OAAO,KAAK,eAAe,CAC3C,QAAO,OAAO,eAAe;AAG/B,QAAO;;;;;;;;;;;;AAaT,SAAgB,eAAe,QAAwB;CACrD,MAAM,UAAU,kBAAkB;AAGlC,KAAI,CAAC,QAAS,QAAO;CAErB,IAAI,UAAU;CAGd,MAAM,cAAc,uBAClB,QACA,QACD;CAED,IAAI;AAEJ,KAAI,aAAa;AACf,YAAU;AACV,WAAS;OAGT,UAAS;CAIX,MAAM,OAAO,OAAO,KAAK,OAAO;AAEhC,MAAK,MAAM,OAAO,MAAM;AACtB,MAAI,CAAC,WAAW,IAAI,CAAE;EAEtB,MAAM,YAAY,OAAO;AAEzB,MACE,CAAC,aACD,OAAO,cAAc,YACrB,MAAM,QAAQ,UAAU,CAExB;EAGF,MAAM,YAAY;AAElB,MAAI,EAAE,YAAY,WAAY;EAE9B,MAAM,cAAc,uBAAuB,WAAW,QAAQ;AAE9D,MAAI,aAAa;AACf,OAAI,CAAC,SAAS;AAEZ,cAAU;AACV,aAAS,EAAE,GAAI,QAAoC;;AAErD,UAAO,OAAO;;;AAIlB,QAAO,UAAW,SAAoB"}
@@ -1,10 +1,10 @@
1
1
  import { StyleParser } from "../parser/parser.js";
2
2
  import { okhslFunc } from "../plugins/okhsl-plugin.js";
3
+ import { createStateParserContext, parseAdvancedState } from "../states/index.js";
3
4
  import { cacheWrapper } from "./cache-wrapper.js";
4
5
  import { camelToKebab } from "./case-converter.js";
5
6
  import { okhslToRgb } from "./okhsl-to-rgb.js";
6
7
  import { hslToRgb } from "./hsl-to-rgb.js";
7
- import { createStateParserContext, parseAdvancedState } from "../states/index.js";
8
8
 
9
9
  //#region src/utils/styles.ts
10
10
  /**
@@ -1,4 +1,3 @@
1
- import "../injector/types.js";
2
1
  import { Styles } from "../styles/types.js";
3
2
 
4
3
  //#region src/zero/extractor.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenphi/tasty",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "A design-system-integrated styling system and DSL for concise, state-aware UI styling",
5
5
  "type": "module",
6
6
  "exports": {
@@ -34,10 +34,10 @@
34
34
  "default": "./dist/zero/next.js"
35
35
  }
36
36
  },
37
- "./parser": {
37
+ "./core": {
38
38
  "import": {
39
- "types": "./dist/parser/index.d.ts",
40
- "default": "./dist/parser/index.js"
39
+ "types": "./dist/core/index.d.ts",
40
+ "default": "./dist/core/index.js"
41
41
  }
42
42
  }
43
43
  },
@@ -1 +0,0 @@
1
- import "../styles/types.js";
@@ -1,3 +0,0 @@
1
- import { CHUNK_NAMES, ChunkInfo, ChunkName, STYLE_TO_CHUNK, categorizeStyleKeys } from "./definitions.js";
2
- import "./cacheKey.js";
3
- import "./renderChunk.js";
@@ -1,2 +0,0 @@
1
- import "../styles/types.js";
2
- import "../pipeline/index.js";
@@ -1,5 +0,0 @@
1
- import { UseStylesOptions, UseStylesResult, useStyles } from "./useStyles.js";
2
- import { useGlobalStyles } from "./useGlobalStyles.js";
3
- import { useRawCSS } from "./useRawCSS.js";
4
- import { useKeyframes } from "./useKeyframes.js";
5
- import { UsePropertyOptions, useProperty } from "./useProperty.js";
@@ -1,3 +0,0 @@
1
- import { Bucket, ParserOptions, ProcessedStyle, StyleDetails, StyleDetailsPart, UnitHandler } from "./types.js";
2
- import { StyleParser } from "./parser.js";
3
- export { Bucket, type ParserOptions, type ProcessedStyle, type StyleDetails, type StyleDetailsPart, StyleParser, type UnitHandler };
@@ -1,4 +0,0 @@
1
- import { Bucket } from "./types.js";
2
- import { StyleParser } from "./parser.js";
3
-
4
- export { Bucket, StyleParser };
@@ -1 +0,0 @@
1
- import "../utils/styles.js";
@@ -1,2 +0,0 @@
1
- import { TastyPlugin, TastyPluginFactory } from "./types.js";
2
- import { okhslFunc, okhslPlugin } from "./okhsl-plugin.js";