@codecademy/variance 1.0.0-alpha.f43515.0 → 67.0.0-alpha.09ad1e.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/LICENSE +1 -1
- package/dist/core.js +37 -66
- package/dist/createTheme/createTheme.js +43 -61
- package/dist/createTheme/createTheme.test.js +6 -6
- package/dist/createTheme/types.d.ts +7 -7
- package/dist/createTheme/types.js +1 -0
- package/dist/scales/createScaleLookup.d.ts +1 -1
- package/dist/scales/createScaleLookup.js +0 -3
- package/dist/transforms/transformSize.js +5 -17
- package/dist/types/config.d.ts +10 -10
- package/dist/types/config.js +1 -0
- package/dist/types/properties.d.ts +5 -5
- package/dist/types/properties.js +1 -0
- package/dist/types/props.d.ts +7 -7
- package/dist/types/props.js +1 -0
- package/dist/types/theme.js +1 -0
- package/dist/types/utils.d.ts +3 -3
- package/dist/types/utils.js +1 -0
- package/dist/utils/flattenScale.d.ts +5 -5
- package/dist/utils/flattenScale.js +7 -8
- package/dist/utils/propNames.js +6 -13
- package/dist/utils/responsive.js +19 -32
- package/dist/utils/serializeTokens.d.ts +2 -2
- package/dist/utils/serializeTokens.js +6 -12
- package/package.json +11 -12
- package/CHANGELOG.md +0 -325
- package/babel.config.js +0 -5
- package/dist/core.js.map +0 -1
- package/dist/createTheme/createTheme.js.map +0 -1
- package/dist/createTheme/createTheme.test.d.ts +0 -1
- package/dist/createTheme/createTheme.test.js.map +0 -1
- package/dist/createTheme/index.js.map +0 -1
- package/dist/createTheme/types.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/scales/createScale.js.map +0 -1
- package/dist/scales/createScaleLookup.js.map +0 -1
- package/dist/transforms/index.js.map +0 -1
- package/dist/transforms/transformSize.js.map +0 -1
- package/dist/types/config.js.map +0 -1
- package/dist/types/properties.js.map +0 -1
- package/dist/types/props.js.map +0 -1
- package/dist/types/theme.js.map +0 -1
- package/dist/types/utils.js.map +0 -1
- package/dist/utils/__fixtures__/testConfig.js.map +0 -1
- package/dist/utils/flattenScale.js.map +0 -1
- package/dist/utils/getStaticProperties.js.map +0 -1
- package/dist/utils/propNames.js.map +0 -1
- package/dist/utils/responsive.js.map +0 -1
- package/dist/utils/serializeTokens.js.map +0 -1
- package/jest.config.js +0 -1
- package/tsconfig.base.json +0 -3
package/dist/types/config.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { Theme } from '@emotion/react';
|
|
|
2
2
|
import { DefaultCSSPropertyValue, PropertyTypes } from './properties';
|
|
3
3
|
import { AbstractProps, CSSObject, CSSPropMap, CSSProps, ResponsiveProp, ThemeProps } from './props';
|
|
4
4
|
import { AllUnionKeys, Key, KeyFromUnion } from './utils';
|
|
5
|
-
export
|
|
6
|
-
export
|
|
5
|
+
export type MapScale = Record<string | number, string | number>;
|
|
6
|
+
export type ArrayScale = readonly (string | number)[] & {
|
|
7
7
|
length: 0;
|
|
8
8
|
};
|
|
9
9
|
export interface BaseProperty {
|
|
@@ -23,9 +23,9 @@ export interface AbstractParser {
|
|
|
23
23
|
propNames: string[];
|
|
24
24
|
config: Record<string, AbstractPropTransformer>;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
export
|
|
26
|
+
export type PropertyValues<Property extends keyof PropertyTypes, All extends boolean = false> = Exclude<PropertyTypes<All extends true ? DefaultCSSPropertyValue : never>[Property], All extends true ? never : object | any[]>;
|
|
27
|
+
export type ScaleValue<Config extends Prop> = Config['scale'] extends keyof Theme ? keyof Theme[Config['scale']] | PropertyValues<Config['property']> : Config['scale'] extends MapScale ? keyof Config['scale'] | PropertyValues<Config['property']> : Config['scale'] extends ArrayScale ? Config['scale'][number] | PropertyValues<Config['property']> : PropertyValues<Config['property'], true>;
|
|
28
|
+
export type Scale<Config extends Prop> = ResponsiveProp<ScaleValue<Config> | ((theme: Theme) => ScaleValue<Config>)>;
|
|
29
29
|
export interface TransformFn<P extends string, Config extends Prop> {
|
|
30
30
|
(value: Scale<Config> | Scale<Config>, prop: P, props: ThemeProps<{
|
|
31
31
|
[K in P]?: Scale<Config>;
|
|
@@ -35,7 +35,7 @@ export interface PropTransformer<P extends string, C extends Prop> extends Abstr
|
|
|
35
35
|
prop: P;
|
|
36
36
|
styleFn: TransformFn<P, C>;
|
|
37
37
|
}
|
|
38
|
-
export
|
|
38
|
+
export type TransformerMap<Config extends Record<string, Prop>> = {
|
|
39
39
|
[P in Key<keyof Config>]: PropTransformer<Key<P>, Config[P]>;
|
|
40
40
|
};
|
|
41
41
|
export interface Parser<Config extends Record<string, AbstractPropTransformer>> {
|
|
@@ -43,7 +43,7 @@ export interface Parser<Config extends Record<string, AbstractPropTransformer>>
|
|
|
43
43
|
propNames: (keyof Config)[];
|
|
44
44
|
config: Config;
|
|
45
45
|
}
|
|
46
|
-
export
|
|
46
|
+
export type Compose<Args extends AbstractParser[]> = {
|
|
47
47
|
[K in AllUnionKeys<Args[number]['config']>]: KeyFromUnion<Args[number]['config'], K>;
|
|
48
48
|
};
|
|
49
49
|
export interface Variant<P extends AbstractParser> {
|
|
@@ -60,12 +60,12 @@ export interface States<P extends AbstractParser> {
|
|
|
60
60
|
export interface CSS<P extends AbstractParser> {
|
|
61
61
|
<Props extends AbstractProps>(config: CSSProps<Props, SystemProps<P>>): (props: ThemeProps) => CSSObject;
|
|
62
62
|
}
|
|
63
|
-
export
|
|
63
|
+
export type ParserProps<Config extends Record<string, AbstractPropTransformer>> = ThemeProps<{
|
|
64
64
|
[P in keyof Config]?: Parameters<Config[P]['styleFn']>[2][Config[P]['prop']];
|
|
65
65
|
}>;
|
|
66
|
-
export
|
|
66
|
+
export type SystemProps<P extends AbstractParser> = {
|
|
67
67
|
[K in keyof Omit<Parameters<P>[0], 'theme'>]: Omit<Parameters<P>[0], 'theme'>[K];
|
|
68
68
|
};
|
|
69
|
-
export
|
|
69
|
+
export type VariantProps<T extends string, V> = {
|
|
70
70
|
[Key in T]?: V;
|
|
71
71
|
};
|
package/dist/types/config.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Globals, StandardProperties, VendorProperties } from 'csstype';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type ColorProperties = 'color' | `${string}Color`;
|
|
3
|
+
type ColorGlobals = {
|
|
4
4
|
[K in Extract<keyof StandardProperties, ColorProperties>]?: Globals | 'currentColor' | 'transparent' | (string & {});
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
type SizeProperties = 'left' | 'right' | 'top' | 'bottom' | 'inset' | 'width' | 'height' | `${string}${'Width' | 'Height'}`;
|
|
7
|
+
type SizeGlobals = {
|
|
8
8
|
[K in Extract<keyof StandardProperties, SizeProperties>]?: StandardProperties[K] | (number & {});
|
|
9
9
|
};
|
|
10
10
|
/** This is a placeholder type for CSS properties that may not have any specific global values (outlineOffset).
|
|
@@ -12,7 +12,7 @@ declare type SizeGlobals = {
|
|
|
12
12
|
*
|
|
13
13
|
* This ensures that autosuggestions will still work for literal types but still allow any string for certain properties.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export type DefaultCSSPropertyValue = (string & {}) | 0;
|
|
16
16
|
export interface PropertyTypes<Overrides = DefaultCSSPropertyValue> extends Omit<StandardProperties<Overrides>, keyof ColorGlobals | keyof SizeGlobals>, ColorGlobals, SizeGlobals {
|
|
17
17
|
}
|
|
18
18
|
export interface VendorPropertyTypes<Overrides = DefaultCSSPropertyValue> extends VendorProperties<Overrides> {
|
package/dist/types/properties.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/props.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Theme } from '@emotion/react';
|
|
2
2
|
import { AbstractParser, Scale } from './config';
|
|
3
3
|
import { CSSPropertyTypes } from './properties';
|
|
4
|
-
export
|
|
4
|
+
export type AbstractProps = ThemeProps<Record<string, unknown>>;
|
|
5
5
|
interface BreakpointKeys<T = string> {
|
|
6
6
|
xs: T;
|
|
7
7
|
sm: T;
|
|
@@ -13,7 +13,7 @@ export interface BreakpointCache {
|
|
|
13
13
|
map: BreakpointKeys;
|
|
14
14
|
array: string[];
|
|
15
15
|
}
|
|
16
|
-
export
|
|
16
|
+
export type ThemeProps<Props = {}> = Props & {
|
|
17
17
|
theme?: Theme;
|
|
18
18
|
};
|
|
19
19
|
export interface MediaQueryArray<T> {
|
|
@@ -32,16 +32,16 @@ export interface MediaQueryMap<T> {
|
|
|
32
32
|
lg?: T;
|
|
33
33
|
xl?: T;
|
|
34
34
|
}
|
|
35
|
-
export
|
|
35
|
+
export type ResponsiveProp<T> = T | MediaQueryMap<T> | MediaQueryArray<T>;
|
|
36
36
|
export interface CSSObject {
|
|
37
37
|
[key: string]: string | number | CSSObject | undefined;
|
|
38
38
|
}
|
|
39
|
-
export
|
|
39
|
+
export type CSSPropMap<Props, System> = {
|
|
40
40
|
[K in keyof Props]?: CSSProps<Props[K], System>;
|
|
41
41
|
};
|
|
42
|
-
export
|
|
42
|
+
export type CSSProps<Props, System> = {
|
|
43
43
|
[K in keyof Props]?: K extends keyof System ? System[K] : K extends keyof CSSPropertyTypes ? CSSPropertyTypes[K] : Omit<CSSPropertyTypes, keyof System> & Omit<System, 'theme'>;
|
|
44
44
|
};
|
|
45
|
-
export
|
|
46
|
-
export
|
|
45
|
+
export type StyleProps<T extends (args: AbstractProps) => CSSObject> = Parameters<T>[0];
|
|
46
|
+
export type ScaleValue<P extends AbstractParser, Prop extends keyof P['config']> = Scale<P['config'][Prop]>;
|
|
47
47
|
export {};
|
package/dist/types/props.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/theme.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export type AllUnionKeys<T> = T extends any ? keyof T : never;
|
|
2
|
+
export type KeyFromUnion<T, K> = T extends any ? K extends keyof T ? T[K] : never : never;
|
|
3
|
+
export type Key<T> = T extends string ? T : never;
|
package/dist/types/utils.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
* Returns an exhaustive list of all possible paths of an object T for keys K.
|
|
3
3
|
* Possibilities are returned as `k1.k2.k3`.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type FindPath<T, K extends keyof T, D extends string = '.'> = K extends string | number ? T[K] extends Record<string | number, any> ? T[K] extends ArrayLike<any> ? K | `${K}${D}${FindPath<T[K], Exclude<keyof T[K], keyof any[]>, D>}` : K | `${K}${D}${FindPath<T[K], keyof T[K], D>}` : K : never;
|
|
6
6
|
/** Returns valid paths of object T */
|
|
7
|
-
export
|
|
7
|
+
export type Path<T, D extends string = '.'> = FindPath<T, keyof T, D> | keyof T;
|
|
8
8
|
/** Returns the value of a valid path P `k1.k2.k3` in object T */
|
|
9
|
-
export
|
|
9
|
+
export type PathValue<T, P extends Path<T, D>, D extends string = '.'> = P extends `${infer K}${D}${infer Rest}` ? K extends keyof T ? Rest extends Path<T[K], D> ? PathValue<T[K], Rest, D> : never : never : P extends keyof T ? T[P] : never;
|
|
10
10
|
/** Check if path has a primitive end value and return only the union of end paths */
|
|
11
|
-
export
|
|
11
|
+
export type PathToLiteral<T, K extends Path<T, D>, D extends string = '.', Base extends string = ''> = PathValue<T, K, D> extends string | number ? K extends string | number ? K extends `${infer BasePath}${D}${Base}` ? BasePath : K : never : never;
|
|
12
12
|
/**
|
|
13
13
|
* Reduce all paths to a single map of paths with primitive values removing all extra non stateful paths
|
|
14
14
|
* { path: { sub: 1 } } => { 'path-sub': 1 }
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export type LiteralPaths<T extends Record<string | number, any>, D extends string = '.', Base extends string = ''> = {
|
|
18
18
|
[K in Path<T, D> as PathToLiteral<T, K, D, Base>]: PathValue<T, PathToLiteral<T, K, D>, D>;
|
|
19
19
|
};
|
|
20
20
|
export declare function flattenScale<T extends Record<string | number, any>, P extends string>(object: T, path?: P): LiteralPaths<T, '-', '_'>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
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
7
|
import { isObject } from 'lodash';
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* Returns an exhaustive list of all possible paths of an object T for keys K.
|
|
10
11
|
* Possibilities are returned as `k1.k2.k3`.
|
|
@@ -14,11 +15,9 @@ export function flattenScale(object, path) {
|
|
|
14
15
|
return Object.keys(object).reduce(function (carry, key) {
|
|
15
16
|
var nextKey = path ? "".concat(path).concat(key === '_' ? '' : "-".concat(key)) : key;
|
|
16
17
|
var current = object[key];
|
|
17
|
-
|
|
18
18
|
if (isObject(current)) {
|
|
19
19
|
return _objectSpread(_objectSpread({}, carry), flattenScale(current, nextKey));
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
return _objectSpread(_objectSpread({}, carry), {}, _defineProperty({}, nextKey, object[key]));
|
|
23
22
|
}, {});
|
|
24
23
|
}
|
package/dist/utils/propNames.js
CHANGED
|
@@ -4,47 +4,40 @@ var SORT = {
|
|
|
4
4
|
B_BEFORE_A: 1,
|
|
5
5
|
EQUAL: 1
|
|
6
6
|
};
|
|
7
|
-
|
|
8
7
|
var compare = function compare(a, b) {
|
|
9
8
|
if (a < b) return SORT.A_BEFORE_B;
|
|
10
9
|
if (b < a) return SORT.B_BEFORE_A;
|
|
11
10
|
return SORT.EQUAL;
|
|
12
11
|
};
|
|
12
|
+
|
|
13
13
|
/**
|
|
14
14
|
* Orders all properties by the most dependent props
|
|
15
15
|
* @param config
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
17
|
export var orderPropNames = function orderPropNames(config) {
|
|
20
18
|
return Object.keys(config).sort(function (a, b) {
|
|
21
19
|
var aConf = config[a],
|
|
22
|
-
|
|
20
|
+
bConf = config[b];
|
|
23
21
|
var aProp = aConf.property,
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
_aConf$properties = aConf.properties,
|
|
23
|
+
aProperties = _aConf$properties === void 0 ? [] : _aConf$properties;
|
|
26
24
|
var bProp = bConf.property,
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
_bConf$properties = bConf.properties,
|
|
26
|
+
bProperties = _bConf$properties === void 0 ? [] : _bConf$properties;
|
|
29
27
|
var aIsShorthand = SHORTHAND_PROPERTIES.includes(aProp);
|
|
30
28
|
var bIsShorthand = SHORTHAND_PROPERTIES.includes(bProp);
|
|
31
|
-
|
|
32
29
|
if (aIsShorthand && bIsShorthand) {
|
|
33
30
|
var aNum = aProperties.length;
|
|
34
31
|
var bNum = bProperties.length;
|
|
35
|
-
|
|
36
32
|
if (aProp !== bProp) {
|
|
37
33
|
return compare(SHORTHAND_PROPERTIES.indexOf(aProp), SHORTHAND_PROPERTIES.indexOf(bProp));
|
|
38
34
|
}
|
|
39
|
-
|
|
40
35
|
if (aProp === bProp) {
|
|
41
36
|
if (aNum === 0) return SORT.A_BEFORE_B;
|
|
42
37
|
if (bNum === 0) return SORT.B_BEFORE_A;
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
return compare(bNum, aNum);
|
|
46
40
|
}
|
|
47
|
-
|
|
48
41
|
if (aIsShorthand) return SORT.A_BEFORE_B;
|
|
49
42
|
if (bIsShorthand) return SORT.B_BEFORE_A;
|
|
50
43
|
return SORT.EQUAL;
|
package/dist/utils/responsive.js
CHANGED
|
@@ -1,38 +1,29 @@
|
|
|
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
|
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
3
|
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."); }
|
|
4
|
-
|
|
5
4
|
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); }
|
|
6
|
-
|
|
7
5
|
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; }
|
|
8
|
-
|
|
9
6
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
-
|
|
11
7
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
|
|
8
|
+
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; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
10
|
+
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); }
|
|
15
11
|
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; }
|
|
16
|
-
|
|
17
12
|
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; }
|
|
18
|
-
|
|
19
13
|
import { intersection, omit } from 'lodash';
|
|
20
14
|
var BREAKPOINT_KEYS = ['_', 'xs', 'sm', 'md', 'lg', 'xl'];
|
|
15
|
+
|
|
21
16
|
/**
|
|
22
17
|
* Destructures the themes breakpoints into an ordered structure to traverse
|
|
23
18
|
*/
|
|
24
|
-
|
|
25
19
|
export var parseBreakpoints = function parseBreakpoints(breakpoints) {
|
|
26
20
|
if (breakpoints === undefined) return null;
|
|
27
|
-
|
|
28
21
|
var _ref = breakpoints !== null && breakpoints !== void 0 ? breakpoints : {},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
xs = _ref.xs,
|
|
23
|
+
sm = _ref.sm,
|
|
24
|
+
md = _ref.md,
|
|
25
|
+
lg = _ref.lg,
|
|
26
|
+
xl = _ref.xl; // Ensure order for mapping
|
|
36
27
|
return {
|
|
37
28
|
map: breakpoints,
|
|
38
29
|
array: [xs, sm, md, lg, xl]
|
|
@@ -47,15 +38,13 @@ export var isMediaMap = function isMediaMap(val) {
|
|
|
47
38
|
export var objectParser = function objectParser(value, props, config, breakpoints) {
|
|
48
39
|
var styles = {};
|
|
49
40
|
var styleFn = config.styleFn,
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
prop = config.prop;
|
|
52
42
|
var _ = value._,
|
|
53
|
-
|
|
43
|
+
rest = _objectWithoutProperties(value, ["_"]); // the keyof 'base' is base styles
|
|
44
|
+
if (_) Object.assign(styles, styleFn(_, prop, props));
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
if (_) Object.assign(styles, styleFn(_, prop, props)); // Map over remaining keys and merge the corresponding breakpoint styles
|
|
46
|
+
// Map over remaining keys and merge the corresponding breakpoint styles
|
|
57
47
|
// for that property.
|
|
58
|
-
|
|
59
48
|
Object.keys(breakpoints).forEach(function (breakpointKey) {
|
|
60
49
|
var bpStyles = rest[breakpointKey];
|
|
61
50
|
if (typeof bpStyles === 'undefined') return;
|
|
@@ -66,16 +55,14 @@ export var objectParser = function objectParser(value, props, config, breakpoint
|
|
|
66
55
|
export var arrayParser = function arrayParser(value, props, config, breakpoints) {
|
|
67
56
|
var styles = {};
|
|
68
57
|
var styleFn = config.styleFn,
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
prop = config.prop;
|
|
71
59
|
var _value = _toArray(value),
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
_ = _value[0],
|
|
61
|
+
rest = _value.slice(1); // the first index is base styles
|
|
62
|
+
if (_) Object.assign(styles, styleFn(_, prop, props));
|
|
74
63
|
|
|
75
|
-
|
|
76
|
-
if (_) Object.assign(styles, styleFn(_, prop, props)); // Map over each value in the array and merge the corresponding breakpoint styles
|
|
64
|
+
// Map over each value in the array and merge the corresponding breakpoint styles
|
|
77
65
|
// for that property.
|
|
78
|
-
|
|
79
66
|
rest.forEach(function (val, i) {
|
|
80
67
|
var breakpointKey = breakpoints[i];
|
|
81
68
|
if (!breakpointKey || typeof val === 'undefined') return;
|
|
@@ -3,10 +3,10 @@ import { CSSObject } from '../types/props';
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns an type of any object with { key: 'var(--key) }
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type KeyAsVariable<T extends Record<string, any>, Prefix extends string> = {
|
|
7
7
|
[V in keyof T]: `var(--${Prefix}-${Extract<V, string>})`;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
type SerializedTokensInput = Record<string, string | number | CSSObject | SerializedTokensInputRecursive>;
|
|
10
10
|
interface SerializedTokensInputRecursive {
|
|
11
11
|
[i: number]: SerializedTokensInput;
|
|
12
12
|
[i: string]: SerializedTokensInput;
|
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
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 _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; }
|
|
3
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
4
|
+
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); }
|
|
3
5
|
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
|
-
|
|
5
6
|
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; }
|
|
6
|
-
|
|
7
7
|
import { isObject, merge } from 'lodash';
|
|
8
|
-
|
|
9
8
|
var templateBreakpoints = function templateBreakpoints(value, alias, theme) {
|
|
10
9
|
if (isObject(value)) {
|
|
11
10
|
var _ = value._,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
base = value.base,
|
|
12
|
+
rest = _objectWithoutProperties(value, ["_", "base"]);
|
|
15
13
|
var css = _defineProperty({}, alias, _ !== null && _ !== void 0 ? _ : base);
|
|
16
|
-
|
|
17
14
|
if (theme) {
|
|
18
15
|
var breakpoints = theme.breakpoints;
|
|
19
16
|
Object.keys(breakpoints).forEach(function (key) {
|
|
20
17
|
css[breakpoints[key]] = _defineProperty({}, alias, rest[key]);
|
|
21
18
|
});
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
return css;
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
return _defineProperty({}, alias, value);
|
|
28
23
|
};
|
|
29
|
-
|
|
30
24
|
export var serializeTokens = function serializeTokens(tokens, prefix, theme) {
|
|
31
25
|
var tokenReferences = {};
|
|
32
26
|
var tokenVariables = {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/variance",
|
|
3
3
|
"description": "Constraint based CSS in JS for building scalable design systems",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "67.0.0-alpha.09ad1e.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"emotion",
|
|
7
7
|
"css",
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"main": "dist/index.js",
|
|
15
15
|
"module": "dist/index.js",
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
17
20
|
"publishConfig": {
|
|
18
21
|
"access": "public"
|
|
19
22
|
},
|
|
@@ -22,11 +25,7 @@
|
|
|
22
25
|
"url": "git+https://github.com/Codecademy/gamut.git"
|
|
23
26
|
},
|
|
24
27
|
"scripts": {
|
|
25
|
-
"build
|
|
26
|
-
"build:compile": "tsc -b",
|
|
27
|
-
"build:transpile": "babel ./src --out-dir ./dist --copy-files --extensions \".ts,.tsx\"",
|
|
28
|
-
"build": "yarn build:clean && yarn build:compile && yarn build:transpile",
|
|
29
|
-
"lernaBuildTask": "yarn build"
|
|
28
|
+
"build": "nx build @codecademy/variance"
|
|
30
29
|
},
|
|
31
30
|
"peerDependencies": {
|
|
32
31
|
"@emotion/react": "*",
|
|
@@ -37,11 +36,11 @@
|
|
|
37
36
|
"lodash": "^4.17.5"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@emotion/jest": "^11.
|
|
41
|
-
"@emotion/styled": "^11.
|
|
42
|
-
"@types/react-test-renderer": "^17.0.
|
|
43
|
-
"react": "17.0.2",
|
|
44
|
-
"react-test-renderer": "17.0.2"
|
|
39
|
+
"@emotion/jest": "^11.11.0",
|
|
40
|
+
"@emotion/styled": "^11.11.0",
|
|
41
|
+
"@types/react-test-renderer": "^17.0.2",
|
|
42
|
+
"react": "^17.0.2",
|
|
43
|
+
"react-test-renderer": "^17.0.2"
|
|
45
44
|
},
|
|
46
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "430c6d83990991443428d7d476f069d368022b83"
|
|
47
46
|
}
|