@nivaro/react 0.3.17 → 0.3.19
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/full.css +1 -1
- package/dist/hooks/useSessionRecorder.js +1 -1
- package/dist/index.d.ts +54 -1
- package/dist/index.js +243 -240
- package/dist/shared/components/CollectionBrowserView.js +439 -438
- package/dist/shared/components/ItemEditForm.js +3758 -3708
- package/dist/shared/components/ProfileView.js +38 -23
- package/dist/shared/components/RecordReadView.js +452 -430
- package/dist/shared/components/bulk/BulkActionButtons.js +113 -106
- package/dist/shared/components/chat/ChannelArchive.js +16 -17
- package/dist/shared/components/chat/ChatPanel.js +992 -930
- package/dist/shared/components/chat/Composer.js +307 -303
- package/dist/shared/components/chat/chat-core.js +8 -4
- package/dist/shared/components/chat/chat-drafts.js +60 -43
- package/dist/shared/components/help-videos/api.js +3 -0
- package/dist/shared/components/help-videos/library/HelpVideoLibrary.js +225 -177
- package/dist/shared/components/item-edit/InlineTableField.js +159 -158
- package/dist/shared/components/item-edit/RecordLiveSync.js +169 -155
- package/dist/shared/components/item-edit/RelationCombobox.js +274 -247
- package/dist/shared/components/item-edit/RowHistorySheet.js +62 -62
- package/dist/shared/components/item-edit/picker-search.js +28 -0
- package/dist/shared/components/panels/RevisionsPanel.js +268 -260
- package/dist/shared/components/profile/BrowserPushCard.js +135 -89
- package/dist/shared/components/profile/push-failure.js +76 -0
- package/dist/shared/lib/display-prefs.js +90 -0
- package/dist/shared/lib/theme-accents.js +21 -16
- package/package.json +1 -1
|
@@ -1,181 +1,227 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useQueryClient as
|
|
3
|
-
import { BellRing as
|
|
4
|
-
import { useState as
|
|
5
|
-
import { useNivaroClient as
|
|
6
|
-
import { get as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { jsxs as i, jsx as o, Fragment as _ } from "react/jsx-runtime";
|
|
2
|
+
import { useQueryClient as $, useQuery as E } from "@tanstack/react-query";
|
|
3
|
+
import { BellRing as P, Loader2 as U } from "lucide-react";
|
|
4
|
+
import { useState as y, useEffect as W } from "react";
|
|
5
|
+
import { useNivaroClient as H } from "../../context.js";
|
|
6
|
+
import { get as M, post as S } from "../../lib/commands.js";
|
|
7
|
+
import { pushFailure as j } from "./push-failure.js";
|
|
8
|
+
function I(d) {
|
|
9
|
+
const c = "=".repeat((4 - d.length % 4) % 4), h = atob((d + c).replace(/-/g, "+").replace(/_/g, "/")), n = new Uint8Array(new ArrayBuffer(h.length));
|
|
10
|
+
for (let s = 0; s < h.length; s++) n[s] = h.charCodeAt(s);
|
|
10
11
|
return n;
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
+
function J() {
|
|
13
14
|
return typeof window < "u" && "serviceWorker" in navigator && "PushManager" in window && "Notification" in window;
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
const
|
|
16
|
+
function Z({ serviceWorkerPath: d = "/sw.js" }) {
|
|
17
|
+
const c = H(), h = $(), n = J(), [s, f] = y(!1), [b, a] = y(null), [u, x] = y(null), [A, K] = y(
|
|
17
18
|
n ? Notification.permission : null
|
|
18
|
-
), { data:
|
|
19
|
+
), { data: w } = E({
|
|
19
20
|
queryKey: ["nvr-push-status"],
|
|
20
|
-
queryFn: () =>
|
|
21
|
+
queryFn: () => c.request(M("/push/status")).then((e) => e.data),
|
|
21
22
|
enabled: n
|
|
22
|
-
}),
|
|
23
|
-
|
|
23
|
+
}), g = (w == null ? void 0 : w.subscriptions) ?? 0;
|
|
24
|
+
W(() => {
|
|
24
25
|
if (!n) return;
|
|
25
26
|
let e = !0;
|
|
26
|
-
return navigator.serviceWorker.getRegistration(d).then((
|
|
27
|
-
e &&
|
|
27
|
+
return navigator.serviceWorker.getRegistration(d).then((r) => (r == null ? void 0 : r.pushManager.getSubscription()) ?? null).then((r) => {
|
|
28
|
+
e && x(!!r);
|
|
28
29
|
}).catch(() => {
|
|
29
|
-
e &&
|
|
30
|
+
e && x(!1);
|
|
30
31
|
}), () => {
|
|
31
32
|
e = !1;
|
|
32
33
|
};
|
|
33
34
|
}, [n, d]);
|
|
34
|
-
const
|
|
35
|
-
async function
|
|
36
|
-
|
|
35
|
+
const C = () => void h.invalidateQueries({ queryKey: ["nvr-push-status"] });
|
|
36
|
+
async function O() {
|
|
37
|
+
var r, p;
|
|
38
|
+
f(!0), a(null);
|
|
39
|
+
const e = (l, m, q) => {
|
|
40
|
+
a({ tone: "error", ...j(l, m, { permission: q }) });
|
|
41
|
+
};
|
|
37
42
|
try {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return;
|
|
43
|
+
if (typeof window < "u" && window.isSecureContext === !1) return e("insecure");
|
|
44
|
+
let l;
|
|
45
|
+
try {
|
|
46
|
+
l = await Notification.requestPermission();
|
|
47
|
+
} catch (t) {
|
|
48
|
+
return e("permission", t, Notification.permission);
|
|
45
49
|
}
|
|
46
|
-
|
|
50
|
+
if (K(l), l !== "granted") return e("permission", null, l);
|
|
51
|
+
let m;
|
|
47
52
|
try {
|
|
48
|
-
|
|
49
|
-
} catch {
|
|
50
|
-
|
|
51
|
-
tone: "error",
|
|
52
|
-
text: "This app is not set up for browser notifications yet (no service worker)."
|
|
53
|
-
});
|
|
54
|
-
return;
|
|
53
|
+
m = await navigator.serviceWorker.register(d);
|
|
54
|
+
} catch (t) {
|
|
55
|
+
return e("register", t);
|
|
55
56
|
}
|
|
56
|
-
await
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
),
|
|
57
|
+
if (!await Promise.race([
|
|
58
|
+
navigator.serviceWorker.ready.then(() => !0),
|
|
59
|
+
new Promise((t) => setTimeout(() => t(!1), 1e4))
|
|
60
|
+
])) return e("ready", `${d} did not activate within 10 s`);
|
|
61
|
+
let v;
|
|
62
|
+
try {
|
|
63
|
+
if (v = (r = (await c.request(
|
|
64
|
+
M("/push/vapid-public-key")
|
|
65
|
+
)).data) == null ? void 0 : r.public_key, !v) return e("key", "empty public_key");
|
|
66
|
+
} catch (t) {
|
|
67
|
+
return e("key", t);
|
|
68
|
+
}
|
|
69
|
+
const T = () => m.pushManager.subscribe({
|
|
60
70
|
userVisibleOnly: !0,
|
|
61
|
-
applicationServerKey:
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
applicationServerKey: I(v)
|
|
72
|
+
});
|
|
73
|
+
let N;
|
|
74
|
+
try {
|
|
75
|
+
N = await m.pushManager.getSubscription() ?? await T();
|
|
76
|
+
} catch (t) {
|
|
77
|
+
if ((t == null ? void 0 : t.name) !== "InvalidStateError") return e("subscribe", t);
|
|
78
|
+
try {
|
|
79
|
+
await ((p = await m.pushManager.getSubscription()) == null ? void 0 : p.unsubscribe()), N = await T();
|
|
80
|
+
} catch (R) {
|
|
81
|
+
return e("subscribe", R);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const B = N.toJSON();
|
|
85
|
+
try {
|
|
86
|
+
await c.request(S("/push/subscribe", { endpoint: B.endpoint, keys: B.keys }));
|
|
87
|
+
} catch (t) {
|
|
88
|
+
return e("save", t);
|
|
89
|
+
}
|
|
90
|
+
x(!0), a({ tone: "ok", text: "Turned on in this browser." }), C();
|
|
91
|
+
} catch (l) {
|
|
92
|
+
e("subscribe", l);
|
|
66
93
|
} finally {
|
|
67
|
-
|
|
94
|
+
f(!1);
|
|
68
95
|
}
|
|
69
96
|
}
|
|
70
|
-
async function
|
|
71
|
-
|
|
97
|
+
async function F() {
|
|
98
|
+
f(!0), a(null);
|
|
72
99
|
try {
|
|
73
|
-
const e = await navigator.serviceWorker.getRegistration(d),
|
|
74
|
-
|
|
100
|
+
const e = await navigator.serviceWorker.getRegistration(d), r = await (e == null ? void 0 : e.pushManager.getSubscription());
|
|
101
|
+
r && (await c.request(S("/push/unsubscribe", { endpoint: r.endpoint })), await r.unsubscribe()), x(!1), a({ tone: "ok", text: "Turned off in this browser." }), C();
|
|
75
102
|
} catch {
|
|
76
|
-
|
|
103
|
+
a({ tone: "error", text: "Could not turn off browser notifications." });
|
|
77
104
|
} finally {
|
|
78
|
-
|
|
105
|
+
f(!1);
|
|
79
106
|
}
|
|
80
107
|
}
|
|
81
|
-
async function
|
|
108
|
+
async function Q() {
|
|
82
109
|
var e;
|
|
83
|
-
|
|
110
|
+
f(!0), a(null);
|
|
84
111
|
try {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
tone:
|
|
88
|
-
text:
|
|
112
|
+
const p = ((e = (await c.request(S("/push/test"))).data) == null ? void 0 : e.sent) ?? 0;
|
|
113
|
+
a({
|
|
114
|
+
tone: p > 0 ? "ok" : "error",
|
|
115
|
+
text: p > 0 ? `Test sent to ${p} browser${p === 1 ? "" : "s"}.` : "No browser received it. Turn notifications on first."
|
|
89
116
|
});
|
|
90
117
|
} catch {
|
|
91
|
-
|
|
118
|
+
a({ tone: "error", text: "Could not send a test notification." });
|
|
92
119
|
} finally {
|
|
93
|
-
|
|
120
|
+
f(!1);
|
|
94
121
|
}
|
|
95
122
|
}
|
|
96
|
-
const
|
|
97
|
-
return /* @__PURE__ */
|
|
123
|
+
const k = u ? g - 1 : g;
|
|
124
|
+
return /* @__PURE__ */ i(
|
|
98
125
|
"div",
|
|
99
126
|
{
|
|
100
127
|
"data-profile-card": "browser-push",
|
|
101
128
|
className: "rounded-xl border border-slate-200 bg-white p-5 dark:border-border dark:bg-card",
|
|
102
129
|
children: [
|
|
103
|
-
/* @__PURE__ */
|
|
104
|
-
/* @__PURE__ */
|
|
105
|
-
/* @__PURE__ */
|
|
106
|
-
/* @__PURE__ */ o(
|
|
130
|
+
/* @__PURE__ */ i("div", { className: "flex items-start justify-between gap-3", children: [
|
|
131
|
+
/* @__PURE__ */ i("div", { children: [
|
|
132
|
+
/* @__PURE__ */ i("p", { className: "flex items-center gap-1.5 text-[13.5px] font-semibold text-slate-800 dark:text-slate-100", children: [
|
|
133
|
+
/* @__PURE__ */ o(P, { className: "h-4 w-4 text-slate-400" }),
|
|
107
134
|
"Browser notifications"
|
|
108
135
|
] }),
|
|
109
136
|
/* @__PURE__ */ o("p", { className: "mt-0.5 text-[12px] text-slate-500 dark:text-muted-foreground", children: "Native notifications from this browser, even when the tab is closed. Which categories push is set in Notification rules." })
|
|
110
137
|
] }),
|
|
111
|
-
n &&
|
|
138
|
+
n && u !== null && /* @__PURE__ */ o(
|
|
112
139
|
"span",
|
|
113
140
|
{
|
|
114
|
-
"data-push-state":
|
|
115
|
-
className:
|
|
116
|
-
children:
|
|
141
|
+
"data-push-state": u ? "on" : "off",
|
|
142
|
+
className: u ? "shrink-0 rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700 dark:bg-emerald-400/10 dark:text-emerald-300" : "shrink-0 rounded-full bg-slate-100 px-2 py-0.5 text-[11px] font-medium text-slate-600 dark:bg-white/5 dark:text-slate-300",
|
|
143
|
+
children: u ? "On in this browser" : "Off in this browser"
|
|
117
144
|
}
|
|
118
145
|
)
|
|
119
146
|
] }),
|
|
120
|
-
n ? /* @__PURE__ */
|
|
121
|
-
|
|
147
|
+
n ? /* @__PURE__ */ i(_, { children: [
|
|
148
|
+
k > 0 && /* @__PURE__ */ i("p", { className: "mt-2 text-[12px] text-slate-500 dark:text-muted-foreground", children: [
|
|
122
149
|
"Also on in ",
|
|
123
|
-
|
|
150
|
+
k,
|
|
124
151
|
" other browser",
|
|
125
|
-
|
|
152
|
+
k === 1 ? "" : "s",
|
|
126
153
|
"."
|
|
127
154
|
] }),
|
|
128
|
-
|
|
129
|
-
/* @__PURE__ */
|
|
130
|
-
|
|
155
|
+
A === "denied" && !u && /* @__PURE__ */ o("p", { className: "mt-2 text-[12px] text-amber-700 dark:text-amber-300", children: "Notifications are blocked for this site in your browser settings." }),
|
|
156
|
+
/* @__PURE__ */ i("div", { className: "mt-3 flex flex-wrap items-center gap-2", children: [
|
|
157
|
+
u ? /* @__PURE__ */ o(
|
|
131
158
|
"button",
|
|
132
159
|
{
|
|
133
160
|
type: "button",
|
|
134
161
|
"data-push-disable": !0,
|
|
135
162
|
disabled: s,
|
|
136
|
-
onClick: () => void
|
|
163
|
+
onClick: () => void F(),
|
|
137
164
|
className: "inline-flex h-8 items-center gap-1.5 rounded-md border border-slate-200 px-3 text-[12px] font-medium text-slate-700 hover:bg-slate-50 disabled:opacity-50 dark:border-border dark:text-slate-200 dark:hover:bg-white/5",
|
|
138
165
|
children: "Turn off"
|
|
139
166
|
}
|
|
140
|
-
) : /* @__PURE__ */
|
|
167
|
+
) : /* @__PURE__ */ i(
|
|
141
168
|
"button",
|
|
142
169
|
{
|
|
143
170
|
type: "button",
|
|
144
171
|
"data-push-enable": !0,
|
|
145
|
-
disabled: s ||
|
|
146
|
-
onClick: () => void
|
|
172
|
+
disabled: s || u === null,
|
|
173
|
+
onClick: () => void O(),
|
|
147
174
|
className: "inline-flex h-8 items-center gap-1.5 rounded-md border border-nvr-cyan/50 bg-nvr-cyan/5 px-3 text-[12px] font-medium text-nvr-navy hover:bg-nvr-cyan/10 disabled:opacity-50 dark:text-nvr-cyan",
|
|
148
175
|
children: [
|
|
149
|
-
s && /* @__PURE__ */ o(
|
|
176
|
+
s && /* @__PURE__ */ o(U, { className: "h-3.5 w-3.5 animate-spin" }),
|
|
150
177
|
"Turn on"
|
|
151
178
|
]
|
|
152
179
|
}
|
|
153
180
|
),
|
|
154
|
-
|
|
181
|
+
g > 0 && /* @__PURE__ */ o(
|
|
155
182
|
"button",
|
|
156
183
|
{
|
|
157
184
|
type: "button",
|
|
158
185
|
"data-push-test": !0,
|
|
159
186
|
disabled: s,
|
|
160
|
-
onClick: () => void
|
|
187
|
+
onClick: () => void Q(),
|
|
161
188
|
className: "inline-flex h-8 items-center rounded-md border border-slate-200 px-3 text-[12px] font-medium text-slate-700 hover:bg-slate-50 disabled:opacity-50 dark:border-border dark:text-slate-200 dark:hover:bg-white/5",
|
|
162
189
|
children: "Send a test"
|
|
163
190
|
}
|
|
164
191
|
)
|
|
165
192
|
] }),
|
|
166
|
-
b && /* @__PURE__ */
|
|
193
|
+
b && /* @__PURE__ */ i(
|
|
167
194
|
"p",
|
|
168
195
|
{
|
|
169
196
|
"data-push-note": b.tone,
|
|
170
197
|
className: b.tone === "ok" ? "mt-2 text-[12px] text-emerald-700 dark:text-emerald-300" : "mt-2 text-[12px] text-red-600 dark:text-red-400",
|
|
171
|
-
children:
|
|
198
|
+
children: [
|
|
199
|
+
b.text,
|
|
200
|
+
b.detail && /* @__PURE__ */ o(
|
|
201
|
+
"span",
|
|
202
|
+
{
|
|
203
|
+
"data-push-detail": !0,
|
|
204
|
+
className: "mt-0.5 block font-mono text-[10.5px] text-slate-500 dark:text-slate-400",
|
|
205
|
+
children: b.detail
|
|
206
|
+
}
|
|
207
|
+
)
|
|
208
|
+
]
|
|
172
209
|
}
|
|
173
210
|
)
|
|
174
|
-
] }) : /* @__PURE__ */ o(
|
|
211
|
+
] }) : /* @__PURE__ */ o(
|
|
212
|
+
"p",
|
|
213
|
+
{
|
|
214
|
+
"data-push-unsupported": !0,
|
|
215
|
+
className: "mt-3 text-[12px] text-slate-500 dark:text-muted-foreground",
|
|
216
|
+
children: j(
|
|
217
|
+
typeof window < "u" && window.isSecureContext === !1 ? "insecure" : "unsupported"
|
|
218
|
+
).text
|
|
219
|
+
}
|
|
220
|
+
)
|
|
175
221
|
]
|
|
176
222
|
}
|
|
177
223
|
);
|
|
178
224
|
}
|
|
179
225
|
export {
|
|
180
|
-
|
|
226
|
+
Z as BrowserPushCard
|
|
181
227
|
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
function r(t) {
|
|
2
|
+
return t && typeof t == "object" && "name" in t ? String(t.name) : "";
|
|
3
|
+
}
|
|
4
|
+
function s(t) {
|
|
5
|
+
var e;
|
|
6
|
+
if (!t || typeof t != "object") return null;
|
|
7
|
+
const n = t, i = Number(n.status ?? ((e = n.response) == null ? void 0 : e.status));
|
|
8
|
+
return Number.isFinite(i) && i > 0 ? i : null;
|
|
9
|
+
}
|
|
10
|
+
function a(t) {
|
|
11
|
+
if (t == null) return "";
|
|
12
|
+
if (typeof t == "string") return t;
|
|
13
|
+
const n = r(t), i = t instanceof Error || typeof t == "object" ? String(t.message ?? "") : "", e = s(t);
|
|
14
|
+
return [e ? `HTTP ${e}` : "", n && n !== "Error" ? n : "", i].filter(Boolean).join(": ").slice(0, 300);
|
|
15
|
+
}
|
|
16
|
+
function u(t, n, i = {}) {
|
|
17
|
+
const e = a(n), o = r(n);
|
|
18
|
+
switch (t) {
|
|
19
|
+
case "insecure":
|
|
20
|
+
return {
|
|
21
|
+
text: "Browser notifications only work over a secure (https) connection. Open the app at its https address and try again.",
|
|
22
|
+
detail: e
|
|
23
|
+
};
|
|
24
|
+
case "unsupported":
|
|
25
|
+
return {
|
|
26
|
+
text: "This browser window cannot receive push notifications. Private and incognito windows usually cannot — open the app in a normal window of Chrome, Edge, Firefox or Safari.",
|
|
27
|
+
detail: e
|
|
28
|
+
};
|
|
29
|
+
case "permission":
|
|
30
|
+
return i.permission === "denied" ? {
|
|
31
|
+
text: "Notifications are blocked for this site. Allow them in your browser’s site settings (the icon left of the address), then try again. Incognito windows block them always — use a normal window.",
|
|
32
|
+
detail: e
|
|
33
|
+
} : {
|
|
34
|
+
text: "The permission prompt was closed without allowing notifications. Press Turn on again and choose Allow.",
|
|
35
|
+
detail: e
|
|
36
|
+
};
|
|
37
|
+
case "register":
|
|
38
|
+
return {
|
|
39
|
+
text: "The app could not install its notification helper (service worker). Reload the page and try again; if it keeps failing, tell your administrator.",
|
|
40
|
+
detail: e
|
|
41
|
+
};
|
|
42
|
+
case "ready":
|
|
43
|
+
return {
|
|
44
|
+
text: "The notification helper (service worker) did not start. Reload the page and try again.",
|
|
45
|
+
detail: e
|
|
46
|
+
};
|
|
47
|
+
case "key":
|
|
48
|
+
return {
|
|
49
|
+
text: s(n) === 401 || s(n) === 403 ? "Your sign-in could not fetch the push key. Sign in again, then try again." : "The server is not set up to send browser notifications (it gave no push key). Tell your administrator.",
|
|
50
|
+
detail: e
|
|
51
|
+
};
|
|
52
|
+
case "subscribe":
|
|
53
|
+
return o === "NotAllowedError" || /permission denied/i.test(e) ? {
|
|
54
|
+
text: "The browser refused the push subscription. This happens in Incognito / private windows and when notifications are blocked for this site — open the app in a normal window, allow notifications for this site, and try again.",
|
|
55
|
+
detail: e
|
|
56
|
+
} : o === "AbortError" ? {
|
|
57
|
+
text: "The browser’s push service is not available. Private windows do not have one; in Brave turn on “Use Google services for push messaging” (Settings → Privacy and security), then try again.",
|
|
58
|
+
detail: e
|
|
59
|
+
} : o === "NotSupportedError" ? {
|
|
60
|
+
text: "This browser does not support push notifications for this site.",
|
|
61
|
+
detail: e
|
|
62
|
+
} : {
|
|
63
|
+
text: "The browser could not create a push subscription. Try again; if it keeps failing, tell your administrator what it said below.",
|
|
64
|
+
detail: e
|
|
65
|
+
};
|
|
66
|
+
case "save":
|
|
67
|
+
return {
|
|
68
|
+
text: "This browser subscribed, but the server could not save it. Try again in a moment.",
|
|
69
|
+
detail: e
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
a as describeError,
|
|
75
|
+
u as pushFailure
|
|
76
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { useQuery as b } from "@tanstack/react-query";
|
|
2
|
+
import { useEffect as f } from "react";
|
|
3
|
+
import { useOptionalNivaroClient as h } from "../context.js";
|
|
4
|
+
import { get as z } from "./commands.js";
|
|
5
|
+
import { resolveAccentColor as g, parseThemeAccents as _ } from "./theme-accents.js";
|
|
6
|
+
import { setDisplayTimezone as k, setTimeDisplay as S, setNumberFormat as N } from "./utils.js";
|
|
7
|
+
function v(n) {
|
|
8
|
+
return n === "small" ? "15px" : n === "large" ? "17.5px" : "";
|
|
9
|
+
}
|
|
10
|
+
function m(n, r = null, l = typeof document > "u" ? null : document.documentElement) {
|
|
11
|
+
const e = n ?? {};
|
|
12
|
+
k(typeof e.timezone == "string" && e.timezone ? e.timezone : r), S(e.time_display ?? null), N(e.number_format ?? null), l && (l.style.fontSize = v(e.font_size));
|
|
13
|
+
}
|
|
14
|
+
function c(n) {
|
|
15
|
+
const r = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n.trim());
|
|
16
|
+
if (!r) return null;
|
|
17
|
+
const l = r[1].length === 3 ? r[1].split("").map((t) => t + t).join("") : r[1], e = Number.parseInt(l, 16);
|
|
18
|
+
return `${e >> 16 & 255} ${e >> 8 & 255} ${e & 255}`;
|
|
19
|
+
}
|
|
20
|
+
function y(n) {
|
|
21
|
+
const r = c(n);
|
|
22
|
+
if (!r) return 0;
|
|
23
|
+
const [l, e, t] = r.split(" ").map((i) => {
|
|
24
|
+
const u = Number(i) / 255;
|
|
25
|
+
return u <= 0.03928 ? u / 12.92 : ((u + 0.055) / 1.055) ** 2.4;
|
|
26
|
+
});
|
|
27
|
+
return 0.2126 * l + 0.7152 * e + 0.0722 * t;
|
|
28
|
+
}
|
|
29
|
+
function a(n, r) {
|
|
30
|
+
const [l, e] = [y(n), y(r)].sort((t, i) => i - t);
|
|
31
|
+
return (l + 0.05) / (e + 0.05);
|
|
32
|
+
}
|
|
33
|
+
function P(n, r, l) {
|
|
34
|
+
const e = (c(n) ?? "0 0 0").split(" ").map(Number), t = (c(r) ?? "0 0 0").split(" ").map(Number);
|
|
35
|
+
return `#${e.map((i, u) => Math.round(i + (t[u] - i) * l)).map((i) => i.toString(16).padStart(2, "0")).join("")}`;
|
|
36
|
+
}
|
|
37
|
+
function x(n, r, l = 4.5) {
|
|
38
|
+
let e = n;
|
|
39
|
+
for (let t = 1; t <= 20 && a(e, r) < l; t++)
|
|
40
|
+
e = P(n, "#ffffff", t * 0.05);
|
|
41
|
+
return e;
|
|
42
|
+
}
|
|
43
|
+
function D(n, r = "#080f1c") {
|
|
44
|
+
return a(n, "#ffffff") >= a(n, r) ? "light" : "dark";
|
|
45
|
+
}
|
|
46
|
+
function p(n, r, l = typeof document > "u" ? null : document.documentElement) {
|
|
47
|
+
if (!l) return;
|
|
48
|
+
const e = n ? c(n) : null;
|
|
49
|
+
for (const t of r.hex ?? [])
|
|
50
|
+
n && e ? l.style.setProperty(t, n) : l.style.removeProperty(t);
|
|
51
|
+
for (const t of r.rgb ?? [])
|
|
52
|
+
e ? l.style.setProperty(t, e) : l.style.removeProperty(t);
|
|
53
|
+
n && e ? l.dataset.accentInk = D(n) : delete l.dataset.accentInk;
|
|
54
|
+
}
|
|
55
|
+
function C(n, r = {}) {
|
|
56
|
+
const l = h(), { data: e } = b({
|
|
57
|
+
queryKey: ["nvr-display-settings"],
|
|
58
|
+
queryFn: () => l.request(
|
|
59
|
+
z("/settings")
|
|
60
|
+
).then((o) => o.data ?? {}),
|
|
61
|
+
enabled: !!l && !!n,
|
|
62
|
+
staleTime: 5 * 6e4,
|
|
63
|
+
retry: !1
|
|
64
|
+
}), t = n ?? null, i = JSON.stringify([
|
|
65
|
+
(t == null ? void 0 : t.timezone) ?? null,
|
|
66
|
+
(t == null ? void 0 : t.time_display) ?? null,
|
|
67
|
+
(t == null ? void 0 : t.number_format) ?? null,
|
|
68
|
+
(t == null ? void 0 : t.font_size) ?? null,
|
|
69
|
+
(e == null ? void 0 : e.default_timezone) ?? null
|
|
70
|
+
]);
|
|
71
|
+
f(() => {
|
|
72
|
+
t && m(t, (e == null ? void 0 : e.default_timezone) ?? null);
|
|
73
|
+
}, [i]), f(() => () => m(null), []);
|
|
74
|
+
const u = t ? g(t.theme_accent, _(e == null ? void 0 : e.theme_accents)) : null, s = u && r.dark && r.darkSurface ? x(u, r.darkSurface) : u, d = JSON.stringify(r.accent ?? {});
|
|
75
|
+
f(() => {
|
|
76
|
+
if (!r.accent) return;
|
|
77
|
+
const o = r.accent;
|
|
78
|
+
return p(s, o), () => p(null, o);
|
|
79
|
+
}, [s, d]);
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
D as accentInk,
|
|
83
|
+
p as applyAccentVars,
|
|
84
|
+
m as applyDisplayPrefs,
|
|
85
|
+
a as contrastRatio,
|
|
86
|
+
c as hexToRgbChannels,
|
|
87
|
+
x as liftForDarkSurface,
|
|
88
|
+
v as rootFontSize,
|
|
89
|
+
C as useDisplayPreferences
|
|
90
|
+
};
|
|
@@ -3,31 +3,36 @@ const f = { key: "brand", label: "Brand", color: null }, l = [
|
|
|
3
3
|
{ key: "emerald", label: "Emerald", color: "#059669" },
|
|
4
4
|
{ key: "rose", label: "Rose", color: "#e11d48" }
|
|
5
5
|
], s = /^[a-z0-9][a-z0-9_-]{0,39}$/, a = /^#[0-9a-fA-F]{6}$/;
|
|
6
|
-
function u(
|
|
7
|
-
if (
|
|
8
|
-
let
|
|
9
|
-
if (typeof
|
|
6
|
+
function u(e) {
|
|
7
|
+
if (e == null || e === "") return l;
|
|
8
|
+
let t = e;
|
|
9
|
+
if (typeof e == "string")
|
|
10
10
|
try {
|
|
11
|
-
|
|
11
|
+
t = JSON.parse(e);
|
|
12
12
|
} catch {
|
|
13
13
|
return l;
|
|
14
14
|
}
|
|
15
|
-
if (!Array.isArray(
|
|
16
|
-
const
|
|
17
|
-
for (const
|
|
18
|
-
if (!
|
|
19
|
-
const
|
|
20
|
-
if (!(!s.test(
|
|
21
|
-
key:
|
|
22
|
-
label: String(
|
|
15
|
+
if (!Array.isArray(t)) return l;
|
|
16
|
+
const o = [];
|
|
17
|
+
for (const n of t) {
|
|
18
|
+
if (!n || typeof n != "object") continue;
|
|
19
|
+
const r = String(n.key ?? "").trim(), c = String(n.color ?? "").trim();
|
|
20
|
+
if (!(!s.test(r) || r === "brand" || !a.test(c)) && !o.some((i) => i.key === r) && (o.push({
|
|
21
|
+
key: r,
|
|
22
|
+
label: String(n.label ?? r).slice(0, 40) || r,
|
|
23
23
|
color: c.toLowerCase()
|
|
24
|
-
}),
|
|
24
|
+
}), o.length >= 6))
|
|
25
25
|
break;
|
|
26
26
|
}
|
|
27
|
-
return
|
|
27
|
+
return o;
|
|
28
|
+
}
|
|
29
|
+
function y(e, t = l) {
|
|
30
|
+
var o;
|
|
31
|
+
return typeof e != "string" || !e || e === "brand" ? null : ((o = t.find((n) => n.key === e)) == null ? void 0 : o.color) ?? null;
|
|
28
32
|
}
|
|
29
33
|
export {
|
|
30
34
|
f as BRAND_ACCENT,
|
|
31
35
|
l as DEFAULT_THEME_ACCENTS,
|
|
32
|
-
u as parseThemeAccents
|
|
36
|
+
u as parseThemeAccents,
|
|
37
|
+
y as resolveAccentColor
|
|
33
38
|
};
|