styled-components.browser.esm.js 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922
  1. import { isElement, isValidElementType } from 'react-is';
  2. import React, { useState, useContext, useMemo, useEffect, useRef, createElement, useDebugValue } from 'react';
  3. import shallowequal from 'shallowequal';
  4. import Stylis from '@emotion/stylis';
  5. import unitless from '@emotion/unitless';
  6. import validAttr from '@emotion/is-prop-valid';
  7. import hoist from 'hoist-non-react-statics';
  8. function _extends() {
  9. _extends = Object.assign || function (target) {
  10. for (var i = 1; i < arguments.length; i++) {
  11. var source = arguments[i];
  12. for (var key in source) {
  13. if (Object.prototype.hasOwnProperty.call(source, key)) {
  14. target[key] = source[key];
  15. }
  16. }
  17. }
  18. return target;
  19. };
  20. return _extends.apply(this, arguments);
  21. }
  22. function _objectWithoutPropertiesLoose(source, excluded) {
  23. if (source == null) return {};
  24. var target = {};
  25. var sourceKeys = Object.keys(source);
  26. var key, i;
  27. for (i = 0; i < sourceKeys.length; i++) {
  28. key = sourceKeys[i];
  29. if (excluded.indexOf(key) >= 0) continue;
  30. target[key] = source[key];
  31. }
  32. return target;
  33. }
  34. //
  35. var interleave = (function (strings, interpolations) {
  36. var result = [strings[0]];
  37. for (var i = 0, len = interpolations.length; i < len; i += 1) {
  38. result.push(interpolations[i], strings[i + 1]);
  39. }
  40. return result;
  41. });
  42. //
  43. var isPlainObject = (function (x) {
  44. return typeof x === 'object' && x.constructor === Object;
  45. });
  46. //
  47. var EMPTY_ARRAY = Object.freeze([]);
  48. var EMPTY_OBJECT = Object.freeze({});
  49. //
  50. function isFunction(test) {
  51. return typeof test === 'function';
  52. }
  53. //
  54. function getComponentName(target) {
  55. return (process.env.NODE_ENV !== 'production' ? typeof target === 'string' && target : false) || // $FlowFixMe
  56. target.displayName || // $FlowFixMe
  57. target.name || 'Component';
  58. }
  59. //
  60. function isStatelessFunction(test) {
  61. return typeof test === 'function' && !(test.prototype && test.prototype.isReactComponent);
  62. }
  63. //
  64. function isStyledComponent(target) {
  65. return target && typeof target.styledComponentId === 'string';
  66. }
  67. //
  68. var SC_ATTR = typeof process !== 'undefined' && (process.env.REACT_APP_SC_ATTR || process.env.SC_ATTR) || 'data-styled';
  69. var SC_ATTR_ACTIVE = 'active';
  70. var SC_ATTR_VERSION = 'data-styled-version';
  71. var SC_VERSION = "5.0.1";
  72. var IS_BROWSER = typeof window !== 'undefined' && 'HTMLElement' in window;
  73. var DISABLE_SPEEDY = typeof SC_DISABLE_SPEEDY === 'boolean' && SC_DISABLE_SPEEDY || typeof process !== 'undefined' && (process.env.REACT_APP_SC_DISABLE_SPEEDY || process.env.SC_DISABLE_SPEEDY) || process.env.NODE_ENV !== 'production'; // Shared empty execution context when generating static styles
  74. var STATIC_EXECUTION_CONTEXT = {};
  75. //
  76. /* eslint-disable camelcase, no-undef */
  77. var getNonce = function getNonce() {
  78. return typeof __webpack_nonce__ !== 'undefined' ? __webpack_nonce__ : null;
  79. };
  80. var errorMap = {
  81. "1": "Cannot create styled-component for component: %s.\n\n",
  82. "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",
  83. "3": "Streaming SSR is only supported in a Node.js environment; Please do not try to call this method in the browser.\n\n",
  84. "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",
  85. "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",
  86. "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",
  87. "7": "ThemeProvider: Please return an object from your \"theme\" prop function, e.g.\n\n```js\ntheme={() => ({})}\n```\n\n",
  88. "8": "ThemeProvider: Please make your \"theme\" prop an object.\n\n",
  89. "9": "Missing document `<head>`\n\n",
  90. "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",
  91. "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",
  92. "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",
  93. "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",
  94. "14": "ThemeProvider: \"theme\" prop is required.\n\n",
  95. "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",
  96. "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",
  97. "17": "CSSStyleSheet could not be found on HTMLStyleElement.\nHas styled-components' style tag been unmounted or altered by another script?\n"
  98. };
  99. //
  100. var ERRORS = process.env.NODE_ENV !== 'production' ? errorMap : {};
  101. /**
  102. * super basic version of sprintf
  103. */
  104. function format() {
  105. var a = arguments.length <= 0 ? undefined : arguments[0];
  106. var b = [];
  107. for (var c = 1, len = arguments.length; c < len; c += 1) {
  108. b.push(c < 0 || arguments.length <= c ? undefined : arguments[c]);
  109. }
  110. b.forEach(function (d) {
  111. a = a.replace(/%[a-z]/, d);
  112. });
  113. return a;
  114. }
  115. /**
  116. * Create an error file out of errors.md for development and a simple web link to the full errors
  117. * in production mode.
  118. */
  119. function throwStyledComponentsError(code) {
  120. for (var _len = arguments.length, interpolations = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  121. interpolations[_key - 1] = arguments[_key];
  122. }
  123. if (process.env.NODE_ENV === 'production') {
  124. throw new Error("An error occurred. See https://github.com/styled-components/styled-components/blob/master/packages/styled-components/src/utils/errors.md#" + code + " for more information." + (interpolations.length > 0 ? " Additional arguments: " + interpolations.join(', ') : ''));
  125. } else {
  126. throw new Error(format.apply(void 0, [ERRORS[code]].concat(interpolations)).trim());
  127. }
  128. }
  129. //
  130. var ELEMENT_TYPE = 1;
  131. /* Node.ELEMENT_TYPE */
  132. /** Find last style element if any inside target */
  133. var findLastStyleTag = function findLastStyleTag(target) {
  134. var childNodes = target.childNodes;
  135. for (var i = childNodes.length; i >= 0; i--) {
  136. var child = childNodes[i];
  137. if (child && child.nodeType === ELEMENT_TYPE && child.hasAttribute(SC_ATTR)) {
  138. return child;
  139. }
  140. }
  141. return undefined;
  142. };
  143. /** Create a style element inside `target` or <head> after the last */
  144. var makeStyleTag = function makeStyleTag(target) {
  145. var head = document.head;
  146. var parent = target || head;
  147. var style = document.createElement('style');
  148. var prevStyle = findLastStyleTag(parent);
  149. var nextSibling = prevStyle !== undefined ? prevStyle.nextSibling : null;
  150. style.setAttribute(SC_ATTR, SC_ATTR_ACTIVE);
  151. style.setAttribute(SC_ATTR_VERSION, SC_VERSION);
  152. var nonce = getNonce();
  153. if (nonce) style.setAttribute('nonce', nonce);
  154. parent.insertBefore(style, nextSibling);
  155. return style;
  156. };
  157. /** Get the CSSStyleSheet instance for a given style element */
  158. var getSheet = function getSheet(tag) {
  159. if (tag.sheet) {
  160. return tag.sheet;
  161. } // Avoid Firefox quirk where the style element might not have a sheet property
  162. var _document = document,
  163. styleSheets = _document.styleSheets;
  164. for (var i = 0, l = styleSheets.length; i < l; i++) {
  165. var sheet = styleSheets[i];
  166. if (sheet.ownerNode === tag) {
  167. return sheet;
  168. }
  169. }
  170. throwStyledComponentsError(17);
  171. return undefined;
  172. };
  173. //
  174. /** Create a CSSStyleSheet-like tag depending on the environment */
  175. var makeTag = function makeTag(_ref) {
  176. var isServer = _ref.isServer,
  177. useCSSOMInjection = _ref.useCSSOMInjection,
  178. target = _ref.target;
  179. if (isServer) {
  180. return new VirtualTag(target);
  181. } else if (useCSSOMInjection) {
  182. return new CSSOMTag(target);
  183. } else {
  184. return new TextTag(target);
  185. }
  186. };
  187. var CSSOMTag =
  188. /*#__PURE__*/
  189. function () {
  190. function CSSOMTag(target) {
  191. var element = this.element = makeStyleTag(target); // Avoid Edge bug where empty style elements don't create sheets
  192. element.appendChild(document.createTextNode(''));
  193. this.sheet = getSheet(element);
  194. this.length = 0;
  195. }
  196. var _proto = CSSOMTag.prototype;
  197. _proto.insertRule = function insertRule(index, rule) {
  198. try {
  199. this.sheet.insertRule(rule, index);
  200. this.length++;
  201. return true;
  202. } catch (_error) {
  203. return false;
  204. }
  205. };
  206. _proto.deleteRule = function deleteRule(index) {
  207. this.sheet.deleteRule(index);
  208. this.length--;
  209. };
  210. _proto.getRule = function getRule(index) {
  211. var rule = this.sheet.cssRules[index]; // Avoid IE11 quirk where cssText is inaccessible on some invalid rules
  212. if (rule !== undefined && typeof rule.cssText === 'string') {
  213. return rule.cssText;
  214. } else {
  215. return '';
  216. }
  217. };
  218. return CSSOMTag;
  219. }();
  220. /** A Tag that emulates the CSSStyleSheet API but uses text nodes */
  221. var TextTag =
  222. /*#__PURE__*/
  223. function () {
  224. function TextTag(target) {
  225. var element = this.element = makeStyleTag(target);
  226. this.nodes = element.childNodes;
  227. this.length = 0;
  228. }
  229. var _proto2 = TextTag.prototype;
  230. _proto2.insertRule = function insertRule(index, rule) {
  231. if (index <= this.length && index >= 0) {
  232. var node = document.createTextNode(rule);
  233. var refNode = this.nodes[index];
  234. this.element.insertBefore(node, refNode || null);
  235. this.length++;
  236. return true;
  237. } else {
  238. return false;
  239. }
  240. };
  241. _proto2.deleteRule = function deleteRule(index) {
  242. this.element.removeChild(this.nodes[index]);
  243. this.length--;
  244. };
  245. _proto2.getRule = function getRule(index) {
  246. if (index < this.length) {
  247. return this.nodes[index].textContent;
  248. } else {
  249. return '';
  250. }
  251. };
  252. return TextTag;
  253. }();
  254. /** A completely virtual (server-side) Tag that doesn't manipulate the DOM */
  255. var VirtualTag =
  256. /*#__PURE__*/
  257. function () {
  258. function VirtualTag(_target) {
  259. this.rules = [];
  260. this.length = 0;
  261. }
  262. var _proto3 = VirtualTag.prototype;
  263. _proto3.insertRule = function insertRule(index, rule) {
  264. if (index <= this.length) {
  265. this.rules.splice(index, 0, rule);
  266. this.length++;
  267. return true;
  268. } else {
  269. return false;
  270. }
  271. };
  272. _proto3.deleteRule = function deleteRule(index) {
  273. this.rules.splice(index, 1);
  274. this.length--;
  275. };
  276. _proto3.getRule = function getRule(index) {
  277. if (index < this.length) {
  278. return this.rules[index];
  279. } else {
  280. return '';
  281. }
  282. };
  283. return VirtualTag;
  284. }();
  285. //
  286. /** Create a GroupedTag with an underlying Tag implementation */
  287. var makeGroupedTag = function makeGroupedTag(tag) {
  288. return new DefaultGroupedTag(tag);
  289. };
  290. var BASE_SIZE = 1 << 9;
  291. var DefaultGroupedTag =
  292. /*#__PURE__*/
  293. function () {
  294. function DefaultGroupedTag(tag) {
  295. this.groupSizes = new Uint32Array(BASE_SIZE);
  296. this.length = BASE_SIZE;
  297. this.tag = tag;
  298. }
  299. var _proto = DefaultGroupedTag.prototype;
  300. _proto.indexOfGroup = function indexOfGroup(group) {
  301. var index = 0;
  302. for (var i = 0; i < group; i++) {
  303. index += this.groupSizes[i];
  304. }
  305. return index;
  306. };
  307. _proto.insertRules = function insertRules(group, rules) {
  308. if (group >= this.groupSizes.length) {
  309. var oldBuffer = this.groupSizes;
  310. var oldSize = oldBuffer.length;
  311. var newSize = oldSize;
  312. while (group >= newSize) {
  313. newSize <<= 1;
  314. if (newSize < 0) {
  315. throwStyledComponentsError(16, "" + group);
  316. }
  317. }
  318. this.groupSizes = new Uint32Array(newSize);
  319. this.groupSizes.set(oldBuffer);
  320. this.length = newSize;
  321. for (var i = oldSize; i < newSize; i++) {
  322. this.groupSizes[i] = 0;
  323. }
  324. }
  325. var ruleIndex = this.indexOfGroup(group + 1);
  326. for (var _i = 0, l = rules.length; _i < l; _i++) {
  327. if (this.tag.insertRule(ruleIndex, rules[_i])) {
  328. this.groupSizes[group]++;
  329. ruleIndex++;
  330. }
  331. }
  332. };
  333. _proto.clearGroup = function clearGroup(group) {
  334. if (group < this.length) {
  335. var length = this.groupSizes[group];
  336. var startIndex = this.indexOfGroup(group);
  337. var endIndex = startIndex + length;
  338. this.groupSizes[group] = 0;
  339. for (var i = startIndex; i < endIndex; i++) {
  340. this.tag.deleteRule(startIndex);
  341. }
  342. }
  343. };
  344. _proto.getGroup = function getGroup(group) {
  345. var css = '';
  346. if (group >= this.length || this.groupSizes[group] === 0) {
  347. return css;
  348. }
  349. var length = this.groupSizes[group];
  350. var startIndex = this.indexOfGroup(group);
  351. var endIndex = startIndex + length;
  352. for (var i = startIndex; i < endIndex; i++) {
  353. css += this.tag.getRule(i) + "\n";
  354. }
  355. return css;
  356. };
  357. return DefaultGroupedTag;
  358. }();
  359. //
  360. var MAX_SMI = 1 << 31 - 1;
  361. var groupIDRegister = new Map();
  362. var reverseRegister = new Map();
  363. var nextFreeGroup = 1;
  364. var getGroupForId = function getGroupForId(id) {
  365. if (groupIDRegister.has(id)) {
  366. return groupIDRegister.get(id);
  367. }
  368. var group = nextFreeGroup++;
  369. if (process.env.NODE_ENV !== 'production' && ((group | 0) < 0 || group > MAX_SMI)) {
  370. throwStyledComponentsError(16, "" + group);
  371. }
  372. groupIDRegister.set(id, group);
  373. reverseRegister.set(group, id);
  374. return group;
  375. };
  376. var getIdForGroup = function getIdForGroup(group) {
  377. return reverseRegister.get(group);
  378. };
  379. var setGroupForId = function setGroupForId(id, group) {
  380. if (group >= nextFreeGroup) {
  381. nextFreeGroup = group + 1;
  382. }
  383. groupIDRegister.set(id, group);
  384. reverseRegister.set(group, id);
  385. };
  386. //
  387. var SELECTOR = "style[" + SC_ATTR + "][" + SC_ATTR_VERSION + "=\"" + SC_VERSION + "\"]";
  388. var RULE_RE = /(?:\s*)?(.*?){((?:{[^}]*}|(?!{).*?)*)}/g;
  389. var MARKER_RE = new RegExp("^" + SC_ATTR + "\\.g(\\d+)\\[id=\"([\\w\\d-]+)\"\\]");
  390. var outputSheet = function outputSheet(sheet) {
  391. var tag = sheet.getTag();
  392. var length = tag.length;
  393. var css = '';
  394. for (var group = 0; group < length; group++) {
  395. var id = getIdForGroup(group);
  396. if (id === undefined) continue;
  397. var names = sheet.names.get(id);
  398. var rules = tag.getGroup(group);
  399. if (names === undefined || rules.length === 0) continue;
  400. var selector = SC_ATTR + ".g" + group + "[id=\"" + id + "\"]";
  401. var content = '';
  402. if (names !== undefined) {
  403. names.forEach(function (name) {
  404. if (name.length > 0) {
  405. content += name + ",";
  406. }
  407. });
  408. } // NOTE: It's easier to collect rules and have the marker
  409. // after the actual rules to simplify the rehydration
  410. css += "" + rules + selector + "{content:\"" + content + "\"}\n";
  411. }
  412. return css;
  413. };
  414. var rehydrateNamesFromContent = function rehydrateNamesFromContent(sheet, id, content) {
  415. var names = content.split(',');
  416. var name;
  417. for (var i = 0, l = names.length; i < l; i++) {
  418. // eslint-disable-next-line
  419. if (name = names[i]) {
  420. sheet.registerName(id, name);
  421. }
  422. }
  423. };
  424. var rehydrateSheetFromTag = function rehydrateSheetFromTag(sheet, style) {
  425. var rawHTML = style.innerHTML;
  426. var rules = [];
  427. var parts; // parts = [match, selector, content]
  428. // eslint-disable-next-line no-cond-assign
  429. while (parts = RULE_RE.exec(rawHTML)) {
  430. var marker = parts[1].match(MARKER_RE);
  431. if (marker) {
  432. var group = parseInt(marker[1], 10) | 0;
  433. var id = marker[2];
  434. if (group !== 0) {
  435. // Rehydrate componentId to group index mapping
  436. setGroupForId(id, group); // Rehydrate names and rules
  437. // looks like: data-styled.g11[id="idA"]{content:"nameA,"}
  438. rehydrateNamesFromContent(sheet, id, parts[2].split('"')[1]);
  439. sheet.getTag().insertRules(group, rules);
  440. }
  441. rules.length = 0;
  442. } else {
  443. rules.push(parts[0].trim());
  444. }
  445. }
  446. };
  447. var rehydrateSheet = function rehydrateSheet(sheet) {
  448. var nodes = document.querySelectorAll(SELECTOR);
  449. for (var i = 0, l = nodes.length; i < l; i++) {
  450. var node = nodes[i];
  451. if (node && node.getAttribute(SC_ATTR) !== SC_ATTR_ACTIVE) {
  452. rehydrateSheetFromTag(sheet, node);
  453. if (node.parentNode) {
  454. node.parentNode.removeChild(node);
  455. }
  456. }
  457. }
  458. };
  459. var SHOULD_REHYDRATE = IS_BROWSER;
  460. var defaultOptions = {
  461. isServer: !IS_BROWSER,
  462. useCSSOMInjection: !DISABLE_SPEEDY
  463. };
  464. /** Contains the main stylesheet logic for stringification and caching */
  465. var StyleSheet =
  466. /*#__PURE__*/
  467. function () {
  468. /** Register a group ID to give it an index */
  469. StyleSheet.registerId = function registerId(id) {
  470. return getGroupForId(id);
  471. };
  472. function StyleSheet(options, globalStyles, names) {
  473. if (options === void 0) {
  474. options = defaultOptions;
  475. }
  476. if (globalStyles === void 0) {
  477. globalStyles = {};
  478. }
  479. this.options = _extends({}, defaultOptions, {}, options);
  480. this.gs = globalStyles;
  481. this.names = new Map(names); // We rehydrate only once and use the sheet that is created first
  482. if (!this.options.isServer && IS_BROWSER && SHOULD_REHYDRATE) {
  483. SHOULD_REHYDRATE = false;
  484. rehydrateSheet(this);
  485. }
  486. }
  487. var _proto = StyleSheet.prototype;
  488. _proto.reconstructWithOptions = function reconstructWithOptions(options) {
  489. return new StyleSheet(_extends({}, this.options, {}, options), this.gs, this.names);
  490. };
  491. _proto.allocateGSInstance = function allocateGSInstance(id) {
  492. return this.gs[id] = (this.gs[id] || 0) + 1;
  493. }
  494. /** Lazily initialises a GroupedTag for when it's actually needed */
  495. ;
  496. _proto.getTag = function getTag() {
  497. return this.tag || (this.tag = makeGroupedTag(makeTag(this.options)));
  498. }
  499. /** Check whether a name is known for caching */
  500. ;
  501. _proto.hasNameForId = function hasNameForId(id, name) {
  502. return this.names.has(id) && this.names.get(id).has(name);
  503. }
  504. /** Mark a group's name as known for caching */
  505. ;
  506. _proto.registerName = function registerName(id, name) {
  507. getGroupForId(id);
  508. if (!this.names.has(id)) {
  509. var groupNames = new Set();
  510. groupNames.add(name);
  511. this.names.set(id, groupNames);
  512. } else {
  513. this.names.get(id).add(name);
  514. }
  515. }
  516. /** Insert new rules which also marks the name as known */
  517. ;
  518. _proto.insertRules = function insertRules(id, name, rules) {
  519. this.registerName(id, name);
  520. this.getTag().insertRules(getGroupForId(id), rules);
  521. }
  522. /** Clears all cached names for a given group ID */
  523. ;
  524. _proto.clearNames = function clearNames(id) {
  525. if (this.names.has(id)) {
  526. this.names.get(id).clear();
  527. }
  528. }
  529. /** Clears all rules for a given group ID */
  530. ;
  531. _proto.clearRules = function clearRules(id) {
  532. this.getTag().clearGroup(getGroupForId(id));
  533. this.clearNames(id);
  534. }
  535. /** Clears the entire tag which deletes all rules but not its names */
  536. ;
  537. _proto.clearTag = function clearTag() {
  538. // NOTE: This does not clear the names, since it's only used during SSR
  539. // so that we can continuously output only new rules
  540. this.tag = undefined;
  541. }
  542. /** Outputs the current sheet as a CSS string with markers for SSR */
  543. ;
  544. _proto.toString = function toString() {
  545. return outputSheet(this);
  546. };
  547. return StyleSheet;
  548. }();
  549. //
  550. /* eslint-disable */
  551. var SEED = 5381; // When we have separate strings it's useful to run a progressive
  552. // version of djb2 where we pretend that we're still looping over
  553. // the same string
  554. var phash = function phash(h, x) {
  555. var i = x.length;
  556. while (i) {
  557. h = h * 33 ^ x.charCodeAt(--i);
  558. }
  559. return h;
  560. }; // This is a djb2 hashing function
  561. var hash = function hash(x) {
  562. return phash(SEED, x);
  563. };
  564. /**
  565. * MIT License
  566. *
  567. * Copyright (c) 2016 Sultan Tarimo
  568. *
  569. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  570. * this software and associated documentation files (the "Software"),
  571. * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  572. * sell copies of the Software and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  573. *
  574. * The above copyright notice and this permission notice shall be included in all
  575. * copies or substantial portions of the Software.
  576. *
  577. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  578. * OR IMPLIED INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  579. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  580. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  581. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  582. * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  583. */
  584. /* eslint-disable */
  585. function insertRulePlugin (insertRule) {
  586. var delimiter = '/*|*/';
  587. var needle = delimiter + "}";
  588. function toSheet(block) {
  589. if (block) {
  590. try {
  591. insertRule(block + "}");
  592. } catch (e) {}
  593. }
  594. }
  595. return function ruleSheet(context, content, selectors, parents, line, column, length, ns, depth, at) {
  596. switch (context) {
  597. // property
  598. case 1:
  599. // @import
  600. if (depth === 0 && content.charCodeAt(0) === 64) return insertRule(content + ";"), '';
  601. break;
  602. // selector
  603. case 2:
  604. if (ns === 0) return content + delimiter;
  605. break;
  606. // at-rule
  607. case 3:
  608. switch (ns) {
  609. // @font-face, @page
  610. case 102:
  611. case 112:
  612. return insertRule(selectors[0] + content), '';
  613. default:
  614. return content + (at === 0 ? delimiter : '');
  615. }
  616. case -2:
  617. content.split(needle).forEach(toSheet);
  618. }
  619. };
  620. }
  621. var COMMENT_REGEX = /^\s*\/\/.*$/gm;
  622. function createStylisInstance(_temp) {
  623. var _ref = _temp === void 0 ? EMPTY_OBJECT : _temp,
  624. _ref$options = _ref.options,
  625. options = _ref$options === void 0 ? EMPTY_OBJECT : _ref$options,
  626. _ref$plugins = _ref.plugins,
  627. plugins = _ref$plugins === void 0 ? EMPTY_ARRAY : _ref$plugins;
  628. var stylis = new Stylis(options); // Wrap `insertRulePlugin to build a list of rules,
  629. // and then make our own plugin to return the rules. This
  630. // makes it easier to hook into the existing SSR architecture
  631. var parsingRules = []; // eslint-disable-next-line consistent-return
  632. var returnRulesPlugin = function returnRulesPlugin(context) {
  633. if (context === -2) {
  634. var parsedRules = parsingRules;
  635. parsingRules = [];
  636. return parsedRules;
  637. }
  638. };
  639. var parseRulesPlugin = insertRulePlugin(function (rule) {
  640. parsingRules.push(rule);
  641. });
  642. var _componentId;
  643. var _selector;
  644. var _selectorRegexp;
  645. var selfReferenceReplacer = function selfReferenceReplacer(match, offset, string) {
  646. if ( // the first self-ref is always untouched
  647. offset > 0 && // there should be at least two self-refs to do a replacement (.b > .b)
  648. string.slice(0, offset).indexOf(_selector) !== -1 && // no consecutive self refs (.b.b); that is a precedence boost and treated differently
  649. string.slice(offset - _selector.length, offset) !== _selector) {
  650. return "." + _componentId;
  651. }
  652. return match;
  653. };
  654. /**
  655. * When writing a style like
  656. *
  657. * & + & {
  658. * color: red;
  659. * }
  660. *
  661. * The second ampersand should be a reference to the static component class. stylis
  662. * has no knowledge of static class so we have to intelligently replace the base selector.
  663. *
  664. * https://github.com/thysultan/stylis.js#plugins <- more info about the context phase values
  665. * "2" means this plugin is taking effect at the very end after all other processing is complete
  666. */
  667. var selfReferenceReplacementPlugin = function selfReferenceReplacementPlugin(context, _, selectors) {
  668. if (context === 2 && selectors.length && selectors[0].lastIndexOf(_selector) > 0) {
  669. // eslint-disable-next-line no-param-reassign
  670. selectors[0] = selectors[0].replace(_selectorRegexp, selfReferenceReplacer);
  671. }
  672. };
  673. stylis.use([].concat(plugins, [selfReferenceReplacementPlugin, parseRulesPlugin, returnRulesPlugin]));
  674. function stringifyRules(css, selector, prefix, componentId) {
  675. if (componentId === void 0) {
  676. componentId = '&';
  677. }
  678. var flatCSS = css.replace(COMMENT_REGEX, '');
  679. var cssStr = selector && prefix ? prefix + " " + selector + " { " + flatCSS + " }" : flatCSS; // stylis has no concept of state to be passed to plugins
  680. // but since JS is single=threaded, we can rely on that to ensure
  681. // these properties stay in sync with the current stylis run
  682. _componentId = componentId;
  683. _selector = selector;
  684. _selectorRegexp = new RegExp("\\" + _selector + "\\b", 'g');
  685. return stylis(prefix || !selector ? '' : selector, cssStr);
  686. }
  687. stringifyRules.hash = plugins.length ? plugins.reduce(function (acc, plugin) {
  688. if (!plugin.name) {
  689. throwStyledComponentsError(15);
  690. }
  691. return phash(acc, plugin.name);
  692. }, SEED).toString() : '';
  693. return stringifyRules;
  694. }
  695. //
  696. var StyleSheetContext = React.createContext();
  697. var StyleSheetConsumer = StyleSheetContext.Consumer;
  698. var StylisContext = React.createContext();
  699. var StylisConsumer = StylisContext.Consumer;
  700. var masterSheet = new StyleSheet();
  701. var masterStylis = createStylisInstance();
  702. function useStyleSheet() {
  703. return useContext(StyleSheetContext) || masterSheet;
  704. }
  705. function useStylis() {
  706. return useContext(StylisContext) || masterStylis;
  707. }
  708. function StyleSheetManager(props) {
  709. var _useState = useState(props.stylisPlugins),
  710. plugins = _useState[0],
  711. setPlugins = _useState[1];
  712. var contextStyleSheet = useStyleSheet();
  713. var styleSheet = useMemo(function () {
  714. var sheet = contextStyleSheet;
  715. if (props.sheet) {
  716. // eslint-disable-next-line prefer-destructuring
  717. sheet = props.sheet;
  718. } else if (props.target) {
  719. sheet = sheet.reconstructWithOptions({
  720. target: props.target
  721. });
  722. }
  723. if (props.disableCSSOMInjection) {
  724. sheet = sheet.reconstructWithOptions({
  725. useCSSOMInjection: false
  726. });
  727. }
  728. return sheet;
  729. }, [props.disableCSSOMInjection, props.sheet, props.target]);
  730. var stylis = useMemo(function () {
  731. return createStylisInstance({
  732. options: {
  733. prefix: !props.disableVendorPrefixes
  734. },
  735. plugins: plugins
  736. });
  737. }, [props.disableVendorPrefixes, plugins]);
  738. useEffect(function () {
  739. if (!shallowequal(plugins, props.stylisPlugins)) setPlugins(props.stylisPlugins);
  740. }, [props.stylisPlugins]);
  741. return React.createElement(StyleSheetContext.Provider, {
  742. value: styleSheet
  743. }, React.createElement(StylisContext.Provider, {
  744. value: stylis
  745. }, process.env.NODE_ENV !== 'production' ? React.Children.only(props.children) : props.children));
  746. }
  747. //
  748. var Keyframes =
  749. /*#__PURE__*/
  750. function () {
  751. function Keyframes(name, stringifyArgs) {
  752. var _this = this;
  753. this.inject = function (styleSheet) {
  754. if (!styleSheet.hasNameForId(_this.id, _this.name)) {
  755. styleSheet.insertRules(_this.id, _this.name, masterStylis.apply(void 0, _this.stringifyArgs));
  756. }
  757. };
  758. this.toString = function () {
  759. return throwStyledComponentsError(12, String(_this.name));
  760. };
  761. this.name = name;
  762. this.id = "sc-keyframes-" + name;
  763. this.stringifyArgs = stringifyArgs;
  764. }
  765. var _proto = Keyframes.prototype;
  766. _proto.getName = function getName() {
  767. return this.name;
  768. };
  769. return Keyframes;
  770. }();
  771. //
  772. /**
  773. * inlined version of
  774. * https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/hyphenateStyleName.js
  775. */
  776. var uppercasePattern = /([A-Z])/g;
  777. var msPattern = /^ms-/;
  778. /**
  779. * Hyphenates a camelcased CSS property name, for example:
  780. *
  781. * > hyphenateStyleName('backgroundColor')
  782. * < "background-color"
  783. * > hyphenateStyleName('MozTransition')
  784. * < "-moz-transition"
  785. * > hyphenateStyleName('msTransition')
  786. * < "-ms-transition"
  787. *
  788. * As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix
  789. * is converted to `-ms-`.
  790. *
  791. * @param {string} string
  792. * @return {string}
  793. */
  794. function hyphenateStyleName(string) {
  795. return string.replace(uppercasePattern, '-$1').toLowerCase().replace(msPattern, '-ms-');
  796. }
  797. //
  798. function addUnitIfNeeded(name, value) {
  799. // https://github.com/amilajack/eslint-plugin-flowtype-errors/issues/133
  800. // $FlowFixMe
  801. if (value == null || typeof value === 'boolean' || value === '') {
  802. return '';
  803. }
  804. if (typeof value === 'number' && value !== 0 && !(name in unitless)) {
  805. return value + "px"; // Presumes implicit 'px' suffix for unitless numbers
  806. }
  807. return String(value).trim();
  808. }
  809. //
  810. /**
  811. * It's falsish not falsy because 0 is allowed.
  812. */
  813. var isFalsish = function isFalsish(chunk) {
  814. return chunk === undefined || chunk === null || chunk === false || chunk === '';
  815. };
  816. var objToCssArray = function objToCssArray(obj, prevKey) {
  817. var rules = [];
  818. var keys = Object.keys(obj);
  819. keys.forEach(function (key) {
  820. if (!isFalsish(obj[key])) {
  821. if (isPlainObject(obj[key])) {
  822. rules.push.apply(rules, objToCssArray(obj[key], key));
  823. return rules;
  824. } else if (isFunction(obj[key])) {
  825. rules.push(hyphenateStyleName(key) + ":", obj[key], ';');
  826. return rules;
  827. }
  828. rules.push(hyphenateStyleName(key) + ": " + addUnitIfNeeded(key, obj[key]) + ";");
  829. }
  830. return rules;
  831. });
  832. return prevKey ? [prevKey + " {"].concat(rules, ['}']) : rules;
  833. };
  834. function flatten(chunk, executionContext, styleSheet) {
  835. if (Array.isArray(chunk)) {
  836. var ruleSet = [];
  837. for (var i = 0, len = chunk.length, result; i < len; i += 1) {
  838. result = flatten(chunk[i], executionContext, styleSheet);
  839. if (result === '') continue;else if (Array.isArray(result)) ruleSet.push.apply(ruleSet, result);else ruleSet.push(result);
  840. }
  841. return ruleSet;
  842. }
  843. if (isFalsish(chunk)) {
  844. return '';
  845. }
  846. /* Handle other components */
  847. if (isStyledComponent(chunk)) {
  848. return "." + chunk.styledComponentId;
  849. }
  850. /* Either execute or defer the function */
  851. if (isFunction(chunk)) {
  852. if (isStatelessFunction(chunk) && executionContext) {
  853. var _result = chunk(executionContext);
  854. if (process.env.NODE_ENV !== 'production' && isElement(_result)) {
  855. // eslint-disable-next-line no-console
  856. console.warn(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.");
  857. }
  858. return flatten(_result, executionContext, styleSheet);
  859. } else return chunk;
  860. }
  861. if (chunk instanceof Keyframes) {
  862. if (styleSheet) {
  863. chunk.inject(styleSheet);
  864. return chunk.getName();
  865. } else return chunk;
  866. }
  867. /* Handle objects */
  868. return isPlainObject(chunk) ? objToCssArray(chunk) : chunk.toString();
  869. }
  870. //
  871. function css(styles) {
  872. for (var _len = arguments.length, interpolations = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  873. interpolations[_key - 1] = arguments[_key];
  874. }
  875. if (isFunction(styles) || isPlainObject(styles)) {
  876. // $FlowFixMe
  877. return flatten(interleave(EMPTY_ARRAY, [styles].concat(interpolations)));
  878. }
  879. if (interpolations.length === 0 && styles.length === 1 && typeof styles[0] === "string") {
  880. // $FlowFixMe
  881. return styles;
  882. } // $FlowFixMe
  883. return flatten(interleave(styles, interpolations));
  884. }
  885. function constructWithOptions(componentConstructor, tag, options) {
  886. if (options === void 0) {
  887. options = EMPTY_OBJECT;
  888. }
  889. if (!isValidElementType(tag)) {
  890. return throwStyledComponentsError(1, String(tag));
  891. }
  892. /* This is callable directly as a template function */
  893. // $FlowFixMe: Not typed to avoid destructuring arguments
  894. var templateFunction = function templateFunction() {
  895. return componentConstructor(tag, options, css.apply(void 0, arguments));
  896. };
  897. /* If config methods are called, wrap up a new template function and merge options */
  898. templateFunction.withConfig = function (config) {
  899. return constructWithOptions(componentConstructor, tag, _extends({}, options, {}, config));
  900. };
  901. /* Modify/inject new props at runtime */
  902. templateFunction.attrs = function (attrs) {
  903. return constructWithOptions(componentConstructor, tag, _extends({}, options, {
  904. attrs: Array.prototype.concat(options.attrs, attrs).filter(Boolean)
  905. }));
  906. };
  907. return templateFunction;
  908. }
  909. /* eslint-disable */
  910. /**
  911. mixin-deep; https://github.com/jonschlinkert/mixin-deep
  912. Inlined such that it will be consistently transpiled to an IE-compatible syntax.
  913. The MIT License (MIT)
  914. Copyright (c) 2014-present, Jon Schlinkert.
  915. Permission is hereby granted, free of charge, to any person obtaining a copy
  916. of this software and associated documentation files (the "Software"), to deal
  917. in the Software without restriction, including without limitation the rights
  918. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  919. copies of the Software, and to permit persons to whom the Software is
  920. furnished to do so, subject to the following conditions:
  921. The above copyright notice and this permission notice shall be included in
  922. all copies or substantial portions of the Software.
  923. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  924. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  925. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  926. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  927. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  928. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  929. THE SOFTWARE.
  930. */
  931. var isObject = function isObject(val) {
  932. return typeof val === 'function' || typeof val === 'object' && val !== null && !Array.isArray(val);
  933. };
  934. var isValidKey = function isValidKey(key) {
  935. return key !== '__proto__' && key !== 'constructor' && key !== 'prototype';
  936. };
  937. function mixin(target, val, key) {
  938. var obj = target[key];
  939. if (isObject(val) && isObject(obj)) {
  940. mixinDeep(obj, val);
  941. } else {
  942. target[key] = val;
  943. }
  944. }
  945. function mixinDeep(target) {
  946. for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  947. rest[_key - 1] = arguments[_key];
  948. }
  949. for (var _i = 0, _rest = rest; _i < _rest.length; _i++) {
  950. var obj = _rest[_i];
  951. if (isObject(obj)) {
  952. for (var key in obj) {
  953. if (isValidKey(key)) {
  954. mixin(target, obj[key], key);
  955. }
  956. }
  957. }
  958. }
  959. return target;
  960. }
  961. //
  962. /* eslint-disable no-bitwise */
  963. var AD_REPLACER_R = /(a)(d)/gi;
  964. /* This is the "capacity" of our alphabet i.e. 2x26 for all letters plus their capitalised
  965. * counterparts */
  966. var charsLength = 52;
  967. /* start at 75 for 'a' until 'z' (25) and then start at 65 for capitalised letters */
  968. var getAlphabeticChar = function getAlphabeticChar(code) {
  969. return String.fromCharCode(code + (code > 25 ? 39 : 97));
  970. };
  971. /* input a number, usually a hash and convert it to base-52 */
  972. function generateAlphabeticName(code) {
  973. var name = '';
  974. var x;
  975. /* get a char and divide by alphabet-length */
  976. for (x = Math.abs(code); x > charsLength; x = x / charsLength | 0) {
  977. name = getAlphabeticChar(x % charsLength) + name;
  978. }
  979. return (getAlphabeticChar(x % charsLength) + name).replace(AD_REPLACER_R, '$1-$2');
  980. }
  981. //
  982. function isStaticRules(rules) {
  983. for (var i = 0; i < rules.length; i += 1) {
  984. var rule = rules[i];
  985. if (isFunction(rule) && !isStyledComponent(rule)) {
  986. // functions are allowed to be static if they're just being
  987. // used to get the classname of a nested styled component
  988. return false;
  989. }
  990. }
  991. return true;
  992. }
  993. //
  994. /*
  995. ComponentStyle is all the CSS-specific stuff, not
  996. the React-specific stuff.
  997. */
  998. var ComponentStyle =
  999. /*#__PURE__*/
  1000. function () {
  1001. function ComponentStyle(rules, componentId) {
  1002. this.rules = rules;
  1003. this.staticRulesId = '';
  1004. this.isStatic = process.env.NODE_ENV === 'production' && isStaticRules(rules);
  1005. this.componentId = componentId;
  1006. this.baseHash = hash(componentId); // NOTE: This registers the componentId, which ensures a consistent order
  1007. // for this component's styles compared to others
  1008. StyleSheet.registerId(componentId);
  1009. }
  1010. /*
  1011. * Flattens a rule set into valid CSS
  1012. * Hashes it, wraps the whole chunk in a .hash1234 {}
  1013. * Returns the hash to be injected on render()
  1014. * */
  1015. var _proto = ComponentStyle.prototype;
  1016. _proto.generateAndInjectStyles = function generateAndInjectStyles(executionContext, styleSheet, stylis) {
  1017. var componentId = this.componentId; // force dynamic classnames if user-supplied stylis plugins are in use
  1018. if (this.isStatic && !stylis.hash) {
  1019. if (this.staticRulesId && styleSheet.hasNameForId(componentId, this.staticRulesId)) {
  1020. return this.staticRulesId;
  1021. }
  1022. var cssStatic = flatten(this.rules, executionContext, styleSheet).join('');
  1023. var name = generateAlphabeticName(phash(this.baseHash, cssStatic.length) >>> 0);
  1024. if (!styleSheet.hasNameForId(componentId, name)) {
  1025. var cssStaticFormatted = stylis(cssStatic, "." + name, undefined, componentId);
  1026. styleSheet.insertRules(componentId, name, cssStaticFormatted);
  1027. }
  1028. this.staticRulesId = name;
  1029. return name;
  1030. } else {
  1031. var length = this.rules.length;
  1032. var dynamicHash = phash(this.baseHash, stylis.hash);
  1033. var css = '';
  1034. for (var i = 0; i < length; i++) {
  1035. var partRule = this.rules[i];
  1036. if (typeof partRule === 'string') {
  1037. css += partRule;
  1038. if (process.env.NODE_ENV !== 'production') dynamicHash = phash(dynamicHash, partRule + i);
  1039. } else {
  1040. var partChunk = flatten(partRule, executionContext, styleSheet);
  1041. var partString = Array.isArray(partChunk) ? partChunk.join('') : partChunk;
  1042. dynamicHash = phash(dynamicHash, partString + i);
  1043. css += partString;
  1044. }
  1045. }
  1046. var _name = generateAlphabeticName(dynamicHash >>> 0);
  1047. if (!styleSheet.hasNameForId(componentId, _name)) {
  1048. var cssFormatted = stylis(css, "." + _name, undefined, componentId);
  1049. styleSheet.insertRules(componentId, _name, cssFormatted);
  1050. }
  1051. return _name;
  1052. }
  1053. };
  1054. return ComponentStyle;
  1055. }();
  1056. //
  1057. var LIMIT = 200;
  1058. var createWarnTooManyClasses = (function (displayName, componentId) {
  1059. var generatedClasses = {};
  1060. var warningSeen = false;
  1061. return function (className) {
  1062. if (!warningSeen) {
  1063. generatedClasses[className] = true;
  1064. if (Object.keys(generatedClasses).length >= LIMIT) {
  1065. // Unable to find latestRule in test environment.
  1066. /* eslint-disable no-console, prefer-template */
  1067. var parsedIdString = componentId ? " with the id of \"" + componentId + "\"" : '';
  1068. console.warn("Over " + LIMIT + " classes were generated for component " + displayName + parsedIdString + ".\n" + 'Consider using the attrs method, together with a style object for frequently changed styles.\n' + 'Example:\n' + ' const Component = styled.div.attrs(props => ({\n' + ' style: {\n' + ' background: props.background,\n' + ' },\n' + ' }))`width: 100%;`\n\n' + ' <Component />');
  1069. warningSeen = true;
  1070. generatedClasses = {};
  1071. }
  1072. }
  1073. };
  1074. });
  1075. //
  1076. var invalidHookCallRe = /invalid hook call/i;
  1077. var seen = new Set();
  1078. var checkDynamicCreation = function checkDynamicCreation(displayName, componentId) {
  1079. if (process.env.NODE_ENV !== 'production') {
  1080. var parsedIdString = componentId ? " with the id of \"" + componentId + "\"" : '';
  1081. var message = "The component " + displayName + parsedIdString + " has been created dynamically.\n" + 'You may see this warning because you\'ve called styled inside another component.\n' + 'To resolve this only create new StyledComponents outside of any render method and function component.';
  1082. try {
  1083. // We purposefully call `useRef` outside of a component and expect it to throw
  1084. // If it doesn't, then we're inside another component.
  1085. // eslint-disable-next-line react-hooks/rules-of-hooks
  1086. useRef();
  1087. if (!seen.has(message)) {
  1088. // eslint-disable-next-line no-console
  1089. console.warn(message);
  1090. seen.add(message);
  1091. }
  1092. } catch (error) {
  1093. // The error here is expected, since we're expecting anything that uses `checkDynamicCreation` to
  1094. // be called outside of a React component.
  1095. if (invalidHookCallRe.test(error.message)) {
  1096. // This shouldn't happen, but resets `warningSeen` if we had this error happen intermittently
  1097. seen["delete"](message);
  1098. }
  1099. }
  1100. }
  1101. };
  1102. //
  1103. var determineTheme = (function (props, providedTheme, defaultProps) {
  1104. if (defaultProps === void 0) {
  1105. defaultProps = EMPTY_OBJECT;
  1106. }
  1107. return props.theme !== defaultProps.theme && props.theme || providedTheme || defaultProps.theme;
  1108. });
  1109. //
  1110. var escapeRegex = /[[\].#*$><+~=|^:(),"'`-]+/g;
  1111. var dashesAtEnds = /(^-|-$)/g;
  1112. /**
  1113. * TODO: Explore using CSS.escape when it becomes more available
  1114. * in evergreen browsers.
  1115. */
  1116. function escape(str) {
  1117. return str // Replace all possible CSS selectors
  1118. .replace(escapeRegex, '-') // Remove extraneous hyphens at the start and end
  1119. .replace(dashesAtEnds, '');
  1120. }
  1121. //
  1122. function isTag(target) {
  1123. return typeof target === 'string' && (process.env.NODE_ENV !== 'production' ? target.charAt(0) === target.charAt(0).toLowerCase() : true);
  1124. }
  1125. //
  1126. function generateDisplayName(target) {
  1127. // $FlowFixMe
  1128. return isTag(target) ? "styled." + target : "Styled(" + getComponentName(target) + ")";
  1129. }
  1130. //
  1131. var generateComponentId = (function (str) {
  1132. return generateAlphabeticName(hash(str) >>> 0);
  1133. });
  1134. /**
  1135. * Convenience function for joining strings to form className chains
  1136. */
  1137. function joinStrings(a, b) {
  1138. return a && b ? a + " " + b : a || b;
  1139. }
  1140. var ThemeContext = React.createContext();
  1141. var ThemeConsumer = ThemeContext.Consumer;
  1142. function mergeTheme(theme, outerTheme) {
  1143. if (!theme) {
  1144. return throwStyledComponentsError(14);
  1145. }
  1146. if (isFunction(theme)) {
  1147. var mergedTheme = theme(outerTheme);
  1148. if (process.env.NODE_ENV !== 'production' && (mergedTheme === null || Array.isArray(mergedTheme) || typeof mergedTheme !== 'object')) {
  1149. return throwStyledComponentsError(7);
  1150. }
  1151. return mergedTheme;
  1152. }
  1153. if (Array.isArray(theme) || typeof theme !== 'object') {
  1154. return throwStyledComponentsError(8);
  1155. }
  1156. return outerTheme ? _extends({}, outerTheme, {}, theme) : theme;
  1157. }
  1158. /**
  1159. * Provide a theme to an entire react component tree via context
  1160. */
  1161. function ThemeProvider(props) {
  1162. var outerTheme = useContext(ThemeContext);
  1163. var themeContext = useMemo(function () {
  1164. return mergeTheme(props.theme, outerTheme);
  1165. }, [props.theme, outerTheme]);
  1166. if (!props.children) {
  1167. return null;
  1168. }
  1169. return React.createElement(ThemeContext.Provider, {
  1170. value: themeContext
  1171. }, props.children);
  1172. }
  1173. /* global $Call */
  1174. var identifiers = {};
  1175. /* We depend on components having unique IDs */
  1176. function generateId(displayName, parentComponentId) {
  1177. var name = typeof displayName !== 'string' ? 'sc' : escape(displayName); // Ensure that no displayName can lead to duplicate componentIds
  1178. identifiers[name] = (identifiers[name] || 0) + 1;
  1179. var componentId = name + "-" + generateComponentId(name + identifiers[name]);
  1180. return parentComponentId ? parentComponentId + "-" + componentId : componentId;
  1181. }
  1182. function useResolvedAttrs(theme, props, attrs) {
  1183. if (theme === void 0) {
  1184. theme = EMPTY_OBJECT;
  1185. }
  1186. // NOTE: can't memoize this
  1187. // returns [context, resolvedAttrs]
  1188. // where resolvedAttrs is only the things injected by the attrs themselves
  1189. var context = _extends({}, props, {
  1190. theme: theme
  1191. });
  1192. var resolvedAttrs = {};
  1193. attrs.forEach(function (attrDef) {
  1194. var resolvedAttrDef = attrDef;
  1195. var key;
  1196. if (isFunction(resolvedAttrDef)) {
  1197. resolvedAttrDef = resolvedAttrDef(context);
  1198. }
  1199. /* eslint-disable guard-for-in */
  1200. for (key in resolvedAttrDef) {
  1201. context[key] = resolvedAttrs[key] = key === 'className' ? joinStrings(resolvedAttrs[key], resolvedAttrDef[key]) : resolvedAttrDef[key];
  1202. }
  1203. /* eslint-enable guard-for-in */
  1204. });
  1205. return [context, resolvedAttrs];
  1206. }
  1207. function useInjectedStyle(componentStyle, hasAttrs, resolvedAttrs, warnTooManyClasses) {
  1208. var styleSheet = useStyleSheet();
  1209. var stylis = useStylis(); // statically styled-components don't need to build an execution context object,
  1210. // and shouldn't be increasing the number of class names
  1211. var isStatic = componentStyle.isStatic && !hasAttrs;
  1212. var className = isStatic ? componentStyle.generateAndInjectStyles(EMPTY_OBJECT, styleSheet, stylis) : componentStyle.generateAndInjectStyles(resolvedAttrs, styleSheet, stylis);
  1213. useDebugValue(className);
  1214. if (process.env.NODE_ENV !== 'production' && !isStatic && warnTooManyClasses) {
  1215. warnTooManyClasses(className);
  1216. }
  1217. return className;
  1218. }
  1219. function useStyledComponentImpl(forwardedComponent, props, forwardedRef) {
  1220. var componentAttrs = forwardedComponent.attrs,
  1221. componentStyle = forwardedComponent.componentStyle,
  1222. defaultProps = forwardedComponent.defaultProps,
  1223. foldedComponentIds = forwardedComponent.foldedComponentIds,
  1224. styledComponentId = forwardedComponent.styledComponentId,
  1225. target = forwardedComponent.target;
  1226. useDebugValue(styledComponentId); // NOTE: the non-hooks version only subscribes to this when !componentStyle.isStatic,
  1227. // but that'd be against the rules-of-hooks. We could be naughty and do it anyway as it
  1228. // should be an immutable value, but behave for now.
  1229. var theme = determineTheme(props, useContext(ThemeContext), defaultProps);
  1230. var _useResolvedAttrs = useResolvedAttrs(theme || EMPTY_OBJECT, props, componentAttrs),
  1231. context = _useResolvedAttrs[0],
  1232. attrs = _useResolvedAttrs[1];
  1233. var generatedClassName = useInjectedStyle(componentStyle, componentAttrs.length > 0, context, process.env.NODE_ENV !== 'production' ? forwardedComponent.warnTooManyClasses : undefined);
  1234. var refToForward = forwardedRef;
  1235. var elementToBeCreated = attrs.as || props.as || target;
  1236. var isTargetTag = isTag(elementToBeCreated);
  1237. var computedProps = attrs !== props ? _extends({}, props, {}, attrs) : props;
  1238. var shouldFilterProps = isTargetTag || 'as' in computedProps || 'forwardedAs' in computedProps;
  1239. var propsForElement = shouldFilterProps ? {} : _extends({}, computedProps);
  1240. if (shouldFilterProps) {
  1241. // eslint-disable-next-line guard-for-in
  1242. for (var key in computedProps) {
  1243. if (key === 'forwardedAs') {
  1244. propsForElement.as = computedProps[key];
  1245. } else if (key !== 'as' && key !== 'forwardedAs' && (!isTargetTag || validAttr(key))) {
  1246. // Don't pass through non HTML tags through to HTML elements
  1247. propsForElement[key] = computedProps[key];
  1248. }
  1249. }
  1250. }
  1251. if (props.style && attrs.style !== props.style) {
  1252. propsForElement.style = _extends({}, props.style, {}, attrs.style);
  1253. }
  1254. propsForElement.className = Array.prototype.concat(foldedComponentIds, styledComponentId, generatedClassName !== styledComponentId ? generatedClassName : null, props.className, attrs.className).filter(Boolean).join(' ');
  1255. propsForElement.ref = refToForward;
  1256. return createElement(elementToBeCreated, propsForElement);
  1257. }
  1258. function createStyledComponent(target, options, rules) {
  1259. var isTargetStyledComp = isStyledComponent(target);
  1260. var isCompositeComponent = !isTag(target);
  1261. var _options$displayName = options.displayName,
  1262. displayName = _options$displayName === void 0 ? generateDisplayName(target) : _options$displayName,
  1263. _options$componentId = options.componentId,
  1264. componentId = _options$componentId === void 0 ? generateId(options.displayName, options.parentComponentId) : _options$componentId,
  1265. _options$attrs = options.attrs,
  1266. attrs = _options$attrs === void 0 ? EMPTY_ARRAY : _options$attrs;
  1267. var styledComponentId = options.displayName && options.componentId ? escape(options.displayName) + "-" + options.componentId : options.componentId || componentId; // fold the underlying StyledComponent attrs up (implicit extend)
  1268. var finalAttrs = // $FlowFixMe
  1269. isTargetStyledComp && target.attrs ? Array.prototype.concat(target.attrs, attrs).filter(Boolean) : attrs;
  1270. var componentStyle = new ComponentStyle(isTargetStyledComp ? // fold the underlying StyledComponent rules up (implicit extend)
  1271. // $FlowFixMe
  1272. target.componentStyle.rules.concat(rules) : rules, styledComponentId);
  1273. /**
  1274. * forwardRef creates a new interim component, which we'll take advantage of
  1275. * instead of extending ParentComponent to create _another_ interim class
  1276. */
  1277. var WrappedStyledComponent; // eslint-disable-next-line react-hooks/rules-of-hooks
  1278. var forwardRef = function forwardRef(props, ref) {
  1279. return useStyledComponentImpl(WrappedStyledComponent, props, ref);
  1280. };
  1281. forwardRef.displayName = displayName; // $FlowFixMe this is a forced cast to merge it StyledComponentWrapperProperties
  1282. WrappedStyledComponent = React.forwardRef(forwardRef);
  1283. WrappedStyledComponent.attrs = finalAttrs;
  1284. WrappedStyledComponent.componentStyle = componentStyle;
  1285. WrappedStyledComponent.displayName = displayName; // this static is used to preserve the cascade of static classes for component selector
  1286. // purposes; this is especially important with usage of the css prop
  1287. WrappedStyledComponent.foldedComponentIds = isTargetStyledComp ? // $FlowFixMe
  1288. Array.prototype.concat(target.foldedComponentIds, target.styledComponentId) : EMPTY_ARRAY;
  1289. WrappedStyledComponent.styledComponentId = styledComponentId; // fold the underlying StyledComponent target up since we folded the styles
  1290. WrappedStyledComponent.target = isTargetStyledComp ? // $FlowFixMe
  1291. target.target : target; // $FlowFixMe
  1292. WrappedStyledComponent.withComponent = function withComponent(tag) {
  1293. var previousComponentId = options.componentId,
  1294. optionsToCopy = _objectWithoutPropertiesLoose(options, ["componentId"]);
  1295. var newComponentId = previousComponentId && previousComponentId + "-" + (isTag(tag) ? tag : escape(getComponentName(tag)));
  1296. var newOptions = _extends({}, optionsToCopy, {
  1297. attrs: finalAttrs,
  1298. componentId: newComponentId
  1299. });
  1300. return createStyledComponent(tag, newOptions, rules);
  1301. }; // $FlowFixMe
  1302. Object.defineProperty(WrappedStyledComponent, 'defaultProps', {
  1303. get: function get() {
  1304. return this._foldedDefaultProps;
  1305. },
  1306. set: function set(obj) {
  1307. // $FlowFixMe
  1308. this._foldedDefaultProps = isTargetStyledComp ? mixinDeep({}, target.defaultProps, obj) : obj;
  1309. }
  1310. });
  1311. if (process.env.NODE_ENV !== 'production') {
  1312. checkDynamicCreation(displayName, styledComponentId);
  1313. WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName, styledComponentId);
  1314. } // $FlowFixMe
  1315. WrappedStyledComponent.toString = function () {
  1316. return "." + WrappedStyledComponent.styledComponentId;
  1317. };
  1318. if (isCompositeComponent) {
  1319. hoist(WrappedStyledComponent, target, {
  1320. // all SC-specific things should not be hoisted
  1321. attrs: true,
  1322. componentStyle: true,
  1323. displayName: true,
  1324. foldedComponentIds: true,
  1325. self: true,
  1326. styledComponentId: true,
  1327. target: true,
  1328. withComponent: true
  1329. });
  1330. }
  1331. return WrappedStyledComponent;
  1332. }
  1333. //
  1334. // Thanks to ReactDOMFactories for this handy list!
  1335. var domElements = ['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'big', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr', // SVG
  1336. 'circle', 'clipPath', 'defs', 'ellipse', 'foreignObject', 'g', 'image', 'line', 'linearGradient', 'marker', 'mask', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'stop', 'svg', 'text', 'tspan'];
  1337. //
  1338. var styled = function styled(tag) {
  1339. return constructWithOptions(createStyledComponent, tag);
  1340. }; // Shorthands for all valid HTML Elements
  1341. domElements.forEach(function (domElement) {
  1342. styled[domElement] = styled(domElement);
  1343. });
  1344. //
  1345. var GlobalStyle =
  1346. /*#__PURE__*/
  1347. function () {
  1348. function GlobalStyle(rules, componentId) {
  1349. this.rules = rules;
  1350. this.componentId = componentId;
  1351. this.isStatic = isStaticRules(rules);
  1352. }
  1353. var _proto = GlobalStyle.prototype;
  1354. _proto.createStyles = function createStyles(instance, executionContext, styleSheet, stylis) {
  1355. var flatCSS = flatten(this.rules, executionContext, styleSheet);
  1356. var css = stylis(flatCSS.join(''), '');
  1357. var id = this.componentId + instance; // NOTE: We use the id as a name as well, since these rules never change
  1358. styleSheet.insertRules(id, id, css);
  1359. };
  1360. _proto.removeStyles = function removeStyles(instance, styleSheet) {
  1361. styleSheet.clearRules(this.componentId + instance);
  1362. };
  1363. _proto.renderStyles = function renderStyles(instance, executionContext, styleSheet, stylis) {
  1364. StyleSheet.registerId(this.componentId + instance); // NOTE: Remove old styles, then inject the new ones
  1365. this.removeStyles(instance, styleSheet);
  1366. this.createStyles(instance, executionContext, styleSheet, stylis);
  1367. };
  1368. return GlobalStyle;
  1369. }();
  1370. function createGlobalStyle(strings) {
  1371. for (var _len = arguments.length, interpolations = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1372. interpolations[_key - 1] = arguments[_key];
  1373. }
  1374. var rules = css.apply(void 0, [strings].concat(interpolations));
  1375. var styledComponentId = "sc-global-" + generateComponentId(JSON.stringify(rules));
  1376. var globalStyle = new GlobalStyle(rules, styledComponentId);
  1377. if (process.env.NODE_ENV !== 'production') {
  1378. checkDynamicCreation(styledComponentId);
  1379. }
  1380. function GlobalStyleComponent(props) {
  1381. var styleSheet = useStyleSheet();
  1382. var stylis = useStylis();
  1383. var theme = useContext(ThemeContext);
  1384. var instanceRef = useRef(null);
  1385. if (instanceRef.current === null) {
  1386. instanceRef.current = styleSheet.allocateGSInstance(styledComponentId);
  1387. }
  1388. var instance = instanceRef.current;
  1389. if (process.env.NODE_ENV !== 'production' && React.Children.count(props.children)) {
  1390. // eslint-disable-next-line no-console
  1391. console.warn("The global style component " + styledComponentId + " was given child JSX. createGlobalStyle does not render children.");
  1392. }
  1393. if (process.env.NODE_ENV !== 'production' && rules.some(function (rule) {
  1394. return typeof rule === 'string' && rule.indexOf('@import') !== -1;
  1395. })) {
  1396. 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.");
  1397. }
  1398. if (globalStyle.isStatic) {
  1399. globalStyle.renderStyles(instance, STATIC_EXECUTION_CONTEXT, styleSheet, stylis);
  1400. } else {
  1401. var context = _extends({}, props, {
  1402. theme: determineTheme(props, theme, GlobalStyleComponent.defaultProps)
  1403. });
  1404. globalStyle.renderStyles(instance, context, styleSheet, stylis);
  1405. }
  1406. useEffect(function () {
  1407. return function () {
  1408. return globalStyle.removeStyles(instance, styleSheet);
  1409. };
  1410. }, EMPTY_ARRAY);
  1411. return null;
  1412. } // $FlowFixMe
  1413. return React.memo(GlobalStyleComponent);
  1414. }
  1415. //
  1416. function keyframes(strings) {
  1417. /* Warning if you've used keyframes on React Native */
  1418. if (process.env.NODE_ENV !== 'production' && typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
  1419. // eslint-disable-next-line no-console
  1420. console.warn('`keyframes` cannot be used on ReactNative, only on the web. To do animation in ReactNative please use Animated.');
  1421. }
  1422. for (var _len = arguments.length, interpolations = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1423. interpolations[_key - 1] = arguments[_key];
  1424. }
  1425. var rules = css.apply(void 0, [strings].concat(interpolations)).join('');
  1426. var name = generateComponentId(rules);
  1427. return new Keyframes(name, [rules, name, '@keyframes']);
  1428. }
  1429. var ServerStyleSheet =
  1430. /*#__PURE__*/
  1431. function () {
  1432. function ServerStyleSheet() {
  1433. var _this = this;
  1434. this._emitSheetCSS = function () {
  1435. var css = _this.instance.toString();
  1436. var nonce = getNonce();
  1437. var attrs = [nonce && "nonce=\"" + nonce + "\"", SC_ATTR + "=\"true\"", SC_ATTR_VERSION + "=\"" + SC_VERSION + "\""];
  1438. var htmlAttr = attrs.filter(Boolean).join(' ');
  1439. return "<style " + htmlAttr + ">" + css + "</style>";
  1440. };
  1441. this.getStyleTags = function () {
  1442. if (_this.sealed) {
  1443. return throwStyledComponentsError(2);
  1444. }
  1445. return _this._emitSheetCSS();
  1446. };
  1447. this.getStyleElement = function () {
  1448. var _props;
  1449. if (_this.sealed) {
  1450. return throwStyledComponentsError(2);
  1451. }
  1452. var props = (_props = {}, _props[SC_ATTR] = '', _props[SC_ATTR_VERSION] = SC_VERSION, _props.dangerouslySetInnerHTML = {
  1453. __html: _this.instance.toString()
  1454. }, _props);
  1455. var nonce = getNonce();
  1456. if (nonce) {
  1457. props.nonce = nonce;
  1458. } // v4 returned an array for this fn, so we'll do the same for v5 for backward compat
  1459. return [React.createElement("style", _extends({}, props, {
  1460. key: "sc-0-0"
  1461. }))];
  1462. };
  1463. this.seal = function () {
  1464. _this.sealed = true;
  1465. };
  1466. this.instance = new StyleSheet({
  1467. isServer: true
  1468. });
  1469. this.sealed = false;
  1470. }
  1471. var _proto = ServerStyleSheet.prototype;
  1472. _proto.collectStyles = function collectStyles(children) {
  1473. if (this.sealed) {
  1474. return throwStyledComponentsError(2);
  1475. }
  1476. return React.createElement(StyleSheetManager, {
  1477. sheet: this.instance
  1478. }, children);
  1479. };
  1480. // eslint-disable-next-line consistent-return
  1481. _proto.interleaveWithNodeStream = function interleaveWithNodeStream(input) {
  1482. {
  1483. return throwStyledComponentsError(3);
  1484. }
  1485. };
  1486. return ServerStyleSheet;
  1487. }();
  1488. // export default <Config: { theme?: any }, Instance>(
  1489. // Component: AbstractComponent<Config, Instance>
  1490. // ): AbstractComponent<$Diff<Config, { theme?: any }> & { theme?: any }, Instance>
  1491. //
  1492. // but the old build system tooling doesn't support the syntax
  1493. var withTheme = (function (Component) {
  1494. // $FlowFixMe This should be React.forwardRef<Config, Instance>
  1495. var WithTheme = React.forwardRef(function (props, ref) {
  1496. var theme = useContext(ThemeContext); // $FlowFixMe defaultProps isn't declared so it can be inferrable
  1497. var defaultProps = Component.defaultProps;
  1498. var themeProp = determineTheme(props, theme, defaultProps);
  1499. if (process.env.NODE_ENV !== 'production' && themeProp === undefined) {
  1500. // eslint-disable-next-line no-console
  1501. console.warn("[withTheme] You are not using a ThemeProvider nor passing a theme prop or a theme in defaultProps in component class \"" + getComponentName(Component) + "\"");
  1502. }
  1503. return React.createElement(Component, _extends({}, props, {
  1504. theme: themeProp,
  1505. ref: ref
  1506. }));
  1507. });
  1508. hoist(WithTheme, Component);
  1509. WithTheme.displayName = "WithTheme(" + getComponentName(Component) + ")";
  1510. return WithTheme;
  1511. });
  1512. //
  1513. var useTheme = function useTheme() {
  1514. return useContext(ThemeContext);
  1515. };
  1516. //
  1517. var __PRIVATE__ = {
  1518. StyleSheet: StyleSheet,
  1519. masterSheet: masterSheet
  1520. };
  1521. //
  1522. /* Define bundle version for export */
  1523. var version = "5.0.1";
  1524. /* Warning if you've imported this file on React Native */
  1525. if (process.env.NODE_ENV !== 'production' && typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
  1526. // eslint-disable-next-line no-console
  1527. console.warn("It looks like you've imported 'styled-components' on React Native.\n" + "Perhaps you're looking to import 'styled-components/native'?\n" + 'Read more about this at https://www.styled-components.com/docs/basics#react-native');
  1528. }
  1529. /* Warning if there are several instances of styled-components */
  1530. if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test' && typeof window !== 'undefined') {
  1531. window['__styled-components-init__'] = window['__styled-components-init__'] || 0;
  1532. if (window['__styled-components-init__'] === 1) {
  1533. // eslint-disable-next-line no-console
  1534. console.warn("It looks like there are several instances of 'styled-components' initialized in this application. " + 'This may cause dynamic styles not rendering properly, errors happening during rehydration process, ' + 'missing theme prop, and makes your application bigger without a good reason.\n\n' + 'See https://s-c.sh/2BAXzed for more info.');
  1535. }
  1536. window['__styled-components-init__'] += 1;
  1537. }
  1538. export default styled;
  1539. export { ServerStyleSheet, StyleSheetConsumer, StyleSheetContext, StyleSheetManager, ThemeConsumer, ThemeContext, ThemeProvider, __PRIVATE__, createGlobalStyle, css, isStyledComponent, keyframes, useTheme, version, withTheme };
  1540. //# sourceMappingURL=styled-components.browser.esm.js.map