@tenphi/tasty 0.0.0-snapshot.c8bdaeb → 0.0.0-snapshot.d82c48b

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,3 +1,4 @@
1
+ import { COLOR_FUNCS, RE_HEX, RE_NUMBER, RE_RAW_UNIT } from "../parser/const.js";
1
2
  import { getRgbValuesFromRgbaString, strToRgb } from "../utils/styles.js";
2
3
 
3
4
  //#region src/properties/index.ts
@@ -152,7 +153,106 @@ function colorInitialValueToRgb(initialValue) {
152
153
  }
153
154
  return "0 0 0";
154
155
  }
156
+ const VAR_COLOR_PATTERN = /^var\(--[a-z0-9-]+-color/;
157
+ /**
158
+ * Check whether a CSS value is a color.
159
+ * Detects named CSS colors, hex values, color functions (rgb, hsl, oklch, etc.),
160
+ * transparent, currentcolor, and var(--*-color) references.
161
+ */
162
+ function isColorValue(value) {
163
+ if (!value || typeof value !== "string") return false;
164
+ const trimmed = value.trim().toLowerCase();
165
+ if (!trimmed) return false;
166
+ if (trimmed === "transparent" || trimmed === "currentcolor") return true;
167
+ if (VAR_COLOR_PATTERN.test(trimmed)) return true;
168
+ if (trimmed.startsWith("#") && RE_HEX.test(trimmed.slice(1))) return true;
169
+ const parenIdx = trimmed.indexOf("(");
170
+ if (parenIdx > 0) {
171
+ const fname = trimmed.slice(0, parenIdx);
172
+ if (COLOR_FUNCS.has(fname)) return true;
173
+ }
174
+ return strToRgb(trimmed) != null;
175
+ }
176
+ const UNIT_TO_SYNTAX = {};
177
+ const LENGTH_UNITS = [
178
+ "px",
179
+ "em",
180
+ "rem",
181
+ "vw",
182
+ "vh",
183
+ "vmin",
184
+ "vmax",
185
+ "ch",
186
+ "ex",
187
+ "cap",
188
+ "ic",
189
+ "lh",
190
+ "rlh",
191
+ "svw",
192
+ "svh",
193
+ "lvw",
194
+ "lvh",
195
+ "dvw",
196
+ "dvh",
197
+ "cqw",
198
+ "cqh",
199
+ "cqi",
200
+ "cqb",
201
+ "cqmin",
202
+ "cqmax"
203
+ ];
204
+ const ANGLE_UNITS = [
205
+ "deg",
206
+ "rad",
207
+ "grad",
208
+ "turn"
209
+ ];
210
+ const TIME_UNITS = ["ms", "s"];
211
+ for (const u of LENGTH_UNITS) UNIT_TO_SYNTAX[u] = {
212
+ syntax: "<length>",
213
+ initialValue: "0px"
214
+ };
215
+ UNIT_TO_SYNTAX["%"] = {
216
+ syntax: "<percentage>",
217
+ initialValue: "0%"
218
+ };
219
+ for (const u of ANGLE_UNITS) UNIT_TO_SYNTAX[u] = {
220
+ syntax: "<angle>",
221
+ initialValue: "0deg"
222
+ };
223
+ for (const u of TIME_UNITS) UNIT_TO_SYNTAX[u] = {
224
+ syntax: "<time>",
225
+ initialValue: "0s"
226
+ };
227
+ /**
228
+ * Infer CSS @property syntax from a concrete value.
229
+ * Inference is purely value-based; name-based checks (e.g. --*-color naming)
230
+ * are handled by the validator in PropertyTypeResolver.
231
+ *
232
+ * @param value - The CSS value to infer from (e.g. '10px', '1', '45deg')
233
+ * @param _propName - Unused, kept for API compatibility
234
+ * @returns Inferred syntax and initial value, or null if not inferable
235
+ */
236
+ function inferSyntaxFromValue(value, _propName) {
237
+ if (!value || typeof value !== "string") return null;
238
+ const trimmed = value.trim();
239
+ if (!trimmed) return null;
240
+ if (isColorValue(trimmed)) return {
241
+ syntax: "<color>",
242
+ initialValue: "transparent"
243
+ };
244
+ if (RE_NUMBER.test(trimmed)) return {
245
+ syntax: "<number>",
246
+ initialValue: "0"
247
+ };
248
+ const unitMatch = trimmed.match(RE_RAW_UNIT);
249
+ if (unitMatch) {
250
+ const mapping = UNIT_TO_SYNTAX[unitMatch[2]];
251
+ if (mapping) return mapping;
252
+ }
253
+ return null;
254
+ }
155
255
 
156
256
  //#endregion
157
- export { colorInitialValueToRgb, extractLocalProperties, getEffectiveDefinition, hasLocalProperties, normalizePropertyDefinition };
257
+ export { colorInitialValueToRgb, extractLocalProperties, getEffectiveDefinition, hasLocalProperties, inferSyntaxFromValue, normalizePropertyDefinition };
158
258
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/properties/index.ts"],"sourcesContent":["/**\n * Properties Utilities\n *\n * Utilities for extracting and processing CSS @property definitions in styles.\n * Unlike keyframes, properties are permanent once registered and don't need cleanup.\n *\n * Property names use tasty token syntax:\n * - `$name` for regular properties → `--name`\n * - `#name` for color properties → `--name-color` (auto-sets syntax: '<color>')\n */\n\nimport type { PropertyDefinition } from '../injector/types';\nimport type { Styles } from '../styles/types';\nimport { getRgbValuesFromRgbaString, strToRgb } from '../utils/styles';\n\n// ============================================================================\n// Constants\n// ============================================================================\n\nconst PROPERTIES_KEY = '@properties';\n\n/**\n * Valid CSS custom property name pattern (after the -- prefix).\n * Must start with a letter or underscore, followed by letters, digits, hyphens, or underscores.\n */\nconst VALID_PROPERTY_NAME_PATTERN = /^[a-z_][a-z0-9-_]*$/i;\n\n// ============================================================================\n// Validation Functions\n// ============================================================================\n\n/**\n * Validate a CSS custom property name (the part after --).\n * Returns true if the name is valid for use as a CSS custom property.\n */\nexport function isValidPropertyName(name: string): boolean {\n return VALID_PROPERTY_NAME_PATTERN.test(name);\n}\n\n/**\n * Result of parsing a property token.\n */\nexport interface ParsedPropertyToken {\n /** The CSS custom property name (e.g., '--my-prop') */\n cssName: string;\n /** Whether this is a color property */\n isColor: boolean;\n /** Whether the token was valid */\n isValid: boolean;\n /** Error message if invalid */\n error?: string;\n}\n\n// ============================================================================\n// Extraction Functions\n// ============================================================================\n\n/**\n * Check if styles object has local @properties definition.\n * Fast path: single property lookup.\n */\nexport function hasLocalProperties(styles: Styles): boolean {\n return PROPERTIES_KEY in styles;\n}\n\n/**\n * Extract local @properties from styles object.\n * Returns null if no local properties (fast path).\n */\nexport function extractLocalProperties(\n styles: Styles,\n): Record<string, PropertyDefinition> | null {\n const properties = styles[PROPERTIES_KEY];\n if (!properties || typeof properties !== 'object') {\n return null;\n }\n return properties as Record<string, PropertyDefinition>;\n}\n\n// ============================================================================\n// Token Parsing Functions\n// ============================================================================\n\n/**\n * Parse a property token name and return the CSS property name and whether it's a color.\n * Supports tasty token syntax and validates the property name.\n *\n * Token formats:\n * - `$name` → { cssName: '--name', isColor: false }\n * - `#name` → { cssName: '--name-color', isColor: true }\n * - `--name` → { cssName: '--name', isColor: false } (legacy, auto-detect color by suffix)\n * - `name` → { cssName: '--name', isColor: false } (legacy)\n *\n * @param token - The property token to parse\n * @returns Parsed result with cssName, isColor, isValid, and optional error\n */\nexport function parsePropertyToken(token: string): ParsedPropertyToken {\n if (!token || typeof token !== 'string') {\n return {\n cssName: '',\n isColor: false,\n isValid: false,\n error: 'Property token must be a non-empty string',\n };\n }\n\n let name: string;\n let isColor: boolean;\n\n if (token.startsWith('$')) {\n // Regular property token: $name → --name\n name = token.slice(1);\n isColor = false;\n } else if (token.startsWith('#')) {\n // Color property token: #name → --name-color\n name = token.slice(1);\n isColor = true;\n } else if (token.startsWith('--')) {\n // Legacy format with -- prefix\n name = token.slice(2);\n isColor = token.endsWith('-color');\n } else {\n // Legacy format without prefix\n name = token;\n isColor = token.endsWith('-color');\n }\n\n // Validate the name\n if (!name) {\n return {\n cssName: '',\n isColor,\n isValid: false,\n error: 'Property name cannot be empty',\n };\n }\n\n if (!isValidPropertyName(name)) {\n return {\n cssName: '',\n isColor,\n isValid: false,\n error: `Invalid property name \"${name}\". Must start with a letter or underscore, followed by letters, digits, hyphens, or underscores.`,\n };\n }\n\n // Build the CSS custom property name\n // For #name tokens, we add -color suffix\n // For legacy formats (--name-color or name-color), the name already includes -color\n let cssName: string;\n if (token.startsWith('#')) {\n // Color token: #name → --name-color\n cssName = `--${name}-color`;\n } else {\n // All other formats: just add -- prefix\n cssName = `--${name}`;\n }\n\n return {\n cssName,\n isColor,\n isValid: true,\n };\n}\n\n// ============================================================================\n// Normalization Functions\n// ============================================================================\n\n/**\n * Normalize a property name to the CSS custom property format.\n *\n * @deprecated Use parsePropertyToken instead for proper token handling\n */\nexport function normalizePropertyName(name: string): string {\n const result = parsePropertyToken(name);\n return result.isValid ? result.cssName : `--${name}`;\n}\n\n/**\n * Normalize a property definition to a consistent string representation.\n * Used for comparing definitions to detect changes/conflicts.\n *\n * Keys are sorted alphabetically to ensure consistent comparison:\n * { inherits: true, syntax: '<color>' } === { syntax: '<color>', inherits: true }\n */\nexport function normalizePropertyDefinition(def: PropertyDefinition): string {\n const normalized: Record<string, unknown> = {};\n\n // Add properties in alphabetical order\n if (def.inherits !== undefined) {\n normalized.inherits = def.inherits;\n }\n if (def.initialValue !== undefined) {\n normalized.initialValue = String(def.initialValue);\n }\n if (def.syntax !== undefined) {\n normalized.syntax = def.syntax;\n }\n\n return JSON.stringify(normalized);\n}\n\n/**\n * Result of getEffectiveDefinition.\n */\nexport interface EffectiveDefinitionResult {\n /** The CSS custom property name */\n cssName: string;\n /** The effective property definition */\n definition: PropertyDefinition;\n /** Whether this is a color property */\n isColor: boolean;\n /** Whether the token was valid */\n isValid: boolean;\n /** Error message if invalid */\n error?: string;\n}\n\n/**\n * Get the effective property definition for a token.\n * For color tokens (#name), auto-sets syntax to '<color>' and defaults initialValue to 'transparent'.\n *\n * @param token - Property token ($name, #name, --name, or plain name)\n * @param userDefinition - User-provided definition options\n * @returns Effective definition with cssName, definition, isValid, and optional error\n */\nexport function getEffectiveDefinition(\n token: string,\n userDefinition: PropertyDefinition,\n): EffectiveDefinitionResult {\n const parsed = parsePropertyToken(token);\n\n if (!parsed.isValid) {\n return {\n cssName: '',\n definition: userDefinition,\n isColor: false,\n isValid: false,\n error: parsed.error,\n };\n }\n\n if (parsed.isColor) {\n // Color properties have fixed syntax and default initialValue\n return {\n cssName: parsed.cssName,\n definition: {\n syntax: '<color>', // Always '<color>' for color tokens, cannot be overridden\n inherits: userDefinition.inherits, // Allow inherits to be customized\n initialValue: userDefinition.initialValue ?? 'transparent', // Default to transparent\n },\n isColor: true,\n isValid: true,\n };\n }\n\n // Regular properties use the definition as-is\n return {\n cssName: parsed.cssName,\n definition: userDefinition,\n isColor: false,\n isValid: true,\n };\n}\n\n// ============================================================================\n// Color RGB Companion Helpers\n// ============================================================================\n\n/**\n * Extract RGB triplet string from a color initial value.\n * Used when auto-creating the companion `-rgb` property for color @property definitions.\n *\n * @param initialValue - The color property's initial value (e.g., 'rgb(255 255 255)', 'transparent', '#fff')\n * @returns Space-separated RGB triplet (e.g., '255 255 255'), defaults to '0 0 0'\n */\nexport function colorInitialValueToRgb(initialValue?: string | number): string {\n if (initialValue == null) return '0 0 0';\n\n const str = String(initialValue).trim();\n if (!str || str === 'transparent') return '0 0 0';\n\n const rgba = strToRgb(str);\n if (rgba) {\n const values = getRgbValuesFromRgbaString(rgba);\n if (values.length >= 3) return values.slice(0, 3).join(' ');\n }\n\n return '0 0 0';\n}\n"],"mappings":";;;AAmBA,MAAM,iBAAiB;;;;;AAMvB,MAAM,8BAA8B;;;;;AAUpC,SAAgB,oBAAoB,MAAuB;AACzD,QAAO,4BAA4B,KAAK,KAAK;;;;;;AAyB/C,SAAgB,mBAAmB,QAAyB;AAC1D,QAAO,kBAAkB;;;;;;AAO3B,SAAgB,uBACd,QAC2C;CAC3C,MAAM,aAAa,OAAO;AAC1B,KAAI,CAAC,cAAc,OAAO,eAAe,SACvC,QAAO;AAET,QAAO;;;;;;;;;;;;;;;AAoBT,SAAgB,mBAAmB,OAAoC;AACrE,KAAI,CAAC,SAAS,OAAO,UAAU,SAC7B,QAAO;EACL,SAAS;EACT,SAAS;EACT,SAAS;EACT,OAAO;EACR;CAGH,IAAI;CACJ,IAAI;AAEJ,KAAI,MAAM,WAAW,IAAI,EAAE;AAEzB,SAAO,MAAM,MAAM,EAAE;AACrB,YAAU;YACD,MAAM,WAAW,IAAI,EAAE;AAEhC,SAAO,MAAM,MAAM,EAAE;AACrB,YAAU;YACD,MAAM,WAAW,KAAK,EAAE;AAEjC,SAAO,MAAM,MAAM,EAAE;AACrB,YAAU,MAAM,SAAS,SAAS;QAC7B;AAEL,SAAO;AACP,Y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I,OAAO,UAAU,EAAG,QAAO,OAAO,MAAM,GAAG,EAAE,CAAC,KAAK,IAAI;;AAG7D,QAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/properties/index.ts"],"sourcesContent":["/**\n * Properties Utilities\n *\n * Utilities for extracting and processing CSS @property definitions in styles.\n * Unlike keyframes, properties are permanent once registered and don't need cleanup.\n *\n * Property names use tasty token syntax:\n * - `$name` for regular properties → `--name`\n * - `#name` for color properties → `--name-color` (auto-sets syntax: '<color>')\n */\n\nimport type { PropertyDefinition } from '../injector/types';\nimport { COLOR_FUNCS, RE_HEX, RE_NUMBER, RE_RAW_UNIT } from '../parser/const';\nimport type { Styles } from '../styles/types';\nimport { getRgbValuesFromRgbaString, strToRgb } from '../utils/styles';\n\n// ============================================================================\n// Constants\n// ============================================================================\n\nconst PROPERTIES_KEY = '@properties';\n\n/**\n * Valid CSS custom property name pattern (after the -- prefix).\n * Must start with a letter or underscore, followed by letters, digits, hyphens, or underscores.\n */\nconst VALID_PROPERTY_NAME_PATTERN = /^[a-z_][a-z0-9-_]*$/i;\n\n// ============================================================================\n// Validation Functions\n// ============================================================================\n\n/**\n * Validate a CSS custom property name (the part after --).\n * Returns true if the name is valid for use as a CSS custom property.\n */\nexport function isValidPropertyName(name: string): boolean {\n return VALID_PROPERTY_NAME_PATTERN.test(name);\n}\n\n/**\n * Result of parsing a property token.\n */\nexport interface ParsedPropertyToken {\n /** The CSS custom property name (e.g., '--my-prop') */\n cssName: string;\n /** Whether this is a color property */\n isColor: boolean;\n /** Whether the token was valid */\n isValid: boolean;\n /** Error message if invalid */\n error?: string;\n}\n\n// ============================================================================\n// Extraction Functions\n// ============================================================================\n\n/**\n * Check if styles object has local @properties definition.\n * Fast path: single property lookup.\n */\nexport function hasLocalProperties(styles: Styles): boolean {\n return PROPERTIES_KEY in styles;\n}\n\n/**\n * Extract local @properties from styles object.\n * Returns null if no local properties (fast path).\n */\nexport function extractLocalProperties(\n styles: Styles,\n): Record<string, PropertyDefinition> | null {\n const properties = styles[PROPERTIES_KEY];\n if (!properties || typeof properties !== 'object') {\n return null;\n }\n return properties as Record<string, PropertyDefinition>;\n}\n\n// ============================================================================\n// Token Parsing Functions\n// ============================================================================\n\n/**\n * Parse a property token name and return the CSS property name and whether it's a color.\n * Supports tasty token syntax and validates the property name.\n *\n * Token formats:\n * - `$name` → { cssName: '--name', isColor: false }\n * - `#name` → { cssName: '--name-color', isColor: true }\n * - `--name` → { cssName: '--name', isColor: false } (legacy, auto-detect color by suffix)\n * - `name` → { cssName: '--name', isColor: false } (legacy)\n *\n * @param token - The property token to parse\n * @returns Parsed result with cssName, isColor, isValid, and optional error\n */\nexport function parsePropertyToken(token: string): ParsedPropertyToken {\n if (!token || typeof token !== 'string') {\n return {\n cssName: '',\n isColor: false,\n isValid: false,\n error: 'Property token must be a non-empty string',\n };\n }\n\n let name: string;\n let isColor: boolean;\n\n if (token.startsWith('$')) {\n // Regular property token: $name → --name\n name = token.slice(1);\n isColor = false;\n } else if (token.startsWith('#')) {\n // Color property token: #name → --name-color\n name = token.slice(1);\n isColor = true;\n } else if (token.startsWith('--')) {\n // Legacy format with -- prefix\n name = token.slice(2);\n isColor = token.endsWith('-color');\n } else {\n // Legacy format without prefix\n name = token;\n isColor = token.endsWith('-color');\n }\n\n // Validate the name\n if (!name) {\n return {\n cssName: '',\n isColor,\n isValid: false,\n error: 'Property name cannot be empty',\n };\n }\n\n if (!isValidPropertyName(name)) {\n return {\n cssName: '',\n isColor,\n isValid: false,\n error: `Invalid property name \"${name}\". Must start with a letter or underscore, followed by letters, digits, hyphens, or underscores.`,\n };\n }\n\n // Build the CSS custom property name\n // For #name tokens, we add -color suffix\n // For legacy formats (--name-color or name-color), the name already includes -color\n let cssName: string;\n if (token.startsWith('#')) {\n // Color token: #name → --name-color\n cssName = `--${name}-color`;\n } else {\n // All other formats: just add -- prefix\n cssName = `--${name}`;\n }\n\n return {\n cssName,\n isColor,\n isValid: true,\n };\n}\n\n// ============================================================================\n// Normalization Functions\n// ============================================================================\n\n/**\n * Normalize a property name to the CSS custom property format.\n *\n * @deprecated Use parsePropertyToken instead for proper token handling\n */\nexport function normalizePropertyName(name: string): string {\n const result = parsePropertyToken(name);\n return result.isValid ? result.cssName : `--${name}`;\n}\n\n/**\n * Normalize a property definition to a consistent string representation.\n * Used for comparing definitions to detect changes/conflicts.\n *\n * Keys are sorted alphabetically to ensure consistent comparison:\n * { inherits: true, syntax: '<color>' } === { syntax: '<color>', inherits: true }\n */\nexport function normalizePropertyDefinition(def: PropertyDefinition): string {\n const normalized: Record<string, unknown> = {};\n\n // Add properties in alphabetical order\n if (def.inherits !== undefined) {\n normalized.inherits = def.inherits;\n }\n if (def.initialValue !== undefined) {\n normalized.initialValue = String(def.initialValue);\n }\n if (def.syntax !== undefined) {\n normalized.syntax = def.syntax;\n }\n\n return JSON.stringify(normalized);\n}\n\n/**\n * Result of getEffectiveDefinition.\n */\nexport interface EffectiveDefinitionResult {\n /** The CSS custom property name */\n cssName: string;\n /** The effective property definition */\n definition: PropertyDefinition;\n /** Whether this is a color property */\n isColor: boolean;\n /** Whether the token was valid */\n isValid: boolean;\n /** Error message if invalid */\n error?: string;\n}\n\n/**\n * Get the effective property definition for a token.\n * For color tokens (#name), auto-sets syntax to '<color>' and defaults initialValue to 'transparent'.\n *\n * @param token - Property token ($name, #name, --name, or plain name)\n * @param userDefinition - User-provided definition options\n * @returns Effective definition with cssName, definition, isValid, and optional error\n */\nexport function getEffectiveDefinition(\n token: string,\n userDefinition: PropertyDefinition,\n): EffectiveDefinitionResult {\n const parsed = parsePropertyToken(token);\n\n if (!parsed.isValid) {\n return {\n cssName: '',\n definition: userDefinition,\n isColor: false,\n isValid: false,\n error: parsed.error,\n };\n }\n\n if (parsed.isColor) {\n // Color properties have fixed syntax and default initialValue\n return {\n cssName: parsed.cssName,\n definition: {\n syntax: '<color>', // Always '<color>' for color tokens, cannot be overridden\n inherits: userDefinition.inherits, // Allow inherits to be customized\n initialValue: userDefinition.initialValue ?? 'transparent', // Default to transparent\n },\n isColor: true,\n isValid: true,\n };\n }\n\n // Regular properties use the definition as-is\n return {\n cssName: parsed.cssName,\n definition: userDefinition,\n isColor: false,\n isValid: true,\n };\n}\n\n// ============================================================================\n// Color RGB Companion Helpers\n// ============================================================================\n\n/**\n * Extract RGB triplet string from a color initial value.\n * Used when auto-creating the companion `-rgb` property for color @property definitions.\n *\n * @param initialValue - The color property's initial value (e.g., 'rgb(255 255 255)', 'transparent', '#fff')\n * @returns Space-separated RGB triplet (e.g., '255 255 255'), defaults to '0 0 0'\n */\nexport function colorInitialValueToRgb(initialValue?: string | number): string {\n if (initialValue == null) return '0 0 0';\n\n const str = String(initialValue).trim();\n if (!str || str === 'transparent') return '0 0 0';\n\n const rgba = strToRgb(str);\n if (rgba) {\n const values = getRgbValuesFromRgbaString(rgba);\n if (values.length >= 3) return values.slice(0, 3).join(' ');\n }\n\n return '0 0 0';\n}\n\n// ============================================================================\n// Value Type Inference\n// ============================================================================\n\nconst VAR_COLOR_PATTERN = /^var\\(--[a-z0-9-]+-color/;\n\n/**\n * Check whether a CSS value is a color.\n * Detects named CSS colors, hex values, color functions (rgb, hsl, oklch, etc.),\n * transparent, currentcolor, and var(--*-color) references.\n */\nexport function isColorValue(value: string): boolean {\n if (!value || typeof value !== 'string') return false;\n\n const trimmed = value.trim().toLowerCase();\n if (!trimmed) return false;\n\n if (trimmed === 'transparent' || trimmed === 'currentcolor') return true;\n\n if (VAR_COLOR_PATTERN.test(trimmed)) return true;\n\n // Check for #hex values\n if (trimmed.startsWith('#') && RE_HEX.test(trimmed.slice(1))) return true;\n\n // Check for color functions: rgb(...), hsl(...), oklch(...), etc.\n const parenIdx = trimmed.indexOf('(');\n if (parenIdx > 0) {\n const fname = trimmed.slice(0, parenIdx);\n if (COLOR_FUNCS.has(fname)) return true;\n }\n\n // Check for named CSS colors via strToRgb\n const rgb = strToRgb(trimmed);\n return rgb != null;\n}\n\n/**\n * Result of inferring a CSS @property syntax from a value.\n */\nexport interface InferredSyntax {\n syntax: string;\n initialValue: string;\n}\n\nconst UNIT_TO_SYNTAX: Record<string, InferredSyntax> = {};\n\nconst LENGTH_UNITS = [\n 'px',\n 'em',\n 'rem',\n 'vw',\n 'vh',\n 'vmin',\n 'vmax',\n 'ch',\n 'ex',\n 'cap',\n 'ic',\n 'lh',\n 'rlh',\n 'svw',\n 'svh',\n 'lvw',\n 'lvh',\n 'dvw',\n 'dvh',\n 'cqw',\n 'cqh',\n 'cqi',\n 'cqb',\n 'cqmin',\n 'cqmax',\n];\n\nconst ANGLE_UNITS = ['deg', 'rad', 'grad', 'turn'];\nconst TIME_UNITS = ['ms', 's'];\n\nfor (const u of LENGTH_UNITS) {\n UNIT_TO_SYNTAX[u] = { syntax: '<length>', initialValue: '0px' };\n}\nUNIT_TO_SYNTAX['%'] = { syntax: '<percentage>', initialValue: '0%' };\nfor (const u of ANGLE_UNITS) {\n UNIT_TO_SYNTAX[u] = { syntax: '<angle>', initialValue: '0deg' };\n}\nfor (const u of TIME_UNITS) {\n UNIT_TO_SYNTAX[u] = { syntax: '<time>', initialValue: '0s' };\n}\n\n/**\n * Infer CSS @property syntax from a concrete value.\n * Inference is purely value-based; name-based checks (e.g. --*-color naming)\n * are handled by the validator in PropertyTypeResolver.\n *\n * @param value - The CSS value to infer from (e.g. '10px', '1', '45deg')\n * @param _propName - Unused, kept for API compatibility\n * @returns Inferred syntax and initial value, or null if not inferable\n */\nexport function inferSyntaxFromValue(\n value: string,\n _propName?: string,\n): InferredSyntax | null {\n if (!value || typeof value !== 'string') return null;\n\n const trimmed = value.trim();\n if (!trimmed) return null;\n\n // Value-based color detection\n if (isColorValue(trimmed)) {\n return { syntax: '<color>', initialValue: 'transparent' };\n }\n\n // Bare number\n if (RE_NUMBER.test(trimmed)) {\n return { syntax: '<number>', initialValue: '0' };\n }\n\n // Number with unit\n const unitMatch = trimmed.match(RE_RAW_UNIT);\n if (unitMatch) {\n const unit = unitMatch[2];\n const mapping = UNIT_TO_S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automatically infers CSS @property types from custom property values.
6
+ * Supports deferred resolution for var() reference chains of arbitrary depth.
7
+ */
8
+ declare class PropertyTypeResolver {
9
+ /** propName → the prop it depends on */
10
+ private pendingDeps;
11
+ /** propName → list of props waiting on it */
12
+ private reverseDeps;
13
+ /**
14
+ * Scan CSS declarations and auto-register @property for custom properties
15
+ * whose types can be inferred from their values.
16
+ */
17
+ scanDeclarations(declarations: string, isPropertyDefined: (name: string) => boolean, registerProperty: (name: string, syntax: string, initialValue: string) => void): void;
18
+ private addDependency;
19
+ private resolve;
20
+ /**
21
+ * Validate that the inferred type matches the token naming convention.
22
+ * Returns false (and warns) on mismatch.
23
+ */
24
+ private validateTokenType;
25
+ private isComplexValue;
26
+ }
27
+ //#endregion
28
+ export { PropertyTypeResolver };
29
+ //# sourceMappingURL=property-type-resolver.d.ts.map
@@ -0,0 +1,103 @@
1
+ import { isDevEnv } from "../utils/is-dev-env.js";
2
+ import { inferSyntaxFromValue } from "./index.js";
3
+
4
+ //#region src/properties/property-type-resolver.ts
5
+ /**
6
+ * PropertyTypeResolver
7
+ *
8
+ * Automatically infers CSS @property types from custom property values.
9
+ * Supports deferred resolution for var() reference chains of arbitrary depth.
10
+ */
11
+ const CUSTOM_PROP_DECL = /^\s*(--[a-z0-9_-]+)\s*:\s*(.+?)\s*$/i;
12
+ const SINGLE_VAR_REF = /^var\((--[a-z0-9_-]+)\)$/i;
13
+ var PropertyTypeResolver = class {
14
+ /** propName → the prop it depends on */
15
+ pendingDeps = /* @__PURE__ */ new Map();
16
+ /** propName → list of props waiting on it */
17
+ reverseDeps = /* @__PURE__ */ new Map();
18
+ /**
19
+ * Scan CSS declarations and auto-register @property for custom properties
20
+ * whose types can be inferred from their values.
21
+ */
22
+ scanDeclarations(declarations, isPropertyDefined, registerProperty) {
23
+ const parts = declarations.split(/;+/);
24
+ for (const part of parts) {
25
+ if (!part.trim()) continue;
26
+ const match = CUSTOM_PROP_DECL.exec(part);
27
+ if (!match) continue;
28
+ const propName = match[1];
29
+ const value = match[2].trim();
30
+ if (isPropertyDefined(propName)) continue;
31
+ const varMatch = SINGLE_VAR_REF.exec(value);
32
+ if (varMatch) {
33
+ const depName = varMatch[1];
34
+ this.addDependency(propName, depName);
35
+ continue;
36
+ }
37
+ if (this.isComplexValue(value)) continue;
38
+ const inferred = inferSyntaxFromValue(value, propName);
39
+ if (!inferred) continue;
40
+ if (!this.validateTokenType(propName, inferred.syntax)) continue;
41
+ this.resolve(propName, inferred.syntax, inferred.initialValue, isPropertyDefined, registerProperty);
42
+ }
43
+ }
44
+ addDependency(propName, depName) {
45
+ if (propName === depName) return;
46
+ this.pendingDeps.set(propName, depName);
47
+ let dependents = this.reverseDeps.get(depName);
48
+ if (!dependents) {
49
+ dependents = [];
50
+ this.reverseDeps.set(depName, dependents);
51
+ }
52
+ if (!dependents.includes(propName)) dependents.push(propName);
53
+ }
54
+ resolve(propName, syntax, initialValue, isPropertyDefined, registerProperty, resolving) {
55
+ if (!resolving) resolving = /* @__PURE__ */ new Set();
56
+ if (resolving.has(propName)) return;
57
+ resolving.add(propName);
58
+ if (!isPropertyDefined(propName)) registerProperty(propName, syntax, initialValue);
59
+ const dependents = this.reverseDeps.get(propName);
60
+ if (dependents) {
61
+ this.reverseDeps.delete(propName);
62
+ for (const dependent of dependents) {
63
+ this.pendingDeps.delete(dependent);
64
+ if (isPropertyDefined(dependent)) continue;
65
+ if (!this.validateTokenType(dependent, syntax)) continue;
66
+ this.resolve(dependent, syntax, initialValue, isPropertyDefined, registerProperty, resolving);
67
+ }
68
+ }
69
+ }
70
+ /**
71
+ * Validate that the inferred type matches the token naming convention.
72
+ * Returns false (and warns) on mismatch.
73
+ */
74
+ validateTokenType(propName, syntax) {
75
+ const isColorProp = propName.endsWith("-color");
76
+ if (isColorProp && syntax !== "<color>") {
77
+ if (isDevEnv()) {
78
+ const tokenName = propName.replace(/^--/, "#").replace(/-color$/, "");
79
+ console.warn(`[Tasty] Color token ${tokenName} has a non-color value. Skipping @property auto-registration.`);
80
+ }
81
+ return false;
82
+ }
83
+ if (!isColorProp && syntax === "<color>") {
84
+ if (isDevEnv()) {
85
+ const tokenName = "$" + propName.replace(/^--/, "");
86
+ console.warn(`[Tasty] Token ${tokenName} has a color value but uses $ prefix instead of #. Use the # prefix for color properties. Skipping @property auto-registration.`);
87
+ }
88
+ return false;
89
+ }
90
+ return true;
91
+ }
92
+ isComplexValue(value) {
93
+ if (value.includes("calc(")) return true;
94
+ const varCount = (value.match(/var\(/g) || []).length;
95
+ if (varCount > 1) return true;
96
+ if (varCount === 1 && !SINGLE_VAR_REF.test(value)) return true;
97
+ return false;
98
+ }
99
+ };
100
+
101
+ //#endregion
102
+ export { PropertyTypeResolver };
103
+ //# sourceMappingURL=property-type-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property-type-resolver.js","names":[],"sources":["../../src/properties/property-type-resolver.ts"],"sourcesContent":["/**\n * PropertyTypeResolver\n *\n * Automatically infers CSS @property types from custom property values.\n * Supports deferred resolution for var() reference chains of arbitrary depth.\n */\n\nimport { isDevEnv } from '../utils/is-dev-env';\n\nimport { inferSyntaxFromValue } from './index';\n\nconst CUSTOM_PROP_DECL = /^\\s*(--[a-z0-9_-]+)\\s*:\\s*(.+?)\\s*$/i;\nconst SINGLE_VAR_REF = /^var\\((--[a-z0-9_-]+)\\)$/i;\n\nexport class PropertyTypeResolver {\n /** propName → the prop it depends on */\n private pendingDeps = new Map<string, string>();\n /** propName → list of props waiting on it */\n private reverseDeps = new Map<string, string[]>();\n\n /**\n * Scan CSS declarations and auto-register @property for custom properties\n * whose types can be inferred from their values.\n */\n scanDeclarations(\n declarations: string,\n isPropertyDefined: (name: string) => boolean,\n registerProperty: (\n name: string,\n syntax: string,\n initialValue: string,\n ) => void,\n ): void {\n const parts = declarations.split(/;+/);\n\n for (const part of parts) {\n if (!part.trim()) continue;\n\n const match = CUSTOM_PROP_DECL.exec(part);\n if (!match) continue;\n\n const propName = match[1];\n const value = match[2].trim();\n\n if (isPropertyDefined(propName)) continue;\n\n // Single var() reference → record dependency for deferred resolution\n const varMatch = SINGLE_VAR_REF.exec(value);\n if (varMatch) {\n const depName = varMatch[1];\n this.addDependency(propName, depName);\n continue;\n }\n\n // Skip complex expressions (calc, multiple var, etc.)\n if (this.isComplexValue(value)) continue;\n\n const inferred = inferSyntaxFromValue(value, propName);\n if (!inferred) continue;\n\n if (!this.validateTokenType(propName, inferred.syntax)) continue;\n\n this.resolve(\n propName,\n inferred.syntax,\n inferred.initialValue,\n isPropertyDefined,\n registerProperty,\n );\n }\n }\n\n private addDependency(propName: string, depName: string): void {\n // Avoid self-references\n if (propName === depName) return;\n\n this.pendingDeps.set(propName, depName);\n\n let dependents = this.reverseDeps.get(depName);\n if (!dependents) {\n dependents = [];\n this.reverseDeps.set(depName, dependents);\n }\n if (!dependents.includes(propName)) {\n dependents.push(propName);\n }\n }\n\n private resolve(\n propName: string,\n syntax: string,\n initialValue: string,\n isPropertyDefined: (name: string) => boolean,\n registerProperty: (\n name: string,\n syntax: string,\n initialValue: string,\n ) => void,\n resolving?: Set<string>,\n ): void {\n // Guard against circular references\n if (!resolving) resolving = new Set();\n if (resolving.has(propName)) return;\n resolving.add(propName);\n\n if (!isPropertyDefined(propName)) {\n registerProperty(propName, syntax, initialValue);\n }\n\n // Propagate to dependents\n const dependents = this.reverseDeps.get(propName);\n if (dependents) {\n this.reverseDeps.delete(propName);\n\n for (const dependent of dependents) {\n this.pendingDeps.delete(dependent);\n\n if (isPropertyDefined(dependent)) continue;\n if (!this.validateTokenType(dependent, syntax)) continue;\n\n this.resolve(\n dependent,\n syntax,\n initialValue,\n isPropertyDefined,\n registerProperty,\n resolving,\n );\n }\n }\n }\n\n /**\n * Validate that the inferred type matches the token naming convention.\n * Returns false (and warns) on mismatch.\n */\n private validateTokenType(propName: string, syntax: string): boolean {\n const isColorProp = propName.endsWith('-color');\n\n if (isColorProp && syntax !== '<color>') {\n if (isDevEnv()) {\n const tokenName = propName.replace(/^--/, '#').replace(/-color$/, '');\n console.warn(\n `[Tasty] Color token ${tokenName} has a non-color value. ` +\n `Skipping @property auto-registration.`,\n );\n }\n return false;\n }\n\n if (!isColorProp && syntax === '<color>') {\n if (isDevEnv()) {\n const tokenName = '$' + propName.replace(/^--/, '');\n console.warn(\n `[Tasty] Token ${tokenName} has a color value but uses $ prefix instead of #. ` +\n `Use the # prefix for color properties. ` +\n `Skipping @property auto-registration.`,\n );\n }\n return false;\n }\n\n return true;\n }\n\n private isComplexValue(value: string): boolean {\n if (value.includes('calc(')) return true;\n // Multiple var() references\n const varCount = (value.match(/var\\(/g) || []).length;\n if (varCount > 1) return true;\n // var() with additional content around it (e.g. \"var(--x) + 1\")\n if (varCount === 1 && !SINGLE_VAR_REF.test(value)) return true;\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AAEvB,IAAa,uBAAb,MAAkC;;CAEhC,AAAQ,8BAAc,IAAI,KAAqB;;CAE/C,AAAQ,8BAAc,IAAI,KAAuB;;;;;CAMjD,iBACE,cACA,mBACA,kBAKM;EACN,MAAM,QAAQ,aAAa,MAAM,KAAK;AAEtC,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,CAAC,KAAK,MAAM,CAAE;GAElB,MAAM,QAAQ,iBAAiB,KAAK,KAAK;AACzC,OAAI,CAAC,MAAO;GAEZ,MAAM,WAAW,MAAM;GACvB,MAAM,QAAQ,MAAM,GAAG,MAAM;AAE7B,OAAI,kBAAkB,SAAS,CAAE;GAGjC,MAAM,WAAW,eAAe,KAAK,MAAM;AAC3C,OAAI,UAAU;IACZ,MAAM,UAAU,SAAS;AACzB,SAAK,cAAc,UAAU,QAAQ;AACrC;;AAIF,OAAI,KAAK,eAAe,MAAM,CAAE;GAEhC,MAAM,WAAW,qBAAqB,OAAO,SAAS;AACtD,OAAI,CAAC,SAAU;AAEf,OAAI,CAAC,KAAK,kBAAkB,UAAU,SAAS,OAAO,CAAE;AAExD,QAAK,Q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U,iIAG5B;;AAEH,UAAO;;AAGT,SAAO;;CAGT,AAAQ,eAAe,OAAwB;AAC7C,MAAI,MAAM,SAAS,QAAQ,CAAE,QAAO;EAEpC,MAAM,YAAY,MAAM,MAAM,SAAS,IAAI,EAAE,EAAE;AAC/C,MAAI,WAAW,EAAG,QAAO;AAEzB,MAAI,aAAa,KAAK,CAAC,eAAe,KAAK,MAAM,CAAE,QAAO;AAC1D,SAAO"}
@@ -200,12 +200,173 @@ function parseColor(val, ignoreError = false) {
200
200
  opacity
201
201
  };
202
202
  }
203
+ /**
204
+ * CSS named color keywords → hex values.
205
+ * Lazy-initialized on first use to avoid up-front cost.
206
+ */
207
+ let _namedColorHex = null;
208
+ function getNamedColorHex() {
209
+ if (_namedColorHex) return _namedColorHex;
210
+ _namedColorHex = new Map([
211
+ ["aliceblue", "#f0f8ff"],
212
+ ["antiquewhite", "#faebd7"],
213
+ ["aqua", "#00ffff"],
214
+ ["aquamarine", "#7fffd4"],
215
+ ["azure", "#f0ffff"],
216
+ ["beige", "#f5f5dc"],
217
+ ["bisque", "#ffe4c4"],
218
+ ["black", "#000000"],
219
+ ["blanchedalmond", "#ffebcd"],
220
+ ["blue", "#0000ff"],
221
+ ["blueviolet", "#8a2be2"],
222
+ ["brown", "#a52a2a"],
223
+ ["burlywood", "#deb887"],
224
+ ["cadetblue", "#5f9ea0"],
225
+ ["chartreuse", "#7fff00"],
226
+ ["chocolate", "#d2691e"],
227
+ ["coral", "#ff7f50"],
228
+ ["cornflowerblue", "#6495ed"],
229
+ ["cornsilk", "#fff8dc"],
230
+ ["crimson", "#dc143c"],
231
+ ["cyan", "#00ffff"],
232
+ ["darkblue", "#00008b"],
233
+ ["darkcyan", "#008b8b"],
234
+ ["darkgoldenrod", "#b8860b"],
235
+ ["darkgray", "#a9a9a9"],
236
+ ["darkgreen", "#006400"],
237
+ ["darkgrey", "#a9a9a9"],
238
+ ["darkkhaki", "#bdb76b"],
239
+ ["darkmagenta", "#8b008b"],
240
+ ["darkolivegreen", "#556b2f"],
241
+ ["darkorange", "#ff8c00"],
242
+ ["darkorchid", "#9932cc"],
243
+ ["darkred", "#8b0000"],
244
+ ["darksalmon", "#e9967a"],
245
+ ["darkseagreen", "#8fbc8f"],
246
+ ["darkslateblue", "#483d8b"],
247
+ ["darkslategray", "#2f4f4f"],
248
+ ["darkslategrey", "#2f4f4f"],
249
+ ["darkturquoise", "#00ced1"],
250
+ ["darkviolet", "#9400d3"],
251
+ ["deeppink", "#ff1493"],
252
+ ["deepskyblue", "#00bfff"],
253
+ ["dimgray", "#696969"],
254
+ ["dimgrey", "#696969"],
255
+ ["dodgerblue", "#1e90ff"],
256
+ ["firebrick", "#b22222"],
257
+ ["floralwhite", "#fffaf0"],
258
+ ["forestgreen", "#228b22"],
259
+ ["fuchsia", "#ff00ff"],
260
+ ["gainsboro", "#dcdcdc"],
261
+ ["ghostwhite", "#f8f8ff"],
262
+ ["gold", "#ffd700"],
263
+ ["goldenrod", "#daa520"],
264
+ ["gray", "#808080"],
265
+ ["green", "#008000"],
266
+ ["greenyellow", "#adff2f"],
267
+ ["grey", "#808080"],
268
+ ["honeydew", "#f0fff0"],
269
+ ["hotpink", "#ff69b4"],
270
+ ["indianred", "#cd5c5c"],
271
+ ["indigo", "#4b0082"],
272
+ ["ivory", "#fffff0"],
273
+ ["khaki", "#f0e68c"],
274
+ ["lavender", "#e6e6fa"],
275
+ ["lavenderblush", "#fff0f5"],
276
+ ["lawngreen", "#7cfc00"],
277
+ ["lemonchiffon", "#fffacd"],
278
+ ["lightblue", "#add8e6"],
279
+ ["lightcoral", "#f08080"],
280
+ ["lightcyan", "#e0ffff"],
281
+ ["lightgoldenrodyellow", "#fafad2"],
282
+ ["lightgray", "#d3d3d3"],
283
+ ["lightgreen", "#90ee90"],
284
+ ["lightgrey", "#d3d3d3"],
285
+ ["lightpink", "#ffb6c1"],
286
+ ["lightsalmon", "#ffa07a"],
287
+ ["lightseagreen", "#20b2aa"],
288
+ ["lightskyblue", "#87cefa"],
289
+ ["lightslategray", "#778899"],
290
+ ["lightslategrey", "#778899"],
291
+ ["lightsteelblue", "#b0c4de"],
292
+ ["lightyellow", "#ffffe0"],
293
+ ["lime", "#00ff00"],
294
+ ["limegreen", "#32cd32"],
295
+ ["linen", "#faf0e6"],
296
+ ["magenta", "#ff00ff"],
297
+ ["maroon", "#800000"],
298
+ ["mediumaquamarine", "#66cdaa"],
299
+ ["mediumblue", "#0000cd"],
300
+ ["mediumorchid", "#ba55d3"],
301
+ ["mediumpurple", "#9370db"],
302
+ ["mediumseagreen", "#3cb371"],
303
+ ["mediumslateblue", "#7b68ee"],
304
+ ["mediumspringgreen", "#00fa9a"],
305
+ ["mediumturquoise", "#48d1cc"],
306
+ ["mediumvioletred", "#c71585"],
307
+ ["midnightblue", "#191970"],
308
+ ["mintcream", "#f5fffa"],
309
+ ["mistyrose", "#ffe4e1"],
310
+ ["moccasin", "#ffe4b5"],
311
+ ["navajowhite", "#ffdead"],
312
+ ["navy", "#000080"],
313
+ ["oldlace", "#fdf5e6"],
314
+ ["olive", "#808000"],
315
+ ["olivedrab", "#6b8e23"],
316
+ ["orange", "#ffa500"],
317
+ ["orangered", "#ff4500"],
318
+ ["orchid", "#da70d6"],
319
+ ["palegoldenrod", "#eee8aa"],
320
+ ["palegreen", "#98fb98"],
321
+ ["paleturquoise", "#afeeee"],
322
+ ["palevioletred", "#db7093"],
323
+ ["papayawhip", "#ffefd5"],
324
+ ["peachpuff", "#ffdab9"],
325
+ ["peru", "#cd853f"],
326
+ ["pink", "#ffc0cb"],
327
+ ["plum", "#dda0dd"],
328
+ ["powderblue", "#b0e0e6"],
329
+ ["purple", "#800080"],
330
+ ["rebeccapurple", "#663399"],
331
+ ["red", "#ff0000"],
332
+ ["rosybrown", "#bc8f8f"],
333
+ ["royalblue", "#4169e1"],
334
+ ["saddlebrown", "#8b4513"],
335
+ ["salmon", "#fa8072"],
336
+ ["sandybrown", "#f4a460"],
337
+ ["seagreen", "#2e8b57"],
338
+ ["seashell", "#fff5ee"],
339
+ ["sienna", "#a0522d"],
340
+ ["silver", "#c0c0c0"],
341
+ ["skyblue", "#87ceeb"],
342
+ ["slateblue", "#6a5acd"],
343
+ ["slategray", "#708090"],
344
+ ["slategrey", "#708090"],
345
+ ["snow", "#fffafa"],
346
+ ["springgreen", "#00ff7f"],
347
+ ["steelblue", "#4682b4"],
348
+ ["tan", "#d2b48c"],
349
+ ["teal", "#008080"],
350
+ ["thistle", "#d8bfd8"],
351
+ ["tomato", "#ff6347"],
352
+ ["turquoise", "#40e0d0"],
353
+ ["violet", "#ee82ee"],
354
+ ["wheat", "#f5deb3"],
355
+ ["white", "#ffffff"],
356
+ ["whitesmoke", "#f5f5f5"],
357
+ ["yellow", "#ffff00"],
358
+ ["yellowgreen", "#9acd32"]
359
+ ]);
360
+ return _namedColorHex;
361
+ }
203
362
  function strToRgb(color, _ignoreAlpha = false) {
204
363
  if (!color) return void 0;
205
364
  if (color.startsWith("rgb")) return color;
206
365
  if (color.startsWith("#")) return hexToRgb(color);
207
366
  if (color.startsWith("okhsl(")) return okhslToRgb(color);
208
367
  if (color.startsWith("hsl")) return hslToRgb(color);
368
+ const namedHex = getNamedColorHex().get(color.toLowerCase());
369
+ if (namedHex) return hexToRgb(namedHex);
209
370
  return null;
210
371
  }
211
372
  /**