@xbrain-swe/nova-chat-widget 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +22 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -57,7 +57,8 @@ var import_react = require("react");
|
|
|
57
57
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
58
58
|
var DEFAULT_THEME = {
|
|
59
59
|
accentFrom: "#4f46e5",
|
|
60
|
-
accentTo: "#7c3aed"
|
|
60
|
+
accentTo: "#7c3aed",
|
|
61
|
+
colorScheme: "system"
|
|
61
62
|
};
|
|
62
63
|
var InternalContext = (0, import_react.createContext)(null);
|
|
63
64
|
function useXbNovaInternal() {
|
|
@@ -968,10 +969,25 @@ function loadCss() {
|
|
|
968
969
|
}
|
|
969
970
|
return cssPromise;
|
|
970
971
|
}
|
|
972
|
+
function useResolvedScheme(scheme) {
|
|
973
|
+
const [systemDark, setSystemDark] = (0, import_react7.useState)(false);
|
|
974
|
+
(0, import_react7.useEffect)(() => {
|
|
975
|
+
if (scheme !== "system") return;
|
|
976
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
977
|
+
setSystemDark(mq.matches);
|
|
978
|
+
const onChange = (e) => setSystemDark(e.matches);
|
|
979
|
+
mq.addEventListener("change", onChange);
|
|
980
|
+
return () => mq.removeEventListener("change", onChange);
|
|
981
|
+
}, [scheme]);
|
|
982
|
+
if (scheme === "system") return systemDark ? "dark" : "light";
|
|
983
|
+
return scheme;
|
|
984
|
+
}
|
|
971
985
|
function XbNovaShadowRoot({
|
|
972
986
|
children,
|
|
973
987
|
style
|
|
974
988
|
}) {
|
|
989
|
+
const { theme } = useXbNovaInternal();
|
|
990
|
+
const scheme = useResolvedScheme(theme.colorScheme);
|
|
975
991
|
const hostRef = (0, import_react7.useRef)(null);
|
|
976
992
|
const [mountNode, setMountNode] = (0, import_react7.useState)(null);
|
|
977
993
|
const [portalTarget, setPortalTarget] = (0, import_react7.useState)(null);
|
|
@@ -993,6 +1009,11 @@ function XbNovaShadowRoot({
|
|
|
993
1009
|
shadow.appendChild(mount);
|
|
994
1010
|
setMountNode(mount);
|
|
995
1011
|
}, [portalTarget]);
|
|
1012
|
+
(0, import_react7.useEffect)(() => {
|
|
1013
|
+
if (!mountNode) return;
|
|
1014
|
+
mountNode.dataset.xbnovaScheme = scheme;
|
|
1015
|
+
mountNode.style.colorScheme = scheme;
|
|
1016
|
+
}, [mountNode, scheme]);
|
|
996
1017
|
if (!portalTarget) return null;
|
|
997
1018
|
return (0, import_react_dom.createPortal)(
|
|
998
1019
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ref: hostRef, style, children: mountNode ? (0, import_react_dom.createPortal)(children, mountNode) : null }),
|