styled-components 6.0.0-alpha.7 → 6.0.0-beta.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/README.md +2 -2
- package/dist/styled-components-macro.cjs.js +1 -1
- package/dist/styled-components-macro.cjs.js.map +1 -1
- package/dist/styled-components-macro.esm.js +1 -1
- package/dist/styled-components-macro.esm.js.map +1 -1
- package/dist/styled-components.browser.cjs.js +1 -1
- package/dist/styled-components.browser.cjs.js.map +1 -1
- package/dist/styled-components.browser.esm.js +1 -1
- package/dist/styled-components.browser.esm.js.map +1 -1
- package/dist/styled-components.cjs.js +1 -1
- package/dist/styled-components.cjs.js.map +1 -1
- package/dist/styled-components.esm.js +1 -1
- package/dist/styled-components.esm.js.map +1 -1
- package/dist/styled-components.js +1 -1
- package/dist/styled-components.js.map +1 -1
- package/dist/styled-components.min.js +1 -1
- package/dist/styled-components.min.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/native/dist/styled-components.native.cjs.js +432 -400
- package/native/dist/styled-components.native.cjs.js.map +1 -1
- package/native/dist/styled-components.native.esm.js +432 -400
- package/native/dist/styled-components.native.esm.js.map +1 -1
- package/package.json +8 -7
- package/test-utils/setupTestFramework.ts +9 -3
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var tslib = require('tslib');
|
|
5
6
|
var React = require('react');
|
|
6
7
|
require('shallowequal');
|
|
7
8
|
var stylis = require('stylis');
|
|
@@ -15,8 +16,8 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
|
15
16
|
var unitless__default = /*#__PURE__*/_interopDefaultLegacy(unitless);
|
|
16
17
|
var transformDeclPairs__default = /*#__PURE__*/_interopDefaultLegacy(transformDeclPairs);
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
var EMPTY_ARRAY = Object.freeze([]);
|
|
20
|
+
var EMPTY_OBJECT = Object.freeze({});
|
|
20
21
|
|
|
21
22
|
var errorMap = {
|
|
22
23
|
'1': 'Cannot create styled-component for component: %s.\n\n',
|
|
@@ -38,17 +39,21 @@ var errorMap = {
|
|
|
38
39
|
'17': "CSSStyleSheet could not be found on HTMLStyleElement.\nHas styled-components' style tag been unmounted or altered by another script?\n",
|
|
39
40
|
};
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
var ERRORS = process.env.NODE_ENV !== 'production' ? errorMap : {};
|
|
42
43
|
/**
|
|
43
44
|
* super basic version of sprintf
|
|
44
45
|
*/
|
|
45
|
-
function format(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
function format() {
|
|
47
|
+
var args = [];
|
|
48
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
49
|
+
args[_i] = arguments[_i];
|
|
50
|
+
}
|
|
51
|
+
var a = args[0];
|
|
52
|
+
var b = [];
|
|
53
|
+
for (var c = 1, len = args.length; c < len; c += 1) {
|
|
49
54
|
b.push(args[c]);
|
|
50
55
|
}
|
|
51
|
-
b.forEach(d
|
|
56
|
+
b.forEach(function (d) {
|
|
52
57
|
a = a.replace(/%[a-z]/, d);
|
|
53
58
|
});
|
|
54
59
|
return a;
|
|
@@ -57,23 +62,27 @@ function format(...args) {
|
|
|
57
62
|
* Create an error file out of errors.md for development and a simple web link to the full errors
|
|
58
63
|
* in production mode.
|
|
59
64
|
*/
|
|
60
|
-
function throwStyledComponentsError(code
|
|
65
|
+
function throwStyledComponentsError(code) {
|
|
66
|
+
var interpolations = [];
|
|
67
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
68
|
+
interpolations[_i - 1] = arguments[_i];
|
|
69
|
+
}
|
|
61
70
|
if (process.env.NODE_ENV === 'production') {
|
|
62
|
-
return new Error(
|
|
71
|
+
return new Error("An error occurred. See https://github.com/styled-components/styled-components/blob/main/packages/styled-components/src/utils/errors.md#".concat(code, " for more information.").concat(interpolations.length > 0 ? " Args: ".concat(interpolations.join(', ')) : ''));
|
|
63
72
|
}
|
|
64
73
|
else {
|
|
65
|
-
return new Error(format(ERRORS[code],
|
|
74
|
+
return new Error(format.apply(void 0, tslib.__spreadArray([ERRORS[code]], interpolations, false)).trim());
|
|
66
75
|
}
|
|
67
76
|
}
|
|
68
77
|
|
|
69
|
-
|
|
78
|
+
var SC_ATTR = (typeof process !== 'undefined' && (process.env.REACT_APP_SC_ATTR || process.env.SC_ATTR)) ||
|
|
70
79
|
'data-styled';
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
var SC_ATTR_ACTIVE = 'active';
|
|
81
|
+
var SC_ATTR_VERSION = 'data-styled-version';
|
|
82
|
+
var SC_VERSION = "6.0.0-beta.0";
|
|
83
|
+
var SPLITTER = '/*!sc*/\n';
|
|
84
|
+
var IS_BROWSER = typeof window !== 'undefined' && 'HTMLElement' in window;
|
|
85
|
+
var DISABLE_SPEEDY = Boolean(typeof SC_DISABLE_SPEEDY === 'boolean'
|
|
77
86
|
? SC_DISABLE_SPEEDY
|
|
78
87
|
: typeof process !== 'undefined' &&
|
|
79
88
|
typeof process.env.REACT_APP_SC_DISABLE_SPEEDY !== 'undefined' &&
|
|
@@ -90,47 +99,44 @@ const DISABLE_SPEEDY = Boolean(typeof SC_DISABLE_SPEEDY === 'boolean'
|
|
|
90
99
|
: process.env.NODE_ENV !== 'production');
|
|
91
100
|
|
|
92
101
|
/** Create a GroupedTag with an underlying Tag implementation */
|
|
93
|
-
|
|
102
|
+
var makeGroupedTag = function (tag) {
|
|
94
103
|
return new DefaultGroupedTag(tag);
|
|
95
104
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
length;
|
|
100
|
-
tag;
|
|
101
|
-
constructor(tag) {
|
|
105
|
+
var BASE_SIZE = 1 << 9;
|
|
106
|
+
var DefaultGroupedTag = /** @class */ (function () {
|
|
107
|
+
function DefaultGroupedTag(tag) {
|
|
102
108
|
this.groupSizes = new Uint32Array(BASE_SIZE);
|
|
103
109
|
this.length = BASE_SIZE;
|
|
104
110
|
this.tag = tag;
|
|
105
111
|
}
|
|
106
|
-
indexOfGroup(group) {
|
|
107
|
-
|
|
108
|
-
for (
|
|
112
|
+
DefaultGroupedTag.prototype.indexOfGroup = function (group) {
|
|
113
|
+
var index = 0;
|
|
114
|
+
for (var i = 0; i < group; i++) {
|
|
109
115
|
index += this.groupSizes[i];
|
|
110
116
|
}
|
|
111
117
|
return index;
|
|
112
|
-
}
|
|
113
|
-
insertRules(group, rules) {
|
|
118
|
+
};
|
|
119
|
+
DefaultGroupedTag.prototype.insertRules = function (group, rules) {
|
|
114
120
|
if (group >= this.groupSizes.length) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
var oldBuffer = this.groupSizes;
|
|
122
|
+
var oldSize = oldBuffer.length;
|
|
123
|
+
var newSize = oldSize;
|
|
118
124
|
while (group >= newSize) {
|
|
119
125
|
newSize <<= 1;
|
|
120
126
|
if (newSize < 0) {
|
|
121
|
-
throw throwStyledComponentsError(16,
|
|
127
|
+
throw throwStyledComponentsError(16, "".concat(group));
|
|
122
128
|
}
|
|
123
129
|
}
|
|
124
130
|
this.groupSizes = new Uint32Array(newSize);
|
|
125
131
|
this.groupSizes.set(oldBuffer);
|
|
126
132
|
this.length = newSize;
|
|
127
|
-
for (
|
|
133
|
+
for (var i = oldSize; i < newSize; i++) {
|
|
128
134
|
this.groupSizes[i] = 0;
|
|
129
135
|
}
|
|
130
136
|
}
|
|
131
|
-
|
|
137
|
+
var ruleIndex = this.indexOfGroup(group + 1);
|
|
132
138
|
if (Array.isArray(rules)) {
|
|
133
|
-
for (
|
|
139
|
+
for (var i = 0, l = rules.length; i < l; i++) {
|
|
134
140
|
if (this.tag.insertRule(ruleIndex, rules[i])) {
|
|
135
141
|
this.groupSizes[group]++;
|
|
136
142
|
ruleIndex++;
|
|
@@ -142,110 +148,115 @@ const DefaultGroupedTag = class DefaultGroupedTag {
|
|
|
142
148
|
this.groupSizes[group]++;
|
|
143
149
|
}
|
|
144
150
|
}
|
|
145
|
-
}
|
|
146
|
-
clearGroup(group) {
|
|
151
|
+
};
|
|
152
|
+
DefaultGroupedTag.prototype.clearGroup = function (group) {
|
|
147
153
|
if (group < this.length) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
var length_1 = this.groupSizes[group];
|
|
155
|
+
var startIndex = this.indexOfGroup(group);
|
|
156
|
+
var endIndex = startIndex + length_1;
|
|
151
157
|
this.groupSizes[group] = 0;
|
|
152
|
-
for (
|
|
158
|
+
for (var i = startIndex; i < endIndex; i++) {
|
|
153
159
|
this.tag.deleteRule(startIndex);
|
|
154
160
|
}
|
|
155
161
|
}
|
|
156
|
-
}
|
|
157
|
-
getGroup(group) {
|
|
158
|
-
|
|
162
|
+
};
|
|
163
|
+
DefaultGroupedTag.prototype.getGroup = function (group) {
|
|
164
|
+
var css = '';
|
|
159
165
|
if (group >= this.length || this.groupSizes[group] === 0) {
|
|
160
166
|
return css;
|
|
161
167
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
for (
|
|
166
|
-
css +=
|
|
168
|
+
var length = this.groupSizes[group];
|
|
169
|
+
var startIndex = this.indexOfGroup(group);
|
|
170
|
+
var endIndex = startIndex + length;
|
|
171
|
+
for (var i = startIndex; i < endIndex; i++) {
|
|
172
|
+
css += "".concat(this.tag.getRule(i)).concat(SPLITTER);
|
|
167
173
|
}
|
|
168
174
|
return css;
|
|
169
|
-
}
|
|
170
|
-
|
|
175
|
+
};
|
|
176
|
+
return DefaultGroupedTag;
|
|
177
|
+
}());
|
|
171
178
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
var MAX_SMI = 1 << (31 - 1);
|
|
180
|
+
var groupIDRegister = new Map();
|
|
181
|
+
var reverseRegister = new Map();
|
|
182
|
+
var nextFreeGroup = 1;
|
|
183
|
+
var getGroupForId = function (id) {
|
|
177
184
|
if (groupIDRegister.has(id)) {
|
|
178
185
|
return groupIDRegister.get(id);
|
|
179
186
|
}
|
|
180
187
|
while (reverseRegister.has(nextFreeGroup)) {
|
|
181
188
|
nextFreeGroup++;
|
|
182
189
|
}
|
|
183
|
-
|
|
190
|
+
var group = nextFreeGroup++;
|
|
184
191
|
if (process.env.NODE_ENV !== 'production' && ((group | 0) < 0 || group > MAX_SMI)) {
|
|
185
|
-
throw throwStyledComponentsError(16,
|
|
192
|
+
throw throwStyledComponentsError(16, "".concat(group));
|
|
186
193
|
}
|
|
187
194
|
groupIDRegister.set(id, group);
|
|
188
195
|
reverseRegister.set(group, id);
|
|
189
196
|
return group;
|
|
190
197
|
};
|
|
191
|
-
|
|
198
|
+
var getIdForGroup = function (group) {
|
|
192
199
|
return reverseRegister.get(group);
|
|
193
200
|
};
|
|
194
|
-
|
|
201
|
+
var setGroupForId = function (id, group) {
|
|
195
202
|
groupIDRegister.set(id, group);
|
|
196
203
|
reverseRegister.set(group, id);
|
|
197
204
|
};
|
|
198
205
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
206
|
+
var SELECTOR = "style[".concat(SC_ATTR, "][").concat(SC_ATTR_VERSION, "=\"").concat(SC_VERSION, "\"]");
|
|
207
|
+
var MARKER_RE = new RegExp("^".concat(SC_ATTR, "\\.g(\\d+)\\[id=\"([\\w\\d-]+)\"\\].*?\"([^\"]*)"));
|
|
208
|
+
var outputSheet = function (sheet) {
|
|
209
|
+
var tag = sheet.getTag();
|
|
210
|
+
var length = tag.length;
|
|
211
|
+
var css = '';
|
|
212
|
+
var _loop_1 = function (group) {
|
|
213
|
+
var id = getIdForGroup(group);
|
|
207
214
|
if (id === undefined)
|
|
208
|
-
continue;
|
|
209
|
-
|
|
210
|
-
|
|
215
|
+
return "continue";
|
|
216
|
+
var names = sheet.names.get(id);
|
|
217
|
+
var rules = tag.getGroup(group);
|
|
211
218
|
if (names === undefined || rules.length === 0)
|
|
212
|
-
continue;
|
|
213
|
-
|
|
214
|
-
|
|
219
|
+
return "continue";
|
|
220
|
+
var selector = "".concat(SC_ATTR, ".g").concat(group, "[id=\"").concat(id, "\"]");
|
|
221
|
+
var content = '';
|
|
215
222
|
if (names !== undefined) {
|
|
216
|
-
names.forEach(name
|
|
223
|
+
names.forEach(function (name) {
|
|
217
224
|
if (name.length > 0) {
|
|
218
|
-
content +=
|
|
225
|
+
content += "".concat(name, ",");
|
|
219
226
|
}
|
|
220
227
|
});
|
|
221
228
|
}
|
|
222
229
|
// NOTE: It's easier to collect rules and have the marker
|
|
223
230
|
// after the actual rules to simplify the rehydration
|
|
224
|
-
css +=
|
|
231
|
+
css += "".concat(rules).concat(selector, "{content:\"").concat(content, "\"}").concat(SPLITTER);
|
|
232
|
+
};
|
|
233
|
+
for (var group = 0; group < length; group++) {
|
|
234
|
+
_loop_1(group);
|
|
225
235
|
}
|
|
226
236
|
return css;
|
|
227
237
|
};
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
for (
|
|
238
|
+
var rehydrateNamesFromContent = function (sheet, id, content) {
|
|
239
|
+
var names = content.split(',');
|
|
240
|
+
var name;
|
|
241
|
+
for (var i = 0, l = names.length; i < l; i++) {
|
|
232
242
|
// eslint-disable-next-line
|
|
233
243
|
if ((name = names[i])) {
|
|
234
244
|
sheet.registerName(id, name);
|
|
235
245
|
}
|
|
236
246
|
}
|
|
237
247
|
};
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
248
|
+
var rehydrateSheetFromTag = function (sheet, style) {
|
|
249
|
+
var _a;
|
|
250
|
+
var parts = ((_a = style.textContent) !== null && _a !== void 0 ? _a : '').split(SPLITTER);
|
|
251
|
+
var rules = [];
|
|
252
|
+
for (var i = 0, l = parts.length; i < l; i++) {
|
|
253
|
+
var part = parts[i].trim();
|
|
243
254
|
if (!part)
|
|
244
255
|
continue;
|
|
245
|
-
|
|
256
|
+
var marker = part.match(MARKER_RE);
|
|
246
257
|
if (marker) {
|
|
247
|
-
|
|
248
|
-
|
|
258
|
+
var group = parseInt(marker[1], 10) | 0;
|
|
259
|
+
var id = marker[2];
|
|
249
260
|
if (group !== 0) {
|
|
250
261
|
// Rehydrate componentId to group index mapping
|
|
251
262
|
setGroupForId(id, group);
|
|
@@ -261,10 +272,10 @@ const rehydrateSheetFromTag = (sheet, style) => {
|
|
|
261
272
|
}
|
|
262
273
|
}
|
|
263
274
|
};
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
for (
|
|
267
|
-
|
|
275
|
+
var rehydrateSheet = function (sheet) {
|
|
276
|
+
var nodes = document.querySelectorAll(SELECTOR);
|
|
277
|
+
for (var i = 0, l = nodes.length; i < l; i++) {
|
|
278
|
+
var node = nodes[i];
|
|
268
279
|
if (node && node.getAttribute(SC_ATTR) !== SC_ATTR_ACTIVE) {
|
|
269
280
|
rehydrateSheetFromTag(sheet, node);
|
|
270
281
|
if (node.parentNode) {
|
|
@@ -278,13 +289,13 @@ function getNonce() {
|
|
|
278
289
|
return typeof __webpack_nonce__ !== 'undefined' ? __webpack_nonce__ : null;
|
|
279
290
|
}
|
|
280
291
|
|
|
281
|
-
|
|
292
|
+
var ELEMENT_TYPE = 1;
|
|
282
293
|
/* Node.ELEMENT_TYPE */
|
|
283
294
|
/** Find last style element if any inside target */
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
for (
|
|
287
|
-
|
|
295
|
+
var findLastStyleTag = function (target) {
|
|
296
|
+
var childNodes = target.childNodes;
|
|
297
|
+
for (var i = childNodes.length; i >= 0; i--) {
|
|
298
|
+
var child = childNodes[i];
|
|
288
299
|
if (child && child.nodeType === ELEMENT_TYPE && child.hasAttribute(SC_ATTR)) {
|
|
289
300
|
return child;
|
|
290
301
|
}
|
|
@@ -292,29 +303,29 @@ const findLastStyleTag = (target) => {
|
|
|
292
303
|
return undefined;
|
|
293
304
|
};
|
|
294
305
|
/** Create a style element inside `target` or <head> after the last */
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
306
|
+
var makeStyleTag = function (target) {
|
|
307
|
+
var head = document.head;
|
|
308
|
+
var parent = target || head;
|
|
309
|
+
var style = document.createElement('style');
|
|
310
|
+
var prevStyle = findLastStyleTag(parent);
|
|
311
|
+
var nextSibling = prevStyle !== undefined ? prevStyle.nextSibling : null;
|
|
301
312
|
style.setAttribute(SC_ATTR, SC_ATTR_ACTIVE);
|
|
302
313
|
style.setAttribute(SC_ATTR_VERSION, SC_VERSION);
|
|
303
|
-
|
|
314
|
+
var nonce = getNonce();
|
|
304
315
|
if (nonce)
|
|
305
316
|
style.setAttribute('nonce', nonce);
|
|
306
317
|
parent.insertBefore(style, nextSibling);
|
|
307
318
|
return style;
|
|
308
319
|
};
|
|
309
320
|
/** Get the CSSStyleSheet instance for a given style element */
|
|
310
|
-
|
|
321
|
+
var getSheet = function (tag) {
|
|
311
322
|
if (tag.sheet) {
|
|
312
323
|
return tag.sheet;
|
|
313
324
|
}
|
|
314
325
|
// Avoid Firefox quirk where the style element might not have a sheet property
|
|
315
|
-
|
|
316
|
-
for (
|
|
317
|
-
|
|
326
|
+
var styleSheets = document.styleSheets;
|
|
327
|
+
for (var i = 0, l = styleSheets.length; i < l; i++) {
|
|
328
|
+
var sheet = styleSheets[i];
|
|
318
329
|
if (sheet.ownerNode === tag) {
|
|
319
330
|
return sheet;
|
|
320
331
|
}
|
|
@@ -323,7 +334,8 @@ const getSheet = (tag) => {
|
|
|
323
334
|
};
|
|
324
335
|
|
|
325
336
|
/** Create a CSSStyleSheet-like tag depending on the environment */
|
|
326
|
-
|
|
337
|
+
var makeTag = function (_a) {
|
|
338
|
+
var isServer = _a.isServer, useCSSOMInjection = _a.useCSSOMInjection, target = _a.target;
|
|
327
339
|
if (isServer) {
|
|
328
340
|
return new VirtualTag(target);
|
|
329
341
|
}
|
|
@@ -334,18 +346,15 @@ const makeTag = ({ isServer, useCSSOMInjection, target }) => {
|
|
|
334
346
|
return new TextTag(target);
|
|
335
347
|
}
|
|
336
348
|
};
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
length;
|
|
341
|
-
constructor(target) {
|
|
342
|
-
const element = (this.element = makeStyleTag(target));
|
|
349
|
+
var CSSOMTag = /** @class */ (function () {
|
|
350
|
+
function CSSOMTag(target) {
|
|
351
|
+
var element = (this.element = makeStyleTag(target));
|
|
343
352
|
// Avoid Edge bug where empty style elements don't create sheets
|
|
344
353
|
element.appendChild(document.createTextNode(''));
|
|
345
354
|
this.sheet = getSheet(element);
|
|
346
355
|
this.length = 0;
|
|
347
356
|
}
|
|
348
|
-
insertRule(index, rule) {
|
|
357
|
+
CSSOMTag.prototype.insertRule = function (index, rule) {
|
|
349
358
|
try {
|
|
350
359
|
this.sheet.insertRule(rule, index);
|
|
351
360
|
this.length++;
|
|
@@ -354,13 +363,13 @@ const CSSOMTag = class CSSOMTag {
|
|
|
354
363
|
catch (_error) {
|
|
355
364
|
return false;
|
|
356
365
|
}
|
|
357
|
-
}
|
|
358
|
-
deleteRule(index) {
|
|
366
|
+
};
|
|
367
|
+
CSSOMTag.prototype.deleteRule = function (index) {
|
|
359
368
|
this.sheet.deleteRule(index);
|
|
360
369
|
this.length--;
|
|
361
|
-
}
|
|
362
|
-
getRule(index) {
|
|
363
|
-
|
|
370
|
+
};
|
|
371
|
+
CSSOMTag.prototype.getRule = function (index) {
|
|
372
|
+
var rule = this.sheet.cssRules[index];
|
|
364
373
|
// Avoid IE11 quirk where cssText is inaccessible on some invalid rules
|
|
365
374
|
if (rule !== undefined && typeof rule.cssText === 'string') {
|
|
366
375
|
return rule.cssText;
|
|
@@ -368,22 +377,20 @@ const CSSOMTag = class CSSOMTag {
|
|
|
368
377
|
else {
|
|
369
378
|
return '';
|
|
370
379
|
}
|
|
371
|
-
}
|
|
372
|
-
|
|
380
|
+
};
|
|
381
|
+
return CSSOMTag;
|
|
382
|
+
}());
|
|
373
383
|
/** A Tag that emulates the CSSStyleSheet API but uses text nodes */
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
length;
|
|
378
|
-
constructor(target) {
|
|
379
|
-
const element = (this.element = makeStyleTag(target));
|
|
384
|
+
var TextTag = /** @class */ (function () {
|
|
385
|
+
function TextTag(target) {
|
|
386
|
+
var element = (this.element = makeStyleTag(target));
|
|
380
387
|
this.nodes = element.childNodes;
|
|
381
388
|
this.length = 0;
|
|
382
389
|
}
|
|
383
|
-
insertRule(index, rule) {
|
|
390
|
+
TextTag.prototype.insertRule = function (index, rule) {
|
|
384
391
|
if (index <= this.length && index >= 0) {
|
|
385
|
-
|
|
386
|
-
|
|
392
|
+
var node = document.createTextNode(rule);
|
|
393
|
+
var refNode = this.nodes[index];
|
|
387
394
|
this.element.insertBefore(node, refNode || null);
|
|
388
395
|
this.length++;
|
|
389
396
|
return true;
|
|
@@ -391,29 +398,28 @@ const TextTag = class TextTag {
|
|
|
391
398
|
else {
|
|
392
399
|
return false;
|
|
393
400
|
}
|
|
394
|
-
}
|
|
395
|
-
deleteRule(index) {
|
|
401
|
+
};
|
|
402
|
+
TextTag.prototype.deleteRule = function (index) {
|
|
396
403
|
this.element.removeChild(this.nodes[index]);
|
|
397
404
|
this.length--;
|
|
398
|
-
}
|
|
399
|
-
getRule(index) {
|
|
405
|
+
};
|
|
406
|
+
TextTag.prototype.getRule = function (index) {
|
|
400
407
|
if (index < this.length) {
|
|
401
408
|
return this.nodes[index].textContent;
|
|
402
409
|
}
|
|
403
410
|
else {
|
|
404
411
|
return '';
|
|
405
412
|
}
|
|
406
|
-
}
|
|
407
|
-
|
|
413
|
+
};
|
|
414
|
+
return TextTag;
|
|
415
|
+
}());
|
|
408
416
|
/** A completely virtual (server-side) Tag that doesn't manipulate the DOM */
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
length;
|
|
412
|
-
constructor(_target) {
|
|
417
|
+
var VirtualTag = /** @class */ (function () {
|
|
418
|
+
function VirtualTag(_target) {
|
|
413
419
|
this.rules = [];
|
|
414
420
|
this.length = 0;
|
|
415
421
|
}
|
|
416
|
-
insertRule(index, rule) {
|
|
422
|
+
VirtualTag.prototype.insertRule = function (index, rule) {
|
|
417
423
|
if (index <= this.length) {
|
|
418
424
|
this.rules.splice(index, 0, rule);
|
|
419
425
|
this.length++;
|
|
@@ -422,42 +428,33 @@ const VirtualTag = class VirtualTag {
|
|
|
422
428
|
else {
|
|
423
429
|
return false;
|
|
424
430
|
}
|
|
425
|
-
}
|
|
426
|
-
deleteRule(index) {
|
|
431
|
+
};
|
|
432
|
+
VirtualTag.prototype.deleteRule = function (index) {
|
|
427
433
|
this.rules.splice(index, 1);
|
|
428
434
|
this.length--;
|
|
429
|
-
}
|
|
430
|
-
getRule(index) {
|
|
435
|
+
};
|
|
436
|
+
VirtualTag.prototype.getRule = function (index) {
|
|
431
437
|
if (index < this.length) {
|
|
432
438
|
return this.rules[index];
|
|
433
439
|
}
|
|
434
440
|
else {
|
|
435
441
|
return '';
|
|
436
442
|
}
|
|
437
|
-
}
|
|
438
|
-
|
|
443
|
+
};
|
|
444
|
+
return VirtualTag;
|
|
445
|
+
}());
|
|
439
446
|
|
|
440
|
-
|
|
441
|
-
|
|
447
|
+
var SHOULD_REHYDRATE = IS_BROWSER;
|
|
448
|
+
var defaultOptions = {
|
|
442
449
|
isServer: !IS_BROWSER,
|
|
443
450
|
useCSSOMInjection: !DISABLE_SPEEDY,
|
|
444
451
|
};
|
|
445
452
|
/** Contains the main stylesheet logic for stringification and caching */
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
tag;
|
|
452
|
-
/** Register a group ID to give it an index */
|
|
453
|
-
static registerId(id) {
|
|
454
|
-
return getGroupForId(id);
|
|
455
|
-
}
|
|
456
|
-
constructor(options = EMPTY_OBJECT, globalStyles = {}, names) {
|
|
457
|
-
this.options = {
|
|
458
|
-
...defaultOptions,
|
|
459
|
-
...options,
|
|
460
|
-
};
|
|
453
|
+
var StyleSheet = /** @class */ (function () {
|
|
454
|
+
function StyleSheet(options, globalStyles, names) {
|
|
455
|
+
if (options === void 0) { options = EMPTY_OBJECT; }
|
|
456
|
+
if (globalStyles === void 0) { globalStyles = {}; }
|
|
457
|
+
this.options = tslib.__assign(tslib.__assign({}, defaultOptions), options);
|
|
461
458
|
this.gs = globalStyles;
|
|
462
459
|
this.names = new Map(names);
|
|
463
460
|
this.server = !!options.isServer;
|
|
@@ -467,89 +464,96 @@ class StyleSheet {
|
|
|
467
464
|
rehydrateSheet(this);
|
|
468
465
|
}
|
|
469
466
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
467
|
+
/** Register a group ID to give it an index */
|
|
468
|
+
StyleSheet.registerId = function (id) {
|
|
469
|
+
return getGroupForId(id);
|
|
470
|
+
};
|
|
471
|
+
StyleSheet.prototype.reconstructWithOptions = function (options, withNames) {
|
|
472
|
+
if (withNames === void 0) { withNames = true; }
|
|
473
|
+
return new StyleSheet(tslib.__assign(tslib.__assign({}, this.options), options), this.gs, (withNames && this.names) || undefined);
|
|
474
|
+
};
|
|
475
|
+
StyleSheet.prototype.allocateGSInstance = function (id) {
|
|
474
476
|
return (this.gs[id] = (this.gs[id] || 0) + 1);
|
|
475
|
-
}
|
|
477
|
+
};
|
|
476
478
|
/** Lazily initialises a GroupedTag for when it's actually needed */
|
|
477
|
-
getTag() {
|
|
479
|
+
StyleSheet.prototype.getTag = function () {
|
|
478
480
|
return this.tag || (this.tag = makeGroupedTag(makeTag(this.options)));
|
|
479
|
-
}
|
|
481
|
+
};
|
|
480
482
|
/** Check whether a name is known for caching */
|
|
481
|
-
hasNameForId(id, name) {
|
|
483
|
+
StyleSheet.prototype.hasNameForId = function (id, name) {
|
|
482
484
|
return this.names.has(id) && this.names.get(id).has(name);
|
|
483
|
-
}
|
|
485
|
+
};
|
|
484
486
|
/** Mark a group's name as known for caching */
|
|
485
|
-
registerName(id, name) {
|
|
487
|
+
StyleSheet.prototype.registerName = function (id, name) {
|
|
486
488
|
getGroupForId(id);
|
|
487
489
|
if (!this.names.has(id)) {
|
|
488
|
-
|
|
490
|
+
var groupNames = new Set();
|
|
489
491
|
groupNames.add(name);
|
|
490
492
|
this.names.set(id, groupNames);
|
|
491
493
|
}
|
|
492
494
|
else {
|
|
493
495
|
this.names.get(id).add(name);
|
|
494
496
|
}
|
|
495
|
-
}
|
|
497
|
+
};
|
|
496
498
|
/** Insert new rules which also marks the name as known */
|
|
497
|
-
insertRules(id, name, rules) {
|
|
499
|
+
StyleSheet.prototype.insertRules = function (id, name, rules) {
|
|
498
500
|
this.registerName(id, name);
|
|
499
501
|
this.getTag().insertRules(getGroupForId(id), rules);
|
|
500
|
-
}
|
|
502
|
+
};
|
|
501
503
|
/** Clears all cached names for a given group ID */
|
|
502
|
-
clearNames(id) {
|
|
504
|
+
StyleSheet.prototype.clearNames = function (id) {
|
|
503
505
|
if (this.names.has(id)) {
|
|
504
506
|
this.names.get(id).clear();
|
|
505
507
|
}
|
|
506
|
-
}
|
|
508
|
+
};
|
|
507
509
|
/** Clears all rules for a given group ID */
|
|
508
|
-
clearRules(id) {
|
|
510
|
+
StyleSheet.prototype.clearRules = function (id) {
|
|
509
511
|
this.getTag().clearGroup(getGroupForId(id));
|
|
510
512
|
this.clearNames(id);
|
|
511
|
-
}
|
|
513
|
+
};
|
|
512
514
|
/** Clears the entire tag which deletes all rules but not its names */
|
|
513
|
-
clearTag() {
|
|
515
|
+
StyleSheet.prototype.clearTag = function () {
|
|
514
516
|
// NOTE: This does not clear the names, since it's only used during SSR
|
|
515
517
|
// so that we can continuously output only new rules
|
|
516
518
|
this.tag = undefined;
|
|
517
|
-
}
|
|
519
|
+
};
|
|
518
520
|
/** Outputs the current sheet as a CSS string with markers for SSR */
|
|
519
|
-
toString() {
|
|
521
|
+
StyleSheet.prototype.toString = function () {
|
|
520
522
|
return outputSheet(this);
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
+
};
|
|
524
|
+
return StyleSheet;
|
|
525
|
+
}());
|
|
523
526
|
|
|
524
|
-
|
|
527
|
+
var SEED = 5381;
|
|
525
528
|
// When we have separate strings it's useful to run a progressive
|
|
526
529
|
// version of djb2 where we pretend that we're still looping over
|
|
527
530
|
// the same string
|
|
528
|
-
|
|
529
|
-
|
|
531
|
+
var phash = function (h, x) {
|
|
532
|
+
var i = x.length;
|
|
530
533
|
while (i) {
|
|
531
534
|
h = (h * 33) ^ x.charCodeAt(--i);
|
|
532
535
|
}
|
|
533
536
|
return h;
|
|
534
537
|
};
|
|
535
538
|
// This is a djb2 hashing function
|
|
536
|
-
|
|
539
|
+
var hash = function (x) {
|
|
537
540
|
return phash(SEED, x);
|
|
538
541
|
};
|
|
539
542
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
function createStylisInstance(
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
543
|
+
var COMMENT_REGEX = /^\s*\/\/.*$/gm;
|
|
544
|
+
var COMPLEX_SELECTOR_PREFIX = [':', '[', '.', '#'];
|
|
545
|
+
function createStylisInstance(_a) {
|
|
546
|
+
var _b = _a === void 0 ? EMPTY_OBJECT : _a, _c = _b.options, options = _c === void 0 ? EMPTY_OBJECT : _c, _d = _b.plugins, plugins = _d === void 0 ? EMPTY_ARRAY : _d;
|
|
547
|
+
var _componentId;
|
|
548
|
+
var _selector;
|
|
549
|
+
var _selectorRegexp;
|
|
550
|
+
var _consecutiveSelfRefRegExp;
|
|
551
|
+
var selfReferenceReplacer = function (match, offset, string) {
|
|
548
552
|
if (
|
|
549
553
|
// do not replace the first occurrence if it is complex (has a modifier)
|
|
550
554
|
(offset === 0 ? !COMPLEX_SELECTOR_PREFIX.includes(string[_selector.length]) : true) && // no consecutive self refs (.b.b); that is a precedence boost and treated differently
|
|
551
555
|
!string.match(_consecutiveSelfRefRegExp)) {
|
|
552
|
-
return
|
|
556
|
+
return ".".concat(_componentId);
|
|
553
557
|
}
|
|
554
558
|
return match;
|
|
555
559
|
};
|
|
@@ -565,31 +569,34 @@ function createStylisInstance({ options = EMPTY_OBJECT, plugins = EMPTY_ARRAY, }
|
|
|
565
569
|
*
|
|
566
570
|
* https://github.com/thysultan/stylis.js/tree/v4.0.2#abstract-syntax-structure
|
|
567
571
|
*/
|
|
568
|
-
|
|
572
|
+
var selfReferenceReplacementPlugin = function (element) {
|
|
569
573
|
if (element.type === stylis.RULESET && element.value.includes('&')) {
|
|
570
|
-
|
|
574
|
+
var props = element.props;
|
|
571
575
|
props[0] = props[0].replace(_selectorRegexp, selfReferenceReplacer);
|
|
572
576
|
}
|
|
573
577
|
};
|
|
574
|
-
|
|
575
|
-
|
|
578
|
+
var stringifyRules = function (css, selector, prefix, componentId) {
|
|
579
|
+
if (selector === void 0) { selector = ''; }
|
|
580
|
+
if (prefix === void 0) { prefix = ''; }
|
|
581
|
+
if (componentId === void 0) { componentId = '&'; }
|
|
582
|
+
var flatCSS = css.replace(COMMENT_REGEX, '');
|
|
576
583
|
// stylis has no concept of state to be passed to plugins
|
|
577
584
|
// but since JS is single-threaded, we can rely on that to ensure
|
|
578
585
|
// these properties stay in sync with the current stylis run
|
|
579
586
|
_componentId = componentId;
|
|
580
587
|
_selector = selector;
|
|
581
|
-
_selectorRegexp = new RegExp(
|
|
582
|
-
_consecutiveSelfRefRegExp = new RegExp(
|
|
583
|
-
|
|
588
|
+
_selectorRegexp = new RegExp("\\".concat(_selector, "\\b"), 'g');
|
|
589
|
+
_consecutiveSelfRefRegExp = new RegExp("(\\".concat(_selector, "\\b){2,}"));
|
|
590
|
+
var middlewares = plugins.slice();
|
|
584
591
|
if (options.prefix || options.prefix === undefined) {
|
|
585
592
|
middlewares.unshift(stylis.prefixer);
|
|
586
593
|
}
|
|
587
594
|
middlewares.push(selfReferenceReplacementPlugin, stylis.stringify);
|
|
588
|
-
return stylis.serialize(stylis.compile(prefix || selector ?
|
|
595
|
+
return stylis.serialize(stylis.compile(prefix || selector ? "".concat(prefix, " ").concat(selector, " { ").concat(flatCSS, " }") : flatCSS), stylis.middleware(middlewares));
|
|
589
596
|
};
|
|
590
597
|
stringifyRules.hash = plugins.length
|
|
591
598
|
? plugins
|
|
592
|
-
.reduce((acc, plugin)
|
|
599
|
+
.reduce(function (acc, plugin) {
|
|
593
600
|
if (!plugin.name) {
|
|
594
601
|
throwStyledComponentsError(15);
|
|
595
602
|
}
|
|
@@ -600,35 +607,36 @@ function createStylisInstance({ options = EMPTY_OBJECT, plugins = EMPTY_ARRAY, }
|
|
|
600
607
|
return stringifyRules;
|
|
601
608
|
}
|
|
602
609
|
|
|
603
|
-
|
|
610
|
+
var StyleSheetContext = React__default["default"].createContext(undefined);
|
|
604
611
|
StyleSheetContext.Consumer;
|
|
605
|
-
|
|
612
|
+
var StylisContext = React__default["default"].createContext(undefined);
|
|
606
613
|
StylisContext.Consumer;
|
|
607
614
|
new StyleSheet();
|
|
608
|
-
|
|
615
|
+
var mainStylis = createStylisInstance();
|
|
609
616
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
617
|
+
var Keyframes = /** @class */ (function () {
|
|
618
|
+
function Keyframes(name, rules) {
|
|
619
|
+
var _this = this;
|
|
620
|
+
this.inject = function (styleSheet, stylisInstance) {
|
|
621
|
+
if (stylisInstance === void 0) { stylisInstance = mainStylis; }
|
|
622
|
+
var resolvedName = _this.name + stylisInstance.hash;
|
|
623
|
+
if (!styleSheet.hasNameForId(_this.id, resolvedName)) {
|
|
624
|
+
styleSheet.insertRules(_this.id, resolvedName, stylisInstance(_this.rules, resolvedName, '@keyframes'));
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
this.toString = function () {
|
|
628
|
+
throw throwStyledComponentsError(12, String(_this.name));
|
|
629
|
+
};
|
|
615
630
|
this.name = name;
|
|
616
|
-
this.id =
|
|
631
|
+
this.id = "sc-keyframes-".concat(name);
|
|
617
632
|
this.rules = rules;
|
|
618
633
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
if (!styleSheet.hasNameForId(this.id, resolvedName)) {
|
|
622
|
-
styleSheet.insertRules(this.id, resolvedName, stylisInstance(this.rules, resolvedName, '@keyframes'));
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
toString = () => {
|
|
626
|
-
throw throwStyledComponentsError(12, String(this.name));
|
|
627
|
-
};
|
|
628
|
-
getName(stylisInstance = mainStylis) {
|
|
634
|
+
Keyframes.prototype.getName = function (stylisInstance) {
|
|
635
|
+
if (stylisInstance === void 0) { stylisInstance = mainStylis; }
|
|
629
636
|
return this.name + stylisInstance.hash;
|
|
630
|
-
}
|
|
631
|
-
|
|
637
|
+
};
|
|
638
|
+
return Keyframes;
|
|
639
|
+
}());
|
|
632
640
|
|
|
633
641
|
// Taken from https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/shared/dangerousStyleValue.js
|
|
634
642
|
function addUnitIfNeeded(name, value) {
|
|
@@ -637,7 +645,7 @@ function addUnitIfNeeded(name, value) {
|
|
|
637
645
|
return '';
|
|
638
646
|
}
|
|
639
647
|
if (typeof value === 'number' && value !== 0 && !(name in unitless__default["default"])) {
|
|
640
|
-
return
|
|
648
|
+
return "".concat(value, "px"); // Presumes implicit 'px' suffix for unitless numbers
|
|
641
649
|
}
|
|
642
650
|
return String(value).trim();
|
|
643
651
|
}
|
|
@@ -653,10 +661,10 @@ function getComponentName(target) {
|
|
|
653
661
|
* inlined version of
|
|
654
662
|
* https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/hyphenateStyleName.js
|
|
655
663
|
*/
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
664
|
+
var uppercaseCheck = /([A-Z])/;
|
|
665
|
+
var uppercasePattern = /([A-Z])/g;
|
|
666
|
+
var msPattern = /^ms-/;
|
|
667
|
+
var prefixAndLowerCase = function (char) { return "-".concat(char.toLowerCase()); };
|
|
660
668
|
/**
|
|
661
669
|
* Hyphenates a camelcased CSS property name, for example:
|
|
662
670
|
*
|
|
@@ -702,33 +710,35 @@ function isStyledComponent(target) {
|
|
|
702
710
|
/**
|
|
703
711
|
* It's falsish not falsy because 0 is allowed.
|
|
704
712
|
*/
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
713
|
+
var isFalsish = function (chunk) {
|
|
714
|
+
return chunk === undefined || chunk === null || chunk === false || chunk === '';
|
|
715
|
+
};
|
|
716
|
+
var objToCssArray = function (obj, prevKey) {
|
|
717
|
+
var rules = [];
|
|
718
|
+
for (var key in obj) {
|
|
709
719
|
if (!obj.hasOwnProperty(key) || isFalsish(obj[key]))
|
|
710
720
|
continue;
|
|
711
721
|
if ((Array.isArray(obj[key]) && obj[key].isCss) || isFunction(obj[key])) {
|
|
712
|
-
rules.push(
|
|
722
|
+
rules.push("".concat(hyphenateStyleName(key), ":"), obj[key], ';');
|
|
713
723
|
}
|
|
714
724
|
else if (isPlainObject(obj[key])) {
|
|
715
|
-
rules.push(
|
|
725
|
+
rules.push.apply(rules, objToCssArray(obj[key], key));
|
|
716
726
|
}
|
|
717
727
|
else {
|
|
718
|
-
rules.push(
|
|
728
|
+
rules.push("".concat(hyphenateStyleName(key), ": ").concat(addUnitIfNeeded(key, obj[key]), ";"));
|
|
719
729
|
}
|
|
720
730
|
}
|
|
721
|
-
return prevKey ? [
|
|
731
|
+
return prevKey ? tslib.__spreadArray(tslib.__spreadArray(["".concat(prevKey, " {")], rules, true), ['}'], false) : rules;
|
|
722
732
|
};
|
|
723
733
|
function flatten(chunk, executionContext, styleSheet, stylisInstance) {
|
|
724
734
|
if (Array.isArray(chunk)) {
|
|
725
|
-
|
|
726
|
-
for (
|
|
735
|
+
var ruleSet = [];
|
|
736
|
+
for (var i = 0, len = chunk.length, result = void 0; i < len; i += 1) {
|
|
727
737
|
result = flatten(chunk[i], executionContext, styleSheet, stylisInstance);
|
|
728
738
|
if (result === '')
|
|
729
739
|
continue;
|
|
730
740
|
else if (Array.isArray(result))
|
|
731
|
-
ruleSet.push(
|
|
741
|
+
ruleSet.push.apply(ruleSet, result);
|
|
732
742
|
else
|
|
733
743
|
ruleSet.push(result);
|
|
734
744
|
}
|
|
@@ -739,22 +749,22 @@ function flatten(chunk, executionContext, styleSheet, stylisInstance) {
|
|
|
739
749
|
}
|
|
740
750
|
/* Handle other components */
|
|
741
751
|
if (isStyledComponent(chunk)) {
|
|
742
|
-
return
|
|
752
|
+
return ".".concat(chunk.styledComponentId);
|
|
743
753
|
}
|
|
744
754
|
/* Either execute or defer the function */
|
|
745
755
|
if (isFunction(chunk)) {
|
|
746
756
|
if (isStatelessFunction(chunk) && executionContext) {
|
|
747
|
-
|
|
748
|
-
|
|
757
|
+
var chunkFn = chunk;
|
|
758
|
+
var result = chunkFn(executionContext);
|
|
749
759
|
if (process.env.NODE_ENV !== 'production' &&
|
|
750
760
|
typeof result === 'object' &&
|
|
751
761
|
!Array.isArray(result) &&
|
|
752
762
|
!(result instanceof Keyframes) &&
|
|
753
763
|
!isPlainObject(result)) {
|
|
754
764
|
// eslint-disable-next-line no-console
|
|
755
|
-
console.error(
|
|
765
|
+
console.error("".concat(getComponentName(
|
|
756
766
|
// @ts-expect-error handling unexpected input
|
|
757
|
-
chunkFn)
|
|
767
|
+
chunkFn), " is not a styled component and cannot be referred to via component selector. See https://www.styled-components.com/docs/advanced#referring-to-other-components for more details."));
|
|
758
768
|
}
|
|
759
769
|
return flatten(result, executionContext, styleSheet, stylisInstance);
|
|
760
770
|
}
|
|
@@ -774,8 +784,8 @@ function flatten(chunk, executionContext, styleSheet, stylisInstance) {
|
|
|
774
784
|
}
|
|
775
785
|
|
|
776
786
|
function interleave(strings, interpolations) {
|
|
777
|
-
|
|
778
|
-
for (
|
|
787
|
+
var result = [strings[0]];
|
|
788
|
+
for (var i = 0, len = interpolations.length; i < len; i += 1) {
|
|
779
789
|
result.push(interpolations[i], strings[i + 1]);
|
|
780
790
|
}
|
|
781
791
|
return result;
|
|
@@ -785,22 +795,25 @@ function interleave(strings, interpolations) {
|
|
|
785
795
|
* Used when flattening object styles to determine if we should
|
|
786
796
|
* expand an array of styles.
|
|
787
797
|
*/
|
|
788
|
-
|
|
798
|
+
var addTag = function (arg) {
|
|
789
799
|
if (Array.isArray(arg)) {
|
|
790
800
|
// eslint-disable-next-line no-param-reassign
|
|
791
801
|
arg.isCss = true;
|
|
792
802
|
}
|
|
793
803
|
return arg;
|
|
794
804
|
};
|
|
795
|
-
function css(styles
|
|
805
|
+
function css(styles) {
|
|
806
|
+
var interpolations = [];
|
|
807
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
808
|
+
interpolations[_i - 1] = arguments[_i];
|
|
809
|
+
}
|
|
796
810
|
if (isFunction(styles) || isPlainObject(styles)) {
|
|
797
|
-
|
|
798
|
-
return addTag(flatten(interleave(EMPTY_ARRAY, [
|
|
799
|
-
styleFunctionOrObject
|
|
800
|
-
|
|
801
|
-
])));
|
|
811
|
+
var styleFunctionOrObject = styles;
|
|
812
|
+
return addTag(flatten(interleave(EMPTY_ARRAY, tslib.__spreadArray([
|
|
813
|
+
styleFunctionOrObject
|
|
814
|
+
], interpolations, true))));
|
|
802
815
|
}
|
|
803
|
-
|
|
816
|
+
var styleStringArray = styles;
|
|
804
817
|
if (interpolations.length === 0 &&
|
|
805
818
|
styleStringArray.length === 1 &&
|
|
806
819
|
typeof styleStringArray[0] === 'string') {
|
|
@@ -809,7 +822,8 @@ function css(styles, ...interpolations) {
|
|
|
809
822
|
return addTag(flatten(interleave(styleStringArray, interpolations)));
|
|
810
823
|
}
|
|
811
824
|
|
|
812
|
-
function constructWithOptions(componentConstructor, tag, options
|
|
825
|
+
function constructWithOptions(componentConstructor, tag, options) {
|
|
826
|
+
if (options === void 0) { options = EMPTY_OBJECT; }
|
|
813
827
|
// We trust that the tag is a valid component as long as it isn't falsish
|
|
814
828
|
// Typically the tag here is a string or function (i.e. class or pure function component)
|
|
815
829
|
// However a component may also be an object if it uses another utility, e.g. React.memo
|
|
@@ -818,30 +832,34 @@ function constructWithOptions(componentConstructor, tag, options = EMPTY_OBJECT)
|
|
|
818
832
|
throw throwStyledComponentsError(1, tag);
|
|
819
833
|
}
|
|
820
834
|
/* This is callable directly as a template function */
|
|
821
|
-
|
|
835
|
+
var templateFunction = function (initialStyles) {
|
|
836
|
+
var interpolations = [];
|
|
837
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
838
|
+
interpolations[_i - 1] = arguments[_i];
|
|
839
|
+
}
|
|
840
|
+
return componentConstructor(tag, options, css.apply(void 0, tslib.__spreadArray([initialStyles], interpolations, false)));
|
|
841
|
+
};
|
|
822
842
|
/* Modify/inject new props at runtime */
|
|
823
|
-
templateFunction.attrs = (attrs)
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
});
|
|
843
|
+
templateFunction.attrs = function (attrs) {
|
|
844
|
+
return constructWithOptions(componentConstructor, tag, tslib.__assign(tslib.__assign({}, options), { attrs: Array.prototype.concat(options.attrs, attrs).filter(Boolean) }));
|
|
845
|
+
};
|
|
827
846
|
/**
|
|
828
847
|
* If config methods are called, wrap up a new template function and merge options */
|
|
829
|
-
templateFunction.withConfig = (config)
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
});
|
|
848
|
+
templateFunction.withConfig = function (config) {
|
|
849
|
+
return constructWithOptions(componentConstructor, tag, tslib.__assign(tslib.__assign({}, options), config));
|
|
850
|
+
};
|
|
833
851
|
return templateFunction;
|
|
834
852
|
}
|
|
835
853
|
|
|
836
|
-
|
|
837
|
-
|
|
854
|
+
var ThemeContext = React__default["default"].createContext(undefined);
|
|
855
|
+
var ThemeConsumer = ThemeContext.Consumer;
|
|
838
856
|
function mergeTheme(theme, outerTheme) {
|
|
839
857
|
if (!theme) {
|
|
840
858
|
throw throwStyledComponentsError(14);
|
|
841
859
|
}
|
|
842
860
|
if (isFunction(theme)) {
|
|
843
|
-
|
|
844
|
-
|
|
861
|
+
var themeFn = theme;
|
|
862
|
+
var mergedTheme = themeFn(outerTheme);
|
|
845
863
|
if (process.env.NODE_ENV !== 'production' &&
|
|
846
864
|
(mergedTheme === null || Array.isArray(mergedTheme) || typeof mergedTheme !== 'object')) {
|
|
847
865
|
throw throwStyledComponentsError(7);
|
|
@@ -851,32 +869,34 @@ function mergeTheme(theme, outerTheme) {
|
|
|
851
869
|
if (Array.isArray(theme) || typeof theme !== 'object') {
|
|
852
870
|
throw throwStyledComponentsError(8);
|
|
853
871
|
}
|
|
854
|
-
return outerTheme ? {
|
|
872
|
+
return outerTheme ? tslib.__assign(tslib.__assign({}, outerTheme), theme) : theme;
|
|
855
873
|
}
|
|
856
874
|
/**
|
|
857
875
|
* Provide a theme to an entire react component tree via context
|
|
858
876
|
*/
|
|
859
877
|
function ThemeProvider(props) {
|
|
860
|
-
|
|
861
|
-
|
|
878
|
+
var outerTheme = React.useContext(ThemeContext);
|
|
879
|
+
var themeContext = React.useMemo(function () { return mergeTheme(props.theme, outerTheme); }, [props.theme, outerTheme]);
|
|
862
880
|
if (!props.children) {
|
|
863
881
|
return null;
|
|
864
882
|
}
|
|
865
883
|
return React__default["default"].createElement(ThemeContext.Provider, { value: themeContext }, props.children);
|
|
866
884
|
}
|
|
867
885
|
|
|
868
|
-
function determineTheme(props, providedTheme, defaultProps
|
|
886
|
+
function determineTheme(props, providedTheme, defaultProps) {
|
|
887
|
+
if (defaultProps === void 0) { defaultProps = EMPTY_OBJECT; }
|
|
869
888
|
return (props.theme !== defaultProps.theme && props.theme) || providedTheme || defaultProps.theme;
|
|
870
889
|
}
|
|
871
890
|
|
|
872
|
-
|
|
891
|
+
var _a;
|
|
892
|
+
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
|
873
893
|
// copied from react-is
|
|
874
|
-
|
|
875
|
-
|
|
894
|
+
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
|
|
895
|
+
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
|
876
896
|
/**
|
|
877
897
|
* Adapted from hoist-non-react-statics to avoid the react-is dependency.
|
|
878
898
|
*/
|
|
879
|
-
|
|
899
|
+
var REACT_STATICS = {
|
|
880
900
|
childContextTypes: true,
|
|
881
901
|
contextType: true,
|
|
882
902
|
contextTypes: true,
|
|
@@ -889,7 +909,7 @@ const REACT_STATICS = {
|
|
|
889
909
|
propTypes: true,
|
|
890
910
|
type: true,
|
|
891
911
|
};
|
|
892
|
-
|
|
912
|
+
var KNOWN_STATICS = {
|
|
893
913
|
name: true,
|
|
894
914
|
length: true,
|
|
895
915
|
prototype: true,
|
|
@@ -898,14 +918,14 @@ const KNOWN_STATICS = {
|
|
|
898
918
|
arguments: true,
|
|
899
919
|
arity: true,
|
|
900
920
|
};
|
|
901
|
-
|
|
921
|
+
var FORWARD_REF_STATICS = {
|
|
902
922
|
$$typeof: true,
|
|
903
923
|
render: true,
|
|
904
924
|
defaultProps: true,
|
|
905
925
|
displayName: true,
|
|
906
926
|
propTypes: true,
|
|
907
927
|
};
|
|
908
|
-
|
|
928
|
+
var MEMO_STATICS = {
|
|
909
929
|
$$typeof: true,
|
|
910
930
|
compare: true,
|
|
911
931
|
defaultProps: true,
|
|
@@ -913,13 +933,13 @@ const MEMO_STATICS = {
|
|
|
913
933
|
propTypes: true,
|
|
914
934
|
type: true,
|
|
915
935
|
};
|
|
916
|
-
|
|
917
|
-
[REACT_FORWARD_REF_TYPE]
|
|
918
|
-
[REACT_MEMO_TYPE]
|
|
919
|
-
|
|
936
|
+
var TYPE_STATICS = (_a = {},
|
|
937
|
+
_a[REACT_FORWARD_REF_TYPE] = FORWARD_REF_STATICS,
|
|
938
|
+
_a[REACT_MEMO_TYPE] = MEMO_STATICS,
|
|
939
|
+
_a);
|
|
920
940
|
// adapted from react-is
|
|
921
941
|
function isMemo(object) {
|
|
922
|
-
|
|
942
|
+
var $$typeofType = 'type' in object && object.type.$$typeof;
|
|
923
943
|
return $$typeofType === REACT_MEMO_TYPE;
|
|
924
944
|
}
|
|
925
945
|
function getStatics(component) {
|
|
@@ -932,34 +952,34 @@ function getStatics(component) {
|
|
|
932
952
|
? TYPE_STATICS[component['$$typeof']]
|
|
933
953
|
: REACT_STATICS;
|
|
934
954
|
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
955
|
+
var defineProperty = Object.defineProperty;
|
|
956
|
+
var getOwnPropertyNames = Object.getOwnPropertyNames;
|
|
957
|
+
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|
958
|
+
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
959
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
960
|
+
var objectPrototype = Object.prototype;
|
|
941
961
|
function hoistNonReactStatics(targetComponent, sourceComponent, excludelist) {
|
|
942
962
|
if (typeof sourceComponent !== 'string') {
|
|
943
963
|
// don't hoist over string (html) components
|
|
944
964
|
if (objectPrototype) {
|
|
945
|
-
|
|
965
|
+
var inheritedComponent = getPrototypeOf(sourceComponent);
|
|
946
966
|
if (inheritedComponent && inheritedComponent !== objectPrototype) {
|
|
947
967
|
hoistNonReactStatics(targetComponent, inheritedComponent, excludelist);
|
|
948
968
|
}
|
|
949
969
|
}
|
|
950
|
-
|
|
970
|
+
var keys = getOwnPropertyNames(sourceComponent);
|
|
951
971
|
if (getOwnPropertySymbols) {
|
|
952
972
|
keys = keys.concat(getOwnPropertySymbols(sourceComponent));
|
|
953
973
|
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
for (
|
|
957
|
-
|
|
974
|
+
var targetStatics = getStatics(targetComponent);
|
|
975
|
+
var sourceStatics = getStatics(sourceComponent);
|
|
976
|
+
for (var i = 0; i < keys.length; ++i) {
|
|
977
|
+
var key = keys[i];
|
|
958
978
|
if (!(key in KNOWN_STATICS) &&
|
|
959
979
|
!(excludelist && excludelist[key]) &&
|
|
960
980
|
!(sourceStatics && key in sourceStatics) &&
|
|
961
981
|
!(targetStatics && key in targetStatics)) {
|
|
962
|
-
|
|
982
|
+
var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
|
|
963
983
|
try {
|
|
964
984
|
// Avoid failures from read-only properties
|
|
965
985
|
defineProperty(targetComponent, key, descriptor);
|
|
@@ -974,31 +994,31 @@ function hoistNonReactStatics(targetComponent, sourceComponent, excludelist) {
|
|
|
974
994
|
}
|
|
975
995
|
|
|
976
996
|
function withTheme(Component) {
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
997
|
+
var WithTheme = React__default["default"].forwardRef(function (props, ref) {
|
|
998
|
+
var theme = React__default["default"].useContext(ThemeContext);
|
|
999
|
+
var themeProp = determineTheme(props, theme, Component.defaultProps);
|
|
980
1000
|
if (process.env.NODE_ENV !== 'production' && themeProp === undefined) {
|
|
981
1001
|
// eslint-disable-next-line no-console
|
|
982
|
-
console.warn(
|
|
1002
|
+
console.warn("[withTheme] You are not using a ThemeProvider nor passing a theme prop or a theme in defaultProps in component class \"".concat(getComponentName(Component), "\""));
|
|
983
1003
|
}
|
|
984
|
-
return React__default["default"].createElement(Component, {
|
|
1004
|
+
return React__default["default"].createElement(Component, tslib.__assign({}, props, { theme: themeProp, ref: ref }));
|
|
985
1005
|
});
|
|
986
|
-
WithTheme.displayName =
|
|
1006
|
+
WithTheme.displayName = "WithTheme(".concat(getComponentName(Component), ")");
|
|
987
1007
|
return hoistNonReactStatics(WithTheme, Component);
|
|
988
1008
|
}
|
|
989
1009
|
|
|
990
|
-
|
|
1010
|
+
var useTheme = function () { return React.useContext(ThemeContext); };
|
|
991
1011
|
|
|
992
|
-
|
|
1012
|
+
var AD_REPLACER_R = /(a)(d)/gi;
|
|
993
1013
|
/* This is the "capacity" of our alphabet i.e. 2x26 for all letters plus their capitalised
|
|
994
1014
|
* counterparts */
|
|
995
|
-
|
|
1015
|
+
var charsLength = 52;
|
|
996
1016
|
/* start at 75 for 'a' until 'z' (25) and then start at 65 for capitalised letters */
|
|
997
|
-
|
|
1017
|
+
var getAlphabeticChar = function (code) { return String.fromCharCode(code + (code > 25 ? 39 : 97)); };
|
|
998
1018
|
/* input a number, usually a hash and convert it to base-52 */
|
|
999
1019
|
function generateAlphabeticName(code) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1020
|
+
var name = '';
|
|
1021
|
+
var x;
|
|
1002
1022
|
/* get a char and divide by alphabet-length */
|
|
1003
1023
|
for (x = Math.abs(code); x > charsLength; x = (x / charsLength) | 0) {
|
|
1004
1024
|
name = getAlphabeticChar(x % charsLength) + name;
|
|
@@ -1010,41 +1030,41 @@ function generateComponentId(str) {
|
|
|
1010
1030
|
return generateAlphabeticName(hash(str) >>> 0);
|
|
1011
1031
|
}
|
|
1012
1032
|
|
|
1013
|
-
|
|
1033
|
+
var generated = {};
|
|
1014
1034
|
/**
|
|
1015
1035
|
* InlineStyle takes arbitrary CSS and generates a flat object
|
|
1016
1036
|
*/
|
|
1017
1037
|
function makeInlineStyleClass(styleSheet) {
|
|
1018
|
-
|
|
1019
|
-
rules
|
|
1020
|
-
constructor(rules) {
|
|
1038
|
+
var InlineStyle = /** @class */ (function () {
|
|
1039
|
+
function InlineStyle(rules) {
|
|
1021
1040
|
this.rules = rules;
|
|
1022
1041
|
}
|
|
1023
|
-
generateStyleObject(executionContext) {
|
|
1042
|
+
InlineStyle.prototype.generateStyleObject = function (executionContext) {
|
|
1024
1043
|
// keyframes, functions, and component selectors are not allowed for React Native
|
|
1025
|
-
|
|
1026
|
-
|
|
1044
|
+
var flatCSS = flatten(this.rules, executionContext).join('');
|
|
1045
|
+
var hash = generateComponentId(flatCSS);
|
|
1027
1046
|
if (!generated[hash]) {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
root.each(node
|
|
1047
|
+
var root = postcss.parse(flatCSS);
|
|
1048
|
+
var declPairs_1 = [];
|
|
1049
|
+
root.each(function (node) {
|
|
1031
1050
|
if (node.type === 'decl') {
|
|
1032
|
-
|
|
1051
|
+
declPairs_1.push([node.prop, node.value]);
|
|
1033
1052
|
}
|
|
1034
1053
|
else if (process.env.NODE_ENV !== 'production' && node.type !== 'comment') {
|
|
1035
1054
|
/* eslint-disable no-console */
|
|
1036
|
-
console.warn(
|
|
1055
|
+
console.warn("Node of type ".concat(node.type, " not supported as an inline style"));
|
|
1037
1056
|
}
|
|
1038
1057
|
});
|
|
1039
|
-
|
|
1040
|
-
|
|
1058
|
+
var styleObject = transformDeclPairs__default["default"](declPairs_1);
|
|
1059
|
+
var styles = styleSheet.create({
|
|
1041
1060
|
generated: styleObject,
|
|
1042
1061
|
});
|
|
1043
1062
|
generated[hash] = styles.generated;
|
|
1044
1063
|
}
|
|
1045
1064
|
return generated[hash];
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1065
|
+
};
|
|
1066
|
+
return InlineStyle;
|
|
1067
|
+
}());
|
|
1048
1068
|
return InlineStyle;
|
|
1049
1069
|
}
|
|
1050
1070
|
|
|
@@ -1056,22 +1076,23 @@ function isTag(target) {
|
|
|
1056
1076
|
}
|
|
1057
1077
|
|
|
1058
1078
|
function generateDisplayName(target) {
|
|
1059
|
-
return isTag(target) ?
|
|
1079
|
+
return isTag(target) ? "styled.".concat(target) : "Styled(".concat(getComponentName(target), ")");
|
|
1060
1080
|
}
|
|
1061
1081
|
|
|
1062
|
-
function mixinRecursively(target, source, forceMerge
|
|
1082
|
+
function mixinRecursively(target, source, forceMerge) {
|
|
1083
|
+
if (forceMerge === void 0) { forceMerge = false; }
|
|
1063
1084
|
/* only merge into POJOs, Arrays, but for top level objects only
|
|
1064
1085
|
* allow to merge into anything by passing forceMerge = true */
|
|
1065
1086
|
if (!forceMerge && !isPlainObject(target) && !Array.isArray(target)) {
|
|
1066
1087
|
return source;
|
|
1067
1088
|
}
|
|
1068
1089
|
if (Array.isArray(source)) {
|
|
1069
|
-
for (
|
|
1090
|
+
for (var key = 0; key < source.length; key++) {
|
|
1070
1091
|
target[key] = mixinRecursively(target[key], source[key]);
|
|
1071
1092
|
}
|
|
1072
1093
|
}
|
|
1073
1094
|
else if (isPlainObject(source)) {
|
|
1074
|
-
for (
|
|
1095
|
+
for (var key in source) {
|
|
1075
1096
|
target[key] = mixinRecursively(target[key], source[key]);
|
|
1076
1097
|
}
|
|
1077
1098
|
}
|
|
@@ -1082,23 +1103,30 @@ function mixinRecursively(target, source, forceMerge = false) {
|
|
|
1082
1103
|
* If target is not a POJO or an Array, it will get source properties injected via shallow merge
|
|
1083
1104
|
* Source objects applied left to right. Mutates & returns target. Similar to lodash merge.
|
|
1084
1105
|
*/
|
|
1085
|
-
function mixinDeep(target
|
|
1086
|
-
|
|
1106
|
+
function mixinDeep(target) {
|
|
1107
|
+
if (target === void 0) { target = {}; }
|
|
1108
|
+
var sources = [];
|
|
1109
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1110
|
+
sources[_i - 1] = arguments[_i];
|
|
1111
|
+
}
|
|
1112
|
+
for (var _a = 0, sources_1 = sources; _a < sources_1.length; _a++) {
|
|
1113
|
+
var source = sources_1[_a];
|
|
1087
1114
|
mixinRecursively(target, source, true);
|
|
1088
1115
|
}
|
|
1089
1116
|
return target;
|
|
1090
1117
|
}
|
|
1091
1118
|
|
|
1092
|
-
function useResolvedAttrs(theme
|
|
1119
|
+
function useResolvedAttrs(theme, props, attrs) {
|
|
1120
|
+
if (theme === void 0) { theme = EMPTY_OBJECT; }
|
|
1093
1121
|
// NOTE: can't memoize this
|
|
1094
1122
|
// returns [context, resolvedAttrs]
|
|
1095
1123
|
// where resolvedAttrs is only the things injected by the attrs themselves
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
attrs.forEach(attrDef
|
|
1124
|
+
var context = tslib.__assign(tslib.__assign({}, props), { theme: theme });
|
|
1125
|
+
var resolvedAttrs = {};
|
|
1126
|
+
attrs.forEach(function (attrDef) {
|
|
1099
1127
|
// @ts-expect-error narrowing isn't working properly for some reason
|
|
1100
|
-
|
|
1101
|
-
|
|
1128
|
+
var resolvedAttrDef = typeof attrDef === 'function' ? attrDef(context) : attrDef;
|
|
1129
|
+
var key;
|
|
1102
1130
|
/* eslint-disable guard-for-in */
|
|
1103
1131
|
for (key in resolvedAttrDef) {
|
|
1104
1132
|
// @ts-expect-error bad types
|
|
@@ -1109,21 +1137,21 @@ function useResolvedAttrs(theme = EMPTY_OBJECT, props, attrs) {
|
|
|
1109
1137
|
return [context, resolvedAttrs];
|
|
1110
1138
|
}
|
|
1111
1139
|
// Validator defaults to true if not in HTML/DOM env
|
|
1112
|
-
|
|
1140
|
+
var validAttr = function () { return true; };
|
|
1113
1141
|
function useStyledComponentImpl(forwardedComponent, props, forwardedRef) {
|
|
1114
|
-
|
|
1142
|
+
var componentAttrs = forwardedComponent.attrs, inlineStyle = forwardedComponent.inlineStyle, defaultProps = forwardedComponent.defaultProps, shouldForwardProp = forwardedComponent.shouldForwardProp, target = forwardedComponent.target;
|
|
1115
1143
|
// NOTE: the non-hooks version only subscribes to this when !componentStyle.isStatic,
|
|
1116
1144
|
// but that'd be against the rules-of-hooks. We could be naughty and do it anyway as it
|
|
1117
1145
|
// should be an immutable value, but behave for now.
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1146
|
+
var theme = determineTheme(props, React.useContext(ThemeContext), defaultProps);
|
|
1147
|
+
var _a = useResolvedAttrs(theme || EMPTY_OBJECT, props, componentAttrs), context = _a[0], attrs = _a[1];
|
|
1148
|
+
var generatedStyles = inlineStyle.generateStyleObject(context);
|
|
1149
|
+
var refToForward = forwardedRef;
|
|
1150
|
+
var elementToBeCreated = attrs.$as || props.$as || attrs.as || props.as || target;
|
|
1151
|
+
var computedProps = attrs !== props ? tslib.__assign(tslib.__assign({}, props), attrs) : props;
|
|
1152
|
+
var propsForElement = {};
|
|
1125
1153
|
// eslint-disable-next-line guard-for-in
|
|
1126
|
-
for (
|
|
1154
|
+
for (var key in computedProps) {
|
|
1127
1155
|
if (key[0] === '$' || key === 'as')
|
|
1128
1156
|
continue;
|
|
1129
1157
|
else if (key === 'forwardedAs') {
|
|
@@ -1133,9 +1161,9 @@ function useStyledComponentImpl(forwardedComponent, props, forwardedRef) {
|
|
|
1133
1161
|
propsForElement[key] = computedProps[key];
|
|
1134
1162
|
}
|
|
1135
1163
|
}
|
|
1136
|
-
propsForElement.style = React.useMemo(()
|
|
1164
|
+
propsForElement.style = React.useMemo(function () {
|
|
1137
1165
|
if (typeof props.style === 'function') {
|
|
1138
|
-
return (state)
|
|
1166
|
+
return function (state) {
|
|
1139
1167
|
return [generatedStyles].concat(props.style(state));
|
|
1140
1168
|
};
|
|
1141
1169
|
}
|
|
@@ -1149,39 +1177,42 @@ function useStyledComponentImpl(forwardedComponent, props, forwardedRef) {
|
|
|
1149
1177
|
propsForElement.ref = refToForward;
|
|
1150
1178
|
return React.createElement(elementToBeCreated, propsForElement);
|
|
1151
1179
|
}
|
|
1152
|
-
var _StyledNativeComponent = (InlineStyle)
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1180
|
+
var _StyledNativeComponent = (function (InlineStyle) {
|
|
1181
|
+
var createStyledNativeComponent = function (target, options, rules) {
|
|
1182
|
+
var isTargetStyledComp = isStyledComponent(target);
|
|
1183
|
+
var styledComponentTarget = target;
|
|
1184
|
+
var _a = options.displayName, displayName = _a === void 0 ? generateDisplayName(target) : _a, _b = options.attrs, attrs = _b === void 0 ? EMPTY_ARRAY : _b;
|
|
1157
1185
|
// fold the underlying StyledComponent attrs up (implicit extend)
|
|
1158
|
-
|
|
1186
|
+
var finalAttrs = isTargetStyledComp && styledComponentTarget.attrs
|
|
1159
1187
|
? styledComponentTarget.attrs.concat(attrs).filter(Boolean)
|
|
1160
1188
|
: attrs;
|
|
1161
1189
|
// eslint-disable-next-line prefer-destructuring
|
|
1162
|
-
|
|
1190
|
+
var shouldForwardProp = options.shouldForwardProp;
|
|
1163
1191
|
if (isTargetStyledComp && styledComponentTarget.shouldForwardProp) {
|
|
1164
|
-
|
|
1192
|
+
var shouldForwardPropFn_1 = styledComponentTarget.shouldForwardProp;
|
|
1165
1193
|
if (options.shouldForwardProp) {
|
|
1166
|
-
|
|
1194
|
+
var passedShouldForwardPropFn_1 = options.shouldForwardProp;
|
|
1167
1195
|
// compose nested shouldForwardProp calls
|
|
1168
|
-
shouldForwardProp =
|
|
1169
|
-
|
|
1196
|
+
shouldForwardProp = function (prop, filterFn, elementToBeCreated) {
|
|
1197
|
+
return shouldForwardPropFn_1(prop, filterFn, elementToBeCreated) &&
|
|
1198
|
+
passedShouldForwardPropFn_1(prop, filterFn, elementToBeCreated);
|
|
1199
|
+
};
|
|
1170
1200
|
}
|
|
1171
1201
|
else {
|
|
1172
1202
|
// eslint-disable-next-line prefer-destructuring
|
|
1173
|
-
shouldForwardProp =
|
|
1203
|
+
shouldForwardProp = shouldForwardPropFn_1;
|
|
1174
1204
|
}
|
|
1175
1205
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1206
|
+
var forwardRef = function (props, ref) {
|
|
1207
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
1208
|
+
return useStyledComponentImpl(WrappedStyledComponent, props, ref);
|
|
1209
|
+
};
|
|
1179
1210
|
forwardRef.displayName = displayName;
|
|
1180
1211
|
/**
|
|
1181
1212
|
* forwardRef creates a new interim component, which we'll take advantage of
|
|
1182
1213
|
* instead of extending ParentComponent to create _another_ interim class
|
|
1183
1214
|
*/
|
|
1184
|
-
|
|
1215
|
+
var WrappedStyledComponent = React__default["default"].forwardRef(forwardRef);
|
|
1185
1216
|
WrappedStyledComponent.attrs = finalAttrs;
|
|
1186
1217
|
WrappedStyledComponent.inlineStyle = new InlineStyle(isTargetStyledComp ? styledComponentTarget.inlineStyle.rules.concat(rules) : rules);
|
|
1187
1218
|
WrappedStyledComponent.displayName = displayName;
|
|
@@ -1191,17 +1222,14 @@ var _StyledNativeComponent = (InlineStyle) => {
|
|
|
1191
1222
|
// fold the underlying StyledComponent target up since we folded the styles
|
|
1192
1223
|
WrappedStyledComponent.target = isTargetStyledComp ? styledComponentTarget.target : target;
|
|
1193
1224
|
WrappedStyledComponent.withComponent = function withComponent(tag) {
|
|
1194
|
-
|
|
1195
|
-
...options,
|
|
1196
|
-
attrs: finalAttrs,
|
|
1197
|
-
};
|
|
1225
|
+
var newOptions = tslib.__assign(tslib.__assign({}, options), { attrs: finalAttrs });
|
|
1198
1226
|
return createStyledNativeComponent(tag, newOptions, rules);
|
|
1199
1227
|
};
|
|
1200
1228
|
Object.defineProperty(WrappedStyledComponent, 'defaultProps', {
|
|
1201
|
-
get() {
|
|
1229
|
+
get: function () {
|
|
1202
1230
|
return this._foldedDefaultProps;
|
|
1203
1231
|
},
|
|
1204
|
-
set(obj) {
|
|
1232
|
+
set: function (obj) {
|
|
1205
1233
|
this._foldedDefaultProps = isTargetStyledComp
|
|
1206
1234
|
? mixinDeep({}, styledComponentTarget.defaultProps, obj)
|
|
1207
1235
|
: obj;
|
|
@@ -1219,16 +1247,18 @@ var _StyledNativeComponent = (InlineStyle) => {
|
|
|
1219
1247
|
return WrappedStyledComponent;
|
|
1220
1248
|
};
|
|
1221
1249
|
return createStyledNativeComponent;
|
|
1222
|
-
};
|
|
1250
|
+
});
|
|
1223
1251
|
|
|
1224
1252
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1253
|
+
var reactNative = require('react-native');
|
|
1254
|
+
var InlineStyle = makeInlineStyleClass(reactNative.StyleSheet);
|
|
1255
|
+
var StyledNativeComponent = _StyledNativeComponent(InlineStyle);
|
|
1256
|
+
var baseStyled = function (tag) {
|
|
1257
|
+
return constructWithOptions(StyledNativeComponent, tag);
|
|
1258
|
+
};
|
|
1229
1259
|
/* React native lazy-requires each of these modules for some reason, so let's
|
|
1230
1260
|
* assume it's for a good reason and not eagerly load them all */
|
|
1231
|
-
|
|
1261
|
+
var aliases = [
|
|
1232
1262
|
'ActivityIndicator',
|
|
1233
1263
|
'Button',
|
|
1234
1264
|
'DatePickerIOS',
|
|
@@ -1254,19 +1284,21 @@ const aliases = [
|
|
|
1254
1284
|
'View',
|
|
1255
1285
|
'VirtualizedList',
|
|
1256
1286
|
];
|
|
1257
|
-
|
|
1287
|
+
var styled = baseStyled;
|
|
1258
1288
|
/* Define a getter for each alias which simply gets the reactNative component
|
|
1259
1289
|
* and passes it to styled */
|
|
1260
|
-
aliases.forEach(
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
}
|
|
1290
|
+
aliases.forEach(function (alias) {
|
|
1291
|
+
return Object.defineProperty(styled, alias, {
|
|
1292
|
+
enumerable: true,
|
|
1293
|
+
configurable: false,
|
|
1294
|
+
get: function () {
|
|
1295
|
+
if (alias in reactNative && reactNative[alias]) {
|
|
1296
|
+
return styled(reactNative[alias]);
|
|
1297
|
+
}
|
|
1298
|
+
throw new Error("".concat(alias, " is not available in the currently-installed version of react-native"));
|
|
1299
|
+
},
|
|
1300
|
+
});
|
|
1301
|
+
});
|
|
1270
1302
|
|
|
1271
1303
|
exports.ThemeConsumer = ThemeConsumer;
|
|
1272
1304
|
exports.ThemeContext = ThemeContext;
|