@atlaskit/tokens 13.0.3 → 13.1.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/CHANGELOG.md +15 -0
- package/codemods/css-to-design-tokens/lib/meta.tsx +1 -1
- package/codemods/css-to-design-tokens/lib/tokens.tsx +1 -1
- package/codemods/theme-to-design-tokens/transform.tsx +16 -14
- package/codemods/theme-to-design-tokens/utils/ast-meta.tsx +2 -151
- package/codemods/theme-to-design-tokens/utils/ast.tsx +3 -35
- package/codemods/theme-to-design-tokens/utils/clean-meta.tsx +63 -0
- package/codemods/theme-to-design-tokens/utils/color.tsx +3 -11
- package/codemods/theme-to-design-tokens/utils/contains-replaceable-css-declarations.tsx +13 -0
- package/codemods/theme-to-design-tokens/utils/css-utils.tsx +2 -35
- package/codemods/theme-to-design-tokens/utils/find-end-index-of-css-expression.tsx +21 -0
- package/codemods/theme-to-design-tokens/utils/find-first-nonspace-index-after.tsx +9 -0
- package/codemods/theme-to-design-tokens/utils/get-closest-decendant-of-type.tsx +10 -0
- package/codemods/theme-to-design-tokens/utils/get-meta-from-ancestors.tsx +87 -0
- package/codemods/theme-to-design-tokens/utils/is-bold-color.tsx +4 -0
- package/codemods/theme-to-design-tokens/utils/is-decendant-of-token.tsx +14 -0
- package/codemods/theme-to-design-tokens/utils/is-legacy-color.tsx +4 -0
- package/codemods/theme-to-design-tokens/utils/is-legacy-named-color.tsx +4 -0
- package/codemods/theme-to-design-tokens/utils/is-parent-of-token.tsx +13 -0
- package/codemods/theme-to-design-tokens/utils/kebabize.tsx +2 -0
- package/codemods/theme-to-design-tokens/utils/legacy-color-meta-map.tsx +88 -0
- package/codemods/theme-to-design-tokens/utils/legacy-color-mixins.tsx +26 -0
- package/codemods/theme-to-design-tokens/utils/legacy-colors.tsx +2 -115
- package/codemods/theme-to-design-tokens/utils/split-at-index.tsx +3 -0
- package/codemods/theme-to-design-tokens/utils/string-utils.tsx +3 -16
- package/codemods/utils/active-tokens.tsx +284 -0
- package/codemods/utils/tokens.tsx +2 -376
- package/codemods/utils/unique-words-from-tokens.tsx +91 -0
- package/dist/cjs/artifacts/replacement-mapping.js +5 -2
- package/dist/cjs/artifacts/themes/atlassian-dark-increased-contrast.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-dark.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-light-increased-contrast.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-light.js +2 -2
- package/dist/cjs/artifacts/token-default-values.js +2 -2
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +3 -3
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +3 -3
- package/dist/cjs/artifacts/tokens-raw/atlassian-light-increased-contrast.js +3 -3
- package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +3 -3
- package/dist/cjs/artifacts/tokens-raw/atlassian-motion.js +3 -3
- package/dist/cjs/constants.js +1 -0
- package/dist/cjs/custom-theme.js +10 -60
- package/dist/cjs/entry-points/token-metadata.codegen.js +2 -11
- package/dist/cjs/get-custom-theme-styles.js +57 -0
- package/dist/cjs/get-global-theme.js +2 -2
- package/dist/cjs/get-theme-html-attrs.js +2 -2
- package/dist/cjs/get-theme-styles.js +33 -32
- package/dist/cjs/load-custom-theme-styles.js +2 -2
- package/dist/cjs/set-global-theme.js +36 -34
- package/dist/cjs/theme-color-modes.js +13 -0
- package/dist/cjs/theme-config.js +21 -16
- package/dist/cjs/theme-ids.js +13 -0
- package/dist/cjs/theme-state-transformer.js +3 -2
- package/dist/cjs/utils/color-detection.js +9 -12
- package/dist/cjs/utils/color-utils.js +45 -46
- package/dist/cjs/utils/custom-theme-loading-utils.js +9 -11
- package/dist/cjs/utils/custom-theme-token-contrast-check.js +2 -0
- package/dist/cjs/utils/generate-custom-color-ramp.js +20 -19
- package/dist/cjs/utils/get-alpha.js +13 -0
- package/dist/cjs/utils/get-closest-color-index.js +20 -0
- package/dist/cjs/utils/get-css-custom-property.js +32 -0
- package/dist/cjs/utils/get-fully-qualified-token-id.js +19 -0
- package/dist/cjs/utils/get-theme-override-preferences.js +12 -0
- package/dist/cjs/utils/get-theme-preferences.js +8 -5
- package/dist/cjs/utils/get-token-id.js +26 -0
- package/dist/cjs/utils/hct-color-utils/argb-from-rgb.js +12 -0
- package/dist/cjs/utils/hct-color-utils/clamp-double.js +20 -0
- package/dist/cjs/utils/hct-color-utils/clamp-int.js +20 -0
- package/dist/cjs/utils/hct-color-utils/color-utils.js +42 -59
- package/dist/cjs/utils/hct-color-utils/delinearized.js +27 -0
- package/dist/cjs/utils/hct-color-utils/hct.js +19 -95
- package/dist/cjs/utils/hct-color-utils/lerp.js +14 -0
- package/dist/cjs/utils/hct-color-utils/linearized.js +22 -0
- package/dist/cjs/utils/hct-color-utils/math-utils.js +38 -107
- package/dist/cjs/utils/hct-color-utils/matrix-multiply.js +15 -0
- package/dist/cjs/utils/hct-color-utils/sanitize-degrees-double.js +19 -0
- package/dist/cjs/utils/hct-color-utils/signum.js +20 -0
- package/dist/cjs/utils/hct-color-utils/viewing-conditions.js +98 -0
- package/dist/cjs/utils/hex-to-rgba-values.js +15 -0
- package/dist/cjs/utils/hsl-to-rgb.js +18 -0
- package/dist/cjs/utils/is-valid-brand-hex.js +9 -0
- package/dist/cjs/utils/limit-size-of-custom-style-elements.js +16 -0
- package/dist/cjs/utils/load-theme-css.js +32 -0
- package/dist/cjs/utils/relative-luminance-w3-c.js +18 -0
- package/dist/cjs/utils/rgb-to-hex.js +9 -0
- package/dist/cjs/utils/theme-loading.js +18 -33
- package/dist/cjs/utils/token-ids.js +21 -62
- package/dist/es2019/artifacts/replacement-mapping.js +5 -2
- package/dist/es2019/artifacts/themes/atlassian-dark-increased-contrast.js +2 -2
- package/dist/es2019/artifacts/themes/atlassian-dark.js +2 -2
- package/dist/es2019/artifacts/themes/atlassian-light-increased-contrast.js +2 -2
- package/dist/es2019/artifacts/themes/atlassian-light.js +2 -2
- package/dist/es2019/artifacts/token-default-values.js +2 -2
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +3 -3
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +3 -3
- package/dist/es2019/artifacts/tokens-raw/atlassian-light-increased-contrast.js +3 -3
- package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +3 -3
- package/dist/es2019/artifacts/tokens-raw/atlassian-motion.js +3 -3
- package/dist/es2019/constants.js +1 -0
- package/dist/es2019/custom-theme.js +4 -66
- package/dist/es2019/entry-points/token-metadata.codegen.js +2 -11
- package/dist/es2019/get-custom-theme-styles.js +60 -0
- package/dist/es2019/get-global-theme.js +1 -1
- package/dist/es2019/get-theme-html-attrs.js +1 -1
- package/dist/es2019/get-theme-styles.js +4 -3
- package/dist/es2019/load-custom-theme-styles.js +1 -1
- package/dist/es2019/set-global-theme.js +3 -2
- package/dist/es2019/theme-color-modes.js +7 -0
- package/dist/es2019/theme-config.js +6 -16
- package/dist/es2019/theme-ids.js +7 -0
- package/dist/es2019/theme-state-transformer.js +2 -1
- package/dist/es2019/utils/color-detection.js +3 -11
- package/dist/es2019/utils/color-utils.js +15 -33
- package/dist/es2019/utils/custom-theme-loading-utils.js +4 -8
- package/dist/es2019/utils/custom-theme-token-contrast-check.js +2 -0
- package/dist/es2019/utils/generate-custom-color-ramp.js +11 -15
- package/dist/es2019/utils/get-alpha.js +7 -0
- package/dist/es2019/utils/get-closest-color-index.js +14 -0
- package/dist/es2019/utils/get-css-custom-property.js +23 -0
- package/dist/es2019/utils/get-fully-qualified-token-id.js +11 -0
- package/dist/es2019/utils/get-theme-override-preferences.js +4 -0
- package/dist/es2019/utils/get-theme-preferences.js +1 -4
- package/dist/es2019/utils/get-token-id.js +18 -0
- package/dist/es2019/utils/hct-color-utils/argb-from-rgb.js +6 -0
- package/dist/es2019/utils/hct-color-utils/clamp-double.js +14 -0
- package/dist/es2019/utils/hct-color-utils/clamp-int.js +14 -0
- package/dist/es2019/utils/hct-color-utils/color-utils.js +15 -45
- package/dist/es2019/utils/hct-color-utils/delinearized.js +20 -0
- package/dist/es2019/utils/hct-color-utils/hct.js +3 -76
- package/dist/es2019/utils/hct-color-utils/lerp.js +8 -0
- package/dist/es2019/utils/hct-color-utils/linearized.js +16 -0
- package/dist/es2019/utils/hct-color-utils/math-utils.js +6 -105
- package/dist/es2019/utils/hct-color-utils/matrix-multiply.js +9 -0
- package/dist/es2019/utils/hct-color-utils/sanitize-degrees-double.js +13 -0
- package/dist/es2019/utils/hct-color-utils/signum.js +14 -0
- package/dist/es2019/utils/hct-color-utils/viewing-conditions.js +78 -0
- package/dist/es2019/utils/hex-to-rgba-values.js +9 -0
- package/dist/es2019/utils/hsl-to-rgb.js +8 -0
- package/dist/es2019/utils/is-valid-brand-hex.js +1 -0
- package/dist/es2019/utils/limit-size-of-custom-style-elements.js +8 -0
- package/dist/es2019/utils/load-theme-css.js +7 -0
- package/dist/es2019/utils/relative-luminance-w3-c.js +12 -0
- package/dist/es2019/utils/rgb-to-hex.js +3 -0
- package/dist/es2019/utils/theme-loading.js +3 -8
- package/dist/es2019/utils/token-ids.js +3 -54
- package/dist/esm/artifacts/replacement-mapping.js +5 -2
- package/dist/esm/artifacts/themes/atlassian-dark-increased-contrast.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-dark.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-light-increased-contrast.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-light.js +2 -2
- package/dist/esm/artifacts/token-default-values.js +2 -2
- package/dist/esm/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +3 -3
- package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +3 -3
- package/dist/esm/artifacts/tokens-raw/atlassian-light-increased-contrast.js +3 -3
- package/dist/esm/artifacts/tokens-raw/atlassian-light.js +3 -3
- package/dist/esm/artifacts/tokens-raw/atlassian-motion.js +3 -3
- package/dist/esm/constants.js +1 -0
- package/dist/esm/custom-theme.js +4 -58
- package/dist/esm/entry-points/token-metadata.codegen.js +2 -11
- package/dist/esm/get-custom-theme-styles.js +52 -0
- package/dist/esm/get-global-theme.js +1 -1
- package/dist/esm/get-theme-html-attrs.js +1 -1
- package/dist/esm/get-theme-styles.js +30 -29
- package/dist/esm/load-custom-theme-styles.js +1 -1
- package/dist/esm/set-global-theme.js +34 -32
- package/dist/esm/theme-color-modes.js +7 -0
- package/dist/esm/theme-config.js +8 -17
- package/dist/esm/theme-ids.js +7 -0
- package/dist/esm/theme-state-transformer.js +2 -1
- package/dist/esm/utils/color-detection.js +3 -11
- package/dist/esm/utils/color-utils.js +15 -39
- package/dist/esm/utils/custom-theme-loading-utils.js +4 -11
- package/dist/esm/utils/custom-theme-token-contrast-check.js +2 -0
- package/dist/esm/utils/generate-custom-color-ramp.js +11 -15
- package/dist/esm/utils/get-alpha.js +7 -0
- package/dist/esm/utils/get-closest-color-index.js +14 -0
- package/dist/esm/utils/get-css-custom-property.js +26 -0
- package/dist/esm/utils/get-fully-qualified-token-id.js +13 -0
- package/dist/esm/utils/get-theme-override-preferences.js +5 -0
- package/dist/esm/utils/get-theme-preferences.js +1 -4
- package/dist/esm/utils/get-token-id.js +20 -0
- package/dist/esm/utils/hct-color-utils/argb-from-rgb.js +6 -0
- package/dist/esm/utils/hct-color-utils/clamp-double.js +14 -0
- package/dist/esm/utils/hct-color-utils/clamp-int.js +14 -0
- package/dist/esm/utils/hct-color-utils/color-utils.js +15 -45
- package/dist/esm/utils/hct-color-utils/delinearized.js +20 -0
- package/dist/esm/utils/hct-color-utils/hct.js +5 -87
- package/dist/esm/utils/hct-color-utils/lerp.js +8 -0
- package/dist/esm/utils/hct-color-utils/linearized.js +16 -0
- package/dist/esm/utils/hct-color-utils/math-utils.js +6 -105
- package/dist/esm/utils/hct-color-utils/matrix-multiply.js +9 -0
- package/dist/esm/utils/hct-color-utils/sanitize-degrees-double.js +13 -0
- package/dist/esm/utils/hct-color-utils/signum.js +14 -0
- package/dist/esm/utils/hct-color-utils/viewing-conditions.js +89 -0
- package/dist/esm/utils/hex-to-rgba-values.js +9 -0
- package/dist/esm/utils/hsl-to-rgb.js +12 -0
- package/dist/esm/utils/is-valid-brand-hex.js +3 -0
- package/dist/esm/utils/limit-size-of-custom-style-elements.js +10 -0
- package/dist/esm/utils/load-theme-css.js +25 -0
- package/dist/esm/utils/relative-luminance-w3-c.js +12 -0
- package/dist/esm/utils/rgb-to-hex.js +3 -0
- package/dist/esm/utils/theme-loading.js +11 -32
- package/dist/esm/utils/token-ids.js +3 -61
- package/dist/types/artifacts/replacement-mapping.d.ts +1 -1
- package/dist/types/artifacts/themes/atlassian-dark-increased-contrast.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-dark.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-light-increased-contrast.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-light.d.ts +2 -2
- package/dist/types/artifacts/token-default-values.d.ts +2 -2
- package/dist/types/artifacts/tokens-raw/atlassian-dark-increased-contrast.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-light-increased-contrast.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-motion.d.ts +1 -1
- package/dist/types/artifacts/types-internal.d.ts +2 -2
- package/dist/types/artifacts/types.d.ts +2 -2
- package/dist/types/custom-theme.d.ts +1 -20
- package/dist/types/entry-points/token-metadata.codegen.d.ts +1 -1
- package/dist/types/get-custom-theme-styles.d.ts +16 -0
- package/dist/types/get-global-theme.d.ts +1 -1
- package/dist/types/theme-color-modes.d.ts +7 -0
- package/dist/types/theme-config.d.ts +4 -14
- package/dist/types/theme-ids.d.ts +7 -0
- package/dist/types/theme-state-transformer.d.ts +1 -1
- package/dist/types/utils/color-detection.d.ts +1 -6
- package/dist/types/utils/color-utils.d.ts +5 -5
- package/dist/types/utils/custom-theme-loading-utils.d.ts +1 -2
- package/dist/types/utils/generate-custom-color-ramp.d.ts +1 -2
- package/dist/types/utils/get-alpha.d.ts +1 -0
- package/dist/types/utils/get-closest-color-index.d.ts +2 -0
- package/dist/types/utils/get-css-custom-property.d.ts +15 -0
- package/dist/types/utils/get-fully-qualified-token-id.d.ts +11 -0
- package/dist/types/utils/get-theme-override-preferences.d.ts +2 -0
- package/dist/types/utils/get-theme-preferences.d.ts +1 -1
- package/dist/types/utils/get-token-id.d.ts +15 -0
- package/dist/types/utils/hct-color-utils/argb-from-rgb.d.ts +4 -0
- package/dist/types/utils/hct-color-utils/clamp-double.d.ts +7 -0
- package/dist/types/utils/hct-color-utils/clamp-int.d.ts +7 -0
- package/dist/types/utils/hct-color-utils/color-utils.d.ts +3 -23
- package/dist/types/utils/hct-color-utils/delinearized.d.ts +9 -0
- package/dist/types/utils/hct-color-utils/hct.d.ts +3 -48
- package/dist/types/utils/hct-color-utils/lerp.d.ts +6 -0
- package/dist/types/utils/hct-color-utils/linearized.d.ts +9 -0
- package/dist/types/utils/hct-color-utils/math-utils.d.ts +6 -60
- package/dist/types/utils/hct-color-utils/matrix-multiply.d.ts +4 -0
- package/dist/types/utils/hct-color-utils/sanitize-degrees-double.d.ts +7 -0
- package/dist/types/utils/hct-color-utils/signum.d.ts +6 -0
- package/dist/types/utils/hct-color-utils/viewing-conditions.d.ts +47 -0
- package/dist/types/utils/hex-to-rgba-values.d.ts +6 -0
- package/dist/types/utils/hsl-to-rgb.d.ts +1 -0
- package/dist/types/utils/is-valid-brand-hex.d.ts +1 -0
- package/dist/types/utils/limit-size-of-custom-style-elements.d.ts +1 -0
- package/dist/types/utils/load-theme-css.d.ts +2 -0
- package/dist/types/utils/relative-luminance-w3-c.d.ts +1 -0
- package/dist/types/utils/rgb-to-hex.d.ts +1 -0
- package/dist/types/utils/theme-loading.d.ts +1 -1
- package/dist/types/utils/token-ids.d.ts +3 -41
- package/dist/types-ts4.5/artifacts/replacement-mapping.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/themes/atlassian-dark-increased-contrast.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-dark.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-light-increased-contrast.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-light.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/token-default-values.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark-increased-contrast.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-light-increased-contrast.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-motion.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/types-internal.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/types.d.ts +2 -2
- package/dist/types-ts4.5/custom-theme.d.ts +1 -20
- package/dist/types-ts4.5/entry-points/token-metadata.codegen.d.ts +1 -1
- package/dist/types-ts4.5/get-custom-theme-styles.d.ts +16 -0
- package/dist/types-ts4.5/get-global-theme.d.ts +1 -1
- package/dist/types-ts4.5/theme-color-modes.d.ts +11 -0
- package/dist/types-ts4.5/theme-config.d.ts +4 -29
- package/dist/types-ts4.5/theme-ids.d.ts +18 -0
- package/dist/types-ts4.5/theme-state-transformer.d.ts +1 -1
- package/dist/types-ts4.5/utils/color-detection.d.ts +1 -6
- package/dist/types-ts4.5/utils/color-utils.d.ts +5 -9
- package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +1 -2
- package/dist/types-ts4.5/utils/generate-custom-color-ramp.d.ts +1 -2
- package/dist/types-ts4.5/utils/get-alpha.d.ts +1 -0
- package/dist/types-ts4.5/utils/get-closest-color-index.d.ts +2 -0
- package/dist/types-ts4.5/utils/get-css-custom-property.d.ts +15 -0
- package/dist/types-ts4.5/utils/get-fully-qualified-token-id.d.ts +11 -0
- package/dist/types-ts4.5/utils/get-theme-override-preferences.d.ts +2 -0
- package/dist/types-ts4.5/utils/get-theme-preferences.d.ts +1 -1
- package/dist/types-ts4.5/utils/get-token-id.d.ts +15 -0
- package/dist/types-ts4.5/utils/hct-color-utils/argb-from-rgb.d.ts +4 -0
- package/dist/types-ts4.5/utils/hct-color-utils/clamp-double.d.ts +7 -0
- package/dist/types-ts4.5/utils/hct-color-utils/clamp-int.d.ts +7 -0
- package/dist/types-ts4.5/utils/hct-color-utils/color-utils.d.ts +3 -23
- package/dist/types-ts4.5/utils/hct-color-utils/delinearized.d.ts +9 -0
- package/dist/types-ts4.5/utils/hct-color-utils/hct.d.ts +3 -48
- package/dist/types-ts4.5/utils/hct-color-utils/lerp.d.ts +6 -0
- package/dist/types-ts4.5/utils/hct-color-utils/linearized.d.ts +9 -0
- package/dist/types-ts4.5/utils/hct-color-utils/math-utils.d.ts +6 -60
- package/dist/types-ts4.5/utils/hct-color-utils/matrix-multiply.d.ts +4 -0
- package/dist/types-ts4.5/utils/hct-color-utils/sanitize-degrees-double.d.ts +7 -0
- package/dist/types-ts4.5/utils/hct-color-utils/signum.d.ts +6 -0
- package/dist/types-ts4.5/utils/hct-color-utils/viewing-conditions.d.ts +47 -0
- package/dist/types-ts4.5/utils/hex-to-rgba-values.d.ts +6 -0
- package/dist/types-ts4.5/utils/hsl-to-rgb.d.ts +5 -0
- package/dist/types-ts4.5/utils/is-valid-brand-hex.d.ts +1 -0
- package/dist/types-ts4.5/utils/limit-size-of-custom-style-elements.d.ts +1 -0
- package/dist/types-ts4.5/utils/load-theme-css.d.ts +2 -0
- package/dist/types-ts4.5/utils/relative-luminance-w3-c.d.ts +1 -0
- package/dist/types-ts4.5/utils/rgb-to-hex.d.ts +1 -0
- package/dist/types-ts4.5/utils/theme-loading.d.ts +1 -1
- package/dist/types-ts4.5/utils/token-ids.d.ts +3 -41
- package/figma/atlassian-dark-increased-contrast.json +1 -1
- package/figma/atlassian-dark.json +1 -1
- package/figma/atlassian-light-increased-contrast.json +1 -1
- package/figma/atlassian-light.json +1 -1
- package/package.json +12 -12
- package/tokens.docs.tsx +48 -46
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/tokens
|
|
2
2
|
|
|
3
|
+
## 13.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`6ae1bed1867c5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6ae1bed1867c5) -
|
|
8
|
+
[ux] Updated `color.background.disabled` to use a stronger neutral palette value (`Neutral200A` in
|
|
9
|
+
light themes, `DarkNeutral300A` in dark themes).
|
|
10
|
+
|
|
11
|
+
## 13.0.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`591568c487e99`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/591568c487e99) -
|
|
16
|
+
Moved "motion.easing.spring" token into experimental state
|
|
17
|
+
|
|
3
18
|
## 13.0.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Declaration, Node, Rule } from 'postcss';
|
|
2
2
|
|
|
3
|
-
import { uniqueWordsFromTokens } from '../../utils/tokens';
|
|
3
|
+
import { uniqueWordsFromTokens } from '../../utils/unique-words-from-tokens';
|
|
4
4
|
|
|
5
5
|
import { extractCssVarName } from './declaration';
|
|
6
6
|
import { knownNamedColors, knownRawColors, knownVariables } from './legacy-colors';
|
|
@@ -3,21 +3,23 @@ import { hasImportDeclaration, isDecendantOfType } from '@hypermod/utils';
|
|
|
3
3
|
import type { API, Collection, FileInfo, JSCodeshift, TemplateElement } from 'jscodeshift';
|
|
4
4
|
|
|
5
5
|
import CSSTransformer from '../css-to-design-tokens/transform';
|
|
6
|
-
import { activeTokens } from '../utils/tokens';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
isHardCodedColor,
|
|
14
|
-
isLegacyColor,
|
|
15
|
-
isLegacyNamedColor,
|
|
16
|
-
} from './utils/color';
|
|
17
|
-
import { containsReplaceableCSSDeclarations, findEndIndexOfCSSExpression } from './utils/css-utils';
|
|
6
|
+
import { activeTokens } from '../utils/active-tokens';
|
|
7
|
+
|
|
8
|
+
import { cleanMeta } from './utils/clean-meta';
|
|
9
|
+
import { includesHardCodedColor, isHardCodedColor } from './utils/color';
|
|
10
|
+
import { containsReplaceableCSSDeclarations } from './utils/contains-replaceable-css-declarations';
|
|
11
|
+
import { findEndIndexOfCSSExpression } from './utils/find-end-index-of-css-expression';
|
|
12
|
+
import { findFirstNonspaceIndexAfter } from './utils/find-first-nonspace-index-after';
|
|
18
13
|
import Search from './utils/fuzzy-search';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
14
|
+
import { getMetaFromAncestors } from './utils/get-meta-from-ancestors';
|
|
15
|
+
import { isBoldColor } from './utils/is-bold-color';
|
|
16
|
+
import { isDecendantOfToken } from './utils/is-decendant-of-token';
|
|
17
|
+
import { isLegacyColor } from './utils/is-legacy-color';
|
|
18
|
+
import { isLegacyNamedColor } from './utils/is-legacy-named-color';
|
|
19
|
+
import { isParentOfToken } from './utils/is-parent-of-token';
|
|
20
|
+
import { kebabize } from './utils/kebabize';
|
|
21
|
+
import { legacyColorMetaMap } from './utils/legacy-color-meta-map';
|
|
22
|
+
import { splitAtIndex } from './utils/split-at-index';
|
|
21
23
|
|
|
22
24
|
function insertTokenImport(j: JSCodeshift, source: Collection<any>) {
|
|
23
25
|
if (hasImportDeclaration(j, source, '@atlaskit/tokens')) {
|
|
@@ -1,151 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { uniqueWordsFromTokens } from '../../utils/tokens';
|
|
4
|
-
|
|
5
|
-
import { getClosestDecendantOfType } from './ast';
|
|
6
|
-
|
|
7
|
-
export function getMetaFromAncestors(
|
|
8
|
-
j: core.JSCodeshift,
|
|
9
|
-
path: any,
|
|
10
|
-
meta: string[] = [],
|
|
11
|
-
): string[] {
|
|
12
|
-
const parent = path.parentPath;
|
|
13
|
-
const grandParent = parent && parent.parentPath;
|
|
14
|
-
|
|
15
|
-
if (parent && parent.value.type === 'ObjectProperty') {
|
|
16
|
-
let value = '';
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
parent.value.key.type === 'Literal' ||
|
|
20
|
-
parent.value.key.type === 'StringLiteral' ||
|
|
21
|
-
parent.value.key.type === 'NumericLiteral'
|
|
22
|
-
) {
|
|
23
|
-
value = parent.value.key.value.toString();
|
|
24
|
-
} else {
|
|
25
|
-
value = parent.value.key.name;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
meta.push(value);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (parent && grandParent && grandParent.value.type === 'TemplateLiteral') {
|
|
32
|
-
const expressionIndex = grandParent.value.expressions.findIndex(
|
|
33
|
-
(exp: any) => exp.name === path.value.name,
|
|
34
|
-
);
|
|
35
|
-
const quasi = grandParent.value.quasis[expressionIndex];
|
|
36
|
-
const propertyName = (quasi.value.cooked || quasi.value.raw || '')
|
|
37
|
-
.replace(/\n/g, '')
|
|
38
|
-
.split(/;|{|}/)
|
|
39
|
-
.filter((el: string) => !el.match(/\.|\@|\(|\)/))
|
|
40
|
-
.pop()
|
|
41
|
-
.split(/:/g)[0]
|
|
42
|
-
.trim();
|
|
43
|
-
|
|
44
|
-
grandParent.value.quasis
|
|
45
|
-
.slice(0, expressionIndex + 1)
|
|
46
|
-
.map((q: any) => q.value.cooked)
|
|
47
|
-
// We reverse so the most nested one is first which we're more likely than not interested in
|
|
48
|
-
.reverse()
|
|
49
|
-
.some((str: string) => {
|
|
50
|
-
const result = /(hover|active|disabled|focus)/.exec(str.toLowerCase());
|
|
51
|
-
|
|
52
|
-
if (result) {
|
|
53
|
-
meta.push(result[0]);
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
meta.push(propertyName);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (parent && parent.value.type === 'JSXAttribute') {
|
|
62
|
-
if (
|
|
63
|
-
!['css', 'styles', 'style', 'fill', 'stopColor', 'startColor'].includes(
|
|
64
|
-
parent.value.name.name,
|
|
65
|
-
)
|
|
66
|
-
) {
|
|
67
|
-
meta.push(parent.value.name.name);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const closestJSXElement = getClosestDecendantOfType(j, path, j.JSXOpeningElement);
|
|
72
|
-
|
|
73
|
-
if (closestJSXElement) {
|
|
74
|
-
const jsxElementName = closestJSXElement.value.name.name;
|
|
75
|
-
const nameComponents = jsxElementName.replace(/([a-z])([A-Z])/g, '$1 $2').split(' ');
|
|
76
|
-
|
|
77
|
-
meta.push(...nameComponents);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (parent && parent.value.type === 'VariableDeclarator') {
|
|
81
|
-
meta.push(parent.value.id.name);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (parent) {
|
|
85
|
-
return getMetaFromAncestors(j, parent, meta);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return meta;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function cleanMeta(meta: string[]): string[] {
|
|
92
|
-
return meta
|
|
93
|
-
.reduce<string[]>(
|
|
94
|
-
(accum, val) => [
|
|
95
|
-
...accum,
|
|
96
|
-
...(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map((e) => e.toLowerCase()) : []),
|
|
97
|
-
],
|
|
98
|
-
[],
|
|
99
|
-
)
|
|
100
|
-
.reduce<string[]>((accum, val) => {
|
|
101
|
-
const cleanVal = val
|
|
102
|
-
.replace(/:/g, '')
|
|
103
|
-
.replace(/,/g, '')
|
|
104
|
-
.replace('grey', 'neutral')
|
|
105
|
-
.replace('skeleton', 'neutral')
|
|
106
|
-
.replace('texts', 'text')
|
|
107
|
-
.replace('red', 'danger')
|
|
108
|
-
.replace('error', 'danger')
|
|
109
|
-
.replace('invalid', 'danger')
|
|
110
|
-
.replace('removed', 'danger')
|
|
111
|
-
.replace('removal', 'danger')
|
|
112
|
-
.replace('remove', 'danger')
|
|
113
|
-
.replace('focus', 'focused')
|
|
114
|
-
.replace('valid', 'success')
|
|
115
|
-
.replace('successful', 'success')
|
|
116
|
-
.replace('risk', 'warning')
|
|
117
|
-
.replace('caution', 'warning')
|
|
118
|
-
.replace('primary', 'bold')
|
|
119
|
-
.replace('secondary', 'subtle')
|
|
120
|
-
.replace('hyperlink', 'link')
|
|
121
|
-
.replace('anchor', 'link')
|
|
122
|
-
.replace('active', 'pressed')
|
|
123
|
-
.replace('hover', 'hovered')
|
|
124
|
-
.replace('card', 'raised')
|
|
125
|
-
.replace('dragged', 'surface overlay')
|
|
126
|
-
.replace('dragging', 'surface overlay')
|
|
127
|
-
.replace('drag', 'surface overlay')
|
|
128
|
-
.replace('background-color', 'background')
|
|
129
|
-
.replace('color', 'text')
|
|
130
|
-
.replace('icons', 'icon')
|
|
131
|
-
.replace('glyph', 'icon')
|
|
132
|
-
.replace('stroke', 'border')
|
|
133
|
-
.replace('border-left', 'border')
|
|
134
|
-
.replace('border-right', 'border')
|
|
135
|
-
.replace('border-top', 'border')
|
|
136
|
-
.replace('border-bottom', 'border')
|
|
137
|
-
.replace('box-shadow', 'shadow');
|
|
138
|
-
|
|
139
|
-
accum.push(...cleanVal.split(' '));
|
|
140
|
-
|
|
141
|
-
return accum;
|
|
142
|
-
}, [])
|
|
143
|
-
.filter((val) => uniqueWordsFromTokens.includes(val))
|
|
144
|
-
.reduce<string[]>((accum, val) => {
|
|
145
|
-
if (!accum.includes(val)) {
|
|
146
|
-
accum.push(val);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return accum;
|
|
150
|
-
}, []);
|
|
151
|
-
}
|
|
1
|
+
export { getMetaFromAncestors } from './get-meta-from-ancestors';
|
|
2
|
+
export { cleanMeta } from './clean-meta';
|
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function isDecendantOfToken(j: JSCodeshift, path: ASTPath | ASTNode): boolean {
|
|
5
|
-
if (
|
|
6
|
-
'type' in path &&
|
|
7
|
-
path.type === 'CallExpression' &&
|
|
8
|
-
path.callee.type === 'Identifier' &&
|
|
9
|
-
path.callee.name === 'token'
|
|
10
|
-
) {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return j(path).closest(j.CallExpression, { callee: { name: 'token' } }).length > 0;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function isParentOfToken(j: JSCodeshift, path: any): boolean {
|
|
18
|
-
if (
|
|
19
|
-
path.type === 'CallExpression' &&
|
|
20
|
-
path.callee.type === 'Identifier' &&
|
|
21
|
-
path.callee.name === 'token'
|
|
22
|
-
) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return j(path).find(j.CallExpression, { callee: { name: 'token' } }).length > 0;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function getClosestDecendantOfType(j: JSCodeshift, path: ASTPath<any>, type: any): any {
|
|
30
|
-
if (!isDecendantOfType(j, path, type)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return j(path).closest(type).get();
|
|
35
|
-
}
|
|
1
|
+
export { isDecendantOfToken } from './is-decendant-of-token';
|
|
2
|
+
export { isParentOfToken } from './is-parent-of-token';
|
|
3
|
+
export { getClosestDecendantOfType } from './get-closest-decendant-of-type';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { uniqueWordsFromTokens } from '../../utils/unique-words-from-tokens';
|
|
2
|
+
|
|
3
|
+
export function cleanMeta(meta: string[]): string[] {
|
|
4
|
+
return meta
|
|
5
|
+
.reduce<string[]>(
|
|
6
|
+
(accum, val) => [
|
|
7
|
+
...accum,
|
|
8
|
+
...(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map((e) => e.toLowerCase()) : []),
|
|
9
|
+
],
|
|
10
|
+
[],
|
|
11
|
+
)
|
|
12
|
+
.reduce<string[]>((accum, val) => {
|
|
13
|
+
const cleanVal = val
|
|
14
|
+
.replace(/:/g, '')
|
|
15
|
+
.replace(/,/g, '')
|
|
16
|
+
.replace('grey', 'neutral')
|
|
17
|
+
.replace('skeleton', 'neutral')
|
|
18
|
+
.replace('texts', 'text')
|
|
19
|
+
.replace('red', 'danger')
|
|
20
|
+
.replace('error', 'danger')
|
|
21
|
+
.replace('invalid', 'danger')
|
|
22
|
+
.replace('removed', 'danger')
|
|
23
|
+
.replace('removal', 'danger')
|
|
24
|
+
.replace('remove', 'danger')
|
|
25
|
+
.replace('focus', 'focused')
|
|
26
|
+
.replace('valid', 'success')
|
|
27
|
+
.replace('successful', 'success')
|
|
28
|
+
.replace('risk', 'warning')
|
|
29
|
+
.replace('caution', 'warning')
|
|
30
|
+
.replace('primary', 'bold')
|
|
31
|
+
.replace('secondary', 'subtle')
|
|
32
|
+
.replace('hyperlink', 'link')
|
|
33
|
+
.replace('anchor', 'link')
|
|
34
|
+
.replace('active', 'pressed')
|
|
35
|
+
.replace('hover', 'hovered')
|
|
36
|
+
.replace('card', 'raised')
|
|
37
|
+
.replace('dragged', 'surface overlay')
|
|
38
|
+
.replace('dragging', 'surface overlay')
|
|
39
|
+
.replace('drag', 'surface overlay')
|
|
40
|
+
.replace('background-color', 'background')
|
|
41
|
+
.replace('color', 'text')
|
|
42
|
+
.replace('icons', 'icon')
|
|
43
|
+
.replace('glyph', 'icon')
|
|
44
|
+
.replace('stroke', 'border')
|
|
45
|
+
.replace('border-left', 'border')
|
|
46
|
+
.replace('border-right', 'border')
|
|
47
|
+
.replace('border-top', 'border')
|
|
48
|
+
.replace('border-bottom', 'border')
|
|
49
|
+
.replace('box-shadow', 'shadow');
|
|
50
|
+
|
|
51
|
+
accum.push(...cleanVal.split(' '));
|
|
52
|
+
|
|
53
|
+
return accum;
|
|
54
|
+
}, [])
|
|
55
|
+
.filter((val) => uniqueWordsFromTokens.includes(val))
|
|
56
|
+
.reduce<string[]>((accum, val) => {
|
|
57
|
+
if (!accum.includes(val)) {
|
|
58
|
+
accum.push(val);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return accum;
|
|
62
|
+
}, []);
|
|
63
|
+
}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import { legacyColorMixins, legacyColors } from './legacy-colors';
|
|
2
1
|
import { namedColors } from './named-colors';
|
|
3
2
|
|
|
4
|
-
export const isLegacyColor: (value: string) => boolean = (value: string) =>
|
|
5
|
-
legacyColors.includes(value);
|
|
6
|
-
|
|
7
|
-
export const isLegacyNamedColor: (value: string) => boolean = (value: string) =>
|
|
8
|
-
legacyColorMixins.includes(value);
|
|
9
|
-
|
|
10
3
|
const colorRegexp =
|
|
11
4
|
/#(?:[a-f0-9]{3}|[a-f0-9]{6}|[a-f0-9]{8})\b|(?:rgb|rgba|hsl|hsla|lch|lab|color)\([^\)]*\)/;
|
|
12
5
|
|
|
@@ -40,7 +33,6 @@ export const isHardCodedColor: (raw: string) => boolean = (raw: string) => {
|
|
|
40
33
|
return false;
|
|
41
34
|
};
|
|
42
35
|
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
36
|
+
export { isLegacyColor } from './is-legacy-color';
|
|
37
|
+
export { isLegacyNamedColor } from './is-legacy-named-color';
|
|
38
|
+
export { isBoldColor } from './is-bold-color';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isColorRelatedProperty } from '../../css-to-design-tokens/lib/declaration';
|
|
2
|
+
|
|
3
|
+
export function containsReplaceableCSSDeclarations(input: string): boolean {
|
|
4
|
+
const cssPattern = /(\S+)\s*:/g;
|
|
5
|
+
|
|
6
|
+
let match;
|
|
7
|
+
while ((match = cssPattern.exec(input)) !== null) {
|
|
8
|
+
if (isColorRelatedProperty(match[1])) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
@@ -1,35 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export function containsReplaceableCSSDeclarations(input: string): boolean {
|
|
4
|
-
const cssPattern = /(\S+)\s*:/g;
|
|
5
|
-
|
|
6
|
-
let match;
|
|
7
|
-
while ((match = cssPattern.exec(input)) !== null) {
|
|
8
|
-
if (isColorRelatedProperty(match[1])) {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function findEndIndexOfCSSExpression(text: string, isAtEndOfInput: boolean): number | null {
|
|
16
|
-
// CSS expression can end *on* a semicolon or *before* a brace. In either
|
|
17
|
-
// case we treat the remaining part of the value to cover one character
|
|
18
|
-
// before that symbol.
|
|
19
|
-
const semicolonIndex = text.indexOf(';');
|
|
20
|
-
const braceIndex = text.indexOf('}');
|
|
21
|
-
|
|
22
|
-
if (semicolonIndex === -1 && braceIndex === -1) {
|
|
23
|
-
if (isAtEndOfInput) {
|
|
24
|
-
return text.length;
|
|
25
|
-
} else {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
} else if (semicolonIndex === -1) {
|
|
29
|
-
return braceIndex - 1;
|
|
30
|
-
} else if (braceIndex === -1) {
|
|
31
|
-
return semicolonIndex - 1;
|
|
32
|
-
} else {
|
|
33
|
-
return Math.min(semicolonIndex, braceIndex) - 1;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
export { containsReplaceableCSSDeclarations } from './contains-replaceable-css-declarations';
|
|
2
|
+
export { findEndIndexOfCSSExpression } from './find-end-index-of-css-expression';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function findEndIndexOfCSSExpression(text: string, isAtEndOfInput: boolean): number | null {
|
|
2
|
+
// CSS expression can end *on* a semicolon or *before* a brace. In either
|
|
3
|
+
// case we treat the remaining part of the value to cover one character
|
|
4
|
+
// before that symbol.
|
|
5
|
+
const semicolonIndex = text.indexOf(';');
|
|
6
|
+
const braceIndex = text.indexOf('}');
|
|
7
|
+
|
|
8
|
+
if (semicolonIndex === -1 && braceIndex === -1) {
|
|
9
|
+
if (isAtEndOfInput) {
|
|
10
|
+
return text.length;
|
|
11
|
+
} else {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
} else if (semicolonIndex === -1) {
|
|
15
|
+
return braceIndex - 1;
|
|
16
|
+
} else if (braceIndex === -1) {
|
|
17
|
+
return semicolonIndex - 1;
|
|
18
|
+
} else {
|
|
19
|
+
return Math.min(semicolonIndex, braceIndex) - 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function findFirstNonspaceIndexAfter(text: string, index: number): number {
|
|
2
|
+
const rest = text.slice(index + 1);
|
|
3
|
+
const indexInRest = rest.search(/\S/);
|
|
4
|
+
if (indexInRest === -1) {
|
|
5
|
+
return text.length;
|
|
6
|
+
} else {
|
|
7
|
+
return index + 1 + indexInRest;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDecendantOfType } from '@hypermod/utils';
|
|
2
|
+
import type { ASTPath, JSCodeshift } from 'jscodeshift';
|
|
3
|
+
|
|
4
|
+
export function getClosestDecendantOfType(j: JSCodeshift, path: ASTPath<any>, type: any): any {
|
|
5
|
+
if (!isDecendantOfType(j, path, type)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return j(path).closest(type).get();
|
|
10
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type core from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
import { getClosestDecendantOfType } from './get-closest-decendant-of-type';
|
|
4
|
+
|
|
5
|
+
export function getMetaFromAncestors(
|
|
6
|
+
j: core.JSCodeshift,
|
|
7
|
+
path: any,
|
|
8
|
+
meta: string[] = [],
|
|
9
|
+
): string[] {
|
|
10
|
+
const parent = path.parentPath;
|
|
11
|
+
const grandParent = parent && parent.parentPath;
|
|
12
|
+
|
|
13
|
+
if (parent && parent.value.type === 'ObjectProperty') {
|
|
14
|
+
let value = '';
|
|
15
|
+
|
|
16
|
+
if (
|
|
17
|
+
parent.value.key.type === 'Literal' ||
|
|
18
|
+
parent.value.key.type === 'StringLiteral' ||
|
|
19
|
+
parent.value.key.type === 'NumericLiteral'
|
|
20
|
+
) {
|
|
21
|
+
value = parent.value.key.value.toString();
|
|
22
|
+
} else {
|
|
23
|
+
value = parent.value.key.name;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
meta.push(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (parent && grandParent && grandParent.value.type === 'TemplateLiteral') {
|
|
30
|
+
const expressionIndex = grandParent.value.expressions.findIndex(
|
|
31
|
+
(exp: any) => exp.name === path.value.name,
|
|
32
|
+
);
|
|
33
|
+
const quasi = grandParent.value.quasis[expressionIndex];
|
|
34
|
+
const propertyName = (quasi.value.cooked || quasi.value.raw || '')
|
|
35
|
+
.replace(/\n/g, '')
|
|
36
|
+
.split(/;|{|}/)
|
|
37
|
+
.filter((el: string) => !el.match(/\.|\@|\(|\)/))
|
|
38
|
+
.pop()
|
|
39
|
+
.split(/:/g)[0]
|
|
40
|
+
.trim();
|
|
41
|
+
|
|
42
|
+
grandParent.value.quasis
|
|
43
|
+
.slice(0, expressionIndex + 1)
|
|
44
|
+
.map((q: any) => q.value.cooked)
|
|
45
|
+
// We reverse so the most nested one is first which we're more likely than not interested in
|
|
46
|
+
.reverse()
|
|
47
|
+
.some((str: string) => {
|
|
48
|
+
const result = /(hover|active|disabled|focus)/.exec(str.toLowerCase());
|
|
49
|
+
|
|
50
|
+
if (result) {
|
|
51
|
+
meta.push(result[0]);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
meta.push(propertyName);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (parent && parent.value.type === 'JSXAttribute') {
|
|
60
|
+
if (
|
|
61
|
+
!['css', 'styles', 'style', 'fill', 'stopColor', 'startColor'].includes(
|
|
62
|
+
parent.value.name.name,
|
|
63
|
+
)
|
|
64
|
+
) {
|
|
65
|
+
meta.push(parent.value.name.name);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const closestJSXElement = getClosestDecendantOfType(j, path, j.JSXOpeningElement);
|
|
70
|
+
|
|
71
|
+
if (closestJSXElement) {
|
|
72
|
+
const jsxElementName = closestJSXElement.value.name.name;
|
|
73
|
+
const nameComponents = jsxElementName.replace(/([a-z])([A-Z])/g, '$1 $2').split(' ');
|
|
74
|
+
|
|
75
|
+
meta.push(...nameComponents);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (parent && parent.value.type === 'VariableDeclarator') {
|
|
79
|
+
meta.push(parent.value.id.name);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (parent) {
|
|
83
|
+
return getMetaFromAncestors(j, parent, meta);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return meta;
|
|
87
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ASTNode, ASTPath, JSCodeshift } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
export function isDecendantOfToken(j: JSCodeshift, path: ASTPath | ASTNode): boolean {
|
|
4
|
+
if (
|
|
5
|
+
'type' in path &&
|
|
6
|
+
path.type === 'CallExpression' &&
|
|
7
|
+
path.callee.type === 'Identifier' &&
|
|
8
|
+
path.callee.name === 'token'
|
|
9
|
+
) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return j(path).closest(j.CallExpression, { callee: { name: 'token' } }).length > 0;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JSCodeshift } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
export function isParentOfToken(j: JSCodeshift, path: any): boolean {
|
|
4
|
+
if (
|
|
5
|
+
path.type === 'CallExpression' &&
|
|
6
|
+
path.callee.type === 'Identifier' &&
|
|
7
|
+
path.callee.name === 'token'
|
|
8
|
+
) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return j(path).find(j.CallExpression, { callee: { name: 'token' } }).length > 0;
|
|
13
|
+
}
|