UNPKG

97.8 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
3 typeof define === 'function' && define.amd ? define(['react'], factory) :
4 (global = global || self, global.styled = factory(global.React));
5})(this, (function (React) { 'use strict';
6
7 var SC_ATTR = (typeof process !== 'undefined' &&
8 typeof process.env !== 'undefined' &&
9 (process.env.REACT_APP_SC_ATTR || process.env.SC_ATTR)) ||
10 'data-styled';
11 var SC_ATTR_ACTIVE = 'active';
12 var SC_ATTR_VERSION = 'data-styled-version';
13 var SC_VERSION = "6.1.13";
14 var SPLITTER = '/*!sc*/\n';
15 var IS_BROWSER = typeof window !== 'undefined' && 'HTMLElement' in window;
16 var DISABLE_SPEEDY = Boolean(typeof SC_DISABLE_SPEEDY === 'boolean'
17 ? SC_DISABLE_SPEEDY
18 : typeof process !== 'undefined' &&
19 typeof process.env !== 'undefined' &&
20 typeof process.env.REACT_APP_SC_DISABLE_SPEEDY !== 'undefined' &&
21 process.env.REACT_APP_SC_DISABLE_SPEEDY !== ''
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 // Shared empty execution context when generating static styles
34 var STATIC_EXECUTION_CONTEXT = {};
35
36 /******************************************************************************
37 Copyright (c) Microsoft Corporation.
38
39 Permission to use, copy, modify, and/or distribute this software for any
40 purpose with or without fee is hereby granted.
41
42 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
43 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
44 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
45 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
46 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
47 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
48 PERFORMANCE OF THIS SOFTWARE.
49 ***************************************************************************** */
50 /* global Reflect, Promise, SuppressedError, Symbol */
51
52
53 var __assign = function() {
54 __assign = Object.assign || function __assign(t) {
55 for (var s, i = 1, n = arguments.length; i < n; i++) {
56 s = arguments[i];
57 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
58 }
59 return t;
60 };
61 return __assign.apply(this, arguments);
62 };
63
64 function __spreadArray(to, from, pack) {
65 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
66 if (ar || !(i in from)) {
67 if (!ar) ar = Array.prototype.slice.call(from, 0, i);
68 ar[i] = from[i];
69 }
70 }
71 return to.concat(ar || Array.prototype.slice.call(from));
72 }
73
74 typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
75 var e = new Error(message);
76 return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
77 };
78
79 var EMPTY_ARRAY = Object.freeze([]);
80 var EMPTY_OBJECT = Object.freeze({});
81
82 /**
83 * If the Object prototype is frozen, the "toString" property is non-writable. This means that any objects which inherit this property
84 * cannot have the property changed using a "=" assignment operator. If using strict mode, attempting that will cause an error. If not using
85 * strict mode, attempting that will be silently ignored.
86 *
87 * If the Object prototype is frozen, inherited non-writable properties can still be shadowed using one of two mechanisms:
88 *
89 * 1. ES6 class methods: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#methods
90 * 2. Using the `Object.defineProperty()` static method:
91 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
92 *
93 * However, this project uses Babel to transpile ES6 classes, and transforms ES6 class methods to use the assignment operator instead:
94 * https://babeljs.io/docs/babel-plugin-transform-class-properties#options
95 *
96 * Therefore, the most compatible way to shadow the prototype's "toString" property is to define a new "toString" property on this object.
97 */
98 function setToString(object, toStringFn) {
99 Object.defineProperty(object, 'toString', { value: toStringFn });
100 }
101
102 var errorMap = {
103 '1': 'Cannot create styled-component for component: %s.\n\n',
104 '2': "Can't collect styles once you've consumed a `ServerStyleSheet`'s styles! `ServerStyleSheet` is a one off instance for each server-side render cycle.\n\n- Are you trying to reuse it across renders?\n- Are you accidentally calling collectStyles twice?\n\n",
105 '3': 'Streaming SSR is only supported in a Node.js environment; Please do not try to call this method in the browser.\n\n',
106 '4': 'The `StyleSheetManager` expects a valid target or sheet prop!\n\n- Does this error occur on the client and is your target falsy?\n- Does this error occur on the server and is the sheet falsy?\n\n',
107 '5': 'The clone method cannot be used on the client!\n\n- Are you running in a client-like environment on the server?\n- Are you trying to run SSR on the client?\n\n',
108 '6': "Trying to insert a new style tag, but the given Node is unmounted!\n\n- Are you using a custom target that isn't mounted?\n- Does your document not have a valid head element?\n- Have you accidentally removed a style tag manually?\n\n",
109 '7': 'ThemeProvider: Please return an object from your "theme" prop function, e.g.\n\n```js\ntheme={() => ({})}\n```\n\n',
110 '8': 'ThemeProvider: Please make your "theme" prop an object.\n\n',
111 '9': 'Missing document `<head>`\n\n',
112 '10': 'Cannot find a StyleSheet instance. Usually this happens if there are multiple copies of styled-components loaded at once. Check out this issue for how to troubleshoot and fix the common cases where this situation can happen: https://github.com/styled-components/styled-components/issues/1941#issuecomment-417862021\n\n',
113 '11': '_This error was replaced with a dev-time warning, it will be deleted for v4 final._ [createGlobalStyle] received children which will not be rendered. Please use the component without passing children elements.\n\n',
114 '12': 'It seems you are interpolating a keyframe declaration (%s) into an untagged string. This was supported in styled-components v3, but is not longer supported in v4 as keyframes are now injected on-demand. Please wrap your string in the css\\`\\` helper which ensures the styles are injected correctly. See https://www.styled-components.com/docs/api#css\n\n',
115 '13': '%s 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.\n\n',
116 '14': 'ThemeProvider: "theme" prop is required.\n\n',
117 '15': "A stylis plugin has been supplied that is not named. We need a name for each plugin to be able to prevent styling collisions between different stylis configurations within the same app. Before you pass your plugin to `<StyleSheetManager stylisPlugins={[]}>`, please make sure each plugin is uniquely-named, e.g.\n\n```js\nObject.defineProperty(importedPlugin, 'name', { value: 'some-unique-name' });\n```\n\n",
118 '16': "Reached the limit of how many styled components may be created at group %s.\nYou may only create up to 1,073,741,824 components. If you're creating components dynamically,\nas for instance in your render method then you may be running into this limitation.\n\n",
119 '17': "CSSStyleSheet could not be found on HTMLStyleElement.\nHas styled-components' style tag been unmounted or altered by another script?\n",
120 '18': 'ThemeProvider: Please make sure your useTheme hook is within a `<ThemeProvider>`',
121 };
122
123 var ERRORS = errorMap ;
124 /**
125 * super basic version of sprintf
126 */
127 function format() {
128 var args = [];
129 for (var _i = 0; _i < arguments.length; _i++) {
130 args[_i] = arguments[_i];
131 }
132 var a = args[0];
133 var b = [];
134 for (var c = 1, len = args.length; c < len; c += 1) {
135 b.push(args[c]);
136 }
137 b.forEach(function (d) {
138 a = a.replace(/%[a-z]/, d);
139 });
140 return a;
141 }
142 /**
143 * Create an error file out of errors.md for development and a simple web link to the full errors
144 * in production mode.
145 */
146 function throwStyledComponentsError(code) {
147 var interpolations = [];
148 for (var _i = 1; _i < arguments.length; _i++) {
149 interpolations[_i - 1] = arguments[_i];
150 }
151 {
152 return new Error(format.apply(void 0, __spreadArray([ERRORS[code]], interpolations, false)).trim());
153 }
154 }
155
156 /** Create a GroupedTag with an underlying Tag implementation */
157 var makeGroupedTag = function (tag) {
158 return new DefaultGroupedTag(tag);
159 };
160 var BASE_SIZE = 1 << 9;
161 var DefaultGroupedTag = /** @class */ (function () {
162 function DefaultGroupedTag(tag) {
163 this.groupSizes = new Uint32Array(BASE_SIZE);
164 this.length = BASE_SIZE;
165 this.tag = tag;
166 }
167 DefaultGroupedTag.prototype.indexOfGroup = function (group) {
168 var index = 0;
169 for (var i = 0; i < group; i++) {
170 index += this.groupSizes[i];
171 }
172 return index;
173 };
174 DefaultGroupedTag.prototype.insertRules = function (group, rules) {
175 if (group >= this.groupSizes.length) {
176 var oldBuffer = this.groupSizes;
177 var oldSize = oldBuffer.length;
178 var newSize = oldSize;
179 while (group >= newSize) {
180 newSize <<= 1;
181 if (newSize < 0) {
182 throw throwStyledComponentsError(16, "".concat(group));
183 }
184 }
185 this.groupSizes = new Uint32Array(newSize);
186 this.groupSizes.set(oldBuffer);
187 this.length = newSize;
188 for (var i = oldSize; i < newSize; i++) {
189 this.groupSizes[i] = 0;
190 }
191 }
192 var ruleIndex = this.indexOfGroup(group + 1);
193 for (var i = 0, l = rules.length; i < l; i++) {
194 if (this.tag.insertRule(ruleIndex, rules[i])) {
195 this.groupSizes[group]++;
196 ruleIndex++;
197 }
198 }
199 };
200 DefaultGroupedTag.prototype.clearGroup = function (group) {
201 if (group < this.length) {
202 var length_1 = this.groupSizes[group];
203 var startIndex = this.indexOfGroup(group);
204 var endIndex = startIndex + length_1;
205 this.groupSizes[group] = 0;
206 for (var i = startIndex; i < endIndex; i++) {
207 this.tag.deleteRule(startIndex);
208 }
209 }
210 };
211 DefaultGroupedTag.prototype.getGroup = function (group) {
212 var css = '';
213 if (group >= this.length || this.groupSizes[group] === 0) {
214 return css;
215 }
216 var length = this.groupSizes[group];
217 var startIndex = this.indexOfGroup(group);
218 var endIndex = startIndex + length;
219 for (var i = startIndex; i < endIndex; i++) {
220 css += "".concat(this.tag.getRule(i)).concat(SPLITTER);
221 }
222 return css;
223 };
224 return DefaultGroupedTag;
225 }());
226
227 var MAX_SMI = 1 << (31 - 1);
228 var groupIDRegister = new Map();
229 var reverseRegister = new Map();
230 var nextFreeGroup = 1;
231 var getGroupForId = function (id) {
232 if (groupIDRegister.has(id)) {
233 return groupIDRegister.get(id);
234 }
235 while (reverseRegister.has(nextFreeGroup)) {
236 nextFreeGroup++;
237 }
238 var group = nextFreeGroup++;
239 if (((group | 0) < 0 || group > MAX_SMI)) {
240 throw throwStyledComponentsError(16, "".concat(group));
241 }
242 groupIDRegister.set(id, group);
243 reverseRegister.set(group, id);
244 return group;
245 };
246 var getIdForGroup = function (group) {
247 return reverseRegister.get(group);
248 };
249 var setGroupForId = function (id, group) {
250 // move pointer
251 nextFreeGroup = group + 1;
252 groupIDRegister.set(id, group);
253 reverseRegister.set(group, id);
254 };
255
256 var SELECTOR = "style[".concat(SC_ATTR, "][").concat(SC_ATTR_VERSION, "=\"").concat(SC_VERSION, "\"]");
257 var MARKER_RE = new RegExp("^".concat(SC_ATTR, "\\.g(\\d+)\\[id=\"([\\w\\d-]+)\"\\].*?\"([^\"]*)"));
258 var outputSheet = function (sheet) {
259 var tag = sheet.getTag();
260 var length = tag.length;
261 var css = '';
262 var _loop_1 = function (group) {
263 var id = getIdForGroup(group);
264 if (id === undefined)
265 return "continue";
266 var names = sheet.names.get(id);
267 var rules = tag.getGroup(group);
268 if (names === undefined || !names.size || rules.length === 0)
269 return "continue";
270 var selector = "".concat(SC_ATTR, ".g").concat(group, "[id=\"").concat(id, "\"]");
271 var content = '';
272 if (names !== undefined) {
273 names.forEach(function (name) {
274 if (name.length > 0) {
275 content += "".concat(name, ",");
276 }
277 });
278 }
279 // NOTE: It's easier to collect rules and have the marker
280 // after the actual rules to simplify the rehydration
281 css += "".concat(rules).concat(selector, "{content:\"").concat(content, "\"}").concat(SPLITTER);
282 };
283 for (var group = 0; group < length; group++) {
284 _loop_1(group);
285 }
286 return css;
287 };
288 var rehydrateNamesFromContent = function (sheet, id, content) {
289 var names = content.split(',');
290 var name;
291 for (var i = 0, l = names.length; i < l; i++) {
292 if ((name = names[i])) {
293 sheet.registerName(id, name);
294 }
295 }
296 };
297 var rehydrateSheetFromTag = function (sheet, style) {
298 var _a;
299 var parts = ((_a = style.textContent) !== null && _a !== void 0 ? _a : '').split(SPLITTER);
300 var rules = [];
301 for (var i = 0, l = parts.length; i < l; i++) {
302 var part = parts[i].trim();
303 if (!part)
304 continue;
305 var marker = part.match(MARKER_RE);
306 if (marker) {
307 var group = parseInt(marker[1], 10) | 0;
308 var id = marker[2];
309 if (group !== 0) {
310 // Rehydrate componentId to group index mapping
311 setGroupForId(id, group);
312 // Rehydrate names and rules
313 // looks like: data-styled.g11[id="idA"]{content:"nameA,"}
314 rehydrateNamesFromContent(sheet, id, marker[3]);
315 sheet.getTag().insertRules(group, rules);
316 }
317 rules.length = 0;
318 }
319 else {
320 rules.push(part);
321 }
322 }
323 };
324 var rehydrateSheet = function (sheet) {
325 var nodes = document.querySelectorAll(SELECTOR);
326 for (var i = 0, l = nodes.length; i < l; i++) {
327 var node = nodes[i];
328 if (node && node.getAttribute(SC_ATTR) !== SC_ATTR_ACTIVE) {
329 rehydrateSheetFromTag(sheet, node);
330 if (node.parentNode) {
331 node.parentNode.removeChild(node);
332 }
333 }
334 }
335 };
336
337 function getNonce() {
338 return typeof __webpack_nonce__ !== 'undefined' ? __webpack_nonce__ : null;
339 }
340
341 /** Find last style element if any inside target */
342 var findLastStyleTag = function (target) {
343 var arr = Array.from(target.querySelectorAll("style[".concat(SC_ATTR, "]")));
344 return arr[arr.length - 1];
345 };
346 /** Create a style element inside `target` or <head> after the last */
347 var makeStyleTag = function (target) {
348 var head = document.head;
349 var parent = target || head;
350 var style = document.createElement('style');
351 var prevStyle = findLastStyleTag(parent);
352 var nextSibling = prevStyle !== undefined ? prevStyle.nextSibling : null;
353 style.setAttribute(SC_ATTR, SC_ATTR_ACTIVE);
354 style.setAttribute(SC_ATTR_VERSION, SC_VERSION);
355 var nonce = getNonce();
356 if (nonce)
357 style.setAttribute('nonce', nonce);
358 parent.insertBefore(style, nextSibling);
359 return style;
360 };
361 /** Get the CSSStyleSheet instance for a given style element */
362 var getSheet = function (tag) {
363 if (tag.sheet) {
364 return tag.sheet;
365 }
366 // Avoid Firefox quirk where the style element might not have a sheet property
367 var styleSheets = document.styleSheets;
368 for (var i = 0, l = styleSheets.length; i < l; i++) {
369 var sheet = styleSheets[i];
370 if (sheet.ownerNode === tag) {
371 return sheet;
372 }
373 }
374 throw throwStyledComponentsError(17);
375 };
376
377 /** Create a CSSStyleSheet-like tag depending on the environment */
378 var makeTag = function (_a) {
379 var isServer = _a.isServer, useCSSOMInjection = _a.useCSSOMInjection, target = _a.target;
380 if (isServer) {
381 return new VirtualTag(target);
382 }
383 else if (useCSSOMInjection) {
384 return new CSSOMTag(target);
385 }
386 else {
387 return new TextTag(target);
388 }
389 };
390 var CSSOMTag = /** @class */ (function () {
391 function CSSOMTag(target) {
392 this.element = makeStyleTag(target);
393 // Avoid Edge bug where empty style elements don't create sheets
394 this.element.appendChild(document.createTextNode(''));
395 this.sheet = getSheet(this.element);
396 this.length = 0;
397 }
398 CSSOMTag.prototype.insertRule = function (index, rule) {
399 try {
400 this.sheet.insertRule(rule, index);
401 this.length++;
402 return true;
403 }
404 catch (_error) {
405 return false;
406 }
407 };
408 CSSOMTag.prototype.deleteRule = function (index) {
409 this.sheet.deleteRule(index);
410 this.length--;
411 };
412 CSSOMTag.prototype.getRule = function (index) {
413 var rule = this.sheet.cssRules[index];
414 // Avoid IE11 quirk where cssText is inaccessible on some invalid rules
415 if (rule && rule.cssText) {
416 return rule.cssText;
417 }
418 else {
419 return '';
420 }
421 };
422 return CSSOMTag;
423 }());
424 /** A Tag that emulates the CSSStyleSheet API but uses text nodes */
425 var TextTag = /** @class */ (function () {
426 function TextTag(target) {
427 this.element = makeStyleTag(target);
428 this.nodes = this.element.childNodes;
429 this.length = 0;
430 }
431 TextTag.prototype.insertRule = function (index, rule) {
432 if (index <= this.length && index >= 0) {
433 var node = document.createTextNode(rule);
434 var refNode = this.nodes[index];
435 this.element.insertBefore(node, refNode || null);
436 this.length++;
437 return true;
438 }
439 else {
440 return false;
441 }
442 };
443 TextTag.prototype.deleteRule = function (index) {
444 this.element.removeChild(this.nodes[index]);
445 this.length--;
446 };
447 TextTag.prototype.getRule = function (index) {
448 if (index < this.length) {
449 return this.nodes[index].textContent;
450 }
451 else {
452 return '';
453 }
454 };
455 return TextTag;
456 }());
457 /** A completely virtual (server-side) Tag that doesn't manipulate the DOM */
458 var VirtualTag = /** @class */ (function () {
459 function VirtualTag(_target) {
460 this.rules = [];
461 this.length = 0;
462 }
463 VirtualTag.prototype.insertRule = function (index, rule) {
464 if (index <= this.length) {
465 this.rules.splice(index, 0, rule);
466 this.length++;
467 return true;
468 }
469 else {
470 return false;
471 }
472 };
473 VirtualTag.prototype.deleteRule = function (index) {
474 this.rules.splice(index, 1);
475 this.length--;
476 };
477 VirtualTag.prototype.getRule = function (index) {
478 if (index < this.length) {
479 return this.rules[index];
480 }
481 else {
482 return '';
483 }
484 };
485 return VirtualTag;
486 }());
487
488 var SHOULD_REHYDRATE = IS_BROWSER;
489 var defaultOptions = {
490 isServer: !IS_BROWSER,
491 useCSSOMInjection: !DISABLE_SPEEDY,
492 };
493 /** Contains the main stylesheet logic for stringification and caching */
494 var StyleSheet = /** @class */ (function () {
495 function StyleSheet(options, globalStyles, names) {
496 if (options === void 0) { options = EMPTY_OBJECT; }
497 if (globalStyles === void 0) { globalStyles = {}; }
498 var _this = this;
499 this.options = __assign(__assign({}, defaultOptions), options);
500 this.gs = globalStyles;
501 this.names = new Map(names);
502 this.server = !!options.isServer;
503 // We rehydrate only once and use the sheet that is created first
504 if (!this.server && IS_BROWSER && SHOULD_REHYDRATE) {
505 SHOULD_REHYDRATE = false;
506 rehydrateSheet(this);
507 }
508 setToString(this, function () { return outputSheet(_this); });
509 }
510 /** Register a group ID to give it an index */
511 StyleSheet.registerId = function (id) {
512 return getGroupForId(id);
513 };
514 StyleSheet.prototype.rehydrate = function () {
515 if (!this.server && IS_BROWSER) {
516 rehydrateSheet(this);
517 }
518 };
519 StyleSheet.prototype.reconstructWithOptions = function (options, withNames) {
520 if (withNames === void 0) { withNames = true; }
521 return new StyleSheet(__assign(__assign({}, this.options), options), this.gs, (withNames && this.names) || undefined);
522 };
523 StyleSheet.prototype.allocateGSInstance = function (id) {
524 return (this.gs[id] = (this.gs[id] || 0) + 1);
525 };
526 /** Lazily initialises a GroupedTag for when it's actually needed */
527 StyleSheet.prototype.getTag = function () {
528 return this.tag || (this.tag = makeGroupedTag(makeTag(this.options)));
529 };
530 /** Check whether a name is known for caching */
531 StyleSheet.prototype.hasNameForId = function (id, name) {
532 return this.names.has(id) && this.names.get(id).has(name);
533 };
534 /** Mark a group's name as known for caching */
535 StyleSheet.prototype.registerName = function (id, name) {
536 getGroupForId(id);
537 if (!this.names.has(id)) {
538 var groupNames = new Set();
539 groupNames.add(name);
540 this.names.set(id, groupNames);
541 }
542 else {
543 this.names.get(id).add(name);
544 }
545 };
546 /** Insert new rules which also marks the name as known */
547 StyleSheet.prototype.insertRules = function (id, name, rules) {
548 this.registerName(id, name);
549 this.getTag().insertRules(getGroupForId(id), rules);
550 };
551 /** Clears all cached names for a given group ID */
552 StyleSheet.prototype.clearNames = function (id) {
553 if (this.names.has(id)) {
554 this.names.get(id).clear();
555 }
556 };
557 /** Clears all rules for a given group ID */
558 StyleSheet.prototype.clearRules = function (id) {
559 this.getTag().clearGroup(getGroupForId(id));
560 this.clearNames(id);
561 };
562 /** Clears the entire tag which deletes all rules but not its names */
563 StyleSheet.prototype.clearTag = function () {
564 // NOTE: This does not clear the names, since it's only used during SSR
565 // so that we can continuously output only new rules
566 this.tag = undefined;
567 };
568 return StyleSheet;
569 }());
570
571 //
572
573 var shallowequal = function shallowEqual(objA, objB, compare, compareContext) {
574 var ret = compare ? compare.call(compareContext, objA, objB) : void 0;
575
576 if (ret !== void 0) {
577 return !!ret;
578 }
579
580 if (objA === objB) {
581 return true;
582 }
583
584 if (typeof objA !== "object" || !objA || typeof objB !== "object" || !objB) {
585 return false;
586 }
587
588 var keysA = Object.keys(objA);
589 var keysB = Object.keys(objB);
590
591 if (keysA.length !== keysB.length) {
592 return false;
593 }
594
595 var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
596
597 // Test for A's keys different from B.
598 for (var idx = 0; idx < keysA.length; idx++) {
599 var key = keysA[idx];
600
601 if (!bHasOwnProperty(key)) {
602 return false;
603 }
604
605 var valueA = objA[key];
606 var valueB = objB[key];
607
608 ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0;
609
610 if (ret === false || (ret === void 0 && valueA !== valueB)) {
611 return false;
612 }
613 }
614
615 return true;
616 };
617
618 var e="-ms-";var r="-moz-";var a="-webkit-";var n="comm";var c="rule";var s="decl";var i="@import";var h="@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,n,c,s,t,u){return {value:e,root:r,parent:a,type:n,props:c,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,ce(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 ne(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 ce(e){while(T())switch(J){case e:return I;case 34:case 39:if(e!==34&&e!==39)ce(J);break;case 40:if(e===41)ce(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,n,c,s,t,u,i){var f=0;var o=0;var l=t;var v=0;var p=0;var h=0;var b=1;var w=1;var d=1;var g=0;var k="";var x=c;var y=s;var j=n;var z=k;while(w)switch(h=g,g=T()){case 40:if(h!=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(h);break;case 92:z+=ne(V()-1,7);continue;case 47:switch(U()){case 42:case 47:B(oe(se(T(),V()),r,a,i),i);break;default:z+="/";}break;case 123*b:u[f++]=S(z)*d;case 125*b:case 59:case 0:switch(g){case 0:case 125:w=0;case 59+o:if(d==-1)z=C(z,/\f/g,"");if(p>0&&S(z)-l)B(p>32?le(z+";",n,a,l-1,i):le(C(z," ","")+";",n,a,l-2,i),i);break;case 59:z+=";";default:B(j=fe(z,r,a,f,o,c,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(v===99&&A(z,3)===110?100:v){case 100:case 108:case 109:case 115:ie(e,j,j,n&&B(fe(e,j,j,0,0,c,u,k,c,x=[],l,y),y),c,y,l,u,n?x:y);break;default:ie(z,j,j,j,[""],y,0,u,y);}}f=o=p=0,b=d=1,k=z="",l=t;break;case 58:l=1+S(z),p=h;default:if(b<1)if(g==123)--b;else if(g==125&&b++==0&&R()==125)continue;switch(z+=m(g),g*b){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());v=U(),o=l=S(k=z+=te(V())),g++;break;case 45:if(h===45&&S(z)==2)b=0;}}return s}function fe(e,r,a,n,s,t,u,i,f,o,l,v){var p=s-1;var h=s===0?t:[""];var b=q(h);for(var w=0,d=0,g=0;w<n;++w)for(var k=0,m=M(e,p+1,p=$(d=u[w])),x=e;k<b;++k)if(x=j(d>0?h[k]+" "+m:C(m,/&\f/g,h[k])))f[g++]=x;return L(e,r,a,s===0?c:i,f,o,l,v)}function oe(e,r,a,c){return L(e,r,a,n,m(Q()),M(e,2,-2),0,c)}function le(e,r,a,n,c){return L(e,r,a,s,M(e,0,n),M(e,n+1,-1),n,c)}function ve(n,c,s){switch(y(n,c)){case 5103:return a+"print-"+n+n;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 6391:case 5879:case 5623:case 6135:case 4599:case 4855:case 4215:case 6389:case 5109:case 5365:case 5621:case 3829:return a+n+n;case 4789:return r+n+n;case 5349:case 4246:case 4810:case 6968:case 2756:return a+n+r+n+e+n+n;case 5936:switch(A(n,c+11)){case 114:return a+n+e+C(n,/[svh]\w+-[tblr]{2}/,"tb")+n;case 108:return a+n+e+C(n,/[svh]\w+-[tblr]{2}/,"tb-rl")+n;case 45:return a+n+e+C(n,/[svh]\w+-[tblr]{2}/,"lr")+n}case 6828:case 4268:case 2903:return a+n+e+n+n;case 6165:return a+n+e+"flex-"+n+n;case 5187:return a+n+C(n,/(\w+).+(:[^]+)/,a+"box-$1$2"+e+"flex-$1$2")+n;case 5443:return a+n+e+"flex-item-"+C(n,/flex-|-self/g,"")+(!z(n,/flex-|baseline/)?e+"grid-row-"+C(n,/flex-|-self/g,""):"")+n;case 4675:return a+n+e+"flex-line-pack"+C(n,/align-content|flex-|-self/g,"")+n;case 5548:return a+n+e+C(n,"shrink","negative")+n;case 5292:return a+n+e+C(n,"basis","preferred-size")+n;case 6060:return a+"box-"+C(n,"-grow","")+a+n+e+C(n,"grow","positive")+n;case 4554:return a+C(n,/([^-])(transform)/g,"$1"+a+"$2")+n;case 6187:return C(C(C(n,/(zoom-|grab)/,a+"$1"),/(image-set)/,a+"$1"),n,"")+n;case 5495:case 3959:return C(n,/(image-set\([^]*)/,a+"$1"+"$`$1");case 4968:return C(C(n,/(.+:)(flex-)?(.*)/,a+"box-pack:$3"+e+"flex-pack:$3"),/s.+-b[^;]+/,"justify")+a+n+n;case 4200:if(!z(n,/flex-|baseline/))return e+"grid-column-align"+M(n,c)+n;break;case 2592:case 3360:return e+C(n,"template-","")+n;case 4384:case 3616:if(s&&s.some((function(e,r){return c=r,z(e.props,/grid-\w+-end/)}))){return ~O(n+(s=s[c].value),"span",0)?n:e+C(n,"-start","")+n+e+"grid-row-span:"+(~O(s,"span",0)?z(s,/\d+/):+z(s,/\d+/)-+z(n,/\d+/))+";"}return e+C(n,"-start","")+n;case 4896:case 4128:return s&&s.some((function(e){return z(e.props,/grid-\w+-start/)}))?n:e+C(C(n,"-end","-span"),"span ","")+n;case 4095:case 3583:case 4068:case 2532:return C(n,/(.+)-inline(.+)/,a+"$1$2")+n;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(n)-1-c>6)switch(A(n,c+1)){case 109:if(A(n,c+4)!==45)break;case 102:return C(n,/(.+:)(.+)-([^]+)/,"$1"+a+"$2-$3"+"$1"+r+(A(n,c+3)==108?"$3":"$2-$3"))+n;case 115:return ~O(n,"stretch",0)?ve(C(n,"stretch","fill-available"),c,s)+n:n}break;case 5152:case 5920:return C(n,/(.+?):(\d+)(\s*\/\s*(span)?\s*(\d+))?(.*)/,(function(r,a,c,s,t,u,i){return e+a+":"+c+i+(s?e+a+"-span:"+(t?u:+u-+c)+i:"")+n}));case 4949:if(A(n,c+6)===121)return C(n,":",":"+a)+n;break;case 6444:switch(A(n,A(n,14)===45?18:11)){case 120:return C(n,/(.+:)([^;\s!]+)(;|(\s+)?!.+)?/,"$1"+a+(A(n,14)===45?"inline-":"")+"box$3"+"$1"+a+"$2$3"+"$1"+e+"$2box$3")+n;case 100:return C(n,":",":"+e)+n}break;case 5719:case 2647:case 2135:case 3927:case 2391:return C(n,"scroll-","scroll-snap-")+n}return n}function pe(e,r){var a="";for(var n=0;n<e.length;n++)a+=r(e[n],n,e,r)||"";return a}function he(e,r,a,t){switch(e.type){case g:if(e.children.length)break;case i:case s:return e.return=e.return||e.value;case n:return "";case h:return e.return=e.value+"{"+pe(e.children,t)+"}";case c:if(!S(e.value=e.props.join(",")))return ""}return S(a=pe(e.children,t))?e.return=e.value+"{"+a+"}":""}function be(e){var r=q(e);return function(a,n,c,s){var t="";for(var u=0;u<r;u++)t+=e[u](a,n,c,s)||"";return t}}function we(e){return function(r){if(!r.root)if(r=r.return)e(r);}}function de(n,t,u,i){if(n.length>-1)if(!n.return)switch(n.type){case s:n.return=ve(n.value,n.length,u);return;case h:return pe([N(n,{value:C(n.value,"@","@"+a)})],i);case c:if(n.length)return D(u=n.props,(function(c){switch(z(c,i=/(::plac\w+|:read-\w+)/)){case":read-only":case":read-write":P(N(n,{props:[C(c,/:(read-\w+)/,":"+r+"$1")]}));P(N(n,{props:[c]}));x(n,{props:E(u,i)});break;case"::placeholder":P(N(n,{props:[C(c,/:(plac\w+)/,":"+a+"input-$1")]}));P(N(n,{props:[C(c,/:(plac\w+)/,":"+r+"$1")]}));P(N(n,{props:[C(c,/:(plac\w+)/,e+"input-$1")]}));P(N(n,{props:[c]}));x(n,{props:E(u,i)});break}return ""}))}}
619
620 var SEED$1 = 5381;
621 // When we have separate strings it's useful to run a progressive
622 // version of djb2 where we pretend that we're still looping over
623 // the same string
624 var phash = function (h, x) {
625 var i = x.length;
626 while (i) {
627 h = (h * 33) ^ x.charCodeAt(--i);
628 }
629 return h;
630 };
631 // This is a djb2 hashing function
632 var hash = function (x) {
633 return phash(SEED$1, x);
634 };
635
636 var AMP_REGEX = /&/g;
637 var COMMENT_REGEX = /^\s*\/\/.*$/gm;
638 /**
639 * Takes an element and recurses through it's rules added the namespace to the start of each selector.
640 * Takes into account media queries by recursing through child rules if they are present.
641 */
642 function recursivelySetNamepace(compiled, namespace) {
643 return compiled.map(function (rule) {
644 if (rule.type === 'rule') {
645 // add the namespace to the start
646 rule.value = "".concat(namespace, " ").concat(rule.value);
647 // add the namespace after each comma for subsequent selectors.
648 rule.value = rule.value.replaceAll(',', ",".concat(namespace, " "));
649 rule.props = rule.props.map(function (prop) {
650 return "".concat(namespace, " ").concat(prop);
651 });
652 }
653 if (Array.isArray(rule.children) && rule.type !== '@keyframes') {
654 rule.children = recursivelySetNamepace(rule.children, namespace);
655 }
656 return rule;
657 });
658 }
659 function createStylisInstance(_a) {
660 var _b = _a === void 0 ? EMPTY_OBJECT : _a, _c = _b.options, options = _c === void 0 ? EMPTY_OBJECT : _c, _d = _b.plugins, plugins = _d === void 0 ? EMPTY_ARRAY : _d;
661 var _componentId;
662 var _selector;
663 var _selectorRegexp;
664 var selfReferenceReplacer = function (match, offset, string) {
665 if (
666 /**
667 * We only want to refer to the static class directly if the selector is part of a
668 * self-reference selector `& + & { color: red; }`
669 */
670 string.startsWith(_selector) &&
671 string.endsWith(_selector) &&
672 string.replaceAll(_selector, '').length > 0) {
673 return ".".concat(_componentId);
674 }
675 return match;
676 };
677 /**
678 * When writing a style like
679 *
680 * & + & {
681 * color: red;
682 * }
683 *
684 * The second ampersand should be a reference to the static component class. stylis
685 * has no knowledge of static class so we have to intelligently replace the base selector.
686 *
687 * https://github.com/thysultan/stylis.js/tree/v4.0.2#abstract-syntax-structure
688 */
689 var selfReferenceReplacementPlugin = function (element) {
690 if (element.type === c && element.value.includes('&')) {
691 element.props[0] = element.props[0]
692 // catch any hanging references that stylis missed
693 .replace(AMP_REGEX, _selector)
694 .replace(_selectorRegexp, selfReferenceReplacer);
695 }
696 };
697 var middlewares = plugins.slice();
698 middlewares.push(selfReferenceReplacementPlugin);
699 /**
700 * Enables automatic vendor-prefixing for styles.
701 */
702 if (options.prefix) {
703 middlewares.push(de);
704 }
705 middlewares.push(he);
706 var stringifyRules = function (css, selector,
707 /**
708 * This "prefix" referes to a _selector_ prefix.
709 */
710 prefix, componentId) {
711 if (selector === void 0) { selector = ''; }
712 if (prefix === void 0) { prefix = ''; }
713 if (componentId === void 0) { componentId = '&'; }
714 // stylis has no concept of state to be passed to plugins
715 // but since JS is single-threaded, we can rely on that to ensure
716 // these properties stay in sync with the current stylis run
717 _componentId = componentId;
718 _selector = selector;
719 _selectorRegexp = new RegExp("\\".concat(_selector, "\\b"), 'g');
720 var flatCSS = css.replace(COMMENT_REGEX, '');
721 var compiled = ue(prefix || selector ? "".concat(prefix, " ").concat(selector, " { ").concat(flatCSS, " }") : flatCSS);
722 if (options.namespace) {
723 compiled = recursivelySetNamepace(compiled, options.namespace);
724 }
725 var stack = [];
726 pe(compiled, be(middlewares.concat(we(function (value) { return stack.push(value); }))));
727 return stack;
728 };
729 stringifyRules.hash = plugins.length
730 ? plugins
731 .reduce(function (acc, plugin) {
732 if (!plugin.name) {
733 throwStyledComponentsError(15);
734 }
735 return phash(acc, plugin.name);
736 }, SEED$1)
737 .toString()
738 : '';
739 return stringifyRules;
740 }
741
742 var mainSheet = new StyleSheet();
743 var mainStylis = createStylisInstance();
744 var StyleSheetContext = React.createContext({
745 shouldForwardProp: undefined,
746 styleSheet: mainSheet,
747 stylis: mainStylis,
748 });
749 var StyleSheetConsumer = StyleSheetContext.Consumer;
750 var StylisContext = React.createContext(undefined);
751 function useStyleSheetContext() {
752 return React.useContext(StyleSheetContext);
753 }
754 function StyleSheetManager(props) {
755 var _a = React.useState(props.stylisPlugins), plugins = _a[0], setPlugins = _a[1];
756 var styleSheet = useStyleSheetContext().styleSheet;
757 var resolvedStyleSheet = React.useMemo(function () {
758 var sheet = styleSheet;
759 if (props.sheet) {
760 sheet = props.sheet;
761 }
762 else if (props.target) {
763 sheet = sheet.reconstructWithOptions({ target: props.target }, false);
764 }
765 if (props.disableCSSOMInjection) {
766 sheet = sheet.reconstructWithOptions({ useCSSOMInjection: false });
767 }
768 return sheet;
769 }, [props.disableCSSOMInjection, props.sheet, props.target, styleSheet]);
770 var stylis = React.useMemo(function () {
771 return createStylisInstance({
772 options: { namespace: props.namespace, prefix: props.enableVendorPrefixes },
773 plugins: plugins,
774 });
775 }, [props.enableVendorPrefixes, props.namespace, plugins]);
776 React.useEffect(function () {
777 if (!shallowequal(plugins, props.stylisPlugins))
778 setPlugins(props.stylisPlugins);
779 }, [props.stylisPlugins]);
780 var styleSheetContextValue = React.useMemo(function () { return ({
781 shouldForwardProp: props.shouldForwardProp,
782 styleSheet: resolvedStyleSheet,
783 stylis: stylis,
784 }); }, [props.shouldForwardProp, resolvedStyleSheet, stylis]);
785 return (React.createElement(StyleSheetContext.Provider, { value: styleSheetContextValue },
786 React.createElement(StylisContext.Provider, { value: stylis }, props.children)));
787 }
788
789 var Keyframes = /** @class */ (function () {
790 function Keyframes(name, rules) {
791 var _this = this;
792 this.inject = function (styleSheet, stylisInstance) {
793 if (stylisInstance === void 0) { stylisInstance = mainStylis; }
794 var resolvedName = _this.name + stylisInstance.hash;
795 if (!styleSheet.hasNameForId(_this.id, resolvedName)) {
796 styleSheet.insertRules(_this.id, resolvedName, stylisInstance(_this.rules, resolvedName, '@keyframes'));
797 }
798 };
799 this.name = name;
800 this.id = "sc-keyframes-".concat(name);
801 this.rules = rules;
802 setToString(this, function () {
803 throw throwStyledComponentsError(12, String(_this.name));
804 });
805 }
806 Keyframes.prototype.getName = function (stylisInstance) {
807 if (stylisInstance === void 0) { stylisInstance = mainStylis; }
808 return this.name + stylisInstance.hash;
809 };
810 return Keyframes;
811 }());
812
813 var unitlessKeys = {
814 animationIterationCount: 1,
815 aspectRatio: 1,
816 borderImageOutset: 1,
817 borderImageSlice: 1,
818 borderImageWidth: 1,
819 boxFlex: 1,
820 boxFlexGroup: 1,
821 boxOrdinalGroup: 1,
822 columnCount: 1,
823 columns: 1,
824 flex: 1,
825 flexGrow: 1,
826 flexPositive: 1,
827 flexShrink: 1,
828 flexNegative: 1,
829 flexOrder: 1,
830 gridRow: 1,
831 gridRowEnd: 1,
832 gridRowSpan: 1,
833 gridRowStart: 1,
834 gridColumn: 1,
835 gridColumnEnd: 1,
836 gridColumnSpan: 1,
837 gridColumnStart: 1,
838 msGridRow: 1,
839 msGridRowSpan: 1,
840 msGridColumn: 1,
841 msGridColumnSpan: 1,
842 fontWeight: 1,
843 lineHeight: 1,
844 opacity: 1,
845 order: 1,
846 orphans: 1,
847 tabSize: 1,
848 widows: 1,
849 zIndex: 1,
850 zoom: 1,
851 WebkitLineClamp: 1,
852 // SVG-related properties
853 fillOpacity: 1,
854 floodOpacity: 1,
855 stopOpacity: 1,
856 strokeDasharray: 1,
857 strokeDashoffset: 1,
858 strokeMiterlimit: 1,
859 strokeOpacity: 1,
860 strokeWidth: 1
861 };
862
863 // Taken from https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/shared/dangerousStyleValue.js
864 function addUnitIfNeeded(name, value) {
865 // https://github.com/amilajack/eslint-plugin-flowtype-errors/issues/133
866 if (value == null || typeof value === 'boolean' || value === '') {
867 return '';
868 }
869 if (typeof value === 'number' && value !== 0 && !(name in unitlessKeys) && !name.startsWith('--')) {
870 return "".concat(value, "px"); // Presumes implicit 'px' suffix for unitless numbers except for CSS variables
871 }
872 return String(value).trim();
873 }
874
875 function getComponentName(target) {
876 return ((typeof target === 'string' && target ) ||
877 target.displayName ||
878 target.name ||
879 'Component');
880 }
881
882 var isUpper = function (c) { return c >= 'A' && c <= 'Z'; };
883 /**
884 * Hyphenates a camelcased CSS property name, for example:
885 *
886 * > hyphenateStyleName('backgroundColor')
887 * < "background-color"
888 * > hyphenateStyleName('MozTransition')
889 * < "-moz-transition"
890 * > hyphenateStyleName('msTransition')
891 * < "-ms-transition"
892 *
893 * As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix
894 * is converted to `-ms-`.
895 */
896 function hyphenateStyleName(string) {
897 var output = '';
898 for (var i = 0; i < string.length; i++) {
899 var c = string[i];
900 // Check for CSS variable prefix
901 if (i === 1 && c === '-' && string[0] === '-') {
902 return string;
903 }
904 if (isUpper(c)) {
905 output += '-' + c.toLowerCase();
906 }
907 else {
908 output += c;
909 }
910 }
911 return output.startsWith('ms-') ? '-' + output : output;
912 }
913
914 function isFunction(test) {
915 return typeof test === 'function';
916 }
917
918 function isPlainObject(x) {
919 return (x !== null &&
920 typeof x === 'object' &&
921 x.constructor.name === Object.name &&
922 /* check for reasonable markers that the object isn't an element for react & preact/compat */
923 !('props' in x && x.$$typeof));
924 }
925
926 function isStatelessFunction(test) {
927 return isFunction(test) && !(test.prototype && test.prototype.isReactComponent);
928 }
929
930 function isStyledComponent(target) {
931 return typeof target === 'object' && 'styledComponentId' in target;
932 }
933
934 /**
935 * It's falsish not falsy because 0 is allowed.
936 */
937 var isFalsish = function (chunk) {
938 return chunk === undefined || chunk === null || chunk === false || chunk === '';
939 };
940 var objToCssArray = function (obj) {
941 var rules = [];
942 for (var key in obj) {
943 var val = obj[key];
944 if (!obj.hasOwnProperty(key) || isFalsish(val))
945 continue;
946 // @ts-expect-error Property 'isCss' does not exist on type 'any[]'
947 if ((Array.isArray(val) && val.isCss) || isFunction(val)) {
948 rules.push("".concat(hyphenateStyleName(key), ":"), val, ';');
949 }
950 else if (isPlainObject(val)) {
951 rules.push.apply(rules, __spreadArray(__spreadArray(["".concat(key, " {")], objToCssArray(val), false), ['}'], false));
952 }
953 else {
954 rules.push("".concat(hyphenateStyleName(key), ": ").concat(addUnitIfNeeded(key, val), ";"));
955 }
956 }
957 return rules;
958 };
959 function flatten(chunk, executionContext, styleSheet, stylisInstance) {
960 if (isFalsish(chunk)) {
961 return [];
962 }
963 /* Handle other components */
964 if (isStyledComponent(chunk)) {
965 return [".".concat(chunk.styledComponentId)];
966 }
967 /* Either execute or defer the function */
968 if (isFunction(chunk)) {
969 if (isStatelessFunction(chunk) && executionContext) {
970 var result = chunk(executionContext);
971 if (typeof result === 'object' &&
972 !Array.isArray(result) &&
973 !(result instanceof Keyframes) &&
974 !isPlainObject(result) &&
975 result !== null) {
976 console.error("".concat(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."));
977 }
978 return flatten(result, executionContext, styleSheet, stylisInstance);
979 }
980 else {
981 return [chunk];
982 }
983 }
984 if (chunk instanceof Keyframes) {
985 if (styleSheet) {
986 chunk.inject(styleSheet, stylisInstance);
987 return [chunk.getName(stylisInstance)];
988 }
989 else {
990 return [chunk];
991 }
992 }
993 /* Handle objects */
994 if (isPlainObject(chunk)) {
995 return objToCssArray(chunk);
996 }
997 if (!Array.isArray(chunk)) {
998 return [chunk.toString()];
999 }
1000 return flatMap(chunk, function (chunklet) {
1001 return flatten(chunklet, executionContext, styleSheet, stylisInstance);
1002 });
1003 }
1004 function flatMap(array, transform) {
1005 return Array.prototype.concat.apply(EMPTY_ARRAY, array.map(transform));
1006 }
1007
1008 function isStaticRules(rules) {
1009 for (var i = 0; i < rules.length; i += 1) {
1010 var rule = rules[i];
1011 if (isFunction(rule) && !isStyledComponent(rule)) {
1012 // functions are allowed to be static if they're just being
1013 // used to get the classname of a nested styled component
1014 return false;
1015 }
1016 }
1017 return true;
1018 }
1019
1020 /**
1021 * Convenience function for joining strings to form className chains
1022 */
1023 function joinStrings(a, b) {
1024 return a && b ? "".concat(a, " ").concat(b) : a || b || '';
1025 }
1026 function joinStringArray(arr, sep) {
1027 if (arr.length === 0) {
1028 return '';
1029 }
1030 var result = arr[0];
1031 for (var i = 1; i < arr.length; i++) {
1032 result += sep ? sep + arr[i] : arr[i];
1033 }
1034 return result;
1035 }
1036
1037 var GlobalStyle = /** @class */ (function () {
1038 function GlobalStyle(rules, componentId) {
1039 this.rules = rules;
1040 this.componentId = componentId;
1041 this.isStatic = isStaticRules(rules);
1042 // pre-register the first instance to ensure global styles
1043 // load before component ones
1044 StyleSheet.registerId(this.componentId + 1);
1045 }
1046 GlobalStyle.prototype.createStyles = function (instance, executionContext, styleSheet, stylis) {
1047 var flatCSS = joinStringArray(flatten(this.rules, executionContext, styleSheet, stylis));
1048 var css = stylis(flatCSS, '');
1049 var id = this.componentId + instance;
1050 // NOTE: We use the id as a name as well, since these rules never change
1051 styleSheet.insertRules(id, id, css);
1052 };
1053 GlobalStyle.prototype.removeStyles = function (instance, styleSheet) {
1054 styleSheet.clearRules(this.componentId + instance);
1055 };
1056 GlobalStyle.prototype.renderStyles = function (instance, executionContext, styleSheet, stylis) {
1057 if (instance > 2)
1058 StyleSheet.registerId(this.componentId + instance);
1059 // NOTE: Remove old styles, then inject the new ones
1060 this.removeStyles(instance, styleSheet);
1061 this.createStyles(instance, executionContext, styleSheet, stylis);
1062 };
1063 return GlobalStyle;
1064 }());
1065
1066 var ThemeContext = React.createContext(undefined);
1067 var ThemeConsumer = ThemeContext.Consumer;
1068 function mergeTheme(theme, outerTheme) {
1069 if (!theme) {
1070 throw throwStyledComponentsError(14);
1071 }
1072 if (isFunction(theme)) {
1073 var themeFn = theme;
1074 var mergedTheme = themeFn(outerTheme);
1075 if ((mergedTheme === null || Array.isArray(mergedTheme) || typeof mergedTheme !== 'object')) {
1076 throw throwStyledComponentsError(7);
1077 }
1078 return mergedTheme;
1079 }
1080 if (Array.isArray(theme) || typeof theme !== 'object') {
1081 throw throwStyledComponentsError(8);
1082 }
1083 return outerTheme ? __assign(__assign({}, outerTheme), theme) : theme;
1084 }
1085 /**
1086 * Returns the current theme (as provided by the closest ancestor `ThemeProvider`.)
1087 *
1088 * If no `ThemeProvider` is found, the function will error. If you need access to the theme in an
1089 * uncertain composition scenario, `React.useContext(ThemeContext)` will not emit an error if there
1090 * is no `ThemeProvider` ancestor.
1091 */
1092 function useTheme() {
1093 var theme = React.useContext(ThemeContext);
1094 if (!theme) {
1095 throw throwStyledComponentsError(18);
1096 }
1097 return theme;
1098 }
1099 /**
1100 * Provide a theme to an entire react component tree via context
1101 */
1102 function ThemeProvider(props) {
1103 var outerTheme = React.useContext(ThemeContext);
1104 var themeContext = React.useMemo(function () { return mergeTheme(props.theme, outerTheme); }, [props.theme, outerTheme]);
1105 if (!props.children) {
1106 return null;
1107 }
1108 return React.createElement(ThemeContext.Provider, { value: themeContext }, props.children);
1109 }
1110
1111 var invalidHookCallRe = /invalid hook call/i;
1112 var seen = new Set();
1113 var checkDynamicCreation = function (displayName, componentId) {
1114 {
1115 var parsedIdString = componentId ? " with the id of \"".concat(componentId, "\"") : '';
1116 var message_1 = "The component ".concat(displayName).concat(parsedIdString, " has been created dynamically.\n") +
1117 "You may see this warning because you've called styled inside another component.\n" +
1118 'To resolve this only create new StyledComponents outside of any render method and function component.';
1119 // If a hook is called outside of a component:
1120 // React 17 and earlier throw an error
1121 // React 18 and above use console.error
1122 var originalConsoleError_1 = console.error;
1123 try {
1124 var didNotCallInvalidHook_1 = true;
1125 console.error = function (consoleErrorMessage) {
1126 var consoleErrorArgs = [];
1127 for (var _i = 1; _i < arguments.length; _i++) {
1128 consoleErrorArgs[_i - 1] = arguments[_i];
1129 }
1130 // The error here is expected, since we're expecting anything that uses `checkDynamicCreation` to
1131 // be called outside of a React component.
1132 if (invalidHookCallRe.test(consoleErrorMessage)) {
1133 didNotCallInvalidHook_1 = false;
1134 // This shouldn't happen, but resets `warningSeen` if we had this error happen intermittently
1135 seen.delete(message_1);
1136 }
1137 else {
1138 originalConsoleError_1.apply(void 0, __spreadArray([consoleErrorMessage], consoleErrorArgs, false));
1139 }
1140 };
1141 // We purposefully call `useRef` outside of a component and expect it to throw
1142 // If it doesn't, then we're inside another component.
1143 React.useRef();
1144 if (didNotCallInvalidHook_1 && !seen.has(message_1)) {
1145 console.warn(message_1);
1146 seen.add(message_1);
1147 }
1148 }
1149 catch (error) {
1150 // The error here is expected, since we're expecting anything that uses `checkDynamicCreation` to
1151 // be called outside of a React component.
1152 if (invalidHookCallRe.test(error.message)) {
1153 // This shouldn't happen, but resets `warningSeen` if we had this error happen intermittently
1154 seen.delete(message_1);
1155 }
1156 }
1157 finally {
1158 console.error = originalConsoleError_1;
1159 }
1160 }
1161 };
1162
1163 function determineTheme(props, providedTheme, defaultProps) {
1164 if (defaultProps === void 0) { defaultProps = EMPTY_OBJECT; }
1165 return (props.theme !== defaultProps.theme && props.theme) || providedTheme || defaultProps.theme;
1166 }
1167
1168 var AD_REPLACER_R = /(a)(d)/gi;
1169 /* This is the "capacity" of our alphabet i.e. 2x26 for all letters plus their capitalised
1170 * counterparts */
1171 var charsLength = 52;
1172 /* start at 75 for 'a' until 'z' (25) and then start at 65 for capitalised letters */
1173 var getAlphabeticChar = function (code) { return String.fromCharCode(code + (code > 25 ? 39 : 97)); };
1174 /* input a number, usually a hash and convert it to base-52 */
1175 function generateAlphabeticName(code) {
1176 var name = '';
1177 var x;
1178 /* get a char and divide by alphabet-length */
1179 for (x = Math.abs(code); x > charsLength; x = (x / charsLength) | 0) {
1180 name = getAlphabeticChar(x % charsLength) + name;
1181 }
1182 return (getAlphabeticChar(x % charsLength) + name).replace(AD_REPLACER_R, '$1-$2');
1183 }
1184
1185 function generateComponentId(str) {
1186 return generateAlphabeticName(hash(str) >>> 0);
1187 }
1188
1189 function interleave(strings, interpolations) {
1190 var result = [strings[0]];
1191 for (var i = 0, len = interpolations.length; i < len; i += 1) {
1192 result.push(interpolations[i], strings[i + 1]);
1193 }
1194 return result;
1195 }
1196
1197 /**
1198 * Used when flattening object styles to determine if we should
1199 * expand an array of styles.
1200 */
1201 var addTag = function (arg) {
1202 return Object.assign(arg, { isCss: true });
1203 };
1204 function css(styles) {
1205 var interpolations = [];
1206 for (var _i = 1; _i < arguments.length; _i++) {
1207 interpolations[_i - 1] = arguments[_i];
1208 }
1209 if (isFunction(styles) || isPlainObject(styles)) {
1210 var styleFunctionOrObject = styles;
1211 return addTag(flatten(interleave(EMPTY_ARRAY, __spreadArray([
1212 styleFunctionOrObject
1213 ], interpolations, true))));
1214 }
1215 var styleStringArray = styles;
1216 if (interpolations.length === 0 &&
1217 styleStringArray.length === 1 &&
1218 typeof styleStringArray[0] === 'string') {
1219 return flatten(styleStringArray);
1220 }
1221 return addTag(flatten(interleave(styleStringArray, interpolations)));
1222 }
1223
1224 function createGlobalStyle(strings) {
1225 var interpolations = [];
1226 for (var _i = 1; _i < arguments.length; _i++) {
1227 interpolations[_i - 1] = arguments[_i];
1228 }
1229 var rules = css.apply(void 0, __spreadArray([strings], interpolations, false));
1230 var styledComponentId = "sc-global-".concat(generateComponentId(JSON.stringify(rules)));
1231 var globalStyle = new GlobalStyle(rules, styledComponentId);
1232 {
1233 checkDynamicCreation(styledComponentId);
1234 }
1235 var GlobalStyleComponent = function (props) {
1236 var ssc = useStyleSheetContext();
1237 var theme = React.useContext(ThemeContext);
1238 var instanceRef = React.useRef(ssc.styleSheet.allocateGSInstance(styledComponentId));
1239 var instance = instanceRef.current;
1240 if (React.Children.count(props.children)) {
1241 console.warn("The global style component ".concat(styledComponentId, " was given child JSX. createGlobalStyle does not render children."));
1242 }
1243 if (rules.some(function (rule) { return typeof rule === 'string' && rule.indexOf('@import') !== -1; })) {
1244 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.");
1245 }
1246 if (ssc.styleSheet.server) {
1247 renderStyles(instance, props, ssc.styleSheet, theme, ssc.stylis);
1248 }
1249 {
1250 React.useLayoutEffect(function () {
1251 if (!ssc.styleSheet.server) {
1252 renderStyles(instance, props, ssc.styleSheet, theme, ssc.stylis);
1253 return function () { return globalStyle.removeStyles(instance, ssc.styleSheet); };
1254 }
1255 }, [instance, props, ssc.styleSheet, theme, ssc.stylis]);
1256 }
1257 return null;
1258 };
1259 function renderStyles(instance, props, styleSheet, theme, stylis) {
1260 if (globalStyle.isStatic) {
1261 globalStyle.renderStyles(instance, STATIC_EXECUTION_CONTEXT, styleSheet, stylis);
1262 }
1263 else {
1264 var context = __assign(__assign({}, props), { theme: determineTheme(props, theme, GlobalStyleComponent.defaultProps) });
1265 globalStyle.renderStyles(instance, context, styleSheet, stylis);
1266 }
1267 }
1268 return React.memo(GlobalStyleComponent);
1269 }
1270
1271 function keyframes(strings) {
1272 var interpolations = [];
1273 for (var _i = 1; _i < arguments.length; _i++) {
1274 interpolations[_i - 1] = arguments[_i];
1275 }
1276 /* Warning if you've used keyframes on React Native */
1277 if (typeof navigator !== 'undefined' &&
1278 navigator.product === 'ReactNative') {
1279 console.warn('`keyframes` cannot be used on ReactNative, only on the web. To do animation in ReactNative please use Animated.');
1280 }
1281 var rules = joinStringArray(css.apply(void 0, __spreadArray([strings], interpolations, false)));
1282 var name = generateComponentId(rules);
1283 return new Keyframes(name, rules);
1284 }
1285
1286 var _a;
1287 var hasSymbol = typeof Symbol === 'function' && Symbol.for;
1288 // copied from react-is
1289 var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
1290 var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
1291 /**
1292 * Adapted from hoist-non-react-statics to avoid the react-is dependency.
1293 */
1294 var REACT_STATICS = {
1295 childContextTypes: true,
1296 contextType: true,
1297 contextTypes: true,
1298 defaultProps: true,
1299 displayName: true,
1300 getDefaultProps: true,
1301 getDerivedStateFromError: true,
1302 getDerivedStateFromProps: true,
1303 mixins: true,
1304 propTypes: true,
1305 type: true,
1306 };
1307 var KNOWN_STATICS = {
1308 name: true,
1309 length: true,
1310 prototype: true,
1311 caller: true,
1312 callee: true,
1313 arguments: true,
1314 arity: true,
1315 };
1316 var FORWARD_REF_STATICS = {
1317 $$typeof: true,
1318 render: true,
1319 defaultProps: true,
1320 displayName: true,
1321 propTypes: true,
1322 };
1323 var MEMO_STATICS = {
1324 $$typeof: true,
1325 compare: true,
1326 defaultProps: true,
1327 displayName: true,
1328 propTypes: true,
1329 type: true,
1330 };
1331 var TYPE_STATICS = (_a = {},
1332 _a[REACT_FORWARD_REF_TYPE] = FORWARD_REF_STATICS,
1333 _a[REACT_MEMO_TYPE] = MEMO_STATICS,
1334 _a);
1335 // adapted from react-is
1336 function isMemo(object) {
1337 var $$typeofType = 'type' in object && object.type.$$typeof;
1338 return $$typeofType === REACT_MEMO_TYPE;
1339 }
1340 function getStatics(component) {
1341 // React v16.11 and below
1342 if (isMemo(component)) {
1343 return MEMO_STATICS;
1344 }
1345 // React v16.12 and above
1346 return '$$typeof' in component
1347 ? TYPE_STATICS[component['$$typeof']]
1348 : REACT_STATICS;
1349 }
1350 var defineProperty = Object.defineProperty;
1351 var getOwnPropertyNames = Object.getOwnPropertyNames;
1352 var getOwnPropertySymbols = Object.getOwnPropertySymbols;
1353 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
1354 var getPrototypeOf = Object.getPrototypeOf;
1355 var objectPrototype = Object.prototype;
1356 function hoistNonReactStatics(targetComponent, sourceComponent, excludelist) {
1357 if (typeof sourceComponent !== 'string') {
1358 // don't hoist over string (html) components
1359 if (objectPrototype) {
1360 var inheritedComponent = getPrototypeOf(sourceComponent);
1361 if (inheritedComponent && inheritedComponent !== objectPrototype) {
1362 hoistNonReactStatics(targetComponent, inheritedComponent, excludelist);
1363 }
1364 }
1365 var keys = getOwnPropertyNames(sourceComponent);
1366 if (getOwnPropertySymbols) {
1367 keys = keys.concat(getOwnPropertySymbols(sourceComponent));
1368 }
1369 var targetStatics = getStatics(targetComponent);
1370 var sourceStatics = getStatics(sourceComponent);
1371 for (var i = 0; i < keys.length; ++i) {
1372 var key = keys[i];
1373 if (!(key in KNOWN_STATICS) &&
1374 !(excludelist && excludelist[key]) &&
1375 !(sourceStatics && key in sourceStatics) &&
1376 !(targetStatics && key in targetStatics)) {
1377 var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
1378 try {
1379 // Avoid failures from read-only properties
1380 defineProperty(targetComponent, key, descriptor);
1381 }
1382 catch (e) {
1383 /* ignore */
1384 }
1385 }
1386 }
1387 }
1388 return targetComponent;
1389 }
1390
1391 function withTheme(Component) {
1392 var WithTheme = React.forwardRef(function (props, ref) {
1393 var theme = React.useContext(ThemeContext);
1394 var themeProp = determineTheme(props, theme, Component.defaultProps);
1395 if (themeProp === undefined) {
1396 console.warn("[withTheme] You are not using a ThemeProvider nor passing a theme prop or a theme in defaultProps in component class \"".concat(getComponentName(Component), "\""));
1397 }
1398 return React.createElement(Component, __assign({}, props, { theme: themeProp, ref: ref }));
1399 });
1400 WithTheme.displayName = "WithTheme(".concat(getComponentName(Component), ")");
1401 return hoistNonReactStatics(WithTheme, Component);
1402 }
1403
1404 var ServerStyleSheet = /** @class */ (function () {
1405 function ServerStyleSheet() {
1406 var _this = this;
1407 this._emitSheetCSS = function () {
1408 var css = _this.instance.toString();
1409 if (!css)
1410 return '';
1411 var nonce = getNonce();
1412 var attrs = [
1413 nonce && "nonce=\"".concat(nonce, "\""),
1414 "".concat(SC_ATTR, "=\"true\""),
1415 "".concat(SC_ATTR_VERSION, "=\"").concat(SC_VERSION, "\""),
1416 ];
1417 var htmlAttr = joinStringArray(attrs.filter(Boolean), ' ');
1418 return "<style ".concat(htmlAttr, ">").concat(css, "</style>");
1419 };
1420 this.getStyleTags = function () {
1421 if (_this.sealed) {
1422 throw throwStyledComponentsError(2);
1423 }
1424 return _this._emitSheetCSS();
1425 };
1426 this.getStyleElement = function () {
1427 var _a;
1428 if (_this.sealed) {
1429 throw throwStyledComponentsError(2);
1430 }
1431 var css = _this.instance.toString();
1432 if (!css)
1433 return [];
1434 var props = (_a = {},
1435 _a[SC_ATTR] = '',
1436 _a[SC_ATTR_VERSION] = SC_VERSION,
1437 _a.dangerouslySetInnerHTML = {
1438 __html: css,
1439 },
1440 _a);
1441 var nonce = getNonce();
1442 if (nonce) {
1443 props.nonce = nonce;
1444 }
1445 // v4 returned an array for this fn, so we'll do the same for v5 for backward compat
1446 return [React.createElement("style", __assign({}, props, { key: "sc-0-0" }))];
1447 };
1448 this.seal = function () {
1449 _this.sealed = true;
1450 };
1451 this.instance = new StyleSheet({ isServer: true });
1452 this.sealed = false;
1453 }
1454 ServerStyleSheet.prototype.collectStyles = function (children) {
1455 if (this.sealed) {
1456 throw throwStyledComponentsError(2);
1457 }
1458 return React.createElement(StyleSheetManager, { sheet: this.instance }, children);
1459 };
1460 // @ts-expect-error alternate return types are not possible due to code transformation
1461 ServerStyleSheet.prototype.interleaveWithNodeStream = function (input) {
1462 {
1463 throw throwStyledComponentsError(3);
1464 }
1465 };
1466 return ServerStyleSheet;
1467 }());
1468
1469 var __PRIVATE__ = {
1470 StyleSheet: StyleSheet,
1471 mainSheet: mainSheet,
1472 };
1473
1474 /* Import singletons */
1475 /* Warning if you've imported this file on React Native */
1476 if (typeof navigator !== 'undefined' &&
1477 navigator.product === 'ReactNative') {
1478 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");
1479 }
1480 var windowGlobalKey = "__sc-".concat(SC_ATTR, "__");
1481 /* Warning if there are several instances of styled-components */
1482 if (typeof window !== 'undefined') {
1483 // @ts-expect-error dynamic key not in window object
1484 window[windowGlobalKey] || (window[windowGlobalKey] = 0);
1485 // @ts-expect-error dynamic key not in window object
1486 if (window[windowGlobalKey] === 1) {
1487 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://s-c.sh/2BAXzed for more info.");
1488 }
1489 // @ts-expect-error dynamic key not in window object
1490 window[windowGlobalKey] += 1;
1491 }
1492
1493 var secondary = /*#__PURE__*/Object.freeze({
1494 __proto__: null,
1495 ServerStyleSheet: ServerStyleSheet,
1496 StyleSheetConsumer: StyleSheetConsumer,
1497 StyleSheetContext: StyleSheetContext,
1498 StyleSheetManager: StyleSheetManager,
1499 ThemeConsumer: ThemeConsumer,
1500 ThemeContext: ThemeContext,
1501 ThemeProvider: ThemeProvider,
1502 __PRIVATE__: __PRIVATE__,
1503 createGlobalStyle: createGlobalStyle,
1504 css: css,
1505 isStyledComponent: isStyledComponent,
1506 keyframes: keyframes,
1507 useTheme: useTheme,
1508 version: SC_VERSION,
1509 withTheme: withTheme
1510 });
1511
1512 function memoize(fn) {
1513 var cache = Object.create(null);
1514 return function (arg) {
1515 if (cache[arg] === undefined) cache[arg] = fn(arg);
1516 return cache[arg];
1517 };
1518 }
1519
1520 var reactPropsRegex = /^((children|dangerouslySetInnerHTML|key|ref|autoFocus|defaultValue|defaultChecked|innerHTML|suppressContentEditableWarning|suppressHydrationWarning|valueLink|abbr|accept|acceptCharset|accessKey|action|allow|allowUserMedia|allowPaymentRequest|allowFullScreen|allowTransparency|alt|async|autoComplete|autoPlay|capture|cellPadding|cellSpacing|challenge|charSet|checked|cite|classID|className|cols|colSpan|content|contentEditable|contextMenu|controls|controlsList|coords|crossOrigin|data|dateTime|decoding|default|defer|dir|disabled|disablePictureInPicture|disableRemotePlayback|download|draggable|encType|enterKeyHint|form|formAction|formEncType|formMethod|formNoValidate|formTarget|frameBorder|headers|height|hidden|high|href|hrefLang|htmlFor|httpEquiv|id|inputMode|integrity|is|keyParams|keyType|kind|label|lang|list|loading|loop|low|marginHeight|marginWidth|max|maxLength|media|mediaGroup|method|min|minLength|multiple|muted|name|nonce|noValidate|open|optimum|pattern|placeholder|playsInline|poster|preload|profile|radioGroup|readOnly|referrerPolicy|rel|required|reversed|role|rows|rowSpan|sandbox|scope|scoped|scrolling|seamless|selected|shape|size|sizes|slot|span|spellCheck|src|srcDoc|srcLang|srcSet|start|step|style|summary|tabIndex|target|title|translate|type|useMap|value|width|wmode|wrap|about|datatype|inlist|prefix|property|resource|typeof|vocab|autoCapitalize|autoCorrect|autoSave|color|incremental|fallback|inert|itemProp|itemScope|itemType|itemID|itemRef|on|option|results|security|unselectable|accentHeight|accumulate|additive|alignmentBaseline|allowReorder|alphabetic|amplitude|arabicForm|ascent|attributeName|attributeType|autoReverse|azimuth|baseFrequency|baselineShift|baseProfile|bbox|begin|bias|by|calcMode|capHeight|clip|clipPathUnits|clipPath|clipRule|colorInterpolation|colorInterpolationFilters|colorProfile|colorRendering|contentScriptType|contentStyleType|cursor|cx|cy|d|decelerate|descent|diffuseConstant|direction|display|divisor|dominantBaseline|dur|dx|dy|edgeMode|elevation|enableBackground|end|exponent|externalResourcesRequired|fill|fillOpacity|fillRule|filter|filterRes|filterUnits|floodColor|floodOpacity|focusable|fontFamily|fontSize|fontSizeAdjust|fontStretch|fontStyle|fontVariant|fontWeight|format|from|fr|fx|fy|g1|g2|glyphName|glyphOrientationHorizontal|glyphOrientationVertical|glyphRef|gradientTransform|gradientUnits|hanging|horizAdvX|horizOriginX|ideographic|imageRendering|in|in2|intercept|k|k1|k2|k3|k4|kernelMatrix|kernelUnitLength|kerning|keyPoints|keySplines|keyTimes|lengthAdjust|letterSpacing|lightingColor|limitingConeAngle|local|markerEnd|markerMid|markerStart|markerHeight|markerUnits|markerWidth|mask|maskContentUnits|maskUnits|mathematical|mode|numOctaves|offset|opacity|operator|order|orient|orientation|origin|overflow|overlinePosition|overlineThickness|panose1|paintOrder|pathLength|patternContentUnits|patternTransform|patternUnits|pointerEvents|points|pointsAtX|pointsAtY|pointsAtZ|preserveAlpha|preserveAspectRatio|primitiveUnits|r|radius|refX|refY|renderingIntent|repeatCount|repeatDur|requiredExtensions|requiredFeatures|restart|result|rotate|rx|ry|scale|seed|shapeRendering|slope|spacing|specularConstant|specularExponent|speed|spreadMethod|startOffset|stdDeviation|stemh|stemv|stitchTiles|stopColor|stopOpacity|strikethroughPosition|strikethroughThickness|string|stroke|strokeDasharray|strokeDashoffset|strokeLinecap|strokeLinejoin|strokeMiterlimit|strokeOpacity|strokeWidth|surfaceScale|systemLanguage|tableValues|targetX|targetY|textAnchor|textDecoration|textRendering|textLength|to|transform|u1|u2|underlinePosition|underlineThickness|unicode|unicodeBidi|unicodeRange|unitsPerEm|vAlphabetic|vHanging|vIdeographic|vMathematical|values|vectorEffect|version|vertAdvY|vertOriginX|vertOriginY|viewBox|viewTarget|visibility|widths|wordSpacing|writingMode|x|xHeight|x1|x2|xChannelSelector|xlinkActuate|xlinkArcrole|xlinkHref|xlinkRole|xlinkShow|xlinkTitle|xlinkType|xmlBase|xmlns|xmlnsXlink|xmlLang|xmlSpace|y|y1|y2|yChannelSelector|z|zoomAndPan|for|class|autofocus)|(([Dd][Aa][Tt][Aa]|[Aa][Rr][Ii][Aa]|x)-.*))$/; // https://esbench.com/bench/5bfee68a4cd7e6009ef61d23
1521
1522 var isPropValid = /* #__PURE__ */memoize(function (prop) {
1523 return reactPropsRegex.test(prop) || prop.charCodeAt(0) === 111
1524 /* o */
1525 && prop.charCodeAt(1) === 110
1526 /* n */
1527 && prop.charCodeAt(2) < 91;
1528 }
1529 /* Z+1 */
1530 );
1531
1532 var LIMIT = 200;
1533 var createWarnTooManyClasses = (function (displayName, componentId) {
1534 var generatedClasses = {};
1535 var warningSeen = false;
1536 return function (className) {
1537 if (!warningSeen) {
1538 generatedClasses[className] = true;
1539 if (Object.keys(generatedClasses).length >= LIMIT) {
1540 // Unable to find latestRule in test environment.
1541 var parsedIdString = componentId ? " with the id of \"".concat(componentId, "\"") : '';
1542 console.warn("Over ".concat(LIMIT, " classes were generated for component ").concat(displayName).concat(parsedIdString, ".\n") +
1543 'Consider using the attrs method, together with a style object for frequently changed styles.\n' +
1544 'Example:\n' +
1545 ' const Component = styled.div.attrs(props => ({\n' +
1546 ' style: {\n' +
1547 ' background: props.background,\n' +
1548 ' },\n' +
1549 ' }))`width: 100%;`\n\n' +
1550 ' <Component />');
1551 warningSeen = true;
1552 generatedClasses = {};
1553 }
1554 }
1555 };
1556 });
1557
1558 // Thanks to ReactDOMFactories for this handy list!
1559 var elements = [
1560 'a',
1561 'abbr',
1562 'address',
1563 'area',
1564 'article',
1565 'aside',
1566 'audio',
1567 'b',
1568 'base',
1569 'bdi',
1570 'bdo',
1571 'big',
1572 'blockquote',
1573 'body',
1574 'br',
1575 'button',
1576 'canvas',
1577 'caption',
1578 'cite',
1579 'code',
1580 'col',
1581 'colgroup',
1582 'data',
1583 'datalist',
1584 'dd',
1585 'del',
1586 'details',
1587 'dfn',
1588 'dialog',
1589 'div',
1590 'dl',
1591 'dt',
1592 'em',
1593 'embed',
1594 'fieldset',
1595 'figcaption',
1596 'figure',
1597 'footer',
1598 'form',
1599 'h1',
1600 'h2',
1601 'h3',
1602 'h4',
1603 'h5',
1604 'h6',
1605 'header',
1606 'hgroup',
1607 'hr',
1608 'html',
1609 'i',
1610 'iframe',
1611 'img',
1612 'input',
1613 'ins',
1614 'kbd',
1615 'keygen',
1616 'label',
1617 'legend',
1618 'li',
1619 'link',
1620 'main',
1621 'map',
1622 'mark',
1623 'menu',
1624 'menuitem',
1625 'meta',
1626 'meter',
1627 'nav',
1628 'noscript',
1629 'object',
1630 'ol',
1631 'optgroup',
1632 'option',
1633 'output',
1634 'p',
1635 'param',
1636 'picture',
1637 'pre',
1638 'progress',
1639 'q',
1640 'rp',
1641 'rt',
1642 'ruby',
1643 's',
1644 'samp',
1645 'script',
1646 'section',
1647 'select',
1648 'small',
1649 'source',
1650 'span',
1651 'strong',
1652 'style',
1653 'sub',
1654 'summary',
1655 'sup',
1656 'table',
1657 'tbody',
1658 'td',
1659 'textarea',
1660 'tfoot',
1661 'th',
1662 'thead',
1663 'time',
1664 'tr',
1665 'track',
1666 'u',
1667 'ul',
1668 'use',
1669 'var',
1670 'video',
1671 'wbr', // SVG
1672 'circle',
1673 'clipPath',
1674 'defs',
1675 'ellipse',
1676 'foreignObject',
1677 'g',
1678 'image',
1679 'line',
1680 'linearGradient',
1681 'marker',
1682 'mask',
1683 'path',
1684 'pattern',
1685 'polygon',
1686 'polyline',
1687 'radialGradient',
1688 'rect',
1689 'stop',
1690 'svg',
1691 'text',
1692 'tspan',
1693 ];
1694 var domElements = new Set(elements);
1695
1696 // Source: https://www.w3.org/TR/cssom-1/#serialize-an-identifier
1697 // Control characters and non-letter first symbols are not supported
1698 var escapeRegex = /[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~-]+/g;
1699 var dashesAtEnds = /(^-|-$)/g;
1700 /**
1701 * TODO: Explore using CSS.escape when it becomes more available
1702 * in evergreen browsers.
1703 */
1704 function escape(str) {
1705 return str // Replace all possible CSS selectors
1706 .replace(escapeRegex, '-') // Remove extraneous hyphens at the start and end
1707 .replace(dashesAtEnds, '');
1708 }
1709
1710 function isTag(target) {
1711 return (typeof target === 'string' &&
1712 (target.charAt(0) === target.charAt(0).toLowerCase()
1713 ));
1714 }
1715
1716 function generateDisplayName(target) {
1717 return isTag(target) ? "styled.".concat(target) : "Styled(".concat(getComponentName(target), ")");
1718 }
1719
1720 function mixinRecursively(target, source, forceMerge) {
1721 if (forceMerge === void 0) { forceMerge = false; }
1722 /* only merge into POJOs, Arrays, but for top level objects only
1723 * allow to merge into anything by passing forceMerge = true */
1724 if (!forceMerge && !isPlainObject(target) && !Array.isArray(target)) {
1725 return source;
1726 }
1727 if (Array.isArray(source)) {
1728 for (var key = 0; key < source.length; key++) {
1729 target[key] = mixinRecursively(target[key], source[key]);
1730 }
1731 }
1732 else if (isPlainObject(source)) {
1733 for (var key in source) {
1734 target[key] = mixinRecursively(target[key], source[key]);
1735 }
1736 }
1737 return target;
1738 }
1739 /**
1740 * Arrays & POJOs merged recursively, other objects and value types are overridden
1741 * If target is not a POJO or an Array, it will get source properties injected via shallow merge
1742 * Source objects applied left to right. Mutates & returns target. Similar to lodash merge.
1743 */
1744 function mixinDeep(target) {
1745 var sources = [];
1746 for (var _i = 1; _i < arguments.length; _i++) {
1747 sources[_i - 1] = arguments[_i];
1748 }
1749 for (var _a = 0, sources_1 = sources; _a < sources_1.length; _a++) {
1750 var source = sources_1[_a];
1751 mixinRecursively(target, source, true);
1752 }
1753 return target;
1754 }
1755
1756 var SEED = hash(SC_VERSION);
1757 /**
1758 * ComponentStyle is all the CSS-specific stuff, not the React-specific stuff.
1759 */
1760 var ComponentStyle = /** @class */ (function () {
1761 function ComponentStyle(rules, componentId, baseStyle) {
1762 this.rules = rules;
1763 this.staticRulesId = '';
1764 this.isStatic =
1765 "development" === 'production' ;
1766 this.componentId = componentId;
1767 this.baseHash = phash(SEED, componentId);
1768 this.baseStyle = baseStyle;
1769 // NOTE: This registers the componentId, which ensures a consistent order
1770 // for this component's styles compared to others
1771 StyleSheet.registerId(componentId);
1772 }
1773 ComponentStyle.prototype.generateAndInjectStyles = function (executionContext, styleSheet, stylis) {
1774 var names = this.baseStyle
1775 ? this.baseStyle.generateAndInjectStyles(executionContext, styleSheet, stylis)
1776 : '';
1777 // force dynamic classnames if user-supplied stylis plugins are in use
1778 if (this.isStatic && !stylis.hash) {
1779 if (this.staticRulesId && styleSheet.hasNameForId(this.componentId, this.staticRulesId)) {
1780 names = joinStrings(names, this.staticRulesId);
1781 }
1782 else {
1783 var cssStatic = joinStringArray(flatten(this.rules, executionContext, styleSheet, stylis));
1784 var name_1 = generateAlphabeticName(phash(this.baseHash, cssStatic) >>> 0);
1785 if (!styleSheet.hasNameForId(this.componentId, name_1)) {
1786 var cssStaticFormatted = stylis(cssStatic, ".".concat(name_1), undefined, this.componentId);
1787 styleSheet.insertRules(this.componentId, name_1, cssStaticFormatted);
1788 }
1789 names = joinStrings(names, name_1);
1790 this.staticRulesId = name_1;
1791 }
1792 }
1793 else {
1794 var dynamicHash = phash(this.baseHash, stylis.hash);
1795 var css = '';
1796 for (var i = 0; i < this.rules.length; i++) {
1797 var partRule = this.rules[i];
1798 if (typeof partRule === 'string') {
1799 css += partRule;
1800 dynamicHash = phash(dynamicHash, partRule);
1801 }
1802 else if (partRule) {
1803 var partString = joinStringArray(flatten(partRule, executionContext, styleSheet, stylis));
1804 // The same value can switch positions in the array, so we include "i" in the hash.
1805 dynamicHash = phash(dynamicHash, partString + i);
1806 css += partString;
1807 }
1808 }
1809 if (css) {
1810 var name_2 = generateAlphabeticName(dynamicHash >>> 0);
1811 if (!styleSheet.hasNameForId(this.componentId, name_2)) {
1812 styleSheet.insertRules(this.componentId, name_2, stylis(css, ".".concat(name_2), undefined, this.componentId));
1813 }
1814 names = joinStrings(names, name_2);
1815 }
1816 }
1817 return names;
1818 };
1819 return ComponentStyle;
1820 }());
1821
1822 var identifiers = {};
1823 /* We depend on components having unique IDs */
1824 function generateId(displayName, parentComponentId) {
1825 var name = typeof displayName !== 'string' ? 'sc' : escape(displayName);
1826 // Ensure that no displayName can lead to duplicate componentIds
1827 identifiers[name] = (identifiers[name] || 0) + 1;
1828 var componentId = "".concat(name, "-").concat(generateComponentId(
1829 // SC_VERSION gives us isolation between multiple runtimes on the page at once
1830 // this is improved further with use of the babel plugin "namespace" feature
1831 SC_VERSION + name + identifiers[name]));
1832 return parentComponentId ? "".concat(parentComponentId, "-").concat(componentId) : componentId;
1833 }
1834 function useInjectedStyle(componentStyle, resolvedAttrs) {
1835 var ssc = useStyleSheetContext();
1836 var className = componentStyle.generateAndInjectStyles(resolvedAttrs, ssc.styleSheet, ssc.stylis);
1837 React.useDebugValue(className);
1838 return className;
1839 }
1840 function resolveContext(attrs, props, theme) {
1841 var context = __assign(__assign({}, props), {
1842 // unset, add `props.className` back at the end so props always "wins"
1843 className: undefined, theme: theme });
1844 var attrDef;
1845 for (var i = 0; i < attrs.length; i += 1) {
1846 attrDef = attrs[i];
1847 var resolvedAttrDef = isFunction(attrDef) ? attrDef(context) : attrDef;
1848 for (var key in resolvedAttrDef) {
1849 context[key] =
1850 key === 'className'
1851 ? joinStrings(context[key], resolvedAttrDef[key])
1852 : key === 'style'
1853 ? __assign(__assign({}, context[key]), resolvedAttrDef[key]) : resolvedAttrDef[key];
1854 }
1855 }
1856 if (props.className) {
1857 context.className = joinStrings(context.className, props.className);
1858 }
1859 return context;
1860 }
1861 var seenUnknownProps = new Set();
1862 function useStyledComponentImpl(forwardedComponent, props, forwardedRef) {
1863 var componentAttrs = forwardedComponent.attrs, componentStyle = forwardedComponent.componentStyle, defaultProps = forwardedComponent.defaultProps, foldedComponentIds = forwardedComponent.foldedComponentIds, styledComponentId = forwardedComponent.styledComponentId, target = forwardedComponent.target;
1864 var contextTheme = React.useContext(ThemeContext);
1865 var ssc = useStyleSheetContext();
1866 var shouldForwardProp = forwardedComponent.shouldForwardProp || ssc.shouldForwardProp;
1867 React.useDebugValue(styledComponentId);
1868 // NOTE: the non-hooks version only subscribes to this when !componentStyle.isStatic,
1869 // but that'd be against the rules-of-hooks. We could be naughty and do it anyway as it
1870 // should be an immutable value, but behave for now.
1871 var theme = determineTheme(props, contextTheme, defaultProps) || EMPTY_OBJECT;
1872 var context = resolveContext(componentAttrs, props, theme);
1873 var elementToBeCreated = context.as || target;
1874 var propsForElement = {};
1875 for (var key in context) {
1876 if (context[key] === undefined) ;
1877 else if (key[0] === '$' || key === 'as' || (key === 'theme' && context.theme === theme)) ;
1878 else if (key === 'forwardedAs') {
1879 propsForElement.as = context.forwardedAs;
1880 }
1881 else if (!shouldForwardProp || shouldForwardProp(key, elementToBeCreated)) {
1882 propsForElement[key] = context[key];
1883 if (!shouldForwardProp &&
1884 "development" === 'development' &&
1885 !isPropValid(key) &&
1886 !seenUnknownProps.has(key) &&
1887 // Only warn on DOM Element.
1888 domElements.has(elementToBeCreated)) {
1889 seenUnknownProps.add(key);
1890 console.warn("styled-components: it looks like an unknown prop \"".concat(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.)"));
1891 }
1892 }
1893 }
1894 var generatedClassName = useInjectedStyle(componentStyle, context);
1895 if (forwardedComponent.warnTooManyClasses) {
1896 forwardedComponent.warnTooManyClasses(generatedClassName);
1897 }
1898 var classString = joinStrings(foldedComponentIds, styledComponentId);
1899 if (generatedClassName) {
1900 classString += ' ' + generatedClassName;
1901 }
1902 if (context.className) {
1903 classString += ' ' + context.className;
1904 }
1905 propsForElement[
1906 // handle custom elements which React doesn't properly alias
1907 isTag(elementToBeCreated) &&
1908 !domElements.has(elementToBeCreated)
1909 ? 'class'
1910 : 'className'] = classString;
1911 propsForElement.ref = forwardedRef;
1912 return React.createElement(elementToBeCreated, propsForElement);
1913 }
1914 function createStyledComponent(target, options, rules) {
1915 var isTargetStyledComp = isStyledComponent(target);
1916 var styledComponentTarget = target;
1917 var isCompositeComponent = !isTag(target);
1918 var _a = options.attrs, attrs = _a === void 0 ? EMPTY_ARRAY : _a, _b = options.componentId, componentId = _b === void 0 ? generateId(options.displayName, options.parentComponentId) : _b, _c = options.displayName, displayName = _c === void 0 ? generateDisplayName(target) : _c;
1919 var styledComponentId = options.displayName && options.componentId
1920 ? "".concat(escape(options.displayName), "-").concat(options.componentId)
1921 : options.componentId || componentId;
1922 // fold the underlying StyledComponent attrs up (implicit extend)
1923 var finalAttrs = isTargetStyledComp && styledComponentTarget.attrs
1924 ? styledComponentTarget.attrs.concat(attrs).filter(Boolean)
1925 : attrs;
1926 var shouldForwardProp = options.shouldForwardProp;
1927 if (isTargetStyledComp && styledComponentTarget.shouldForwardProp) {
1928 var shouldForwardPropFn_1 = styledComponentTarget.shouldForwardProp;
1929 if (options.shouldForwardProp) {
1930 var passedShouldForwardPropFn_1 = options.shouldForwardProp;
1931 // compose nested shouldForwardProp calls
1932 shouldForwardProp = function (prop, elementToBeCreated) {
1933 return shouldForwardPropFn_1(prop, elementToBeCreated) &&
1934 passedShouldForwardPropFn_1(prop, elementToBeCreated);
1935 };
1936 }
1937 else {
1938 shouldForwardProp = shouldForwardPropFn_1;
1939 }
1940 }
1941 var componentStyle = new ComponentStyle(rules, styledComponentId, isTargetStyledComp ? styledComponentTarget.componentStyle : undefined);
1942 function forwardRefRender(props, ref) {
1943 return useStyledComponentImpl(WrappedStyledComponent, props, ref);
1944 }
1945 forwardRefRender.displayName = displayName;
1946 /**
1947 * forwardRef creates a new interim component, which we'll take advantage of
1948 * instead of extending ParentComponent to create _another_ interim class
1949 */
1950 var WrappedStyledComponent = React.forwardRef(forwardRefRender);
1951 WrappedStyledComponent.attrs = finalAttrs;
1952 WrappedStyledComponent.componentStyle = componentStyle;
1953 WrappedStyledComponent.displayName = displayName;
1954 WrappedStyledComponent.shouldForwardProp = shouldForwardProp;
1955 // this static is used to preserve the cascade of static classes for component selector
1956 // purposes; this is especially important with usage of the css prop
1957 WrappedStyledComponent.foldedComponentIds = isTargetStyledComp
1958 ? joinStrings(styledComponentTarget.foldedComponentIds, styledComponentTarget.styledComponentId)
1959 : '';
1960 WrappedStyledComponent.styledComponentId = styledComponentId;
1961 // fold the underlying StyledComponent target up since we folded the styles
1962 WrappedStyledComponent.target = isTargetStyledComp ? styledComponentTarget.target : target;
1963 Object.defineProperty(WrappedStyledComponent, 'defaultProps', {
1964 get: function () {
1965 return this._foldedDefaultProps;
1966 },
1967 set: function (obj) {
1968 this._foldedDefaultProps = isTargetStyledComp
1969 ? mixinDeep({}, styledComponentTarget.defaultProps, obj)
1970 : obj;
1971 },
1972 });
1973 {
1974 checkDynamicCreation(displayName, styledComponentId);
1975 WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName, styledComponentId);
1976 }
1977 setToString(WrappedStyledComponent, function () { return ".".concat(WrappedStyledComponent.styledComponentId); });
1978 if (isCompositeComponent) {
1979 var compositeComponentTarget = target;
1980 hoistNonReactStatics(WrappedStyledComponent, compositeComponentTarget, {
1981 // all SC-specific things should not be hoisted
1982 attrs: true,
1983 componentStyle: true,
1984 displayName: true,
1985 foldedComponentIds: true,
1986 shouldForwardProp: true,
1987 styledComponentId: true,
1988 target: true,
1989 });
1990 }
1991 return WrappedStyledComponent;
1992 }
1993
1994 function constructWithOptions(componentConstructor, tag, options) {
1995 if (options === void 0) { options = EMPTY_OBJECT; }
1996 /**
1997 * We trust that the tag is a valid component as long as it isn't
1998 * falsish. Typically the tag here is a string or function (i.e.
1999 * class or pure function component), however a component may also be
2000 * an object if it uses another utility, e.g. React.memo. React will
2001 * output an appropriate warning however if the `tag` isn't valid.
2002 */
2003 if (!tag) {
2004 throw throwStyledComponentsError(1, tag);
2005 }
2006 /* This is callable directly as a template function */
2007 var templateFunction = function (initialStyles) {
2008 var interpolations = [];
2009 for (var _i = 1; _i < arguments.length; _i++) {
2010 interpolations[_i - 1] = arguments[_i];
2011 }
2012 return componentConstructor(tag, options, css.apply(void 0, __spreadArray([initialStyles], interpolations, false)));
2013 };
2014 /**
2015 * Attrs allows for accomplishing two goals:
2016 *
2017 * 1. Backfilling props at runtime more expressively than defaultProps
2018 * 2. Amending the prop interface of a wrapped styled component
2019 */
2020 templateFunction.attrs = function (attrs) {
2021 return constructWithOptions(componentConstructor, tag, __assign(__assign({}, options), { attrs: Array.prototype.concat(options.attrs, attrs).filter(Boolean) }));
2022 };
2023 /**
2024 * If config methods are called, wrap up a new template function
2025 * and merge options.
2026 */
2027 templateFunction.withConfig = function (config) {
2028 return constructWithOptions(componentConstructor, tag, __assign(__assign({}, options), config));
2029 };
2030 return templateFunction;
2031 }
2032
2033 var baseStyled = function (tag) {
2034 return constructWithOptions(createStyledComponent, tag);
2035 };
2036 var styled = baseStyled;
2037 // Shorthands for all valid HTML Elements
2038 domElements.forEach(function (domElement) {
2039 // @ts-expect-error some react typing bs
2040 styled[domElement] = baseStyled(domElement);
2041 });
2042
2043 /**
2044 * eliminates the need to do styled.default since the other APIs
2045 * are directly assigned as properties to the main function
2046 * */
2047 for (var key in secondary) {
2048 // @ts-expect-error shush
2049 styled[key] = secondary[key];
2050 }
2051
2052 return styled;
2053
2054}));
2055//# sourceMappingURL=styled-components.js.map