wi-chat 0.5.0 → 0.6.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.
@@ -1,34 +1,34 @@
1
1
  import "wi-chat/style.css";
2
- import { createVNode as P, render as E, defineComponent as A, ref as T, computed as H, onBeforeUnmount as j, openBlock as I, createElementBlock as q, unref as F, watch as G, getCurrentInstance as N, onUnmounted as J, nextTick as O } from "vue";
3
- import { resolveAttachDownloadUrl as Z } from "wi-chat/parser";
4
- import { consumeStream as xe } from "wi-chat/parser";
5
- import { katex as z } from "@mdit/plugin-katex";
6
- import B from "highlight.js";
7
- import D from "markdown-it";
8
- const y = (e) => new D().utils.escapeHtml(e), C = (e) => y(e).replace(/"/g, """).replace(/'/g, "'"), V = (e) => !e || e.includes("get_image_full") ? e : e.replace("get_image", "get_image_full"), M = (e) => {
9
- const { langPrefix: t = "language-", imagePreview: r = !0, showCodeLang: o = !0, imageSrcResolver: d, imageDownload: l = !0, tableDownload: n = !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>', s = new D({
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, "&quot;").replace(/'/g, "&#39;"), 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({
10
10
  linkify: !0,
11
11
  typographer: !0,
12
12
  breaks: !0,
13
13
  html: !0,
14
14
  langPrefix: t,
15
- highlight: (i, u) => {
16
- if (u && B.getLanguage(u))
15
+ highlight: (c, u) => {
16
+ if (u && D.getLanguage(u))
17
17
  try {
18
- return B.highlight(i, { language: u }).value;
18
+ return D.highlight(c, { language: u }).value;
19
19
  } catch {
20
- return y(i);
20
+ return C(c);
21
21
  }
22
- return y(i);
22
+ return C(c);
23
23
  }
24
- }).use(z, { delimiters: "dollars" });
25
- return s.renderer.rules.fence = (i, u, m, v, p) => {
26
- var b;
27
- const g = i[u], h = g.info.trim().split(/\s+/)[0].toLowerCase(), c = ((b = m.highlight) == null ? void 0 : b.call(m, g.content, h, "")) || y(g.content);
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);
28
28
  return `
29
29
  <div class="wi-md-block">
30
30
  <div class="wi-md-block-header">
31
- <div class="wi-md-block-header-left">${o && h ? `<span class="wi-md-lang">${y(h)}</span>` : ""}</div>
31
+ <div class="wi-md-block-header-left">${n && p ? `<span class="wi-md-lang">${C(p)}</span>` : ""}</div>
32
32
  <div class="wi-md-block-header-right">
33
33
  <button type="button" class="wi-md-copy" title="复制" aria-label="复制代码">
34
34
  <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,234 +38,249 @@ const y = (e) => new D().utils.escapeHtml(e), C = (e) => y(e).replace(/"/g, "&qu
38
38
  </button>
39
39
  </div>
40
40
  </div>
41
- <pre class="wi-md-code"><code class="${m.langPrefix}${y(h)}">${c}</code></pre>
41
+ <pre class="wi-md-code"><code class="${m.langPrefix}${C(p)}">${y}</code></pre>
42
42
  </div>
43
43
  `.trim();
44
- }, s.renderer.rules.table_open = () => n ? '<div class="wi-md-table-wrap"><table class="wi-md-table">' : '<table class="wi-md-table">', s.renderer.rules.table_close = () => n ? `</table>${a}</div>` : "</table>", s.renderer.rules.ordered_list_open = (i, u, m, v, p) => (i[u].attrJoin("class", "wi-md-list wi-md-list-ordered"), p.renderToken(i, u, m)), s.renderer.rules.bullet_list_open = (i, u, m, v, p) => (i[u].attrJoin("class", "wi-md-list wi-md-list-bullet"), p.renderToken(i, u, m)), s.renderer.rules.list_item_open = (i, u, m, v, p) => (i[u].attrJoin("class", "wi-md-list-item"), p.renderToken(i, u, m)), s.renderer.rules.image = (i, u, m, v, p) => {
45
- const g = i[u], h = g.attrGet("src") || "", c = g.attrGet("alt") || g.content || "", w = g.attrGet("title") || "", b = [
46
- `src="${C(h)}"`,
47
- `alt="${C(c)}"`,
48
- w ? `title="${C(w)}"` : ""
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)}"` : ""
49
49
  ].filter(Boolean).join(" ");
