@yahoo/uds 3.133.3 → 3.134.1
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 +14 -0
- package/dist/automated-config/dist/generated/autoVariants.d.cts +14 -0
- package/dist/automated-config/dist/generated/autoVariants.d.ts +14 -0
- package/dist/automated-config/dist/generated/autoVariants.js +14 -0
- package/dist/automated-config/dist/generated/generatedConfigs.cjs +2796 -1
- package/dist/automated-config/dist/generated/generatedConfigs.d.cts +288 -2
- package/dist/automated-config/dist/generated/generatedConfigs.d.ts +288 -2
- package/dist/automated-config/dist/generated/generatedConfigs.js +2796 -2
- package/dist/automated-config/dist/generated/universalTokensConfigAuto.cjs +119 -0
- package/dist/automated-config/dist/generated/universalTokensConfigAuto.d.cts +2 -1
- package/dist/automated-config/dist/generated/universalTokensConfigAuto.d.ts +2 -1
- package/dist/automated-config/dist/generated/universalTokensConfigAuto.js +119 -0
- package/dist/automated-config/dist/properties.cjs +15 -1
- package/dist/automated-config/dist/properties.d.cts +4 -0
- package/dist/automated-config/dist/properties.d.ts +4 -0
- package/dist/automated-config/dist/properties.js +15 -1
- 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 +4 -0
- package/dist/cli/commands/sync.js +4 -0
- package/dist/cli/dist/lib/args.cjs +7 -3
- package/dist/cli/dist/lib/args.js +7 -3
- 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/Modal/Modal.cjs +193 -0
- package/dist/components/client/Modal/Modal.d.cts +51 -0
- package/dist/components/client/Modal/Modal.d.ts +52 -0
- package/dist/components/client/Modal/Modal.js +191 -0
- package/dist/components/client/Modal/ModalActions.cjs +54 -0
- package/dist/components/client/Modal/ModalActions.d.cts +27 -0
- package/dist/components/client/Modal/ModalActions.d.ts +28 -0
- package/dist/components/client/Modal/ModalActions.js +52 -0
- package/dist/components/client/Modal/ModalContent.cjs +37 -0
- package/dist/components/client/Modal/ModalContent.d.cts +24 -0
- package/dist/components/client/Modal/ModalContent.d.ts +25 -0
- package/dist/components/client/Modal/ModalContent.js +35 -0
- package/dist/components/client/Modal/ModalContext.cjs +15 -0
- package/dist/components/client/Modal/ModalContext.d.cts +13 -0
- package/dist/components/client/Modal/ModalContext.d.ts +14 -0
- package/dist/components/client/Modal/ModalContext.js +12 -0
- package/dist/components/client/Modal/ModalDescription.cjs +29 -0
- package/dist/components/client/Modal/ModalDescription.d.cts +23 -0
- package/dist/components/client/Modal/ModalDescription.d.ts +24 -0
- package/dist/components/client/Modal/ModalDescription.js +27 -0
- package/dist/components/client/Modal/ModalTitle.cjs +29 -0
- package/dist/components/client/Modal/ModalTitle.d.cts +23 -0
- package/dist/components/client/Modal/ModalTitle.d.ts +24 -0
- package/dist/components/client/Modal/ModalTitle.js +27 -0
- package/dist/components/client/Modal/UDSModalConfigProvider.cjs +42 -0
- package/dist/components/client/Modal/UDSModalConfigProvider.d.cts +35 -0
- package/dist/components/client/Modal/UDSModalConfigProvider.d.ts +36 -0
- package/dist/components/client/Modal/UDSModalConfigProvider.js +39 -0
- package/dist/components/client/Modal/index.cjs +16 -0
- package/dist/components/client/Modal/index.d.cts +8 -0
- package/dist/components/client/Modal/index.d.ts +9 -0
- package/dist/components/client/Modal/index.js +9 -0
- package/dist/components/client/Modal/useScrollFade.cjs +38 -0
- package/dist/components/client/Modal/useScrollFade.d.cts +13 -0
- package/dist/components/client/Modal/useScrollFade.d.ts +14 -0
- package/dist/components/client/Modal/useScrollFade.js +36 -0
- package/dist/components/client/Modal/utils.cjs +32 -0
- package/dist/components/client/Modal/utils.d.cts +13 -0
- package/dist/components/client/Modal/utils.d.ts +14 -0
- package/dist/components/client/Modal/utils.js +30 -0
- package/dist/components/client/Popover/index.d.cts +1 -1
- package/dist/components/client/Popover/index.d.ts +1 -1
- package/dist/components/client/Toast/UDSToastConfigProvider.d.cts +1 -1
- package/dist/components/client/Toast/UDSToastConfigProvider.d.ts +1 -1
- package/dist/components/client/index.cjs +13 -0
- package/dist/components/client/index.d.cts +8 -2
- package/dist/components/client/index.d.ts +8 -2
- package/dist/components/client/index.js +7 -1
- package/dist/components/client/providers/UDSConfigProvider.cjs +6 -2
- package/dist/components/client/providers/UDSConfigProvider.d.cts +2 -1
- package/dist/components/client/providers/UDSConfigProvider.d.ts +2 -1
- package/dist/components/client/providers/UDSConfigProvider.js +6 -2
- package/dist/components/experimental/client/index.cjs +0 -5
- package/dist/components/experimental/client/index.d.cts +1 -2
- package/dist/components/experimental/client/index.d.ts +1 -2
- package/dist/components/experimental/client/index.js +1 -2
- package/dist/components/experimental/index.cjs +1 -10
- package/dist/components/experimental/index.d.cts +1 -2
- package/dist/components/experimental/index.d.ts +1 -2
- package/dist/components/experimental/index.js +2 -7
- package/dist/components/index.cjs +20 -0
- package/dist/components/index.d.cts +8 -2
- package/dist/components/index.d.ts +8 -2
- package/dist/components/index.js +14 -1
- package/dist/config/dist/index.cjs +129 -4
- package/dist/config/dist/index.js +129 -4
- package/dist/index.cjs +16 -0
- package/dist/index.d.cts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +9 -2
- 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/modalConfig.cjs +22 -0
- package/dist/runtime/modalConfig.d.cts +22 -0
- package/dist/runtime/modalConfig.d.ts +22 -0
- package/dist/runtime/modalConfig.js +21 -0
- package/dist/runtime/udsConfig.cjs +4 -2
- package/dist/runtime/udsConfig.d.cts +2 -0
- package/dist/runtime/udsConfig.d.ts +2 -0
- package/dist/runtime/udsConfig.js +4 -2
- package/dist/styles/styler.d.cts +35 -21
- package/dist/styles/styler.d.ts +35 -21
- package/dist/styles/variants.d.cts +42 -0
- package/dist/styles/variants.d.ts +42 -0
- package/dist/tailwind/dist/automated-config/dist/generated/autoVariants.cjs +14 -0
- package/dist/tailwind/dist/automated-config/dist/generated/autoVariants.js +14 -0
- package/dist/tailwind/dist/automated-config/dist/generated/autoVariants.js.map +1 -1
- package/dist/tailwind/dist/automated-config/dist/generated/generatedConfigs.cjs +2796 -1
- package/dist/tailwind/dist/automated-config/dist/generated/generatedConfigs.js +2796 -2
- package/dist/tailwind/dist/automated-config/dist/generated/generatedConfigs.js.map +1 -1
- package/dist/tailwind/dist/automated-config/dist/properties.cjs +15 -1
- package/dist/tailwind/dist/automated-config/dist/properties.js +15 -1
- package/dist/tailwind/dist/automated-config/dist/properties.js.map +1 -1
- package/dist/tailwind/dist/commands/css.cjs +1 -0
- package/dist/tailwind/dist/commands/css.d.cts.map +1 -1
- package/dist/tailwind/dist/commands/css.d.ts.map +1 -1
- package/dist/tailwind/dist/commands/css.helpers.cjs +8 -1
- package/dist/tailwind/dist/commands/css.helpers.js +8 -1
- package/dist/tailwind/dist/commands/css.helpers.js.map +1 -1
- package/dist/tailwind/dist/commands/css.js +1 -0
- package/dist/tailwind/dist/commands/css.js.map +1 -1
- package/dist/tailwind/dist/config/dist/index.cjs +129 -4
- package/dist/tailwind/dist/config/dist/index.js +129 -4
- package/dist/tailwind/dist/config/dist/index.js.map +1 -1
- package/dist/tailwind/dist/css/generate.cjs +7 -4
- package/dist/tailwind/dist/css/generate.d.cts.map +1 -1
- package/dist/tailwind/dist/css/generate.d.ts.map +1 -1
- package/dist/tailwind/dist/css/generate.js +7 -4
- package/dist/tailwind/dist/css/generate.js.map +1 -1
- package/dist/tailwind/dist/css/nodeUtils.cjs +19 -8
- package/dist/tailwind/dist/css/nodeUtils.js +19 -8
- package/dist/tailwind/dist/css/nodeUtils.js.map +1 -1
- package/dist/tailwind/dist/css/perf.cjs +92 -0
- package/dist/tailwind/dist/css/perf.js +89 -0
- package/dist/tailwind/dist/css/perf.js.map +1 -0
- package/dist/tailwind/dist/css/purgeWorker.cjs +47 -0
- package/dist/tailwind/dist/css/purgeWorker.d.cts +2 -0
- package/dist/tailwind/dist/css/purgeWorker.d.ts +2 -0
- package/dist/tailwind/dist/css/purgeWorker.js +48 -0
- package/dist/tailwind/dist/css/purgeWorker.js.map +1 -0
- package/dist/tailwind/dist/css/runner.cjs +158 -145
- package/dist/tailwind/dist/css/runner.js +158 -145
- package/dist/tailwind/dist/css/runner.js.map +1 -1
- package/dist/tailwind/dist/css/utils.cjs +8 -0
- package/dist/tailwind/dist/css/utils.js +8 -0
- package/dist/tailwind/dist/css/utils.js.map +1 -1
- package/dist/tailwind/dist/css/workerPool.cjs +89 -0
- package/dist/tailwind/dist/css/workerPool.js +90 -0
- package/dist/tailwind/dist/css/workerPool.js.map +1 -0
- package/dist/tailwind/dist/purger/optimized/ast/expressions.cjs +95 -15
- package/dist/tailwind/dist/purger/optimized/ast/expressions.js +95 -15
- package/dist/tailwind/dist/purger/optimized/ast/expressions.js.map +1 -1
- package/dist/tailwind/dist/purger/optimized/purgeFromCode.cjs +38 -14
- package/dist/tailwind/dist/purger/optimized/purgeFromCode.d.cts.map +1 -1
- package/dist/tailwind/dist/purger/optimized/purgeFromCode.d.ts.map +1 -1
- package/dist/tailwind/dist/purger/optimized/purgeFromCode.js +39 -15
- package/dist/tailwind/dist/purger/optimized/purgeFromCode.js.map +1 -1
- package/dist/tailwind/dist/purger/optimized/types.d.cts +10 -0
- package/dist/tailwind/dist/purger/optimized/types.d.cts.map +1 -1
- package/dist/tailwind/dist/purger/optimized/types.d.ts +10 -0
- package/dist/tailwind/dist/purger/optimized/types.d.ts.map +1 -1
- package/dist/tailwind/dist/runtimeConfig/hookMetadata.cjs +34 -0
- package/dist/tailwind/dist/runtimeConfig/hookMetadata.js +34 -0
- package/dist/tailwind/dist/runtimeConfig/hookMetadata.js.map +1 -1
- package/dist/tailwind/dist/tailwind/plugins/blurBgFallback.cjs +3 -0
- package/dist/tailwind/dist/tailwind/plugins/blurBgFallback.js +3 -0
- package/dist/tailwind/dist/tailwind/plugins/blurBgFallback.js.map +1 -1
- package/dist/tailwind/dist/tailwind/plugins/components.cjs +1 -0
- package/dist/tailwind/dist/tailwind/plugins/components.js +2 -1
- package/dist/tailwind/dist/tailwind/plugins/components.js.map +1 -1
- package/dist/tailwind/dist/types/dist/index.d.cts.map +1 -1
- package/dist/tailwind/dist/types/dist/index.d.ts.map +1 -1
- package/dist/tokens/automation/configs/index.cjs +1 -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 +1 -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 +1 -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 +68 -2
- package/dist/types/dist/index.d.ts +68 -2
- package/dist/uds/generated/componentData.cjs +1024 -833
- package/dist/uds/generated/componentData.js +995 -840
- package/dist/uds/generated/tailwindPurge.cjs +137 -96
- package/dist/uds/generated/tailwindPurge.js +137 -96
- package/dist/utils/exposeAriakitScrollbarWidth.cjs +17 -0
- package/dist/utils/exposeAriakitScrollbarWidth.d.cts +13 -0
- package/dist/utils/exposeAriakitScrollbarWidth.d.ts +13 -0
- package/dist/utils/exposeAriakitScrollbarWidth.js +16 -0
- package/generated/componentData.json +1761 -1550
- package/generated/tailwindPurge.ts +4 -4
- package/package.json +1 -1
- package/dist/components/experimental/client/Modal.cjs +0 -60
- package/dist/components/experimental/client/Modal.d.cts +0 -27
- package/dist/components/experimental/client/Modal.d.ts +0 -28
- package/dist/components/experimental/client/Modal.js +0 -55
- package/dist/tailwind/dist/purger/optimized/ast/jsx.cjs +0 -16
- package/dist/tailwind/dist/purger/optimized/ast/jsx.js +0 -17
- package/dist/tailwind/dist/purger/optimized/ast/jsx.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/css/utils.ts"],"sourcesContent":["import { configurableProperties } from '@yahoo/uds-automated-config/properties';\nimport type { UniversalTokensConfig } from '@yahoo/uds-config';\n\nimport type { SerializedComponentInfo } from '../commands/generateComponentData';\nimport type { RuntimeConfigValues, VariantDefaults } from '../purger/optimized/purgeFromCode';\nimport {\n getRuntimeDefaultPropSelector,\n getRuntimeDefaultPropValue,\n getRuntimeFieldSelector,\n getRuntimeFieldStaticValue,\n getRuntimeFieldTokenValue,\n getRuntimeSelectorParamValues,\n} from '../runtimeConfig/hookMetadata';\n\n/**\n * Extract variant defaults from a UniversalTokensConfig.\n * Converts from config structure to a simpler lookup format.\n * e.g., { button: { defaults: { size: 'md' } } } -> { Button: { size: 'md' } }\n */\nconst extractVariantDefaults = (config: UniversalTokensConfig): VariantDefaults => {\n // Component names in config are lowercase, but we need PascalCase for matching\n const componentNameMap: Record<string, string> = {\n avatar: 'Avatar',\n badge: 'Badge',\n button: 'Button',\n checkbox: 'Checkbox',\n chip: 'Chip',\n divider: 'Divider',\n iconButton: 'IconButton',\n input: 'Input',\n link: 'Link',\n menu: 'Menu',\n radio: 'Radio',\n switch: 'Switch',\n tab: 'Tab',\n tabs: 'Tabs',\n };\n\n // Extract defaults from each component in the config\n return Object.entries(config).reduce<VariantDefaults>((acc, [configKey, componentConfig]) => {\n const pascalName = componentNameMap[configKey];\n if (!pascalName || !componentConfig || typeof componentConfig !== 'object') {\n return acc;\n }\n\n const configWithDefaults = componentConfig as { defaults?: Record<string, string> };\n return configWithDefaults.defaults\n ? { ...acc, [pascalName]: configWithDefaults.defaults }\n : acc;\n }, {});\n};\n\nconst extractRuntimeConfigValues = (config: UniversalTokensConfig): RuntimeConfigValues => {\n const values: RuntimeConfigValues = {};\n\n const setRuntimeValue = (\n selector: string | null,\n value: string | number | boolean | undefined,\n ) => {\n if (!selector || value === undefined) {\n return;\n }\n\n values[selector] = value;\n };\n\n const bottomSheetBackgroundColor = getRuntimeFieldTokenValue(\n config,\n 'useBottomSheetConfig',\n 'backgroundColor',\n { variant: 'default' },\n );\n\n if (bottomSheetBackgroundColor !== undefined) {\n setRuntimeValue(\n getRuntimeFieldSelector('useBottomSheetConfig', 'backgroundColor', { variant: 'default' }),\n bottomSheetBackgroundColor,\n );\n }\n\n if (config.toast?.variables && config.toast?.defaults) {\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'autoClose'),\n getRuntimeFieldStaticValue('useToastConfig', 'autoClose') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'position'),\n getRuntimeFieldStaticValue('useToastConfig', 'position') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeDefaultPropSelector('useToastConfig', 'size'),\n getRuntimeDefaultPropValue(config, 'useToastConfig', 'size'),\n );\n setRuntimeValue(\n getRuntimeDefaultPropSelector('useToastConfig', 'variant'),\n getRuntimeDefaultPropValue(config, 'useToastConfig', 'variant'),\n );\n\n getRuntimeSelectorParamValues('useToastConfig', 'size').forEach((size) => {\n const textVariant = getRuntimeFieldTokenValue(config, 'useToastConfig', 'textVariant', {\n size,\n });\n const iconSize = getRuntimeFieldTokenValue(config, 'useToastConfig', 'iconSize', { size });\n const buttonSize = getRuntimeFieldTokenValue(config, 'useToastConfig', 'buttonSize', {\n size,\n });\n\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'textVariant', { size }),\n textVariant,\n );\n setRuntimeValue(getRuntimeFieldSelector('useToastConfig', 'iconSize', { size }), iconSize);\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'buttonSize', { size }),\n buttonSize,\n );\n });\n\n getRuntimeSelectorParamValues('useToastConfig', 'variant').forEach((variant) => {\n const textColor = getRuntimeFieldTokenValue(config, 'useToastConfig', 'textColor', {\n variant,\n });\n const buttonVariant = getRuntimeFieldTokenValue(config, 'useToastConfig', 'buttonVariant', {\n variant,\n });\n const iconVariant = getRuntimeFieldTokenValue(config, 'useToastConfig', 'iconVariant', {\n variant,\n });\n const backgroundColor = getRuntimeFieldTokenValue(\n config,\n 'useToastConfig',\n 'backgroundColor',\n { variant },\n );\n\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'textColor', { variant }),\n textColor,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'buttonVariant', { variant }),\n buttonVariant,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'iconVariant', { variant }),\n iconVariant,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'backgroundColor', { variant }),\n backgroundColor,\n );\n });\n }\n\n const tooltipBorderRadius = getRuntimeFieldTokenValue(\n config,\n 'useTooltipConfig',\n 'borderRadius',\n {\n size: 'default',\n },\n );\n\n if (tooltipBorderRadius !== undefined) {\n setRuntimeValue(\n getRuntimeFieldSelector('useTooltipConfig', 'animationDuration'),\n getRuntimeFieldStaticValue('useTooltipConfig', 'animationDuration') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useTooltipConfig', 'placement'),\n getRuntimeFieldStaticValue('useTooltipConfig', 'placement') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useTooltipConfig', 'borderRadius', { size: 'default' }),\n tooltipBorderRadius,\n );\n }\n\n if (config.popover?.variables && config.scaleMode?.medium) {\n setRuntimeValue(\n getRuntimeDefaultPropSelector('usePopoverConfig', 'size'),\n getRuntimeDefaultPropValue(config, 'usePopoverConfig', 'size') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeDefaultPropSelector('usePopoverConfig', 'variant'),\n getRuntimeDefaultPropValue(config, 'usePopoverConfig', 'variant') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'animationDuration'),\n getRuntimeFieldStaticValue('usePopoverConfig', 'animationDuration') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'placement'),\n getRuntimeFieldStaticValue('usePopoverConfig', 'placement') ?? undefined,\n );\n\n getRuntimeSelectorParamValues('usePopoverConfig', 'size').forEach((size) => {\n const borderRadius = getRuntimeFieldTokenValue(config, 'usePopoverConfig', 'borderRadius', {\n size,\n });\n const gap = getRuntimeFieldTokenValue(config, 'usePopoverConfig', 'gap', { size });\n const spacingHorizontal = getRuntimeFieldTokenValue(\n config,\n 'usePopoverConfig',\n 'spacingHorizontal',\n { size },\n );\n const spacingVertical = getRuntimeFieldTokenValue(\n config,\n 'usePopoverConfig',\n 'spacingVertical',\n { size },\n );\n const dismissButtonSpacing = getRuntimeFieldTokenValue(\n config,\n 'usePopoverConfig',\n 'dismissButtonSpacing',\n { size },\n );\n const dismissIconSize = getRuntimeFieldTokenValue(\n config,\n 'usePopoverConfig',\n 'dismissIconSize',\n { size },\n );\n\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'borderRadius', { size }),\n borderRadius,\n );\n setRuntimeValue(getRuntimeFieldSelector('usePopoverConfig', 'gap', { size }), gap);\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'spacingHorizontal', { size }),\n spacingHorizontal,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'spacingVertical', { size }),\n spacingVertical,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'dismissButtonSpacing', { size }),\n dismissButtonSpacing,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'dismissIconSize', { size }),\n dismissIconSize,\n );\n });\n }\n\n return values;\n};\n\n/**\n * Format bytes to human readable string\n */\nconst formatBytes = (bytes: number): string => {\n if (bytes < 1024) {\n return `${bytes} B`;\n }\n const kb = bytes / 1024;\n if (kb < 1024) {\n return `${kb.toFixed(1)} KB`;\n }\n const mb = kb / 1024;\n return `${mb.toFixed(2)} MB`;\n};\n\n/**\n * Get motion CSS variable prefixes needed by a set of components.\n * Looks up motionVarPrefixes from componentData.json for each component.\n */\nconst getMotionVarPrefixes = (\n componentData: Record<string, SerializedComponentInfo>,\n components: string[],\n): string[] => {\n const prefixes = components.flatMap((componentName) => {\n const info = (componentData as Record<string, { motionVarPrefixes?: string[] }>)[componentName];\n return info?.motionVarPrefixes ?? [];\n });\n\n return [...new Set(prefixes)];\n};\n\n/**\n * Collect css variable names exposed by configurable properties.\n */\nconst getConfigurableCssVariables = (): string[] => {\n const udsVarPrefix = '--uds';\n const cssVars = Object.values(configurableProperties).flatMap(({ cssProperties }) => {\n if (typeof cssProperties === 'string') {\n return cssProperties.startsWith(udsVarPrefix) ? [cssProperties] : [];\n }\n\n if (Array.isArray(cssProperties)) {\n return cssProperties.filter(\n (cssProperty): cssProperty is string =>\n typeof cssProperty === 'string' && cssProperty.startsWith(udsVarPrefix),\n );\n }\n\n return [];\n });\n\n return [...new Set(['--uds-button-gap', ...cssVars])];\n};\n\nexport {\n extractRuntimeConfigValues,\n extractVariantDefaults,\n formatBytes,\n getConfigurableCssVariables,\n getMotionVarPrefixes,\n};\n"],"mappings":";;;;;;;;;AAmBA,MAAM,0BAA0B,WAAmD;CAEjF,MAAM,mBAA2C;EAC/C,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,UAAU;EACV,MAAM;EACN,SAAS;EACT,YAAY;EACZ,OAAO;EACP,MAAM;EACN,MAAM;EACN,OAAO;EACP,QAAQ;EACR,KAAK;EACL,MAAM;EACP;AAGD,QAAO,OAAO,QAAQ,OAAO,CAAC,QAAyB,KAAK,CAAC,WAAW,qBAAqB;EAC3F,MAAM,aAAa,iBAAiB;AACpC,MAAI,CAAC,cAAc,CAAC,mBAAmB,OAAO,oBAAoB,SAChE,QAAO;EAGT,MAAM,qBAAqB;AAC3B,SAAO,mBAAmB,WACtB;GAAE,GAAG;IAAM,aAAa,mBAAmB;GAAU,GACrD;IACH,EAAE,CAAC;;AAGR,MAA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,OAAO,uBAAuB,CAAC,SAAS,EAAE,oBAAoB;AACnF,MAAI,OAAO,kBAAkB,SAC3B,QAAO,cAAc,WAAW,aAAa,GAAG,CAAC,cAAc,GAAG,EAAE;AAGtE,MAAI,MAAM,QAAQ,cAAc,CAC9B,QAAO,cAAc,QAClB,gBACC,OAAO,gBAAgB,YAAY,YAAY,WAAW,aAAa,CAC1E;AAGH,SAAO,EAAE;GACT;AAEF,QAAO,CAAC,GAAG,IAAI,IAAI,CAAC,oBAAoB,GAAG,QAAQ,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/css/utils.ts"],"sourcesContent":["import { configurableProperties } from '@yahoo/uds-automated-config/properties';\nimport type { UniversalTokensConfig } from '@yahoo/uds-config';\n\nimport type { SerializedComponentInfo } from '../commands/generateComponentData';\nimport type { RuntimeConfigValues, VariantDefaults } from '../purger/optimized/purgeFromCode';\nimport {\n getRuntimeDefaultPropSelector,\n getRuntimeDefaultPropValue,\n getRuntimeFieldSelector,\n getRuntimeFieldStaticValue,\n getRuntimeFieldTokenValue,\n getRuntimeSelectorParamValues,\n} from '../runtimeConfig/hookMetadata';\n\n/**\n * Extract variant defaults from a UniversalTokensConfig.\n * Converts from config structure to a simpler lookup format.\n * e.g., { button: { defaults: { size: 'md' } } } -> { Button: { size: 'md' } }\n */\nconst extractVariantDefaults = (config: UniversalTokensConfig): VariantDefaults => {\n // Component names in config are lowercase, but we need PascalCase for matching\n const componentNameMap: Record<string, string> = {\n avatar: 'Avatar',\n badge: 'Badge',\n button: 'Button',\n checkbox: 'Checkbox',\n chip: 'Chip',\n divider: 'Divider',\n iconButton: 'IconButton',\n input: 'Input',\n link: 'Link',\n menu: 'Menu',\n radio: 'Radio',\n switch: 'Switch',\n tab: 'Tab',\n tabs: 'Tabs',\n };\n\n // Extract defaults from each component in the config\n return Object.entries(config).reduce<VariantDefaults>((acc, [configKey, componentConfig]) => {\n const pascalName = componentNameMap[configKey];\n if (!pascalName || !componentConfig || typeof componentConfig !== 'object') {\n return acc;\n }\n\n const configWithDefaults = componentConfig as { defaults?: Record<string, string> };\n return configWithDefaults.defaults\n ? { ...acc, [pascalName]: configWithDefaults.defaults }\n : acc;\n }, {});\n};\n\nconst extractRuntimeConfigValues = (config: UniversalTokensConfig): RuntimeConfigValues => {\n const values: RuntimeConfigValues = {};\n\n const setRuntimeValue = (\n selector: string | null,\n value: string | number | boolean | undefined,\n ) => {\n if (!selector || value === undefined) {\n return;\n }\n\n values[selector] = value;\n };\n\n const bottomSheetBackgroundColor = getRuntimeFieldTokenValue(\n config,\n 'useBottomSheetConfig',\n 'backgroundColor',\n { variant: 'default' },\n );\n\n if (bottomSheetBackgroundColor !== undefined) {\n setRuntimeValue(\n getRuntimeFieldSelector('useBottomSheetConfig', 'backgroundColor', { variant: 'default' }),\n bottomSheetBackgroundColor,\n );\n }\n\n if (config.toast?.variables && config.toast?.defaults) {\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'autoClose'),\n getRuntimeFieldStaticValue('useToastConfig', 'autoClose') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'position'),\n getRuntimeFieldStaticValue('useToastConfig', 'position') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeDefaultPropSelector('useToastConfig', 'size'),\n getRuntimeDefaultPropValue(config, 'useToastConfig', 'size'),\n );\n setRuntimeValue(\n getRuntimeDefaultPropSelector('useToastConfig', 'variant'),\n getRuntimeDefaultPropValue(config, 'useToastConfig', 'variant'),\n );\n\n getRuntimeSelectorParamValues('useToastConfig', 'size').forEach((size) => {\n const textVariant = getRuntimeFieldTokenValue(config, 'useToastConfig', 'textVariant', {\n size,\n });\n const iconSize = getRuntimeFieldTokenValue(config, 'useToastConfig', 'iconSize', { size });\n const buttonSize = getRuntimeFieldTokenValue(config, 'useToastConfig', 'buttonSize', {\n size,\n });\n\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'textVariant', { size }),\n textVariant,\n );\n setRuntimeValue(getRuntimeFieldSelector('useToastConfig', 'iconSize', { size }), iconSize);\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'buttonSize', { size }),\n buttonSize,\n );\n });\n\n getRuntimeSelectorParamValues('useToastConfig', 'variant').forEach((variant) => {\n const textColor = getRuntimeFieldTokenValue(config, 'useToastConfig', 'textColor', {\n variant,\n });\n const buttonVariant = getRuntimeFieldTokenValue(config, 'useToastConfig', 'buttonVariant', {\n variant,\n });\n const iconVariant = getRuntimeFieldTokenValue(config, 'useToastConfig', 'iconVariant', {\n variant,\n });\n const backgroundColor = getRuntimeFieldTokenValue(\n config,\n 'useToastConfig',\n 'backgroundColor',\n { variant },\n );\n\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'textColor', { variant }),\n textColor,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'buttonVariant', { variant }),\n buttonVariant,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'iconVariant', { variant }),\n iconVariant,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useToastConfig', 'backgroundColor', { variant }),\n backgroundColor,\n );\n });\n }\n\n const tooltipBorderRadius = getRuntimeFieldTokenValue(\n config,\n 'useTooltipConfig',\n 'borderRadius',\n {\n size: 'default',\n },\n );\n\n if (tooltipBorderRadius !== undefined) {\n setRuntimeValue(\n getRuntimeFieldSelector('useTooltipConfig', 'animationDuration'),\n getRuntimeFieldStaticValue('useTooltipConfig', 'animationDuration') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useTooltipConfig', 'placement'),\n getRuntimeFieldStaticValue('useTooltipConfig', 'placement') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('useTooltipConfig', 'borderRadius', { size: 'default' }),\n tooltipBorderRadius,\n );\n }\n\n if (config.popover?.variables && config.scaleMode?.medium) {\n setRuntimeValue(\n getRuntimeDefaultPropSelector('usePopoverConfig', 'size'),\n getRuntimeDefaultPropValue(config, 'usePopoverConfig', 'size') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeDefaultPropSelector('usePopoverConfig', 'variant'),\n getRuntimeDefaultPropValue(config, 'usePopoverConfig', 'variant') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'animationDuration'),\n getRuntimeFieldStaticValue('usePopoverConfig', 'animationDuration') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'placement'),\n getRuntimeFieldStaticValue('usePopoverConfig', 'placement') ?? undefined,\n );\n\n getRuntimeSelectorParamValues('usePopoverConfig', 'size').forEach((size) => {\n const borderRadius = getRuntimeFieldTokenValue(config, 'usePopoverConfig', 'borderRadius', {\n size,\n });\n const gap = getRuntimeFieldTokenValue(config, 'usePopoverConfig', 'gap', { size });\n const spacingHorizontal = getRuntimeFieldTokenValue(\n config,\n 'usePopoverConfig',\n 'spacingHorizontal',\n { size },\n );\n const spacingVertical = getRuntimeFieldTokenValue(\n config,\n 'usePopoverConfig',\n 'spacingVertical',\n { size },\n );\n const dismissButtonSpacing = getRuntimeFieldTokenValue(\n config,\n 'usePopoverConfig',\n 'dismissButtonSpacing',\n { size },\n );\n const dismissIconSize = getRuntimeFieldTokenValue(\n config,\n 'usePopoverConfig',\n 'dismissIconSize',\n { size },\n );\n\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'borderRadius', { size }),\n borderRadius,\n );\n setRuntimeValue(getRuntimeFieldSelector('usePopoverConfig', 'gap', { size }), gap);\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'spacingHorizontal', { size }),\n spacingHorizontal,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'spacingVertical', { size }),\n spacingVertical,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'dismissButtonSpacing', { size }),\n dismissButtonSpacing,\n );\n setRuntimeValue(\n getRuntimeFieldSelector('usePopoverConfig', 'dismissIconSize', { size }),\n dismissIconSize,\n );\n });\n }\n\n if (config.modal?.variables) {\n setRuntimeValue(\n getRuntimeDefaultPropSelector('useModalConfig', 'size'),\n getRuntimeDefaultPropValue(config, 'useModalConfig', 'size') ?? undefined,\n );\n setRuntimeValue(\n getRuntimeDefaultPropSelector('useModalConfig', 'variant'),\n getRuntimeDefaultPropValue(config, 'useModalConfig', 'variant') ?? undefined,\n );\n\n getRuntimeSelectorParamValues('useModalConfig', 'size').forEach((size) => {\n const gutter = getRuntimeFieldTokenValue(config, 'useModalConfig', 'gutter', { size });\n\n setRuntimeValue(getRuntimeFieldSelector('useModalConfig', 'gutter', { size }), gutter);\n });\n }\n\n return values;\n};\n\n/**\n * Format bytes to human readable string\n */\nconst formatBytes = (bytes: number): string => {\n if (bytes < 1024) {\n return `${bytes} B`;\n }\n const kb = bytes / 1024;\n if (kb < 1024) {\n return `${kb.toFixed(1)} KB`;\n }\n const mb = kb / 1024;\n return `${mb.toFixed(2)} MB`;\n};\n\n/**\n * Get motion CSS variable prefixes needed by a set of components.\n * Looks up motionVarPrefixes from componentData.json for each component.\n */\nconst getMotionVarPrefixes = (\n componentData: Record<string, SerializedComponentInfo>,\n components: string[],\n): string[] => {\n const prefixes = components.flatMap((componentName) => {\n const info = (componentData as Record<string, { motionVarPrefixes?: string[] }>)[componentName];\n return info?.motionVarPrefixes ?? [];\n });\n\n return [...new Set(prefixes)];\n};\n\n/**\n * Collect css variable names exposed by configurable properties.\n */\nconst getConfigurableCssVariables = (): string[] => {\n const udsVarPrefix = '--uds';\n const cssVars = Object.values(configurableProperties).flatMap(({ cssProperties }) => {\n if (typeof cssProperties === 'string') {\n return cssProperties.startsWith(udsVarPrefix) ? [cssProperties] : [];\n }\n\n if (Array.isArray(cssProperties)) {\n return cssProperties.filter(\n (cssProperty): cssProperty is string =>\n typeof cssProperty === 'string' && cssProperty.startsWith(udsVarPrefix),\n );\n }\n\n return [];\n });\n\n return [...new Set(['--uds-button-gap', ...cssVars])];\n};\n\nexport {\n extractRuntimeConfigValues,\n extractVariantDefaults,\n formatBytes,\n getConfigurableCssVariables,\n getMotionVarPrefixes,\n};\n"],"mappings":";;;;;;;;;AAmBA,MAAM,0BAA0B,WAAmD;CAEjF,MAAM,mBAA2C;EAC/C,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,UAAU;EACV,MAAM;EACN,SAAS;EACT,YAAY;EACZ,OAAO;EACP,MAAM;EACN,MAAM;EACN,OAAO;EACP,QAAQ;EACR,KAAK;EACL,MAAM;EACP;AAGD,QAAO,OAAO,QAAQ,OAAO,CAAC,QAAyB,KAAK,CAAC,WAAW,qBAAqB;EAC3F,MAAM,aAAa,iBAAiB;AACpC,MAAI,CAAC,cAAc,CAAC,mBAAmB,OAAO,oBAAoB,SAChE,QAAO;EAGT,MAAM,qBAAqB;AAC3B,SAAO,mBAAmB,WACtB;GAAE,GAAG;IAAM,aAAa,mBAAmB;GAAU,GACrD;IACH,EAAE,CAAC;;AAGR,MAAM,8BAA8B,WAAuD;CACzF,MAAM,SAA8B,EAAE;CAEtC,MAAM,mBACJ,UACA,UACG;AACH,MAAI,CAAC,YAAY,UAAU,KAAA,EACzB;AAGF,SAAO,YAAY;;CAGrB,MAAM,6BAA6B,0BACjC,QACA,wBACA,mBACA,EAAE,SAAS,WAAW,CACvB;AAED,KAAI,+BAA+B,KAAA,EACjC,iBACE,wBAAwB,wBAAwB,mBAAmB,EAAE,SAAS,WAAW,CAAC,EAC1F,2BACD;AAGH,KAAI,OAAO,OAAO,aAAa,OAAO,OAAO,UAAU;AACrD,kBACE,wBAAwB,kBAAkB,YAAY,EACtD,2BAA2B,kBAAkB,YAAY,IAAI,KAAA,EAC9D;AACD,kBACE,wBAAwB,kBAAkB,WAAW,EACrD,2BAA2B,kBAAkB,WAAW,IAAI,KAAA,EAC7D;AACD,kBACE,8BAA8B,kBAAkB,OAAO,EACvD,2BAA2B,QAAQ,kBAAkB,OAAO,CAC7D;AACD,kBACE,8BAA8B,kBAAkB,UAAU,EAC1D,2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E;AAGH,SAAO,EAAE;GACT;AAEF,QAAO,CAAC,GAAG,IAAI,IAAI,CAAC,oBAAoB,GAAG,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
|
|
2
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
let node_os = require("node:os");
|
|
4
|
+
let node_worker_threads = require("node:worker_threads");
|
|
5
|
+
//#region src/css/workerPool.ts
|
|
6
|
+
const createWorkerPool = async (config, numWorkers) => {
|
|
7
|
+
const workerCount = numWorkers ?? Math.max(1, (0, node_os.cpus)().length - 1);
|
|
8
|
+
const workerUrl = new URL("./purgeWorker.js", require("url").pathToFileURL(__filename).href);
|
|
9
|
+
const workers = [];
|
|
10
|
+
const available = [];
|
|
11
|
+
const pending = /* @__PURE__ */ new Map();
|
|
12
|
+
const queue = [];
|
|
13
|
+
let nextId = 0;
|
|
14
|
+
await Promise.all(Array.from({ length: workerCount }, () => {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const worker = new node_worker_threads.Worker(workerUrl);
|
|
17
|
+
let initialized = false;
|
|
18
|
+
worker.on("message", (msg) => {
|
|
19
|
+
if (msg.type === "ready") {
|
|
20
|
+
initialized = true;
|
|
21
|
+
workers.push(worker);
|
|
22
|
+
available.push(worker);
|
|
23
|
+
resolve();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (msg.type === "result" || msg.type === "error") {
|
|
27
|
+
const task = msg.id != null ? pending.get(msg.id) : void 0;
|
|
28
|
+
if (task) {
|
|
29
|
+
pending.delete(msg.id);
|
|
30
|
+
if (msg.type === "result") task.resolve(msg.result);
|
|
31
|
+
else task.reject(new Error(msg.error ?? "Unknown worker error"));
|
|
32
|
+
}
|
|
33
|
+
available.push(worker);
|
|
34
|
+
if (queue.length > 0 && available.length > 0) {
|
|
35
|
+
const next = queue.shift();
|
|
36
|
+
const nextWorker = available.pop();
|
|
37
|
+
pending.set(next.msg.id, next.task);
|
|
38
|
+
nextWorker.postMessage(next.msg);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
worker.on("error", (err) => {
|
|
43
|
+
if (!initialized) reject(err);
|
|
44
|
+
});
|
|
45
|
+
worker.postMessage({
|
|
46
|
+
type: "init",
|
|
47
|
+
config: JSON.parse(JSON.stringify(config))
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}));
|
|
51
|
+
const processFile = (options) => {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const id = nextId++;
|
|
54
|
+
const msg = {
|
|
55
|
+
type: "task",
|
|
56
|
+
id,
|
|
57
|
+
code: options.code,
|
|
58
|
+
filePath: options.filePath,
|
|
59
|
+
colorModes: options.colorModes,
|
|
60
|
+
variantDefaults: options.variantDefaults,
|
|
61
|
+
runtimeConfigValues: options.runtimeConfigValues,
|
|
62
|
+
includeAllClassNamePrimitives: options.includeAllClassNamePrimitives
|
|
63
|
+
};
|
|
64
|
+
const task = {
|
|
65
|
+
resolve,
|
|
66
|
+
reject
|
|
67
|
+
};
|
|
68
|
+
if (available.length > 0) {
|
|
69
|
+
const worker = available.pop();
|
|
70
|
+
pending.set(id, task);
|
|
71
|
+
worker.postMessage(msg);
|
|
72
|
+
} else queue.push({
|
|
73
|
+
msg,
|
|
74
|
+
task
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const destroy = async () => {
|
|
79
|
+
for (const worker of workers) worker.postMessage({ type: "done" });
|
|
80
|
+
await Promise.all(workers.map((w) => new Promise((res) => w.on("exit", () => res()))));
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
processFile,
|
|
84
|
+
destroy,
|
|
85
|
+
workerCount
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
//#endregion
|
|
89
|
+
exports.createWorkerPool = createWorkerPool;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
|
|
2
|
+
import { cpus } from "node:os";
|
|
3
|
+
import { Worker } from "node:worker_threads";
|
|
4
|
+
//#region src/css/workerPool.ts
|
|
5
|
+
const createWorkerPool = async (config, numWorkers) => {
|
|
6
|
+
const workerCount = numWorkers ?? Math.max(1, cpus().length - 1);
|
|
7
|
+
const workerUrl = new URL("./purgeWorker.js", import.meta.url);
|
|
8
|
+
const workers = [];
|
|
9
|
+
const available = [];
|
|
10
|
+
const pending = /* @__PURE__ */ new Map();
|
|
11
|
+
const queue = [];
|
|
12
|
+
let nextId = 0;
|
|
13
|
+
await Promise.all(Array.from({ length: workerCount }, () => {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const worker = new Worker(workerUrl);
|
|
16
|
+
let initialized = false;
|
|
17
|
+
worker.on("message", (msg) => {
|
|
18
|
+
if (msg.type === "ready") {
|
|
19
|
+
initialized = true;
|
|
20
|
+
workers.push(worker);
|
|
21
|
+
available.push(worker);
|
|
22
|
+
resolve();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (msg.type === "result" || msg.type === "error") {
|
|
26
|
+
const task = msg.id != null ? pending.get(msg.id) : void 0;
|
|
27
|
+
if (task) {
|
|
28
|
+
pending.delete(msg.id);
|
|
29
|
+
if (msg.type === "result") task.resolve(msg.result);
|
|
30
|
+
else task.reject(new Error(msg.error ?? "Unknown worker error"));
|
|
31
|
+
}
|
|
32
|
+
available.push(worker);
|
|
33
|
+
if (queue.length > 0 && available.length > 0) {
|
|
34
|
+
const next = queue.shift();
|
|
35
|
+
const nextWorker = available.pop();
|
|
36
|
+
pending.set(next.msg.id, next.task);
|
|
37
|
+
nextWorker.postMessage(next.msg);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
worker.on("error", (err) => {
|
|
42
|
+
if (!initialized) reject(err);
|
|
43
|
+
});
|
|
44
|
+
worker.postMessage({
|
|
45
|
+
type: "init",
|
|
46
|
+
config: JSON.parse(JSON.stringify(config))
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}));
|
|
50
|
+
const processFile = (options) => {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
const id = nextId++;
|
|
53
|
+
const msg = {
|
|
54
|
+
type: "task",
|
|
55
|
+
id,
|
|
56
|
+
code: options.code,
|
|
57
|
+
filePath: options.filePath,
|
|
58
|
+
colorModes: options.colorModes,
|
|
59
|
+
variantDefaults: options.variantDefaults,
|
|
60
|
+
runtimeConfigValues: options.runtimeConfigValues,
|
|
61
|
+
includeAllClassNamePrimitives: options.includeAllClassNamePrimitives
|
|
62
|
+
};
|
|
63
|
+
const task = {
|
|
64
|
+
resolve,
|
|
65
|
+
reject
|
|
66
|
+
};
|
|
67
|
+
if (available.length > 0) {
|
|
68
|
+
const worker = available.pop();
|
|
69
|
+
pending.set(id, task);
|
|
70
|
+
worker.postMessage(msg);
|
|
71
|
+
} else queue.push({
|
|
72
|
+
msg,
|
|
73
|
+
task
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const destroy = async () => {
|
|
78
|
+
for (const worker of workers) worker.postMessage({ type: "done" });
|
|
79
|
+
await Promise.all(workers.map((w) => new Promise((res) => w.on("exit", () => res()))));
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
processFile,
|
|
83
|
+
destroy,
|
|
84
|
+
workerCount
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
export { createWorkerPool };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=workerPool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerPool.js","names":[],"sources":["../../src/css/workerPool.ts"],"sourcesContent":["import { cpus } from 'node:os';\nimport { Worker } from 'node:worker_threads';\n\nimport type { PurgeFromCodeOptions, PurgeFromCodeResult } from '../purger/optimized/purgeFromCode';\n\ntype SharedConfig = Pick<PurgeFromCodeOptions, 'variants' | 'autoVariants' | 'componentData'>;\n\ninterface TaskOptions {\n code: string;\n filePath: string;\n colorModes?: ('dark' | 'light')[];\n variantDefaults?: PurgeFromCodeOptions['variantDefaults'];\n runtimeConfigValues?: PurgeFromCodeOptions['runtimeConfigValues'];\n includeAllClassNamePrimitives?: boolean;\n}\n\ninterface PendingTask {\n resolve: (result: PurgeFromCodeResult) => void;\n reject: (error: Error) => void;\n}\n\nexport interface WorkerPool {\n processFile: (options: TaskOptions) => Promise<PurgeFromCodeResult>;\n destroy: () => Promise<void>;\n workerCount: number;\n}\n\nexport const createWorkerPool = async (\n config: SharedConfig,\n numWorkers?: number,\n): Promise<WorkerPool> => {\n const workerCount = numWorkers ?? Math.max(1, cpus().length - 1);\n const workerUrl = new URL('./purgeWorker.js', import.meta.url);\n\n const workers: Worker[] = [];\n const available: Worker[] = [];\n const pending = new Map<number, PendingTask>();\n const queue: Array<{ msg: Record<string, unknown>; task: PendingTask }> = [];\n let nextId = 0;\n\n // Create workers, init with shared config, and set up message handlers\n await Promise.all(\n Array.from({ length: workerCount }, () => {\n return new Promise<void>((resolve, reject) => {\n const worker = new Worker(workerUrl);\n let initialized = false;\n\n worker.on(\n 'message',\n (msg: { type: string; id?: number; result?: PurgeFromCodeResult; error?: string }) => {\n if (msg.type === 'ready') {\n initialized = true;\n workers.push(worker);\n available.push(worker);\n resolve();\n return;\n }\n\n if (msg.type === 'result' || msg.type === 'error') {\n const task = msg.id != null ? pending.get(msg.id) : undefined;\n if (task) {\n pending.delete(msg.id!);\n if (msg.type === 'result') {\n task.resolve(msg.result!);\n } else {\n task.reject(new Error(msg.error ?? 'Unknown worker error'));\n }\n }\n\n available.push(worker);\n\n // Drain queue\n if (queue.length > 0 && available.length > 0) {\n const next = queue.shift()!;\n const nextWorker = available.pop()!;\n pending.set(next.msg.id as number, next.task);\n nextWorker.postMessage(next.msg);\n }\n }\n },\n );\n\n worker.on('error', (err) => {\n if (!initialized) {\n reject(err);\n }\n });\n\n // JSON round-trip ensures config is a plain object (ES module namespaces can't be cloned)\n worker.postMessage({ type: 'init', config: JSON.parse(JSON.stringify(config)) });\n });\n }),\n );\n\n const processFile = (options: TaskOptions): Promise<PurgeFromCodeResult> => {\n return new Promise((resolve, reject) => {\n const id = nextId++;\n const msg = {\n type: 'task' as const,\n id,\n code: options.code,\n filePath: options.filePath,\n colorModes: options.colorModes,\n variantDefaults: options.variantDefaults,\n runtimeConfigValues: options.runtimeConfigValues,\n includeAllClassNamePrimitives: options.includeAllClassNamePrimitives,\n };\n const task = { resolve, reject };\n\n if (available.length > 0) {\n const worker = available.pop()!;\n pending.set(id, task);\n worker.postMessage(msg);\n } else {\n queue.push({ msg, task });\n }\n });\n };\n\n const destroy = async () => {\n for (const worker of workers) {\n worker.postMessage({ type: 'done' });\n }\n await Promise.all(workers.map((w) => new Promise<void>((res) => w.on('exit', () => res()))));\n };\n\n return { processFile, destroy, workerCount };\n};\n"],"mappings":";;;;AA2BA,MAAa,mBAAmB,OAC9B,QACA,eACwB;CACxB,MAAM,cAAc,cAAc,KAAK,IAAI,GAAG,MAAM,CAAC,SAAS,EAAE;CAChE,MAAM,YAAY,IAAI,IAAI,oBAAoB,OAAO,KAAK,IAAI;CAE9D,MAAM,UAAoB,EAAE;CAC5B,MAAM,YAAsB,EAAE;CAC9B,MAAM,0BAAU,IAAI,KAA0B;CAC9C,MAAM,QAAoE,EAAE;CAC5E,IAAI,SAAS;AAGb,OAAM,QAAQ,IACZ,MAAM,KAAK,EAAE,QAAQ,aAAa,QAAQ;AACxC,SAAO,IAAI,SAAe,SAAS,WAAW;GAC5C,MAAM,SAAS,IAAI,OAAO,UAAU;GACpC,IAAI,cAAc;AAElB,UAAO,GACL,YACC,QAAqF;AACpF,QAAI,IAAI,SAAS,SAAS;AACxB,mBAAc;AACd,aAAQ,KAAK,OAAO;AACpB,eAAU,KAAK,OAAO;AACtB,cAAS;AACT;;AAGF,QAAI,IAAI,SAA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AAI,QAAQ,KAAK,MAAM,IAAI,SAAe,QAAQ,EAAE,GAAG,cAAc,KAAK,CAAC,CAAC,CAAC,CAAC;;AAG9F,QAAO;EAAE;EAAa;EAAS;EAAa"}
|
|
@@ -24,11 +24,7 @@ const getLocalDefinitionNodes = (node) => {
|
|
|
24
24
|
].sort((left, right) => right.getStart() - left.getStart()).slice(0, 1);
|
|
25
25
|
};
|
|
26
26
|
const getDefinitionNodesSafe = (node) => {
|
|
27
|
-
|
|
28
|
-
return node.getDefinitionNodes();
|
|
29
|
-
} catch {
|
|
30
|
-
return getLocalDefinitionNodes(node);
|
|
31
|
-
}
|
|
27
|
+
return getLocalDefinitionNodes(node);
|
|
32
28
|
};
|
|
33
29
|
const isExistingFile = (candidate) => node_fs.default.existsSync(candidate) && node_fs.default.statSync(candidate).isFile();
|
|
34
30
|
const resolveRelativeImportPath = (sourceFilePath, moduleSpecifier) => {
|
|
@@ -230,7 +226,7 @@ const extractArrayElementValues = (node, visited) => {
|
|
|
230
226
|
if (ts_morph.Node.isArrayLiteralExpression(node)) return node.getElements().flatMap((element) => extractStringLiterals(element, visited)).filter((value, index, values) => values.indexOf(value) === index);
|
|
231
227
|
if (ts_morph.Node.isParenthesizedExpression(node)) return extractArrayElementValues(node.getExpression(), visited);
|
|
232
228
|
if (ts_morph.Node.isAsExpression(node) || ts_morph.Node.isTypeAssertion(node) || ts_morph.Node.isSatisfiesExpression(node)) return extractArrayElementValues(node.getExpression(), visited);
|
|
233
|
-
if (ts_morph.Node.isIdentifier(node)) return node
|
|
229
|
+
if (ts_morph.Node.isIdentifier(node)) return getLocalDefinitionNodes(node).flatMap((definition) => {
|
|
234
230
|
if (ts_morph.Node.isVariableDeclaration(definition)) {
|
|
235
231
|
const initializer = definition.getInitializer();
|
|
236
232
|
return initializer ? extractArrayElementValues(initializer, visited) : [];
|
|
@@ -258,7 +254,22 @@ const extractIdentifierValues = (node, visited) => {
|
|
|
258
254
|
if (mappedParameterValues.length > 0) return mappedParameterValues;
|
|
259
255
|
if (ts_morph.Node.isVariableDeclaration(definition) || ts_morph.Node.isParameterDeclaration(definition) || ts_morph.Node.isBindingElement(definition)) {
|
|
260
256
|
const initializer = definition.getInitializer();
|
|
261
|
-
|
|
257
|
+
if (initializer) return extractStringLiterals(initializer, visited);
|
|
258
|
+
if (ts_morph.Node.isBindingElement(definition)) {
|
|
259
|
+
const bindingPattern = definition.getParent();
|
|
260
|
+
if (ts_morph.Node.isObjectBindingPattern(bindingPattern)) {
|
|
261
|
+
const parentDecl = bindingPattern.getParent();
|
|
262
|
+
if (ts_morph.Node.isVariableDeclaration(parentDecl)) {
|
|
263
|
+
const parentInit = parentDecl.getInitializer();
|
|
264
|
+
if (parentInit) {
|
|
265
|
+
const propName = definition.getNameNode().getText();
|
|
266
|
+
const propValues = extractObjectValues(parentInit, new Set(visited)).filter((obj) => typeof obj === "object" && obj !== null && propName in obj).map((obj) => obj[propName]).filter((v) => typeof v === "string");
|
|
267
|
+
if (propValues.length > 0) return propValues;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return [];
|
|
262
273
|
}
|
|
263
274
|
return [];
|
|
264
275
|
});
|
|
@@ -321,6 +332,35 @@ const extractObjectValues = (node, visited) => {
|
|
|
321
332
|
});
|
|
322
333
|
return values;
|
|
323
334
|
}
|
|
335
|
+
if (ts_morph.Node.isCallExpression(node)) {
|
|
336
|
+
const expression = node.getExpression();
|
|
337
|
+
if (ts_morph.Node.isIdentifier(expression)) getDefinitionNodesSafe(expression).forEach((definition) => {
|
|
338
|
+
if (ts_morph.Node.isFunctionDeclaration(definition)) definition.getDescendantsOfKind(ts_morph.SyntaxKind.ReturnStatement).forEach((returnStmt) => {
|
|
339
|
+
const returnExpr = returnStmt.getExpression();
|
|
340
|
+
if (returnExpr) values.push(...extractObjectValues(returnExpr, visited));
|
|
341
|
+
});
|
|
342
|
+
if (ts_morph.Node.isVariableDeclaration(definition)) {
|
|
343
|
+
const initializer = definition.getInitializer();
|
|
344
|
+
if (initializer) {
|
|
345
|
+
const extractFromFn = (fn) => {
|
|
346
|
+
if (ts_morph.Node.isArrowFunction(fn)) {
|
|
347
|
+
const body = fn.getBody();
|
|
348
|
+
if (ts_morph.Node.isBlock(body)) body.getDescendantsOfKind(ts_morph.SyntaxKind.ReturnStatement).forEach((returnStmt) => {
|
|
349
|
+
const returnExpr = returnStmt.getExpression();
|
|
350
|
+
if (returnExpr) values.push(...extractObjectValues(returnExpr, visited));
|
|
351
|
+
});
|
|
352
|
+
else values.push(...extractObjectValues(body, visited));
|
|
353
|
+
} else if (ts_morph.Node.isFunctionExpression(fn)) fn.getDescendantsOfKind(ts_morph.SyntaxKind.ReturnStatement).forEach((returnStmt) => {
|
|
354
|
+
const returnExpr = returnStmt.getExpression();
|
|
355
|
+
if (returnExpr) values.push(...extractObjectValues(returnExpr, visited));
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
extractFromFn(initializer);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
return values;
|
|
363
|
+
}
|
|
324
364
|
if (ts_morph.Node.isElementAccessExpression(node)) {
|
|
325
365
|
extractObjectValues(node.getExpression(), visited).forEach((obj) => {
|
|
326
366
|
if (typeof obj === "object" && obj !== null) Object.values(obj).forEach((value) => values.push(value));
|
|
@@ -330,16 +370,56 @@ const extractObjectValues = (node, visited) => {
|
|
|
330
370
|
return values;
|
|
331
371
|
};
|
|
332
372
|
/**
|
|
333
|
-
* Extract literal values from a TypeScript type
|
|
373
|
+
* Extract string literal values from a TypeScript type annotation AST node.
|
|
374
|
+
* Pure AST traversal — avoids expensive TS Language Service `getType()` calls.
|
|
375
|
+
*/
|
|
376
|
+
const extractStringLiteralsFromTypeNode = (typeNode) => {
|
|
377
|
+
if (ts_morph.Node.isLiteralTypeNode(typeNode)) {
|
|
378
|
+
const literal = typeNode.getLiteral();
|
|
379
|
+
if (ts_morph.Node.isStringLiteral(literal)) return [literal.getLiteralValue()];
|
|
380
|
+
return [];
|
|
381
|
+
}
|
|
382
|
+
if (ts_morph.Node.isUnionTypeNode(typeNode)) return typeNode.getTypeNodes().flatMap(extractStringLiteralsFromTypeNode);
|
|
383
|
+
return [];
|
|
384
|
+
};
|
|
385
|
+
/**
|
|
386
|
+
* Extract literal values from a TypeScript type annotation (for union types like 'brand' | 'secondary').
|
|
387
|
+
* Uses pure AST traversal instead of the TS type checker to avoid expensive LS initialization.
|
|
334
388
|
*/
|
|
335
389
|
const extractLiteralValuesFromType = (node) => {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
390
|
+
if (ts_morph.Node.isIdentifier(node)) {
|
|
391
|
+
const definitions = getLocalDefinitionNodes(node);
|
|
392
|
+
for (const def of definitions) {
|
|
393
|
+
if (ts_morph.Node.isParameterDeclaration(def) || ts_morph.Node.isVariableDeclaration(def) || ts_morph.Node.isPropertyDeclaration(def) || ts_morph.Node.isPropertySignature(def)) {
|
|
394
|
+
const typeNode = def.getTypeNode?.();
|
|
395
|
+
if (typeNode) {
|
|
396
|
+
const values = extractStringLiteralsFromTypeNode(typeNode);
|
|
397
|
+
if (values.length > 0) return values;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (ts_morph.Node.isBindingElement(def)) {
|
|
401
|
+
const bindingPattern = def.getParent();
|
|
402
|
+
if (bindingPattern) {
|
|
403
|
+
const parentDecl = bindingPattern.getParent();
|
|
404
|
+
if (parentDecl && ts_morph.Node.isVariableDeclaration(parentDecl)) {
|
|
405
|
+
const parentType = parentDecl.getTypeNode();
|
|
406
|
+
if (parentType && ts_morph.Node.isTypeLiteral(parentType)) {
|
|
407
|
+
const propName = def.getNameNode().getText();
|
|
408
|
+
for (const member of parentType.getMembers()) if (ts_morph.Node.isPropertySignature(member) && member.getName() === propName) {
|
|
409
|
+
const memberType = member.getTypeNode();
|
|
410
|
+
if (memberType) {
|
|
411
|
+
const values = extractStringLiteralsFromTypeNode(memberType);
|
|
412
|
+
if (values.length > 0) return values;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (ts_morph.Node.isPropertyAccessExpression(node) || ts_morph.Node.isElementAccessExpression(node)) return [];
|
|
422
|
+
return [];
|
|
343
423
|
};
|
|
344
424
|
//#endregion
|
|
345
425
|
exports.extractStringLiterals = extractStringLiterals;
|
|
@@ -21,11 +21,7 @@ const getLocalDefinitionNodes = (node) => {
|
|
|
21
21
|
].sort((left, right) => right.getStart() - left.getStart()).slice(0, 1);
|
|
22
22
|
};
|
|
23
23
|
const getDefinitionNodesSafe = (node) => {
|
|
24
|
-
|
|
25
|
-
return node.getDefinitionNodes();
|
|
26
|
-
} catch {
|
|
27
|
-
return getLocalDefinitionNodes(node);
|
|
28
|
-
}
|
|
24
|
+
return getLocalDefinitionNodes(node);
|
|
29
25
|
};
|
|
30
26
|
const isExistingFile = (candidate) => fs.existsSync(candidate) && fs.statSync(candidate).isFile();
|
|
31
27
|
const resolveRelativeImportPath = (sourceFilePath, moduleSpecifier) => {
|
|
@@ -227,7 +223,7 @@ const extractArrayElementValues = (node, visited) => {
|
|
|
227
223
|
if (Node.isArrayLiteralExpression(node)) return node.getElements().flatMap((element) => extractStringLiterals(element, visited)).filter((value, index, values) => values.indexOf(value) === index);
|
|
228
224
|
if (Node.isParenthesizedExpression(node)) return extractArrayElementValues(node.getExpression(), visited);
|
|
229
225
|
if (Node.isAsExpression(node) || Node.isTypeAssertion(node) || Node.isSatisfiesExpression(node)) return extractArrayElementValues(node.getExpression(), visited);
|
|
230
|
-
if (Node.isIdentifier(node)) return node
|
|
226
|
+
if (Node.isIdentifier(node)) return getLocalDefinitionNodes(node).flatMap((definition) => {
|
|
231
227
|
if (Node.isVariableDeclaration(definition)) {
|
|
232
228
|
const initializer = definition.getInitializer();
|
|
233
229
|
return initializer ? extractArrayElementValues(initializer, visited) : [];
|
|
@@ -255,7 +251,22 @@ const extractIdentifierValues = (node, visited) => {
|
|
|
255
251
|
if (mappedParameterValues.length > 0) return mappedParameterValues;
|
|
256
252
|
if (Node.isVariableDeclaration(definition) || Node.isParameterDeclaration(definition) || Node.isBindingElement(definition)) {
|
|
257
253
|
const initializer = definition.getInitializer();
|
|
258
|
-
|
|
254
|
+
if (initializer) return extractStringLiterals(initializer, visited);
|
|
255
|
+
if (Node.isBindingElement(definition)) {
|
|
256
|
+
const bindingPattern = definition.getParent();
|
|
257
|
+
if (Node.isObjectBindingPattern(bindingPattern)) {
|
|
258
|
+
const parentDecl = bindingPattern.getParent();
|
|
259
|
+
if (Node.isVariableDeclaration(parentDecl)) {
|
|
260
|
+
const parentInit = parentDecl.getInitializer();
|
|
261
|
+
if (parentInit) {
|
|
262
|
+
const propName = definition.getNameNode().getText();
|
|
263
|
+
const propValues = extractObjectValues(parentInit, new Set(visited)).filter((obj) => typeof obj === "object" && obj !== null && propName in obj).map((obj) => obj[propName]).filter((v) => typeof v === "string");
|
|
264
|
+
if (propValues.length > 0) return propValues;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return [];
|
|
259
270
|
}
|
|
260
271
|
return [];
|
|
261
272
|
});
|
|
@@ -318,6 +329,35 @@ const extractObjectValues = (node, visited) => {
|
|
|
318
329
|
});
|
|
319
330
|
return values;
|
|
320
331
|
}
|
|
332
|
+
if (Node.isCallExpression(node)) {
|
|
333
|
+
const expression = node.getExpression();
|
|
334
|
+
if (Node.isIdentifier(expression)) getDefinitionNodesSafe(expression).forEach((definition) => {
|
|
335
|
+
if (Node.isFunctionDeclaration(definition)) definition.getDescendantsOfKind(SyntaxKind.ReturnStatement).forEach((returnStmt) => {
|
|
336
|
+
const returnExpr = returnStmt.getExpression();
|
|
337
|
+
if (returnExpr) values.push(...extractObjectValues(returnExpr, visited));
|
|
338
|
+
});
|
|
339
|
+
if (Node.isVariableDeclaration(definition)) {
|
|
340
|
+
const initializer = definition.getInitializer();
|
|
341
|
+
if (initializer) {
|
|
342
|
+
const extractFromFn = (fn) => {
|
|
343
|
+
if (Node.isArrowFunction(fn)) {
|
|
344
|
+
const body = fn.getBody();
|
|
345
|
+
if (Node.isBlock(body)) body.getDescendantsOfKind(SyntaxKind.ReturnStatement).forEach((returnStmt) => {
|
|
346
|
+
const returnExpr = returnStmt.getExpression();
|
|
347
|
+
if (returnExpr) values.push(...extractObjectValues(returnExpr, visited));
|
|
348
|
+
});
|
|
349
|
+
else values.push(...extractObjectValues(body, visited));
|
|
350
|
+
} else if (Node.isFunctionExpression(fn)) fn.getDescendantsOfKind(SyntaxKind.ReturnStatement).forEach((returnStmt) => {
|
|
351
|
+
const returnExpr = returnStmt.getExpression();
|
|
352
|
+
if (returnExpr) values.push(...extractObjectValues(returnExpr, visited));
|
|
353
|
+
});
|
|
354
|
+
};
|
|
355
|
+
extractFromFn(initializer);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
return values;
|
|
360
|
+
}
|
|
321
361
|
if (Node.isElementAccessExpression(node)) {
|
|
322
362
|
extractObjectValues(node.getExpression(), visited).forEach((obj) => {
|
|
323
363
|
if (typeof obj === "object" && obj !== null) Object.values(obj).forEach((value) => values.push(value));
|
|
@@ -327,16 +367,56 @@ const extractObjectValues = (node, visited) => {
|
|
|
327
367
|
return values;
|
|
328
368
|
};
|
|
329
369
|
/**
|
|
330
|
-
* Extract literal values from a TypeScript type
|
|
370
|
+
* Extract string literal values from a TypeScript type annotation AST node.
|
|
371
|
+
* Pure AST traversal — avoids expensive TS Language Service `getType()` calls.
|
|
372
|
+
*/
|
|
373
|
+
const extractStringLiteralsFromTypeNode = (typeNode) => {
|
|
374
|
+
if (Node.isLiteralTypeNode(typeNode)) {
|
|
375
|
+
const literal = typeNode.getLiteral();
|
|
376
|
+
if (Node.isStringLiteral(literal)) return [literal.getLiteralValue()];
|
|
377
|
+
return [];
|
|
378
|
+
}
|
|
379
|
+
if (Node.isUnionTypeNode(typeNode)) return typeNode.getTypeNodes().flatMap(extractStringLiteralsFromTypeNode);
|
|
380
|
+
return [];
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* Extract literal values from a TypeScript type annotation (for union types like 'brand' | 'secondary').
|
|
384
|
+
* Uses pure AST traversal instead of the TS type checker to avoid expensive LS initialization.
|
|
331
385
|
*/
|
|
332
386
|
const extractLiteralValuesFromType = (node) => {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
387
|
+
if (Node.isIdentifier(node)) {
|
|
388
|
+
const definitions = getLocalDefinitionNodes(node);
|
|
389
|
+
for (const def of definitions) {
|
|
390
|
+
if (Node.isParameterDeclaration(def) || Node.isVariableDeclaration(def) || Node.isPropertyDeclaration(def) || Node.isPropertySignature(def)) {
|
|
391
|
+
const typeNode = def.getTypeNode?.();
|
|
392
|
+
if (typeNode) {
|
|
393
|
+
const values = extractStringLiteralsFromTypeNode(typeNode);
|
|
394
|
+
if (values.length > 0) return values;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (Node.isBindingElement(def)) {
|
|
398
|
+
const bindingPattern = def.getParent();
|
|
399
|
+
if (bindingPattern) {
|
|
400
|
+
const parentDecl = bindingPattern.getParent();
|
|
401
|
+
if (parentDecl && Node.isVariableDeclaration(parentDecl)) {
|
|
402
|
+
const parentType = parentDecl.getTypeNode();
|
|
403
|
+
if (parentType && Node.isTypeLiteral(parentType)) {
|
|
404
|
+
const propName = def.getNameNode().getText();
|
|
405
|
+
for (const member of parentType.getMembers()) if (Node.isPropertySignature(member) && member.getName() === propName) {
|
|
406
|
+
const memberType = member.getTypeNode();
|
|
407
|
+
if (memberType) {
|
|
408
|
+
const values = extractStringLiteralsFromTypeNode(memberType);
|
|
409
|
+
if (values.length > 0) return values;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (Node.isPropertyAccessExpression(node) || Node.isElementAccessExpression(node)) return [];
|
|
419
|
+
return [];
|
|
340
420
|
};
|
|
341
421
|
//#endregion
|
|
342
422
|
export { extractStringLiterals };
|