@helpdice/theme 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +37 -0
- package/dist/css-baseline/css-baseline.d.ts +9 -0
- package/dist/css-baseline/index.d.ts +1 -0
- package/dist/css-baseline/index.js +868 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1516 -0
- package/dist/shared/css-transition.d.ts +13 -0
- package/dist/styled-jsx.cjs.js +748 -0
- package/dist/themes/index.d.ts +4 -0
- package/dist/themes/index.js +299 -0
- package/dist/themes/presets/dark.d.ts +8 -0
- package/dist/themes/presets/default.d.ts +8 -0
- package/dist/themes/presets/index.d.ts +90 -0
- package/dist/themes/presets/shared.d.ts +4 -0
- package/dist/themes/themes.d.ts +18 -0
- package/dist/ui-provider/index.d.ts +3 -0
- package/dist/ui-provider/index.js +1425 -0
- package/dist/ui-provider/theme-provider.d.ts +8 -0
- package/dist/ui-provider/ui-provider.d.ts +8 -0
- package/dist/use-all-themes/all-themes-context.d.ts +7 -0
- package/dist/use-all-themes/index.d.ts +3 -0
- package/dist/use-all-themes/index.js +311 -0
- package/dist/use-classes/index.d.ts +2 -0
- package/dist/use-classes/index.js +48 -0
- package/dist/use-classes/use-classes.d.ts +4 -0
- package/dist/use-current-state/index.d.ts +2 -0
- package/dist/use-current-state/index.js +72 -0
- package/dist/use-current-state/use-current-state.d.ts +4 -0
- package/dist/use-media-query/index.js +444 -0
- package/dist/use-theme/index.d.ts +2 -0
- package/dist/use-theme/index.js +309 -0
- package/dist/use-theme/theme-context.d.ts +4 -0
- package/dist/use-toasts/helpers.d.ts +18 -0
- package/dist/use-toasts/index.js +204 -0
- package/dist/use-toasts/toast-container.d.ts +3 -0
- package/dist/use-toasts/toast-item.d.ts +8 -0
- package/dist/use-toasts/use-toast.d.ts +40 -0
- package/dist/utils/collections.d.ts +15 -0
- package/dist/utils/layouts.d.ts +20 -0
- package/dist/utils/prop-types.d.ts +19 -0
- package/dist/utils/types.d.ts +3 -0
- package/dist/utils/use-current-state.d.ts +2 -0
- package/dist/utils/use-hd-ui-context.d.ts +16 -0
- package/dist/utils/use-portal.d.ts +2 -0
- package/dist/utils/use-ssr.d.ts +6 -0
- package/esm/css-baseline/css-baseline.d.ts +9 -0
- package/esm/css-baseline/css-baseline.js +23 -0
- package/esm/css-baseline/index.d.ts +1 -0
- package/esm/css-baseline/index.js +2 -0
- package/esm/index.d.ts +12 -0
- package/esm/index.js +11 -0
- package/esm/shared/backdrop.js +66 -0
- package/esm/shared/css-transition.d.ts +13 -0
- package/esm/shared/css-transition.js +65 -0
- package/esm/shared/dropdown.js +99 -0
- package/esm/shared/ellipsis.js +13 -0
- package/esm/shared/expand.js +86 -0
- package/esm/shared/highlight.js +46 -0
- package/esm/styled-jsx-server.es.js +5 -0
- package/esm/styled-jsx.es.js +737 -0
- package/esm/themes/index.d.ts +4 -0
- package/esm/themes/index.js +2 -0
- package/esm/themes/presets/dark.d.ts +8 -0
- package/esm/themes/presets/dark.js +64 -0
- package/esm/themes/presets/default.d.ts +8 -0
- package/esm/themes/presets/default.js +64 -0
- package/esm/themes/presets/index.d.ts +90 -0
- package/esm/themes/presets/index.js +1 -0
- package/esm/themes/presets/shared.d.ts +4 -0
- package/esm/themes/presets/shared.js +42 -0
- package/esm/themes/themes.d.ts +18 -0
- package/esm/themes/themes.js +77 -0
- package/esm/ui-provider/index.d.ts +3 -0
- package/esm/ui-provider/index.js +4 -0
- package/esm/ui-provider/theme-provider.d.ts +8 -0
- package/esm/ui-provider/theme-provider.js +45 -0
- package/esm/ui-provider/ui-provider.d.ts +8 -0
- package/esm/ui-provider/ui-provider.js +55 -0
- package/esm/use-all-themes/all-themes-context.d.ts +7 -0
- package/esm/use-all-themes/all-themes-context.js +11 -0
- package/esm/use-all-themes/index.d.ts +3 -0
- package/esm/use-all-themes/index.js +2 -0
- package/esm/use-classes/index.d.ts +2 -0
- package/esm/use-classes/index.js +2 -0
- package/esm/use-classes/use-classes.d.ts +4 -0
- package/esm/use-classes/use-classes.js +34 -0
- package/esm/use-current-state/index.d.ts +2 -0
- package/esm/use-current-state/index.js +2 -0
- package/esm/use-current-state/use-current-state.d.ts +4 -0
- package/esm/use-current-state/use-current-state.js +23 -0
- package/esm/use-media-query/index.js +2 -0
- package/esm/use-media-query/use-media-query.js +81 -0
- package/esm/use-theme/index.d.ts +2 -0
- package/esm/use-theme/index.js +2 -0
- package/esm/use-theme/theme-context.d.ts +4 -0
- package/esm/use-theme/theme-context.js +9 -0
- package/esm/use-toasts/helpers.d.ts +18 -0
- package/esm/use-toasts/helpers.js +66 -0
- package/esm/use-toasts/index.js +2 -0
- package/esm/use-toasts/toast-container.d.ts +3 -0
- package/esm/use-toasts/toast-container.js +120 -0
- package/esm/use-toasts/toast-item.d.ts +8 -0
- package/esm/use-toasts/toast-item.js +45 -0
- package/esm/use-toasts/use-toast.d.ts +40 -0
- package/esm/use-toasts/use-toast.js +103 -0
- package/esm/utils/calculations.js +29 -0
- package/esm/utils/collections.d.ts +15 -0
- package/esm/utils/collections.js +128 -0
- package/esm/utils/color.js +35 -0
- package/esm/utils/layouts.d.ts +20 -0
- package/esm/utils/layouts.js +73 -0
- package/esm/utils/prop-types.d.ts +19 -0
- package/esm/utils/prop-types.js +20 -0
- package/esm/utils/types.d.ts +3 -0
- package/esm/utils/types.js +1 -0
- package/esm/utils/use-click-anywhere.js +15 -0
- package/esm/utils/use-context-state/create-ui-context.js +50 -0
- package/esm/utils/use-context-state/use-context-state.js +40 -0
- package/esm/utils/use-current-state.d.ts +2 -0
- package/esm/utils/use-current-state.js +2 -0
- package/esm/utils/use-default-props.js +17 -0
- package/esm/utils/use-dom-observer.js +26 -0
- package/esm/utils/use-hd-ui-context.d.ts +16 -0
- package/esm/utils/use-hd-ui-context.js +27 -0
- package/esm/utils/use-portal.d.ts +2 -0
- package/esm/utils/use-portal.js +34 -0
- package/esm/utils/use-previous.js +11 -0
- package/esm/utils/use-real-shape.js +47 -0
- package/esm/utils/use-resize.js +19 -0
- package/esm/utils/use-ssr.d.ts +6 -0
- package/esm/utils/use-ssr.js +19 -0
- package/esm/utils/use-warning.js +13 -0
- package/package.json +111 -0
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var React = require('react')
|
|
4
|
+
|
|
5
|
+
function _interopDefaultLegacy(e) {
|
|
6
|
+
return e && typeof e === 'object' && 'default' in e ? e : { default: e }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/ _interopDefaultLegacy(React)
|
|
10
|
+
|
|
11
|
+
var style$1 = {}
|
|
12
|
+
|
|
13
|
+
var stylesheetRegistry = {}
|
|
14
|
+
|
|
15
|
+
function hash(str) {
|
|
16
|
+
var hash = 5381,
|
|
17
|
+
i = str.length
|
|
18
|
+
|
|
19
|
+
while (i) {
|
|
20
|
+
hash = (hash * 33) ^ str.charCodeAt(--i)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/* JavaScript does bitwise operations (like XOR, above) on 32-bit signed
|
|
24
|
+
* integers. Since we want the results to be always positive, convert the
|
|
25
|
+
* signed int to an unsigned by doing an unsigned bitshift. */
|
|
26
|
+
return hash >>> 0
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var stringHash = hash
|
|
30
|
+
|
|
31
|
+
var stylesheet = {}
|
|
32
|
+
|
|
33
|
+
;(function (exports) {
|
|
34
|
+
exports.__esModule = true
|
|
35
|
+
exports['default'] = void 0
|
|
36
|
+
|
|
37
|
+
function _defineProperties(target, props) {
|
|
38
|
+
for (var i = 0; i < props.length; i++) {
|
|
39
|
+
var descriptor = props[i]
|
|
40
|
+
descriptor.enumerable = descriptor.enumerable || false
|
|
41
|
+
descriptor.configurable = true
|
|
42
|
+
if ('value' in descriptor) descriptor.writable = true
|
|
43
|
+
Object.defineProperty(target, descriptor.key, descriptor)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
48
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps)
|
|
49
|
+
if (staticProps) _defineProperties(Constructor, staticProps)
|
|
50
|
+
return Constructor
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
Based on Glamor's sheet
|
|
55
|
+
https://github.com/threepointone/glamor/blob/667b480d31b3721a905021b26e1290ce92ca2879/src/sheet.js
|
|
56
|
+
*/
|
|
57
|
+
var isProd =
|
|
58
|
+
typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'production'
|
|
59
|
+
|
|
60
|
+
var isString = function isString(o) {
|
|
61
|
+
return Object.prototype.toString.call(o) === '[object String]'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var StyleSheet = /*#__PURE__*/ (function () {
|
|
65
|
+
function StyleSheet(_temp) {
|
|
66
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
67
|
+
_ref$name = _ref.name,
|
|
68
|
+
name = _ref$name === void 0 ? 'stylesheet' : _ref$name,
|
|
69
|
+
_ref$optimizeForSpeed = _ref.optimizeForSpeed,
|
|
70
|
+
optimizeForSpeed =
|
|
71
|
+
_ref$optimizeForSpeed === void 0 ? isProd : _ref$optimizeForSpeed,
|
|
72
|
+
_ref$isBrowser = _ref.isBrowser,
|
|
73
|
+
isBrowser =
|
|
74
|
+
_ref$isBrowser === void 0 ? typeof window !== 'undefined' : _ref$isBrowser
|
|
75
|
+
|
|
76
|
+
invariant(isString(name), '`name` must be a string')
|
|
77
|
+
this._name = name
|
|
78
|
+
this._deletedRulePlaceholder = '#' + name + '-deleted-rule____{}'
|
|
79
|
+
invariant(
|
|
80
|
+
typeof optimizeForSpeed === 'boolean',
|
|
81
|
+
'`optimizeForSpeed` must be a boolean',
|
|
82
|
+
)
|
|
83
|
+
this._optimizeForSpeed = optimizeForSpeed
|
|
84
|
+
this._isBrowser = isBrowser
|
|
85
|
+
this._serverSheet = undefined
|
|
86
|
+
this._tags = []
|
|
87
|
+
this._injected = false
|
|
88
|
+
this._rulesCount = 0
|
|
89
|
+
var node = this._isBrowser && document.querySelector('meta[property="csp-nonce"]')
|
|
90
|
+
this._nonce = node ? node.getAttribute('content') : null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
var _proto = StyleSheet.prototype
|
|
94
|
+
|
|
95
|
+
_proto.setOptimizeForSpeed = function setOptimizeForSpeed(bool) {
|
|
96
|
+
invariant(typeof bool === 'boolean', '`setOptimizeForSpeed` accepts a boolean')
|
|
97
|
+
invariant(
|
|
98
|
+
this._rulesCount === 0,
|
|
99
|
+
'optimizeForSpeed cannot be when rules have already been inserted',
|
|
100
|
+
)
|
|
101
|
+
this.flush()
|
|
102
|
+
this._optimizeForSpeed = bool
|
|
103
|
+
this.inject()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
_proto.isOptimizeForSpeed = function isOptimizeForSpeed() {
|
|
107
|
+
return this._optimizeForSpeed
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
_proto.inject = function inject() {
|
|
111
|
+
var _this = this
|
|
112
|
+
|
|
113
|
+
invariant(!this._injected, 'sheet already injected')
|
|
114
|
+
this._injected = true
|
|
115
|
+
|
|
116
|
+
if (this._isBrowser && this._optimizeForSpeed) {
|
|
117
|
+
this._tags[0] = this.makeStyleTag(this._name)
|
|
118
|
+
this._optimizeForSpeed = 'insertRule' in this.getSheet()
|
|
119
|
+
|
|
120
|
+
if (!this._optimizeForSpeed) {
|
|
121
|
+
if (!isProd) {
|
|
122
|
+
console.warn(
|
|
123
|
+
'StyleSheet: optimizeForSpeed mode not supported falling back to standard mode.',
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
this.flush()
|
|
128
|
+
this._injected = true
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this._serverSheet = {
|
|
135
|
+
cssRules: [],
|
|
136
|
+
insertRule: function insertRule(rule, index) {
|
|
137
|
+
if (typeof index === 'number') {
|
|
138
|
+
_this._serverSheet.cssRules[index] = {
|
|
139
|
+
cssText: rule,
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
_this._serverSheet.cssRules.push({
|
|
143
|
+
cssText: rule,
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return index
|
|
148
|
+
},
|
|
149
|
+
deleteRule: function deleteRule(index) {
|
|
150
|
+
_this._serverSheet.cssRules[index] = null
|
|
151
|
+
},
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_proto.getSheetForTag = function getSheetForTag(tag) {
|
|
156
|
+
if (tag.sheet) {
|
|
157
|
+
return tag.sheet
|
|
158
|
+
} // this weirdness brought to you by firefox
|
|
159
|
+
|
|
160
|
+
for (var i = 0; i < document.styleSheets.length; i++) {
|
|
161
|
+
if (document.styleSheets[i].ownerNode === tag) {
|
|
162
|
+
return document.styleSheets[i]
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
_proto.getSheet = function getSheet() {
|
|
168
|
+
return this.getSheetForTag(this._tags[this._tags.length - 1])
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
_proto.insertRule = function insertRule(rule, index) {
|
|
172
|
+
invariant(isString(rule), '`insertRule` accepts only strings')
|
|
173
|
+
|
|
174
|
+
if (!this._isBrowser) {
|
|
175
|
+
if (typeof index !== 'number') {
|
|
176
|
+
index = this._serverSheet.cssRules.length
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
this._serverSheet.insertRule(rule, index)
|
|
180
|
+
|
|
181
|
+
return this._rulesCount++
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (this._optimizeForSpeed) {
|
|
185
|
+
var sheet = this.getSheet()
|
|
186
|
+
|
|
187
|
+
if (typeof index !== 'number') {
|
|
188
|
+
index = sheet.cssRules.length
|
|
189
|
+
} // this weirdness for perf, and chrome's weird bug
|
|
190
|
+
// https://stackoverflow.com/questions/20007992/chrome-suddenly-stopped-accepting-insertrule
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
sheet.insertRule(rule, index)
|
|
194
|
+
} catch (error) {
|
|
195
|
+
if (!isProd) {
|
|
196
|
+
console.warn(
|
|
197
|
+
'StyleSheet: illegal rule: \n\n' +
|
|
198
|
+
rule +
|
|
199
|
+
'\n\nSee https://stackoverflow.com/q/20007992 for more info',
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return -1
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
var insertionPoint = this._tags[index]
|
|
207
|
+
|
|
208
|
+
this._tags.push(this.makeStyleTag(this._name, rule, insertionPoint))
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return this._rulesCount++
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
_proto.replaceRule = function replaceRule(index, rule) {
|
|
215
|
+
if (this._optimizeForSpeed || !this._isBrowser) {
|
|
216
|
+
var sheet = this._isBrowser ? this.getSheet() : this._serverSheet
|
|
217
|
+
|
|
218
|
+
if (!rule.trim()) {
|
|
219
|
+
rule = this._deletedRulePlaceholder
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (!sheet.cssRules[index]) {
|
|
223
|
+
// @TBD Should we throw an error?
|
|
224
|
+
return index
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
sheet.deleteRule(index)
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
sheet.insertRule(rule, index)
|
|
231
|
+
} catch (error) {
|
|
232
|
+
if (!isProd) {
|
|
233
|
+
console.warn(
|
|
234
|
+
'StyleSheet: illegal rule: \n\n' +
|
|
235
|
+
rule +
|
|
236
|
+
'\n\nSee https://stackoverflow.com/q/20007992 for more info',
|
|
237
|
+
)
|
|
238
|
+
} // In order to preserve the indices we insert a deleteRulePlaceholder
|
|
239
|
+
|
|
240
|
+
sheet.insertRule(this._deletedRulePlaceholder, index)
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
var tag = this._tags[index]
|
|
244
|
+
invariant(tag, 'old rule at index `' + index + '` not found')
|
|
245
|
+
tag.textContent = rule
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return index
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
_proto.deleteRule = function deleteRule(index) {
|
|
252
|
+
if (!this._isBrowser) {
|
|
253
|
+
this._serverSheet.deleteRule(index)
|
|
254
|
+
|
|
255
|
+
return
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (this._optimizeForSpeed) {
|
|
259
|
+
this.replaceRule(index, '')
|
|
260
|
+
} else {
|
|
261
|
+
var tag = this._tags[index]
|
|
262
|
+
invariant(tag, 'rule at index `' + index + '` not found')
|
|
263
|
+
tag.parentNode.removeChild(tag)
|
|
264
|
+
this._tags[index] = null
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
_proto.flush = function flush() {
|
|
269
|
+
this._injected = false
|
|
270
|
+
this._rulesCount = 0
|
|
271
|
+
|
|
272
|
+
if (this._isBrowser) {
|
|
273
|
+
this._tags.forEach(function (tag) {
|
|
274
|
+
return tag && tag.parentNode.removeChild(tag)
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
this._tags = []
|
|
278
|
+
} else {
|
|
279
|
+
// simpler on server
|
|
280
|
+
this._serverSheet.cssRules = []
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
_proto.cssRules = function cssRules() {
|
|
285
|
+
var _this2 = this
|
|
286
|
+
|
|
287
|
+
if (!this._isBrowser) {
|
|
288
|
+
return this._serverSheet.cssRules
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return this._tags.reduce(function (rules, tag) {
|
|
292
|
+
if (tag) {
|
|
293
|
+
rules = rules.concat(
|
|
294
|
+
Array.prototype.map.call(
|
|
295
|
+
_this2.getSheetForTag(tag).cssRules,
|
|
296
|
+
function (rule) {
|
|
297
|
+
return rule.cssText === _this2._deletedRulePlaceholder ? null : rule
|
|
298
|
+
},
|
|
299
|
+
),
|
|
300
|
+
)
|
|
301
|
+
} else {
|
|
302
|
+
rules.push(null)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return rules
|
|
306
|
+
}, [])
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
_proto.makeStyleTag = function makeStyleTag(name, cssString, relativeToTag) {
|
|
310
|
+
if (cssString) {
|
|
311
|
+
invariant(
|
|
312
|
+
isString(cssString),
|
|
313
|
+
'makeStyleTag acceps only strings as second parameter',
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
var tag = document.createElement('style')
|
|
318
|
+
if (this._nonce) tag.setAttribute('nonce', this._nonce)
|
|
319
|
+
tag.type = 'text/css'
|
|
320
|
+
tag.setAttribute('data-' + name, '')
|
|
321
|
+
|
|
322
|
+
if (cssString) {
|
|
323
|
+
tag.appendChild(document.createTextNode(cssString))
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
var head = document.head || document.getElementsByTagName('head')[0]
|
|
327
|
+
|
|
328
|
+
if (relativeToTag) {
|
|
329
|
+
head.insertBefore(tag, relativeToTag)
|
|
330
|
+
} else {
|
|
331
|
+
head.appendChild(tag)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return tag
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
_createClass(StyleSheet, [
|
|
338
|
+
{
|
|
339
|
+
key: 'length',
|
|
340
|
+
get: function get() {
|
|
341
|
+
return this._rulesCount
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
])
|
|
345
|
+
|
|
346
|
+
return StyleSheet
|
|
347
|
+
})()
|
|
348
|
+
|
|
349
|
+
exports['default'] = StyleSheet
|
|
350
|
+
|
|
351
|
+
function invariant(condition, message) {
|
|
352
|
+
if (!condition) {
|
|
353
|
+
throw new Error('StyleSheet: ' + message + '.')
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
})(stylesheet)
|
|
357
|
+
|
|
358
|
+
;(function (exports) {
|
|
359
|
+
exports.__esModule = true
|
|
360
|
+
exports['default'] = void 0
|
|
361
|
+
|
|
362
|
+
var _stringHash = _interopRequireDefault(stringHash)
|
|
363
|
+
|
|
364
|
+
var _stylesheet = _interopRequireDefault(stylesheet)
|
|
365
|
+
|
|
366
|
+
function _interopRequireDefault(obj) {
|
|
367
|
+
return obj && obj.__esModule ? obj : { default: obj }
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
var sanitize = function sanitize(rule) {
|
|
371
|
+
return rule.replace(/\/style/gi, '\\/style')
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
var StyleSheetRegistry = /*#__PURE__*/ (function () {
|
|
375
|
+
function StyleSheetRegistry(_temp) {
|
|
376
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
377
|
+
_ref$styleSheet = _ref.styleSheet,
|
|
378
|
+
styleSheet = _ref$styleSheet === void 0 ? null : _ref$styleSheet,
|
|
379
|
+
_ref$optimizeForSpeed = _ref.optimizeForSpeed,
|
|
380
|
+
optimizeForSpeed =
|
|
381
|
+
_ref$optimizeForSpeed === void 0 ? false : _ref$optimizeForSpeed,
|
|
382
|
+
_ref$isBrowser = _ref.isBrowser,
|
|
383
|
+
isBrowser =
|
|
384
|
+
_ref$isBrowser === void 0 ? typeof window !== 'undefined' : _ref$isBrowser
|
|
385
|
+
|
|
386
|
+
this._sheet =
|
|
387
|
+
styleSheet ||
|
|
388
|
+
new _stylesheet['default']({
|
|
389
|
+
name: 'styled-jsx',
|
|
390
|
+
optimizeForSpeed: optimizeForSpeed,
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
this._sheet.inject()
|
|
394
|
+
|
|
395
|
+
if (styleSheet && typeof optimizeForSpeed === 'boolean') {
|
|
396
|
+
this._sheet.setOptimizeForSpeed(optimizeForSpeed)
|
|
397
|
+
|
|
398
|
+
this._optimizeForSpeed = this._sheet.isOptimizeForSpeed()
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
this._isBrowser = isBrowser
|
|
402
|
+
this._fromServer = undefined
|
|
403
|
+
this._indices = {}
|
|
404
|
+
this._instancesCounts = {}
|
|
405
|
+
this.computeId = this.createComputeId()
|
|
406
|
+
this.computeSelector = this.createComputeSelector()
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
var _proto = StyleSheetRegistry.prototype
|
|
410
|
+
|
|
411
|
+
_proto.add = function add(props) {
|
|
412
|
+
var _this = this
|
|
413
|
+
|
|
414
|
+
if (undefined === this._optimizeForSpeed) {
|
|
415
|
+
this._optimizeForSpeed = Array.isArray(props.children)
|
|
416
|
+
|
|
417
|
+
this._sheet.setOptimizeForSpeed(this._optimizeForSpeed)
|
|
418
|
+
|
|
419
|
+
this._optimizeForSpeed = this._sheet.isOptimizeForSpeed()
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (this._isBrowser && !this._fromServer) {
|
|
423
|
+
this._fromServer = this.selectFromServer()
|
|
424
|
+
this._instancesCounts = Object.keys(this._fromServer).reduce(function (
|
|
425
|
+
acc,
|
|
426
|
+
tagName,
|
|
427
|
+
) {
|
|
428
|
+
acc[tagName] = 0
|
|
429
|
+
return acc
|
|
430
|
+
},
|
|
431
|
+
{})
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
var _this$getIdAndRules = this.getIdAndRules(props),
|
|
435
|
+
styleId = _this$getIdAndRules.styleId,
|
|
436
|
+
rules = _this$getIdAndRules.rules // Deduping: just increase the instances count.
|
|
437
|
+
|
|
438
|
+
if (styleId in this._instancesCounts) {
|
|
439
|
+
this._instancesCounts[styleId] += 1
|
|
440
|
+
return
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
var indices = rules
|
|
444
|
+
.map(function (rule) {
|
|
445
|
+
return _this._sheet.insertRule(rule)
|
|
446
|
+
}) // Filter out invalid rules
|
|
447
|
+
.filter(function (index) {
|
|
448
|
+
return index !== -1
|
|
449
|
+
})
|
|
450
|
+
this._indices[styleId] = indices
|
|
451
|
+
this._instancesCounts[styleId] = 1
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
_proto.remove = function remove(props) {
|
|
455
|
+
var _this2 = this
|
|
456
|
+
|
|
457
|
+
var _this$getIdAndRules2 = this.getIdAndRules(props),
|
|
458
|
+
styleId = _this$getIdAndRules2.styleId
|
|
459
|
+
|
|
460
|
+
invariant(styleId in this._instancesCounts, 'styleId: `' + styleId + '` not found')
|
|
461
|
+
this._instancesCounts[styleId] -= 1
|
|
462
|
+
|
|
463
|
+
if (this._instancesCounts[styleId] < 1) {
|
|
464
|
+
var tagFromServer = this._fromServer && this._fromServer[styleId]
|
|
465
|
+
|
|
466
|
+
if (tagFromServer) {
|
|
467
|
+
tagFromServer.parentNode.removeChild(tagFromServer)
|
|
468
|
+
delete this._fromServer[styleId]
|
|
469
|
+
} else {
|
|
470
|
+
this._indices[styleId].forEach(function (index) {
|
|
471
|
+
return _this2._sheet.deleteRule(index)
|
|
472
|
+
})
|
|
473
|
+
|
|
474
|
+
delete this._indices[styleId]
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
delete this._instancesCounts[styleId]
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
_proto.update = function update(props, nextProps) {
|
|
482
|
+
this.add(nextProps)
|
|
483
|
+
this.remove(props)
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
_proto.flush = function flush() {
|
|
487
|
+
this._sheet.flush()
|
|
488
|
+
|
|
489
|
+
this._sheet.inject()
|
|
490
|
+
|
|
491
|
+
this._fromServer = undefined
|
|
492
|
+
this._indices = {}
|
|
493
|
+
this._instancesCounts = {}
|
|
494
|
+
this.computeId = this.createComputeId()
|
|
495
|
+
this.computeSelector = this.createComputeSelector()
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
_proto.cssRules = function cssRules() {
|
|
499
|
+
var _this3 = this
|
|
500
|
+
|
|
501
|
+
var fromServer = this._fromServer
|
|
502
|
+
? Object.keys(this._fromServer).map(function (styleId) {
|
|
503
|
+
return [styleId, _this3._fromServer[styleId]]
|
|
504
|
+
})
|
|
505
|
+
: []
|
|
506
|
+
|
|
507
|
+
var cssRules = this._sheet.cssRules()
|
|
508
|
+
|
|
509
|
+
return fromServer.concat(
|
|
510
|
+
Object.keys(this._indices)
|
|
511
|
+
.map(function (styleId) {
|
|
512
|
+
return [
|
|
513
|
+
styleId,
|
|
514
|
+
_this3._indices[styleId]
|
|
515
|
+
.map(function (index) {
|
|
516
|
+
return cssRules[index].cssText
|
|
517
|
+
})
|
|
518
|
+
.join(_this3._optimizeForSpeed ? '' : '\n'),
|
|
519
|
+
]
|
|
520
|
+
}) // filter out empty rules
|
|
521
|
+
.filter(function (rule) {
|
|
522
|
+
return Boolean(rule[1])
|
|
523
|
+
}),
|
|
524
|
+
)
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* createComputeId
|
|
528
|
+
*
|
|
529
|
+
* Creates a function to compute and memoize a jsx id from a basedId and optionally props.
|
|
530
|
+
*/
|
|
531
|
+
|
|
532
|
+
_proto.createComputeId = function createComputeId() {
|
|
533
|
+
var cache = {}
|
|
534
|
+
return function (baseId, props) {
|
|
535
|
+
if (!props) {
|
|
536
|
+
return 'jsx-' + baseId
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
var propsToString = String(props)
|
|
540
|
+
var key = baseId + propsToString // return `jsx-${hashString(`${baseId}-${propsToString}`)}`
|
|
541
|
+
|
|
542
|
+
if (!cache[key]) {
|
|
543
|
+
cache[key] = 'jsx-' + (0, _stringHash['default'])(baseId + '-' + propsToString)
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
return cache[key]
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* createComputeSelector
|
|
551
|
+
*
|
|
552
|
+
* Creates a function to compute and memoize dynamic selectors.
|
|
553
|
+
*/
|
|
554
|
+
|
|
555
|
+
_proto.createComputeSelector = function createComputeSelector(
|
|
556
|
+
selectoPlaceholderRegexp,
|
|
557
|
+
) {
|
|
558
|
+
if (selectoPlaceholderRegexp === void 0) {
|
|
559
|
+
selectoPlaceholderRegexp = /__jsx-style-dynamic-selector/g
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
var cache = {}
|
|
563
|
+
return function (id, css) {
|
|
564
|
+
// Sanitize SSR-ed CSS.
|
|
565
|
+
// Client side code doesn't need to be sanitized since we use
|
|
566
|
+
// document.createTextNode (dev) and the CSSOM api sheet.insertRule (prod).
|
|
567
|
+
if (!this._isBrowser) {
|
|
568
|
+
css = sanitize(css)
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
var idcss = id + css
|
|
572
|
+
|
|
573
|
+
if (!cache[idcss]) {
|
|
574
|
+
cache[idcss] = css.replace(selectoPlaceholderRegexp, id)
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
return cache[idcss]
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
_proto.getIdAndRules = function getIdAndRules(props) {
|
|
582
|
+
var _this4 = this
|
|
583
|
+
|
|
584
|
+
var css = props.children,
|
|
585
|
+
dynamic = props.dynamic,
|
|
586
|
+
id = props.id
|
|
587
|
+
|
|
588
|
+
if (dynamic) {
|
|
589
|
+
var styleId = this.computeId(id, dynamic)
|
|
590
|
+
return {
|
|
591
|
+
styleId: styleId,
|
|
592
|
+
rules: Array.isArray(css)
|
|
593
|
+
? css.map(function (rule) {
|
|
594
|
+
return _this4.computeSelector(styleId, rule)
|
|
595
|
+
})
|
|
596
|
+
: [this.computeSelector(styleId, css)],
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
return {
|
|
601
|
+
styleId: this.computeId(id),
|
|
602
|
+
rules: Array.isArray(css) ? css : [css],
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* selectFromServer
|
|
607
|
+
*
|
|
608
|
+
* Collects style tags from the document with id __jsx-XXX
|
|
609
|
+
*/
|
|
610
|
+
|
|
611
|
+
_proto.selectFromServer = function selectFromServer() {
|
|
612
|
+
var elements = Array.prototype.slice.call(
|
|
613
|
+
document.querySelectorAll('[id^="__jsx-"]'),
|
|
614
|
+
)
|
|
615
|
+
return elements.reduce(function (acc, element) {
|
|
616
|
+
var id = element.id.slice(2)
|
|
617
|
+
acc[id] = element
|
|
618
|
+
return acc
|
|
619
|
+
}, {})
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
return StyleSheetRegistry
|
|
623
|
+
})()
|
|
624
|
+
|
|
625
|
+
exports['default'] = StyleSheetRegistry
|
|
626
|
+
|
|
627
|
+
function invariant(condition, message) {
|
|
628
|
+
if (!condition) {
|
|
629
|
+
throw new Error('StyleSheetRegistry: ' + message + '.')
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
})(stylesheetRegistry)
|
|
633
|
+
|
|
634
|
+
;(function (exports) {
|
|
635
|
+
exports.__esModule = true
|
|
636
|
+
exports['default'] = JSXStyle
|
|
637
|
+
exports.flush = flush
|
|
638
|
+
|
|
639
|
+
var _react = React__default['default']
|
|
640
|
+
|
|
641
|
+
var _stylesheetRegistry = _interopRequireDefault(stylesheetRegistry)
|
|
642
|
+
|
|
643
|
+
function _interopRequireDefault(obj) {
|
|
644
|
+
return obj && obj.__esModule ? obj : { default: obj }
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
var styleSheetRegistry = new _stylesheetRegistry['default']()
|
|
648
|
+
|
|
649
|
+
function JSXStyle(props) {
|
|
650
|
+
if (typeof window === 'undefined') {
|
|
651
|
+
styleSheetRegistry.add(props)
|
|
652
|
+
return null
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
;(0, _react.useLayoutEffect)(
|
|
656
|
+
function () {
|
|
657
|
+
styleSheetRegistry.add(props)
|
|
658
|
+
return function () {
|
|
659
|
+
styleSheetRegistry.remove(props)
|
|
660
|
+
} // props.children can be string[], will be striped since id is identical
|
|
661
|
+
},
|
|
662
|
+
[props.id, String(props.dynamic)],
|
|
663
|
+
)
|
|
664
|
+
return null
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
JSXStyle.dynamic = function (info) {
|
|
668
|
+
return info
|
|
669
|
+
.map(function (tagInfo) {
|
|
670
|
+
var baseId = tagInfo[0]
|
|
671
|
+
var props = tagInfo[1]
|
|
672
|
+
return styleSheetRegistry.computeId(baseId, props)
|
|
673
|
+
})
|
|
674
|
+
.join(' ')
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function flush() {
|
|
678
|
+
var cssRules = styleSheetRegistry.cssRules()
|
|
679
|
+
styleSheetRegistry.flush()
|
|
680
|
+
return cssRules
|
|
681
|
+
}
|
|
682
|
+
})(style$1)
|
|
683
|
+
|
|
684
|
+
var style = style$1.default || style$1
|
|
685
|
+
style.flush = style$1.flush
|
|
686
|
+
|
|
687
|
+
var server$1 = {}
|
|
688
|
+
|
|
689
|
+
;(function (exports) {
|
|
690
|
+
exports.__esModule = true
|
|
691
|
+
exports['default'] = flushToReact
|
|
692
|
+
exports.flushToHTML = flushToHTML
|
|
693
|
+
|
|
694
|
+
var _react = _interopRequireDefault(React__default['default'])
|
|
695
|
+
|
|
696
|
+
var _style = style$1.default || style$1
|
|
697
|
+
_style.flush = style$1.flush
|
|
698
|
+
|
|
699
|
+
function _interopRequireDefault(obj) {
|
|
700
|
+
return obj && obj.__esModule ? obj : { default: obj }
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function flushToReact(options) {
|
|
704
|
+
if (options === void 0) {
|
|
705
|
+
options = {}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
return (0, _style.flush)().map(function (args) {
|
|
709
|
+
var id = args[0]
|
|
710
|
+
var css = args[1]
|
|
711
|
+
return _react['default'].createElement('style', {
|
|
712
|
+
id: '__' + id,
|
|
713
|
+
// Avoid warnings upon render with a key
|
|
714
|
+
key: '__' + id,
|
|
715
|
+
nonce: options.nonce ? options.nonce : undefined,
|
|
716
|
+
dangerouslySetInnerHTML: {
|
|
717
|
+
__html: css,
|
|
718
|
+
},
|
|
719
|
+
})
|
|
720
|
+
})
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function flushToHTML(options) {
|
|
724
|
+
if (options === void 0) {
|
|
725
|
+
options = {}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
return (0, _style.flush)().reduce(function (html, args) {
|
|
729
|
+
var id = args[0]
|
|
730
|
+
var css = args[1]
|
|
731
|
+
html +=
|
|
732
|
+
'<style id="__' +
|
|
733
|
+
id +
|
|
734
|
+
'"' +
|
|
735
|
+
(options.nonce ? ' nonce="' + options.nonce + '"' : '') +
|
|
736
|
+
'>' +
|
|
737
|
+
css +
|
|
738
|
+
'</style>'
|
|
739
|
+
return html
|
|
740
|
+
}, '')
|
|
741
|
+
}
|
|
742
|
+
})(server$1)
|
|
743
|
+
|
|
744
|
+
var server = server$1.default || server$1
|
|
745
|
+
server.flushToHTML = server$1.flushToHTML
|
|
746
|
+
|
|
747
|
+
exports.server = server
|
|
748
|
+
exports.style = style
|