@atlaskit/tokens 13.0.2 → 13.0.4
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 +18 -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/tokens-raw/atlassian-motion.js +3 -3
- package/dist/cjs/custom-theme.js +10 -60
- package/dist/cjs/entry-points/token-metadata.codegen.js +1 -10
- 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 +6 -5
- package/dist/cjs/load-custom-theme-styles.js +2 -2
- package/dist/cjs/set-global-theme.js +4 -3
- package/dist/cjs/theme-color-modes.js +13 -0
- package/dist/cjs/theme-config.js +19 -16
- package/dist/cjs/theme-ids.js +13 -0
- package/dist/cjs/theme-state-transformer.js +2 -2
- package/dist/cjs/utils/color-detection.js +9 -12
- package/dist/cjs/utils/color-utils.js +38 -47
- package/dist/cjs/utils/custom-theme-loading-utils.js +7 -11
- package/dist/cjs/utils/generate-custom-color-ramp.js +16 -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 +34 -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 +10 -25
- package/dist/cjs/utils/token-ids.js +21 -62
- package/dist/es2019/artifacts/replacement-mapping.js +5 -2
- package/dist/es2019/artifacts/tokens-raw/atlassian-motion.js +3 -3
- package/dist/es2019/custom-theme.js +4 -66
- package/dist/es2019/entry-points/token-metadata.codegen.js +1 -10
- 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 +4 -16
- package/dist/es2019/theme-ids.js +7 -0
- package/dist/es2019/theme-state-transformer.js +1 -1
- package/dist/es2019/utils/color-detection.js +3 -11
- package/dist/es2019/utils/color-utils.js +8 -34
- package/dist/es2019/utils/custom-theme-loading-utils.js +2 -8
- package/dist/es2019/utils/generate-custom-color-ramp.js +7 -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 +7 -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/tokens-raw/atlassian-motion.js +3 -3
- package/dist/esm/custom-theme.js +4 -58
- package/dist/esm/entry-points/token-metadata.codegen.js +1 -10
- 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 +4 -3
- package/dist/esm/load-custom-theme-styles.js +1 -1
- package/dist/esm/set-global-theme.js +3 -2
- package/dist/esm/theme-color-modes.js +7 -0
- package/dist/esm/theme-config.js +6 -17
- package/dist/esm/theme-ids.js +7 -0
- package/dist/esm/theme-state-transformer.js +1 -1
- package/dist/esm/utils/color-detection.js +3 -11
- package/dist/esm/utils/color-utils.js +8 -40
- package/dist/esm/utils/custom-theme-loading-utils.js +2 -11
- package/dist/esm/utils/generate-custom-color-ramp.js +7 -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 +7 -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 +3 -24
- package/dist/esm/utils/token-ids.js +3 -61
- package/dist/types/artifacts/replacement-mapping.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/css-type-schema.codegen.d.ts +2 -2
- 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/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/css-type-schema.codegen.d.ts +2 -2
- 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/package.json +7 -7
- package/offerings.json +0 -44
|
@@ -7,12 +7,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _constants = require("./constants");
|
|
10
|
-
var
|
|
10
|
+
var _themeColorModes = require("./theme-color-modes");
|
|
11
11
|
var _themeStateTransformer = require("./theme-state-transformer");
|
|
12
12
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
13
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
14
|
var isThemeColorMode = function isThemeColorMode(colorMode) {
|
|
15
|
-
return
|
|
15
|
+
return _themeColorModes.themeColorModes.find(function (mode) {
|
|
16
16
|
return mode === colorMode;
|
|
17
17
|
}) !== undefined;
|
|
18
18
|
};
|
|
@@ -10,8 +10,8 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
|
10
10
|
var _constants = require("./constants");
|
|
11
11
|
var _themeConfig = require("./theme-config");
|
|
12
12
|
var _themeStateTransformer = require("./theme-state-transformer");
|
|
13
|
-
var _colorUtils = require("./utils/color-utils");
|
|
14
13
|
var _hash = require("./utils/hash");
|
|
14
|
+
var _isValidBrandHex = require("./utils/is-valid-brand-hex");
|
|
15
15
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
16
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
17
|
var defaultColorMode = 'light';
|
|
@@ -64,7 +64,7 @@ var getThemeHtmlAttrs = function getThemeHtmlAttrs() {
|
|
|
64
64
|
if ((0, _platformFeatureFlags.fg)('platform_increased-contrast-themes')) {
|
|
65
65
|
result = _objectSpread(_objectSpread({}, result), {}, (0, _defineProperty2.default)({}, _constants.CONTRAST_MODE_ATTRIBUTE, contrastMode === 'auto' ? defaultContrastMode : contrastMode));
|
|
66
66
|
}
|
|
67
|
-
if (UNSAFE_themeOptions && (0,
|
|
67
|
+
if (UNSAFE_themeOptions && (0, _isValidBrandHex.isValidBrandHex)(UNSAFE_themeOptions.brandColor)) {
|
|
68
68
|
var optionString = JSON.stringify(UNSAFE_themeOptions);
|
|
69
69
|
var uniqueId = (0, _hash.hash)(optionString);
|
|
70
70
|
result[_constants.CUSTOM_THEME_ATTRIBUTE] = uniqueId;
|
|
@@ -11,9 +11,10 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
11
11
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
12
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
13
|
var _themeConfig = require("./theme-config");
|
|
14
|
-
var
|
|
14
|
+
var _getThemeOverridePreferences = require("./utils/get-theme-override-preferences");
|
|
15
15
|
var _getThemePreferences = require("./utils/get-theme-preferences");
|
|
16
|
-
var
|
|
16
|
+
var _isValidBrandHex = require("./utils/is-valid-brand-hex");
|
|
17
|
+
var _loadThemeCss = require("./utils/load-theme-css");
|
|
17
18
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
18
19
|
/**
|
|
19
20
|
* Takes an object containing theme preferences, and returns an array of objects for use in applying styles to the document head.
|
|
@@ -60,7 +61,7 @@ var getThemeStyles = /*#__PURE__*/function () {
|
|
|
60
61
|
typography: (preferences === null || preferences === void 0 ? void 0 : preferences.typography) || _themeConfig.themeStateDefaults['typography']
|
|
61
62
|
};
|
|
62
63
|
themePreferences = (0, _getThemePreferences.getThemePreferences)(themeState);
|
|
63
|
-
themeOverridePreferences = (0,
|
|
64
|
+
themeOverridePreferences = (0, _getThemeOverridePreferences.getThemeOverridePreferences)(themeState);
|
|
64
65
|
}
|
|
65
66
|
_context3.next = 4;
|
|
66
67
|
return Promise.all([].concat((0, _toConsumableArray2.default)([].concat((0, _toConsumableArray2.default)(themePreferences), (0, _toConsumableArray2.default)(themeOverridePreferences)).map( /*#__PURE__*/function () {
|
|
@@ -71,7 +72,7 @@ var getThemeStyles = /*#__PURE__*/function () {
|
|
|
71
72
|
case 0:
|
|
72
73
|
_context.prev = 0;
|
|
73
74
|
_context.next = 3;
|
|
74
|
-
return (0,
|
|
75
|
+
return (0, _loadThemeCss.loadThemeCss)(themeId);
|
|
75
76
|
case 3:
|
|
76
77
|
css = _context.sent;
|
|
77
78
|
return _context.abrupt("return", {
|
|
@@ -102,7 +103,7 @@ var getThemeStyles = /*#__PURE__*/function () {
|
|
|
102
103
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
103
104
|
while (1) switch (_context2.prev = _context2.next) {
|
|
104
105
|
case 0:
|
|
105
|
-
if (!(preferences !== 'all' && preferences !== null && preferences !== void 0 && preferences.UNSAFE_themeOptions && (0,
|
|
106
|
+
if (!(preferences !== 'all' && preferences !== null && preferences !== void 0 && preferences.UNSAFE_themeOptions && (0, _isValidBrandHex.isValidBrandHex)(preferences === null || preferences === void 0 || (_preferences$UNSAFE_t = preferences.UNSAFE_themeOptions) === null || _preferences$UNSAFE_t === void 0 ? void 0 : _preferences$UNSAFE_t.brandColor))) {
|
|
106
107
|
_context2.next = 15;
|
|
107
108
|
break;
|
|
108
109
|
}
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _customTheme = require("./custom-theme");
|
|
8
8
|
var _themeConfig = require("./theme-config");
|
|
9
|
-
var _colorUtils = require("./utils/color-utils");
|
|
10
9
|
var _customThemeLoadingUtils = require("./utils/custom-theme-loading-utils");
|
|
10
|
+
var _isValidBrandHex = require("./utils/is-valid-brand-hex");
|
|
11
11
|
/**
|
|
12
12
|
* Synchronously generates and applies custom theme styles to the page.
|
|
13
13
|
*
|
|
@@ -29,7 +29,7 @@ var UNSAFE_loadCustomThemeStyles = function UNSAFE_loadCustomThemeStyles() {
|
|
|
29
29
|
_ref$UNSAFE_themeOpti = _ref.UNSAFE_themeOptions,
|
|
30
30
|
UNSAFE_themeOptions = _ref$UNSAFE_themeOpti === void 0 ? _themeConfig.themeStateDefaults['UNSAFE_themeOptions'] : _ref$UNSAFE_themeOpti;
|
|
31
31
|
// Load custom theme styles
|
|
32
|
-
if (UNSAFE_themeOptions && (0,
|
|
32
|
+
if (UNSAFE_themeOptions && (0, _isValidBrandHex.isValidBrandHex)(UNSAFE_themeOptions === null || UNSAFE_themeOptions === void 0 ? void 0 : UNSAFE_themeOptions.brandColor)) {
|
|
33
33
|
var attrOfMissingCustomStyles = (0, _customThemeLoadingUtils.findMissingCustomStyleElements)(UNSAFE_themeOptions, colorMode);
|
|
34
34
|
if (attrOfMissingCustomStyles.length !== 0) {
|
|
35
35
|
(0, _customTheme.loadAndAppendCustomThemeCss)({
|
|
@@ -12,10 +12,11 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
12
12
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
13
|
var _getGlobalTheme = _interopRequireDefault(require("./get-global-theme"));
|
|
14
14
|
var _themeConfig = require("./theme-config");
|
|
15
|
-
var _colorUtils = require("./utils/color-utils");
|
|
16
15
|
var _configurePage = _interopRequireDefault(require("./utils/configure-page"));
|
|
17
16
|
var _customThemeLoadingUtils = require("./utils/custom-theme-loading-utils");
|
|
17
|
+
var _getThemeOverridePreferences = require("./utils/get-theme-override-preferences");
|
|
18
18
|
var _getThemePreferences = require("./utils/get-theme-preferences");
|
|
19
|
+
var _isValidBrandHex = require("./utils/is-valid-brand-hex");
|
|
19
20
|
var _themeLoading = require("./utils/theme-loading");
|
|
20
21
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
21
22
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
@@ -131,7 +132,7 @@ var setGlobalTheme = /*#__PURE__*/function () {
|
|
|
131
132
|
return _ref3.apply(this, arguments);
|
|
132
133
|
};
|
|
133
134
|
}()); // Load custom themes if needed
|
|
134
|
-
if (!themeLoader && UNSAFE_themeOptions && (0,
|
|
135
|
+
if (!themeLoader && UNSAFE_themeOptions && (0, _isValidBrandHex.isValidBrandHex)(UNSAFE_themeOptions === null || UNSAFE_themeOptions === void 0 ? void 0 : UNSAFE_themeOptions.brandColor)) {
|
|
135
136
|
mode = colorMode || _themeConfig.themeStateDefaults['colorMode'];
|
|
136
137
|
attrOfMissingCustomStyles = (0, _customThemeLoadingUtils.findMissingCustomStyleElements)(UNSAFE_themeOptions, mode);
|
|
137
138
|
if (attrOfMissingCustomStyles.length > 0) {
|
|
@@ -167,7 +168,7 @@ var setGlobalTheme = /*#__PURE__*/function () {
|
|
|
167
168
|
return Promise.all(loadingTasks);
|
|
168
169
|
case 11:
|
|
169
170
|
// Load override themes after standard themes
|
|
170
|
-
themeOverridePreferences = (0,
|
|
171
|
+
themeOverridePreferences = (0, _getThemeOverridePreferences.getThemeOverridePreferences)(themeState);
|
|
171
172
|
_iterator = _createForOfIteratorHelper(themeOverridePreferences);
|
|
172
173
|
_context3.prev = 13;
|
|
173
174
|
_iterator.s();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.themeColorModes = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Theme modes: The general purpose of a theme.
|
|
9
|
+
* This attr is used to apply the appropriate system-preference option
|
|
10
|
+
* It may also be used as a selector for mode-specific overrides such as light/dark images.
|
|
11
|
+
* The idea is there may exist many color themes, but every theme must either fit into light or dark.
|
|
12
|
+
*/
|
|
13
|
+
var themeColorModes = exports.themeColorModes = ['light', 'dark', 'auto'];
|
package/dist/cjs/theme-config.js
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports.
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
Object.defineProperty(exports, "themeColorModes", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _themeColorModes.themeColorModes;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "themeIds", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _themeIds.themeIds;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
exports.themeStateDefaults = exports.themeIdsWithOverrides = void 0;
|
|
21
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
22
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
23
|
+
var _themeIds = require("./theme-ids");
|
|
24
|
+
var _themeColorModes = require("./theme-color-modes");
|
|
8
25
|
/**
|
|
9
26
|
* This file contains the source of truth for themes and all associated meta data.
|
|
10
27
|
*/
|
|
@@ -28,30 +45,16 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
|
28
45
|
* In the future other types may be introduced such as typography.
|
|
29
46
|
*/
|
|
30
47
|
|
|
31
|
-
/**
|
|
32
|
-
* Theme modes: The general purpose of a theme.
|
|
33
|
-
* This attr is used to apply the appropriate system-preference option
|
|
34
|
-
* It may also be used as a selector for mode-specific overrides such as light/dark images.
|
|
35
|
-
* The idea is there may exist many color themes, but every theme must either fit into light or dark.
|
|
36
|
-
*/
|
|
37
|
-
var themeColorModes = exports.themeColorModes = ['light', 'dark', 'auto'];
|
|
38
48
|
/**
|
|
39
49
|
* Contrast preferences: The system contrast preference
|
|
40
50
|
*/
|
|
41
51
|
var themeContrastModes = ['more', 'no-preference', 'auto'];
|
|
42
|
-
/**
|
|
43
|
-
* Theme ids: The value that will be mounted to the DOM as a data attr
|
|
44
|
-
* For example: `data-theme="light:light dark:dark spacing:spacing"
|
|
45
|
-
*
|
|
46
|
-
* These ids must be kebab case
|
|
47
|
-
*/
|
|
48
|
-
var themeIds = exports.themeIds = ['light-increased-contrast', 'light', 'light-future', 'dark', 'dark-future', 'dark-increased-contrast', 'spacing', 'shape', 'typography', 'motion'];
|
|
49
52
|
/**
|
|
50
53
|
* Theme override ids: the equivalent of themeIds for theme overrides.
|
|
51
54
|
* Theme overrides are temporary and there may not be any defined at times.
|
|
52
55
|
*/
|
|
53
56
|
var themeOverrideIds = [];
|
|
54
|
-
var themeIdsWithOverrides = exports.themeIdsWithOverrides = [].concat(themeIds, themeOverrideIds);
|
|
57
|
+
var themeIdsWithOverrides = exports.themeIdsWithOverrides = [].concat((0, _toConsumableArray2.default)(_themeIds.themeIds), themeOverrideIds);
|
|
55
58
|
|
|
56
59
|
/**
|
|
57
60
|
* Theme to use a base. This will create the theme as
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.themeIds = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Theme ids: The value that will be mounted to the DOM as a data attr
|
|
9
|
+
* For example: `data-theme="light:light dark:dark spacing:spacing"
|
|
10
|
+
*
|
|
11
|
+
* These ids must be kebab case
|
|
12
|
+
*/
|
|
13
|
+
var themeIds = exports.themeIds = ['light-increased-contrast', 'light', 'light-future', 'dark', 'dark-future', 'dark-increased-contrast', 'spacing', 'shape', 'typography', 'motion'];
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.themeStringToObject = exports.themeObjectToString = void 0;
|
|
8
8
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
-
var
|
|
10
|
+
var _themeIds = require("./theme-ids");
|
|
11
11
|
var themeKinds = ['light', 'dark', 'spacing', 'typography', 'shape', 'motion'];
|
|
12
12
|
var customThemeOptions = 'UNSAFE_themeOptions';
|
|
13
13
|
var isThemeKind = function isThemeKind(themeKind) {
|
|
@@ -16,7 +16,7 @@ var isThemeKind = function isThemeKind(themeKind) {
|
|
|
16
16
|
}) !== undefined;
|
|
17
17
|
};
|
|
18
18
|
var isThemeIds = function isThemeIds(themeId) {
|
|
19
|
-
return
|
|
19
|
+
return _themeIds.themeIds.find(function (id) {
|
|
20
20
|
return id === themeId;
|
|
21
21
|
}) !== undefined;
|
|
22
22
|
};
|
|
@@ -3,17 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
|
|
6
|
+
exports.getBoxShadow = void 0;
|
|
7
|
+
Object.defineProperty(exports, "hexToRGBAValues", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _hexToRgbaValues.hexToRGBAValues;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _hexToRgbaValues = require("./hex-to-rgba-values");
|
|
17
14
|
/**
|
|
18
15
|
* Returns a box shadow formatted for CSS from a ShadowToken raw value.
|
|
19
16
|
*
|
|
@@ -25,7 +22,7 @@ var getBoxShadow = exports.getBoxShadow = function getBoxShadow(rawShadow) {
|
|
|
25
22
|
offset = _ref.offset,
|
|
26
23
|
color = _ref.color,
|
|
27
24
|
opacity = _ref.opacity;
|
|
28
|
-
var _hexToRGBAValues = hexToRGBAValues(color),
|
|
25
|
+
var _hexToRGBAValues = (0, _hexToRgbaValues.hexToRGBAValues)(color),
|
|
29
26
|
r = _hexToRGBAValues.r,
|
|
30
27
|
g = _hexToRGBAValues.g,
|
|
31
28
|
b = _hexToRGBAValues.b;
|
|
@@ -3,35 +3,50 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
Object.defineProperty(exports, "HSLToRGB", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _hslToRgb.HSLToRGB;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
7
12
|
exports.deltaE = deltaE;
|
|
8
|
-
exports
|
|
13
|
+
Object.defineProperty(exports, "getAlpha", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _getAlpha.getAlpha;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
9
19
|
exports.getContrastRatio = getContrastRatio;
|
|
10
20
|
exports.hexToHSL = hexToHSL;
|
|
11
21
|
exports.hexToRgb = hexToRgb;
|
|
12
22
|
exports.hexToRgbA = hexToRgbA;
|
|
13
|
-
exports
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
Object.defineProperty(exports, "isValidBrandHex", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function get() {
|
|
26
|
+
return _isValidBrandHex.isValidBrandHex;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(exports, "relativeLuminanceW3C", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function get() {
|
|
32
|
+
return _relativeLuminanceW3C.relativeLuminanceW3C;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "rgbToHex", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function get() {
|
|
38
|
+
return _rgbToHex.rgbToHex;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
var _getAlpha = require("./get-alpha");
|
|
42
|
+
var _relativeLuminanceW3C = require("./relative-luminance-w3-c");
|
|
43
|
+
var _isValidBrandHex = require("./is-valid-brand-hex");
|
|
44
|
+
var _rgbToHex = require("./rgb-to-hex");
|
|
45
|
+
var _hslToRgb = require("./hsl-to-rgb");
|
|
21
46
|
// valid hex color with 4, 6 or 8 digits
|
|
22
47
|
var isValidHex = function isValidHex(hex) {
|
|
23
48
|
return /^#([A-Fa-f0-9]{3,4}){1,2}$/.test(hex);
|
|
24
49
|
};
|
|
25
|
-
function rgbToHex(r, g, b) {
|
|
26
|
-
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
|
27
|
-
}
|
|
28
|
-
function getAlpha(hex) {
|
|
29
|
-
if (hex.length === 9) {
|
|
30
|
-
var int = parseInt(hex.slice(7, 9), 16) / 255;
|
|
31
|
-
return Number(parseFloat(int.toString()).toFixed(2));
|
|
32
|
-
}
|
|
33
|
-
return 1;
|
|
34
|
-
}
|
|
35
50
|
function hexToRgbA(hex) {
|
|
36
51
|
if (!isValidHex(hex)) {
|
|
37
52
|
throw new Error('Invalid HEX');
|
|
@@ -42,7 +57,7 @@ function hexToRgbA(hex) {
|
|
|
42
57
|
c = [c[0], c[0], c[1], c[1], c[2], c[2]];
|
|
43
58
|
}
|
|
44
59
|
c = '0x' + c.join('');
|
|
45
|
-
return [c >> 16 & 255, c >> 8 & 255, c & 255, getAlpha(hex)];
|
|
60
|
+
return [c >> 16 & 255, c >> 8 & 255, c & 255, (0, _getAlpha.getAlpha)(hex)];
|
|
46
61
|
}
|
|
47
62
|
function hexToRgb(hex) {
|
|
48
63
|
if (!isValidHex(hex)) {
|
|
@@ -101,38 +116,14 @@ function hexToHSL(hex) {
|
|
|
101
116
|
l = +(l * 100).toFixed(1);
|
|
102
117
|
return [h, s, l];
|
|
103
118
|
}
|
|
104
|
-
function HSLToRGB(h, s, l) {
|
|
105
|
-
s /= 100;
|
|
106
|
-
l /= 100;
|
|
107
|
-
var k = function k(n) {
|
|
108
|
-
return (n + h / 30) % 12;
|
|
109
|
-
};
|
|
110
|
-
var a = s * Math.min(l, 1 - l);
|
|
111
|
-
var f = function f(n) {
|
|
112
|
-
return l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
|
|
113
|
-
};
|
|
114
|
-
return [255 * f(0), 255 * f(8), 255 * f(4)];
|
|
115
|
-
}
|
|
116
|
-
function relativeLuminanceW3C(r, g, b) {
|
|
117
|
-
var RsRGB = r / 255;
|
|
118
|
-
var GsRGB = g / 255;
|
|
119
|
-
var BsRGB = b / 255;
|
|
120
|
-
var R = RsRGB <= 0.03928 ? RsRGB / 12.92 : Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
121
|
-
var G = GsRGB <= 0.03928 ? GsRGB / 12.92 : Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
122
|
-
var B = BsRGB <= 0.03928 ? BsRGB / 12.92 : Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
123
|
-
|
|
124
|
-
// For the sRGB colorspace, the relative luminance of a color is defined as:
|
|
125
|
-
var L = 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
126
|
-
return L;
|
|
127
|
-
}
|
|
128
119
|
function getContrastRatio(foreground, background) {
|
|
129
120
|
if (!isValidHex(foreground) || !isValidHex(background)) {
|
|
130
121
|
throw new Error('Invalid HEX');
|
|
131
122
|
}
|
|
132
123
|
var foregroundRgb = hexToRgb(foreground);
|
|
133
124
|
var backgroundRgb = hexToRgb(background);
|
|
134
|
-
var foregroundLuminance = relativeLuminanceW3C(foregroundRgb[0], foregroundRgb[1], foregroundRgb[2]);
|
|
135
|
-
var backgroundLuminance = relativeLuminanceW3C(backgroundRgb[0], backgroundRgb[1], backgroundRgb[2]);
|
|
125
|
+
var foregroundLuminance = (0, _relativeLuminanceW3C.relativeLuminanceW3C)(foregroundRgb[0], foregroundRgb[1], foregroundRgb[2]);
|
|
126
|
+
var backgroundLuminance = (0, _relativeLuminanceW3C.relativeLuminanceW3C)(backgroundRgb[0], backgroundRgb[1], backgroundRgb[2]);
|
|
136
127
|
// calculate the color contrast ratio
|
|
137
128
|
var brightest = Math.max(foregroundLuminance, backgroundLuminance);
|
|
138
129
|
var darkest = Math.min(foregroundLuminance, backgroundLuminance);
|
|
@@ -5,13 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.findMissingCustomStyleElements = findMissingCustomStyleElements;
|
|
8
|
-
exports
|
|
8
|
+
Object.defineProperty(exports, "limitSizeOfCustomStyleElements", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _limitSizeOfCustomStyleElements.limitSizeOfCustomStyleElements;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
9
14
|
exports.reduceTokenMap = reduceTokenMap;
|
|
10
15
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
16
|
var _tokenNames = _interopRequireDefault(require("../artifacts/token-names"));
|
|
13
17
|
var _constants = require("../constants");
|
|
14
18
|
var _hash = require("./hash");
|
|
19
|
+
var _limitSizeOfCustomStyleElements = require("./limit-size-of-custom-style-elements");
|
|
15
20
|
function findMissingCustomStyleElements(UNSAFE_themeOptions, mode) {
|
|
16
21
|
var optionString = JSON.stringify(UNSAFE_themeOptions);
|
|
17
22
|
var uniqueId = (0, _hash.hash)(optionString);
|
|
@@ -27,15 +32,6 @@ function findMissingCustomStyleElements(UNSAFE_themeOptions, mode) {
|
|
|
27
32
|
});
|
|
28
33
|
return attrOfMissingCustomStyles;
|
|
29
34
|
}
|
|
30
|
-
function limitSizeOfCustomStyleElements(sizeThreshold) {
|
|
31
|
-
var styleTags = (0, _toConsumableArray2.default)(Array.from(document.head.querySelectorAll("style[".concat(_constants.CUSTOM_THEME_ATTRIBUTE, "][").concat(_constants.THEME_DATA_ATTRIBUTE, "]"))));
|
|
32
|
-
if (styleTags.length < sizeThreshold) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
styleTags.slice(0, styleTags.length - (sizeThreshold - 1)).forEach(function (element) {
|
|
36
|
-
return element.remove();
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
35
|
function reduceTokenMap(tokenMap, themeRamp) {
|
|
40
36
|
return Object.entries(tokenMap).reduce(function (acc, _ref) {
|
|
41
37
|
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
@@ -4,36 +4,33 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.generateTokenMapWithContrastCheck = exports.generateTokenMap = exports.generateColors = void 0;
|
|
8
|
+
Object.defineProperty(exports, "getClosestColorIndex", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _getClosestColorIndex.getClosestColorIndex;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
8
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
15
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
16
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
17
|
var _atlassianDarkTokenValueForContrastCheck = _interopRequireDefault(require("../artifacts/atlassian-dark-token-value-for-contrast-check"));
|
|
12
18
|
var _colorUtils = require("./color-utils");
|
|
13
19
|
var _customThemeTokenContrastCheck = require("./custom-theme-token-contrast-check");
|
|
20
|
+
var _getClosestColorIndex = require("./get-closest-color-index");
|
|
14
21
|
var _hctColorUtils = require("./hct-color-utils");
|
|
22
|
+
var _hslToRgb = require("./hsl-to-rgb");
|
|
23
|
+
var _relativeLuminanceW3C = require("./relative-luminance-w3-c");
|
|
24
|
+
var _rgbToHex = require("./rgb-to-hex");
|
|
15
25
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
26
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
27
|
var lowLuminanceContrastRatios = [1.12, 1.33, 2.03, 2.73, 3.33, 4.27, 5.2, 6.62, 12.46, 14.25];
|
|
18
28
|
var highLuminanceContrastRatios = [1.08, 1.24, 1.55, 1.99, 2.45, 3.34, 4.64, 6.1, 10.19, 12.6];
|
|
19
|
-
var getClosestColorIndex = exports.getClosestColorIndex = function getClosestColorIndex(themeRamp, brandColor) {
|
|
20
|
-
// Iterate over themeRamp and find whichever color is closest to brandColor
|
|
21
|
-
var closestColorIndex = 0;
|
|
22
|
-
var closestColorDistance = null;
|
|
23
|
-
themeRamp.forEach(function (value, index) {
|
|
24
|
-
var distance = (0, _colorUtils.deltaE)((0, _colorUtils.hexToRgb)(value), (0, _colorUtils.hexToRgb)(brandColor));
|
|
25
|
-
if (closestColorDistance === null || distance < closestColorDistance) {
|
|
26
|
-
closestColorIndex = index;
|
|
27
|
-
closestColorDistance = distance;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
return closestColorIndex;
|
|
31
|
-
};
|
|
32
29
|
var generateColors = exports.generateColors = function generateColors(brandColor) {
|
|
33
30
|
// Determine luminance
|
|
34
31
|
var HSLBrandColorHue = (0, _colorUtils.hexToHSL)(brandColor)[0];
|
|
35
|
-
var baseRgb = (0,
|
|
36
|
-
var isLowLuminance = (0,
|
|
32
|
+
var baseRgb = (0, _hslToRgb.HSLToRGB)(HSLBrandColorHue, 100, 60);
|
|
33
|
+
var isLowLuminance = (0, _relativeLuminanceW3C.relativeLuminanceW3C)(baseRgb[0], baseRgb[1], baseRgb[2]) < 0.4;
|
|
37
34
|
// Choose right palette
|
|
38
35
|
var themeRatios = isLowLuminance ? lowLuminanceContrastRatios : highLuminanceContrastRatios;
|
|
39
36
|
var brandRgba = (0, _colorUtils.hexToRgbA)(brandColor);
|
|
@@ -46,9 +43,9 @@ var generateColors = exports.generateColors = function generateColors(brandColor
|
|
|
46
43
|
var themeRamp = themeRatios.map(function (contrast) {
|
|
47
44
|
var rgbaColor = (0, _hctColorUtils.rgbaFromArgb)(_hctColorUtils.Hct.from(hctColor.hue, hctColor.chroma, _hctColorUtils.Contrast.darker(100, contrast) + 0.25 // Material's utils provide an offset
|
|
48
45
|
).toInt());
|
|
49
|
-
return (0,
|
|
46
|
+
return (0, _rgbToHex.rgbToHex)(rgbaColor.r, rgbaColor.g, rgbaColor.b);
|
|
50
47
|
});
|
|
51
|
-
var closestColorIndex = getClosestColorIndex(themeRamp, brandColor);
|
|
48
|
+
var closestColorIndex = (0, _getClosestColorIndex.getClosestColorIndex)(themeRamp, brandColor);
|
|
52
49
|
|
|
53
50
|
// Replace closet color with brandColor
|
|
54
51
|
var updatedThemeRamp = (0, _toConsumableArray2.default)(themeRamp);
|
|
@@ -84,7 +81,7 @@ var generateTokenMap = exports.generateTokenMap = function generateTokenMap(bran
|
|
|
84
81
|
ramp = _generateColors.ramp,
|
|
85
82
|
replacedColor = _generateColors.replacedColor;
|
|
86
83
|
var colors = themeRamp || ramp;
|
|
87
|
-
var closestColorIndex = getClosestColorIndex(colors, brandColor);
|
|
84
|
+
var closestColorIndex = (0, _getClosestColorIndex.getClosestColorIndex)(colors, brandColor);
|
|
88
85
|
var customThemeTokenMapLight = {};
|
|
89
86
|
var customThemeTokenMapDark = {};
|
|
90
87
|
var inputContrast = (0, _colorUtils.getContrastRatio)(brandColor, '#FFFFFF');
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAlpha = getAlpha;
|
|
7
|
+
function getAlpha(hex) {
|
|
8
|
+
if (hex.length === 9) {
|
|
9
|
+
var int = parseInt(hex.slice(7, 9), 16) / 255;
|
|
10
|
+
return Number(parseFloat(int.toString()).toFixed(2));
|
|
11
|
+
}
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getClosestColorIndex = void 0;
|
|
7
|
+
var _colorUtils = require("./color-utils");
|
|
8
|
+
var getClosestColorIndex = exports.getClosestColorIndex = function getClosestColorIndex(themeRamp, brandColor) {
|
|
9
|
+
// Iterate over themeRamp and find whichever color is closest to brandColor
|
|
10
|
+
var closestColorIndex = 0;
|
|
11
|
+
var closestColorDistance = null;
|
|
12
|
+
themeRamp.forEach(function (value, index) {
|
|
13
|
+
var distance = (0, _colorUtils.deltaE)((0, _colorUtils.hexToRgb)(value), (0, _colorUtils.hexToRgb)(brandColor));
|
|
14
|
+
if (closestColorDistance === null || distance < closestColorDistance) {
|
|
15
|
+
closestColorIndex = index;
|
|
16
|
+
closestColorDistance = distance;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return closestColorIndex;
|
|
20
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getCSSCustomProperty = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _constants = require("../constants");
|
|
10
|
+
/**
|
|
11
|
+
* Transforms a style dictionary token path to a CSS custom property.
|
|
12
|
+
*
|
|
13
|
+
* A css prefix will be prepended and all [default] key words will be omitted
|
|
14
|
+
* from the path
|
|
15
|
+
*
|
|
16
|
+
* @example <caption>Passing a path as an array</caption>
|
|
17
|
+
* // Returns ds-background-bold
|
|
18
|
+
* getCSSCustomProperty(['color', 'background', 'bold', '[default]'])
|
|
19
|
+
*
|
|
20
|
+
* @example <caption>Passing a path as a string</caption>
|
|
21
|
+
* // Returns ds-background-bold
|
|
22
|
+
* getCSSCustomProperty('color.background.bold.[default]')
|
|
23
|
+
*/
|
|
24
|
+
var getCSSCustomProperty = exports.getCSSCustomProperty = function getCSSCustomProperty(path) {
|
|
25
|
+
var normalizedPath = typeof path === 'string' ? path.split('.') : path;
|
|
26
|
+
|
|
27
|
+
// Opacity and other 'shallow' groups are more readable when not trimmed
|
|
28
|
+
var slice = _constants.CSS_VAR_FULL.includes(normalizedPath[0]) ? 0 : 1;
|
|
29
|
+
return "--".concat([_constants.CSS_PREFIX].concat((0, _toConsumableArray2.default)(normalizedPath.slice(slice))).filter(function (el) {
|
|
30
|
+
return el !== '[default]';
|
|
31
|
+
}).join('-'));
|
|
32
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFullyQualifiedTokenId = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Transforms a style dictionary token path to a fully qualified token id
|
|
9
|
+
* These Ids are intended to be used internal to this package by style-dictionary
|
|
10
|
+
*
|
|
11
|
+
* [default] key words will NOT be omitted from the path
|
|
12
|
+
*
|
|
13
|
+
* @example <caption>Passing a path as a string</caption>
|
|
14
|
+
* // Returns color.background.bold.[default]
|
|
15
|
+
* getFullyQualifiedTokenId(['color', 'background', 'bold', '[default]'])
|
|
16
|
+
*/
|
|
17
|
+
var getFullyQualifiedTokenId = exports.getFullyQualifiedTokenId = function getFullyQualifiedTokenId(path) {
|
|
18
|
+
return path.join('.');
|
|
19
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getThemeOverridePreferences = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var getThemeOverridePreferences = exports.getThemeOverridePreferences = function getThemeOverridePreferences(_themeState) {
|
|
10
|
+
var themeOverridePreferences = [];
|
|
11
|
+
return (0, _toConsumableArray2.default)(new Set(themeOverridePreferences));
|
|
12
|
+
};
|
|
@@ -4,10 +4,17 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports
|
|
7
|
+
Object.defineProperty(exports, "getThemeOverridePreferences", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _getThemeOverridePreferences.getThemeOverridePreferences;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
exports.getThemePreferences = void 0;
|
|
8
14
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
15
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
10
16
|
var _getIncreasedContrastTheme = _interopRequireDefault(require("./get-increased-contrast-theme"));
|
|
17
|
+
var _getThemeOverridePreferences = require("./get-theme-override-preferences");
|
|
11
18
|
var getThemePreferences = exports.getThemePreferences = function getThemePreferences(themeState) {
|
|
12
19
|
var colorMode = themeState.colorMode,
|
|
13
20
|
contrastMode = themeState.contrastMode,
|
|
@@ -44,8 +51,4 @@ var getThemePreferences = exports.getThemePreferences = function getThemePrefere
|
|
|
44
51
|
}
|
|
45
52
|
});
|
|
46
53
|
return (0, _toConsumableArray2.default)(new Set(themePreferences));
|
|
47
|
-
};
|
|
48
|
-
var getThemeOverridePreferences = exports.getThemeOverridePreferences = function getThemeOverridePreferences(_themeState) {
|
|
49
|
-
var themeOverridePreferences = [];
|
|
50
|
-
return (0, _toConsumableArray2.default)(new Set(themeOverridePreferences));
|
|
51
54
|
};
|