@yahoo/uds 3.114.0-beta.2 → 3.114.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/dist/automated-config/dist/generated/autoVariants.cjs +3 -0
  2. package/dist/automated-config/dist/generated/autoVariants.d.cts +3 -0
  3. package/dist/automated-config/dist/generated/autoVariants.d.ts +3 -0
  4. package/dist/automated-config/dist/generated/autoVariants.js +3 -0
  5. package/dist/automated-config/dist/generated/generatedConfigs.cjs +1883 -0
  6. package/dist/automated-config/dist/generated/generatedConfigs.d.cts +175 -1
  7. package/dist/automated-config/dist/generated/generatedConfigs.d.ts +175 -1
  8. package/dist/automated-config/dist/generated/generatedConfigs.js +1882 -1
  9. package/dist/automated-config/dist/generated/universalTokensConfigAuto.cjs +84 -0
  10. package/dist/automated-config/dist/generated/universalTokensConfigAuto.d.cts +3 -1
  11. package/dist/automated-config/dist/generated/universalTokensConfigAuto.d.ts +3 -1
  12. package/dist/automated-config/dist/generated/universalTokensConfigAuto.js +84 -0
  13. package/dist/automated-config/dist/mapTextVariantFixtureToValue.cjs +1 -12
  14. package/dist/automated-config/dist/mapTextVariantFixtureToValue.js +1 -12
  15. package/dist/automated-config/dist/properties.cjs +58 -12
  16. package/dist/automated-config/dist/properties.d.cts +8 -0
  17. package/dist/automated-config/dist/properties.d.ts +8 -0
  18. package/dist/automated-config/dist/properties.js +58 -12
  19. package/dist/automated-config/dist/utils/getConfigVariantProperties.d.cts +2 -2
  20. package/dist/automated-config/dist/utils/getConfigVariantProperties.d.ts +2 -2
  21. package/dist/cli/commands/sync.cjs +7 -1
  22. package/dist/cli/commands/sync.d.cts +1 -1
  23. package/dist/cli/commands/sync.d.ts +1 -1
  24. package/dist/cli/commands/sync.js +7 -1
  25. package/dist/cli/commands/version.cjs +2 -0
  26. package/dist/cli/commands/version.d.cts +1 -1
  27. package/dist/cli/commands/version.d.ts +1 -1
  28. package/dist/cli/commands/version.js +2 -0
  29. package/dist/cli/dist/cli.cjs +1 -1
  30. package/dist/cli/dist/cli.js +1 -1
  31. package/dist/cli/dist/commands/editor-rules.cjs +2 -2
  32. package/dist/cli/dist/commands/editor-rules.js +2 -2
  33. package/dist/cli/dist/utils/rules/config.cjs +1 -1
  34. package/dist/cli/dist/utils/rules/config.js +1 -1
  35. package/dist/cli/runner.cjs +2 -11
  36. package/dist/cli/runner.js +2 -11
  37. package/dist/components/Scrim.cjs +28 -0
  38. package/dist/components/Scrim.d.cts +14 -0
  39. package/dist/components/Scrim.d.ts +14 -0
  40. package/dist/components/Scrim.js +26 -0
  41. package/dist/components/client/BottomSheet/BottomSheet.cjs +209 -0
  42. package/dist/components/client/BottomSheet/BottomSheet.d.cts +77 -0
  43. package/dist/components/client/BottomSheet/BottomSheet.d.ts +77 -0
  44. package/dist/components/client/BottomSheet/BottomSheet.js +207 -0
  45. package/dist/components/client/BottomSheet/BottomSheetContent.cjs +26 -0
  46. package/dist/components/client/BottomSheet/BottomSheetContent.d.cts +15 -0
  47. package/dist/components/client/BottomSheet/BottomSheetContent.d.ts +15 -0
  48. package/dist/components/client/BottomSheet/BottomSheetContent.js +24 -0
  49. package/dist/components/client/BottomSheet/BottomSheetDismiss.cjs +15 -0
  50. package/dist/components/client/BottomSheet/BottomSheetDismiss.d.cts +12 -0
  51. package/dist/components/client/BottomSheet/BottomSheetDismiss.d.ts +12 -0
  52. package/dist/components/client/BottomSheet/BottomSheetDismiss.js +13 -0
  53. package/dist/components/client/BottomSheet/BottomSheetHandle.cjs +30 -0
  54. package/dist/components/client/BottomSheet/BottomSheetHandle.d.cts +19 -0
  55. package/dist/components/client/BottomSheet/BottomSheetHandle.d.ts +19 -0
  56. package/dist/components/client/BottomSheet/BottomSheetHandle.js +28 -0
  57. package/dist/components/client/BottomSheet/BottomSheetHeader.cjs +42 -0
  58. package/dist/components/client/BottomSheet/BottomSheetHeader.d.cts +18 -0
  59. package/dist/components/client/BottomSheet/BottomSheetHeader.d.ts +18 -0
  60. package/dist/components/client/BottomSheet/BottomSheetHeader.js +40 -0
  61. package/dist/components/client/BottomSheet/BottomSheetProvider.cjs +21 -0
  62. package/dist/components/client/BottomSheet/BottomSheetProvider.d.cts +19 -0
  63. package/dist/components/client/BottomSheet/BottomSheetProvider.d.ts +19 -0
  64. package/dist/components/client/BottomSheet/BottomSheetProvider.js +19 -0
  65. package/dist/components/client/BottomSheet/BottomSheetTrigger.cjs +15 -0
  66. package/dist/components/client/BottomSheet/BottomSheetTrigger.d.cts +12 -0
  67. package/dist/components/client/BottomSheet/BottomSheetTrigger.d.ts +12 -0
  68. package/dist/components/client/BottomSheet/BottomSheetTrigger.js +13 -0
  69. package/dist/components/client/BottomSheet/UDSBottomSheetConfigProvider.cjs +32 -0
  70. package/dist/components/client/BottomSheet/UDSBottomSheetConfigProvider.d.cts +22 -0
  71. package/dist/components/client/BottomSheet/UDSBottomSheetConfigProvider.d.ts +22 -0
  72. package/dist/components/client/BottomSheet/UDSBottomSheetConfigProvider.js +29 -0
  73. package/dist/components/client/BottomSheet/index.cjs +22 -0
  74. package/dist/components/client/BottomSheet/index.d.cts +10 -0
  75. package/dist/components/client/BottomSheet/index.d.ts +10 -0
  76. package/dist/components/client/BottomSheet/index.js +12 -0
  77. package/dist/components/client/BottomSheet/useBottomSheetDrag.cjs +188 -0
  78. package/dist/components/client/BottomSheet/useBottomSheetDrag.d.cts +44 -0
  79. package/dist/components/client/BottomSheet/useBottomSheetDrag.d.ts +44 -0
  80. package/dist/components/client/BottomSheet/useBottomSheetDrag.js +185 -0
  81. package/dist/components/client/BottomSheet/useBottomSheetSnapModel.cjs +138 -0
  82. package/dist/components/client/BottomSheet/useBottomSheetSnapModel.d.cts +46 -0
  83. package/dist/components/client/BottomSheet/useBottomSheetSnapModel.d.ts +46 -0
  84. package/dist/components/client/BottomSheet/useBottomSheetSnapModel.js +135 -0
  85. package/dist/components/client/BottomSheet/useBottomSheetStore.cjs +34 -0
  86. package/dist/components/client/BottomSheet/useBottomSheetStore.d.cts +38 -0
  87. package/dist/components/client/BottomSheet/useBottomSheetStore.d.ts +38 -0
  88. package/dist/components/client/BottomSheet/useBottomSheetStore.js +31 -0
  89. package/dist/components/client/BottomSheet/useBottomSheetStoreInternal.cjs +17 -0
  90. package/dist/components/client/BottomSheet/useBottomSheetStoreInternal.d.cts +13 -0
  91. package/dist/components/client/BottomSheet/useBottomSheetStoreInternal.d.ts +13 -0
  92. package/dist/components/client/BottomSheet/useBottomSheetStoreInternal.js +15 -0
  93. package/dist/components/client/BottomSheet/useExpansionMargins.cjs +89 -0
  94. package/dist/components/client/BottomSheet/useExpansionMargins.d.cts +34 -0
  95. package/dist/components/client/BottomSheet/useExpansionMargins.d.ts +34 -0
  96. package/dist/components/client/BottomSheet/useExpansionMargins.js +87 -0
  97. package/dist/components/client/BottomSheet/useViewportHeight.cjs +32 -0
  98. package/dist/components/client/BottomSheet/useViewportHeight.d.cts +9 -0
  99. package/dist/components/client/BottomSheet/useViewportHeight.d.ts +9 -0
  100. package/dist/components/client/BottomSheet/useViewportHeight.js +30 -0
  101. package/dist/components/client/BottomSheet/useVirtualKeyboard.cjs +48 -0
  102. package/dist/components/client/BottomSheet/useVirtualKeyboard.d.cts +10 -0
  103. package/dist/components/client/BottomSheet/useVirtualKeyboard.d.ts +10 -0
  104. package/dist/components/client/BottomSheet/useVirtualKeyboard.js +46 -0
  105. package/dist/components/client/BottomSheet/utils.cjs +128 -0
  106. package/dist/components/client/BottomSheet/utils.d.cts +61 -0
  107. package/dist/components/client/BottomSheet/utils.d.ts +61 -0
  108. package/dist/components/client/BottomSheet/utils.js +118 -0
  109. package/dist/components/client/Menu/Menu.Content.cjs +1 -1
  110. package/dist/components/client/Menu/Menu.Content.js +1 -1
  111. package/dist/components/client/Menu/Menu.ItemCheckbox.d.cts +1 -1
  112. package/dist/components/client/Menu/Menu.ItemCheckbox.d.ts +1 -1
  113. package/dist/components/client/Menu/Menu.index.d.cts +1 -1
  114. package/dist/components/client/index.cjs +16 -0
  115. package/dist/components/client/index.d.cts +10 -1
  116. package/dist/components/client/index.d.ts +10 -1
  117. package/dist/components/client/index.js +9 -1
  118. package/dist/components/client/providers/UDSConfigProvider.cjs +10 -6
  119. package/dist/components/client/providers/UDSConfigProvider.d.cts +1 -0
  120. package/dist/components/client/providers/UDSConfigProvider.d.ts +1 -0
  121. package/dist/components/client/providers/UDSConfigProvider.js +10 -6
  122. package/dist/components/index.cjs +24 -0
  123. package/dist/components/index.d.cts +9 -1
  124. package/dist/components/index.d.ts +9 -1
  125. package/dist/components/index.js +17 -1
  126. package/dist/config/dist/index.cjs +110 -2
  127. package/dist/config/dist/index.js +110 -2
  128. package/dist/fixtures/dist/index.cjs +103 -0
  129. package/dist/fixtures/dist/index.d.cts +3 -2
  130. package/dist/fixtures/dist/index.d.ts +3 -2
  131. package/dist/fixtures/dist/index.js +103 -1
  132. package/dist/fixtures/index.cjs +1 -0
  133. package/dist/fixtures/index.d.cts +2 -2
  134. package/dist/fixtures/index.d.ts +2 -2
  135. package/dist/fixtures/index.js +2 -2
  136. package/dist/index.cjs +20 -2
  137. package/dist/index.d.cts +12 -5
  138. package/dist/index.d.ts +12 -5
  139. package/dist/index.js +11 -3
  140. package/dist/runtime/bottomSheetConfig.cjs +11 -0
  141. package/dist/runtime/bottomSheetConfig.d.cts +15 -0
  142. package/dist/runtime/bottomSheetConfig.d.ts +15 -0
  143. package/dist/runtime/bottomSheetConfig.js +9 -0
  144. package/dist/runtime/index.cjs +2 -0
  145. package/dist/runtime/index.d.cts +2 -1
  146. package/dist/runtime/index.d.ts +2 -1
  147. package/dist/runtime/index.js +2 -1
  148. package/dist/runtime/udsConfig.cjs +2 -0
  149. package/dist/runtime/udsConfig.d.cts +2 -0
  150. package/dist/runtime/udsConfig.d.ts +2 -0
  151. package/dist/runtime/udsConfig.js +2 -0
  152. package/dist/styles/styler.d.cts +33 -30
  153. package/dist/styles/styler.d.ts +33 -30
  154. package/dist/styles/variants.cjs +278 -278
  155. package/dist/styles/variants.d.cts +9 -0
  156. package/dist/styles/variants.d.ts +9 -0
  157. package/dist/styles/variants.js +278 -278
  158. package/dist/tailwind/dist/commands/generateComponentData.cjs +31 -33
  159. package/dist/tailwind/dist/commands/generateComponentData.d.ts +1 -1
  160. package/dist/tailwind/dist/commands/generateComponentData.js +31 -33
  161. package/dist/tailwind/dist/commands/generatePurgeCSSData.d.ts +1 -1
  162. package/dist/tailwind/dist/commands/purge.cjs +4 -3
  163. package/dist/tailwind/dist/commands/purge.d.ts +1 -1
  164. package/dist/tailwind/dist/commands/purge.js +4 -3
  165. package/dist/tailwind/dist/index.d.cts +0 -1
  166. package/dist/tailwind/dist/index.d.ts +3 -5
  167. package/dist/tailwind/dist/purger/legacy/purgeCSS.cjs +3 -4
  168. package/dist/tailwind/dist/purger/legacy/purgeCSS.js +3 -4
  169. package/dist/tailwind/dist/purger/optimized/ast/expressions.cjs +125 -122
  170. package/dist/tailwind/dist/purger/optimized/ast/expressions.js +125 -122
  171. package/dist/tailwind/dist/purger/optimized/ast/jsx.cjs +8 -1
  172. package/dist/tailwind/dist/purger/optimized/ast/jsx.js +8 -1
  173. package/dist/tailwind/dist/purger/optimized/purge.cjs +10 -11
  174. package/dist/tailwind/dist/purger/optimized/purge.js +9 -10
  175. package/dist/tailwind/dist/purger/optimized/purgeFromCode.cjs +127 -232
  176. package/dist/tailwind/dist/purger/optimized/purgeFromCode.js +127 -232
  177. package/dist/tailwind/dist/purger/optimized/utils/componentAnalyzer.cjs +262 -330
  178. package/dist/tailwind/dist/purger/optimized/utils/componentAnalyzer.js +262 -329
  179. package/dist/tailwind/dist/purger/optimized/utils/files.cjs +3 -4
  180. package/dist/tailwind/dist/purger/optimized/utils/files.js +3 -4
  181. package/dist/tailwind/dist/purger/optimized/utils/safelist.cjs +21 -13
  182. package/dist/tailwind/dist/purger/optimized/utils/safelist.js +21 -13
  183. package/dist/tailwind/dist/tailwind/plugins/components.cjs +2 -0
  184. package/dist/tailwind/dist/tailwind/plugins/components.js +3 -1
  185. package/dist/tailwind/dist/tailwind/plugins/typography.cjs +13 -41
  186. package/dist/tailwind/dist/tailwind/plugins/typography.js +13 -41
  187. package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.cjs +2 -4
  188. package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.d.cts +1 -10
  189. package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.d.ts +1 -10
  190. package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.js +2 -4
  191. package/dist/tailwind/dist/utils/tsMorph.cjs +1 -1
  192. package/dist/tokens/automation/configs/index.cjs +2 -0
  193. package/dist/tokens/automation/configs/index.d.cts +2 -2
  194. package/dist/tokens/automation/configs/index.d.ts +2 -2
  195. package/dist/tokens/automation/configs/index.js +2 -2
  196. package/dist/tokens/automation/index.cjs +2 -0
  197. package/dist/tokens/automation/index.d.cts +2 -2
  198. package/dist/tokens/automation/index.d.ts +2 -2
  199. package/dist/tokens/automation/index.js +2 -2
  200. package/dist/tokens/index.cjs +2 -0
  201. package/dist/tokens/index.d.cts +3 -3
  202. package/dist/tokens/index.d.ts +3 -3
  203. package/dist/tokens/index.js +2 -2
  204. package/dist/tokens/types.d.cts +2 -2
  205. package/dist/tokens/types.d.ts +2 -2
  206. package/dist/types/dist/index.d.cts +76 -1
  207. package/dist/types/dist/index.d.ts +76 -1
  208. package/dist/uds/generated/componentData.cjs +1187 -961
  209. package/dist/uds/generated/componentData.js +1111 -939
  210. package/dist/uds/generated/tailwindPurge.cjs +57 -29
  211. package/dist/uds/generated/tailwindPurge.js +57 -29
  212. package/dist/uds/package.cjs +4 -10
  213. package/dist/uds/package.js +4 -10
  214. package/package.json +4 -7
  215. package/dist/cli/dist/lib/logger.cjs +0 -66
  216. package/dist/cli/dist/lib/logger.js +0 -66
  217. package/dist/tailwind/dist/commands/css.cjs +0 -79
  218. package/dist/tailwind/dist/commands/css.d.ts +0 -3
  219. package/dist/tailwind/dist/commands/css.helpers.cjs +0 -32
  220. package/dist/tailwind/dist/commands/css.helpers.js +0 -28
  221. package/dist/tailwind/dist/commands/css.js +0 -79
  222. package/dist/tailwind/dist/css/generate.cjs +0 -120
  223. package/dist/tailwind/dist/css/generate.d.cts +0 -30
  224. package/dist/tailwind/dist/css/generate.d.ts +0 -31
  225. package/dist/tailwind/dist/css/generate.helpers.cjs +0 -112
  226. package/dist/tailwind/dist/css/generate.helpers.js +0 -100
  227. package/dist/tailwind/dist/css/generate.js +0 -115
  228. package/dist/tailwind/dist/css/postcss.cjs +0 -35
  229. package/dist/tailwind/dist/css/postcss.helpers.cjs +0 -27
  230. package/dist/tailwind/dist/css/postcss.helpers.js +0 -26
  231. package/dist/tailwind/dist/css/postcss.js +0 -35
  232. package/dist/tailwind/dist/css/runner.cjs +0 -278
  233. package/dist/tailwind/dist/css/runner.helpers.cjs +0 -26
  234. package/dist/tailwind/dist/css/runner.helpers.js +0 -23
  235. package/dist/tailwind/dist/css/runner.js +0 -275
  236. package/dist/tailwind/dist/css/theme.cjs +0 -12
  237. package/dist/tailwind/dist/css/theme.d.cts +0 -66
  238. package/dist/tailwind/dist/css/theme.d.ts +0 -66
  239. package/dist/tailwind/dist/css/theme.js +0 -11
  240. package/dist/tailwind/dist/css/utils.cjs +0 -234
  241. package/dist/tailwind/dist/css/utils.js +0 -223
  242. package/dist/tailwind/dist/utils/optimizeCSS.cjs +0 -405
  243. package/dist/tailwind/dist/utils/optimizeCSS.js +0 -403
  244. package/dist/tailwind/dist/utils/postcssPreserveVars.cjs +0 -67
  245. package/dist/tailwind/dist/utils/postcssPreserveVars.js +0 -65
  246. package/generated/componentData.json +0 -2397
  247. package/generated/tailwindPurge.ts +0 -4560
