wi-chat 0.6.2 → 0.7.0

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.
Files changed (78) hide show
  1. package/dist/core/index.cjs +1 -1
  2. package/dist/core/index.d.ts +12 -0
  3. package/dist/core/index.js +731 -328
  4. package/dist/core/useAnswerActions.d.ts +61 -0
  5. package/dist/core/useChat.d.ts +29 -3
  6. package/dist/core/useChatAuth.d.ts +96 -0
  7. package/dist/core/useChatRooms.d.ts +66 -0
  8. package/dist/core/useKeepAlive.d.ts +41 -0
  9. package/dist/core/useLlm.d.ts +73 -0
  10. package/dist/core/useRunningGroups.d.ts +58 -0
  11. package/dist/index.cjs +1 -1
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.js +119 -108
  14. package/dist/mobile-ui/chat/ChatContainer.vue.d.ts +2 -2
  15. package/dist/mobile-ui/inputbox/Inputbox.vue.d.ts +1 -1
  16. package/dist/parser/answerCom/generic/parseGeneric.d.ts +52 -0
  17. package/dist/parser/answerCom/generic/types.d.ts +75 -0
  18. package/dist/parser/answerCom/outputFile/parseOutputFile.d.ts +7 -6
  19. package/dist/parser/answerCom/outputFile/types.d.ts +15 -5
  20. package/dist/parser/answerCom/presentFiles/parsePresentFiles.d.ts +58 -0
  21. package/dist/parser/answerCom/presentFiles/types.d.ts +27 -0
  22. package/dist/parser/answerMeta.d.ts +71 -0
  23. package/dist/parser/deepThinking/parseDeepThinking.d.ts +8 -0
  24. package/dist/parser/history/history.d.ts +9 -0
  25. package/dist/parser/history/index.d.ts +1 -1
  26. package/dist/parser/index.cjs +6 -2
  27. package/dist/parser/index.d.ts +11 -2
  28. package/dist/parser/index.js +591 -366
  29. package/dist/parser/message.d.ts +9 -0
  30. package/dist/parser/runTime.d.ts +29 -0
  31. package/dist/renderers/TextAnswer-BgKGvG_o.cjs +2 -0
  32. package/dist/renderers/TextAnswer-PQwV3K7v.js +5 -0
  33. package/dist/renderers/answerCard/AnswerCard.vue.d.ts +65 -0
  34. package/dist/renderers/answerCard/AnswerToolbar.vue.d.ts +42 -0
  35. package/dist/renderers/answerConfig.d.ts +33 -0
  36. package/dist/renderers/deviceLastValue/DeviceLastValue.vue.d.ts +37 -0
  37. package/dist/renderers/index.cjs +6 -1
  38. package/dist/renderers/index.d.ts +14 -0
  39. package/dist/renderers/index.js +1485 -574
  40. package/dist/renderers/media/MediaAnswer.vue.d.ts +19 -0
  41. package/dist/renderers/outputFile/OutputFileLink.vue.d.ts +19 -0
  42. package/dist/renderers/outputFile/localFile.d.ts +46 -0
  43. package/dist/renderers/outputFile/useOutputFile.d.ts +32 -3
  44. package/dist/renderers/presentFiles/PresentFiles.vue.d.ts +19 -0
  45. package/dist/renderers/recordset/RecordsetView.vue.d.ts +19 -0
  46. package/dist/renderers/sqlQuery/SqlQuery.vue.d.ts +19 -0
  47. package/dist/renderers/style.css +1 -1
  48. package/dist/renderers/text/TextAnswer.vue.d.ts +19 -0
  49. package/dist/request/api.d.ts +121 -1
  50. package/dist/request/client.d.ts +6 -0
  51. package/dist/request/index.cjs +4 -2
  52. package/dist/request/index.d.ts +4 -2
  53. package/dist/request/index.js +753 -173
  54. package/dist/request/ws.d.ts +11 -86
  55. package/dist/request/wsCore.d.ts +104 -0
  56. package/dist/request/wsSession.d.ts +353 -0
  57. package/dist/right-panel/RightPanelTabs.vue.d.ts +4 -0
  58. package/dist/right-panel/index.cjs +1 -1
  59. package/dist/right-panel/index.d.ts +1 -1
  60. package/dist/right-panel/index.js +598 -499
  61. package/dist/right-panel/style.css +1 -1
  62. package/dist/right-panel/types.d.ts +10 -0
  63. package/dist/tools/index.cjs +5 -5
  64. package/dist/tools/index.d.ts +2 -2
  65. package/dist/tools/index.js +323 -208
  66. package/dist/tools/markdown/index.d.ts +2 -0
  67. package/dist/tools/markdown/interactions.d.ts +39 -0
  68. package/dist/tools/markdown/sanitize.d.ts +6 -0
  69. package/dist/tools/style.css +1 -1
  70. package/dist/web-ui/attach/AttachmentCard.vue.d.ts +1 -1
  71. package/dist/web-ui/attach/AttachmentList.vue.d.ts +1 -1
  72. package/dist/web-ui/chat/ChatContainer.vue.d.ts +5 -5
  73. package/dist/web-ui/envswitch/EnvSwitch.vue.d.ts +1 -1
  74. package/dist/web-ui/index.cjs +1 -1
  75. package/dist/web-ui/index.js +1 -1
  76. package/dist/web-ui/inputbox/Inputbox.vue.d.ts +5 -5
  77. package/dist/web-ui/style.css +1 -1
  78. package/package.json +2 -2
@@ -1,34 +1,49 @@
1
1
  import "wi-chat/style.css";
