styled-components 6.0.0-alpha.7 → 6.0.0-beta.0

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