@zuzjs/ui 0.3.3 → 0.3.4

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 (84) hide show
  1. package/README.md +0 -0
  2. package/dist/hooks.js +89 -0
  3. package/dist/styles.css +37 -62
  4. package/dist/ui.js +665 -0
  5. package/jest.config.js +0 -0
  6. package/package.json +16 -18
  7. package/rollup.config.js +30 -47
  8. package/src/comps/box.tsx +24 -28
  9. package/src/comps/button.tsx +23 -47
  10. package/src/comps/crumb.tsx +9 -0
  11. package/src/comps/form.tsx +57 -88
  12. package/src/comps/heading.tsx +25 -31
  13. package/src/comps/icon.tsx +24 -36
  14. package/src/comps/input.tsx +24 -224
  15. package/src/comps/select.tsx +23 -63
  16. package/src/comps/spinner.tsx +23 -35
  17. package/src/comps/stylesheet.tsx +5 -0
  18. package/src/context/AppContext.tsx +2 -2
  19. package/src/context/AppProvider.tsx +68 -105
  20. package/src/context/createSlice.tsx +15 -39
  21. package/src/context/index.tsx +4 -5
  22. package/src/core/css.ts +1 -0
  23. package/src/core/index.tsx +241 -0
  24. package/src/core/styles.ts +378 -371
  25. package/src/hooks/index.tsx +2 -10
  26. package/src/hooks/useDispatch.tsx +36 -36
  27. package/src/hooks/useStore.tsx +24 -26
  28. package/src/hooks.tsx +8 -0
  29. package/src/scss/mixins.scss +2 -2
  30. package/src/scss/props.scss +91 -69
  31. package/src/scss/{style.scss → styles.scss} +102 -132
  32. package/src/ui.tsx +13 -0
  33. package/tsconfig.json +0 -0
  34. package/tsconfig.lib.json +0 -0
  35. package/tsconfig.spec.json +0 -0
  36. package/dist/index.js +0 -1879
  37. package/src/actions/addForm.tsx +0 -0
  38. package/src/actions/index.tsx +0 -29
  39. package/src/actions/redo.tsx +0 -1
  40. package/src/actions/reset.tsx +0 -1
  41. package/src/actions/undo.tsx +0 -1
  42. package/src/comps/app.tsx +0 -34
  43. package/src/comps/checkbox.tsx +0 -74
  44. package/src/comps/component.tsx +0 -32
  45. package/src/comps/contextmenu.tsx +0 -60
  46. package/src/comps/cover.tsx +0 -34
  47. package/src/comps/image.tsx +0 -34
  48. package/src/comps/masonry.tsx +0 -192
  49. package/src/comps/mediaplayer.tsx +0 -12
  50. package/src/comps/placeholder.tsx +0 -58
  51. package/src/comps/root.tsx +0 -32
  52. package/src/comps/spacer.tsx +0 -20
  53. package/src/comps/text.tsx +0 -27
  54. package/src/comps/toaster.tsx +0 -123
  55. package/src/comps/tweet.tsx +0 -48
  56. package/src/context/_AppProvider.tsx +0 -116
  57. package/src/context/combineReducers.tsx +0 -47
  58. package/src/context/combineState.tsx +0 -14
  59. package/src/context/reduceReducers.tsx +0 -6
  60. package/src/context/store/appbase.tsx +0 -19
  61. package/src/context/store/lang.tsx +0 -26
  62. package/src/context/store/theme.tsx +0 -54
  63. package/src/core/extractCurrentDesignState.tsx +0 -0
  64. package/src/core/index.ts +0 -431
  65. package/src/core/router.ts +0 -86
  66. package/src/hooks/useAppReducer.tsx +0 -40
  67. package/src/hooks/useChooseEffect.tsx +0 -6
  68. package/src/hooks/useContextMenu.tsx +0 -123
  69. package/src/hooks/useDevice.tsx +0 -168
  70. package/src/hooks/useImage.tsx +0 -84
  71. package/src/hooks/useLang.tsx +0 -9
  72. package/src/hooks/useMediaPlayer.tsx +0 -27
  73. package/src/hooks/useNavigator.tsx +0 -6
  74. package/src/hooks/useRender.tsx +0 -29
  75. package/src/hooks/useResizeObserver.tsx +0 -84
  76. package/src/hooks/useRouter.tsx +0 -45
  77. package/src/hooks/useSelector.tsx +0 -9
  78. package/src/hooks/useTheme.tsx +0 -9
  79. package/src/hooks/useToast.tsx +0 -11
  80. package/src/index.tsx +0 -33
  81. package/src/kit/Builder.tsx +0 -18
  82. package/src/kit/Component.tsx +0 -32
  83. package/src/kit/Header.tsx +0 -21
  84. package/src/scss/constants.scss +0 -4