50
- if (!r)
51
- return `<img ${b} />`;
52
- const x = d ? d(h) : V(h), f = 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>' : "";
53
- return `<span class="wi-md-image-wrap" data-src="${C(x)}"><img ${b} loading="lazy" />${f}</span>`;
54
- }, s;
55
- }, X = ".wi-markdown";
56
- let Y = 0;
57
- const K = () => {
58
- const e = "data-wi-md-scope", t = `wi-md-scope-${++Y}`;
50
+ if (!o)
51
+ return `<img ${v} />`;
52
+ 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>' : "";
53
+ return `<span class="wi-md-image-wrap" data-src="${$(S)}"><img ${v} loading="lazy" />${w}</span>`;
54
+ }, i;
55
+ }, Q = ".wi-markdown";
56
+ let W = 0;
57
+ const ee = () => {
58
+ const e = "data-wi-md-scope", t = `wi-md-scope-${++W}`;
59
59
  return { attr: e, id: t, selector: `[${e}="${t}"]` };
60
- }, Q = /^(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, W = (e) => e.replace(/(^|[{};,])(\s*)(?:html|body|:root)(?![\w-])\s*\{([^}]*)\}/gi, (t, r, o, d) => {
61
- const l = d.split(";").map((n) => n.trim()).filter((n) => n && !Q.test(n)).join(";");
62
- return l ? `${r}${o}:scope{${l}}` : "";
63
- }), ee = (e, t) => {
64
- const r = [];
65
- let o = e.replace(/<style\b([^>]*)>([\s\S]*?)<\/style\s*>/gi, (d, l, n) => {
66
- const a = /^\s*@scope\b/i.test(n) ? `<style${l}>${n}</style>` : `<style${l}>@scope (${t}) {${W(n)}}</style>`;
67
- return r.push(a), `\0wi-md-style-${r.length - 1}\0`;
60
+ }, 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) => {
61
+ const l = d.split(";").map((r) => r.trim()).filter((r) => r && !te.test(r)).join(";");
62
+ return l ? `${o}${n}:scope{${l}}` : "";
63
+ }), ne = (e, t) => {
64
+ const o = [];
65
+ let n = e.replace(/<style\b([^>]*)>([\s\S]*?)<\/style\s*>/gi, (d, l, r) => {
66
+ const a = /^\s*@scope\b/i.test(r) ? `<style${l}>${r}</style>` : `<style${l}>@scope (${t}) {${oe(r)}}</style>`;
67
+ return o.push(a), `\0wi-md-style-${o.length - 1}\0`;
68
68
  });
69
- 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, (d, l) => r[Number(l)]);
69
+ 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)]);
70
70
  };
