@xanui/core 1.2.44 → 1.2.45
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/AppRootProvider.cjs +1 -1
- package/AppRoot/AppRootProvider.cjs.map +1 -1
- package/AppRoot/AppRootProvider.js +1 -1
- package/AppRoot/AppRootProvider.js.map +1 -1
- package/AppRoot/index.cjs +3 -1
- package/AppRoot/index.cjs.map +1 -1
- package/AppRoot/index.js +4 -2
- package/AppRoot/index.js.map +1 -1
- package/Document/index.cjs.map +1 -1
- package/Document/index.js.map +1 -1
- package/Tag/useTagProps.cjs +3 -3
- package/Tag/useTagProps.cjs.map +1 -1
- package/Tag/useTagProps.js +3 -3
- package/Tag/useTagProps.js.map +1 -1
- package/breakpoint/BreakpointProvider.cjs +22 -16
- package/breakpoint/BreakpointProvider.cjs.map +1 -1
- package/breakpoint/BreakpointProvider.js +18 -12
- package/breakpoint/BreakpointProvider.js.map +1 -1
- package/hooks/usePortal.cjs +10 -7
- package/hooks/usePortal.cjs.map +1 -1
- package/hooks/usePortal.js +10 -7
- package/hooks/usePortal.js.map +1 -1
- package/hooks/useTransition/index.cjs +7 -7
- package/hooks/useTransition/index.cjs.map +1 -1
- package/hooks/useTransition/index.js +7 -7
- package/hooks/useTransition/index.js.map +1 -1
- package/package.json +1 -1
- package/theme/ThemeProvider.cjs +4 -4
- package/theme/ThemeProvider.cjs.map +1 -1
- package/theme/ThemeProvider.js +4 -4
- package/theme/ThemeProvider.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppRootProvider.cjs","sources":["../../src/AppRoot/AppRootProvider.tsx"],"sourcesContent":["import React from \"react\";\r\n\r\nconst AppRootContext = React.createContext<HTMLElement | null>(null);\r\n\r\nexport const AppRootProvider: React.FC<{ element: HTMLElement | null; children: React.ReactNode }> = ({ element, children }) => {\r\n return (\r\n <AppRootContext.Provider value={element}>\r\n {children}\r\n </AppRootContext.Provider>\r\n );\r\n}\r\n\r\nexport const useAppRootElement = (): HTMLElement => {\r\n const context = React.useContext(AppRootContext);\r\n if (typeof window === 'undefined') {\r\n return null as any;\r\n }\r\n return context as HTMLElement\r\n}\r\n"],"names":["_jsx"],"mappings":";;;;;AAEA,MAAM,cAAc,GAAG,KAAK,CAAC,aAAa,
|
|
1
|
+
{"version":3,"file":"AppRootProvider.cjs","sources":["../../src/AppRoot/AppRootProvider.tsx"],"sourcesContent":["import React from \"react\";\r\n\r\nconst AppRootContext = React.createContext<(() => HTMLElement | null) | null>(null);\r\n\r\nexport const AppRootProvider: React.FC<{ element: () => HTMLElement | null; children: React.ReactNode }> = ({ element, children }) => {\r\n return (\r\n <AppRootContext.Provider value={element}>\r\n {children}\r\n </AppRootContext.Provider>\r\n );\r\n}\r\n\r\nexport const useAppRootElement = (): HTMLElement => {\r\n const context = React.useContext(AppRootContext);\r\n if (typeof window === 'undefined') {\r\n return null as any;\r\n }\r\n\r\n return context!() as HTMLElement\r\n}\r\n"],"names":["_jsx"],"mappings":";;;;;AAEA,MAAM,cAAc,GAAG,KAAK,CAAC,aAAa,CAAoC,IAAI,CAAC;AAE5E,MAAM,eAAe,GAA+E,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAI;AAClI,IAAA,QACGA,cAAA,CAAC,cAAc,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,OAAO,EAAA,QAAA,EACnC,QAAQ,EAAA,CACc;AAEhC;AAEO,MAAM,iBAAiB,GAAG,MAAkB;IAChD,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC;AAChD,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AAChC,QAAA,OAAO,IAAW;IACrB;IAEA,OAAO,OAAQ,EAAiB;AACnC;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppRootProvider.js","sources":["../../src/AppRoot/AppRootProvider.tsx"],"sourcesContent":["import React from \"react\";\r\n\r\nconst AppRootContext = React.createContext<HTMLElement | null>(null);\r\n\r\nexport const AppRootProvider: React.FC<{ element: HTMLElement | null; children: React.ReactNode }> = ({ element, children }) => {\r\n return (\r\n <AppRootContext.Provider value={element}>\r\n {children}\r\n </AppRootContext.Provider>\r\n );\r\n}\r\n\r\nexport const useAppRootElement = (): HTMLElement => {\r\n const context = React.useContext(AppRootContext);\r\n if (typeof window === 'undefined') {\r\n return null as any;\r\n }\r\n return context as HTMLElement\r\n}\r\n"],"names":["React","_jsx"],"mappings":";;;AAEA,MAAM,cAAc,GAAGA,cAAK,CAAC,aAAa,
|
|
1
|
+
{"version":3,"file":"AppRootProvider.js","sources":["../../src/AppRoot/AppRootProvider.tsx"],"sourcesContent":["import React from \"react\";\r\n\r\nconst AppRootContext = React.createContext<(() => HTMLElement | null) | null>(null);\r\n\r\nexport const AppRootProvider: React.FC<{ element: () => HTMLElement | null; children: React.ReactNode }> = ({ element, children }) => {\r\n return (\r\n <AppRootContext.Provider value={element}>\r\n {children}\r\n </AppRootContext.Provider>\r\n );\r\n}\r\n\r\nexport const useAppRootElement = (): HTMLElement => {\r\n const context = React.useContext(AppRootContext);\r\n if (typeof window === 'undefined') {\r\n return null as any;\r\n }\r\n\r\n return context!() as HTMLElement\r\n}\r\n"],"names":["React","_jsx"],"mappings":";;;AAEA,MAAM,cAAc,GAAGA,cAAK,CAAC,aAAa,CAAoC,IAAI,CAAC;AAE5E,MAAM,eAAe,GAA+E,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAI;AAClI,IAAA,QACGC,GAAA,CAAC,cAAc,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,OAAO,EAAA,QAAA,EACnC,QAAQ,EAAA,CACc;AAEhC;AAEO,MAAM,iBAAiB,GAAG,MAAkB;IAChD,MAAM,OAAO,GAAGD,cAAK,CAAC,UAAU,CAAC,cAAc,CAAC;AAChD,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AAChC,QAAA,OAAO,IAAW;IACrB;IAEA,OAAO,OAAQ,EAAiB;AACnC;;;;"}
|
package/AppRoot/index.cjs
CHANGED
|
@@ -24,8 +24,10 @@ const AppRoot = React.forwardRef((_a, ref) => {
|
|
|
24
24
|
const csscacheId = React.useId();
|
|
25
25
|
CSSCacheId !== null && CSSCacheId !== void 0 ? CSSCacheId : (CSSCacheId = csscacheId);
|
|
26
26
|
const [visibility, setVisibility] = React.useState("hidden");
|
|
27
|
+
const [doc, setDoc] = React.useState(_document !== null && _document !== void 0 ? _document : (_document = document));
|
|
27
28
|
const rootRef = React.useRef(null);
|
|
28
29
|
const mergeRef = useMergeRefs(rootRef, ref);
|
|
30
|
+
// console.log(_document);
|
|
29
31
|
React.useEffect(() => {
|
|
30
32
|
setVisibility("visible");
|
|
31
33
|
// move oncss style tags to head
|
|
@@ -36,7 +38,7 @@ const AppRoot = React.forwardRef((_a, ref) => {
|
|
|
36
38
|
_document.head.appendChild(style);
|
|
37
39
|
});
|
|
38
40
|
}, []);
|
|
39
|
-
return (jsxRuntime.jsx(index.DocumentProvider, { document:
|
|
41
|
+
return (jsxRuntime.jsx(index.DocumentProvider, { document: doc, id: docid, children: jsxRuntime.jsx(CSSCacheProvider.CSSCacheProvider, { cacheId: CSSCacheId, children: jsxRuntime.jsx(AppRootProvider.AppRootProvider, { element: () => rootRef.current, children: jsxRuntime.jsx(ThemeProvider, Object.assign({ theme: theme }, props, { ref: mergeRef, isRoot: true, sx: Object.assign(Object.assign({}, props.sx), (visibility === "hidden" ? { visibility: "hidden" } : {})), children: jsxRuntime.jsxs(BreakpointProvider.BreakpointProvider, { children: [children, jsxRuntime.jsx(Renderar.RenderRenderar, {})] }) })) }) }) }));
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
module.exports = AppRoot;
|
package/AppRoot/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/AppRoot/index.tsx"],"sourcesContent":["\"use client\";\r\nimport React, { useEffect, useId, useRef } from 'react';\r\nimport { TagComponentType } from '../Tag/types';\r\nimport { ThemeProvider, ThemeProviderProps } from '../theme';\r\nimport { BreakpointProvider } from '../breakpoint';\r\nimport { RenderRenderar } from './Renderar';\r\nimport { DocumentProvider } from '../Document';\r\nimport { AppRootProvider } from './AppRootProvider';\r\nimport useMergeRefs from '../hooks/useMergeRefs';\r\nimport { CSSCacheProvider } from '../css/CSSCacheProvider';\r\n\r\nexport type AppRootProps<T extends TagComponentType = \"div\"> = ThemeProviderProps<T> & {\r\n noScrollbarCss?: boolean;\r\n document?: Document;\r\n CSSCacheId?: string;\r\n}\r\n\r\nconst AppRoot = React.forwardRef(<T extends TagComponentType = \"div\">({ children, noScrollbarCss, CSSCacheId, theme, document: _document, ...props }: AppRootProps<T>, ref: React.Ref<any>) => {\r\n noScrollbarCss ??= false\r\n _document ??= document\r\n const docid = useId()\r\n\r\n const csscacheId = useId()\r\n CSSCacheId ??= csscacheId\r\n\r\n
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/AppRoot/index.tsx"],"sourcesContent":["\"use client\";\r\nimport React, { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';\r\nimport { TagComponentType } from '../Tag/types';\r\nimport { ThemeProvider, ThemeProviderProps } from '../theme';\r\nimport { BreakpointProvider } from '../breakpoint';\r\nimport { RenderRenderar } from './Renderar';\r\nimport { DocumentProvider } from '../Document';\r\nimport { AppRootProvider } from './AppRootProvider';\r\nimport useMergeRefs from '../hooks/useMergeRefs';\r\nimport { CSSCacheProvider } from '../css/CSSCacheProvider';\r\n\r\nexport type AppRootProps<T extends TagComponentType = \"div\"> = ThemeProviderProps<T> & {\r\n noScrollbarCss?: boolean;\r\n document?: Document;\r\n CSSCacheId?: string;\r\n}\r\n\r\nconst AppRoot = React.forwardRef(<T extends TagComponentType = \"div\">({ children, noScrollbarCss, CSSCacheId, theme, document: _document, ...props }: AppRootProps<T>, ref: React.Ref<any>) => {\r\n noScrollbarCss ??= false\r\n _document ??= document\r\n const docid = useId()\r\n\r\n const csscacheId = useId()\r\n CSSCacheId ??= csscacheId\r\n\r\n const [visibility, setVisibility] = React.useState<string>(\"hidden\");\r\n const [doc, setDoc] = useState(_document ??= document)\r\n const rootRef = useRef(null)\r\n const mergeRef = useMergeRefs(rootRef, ref)\r\n // console.log(_document);\r\n\r\n useEffect(() => {\r\n setVisibility(\"visible\");\r\n\r\n // move oncss style tags to head\r\n if (typeof _document === 'undefined') return;\r\n const styles = Array.from(_document.querySelectorAll('body style[data-oncss]'));\r\n styles.forEach((style) => {\r\n _document.head.appendChild(style);\r\n });\r\n }, [])\r\n\r\n return (\r\n <DocumentProvider document={doc} id={docid}>\r\n <CSSCacheProvider cacheId={CSSCacheId}>\r\n <AppRootProvider element={() => rootRef.current}>\r\n <ThemeProvider\r\n theme={theme}\r\n {...props}\r\n ref={mergeRef}\r\n isRoot\r\n sx={{\r\n ...props.sx,\r\n ...(visibility === \"hidden\" ? { visibility: \"hidden\" } : {})\r\n }}\r\n >\r\n <BreakpointProvider>\r\n {children}\r\n <RenderRenderar />\r\n </BreakpointProvider>\r\n </ThemeProvider>\r\n </AppRootProvider>\r\n </CSSCacheProvider>\r\n </DocumentProvider>\r\n )\r\n})\r\n\r\nexport default AppRoot\r\n\r\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAiBA;AAAsE;;;AAGnE;AAEA;;AAGA;AACA;AACA;;;;;;;;AASG;AACA;AACG;AACH;;AAGH;AAuBH;;"}
|
package/AppRoot/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { __rest } from 'tslib';
|
|
3
3
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
4
|
-
import React__default, { useId, useRef, useEffect } from 'react';
|
|
4
|
+
import React__default, { useId, useState, useRef, useEffect } from 'react';
|
|
5
5
|
import '../theme/core.js';
|
|
6
6
|
import '../css/getValue.js';
|
|
7
7
|
import 'oncss';
|
|
@@ -22,8 +22,10 @@ const AppRoot = React__default.forwardRef((_a, ref) => {
|
|
|
22
22
|
const csscacheId = useId();
|
|
23
23
|
CSSCacheId !== null && CSSCacheId !== void 0 ? CSSCacheId : (CSSCacheId = csscacheId);
|
|
24
24
|
const [visibility, setVisibility] = React__default.useState("hidden");
|
|
25
|
+
const [doc, setDoc] = useState(_document !== null && _document !== void 0 ? _document : (_document = document));
|
|
25
26
|
const rootRef = useRef(null);
|
|
26
27
|
const mergeRef = useMergeRefs(rootRef, ref);
|
|
28
|
+
// console.log(_document);
|
|
27
29
|
useEffect(() => {
|
|
28
30
|
setVisibility("visible");
|
|
29
31
|
// move oncss style tags to head
|
|
@@ -34,7 +36,7 @@ const AppRoot = React__default.forwardRef((_a, ref) => {
|
|
|
34
36
|
_document.head.appendChild(style);
|
|
35
37
|
});
|
|
36
38
|
}, []);
|
|
37
|
-
return (jsx(DocumentProvider, { document:
|
|
39
|
+
return (jsx(DocumentProvider, { document: doc, id: docid, children: jsx(CSSCacheProvider, { cacheId: CSSCacheId, children: jsx(AppRootProvider, { element: () => rootRef.current, children: jsx(ThemeProvider, Object.assign({ theme: theme }, props, { ref: mergeRef, isRoot: true, sx: Object.assign(Object.assign({}, props.sx), (visibility === "hidden" ? { visibility: "hidden" } : {})), children: jsxs(BreakpointProvider, { children: [children, jsx(RenderRenderar, {})] }) })) }) }) }));
|
|
38
40
|
});
|
|
39
41
|
|
|
40
42
|
export { AppRoot as default };
|
package/AppRoot/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/AppRoot/index.tsx"],"sourcesContent":["\"use client\";\r\nimport React, { useEffect, useId, useRef } from 'react';\r\nimport { TagComponentType } from '../Tag/types';\r\nimport { ThemeProvider, ThemeProviderProps } from '../theme';\r\nimport { BreakpointProvider } from '../breakpoint';\r\nimport { RenderRenderar } from './Renderar';\r\nimport { DocumentProvider } from '../Document';\r\nimport { AppRootProvider } from './AppRootProvider';\r\nimport useMergeRefs from '../hooks/useMergeRefs';\r\nimport { CSSCacheProvider } from '../css/CSSCacheProvider';\r\n\r\nexport type AppRootProps<T extends TagComponentType = \"div\"> = ThemeProviderProps<T> & {\r\n noScrollbarCss?: boolean;\r\n document?: Document;\r\n CSSCacheId?: string;\r\n}\r\n\r\nconst AppRoot = React.forwardRef(<T extends TagComponentType = \"div\">({ children, noScrollbarCss, CSSCacheId, theme, document: _document, ...props }: AppRootProps<T>, ref: React.Ref<any>) => {\r\n noScrollbarCss ??= false\r\n _document ??= document\r\n const docid = useId()\r\n\r\n const csscacheId = useId()\r\n CSSCacheId ??= csscacheId\r\n\r\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/AppRoot/index.tsx"],"sourcesContent":["\"use client\";\r\nimport React, { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';\r\nimport { TagComponentType } from '../Tag/types';\r\nimport { ThemeProvider, ThemeProviderProps } from '../theme';\r\nimport { BreakpointProvider } from '../breakpoint';\r\nimport { RenderRenderar } from './Renderar';\r\nimport { DocumentProvider } from '../Document';\r\nimport { AppRootProvider } from './AppRootProvider';\r\nimport useMergeRefs from '../hooks/useMergeRefs';\r\nimport { CSSCacheProvider } from '../css/CSSCacheProvider';\r\n\r\nexport type AppRootProps<T extends TagComponentType = \"div\"> = ThemeProviderProps<T> & {\r\n noScrollbarCss?: boolean;\r\n document?: Document;\r\n CSSCacheId?: string;\r\n}\r\n\r\nconst AppRoot = React.forwardRef(<T extends TagComponentType = \"div\">({ children, noScrollbarCss, CSSCacheId, theme, document: _document, ...props }: AppRootProps<T>, ref: React.Ref<any>) => {\r\n noScrollbarCss ??= false\r\n _document ??= document\r\n const docid = useId()\r\n\r\n const csscacheId = useId()\r\n CSSCacheId ??= csscacheId\r\n\r\n const [visibility, setVisibility] = React.useState<string>(\"hidden\");\r\n const [doc, setDoc] = useState(_document ??= document)\r\n const rootRef = useRef(null)\r\n const mergeRef = useMergeRefs(rootRef, ref)\r\n // console.log(_document);\r\n\r\n useEffect(() => {\r\n setVisibility(\"visible\");\r\n\r\n // move oncss style tags to head\r\n if (typeof _document === 'undefined') return;\r\n const styles = Array.from(_document.querySelectorAll('body style[data-oncss]'));\r\n styles.forEach((style) => {\r\n _document.head.appendChild(style);\r\n });\r\n }, [])\r\n\r\n return (\r\n <DocumentProvider document={doc} id={docid}>\r\n <CSSCacheProvider cacheId={CSSCacheId}>\r\n <AppRootProvider element={() => rootRef.current}>\r\n <ThemeProvider\r\n theme={theme}\r\n {...props}\r\n ref={mergeRef}\r\n isRoot\r\n sx={{\r\n ...props.sx,\r\n ...(visibility === \"hidden\" ? { visibility: \"hidden\" } : {})\r\n }}\r\n >\r\n <BreakpointProvider>\r\n {children}\r\n <RenderRenderar />\r\n </BreakpointProvider>\r\n </ThemeProvider>\r\n </AppRootProvider>\r\n </CSSCacheProvider>\r\n </DocumentProvider>\r\n )\r\n})\r\n\r\nexport default AppRoot\r\n\r\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAiBA;AAAsE;;;AAGnE;AAEA;;AAGA;AACA;AACA;;;;;;;;AASG;AACA;AACG;AACH;;AAGH;AAuBH;;"}
|
package/Document/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Document/index.tsx"],"sourcesContent":["'use client'\r\nimport React, { useContext, createContext } from \"react\";\r\n\r\n\r\nexport type DocumentID = string\r\nexport type DocumentContextValue = { document: Document; id: DocumentID }\r\nconst DocumentContext = createContext<DocumentContextValue | null>(null);\r\n\r\nexport const DocumentProvider: React.FC<{ children: React.ReactNode } & DocumentContextValue> = ({ document, id, children }) => {\r\n return (\r\n <DocumentContext.Provider value={{ document, id }}>\r\n {children}\r\n </DocumentContext.Provider>\r\n );\r\n}\r\n\r\nexport const useDocument = (): DocumentContextValue => {\r\n const context = useContext(DocumentContext);\r\n if (typeof window === 'undefined') {\r\n return null as any;\r\n }\r\n return context as DocumentContextValue\r\n}"],"names":[],"mappings":";;;;;;AAMA;AAEO;AACJ;AAKH;AAEO;AACJ;AACA;AACG;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Document/index.tsx"],"sourcesContent":["'use client'\r\nimport React, { useContext, createContext } from \"react\";\r\n\r\n\r\nexport type DocumentID = string\r\nexport type DocumentContextValue = { document: Document; id: DocumentID }\r\nconst DocumentContext = createContext<DocumentContextValue | null>(null);\r\n\r\nexport const DocumentProvider: React.FC<{ children: React.ReactNode } & DocumentContextValue> = ({ document, id, children }) => {\r\n return (\r\n <DocumentContext.Provider value={{ document, id }}>\r\n {children}\r\n </DocumentContext.Provider>\r\n );\r\n}\r\n\r\nexport const useDocument = (): DocumentContextValue => {\r\n const context = useContext(DocumentContext);\r\n if (typeof window === 'undefined') {\r\n return null as any;\r\n }\r\n\r\n return context as DocumentContextValue\r\n}"],"names":[],"mappings":";;;;;;AAMA;AAEO;AACJ;AAKH;AAEO;AACJ;AACA;AACG;;AAGH;AACH;;;"}
|
package/Document/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Document/index.tsx"],"sourcesContent":["'use client'\r\nimport React, { useContext, createContext } from \"react\";\r\n\r\n\r\nexport type DocumentID = string\r\nexport type DocumentContextValue = { document: Document; id: DocumentID }\r\nconst DocumentContext = createContext<DocumentContextValue | null>(null);\r\n\r\nexport const DocumentProvider: React.FC<{ children: React.ReactNode } & DocumentContextValue> = ({ document, id, children }) => {\r\n return (\r\n <DocumentContext.Provider value={{ document, id }}>\r\n {children}\r\n </DocumentContext.Provider>\r\n );\r\n}\r\n\r\nexport const useDocument = (): DocumentContextValue => {\r\n const context = useContext(DocumentContext);\r\n if (typeof window === 'undefined') {\r\n return null as any;\r\n }\r\n return context as DocumentContextValue\r\n}"],"names":[],"mappings":";;;;AAMA;AAEO;AACJ;AAKH;AAEO;AACJ;AACA;AACG;;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Document/index.tsx"],"sourcesContent":["'use client'\r\nimport React, { useContext, createContext } from \"react\";\r\n\r\n\r\nexport type DocumentID = string\r\nexport type DocumentContextValue = { document: Document; id: DocumentID }\r\nconst DocumentContext = createContext<DocumentContextValue | null>(null);\r\n\r\nexport const DocumentProvider: React.FC<{ children: React.ReactNode } & DocumentContextValue> = ({ document, id, children }) => {\r\n return (\r\n <DocumentContext.Provider value={{ document, id }}>\r\n {children}\r\n </DocumentContext.Provider>\r\n );\r\n}\r\n\r\nexport const useDocument = (): DocumentContextValue => {\r\n const context = useContext(DocumentContext);\r\n if (typeof window === 'undefined') {\r\n return null as any;\r\n }\r\n\r\n return context as DocumentContextValue\r\n}"],"names":[],"mappings":";;;;AAMA;AAEO;AACJ;AAKH;AAEO;AACJ;AACA;AACG;;AAGH;AACH;;"}
|
package/Tag/useTagProps.cjs
CHANGED
|
@@ -11,7 +11,7 @@ const useTagProps = (props) => {
|
|
|
11
11
|
const cachekey = JSON.stringify(props, (key, value) => {
|
|
12
12
|
return key === '_owner' || key === '_store' ? undefined : value;
|
|
13
13
|
}, 2);
|
|
14
|
-
const doc = index.useDocument()
|
|
14
|
+
const doc = index.useDocument();
|
|
15
15
|
const cacheId = CSSCacheProvider.useCSSCacheId();
|
|
16
16
|
const parsed = React.useMemo(() => {
|
|
17
17
|
let _props = {};
|
|
@@ -33,8 +33,8 @@ const useTagProps = (props) => {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
const styles = index$1.css(Object.assign(Object.assign(Object.assign(Object.assign({}, props.sxr), _css), props.sx), props.style), {
|
|
36
|
-
injectStyle: typeof doc !== 'undefined',
|
|
37
|
-
container: doc,
|
|
36
|
+
injectStyle: typeof doc.document !== 'undefined',
|
|
37
|
+
container: doc.document,
|
|
38
38
|
cacheId
|
|
39
39
|
});
|
|
40
40
|
return {
|
package/Tag/useTagProps.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTagProps.cjs","sources":["../../src/Tag/useTagProps.ts"],"sourcesContent":["import { TagComponentType, TagProps, TagPropsRoot } from './types';\r\nimport cssPropList from './cssPropList';\r\nimport { css } from '../css';\r\nimport { classNames } from 'pretty-class';\r\nimport { CSSFactoryType } from 'oncss';\r\nimport { useMemo } from 'react';\r\nimport { useDocument } from '../Document';\r\nimport { useCSSCacheId } from '../css/CSSCacheProvider';\r\n\r\nexport type useTagPropsReturn<T extends TagComponentType = \"div\"> = {\r\n props: TagProps<T>,\r\n style: CSSFactoryType\r\n}\r\n\r\nconst useTagProps = <T extends TagComponentType = \"div\">(props: TagPropsRoot<T>): useTagPropsReturn<T> => {\r\n const cachekey = JSON.stringify(props, (key, value) => {\r\n return key === '_owner' || key === '_store' ? undefined : value;\r\n }, 2);\r\n\r\n const doc = useDocument()
|
|
1
|
+
{"version":3,"file":"useTagProps.cjs","sources":["../../src/Tag/useTagProps.ts"],"sourcesContent":["import { TagComponentType, TagProps, TagPropsRoot } from './types';\r\nimport cssPropList from './cssPropList';\r\nimport { css } from '../css';\r\nimport { classNames } from 'pretty-class';\r\nimport { CSSFactoryType } from 'oncss';\r\nimport { useMemo } from 'react';\r\nimport { useDocument } from '../Document';\r\nimport { useCSSCacheId } from '../css/CSSCacheProvider';\r\n\r\nexport type useTagPropsReturn<T extends TagComponentType = \"div\"> = {\r\n props: TagProps<T>,\r\n style: CSSFactoryType\r\n}\r\n\r\nconst useTagProps = <T extends TagComponentType = \"div\">(props: TagPropsRoot<T>): useTagPropsReturn<T> => {\r\n const cachekey = JSON.stringify(props, (key, value) => {\r\n return key === '_owner' || key === '_store' ? undefined : value;\r\n }, 2);\r\n\r\n const doc = useDocument();\r\n const cacheId = useCSSCacheId()\r\n\r\n const parsed = useMemo(() => {\r\n let _props: any = {}\r\n let _css: any = {}\r\n\r\n if (props.hover && Object.keys(props.hover).length > 0) {\r\n _css['&:hover'] = {\r\n ...props.hover\r\n }\r\n }\r\n\r\n for (let key in props) {\r\n const keys = [\"sx\", \"sxr\", \"style\", \"hover\", \"className\", \"classNames\", \"baseClass\"];\r\n if (keys.includes(key)) {\r\n continue;\r\n }\r\n let val = (props as any)[key];\r\n if (!cssPropList[key]) {\r\n _props[key] = val\r\n } else {\r\n _css[key] = val\r\n }\r\n }\r\n\r\n const styles = css({ ...props.sxr, ..._css, ...props.sx, ...props.style }, {\r\n injectStyle: typeof doc.document !== 'undefined',\r\n container: doc.document,\r\n cacheId\r\n })\r\n\r\n return {\r\n props: _props,\r\n styles,\r\n className: classNames(\r\n props.baseClass ? \"xui-\" + props.baseClass : undefined,\r\n props.classNames,\r\n props.className,\r\n styles.classname\r\n )\r\n }\r\n }, [cachekey])\r\n\r\n const _props: any = {};\r\n for (let prop in parsed.props) {\r\n _props[prop] = (props as any)[prop]\r\n }\r\n _props.className = parsed.className;\r\n\r\n return { props: _props, style: parsed.styles };\r\n}\r\n\r\n\r\nexport default useTagProps"],"names":["useDocument","useCSSCacheId","useMemo","css","classNames"],"mappings":";;;;;;;;;AAcA,MAAM,WAAW,GAAG,CAAqC,KAAsB,KAA0B;AACtG,IAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,KAAK,KAAI;AACnD,QAAA,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,QAAQ,GAAG,SAAS,GAAG,KAAK;IAClE,CAAC,EAAE,CAAC,CAAC;AAEL,IAAA,MAAM,GAAG,GAAGA,iBAAW,EAAE;AACzB,IAAA,MAAM,OAAO,GAAGC,8BAAa,EAAE;AAE/B,IAAA,MAAM,MAAM,GAAGC,aAAO,CAAC,MAAK;QACzB,IAAI,MAAM,GAAQ,EAAE;QACpB,IAAI,IAAI,GAAQ,EAAE;AAElB,QAAA,IAAI,KAAK,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACrD,IAAI,CAAC,SAAS,CAAC,GAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACT,KAAK,CAAC,KAAK,CAChB;QACJ;AAEA,QAAA,KAAK,IAAI,GAAG,IAAI,KAAK,EAAE;AACpB,YAAA,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC;AACpF,YAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBACrB;YACH;AACA,YAAA,IAAI,GAAG,GAAI,KAAa,CAAC,GAAG,CAAC;AAC7B,YAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE;AACpB,gBAAA,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG;YACpB;iBAAO;AACJ,gBAAA,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG;YAClB;QACH;AAEA,QAAA,MAAM,MAAM,GAAGC,WAAG,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAM,KAAK,CAAC,GAAG,CAAA,EAAK,IAAI,CAAA,EAAK,KAAK,CAAC,EAAE,GAAK,KAAK,CAAC,KAAK,CAAA,EAAI;AACxE,YAAA,WAAW,EAAE,OAAO,GAAG,CAAC,QAAQ,KAAK,WAAW;YAChD,SAAS,EAAE,GAAG,CAAC,QAAQ;YACvB;AACF,SAAA,CAAC;QAEF,OAAO;AACJ,YAAA,KAAK,EAAE,MAAM;YACb,MAAM;AACN,YAAA,SAAS,EAAEC,sBAAU,CAClB,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,KAAK,CAAC,SAAS,GAAG,SAAS,EACtD,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,SAAS,EACf,MAAM,CAAC,SAAS;SAErB;AACJ,IAAA,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;IAEd,MAAM,MAAM,GAAQ,EAAE;AACtB,IAAA,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;QAC5B,MAAM,CAAC,IAAI,CAAC,GAAI,KAAa,CAAC,IAAI,CAAC;IACtC;AACA,IAAA,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS;IAEnC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;AACjD;;;;"}
|
package/Tag/useTagProps.js
CHANGED
|
@@ -9,7 +9,7 @@ const useTagProps = (props) => {
|
|
|
9
9
|
const cachekey = JSON.stringify(props, (key, value) => {
|
|
10
10
|
return key === '_owner' || key === '_store' ? undefined : value;
|
|
11
11
|
}, 2);
|
|
12
|
-
const doc = useDocument()
|
|
12
|
+
const doc = useDocument();
|
|
13
13
|
const cacheId = useCSSCacheId();
|
|
14
14
|
const parsed = useMemo(() => {
|
|
15
15
|
let _props = {};
|
|
@@ -31,8 +31,8 @@ const useTagProps = (props) => {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
const styles = css(Object.assign(Object.assign(Object.assign(Object.assign({}, props.sxr), _css), props.sx), props.style), {
|
|
34
|
-
injectStyle: typeof doc !== 'undefined',
|
|
35
|
-
container: doc,
|
|
34
|
+
injectStyle: typeof doc.document !== 'undefined',
|
|
35
|
+
container: doc.document,
|
|
36
36
|
cacheId
|
|
37
37
|
});
|
|
38
38
|
return {
|
package/Tag/useTagProps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTagProps.js","sources":["../../src/Tag/useTagProps.ts"],"sourcesContent":["import { TagComponentType, TagProps, TagPropsRoot } from './types';\r\nimport cssPropList from './cssPropList';\r\nimport { css } from '../css';\r\nimport { classNames } from 'pretty-class';\r\nimport { CSSFactoryType } from 'oncss';\r\nimport { useMemo } from 'react';\r\nimport { useDocument } from '../Document';\r\nimport { useCSSCacheId } from '../css/CSSCacheProvider';\r\n\r\nexport type useTagPropsReturn<T extends TagComponentType = \"div\"> = {\r\n props: TagProps<T>,\r\n style: CSSFactoryType\r\n}\r\n\r\nconst useTagProps = <T extends TagComponentType = \"div\">(props: TagPropsRoot<T>): useTagPropsReturn<T> => {\r\n const cachekey = JSON.stringify(props, (key, value) => {\r\n return key === '_owner' || key === '_store' ? undefined : value;\r\n }, 2);\r\n\r\n const doc = useDocument()
|
|
1
|
+
{"version":3,"file":"useTagProps.js","sources":["../../src/Tag/useTagProps.ts"],"sourcesContent":["import { TagComponentType, TagProps, TagPropsRoot } from './types';\r\nimport cssPropList from './cssPropList';\r\nimport { css } from '../css';\r\nimport { classNames } from 'pretty-class';\r\nimport { CSSFactoryType } from 'oncss';\r\nimport { useMemo } from 'react';\r\nimport { useDocument } from '../Document';\r\nimport { useCSSCacheId } from '../css/CSSCacheProvider';\r\n\r\nexport type useTagPropsReturn<T extends TagComponentType = \"div\"> = {\r\n props: TagProps<T>,\r\n style: CSSFactoryType\r\n}\r\n\r\nconst useTagProps = <T extends TagComponentType = \"div\">(props: TagPropsRoot<T>): useTagPropsReturn<T> => {\r\n const cachekey = JSON.stringify(props, (key, value) => {\r\n return key === '_owner' || key === '_store' ? undefined : value;\r\n }, 2);\r\n\r\n const doc = useDocument();\r\n const cacheId = useCSSCacheId()\r\n\r\n const parsed = useMemo(() => {\r\n let _props: any = {}\r\n let _css: any = {}\r\n\r\n if (props.hover && Object.keys(props.hover).length > 0) {\r\n _css['&:hover'] = {\r\n ...props.hover\r\n }\r\n }\r\n\r\n for (let key in props) {\r\n const keys = [\"sx\", \"sxr\", \"style\", \"hover\", \"className\", \"classNames\", \"baseClass\"];\r\n if (keys.includes(key)) {\r\n continue;\r\n }\r\n let val = (props as any)[key];\r\n if (!cssPropList[key]) {\r\n _props[key] = val\r\n } else {\r\n _css[key] = val\r\n }\r\n }\r\n\r\n const styles = css({ ...props.sxr, ..._css, ...props.sx, ...props.style }, {\r\n injectStyle: typeof doc.document !== 'undefined',\r\n container: doc.document,\r\n cacheId\r\n })\r\n\r\n return {\r\n props: _props,\r\n styles,\r\n className: classNames(\r\n props.baseClass ? \"xui-\" + props.baseClass : undefined,\r\n props.classNames,\r\n props.className,\r\n styles.classname\r\n )\r\n }\r\n }, [cachekey])\r\n\r\n const _props: any = {};\r\n for (let prop in parsed.props) {\r\n _props[prop] = (props as any)[prop]\r\n }\r\n _props.className = parsed.className;\r\n\r\n return { props: _props, style: parsed.styles };\r\n}\r\n\r\n\r\nexport default useTagProps"],"names":["cssPropList"],"mappings":";;;;;;;AAcA,MAAM,WAAW,GAAG,CAAqC,KAAsB,KAA0B;AACtG,IAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,KAAK,KAAI;AACnD,QAAA,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,QAAQ,GAAG,SAAS,GAAG,KAAK;IAClE,CAAC,EAAE,CAAC,CAAC;AAEL,IAAA,MAAM,GAAG,GAAG,WAAW,EAAE;AACzB,IAAA,MAAM,OAAO,GAAG,aAAa,EAAE;AAE/B,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAK;QACzB,IAAI,MAAM,GAAQ,EAAE;QACpB,IAAI,IAAI,GAAQ,EAAE;AAElB,QAAA,IAAI,KAAK,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACrD,IAAI,CAAC,SAAS,CAAC,GAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACT,KAAK,CAAC,KAAK,CAChB;QACJ;AAEA,QAAA,KAAK,IAAI,GAAG,IAAI,KAAK,EAAE;AACpB,YAAA,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC;AACpF,YAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBACrB;YACH;AACA,YAAA,IAAI,GAAG,GAAI,KAAa,CAAC,GAAG,CAAC;AAC7B,YAAA,IAAI,CAACA,aAAW,CAAC,GAAG,CAAC,EAAE;AACpB,gBAAA,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG;YACpB;iBAAO;AACJ,gBAAA,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG;YAClB;QACH;AAEA,QAAA,MAAM,MAAM,GAAG,GAAG,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAM,KAAK,CAAC,GAAG,CAAA,EAAK,IAAI,CAAA,EAAK,KAAK,CAAC,EAAE,GAAK,KAAK,CAAC,KAAK,CAAA,EAAI;AACxE,YAAA,WAAW,EAAE,OAAO,GAAG,CAAC,QAAQ,KAAK,WAAW;YAChD,SAAS,EAAE,GAAG,CAAC,QAAQ;YACvB;AACF,SAAA,CAAC;QAEF,OAAO;AACJ,YAAA,KAAK,EAAE,MAAM;YACb,MAAM;AACN,YAAA,SAAS,EAAE,UAAU,CAClB,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,KAAK,CAAC,SAAS,GAAG,SAAS,EACtD,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,SAAS,EACf,MAAM,CAAC,SAAS;SAErB;AACJ,IAAA,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;IAEd,MAAM,MAAM,GAAQ,EAAE;AACtB,IAAA,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;QAC5B,MAAM,CAAC,IAAI,CAAC,GAAI,KAAa,CAAC,IAAI,CAAC;IACtC;AACA,IAAA,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS;IAEnC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;AACjD;;;;"}
|
|
@@ -3,36 +3,42 @@
|
|
|
3
3
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var index = require('../css/index.cjs');
|
|
6
|
+
var index$1 = require('../css/index.cjs');
|
|
7
|
+
var index = require('../Document/index.cjs');
|
|
7
8
|
|
|
8
|
-
const BreakpointCtx = React.createContext("
|
|
9
|
+
const BreakpointCtx = React.createContext("xl");
|
|
9
10
|
/**
|
|
10
11
|
* SSR-safe breakpoint detection
|
|
11
12
|
*/
|
|
12
|
-
const getKey = () => {
|
|
13
|
-
if (typeof window ===
|
|
13
|
+
const getKey = (doc) => {
|
|
14
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
14
15
|
return "xl";
|
|
15
16
|
}
|
|
16
|
-
const width = window.innerWidth;
|
|
17
|
-
if (width < index.breakpoints.sm)
|
|
17
|
+
const width = doc.documentElement.clientWidth || window.innerWidth;
|
|
18
|
+
if (width < index$1.breakpoints.sm)
|
|
18
19
|
return "xs";
|
|
19
|
-
if (width < index.breakpoints.md)
|
|
20
|
+
if (width < index$1.breakpoints.md)
|
|
20
21
|
return "sm";
|
|
21
|
-
if (width < index.breakpoints.lg)
|
|
22
|
+
if (width < index$1.breakpoints.lg)
|
|
22
23
|
return "md";
|
|
23
|
-
if (width < index.breakpoints.xl)
|
|
24
|
+
if (width < index$1.breakpoints.xl)
|
|
24
25
|
return "lg";
|
|
25
26
|
return "xl";
|
|
26
27
|
};
|
|
27
28
|
const BreakpointProvider = ({ children }) => {
|
|
28
|
-
|
|
29
|
+
// hydrate-safe initial state
|
|
30
|
+
const doc = index.useDocument();
|
|
31
|
+
const [current, setCurrent] = React.useState(() => getKey(doc === null || doc === void 0 ? void 0 : doc.document));
|
|
29
32
|
const handler = React.useCallback(() => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if (doc) {
|
|
34
|
+
const next = getKey(doc.document);
|
|
35
|
+
setCurrent(prev => (prev === next ? prev : next));
|
|
36
|
+
}
|
|
37
|
+
}, [doc]);
|
|
38
|
+
// useLayoutEffect avoids visual flicker on first paint
|
|
39
|
+
React.useLayoutEffect(() => {
|
|
40
|
+
handler();
|
|
41
|
+
window.addEventListener("resize", handler, { passive: true });
|
|
36
42
|
return () => window.removeEventListener("resize", handler);
|
|
37
43
|
}, [handler]);
|
|
38
44
|
return (jsxRuntime.jsx(BreakpointCtx.Provider, { value: current, children: children }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BreakpointProvider.cjs","sources":["../../src/breakpoint/BreakpointProvider.tsx"],"sourcesContent":["\"use client\";\r\nimport React, {
|
|
1
|
+
{"version":3,"file":"BreakpointProvider.cjs","sources":["../../src/breakpoint/BreakpointProvider.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport React, {\r\n ReactNode,\r\n useState,\r\n useCallback,\r\n useLayoutEffect,\r\n} from \"react\";\r\nimport { breakpoints } from \"../css\";\r\nimport { BreakpointKeys } from \"../css/types\";\r\nimport { useDocument } from \"../Document\";\r\n\r\nexport const BreakpointCtx = React.createContext<BreakpointKeys>(\"xl\");\r\n\r\n/**\r\n * SSR-safe breakpoint detection\r\n */\r\nconst getKey = (doc: Document): BreakpointKeys => {\r\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\r\n return \"xl\";\r\n }\r\n\r\n const width = doc.documentElement.clientWidth || window.innerWidth;\r\n\r\n if (width < breakpoints.sm) return \"xs\";\r\n if (width < breakpoints.md) return \"sm\";\r\n if (width < breakpoints.lg) return \"md\";\r\n if (width < breakpoints.xl) return \"lg\";\r\n return \"xl\";\r\n};\r\n\r\nexport const BreakpointProvider = ({ children }: { children?: ReactNode }) => {\r\n // hydrate-safe initial state\r\n const doc = useDocument()\r\n const [current, setCurrent] = useState<BreakpointKeys>(() => getKey(doc?.document));\r\n\r\n const handler = useCallback(() => {\r\n if (doc) {\r\n const next = getKey(doc.document)\r\n setCurrent(prev => (prev === next ? prev : next));\r\n }\r\n }, [doc]);\r\n\r\n // useLayoutEffect avoids visual flicker on first paint\r\n useLayoutEffect(() => {\r\n handler();\r\n window.addEventListener(\"resize\", handler, { passive: true });\r\n return () => window.removeEventListener(\"resize\", handler);\r\n }, [handler]);\r\n\r\n return (\r\n <BreakpointCtx.Provider value={current}>\r\n {children}\r\n </BreakpointCtx.Provider>\r\n );\r\n};\r\n"],"names":[],"mappings":";;;;;;;;AAYO;AAEP;;AAEG;AACH;;AAEQ;;;AAKJ;AAA4B;AAC5B;AAA4B;AAC5B;AAA4B;AAC5B;AAA4B;AAC5B;AACJ;;;AAII;;AAGA;;;AAGQ;;AAER;;;AAII;AACA;;AAEJ;AAEA;AAKJ;;;"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import React__default, { useState, useCallback } from 'react';
|
|
3
|
+
import React__default, { useState, useCallback, useLayoutEffect } from 'react';
|
|
4
4
|
import { breakpoints } from '../css/index.js';
|
|
5
|
+
import { useDocument } from '../Document/index.js';
|
|
5
6
|
|
|
6
|
-
const BreakpointCtx = React__default.createContext("
|
|
7
|
+
const BreakpointCtx = React__default.createContext("xl");
|
|
7
8
|
/**
|
|
8
9
|
* SSR-safe breakpoint detection
|
|
9
10
|
*/
|
|
10
|
-
const getKey = () => {
|
|
11
|
-
if (typeof window ===
|
|
11
|
+
const getKey = (doc) => {
|
|
12
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
12
13
|
return "xl";
|
|
13
14
|
}
|
|
14
|
-
const width = window.innerWidth;
|
|
15
|
+
const width = doc.documentElement.clientWidth || window.innerWidth;
|
|
15
16
|
if (width < breakpoints.sm)
|
|
16
17
|
return "xs";
|
|
17
18
|
if (width < breakpoints.md)
|
|
@@ -23,14 +24,19 @@ const getKey = () => {
|
|
|
23
24
|
return "xl";
|
|
24
25
|
};
|
|
25
26
|
const BreakpointProvider = ({ children }) => {
|
|
26
|
-
|
|
27
|
+
// hydrate-safe initial state
|
|
28
|
+
const doc = useDocument();
|
|
29
|
+
const [current, setCurrent] = useState(() => getKey(doc === null || doc === void 0 ? void 0 : doc.document));
|
|
27
30
|
const handler = useCallback(() => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
if (doc) {
|
|
32
|
+
const next = getKey(doc.document);
|
|
33
|
+
setCurrent(prev => (prev === next ? prev : next));
|
|
34
|
+
}
|
|
35
|
+
}, [doc]);
|
|
36
|
+
// useLayoutEffect avoids visual flicker on first paint
|
|
37
|
+
useLayoutEffect(() => {
|
|
38
|
+
handler();
|
|
39
|
+
window.addEventListener("resize", handler, { passive: true });
|
|
34
40
|
return () => window.removeEventListener("resize", handler);
|
|
35
41
|
}, [handler]);
|
|
36
42
|
return (jsx(BreakpointCtx.Provider, { value: current, children: children }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BreakpointProvider.js","sources":["../../src/breakpoint/BreakpointProvider.tsx"],"sourcesContent":["\"use client\";\r\nimport React, {
|
|
1
|
+
{"version":3,"file":"BreakpointProvider.js","sources":["../../src/breakpoint/BreakpointProvider.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport React, {\r\n ReactNode,\r\n useState,\r\n useCallback,\r\n useLayoutEffect,\r\n} from \"react\";\r\nimport { breakpoints } from \"../css\";\r\nimport { BreakpointKeys } from \"../css/types\";\r\nimport { useDocument } from \"../Document\";\r\n\r\nexport const BreakpointCtx = React.createContext<BreakpointKeys>(\"xl\");\r\n\r\n/**\r\n * SSR-safe breakpoint detection\r\n */\r\nconst getKey = (doc: Document): BreakpointKeys => {\r\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\r\n return \"xl\";\r\n }\r\n\r\n const width = doc.documentElement.clientWidth || window.innerWidth;\r\n\r\n if (width < breakpoints.sm) return \"xs\";\r\n if (width < breakpoints.md) return \"sm\";\r\n if (width < breakpoints.lg) return \"md\";\r\n if (width < breakpoints.xl) return \"lg\";\r\n return \"xl\";\r\n};\r\n\r\nexport const BreakpointProvider = ({ children }: { children?: ReactNode }) => {\r\n // hydrate-safe initial state\r\n const doc = useDocument()\r\n const [current, setCurrent] = useState<BreakpointKeys>(() => getKey(doc?.document));\r\n\r\n const handler = useCallback(() => {\r\n if (doc) {\r\n const next = getKey(doc.document)\r\n setCurrent(prev => (prev === next ? prev : next));\r\n }\r\n }, [doc]);\r\n\r\n // useLayoutEffect avoids visual flicker on first paint\r\n useLayoutEffect(() => {\r\n handler();\r\n window.addEventListener(\"resize\", handler, { passive: true });\r\n return () => window.removeEventListener(\"resize\", handler);\r\n }, [handler]);\r\n\r\n return (\r\n <BreakpointCtx.Provider value={current}>\r\n {children}\r\n </BreakpointCtx.Provider>\r\n );\r\n};\r\n"],"names":[],"mappings":";;;;;;AAYO;AAEP;;AAEG;AACH;;AAEQ;;;AAKJ;AAA4B;AAC5B;AAA4B;AAC5B;AAA4B;AAC5B;AAA4B;AAC5B;AACJ;;;AAII;;AAGA;;;AAGQ;;AAER;;;AAII;AACA;;AAEJ;AAEA;AAKJ;;"}
|
package/hooks/usePortal.cjs
CHANGED
|
@@ -7,10 +7,12 @@ var client = require('react-dom/client');
|
|
|
7
7
|
var core = require('../theme/core.cjs');
|
|
8
8
|
require('../css/getValue.cjs');
|
|
9
9
|
require('oncss');
|
|
10
|
-
|
|
10
|
+
require('../theme/ThemeProvider.cjs');
|
|
11
11
|
require('react-state-bucket');
|
|
12
12
|
var AppRootProvider = require('../AppRoot/AppRootProvider.cjs');
|
|
13
13
|
var index = require('../Document/index.cjs');
|
|
14
|
+
var index$1 = require('../AppRoot/index.cjs');
|
|
15
|
+
var CSSCacheProvider = require('../css/CSSCacheProvider.cjs');
|
|
14
16
|
|
|
15
17
|
function usePortal(children, options) {
|
|
16
18
|
options = options || {};
|
|
@@ -19,8 +21,9 @@ function usePortal(children, options) {
|
|
|
19
21
|
}
|
|
20
22
|
const [mounted, setMounted] = React.useState(options.autoMount);
|
|
21
23
|
const theme = core.useTheme();
|
|
22
|
-
const appRoot = AppRootProvider.useAppRootElement();
|
|
23
24
|
const doc = index.useDocument();
|
|
25
|
+
const appRoot = AppRootProvider.useAppRootElement();
|
|
26
|
+
const cacheId = CSSCacheProvider.useCSSCacheId();
|
|
24
27
|
const { el, root } = React.useMemo(() => {
|
|
25
28
|
const el = doc.document.createElement("div");
|
|
26
29
|
const root = client.createRoot(el);
|
|
@@ -37,19 +40,19 @@ function usePortal(children, options) {
|
|
|
37
40
|
if (!cont.contains(el)) {
|
|
38
41
|
cont.appendChild(el);
|
|
39
42
|
}
|
|
40
|
-
root.render(jsxRuntime.jsx(
|
|
43
|
+
root.render(jsxRuntime.jsx(index$1, { theme: theme.name, CSSCacheId: cacheId, document: doc.document, children: children }));
|
|
41
44
|
};
|
|
42
45
|
const unmount = () => {
|
|
43
46
|
root.render(null);
|
|
44
47
|
el.remove();
|
|
45
48
|
};
|
|
46
49
|
React.useEffect(() => {
|
|
47
|
-
mounted ? mount() : unmount();
|
|
48
|
-
}, [mounted]);
|
|
50
|
+
(mounted && appRoot) ? mount() : unmount();
|
|
51
|
+
}, [mounted, appRoot]);
|
|
49
52
|
React.useEffect(() => {
|
|
50
|
-
if (mounted)
|
|
53
|
+
if (mounted && appRoot)
|
|
51
54
|
mount();
|
|
52
|
-
}, [children]);
|
|
55
|
+
}, [children, appRoot]);
|
|
53
56
|
React.useEffect(() => {
|
|
54
57
|
return () => {
|
|
55
58
|
unmount();
|
package/hooks/usePortal.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePortal.cjs","sources":["../../src/hooks/usePortal.tsx"],"sourcesContent":["\"use client\";\r\nimport React, { useEffect, useMemo } from \"react\";\r\nimport { createRoot } from \"react-dom/client\";\r\nimport { ThemeProvider, useTheme } from \"../theme\";\r\nimport { useAppRootElement } from \"../AppRoot/AppRootProvider\";\r\nimport { useDocument } from \"../Document\";\r\n\r\nexport type UsePortalOptions = {\r\n container?: HTMLElement;\r\n autoMount?: boolean;\r\n}\r\n\r\nfunction usePortal(children: React.ReactNode, options?: UsePortalOptions) {\r\n options = options || {};\r\n if (options.autoMount === undefined) {\r\n options.autoMount = true;\r\n }\r\n const [mounted, setMounted] = React.useState(options.autoMount);\r\n const theme = useTheme();\r\n const appRoot = useAppRootElement();\r\n const
|
|
1
|
+
{"version":3,"file":"usePortal.cjs","sources":["../../src/hooks/usePortal.tsx"],"sourcesContent":["\"use client\";\r\nimport React, { useEffect, useMemo } from \"react\";\r\nimport { createRoot } from \"react-dom/client\";\r\nimport { ThemeProvider, useTheme } from \"../theme\";\r\nimport { useAppRootElement } from \"../AppRoot/AppRootProvider\";\r\nimport { useDocument } from \"../Document\";\r\nimport AppRoot from \"../AppRoot\";\r\nimport { useCSSCacheId } from \"../css/CSSCacheProvider\";\r\n\r\nexport type UsePortalOptions = {\r\n container?: HTMLElement;\r\n autoMount?: boolean;\r\n}\r\n\r\nfunction usePortal(children: React.ReactNode, options?: UsePortalOptions) {\r\n options = options || {};\r\n if (options.autoMount === undefined) {\r\n options.autoMount = true;\r\n }\r\n const [mounted, setMounted] = React.useState(options.autoMount);\r\n const theme = useTheme();\r\n const doc = useDocument()\r\n const appRoot = useAppRootElement();\r\n const cacheId = useCSSCacheId()\r\n\r\n const { el, root } = useMemo(() => {\r\n const el = doc.document.createElement(\"div\");\r\n const root = createRoot(el);\r\n return { el, root };\r\n }, [options.autoMount]);\r\n\r\n const container = () => {\r\n const container = options?.container || appRoot\r\n if (!container) throw new Error(`Container not found for portal. Please ensure that AppRoot is present in the application tree.`);\r\n return container;\r\n }\r\n\r\n const mount = () => {\r\n const cont = container();\r\n if (!cont.contains(el)) {\r\n cont.appendChild(el);\r\n }\r\n root.render(<AppRoot theme={theme.name} CSSCacheId={cacheId} document={doc.document}>{children}</AppRoot>)\r\n }\r\n\r\n const unmount = () => {\r\n root.render(null)\r\n el.remove();\r\n }\r\n\r\n useEffect(() => {\r\n (mounted && appRoot) ? mount() : unmount()\r\n }, [mounted, appRoot]);\r\n\r\n useEffect(() => {\r\n if (mounted && appRoot) mount()\r\n }, [children, appRoot]);\r\n\r\n useEffect(() => {\r\n return () => {\r\n unmount()\r\n };\r\n }, []);\r\n\r\n return {\r\n isMount: () => mounted,\r\n mount: () => setMounted(true),\r\n unmount: () => setMounted(false)\r\n }\r\n}\r\n\r\n\r\nexport default usePortal;"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAcA;AACG;AACA;AACG;;AAEH;AACA;AACA;AACA;AACA;;;AAIG;AACA;AACH;;AAGG;AACA;AAAgB;AAChB;AACH;;AAGG;;AAEG;;;AAGN;;AAGG;;AAEH;;AAGG;AACH;;;AAG2B;AAC3B;;AAGG;AACG;AACH;;;AAIA;AACA;AACA;;AAEN;;"}
|
package/hooks/usePortal.js
CHANGED
|
@@ -5,10 +5,12 @@ import { createRoot } from 'react-dom/client';
|
|
|
5
5
|
import { useTheme } from '../theme/core.js';
|
|
6
6
|
import '../css/getValue.js';
|
|
7
7
|
import 'oncss';
|
|
8
|
-
import
|
|
8
|
+
import '../theme/ThemeProvider.js';
|
|
9
9
|
import 'react-state-bucket';
|
|
10
10
|
import { useAppRootElement } from '../AppRoot/AppRootProvider.js';
|
|
11
11
|
import { useDocument } from '../Document/index.js';
|
|
12
|
+
import AppRoot from '../AppRoot/index.js';
|
|
13
|
+
import { useCSSCacheId } from '../css/CSSCacheProvider.js';
|
|
12
14
|
|
|
13
15
|
function usePortal(children, options) {
|
|
14
16
|
options = options || {};
|
|
@@ -17,8 +19,9 @@ function usePortal(children, options) {
|
|
|
17
19
|
}
|
|
18
20
|
const [mounted, setMounted] = React__default.useState(options.autoMount);
|
|
19
21
|
const theme = useTheme();
|
|
20
|
-
const appRoot = useAppRootElement();
|
|
21
22
|
const doc = useDocument();
|
|
23
|
+
const appRoot = useAppRootElement();
|
|
24
|
+
const cacheId = useCSSCacheId();
|
|
22
25
|
const { el, root } = useMemo(() => {
|
|
23
26
|
const el = doc.document.createElement("div");
|
|
24
27
|
const root = createRoot(el);
|
|
@@ -35,19 +38,19 @@ function usePortal(children, options) {
|
|
|
35
38
|
if (!cont.contains(el)) {
|
|
36
39
|
cont.appendChild(el);
|
|
37
40
|
}
|
|
38
|
-
root.render(jsx(
|
|
41
|
+
root.render(jsx(AppRoot, { theme: theme.name, CSSCacheId: cacheId, document: doc.document, children: children }));
|
|
39
42
|
};
|
|
40
43
|
const unmount = () => {
|
|
41
44
|
root.render(null);
|
|
42
45
|
el.remove();
|
|
43
46
|
};
|
|
44
47
|
useEffect(() => {
|
|
45
|
-
mounted ? mount() : unmount();
|
|
46
|
-
}, [mounted]);
|
|
48
|
+
(mounted && appRoot) ? mount() : unmount();
|
|
49
|
+
}, [mounted, appRoot]);
|
|
47
50
|
useEffect(() => {
|
|
48
|
-
if (mounted)
|
|
51
|
+
if (mounted && appRoot)
|
|
49
52
|
mount();
|
|
50
|
-
}, [children]);
|
|
53
|
+
}, [children, appRoot]);
|
|
51
54
|
useEffect(() => {
|
|
52
55
|
return () => {
|
|
53
56
|
unmount();
|
package/hooks/usePortal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePortal.js","sources":["../../src/hooks/usePortal.tsx"],"sourcesContent":["\"use client\";\r\nimport React, { useEffect, useMemo } from \"react\";\r\nimport { createRoot } from \"react-dom/client\";\r\nimport { ThemeProvider, useTheme } from \"../theme\";\r\nimport { useAppRootElement } from \"../AppRoot/AppRootProvider\";\r\nimport { useDocument } from \"../Document\";\r\n\r\nexport type UsePortalOptions = {\r\n container?: HTMLElement;\r\n autoMount?: boolean;\r\n}\r\n\r\nfunction usePortal(children: React.ReactNode, options?: UsePortalOptions) {\r\n options = options || {};\r\n if (options.autoMount === undefined) {\r\n options.autoMount = true;\r\n }\r\n const [mounted, setMounted] = React.useState(options.autoMount);\r\n const theme = useTheme();\r\n const appRoot = useAppRootElement();\r\n const
|
|
1
|
+
{"version":3,"file":"usePortal.js","sources":["../../src/hooks/usePortal.tsx"],"sourcesContent":["\"use client\";\r\nimport React, { useEffect, useMemo } from \"react\";\r\nimport { createRoot } from \"react-dom/client\";\r\nimport { ThemeProvider, useTheme } from \"../theme\";\r\nimport { useAppRootElement } from \"../AppRoot/AppRootProvider\";\r\nimport { useDocument } from \"../Document\";\r\nimport AppRoot from \"../AppRoot\";\r\nimport { useCSSCacheId } from \"../css/CSSCacheProvider\";\r\n\r\nexport type UsePortalOptions = {\r\n container?: HTMLElement;\r\n autoMount?: boolean;\r\n}\r\n\r\nfunction usePortal(children: React.ReactNode, options?: UsePortalOptions) {\r\n options = options || {};\r\n if (options.autoMount === undefined) {\r\n options.autoMount = true;\r\n }\r\n const [mounted, setMounted] = React.useState(options.autoMount);\r\n const theme = useTheme();\r\n const doc = useDocument()\r\n const appRoot = useAppRootElement();\r\n const cacheId = useCSSCacheId()\r\n\r\n const { el, root } = useMemo(() => {\r\n const el = doc.document.createElement(\"div\");\r\n const root = createRoot(el);\r\n return { el, root };\r\n }, [options.autoMount]);\r\n\r\n const container = () => {\r\n const container = options?.container || appRoot\r\n if (!container) throw new Error(`Container not found for portal. Please ensure that AppRoot is present in the application tree.`);\r\n return container;\r\n }\r\n\r\n const mount = () => {\r\n const cont = container();\r\n if (!cont.contains(el)) {\r\n cont.appendChild(el);\r\n }\r\n root.render(<AppRoot theme={theme.name} CSSCacheId={cacheId} document={doc.document}>{children}</AppRoot>)\r\n }\r\n\r\n const unmount = () => {\r\n root.render(null)\r\n el.remove();\r\n }\r\n\r\n useEffect(() => {\r\n (mounted && appRoot) ? mount() : unmount()\r\n }, [mounted, appRoot]);\r\n\r\n useEffect(() => {\r\n if (mounted && appRoot) mount()\r\n }, [children, appRoot]);\r\n\r\n useEffect(() => {\r\n return () => {\r\n unmount()\r\n };\r\n }, []);\r\n\r\n return {\r\n isMount: () => mounted,\r\n mount: () => setMounted(true),\r\n unmount: () => setMounted(false)\r\n }\r\n}\r\n\r\n\r\nexport default usePortal;"],"names":[],"mappings":";;;;;;;;;;;;;;AAcA;AACG;AACA;AACG;;AAEH;AACA;AACA;AACA;AACA;;;AAIG;AACA;AACH;;AAGG;AACA;AAAgB;AAChB;AACH;;AAGG;;AAEG;;;AAGN;;AAGG;;AAEH;;AAGG;AACH;;;AAG2B;AAC3B;;AAGG;AACG;AACH;;;AAIA;AACA;AACA;;AAEN;;"}
|
|
@@ -22,19 +22,19 @@ const getVariant = (rect, variant) => {
|
|
|
22
22
|
const useTransition = (_a) => {
|
|
23
23
|
var { open } = _a, props = tslib.__rest(_a, ["open"]);
|
|
24
24
|
let { disableInitialTransition = false, variant = "fade", duration = 400, delay, ease, easing, exitOnUnmount = false, onOpen, onOpened, onClose, onClosed, onState } = props;
|
|
25
|
-
const doc = index.useDocument()
|
|
25
|
+
const doc = index.useDocument();
|
|
26
26
|
const cacheId = CSSCacheProvider.useCSSCacheId();
|
|
27
27
|
let _ease = ease || useAnimation.animationEases[easing] || useAnimation.animationEases.bounce;
|
|
28
28
|
const id = "xui-transition-" + React.useId();
|
|
29
29
|
const [state, setState] = React.useState({
|
|
30
30
|
initial: false,
|
|
31
|
-
classname: style({ visibility: "hidden" }, doc, cacheId),
|
|
31
|
+
classname: style({ visibility: "hidden" }, doc.document, cacheId),
|
|
32
32
|
variant: variant,
|
|
33
33
|
rect: null,
|
|
34
34
|
stage: open ? "open" : "closed",
|
|
35
35
|
unmounted: false,
|
|
36
36
|
});
|
|
37
|
-
const getEle = () => doc.querySelector(`[data-transition="${id}"]`);
|
|
37
|
+
const getEle = () => doc.document.querySelector(`[data-transition="${id}"]`);
|
|
38
38
|
const getBoundary = () => { var _a; return state.rect || ((_a = getEle()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) || new DOMRect(0, 0, 0, 0); };
|
|
39
39
|
React.useEffect(() => {
|
|
40
40
|
if (exitOnUnmount && state.stage === 'closed') {
|
|
@@ -42,7 +42,7 @@ const useTransition = (_a) => {
|
|
|
42
42
|
setState(s => (Object.assign(Object.assign({}, s), { initial: false, classname: "", unmounted: true, variant: variant })));
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
setState(s => (Object.assign(Object.assign({}, s), { variant: variant, classname: style({ visibility: "hidden" }, doc, cacheId), stage: "open" })));
|
|
45
|
+
setState(s => (Object.assign(Object.assign({}, s), { variant: variant, classname: style({ visibility: "hidden" }, doc.document, cacheId), stage: "open" })));
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}, [open, state.stage, exitOnUnmount, variant]);
|
|
@@ -56,7 +56,7 @@ const useTransition = (_a) => {
|
|
|
56
56
|
const rect = getBoundary();
|
|
57
57
|
let { from } = getVariant(rect, state.variant);
|
|
58
58
|
if (open && !state.initial) {
|
|
59
|
-
setState(s => (Object.assign(Object.assign({}, s), { classname: (!disableInitialTransition || state.unmounted) ? style(from, doc, cacheId) : "", initial: true, rect: rect })));
|
|
59
|
+
setState(s => (Object.assign(Object.assign({}, s), { classname: (!disableInitialTransition || state.unmounted) ? style(from, doc.document, cacheId) : "", initial: true, rect: rect })));
|
|
60
60
|
let stimer = null;
|
|
61
61
|
let etimer = null;
|
|
62
62
|
ele.ontransitionstart = () => {
|
|
@@ -81,7 +81,7 @@ const useTransition = (_a) => {
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
else if (!state.initial) {
|
|
84
|
-
setState(s => (Object.assign(Object.assign({}, s), { classname: style(from, doc, cacheId), rect: rect })));
|
|
84
|
+
setState(s => (Object.assign(Object.assign({}, s), { classname: style(from, doc.document, cacheId), rect: rect })));
|
|
85
85
|
}
|
|
86
86
|
}, [open, state.initial, state.stage, exitOnUnmount]);
|
|
87
87
|
React.useEffect(() => {
|
|
@@ -91,7 +91,7 @@ const useTransition = (_a) => {
|
|
|
91
91
|
let _css = open ? to : from;
|
|
92
92
|
let trans = ` ${duration}ms ${_ease} ${delay || 0}ms`;
|
|
93
93
|
let _ = Object.assign(Object.assign({}, _css), { transition: Object.keys(_css || {}).map(k => oncss.formatCSSProp(k)).join(trans + ", ") + trans });
|
|
94
|
-
setState(s => (Object.assign(Object.assign({}, s), { classname: style(_, doc, cacheId), variant: _variant })));
|
|
94
|
+
setState(s => (Object.assign(Object.assign({}, s), { classname: style(_, doc.document, cacheId), variant: _variant })));
|
|
95
95
|
}
|
|
96
96
|
}, [open, state.initial, variant]);
|
|
97
97
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/hooks/useTransition/index.ts"],"sourcesContent":["\"use client\";\r\nimport { useState, useEffect, useId } from 'react';\r\nimport { animationEases } from '../useAnimation';\r\nimport { css } from '../../css';\r\nimport { formatCSSProp } from 'oncss';\r\nimport { CSSProps } from '../../css/types';\r\nimport * as variants from './variants'\r\nimport { useDocument } from '../../Document';\r\nimport { useCSSCacheId } from '../../css/CSSCacheProvider';\r\n\r\nexport type UseTransitionVariantTypes = keyof typeof variants\r\nexport type UseTransitionState = \"open\" | \"opened\" | \"close\" | \"closed\"\r\n\r\nexport type UseTransitionVariant = (rect: DOMRect) => ({ from: CSSProps, to: CSSProps })\r\n\r\nexport type UseTransitionProps = {\r\n open: boolean;\r\n variant: UseTransitionVariant | UseTransitionVariantTypes;\r\n ease?: string;\r\n easing?: keyof typeof animationEases;\r\n duration?: number;\r\n delay?: number;\r\n disableInitialTransition?: boolean;\r\n exitOnUnmount?: boolean;\r\n onOpen?: () => void;\r\n onOpened?: () => void;\r\n onClose?: () => void;\r\n onClosed?: () => void;\r\n onState?: (state: UseTransitionState) => void;\r\n}\r\n\r\n\r\nconst style = (obj = {}, doc: Document, cacheId: string) => {\r\n return css(obj, { selector: \"#\", container: doc, cacheId }).classname;\r\n}\r\n\r\nconst getVariant = (rect: DOMRect | null, variant: UseTransitionProps['variant']) => {\r\n let fn = typeof variant === 'string' ? variants[variant] : variant\r\n if (!fn) throw new Error(`Transition variant \"${variant}\" not found.`)\r\n return fn(rect as DOMRect);\r\n}\r\n\r\nconst useTransition = ({ open, ...props }: UseTransitionProps) => {\r\n let {\r\n disableInitialTransition = false,\r\n variant = \"fade\",\r\n duration = 400,\r\n delay,\r\n ease,\r\n easing,\r\n exitOnUnmount = false,\r\n onOpen,\r\n onOpened,\r\n onClose,\r\n onClosed,\r\n onState\r\n } = props\r\n const doc = useDocument()
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/hooks/useTransition/index.ts"],"sourcesContent":["\"use client\";\r\nimport { useState, useEffect, useId } from 'react';\r\nimport { animationEases } from '../useAnimation';\r\nimport { css } from '../../css';\r\nimport { formatCSSProp } from 'oncss';\r\nimport { CSSProps } from '../../css/types';\r\nimport * as variants from './variants'\r\nimport { useDocument } from '../../Document';\r\nimport { useCSSCacheId } from '../../css/CSSCacheProvider';\r\n\r\nexport type UseTransitionVariantTypes = keyof typeof variants\r\nexport type UseTransitionState = \"open\" | \"opened\" | \"close\" | \"closed\"\r\n\r\nexport type UseTransitionVariant = (rect: DOMRect) => ({ from: CSSProps, to: CSSProps })\r\n\r\nexport type UseTransitionProps = {\r\n open: boolean;\r\n variant: UseTransitionVariant | UseTransitionVariantTypes;\r\n ease?: string;\r\n easing?: keyof typeof animationEases;\r\n duration?: number;\r\n delay?: number;\r\n disableInitialTransition?: boolean;\r\n exitOnUnmount?: boolean;\r\n onOpen?: () => void;\r\n onOpened?: () => void;\r\n onClose?: () => void;\r\n onClosed?: () => void;\r\n onState?: (state: UseTransitionState) => void;\r\n}\r\n\r\n\r\nconst style = (obj = {}, doc: Document, cacheId: string) => {\r\n return css(obj, { selector: \"#\", container: doc, cacheId }).classname;\r\n}\r\n\r\nconst getVariant = (rect: DOMRect | null, variant: UseTransitionProps['variant']) => {\r\n let fn = typeof variant === 'string' ? variants[variant] : variant\r\n if (!fn) throw new Error(`Transition variant \"${variant}\" not found.`)\r\n return fn(rect as DOMRect);\r\n}\r\n\r\nconst useTransition = ({ open, ...props }: UseTransitionProps) => {\r\n let {\r\n disableInitialTransition = false,\r\n variant = \"fade\",\r\n duration = 400,\r\n delay,\r\n ease,\r\n easing,\r\n exitOnUnmount = false,\r\n onOpen,\r\n onOpened,\r\n onClose,\r\n onClosed,\r\n onState\r\n } = props\r\n const doc = useDocument();\r\n const cacheId = useCSSCacheId()\r\n let _ease = ease || (animationEases as any)[easing as any] || animationEases.bounce\r\n const id = \"xui-transition-\" + useId()\r\n const [state, setState] = useState({\r\n initial: false,\r\n classname: style({ visibility: \"hidden\" }, doc.document, cacheId),\r\n variant: variant,\r\n rect: null as DOMRect | null,\r\n stage: open ? \"open\" : \"closed\",\r\n unmounted: false,\r\n })\r\n\r\n const getEle = () => doc.document.querySelector(`[data-transition=\"${id}\"]`) as HTMLElement;\r\n const getBoundary = () => state.rect || getEle()?.getBoundingClientRect() || new DOMRect(0, 0, 0, 0);\r\n\r\n useEffect(() => {\r\n if (exitOnUnmount && state.stage === 'closed') {\r\n if (!open) {\r\n setState(s => ({\r\n ...s,\r\n initial: false,\r\n classname: \"\",\r\n unmounted: true,\r\n variant: variant,\r\n }))\r\n } else {\r\n setState(s => ({\r\n ...s,\r\n variant: variant,\r\n classname: style({ visibility: \"hidden\" }, doc.document, cacheId),\r\n stage: \"open\",\r\n }))\r\n }\r\n }\r\n }, [open, state.stage, exitOnUnmount, variant])\r\n\r\n // initial effect\r\n useEffect(() => {\r\n const ele = getEle()\r\n if (!ele) return\r\n if (exitOnUnmount && state.stage === 'closed') return\r\n\r\n const rect = getBoundary();\r\n let { from } = getVariant(rect, state.variant)\r\n if (open && !state.initial) {\r\n setState(s => ({\r\n ...s,\r\n classname: (!disableInitialTransition || state.unmounted) ? style(from, doc.document, cacheId) : \"\",\r\n initial: true,\r\n rect: rect,\r\n }))\r\n let stimer: any = null\r\n let etimer: any = null\r\n ele.ontransitionstart = () => {\r\n clearTimeout(stimer)\r\n stimer = setTimeout(() => {\r\n const isOpen = ele.getAttribute('data-transition-state') === 'open';\r\n (onOpen && isOpen) && onOpen();\r\n (onClose && !isOpen) && onClose()\r\n onState && onState(isOpen ? \"open\" : \"close\")\r\n setState(s => ({\r\n ...s,\r\n stage: isOpen ? \"open\" : \"close\"\r\n }))\r\n }, 1)\r\n }\r\n\r\n ele.ontransitionend = () => {\r\n clearTimeout(etimer)\r\n etimer = setTimeout(() => {\r\n const isOpen = ele.getAttribute('data-transition-state') === 'open';\r\n (onOpened && isOpen) && onOpened();\r\n (onClosed && !isOpen) && onClosed();\r\n onState && onState(isOpen ? \"opened\" : \"closed\")\r\n setState(s => ({\r\n ...s,\r\n stage: isOpen ? \"opened\" : \"closed\"\r\n }))\r\n }, 1)\r\n }\r\n } else if (!state.initial) {\r\n setState(s => ({\r\n ...s,\r\n classname: style(from, doc.document, cacheId),\r\n rect: rect,\r\n }))\r\n }\r\n }, [open, state.initial, state.stage, exitOnUnmount])\r\n\r\n\r\n useEffect(() => {\r\n if (state.initial) {\r\n let _variant = state.variant !== variant ? variant : state.variant\r\n const { from, to } = getVariant(state.rect, _variant)\r\n let _css: CSSProps = open ? to : from\r\n let trans = ` ${duration}ms ${_ease} ${delay || 0}ms`\r\n let _ = {\r\n ..._css,\r\n transition: Object.keys(_css || {}).map(k => formatCSSProp(k)).join(trans + \", \") + trans,\r\n }\r\n setState(s => ({\r\n ...s,\r\n classname: style(_, doc.document, cacheId),\r\n variant: _variant\r\n }))\r\n }\r\n }, [open, state.initial, variant])\r\n\r\n return {\r\n exited: exitOnUnmount && state.stage === 'closed',\r\n props: {\r\n 'id': state.classname,\r\n 'data-transition': id,\r\n 'data-transition-state': open ? 'open' : 'close',\r\n }\r\n }\r\n}\r\n\r\n\r\nexport default useTransition"],"names":[],"mappings":";;;;;;;;;;;;AAgCA;AACG;AACH;AAEA;AACG;AACA;AAAS;AACT;AACH;AAEA;AAAuB;AACpB;AAcA;AACA;AACA;AACA;AACA;AACG;AACA;AACA;AACA;;AAEA;AACF;AAED;AACA;;;;;;;AAaS;;;AAQT;;;AAIG;AACA;;AACA;;AAEA;AACA;AACA;;;;AASG;;AAEG;;AAEG;;AAEA;;;AAMN;AAEA;;AAEG;;AAEG;;AAEA;;;AAMN;;AACI;;;AAOV;;AAIG;AACG;AACA;;;AAGA;;;;;AAaH;AACA;;AAEG;;AAEF;;AAEP;;"}
|
|
@@ -20,19 +20,19 @@ const getVariant = (rect, variant) => {
|
|
|
20
20
|
const useTransition = (_a) => {
|
|
21
21
|
var { open } = _a, props = __rest(_a, ["open"]);
|
|
22
22
|
let { disableInitialTransition = false, variant = "fade", duration = 400, delay, ease, easing, exitOnUnmount = false, onOpen, onOpened, onClose, onClosed, onState } = props;
|
|
23
|
-
const doc = useDocument()
|
|
23
|
+
const doc = useDocument();
|
|
24
24
|
const cacheId = useCSSCacheId();
|
|
25
25
|
let _ease = ease || animationEases[easing] || animationEases.bounce;
|
|
26
26
|
const id = "xui-transition-" + useId();
|
|
27
27
|
const [state, setState] = useState({
|
|
28
28
|
initial: false,
|
|
29
|
-
classname: style({ visibility: "hidden" }, doc, cacheId),
|
|
29
|
+
classname: style({ visibility: "hidden" }, doc.document, cacheId),
|
|
30
30
|
variant: variant,
|
|
31
31
|
rect: null,
|
|
32
32
|
stage: open ? "open" : "closed",
|
|
33
33
|
unmounted: false,
|
|
34
34
|
});
|
|
35
|
-
const getEle = () => doc.querySelector(`[data-transition="${id}"]`);
|
|
35
|
+
const getEle = () => doc.document.querySelector(`[data-transition="${id}"]`);
|
|
36
36
|
const getBoundary = () => { var _a; return state.rect || ((_a = getEle()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) || new DOMRect(0, 0, 0, 0); };
|
|
37
37
|
useEffect(() => {
|
|
38
38
|
if (exitOnUnmount && state.stage === 'closed') {
|
|
@@ -40,7 +40,7 @@ const useTransition = (_a) => {
|
|
|
40
40
|
setState(s => (Object.assign(Object.assign({}, s), { initial: false, classname: "", unmounted: true, variant: variant })));
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
-
setState(s => (Object.assign(Object.assign({}, s), { variant: variant, classname: style({ visibility: "hidden" }, doc, cacheId), stage: "open" })));
|
|
43
|
+
setState(s => (Object.assign(Object.assign({}, s), { variant: variant, classname: style({ visibility: "hidden" }, doc.document, cacheId), stage: "open" })));
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
}, [open, state.stage, exitOnUnmount, variant]);
|
|
@@ -54,7 +54,7 @@ const useTransition = (_a) => {
|
|
|
54
54
|
const rect = getBoundary();
|
|
55
55
|
let { from } = getVariant(rect, state.variant);
|
|
56
56
|
if (open && !state.initial) {
|
|
57
|
-
setState(s => (Object.assign(Object.assign({}, s), { classname: (!disableInitialTransition || state.unmounted) ? style(from, doc, cacheId) : "", initial: true, rect: rect })));
|
|
57
|
+
setState(s => (Object.assign(Object.assign({}, s), { classname: (!disableInitialTransition || state.unmounted) ? style(from, doc.document, cacheId) : "", initial: true, rect: rect })));
|
|
58
58
|
let stimer = null;
|
|
59
59
|
let etimer = null;
|
|
60
60
|
ele.ontransitionstart = () => {
|
|
@@ -79,7 +79,7 @@ const useTransition = (_a) => {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
else if (!state.initial) {
|
|
82
|
-
setState(s => (Object.assign(Object.assign({}, s), { classname: style(from, doc, cacheId), rect: rect })));
|
|
82
|
+
setState(s => (Object.assign(Object.assign({}, s), { classname: style(from, doc.document, cacheId), rect: rect })));
|
|
83
83
|
}
|
|
84
84
|
}, [open, state.initial, state.stage, exitOnUnmount]);
|
|
85
85
|
useEffect(() => {
|
|
@@ -89,7 +89,7 @@ const useTransition = (_a) => {
|
|
|
89
89
|
let _css = open ? to : from;
|
|
90
90
|
let trans = ` ${duration}ms ${_ease} ${delay || 0}ms`;
|
|
91
91
|
let _ = Object.assign(Object.assign({}, _css), { transition: Object.keys(_css || {}).map(k => formatCSSProp(k)).join(trans + ", ") + trans });
|
|
92
|
-
setState(s => (Object.assign(Object.assign({}, s), { classname: style(_, doc, cacheId), variant: _variant })));
|
|
92
|
+
setState(s => (Object.assign(Object.assign({}, s), { classname: style(_, doc.document, cacheId), variant: _variant })));
|
|
93
93
|
}
|
|
94
94
|
}, [open, state.initial, variant]);
|
|
95
95
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/hooks/useTransition/index.ts"],"sourcesContent":["\"use client\";\r\nimport { useState, useEffect, useId } from 'react';\r\nimport { animationEases } from '../useAnimation';\r\nimport { css } from '../../css';\r\nimport { formatCSSProp } from 'oncss';\r\nimport { CSSProps } from '../../css/types';\r\nimport * as variants from './variants'\r\nimport { useDocument } from '../../Document';\r\nimport { useCSSCacheId } from '../../css/CSSCacheProvider';\r\n\r\nexport type UseTransitionVariantTypes = keyof typeof variants\r\nexport type UseTransitionState = \"open\" | \"opened\" | \"close\" | \"closed\"\r\n\r\nexport type UseTransitionVariant = (rect: DOMRect) => ({ from: CSSProps, to: CSSProps })\r\n\r\nexport type UseTransitionProps = {\r\n open: boolean;\r\n variant: UseTransitionVariant | UseTransitionVariantTypes;\r\n ease?: string;\r\n easing?: keyof typeof animationEases;\r\n duration?: number;\r\n delay?: number;\r\n disableInitialTransition?: boolean;\r\n exitOnUnmount?: boolean;\r\n onOpen?: () => void;\r\n onOpened?: () => void;\r\n onClose?: () => void;\r\n onClosed?: () => void;\r\n onState?: (state: UseTransitionState) => void;\r\n}\r\n\r\n\r\nconst style = (obj = {}, doc: Document, cacheId: string) => {\r\n return css(obj, { selector: \"#\", container: doc, cacheId }).classname;\r\n}\r\n\r\nconst getVariant = (rect: DOMRect | null, variant: UseTransitionProps['variant']) => {\r\n let fn = typeof variant === 'string' ? variants[variant] : variant\r\n if (!fn) throw new Error(`Transition variant \"${variant}\" not found.`)\r\n return fn(rect as DOMRect);\r\n}\r\n\r\nconst useTransition = ({ open, ...props }: UseTransitionProps) => {\r\n let {\r\n disableInitialTransition = false,\r\n variant = \"fade\",\r\n duration = 400,\r\n delay,\r\n ease,\r\n easing,\r\n exitOnUnmount = false,\r\n onOpen,\r\n onOpened,\r\n onClose,\r\n onClosed,\r\n onState\r\n } = props\r\n const doc = useDocument()
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/hooks/useTransition/index.ts"],"sourcesContent":["\"use client\";\r\nimport { useState, useEffect, useId } from 'react';\r\nimport { animationEases } from '../useAnimation';\r\nimport { css } from '../../css';\r\nimport { formatCSSProp } from 'oncss';\r\nimport { CSSProps } from '../../css/types';\r\nimport * as variants from './variants'\r\nimport { useDocument } from '../../Document';\r\nimport { useCSSCacheId } from '../../css/CSSCacheProvider';\r\n\r\nexport type UseTransitionVariantTypes = keyof typeof variants\r\nexport type UseTransitionState = \"open\" | \"opened\" | \"close\" | \"closed\"\r\n\r\nexport type UseTransitionVariant = (rect: DOMRect) => ({ from: CSSProps, to: CSSProps })\r\n\r\nexport type UseTransitionProps = {\r\n open: boolean;\r\n variant: UseTransitionVariant | UseTransitionVariantTypes;\r\n ease?: string;\r\n easing?: keyof typeof animationEases;\r\n duration?: number;\r\n delay?: number;\r\n disableInitialTransition?: boolean;\r\n exitOnUnmount?: boolean;\r\n onOpen?: () => void;\r\n onOpened?: () => void;\r\n onClose?: () => void;\r\n onClosed?: () => void;\r\n onState?: (state: UseTransitionState) => void;\r\n}\r\n\r\n\r\nconst style = (obj = {}, doc: Document, cacheId: string) => {\r\n return css(obj, { selector: \"#\", container: doc, cacheId }).classname;\r\n}\r\n\r\nconst getVariant = (rect: DOMRect | null, variant: UseTransitionProps['variant']) => {\r\n let fn = typeof variant === 'string' ? variants[variant] : variant\r\n if (!fn) throw new Error(`Transition variant \"${variant}\" not found.`)\r\n return fn(rect as DOMRect);\r\n}\r\n\r\nconst useTransition = ({ open, ...props }: UseTransitionProps) => {\r\n let {\r\n disableInitialTransition = false,\r\n variant = \"fade\",\r\n duration = 400,\r\n delay,\r\n ease,\r\n easing,\r\n exitOnUnmount = false,\r\n onOpen,\r\n onOpened,\r\n onClose,\r\n onClosed,\r\n onState\r\n } = props\r\n const doc = useDocument();\r\n const cacheId = useCSSCacheId()\r\n let _ease = ease || (animationEases as any)[easing as any] || animationEases.bounce\r\n const id = \"xui-transition-\" + useId()\r\n const [state, setState] = useState({\r\n initial: false,\r\n classname: style({ visibility: \"hidden\" }, doc.document, cacheId),\r\n variant: variant,\r\n rect: null as DOMRect | null,\r\n stage: open ? \"open\" : \"closed\",\r\n unmounted: false,\r\n })\r\n\r\n const getEle = () => doc.document.querySelector(`[data-transition=\"${id}\"]`) as HTMLElement;\r\n const getBoundary = () => state.rect || getEle()?.getBoundingClientRect() || new DOMRect(0, 0, 0, 0);\r\n\r\n useEffect(() => {\r\n if (exitOnUnmount && state.stage === 'closed') {\r\n if (!open) {\r\n setState(s => ({\r\n ...s,\r\n initial: false,\r\n classname: \"\",\r\n unmounted: true,\r\n variant: variant,\r\n }))\r\n } else {\r\n setState(s => ({\r\n ...s,\r\n variant: variant,\r\n classname: style({ visibility: \"hidden\" }, doc.document, cacheId),\r\n stage: \"open\",\r\n }))\r\n }\r\n }\r\n }, [open, state.stage, exitOnUnmount, variant])\r\n\r\n // initial effect\r\n useEffect(() => {\r\n const ele = getEle()\r\n if (!ele) return\r\n if (exitOnUnmount && state.stage === 'closed') return\r\n\r\n const rect = getBoundary();\r\n let { from } = getVariant(rect, state.variant)\r\n if (open && !state.initial) {\r\n setState(s => ({\r\n ...s,\r\n classname: (!disableInitialTransition || state.unmounted) ? style(from, doc.document, cacheId) : \"\",\r\n initial: true,\r\n rect: rect,\r\n }))\r\n let stimer: any = null\r\n let etimer: any = null\r\n ele.ontransitionstart = () => {\r\n clearTimeout(stimer)\r\n stimer = setTimeout(() => {\r\n const isOpen = ele.getAttribute('data-transition-state') === 'open';\r\n (onOpen && isOpen) && onOpen();\r\n (onClose && !isOpen) && onClose()\r\n onState && onState(isOpen ? \"open\" : \"close\")\r\n setState(s => ({\r\n ...s,\r\n stage: isOpen ? \"open\" : \"close\"\r\n }))\r\n }, 1)\r\n }\r\n\r\n ele.ontransitionend = () => {\r\n clearTimeout(etimer)\r\n etimer = setTimeout(() => {\r\n const isOpen = ele.getAttribute('data-transition-state') === 'open';\r\n (onOpened && isOpen) && onOpened();\r\n (onClosed && !isOpen) && onClosed();\r\n onState && onState(isOpen ? \"opened\" : \"closed\")\r\n setState(s => ({\r\n ...s,\r\n stage: isOpen ? \"opened\" : \"closed\"\r\n }))\r\n }, 1)\r\n }\r\n } else if (!state.initial) {\r\n setState(s => ({\r\n ...s,\r\n classname: style(from, doc.document, cacheId),\r\n rect: rect,\r\n }))\r\n }\r\n }, [open, state.initial, state.stage, exitOnUnmount])\r\n\r\n\r\n useEffect(() => {\r\n if (state.initial) {\r\n let _variant = state.variant !== variant ? variant : state.variant\r\n const { from, to } = getVariant(state.rect, _variant)\r\n let _css: CSSProps = open ? to : from\r\n let trans = ` ${duration}ms ${_ease} ${delay || 0}ms`\r\n let _ = {\r\n ..._css,\r\n transition: Object.keys(_css || {}).map(k => formatCSSProp(k)).join(trans + \", \") + trans,\r\n }\r\n setState(s => ({\r\n ...s,\r\n classname: style(_, doc.document, cacheId),\r\n variant: _variant\r\n }))\r\n }\r\n }, [open, state.initial, variant])\r\n\r\n return {\r\n exited: exitOnUnmount && state.stage === 'closed',\r\n props: {\r\n 'id': state.classname,\r\n 'data-transition': id,\r\n 'data-transition-state': open ? 'open' : 'close',\r\n }\r\n }\r\n}\r\n\r\n\r\nexport default useTransition"],"names":[],"mappings":";;;;;;;;;;AAgCA;AACG;AACH;AAEA;AACG;AACA;AAAS;AACT;AACH;AAEA;AAAuB;AACpB;AAcA;AACA;AACA;AACA;AACA;AACG;AACA;AACA;AACA;;AAEA;AACF;AAED;AACA;;;;;;;AAaS;;;AAQT;;;AAIG;AACA;;AACA;;AAEA;AACA;AACA;;;;AASG;;AAEG;;AAEG;;AAEA;;;AAMN;AAEA;;AAEG;;AAEG;;AAEA;;;AAMN;;AACI;;;AAOV;;AAIG;AACG;AACA;;;AAGA;;;;;AAaH;AACA;;AAEG;;AAEF;;AAEP;;"}
|
package/package.json
CHANGED
package/theme/ThemeProvider.cjs
CHANGED
|
@@ -41,7 +41,7 @@ const ThemeProvider = (_a) => {
|
|
|
41
41
|
console.error(`ThemeProvider: The theme '${theme}' is not defined. Please make sure to use a valid theme name.`);
|
|
42
42
|
THEME = core.ThemeFactory.get("light");
|
|
43
43
|
}
|
|
44
|
-
const doc = index.useDocument()
|
|
44
|
+
const doc = index.useDocument();
|
|
45
45
|
const cacheId = CSSCacheProvider.useCSSCacheId();
|
|
46
46
|
const themeGlobalStyle = React__namespace.useMemo(() => {
|
|
47
47
|
const root_cls = `.xui-${theme}-theme-root`;
|
|
@@ -54,7 +54,7 @@ const ThemeProvider = (_a) => {
|
|
|
54
54
|
"@global": Object.assign(Object.assign({}, gstyles), { [root_cls]: ThemeCssVars(THEME) })
|
|
55
55
|
}, {
|
|
56
56
|
injectStyle: typeof window !== 'undefined',
|
|
57
|
-
container: doc,
|
|
57
|
+
container: doc === null || doc === void 0 ? void 0 : doc.document,
|
|
58
58
|
cacheId
|
|
59
59
|
});
|
|
60
60
|
}, [theme, doc]);
|
|
@@ -106,7 +106,7 @@ const ThemeProvider = (_a) => {
|
|
|
106
106
|
}
|
|
107
107
|
}, {
|
|
108
108
|
injectStyle: typeof window !== 'undefined',
|
|
109
|
-
container: doc,
|
|
109
|
+
container: doc === null || doc === void 0 ? void 0 : doc.document,
|
|
110
110
|
cacheId
|
|
111
111
|
});
|
|
112
112
|
}, []);
|
|
@@ -139,7 +139,7 @@ const ThemeProvider = (_a) => {
|
|
|
139
139
|
}
|
|
140
140
|
}, {
|
|
141
141
|
injectStyle: typeof window !== 'undefined',
|
|
142
|
-
container: doc,
|
|
142
|
+
container: doc === null || doc === void 0 ? void 0 : doc.document,
|
|
143
143
|
cacheId
|
|
144
144
|
});
|
|
145
145
|
}, [noScrollbarCss, theme]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.cjs","sources":["../../src/theme/ThemeProvider.tsx"],"sourcesContent":["\"use client\";\r\nimport * as React from \"react\"\r\nimport { ThemeOptions } from \"./types\"\r\nimport Tag from \"../Tag\"\r\nimport { TagComponentType, TagProps } from \"../Tag/types\"\r\nimport { ThemeContex, ThemeFactory } from \"./core\"\r\nimport ThemeCssVars from \"./ThemeCssVars\"\r\nimport { css } from \"../css\"\r\nimport { createDefaultThemes } from \"./ThemeDefaultOptions\"\r\nimport ServerStyleTag from \"../Tag/ServerStyleTag\"\r\nimport { useDocument } from \"../Document\";\r\nimport { themeRootClass } from \".\";\r\nimport { useCSSCacheId } from \"../css/CSSCacheProvider\";\r\n\r\nexport type ThemeProviderProps<T extends TagComponentType = 'div'> = TagProps<T> & {\r\n theme: string;\r\n isRoot?: boolean;\r\n noScrollbarCss?: boolean;\r\n}\r\n\r\ncreateDefaultThemes()\r\n\r\nconst ThemeProvider = <T extends TagComponentType = 'div'>({ children, theme, isRoot, noScrollbarCss, ...props }: ThemeProviderProps<T>) => {\r\n let THEME = ThemeFactory.get(theme) as ThemeOptions\r\n if (!THEME) {\r\n console.error(`ThemeProvider: The theme '${theme}' is not defined. Please make sure to use a valid theme name.`)\r\n THEME = ThemeFactory.get(\"light\") as ThemeOptions\r\n }\r\n const doc = useDocument()
|
|
1
|
+
{"version":3,"file":"ThemeProvider.cjs","sources":["../../src/theme/ThemeProvider.tsx"],"sourcesContent":["\"use client\";\r\nimport * as React from \"react\"\r\nimport { ThemeOptions } from \"./types\"\r\nimport Tag from \"../Tag\"\r\nimport { TagComponentType, TagProps } from \"../Tag/types\"\r\nimport { ThemeContex, ThemeFactory } from \"./core\"\r\nimport ThemeCssVars from \"./ThemeCssVars\"\r\nimport { css } from \"../css\"\r\nimport { createDefaultThemes } from \"./ThemeDefaultOptions\"\r\nimport ServerStyleTag from \"../Tag/ServerStyleTag\"\r\nimport { useDocument } from \"../Document\";\r\nimport { themeRootClass } from \".\";\r\nimport { useCSSCacheId } from \"../css/CSSCacheProvider\";\r\n\r\nexport type ThemeProviderProps<T extends TagComponentType = 'div'> = TagProps<T> & {\r\n theme: string;\r\n isRoot?: boolean;\r\n noScrollbarCss?: boolean;\r\n}\r\n\r\ncreateDefaultThemes()\r\n\r\nconst ThemeProvider = <T extends TagComponentType = 'div'>({ children, theme, isRoot, noScrollbarCss, ...props }: ThemeProviderProps<T>) => {\r\n let THEME = ThemeFactory.get(theme) as ThemeOptions\r\n if (!THEME) {\r\n console.error(`ThemeProvider: The theme '${theme}' is not defined. Please make sure to use a valid theme name.`)\r\n THEME = ThemeFactory.get(\"light\") as ThemeOptions\r\n }\r\n const doc = useDocument()\r\n const cacheId = useCSSCacheId()\r\n\r\n const themeGlobalStyle: any = React.useMemo(() => {\r\n const root_cls = `.xui-${theme}-theme-root`\r\n let gkeys = Object.keys(THEME.globalStyle || {})\r\n let gstyles: any = {}\r\n gkeys.forEach((key) => {\r\n gstyles[`${root_cls} ${key}`] = THEME.globalStyle[key as any]\r\n })\r\n\r\n return css({\r\n \"@global\": {\r\n ...gstyles,\r\n [root_cls]: ThemeCssVars(THEME)\r\n }\r\n }, {\r\n injectStyle: typeof window !== 'undefined',\r\n container: doc?.document,\r\n cacheId\r\n })\r\n }, [theme, doc])\r\n\r\n const resetCss = React.useMemo(() => {\r\n if (!isRoot) return\r\n return css({\r\n \"@global\": {\r\n \"*\": {\r\n m: 0,\r\n p: 0,\r\n outline: \"none\",\r\n boxSizing: \"border-box\",\r\n verticalAlign: \"baseline\",\r\n },\r\n \"html, body\": {\r\n minHeight: \"100%\",\r\n \"-webkit-font-smoothing\": \"antialiased\",\r\n \"-moz-osx-font-smoothing\": \"grayscale\",\r\n } as any,\r\n \"img, picture, video, canvas, svg\": {\r\n maxWidth: \"100%\",\r\n display: \"block\"\r\n },\r\n \"input, button, textarea, select\": {\r\n font: \"inherit\"\r\n },\r\n \"table\": {\r\n borderCollapse: \"collapse\",\r\n borderSpacing: 0,\r\n },\r\n \"ol, ul\": {\r\n listStyle: \"none\",\r\n padding: 0,\r\n margin: 0,\r\n },\r\n \"a\": {\r\n display: \"inline-block\",\r\n color: \"inherit\",\r\n textDecoration: \"none\",\r\n cursor: \"pointer\",\r\n \"&:hover\": {\r\n textDecoration: \"underline\"\r\n }\r\n },\r\n \"p, h1, h2, h3, h4, h5, h6\": {\r\n overflowWrap: \"break-word\",\r\n },\r\n }\r\n }, {\r\n injectStyle: typeof window !== 'undefined',\r\n container: doc?.document,\r\n cacheId\r\n })\r\n }, [])\r\n\r\n const scrollbarCss: any = React.useMemo(() => {\r\n if (noScrollbarCss) return;\r\n const cls = (cls: string) => `${themeRootClass(theme)} ${cls}`\r\n let thumbSize = 6\r\n let thumbColor = \"var(--color-text-secondary)\"\r\n let trackColor = \"transparent\"\r\n\r\n return css({\r\n \"@global\": {\r\n [cls('*::-webkit-scrollbar')]: {\r\n width: thumbSize,\r\n height: thumbSize,\r\n },\r\n [cls(\"*::-webkit-scrollbar-thumb\")]: {\r\n backgroundColor: thumbColor,\r\n borderRadius: \"6px\",\r\n opacity: 0.6,\r\n },\r\n [cls(\"*::-webkit-scrollbar-thumb:hover\")]: {\r\n backgroundColor: thumbColor,\r\n opacity: 0.0,\r\n },\r\n [cls(\"*::-webkit-scrollbar-track\")]: {\r\n backgroundColor: trackColor,\r\n borderRadius: \"6px\",\r\n },\r\n }\r\n }, {\r\n injectStyle: typeof window !== 'undefined',\r\n container: doc?.document,\r\n cacheId\r\n }) as any\r\n }, [noScrollbarCss, theme])\r\n\r\n return (\r\n <ThemeContex.Provider value={theme}>\r\n {\r\n isRoot && <>\r\n <ServerStyleTag factory={resetCss as any} />\r\n {\r\n !noScrollbarCss && <ServerStyleTag factory={scrollbarCss} />\r\n }\r\n </>\r\n }\r\n <ServerStyleTag factory={themeGlobalStyle} />\r\n <Tag\r\n minHeight=\"100%\"\r\n bgcolor=\"background.primary\"\r\n color=\"text.primary\"\r\n fontSize=\"text\"\r\n fontWeight=\"text\"\r\n lineHeight=\"text\"\r\n fontFamily={`system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif`}\r\n {...props}\r\n sxr={{\r\n \"& a\": {\r\n color: \"brand.primary\",\r\n },\r\n }}\r\n baseClass={`${theme}-theme-root`}\r\n direction={THEME.rtl ? \"rtl\" : \"ltr\"}\r\n >\r\n {children}\r\n </Tag>\r\n </ThemeContex.Provider>\r\n )\r\n}\r\n\r\nexport default ThemeProvider"],"names":["createDefaultThemes"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBAA;AAEA;AAA2D;;;AAGrD;AACA;;AAEH;AACA;AAEA;AACG;AACA;;AAEA;AACG;AACH;AAEA;;;AAMG;AACA;;AAEF;AACJ;AAEA;AACG;;AACA;AACG;AACG;AACG;AACA;AACA;AACA;AACA;AACF;AACD;AACG;AACA;AACA;AACK;AACR;AACG;AACA;AACF;AACD;AACG;AACF;AACD;AACG;AACA;AACF;AACD;AACG;AACA;AACA;AACF;AACD;AACG;AACA;AACA;AACA;AACA;AACG;AACF;AACH;AACD;AACG;AACF;AACH;;AAED;AACA;;AAEF;;AAGJ;AACG;;AACA;;;;AAKA;AACG;AACG;AACG;AACA;AACF;AACD;AACG;AACA;AACA;AACF;AACD;AACG;AACA;AACF;AACD;AACG;AACA;AACF;AACH;;AAED;AACA;;AAEF;AACJ;AAEA;AAqBY;AACG;AACF;;AAShB;;"}
|
package/theme/ThemeProvider.js
CHANGED
|
@@ -20,7 +20,7 @@ const ThemeProvider = (_a) => {
|
|
|
20
20
|
console.error(`ThemeProvider: The theme '${theme}' is not defined. Please make sure to use a valid theme name.`);
|
|
21
21
|
THEME = ThemeFactory.get("light");
|
|
22
22
|
}
|
|
23
|
-
const doc = useDocument()
|
|
23
|
+
const doc = useDocument();
|
|
24
24
|
const cacheId = useCSSCacheId();
|
|
25
25
|
const themeGlobalStyle = React.useMemo(() => {
|
|
26
26
|
const root_cls = `.xui-${theme}-theme-root`;
|
|
@@ -33,7 +33,7 @@ const ThemeProvider = (_a) => {
|
|
|
33
33
|
"@global": Object.assign(Object.assign({}, gstyles), { [root_cls]: ThemeCssVars(THEME) })
|
|
34
34
|
}, {
|
|
35
35
|
injectStyle: typeof window !== 'undefined',
|
|
36
|
-
container: doc,
|
|
36
|
+
container: doc === null || doc === void 0 ? void 0 : doc.document,
|
|
37
37
|
cacheId
|
|
38
38
|
});
|
|
39
39
|
}, [theme, doc]);
|
|
@@ -85,7 +85,7 @@ const ThemeProvider = (_a) => {
|
|
|
85
85
|
}
|
|
86
86
|
}, {
|
|
87
87
|
injectStyle: typeof window !== 'undefined',
|
|
88
|
-
container: doc,
|
|
88
|
+
container: doc === null || doc === void 0 ? void 0 : doc.document,
|
|
89
89
|
cacheId
|
|
90
90
|
});
|
|
91
91
|
}, []);
|
|
@@ -118,7 +118,7 @@ const ThemeProvider = (_a) => {
|
|
|
118
118
|
}
|
|
119
119
|
}, {
|
|
120
120
|
injectStyle: typeof window !== 'undefined',
|
|
121
|
-
container: doc,
|
|
121
|
+
container: doc === null || doc === void 0 ? void 0 : doc.document,
|
|
122
122
|
cacheId
|
|
123
123
|
});
|
|
124
124
|
}, [noScrollbarCss, theme]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.js","sources":["../../src/theme/ThemeProvider.tsx"],"sourcesContent":["\"use client\";\r\nimport * as React from \"react\"\r\nimport { ThemeOptions } from \"./types\"\r\nimport Tag from \"../Tag\"\r\nimport { TagComponentType, TagProps } from \"../Tag/types\"\r\nimport { ThemeContex, ThemeFactory } from \"./core\"\r\nimport ThemeCssVars from \"./ThemeCssVars\"\r\nimport { css } from \"../css\"\r\nimport { createDefaultThemes } from \"./ThemeDefaultOptions\"\r\nimport ServerStyleTag from \"../Tag/ServerStyleTag\"\r\nimport { useDocument } from \"../Document\";\r\nimport { themeRootClass } from \".\";\r\nimport { useCSSCacheId } from \"../css/CSSCacheProvider\";\r\n\r\nexport type ThemeProviderProps<T extends TagComponentType = 'div'> = TagProps<T> & {\r\n theme: string;\r\n isRoot?: boolean;\r\n noScrollbarCss?: boolean;\r\n}\r\n\r\ncreateDefaultThemes()\r\n\r\nconst ThemeProvider = <T extends TagComponentType = 'div'>({ children, theme, isRoot, noScrollbarCss, ...props }: ThemeProviderProps<T>) => {\r\n let THEME = ThemeFactory.get(theme) as ThemeOptions\r\n if (!THEME) {\r\n console.error(`ThemeProvider: The theme '${theme}' is not defined. Please make sure to use a valid theme name.`)\r\n THEME = ThemeFactory.get(\"light\") as ThemeOptions\r\n }\r\n const doc = useDocument()
|
|
1
|
+
{"version":3,"file":"ThemeProvider.js","sources":["../../src/theme/ThemeProvider.tsx"],"sourcesContent":["\"use client\";\r\nimport * as React from \"react\"\r\nimport { ThemeOptions } from \"./types\"\r\nimport Tag from \"../Tag\"\r\nimport { TagComponentType, TagProps } from \"../Tag/types\"\r\nimport { ThemeContex, ThemeFactory } from \"./core\"\r\nimport ThemeCssVars from \"./ThemeCssVars\"\r\nimport { css } from \"../css\"\r\nimport { createDefaultThemes } from \"./ThemeDefaultOptions\"\r\nimport ServerStyleTag from \"../Tag/ServerStyleTag\"\r\nimport { useDocument } from \"../Document\";\r\nimport { themeRootClass } from \".\";\r\nimport { useCSSCacheId } from \"../css/CSSCacheProvider\";\r\n\r\nexport type ThemeProviderProps<T extends TagComponentType = 'div'> = TagProps<T> & {\r\n theme: string;\r\n isRoot?: boolean;\r\n noScrollbarCss?: boolean;\r\n}\r\n\r\ncreateDefaultThemes()\r\n\r\nconst ThemeProvider = <T extends TagComponentType = 'div'>({ children, theme, isRoot, noScrollbarCss, ...props }: ThemeProviderProps<T>) => {\r\n let THEME = ThemeFactory.get(theme) as ThemeOptions\r\n if (!THEME) {\r\n console.error(`ThemeProvider: The theme '${theme}' is not defined. Please make sure to use a valid theme name.`)\r\n THEME = ThemeFactory.get(\"light\") as ThemeOptions\r\n }\r\n const doc = useDocument()\r\n const cacheId = useCSSCacheId()\r\n\r\n const themeGlobalStyle: any = React.useMemo(() => {\r\n const root_cls = `.xui-${theme}-theme-root`\r\n let gkeys = Object.keys(THEME.globalStyle || {})\r\n let gstyles: any = {}\r\n gkeys.forEach((key) => {\r\n gstyles[`${root_cls} ${key}`] = THEME.globalStyle[key as any]\r\n })\r\n\r\n return css({\r\n \"@global\": {\r\n ...gstyles,\r\n [root_cls]: ThemeCssVars(THEME)\r\n }\r\n }, {\r\n injectStyle: typeof window !== 'undefined',\r\n container: doc?.document,\r\n cacheId\r\n })\r\n }, [theme, doc])\r\n\r\n const resetCss = React.useMemo(() => {\r\n if (!isRoot) return\r\n return css({\r\n \"@global\": {\r\n \"*\": {\r\n m: 0,\r\n p: 0,\r\n outline: \"none\",\r\n boxSizing: \"border-box\",\r\n verticalAlign: \"baseline\",\r\n },\r\n \"html, body\": {\r\n minHeight: \"100%\",\r\n \"-webkit-font-smoothing\": \"antialiased\",\r\n \"-moz-osx-font-smoothing\": \"grayscale\",\r\n } as any,\r\n \"img, picture, video, canvas, svg\": {\r\n maxWidth: \"100%\",\r\n display: \"block\"\r\n },\r\n \"input, button, textarea, select\": {\r\n font: \"inherit\"\r\n },\r\n \"table\": {\r\n borderCollapse: \"collapse\",\r\n borderSpacing: 0,\r\n },\r\n \"ol, ul\": {\r\n listStyle: \"none\",\r\n padding: 0,\r\n margin: 0,\r\n },\r\n \"a\": {\r\n display: \"inline-block\",\r\n color: \"inherit\",\r\n textDecoration: \"none\",\r\n cursor: \"pointer\",\r\n \"&:hover\": {\r\n textDecoration: \"underline\"\r\n }\r\n },\r\n \"p, h1, h2, h3, h4, h5, h6\": {\r\n overflowWrap: \"break-word\",\r\n },\r\n }\r\n }, {\r\n injectStyle: typeof window !== 'undefined',\r\n container: doc?.document,\r\n cacheId\r\n })\r\n }, [])\r\n\r\n const scrollbarCss: any = React.useMemo(() => {\r\n if (noScrollbarCss) return;\r\n const cls = (cls: string) => `${themeRootClass(theme)} ${cls}`\r\n let thumbSize = 6\r\n let thumbColor = \"var(--color-text-secondary)\"\r\n let trackColor = \"transparent\"\r\n\r\n return css({\r\n \"@global\": {\r\n [cls('*::-webkit-scrollbar')]: {\r\n width: thumbSize,\r\n height: thumbSize,\r\n },\r\n [cls(\"*::-webkit-scrollbar-thumb\")]: {\r\n backgroundColor: thumbColor,\r\n borderRadius: \"6px\",\r\n opacity: 0.6,\r\n },\r\n [cls(\"*::-webkit-scrollbar-thumb:hover\")]: {\r\n backgroundColor: thumbColor,\r\n opacity: 0.0,\r\n },\r\n [cls(\"*::-webkit-scrollbar-track\")]: {\r\n backgroundColor: trackColor,\r\n borderRadius: \"6px\",\r\n },\r\n }\r\n }, {\r\n injectStyle: typeof window !== 'undefined',\r\n container: doc?.document,\r\n cacheId\r\n }) as any\r\n }, [noScrollbarCss, theme])\r\n\r\n return (\r\n <ThemeContex.Provider value={theme}>\r\n {\r\n isRoot && <>\r\n <ServerStyleTag factory={resetCss as any} />\r\n {\r\n !noScrollbarCss && <ServerStyleTag factory={scrollbarCss} />\r\n }\r\n </>\r\n }\r\n <ServerStyleTag factory={themeGlobalStyle} />\r\n <Tag\r\n minHeight=\"100%\"\r\n bgcolor=\"background.primary\"\r\n color=\"text.primary\"\r\n fontSize=\"text\"\r\n fontWeight=\"text\"\r\n lineHeight=\"text\"\r\n fontFamily={`system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif`}\r\n {...props}\r\n sxr={{\r\n \"& a\": {\r\n color: \"brand.primary\",\r\n },\r\n }}\r\n baseClass={`${theme}-theme-root`}\r\n direction={THEME.rtl ? \"rtl\" : \"ltr\"}\r\n >\r\n {children}\r\n </Tag>\r\n </ThemeContex.Provider>\r\n )\r\n}\r\n\r\nexport default ThemeProvider"],"names":[],"mappings":";;;;;;;;;;;;;;AAoBA;AAEA;AAA2D;;;AAGrD;AACA;;AAEH;AACA;AAEA;AACG;AACA;;AAEA;AACG;AACH;AAEA;;;AAMG;AACA;;AAEF;AACJ;AAEA;AACG;;AACA;AACG;AACG;AACG;AACA;AACA;AACA;AACA;AACF;AACD;AACG;AACA;AACA;AACK;AACR;AACG;AACA;AACF;AACD;AACG;AACF;AACD;AACG;AACA;AACF;AACD;AACG;AACA;AACA;AACF;AACD;AACG;AACA;AACA;AACA;AACA;AACG;AACF;AACH;AACD;AACG;AACF;AACH;;AAED;AACA;;AAEF;;AAGJ;AACG;;AACA;;;;AAKA;AACG;AACG;AACG;AACA;AACF;AACD;AACG;AACA;AACA;AACF;AACD;AACG;AACA;AACF;AACD;AACG;AACA;AACF;AACH;;AAED;AACA;;AAEF;AACJ;AAEA;AAqBY;AACG;AACF;;AAShB;;"}
|