@alexpeng/dsh-custom-plugin 0.9.1 → 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 +34 -0
- package/README.i18n.yaml +2 -2
- package/README.md +3 -1
- package/README.zh.md +2 -1
- package/lib/client.js +454 -271
- 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,44 +3394,10 @@ window.__ModuleLoader__.load({
|
|
|
3117
3394
|
clearTimeout(watchdog);
|
|
3118
3395
|
}
|
|
3119
3396
|
}
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
ok: false,
|
|
3125
|
-
error: "引擎未就绪"
|
|
3126
|
-
};
|
|
3127
|
-
const id = "vx-mmd-" + Date.now() + Math.floor(Math.random() * 9999);
|
|
3128
|
-
try {
|
|
3129
|
-
mermaid.initialize({
|
|
3130
|
-
startOnLoad: false,
|
|
3131
|
-
theme: dark ? "dark" : "default",
|
|
3132
|
-
securityLevel: "strict",
|
|
3133
|
-
suppressErrorRendering: true
|
|
3134
|
-
});
|
|
3135
|
-
const out = await mermaid.render(id, code);
|
|
3136
|
-
const svg = typeof out === "string" ? out : out?.svg ?? "";
|
|
3137
|
-
if (svg === "") return {
|
|
3138
|
-
ok: false,
|
|
3139
|
-
error: "引擎未返回 SVG"
|
|
3140
|
-
};
|
|
3141
|
-
return {
|
|
3142
|
-
ok: true,
|
|
3143
|
-
svg
|
|
3144
|
-
};
|
|
3145
|
-
} catch (error) {
|
|
3146
|
-
return {
|
|
3147
|
-
ok: false,
|
|
3148
|
-
error: String(error?.message ?? error)
|
|
3149
|
-
};
|
|
3150
|
-
} finally {
|
|
3151
|
-
if (d !== null) for (const scratch of [
|
|
3152
|
-
id,
|
|
3153
|
-
"d" + id,
|
|
3154
|
-
"i" + id
|
|
3155
|
-
]) d.getElementById(scratch)?.remove();
|
|
3156
|
-
}
|
|
3157
|
-
}
|
|
3397
|
+
const mermaidScanner = createMermaidScanner({
|
|
3398
|
+
ensureMermaid,
|
|
3399
|
+
renderMermaid
|
|
3400
|
+
});
|
|
3158
3401
|
function extractMermaid(text) {
|
|
3159
3402
|
const out = [];
|
|
3160
3403
|
const re = /```mermaid\s*\n([\s\S]*?)```/gi;
|
|
@@ -3174,137 +3417,6 @@ window.__ModuleLoader__.load({
|
|
|
3174
3417
|
index: 0
|
|
3175
3418
|
} });
|
|
3176
3419
|
}
|
|
3177
|
-
/** Blocks with a render already in flight (WeakSet: dead blocks drop out). */
|
|
3178
|
-
const mmdInflight = /* @__PURE__ */ new WeakSet();
|
|
3179
|
-
/** Previous scan theme; a flip invalidates rendered-SVG memoization. */
|
|
3180
|
-
let mmdLastDark = null;
|
|
3181
|
-
/** The banner's language label: `.md-code-block > bannerWrap > banner >
|
|
3182
|
-
* infostring` is the GUI CodeBlock's stable shape (its CSS classes are
|
|
3183
|
-
* hashed, the structure is not). */
|
|
3184
|
-
function blockInfostring(block) {
|
|
3185
|
-
const info = block.querySelector(":scope > div:first-child > div:first-child > div:first-child");
|
|
3186
|
-
return info !== null ? info.textContent ?? "" : null;
|
|
3187
|
-
}
|
|
3188
|
-
/** Raw fence text: the GUI keeps unknown languages (mermaid among them) on
|
|
3189
|
-
* the plain `<pre><code>` path, so `pre` always carries the source. */
|
|
3190
|
-
function blockCodeText(block) {
|
|
3191
|
-
const pre = block.querySelector("pre");
|
|
3192
|
-
return pre !== null ? pre.textContent ?? "" : null;
|
|
3193
|
-
}
|
|
3194
|
-
/** Insert/refresh the diagram wrapper before one code block. Never moves
|
|
3195
|
-
* GUI-owned nodes — React keeps reconciling its tree; the block is only
|
|
3196
|
-
* visually swapped with the diagram stage via display. */
|
|
3197
|
-
async function renderInPlace(block, code, dark) {
|
|
3198
|
-
const key = mermaidCodeKey(code);
|
|
3199
|
-
const existingWrap = block.previousElementSibling;
|
|
3200
|
-
if (block.dataset.vxMmd === key && existingWrap !== null && existingWrap.classList.contains("vx-mmd-wrap")) return;
|
|
3201
|
-
if (!await ensureMermaid()) {
|
|
3202
|
-
block.dataset.vxMmdFail = key;
|
|
3203
|
-
return;
|
|
3204
|
-
}
|
|
3205
|
-
const r = await renderMermaid(code, dark);
|
|
3206
|
-
if (!r.ok) {
|
|
3207
|
-
block.dataset.vxMmdFail = key;
|
|
3208
|
-
return;
|
|
3209
|
-
}
|
|
3210
|
-
delete block.dataset.vxMmdFail;
|
|
3211
|
-
const d = typeof document !== "undefined" ? document : null;
|
|
3212
|
-
if (d === null) return;
|
|
3213
|
-
let wrap = block.previousElementSibling;
|
|
3214
|
-
if (wrap === null || !wrap.classList.contains("vx-mmd-wrap")) {
|
|
3215
|
-
wrap = d.createElement("div");
|
|
3216
|
-
wrap.className = "vx-mmd-wrap";
|
|
3217
|
-
block.parentElement?.insertBefore(wrap, block);
|
|
3218
|
-
const bar = d.createElement("div");
|
|
3219
|
-
bar.className = "vx-mmd-bar";
|
|
3220
|
-
const diagramBtn = d.createElement("button");
|
|
3221
|
-
diagramBtn.type = "button";
|
|
3222
|
-
diagramBtn.className = "vx-mmd-btn active";
|
|
3223
|
-
diagramBtn.textContent = "图表";
|
|
3224
|
-
const codeBtn = d.createElement("button");
|
|
3225
|
-
codeBtn.type = "button";
|
|
3226
|
-
codeBtn.className = "vx-mmd-btn";
|
|
3227
|
-
codeBtn.textContent = "代码";
|
|
3228
|
-
const live = d.createElement("a");
|
|
3229
|
-
live.className = "vx-mmd-live";
|
|
3230
|
-
live.target = "_blank";
|
|
3231
|
-
live.rel = "noopener noreferrer";
|
|
3232
|
-
live.textContent = "mermaid.live";
|
|
3233
|
-
mermaidLiveUrl(code).then((url) => {
|
|
3234
|
-
live.href = url;
|
|
3235
|
-
}).catch(() => {});
|
|
3236
|
-
bar.append(diagramBtn, codeBtn, live);
|
|
3237
|
-
const stage = d.createElement("div");
|
|
3238
|
-
stage.className = "vx-mmd-stage";
|
|
3239
|
-
wrap.append(bar, stage);
|
|
3240
|
-
const showDiagram = () => {
|
|
3241
|
-
stage.style.display = "";
|
|
3242
|
-
block.style.display = "none";
|
|
3243
|
-
diagramBtn.classList.add("active");
|
|
3244
|
-
codeBtn.classList.remove("active");
|
|
3245
|
-
};
|
|
3246
|
-
const showCode = () => {
|
|
3247
|
-
stage.style.display = "none";
|
|
3248
|
-
block.style.display = "";
|
|
3249
|
-
diagramBtn.classList.remove("active");
|
|
3250
|
-
codeBtn.classList.add("active");
|
|
3251
|
-
};
|
|
3252
|
-
diagramBtn.addEventListener("click", showDiagram);
|
|
3253
|
-
codeBtn.addEventListener("click", showCode);
|
|
3254
|
-
showDiagram();
|
|
3255
|
-
}
|
|
3256
|
-
const stage = wrap.querySelector(".vx-mmd-stage");
|
|
3257
|
-
if (stage === null) return;
|
|
3258
|
-
stage.innerHTML = r.svg;
|
|
3259
|
-
block.dataset.vxMmd = key;
|
|
3260
|
-
}
|
|
3261
|
-
/** Scan every chat code block and render the mermaid ones in place. */
|
|
3262
|
-
async function scanMermaidBlocks(dark) {
|
|
3263
|
-
const d = typeof document !== "undefined" ? document : null;
|
|
3264
|
-
if (d === null) return;
|
|
3265
|
-
for (const leftover of Array.from(d.querySelectorAll("body > div[id^=\"dvx-mmd-\"]"))) leftover.remove();
|
|
3266
|
-
for (const wrap of Array.from(d.querySelectorAll(".vx-mmd-wrap"))) {
|
|
3267
|
-
const next = wrap.nextElementSibling;
|
|
3268
|
-
if (next === null || !next.classList.contains("md-code-block")) wrap.remove();
|
|
3269
|
-
}
|
|
3270
|
-
for (const block of Array.from(d.querySelectorAll(".md-code-block"))) {
|
|
3271
|
-
if (mmdInflight.has(block)) continue;
|
|
3272
|
-
const codeRaw = blockCodeText(block);
|
|
3273
|
-
if (codeRaw === null) continue;
|
|
3274
|
-
const code = normalizeMermaidText(codeRaw).trim();
|
|
3275
|
-
if (code === "") continue;
|
|
3276
|
-
const key = mermaidCodeKey(code);
|
|
3277
|
-
const info = blockInfostring(block);
|
|
3278
|
-
if (info !== null && info.trim().toLowerCase() === "mermaid") {
|
|
3279
|
-
if (code.split("\n").filter((l) => l.trim() !== "").length < 2) continue;
|
|
3280
|
-
} else {
|
|
3281
|
-
if (!isGenericInfostring(info)) continue;
|
|
3282
|
-
if (!isMermaidCode(codeRaw)) continue;
|
|
3283
|
-
}
|
|
3284
|
-
if (block.dataset.vxMmd === key || block.dataset.vxMmdFail === key) continue;
|
|
3285
|
-
mmdInflight.add(block);
|
|
3286
|
-
try {
|
|
3287
|
-
await renderInPlace(block, code, dark);
|
|
3288
|
-
} finally {
|
|
3289
|
-
mmdInflight.delete(block);
|
|
3290
|
-
}
|
|
3291
|
-
}
|
|
3292
|
-
}
|
|
3293
|
-
/** Undo in-place rendering (feature toggled off): remove wrappers, unhide
|
|
3294
|
-
* code blocks. Diagram DOM is plugin-owned, so removal is safe. */
|
|
3295
|
-
function restoreMermaidBlocks() {
|
|
3296
|
-
const d = typeof document !== "undefined" ? document : null;
|
|
3297
|
-
if (d === null) return;
|
|
3298
|
-
for (const wrap of Array.from(d.querySelectorAll(".vx-mmd-wrap"))) {
|
|
3299
|
-
const next = wrap.nextElementSibling;
|
|
3300
|
-
if (next !== null && next.classList.contains("md-code-block")) next.style.display = "";
|
|
3301
|
-
wrap.remove();
|
|
3302
|
-
}
|
|
3303
|
-
for (const block of Array.from(d.querySelectorAll(".md-code-block"))) {
|
|
3304
|
-
delete block.dataset.vxMmd;
|
|
3305
|
-
delete block.dataset.vxMmdFail;
|
|
3306
|
-
}
|
|
3307
|
-
}
|
|
3308
3420
|
let balanceRetryTimer = null;
|
|
3309
3421
|
let balanceRetries = 0;
|
|
3310
3422
|
async function refreshBalance() {
|
|
@@ -3576,6 +3688,7 @@ window.__ModuleLoader__.load({
|
|
|
3576
3688
|
}, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, "提示词库"), react.createElement("button", {
|
|
3577
3689
|
className: "vx-chip",
|
|
3578
3690
|
title: "关闭",
|
|
3691
|
+
"aria-label": "关闭提示词面板",
|
|
3579
3692
|
onClick: () => setS({ promptOpen: null })
|
|
3580
3693
|
}, react.createElement(Icon, {
|
|
3581
3694
|
n: "x",
|
|
@@ -3597,40 +3710,65 @@ window.__ModuleLoader__.load({
|
|
|
3597
3710
|
}
|
|
3598
3711
|
function HeaderBalance(props) {
|
|
3599
3712
|
useViewedSession(props);
|
|
3600
|
-
const
|
|
3601
|
-
|
|
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);
|
|
3602
3718
|
react.useEffect(() => {
|
|
3603
3719
|
if (S.balance === null) refreshBalance();
|
|
3604
|
-
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;
|
|
3605
3727
|
refreshBalance();
|
|
3606
|
-
}
|
|
3728
|
+
};
|
|
3729
|
+
if (typeof document !== "undefined") document.addEventListener("visibilitychange", onVisibility);
|
|
3607
3730
|
return () => {
|
|
3608
3731
|
clearInterval(timer);
|
|
3732
|
+
if (typeof document !== "undefined") document.removeEventListener("visibilitychange", onVisibility);
|
|
3609
3733
|
};
|
|
3610
3734
|
}, []);
|
|
3611
|
-
const usageToday =
|
|
3612
|
-
const calls = Object.keys(usageToday).reduce((n, k) => n + (usageToday[k].calls ?? 0), 0);
|
|
3613
|
-
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]);
|
|
3614
3738
|
const bal = b?.ok === true && b.balance !== null && b.balance !== void 0 ? b.balance : null;
|
|
3615
3739
|
const keyConfigured = b?.ok === false && b.keyConfigured === true;
|
|
3616
3740
|
const balance = bal !== null ? (bal.currency ?? "CNY") === "CNY" ? "¥" + (bal.total ?? "") : `${bal.total ?? ""} ${bal.currency ?? ""}` : keyConfigured ? "额度" : b === null ? "额度…" : `≈¥${estimate.toFixed(2)}`;
|
|
3617
3741
|
const estimateTitle = `按本机 token 用量与官方价目表折算的估算值(${DEEPSEEK_PRICING_CHECKED_ON} 核对),非账号账单;配置 API Key 后显示真实余额`;
|
|
3618
3742
|
const balanceError = keyConfigured && b?.ok === false ? String(b.error ?? "未知错误") : null;
|
|
3619
3743
|
const pillTitle = bal !== null ? void 0 : balanceError !== null ? `余额查询失败:${balanceError}(失败后会自动重试,也可在面板中手动刷新)` : b === null ? void 0 : estimateTitle;
|
|
3620
|
-
const
|
|
3744
|
+
const togglePanel = () => setS({
|
|
3745
|
+
balanceOpen: !open,
|
|
3746
|
+
panelOpen: false,
|
|
3747
|
+
promptOpen: null,
|
|
3748
|
+
foldersOpen: false
|
|
3749
|
+
});
|
|
3621
3750
|
return react.createElement("span", { className: "vx-balance-wrap" }, react.createElement("span", {
|
|
3622
3751
|
className: "vx-balance-text" + (open ? " vx-balance-open" : ""),
|
|
3752
|
+
role: "button",
|
|
3753
|
+
tabIndex: 0,
|
|
3754
|
+
"aria-expanded": open,
|
|
3755
|
+
"aria-haspopup": "dialog",
|
|
3623
3756
|
title: open ? "再次点击收起面板" : "点击打开面板",
|
|
3624
|
-
onClick:
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3757
|
+
onClick: togglePanel,
|
|
3758
|
+
onKeyDown: (e) => {
|
|
3759
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
3760
|
+
e.preventDefault();
|
|
3761
|
+
togglePanel();
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3630
3764
|
}, react.createElement(Icon, {
|
|
3631
3765
|
n: "wallet",
|
|
3632
3766
|
size: 13
|
|
3633
|
-
}), 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);
|
|
3634
3772
|
}
|
|
3635
3773
|
function UsageTable() {
|
|
3636
3774
|
const day = useS().usage[dayKey()] ?? {};
|
|
@@ -3807,7 +3945,7 @@ window.__ModuleLoader__.load({
|
|
|
3807
3945
|
}
|
|
3808
3946
|
function QuoteDock(props) {
|
|
3809
3947
|
useViewedSession(props);
|
|
3810
|
-
const
|
|
3948
|
+
const quoteEnabled = useSSelector((state) => state.cfg.quote === true);
|
|
3811
3949
|
const inputRef = react.useRef(props.input);
|
|
3812
3950
|
inputRef.current = props.input;
|
|
3813
3951
|
const actionsRef = react.useRef(props.inputActions);
|
|
@@ -3830,7 +3968,7 @@ window.__ModuleLoader__.load({
|
|
|
3830
3968
|
};
|
|
3831
3969
|
}, []);
|
|
3832
3970
|
react.useEffect(() => {
|
|
3833
|
-
if (
|
|
3971
|
+
if (!quoteEnabled) {
|
|
3834
3972
|
if (S.quoteSel !== null) setS({ quoteSel: null });
|
|
3835
3973
|
return;
|
|
3836
3974
|
}
|
|
@@ -3874,13 +4012,13 @@ window.__ModuleLoader__.load({
|
|
|
3874
4012
|
};
|
|
3875
4013
|
d.addEventListener("selectionchange", onSel);
|
|
3876
4014
|
return () => d.removeEventListener("selectionchange", onSel);
|
|
3877
|
-
}, [
|
|
4015
|
+
}, [quoteEnabled]);
|
|
3878
4016
|
return null;
|
|
3879
4017
|
}
|
|
3880
4018
|
function QuoteButton() {
|
|
3881
|
-
const
|
|
3882
|
-
if (
|
|
3883
|
-
const q =
|
|
4019
|
+
const quoteSel = useSSelector((state) => state.quoteSel);
|
|
4020
|
+
if (quoteSel === null) return null;
|
|
4021
|
+
const q = quoteSel;
|
|
3884
4022
|
const fmt = q.text.split("\n").map((l) => "> " + l).join("\n");
|
|
3885
4023
|
return react.createElement("button", {
|
|
3886
4024
|
className: "vx-quote-btn",
|
|
@@ -4825,6 +4963,7 @@ window.__ModuleLoader__.load({
|
|
|
4825
4963
|
react.useEffect(() => {
|
|
4826
4964
|
if (s.ask !== null) setVal(s.ask.value ?? "");
|
|
4827
4965
|
}, [s.ask?.title]);
|
|
4966
|
+
const dialogRef = useDialogFocus(() => setS({ ask: null }));
|
|
4828
4967
|
const ask = s.ask;
|
|
4829
4968
|
if (ask === null) return null;
|
|
4830
4969
|
const submit = () => {
|
|
@@ -4838,6 +4977,11 @@ window.__ModuleLoader__.load({
|
|
|
4838
4977
|
}, react.createElement("div", {
|
|
4839
4978
|
className: "vx-glass vx-modal",
|
|
4840
4979
|
style: { width: "min(360px, 92vw)" },
|
|
4980
|
+
role: "dialog",
|
|
4981
|
+
"aria-modal": true,
|
|
4982
|
+
"aria-label": ask.title,
|
|
4983
|
+
tabIndex: -1,
|
|
4984
|
+
ref: dialogRef,
|
|
4841
4985
|
onClick: (e) => e.stopPropagation()
|
|
4842
4986
|
}, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, ask.title)), react.createElement("input", {
|
|
4843
4987
|
className: "vx-input",
|
|
@@ -4856,32 +5000,43 @@ window.__ModuleLoader__.load({
|
|
|
4856
5000
|
}, "取消"))));
|
|
4857
5001
|
}
|
|
4858
5002
|
function ConfirmModal() {
|
|
4859
|
-
const
|
|
4860
|
-
if (s.confirmAsk === null) return null;
|
|
4861
|
-
const c = s.confirmAsk;
|
|
5003
|
+
const c = useS().confirmAsk;
|
|
4862
5004
|
const answer = (ok) => {
|
|
5005
|
+
if (c === null) return;
|
|
4863
5006
|
const cb = c.cb;
|
|
4864
5007
|
setS({ confirmAsk: null });
|
|
4865
5008
|
cb(ok);
|
|
4866
5009
|
};
|
|
5010
|
+
const dialogRef = useDialogFocus(() => answer(false));
|
|
5011
|
+
if (c === null) return null;
|
|
4867
5012
|
return react.createElement("div", {
|
|
4868
5013
|
className: "vx-modal-mask",
|
|
4869
5014
|
onClick: () => answer(false)
|
|
4870
5015
|
}, react.createElement("div", {
|
|
4871
5016
|
className: "vx-glass vx-modal",
|
|
4872
5017
|
style: { width: "min(380px, 92vw)" },
|
|
5018
|
+
role: "dialog",
|
|
5019
|
+
"aria-modal": true,
|
|
5020
|
+
"aria-label": "确认操作",
|
|
5021
|
+
tabIndex: -1,
|
|
5022
|
+
ref: dialogRef,
|
|
4873
5023
|
onClick: (e) => e.stopPropagation()
|
|
4874
5024
|
}, react.createElement("div", { className: "vx-pad" }, c.message), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement("button", {
|
|
4875
5025
|
className: "vx-btn vx-btn-danger",
|
|
4876
5026
|
onClick: () => answer(true)
|
|
4877
5027
|
}, "确定"), react.createElement("button", {
|
|
4878
5028
|
className: "vx-btn",
|
|
5029
|
+
autoFocus: true,
|
|
4879
5030
|
onClick: () => answer(false)
|
|
4880
5031
|
}, "取消"))));
|
|
4881
5032
|
}
|
|
4882
5033
|
function TemplateModal() {
|
|
4883
5034
|
const s = useS();
|
|
4884
5035
|
const prompt = s.templatePrompt;
|
|
5036
|
+
const dialogRef = useDialogFocus(() => setS({
|
|
5037
|
+
templatePrompt: null,
|
|
5038
|
+
templateValues: {}
|
|
5039
|
+
}));
|
|
4885
5040
|
if (prompt === null) return null;
|
|
4886
5041
|
const names = promptVariables(prompt.text);
|
|
4887
5042
|
const submit = () => {
|
|
@@ -4916,6 +5071,11 @@ window.__ModuleLoader__.load({
|
|
|
4916
5071
|
}, react.createElement("div", {
|
|
4917
5072
|
className: "vx-glass vx-modal",
|
|
4918
5073
|
style: { width: "min(440px, 92vw)" },
|
|
5074
|
+
role: "dialog",
|
|
5075
|
+
"aria-modal": true,
|
|
5076
|
+
"aria-label": `填写变量 · ${prompt.name}`,
|
|
5077
|
+
tabIndex: -1,
|
|
5078
|
+
ref: dialogRef,
|
|
4919
5079
|
onClick: (e) => e.stopPropagation()
|
|
4920
5080
|
}, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, `填写变量 · ${prompt.name}`)), names.map((name) => react.createElement("label", {
|
|
4921
5081
|
key: name,
|
|
@@ -4939,12 +5099,13 @@ window.__ModuleLoader__.load({
|
|
|
4939
5099
|
}, "取消"))));
|
|
4940
5100
|
}
|
|
4941
5101
|
function MermaidInPlace() {
|
|
4942
|
-
const
|
|
4943
|
-
|
|
4944
|
-
|
|
5102
|
+
const { enabled, dark } = useSSelector((state) => ({
|
|
5103
|
+
enabled: state.cfg.mermaid === true,
|
|
5104
|
+
dark: state.dark === true
|
|
5105
|
+
}), shallowEqual);
|
|
4945
5106
|
react.useEffect(() => {
|
|
4946
5107
|
if (!enabled) {
|
|
4947
|
-
|
|
5108
|
+
mermaidScanner.restore();
|
|
4948
5109
|
return;
|
|
4949
5110
|
}
|
|
4950
5111
|
const d = typeof document !== "undefined" ? document : null;
|
|
@@ -4953,14 +5114,12 @@ window.__ModuleLoader__.load({
|
|
|
4953
5114
|
let timer = null;
|
|
4954
5115
|
let stopped = false;
|
|
4955
5116
|
const scan = () => {
|
|
4956
|
-
if (!stopped)
|
|
5117
|
+
if (!stopped) mermaidScanner.scan(dark);
|
|
4957
5118
|
};
|
|
4958
5119
|
const schedule = () => {
|
|
4959
5120
|
if (timer !== null) clearTimeout(timer);
|
|
4960
5121
|
timer = setTimeout(scan, 400);
|
|
4961
5122
|
};
|
|
4962
|
-
if (mmdLastDark !== null && mmdLastDark !== dark) for (const block of Array.from(d.querySelectorAll(".md-code-block"))) delete block.dataset.vxMmd;
|
|
4963
|
-
mmdLastDark = dark;
|
|
4964
5123
|
scan();
|
|
4965
5124
|
const observer = new MutationObserver(schedule);
|
|
4966
5125
|
observer.observe(d.body, {
|
|
@@ -4985,6 +5144,7 @@ window.__ModuleLoader__.load({
|
|
|
4985
5144
|
const [err, setErr] = react.useState(null);
|
|
4986
5145
|
const [loading, setLoading] = react.useState(false);
|
|
4987
5146
|
const [liveUrl, setLiveUrl] = react.useState("#");
|
|
5147
|
+
const dialogRef = useDialogFocus(() => setS({ mermaidModal: null }));
|
|
4988
5148
|
react.useEffect(() => {
|
|
4989
5149
|
if (mm === null) return;
|
|
4990
5150
|
let alive = true;
|
|
@@ -5018,10 +5178,16 @@ window.__ModuleLoader__.load({
|
|
|
5018
5178
|
onClick: () => setS({ mermaidModal: null })
|
|
5019
5179
|
}, react.createElement("div", {
|
|
5020
5180
|
className: "vx-glass vx-modal",
|
|
5181
|
+
role: "dialog",
|
|
5182
|
+
"aria-modal": true,
|
|
5183
|
+
"aria-label": "Mermaid 图表",
|
|
5184
|
+
tabIndex: -1,
|
|
5185
|
+
ref: dialogRef,
|
|
5021
5186
|
onClick: (e) => e.stopPropagation()
|
|
5022
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", {
|
|
5023
5188
|
className: "vx-chip",
|
|
5024
5189
|
title: "上一个",
|
|
5190
|
+
"aria-label": "上一个图表",
|
|
5025
5191
|
onClick: () => setS({ mermaidModal: {
|
|
5026
5192
|
...mm,
|
|
5027
5193
|
index: (mm.index + mm.codes.length - 1) % mm.codes.length
|
|
@@ -5033,6 +5199,7 @@ window.__ModuleLoader__.load({
|
|
|
5033
5199
|
})) : null, mm.codes.length > 1 ? react.createElement("button", {
|
|
5034
5200
|
className: "vx-chip",
|
|
5035
5201
|
title: "下一个",
|
|
5202
|
+
"aria-label": "下一个图表",
|
|
5036
5203
|
onClick: () => setS({ mermaidModal: {
|
|
5037
5204
|
...mm,
|
|
5038
5205
|
index: (mm.index + 1) % mm.codes.length
|
|
@@ -5048,6 +5215,7 @@ window.__ModuleLoader__.load({
|
|
|
5048
5215
|
}, "在 mermaid.live 打开"), react.createElement("button", {
|
|
5049
5216
|
className: "vx-chip",
|
|
5050
5217
|
title: "关闭",
|
|
5218
|
+
"aria-label": "关闭图表",
|
|
5051
5219
|
onClick: () => setS({ mermaidModal: null })
|
|
5052
5220
|
}, react.createElement(Icon, {
|
|
5053
5221
|
n: "x",
|
|
@@ -5067,6 +5235,7 @@ window.__ModuleLoader__.load({
|
|
|
5067
5235
|
const [index, setIndex] = react.useState(0);
|
|
5068
5236
|
const [remote, setRemote] = react.useState([]);
|
|
5069
5237
|
const [remoteStatus, setRemoteStatus] = react.useState("");
|
|
5238
|
+
const dialogRef = useDialogFocus(() => setS({ commandOpen: false }));
|
|
5070
5239
|
react.useEffect(() => {
|
|
5071
5240
|
if (!s.commandOpen || query.trim().length < 2) {
|
|
5072
5241
|
setRemote([]);
|
|
@@ -5233,6 +5402,11 @@ window.__ModuleLoader__.load({
|
|
|
5233
5402
|
}, react.createElement("div", {
|
|
5234
5403
|
className: "vx-glass vx-modal",
|
|
5235
5404
|
style: { width: "min(620px, 94vw)" },
|
|
5405
|
+
role: "dialog",
|
|
5406
|
+
"aria-modal": true,
|
|
5407
|
+
"aria-label": "命令面板",
|
|
5408
|
+
tabIndex: -1,
|
|
5409
|
+
ref: dialogRef,
|
|
5236
5410
|
onClick: (e) => e.stopPropagation()
|
|
5237
5411
|
}, react.createElement("input", {
|
|
5238
5412
|
className: "vx-input",
|
|
@@ -5268,6 +5442,7 @@ window.__ModuleLoader__.load({
|
|
|
5268
5442
|
useS();
|
|
5269
5443
|
const [sel, setSel] = react.useState({});
|
|
5270
5444
|
const [q, setQ] = react.useState("");
|
|
5445
|
+
const dialogRef = useDialogFocus(() => setS({ batchModal: false }));
|
|
5271
5446
|
const sessions = useSessionsSafe(props);
|
|
5272
5447
|
const ids = sessions !== null ? sessions.ids ?? [] : [];
|
|
5273
5448
|
const byId = sessions !== null ? sessions.byId : {};
|
|
@@ -5300,10 +5475,16 @@ window.__ModuleLoader__.load({
|
|
|
5300
5475
|
}, react.createElement("div", {
|
|
5301
5476
|
className: "vx-glass vx-modal",
|
|
5302
5477
|
style: { width: "min(560px, 92vw)" },
|
|
5478
|
+
role: "dialog",
|
|
5479
|
+
"aria-modal": true,
|
|
5480
|
+
"aria-label": "批量归档会话",
|
|
5481
|
+
tabIndex: -1,
|
|
5482
|
+
ref: dialogRef,
|
|
5303
5483
|
onClick: (e) => e.stopPropagation()
|
|
5304
5484
|
}, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, "批量归档会话"), react.createElement("button", {
|
|
5305
5485
|
className: "vx-chip",
|
|
5306
5486
|
title: "关闭",
|
|
5487
|
+
"aria-label": "关闭批量归档",
|
|
5307
5488
|
onClick: () => setS({ batchModal: false })
|
|
5308
5489
|
}, react.createElement(Icon, {
|
|
5309
5490
|
n: "x",
|
|
@@ -5477,6 +5658,7 @@ window.__ModuleLoader__.load({
|
|
|
5477
5658
|
}), react.createElement("span", { className: "vx-panel-title" }, "个性化中心"), react.createElement("span", { className: "vx-panel-sub" }, "外观 · 效率 · 额度"), react.createElement("span", { className: "vx-flex1" }), react.createElement("button", {
|
|
5478
5659
|
className: "vx-chip",
|
|
5479
5660
|
title: "关闭",
|
|
5661
|
+
"aria-label": "关闭个性化面板",
|
|
5480
5662
|
onClick: () => setS({ panelOpen: false })
|
|
5481
5663
|
}, react.createElement(Icon, {
|
|
5482
5664
|
n: "x",
|
|
@@ -5520,6 +5702,7 @@ window.__ModuleLoader__.load({
|
|
|
5520
5702
|
})), react.createElement("button", {
|
|
5521
5703
|
className: "vx-chip",
|
|
5522
5704
|
title: "关闭",
|
|
5705
|
+
"aria-label": "关闭项目文件夹",
|
|
5523
5706
|
onClick: () => setS({ foldersOpen: false })
|
|
5524
5707
|
}, react.createElement(Icon, {
|
|
5525
5708
|
n: "x",
|
|
@@ -5535,8 +5718,8 @@ window.__ModuleLoader__.load({
|
|
|
5535
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));
|
|
5536
5719
|
}
|
|
5537
5720
|
function Toasts() {
|
|
5538
|
-
const
|
|
5539
|
-
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", {
|
|
5540
5723
|
key: t.id,
|
|
5541
5724
|
className: "vx-toast" + (t.kind === "error" ? " err" : "")
|
|
5542
5725
|
}, react.createElement(Icon, {
|
|
@@ -5818,7 +6001,7 @@ window.__ModuleLoader__.load({
|
|
|
5818
6001
|
syncAntiScroll(false);
|
|
5819
6002
|
} catch {}
|
|
5820
6003
|
try {
|
|
5821
|
-
|
|
6004
|
+
mermaidScanner.restore();
|
|
5822
6005
|
} catch {}
|
|
5823
6006
|
const d = typeof document !== "undefined" ? document : null;
|
|
5824
6007
|
if (d !== null) {
|