@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,1425 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var reactDom = require('react-dom');
7
+
8
+ function _arrayLikeToArray(r, a) {
9
+ (null == a || a > r.length) && (a = r.length);
10
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
11
+ return n;
12
+ }
13
+ function _arrayWithHoles(r) {
14
+ if (Array.isArray(r)) return r;
15
+ }
16
+ function _defineProperty(e, r, t) {
17
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
18
+ value: t,
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true
22
+ }) : e[r] = t, e;
23
+ }
24
+ function _iterableToArrayLimit(r, l) {
25
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
26
+ if (null != t) {
27
+ var e,
28
+ n,
29
+ i,
30
+ u,
31
+ a = [],
32
+ f = true,
33
+ o = false;
34
+ try {
35
+ if (i = (t = t.call(r)).next, 0 === l) {
36
+ if (Object(t) !== t) return;
37
+ f = !1;
38
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
39
+ } catch (r) {
40
+ o = true, n = r;
41
+ } finally {
42
+ try {
43
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
44
+ } finally {
45
+ if (o) throw n;
46
+ }
47
+ }
48
+ return a;
49
+ }
50
+ }
51
+ function _nonIterableRest() {
52
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
53
+ }
54
+ function ownKeys(e, r) {
55
+ var t = Object.keys(e);
56
+ if (Object.getOwnPropertySymbols) {
57
+ var o = Object.getOwnPropertySymbols(e);
58
+ r && (o = o.filter(function (r) {
59
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
60
+ })), t.push.apply(t, o);
61
+ }
62
+ return t;
63
+ }
64
+ function _objectSpread2(e) {
65
+ for (var r = 1; r < arguments.length; r++) {
66
+ var t = null != arguments[r] ? arguments[r] : {};
67
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
68
+ _defineProperty(e, r, t[r]);
69
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
70
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
71
+ });
72
+ }
73
+ return e;
74
+ }
75
+ function _objectWithoutProperties(e, t) {
76
+ if (null == e) return {};
77
+ var o,
78
+ r,
79
+ i = _objectWithoutPropertiesLoose(e, t);
80
+ if (Object.getOwnPropertySymbols) {
81
+ var n = Object.getOwnPropertySymbols(e);
82
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
83
+ }
84
+ return i;
85
+ }
86
+ function _objectWithoutPropertiesLoose(r, e) {
87
+ if (null == r) return {};
88
+ var t = {};
89
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
90
+ if (-1 !== e.indexOf(n)) continue;
91
+ t[n] = r[n];
92
+ }
93
+ return t;
94
+ }
95
+ function _slicedToArray(r, e) {
96
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
97
+ }
98
+ function _toPrimitive(t, r) {
99
+ if ("object" != typeof t || !t) return t;
100
+ var e = t[Symbol.toPrimitive];
101
+ if (void 0 !== e) {
102
+ var i = e.call(t, r);
103
+ if ("object" != typeof i) return i;
104
+ throw new TypeError("@@toPrimitive must return a primitive value.");
105
+ }
106
+ return ("string" === r ? String : Number)(t);
107
+ }
108
+ function _toPropertyKey(t) {
109
+ var i = _toPrimitive(t, "string");
110
+ return "symbol" == typeof i ? i : i + "";
111
+ }
112
+ function _typeof(o) {
113
+ "@babel/helpers - typeof";
114
+
115
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
116
+ return typeof o;
117
+ } : function (o) {
118
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
119
+ }, _typeof(o);
120
+ }
121
+ function _unsupportedIterableToArray(r, a) {
122
+ if (r) {
123
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
124
+ var t = {}.toString.call(r).slice(8, -1);
125
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
126
+ }
127
+ }
128
+
129
+ var defaultToastLayout = {
130
+ padding: '12px 16px',
131
+ margin: '8px 0',
132
+ width: '420px',
133
+ maxWidth: '90vw',
134
+ maxHeight: '75px',
135
+ placement: 'bottomRight'
136
+ };
137
+ var defaultParams = {
138
+ toasts: [],
139
+ toastLayout: defaultToastLayout,
140
+ updateToastLayout: function updateToastLayout(t) {
141
+ return t;
142
+ },
143
+ updateToasts: function updateToasts(t) {
144
+ return t;
145
+ },
146
+ lastUpdateToastId: null,
147
+ updateLastToastId: function updateLastToastId() {
148
+ return null;
149
+ }
150
+ };
151
+ var HUIContent = /*#__PURE__*/React.createContext(defaultParams);
152
+ var useHUIContext = function useHUIContext() {
153
+ return React.useContext(HUIContent);
154
+ };
155
+
156
+ var defaultFont = {
157
+ sans: '"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',
158
+ mono: 'Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace',
159
+ prism: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,"Liberation Mono", "Courier New", monospace'
160
+ };
161
+ var defaultBreakpoints = {
162
+ xs: {
163
+ min: '0',
164
+ max: '650px'
165
+ },
166
+ sm: {
167
+ min: '650px',
168
+ max: '900px'
169
+ },
170
+ md: {
171
+ min: '900px',
172
+ max: '1280px'
173
+ },
174
+ lg: {
175
+ min: '1280px',
176
+ max: '1920px'
177
+ },
178
+ xl: {
179
+ min: '1920px',
180
+ max: '10000px'
181
+ }
182
+ };
183
+ var defaultLayout = {
184
+ gap: '16pt',
185
+ gapNegative: '-16pt',
186
+ gapHalf: '8pt',
187
+ gapHalfNegative: '-8pt',
188
+ gapQuarter: '4pt',
189
+ gapQuarterNegative: '-4pt',
190
+ pageMargin: '16pt',
191
+ pageWidth: '750pt',
192
+ pageWidthWithMargin: '782pt',
193
+ breakpointMobile: defaultBreakpoints.xs.max,
194
+ breakpointTablet: defaultBreakpoints.sm.max,
195
+ radius: '6px',
196
+ unit: '16px'
197
+ };
198
+
199
+ var palette$1 = {
200
+ accents_1: '#fafafa',
201
+ accents_2: '#eaeaea',
202
+ accents_3: '#999',
203
+ accents_4: '#888',
204
+ accents_5: '#666',
205
+ accents_6: '#444',
206
+ accents_7: '#333',
207
+ accents_8: '#111',
208
+ background: '#fff',
209
+ foreground: '#000',
210
+ selection: '#79ffe1',
211
+ secondary: '#666',
212
+ code: '#f81ce5',
213
+ border: '#eaeaea',
214
+ error: '#e00',
215
+ errorLight: '#ff1a1a',
216
+ errorLighter: '#f7d4d6',
217
+ errorDark: '#c50000',
218
+ success: '#0070f3',
219
+ successLight: '#3291ff',
220
+ successLighter: '#d3e5ff',
221
+ successDark: '#0761d1',
222
+ warning: '#f5a623',
223
+ warningLight: '#f7b955',
224
+ warningLighter: '#ffefcf',
225
+ warningDark: '#ab570a',
226
+ cyan: '#50e3c2',
227
+ cyanLighter: '#aaffec',
228
+ cyanLight: '#79ffe1',
229
+ cyanDark: '#29bc9b',
230
+ violet: '#7928ca',
231
+ violetLighter: '#e3d7fc',
232
+ violetLight: '#8a63d2',
233
+ violetDark: '#4c2889',
234
+ purple: '#f81ce5',
235
+ alert: '#ff0080',
236
+ magenta: '#eb367f',
237
+ link: '#0070f3'
238
+ };
239
+ var expressiveness$1 = {
240
+ linkStyle: 'none',
241
+ linkHoverStyle: 'none',
242
+ dropdownBoxShadow: '0 4px 4px 0 rgba(0, 0, 0, 0.02)',
243
+ scrollerStart: 'rgba(255, 255, 255, 1)',
244
+ scrollerEnd: 'rgba(255, 255, 255, 0)',
245
+ shadowSmall: '0 5px 10px rgba(0, 0, 0, 0.12)',
246
+ shadowMedium: '0 8px 30px rgba(0, 0, 0, 0.12)',
247
+ shadowLarge: '0 30px 60px rgba(0, 0, 0, 0.12)',
248
+ portalOpacity: 0.25
249
+ };
250
+ var font$1 = defaultFont;
251
+ var breakpoints$1 = defaultBreakpoints;
252
+ var layout$1 = defaultLayout;
253
+ var themes$1 = {
254
+ type: 'light',
255
+ font: font$1,
256
+ layout: layout$1,
257
+ palette: palette$1,
258
+ breakpoints: breakpoints$1,
259
+ expressiveness: expressiveness$1
260
+ };
261
+
262
+ var palette = {
263
+ accents_1: '#111',
264
+ accents_2: '#333',
265
+ accents_3: '#444',
266
+ accents_4: '#666',
267
+ accents_5: '#888',
268
+ accents_6: '#999',
269
+ accents_7: '#eaeaea',
270
+ accents_8: '#fafafa',
271
+ background: '#000',
272
+ foreground: '#fff',
273
+ selection: '#f81ce5',
274
+ secondary: '#888',
275
+ code: '#79ffe1',
276
+ border: '#333',
277
+ error: '#e00',
278
+ errorLighter: '#f7d4d6',
279
+ errorLight: '#ff1a1a',
280
+ errorDark: '#c50000',
281
+ success: '#0070f3',
282
+ successLighter: '#d3e5ff',
283
+ successLight: '#3291ff',
284
+ successDark: '#0761d1',
285
+ warning: '#f5a623',
286
+ warningLighter: '#ffefcf',
287
+ warningLight: '#f7b955',
288
+ warningDark: '#ab570a',
289
+ cyan: '#50e3c2',
290
+ cyanLighter: '#aaffec',
291
+ cyanLight: '#79ffe1',
292
+ cyanDark: '#29bc9b',
293
+ violet: '#7928ca',
294
+ violetLighter: '#e3d7fc',
295
+ violetLight: '#8a63d2',
296
+ violetDark: '#4c2889',
297
+ purple: '#f81ce5',
298
+ alert: '#ff0080',
299
+ magenta: '#eb367f',
300
+ link: '#3291ff'
301
+ };
302
+ var expressiveness = {
303
+ linkStyle: 'none',
304
+ linkHoverStyle: 'none',
305
+ dropdownBoxShadow: '0 0 0 1px #333',
306
+ scrollerStart: 'rgba(255, 255, 255, 1)',
307
+ scrollerEnd: 'rgba(255, 255, 255, 0)',
308
+ shadowSmall: '0 0 0 1px #333',
309
+ shadowMedium: '0 0 0 1px #333',
310
+ shadowLarge: '0 0 0 1px #333',
311
+ portalOpacity: 0.75
312
+ };
313
+ var font = defaultFont;
314
+ var breakpoints = defaultBreakpoints;
315
+ var layout = defaultLayout;
316
+ var themes = {
317
+ type: 'dark',
318
+ font: font,
319
+ layout: layout,
320
+ palette: palette,
321
+ breakpoints: breakpoints,
322
+ expressiveness: expressiveness
323
+ };
324
+
325
+ var isObject = function isObject(target) {
326
+ return target && _typeof(target) === 'object';
327
+ };
328
+ var _deepDuplicable = function deepDuplicable(source, target) {
329
+ if (!isObject(target) || !isObject(source)) return source;
330
+ var sourceKeys = Object.keys(source);
331
+ var result = {};
332
+ for (var _i = 0, _sourceKeys = sourceKeys; _i < _sourceKeys.length; _i++) {
333
+ var key = _sourceKeys[_i];
334
+ var sourceValue = source[key];
335
+ var targetValue = target[key];
336
+ if (Array.isArray(sourceValue) && Array.isArray(targetValue)) {
337
+ result[key] = targetValue.concat(sourceValue);
338
+ } else if (isObject(sourceValue) && isObject(targetValue)) {
339
+ result[key] = _deepDuplicable(sourceValue, _objectSpread2({}, targetValue));
340
+ } else if (targetValue) {
341
+ result[key] = targetValue;
342
+ } else {
343
+ result[key] = sourceValue;
344
+ }
345
+ }
346
+ return result;
347
+ };
348
+ var getPresets = function getPresets() {
349
+ return [themes$1, themes];
350
+ };
351
+ var getPresetStaticTheme = function getPresetStaticTheme() {
352
+ return themes$1;
353
+ };
354
+ var isAvailableThemeType = function isAvailableThemeType(type) {
355
+ if (!type) return false;
356
+ var presetThemes = getPresets();
357
+ var hasType = presetThemes.find(function (theme) {
358
+ return theme.type === type;
359
+ });
360
+ return !hasType;
361
+ };
362
+ var isPresetTheme = function isPresetTheme(themeOrType) {
363
+ if (!themeOrType) return false;
364
+ var isType = typeof themeOrType === 'string';
365
+ var type = isType ? themeOrType : themeOrType.type;
366
+ return !isAvailableThemeType(type);
367
+ };
368
+ var hasUserCustomTheme = function hasUserCustomTheme() {
369
+ var themes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
370
+ return !!themes.find(function (item) {
371
+ return isAvailableThemeType(item.type);
372
+ });
373
+ };
374
+ var create = function create(base, custom) {
375
+ if (!isAvailableThemeType(custom.type)) {
376
+ throw new Error('Duplicate or unavailable theme type');
377
+ }
378
+ return _deepDuplicable(base, custom);
379
+ };
380
+ var createFromDark = function createFromDark(custom) {
381
+ return create(themes, custom);
382
+ };
383
+ var createFromLight = function createFromLight(custom) {
384
+ return create(themes$1, custom);
385
+ };
386
+ var Themes = {
387
+ isPresetTheme: isPresetTheme,
388
+ isAvailableThemeType: isAvailableThemeType,
389
+ hasUserCustomTheme: hasUserCustomTheme,
390
+ getPresets: getPresets,
391
+ getPresetStaticTheme: getPresetStaticTheme,
392
+ create: create,
393
+ createFromDark: createFromDark,
394
+ createFromLight: createFromLight
395
+ };
396
+
397
+ /* "use client" */
398
+
399
+ var defaultTheme = Themes.getPresetStaticTheme();
400
+ var ThemeContext = /*#__PURE__*/React.createContext(defaultTheme);
401
+ var useTheme = function useTheme() {
402
+ return React.useContext(ThemeContext);
403
+ };
404
+
405
+ /* "use client" */
406
+
407
+ var defaultAllThemesConfig = {
408
+ themes: Themes.getPresets()
409
+ };
410
+ var AllThemesContext = /*#__PURE__*/React.createContext(defaultAllThemesConfig);
411
+
412
+ var ThemeProvider = function ThemeProvider(_ref) {
413
+ var children = _ref.children,
414
+ themeType = _ref.themeType,
415
+ _ref$themes = _ref.themes,
416
+ themes = _ref$themes === void 0 ? [] : _ref$themes;
417
+ var _React$useState = React.useState({
418
+ themes: Themes.getPresets()
419
+ }),
420
+ _React$useState2 = _slicedToArray(_React$useState, 2),
421
+ allThemes = _React$useState2[0],
422
+ setAllThemes = _React$useState2[1];
423
+ var currentTheme = React.useMemo(function () {
424
+ var theme = allThemes.themes.find(function (item) {
425
+ return item.type === themeType;
426
+ });
427
+ if (theme) return theme;
428
+ return Themes.getPresetStaticTheme();
429
+ }, [allThemes, themeType]);
430
+ React.useEffect(function () {
431
+ if (!(themes !== null && themes !== void 0 && themes.length)) return;
432
+ setAllThemes(function (last) {
433
+ var safeThemes = themes.filter(function (item) {
434
+ return Themes.isAvailableThemeType(item.type);
435
+ });
436
+ var nextThemes = Themes.getPresets().concat(safeThemes);
437
+ return _objectSpread2(_objectSpread2({}, last), {}, {
438
+ themes: nextThemes
439
+ });
440
+ });
441
+ }, [themes]);
442
+ return /*#__PURE__*/React.createElement(AllThemesContext.Provider, {
443
+ value: allThemes
444
+ }, /*#__PURE__*/React.createElement(ThemeContext.Provider, {
445
+ value: currentTheme
446
+ }, children));
447
+ };
448
+
449
+ var useCurrentState = function useCurrentState(initialState) {
450
+ var _useState = React.useState(function () {
451
+ return typeof initialState === 'function' ? initialState() : initialState;
452
+ }),
453
+ _useState2 = _slicedToArray(_useState, 2),
454
+ state = _useState2[0],
455
+ setState = _useState2[1];
456
+ var ref = React.useRef(initialState);
457
+ React.useEffect(function () {
458
+ ref.current = state;
459
+ }, [state]);
460
+ var setValue = function setValue(val) {
461
+ var result = typeof val === 'function' ? val(ref.current) : val;
462
+ ref.current = result;
463
+ setState(result);
464
+ };
465
+ return [state, setValue, ref];
466
+ };
467
+
468
+ function getDefaultExportFromCjs (x) {
469
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
470
+ }
471
+
472
+ var index = {};
473
+
474
+ var hasRequiredIndex;
475
+
476
+ function requireIndex () {
477
+ if (hasRequiredIndex) return index;
478
+ hasRequiredIndex = 1;
479
+ var React$1 = React;
480
+
481
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
482
+
483
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React$1);
484
+
485
+ /*
486
+ Based on Glamor's sheet
487
+ https://github.com/threepointone/glamor/blob/667b480d31b3721a905021b26e1290ce92ca2879/src/sheet.js
488
+ */ function _defineProperties(target, props) {
489
+ for(var i = 0; i < props.length; i++){
490
+ var descriptor = props[i];
491
+ descriptor.enumerable = descriptor.enumerable || false;
492
+ descriptor.configurable = true;
493
+ if ("value" in descriptor) descriptor.writable = true;
494
+ Object.defineProperty(target, descriptor.key, descriptor);
495
+ }
496
+ }
497
+ function _createClass(Constructor, protoProps, staticProps) {
498
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
499
+ return Constructor;
500
+ }
501
+ var isProd = typeof process !== "undefined" && process.env && process.env.NODE_ENV === "production";
502
+ var isString = function(o) {
503
+ return Object.prototype.toString.call(o) === "[object String]";
504
+ };
505
+ var StyleSheet = /*#__PURE__*/ function() {
506
+ function StyleSheet(param) {
507
+ var ref = param === void 0 ? {} : param, _name = ref.name, name = _name === void 0 ? "stylesheet" : _name, _optimizeForSpeed = ref.optimizeForSpeed, optimizeForSpeed = _optimizeForSpeed === void 0 ? isProd : _optimizeForSpeed;
508
+ invariant$1(isString(name), "`name` must be a string");
509
+ this._name = name;
510
+ this._deletedRulePlaceholder = "#" + name + "-deleted-rule____{}";
511
+ invariant$1(typeof optimizeForSpeed === "boolean", "`optimizeForSpeed` must be a boolean");
512
+ this._optimizeForSpeed = optimizeForSpeed;
513
+ this._serverSheet = undefined;
514
+ this._tags = [];
515
+ this._injected = false;
516
+ this._rulesCount = 0;
517
+ var node = typeof window !== "undefined" && document.querySelector('meta[property="csp-nonce"]');
518
+ this._nonce = node ? node.getAttribute("content") : null;
519
+ }
520
+ var _proto = StyleSheet.prototype;
521
+ _proto.setOptimizeForSpeed = function setOptimizeForSpeed(bool) {
522
+ invariant$1(typeof bool === "boolean", "`setOptimizeForSpeed` accepts a boolean");
523
+ invariant$1(this._rulesCount === 0, "optimizeForSpeed cannot be when rules have already been inserted");
524
+ this.flush();
525
+ this._optimizeForSpeed = bool;
526
+ this.inject();
527
+ };
528
+ _proto.isOptimizeForSpeed = function isOptimizeForSpeed() {
529
+ return this._optimizeForSpeed;
530
+ };
531
+ _proto.inject = function inject() {
532
+ var _this = this;
533
+ invariant$1(!this._injected, "sheet already injected");
534
+ this._injected = true;
535
+ if (typeof window !== "undefined" && this._optimizeForSpeed) {
536
+ this._tags[0] = this.makeStyleTag(this._name);
537
+ this._optimizeForSpeed = "insertRule" in this.getSheet();
538
+ if (!this._optimizeForSpeed) {
539
+ if (!isProd) {
540
+ console.warn("StyleSheet: optimizeForSpeed mode not supported falling back to standard mode.");
541
+ }
542
+ this.flush();
543
+ this._injected = true;
544
+ }
545
+ return;
546
+ }
547
+ this._serverSheet = {
548
+ cssRules: [],
549
+ insertRule: function(rule, index) {
550
+ if (typeof index === "number") {
551
+ _this._serverSheet.cssRules[index] = {
552
+ cssText: rule
553
+ };
554
+ } else {
555
+ _this._serverSheet.cssRules.push({
556
+ cssText: rule
557
+ });
558
+ }
559
+ return index;
560
+ },
561
+ deleteRule: function(index) {
562
+ _this._serverSheet.cssRules[index] = null;
563
+ }
564
+ };
565
+ };
566
+ _proto.getSheetForTag = function getSheetForTag(tag) {
567
+ if (tag.sheet) {
568
+ return tag.sheet;
569
+ }
570
+ // this weirdness brought to you by firefox
571
+ for(var i = 0; i < document.styleSheets.length; i++){
572
+ if (document.styleSheets[i].ownerNode === tag) {
573
+ return document.styleSheets[i];
574
+ }
575
+ }
576
+ };
577
+ _proto.getSheet = function getSheet() {
578
+ return this.getSheetForTag(this._tags[this._tags.length - 1]);
579
+ };
580
+ _proto.insertRule = function insertRule(rule, index) {
581
+ invariant$1(isString(rule), "`insertRule` accepts only strings");
582
+ if (typeof window === "undefined") {
583
+ if (typeof index !== "number") {
584
+ index = this._serverSheet.cssRules.length;
585
+ }
586
+ this._serverSheet.insertRule(rule, index);
587
+ return this._rulesCount++;
588
+ }
589
+ if (this._optimizeForSpeed) {
590
+ var sheet = this.getSheet();
591
+ if (typeof index !== "number") {
592
+ index = sheet.cssRules.length;
593
+ }
594
+ // this weirdness for perf, and chrome's weird bug
595
+ // https://stackoverflow.com/questions/20007992/chrome-suddenly-stopped-accepting-insertrule
596
+ try {
597
+ sheet.insertRule(rule, index);
598
+ } catch (error) {
599
+ if (!isProd) {
600
+ console.warn("StyleSheet: illegal rule: \n\n" + rule + "\n\nSee https://stackoverflow.com/q/20007992 for more info");
601
+ }
602
+ return -1;
603
+ }
604
+ } else {
605
+ var insertionPoint = this._tags[index];
606
+ this._tags.push(this.makeStyleTag(this._name, rule, insertionPoint));
607
+ }
608
+ return this._rulesCount++;
609
+ };
610
+ _proto.replaceRule = function replaceRule(index, rule) {
611
+ if (this._optimizeForSpeed || typeof window === "undefined") {
612
+ var sheet = typeof window !== "undefined" ? this.getSheet() : this._serverSheet;
613
+ if (!rule.trim()) {
614
+ rule = this._deletedRulePlaceholder;
615
+ }
616
+ if (!sheet.cssRules[index]) {
617
+ // @TBD Should we throw an error?
618
+ return index;
619
+ }
620
+ sheet.deleteRule(index);
621
+ try {
622
+ sheet.insertRule(rule, index);
623
+ } catch (error) {
624
+ if (!isProd) {
625
+ console.warn("StyleSheet: illegal rule: \n\n" + rule + "\n\nSee https://stackoverflow.com/q/20007992 for more info");
626
+ }
627
+ // In order to preserve the indices we insert a deleteRulePlaceholder
628
+ sheet.insertRule(this._deletedRulePlaceholder, index);
629
+ }
630
+ } else {
631
+ var tag = this._tags[index];
632
+ invariant$1(tag, "old rule at index `" + index + "` not found");
633
+ tag.textContent = rule;
634
+ }
635
+ return index;
636
+ };
637
+ _proto.deleteRule = function deleteRule(index) {
638
+ if (typeof window === "undefined") {
639
+ this._serverSheet.deleteRule(index);
640
+ return;
641
+ }
642
+ if (this._optimizeForSpeed) {
643
+ this.replaceRule(index, "");
644
+ } else {
645
+ var tag = this._tags[index];
646
+ invariant$1(tag, "rule at index `" + index + "` not found");
647
+ tag.parentNode.removeChild(tag);
648
+ this._tags[index] = null;
649
+ }
650
+ };
651
+ _proto.flush = function flush() {
652
+ this._injected = false;
653
+ this._rulesCount = 0;
654
+ if (typeof window !== "undefined") {
655
+ this._tags.forEach(function(tag) {
656
+ return tag && tag.parentNode.removeChild(tag);
657
+ });
658
+ this._tags = [];
659
+ } else {
660
+ // simpler on server
661
+ this._serverSheet.cssRules = [];
662
+ }
663
+ };
664
+ _proto.cssRules = function cssRules() {
665
+ var _this = this;
666
+ if (typeof window === "undefined") {
667
+ return this._serverSheet.cssRules;
668
+ }
669
+ return this._tags.reduce(function(rules, tag) {
670
+ if (tag) {
671
+ rules = rules.concat(Array.prototype.map.call(_this.getSheetForTag(tag).cssRules, function(rule) {
672
+ return rule.cssText === _this._deletedRulePlaceholder ? null : rule;
673
+ }));
674
+ } else {
675
+ rules.push(null);
676
+ }
677
+ return rules;
678
+ }, []);
679
+ };
680
+ _proto.makeStyleTag = function makeStyleTag(name, cssString, relativeToTag) {
681
+ if (cssString) {
682
+ invariant$1(isString(cssString), "makeStyleTag accepts only strings as second parameter");
683
+ }
684
+ var tag = document.createElement("style");
685
+ if (this._nonce) tag.setAttribute("nonce", this._nonce);
686
+ tag.type = "text/css";
687
+ tag.setAttribute("data-" + name, "");
688
+ if (cssString) {
689
+ tag.appendChild(document.createTextNode(cssString));
690
+ }
691
+ var head = document.head || document.getElementsByTagName("head")[0];
692
+ if (relativeToTag) {
693
+ head.insertBefore(tag, relativeToTag);
694
+ } else {
695
+ head.appendChild(tag);
696
+ }
697
+ return tag;
698
+ };
699
+ _createClass(StyleSheet, [
700
+ {
701
+ key: "length",
702
+ get: function get() {
703
+ return this._rulesCount;
704
+ }
705
+ }
706
+ ]);
707
+ return StyleSheet;
708
+ }();
709
+ function invariant$1(condition, message) {
710
+ if (!condition) {
711
+ throw new Error("StyleSheet: " + message + ".");
712
+ }
713
+ }
714
+
715
+ function hash(str) {
716
+ var _$hash = 5381, i = str.length;
717
+ while(i){
718
+ _$hash = _$hash * 33 ^ str.charCodeAt(--i);
719
+ }
720
+ /* JavaScript does bitwise operations (like XOR, above) on 32-bit signed
721
+ * integers. Since we want the results to be always positive, convert the
722
+ * signed int to an unsigned by doing an unsigned bitshift. */ return _$hash >>> 0;
723
+ }
724
+ var stringHash = hash;
725
+
726
+ var sanitize = function(rule) {
727
+ return rule.replace(/\/style/gi, "\\/style");
728
+ };
729
+ var cache = {};
730
+ /**
731
+ * computeId
732
+ *
733
+ * Compute and memoize a jsx id from a basedId and optionally props.
734
+ */ function computeId(baseId, props) {
735
+ if (!props) {
736
+ return "jsx-" + baseId;
737
+ }
738
+ var propsToString = String(props);
739
+ var key = baseId + propsToString;
740
+ if (!cache[key]) {
741
+ cache[key] = "jsx-" + stringHash(baseId + "-" + propsToString);
742
+ }
743
+ return cache[key];
744
+ }
745
+ /**
746
+ * computeSelector
747
+ *
748
+ * Compute and memoize dynamic selectors.
749
+ */ function computeSelector(id, css) {
750
+ var selectoPlaceholderRegexp = /__jsx-style-dynamic-selector/g;
751
+ // Sanitize SSR-ed CSS.
752
+ // Client side code doesn't need to be sanitized since we use
753
+ // document.createTextNode (dev) and the CSSOM api sheet.insertRule (prod).
754
+ if (typeof window === "undefined") {
755
+ css = sanitize(css);
756
+ }
757
+ var idcss = id + css;
758
+ if (!cache[idcss]) {
759
+ cache[idcss] = css.replace(selectoPlaceholderRegexp, id);
760
+ }
761
+ return cache[idcss];
762
+ }
763
+
764
+ function mapRulesToStyle(cssRules, options) {
765
+ if (options === void 0) options = {};
766
+ return cssRules.map(function(args) {
767
+ var id = args[0];
768
+ var css = args[1];
769
+ return /*#__PURE__*/ React__default["default"].createElement("style", {
770
+ id: "__" + id,
771
+ // Avoid warnings upon render with a key
772
+ key: "__" + id,
773
+ nonce: options.nonce ? options.nonce : undefined,
774
+ dangerouslySetInnerHTML: {
775
+ __html: css
776
+ }
777
+ });
778
+ });
779
+ }
780
+ var StyleSheetRegistry = /*#__PURE__*/ function() {
781
+ function StyleSheetRegistry(param) {
782
+ var ref = param === void 0 ? {} : param, _styleSheet = ref.styleSheet, styleSheet = _styleSheet === void 0 ? null : _styleSheet, _optimizeForSpeed = ref.optimizeForSpeed, optimizeForSpeed = _optimizeForSpeed === void 0 ? false : _optimizeForSpeed;
783
+ this._sheet = styleSheet || new StyleSheet({
784
+ name: "styled-jsx",
785
+ optimizeForSpeed: optimizeForSpeed
786
+ });
787
+ this._sheet.inject();
788
+ if (styleSheet && typeof optimizeForSpeed === "boolean") {
789
+ this._sheet.setOptimizeForSpeed(optimizeForSpeed);
790
+ this._optimizeForSpeed = this._sheet.isOptimizeForSpeed();
791
+ }
792
+ this._fromServer = undefined;
793
+ this._indices = {};
794
+ this._instancesCounts = {};
795
+ }
796
+ var _proto = StyleSheetRegistry.prototype;
797
+ _proto.add = function add(props) {
798
+ var _this = this;
799
+ if (undefined === this._optimizeForSpeed) {
800
+ this._optimizeForSpeed = Array.isArray(props.children);
801
+ this._sheet.setOptimizeForSpeed(this._optimizeForSpeed);
802
+ this._optimizeForSpeed = this._sheet.isOptimizeForSpeed();
803
+ }
804
+ if (typeof window !== "undefined" && !this._fromServer) {
805
+ this._fromServer = this.selectFromServer();
806
+ this._instancesCounts = Object.keys(this._fromServer).reduce(function(acc, tagName) {
807
+ acc[tagName] = 0;
808
+ return acc;
809
+ }, {});
810
+ }
811
+ var ref = this.getIdAndRules(props), styleId = ref.styleId, rules = ref.rules;
812
+ // Deduping: just increase the instances count.
813
+ if (styleId in this._instancesCounts) {
814
+ this._instancesCounts[styleId] += 1;
815
+ return;
816
+ }
817
+ var indices = rules.map(function(rule) {
818
+ return _this._sheet.insertRule(rule);
819
+ })// Filter out invalid rules
820
+ .filter(function(index) {
821
+ return index !== -1;
822
+ });
823
+ this._indices[styleId] = indices;
824
+ this._instancesCounts[styleId] = 1;
825
+ };
826
+ _proto.remove = function remove(props) {
827
+ var _this = this;
828
+ var styleId = this.getIdAndRules(props).styleId;
829
+ invariant(styleId in this._instancesCounts, "styleId: `" + styleId + "` not found");
830
+ this._instancesCounts[styleId] -= 1;
831
+ if (this._instancesCounts[styleId] < 1) {
832
+ var tagFromServer = this._fromServer && this._fromServer[styleId];
833
+ if (tagFromServer) {
834
+ tagFromServer.parentNode.removeChild(tagFromServer);
835
+ delete this._fromServer[styleId];
836
+ } else {
837
+ this._indices[styleId].forEach(function(index) {
838
+ return _this._sheet.deleteRule(index);
839
+ });
840
+ delete this._indices[styleId];
841
+ }
842
+ delete this._instancesCounts[styleId];
843
+ }
844
+ };
845
+ _proto.update = function update(props, nextProps) {
846
+ this.add(nextProps);
847
+ this.remove(props);
848
+ };
849
+ _proto.flush = function flush() {
850
+ this._sheet.flush();
851
+ this._sheet.inject();
852
+ this._fromServer = undefined;
853
+ this._indices = {};
854
+ this._instancesCounts = {};
855
+ };
856
+ _proto.cssRules = function cssRules() {
857
+ var _this = this;
858
+ var fromServer = this._fromServer ? Object.keys(this._fromServer).map(function(styleId) {
859
+ return [
860
+ styleId,
861
+ _this._fromServer[styleId]
862
+ ];
863
+ }) : [];
864
+ var cssRules = this._sheet.cssRules();
865
+ return fromServer.concat(Object.keys(this._indices).map(function(styleId) {
866
+ return [
867
+ styleId,
868
+ _this._indices[styleId].map(function(index) {
869
+ return cssRules[index].cssText;
870
+ }).join(_this._optimizeForSpeed ? "" : "\n")
871
+ ];
872
+ })// filter out empty rules
873
+ .filter(function(rule) {
874
+ return Boolean(rule[1]);
875
+ }));
876
+ };
877
+ _proto.styles = function styles(options) {
878
+ return mapRulesToStyle(this.cssRules(), options);
879
+ };
880
+ _proto.getIdAndRules = function getIdAndRules(props) {
881
+ var css = props.children, dynamic = props.dynamic, id = props.id;
882
+ if (dynamic) {
883
+ var styleId = computeId(id, dynamic);
884
+ return {
885
+ styleId: styleId,
886
+ rules: Array.isArray(css) ? css.map(function(rule) {
887
+ return computeSelector(styleId, rule);
888
+ }) : [
889
+ computeSelector(styleId, css)
890
+ ]
891
+ };
892
+ }
893
+ return {
894
+ styleId: computeId(id),
895
+ rules: Array.isArray(css) ? css : [
896
+ css
897
+ ]
898
+ };
899
+ };
900
+ /**
901
+ * selectFromServer
902
+ *
903
+ * Collects style tags from the document with id __jsx-XXX
904
+ */ _proto.selectFromServer = function selectFromServer() {
905
+ var elements = Array.prototype.slice.call(document.querySelectorAll('[id^="__jsx-"]'));
906
+ return elements.reduce(function(acc, element) {
907
+ var id = element.id.slice(2);
908
+ acc[id] = element;
909
+ return acc;
910
+ }, {});
911
+ };
912
+ return StyleSheetRegistry;
913
+ }();
914
+ function invariant(condition, message) {
915
+ if (!condition) {
916
+ throw new Error("StyleSheetRegistry: " + message + ".");
917
+ }
918
+ }
919
+ var StyleSheetContext = /*#__PURE__*/ React$1.createContext(null);
920
+ StyleSheetContext.displayName = "StyleSheetContext";
921
+ function createStyleRegistry() {
922
+ return new StyleSheetRegistry();
923
+ }
924
+ function StyleRegistry(param) {
925
+ var configuredRegistry = param.registry, children = param.children;
926
+ var rootRegistry = React$1.useContext(StyleSheetContext);
927
+ var ref = React$1.useState(function() {
928
+ return rootRegistry || configuredRegistry || createStyleRegistry();
929
+ }), registry = ref[0];
930
+ return /*#__PURE__*/ React__default["default"].createElement(StyleSheetContext.Provider, {
931
+ value: registry
932
+ }, children);
933
+ }
934
+ function useStyleRegistry() {
935
+ return React$1.useContext(StyleSheetContext);
936
+ }
937
+
938
+ // Opt-into the new `useInsertionEffect` API in React 18, fallback to `useLayoutEffect`.
939
+ // https://github.com/reactwg/react-18/discussions/110
940
+ var useInsertionEffect = React__default["default"].useInsertionEffect || React$1.useLayoutEffect;
941
+ var defaultRegistry = typeof window !== "undefined" ? createStyleRegistry() : undefined;
942
+ function JSXStyle(props) {
943
+ var registry = defaultRegistry ? defaultRegistry : useStyleRegistry();
944
+ var insertionEffectCalled = React$1.useRef(false);
945
+ // `registry` might not exist while server-side rendering
946
+ if (!registry) {
947
+ return null;
948
+ }
949
+ if (typeof window === "undefined") {
950
+ registry.add(props);
951
+ return null;
952
+ }
953
+ useInsertionEffect(function() {
954
+ // ReactDOM removes all DOM during hydration in certain cases
955
+ if (!document.head) {
956
+ return;
957
+ }
958
+ registry.add(props);
959
+ insertionEffectCalled.current = true;
960
+ return function() {
961
+ insertionEffectCalled.current = false;
962
+ registry.remove(props);
963
+ };
964
+ }, [
965
+ props.id,
966
+ String(props.dynamic)
967
+ ]);
968
+ React$1.useLayoutEffect(function() {
969
+ if (!document.head || insertionEffectCalled.current) {
970
+ return;
971
+ }
972
+ registry.add(props);
973
+ return function() {
974
+ registry.remove(props);
975
+ };
976
+ // props.children can be string[], will be striped since id is identical
977
+ }, [
978
+ props.id,
979
+ String(props.dynamic)
980
+ ]);
981
+ return null;
982
+ }
983
+ JSXStyle.dynamic = function(info) {
984
+ return info.map(function(tagInfo) {
985
+ var baseId = tagInfo[0];
986
+ var props = tagInfo[1];
987
+ return computeId(baseId, props);
988
+ }).join(" ");
989
+ };
990
+
991
+ index.StyleRegistry = StyleRegistry;
992
+ index.createStyleRegistry = createStyleRegistry;
993
+ index.style = JSXStyle;
994
+ index.useStyleRegistry = useStyleRegistry;
995
+ return index;
996
+ }
997
+
998
+ var style;
999
+ var hasRequiredStyle;
1000
+
1001
+ function requireStyle () {
1002
+ if (hasRequiredStyle) return style;
1003
+ hasRequiredStyle = 1;
1004
+ style = requireIndex().style;
1005
+ return style;
1006
+ }
1007
+
1008
+ var styleExports = requireStyle();
1009
+ var _JSXStyle = /*@__PURE__*/getDefaultExportFromCjs(styleExports);
1010
+
1011
+ /* "use client" */
1012
+
1013
+ var getId = function getId() {
1014
+ return Math.random().toString(32).slice(2, 10);
1015
+ };
1016
+ var isBrowser = function isBrowser() {
1017
+ return Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
1018
+ };
1019
+
1020
+ var useSSR = function useSSR() {
1021
+ var _useState = React.useState(false),
1022
+ _useState2 = _slicedToArray(_useState, 2),
1023
+ browser = _useState2[0],
1024
+ setBrowser = _useState2[1];
1025
+ React.useEffect(function () {
1026
+ setBrowser(isBrowser());
1027
+ }, []);
1028
+ return {
1029
+ isBrowser: browser,
1030
+ isServer: !browser
1031
+ };
1032
+ };
1033
+
1034
+ var createElement = function createElement(id) {
1035
+ var el = document.createElement('div');
1036
+ el.setAttribute('id', id);
1037
+ return el;
1038
+ };
1039
+ var usePortal = function usePortal() {
1040
+ var selectId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getId();
1041
+ var getContainer = arguments.length > 1 ? arguments[1] : undefined;
1042
+ var id = "helpdice-ui-".concat(selectId);
1043
+ var _useSSR = useSSR(),
1044
+ isBrowser = _useSSR.isBrowser;
1045
+ var _useState = React.useState(isBrowser ? createElement(id) : null),
1046
+ _useState2 = _slicedToArray(_useState, 2),
1047
+ elSnapshot = _useState2[0],
1048
+ setElSnapshot = _useState2[1];
1049
+ React.useEffect(function () {
1050
+ var customContainer = getContainer ? getContainer() : null;
1051
+ var parentElement = customContainer || document.body;
1052
+ var hasElement = parentElement.querySelector("#".concat(id));
1053
+ var el = hasElement || createElement(id);
1054
+ if (!hasElement) {
1055
+ parentElement.appendChild(el);
1056
+ }
1057
+ setElSnapshot(el);
1058
+ }, []);
1059
+ return elSnapshot;
1060
+ };
1061
+
1062
+ var _excluded = ["children", "className", "visible", "enterTime", "leaveTime", "clearTime", "name"];
1063
+ var CssTransition = function CssTransition(_ref) {
1064
+ var children = _ref.children,
1065
+ _ref$className = _ref.className,
1066
+ className = _ref$className === void 0 ? '' : _ref$className,
1067
+ _ref$visible = _ref.visible,
1068
+ visible = _ref$visible === void 0 ? false : _ref$visible,
1069
+ _ref$enterTime = _ref.enterTime,
1070
+ enterTime = _ref$enterTime === void 0 ? 60 : _ref$enterTime,
1071
+ _ref$leaveTime = _ref.leaveTime,
1072
+ leaveTime = _ref$leaveTime === void 0 ? 60 : _ref$leaveTime,
1073
+ _ref$clearTime = _ref.clearTime,
1074
+ clearTime = _ref$clearTime === void 0 ? 60 : _ref$clearTime,
1075
+ _ref$name = _ref.name,
1076
+ name = _ref$name === void 0 ? 'transition' : _ref$name,
1077
+ props = _objectWithoutProperties(_ref, _excluded);
1078
+ var _useState = React.useState(''),
1079
+ _useState2 = _slicedToArray(_useState, 2),
1080
+ classes = _useState2[0],
1081
+ setClasses = _useState2[1];
1082
+ var _useState3 = React.useState(visible),
1083
+ _useState4 = _slicedToArray(_useState3, 2),
1084
+ renderable = _useState4[0],
1085
+ setRenderable = _useState4[1];
1086
+ React.useEffect(function () {
1087
+ var statusClassName = visible ? 'enter' : 'leave';
1088
+ var time = visible ? enterTime : leaveTime;
1089
+ if (visible && !renderable) {
1090
+ setRenderable(true);
1091
+ }
1092
+ setClasses("".concat(name, "-").concat(statusClassName));
1093
+
1094
+ // set class to active
1095
+ var timer = setTimeout(function () {
1096
+ setClasses("".concat(name, "-").concat(statusClassName, " ").concat(name, "-").concat(statusClassName, "-active"));
1097
+ clearTimeout(timer);
1098
+ }, time);
1099
+
1100
+ // remove classess when animation over
1101
+ var clearClassesTimer = setTimeout(function () {
1102
+ if (!visible) {
1103
+ setClasses('');
1104
+ setRenderable(false);
1105
+ }
1106
+ clearTimeout(clearClassesTimer);
1107
+ }, time + clearTime);
1108
+ return function () {
1109
+ clearTimeout(timer);
1110
+ clearTimeout(clearClassesTimer);
1111
+ };
1112
+ }, [visible, renderable]);
1113
+ if (! /*#__PURE__*/React.isValidElement(children) || !renderable) return null;
1114
+ var propsTransition = _objectSpread2(_objectSpread2({}, props), {}, {
1115
+ className: "".concat(children.props.className, " ").concat(className, " ").concat(classes)
1116
+ });
1117
+ return /*#__PURE__*/React.cloneElement(children, propsTransition);
1118
+ };
1119
+ CssTransition.displayName = 'CssTransition';
1120
+
1121
+ var tuple = function tuple() {
1122
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1123
+ args[_key] = arguments[_key];
1124
+ }
1125
+ return args;
1126
+ };
1127
+ tuple('default', 'secondary', 'success', 'warning', 'error', 'abort', 'secondary-light', 'success-light', 'warning-light', 'error-light');
1128
+ tuple('default', 'secondary', 'success', 'warning', 'error');
1129
+ tuple('default', 'secondary', 'success', 'warning', 'error', 'dark', 'lite');
1130
+ tuple('default', 'secondary', 'success', 'warning', 'error', 'dark', 'lite', 'alert', 'purple', 'violet', 'cyan');
1131
+ tuple('default', 'silent', 'prevent');
1132
+ tuple('hover', 'click');
1133
+ tuple('top', 'topStart', 'topEnd', 'left', 'leftStart', 'leftEnd', 'bottom', 'bottomStart', 'bottomEnd', 'right', 'rightStart', 'rightEnd');
1134
+ tuple('start', 'center', 'end', 'left', 'right');
1135
+
1136
+ var makeToastActions = function makeToastActions(actions, cancelHandle) {
1137
+ var handler = function handler(event, userHandler) {
1138
+ userHandler && userHandler(event, cancelHandle);
1139
+ };
1140
+ if (!actions || !actions.length) return null;
1141
+ return actions.map(function (action, index) {
1142
+ return /*#__PURE__*/React.createElement("button", {
1143
+ color: action.passive ? 'default' : 'secondary',
1144
+ key: "action-".concat(index),
1145
+ onClick: function onClick(event) {
1146
+ return handler(event, action.handler);
1147
+ }
1148
+ }, action.name);
1149
+ });
1150
+ };
1151
+ var getColors = function getColors(palette, type) {
1152
+ var colors = {
1153
+ "default": palette.background,
1154
+ secondary: palette.secondary,
1155
+ success: palette.success,
1156
+ warning: palette.warning,
1157
+ error: palette.error
1158
+ };
1159
+ var isDefault = !type || type === 'default';
1160
+ if (isDefault) return {
1161
+ bgColor: colors["default"],
1162
+ color: palette.foreground
1163
+ };
1164
+ /**
1165
+ * Prevent main color change in special types.
1166
+ * The color will only follow the theme when it is in the default type.
1167
+ */
1168
+ return {
1169
+ bgColor: colors[type],
1170
+ color: 'white'
1171
+ };
1172
+ };
1173
+ tuple('topLeft', 'topRight', 'bottomLeft', 'bottomRight');
1174
+ var isTopPlacement = function isTopPlacement(placement) {
1175
+ return "".concat(placement).toLowerCase().startsWith('top');
1176
+ };
1177
+ var isLeftPlacement = function isLeftPlacement(placement) {
1178
+ return "".concat(placement).toLowerCase().endsWith('left');
1179
+ };
1180
+ var getTranslateByPlacement = function getTranslateByPlacement(placement) {
1181
+ var translateInByPlacement = {
1182
+ topLeft: 'translate(-60px, -60px)',
1183
+ topRight: 'translate(60px, -60px)',
1184
+ bottomLeft: 'translate(-60px, 60px)',
1185
+ bottomRight: 'translate(60px, 60px)'
1186
+ };
1187
+ var translateOutByPlacement = {
1188
+ topLeft: 'translate(-50px, 15px) scale(0.85)',
1189
+ topRight: 'translate(50px, 15px) scale(0.85)',
1190
+ bottomLeft: 'translate(-50px, -15px) scale(0.85)',
1191
+ bottomRight: 'translate(50px, -15px) scale(0.85)'
1192
+ };
1193
+ return {
1194
+ enter: translateInByPlacement[placement],
1195
+ leave: translateOutByPlacement[placement]
1196
+ };
1197
+ };
1198
+
1199
+ var ToastItem = /*#__PURE__*/React.memo(function (_ref) {
1200
+ var toast = _ref.toast,
1201
+ layout = _ref.layout;
1202
+ var theme = useTheme();
1203
+ var _useMemo = React.useMemo(function () {
1204
+ return getColors(theme.palette, toast.type);
1205
+ }, [theme.palette, toast.type]),
1206
+ color = _useMemo.color,
1207
+ bgColor = _useMemo.bgColor;
1208
+ var isReactNode = typeof toast.text !== 'string';
1209
+ var padding = layout.padding,
1210
+ margin = layout.margin,
1211
+ maxHeight = layout.maxHeight,
1212
+ maxWidth = layout.maxWidth,
1213
+ width = layout.width,
1214
+ placement = layout.placement;
1215
+ var _useMemo2 = React.useMemo(function () {
1216
+ return getTranslateByPlacement(placement);
1217
+ }, [placement]),
1218
+ enter = _useMemo2.enter,
1219
+ leave = _useMemo2.leave;
1220
+ return /*#__PURE__*/React.createElement(CssTransition, {
1221
+ name: "toast",
1222
+ visible: toast.visible,
1223
+ clearTime: 350
1224
+ }, /*#__PURE__*/React.createElement("div", {
1225
+ key: toast.id,
1226
+ className: _JSXStyle.dynamic([["1407001838", [width, maxWidth, maxHeight, theme.palette.foreground, bgColor, color, theme.layout.radius, theme.expressiveness.shadowSmall, theme.layout.gapHalf, enter, margin, padding, margin, padding, leave]]]) + " " + "toast"
1227
+ }, isReactNode ? toast.text : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
1228
+ className: _JSXStyle.dynamic([["1407001838", [width, maxWidth, maxHeight, theme.palette.foreground, bgColor, color, theme.layout.radius, theme.expressiveness.shadowSmall, theme.layout.gapHalf, enter, margin, padding, margin, padding, leave]]]) + " " + "message"
1229
+ }, toast.text), /*#__PURE__*/React.createElement("div", {
1230
+ className: _JSXStyle.dynamic([["1407001838", [width, maxWidth, maxHeight, theme.palette.foreground, bgColor, color, theme.layout.radius, theme.expressiveness.shadowSmall, theme.layout.gapHalf, enter, margin, padding, margin, padding, leave]]]) + " " + "action"
1231
+ }, makeToastActions(toast.actions, toast.cancel))), /*#__PURE__*/React.createElement(_JSXStyle, {
1232
+ id: "1407001838",
1233
+ dynamic: [width, maxWidth, maxHeight, theme.palette.foreground, bgColor, color, theme.layout.radius, theme.expressiveness.shadowSmall, theme.layout.gapHalf, enter, margin, padding, margin, padding, leave]
1234
+ }, ".toast.__jsx-style-dynamic-selector{width:".concat(width, ";max-width:").concat(maxWidth, ";max-height:").concat(maxHeight, ";display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:").concat(theme.palette.foreground, ";background-color:").concat(bgColor, ";color:").concat(color, ";border:0;border-radius:").concat(theme.layout.radius, ";opacity:1;box-shadow:").concat(theme.expressiveness.shadowSmall, ";-webkit-transition:all 350ms cubic-bezier(0.1,0.2,0.1,1);transition:all 350ms cubic-bezier(0.1,0.2,0.1,1);overflow:hidden;}.message.__jsx-style-dynamic-selector{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;height:100%;font-size:0.875em;display:-webkit-box;word-break:break-all;padding-right:").concat(theme.layout.gapHalf, ";overflow:hidden;max-height:100%;text-overflow:ellipsis;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-height:1.1rem;}.toast-enter.__jsx-style-dynamic-selector{opacity:0;height:0;padding:0;margin:0;-webkit-transform:").concat(enter, ";-ms-transform:").concat(enter, ";transform:").concat(enter, ";}.toast-enter-active.__jsx-style-dynamic-selector{opacity:1;height:auto;margin:").concat(margin, ";padding:").concat(padding, ";-webkit-transform:translate(0,0);-ms-transform:translate(0,0);transform:translate(0,0);}.toast-leave.__jsx-style-dynamic-selector{opacity:1;-webkit-transform:translate(0,0);-ms-transform:translate(0,0);transform:translate(0,0);height:auto;margin:").concat(margin, ";padding:").concat(padding, ";}.toast-leave-active.__jsx-style-dynamic-selector{opacity:0;-webkit-transform:").concat(leave, ";-ms-transform:").concat(leave, ";transform:").concat(leave, ";}"))));
1235
+ });
1236
+
1237
+ /* "use client" */
1238
+
1239
+ var classObjectToString = function classObjectToString(className) {
1240
+ var keys = Object.keys(className);
1241
+ var len = keys.length;
1242
+ var str = '';
1243
+ for (var index = 0; index < len; index++) {
1244
+ var key = keys[index];
1245
+ var val = className[keys[index]];
1246
+ if (!val) continue;
1247
+ str = str ? "".concat(str, " ").concat(String(key)) : String(key);
1248
+ }
1249
+ return str;
1250
+ };
1251
+ var isObjectClassName = function isObjectClassName(value) {
1252
+ return _typeof(value) === 'object' && !Array.isArray(value);
1253
+ };
1254
+ var useClasses = function useClasses() {
1255
+ var len = arguments.length;
1256
+ var classes = '';
1257
+ if (len === 0) return classes;
1258
+ for (var index = 0; index < len; index++) {
1259
+ var val = index < 0 || arguments.length <= index ? undefined : arguments[index];
1260
+ if (!val) continue;
1261
+ if (isObjectClassName(val)) {
1262
+ classes += " ".concat(classObjectToString(val));
1263
+ } else {
1264
+ classes += " ".concat(String(val).trim());
1265
+ }
1266
+ }
1267
+ return classes.trim();
1268
+ };
1269
+
1270
+ var ToastContainer = function ToastContainer() {
1271
+ var theme = useTheme();
1272
+ var portal = usePortal('toast');
1273
+ var _useCurrentState = useCurrentState(false),
1274
+ _useCurrentState2 = _slicedToArray(_useCurrentState, 3),
1275
+ setHovering = _useCurrentState2[1],
1276
+ hoveringRef = _useCurrentState2[2];
1277
+ var _useHUIContext = useHUIContext(),
1278
+ toasts = _useHUIContext.toasts,
1279
+ updateToasts = _useHUIContext.updateToasts,
1280
+ toastLayout = _useHUIContext.toastLayout,
1281
+ lastUpdateToastId = _useHUIContext.lastUpdateToastId;
1282
+ var memoizedLayout = React.useMemo(function () {
1283
+ return toastLayout;
1284
+ }, [toastLayout]);
1285
+ var toastElements = React.useMemo(function () {
1286
+ return toasts.map(function (toast) {
1287
+ return /*#__PURE__*/React.createElement(ToastItem, {
1288
+ toast: toast,
1289
+ layout: memoizedLayout,
1290
+ key: toast._internalIdent
1291
+ });
1292
+ });
1293
+ }, [toasts, memoizedLayout]);
1294
+ var classNames = React.useMemo(function () {
1295
+ return useClasses('toasts', {
1296
+ top: isTopPlacement(toastLayout.placement),
1297
+ left: isLeftPlacement(toastLayout.placement)
1298
+ });
1299
+ }, [memoizedLayout]);
1300
+ var hoverHandler = function hoverHandler(isHovering) {
1301
+ setHovering(isHovering);
1302
+ if (isHovering) {
1303
+ return updateToasts(function (last) {
1304
+ return last.map(function (toast) {
1305
+ if (!toast.visible) return toast;
1306
+ toast._timeout && window.clearTimeout(toast._timeout);
1307
+ return _objectSpread2(_objectSpread2({}, toast), {}, {
1308
+ timeout: null
1309
+ });
1310
+ });
1311
+ });
1312
+ }
1313
+ updateToasts(function (last) {
1314
+ return last.map(function (toast, index) {
1315
+ if (!toast.visible) return toast;
1316
+ toast._timeout && window.clearTimeout(toast._timeout);
1317
+ return _objectSpread2(_objectSpread2({}, toast), {}, {
1318
+ _timeout: function () {
1319
+ var timer = window.setTimeout(function () {
1320
+ toast.cancel();
1321
+ window.clearTimeout(timer);
1322
+ }, toast.delay + index * 100);
1323
+ return timer;
1324
+ }()
1325
+ });
1326
+ });
1327
+ });
1328
+ };
1329
+ React.useEffect(function () {
1330
+ var index = toasts.findIndex(function (r) {
1331
+ return r._internalIdent === lastUpdateToastId;
1332
+ });
1333
+ var toast = toasts[index];
1334
+ if (!toast || toast.visible || !hoveringRef.current) return;
1335
+ var hasVisible = toasts.find(function (r, i) {
1336
+ return i < index && r.visible;
1337
+ });
1338
+ if (hasVisible || !hoveringRef.current) return;
1339
+ hoverHandler(false);
1340
+ }, [toasts, lastUpdateToastId]);
1341
+ React.useEffect(function () {
1342
+ var timeout = null;
1343
+ var timer = window.setInterval(function () {
1344
+ if (toasts.length === 0) return;
1345
+ timeout = window.setTimeout(function () {
1346
+ var allInvisible = !toasts.find(function (r) {
1347
+ return r.visible;
1348
+ });
1349
+ allInvisible && updateToasts(function () {
1350
+ return [];
1351
+ });
1352
+ timeout && clearTimeout(timeout);
1353
+ }, 350);
1354
+ }, 5000);
1355
+ return function () {
1356
+ timer && clearInterval(timer);
1357
+ timeout && clearTimeout(timeout);
1358
+ };
1359
+ }, [toasts]);
1360
+ if (!portal) return null;
1361
+ if (!toasts || toasts.length === 0) return null;
1362
+ return /*#__PURE__*/reactDom.createPortal(/*#__PURE__*/React.createElement("div", {
1363
+ onMouseEnter: function onMouseEnter() {
1364
+ return hoverHandler(true);
1365
+ },
1366
+ onMouseLeave: function onMouseLeave() {
1367
+ return hoverHandler(false);
1368
+ },
1369
+ className: _JSXStyle.dynamic([["622610754", [theme.layout.gap, theme.layout.gap, theme.layout.gap, theme.layout.gap]]]) + " " + (classNames || "")
1370
+ }, toastElements, /*#__PURE__*/React.createElement(_JSXStyle, {
1371
+ id: "622610754",
1372
+ dynamic: [theme.layout.gap, theme.layout.gap, theme.layout.gap, theme.layout.gap]
1373
+ }, ".toasts.__jsx-style-dynamic-selector{position:fixed;width:auto;max-width:100%;right:".concat(theme.layout.gap, ";bottom:").concat(theme.layout.gap, ";z-index:2000;-webkit-transition:all 400ms ease;transition:all 400ms ease;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}.top.__jsx-style-dynamic-selector{bottom:unset;-webkit-flex-direction:column-reverse;-ms-flex-direction:column-reverse;flex-direction:column-reverse;top:").concat(theme.layout.gap, ";}.left.__jsx-style-dynamic-selector{right:unset;left:").concat(theme.layout.gap, ";}"))), portal);
1374
+ };
1375
+
1376
+ var HuiProvider = function HuiProvider(_ref) {
1377
+ var themes = _ref.themes,
1378
+ themeType = _ref.themeType,
1379
+ children = _ref.children;
1380
+ var _React$useState = React.useState(''),
1381
+ _React$useState2 = _slicedToArray(_React$useState, 2),
1382
+ lastUpdateToastId = _React$useState2[0],
1383
+ setLastUpdateToastId = _React$useState2[1];
1384
+ var _useCurrentState = useCurrentState([]),
1385
+ _useCurrentState2 = _slicedToArray(_useCurrentState, 3),
1386
+ toasts = _useCurrentState2[0],
1387
+ setToasts = _useCurrentState2[1],
1388
+ toastsRef = _useCurrentState2[2];
1389
+ var _useCurrentState3 = useCurrentState(defaultToastLayout),
1390
+ _useCurrentState4 = _slicedToArray(_useCurrentState3, 3),
1391
+ toastLayout = _useCurrentState4[0],
1392
+ setToastLayout = _useCurrentState4[1],
1393
+ toastLayoutRef = _useCurrentState4[2];
1394
+ var updateToasts = function updateToasts(fn) {
1395
+ var nextToasts = fn(toastsRef.current);
1396
+ setToasts(nextToasts);
1397
+ };
1398
+ var updateToastLayout = function updateToastLayout(fn) {
1399
+ var nextLayout = fn(toastLayoutRef.current);
1400
+ setToastLayout(nextLayout);
1401
+ };
1402
+ var updateLastToastId = function updateLastToastId(fn) {
1403
+ setLastUpdateToastId(fn());
1404
+ };
1405
+ var initialValue = React.useMemo(function () {
1406
+ return {
1407
+ toasts: toasts,
1408
+ toastLayout: toastLayout,
1409
+ updateToasts: updateToasts,
1410
+ lastUpdateToastId: lastUpdateToastId,
1411
+ updateToastLayout: updateToastLayout,
1412
+ updateLastToastId: updateLastToastId
1413
+ };
1414
+ }, [toasts, toastLayout, lastUpdateToastId]);
1415
+ return /*#__PURE__*/React.createElement(HUIContent.Provider, {
1416
+ value: initialValue
1417
+ }, /*#__PURE__*/React.createElement(ThemeProvider, {
1418
+ themes: themes,
1419
+ themeType: themeType
1420
+ }, children, /*#__PURE__*/React.createElement(ToastContainer, null)));
1421
+ };
1422
+
1423
+ /* "use client" */
1424
+
1425
+ exports.default = HuiProvider;