@alexpeng/dsh-custom-plugin 0.9.0 → 0.9.2
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/CHANGELOG.md +53 -0
- package/README.i18n.yaml +2 -2
- package/README.md +3 -1
- package/README.zh.md +2 -1
- package/lib/client.js +454 -262
- package/lib/client.js.map +1 -1
- package/lib/types/client/mermaid-render.d.ts +36 -0
- package/lib/types/client/mermaid-scan.d.ts +21 -0
- package/package.json +2 -1
package/lib/client.js
CHANGED
|
@@ -673,6 +673,130 @@ window.__ModuleLoader__.load({
|
|
|
673
673
|
};
|
|
674
674
|
}
|
|
675
675
|
//#endregion
|
|
676
|
+
//#region src/client/mermaid-url.ts
|
|
677
|
+
function bytesToBase64Url(bytes) {
|
|
678
|
+
let bin = "";
|
|
679
|
+
for (const byte of bytes) bin += String.fromCharCode(byte);
|
|
680
|
+
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
681
|
+
}
|
|
682
|
+
async function deflateZlibBase64Url(text) {
|
|
683
|
+
const Ctor = globalThis.CompressionStream;
|
|
684
|
+
if (typeof Ctor !== "function") return null;
|
|
685
|
+
try {
|
|
686
|
+
const stream = new Ctor("deflate");
|
|
687
|
+
const writer = stream.writable.getWriter();
|
|
688
|
+
writer.write(new TextEncoder().encode(text));
|
|
689
|
+
writer.close();
|
|
690
|
+
return bytesToBase64Url(new Uint8Array(await new Response(stream.readable).arrayBuffer()));
|
|
691
|
+
} catch {
|
|
692
|
+
return null;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
/** Build the `https://mermaid.live/edit#pako:…` share link for one diagram. */
|
|
696
|
+
async function mermaidLiveUrl(code) {
|
|
697
|
+
const state = JSON.stringify({
|
|
698
|
+
code,
|
|
699
|
+
mermaid: { theme: "default" }
|
|
700
|
+
});
|
|
701
|
+
return "https://mermaid.live/edit#pako:" + (await deflateZlibBase64Url(state) ?? bytesToBase64Url(new TextEncoder().encode(state)));
|
|
702
|
+
}
|
|
703
|
+
//#endregion
|
|
704
|
+
//#region src/client/timeline-diff.ts
|
|
705
|
+
/** Whether two timeline entries would render identically. */
|
|
706
|
+
function sameTimelineItem(a, b) {
|
|
707
|
+
return a.seq === b.seq && a.time === b.time && a.turn === b.turn && a.text === b.text && a.imageCount === b.imageCount && a.hasLatex === b.hasLatex && a.hasMathml === b.hasMathml && a.hasMermaid === b.hasMermaid;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Diff one fetched timeline against the previous snapshot by sequence.
|
|
711
|
+
* @param previous - previous ordered items, or null when this is the first fetch.
|
|
712
|
+
* @param previousBySeq - seq index for `previous` (same generation), or null.
|
|
713
|
+
* @param next - freshly fetched items.
|
|
714
|
+
* @returns reused items plus whether any rendered field changed.
|
|
715
|
+
*/
|
|
716
|
+
function reuseTimelineItems(previous, previousBySeq, next) {
|
|
717
|
+
const bySeq = /* @__PURE__ */ new Map();
|
|
718
|
+
const items = [];
|
|
719
|
+
let changed = previous === null || previous.length !== next.length;
|
|
720
|
+
for (let index = 0; index < next.length; index++) {
|
|
721
|
+
const raw = next[index];
|
|
722
|
+
const old = previousBySeq?.get(raw.seq);
|
|
723
|
+
const item = old !== void 0 && sameTimelineItem(old, raw) ? old : raw;
|
|
724
|
+
items.push(item);
|
|
725
|
+
bySeq.set(item.seq, item);
|
|
726
|
+
if (!changed && previous !== null && previous[index] !== item) changed = true;
|
|
727
|
+
}
|
|
728
|
+
return {
|
|
729
|
+
items,
|
|
730
|
+
bySeq,
|
|
731
|
+
changed
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
/** Compact DOM identity for a rendered Mermaid block. A 32-bit FNV-1a hash
|
|
735
|
+
* plus the source length is enough to distinguish live blocks without
|
|
736
|
+
* duplicating every diagram's text into a `data-*` attribute. */
|
|
737
|
+
function mermaidCodeKey(code) {
|
|
738
|
+
let hash = 2166136261;
|
|
739
|
+
for (let i = 0; i < code.length; i++) {
|
|
740
|
+
hash ^= code.charCodeAt(i);
|
|
741
|
+
hash = Math.imul(hash, 16777619);
|
|
742
|
+
}
|
|
743
|
+
return (hash >>> 0).toString(36) + "-" + code.length.toString(36);
|
|
744
|
+
}
|
|
745
|
+
//#endregion
|
|
746
|
+
//#region src/client/mermaid-render.ts
|
|
747
|
+
/** A fresh id per render; Mermaid appends `d` + id / `i` + id scratch nodes. */
|
|
748
|
+
function mermaidScratchId() {
|
|
749
|
+
return "vx-mmd-" + Date.now() + Math.floor(Math.random() * 9999);
|
|
750
|
+
}
|
|
751
|
+
/** Remove the three nodes Mermaid may leave for one render id. */
|
|
752
|
+
function removeMermaidScratch(doc, id) {
|
|
753
|
+
if (doc === null) return;
|
|
754
|
+
for (const scratch of [
|
|
755
|
+
id,
|
|
756
|
+
"d" + id,
|
|
757
|
+
"i" + id
|
|
758
|
+
]) doc.getElementById(scratch)?.remove();
|
|
759
|
+
}
|
|
760
|
+
/** Remove error diagrams left in <body> by builds without error suppression. */
|
|
761
|
+
function removeLegacyMermaidErrors(doc) {
|
|
762
|
+
if (doc === null) return;
|
|
763
|
+
for (const leftover of Array.from(doc.querySelectorAll("body > div[id^=\"dvx-mmd-\"]"))) leftover.remove();
|
|
764
|
+
}
|
|
765
|
+
async function renderMermaid(code, dark = false, options = {}) {
|
|
766
|
+
const doc = options.doc !== void 0 ? options.doc : typeof document !== "undefined" ? document : null;
|
|
767
|
+
const mermaid = (options.win !== void 0 ? options.win : typeof window !== "undefined" ? window : null)?.mermaid;
|
|
768
|
+
if (mermaid === void 0) return {
|
|
769
|
+
ok: false,
|
|
770
|
+
error: "引擎未就绪"
|
|
771
|
+
};
|
|
772
|
+
const id = mermaidScratchId();
|
|
773
|
+
try {
|
|
774
|
+
mermaid.initialize({
|
|
775
|
+
startOnLoad: false,
|
|
776
|
+
theme: dark ? "dark" : "default",
|
|
777
|
+
securityLevel: "strict",
|
|
778
|
+
suppressErrorRendering: true
|
|
779
|
+
});
|
|
780
|
+
const out = await mermaid.render(id, code);
|
|
781
|
+
const svg = typeof out === "string" ? out : out?.svg ?? "";
|
|
782
|
+
if (svg === "") return {
|
|
783
|
+
ok: false,
|
|
784
|
+
error: "引擎未返回 SVG"
|
|
785
|
+
};
|
|
786
|
+
return {
|
|
787
|
+
ok: true,
|
|
788
|
+
svg
|
|
789
|
+
};
|
|
790
|
+
} catch (error) {
|
|
791
|
+
return {
|
|
792
|
+
ok: false,
|
|
793
|
+
error: String(error?.message ?? error)
|
|
794
|
+
};
|
|
795
|
+
} finally {
|
|
796
|
+
removeMermaidScratch(doc, id);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
//#endregion
|
|
676
800
|
//#region src/client/mermaid-code.ts
|
|
677
801
|
/**
|
|
678
802
|
* Pure Mermaid code-block detection helpers for the in-place renderer.
|
|
@@ -787,75 +911,157 @@ window.__ModuleLoader__.load({
|
|
|
787
911
|
return true;
|
|
788
912
|
}
|
|
789
913
|
//#endregion
|
|
790
|
-
//#region src/client/mermaid-
|
|
791
|
-
function bytesToBase64Url(bytes) {
|
|
792
|
-
let bin = "";
|
|
793
|
-
for (const byte of bytes) bin += String.fromCharCode(byte);
|
|
794
|
-
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
795
|
-
}
|
|
796
|
-
async function deflateZlibBase64Url(text) {
|
|
797
|
-
const Ctor = globalThis.CompressionStream;
|
|
798
|
-
if (typeof Ctor !== "function") return null;
|
|
799
|
-
try {
|
|
800
|
-
const stream = new Ctor("deflate");
|
|
801
|
-
const writer = stream.writable.getWriter();
|
|
802
|
-
writer.write(new TextEncoder().encode(text));
|
|
803
|
-
writer.close();
|
|
804
|
-
return bytesToBase64Url(new Uint8Array(await new Response(stream.readable).arrayBuffer()));
|
|
805
|
-
} catch {
|
|
806
|
-
return null;
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
/** Build the `https://mermaid.live/edit#pako:…` share link for one diagram. */
|
|
810
|
-
async function mermaidLiveUrl(code) {
|
|
811
|
-
const state = JSON.stringify({
|
|
812
|
-
code,
|
|
813
|
-
mermaid: { theme: "default" }
|
|
814
|
-
});
|
|
815
|
-
return "https://mermaid.live/edit#pako:" + (await deflateZlibBase64Url(state) ?? bytesToBase64Url(new TextEncoder().encode(state)));
|
|
816
|
-
}
|
|
817
|
-
//#endregion
|
|
818
|
-
//#region src/client/timeline-diff.ts
|
|
819
|
-
/** Whether two timeline entries would render identically. */
|
|
820
|
-
function sameTimelineItem(a, b) {
|
|
821
|
-
return a.seq === b.seq && a.time === b.time && a.turn === b.turn && a.text === b.text && a.imageCount === b.imageCount && a.hasLatex === b.hasLatex && a.hasMathml === b.hasMathml && a.hasMermaid === b.hasMermaid;
|
|
822
|
-
}
|
|
914
|
+
//#region src/client/mermaid-scan.ts
|
|
823
915
|
/**
|
|
824
|
-
*
|
|
825
|
-
*
|
|
826
|
-
*
|
|
827
|
-
*
|
|
828
|
-
*
|
|
916
|
+
* In-place Mermaid rendering over the GUI's code-block DOM, extracted from the
|
|
917
|
+
* React component so it can be benchmarked and tested without mounting the
|
|
918
|
+
* whole shell.
|
|
919
|
+
*
|
|
920
|
+
* Behaviour is deliberately unchanged: the GUI-owned `<pre>` node is never
|
|
921
|
+
* moved, the plugin-owned wrapper is inserted before the block and toggles the
|
|
922
|
+
* block's `display`, a failed render keeps the raw fence plus a retry marker,
|
|
923
|
+
* and a theme flip invalidates the rendered-SVG memo.
|
|
924
|
+
* @module @alexpeng/dsh-custom-plugin/client/mermaid-scan
|
|
829
925
|
*/
|
|
830
|
-
function
|
|
831
|
-
|
|
832
|
-
const
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
926
|
+
function createMermaidScanner(deps) {
|
|
927
|
+
/** Blocks with a render already in flight (WeakSet: dead blocks drop out). */
|
|
928
|
+
const inflight = /* @__PURE__ */ new WeakSet();
|
|
929
|
+
/** Previous scan theme; a flip invalidates rendered-SVG memoization. */
|
|
930
|
+
let lastDark = null;
|
|
931
|
+
/** The banner's language label: `.md-code-block > bannerWrap > banner >
|
|
932
|
+
* infostring` is the GUI CodeBlock's stable shape (its CSS classes are
|
|
933
|
+
* hashed, the structure is not). */
|
|
934
|
+
function blockInfostring(block) {
|
|
935
|
+
const info = block.querySelector(":scope > div:first-child > div:first-child > div:first-child");
|
|
936
|
+
return info !== null ? info.textContent ?? "" : null;
|
|
937
|
+
}
|
|
938
|
+
/** Raw fence text: the GUI keeps unknown languages (mermaid among them) on
|
|
939
|
+
* the plain `<pre><code>` path, so `pre` always carries the source. */
|
|
940
|
+
function blockCodeText(block) {
|
|
941
|
+
const pre = block.querySelector("pre");
|
|
942
|
+
return pre !== null ? pre.textContent ?? "" : null;
|
|
943
|
+
}
|
|
944
|
+
/** Insert/refresh the diagram wrapper before one code block. Never moves
|
|
945
|
+
* GUI-owned nodes — React keeps reconciling its tree; the block is only
|
|
946
|
+
* visually swapped with the diagram stage via display. */
|
|
947
|
+
async function renderInPlace(block, code, dark) {
|
|
948
|
+
const key = mermaidCodeKey(code);
|
|
949
|
+
const existingWrap = block.previousElementSibling;
|
|
950
|
+
if (block.dataset.vxMmd === key && existingWrap !== null && existingWrap.classList.contains("vx-mmd-wrap")) return;
|
|
951
|
+
if (!await deps.ensureMermaid()) {
|
|
952
|
+
block.dataset.vxMmdFail = key;
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
const r = await deps.renderMermaid(code, dark);
|
|
956
|
+
if (!r.ok) {
|
|
957
|
+
block.dataset.vxMmdFail = key;
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
delete block.dataset.vxMmdFail;
|
|
961
|
+
const d = typeof document !== "undefined" ? document : null;
|
|
962
|
+
if (d === null) return;
|
|
963
|
+
let wrap = block.previousElementSibling;
|
|
964
|
+
if (wrap === null || !wrap.classList.contains("vx-mmd-wrap")) {
|
|
965
|
+
wrap = d.createElement("div");
|
|
966
|
+
wrap.className = "vx-mmd-wrap";
|
|
967
|
+
block.parentElement?.insertBefore(wrap, block);
|
|
968
|
+
const bar = d.createElement("div");
|
|
969
|
+
bar.className = "vx-mmd-bar";
|
|
970
|
+
const diagramBtn = d.createElement("button");
|
|
971
|
+
diagramBtn.type = "button";
|
|
972
|
+
diagramBtn.className = "vx-mmd-btn active";
|
|
973
|
+
diagramBtn.textContent = "图表";
|
|
974
|
+
const codeBtn = d.createElement("button");
|
|
975
|
+
codeBtn.type = "button";
|
|
976
|
+
codeBtn.className = "vx-mmd-btn";
|
|
977
|
+
codeBtn.textContent = "代码";
|
|
978
|
+
const live = d.createElement("a");
|
|
979
|
+
live.className = "vx-mmd-live";
|
|
980
|
+
live.target = "_blank";
|
|
981
|
+
live.rel = "noopener noreferrer";
|
|
982
|
+
live.textContent = "mermaid.live";
|
|
983
|
+
mermaidLiveUrl(code).then((url) => {
|
|
984
|
+
live.href = url;
|
|
985
|
+
}).catch(() => {});
|
|
986
|
+
bar.append(diagramBtn, codeBtn, live);
|
|
987
|
+
const stage = d.createElement("div");
|
|
988
|
+
stage.className = "vx-mmd-stage";
|
|
989
|
+
wrap.append(bar, stage);
|
|
990
|
+
const showDiagram = () => {
|
|
991
|
+
stage.style.display = "";
|
|
992
|
+
block.style.display = "none";
|
|
993
|
+
diagramBtn.classList.add("active");
|
|
994
|
+
codeBtn.classList.remove("active");
|
|
995
|
+
};
|
|
996
|
+
const showCode = () => {
|
|
997
|
+
stage.style.display = "none";
|
|
998
|
+
block.style.display = "";
|
|
999
|
+
diagramBtn.classList.remove("active");
|
|
1000
|
+
codeBtn.classList.add("active");
|
|
1001
|
+
};
|
|
1002
|
+
diagramBtn.addEventListener("click", showDiagram);
|
|
1003
|
+
codeBtn.addEventListener("click", showCode);
|
|
1004
|
+
showDiagram();
|
|
1005
|
+
}
|
|
1006
|
+
const stage = wrap.querySelector(".vx-mmd-stage");
|
|
1007
|
+
if (stage === null) return;
|
|
1008
|
+
stage.innerHTML = r.svg;
|
|
1009
|
+
block.dataset.vxMmd = key;
|
|
1010
|
+
}
|
|
1011
|
+
/** Scan every chat code block and render the mermaid ones in place. */
|
|
1012
|
+
async function scan(dark) {
|
|
1013
|
+
const d = typeof document !== "undefined" ? document : null;
|
|
1014
|
+
if (d === null) return;
|
|
1015
|
+
if (lastDark !== null && lastDark !== dark) for (const block of Array.from(d.querySelectorAll(".md-code-block"))) delete block.dataset.vxMmd;
|
|
1016
|
+
lastDark = dark;
|
|
1017
|
+
removeLegacyMermaidErrors(d);
|
|
1018
|
+
for (const wrap of Array.from(d.querySelectorAll(".vx-mmd-wrap"))) {
|
|
1019
|
+
const next = wrap.nextElementSibling;
|
|
1020
|
+
if (next === null || !next.classList.contains("md-code-block")) wrap.remove();
|
|
1021
|
+
}
|
|
1022
|
+
for (const block of Array.from(d.querySelectorAll(".md-code-block"))) {
|
|
1023
|
+
if (inflight.has(block)) continue;
|
|
1024
|
+
const codeRaw = blockCodeText(block);
|
|
1025
|
+
if (codeRaw === null) continue;
|
|
1026
|
+
const code = normalizeMermaidText(codeRaw).trim();
|
|
1027
|
+
if (code === "") continue;
|
|
1028
|
+
const key = mermaidCodeKey(code);
|
|
1029
|
+
const info = blockInfostring(block);
|
|
1030
|
+
if (info !== null && info.trim().toLowerCase() === "mermaid") {
|
|
1031
|
+
if (code.split("\n").filter((l) => l.trim() !== "").length < 2) continue;
|
|
1032
|
+
} else {
|
|
1033
|
+
if (!isGenericInfostring(info)) continue;
|
|
1034
|
+
if (!isMermaidCode(codeRaw)) continue;
|
|
1035
|
+
}
|
|
1036
|
+
if (block.dataset.vxMmd === key || block.dataset.vxMmdFail === key) continue;
|
|
1037
|
+
inflight.add(block);
|
|
1038
|
+
try {
|
|
1039
|
+
await renderInPlace(block, code, dark);
|
|
1040
|
+
} finally {
|
|
1041
|
+
inflight.delete(block);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
/** Undo in-place rendering (feature toggled off): remove wrappers, unhide
|
|
1046
|
+
* code blocks. Diagram DOM is plugin-owned, so removal is safe. */
|
|
1047
|
+
function restore() {
|
|
1048
|
+
const d = typeof document !== "undefined" ? document : null;
|
|
1049
|
+
if (d === null) return;
|
|
1050
|
+
for (const wrap of Array.from(d.querySelectorAll(".vx-mmd-wrap"))) {
|
|
1051
|
+
const next = wrap.nextElementSibling;
|
|
1052
|
+
if (next !== null && next.classList.contains("md-code-block")) next.style.display = "";
|
|
1053
|
+
wrap.remove();
|
|
1054
|
+
}
|
|
1055
|
+
for (const block of Array.from(d.querySelectorAll(".md-code-block"))) {
|
|
1056
|
+
delete block.dataset.vxMmd;
|
|
1057
|
+
delete block.dataset.vxMmdFail;
|
|
1058
|
+
}
|
|
841
1059
|
}
|
|
842
1060
|
return {
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
changed
|
|
1061
|
+
scan,
|
|
1062
|
+
restore
|
|
846
1063
|
};
|
|
847
1064
|
}
|
|
848
|
-
/** Compact DOM identity for a rendered Mermaid block. A 32-bit FNV-1a hash
|
|
849
|
-
* plus the source length is enough to distinguish live blocks without
|
|
850
|
-
* duplicating every diagram's text into a `data-*` attribute. */
|
|
851
|
-
function mermaidCodeKey(code) {
|
|
852
|
-
let hash = 2166136261;
|
|
853
|
-
for (let i = 0; i < code.length; i++) {
|
|
854
|
-
hash ^= code.charCodeAt(i);
|
|
855
|
-
hash = Math.imul(hash, 16777619);
|
|
856
|
-
}
|
|
857
|
-
return (hash >>> 0).toString(36) + "-" + code.length.toString(36);
|
|
858
|
-
}
|
|
859
1065
|
//#endregion
|
|
860
1066
|
//#region src/client/styles.ts
|
|
861
1067
|
/**
|
|
@@ -1848,6 +2054,75 @@ window.__ModuleLoader__.load({
|
|
|
1848
2054
|
}, []);
|
|
1849
2055
|
return current;
|
|
1850
2056
|
}
|
|
2057
|
+
/** Follow the OS "reduce motion" preference; weather FX is decorative. */
|
|
2058
|
+
function useReducedMotion() {
|
|
2059
|
+
const query = () => {
|
|
2060
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return null;
|
|
2061
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
2062
|
+
};
|
|
2063
|
+
const [reduced, setReduced] = react.useState(() => query()?.matches === true);
|
|
2064
|
+
react.useEffect(() => {
|
|
2065
|
+
const mq = query();
|
|
2066
|
+
if (mq === null) return;
|
|
2067
|
+
const onChange = () => setReduced(mq.matches);
|
|
2068
|
+
setReduced(mq.matches);
|
|
2069
|
+
mq.addEventListener?.("change", onChange);
|
|
2070
|
+
return () => {
|
|
2071
|
+
mq.removeEventListener?.("change", onChange);
|
|
2072
|
+
};
|
|
2073
|
+
}, []);
|
|
2074
|
+
return reduced;
|
|
2075
|
+
}
|
|
2076
|
+
const DIALOG_FOCUSABLE = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
|
|
2077
|
+
/**
|
|
2078
|
+
* Modal semantics for the six overlays: focus enters the panel, Tab wraps,
|
|
2079
|
+
* Escape closes, and closing restores the element that opened it.
|
|
2080
|
+
*/
|
|
2081
|
+
function useDialogFocus(onClose) {
|
|
2082
|
+
const ref = react.useRef(null);
|
|
2083
|
+
const closeRef = react.useRef(onClose);
|
|
2084
|
+
closeRef.current = onClose;
|
|
2085
|
+
react.useEffect(() => {
|
|
2086
|
+
const node = ref.current;
|
|
2087
|
+
if (node === null) return;
|
|
2088
|
+
const previous = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
2089
|
+
const focusables = () => Array.from(node.querySelectorAll(DIALOG_FOCUSABLE)).filter((el) => el.getClientRects().length > 0);
|
|
2090
|
+
if (!node.contains(document.activeElement)) (focusables()[0] ?? node).focus();
|
|
2091
|
+
const onKeyDown = (event) => {
|
|
2092
|
+
if (event.key === "Escape") {
|
|
2093
|
+
event.preventDefault();
|
|
2094
|
+
event.stopPropagation();
|
|
2095
|
+
closeRef.current();
|
|
2096
|
+
return;
|
|
2097
|
+
}
|
|
2098
|
+
if (event.key !== "Tab") return;
|
|
2099
|
+
const items = focusables();
|
|
2100
|
+
if (items.length === 0) {
|
|
2101
|
+
event.preventDefault();
|
|
2102
|
+
node.focus();
|
|
2103
|
+
return;
|
|
2104
|
+
}
|
|
2105
|
+
const first = items[0];
|
|
2106
|
+
const last = items[items.length - 1];
|
|
2107
|
+
const active = document.activeElement;
|
|
2108
|
+
if (event.shiftKey && (active === first || active === node)) {
|
|
2109
|
+
event.preventDefault();
|
|
2110
|
+
last.focus();
|
|
2111
|
+
} else if (!event.shiftKey && active === last) {
|
|
2112
|
+
event.preventDefault();
|
|
2113
|
+
first.focus();
|
|
2114
|
+
}
|
|
2115
|
+
};
|
|
2116
|
+
node.addEventListener("keydown", onKeyDown);
|
|
2117
|
+
return () => {
|
|
2118
|
+
node.removeEventListener("keydown", onKeyDown);
|
|
2119
|
+
if (previous !== null && previous.isConnected) try {
|
|
2120
|
+
previous.focus();
|
|
2121
|
+
} catch {}
|
|
2122
|
+
};
|
|
2123
|
+
}, []);
|
|
2124
|
+
return ref;
|
|
2125
|
+
}
|
|
1851
2126
|
function useSessionsSafe(props) {
|
|
1852
2127
|
try {
|
|
1853
2128
|
return props.useSessions((st) => st);
|
|
@@ -2829,6 +3104,7 @@ window.__ModuleLoader__.load({
|
|
|
2829
3104
|
weather: state.cfg.weather ?? "none",
|
|
2830
3105
|
dark: state.dark === true
|
|
2831
3106
|
}), shallowEqual);
|
|
3107
|
+
const reduced = useReducedMotion();
|
|
2832
3108
|
const ref = react.useRef(null);
|
|
2833
3109
|
/** 粒子配色跟随背景亮度:浅色主题需要更深的粒子颜色才可辨识。
|
|
2834
3110
|
* ref 让 RAF 循环每帧读到最新值,主题/背景切换时无需重建粒子场。 */
|
|
@@ -2843,11 +3119,11 @@ window.__ModuleLoader__.load({
|
|
|
2843
3119
|
if (g === null) return;
|
|
2844
3120
|
const w = cvs.clientWidth || 0;
|
|
2845
3121
|
const h = cvs.clientHeight || 0;
|
|
2846
|
-
initFx(weather, w, h);
|
|
3122
|
+
if (!reduced) initFx(weather, w, h);
|
|
2847
3123
|
let raf = 0;
|
|
2848
3124
|
const t0 = Date.now();
|
|
2849
3125
|
const loop = () => {
|
|
2850
|
-
if (weather === "none") {
|
|
3126
|
+
if (weather === "none" || reduced) {
|
|
2851
3127
|
try {
|
|
2852
3128
|
g.clearRect(0, 0, cvs.width, cvs.height);
|
|
2853
3129
|
} catch {}
|
|
@@ -2862,10 +3138,11 @@ window.__ModuleLoader__.load({
|
|
|
2862
3138
|
cancelAnimationFrame(raf);
|
|
2863
3139
|
} catch {}
|
|
2864
3140
|
};
|
|
2865
|
-
}, [weather]);
|
|
3141
|
+
}, [weather, reduced]);
|
|
2866
3142
|
return react.createElement("canvas", {
|
|
2867
3143
|
ref,
|
|
2868
|
-
className: "vx-fx"
|
|
3144
|
+
className: "vx-fx",
|
|
3145
|
+
"aria-hidden": true
|
|
2869
3146
|
});
|
|
2870
3147
|
}
|
|
2871
3148
|
let turnsRequestSerial = 0;
|
|
@@ -3098,7 +3375,7 @@ window.__ModuleLoader__.load({
|
|
|
3098
3375
|
mermaidState = { status: "ready" };
|
|
3099
3376
|
if (d0 !== null) {
|
|
3100
3377
|
for (const el of Array.from(d0.querySelectorAll("[data-vx-mmd-fail]"))) delete el.dataset.vxMmdFail;
|
|
3101
|
-
if (S.cfg.mermaid === true)
|
|
3378
|
+
if (S.cfg.mermaid === true) mermaidScanner.scan(S.dark);
|
|
3102
3379
|
}
|
|
3103
3380
|
return true;
|
|
3104
3381
|
}
|
|
@@ -3117,36 +3394,10 @@ window.__ModuleLoader__.load({
|
|
|
3117
3394
|
clearTimeout(watchdog);
|
|
3118
3395
|
}
|
|
3119
3396
|
}
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
ok: false,
|
|
3125
|
-
error: "引擎未就绪"
|
|
3126
|
-
};
|
|
3127
|
-
mermaid.initialize({
|
|
3128
|
-
startOnLoad: false,
|
|
3129
|
-
theme: dark ? "dark" : "default",
|
|
3130
|
-
securityLevel: "strict"
|
|
3131
|
-
});
|
|
3132
|
-
const id = "vx-mmd-" + Date.now() + Math.floor(Math.random() * 9999);
|
|
3133
|
-
const out = await mermaid.render(id, code);
|
|
3134
|
-
const svg = typeof out === "string" ? out : out?.svg ?? "";
|
|
3135
|
-
if (svg === "") return {
|
|
3136
|
-
ok: false,
|
|
3137
|
-
error: "引擎未返回 SVG"
|
|
3138
|
-
};
|
|
3139
|
-
return {
|
|
3140
|
-
ok: true,
|
|
3141
|
-
svg
|
|
3142
|
-
};
|
|
3143
|
-
} catch (error) {
|
|
3144
|
-
return {
|
|
3145
|
-
ok: false,
|
|
3146
|
-
error: String(error?.message ?? error)
|
|
3147
|
-
};
|
|
3148
|
-
}
|
|
3149
|
-
}
|
|
3397
|
+
const mermaidScanner = createMermaidScanner({
|
|
3398
|
+
ensureMermaid,
|
|
3399
|
+
renderMermaid
|
|
3400
|
+
});
|
|
3150
3401
|
function extractMermaid(text) {
|
|
3151
3402
|
const out = [];
|
|
3152
3403
|
const re = /```mermaid\s*\n([\s\S]*?)```/gi;
|
|
@@ -3166,136 +3417,6 @@ window.__ModuleLoader__.load({
|
|
|
3166
3417
|
index: 0
|
|
3167
3418
|
} });
|
|
3168
3419
|
}
|
|
3169
|
-
/** Blocks with a render already in flight (WeakSet: dead blocks drop out). */
|
|
3170
|
-
const mmdInflight = /* @__PURE__ */ new WeakSet();
|
|
3171
|
-
/** Previous scan theme; a flip invalidates rendered-SVG memoization. */
|
|
3172
|
-
let mmdLastDark = null;
|
|
3173
|
-
/** The banner's language label: `.md-code-block > bannerWrap > banner >
|
|
3174
|
-
* infostring` is the GUI CodeBlock's stable shape (its CSS classes are
|
|
3175
|
-
* hashed, the structure is not). */
|
|
3176
|
-
function blockInfostring(block) {
|
|
3177
|
-
const info = block.querySelector(":scope > div:first-child > div:first-child > div:first-child");
|
|
3178
|
-
return info !== null ? info.textContent ?? "" : null;
|
|
3179
|
-
}
|
|
3180
|
-
/** Raw fence text: the GUI keeps unknown languages (mermaid among them) on
|
|
3181
|
-
* the plain `<pre><code>` path, so `pre` always carries the source. */
|
|
3182
|
-
function blockCodeText(block) {
|
|
3183
|
-
const pre = block.querySelector("pre");
|
|
3184
|
-
return pre !== null ? pre.textContent ?? "" : null;
|
|
3185
|
-
}
|
|
3186
|
-
/** Insert/refresh the diagram wrapper before one code block. Never moves
|
|
3187
|
-
* GUI-owned nodes — React keeps reconciling its tree; the block is only
|
|
3188
|
-
* visually swapped with the diagram stage via display. */
|
|
3189
|
-
async function renderInPlace(block, code, dark) {
|
|
3190
|
-
const key = mermaidCodeKey(code);
|
|
3191
|
-
const existingWrap = block.previousElementSibling;
|
|
3192
|
-
if (block.dataset.vxMmd === key && existingWrap !== null && existingWrap.classList.contains("vx-mmd-wrap")) return;
|
|
3193
|
-
if (!await ensureMermaid()) {
|
|
3194
|
-
block.dataset.vxMmdFail = key;
|
|
3195
|
-
return;
|
|
3196
|
-
}
|
|
3197
|
-
const r = await renderMermaid(code, dark);
|
|
3198
|
-
if (!r.ok) {
|
|
3199
|
-
block.dataset.vxMmdFail = key;
|
|
3200
|
-
return;
|
|
3201
|
-
}
|
|
3202
|
-
delete block.dataset.vxMmdFail;
|
|
3203
|
-
const d = typeof document !== "undefined" ? document : null;
|
|
3204
|
-
if (d === null) return;
|
|
3205
|
-
let wrap = block.previousElementSibling;
|
|
3206
|
-
if (wrap === null || !wrap.classList.contains("vx-mmd-wrap")) {
|
|
3207
|
-
wrap = d.createElement("div");
|
|
3208
|
-
wrap.className = "vx-mmd-wrap";
|
|
3209
|
-
block.parentElement?.insertBefore(wrap, block);
|
|
3210
|
-
const bar = d.createElement("div");
|
|
3211
|
-
bar.className = "vx-mmd-bar";
|
|
3212
|
-
const diagramBtn = d.createElement("button");
|
|
3213
|
-
diagramBtn.type = "button";
|
|
3214
|
-
diagramBtn.className = "vx-mmd-btn active";
|
|
3215
|
-
diagramBtn.textContent = "图表";
|
|
3216
|
-
const codeBtn = d.createElement("button");
|
|
3217
|
-
codeBtn.type = "button";
|
|
3218
|
-
codeBtn.className = "vx-mmd-btn";
|
|
3219
|
-
codeBtn.textContent = "代码";
|
|
3220
|
-
const live = d.createElement("a");
|
|
3221
|
-
live.className = "vx-mmd-live";
|
|
3222
|
-
live.target = "_blank";
|
|
3223
|
-
live.rel = "noopener noreferrer";
|
|
3224
|
-
live.textContent = "mermaid.live";
|
|
3225
|
-
mermaidLiveUrl(code).then((url) => {
|
|
3226
|
-
live.href = url;
|
|
3227
|
-
}).catch(() => {});
|
|
3228
|
-
bar.append(diagramBtn, codeBtn, live);
|
|
3229
|
-
const stage = d.createElement("div");
|
|
3230
|
-
stage.className = "vx-mmd-stage";
|
|
3231
|
-
wrap.append(bar, stage);
|
|
3232
|
-
const showDiagram = () => {
|
|
3233
|
-
stage.style.display = "";
|
|
3234
|
-
block.style.display = "none";
|
|
3235
|
-
diagramBtn.classList.add("active");
|
|
3236
|
-
codeBtn.classList.remove("active");
|
|
3237
|
-
};
|
|
3238
|
-
const showCode = () => {
|
|
3239
|
-
stage.style.display = "none";
|
|
3240
|
-
block.style.display = "";
|
|
3241
|
-
diagramBtn.classList.remove("active");
|
|
3242
|
-
codeBtn.classList.add("active");
|
|
3243
|
-
};
|
|
3244
|
-
diagramBtn.addEventListener("click", showDiagram);
|
|
3245
|
-
codeBtn.addEventListener("click", showCode);
|
|
3246
|
-
showDiagram();
|
|
3247
|
-
}
|
|
3248
|
-
const stage = wrap.querySelector(".vx-mmd-stage");
|
|
3249
|
-
if (stage === null) return;
|
|
3250
|
-
stage.innerHTML = r.svg;
|
|
3251
|
-
block.dataset.vxMmd = key;
|
|
3252
|
-
}
|
|
3253
|
-
/** Scan every chat code block and render the mermaid ones in place. */
|
|
3254
|
-
async function scanMermaidBlocks(dark) {
|
|
3255
|
-
const d = typeof document !== "undefined" ? document : null;
|
|
3256
|
-
if (d === null) return;
|
|
3257
|
-
for (const wrap of Array.from(d.querySelectorAll(".vx-mmd-wrap"))) {
|
|
3258
|
-
const next = wrap.nextElementSibling;
|
|
3259
|
-
if (next === null || !next.classList.contains("md-code-block")) wrap.remove();
|
|
3260
|
-
}
|
|
3261
|
-
for (const block of Array.from(d.querySelectorAll(".md-code-block"))) {
|
|
3262
|
-
if (mmdInflight.has(block)) continue;
|
|
3263
|
-
const codeRaw = blockCodeText(block);
|
|
3264
|
-
if (codeRaw === null) continue;
|
|
3265
|
-
const code = normalizeMermaidText(codeRaw).trim();
|
|
3266
|
-
if (code === "") continue;
|
|
3267
|
-
const key = mermaidCodeKey(code);
|
|
3268
|
-
const info = blockInfostring(block);
|
|
3269
|
-
if (info !== null && info.trim().toLowerCase() === "mermaid") {
|
|
3270
|
-
if (code.split("\n").filter((l) => l.trim() !== "").length < 2) continue;
|
|
3271
|
-
} else {
|
|
3272
|
-
if (!isGenericInfostring(info)) continue;
|
|
3273
|
-
if (!isMermaidCode(codeRaw)) continue;
|
|
3274
|
-
}
|
|
3275
|
-
if (block.dataset.vxMmd === key || block.dataset.vxMmdFail === key) continue;
|
|
3276
|
-
mmdInflight.add(block);
|
|
3277
|
-
try {
|
|
3278
|
-
await renderInPlace(block, code, dark);
|
|
3279
|
-
} finally {
|
|
3280
|
-
mmdInflight.delete(block);
|
|
3281
|
-
}
|
|
3282
|
-
}
|
|
3283
|
-
}
|
|
3284
|
-
/** Undo in-place rendering (feature toggled off): remove wrappers, unhide
|
|
3285
|
-
* code blocks. Diagram DOM is plugin-owned, so removal is safe. */
|
|
3286
|
-
function restoreMermaidBlocks() {
|
|
3287
|
-
const d = typeof document !== "undefined" ? document : null;
|
|
3288
|
-
if (d === null) return;
|
|
3289
|
-
for (const wrap of Array.from(d.querySelectorAll(".vx-mmd-wrap"))) {
|
|
3290
|
-
const next = wrap.nextElementSibling;
|
|
3291
|
-
if (next !== null && next.classList.contains("md-code-block")) next.style.display = "";
|
|
3292
|
-
wrap.remove();
|
|
3293
|
-
}
|
|
3294
|
-
for (const block of Array.from(d.querySelectorAll(".md-code-block"))) {
|
|
3295
|
-
delete block.dataset.vxMmd;
|
|
3296
|
-
delete block.dataset.vxMmdFail;
|
|
3297
|
-
}
|
|
3298
|
-
}
|
|
3299
3420
|
let balanceRetryTimer = null;
|
|
3300
3421
|
let balanceRetries = 0;
|
|
3301
3422
|
async function refreshBalance() {
|
|
@@ -3567,6 +3688,7 @@ window.__ModuleLoader__.load({
|
|
|
3567
3688
|
}, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, "提示词库"), react.createElement("button", {
|
|
3568
3689
|
className: "vx-chip",
|
|
3569
3690
|
title: "关闭",
|
|
3691
|
+
"aria-label": "关闭提示词面板",
|
|
3570
3692
|
onClick: () => setS({ promptOpen: null })
|
|
3571
3693
|
}, react.createElement(Icon, {
|
|
3572
3694
|
n: "x",
|
|
@@ -3588,40 +3710,65 @@ window.__ModuleLoader__.load({
|
|
|
3588
3710
|
}
|
|
3589
3711
|
function HeaderBalance(props) {
|
|
3590
3712
|
useViewedSession(props);
|
|
3591
|
-
const
|
|
3592
|
-
|
|
3713
|
+
const { balance: b, usageRow, balanceOpen: open } = useSSelector((state) => ({
|
|
3714
|
+
balance: state.balance,
|
|
3715
|
+
usageRow: state.usage[dayKey()] ?? null,
|
|
3716
|
+
balanceOpen: state.balanceOpen === true
|
|
3717
|
+
}), shallowEqual);
|
|
3593
3718
|
react.useEffect(() => {
|
|
3594
3719
|
if (S.balance === null) refreshBalance();
|
|
3595
|
-
const
|
|
3720
|
+
const tick = () => {
|
|
3721
|
+
if (typeof document !== "undefined" && document.hidden) return;
|
|
3722
|
+
refreshBalance();
|
|
3723
|
+
};
|
|
3724
|
+
const timer = setInterval(tick, 6e4);
|
|
3725
|
+
const onVisibility = () => {
|
|
3726
|
+
if (typeof document === "undefined" || document.hidden) return;
|
|
3596
3727
|
refreshBalance();
|
|
3597
|
-
}
|
|
3728
|
+
};
|
|
3729
|
+
if (typeof document !== "undefined") document.addEventListener("visibilitychange", onVisibility);
|
|
3598
3730
|
return () => {
|
|
3599
3731
|
clearInterval(timer);
|
|
3732
|
+
if (typeof document !== "undefined") document.removeEventListener("visibilitychange", onVisibility);
|
|
3600
3733
|
};
|
|
3601
3734
|
}, []);
|
|
3602
|
-
const usageToday =
|
|
3603
|
-
const calls = Object.keys(usageToday).reduce((n, k) => n + (usageToday[k].calls ?? 0), 0);
|
|
3604
|
-
const estimate = Object.entries(usageToday).reduce((sum, [model, row]) => sum + estimateUsageCostCny(row, model), 0);
|
|
3735
|
+
const usageToday = usageRow ?? {};
|
|
3736
|
+
const calls = react.useMemo(() => Object.keys(usageToday).reduce((n, k) => n + (usageToday[k].calls ?? 0), 0), [usageToday]);
|
|
3737
|
+
const estimate = react.useMemo(() => Object.entries(usageToday).reduce((sum, [model, row]) => sum + estimateUsageCostCny(row, model), 0), [usageToday]);
|
|
3605
3738
|
const bal = b?.ok === true && b.balance !== null && b.balance !== void 0 ? b.balance : null;
|
|
3606
3739
|
const keyConfigured = b?.ok === false && b.keyConfigured === true;
|
|
3607
3740
|
const balance = bal !== null ? (bal.currency ?? "CNY") === "CNY" ? "¥" + (bal.total ?? "") : `${bal.total ?? ""} ${bal.currency ?? ""}` : keyConfigured ? "额度" : b === null ? "额度…" : `≈¥${estimate.toFixed(2)}`;
|
|
3608
3741
|
const estimateTitle = `按本机 token 用量与官方价目表折算的估算值(${DEEPSEEK_PRICING_CHECKED_ON} 核对),非账号账单;配置 API Key 后显示真实余额`;
|
|
3609
3742
|
const balanceError = keyConfigured && b?.ok === false ? String(b.error ?? "未知错误") : null;
|
|
3610
3743
|
const pillTitle = bal !== null ? void 0 : balanceError !== null ? `余额查询失败:${balanceError}(失败后会自动重试,也可在面板中手动刷新)` : b === null ? void 0 : estimateTitle;
|
|
3611
|
-
const
|
|
3744
|
+
const togglePanel = () => setS({
|
|
3745
|
+
balanceOpen: !open,
|
|
3746
|
+
panelOpen: false,
|
|
3747
|
+
promptOpen: null,
|
|
3748
|
+
foldersOpen: false
|
|
3749
|
+
});
|
|
3612
3750
|
return react.createElement("span", { className: "vx-balance-wrap" }, react.createElement("span", {
|
|
3613
3751
|
className: "vx-balance-text" + (open ? " vx-balance-open" : ""),
|
|
3752
|
+
role: "button",
|
|
3753
|
+
tabIndex: 0,
|
|
3754
|
+
"aria-expanded": open,
|
|
3755
|
+
"aria-haspopup": "dialog",
|
|
3614
3756
|
title: open ? "再次点击收起面板" : "点击打开面板",
|
|
3615
|
-
onClick:
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3757
|
+
onClick: togglePanel,
|
|
3758
|
+
onKeyDown: (e) => {
|
|
3759
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
3760
|
+
e.preventDefault();
|
|
3761
|
+
togglePanel();
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3621
3764
|
}, react.createElement(Icon, {
|
|
3622
3765
|
n: "wallet",
|
|
3623
3766
|
size: 13
|
|
3624
|
-
}), react.createElement("span", { title: pillTitle }, balance), calls > 0 ? react.createElement("span", { className: "vx-balance-today" }, `今日 ${calls} 次`) : null), open ? react.createElement("div", {
|
|
3767
|
+
}), react.createElement("span", { title: pillTitle }, balance), calls > 0 ? react.createElement("span", { className: "vx-balance-today" }, `今日 ${calls} 次`) : null), open ? react.createElement("div", {
|
|
3768
|
+
className: "vx-glass vx-balance-hover",
|
|
3769
|
+
role: "dialog",
|
|
3770
|
+
"aria-label": "额度面板"
|
|
3771
|
+
}, react.createElement(BalancePanelContent, null)) : null);
|
|
3625
3772
|
}
|
|
3626
3773
|
function UsageTable() {
|
|
3627
3774
|
const day = useS().usage[dayKey()] ?? {};
|
|
@@ -3798,7 +3945,7 @@ window.__ModuleLoader__.load({
|
|
|
3798
3945
|
}
|
|
3799
3946
|
function QuoteDock(props) {
|
|
3800
3947
|
useViewedSession(props);
|
|
3801
|
-
const
|
|
3948
|
+
const quoteEnabled = useSSelector((state) => state.cfg.quote === true);
|
|
3802
3949
|
const inputRef = react.useRef(props.input);
|
|
3803
3950
|
inputRef.current = props.input;
|
|
3804
3951
|
const actionsRef = react.useRef(props.inputActions);
|
|
@@ -3821,7 +3968,7 @@ window.__ModuleLoader__.load({
|
|
|
3821
3968
|
};
|
|
3822
3969
|
}, []);
|
|
3823
3970
|
react.useEffect(() => {
|
|
3824
|
-
if (
|
|
3971
|
+
if (!quoteEnabled) {
|
|
3825
3972
|
if (S.quoteSel !== null) setS({ quoteSel: null });
|
|
3826
3973
|
return;
|
|
3827
3974
|
}
|
|
@@ -3865,13 +4012,13 @@ window.__ModuleLoader__.load({
|
|
|
3865
4012
|
};
|
|
3866
4013
|
d.addEventListener("selectionchange", onSel);
|
|
3867
4014
|
return () => d.removeEventListener("selectionchange", onSel);
|
|
3868
|
-
}, [
|
|
4015
|
+
}, [quoteEnabled]);
|
|
3869
4016
|
return null;
|
|
3870
4017
|
}
|
|
3871
4018
|
function QuoteButton() {
|
|
3872
|
-
const
|
|
3873
|
-
if (
|
|
3874
|
-
const q =
|
|
4019
|
+
const quoteSel = useSSelector((state) => state.quoteSel);
|
|
4020
|
+
if (quoteSel === null) return null;
|
|
4021
|
+
const q = quoteSel;
|
|
3875
4022
|
const fmt = q.text.split("\n").map((l) => "> " + l).join("\n");
|
|
3876
4023
|
return react.createElement("button", {
|
|
3877
4024
|
className: "vx-quote-btn",
|
|
@@ -4816,6 +4963,7 @@ window.__ModuleLoader__.load({
|
|
|
4816
4963
|
react.useEffect(() => {
|
|
4817
4964
|
if (s.ask !== null) setVal(s.ask.value ?? "");
|
|
4818
4965
|
}, [s.ask?.title]);
|
|
4966
|
+
const dialogRef = useDialogFocus(() => setS({ ask: null }));
|
|
4819
4967
|
const ask = s.ask;
|
|
4820
4968
|
if (ask === null) return null;
|
|
4821
4969
|
const submit = () => {
|
|
@@ -4829,6 +4977,11 @@ window.__ModuleLoader__.load({
|
|
|
4829
4977
|
}, react.createElement("div", {
|
|
4830
4978
|
className: "vx-glass vx-modal",
|
|
4831
4979
|
style: { width: "min(360px, 92vw)" },
|
|
4980
|
+
role: "dialog",
|
|
4981
|
+
"aria-modal": true,
|
|
4982
|
+
"aria-label": ask.title,
|
|
4983
|
+
tabIndex: -1,
|
|
4984
|
+
ref: dialogRef,
|
|
4832
4985
|
onClick: (e) => e.stopPropagation()
|
|
4833
4986
|
}, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, ask.title)), react.createElement("input", {
|
|
4834
4987
|
className: "vx-input",
|
|
@@ -4847,32 +5000,43 @@ window.__ModuleLoader__.load({
|
|
|
4847
5000
|
}, "取消"))));
|
|
4848
5001
|
}
|
|
4849
5002
|
function ConfirmModal() {
|
|
4850
|
-
const
|
|
4851
|
-
if (s.confirmAsk === null) return null;
|
|
4852
|
-
const c = s.confirmAsk;
|
|
5003
|
+
const c = useS().confirmAsk;
|
|
4853
5004
|
const answer = (ok) => {
|
|
5005
|
+
if (c === null) return;
|
|
4854
5006
|
const cb = c.cb;
|
|
4855
5007
|
setS({ confirmAsk: null });
|
|
4856
5008
|
cb(ok);
|
|
4857
5009
|
};
|
|
5010
|
+
const dialogRef = useDialogFocus(() => answer(false));
|
|
5011
|
+
if (c === null) return null;
|
|
4858
5012
|
return react.createElement("div", {
|
|
4859
5013
|
className: "vx-modal-mask",
|
|
4860
5014
|
onClick: () => answer(false)
|
|
4861
5015
|
}, react.createElement("div", {
|
|
4862
5016
|
className: "vx-glass vx-modal",
|
|
4863
5017
|
style: { width: "min(380px, 92vw)" },
|
|
5018
|
+
role: "dialog",
|
|
5019
|
+
"aria-modal": true,
|
|
5020
|
+
"aria-label": "确认操作",
|
|
5021
|
+
tabIndex: -1,
|
|
5022
|
+
ref: dialogRef,
|
|
4864
5023
|
onClick: (e) => e.stopPropagation()
|
|
4865
5024
|
}, react.createElement("div", { className: "vx-pad" }, c.message), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement("button", {
|
|
4866
5025
|
className: "vx-btn vx-btn-danger",
|
|
4867
5026
|
onClick: () => answer(true)
|
|
4868
5027
|
}, "确定"), react.createElement("button", {
|
|
4869
5028
|
className: "vx-btn",
|
|
5029
|
+
autoFocus: true,
|
|
4870
5030
|
onClick: () => answer(false)
|
|
4871
5031
|
}, "取消"))));
|
|
4872
5032
|
}
|
|
4873
5033
|
function TemplateModal() {
|
|
4874
5034
|
const s = useS();
|
|
4875
5035
|
const prompt = s.templatePrompt;
|
|
5036
|
+
const dialogRef = useDialogFocus(() => setS({
|
|
5037
|
+
templatePrompt: null,
|
|
5038
|
+
templateValues: {}
|
|
5039
|
+
}));
|
|
4876
5040
|
if (prompt === null) return null;
|
|
4877
5041
|
const names = promptVariables(prompt.text);
|
|
4878
5042
|
const submit = () => {
|
|
@@ -4907,6 +5071,11 @@ window.__ModuleLoader__.load({
|
|
|
4907
5071
|
}, react.createElement("div", {
|
|
4908
5072
|
className: "vx-glass vx-modal",
|
|
4909
5073
|
style: { width: "min(440px, 92vw)" },
|
|
5074
|
+
role: "dialog",
|
|
5075
|
+
"aria-modal": true,
|
|
5076
|
+
"aria-label": `填写变量 · ${prompt.name}`,
|
|
5077
|
+
tabIndex: -1,
|
|
5078
|
+
ref: dialogRef,
|
|
4910
5079
|
onClick: (e) => e.stopPropagation()
|
|
4911
5080
|
}, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, `填写变量 · ${prompt.name}`)), names.map((name) => react.createElement("label", {
|
|
4912
5081
|
key: name,
|
|
@@ -4930,12 +5099,13 @@ window.__ModuleLoader__.load({
|
|
|
4930
5099
|
}, "取消"))));
|
|
4931
5100
|
}
|
|
4932
5101
|
function MermaidInPlace() {
|
|
4933
|
-
const
|
|
4934
|
-
|
|
4935
|
-
|
|
5102
|
+
const { enabled, dark } = useSSelector((state) => ({
|
|
5103
|
+
enabled: state.cfg.mermaid === true,
|
|
5104
|
+
dark: state.dark === true
|
|
5105
|
+
}), shallowEqual);
|
|
4936
5106
|
react.useEffect(() => {
|
|
4937
5107
|
if (!enabled) {
|
|
4938
|
-
|
|
5108
|
+
mermaidScanner.restore();
|
|
4939
5109
|
return;
|
|
4940
5110
|
}
|
|
4941
5111
|
const d = typeof document !== "undefined" ? document : null;
|
|
@@ -4944,14 +5114,12 @@ window.__ModuleLoader__.load({
|
|
|
4944
5114
|
let timer = null;
|
|
4945
5115
|
let stopped = false;
|
|
4946
5116
|
const scan = () => {
|
|
4947
|
-
if (!stopped)
|
|
5117
|
+
if (!stopped) mermaidScanner.scan(dark);
|
|
4948
5118
|
};
|
|
4949
5119
|
const schedule = () => {
|
|
4950
5120
|
if (timer !== null) clearTimeout(timer);
|
|
4951
5121
|
timer = setTimeout(scan, 400);
|
|
4952
5122
|
};
|
|
4953
|
-
if (mmdLastDark !== null && mmdLastDark !== dark) for (const block of Array.from(d.querySelectorAll(".md-code-block"))) delete block.dataset.vxMmd;
|
|
4954
|
-
mmdLastDark = dark;
|
|
4955
5123
|
scan();
|
|
4956
5124
|
const observer = new MutationObserver(schedule);
|
|
4957
5125
|
observer.observe(d.body, {
|
|
@@ -4976,6 +5144,7 @@ window.__ModuleLoader__.load({
|
|
|
4976
5144
|
const [err, setErr] = react.useState(null);
|
|
4977
5145
|
const [loading, setLoading] = react.useState(false);
|
|
4978
5146
|
const [liveUrl, setLiveUrl] = react.useState("#");
|
|
5147
|
+
const dialogRef = useDialogFocus(() => setS({ mermaidModal: null }));
|
|
4979
5148
|
react.useEffect(() => {
|
|
4980
5149
|
if (mm === null) return;
|
|
4981
5150
|
let alive = true;
|
|
@@ -5009,10 +5178,16 @@ window.__ModuleLoader__.load({
|
|
|
5009
5178
|
onClick: () => setS({ mermaidModal: null })
|
|
5010
5179
|
}, react.createElement("div", {
|
|
5011
5180
|
className: "vx-glass vx-modal",
|
|
5181
|
+
role: "dialog",
|
|
5182
|
+
"aria-modal": true,
|
|
5183
|
+
"aria-label": "Mermaid 图表",
|
|
5184
|
+
tabIndex: -1,
|
|
5185
|
+
ref: dialogRef,
|
|
5012
5186
|
onClick: (e) => e.stopPropagation()
|
|
5013
5187
|
}, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, `${mm.title} (${mm.index + 1}/${mm.codes.length})`), react.createElement("span", { className: "vx-row" }, mm.codes.length > 1 ? react.createElement("button", {
|
|
5014
5188
|
className: "vx-chip",
|
|
5015
5189
|
title: "上一个",
|
|
5190
|
+
"aria-label": "上一个图表",
|
|
5016
5191
|
onClick: () => setS({ mermaidModal: {
|
|
5017
5192
|
...mm,
|
|
5018
5193
|
index: (mm.index + mm.codes.length - 1) % mm.codes.length
|
|
@@ -5024,6 +5199,7 @@ window.__ModuleLoader__.load({
|
|
|
5024
5199
|
})) : null, mm.codes.length > 1 ? react.createElement("button", {
|
|
5025
5200
|
className: "vx-chip",
|
|
5026
5201
|
title: "下一个",
|
|
5202
|
+
"aria-label": "下一个图表",
|
|
5027
5203
|
onClick: () => setS({ mermaidModal: {
|
|
5028
5204
|
...mm,
|
|
5029
5205
|
index: (mm.index + 1) % mm.codes.length
|
|
@@ -5039,6 +5215,7 @@ window.__ModuleLoader__.load({
|
|
|
5039
5215
|
}, "在 mermaid.live 打开"), react.createElement("button", {
|
|
5040
5216
|
className: "vx-chip",
|
|
5041
5217
|
title: "关闭",
|
|
5218
|
+
"aria-label": "关闭图表",
|
|
5042
5219
|
onClick: () => setS({ mermaidModal: null })
|
|
5043
5220
|
}, react.createElement(Icon, {
|
|
5044
5221
|
n: "x",
|
|
@@ -5058,6 +5235,7 @@ window.__ModuleLoader__.load({
|
|
|
5058
5235
|
const [index, setIndex] = react.useState(0);
|
|
5059
5236
|
const [remote, setRemote] = react.useState([]);
|
|
5060
5237
|
const [remoteStatus, setRemoteStatus] = react.useState("");
|
|
5238
|
+
const dialogRef = useDialogFocus(() => setS({ commandOpen: false }));
|
|
5061
5239
|
react.useEffect(() => {
|
|
5062
5240
|
if (!s.commandOpen || query.trim().length < 2) {
|
|
5063
5241
|
setRemote([]);
|
|
@@ -5224,6 +5402,11 @@ window.__ModuleLoader__.load({
|
|
|
5224
5402
|
}, react.createElement("div", {
|
|
5225
5403
|
className: "vx-glass vx-modal",
|
|
5226
5404
|
style: { width: "min(620px, 94vw)" },
|
|
5405
|
+
role: "dialog",
|
|
5406
|
+
"aria-modal": true,
|
|
5407
|
+
"aria-label": "命令面板",
|
|
5408
|
+
tabIndex: -1,
|
|
5409
|
+
ref: dialogRef,
|
|
5227
5410
|
onClick: (e) => e.stopPropagation()
|
|
5228
5411
|
}, react.createElement("input", {
|
|
5229
5412
|
className: "vx-input",
|
|
@@ -5259,6 +5442,7 @@ window.__ModuleLoader__.load({
|
|
|
5259
5442
|
useS();
|
|
5260
5443
|
const [sel, setSel] = react.useState({});
|
|
5261
5444
|
const [q, setQ] = react.useState("");
|
|
5445
|
+
const dialogRef = useDialogFocus(() => setS({ batchModal: false }));
|
|
5262
5446
|
const sessions = useSessionsSafe(props);
|
|
5263
5447
|
const ids = sessions !== null ? sessions.ids ?? [] : [];
|
|
5264
5448
|
const byId = sessions !== null ? sessions.byId : {};
|
|
@@ -5291,10 +5475,16 @@ window.__ModuleLoader__.load({
|
|
|
5291
5475
|
}, react.createElement("div", {
|
|
5292
5476
|
className: "vx-glass vx-modal",
|
|
5293
5477
|
style: { width: "min(560px, 92vw)" },
|
|
5478
|
+
role: "dialog",
|
|
5479
|
+
"aria-modal": true,
|
|
5480
|
+
"aria-label": "批量归档会话",
|
|
5481
|
+
tabIndex: -1,
|
|
5482
|
+
ref: dialogRef,
|
|
5294
5483
|
onClick: (e) => e.stopPropagation()
|
|
5295
5484
|
}, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, "批量归档会话"), react.createElement("button", {
|
|
5296
5485
|
className: "vx-chip",
|
|
5297
5486
|
title: "关闭",
|
|
5487
|
+
"aria-label": "关闭批量归档",
|
|
5298
5488
|
onClick: () => setS({ batchModal: false })
|
|
5299
5489
|
}, react.createElement(Icon, {
|
|
5300
5490
|
n: "x",
|
|
@@ -5468,6 +5658,7 @@ window.__ModuleLoader__.load({
|
|
|
5468
5658
|
}), react.createElement("span", { className: "vx-panel-title" }, "个性化中心"), react.createElement("span", { className: "vx-panel-sub" }, "外观 · 效率 · 额度"), react.createElement("span", { className: "vx-flex1" }), react.createElement("button", {
|
|
5469
5659
|
className: "vx-chip",
|
|
5470
5660
|
title: "关闭",
|
|
5661
|
+
"aria-label": "关闭个性化面板",
|
|
5471
5662
|
onClick: () => setS({ panelOpen: false })
|
|
5472
5663
|
}, react.createElement(Icon, {
|
|
5473
5664
|
n: "x",
|
|
@@ -5511,6 +5702,7 @@ window.__ModuleLoader__.load({
|
|
|
5511
5702
|
})), react.createElement("button", {
|
|
5512
5703
|
className: "vx-chip",
|
|
5513
5704
|
title: "关闭",
|
|
5705
|
+
"aria-label": "关闭项目文件夹",
|
|
5514
5706
|
onClick: () => setS({ foldersOpen: false })
|
|
5515
5707
|
}, react.createElement(Icon, {
|
|
5516
5708
|
n: "x",
|
|
@@ -5526,8 +5718,8 @@ window.__ModuleLoader__.load({
|
|
|
5526
5718
|
return react.createElement("div", { className: "vx-settings-page" }, react.createElement(AppearanceTab, null), react.createElement("div", { className: "vx-section-title" }, "功能开关"), react.createElement(ToolsTab, null), react.createElement(MermaidTab, null));
|
|
5527
5719
|
}
|
|
5528
5720
|
function Toasts() {
|
|
5529
|
-
const
|
|
5530
|
-
return react.createElement("div", { className: "vx-toasts" },
|
|
5721
|
+
const toasts = useSSelector((state) => state.toasts);
|
|
5722
|
+
return react.createElement("div", { className: "vx-toasts" }, toasts.map((t) => react.createElement("div", {
|
|
5531
5723
|
key: t.id,
|
|
5532
5724
|
className: "vx-toast" + (t.kind === "error" ? " err" : "")
|
|
5533
5725
|
}, react.createElement(Icon, {
|
|
@@ -5809,7 +6001,7 @@ window.__ModuleLoader__.load({
|
|
|
5809
6001
|
syncAntiScroll(false);
|
|
5810
6002
|
} catch {}
|
|
5811
6003
|
try {
|
|
5812
|
-
|
|
6004
|
+
mermaidScanner.restore();
|
|
5813
6005
|
} catch {}
|
|
5814
6006
|
const d = typeof document !== "undefined" ? document : null;
|
|
5815
6007
|
if (d !== null) {
|