@codecademy/variance 0.19.1-alpha.a809e8.0 → 1.0.0-alpha.2627a4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -2
- package/dist/core.d.ts +10 -0
- package/dist/core.js +251 -0
- package/dist/core.js.map +1 -0
- package/dist/createTheme/createTheme.d.ts +55 -0
- package/dist/createTheme/createTheme.js +168 -0
- package/dist/createTheme/createTheme.js.map +1 -0
- package/dist/createTheme/createTheme.test.d.ts +1 -0
- package/dist/createTheme/createTheme.test.js +192 -0
- package/dist/createTheme/createTheme.test.js.map +1 -0
- package/dist/createTheme/index.d.ts +3 -0
- package/dist/createTheme/index.js +3 -0
- package/dist/createTheme/index.js.map +1 -0
- package/dist/createTheme/types.d.ts +42 -0
- package/dist/createTheme/types.js +0 -0
- package/dist/createTheme/types.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/scales/createScale.d.ts +3 -0
- package/dist/scales/createScale.js +3 -0
- package/dist/scales/createScale.js.map +1 -0
- package/dist/scales/createScaleLookup.d.ts +5 -0
- package/dist/scales/createScaleLookup.js +24 -0
- package/dist/scales/createScaleLookup.js.map +1 -0
- package/dist/transforms/index.d.ts +1 -0
- package/dist/transforms/index.js +1 -0
- package/dist/transforms/index.js.map +1 -0
- package/dist/transforms/transformSize.d.ts +2 -0
- package/dist/transforms/transformSize.js +47 -0
- package/dist/transforms/transformSize.js.map +1 -0
- package/dist/types/config.d.ts +71 -0
- package/dist/types/config.js +0 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/properties.d.ts +22 -0
- package/dist/types/properties.js +0 -0
- package/dist/types/properties.js.map +1 -0
- package/dist/types/props.d.ts +47 -0
- package/dist/types/props.js +0 -0
- package/dist/types/props.js.map +1 -0
- package/dist/types/theme.d.ts +17 -0
- package/dist/types/theme.js +0 -0
- package/dist/types/theme.js.map +1 -0
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/utils.js +0 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/utils/__fixtures__/testConfig.d.ts +153 -0
- package/dist/utils/__fixtures__/testConfig.js +153 -0
- package/dist/utils/__fixtures__/testConfig.js.map +1 -0
- package/dist/utils/flattenScale.d.ts +20 -0
- package/dist/utils/flattenScale.js +24 -0
- package/dist/utils/flattenScale.js.map +1 -0
- package/dist/utils/getStaticProperties.d.ts +1 -0
- package/dist/utils/getStaticProperties.js +6 -0
- package/dist/utils/getStaticProperties.js.map +1 -0
- package/dist/utils/propNames.d.ts +6 -0
- package/dist/utils/propNames.js +52 -0
- package/dist/utils/propNames.js.map +1 -0
- package/dist/utils/responsive.d.ts +16 -0
- package/dist/utils/responsive.js +94 -0
- package/dist/utils/responsive.js.map +1 -0
- package/dist/utils/serializeTokens.d.ts +18 -0
- package/dist/utils/serializeTokens.js +42 -0
- package/dist/utils/serializeTokens.js.map +1 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,11 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
## [1.0.0-alpha.2627a4.0](https://github.com/Codecademy/gamut/compare/@codecademy/variance@0.19.0...@codecademy/variance@1.0.0-alpha.2627a4.0) (2022-01-25)
|
|
7
7
|
|
|
8
|
-
**Note:** Version bump only for package @codecademy/variance
|
|
9
8
|
|
|
9
|
+
### ⚠ BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* bumped React to 17
|
|
12
|
+
|
|
13
|
+
### Features
|
|
10
14
|
|
|
15
|
+
* bumped React to 17 ([c074ecb](https://github.com/Codecademy/gamut/commit/c074ecbfa026ed8e37cf41e874d345574a46e5e4))
|
|
11
16
|
|
|
12
17
|
|
|
13
18
|
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AbstractParser, AbstractPropTransformer, Compose, CSS, Parser, Prop, PropTransformer, States, TransformerMap, Variant } from './types/config';
|
|
2
|
+
export declare const variance: {
|
|
3
|
+
createParser<Config extends Record<string, AbstractPropTransformer>>(config: Config): Parser<Config>;
|
|
4
|
+
createTransform<P extends string, Config_1 extends Prop>(prop: P, config: Config_1): PropTransformer<P, Config_1>;
|
|
5
|
+
compose<Args extends AbstractParser[]>(...parsers: Args): Parser<Compose<Args>>;
|
|
6
|
+
createCss<Config_2 extends Record<string, Prop>, P_1 extends Parser<TransformerMap<Config_2>>>(config: Config_2): CSS<P_1>;
|
|
7
|
+
createVariant<Config_3 extends Record<string, Prop>, P_2 extends Parser<TransformerMap<Config_3>>>(config: Config_3): Variant<P_2>;
|
|
8
|
+
createStates<Config_4 extends Record<string, Prop>, P_3 extends Parser<TransformerMap<Config_4>>>(config: Config_4): States<P_3>;
|
|
9
|
+
create<Config_5 extends Record<string, Prop>>(config: Config_5): Parser<TransformerMap<Config_5>>;
|
|
10
|
+
};
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
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
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
|
+
|
|
9
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
10
|
+
|
|
11
|
+
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; }
|
|
12
|
+
|
|
13
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
14
|
+
|
|
15
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
16
|
+
|
|
17
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
+
|
|
19
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
20
|
+
|
|
21
|
+
import { get, identity, isArray, isObject, isUndefined, merge } from 'lodash';
|
|
22
|
+
import { createScaleLookup } from './scales/createScaleLookup';
|
|
23
|
+
import { getStaticCss } from './utils/getStaticProperties';
|
|
24
|
+
import { orderPropNames } from './utils/propNames';
|
|
25
|
+
import { arrayParser, isMediaArray, isMediaMap, objectParser, orderBreakpoints, parseBreakpoints } from './utils/responsive';
|
|
26
|
+
export var variance = {
|
|
27
|
+
// Parser to handle any set of configured props
|
|
28
|
+
createParser: function createParser(config) {
|
|
29
|
+
var propNames = orderPropNames(config);
|
|
30
|
+
var breakpoints;
|
|
31
|
+
|
|
32
|
+
var parser = function parser(props) {
|
|
33
|
+
var styles = {};
|
|
34
|
+
var theme = props.theme; // Attempt to cache the breakpoints if we have not yet or if theme has become available.
|
|
35
|
+
|
|
36
|
+
if (breakpoints === undefined || breakpoints === null && theme !== null && theme !== void 0 && theme.breakpoints) {
|
|
37
|
+
// Save the breakpoints if we can
|
|
38
|
+
breakpoints = parseBreakpoints(theme === null || theme === void 0 ? void 0 : theme.breakpoints);
|
|
39
|
+
} // Loops over all prop names on the configured config to check for configured styles
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
propNames.forEach(function (prop) {
|
|
43
|
+
var property = config[prop];
|
|
44
|
+
var value = get(props, prop);
|
|
45
|
+
|
|
46
|
+
switch (_typeof(value)) {
|
|
47
|
+
case 'string':
|
|
48
|
+
case 'number':
|
|
49
|
+
case 'function':
|
|
50
|
+
return Object.assign(styles, property.styleFn(value, prop, props));
|
|
51
|
+
// handle any props configured with the responsive notation
|
|
52
|
+
|
|
53
|
+
case 'object':
|
|
54
|
+
if (!breakpoints) {
|
|
55
|
+
return;
|
|
56
|
+
} // If it is an array the order of values is smallest to largest: [_, xs, ...]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if (isMediaArray(value)) {
|
|
60
|
+
return merge(styles, arrayParser(value, props, property, breakpoints.array));
|
|
61
|
+
} // Check to see if value is an object matching the responsive syntax and generate the styles.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if (isMediaMap(value)) {
|
|
65
|
+
return merge(styles, objectParser(value, props, property, breakpoints.map));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return breakpoints ? orderBreakpoints(styles, breakpoints.array) : styles;
|
|
71
|
+
}; // return the parser function with the resulting meta information for further composition
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
return Object.assign(parser, {
|
|
75
|
+
propNames: propNames,
|
|
76
|
+
config: config
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
// Given a single property configuration enrich the config with a transform function
|
|
80
|
+
// that traverses the properties the function is responsible for.
|
|
81
|
+
createTransform: function createTransform(prop, config) {
|
|
82
|
+
var _config$transform = config.transform,
|
|
83
|
+
transform = _config$transform === void 0 ? identity : _config$transform,
|
|
84
|
+
property = config.property,
|
|
85
|
+
_config$properties = config.properties,
|
|
86
|
+
properties = _config$properties === void 0 ? [property] : _config$properties,
|
|
87
|
+
scale = config.scale;
|
|
88
|
+
var getScaleValue = createScaleLookup(scale);
|
|
89
|
+
var alwaysTransform = scale === undefined || isArray(scale);
|
|
90
|
+
return _objectSpread(_objectSpread({}, config), {}, {
|
|
91
|
+
prop: prop,
|
|
92
|
+
styleFn: function styleFn(value, prop, props) {
|
|
93
|
+
var _scaleValue;
|
|
94
|
+
|
|
95
|
+
var styles = {};
|
|
96
|
+
|
|
97
|
+
if (isUndefined(value)) {
|
|
98
|
+
return styles;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
var useTransform = false;
|
|
102
|
+
var intermediateValue;
|
|
103
|
+
var scaleValue;
|
|
104
|
+
|
|
105
|
+
switch (_typeof(value)) {
|
|
106
|
+
case 'number':
|
|
107
|
+
case 'string':
|
|
108
|
+
scaleValue = getScaleValue(value, props);
|
|
109
|
+
useTransform = scaleValue !== undefined || alwaysTransform;
|
|
110
|
+
intermediateValue = (_scaleValue = scaleValue) !== null && _scaleValue !== void 0 ? _scaleValue : value;
|
|
111
|
+
break;
|
|
112
|
+
|
|
113
|
+
case 'function':
|
|
114
|
+
if (props.theme) {
|
|
115
|
+
intermediateValue = value(props.theme);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
default:
|
|
121
|
+
return styles;
|
|
122
|
+
} // for each property look up the scale value from theme if passed and apply any
|
|
123
|
+
// final transforms to the value
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
properties.forEach(function (property) {
|
|
127
|
+
var styleValue = intermediateValue;
|
|
128
|
+
|
|
129
|
+
if (useTransform && !isUndefined(styleValue)) {
|
|
130
|
+
styleValue = transform(styleValue, property, props);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
switch (_typeof(styleValue)) {
|
|
134
|
+
case 'number':
|
|
135
|
+
case 'string':
|
|
136
|
+
return styles[property] = styleValue;
|
|
137
|
+
|
|
138
|
+
case 'object':
|
|
139
|
+
return Object.assign(styles, styleValue);
|
|
140
|
+
|
|
141
|
+
default:
|
|
142
|
+
}
|
|
143
|
+
}); // return the resulting styles object
|
|
144
|
+
|
|
145
|
+
return styles;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
compose: function compose() {
|
|
150
|
+
for (var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
151
|
+
parsers[_key] = arguments[_key];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return this.createParser(parsers.reduce(function (carry, parser) {
|
|
155
|
+
return _objectSpread(_objectSpread({}, carry), parser.config);
|
|
156
|
+
}, {}));
|
|
157
|
+
},
|
|
158
|
+
createCss: function createCss(config) {
|
|
159
|
+
var parser = this.create(config);
|
|
160
|
+
var filteredProps = parser.propNames;
|
|
161
|
+
return function (cssProps) {
|
|
162
|
+
var cache;
|
|
163
|
+
var allKeys = Object.keys(cssProps);
|
|
164
|
+
/** Any key of the CSSProps that is not a System Prop or a Static CSS Property is treated as a nested selector */
|
|
165
|
+
|
|
166
|
+
var selectors = allKeys.filter(function (key) {
|
|
167
|
+
return !filteredProps.includes(key) && isObject(cssProps[key]);
|
|
168
|
+
});
|
|
169
|
+
/** Static CSS Properties get extracted if they match neither syntax */
|
|
170
|
+
|
|
171
|
+
var staticCss = getStaticCss(cssProps, ['theme'].concat(_toConsumableArray(selectors), _toConsumableArray(filteredProps)));
|
|
172
|
+
return function (_ref) {
|
|
173
|
+
var theme = _ref.theme;
|
|
174
|
+
if (cache) return cache;
|
|
175
|
+
var css = parser(_objectSpread(_objectSpread({}, cssProps), {}, {
|
|
176
|
+
theme: theme
|
|
177
|
+
}));
|
|
178
|
+
selectors.forEach(function (selector) {
|
|
179
|
+
var _cssProps$selector;
|
|
180
|
+
|
|
181
|
+
var selectorConfig = (_cssProps$selector = cssProps[selector]) !== null && _cssProps$selector !== void 0 ? _cssProps$selector : {};
|
|
182
|
+
css[selector] = _objectSpread(_objectSpread({}, getStaticCss(selectorConfig, filteredProps)), parser(_objectSpread(_objectSpread({}, selectorConfig), {}, {
|
|
183
|
+
theme: theme
|
|
184
|
+
})));
|
|
185
|
+
});
|
|
186
|
+
/** Merge the static and generated css and save it to the cache */
|
|
187
|
+
|
|
188
|
+
cache = _objectSpread(_objectSpread({}, staticCss), css);
|
|
189
|
+
return cache;
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
createVariant: function createVariant(config) {
|
|
194
|
+
var css = this.createCss(config);
|
|
195
|
+
return function (_ref2) {
|
|
196
|
+
var _ref2$prop = _ref2.prop,
|
|
197
|
+
prop = _ref2$prop === void 0 ? 'variant' : _ref2$prop,
|
|
198
|
+
defaultVariant = _ref2.defaultVariant,
|
|
199
|
+
_ref2$base = _ref2.base,
|
|
200
|
+
base = _ref2$base === void 0 ? {} : _ref2$base,
|
|
201
|
+
variants = _ref2.variants;
|
|
202
|
+
var baseFn = css(base);
|
|
203
|
+
var variantFns = {};
|
|
204
|
+
Object.keys(variants).forEach(function (key) {
|
|
205
|
+
var variantKey = key;
|
|
206
|
+
var cssProps = variants[variantKey];
|
|
207
|
+
variantFns[variantKey] = css(cssProps);
|
|
208
|
+
});
|
|
209
|
+
return function (props) {
|
|
210
|
+
var _variantFns;
|
|
211
|
+
|
|
212
|
+
var _props$prop = props[prop],
|
|
213
|
+
selected = _props$prop === void 0 ? defaultVariant : _props$prop;
|
|
214
|
+
var styles = {};
|
|
215
|
+
if (!selected) return styles;
|
|
216
|
+
return merge(styles, baseFn(props), variantFns === null || variantFns === void 0 ? void 0 : (_variantFns = variantFns[selected]) === null || _variantFns === void 0 ? void 0 : _variantFns.call(variantFns, props));
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
createStates: function createStates(config) {
|
|
221
|
+
var css = this.createCss(config);
|
|
222
|
+
return function (states) {
|
|
223
|
+
var orderedStates = Object.keys(states);
|
|
224
|
+
var stateFns = {};
|
|
225
|
+
orderedStates.forEach(function (key) {
|
|
226
|
+
var stateKey = key;
|
|
227
|
+
var cssProps = states[stateKey];
|
|
228
|
+
stateFns[stateKey] = css(cssProps);
|
|
229
|
+
});
|
|
230
|
+
return function (props) {
|
|
231
|
+
var styles = {};
|
|
232
|
+
orderedStates.forEach(function (state) {
|
|
233
|
+
merge(styles, props[state] && stateFns[state](props));
|
|
234
|
+
});
|
|
235
|
+
return styles;
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
create: function create(config) {
|
|
240
|
+
var transforms = {}; // Create a transform function for each of the props
|
|
241
|
+
|
|
242
|
+
for (var prop in config) {
|
|
243
|
+
if (typeof prop === 'string') {
|
|
244
|
+
transforms[prop] = this.createTransform(prop, config[prop]);
|
|
245
|
+
}
|
|
246
|
+
} // Create a parser that handles all the props within the config
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
return this.createParser(transforms);
|
|
250
|
+
}
|
|
251
|
+
};
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,QA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/theme';
|
|
3
|
+
import { LiteralPaths } from '../utils/flattenScale';
|
|
4
|
+
import { KeyAsVariable } from '../utils/serializeTokens';
|
|
5
|
+
import { ColorModeConfig, Merge, MergeTheme, PrivateThemeKeys } from './types';
|
|
6
|
+
declare class ThemeBuilder<T extends AbstractTheme> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(baseTheme: T);
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param key A key of the current theme to transform into CSS Variables and Variable References
|
|
12
|
+
* @example .createScaleVariables('fontSize')
|
|
13
|
+
*/
|
|
14
|
+
createScaleVariables<Key extends keyof Omit<T, 'breakpoints'> & string>(key: Key): ThemeBuilder<MergeTheme<T, PrivateThemeKeys, Record<Key, Record<Key, KeyAsVariable<T[Key], Key>>>>>;
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
|
|
18
|
+
* @example .addColors({ navy: 'navy', hyper: 'purple' })
|
|
19
|
+
*/
|
|
20
|
+
addColors<Colors extends Record<string, string | number | CSSObject>, NextColors extends LiteralPaths<Colors, '-'>>(colors: Colors): ThemeBuilder<MergeTheme<T & PrivateThemeKeys, Record<'colors', KeyAsVariable<NextColors, 'color'>>>>;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
|
|
24
|
+
* @param modes A map of color modes with keys of each possible mode with a value of alias to color keys. This must be called after `addColors`
|
|
25
|
+
* @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
|
|
26
|
+
*/
|
|
27
|
+
addColorModes<Modes extends string, InitialMode extends keyof Config, Colors extends keyof T['colors'], ModeColors extends ColorModeConfig<Colors>, Config extends Record<Modes, ModeColors>, ColorAliases extends {
|
|
28
|
+
[K in keyof Config]: LiteralPaths<Config[K], '-', '_'>;
|
|
29
|
+
}>(initialMode: InitialMode, modeConfig: Config): ThemeBuilder<MergeTheme<T & PrivateThemeKeys, {
|
|
30
|
+
colors: KeyAsVariable<LiteralPaths<Config[keyof Config], '-', '_'>, 'colors'> & T['colors'];
|
|
31
|
+
modes: Merge<T['modes'], ColorAliases>;
|
|
32
|
+
mode: keyof Config;
|
|
33
|
+
_getColorValue: (color: keyof T['colors']) => string;
|
|
34
|
+
}>>;
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param key A new key of theme
|
|
38
|
+
* @param createScale A function that accepts the current theme and returns a new object of scale values.
|
|
39
|
+
* @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
|
|
40
|
+
*/
|
|
41
|
+
addScale<Key extends string, Fn extends (theme: T) => Record<string | number, string | number | Record<string, string | number>>, NewScale extends LiteralPaths<ReturnType<Fn>, '-'>>(key: Key, createScale: Fn): ThemeBuilder<MergeTheme<T, Record<Key, NewScale>>>;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param key A current key of theme to be updated with new or computed values
|
|
45
|
+
* @param updateFn A function that accepts an argument of the current values at the specified keys an returns a map of new values to merge.
|
|
46
|
+
* @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
|
|
47
|
+
*/
|
|
48
|
+
updateScale<Key extends keyof T, Fn extends (tokens: T[Key]) => Record<string | number, unknown>>(key: Key, updateFn: Fn): ThemeBuilder<T & Record<Key, T[Key] & ReturnType<Fn>>>;
|
|
49
|
+
/**
|
|
50
|
+
* This finalizes the theme build and returns the final theme and variables to be provided.
|
|
51
|
+
*/
|
|
52
|
+
build(): T & PrivateThemeKeys;
|
|
53
|
+
}
|
|
54
|
+
export declare function createTheme<T extends AbstractTheme>(base: T): ThemeBuilder<T>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
|
|
5
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
6
|
+
|
|
7
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
8
|
+
|
|
9
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
10
|
+
|
|
11
|
+
var id = 0;
|
|
12
|
+
|
|
13
|
+
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
14
|
+
|
|
15
|
+
import { mapValues, merge } from 'lodash';
|
|
16
|
+
import { flattenScale } from '../utils/flattenScale';
|
|
17
|
+
import { serializeTokens } from '../utils/serializeTokens';
|
|
18
|
+
|
|
19
|
+
var _theme = _classPrivateFieldLooseKey("theme");
|
|
20
|
+
|
|
21
|
+
var ThemeBuilder = /*#__PURE__*/function () {
|
|
22
|
+
function ThemeBuilder(baseTheme) {
|
|
23
|
+
_classCallCheck(this, ThemeBuilder);
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(this, _theme, {
|
|
26
|
+
writable: true,
|
|
27
|
+
value: {}
|
|
28
|
+
});
|
|
29
|
+
_classPrivateFieldLooseBase(this, _theme)[_theme] = baseTheme;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param key A key of the current theme to transform into CSS Variables and Variable References
|
|
34
|
+
* @example .createScaleVariables('fontSize')
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
_createClass(ThemeBuilder, [{
|
|
39
|
+
key: "createScaleVariables",
|
|
40
|
+
value: function createScaleVariables(key) {
|
|
41
|
+
var _merge;
|
|
42
|
+
|
|
43
|
+
var _serializeTokens = serializeTokens(_classPrivateFieldLooseBase(this, _theme)[_theme][key], key, _classPrivateFieldLooseBase(this, _theme)[_theme]),
|
|
44
|
+
variables = _serializeTokens.variables,
|
|
45
|
+
tokens = _serializeTokens.tokens;
|
|
46
|
+
|
|
47
|
+
_classPrivateFieldLooseBase(this, _theme)[_theme] = merge({}, _classPrivateFieldLooseBase(this, _theme)[_theme], (_merge = {}, _defineProperty(_merge, key, tokens), _defineProperty(_merge, "_variables", {
|
|
48
|
+
root: variables
|
|
49
|
+
}), _defineProperty(_merge, "_tokens", _defineProperty({}, key, _classPrivateFieldLooseBase(this, _theme)[_theme][key])), _merge));
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
|
|
55
|
+
* @example .addColors({ navy: 'navy', hyper: 'purple' })
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
}, {
|
|
59
|
+
key: "addColors",
|
|
60
|
+
value: function addColors(colors) {
|
|
61
|
+
var flatColors = flattenScale(colors);
|
|
62
|
+
|
|
63
|
+
var _serializeTokens2 = serializeTokens(flatColors, 'color', _classPrivateFieldLooseBase(this, _theme)[_theme]),
|
|
64
|
+
variables = _serializeTokens2.variables,
|
|
65
|
+
tokens = _serializeTokens2.tokens;
|
|
66
|
+
|
|
67
|
+
_classPrivateFieldLooseBase(this, _theme)[_theme] = merge({}, _classPrivateFieldLooseBase(this, _theme)[_theme], {
|
|
68
|
+
colors: tokens,
|
|
69
|
+
_variables: {
|
|
70
|
+
root: variables
|
|
71
|
+
},
|
|
72
|
+
_tokens: {
|
|
73
|
+
colors: flatColors
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
|
|
81
|
+
* @param modes A map of color modes with keys of each possible mode with a value of alias to color keys. This must be called after `addColors`
|
|
82
|
+
* @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
}, {
|
|
86
|
+
key: "addColorModes",
|
|
87
|
+
value: function addColorModes(initialMode, modeConfig) {
|
|
88
|
+
var _classPrivateFieldLoo,
|
|
89
|
+
_this = this;
|
|
90
|
+
|
|
91
|
+
var modes = mapValues(modeConfig, function (mode) {
|
|
92
|
+
return flattenScale(mode);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
var _serializeTokens3 = serializeTokens(mapValues(merge({}, (_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _theme)[_theme].modes) === null || _classPrivateFieldLoo === void 0 ? void 0 : _classPrivateFieldLoo[initialMode], modes[initialMode]), function (color) {
|
|
96
|
+
return _classPrivateFieldLooseBase(_this, _theme)[_theme].colors[color];
|
|
97
|
+
}), 'color', _classPrivateFieldLooseBase(this, _theme)[_theme]),
|
|
98
|
+
colors = _serializeTokens3.tokens,
|
|
99
|
+
variables = _serializeTokens3.variables;
|
|
100
|
+
|
|
101
|
+
var getColorValue = function getColorValue(color) {
|
|
102
|
+
var _classPrivateFieldLoo2, _classPrivateFieldLoo3;
|
|
103
|
+
|
|
104
|
+
return (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_this, _theme)[_theme]._tokens) === null || _classPrivateFieldLoo2 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLoo2.colors) === null || _classPrivateFieldLoo3 === void 0 ? void 0 : _classPrivateFieldLoo3[color];
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
_classPrivateFieldLooseBase(this, _theme)[_theme] = merge({}, _classPrivateFieldLooseBase(this, _theme)[_theme], {
|
|
108
|
+
colors: colors,
|
|
109
|
+
modes: modes,
|
|
110
|
+
mode: initialMode,
|
|
111
|
+
_getColorValue: getColorValue,
|
|
112
|
+
_variables: {
|
|
113
|
+
mode: variables
|
|
114
|
+
},
|
|
115
|
+
_tokens: {
|
|
116
|
+
modes: mapValues(modes, function (mode) {
|
|
117
|
+
return mapValues(mode, getColorValue);
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
*
|
|
125
|
+
* @param key A new key of theme
|
|
126
|
+
* @param createScale A function that accepts the current theme and returns a new object of scale values.
|
|
127
|
+
* @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
}, {
|
|
131
|
+
key: "addScale",
|
|
132
|
+
value: function addScale(key, createScale) {
|
|
133
|
+
_classPrivateFieldLooseBase(this, _theme)[_theme] = merge({}, _classPrivateFieldLooseBase(this, _theme)[_theme], _defineProperty({}, key, flattenScale(createScale(_classPrivateFieldLooseBase(this, _theme)[_theme]))));
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
*
|
|
138
|
+
* @param key A current key of theme to be updated with new or computed values
|
|
139
|
+
* @param updateFn A function that accepts an argument of the current values at the specified keys an returns a map of new values to merge.
|
|
140
|
+
* @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
}, {
|
|
144
|
+
key: "updateScale",
|
|
145
|
+
value: function updateScale(key, updateFn) {
|
|
146
|
+
_classPrivateFieldLooseBase(this, _theme)[_theme] = merge({}, _classPrivateFieldLooseBase(this, _theme)[_theme], _defineProperty({}, key, updateFn(_classPrivateFieldLooseBase(this, _theme)[_theme][key])));
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* This finalizes the theme build and returns the final theme and variables to be provided.
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
}, {
|
|
154
|
+
key: "build",
|
|
155
|
+
value: function build() {
|
|
156
|
+
return merge({}, _classPrivateFieldLooseBase(this, _theme)[_theme], {
|
|
157
|
+
_variables: {},
|
|
158
|
+
_tokens: {}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}]);
|
|
162
|
+
|
|
163
|
+
return ThemeBuilder;
|
|
164
|
+
}();
|
|
165
|
+
|
|
166
|
+
export function createTheme(base) {
|
|
167
|
+
return new ThemeBuilder(base);
|
|
168
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTheme.js","sourceRoot":"","sources":["../../src/createTheme/createTheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAI1C,OAAO,EAAE,YAAY,EAAgB,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAiB,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAG1E,MAAM,YAAY;IAChB,MAAM,GAAG,EAAO,CAAC;IAEjB,YAAY,SAAY;QACtB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;IACD;;;;OAIG;IACH,oBAAoB,CAClB,GAAQ;QAQR,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,eAAe,CAC3C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAChB,GAAG,EACH,IAAI,CAAC,MAAM,CACZ,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE;YACnC,CAAC,GAAG,CAAC,EAAE,MAAM;YACb,UAAU,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;YAC/B,OAAO,EAAE;gBACP,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,MAA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