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