@xanui/core 1.2.66 → 1.2.67
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/index.cjs +5 -2
- package/AppRoot/index.cjs.map +1 -1
- package/AppRoot/index.js +5 -2
- package/AppRoot/index.js.map +1 -1
- package/Transition/index.cjs +5 -16
- package/Transition/index.cjs.map +1 -1
- package/Transition/index.js +5 -16
- package/Transition/index.js.map +1 -1
- package/breakpoint/BreakpointProvider.cjs +3 -2
- package/breakpoint/BreakpointProvider.cjs.map +1 -1
- package/breakpoint/BreakpointProvider.js +3 -2
- package/breakpoint/BreakpointProvider.js.map +1 -1
- package/cookie.cjs +43 -0
- package/cookie.cjs.map +1 -0
- package/cookie.js +41 -0
- package/cookie.js.map +1 -0
- package/package.json +1 -1
package/AppRoot/index.cjs
CHANGED
|
@@ -14,6 +14,7 @@ var index = require('../Document/index.cjs');
|
|
|
14
14
|
var AppRootProvider = require('./AppRootProvider.cjs');
|
|
15
15
|
var useMergeRefs = require('../hooks/useMergeRefs.cjs');
|
|
16
16
|
var CSSCacheProvider = require('../css/CSSCacheProvider.cjs');
|
|
17
|
+
var cookie = require('../cookie.cjs');
|
|
17
18
|
|
|
18
19
|
const AppRoot = React.forwardRef((_a, ref) => {
|
|
19
20
|
var { children, defaultBreakpoint, noScrollbarCss, CSSCacheId, theme, onThemeChange, disableRenderar, selectionColor, document: _document } = _a, props = tslib.__rest(_a, ["children", "defaultBreakpoint", "noScrollbarCss", "CSSCacheId", "theme", "onThemeChange", "disableRenderar", "selectionColor", "document"]);
|
|
@@ -35,7 +36,9 @@ const AppRoot = React.forwardRef((_a, ref) => {
|
|
|
35
36
|
React.useEffect(() => {
|
|
36
37
|
if (typeof _document === 'undefined')
|
|
37
38
|
return;
|
|
38
|
-
|
|
39
|
+
if (!cookie.exists("xuitm")) {
|
|
40
|
+
cookie.set("xuitm", theme.name);
|
|
41
|
+
}
|
|
39
42
|
const styles = Array.from(_document.querySelectorAll('body style[data-oncss]'));
|
|
40
43
|
styles.forEach((style) => {
|
|
41
44
|
_document.head.appendChild(style);
|
|
@@ -52,7 +55,7 @@ const AppRoot = React.forwardRef((_a, ref) => {
|
|
|
52
55
|
}
|
|
53
56
|
return (jsxRuntime.jsx(index.DocumentProvider, { value: _document ? { document: _document, id: docid } : undefined, children: jsxRuntime.jsx(CSSCacheProvider.CSSCacheProvider, { cacheId: CSSCacheId, children: jsxRuntime.jsx(AppRootProvider.AppRootProvider, { element: () => rootRef.current, children: jsxRuntime.jsx(ThemeProvider, Object.assign({ theme: theme, onThemeChange: (t) => {
|
|
54
57
|
onThemeChange && onThemeChange(t);
|
|
55
|
-
|
|
58
|
+
cookie.set("xuitm", t.name);
|
|
56
59
|
} }, props, { ref: mergeRef, isRoot: true, sx: Object.assign(Object.assign(Object.assign({}, props.sx), (visibility === "hidden" ? { visibility: "hidden" } : {})), selection), children: jsxRuntime.jsxs(BreakpointProvider.BreakpointProvider, { defaultKey: defaultBreakpoint !== null && defaultBreakpoint !== void 0 ? defaultBreakpoint : "xl", children: [children, !disableRenderar && jsxRuntime.jsx(Renderar.RenderRenderar, {})] }) })) }) }) }));
|
|
57
60
|
});
|
|
58
61
|
|
package/AppRoot/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/AppRoot/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useId, useLayoutEffect, useRef } from 'react';\nimport { TagComponentType } from '../Tag/types';\nimport { ThemeProvider, ThemeProviderProps } from '../theme';\nimport { BreakpointProvider } from '../breakpoint';\nimport { RenderRenderar } from './Renderar';\nimport { DocumentProvider } from '../Document';\nimport { AppRootProvider } from './AppRootProvider';\nimport useMergeRefs from '../hooks/useMergeRefs';\nimport { CSSCacheProvider } from '../css/CSSCacheProvider';\nimport { BreakpointKeys } from '../css/types';\n\nexport type AppRootProps<T extends TagComponentType = \"div\"> = ThemeProviderProps<T> & {\n noScrollbarCss?: boolean;\n document?: Document;\n CSSCacheId?: string;\n disableRenderar?: boolean;\n defaultBreakpoint?: BreakpointKeys\n selectionColor?: \"default\" | \"brand\" | \"accent\" | \"success\" | \"info\" | \"warning\" | \"danger\";\n}\n\nconst AppRoot = React.forwardRef(<T extends TagComponentType = \"div\">({ children, defaultBreakpoint, noScrollbarCss, CSSCacheId, theme, onThemeChange, disableRenderar, selectionColor, document: _document, ...props }: AppRootProps<T>, ref: React.Ref<any>) => {\n\n noScrollbarCss ??= false\n selectionColor ??= \"brand\"\n if (typeof window !== \"undefined\") {\n _document ??= document\n }\n disableRenderar ??= false\n const docid = useId()\n const csscacheId = useId()\n CSSCacheId ??= csscacheId\n\n const [visibility, setVisibility] = React.useState<string>(!defaultBreakpoint ? \"hidden\" : \"\");\n const rootRef = useRef(null)\n const mergeRef = useMergeRefs(rootRef, ref)\n\n useLayoutEffect(() => {\n !defaultBreakpoint && setVisibility(\"\");\n }, [])\n\n useEffect(() => {\n if (typeof _document === 'undefined') return;\n
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/AppRoot/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useId, useLayoutEffect, useRef } from 'react';\nimport { TagComponentType } from '../Tag/types';\nimport { ThemeProvider, ThemeProviderProps } from '../theme';\nimport { BreakpointProvider } from '../breakpoint';\nimport { RenderRenderar } from './Renderar';\nimport { DocumentProvider } from '../Document';\nimport { AppRootProvider } from './AppRootProvider';\nimport useMergeRefs from '../hooks/useMergeRefs';\nimport { CSSCacheProvider } from '../css/CSSCacheProvider';\nimport { BreakpointKeys } from '../css/types';\nimport Cookie from '../cookie';\n\nexport type AppRootProps<T extends TagComponentType = \"div\"> = ThemeProviderProps<T> & {\n noScrollbarCss?: boolean;\n document?: Document;\n CSSCacheId?: string;\n disableRenderar?: boolean;\n defaultBreakpoint?: BreakpointKeys\n selectionColor?: \"default\" | \"brand\" | \"accent\" | \"success\" | \"info\" | \"warning\" | \"danger\";\n}\n\nconst AppRoot = React.forwardRef(<T extends TagComponentType = \"div\">({ children, defaultBreakpoint, noScrollbarCss, CSSCacheId, theme, onThemeChange, disableRenderar, selectionColor, document: _document, ...props }: AppRootProps<T>, ref: React.Ref<any>) => {\n\n noScrollbarCss ??= false\n selectionColor ??= \"brand\"\n if (typeof window !== \"undefined\") {\n _document ??= document\n }\n disableRenderar ??= false\n const docid = useId()\n const csscacheId = useId()\n CSSCacheId ??= csscacheId\n\n const [visibility, setVisibility] = React.useState<string>(!defaultBreakpoint ? \"hidden\" : \"\");\n const rootRef = useRef(null)\n const mergeRef = useMergeRefs(rootRef, ref)\n\n useLayoutEffect(() => {\n !defaultBreakpoint && setVisibility(\"\");\n }, [])\n\n useEffect(() => {\n if (typeof _document === 'undefined') return;\n if (!Cookie.exists(\"xuitm\")) {\n Cookie.set(\"xuitm\", theme.name)\n }\n\n const styles = Array.from(_document.querySelectorAll('body style[data-oncss]'));\n styles.forEach((style) => {\n _document.head.appendChild(style);\n });\n }, [])\n\n let selection: any = {}\n if (selectionColor && selectionColor !== 'default') {\n selection = {\n \"&::selection\": {\n bgcolor: `${selectionColor}.primary`,\n color: `${selectionColor}.text`\n }\n }\n }\n\n return (\n <DocumentProvider value={_document ? { document: _document, id: docid } : undefined}>\n <CSSCacheProvider cacheId={CSSCacheId}>\n <AppRootProvider element={() => rootRef.current}>\n <ThemeProvider\n theme={theme}\n onThemeChange={(t) => {\n onThemeChange && onThemeChange(t)\n Cookie.set(\"xuitm\", t.name)\n }}\n {...props}\n ref={mergeRef}\n isRoot\n sx={{\n ...props.sx,\n ...(visibility === \"hidden\" ? { visibility: \"hidden\" } : {}),\n ...selection\n }}\n >\n <BreakpointProvider defaultKey={defaultBreakpoint ?? \"xl\"}>\n {children}\n {!disableRenderar && <RenderRenderar />}\n </BreakpointProvider>\n </ThemeProvider>\n </AppRootProvider>\n </CSSCacheProvider>\n </DocumentProvider>\n )\n})\n\nexport default AppRoot\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAsBA;;;;AAIG;;;;AAIA;AACA;;;AAIA;;;AAIG;;;;;;;;AASA;AACA;AACG;AACH;;;AAIH;AACG;AACG;;;AAGC;;;;AAWW;;AAEH;AAmBlB;;"}
|
package/AppRoot/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { DocumentProvider } from '../Document/index.js';
|
|
|
12
12
|
import { AppRootProvider } from './AppRootProvider.js';
|
|
13
13
|
import useMergeRefs from '../hooks/useMergeRefs.js';
|
|
14
14
|
import { CSSCacheProvider } from '../css/CSSCacheProvider.js';
|
|
15
|
+
import Cookie from '../cookie.js';
|
|
15
16
|
|
|
16
17
|
const AppRoot = React__default.forwardRef((_a, ref) => {
|
|
17
18
|
var { children, defaultBreakpoint, noScrollbarCss, CSSCacheId, theme, onThemeChange, disableRenderar, selectionColor, document: _document } = _a, props = __rest(_a, ["children", "defaultBreakpoint", "noScrollbarCss", "CSSCacheId", "theme", "onThemeChange", "disableRenderar", "selectionColor", "document"]);
|
|
@@ -33,7 +34,9 @@ const AppRoot = React__default.forwardRef((_a, ref) => {
|
|
|
33
34
|
useEffect(() => {
|
|
34
35
|
if (typeof _document === 'undefined')
|
|
35
36
|
return;
|
|
36
|
-
|
|
37
|
+
if (!Cookie.exists("xuitm")) {
|
|
38
|
+
Cookie.set("xuitm", theme.name);
|
|
39
|
+
}
|
|
37
40
|
const styles = Array.from(_document.querySelectorAll('body style[data-oncss]'));
|
|
38
41
|
styles.forEach((style) => {
|
|
39
42
|
_document.head.appendChild(style);
|
|
@@ -50,7 +53,7 @@ const AppRoot = React__default.forwardRef((_a, ref) => {
|
|
|
50
53
|
}
|
|
51
54
|
return (jsx(DocumentProvider, { value: _document ? { document: _document, id: docid } : undefined, children: jsx(CSSCacheProvider, { cacheId: CSSCacheId, children: jsx(AppRootProvider, { element: () => rootRef.current, children: jsx(ThemeProvider, Object.assign({ theme: theme, onThemeChange: (t) => {
|
|
52
55
|
onThemeChange && onThemeChange(t);
|
|
53
|
-
|
|
56
|
+
Cookie.set("xuitm", t.name);
|
|
54
57
|
} }, props, { ref: mergeRef, isRoot: true, sx: Object.assign(Object.assign(Object.assign({}, props.sx), (visibility === "hidden" ? { visibility: "hidden" } : {})), selection), children: jsxs(BreakpointProvider, { defaultKey: defaultBreakpoint !== null && defaultBreakpoint !== void 0 ? defaultBreakpoint : "xl", children: [children, !disableRenderar && jsx(RenderRenderar, {})] }) })) }) }) }));
|
|
55
58
|
});
|
|
56
59
|
|
package/AppRoot/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/AppRoot/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useId, useLayoutEffect, useRef } from 'react';\nimport { TagComponentType } from '../Tag/types';\nimport { ThemeProvider, ThemeProviderProps } from '../theme';\nimport { BreakpointProvider } from '../breakpoint';\nimport { RenderRenderar } from './Renderar';\nimport { DocumentProvider } from '../Document';\nimport { AppRootProvider } from './AppRootProvider';\nimport useMergeRefs from '../hooks/useMergeRefs';\nimport { CSSCacheProvider } from '../css/CSSCacheProvider';\nimport { BreakpointKeys } from '../css/types';\n\nexport type AppRootProps<T extends TagComponentType = \"div\"> = ThemeProviderProps<T> & {\n noScrollbarCss?: boolean;\n document?: Document;\n CSSCacheId?: string;\n disableRenderar?: boolean;\n defaultBreakpoint?: BreakpointKeys\n selectionColor?: \"default\" | \"brand\" | \"accent\" | \"success\" | \"info\" | \"warning\" | \"danger\";\n}\n\nconst AppRoot = React.forwardRef(<T extends TagComponentType = \"div\">({ children, defaultBreakpoint, noScrollbarCss, CSSCacheId, theme, onThemeChange, disableRenderar, selectionColor, document: _document, ...props }: AppRootProps<T>, ref: React.Ref<any>) => {\n\n noScrollbarCss ??= false\n selectionColor ??= \"brand\"\n if (typeof window !== \"undefined\") {\n _document ??= document\n }\n disableRenderar ??= false\n const docid = useId()\n const csscacheId = useId()\n CSSCacheId ??= csscacheId\n\n const [visibility, setVisibility] = React.useState<string>(!defaultBreakpoint ? \"hidden\" : \"\");\n const rootRef = useRef(null)\n const mergeRef = useMergeRefs(rootRef, ref)\n\n useLayoutEffect(() => {\n !defaultBreakpoint && setVisibility(\"\");\n }, [])\n\n useEffect(() => {\n if (typeof _document === 'undefined') return;\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/AppRoot/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useId, useLayoutEffect, useRef } from 'react';\nimport { TagComponentType } from '../Tag/types';\nimport { ThemeProvider, ThemeProviderProps } from '../theme';\nimport { BreakpointProvider } from '../breakpoint';\nimport { RenderRenderar } from './Renderar';\nimport { DocumentProvider } from '../Document';\nimport { AppRootProvider } from './AppRootProvider';\nimport useMergeRefs from '../hooks/useMergeRefs';\nimport { CSSCacheProvider } from '../css/CSSCacheProvider';\nimport { BreakpointKeys } from '../css/types';\nimport Cookie from '../cookie';\n\nexport type AppRootProps<T extends TagComponentType = \"div\"> = ThemeProviderProps<T> & {\n noScrollbarCss?: boolean;\n document?: Document;\n CSSCacheId?: string;\n disableRenderar?: boolean;\n defaultBreakpoint?: BreakpointKeys\n selectionColor?: \"default\" | \"brand\" | \"accent\" | \"success\" | \"info\" | \"warning\" | \"danger\";\n}\n\nconst AppRoot = React.forwardRef(<T extends TagComponentType = \"div\">({ children, defaultBreakpoint, noScrollbarCss, CSSCacheId, theme, onThemeChange, disableRenderar, selectionColor, document: _document, ...props }: AppRootProps<T>, ref: React.Ref<any>) => {\n\n noScrollbarCss ??= false\n selectionColor ??= \"brand\"\n if (typeof window !== \"undefined\") {\n _document ??= document\n }\n disableRenderar ??= false\n const docid = useId()\n const csscacheId = useId()\n CSSCacheId ??= csscacheId\n\n const [visibility, setVisibility] = React.useState<string>(!defaultBreakpoint ? \"hidden\" : \"\");\n const rootRef = useRef(null)\n const mergeRef = useMergeRefs(rootRef, ref)\n\n useLayoutEffect(() => {\n !defaultBreakpoint && setVisibility(\"\");\n }, [])\n\n useEffect(() => {\n if (typeof _document === 'undefined') return;\n if (!Cookie.exists(\"xuitm\")) {\n Cookie.set(\"xuitm\", theme.name)\n }\n\n const styles = Array.from(_document.querySelectorAll('body style[data-oncss]'));\n styles.forEach((style) => {\n _document.head.appendChild(style);\n });\n }, [])\n\n let selection: any = {}\n if (selectionColor && selectionColor !== 'default') {\n selection = {\n \"&::selection\": {\n bgcolor: `${selectionColor}.primary`,\n color: `${selectionColor}.text`\n }\n }\n }\n\n return (\n <DocumentProvider value={_document ? { document: _document, id: docid } : undefined}>\n <CSSCacheProvider cacheId={CSSCacheId}>\n <AppRootProvider element={() => rootRef.current}>\n <ThemeProvider\n theme={theme}\n onThemeChange={(t) => {\n onThemeChange && onThemeChange(t)\n Cookie.set(\"xuitm\", t.name)\n }}\n {...props}\n ref={mergeRef}\n isRoot\n sx={{\n ...props.sx,\n ...(visibility === \"hidden\" ? { visibility: \"hidden\" } : {}),\n ...selection\n }}\n >\n <BreakpointProvider defaultKey={defaultBreakpoint ?? \"xl\"}>\n {children}\n {!disableRenderar && <RenderRenderar />}\n </BreakpointProvider>\n </ThemeProvider>\n </AppRootProvider>\n </CSSCacheProvider>\n </DocumentProvider>\n )\n})\n\nexport default AppRoot\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAsBA;;;;AAIG;;;;AAIA;AACA;;;AAIA;;;AAIG;;;;;;;;AASA;AACA;AACG;AACH;;;AAIH;AACG;AACG;;;AAGC;;;;AAWW;;AAEH;AAmBlB;;"}
|
package/Transition/index.cjs
CHANGED
|
@@ -35,19 +35,10 @@ function Transition(_a) {
|
|
|
35
35
|
if (!isDisableInitial || (isDisableInitial && !open)) {
|
|
36
36
|
props.opacity = 0;
|
|
37
37
|
props.pointerEvents = 'none';
|
|
38
|
+
props.transition = 'none';
|
|
38
39
|
}
|
|
39
40
|
return style(props);
|
|
40
41
|
});
|
|
41
|
-
// useEffect(() => {
|
|
42
|
-
// const node = ref.current
|
|
43
|
-
// if (!node) return
|
|
44
|
-
// const observer = new ResizeObserver(() => {
|
|
45
|
-
// const rect = node.getBoundingClientRect()
|
|
46
|
-
// setRect(rect)
|
|
47
|
-
// })
|
|
48
|
-
// observer.observe(node)
|
|
49
|
-
// return () => observer.disconnect()
|
|
50
|
-
// }, [])
|
|
51
42
|
React.useEffect(() => {
|
|
52
43
|
let frame;
|
|
53
44
|
const measure = () => {
|
|
@@ -58,12 +49,10 @@ function Transition(_a) {
|
|
|
58
49
|
}
|
|
59
50
|
const rect = node.getBoundingClientRect();
|
|
60
51
|
const v = getVariant(rect, variant);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
setCls(style(open ? v.from : v.to));
|
|
66
|
-
}
|
|
52
|
+
const initial = isDisableInitial
|
|
53
|
+
? (open ? v.to : v.from)
|
|
54
|
+
: (open ? v.from : v.to);
|
|
55
|
+
setCls(style(Object.assign(Object.assign({}, initial), { transition: 'none' })));
|
|
67
56
|
setRect(rect);
|
|
68
57
|
};
|
|
69
58
|
frame = requestAnimationFrame(measure);
|
package/Transition/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Transition/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { cloneElement, Children, useState, useEffect, useRef } from 'react';\nimport * as variants from './variants'\nimport { css } from '../css';\nimport { useDocument } from '../Document';\nimport { useCSSCacheId } from '../css/CSSCacheProvider';\nimport { animationEases } from '../hooks/useAnimation';\nimport { formatCSSProp } from 'oncss';\nimport { CSSProps } from '../css/types';\n\nexport type TransitionVariantTypes = keyof typeof variants\nexport type TransitionVariant = TransitionVariantTypes | ((rect: DOMRect) => ({ from: CSSProps, to: CSSProps }))\nexport type TransitionState = \"open\" | \"opened\" | \"close\" | \"closed\"\n\nexport type TransitionProps = {\n children: React.ReactElement;\n open: boolean;\n variant: TransitionVariant\n ease?: string;\n easing?: keyof typeof animationEases;\n duration?: number;\n delay?: number;\n disableInitialTransition?: boolean;\n onOpen?: () => void;\n onOpened?: () => void;\n onClose?: () => void;\n onClosed?: () => void;\n onState?: (state: TransitionState) => void;\n}\n\nconst getVariant = (rect: DOMRect, variant: TransitionVariant) => {\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\nfunction Transition({ children, ...options }: TransitionProps) {\n let {\n disableInitialTransition = false,\n variant = \"fade\",\n duration = 400,\n delay,\n ease,\n easing,\n open,\n onOpen,\n onOpened,\n onClose,\n onClosed,\n onState\n } = options\n\n const endTimer = useRef<any>(null)\n const animId = useRef(0)\n const [rect, setRect] = useState<DOMRect>()\n const [isDisableInitial, setIsDisableInitial] = useState(disableInitialTransition)\n const ref = useRef<HTMLElement>(null)\n const doc = useDocument();\n const cacheId = useCSSCacheId()\n let _ease = ease || (animationEases as any)[easing as any] || animationEases.bounce\n\n const style = (obj = {}) => {\n return css(obj, { container: doc?.document, cacheId }).classname;\n }\n\n let [cls, setCls] = useState(() => {\n let props: any = {}\n if (!isDisableInitial || (isDisableInitial && !open)) {\n props.opacity = 0\n props.pointerEvents = 'none'\n
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Transition/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { cloneElement, Children, useState, useEffect, useRef } from 'react';\nimport * as variants from './variants'\nimport { css } from '../css';\nimport { useDocument } from '../Document';\nimport { useCSSCacheId } from '../css/CSSCacheProvider';\nimport { animationEases } from '../hooks/useAnimation';\nimport { formatCSSProp } from 'oncss';\nimport { CSSProps } from '../css/types';\n\nexport type TransitionVariantTypes = keyof typeof variants\nexport type TransitionVariant = TransitionVariantTypes | ((rect: DOMRect) => ({ from: CSSProps, to: CSSProps }))\nexport type TransitionState = \"open\" | \"opened\" | \"close\" | \"closed\"\n\nexport type TransitionProps = {\n children: React.ReactElement;\n open: boolean;\n variant: TransitionVariant\n ease?: string;\n easing?: keyof typeof animationEases;\n duration?: number;\n delay?: number;\n disableInitialTransition?: boolean;\n onOpen?: () => void;\n onOpened?: () => void;\n onClose?: () => void;\n onClosed?: () => void;\n onState?: (state: TransitionState) => void;\n}\n\nconst getVariant = (rect: DOMRect, variant: TransitionVariant) => {\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\nfunction Transition({ children, ...options }: TransitionProps) {\n let {\n disableInitialTransition = false,\n variant = \"fade\",\n duration = 400,\n delay,\n ease,\n easing,\n open,\n onOpen,\n onOpened,\n onClose,\n onClosed,\n onState\n } = options\n\n const endTimer = useRef<any>(null)\n const animId = useRef(0)\n const [rect, setRect] = useState<DOMRect>()\n const [isDisableInitial, setIsDisableInitial] = useState(disableInitialTransition)\n const ref = useRef<HTMLElement>(null)\n const doc = useDocument();\n const cacheId = useCSSCacheId()\n let _ease = ease || (animationEases as any)[easing as any] || animationEases.bounce\n\n const style = (obj = {}) => {\n return css(obj, { container: doc?.document, cacheId }).classname;\n }\n\n let [cls, setCls] = useState(() => {\n let props: any = {}\n if (!isDisableInitial || (isDisableInitial && !open)) {\n props.opacity = 0\n props.pointerEvents = 'none'\n props.transition = 'none'\n }\n return style(props)\n })\n\n\n useEffect(() => {\n let frame: any\n const measure = () => {\n const node = ref.current\n if (!node) {\n frame = requestAnimationFrame(measure) // ⬅️ retry next frame\n return\n }\n\n const rect = node.getBoundingClientRect()\n const v = getVariant(rect, variant)\n const initial = isDisableInitial\n ? (open ? v.to : v.from)\n : (open ? v.from : v.to)\n\n setCls(style({\n ...initial,\n transition: 'none'\n }))\n setRect(rect)\n }\n\n frame = requestAnimationFrame(measure)\n\n return () => {\n if (endTimer.current) {\n clearTimeout(endTimer.current)\n }\n cancelAnimationFrame(frame)\n }\n\n }, [])\n\n useEffect(() => {\n if (rect) {\n let _duration = isDisableInitial ? 0 : duration\n let _delay = isDisableInitial ? 0 : (delay || 0)\n\n if (isDisableInitial) {\n setIsDisableInitial(false)\n }\n const v = getVariant(rect, variant)\n let _css: any = open ? v.to : v.from\n\n let _ = {\n ..._css,\n transition: Object.keys(_css || {})\n .map(k => `${formatCSSProp(k)} ${_duration}ms ${_ease} ${_delay}ms`)\n .join(\", \"),\n willChange: Object.keys(_css || {})\n .map(formatCSSProp)\n .join(\", \"),\n }\n\n if (open) {\n onOpen?.();\n onState?.(\"open\");\n } else {\n onClose?.();\n onState?.(\"close\");\n }\n\n setCls(style(_))\n if (endTimer.current) {\n clearTimeout(endTimer.current)\n }\n animId.current++\n const id = animId.current\n endTimer.current = setTimeout(() => {\n if (id !== animId.current) return\n if (open) {\n onOpened?.();\n onState?.(\"opened\");\n } else {\n onClosed?.();\n onState?.(\"closed\");\n }\n }, _duration + _delay)\n }\n }, [rect, open, variant])\n\n const clone: any = Children.only(children);\n\n return cloneElement(clone, {\n className: cls,\n ref: (node: HTMLElement) => {\n ref.current = node;\n\n const childRef = (clone as any).ref;\n if (typeof childRef === \"function\") {\n childRef(node);\n } else if (childRef) {\n childRef.current = node;\n }\n }\n });\n}\n\nexport default Transition"],"names":[],"mappings":";;;;;;;;;;;;AA8BA;AACI;AACA;AAAS;AACT;AACJ;AAEA;AAAoB;AAChB;AAeA;AACA;;;AAGA;AACA;AACA;AACA;AAEA;;AAEA;;;;AAKQ;AACA;AACA;;AAEJ;AACJ;;AAII;;AAEI;;AAEI;;;AAIJ;;;AAGI;AACA;;;AAOR;AAEA;AAEA;AACI;AACI;;;AAGR;;;;;AAOI;;;;;AAMA;AAEA;AAGS;AACA;;AAGA;;AAIL;AACA;;;AAEA;AACA;;AAGJ;AACA;AACI;;;AAGJ;AACA;AACI;;;AAEI;AACA;;;AAEA;AACA;;AAER;;;;;AAOJ;AACA;AACI;AAEA;AACA;;;;AAGI;;;AAGX;AACL;;"}
|
package/Transition/index.js
CHANGED
|
@@ -33,19 +33,10 @@ function Transition(_a) {
|
|
|
33
33
|
if (!isDisableInitial || (isDisableInitial && !open)) {
|
|
34
34
|
props.opacity = 0;
|
|
35
35
|
props.pointerEvents = 'none';
|
|
36
|
+
props.transition = 'none';
|
|
36
37
|
}
|
|
37
38
|
return style(props);
|
|
38
39
|
});
|
|
39
|
-
// useEffect(() => {
|
|
40
|
-
// const node = ref.current
|
|
41
|
-
// if (!node) return
|
|
42
|
-
// const observer = new ResizeObserver(() => {
|
|
43
|
-
// const rect = node.getBoundingClientRect()
|
|
44
|
-
// setRect(rect)
|
|
45
|
-
// })
|
|
46
|
-
// observer.observe(node)
|
|
47
|
-
// return () => observer.disconnect()
|
|
48
|
-
// }, [])
|
|
49
40
|
useEffect(() => {
|
|
50
41
|
let frame;
|
|
51
42
|
const measure = () => {
|
|
@@ -56,12 +47,10 @@ function Transition(_a) {
|
|
|
56
47
|
}
|
|
57
48
|
const rect = node.getBoundingClientRect();
|
|
58
49
|
const v = getVariant(rect, variant);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
setCls(style(open ? v.from : v.to));
|
|
64
|
-
}
|
|
50
|
+
const initial = isDisableInitial
|
|
51
|
+
? (open ? v.to : v.from)
|
|
52
|
+
: (open ? v.from : v.to);
|
|
53
|
+
setCls(style(Object.assign(Object.assign({}, initial), { transition: 'none' })));
|
|
65
54
|
setRect(rect);
|
|
66
55
|
};
|
|
67
56
|
frame = requestAnimationFrame(measure);
|
package/Transition/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Transition/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { cloneElement, Children, useState, useEffect, useRef } from 'react';\nimport * as variants from './variants'\nimport { css } from '../css';\nimport { useDocument } from '../Document';\nimport { useCSSCacheId } from '../css/CSSCacheProvider';\nimport { animationEases } from '../hooks/useAnimation';\nimport { formatCSSProp } from 'oncss';\nimport { CSSProps } from '../css/types';\n\nexport type TransitionVariantTypes = keyof typeof variants\nexport type TransitionVariant = TransitionVariantTypes | ((rect: DOMRect) => ({ from: CSSProps, to: CSSProps }))\nexport type TransitionState = \"open\" | \"opened\" | \"close\" | \"closed\"\n\nexport type TransitionProps = {\n children: React.ReactElement;\n open: boolean;\n variant: TransitionVariant\n ease?: string;\n easing?: keyof typeof animationEases;\n duration?: number;\n delay?: number;\n disableInitialTransition?: boolean;\n onOpen?: () => void;\n onOpened?: () => void;\n onClose?: () => void;\n onClosed?: () => void;\n onState?: (state: TransitionState) => void;\n}\n\nconst getVariant = (rect: DOMRect, variant: TransitionVariant) => {\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\nfunction Transition({ children, ...options }: TransitionProps) {\n let {\n disableInitialTransition = false,\n variant = \"fade\",\n duration = 400,\n delay,\n ease,\n easing,\n open,\n onOpen,\n onOpened,\n onClose,\n onClosed,\n onState\n } = options\n\n const endTimer = useRef<any>(null)\n const animId = useRef(0)\n const [rect, setRect] = useState<DOMRect>()\n const [isDisableInitial, setIsDisableInitial] = useState(disableInitialTransition)\n const ref = useRef<HTMLElement>(null)\n const doc = useDocument();\n const cacheId = useCSSCacheId()\n let _ease = ease || (animationEases as any)[easing as any] || animationEases.bounce\n\n const style = (obj = {}) => {\n return css(obj, { container: doc?.document, cacheId }).classname;\n }\n\n let [cls, setCls] = useState(() => {\n let props: any = {}\n if (!isDisableInitial || (isDisableInitial && !open)) {\n props.opacity = 0\n props.pointerEvents = 'none'\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Transition/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { cloneElement, Children, useState, useEffect, useRef } from 'react';\nimport * as variants from './variants'\nimport { css } from '../css';\nimport { useDocument } from '../Document';\nimport { useCSSCacheId } from '../css/CSSCacheProvider';\nimport { animationEases } from '../hooks/useAnimation';\nimport { formatCSSProp } from 'oncss';\nimport { CSSProps } from '../css/types';\n\nexport type TransitionVariantTypes = keyof typeof variants\nexport type TransitionVariant = TransitionVariantTypes | ((rect: DOMRect) => ({ from: CSSProps, to: CSSProps }))\nexport type TransitionState = \"open\" | \"opened\" | \"close\" | \"closed\"\n\nexport type TransitionProps = {\n children: React.ReactElement;\n open: boolean;\n variant: TransitionVariant\n ease?: string;\n easing?: keyof typeof animationEases;\n duration?: number;\n delay?: number;\n disableInitialTransition?: boolean;\n onOpen?: () => void;\n onOpened?: () => void;\n onClose?: () => void;\n onClosed?: () => void;\n onState?: (state: TransitionState) => void;\n}\n\nconst getVariant = (rect: DOMRect, variant: TransitionVariant) => {\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\nfunction Transition({ children, ...options }: TransitionProps) {\n let {\n disableInitialTransition = false,\n variant = \"fade\",\n duration = 400,\n delay,\n ease,\n easing,\n open,\n onOpen,\n onOpened,\n onClose,\n onClosed,\n onState\n } = options\n\n const endTimer = useRef<any>(null)\n const animId = useRef(0)\n const [rect, setRect] = useState<DOMRect>()\n const [isDisableInitial, setIsDisableInitial] = useState(disableInitialTransition)\n const ref = useRef<HTMLElement>(null)\n const doc = useDocument();\n const cacheId = useCSSCacheId()\n let _ease = ease || (animationEases as any)[easing as any] || animationEases.bounce\n\n const style = (obj = {}) => {\n return css(obj, { container: doc?.document, cacheId }).classname;\n }\n\n let [cls, setCls] = useState(() => {\n let props: any = {}\n if (!isDisableInitial || (isDisableInitial && !open)) {\n props.opacity = 0\n props.pointerEvents = 'none'\n props.transition = 'none'\n }\n return style(props)\n })\n\n\n useEffect(() => {\n let frame: any\n const measure = () => {\n const node = ref.current\n if (!node) {\n frame = requestAnimationFrame(measure) // ⬅️ retry next frame\n return\n }\n\n const rect = node.getBoundingClientRect()\n const v = getVariant(rect, variant)\n const initial = isDisableInitial\n ? (open ? v.to : v.from)\n : (open ? v.from : v.to)\n\n setCls(style({\n ...initial,\n transition: 'none'\n }))\n setRect(rect)\n }\n\n frame = requestAnimationFrame(measure)\n\n return () => {\n if (endTimer.current) {\n clearTimeout(endTimer.current)\n }\n cancelAnimationFrame(frame)\n }\n\n }, [])\n\n useEffect(() => {\n if (rect) {\n let _duration = isDisableInitial ? 0 : duration\n let _delay = isDisableInitial ? 0 : (delay || 0)\n\n if (isDisableInitial) {\n setIsDisableInitial(false)\n }\n const v = getVariant(rect, variant)\n let _css: any = open ? v.to : v.from\n\n let _ = {\n ..._css,\n transition: Object.keys(_css || {})\n .map(k => `${formatCSSProp(k)} ${_duration}ms ${_ease} ${_delay}ms`)\n .join(\", \"),\n willChange: Object.keys(_css || {})\n .map(formatCSSProp)\n .join(\", \"),\n }\n\n if (open) {\n onOpen?.();\n onState?.(\"open\");\n } else {\n onClose?.();\n onState?.(\"close\");\n }\n\n setCls(style(_))\n if (endTimer.current) {\n clearTimeout(endTimer.current)\n }\n animId.current++\n const id = animId.current\n endTimer.current = setTimeout(() => {\n if (id !== animId.current) return\n if (open) {\n onOpened?.();\n onState?.(\"opened\");\n } else {\n onClosed?.();\n onState?.(\"closed\");\n }\n }, _duration + _delay)\n }\n }, [rect, open, variant])\n\n const clone: any = Children.only(children);\n\n return cloneElement(clone, {\n className: cls,\n ref: (node: HTMLElement) => {\n ref.current = node;\n\n const childRef = (clone as any).ref;\n if (typeof childRef === \"function\") {\n childRef(node);\n } else if (childRef) {\n childRef.current = node;\n }\n }\n });\n}\n\nexport default Transition"],"names":[],"mappings":";;;;;;;;;;AA8BA;AACI;AACA;AAAS;AACT;AACJ;AAEA;AAAoB;AAChB;AAeA;AACA;;;AAGA;AACA;AACA;AACA;AAEA;;AAEA;;;;AAKQ;AACA;AACA;;AAEJ;AACJ;;AAII;;AAEI;;AAEI;;;AAIJ;;;AAGI;AACA;;;AAOR;AAEA;AAEA;AACI;AACI;;;AAGR;;;;;AAOI;;;;;AAMA;AAEA;AAGS;AACA;;AAGA;;AAIL;AACA;;;AAEA;AACA;;AAGJ;AACA;AACI;;;AAGJ;AACA;AACI;;;AAEI;AACA;;;AAEA;AACA;;AAER;;;;;AAOJ;AACA;AACI;AAEA;AACA;;;;AAGI;;;AAGX;AACL;;"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var index = require('../css/index.cjs');
|
|
7
|
+
var cookie = require('../cookie.cjs');
|
|
7
8
|
|
|
8
9
|
const BreakpointCtx = React.createContext(null);
|
|
9
10
|
const queries = {
|
|
@@ -29,13 +30,13 @@ const BreakpointProvider = ({ children, defaultKey }) => {
|
|
|
29
30
|
React.useEffect(() => {
|
|
30
31
|
const current = getCurrent(defaultKey);
|
|
31
32
|
setCurrent(current);
|
|
32
|
-
|
|
33
|
+
cookie.set("xuibp", current);
|
|
33
34
|
const mqls = Object.entries(queries).map(([key, query]) => {
|
|
34
35
|
const mql = window.matchMedia(query);
|
|
35
36
|
const handler = () => {
|
|
36
37
|
if (mql.matches) {
|
|
37
38
|
setCurrent(key);
|
|
38
|
-
|
|
39
|
+
cookie.set("xuibp", key);
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
42
|
mql.addEventListener("change", handler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BreakpointProvider.cjs","sources":["../../src/breakpoint/BreakpointProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { ReactNode, useEffect, useState } from \"react\";\nimport { breakpoints } from \"../css\";\nimport { BreakpointKeys } from \"../css/types\";\n\nexport const BreakpointCtx = React.createContext<BreakpointKeys | null>(null);\n\nconst queries: Record<BreakpointKeys, string> = {\n xs: `(max-width:${breakpoints.sm - 0.02}px)`,\n sm: `(min-width:${breakpoints.sm}px) and (max-width:${breakpoints.md - 0.02}px)`,\n md: `(min-width:${breakpoints.md}px) and (max-width:${breakpoints.lg - 0.02}px)`,\n lg: `(min-width:${breakpoints.lg}px) and (max-width:${breakpoints.xl - 0.02}px)`,\n xl: `(min-width:${breakpoints.xl}px)`\n};\n\nconst getCurrent = (def: BreakpointKeys): BreakpointKeys => {\n if (typeof window === \"undefined\") return def;\n const entries = Object.entries(queries) as [BreakpointKeys, string][];\n for (const [key, query] of entries) {\n if (window.matchMedia(query).matches) {\n return key;\n }\n }\n return def;\n};\n\nexport const BreakpointProvider = ({ children, defaultKey }: { children?: ReactNode, defaultKey: BreakpointKeys }) => {\n const [current, setCurrent] = useState<BreakpointKeys>(defaultKey);\n\n useEffect(() => {\n const current = getCurrent(defaultKey)\n setCurrent(current)\n
|
|
1
|
+
{"version":3,"file":"BreakpointProvider.cjs","sources":["../../src/breakpoint/BreakpointProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { ReactNode, useEffect, useState } from \"react\";\nimport { breakpoints } from \"../css\";\nimport { BreakpointKeys } from \"../css/types\";\nimport Cookie from \"../cookie\";\n\nexport const BreakpointCtx = React.createContext<BreakpointKeys | null>(null);\n\nconst queries: Record<BreakpointKeys, string> = {\n xs: `(max-width:${breakpoints.sm - 0.02}px)`,\n sm: `(min-width:${breakpoints.sm}px) and (max-width:${breakpoints.md - 0.02}px)`,\n md: `(min-width:${breakpoints.md}px) and (max-width:${breakpoints.lg - 0.02}px)`,\n lg: `(min-width:${breakpoints.lg}px) and (max-width:${breakpoints.xl - 0.02}px)`,\n xl: `(min-width:${breakpoints.xl}px)`\n};\n\nconst getCurrent = (def: BreakpointKeys): BreakpointKeys => {\n if (typeof window === \"undefined\") return def;\n const entries = Object.entries(queries) as [BreakpointKeys, string][];\n for (const [key, query] of entries) {\n if (window.matchMedia(query).matches) {\n return key;\n }\n }\n return def;\n};\n\nexport const BreakpointProvider = ({ children, defaultKey }: { children?: ReactNode, defaultKey: BreakpointKeys }) => {\n const [current, setCurrent] = useState<BreakpointKeys>(defaultKey);\n\n useEffect(() => {\n const current = getCurrent(defaultKey)\n setCurrent(current)\n Cookie.set(\"xuibp\", current)\n const mqls = Object.entries(queries).map(([key, query]) => {\n const mql = window.matchMedia(query);\n const handler = () => {\n if (mql.matches) {\n setCurrent(key as BreakpointKeys);\n Cookie.set(\"xuibp\", key)\n }\n };\n\n mql.addEventListener(\"change\", handler);\n\n return () => mql.removeEventListener(\"change\", handler);\n });\n\n return () => {\n mqls.forEach(fn => fn());\n };\n }, []);\n\n return (\n <BreakpointCtx.Provider value={current}>\n {children}\n </BreakpointCtx.Provider>\n );\n};"],"names":[],"mappings":";;;;;;;;AAOO;AAEP;AACI;;;;AAIA;;AAGJ;;AACuC;;;;AAI3B;;;AAGR;AACJ;AAEO;;;AAIC;;AAEA;AACA;;;AAGQ;;AAEI;;AAER;AAEA;;AAGJ;AAEA;;AAEA;;AAGJ;AAKJ;;;"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import React__default, { useState, useEffect } from 'react';
|
|
4
4
|
import { breakpoints } from '../css/index.js';
|
|
5
|
+
import Cookie from '../cookie.js';
|
|
5
6
|
|
|
6
7
|
const BreakpointCtx = React__default.createContext(null);
|
|
7
8
|
const queries = {
|
|
@@ -27,13 +28,13 @@ const BreakpointProvider = ({ children, defaultKey }) => {
|
|
|
27
28
|
useEffect(() => {
|
|
28
29
|
const current = getCurrent(defaultKey);
|
|
29
30
|
setCurrent(current);
|
|
30
|
-
|
|
31
|
+
Cookie.set("xuibp", current);
|
|
31
32
|
const mqls = Object.entries(queries).map(([key, query]) => {
|
|
32
33
|
const mql = window.matchMedia(query);
|
|
33
34
|
const handler = () => {
|
|
34
35
|
if (mql.matches) {
|
|
35
36
|
setCurrent(key);
|
|
36
|
-
|
|
37
|
+
Cookie.set("xuibp", key);
|
|
37
38
|
}
|
|
38
39
|
};
|
|
39
40
|
mql.addEventListener("change", handler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BreakpointProvider.js","sources":["../../src/breakpoint/BreakpointProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { ReactNode, useEffect, useState } from \"react\";\nimport { breakpoints } from \"../css\";\nimport { BreakpointKeys } from \"../css/types\";\n\nexport const BreakpointCtx = React.createContext<BreakpointKeys | null>(null);\n\nconst queries: Record<BreakpointKeys, string> = {\n xs: `(max-width:${breakpoints.sm - 0.02}px)`,\n sm: `(min-width:${breakpoints.sm}px) and (max-width:${breakpoints.md - 0.02}px)`,\n md: `(min-width:${breakpoints.md}px) and (max-width:${breakpoints.lg - 0.02}px)`,\n lg: `(min-width:${breakpoints.lg}px) and (max-width:${breakpoints.xl - 0.02}px)`,\n xl: `(min-width:${breakpoints.xl}px)`\n};\n\nconst getCurrent = (def: BreakpointKeys): BreakpointKeys => {\n if (typeof window === \"undefined\") return def;\n const entries = Object.entries(queries) as [BreakpointKeys, string][];\n for (const [key, query] of entries) {\n if (window.matchMedia(query).matches) {\n return key;\n }\n }\n return def;\n};\n\nexport const BreakpointProvider = ({ children, defaultKey }: { children?: ReactNode, defaultKey: BreakpointKeys }) => {\n const [current, setCurrent] = useState<BreakpointKeys>(defaultKey);\n\n useEffect(() => {\n const current = getCurrent(defaultKey)\n setCurrent(current)\n
|
|
1
|
+
{"version":3,"file":"BreakpointProvider.js","sources":["../../src/breakpoint/BreakpointProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { ReactNode, useEffect, useState } from \"react\";\nimport { breakpoints } from \"../css\";\nimport { BreakpointKeys } from \"../css/types\";\nimport Cookie from \"../cookie\";\n\nexport const BreakpointCtx = React.createContext<BreakpointKeys | null>(null);\n\nconst queries: Record<BreakpointKeys, string> = {\n xs: `(max-width:${breakpoints.sm - 0.02}px)`,\n sm: `(min-width:${breakpoints.sm}px) and (max-width:${breakpoints.md - 0.02}px)`,\n md: `(min-width:${breakpoints.md}px) and (max-width:${breakpoints.lg - 0.02}px)`,\n lg: `(min-width:${breakpoints.lg}px) and (max-width:${breakpoints.xl - 0.02}px)`,\n xl: `(min-width:${breakpoints.xl}px)`\n};\n\nconst getCurrent = (def: BreakpointKeys): BreakpointKeys => {\n if (typeof window === \"undefined\") return def;\n const entries = Object.entries(queries) as [BreakpointKeys, string][];\n for (const [key, query] of entries) {\n if (window.matchMedia(query).matches) {\n return key;\n }\n }\n return def;\n};\n\nexport const BreakpointProvider = ({ children, defaultKey }: { children?: ReactNode, defaultKey: BreakpointKeys }) => {\n const [current, setCurrent] = useState<BreakpointKeys>(defaultKey);\n\n useEffect(() => {\n const current = getCurrent(defaultKey)\n setCurrent(current)\n Cookie.set(\"xuibp\", current)\n const mqls = Object.entries(queries).map(([key, query]) => {\n const mql = window.matchMedia(query);\n const handler = () => {\n if (mql.matches) {\n setCurrent(key as BreakpointKeys);\n Cookie.set(\"xuibp\", key)\n }\n };\n\n mql.addEventListener(\"change\", handler);\n\n return () => mql.removeEventListener(\"change\", handler);\n });\n\n return () => {\n mqls.forEach(fn => fn());\n };\n }, []);\n\n return (\n <BreakpointCtx.Provider value={current}>\n {children}\n </BreakpointCtx.Provider>\n );\n};"],"names":[],"mappings":";;;;;;AAOO;AAEP;AACI;;;;AAIA;;AAGJ;;AACuC;;;;AAI3B;;;AAGR;AACJ;AAEO;;;AAIC;;AAEA;AACA;;;AAGQ;;AAEI;;AAER;AAEA;;AAGJ;AAEA;;AAEA;;AAGJ;AAKJ;;"}
|
package/cookie.cjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// cookieUtils.ts
|
|
4
|
+
const Cookie = {
|
|
5
|
+
/**
|
|
6
|
+
* Set a cookie
|
|
7
|
+
* @param name - cookie name
|
|
8
|
+
* @param value - cookie value
|
|
9
|
+
* @param days - optional, number of days to expire, default 36500 (~100 years)
|
|
10
|
+
*/
|
|
11
|
+
set: (name, value, days = 36500) => {
|
|
12
|
+
const expires = new Date();
|
|
13
|
+
expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
|
|
14
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires.toUTCString()}; path=/`;
|
|
15
|
+
},
|
|
16
|
+
/**
|
|
17
|
+
* Get a cookie by name
|
|
18
|
+
* @param name - cookie name
|
|
19
|
+
* @returns value or null
|
|
20
|
+
*/
|
|
21
|
+
// get: (name: string) => {
|
|
22
|
+
// const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
|
|
23
|
+
// return match ? decodeURIComponent(match[1]) : null;
|
|
24
|
+
// },
|
|
25
|
+
/**
|
|
26
|
+
* Delete a cookie
|
|
27
|
+
* @param name - cookie name
|
|
28
|
+
*/
|
|
29
|
+
// delete: (name: string) => {
|
|
30
|
+
// document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
|
|
31
|
+
// },
|
|
32
|
+
/**
|
|
33
|
+
* Check if a cookie exists
|
|
34
|
+
* @param name - cookie name
|
|
35
|
+
* @returns boolean
|
|
36
|
+
*/
|
|
37
|
+
exists: (name) => {
|
|
38
|
+
return document.cookie.split("; ").some(c => c.startsWith(`${name}=`));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports = Cookie;
|
|
43
|
+
//# sourceMappingURL=cookie.cjs.map
|
package/cookie.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.cjs","sources":["../src/cookie.ts"],"sourcesContent":["// cookieUtils.ts\nconst Cookie = {\n /**\n * Set a cookie\n * @param name - cookie name\n * @param value - cookie value\n * @param days - optional, number of days to expire, default 36500 (~100 years)\n */\n set: (name: string, value: string, days = 36500) => {\n const expires = new Date();\n expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);\n document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires.toUTCString()}; path=/`;\n },\n\n /**\n * Get a cookie by name\n * @param name - cookie name\n * @returns value or null\n */\n // get: (name: string) => {\n // const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));\n // return match ? decodeURIComponent(match[1]) : null;\n // },\n\n /**\n * Delete a cookie\n * @param name - cookie name\n */\n // delete: (name: string) => {\n // document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;\n // },\n\n /**\n * Check if a cookie exists\n * @param name - cookie name\n * @returns boolean\n */\n exists: (name: string) => {\n return document.cookie.split(\"; \").some(c => c.startsWith(`${name}=`));\n }\n};\n\nexport default Cookie"],"names":[],"mappings":";;AAAA;AACA,MAAM,MAAM,GAAG;AACZ;;;;;AAKG;IACH,GAAG,EAAE,CAAC,IAAY,EAAE,KAAa,EAAE,IAAI,GAAG,KAAK,KAAI;AAChD,QAAA,MAAM,OAAO,GAAG,IAAI,IAAI,EAAE;AAC1B,QAAA,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/D,QAAA,QAAQ,CAAC,MAAM,GAAG,CAAA,EAAG,IAAI,IAAI,kBAAkB,CAAC,KAAK,CAAC,aAAa,OAAO,CAAC,WAAW,EAAE,UAAU;IACrG,CAAC;AAED;;;;AAIG;;;;;AAMH;;;AAGG;;;;AAKH;;;;AAIG;AACH,IAAA,MAAM,EAAE,CAAC,IAAY,KAAI;QACtB,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAA,CAAA,CAAG,CAAC,CAAC;IACzE;;;;;"}
|
package/cookie.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// cookieUtils.ts
|
|
2
|
+
const Cookie = {
|
|
3
|
+
/**
|
|
4
|
+
* Set a cookie
|
|
5
|
+
* @param name - cookie name
|
|
6
|
+
* @param value - cookie value
|
|
7
|
+
* @param days - optional, number of days to expire, default 36500 (~100 years)
|
|
8
|
+
*/
|
|
9
|
+
set: (name, value, days = 36500) => {
|
|
10
|
+
const expires = new Date();
|
|
11
|
+
expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
|
|
12
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires.toUTCString()}; path=/`;
|
|
13
|
+
},
|
|
14
|
+
/**
|
|
15
|
+
* Get a cookie by name
|
|
16
|
+
* @param name - cookie name
|
|
17
|
+
* @returns value or null
|
|
18
|
+
*/
|
|
19
|
+
// get: (name: string) => {
|
|
20
|
+
// const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
|
|
21
|
+
// return match ? decodeURIComponent(match[1]) : null;
|
|
22
|
+
// },
|
|
23
|
+
/**
|
|
24
|
+
* Delete a cookie
|
|
25
|
+
* @param name - cookie name
|
|
26
|
+
*/
|
|
27
|
+
// delete: (name: string) => {
|
|
28
|
+
// document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
|
|
29
|
+
// },
|
|
30
|
+
/**
|
|
31
|
+
* Check if a cookie exists
|
|
32
|
+
* @param name - cookie name
|
|
33
|
+
* @returns boolean
|
|
34
|
+
*/
|
|
35
|
+
exists: (name) => {
|
|
36
|
+
return document.cookie.split("; ").some(c => c.startsWith(`${name}=`));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { Cookie as default };
|
|
41
|
+
//# sourceMappingURL=cookie.js.map
|
package/cookie.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.js","sources":["../src/cookie.ts"],"sourcesContent":["// cookieUtils.ts\nconst Cookie = {\n /**\n * Set a cookie\n * @param name - cookie name\n * @param value - cookie value\n * @param days - optional, number of days to expire, default 36500 (~100 years)\n */\n set: (name: string, value: string, days = 36500) => {\n const expires = new Date();\n expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);\n document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires.toUTCString()}; path=/`;\n },\n\n /**\n * Get a cookie by name\n * @param name - cookie name\n * @returns value or null\n */\n // get: (name: string) => {\n // const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));\n // return match ? decodeURIComponent(match[1]) : null;\n // },\n\n /**\n * Delete a cookie\n * @param name - cookie name\n */\n // delete: (name: string) => {\n // document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;\n // },\n\n /**\n * Check if a cookie exists\n * @param name - cookie name\n * @returns boolean\n */\n exists: (name: string) => {\n return document.cookie.split(\"; \").some(c => c.startsWith(`${name}=`));\n }\n};\n\nexport default Cookie"],"names":[],"mappings":"AAAA;AACA,MAAM,MAAM,GAAG;AACZ;;;;;AAKG;IACH,GAAG,EAAE,CAAC,IAAY,EAAE,KAAa,EAAE,IAAI,GAAG,KAAK,KAAI;AAChD,QAAA,MAAM,OAAO,GAAG,IAAI,IAAI,EAAE;AAC1B,QAAA,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/D,QAAA,QAAQ,CAAC,MAAM,GAAG,CAAA,EAAG,IAAI,IAAI,kBAAkB,CAAC,KAAK,CAAC,aAAa,OAAO,CAAC,WAAW,EAAE,UAAU;IACrG,CAAC;AAED;;;;AAIG;;;;;AAMH;;;AAGG;;;;AAKH;;;;AAIG;AACH,IAAA,MAAM,EAAE,CAAC,IAAY,KAAI;QACtB,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAA,CAAA,CAAG,CAAC,CAAC;IACzE;;;;;"}
|