styled-components 6.4.0-prerelease.3 → 6.4.0-prerelease.5
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 +221 -47
- package/dist/constructors/createTheme.d.ts +1 -1
- package/dist/styled-components.browser.cjs.js +5 -1
- package/dist/styled-components.browser.cjs.js.map +1 -1
- package/dist/styled-components.browser.esm.js +5 -1
- package/dist/styled-components.browser.esm.js.map +1 -1
- package/dist/styled-components.cjs.js +5 -1
- package/dist/styled-components.cjs.js.map +1 -1
- package/dist/styled-components.esm.js +5 -1
- package/dist/styled-components.esm.js.map +1 -1
- package/dist/styled-components.js +647 -935
- package/dist/styled-components.js.map +1 -1
- package/dist/styled-components.min.js +5 -1
- package/dist/styled-components.min.js.map +1 -1
- package/dist/utils/hoist.d.ts +0 -4
- package/native/dist/constructors/createTheme.d.ts +1 -1
- package/native/dist/dist/constructors/createTheme.d.ts +1 -1
- package/native/dist/dist/utils/hoist.d.ts +0 -4
- package/native/dist/styled-components.native.cjs.js +1 -1
- package/native/dist/styled-components.native.cjs.js.map +1 -1
- package/native/dist/styled-components.native.esm.js +1 -1
- package/native/dist/styled-components.native.esm.js.map +1 -1
- package/native/dist/utils/hoist.d.ts +0 -4
- package/package.json +4 -5
|
@@ -4,85 +4,36 @@
|
|
|
4
4
|
(global = global || self, factory(global.styled = {}, global.React));
|
|
5
5
|
})(this, (function (exports, React) { 'use strict';
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _a$1, _b;
|
|
8
|
+
const SC_ATTR = (typeof process !== 'undefined' &&
|
|
8
9
|
typeof process.env !== 'undefined' &&
|
|
9
10
|
(process.env.REACT_APP_SC_ATTR || process.env.SC_ATTR)) ||
|
|
10
11
|
'data-styled';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const SC_ATTR_ACTIVE = 'active';
|
|
13
|
+
const SC_ATTR_VERSION = 'data-styled-version';
|
|
14
|
+
const SC_VERSION = "6.4.0-prerelease.5";
|
|
15
|
+
const SPLITTER = '/*!sc*/\n';
|
|
16
|
+
const IS_BROWSER = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
17
|
+
function readSpeedyFlag(name) {
|
|
18
|
+
if (typeof process !== 'undefined' && typeof process.env !== 'undefined') {
|
|
19
|
+
const val = process.env[name];
|
|
20
|
+
if (val !== undefined && val !== '') {
|
|
21
|
+
return val !== 'false';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const DISABLE_SPEEDY = Boolean(typeof SC_DISABLE_SPEEDY === 'boolean'
|
|
17
27
|
? SC_DISABLE_SPEEDY
|
|
18
|
-
: typeof process !== 'undefined' &&
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
? process.env.REACT_APP_SC_DISABLE_SPEEDY === 'false'
|
|
23
|
-
? false
|
|
24
|
-
: process.env.REACT_APP_SC_DISABLE_SPEEDY
|
|
25
|
-
: typeof process !== 'undefined' &&
|
|
26
|
-
typeof process.env !== 'undefined' &&
|
|
27
|
-
typeof process.env.SC_DISABLE_SPEEDY !== 'undefined' &&
|
|
28
|
-
process.env.SC_DISABLE_SPEEDY !== ''
|
|
29
|
-
? process.env.SC_DISABLE_SPEEDY === 'false'
|
|
30
|
-
? false
|
|
31
|
-
: process.env.SC_DISABLE_SPEEDY
|
|
32
|
-
: "development" !== 'production');
|
|
33
|
-
var KEYFRAMES_ID_PREFIX = 'sc-keyframes-';
|
|
28
|
+
: ((_b = (_a$1 = readSpeedyFlag('REACT_APP_SC_DISABLE_SPEEDY')) !== null && _a$1 !== void 0 ? _a$1 : readSpeedyFlag('SC_DISABLE_SPEEDY')) !== null && _b !== void 0 ? _b : (typeof process !== 'undefined' && typeof process.env !== 'undefined'
|
|
29
|
+
? "development" !== 'production'
|
|
30
|
+
: true)));
|
|
31
|
+
const KEYFRAMES_ID_PREFIX = 'sc-keyframes-';
|
|
34
32
|
// Shared empty execution context when generating static styles
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
/******************************************************************************
|
|
38
|
-
Copyright (c) Microsoft Corporation.
|
|
39
|
-
|
|
40
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
41
|
-
purpose with or without fee is hereby granted.
|
|
42
|
-
|
|
43
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
44
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
45
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
46
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
47
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
48
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
49
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
50
|
-
***************************************************************************** */
|
|
51
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var __assign = function() {
|
|
55
|
-
__assign = Object.assign || function __assign(t) {
|
|
56
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
57
|
-
s = arguments[i];
|
|
58
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
59
|
-
}
|
|
60
|
-
return t;
|
|
61
|
-
};
|
|
62
|
-
return __assign.apply(this, arguments);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
function __spreadArray(to, from, pack) {
|
|
66
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
-
if (ar || !(i in from)) {
|
|
68
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
-
ar[i] = from[i];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function __makeTemplateObject(cooked, raw) {
|
|
76
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
77
|
-
return cooked;
|
|
78
|
-
}
|
|
79
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
80
|
-
var e = new Error(message);
|
|
81
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
82
|
-
};
|
|
33
|
+
const STATIC_EXECUTION_CONTEXT = {};
|
|
83
34
|
|
|
84
|
-
|
|
85
|
-
|
|
35
|
+
const EMPTY_ARRAY = Object.freeze([]);
|
|
36
|
+
const EMPTY_OBJECT = Object.freeze({});
|
|
86
37
|
|
|
87
38
|
/**
|
|
88
39
|
* If the Object prototype is frozen, the "toString" property is non-writable. This means that any objects which inherit this property
|
|
@@ -125,21 +76,17 @@
|
|
|
125
76
|
'18': 'ThemeProvider: Please make sure your useTheme hook is within a `<ThemeProvider>`',
|
|
126
77
|
};
|
|
127
78
|
|
|
128
|
-
|
|
79
|
+
const ERRORS = errorMap ;
|
|
129
80
|
/**
|
|
130
81
|
* super basic version of sprintf
|
|
131
82
|
*/
|
|
132
|
-
function format() {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
var a = args[0];
|
|
138
|
-
var b = [];
|
|
139
|
-
for (var c = 1, len = args.length; c < len; c += 1) {
|
|
83
|
+
function format(...args) {
|
|
84
|
+
let a = args[0];
|
|
85
|
+
const b = [];
|
|
86
|
+
for (let c = 1, len = args.length; c < len; c += 1) {
|
|
140
87
|
b.push(args[c]);
|
|
141
88
|
}
|
|
142
|
-
b.forEach(
|
|
89
|
+
b.forEach(d => {
|
|
143
90
|
a = a.replace(/%[a-z]/, d);
|
|
144
91
|
});
|
|
145
92
|
return a;
|
|
@@ -148,68 +95,64 @@
|
|
|
148
95
|
* Create an error file out of errors.md for development and a simple web link to the full errors
|
|
149
96
|
* in production mode.
|
|
150
97
|
*/
|
|
151
|
-
function throwStyledComponentsError(code) {
|
|
152
|
-
var interpolations = [];
|
|
153
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
154
|
-
interpolations[_i - 1] = arguments[_i];
|
|
155
|
-
}
|
|
98
|
+
function throwStyledComponentsError(code, ...interpolations) {
|
|
156
99
|
{
|
|
157
|
-
return new Error(format
|
|
100
|
+
return new Error(format(ERRORS[code], ...interpolations).trim());
|
|
158
101
|
}
|
|
159
102
|
}
|
|
160
103
|
|
|
161
104
|
/** Create a GroupedTag with an underlying Tag implementation */
|
|
162
|
-
|
|
105
|
+
const makeGroupedTag = (tag) => {
|
|
163
106
|
return new DefaultGroupedTag(tag);
|
|
164
107
|
};
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
108
|
+
const BASE_SIZE = 1 << 9;
|
|
109
|
+
const DefaultGroupedTag = class DefaultGroupedTag {
|
|
110
|
+
constructor(tag) {
|
|
168
111
|
this.groupSizes = new Uint32Array(BASE_SIZE);
|
|
169
112
|
this.length = BASE_SIZE;
|
|
170
113
|
this.tag = tag;
|
|
171
114
|
this._cGroup = 0;
|
|
172
115
|
this._cIndex = 0;
|
|
173
116
|
}
|
|
174
|
-
|
|
117
|
+
indexOfGroup(group) {
|
|
175
118
|
if (group === this._cGroup)
|
|
176
119
|
return this._cIndex;
|
|
177
|
-
|
|
120
|
+
let index = this._cIndex;
|
|
178
121
|
if (group > this._cGroup) {
|
|
179
|
-
for (
|
|
122
|
+
for (let i = this._cGroup; i < group; i++) {
|
|
180
123
|
index += this.groupSizes[i];
|
|
181
124
|
}
|
|
182
125
|
}
|
|
183
126
|
else {
|
|
184
|
-
for (
|
|
127
|
+
for (let i = this._cGroup - 1; i >= group; i--) {
|
|
185
128
|
index -= this.groupSizes[i];
|
|
186
129
|
}
|
|
187
130
|
}
|
|
188
131
|
this._cGroup = group;
|
|
189
132
|
this._cIndex = index;
|
|
190
133
|
return index;
|
|
191
|
-
}
|
|
192
|
-
|
|
134
|
+
}
|
|
135
|
+
insertRules(group, rules) {
|
|
193
136
|
if (group >= this.groupSizes.length) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
137
|
+
const oldBuffer = this.groupSizes;
|
|
138
|
+
const oldSize = oldBuffer.length;
|
|
139
|
+
let newSize = oldSize;
|
|
197
140
|
while (group >= newSize) {
|
|
198
141
|
newSize <<= 1;
|
|
199
142
|
if (newSize < 0) {
|
|
200
|
-
throw throwStyledComponentsError(16,
|
|
143
|
+
throw throwStyledComponentsError(16, `${group}`);
|
|
201
144
|
}
|
|
202
145
|
}
|
|
203
146
|
this.groupSizes = new Uint32Array(newSize);
|
|
204
147
|
this.groupSizes.set(oldBuffer);
|
|
205
148
|
this.length = newSize;
|
|
206
|
-
for (
|
|
149
|
+
for (let i = oldSize; i < newSize; i++) {
|
|
207
150
|
this.groupSizes[i] = 0;
|
|
208
151
|
}
|
|
209
152
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
for (
|
|
153
|
+
let ruleIndex = this.indexOfGroup(group + 1);
|
|
154
|
+
let insertedCount = 0;
|
|
155
|
+
for (let i = 0, l = rules.length; i < l; i++) {
|
|
213
156
|
if (this.tag.insertRule(ruleIndex, rules[i])) {
|
|
214
157
|
this.groupSizes[group]++;
|
|
215
158
|
ruleIndex++;
|
|
@@ -220,74 +163,73 @@
|
|
|
220
163
|
if (insertedCount > 0 && this._cGroup > group) {
|
|
221
164
|
this._cIndex += insertedCount;
|
|
222
165
|
}
|
|
223
|
-
}
|
|
224
|
-
|
|
166
|
+
}
|
|
167
|
+
clearGroup(group) {
|
|
225
168
|
if (group < this.length) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
169
|
+
const length = this.groupSizes[group];
|
|
170
|
+
const startIndex = this.indexOfGroup(group);
|
|
171
|
+
const endIndex = startIndex + length;
|
|
229
172
|
this.groupSizes[group] = 0;
|
|
230
|
-
for (
|
|
173
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
231
174
|
this.tag.deleteRule(startIndex);
|
|
232
175
|
}
|
|
233
176
|
// Keep cache consistent: groups after the cleared group shift backward
|
|
234
|
-
if (
|
|
235
|
-
this._cIndex -=
|
|
177
|
+
if (length > 0 && this._cGroup > group) {
|
|
178
|
+
this._cIndex -= length;
|
|
236
179
|
}
|
|
237
180
|
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
181
|
+
}
|
|
182
|
+
getGroup(group) {
|
|
183
|
+
let css = '';
|
|
241
184
|
if (group >= this.length || this.groupSizes[group] === 0) {
|
|
242
185
|
return css;
|
|
243
186
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
for (
|
|
187
|
+
const length = this.groupSizes[group];
|
|
188
|
+
const startIndex = this.indexOfGroup(group);
|
|
189
|
+
const endIndex = startIndex + length;
|
|
190
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
248
191
|
css += this.tag.getRule(i) + SPLITTER;
|
|
249
192
|
}
|
|
250
193
|
return css;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
}());
|
|
194
|
+
}
|
|
195
|
+
};
|
|
254
196
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
197
|
+
const MAX_SMI = 1 << (31 - 1);
|
|
198
|
+
let groupIDRegister = new Map();
|
|
199
|
+
let reverseRegister = new Map();
|
|
200
|
+
let nextFreeGroup = 1;
|
|
201
|
+
const getGroupForId = (id) => {
|
|
260
202
|
if (groupIDRegister.has(id)) {
|
|
261
203
|
return groupIDRegister.get(id);
|
|
262
204
|
}
|
|
263
205
|
while (reverseRegister.has(nextFreeGroup)) {
|
|
264
206
|
nextFreeGroup++;
|
|
265
207
|
}
|
|
266
|
-
|
|
208
|
+
const group = nextFreeGroup++;
|
|
267
209
|
if (((group | 0) < 0 || group > MAX_SMI)) {
|
|
268
|
-
throw throwStyledComponentsError(16,
|
|
210
|
+
throw throwStyledComponentsError(16, `${group}`);
|
|
269
211
|
}
|
|
270
212
|
groupIDRegister.set(id, group);
|
|
271
213
|
reverseRegister.set(group, id);
|
|
272
214
|
return group;
|
|
273
215
|
};
|
|
274
|
-
|
|
216
|
+
const getIdForGroup = (group) => {
|
|
275
217
|
return reverseRegister.get(group);
|
|
276
218
|
};
|
|
277
|
-
|
|
219
|
+
const setGroupForId = (id, group) => {
|
|
278
220
|
// move pointer
|
|
279
221
|
nextFreeGroup = group + 1;
|
|
280
222
|
groupIDRegister.set(id, group);
|
|
281
223
|
reverseRegister.set(group, id);
|
|
282
224
|
};
|
|
283
225
|
|
|
284
|
-
|
|
285
|
-
|
|
226
|
+
const SELECTOR = `style[${SC_ATTR}][${SC_ATTR_VERSION}="${SC_VERSION}"]`;
|
|
227
|
+
const MARKER_RE = new RegExp(`^${SC_ATTR}\\.g(\\d+)\\[id="([\\w\\d-]+)"\\].*?"([^"]*)`);
|
|
286
228
|
/**
|
|
287
229
|
* Type guard to check if a node is a ShadowRoot.
|
|
288
230
|
* Uses instanceof when available, with duck-typing fallback for cross-realm scenarios.
|
|
289
231
|
*/
|
|
290
|
-
|
|
232
|
+
const isShadowRoot = (node) => {
|
|
291
233
|
return ((typeof ShadowRoot !== 'undefined' && node instanceof ShadowRoot) ||
|
|
292
234
|
('host' in node &&
|
|
293
235
|
// https://dom.spec.whatwg.org/#dom-node-document_fragment_node
|
|
@@ -298,7 +240,7 @@
|
|
|
298
240
|
* If the target is a ShadowRoot, return it directly.
|
|
299
241
|
* If the target is an HTMLElement, return its root node if it's a ShadowRoot, otherwise return document.
|
|
300
242
|
*/
|
|
301
|
-
|
|
243
|
+
const getRehydrationContainer = (target) => {
|
|
302
244
|
if (!target) {
|
|
303
245
|
return document;
|
|
304
246
|
}
|
|
@@ -308,30 +250,30 @@
|
|
|
308
250
|
}
|
|
309
251
|
// Check if target is an HTMLElement inside a ShadowRoot
|
|
310
252
|
if ('getRootNode' in target) {
|
|
311
|
-
|
|
253
|
+
const root = target.getRootNode();
|
|
312
254
|
if (isShadowRoot(root)) {
|
|
313
255
|
return root;
|
|
314
256
|
}
|
|
315
257
|
}
|
|
316
258
|
return document;
|
|
317
259
|
};
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
260
|
+
const outputSheet = (sheet) => {
|
|
261
|
+
const tag = sheet.getTag();
|
|
262
|
+
const { length } = tag;
|
|
263
|
+
let css = '';
|
|
264
|
+
for (let group = 0; group < length; group++) {
|
|
265
|
+
const id = getIdForGroup(group);
|
|
324
266
|
if (id === undefined)
|
|
325
|
-
|
|
326
|
-
|
|
267
|
+
continue;
|
|
268
|
+
const names = sheet.names.get(id);
|
|
327
269
|
if (names === undefined || !names.size)
|
|
328
|
-
|
|
329
|
-
|
|
270
|
+
continue;
|
|
271
|
+
const rules = tag.getGroup(group);
|
|
330
272
|
if (rules.length === 0)
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
names.forEach(
|
|
273
|
+
continue;
|
|
274
|
+
const selector = SC_ATTR + '.g' + group + '[id="' + id + '"]';
|
|
275
|
+
let content = '';
|
|
276
|
+
names.forEach(name => {
|
|
335
277
|
if (name.length > 0) {
|
|
336
278
|
content += name + ',';
|
|
337
279
|
}
|
|
@@ -339,33 +281,30 @@
|
|
|
339
281
|
// NOTE: It's easier to collect rules and have the marker
|
|
340
282
|
// after the actual rules to simplify the rehydration
|
|
341
283
|
css += rules + selector + '{content:"' + content + '"}' + SPLITTER;
|
|
342
|
-
};
|
|
343
|
-
for (var group = 0; group < length; group++) {
|
|
344
|
-
_loop_1(group);
|
|
345
284
|
}
|
|
346
285
|
return css;
|
|
347
286
|
};
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
for (
|
|
287
|
+
const rehydrateNamesFromContent = (sheet, id, content) => {
|
|
288
|
+
const names = content.split(',');
|
|
289
|
+
let name;
|
|
290
|
+
for (let i = 0, l = names.length; i < l; i++) {
|
|
352
291
|
if ((name = names[i])) {
|
|
353
292
|
sheet.registerName(id, name);
|
|
354
293
|
}
|
|
355
294
|
}
|
|
356
295
|
};
|
|
357
|
-
|
|
296
|
+
const rehydrateSheetFromTag = (sheet, style) => {
|
|
358
297
|
var _a;
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
for (
|
|
362
|
-
|
|
298
|
+
const parts = ((_a = style.textContent) !== null && _a !== void 0 ? _a : '').split(SPLITTER);
|
|
299
|
+
const rules = [];
|
|
300
|
+
for (let i = 0, l = parts.length; i < l; i++) {
|
|
301
|
+
const part = parts[i].trim();
|
|
363
302
|
if (!part)
|
|
364
303
|
continue;
|
|
365
|
-
|
|
304
|
+
const marker = part.match(MARKER_RE);
|
|
366
305
|
if (marker) {
|
|
367
|
-
|
|
368
|
-
|
|
306
|
+
const group = parseInt(marker[1], 10) | 0;
|
|
307
|
+
const id = marker[2];
|
|
369
308
|
if (group !== 0) {
|
|
370
309
|
// Rehydrate componentId to group index mapping
|
|
371
310
|
setGroupForId(id, group);
|
|
@@ -381,11 +320,11 @@
|
|
|
381
320
|
}
|
|
382
321
|
}
|
|
383
322
|
};
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
for (
|
|
388
|
-
|
|
323
|
+
const rehydrateSheet = (sheet) => {
|
|
324
|
+
const container = getRehydrationContainer(sheet.options.target);
|
|
325
|
+
const nodes = container.querySelectorAll(SELECTOR);
|
|
326
|
+
for (let i = 0, l = nodes.length; i < l; i++) {
|
|
327
|
+
const node = nodes[i];
|
|
389
328
|
if (node && node.getAttribute(SC_ATTR) !== SC_ATTR_ACTIVE) {
|
|
390
329
|
rehydrateSheetFromTag(sheet, node);
|
|
391
330
|
if (node.parentNode) {
|
|
@@ -404,17 +343,17 @@
|
|
|
404
343
|
* For Next.js/Remix, pass nonces explicitly via StyleSheetManager or
|
|
405
344
|
* ServerStyleSheet instead—auto-detection doesn't apply to header-based nonces.
|
|
406
345
|
*/
|
|
407
|
-
|
|
346
|
+
let cached = false;
|
|
408
347
|
function getNonce() {
|
|
409
348
|
if (cached !== false)
|
|
410
349
|
return cached;
|
|
411
350
|
if (typeof document !== 'undefined') {
|
|
412
351
|
// Vite sets the nonce in the `nonce` attribute. Browsers expose this via
|
|
413
352
|
// the .nonce DOM property but return "" from getAttribute('nonce').
|
|
414
|
-
|
|
353
|
+
const viteMeta = document.head.querySelector('meta[property="csp-nonce"]');
|
|
415
354
|
if (viteMeta)
|
|
416
355
|
return (cached = viteMeta.nonce || viteMeta.getAttribute('content') || undefined);
|
|
417
|
-
|
|
356
|
+
const scMeta = document.head.querySelector('meta[name="sc-nonce"]');
|
|
418
357
|
if (scMeta)
|
|
419
358
|
return (cached = scMeta.getAttribute('content') || undefined);
|
|
420
359
|
}
|
|
@@ -422,27 +361,27 @@
|
|
|
422
361
|
}
|
|
423
362
|
|
|
424
363
|
/** Find last style element if any inside target */
|
|
425
|
-
|
|
426
|
-
|
|
364
|
+
const findLastStyleTag = (target) => {
|
|
365
|
+
const arr = Array.from(target.querySelectorAll(`style[${SC_ATTR}]`));
|
|
427
366
|
return arr[arr.length - 1];
|
|
428
367
|
};
|
|
429
368
|
/** Create a style element inside `target` or <head> after the last */
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
369
|
+
const makeStyleTag = (target, nonce) => {
|
|
370
|
+
const head = document.head;
|
|
371
|
+
const parent = target || head;
|
|
372
|
+
const style = document.createElement('style');
|
|
373
|
+
const prevStyle = findLastStyleTag(parent);
|
|
374
|
+
const nextSibling = prevStyle !== undefined ? prevStyle.nextSibling : null;
|
|
436
375
|
style.setAttribute(SC_ATTR, SC_ATTR_ACTIVE);
|
|
437
376
|
style.setAttribute(SC_ATTR_VERSION, SC_VERSION);
|
|
438
|
-
|
|
377
|
+
const resolvedNonce = nonce || getNonce();
|
|
439
378
|
if (resolvedNonce)
|
|
440
379
|
style.setAttribute('nonce', resolvedNonce);
|
|
441
380
|
parent.insertBefore(style, nextSibling);
|
|
442
381
|
return style;
|
|
443
382
|
};
|
|
444
383
|
/** Get the CSSStyleSheet instance for a given style element */
|
|
445
|
-
|
|
384
|
+
const getSheet = (tag) => {
|
|
446
385
|
var _a;
|
|
447
386
|
if (tag.sheet) {
|
|
448
387
|
return tag.sheet;
|
|
@@ -450,10 +389,10 @@
|
|
|
450
389
|
// Avoid Firefox quirk where the style element might not have a sheet property.
|
|
451
390
|
// Use the tag's root node to find styleSheets — document.styleSheets doesn't
|
|
452
391
|
// include sheets inside shadow roots.
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
for (
|
|
456
|
-
|
|
392
|
+
const root = tag.getRootNode();
|
|
393
|
+
const styleSheets = (_a = root.styleSheets) !== null && _a !== void 0 ? _a : document.styleSheets;
|
|
394
|
+
for (let i = 0, l = styleSheets.length; i < l; i++) {
|
|
395
|
+
const sheet = styleSheets[i];
|
|
457
396
|
if (sheet.ownerNode === tag) {
|
|
458
397
|
return sheet;
|
|
459
398
|
}
|
|
@@ -462,8 +401,7 @@
|
|
|
462
401
|
};
|
|
463
402
|
|
|
464
403
|
/** Create a CSSStyleSheet-like tag depending on the environment */
|
|
465
|
-
|
|
466
|
-
var isServer = _a.isServer, useCSSOMInjection = _a.useCSSOMInjection, target = _a.target, nonce = _a.nonce;
|
|
404
|
+
const makeTag = ({ isServer, useCSSOMInjection, target, nonce }) => {
|
|
467
405
|
if (isServer) {
|
|
468
406
|
return new VirtualTag(target);
|
|
469
407
|
}
|
|
@@ -474,15 +412,15 @@
|
|
|
474
412
|
return new TextTag(target, nonce);
|
|
475
413
|
}
|
|
476
414
|
};
|
|
477
|
-
|
|
478
|
-
|
|
415
|
+
const CSSOMTag = class CSSOMTag {
|
|
416
|
+
constructor(target, nonce) {
|
|
479
417
|
this.element = makeStyleTag(target, nonce);
|
|
480
418
|
// Avoid Edge bug where empty style elements don't create sheets
|
|
481
419
|
this.element.appendChild(document.createTextNode(''));
|
|
482
420
|
this.sheet = getSheet(this.element);
|
|
483
421
|
this.length = 0;
|
|
484
422
|
}
|
|
485
|
-
|
|
423
|
+
insertRule(index, rule) {
|
|
486
424
|
try {
|
|
487
425
|
this.sheet.insertRule(rule, index);
|
|
488
426
|
this.length++;
|
|
@@ -491,13 +429,13 @@
|
|
|
491
429
|
catch (_error) {
|
|
492
430
|
return false;
|
|
493
431
|
}
|
|
494
|
-
}
|
|
495
|
-
|
|
432
|
+
}
|
|
433
|
+
deleteRule(index) {
|
|
496
434
|
this.sheet.deleteRule(index);
|
|
497
435
|
this.length--;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
|
|
436
|
+
}
|
|
437
|
+
getRule(index) {
|
|
438
|
+
const rule = this.sheet.cssRules[index];
|
|
501
439
|
// Avoid IE11 quirk where cssText is inaccessible on some invalid rules
|
|
502
440
|
if (rule && rule.cssText) {
|
|
503
441
|
return rule.cssText;
|
|
@@ -505,20 +443,19 @@
|
|
|
505
443
|
else {
|
|
506
444
|
return '';
|
|
507
445
|
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
}());
|
|
446
|
+
}
|
|
447
|
+
};
|
|
511
448
|
/** A Tag that emulates the CSSStyleSheet API but uses text nodes */
|
|
512
|
-
|
|
513
|
-
|
|
449
|
+
const TextTag = class TextTag {
|
|
450
|
+
constructor(target, nonce) {
|
|
514
451
|
this.element = makeStyleTag(target, nonce);
|
|
515
452
|
this.nodes = this.element.childNodes;
|
|
516
453
|
this.length = 0;
|
|
517
454
|
}
|
|
518
|
-
|
|
455
|
+
insertRule(index, rule) {
|
|
519
456
|
if (index <= this.length && index >= 0) {
|
|
520
|
-
|
|
521
|
-
|
|
457
|
+
const node = document.createTextNode(rule);
|
|
458
|
+
const refNode = this.nodes[index];
|
|
522
459
|
this.element.insertBefore(node, refNode || null);
|
|
523
460
|
this.length++;
|
|
524
461
|
return true;
|
|
@@ -526,28 +463,27 @@
|
|
|
526
463
|
else {
|
|
527
464
|
return false;
|
|
528
465
|
}
|
|
529
|
-
}
|
|
530
|
-
|
|
466
|
+
}
|
|
467
|
+
deleteRule(index) {
|
|
531
468
|
this.element.removeChild(this.nodes[index]);
|
|
532
469
|
this.length--;
|
|
533
|
-
}
|
|
534
|
-
|
|
470
|
+
}
|
|
471
|
+
getRule(index) {
|
|
535
472
|
if (index < this.length) {
|
|
536
473
|
return this.nodes[index].textContent;
|
|
537
474
|
}
|
|
538
475
|
else {
|
|
539
476
|
return '';
|
|
540
477
|
}
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
}());
|
|
478
|
+
}
|
|
479
|
+
};
|
|
544
480
|
/** A completely virtual (server-side) Tag that doesn't manipulate the DOM */
|
|
545
|
-
|
|
546
|
-
|
|
481
|
+
const VirtualTag = class VirtualTag {
|
|
482
|
+
constructor(_target) {
|
|
547
483
|
this.rules = [];
|
|
548
484
|
this.length = 0;
|
|
549
485
|
}
|
|
550
|
-
|
|
486
|
+
insertRule(index, rule) {
|
|
551
487
|
if (index <= this.length) {
|
|
552
488
|
if (index === this.length) {
|
|
553
489
|
this.rules.push(rule);
|
|
@@ -561,34 +497,34 @@
|
|
|
561
497
|
else {
|
|
562
498
|
return false;
|
|
563
499
|
}
|
|
564
|
-
}
|
|
565
|
-
|
|
500
|
+
}
|
|
501
|
+
deleteRule(index) {
|
|
566
502
|
this.rules.splice(index, 1);
|
|
567
503
|
this.length--;
|
|
568
|
-
}
|
|
569
|
-
|
|
504
|
+
}
|
|
505
|
+
getRule(index) {
|
|
570
506
|
if (index < this.length) {
|
|
571
507
|
return this.rules[index];
|
|
572
508
|
}
|
|
573
509
|
else {
|
|
574
510
|
return '';
|
|
575
511
|
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
}());
|
|
512
|
+
}
|
|
513
|
+
};
|
|
579
514
|
|
|
580
|
-
|
|
581
|
-
|
|
515
|
+
let SHOULD_REHYDRATE = IS_BROWSER;
|
|
516
|
+
const defaultOptions = {
|
|
582
517
|
isServer: !IS_BROWSER,
|
|
583
518
|
useCSSOMInjection: !DISABLE_SPEEDY,
|
|
584
519
|
};
|
|
585
520
|
/** Contains the main stylesheet logic for stringification and caching */
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
521
|
+
class StyleSheet {
|
|
522
|
+
/** Register a group ID to give it an index */
|
|
523
|
+
static registerId(id) {
|
|
524
|
+
return getGroupForId(id);
|
|
525
|
+
}
|
|
526
|
+
constructor(options = EMPTY_OBJECT, globalStyles = {}, names) {
|
|
527
|
+
this.options = Object.assign(Object.assign({}, defaultOptions), options);
|
|
592
528
|
this.gs = globalStyles;
|
|
593
529
|
this.keyframeIds = new Set();
|
|
594
530
|
this.names = new Map(names);
|
|
@@ -598,143 +534,131 @@
|
|
|
598
534
|
SHOULD_REHYDRATE = false;
|
|
599
535
|
rehydrateSheet(this);
|
|
600
536
|
}
|
|
601
|
-
setToString(this,
|
|
537
|
+
setToString(this, () => outputSheet(this));
|
|
602
538
|
}
|
|
603
|
-
|
|
604
|
-
StyleSheet.registerId = function (id) {
|
|
605
|
-
return getGroupForId(id);
|
|
606
|
-
};
|
|
607
|
-
StyleSheet.prototype.rehydrate = function () {
|
|
539
|
+
rehydrate() {
|
|
608
540
|
if (!this.server && IS_BROWSER) {
|
|
609
541
|
rehydrateSheet(this);
|
|
610
542
|
}
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
var newSheet = new StyleSheet(__assign(__assign({}, this.options), options), this.gs, (withNames && this.names) || undefined);
|
|
543
|
+
}
|
|
544
|
+
reconstructWithOptions(options, withNames = true) {
|
|
545
|
+
const newSheet = new StyleSheet(Object.assign(Object.assign({}, this.options), options), this.gs, (withNames && this.names) || undefined);
|
|
615
546
|
newSheet.keyframeIds = new Set(this.keyframeIds);
|
|
616
547
|
// If we're reconstructing with a new target on the client, check if the container changed
|
|
617
548
|
// This handles the case where StyleSheetManager's target prop changes (e.g., from undefined to shadowRoot)
|
|
618
549
|
// We only rehydrate if the container (Document or ShadowRoot) actually changes
|
|
619
550
|
if (!this.server && IS_BROWSER && options.target !== this.options.target) {
|
|
620
|
-
|
|
621
|
-
|
|
551
|
+
const oldContainer = getRehydrationContainer(this.options.target);
|
|
552
|
+
const newContainer = getRehydrationContainer(options.target);
|
|
622
553
|
if (oldContainer !== newContainer) {
|
|
623
554
|
rehydrateSheet(newSheet);
|
|
624
555
|
}
|
|
625
556
|
}
|
|
626
557
|
return newSheet;
|
|
627
|
-
}
|
|
628
|
-
|
|
558
|
+
}
|
|
559
|
+
allocateGSInstance(id) {
|
|
629
560
|
return (this.gs[id] = (this.gs[id] || 0) + 1);
|
|
630
|
-
}
|
|
561
|
+
}
|
|
631
562
|
/** Lazily initialises a GroupedTag for when it's actually needed */
|
|
632
|
-
|
|
563
|
+
getTag() {
|
|
633
564
|
return this.tag || (this.tag = makeGroupedTag(makeTag(this.options)));
|
|
634
|
-
}
|
|
565
|
+
}
|
|
635
566
|
/** Check whether a name is known for caching */
|
|
636
|
-
|
|
567
|
+
hasNameForId(id, name) {
|
|
637
568
|
var _a, _b;
|
|
638
569
|
return (_b = (_a = this.names.get(id)) === null || _a === void 0 ? void 0 : _a.has(name)) !== null && _b !== void 0 ? _b : false;
|
|
639
|
-
}
|
|
570
|
+
}
|
|
640
571
|
/** Mark a group's name as known for caching */
|
|
641
|
-
|
|
572
|
+
registerName(id, name) {
|
|
642
573
|
getGroupForId(id);
|
|
643
574
|
if (id.startsWith(KEYFRAMES_ID_PREFIX)) {
|
|
644
575
|
this.keyframeIds.add(id);
|
|
645
576
|
}
|
|
646
|
-
|
|
577
|
+
const existing = this.names.get(id);
|
|
647
578
|
if (existing) {
|
|
648
579
|
existing.add(name);
|
|
649
580
|
}
|
|
650
581
|
else {
|
|
651
582
|
this.names.set(id, new Set([name]));
|
|
652
583
|
}
|
|
653
|
-
}
|
|
584
|
+
}
|
|
654
585
|
/** Insert new rules which also marks the name as known */
|
|
655
|
-
|
|
586
|
+
insertRules(id, name, rules) {
|
|
656
587
|
this.registerName(id, name);
|
|
657
588
|
this.getTag().insertRules(getGroupForId(id), rules);
|
|
658
|
-
}
|
|
589
|
+
}
|
|
659
590
|
/** Clears all cached names for a given group ID */
|
|
660
|
-
|
|
591
|
+
clearNames(id) {
|
|
661
592
|
if (this.names.has(id)) {
|
|
662
593
|
this.names.get(id).clear();
|
|
663
594
|
}
|
|
664
|
-
}
|
|
595
|
+
}
|
|
665
596
|
/** Clears all rules for a given group ID */
|
|
666
|
-
|
|
597
|
+
clearRules(id) {
|
|
667
598
|
this.getTag().clearGroup(getGroupForId(id));
|
|
668
599
|
this.clearNames(id);
|
|
669
|
-
}
|
|
600
|
+
}
|
|
670
601
|
/** Clears the entire tag which deletes all rules but not its names */
|
|
671
|
-
|
|
602
|
+
clearTag() {
|
|
672
603
|
// NOTE: This does not clear the names, since it's only used during SSR
|
|
673
604
|
// so that we can continuously output only new rules
|
|
674
605
|
this.tag = undefined;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
}());
|
|
606
|
+
}
|
|
607
|
+
}
|
|
678
608
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
strokeDasharray: 1,
|
|
724
|
-
strokeDashoffset: 1,
|
|
725
|
-
strokeMiterlimit: 1,
|
|
726
|
-
strokeOpacity: 1,
|
|
727
|
-
strokeWidth: 1
|
|
609
|
+
/**
|
|
610
|
+
* CSS properties that accept unitless numeric values.
|
|
611
|
+
* Inlined from @emotion/unitless with IE-only entries removed
|
|
612
|
+
* (boxFlex, boxFlexGroup, boxOrdinalGroup, flexPositive, flexNegative,
|
|
613
|
+
* flexOrder, msGridRow, msGridRowSpan, msGridColumn, msGridColumnSpan).
|
|
614
|
+
*/
|
|
615
|
+
const unitless = {
|
|
616
|
+
animationIterationCount: 1,
|
|
617
|
+
aspectRatio: 1,
|
|
618
|
+
borderImageOutset: 1,
|
|
619
|
+
borderImageSlice: 1,
|
|
620
|
+
borderImageWidth: 1,
|
|
621
|
+
columnCount: 1,
|
|
622
|
+
columns: 1,
|
|
623
|
+
flex: 1,
|
|
624
|
+
flexGrow: 1,
|
|
625
|
+
flexShrink: 1,
|
|
626
|
+
gridRow: 1,
|
|
627
|
+
gridRowEnd: 1,
|
|
628
|
+
gridRowSpan: 1,
|
|
629
|
+
gridRowStart: 1,
|
|
630
|
+
gridColumn: 1,
|
|
631
|
+
gridColumnEnd: 1,
|
|
632
|
+
gridColumnSpan: 1,
|
|
633
|
+
gridColumnStart: 1,
|
|
634
|
+
fontWeight: 1,
|
|
635
|
+
lineHeight: 1,
|
|
636
|
+
opacity: 1,
|
|
637
|
+
order: 1,
|
|
638
|
+
orphans: 1,
|
|
639
|
+
scale: 1,
|
|
640
|
+
tabSize: 1,
|
|
641
|
+
widows: 1,
|
|
642
|
+
zIndex: 1,
|
|
643
|
+
zoom: 1,
|
|
644
|
+
WebkitLineClamp: 1,
|
|
645
|
+
fillOpacity: 1,
|
|
646
|
+
floodOpacity: 1,
|
|
647
|
+
stopOpacity: 1,
|
|
648
|
+
strokeDasharray: 1,
|
|
649
|
+
strokeDashoffset: 1,
|
|
650
|
+
strokeMiterlimit: 1,
|
|
651
|
+
strokeOpacity: 1,
|
|
652
|
+
strokeWidth: 1,
|
|
728
653
|
};
|
|
729
|
-
|
|
730
654
|
// Taken from https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/shared/dangerousStyleValue.js
|
|
731
655
|
function addUnitIfNeeded(name, value) {
|
|
732
656
|
// https://github.com/amilajack/eslint-plugin-flowtype-errors/issues/133
|
|
733
657
|
if (value == null || typeof value === 'boolean' || value === '') {
|
|
734
658
|
return '';
|
|
735
659
|
}
|
|
736
|
-
if (typeof value === 'number' && value !== 0 && !(name in
|
|
737
|
-
return
|
|
660
|
+
if (typeof value === 'number' && value !== 0 && !(name in unitless) && !name.startsWith('--')) {
|
|
661
|
+
return `${value}px`; // Presumes implicit 'px' suffix for unitless numbers except for CSS variables
|
|
738
662
|
}
|
|
739
663
|
return String(value).trim();
|
|
740
664
|
}
|
|
@@ -746,7 +670,7 @@
|
|
|
746
670
|
'Component');
|
|
747
671
|
}
|
|
748
672
|
|
|
749
|
-
|
|
673
|
+
const isUpper = (c) => c >= 'A' && c <= 'Z';
|
|
750
674
|
/**
|
|
751
675
|
* Hyphenates a camelcased CSS property name, for example:
|
|
752
676
|
*
|
|
@@ -761,9 +685,9 @@
|
|
|
761
685
|
* is converted to `-ms-`.
|
|
762
686
|
*/
|
|
763
687
|
function hyphenateStyleName(string) {
|
|
764
|
-
|
|
765
|
-
for (
|
|
766
|
-
|
|
688
|
+
let output = '';
|
|
689
|
+
for (let i = 0; i < string.length; i++) {
|
|
690
|
+
const c = string[i];
|
|
767
691
|
// Check for CSS variable prefix
|
|
768
692
|
if (i === 1 && c === '-' && string[0] === '-') {
|
|
769
693
|
return string;
|
|
@@ -782,7 +706,7 @@
|
|
|
782
706
|
return typeof test === 'function';
|
|
783
707
|
}
|
|
784
708
|
|
|
785
|
-
|
|
709
|
+
const KEYFRAMES_SYMBOL = Symbol.for('sc-keyframes');
|
|
786
710
|
function isKeyframes(value) {
|
|
787
711
|
return typeof value === 'object' && value !== null && KEYFRAMES_SYMBOL in value;
|
|
788
712
|
}
|
|
@@ -806,30 +730,27 @@
|
|
|
806
730
|
/**
|
|
807
731
|
* It's falsish not falsy because 0 is allowed.
|
|
808
732
|
*/
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
for (var key in obj) {
|
|
815
|
-
var val = obj[key];
|
|
733
|
+
const isFalsish = (chunk) => chunk === undefined || chunk === null || chunk === false || chunk === '';
|
|
734
|
+
const objToCssArray = (obj) => {
|
|
735
|
+
const rules = [];
|
|
736
|
+
for (const key in obj) {
|
|
737
|
+
const val = obj[key];
|
|
816
738
|
if (!obj.hasOwnProperty(key) || isFalsish(val))
|
|
817
739
|
continue;
|
|
818
740
|
// @ts-expect-error Property 'isCss' does not exist on type 'any[]'
|
|
819
741
|
if ((Array.isArray(val) && val.isCss) || isFunction(val)) {
|
|
820
|
-
rules.push(
|
|
742
|
+
rules.push(`${hyphenateStyleName(key)}:`, val, ';');
|
|
821
743
|
}
|
|
822
744
|
else if (isPlainObject(val)) {
|
|
823
|
-
rules.push
|
|
745
|
+
rules.push(`${key} {`, ...objToCssArray(val), '}');
|
|
824
746
|
}
|
|
825
747
|
else {
|
|
826
|
-
rules.push(
|
|
748
|
+
rules.push(`${hyphenateStyleName(key)}: ${addUnitIfNeeded(key, val)};`);
|
|
827
749
|
}
|
|
828
750
|
}
|
|
829
751
|
return rules;
|
|
830
752
|
};
|
|
831
|
-
function flatten(chunk, executionContext, styleSheet, stylisInstance, result) {
|
|
832
|
-
if (result === void 0) { result = []; }
|
|
753
|
+
function flatten(chunk, executionContext, styleSheet, stylisInstance, result = []) {
|
|
833
754
|
if (typeof chunk === 'string') {
|
|
834
755
|
if (chunk)
|
|
835
756
|
result.push(chunk);
|
|
@@ -840,19 +761,19 @@
|
|
|
840
761
|
}
|
|
841
762
|
/* Handle other components */
|
|
842
763
|
if (isStyledComponent(chunk)) {
|
|
843
|
-
result.push(
|
|
764
|
+
result.push(`.${chunk.styledComponentId}`);
|
|
844
765
|
return result;
|
|
845
766
|
}
|
|
846
767
|
/* Either execute or defer the function */
|
|
847
768
|
if (isFunction(chunk)) {
|
|
848
769
|
if (isStatelessFunction(chunk) && executionContext) {
|
|
849
|
-
|
|
770
|
+
const fnResult = chunk(executionContext);
|
|
850
771
|
if (typeof fnResult === 'object' &&
|
|
851
772
|
!Array.isArray(fnResult) &&
|
|
852
773
|
!isKeyframes(fnResult) &&
|
|
853
774
|
!isPlainObject(fnResult) &&
|
|
854
775
|
fnResult !== null) {
|
|
855
|
-
console.error(
|
|
776
|
+
console.error(`${getComponentName(chunk)} 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.`);
|
|
856
777
|
}
|
|
857
778
|
return flatten(fnResult, executionContext, styleSheet, stylisInstance, result);
|
|
858
779
|
}
|
|
@@ -873,8 +794,8 @@
|
|
|
873
794
|
}
|
|
874
795
|
/* Handle objects */
|
|
875
796
|
if (isPlainObject(chunk)) {
|
|
876
|
-
|
|
877
|
-
for (
|
|
797
|
+
const cssArr = objToCssArray(chunk);
|
|
798
|
+
for (let i = 0; i < cssArr.length; i++)
|
|
878
799
|
result.push(cssArr[i]);
|
|
879
800
|
return result;
|
|
880
801
|
}
|
|
@@ -882,15 +803,15 @@
|
|
|
882
803
|
result.push(chunk.toString());
|
|
883
804
|
return result;
|
|
884
805
|
}
|
|
885
|
-
for (
|
|
806
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
886
807
|
flatten(chunk[i], executionContext, styleSheet, stylisInstance, result);
|
|
887
808
|
}
|
|
888
809
|
return result;
|
|
889
810
|
}
|
|
890
811
|
|
|
891
812
|
function isStaticRules(rules) {
|
|
892
|
-
for (
|
|
893
|
-
|
|
813
|
+
for (let i = 0; i < rules.length; i += 1) {
|
|
814
|
+
const rule = rules[i];
|
|
894
815
|
if (isFunction(rule) && !isStyledComponent(rule)) {
|
|
895
816
|
// functions are allowed to be static if they're just being
|
|
896
817
|
// used to get the classname of a nested styled component
|
|
@@ -904,14 +825,14 @@
|
|
|
904
825
|
* Convenience function for joining strings to form className chains
|
|
905
826
|
*/
|
|
906
827
|
function joinStrings(a, b) {
|
|
907
|
-
return a && b ?
|
|
828
|
+
return a && b ? `${a} ${b}` : a || b || '';
|
|
908
829
|
}
|
|
909
830
|
function joinStringArray(arr, sep) {
|
|
910
831
|
return arr.join(sep || '');
|
|
911
832
|
}
|
|
912
833
|
|
|
913
|
-
|
|
914
|
-
|
|
834
|
+
class GlobalStyle {
|
|
835
|
+
constructor(rules, componentId) {
|
|
915
836
|
/** @internal Per-instance rule cache for shared-group rebuild. */
|
|
916
837
|
this.instanceRules = new Map();
|
|
917
838
|
this.rules = rules;
|
|
@@ -921,15 +842,15 @@
|
|
|
921
842
|
// components always appear before them in the stylesheet.
|
|
922
843
|
StyleSheet.registerId(this.componentId);
|
|
923
844
|
}
|
|
924
|
-
|
|
845
|
+
removeStyles(instance, styleSheet) {
|
|
925
846
|
this.instanceRules.delete(instance);
|
|
926
847
|
this.rebuildGroup(styleSheet);
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
|
|
848
|
+
}
|
|
849
|
+
renderStyles(instance, executionContext, styleSheet, stylis) {
|
|
850
|
+
const id = this.componentId;
|
|
930
851
|
if (this.isStatic) {
|
|
931
852
|
if (!styleSheet.hasNameForId(id, id + instance)) {
|
|
932
|
-
|
|
853
|
+
const entry = this.computeRules(instance, executionContext, styleSheet, stylis);
|
|
933
854
|
styleSheet.insertRules(id, entry.name, entry.rules);
|
|
934
855
|
}
|
|
935
856
|
else if (!this.instanceRules.has(instance)) {
|
|
@@ -942,14 +863,14 @@
|
|
|
942
863
|
// Compute new rules; skip CSSOM rebuild if CSS is unchanged.
|
|
943
864
|
// The fast-path is only safe on the client where the tag persists between renders.
|
|
944
865
|
// During SSR, clearTag() destroys the tag between requests, so we must always rebuild.
|
|
945
|
-
|
|
866
|
+
const prev = this.instanceRules.get(instance);
|
|
946
867
|
this.computeRules(instance, executionContext, styleSheet, stylis);
|
|
947
868
|
if (!styleSheet.server && prev) {
|
|
948
|
-
|
|
949
|
-
|
|
869
|
+
const a = prev.rules;
|
|
870
|
+
const b = this.instanceRules.get(instance).rules;
|
|
950
871
|
if (a.length === b.length) {
|
|
951
|
-
|
|
952
|
-
for (
|
|
872
|
+
let same = true;
|
|
873
|
+
for (let i = 0; i < a.length; i++) {
|
|
953
874
|
if (a[i] !== b[i]) {
|
|
954
875
|
same = false;
|
|
955
876
|
break;
|
|
@@ -960,61 +881,60 @@
|
|
|
960
881
|
}
|
|
961
882
|
}
|
|
962
883
|
this.rebuildGroup(styleSheet);
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
884
|
+
}
|
|
885
|
+
computeRules(instance, executionContext, styleSheet, stylis) {
|
|
886
|
+
const flatCSS = joinStringArray(flatten(this.rules, executionContext, styleSheet, stylis));
|
|
887
|
+
const entry = {
|
|
967
888
|
name: this.componentId + instance,
|
|
968
889
|
rules: stylis(flatCSS, ''),
|
|
969
890
|
};
|
|
970
891
|
this.instanceRules.set(instance, entry);
|
|
971
892
|
return entry;
|
|
972
|
-
}
|
|
893
|
+
}
|
|
973
894
|
/**
|
|
974
895
|
* Clear all CSS rules in the shared group and re-insert from surviving instances.
|
|
975
896
|
* Must run synchronously — no yielding between clear and re-insert.
|
|
976
897
|
*/
|
|
977
|
-
|
|
978
|
-
|
|
898
|
+
rebuildGroup(styleSheet) {
|
|
899
|
+
const id = this.componentId;
|
|
979
900
|
styleSheet.clearRules(id);
|
|
980
|
-
this.instanceRules.forEach(
|
|
901
|
+
this.instanceRules.forEach(entry => {
|
|
981
902
|
styleSheet.insertRules(id, entry.name, entry.rules);
|
|
982
903
|
});
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
}());
|
|
904
|
+
}
|
|
905
|
+
}
|
|
986
906
|
|
|
987
907
|
var e="-ms-";var r="-moz-";var a="-webkit-";var c="comm";var n="rule";var s="decl";var i="@import";var v="@namespace";var b="@keyframes";var g="@layer";var $=Math.abs;var m=String.fromCharCode;var x=Object.assign;function y(e,r){return A(e,0)^45?(((r<<2^A(e,0))<<2^A(e,1))<<2^A(e,2))<<2^A(e,3):0}function j(e){return e.trim()}function z(e,r){return (e=r.exec(e))?e[0]:e}function C(e,r,a){return e.replace(r,a)}function O(e,r,a){return e.indexOf(r,a)}function A(e,r){return e.charCodeAt(r)|0}function M(e,r,a){return e.slice(r,a)}function S(e){return e.length}function q(e){return e.length}function B(e,r){return r.push(e),e}function D(e,r){return e.map(r).join("")}function E(e,r){return e.filter((function(e){return !z(e,r)}))}var F=1;var G=1;var H=0;var I=0;var J=0;var K="";function L(e,r,a,c,n,s,t,u){return {value:e,root:r,parent:a,type:c,props:n,children:s,line:F,column:G,length:t,return:"",siblings:u}}function N(e,r){return x(L("",null,null,"",null,null,0,e.siblings),e,{length:-e.length},r)}function P(e){while(e.root)e=N(e.root,{children:[e]});B(e,e.siblings);}function Q(){return J}function R(){J=I>0?A(K,--I):0;if(G--,J===10)G=1,F--;return J}function T(){J=I<H?A(K,I++):0;if(G++,J===10)G=1,F++;return J}function U(){return A(K,I)}function V(){return I}function W(e,r){return M(K,e,r)}function X(e){switch(e){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function Y(e){return F=G=1,H=S(K=e),I=0,[]}function Z(e){return K="",e}function _(e){return j(W(I-1,ne(e===91?e+2:e===40?e+1:e)))}function re(e){while(J=U())if(J<33)T();else break;return X(e)>2||X(J)>3?"":" "}function ce(e,r){while(--r&&T())if(J<48||J>102||J>57&&J<65||J>70&&J<97)break;return W(e,V()+(r<6&&U()==32&&T()==32))}function ne(e){while(T())switch(J){case e:return I;case 34:case 39:if(e!==34&&e!==39)ne(J);break;case 40:if(e===41)ne(e);break;case 92:T();break}return I}function se(e,r){while(T())if(e+J===47+10)break;else if(e+J===42+42&&U()===47)break;return "/*"+W(r,I-1)+"*"+m(e===47?e:T())}function te(e){while(!X(U()))T();return W(e,I)}function ue(e){return Z(ie("",null,null,null,[""],e=Y(e),0,[0],e))}function ie(e,r,a,c,n,s,t,u,i){var f=0;var o=0;var l=t;var p=0;var v=0;var b=0;var h=1;var w=1;var d=1;var g=0;var k="";var x=n;var y=s;var j=c;var z=k;while(w)switch(b=g,g=T()){case 40:if(b!=108&&A(z,l-1)==58){if(O(z+=C(_(g),"&","&\f"),"&\f",$(f?u[f-1]:0))!=-1)d=-1;break}case 34:case 39:case 91:z+=_(g);break;case 9:case 10:case 13:case 32:z+=re(b);break;case 92:z+=ce(V()-1,7);continue;case 47:switch(U()){case 42:case 47:B(oe(se(T(),V()),r,a,i),i);if((X(b||1)==5||X(U()||1)==5)&&S(z)&&M(z,-1,void 0)!==" ")z+=" ";break;default:z+="/";}break;case 123*h:u[f++]=S(z)*d;case 125*h:case 59:case 0:switch(g){case 0:case 125:w=0;case 59+o:if(d==-1)z=C(z,/\f/g,"");if(v>0&&(S(z)-l||h===0&&b===47))B(v>32?le(z+";",c,a,l-1,i):le(C(z," ","")+";",c,a,l-2,i),i);break;case 59:z+=";";default:B(j=fe(z,r,a,f,o,n,u,k,x=[],y=[],l,s),s);if(g===123)if(o===0)ie(z,r,j,j,x,s,l,u,y);else {switch(p){case 99:if(A(z,3)===110)break;case 108:if(A(z,2)===97)break;default:o=0;case 100:case 109:case 115:}if(o)ie(e,j,j,c&&B(fe(e,j,j,0,0,n,u,k,n,x=[],l,y),y),n,y,l,u,c?x:y);else ie(z,j,j,j,[""],y,0,u,y);}}f=o=v=0,h=d=1,k=z="",l=t;break;case 58:l=1+S(z),v=b;default:if(h<1)if(g==123)--h;else if(g==125&&h++==0&&R()==125)continue;switch(z+=m(g),g*h){case 38:d=o>0?1:(z+="\f",-1);break;case 44:u[f++]=(S(z)-1)*d,d=1;break;case 64:if(U()===45)z+=_(T());p=U(),o=l=S(k=z+=te(V())),g++;break;case 45:if(b===45&&S(z)==2)h=0;}}return s}function fe(e,r,a,c,s,t,u,i,f,o,l,p){var v=s-1;var b=s===0?t:[""];var h=q(b);for(var w=0,d=0,g=0;w<c;++w)for(var k=0,m=M(e,v+1,v=$(d=u[w])),x=e;k<h;++k)if(x=j(d>0?b[k]+" "+m:C(m,/&\f/g,b[k])))f[g++]=x;return L(e,r,a,s===0?n:i,f,o,l,p)}function oe(e,r,a,n){return L(e,r,a,c,m(Q()),M(e,2,-2),0,n)}function le(e,r,a,c,n){return L(e,r,a,s,M(e,0,c),M(e,c+1,-1),c,n)}function pe(c,n,s){switch(y(c,n)){case 5103:return a+"print-"+c+c;case 5737:case 4201:case 3177:case 3433:case 1641:case 4457:case 2921:case 5572:case 6356:case 5844:case 3191:case 6645:case 3005:case 4215:case 6389:case 5109:case 5365:case 5621:case 3829:case 6391:case 5879:case 5623:case 6135:case 4599:return a+c+c;case 4855:return a+c.replace("add","source-over").replace("substract","source-out").replace("intersect","source-in").replace("exclude","xor")+c;case 4789:return r+c+c;case 5349:case 4246:case 4810:case 6968:case 2756:return a+c+r+c+e+c+c;case 5936:switch(A(c,n+11)){case 114:return a+c+e+C(c,/[svh]\w+-[tblr]{2}/,"tb")+c;case 108:return a+c+e+C(c,/[svh]\w+-[tblr]{2}/,"tb-rl")+c;case 45:return a+c+e+C(c,/[svh]\w+-[tblr]{2}/,"lr")+c}case 6828:case 4268:case 2903:return a+c+e+c+c;case 6165:return a+c+e+"flex-"+c+c;case 5187:return a+c+C(c,/(\w+).+(:[^]+)/,a+"box-$1$2"+e+"flex-$1$2")+c;case 5443:return a+c+e+"flex-item-"+C(c,/flex-|-self/g,"")+(!z(c,/flex-|baseline/)?e+"grid-row-"+C(c,/flex-|-self/g,""):"")+c;case 4675:return a+c+e+"flex-line-pack"+C(c,/align-content|flex-|-self/g,"")+c;case 5548:return a+c+e+C(c,"shrink","negative")+c;case 5292:return a+c+e+C(c,"basis","preferred-size")+c;case 6060:return a+"box-"+C(c,"-grow","")+a+c+e+C(c,"grow","positive")+c;case 4554:return a+C(c,/([^-])(transform)/g,"$1"+a+"$2")+c;case 6187:return C(C(C(c,/(zoom-|grab)/,a+"$1"),/(image-set)/,a+"$1"),c,"")+c;case 5495:case 3959:return C(c,/(image-set\([^]*)/,a+"$1"+"$`$1");case 4968:return C(C(c,/(.+:)(flex-)?(.*)/,a+"box-pack:$3"+e+"flex-pack:$3"),/space-between/,"justify")+a+c+c;case 4200:if(!z(c,/flex-|baseline/))return e+"grid-column-align"+M(c,n)+c;break;case 2592:case 3360:return e+C(c,"template-","")+c;case 4384:case 3616:if(s&&s.some((function(e,r){return n=r,z(e.props,/grid-\w+-end/)}))){return ~O(c+(s=s[n].value),"span",0)?c:e+C(c,"-start","")+c+e+"grid-row-span:"+(~O(s,"span",0)?z(s,/\d+/):+z(s,/\d+/)-+z(c,/\d+/))+";"}return e+C(c,"-start","")+c;case 4896:case 4128:return s&&s.some((function(e){return z(e.props,/grid-\w+-start/)}))?c:e+C(C(c,"-end","-span"),"span ","")+c;case 4095:case 3583:case 4068:case 2532:return C(c,/(.+)-inline(.+)/,a+"$1$2")+c;case 8116:case 7059:case 5753:case 5535:case 5445:case 5701:case 4933:case 4677:case 5533:case 5789:case 5021:case 4765:if(S(c)-1-n>6)switch(A(c,n+1)){case 109:if(A(c,n+4)!==45)break;case 102:return C(c,/(.+:)(.+)-([^]+)/,"$1"+a+"$2-$3"+"$1"+r+(A(c,n+3)==108?"$3":"$2-$3"))+c;case 115:return ~O(c,"stretch",0)?pe(C(c,"stretch","fill-available"),n,s)+c:c}break;case 5152:case 5920:return C(c,/(.+?):(\d+)(\s*\/\s*(span)?\s*(\d+))?(.*)/,(function(r,a,n,s,t,u,i){return e+a+":"+n+i+(s?e+a+"-span:"+(t?u:+u-+n)+i:"")+c}));case 4949:if(A(c,n+6)===121)return C(c,":",":"+a)+c;break;case 6444:switch(A(c,A(c,14)===45?18:11)){case 120:return C(c,/(.+:)([^;\s!]+)(;|(\s+)?!.+)?/,"$1"+a+(A(c,14)===45?"inline-":"")+"box$3"+"$1"+a+"$2$3"+"$1"+e+"$2box$3")+c;case 100:return C(c,":",":"+e)+c}break;case 5719:case 2647:case 2135:case 3927:case 2391:return C(c,"scroll-","scroll-snap-")+c}return c}function ve(e,r){var a="";for(var c=0;c<e.length;c++)a+=r(e[c],c,e,r)||"";return a}function be(e,r,a,t){switch(e.type){case g:if(e.children.length)break;case i:case v:case s:return e.return=e.return||e.value;case c:return "";case b:return e.return=e.value+"{"+ve(e.children,t)+"}";case n:if(!S(e.value=e.props.join(",")))return ""}return S(a=ve(e.children,t))?e.return=e.value+"{"+a+"}":""}function he(e){var r=q(e);return function(a,c,n,s){var t="";for(var u=0;u<r;u++)t+=e[u](a,c,n,s)||"";return t}}function we(e){return function(r){if(!r.root)if(r=r.return)e(r);}}function de(c,t,u,i){if(c.length>-1)if(!c.return)switch(c.type){case s:c.return=pe(c.value,c.length,u);return;case b:return ve([N(c,{value:C(c.value,"@","@"+a)})],i);case n:if(c.length)return D(u=c.props,(function(n){switch(z(n,i=/(::plac\w+|:read-\w+)/)){case":read-only":case":read-write":P(N(c,{props:[C(n,/:(read-\w+)/,":"+r+"$1")]}));P(N(c,{props:[n]}));x(c,{props:E(u,i)});break;case"::placeholder":P(N(c,{props:[C(n,/:(plac\w+)/,":"+a+"input-$1")]}));P(N(c,{props:[C(n,/:(plac\w+)/,":"+r+"$1")]}));P(N(c,{props:[C(n,/:(plac\w+)/,e+"input-$1")]}));P(N(c,{props:[n]}));x(c,{props:E(u,i)});break}return ""}))}}
|
|
988
908
|
|
|
989
|
-
|
|
909
|
+
const SEED$1 = 5381;
|
|
990
910
|
// When we have separate strings it's useful to run a progressive
|
|
991
911
|
// version of djb2 where we pretend that we're still looping over
|
|
992
912
|
// the same string
|
|
993
|
-
|
|
994
|
-
|
|
913
|
+
const phash = (h, x) => {
|
|
914
|
+
let i = x.length;
|
|
995
915
|
while (i) {
|
|
996
916
|
h = (h * 33) ^ x.charCodeAt(--i);
|
|
997
917
|
}
|
|
998
918
|
return h;
|
|
999
919
|
};
|
|
1000
920
|
// This is a djb2 hashing function
|
|
1001
|
-
|
|
921
|
+
const hash = (x) => {
|
|
1002
922
|
return phash(SEED$1, x);
|
|
1003
923
|
};
|
|
1004
924
|
|
|
1005
|
-
|
|
925
|
+
const AMP_REGEX = /&/g;
|
|
1006
926
|
// Character codes for fast comparison
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
927
|
+
const DOUBLE_QUOTE = 34; // "
|
|
928
|
+
const SINGLE_QUOTE = 39; // '
|
|
929
|
+
const SLASH = 47; // /
|
|
930
|
+
const ASTERISK = 42; // *
|
|
931
|
+
const BACKSLASH = 92; // \
|
|
932
|
+
const OPEN_BRACE = 123; // {
|
|
933
|
+
const CLOSE_BRACE = 125; // }
|
|
934
|
+
const SEMICOLON = 59; // ;
|
|
935
|
+
const NEWLINE = 10; // \n
|
|
936
|
+
const OPEN_PAREN = 40; // (
|
|
937
|
+
const CLOSE_PAREN = 41; // )
|
|
1018
938
|
/**
|
|
1019
939
|
* Strips JS-style line comments (//) from CSS, handling comments anywhere
|
|
1020
940
|
* in the line while preserving strings, url() contents, and valid CSS.
|
|
@@ -1024,14 +944,14 @@
|
|
|
1024
944
|
// Fast path: no // means no line comments
|
|
1025
945
|
if (css.indexOf('//') === -1)
|
|
1026
946
|
return css;
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
947
|
+
const len = css.length;
|
|
948
|
+
const parts = [];
|
|
949
|
+
let start = 0;
|
|
950
|
+
let i = 0;
|
|
951
|
+
let inString = 0; // 0 = none, DOUBLE_QUOTE or SINGLE_QUOTE when in string
|
|
952
|
+
let urlDepth = 0; // Track nesting depth inside url()
|
|
1033
953
|
while (i < len) {
|
|
1034
|
-
|
|
954
|
+
const code = css.charCodeAt(i);
|
|
1035
955
|
// Track string state
|
|
1036
956
|
if ((code === DOUBLE_QUOTE || code === SINGLE_QUOTE) &&
|
|
1037
957
|
(i === 0 || css.charCodeAt(i - 1) !== BACKSLASH)) {
|
|
@@ -1115,12 +1035,12 @@
|
|
|
1115
1035
|
// Fast path: no closing brace means can't have unbalanced braces
|
|
1116
1036
|
if (css.indexOf('}') === -1)
|
|
1117
1037
|
return false;
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
for (
|
|
1123
|
-
|
|
1038
|
+
const len = css.length;
|
|
1039
|
+
let depth = 0;
|
|
1040
|
+
let inString = 0; // 0 = none, char code when in string
|
|
1041
|
+
let inComment = false;
|
|
1042
|
+
for (let i = 0; i < len; i++) {
|
|
1043
|
+
const code = css.charCodeAt(i);
|
|
1124
1044
|
// Handle CSS comments
|
|
1125
1045
|
if (inString === 0 && !inComment && code === SLASH && css.charCodeAt(i + 1) === ASTERISK) {
|
|
1126
1046
|
inComment = true;
|
|
@@ -1169,14 +1089,14 @@
|
|
|
1169
1089
|
if (!hasUnbalancedBraces(css)) {
|
|
1170
1090
|
return css;
|
|
1171
1091
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
for (
|
|
1179
|
-
|
|
1092
|
+
const len = css.length;
|
|
1093
|
+
let result = '';
|
|
1094
|
+
let declStart = 0;
|
|
1095
|
+
let braceDepth = 0;
|
|
1096
|
+
let inString = 0;
|
|
1097
|
+
let inComment = false;
|
|
1098
|
+
for (let i = 0; i < len; i++) {
|
|
1099
|
+
const code = css.charCodeAt(i);
|
|
1180
1100
|
// Handle CSS comments
|
|
1181
1101
|
if (inString === 0 && !inComment && code === SLASH && css.charCodeAt(i + 1) === ASTERISK) {
|
|
1182
1102
|
inComment = true;
|
|
@@ -1210,9 +1130,9 @@
|
|
|
1210
1130
|
braceDepth--;
|
|
1211
1131
|
if (braceDepth < 0) {
|
|
1212
1132
|
// Extra closing brace - skip to next semicolon or newline
|
|
1213
|
-
|
|
1133
|
+
let skipEnd = i + 1;
|
|
1214
1134
|
while (skipEnd < len) {
|
|
1215
|
-
|
|
1135
|
+
const skipCode = css.charCodeAt(skipEnd);
|
|
1216
1136
|
if (skipCode === SEMICOLON || skipCode === NEWLINE)
|
|
1217
1137
|
break;
|
|
1218
1138
|
skipEnd++;
|
|
@@ -1236,7 +1156,7 @@
|
|
|
1236
1156
|
}
|
|
1237
1157
|
// Add remaining valid content
|
|
1238
1158
|
if (declStart < len) {
|
|
1239
|
-
|
|
1159
|
+
const remaining = css.substring(declStart);
|
|
1240
1160
|
if (!hasUnbalancedBraces(remaining)) {
|
|
1241
1161
|
result += remaining;
|
|
1242
1162
|
}
|
|
@@ -1248,14 +1168,14 @@
|
|
|
1248
1168
|
* Takes into account media queries by recursing through child rules if they are present.
|
|
1249
1169
|
*/
|
|
1250
1170
|
function recursivelySetNamepace(compiled, namespace) {
|
|
1251
|
-
return compiled.map(
|
|
1171
|
+
return compiled.map(rule => {
|
|
1252
1172
|
if (rule.type === 'rule') {
|
|
1253
1173
|
// add the namespace to the start
|
|
1254
|
-
rule.value =
|
|
1174
|
+
rule.value = `${namespace} ${rule.value}`;
|
|
1255
1175
|
// add the namespace after each comma for subsequent selectors.
|
|
1256
|
-
rule.value = rule.value.replaceAll(',',
|
|
1257
|
-
rule.props = rule.props.map(
|
|
1258
|
-
return
|
|
1176
|
+
rule.value = rule.value.replaceAll(',', `,${namespace} `);
|
|
1177
|
+
rule.props = rule.props.map(prop => {
|
|
1178
|
+
return `${namespace} ${prop}`;
|
|
1259
1179
|
});
|
|
1260
1180
|
}
|
|
1261
1181
|
if (Array.isArray(rule.children) && rule.type !== '@keyframes') {
|
|
@@ -1264,12 +1184,11 @@
|
|
|
1264
1184
|
return rule;
|
|
1265
1185
|
});
|
|
1266
1186
|
}
|
|
1267
|
-
function createStylisInstance(
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
var selfReferenceReplacer = function (match, offset, string) {
|
|
1187
|
+
function createStylisInstance({ options = EMPTY_OBJECT, plugins = EMPTY_ARRAY, } = EMPTY_OBJECT) {
|
|
1188
|
+
let _componentId;
|
|
1189
|
+
let _selector;
|
|
1190
|
+
let _selectorRegexp;
|
|
1191
|
+
const selfReferenceReplacer = (match, offset, string) => {
|
|
1273
1192
|
if (
|
|
1274
1193
|
/**
|
|
1275
1194
|
* We only want to refer to the static class directly if the selector is part of a
|
|
@@ -1278,7 +1197,7 @@
|
|
|
1278
1197
|
string.startsWith(_selector) &&
|
|
1279
1198
|
string.endsWith(_selector) &&
|
|
1280
1199
|
string.replaceAll(_selector, '').length > 0) {
|
|
1281
|
-
return
|
|
1200
|
+
return `.${_componentId}`;
|
|
1282
1201
|
}
|
|
1283
1202
|
return match;
|
|
1284
1203
|
};
|
|
@@ -1294,11 +1213,11 @@
|
|
|
1294
1213
|
*
|
|
1295
1214
|
* https://github.com/thysultan/stylis.js/tree/v4.0.2#abstract-syntax-structure
|
|
1296
1215
|
*/
|
|
1297
|
-
|
|
1216
|
+
const selfReferenceReplacementPlugin = element => {
|
|
1298
1217
|
if (element.type === n && element.value.includes('&')) {
|
|
1299
1218
|
// Lazy RegExp creation: only allocate when self-reference pattern is actually used
|
|
1300
1219
|
if (!_selectorRegexp) {
|
|
1301
|
-
_selectorRegexp = new RegExp(
|
|
1220
|
+
_selectorRegexp = new RegExp(`\\${_selector}\\b`, 'g');
|
|
1302
1221
|
}
|
|
1303
1222
|
element.props[0] = element.props[0]
|
|
1304
1223
|
// catch any hanging references that stylis missed
|
|
@@ -1306,7 +1225,7 @@
|
|
|
1306
1225
|
.replace(_selectorRegexp, selfReferenceReplacer);
|
|
1307
1226
|
}
|
|
1308
1227
|
};
|
|
1309
|
-
|
|
1228
|
+
const middlewares = plugins.slice();
|
|
1310
1229
|
middlewares.push(selfReferenceReplacementPlugin);
|
|
1311
1230
|
/**
|
|
1312
1231
|
* Enables automatic vendor-prefixing for styles.
|
|
@@ -1318,24 +1237,21 @@
|
|
|
1318
1237
|
// Pre-build the middleware chain once to avoid allocating closures,
|
|
1319
1238
|
// arrays, and middleware wrappers on every stringifyRules call.
|
|
1320
1239
|
// Safe because JS is single-threaded and _stack is consumed before next call.
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1240
|
+
let _stack = [];
|
|
1241
|
+
const _middleware = he(middlewares.concat(we(value => _stack.push(value))));
|
|
1242
|
+
const stringifyRules = (css, selector = '',
|
|
1324
1243
|
/**
|
|
1325
1244
|
* This "prefix" referes to a _selector_ prefix.
|
|
1326
1245
|
*/
|
|
1327
|
-
prefix, componentId) {
|
|
1328
|
-
if (selector === void 0) { selector = ''; }
|
|
1329
|
-
if (prefix === void 0) { prefix = ''; }
|
|
1330
|
-
if (componentId === void 0) { componentId = '&'; }
|
|
1246
|
+
prefix = '', componentId = '&') => {
|
|
1331
1247
|
// stylis has no concept of state to be passed to plugins
|
|
1332
1248
|
// but since JS is single-threaded, we can rely on that to ensure
|
|
1333
1249
|
// these properties stay in sync with the current stylis run
|
|
1334
1250
|
_componentId = componentId;
|
|
1335
1251
|
_selector = selector;
|
|
1336
1252
|
_selectorRegexp = undefined; // Reset for lazy creation per call
|
|
1337
|
-
|
|
1338
|
-
|
|
1253
|
+
const flatCSS = sanitizeCSS(stripLineComments(css));
|
|
1254
|
+
let compiled = ue(prefix || selector ? `${prefix} ${selector} { ${flatCSS} }` : flatCSS);
|
|
1339
1255
|
if (options.namespace) {
|
|
1340
1256
|
compiled = recursivelySetNamepace(compiled, options.namespace);
|
|
1341
1257
|
}
|
|
@@ -1345,7 +1261,7 @@
|
|
|
1345
1261
|
};
|
|
1346
1262
|
stringifyRules.hash = plugins.length
|
|
1347
1263
|
? plugins
|
|
1348
|
-
.reduce(
|
|
1264
|
+
.reduce((acc, plugin) => {
|
|
1349
1265
|
if (!plugin.name) {
|
|
1350
1266
|
throwStyledComponentsError(15);
|
|
1351
1267
|
}
|
|
@@ -1356,18 +1272,18 @@
|
|
|
1356
1272
|
return stringifyRules;
|
|
1357
1273
|
}
|
|
1358
1274
|
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1275
|
+
const mainSheet = new StyleSheet();
|
|
1276
|
+
const mainStylis = createStylisInstance();
|
|
1277
|
+
const defaultContextValue = {
|
|
1362
1278
|
shouldForwardProp: undefined,
|
|
1363
1279
|
styleSheet: mainSheet,
|
|
1364
1280
|
stylis: mainStylis,
|
|
1365
1281
|
};
|
|
1366
1282
|
// Create context only if createContext is available, otherwise create a fallback
|
|
1367
|
-
|
|
1283
|
+
const StyleSheetContext = React.createContext(defaultContextValue)
|
|
1368
1284
|
;
|
|
1369
|
-
|
|
1370
|
-
|
|
1285
|
+
const StyleSheetConsumer = StyleSheetContext.Consumer;
|
|
1286
|
+
const StylisContext = React.createContext(undefined)
|
|
1371
1287
|
;
|
|
1372
1288
|
function useStyleSheetContext() {
|
|
1373
1289
|
// Skip useContext if we're in an RSC environment without context support
|
|
@@ -1378,9 +1294,9 @@
|
|
|
1378
1294
|
if (!React.useMemo) {
|
|
1379
1295
|
return props.children;
|
|
1380
1296
|
}
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1297
|
+
const { styleSheet } = useStyleSheetContext();
|
|
1298
|
+
const resolvedStyleSheet = React.useMemo(() => {
|
|
1299
|
+
let sheet = styleSheet;
|
|
1384
1300
|
if (props.sheet) {
|
|
1385
1301
|
sheet = props.sheet;
|
|
1386
1302
|
}
|
|
@@ -1395,32 +1311,30 @@
|
|
|
1395
1311
|
}
|
|
1396
1312
|
return sheet;
|
|
1397
1313
|
}, [props.disableCSSOMInjection, props.nonce, props.sheet, props.target, styleSheet]);
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
}, [props.enableVendorPrefixes, props.namespace, props.stylisPlugins]);
|
|
1404
|
-
var styleSheetContextValue = React.useMemo(function () { return ({
|
|
1314
|
+
const stylis = React.useMemo(() => createStylisInstance({
|
|
1315
|
+
options: { namespace: props.namespace, prefix: props.enableVendorPrefixes },
|
|
1316
|
+
plugins: props.stylisPlugins,
|
|
1317
|
+
}), [props.enableVendorPrefixes, props.namespace, props.stylisPlugins]);
|
|
1318
|
+
const styleSheetContextValue = React.useMemo(() => ({
|
|
1405
1319
|
shouldForwardProp: props.shouldForwardProp,
|
|
1406
1320
|
styleSheet: resolvedStyleSheet,
|
|
1407
|
-
stylis
|
|
1408
|
-
})
|
|
1321
|
+
stylis,
|
|
1322
|
+
}), [props.shouldForwardProp, resolvedStyleSheet, stylis]);
|
|
1409
1323
|
return (React.createElement(StyleSheetContext.Provider, { value: styleSheetContextValue },
|
|
1410
1324
|
React.createElement(StylisContext.Provider, { value: stylis }, props.children)));
|
|
1411
1325
|
}
|
|
1412
1326
|
|
|
1413
1327
|
// Create context only if createContext is available, otherwise create a fallback
|
|
1414
|
-
|
|
1328
|
+
const ThemeContext = React.createContext(undefined)
|
|
1415
1329
|
;
|
|
1416
|
-
|
|
1330
|
+
const ThemeConsumer = ThemeContext.Consumer;
|
|
1417
1331
|
function mergeTheme(theme, outerTheme) {
|
|
1418
1332
|
if (!theme) {
|
|
1419
1333
|
throw throwStyledComponentsError(14);
|
|
1420
1334
|
}
|
|
1421
1335
|
if (isFunction(theme)) {
|
|
1422
|
-
|
|
1423
|
-
|
|
1336
|
+
const themeFn = theme;
|
|
1337
|
+
const mergedTheme = themeFn(outerTheme);
|
|
1424
1338
|
if ((mergedTheme === null || Array.isArray(mergedTheme) || typeof mergedTheme !== 'object')) {
|
|
1425
1339
|
throw throwStyledComponentsError(7);
|
|
1426
1340
|
}
|
|
@@ -1429,7 +1343,7 @@
|
|
|
1429
1343
|
if (Array.isArray(theme) || typeof theme !== 'object') {
|
|
1430
1344
|
throw throwStyledComponentsError(8);
|
|
1431
1345
|
}
|
|
1432
|
-
return outerTheme ?
|
|
1346
|
+
return outerTheme ? Object.assign(Object.assign({}, outerTheme), theme) : theme;
|
|
1433
1347
|
}
|
|
1434
1348
|
/**
|
|
1435
1349
|
* Returns the current theme (as provided by the closest ancestor `ThemeProvider`.)
|
|
@@ -1440,7 +1354,7 @@
|
|
|
1440
1354
|
*/
|
|
1441
1355
|
function useTheme() {
|
|
1442
1356
|
// Skip useContext if we're in an RSC environment without context support
|
|
1443
|
-
|
|
1357
|
+
const theme = React.useContext(ThemeContext) ;
|
|
1444
1358
|
if (!theme) {
|
|
1445
1359
|
throw throwStyledComponentsError(18);
|
|
1446
1360
|
}
|
|
@@ -1450,43 +1364,39 @@
|
|
|
1450
1364
|
* Provide a theme to an entire react component tree via context
|
|
1451
1365
|
*/
|
|
1452
1366
|
function ThemeProvider(props) {
|
|
1453
|
-
|
|
1454
|
-
|
|
1367
|
+
const outerTheme = React.useContext(ThemeContext);
|
|
1368
|
+
const themeContext = React.useMemo(() => mergeTheme(props.theme, outerTheme), [props.theme, outerTheme]);
|
|
1455
1369
|
if (!props.children) {
|
|
1456
1370
|
return null;
|
|
1457
1371
|
}
|
|
1458
1372
|
return React.createElement(ThemeContext.Provider, { value: themeContext }, props.children);
|
|
1459
1373
|
}
|
|
1460
1374
|
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1375
|
+
const invalidHookCallRe = /invalid hook call/i;
|
|
1376
|
+
const seen = new Set();
|
|
1377
|
+
const checkDynamicCreation = (displayName, componentId) => {
|
|
1464
1378
|
{
|
|
1465
|
-
|
|
1466
|
-
|
|
1379
|
+
const parsedIdString = componentId ? ` with the id of "${componentId}"` : '';
|
|
1380
|
+
const message = `The component ${displayName}${parsedIdString} has been created dynamically.\n` +
|
|
1467
1381
|
"You may see this warning because you've called styled inside another component.\n" +
|
|
1468
1382
|
'To resolve this only create new StyledComponents outside of any render method and function component.\n' +
|
|
1469
1383
|
'See https://styled-components.com/docs/basics#define-styled-components-outside-of-the-render-method for more info.\n';
|
|
1470
1384
|
// If a hook is called outside of a component:
|
|
1471
1385
|
// React 17 and earlier throw an error
|
|
1472
1386
|
// React 18 and above use console.error
|
|
1473
|
-
|
|
1387
|
+
const originalConsoleError = console.error;
|
|
1474
1388
|
try {
|
|
1475
|
-
|
|
1476
|
-
console.error =
|
|
1477
|
-
var consoleErrorArgs = [];
|
|
1478
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1479
|
-
consoleErrorArgs[_i - 1] = arguments[_i];
|
|
1480
|
-
}
|
|
1389
|
+
let didNotCallInvalidHook = true;
|
|
1390
|
+
console.error = (consoleErrorMessage, ...consoleErrorArgs) => {
|
|
1481
1391
|
// The error here is expected, since we're expecting anything that uses `checkDynamicCreation` to
|
|
1482
1392
|
// be called outside of a React component.
|
|
1483
1393
|
if (invalidHookCallRe.test(consoleErrorMessage)) {
|
|
1484
|
-
|
|
1394
|
+
didNotCallInvalidHook = false;
|
|
1485
1395
|
// This shouldn't happen, but resets `warningSeen` if we had this error happen intermittently
|
|
1486
|
-
seen.delete(
|
|
1396
|
+
seen.delete(message);
|
|
1487
1397
|
}
|
|
1488
1398
|
else {
|
|
1489
|
-
|
|
1399
|
+
originalConsoleError(consoleErrorMessage, ...consoleErrorArgs);
|
|
1490
1400
|
}
|
|
1491
1401
|
};
|
|
1492
1402
|
// We purposefully call a hook outside of a component and expect it to throw
|
|
@@ -1495,9 +1405,9 @@
|
|
|
1495
1405
|
if (typeof React.useState === 'function') {
|
|
1496
1406
|
React.useState(null);
|
|
1497
1407
|
}
|
|
1498
|
-
if (
|
|
1499
|
-
console.warn(
|
|
1500
|
-
seen.add(
|
|
1408
|
+
if (didNotCallInvalidHook && !seen.has(message)) {
|
|
1409
|
+
console.warn(message);
|
|
1410
|
+
seen.add(message);
|
|
1501
1411
|
}
|
|
1502
1412
|
}
|
|
1503
1413
|
catch (error) {
|
|
@@ -1505,30 +1415,29 @@
|
|
|
1505
1415
|
// be called outside of a React component.
|
|
1506
1416
|
if (invalidHookCallRe.test(error.message)) {
|
|
1507
1417
|
// This shouldn't happen, but resets `warningSeen` if we had this error happen intermittently
|
|
1508
|
-
seen.delete(
|
|
1418
|
+
seen.delete(message);
|
|
1509
1419
|
}
|
|
1510
1420
|
}
|
|
1511
1421
|
finally {
|
|
1512
|
-
console.error =
|
|
1422
|
+
console.error = originalConsoleError;
|
|
1513
1423
|
}
|
|
1514
1424
|
}
|
|
1515
1425
|
};
|
|
1516
1426
|
|
|
1517
|
-
function determineTheme(props, providedTheme, defaultProps) {
|
|
1518
|
-
if (defaultProps === void 0) { defaultProps = EMPTY_OBJECT; }
|
|
1427
|
+
function determineTheme(props, providedTheme, defaultProps = EMPTY_OBJECT) {
|
|
1519
1428
|
return (props.theme !== defaultProps.theme && props.theme) || providedTheme || defaultProps.theme;
|
|
1520
1429
|
}
|
|
1521
1430
|
|
|
1522
|
-
|
|
1431
|
+
const AD_REPLACER_R = /(a)(d)/gi;
|
|
1523
1432
|
/* This is the "capacity" of our alphabet i.e. 2x26 for all letters plus their capitalised
|
|
1524
1433
|
* counterparts */
|
|
1525
|
-
|
|
1434
|
+
const charsLength = 52;
|
|
1526
1435
|
/* start at 75 for 'a' until 'z' (25) and then start at 65 for capitalised letters */
|
|
1527
|
-
|
|
1436
|
+
const getAlphabeticChar = (code) => String.fromCharCode(code + (code > 25 ? 39 : 97));
|
|
1528
1437
|
/* input a number, usually a hash and convert it to base-52 */
|
|
1529
1438
|
function generateAlphabeticName(code) {
|
|
1530
|
-
|
|
1531
|
-
|
|
1439
|
+
let name = '';
|
|
1440
|
+
let x;
|
|
1532
1441
|
/* get a char and divide by alphabet-length */
|
|
1533
1442
|
for (x = Math.abs(code); x > charsLength; x = (x / charsLength) | 0) {
|
|
1534
1443
|
name = getAlphabeticChar(x % charsLength) + name;
|
|
@@ -1541,8 +1450,8 @@
|
|
|
1541
1450
|
}
|
|
1542
1451
|
|
|
1543
1452
|
function interleave(strings, interpolations) {
|
|
1544
|
-
|
|
1545
|
-
for (
|
|
1453
|
+
const result = [strings[0]];
|
|
1454
|
+
for (let i = 0, len = interpolations.length; i < len; i += 1) {
|
|
1546
1455
|
result.push(interpolations[i], strings[i + 1]);
|
|
1547
1456
|
}
|
|
1548
1457
|
return result;
|
|
@@ -1552,21 +1461,16 @@
|
|
|
1552
1461
|
* Used when flattening object styles to determine if we should
|
|
1553
1462
|
* expand an array of styles.
|
|
1554
1463
|
*/
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
};
|
|
1558
|
-
function css(styles) {
|
|
1559
|
-
var interpolations = [];
|
|
1560
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1561
|
-
interpolations[_i - 1] = arguments[_i];
|
|
1562
|
-
}
|
|
1464
|
+
const addTag = (arg) => Object.assign(arg, { isCss: true });
|
|
1465
|
+
function css(styles, ...interpolations) {
|
|
1563
1466
|
if (isFunction(styles) || isPlainObject(styles)) {
|
|
1564
|
-
|
|
1565
|
-
return addTag(flatten(interleave(EMPTY_ARRAY,
|
|
1566
|
-
styleFunctionOrObject
|
|
1567
|
-
|
|
1467
|
+
const styleFunctionOrObject = styles;
|
|
1468
|
+
return addTag(flatten(interleave(EMPTY_ARRAY, [
|
|
1469
|
+
styleFunctionOrObject,
|
|
1470
|
+
...interpolations,
|
|
1471
|
+
])));
|
|
1568
1472
|
}
|
|
1569
|
-
|
|
1473
|
+
const styleStringArray = styles;
|
|
1570
1474
|
if (interpolations.length === 0 &&
|
|
1571
1475
|
styleStringArray.length === 1 &&
|
|
1572
1476
|
typeof styleStringArray[0] === 'string') {
|
|
@@ -1575,28 +1479,24 @@
|
|
|
1575
1479
|
return addTag(flatten(interleave(styleStringArray, interpolations)));
|
|
1576
1480
|
}
|
|
1577
1481
|
|
|
1578
|
-
function createGlobalStyle(strings) {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
}
|
|
1583
|
-
var rules = css.apply(void 0, __spreadArray([strings], interpolations, false));
|
|
1584
|
-
var styledComponentId = "sc-global-".concat(generateComponentId(JSON.stringify(rules)));
|
|
1585
|
-
var globalStyle = new GlobalStyle(rules, styledComponentId);
|
|
1482
|
+
function createGlobalStyle(strings, ...interpolations) {
|
|
1483
|
+
const rules = css(strings, ...interpolations);
|
|
1484
|
+
const styledComponentId = `sc-global-${generateComponentId(JSON.stringify(rules))}`;
|
|
1485
|
+
const globalStyle = new GlobalStyle(rules, styledComponentId);
|
|
1586
1486
|
{
|
|
1587
1487
|
checkDynamicCreation(styledComponentId);
|
|
1588
1488
|
}
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1489
|
+
const GlobalStyleComponent = props => {
|
|
1490
|
+
const ssc = useStyleSheetContext();
|
|
1491
|
+
const theme = React.useContext(ThemeContext) ;
|
|
1592
1492
|
// Each mount needs a unique instance ID for the shared-group instanceRules cache.
|
|
1593
1493
|
// false is a build-time constant: the dead branch is entirely eliminated,
|
|
1594
1494
|
// so React never sees a conditional hook call.
|
|
1595
1495
|
// Server bundle: direct allocation (one-shot renders, no stability needed).
|
|
1596
1496
|
// Browser bundle: useRef for stable ID across re-renders + useLayoutEffect cleanup.
|
|
1597
|
-
|
|
1497
|
+
let instance;
|
|
1598
1498
|
{
|
|
1599
|
-
|
|
1499
|
+
const instanceRef = React.useRef(null);
|
|
1600
1500
|
if (instanceRef.current === null) {
|
|
1601
1501
|
instanceRef.current = ssc.styleSheet.allocateGSInstance(styledComponentId);
|
|
1602
1502
|
}
|
|
@@ -1604,15 +1504,20 @@
|
|
|
1604
1504
|
}
|
|
1605
1505
|
if (// @ts-expect-error invariant check
|
|
1606
1506
|
React.Children.count(props.children)) {
|
|
1607
|
-
console.warn(
|
|
1608
|
-
}
|
|
1609
|
-
if (rules.some(
|
|
1610
|
-
console.warn(
|
|
1611
|
-
}
|
|
1612
|
-
// Render styles during component execution for
|
|
1613
|
-
//
|
|
1614
|
-
//
|
|
1615
|
-
//
|
|
1507
|
+
console.warn(`The global style component ${styledComponentId} was given child JSX. createGlobalStyle does not render children.`);
|
|
1508
|
+
}
|
|
1509
|
+
if (rules.some(rule => typeof rule === 'string' && rule.indexOf('@import') !== -1)) {
|
|
1510
|
+
console.warn(`Please do not use @import CSS syntax in createGlobalStyle at this time, as the CSSOM APIs we use in production do not handle it well. Instead, we recommend using a library such as react-helmet to inject a typical <link> meta tag to the stylesheet, or simply embedding it manually in your index.html <head> section for a simpler app.`);
|
|
1511
|
+
}
|
|
1512
|
+
// Render styles during component execution for RSC or explicit ServerStyleSheet.
|
|
1513
|
+
// Gate on IS_RSC or styleSheet.server (runtime flag from ServerStyleSheet),
|
|
1514
|
+
// NOT on false alone. The server build sets false=true and eliminates
|
|
1515
|
+
// useLayoutEffect, so if we rendered here without cleanup, styles would
|
|
1516
|
+
// accumulate unboundedly in jsdom test environments (O(n²) regression).
|
|
1517
|
+
// On a real server without ServerStyleSheet, VirtualTag is used and styles are
|
|
1518
|
+
// discarded anyway, so skipping this path has no functional impact.
|
|
1519
|
+
// Turbopack resolves the browser entry for SSR, so false is false there;
|
|
1520
|
+
// styleSheet.server handles that case at runtime.
|
|
1616
1521
|
if (ssc.styleSheet.server) {
|
|
1617
1522
|
renderStyles(instance, props, ssc.styleSheet, theme, ssc.stylis);
|
|
1618
1523
|
}
|
|
@@ -1624,14 +1529,14 @@
|
|
|
1624
1529
|
// for initial injection and unmount cleanup, but we use a narrow deps array
|
|
1625
1530
|
// to avoid unnecessary effect re-runs on every render.
|
|
1626
1531
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1627
|
-
|
|
1532
|
+
const effectDeps = globalStyle.isStatic
|
|
1628
1533
|
? [instance, ssc.styleSheet]
|
|
1629
1534
|
: [instance, props, ssc.styleSheet, theme, ssc.stylis];
|
|
1630
|
-
React.useLayoutEffect(
|
|
1535
|
+
React.useLayoutEffect(() => {
|
|
1631
1536
|
if (!ssc.styleSheet.server) {
|
|
1632
1537
|
renderStyles(instance, props, ssc.styleSheet, theme, ssc.stylis);
|
|
1633
1538
|
}
|
|
1634
|
-
return
|
|
1539
|
+
return () => {
|
|
1635
1540
|
globalStyle.removeStyles(instance, ssc.styleSheet);
|
|
1636
1541
|
};
|
|
1637
1542
|
}, effectDeps);
|
|
@@ -1648,7 +1553,7 @@
|
|
|
1648
1553
|
globalStyle.renderStyles(instance, STATIC_EXECUTION_CONTEXT, styleSheet, stylis);
|
|
1649
1554
|
}
|
|
1650
1555
|
else {
|
|
1651
|
-
|
|
1556
|
+
const context = Object.assign(Object.assign({}, props), { theme: determineTheme(props, theme, GlobalStyleComponent.defaultProps) });
|
|
1652
1557
|
globalStyle.renderStyles(instance, context, styleSheet, stylis);
|
|
1653
1558
|
}
|
|
1654
1559
|
}
|
|
@@ -1657,11 +1562,11 @@
|
|
|
1657
1562
|
|
|
1658
1563
|
/** Shared recursive traversal — calls `leafFn` for each leaf, recurses for objects. */
|
|
1659
1564
|
function walkTheme(obj, varPrefix, result, leafFn, path) {
|
|
1660
|
-
for (
|
|
1661
|
-
|
|
1662
|
-
|
|
1565
|
+
for (const key in obj) {
|
|
1566
|
+
const val = obj[key];
|
|
1567
|
+
const fullPath = path ? path + '-' + key : key;
|
|
1663
1568
|
if (typeof val === 'object' && val !== null) {
|
|
1664
|
-
|
|
1569
|
+
const nested = {};
|
|
1665
1570
|
walkTheme(val, varPrefix, nested, leafFn, fullPath);
|
|
1666
1571
|
result[key] = nested;
|
|
1667
1572
|
}
|
|
@@ -1672,12 +1577,12 @@
|
|
|
1672
1577
|
}
|
|
1673
1578
|
/** Build `var(--prefix-a-b, fallback)` accessor object */
|
|
1674
1579
|
function buildVars(obj, varPrefix) {
|
|
1675
|
-
|
|
1676
|
-
walkTheme(obj, varPrefix, result,
|
|
1580
|
+
const result = {};
|
|
1581
|
+
walkTheme(obj, varPrefix, result, (fullPath, val) => {
|
|
1677
1582
|
{
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
for (
|
|
1583
|
+
const str = String(val);
|
|
1584
|
+
let depth = 0;
|
|
1585
|
+
for (let i = 0; i < str.length; i++) {
|
|
1681
1586
|
if (str.charCodeAt(i) === 40)
|
|
1682
1587
|
depth++;
|
|
1683
1588
|
else if (str.charCodeAt(i) === 41)
|
|
@@ -1686,7 +1591,7 @@
|
|
|
1686
1591
|
break;
|
|
1687
1592
|
}
|
|
1688
1593
|
if (depth !== 0) {
|
|
1689
|
-
console.warn(
|
|
1594
|
+
console.warn(`createTheme: value "${str}" at "${fullPath}" contains unbalanced parentheses and may break the var() fallback`);
|
|
1690
1595
|
}
|
|
1691
1596
|
}
|
|
1692
1597
|
return 'var(--' + varPrefix + fullPath + ', ' + val + ')';
|
|
@@ -1695,9 +1600,9 @@
|
|
|
1695
1600
|
}
|
|
1696
1601
|
/** Read computed CSS variable values from the DOM */
|
|
1697
1602
|
function resolveVars(obj, varPrefix, styles) {
|
|
1698
|
-
|
|
1699
|
-
walkTheme(obj, varPrefix, result,
|
|
1700
|
-
|
|
1603
|
+
const result = {};
|
|
1604
|
+
walkTheme(obj, varPrefix, result, (fullPath, val) => {
|
|
1605
|
+
const resolved = styles.getPropertyValue('--' + varPrefix + fullPath).trim();
|
|
1701
1606
|
return resolved || val;
|
|
1702
1607
|
});
|
|
1703
1608
|
return result;
|
|
@@ -1708,11 +1613,11 @@
|
|
|
1708
1613
|
* present in the original theme shape are traversed.
|
|
1709
1614
|
*/
|
|
1710
1615
|
function emitVarDeclarations(shape, theme, varPrefix, path) {
|
|
1711
|
-
|
|
1712
|
-
for (
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1616
|
+
let css = '';
|
|
1617
|
+
for (const key in shape) {
|
|
1618
|
+
const shapeVal = shape[key];
|
|
1619
|
+
const themeVal = theme[key];
|
|
1620
|
+
const fullPath = path ? path + '-' + key : key;
|
|
1716
1621
|
if (typeof shapeVal === 'object' && shapeVal !== null) {
|
|
1717
1622
|
if (typeof themeVal === 'object' && themeVal !== null) {
|
|
1718
1623
|
css += emitVarDeclarations(shapeVal, themeVal, varPrefix, fullPath);
|
|
@@ -1725,7 +1630,7 @@
|
|
|
1725
1630
|
return css;
|
|
1726
1631
|
}
|
|
1727
1632
|
/**
|
|
1728
|
-
* Create a theme
|
|
1633
|
+
* Create a theme backed by CSS custom properties, bridging `ThemeProvider` and CSS variables.
|
|
1729
1634
|
*
|
|
1730
1635
|
* Returns an object with the same shape as the input theme, but every leaf value
|
|
1731
1636
|
* is a `var(--prefix-*, fallback)` CSS string. Use these in styled component
|
|
@@ -1756,34 +1661,35 @@
|
|
|
1756
1661
|
*/
|
|
1757
1662
|
function createTheme(defaultTheme, options) {
|
|
1758
1663
|
var _a, _b;
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1664
|
+
const pfx = ((_a = options === null || options === void 0 ? void 0 : options.prefix) !== null && _a !== void 0 ? _a : 'sc') + '-';
|
|
1665
|
+
const sel = (_b = options === null || options === void 0 ? void 0 : options.selector) !== null && _b !== void 0 ? _b : ':root';
|
|
1666
|
+
const vars = buildVars(defaultTheme, pfx);
|
|
1667
|
+
const GlobalStyle = createGlobalStyle `
|
|
1668
|
+
${sel} {
|
|
1669
|
+
${(p) => emitVarDeclarations(defaultTheme, p.theme, pfx)}
|
|
1670
|
+
}
|
|
1671
|
+
`;
|
|
1763
1672
|
return Object.assign(vars, {
|
|
1764
|
-
GlobalStyle
|
|
1673
|
+
GlobalStyle,
|
|
1765
1674
|
raw: defaultTheme,
|
|
1766
|
-
resolve
|
|
1675
|
+
resolve(el) {
|
|
1767
1676
|
if (!IS_BROWSER) {
|
|
1768
1677
|
throw new Error('createTheme.resolve() is client-only');
|
|
1769
1678
|
}
|
|
1770
|
-
|
|
1679
|
+
const target = el !== null && el !== void 0 ? el : document.documentElement;
|
|
1771
1680
|
return resolveVars(defaultTheme, pfx, getComputedStyle(target));
|
|
1772
1681
|
},
|
|
1773
1682
|
});
|
|
1774
1683
|
}
|
|
1775
|
-
var templateObject_1;
|
|
1776
1684
|
|
|
1777
|
-
var _a
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
this
|
|
1782
|
-
|
|
1783
|
-
if (
|
|
1784
|
-
|
|
1785
|
-
if (!styleSheet.hasNameForId(_this.id, resolvedName)) {
|
|
1786
|
-
styleSheet.insertRules(_this.id, resolvedName, stylisInstance(_this.rules, resolvedName, '@keyframes'));
|
|
1685
|
+
var _a;
|
|
1686
|
+
class Keyframes {
|
|
1687
|
+
constructor(name, rules) {
|
|
1688
|
+
this[_a] = true;
|
|
1689
|
+
this.inject = (styleSheet, stylisInstance = mainStylis) => {
|
|
1690
|
+
const resolvedName = this.name + stylisInstance.hash;
|
|
1691
|
+
if (!styleSheet.hasNameForId(this.id, resolvedName)) {
|
|
1692
|
+
styleSheet.insertRules(this.id, resolvedName, stylisInstance(this.rules, resolvedName, '@keyframes'));
|
|
1787
1693
|
}
|
|
1788
1694
|
};
|
|
1789
1695
|
this.name = name;
|
|
@@ -1794,55 +1700,43 @@
|
|
|
1794
1700
|
// Uses getGroupForId directly (not StyleSheet.registerId) because
|
|
1795
1701
|
// GroupIDAllocator is pure JS — safe for native builds.
|
|
1796
1702
|
getGroupForId(this.id);
|
|
1797
|
-
setToString(this,
|
|
1798
|
-
throw throwStyledComponentsError(12, String(
|
|
1703
|
+
setToString(this, () => {
|
|
1704
|
+
throw throwStyledComponentsError(12, String(this.name));
|
|
1799
1705
|
});
|
|
1800
1706
|
}
|
|
1801
|
-
|
|
1802
|
-
if (stylisInstance === void 0) { stylisInstance = mainStylis; }
|
|
1707
|
+
getName(stylisInstance = mainStylis) {
|
|
1803
1708
|
return this.name + stylisInstance.hash;
|
|
1804
|
-
};
|
|
1805
|
-
return Keyframes;
|
|
1806
|
-
}());
|
|
1807
|
-
_a$1 = KEYFRAMES_SYMBOL;
|
|
1808
|
-
|
|
1809
|
-
function keyframes(strings) {
|
|
1810
|
-
var interpolations = [];
|
|
1811
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1812
|
-
interpolations[_i - 1] = arguments[_i];
|
|
1813
1709
|
}
|
|
1710
|
+
}
|
|
1711
|
+
_a = KEYFRAMES_SYMBOL;
|
|
1712
|
+
|
|
1713
|
+
function keyframes(strings, ...interpolations) {
|
|
1814
1714
|
/* Warning if you've used keyframes on React Native */
|
|
1815
1715
|
if (typeof navigator !== 'undefined' &&
|
|
1816
1716
|
navigator.product === 'ReactNative') {
|
|
1817
1717
|
console.warn('`keyframes` cannot be used on ReactNative, only on the web. To do animation in ReactNative please use Animated.');
|
|
1818
1718
|
}
|
|
1819
|
-
|
|
1820
|
-
|
|
1719
|
+
const rules = joinStringArray(css(strings, ...interpolations));
|
|
1720
|
+
const name = generateComponentId(rules);
|
|
1821
1721
|
return new Keyframes(name, rules);
|
|
1822
1722
|
}
|
|
1823
1723
|
|
|
1824
|
-
var _a;
|
|
1825
|
-
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
|
1826
1724
|
// copied from react-is
|
|
1827
|
-
|
|
1828
|
-
|
|
1725
|
+
const REACT_MEMO_TYPE = Symbol.for('react.memo');
|
|
1726
|
+
const REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
|
|
1829
1727
|
/**
|
|
1830
1728
|
* Adapted from hoist-non-react-statics to avoid the react-is dependency.
|
|
1831
1729
|
*/
|
|
1832
|
-
|
|
1833
|
-
childContextTypes: true,
|
|
1730
|
+
const REACT_STATICS = {
|
|
1834
1731
|
contextType: true,
|
|
1835
|
-
contextTypes: true,
|
|
1836
1732
|
defaultProps: true,
|
|
1837
1733
|
displayName: true,
|
|
1838
|
-
getDefaultProps: true,
|
|
1839
1734
|
getDerivedStateFromError: true,
|
|
1840
1735
|
getDerivedStateFromProps: true,
|
|
1841
|
-
mixins: true,
|
|
1842
1736
|
propTypes: true,
|
|
1843
1737
|
type: true,
|
|
1844
1738
|
};
|
|
1845
|
-
|
|
1739
|
+
const KNOWN_STATICS = {
|
|
1846
1740
|
name: true,
|
|
1847
1741
|
length: true,
|
|
1848
1742
|
prototype: true,
|
|
@@ -1851,14 +1745,14 @@
|
|
|
1851
1745
|
arguments: true,
|
|
1852
1746
|
arity: true,
|
|
1853
1747
|
};
|
|
1854
|
-
|
|
1748
|
+
const FORWARD_REF_STATICS = {
|
|
1855
1749
|
$$typeof: true,
|
|
1856
1750
|
render: true,
|
|
1857
1751
|
defaultProps: true,
|
|
1858
1752
|
displayName: true,
|
|
1859
1753
|
propTypes: true,
|
|
1860
1754
|
};
|
|
1861
|
-
|
|
1755
|
+
const MEMO_STATICS = {
|
|
1862
1756
|
$$typeof: true,
|
|
1863
1757
|
compare: true,
|
|
1864
1758
|
defaultProps: true,
|
|
@@ -1866,13 +1760,13 @@
|
|
|
1866
1760
|
propTypes: true,
|
|
1867
1761
|
type: true,
|
|
1868
1762
|
};
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1763
|
+
const TYPE_STATICS = {
|
|
1764
|
+
[REACT_FORWARD_REF_TYPE]: FORWARD_REF_STATICS,
|
|
1765
|
+
[REACT_MEMO_TYPE]: MEMO_STATICS,
|
|
1766
|
+
};
|
|
1873
1767
|
// adapted from react-is
|
|
1874
1768
|
function isMemo(object) {
|
|
1875
|
-
|
|
1769
|
+
const $$typeofType = 'type' in object && object.type.$$typeof;
|
|
1876
1770
|
return $$typeofType === REACT_MEMO_TYPE;
|
|
1877
1771
|
}
|
|
1878
1772
|
function getStatics(component) {
|
|
@@ -1885,34 +1779,29 @@
|
|
|
1885
1779
|
? TYPE_STATICS[component['$$typeof']]
|
|
1886
1780
|
: REACT_STATICS;
|
|
1887
1781
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1782
|
+
const defineProperty = Object.defineProperty;
|
|
1783
|
+
const getOwnPropertyNames = Object.getOwnPropertyNames;
|
|
1784
|
+
const getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|
1785
|
+
const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
1786
|
+
const getPrototypeOf = Object.getPrototypeOf;
|
|
1787
|
+
const objectPrototype = Object.prototype;
|
|
1894
1788
|
function hoistNonReactStatics(targetComponent, sourceComponent, excludelist) {
|
|
1895
1789
|
if (typeof sourceComponent !== 'string') {
|
|
1896
1790
|
// don't hoist over string (html) components
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
}
|
|
1907
|
-
var targetStatics = getStatics(targetComponent);
|
|
1908
|
-
var sourceStatics = getStatics(sourceComponent);
|
|
1909
|
-
for (var i = 0; i < keys.length; ++i) {
|
|
1910
|
-
var key = keys[i];
|
|
1791
|
+
const inheritedComponent = getPrototypeOf(sourceComponent);
|
|
1792
|
+
if (inheritedComponent && inheritedComponent !== objectPrototype) {
|
|
1793
|
+
hoistNonReactStatics(targetComponent, inheritedComponent, excludelist);
|
|
1794
|
+
}
|
|
1795
|
+
const keys = getOwnPropertyNames(sourceComponent).concat(getOwnPropertySymbols(sourceComponent));
|
|
1796
|
+
const targetStatics = getStatics(targetComponent);
|
|
1797
|
+
const sourceStatics = getStatics(sourceComponent);
|
|
1798
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
1799
|
+
const key = keys[i];
|
|
1911
1800
|
if (!(key in KNOWN_STATICS) &&
|
|
1912
1801
|
!(excludelist && excludelist[key]) &&
|
|
1913
1802
|
!(sourceStatics && key in sourceStatics) &&
|
|
1914
1803
|
!(targetStatics && key in targetStatics)) {
|
|
1915
|
-
|
|
1804
|
+
const descriptor = getOwnPropertyDescriptor(sourceComponent, key);
|
|
1916
1805
|
try {
|
|
1917
1806
|
// Avoid failures from read-only properties
|
|
1918
1807
|
defineProperty(targetComponent, key, descriptor);
|
|
@@ -1927,102 +1816,98 @@
|
|
|
1927
1816
|
}
|
|
1928
1817
|
|
|
1929
1818
|
function withTheme(Component) {
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1819
|
+
const WithTheme = React.forwardRef((props, ref) => {
|
|
1820
|
+
const theme = React.useContext(ThemeContext) ;
|
|
1821
|
+
const themeProp = determineTheme(props, theme, Component.defaultProps);
|
|
1933
1822
|
if (themeProp === undefined) {
|
|
1934
|
-
console.warn(
|
|
1823
|
+
console.warn(`[withTheme] You are not using a ThemeProvider nor passing a theme prop or a theme in defaultProps in component class "${getComponentName(Component)}"`);
|
|
1935
1824
|
}
|
|
1936
|
-
return React.createElement(Component,
|
|
1825
|
+
return React.createElement(Component, Object.assign(Object.assign({}, props), { theme: themeProp, ref }));
|
|
1937
1826
|
});
|
|
1938
|
-
WithTheme.displayName =
|
|
1827
|
+
WithTheme.displayName = `WithTheme(${getComponentName(Component)})`;
|
|
1939
1828
|
return hoistNonReactStatics(WithTheme, Component);
|
|
1940
1829
|
}
|
|
1941
1830
|
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
this._emitSheetCSS = function () {
|
|
1947
|
-
var css = _this.instance.toString();
|
|
1831
|
+
class ServerStyleSheet {
|
|
1832
|
+
constructor({ nonce } = {}) {
|
|
1833
|
+
this._emitSheetCSS = () => {
|
|
1834
|
+
const css = this.instance.toString();
|
|
1948
1835
|
if (!css)
|
|
1949
1836
|
return '';
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
nonce &&
|
|
1953
|
-
|
|
1954
|
-
|
|
1837
|
+
const nonce = this.instance.options.nonce || getNonce();
|
|
1838
|
+
const attrs = [
|
|
1839
|
+
nonce && `nonce="${nonce}"`,
|
|
1840
|
+
`${SC_ATTR}="true"`,
|
|
1841
|
+
`${SC_ATTR_VERSION}="${SC_VERSION}"`,
|
|
1955
1842
|
];
|
|
1956
|
-
|
|
1957
|
-
return
|
|
1843
|
+
const htmlAttr = joinStringArray(attrs.filter(Boolean), ' ');
|
|
1844
|
+
return `<style ${htmlAttr}>${css}</style>`;
|
|
1958
1845
|
};
|
|
1959
|
-
this.getStyleTags =
|
|
1960
|
-
if (
|
|
1846
|
+
this.getStyleTags = () => {
|
|
1847
|
+
if (this.sealed) {
|
|
1961
1848
|
throw throwStyledComponentsError(2);
|
|
1962
1849
|
}
|
|
1963
|
-
return
|
|
1850
|
+
return this._emitSheetCSS();
|
|
1964
1851
|
};
|
|
1965
|
-
this.getStyleElement =
|
|
1966
|
-
|
|
1967
|
-
if (_this.sealed) {
|
|
1852
|
+
this.getStyleElement = () => {
|
|
1853
|
+
if (this.sealed) {
|
|
1968
1854
|
throw throwStyledComponentsError(2);
|
|
1969
1855
|
}
|
|
1970
|
-
|
|
1856
|
+
const css = this.instance.toString();
|
|
1971
1857
|
if (!css)
|
|
1972
1858
|
return [];
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1859
|
+
const props = {
|
|
1860
|
+
[SC_ATTR]: '',
|
|
1861
|
+
[SC_ATTR_VERSION]: SC_VERSION,
|
|
1862
|
+
dangerouslySetInnerHTML: {
|
|
1977
1863
|
__html: css,
|
|
1978
1864
|
},
|
|
1979
|
-
|
|
1980
|
-
|
|
1865
|
+
};
|
|
1866
|
+
const nonce = this.instance.options.nonce || getNonce();
|
|
1981
1867
|
if (nonce) {
|
|
1982
1868
|
props.nonce = nonce;
|
|
1983
1869
|
}
|
|
1984
1870
|
// v4 returned an array for this fn, so we'll do the same for v5 for backward compat
|
|
1985
|
-
return [React.createElement("style",
|
|
1871
|
+
return [React.createElement("style", Object.assign({}, props, { key: "sc-0-0" }))];
|
|
1986
1872
|
};
|
|
1987
|
-
this.seal =
|
|
1988
|
-
|
|
1873
|
+
this.seal = () => {
|
|
1874
|
+
this.sealed = true;
|
|
1989
1875
|
};
|
|
1990
|
-
this.instance = new StyleSheet({ isServer: true, nonce
|
|
1876
|
+
this.instance = new StyleSheet({ isServer: true, nonce });
|
|
1991
1877
|
this.sealed = false;
|
|
1992
1878
|
}
|
|
1993
|
-
|
|
1879
|
+
collectStyles(children) {
|
|
1994
1880
|
if (this.sealed) {
|
|
1995
1881
|
throw throwStyledComponentsError(2);
|
|
1996
1882
|
}
|
|
1997
1883
|
return React.createElement(StyleSheetManager, { sheet: this.instance }, children);
|
|
1998
|
-
}
|
|
1999
|
-
|
|
1884
|
+
}
|
|
1885
|
+
interleaveWithNodeStream(input) {
|
|
2000
1886
|
{
|
|
2001
1887
|
throw throwStyledComponentsError(3);
|
|
2002
1888
|
}
|
|
2003
|
-
}
|
|
2004
|
-
|
|
2005
|
-
}());
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
2006
1891
|
|
|
2007
|
-
|
|
2008
|
-
StyleSheet
|
|
2009
|
-
mainSheet
|
|
1892
|
+
const __PRIVATE__ = {
|
|
1893
|
+
StyleSheet,
|
|
1894
|
+
mainSheet,
|
|
2010
1895
|
};
|
|
2011
1896
|
|
|
2012
1897
|
/* Import singletons */
|
|
2013
1898
|
/* Warning if you've imported this file on React Native */
|
|
2014
1899
|
if (typeof navigator !== 'undefined' &&
|
|
2015
1900
|
navigator.product === 'ReactNative') {
|
|
2016
|
-
console.warn(
|
|
1901
|
+
console.warn(`It looks like you've imported 'styled-components' on React Native.\nPerhaps you're looking to import 'styled-components/native'?\nRead more about this at https://www.styled-components.com/docs/basics#react-native`);
|
|
2017
1902
|
}
|
|
2018
|
-
|
|
1903
|
+
const windowGlobalKey = `__sc-${SC_ATTR}__`;
|
|
2019
1904
|
/* Warning if there are several instances of styled-components */
|
|
2020
1905
|
if (typeof window !== 'undefined') {
|
|
2021
1906
|
// @ts-expect-error dynamic key not in window object
|
|
2022
1907
|
window[windowGlobalKey] || (window[windowGlobalKey] = 0);
|
|
2023
1908
|
// @ts-expect-error dynamic key not in window object
|
|
2024
1909
|
if (window[windowGlobalKey] === 1) {
|
|
2025
|
-
console.warn(
|
|
1910
|
+
console.warn(`It looks like there are several instances of 'styled-components' initialized in this application. This may cause dynamic styles to not render properly, errors during the rehydration process, a missing theme prop, and makes your application bigger without good reason.\n\nSee https://styled-components.com/docs/faqs#why-am-i-getting-a-warning-about-several-instances-of-module-on-the-page for more info.`);
|
|
2026
1911
|
}
|
|
2027
1912
|
// @ts-expect-error dynamic key not in window object
|
|
2028
1913
|
window[windowGlobalKey] += 1;
|
|
@@ -2069,17 +1954,17 @@
|
|
|
2069
1954
|
/* Z+1 */
|
|
2070
1955
|
);
|
|
2071
1956
|
|
|
2072
|
-
|
|
2073
|
-
var createWarnTooManyClasses = (
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
return
|
|
1957
|
+
const LIMIT = 200;
|
|
1958
|
+
var createWarnTooManyClasses = (displayName, componentId) => {
|
|
1959
|
+
let generatedClasses = {};
|
|
1960
|
+
let warningSeen = false;
|
|
1961
|
+
return (className) => {
|
|
2077
1962
|
if (!warningSeen) {
|
|
2078
1963
|
generatedClasses[className] = true;
|
|
2079
1964
|
if (Object.keys(generatedClasses).length >= LIMIT) {
|
|
2080
1965
|
// Unable to find latestRule in test environment.
|
|
2081
|
-
|
|
2082
|
-
console.warn(
|
|
1966
|
+
const parsedIdString = componentId ? ` with the id of "${componentId}"` : '';
|
|
1967
|
+
console.warn(`Over ${LIMIT} classes were generated for component ${displayName}${parsedIdString}.\n` +
|
|
2083
1968
|
'Consider using the attrs method, together with a style object for frequently changed styles.\n' +
|
|
2084
1969
|
'Example:\n' +
|
|
2085
1970
|
' const Component = styled.div.attrs(props => ({\n' +
|
|
@@ -2093,169 +1978,18 @@
|
|
|
2093
1978
|
}
|
|
2094
1979
|
}
|
|
2095
1980
|
};
|
|
2096
|
-
}
|
|
1981
|
+
};
|
|
2097
1982
|
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
'abbr',
|
|
2101
|
-
'address',
|
|
2102
|
-
'area',
|
|
2103
|
-
'article',
|
|
2104
|
-
'aside',
|
|
2105
|
-
'audio',
|
|
2106
|
-
'b',
|
|
2107
|
-
'bdi',
|
|
2108
|
-
'bdo',
|
|
2109
|
-
'blockquote',
|
|
2110
|
-
'body',
|
|
2111
|
-
'button',
|
|
2112
|
-
'br',
|
|
2113
|
-
'canvas',
|
|
2114
|
-
'caption',
|
|
2115
|
-
'cite',
|
|
2116
|
-
'code',
|
|
2117
|
-
'col',
|
|
2118
|
-
'colgroup',
|
|
2119
|
-
'data',
|
|
2120
|
-
'datalist',
|
|
2121
|
-
'dd',
|
|
2122
|
-
'del',
|
|
2123
|
-
'details',
|
|
2124
|
-
'dfn',
|
|
2125
|
-
'dialog',
|
|
2126
|
-
'div',
|
|
2127
|
-
'dl',
|
|
2128
|
-
'dt',
|
|
2129
|
-
'em',
|
|
2130
|
-
'embed',
|
|
2131
|
-
'fieldset',
|
|
2132
|
-
'figcaption',
|
|
2133
|
-
'figure',
|
|
2134
|
-
'footer',
|
|
2135
|
-
'form',
|
|
2136
|
-
'h1',
|
|
2137
|
-
'h2',
|
|
2138
|
-
'h3',
|
|
2139
|
-
'h4',
|
|
2140
|
-
'h5',
|
|
2141
|
-
'h6',
|
|
2142
|
-
'header',
|
|
2143
|
-
'hgroup',
|
|
2144
|
-
'hr',
|
|
2145
|
-
'html',
|
|
2146
|
-
'i',
|
|
2147
|
-
'iframe',
|
|
2148
|
-
'img',
|
|
2149
|
-
'input',
|
|
2150
|
-
'ins',
|
|
2151
|
-
'kbd',
|
|
2152
|
-
'label',
|
|
2153
|
-
'legend',
|
|
2154
|
-
'li',
|
|
2155
|
-
'main',
|
|
2156
|
-
'map',
|
|
2157
|
-
'mark',
|
|
2158
|
-
'menu',
|
|
2159
|
-
'meter',
|
|
2160
|
-
'nav',
|
|
2161
|
-
'object',
|
|
2162
|
-
'ol',
|
|
2163
|
-
'optgroup',
|
|
2164
|
-
'option',
|
|
2165
|
-
'output',
|
|
2166
|
-
'p',
|
|
2167
|
-
'picture',
|
|
2168
|
-
'pre',
|
|
2169
|
-
'progress',
|
|
2170
|
-
'q',
|
|
2171
|
-
'rp',
|
|
2172
|
-
'rt',
|
|
2173
|
-
'ruby',
|
|
2174
|
-
's',
|
|
2175
|
-
'samp',
|
|
2176
|
-
'search',
|
|
2177
|
-
'section',
|
|
2178
|
-
'select',
|
|
2179
|
-
'slot',
|
|
2180
|
-
'small',
|
|
2181
|
-
'span',
|
|
2182
|
-
'strong',
|
|
2183
|
-
'sub',
|
|
2184
|
-
'summary',
|
|
2185
|
-
'sup',
|
|
2186
|
-
'table',
|
|
2187
|
-
'tbody',
|
|
2188
|
-
'td',
|
|
2189
|
-
'template',
|
|
2190
|
-
'textarea',
|
|
2191
|
-
'tfoot',
|
|
2192
|
-
'th',
|
|
2193
|
-
'thead',
|
|
2194
|
-
'time',
|
|
2195
|
-
'tr',
|
|
2196
|
-
'u',
|
|
2197
|
-
'ul',
|
|
2198
|
-
'var',
|
|
2199
|
-
'video',
|
|
2200
|
-
'wbr',
|
|
2201
|
-
'circle',
|
|
2202
|
-
'clipPath',
|
|
2203
|
-
'defs',
|
|
2204
|
-
'ellipse',
|
|
2205
|
-
'feBlend',
|
|
2206
|
-
'feColorMatrix',
|
|
2207
|
-
'feComponentTransfer',
|
|
2208
|
-
'feComposite',
|
|
2209
|
-
'feConvolveMatrix',
|
|
2210
|
-
'feDiffuseLighting',
|
|
2211
|
-
'feDisplacementMap',
|
|
2212
|
-
'feDistantLight',
|
|
2213
|
-
'feDropShadow',
|
|
2214
|
-
'feFlood',
|
|
2215
|
-
'feFuncA',
|
|
2216
|
-
'feFuncB',
|
|
2217
|
-
'feFuncG',
|
|
2218
|
-
'feFuncR',
|
|
2219
|
-
'feGaussianBlur',
|
|
2220
|
-
'feImage',
|
|
2221
|
-
'feMerge',
|
|
2222
|
-
'feMergeNode',
|
|
2223
|
-
'feMorphology',
|
|
2224
|
-
'feOffset',
|
|
2225
|
-
'fePointLight',
|
|
2226
|
-
'feSpecularLighting',
|
|
2227
|
-
'feSpotLight',
|
|
2228
|
-
'feTile',
|
|
2229
|
-
'feTurbulence',
|
|
2230
|
-
'filter',
|
|
2231
|
-
'foreignObject',
|
|
2232
|
-
'g',
|
|
2233
|
-
'image',
|
|
2234
|
-
'line',
|
|
2235
|
-
'linearGradient',
|
|
2236
|
-
'marker',
|
|
2237
|
-
'mask',
|
|
2238
|
-
'path',
|
|
2239
|
-
'pattern',
|
|
2240
|
-
'polygon',
|
|
2241
|
-
'polyline',
|
|
2242
|
-
'radialGradient',
|
|
2243
|
-
'rect',
|
|
2244
|
-
'stop',
|
|
2245
|
-
'svg',
|
|
2246
|
-
'switch',
|
|
2247
|
-
'symbol',
|
|
2248
|
-
'text',
|
|
2249
|
-
'textPath',
|
|
2250
|
-
'tspan',
|
|
2251
|
-
'use',
|
|
1983
|
+
// prettier-ignore
|
|
1984
|
+
const elements = [
|
|
1985
|
+
'a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'blockquote', 'body', 'button', 'br', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'menu', 'meter', 'nav', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'slot', 'small', 'span', 'strong', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'u', 'ul', 'var', 'video', 'wbr', 'circle', 'clipPath', 'defs', 'ellipse', 'feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence', 'filter', 'foreignObject', 'g', 'image', 'line', 'linearGradient', 'marker', 'mask', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'stop', 'svg', 'switch', 'symbol', 'text', 'textPath', 'tspan', 'use',
|
|
2252
1986
|
];
|
|
2253
1987
|
var domElements = new Set(elements);
|
|
2254
1988
|
|
|
2255
1989
|
// Source: https://www.w3.org/TR/cssom-1/#serialize-an-identifier
|
|
2256
1990
|
// Control characters and non-letter first symbols are not supported
|
|
2257
|
-
|
|
2258
|
-
|
|
1991
|
+
const escapeRegex = /[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~-]+/g;
|
|
1992
|
+
const dashesAtEnds = /(^-|-$)/g;
|
|
2259
1993
|
/**
|
|
2260
1994
|
* TODO: Explore using CSS.escape when it becomes more available
|
|
2261
1995
|
* in evergreen browsers.
|
|
@@ -2273,23 +2007,22 @@
|
|
|
2273
2007
|
}
|
|
2274
2008
|
|
|
2275
2009
|
function generateDisplayName(target) {
|
|
2276
|
-
return isTag(target) ?
|
|
2010
|
+
return isTag(target) ? `styled.${target}` : `Styled(${getComponentName(target)})`;
|
|
2277
2011
|
}
|
|
2278
2012
|
|
|
2279
|
-
function mixinRecursively(target, source, forceMerge) {
|
|
2280
|
-
if (forceMerge === void 0) { forceMerge = false; }
|
|
2013
|
+
function mixinRecursively(target, source, forceMerge = false) {
|
|
2281
2014
|
/* only merge into POJOs, Arrays, but for top level objects only
|
|
2282
2015
|
* allow to merge into anything by passing forceMerge = true */
|
|
2283
2016
|
if (!forceMerge && !isPlainObject(target) && !Array.isArray(target)) {
|
|
2284
2017
|
return source;
|
|
2285
2018
|
}
|
|
2286
2019
|
if (Array.isArray(source)) {
|
|
2287
|
-
for (
|
|
2020
|
+
for (let key = 0; key < source.length; key++) {
|
|
2288
2021
|
target[key] = mixinRecursively(target[key], source[key]);
|
|
2289
2022
|
}
|
|
2290
2023
|
}
|
|
2291
2024
|
else if (isPlainObject(source)) {
|
|
2292
|
-
for (
|
|
2025
|
+
for (const key in source) {
|
|
2293
2026
|
target[key] = mixinRecursively(target[key], source[key]);
|
|
2294
2027
|
}
|
|
2295
2028
|
}
|
|
@@ -2300,24 +2033,19 @@
|
|
|
2300
2033
|
* If target is not a POJO or an Array, it will get source properties injected via shallow merge
|
|
2301
2034
|
* Source objects applied left to right. Mutates & returns target. Similar to lodash merge.
|
|
2302
2035
|
*/
|
|
2303
|
-
function mixinDeep(target) {
|
|
2304
|
-
|
|
2305
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2306
|
-
sources[_i - 1] = arguments[_i];
|
|
2307
|
-
}
|
|
2308
|
-
for (var _a = 0, sources_1 = sources; _a < sources_1.length; _a++) {
|
|
2309
|
-
var source = sources_1[_a];
|
|
2036
|
+
function mixinDeep(target, ...sources) {
|
|
2037
|
+
for (const source of sources) {
|
|
2310
2038
|
mixinRecursively(target, source, true);
|
|
2311
2039
|
}
|
|
2312
2040
|
return target;
|
|
2313
2041
|
}
|
|
2314
2042
|
|
|
2315
|
-
|
|
2043
|
+
const SEED = hash(SC_VERSION);
|
|
2316
2044
|
/**
|
|
2317
2045
|
* ComponentStyle is all the CSS-specific stuff, not the React-specific stuff.
|
|
2318
2046
|
*/
|
|
2319
|
-
|
|
2320
|
-
|
|
2047
|
+
class ComponentStyle {
|
|
2048
|
+
constructor(rules, componentId, baseStyle) {
|
|
2321
2049
|
this.rules = rules;
|
|
2322
2050
|
this.staticRulesId = '';
|
|
2323
2051
|
this.isStatic =
|
|
@@ -2329,8 +2057,8 @@
|
|
|
2329
2057
|
// for this component's styles compared to others
|
|
2330
2058
|
StyleSheet.registerId(componentId);
|
|
2331
2059
|
}
|
|
2332
|
-
|
|
2333
|
-
|
|
2060
|
+
generateAndInjectStyles(executionContext, styleSheet, stylis) {
|
|
2061
|
+
let names = this.baseStyle
|
|
2334
2062
|
? this.baseStyle.generateAndInjectStyles(executionContext, styleSheet, stylis)
|
|
2335
2063
|
: '';
|
|
2336
2064
|
// force dynamic classnames if user-supplied stylis plugins are in use
|
|
@@ -2339,27 +2067,27 @@
|
|
|
2339
2067
|
names = joinStrings(names, this.staticRulesId);
|
|
2340
2068
|
}
|
|
2341
2069
|
else {
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
if (!styleSheet.hasNameForId(this.componentId,
|
|
2345
|
-
|
|
2346
|
-
styleSheet.insertRules(this.componentId,
|
|
2070
|
+
const cssStatic = joinStringArray(flatten(this.rules, executionContext, styleSheet, stylis));
|
|
2071
|
+
const name = generateAlphabeticName(phash(this.baseHash, cssStatic) >>> 0);
|
|
2072
|
+
if (!styleSheet.hasNameForId(this.componentId, name)) {
|
|
2073
|
+
const cssStaticFormatted = stylis(cssStatic, '.' + name, undefined, this.componentId);
|
|
2074
|
+
styleSheet.insertRules(this.componentId, name, cssStaticFormatted);
|
|
2347
2075
|
}
|
|
2348
|
-
names = joinStrings(names,
|
|
2349
|
-
this.staticRulesId =
|
|
2076
|
+
names = joinStrings(names, name);
|
|
2077
|
+
this.staticRulesId = name;
|
|
2350
2078
|
}
|
|
2351
2079
|
}
|
|
2352
2080
|
else {
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
for (
|
|
2356
|
-
|
|
2081
|
+
let dynamicHash = phash(this.baseHash, stylis.hash);
|
|
2082
|
+
let css = '';
|
|
2083
|
+
for (let i = 0; i < this.rules.length; i++) {
|
|
2084
|
+
const partRule = this.rules[i];
|
|
2357
2085
|
if (typeof partRule === 'string') {
|
|
2358
2086
|
css += partRule;
|
|
2359
2087
|
dynamicHash = phash(dynamicHash, partRule);
|
|
2360
2088
|
}
|
|
2361
2089
|
else if (partRule) {
|
|
2362
|
-
|
|
2090
|
+
const partString = joinStringArray(flatten(partRule, executionContext, styleSheet, stylis));
|
|
2363
2091
|
// The same value can switch positions in the array, so we include "i" in the hash.
|
|
2364
2092
|
// Split into two phash calls to avoid temp string allocation (partString + i).
|
|
2365
2093
|
// phash processes right-to-left, so phash(h, a+b) === phash(phash(h, b), a).
|
|
@@ -2368,54 +2096,53 @@
|
|
|
2368
2096
|
}
|
|
2369
2097
|
}
|
|
2370
2098
|
if (css) {
|
|
2371
|
-
|
|
2372
|
-
if (!styleSheet.hasNameForId(this.componentId,
|
|
2373
|
-
|
|
2374
|
-
styleSheet.insertRules(this.componentId,
|
|
2099
|
+
const name = generateAlphabeticName(dynamicHash >>> 0);
|
|
2100
|
+
if (!styleSheet.hasNameForId(this.componentId, name)) {
|
|
2101
|
+
const cssFormatted = stylis(css, '.' + name, undefined, this.componentId);
|
|
2102
|
+
styleSheet.insertRules(this.componentId, name, cssFormatted);
|
|
2375
2103
|
}
|
|
2376
|
-
names = joinStrings(names,
|
|
2104
|
+
names = joinStrings(names, name);
|
|
2377
2105
|
}
|
|
2378
2106
|
}
|
|
2379
2107
|
return names;
|
|
2380
|
-
}
|
|
2381
|
-
|
|
2382
|
-
}());
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2383
2110
|
|
|
2384
|
-
|
|
2111
|
+
const identifiers = {};
|
|
2385
2112
|
/* We depend on components having unique IDs */
|
|
2386
2113
|
function generateId(displayName, parentComponentId) {
|
|
2387
|
-
|
|
2114
|
+
const name = typeof displayName !== 'string' ? 'sc' : escape(displayName);
|
|
2388
2115
|
// Ensure that no displayName can lead to duplicate componentIds
|
|
2389
2116
|
identifiers[name] = (identifiers[name] || 0) + 1;
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
return parentComponentId ?
|
|
2117
|
+
const componentId = `${name}-${generateComponentId(
|
|
2118
|
+
// SC_VERSION gives us isolation between multiple runtimes on the page at once
|
|
2119
|
+
// this is improved further with use of the babel plugin "namespace" feature
|
|
2120
|
+
SC_VERSION + name + identifiers[name])}`;
|
|
2121
|
+
return parentComponentId ? `${parentComponentId}-${componentId}` : componentId;
|
|
2395
2122
|
}
|
|
2396
2123
|
function useInjectedStyle(componentStyle, resolvedAttrs, styleSheet, stylis) {
|
|
2397
|
-
|
|
2124
|
+
const className = componentStyle.generateAndInjectStyles(resolvedAttrs, styleSheet, stylis);
|
|
2398
2125
|
if (React.useDebugValue) {
|
|
2399
2126
|
React.useDebugValue(className);
|
|
2400
2127
|
}
|
|
2401
2128
|
return className;
|
|
2402
2129
|
}
|
|
2403
2130
|
function resolveContext(attrs, props, theme) {
|
|
2404
|
-
|
|
2131
|
+
const context = Object.assign(Object.assign({}, props), {
|
|
2405
2132
|
// unset, add `props.className` back at the end so props always "wins"
|
|
2406
|
-
className: undefined, theme
|
|
2407
|
-
|
|
2408
|
-
for (
|
|
2133
|
+
className: undefined, theme });
|
|
2134
|
+
let attrDef;
|
|
2135
|
+
for (let i = 0; i < attrs.length; i += 1) {
|
|
2409
2136
|
attrDef = attrs[i];
|
|
2410
2137
|
// Pass a shallow copy to function attrs so the callback's captured
|
|
2411
2138
|
// reference isn't mutated by subsequent attrs processing (#3336).
|
|
2412
|
-
|
|
2413
|
-
for (
|
|
2139
|
+
const resolvedAttrDef = isFunction(attrDef) ? attrDef(Object.assign({}, context)) : attrDef;
|
|
2140
|
+
for (const key in resolvedAttrDef) {
|
|
2414
2141
|
if (key === 'className') {
|
|
2415
2142
|
context.className = joinStrings(context.className, resolvedAttrDef[key]);
|
|
2416
2143
|
}
|
|
2417
2144
|
else if (key === 'style') {
|
|
2418
|
-
context.style =
|
|
2145
|
+
context.style = Object.assign(Object.assign({}, context.style), resolvedAttrDef[key]);
|
|
2419
2146
|
}
|
|
2420
2147
|
else if (!(key in props && props[key] === undefined)) {
|
|
2421
2148
|
// Apply attr value unless the user explicitly passed undefined for this prop,
|
|
@@ -2430,23 +2157,23 @@
|
|
|
2430
2157
|
}
|
|
2431
2158
|
return context;
|
|
2432
2159
|
}
|
|
2433
|
-
|
|
2160
|
+
let seenUnknownProps = new Set();
|
|
2434
2161
|
function useStyledComponentImpl(forwardedComponent, props, forwardedRef) {
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2162
|
+
const { attrs: componentAttrs, componentStyle, defaultProps, foldedComponentIds, styledComponentId, target, } = forwardedComponent;
|
|
2163
|
+
const contextTheme = React.useContext(ThemeContext) ;
|
|
2164
|
+
const ssc = useStyleSheetContext();
|
|
2165
|
+
const shouldForwardProp = forwardedComponent.shouldForwardProp || ssc.shouldForwardProp;
|
|
2439
2166
|
if (React.useDebugValue) {
|
|
2440
2167
|
React.useDebugValue(styledComponentId);
|
|
2441
2168
|
}
|
|
2442
2169
|
// NOTE: the non-hooks version only subscribes to this when !componentStyle.isStatic,
|
|
2443
2170
|
// but that'd be against the rules-of-hooks. We could be naughty and do it anyway as it
|
|
2444
2171
|
// should be an immutable value, but behave for now.
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
for (
|
|
2172
|
+
const theme = determineTheme(props, contextTheme, defaultProps) || (EMPTY_OBJECT);
|
|
2173
|
+
const context = resolveContext(componentAttrs, props, theme);
|
|
2174
|
+
const elementToBeCreated = context.as || target;
|
|
2175
|
+
const propsForElement = {};
|
|
2176
|
+
for (const key in context) {
|
|
2450
2177
|
// @ts-expect-error context may have arbitrary properties from attrs
|
|
2451
2178
|
if (context[key] === undefined) ;
|
|
2452
2179
|
else if (key[0] === '$' || key === 'as' || (key === 'theme' && context.theme === theme)) ;
|
|
@@ -2463,15 +2190,15 @@
|
|
|
2463
2190
|
// Only warn on DOM Element.
|
|
2464
2191
|
domElements.has(elementToBeCreated)) {
|
|
2465
2192
|
seenUnknownProps.add(key);
|
|
2466
|
-
console.warn(
|
|
2193
|
+
console.warn(`styled-components: it looks like an unknown prop "${key}" is being sent through to the DOM, which will likely trigger a React console error. If you would like automatic filtering of unknown props, you can opt-into that behavior via \`<StyleSheetManager shouldForwardProp={...}>\` (connect an API like \`@emotion/is-prop-valid\`) or consider using transient props (\`$\` prefix for automatic filtering.)`);
|
|
2467
2194
|
}
|
|
2468
2195
|
}
|
|
2469
2196
|
}
|
|
2470
|
-
|
|
2197
|
+
const generatedClassName = useInjectedStyle(componentStyle, context, ssc.styleSheet, ssc.stylis);
|
|
2471
2198
|
if (forwardedComponent.warnTooManyClasses) {
|
|
2472
2199
|
forwardedComponent.warnTooManyClasses(generatedClassName);
|
|
2473
2200
|
}
|
|
2474
|
-
|
|
2201
|
+
let classString = joinStrings(foldedComponentIds, styledComponentId);
|
|
2475
2202
|
if (generatedClassName) {
|
|
2476
2203
|
classString += ' ' + generatedClassName;
|
|
2477
2204
|
}
|
|
@@ -2490,37 +2217,35 @@
|
|
|
2490
2217
|
if (forwardedRef) {
|
|
2491
2218
|
propsForElement.ref = forwardedRef;
|
|
2492
2219
|
}
|
|
2493
|
-
|
|
2220
|
+
const element = React.createElement(elementToBeCreated, propsForElement);
|
|
2494
2221
|
return element;
|
|
2495
2222
|
}
|
|
2496
2223
|
function createStyledComponent(target, options, rules) {
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
?
|
|
2224
|
+
const isTargetStyledComp = isStyledComponent(target);
|
|
2225
|
+
const styledComponentTarget = target;
|
|
2226
|
+
const isCompositeComponent = !isTag(target);
|
|
2227
|
+
const { attrs = EMPTY_ARRAY, componentId = generateId(options.displayName, options.parentComponentId), displayName = generateDisplayName(target), } = options;
|
|
2228
|
+
const styledComponentId = options.displayName && options.componentId
|
|
2229
|
+
? `${escape(options.displayName)}-${options.componentId}`
|
|
2503
2230
|
: options.componentId || componentId;
|
|
2504
2231
|
// fold the underlying StyledComponent attrs up (implicit extend)
|
|
2505
|
-
|
|
2232
|
+
const finalAttrs = isTargetStyledComp && styledComponentTarget.attrs
|
|
2506
2233
|
? styledComponentTarget.attrs.concat(attrs).filter(Boolean)
|
|
2507
2234
|
: attrs;
|
|
2508
|
-
|
|
2235
|
+
let { shouldForwardProp } = options;
|
|
2509
2236
|
if (isTargetStyledComp && styledComponentTarget.shouldForwardProp) {
|
|
2510
|
-
|
|
2237
|
+
const shouldForwardPropFn = styledComponentTarget.shouldForwardProp;
|
|
2511
2238
|
if (options.shouldForwardProp) {
|
|
2512
|
-
|
|
2239
|
+
const passedShouldForwardPropFn = options.shouldForwardProp;
|
|
2513
2240
|
// compose nested shouldForwardProp calls
|
|
2514
|
-
shouldForwardProp =
|
|
2515
|
-
|
|
2516
|
-
passedShouldForwardPropFn_1(prop, elementToBeCreated);
|
|
2517
|
-
};
|
|
2241
|
+
shouldForwardProp = (prop, elementToBeCreated) => shouldForwardPropFn(prop, elementToBeCreated) &&
|
|
2242
|
+
passedShouldForwardPropFn(prop, elementToBeCreated);
|
|
2518
2243
|
}
|
|
2519
2244
|
else {
|
|
2520
|
-
shouldForwardProp =
|
|
2245
|
+
shouldForwardProp = shouldForwardPropFn;
|
|
2521
2246
|
}
|
|
2522
2247
|
}
|
|
2523
|
-
|
|
2248
|
+
const componentStyle = new ComponentStyle(rules, styledComponentId, isTargetStyledComp ? styledComponentTarget.componentStyle : undefined);
|
|
2524
2249
|
function forwardRefRender(props, ref) {
|
|
2525
2250
|
return useStyledComponentImpl(WrappedStyledComponent, props, ref);
|
|
2526
2251
|
}
|
|
@@ -2529,7 +2254,7 @@
|
|
|
2529
2254
|
* forwardRef creates a new interim component, which we'll take advantage of
|
|
2530
2255
|
* instead of extending ParentComponent to create _another_ interim class
|
|
2531
2256
|
*/
|
|
2532
|
-
|
|
2257
|
+
let WrappedStyledComponent = React.forwardRef(forwardRefRender);
|
|
2533
2258
|
WrappedStyledComponent.attrs = finalAttrs;
|
|
2534
2259
|
WrappedStyledComponent.componentStyle = componentStyle;
|
|
2535
2260
|
WrappedStyledComponent.displayName = displayName;
|
|
@@ -2543,10 +2268,10 @@
|
|
|
2543
2268
|
// fold the underlying StyledComponent target up since we folded the styles
|
|
2544
2269
|
WrappedStyledComponent.target = isTargetStyledComp ? styledComponentTarget.target : target;
|
|
2545
2270
|
Object.defineProperty(WrappedStyledComponent, 'defaultProps', {
|
|
2546
|
-
get
|
|
2271
|
+
get() {
|
|
2547
2272
|
return this._foldedDefaultProps;
|
|
2548
2273
|
},
|
|
2549
|
-
set
|
|
2274
|
+
set(obj) {
|
|
2550
2275
|
this._foldedDefaultProps = isTargetStyledComp
|
|
2551
2276
|
? mixinDeep({}, styledComponentTarget.defaultProps, obj)
|
|
2552
2277
|
: obj;
|
|
@@ -2556,9 +2281,9 @@
|
|
|
2556
2281
|
checkDynamicCreation(displayName, styledComponentId);
|
|
2557
2282
|
WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName, styledComponentId);
|
|
2558
2283
|
}
|
|
2559
|
-
setToString(WrappedStyledComponent,
|
|
2284
|
+
setToString(WrappedStyledComponent, () => `.${WrappedStyledComponent.styledComponentId}`);
|
|
2560
2285
|
if (isCompositeComponent) {
|
|
2561
|
-
|
|
2286
|
+
const compositeComponentTarget = target;
|
|
2562
2287
|
hoistNonReactStatics(WrappedStyledComponent, compositeComponentTarget, {
|
|
2563
2288
|
// all SC-specific things should not be hoisted
|
|
2564
2289
|
attrs: true,
|
|
@@ -2573,8 +2298,7 @@
|
|
|
2573
2298
|
return WrappedStyledComponent;
|
|
2574
2299
|
}
|
|
2575
2300
|
|
|
2576
|
-
function constructWithOptions(componentConstructor, tag, options) {
|
|
2577
|
-
if (options === void 0) { options = EMPTY_OBJECT; }
|
|
2301
|
+
function constructWithOptions(componentConstructor, tag, options = EMPTY_OBJECT) {
|
|
2578
2302
|
/**
|
|
2579
2303
|
* We trust that the tag is a valid component as long as it isn't
|
|
2580
2304
|
* falsish. Typically the tag here is a string or function (i.e.
|
|
@@ -2586,38 +2310,26 @@
|
|
|
2586
2310
|
throw throwStyledComponentsError(1, tag);
|
|
2587
2311
|
}
|
|
2588
2312
|
/* This is callable directly as a template function */
|
|
2589
|
-
|
|
2590
|
-
var interpolations = [];
|
|
2591
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2592
|
-
interpolations[_i - 1] = arguments[_i];
|
|
2593
|
-
}
|
|
2594
|
-
return componentConstructor(tag, options, css.apply(void 0, __spreadArray([initialStyles], interpolations, false)));
|
|
2595
|
-
};
|
|
2313
|
+
const templateFunction = (initialStyles, ...interpolations) => componentConstructor(tag, options, css(initialStyles, ...interpolations));
|
|
2596
2314
|
/**
|
|
2597
2315
|
* Attrs allows for accomplishing two goals:
|
|
2598
2316
|
*
|
|
2599
2317
|
* 1. Backfilling props at runtime more expressively than defaultProps
|
|
2600
2318
|
* 2. Amending the prop interface of a wrapped styled component
|
|
2601
2319
|
*/
|
|
2602
|
-
templateFunction.attrs =
|
|
2603
|
-
return constructWithOptions(componentConstructor, tag, __assign(__assign({}, options), { attrs: Array.prototype.concat(options.attrs, attrs).filter(Boolean) }));
|
|
2604
|
-
};
|
|
2320
|
+
templateFunction.attrs = (attrs) => constructWithOptions(componentConstructor, tag, Object.assign(Object.assign({}, options), { attrs: Array.prototype.concat(options.attrs, attrs).filter(Boolean) }));
|
|
2605
2321
|
/**
|
|
2606
2322
|
* If config methods are called, wrap up a new template function
|
|
2607
2323
|
* and merge options.
|
|
2608
2324
|
*/
|
|
2609
|
-
templateFunction.withConfig =
|
|
2610
|
-
return constructWithOptions(componentConstructor, tag, __assign(__assign({}, options), config));
|
|
2611
|
-
};
|
|
2325
|
+
templateFunction.withConfig = (config) => constructWithOptions(componentConstructor, tag, Object.assign(Object.assign({}, options), config));
|
|
2612
2326
|
return templateFunction;
|
|
2613
2327
|
}
|
|
2614
2328
|
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
};
|
|
2618
|
-
var styled = baseStyled;
|
|
2329
|
+
const baseStyled = (tag) => constructWithOptions(createStyledComponent, tag);
|
|
2330
|
+
const styled = baseStyled;
|
|
2619
2331
|
// Shorthands for all valid HTML Elements
|
|
2620
|
-
domElements.forEach(
|
|
2332
|
+
domElements.forEach(domElement => {
|
|
2621
2333
|
// @ts-expect-error some react typing bs
|
|
2622
2334
|
styled[domElement] = baseStyled(domElement);
|
|
2623
2335
|
});
|
|
@@ -2626,7 +2338,7 @@
|
|
|
2626
2338
|
* eliminates the need to do styled.default since the other APIs
|
|
2627
2339
|
* are directly assigned as properties to the main function
|
|
2628
2340
|
* */
|
|
2629
|
-
for (
|
|
2341
|
+
for (const key in secondary) {
|
|
2630
2342
|
// @ts-expect-error shush
|
|
2631
2343
|
styled[key] = secondary[key];
|
|
2632
2344
|
}
|