@salesforce-ux/eslint-plugin-slds 1.0.7 → 1.0.9-internal

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.
Files changed (115) hide show
  1. package/README.md +62 -0
  2. package/build/config/rule-messages.d.ts +2 -0
  3. package/build/config/rule-messages.js +197 -0
  4. package/build/config/rule-messages.js.map +7 -0
  5. package/build/index.js +40 -2332
  6. package/build/index.js.map +4 -4
  7. package/build/rules/enforce-bem-usage.js +18 -234
  8. package/build/rules/enforce-bem-usage.js.map +4 -4
  9. package/build/rules/modal-close-button-issue.js +11 -183
  10. package/build/rules/modal-close-button-issue.js.map +4 -4
  11. package/build/rules/no-deprecated-classes-slds2.js +6 -178
  12. package/build/rules/no-deprecated-classes-slds2.js.map +4 -4
  13. package/build/rules/v9/enforce-bem-usage.js +3 -163
  14. package/build/rules/v9/enforce-bem-usage.js.map +4 -4
  15. package/build/rules/v9/enforce-component-hook-naming-convention.js +3 -163
  16. package/build/rules/v9/enforce-component-hook-naming-convention.js.map +4 -4
  17. package/build/rules/v9/enforce-sds-to-slds-hooks.js +3 -163
  18. package/build/rules/v9/enforce-sds-to-slds-hooks.js.map +4 -4
  19. package/build/rules/v9/lwc-token-to-slds-hook.js +6 -264
  20. package/build/rules/v9/lwc-token-to-slds-hook.js.map +4 -4
  21. package/build/rules/v9/no-deprecated-slds-classes.js +3 -163
  22. package/build/rules/v9/no-deprecated-slds-classes.js.map +4 -4
  23. package/build/rules/v9/no-deprecated-tokens-slds1.js +30 -169
  24. package/build/rules/v9/no-deprecated-tokens-slds1.js.map +4 -4
  25. package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js +29 -253
  26. package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js.map +4 -4
  27. package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js +31 -289
  28. package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js.map +4 -4
  29. package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js +23 -286
  30. package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js.map +4 -4
  31. package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js +24 -316
  32. package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js.map +4 -4
  33. package/build/rules/v9/no-hardcoded-values/handlers/index.js +8 -799
  34. package/build/rules/v9/no-hardcoded-values/handlers/index.js.map +4 -4
  35. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js +5 -1090
  36. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +4 -4
  37. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +5 -1090
  38. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +4 -4
  39. package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js +31 -882
  40. package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js.map +4 -4
  41. package/build/rules/v9/no-hardcoded-values/ruleOptionsSchema.d.ts +40 -0
  42. package/build/rules/v9/no-hardcoded-values/ruleOptionsSchema.js +63 -0
  43. package/build/rules/v9/no-hardcoded-values/ruleOptionsSchema.js.map +7 -0
  44. package/build/rules/v9/no-slds-class-overrides.js +3 -163
  45. package/build/rules/v9/no-slds-class-overrides.js.map +4 -4
  46. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js +5 -254
  47. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +4 -4
  48. package/build/rules/v9/no-slds-private-var.js +1 -161
  49. package/build/rules/v9/no-slds-private-var.js.map +4 -4
  50. package/build/rules/v9/no-slds-var-without-fallback.js +5 -257
  51. package/build/rules/v9/no-slds-var-without-fallback.js.map +4 -4
  52. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js +3 -163
  53. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js.map +4 -4
  54. package/build/rules/v9/no-unsupported-hooks-slds2.js +3 -163
  55. package/build/rules/v9/no-unsupported-hooks-slds2.js.map +4 -4
  56. package/build/rules/v9/reduce-annotations.js +1 -161
  57. package/build/rules/v9/reduce-annotations.js.map +4 -4
  58. package/build/types/index.d.ts +57 -0
  59. package/build/types/index.js.map +1 -1
  60. package/build/{src/utils → utils}/boxShadowValueParser.d.ts +1 -1
  61. package/build/utils/boxShadowValueParser.js +63 -93
  62. package/build/utils/boxShadowValueParser.js.map +4 -4
  63. package/build/utils/color-lib-utils.d.ts +25 -0
  64. package/build/utils/color-lib-utils.js +28 -79
  65. package/build/utils/color-lib-utils.js.map +3 -3
  66. package/build/{src/utils → utils}/css-utils.d.ts +7 -0
  67. package/build/utils/css-utils.js +10 -71
  68. package/build/utils/css-utils.js.map +4 -4
  69. package/build/utils/custom-mapping-utils.d.ts +9 -0
  70. package/build/utils/custom-mapping-utils.js +62 -0
  71. package/build/utils/custom-mapping-utils.js.map +7 -0
  72. package/build/{src/utils → utils}/hardcoded-shared-utils.d.ts +1 -0
  73. package/build/utils/hardcoded-shared-utils.js +46 -98
  74. package/build/utils/hardcoded-shared-utils.js.map +4 -4
  75. package/build/{src/utils → utils}/property-matcher.d.ts +3 -1
  76. package/build/utils/property-matcher.js +22 -8
  77. package/build/utils/property-matcher.js.map +2 -2
  78. package/build/utils/styling-hook-utils.js +16 -39
  79. package/build/utils/styling-hook-utils.js.map +3 -3
  80. package/build/{src/utils → utils}/value-utils.d.ts +2 -2
  81. package/build/utils/value-utils.js +8 -8
  82. package/build/utils/value-utils.js.map +2 -2
  83. package/package.json +6 -11
  84. package/build/src/types/index.d.ts +0 -26
  85. package/build/src/utils/color-lib-utils.d.ts +0 -18
  86. package/src/config/rule-messages.yml +0 -143
  87. /package/build/{src/index.d.ts → index.d.ts} +0 -0
  88. /package/build/{src/rules → rules}/enforce-bem-usage.d.ts +0 -0
  89. /package/build/{src/rules → rules}/modal-close-button-issue.d.ts +0 -0
  90. /package/build/{src/rules → rules}/no-deprecated-classes-slds2.d.ts +0 -0
  91. /package/build/{src/rules → rules}/v9/enforce-bem-usage.d.ts +0 -0
  92. /package/build/{src/rules → rules}/v9/enforce-component-hook-naming-convention.d.ts +0 -0
  93. /package/build/{src/rules → rules}/v9/enforce-sds-to-slds-hooks.d.ts +0 -0
  94. /package/build/{src/rules → rules}/v9/lwc-token-to-slds-hook.d.ts +0 -0
  95. /package/build/{src/rules → rules}/v9/no-deprecated-slds-classes.d.ts +0 -0
  96. /package/build/{src/rules → rules}/v9/no-deprecated-tokens-slds1.d.ts +0 -0
  97. /package/build/{src/rules → rules}/v9/no-hardcoded-values/handlers/boxShadowHandler.d.ts +0 -0
  98. /package/build/{src/rules → rules}/v9/no-hardcoded-values/handlers/colorHandler.d.ts +0 -0
  99. /package/build/{src/rules → rules}/v9/no-hardcoded-values/handlers/densityHandler.d.ts +0 -0
  100. /package/build/{src/rules → rules}/v9/no-hardcoded-values/handlers/fontHandler.d.ts +0 -0
  101. /package/build/{src/rules → rules}/v9/no-hardcoded-values/handlers/index.d.ts +0 -0
  102. /package/build/{src/rules → rules}/v9/no-hardcoded-values/no-hardcoded-values-slds1.d.ts +0 -0
  103. /package/build/{src/rules → rules}/v9/no-hardcoded-values/no-hardcoded-values-slds2.d.ts +0 -0
  104. /package/build/{src/rules → rules}/v9/no-hardcoded-values/noHardcodedValueRule.d.ts +0 -0
  105. /package/build/{src/rules → rules}/v9/no-slds-class-overrides.d.ts +0 -0
  106. /package/build/{src/rules → rules}/v9/no-slds-namespace-for-custom-hooks.d.ts +0 -0
  107. /package/build/{src/rules → rules}/v9/no-slds-private-var.d.ts +0 -0
  108. /package/build/{src/rules → rules}/v9/no-slds-var-without-fallback.d.ts +0 -0
  109. /package/build/{src/rules → rules}/v9/no-sldshook-fallback-for-lwctoken.d.ts +0 -0
  110. /package/build/{src/rules → rules}/v9/no-unsupported-hooks-slds2.d.ts +0 -0
  111. /package/build/{src/rules → rules}/v9/reduce-annotations.d.ts +0 -0
  112. /package/build/{src/utils → utils}/css-functions.d.ts +0 -0
  113. /package/build/{src/utils → utils}/node.d.ts +0 -0
  114. /package/build/{src/utils → utils}/rule-utils.d.ts +0 -0
  115. /package/build/{src/utils → utils}/styling-hook-utils.d.ts +0 -0
