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.cjs.dev.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. var weakMemoize = _interopDefault(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 removeLabel = function removeLabel(context, content) {
  74. if (context === 1 && // charcode for l
  75. content.charCodeAt(0) === 108 && // charcode for b
  76. content.charCodeAt(2) === 98 // this ignores label
  77. ) {
  78. return '';
  79. }
  80. };
  81. var isBrowser = typeof document !== 'undefined';
  82. var rootServerStylisCache = {};
  83. var getServerStylisCache = isBrowser ? undefined : weakMemoize(function () {
  84. var getCache = weakMemoize(function () {
  85. return {};
  86. });
  87. var prefixTrueCache = {};
  88. var prefixFalseCache = {};
  89. return function (prefix) {
  90. if (prefix === undefined || prefix === true) {
  91. return prefixTrueCache;
  92. }
  93. if (prefix === false) {
  94. return prefixFalseCache;
  95. }
  96. return getCache(prefix);
  97. };
  98. });
  99. var createCache = function createCache(options) {
  100. if (options === undefined) options = {};
  101. var key = options.key || 'css';
  102. var stylisOptions;
  103. if (options.prefix !== undefined) {
  104. stylisOptions = {
  105. prefix: options.prefix
  106. };
  107. }
  108. var stylis = new Stylis(stylisOptions);
  109. if (process.env.NODE_ENV !== 'production') {
  110. // $FlowFixMe
  111. if (/[^a-z-]/.test(key)) {
  112. throw new Error("Emotion key must only contain lower case alphabetical characters and - but \"" + key + "\" was passed");
  113. }
  114. }
  115. var inserted = {}; // $FlowFixMe
  116. var container;
  117. if (isBrowser) {
  118. container = options.container || document.head;
  119. var nodes = document.querySelectorAll("style[data-emotion-" + key + "]");
  120. Array.prototype.forEach.call(nodes, function (node) {
  121. var attrib = node.getAttribute("data-emotion-" + key); // $FlowFixMe
  122. attrib.split(' ').forEach(function (id) {
  123. inserted[id] = true;
  124. });
  125. if (node.parentNode !== container) {
  126. container.appendChild(node);
  127. }
  128. });
  129. }
  130. var _insert;
  131. if (isBrowser) {
  132. stylis.use(options.stylisPlugins)(ruleSheet);
  133. _insert = function insert(selector, serialized, sheet, shouldCache) {
  134. var name = serialized.name;
  135. Sheet.current = sheet;
  136. if (process.env.NODE_ENV !== 'production' && serialized.map !== undefined) {
  137. var map = serialized.map;
  138. Sheet.current = {
  139. insert: function insert(rule) {
  140. sheet.insert(rule + map);
  141. }
  142. };
  143. }
  144. stylis(selector, serialized.styles);
  145. if (shouldCache) {
  146. cache.inserted[name] = true;
  147. }
  148. };
  149. } else {
  150. stylis.use(removeLabel);
  151. var serverStylisCache = rootServerStylisCache;
  152. if (options.stylisPlugins || options.prefix !== undefined) {
  153. stylis.use(options.stylisPlugins); // $FlowFixMe
  154. serverStylisCache = getServerStylisCache(options.stylisPlugins || rootServerStylisCache)(options.prefix);
  155. }
  156. var getRules = function getRules(selector, serialized) {
  157. var name = serialized.name;
  158. if (serverStylisCache[name] === undefined) {
  159. serverStylisCache[name] = stylis(selector, serialized.styles);
  160. }
  161. return serverStylisCache[name];
  162. };
  163. _insert = function _insert(selector, serialized, sheet, shouldCache) {
  164. var name = serialized.name;
  165. var rules = getRules(selector, serialized);
  166. if (cache.compat === undefined) {
  167. // in regular mode, we don't set the styles on the inserted cache
  168. // since we don't need to and that would be wasting memory
  169. // we return them so that they are rendered in a style tag
  170. if (shouldCache) {
  171. cache.inserted[name] = true;
  172. }
  173. if ( // using === development instead of !== production
  174. // because if people do ssr in tests, the source maps showing up would be annoying
  175. process.env.NODE_ENV === 'development' && serialized.map !== undefined) {
  176. return rules + serialized.map;
  177. }
  178. return rules;
  179. } else {
  180. // in compat mode, we put the styles on the inserted cache so
  181. // that emotion-server can pull out the styles
  182. // except when we don't want to cache it which was in Global but now
  183. // is nowhere but we don't want to do a major right now
  184. // and just in case we're going to leave the case here
  185. // it's also not affecting client side bundle size
  186. // so it's really not a big deal
  187. if (shouldCache) {
  188. cache.inserted[name] = rules;
  189. } else {
  190. return rules;
  191. }
  192. }
  193. };
  194. }
  195. if (process.env.NODE_ENV !== 'production') {
  196. // https://esbench.com/bench/5bf7371a4cd7e6009ef61d0a
  197. var commentStart = /\/\*/g;
  198. var commentEnd = /\*\//g;
  199. stylis.use(function (context, content) {
  200. switch (context) {
  201. case -1:
  202. {
  203. while (commentStart.test(content)) {
  204. commentEnd.lastIndex = commentStart.lastIndex;
  205. if (commentEnd.test(content)) {
  206. commentStart.lastIndex = commentEnd.lastIndex;
  207. continue;
  208. }
  209. throw new Error('Your styles have an unterminated comment ("/*" without corresponding "*/").');
  210. }
  211. commentStart.lastIndex = 0;
  212. break;
  213. }
  214. }
  215. });
  216. stylis.use(function (context, content, selectors) {
  217. switch (context) {
  218. case -1:
  219. {
  220. var flag = 'emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason';
  221. var unsafePseudoClasses = content.match(/(:first|:nth|:nth-last)-child/g);
  222. if (unsafePseudoClasses && cache.compat !== true) {
  223. unsafePseudoClasses.forEach(function (unsafePseudoClass) {
  224. var ignoreRegExp = new RegExp(unsafePseudoClass + ".*\\/\\* " + flag + " \\*\\/");
  225. var ignore = ignoreRegExp.test(content);
  226. if (unsafePseudoClass && !ignore) {
  227. console.error("The pseudo class \"" + unsafePseudoClass + "\" is potentially unsafe when doing server-side rendering. Try changing it to \"" + unsafePseudoClass.split('-child')[0] + "-of-type\".");
  228. }
  229. });
  230. }
  231. break;
  232. }
  233. }
  234. });
  235. }
  236. var cache = {
  237. key: key,
  238. sheet: new sheet.StyleSheet({
  239. key: key,
  240. container: container,
  241. nonce: options.nonce,
  242. speedy: options.speedy
  243. }),
  244. nonce: options.nonce,
  245. inserted: inserted,
  246. registered: {},
  247. insert: _insert
  248. };
  249. return cache;
  250. };
  251. exports.default = createCache;