Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cache.browser.cjs.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var sheet = require('@emotion/sheet');
  5. var Stylis = _interopDefault(require('@emotion/stylis'));
  6. require('@emotion/weak-memoize');
  7. // https://github.com/thysultan/stylis.js/tree/master/plugins/rule-sheet
  8. // inlined to avoid umd wrapper and peerDep warnings/installing stylis
  9. // since we use stylis after closure compiler
  10. var delimiter = '/*|*/';
  11. var needle = delimiter + '}';
  12. function toSheet(block) {
  13. if (block) {
  14. Sheet.current.insert(block + '}');
  15. }
  16. }
  17. var Sheet = {
  18. current: null
  19. };
  20. var ruleSheet = function ruleSheet(context, content, selectors, parents, line, column, length, ns, depth, at) {
  21. switch (context) {
  22. // property
  23. case 1:
  24. {
  25. switch (content.charCodeAt(0)) {
  26. case 64:
  27. {
  28. // @import
  29. Sheet.current.insert(content + ';');
  30. return '';
  31. }
  32. // charcode for l
  33. case 108:
  34. {
  35. // charcode for b
  36. // this ignores label
  37. if (content.charCodeAt(2) === 98) {
  38. return '';
  39. }
  40. }
  41. }
  42. break;
  43. }
  44. // selector
  45. case 2:
  46. {
  47. if (ns === 0) return content + delimiter;
  48. break;
  49. }
  50. // at-rule
  51. case 3:
  52. {
  53. switch (ns) {
  54. // @font-face, @page
  55. case 102:
  56. case 112:
  57. {
  58. Sheet.current.insert(selectors[0] + content);
  59. return '';
  60. }
  61. default:
  62. {
  63. return content + (at === 0 ? delimiter : '');
  64. }
  65. }
  66. }
  67. case -2:
  68. {
  69. content.split(needle).forEach(toSheet);
  70. }
  71. }
  72. };
  73. var createCache = function createCache(options) {
  74. if (options === undefined) options = {};
  75. var key = options.key || 'css';
  76. var stylisOptions;
  77. if (options.prefix !== undefined) {
  78. stylisOptions = {
  79. prefix: options.prefix
  80. };
  81. }
  82. var stylis = new Stylis(stylisOptions);
  83. if (process.env.NODE_ENV !== 'production') {
  84. // $FlowFixMe
  85. if (/[^a-z-]/.test(key)) {
  86. throw new Error("Emotion key must only contain lower case alphabetical characters and - but \"" + key + "\" was passed");
  87. }
  88. }
  89. var inserted = {}; // $FlowFixMe
  90. var container;
  91. {
  92. container = options.container || document.head;
  93. var nodes = document.querySelectorAll("style[data-emotion-" + key + "]");
  94. Array.prototype.forEach.call(nodes, function (node) {
  95. var attrib = node.getAttribute("data-emotion-" + key); // $FlowFixMe
  96. attrib.split(' ').forEach(function (id) {
  97. inserted[id] = true;
  98. });
  99. if (node.parentNode !== container) {
  100. container.appendChild(node);
  101. }
  102. });
  103. }
  104. var _insert;
  105. {
  106. stylis.use(options.stylisPlugins)(ruleSheet);
  107. _insert = function insert(selector, serialized, sheet, shouldCache) {
  108. var name = serialized.name;
  109. Sheet.current = sheet;
  110. if (process.env.NODE_ENV !== 'production' && serialized.map !== undefined) {
  111. var map = serialized.map;
  112. Sheet.current = {
  113. insert: function insert(rule) {
  114. sheet.insert(rule + map);
  115. }
  116. };
  117. }
  118. stylis(selector, serialized.styles);
  119. if (shouldCache) {
  120. cache.inserted[name] = true;
  121. }
  122. };
  123. }
  124. if (process.env.NODE_ENV !== 'production') {
  125. // https://esbench.com/bench/5bf7371a4cd7e6009ef61d0a
  126. var commentStart = /\/\*/g;
  127. var commentEnd = /\*\//g;
  128. stylis.use(function (context, content) {
  129. switch (context) {
  130. case -1:
  131. {
  132. while (commentStart.test(content)) {
  133. commentEnd.lastIndex = commentStart.lastIndex;
  134. if (commentEnd.test(content)) {
  135. commentStart.lastIndex = commentEnd.lastIndex;
  136. continue;
  137. }
  138. throw new Error('Your styles have an unterminated comment ("/*" without corresponding "*/").');
  139. }
  140. commentStart.lastIndex = 0;
  141. break;
  142. }
  143. }
  144. });
  145. stylis.use(function (context, content, selectors) {
  146. switch (context) {
  147. case -1:
  148. {
  149. var flag = 'emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason';
  150. var unsafePseudoClasses = content.match(/(:first|:nth|:nth-last)-child/g);
  151. if (unsafePseudoClasses && cache.compat !== true) {
  152. unsafePseudoClasses.forEach(function (unsafePseudoClass) {
  153. var ignoreRegExp = new RegExp(unsafePseudoClass + ".*\\/\\* " + flag + " \\*\\/");
  154. var ignore = ignoreRegExp.test(content);
  155. if (unsafePseudoClass && !ignore) {
  156. console.error("The pseudo class \"" + unsafePseudoClass + "\" is potentially unsafe when doing server-side rendering. Try changing it to \"" + unsafePseudoClass.split('-child')[0] + "-of-type\".");
  157. }
  158. });
  159. }
  160. break;
  161. }
  162. }
  163. });
  164. }
  165. var cache = {
  166. key: key,
  167. sheet: new sheet.StyleSheet({
  168. key: key,
  169. container: container,
  170. nonce: options.nonce,
  171. speedy: options.speedy
  172. }),
  173. nonce: options.nonce,
  174. inserted: inserted,
  175. registered: {},
  176. insert: _insert
  177. };
  178. return cache;
  179. };
  180. exports.default = createCache;