@codecademy/variance 0.20.4 → 0.20.5-alpha.b44e47.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/createTheme/createTheme.js +33 -23
- package/package.json +2 -2
|
@@ -6,27 +6,32 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
6
6
|
|
|
7
7
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
8
|
|
|
9
|
-
function
|
|
9
|
+
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
12
12
|
|
|
13
|
-
function
|
|
13
|
+
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
14
|
+
|
|
15
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
16
|
+
|
|
17
|
+
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
|
|
14
18
|
|
|
15
19
|
import { mapValues, merge } from 'lodash';
|
|
16
20
|
import { flattenScale } from '../utils/flattenScale';
|
|
17
21
|
import { serializeTokens } from '../utils/serializeTokens';
|
|
18
22
|
|
|
19
|
-
var _theme =
|
|
23
|
+
var _theme = new WeakMap();
|
|
20
24
|
|
|
21
25
|
var ThemeBuilder = /*#__PURE__*/function () {
|
|
22
26
|
function ThemeBuilder(baseTheme) {
|
|
23
27
|
_classCallCheck(this, ThemeBuilder);
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
_theme.set(this, {
|
|
26
30
|
writable: true,
|
|
27
31
|
value: {}
|
|
28
32
|
});
|
|
29
|
-
|
|
33
|
+
|
|
34
|
+
_classPrivateFieldSet(this, _theme, baseTheme);
|
|
30
35
|
}
|
|
31
36
|
/**
|
|
32
37
|
*
|
|
@@ -40,13 +45,14 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
40
45
|
value: function createScaleVariables(key) {
|
|
41
46
|
var _merge;
|
|
42
47
|
|
|
43
|
-
var _serializeTokens = serializeTokens(
|
|
48
|
+
var _serializeTokens = serializeTokens(_classPrivateFieldGet(this, _theme)[key], key, _classPrivateFieldGet(this, _theme)),
|
|
44
49
|
variables = _serializeTokens.variables,
|
|
45
50
|
tokens = _serializeTokens.tokens;
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), (_merge = {}, _defineProperty(_merge, key, tokens), _defineProperty(_merge, "_variables", {
|
|
48
53
|
root: variables
|
|
49
|
-
}), _defineProperty(_merge, "_tokens", _defineProperty({}, key,
|
|
54
|
+
}), _defineProperty(_merge, "_tokens", _defineProperty({}, key, _classPrivateFieldGet(this, _theme)[key])), _merge)));
|
|
55
|
+
|
|
50
56
|
return this;
|
|
51
57
|
}
|
|
52
58
|
/**
|
|
@@ -60,11 +66,11 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
60
66
|
value: function addColors(colors) {
|
|
61
67
|
var flatColors = flattenScale(colors);
|
|
62
68
|
|
|
63
|
-
var _serializeTokens2 = serializeTokens(flatColors, 'color',
|
|
69
|
+
var _serializeTokens2 = serializeTokens(flatColors, 'color', _classPrivateFieldGet(this, _theme)),
|
|
64
70
|
variables = _serializeTokens2.variables,
|
|
65
71
|
tokens = _serializeTokens2.tokens;
|
|
66
72
|
|
|
67
|
-
|
|
73
|
+
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), {
|
|
68
74
|
colors: tokens,
|
|
69
75
|
_variables: {
|
|
70
76
|
root: variables
|
|
@@ -72,7 +78,8 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
72
78
|
_tokens: {
|
|
73
79
|
colors: flatColors
|
|
74
80
|
}
|
|
75
|
-
});
|
|
81
|
+
}));
|
|
82
|
+
|
|
76
83
|
return this;
|
|
77
84
|
}
|
|
78
85
|
/**
|
|
@@ -85,26 +92,26 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
85
92
|
}, {
|
|
86
93
|
key: "addColorModes",
|
|
87
94
|
value: function addColorModes(initialMode, modeConfig) {
|
|
88
|
-
var
|
|
95
|
+
var _classPrivateFieldGet2,
|
|
89
96
|
_this = this;
|
|
90
97
|
|
|
91
98
|
var modes = mapValues(modeConfig, function (mode) {
|
|
92
99
|
return flattenScale(mode);
|
|
93
100
|
});
|
|
94
101
|
|
|
95
|
-
var _serializeTokens3 = serializeTokens(mapValues(merge({}, (
|
|
96
|
-
return
|
|
97
|
-
}), 'color',
|
|
102
|
+
var _serializeTokens3 = serializeTokens(mapValues(merge({}, (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _theme).modes) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2[initialMode], modes[initialMode]), function (color) {
|
|
103
|
+
return _classPrivateFieldGet(_this, _theme).colors[color];
|
|
104
|
+
}), 'color', _classPrivateFieldGet(this, _theme)),
|
|
98
105
|
colors = _serializeTokens3.tokens,
|
|
99
106
|
variables = _serializeTokens3.variables;
|
|
100
107
|
|
|
101
108
|
var getColorValue = function getColorValue(color) {
|
|
102
|
-
var
|
|
109
|
+
var _classPrivateFieldGet3, _classPrivateFieldGet4;
|
|
103
110
|
|
|
104
|
-
return (
|
|
111
|
+
return (_classPrivateFieldGet3 = _classPrivateFieldGet(_this, _theme)._tokens) === null || _classPrivateFieldGet3 === void 0 ? void 0 : (_classPrivateFieldGet4 = _classPrivateFieldGet3.colors) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4[color];
|
|
105
112
|
};
|
|
106
113
|
|
|
107
|
-
|
|
114
|
+
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), {
|
|
108
115
|
colors: colors,
|
|
109
116
|
modes: modes,
|
|
110
117
|
mode: initialMode,
|
|
@@ -117,7 +124,8 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
117
124
|
return mapValues(mode, getColorValue);
|
|
118
125
|
})
|
|
119
126
|
}
|
|
120
|
-
});
|
|
127
|
+
}));
|
|
128
|
+
|
|
121
129
|
return this;
|
|
122
130
|
}
|
|
123
131
|
/**
|
|
@@ -130,7 +138,8 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
130
138
|
}, {
|
|
131
139
|
key: "addScale",
|
|
132
140
|
value: function addScale(key, createScale) {
|
|
133
|
-
|
|
141
|
+
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, flattenScale(createScale(_classPrivateFieldGet(this, _theme))))));
|
|
142
|
+
|
|
134
143
|
return this;
|
|
135
144
|
}
|
|
136
145
|
/**
|
|
@@ -143,7 +152,8 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
143
152
|
}, {
|
|
144
153
|
key: "updateScale",
|
|
145
154
|
value: function updateScale(key, updateFn) {
|
|
146
|
-
|
|
155
|
+
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, updateFn(_classPrivateFieldGet(this, _theme)[key]))));
|
|
156
|
+
|
|
147
157
|
return this;
|
|
148
158
|
}
|
|
149
159
|
/**
|
|
@@ -153,7 +163,7 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
153
163
|
}, {
|
|
154
164
|
key: "build",
|
|
155
165
|
value: function build() {
|
|
156
|
-
return merge({},
|
|
166
|
+
return merge({}, _classPrivateFieldGet(this, _theme), {
|
|
157
167
|
_variables: {},
|
|
158
168
|
_tokens: {}
|
|
159
169
|
});
|
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": "0.20.
|
|
4
|
+
"version": "0.20.5-alpha.b44e47.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"emotion",
|
|
7
7
|
"css",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"react": "17.0.2",
|
|
43
43
|
"react-test-renderer": "17.0.2"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "9342213b2938ef038d15d15265d11838ba9fec93"
|
|
46
46
|
}
|