@xanui/core 1.2.34 → 1.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AppRoot/Renderar.js +11 -2
- package/AppRoot/Renderar.js.map +1 -1
- package/AppRoot/Renderar.mjs +8 -2
- package/AppRoot/Renderar.mjs.map +1 -1
- package/AppRoot/index.js +22 -3
- package/AppRoot/index.js.map +1 -1
- package/AppRoot/index.mjs +16 -2
- package/AppRoot/index.mjs.map +1 -1
- package/Tag/ServerStyleTag.js +9 -2
- package/Tag/ServerStyleTag.js.map +1 -1
- package/Tag/ServerStyleTag.mjs +7 -2
- package/Tag/ServerStyleTag.mjs.map +1 -1
- package/Tag/cssPropList.js +7 -2
- package/Tag/cssPropList.js.map +1 -1
- package/Tag/cssPropList.mjs +4 -1
- package/Tag/cssPropList.mjs.map +1 -1
- package/Tag/index.js +34 -4
- package/Tag/index.js.map +1 -1
- package/Tag/index.mjs +11 -2
- package/Tag/index.mjs.map +1 -1
- package/Tag/useTagProps.js +13 -3
- package/Tag/useTagProps.js.map +1 -1
- package/Tag/useTagProps.mjs +10 -2
- package/Tag/useTagProps.mjs.map +1 -1
- package/Transition/index.d.ts +3 -7
- package/Transition/index.js +24 -4
- package/Transition/index.js.map +1 -1
- package/Transition/index.mjs +22 -4
- package/Transition/index.mjs.map +1 -1
- package/breakpoint/BreakpointProvider.js +13 -2
- package/breakpoint/BreakpointProvider.js.map +1 -1
- package/breakpoint/BreakpointProvider.mjs +10 -2
- package/breakpoint/BreakpointProvider.mjs.map +1 -1
- package/breakpoint/useBreakpoint.js +11 -2
- package/breakpoint/useBreakpoint.js.map +1 -1
- package/breakpoint/useBreakpoint.mjs +9 -2
- package/breakpoint/useBreakpoint.mjs.map +1 -1
- package/breakpoint/useBreakpointProps.js +11 -3
- package/breakpoint/useBreakpointProps.js.map +1 -1
- package/breakpoint/useBreakpointProps.mjs +8 -2
- package/breakpoint/useBreakpointProps.mjs.map +1 -1
- package/css/aliases.js +7 -2
- package/css/aliases.js.map +1 -1
- package/css/aliases.mjs +4 -1
- package/css/aliases.mjs.map +1 -1
- package/css/getProps.js +7 -2
- package/css/getProps.js.map +1 -1
- package/css/getProps.mjs +4 -1
- package/css/getProps.mjs.map +1 -1
- package/css/getValue.js +7 -2
- package/css/getValue.js.map +1 -1
- package/css/getValue.mjs +4 -1
- package/css/getValue.mjs.map +1 -1
- package/css/index.js +21 -5
- package/css/index.js.map +1 -1
- package/css/index.mjs +10 -2
- package/css/index.mjs.map +1 -1
- package/hooks/useAnimation.js +14 -2
- package/hooks/useAnimation.js.map +1 -1
- package/hooks/useAnimation.mjs +9 -2
- package/hooks/useAnimation.mjs.map +1 -1
- package/hooks/useColorTemplate.js +8 -2
- package/hooks/useColorTemplate.js.map +1 -1
- package/hooks/useColorTemplate.mjs +5 -1
- package/hooks/useColorTemplate.mjs.map +1 -1
- package/hooks/useInterface.js +13 -2
- package/hooks/useInterface.js.map +1 -1
- package/hooks/useInterface.mjs +11 -2
- package/hooks/useInterface.mjs.map +1 -1
- package/hooks/usePortal.js +22 -3
- package/hooks/usePortal.js.map +1 -1
- package/hooks/usePortal.mjs +16 -2
- package/hooks/usePortal.mjs.map +1 -1
- package/hooks/useTransition/index.d.ts +1 -1
- package/hooks/useTransition/index.js +17 -5
- package/hooks/useTransition/index.js.map +1 -1
- package/hooks/useTransition/index.mjs +15 -5
- package/hooks/useTransition/index.mjs.map +1 -1
- package/hooks/useTransition/variants.js +20 -2
- package/hooks/useTransition/variants.js.map +1 -1
- package/hooks/useTransition/variants.mjs +4 -1
- package/hooks/useTransition/variants.mjs.map +1 -1
- package/index.js +53 -1
- package/index.js.map +1 -1
- package/index.mjs +21 -1
- package/index.mjs.map +1 -1
- package/package.json +2 -8
- package/theme/ThemeCssVars.js +7 -2
- package/theme/ThemeCssVars.js.map +1 -1
- package/theme/ThemeCssVars.mjs +4 -1
- package/theme/ThemeCssVars.mjs.map +1 -1
- package/theme/ThemeDefaultOptions.js +54 -44
- package/theme/ThemeDefaultOptions.js.map +1 -1
- package/theme/ThemeDefaultOptions.mjs +48 -44
- package/theme/ThemeDefaultOptions.mjs.map +1 -1
- package/theme/ThemeProvider.js +39 -4
- package/theme/ThemeProvider.js.map +1 -1
- package/theme/ThemeProvider.mjs +16 -2
- package/theme/ThemeProvider.mjs.map +1 -1
- package/theme/core.js +13 -2
- package/theme/core.js.map +1 -1
- package/theme/core.mjs +7 -2
- package/theme/core.mjs.map +1 -1
- package/theme/createTheme.js +11 -2
- package/theme/createTheme.js.map +1 -1
- package/theme/createTheme.mjs +9 -2
- package/theme/createTheme.mjs.map +1 -1
- package/theme/createThemeSwitcher.js +11 -2
- package/theme/createThemeSwitcher.js.map +1 -1
- package/theme/createThemeSwitcher.mjs +9 -2
- package/theme/createThemeSwitcher.mjs.map +1 -1
- package/theme/index.js +15 -1
- package/theme/index.js.map +1 -1
- package/theme/index.mjs +10 -1
- package/theme/index.mjs.map +1 -1
package/css/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getValue = require('./getValue.js');
|
|
4
|
+
var getProps = require('./getProps.js');
|
|
5
|
+
var aliases = require('./aliases.js');
|
|
6
|
+
var oncss = require('oncss');
|
|
7
|
+
|
|
8
|
+
const breakpoints = {
|
|
2
9
|
xs: 0,
|
|
3
10
|
sm: 600,
|
|
4
11
|
md: 900,
|
|
@@ -7,20 +14,20 @@
|
|
|
7
14
|
};
|
|
8
15
|
const css = (props, options) => {
|
|
9
16
|
const cssOptions = Object.assign(Object.assign({}, options), { breakpoints,
|
|
10
|
-
aliases
|
|
17
|
+
aliases, getValue: (p, v, _c, dept) => {
|
|
11
18
|
if (options === null || options === void 0 ? void 0 : options.getValue) {
|
|
12
19
|
let _val = options === null || options === void 0 ? void 0 : options.getValue(p, v, _c, dept);
|
|
13
20
|
if (_val)
|
|
14
21
|
return _val;
|
|
15
22
|
}
|
|
16
|
-
return getValue
|
|
23
|
+
return getValue(p, v);
|
|
17
24
|
}, getProps: (p, v, _c, dept) => {
|
|
18
25
|
if (options === null || options === void 0 ? void 0 : options.getProps) {
|
|
19
26
|
let _p = options === null || options === void 0 ? void 0 : options.getProps(p, v, _c, dept);
|
|
20
27
|
if (_p)
|
|
21
28
|
return _p;
|
|
22
29
|
}
|
|
23
|
-
return getProps
|
|
30
|
+
return getProps(p, v, _c);
|
|
24
31
|
} });
|
|
25
32
|
return oncss.css(props, cssOptions);
|
|
26
33
|
};
|
|
@@ -52,4 +59,13 @@ const alpha = (color, opacity = 1) => {
|
|
|
52
59
|
if (!color.startsWith("#"))
|
|
53
60
|
throw new Error(`color must be hex`);
|
|
54
61
|
return (color + (`0${Math.round((255 / 100) * _opacity).toString(16)}`.slice(-2))).toUpperCase();
|
|
55
|
-
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
exports.getValue = getValue;
|
|
65
|
+
exports.getProps = getProps;
|
|
66
|
+
exports.adjustColor = adjustColor;
|
|
67
|
+
exports.adjustTextContrast = adjustTextContrast;
|
|
68
|
+
exports.alpha = alpha;
|
|
69
|
+
exports.breakpoints = breakpoints;
|
|
70
|
+
exports.css = css;
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
package/css/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/css/index.ts"],"sourcesContent":["import getValue from \"./getValue\"\nimport getProps from \"./getProps\"\nimport aliases from \"./aliases\"\nimport { Aliases, BreakpointKeys, CSSOptionProps, CSSProps } from './types'\nimport { css as _css } from \"oncss\"\n\nexport {\n getValue,\n getProps\n}\n\nexport const breakpoints = {\n xs: 0,\n sm: 600,\n md: 900,\n lg: 1200,\n xl: 1536\n}\n\nexport const css = (props: CSSProps, options?: CSSOptionProps) => {\n const cssOptions: CSSOptionProps = {\n ...options,\n breakpoints,\n aliases,\n getValue: (p: any, v: any, _c: any, dept) => {\n if (options?.getValue) {\n let _val = options?.getValue(p, v, _c, dept)\n if (_val) return _val\n }\n return getValue(p, v, _c)\n },\n getProps: (p: any, v: any, _c: any, dept) => {\n if (options?.getProps) {\n let _p = options?.getProps(p, v, _c, dept)\n if (_p) return _p\n }\n return getProps(p, v, _c)\n },\n }\n return _css<Aliases, BreakpointKeys>(props, cssOptions)\n}\n\nexport const adjustColor = (hex: string, factor: number) => {\n\n hex = hex.replace(/^#/, '')\n\n let r = parseInt(hex.slice(0, 2), 16)\n let g = parseInt(hex.slice(2, 4), 16)\n let b = parseInt(hex.slice(4, 6), 16)\n\n r = Math.floor(r * factor)\n g = Math.floor(g * factor)\n b = Math.floor(b * factor)\n\n r = Math.min(255, Math.max(0, r))\n g = Math.min(255, Math.max(0, g))\n b = Math.min(255, Math.max(0, b))\n\n return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;\n}\n\nexport const adjustTextContrast = (color: string) => {\n color = color.replace(/^#/, '')\n const r = parseInt(color.slice(0, 2), 16);\n const g = parseInt(color.slice(2, 4), 16);\n const b = parseInt(color.slice(4, 6), 16);\n\n const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;\n return luminance > 0.5 ? '#111111' : '#FFFFFF';\n}\n\nexport const alpha = (color: string, opacity = 1) => {\n if (typeof opacity !== 'number') return color\n let _opacity = opacity * 100\n if (!color.startsWith(\"#\")) throw new Error(`color must be hex`)\n return (color + (`0${Math.round((255 / 100) * _opacity).toString(16)}`.slice(-2))).toUpperCase();\n};\n\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/css/index.ts"],"sourcesContent":["import getValue from \"./getValue\"\nimport getProps from \"./getProps\"\nimport aliases from \"./aliases\"\nimport { Aliases, BreakpointKeys, CSSOptionProps, CSSProps } from './types'\nimport { css as _css } from \"oncss\"\n\nexport {\n getValue,\n getProps\n}\n\nexport const breakpoints = {\n xs: 0,\n sm: 600,\n md: 900,\n lg: 1200,\n xl: 1536\n}\n\nexport const css = (props: CSSProps, options?: CSSOptionProps) => {\n const cssOptions: CSSOptionProps = {\n ...options,\n breakpoints,\n aliases,\n getValue: (p: any, v: any, _c: any, dept) => {\n if (options?.getValue) {\n let _val = options?.getValue(p, v, _c, dept)\n if (_val) return _val\n }\n return getValue(p, v, _c)\n },\n getProps: (p: any, v: any, _c: any, dept) => {\n if (options?.getProps) {\n let _p = options?.getProps(p, v, _c, dept)\n if (_p) return _p\n }\n return getProps(p, v, _c)\n },\n }\n return _css<Aliases, BreakpointKeys>(props, cssOptions)\n}\n\nexport const adjustColor = (hex: string, factor: number) => {\n\n hex = hex.replace(/^#/, '')\n\n let r = parseInt(hex.slice(0, 2), 16)\n let g = parseInt(hex.slice(2, 4), 16)\n let b = parseInt(hex.slice(4, 6), 16)\n\n r = Math.floor(r * factor)\n g = Math.floor(g * factor)\n b = Math.floor(b * factor)\n\n r = Math.min(255, Math.max(0, r))\n g = Math.min(255, Math.max(0, g))\n b = Math.min(255, Math.max(0, b))\n\n return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;\n}\n\nexport const adjustTextContrast = (color: string) => {\n color = color.replace(/^#/, '')\n const r = parseInt(color.slice(0, 2), 16);\n const g = parseInt(color.slice(2, 4), 16);\n const b = parseInt(color.slice(4, 6), 16);\n\n const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;\n return luminance > 0.5 ? '#111111' : '#FFFFFF';\n}\n\nexport const alpha = (color: string, opacity = 1) => {\n if (typeof opacity !== 'number') return color\n let _opacity = opacity * 100\n if (!color.startsWith(\"#\")) throw new Error(`color must be hex`)\n return (color + (`0${Math.round((255 / 100) * _opacity).toString(16)}`.slice(-2))).toUpperCase();\n};\n\n"],"names":["_css"],"mappings":";;;;;;;AAWO,MAAM,WAAW,GAAG;AACvB,IAAA,EAAE,EAAE,CAAC;AACL,IAAA,EAAE,EAAE,GAAG;AACP,IAAA,EAAE,EAAE,GAAG;A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Value.mjs';
|
|
1
|
+
import getValue from './getValue.mjs';
|
|
2
|
+
import getProps from './getProps.mjs';
|
|
3
|
+
import aliases from './aliases.mjs';
|
|
4
|
+
import { css as css$1 } from 'oncss';
|
|
5
|
+
|
|
6
|
+
const breakpoints = {
|
|
2
7
|
xs: 0,
|
|
3
8
|
sm: 600,
|
|
4
9
|
md: 900,
|
|
@@ -52,4 +57,7 @@ const alpha = (color, opacity = 1) => {
|
|
|
52
57
|
if (!color.startsWith("#"))
|
|
53
58
|
throw new Error(`color must be hex`);
|
|
54
59
|
return (color + (`0${Math.round((255 / 100) * _opacity).toString(16)}`.slice(-2))).toUpperCase();
|
|
55
|
-
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { adjustColor, adjustTextContrast, alpha, breakpoints, css, getProps, getValue };
|
|
63
|
+
//# sourceMappingURL=index.mjs.map
|
package/css/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/css/index.ts"],"sourcesContent":["import getValue from \"./getValue\"\nimport getProps from \"./getProps\"\nimport aliases from \"./aliases\"\nimport { Aliases, BreakpointKeys, CSSOptionProps, CSSProps } from './types'\nimport { css as _css } from \"oncss\"\n\nexport {\n getValue,\n getProps\n}\n\nexport const breakpoints = {\n xs: 0,\n sm: 600,\n md: 900,\n lg: 1200,\n xl: 1536\n}\n\nexport const css = (props: CSSProps, options?: CSSOptionProps) => {\n const cssOptions: CSSOptionProps = {\n ...options,\n breakpoints,\n aliases,\n getValue: (p: any, v: any, _c: any, dept) => {\n if (options?.getValue) {\n let _val = options?.getValue(p, v, _c, dept)\n if (_val) return _val\n }\n return getValue(p, v, _c)\n },\n getProps: (p: any, v: any, _c: any, dept) => {\n if (options?.getProps) {\n let _p = options?.getProps(p, v, _c, dept)\n if (_p) return _p\n }\n return getProps(p, v, _c)\n },\n }\n return _css<Aliases, BreakpointKeys>(props, cssOptions)\n}\n\nexport const adjustColor = (hex: string, factor: number) => {\n\n hex = hex.replace(/^#/, '')\n\n let r = parseInt(hex.slice(0, 2), 16)\n let g = parseInt(hex.slice(2, 4), 16)\n let b = parseInt(hex.slice(4, 6), 16)\n\n r = Math.floor(r * factor)\n g = Math.floor(g * factor)\n b = Math.floor(b * factor)\n\n r = Math.min(255, Math.max(0, r))\n g = Math.min(255, Math.max(0, g))\n b = Math.min(255, Math.max(0, b))\n\n return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;\n}\n\nexport const adjustTextContrast = (color: string) => {\n color = color.replace(/^#/, '')\n const r = parseInt(color.slice(0, 2), 16);\n const g = parseInt(color.slice(2, 4), 16);\n const b = parseInt(color.slice(4, 6), 16);\n\n const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;\n return luminance > 0.5 ? '#111111' : '#FFFFFF';\n}\n\nexport const alpha = (color: string, opacity = 1) => {\n if (typeof opacity !== 'number') return color\n let _opacity = opacity * 100\n if (!color.startsWith(\"#\")) throw new Error(`color must be hex`)\n return (color + (`0${Math.round((255 / 100) * _opacity).toString(16)}`.slice(-2))).toUpperCase();\n};\n\n"],"names":["_css"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/css/index.ts"],"sourcesContent":["import getValue from \"./getValue\"\nimport getProps from \"./getProps\"\nimport aliases from \"./aliases\"\nimport { Aliases, BreakpointKeys, CSSOptionProps, CSSProps } from './types'\nimport { css as _css } from \"oncss\"\n\nexport {\n getValue,\n getProps\n}\n\nexport const breakpoints = {\n xs: 0,\n sm: 600,\n md: 900,\n lg: 1200,\n xl: 1536\n}\n\nexport const css = (props: CSSProps, options?: CSSOptionProps) => {\n const cssOptions: CSSOptionProps = {\n ...options,\n breakpoints,\n aliases,\n getValue: (p: any, v: any, _c: any, dept) => {\n if (options?.getValue) {\n let _val = options?.getValue(p, v, _c, dept)\n if (_val) return _val\n }\n return getValue(p, v, _c)\n },\n getProps: (p: any, v: any, _c: any, dept) => {\n if (options?.getProps) {\n let _p = options?.getProps(p, v, _c, dept)\n if (_p) return _p\n }\n return getProps(p, v, _c)\n },\n }\n return _css<Aliases, BreakpointKeys>(props, cssOptions)\n}\n\nexport const adjustColor = (hex: string, factor: number) => {\n\n hex = hex.replace(/^#/, '')\n\n let r = parseInt(hex.slice(0, 2), 16)\n let g = parseInt(hex.slice(2, 4), 16)\n let b = parseInt(hex.slice(4, 6), 16)\n\n r = Math.floor(r * factor)\n g = Math.floor(g * factor)\n b = Math.floor(b * factor)\n\n r = Math.min(255, Math.max(0, r))\n g = Math.min(255, Math.max(0, g))\n b = Math.min(255, Math.max(0, b))\n\n return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;\n}\n\nexport const adjustTextContrast = (color: string) => {\n color = color.replace(/^#/, '')\n const r = parseInt(color.slice(0, 2), 16);\n const g = parseInt(color.slice(2, 4), 16);\n const b = parseInt(color.slice(4, 6), 16);\n\n const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;\n return luminance > 0.5 ? '#111111' : '#FFFFFF';\n}\n\nexport const alpha = (color: string, opacity = 1) => {\n if (typeof opacity !== 'number') return color\n let _opacity = opacity * 100\n if (!color.startsWith(\"#\")) throw new Error(`color must be hex`)\n return (color + (`0${Math.round((255 / 100) * _opacity).toString(16)}`.slice(-2))).toUpperCase();\n};\n\n"],"names":["_css"],"mappings":";;;;;AAWO,MAAM,WAAW,GAAG;AACvB,IAAA,EAAE,EAAE,CAAC;AACL,IAAA,EAAE,EAAE,GAAG;AACP,IAAA,EAAE,EAAE,GAAG;AACP,IAAA,EAAE,EAAE,IAAI;AACR,IAAA,EAAE,EAAE;;MAGK,GAAG,GAAG,CAAC,KAAe,EAAE,OAAwB,KAAI;AAC7D,IAAA,MAAM,UAAU,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACT,OAAO,CAAA,EAAA,EACV,WAAW;AACX,QAAA,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E,CAAC;AACzC,IAAA,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;AACzC,IAAA,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;AAEzC,IAAA,MAAM,SAAS,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI,GAAG;IAC3D,OAAO,SAAS,GAAG,GAAG,GAAG,SAAS,GAAG,SAAS;AAClD;AAEO,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,OAAO,GAAG,CAAC,KAAI;IAChD,IAAI,OAAO,OAAO,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;AAC7C,IAAA,IAAI,QAAQ,GAAG,OAAO,GAAG,GAAG;AAC5B,IAAA,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,CAAA,iBAAA,CAAmB,CAAC;AAChE,IAAA,OAAO,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA,CAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE;AACpG;;;;"}
|
package/hooks/useAnimation.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var index = require('../css/index.js');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
|
|
9
|
+
const animationEases = {
|
|
2
10
|
standard: "cubic-bezier(0.4, 0, 0.2, 1)",
|
|
3
11
|
fast: "cubic-bezier(0.2, 0, 0, 1)",
|
|
4
12
|
smooth: "cubic-bezier(0.25, 0.46, 0.45, 0.94)",
|
|
@@ -21,4 +29,8 @@ const useAnimation = ({ from, to, delay, ease, duration }) => {
|
|
|
21
29
|
}
|
|
22
30
|
});
|
|
23
31
|
return anim.classname;
|
|
24
|
-
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.animationEases = animationEases;
|
|
35
|
+
exports.default = useAnimation;
|
|
36
|
+
//# sourceMappingURL=useAnimation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAnimation.js","sources":["../../src/hooks/useAnimation.ts"],"sourcesContent":["\"use client\";\nimport { css } from '../css'\nimport { useId } from 'react'\nimport { CSSProps } from '../css/types'\n\nexport const animationEases = {\n standard: \"cubic-bezier(0.4, 0, 0.2, 1)\",\n fast: \"cubic-bezier(0.2, 0, 0, 1)\",\n smooth: \"cubic-bezier(0.25, 0.46, 0.45, 0.94)\",\n linear: \"cubic-bezier(0, 0, 1, 1)\",\n bounce: \"cubic-bezier(0.34, 1.50, 0.64, 1)\",\n};\n\nexport interface UseAnimationProps {\n delay?: number;\n duration?: number;\n from: CSSProps;\n to: CSSProps;\n ease?: keyof typeof animationEases;\n}\n\nconst useAnimation = ({ from, to, delay, ease, duration }: UseAnimationProps) => {\n let _delay = delay || 0;\n let _duration = duration || 600;\n let _ease = ease || \"standard\"\n const id = \"anim\" + useId().replace(/:/g, \"\")\n const anim = css({\n animationName: id,\n animationDelay: _delay + \"ms\",\n animationDuration: _duration + \"ms\",\n animationTimingFunction: animationEases[_ease] || animationEases.standard,\n [`@keyframes ${id}`]: {\n from: from as any,\n to: to as any\n }\n })\n return anim.classname\n}\n\nexport default useAnimation"],"names":[
|
|
1
|
+
{"version":3,"file":"useAnimation.js","sources":["../../src/hooks/useAnimation.ts"],"sourcesContent":["\"use client\";\nimport { css } from '../css'\nimport { useId } from 'react'\nimport { CSSProps } from '../css/types'\n\nexport const animationEases = {\n standard: \"cubic-bezier(0.4, 0, 0.2, 1)\",\n fast: \"cubic-bezier(0.2, 0, 0, 1)\",\n smooth: \"cubic-bezier(0.25, 0.46, 0.45, 0.94)\",\n linear: \"cubic-bezier(0, 0, 1, 1)\",\n bounce: \"cubic-bezier(0.34, 1.50, 0.64, 1)\",\n};\n\nexport interface UseAnimationProps {\n delay?: number;\n duration?: number;\n from: CSSProps;\n to: CSSProps;\n ease?: keyof typeof animationEases;\n}\n\nconst useAnimation = ({ from, to, delay, ease, duration }: UseAnimationProps) => {\n let _delay = delay || 0;\n let _duration = duration || 600;\n let _ease = ease || \"standard\"\n const id = \"anim\" + useId().replace(/:/g, \"\")\n const anim = css({\n animationName: id,\n animationDelay: _delay + \"ms\",\n animationDuration: _duration + \"ms\",\n animationTimingFunction: animationEases[_ease] || animationEases.standard,\n [`@keyframes ${id}`]: {\n from: from as any,\n to: to as any\n }\n })\n return anim.classname\n}\n\nexport default useAnimation"],"names":[],"mappings":";;;;;;;;AAKO;AACH;AACA;AACA;AACA;AACA;;AAWJ;AACI;AACA;AACA;AACA;;AAEI;;;;AAIA;AACI;AACA;AACH;AACJ;;AAEL;;;"}
|
package/hooks/useAnimation.mjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { css } from '../css/index.mjs';
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
|
|
5
|
+
const animationEases = {
|
|
2
6
|
standard: "cubic-bezier(0.4, 0, 0.2, 1)",
|
|
3
7
|
fast: "cubic-bezier(0.2, 0, 0, 1)",
|
|
4
8
|
smooth: "cubic-bezier(0.25, 0.46, 0.45, 0.94)",
|
|
@@ -21,4 +25,7 @@ const useAnimation = ({ from, to, delay, ease, duration }) => {
|
|
|
21
25
|
}
|
|
22
26
|
});
|
|
23
27
|
return anim.classname;
|
|
24
|
-
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { animationEases, useAnimation as default };
|
|
31
|
+
//# sourceMappingURL=useAnimation.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAnimation.mjs","sources":["../../src/hooks/useAnimation.ts"],"sourcesContent":["\"use client\";\nimport { css } from '../css'\nimport { useId } from 'react'\nimport { CSSProps } from '../css/types'\n\nexport const animationEases = {\n standard: \"cubic-bezier(0.4, 0, 0.2, 1)\",\n fast: \"cubic-bezier(0.2, 0, 0, 1)\",\n smooth: \"cubic-bezier(0.25, 0.46, 0.45, 0.94)\",\n linear: \"cubic-bezier(0, 0, 1, 1)\",\n bounce: \"cubic-bezier(0.34, 1.50, 0.64, 1)\",\n};\n\nexport interface UseAnimationProps {\n delay?: number;\n duration?: number;\n from: CSSProps;\n to: CSSProps;\n ease?: keyof typeof animationEases;\n}\n\nconst useAnimation = ({ from, to, delay, ease, duration }: UseAnimationProps) => {\n let _delay = delay || 0;\n let _duration = duration || 600;\n let _ease = ease || \"standard\"\n const id = \"anim\" + useId().replace(/:/g, \"\")\n const anim = css({\n animationName: id,\n animationDelay: _delay + \"ms\",\n animationDuration: _duration + \"ms\",\n animationTimingFunction: animationEases[_ease] || animationEases.standard,\n [`@keyframes ${id}`]: {\n from: from as any,\n to: to as any\n }\n })\n return anim.classname\n}\n\nexport default useAnimation"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAnimation.mjs","sources":["../../src/hooks/useAnimation.ts"],"sourcesContent":["\"use client\";\nimport { css } from '../css'\nimport { useId } from 'react'\nimport { CSSProps } from '../css/types'\n\nexport const animationEases = {\n standard: \"cubic-bezier(0.4, 0, 0.2, 1)\",\n fast: \"cubic-bezier(0.2, 0, 0, 1)\",\n smooth: \"cubic-bezier(0.25, 0.46, 0.45, 0.94)\",\n linear: \"cubic-bezier(0, 0, 1, 1)\",\n bounce: \"cubic-bezier(0.34, 1.50, 0.64, 1)\",\n};\n\nexport interface UseAnimationProps {\n delay?: number;\n duration?: number;\n from: CSSProps;\n to: CSSProps;\n ease?: keyof typeof animationEases;\n}\n\nconst useAnimation = ({ from, to, delay, ease, duration }: UseAnimationProps) => {\n let _delay = delay || 0;\n let _duration = duration || 600;\n let _ease = ease || \"standard\"\n const id = \"anim\" + useId().replace(/:/g, \"\")\n const anim = css({\n animationName: id,\n animationDelay: _delay + \"ms\",\n animationDuration: _duration + \"ms\",\n animationTimingFunction: animationEases[_ease] || animationEases.standard,\n [`@keyframes ${id}`]: {\n from: from as any,\n to: to as any\n }\n })\n return anim.classname\n}\n\nexport default useAnimation"],"names":[],"mappings":";;;;AAKO;AACH;AACA;AACA;AACA;AACA;;AAWJ;AACI;AACA;AACA;AACA;;AAEI;;;;AAIA;AACI;AACA;AACH;AACJ;;AAEL;;"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const useColorTemplate = (color, type) => {
|
|
2
5
|
const is_def = color === "default";
|
|
3
6
|
if (is_def) {
|
|
4
7
|
color = "divider";
|
|
@@ -68,4 +71,7 @@
|
|
|
68
71
|
};
|
|
69
72
|
}
|
|
70
73
|
throw new Error(`useColorTemplate: Unknown type ${type}`);
|
|
71
|
-
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
module.exports = useColorTemplate;
|
|
77
|
+
//# sourceMappingURL=useColorTemplate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useColorTemplate.js","sources":["../../src/hooks/useColorTemplate.ts"],"sourcesContent":["\"use client\";\nexport type UseColorTemplateType = \"fill\" | \"outline\" | \"text\" | \"soft\"\nexport type UseColorTemplateColor = \"default\" | \"brand\" | \"accent\" | \"success\" | \"info\" | \"warning\" | \"danger\"\n\nconst useColorTemplate = (color: UseColorTemplateColor, type: UseColorTemplateType) => {\n const is_def = color === \"default\";\n if (is_def) {\n color = \"divider\" as any\n }\n\n if (type === \"outline\") {\n return {\n primary: {\n bgcolor: `transparent`,\n color: is_def ? `text.primary` : `${color}.primary`,\n border: 1,\n borderColor: is_def ? `divider` : `${color}.primary`,\n },\n secondary: {\n bgcolor: `transparent`,\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n }\n }\n } else if (type === \"fill\") {\n return {\n primary: {\n bgcolor: color,\n color: is_def ? `text.primary` : `${color}.text`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n },\n secondary: {\n bgcolor: `${color}.secondary`,\n color: is_def ? `text.primary` : `${color}.text`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n }\n }\n } else if (type === \"text\") {\n return {\n primary: {\n bgcolor: \"transparent\",\n color: is_def ? `text.primary` : `${color}.primary`,\n border: 0,\n borderColor: `transparent`,\n },\n secondary: {\n bgcolor: \"transparent\",\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 0,\n borderColor: `transparent`,\n }\n }\n } else if (type === \"soft\") {\n return {\n primary: {\n bgcolor: `${color}.soft.primary`,\n color: is_def ? `text.primary` : color,\n border: 0,\n borderColor: `transparent`,\n },\n secondary: {\n bgcolor: `${color}.soft.secondary`,\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 0,\n borderColor: `transparent`,\n }\n }\n }\n\n throw new Error(`useColorTemplate: Unknown type ${type}`);\n}\n\nexport default useColorTemplate"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useColorTemplate.js","sources":["../../src/hooks/useColorTemplate.ts"],"sourcesContent":["\"use client\";\nexport type UseColorTemplateType = \"fill\" | \"outline\" | \"text\" | \"soft\"\nexport type UseColorTemplateColor = \"default\" | \"brand\" | \"accent\" | \"success\" | \"info\" | \"warning\" | \"danger\"\n\nconst useColorTemplate = (color: UseColorTemplateColor, type: UseColorTemplateType) => {\n const is_def = color === \"default\";\n if (is_def) {\n color = \"divider\" as any\n }\n\n if (type === \"outline\") {\n return {\n primary: {\n bgcolor: `transparent`,\n color: is_def ? `text.primary` : `${color}.primary`,\n border: 1,\n borderColor: is_def ? `divider` : `${color}.primary`,\n },\n secondary: {\n bgcolor: `transparent`,\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n }\n }\n } else if (type === \"fill\") {\n return {\n primary: {\n bgcolor: color,\n color: is_def ? `text.primary` : `${color}.text`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n },\n secondary: {\n bgcolor: `${color}.secondary`,\n color: is_def ? `text.primary` : `${color}.text`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n }\n }\n } else if (type === \"text\") {\n return {\n primary: {\n bgcolor: \"transparent\",\n color: is_def ? `text.primary` : `${color}.primary`,\n border: 0,\n borderColor: `transparent`,\n },\n secondary: {\n bgcolor: \"transparent\",\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 0,\n borderColor: `transparent`,\n }\n }\n } else if (type === \"soft\") {\n return {\n primary: {\n bgcolor: `${color}.soft.primary`,\n color: is_def ? `text.primary` : color,\n border: 0,\n borderColor: `transparent`,\n },\n secondary: {\n bgcolor: `${color}.soft.secondary`,\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 0,\n borderColor: `transparent`,\n }\n }\n }\n\n throw new Error(`useColorTemplate: Unknown type ${type}`);\n}\n\nexport default useColorTemplate"],"names":[],"mappings":";;;AAIA;AACI;;;;AAKA;;AAEQ;AACI;;AAEA;;AAEH;AACD;AACI;;AAEA;;AAEH;;;AAEF;;AAEC;AACI;;AAEA;;AAEH;AACD;;;AAGI;;AAEH;;;AAEF;;AAEC;AACI;;AAEA;AACA;AACH;AACD;AACI;;AAEA;AACA;AACH;;;AAEF;;AAEC;;;AAGI;AACA;AACH;AACD;;;AAGI;AACA;AACH;;;AAIT;AACJ;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
const useColorTemplate = (color, type) => {
|
|
2
3
|
const is_def = color === "default";
|
|
3
4
|
if (is_def) {
|
|
@@ -68,4 +69,7 @@ const useColorTemplate = (color, type) => {
|
|
|
68
69
|
};
|
|
69
70
|
}
|
|
70
71
|
throw new Error(`useColorTemplate: Unknown type ${type}`);
|
|
71
|
-
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export { useColorTemplate as default };
|
|
75
|
+
//# sourceMappingURL=useColorTemplate.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useColorTemplate.mjs","sources":["../../src/hooks/useColorTemplate.ts"],"sourcesContent":["\"use client\";\nexport type UseColorTemplateType = \"fill\" | \"outline\" | \"text\" | \"soft\"\nexport type UseColorTemplateColor = \"default\" | \"brand\" | \"accent\" | \"success\" | \"info\" | \"warning\" | \"danger\"\n\nconst useColorTemplate = (color: UseColorTemplateColor, type: UseColorTemplateType) => {\n const is_def = color === \"default\";\n if (is_def) {\n color = \"divider\" as any\n }\n\n if (type === \"outline\") {\n return {\n primary: {\n bgcolor: `transparent`,\n color: is_def ? `text.primary` : `${color}.primary`,\n border: 1,\n borderColor: is_def ? `divider` : `${color}.primary`,\n },\n secondary: {\n bgcolor: `transparent`,\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n }\n }\n } else if (type === \"fill\") {\n return {\n primary: {\n bgcolor: color,\n color: is_def ? `text.primary` : `${color}.text`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n },\n secondary: {\n bgcolor: `${color}.secondary`,\n color: is_def ? `text.primary` : `${color}.text`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n }\n }\n } else if (type === \"text\") {\n return {\n primary: {\n bgcolor: \"transparent\",\n color: is_def ? `text.primary` : `${color}.primary`,\n border: 0,\n borderColor: `transparent`,\n },\n secondary: {\n bgcolor: \"transparent\",\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 0,\n borderColor: `transparent`,\n }\n }\n } else if (type === \"soft\") {\n return {\n primary: {\n bgcolor: `${color}.soft.primary`,\n color: is_def ? `text.primary` : color,\n border: 0,\n borderColor: `transparent`,\n },\n secondary: {\n bgcolor: `${color}.soft.secondary`,\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 0,\n borderColor: `transparent`,\n }\n }\n }\n\n throw new Error(`useColorTemplate: Unknown type ${type}`);\n}\n\nexport default useColorTemplate"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"useColorTemplate.mjs","sources":["../../src/hooks/useColorTemplate.ts"],"sourcesContent":["\"use client\";\nexport type UseColorTemplateType = \"fill\" | \"outline\" | \"text\" | \"soft\"\nexport type UseColorTemplateColor = \"default\" | \"brand\" | \"accent\" | \"success\" | \"info\" | \"warning\" | \"danger\"\n\nconst useColorTemplate = (color: UseColorTemplateColor, type: UseColorTemplateType) => {\n const is_def = color === \"default\";\n if (is_def) {\n color = \"divider\" as any\n }\n\n if (type === \"outline\") {\n return {\n primary: {\n bgcolor: `transparent`,\n color: is_def ? `text.primary` : `${color}.primary`,\n border: 1,\n borderColor: is_def ? `divider` : `${color}.primary`,\n },\n secondary: {\n bgcolor: `transparent`,\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n }\n }\n } else if (type === \"fill\") {\n return {\n primary: {\n bgcolor: color,\n color: is_def ? `text.primary` : `${color}.text`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n },\n secondary: {\n bgcolor: `${color}.secondary`,\n color: is_def ? `text.primary` : `${color}.text`,\n border: 1,\n borderColor: is_def ? `divider.secondary` : `${color}.secondary`,\n }\n }\n } else if (type === \"text\") {\n return {\n primary: {\n bgcolor: \"transparent\",\n color: is_def ? `text.primary` : `${color}.primary`,\n border: 0,\n borderColor: `transparent`,\n },\n secondary: {\n bgcolor: \"transparent\",\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 0,\n borderColor: `transparent`,\n }\n }\n } else if (type === \"soft\") {\n return {\n primary: {\n bgcolor: `${color}.soft.primary`,\n color: is_def ? `text.primary` : color,\n border: 0,\n borderColor: `transparent`,\n },\n secondary: {\n bgcolor: `${color}.soft.secondary`,\n color: is_def ? `text.primary` : `${color}.secondary`,\n border: 0,\n borderColor: `transparent`,\n }\n }\n }\n\n throw new Error(`useColorTemplate: Unknown type ${type}`);\n}\n\nexport default useColorTemplate"],"names":[],"mappings":";AAIA;AACI;;;;AAKA;;AAEQ;AACI;;AAEA;;AAEH;AACD;AACI;;AAEA;;AAEH;;;AAEF;;AAEC;AACI;;AAEA;;AAEH;AACD;;;AAGI;;AAEH;;;AAEF;;AAEC;AACI;;AAEA;AACA;AACH;AACD;AACI;;AAEA;AACA;AACH;;;AAEF;;AAEC;;;AAGI;AACA;AACH;AACD;;;AAGI;AACA;AACH;;;AAIT;AACJ;;"}
|
package/hooks/useInterface.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('../theme/core.js');
|
|
4
|
+
require('../css/getValue.js');
|
|
5
|
+
require('oncss');
|
|
6
|
+
require('../theme/ThemeProvider.js');
|
|
7
|
+
require('react-state-bucket');
|
|
8
|
+
|
|
9
|
+
const useInterface = (name, userPorps, defaultProps) => {
|
|
2
10
|
const theme = core.useTheme();
|
|
3
11
|
let _props = Object.assign(Object.assign({}, defaultProps), userPorps);
|
|
4
12
|
if (name in theme.interfaces) {
|
|
5
13
|
return theme.interfaces[name](_props, theme);
|
|
6
14
|
}
|
|
7
15
|
return [_props, theme];
|
|
8
|
-
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = useInterface;
|
|
19
|
+
//# sourceMappingURL=useInterface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInterface.js","sources":["../../src/hooks/useInterface.ts"],"sourcesContent":["import { useTheme } from \"../theme\"\n\nconst useInterface = <P extends object>(name: string, userPorps: P, defaultProps: P) => {\n const theme = useTheme()\n let _props = { ...defaultProps, ...userPorps } as P\n if (name in theme.interfaces) {\n return theme.interfaces[name](_props, theme)\n }\n return [_props, theme]\n}\n\nexport default useInterface"],"names":["useTheme"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useInterface.js","sources":["../../src/hooks/useInterface.ts"],"sourcesContent":["import { useTheme } from \"../theme\"\n\nconst useInterface = <P extends object>(name: string, userPorps: P, defaultProps: P) => {\n const theme = useTheme()\n let _props = { ...defaultProps, ...userPorps } as P\n if (name in theme.interfaces) {\n return theme.interfaces[name](_props, theme)\n }\n return [_props, theme]\n}\n\nexport default useInterface"],"names":["useTheme"],"mappings":";;;;;;;;AAEA,MAAM,YAAY,GAAG,CAAmB,IAAY,EAAE,SAAY,EAAE,YAAe,KAAI;AACnF,IAAA,MAAM,KAAK,GAAGA,aAAQ,EAAE;AACxB,IAAA,IAAI,MAAM,GAAG,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAK,YAAY,CAAA,EAAK,SAAS,CAAO;AACnD,IAAA,IAAI,IAAI,IAAI,KAAK,CAAC,UAAU,EAAE;QAC1B,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC;IAChD;AACA,IAAA,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC;AAC1B;;;;"}
|
package/hooks/useInterface.mjs
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import {useTheme}from'../theme/core.mjs';
|
|
1
|
+
import { useTheme } from '../theme/core.mjs';
|
|
2
|
+
import '../css/getValue.mjs';
|
|
3
|
+
import 'oncss';
|
|
4
|
+
import '../theme/ThemeProvider.mjs';
|
|
5
|
+
import 'react-state-bucket';
|
|
6
|
+
|
|
7
|
+
const useInterface = (name, userPorps, defaultProps) => {
|
|
2
8
|
const theme = useTheme();
|
|
3
9
|
let _props = Object.assign(Object.assign({}, defaultProps), userPorps);
|
|
4
10
|
if (name in theme.interfaces) {
|
|
5
11
|
return theme.interfaces[name](_props, theme);
|
|
6
12
|
}
|
|
7
13
|
return [_props, theme];
|
|
8
|
-
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { useInterface as default };
|
|
17
|
+
//# sourceMappingURL=useInterface.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInterface.mjs","sources":["../../src/hooks/useInterface.ts"],"sourcesContent":["import { useTheme } from \"../theme\"\n\nconst useInterface = <P extends object>(name: string, userPorps: P, defaultProps: P) => {\n const theme = useTheme()\n let _props = { ...defaultProps, ...userPorps } as P\n if (name in theme.interfaces) {\n return theme.interfaces[name](_props, theme)\n }\n return [_props, theme]\n}\n\nexport default useInterface"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useInterface.mjs","sources":["../../src/hooks/useInterface.ts"],"sourcesContent":["import { useTheme } from \"../theme\"\n\nconst useInterface = <P extends object>(name: string, userPorps: P, defaultProps: P) => {\n const theme = useTheme()\n let _props = { ...defaultProps, ...userPorps } as P\n if (name in theme.interfaces) {\n return theme.interfaces[name](_props, theme)\n }\n return [_props, theme]\n}\n\nexport default useInterface"],"names":[],"mappings":";;;;;;AAEA,MAAM,YAAY,GAAG,CAAmB,IAAY,EAAE,SAAY,EAAE,YAAe,KAAI;AACnF,IAAA,MAAM,KAAK,GAAG,QAAQ,EAAE;AACxB,IAAA,IAAI,MAAM,GAAG,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAK,YAAY,CAAA,EAAK,SAAS,CAAO;AACnD,IAAA,IAAI,IAAI,IAAI,KAAK,CAAC,UAAU,EAAE;QAC1B,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC;IAChD;AACA,IAAA,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC;AAC1B;;;;"}
|
package/hooks/usePortal.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var client = require('react-dom/client');
|
|
9
|
+
var core = require('../theme/core.js');
|
|
10
|
+
require('../css/getValue.js');
|
|
11
|
+
require('oncss');
|
|
12
|
+
var ThemeProvider = require('../theme/ThemeProvider.js');
|
|
13
|
+
require('react-state-bucket');
|
|
14
|
+
var index = require('../AppRoot/index.js');
|
|
15
|
+
|
|
16
|
+
function usePortal(children, options) {
|
|
2
17
|
options = options || {};
|
|
3
18
|
if (options.autoMount === undefined) {
|
|
4
19
|
options.autoMount = true;
|
|
@@ -22,7 +37,7 @@
|
|
|
22
37
|
if (!cont.contains(el)) {
|
|
23
38
|
cont.appendChild(el);
|
|
24
39
|
}
|
|
25
|
-
root.render(jsxRuntime.jsx(ThemeProvider
|
|
40
|
+
root.render(jsxRuntime.jsx(ThemeProvider, { theme: theme.name, children: children }));
|
|
26
41
|
};
|
|
27
42
|
const unmount = () => {
|
|
28
43
|
root.render(null);
|
|
@@ -51,4 +66,8 @@
|
|
|
51
66
|
mount: () => setMounted(true),
|
|
52
67
|
unmount: () => setMounted(false)
|
|
53
68
|
};
|
|
54
|
-
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
exports.default = usePortal;
|
|
72
|
+
exports.usePortal = usePortal;
|
|
73
|
+
//# sourceMappingURL=usePortal.js.map
|
package/hooks/usePortal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePortal.js","sources":["../../src/hooks/usePortal.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useMemo } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { ThemeProvider, useTheme } from \"../theme\";\nimport { appRootElement } from \"../AppRoot\";\n\nexport type UsePortalOptions = {\n container?: HTMLElement;\n autoMount?: boolean;\n}\n\nexport function usePortal(children: React.ReactNode, options?: UsePortalOptions) {\n options = options || {};\n if (options.autoMount === undefined) {\n options.autoMount = true;\n }\n const [mounted, setMounted] = React.useState(options.autoMount);\n const theme = useTheme();\n const { el, root } = useMemo(() => {\n const el = document.createElement(\"div\");\n const root = createRoot(el);\n return { el, root };\n }, [options.autoMount]);\n\n const container = () => {\n const rootEle = appRootElement();\n const container = options?.container || rootEle\n if (!container) throw new Error(`Container not found for portal. Please ensure that AppRoot is present in the application tree.`);\n return container;\n }\n\n const mount = () => {\n const cont = container();\n if (!cont.contains(el)) {\n cont.appendChild(el);\n }\n root.render(<ThemeProvider theme={theme.name}>{children}</ThemeProvider>)\n }\n\n const unmount = () => {\n root.render(null)\n el.remove();\n }\n\n\n useEffect(() => {\n if (mounted) {\n mount()\n } else {\n unmount()\n }\n }, [mounted]);\n\n useEffect(() => {\n if (mounted) {\n mount()\n }\n }, [children]);\n\n useEffect(() => {\n return () => {\n unmount()\n };\n }, []);\n\n return {\n isMount: () => mounted,\n mount: () => setMounted(true),\n unmount: () => setMounted(false)\n }\n}\n\n\nexport default usePortal;"],"names":[
|
|
1
|
+
{"version":3,"file":"usePortal.js","sources":["../../src/hooks/usePortal.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useMemo } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { ThemeProvider, useTheme } from \"../theme\";\nimport { appRootElement } from \"../AppRoot\";\n\nexport type UsePortalOptions = {\n container?: HTMLElement;\n autoMount?: boolean;\n}\n\nexport function usePortal(children: React.ReactNode, options?: UsePortalOptions) {\n options = options || {};\n if (options.autoMount === undefined) {\n options.autoMount = true;\n }\n const [mounted, setMounted] = React.useState(options.autoMount);\n const theme = useTheme();\n const { el, root } = useMemo(() => {\n const el = document.createElement(\"div\");\n const root = createRoot(el);\n return { el, root };\n }, [options.autoMount]);\n\n const container = () => {\n const rootEle = appRootElement();\n const container = options?.container || rootEle\n if (!container) throw new Error(`Container not found for portal. Please ensure that AppRoot is present in the application tree.`);\n return container;\n }\n\n const mount = () => {\n const cont = container();\n if (!cont.contains(el)) {\n cont.appendChild(el);\n }\n root.render(<ThemeProvider theme={theme.name}>{children}</ThemeProvider>)\n }\n\n const unmount = () => {\n root.render(null)\n el.remove();\n }\n\n\n useEffect(() => {\n if (mounted) {\n mount()\n } else {\n unmount()\n }\n }, [mounted]);\n\n useEffect(() => {\n if (mounted) {\n mount()\n }\n }, [children]);\n\n useEffect(() => {\n return () => {\n unmount()\n };\n }, []);\n\n return {\n isMount: () => mounted,\n mount: () => setMounted(true),\n unmount: () => setMounted(false)\n }\n}\n\n\nexport default usePortal;"],"names":[],"mappings":";;;;;;;;;;;;;;;AAWM;AACH;AACA;AACG;;AAEH;AACA;;;AAGG;AACA;AACH;;AAGG;AACA;AACA;AAAgB;AAChB;AACH;;AAGG;;AAEG;;AAEH;AACH;;AAGG;;AAEH;;;AAKM;;;AAEA;;AAEN;;;AAIM;;AAEN;;AAGG;AACG;AACH;;;AAIA;AACA;AACA;;AAEN;;;"}
|
package/hooks/usePortal.mjs
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React__default, { useMemo, useEffect } from 'react';
|
|
4
|
+
import { createRoot } from 'react-dom/client';
|
|
5
|
+
import { useTheme } from '../theme/core.mjs';
|
|
6
|
+
import '../css/getValue.mjs';
|
|
7
|
+
import 'oncss';
|
|
8
|
+
import ThemeProvider from '../theme/ThemeProvider.mjs';
|
|
9
|
+
import 'react-state-bucket';
|
|
10
|
+
import { appRootElement } from '../AppRoot/index.mjs';
|
|
11
|
+
|
|
12
|
+
function usePortal(children, options) {
|
|
2
13
|
options = options || {};
|
|
3
14
|
if (options.autoMount === undefined) {
|
|
4
15
|
options.autoMount = true;
|
|
@@ -51,4 +62,7 @@ import {jsx}from'react/jsx-runtime';import React__default,{useMemo,useEffect}fro
|
|
|
51
62
|
mount: () => setMounted(true),
|
|
52
63
|
unmount: () => setMounted(false)
|
|
53
64
|
};
|
|
54
|
-
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { usePortal as default, usePortal };
|
|
68
|
+
//# sourceMappingURL=usePortal.mjs.map
|
package/hooks/usePortal.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePortal.mjs","sources":["../../src/hooks/usePortal.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useMemo } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { ThemeProvider, useTheme } from \"../theme\";\nimport { appRootElement } from \"../AppRoot\";\n\nexport type UsePortalOptions = {\n container?: HTMLElement;\n autoMount?: boolean;\n}\n\nexport function usePortal(children: React.ReactNode, options?: UsePortalOptions) {\n options = options || {};\n if (options.autoMount === undefined) {\n options.autoMount = true;\n }\n const [mounted, setMounted] = React.useState(options.autoMount);\n const theme = useTheme();\n const { el, root } = useMemo(() => {\n const el = document.createElement(\"div\");\n const root = createRoot(el);\n return { el, root };\n }, [options.autoMount]);\n\n const container = () => {\n const rootEle = appRootElement();\n const container = options?.container || rootEle\n if (!container) throw new Error(`Container not found for portal. Please ensure that AppRoot is present in the application tree.`);\n return container;\n }\n\n const mount = () => {\n const cont = container();\n if (!cont.contains(el)) {\n cont.appendChild(el);\n }\n root.render(<ThemeProvider theme={theme.name}>{children}</ThemeProvider>)\n }\n\n const unmount = () => {\n root.render(null)\n el.remove();\n }\n\n\n useEffect(() => {\n if (mounted) {\n mount()\n } else {\n unmount()\n }\n }, [mounted]);\n\n useEffect(() => {\n if (mounted) {\n mount()\n }\n }, [children]);\n\n useEffect(() => {\n return () => {\n unmount()\n };\n }, []);\n\n return {\n isMount: () => mounted,\n mount: () => setMounted(true),\n unmount: () => setMounted(false)\n }\n}\n\n\nexport default usePortal;"],"names":[
|
|
1
|
+
{"version":3,"file":"usePortal.mjs","sources":["../../src/hooks/usePortal.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useMemo } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { ThemeProvider, useTheme } from \"../theme\";\nimport { appRootElement } from \"../AppRoot\";\n\nexport type UsePortalOptions = {\n container?: HTMLElement;\n autoMount?: boolean;\n}\n\nexport function usePortal(children: React.ReactNode, options?: UsePortalOptions) {\n options = options || {};\n if (options.autoMount === undefined) {\n options.autoMount = true;\n }\n const [mounted, setMounted] = React.useState(options.autoMount);\n const theme = useTheme();\n const { el, root } = useMemo(() => {\n const el = document.createElement(\"div\");\n const root = createRoot(el);\n return { el, root };\n }, [options.autoMount]);\n\n const container = () => {\n const rootEle = appRootElement();\n const container = options?.container || rootEle\n if (!container) throw new Error(`Container not found for portal. Please ensure that AppRoot is present in the application tree.`);\n return container;\n }\n\n const mount = () => {\n const cont = container();\n if (!cont.contains(el)) {\n cont.appendChild(el);\n }\n root.render(<ThemeProvider theme={theme.name}>{children}</ThemeProvider>)\n }\n\n const unmount = () => {\n root.render(null)\n el.remove();\n }\n\n\n useEffect(() => {\n if (mounted) {\n mount()\n } else {\n unmount()\n }\n }, [mounted]);\n\n useEffect(() => {\n if (mounted) {\n mount()\n }\n }, [children]);\n\n useEffect(() => {\n return () => {\n unmount()\n };\n }, []);\n\n return {\n isMount: () => mounted,\n mount: () => setMounted(true),\n unmount: () => setMounted(false)\n }\n}\n\n\nexport default usePortal;"],"names":[],"mappings":";;;;;;;;;;;AAWM;AACH;AACA;AACG;;AAEH;AACA;;;AAGG;AACA;AACH;;AAGG;AACA;AACA;AAAgB;AAChB;AACH;;AAGG;;AAEG;;AAEH;AACH;;AAGG;;AAEH;;;AAKM;;;AAEA;;AAEN;;;AAIM;;AAEN;;AAGG;AACG;AACH;;;AAIA;AACA;AACA;;AAEN;;"}
|
|
@@ -23,7 +23,7 @@ type UseTransitionProps = {
|
|
|
23
23
|
onClosed?: () => void;
|
|
24
24
|
onState?: (state: UseTransitionState) => void;
|
|
25
25
|
};
|
|
26
|
-
declare const useTransition: (
|
|
26
|
+
declare const useTransition: ({ open, ...props }: UseTransitionProps) => {
|
|
27
27
|
exited: boolean;
|
|
28
28
|
props: {
|
|
29
29
|
id: string;
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var tslib = require('tslib');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var useAnimation = require('../useAnimation.js');
|
|
7
|
+
var index = require('../../css/index.js');
|
|
8
|
+
var oncss = require('oncss');
|
|
9
|
+
var variants = require('./variants.js');
|
|
10
|
+
|
|
11
|
+
const style = (obj) => {
|
|
2
12
|
return index.css(obj || {}, { selector: "#" }).classname;
|
|
3
13
|
};
|
|
4
14
|
const getVariant = (rect, variant) => {
|
|
@@ -7,12 +17,11 @@ const getVariant = (rect, variant) => {
|
|
|
7
17
|
throw new Error(`Transition variant "${variant}" not found.`);
|
|
8
18
|
return fn(rect);
|
|
9
19
|
};
|
|
10
|
-
const useTransition = (
|
|
20
|
+
const useTransition = (_a) => {
|
|
11
21
|
var { open } = _a, props = tslib.__rest(_a, ["open"]);
|
|
12
22
|
let { disableInitialTransition = false, variant = "fade", duration = 400, delay, ease, easing, exitOnUnmount = false, onOpen, onOpened, onClose, onClosed, onState } = props;
|
|
13
23
|
let _ease = ease || useAnimation.animationEases[easing] || useAnimation.animationEases.bounce;
|
|
14
|
-
|
|
15
|
-
id = `xui-transition-${id}`;
|
|
24
|
+
const id = "xui-transition-" + React.useId();
|
|
16
25
|
const [state, setState] = React.useState({
|
|
17
26
|
initial: false,
|
|
18
27
|
classname: style({ visibility: "hidden" }),
|
|
@@ -89,4 +98,7 @@ const useTransition = (id, _a) => {
|
|
|
89
98
|
'data-transition-state': open ? 'open' : 'close',
|
|
90
99
|
}
|
|
91
100
|
};
|
|
92
|
-
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
module.exports = useTransition;
|
|
104
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/hooks/useTransition/index.ts"],"sourcesContent":["\"use client\";\nimport { useState, useEffect, useId, useRef } from 'react';\nimport { animationEases } from '../useAnimation';\nimport { css } from '../../css';\nimport { formatCSSProp } from 'oncss';\nimport { CSSProps } from '../../css/types';\nimport * as variants from './variants'\n\nexport type UseTransitionVariantTypes = keyof typeof variants\nexport type UseTransitionState = \"open\" | \"opened\" | \"close\" | \"closed\"\n\nexport type UseTransitionVariant = (rect: DOMRect) => ({ from: CSSProps, to: CSSProps })\n\nexport type UseTransitionProps = {\n open: boolean;\n variant: UseTransitionVariant | UseTransitionVariantTypes;\n ease?: string;\n easing?: keyof typeof animationEases;\n duration?: number;\n delay?: number;\n disableInitialTransition?: boolean;\n exitOnUnmount?: boolean;\n onOpen?: () => void;\n onOpened?: () => void;\n onClose?: () => void;\n onClosed?: () => void;\n onState?: (state: UseTransitionState) => void;\n}\n\n\nconst style = (obj?: any) => {\n return css(obj || {}, { selector: \"#\" }).classname;\n}\n\nconst getVariant = (rect: DOMRect | null, variant: UseTransitionProps['variant']) => {\n let fn = typeof variant === 'string' ? variants[variant] : variant\n if (!fn) throw new Error(`Transition variant \"${variant}\" not found.`)\n return fn(rect as DOMRect);\n}\n\nconst useTransition = (id: string, { open, ...props }: UseTransitionProps) => {\n let {\n disableInitialTransition = false,\n variant = \"fade\",\n duration = 400,\n delay,\n ease,\n easing,\n exitOnUnmount = false,\n onOpen,\n onOpened,\n onClose,\n onClosed,\n onState\n } = props\n let _ease = ease || (animationEases as any)[easing as any] || animationEases.bounce\n // const id = \"xui-transition-\" + useId()\n id = `xui-transition-${id}`\n\n const [state, setState] = useState({\n initial: false,\n classname: style({ visibility: \"hidden\" }),\n variant: variant,\n rect: null as DOMRect | null,\n stage: open ? \"open\" : \"closed\",\n unmounted: false,\n })\n\n const getEle = () => document.querySelector(`[data-transition=\"${id}\"]`) as HTMLElement;\n const getBoundary = () => state.rect || getEle()?.getBoundingClientRect() || new DOMRect(0, 0, 0, 0);\n\n useEffect(() => {\n if (exitOnUnmount && state.stage === 'closed') {\n if (!open) {\n setState(s => ({\n ...s,\n initial: false,\n classname: \"\",\n unmounted: true,\n variant: variant,\n }))\n } else {\n setState(s => ({\n ...s,\n variant: variant,\n classname: style({ visibility: \"hidden\" }),\n stage: \"open\",\n }))\n }\n }\n }, [open, state.stage, exitOnUnmount, variant])\n\n // initial effect\n useEffect(() => {\n const ele = getEle()\n if (!ele) return\n if (exitOnUnmount && state.stage === 'closed') return\n\n const rect = getBoundary();\n let { from } = getVariant(rect, state.variant)\n if (open && !state.initial) {\n setState(s => ({\n ...s,\n classname: (!disableInitialTransition || state.unmounted) ? style(from) : \"\",\n initial: true,\n rect: rect,\n }))\n let stimer: any = null\n let etimer: any = null\n ele.ontransitionstart = () => {\n clearTimeout(stimer)\n stimer = setTimeout(() => {\n const isOpen = ele.getAttribute('data-transition-state') === 'open';\n (onOpen && isOpen) && onOpen();\n (onClose && !isOpen) && onClose()\n onState && onState(isOpen ? \"open\" : \"close\")\n setState(s => ({\n ...s,\n stage: isOpen ? \"open\" : \"close\"\n }))\n }, 1)\n }\n\n ele.ontransitionend = () => {\n clearTimeout(etimer)\n etimer = setTimeout(() => {\n const isOpen = ele.getAttribute('data-transition-state') === 'open';\n (onOpened && isOpen) && onOpened();\n (onClosed && !isOpen) && onClosed();\n onState && onState(isOpen ? \"opened\" : \"closed\")\n setState(s => ({\n ...s,\n stage: isOpen ? \"opened\" : \"closed\"\n }))\n }, 1)\n }\n } else if (!state.initial) {\n setState(s => ({\n ...s,\n classname: style(from),\n rect: rect,\n }))\n }\n }, [open, state.initial, state.stage, exitOnUnmount])\n\n\n useEffect(() => {\n if (state.initial) {\n let _variant = state.variant !== variant ? variant : state.variant\n const { from, to } = getVariant(state.rect, _variant)\n let _css: CSSProps = open ? to : from\n let trans = ` ${duration}ms ${_ease} ${delay || 0}ms`\n let _ = {\n ..._css,\n transition: Object.keys(_css || {}).map(k => formatCSSProp(k)).join(trans + \", \") + trans,\n }\n setState(s => ({\n ...s,\n classname: style(_),\n variant: _variant\n }))\n }\n }, [open, state.initial, variant])\n\n return {\n exited: exitOnUnmount && state.stage === 'closed',\n props: {\n 'id': state.classname,\n 'data-transition': id,\n 'data-transition-state': open ? 'open' : 'close',\n }\n }\n}\n\n\nexport default useTransition"],"names":["css","__rest","animationEases","useState","useEffect","formatCSSProp"],"mappings":"gQA8BA,MAAM,KAAK,GAAG,CAAC,GAAS,KAAI;AACzB,IAAA,OAAOA,SAAG,CAAC,GAAG,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,SAAS;AACrD,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,IAAoB,EAAE,OAAsC,KAAI;AACjF,IAAA,IAAI,EAAE,GAAG,OAAO,OAAO,KAAK,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO;AAClE,IAAA,IAAI,CAAC,EAAE;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,uBAAuB,OAAO,CAAA,YAAA,CAAc,CAAC;AACtE,IAAA,OAAO,EAAE,CAAC,IAAe,CAAC;AAC7B,CAAC;AAED,MAAM,aAAa,GAAG,CAAC,EAAU,EAAE,EAAsC,KAAI;AAA1C,IAAA,IAAA,EAAE,IAAI,EAAA,GAAA,EAAgC,EAA3B,KAAK,GAAAC,YAAA,CAAA,EAAA,EAAhB,QAAkB,CAAF;AAChD,IAAA,IAAI,EACD,wBAAwB,GAAG,KAAK,EAChC,OAAO,GAAG,MAAM,EAChB,QAAQ,GAAG,GAAG,EACd,KAAK,EACL,IAAI,EACJ,MAAM,EACN,aAAa,GAAG,KAAK,EACrB,MAAM,EACN,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,OAAO,EACT,GAAG,KAAK;AACT,IAAA,IAAI,KAAK,GAAG,IAAI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B,uBAAuB,EAAE,IAAI,GAAG,MAAM,GAAG,OAAO;AAClD;KACH;AACJ"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/hooks/useTransition/index.ts"],"sourcesContent":["\"use client\";\nimport { useState, useEffect, useId } from 'react';\nimport { animationEases } from '../useAnimation';\nimport { css } from '../../css';\nimport { formatCSSProp } from 'oncss';\nimport { CSSProps } from '../../css/types';\nimport * as variants from './variants'\n\nexport type UseTransitionVariantTypes = keyof typeof variants\nexport type UseTransitionState = \"open\" | \"opened\" | \"close\" | \"closed\"\n\nexport type UseTransitionVariant = (rect: DOMRect) => ({ from: CSSProps, to: CSSProps })\n\nexport type UseTransitionProps = {\n open: boolean;\n variant: UseTransitionVariant | UseTransitionVariantTypes;\n ease?: string;\n easing?: keyof typeof animationEases;\n duration?: number;\n delay?: number;\n disableInitialTransition?: boolean;\n exitOnUnmount?: boolean;\n onOpen?: () => void;\n onOpened?: () => void;\n onClose?: () => void;\n onClosed?: () => void;\n onState?: (state: UseTransitionState) => void;\n}\n\n\nconst style = (obj?: any) => {\n return css(obj || {}, { selector: \"#\" }).classname;\n}\n\nconst getVariant = (rect: DOMRect | null, variant: UseTransitionProps['variant']) => {\n let fn = typeof variant === 'string' ? variants[variant] : variant\n if (!fn) throw new Error(`Transition variant \"${variant}\" not found.`)\n return fn(rect as DOMRect);\n}\n\nconst useTransition = ({ open, ...props }: UseTransitionProps) => {\n let {\n disableInitialTransition = false,\n variant = \"fade\",\n duration = 400,\n delay,\n ease,\n easing,\n exitOnUnmount = false,\n onOpen,\n onOpened,\n onClose,\n onClosed,\n onState\n } = props\n let _ease = ease || (animationEases as any)[easing as any] || animationEases.bounce\n const id = \"xui-transition-\" + useId()\n const [state, setState] = useState({\n initial: false,\n classname: style({ visibility: \"hidden\" }),\n variant: variant,\n rect: null as DOMRect | null,\n stage: open ? \"open\" : \"closed\",\n unmounted: false,\n })\n\n const getEle = () => document.querySelector(`[data-transition=\"${id}\"]`) as HTMLElement;\n const getBoundary = () => state.rect || getEle()?.getBoundingClientRect() || new DOMRect(0, 0, 0, 0);\n\n useEffect(() => {\n if (exitOnUnmount && state.stage === 'closed') {\n if (!open) {\n setState(s => ({\n ...s,\n initial: false,\n classname: \"\",\n unmounted: true,\n variant: variant,\n }))\n } else {\n setState(s => ({\n ...s,\n variant: variant,\n classname: style({ visibility: \"hidden\" }),\n stage: \"open\",\n }))\n }\n }\n }, [open, state.stage, exitOnUnmount, variant])\n\n // initial effect\n useEffect(() => {\n const ele = getEle()\n if (!ele) return\n if (exitOnUnmount && state.stage === 'closed') return\n\n const rect = getBoundary();\n let { from } = getVariant(rect, state.variant)\n if (open && !state.initial) {\n setState(s => ({\n ...s,\n classname: (!disableInitialTransition || state.unmounted) ? style(from) : \"\",\n initial: true,\n rect: rect,\n }))\n let stimer: any = null\n let etimer: any = null\n ele.ontransitionstart = () => {\n clearTimeout(stimer)\n stimer = setTimeout(() => {\n const isOpen = ele.getAttribute('data-transition-state') === 'open';\n (onOpen && isOpen) && onOpen();\n (onClose && !isOpen) && onClose()\n onState && onState(isOpen ? \"open\" : \"close\")\n setState(s => ({\n ...s,\n stage: isOpen ? \"open\" : \"close\"\n }))\n }, 1)\n }\n\n ele.ontransitionend = () => {\n clearTimeout(etimer)\n etimer = setTimeout(() => {\n const isOpen = ele.getAttribute('data-transition-state') === 'open';\n (onOpened && isOpen) && onOpened();\n (onClosed && !isOpen) && onClosed();\n onState && onState(isOpen ? \"opened\" : \"closed\")\n setState(s => ({\n ...s,\n stage: isOpen ? \"opened\" : \"closed\"\n }))\n }, 1)\n }\n } else if (!state.initial) {\n setState(s => ({\n ...s,\n classname: style(from),\n rect: rect,\n }))\n }\n }, [open, state.initial, state.stage, exitOnUnmount])\n\n\n useEffect(() => {\n if (state.initial) {\n let _variant = state.variant !== variant ? variant : state.variant\n const { from, to } = getVariant(state.rect, _variant)\n let _css: CSSProps = open ? to : from\n let trans = ` ${duration}ms ${_ease} ${delay || 0}ms`\n let _ = {\n ..._css,\n transition: Object.keys(_css || {}).map(k => formatCSSProp(k)).join(trans + \", \") + trans,\n }\n setState(s => ({\n ...s,\n classname: style(_),\n variant: _variant\n }))\n }\n }, [open, state.initial, variant])\n\n return {\n exited: exitOnUnmount && state.stage === 'closed',\n props: {\n 'id': state.classname,\n 'data-transition': id,\n 'data-transition-state': open ? 'open' : 'close',\n }\n }\n}\n\n\nexport default useTransition"],"names":[],"mappings":";;;;;;;;;;AA8BA;AACG;AACH;AAEA;AACG;AACA;AAAS;AACT;AACH;AAEA;AAAuB;AACpB;AAcA;AACA;AACA;AACG;;AAEA;AACA;;AAEA;AACF;AAED;AACA;;;;;;;AAaS;;;AAQT;;;AAIG;AACA;;AACA;;AAEA;AACA;AACA;AACG;;;AAQA;;AAEG;;AAEG;;AAEA;;;AAMN;AAEA;;AAEG;;AAEG;;AAEA;;;AAMN;;AACI;;;AAOV;;AAIG;AACG;AACA;;;AAGA;;;;;AAaH;AACA;;AAEG;;AAEF;;AAEP;;"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { __rest } from 'tslib';
|
|
3
|
+
import { useId, useState, useEffect } from 'react';
|
|
4
|
+
import { animationEases } from '../useAnimation.mjs';
|
|
5
|
+
import { css } from '../../css/index.mjs';
|
|
6
|
+
import { formatCSSProp } from 'oncss';
|
|
7
|
+
import * as variants from './variants.mjs';
|
|
8
|
+
|
|
9
|
+
const style = (obj) => {
|
|
2
10
|
return css(obj || {}, { selector: "#" }).classname;
|
|
3
11
|
};
|
|
4
12
|
const getVariant = (rect, variant) => {
|
|
@@ -7,12 +15,11 @@ const getVariant = (rect, variant) => {
|
|
|
7
15
|
throw new Error(`Transition variant "${variant}" not found.`);
|
|
8
16
|
return fn(rect);
|
|
9
17
|
};
|
|
10
|
-
const useTransition = (
|
|
18
|
+
const useTransition = (_a) => {
|
|
11
19
|
var { open } = _a, props = __rest(_a, ["open"]);
|
|
12
20
|
let { disableInitialTransition = false, variant = "fade", duration = 400, delay, ease, easing, exitOnUnmount = false, onOpen, onOpened, onClose, onClosed, onState } = props;
|
|
13
21
|
let _ease = ease || animationEases[easing] || animationEases.bounce;
|
|
14
|
-
|
|
15
|
-
id = `xui-transition-${id}`;
|
|
22
|
+
const id = "xui-transition-" + useId();
|
|
16
23
|
const [state, setState] = useState({
|
|
17
24
|
initial: false,
|
|
18
25
|
classname: style({ visibility: "hidden" }),
|
|
@@ -89,4 +96,7 @@ const useTransition = (id, _a) => {
|
|
|
89
96
|
'data-transition-state': open ? 'open' : 'close',
|
|
90
97
|
}
|
|
91
98
|
};
|
|
92
|
-
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export { useTransition as default };
|
|
102
|
+
//# sourceMappingURL=index.mjs.map
|