@@ -0,0 +1,25 @@
1
+ import { ValueToStylingHooksMapping } from '@salesforce-ux/sds-metadata';
2
+ /**
3
+ * Convert any valid CSS color (named, hex, rgb(a), hsl(a), etc.) to hex.
4
+ * Returns null if the value is not a valid color.
5
+ */
6
+ declare const convertToHex: (color: string) => string | null;
7
+ /**
8
+ * Given an input color and the metadata mapping of supported colors to hooks,
9
+ * suggest up to 5 styling hook names ordered by:
10
+ * 1) Category priority: semantic -> system -> palette
11
+ * 2) Perceptual distance (Delta E)
12
+ * Also prioritizes exact color matches (distance 0).
13
+ */
14
+ declare const findClosestColorHook: (color: string, supportedColors: ValueToStylingHooksMapping, cssProperty: string) => string[];
15
+ /**
16
+ * Check if a value is any valid CSS color string (delegates to chroma-js).
17
+ */
18
+ declare const isValidColor: (val: string) => boolean;
19
+ /**
20
+ * Extract a color string from a CSS AST node produced by @eslint/css-tree.
21
+ * Supports Hash (#rrggbb), Identifier (named colors), and color Function nodes.
22
+ * Returns null if the extracted value is not a valid color.
23
+ */
24
+ declare const extractColorValue: (node: any) => string | null;
25
+ export { findClosestColorHook, convertToHex, isValidColor, extractColorValue };
@@ -32,50 +32,13 @@ __export(color_lib_utils_exports, {
32
32
  convertToHex: () => convertToHex,
33
33
  extractColorValue: () => extractColorValue,
34
34
  findClosestColorHook: () => findClosestColorHook,
35
- isHardCodedColor: () => isHardCodedColor,
36
- isHexCode: () => isHexCode,
37
35
  isValidColor: () => isValidColor
38
36
  });
39
37
  module.exports = __toCommonJS(color_lib_utils_exports);
40
38
  var import_chroma_js = __toESM(require("chroma-js"));
41
39
  var import_css_tree = require("@eslint/css-tree");
