@codecademy/gamut-styles 16.3.1-alpha.8ea574.0 → 16.3.1-alpha.d1fa10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AssetProvider.js +18 -15
- package/dist/Background.js +45 -28
- package/dist/ColorMode.d.ts +27 -0
- package/dist/ColorMode.js +77 -70
- package/dist/GamutProvider.js +22 -20
- package/dist/cache/createEmotionCache.d.ts +1 -1
- package/dist/cache/createEmotionCache.js +26 -11
- package/dist/cache/stylisPlugins/focusVisible.js +4 -4
- package/dist/globals/Reboot.js +6 -4
- package/dist/globals/Typography.js +20 -18
- package/dist/globals/Variables.js +21 -12
- package/dist/remoteAssets/fonts.js +8 -8
- package/dist/styles/boxShadow.d.ts +1 -1
- package/dist/styles/boxShadow.js +20 -10
- package/dist/styles/fontSmoothing.js +7 -5
- package/dist/styles/noSelect.d.ts +1 -1
- package/dist/styles/noSelect.js +1 -1
- package/dist/styles/pxRem.js +3 -3
- package/dist/styles/responsive.js +6 -4
- package/dist/styles/screenReaderOnly.d.ts +2 -2
- package/dist/styles/screenReaderOnly.js +2 -2
- package/dist/styles/transitionConcat.js +4 -4
- package/dist/themes/admin.d.ts +8 -0
- package/dist/themes/admin.js +1 -1
- package/dist/themes/core.d.ts +8 -0
- package/dist/themes/core.js +13 -14
- package/dist/themes/platform.d.ts +8 -0
- package/dist/themes/platform.js +1 -1
- package/dist/utilities/themed.js +2 -4
- package/dist/variables/borderRadii.d.ts +8 -0
- package/dist/variables/borderRadii.js +8 -0
- package/dist/variables/colors.js +18 -19
- package/dist/variables/deprecated-colors.js +16 -17
- package/dist/variables/elements.js +1 -1
- package/dist/variables/index.d.ts +3 -2
- package/dist/variables/index.js +3 -2
- package/dist/variables/responsive.js +6 -4
- package/dist/variables/spacing.js +1 -1
- package/dist/variables/timing.js +5 -5
- package/dist/variables/typography.js +8 -14
- package/dist/variance/config.d.ts +18 -0
- package/dist/variance/config.js +50 -58
- package/dist/variance/index.js +2 -1
- package/dist/variance/props.d.ts +36 -0
- package/dist/variance/props.js +16 -16
- package/dist/variance/utils.js +14 -6
- package/package.json +3 -3
package/dist/AssetProvider.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { webFonts } from './remoteAssets/fonts';
|
|
2
|
-
import { jsx as _jsx
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
4
|
+
export var createFontLinks = function createFontLinks() {
|
|
5
|
+
return webFonts.flatMap(function (_ref) {
|
|
6
|
+
var filePath = _ref.filePath,
|
|
7
|
+
extensions = _ref.extensions;
|
|
8
|
+
return extensions.map(function (ext) {
|
|
9
|
+
return /*#__PURE__*/_jsx("link", {
|
|
10
|
+
rel: "preload",
|
|
11
|
+
href: "".concat(filePath, ".").concat(ext),
|
|
12
|
+
crossOrigin: "anonymous",
|
|
13
|
+
as: "font",
|
|
14
|
+
type: "font/".concat(ext)
|
|
15
|
+
}, "".concat(filePath, "-").concat(ext));
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export var AssetProvider = function AssetProvider() {
|
|
17
20
|
return /*#__PURE__*/_jsx(_Fragment, {
|
|
18
21
|
children: createFontLinks()
|
|
19
22
|
});
|
package/dist/Background.js
CHANGED
|
@@ -1,25 +1,41 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
14
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
1
15
|
import { getContrast } from 'polished';
|
|
2
16
|
import { forwardRef, useCallback, useMemo } from 'react';
|
|
3
17
|
import { ColorMode, useColorModes } from './ColorMode';
|
|
4
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
|
|
19
|
+
var isColorAlias = function isColorAlias(mode, color) {
|
|
6
20
|
return Object.keys(mode).includes(color);
|
|
7
21
|
};
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
bg
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
export var Background = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
23
|
+
var bg = _ref.bg,
|
|
24
|
+
rest = _objectWithoutProperties(_ref, ["bg"]);
|
|
25
|
+
var _useColorModes = useColorModes(),
|
|
26
|
+
_useColorModes2 = _slicedToArray(_useColorModes, 4),
|
|
27
|
+
active = _useColorModes2[0],
|
|
28
|
+
activeColors = _useColorModes2[1],
|
|
29
|
+
modes = _useColorModes2[2],
|
|
30
|
+
getColorValue = _useColorModes2[3];
|
|
15
31
|
/** If a color alias was used then look up the true color key from the active mode */
|
|
16
|
-
|
|
32
|
+
var trueColor = useMemo(function () {
|
|
17
33
|
if (isColorAlias(activeColors, bg)) {
|
|
18
34
|
return activeColors[bg];
|
|
19
35
|
}
|
|
20
36
|
return bg;
|
|
21
37
|
}, [bg, activeColors]);
|
|
22
|
-
|
|
38
|
+
var getTextContrast = useCallback(function (foreground) {
|
|
23
39
|
return getContrast(getColorValue(foreground), getColorValue(trueColor));
|
|
24
40
|
}, [trueColor, getColorValue]);
|
|
25
41
|
|
|
@@ -33,12 +49,10 @@ export const Background = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
33
49
|
* This does not guarantee a level of A/AA/AA compliance.
|
|
34
50
|
*/
|
|
35
51
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
[active]
|
|
39
|
-
|
|
40
|
-
} = modes;
|
|
41
|
-
const possibleModes = Object.entries(otherModes);
|
|
52
|
+
var accessibleMode = useMemo(function () {
|
|
53
|
+
var activeMode = modes[active],
|
|
54
|
+
otherModes = _objectWithoutProperties(modes, [active].map(_toPropertyKey));
|
|
55
|
+
var possibleModes = Object.entries(otherModes);
|
|
42
56
|
|
|
43
57
|
/**
|
|
44
58
|
* Reduce all remaining modes to the mode key with the highest contrast
|
|
@@ -48,22 +62,25 @@ export const Background = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
48
62
|
* it will likely fail to return a mode outside of the lightest and
|
|
49
63
|
* darkest versions.
|
|
50
64
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
var _possibleModes$reduce = possibleModes.reduce(function (_ref2, _ref3) {
|
|
66
|
+
var _ref4 = _slicedToArray(_ref2, 2),
|
|
67
|
+
prevMode = _ref4[0],
|
|
68
|
+
prevContrast = _ref4[1];
|
|
69
|
+
var _ref5 = _slicedToArray(_ref3, 2),
|
|
70
|
+
mode = _ref5[0],
|
|
71
|
+
text = _ref5[1].text;
|
|
72
|
+
var contrast = getTextContrast(text);
|
|
57
73
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
// Keep the higher contrast mode.
|
|
75
|
+
return contrast > prevContrast ? [mode, contrast] : [prevMode, prevContrast];
|
|
76
|
+
}, [active, getTextContrast(activeMode.text)]),
|
|
77
|
+
_possibleModes$reduce2 = _slicedToArray(_possibleModes$reduce, 1),
|
|
78
|
+
highestContrastMode = _possibleModes$reduce2[0];
|
|
61
79
|
return highestContrastMode;
|
|
62
80
|
}, [modes, active, getTextContrast]);
|
|
63
|
-
return /*#__PURE__*/_jsx(ColorMode, {
|
|
64
|
-
...rest,
|
|
81
|
+
return /*#__PURE__*/_jsx(ColorMode, _objectSpread(_objectSpread({}, rest), {}, {
|
|
65
82
|
mode: accessibleMode,
|
|
66
83
|
bg: bg,
|
|
67
84
|
ref: ref
|
|
68
|
-
});
|
|
85
|
+
}));
|
|
69
86
|
});
|
package/dist/ColorMode.d.ts
CHANGED
|
@@ -398,34 +398,43 @@ export declare const providerProps: import("@codecademy/variance/dist/types/conf
|
|
|
398
398
|
};
|
|
399
399
|
readonly borderRadius: {
|
|
400
400
|
readonly property: "borderRadius";
|
|
401
|
+
readonly scale: "borderRadii";
|
|
401
402
|
};
|
|
402
403
|
readonly borderRadiusLeft: {
|
|
403
404
|
readonly property: "borderRadius";
|
|
404
405
|
readonly properties: readonly ["borderTopLeftRadius", "borderBottomLeftRadius"];
|
|
406
|
+
readonly scale: "borderRadii";
|
|
405
407
|
};
|
|
406
408
|
readonly borderRadiusTop: {
|
|
407
409
|
readonly property: "borderRadius";
|
|
408
410
|
readonly properties: readonly ["borderTopLeftRadius", "borderTopRightRadius"];
|
|
411
|
+
readonly scale: "borderRadii";
|
|
409
412
|
};
|
|
410
413
|
readonly borderRadiusBottom: {
|
|
411
414
|
readonly property: "borderRadius";
|
|
412
415
|
readonly properties: readonly ["borderBottomLeftRadius", "borderBottomRightRadius"];
|
|
416
|
+
readonly scale: "borderRadii";
|
|
413
417
|
};
|
|
414
418
|
readonly borderRadiusRight: {
|
|
415
419
|
readonly property: "borderRadius";
|
|
416
420
|
readonly properties: readonly ["borderTopRightRadius", "borderBottomRightRadius"];
|
|
421
|
+
readonly scale: "borderRadii";
|
|
417
422
|
};
|
|
418
423
|
readonly borderRadiusTopLeft: {
|
|
419
424
|
readonly property: "borderTopLeftRadius";
|
|
425
|
+
readonly scale: "borderRadii";
|
|
420
426
|
};
|
|
421
427
|
readonly borderRadiusTopRight: {
|
|
422
428
|
readonly property: "borderTopRightRadius";
|
|
429
|
+
readonly scale: "borderRadii";
|
|
423
430
|
};
|
|
424
431
|
readonly borderRadiusBottomRight: {
|
|
425
432
|
readonly property: "borderBottomRightRadius";
|
|
433
|
+
readonly scale: "borderRadii";
|
|
426
434
|
};
|
|
427
435
|
readonly borderRadiusBottomLeft: {
|
|
428
436
|
readonly property: "borderBottomLeftRadius";
|
|
437
|
+
readonly scale: "borderRadii";
|
|
429
438
|
};
|
|
430
439
|
readonly borderStyle: {
|
|
431
440
|
readonly property: "borderStyle";
|
|
@@ -663,6 +672,7 @@ export declare const VariableProvider: import("@emotion/styled").StyledComponent
|
|
|
663
672
|
}>;
|
|
664
673
|
borderRadius?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
665
674
|
readonly property: "borderRadius";
|
|
675
|
+
readonly scale: "borderRadii";
|
|
666
676
|
}>;
|
|
667
677
|
borderRight?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
668
678
|
readonly property: "borderRight";
|
|
@@ -825,30 +835,38 @@ export declare const VariableProvider: import("@emotion/styled").StyledComponent
|
|
|
825
835
|
borderRadiusLeft?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
826
836
|
readonly property: "borderRadius";
|
|
827
837
|
readonly properties: readonly ["borderTopLeftRadius", "borderBottomLeftRadius"];
|
|
838
|
+
readonly scale: "borderRadii";
|
|
828
839
|
}>;
|
|
829
840
|
borderRadiusTop?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
830
841
|
readonly property: "borderRadius";
|
|
831
842
|
readonly properties: readonly ["borderTopLeftRadius", "borderTopRightRadius"];
|
|
843
|
+
readonly scale: "borderRadii";
|
|
832
844
|
}>;
|
|
833
845
|
borderRadiusBottom?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
834
846
|
readonly property: "borderRadius";
|
|
835
847
|
readonly properties: readonly ["borderBottomLeftRadius", "borderBottomRightRadius"];
|
|
848
|
+
readonly scale: "borderRadii";
|
|
836
849
|
}>;
|
|
837
850
|
borderRadiusRight?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
838
851
|
readonly property: "borderRadius";
|
|
839
852
|
readonly properties: readonly ["borderTopRightRadius", "borderBottomRightRadius"];
|
|
853
|
+
readonly scale: "borderRadii";
|
|
840
854
|
}>;
|
|
841
855
|
borderRadiusTopLeft?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
842
856
|
readonly property: "borderTopLeftRadius";
|
|
857
|
+
readonly scale: "borderRadii";
|
|
843
858
|
}>;
|
|
844
859
|
borderRadiusTopRight?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
845
860
|
readonly property: "borderTopRightRadius";
|
|
861
|
+
readonly scale: "borderRadii";
|
|
846
862
|
}>;
|
|
847
863
|
borderRadiusBottomRight?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
848
864
|
readonly property: "borderBottomRightRadius";
|
|
865
|
+
readonly scale: "borderRadii";
|
|
849
866
|
}>;
|
|
850
867
|
borderRadiusBottomLeft?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
851
868
|
readonly property: "borderBottomLeftRadius";
|
|
869
|
+
readonly scale: "borderRadii";
|
|
852
870
|
}>;
|
|
853
871
|
borderStyleX?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
854
872
|
readonly property: "borderStyle";
|
|
@@ -1061,6 +1079,7 @@ export declare const ColorMode: import("react").ForwardRefExoticComponent<Pick<O
|
|
|
1061
1079
|
}>;
|
|
1062
1080
|
borderRadius?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
1063
1081
|
readonly property: "borderRadius";
|
|
1082
|
+
readonly scale: "borderRadii";
|
|
1064
1083
|
}>;
|
|
1065
1084
|
borderRight?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
1066
1085
|
readonly property: "borderRight";
|
|
@@ -1223,30 +1242,38 @@ export declare const ColorMode: import("react").ForwardRefExoticComponent<Pick<O
|
|
|
1223
1242
|
borderRadiusLeft?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
1224
1243
|
readonly property: "borderRadius";
|
|
1225
1244
|
readonly properties: readonly ["borderTopLeftRadius", "borderBottomLeftRadius"];
|
|
1245
|
+
readonly scale: "borderRadii";
|
|
1226
1246
|
}>;
|
|
1227
1247
|
borderRadiusTop?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
1228
1248
|
readonly property: "borderRadius";
|
|
1229
1249
|
readonly properties: readonly ["borderTopLeftRadius", "borderTopRightRadius"];
|
|
1250
|
+
readonly scale: "borderRadii";
|
|
1230
1251
|
}>;
|
|
1231
1252
|
borderRadiusBottom?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
1232
1253
|
readonly property: "borderRadius";
|
|
1233
1254
|
readonly properties: readonly ["borderBottomLeftRadius", "borderBottomRightRadius"];
|
|
1255
|
+
readonly scale: "borderRadii";
|
|
1234
1256
|
}>;
|
|
1235
1257
|
borderRadiusRight?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
1236
1258
|
readonly property: "borderRadius";
|
|
1237
1259
|
readonly properties: readonly ["borderTopRightRadius", "borderBottomRightRadius"];
|
|
1260
|
+
readonly scale: "borderRadii";
|
|
1238
1261
|
}>;
|
|
1239
1262
|
borderRadiusTopLeft?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
1240
1263
|
readonly property: "borderTopLeftRadius";
|
|
1264
|
+
readonly scale: "borderRadii";
|
|
1241
1265
|
}>;
|
|
1242
1266
|
borderRadiusTopRight?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
1243
1267
|
readonly property: "borderTopRightRadius";
|
|
1268
|
+
readonly scale: "borderRadii";
|
|
1244
1269
|
}>;
|
|
1245
1270
|
borderRadiusBottomRight?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
1246
1271
|
readonly property: "borderBottomRightRadius";
|
|
1272
|
+
readonly scale: "borderRadii";
|
|
1247
1273
|
}>;
|
|
1248
1274
|
borderRadiusBottomLeft?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
1249
1275
|
readonly property: "borderBottomLeftRadius";
|
|
1276
|
+
readonly scale: "borderRadii";
|
|
1250
1277
|
}>;
|
|
1251
1278
|
borderStyleX?: import("@codecademy/variance/dist/types/config").Scale<{
|
|
1252
1279
|
readonly property: "borderStyle";
|
package/dist/ColorMode.js
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
1
2
|
import _styled from "@emotion/styled/base";
|
|
2
|
-
function
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
15
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
17
|
import { serializeTokens, variance } from '@codecademy/variance';
|
|
4
18
|
import { ThemeProvider, useTheme } from '@emotion/react';
|
|
5
19
|
import mapValues from 'lodash/mapValues';
|
|
@@ -8,31 +22,26 @@ import { createContext, forwardRef, useContext, useEffect, useMemo, useState } f
|
|
|
8
22
|
import { background, border, color, css, flex, grid, layout, positioning, space } from './variance/props';
|
|
9
23
|
import { styledOptions } from './variance/utils';
|
|
10
24
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} = theme;
|
|
21
|
-
return serializeTokens(mapValues(theme?.modes[mode], color => colors[color]), 'color', theme).variables;
|
|
25
|
+
export var providerProps = variance.compose(layout, color, grid, flex, positioning, space, border, background);
|
|
26
|
+
export var modeColorProps = function modeColorProps(_ref) {
|
|
27
|
+
var theme = _ref.theme,
|
|
28
|
+
mode = _ref.mode;
|
|
29
|
+
if (!theme || !mode || mode === (theme === null || theme === void 0 ? void 0 : theme.mode)) return {};
|
|
30
|
+
var colors = theme.colors;
|
|
31
|
+
return serializeTokens(mapValues(theme === null || theme === void 0 ? void 0 : theme.modes[mode], function (color) {
|
|
32
|
+
return colors[color];
|
|
33
|
+
}), 'color', theme).variables;
|
|
22
34
|
};
|
|
23
|
-
|
|
35
|
+
var BackgroundCurrentContext = /*#__PURE__*/createContext({
|
|
24
36
|
'background-current': undefined
|
|
25
37
|
});
|
|
26
38
|
export function useColorModes() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
mode,
|
|
30
|
-
modes,
|
|
31
|
-
_getColorValue
|
|
32
|
-
|
|
33
|
-
const modesCopy = {
|
|
34
|
-
...modes
|
|
35
|
-
};
|
|
39
|
+
var bgCurrent = useContext(BackgroundCurrentContext);
|
|
40
|
+
var _ref2 = useTheme() || {},
|
|
41
|
+
mode = _ref2.mode,
|
|
42
|
+
modes = _ref2.modes,
|
|
43
|
+
getColorValue = _ref2._getColorValue;
|
|
44
|
+
var modesCopy = _objectSpread({}, modes);
|
|
36
45
|
if (bgCurrent['background-current'] && modesCopy[mode]['background-current'] !== bgCurrent['background-current']) {
|
|
37
46
|
/* sets the color to the copy of our modes object, and casts the type as the default color values for background-current.
|
|
38
47
|
we could potentially alter the Merge type utility function from createTheme, but since 'background-current' is the only exception to the type-merging rule and this is the only place we override, this seems to be a more straightforward + lower-risk solution.
|
|
@@ -40,100 +49,98 @@ export function useColorModes() {
|
|
|
40
49
|
|
|
41
50
|
modesCopy[mode]['background-current'] = bgCurrent['background-current'];
|
|
42
51
|
}
|
|
43
|
-
return [mode, modesCopy
|
|
52
|
+
return [mode, modesCopy === null || modesCopy === void 0 ? void 0 : modesCopy[mode], modes, getColorValue];
|
|
44
53
|
}
|
|
45
54
|
export function useCurrentMode(mode) {
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
var _useColorModes = useColorModes(),
|
|
56
|
+
_useColorModes2 = _slicedToArray(_useColorModes, 1),
|
|
57
|
+
activeMode = _useColorModes2[0];
|
|
58
|
+
return mode !== null && mode !== void 0 ? mode : activeMode;
|
|
48
59
|
}
|
|
49
60
|
export function usePrefersDarkMode() {
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
var _useState = useState(false),
|
|
62
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
63
|
+
prefersDarkMode = _useState2[0],
|
|
64
|
+
setPrefersDarkMode = _useState2[1];
|
|
65
|
+
useEffect(function () {
|
|
52
66
|
function onChange(event) {
|
|
53
67
|
setPrefersDarkMode(event.matches);
|
|
54
68
|
}
|
|
55
69
|
if (window && 'matchMedia' in window) {
|
|
56
|
-
|
|
70
|
+
var mq = window.matchMedia('(prefers-color-scheme: dark)');
|
|
57
71
|
if (mq && 'addEventListener' in mq) {
|
|
58
72
|
setPrefersDarkMode(mq.matches);
|
|
59
73
|
mq.addEventListener('change', onChange);
|
|
60
|
-
return ()
|
|
74
|
+
return function () {
|
|
75
|
+
return mq.removeEventListener('change', onChange);
|
|
76
|
+
};
|
|
61
77
|
}
|
|
62
78
|
}
|
|
63
79
|
}, []);
|
|
64
80
|
return prefersDarkMode;
|
|
65
81
|
}
|
|
66
|
-
export
|
|
82
|
+
export var VariableProvider = /*#__PURE__*/_styled('div', _extends({}, {
|
|
67
83
|
target: "e1skjn880",
|
|
68
84
|
label: "VariableProvider"
|
|
69
|
-
}, styledOptions(['variables', 'alwaysSetVariables'])))(
|
|
70
|
-
|
|
71
|
-
variables
|
|
72
|
-
} = _ref2;
|
|
85
|
+
}, styledOptions(['variables', 'alwaysSetVariables'])))(function (_ref3) {
|
|
86
|
+
var variables = _ref3.variables;
|
|
73
87
|
return variables;
|
|
74
88
|
}, css({
|
|
75
89
|
textColor: 'text'
|
|
76
90
|
}), providerProps, process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9Db2xvck1vZGUudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQXFJZ0MiLCJmaWxlIjoiLi4vc3JjL0NvbG9yTW9kZS50c3giLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQge1xuICBzZXJpYWxpemVUb2tlbnMsXG4gIFN0eWxlUHJvcHMsXG4gIFRoZW1lUHJvcHMsXG4gIHZhcmlhbmNlLFxufSBmcm9tICdAY29kZWNhZGVteS92YXJpYW5jZSc7XG5pbXBvcnQgeyBDU1NPYmplY3QsIFRoZW1lLCBUaGVtZVByb3ZpZGVyLCB1c2VUaGVtZSB9IGZyb20gJ0BlbW90aW9uL3JlYWN0JztcbmltcG9ydCBzdHlsZWQgZnJvbSAnQGVtb3Rpb24vc3R5bGVkJztcbmltcG9ydCBtYXBWYWx1ZXMgZnJvbSAnbG9kYXNoL21hcFZhbHVlcyc7XG5pbXBvcnQgc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m91bmQtY3VycmVudCcgJiYgdHlwZW9mIGJnICE9PSAndW5kZWZpbmVkJykge1xuICAgICAgICAgIHJldHVybiBjb2xvcnNbYmddO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBjb2xvcnNbY29sb3JdO1xuICAgICAgfSksXG4gICAgICAnY29sb3InLFxuICAgICAgdGhlbWVcbiAgICApO1xuICB9LCBbY29sb3JzLCBtb2RlLCBtb2RlcywgdGhlbWUsIGJnXSk7XG5cbiAgaWYgKGFjdGl2ZSA9PT0gbW9kZSkge1xuICAgIGNvbnN0IHZhcnMgPSBhbHdheXNTZXRWYXJpYWJsZXNcbiAgICAgID8gdmFyaWFibGVzXG4gICAgICA6IHBpY2sodmFyaWFibGVzLCBbJy0tY29sb3ItYmFja2dyb3VuZC1jdXJyZW50J10pO1xuXG4gICAgcmV0dXJuIChcbiAgICAgIDxCYWNrZ3JvdW5kQ3VycmVudENvbnRleHQuUHJvdmlkZXJcbiAgICAgICAgdmFsdWU9e3sgJ2JhY2tncm91bmQtY3VycmVudCc6IGJnQ3VycmVudCB9fVxuICAgICAgPlxuICAgICAgICA8VmFyaWFibGVQcm92aWRlciB7Li4ucmVzdH0gdmFyaWFibGVzPXt2YXJzfSBiZz17Y29udGV4dEJnfSByZWY9e3JlZn0gLz5cbiAgICAgIDwvQmFja2dyb3VuZEN1cnJlbnRDb250ZXh0LlByb3ZpZGVyPlxuICAgICk7XG4gIH1cblxuICByZXR1cm4gKFxuICAgIDxUaGVtZVByb3ZpZGVyIHRoZW1lPXt7IG1vZGUgfX0+XG4gICAgICA8VmFyaWFibGVQcm92aWRlclxuICAgICAgICB7Li4ucmVzdH1cbiAgICAgICAgdmFyaWFibGVzPXt2YXJpYWJsZXN9XG4gICAgICAgIGJnPXtjb250ZXh0Qmd9XG4gICAgICAgIHJlZj17cmVmfVxuICAgICAgLz5cbiAgICA8L1RoZW1lUHJvdmlkZXI+XG4gICk7XG59KTtcbiJdfQ== */");
|
|
77
|
-
export
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
bg
|
|
82
|
-
...rest
|
|
83
|
-
} = _ref3;
|
|
91
|
+
export var ColorMode = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
92
|
+
var preference = _ref4.mode,
|
|
93
|
+
alwaysSetVariables = _ref4.alwaysSetVariables,
|
|
94
|
+
bg = _ref4.bg,
|
|
95
|
+
rest = _objectWithoutProperties(_ref4, ["mode", "alwaysSetVariables", "bg"]);
|
|
84
96
|
// checks if the user has set 'system' as their color mode preference
|
|
85
97
|
// then sets the color mode
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
} = theme;
|
|
94
|
-
const contextBg = bg ? 'background-current' : undefined;
|
|
98
|
+
var prefersDarkMode = usePrefersDarkMode();
|
|
99
|
+
var mode = preference === 'system' ? prefersDarkMode ? 'dark' : 'light' : preference;
|
|
100
|
+
var theme = useTheme();
|
|
101
|
+
var modes = theme.modes,
|
|
102
|
+
active = theme.mode,
|
|
103
|
+
colors = theme.colors;
|
|
104
|
+
var contextBg = bg ? 'background-current' : undefined;
|
|
95
105
|
// This makes sure the background-current context is always set to the correct color + not the semantic color name.
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
var currentParentBg = useContext(BackgroundCurrentContext);
|
|
107
|
+
var bgCurrent = bg === 'background-current' ? currentParentBg['background-current'] ? currentParentBg['background-current'] : modes[active]['background-current'] : bg;
|
|
98
108
|
|
|
99
109
|
/** Serialize color variables for the current mode
|
|
100
110
|
* 1. If all variables are required add all mode variables to the current context
|
|
101
111
|
* 2. If the user has specified a background color - set that color to the current-bg
|
|
102
112
|
* 3. If not
|
|
103
113
|
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return colors[
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}, [colors, mode, modes, theme, bg]);
|
|
114
|
+
var _useMemo = useMemo(function () {
|
|
115
|
+
return serializeTokens(mapValues(modes[mode], function (color, key) {
|
|
116
|
+
if (key === 'background-current' && typeof bg !== 'undefined') {
|
|
117
|
+
return colors[bg];
|
|
118
|
+
}
|
|
119
|
+
return colors[color];
|
|
120
|
+
}), 'color', theme);
|
|
121
|
+
}, [colors, mode, modes, theme, bg]),
|
|
122
|
+
variables = _useMemo.variables;
|
|
114
123
|
if (active === mode) {
|
|
115
|
-
|
|
124
|
+
var vars = alwaysSetVariables ? variables : pick(variables, ['--color-background-current']);
|
|
116
125
|
return /*#__PURE__*/_jsx(BackgroundCurrentContext.Provider, {
|
|
117
126
|
value: {
|
|
118
127
|
'background-current': bgCurrent
|
|
119
128
|
},
|
|
120
|
-
children: /*#__PURE__*/_jsx(VariableProvider, {
|
|
121
|
-
...rest,
|
|
129
|
+
children: /*#__PURE__*/_jsx(VariableProvider, _objectSpread(_objectSpread({}, rest), {}, {
|
|
122
130
|
variables: vars,
|
|
123
131
|
bg: contextBg,
|
|
124
132
|
ref: ref
|
|
125
|
-
})
|
|
133
|
+
}))
|
|
126
134
|
});
|
|
127
135
|
}
|
|
128
136
|
return /*#__PURE__*/_jsx(ThemeProvider, {
|
|
129
137
|
theme: {
|
|
130
|
-
mode
|
|
138
|
+
mode: mode
|
|
131
139
|
},
|
|
132
|
-
children: /*#__PURE__*/_jsx(VariableProvider, {
|
|
133
|
-
...rest,
|
|
140
|
+
children: /*#__PURE__*/_jsx(VariableProvider, _objectSpread(_objectSpread({}, rest), {}, {
|
|
134
141
|
variables: variables,
|
|
135
142
|
bg: contextBg,
|
|
136
143
|
ref: ref
|
|
137
|
-
})
|
|
144
|
+
}))
|
|
138
145
|
});
|
|
139
146
|
});
|
package/dist/GamutProvider.js
CHANGED
|
@@ -5,35 +5,37 @@ import { createEmotionCache } from './cache';
|
|
|
5
5
|
import { Reboot, Typography } from './globals';
|
|
6
6
|
import { Variables } from './globals/Variables';
|
|
7
7
|
import { coreTheme } from './themes/core';
|
|
8
|
-
import { jsx as _jsx
|
|
9
|
-
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
export var GamutContext = /*#__PURE__*/React.createContext({
|
|
10
12
|
hasGlobals: false,
|
|
11
13
|
hasCache: false
|
|
12
14
|
});
|
|
13
15
|
GamutContext.displayName = 'GamutContext';
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
theme = coreTheme,
|
|
19
|
-
variables,
|
|
20
|
-
useGlobals =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
export var GamutProvider = function GamutProvider(_ref) {
|
|
17
|
+
var children = _ref.children,
|
|
18
|
+
cache = _ref.cache,
|
|
19
|
+
_ref$theme = _ref.theme,
|
|
20
|
+
theme = _ref$theme === void 0 ? coreTheme : _ref$theme,
|
|
21
|
+
variables = _ref.variables,
|
|
22
|
+
_ref$useGlobals = _ref.useGlobals,
|
|
23
|
+
useGlobals = _ref$useGlobals === void 0 ? true : _ref$useGlobals,
|
|
24
|
+
_ref$useCache = _ref.useCache,
|
|
25
|
+
useCache = _ref$useCache === void 0 ? true : _ref$useCache;
|
|
26
|
+
var _useContext = useContext(GamutContext),
|
|
27
|
+
hasGlobals = _useContext.hasGlobals,
|
|
28
|
+
hasCache = _useContext.hasCache;
|
|
29
|
+
var shouldCreateCache = useCache && !hasCache;
|
|
30
|
+
var shouldInsertGlobals = useGlobals && !hasGlobals;
|
|
29
31
|
|
|
30
32
|
// Do not initialize a new cache if one has been provided as props
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
var activeCache = useRef(shouldCreateCache && (cache !== null && cache !== void 0 ? cache : createEmotionCache()));
|
|
34
|
+
var contextValue = {
|
|
33
35
|
hasGlobals: shouldInsertGlobals,
|
|
34
36
|
hasCache: shouldCreateCache
|
|
35
37
|
};
|
|
36
|
-
|
|
38
|
+
var globals = shouldInsertGlobals && /*#__PURE__*/_jsxs(_Fragment, {
|
|
37
39
|
children: [/*#__PURE__*/_jsx(Typography, {}), /*#__PURE__*/_jsx(Reboot, {}), /*#__PURE__*/_jsx(Variables, {
|
|
38
40
|
variables: theme._variables
|
|
39
41
|
}), variables && /*#__PURE__*/_jsx(Variables, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Options } from '@emotion/cache';
|
|
2
2
|
export declare const EMOTION_KEY = "gamut";
|
|
3
3
|
export declare const EMOTION_CONTAINER = "emotion-styles";
|
|
4
|
-
export declare const createEmotionCache: (overrides?: Partial<Options>) => import("@emotion/
|
|
4
|
+
export declare const createEmotionCache: (overrides?: Partial<Options>) => import("@emotion/cache").EmotionCache;
|