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