cache.cjs.js
3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var sheet = require('@emotion/sheet');
var utils = require('@emotion/utils');
var Stylis = _interopDefault(require('@emotion/stylis'));
// https://github.com/thysultan/stylis.js/tree/master/plugins/rule-sheet
// inlined to avoid umd wrapper and peerDep warnings/installing stylis
// since we use stylis after closure compiler
var delimiter = '/*|*/';
var needle = delimiter + '}';
function toSheet(block) {
if (block) {
current.push(block + '}');
}
}
var ruleSheet = function ruleSheet(context, content, selectors, parents, line, column, length, at, depth) {
switch (context) {
case -1:
{
current = [];
break;
}
case 2:
if (at === 0) return content + delimiter;
break;
// at-rule
case 3:
switch (at) {
// @font-face, @page
case 102:
case 112:
{
current.push(selectors[0] + content);
return '';
}
default:
{
return content + delimiter;
}
}
case -2:
{
content.split(needle).forEach(toSheet);
return current;
}
}
};
var current;
var createCache = function createCache(options) {
if (options === undefined) options = {};
var key = options.key || 'css';
var stylisOptions;
if (options.prefix !== undefined) {
stylisOptions = {
prefix: options.prefix
};
}
var stylis = new Stylis(stylisOptions);
stylis.use(options.stylisPlugins)(ruleSheet);
if (process.env.NODE_ENV !== 'production') {
// $FlowFixMe
if (/[^a-z-]/.test(key)) {
throw new Error("Emotion key must only contain lower case alphabetical characters and - but \"" + key + "\" was passed");
}
var sourceMapRegEx = /\/\*#\ssourceMappingURL=data:application\/json;\S+\s+\*\//;
var currentSourceMap;
stylis.use(function (context, content, selectors) {
switch (context) {
case -1:
{
var result = sourceMapRegEx.exec(content);
if (result) {
currentSourceMap = result[0];
}
break;
}
case 2:
{
for (var i = 0, len = selectors.length; len > i; i++) {
// :last-child isn't included here since it's safe
// because a style element will never be the last element
var match = selectors[i].match(/:(first|nth|nth-last)-child/);
if (match !== null) {
console.error("The pseudo class \"" + match[1] + "\" is potentially unsafe when doing server-side rendering. Try changing it to \"" + match[1] + "-of-type\"");
}
}
break;
}
case -2:
{
if (currentSourceMap) {
content.forEach(function (rule, i) {
content[i] = rule + currentSourceMap;
});
currentSourceMap = '';
}
}
}
});
}
var inserted = {}; // $FlowFixMe
var container;
if (utils.isBrowser) {
container = options.container || document.head;
var nodes = document.querySelectorAll("style[data-emotion-" + key + "]");
Array.prototype.forEach.call(nodes, function (node) {
var attrib = node.getAttribute("data-emotion-" + key); // $FlowFixMe
attrib.split(' ').forEach(function (id) {
inserted[id] = true;
});
if (node.parentNode !== container) {
container.appendChild(node);
}
});
}
var context = {
stylis: stylis,
key: key,
sheet: new sheet.StyleSheet({
key: key,
container: container,
nonce: options.nonce
}),
inserted: inserted,
registered: {},
theme: {}
};
return context;
};
module.exports = createCache;