42
-
43
- // src/utils/css-functions.ts
44
- var CSS_FUNCTIONS = [
45
- "attr",
46
- "calc",
47
- "color-mix",
48
- "conic-gradient",
49
- "counter",
50
- "cubic-bezier",
51
- "linear-gradient",
52
- "max",
53
- "min",
54
- "radial-gradient",
55
- "repeating-conic-gradient",
56
- "repeating-linear-gradient",
57
- "repeating-radial-gradient",
58
- "var"
59
- ];
60
- var CSS_MATH_FUNCTIONS = ["calc", "min", "max"];
61
- var RGB_COLOR_FUNCTIONS = ["rgb", "rgba", "hsl", "hsla"];
62
- var cssFunctionsRegex = new RegExp(`(?:${CSS_FUNCTIONS.join("|")})`);
63
- var cssFunctionsExactRegex = new RegExp(`^(?:${CSS_FUNCTIONS.join("|")})$`);
64
- var cssMathFunctionsRegex = new RegExp(`^(?:${CSS_MATH_FUNCTIONS.join("|")})$`);
65
- function isCssColorFunction(value) {
66
- return RGB_COLOR_FUNCTIONS.includes(value);
67
- }
68
-
69
- // src/utils/color-lib-utils.ts
70
- var LAB_THRESHOLD = 25;
71
- var isHardCodedColor = (color) => {
72
- const colorRegex = /\b(rgb|rgba)\((\s*\d{1,3}\s*,\s*){2,3}\s*(0|1|0?\.\d+)\s*\)|#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\b|[a-zA-Z]+/g;
73
- return colorRegex.test(color);
74
- };
75
- var isHexCode = (color) => {
76
- const hexPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;
77
- return hexPattern.test(color);
78
- };
40
+ var import_css_functions = require("./css-functions");
41
+ var DELTAE_THRESHOLD = 10;
79
42
  var convertToHex = (color) => {
80
43
  try {
81
44
  return (0, import_chroma_js.default)(color).hex();
@@ -83,52 +46,40 @@ var convertToHex = (color) => {
83
46
  return null;
84
47
  }
85
48
  };
49
+ var isHookPropertyMatch = (hook, cssProperty) => {
50
+ return hook.properties.includes(cssProperty) || hook.properties.includes("*");
51
+ };
52
+ function getOrderByCssProp(cssProperty) {
53
+ if (cssProperty === "color" || cssProperty === "fill") {
54
+ return ["surface", "theme", "feedback", "reference"];
55
+ } else if (cssProperty.match(/background/)) {
56
+ return ["surface", "surface-inverse", "theme", "feedback", "reference"];
57
+ } else if (cssProperty.match(/border/) || cssProperty.match(/outline/) || cssProperty.match(/stroke/)) {
58
+ return ["borders", "borders-inverse", "feedback", "theme", "reference"];
59
+ }
60
+ return ["surface", "surface-inverse", "borders", "borders-inverse", "theme", "feedback", "reference"];
61
+ }
86
62
  var findClosestColorHook = (color, supportedColors, cssProperty) => {
87
- const returnStylingHooks = [];
88
- const closestHooksWithSameProperty = [];
89
- const closestHooksWithoutSameProperty = [];
90
- const closestHooksWithAllProperty = [];
91
- const labColor = (0, import_chroma_js.default)(color).lab();
63
+ const closestHooks = [];
92
64
  Object.entries(supportedColors).forEach(([sldsValue, data]) => {
93
- if (sldsValue && isHexCode(sldsValue)) {
65
+ if (sldsValue && isValidColor(sldsValue)) {
94
66
  const hooks = data;
95
67
  hooks.forEach((hook) => {
96
- const labSupportedColor = (0, import_chroma_js.default)(sldsValue).lab();
97
- const distance = JSON.stringify(labColor) === JSON.stringify(labSupportedColor) ? 0 : import_chroma_js.default.distance(import_chroma_js.default.lab(...labColor), import_chroma_js.default.lab(...labSupportedColor), "lab");
98
- if (hook.properties.includes(cssProperty)) {
99
- if (distance <= LAB_THRESHOLD) {
100
- closestHooksWithSameProperty.push({ name: hook.name, distance });
101
- }
102
- } else if (hook.properties.includes("*")) {
103
- if (distance <= LAB_THRESHOLD) {
104
- closestHooksWithAllProperty.push({ name: hook.name, distance });
105
- }
106
- } else {
107
- if (distance <= LAB_THRESHOLD) {
108
- closestHooksWithoutSameProperty.push({ name: hook.name, distance });
109
- }
68
+ const distance = sldsValue.toLowerCase() === color.toLowerCase() ? 0 : import_chroma_js.default.deltaE(sldsValue, color);
69
+ if (isHookPropertyMatch(hook, cssProperty) && distance <= DELTAE_THRESHOLD) {
70
+ closestHooks.push({ distance, group: hook.group, name: hook.name });
110
71
  }
111
72
  });
112
73
  }
113
74
  });
114
- const closesthookGroups = [
115
- { hooks: closestHooksWithSameProperty, distance: 0 },
116
- { hooks: closestHooksWithAllProperty, distance: 0 },
117
- { hooks: closestHooksWithSameProperty, distance: Infinity },
118
- // For hooks with distance > 0
119
- { hooks: closestHooksWithAllProperty, distance: Infinity },
120
- { hooks: closestHooksWithoutSameProperty, distance: Infinity }
121
- ];
122
- for (const group of closesthookGroups) {
123
- const filteredHooks = group.hooks.filter(
124
- (h) => group.distance === 0 ? h.distance === 0 : h.distance > 0
125
- );
126
- if (returnStylingHooks.length < 1 && filteredHooks.length > 0) {
127
- filteredHooks.sort((a, b) => a.distance - b.distance);
128
- returnStylingHooks.push(...filteredHooks.slice(0, 5).map((h) => h.name));
75
+ const hooksByGroupMap = closestHooks.sort((a, b) => a.distance - b.distance).reduce((acc, hook) => {
76
+ if (!acc[hook.group]) {
77
+ acc[hook.group] = [];
129
78
  }
130
- }
131
- return Array.from(new Set(returnStylingHooks));
79
+ acc[hook.group].push(hook.name);
80
+ return acc;
81
+ }, {});
82
+ return getOrderByCssProp(cssProperty).map((group) => hooksByGroupMap[group] || []).flat().slice(0, 5);
132
83
  };
133
84
  var isValidColor = (val) => import_chroma_js.default.valid(val);
134
85
  var extractColorValue = (node) => {
@@ -141,7 +92,7 @@ var extractColorValue = (node) => {
141
92
  colorValue = node.name;
142
93
  break;
143
94
  case "Function":
144
- if (isCssColorFunction(node.name)) {
95
+ if ((0, import_css_functions.isCssColorFunction)(node.name)) {
145
96
  colorValue = (0, import_css_tree.generate)(node);
146
97
  }
147
98
  break;
@@ -153,8 +104,6 @@ var extractColorValue = (node) => {
153
104
  convertToHex,
154
105
  extractColorValue,
155
106
  findClosestColorHook,
156
- isHardCodedColor,
157
- isHexCode,
158
107
  isValidColor
159
108
  });
160
109
  //# sourceMappingURL=color-lib-utils.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/utils/color-lib-utils.ts", "../../src/utils/css-functions.ts"],
4
- "sourcesContent": ["//stylelint-sds/packages/stylelint-plugin-slds/src/utils/color-lib-utils.ts\nimport { ValueToStylingHooksMapping, ValueToStylingHookEntry } from '@salesforce-ux/sds-metadata';\nimport chroma from 'chroma-js';\nimport { generate } from '@eslint/css-tree';\nimport { isCssColorFunction } from './css-functions';\n\nconst LAB_THRESHOLD = 25; // Adjust this to set how strict the matching should be\n\nconst isHardCodedColor = (color: string): boolean => {\n const colorRegex =\n /\\b(rgb|rgba)\\((\\s*\\d{1,3}\\s*,\\s*){2,3}\\s*(0|1|0?\\.\\d+)\\s*\\)|#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\\b|[a-zA-Z]+/g;\n return colorRegex.test(color);\n};\n\nconst isHexCode = (color: string): boolean => {\n const hexPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/; // Pattern for #RGB or #RRGGBB\n return hexPattern.test(color);\n};\n\n// Convert a named color or hex code into a hex format using chroma-js\nconst convertToHex = (color: string): string | null => {\n try {\n // Try converting the color using chroma-js, which handles both named and hex colors\n return chroma(color).hex();\n } catch (e) {\n // If chroma can't process the color, it's likely invalid\n return null;\n }\n};\n\n// Find the closest color hook using LAB distance\nconst findClosestColorHook = (\n color: string,\n supportedColors:ValueToStylingHooksMapping,\n cssProperty: string\n): string[] => {\n const returnStylingHooks: string[] = [];\n const closestHooksWithSameProperty: { name: string; distance: number }[] = [];\n const closestHooksWithoutSameProperty: { name: string; distance: number }[] =\n [];\n const closestHooksWithAllProperty: { name: string; distance: number }[] =\n [];\n const labColor = chroma(color).lab();\n\n Object.entries(supportedColors).forEach(([sldsValue, data]) => {\n if (sldsValue && isHexCode(sldsValue)) {\n const hooks = data as ValueToStylingHookEntry[]; // Get the hooks for the sldsValue\n\n hooks.forEach((hook) => {\n const labSupportedColor = chroma(sldsValue).lab();\n const distance = (JSON.stringify(labColor) === JSON.stringify(labSupportedColor)) ? 0\n : chroma.distance(chroma.lab(...labColor), chroma.lab(...labSupportedColor), \"lab\");\n // Check if the hook has the same property\n if (hook.properties.includes(cssProperty)) {\n // Add to same property hooks if within threshold\n if (distance <= LAB_THRESHOLD) {\n closestHooksWithSameProperty.push({ name: hook.name, distance });\n }\n } \n // Check for the universal selector\n else if ( hook.properties.includes(\"*\") ){\n // Add to same property hooks if within threshold\n if (distance <= LAB_THRESHOLD) {\n closestHooksWithAllProperty.push({ name: hook.name, distance });\n }\n }\n else {\n // Add to different property hooks if within threshold\n if (distance <= LAB_THRESHOLD) {\n closestHooksWithoutSameProperty.push({ name: hook.name, distance });\n }\n }\n });\n }\n });\n\n// Group hooks by their priority\nconst closesthookGroups = [\n { hooks: closestHooksWithSameProperty, distance: 0 },\n { hooks: closestHooksWithAllProperty, distance: 0 },\n { hooks: closestHooksWithSameProperty, distance: Infinity }, // For hooks with distance > 0\n { hooks: closestHooksWithAllProperty, distance: Infinity },\n { hooks: closestHooksWithoutSameProperty, distance: Infinity },\n];\n\nfor (const group of closesthookGroups) {\n // Filter hooks based on the distance condition\n const filteredHooks = group.hooks.filter(h => \n group.distance === 0 ? h.distance === 0 : h.distance > 0\n );\n\n if (returnStylingHooks.length < 1 && filteredHooks.length > 0) {\n filteredHooks.sort((a, b) => a.distance - b.distance);\n returnStylingHooks.push(...filteredHooks.slice(0, 5).map((h) => h.name));\n }\n}\n\n\n return Array.from(new Set(returnStylingHooks));\n};\n\n/**\n * This method is usefull to identify all possible css color values.\n * - names colors\n * - 6,8 digit hex\n * - rgb and rgba\n * - hsl and hsla\n */\nconst isValidColor = (val:string):boolean => chroma.valid(val);\n\n/**\n * Extract color value from CSS AST node\n */\nconst extractColorValue = (node: any): string | null => {\n let colorValue: string | null = null;\n \n switch (node.type) {\n case 'Hash':\n colorValue = `#${node.value}`;\n break;\n case 'Identifier':\n colorValue = node.name;\n break;\n case 'Function':\n // Only extract color functions\n if (isCssColorFunction(node.name)) {\n colorValue = generate(node);\n }\n break;\n }\n \n return colorValue && isValidColor(colorValue) ? colorValue : null;\n};\n\nexport { findClosestColorHook, convertToHex, isHexCode, isHardCodedColor, isValidColor, extractColorValue };\n", "//stylelint-sds/packages/stylelint-plugin-slds/src/utils/css-functions.ts\n/**\n * Complete list of CSS functions that should be preserved/recognized\n */\nconst CSS_FUNCTIONS = [\n 'attr',\n 'calc',\n 'color-mix',\n 'conic-gradient',\n 'counter',\n 'cubic-bezier',\n 'linear-gradient',\n 'max',\n 'min',\n 'radial-gradient',\n 'repeating-conic-gradient',\n 'repeating-linear-gradient',\n 'repeating-radial-gradient',\n 'var'\n ];\n \n \n const CSS_MATH_FUNCTIONS = ['calc', 'min', 'max'];\n \n \n const RGB_COLOR_FUNCTIONS = ['rgb', 'rgba', 'hsl', 'hsla'];\n \n /**\n * Regex for matching any CSS function (for general detection)\n * Matches function names within other text\n */\n const cssFunctionsRegex = new RegExp(`(?:${CSS_FUNCTIONS.join('|')})`);\n \n \n const cssFunctionsExactRegex = new RegExp(`^(?:${CSS_FUNCTIONS.join('|')})$`);\n \n \n const cssMathFunctionsRegex = new RegExp(`^(?:${CSS_MATH_FUNCTIONS.join('|')})$`);\n \n export function containsCssFunction(value: string): boolean {\n return cssFunctionsRegex.test(value);\n }\n \n /**\n * Check if a value is exactly a CSS function name\n */\n export function isCssFunction(value: string): boolean {\n return cssFunctionsExactRegex.test(value);\n }\n \n export function isCssMathFunction(value: string): boolean {\n return cssMathFunctionsRegex.test(value);\n }\n \n export function isCssColorFunction(value: string): boolean {\n return RGB_COLOR_FUNCTIONS.includes(value);\n }"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAAmB;AACnB,sBAAyB;;;ACCzB,IAAM,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGA,IAAM,qBAAqB,CAAC,QAAQ,OAAO,KAAK;AAGhD,IAAM,sBAAsB,CAAC,OAAO,QAAQ,OAAO,MAAM;AAMzD,IAAM,oBAAoB,IAAI,OAAO,MAAM,cAAc,KAAK,GAAG,C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AK,KAAK;AAC3B;AAAA,IACF,KAAK;AACH,mBAAa,KAAK;AAClB;AAAA,IACF,KAAK;AAEH,UAAI,mBAAmB,KAAK,IAAI,GAAG;AACjC,yBAAa,0BAAS,IAAI;AAAA,MAC5B;AACA;AAAA,EACJ;AAEA,SAAO,cAAc,aAAa,UAAU,IAAI,aAAa;AAC/D;",
3
+ "sources": ["../../src/utils/color-lib-utils.ts"],
4
+ "sourcesContent": ["import { ValueToStylingHooksMapping, ValueToStylingHookEntry } from '@salesforce-ux/sds-metadata/next';\nimport chroma from 'chroma-js';\nimport { generate } from '@eslint/css-tree';\nimport { isCssColorFunction } from './css-functions';\n\n/**\n * Perceptual color difference threshold (Delta E, CIEDE2000 via chroma.deltaE).\n * Lower values are stricter matches. Used to decide which hooks are \"close enough\".\n */\nconst DELTAE_THRESHOLD = 10;\n\n/**\n * Convert any valid CSS color (named, hex, rgb(a), hsl(a), etc.) to hex.\n * Returns null if the value is not a valid color.\n */\nconst convertToHex = (color: string): string | null => {\n try {\n // Try converting the color using chroma-js, which handles both named and hex colors\n return chroma(color).hex();\n } catch (e) {\n // If chroma can't process the color, it's likely invalid\n return null;\n }\n};\n\nconst isHookPropertyMatch = (hook: ValueToStylingHookEntry, cssProperty: string): boolean => {\n return hook.properties.includes(cssProperty) || hook.properties.includes(\"*\");\n}\n\nfunction getOrderByCssProp(cssProperty: string): string[] {\n if(cssProperty === 'color' || cssProperty === 'fill') {\n return [\"surface\", \"theme\", \"feedback\", \"reference\"];\n } else if(cssProperty.match(/background/)){\n return [\"surface\", \"surface-inverse\", \"theme\", \"feedback\", \"reference\"];\n } else if(cssProperty.match(/border/) || cssProperty.match(/outline/) || cssProperty.match(/stroke/)) {\n return [\"borders\", \"borders-inverse\", \"feedback\", \"theme\", \"reference\"];\n }\n return [\"surface\", \"surface-inverse\", \"borders\", \"borders-inverse\", \"theme\", \"feedback\", \"reference\"];\n}\n\n\n/**\n * Given an input color and the metadata mapping of supported colors to hooks,\n * suggest up to 5 styling hook names ordered by:\n * 1) Category priority: semantic -> system -> palette\n * 2) Perceptual distance (Delta E)\n * Also prioritizes exact color matches (distance 0).\n */\nconst findClosestColorHook = (\n color: string,\n supportedColors:ValueToStylingHooksMapping,\n cssProperty: string\n): string[] => {\n const closestHooks: Array<{distance: number, group: string, name: string}> = [];\n Object.entries(supportedColors).forEach(([sldsValue, data]) => {\n if (sldsValue && isValidColor(sldsValue)) {\n const hooks = data as ValueToStylingHookEntry[]; // Get the hooks for the sldsValue\n\n hooks.forEach((hook) => {\n // Exact match shortcut to avoid floating rounding noise\n const distance = (sldsValue.toLowerCase() === color.toLowerCase())\n ? 0\n : chroma.deltaE(sldsValue, color);\n \n // Check if the hook has the same property or universal selector\n if (isHookPropertyMatch(hook, cssProperty) && distance <= DELTAE_THRESHOLD) {\n // Add to same property hooks if within threshold\n closestHooks.push({ distance, group: hook.group, name: hook.name });\n }\n });\n }\n });\n\n const hooksByGroupMap:Record<string, string[]> = closestHooks.sort((a, b) => a.distance - b.distance).reduce((acc, hook) => {\n if (!acc[hook.group]) {\n acc[hook.group] = [];\n }\n acc[hook.group].push(hook.name);\n return acc;\n }, {});\n\n return getOrderByCssProp(cssProperty)\n .map(group => hooksByGroupMap[group]||[])\n .flat().slice(0, 5);\n};\n\n/**\n * Check if a value is any valid CSS color string (delegates to chroma-js).\n */\nconst isValidColor = (val:string):boolean => chroma.valid(val);\n\n/**\n * Extract a color string from a CSS AST node produced by @eslint/css-tree.\n * Supports Hash (#rrggbb), Identifier (named colors), and color Function nodes.\n * Returns null if the extracted value is not a valid color.\n */\nconst extractColorValue = (node: any): string | null => {\n let colorValue: string | null = null;\n \n switch (node.type) {\n case 'Hash':\n colorValue = `#${node.value}`;\n break;\n case 'Identifier':\n colorValue = node.name;\n break;\n case 'Function':\n // Only extract color functions\n if (isCssColorFunction(node.name)) {\n colorValue = generate(node);\n }\n break;\n }\n \n return colorValue && isValidColor(colorValue) ? colorValue : null;\n};\n\nexport { findClosestColorHook, convertToHex,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AAY,kBAAkB;AAE1E,uBAAa,KAAK,EAAE,UAAU,OAAO,KAAK,OAAO,MAAM,KAAK,KAAK,CAAC;AAAA,QACpE;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,QAAM,kBAA2C,aAAa,KAAK,CAAC,GAAG,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,KAAK,SAAS;AAC1H,QAAI,CAAC,IAAI,KAAK,KAAK,GAAG;AACpB,UAAI,KAAK,KAAK,IAAI,CAAC;AAAA,IACrB;AACA,QAAI,KAAK,KAAK,EAAE,KAAK,KAAK,IAAI;AAC9B,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO,kBAAkB,WAAW,EACjC,IAAI,WAAS,gBAAgB,KAAK,KAAG,CAAC,CAAC,EACvC,KAAK,EAAE,MAAM,GAAG,CAAC;AACtB;AAKA,IAAM,eAAe,CAAC,QAAuB,iBAAAA,QAAO,MAAM,GAAG;AAO7D,IAAM,oBAAoB,CAAC,SAA6B;AACtD,MAAI,aAA4B;AAEhC,UAAQ,KAAK,MAAM;AAAA,IACjB,KAAK;AACH,mBAAa,IAAI,KAAK,KAAK;AAC3B;AAAA,IACF,KAAK;AACH,mBAAa,KAAK;AAClB;AAAA,IACF,KAAK;AAEH,cAAI,yCAAmB,KAAK,IAAI,GAAG;AACjC,yBAAa,0BAAS,IAAI;AAAA,MAC5B;AACA;AAAA,EACJ;AAEA,SAAO,cAAc,aAAa,UAAU,IAAI,aAAa;AAC/D;",
6
6
  "names": ["chroma"]
7
7
  }
@@ -13,6 +13,13 @@ export interface CssVariableInfo {
13
13
  name: string;
14
14
  hasFallback: boolean;
15
15
  }
16
+ /**
17
+ * Get the CSS variable token from a var() function node
18
+ * Extracts the custom property name from var(--custom-prop) -> "--custom-prop"
19
+ * @param node - CSS tree AST node (Function node expected)
20
+ * @returns The custom property name (e.g., "--slds-g-color-brand-base-15") or empty string
21
+ */
22
+ export declare function getVarToken(node: any): string;
16
23
  /**
17
24
  * Specialized CSS variable traversal for SLDS variables
18
25
  * Finds var(--slds-*) functions and reports their fallback status
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/utils/css-utils.ts
@@ -33,67 +23,11 @@ __export(css_utils_exports, {
33
23
  forEachNamespacedVariable: () => forEachNamespacedVariable,
34
24
  forEachSldsVariable: () => forEachSldsVariable,
35
25
  formatSuggestionHooks: () => formatSuggestionHooks,
26
+ getVarToken: () => getVarToken,
36
27
  isTargetProperty: () => isTargetProperty
37
28
  });
38
29
  module.exports = __toCommonJS(css_utils_exports);
39
-
40
- // src/utils/hardcoded-shared-utils.ts
41
- var import_css_tree2 = require("@eslint/css-tree");
42
-
43
- // src/utils/color-lib-utils.ts
44
- var import_chroma_js = __toESM(require("chroma-js"));
45
- var import_css_tree = require("@eslint/css-tree");
46
-
47
- // src/utils/css-functions.ts
48
- var CSS_FUNCTIONS = [
49
- "attr",
50
- "calc",
51
- "color-mix",
52
- "conic-gradient",
53
- "counter",
54
- "cubic-bezier",
55
- "linear-gradient",
56
- "max",
57
- "min",
58
- "radial-gradient",
59
- "repeating-conic-gradient",
60
- "repeating-linear-gradient",
61
- "repeating-radial-gradient",
62
- "var"
63
- ];
64
- var CSS_MATH_FUNCTIONS = ["calc", "min", "max"];
65
- var cssFunctionsRegex = new RegExp(`(?:${CSS_FUNCTIONS.join("|")})`);
66
- var cssFunctionsExactRegex = new RegExp(`^(?:${CSS_FUNCTIONS.join("|")})$`);
67
- var cssMathFunctionsRegex = new RegExp(`^(?:${CSS_MATH_FUNCTIONS.join("|")})$`);
68
-
69
- // src/utils/hardcoded-shared-utils.ts
70
- function forEachValue(valueText, extractValue, shouldSkipNode, callback) {
71
- if (!valueText || typeof valueText !== "string") {
72
- return;
73
- }
74
- try {
75
- const ast = (0, import_css_tree2.parse)(valueText, { context: "value", positions: true });
76
- (0, import_css_tree2.walk)(ast, {
77
- enter(node) {
78
- if (shouldSkipNode(node)) {
79
- return this.skip;
80
- }
81
- const value = extractValue(node);
82
- if (value !== null) {
83
- const positionInfo = {
84
- start: node.loc?.start,
85
- end: node.loc?.end
86
- };
87
- callback(value, positionInfo);
88
- }
89
- }
90
- });
91
- } catch (error) {
92
- return;
93
- }
94
- }
95
-
96
- // src/utils/css-utils.ts
30
+ var import_hardcoded_shared_utils = require("./hardcoded-shared-utils");
97
31
  function isTargetProperty(property, propertyTargets = []) {
98
32
  if (typeof property !== "string") return false;
99
33
  return property.startsWith("--sds-") || property.startsWith("--slds-") || property.startsWith("--lwc-") || propertyTargets.length === 0 || propertyTargets.includes(property);
@@ -119,6 +53,10 @@ function extractCssVariable(node, filter) {
119
53
  }
120
54
  return filter(variableName, childrenArray);
121
55
  }
56
+ function getVarToken(node) {
57
+ const result = extractCssVariable(node, (variableName) => variableName);
58
+ return result || "";
59
+ }
122
60
  function forEachSldsVariable(valueText, callback) {
123
61
  const extractor = (node) => extractCssVariable(node, (variableName, childrenArray) => {
124
62
  if (!variableName.startsWith("--slds-")) {
@@ -129,7 +67,7 @@ function forEachSldsVariable(valueText, callback) {
129
67
  );
130
68
  return { name: variableName, hasFallback };
131
69
  });
132
- forEachValue(valueText, extractor, () => false, callback);
70
+ (0, import_hardcoded_shared_utils.forEachValue)(valueText, extractor, () => false, callback);
133
71
  }
134
72
  function forEachNamespacedVariable(valueText, callback) {
135
73
  const extractor = (node) => extractCssVariable(node, (variableName) => {
@@ -138,7 +76,7 @@ function forEachNamespacedVariable(valueText, callback) {
138
76
  }
139
77
  return null;
140
78
  });
141
- forEachValue(valueText, extractor, () => false, callback);
79
+ (0, import_hardcoded_shared_utils.forEachValue)(valueText, extractor, () => false, callback);
142
80
  }
143
81
  function forEachLwcVariable(valueText, callback) {
144
82
  const extractor = (node) => extractCssVariable(node, (variableName, childrenArray) => {
@@ -150,7 +88,7 @@ function forEachLwcVariable(valueText, callback) {
150
88
  );
151
89
  return { name: variableName, hasFallback };
152
90
  });
153
- forEachValue(valueText, extractor, () => false, callback);
91
+ (0, import_hardcoded_shared_utils.forEachValue)(valueText, extractor, () => false, callback);
154
92
  }
155
93
  function formatSuggestionHooks(hooks) {
156
94
  if (hooks.length === 1) {
@@ -164,6 +102,7 @@ function formatSuggestionHooks(hooks) {
164
102
  forEachNamespacedVariable,
165
103
  forEachSldsVariable,
166
104
  formatSuggestionHooks,
105
+ getVarToken,
167
106
  isTargetProperty
168
107
  });
169
108
  //# sourceMappingURL=css-utils.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/utils/css-utils.ts", "../../src/utils/hardcoded-shared-utils.ts", "../../src/utils/color-lib-utils.ts", "../../src/utils/css-functions.ts"],
4
- "sourcesContent": ["import { \n forEachValue, \n type PositionInfo \n} from './hardcoded-shared-utils';\n\n/**\n * Check if a CSS property should be targeted for linting based on prefixes or explicit targets\n * @param property - The CSS property name to check\n * @param propertyTargets - Array of specific properties to target (empty means target all)\n * @returns true if the property should be targeted\n */\nexport function isTargetProperty(property: string, propertyTargets: string[] = []): boolean {\n if (typeof property !== 'string') return false;\n return property.startsWith('--sds-')\n || property.startsWith('--slds-')\n || property.startsWith('--lwc-')\n || propertyTargets.length === 0\n || propertyTargets.includes(property);\n}\n\n/**\n * CSS Variable information for SLDS variable detection\n */\nexport interface CssVariableInfo {\n name: string; // Variable name: --slds-g-color-surface-1\n hasFallback: boolean; // Whether var() already has a fallback\n}\n\n/**\n * Generic CSS variable extractor that can be customized for different use cases\n * @param node - AST node to extract from\n * @param filter - Function to validate and extract variable information\n * @returns Extracted variable info or null\n */\nfunction extractCssVariable<T>(\n node: any,\n filter: (variableName: string, childrenArray: any[]) => T | null\n): T | null {\n if (!node || node.type !== 'Function' || node.name !== 'var') {\n return null;\n }\n\n if (!node.children) {\n return null;\n }\n\n // Convert children to array and get the first child (variable name)\n const childrenArray = Array.from(node.children);\n if (childrenArray.length === 0) {\n return null;\n }\n \n const firstChild = childrenArray[0] as any;\n if (!firstChild || firstChild.type !== 'Identifier') {\n return null;\n }\n\n const variableName = firstChild.name;\n if (!variableName) {\n return null;\n }\n\n return filter(variableName, childrenArray);\n}\n\n/**\n * Specialized CSS variable traversal for SLDS variables\n * Finds var(--slds-*) functions and reports their fallback status\n */\nexport function forEachSldsVariable(\n valueText: string,\n callback: (variableInfo: CssVariableInfo, positionInfo: PositionInfo) => void\n): void {\n const extractor = (node: any) => extractCssVariable(node, (variableName, childrenArray) => {\n if (!variableName.startsWith('--slds-')) {\n return null;\n }\n\n // Check if there's a fallback (comma separator)\n const hasFallback = childrenArray.some((child: any) => \n child.type === 'Operator' && child.value === ','\n );\n\n return { name: variableName, hasFallback };\n });\n\n forEachValue(valueText, extractor, () => false, callback);\n}\n\n/**\n * Specialized CSS variable traversal for SLDS/SDS namespace detection\n * Finds var(--slds-*) or var(--sds-*) functions in CSS values\n * Note: hasFallback is set to false as it's unused for namespace validation\n */\nexport function forEachNamespacedVariable(\n valueText: string,\n callback: (variableInfo: CssVariableInfo, positionInfo: PositionInfo) => void\n): void {\n const extractor = (node: any) => extractCssVariable(node, (variableName) => {\n // Check for SLDS or SDS namespace\n if (variableName.startsWith('--slds-') || variableName.startsWith('--sds-')) {\n return { name: variableName, hasFallback: false }; // hasFallback unused, but required by interface\n }\n return null;\n });\n\n forEachValue(valueText, extractor, () => false, callback);\n}\n\n/**\n * Specialized CSS variable traversal for LWC variables\n * Finds var(--lwc-*) functions in CSS values and reports their fallback status\n */\nexport function forEachLwcVariable(\n valueText: string,\n callback: (variableInfo: CssVariableInfo, positionInfo: PositionInfo) => void\n): void {\n const extractor = (node: any) => extractCssVariable(node, (variableName, childrenArray) => {\n if (!variableName.startsWith('--lwc-')) {\n return null;\n }\n\n // Check if there's a fallback (comma separator)\n const hasFallback = childrenArray.some((child: any) => \n child.type === 'Operator' && child.value === ','\n );\n\n return { name: variableName, hasFallback };\n });\n\n forEachValue(valueText, extractor, () => false, callback);\n}\n\n/**\n * Format multiple hook suggestions for better readability\n * @param hooks - Array of hook names to format\n * @returns Formatted string with hooks\n */\nexport function formatSuggestionHooks(hooks: string[]): string {\n if (hooks.length === 1) {\n return `${hooks[0]}`;\n }\n\n // Loop through hooks and append each as a numbered list item with line breaks\n return '\\n' + hooks.map((hook, index) => `${index + 1}. ${hook}`).join('\\n');\n}", "import { parse, walk } from '@eslint/css-tree';\nimport type { HandlerContext } from '../types';\nimport type { ParsedUnitValue } from './value-utils';\nimport { ALLOWED_UNITS } from './value-utils';\nimport { extractColorValue } from './color-lib-utils';\nimport { isCssFunction } from './css-functions';\n\n/**\n * Common replacement data structure used by both color and density handlers\n */\nexport interface ReplacementInfo {\n start: number;\n end: number;\n replacement: string; // Full CSS var: var(--hook, fallback)\n displayValue: string; // Just the hook: --hook\n hasHook: boolean;\n}\n\n/**\n * Position information from CSS tree parsing\n */\nexport interface PositionInfo {\n start?: { offset: number; line: number; column: number };\n end?: { offset: number; line: number; column: number };\n}\n\n/**\n * Generic callback for processing values with position information\n */\nexport type ValueCallback<T> = (value: T, positionInfo?: PositionInfo) => void;\n\n/**\n * Known valid font-weight values\n */\nconst FONT_WEIGHTS = [\n 'normal',\n 'bold', \n 'bolder',\n 'lighter',\n '100',\n '200', \n '300',\n '400',\n '500',\n '600',\n '700',\n '800',\n '900'\n];\n\n/**\n * Check if a value is a known font-weight\n */\nexport function isKnownFontWeight(value: string | number): boolean {\n const stringValue = value.toString();\n return FONT_WEIGHTS.includes(stringValue.toLowerCase());\n}\n\n/**\n * Generic shorthand auto-fix handler\n * Handles the common logic for reconstructing shorthand values with replacements\n */\nexport function handleShorthandAutoFix(\n declarationNode: any,\n context: HandlerContext,\n valueText: string,\n replacements: ReplacementInfo[]\n) {\n // Sort replacements by position for proper reconstruction\n const sortedReplacements = replacements.sort((a, b) => a.start - b.start);\n \n // Check if we can apply auto-fix (at least one value has a hook)\n const hasAnyHooks = sortedReplacements.some(r => r.hasHook);\n const canAutoFix = hasAnyHooks;\n\n // Report each individual value\n sortedReplacements.forEach(({ start, end, replacement, displayValue, hasHook }) => {\n const originalValue = valueText.substring(start, end);\n const valueStartColumn = declarationNode.value.loc.start.column;\n const valueColumn = valueStartColumn + start;\n \n // Create precise error location for this value\n const { loc: { start: locStart, end: locEnd } } = declarationNode.value;\n const reportNode = {\n ...declarationNode.value,\n loc: {\n ...declarationNode.value.loc,\n start: {\n ...locStart,\n column: valueColumn\n },\n end: {\n ...locEnd,\n column: valueColumn + originalValue.length\n }\n }\n };\n\n if (hasHook) {\n // Create auto-fix for the entire shorthand value\n const fix = canAutoFix ? (fixer: any) => {\n // Reconstruct the entire value with all replacements\n let newValue = valueText;\n \n // Apply replacements from right to left to maintain string positions\n for (let i = sortedReplacements.length - 1; i >= 0; i--) {\n const { start: rStart, end: rEnd, replacement: rReplacement } = sortedReplacements[i];\n newValue = newValue.substring(0, rStart) + rReplacement + newValue.substring(rEnd);\n }\n \n return fixer.replaceText(declarationNode.value, newValue);\n } : undefined;\n\n context.context.report({\n node: reportNode,\n messageId: 'hardcodedValue',\n data: {\n oldValue: originalValue,\n newValue: displayValue\n },\n fix\n });\n } else {\n // No hook available\n context.context.report({\n node: reportNode,\n messageId: 'noReplacement',\n data: {\n oldValue: originalValue\n }\n });\n }\n });\n}\n\n/**\n * Generic CSS tree traversal with position tracking\n * Always provides position information since both handlers need it\n */\nexport function forEachValue<T>(\n valueText: string,\n extractValue: (node: any) => T | null,\n shouldSkipNode: (node: any) => boolean,\n callback: (value: T, positionInfo: PositionInfo) => void\n): void {\n if (!valueText || typeof valueText !== 'string') {\n return;\n }\n\n try {\n const ast = parse(valueText, { context: 'value' as const, positions: true });\n \n walk(ast, {\n enter(node: any) {\n // Skip nodes efficiently using this.skip\n if (shouldSkipNode(node)) {\n return this.skip;\n }\n \n const value = extractValue(node);\n if (value !== null) {\n const positionInfo: PositionInfo = {\n start: node.loc?.start,\n end: node.loc?.end\n };\n callback(value, positionInfo);\n }\n }\n });\n } catch (error) {\n // Silently handle parse errors\n return;\n }\n}\n\n/**\n * Check if color node should be skipped during traversal\n */\nfunction shouldSkipColorNode(node: any): boolean {\n return node.type === 'Function' && isCssFunction(node.name);\n}\n\n/**\n * Check if dimension node should be skipped during traversal\n * Skip all function nodes by default\n */\nfunction shouldSkipDimensionNode(node: any): boolean {\n return node.type === 'Function';\n}\n\n/**\n * Extract dimension value from CSS AST node\n * Returns structured data with number and unit to eliminate regex parsing\n */\nfunction extractDimensionValue(valueNode: any, cssProperty?: string): ParsedUnitValue | null {\n if (!valueNode) return null;\n \n switch (valueNode.type) {\n case 'Dimension':\n // Dimensions: 16px, 1rem -> extract value and unit directly from AST\n const numValue = Number(valueNode.value);\n if (numValue === 0) return null; // Skip zero values\n \n const unit = valueNode.unit.toLowerCase();\n if (!ALLOWED_UNITS.includes(unit)) return null; // Support only allowed units\n \n return {\n number: numValue,\n unit: unit as 'px' | 'rem' | '%' | 'em' | 'ch'\n };\n \n case 'Number':\n // Numbers: 400, 1.5 -> treat as unitless (font-weight, line-height, etc.)\n const numberValue = Number(valueNode.value);\n if (numberValue === 0) return null; // Skip zero values\n \n return {\n number: numberValue,\n unit: null\n };\n \n case 'Percentage':\n // Percentage values: 100%, 50% -> extract value and add % unit\n const percentValue = Number(valueNode.value);\n if (percentValue === 0) return null; // Skip zero values\n \n return {\n number: percentValue,\n unit: '%'\n };\n \n case 'Value':\n // Value wrapper - extract from first child\n return valueNode.children?.[0] ? extractDimensionValue(valueNode.children[0], cssProperty) : null;\n }\n \n return null;\n}\n\n/**\n * Specialized color value traversal\n * Handles color-specific extraction and skipping logic\n */\nexport function forEachColorValue(\n valueText: string,\n callback: (colorValue: string, positionInfo: PositionInfo) => void\n): void {\n forEachValue(valueText, extractColorValue, shouldSkipColorNode, callback);\n}\n\n/**\n * Specialized density value traversal\n * Handles dimension-specific extraction and skipping logic\n */\nexport function forEachDensityValue(\n valueText: string,\n cssProperty: string,\n callback: (parsedDimension: ParsedUnitValue, positionInfo: PositionInfo) => void\n): void {\n forEachValue(\n valueText, \n (node) => extractDimensionValue(node, cssProperty), \n shouldSkipDimensionNode, \n callback\n );\n}\n\n/**\n * Extract font-related values from CSS AST node\n * Handles font-size and font-weight values\n */\nfunction extractFontValue(node: any): ParsedUnitValue | null {\n if (!node) return null;\n \n switch (node.type) {\n case 'Dimension':\n // Font-size: 16px, 1rem, etc.\n const numValue = Number(node.value);\n if (numValue <= 0) return null; // Skip zero/negative values\n \n const unit = node.unit.toLowerCase();\n if (!ALLOWED_UNITS.includes(unit)) return null;\n \n return {\n number: numValue,\n unit: unit as 'px' | 'rem' | '%' | 'em' | 'ch'\n };\n \n case 'Number':\n // Font-weight: 400, 700, etc.\n const numberValue = Number(node.value);\n if (numberValue <= 0) {\n return null; // Skip zero/negative values\n }\n \n // Only accept known font-weight values for unitless numbers\n if (!isKnownFontWeight(numberValue)) {\n return null; // Skip values that aren't valid font-weights\n }\n \n return {\n number: numberValue,\n unit: null\n };\n \n case 'Identifier':\n // Font-weight keywords: normal, bold, etc.\n const namedValue = node.name.toLowerCase();\n \n // Only accept known font-weight keywords\n if (!isKnownFontWeight(namedValue)) {\n return null;\n }\n \n // Convert known keywords to numeric values\n if (namedValue === 'normal') {\n return { number: 400, unit: null };\n }\n \n // For other keywords (bolder, lighter), we can't determine exact numeric value\n // but we know they're valid font-weight values\n return { number: namedValue, unit: null };\n \n case 'Percentage':\n // Percentage values for font-size\n const percentValue = Number(node.value);\n if (percentValue === 0) return null; // Skip zero values\n \n return {\n number: percentValue,\n unit: '%'\n };\n \n case 'Value':\n // Value wrapper - extract from first child\n return node.children?.[0] ? extractFontValue(node.children[0]) : null;\n }\n \n return null;\n}\n\n/**\n * Check if font node should be skipped during traversal\n * Skip all function nodes by default\n */\nfunction shouldSkipFontNode(node: any): boolean {\n return node.type === 'Function';\n}\n\n/**\n * Specialized font value traversal\n * Handles font-specific extraction and skipping logic\n */\nexport function forEachFontValue(\n valueText: string,\n callback: (fontValue: ParsedUnitValue, positionInfo: PositionInfo) => void\n): void {\n forEachValue(valueText, extractFontValue, shouldSkipFontNode, callback);\n}\n", "//stylelint-sds/packages/stylelint-plugin-slds/src/utils/color-lib-utils.ts\nimport { ValueToStylingHooksMapping, ValueToStylingHookEntry } from '@salesforce-ux/sds-metadata';\nimport chroma from 'chroma-js';\nimport { generate } from '@eslint/css-tree';\nimport { isCssColorFunction } from './css-functions';\n\nconst LAB_THRESHOLD = 25; // Adjust this to set how strict the matching should be\n\nconst isHardCodedColor = (color: string): boolean => {\n const colorRegex =\n /\\b(rgb|rgba)\\((\\s*\\d{1,3}\\s*,\\s*){2,3}\\s*(0|1|0?\\.\\d+)\\s*\\)|#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\\b|[a-zA-Z]+/g;\n return colorRegex.test(color);\n};\n\nconst isHexCode = (color: string): boolean => {\n const hexPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/; // Pattern for #RGB or #RRGGBB\n return hexPattern.test(color);\n};\n\n// Convert a named color or hex code into a hex format using chroma-js\nconst convertToHex = (color: string): string | null => {\n try {\n // Try converting the color using chroma-js, which handles both named and hex colors\n return chroma(color).hex();\n } catch (e) {\n // If chroma can't process the color, it's likely invalid\n return null;\n }\n};\n\n// Find the closest color hook using LAB distance\nconst findClosestColorHook = (\n color: string,\n supportedColors:ValueToStylingHooksMapping,\n cssProperty: string\n): string[] => {\n const returnStylingHooks: string[] = [];\n const closestHooksWithSameProperty: { name: string; distance: number }[] = [];\n const closestHooksWithoutSameProperty: { name: string; distance: number }[] =\n [];\n const closestHooksWithAllProperty: { name: string; distance: number }[] =\n [];\n const labColor = chroma(color).lab();\n\n Object.entries(supportedColors).forEach(([sldsValue, data]) => {\n if (sldsValue && isHexCode(sldsValue)) {\n const hooks = data as ValueToStylingHookEntry[]; // Get the hooks for the sldsValue\n\n hooks.forEach((hook) => {\n const labSupportedColor = chroma(sldsValue).lab();\n const distance = (JSON.stringify(labColor) === JSON.stringify(labSupportedColor)) ? 0\n : chroma.distance(chroma.lab(...labColor), chroma.lab(...labSupportedColor), \"lab\");\n // Check if the hook has the same property\n if (hook.properties.includes(cssProperty)) {\n // Add to same property hooks if within threshold\n if (distance <= LAB_THRESHOLD) {\n closestHooksWithSameProperty.push({ name: hook.name, distance });\n }\n } \n // Check for the universal selector\n else if ( hook.properties.includes(\"*\") ){\n // Add to same property hooks if within threshold\n if (distance <= LAB_THRESHOLD) {\n closestHooksWithAllProperty.push({ name: hook.name, distance });\n }\n }\n else {\n // Add to different property hooks if within threshold\n if (distance <= LAB_THRESHOLD) {\n closestHooksWithoutSameProperty.push({ name: hook.name, distance });\n }\n }\n });\n }\n });\n\n// Group hooks by their priority\nconst closesthookGroups = [\n { hooks: closestHooksWithSameProperty, distance: 0 },\n { hooks: closestHooksWithAllProperty, distance: 0 },\n { hooks: closestHooksWithSameProperty, distance: Infinity }, // For hooks with distance > 0\n { hooks: closestHooksWithAllProperty, distance: Infinity },\n { hooks: closestHooksWithoutSameProperty, distance: Infinity },\n];\n\nfor (const group of closesthookGroups) {\n // Filter hooks based on the distance condition\n const filteredHooks = group.hooks.filter(h => \n group.distance === 0 ? h.distance === 0 : h.distance > 0\n );\n\n if (returnStylingHooks.length < 1 && filteredHooks.length > 0) {\n filteredHooks.sort((a, b) => a.distance - b.distance);\n returnStylingHooks.push(...filteredHooks.slice(0, 5).map((h) => h.name));\n }\n}\n\n\n return Array.from(new Set(returnStylingHooks));\n};\n\n/**\n * This method is usefull to identify all possible css color values.\n * - names colors\n * - 6,8 digit hex\n * - rgb and rgba\n * - hsl and hsla\n */\nconst isValidColor = (val:string):boolean => chroma.valid(val);\n\n/**\n * Extract color value from CSS AST node\n */\nconst extractColorValue = (node: any): string | null => {\n let colorValue: string | null = null;\n \n switch (node.type) {\n case 'Hash':\n colorValue = `#${node.value}`;\n break;\n case 'Identifier':\n colorValue = node.name;\n break;\n case 'Function':\n // Only extract color functions\n if (isCssColorFunction(node.name)) {\n colorValue = generate(node);\n }\n break;\n }\n \n return colorValue && isValidColor(colorValue) ? colorValue : null;\n};\n\nexport { findClosestColorHook, convertToHex, isHexCode, isHardCodedColor, isValidColor, extractColorValue };\n", "//stylelint-sds/packages/stylelint-plugin-slds/src/utils/css-functions.ts\n/**\n * Complete list of CSS functions that should be preserved/recognized\n */\nconst CSS_FUNCTIONS = [\n 'attr',\n 'calc',\n 'color-mix',\n 'conic-gradient',\n 'counter',\n 'cubic-bezier',\n 'linear-gradient',\n 'max',\n 'min',\n 'radial-gradient',\n 'repeating-conic-gradient',\n 'repeating-linear-gradient',\n 'repeating-radial-gradient',\n 'var'\n ];\n \n \n const CSS_MATH_FUNCTIONS = ['calc', 'min', 'max'];\n \n \n const RGB_COLOR_FUNCTIONS = ['rgb', 'rgba', 'hsl', 'hsla'];\n \n /**\n * Regex for matching any CSS function (for general detection)\n * Matches function names within other text\n */\n const cssFunctionsRegex = new RegExp(`(?:${CSS_FUNCTIONS.join('|')})`);\n \n \n const cssFunctionsExactRegex = new RegExp(`^(?:${CSS_FUNCTIONS.join('|')})$`);\n \n \n const cssMathFunctionsRegex = new RegExp(`^(?:${CSS_MATH_FUNCTIONS.join('|')})$`);\n \n export function containsCssFunction(value: string): boolean {\n return cssFunctionsRegex.test(value);\n }\n \n /**\n * Check if a value is exactly a CSS function name\n */\n export function isCssFunction(value: string): boolean {\n return cssFunctionsExactRegex.test(value);\n }\n \n export function isCssMathFunction(value: string): boolean {\n return cssMathFunctionsRegex.test(value);\n }\n \n export function isCssColorFunction(value: string): boolean {\n return RGB_COLOR_FUNCTIONS.includes(value);\n }"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,mBAA4B;;;ACE5B,uBAAmB;AACnB,sBAAyB;;;ACCzB,IAAM,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGA,IAAM,qBAAqB,CAAC,QAAQ,OAAO,KAAK;AAShD,IAAM,oBAAoB,IAAI,OAAO,MAAM,cAAc,KAAK,GAAG,CAAC,GAAG;AAGrE,IAAM,yBAAyB,IAAI,OAAO,OAAO,cAAc,KAAK,GAAG,CAAC,IAAI;AAG5E,IAAM,wBAAwB,IAAI,OAAO,OAAO,mBAAmB,KAAK,GAAG,CAAC,IAAI;;;AFsG3E,SAAS,aACd,WACA,cACA,gBACA,UACM;AACN,MAAI,CAAC,aAAa,OAAO,cAAc,UAAU;AAC/C;AAAA,EACF;AAEA,MAAI;AACF,UAAM,UAAM,wBAAM,WAAW,EAAE,SAAS,SAAkB,WAAW,KAAK,CAAC;AAE3E,+BAAK,KAAK;AAAA,MACR,MAAM,MAAW;AAEf,YAAI,eAAe,IAAI,GAAG;AACxB,iBAAO,KAAK;AAAA,QACd;AAEA,cAAM,QAAQ,aAAa,IAAI;AAC/B,YAAI,UAAU,MAAM;AAClB,gBAAM,eAA6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1D;AAOO,SAAS,0BACd,WACA,UACM;AACN,QAAM,YAAY,CAAC,SAAc,mBAAmB,MAAM,CAAC,iBAAiB;AAE1E,QAAI,aAAa,WAAW,SAAS,KAAK,aAAa,WAAW,QAAQ,GAAG;AAC3E,aAAO,EAAE,MAAM,cAAc,aAAa,MAAM;AAAA,IAClD;AACA,WAAO;AAAA,EACT,CAAC;AAED,eAAa,WAAW,WAAW,MAAM,OAAO,QAAQ;AAC1D;AAMO,SAAS,mBACd,WACA,UACM;AACN,QAAM,YAAY,CAAC,SAAc,mBAAmB,MAAM,CAAC,cAAc,kBAAkB;AACzF,QAAI,CAAC,aAAa,WAAW,QAAQ,GAAG;AACtC,aAAO;AAAA,IACT;AAGA,UAAM,cAAc,cAAc;AAAA,MAAK,CAAC,UACtC,MAAM,SAAS,cAAc,MAAM,UAAU;AAAA,IAC/C;AAEA,WAAO,EAAE,MAAM,cAAc,YAAY;AAAA,EAC3C,CAAC;AAED,eAAa,WAAW,WAAW,MAAM,OAAO,QAAQ;AAC1D;AAOO,SAAS,sBAAsB,OAAyB;AAC7D,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO,GAAG,MAAM,CAAC,CAAC;AAAA,EACpB;AAGA,SAAO,OAAO,MAAM,IAAI,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,IAAI,EAAE,EAAE,KAAK,IAAI;AAC7E;",
6
- "names": ["import_css_tree"]
3
+ "sources": ["../../src/utils/css-utils.ts"],
4
+ "sourcesContent": ["import { \n forEachValue, \n type PositionInfo \n} from './hardcoded-shared-utils';\n\n/**\n * Check if a CSS property should be targeted for linting based on prefixes or explicit targets\n * @param property - The CSS property name to check\n * @param propertyTargets - Array of specific properties to target (empty means target all)\n * @returns true if the property should be targeted\n */\nexport function isTargetProperty(property: string, propertyTargets: string[] = []): boolean {\n if (typeof property !== 'string') return false;\n return property.startsWith('--sds-')\n || property.startsWith('--slds-')\n || property.startsWith('--lwc-')\n || propertyTargets.length === 0\n || propertyTargets.includes(property);\n}\n\n/**\n * CSS Variable information for SLDS variable detection\n */\nexport interface CssVariableInfo {\n name: string; // Variable name: --slds-g-color-surface-1\n hasFallback: boolean; // Whether var() already has a fallback\n}\n\n/**\n * Generic CSS variable extractor that can be customized for different use cases\n * @param node - AST node to extract from\n * @param filter - Function to validate and extract variable information\n * @returns Extracted variable info or null\n */\nfunction extractCssVariable<T>(\n node: any,\n filter: (variableName: string, childrenArray: any[]) => T | null\n): T | null {\n if (!node || node.type !== 'Function' || node.name !== 'var') {\n return null;\n }\n\n if (!node.children) {\n return null;\n }\n\n // Convert children to array and get the first child (variable name)\n const childrenArray = Array.from(node.children);\n if (childrenArray.length === 0) {\n return null;\n }\n \n const firstChild = childrenArray[0] as any;\n if (!firstChild || firstChild.type !== 'Identifier') {\n return null;\n }\n\n const variableName = firstChild.name;\n if (!variableName) {\n return null;\n }\n\n return filter(variableName, childrenArray);\n}\n\n/**\n * Get the CSS variable token from a var() function node\n * Extracts the custom property name from var(--custom-prop) -> \"--custom-prop\"\n * @param node - CSS tree AST node (Function node expected)\n * @returns The custom property name (e.g., \"--slds-g-color-brand-base-15\") or empty string\n */\nexport function getVarToken(node: any): string {\n const result = extractCssVariable(node, (variableName) => variableName);\n return result || '';\n}\n\n/**\n * Specialized CSS variable traversal for SLDS variables\n * Finds var(--slds-*) functions and reports their fallback status\n */\nexport function forEachSldsVariable(\n valueText: string,\n callback: (variableInfo: CssVariableInfo, positionInfo: PositionInfo) => void\n): void {\n const extractor = (node: any) => extractCssVariable(node, (variableName, childrenArray) => {\n if (!variableName.startsWith('--slds-')) {\n return null;\n }\n\n // Check if there's a fallback (comma separator)\n const hasFallback = childrenArray.some((child: any) => \n child.type === 'Operator' && child.value === ','\n );\n\n return { name: variableName, hasFallback };\n });\n\n forEachValue(valueText, extractor, () => false, callback);\n}\n\n/**\n * Specialized CSS variable traversal for SLDS/SDS namespace detection\n * Finds var(--slds-*) or var(--sds-*) functions in CSS values\n * Note: hasFallback is set to false as it's unused for namespace validation\n */\nexport function forEachNamespacedVariable(\n valueText: string,\n callback: (variableInfo: CssVariableInfo, positionInfo: PositionInfo) => void\n): void {\n const extractor = (node: any) => extractCssVariable(node, (variableName) => {\n // Check for SLDS or SDS namespace\n if (variableName.startsWith('--slds-') || variableName.startsWith('--sds-')) {\n return { name: variableName, hasFallback: false }; // hasFallback unused, but required by interface\n }\n return null;\n });\n\n forEachValue(valueText, extractor, () => false, callback);\n}\n\n/**\n * Specialized CSS variable traversal for LWC variables\n * Finds var(--lwc-*) functions in CSS values and reports their fallback status\n */\nexport function forEachLwcVariable(\n valueText: string,\n callback: (variableInfo: CssVariableInfo, positionInfo: PositionInfo) => void\n): void {\n const extractor = (node: any) => extractCssVariable(node, (variableName, childrenArray) => {\n if (!variableName.startsWith('--lwc-')) {\n return null;\n }\n\n // Check if there's a fallback (comma separator)\n const hasFallback = childrenArray.some((child: any) => \n child.type === 'Operator' && child.value === ','\n );\n\n return { name: variableName, hasFallback };\n });\n\n forEachValue(valueText, extractor, () => false, callback);\n}\n\n/**\n * Format multiple hook suggestions for better readability\n * @param hooks - Array of hook names to format\n * @returns Formatted string with hooks\n */\nexport function formatSuggestionHooks(hooks: string[]): string {\n if (hooks.length === 1) {\n return `${hooks[0]}`;\n }\n\n // Loop through hooks and append each as a numbered list item with line breaks\n return '\\n' + hooks.map((hook, index) => `${index + 1}. ${hook}`).join('\\n');\n}"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAGO;AAQA,SAAS,iBAAiB,UAAkB,kBAA4B,CAAC,GAAY;AAC1F,MAAI,OAAO,aAAa,SAAU,QAAO;AACzC,SAAO,SAAS,WAAW,QAAQ,KAC9B,SAAS,WAAW,SAAS,KAC7B,SAAS,WAAW,QAAQ,KAC5B,gBAAgB,WAAW,KAC3B,gBAAgB,SAAS,QAAQ;AACxC;AAgBA,SAAS,mBACP,MACA,QACU;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AAc,mBAAmB,MAAM,CAAC,cAAc,kBAAkB;AACzF,QAAI,CAAC,aAAa,WAAW,QAAQ,GAAG;AACtC,aAAO;AAAA,IACT;AAGA,UAAM,cAAc,cAAc;AAAA,MAAK,CAAC,UACtC,MAAM,SAAS,cAAc,MAAM,UAAU;AAAA,IAC/C;AAEA,WAAO,EAAE,MAAM,cAAc,YAAY;AAAA,EAC3C,CAAC;AAED,kDAAa,WAAW,WAAW,MAAM,OAAO,QAAQ;AAC1D;AAOO,SAAS,sBAAsB,OAAyB;AAC7D,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO,GAAG,MAAM,CAAC,CAAC;AAAA,EACpB;AAGA,SAAO,OAAO,MAAM,IAAI,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,IAAI,EAAE,EAAE,KAAK,IAAI;AAC7E;",
6
+ "names": []
7
7
  }
@@ -0,0 +1,9 @@
1
+ import type { CustomHookMapping } from '../types';
2
+ /**
3
+ * Get custom hook mapping for a given CSS property and value
4
+ * @param cssProperty - The CSS property (e.g., "background-color", "color")
5
+ * @param value - The hardcoded value (e.g., "#fff", "16px")
6
+ * @param customMapping - The custom mapping configuration from rule options
7
+ * @returns The hook name if a mapping is found, null otherwise
8
+ */
9
+ export declare function getCustomMapping(cssProperty: string, value: string, customMapping?: CustomHookMapping): string | null;
@@ -0,0 +1,62 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/utils/custom-mapping-utils.ts
20
+ var custom_mapping_utils_exports = {};
21
+ __export(custom_mapping_utils_exports, {
22
+ getCustomMapping: () => getCustomMapping
23
+ });
24
+ module.exports = __toCommonJS(custom_mapping_utils_exports);
25
+ function matchesPropertyPattern(cssProperty, pattern) {
26
+ const normalizedProperty = cssProperty.toLowerCase();
27
+ const normalizedPattern = pattern.toLowerCase();
28
+ if (normalizedProperty === normalizedPattern) {
29
+ return true;
30
+ }
31
+ if (normalizedPattern.endsWith("*")) {
32
+ const prefix = normalizedPattern.slice(0, -1);
33
+ return normalizedProperty.startsWith(prefix);
34
+ }
35
+ return false;
36
+ }
37
+ function getCustomMapping(cssProperty, value, customMapping) {
38
+ if (!customMapping) {
39
+ return null;
40
+ }
41
+ const normalizedValue = value.toLowerCase().trim();
42
+ for (const [hookName, config] of Object.entries(customMapping)) {
43
+ const propertyMatches = config.properties.some(
44
+ (pattern) => matchesPropertyPattern(cssProperty, pattern)
45
+ );
46
+ if (!propertyMatches) {
47
+ continue;
48
+ }
49
+ const valueMatches = config.values.some(
50
+ (configValue) => configValue.toLowerCase().trim() === normalizedValue
51
+ );
52
+ if (valueMatches) {
53
+ return hookName;
54
+ }
55
+ }
56
+ return null;
57
+ }
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ getCustomMapping
61
+ });
62
+ //# sourceMappingURL=custom-mapping-utils.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/custom-mapping-utils.ts"],
4
+ "sourcesContent": ["import type { CustomHookMapping } from '../types';\n\n/**\n * Check if a CSS property matches a pattern (supports wildcards)\n * @param cssProperty - The CSS property to check (e.g., \"background-color\")\n * @param pattern - The pattern to match against (e.g., \"background*\" or \"color\")\n * @returns true if the property matches the pattern\n */\nfunction matchesPropertyPattern(cssProperty: string, pattern: string): boolean {\n const normalizedProperty = cssProperty.toLowerCase();\n const normalizedPattern = pattern.toLowerCase();\n\n // Exact match\n if (normalizedProperty === normalizedPattern) {\n return true;\n }\n\n // Wildcard match (e.g., \"background*\" matches \"background-color\", \"background-image\")\n if (normalizedPattern.endsWith('*')) {\n const prefix = normalizedPattern.slice(0, -1);\n return normalizedProperty.startsWith(prefix);\n }\n\n return false;\n}\n\n/**\n * Get custom hook mapping for a given CSS property and value\n * @param cssProperty - The CSS property (e.g., \"background-color\", \"color\")\n * @param value - The hardcoded value (e.g., \"#fff\", \"16px\")\n * @param customMapping - The custom mapping configuration from rule options\n * @returns The hook name if a mapping is found, null otherwise\n */\nexport function getCustomMapping(\n cssProperty: string,\n value: string,\n customMapping?: CustomHookMapping\n): string | null {\n if (!customMapping) {\n return null;\n }\n\n const normalizedValue = value.toLowerCase().trim();\n\n // Iterate through all hook mappings\n for (const [hookName, config] of Object.entries(customMapping)) {\n // Check if any property pattern matches\n const propertyMatches = config.properties.some((pattern) =>\n matchesPropertyPattern(cssProperty, pattern)\n );\n\n if (!propertyMatches) {\n continue;\n }\n\n // Check if the value matches any configured value\n const valueMatches = config.values.some(\n (configValue) => configValue.toLowerCase().trim() === normalizedValue\n );\n\n if (valueMatches) {\n return hookName;\n }\n }\n\n return null;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,SAAS,uBAAuB,aAAqB,SAA0B;AAC7E,QAAM,qBAAqB,YAAY,YAAY;AACnD,QAAM,oBAAoB,QAAQ,YAAY;AAG9C,MAAI,uBAAuB,mBAAmB;AAC5C,WAAO;AAAA,EACT;AAGA,MAAI,kBAAkB,SAAS,GAAG,GAAG;AACnC,UAAM,SAAS,kBAAkB,MAAM,GAAG,EAAE;AAC5C,WAAO,mBAAmB,WAAW,MAAM;AAAA,EAC7C;AAEA,SAAO;AACT;AASO,SAAS,iBACd,aACA,OACA,eACe;AACf,MAAI,CAAC,eAAe;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,kBAAkB,MAAM,YAAY,EAAE,KAAK;AAGjD,aAAW,CAAC,UAAU,MAAM,KAAK,OAAO,QAAQ,aAAa,GAAG;AAE9D,UAAM,kBAAkB,OAAO,WAAW;AAAA,MAAK,CAAC,YAC9C,uBAAuB,aAAa,OAAO;AAAA,IAC7C;AAEA,QAAI,CAAC,iBAAiB;AACpB;AAAA,IACF;AAGA,UAAM,eAAe,OAAO,OAAO;AAAA,MACjC,CAAC,gBAAgB,YAAY,YAAY,EAAE,KAAK,MAAM;AAAA,IACxD;AAEA,QAAI,cAAc;AAChB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -9,6 +9,7 @@ export interface ReplacementInfo {
9
9
  replacement: string;
10
10
  displayValue: string;
11
11
  hasHook: boolean;
12
+ isNumeric?: boolean;
12
13
  }
13
14
  /**
14
15
  * Position information from CSS tree parsing