71
- let S = null;
72
- const te = () => (S || (S = M({})), S), oe = (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, ne = (e, t = {}) => {
73
- const r = oe(t) ? te() : M(t);
74
- return ee(r.render(e), t.styleScope || X);
71
+ let U = null;
72
+ 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 = {}) => {
73
+ const o = le(t) ? re() : P(t);
74
+ return ne(o.render(e), t.styleScope || Q);
75
75
  };
76
- let k = null;
77
- const $ = () => {
78
- k && (E(null, k), k.remove(), k = null);
79
- }, re = async (e, t, r) => {
80
- $();
81
- const o = t && t.length ? t.includes(e) ? t : [e, ...t.filter((s) => s !== e)] : [e], d = Math.max(r ?? o.indexOf(e), 0), l = document.createElement("div");
82
- document.body.appendChild(l), k = l;
83
- const { ElImageViewer: n } = await import("element-plus");
84
- if (k !== l)
76
+ let _ = null;
77
+ const O = () => {
78
+ _ && (E(null, _), _.remove(), _ = null);
79
+ }, ce = async (e, t, o) => {
80
+ O();
81
+ 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");
82
+ document.body.appendChild(l), _ = l;
83
+ const { ElImageViewer: r } = await import("element-plus");
84
+ if (_ !== l)
85
85
  return;
86
- const a = P(n, {
87
- urlList: o,
88
- initialIndex: Math.min(d, o.length - 1),
89
- onClose: $,
86
+ const a = j(r, {
87
+ urlList: n,
88
+ initialIndex: Math.min(d, n.length - 1),
89
+ onClose: O,
90
90
  hideOnClickModal: !0,
91
91
  teleported: !0
92
92
  });
93
93
  E(a, l);
94
- }, le = (e) => {
94
+ }, se = (e) => {
95
95
  fetch(e).then((t) => t.blob()).then((t) => {
96
96
  var d;
97
- const r = URL.createObjectURL(t), o = document.createElement("a");
98
- o.href = r, o.download = ((d = e.split("/").pop()) == null ? void 0 : d.split("?")[0]) || "image", document.body.appendChild(o), o.click(), document.body.removeChild(o), URL.revokeObjectURL(r);
97
+ const o = URL.createObjectURL(t), n = document.createElement("a");
98
+ 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);
99
99
  }).catch(() => {
100
100
  const t = document.createElement("a");
101
101
  t.href = e, t.download = "", t.target = "_blank", document.body.appendChild(t), t.click(), document.body.removeChild(t);
102
102
  });
103
- }, ae = async (e, t) => {
103
+ }, ie = async (e, t) => {
104
104
  try {
105
- const r = await import("xlsx"), o = r.utils.table_to_sheet(e), d = r.utils.book_new();
106
- r.utils.book_append_sheet(d, o, "查询结果");
107
- const l = r.write(d, { bookType: "xlsx", type: "array" }), n = new Blob([l], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }), a = URL.createObjectURL(n), s = document.createElement("a");
108
- s.href = a, s.download = `${t || "表格"}_${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.xlsx`, document.body.appendChild(s), s.click(), document.body.removeChild(s), URL.revokeObjectURL(a);
109
- } catch (r) {
110
- console.error("[downloadTableAsExcel] 表格导出 Excel 失败:", r);
105
+ const o = await import("xlsx"), n = o.utils.table_to_sheet(e), d = o.utils.book_new();
106
+ o.utils.book_append_sheet(d, n, "查询结果");
107
+ 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");
108
+ 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);
109
+ } catch (o) {
110
+ console.error("[downloadTableAsExcel] 表格导出 Excel 失败:", o);
111
111
  }
112
- }, ce = ["data-wi-md-scope", "innerHTML"], fe = /* @__PURE__ */ A({
112
+ }, de = ["data-wi-md-scope", "innerHTML"], ke = /* @__PURE__ */ I({
113
113
  __name: "MarkdownContent",
114
114
  props: {
115
115
  source: { default: "" },
116
116
  renderOptions: { default: () => ({}) }
117
117
  },
118
118
  setup(e) {
119
- const t = e, r = T(), o = K(), d = H(() => ne(t.source, { ...t.renderOptions, styleScope: o.selector })), l = async (a, s) => {
119
+ const t = e, o = B(), n = ee(), d = q(() => ae(t.source, { ...t.renderOptions, styleScope: n.selector })), l = async (a, i) => {
120
120
  try {
121
- await navigator.clipboard.writeText(s);
121
+ await navigator.clipboard.writeText(i);
122
122
  } catch {
123
- const i = document.createElement("textarea");
124
- i.value = s, i.style.position = "fixed", i.style.opacity = "0", document.body.appendChild(i), i.select(), document.execCommand("copy"), i.remove();
123
+ const c = document.createElement("textarea");
124
+ c.value = i, c.style.position = "fixed", c.style.opacity = "0", document.body.appendChild(c), c.select(), document.execCommand("copy"), c.remove();
125
125
  }
126
126
  a.classList.add("wi-md-copied"), window.setTimeout(() => a.classList.remove("wi-md-copied"), 1500);
127
- }, n = (a) => {
128
- var g, h, c, w, b, x;
129
- const s = a.target, i = s.closest(".wi-md-copy");
130
- if (i) {
127
+ }, r = (a) => {
128
+ var h, p, y, k, v, S;
129
+ const i = a.target, c = i.closest(".wi-md-copy");
130
+ if (c) {
131
131
  a.preventDefault();
132
- const f = ((h = (g = i.closest(".wi-md-block")) == null ? void 0 : g.querySelector(".wi-md-code code")) == null ? void 0 : h.textContent) || "";
133
- l(i, f);
132
+ const w = ((p = (h = c.closest(".wi-md-block")) == null ? void 0 : h.querySelector(".wi-md-code code")) == null ? void 0 : p.textContent) || "";
133
+ l(c, w);
134
134
  return;
135
135
  }
136
- const u = s.closest(".wi-md-toggle");
136
+ const u = i.closest(".wi-md-toggle");
137
137
  if (u) {
138
- a.preventDefault(), (c = u.closest(".wi-md-block")) == null || c.classList.toggle("wi-md-collapsed");
138
+ a.preventDefault(), (y = u.closest(".wi-md-block")) == null || y.classList.toggle("wi-md-collapsed");
139
139
  return;
140
140
  }
141
- const m = s.closest(".wi-md-image-download");
141
+ const m = i.closest(".wi-md-image-download");
142
142
  if (m) {
143
143
  a.preventDefault(), a.stopPropagation();
144
- const f = (w = m.closest(".wi-md-image-wrap")) == null ? void 0 : w.dataset.src;
145
- f && le(f);
144
+ const w = (k = m.closest(".wi-md-image-wrap")) == null ? void 0 : k.dataset.src;
145
+ w && se(w);
146
146
  return;
147
147
  }
148
- const v = s.closest(".wi-md-table-download");
149
- if (v) {
148
+ const b = i.closest(".wi-md-table-download");
149
+ if (b) {
150
150
  a.preventDefault(), a.stopPropagation();
151
- const f = (b = v.closest(".wi-md-table-wrap")) == null ? void 0 : b.querySelector("table");
152
- f && ae(f);
151
+ const w = (v = b.closest(".wi-md-table-wrap")) == null ? void 0 : v.querySelector("table");
152
+ w && ie(w);
153
153
  return;
154
154
  }
155
- const p = s.closest(".wi-md-image-wrap img");
156
- if (p) {
155
+ const f = i.closest(".wi-md-image-wrap img");
156
+ if (f) {
157
157
  a.preventDefault();
158
- const f = p.closest(".wi-md-image-wrap"), _ = (f == null ? void 0 : f.dataset.src) || p.src || "";
159
- if (!_)
158
+ const w = f.closest(".wi-md-image-wrap"), x = (w == null ? void 0 : w.dataset.src) || f.src || "";
159
+ if (!x)
160
160
  return;
161
- const L = Array.from(((x = r.value) == null ? void 0 : x.querySelectorAll(".wi-md-image-wrap")) ?? []).map((R) => {
162
- var U;
163
- return R.dataset.src || ((U = R.querySelector("img")) == null ? void 0 : U.getAttribute("src")) || "";
161
+ const L = Array.from(((S = o.value) == null ? void 0 : S.querySelectorAll(".wi-md-image-wrap")) ?? []).map((T) => {
162
+ var s;
163
+ return T.dataset.src || ((s = T.querySelector("img")) == null ? void 0 : s.getAttribute("src")) || "";
164
164
  }).filter(Boolean);
165
- re(_, L.length > 1 ? L : void 0, L.indexOf(_));
165
+ ce(x, L.length > 1 ? L : void 0, L.indexOf(x));
166
166
  }
167
167
  };
168
- return j($), (a, s) => (I(), q("div", {
168
+ return F(O), (a, i) => (G(), N("div", {
169
169
  ref_key: "rootEl",
170
- ref: r,
170
+ ref: o,
171
171
  class: "wi-markdown",
172
- "data-wi-md-scope": F(o).id,
172
+ "data-wi-md-scope": z(n).id,
173
173
  innerHTML: d.value,
174
- onClick: n
175
- }, null, 8, ce));
174
+ onClick: r
175
+ }, null, 8, de));
176
176
  }
177
- }), ie = 48, se = 48, de = async () => {
178
- await O(), await new Promise((e) => requestAnimationFrame(() => e()));
179
- }, be = (e) => {
180
- const t = T(!1), r = T(!0);
181
- let o, d, l = { preserveScroll: !0 }, n = !1, a = !1;
182
- const s = (c) => c.scrollHeight - c.scrollTop - c.clientHeight <= ie, i = (c) => c.scrollTop <= se, u = () => {
183
- const c = e.value;
184
- if (!c)
177
+ }), ue = 48, me = 48, pe = async () => {
178
+ await M(), await new Promise((e) => requestAnimationFrame(() => e()));
179
+ }, we = (e) => {
180
+ typeof requestAnimationFrame == "function" ? requestAnimationFrame(e) : setTimeout(e, 0);
181
+ }, Se = (e) => {
182
+ const t = B(!1), o = B(!0);
183
+ let n, d, l, r = !1, a = 0, i, c = { preserveScroll: !0 }, u = !1, m = !1;
184
+ const b = (s) => s.scrollHeight - s.scrollTop - s.clientHeight <= ue, f = (s) => s.scrollTop <= me, h = (s) => {
185
+ const g = e.value;
186
+ if (!g)
185
187
  return;
186
- const w = s(c);
187
- r.value = w, t.value = !w;
188
- }, m = async () => {
189
- await de();
190
- const c = e.value;
191
- c && (c.scrollTop = c.scrollHeight, r.value = !0, t.value = !1);
188
+ const R = g.scrollHeight > a;
189
+ a = g.scrollHeight, s && R && o.value && (g.scrollTop = g.scrollHeight);
190
+ const H = b(g);
191
+ o.value = H, t.value = !H;
192
+ }, p = () => h(!1), y = () => {
193
+ r || (r = !0, we(() => {
194
+ r = !1, h(!0);
195
+ }));
196
+ }, k = () => {
197
+ n == null || n(), n = void 0, d == null || d.disconnect(), d = void 0, l == null || l.disconnect(), l = void 0;
192
198
  }, v = async () => {
193
- if (!r.value) {
199
+ await pe();
200
+ const s = e.value;
201
+ s && (s.scrollTop = s.scrollHeight, a = s.scrollHeight, o.value = !0, t.value = !1);
202
+ }, S = async () => {
203
+ if (!o.value) {
194
204
  t.value = !0;
195
205
  return;
196
206
  }
197
- await m();
198
- }, p = async (c) => {
199
- const w = e.value, b = w ? w.scrollHeight : 0;
207
+ await v();
208
+ }, w = () => {
209
+ const s = e.value;
210
+ s && (s.scrollTop = 0), a = 0, o.value = !0, t.value = !1;
211
+ }, x = async (s) => {
212
+ const g = e.value, R = g ? g.scrollHeight : 0;
200
213
  try {
201
- await c();
214
+ await s();
202
215
  } finally {
203
- await O(), e.value && b && (e.value.scrollTop += e.value.scrollHeight - b);
216
+ await M(), e.value && R && (e.value.scrollTop += e.value.scrollHeight - R, a = e.value.scrollHeight);
204
217
  }
205
- }, g = (c, w = { preserveScroll: !0 }) => {
206
- d = c, l = w;
207
- }, h = async () => {
208
- const c = e.value;
209
- if (!c || (u(), !d || n))
218
+ }, L = (s, g = { preserveScroll: !0 }) => {
219
+ i = s, c = g;
220
+ }, T = async () => {
221
+ const s = e.value;
222
+ if (!s || (p(), !i || u))
210
223
  return;
211
- const w = i(c);
212
- if (w && !a) {
213
- a = !0, n = !0;
224
+ const g = f(s);
225
+ if (g && !m) {
226
+ m = !0, u = !0;
214
227
  try {
215
- (l == null ? void 0 : l.preserveScroll) !== !1 ? await p(d) : await d();
228
+ (c == null ? void 0 : c.preserveScroll) !== !1 ? await x(i) : await i();
216
229
  } finally {
217
- n = !1, i(c) || (a = !1);
230
+ u = !1, f(s) || (m = !1);
218
231
  }
219
232
  } else
220
- w || (a = !1);
233
+ g || (m = !1);
221
234
  };
222
- return G(
235
+ return J(
223
236
  e,
224
- (c) => {
225
- o == null || o(), c && (c.addEventListener("scroll", h, { passive: !0 }), o = () => c.removeEventListener("scroll", h), u());
237
+ (s) => {
238
+ 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());
226
239
  },
227
240
  { immediate: !0, flush: "post" }
228
- ), N() && J(() => o == null ? void 0 : o()), {
241
+ ), Z() && V(() => k()), {
229
242
  showScrollToBottom: t,
230
- forceScrollToBottom: m,
231
- requestScrollToBottom: v,
232
- onReachTop: g,
233
- preserveScrollPosition: p
243
+ forceScrollToBottom: v,
244
+ requestScrollToBottom: S,
245
+ syncScrollState: p,
246
+ resetScrollState: w,
247
+ onReachTop: L,
248
+ preserveScrollPosition: x
234
249
  };
235
- }, ve = async (e, t = {}) => {
250
+ }, xe = async (e, t = {}) => {
236
251
  if (typeof window > "u" || typeof document > "u")
237
252
  return;
238
- const r = e.attachContent || {}, o = e.name || r.file_name || "download";
239
- if (r.raw) {
240
- const l = URL.createObjectURL(r.raw), n = document.createElement("a");
241
- n.href = l, n.download = o, document.body.appendChild(n), n.click(), document.body.removeChild(n), URL.revokeObjectURL(l);
253
+ const o = e.attachContent || {}, n = e.name || o.file_name || "download";
254
+ if (o.raw) {
255
+ const l = URL.createObjectURL(o.raw), r = document.createElement("a");
256
+ r.href = l, r.download = n, document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(l);
242
257
  return;
243
258
  }
244
- if (!r.fileId)
259
+ if (!o.fileId)
245
260
  return;
246
- const d = Z(r.fileId, t.baseURL, t.getFileUrl);
261
+ const d = X(o.fileId, t.baseURL, t.getFileUrl);
247
262
  if (d)
248
263
  try {
249
264
  const l = await fetch(d, { credentials: "include" });
250
265
  if (!l.ok)
251
266
  throw new Error(`Download failed with status ${l.status}`);
252
- const n = URL.createObjectURL(await l.blob()), a = document.createElement("a");
253
- a.href = n, a.download = o, document.body.appendChild(a), a.click(), document.body.removeChild(a), URL.revokeObjectURL(n);
267
+ const r = URL.createObjectURL(await l.blob()), a = document.createElement("a");
268
+ a.href = r, a.download = n, document.body.appendChild(a), a.click(), document.body.removeChild(a), URL.revokeObjectURL(r);
254
269
  } catch (l) {
255
270
  console.error("[downloadAttachment] fetch blob 失败,降级为直接链接触发:", l);
256
- const n = document.createElement("a");
257
- n.href = d, n.download = o, document.body.appendChild(n), n.click(), document.body.removeChild(n);
271
+ const r = document.createElement("a");
272
+ r.href = d, r.download = n, document.body.appendChild(r), r.click(), document.body.removeChild(r);
258
273
  }
259
274
  };
260
275
  export {
261
- fe as MarkdownContent,
262
- $ as closeImagePreview,
263
- xe as consumeStream,
264
- K as createStyleScope,
265
- ve as downloadAttachment,
266
- ae as downloadTableAsExcel,
267
- re as openImagePreview,
268
- ne as renderMarkdown,
269
- be as useAutoScroll
276
+ ke as MarkdownContent,
277
+ O as closeImagePreview,
278
+ Le as consumeStream,
279
+ ee as createStyleScope,
280
+ xe as downloadAttachment,
281
+ ie as downloadTableAsExcel,
282
+ ce as openImagePreview,
283
+ ae as renderMarkdown,
284
+ Se as useAutoScroll
270
285
  };
271
286
  //# sourceMappingURL=index.js.map
@@ -11,20 +11,28 @@ export interface OnReachTopOptions {
11
11
  * useAutoScroll 返回值
12
12
  */
13
13
  export interface UseAutoScrollReturn {
14
- /** 是否显示"回到底部"按钮(距底部超过阈值、自动滚动关闭时为 true) */
14
+ /** 是否显示"回到底部"按钮(内容有溢出、且距底部超过阈值时为 true) */
15
15
  showScrollToBottom: Ref<boolean>;
16
16
  /** 强制滚动到底部:等待渲染完成(nextTick + 一帧)后执行,并重置自动滚动状态为开启 */
17
17
  forceScrollToBottom: () => Promise<void>;
18
18
  /** 请求滚动到底部:自动滚动开启时执行强制滚动;关闭(用户上翻)时仅点亮"回到底部"按钮,不强滚 */
19
19
  requestScrollToBottom: () => Promise<void>;
20
+ /** 立即按当前滚动位置重算状态(内容被整体替换后外部可主动调用;观察器已自动触发,一般不用手调) */
21
+ syncScrollState: () => void;
22
+ /**
23
+ * 重置滚动状态:滚动位置归零、重新开启自动滚动、隐藏按钮。
24
+ * 用于「整表替换」场景(如切换会话时消息被清空),避免上一会话的按钮状态/上翻态滞留。
25
+ */
26
+ resetScrollState: () => void;
20
27
  /** 注册"滚动触顶"回调(触发一次后需离开顶部区域才能再次触发;触发期间防重入),供向上翻页加载更早历史 */
21
28
  onReachTop: (cb: () => unknown | Promise<unknown>, options?: OnReachTopOptions) => void;
22
29
  /** 在执行前插动作(如加载更早历史)期间保持相对滚动位置:action 前记录 scrollHeight,渲染后补偿 scrollTop,避免视图跳变 */
23
30
  preserveScrollPosition: (action: () => unknown | Promise<unknown>) => Promise<void>;
24
31
  }
25
32
  /**
26
- * 创建自动滚动控制句柄:监听滚动容器的滚动位置,维护"是否贴底 / 是否显示回到底部按钮"状态,
27
- * 并提供触顶回调注册与前插位置补偿;组件内使用时卸载会自动移除滚动监听。
33
+ * 创建自动滚动控制句柄:监听滚动容器的滚动位置、内容变化与容器尺寸变化,维护
34
+ * "是否贴底 / 是否显示回到底部按钮"状态,并提供触顶回调注册与前插位置补偿;
35
+ * 组件内使用时卸载会自动移除监听与观察器。
28
36
  * @param scrollEl 滚动容器元素的 ref(需指向实际发生滚动的元素;ref 值变化时自动重挂监听)
29
37
  * @returns 自动滚动控制句柄(成员说明见 UseAutoScrollReturn)
30
38
  */