2
- import { createVNode as j, render as E, defineComponent as I, ref as B, computed as q, onBeforeUnmount as F, openBlock as G, createElementBlock as N, unref as z, watch as J, getCurrentInstance as Z, onUnmounted as V, nextTick as M } from "vue";
3
- import { resolveAttachDownloadUrl as X } from "wi-chat/parser";
4
- import { consumeStream as Le } from "wi-chat/parser";
5
- import { katex as Y } from "@mdit/plugin-katex";
6
- import D from "highlight.js";
7
- import A from "markdown-it";
8
- const C = (e) => new A().utils.escapeHtml(e), $ = (e) => C(e).replace(/"/g, """).replace(/'/g, "'"), K = (e) => !e || e.includes("get_image_full") ? e : e.replace("get_image", "get_image_full"), P = (e) => {
9
- const { langPrefix: t = "language-", imagePreview: o = !0, showCodeLang: n = !0, imageSrcResolver: d, imageDownload: l = !0, tableDownload: r = !0 } = e, a = '<button type="button" class="wi-md-table-download" title="下载 Excel" aria-label="下载表格为 Excel"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg></button>', i = new A({
2
+ import { createVNode as q, render as B, defineComponent as F, ref as O, watch as $, onMounted as N, onBeforeUnmount as G, openBlock as z, createElementBlock as J, unref as V, getCurrentInstance as Y, onUnmounted as Z, nextTick as P } from "vue";
3
+ import { resolveAttachDownloadUrl as W } from "wi-chat/parser";
4
+ import { consumeStream as Me } from "wi-chat/parser";
5
+ import { katex as X } from "@mdit/plugin-katex";
6
+ import U from "highlight.js";
7
+ import I from "markdown-it";
8
+ import K from "dompurify";
9
+ const A = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"), Q = (e) => {
10
+ if (!e) return e;
11
+ if (typeof window > "u") return A(e);
12
+ try {
13
+ const n = K(window);
14
+ return !n.isSupported || !n.sanitize('<div class="wi-probe"><span>ok</span></div>').includes("wi-probe") ? A(e) : n.sanitize(e, {
15
+ FORCE_BODY: !0,
16
+ ADD_TAGS: ["style"],
17
+ ADD_ATTR: ["rel", "target"],
18
+ FORBID_TAGS: ["iframe", "object", "embed", "base", "link"]
19
+ });
20
+ } catch {
21
+ return A(e);
22
+ }
23
+ }, R = (e) => new I().utils.escapeHtml(e), E = (e) => R(e).replace(/"/g, "&quot;").replace(/'/g, "&#39;"), ee = (e) => !e || e.includes("get_image_full") ? e : e.replace("get_image", "get_image_full"), j = (e) => {
24
+ const { langPrefix: n = "language-", imagePreview: r = !0, showCodeLang: o = !0, imageSrcResolver: s, imageDownload: i = !0, tableDownload: t = !0 } = e, l = '<button type="button" class="wi-md-table-download" title="下载 Excel" aria-label="下载表格为 Excel"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg></button>', a = new I({
10
25
  linkify: !0,
11
26
  typographer: !0,
12
27
  breaks: !0,
13
28
  html: !0,
14
- langPrefix: t,
29
+ langPrefix: n,
15
30
  highlight: (c, u) => {
16
- if (u && D.getLanguage(u))
31
+ if (u && U.getLanguage(u))
17
32
  try {
18
- return D.highlight(c, { language: u }).value;
33
+ return U.highlight(c, { language: u }).value;
19
34
  } catch {
20
- return C(c);
35
+ return R(c);
21
36
  }
22
- return C(c);
37
+ return R(c);
23
38
  }
24
- }).use(Y, { delimiters: "dollars" });
25
- return i.renderer.rules.fence = (c, u, m, b, f) => {
26
- var v;
27
- const h = c[u], p = h.info.trim().split(/\s+/)[0].toLowerCase(), y = ((v = m.highlight) == null ? void 0 : v.call(m, h.content, p, "")) || C(h.content);
39
+ }).use(X, { delimiters: "dollars" });
40
+ return a.renderer.rules.fence = (c, u, w, k, h) => {
41
+ var p;
42
+ const b = c[u], g = b.info.trim().split(/\s+/)[0].toLowerCase(), v = ((p = w.highlight) == null ? void 0 : p.call(w, b.content, g, "")) || R(b.content);
28
43
  return `
29
44
  <div class="wi-md-block">
30
- <div class="wi-md-block-header">
31
- <div class="wi-md-block-header-left">${n && p ? `<span class="wi-md-lang">${C(p)}</span>` : ""}</div>
45
+ <div class="wi-md-block-header" tabindex="0" aria-expanded="true" title="点击折叠 / 展开">
46
+ <div class="wi-md-block-header-left">${o && g ? `<span class="wi-md-lang">${R(g)}</span>` : ""}</div>
32
47
  <div class="wi-md-block-header-right">
33
48
  <button type="button" class="wi-md-copy" title="复制" aria-label="复制代码">
34
49
  <svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Zm5-5C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"/></svg>
@@ -38,240 +53,340 @@ const C = (e) => new A().utils.escapeHtml(e), $ = (e) => C(e).replace(/"/g, "&qu
38
53
  </button>
39
54
  </div>
40
55
  </div>
41
- <pre class="wi-md-code"><code class="${m.langPrefix}${C(p)}">${y}</code></pre>
56
+ <pre class="wi-md-code"><code class="${w.langPrefix}${R(g)}">${v}</code></pre>
42
57
  </div>
43
58
  `.trim();
44
- }, i.renderer.rules.table_open = () => r ? '<div class="wi-md-table-wrap"><table class="wi-md-table">' : '<table class="wi-md-table">', i.renderer.rules.table_close = () => r ? `</table>${a}</div>` : "</table>", i.renderer.rules.ordered_list_open = (c, u, m, b, f) => (c[u].attrJoin("class", "wi-md-list wi-md-list-ordered"), f.renderToken(c, u, m)), i.renderer.rules.bullet_list_open = (c, u, m, b, f) => (c[u].attrJoin("class", "wi-md-list wi-md-list-bullet"), f.renderToken(c, u, m)), i.renderer.rules.list_item_open = (c, u, m, b, f) => (c[u].attrJoin("class", "wi-md-list-item"), f.renderToken(c, u, m)), i.renderer.rules.image = (c, u, m, b, f) => {
45
- const h = c[u], p = h.attrGet("src") || "", y = h.attrGet("alt") || h.content || "", k = h.attrGet("title") || "", v = [
46
- `src="${$(p)}"`,
47
- `alt="${$(y)}"`,
48
- k ? `title="${$(k)}"` : ""
59
+ }, a.renderer.rules.table_open = () => t ? '<div class="wi-md-table-wrap"><table class="wi-md-table">' : '<table class="wi-md-table">', a.renderer.rules.table_close = () => t ? `</table>${l}</div>` : "</table>", a.renderer.rules.ordered_list_open = (c, u, w, k, h) => (c[u].attrJoin("class", "wi-md-list wi-md-list-ordered"), h.renderToken(c, u, w)), a.renderer.rules.bullet_list_open = (c, u, w, k, h) => (c[u].attrJoin("class", "wi-md-list wi-md-list-bullet"), h.renderToken(c, u, w)), a.renderer.rules.list_item_open = (c, u, w, k, h) => (c[u].attrJoin("class", "wi-md-list-item"), h.renderToken(c, u, w)), a.renderer.rules.image = (c, u, w, k, h) => {
60
+ const b = c[u], g = b.attrGet("src") || "", v = b.attrGet("alt") || b.content || "", f = b.attrGet("title") || "", p = [
61
+ `src="${E(g)}"`,
62
+ `alt="${E(v)}"`,
63
+ f ? `title="${E(f)}"` : ""
49
64
  ].filter(Boolean).join(" ");
50
- if (!o) return `<img ${v} />`;
51
- const S = d ? d(p) : K(p), w = l ? '<span class="wi-md-image-download" title="下载图片" role="button" aria-label="下载图片"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg></span>' : "";
52
- return `<span class="wi-md-image-wrap" data-src="${$(S)}"><img ${v} loading="lazy" />${w}</span>`;
53
- }, i;
54
- }, Q = ".wi-markdown";
55
- let W = 0;
56
- const ee = () => {
57
- const e = "data-wi-md-scope", t = `wi-md-scope-${++W}`;
58
- return { attr: e, id: t, selector: `[${e}="${t}"]` };
59
- }, te = /^(background|padding|margin|width|height|min-width|min-height|max-width|max-height|overflow|display|position|inset|top|right|bottom|left|border|box-shadow|flex|gap|justify-content|align-items)/i, oe = (e) => e.replace(/(^|[{};,])(\s*)(?:html|body|:root)(?![\w-])\s*\{([^}]*)\}/gi, (t, o, n, d) => {
60
- const l = d.split(";").map((r) => r.trim()).filter((r) => r && !te.test(r)).join(";");
61
- return l ? `${o}${n}:scope{${l}}` : "";
62
- }), ne = (e, t) => {
63
- const o = [];
64
- let n = e.replace(/<style\b([^>]*)>([\s\S]*?)<\/style\s*>/gi, (d, l, r) => {
65
- const a = /^\s*@scope\b/i.test(r) ? `<style${l}>${r}</style>` : `<style${l}>@scope (${t}) {${oe(r)}}</style>`;
66
- return o.push(a), `\0wi-md-style-${o.length - 1}\0`;
65
+ if (!r) return `<img ${p} />`;
66
+ const m = s ? s(g) : ee(g), S = i ? '<span class="wi-md-image-download" title="下载图片" role="button" aria-label="下载图片"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg></span>' : "";
67
+ return `<span class="wi-md-image-wrap" data-src="${E(m)}"><img ${p} loading="lazy" />${S}</span>`;
68
+ }, a;
69
+ }, te = ".wi-markdown";
70
+ let oe = 0;
71
+ const ne = () => {
72
+ const e = "data-wi-md-scope", n = `wi-md-scope-${++oe}`;
73
+ return { attr: e, id: n, selector: `[${e}="${n}"]` };
74
+ }, re = /^(background|padding|margin|width|height|min-width|min-height|max-width|max-height|overflow|display|position|inset|top|right|bottom|left|border|box-shadow|flex|gap|justify-content|align-items)/i, le = (e) => e.replace(/(^|[{};,])(\s*)(?:html|body|:root)(?![\w-])\s*\{([^}]*)\}/gi, (n, r, o, s) => {
75
+ const i = s.split(";").map((t) => t.trim()).filter((t) => t && !re.test(t)).join(";");
76
+ return i ? `${r}${o}:scope{${i}}` : "";
77
+ }), ae = (e, n) => {
78
+ const r = [];
79
+ let o = e.replace(/<style\b([^>]*)>([\s\S]*?)<\/style\s*>/gi, (s, i, t) => {
80
+ const l = /^\s*@scope\b/i.test(t) ? `<style${i}>${t}</style>` : `<style${i}>@scope (${n}) {${le(t)}}</style>`;
81
+ return r.push(l), `\0wi-md-style-${r.length - 1}\0`;
67
82
  });
68
- return n = n.replace(/<\/?style\b[^>]*>/gi, ""), n = n.replace(/<script\b[^>]*>[\s\S]*?<\/script\s*>/gi, "").replace(/<\/?script\b[^>]*>/gi, ""), n = n.replace(/<link\b[^>]*>/gi, ""), n.replace(/\u0000wi-md-style-(\d+)\u0000/g, (d, l) => o[Number(l)]);
83
+ return o = o.replace(/<\/?style\b[^>]*>/gi, ""), o = o.replace(/<script\b[^>]*>[\s\S]*?<\/script\s*>/gi, "").replace(/<\/?script\b[^>]*>/gi, ""), o = o.replace(/<link\b[^>]*>/gi, ""), o.replace(/\u0000wi-md-style-(\d+)\u0000/g, (s, i) => r[Number(i)]);
69
84
  };
70
- let U = null;
71
- const re = () => (U || (U = P({})), U), le = (e) => (e.langPrefix === void 0 || e.langPrefix === "language-") && (e.imagePreview === void 0 || e.imagePreview) && (e.showCodeLang === void 0 || e.showCodeLang) && (e.imageDownload === void 0 || e.imageDownload) && (e.tableDownload === void 0 || e.tableDownload) && !e.imageSrcResolver, ae = (e, t = {}) => {
72
- const o = le(t) ? re() : P(t);
73
- return ne(o.render(e), t.styleScope || Q);
85
+ let D = null;
86
+ const ie = () => (D || (D = j({})), D), se = (e) => (e.langPrefix === void 0 || e.langPrefix === "language-") && (e.imagePreview === void 0 || e.imagePreview) && (e.showCodeLang === void 0 || e.showCodeLang) && (e.imageDownload === void 0 || e.imageDownload) && (e.tableDownload === void 0 || e.tableDownload) && !e.imageSrcResolver, ce = (e, n = {}) => {
87
+ const r = se(n) ? ie() : j(n), o = ae(r.render(e), n.styleScope || te);
88
+ return Q(o);
74
89
  };
75
- let _ = null;
76
- const O = () => {
77
- _ && (E(null, _), _.remove(), _ = null);
78
- }, ce = async (e, t, o) => {
79
- O();
80
- const n = t && t.length ? t.includes(e) ? t : [e, ...t.filter((i) => i !== e)] : [e], d = Math.max(o ?? n.indexOf(e), 0), l = document.createElement("div");
81
- document.body.appendChild(l), _ = l;
82
- const { ElImageViewer: r } = await import("element-plus");
83
- if (_ !== l) return;
84
- const a = j(r, {
85
- urlList: n,
86
- initialIndex: Math.min(d, n.length - 1),
87
- onClose: O,
90
+ let x = null;
91
+ const M = () => {
92
+ x && (B(null, x), x.remove(), x = null);
93
+ }, de = async (e, n, r) => {
94
+ M();
95
+ const o = n && n.length ? n.includes(e) ? n : [e, ...n.filter((a) => a !== e)] : [e], s = Math.max(r ?? o.indexOf(e), 0), i = document.createElement("div");
96
+ document.body.appendChild(i), x = i;
97
+ const { ElImageViewer: t } = await import("element-plus");
98
+ if (x !== i) return;
99
+ const l = q(t, {
100
+ urlList: o,
101
+ initialIndex: Math.min(s, o.length - 1),
102
+ onClose: M,
88
103
  hideOnClickModal: !0,
89
104
  teleported: !0
90
105
  });
91
- E(a, l);
92
- }, se = (e) => {
93
- fetch(e).then((t) => t.blob()).then((t) => {
94
- var d;
95
- const o = URL.createObjectURL(t), n = document.createElement("a");
96
- n.href = o, n.download = ((d = e.split("/").pop()) == null ? void 0 : d.split("?")[0]) || "image", document.body.appendChild(n), n.click(), document.body.removeChild(n), URL.revokeObjectURL(o);
106
+ B(l, i);
107
+ }, ue = (e) => {
108
+ fetch(e).then((n) => n.blob()).then((n) => {
109
+ var s;
110
+ const r = URL.createObjectURL(n), o = document.createElement("a");
111
+ o.href = r, o.download = ((s = e.split("/").pop()) == null ? void 0 : s.split("?")[0]) || "image", document.body.appendChild(o), o.click(), document.body.removeChild(o), URL.revokeObjectURL(r);
97
112
  }).catch(() => {
98
- const t = document.createElement("a");
99
- t.href = e, t.download = "", t.target = "_blank", document.body.appendChild(t), t.click(), document.body.removeChild(t);
113
+ const n = document.createElement("a");
114
+ n.href = e, n.download = "", n.target = "_blank", document.body.appendChild(n), n.click(), document.body.removeChild(n);
100
115
  });
101
- }, ie = async (e, t) => {
116
+ }, me = async (e, n) => {
117
+ try {
118
+ const r = await import("xlsx"), o = r.utils.table_to_sheet(e), s = r.utils.book_new();
119
+ r.utils.book_append_sheet(s, o, "查询结果");
120
+ const i = r.write(s, { bookType: "xlsx", type: "array" }), t = new Blob([i], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }), l = URL.createObjectURL(t), a = document.createElement("a");
121
+ a.href = l, a.download = `${n || "表格"}_${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.xlsx`, document.body.appendChild(a), a.click(), document.body.removeChild(a), URL.revokeObjectURL(l);
122
+ } catch (r) {
123
+ console.error("[downloadTableAsExcel] 表格导出 Excel 失败:", r);
124
+ }
125
+ }, fe = async (e) => {
126
+ var i;
127
+ if ((i = navigator.clipboard) != null && i.writeText)
128
+ try {
129
+ await navigator.clipboard.writeText(e);
130
+ return;
131
+ } catch {
132
+ }
133
+ if (typeof document.execCommand != "function")
134
+ throw new Error("当前环境不支持复制");
135
+ const n = /iP(ad|hone|od)/.test(navigator.userAgent), r = document.createElement("textarea");
136
+ r.value = e, r.setAttribute("readonly", ""), r.style.cssText = "position:fixed;top:0;left:0;width:1px;height:1px;padding:0;border:0;opacity:0;", document.body.appendChild(r);
137
+ const o = document.getSelection(), s = o && o.rangeCount > 0 ? o.getRangeAt(0) : null;
102
138
  try {
103
- const o = await import("xlsx"), n = o.utils.table_to_sheet(e), d = o.utils.book_new();
104
- o.utils.book_append_sheet(d, n, "查询结果");
105
- const l = o.write(d, { bookType: "xlsx", type: "array" }), r = new Blob([l], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }), a = URL.createObjectURL(r), i = document.createElement("a");
106
- i.href = a, i.download = `${t || "表格"}_${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.xlsx`, document.body.appendChild(i), i.click(), document.body.removeChild(i), URL.revokeObjectURL(a);
107
- } catch (o) {
108
- console.error("[downloadTableAsExcel] 表格导出 Excel 失败:", o);
139
+ if (n) {
140
+ r.contentEditable = "true", r.readOnly = !1;
141
+ const t = document.createRange();
142
+ t.selectNodeContents(r), o == null || o.removeAllRanges(), o == null || o.addRange(t), r.setSelectionRange(0, e.length);
143
+ } else
144
+ r.select();
145
+ if (r.focus(), !document.execCommand("copy"))
146
+ throw new Error("浏览器拒绝复制");
147
+ } finally {
148
+ r.remove(), s && o && (o.removeAllRanges(), o.addRange(s));
109
149
  }
110
- }, de = ["data-wi-md-scope", "innerHTML"], ke = /* @__PURE__ */ I({
150
+ }, pe = (e, n = {}) => {
151
+ if (!e) return () => {
152
+ };
153
+ const r = (t, l) => {
154
+ const a = l ? "wi-md-copied" : "wi-md-copy-failed";
155
+ t.classList.remove("wi-md-copied", "wi-md-copy-failed"), t.classList.add(a), t.title = l ? "已复制" : "复制失败,请手动选择代码复制", window.setTimeout(() => {
156
+ t.classList.remove(a), t.title = "复制";
157
+ }, 1500);
158
+ }, o = (t) => {
159
+ const l = t.classList.toggle("wi-md-collapsed"), a = t.querySelector(":scope > .wi-md-block-header"), c = t.querySelector(".wi-md-toggle");
160
+ a && (a.setAttribute("aria-expanded", String(!l)), a.title = l ? "点击展开" : "点击折叠"), c && (c.title = l ? "展开" : "折叠", c.setAttribute("aria-label", l ? "展开代码块" : "折叠代码块"));
161
+ }, s = (t) => {
162
+ var b, g, v, f, p;
163
+ if (t.defaultPrevented) return;
164
+ const l = t.target;
165
+ if (!(l instanceof Element)) return;
166
+ const a = l.closest(".wi-md-copy");
167
+ if (a) {
168
+ t.preventDefault(), t.stopPropagation();
169
+ const m = ((g = (b = a.closest(".wi-md-block")) == null ? void 0 : b.querySelector(".wi-md-code code")) == null ? void 0 : g.textContent) || "";
170
+ fe(m).then(() => r(a, !0)).catch(() => r(a, !1));
171
+ return;
172
+ }
173
+ const c = l.closest(".wi-md-toggle");
174
+ if (c) {
175
+ t.preventDefault();
176
+ const m = c.closest(".wi-md-block");
177
+ m && o(m);
178
+ return;
179
+ }
180
+ const u = l.closest(".wi-md-block-header");
181
+ if (u) {
182
+ t.preventDefault();
183
+ const m = u.closest(".wi-md-block");
184
+ m && o(m);
185
+ return;
186
+ }
187
+ const w = l.closest(".wi-md-image-download");
188
+ if (w) {
189
+ t.preventDefault(), t.stopPropagation();
190
+ const m = (v = w.closest(".wi-md-image-wrap")) == null ? void 0 : v.dataset.src;
191
+ m && ue(m);
192
+ return;
193
+ }
194
+ const k = l.closest(".wi-md-table-download");
195
+ if (k) {
196
+ t.preventDefault(), t.stopPropagation();
197
+ const m = (f = k.closest(".wi-md-table-wrap")) == null ? void 0 : f.querySelector("table");
198
+ m && me(m);
199
+ return;
200
+ }
201
+ const h = l.closest(".wi-md-image-wrap img");
202
+ if (h) {
203
+ t.preventDefault();
204
+ const m = h.closest(".wi-md-image-wrap"), S = (m == null ? void 0 : m.dataset.src) || h.src || "";
205
+ if (!S) return;
206
+ const _ = ((p = n.imageRoot) == null ? void 0 : p.call(n)) ?? e, C = Array.from(_.querySelectorAll(".wi-md-image-wrap")).map((T) => {
207
+ var d;
208
+ return T.dataset.src || ((d = T.querySelector("img")) == null ? void 0 : d.getAttribute("src")) || "";
209
+ }).filter(Boolean);
210
+ de(S, C.length > 1 ? C : void 0, C.indexOf(S));
211
+ }
212
+ };
213
+ e.addEventListener("click", s);
214
+ const i = (t) => {
215
+ if (t.key !== "Enter" && t.key !== " ") return;
216
+ const l = t.target;
217
+ if (!(l instanceof Element) || l.closest(".wi-md-copy, .wi-md-toggle")) return;
218
+ const a = l.closest(".wi-md-block-header");
219
+ if (!a) return;
220
+ t.preventDefault();
221
+ const c = a.closest(".wi-md-block");
222
+ c && o(c);
223
+ };
224
+ return e.addEventListener("keydown", i), () => {
225
+ e.removeEventListener("click", s), e.removeEventListener("keydown", i);
226
+ };
227
+ }, we = ["data-wi-md-scope", "innerHTML"], ge = 120, he = 3, Ae = /* @__PURE__ */ F({
111
228
  __name: "MarkdownContent",
112
229
  props: {
113
230
  source: { default: "" },
114
231
  renderOptions: { default: () => ({}) }
115
232
  },
116
233
  setup(e) {
117
- const t = e, o = B(), n = ee(), d = q(() => ae(t.source, { ...t.renderOptions, styleScope: n.selector })), l = async (a, i) => {
118
- try {
119
- await navigator.clipboard.writeText(i);
120
- } catch {
121
- const c = document.createElement("textarea");
122
- c.value = i, c.style.position = "fixed", c.style.opacity = "0", document.body.appendChild(c), c.select(), document.execCommand("copy"), c.remove();
123
- }
124
- a.classList.add("wi-md-copied"), window.setTimeout(() => a.classList.remove("wi-md-copied"), 1500);
125
- }, r = (a) => {
126
- var h, p, y, k, v, S;
127
- const i = a.target, c = i.closest(".wi-md-copy");
128
- if (c) {
129
- a.preventDefault();
130
- const w = ((p = (h = c.closest(".wi-md-block")) == null ? void 0 : h.querySelector(".wi-md-code code")) == null ? void 0 : p.textContent) || "";
131
- l(c, w);
132
- return;
133
- }
134
- const u = i.closest(".wi-md-toggle");
135
- if (u) {
136
- a.preventDefault(), (y = u.closest(".wi-md-block")) == null || y.classList.toggle("wi-md-collapsed");
137
- return;
138
- }
139
- const m = i.closest(".wi-md-image-download");
140
- if (m) {
141
- a.preventDefault(), a.stopPropagation();
142
- const w = (k = m.closest(".wi-md-image-wrap")) == null ? void 0 : k.dataset.src;
143
- w && se(w);
144
- return;
145
- }
146
- const b = i.closest(".wi-md-table-download");
147
- if (b) {
148
- a.preventDefault(), a.stopPropagation();
149
- const w = (v = b.closest(".wi-md-table-wrap")) == null ? void 0 : v.querySelector("table");
150
- w && ie(w);
151
- return;
152
- }
153
- const f = i.closest(".wi-md-image-wrap img");
154
- if (f) {
155
- a.preventDefault();
156
- const w = f.closest(".wi-md-image-wrap"), x = (w == null ? void 0 : w.dataset.src) || f.src || "";
157
- if (!x) return;
158
- const L = Array.from(((S = o.value) == null ? void 0 : S.querySelectorAll(".wi-md-image-wrap")) ?? []).map((T) => {
159
- var s;
160
- return T.dataset.src || ((s = T.querySelector("img")) == null ? void 0 : s.getAttribute("src")) || "";
161
- }).filter(Boolean);
162
- ce(x, L.length > 1 ? L : void 0, L.indexOf(x));
163
- }
234
+ const n = e, r = O(), o = ne(), s = O("");
235
+ let i = "", t = 0, l = 0, a = null;
236
+ const c = () => {
237
+ const f = performance.now();
238
+ s.value = ce(n.source, { ...n.renderOptions, styleScope: o.selector }), l = performance.now() - f, t = performance.now();
239
+ }, u = () => {
240
+ a !== null && (clearTimeout(a), a = null);
241
+ }, w = (f) => {
242
+ a === null && (a = setTimeout(() => {
243
+ a = null, c();
244
+ }, f));
164
245
  };
165
- return F(O), (a, i) => (G(), N("div", {
246
+ $(
247
+ () => n.source,
248
+ (f) => {
249
+ const p = f.length >= i.length && f.startsWith(i);
250
+ if (i = f, !s.value || !p) {
251
+ u(), c();
252
+ return;
253
+ }
254
+ const m = performance.now() - t, S = Math.max(ge, l * he - m);
255
+ w(Math.max(0, S));
256
+ },
257
+ { immediate: !0 }
258
+ );
259
+ const k = /* @__PURE__ */ new WeakMap();
260
+ let h = 0;
261
+ const b = (f) => {
262
+ let p = k.get(f);
263
+ return p === void 0 && (p = ++h, k.set(f, p)), p;
264
+ }, g = (f) => f ? Object.keys(f).sort().map((p) => {
265
+ const m = f[p];
266
+ return typeof m == "function" ? `${p}=fn:${b(m)}` : `${p}=${JSON.stringify(m)}`;
267
+ }).join("|") : "";
268
+ $(
269
+ () => g(n.renderOptions),
270
+ () => {
271
+ u(), c();
272
+ }
273
+ );
274
+ let v;
275
+ return N(() => {
276
+ v = pe(r.value, { imageRoot: () => r.value });
277
+ }), G(() => {
278
+ u(), v == null || v(), M();
279
+ }), (f, p) => (z(), J("div", {
166
280
  ref_key: "rootEl",
167
- ref: o,
281
+ ref: r,
168
282
  class: "wi-markdown",
169
- "data-wi-md-scope": z(n).id,
170
- innerHTML: d.value,
171
- onClick: r
172
- }, null, 8, de));
283
+ "data-wi-md-scope": V(o).id,
284
+ innerHTML: s.value
285
+ }, null, 8, we));
173
286
  }
174
- }), ue = 48, me = 48, pe = async () => {
175
- await M(), await new Promise((e) => requestAnimationFrame(() => e()));
176
- }, we = (e) => {
287
+ }), be = 48, ve = 48, ye = async () => {
288
+ await P(), await new Promise((e) => requestAnimationFrame(() => e()));
289
+ }, ke = (e) => {
177
290
  typeof requestAnimationFrame == "function" ? requestAnimationFrame(e) : setTimeout(e, 0);
178
- }, Se = (e) => {
179
- const t = B(!1), o = B(!0);
180
- let n, d, l, r = !1, a = 0, i, c = { preserveScroll: !0 }, u = !1, m = !1;
181
- const b = (s) => s.scrollHeight - s.scrollTop - s.clientHeight <= ue, f = (s) => s.scrollTop <= me, h = (s) => {
182
- const g = e.value;
183
- if (!g) return;
184
- const R = g.scrollHeight > a;
185
- a = g.scrollHeight, s && R && o.value && (g.scrollTop = g.scrollHeight);
186
- const H = b(g);
187
- o.value = H, t.value = !H;
188
- }, p = () => h(!1), y = () => {
189
- r || (r = !0, we(() => {
190
- r = !1, h(!0);
291
+ }, Ee = (e) => {
292
+ const n = O(!1), r = O(!0);
293
+ let o, s, i, t = !1, l = 0, a, c = { preserveScroll: !0 }, u = !1, w = !1;
294
+ const k = (d) => d.scrollHeight - d.scrollTop - d.clientHeight <= be, h = (d) => d.scrollTop <= ve, b = (d) => {
295
+ const y = e.value;
296
+ if (!y) return;
297
+ const L = y.scrollHeight > l;
298
+ l = y.scrollHeight, d && L && r.value && (y.scrollTop = y.scrollHeight);
299
+ const H = k(y);
300
+ r.value = H, n.value = !H;
301
+ }, g = () => b(!1), v = () => {
302
+ t || (t = !0, ke(() => {
303
+ t = !1, b(!0);
191
304
  }));
192
- }, k = () => {
193
- n == null || n(), n = void 0, d == null || d.disconnect(), d = void 0, l == null || l.disconnect(), l = void 0;
194
- }, v = async () => {
195
- await pe();
196
- const s = e.value;
197
- s && (s.scrollTop = s.scrollHeight, a = s.scrollHeight, o.value = !0, t.value = !1);
198
- }, S = async () => {
199
- if (!o.value) {
200
- t.value = !0;
305
+ }, f = () => {
306
+ o == null || o(), o = void 0, s == null || s.disconnect(), s = void 0, i == null || i.disconnect(), i = void 0;
307
+ }, p = async () => {
308
+ await ye();
309
+ const d = e.value;
310
+ d && (d.scrollTop = d.scrollHeight, l = d.scrollHeight, r.value = !0, n.value = !1);
311
+ }, m = async () => {
312
+ if (!r.value) {
313
+ n.value = !0;
201
314
  return;
202
315
  }
203
- await v();
204
- }, w = () => {
205
- const s = e.value;
206
- s && (s.scrollTop = 0), a = 0, o.value = !0, t.value = !1, m = !1, u = !1;
207
- }, x = async (s) => {
208
- const g = e.value, R = g ? g.scrollHeight : 0;
316
+ await p();
317
+ }, S = () => {
318
+ const d = e.value;
319
+ d && (d.scrollTop = 0), l = 0, r.value = !0, n.value = !1, w = !1, u = !1;
320
+ }, _ = async (d) => {
321
+ const y = e.value, L = y ? y.scrollHeight : 0;
209
322
  try {
210
- await s();
323
+ await d();
211
324
  } finally {
212
- await M(), e.value && R && (e.value.scrollTop += e.value.scrollHeight - R, a = e.value.scrollHeight);
325
+ await P(), e.value && L && (e.value.scrollTop += e.value.scrollHeight - L, l = e.value.scrollHeight);
213
326
  }
214
- }, L = (s, g = { preserveScroll: !0 }) => {
215
- i = s, c = g;
327
+ }, C = (d, y = { preserveScroll: !0 }) => {
328
+ a = d, c = y;
216
329
  }, T = async () => {
217
- const s = e.value;
218
- if (!s || (p(), !i || u)) return;
219
- const g = f(s);
220
- if (g && !m) {
221
- m = !0, u = !0;
330
+ const d = e.value;
331
+ if (!d || (g(), !a || u)) return;
332
+ const y = h(d);
333
+ if (y && !w) {
334
+ w = !0, u = !0;
222
335
  try {
223
- (c == null ? void 0 : c.preserveScroll) !== !1 ? await x(i) : await i();
336
+ (c == null ? void 0 : c.preserveScroll) !== !1 ? await _(a) : await a();
224
337
  } finally {
225
- u = !1, f(s) || (m = !1);
338
+ u = !1, h(d) || (w = !1);
226
339
  }
227
- } else g || (m = !1);
340
+ } else y || (w = !1);
228
341
  };
229
- return J(
342
+ return $(
230
343
  e,
231
- (s) => {
232
- k(), s && (s.addEventListener("scroll", T, { passive: !0 }), n = () => s.removeEventListener("scroll", T), typeof MutationObserver < "u" && (d = new MutationObserver(y), d.observe(s, { childList: !0, subtree: !0, characterData: !0 })), typeof ResizeObserver < "u" && (l = new ResizeObserver(y), l.observe(s)), a = 0, p());
344
+ (d) => {
345
+ f(), d && (d.addEventListener("scroll", T, { passive: !0 }), o = () => d.removeEventListener("scroll", T), typeof MutationObserver < "u" && (s = new MutationObserver(v), s.observe(d, { childList: !0, subtree: !0, characterData: !0 })), typeof ResizeObserver < "u" && (i = new ResizeObserver(v), i.observe(d)), l = 0, g());
233
346
  },
234
347
  { immediate: !0, flush: "post" }
235
- ), Z() && V(() => k()), {
236
- showScrollToBottom: t,
237
- forceScrollToBottom: v,
238
- requestScrollToBottom: S,
239
- syncScrollState: p,
240
- resetScrollState: w,
241
- onReachTop: L,
242
- preserveScrollPosition: x
348
+ ), Y() && Z(() => f()), {
349
+ showScrollToBottom: n,
350
+ forceScrollToBottom: p,
351
+ requestScrollToBottom: m,
352
+ syncScrollState: g,
353
+ resetScrollState: S,
354
+ onReachTop: C,
355
+ preserveScrollPosition: _
243
356
  };
244
- }, xe = async (e, t = {}) => {
357
+ }, Oe = async (e, n = {}) => {
245
358
  if (typeof window > "u" || typeof document > "u") return;
246
- const o = e.attachContent || {}, n = e.name || o.file_name || "download";
247
- if (o.raw) {
248
- const l = URL.createObjectURL(o.raw), r = document.createElement("a");
249
- r.href = l, r.download = n, document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(l);
359
+ const r = e.attachContent || {}, o = e.name || r.file_name || "download";
360
+ if (r.raw) {
361
+ const i = URL.createObjectURL(r.raw), t = document.createElement("a");
362
+ t.href = i, t.download = o, document.body.appendChild(t), t.click(), document.body.removeChild(t), URL.revokeObjectURL(i);
250
363
  return;
251
364
  }
252
- if (!o.fileId) return;
253
- const d = X(o.fileId, t.baseURL, t.getFileUrl);
254
- if (d)
365
+ if (!r.fileId) return;
366
+ const s = W(r.fileId, n.baseURL, n.getFileUrl);
367
+ if (s)
255
368
  try {
256
- const l = await fetch(d, { credentials: "include" });
257
- if (!l.ok) throw new Error(`Download failed with status ${l.status}`);
258
- const r = URL.createObjectURL(await l.blob()), a = document.createElement("a");
259
- a.href = r, a.download = n, document.body.appendChild(a), a.click(), document.body.removeChild(a), URL.revokeObjectURL(r);
260
- } catch (l) {
261
- console.error("[downloadAttachment] fetch blob 失败,降级为直接链接触发:", l);
262
- const r = document.createElement("a");
263
- r.href = d, r.download = n, document.body.appendChild(r), r.click(), document.body.removeChild(r);
369
+ const i = await fetch(s, { credentials: "include" });
370
+ if (!i.ok) throw new Error(`Download failed with status ${i.status}`);
371
+ const t = URL.createObjectURL(await i.blob()), l = document.createElement("a");
372
+ l.href = t, l.download = o, document.body.appendChild(l), l.click(), document.body.removeChild(l), URL.revokeObjectURL(t);
373
+ } catch (i) {
374
+ console.error("[downloadAttachment] fetch blob 失败,降级为直接链接触发:", i);
375
+ const t = document.createElement("a");
376
+ t.href = s, t.download = o, document.body.appendChild(t), t.click(), document.body.removeChild(t);
264
377
  }
265
378
  };
266
379
  export {
267
- ke as MarkdownContent,
268
- O as closeImagePreview,
269
- Le as consumeStream,
270
- ee as createStyleScope,
271
- xe as downloadAttachment,
272
- ie as downloadTableAsExcel,
273
- ce as openImagePreview,
274
- ae as renderMarkdown,
275
- Se as useAutoScroll
380
+ Ae as MarkdownContent,
381
+ pe as bindMarkdownInteractions,
382
+ M as closeImagePreview,
383
+ Me as consumeStream,
384
+ ne as createStyleScope,
385
+ Oe as downloadAttachment,
386
+ me as downloadTableAsExcel,
387
+ de as openImagePreview,
388
+ ce as renderMarkdown,
389
+ Ee as useAutoScroll,
390
+ fe as writeClipboard
276
391
  };
277
392
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,7 @@
1
1
  export { renderMarkdown, createStyleScope } from './renderMarkdown';
2
2
  export type { MarkdownRenderOptions } from './renderMarkdown';
3
+ export { bindMarkdownInteractions, writeClipboard } from './interactions';
4
+ export type { BindMarkdownInteractionsOptions } from './interactions';
3
5
  export { default as MarkdownContent } from './MarkdownContent.vue';
4
6
  export { openImagePreview, closeImagePreview } from './imagePreview';
5
7
  export { downloadTableAsExcel } from './tableDownload';