package/dist/index.js DELETED
@@ -1,1879 +0,0 @@
1
- import { createContext, useEffect, useMemo, useReducer, useCallback, useContext, forwardRef, useRef, useState, useLayoutEffect, useDebugValue, cloneElement, useImperativeHandle, createElement, Component as Component$1, Children as Children$1 } from 'react';
2
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
- import PropTypes from 'prop-types';
4
- import Children from 'react-children-utilities';
5
- import Cookies from 'js-cookie';
6
- import axios from 'axios';
7
- import { nanoid } from 'nanoid';
8
- import { ClassNames } from '@emotion/react';
9
- import ReactDOM from 'react-dom/client';
10
- import styled from '@emotion/styled';
11
-
12
- const AppContext = createContext({});
13
-
14
- /******************************************************************************
15
- Copyright (c) Microsoft Corporation.
16
-
17
- Permission to use, copy, modify, and/or distribute this software for any
18
- purpose with or without fee is hereby granted.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
21
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
22
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
23
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
24
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
26
- PERFORMANCE OF THIS SOFTWARE.
27
- ***************************************************************************** */
28
-
29
- function __rest(s, e) {
30
- var t = {};
31
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
32
- t[p] = s[p];
33
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
34
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
35
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
36
- t[p[i]] = s[p[i]];
37
- }
38
- return t;
39
- }
40
-
41
- function __classPrivateFieldGet(receiver, state, kind, f) {
42
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
43
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
44
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
45
- }
46
-
47
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
48
- if (kind === "m") throw new TypeError("Private method is not writable");
49
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
50
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
51
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
52
- }
53
-
54
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
55
- var e = new Error(message);
56
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
- };
58
-
59
- var _AppTheme_mode, _AppTheme_listen, _AppTheme_lightTheme, _AppTheme_darkTheme;
60
- class AppTheme {
61
- constructor(_conf) {
62
- _AppTheme_mode.set(this, void 0);
63
- _AppTheme_listen.set(this, void 0);
64
- _AppTheme_lightTheme.set(this, void 0);
65
- _AppTheme_darkTheme.set(this, void 0);
66
- this.get = () => {
67
- let self = this;
68
- if (__classPrivateFieldGet(self, _AppTheme_mode, "f") === "auto") {
69
- typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
70
- __classPrivateFieldSet(self, _AppTheme_mode, event.matches ? "dark" : "light", "f");
71
- __classPrivateFieldGet(self, _AppTheme_listen, "f").call(self, __classPrivateFieldGet(self, _AppTheme_mode, "f"));
72
- });
73
- return typeof window !== 'undefined' && window.matchMedia &&
74
- window.matchMedia('(prefers-color-scheme: dark)').matches ?
75
- __classPrivateFieldGet(self, _AppTheme_darkTheme, "f") : __classPrivateFieldGet(self, _AppTheme_lightTheme, "f");
76
- }
77
- else {
78
- if (__classPrivateFieldGet(self, _AppTheme_mode, "f") === "light") {
79
- return __classPrivateFieldGet(self, _AppTheme_lightTheme, "f");
80
- }
81
- else if (__classPrivateFieldGet(self, _AppTheme_mode, "f") === "dark") {
82
- return __classPrivateFieldGet(self, _AppTheme_darkTheme, "f");
83
- }
84
- }
85
- };
86
- const conf = _conf || {};
87
- __classPrivateFieldSet(this, _AppTheme_listen, "listen" in conf ? conf.listen : (mod) => { console.log(`Theme switched to ${mod}`); }, "f");
88
- __classPrivateFieldSet(this, _AppTheme_mode, conf.mode || conf.theme.mode || "auto", "f");
89
- __classPrivateFieldSet(this, _AppTheme_lightTheme, Object.assign({
90
- //CORE
91
- tag: "light", dark: false, primary: '#edeef5', secondary: '#f9f9f9', textColor: '#111111' }, ("theme" in conf && "light" in conf.theme ? Object.assign({}, conf.theme.light) : {})), "f");
92
- __classPrivateFieldSet(this, _AppTheme_darkTheme, Object.assign({
93
- //CORE
94
- tag: "dark", dark: true, primary: '#21222d', secondary: '#282a37', textColor: '#f9f9f9' }, ("theme" in conf && "dark" in conf.theme ? Object.assign({}, conf.theme.dark) : {})), "f");
95
- }
96
- }
97
- _AppTheme_mode = new WeakMap(), _AppTheme_listen = new WeakMap(), _AppTheme_lightTheme = new WeakMap(), _AppTheme_darkTheme = new WeakMap();
98
-
99
- var _AppLang_mode, _AppLang_listen, _AppLang_lang;
100
- class AppLang {
101
- constructor(_conf) {
102
- _AppLang_mode.set(this, void 0);
103
- _AppLang_listen.set(this, void 0);
104
- _AppLang_lang.set(this, void 0);
105
- this.get = () => {
106
- let self = this;
107
- return __classPrivateFieldGet(self, _AppLang_lang, "f");
108
- };
109
- const conf = _conf || {};
110
- __classPrivateFieldSet(this, _AppLang_listen, "listen" in conf ? conf.listen : (mod) => { console.log(`Lang switched to ${mod}`); }, "f");
111
- __classPrivateFieldSet(this, _AppLang_mode, conf.mode || "en", "f");
112
- __classPrivateFieldSet(this, _AppLang_lang, Object.assign({
113
- //CORE
114
- tag: "en" }, ("lang" in conf ? Object.assign({}, conf.lang) : {})), "f");
115
- }
116
- }
117
- _AppLang_mode = new WeakMap(), _AppLang_listen = new WeakMap(), _AppLang_lang = new WeakMap();
118
-
119
- let isMounted = true;
120
- const STORE_KEY = `__zuzjs`;
121
- const STORE_FORM_KEY = `${STORE_KEY}forms`;
122
- const defaultState = {
123
- [`${STORE_KEY}base`]: {
124
- debug: true,
125
- loading: false,
126
- _tmp: Math.random()
127
- },
128
- [STORE_FORM_KEY]: {
129
- forms: {}
130
- }
131
- };
132
- const rootReducer = (state, action) => (Object.assign(Object.assign({}, state), action.payload));
133
- const AppProvider = ({ children, initialState = {}, theme = {}, lang = {} }) => {
134
- useEffect(() => {
135
- isMounted = true;
136
- return () => {
137
- isMounted = false;
138
- };
139
- }, []);
140
- const rootState = useMemo(() => (Object.assign(Object.assign(Object.assign({}, defaultState), initialState), { theme: new AppTheme({ theme }).get(), lang: new AppLang({ lang }).get() })), [initialState]);
141
- const [state, _dispatch] = useReducer(rootReducer, rootState);
142
- const dispatch = useCallback((args) => {
143
- if (isMounted) {
144
- _dispatch(Object.assign({}, args));
145
- }
146
- }, [_dispatch]);
147
- // const dispatch = useCallback((payload = {}, _key = 'base') => {
148
- // if(isMounted){
149
- // const key = STORE_DEFAUTLS.indexOf(`${STORE_KEY}${_key}`) > -1 ? `${STORE_KEY}${_key}` : _key;
150
- // const _state = { ...state[key] }
151
- // console.log('key', key)
152
- // console.log('state', _state)
153
- // _dispatch({
154
- // type: 'any',
155
- // payload: {
156
- // payload
157
- // }
158
- // })
159
- // }
160
- // }, [_dispatch]);
161
- const providedValue = useMemo(() => (Object.assign(Object.assign({}, state), { dispatch })), [state]);
162
- return jsx(AppContext.Provider, { value: providedValue, children: children });
163
- };
164
- AppProvider.defaultProps = {
165
- theme: {},
166
- lang: {},
167
- initialState: {},
168
- };
169
- AppProvider.propTypes = {
170
- children: PropTypes.node.isRequired,
171
- initialState: PropTypes.instanceOf(Object),
172
- theme: PropTypes.instanceOf(Object),
173
- lang: PropTypes.instanceOf(Object)
174
- };
175
-
176
- const createSlice = ({ name, initialState, reducers }) => {
177
- // const _dynamiceReducers = {}
178
- // Object.keys(reducers).map(k => {
179
- // _dynamiceReducers[reducers[k].name] = [reducers[k].reducer, initialState]
180
- // })
181
- // const _keys = Object.keys(reducers);
182
- // const [reducer, state] = combineReducers(_dynamiceReducers);
183
- return {
184
- name,
185
- reducer: reducers,
186
- actions: reducers,
187
- state: initialState
188
- };
189
- };
190
- createSlice.defaultProps = {
191
- name: `app`,
192
- initialState: {},
193
- reducers: {}
194
- };
195
- createSlice.propTypes = {
196
- name: PropTypes.string.isRequired,
197
- initialState: PropTypes.instanceOf(Object).isRequired,
198
- reducers: PropTypes.instanceOf(Object).isRequired
199
- };
200
-
201
- const cssProps = {
202
- "ac": "align-content",
203
- "alignContent": "align-content",
204
- "aic": "aic",
205
- "ais": "ais",
206
- "aie": "aie",
207
- "nous": "nous",
208
- "nope": "nope",
209
- "ai": "align-items",
210
- "alignItems": "align-items",
211
- "ass": "ass",
212
- "asc": "asc",
213
- "ase": "ase",
214
- "alignSelf": "align-self",
215
- "all": "all",
216
- "animation": "animation",
217
- "animationDelay": "animation-delay",
218
- "animationDirection": "animation-direction",
219
- "animationDuration": "animation-duration",
220
- "animationFillMode": "animation-fill-mode",
221
- "animationIterationCount": "animation-iteration-count",
222
- "animationName": "animation-name",
223
- "animationPlayState": "animation-play-state",
224
- "animationTimingFunction": "animation-timing-function",
225
- "backfaceVisibility": "backface-visibility",
226
- "backgroundAttachment": "background-attachment",
227
- "backgroundBlendMode": "background-blend-mode",
228
- "backgroundClip": "background-clip",
229
- "bg": "background",
230
- "background": "background",
231
- "bgc": "background-color",
232
- "bgColor": "background-color",
233
- "backgroundColor": "background-color",
234
- "backgroundImage": "background-image",
235
- "backgroundOrigin": "background-origin",
236
- "backgroundPosition": "background-position",
237
- "backgroundRepeat": "background-repeat",
238
- "backgroundSize": "background-size",
239
- "border": "border",
240
- "borderBottom": "border-bottom",
241
- "borderBottomColor": "border-bottom-color",
242
- "borderBottomStyle": "border-bottom-style",
243
- "borderBottomWidth": "border-bottom-width",
244
- "borderCollapse": "border-collapse",
245
- "borderColor": "border-color",
246
- "borderImage": "border-image",
247
- "borderImageOutset": "border-image-outset",
248
- "borderImageRepeat": "border-image-repeat",
249
- "borderImageSlice": "border-image-slice",
250
- "borderImageSource": "border-image-source",
251
- "borderImageWidth": "border-image-width",
252
- "borderLeft": "border-left",
253
- "borderLeftColor": "border-left-color",
254
- "borderLeftStyle": "border-left-style",
255
- "borderLeftWidth": "border-left-width",
256
- //Radius
257
- "r": "border-radius",
258
- "br": "border-radius",
259
- "borderRadius": "border-radius",
260
- "brtl": "border-top-left-radius",
261
- "borderTopLeftRadius": "border-top-left-radius",
262
- "brtr": "border-top-right-radius",
263
- "borderTopRightRadius": "border-top-right-radius",
264
- "brbl": "border-bottom-left-radius",
265
- "borderBottomLeftRadius": "border-bottom-left-radius",
266
- "brbr": "border-bottom-right-radius",
267
- "borderBottomRightRadius": "border-bottom-right-radius",
268
- "borderRight": "border-right",
269
- "borderRightColor": "border-right-color",
270
- "borderRightStyle": "border-right-style",
271
- "borderRightWidth": "border-right-width",
272
- "borderSpacing": "border-spacing",
273
- "borderStyle": "border-style",
274
- "borderTop": "border-top",
275
- "borderTopColor": "border-top-color",
276
- "borderTopStyle": "border-top-style",
277
- "borderTopWidth": "border-top-width",
278
- "borderWidth": "border-width",
279
- "bottom": "bottom",
280
- "boxDecorationBreak": "box-decoration-break",
281
- "boxShadow": "box-shadow",
282
- "boxSizing": "box-sizing",
283
- "captionSide": "caption-side",
284
- "caretColor": "caret-color",
285
- "@charset": "@charset",
286
- "clear": "clear",
287
- "clip": "clip",
288
- "clipPath": "clip-path",
289
- "color": "color",
290
- "columnCount": "column-count",
291
- "columnFill": "column-fill",
292
- "columnGap": "column-gap",
293
- "colGap": "column-gap",
294
- "columnRule": "column-rule",
295
- "columnRuleColor": "column-rule-color",
296
- "columnRuleStyle": "column-rule-style",
297
- "columnRuleWidth": "column-rule-width",
298
- "columnSpan": "column-span",
299
- "columnWidth": "column-width",
300
- "colW": "column-width",
301
- "columns": "columns",
302
- "content": "content",
303
- "counterIncrement": "counter-increment",
304
- "counterReset": "counter-reset",
305
- "cursor": "cursor",
306
- "pointer": "pointer",
307
- "direction": "direction",
308
- "display": "display",
309
- "emptyCells": "empty-cells",
310
- "filter": "filter",
311
- "flex": "flex",
312
- "flexBasis": "flex-basis",
313
- "dir": "flex-direction",
314
- "flexDirection": "flex-direction",
315
- "flexFlow": "flex-flow",
316
- "flexGrow": "flex-grow",
317
- "flexShrink": "flex-shrink",
318
- "flexWrap": "flex-wrap",
319
- "float": "float",
320
- "font": "font",
321
- "fontFamily": "font-family",
322
- "fontKerning": "font-kerning",
323
- "size": "font-size",
324
- "fontSize": "font-size",
325
- "fontSizeAdjust": "font-size-adjust",
326
- "fontStretch": "font-stretch",
327
- "fontStyle": "font-style",
328
- "fontVariant": "font-variant",
329
- "bold": "bold",
330
- "fontWeight": "font-weight",
331
- "gap": "gap",
332
- "grid": "grid",
333
- "gridArea": "grid-area",
334
- "gridAutoColumns": "grid-auto-columns",
335
- "gridAutoFlow": "grid-auto-flow",
336
- "gridAutoRows": "grid-auto-rows",
337
- "gridColumn": "grid-column",
338
- "gridColumnEnd": "grid-column-end",
339
- "gridColumnGap": "grid-column-gap",
340
- "gridColumnStart": "grid-column-start",
341
- "gridGap": "grid-gap",
342
- "gridRow": "grid-row",
343
- "gridRowEnd": "grid-row-end",
344
- "gridRowGap": "grid-row-gap",
345
- "gridRowStart": "grid-row-start",
346
- "gridTemplate": "grid-template",
347
- "gridTemplateAreas": "grid-template-areas",
348
- "gridTemplateColumns": "grid-template-columns",
349
- "gridTemplateRows": "grid-template-rows",
350
- "hangingPunctuation": "hanging-punctuation",
351
- "hyphens": "hyphens",
352
- "isolation": "isolation",
353
- "jcc": "jcc",
354
- "jcs": "jcs",
355
- "jce": "jce",
356
- "jc": "justify-content",
357
- "justifyContent": "justify-content",
358
- "left": "left",
359
- "letterSpacing": "letter-spacing",
360
- "lineHeight": "line-height",
361
- "listStyle": "list-style",
362
- "listStyleImage": "list-style-image",
363
- "listStylePosition": "list-style-position",
364
- "listStyleType": "list-style-type",
365
- //Margin
366
- "m": "margin",
367
- "margin": "margin",
368
- "mb": "margin-bottom",
369
- "marginBottom": "margin-bottom",
370
- "ml": "margin-left",
371
- "marginLeft": "margin-left",
372
- "mr": "margin-right",
373
- "marginRight": "margin-right",
374
- "mt": "margin-top",
375
- "marginTop": "margin-top",
376
- //Height
377
- "h": "height",
378
- "height": "height",
379
- "minH": "min-height",
380
- "minHeight": "min-height",
381
- "maxH": "max-height",
382
- "maxHeight": "max-height",
383
- //Width
384
- "w": "width",
385
- "width": "width",
386
- "minW": "min-width",
387
- "minWidth": "min-width",
388
- "maxW": "max-width",
389
- "maxWidth": "max-width",
390
- "mixBlendMode": "mix-blend-mode",
391
- "objectFit": "object-fit",
392
- "objectPosition": "object-position",
393
- "opacity": "opacity",
394
- "order": "order",
395
- "outline": "outline",
396
- "outlineColor": "outline-color",
397
- "outlineOffset": "outline-offset",
398
- "outlineStyle": "outline-style",
399
- "outlineWidth": "outline-width",
400
- "overflow": "overflow",
401
- "overflowX": "overflow-x",
402
- "overflowY": "overflow-y",
403
- "p": "padding",
404
- "padding": "padding",
405
- "pb": "padding-bottom",
406
- "paddingBottom": "padding-bottom",
407
- "pl": "padding-left",
408
- "paddingLeft": "padding-left",
409
- "pr": "padding-right",
410
- "paddingRight": "padding-right",
411
- "pt": "padding-top",
412
- "paddingTop": "padding-top",
413
- "pageBreakAfter": "page-break-after",
414
- "pageBreakBefore": "page-break-before",
415
- "pageBreakInside": "page-break-inside",
416
- "perspective": "perspective",
417
- "perspectiveOrigin": "perspective-origin",
418
- "pointerEvents": "pointer-events",
419
- "rel": "rel",
420
- "abs": "abs",
421
- "fixed": "fixed",
422
- "sticky": "sticky",
423
- "pos": "position",
424
- "position": "position",
425
- "quotes": "quotes",
426
- "resize": "resize",
427
- "right": "right",
428
- "scrollBehavior": "scroll-behavior",
429
- "tabSize": "tab-size",
430
- "tableLayout": "table-layout",
431
- "align": "text-align",
432
- "textAlign": "text-align",
433
- "textAlignLast": "text-align-last",
434
- "tdh": "tdh",
435
- "td": "text-decoration",
436
- "textDecoration": "text-decoration",
437
- "textDecorationColor": "text-decoration-color",
438
- "textDecorationLine": "text-decoration-line",
439
- "textDecorationStyle": "text-decoration-style",
440
- "textIndent": "text-indent",
441
- "textJustify": "text-justify",
442
- "textOverflow": "text-overflow",
443
- "textShadow": "text-shadow",
444
- "textTransform": "text-transform",
445
- "top": "top",
446
- "transform": "transform",
447
- "transform(2D)": "transform(2D)",
448
- "transformOrigin(twoValue syntax)": "transform-origin(two-value syntax)",
449
- "transformStyle": "transform-style",
450
- "transition": "transition",
451
- "transitionDelay": "transition-delay",
452
- "transitionDuration": "transition-duration",
453
- "transitionProperty": "transition-property",
454
- "transitionTimingFunction": "transition-timing-function",
455
- "unicodeBidi": "unicode-bidi",
456
- "userSelect": "user-select",
457
- "verticalAlign": "vertical-align",
458
- "visibility": "visibility",
459
- "weight": "flex",
460
- "whiteSpace": "white-space",
461
- "ws": "white-space",
462
- "wordBreak": "word-break",
463
- "wordSpacing": "word-spacing",
464
- "wrap": "wrap",
465
- "textWrap": "textWrap",
466
- "wordWrap": "word-wrap",
467
- "writingMode": "writing-mode",
468
- "zIndex": "z-index",
469
- "backdropFilter": "backdrop-filter",
470
- "bgFilter": "backdrop-filter",
471
- //Custom
472
- "anim": "anim",
473
- "fill": "fill",
474
- "abc": "abc",
475
- "fb": "fb",
476
- "ph": "ph",
477
- "pv": "pv",
478
- "mv": "mv",
479
- "mh": "mh"
480
- };
481
- const cssPropsVals = {
482
- //Colors
483
- "primary": 'var(--primary-color)',
484
- "c": "center",
485
- //Flex Directions
486
- "cols": "column",
487
- "colsr": "column-reverse",
488
- "rows": "row",
489
- "rowsr": "row-reverse",
490
- //Positions
491
- "rel": "relative",
492
- "abs": "absolute",
493
- };
494
- const cssPropsDirect = {
495
- 'rel': 'position: relative;',
496
- 'fixed': 'position: fixed;',
497
- 'abs': 'position: absolute;',
498
- 'sticky': 'position: sticky;',
499
- 'flex': 'display: flex;',
500
- 'fwrap': 'flex-wrap: wrap;',
501
- 'aic': 'align-items: center;',
502
- 'ais': 'align-items: flex-start;',
503
- 'aie': 'align-items: flex-end;',
504
- 'ass': 'align-self: flex-start;',
505
- 'asc': 'align-self: center;',
506
- 'ase': 'align-self: flex-end;',
507
- 'jcc': 'justify-content: center;',
508
- 'jcs': 'justify-content: flex-start;',
509
- 'jce': 'justify-content: flex-end;',
510
- 'grid': 'display: grid;',
511
- 'fill': 'top: 0px;left: 0px;right: 0px;bottom: 0px;',
512
- 'abc': 'top: 50%;left: 50%;transform: translate(-50%, -50%);',
513
- 'block': 'display: block;',
514
- 'bold': "font-weight: bold;",
515
- 'wrap': "word-wrap: break-word;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 99%;",
516
- 'textWrap': "word-wrap: break-word;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 99%;",
517
- 'pointer': "cursor: pointer;",
518
- 'fb': 'font-family: var(--primary-font-bold);',
519
- 'ph': 'padding-left: __VALUE__;padding-right: __VALUE__;',
520
- 'pv': 'padding-bottom: __VALUE__;padding-top: __VALUE__;',
521
- 'mv': 'margin-bottom: __VALUE__;margin-top: __VALUE__;',
522
- 'mh': 'margin-left: __VALUE__;margin-right: __VALUE__;',
523
- 'anim': 'transition:all __VALUE__s linear 0s;',
524
- 'nous': 'user-select: none;',
525
- 'nope': 'pointer-events: none;',
526
- 'tdn': 'text-decoration: none;',
527
- };
528
- const cssPropsIgnore = [
529
- 'weight', `opacity`
530
- ];
531
- const _cssColors = [`white`, `black`, `gray`, `red`, `orange`, `yellow`, `green`, `teal`, `blue`, `cyan`, `purple`, `pink`, `linkedin`, `facebook`, `messenger`, `whatsapp`, `twitter`, `telegram`];
532
- const _cssColorsRange = [`50`, `100`, `200`, `300`, `400`, `500`, `600`, `700`, `800`, `900`];
533
- let cssColors = [];
534
- if (cssColors.length == 0) {
535
- _cssColors.map(c => {
536
- _cssColorsRange.map(r => cssColors.push(`${c}.${r}`));
537
- });
538
- }
539
-
540
- const useDispatch = (key) => {
541
- const state = useContext(AppContext);
542
- const dispatch = state['dispatch'];
543
- const prepareState = (prevState, nextState) => {
544
- const nextKeys = Object.keys(nextState);
545
- nextKeys.map(k => {
546
- if (prevState[k] !== nextState[k]) {
547
- prevState[k] = nextState[k];
548
- }
549
- });
550
- return Object.assign(Object.assign({}, prevState), nextState);
551
- };
552
- if (key) {
553
- return (payload = {}) => {
554
- dispatch({
555
- action: key,
556
- payload: {
557
- [key]: prepareState(state[key], payload)
558
- }
559
- });
560
- };
561
- }
562
- return dispatch;
563
- };
564
-
565
- const useStore = (callback, withFilter = true) => {
566
- // if(withInititalState){
567
- // return useContext(AppContext)
568
- // }
569
- let _state = useContext(AppContext);
570
- let state = withFilter ? {} : _state;
571
- if (withFilter) {
572
- const filters = ['defaultState', 'theme', 'dispatch', `${STORE_KEY}base`, `${STORE_KEY}forms`];
573
- Object.keys(_state).map(k => {
574
- if (filters.indexOf(k) == -1) {
575
- state[k] = _state[k];
576
- }
577
- });
578
- }
579
- if ("function" == typeof callback) {
580
- return callback(state);
581
- }
582
- return state;
583
- };
584
-
585
- const ADD_FORM = (name, fields, forms) => ({
586
- forms: Object.assign(Object.assign({}, forms), { [name]: Object.assign({ touched: false, loading: false }, fields) })
587
- });
588
- const UPDATE_FORM_FIELD = (formName, field, value, forms) => {
589
- if (forms[formName]) {
590
- let _forms = Object.assign({}, forms);
591
- _forms[formName][field] = value;
592
- return {
593
- forms: _forms
594
- };
595
- }
596
- return {};
597
- };
598
-
599
- typeof window !== "undefined" && !!document.documentElement.currentStyle;
600
- const Input = forwardRef((props, ref) => {
601
- const { as, accept, multiple, onChange, onKeyUp, onClick, onBlur, onFocus, readOnly, type, tag, placeholder, name, form, touched, onSubmit, value, defaultValue, fref, autoComplete, elastic, minRows, maxRows } = props;
602
- const dispatch = useDispatch(STORE_FORM_KEY);
603
- const { forms } = useStore(state => state[STORE_FORM_KEY], false);
604
- let Tag = tag || 'input';
605
- const El = Tag;
606
- const _ref = fref || useRef();
607
- const _defaultCSS = `width: 100%;border-radius: var(--radius-base);padding-left: 4px;padding-right: 4px;border-style: solid;border-width: 1px;border-color: var(--colors-gray-200);`;
608
- props.value !== undefined;
609
- useRef();
610
- useEffect(() => { }, []);
611
- return (jsx(ClassNames, { children: ({ css, cx }) => jsx(El, Object.assign({}, cleanProps(props), { type: type || `text`, placeholder: placeholder || undefined, autoComplete: autoComplete || undefined, name: name || nanoid(), multiple: type == 'file' ? multiple : undefined, accept: accept || `*`, className: `${as ? `${as} ` : ``}f ${cx(css `${_defaultCSS}${buildCSS(props)}&:hover {${buildCSS(props.hover || {})}} &:focus {${buildCSS(props.focus || {})}}`)}`, ref: _ref, value: value || undefined, defaultValue: defaultValue || ``, onKeyUp: (e) => {
612
- let k = e['keyCode'] || ['which'];
613
- if (form && onSubmit && El != 'textarea' && k == 13) {
614
- onSubmit(forms[form]);
615
- }
616
- else {
617
- if (onKeyUp)
618
- onKeyUp(e);
619
- }
620
- }, onChange: e => {
621
- let val = type == 'file' ?
622
- e.currentTarget.files
623
- : e.currentTarget.value;
624
- if (form)
625
- dispatch(dispatch(UPDATE_FORM_FIELD(form || 'orphan', name, val == "" ? null : val, forms)));
626
- // if(El == `textarea` && elastic) handleElastic()
627
- onChange && onChange(val == "" ? null : val);
628
- }, onClick: onClick ? onClick : () => { }, readOnly: readOnly || false, onBlur: e => {
629
- if (onBlur)
630
- onBlur(e);
631
- }, onFocus: e => {
632
- if (touched == false)
633
- dispatch(UPDATE_FORM_FIELD(form || 'orphan', `touched`, true, forms));
634
- if (onFocus)
635
- onFocus(e);
636
- } })) }));
637
- });
638
-
639
- const Select = forwardRef((props, ref) => {
640
- const { as, onChange, name, form, touched, options, defaultValue } = props;
641
- const _ref = useRef();
642
- const dispatch = useDispatch(STORE_FORM_KEY);
643
- const { forms } = useStore(state => state[STORE_FORM_KEY], false);
644
- const _defaultCSS = `width: 100%;border-radius: var(--radius-base);padding-left: 4px;padding-right: 4px;border-style: solid;border-width: 1px;border-color: var(--colors-gray-200);`;
645
- useEffect(() => {
646
- var _a;
647
- dispatch(dispatch(UPDATE_FORM_FIELD(form || 'orphan', name, defaultValue && defaultValue != null && defaultValue != "" && defaultValue != undefined ? defaultValue : ((_a = options[0]) === null || _a === void 0 ? void 0 : _a.value) || '-1', forms)));
648
- }, []);
649
- return (jsx(ClassNames, { children: ({ css, cx }) => jsx("select", { onChange: e => {
650
- let val = e.currentTarget.value;
651
- dispatch(dispatch(UPDATE_FORM_FIELD(form || 'orphan', name, val, forms)));
652
- onChange && onChange(val);
653
- }, onFocus: e => touched == false && dispatch(UPDATE_FORM_FIELD(form || 'orphan', `touched`, true, forms)), onBlur: e => {
654
- }, name: name || nanoid(), className: `${as ? as : ``} ${cx(css `${_defaultCSS}${buildCSS(props)}&:hover {${buildCSS(props.hover || {})}}`)}`, ref: _ref, children: options === null || options === void 0 ? void 0 : options.map(o => jsx("option", { value: o.value, children: o.label }, `select-${name}-option-${o.value}`)) }) }));
655
- });
656
-
657
- const useTheme = (mod = 'auto') => {
658
- const state = useContext(AppContext);
659
- return state['theme'] || {};
660
- };
661
-
662
- const removeBlankArrayElements = (a) => a.filter((x) => x);
663
- const stringToArray = (x) => (Array.isArray(x) ? x : [x]);
664
- const cache = {};
665
- // sequential map.find for promises
666
- const promiseFind = (arr, promiseFactory) => {
667
- let done = false;
668
- return new Promise((resolve, reject) => {
669
- const queueNext = (src) => {
670
- return promiseFactory(src).then(() => {
671
- done = true;
672
- resolve(src);
673
- });
674
- };
675
- arr
676
- .reduce((p, src) => {
677
- // ensure we aren't done before enqueuing the next source
678
- return p.catch(() => {
679
- if (!done)
680
- return queueNext(src);
681
- });
682
- }, queueNext(arr.shift()))
683
- .catch(reject);
684
- });
685
- };
686
- const useImage = ({ srcList, imgPromise = imgPromiseFactory({ decode: true }), useSuspense = true, }) => {
687
- const [, setIsSettled] = useState(false);
688
- const sourceList = removeBlankArrayElements(stringToArray(srcList));
689
- const sourceKey = sourceList.join('');
690
- if (!cache[sourceKey]) {
691
- // create promise to loop through sources and try to load one
692
- cache[sourceKey] = {
693
- promise: promiseFind(sourceList, imgPromise),
694
- cache: 'pending',
695
- error: null,
696
- };
697
- }
698
- // when promise resolves/reject, update cache & state
699
- if (cache[sourceKey].cache === 'resolved') {
700
- return { src: cache[sourceKey].src, isLoading: false, error: null };
701
- }
702
- if (cache[sourceKey].cache === 'rejected') {
703
- if (useSuspense)
704
- throw cache[sourceKey].error;
705
- return { isLoading: false, error: cache[sourceKey].error, src: undefined };
706
- }
707
- cache[sourceKey].promise
708
- // if a source was found, update cache
709
- // when not using suspense, update state to force a rerender
710
- .then((src) => {
711
- cache[sourceKey] = Object.assign(Object.assign({}, cache[sourceKey]), { cache: 'resolved', src });
712
- if (!useSuspense)
713
- setIsSettled(sourceKey);
714
- })
715
- // if no source was found, or if another error occurred, update cache
716
- // when not using suspense, update state to force a rerender
717
- .catch((error) => {
718
- cache[sourceKey] = Object.assign(Object.assign({}, cache[sourceKey]), { cache: 'rejected', error });
719
- if (!useSuspense)
720
- setIsSettled(sourceKey);
721
- });
722
- // cache[sourceKey].cache === 'pending')
723
- if (useSuspense)
724
- throw cache[sourceKey].promise;
725
- return { isLoading: true, src: undefined, error: null };
726
- };
727
-
728
- /** External Dependencies */
729
- const useResizeObserver = (onResized) => {
730
- const onResize = onResized ? onResized : () => { };
731
- const onResizeCallback = useRef(onResize);
732
- const resizeObserver = useRef();
733
- const observerCallback = useCallback((entries) => {
734
- entries.forEach((entry) => {
735
- if (entry.contentRect) {
736
- const { width, height } = entry.contentRect;
737
- onResizeCallback.current({
738
- entry,
739
- width,
740
- height,
741
- });
742
- }
743
- });
744
- }, []);
745
- const updateOnResizeCallback = useCallback((newOnResizeCallback) => {
746
- onResizeCallback.current = newOnResizeCallback;
747
- }, []);
748
- const initObserver = useCallback(() => {
749
- if (!resizeObserver.current) {
750
- resizeObserver.current = new ResizeObserver(observerCallback);
751
- }
752
- }, []);
753
- const observeElement = useCallback((element, newOnResizeCallback) => {
754
- if (element) {
755
- if (!resizeObserver.current) {
756
- initObserver();
757
- }
758
- resizeObserver.current.observe(element);
759
- if (newOnResizeCallback) {
760
- onResizeCallback.current = newOnResizeCallback;
761
- }
762
- }
763
- }, []);
764
- const unobserveElement = useCallback((element, newOnResizeCallback) => {
765
- if (resizeObserver.current && element) {
766
- resizeObserver.current.unobserve(element);
767
- if (newOnResizeCallback) {
768
- onResizeCallback.current = newOnResizeCallback;
769
- }
770
- }
771
- }, []);
772
- const removeObserver = useCallback(() => {
773
- if (resizeObserver.current) {
774
- resizeObserver.current.disconnect();
775
- }
776
- }, []);
777
- useEffect(() => {
778
- initObserver();
779
- return removeObserver;
780
- }, []);
781
- return useMemo(() => [observeElement, unobserveElement, updateOnResizeCallback], []);
782
- };
783
-
784
- const useChooseEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
785
-
786
- const EMPTY_BREAKPOINT = {
787
- breakpoint: undefined,
788
- minWidth: undefined,
789
- maxWidth: undefined,
790
- };
791
- const isBrowser = typeof window !== 'undefined';
792
- const useDevice = (config, defaultBreakpoint, hydrateInitial = true) => {
793
- const buildQueries = (breakpoints) => {
794
- const sorted = Object.keys(breakpoints).sort((a, b) => breakpoints[b] - breakpoints[a]);
795
- return sorted.map((breakpoint, index) => {
796
- let query = '';
797
- const minWidth = breakpoints[breakpoint];
798
- const nextBreakpoint = sorted[index - 1];
799
- const maxWidth = nextBreakpoint ? breakpoints[nextBreakpoint] : null;
800
- if (minWidth >= 0) {
801
- query = `(min-width: ${minWidth}px)`;
802
- }
803
- if (maxWidth !== null) {
804
- if (query) {
805
- query += ' and ';
806
- }
807
- query += `(max-width: ${maxWidth - 1}px)`;
808
- }
809
- const mediaQuery = {
810
- breakpoint,
811
- maxWidth: maxWidth ? maxWidth - 1 : null,
812
- minWidth,
813
- query,
814
- };
815
- return mediaQuery;
816
- });
817
- };
818
- /** Memoize list of calculated media queries from config */
819
- const mediaQueries = useMemo(() => buildQueries(config), [config]);
820
- /** Get initial breakpoint value */
821
- const [currentBreakpoint, setCurrentBreakpoint] = useState(() => {
822
- /** Loop through all media queries */
823
- for (let _a of mediaQueries) {
824
- const { query } = _a, breakpoint = __rest(_a, ["query"]);
825
- /**
826
- * If we're in the browser and there's no default value,
827
- * try to match actual breakpoint. If the default value
828
- * should not be hydrated, use the actual breakpoint.
829
- */
830
- if (typeof window !== 'undefined' &&
831
- !(defaultBreakpoint && hydrateInitial)) {
832
- const mediaQuery = window === null || window === void 0 ? void 0 : window.matchMedia(query);
833
- if (mediaQuery.matches) {
834
- return breakpoint;
835
- }
836
- }
837
- else if (breakpoint.breakpoint === defaultBreakpoint) {
838
- /** Otherwise, try to match default value */
839
- return breakpoint;
840
- }
841
- }
842
- return EMPTY_BREAKPOINT;
843
- });
844
- /** If there's a match, update the current breakpoint */
845
- const updateBreakpoint = useCallback(({ matches }, breakpoint) => {
846
- if (matches) {
847
- setCurrentBreakpoint(breakpoint);
848
- }
849
- }, []);
850
- /** On changes to mediaQueries, subscribe to changes using window.matchMedia */
851
- useChooseEffect(() => {
852
- if (isBrowser) {
853
- const unsubscribers = mediaQueries.map((_a) => {
854
- var { query } = _a, breakpoint = __rest(_a, ["query"]);
855
- const list = window.matchMedia(query);
856
- updateBreakpoint(list, breakpoint);
857
- const handleChange = (event) => {
858
- updateBreakpoint(event, breakpoint);
859
- };
860
- const supportsNewEventListeners = 'addEventListener' in list && 'removeEventListener' in list;
861
- if (supportsNewEventListeners) {
862
- list.addEventListener('change', handleChange);
863
- }
864
- else {
865
- list.addListener(handleChange);
866
- }
867
- /** Map the unsubscribers array to a list of unsubscriber methods */
868
- return () => {
869
- if (supportsNewEventListeners) {
870
- list.removeEventListener('change', handleChange);
871
- }
872
- else {
873
- list.removeListener(handleChange);
874
- }
875
- };
876
- });
877
- /** Return a function that when called, will call all unsubscribers */
878
- return () => unsubscribers.forEach((unsubscriber) => unsubscriber());
879
- }
880
- }, [mediaQueries, updateBreakpoint]);
881
- /** Print a nice debug value for React Devtools */
882
- useDebugValue(currentBreakpoint, (c) => typeof c.breakpoint === 'string'
883
- ? `${c.breakpoint} (${c.minWidth} ≤ x${c.maxWidth ? ` < ${c.maxWidth + 1}` : ''})`
884
- : '');
885
- return currentBreakpoint;
886
- };
887
-
888
- var _Toaster_container, _Toaster_startTop, _Toaster_tout, _Toaster_defaultTimeLeft, _Toaster_root;
889
- class Toaster {
890
- constructor(config) {
891
- _Toaster_container.set(this, void 0);
892
- _Toaster_startTop.set(this, void 0);
893
- _Toaster_tout.set(this, void 0);
894
- _Toaster_defaultTimeLeft.set(this, void 0);
895
- _Toaster_root.set(this, void 0);
896
- this.show = (message, duration) => {
897
- let self = this;
898
- self.toast({
899
- message: message,
900
- duration: duration
901
- });
902
- };
903
- __classPrivateFieldSet(this, _Toaster_startTop, 20, "f");
904
- __classPrivateFieldSet(this, _Toaster_defaultTimeLeft, 4, "f");
905
- const rootID = (config === null || config === void 0 ? void 0 : config.root) || `toast-container`;
906
- __classPrivateFieldSet(this, _Toaster_root, rootID, "f");
907
- this.addRoot();
908
- }
909
- addRoot() {
910
- if (window.document.querySelector(`#${__classPrivateFieldGet(this, _Toaster_root, "f")}`))
911
- return;
912
- var root = window.document.createElement('div');
913
- root.id = __classPrivateFieldGet(this, _Toaster_root, "f");
914
- window.document.body.appendChild(root);
915
- __classPrivateFieldSet(this, _Toaster_container, window.document.querySelector(`#${__classPrivateFieldGet(this, _Toaster_root, "f")}`), "f");
916
- }
917
- dismiss(ID) {
918
- let self = this;
919
- __classPrivateFieldGet(self, _Toaster_tout, "f") && clearTimeout(__classPrivateFieldGet(self, _Toaster_tout, "f"));
920
- setTimeout(() => {
921
- let tost = document.querySelector(`#${ID}`);
922
- tost && tost.classList.remove("visible");
923
- // tost && tost.classList.add("hidden");
924
- setTimeout(() => {
925
- try {
926
- document.getElementById(ID).parentNode.removeChild(document.getElementById(ID));
927
- }
928
- catch (e) { }
929
- self.arrangeToasts();
930
- }, 200);
931
- }, 200);
932
- }
933
- toast(config) {
934
- var self = this;
935
- self.addRoot();
936
- var ID = 'toast-' + nanoid(), toast = window.document.createElement('div'); window.document.createElement('div');
937
- toast.id = ID;
938
- toast.style.backgroundColor = `#111`;
939
- toast.style.color = `#fff`;
940
- toast.style.transform = `translate(-50%, -300px) scale(0.5)`;
941
- toast.style.position = `fixed`;
942
- toast.style.padding = `6px 12px`;
943
- toast.style.fontSize = `14px`;
944
- toast.style.left = `50%`;
945
- toast.style.maxWidth = `95%`;
946
- toast.style.zIndex = `2147483647`;
947
- toast.classList.add('zuz-toast');
948
- toast.classList.add('fixed');
949
- toast.classList.add('f');
950
- toast.innerHTML = config.message || `You haven't passed "message" in this toast`;
951
- (__classPrivateFieldGet(self, _Toaster_container, "f") || window.document.querySelector(`#${__classPrivateFieldGet(self, _Toaster_root, "f")}`)).appendChild(toast);
952
- self.arrangeToasts()
953
- .then(() => {
954
- setTimeout(() => {
955
- let tost = document.querySelector("#" + ID);
956
- tost.classList.add("showing");
957
- setTimeout(() => self.dismiss(ID), ((config === null || config === void 0 ? void 0 : config.duration) == undefined ? __classPrivateFieldGet(self, _Toaster_defaultTimeLeft, "f") : (config === null || config === void 0 ? void 0 : config.duration) == -1 ? 86400 : config === null || config === void 0 ? void 0 : config.duration) * 1000);
958
- setTimeout(() => {
959
- let tost = document.querySelector("#" + ID);
960
- tost.classList.remove("showing");
961
- tost.classList.add("visible");
962
- }, 200);
963
- }, 10);
964
- });
965
- }
966
- arrangeToasts() {
967
- var self = this, top = __classPrivateFieldGet(self, _Toaster_startTop, "f");
968
- return new Promise((resolve, reject) => {
969
- var toasts = document.querySelectorAll(".zuz-toast"), i = toasts.length;
970
- while (i--) {
971
- toasts[i]['style'].top = `${top}px`;
972
- top += parseInt(getComputedStyle(toasts[i]).height.replace('px', '')) + 6;
973
- }
974
- resolve(null);
975
- });
976
- }
977
- }
978
- _Toaster_container = new WeakMap(), _Toaster_startTop = new WeakMap(), _Toaster_tout = new WeakMap(), _Toaster_defaultTimeLeft = new WeakMap(), _Toaster_root = new WeakMap();
979
-
980
- const useToast = () => {
981
- const toaster = useMemo(() => new Toaster(), []);
982
- return toaster;
983
- };
984
-
985
- const useLang = (mod = 'en') => {
986
- const state = useContext(AppContext);
987
- return state['lang'] || {};
988
- };
989
-
990
- const Box = forwardRef((props, ref) => {
991
- const _noClick = () => { };
992
- // console.log(props)
993
- return (jsx(ClassNames, { children: ({ css, cx }) => jsx("div", Object.assign({}, cleanProps(props), { title: props.title || undefined, id: props.id || undefined, onDoubleClick: props.onDoubleClick || undefined, onClick: props.onClick || _noClick, className: `${props.as ? `${props.as} ` : ``}${cx(css `${buildCSS(props)} &:hover {${buildCSS(props.hover || {})}} &:active {${buildCSS(props.active || {})}}`)}`, ref: props.bref || ref, children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children })) }));
994
- });
995
-
996
- const Menu = ({ ID, hide, e, items, width }) => {
997
- const nodeRef = useRef(null);
998
- const [p, setP] = useState(getMousePosition(e));
999
- const [visible, setVisible] = useState(false);
1000
- const checkBoundaries = (x, y) => {
1001
- if (nodeRef.current) {
1002
- const { innerWidth, innerHeight } = window;
1003
- const { offsetWidth, offsetHeight } = nodeRef.current;
1004
- if (x + offsetWidth > innerWidth)
1005
- x -= offsetWidth; //x + offsetWidth - innerWidth;
1006
- if (y + offsetHeight > innerHeight)
1007
- y -= offsetHeight;
1008
- }
1009
- setP({ x, y });
1010
- setVisible(true);
1011
- };
1012
- useEffect(() => {
1013
- checkBoundaries(p.x, p.y);
1014
- }, [e]);
1015
- return (jsx(Box, { bref: nodeRef, flex: true, dir: `cols`, fixed: true, top: p.y, left: p.x, w: width || 220, opacity: visible ? 1 : 0, as: `zuz-contextmenu ${ID}`, children: items.map((m, i) => m.id == `line` ? jsx(Box, { as: `line` }, `line-${i}-${m.id}`) : jsx("button", { onClick: ev => {
1016
- if (m.onClick) {
1017
- m.onClick(ev, m);
1018
- }
1019
- else {
1020
- console.log(`No onClick eventFound`);
1021
- }
1022
- hide();
1023
- }, children: m.label }, `cm-${i}-${m.id}`)) }));
1024
- };
1025
- const useContextMenu = (contextID, contextWidth, contextToken = `____uchides`) => {
1026
- const ID = `contextmenu-${contextID}`;
1027
- useState(false);
1028
- const [root, setRoot] = useState(null);
1029
- const el = (e) => window.document.createElement(e);
1030
- const createRoot = () => {
1031
- if (!window.document.querySelector(`#${ID}`)) {
1032
- let div = el(`div`);
1033
- div.id = ID;
1034
- window.document.body.appendChild(div);
1035
- }
1036
- };
1037
- const hideAll = () => {
1038
- if (window[contextToken]) {
1039
- window[contextToken].map((h) => h['ID'] != ID && h['fnc']());
1040
- }
1041
- };
1042
- const _hide = () => {
1043
- try {
1044
- root === null || root === void 0 ? void 0 : root.unmount();
1045
- document.querySelector(`#${ID}`).parentNode.removeChild(document.querySelector(`#${ID}`));
1046
- setRoot(null);
1047
- }
1048
- catch (e) { }
1049
- };
1050
- const hide = () => {
1051
- _hide();
1052
- hideAll();
1053
- };
1054
- const show = (e, items) => {
1055
- e.preventDefault();
1056
- e.stopPropagation();
1057
- hideAll();
1058
- root.render(jsx(Menu, { e: e, width: contextWidth || 220, items: items, ID: ID, hide: hide }));
1059
- };
1060
- useEffect(() => {
1061
- createRoot();
1062
- if (!root)
1063
- setRoot(ReactDOM.createRoot(document.getElementById(ID)));
1064
- }, [root]);
1065
- useEffect(() => {
1066
- if (contextToken in window == false) {
1067
- window[contextToken] = [];
1068
- }
1069
- if (window[contextToken].findIndex(x => x.ID == ID) == -1) {
1070
- window[contextToken].push({ ID: ID, fnc: _hide });
1071
- if (window[contextToken].length > document.querySelectorAll('div[id^="contextmenu-"]').length) {
1072
- window[contextToken].shift();
1073
- }
1074
- }
1075
- }, []);
1076
- return {
1077
- show,
1078
- hide,
1079
- hideAll
1080
- };
1081
- };
1082
-
1083
- const useRender = (isMounted, delay) => {
1084
- const [canRender, setCanRender] = useState(false);
1085
- // console.log(
1086
- // `isMounted:`, isMounted,
1087
- // `canRender:`, canRender,
1088
- // )
1089
- useEffect(() => {
1090
- let outID;
1091
- if (isMounted && !canRender) {
1092
- setCanRender(true);
1093
- }
1094
- else if (isMounted && canRender) {
1095
- outID = setTimeout(() => setCanRender(false), delay * 1000);
1096
- }
1097
- return () => clearTimeout(outID);
1098
- }, [isMounted, delay]);
1099
- return canRender;
1100
- };
1101
-
1102
- const Button = forwardRef((props, ref) => {
1103
- const { forms } = useStore(state => state[STORE_FORM_KEY], false);
1104
- if (props.html) {
1105
- ({ __html: props.html });
1106
- }
1107
- return (jsx(ClassNames, { children: ({ css, cx }) => {
1108
- return (jsx("button", Object.assign({}, cleanProps(props), { title: "title" in props ? props.title : undefined, type: props.type, className: `button${props.as ? ` ${props.as}` : ``} ${cx(css `
1109
- padding: 5px 10px;
1110
- border-radius: 2px;
1111
- ${buildCSS(props)} &:hover {${buildCSS(props.hover || {})}} &:active {${buildCSS(props.active || {})}}`)}`, ref: ref, onDoubleClick: props.onDoubleClick || undefined, onClick: e => {
1112
- if (props.form && props.type && props.type == 'submit') {
1113
- props.onSubmit(forms[props.form]);
1114
- }
1115
- else {
1116
- props.onClick ? props.onClick(e) : () => console.warn('onClick Missing');
1117
- }
1118
- }, disabled: props.disabled || false, children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children })));
1119
- } }));
1120
- });
1121
-
1122
- const patterns = {
1123
- route: [/^.*\/src\/pages\/|\.(jsx|tsx)$/g, ''],
1124
- splat: [/\[\.{3}\w+\]/g, '*'],
1125
- param: [/\[([^\]]+)\]/g, ':$1'],
1126
- slash: [/^index$|\./g, '/'],
1127
- optional: [/^-(:?[\w-]+)/, '$1?'],
1128
- };
1129
- const generatePreservedRoutes = (files) => {
1130
- return Object.keys(files).reduce((routes, key) => {
1131
- const path = key.replace(...patterns.route);
1132
- return Object.assign(Object.assign({}, routes), { [path]: files[key] });
1133
- }, {});
1134
- };
1135
- const generateRegularRoutes = (files, buildRoute) => {
1136
- const filteredRoutes = Object.keys(files).filter((key) => !key.includes('/_') || /_layout\.(jsx|tsx)$/.test(key));
1137
- return filteredRoutes.reduce((routes, key) => {
1138
- const module = files[key];
1139
- const route = Object.assign({ id: key.replace(...patterns.route) }, buildRoute(module, key));
1140
- const segments = key
1141
- .replace(...patterns.route)
1142
- .replace(...patterns.splat)
1143
- .replace(...patterns.param)
1144
- .split('/')
1145
- .filter(Boolean);
1146
- segments.reduce((parent, segment, index) => {
1147
- var _a, _b;
1148
- const path = segment.replace(...patterns.slash).replace(...patterns.optional);
1149
- const root = index === 0;
1150
- const leaf = index === segments.length - 1 && segments.length > 1;
1151
- const node = !root && !leaf;
1152
- const layout = segment === '_layout';
1153
- const group = /\(\w+\)/.test(path);
1154
- const insert = /^\w|\//.test(path) ? 'unshift' : 'push';
1155
- if (root) {
1156
- const last = segments.length === 1;
1157
- if (last) {
1158
- routes.push(Object.assign({ path }, route));
1159
- return parent;
1160
- }
1161
- }
1162
- if (root || node) {
1163
- const current = root ? routes : parent.children;
1164
- const found = current === null || current === void 0 ? void 0 : current.find((route) => { var _a, _b; return route.path === path || ((_b = (_a = route.id) === null || _a === void 0 ? void 0 : _a.split('@')) === null || _b === void 0 ? void 0 : _b[0]) === path; });
1165
- const props = group ? ((route === null || route === void 0 ? void 0 : route.component) ? { id: path, path: '/' } : { id: path }) : { path };
1166
- if (found)
1167
- (_a = found.children) !== null && _a !== void 0 ? _a : (found.children = []);
1168
- else
1169
- current === null || current === void 0 ? void 0 : current[insert](Object.assign(Object.assign({}, props), { children: [] }));
1170
- return found || (current === null || current === void 0 ? void 0 : current[insert === 'unshift' ? 0 : current.length - 1]);
1171
- }
1172
- if (layout) {
1173
- return Object.assign(parent, Object.assign(Object.assign({}, route), { id: `${parent.id || parent.path}@${route.id}` }));
1174
- }
1175
- if (leaf) {
1176
- (_b = parent === null || parent === void 0 ? void 0 : parent.children) === null || _b === void 0 ? void 0 : _b[insert]((route === null || route === void 0 ? void 0 : route.index) ? route : Object.assign({ path }, route));
1177
- }
1178
- return parent;
1179
- }, {});
1180
- return routes;
1181
- }, []);
1182
- };
1183
- const generateModalRoutes = (files) => {
1184
- return Object.keys(files).reduce((modals, key) => {
1185
- var _a;
1186
- const path = key
1187
- .replace(...patterns.route)
1188
- .replace(/\+|\(\w+\)\//g, '')
1189
- .replace(/(\/)?index/g, '')
1190
- .replace(/\./g, '/');
1191
- return Object.assign(Object.assign({}, modals), { [`/${path}`]: (_a = files[key]) === null || _a === void 0 ? void 0 : _a.default });
1192
- }, {});
1193
- };
1194
-
1195
- const makeCSSValue = (k, v, o) => {
1196
- let ignore = cssPropsIgnore.indexOf(o) == -1;
1197
- if (k in cssPropsDirect && ignore == true) {
1198
- // return cssPropsDirect[k];
1199
- return cssPropsDirect[k].indexOf(`__VALUE__`) > -1 ?
1200
- cssPropsDirect[k].replaceAll(`__VALUE__`, `${v}${"number" == typeof v ? `px` : ``}`)
1201
- : cssPropsDirect[k];
1202
- }
1203
- let unit = "number" == typeof v && ignore ? `px` : ``;
1204
- if (cssColors.indexOf(v) > -1) {
1205
- v = `var(--colors-${v.replaceAll(`.`, `-`)})`;
1206
- unit = ``;
1207
- }
1208
- else if (v in cssPropsVals) {
1209
- v = cssPropsVals[v];
1210
- }
1211
- return `${k}:${v}${unit};`;
1212
- };
1213
- const cleanProps = (props) => {
1214
- let _props = Object.assign({}, props);
1215
- Object.keys(_props).map(k => {
1216
- if (k in cssProps) {
1217
- delete _props[k];
1218
- }
1219
- });
1220
- let _extras = [`as`, `hover`, `bref`, `tag`];
1221
- _extras.map(x => x in _props && delete _props[x]);
1222
- return _props;
1223
- };
1224
- const buildCSS = (props) => {
1225
- let css = ``;
1226
- Object.keys(props).map(k => {
1227
- css += k in cssProps ? makeCSSValue(cssProps[k], props[k], k) : '';
1228
- });
1229
- return css;
1230
- };
1231
- const setCSSVar = (key, val) => {
1232
- document.documentElement.style.setProperty(`--${key}`, val);
1233
- };
1234
- const isUrl = (u) => {
1235
- let url;
1236
- try {
1237
- url = new URL(u);
1238
- }
1239
- catch (_) {
1240
- return false;
1241
- }
1242
- return url.protocol === 'http:' || url.protocol === 'https:';
1243
- };
1244
- const isEmail = (e) => {
1245
- let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
1246
- return reg.test(e);
1247
- };
1248
- const isIPv4 = (ipaddress) => {
1249
- return /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress);
1250
- };
1251
- const randstr = function (len) {
1252
- var text = "";
1253
- var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
1254
- len = len || 10;
1255
- for (var i = 0; i < len; i++) {
1256
- text += possible.charAt(Math.floor(Math.random() * possible.length));
1257
- }
1258
- return text;
1259
- };
1260
- const setCookie = (key, value, expiry, host) => Cookies.set(key, value, { expires: expiry || 7, domain: host || window.location.host });
1261
- const getCookie = (key) => Cookies.get(key) || null;
1262
- const removeCookie = (key) => Cookies.remove(key);
1263
- const buildFormData = (data) => {
1264
- var formData = new FormData();
1265
- var _data = Cookies.get();
1266
- Object.keys(_data).map(k => formData.append(k, _data[k]));
1267
- Object.keys(data).filter(x => x != 'files').map(k => formData.append(k, data[k]));
1268
- if ('files' in data)
1269
- [data['files']].map((f) => formData.append('files[]', f));
1270
- return formData;
1271
- };
1272
- const withRest = async (uri, data, timeout = 60, fd = null, progress, bearer = `__ha`) => {
1273
- var Bearer = getCookie(bearer) || `${randstr(8)}^${randstr(8)}`;
1274
- window['__grabToken'] = axios.CancelToken.source();
1275
- if (fd) {
1276
- return new Promise((resolve, reject) => {
1277
- axios({
1278
- method: "post",
1279
- url: uri,
1280
- data: buildFormData(data),
1281
- timeout: 1000 * timeout,
1282
- cancelToken: window['__grabToken'].token,
1283
- headers: {
1284
- 'Content-Type': 'multipart/form-data',
1285
- 'Authorization': `Bearer ${Bearer}`
1286
- },
1287
- onUploadProgress: ev => {
1288
- //TODO: Add progress
1289
- // if(progress) progress(ev.)
1290
- }
1291
- })
1292
- .then(resp => {
1293
- if (resp.data && "kind" in resp.data) {
1294
- resolve(resp.data);
1295
- }
1296
- else {
1297
- reject(resp.data);
1298
- }
1299
- })
1300
- .catch(err => reject(err));
1301
- });
1302
- }
1303
- return new Promise((resolve, reject) => {
1304
- axios.post(uri, Object.assign(Object.assign(Object.assign({}, Cookies.get()), data), { __ustmp: new Date().getTime() / 1000 }), {
1305
- timeout: 1000 * timeout,
1306
- headers: {
1307
- 'Content-Type': 'application/json',
1308
- 'Authorization': `Bearer ${Bearer}`
1309
- },
1310
- cancelToken: window['__grabToken'].token
1311
- })
1312
- .then(resp => {
1313
- if (resp.data && "kind" in resp.data) {
1314
- resolve(resp.data);
1315
- }
1316
- else {
1317
- reject(resp.data);
1318
- }
1319
- })
1320
- .catch(err => reject(err));
1321
- });
1322
- };
1323
- const el = (e) => document.querySelector(e);
1324
- const byName = (e) => document.querySelector(`*[name="${e}"]`);
1325
- const byId = (e) => document.getElementById(e);
1326
- const addProps = (children, prop) => {
1327
- let form = {};
1328
- let allowedFields = [Input, Select, Button];
1329
- let child = Children.deepMap(children, c => {
1330
- if (allowedFields.indexOf(c['type']) > -1 && c['props'] && !form[c['props'].name]) {
1331
- form[c['props'].name] = c['props'].value || null;
1332
- }
1333
- let Clone = cloneElement(c, prop);
1334
- return Clone;
1335
- });
1336
- return {
1337
- children: child,
1338
- fields: form
1339
- };
1340
- };
1341
- const ucfirst = (str) => {
1342
- return str.charAt(0).toUpperCase() + str.slice(1);
1343
- };
1344
- const filterStyleProps = (props) => {
1345
- const pks = Object.keys(props);
1346
- const css = Object.keys(cssProps);
1347
- let filter = {};
1348
- css.filter(x => pks.includes(x));
1349
- // .map(k => filter[k] = props[k].toString());
1350
- return filter;
1351
- // const allowed = Object.keys(props);
1352
- // let allowed = Object.keys(cssProps);
1353
- // return Object.keys(props)
1354
- // .filter( k => allowed.includes(k))
1355
- // .reduce( (o, k) => {
1356
- // // console.log(o)
1357
- // console.log(k, props[k])
1358
- // // o[k] = props[k].toString();
1359
- // // return o;
1360
- // })
1361
- // return [props].filter( row => (
1362
- // Object.keys(row)
1363
- // .map(key => css.includes(key))
1364
- // ));
1365
- };
1366
- const filterHTMLProps = (props) => {
1367
- const pks = Object.keys(props);
1368
- const css = Object.keys(cssProps);
1369
- let filter = {};
1370
- pks.filter(x => {
1371
- if (x != `for` && !css.includes(x)) {
1372
- filter[x] = props[x];
1373
- }
1374
- });
1375
- return filter;
1376
- };
1377
- const uuid = (len = 21) => nanoid(len);
1378
- const addScript = (src, callback) => {
1379
- var s = document.createElement('script');
1380
- s.setAttribute('src', src);
1381
- s.addEventListener('load', callback, false);
1382
- document.body.appendChild(s);
1383
- };
1384
- const shuffleArray = array => {
1385
- for (let i = array.length - 1; i > 0; i--) {
1386
- const j = Math.floor(Math.random() * (i + 1));
1387
- [array[i], array[j]] = [array[j], array[i]];
1388
- }
1389
- return array;
1390
- };
1391
- const getUriParams = () => {
1392
- var search = location.search.substring(1);
1393
- if (search == '')
1394
- return JSON.parse('{}');
1395
- var xny = {};
1396
- if ("URLSearchParams" in window) {
1397
- var items = new URLSearchParams(search);
1398
- for (const [k, v] of items) {
1399
- xny[k] = v || ``;
1400
- }
1401
- }
1402
- else {
1403
- try {
1404
- xny = JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');
1405
- }
1406
- catch (e) {
1407
- xny = {};
1408
- }
1409
- }
1410
- return xny;
1411
- };
1412
- const rgb2hex = rgb => `#${rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/).slice(1).map(n => parseInt(n, 10).toString(16).padStart(2, '0')).join('')}`;
1413
- const getHostname = url => {
1414
- if (window.URL) {
1415
- let u = new window.URL(url);
1416
- return u.hostname;
1417
- }
1418
- else {
1419
- var a = document.createElement(`a`);
1420
- a.href = url;
1421
- return a.hostname.replace("www.", "");
1422
- }
1423
- };
1424
- const imgPromiseFactory = ({ decode = true, crossOrigin = '' }) => (src) => {
1425
- return new Promise((resolve, reject) => {
1426
- const i = new Image();
1427
- if (crossOrigin)
1428
- i.crossOrigin = crossOrigin;
1429
- i.onload = () => {
1430
- decode && i.decode ? i.decode().then(resolve).catch(reject) : resolve();
1431
- };
1432
- i.onerror = reject;
1433
- i.src = src;
1434
- });
1435
- };
1436
- const parseFilename = nm => {
1437
- var re = /(?:\.([^.]+))?$/;
1438
- return {
1439
- name: nm.split('.').slice(0, -1).join('.'),
1440
- ext: re.exec(nm)[1]
1441
- };
1442
- };
1443
- const camelCase = str => str.replace(":", "-").replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
1444
- const getMousePosition = e => {
1445
- const pos = {
1446
- x: e.clientX,
1447
- y: e.clientY,
1448
- };
1449
- const touch = e.changedTouches;
1450
- if (touch) {
1451
- pos.x = touch[0].clientX;
1452
- pos.y = touch[0].clientY;
1453
- }
1454
- if (!pos.x || pos.x < 0)
1455
- pos.x = 0;
1456
- if (!pos.y || pos.y < 0)
1457
- pos.y = 0;
1458
- return pos;
1459
- };
1460
- const copyToClipboard = (str, callback) => {
1461
- const el = document.createElement('textarea');
1462
- let storeContentEditable = el.contentEditable;
1463
- let storeReadOnly = el.readOnly;
1464
- el.value = str;
1465
- el.contentEditable = `true`;
1466
- el.readOnly = false;
1467
- el.setAttribute('readonly', `false`);
1468
- el.setAttribute('contenteditable', `true`);
1469
- el.style.position = 'absolute';
1470
- el.style.left = '-999999999px';
1471
- document.body.appendChild(el);
1472
- const selected = document.getSelection().rangeCount > 0
1473
- ? document.getSelection().getRangeAt(0)
1474
- : false;
1475
- el.select();
1476
- el.setSelectionRange(0, 999999);
1477
- document.execCommand('copy');
1478
- document.body.removeChild(el);
1479
- if (selected) {
1480
- document.getSelection().removeAllRanges();
1481
- document.getSelection().addRange(selected);
1482
- }
1483
- el.contentEditable = storeContentEditable;
1484
- el.readOnly = storeReadOnly;
1485
- if (callback)
1486
- callback();
1487
- };
1488
- /**
1489
- * Format bytes as human-readable text.
1490
- *
1491
- * @param bytes Number of bytes.
1492
- * @param si True to use metric (SI) units, aka powers of 1000. False to use
1493
- * binary (IEC), aka powers of 1024.
1494
- * @param dp Number of decimal places to display.
1495
- *
1496
- * @return Formatted string.
1497
- */
1498
- const formatSize = (bytes, si = false, dp = 1) => {
1499
- const thresh = si ? 1000 : 1024;
1500
- if (Math.abs(bytes) < thresh) {
1501
- return bytes + ' B';
1502
- }
1503
- const units = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
1504
- let u = -1;
1505
- const r = 10 ** dp;
1506
- do {
1507
- bytes /= thresh;
1508
- ++u;
1509
- } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
1510
- return bytes.toFixed(dp) + ' ' + units[u];
1511
- };
1512
- const slugify = (...args) => {
1513
- const value = args.join(' ');
1514
- return value
1515
- .normalize('NFD') // split an accented letter in the base letter and the acent
1516
- .replace(/[\u0300-\u036f]/g, '') // remove all previously split accents
1517
- .toLowerCase()
1518
- .trim()
1519
- .replace(/[^a-z0-9 ]/g, '') // remove all chars not letters, numbers and spaces (to be replaced)
1520
- .replace(/\s+/g, '-'); // separator
1521
- };
1522
-
1523
- const AppMain = forwardRef((props, ref) => {
1524
- // const { dispatch } = useStore()
1525
- // if("theme" in props && !theme){
1526
- // dispatch(setTheme(props.theme));
1527
- // }
1528
- return (jsx(ClassNames, { children: ({ css, cx }) => jsx("main", { className: `${props.as ? props.as : `zuz-app`} ${cx(css `${buildCSS(props)} &:hover {${buildCSS(props.hover || {})}} &:active {${buildCSS(props.active || {})}}`)}`, children: props.children }) }));
1529
- });
1530
- const App = forwardRef((props, ref) => {
1531
- return (jsx(AppProvider, { children: jsx(AppMain, {}) }));
1532
- });
1533
-
1534
- // const CoreBlock = styled.section`display: block;`
1535
- // const buildComponent = (props: any) => Block.withComponent(props.for || `div`)`${buildCSS(props)}`
1536
- const Component = forwardRef((props, ref) => {
1537
- const Tag = props.for;
1538
- const Block = (typeof props.for == 'string' ?
1539
- styled[props.for || `div`] : Tag) `${buildCSS(props)}`;
1540
- // const Block = styled.`${buildCSS(props)}`;
1541
- // const Block = CoreBlock.withComponent(props.for)`background: red`
1542
- // console.log(props)
1543
- // console.log(Styles)
1544
- // return <button>{props.children}</button>
1545
- return jsx(Block, Object.assign({ className: props.as || `` }, filterHTMLProps(props)));
1546
- });
1547
-
1548
- function Checkbox(props) {
1549
- const { checked, as, name, form, touched, onChange } = props;
1550
- const [_checked, setChecked] = useState(checked || false);
1551
- const theme = useTheme();
1552
- const dispatch = useDispatch(STORE_FORM_KEY);
1553
- const { forms } = useStore(state => state[STORE_FORM_KEY], false);
1554
- const switchCheck = useCallback(() => {
1555
- let nextVal = !_checked;
1556
- onChange && onChange(nextVal);
1557
- setChecked(nextVal);
1558
- dispatch(dispatch(UPDATE_FORM_FIELD(form || 'orphan', name, nextVal, forms)));
1559
- }, [_checked]);
1560
- const defaultCSS = `cursor: pointer;&:before {
1561
- background: ${!_checked ? `transparent` : theme.color} !important;
1562
- }`;
1563
- const _name = useMemo(() => name || nanoid(), [name]);
1564
- return (jsx(ClassNames, { children: ({ css, cx }) => jsxs(Fragment, { children: [jsx("input", { onChange: switchCheck, id: `zuz${_name}`,
1565
- // className={`${_checked ? 'y' : 'n'} ${as ? ` ${as} ` : ``}f ${cx(css`opacity: 0;position: absolute;&:checked {${defaultCSSChecked}}`)}`}
1566
- className: `zuz-checkbox`, name: _name, type: `checkbox`, value: `checked` }), jsx("label", { className: `${as ? `${as} ` : ``}f ${cx(css `${defaultCSS}`)}`, htmlFor: `zuz${_name}` })] }) })
1567
- // <Button
1568
- // overflow={`hidden`}
1569
- // name={name || nanoid()}
1570
- // onClick={switchCheck}
1571
- // w={38} h={22} r={20} bg={`#ddd`} rel>
1572
- // <Box w={38} h={22} anim={`0.2`} abs top={0} r={20} left={0} transform={`translateX(${_checked ? 0 : -16}px)`} bg={theme.color}>
1573
- // <Box w={18} h={18} abs right={2} top={2} bg={`#fff`} r={20} boxShadow={`0px 0px 0px 5px ${_checked ? theme.color : `#ddd`}`} />
1574
- // </Box>
1575
- // </Button>
1576
- );
1577
- }
1578
-
1579
- const Spinner = (props) => {
1580
- return (jsxs(Box, { rel: true, w: props.size, h: props.size, zIndex: `1`, useSelect: `none`, children: [jsx(Box, { abs: true, as: `spinner rotating`, animationDirection: `reverse`, animationDuration: typeof props.s1 == `string` ? props.s1 : `${props.s1}s`, w: props.size, r: props.radius, h: props.size, bg: props.color, opacity: 0.2 }), jsx(Box, { abs: true, as: `spinner rotating`, animationDuration: typeof props.s2 == `string` ? props.s2 : `${props.s2}s`, w: props.size, r: props.radius, h: props.size, bg: props.color, opacity: 0.5 })] }));
1581
- };
1582
- Spinner.defaultProps = {
1583
- size: 30,
1584
- radius: 4,
1585
- color: `black`,
1586
- s1: `5s`,
1587
- s2: `1s`
1588
- };
1589
- Spinner.propTypes = {
1590
- size: PropTypes.number.isRequired,
1591
- color: PropTypes.string,
1592
- radius: PropTypes.number,
1593
- s1: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
1594
- s2: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
1595
- };
1596
-
1597
- const Heading = forwardRef((props, ref) => {
1598
- const { children, as, h } = props;
1599
- let Tag = `h${h || 1}`;
1600
- const HeadingTag = Tag;
1601
- return (jsx(ClassNames, { children: ({ css, cx }) => jsx(HeadingTag, { className: `${as ? `${as} ` : ``}${cx(css `${buildCSS(props)}`)}`, ref: ref, children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : children }) }));
1602
- });
1603
-
1604
- const Cover = (props) => {
1605
- return (jsx(Box, { abs: true, fill: true, bgFilter: props.backdrop ? `saturate(${props.backdrop.saturate}%) blur(${props.backdrop.blur}px)` : undefined, zIndex: `2`, bg: props.bg, children: jsxs(Box, { abs: true, abc: true, aic: true, jcc: true, flex: true, dir: `cols`, gap: 20, children: [jsx(Spinner, {}, `cover-spinner`), props.label && jsx(Heading, { size: 16, as: `f`, opacity: 0.7, children: props.label }, `cover-label`)] }, `cover-shadow`) }, `cover-cloud`));
1606
- };
1607
- Cover.defaultProps = {
1608
- bg: `rgba(0,0,0,0.5)`,
1609
- backdrop: { saturate: 80, blur: 10 },
1610
- label: null
1611
- };
1612
- Cover.propTypes = {
1613
- bg: PropTypes.string,
1614
- backdrop: PropTypes.object,
1615
- label: PropTypes.string,
1616
- };
1617
-
1618
- const Form = forwardRef((props, ref) => {
1619
- var _a;
1620
- const { name, children, onSubmit, cover, debug } = props;
1621
- const [_html, setHTML] = useState(null);
1622
- const [_loading, setLoading] = useState((debug === null || debug === void 0 ? void 0 : debug.loading) || false);
1623
- const dispatch = useDispatch(STORE_FORM_KEY);
1624
- const { forms } = useStore(state => state[STORE_FORM_KEY], false);
1625
- const buildFields = () => {
1626
- return addProps(children, { form: name, touched: undefined, loading: undefined, onSubmit: onSubmit ? onSubmit : () => console.log(`onSubmit Missing`) });
1627
- };
1628
- const update = (e) => Object.keys(e).map(k => {
1629
- dispatch(UPDATE_FORM_FIELD(name || 'orphan', k, e[k], forms));
1630
- if (k == 'loading')
1631
- setLoading(e[k]);
1632
- });
1633
- const get = (k) => forms[name][k] || null;
1634
- useImperativeHandle(ref, () => ({
1635
- update,
1636
- get
1637
- }));
1638
- useEffect(() => {
1639
- let f = buildFields();
1640
- setHTML(f.children);
1641
- if (!forms[name]) {
1642
- dispatch(ADD_FORM(name, f.fields, forms));
1643
- }
1644
- }, [children, (_a = forms[name]) === null || _a === void 0 ? void 0 : _a.loading]);
1645
- return createElement(Box, Object.assign(Object.assign({ rel: true }, props), { as: name }), [
1646
- _loading ? jsx(Cover, { backdrop: (cover === null || cover === void 0 ? void 0 : cover.filter) || { saturate: 80, blur: 10 }, bg: (cover === null || cover === void 0 ? void 0 : cover.bg) || `rgba(0,0,0,0.5)` }, `form-${name}-cover`) : null,
1647
- _html
1648
- ]);
1649
- });
1650
- Form.defaultProps = {
1651
- name: 'form1',
1652
- onSubmit: () => { console.log(`onSubmit not provided`); }
1653
- };
1654
- Form.propTypes = {
1655
- name: PropTypes.string.isRequired,
1656
- children: PropTypes.node.isRequired,
1657
- onSubmit: PropTypes.func.isRequired
1658
- };
1659
-
1660
- const Icon = forwardRef((props, ref) => {
1661
- const { as, path, size, color, hover } = props;
1662
- return (jsx(Box, { hover: hover || {}, flex: true, bref: ref, as: `icon-${as}`, ai: `c`, jc: `c`, size: size || 24, color: color || `#111111`, children: path && Array(path).fill(undefined).map((p, i) => jsx("span", { className: `path${i + 1}` }, `ico-${as}-${i}`)) }));
1663
- });
1664
-
1665
- const Image$1 = forwardRef((props, ref) => {
1666
- const { src, isLoading, error } = useImage({ srcList: props.src, useSuspense: false });
1667
- return (jsx(ClassNames, { children: ({ css, cx }) => jsxs(Fragment, { children: [isLoading && jsx(Box, { className: `${props.as ? `${props.as} ` : ``}${cx(css `background: #eee;${buildCSS(props)}`)}` }), !isLoading && jsx("img", { src: src, className: `${props.as ? `${props.as} ` : ``}${cx(css `${buildCSS(props)}`)}`, ref: ref })] }) })
1668
- // <ClassNames>
1669
- // {({ css, cx }) => <picture className={cx(css`${buildCSS({ flex: true })}`)}>
1670
- // {status == 'loading' && <Box className={`${props.as ? `${props.as} ` : ``}${cx(css`background: #eee;${buildCSS(props)}`)}`} />}
1671
- // {status == 'loaded' && <img src={props.src}
1672
- // className={`${props.as ? `${props.as} ` : ``}${cx(css`${buildCSS(props)}`)}`}
1673
- // ref={ref} />}
1674
- // </picture>}
1675
- // </ClassNames>
1676
- );
1677
- });
1678
-
1679
- const DEFAULT_COLUMNS = 2;
1680
- class Masonry extends Component$1 {
1681
- constructor(props) {
1682
- super(props);
1683
- this._lastRecalculateAnimationFrame = window.requestAnimationFrame(() => {
1684
- this.reCalculateColumnCount();
1685
- });
1686
- // Correct scope for when methods are accessed externally
1687
- this.reCalculateColumnCount = this.reCalculateColumnCount.bind(this);
1688
- this.reCalculateColumnCountDebounce = this.reCalculateColumnCountDebounce.bind(this);
1689
- // default state
1690
- let columnCount;
1691
- if (this.props && this.props.breakpointCols.default) {
1692
- columnCount = this.props.breakpointCols.default;
1693
- }
1694
- else {
1695
- columnCount = parseInt(this.props.breakpointCols) || DEFAULT_COLUMNS;
1696
- }
1697
- this.state = {
1698
- columnCount
1699
- };
1700
- }
1701
- componentDidMount() {
1702
- this.reCalculateColumnCount();
1703
- // window may not be available in some environments
1704
- if (window) {
1705
- window.addEventListener('resize', this.reCalculateColumnCountDebounce);
1706
- }
1707
- }
1708
- componentDidUpdate() {
1709
- this.reCalculateColumnCount();
1710
- }
1711
- componentWillUnmount() {
1712
- if (window) {
1713
- window.removeEventListener('resize', this.reCalculateColumnCountDebounce);
1714
- }
1715
- }
1716
- reCalculateColumnCountDebounce() {
1717
- if (!window || !window.requestAnimationFrame) { // IE10+
1718
- this.reCalculateColumnCount();
1719
- return;
1720
- }
1721
- if (window.cancelAnimationFrame) { // IE10+
1722
- window.cancelAnimationFrame(this._lastRecalculateAnimationFrame);
1723
- }
1724
- }
1725
- reCalculateColumnCount() {
1726
- const windowWidth = window && window.innerWidth || Infinity;
1727
- let breakpointColsObject = this.props.breakpointCols;
1728
- // Allow passing a single number to `breakpointCols` instead of an object
1729
- if (typeof breakpointColsObject !== 'object') {
1730
- breakpointColsObject = {
1731
- default: parseInt(breakpointColsObject) || DEFAULT_COLUMNS
1732
- };
1733
- }
1734
- let matchedBreakpoint = Infinity;
1735
- let columns = breakpointColsObject.default || DEFAULT_COLUMNS;
1736
- for (let breakpoint in breakpointColsObject) {
1737
- const optBreakpoint = parseInt(breakpoint);
1738
- const isCurrentBreakpoint = optBreakpoint > 0 && windowWidth <= optBreakpoint;
1739
- if (isCurrentBreakpoint && optBreakpoint < matchedBreakpoint) {
1740
- matchedBreakpoint = optBreakpoint;
1741
- columns = breakpointColsObject[breakpoint];
1742
- }
1743
- }
1744
- columns = Math.max(1, parseInt(columns) || 1);
1745
- if (this.state.columnCount !== columns) {
1746
- this.setState({
1747
- columnCount: columns
1748
- });
1749
- this.props.onChange && this.props.onChange({ columns: columns });
1750
- }
1751
- }
1752
- itemsInColumns() {
1753
- const currentColumnCount = this.state.columnCount;
1754
- const itemsInColumns = new Array(currentColumnCount);
1755
- // Force children to be handled as an array
1756
- const items = Children$1.toArray(this.props.children);
1757
- for (let i = 0; i < items.length; i++) {
1758
- const columnIndex = i % currentColumnCount;
1759
- if (!itemsInColumns[columnIndex]) {
1760
- itemsInColumns[columnIndex] = [];
1761
- }
1762
- itemsInColumns[columnIndex].push(items[i]);
1763
- }
1764
- return itemsInColumns;
1765
- }
1766
- renderColumns() {
1767
- const { column, columnAttrs = {}, columnClassName } = this.props;
1768
- const childrenInColumns = this.itemsInColumns();
1769
- const columnWidth = `${100 / childrenInColumns.length}%`;
1770
- let className = columnClassName;
1771
- if (className && typeof className !== 'string') {
1772
- this.logDeprecated('The property "columnClassName" requires a string');
1773
- // This is a deprecated default and will be removed soon.
1774
- if (typeof className === 'undefined') {
1775
- className = 'my-masonry-grid_column';
1776
- }
1777
- }
1778
- const columnAttributes = Object.assign(Object.assign(Object.assign({}, column), columnAttrs), { style: Object.assign(Object.assign({}, columnAttrs.style), { width: columnWidth }), className });
1779
- return childrenInColumns.map((items, i) => {
1780
- return createElement("div", Object.assign({}, columnAttributes, { key: i }), items);
1781
- });
1782
- }
1783
- logDeprecated(message) {
1784
- console.error('[Masonry]', message);
1785
- }
1786
- render() {
1787
- const _a = this.props, {
1788
- // ignored
1789
- children, breakpointCols, columnClassName, columnAttrs, column,
1790
- // used
1791
- className } = _a, rest = __rest(_a, ["children", "breakpointCols", "columnClassName", "columnAttrs", "column", "className"]);
1792
- let classNameOutput = className;
1793
- if (typeof className !== 'string') {
1794
- this.logDeprecated('The property "className" requires a string');
1795
- // This is a deprecated default and will be removed soon.
1796
- if (typeof className === 'undefined') {
1797
- classNameOutput = 'my-masonry-grid';
1798
- }
1799
- }
1800
- return (jsx("div", Object.assign({}, rest, { className: classNameOutput, children: this.renderColumns() })));
1801
- }
1802
- }
1803
-
1804
- const calcPlaceholderStyle = (width, height, duration = 1600) => ({
1805
- backgroundSize: `${parseInt(width.toString()) * 10}px ${height}px`,
1806
- animationDuration: `${(duration / 1000).toFixed(1)}s`,
1807
- });
1808
- const Placeholder = forwardRef(({ width, height, duration, bg, bgFrom, bgTo }, ref) => {
1809
- const placeholderStyle = calcPlaceholderStyle(width, height, duration);
1810
- return (jsx(Box, { as: `shimmer`, w: width, h: height, bg: bg || `#f6f7f8`, backgroundImage: `linear-gradient(to right, ${bgFrom || `rgb(238, 238, 238)`} 8%, ${bgTo || `rgb(203, 203, 203)`} 18%, ${bgFrom || `rgb(238, 238, 238)`} 33%);`, backgroundSize: placeholderStyle.backgroundSize, animationDuration: placeholderStyle.animationDuration }));
1811
- });
1812
- Placeholder.propTypes = {
1813
- width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
1814
- height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
1815
- duration: PropTypes.number,
1816
- bg: PropTypes.string,
1817
- bgFrom: PropTypes.string,
1818
- bgTo: PropTypes.string
1819
- };
1820
-
1821
- const Spacer = ({ w, h }) => {
1822
- return (jsx(Box, { as: `spacer`, w: w || 0, h: h || 0 }));
1823
- };
1824
-
1825
- const Text = forwardRef((props, ref) => {
1826
- const { children, as } = props;
1827
- return (jsx(ClassNames, { children: ({ css, cx }) => jsx("p", { className: `${as ? `${as} ` : ``}${cx(css `${buildCSS(props)}`)}`, ref: ref, children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : children }) }));
1828
- });
1829
-
1830
- const Tweet = (props) => {
1831
- const [rand, setRand] = useState(Math.random());
1832
- const _tweet = useRef();
1833
- const renderTweet = () => {
1834
- const twttr = window['twttr'];
1835
- twttr.ready().then(({ widgets }) => {
1836
- const { options, onTweetLoadSuccess, onTweetLoadError } = props;
1837
- widgets
1838
- .createTweetEmbed(props.id, _tweet.current, options || {})
1839
- .then((twitterWidgetElement) => {
1840
- // this.setState({
1841
- // isLoading: false
1842
- // })
1843
- // onTweetLoadSuccess && onTweetLoadSuccess(twitterWidgetElement)
1844
- })
1845
- .catch(() => { });
1846
- });
1847
- };
1848
- useEffect(() => {
1849
- const twttr = window['twttr'];
1850
- if (!(twttr && twttr.ready)) {
1851
- addScript(`https://platform.twitter.com/widgets.js`, renderTweet);
1852
- }
1853
- else {
1854
- renderTweet();
1855
- }
1856
- }, []);
1857
- useEffect(() => {
1858
- }, [rand]);
1859
- return (jsx(Box, { as: `tweet`, weight: 1, bref: _tweet }));
1860
- };
1861
-
1862
- const buildElement = (el) => {
1863
- switch (el.is) {
1864
- case "Box":
1865
- return jsx(Box, Object.assign({}, (el.props || {}), { children: el.children || null }), el.key || nanoid());
1866
- }
1867
- };
1868
- const buildComponent = (data) => {
1869
- return data.map(e => buildElement(e));
1870
- };
1871
-
1872
- const Header = forwardRef((props, ref) => {
1873
- const data = [
1874
- { is: `Box` }
1875
- ];
1876
- return (jsx(Fragment, { children: buildComponent(data) }));
1877
- });
1878
-
1879
- export { App, Component as Block, Box, Button, Checkbox, Cover, Form, Header, Heading, Icon, Image$1 as Image, Input, Masonry, Placeholder, AppProvider as Provider, Select, Spacer, Spinner, Text, Toaster, Tweet, addProps, addScript, buildCSS, buildFormData, byId, byName, camelCase, cleanProps, copyToClipboard, createSlice, el, filterHTMLProps, filterStyleProps, formatSize, generateModalRoutes, generatePreservedRoutes, generateRegularRoutes, getCookie, getHostname, getMousePosition, getUriParams, imgPromiseFactory, isEmail, isIPv4, isUrl, parseFilename, randstr, removeCookie, rgb2hex, setCSSVar, setCookie, shuffleArray, slugify, ucfirst, useContextMenu, useDevice, useDispatch, useImage, useLang, useRender, useResizeObserver, useStore, useTheme, useToast, uuid, withRest };