@@ -8,20 +8,20 @@ import { Node, Project, SyntaxKind, ts } from "ts-morph";
8
8
  /**
9
9
  * Get component info with all its dependencies (using pre-generated data)
10
10
  */
11
- const getComponentWithDeps = (componentName) => {
11
+ function getComponentWithDeps(componentName) {
12
12
  const visited = /* @__PURE__ */ new Set();
13
13
  const result = [];
14
- const collect = (name) => {
14
+ function collect(name) {
15
15
  if (visited.has(name)) return;
16
16
  visited.add(name);
17
- const info = resolveComponentInfo(name);
17
+ const info = componentCache[name];
18
18
  if (!info) return;
19
19
  result.push(info);
20
- info.internalComponents.forEach((depName) => collect(depName));
21
- };
20
+ for (const depName of info.internalComponents) collect(depName);
21
+ }
22
22
  collect(componentName);
23
23
  return result;
24
- };
24
+ }
25
25
  /**
26
26
  * Auto-variants lookup (loaded at module init)
27
27
  */
@@ -30,96 +30,10 @@ let autoVariantsCache = null;
30
30
  * Pre-generated component data (loaded at module init)
31
31
  */
32
32
  let componentCache = null;
33
- /**
34
- * Map of normalized component name -> actual component cache key
35
- * Useful when internal components are imported without namespace separators
36
- * (e.g., MenuItemBase vs Menu.ItemBase).
37
- */
38
- let componentNameLookup = null;
39
- const buildComponentNameLookup = (data) => {
40
- const lookup = {};
41
- Object.keys(data).forEach((key) => {
42
- const normalized = normalizeComponentName(key);
43
- if (!lookup[normalized]) lookup[normalized] = key;
44
- });
45
- return lookup;
46
- };
47
- const resolveComponentInfo = (name) => {
48
- if (componentCache && componentCache[name]) return componentCache[name];
49
- const normalized = normalizeComponentName(name);
50
- const mappedName = componentNameLookup?.[normalized];
51
- if (mappedName && componentCache) return componentCache[mappedName];
52
- };
53
- const getModuleSpecifierValue = (importDecl) => {
54
- return importDecl.getModuleSpecifierValue() ?? importDecl.getModuleSpecifier().getText().replace(/^['"]|['"]$/g, "");
55
- };
56
- const isUdsComponentModule = (moduleSpecifier) => {
57
- const cleaned = moduleSpecifier.replace(/^['"]|['"]$/g, "");
58
- return cleaned === "@yahoo/uds" || cleaned.startsWith("@yahoo/uds/");
59
- };
60
- /**
61
- * Normalize component name to match autoVariants keys (lower camel, no punctuation).
62
- */
63
- const normalizeComponentName = (name) => {
64
- const cleaned = name.replace(/\W/g, "");
65
- return cleaned.charAt(0).toLowerCase() + cleaned.slice(1);
66
- };
67
- /**
68
- * Fallback: infer prop -> variant key mapping from autoVariants when the
69
- * generated component data misses it (e.g., helpers like buildAvatarRootClasses).
70
- */
71
- const getAutoVariantKeysForProp = (componentName, propName) => {
72
- if (!autoVariantsCache) return [];
73
- const segments = componentName.match(/[A-Z][a-z0-9]*/g) ?? [];
74
- const candidates = new Set([normalizeComponentName(componentName)]);
75
- if (segments.length > 0) Array.from({ length: segments.length }, (_, index) => index + 1).forEach((i) => {
76
- const partial = segments.slice(0, i).join("");
77
- candidates.add(normalizeComponentName(partial));
78
- });
79
- const propLower = propName.toLowerCase();
80
- return Object.keys(autoVariantsCache).filter((key) => {
81
- const keyLower = key.toLowerCase();
82
- return Array.from(candidates).some((candidate) => keyLower.startsWith(candidate) && keyLower.includes(propLower));
83
- });
84
- };
85
- const getVariantKeysForProp = (componentInfo, propName) => {
86
- const keys = new Set(componentInfo.propToVariantKeys?.[propName] ?? []);
87
- getAutoVariantKeysForProp(componentInfo.name, propName).forEach((inferred) => keys.add(inferred));
88
- return [...keys];
89
- };
90
- const extractClassNamePrimitives = (sourceFile) => {
91
- const classes = [];
92
- sourceFile.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach((attr) => {
93
- if (attr.getNameNode().getText() !== "className") return;
94
- const initializer = attr.getInitializer();
95
- if (!initializer) return;
96
- const values = [];
97
- if (Node.isStringLiteral(initializer)) values.push(initializer.getLiteralText());
98
- else if (Node.isJsxExpression(initializer)) {
99
- const expr = initializer.getExpression();
100
- if (expr) values.push(...extractStringLiterals(expr));
101
- }
102
- values.forEach((raw) => {
103
- classes.push(...raw.split(/\s+/).filter(Boolean));
104
- });
105
- });
106
- sourceFile.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach((prop) => {
107
- if (prop.getName() !== "className") return;
108
- const initializer = prop.getInitializer();
109
- if (!initializer) return;
110
- extractStringLiterals(initializer).forEach((raw) => {
111
- classes.push(...raw.split(/\s+/).filter(Boolean));
112
- });
113
- });
114
- return classes;
115
- };
116
- const purgeFromCodeOptimized = async (code, options) => {
33
+ async function purgeFromCodeOptimized(code, options) {
117
34
  const { variants, autoVariants, componentData } = options;
118
35
  if (!autoVariantsCache) autoVariantsCache = autoVariants;
119
- if (!componentCache) {
120
- componentCache = componentData;
121
- componentNameLookup = buildComponentNameLookup(componentData);
122
- }
36
+ if (!componentCache) componentCache = componentData;
123
37
  const startTime = performance.now();
124
38
  const sourceFile = new Project({ useInMemoryFileSystem: true }).createSourceFile("input.tsx", code);
125
39
  const stats = {
@@ -130,120 +44,105 @@ const purgeFromCodeOptimized = async (code, options) => {
130
44
  expressionsResolved: 0
131
45
  };
132
46
  const imports = [];
133
- sourceFile.getImportDeclarations().forEach((importDecl) => {
134
- if (isUdsComponentModule(getModuleSpecifierValue(importDecl))) importDecl.getNamedImports().forEach((namedImport) => imports.push(namedImport.getName()));
135
- });
47
+ for (const importDecl of sourceFile.getImportDeclarations()) if (importDecl.getModuleSpecifier().getText().includes("@yahoo/uds")) for (const namedImport of importDecl.getNamedImports()) imports.push(namedImport.getName());
136
48
  const componentProps = /* @__PURE__ */ new Map();
137
- const referencedComponents = /* @__PURE__ */ new Set();
138
49
  const getStylesProps = extractGetStylesCalls(sourceFile, stats, variants);
139
- imports.forEach((imp) => {
140
- findComponentReferences(sourceFile, imp).forEach((reference) => {
141
- const componentName = reference.getTagNameNode().getText() || imp;
142
- referencedComponents.add(componentName);
143
- const propsMap = componentProps.get(componentName) ?? /* @__PURE__ */ new Map();
144
- extractPropsFromReference(reference, stats, sourceFile).forEach(([propName, values]) => {
145
- if (values.length > 0) {
146
- const existing = propsMap.get(propName) ?? /* @__PURE__ */ new Set();
147
- values.forEach((val) => existing.add(val));
148
- propsMap.set(propName, existing);
149
- }
150
- });
151
- componentProps.set(componentName, propsMap);
152
- });
153
- if (!componentProps.has(imp)) componentProps.set(imp, /* @__PURE__ */ new Map());
154
- });
50
+ for (const imp of imports) {
51
+ const references = findComponentReferences(sourceFile, imp);
52
+ const propsMap = componentProps.get(imp) ?? /* @__PURE__ */ new Map();
53
+ for (const reference of references) {
54
+ const props = extractPropsFromReference(reference, stats, sourceFile);
55
+ for (const [propName, values] of props) if (values.length > 0) {
56
+ const existing = propsMap.get(propName) ?? /* @__PURE__ */ new Set();
57
+ for (const val of values) existing.add(val);
58
+ propsMap.set(propName, existing);
59
+ }
60
+ }
61
+ componentProps.set(imp, propsMap);
62
+ }
155
63
  const allComponents = [];
156
64
  const seenComponents = /* @__PURE__ */ new Set();
157
- new Set([...imports, ...referencedComponents]).forEach((componentName) => {
158
- getComponentWithDeps(componentName).forEach((comp) => {
159
- if (!seenComponents.has(comp.name)) {
160
- seenComponents.add(comp.name);
161
- allComponents.push(comp);
162
- }
163
- });
164
- });
65
+ for (const componentName of imports) {
66
+ const componentsWithDeps = getComponentWithDeps(componentName);
67
+ for (const comp of componentsWithDeps) if (!seenComponents.has(comp.name)) {
68
+ seenComponents.add(comp.name);
69
+ allComponents.push(comp);
70
+ }
71
+ }
165
72
  const safelist = [];
166
- [...getStylesProps.entries()].forEach(([propName, values]) => {
73
+ for (const [propName, values] of getStylesProps) {
167
74
  const variantGroup = variants[propName];
168
- if (variantGroup) values.forEach((value) => {
75
+ if (variantGroup) for (const value of values) {
169
76
  const cls = variantGroup[value];
170
77
  if (cls) safelist.push(cls.replaceAll("\\", ""));
171
- });
172
- });
173
- allComponents.forEach((componentInfo) => {
78
+ }
79
+ }
80
+ for (const componentInfo of allComponents) {
174
81
  const userProps = componentProps.get(componentInfo.name) ?? /* @__PURE__ */ new Map();
175
- Object.entries(componentInfo.defaultProps).forEach(([propName, propValue]) => {
176
- if (userProps.has(propName)) return;
82
+ for (const [propName, propValue] of Object.entries(componentInfo.defaultProps)) {
83
+ if (userProps.has(propName)) continue;
177
84
  const variantGroup = variants[propName];
178
85
  if (variantGroup) {
179
86
  const cls = variantGroup[propValue];
180
87
  if (cls) safelist.push(cls.replaceAll("\\", ""));
181
88
  }
182
- const variantKeys = getVariantKeysForProp(componentInfo, propName);
183
- if (variantKeys.length > 0) variantKeys.forEach((variantKey) => {
184
- const mappedVariantGroup = variants[variantKey] ?? autoVariantsCache[variantKey];
89
+ const variantKeys = componentInfo.propToVariantKeys?.[propName];
90
+ if (variantKeys) for (const variantKey of variantKeys) {
91
+ const mappedVariantGroup = variants[variantKey];
185
92
  if (mappedVariantGroup) {
186
93
  const cls = mappedVariantGroup[propValue];
187
94
  if (cls) safelist.push(cls.replaceAll("\\", ""));
188
95
  }
189
- });
190
- });
191
- Object.entries(componentInfo.getStylesLiterals).forEach(([propName, propValue]) => {
96
+ }
97
+ }
98
+ for (const [propName, propValue] of Object.entries(componentInfo.getStylesLiterals)) {
192
99
  const variantGroup = variants[propName.replace(/:\d+$/, "")];
193
100
  if (variantGroup) {
194
101
  const cls = variantGroup[propValue];
195
102
  if (cls) safelist.push(cls.replaceAll("\\", ""));
196
103
  }
197
- });
198
- if (componentInfo.cxLiterals) componentInfo.cxLiterals.forEach((cls) => safelist.push(cls));
104
+ }
105
+ if (componentInfo.cxLiterals) for (const cls of componentInfo.cxLiterals) safelist.push(cls);
199
106
  if (componentInfo.propToVariantKeys) {
200
107
  const componentDefaults = options.variantDefaults?.[componentInfo.name] ?? {};
201
- Object.keys(componentInfo.propToVariantKeys).forEach((propName) => {
202
- if (userProps.has(propName)) return;
108
+ for (const [propName, variantKeys] of Object.entries(componentInfo.propToVariantKeys)) {
109
+ if (userProps.has(propName)) continue;
203
110
  const defaultValue = componentDefaults[propName];
204
- getVariantKeysForProp(componentInfo, propName).forEach((variantKey) => {
111
+ for (const variantKey of variantKeys) {
205
112
  const variantGroup = autoVariantsCache[variantKey];
206
113
  if (variantGroup) {
207
114
  if (variantGroup["default"]) safelist.push(variantGroup["default"]);
208
115
  if (defaultValue && variantGroup[defaultValue]) safelist.push(variantGroup[defaultValue]);
209
116
  }
210
- });
211
- });
117
+ }
118
+ }
212
119
  }
213
- Object.entries(componentInfo.internalComponentProps).forEach(([_internalCompName, propsRecord]) => {
214
- Object.entries(propsRecord).forEach(([propName, propValues]) => {
215
- const variantGroup = variants[propName];
216
- if (variantGroup) propValues.forEach((propValue) => {
217
- const cls = variantGroup[propValue];
218
- if (cls) safelist.push(cls.replaceAll("\\", ""));
219
- });
220
- });
221
- });
222
- [...userProps.entries()].forEach(([propName, usedValues]) => {
223
- if (propName === "className") {
224
- [...usedValues].forEach((value) => {
225
- value.split(/\s+/).filter(Boolean).forEach((cls) => safelist.push(cls));
226
- });
227
- return;
120
+ for (const [_internalCompName, propsRecord] of Object.entries(componentInfo.internalComponentProps)) for (const [propName, propValues] of Object.entries(propsRecord)) {
121
+ const variantGroup = variants[propName];
122
+ if (variantGroup) for (const propValue of propValues) {
123
+ const cls = variantGroup[propValue];
124
+ if (cls) safelist.push(cls.replaceAll("\\", ""));
228
125
  }
126
+ }
127
+ for (const [propName, usedValues] of userProps) {
229
128
  const variantGroup = variants[propName];
230
- if (variantGroup) [...usedValues].forEach((value) => {
129
+ if (variantGroup) for (const value of usedValues) {
231
130
  const cls = variantGroup[value];
232
131
  if (cls) safelist.push(cls.replaceAll("\\", ""));
233
- });
234
- [componentInfo, ...getComponentWithDeps(componentInfo.name).slice(1)].forEach((comp) => {
235
- const variantKeys = getVariantKeysForProp(comp, propName);
236
- if (variantKeys.length > 0) variantKeys.forEach((variantKey) => {
132
+ }
133
+ const componentsToCheck = [componentInfo, ...getComponentWithDeps(componentInfo.name).slice(1)];
134
+ for (const comp of componentsToCheck) {
135
+ const variantKeys = comp.propToVariantKeys?.[propName];
136
+ if (variantKeys) for (const variantKey of variantKeys) {
237
137
  const mappedVariantGroup = variants[variantKey];
238
- if (mappedVariantGroup) [...usedValues].forEach((value) => {
138
+ if (mappedVariantGroup) for (const value of usedValues) {
239
139
  const cls = mappedVariantGroup[value];
240
140
  if (cls) safelist.push(cls.replaceAll("\\", ""));
241
- });
242
- });
243
- });
244
- });
245
- });
246
- if (options.includeAllClassNamePrimitives) safelist.push(...extractClassNamePrimitives(sourceFile));
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
247
146
  const finalSafelist = [...new Set(safelist)];
248
147
  stats.timeMs = Math.round(performance.now() - startTime);
249
148
  stats.classesGenerated = finalSafelist.length;
@@ -253,29 +152,28 @@ const purgeFromCodeOptimized = async (code, options) => {
253
152
  components: [...seenComponents],
254
153
  stats
255
154
  };
256
- };
155
+ }
257
156
  /**
258
157
  * Find JSX references for a component in the source file
259
158
  */
260
- const findComponentReferences = (sourceFile, componentName) => {
159
+ function findComponentReferences(sourceFile, componentName) {
261
160
  const references = [];
262
- sourceFile.getImportDeclarations().forEach((importDecl) => {
263
- if (!isUdsComponentModule(getModuleSpecifierValue(importDecl))) return;
264
- importDecl.getNamedImports().forEach((namedImport) => {
265
- if (namedImport.getName() === componentName) {
266
- const identifier = namedImport.getFirstDescendantByKindOrThrow(ts.SyntaxKind.Identifier);
267
- references.push(...findJsxReferences(identifier));
268
- }
269
- });
270
- });
161
+ for (const importDecl of sourceFile.getImportDeclarations()) {
162
+ if (!importDecl.getModuleSpecifier().getText().includes("@yahoo/uds")) continue;
163
+ for (const namedImport of importDecl.getNamedImports()) if (namedImport.getName() === componentName) {
164
+ const identifier = namedImport.getFirstDescendantByKindOrThrow(ts.SyntaxKind.Identifier);
165
+ references.push(...findJsxReferences(identifier));
166
+ }
167
+ }
271
168
  return references;
272
- };
169
+ }
273
170
  /**
274
171
  * Extract props from a JSX reference.
275
172
  */
276
- const extractPropsFromReference = (reference, stats, sourceFile) => {
173
+ function extractPropsFromReference(reference, stats, sourceFile) {
277
174
  const props = [];
278
- reference.getAttributes().forEach((attr) => {
175
+ const attributes = reference.getAttributes();
176
+ for (const attr of attributes) {
279
177
  if (attr.asKind(SyntaxKind.JsxAttribute)) {
280
178
  const jsxAttr = attr.asKindOrThrow(SyntaxKind.JsxAttribute);
281
179
  const propName = jsxAttr.getNameNode().getText();
@@ -296,17 +194,16 @@ const extractPropsFromReference = (reference, stats, sourceFile) => {
296
194
  }
297
195
  if (attr.asKind(SyntaxKind.JsxSpreadAttribute)) {
298
196
  stats.spreadsTraced++;
299
- traceSpreadInFile(attr.asKindOrThrow(SyntaxKind.JsxSpreadAttribute).getExpression().getText(), sourceFile).forEach(([propName, values]) => {
300
- if (values.length > 0) props.push([propName, values]);
301
- });
197
+ const resolvedSpreadProps = traceSpreadInFile(attr.asKindOrThrow(SyntaxKind.JsxSpreadAttribute).getExpression().getText(), sourceFile);
198
+ for (const [propName, values] of resolvedSpreadProps) if (values.length > 0) props.push([propName, values]);
302
199
  }
303
- });
200
+ }
304
201
  return props;
305
- };
202
+ }
306
203
  /**
307
204
  * Trace spread props to their source within the same file.
308
205
  */
309
- const traceSpreadInFile = (spreadName, sourceFile) => {
206
+ function traceSpreadInFile(spreadName, sourceFile) {
310
207
  const props = [];
311
208
  const varDecl = sourceFile.getVariableDeclaration(spreadName);
312
209
  if (!varDecl) return props;
@@ -314,64 +211,62 @@ const traceSpreadInFile = (spreadName, sourceFile) => {
314
211
  if (!initializer) return props;
315
212
  const objLiteral = initializer.asKind(SyntaxKind.ObjectLiteralExpression) ? initializer.asKindOrThrow(SyntaxKind.ObjectLiteralExpression) : initializer.asKind(SyntaxKind.AsExpression) ? initializer.asKindOrThrow(SyntaxKind.AsExpression).getExpression().asKind(SyntaxKind.ObjectLiteralExpression) ? initializer.asKindOrThrow(SyntaxKind.AsExpression).getExpression().asKindOrThrow(SyntaxKind.ObjectLiteralExpression) : null : null;
316
213
  if (!objLiteral) return props;
317
- objLiteral.getProperties().forEach((prop) => {
318
- if (prop.asKind(SyntaxKind.PropertyAssignment)) {
319
- const propAssign = prop.asKindOrThrow(SyntaxKind.PropertyAssignment);
320
- const propName = propAssign.getName();
321
- const propInit = propAssign.getInitializer();
322
- if (propInit) {
323
- const values = extractStringLiterals(propInit);
324
- if (values.length > 0) props.push([propName, values]);
325
- }
214
+ for (const prop of objLiteral.getProperties()) if (prop.asKind(SyntaxKind.PropertyAssignment)) {
215
+ const propAssign = prop.asKindOrThrow(SyntaxKind.PropertyAssignment);
216
+ const propName = propAssign.getName();
217
+ const propInit = propAssign.getInitializer();
218
+ if (propInit) {
219
+ const values = extractStringLiterals(propInit);
220
+ if (values.length > 0) props.push([propName, values]);
326
221
  }
327
- });
222
+ }
328
223
  return props;
329
- };
224
+ }
330
225
  /**
331
226
  * Extract props from getStyles() calls in user code.
332
227
  * This handles cases like:
333
228
  * const styles = getStyles({ backgroundColor: 'brand', spacing: '4' });
334
229
  */
335
- const extractGetStylesCalls = (sourceFile, stats, variants) => {
230
+ function extractGetStylesCalls(sourceFile, stats, variants) {
336
231
  const props = /* @__PURE__ */ new Map();
337
232
  const VALID_VARIANTS = new Set(Object.keys(variants));
338
- sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).forEach((call) => {
339
- if (call.getExpression().getText() !== "getStyles") return;
233
+ const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression);
234
+ for (const call of callExpressions) {
235
+ if (call.getExpression().getText() !== "getStyles") continue;
340
236
  const args = call.getArguments();
341
- if (args.length === 0) return;
237
+ if (args.length === 0) continue;
342
238
  const firstArg = args[0];
343
- if (!firstArg.asKind(SyntaxKind.ObjectLiteralExpression)) return;
344
- firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression).getProperties().forEach((prop) => {
345
- if (prop.asKind(SyntaxKind.PropertyAssignment)) {
346
- const propAssign = prop.asKindOrThrow(SyntaxKind.PropertyAssignment);
347
- const propName = propAssign.getName();
348
- const propInit = propAssign.getInitializer();
349
- if (propInit && VALID_VARIANTS.has(propName)) {
350
- const values = extractStringLiterals(propInit);
351
- if (values.length > 0) {
352
- const existing = props.get(propName) ?? /* @__PURE__ */ new Set();
353
- values.forEach((v) => existing.add(v));
354
- props.set(propName, existing);
355
- stats.expressionsResolved++;
356
- }
239
+ if (!firstArg.asKind(SyntaxKind.ObjectLiteralExpression)) continue;
240
+ const objLiteral = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);
241
+ for (const prop of objLiteral.getProperties()) if (prop.asKind(SyntaxKind.PropertyAssignment)) {
242
+ const propAssign = prop.asKindOrThrow(SyntaxKind.PropertyAssignment);
243
+ const propName = propAssign.getName();
244
+ const propInit = propAssign.getInitializer();
245
+ if (propInit && VALID_VARIANTS.has(propName)) {
246
+ const values = extractStringLiterals(propInit);
247
+ if (values.length > 0) {
248
+ const existing = props.get(propName) ?? /* @__PURE__ */ new Set();
249
+ for (const v of values) existing.add(v);
250
+ props.set(propName, existing);
251
+ stats.expressionsResolved++;
357
252
  }
358
- } else if (prop.asKind(SyntaxKind.ShorthandPropertyAssignment)) {
359
- const shorthand = prop.asKindOrThrow(SyntaxKind.ShorthandPropertyAssignment);
360
- const propName = shorthand.getName();
361
- if (VALID_VARIANTS.has(propName)) {
362
- const values = extractStringLiterals(shorthand.getNameNode());
363
- if (values.length > 0) {
364
- const existing = props.get(propName) ?? /* @__PURE__ */ new Set();
365
- values.forEach((v) => existing.add(v));
366
- props.set(propName, existing);
367
- stats.expressionsResolved++;
368
- }
253
+ }
254
+ } else if (prop.asKind(SyntaxKind.ShorthandPropertyAssignment)) {
255
+ const shorthand = prop.asKindOrThrow(SyntaxKind.ShorthandPropertyAssignment);
256
+ const propName = shorthand.getName();
257
+ if (VALID_VARIANTS.has(propName)) {
258
+ const values = extractStringLiterals(shorthand.getNameNode());
259
+ if (values.length > 0) {
260
+ const existing = props.get(propName) ?? /* @__PURE__ */ new Set();
261
+ for (const v of values) existing.add(v);
262
+ props.set(propName, existing);
263
+ stats.expressionsResolved++;
369
264
  }
370
265
  }
371
- });
372
- });
266
+ }
267
+ }
373
268
  return props;
374
- };
269
+ }
375
270
 
376
271
  //#endregion
377
272
  export { purgeFromCodeOptimized };