@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.d.cts
CHANGED
|
@@ -43,6 +43,10 @@ type FactValue = unknown | (() => unknown);
|
|
|
43
43
|
type XbNovaTheme = {
|
|
44
44
|
accentFrom: string;
|
|
45
45
|
accentTo: string;
|
|
46
|
+
/** 위젯의 라이트/다크. `"system"`(기본)은 브라우저·OS 설정을 따른다 — 호스트 사이트가 다크
|
|
47
|
+
* 모드를 지원하지 않는데 사용자 OS만 다크이면 사이트는 밝은데 위젯만 어두워진다. 그런 사이트는
|
|
48
|
+
* `"light"`로 고정하고, 사이트 자체 테마를 가진 호스트는 그 값을 넘기면 된다. */
|
|
49
|
+
colorScheme: "light" | "dark" | "system";
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
declare function XbNovaProvider({ apiKey, botId, appId, screen, apiBaseUrl, clientActions, theme, children, }: {
|
package/dist/index.d.ts
CHANGED
|
@@ -43,6 +43,10 @@ type FactValue = unknown | (() => unknown);
|
|
|
43
43
|
type XbNovaTheme = {
|
|
44
44
|
accentFrom: string;
|
|
45
45
|
accentTo: string;
|
|
46
|
+
/** 위젯의 라이트/다크. `"system"`(기본)은 브라우저·OS 설정을 따른다 — 호스트 사이트가 다크
|
|
47
|
+
* 모드를 지원하지 않는데 사용자 OS만 다크이면 사이트는 밝은데 위젯만 어두워진다. 그런 사이트는
|
|
48
|
+
* `"light"`로 고정하고, 사이트 자체 테마를 가진 호스트는 그 값을 넘기면 된다. */
|
|
49
|
+
colorScheme: "light" | "dark" | "system";
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
declare function XbNovaProvider({ apiKey, botId, appId, screen, apiBaseUrl, clientActions, theme, children, }: {
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,8 @@ import { createContext, useContext, useMemo, useRef } from "react";
|
|
|
11
11
|
import { jsx } from "react/jsx-runtime";
|
|
12
12
|
var DEFAULT_THEME = {
|
|
13
13
|
accentFrom: "#4f46e5",
|
|
14
|
-
accentTo: "#7c3aed"
|
|
14
|
+
accentTo: "#7c3aed",
|
|
15
|
+
colorScheme: "system"
|
|
15
16
|
};
|
|
16
17
|
var InternalContext = createContext(null);
|
|
17
18
|
function useXbNovaInternal() {
|
|
@@ -921,10 +922,25 @@ function loadCss() {
|
|
|
921
922
|
}
|
|
922
923
|
return cssPromise;
|
|
923
924
|
}
|
|
925
|
+
function useResolvedScheme(scheme) {
|
|
926
|
+
const [systemDark, setSystemDark] = useState2(false);
|
|
927
|
+
useEffect6(() => {
|
|
928
|
+
if (scheme !== "system") return;
|
|
929
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
930
|
+
setSystemDark(mq.matches);
|
|
931
|
+
const onChange = (e) => setSystemDark(e.matches);
|
|
932
|
+
mq.addEventListener("change", onChange);
|
|
933
|
+
return () => mq.removeEventListener("change", onChange);
|
|
934
|
+
}, [scheme]);
|
|
935
|
+
if (scheme === "system") return systemDark ? "dark" : "light";
|
|
936
|
+
return scheme;
|
|
937
|
+
}
|
|
924
938
|
function XbNovaShadowRoot({
|
|
925
939
|
children,
|
|
926
940
|
style
|
|
927
941
|
}) {
|
|
942
|
+
const { theme } = useXbNovaInternal();
|
|
943
|
+
const scheme = useResolvedScheme(theme.colorScheme);
|
|
928
944
|
const hostRef = useRef6(null);
|
|
929
945
|
const [mountNode, setMountNode] = useState2(null);
|
|
930
946
|
const [portalTarget, setPortalTarget] = useState2(null);
|
|
@@ -946,6 +962,11 @@ function XbNovaShadowRoot({
|
|
|
946
962
|
shadow.appendChild(mount);
|
|
947
963
|
setMountNode(mount);
|
|
948
964
|
}, [portalTarget]);
|
|
965
|
+
useEffect6(() => {
|
|
966
|
+
if (!mountNode) return;
|
|
967
|
+
mountNode.dataset.xbnovaScheme = scheme;
|
|
968
|
+
mountNode.style.colorScheme = scheme;
|
|
969
|
+
}, [mountNode, scheme]);
|
|
949
970
|
if (!portalTarget) return null;
|
|
950
971
|
return createPortal(
|
|
951
972
|
/* @__PURE__ */ jsx5("div", { ref: hostRef, style, children: mountNode ? createPortal(children, mountNode) : null }),
|