reactive-md 0.0.0-stage → 0.3.1

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 (60) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/CONTRIBUTING.md +65 -0
  3. package/LICENSE +21 -0
  4. package/README.en.md +76 -0
  5. package/README.md +88 -2
  6. package/SECURITY.md +71 -0
  7. package/THIRD_PARTY_NOTICES.md +1967 -0
  8. package/dist-library/reactive-md-react.js +3649 -0
  9. package/dist-library/reactive-md.css +2 -0
  10. package/dist-library/reactive-md.js +4 -0
  11. package/dist-library/runtime-CPzMEMcW.js +11111 -0
  12. package/dist-library/types/index.d.ts +1 -0
  13. package/dist-library/types/local/LocalDocumentView.d.ts +19 -0
  14. package/dist-library/types/local/compiler.d.ts +3 -0
  15. package/dist-library/types/local/expression.d.ts +37 -0
  16. package/dist-library/types/local/heading-anchors.d.ts +6 -0
  17. package/dist-library/types/local/index.d.ts +6 -0
  18. package/dist-library/types/local/limits.d.ts +14 -0
  19. package/dist-library/types/local/math-view.d.ts +14 -0
  20. package/dist-library/types/local/math.d.ts +43 -0
  21. package/dist-library/types/local/parser.d.ts +7 -0
  22. package/dist-library/types/local/render-types.d.ts +12 -0
  23. package/dist-library/types/local/runtime.d.ts +2 -0
  24. package/dist-library/types/local/schema.d.ts +55 -0
  25. package/dist-library/types/local/types.d.ts +84 -0
  26. package/dist-library/types/local/version.d.ts +2 -0
  27. package/dist-library/types/local/visuals.d.ts +3 -0
  28. package/dist-library/types/react/index.d.ts +2 -0
  29. package/docs/compatibility.md +68 -0
  30. package/docs/component-development.md +206 -0
  31. package/docs/component-protocol.md +685 -0
  32. package/docs/local-guide.md +941 -0
  33. package/docs/local-integration.md +218 -0
  34. package/docs/local-interaction-syntax.md +439 -0
  35. package/docs/performance.md +67 -0
  36. package/docs/releasing.md +92 -0
  37. package/examples/conformance/README.md +51 -0
  38. package/examples/conformance/component-protocol-1.json +194 -0
  39. package/examples/conformance/component-protocol-1.schema.json +76 -0
  40. package/examples/conformance/local-draft-1.json +50 -0
  41. package/examples/integration/README.md +29 -0
  42. package/examples/integration/core/index.mjs +19 -0
  43. package/examples/integration/core/package.json +7 -0
  44. package/examples/integration/react/index.html +12 -0
  45. package/examples/integration/react/main.jsx +21 -0
  46. package/examples/integration/react/package.json +9 -0
  47. package/examples/local/README.md +66 -0
  48. package/examples/local/catalog.reactive.md +20 -0
  49. package/examples/local/charts.reactive.md +73 -0
  50. package/examples/local/checklist.reactive.md +32 -0
  51. package/examples/local/comparison.reactive.md +47 -0
  52. package/examples/local/components.reactive.md +44 -0
  53. package/examples/local/counter.reactive.md +7 -0
  54. package/examples/local/diagnostics.reactive.md +54 -0
  55. package/examples/local/diagram.reactive.md +44 -0
  56. package/examples/local/gallery.reactive.md +61 -0
  57. package/examples/local/parameters.reactive.md +36 -0
  58. package/examples/local/planning.reactive.md +24 -0
  59. package/examples/local/pricing.reactive.md +20 -0
  60. package/package.json +77 -6
@@ -0,0 +1,3649 @@
1
+ import { a as e, c as t, d as n, i as r, l as i, n as a, r as o, s, t as c, u as l } from "./runtime-CPzMEMcW.js";
2
+ import { Component as u, createContext as d, createElement as f, useCallback as p, useContext as m, useEffect as h, useId as g, useMemo as _, useRef as v, useState as y, useSyncExternalStore as b } from "react";
3
+ import { Fragment as x, jsx as S, jsxs as C } from "react/jsx-runtime";
4
+ // src/local/math-view.tsx
5
+ var w = (e, t, ...n) => f(e, t, ...n), T = {
6
+ " ": "space",
7
+ ",": "thinspace",
8
+ ":": "medspace",
9
+ ";": "thickspace",
10
+ "!": "negthinspace",
11
+ "{": "lbrace",
12
+ "}": "rbrace",
13
+ "|": "vert",
14
+ "%": "percent",
15
+ "&": "amp",
16
+ "#": "hash",
17
+ _: "underscore",
18
+ $: "dollar"
19
+ }, E = 5e4, D = 2e4, O = 120, k = 2e3;
20
+ function A(e) {
21
+ return e.length > k ? `${e.slice(0, k)}…` : e;
22
+ }
23
+ function j(e) {
24
+ if (e.length > E) throw Error("数学源码超过长度上限。");
25
+ let t = [], n = (e) => {
26
+ if (t.length >= D) throw Error("数学输入包含过多记号。");
27
+ t.push(e);
28
+ }, r = 0;
29
+ for (; r < e.length;) {
30
+ let t = e[r];
31
+ if (t === " " || t === " " || t === "\r" || t === "\n") r += 1;
32
+ else if (t === "%") for (; r < e.length && e[r] !== "\n";) r += 1;
33
+ else if (t === "\\") {
34
+ if (r + 1 >= e.length) {
35
+ n({
36
+ kind: "command",
37
+ value: "backslash",
38
+ offset: r
39
+ }), r += 1;
40
+ continue;
41
+ }
42
+ let t = e[r + 1];
43
+ if (t === "\\") {
44
+ n({
45
+ kind: "newline",
46
+ value: "\\\\",
47
+ offset: r
48
+ }), r += 2;
49
+ continue;
50
+ }
51
+ if (/[A-Za-z]/.test(t)) {
52
+ let t = r + 1;
53
+ for (; t < e.length && /[A-Za-z]/.test(e[t]);) t += 1;
54
+ n({
55
+ kind: "command",
56
+ value: e.slice(r + 1, t),
57
+ offset: r
58
+ }), r = t;
59
+ continue;
60
+ }
61
+ n({
62
+ kind: "command",
63
+ value: Object.hasOwn(T, t) ? T[t] : t,
64
+ offset: r
65
+ }), r += 2;
66
+ } else if (t >= "0" && t <= "9") {
67
+ let t = /^\d+(?:\.\d*)?/.exec(e.slice(r));
68
+ n({
69
+ kind: "number",
70
+ value: t[0],
71
+ offset: r
72
+ }), r += t[0].length;
73
+ } else if (t === "." && e[r + 1] >= "0" && e[r + 1] <= "9") {
74
+ let t = /^(?:\d+(?:\.\d*)?|\.\d+)/.exec(e.slice(r));
75
+ n({
76
+ kind: "number",
77
+ value: t[0],
78
+ offset: r
79
+ }), r += t[0].length;
80
+ } else /[A-Za-z]/.test(t) ? (n({
81
+ kind: "letter",
82
+ value: t,
83
+ offset: r
84
+ }), r += 1) : (n({
85
+ kind: "punct",
86
+ value: t,
87
+ offset: r
88
+ }), r += 1);
89
+ }
90
+ return n({
91
+ kind: "eof",
92
+ value: "",
93
+ offset: e.length
94
+ }), t;
95
+ }
96
+ var M = {
97
+ alpha: "α",
98
+ beta: "β",
99
+ gamma: "γ",
100
+ delta: "δ",
101
+ epsilon: "ϵ",
102
+ varepsilon: "ε",
103
+ zeta: "ζ",
104
+ eta: "η",
105
+ theta: "θ",
106
+ vartheta: "ϑ",
107
+ iota: "ι",
108
+ kappa: "κ",
109
+ lambda: "λ",
110
+ mu: "μ",
111
+ nu: "ν",
112
+ xi: "ξ",
113
+ omicron: "ο",
114
+ pi: "π",
115
+ varpi: "ϖ",
116
+ rho: "ρ",
117
+ varrho: "ϱ",
118
+ sigma: "σ",
119
+ varsigma: "ς",
120
+ tau: "τ",
121
+ upsilon: "υ",
122
+ phi: "φ",
123
+ varphi: "ϕ",
124
+ chi: "χ",
125
+ psi: "ψ",
126
+ omega: "ω",
127
+ Gamma: "Γ",
128
+ Delta: "Δ",
129
+ Theta: "Θ",
130
+ Lambda: "Λ",
131
+ Xi: "Ξ",
132
+ Pi: "Π",
133
+ Sigma: "Σ",
134
+ Upsilon: "Υ",
135
+ Phi: "Φ",
136
+ Psi: "Ψ",
137
+ Omega: "Ω"
138
+ }, N = {
139
+ cdot: "·",
140
+ times: "×",
141
+ div: "÷",
142
+ pm: "±",
143
+ mp: "∓",
144
+ le: "≤",
145
+ leq: "≤",
146
+ ge: "≥",
147
+ geq: "≥",
148
+ ne: "≠",
149
+ neq: "≠",
150
+ lt: "<",
151
+ gt: ">",
152
+ approx: "≈",
153
+ equiv: "≡",
154
+ sim: "∼",
155
+ propto: "∝",
156
+ infty: "∞",
157
+ partial: "∂",
158
+ nabla: "∇",
159
+ sum: "∑",
160
+ prod: "∏",
161
+ int: "∫",
162
+ iint: "∬",
163
+ oint: "∮",
164
+ to: "→",
165
+ rightarrow: "→",
166
+ leftarrow: "←",
167
+ Rightarrow: "⇒",
168
+ leftrightarrow: "↔",
169
+ in: "∈",
170
+ notin: "∉",
171
+ ni: "∋",
172
+ subset: "⊂",
173
+ supset: "⊃",
174
+ subseteq: "⊆",
175
+ supseteq: "⊇",
176
+ cup: "∪",
177
+ cap: "∩",
178
+ emptyset: "∅",
179
+ forall: "∀",
180
+ exists: "∃",
181
+ neg: "¬",
182
+ land: "∧",
183
+ lor: "∨",
184
+ angle: "∠",
185
+ perp: "⊥",
186
+ parallel: "∥",
187
+ degree: "°",
188
+ prime: "′",
189
+ ldots: "…",
190
+ cdots: "⋯",
191
+ dots: "…",
192
+ langle: "⟨",
193
+ rangle: "⟩",
194
+ lbrace: "{",
195
+ rbrace: "}",
196
+ vert: "|",
197
+ lvert: "|",
198
+ rvert: "|",
199
+ lVert: "‖",
200
+ rVert: "‖",
201
+ backslash: "\\",
202
+ percent: "%",
203
+ amp: "&",
204
+ hash: "#",
205
+ underscore: "_",
206
+ dollar: "$",
207
+ colon: ":"
208
+ }, P = /* @__PURE__ */ new Set([
209
+ "sin",
210
+ "cos",
211
+ "tan",
212
+ "arcsin",
213
+ "arccos",
214
+ "arctan",
215
+ "exp",
216
+ "ln",
217
+ "log",
218
+ "min",
219
+ "max",
220
+ "lim",
221
+ "det",
222
+ "sup",
223
+ "inf",
224
+ "arg",
225
+ "gcd"
226
+ ]), F = {
227
+ space: "0.25em",
228
+ thinspace: "0.167em",
229
+ medspace: "0.222em",
230
+ thickspace: "0.278em",
231
+ negthinspace: "-0.167em",
232
+ quad: "1em",
233
+ qquad: "2em",
234
+ enspace: "0.5em"
235
+ }, ee = /* @__PURE__ */ new Set([
236
+ "displaystyle",
237
+ "textstyle",
238
+ "scriptstyle",
239
+ "scriptscriptstyle",
240
+ "limits",
241
+ "nolimits"
242
+ ]), te = class {
243
+ tokens;
244
+ pos = 0;
245
+ source;
246
+ depth = 0;
247
+ constructor(e) {
248
+ this.source = e, this.tokens = j(e);
249
+ }
250
+ enter() {
251
+ if (this.depth += 1, this.depth > O) throw --this.depth, Error("数学公式嵌套过深。");
252
+ }
253
+ leave() {
254
+ --this.depth;
255
+ }
256
+ render() {
257
+ let e = this.parseRow({});
258
+ return e.length === 1 ? e[0] : w("mrow", null, ...e);
259
+ }
260
+ peek(e = 0) {
261
+ return this.tokens[Math.min(this.pos + e, this.tokens.length - 1)];
262
+ }
263
+ take() {
264
+ return this.tokens[this.pos++];
265
+ }
266
+ atPunct(e) {
267
+ let t = this.peek();
268
+ return t.kind === "punct" && t.value === e;
269
+ }
270
+ atCommand(e) {
271
+ let t = this.peek();
272
+ return t.kind === "command" && t.value === e;
273
+ }
274
+ parseRow(e) {
275
+ this.enter();
276
+ try {
277
+ let t = [];
278
+ for (;;) {
279
+ let n = this.peek();
280
+ if (n.kind === "eof" || n.kind === "punct" && e.chars?.has(n.value) || n.kind === "command" && e.commands?.has(n.value) || n.kind === "newline" && e.newline) break;
281
+ t.push(this.parseAtom());
282
+ }
283
+ return t;
284
+ } finally {
285
+ this.leave();
286
+ }
287
+ }
288
+ parseAtom() {
289
+ this.enter();
290
+ try {
291
+ return this.parseAtomBody();
292
+ } finally {
293
+ this.leave();
294
+ }
295
+ }
296
+ parseAtomBody() {
297
+ let e = this.peek(), t;
298
+ return e.kind === "number" ? (this.take(), t = w("mn", null, e.value)) : e.kind === "letter" ? (this.take(), t = w("mi", null, e.value)) : e.kind === "punct" ? t = this.parsePunctuation(e) : e.kind === "newline" ? (this.take(), t = w("mspace", { linebreak: "newline" })) : e.kind === "command" ? t = this.parseCommand(e) : (this.take(), t = w("mtext", null, "")), this.applyScripts(t);
299
+ }
300
+ parsePunctuation(e) {
301
+ return this.take(), e.value === "{" ? (--this.pos, this.parseBraceGroup()) : e.value === "}" || e.value === "&" || e.value === "#" ? w("mo", null, e.value) : w("mo", e.value === "(" || e.value === ")" || e.value === "[" || e.value === "]" || e.value === "|" ? {
302
+ fence: "true",
303
+ stretchy: "true"
304
+ } : null, e.value);
305
+ }
306
+ parseCommand(e) {
307
+ let t = e.value;
308
+ if (t === "frac" || t === "dfrac" || t === "tfrac") return this.take(), this.parseFraction();
309
+ if (t === "sqrt") return this.take(), this.parseRoot();
310
+ if (t === "left") return this.take(), this.parseLeft();
311
+ if (t === "right") return this.take(), this.readDelimiter() ?? w("mrow", null);
312
+ if (t === "begin") return this.take(), this.parseEnvironment();
313
+ if (t === "end") return this.take(), this.readRawGroup(), w("mtext", null, "\\end");
314
+ if (t === "text" || t === "textrm" || t === "mbox" || t === "operatorname") return this.take(), w("mtext", null, this.readRawGroup());
315
+ if (t === "mathrm" || t === "mathbf" || t === "mathit" || t === "mathsf") {
316
+ this.take();
317
+ let e = this.readRawGroup();
318
+ return w("mtext", { mathvariant: t === "mathrm" ? "normal" : t === "mathbf" ? "bold" : t === "mathit" ? "italic" : "sans-serif" }, e);
319
+ }
320
+ if (t === "overline" || t === "bar" || t === "hat" || t === "tilde" || t === "vec" || t === "dot" || t === "ddot") return this.take(), w("mover", { accent: "true" }, this.parseRequiredArgument(), w("mo", { stretchy: "true" }, t === "overline" || t === "bar" ? "¯" : t === "hat" ? "^" : t === "tilde" ? "~" : t === "vec" ? "→" : t === "dot" ? "˙" : "¨"));
321
+ if (ee.has(t)) return this.take(), w("mrow", null);
322
+ if (Object.hasOwn(F, t)) return this.take(), w("mspace", { width: F[t] });
323
+ if (P.has(t)) return this.take(), w("mo", {
324
+ mathvariant: "normal",
325
+ form: "prefix"
326
+ }, t);
327
+ if (Object.hasOwn(M, t)) return this.take(), w("mi", null, M[t]);
328
+ if (Object.hasOwn(N, t)) {
329
+ this.take();
330
+ let e = N[t];
331
+ return w("mo", e === "(" || e === ")" || e === "[" || e === "]" || e === "{" || e === "}" || e === "|" || e === "‖" || e === "⟨" || e === "⟩" ? {
332
+ fence: "true",
333
+ stretchy: "true"
334
+ } : null, e);
335
+ }
336
+ return this.take(), w("mtext", null, `\\${t}`);
337
+ }
338
+ parseBraceGroup() {
339
+ if (!this.atPunct("{")) return w("mrow", null);
340
+ this.take();
341
+ let e = this.parseRow({ chars: /* @__PURE__ */ new Set(["}"]) });
342
+ return this.atPunct("}") && this.take(), w("mrow", null, ...e);
343
+ }
344
+ parseFraction() {
345
+ return w("mfrac", null, this.parseRequiredArgument(), this.parseRequiredArgument());
346
+ }
347
+ parseRoot() {
348
+ let e = null;
349
+ if (this.atPunct("[")) {
350
+ this.take();
351
+ let t = this.parseRow({ chars: /* @__PURE__ */ new Set(["]"]) });
352
+ this.atPunct("]") && this.take(), e = w("mrow", null, ...t);
353
+ }
354
+ let t = this.parseRequiredArgument();
355
+ return e ? w("mroot", null, t, e) : w("msqrt", null, t);
356
+ }
357
+ parseRequiredArgument() {
358
+ return this.atPunct("{") ? this.parseBraceGroup() : this.parseAtom();
359
+ }
360
+ parseLeft() {
361
+ let e = this.readDelimiter(), t = this.parseRow({ commands: /* @__PURE__ */ new Set(["right"]) }), n = null;
362
+ return this.atCommand("right") && (this.take(), n = this.readDelimiter()), !e && !n ? w("mrow", null, ...t) : w("mrow", null, e, ...t, n);
363
+ }
364
+ readDelimiter() {
365
+ let e = this.peek();
366
+ if (e.kind === "punct") return e.value === "." ? (this.take(), null) : "()[]|".includes(e.value) ? (this.take(), w("mo", {
367
+ fence: "true",
368
+ stretchy: "true"
369
+ }, e.value)) : null;
370
+ if (e.kind === "command") {
371
+ let t = {
372
+ lbrace: "{",
373
+ rbrace: "}",
374
+ lvert: "|",
375
+ rvert: "|",
376
+ vert: "|",
377
+ lVert: "‖",
378
+ rVert: "‖",
379
+ Vert: "‖",
380
+ langle: "⟨",
381
+ rangle: "⟩"
382
+ }, n = Object.hasOwn(t, e.value) ? t[e.value] : void 0;
383
+ if (n) return this.take(), w("mo", {
384
+ fence: "true",
385
+ stretchy: "true"
386
+ }, n);
387
+ }
388
+ return null;
389
+ }
390
+ parseEnvironment() {
391
+ let e = this.readRawGroup().trim();
392
+ if (e !== "cases") return w("mtext", null, `\\begin{${e}}`);
393
+ let t = [], n = 0;
394
+ for (; !this.atCommand("end") && this.peek().kind !== "eof" && n < 500;) {
395
+ n += 1;
396
+ let e = [];
397
+ for (;;) {
398
+ let t = this.parseRow({
399
+ chars: /* @__PURE__ */ new Set(["&"]),
400
+ commands: /* @__PURE__ */ new Set(["end"]),
401
+ newline: !0
402
+ });
403
+ if (e.push(w("mtd", { columnalign: "left" }, ...t)), !this.atPunct("&")) break;
404
+ this.take();
405
+ }
406
+ if (t.push(w("mtr", null, ...e)), this.peek().kind === "newline") this.take();
407
+ else {
408
+ if (this.atCommand("end") || this.peek().kind === "eof") break;
409
+ this.take();
410
+ }
411
+ }
412
+ this.atCommand("end") && (this.take(), this.readRawGroup());
413
+ let r = w("mtable", {
414
+ columnalign: "left",
415
+ columnspacing: "1em"
416
+ }, ...t);
417
+ return w("mrow", null, w("mo", {
418
+ fence: "true",
419
+ stretchy: "true"
420
+ }, "{"), r);
421
+ }
422
+ applyScripts(e) {
423
+ let t = null, n = null, r = !1;
424
+ for (;;) if (this.atPunct("^")) this.take(), n = this.parseScriptArgument(), r = !0;
425
+ else if (this.atPunct("_")) this.take(), t = this.parseScriptArgument(), r = !0;
426
+ else break;
427
+ return r ? t !== null && n !== null ? w("msubsup", null, e, t, n) : n === null ? w("msub", null, e, t) : w("msup", null, e, n) : e;
428
+ }
429
+ parseScriptArgument() {
430
+ return this.atPunct("{") ? this.parseBraceGroup() : this.atPunct("+") || this.atPunct("-") ? w("mrow", null, w("mo", null, this.take().value), this.parseAtom()) : this.parseAtom();
431
+ }
432
+ readRawGroup() {
433
+ if (!this.atPunct("{")) return "";
434
+ let e = this.take(), t = 1, n = this.pos;
435
+ for (; n < this.tokens.length; n += 1) {
436
+ let e = this.tokens[n];
437
+ if (e.kind === "eof") break;
438
+ if (e.kind === "punct") {
439
+ if (e.value === "{") t += 1;
440
+ else if (e.value === "}" && (--t, t === 0)) break;
441
+ }
442
+ }
443
+ if (n >= this.tokens.length || this.tokens[n].kind === "eof") return this.pos = n, this.source.slice(e.offset + 1);
444
+ let r = this.tokens[n];
445
+ return this.pos = n + 1, this.source.slice(e.offset + 1, r.offset);
446
+ }
447
+ };
448
+ function ne({ source: e, display: t = !1 }) {
449
+ let n = A(e), r;
450
+ if (e.length > E) r = w("mtext", null, n);
451
+ else try {
452
+ r = new te(e).render();
453
+ } catch {
454
+ r = w("mtext", null, n);
455
+ }
456
+ let i = e.length > k ? n : e;
457
+ return w("math", {
458
+ display: t ? "block" : "inline",
459
+ className: t ? "local-math local-math-block" : "local-math",
460
+ "aria-label": i
461
+ }, w("semantics", null, w("mrow", null, r), w("annotation", { encoding: "application/x-tex" }, i)));
462
+ }
463
+ // src/local/visuals.tsx
464
+ var I = [
465
+ "var(--chart-1)",
466
+ "var(--chart-2)",
467
+ "var(--chart-3)",
468
+ "var(--chart-4)",
469
+ "var(--chart-5)",
470
+ "var(--chart-6)",
471
+ "var(--chart-7)",
472
+ "var(--chart-8)"
473
+ ], re = 520, ie = 320, ae = 520, oe = 320, se = 520, ce = 120, L = 46, le = 150, ue = 12.5, de = 10, R = 100, z = 2, fe = 15, pe = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/, me = /^\s*\{\{([\s\S]*)\}\}\s*$/;
474
+ function B(e) {
475
+ if (!Number.isFinite(e)) return "—";
476
+ if (Object.is(e, -0)) return "0";
477
+ let t = Math.abs(e);
478
+ return t >= 0xe8d4a51000 || t > 0 && t < 1e-4 ? e.toExponential(3).replace(/(\.\d*?)0+e/, "$1e").replace(/\.e/, "e") : Number(e.toFixed(6)).toString();
479
+ }
480
+ function he(e) {
481
+ if (!Number.isFinite(e)) return "—";
482
+ let t = Math.abs(e);
483
+ return t >= 1e6 || t > 0 && t < .001 ? e.toExponential(2) : Number(e.toFixed(4)).toString();
484
+ }
485
+ function V(e) {
486
+ return e instanceof Error ? e.message : String(e);
487
+ }
488
+ function H(e, t, n, r = "") {
489
+ let i = t?.[n];
490
+ if (i === void 0) return r;
491
+ try {
492
+ return e.text(i);
493
+ } catch {
494
+ return r;
495
+ }
496
+ }
497
+ function ge(e, t, n, r) {
498
+ let i = t?.[n];
499
+ if (i === void 0) return r;
500
+ let a = i.trim();
501
+ if (!a) return null;
502
+ let o = me.exec(a);
503
+ try {
504
+ let t = o ? e.evaluate(o[1].trim()) : Number(a);
505
+ return typeof t == "number" && Number.isFinite(t) ? t : null;
506
+ } catch {
507
+ return null;
508
+ }
509
+ }
510
+ function _e(e, t, n, r) {
511
+ let i = t?.[n];
512
+ if (i === void 0) return r;
513
+ let a = i.trim();
514
+ if (!a || a === "true") return !0;
515
+ if (a === "false") return !1;
516
+ let o = me.exec(a);
517
+ if (!o) return r;
518
+ try {
519
+ let t = e.evaluate(o[1].trim());
520
+ return typeof t == "boolean" ? t : r;
521
+ } catch {
522
+ return r;
523
+ }
524
+ }
525
+ function ve(e, t, n, r) {
526
+ let i = ge(e, t, n, r);
527
+ return i === null || !Number.isFinite(i) ? r : Math.trunc(i);
528
+ }
529
+ function ye(e, t) {
530
+ return e.length > t ? `${e.slice(0, Math.max(1, t - 1))}…` : e;
531
+ }
532
+ function be(e, t = 8, n = 2) {
533
+ if (!e) return [""];
534
+ let r = [], i = e;
535
+ for (; i && r.length < n - 1;) r.push(i.slice(0, t)), i = i.slice(t);
536
+ return (i || r.length === 0) && r.push(i.length > t ? `${i.slice(0, Math.max(1, t - 1))}…` : i), r;
537
+ }
538
+ function xe(e, t) {
539
+ let n = Array.from(e), r = Array.from(t), i = Math.min(n.length, r.length);
540
+ for (let e = 0; e < i; e += 1) {
541
+ let t = (n[e].codePointAt(0) ?? 0) - (r[e].codePointAt(0) ?? 0);
542
+ if (t !== 0) return t;
543
+ }
544
+ return n.length - r.length;
545
+ }
546
+ function Se(e, t, n = 5) {
547
+ if (!Number.isFinite(e) || !Number.isFinite(t) || t <= e) return [e];
548
+ let r = (t - e) / Math.max(1, n - 1), i = 10 ** Math.floor(Math.log10(r)), a = r / i, o = (a <= 1 ? 1 : a <= 2 ? 2 : a <= 5 ? 5 : 10) * i, s = Math.ceil(e / o) * o, c = [];
549
+ for (let e = s; e <= t + o * 1e-9 && c.length < 40; e += o) c.push(Number(e.toFixed(10)));
550
+ return c;
551
+ }
552
+ function Ce(e, t) {
553
+ let n = Infinity, r = -Infinity;
554
+ for (let t of e) Number.isFinite(t) && (t < n && (n = t), t > r && (r = t));
555
+ if (!Number.isFinite(n) || !Number.isFinite(r)) return {
556
+ min: 0,
557
+ max: 1
558
+ };
559
+ if (t && (n = Math.min(n, 0), r = Math.max(r, 0)), n === r) {
560
+ let e = Math.abs(n) > 0 ? Math.abs(n) * .15 : 1;
561
+ n -= e, r += e;
562
+ } else {
563
+ let e = (r - n) * .06;
564
+ n -= e, r += e, t && (n = Math.min(n, 0), r = Math.max(r, 0));
565
+ }
566
+ return {
567
+ min: n,
568
+ max: r
569
+ };
570
+ }
571
+ function we(e, t) {
572
+ return Math.max(46, ...e.map((e) => he(e).length * 6 + (t ? 24 : 10)));
573
+ }
574
+ function Te(e, t, n) {
575
+ let r = e.currentTarget, i = r.ownerSVGElement ?? r.closest("svg");
576
+ if (!i) return;
577
+ let a = Array.from(i.querySelectorAll(t)), o = a.indexOf(r);
578
+ o < 0 || a.length === 0 || (e.preventDefault(), a[(o + n + a.length) % a.length]?.focus());
579
+ }
580
+ function Ee(e) {
581
+ return e.key === "Enter" || e.key === " " || e.key === "Spacebar";
582
+ }
583
+ function De(e) {
584
+ return e === null ? {
585
+ text: "",
586
+ kind: "null",
587
+ error: null
588
+ } : typeof e == "string" ? {
589
+ text: e,
590
+ kind: "string",
591
+ error: null
592
+ } : typeof e == "number" ? Number.isFinite(e) ? {
593
+ text: B(e),
594
+ kind: "number",
595
+ error: null
596
+ } : {
597
+ text: "无法计算",
598
+ kind: "error",
599
+ error: "结果不是有限数字"
600
+ } : typeof e == "boolean" ? {
601
+ text: e ? "true" : "false",
602
+ kind: "boolean",
603
+ error: null
604
+ } : {
605
+ text: "无法计算",
606
+ kind: "array",
607
+ error: "数组需要先用 len 等函数转换"
608
+ };
609
+ }
610
+ function Oe(e, t) {
611
+ let n = "", r = null;
612
+ for (let i of e ?? []) if (i.type === "text" || i.type === "inlineCode" || i.type === "code") n += i.value ?? "";
613
+ else if (i.type === "interpolation") try {
614
+ let e = De(t.evaluate((i.value ?? "").trim()));
615
+ e.error && (r ??= e.error), n += e.text;
616
+ } catch (e) {
617
+ r ??= V(e), n += "无法计算";
618
+ }
619
+ else if (i.type === "inlineMath" || i.type === "math") n += i.value ?? "";
620
+ else if (i.type === "image") n += i.alt ?? "";
621
+ else if (i.children && i.children.length > 0) {
622
+ let e = Oe(i.children, t);
623
+ n += e.text, r ??= e.error;
624
+ } else i.value && (n += i.value);
625
+ return {
626
+ text: n,
627
+ error: r
628
+ };
629
+ }
630
+ function ke(e, t) {
631
+ let n = e.children ?? [], r = n.filter((e) => !(e.type === "text" && !(e.value ?? "").trim()));
632
+ if (r.length === 1 && r[0].type === "interpolation") try {
633
+ let i = t.evaluate((r[0].value ?? "").trim()), a = De(i);
634
+ return {
635
+ node: e,
636
+ children: n,
637
+ text: a.text,
638
+ value: i,
639
+ kind: a.kind,
640
+ numeric: a.kind === "number" ? i : null,
641
+ error: a.error
642
+ };
643
+ } catch (t) {
644
+ return {
645
+ node: e,
646
+ children: n,
647
+ text: "无法计算",
648
+ value: void 0,
649
+ kind: "error",
650
+ numeric: null,
651
+ error: V(t)
652
+ };
653
+ }
654
+ let i = Oe(n, t);
655
+ if (r.length > 0 && r.every((e) => e.type === "text") && pe.test(i.text.trim())) {
656
+ let t = Number(i.text.trim());
657
+ if (Number.isFinite(t)) return {
658
+ node: e,
659
+ children: n,
660
+ text: i.text,
661
+ value: t,
662
+ kind: "number",
663
+ numeric: t,
664
+ error: null
665
+ };
666
+ }
667
+ let a = !i.text.trim() && !i.error;
668
+ return {
669
+ node: e,
670
+ children: n,
671
+ text: i.error ? "无法计算" : i.text,
672
+ value: i.text,
673
+ kind: i.error ? "error" : a ? "empty" : "string",
674
+ numeric: null,
675
+ error: i.error
676
+ };
677
+ }
678
+ function Ae(e) {
679
+ return e ? e.error ? "无法计算" : e.text : "";
680
+ }
681
+ function je(e, t) {
682
+ let n = e.children?.find((e) => e.type === "table");
683
+ if (!n) return null;
684
+ let r = n.children?.filter((e) => e.type === "tableRow") ?? [];
685
+ if (r.length === 0) return null;
686
+ let i = (r[0].children ?? []).map((e) => ke(e, t));
687
+ return {
688
+ tableNode: n,
689
+ header: i,
690
+ headerText: i.map(Ae),
691
+ rows: r.slice(1).map((e, n) => ({
692
+ index: n,
693
+ cells: (e.children ?? []).map((e) => ke(e, t))
694
+ }))
695
+ };
696
+ }
697
+ function Me(e, t) {
698
+ let n = !1;
699
+ for (let r of e.rows) {
700
+ let e = r.cells[t];
701
+ if (e && e.kind !== "empty") {
702
+ if (e.numeric === null) return !1;
703
+ n = !0;
704
+ }
705
+ }
706
+ return n;
707
+ }
708
+ function U({ className: e, label: t, children: n }) {
709
+ let r = g();
710
+ return /* @__PURE__ */ C("figure", {
711
+ className: `local-visual ${e}`,
712
+ "aria-labelledby": r,
713
+ children: [/* @__PURE__ */ S("figcaption", {
714
+ id: r,
715
+ className: "local-visual-title",
716
+ children: t
717
+ }), n]
718
+ });
719
+ }
720
+ function W({ message: e, kind: t = "status" }) {
721
+ return /* @__PURE__ */ S("p", {
722
+ className: `local-visual-message local-visual-${t}`,
723
+ role: t,
724
+ children: e
725
+ });
726
+ }
727
+ function Ne({ notes: e }) {
728
+ return e.length === 0 ? null : /* @__PURE__ */ S("ul", {
729
+ className: "local-visual-notes",
730
+ role: "status",
731
+ children: e.map((e, t) => /* @__PURE__ */ S("li", { children: e }, `${e}-${t}`))
732
+ });
733
+ }
734
+ function Pe({ items: e, hidden: t, onToggle: n, label: r }) {
735
+ return /* @__PURE__ */ S("div", {
736
+ className: "local-visual-legend",
737
+ role: "group",
738
+ "aria-label": r,
739
+ children: e.map((e, r) => {
740
+ let i = t.has(r);
741
+ return /* @__PURE__ */ C("button", {
742
+ type: "button",
743
+ className: `local-visual-legend-item${i ? " is-off" : ""}`,
744
+ "aria-pressed": !i,
745
+ disabled: e.disabled,
746
+ onClick: () => n(r),
747
+ title: i ? `显示 ${e.name}` : `隐藏 ${e.name}`,
748
+ children: [/* @__PURE__ */ S("span", {
749
+ className: "local-visual-swatch",
750
+ style: { backgroundColor: e.color },
751
+ "aria-hidden": "true"
752
+ }), /* @__PURE__ */ C("span", {
753
+ className: "local-visual-legend-text",
754
+ children: [e.name, e.detail ? `(${e.detail})` : ""]
755
+ })]
756
+ }, `${e.name}-${r}`);
757
+ })
758
+ });
759
+ }
760
+ function Fe({ node: e, runtime: t, render: n }) {
761
+ let [r, i] = y(""), [a, o] = y(null), [s, c] = y(1), l = t.resetToken(e);
762
+ h(() => {
763
+ i(""), o(null), c(1);
764
+ }, [l]);
765
+ let u = H(t, e.attrs, "label", "表格"), d = _e(t, e.attrs, "searchable", !0), f = _e(t, e.attrs, "sortable", !0), p = ve(t, e.attrs, "page-size", 10), m = Math.max(1, p), g = je(e, t);
766
+ if (!g || g.header.length === 0) return /* @__PURE__ */ S(U, {
767
+ className: "local-visual-table-block",
768
+ label: u,
769
+ children: /* @__PURE__ */ S(W, {
770
+ message: "表格需要一个非空的 Markdown 表格。",
771
+ kind: "alert"
772
+ })
773
+ });
774
+ let _ = g.header.map((e, t) => Me(g, t)), v = r.trim().toLowerCase(), b = [...g.rows.filter((e) => !v || e.cells.some((e) => Ae(e).toLowerCase().includes(v)))];
775
+ if (a) {
776
+ let e = _[a.column];
777
+ b.sort((t, n) => {
778
+ let r = t.cells[a.column], i = n.cells[a.column], o;
779
+ if (e) {
780
+ let e = r?.numeric ?? -Infinity, t = i?.numeric ?? -Infinity;
781
+ o = e === t ? 0 : e < t ? -1 : 1;
782
+ } else o = xe(Ae(r), Ae(i));
783
+ return o === 0 ? t.index - n.index : a.direction === "asc" ? o : -o;
784
+ });
785
+ }
786
+ let x = Math.max(1, Math.ceil(b.length / m)), w = Math.min(s, x), T = b.slice((w - 1) * m, w * m), E = (e) => {
787
+ c(1), o((t) => !t || t.column !== e ? {
788
+ column: e,
789
+ direction: "asc"
790
+ } : t.direction === "asc" ? {
791
+ column: e,
792
+ direction: "desc"
793
+ } : null);
794
+ }, D = (e) => !a || a.column !== e ? "" : a.direction === "asc" ? "(升序)" : "(降序)";
795
+ return /* @__PURE__ */ C(U, {
796
+ className: "local-visual-table-block",
797
+ label: u,
798
+ children: [
799
+ d ? /* @__PURE__ */ C("label", {
800
+ className: "local-visual-search",
801
+ children: [/* @__PURE__ */ S("span", { children: "搜索" }), /* @__PURE__ */ S("input", {
802
+ type: "search",
803
+ value: r,
804
+ placeholder: "搜索所有列",
805
+ "aria-label": `搜索${u}`,
806
+ onChange: (e) => {
807
+ i(e.target.value), c(1);
808
+ }
809
+ })]
810
+ }) : null,
811
+ /* @__PURE__ */ S("div", {
812
+ className: "local-visual-table-scroll",
813
+ children: /* @__PURE__ */ C("table", {
814
+ className: "local-visual-table",
815
+ children: [
816
+ /* @__PURE__ */ S("caption", {
817
+ className: "local-visual-sr-only",
818
+ children: u
819
+ }),
820
+ /* @__PURE__ */ S("thead", { children: /* @__PURE__ */ S("tr", { children: g.header.map((e, t) => {
821
+ let n = a && a.column === t ? a.direction === "asc" ? "ascending" : "descending" : "none";
822
+ return /* @__PURE__ */ S("th", {
823
+ scope: "col",
824
+ "aria-sort": n,
825
+ className: _[t] ? "is-numeric" : void 0,
826
+ children: f ? /* @__PURE__ */ C("button", {
827
+ type: "button",
828
+ className: `local-visual-sort-button${a && a.column === t ? " is-sorted" : ""}`,
829
+ onClick: () => E(t),
830
+ title: "点击切换升序、降序和原始顺序",
831
+ children: [Ae(e), D(t)]
832
+ }) : Ae(e)
833
+ }, `head-${t}`);
834
+ }) }) }),
835
+ /* @__PURE__ */ S("tbody", { children: T.map((e) => /* @__PURE__ */ S("tr", { children: g.header.map((t, r) => {
836
+ let i = e.cells[r];
837
+ return /* @__PURE__ */ S("td", {
838
+ className: _[r] ? "is-numeric" : void 0,
839
+ children: i?.error ? /* @__PURE__ */ S("span", {
840
+ className: "local-visual-cell-error",
841
+ title: i.error,
842
+ children: "无法计算"
843
+ }) : n(i?.children ?? [])
844
+ }, `cell-${e.index}-${r}`);
845
+ }) }, `row-${e.index}`)) })
846
+ ]
847
+ })
848
+ }),
849
+ b.length === 0 ? /* @__PURE__ */ S(W, { message: "没有匹配结果" }) : null,
850
+ x > 1 ? /* @__PURE__ */ C("nav", {
851
+ className: "local-visual-pagination",
852
+ "aria-label": "表格分页",
853
+ children: [
854
+ /* @__PURE__ */ S("button", {
855
+ type: "button",
856
+ disabled: w <= 1,
857
+ onClick: () => c((e) => Math.max(1, e - 1)),
858
+ children: "上一页"
859
+ }),
860
+ /* @__PURE__ */ C("span", { children: [
861
+ "第 ",
862
+ w,
863
+ " / ",
864
+ x,
865
+ " 页 · 共 ",
866
+ b.length,
867
+ " 行"
868
+ ] }),
869
+ /* @__PURE__ */ S("button", {
870
+ type: "button",
871
+ disabled: w >= x,
872
+ onClick: () => c((e) => Math.min(x, e + 1)),
873
+ children: "下一页"
874
+ })
875
+ ]
876
+ }) : null
877
+ ]
878
+ });
879
+ }
880
+ var Ie = [
881
+ "bar",
882
+ "line",
883
+ "area",
884
+ "scatter",
885
+ "donut"
886
+ ];
887
+ function Le(e, t, n, r, i, a) {
888
+ let o = (n, r) => [e + n * Math.cos(r), t + n * Math.sin(r)], [s, c] = o(n, i), [l, u] = o(n, a), [d, f] = o(r, a), [p, m] = o(r, i), h = +(a - i > Math.PI);
889
+ return [
890
+ `M ${s} ${c}`,
891
+ `A ${n} ${n} 0 ${h} 1 ${l} ${u}`,
892
+ `L ${d} ${f}`,
893
+ `A ${r} ${r} 0 ${h} 0 ${p} ${m}`,
894
+ "Z"
895
+ ].join(" ");
896
+ }
897
+ function Re({ node: e, runtime: t }) {
898
+ let [n, r] = y(/* @__PURE__ */ new Set()), [i, a] = y(/* @__PURE__ */ new Set()), [o, s] = y(null), c = t.resetToken(e);
899
+ h(() => {
900
+ r(/* @__PURE__ */ new Set()), a(/* @__PURE__ */ new Set()), s(null);
901
+ }, [c]);
902
+ let l = g(), u = H(t, e.attrs, "title", "") || H(t, e.attrs, "label", "") || "图表", d = (e.attrs?.kind ?? "bar").trim().toLowerCase(), f = Ie.includes(d) ? d : null, p = H(t, e.attrs, "x-label", ""), m = H(t, e.attrs, "y-label", ""), _ = je(e, t);
903
+ if (!_ || _.header.length === 0) return /* @__PURE__ */ S(U, {
904
+ className: "local-visual-chart",
905
+ label: u,
906
+ children: /* @__PURE__ */ S(W, {
907
+ message: "chart 正文需要一个非空的 Markdown 表格。",
908
+ kind: "alert"
909
+ })
910
+ });
911
+ let v = _.headerText.map((e) => e.trim()), b = _.rows.map((e) => ({
912
+ index: e.index,
913
+ cells: e.cells,
914
+ texts: v.map((t, n) => Ae(e.cells[n]))
915
+ }));
916
+ if (!f) return /* @__PURE__ */ S(U, {
917
+ className: "local-visual-chart",
918
+ label: u,
919
+ children: /* @__PURE__ */ S(W, {
920
+ message: `未知图表类型“${d}”。`,
921
+ kind: "alert"
922
+ })
923
+ });
924
+ let x = [], w = [], T = (e.attrs?.x ?? "").trim(), E = T ? v.indexOf(T) : 0;
925
+ (E < 0 || E >= v.length) && w.push(`x 列“${T}”不存在。`);
926
+ let D = (e.attrs?.y ?? "").split(",").map((e) => e.trim()).filter(Boolean), O = [];
927
+ if (f === "donut") {
928
+ if (D.length > 1) w.push("donut 只能使用一个数值列,请在 y 中指定唯一列。");
929
+ else if (D.length === 1) {
930
+ let e = v.indexOf(D[0]);
931
+ e < 0 ? w.push(`y 列“${D[0]}”不存在。`) : O = [e];
932
+ } else v.length === 2 ? O = [1] : w.push("donut 多于两列时必须用 y 指定唯一数值列。");
933
+ } else if (D.length > 0) for (let e of D) {
934
+ let t = v.indexOf(e);
935
+ t < 0 ? w.push(`y 列“${e}”不存在。`) : O.includes(t) || O.push(t);
936
+ }
937
+ else O = v.map((e, t) => t).filter((e) => e !== E);
938
+ if (w.length === 0 && O.length === 0 && w.push("图表至少需要一个数值系列。"), w.length > 0) return /* @__PURE__ */ S(U, {
939
+ className: `local-visual-chart local-visual-chart-${f}`,
940
+ label: u,
941
+ children: w.map((e, t) => /* @__PURE__ */ S(W, {
942
+ message: e,
943
+ kind: "alert"
944
+ }, `${e}-${t}`))
945
+ });
946
+ let k = O.map((e) => v[e] || `系列 ${e + 1}`), A = 0, j = 0, M = b.map((e) => {
947
+ let t = e.cells[E], n = e.texts[E] || `第 ${e.index + 1} 项`, r = t && t.numeric !== null ? t.numeric : null, i = O.map((t) => {
948
+ let n = e.cells[t];
949
+ return !n || n.kind === "empty" || n.numeric === null ? (A += 1, null) : (f === "donut" && n.numeric < 0 && (j += 1), n.numeric);
950
+ });
951
+ return {
952
+ index: e.index,
953
+ label: n,
954
+ xValue: r,
955
+ values: i,
956
+ cells: e.cells
957
+ };
958
+ });
959
+ A > 0 && x.push(`${A} 个数值为空或无法计算,图表中保留空缺。`);
960
+ for (let e of O) Me(_, e) || x.push(`列“${v[e]}”不是纯数值列,非数值按空缺处理。`);
961
+ f === "donut" && j > 0 && x.push(`环形图数值必须非负,已忽略 ${j} 个负值。`), f === "scatter" && !Me(_, E) && x.push(`scatter 的横轴列“${v[E]}”需要数值。`);
962
+ let N = (e) => {
963
+ s(null), r((t) => {
964
+ let n = new Set(t);
965
+ return n.has(e) ? n.delete(e) : n.add(e), n;
966
+ });
967
+ }, P = (e) => {
968
+ s(null), a((t) => {
969
+ let n = new Set(t);
970
+ return n.has(e) ? n.delete(e) : n.add(e), n;
971
+ });
972
+ }, F = k.map((e, t) => ({
973
+ name: e,
974
+ color: I[t % I.length]
975
+ }));
976
+ if (f === "donut") {
977
+ let e = M.map((e) => e.values[0]), t = e.map((e) => e !== null && e >= 0 ? e : 0), n = t.reduce((e, t, n) => i.has(n) ? e : e + t, 0), r = M.map((n, r) => ({
978
+ name: n.label,
979
+ color: I[r % I.length],
980
+ detail: e[r] === null ? "—" : B(e[r]),
981
+ disabled: t[r] <= 0
982
+ }));
983
+ if (n <= 0) return /* @__PURE__ */ C(U, {
984
+ className: "local-visual-chart local-visual-chart-donut",
985
+ label: u,
986
+ children: [
987
+ /* @__PURE__ */ S(W, { message: "暂无占比" }),
988
+ /* @__PURE__ */ S(Ne, { notes: x }),
989
+ /* @__PURE__ */ S(Pe, {
990
+ items: r,
991
+ hidden: i,
992
+ onToggle: P,
993
+ label: "图例"
994
+ })
995
+ ]
996
+ });
997
+ let a = re / 2, c = -Math.PI / 2, d = [];
998
+ M.forEach((e, r) => {
999
+ if (i.has(r)) return;
1000
+ let o = t[r];
1001
+ if (o <= 0) return;
1002
+ let s = o / n * Math.PI * 2, l = c, u = c + s;
1003
+ c = u, d.push({
1004
+ key: `donut:${r}`,
1005
+ label: e.label,
1006
+ value: o,
1007
+ start: l,
1008
+ end: u,
1009
+ color: I[r % I.length],
1010
+ x: a,
1011
+ y: 140
1012
+ });
1013
+ });
1014
+ let f = o ? `${o.label}:${B(o.value)}` : "聚焦扇区或图例查看数值";
1015
+ return /* @__PURE__ */ C(U, {
1016
+ className: "local-visual-chart local-visual-chart-donut",
1017
+ label: u,
1018
+ children: [
1019
+ /* @__PURE__ */ S("div", {
1020
+ className: "local-visual-readout",
1021
+ id: l,
1022
+ "aria-live": "polite",
1023
+ children: f
1024
+ }),
1025
+ /* @__PURE__ */ S("div", {
1026
+ className: "local-visual-svg-wrap",
1027
+ children: /* @__PURE__ */ C("svg", {
1028
+ className: "local-visual-svg",
1029
+ viewBox: `0 0 ${re} 290`,
1030
+ role: "group",
1031
+ "aria-label": `${u},环形图,共 ${M.length} 项`,
1032
+ "aria-describedby": l,
1033
+ children: [/* @__PURE__ */ C("g", {
1034
+ className: "local-visual-donut-center",
1035
+ "aria-hidden": "true",
1036
+ children: [/* @__PURE__ */ S("text", {
1037
+ x: a,
1038
+ y: 138,
1039
+ textAnchor: "middle",
1040
+ className: "local-visual-donut-total",
1041
+ children: B(n)
1042
+ }), /* @__PURE__ */ S("text", {
1043
+ x: a,
1044
+ y: 158,
1045
+ textAnchor: "middle",
1046
+ className: "local-visual-donut-caption",
1047
+ children: ye(k[0], 14)
1048
+ })]
1049
+ }), d.map((e) => {
1050
+ let t = {
1051
+ key: e.key,
1052
+ series: k[0],
1053
+ label: e.label,
1054
+ value: e.value,
1055
+ x: e.x,
1056
+ y: e.y
1057
+ }, n = {
1058
+ "data-chart-mark": "",
1059
+ tabIndex: 0,
1060
+ role: "img",
1061
+ "aria-label": `${e.label}:${B(e.value)}`,
1062
+ onFocus: () => s(t),
1063
+ onBlur: () => s(null),
1064
+ onPointerEnter: () => s(t),
1065
+ onPointerLeave: () => s(null),
1066
+ onKeyDown: (e) => {
1067
+ e.key === "ArrowRight" || e.key === "ArrowDown" ? Te(e, "[data-chart-mark]", 1) : (e.key === "ArrowLeft" || e.key === "ArrowUp") && Te(e, "[data-chart-mark]", -1);
1068
+ }
1069
+ };
1070
+ return e.end - e.start >= Math.PI * 2 - 1e-6 ? /* @__PURE__ */ S("circle", {
1071
+ className: "local-visual-donut-slice",
1072
+ cx: a,
1073
+ cy: 140,
1074
+ r: 78,
1075
+ fill: "none",
1076
+ style: { stroke: e.color },
1077
+ strokeWidth: 40,
1078
+ ...n,
1079
+ children: /* @__PURE__ */ S("title", { children: `${e.label}:${B(e.value)}` })
1080
+ }, e.key) : /* @__PURE__ */ S("path", {
1081
+ className: "local-visual-donut-slice",
1082
+ d: Le(a, 140, 98, 58, e.start, e.end),
1083
+ style: { fill: e.color },
1084
+ ...n,
1085
+ children: /* @__PURE__ */ S("title", { children: `${e.label}:${B(e.value)}` })
1086
+ }, e.key);
1087
+ })]
1088
+ })
1089
+ }),
1090
+ /* @__PURE__ */ S(Pe, {
1091
+ items: r,
1092
+ hidden: i,
1093
+ onToggle: P,
1094
+ label: "图例,可开关扇区"
1095
+ }),
1096
+ /* @__PURE__ */ S(Ne, { notes: x })
1097
+ ]
1098
+ });
1099
+ }
1100
+ let ee = k.map((e, t) => t).filter((e) => !n.has(e));
1101
+ if (ee.length === 0) return /* @__PURE__ */ C(U, {
1102
+ className: `local-visual-chart local-visual-chart-${f}`,
1103
+ label: u,
1104
+ children: [/* @__PURE__ */ S(W, { message: "所有系列已在图例中关闭" }), /* @__PURE__ */ S(Pe, {
1105
+ items: F,
1106
+ hidden: n,
1107
+ onToggle: N,
1108
+ label: "图例,可开关系列"
1109
+ })]
1110
+ });
1111
+ let te = Me(_, E), ne = f === "scatter" ? !0 : f === "line" || f === "area" ? te : !1, ae = ne ? M.filter((e) => e.xValue !== null) : M;
1112
+ ne && ae.length < M.length && x.push(`${M.length - ae.length} 行横轴为空或不是数值,未参与绘制。`);
1113
+ let oe = [];
1114
+ for (let e of ae) for (let t of ee) {
1115
+ let n = e.values[t];
1116
+ n !== null && oe.push(n);
1117
+ }
1118
+ if (ae.length === 0) return /* @__PURE__ */ C(U, {
1119
+ className: `local-visual-chart local-visual-chart-${f}`,
1120
+ label: u,
1121
+ children: [
1122
+ /* @__PURE__ */ S(W, { message: "没有可绘制的数据行" }),
1123
+ /* @__PURE__ */ S(Ne, { notes: x }),
1124
+ /* @__PURE__ */ S(Pe, {
1125
+ items: F,
1126
+ hidden: n,
1127
+ onToggle: N,
1128
+ label: "图例,可开关系列"
1129
+ })
1130
+ ]
1131
+ });
1132
+ if (oe.length === 0) return /* @__PURE__ */ C(U, {
1133
+ className: `local-visual-chart local-visual-chart-${f}`,
1134
+ label: u,
1135
+ children: [
1136
+ /* @__PURE__ */ S(W, { message: "没有可读取的数值" }),
1137
+ /* @__PURE__ */ S(Ne, { notes: x }),
1138
+ /* @__PURE__ */ S(Pe, {
1139
+ items: F,
1140
+ hidden: n,
1141
+ onToggle: N,
1142
+ label: "图例,可开关系列"
1143
+ })
1144
+ ]
1145
+ });
1146
+ let se = Ce(oe, f === "bar" || f === "area"), ce = Se(se.min, se.max, 5), L = we(ce, !!m), le = 506 - L, ue = (e) => 16 + (se.max - e) / (se.max - se.min) * 258, de = ue(Math.max(se.min, Math.min(se.max, 0))), R = ne && ae.length > 0 ? Ce(ae.map((e) => e.xValue).filter((e) => e !== null), !1) : null, z = le / Math.max(1, M.length), fe = (e) => L + z * (e + .5), pe = (e) => L + (e - R.min) / (R.max - R.min) * le, me = (e, t) => R ? e.xValue === null ? null : pe(e.xValue) : fe(t), V = [];
1147
+ if (R) V.push(...Se(R.min, R.max, 5));
1148
+ else {
1149
+ let e = Math.max(1, Math.ceil(M.length / 6));
1150
+ for (let t = 0; t < M.length; t += e) V.push(t);
1151
+ let t = M.length - 1;
1152
+ t >= 0 && V[V.length - 1] !== t && (V.length > 1 && t - V[V.length - 1] < e * .6 ? V[V.length - 1] = t : V.push(t));
1153
+ }
1154
+ let ge = (e) => R ? L + (e - R.min) / (R.max - R.min) * le : fe(e), _e = o && !R ? null : o ? /* @__PURE__ */ S("line", {
1155
+ className: "local-visual-guide",
1156
+ x1: Math.max(L, Math.min(506, o.x)),
1157
+ x2: Math.max(L, Math.min(506, o.x)),
1158
+ y1: 16,
1159
+ y2: 274
1160
+ }) : null, ve = (e) => ({
1161
+ "data-chart-mark": "",
1162
+ tabIndex: 0,
1163
+ role: "img",
1164
+ "aria-label": `${e.series},${e.label}:${B(e.value)}`,
1165
+ onFocus: () => s(e),
1166
+ onBlur: () => s(null),
1167
+ onPointerEnter: () => s(e),
1168
+ onPointerLeave: () => s(null),
1169
+ onKeyDown: (e) => {
1170
+ e.key === "ArrowRight" || e.key === "ArrowDown" ? Te(e, "[data-chart-mark]", 1) : (e.key === "ArrowLeft" || e.key === "ArrowUp") && Te(e, "[data-chart-mark]", -1);
1171
+ }
1172
+ }), be = (e, t, n, r, i) => ({
1173
+ key: `${e}:${t.index}`,
1174
+ series: k[e],
1175
+ label: t.label,
1176
+ value: n,
1177
+ x: r,
1178
+ y: i
1179
+ }), xe = [];
1180
+ if (f === "bar") {
1181
+ let e = z * .76, t = Math.max(1, e / Math.max(1, ee.length));
1182
+ M.forEach((n, r) => {
1183
+ ee.forEach((i, a) => {
1184
+ let o = n.values[i];
1185
+ if (o === null) return;
1186
+ let s = L + z * r + (z - e) / 2 + a * t, c = Math.max(1, Math.abs(ue(o) - de)), l = o >= 0 ? de - c : de, u = be(i, n, o, s + t / 2, l + c / 2);
1187
+ xe.push(/* @__PURE__ */ S("rect", {
1188
+ className: "local-visual-bar",
1189
+ x: s,
1190
+ y: l,
1191
+ width: Math.max(1.5, t - 1),
1192
+ height: c,
1193
+ rx: 2,
1194
+ style: { fill: I[i % I.length] },
1195
+ ...ve(u),
1196
+ children: /* @__PURE__ */ S("title", { children: `${u.series},${u.label}:${B(u.value)}` })
1197
+ }, `bar-${i}-${n.index}`));
1198
+ });
1199
+ });
1200
+ }
1201
+ let Ee = [], De = [], Oe = [];
1202
+ if (f === "line" || f === "area") for (let e of ee) {
1203
+ let t = [], n = [], r = () => {
1204
+ n.length > 0 && t.push(n), n = [];
1205
+ };
1206
+ M.forEach((t, i) => {
1207
+ let a = t.values[e], o = me(t, i);
1208
+ a === null || o === null ? r() : n.push({
1209
+ row: t,
1210
+ value: a,
1211
+ x: o,
1212
+ y: ue(a)
1213
+ });
1214
+ }), r();
1215
+ for (let n of t) {
1216
+ if (n.length >= 2) {
1217
+ let t = n.map((e, t) => `${t === 0 ? "M" : "L"} ${e.x} ${e.y}`).join(" ");
1218
+ if (Ee.push(/* @__PURE__ */ S("path", {
1219
+ className: "local-visual-line",
1220
+ d: t,
1221
+ fill: "none",
1222
+ style: { stroke: I[e % I.length] },
1223
+ strokeWidth: 2.4,
1224
+ strokeLinejoin: "round",
1225
+ strokeLinecap: "round"
1226
+ }, `line-${e}-${n[0].row.index}`)), f === "area") {
1227
+ let t = de, r = n[0], i = n[n.length - 1], a = `M ${r.x} ${t} ${n.map((e) => `L ${e.x} ${e.y}`).join(" ")} L ${i.x} ${t} Z`;
1228
+ De.push(/* @__PURE__ */ S("path", {
1229
+ className: "local-visual-area",
1230
+ d: a,
1231
+ style: { fill: I[e % I.length] }
1232
+ }, `area-${e}-${r.row.index}`));
1233
+ }
1234
+ }
1235
+ for (let t of n) {
1236
+ let n = be(e, t.row, t.value, t.x, t.y);
1237
+ Oe.push(/* @__PURE__ */ C("g", {
1238
+ className: "local-visual-point-group",
1239
+ children: [/* @__PURE__ */ S("circle", {
1240
+ className: "local-visual-hit",
1241
+ cx: t.x,
1242
+ cy: t.y,
1243
+ r: 12,
1244
+ fill: "transparent",
1245
+ ...ve(n),
1246
+ children: /* @__PURE__ */ S("title", { children: `${n.series},${n.label}:${B(n.value)}` })
1247
+ }), /* @__PURE__ */ S("circle", {
1248
+ className: "local-visual-point",
1249
+ cx: t.x,
1250
+ cy: t.y,
1251
+ r: 4.5,
1252
+ style: {
1253
+ fill: I[e % I.length],
1254
+ stroke: "var(--surface)"
1255
+ },
1256
+ strokeWidth: 1.5,
1257
+ pointerEvents: "none"
1258
+ })]
1259
+ }, `point-${e}-${t.row.index}`));
1260
+ }
1261
+ }
1262
+ }
1263
+ f === "scatter" && M.forEach((e, t) => {
1264
+ let n = me(e, t);
1265
+ n !== null && ee.forEach((t) => {
1266
+ let r = e.values[t];
1267
+ if (r === null) return;
1268
+ let i = ue(r), a = be(t, e, r, n, i);
1269
+ Oe.push(/* @__PURE__ */ C("g", {
1270
+ className: "local-visual-point-group",
1271
+ children: [/* @__PURE__ */ S("circle", {
1272
+ className: "local-visual-hit",
1273
+ cx: n,
1274
+ cy: i,
1275
+ r: 15,
1276
+ fill: "transparent",
1277
+ ...ve(a),
1278
+ children: /* @__PURE__ */ S("title", { children: `${a.series},${a.label}:${B(a.value)}` })
1279
+ }), /* @__PURE__ */ S("circle", {
1280
+ className: "local-visual-point",
1281
+ cx: n,
1282
+ cy: i,
1283
+ r: 6,
1284
+ style: {
1285
+ fill: I[t % I.length],
1286
+ stroke: "var(--surface)"
1287
+ },
1288
+ strokeWidth: 1.5,
1289
+ pointerEvents: "none"
1290
+ })]
1291
+ }, `scatter-${t}-${e.index}`));
1292
+ });
1293
+ });
1294
+ let ke = o ? `${o.series} · ${o.label}:${B(o.value)}` : "聚焦或指向图形,用方向键切换读数", Fe = `${u},${f} 图,共 ${M.length} 项,${ee.length} 个系列`;
1295
+ return /* @__PURE__ */ C(U, {
1296
+ className: `local-visual-chart local-visual-chart-${f}`,
1297
+ label: u,
1298
+ children: [
1299
+ /* @__PURE__ */ S("div", {
1300
+ className: "local-visual-readout",
1301
+ id: l,
1302
+ "aria-live": "polite",
1303
+ children: ke
1304
+ }),
1305
+ /* @__PURE__ */ S("div", {
1306
+ className: "local-visual-svg-wrap",
1307
+ children: /* @__PURE__ */ C("svg", {
1308
+ className: "local-visual-svg",
1309
+ viewBox: `0 0 ${re} ${ie}`,
1310
+ role: "group",
1311
+ "aria-label": Fe,
1312
+ "aria-describedby": l,
1313
+ children: [
1314
+ ce.map((e) => /* @__PURE__ */ C("g", { children: [/* @__PURE__ */ S("line", {
1315
+ className: "local-visual-grid-line",
1316
+ x1: L,
1317
+ x2: 506,
1318
+ y1: ue(e),
1319
+ y2: ue(e)
1320
+ }), /* @__PURE__ */ S("text", {
1321
+ className: "local-visual-axis-label",
1322
+ x: L - 6,
1323
+ y: ue(e),
1324
+ textAnchor: "end",
1325
+ dominantBaseline: "middle",
1326
+ children: he(e)
1327
+ })] }, `y-${e}`)),
1328
+ se.min < 0 && se.max > 0 ? /* @__PURE__ */ S("line", {
1329
+ className: "local-visual-zero-line",
1330
+ x1: L,
1331
+ x2: 506,
1332
+ y1: de,
1333
+ y2: de
1334
+ }) : null,
1335
+ /* @__PURE__ */ S("line", {
1336
+ className: "local-visual-axis-line",
1337
+ x1: L,
1338
+ x2: 506,
1339
+ y1: 274,
1340
+ y2: 274
1341
+ }),
1342
+ V.map((e) => {
1343
+ let t = ge(e), n = R ? he(e) : ye(M[e]?.label ?? "", 8);
1344
+ return /* @__PURE__ */ C("g", { children: [/* @__PURE__ */ S("line", {
1345
+ className: "local-visual-tick",
1346
+ x1: t,
1347
+ x2: t,
1348
+ y1: 274,
1349
+ y2: 279
1350
+ }), /* @__PURE__ */ C("text", {
1351
+ className: "local-visual-axis-label",
1352
+ x: t,
1353
+ y: 293,
1354
+ textAnchor: "middle",
1355
+ children: [n, !R && M[e] ? /* @__PURE__ */ S("title", { children: M[e].label }) : null]
1356
+ })] }, `x-${e}`);
1357
+ }),
1358
+ p ? /* @__PURE__ */ S("text", {
1359
+ className: "local-visual-axis-title",
1360
+ x: (L + 506) / 2,
1361
+ y: 318,
1362
+ textAnchor: "middle",
1363
+ children: p
1364
+ }) : null,
1365
+ m ? /* @__PURE__ */ S("text", {
1366
+ className: "local-visual-axis-title",
1367
+ transform: "translate(12 145) rotate(-90)",
1368
+ textAnchor: "middle",
1369
+ children: m
1370
+ }) : null,
1371
+ De,
1372
+ Ee,
1373
+ _e,
1374
+ xe,
1375
+ Oe
1376
+ ]
1377
+ })
1378
+ }),
1379
+ /* @__PURE__ */ S(Pe, {
1380
+ items: F,
1381
+ hidden: n,
1382
+ onToggle: N,
1383
+ label: "图例,可开关系列"
1384
+ }),
1385
+ /* @__PURE__ */ S(Ne, { notes: x })
1386
+ ]
1387
+ });
1388
+ }
1389
+ var ze = /* @__PURE__ */ new WeakMap();
1390
+ function Be(e, t) {
1391
+ let n = ze.get(e);
1392
+ return n && n.revision === t || (n = {
1393
+ revision: t,
1394
+ requestedPoints: /* @__PURE__ */ new Map(),
1395
+ evaluation: {
1396
+ steps: 0,
1397
+ limit: i
1398
+ },
1399
+ samples: /* @__PURE__ */ new Map()
1400
+ }, ze.set(e, n)), n;
1401
+ }
1402
+ function Ve(n, i, a, s, c, l, u, d, f) {
1403
+ let p = Be(d, f), m = p.samples.get(i);
1404
+ if (m) return m;
1405
+ let h = (e) => {
1406
+ let t = {
1407
+ ok: !1,
1408
+ message: e
1409
+ };
1410
+ return p.samples.set(i, t), t;
1411
+ };
1412
+ if (a.length > 16) return h(`plot 最多支持 16 条曲线,当前为 ${a.length} 条。`);
1413
+ let g = a.length * u;
1414
+ p.requestedPoints.set(n, g);
1415
+ let _ = 0;
1416
+ for (let e of p.requestedPoints.values()) _ += e;
1417
+ if (_ > 2e4) return h(`整篇文档的绘图采样点超过上限:已请求 ${_} 个,最多 ${t} 个。请减少曲线或采样数。`);
1418
+ let v = [], y = { message: null }, b = a.map((t, n) => {
1419
+ let i = (t.value ?? "").trim(), a = /^y\s*=\s*([\s\S]+)$/.exec(i);
1420
+ if (!a) return v.push(`曲线 ${n + 1}:无法计算(每块公式需写成 y = 表达式)。`), {
1421
+ source: i,
1422
+ expression: null,
1423
+ points: [],
1424
+ endpoint: null,
1425
+ error: "formula"
1426
+ };
1427
+ try {
1428
+ let t = r(a[1].trim()), n = e(t, s, c, l, u, p.evaluation);
1429
+ return {
1430
+ source: i,
1431
+ expression: t,
1432
+ points: n.points,
1433
+ endpoint: n.endpoint,
1434
+ error: null
1435
+ };
1436
+ } catch (e) {
1437
+ return e instanceof o && e.code === "latex-budget" ? (y.message = e.message, {
1438
+ source: i,
1439
+ expression: null,
1440
+ points: [],
1441
+ endpoint: null,
1442
+ error: e.message
1443
+ }) : (v.push(`曲线 ${n + 1}:无法计算(${V(e)})。`), {
1444
+ source: i,
1445
+ expression: null,
1446
+ points: [],
1447
+ endpoint: null,
1448
+ error: V(e)
1449
+ });
1450
+ }
1451
+ });
1452
+ if (y.message !== null) return h(`绘图计算超过共享执行预算:${y.message}`);
1453
+ let x = {
1454
+ ok: !0,
1455
+ curves: b,
1456
+ notes: v
1457
+ };
1458
+ return p.samples.set(i, x), x;
1459
+ }
1460
+ function He(e) {
1461
+ if (e.length === 0) return 0;
1462
+ let t = [...e].sort((e, t) => e - t), n = Math.floor(t.length / 2);
1463
+ return t.length % 2 == 0 ? (t[n - 1] + t[n]) / 2 : t[n];
1464
+ }
1465
+ function Ue(e, t, n, r) {
1466
+ let i = [], a = [], o = (e, i) => {
1467
+ let a = Math.abs(i.y - e.y), o = e.y * i.y < 0 && Math.min(Math.abs(e.y), Math.abs(i.y)) > Math.max(1, n * 8), s = a > t * .8 && a > Math.max(r, 1e-9) * 10;
1468
+ return o || s;
1469
+ };
1470
+ for (let t of e) {
1471
+ if (t.y === null) {
1472
+ a.length > 0 && i.push(a), a = [];
1473
+ continue;
1474
+ }
1475
+ let e = {
1476
+ x: t.x,
1477
+ y: t.y
1478
+ }, n = a[a.length - 1];
1479
+ n && o(n, e) && (i.push(a), a = []), a.push(e);
1480
+ }
1481
+ return a.length > 0 && i.push(a), i;
1482
+ }
1483
+ function We({ node: e, runtime: t }) {
1484
+ let [n, r] = y(null), a = t.resetToken(e);
1485
+ h(() => {
1486
+ r(null);
1487
+ }, [a]);
1488
+ let o = g(), s = H(t, e.attrs, "label", "") || "函数图", c = H(t, e.attrs, "x-label", "x"), l = H(t, e.attrs, "y-label", "y"), u = ge(t, e.attrs, "min", -10), d = ge(t, e.attrs, "max", 10), f = Math.min(2e3, Math.max(2, ve(t, e.attrs, "samples", 200))), p = (e.children ?? []).filter((e) => e.type === "math" || e.type === "inlineMath"), m = (() => {
1489
+ try {
1490
+ return { ...t.snapshot().state };
1491
+ } catch {
1492
+ return {};
1493
+ }
1494
+ })(), v = 0;
1495
+ try {
1496
+ v = t.snapshot().revision;
1497
+ } catch {
1498
+ v = 0;
1499
+ }
1500
+ let b = p.map((e) => `${e.id}\u0000${e.value ?? ""}`).join(""), x = `${e.id}\u0000${u}\u0000${d}\u0000${f}\u0000${b}`, w = _(() => p.length === 0 || u === null || d === null || !(d > u) ? {
1501
+ ok: !0,
1502
+ curves: [],
1503
+ notes: []
1504
+ } : Ve(e.id, x, p, m, u, d, f, t, v), [
1505
+ x,
1506
+ e.id,
1507
+ v,
1508
+ t
1509
+ ]);
1510
+ if (p.length === 0) return /* @__PURE__ */ S(U, {
1511
+ className: "local-visual-plot",
1512
+ label: s,
1513
+ children: /* @__PURE__ */ S(W, {
1514
+ message: "plot 正文需要一个或多个 $$ 公式块。",
1515
+ kind: "alert"
1516
+ })
1517
+ });
1518
+ if (u === null || d === null || !(d > u)) return /* @__PURE__ */ S(U, {
1519
+ className: "local-visual-plot",
1520
+ label: s,
1521
+ children: /* @__PURE__ */ S(W, {
1522
+ message: "plot 的 min 必须小于 max。",
1523
+ kind: "alert"
1524
+ })
1525
+ });
1526
+ if (!w.ok) return /* @__PURE__ */ S(U, {
1527
+ className: "local-visual-plot",
1528
+ label: s,
1529
+ children: /* @__PURE__ */ S(W, {
1530
+ message: w.message,
1531
+ kind: "alert"
1532
+ })
1533
+ });
1534
+ let { curves: T, notes: E } = w, D = T.flatMap((e) => e.points.filter((e) => e.y !== null && Number.isFinite(e.y))), O = /* @__PURE__ */ S("div", {
1535
+ className: "local-visual-plot-legend",
1536
+ role: "list",
1537
+ "aria-label": "曲线图例",
1538
+ children: T.map((e, t) => /* @__PURE__ */ C("div", {
1539
+ className: "local-visual-plot-legend-item",
1540
+ role: "listitem",
1541
+ children: [/* @__PURE__ */ S("span", {
1542
+ className: "local-visual-swatch",
1543
+ style: { backgroundColor: I[t % I.length] },
1544
+ "aria-hidden": "true"
1545
+ }), /* @__PURE__ */ S("span", {
1546
+ className: "local-visual-plot-legend-text",
1547
+ children: /* @__PURE__ */ S("span", {
1548
+ className: "local-visual-plot-formula",
1549
+ children: /* @__PURE__ */ S(ne, { source: e.source })
1550
+ })
1551
+ })]
1552
+ }, `curve-legend-${t}`))
1553
+ });
1554
+ if (D.length === 0) return /* @__PURE__ */ C(U, {
1555
+ className: "local-visual-plot",
1556
+ label: s,
1557
+ children: [
1558
+ /* @__PURE__ */ S(W, { message: "当前范围内没有可绘制的值" }),
1559
+ /* @__PURE__ */ S(Ne, { notes: E }),
1560
+ O
1561
+ ]
1562
+ });
1563
+ let k = Ce(D.map((e) => e.y), !1), A = Se(k.min, k.max, 5), j = Se(u, d, 5), M = we(A, !!l), N = 506 - M, P = (e) => M + (e - u) / (d - u) * N, F = (e) => 16 + (k.max - e) / (k.max - k.min) * 258, ee = He(D.map((e) => Math.abs(e.y))), te = [];
1564
+ for (let e of T) for (let t = 1; t < e.points.length; t += 1) {
1565
+ let n = e.points[t - 1], r = e.points[t];
1566
+ n.y !== null && r.y !== null && te.push(Math.abs(r.y - n.y));
1567
+ }
1568
+ let re = He(te), ie = k.max - k.min, se = T.map((e) => Ue(e.points, ie, ee, re)), ce = {
1569
+ steps: 0,
1570
+ limit: i
1571
+ }, L = (e, t) => {
1572
+ if (!e.expression) return null;
1573
+ try {
1574
+ let n = e.expression.evaluate(t, m, ce);
1575
+ return typeof n == "number" && Number.isFinite(n) ? n : null;
1576
+ } catch {
1577
+ return null;
1578
+ }
1579
+ }, le = (e) => Math.max(u, Math.min(d, e)), ue = (d - u) / 100, de = (e) => {
1580
+ let t = e.currentTarget.getBoundingClientRect();
1581
+ if (t.width === 0) return;
1582
+ let n = Math.max(0, Math.min(1, (e.clientX - t.left) / t.width));
1583
+ r(u + n * (d - u));
1584
+ }, R = (e) => {
1585
+ let t = e.shiftKey ? 10 : 1, i = n;
1586
+ if (e.key === "ArrowRight") i = (n ?? (u + d) / 2) + ue * t;
1587
+ else if (e.key === "ArrowLeft") i = (n ?? (u + d) / 2) - ue * t;
1588
+ else if (e.key === "Home") i = u;
1589
+ else if (e.key === "End") i = d;
1590
+ else return;
1591
+ e.preventDefault(), r(le(i));
1592
+ }, z = n === null ? null : le(n), fe = z === null ? `区间 [${B(u)}, ${B(d)}] · ${f} 个采样点;用方向键或指针读取数值` : `x = ${B(z)};${T.map((e, t) => {
1593
+ let n = L(e, z);
1594
+ return `曲线 ${t + 1}:${e.error ? "无法计算" : n === null ? "无定义" : B(n)}`;
1595
+ }).join(";")}`, pe = z === null ? null : T.map((e, t) => {
1596
+ let n = L(e, z);
1597
+ return n === null || !e.expression ? null : /* @__PURE__ */ S("circle", {
1598
+ className: "local-visual-active-point",
1599
+ cx: P(z),
1600
+ cy: F(n),
1601
+ r: 4.5,
1602
+ style: {
1603
+ fill: I[t % I.length],
1604
+ stroke: "var(--surface)"
1605
+ },
1606
+ strokeWidth: 1.5
1607
+ }, `active-${t}`);
1608
+ });
1609
+ return /* @__PURE__ */ C(U, {
1610
+ className: "local-visual-plot",
1611
+ label: s,
1612
+ children: [
1613
+ /* @__PURE__ */ S("div", {
1614
+ className: "local-visual-readout",
1615
+ id: o,
1616
+ "aria-live": "polite",
1617
+ children: fe
1618
+ }),
1619
+ /* @__PURE__ */ S("div", {
1620
+ className: "local-visual-svg-wrap",
1621
+ children: /* @__PURE__ */ C("svg", {
1622
+ className: "local-visual-svg",
1623
+ viewBox: `0 0 ${ae} ${oe}`,
1624
+ role: "group",
1625
+ "aria-label": `${s},区间 ${B(u)} 到 ${B(d)},${f} 个采样点`,
1626
+ "aria-describedby": o,
1627
+ tabIndex: 0,
1628
+ onPointerMove: de,
1629
+ onPointerLeave: () => r(null),
1630
+ onFocus: () => r((e) => e ?? (u + d) / 2),
1631
+ onBlur: () => r(null),
1632
+ onKeyDown: R,
1633
+ children: [
1634
+ A.map((e) => /* @__PURE__ */ C("g", { children: [/* @__PURE__ */ S("line", {
1635
+ className: "local-visual-grid-line",
1636
+ x1: M,
1637
+ x2: 506,
1638
+ y1: F(e),
1639
+ y2: F(e)
1640
+ }), /* @__PURE__ */ S("text", {
1641
+ className: "local-visual-axis-label",
1642
+ x: M - 6,
1643
+ y: F(e),
1644
+ textAnchor: "end",
1645
+ dominantBaseline: "middle",
1646
+ children: he(e)
1647
+ })] }, `y-${e}`)),
1648
+ k.min < 0 && k.max > 0 ? /* @__PURE__ */ S("line", {
1649
+ className: "local-visual-zero-line",
1650
+ x1: M,
1651
+ x2: 506,
1652
+ y1: F(0),
1653
+ y2: F(0)
1654
+ }) : null,
1655
+ /* @__PURE__ */ S("line", {
1656
+ className: "local-visual-axis-line",
1657
+ x1: M,
1658
+ x2: 506,
1659
+ y1: 274,
1660
+ y2: 274
1661
+ }),
1662
+ j.map((e) => /* @__PURE__ */ C("g", { children: [/* @__PURE__ */ S("line", {
1663
+ className: "local-visual-tick",
1664
+ x1: P(e),
1665
+ x2: P(e),
1666
+ y1: 274,
1667
+ y2: 279
1668
+ }), /* @__PURE__ */ S("text", {
1669
+ className: "local-visual-axis-label",
1670
+ x: P(e),
1671
+ y: 293,
1672
+ textAnchor: "middle",
1673
+ children: he(e)
1674
+ })] }, `x-${e}`)),
1675
+ c ? /* @__PURE__ */ S("text", {
1676
+ className: "local-visual-axis-title",
1677
+ x: (M + 506) / 2,
1678
+ y: 318,
1679
+ textAnchor: "middle",
1680
+ children: c
1681
+ }) : null,
1682
+ l ? /* @__PURE__ */ S("text", {
1683
+ className: "local-visual-axis-title",
1684
+ transform: "translate(12 145) rotate(-90)",
1685
+ textAnchor: "middle",
1686
+ children: l
1687
+ }) : null,
1688
+ se.map((e, t) => e.map((e, n) => {
1689
+ if (e.length < 2) return null;
1690
+ let r = e.map((e, t) => `${t === 0 ? "M" : "L"} ${P(e.x)} ${F(e.y)}`).join(" ");
1691
+ return /* @__PURE__ */ S("path", {
1692
+ className: "local-visual-plot-line",
1693
+ d: r,
1694
+ fill: "none",
1695
+ style: { stroke: I[t % I.length] },
1696
+ strokeWidth: 2.4,
1697
+ strokeLinejoin: "round",
1698
+ strokeLinecap: "round"
1699
+ }, `curve-${t}-${n}`);
1700
+ })),
1701
+ z === null ? null : /* @__PURE__ */ S("line", {
1702
+ className: "local-visual-guide",
1703
+ x1: P(z),
1704
+ x2: P(z),
1705
+ y1: 16,
1706
+ y2: 274
1707
+ }),
1708
+ pe
1709
+ ]
1710
+ })
1711
+ }),
1712
+ /* @__PURE__ */ S(Ne, { notes: E }),
1713
+ O
1714
+ ]
1715
+ });
1716
+ }
1717
+ function Ge({ node: e, runtime: t, render: n }) {
1718
+ let [r, i] = y(null), a = t.resetToken(e);
1719
+ h(() => {
1720
+ i(null);
1721
+ }, [a]);
1722
+ let o = H(t, e.attrs, "title", "") || "时间轴", s = H(t, e.attrs, "unit", "分钟"), c = je(e, t);
1723
+ if (!c) return /* @__PURE__ */ S(U, {
1724
+ className: "local-visual-timeline",
1725
+ label: o,
1726
+ children: /* @__PURE__ */ S(W, {
1727
+ message: "timeline 正文需要一个 Markdown 表格。",
1728
+ kind: "alert"
1729
+ })
1730
+ });
1731
+ let l = c.headerText.map((e) => e.trim()), u = l.indexOf("事项"), d = l.indexOf("开始"), f = l.indexOf("时长"), p = l.indexOf("说明");
1732
+ if (u < 0 || d < 0 || f < 0) return /* @__PURE__ */ S(U, {
1733
+ className: "local-visual-timeline",
1734
+ label: o,
1735
+ children: /* @__PURE__ */ S(W, {
1736
+ message: "timeline 表格需要“事项”“开始”“时长”三列。",
1737
+ kind: "alert"
1738
+ })
1739
+ });
1740
+ let m = [], g = [], _ = [];
1741
+ if (c.rows.forEach((e, t) => {
1742
+ let n = e.cells[d], r = e.cells[f], i = n?.numeric ?? null, a = r?.numeric ?? null;
1743
+ if (i === null || a === null || i < 0 || a < 0) {
1744
+ g.push(t + 1);
1745
+ return;
1746
+ }
1747
+ let o = Ae(e.cells[u]) || `事项 ${t + 1}`;
1748
+ _.push({
1749
+ key: `item-${e.index}`,
1750
+ title: o,
1751
+ start: i,
1752
+ duration: a,
1753
+ description: p >= 0 ? e.cells[p]?.children ?? [] : [],
1754
+ sourceIndex: t
1755
+ });
1756
+ }), g.length > 0 && m.push(`第 ${g.join("、")} 行的开始或时长不是非负数字,未显示。`), _.length === 0) return /* @__PURE__ */ C(U, {
1757
+ className: "local-visual-timeline",
1758
+ label: o,
1759
+ children: [/* @__PURE__ */ S(W, { message: "没有有效的时间轴事项。" }), /* @__PURE__ */ S(Ne, { notes: m })]
1760
+ });
1761
+ let v = [..._].sort((e, t) => e.start - t.start || e.sourceIndex - t.sourceIndex), b = v.reduce((e, t) => Math.max(e, t.start + t.duration), 0), w = Math.max(1, b), T = Se(0, w, 5);
1762
+ (T.length === 0 || T[0] !== 0) && T.unshift(0), T[T.length - 1] < w && T.push(w);
1763
+ let E = s ? ` ${s}` : "", D = (e) => `${B(e)}${E}`, O = v.find((e) => e.key === r) ?? null;
1764
+ return /* @__PURE__ */ C(U, {
1765
+ className: "local-visual-timeline",
1766
+ label: o,
1767
+ children: [
1768
+ /* @__PURE__ */ S("div", {
1769
+ className: "local-visual-timeline-axis",
1770
+ "aria-hidden": "true",
1771
+ children: T.map((e, t) => {
1772
+ let n = e / w * 100, r = t === T.length - 1 ? {
1773
+ left: `${n}%`,
1774
+ transform: "translateX(-100%)"
1775
+ } : t === 0 ? { left: "0%" } : {
1776
+ left: `${n}%`,
1777
+ transform: "translateX(-50%)"
1778
+ };
1779
+ return /* @__PURE__ */ S("span", {
1780
+ className: "local-visual-timeline-tick",
1781
+ style: r,
1782
+ children: he(e)
1783
+ }, `tick-${e}`);
1784
+ })
1785
+ }),
1786
+ /* @__PURE__ */ S("ol", {
1787
+ className: "local-visual-timeline-list",
1788
+ children: v.map((e) => {
1789
+ let t = e.start + e.duration, n = e.start / w * 100, a = e.duration / w * 100, o = v.indexOf(e);
1790
+ return /* @__PURE__ */ C("li", {
1791
+ className: `local-visual-timeline-item${r === e.key ? " is-active" : ""}`,
1792
+ tabIndex: 0,
1793
+ "aria-label": `${e.title},开始 ${D(e.start)},结束 ${D(t)},时长 ${D(e.duration)}${e.description.length > 0 ? ",有说明" : ""}`,
1794
+ onFocus: () => i(e.key),
1795
+ onBlur: () => i((t) => t === e.key ? null : t),
1796
+ onPointerEnter: () => i(e.key),
1797
+ onPointerLeave: () => i((t) => t === e.key ? null : t),
1798
+ onKeyDown: (e) => {
1799
+ e.key === "Escape" && (e.preventDefault(), i(null));
1800
+ },
1801
+ children: [/* @__PURE__ */ C("div", {
1802
+ className: "local-visual-timeline-head",
1803
+ children: [/* @__PURE__ */ C("span", {
1804
+ className: "local-visual-timeline-title",
1805
+ children: [/* @__PURE__ */ S("span", {
1806
+ className: "local-visual-swatch",
1807
+ style: { backgroundColor: I[o % I.length] },
1808
+ "aria-hidden": "true"
1809
+ }), e.title]
1810
+ }), /* @__PURE__ */ C("span", {
1811
+ className: "local-visual-timeline-times",
1812
+ children: [
1813
+ "开始 ",
1814
+ D(e.start),
1815
+ " · 结束 ",
1816
+ D(t),
1817
+ " · 时长",
1818
+ " ",
1819
+ D(e.duration)
1820
+ ]
1821
+ })]
1822
+ }), /* @__PURE__ */ S("div", {
1823
+ className: "local-visual-timeline-track",
1824
+ "aria-hidden": "true",
1825
+ children: /* @__PURE__ */ S("span", {
1826
+ className: `local-visual-timeline-bar${e.duration === 0 ? " is-zero" : ""}`,
1827
+ style: {
1828
+ left: `${n}%`,
1829
+ width: `${a}%`,
1830
+ backgroundColor: I[o % I.length]
1831
+ }
1832
+ })
1833
+ })]
1834
+ }, e.key);
1835
+ })
1836
+ }),
1837
+ /* @__PURE__ */ S("div", {
1838
+ className: "local-visual-timeline-detail",
1839
+ "aria-live": "polite",
1840
+ children: O ? /* @__PURE__ */ C(x, { children: [/* @__PURE__ */ S("strong", { children: O.title }), O.description.length > 0 ? n(O.description) : /* @__PURE__ */ S("span", { children: "没有说明。" })] }) : /* @__PURE__ */ S("span", { children: "聚焦或指向事项查看说明。" })
1841
+ }),
1842
+ /* @__PURE__ */ S(Ne, { notes: m })
1843
+ ]
1844
+ });
1845
+ }
1846
+ var Ke = /[\u1100-\u115f\u2e80-\u303f\u3040-\u33ff\u3400-\u4dbf\u4e00-\u9fff\uac00-\ud7af\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6]/u;
1847
+ function qe(e) {
1848
+ let t = 0;
1849
+ for (let n of e) Ke.test(n) ? t += 1 : /\s/u.test(n) ? t += .3 : t += .58;
1850
+ return t * ue;
1851
+ }
1852
+ function Je(e, t) {
1853
+ if (qe(e) <= t) return e;
1854
+ let n = "";
1855
+ for (let r of e) {
1856
+ if (qe(`${n}${r}…`) > t) break;
1857
+ n += r;
1858
+ }
1859
+ return `${n.trimEnd()}…`;
1860
+ }
1861
+ function Ye(e) {
1862
+ let t = [], n = "";
1863
+ for (let r of e) n && qe(n + r) > R ? (t.push(n), n = r) : n += r;
1864
+ if (n && t.push(n), t.length <= z) return t;
1865
+ let r = t.slice(0, z);
1866
+ return r[1] = Je(t.slice(1).join(""), R), r;
1867
+ }
1868
+ function Xe(e) {
1869
+ let t = Ye(e);
1870
+ return {
1871
+ width: t.reduce((e, t) => Math.max(e, qe(t)), 0) + 10,
1872
+ height: t.length * fe + 6,
1873
+ lines: t
1874
+ };
1875
+ }
1876
+ function Ze(e) {
1877
+ let t = /* @__PURE__ */ new Map();
1878
+ for (let n of e) {
1879
+ let e = `${n.from}\u0000${n.to}`;
1880
+ t.set(e, (t.get(e) ?? 0) + 1);
1881
+ }
1882
+ let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
1883
+ for (let i of e) {
1884
+ let e = `${i.from}\u0000${i.to}`, a = t.get(e) ?? 1, o = n.get(e) ?? 0;
1885
+ n.set(e, o + 1), r.set(i.key, (o - (a - 1) / 2) * 12);
1886
+ }
1887
+ return r;
1888
+ }
1889
+ function Qe(e, t, n) {
1890
+ let { width: r, height: i, positions: a } = e, o = Ze(t), s = Infinity, c = Infinity, l = -Infinity, u = -Infinity;
1891
+ for (let e of t) {
1892
+ if (!e.label) continue;
1893
+ let t = a.get(e.from), r = a.get(e.to);
1894
+ if (!t || !r) continue;
1895
+ let i = et(n, t, r, o.get(e.key) ?? 0, e.from === e.to), d = Xe(e.label);
1896
+ s = Math.min(s, i.labelX - d.width / 2), c = Math.min(c, i.labelY - d.height / 2), l = Math.max(l, i.labelX + d.width / 2), u = Math.max(u, i.labelY + d.height / 2);
1897
+ }
1898
+ if (!Number.isFinite(s)) return e;
1899
+ let d = Math.max(0, de - s), f = Math.max(0, de - c), p = Math.max(0, l + de - r), m = Math.max(0, u + de - i);
1900
+ if (d === 0 && f === 0 && p === 0 && m === 0) return e;
1901
+ for (let e of a.values()) e.x += d, e.y += f;
1902
+ return {
1903
+ width: r + d + p,
1904
+ height: i + f + m,
1905
+ positions: a
1906
+ };
1907
+ }
1908
+ function $e(e, t, n) {
1909
+ let r = e.map((e) => e.id), i = new Map(r.map((e, t) => [e, t])), a = new Set(r), o = new Map(r.map((e) => [e, []]));
1910
+ for (let e of t) e.from !== e.to && a.has(e.from) && a.has(e.to) && o.get(e.from).push(e.to);
1911
+ let s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Set(), u = [], d = [], f = 0, p = (e) => {
1912
+ s.set(e, f), c.set(e, f), f += 1, u.push(e), l.add(e);
1913
+ for (let t of o.get(e) ?? []) s.has(t) ? l.has(t) && c.set(e, Math.min(c.get(e), s.get(t))) : (p(t), c.set(e, Math.min(c.get(e), c.get(t))));
1914
+ if (c.get(e) === s.get(e)) {
1915
+ let t = [], n;
1916
+ do
1917
+ n = u.pop(), l.delete(n), t.push(n);
1918
+ while (n !== e);
1919
+ d.push(t.reverse());
1920
+ }
1921
+ };
1922
+ for (let e of r) s.has(e) || p(e);
1923
+ let m = /* @__PURE__ */ new Map();
1924
+ d.forEach((e, t) => {
1925
+ for (let n of e) m.set(n, t);
1926
+ });
1927
+ let h = d.map(() => /* @__PURE__ */ new Set()), g = d.map(() => 0);
1928
+ for (let e of t) {
1929
+ if (!a.has(e.from) || !a.has(e.to)) continue;
1930
+ let t = m.get(e.from), n = m.get(e.to);
1931
+ t === n || h[t].has(n) || (h[t].add(n), g[n] += 1);
1932
+ }
1933
+ let _ = d.map((e, t) => ({
1934
+ index: t,
1935
+ order: Math.min(...e.map((e) => i.get(e) ?? 0))
1936
+ })), v = _.filter((e) => g[e.index] === 0).map((e) => e.index).sort((e, t) => _[e].order - _[t].order), y = d.map(() => 0);
1937
+ for (; v.length > 0;) {
1938
+ let e = v.shift();
1939
+ for (let t of h[e]) y[t] = Math.max(y[t], y[e] + 1), --g[t], g[t] === 0 && v.push(t);
1940
+ }
1941
+ let b = Math.max(1, ...y) + 1, x = Array.from({ length: b }, () => []);
1942
+ for (let e of r) x[y[m.get(e)]].push(e);
1943
+ let S = x.filter((e) => e.length > 0), C = Math.max(1, ...S.map((e) => e.length)), w = /* @__PURE__ */ new Map(), T, E;
1944
+ if (n === "down") T = se, E = Math.max(240, 106 + (S.length - 1) * 120), S.forEach((e, t) => {
1945
+ let n = 53 + t * 120;
1946
+ e.forEach((t, r) => {
1947
+ let i = e.length === 1 ? T / 2 : 104 + r * ((T - 88 - ce) / (e.length - 1));
1948
+ w.set(t, {
1949
+ x: i,
1950
+ y: n
1951
+ });
1952
+ });
1953
+ });
1954
+ else {
1955
+ let e = t.reduce((e, t) => t.label ? Math.max(e, Xe(t.label).width) : e, 0), n = Math.max(le, ce + (e > 0 ? e + 24 : 0));
1956
+ T = Math.max(se, 208 + (S.length - 1) * n), E = Math.max(240, 106 + (C - 1) * 74), S.forEach((e, t) => {
1957
+ let n = S.length === 1 ? T / 2 : 104 + t * ((T - 88 - ce) / (S.length - 1));
1958
+ e.forEach((t, r) => {
1959
+ let i = e.length === 1 ? E / 2 : 53 + r * ((E - 60 - L) / (e.length - 1));
1960
+ w.set(t, {
1961
+ x: n,
1962
+ y: i
1963
+ });
1964
+ });
1965
+ });
1966
+ }
1967
+ return Qe({
1968
+ width: T,
1969
+ height: E,
1970
+ positions: w
1971
+ }, t, n);
1972
+ }
1973
+ function et(e, t, n, r, i) {
1974
+ let a = ce, o = L;
1975
+ if (i) return e === "right" ? {
1976
+ d: `M ${t.x + 20} ${t.y - o / 2} C ${t.x + 64} ${t.y - o / 2 - 64}, ${t.x - 64} ${t.y - o / 2 - 64}, ${t.x - 20} ${t.y - o / 2}`,
1977
+ labelX: t.x,
1978
+ labelY: t.y - o / 2 - 46
1979
+ } : {
1980
+ d: `M ${t.x + a / 2} ${t.y - 10} C ${t.x + a / 2 + 64} ${t.y - 54}, ${t.x + a / 2 + 64} ${t.y + 54}, ${t.x + a / 2} ${t.y + 10}`,
1981
+ labelX: t.x + a / 2 + 44,
1982
+ labelY: t.y
1983
+ };
1984
+ if (e === "right") {
1985
+ if (n.x > t.x) {
1986
+ let e = t.x + a / 2, i = t.y + r, o = n.x - a / 2, s = n.y + r;
1987
+ return {
1988
+ d: `M ${e} ${i} L ${o} ${s}`,
1989
+ labelX: (e + o) / 2,
1990
+ labelY: (i + s) / 2 - 12
1991
+ };
1992
+ }
1993
+ let e = t.x + r, i = n.x + r, s = t.y + o / 2, c = n.y - o / 2, l = Math.max(70, Math.abs(i - e) * .45);
1994
+ return {
1995
+ d: `M ${e} ${s} C ${e + l} ${s + 86}, ${i - l} ${c + 86}, ${i} ${c}`,
1996
+ labelX: (e + i) / 2,
1997
+ labelY: Math.max(s, c) + 48
1998
+ };
1999
+ }
2000
+ if (n.y > t.y) {
2001
+ let e = t.x + r, i = n.x + r, a = t.y + o / 2, s = n.y - o / 2;
2002
+ return {
2003
+ d: `M ${e} ${a} L ${i} ${s}`,
2004
+ labelX: (e + i) / 2 + 10,
2005
+ labelY: (a + s) / 2
2006
+ };
2007
+ }
2008
+ let s = t.x + a / 2, c = n.x - a / 2, l = t.y + r, u = n.y + r, d = Math.max(70, Math.abs(u - l) * .45);
2009
+ return {
2010
+ d: `M ${s} ${l} C ${s + 86} ${l + d}, ${c + 86} ${u - d}, ${c} ${u}`,
2011
+ labelX: Math.max(s, c) + 48,
2012
+ labelY: (l + u) / 2
2013
+ };
2014
+ }
2015
+ function tt({ node: e, runtime: t, render: n }) {
2016
+ let [r, i] = y(null), [a, o] = y(null), s = t.resetToken(e);
2017
+ h(() => {
2018
+ i(null), o(null);
2019
+ }, [s]);
2020
+ let c = g().replace(/[^a-zA-Z0-9_-]/g, ""), l = `local-diagram-arrow-${c}`, u = `local-diagram-description-${c}`, d = H(t, e.attrs, "label", "") || "图解", f = (e.attrs?.direction ?? "right").trim().toLowerCase() === "down" ? "down" : "right", p = e.children?.filter((e) => e.type === "component") ?? [], m = [], _ = [], v = /* @__PURE__ */ new Set();
2021
+ for (let e of p) {
2022
+ if (e.name !== "node") continue;
2023
+ let n = (e.attrs?.id ?? "").trim();
2024
+ if (!n) {
2025
+ m.push("存在缺少 id 的节点,已忽略。");
2026
+ continue;
2027
+ }
2028
+ if (v.has(n)) {
2029
+ m.push(`节点 id 重复:${n},已忽略后续节点。`);
2030
+ continue;
2031
+ }
2032
+ v.add(n);
2033
+ let r = H(t, e.attrs, "tone", "neutral").trim(), i = r === "success" || r === "warning" ? r : "neutral";
2034
+ _.push({
2035
+ id: n,
2036
+ label: H(t, e.attrs, "label", n) || n,
2037
+ tone: i,
2038
+ children: e.children ?? []
2039
+ });
2040
+ }
2041
+ let b = [], w = /* @__PURE__ */ new Set();
2042
+ for (let e of p) {
2043
+ if (e.name !== "edge") continue;
2044
+ let n = (e.attrs?.from ?? "").trim(), r = (e.attrs?.to ?? "").trim();
2045
+ if (!n || !r || !v.has(n) || !v.has(r)) {
2046
+ m.push(`边 ${n || "?"} → ${r || "?"} 的端点不存在,已忽略。`);
2047
+ continue;
2048
+ }
2049
+ let i = H(t, e.attrs, "label", ""), a = `${n}\u0000${r}\u0000${i}`;
2050
+ w.has(a) ? m.push(`重复的边:${n} → ${r}${i ? `(${i})` : ""},已忽略。`) : (w.add(a), b.push({
2051
+ key: a,
2052
+ from: n,
2053
+ to: r,
2054
+ label: i
2055
+ }));
2056
+ }
2057
+ if (_.length === 0) return /* @__PURE__ */ C(U, {
2058
+ className: "local-visual-diagram",
2059
+ label: d,
2060
+ children: [/* @__PURE__ */ S(W, {
2061
+ message: "diagram 至少需要一个 node。",
2062
+ kind: "alert"
2063
+ }), /* @__PURE__ */ S(Ne, { notes: m })]
2064
+ });
2065
+ let T = null;
2066
+ try {
2067
+ let n = t.get(e);
2068
+ typeof n == "string" && (T = n);
2069
+ } catch {
2070
+ T = null;
2071
+ }
2072
+ let E = new Set(_.map((e) => e.id)), D = (e.attrs?.initial ?? "").trim(), O = D && E.has(D) ? D : _[0].id, k = T && E.has(T) ? T : r && E.has(r) ? r : O, A = _.find((e) => e.id === k) ?? _[0], j = (n) => {
2073
+ i(n), o(null);
2074
+ try {
2075
+ let r = t.set(e, n);
2076
+ r.length > 0 && o(r.map((e) => e.message).join(";"));
2077
+ } catch (e) {
2078
+ o(V(e));
2079
+ }
2080
+ }, M = $e(_, b, f), N = Ze(b), P = [], F = [];
2081
+ for (let e of b) {
2082
+ let t = M.positions.get(e.from), n = M.positions.get(e.to);
2083
+ if (!t || !n) continue;
2084
+ let r = et(f, t, n, N.get(e.key) ?? 0, e.from === e.to);
2085
+ if (P.push(/* @__PURE__ */ S("g", {
2086
+ className: "local-visual-edge",
2087
+ children: /* @__PURE__ */ S("path", {
2088
+ d: r.d,
2089
+ fill: "none",
2090
+ style: { stroke: "var(--ink-muted)" },
2091
+ strokeWidth: 1.6,
2092
+ markerEnd: `url(#${l})`
2093
+ })
2094
+ }, `edge-${e.key}`)), !e.label) continue;
2095
+ let i = Xe(e.label);
2096
+ F.push(/* @__PURE__ */ S("g", {
2097
+ className: "local-visual-edge-label-group",
2098
+ children: /* @__PURE__ */ S("text", {
2099
+ className: "local-visual-edge-label",
2100
+ x: r.labelX,
2101
+ y: r.labelY,
2102
+ textAnchor: "middle",
2103
+ dominantBaseline: "middle",
2104
+ children: i.lines.map((e, t) => /* @__PURE__ */ S("tspan", {
2105
+ x: r.labelX,
2106
+ y: r.labelY + (t - (i.lines.length - 1) / 2) * fe,
2107
+ children: e
2108
+ }, t))
2109
+ })
2110
+ }, `edge-label-${e.key}`));
2111
+ }
2112
+ return /* @__PURE__ */ C(U, {
2113
+ className: "local-visual-diagram",
2114
+ label: d,
2115
+ children: [
2116
+ /* @__PURE__ */ S("div", {
2117
+ className: "local-visual-svg-wrap",
2118
+ children: /* @__PURE__ */ C("svg", {
2119
+ className: "local-visual-svg local-visual-diagram-svg",
2120
+ viewBox: `0 0 ${M.width} ${M.height}`,
2121
+ role: "group",
2122
+ "aria-label": `${d},包含 ${_.length} 个节点和 ${b.length} 条边;用 Tab 聚焦节点,回车选择`,
2123
+ "aria-describedby": u,
2124
+ children: [
2125
+ /* @__PURE__ */ S("defs", { children: /* @__PURE__ */ S("marker", {
2126
+ id: l,
2127
+ viewBox: "0 0 10 10",
2128
+ refX: "9",
2129
+ refY: "5",
2130
+ markerWidth: "7",
2131
+ markerHeight: "7",
2132
+ orient: "auto-start-reverse",
2133
+ children: /* @__PURE__ */ S("path", {
2134
+ d: "M 0 0 L 10 5 L 0 10 z",
2135
+ style: { fill: "var(--ink-muted)" }
2136
+ })
2137
+ }) }),
2138
+ P,
2139
+ _.map((e) => {
2140
+ let t = M.positions.get(e.id);
2141
+ if (!t) return null;
2142
+ let n = e.id === k, r = be(e.label, 8, 2);
2143
+ return /* @__PURE__ */ C("g", {
2144
+ className: `local-visual-node local-visual-node-${e.tone}${n ? " is-selected" : ""}`,
2145
+ "data-diagram-node": "",
2146
+ transform: `translate(${t.x} ${t.y})`,
2147
+ role: "button",
2148
+ tabIndex: 0,
2149
+ "aria-pressed": n,
2150
+ "aria-label": e.label,
2151
+ onClick: () => j(e.id),
2152
+ onKeyDown: (t) => {
2153
+ Ee(t) ? (t.preventDefault(), j(e.id)) : t.key === "ArrowRight" || t.key === "ArrowDown" ? Te(t, "[data-diagram-node]", 1) : (t.key === "ArrowLeft" || t.key === "ArrowUp") && Te(t, "[data-diagram-node]", -1);
2154
+ },
2155
+ children: [
2156
+ /* @__PURE__ */ S("title", { children: e.label }),
2157
+ /* @__PURE__ */ S("rect", {
2158
+ className: "local-visual-node-shape",
2159
+ x: -60,
2160
+ y: -23,
2161
+ width: ce,
2162
+ height: L,
2163
+ rx: 10
2164
+ }),
2165
+ /* @__PURE__ */ S("text", {
2166
+ className: "local-visual-node-text",
2167
+ textAnchor: "middle",
2168
+ children: r.map((e, t) => /* @__PURE__ */ S("tspan", {
2169
+ x: 0,
2170
+ y: (t - (r.length - 1) / 2) * 16 + 4,
2171
+ children: e
2172
+ }, t))
2173
+ })
2174
+ ]
2175
+ }, `node-${e.id}`);
2176
+ }),
2177
+ F
2178
+ ]
2179
+ })
2180
+ }),
2181
+ /* @__PURE__ */ S("div", {
2182
+ className: "local-visual-diagram-detail",
2183
+ "aria-live": "polite",
2184
+ children: A ? /* @__PURE__ */ C(x, { children: [/* @__PURE__ */ S("strong", { children: A.label }), A.children.length > 0 ? n(A.children) : /* @__PURE__ */ S("span", { children: "该节点没有说明。" })] }) : /* @__PURE__ */ S("span", { children: "点击或用 Tab 聚焦节点后按回车查看说明。" })
2185
+ }),
2186
+ /* @__PURE__ */ C("ul", {
2187
+ id: u,
2188
+ className: "local-visual-sr-only",
2189
+ "aria-label": "节点与连线",
2190
+ children: [_.map((e) => /* @__PURE__ */ S("li", { children: e.label }, `description-node-${e.id}`)), b.map((e) => {
2191
+ let t = _.find((t) => t.id === e.from), n = _.find((t) => t.id === e.to);
2192
+ return /* @__PURE__ */ C("li", { children: [
2193
+ t?.label ?? e.from,
2194
+ " → ",
2195
+ n?.label ?? e.to,
2196
+ e.label ? `(${e.label})` : ""
2197
+ ] }, `description-edge-${e.key}`);
2198
+ })]
2199
+ }),
2200
+ a ? /* @__PURE__ */ S(W, {
2201
+ message: a,
2202
+ kind: "alert"
2203
+ }) : null,
2204
+ /* @__PURE__ */ S(Ne, { notes: m })
2205
+ ]
2206
+ });
2207
+ }
2208
+ function nt(e) {
2209
+ switch (e.node.name) {
2210
+ case "table": return /* @__PURE__ */ S(Fe, { ...e });
2211
+ case "chart": return /* @__PURE__ */ S(Re, { ...e });
2212
+ case "plot": return /* @__PURE__ */ S(We, { ...e });
2213
+ case "timeline": return /* @__PURE__ */ S(Ge, { ...e });
2214
+ case "diagram": return /* @__PURE__ */ S(tt, { ...e });
2215
+ default: return null;
2216
+ }
2217
+ }
2218
+ // src/local/heading-anchors.ts
2219
+ function rt(e, t) {
2220
+ return (e ?? []).map((e) => {
2221
+ switch (e.type) {
2222
+ case "text":
2223
+ case "inlineCode":
2224
+ case "inlineMath":
2225
+ case "fallback": return e.value ?? "";
2226
+ case "image": return e.alt ?? "";
2227
+ case "break": return " ";
2228
+ case "interpolation": try {
2229
+ let n = s(e.value ?? "").evaluate(t);
2230
+ return Array.isArray(n) ? "无法计算" : n === null ? "" : String(n);
2231
+ } catch {
2232
+ return "无法计算";
2233
+ }
2234
+ default: return rt(e.children, t);
2235
+ }
2236
+ }).join("");
2237
+ }
2238
+ function it(e) {
2239
+ return e.trim().toLowerCase().replace(/[^\p{L}\p{N}\p{M}\s_-]/gu, "").replace(/\s+/g, "-") || "section";
2240
+ }
2241
+ function at(e, t) {
2242
+ let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
2243
+ function a(o) {
2244
+ for (let s of o) {
2245
+ if (s.type === "heading") {
2246
+ let a = it(rt(s.children, e.initialState)), o = a, c = i.get(a) ?? 0;
2247
+ for (; r.has(o);) c += 1, o = `${a}-${c}`;
2248
+ i.set(a, c);
2249
+ let l = `${t}-${o}`;
2250
+ n.set(s, l), r.set(o, l);
2251
+ }
2252
+ s.children && a(s.children);
2253
+ }
2254
+ }
2255
+ return a(e.nodes), {
2256
+ ids: n,
2257
+ resolve(e) {
2258
+ if (!e.startsWith("#")) return e;
2259
+ try {
2260
+ let t = r.get(decodeURIComponent(e.slice(1)));
2261
+ return t ? `#${t}` : e;
2262
+ } catch {
2263
+ return e;
2264
+ }
2265
+ }
2266
+ };
2267
+ }
2268
+ // src/local/LocalDocumentView.tsx
2269
+ var ot = d(null);
2270
+ function G() {
2271
+ let e = m(ot);
2272
+ if (!e) throw Error("LocalViewContext 未初始化");
2273
+ return e;
2274
+ }
2275
+ var st = /^\s*\{\{([\s\S]*)\}\}\s*$/, ct = {
2276
+ revision: 0,
2277
+ state: {}
2278
+ };
2279
+ function K(e, t) {
2280
+ return e.attrs?.[t];
2281
+ }
2282
+ function lt(e, t, n) {
2283
+ let r = K(t, n);
2284
+ if (r === void 0) return { present: !1 };
2285
+ let i = st.exec(r);
2286
+ if (!i) return {
2287
+ present: !0,
2288
+ ok: !0,
2289
+ value: r
2290
+ };
2291
+ try {
2292
+ return {
2293
+ present: !0,
2294
+ ok: !0,
2295
+ value: e.evaluate(i[1])
2296
+ };
2297
+ } catch {
2298
+ return {
2299
+ present: !0,
2300
+ ok: !1
2301
+ };
2302
+ }
2303
+ }
2304
+ function ut(e) {
2305
+ return e === null ? "" : typeof e == "string" ? e : typeof e == "number" ? Number.isFinite(e) ? String(e) : null : typeof e == "boolean" ? e ? "true" : "false" : null;
2306
+ }
2307
+ function q(e, t, n, r = "") {
2308
+ let i = K(t, n);
2309
+ if (i === void 0) return r;
2310
+ let a = st.exec(i);
2311
+ try {
2312
+ return a ? ut(e.evaluate(a[1])) ?? "无法计算" : e.text(i);
2313
+ } catch {
2314
+ return "无法计算";
2315
+ }
2316
+ }
2317
+ function dt(e, t, n, r) {
2318
+ let i = K(t, n);
2319
+ if (i === void 0) return {
2320
+ ok: !0,
2321
+ value: r
2322
+ };
2323
+ let a = st.exec(i);
2324
+ if (!a) return {
2325
+ ok: !0,
2326
+ value: i === "true"
2327
+ };
2328
+ try {
2329
+ let t = e.evaluate(a[1]);
2330
+ return typeof t == "boolean" ? {
2331
+ ok: !0,
2332
+ value: t
2333
+ } : { ok: !1 };
2334
+ } catch {
2335
+ return { ok: !1 };
2336
+ }
2337
+ }
2338
+ function ft(e, t, n, r = !1) {
2339
+ let i = dt(e, t, n, r);
2340
+ return i.ok ? i.value : r;
2341
+ }
2342
+ function pt(e) {
2343
+ try {
2344
+ return e.snapshot().revision;
2345
+ } catch {
2346
+ return 0;
2347
+ }
2348
+ }
2349
+ function J(e, t, n, r) {
2350
+ let i = K(t, n);
2351
+ if (i === void 0) return r;
2352
+ let a = st.exec(i);
2353
+ try {
2354
+ let t = a ? e.evaluate(a[1]) : Number(i);
2355
+ return typeof t == "number" && Number.isFinite(t) ? t : r;
2356
+ } catch {
2357
+ return r;
2358
+ }
2359
+ }
2360
+ function Y(e, t) {
2361
+ try {
2362
+ return e.get(t);
2363
+ } catch {
2364
+ return null;
2365
+ }
2366
+ }
2367
+ function mt(e) {
2368
+ return ut(e) ?? "";
2369
+ }
2370
+ function X(e) {
2371
+ let { runtime: t, report: n } = G(), [r, i] = y(null);
2372
+ return {
2373
+ write: p((r) => {
2374
+ try {
2375
+ let a = t.set(e, r);
2376
+ return a.length ? (i(a.map((e) => e.message).join(";")), n(a), !1) : (i(null), !0);
2377
+ } catch (e) {
2378
+ return i(e instanceof Error ? e.message : "无法写入"), !1;
2379
+ }
2380
+ }, [
2381
+ e,
2382
+ n,
2383
+ t
2384
+ ]),
2385
+ error: r,
2386
+ setError: i
2387
+ };
2388
+ }
2389
+ function ht(e) {
2390
+ let { runtime: t } = G(), n = dt(t, e, "disabled", !1);
2391
+ return n.ok ? {
2392
+ disabled: n.value,
2393
+ invalid: !1
2394
+ } : {
2395
+ disabled: !0,
2396
+ invalid: !0
2397
+ };
2398
+ }
2399
+ function gt(e, t, n) {
2400
+ let r = 0;
2401
+ try {
2402
+ r = e.resetToken(t);
2403
+ } catch {
2404
+ r = 0;
2405
+ }
2406
+ let i = v(r), a = v(n);
2407
+ a.current = n, h(() => {
2408
+ i.current !== r && (i.current = r, a.current());
2409
+ }, [r]);
2410
+ }
2411
+ function Z({ message: e = "无法计算" }) {
2412
+ return /* @__PURE__ */ S("span", {
2413
+ className: "local-error",
2414
+ role: "alert",
2415
+ children: e
2416
+ });
2417
+ }
2418
+ var _t = class extends u {
2419
+ state = { failed: !1 };
2420
+ static getDerivedStateFromError() {
2421
+ return { failed: !0 };
2422
+ }
2423
+ componentDidUpdate(e) {
2424
+ this.state.failed && e.revision !== this.props.revision && this.setState({ failed: !1 });
2425
+ }
2426
+ render() {
2427
+ return this.state.failed ? /* @__PURE__ */ S(Z, {}) : this.props.children;
2428
+ }
2429
+ }, vt = /* @__PURE__ */ new Set([
2430
+ "table",
2431
+ "chart",
2432
+ "plot",
2433
+ "timeline",
2434
+ "diagram"
2435
+ ]);
2436
+ function yt(e, t, n) {
2437
+ if (!e) return null;
2438
+ let r = e.trim();
2439
+ if (!r) return null;
2440
+ let i = r.replace(/[\u0000- ]+/g, ""), a = /^([a-z][a-z0-9+.-]*):/i.exec(i);
2441
+ if (a) {
2442
+ let e = a[1].toLowerCase();
2443
+ if (!(t === "image" ? e === "http" || e === "https" : e === "http" || e === "https" || e === "mailto" || e === "tel")) return null;
2444
+ }
2445
+ if (!n) return t === "image" ? null : r;
2446
+ try {
2447
+ return n(r, t) ? r : null;
2448
+ } catch {
2449
+ return null;
2450
+ }
2451
+ }
2452
+ function bt(e) {
2453
+ return `h${Math.min(6, Math.max(1, e ?? 1))}`;
2454
+ }
2455
+ function Q(e, t, n, r = !0) {
2456
+ return !t || t.length === 0 ? null : t.map((t, i) => wt(e, t, i, n, r));
2457
+ }
2458
+ function xt(e, t) {
2459
+ if (typeof t.value == "string") return t.value;
2460
+ let { start: n, end: r } = t.range;
2461
+ return Number.isInteger(n) && Number.isInteger(r) && n >= 0 && r >= n ? e.runtime.document.source.slice(n, r) : "";
2462
+ }
2463
+ function St(e, t, n, r) {
2464
+ return /* @__PURE__ */ S("span", {
2465
+ className: r ? "local-fallback local-fallback-block" : "local-fallback local-fallback-inline",
2466
+ title: "未支持的语法,已按源码原样显示",
2467
+ "data-local-fallback": "",
2468
+ children: xt(e, t)
2469
+ }, n);
2470
+ }
2471
+ function Ct(e, t, n) {
2472
+ return !t || t.length === 0 ? null : t.map((t, r) => t.type === "paragraph" || t.type === "root" ? /* @__PURE__ */ S("span", { children: Q(e, t.children, n, !1) }, t.id || `inline-${r}`) : wt(e, t, r, n, !1));
2473
+ }
2474
+ function wt(e, t, n, r, i = !0) {
2475
+ let a = t.id || `${t.type}-${n}`;
2476
+ if (t.type === "component") return /* @__PURE__ */ S(_t, {
2477
+ revision: pt(e.runtime),
2478
+ children: Et(t, r)
2479
+ }, a);
2480
+ switch (t.type) {
2481
+ case "root": return /* @__PURE__ */ S("div", { children: Q(e, t.children, r) }, a);
2482
+ case "heading": return f(bt(t.depth), {
2483
+ key: a,
2484
+ id: e.anchors.ids.get(t)
2485
+ }, Q(e, t.children, r, !1));
2486
+ case "paragraph": return /* @__PURE__ */ S("p", { children: Q(e, t.children, r, !1) }, a);
2487
+ case "text": return /* @__PURE__ */ S("span", { children: t.value ?? "" }, a);
2488
+ case "emphasis": return /* @__PURE__ */ S("em", { children: Q(e, t.children, r, !1) }, a);
2489
+ case "strong": return /* @__PURE__ */ S("strong", { children: Q(e, t.children, r, !1) }, a);
2490
+ case "delete": return /* @__PURE__ */ S("del", { children: Q(e, t.children, r, !1) }, a);
2491
+ case "inlineCode": return /* @__PURE__ */ S("code", {
2492
+ className: "md-inline-code",
2493
+ children: t.value ?? ""
2494
+ }, a);
2495
+ case "code": {
2496
+ let e = t.lang ? `language-${t.lang}` : void 0;
2497
+ return /* @__PURE__ */ S("pre", {
2498
+ className: "md-code",
2499
+ children: /* @__PURE__ */ S("code", {
2500
+ className: e,
2501
+ children: t.value ?? ""
2502
+ })
2503
+ }, a);
2504
+ }
2505
+ case "blockquote": return /* @__PURE__ */ S("blockquote", { children: Q(e, t.children, r) }, a);
2506
+ case "break": return /* @__PURE__ */ S("br", {}, a);
2507
+ case "thematicBreak": return /* @__PURE__ */ S("hr", {}, a);
2508
+ case "list": return t.ordered ? /* @__PURE__ */ S("ol", {
2509
+ start: t.start ?? 1,
2510
+ className: "md-list",
2511
+ children: Q(e, t.children, r)
2512
+ }, a) : /* @__PURE__ */ S("ul", {
2513
+ className: "md-list",
2514
+ children: Q(e, t.children, r)
2515
+ }, a);
2516
+ case "listItem": {
2517
+ let n = typeof t.checked == "boolean";
2518
+ return /* @__PURE__ */ C("li", {
2519
+ className: n ? "md-list-item md-task-item" : "md-list-item",
2520
+ children: [n ? /* @__PURE__ */ S("input", {
2521
+ type: "checkbox",
2522
+ className: "md-task-checkbox",
2523
+ checked: t.checked === !0,
2524
+ readOnly: !0,
2525
+ tabIndex: -1,
2526
+ "aria-label": t.checked ? "已完成" : "未完成"
2527
+ }) : null, Q(e, t.children, r)]
2528
+ }, a);
2529
+ }
2530
+ case "link": {
2531
+ let n = yt(t.url, "link", e.urlPolicy);
2532
+ if (!n) return /* @__PURE__ */ S("span", {
2533
+ className: "md-link-rejected",
2534
+ title: "已拒绝不安全的链接地址",
2535
+ children: Q(e, t.children, r, !1)
2536
+ }, a);
2537
+ let i = e.anchors.resolve(n), o = /^https?:/i.test(i);
2538
+ return /* @__PURE__ */ S("a", {
2539
+ href: i,
2540
+ title: t.title ?? void 0,
2541
+ target: o ? "_blank" : void 0,
2542
+ rel: o ? "noopener noreferrer" : void 0,
2543
+ children: Q(e, t.children, r, !1)
2544
+ }, a);
2545
+ }
2546
+ case "image": {
2547
+ let n = yt(t.url, "image", e.urlPolicy);
2548
+ return n ? /* @__PURE__ */ S("img", {
2549
+ className: "md-image",
2550
+ src: n,
2551
+ alt: t.alt ?? "",
2552
+ title: t.title ?? void 0,
2553
+ loading: "lazy",
2554
+ referrerPolicy: "no-referrer"
2555
+ }, a) : /* @__PURE__ */ C("span", {
2556
+ className: "md-image-rejected",
2557
+ children: [
2558
+ "[已拒绝不安全的图片",
2559
+ t.alt ? `:${t.alt}` : "",
2560
+ "]"
2561
+ ]
2562
+ }, a);
2563
+ }
2564
+ case "table": {
2565
+ let [n, ...i] = t.children ?? [];
2566
+ return /* @__PURE__ */ S("div", {
2567
+ className: "md-table-scroll",
2568
+ children: /* @__PURE__ */ C("table", {
2569
+ className: "md-table",
2570
+ children: [n ? /* @__PURE__ */ S("thead", { children: /* @__PURE__ */ S("tr", { children: Tt(e, n, "th", t.align, r) }) }) : null, i.length ? /* @__PURE__ */ S("tbody", { children: i.map((n, i) => /* @__PURE__ */ S("tr", { children: Tt(e, n, "td", t.align, r) }, n.id || `${a}-row-${i}`)) }) : null]
2571
+ })
2572
+ }, a);
2573
+ }
2574
+ case "tableRow": return /* @__PURE__ */ S("tr", { children: Tt(e, t, "td", void 0, r) }, a);
2575
+ case "tableCell": {
2576
+ let n = t.align?.[0] ?? void 0;
2577
+ return /* @__PURE__ */ S("td", {
2578
+ style: { textAlign: n ?? void 0 },
2579
+ children: Q(e, t.children, r, !1)
2580
+ }, a);
2581
+ }
2582
+ case "interpolation": try {
2583
+ let n = ut(e.runtime.evaluate(t.value ?? ""));
2584
+ if (n === null) throw Error("无法显示数组");
2585
+ return /* @__PURE__ */ S("span", {
2586
+ className: "local-interpolation",
2587
+ children: n
2588
+ }, a);
2589
+ } catch {
2590
+ return /* @__PURE__ */ S(Z, {}, a);
2591
+ }
2592
+ case "math":
2593
+ case "inlineMath": {
2594
+ let n = t.type === "math";
2595
+ return /* @__PURE__ */ S("span", {
2596
+ className: n ? "local-math-display" : "local-math-inline",
2597
+ children: /* @__PURE__ */ S(_t, {
2598
+ revision: pt(e.runtime),
2599
+ children: /* @__PURE__ */ S(ne, {
2600
+ source: t.value ?? "",
2601
+ display: n
2602
+ })
2603
+ })
2604
+ }, a);
2605
+ }
2606
+ case "html": return /* @__PURE__ */ S("span", {
2607
+ className: "md-raw-html",
2608
+ children: t.value ?? ""
2609
+ }, a);
2610
+ case "fallback": return St(e, t, a, i);
2611
+ case "footnoteReference": return St(e, t, a, !1);
2612
+ case "footnoteDefinition": return St(e, t, a, i);
2613
+ case "comment":
2614
+ case "definition": return null;
2615
+ default: return t.children && t.children.length ? /* @__PURE__ */ S("span", { children: Q(e, t.children, r, i) }, a) : typeof t.value == "string" ? /* @__PURE__ */ S("span", { children: t.value }, a) : null;
2616
+ }
2617
+ }
2618
+ function Tt(e, t, n, r, i) {
2619
+ return (t.children ?? []).map((a, o) => {
2620
+ let s = a.align?.[0] ?? t.align?.[o] ?? r?.[o] ?? void 0;
2621
+ return n === "th" ? /* @__PURE__ */ S("th", {
2622
+ style: { textAlign: s ?? void 0 },
2623
+ children: Q(e, a.children, i, !1)
2624
+ }, a.id || `${t.id}-h-${o}`) : /* @__PURE__ */ S("td", {
2625
+ style: { textAlign: s ?? void 0 },
2626
+ children: Q(e, a.children, i, !1)
2627
+ }, a.id || `${t.id}-c-${o}`);
2628
+ });
2629
+ }
2630
+ function Et(e, t) {
2631
+ let n = e.name ?? "";
2632
+ if (vt.has(n)) return /* @__PURE__ */ S(Dt, {
2633
+ node: e,
2634
+ visible: t
2635
+ });
2636
+ let r = un[n];
2637
+ return r ? /* @__PURE__ */ S(r, {
2638
+ node: e,
2639
+ visible: t
2640
+ }) : /* @__PURE__ */ C("span", {
2641
+ className: "component-error",
2642
+ children: [
2643
+ "未知组件“",
2644
+ n || "(缺少名称)",
2645
+ "”"
2646
+ ]
2647
+ });
2648
+ }
2649
+ function Dt({ node: e, visible: t }) {
2650
+ let { runtime: n, render: r } = G();
2651
+ return /* @__PURE__ */ S(nt, {
2652
+ node: e,
2653
+ runtime: n,
2654
+ render: r,
2655
+ visible: t
2656
+ });
2657
+ }
2658
+ function $({ message: e }) {
2659
+ return e ? /* @__PURE__ */ S("span", {
2660
+ className: "field-error",
2661
+ role: "alert",
2662
+ children: e
2663
+ }) : null;
2664
+ }
2665
+ function Ot(e, t) {
2666
+ if (t.required && e.length === 0) return "请填写此字段";
2667
+ if (e.length > 1e5) return `最多允许 ${l} 个字符`;
2668
+ if (t.email && e !== "" && !n(e)) return "请输入有效的邮箱地址";
2669
+ let r = e.length;
2670
+ return t.minLength !== void 0 && t.minLength > 0 && e !== "" && r < t.minLength ? `至少需要 ${t.minLength} 个字符` : t.maxLength !== void 0 && t.maxLength >= 0 && r > t.maxLength ? `最多允许 ${t.maxLength} 个字符` : null;
2671
+ }
2672
+ function kt({ node: e }) {
2673
+ let t = g(), { runtime: n } = G(), { write: r, error: i, setError: a } = X(e), o = q(n, e, "label", e.name ?? "输入"), s = q(n, e, "placeholder", ""), c = (K(e, "type") ?? "text") === "email", l = ft(n, e, "required", !1), { disabled: u, invalid: d } = ht(e), f = K(e, "min-length"), p = K(e, "max-length"), m = f === void 0 ? void 0 : Math.max(0, Math.floor(J(n, e, "min-length", 0))), _ = p === void 0 ? void 0 : Math.max(0, Math.floor(J(n, e, "max-length", 0))), b = mt(Y(n, e)), [x, w] = y(b), [T, E] = y(!1), [D, O] = y(!1), [k, A] = y(null), j = v(!1), M = v(b), N = v(b);
2674
+ N.current = b, h(() => {
2675
+ M.current !== b && (M.current = b, !T && !j.current && w(b));
2676
+ }, [b, T]), gt(n, e, () => {
2677
+ j.current = !1, w(N.current), O(!1), A(null), a(null);
2678
+ });
2679
+ let P = (e) => Ot(e, {
2680
+ required: l,
2681
+ minLength: m,
2682
+ maxLength: _,
2683
+ email: c
2684
+ });
2685
+ return /* @__PURE__ */ C("div", {
2686
+ className: `md-control local-input${c ? " local-input-email" : ""}`,
2687
+ children: [
2688
+ /* @__PURE__ */ S("label", {
2689
+ className: "md-label",
2690
+ htmlFor: `${t}-input`,
2691
+ children: o
2692
+ }),
2693
+ /* @__PURE__ */ S("input", {
2694
+ id: `${t}-input`,
2695
+ className: "md-text-input",
2696
+ type: c ? "email" : "text",
2697
+ value: x,
2698
+ placeholder: s || void 0,
2699
+ disabled: u,
2700
+ required: l,
2701
+ minLength: m,
2702
+ maxLength: _,
2703
+ "aria-invalid": k || i ? !0 : void 0,
2704
+ onFocus: () => E(!0),
2705
+ onBlur: () => {
2706
+ E(!1), O(!0);
2707
+ let e = P(x);
2708
+ A(e), !e && x !== b && r(x);
2709
+ },
2710
+ onChange: (e) => {
2711
+ let t = e.target.value;
2712
+ w(t), a(null), D && A(P(t)), !j.current && P(t) === null && r(t);
2713
+ },
2714
+ onCompositionStart: () => {
2715
+ j.current = !0;
2716
+ },
2717
+ onCompositionEnd: (e) => {
2718
+ j.current = !1;
2719
+ let t = e.currentTarget.value;
2720
+ w(t), D && A(P(t)), P(t) === null && r(t);
2721
+ }
2722
+ }),
2723
+ /* @__PURE__ */ S($, { message: d ? "无法计算" : k ?? i })
2724
+ ]
2725
+ });
2726
+ }
2727
+ function At({ node: e }) {
2728
+ let t = g(), { runtime: n } = G(), { write: r, error: i, setError: a } = X(e), o = q(n, e, "label", "文本"), s = q(n, e, "placeholder", ""), c = Math.min(40, Math.max(1, Math.floor(J(n, e, "rows", 4)))), l = ft(n, e, "required", !1), { disabled: u, invalid: d } = ht(e), f = K(e, "min-length"), p = K(e, "max-length"), m = f === void 0 ? void 0 : Math.max(0, Math.floor(J(n, e, "min-length", 0))), _ = p === void 0 ? void 0 : Math.max(0, Math.floor(J(n, e, "max-length", 0))), b = mt(Y(n, e)), [x, w] = y(b), [T, E] = y(!1), [D, O] = y(!1), [k, A] = y(null), j = v(!1), M = v(b), N = v(b);
2729
+ N.current = b, h(() => {
2730
+ M.current !== b && (M.current = b, !T && !j.current && w(b));
2731
+ }, [b, T]), gt(n, e, () => {
2732
+ j.current = !1, w(N.current), O(!1), A(null), a(null);
2733
+ });
2734
+ let P = (e) => Ot(e, {
2735
+ required: l,
2736
+ minLength: m,
2737
+ maxLength: _
2738
+ });
2739
+ return /* @__PURE__ */ C("div", {
2740
+ className: "md-control local-textarea",
2741
+ children: [
2742
+ /* @__PURE__ */ S("label", {
2743
+ className: "md-label",
2744
+ htmlFor: `${t}-textarea`,
2745
+ children: o
2746
+ }),
2747
+ /* @__PURE__ */ S("textarea", {
2748
+ id: `${t}-textarea`,
2749
+ className: "md-text-input",
2750
+ rows: c,
2751
+ value: x,
2752
+ placeholder: s || void 0,
2753
+ disabled: u,
2754
+ required: l,
2755
+ minLength: m,
2756
+ maxLength: _,
2757
+ "aria-invalid": k || i ? !0 : void 0,
2758
+ onFocus: () => E(!0),
2759
+ onBlur: () => {
2760
+ E(!1), O(!0);
2761
+ let e = P(x);
2762
+ A(e), !e && x !== b && r(x);
2763
+ },
2764
+ onChange: (e) => {
2765
+ let t = e.target.value;
2766
+ w(t), a(null), D && A(P(t)), !j.current && P(t) === null && r(t);
2767
+ },
2768
+ onCompositionStart: () => {
2769
+ j.current = !0;
2770
+ },
2771
+ onCompositionEnd: (e) => {
2772
+ j.current = !1;
2773
+ let t = e.currentTarget.value;
2774
+ w(t), D && A(P(t)), P(t) === null && r(t);
2775
+ }
2776
+ }),
2777
+ /* @__PURE__ */ S($, { message: d ? "无法计算" : k ?? i })
2778
+ ]
2779
+ });
2780
+ }
2781
+ function jt(e) {
2782
+ let t = e.trim();
2783
+ if (t === "" || t === "-" || t === "+" || t === "." || t === "-.") return { kind: "empty" };
2784
+ let n = Number(t);
2785
+ return Number.isFinite(n) ? {
2786
+ kind: "valid",
2787
+ value: n
2788
+ } : { kind: "invalid" };
2789
+ }
2790
+ function Mt(e, t, n, r) {
2791
+ let i = 1e-9 * Math.max(1, Math.abs(e));
2792
+ if (t !== void 0 && e < t - i) return `不能小于 ${t}`;
2793
+ if (n !== void 0 && e > n + i) return `不能大于 ${n}`;
2794
+ if (!Number.isFinite(r) || r <= 0) return "步长必须大于 0";
2795
+ let a = (e - (t ?? 0)) / r;
2796
+ return Math.abs(a - Math.round(a)) > 1e-9 * Math.max(1, Math.abs(a)) ? `需要按步长 ${r} 取值` : null;
2797
+ }
2798
+ function Nt({ node: e }) {
2799
+ let t = g(), { runtime: n } = G(), { write: r, error: i, setError: a } = X(e), o = q(n, e, "label", "数字"), { disabled: s, invalid: c } = ht(e), l = K(e, "min") !== void 0, u = K(e, "max") !== void 0, d = l ? J(n, e, "min", 0) : void 0, f = u ? J(n, e, "max", 0) : void 0, p = J(n, e, "step", 1), m = Y(n, e), _ = typeof m == "number" && Number.isFinite(m) ? String(m) : "", [b, x] = y(_), [w, T] = y(!1), [E, D] = y(!1), [O, k] = y(null), A = v(!1), j = v(_), M = v(_);
2800
+ M.current = _, h(() => {
2801
+ j.current !== _ && (j.current = _, !w && !A.current && x(_));
2802
+ }, [_, w]), gt(n, e, () => {
2803
+ A.current = !1, x(M.current), D(!1), k(null), a(null);
2804
+ });
2805
+ let N = (e, t) => {
2806
+ let n = jt(e);
2807
+ if (n.kind !== "valid") return t && k("请输入有效数字"), !1;
2808
+ let i = Mt(n.value, d, f, p);
2809
+ return i ? (t && k(i), !1) : (k(null), r(n.value));
2810
+ };
2811
+ return /* @__PURE__ */ C("div", {
2812
+ className: "md-control local-number",
2813
+ children: [
2814
+ /* @__PURE__ */ S("label", {
2815
+ className: "md-label",
2816
+ htmlFor: `${t}-number`,
2817
+ children: o
2818
+ }),
2819
+ /* @__PURE__ */ S("input", {
2820
+ id: `${t}-number`,
2821
+ className: "md-text-input",
2822
+ type: "text",
2823
+ inputMode: "decimal",
2824
+ value: b,
2825
+ disabled: s,
2826
+ "aria-invalid": O || i ? !0 : void 0,
2827
+ onFocus: () => T(!0),
2828
+ onBlur: () => {
2829
+ T(!1), D(!0), N(b, !0);
2830
+ },
2831
+ onChange: (e) => {
2832
+ let t = e.target.value;
2833
+ x(t), a(null), A.current || N(t, E);
2834
+ },
2835
+ onCompositionStart: () => {
2836
+ A.current = !0;
2837
+ },
2838
+ onCompositionEnd: (e) => {
2839
+ A.current = !1, N(e.currentTarget.value, E);
2840
+ }
2841
+ }),
2842
+ d !== void 0 || f !== void 0 || p !== void 0 ? /* @__PURE__ */ C("span", {
2843
+ className: "md-hint",
2844
+ children: [
2845
+ d === void 0 ? "" : `最小 ${d}`,
2846
+ d !== void 0 && f !== void 0 ? " · " : "",
2847
+ f === void 0 ? "" : `最大 ${f}`,
2848
+ p === void 0 ? "" : ` · 步长 ${p}`
2849
+ ]
2850
+ }) : null,
2851
+ /* @__PURE__ */ S($, { message: c ? "无法计算" : O ?? i })
2852
+ ]
2853
+ });
2854
+ }
2855
+ function Pt({ node: e }) {
2856
+ let t = g(), { runtime: n } = G(), { write: r, error: i } = X(e), a = q(n, e, "label", "滑块"), { disabled: o, invalid: s } = ht(e), c = J(n, e, "min", 0), l = J(n, e, "max", 100), u = J(n, e, "step", 1), d = Y(n, e), f = Math.min(l, Math.max(c, typeof d == "number" && Number.isFinite(d) ? d : c));
2857
+ return /* @__PURE__ */ C("div", {
2858
+ className: "md-control md-slider local-slider",
2859
+ children: [
2860
+ /* @__PURE__ */ C("label", {
2861
+ className: "md-label",
2862
+ htmlFor: `${t}-slider`,
2863
+ children: [/* @__PURE__ */ S("span", { children: a }), /* @__PURE__ */ S("span", {
2864
+ className: "md-slider-value",
2865
+ "aria-hidden": "true",
2866
+ children: f
2867
+ })]
2868
+ }),
2869
+ /* @__PURE__ */ S("input", {
2870
+ id: `${t}-slider`,
2871
+ type: "range",
2872
+ min: c,
2873
+ max: l,
2874
+ step: u,
2875
+ value: f,
2876
+ disabled: o,
2877
+ onChange: (e) => r(Number(e.target.value))
2878
+ }),
2879
+ /* @__PURE__ */ S($, { message: s ? "无法计算" : i })
2880
+ ]
2881
+ });
2882
+ }
2883
+ function Ft({ node: e }) {
2884
+ let t = g(), { runtime: n } = G(), { write: r, error: i } = X(e), a = q(n, e, "label", "开关"), { disabled: o, invalid: s } = ht(e), c = Y(n, e) === !0;
2885
+ return /* @__PURE__ */ C("div", {
2886
+ className: "md-control md-toggle local-toggle",
2887
+ children: [/* @__PURE__ */ C("label", {
2888
+ className: "md-toggle-label",
2889
+ htmlFor: `${t}-toggle`,
2890
+ children: [/* @__PURE__ */ S("input", {
2891
+ id: `${t}-toggle`,
2892
+ type: "checkbox",
2893
+ checked: c,
2894
+ disabled: o,
2895
+ onChange: (e) => r(e.target.checked)
2896
+ }), /* @__PURE__ */ S("span", { children: a })]
2897
+ }), /* @__PURE__ */ S($, { message: s ? "无法计算" : i })]
2898
+ });
2899
+ }
2900
+ function It({ node: e }) {
2901
+ let t = g(), { runtime: n } = G(), { write: r, error: i } = X(e), a = q(n, e, "label", "勾选"), { disabled: o, invalid: s } = ht(e), c = Y(n, e) === !0;
2902
+ return /* @__PURE__ */ C("div", {
2903
+ className: "md-control local-checkbox",
2904
+ children: [/* @__PURE__ */ C("label", {
2905
+ className: "md-toggle-label",
2906
+ htmlFor: `${t}-checkbox`,
2907
+ children: [/* @__PURE__ */ S("input", {
2908
+ id: `${t}-checkbox`,
2909
+ type: "checkbox",
2910
+ checked: c,
2911
+ disabled: o,
2912
+ onChange: (e) => r(e.target.checked)
2913
+ }), /* @__PURE__ */ S("span", { children: a })]
2914
+ }), /* @__PURE__ */ S($, { message: s ? "无法计算" : i })]
2915
+ });
2916
+ }
2917
+ function Lt({ node: e }) {
2918
+ let t = g(), { runtime: n } = G(), { write: r, error: i } = X(e), a = q(n, e, "label", "日期"), { disabled: o, invalid: s } = ht(e), c = ft(n, e, "required", !1), l = q(n, e, "min", ""), u = q(n, e, "max", ""), d = Y(n, e), f = typeof d == "string" ? d : "", [p, m] = y(!1), h = p && c && f === "" ? "请选择日期" : null;
2919
+ return /* @__PURE__ */ C("div", {
2920
+ className: "md-control local-date",
2921
+ children: [
2922
+ /* @__PURE__ */ S("label", {
2923
+ className: "md-label",
2924
+ htmlFor: `${t}-date`,
2925
+ children: a
2926
+ }),
2927
+ /* @__PURE__ */ S("input", {
2928
+ id: `${t}-date`,
2929
+ className: "md-text-input",
2930
+ type: "date",
2931
+ value: f,
2932
+ min: l || void 0,
2933
+ max: u || void 0,
2934
+ required: c,
2935
+ disabled: o,
2936
+ "aria-invalid": h || i ? !0 : void 0,
2937
+ onBlur: () => m(!0),
2938
+ onChange: (e) => {
2939
+ m(!0), r(e.target.value);
2940
+ }
2941
+ }),
2942
+ /* @__PURE__ */ S($, { message: s ? "无法计算" : h ?? i })
2943
+ ]
2944
+ });
2945
+ }
2946
+ function Rt(e) {
2947
+ return (e.children ?? []).filter((e) => e.type === "component" && e.name === "option").map((e, t) => ({
2948
+ value: K(e, "value") ?? `option-${t + 1}`,
2949
+ node: e
2950
+ }));
2951
+ }
2952
+ function zt(e, t) {
2953
+ if (!t) return "";
2954
+ let n = "";
2955
+ for (let r of t) if (r.type === "text" || r.type === "inlineCode") n += r.value ?? "";
2956
+ else if (r.type === "fallback") n += r.value ?? "";
2957
+ else if (r.type === "interpolation") try {
2958
+ n += ut(e.evaluate(r.value ?? "")) ?? "";
2959
+ } catch {
2960
+ n += "无法计算";
2961
+ }
2962
+ else r.type === "break" ? n += " " : n += zt(e, r.children);
2963
+ return n;
2964
+ }
2965
+ function Bt(e, t) {
2966
+ return zt(e, t.children) || K(t, "value") || "";
2967
+ }
2968
+ function Vt() {
2969
+ return null;
2970
+ }
2971
+ function Ht({ node: e }) {
2972
+ let t = g(), { runtime: n } = G(), { write: r, error: i } = X(e), a = q(n, e, "label", "选择"), { disabled: o, invalid: s } = ht(e), c = Rt(e), l = Y(n, e), u = typeof l == "string" ? l : "", d = c.some((e) => e.value === u) ? u : c[0]?.value ?? "";
2973
+ return c.length === 0 ? /* @__PURE__ */ S(Z, { message: "缺少选项" }) : /* @__PURE__ */ C("div", {
2974
+ className: "md-control md-select local-select",
2975
+ children: [
2976
+ /* @__PURE__ */ S("label", {
2977
+ className: "md-label",
2978
+ htmlFor: `${t}-select`,
2979
+ children: a
2980
+ }),
2981
+ /* @__PURE__ */ S("select", {
2982
+ id: `${t}-select`,
2983
+ className: "md-select-input",
2984
+ value: d,
2985
+ disabled: o,
2986
+ onChange: (e) => r(e.target.value),
2987
+ children: c.map((e) => /* @__PURE__ */ S("option", {
2988
+ value: e.value,
2989
+ children: Bt(n, e.node) || e.value
2990
+ }, e.node.id))
2991
+ }),
2992
+ /* @__PURE__ */ S($, { message: s ? "无法计算" : i })
2993
+ ]
2994
+ });
2995
+ }
2996
+ function Ut({ node: e, visible: t }) {
2997
+ let n = g(), r = G(), { runtime: i } = r, { write: a, error: o } = X(e), s = q(i, e, "label", "选项"), { disabled: c, invalid: l } = ht(e), u = Rt(e), d = Y(i, e), f = typeof d == "string" ? d : "", p = u.findIndex((e) => e.value === f), m = p >= 0 ? p : 0, h = v([]);
2998
+ if (u.length === 0) return /* @__PURE__ */ S(Z, { message: "缺少选项" });
2999
+ let _ = (e) => {
3000
+ let t = u[e];
3001
+ t && (a(t.value), h.current[e]?.focus());
3002
+ }, y = (e, t) => {
3003
+ let n = -1;
3004
+ e.key === "ArrowRight" || e.key === "ArrowDown" ? n = (t + 1) % u.length : e.key === "ArrowLeft" || e.key === "ArrowUp" ? n = (t - 1 + u.length) % u.length : e.key === "Home" ? n = 0 : e.key === "End" && (n = u.length - 1), !(n < 0) && (e.preventDefault(), _(n));
3005
+ };
3006
+ return /* @__PURE__ */ C("div", {
3007
+ className: "md-control local-choices",
3008
+ children: [
3009
+ /* @__PURE__ */ S("span", {
3010
+ className: "md-label",
3011
+ id: `${n}-choices-label`,
3012
+ children: s
3013
+ }),
3014
+ /* @__PURE__ */ S("div", {
3015
+ className: "local-choice-list",
3016
+ role: "radiogroup",
3017
+ "aria-labelledby": `${n}-choices-label`,
3018
+ "aria-disabled": c || void 0,
3019
+ children: u.map((e, n) => {
3020
+ let i = e.value === f;
3021
+ return /* @__PURE__ */ S("button", {
3022
+ ref: (e) => {
3023
+ h.current[n] = e;
3024
+ },
3025
+ type: "button",
3026
+ role: "radio",
3027
+ "aria-checked": i,
3028
+ tabIndex: n === m ? 0 : -1,
3029
+ disabled: c,
3030
+ className: `local-choice${i ? " is-selected" : ""}`,
3031
+ onClick: () => a(e.value),
3032
+ onKeyDown: (e) => y(e, n),
3033
+ children: Ct(r, e.node.children, t)
3034
+ }, e.node.id);
3035
+ })
3036
+ }),
3037
+ /* @__PURE__ */ S($, { message: l ? "无法计算" : o })
3038
+ ]
3039
+ });
3040
+ }
3041
+ function Wt({ node: e, visible: t }) {
3042
+ let n = g(), r = G(), { runtime: i } = r, { write: a, error: o } = X(e), s = q(i, e, "label", "选项"), { disabled: c, invalid: l } = ht(e), u = Rt(e), d = Y(i, e), f = typeof d == "string" ? d : "", p = n;
3043
+ return u.length === 0 ? /* @__PURE__ */ S(Z, { message: "缺少选项" }) : /* @__PURE__ */ C("fieldset", {
3044
+ className: "md-control local-radio-group",
3045
+ disabled: c,
3046
+ children: [
3047
+ /* @__PURE__ */ S("legend", {
3048
+ className: "md-label",
3049
+ children: s
3050
+ }),
3051
+ u.map((e) => /* @__PURE__ */ C("label", {
3052
+ className: "local-radio-option",
3053
+ children: [/* @__PURE__ */ S("input", {
3054
+ type: "radio",
3055
+ name: p,
3056
+ value: e.value,
3057
+ checked: f === e.value,
3058
+ onChange: () => a(e.value)
3059
+ }), /* @__PURE__ */ S("span", { children: Ct(r, e.node.children, t) })]
3060
+ }, e.node.id)),
3061
+ /* @__PURE__ */ S($, { message: l ? "无法计算" : o })
3062
+ ]
3063
+ });
3064
+ }
3065
+ function Gt(e) {
3066
+ return ((e.children ?? []).find((e) => e.type === "list")?.children ?? []).filter((e) => e.type === "listItem").map((e, t) => ({
3067
+ id: `item-${t + 1}`,
3068
+ node: e
3069
+ }));
3070
+ }
3071
+ function Kt({ node: e, visible: t }) {
3072
+ let n = g(), r = G(), { runtime: i } = r, { write: a, error: o } = X(e), s = q(i, e, "label", "清单"), { disabled: c, invalid: l } = ht(e), u = Gt(e), d = Y(i, e), f = Array.isArray(d) ? d.filter((e) => typeof e == "string") : [];
3073
+ if (u.length === 0) return /* @__PURE__ */ S(Z, { message: "清单需要任务列表" });
3074
+ let p = (e, t) => {
3075
+ let n = new Set(f);
3076
+ t ? n.add(e) : n.delete(e), a(u.filter((e) => n.has(e.id)).map((e) => e.id));
3077
+ };
3078
+ return /* @__PURE__ */ C("fieldset", {
3079
+ className: "local-checklist",
3080
+ disabled: c,
3081
+ children: [
3082
+ /* @__PURE__ */ S("legend", {
3083
+ className: "md-label",
3084
+ children: s
3085
+ }),
3086
+ u.map((e) => /* @__PURE__ */ C("div", {
3087
+ className: "local-checklist-item",
3088
+ children: [/* @__PURE__ */ S("input", {
3089
+ id: `${n}-${e.id}`,
3090
+ type: "checkbox",
3091
+ checked: f.includes(e.id),
3092
+ onChange: (t) => p(e.id, t.target.checked)
3093
+ }), /* @__PURE__ */ S("label", {
3094
+ className: "local-checklist-text",
3095
+ htmlFor: `${n}-${e.id}`,
3096
+ children: Ct(r, e.node.children, t)
3097
+ })]
3098
+ }, e.id)),
3099
+ /* @__PURE__ */ S($, { message: l ? "无法计算" : o })
3100
+ ]
3101
+ });
3102
+ }
3103
+ function qt(e) {
3104
+ let t = Math.max(0, Math.floor(e)), n = Math.floor(t / 60), r = t % 60;
3105
+ return n === 0 ? `${r} 秒` : `${n}:${String(r).padStart(2, "0")}`;
3106
+ }
3107
+ function Jt({ node: e }) {
3108
+ let { runtime: t } = G(), { write: n, error: r } = X(e), i = q(t, e, "label", "计数"), { disabled: a, invalid: o } = ht(e), s = J(t, e, "min", 0), c = K(e, "max") === void 0 ? void 0 : J(t, e, "max", 0), l = J(t, e, "step", 1), u = Y(t, e), d = typeof u == "number" && Number.isFinite(u) ? u : s, f = Number.isFinite(l) && l > 0 ? l : 1, p = 1e-9 * Math.max(1, Math.abs(d)), m = d - f >= s - p, h = c === void 0 || d + f <= c + p, g = (e) => {
3109
+ let t = Number((d + e * f).toFixed(12));
3110
+ n(t);
3111
+ };
3112
+ return /* @__PURE__ */ C("div", {
3113
+ className: "local-counter",
3114
+ role: "group",
3115
+ "aria-label": i,
3116
+ children: [
3117
+ /* @__PURE__ */ S("span", {
3118
+ className: "md-label",
3119
+ children: i
3120
+ }),
3121
+ /* @__PURE__ */ C("div", {
3122
+ className: "local-counter-row",
3123
+ children: [
3124
+ /* @__PURE__ */ S("button", {
3125
+ type: "button",
3126
+ className: "md-button md-button-secondary local-counter-button",
3127
+ "aria-label": `${i} 减少`,
3128
+ disabled: a || !m,
3129
+ onClick: () => g(-1),
3130
+ children: "−"
3131
+ }),
3132
+ /* @__PURE__ */ S("span", {
3133
+ className: "local-counter-value",
3134
+ "aria-live": "polite",
3135
+ children: d
3136
+ }),
3137
+ /* @__PURE__ */ S("button", {
3138
+ type: "button",
3139
+ className: "md-button md-button-secondary local-counter-button",
3140
+ "aria-label": `${i} 增加`,
3141
+ disabled: a || !h,
3142
+ onClick: () => g(1),
3143
+ children: "+"
3144
+ }),
3145
+ /* @__PURE__ */ S("button", {
3146
+ type: "button",
3147
+ className: "md-button md-button-quiet local-counter-reset",
3148
+ disabled: a,
3149
+ onClick: () => {
3150
+ try {
3151
+ t.reset(e);
3152
+ } catch {}
3153
+ },
3154
+ children: "恢复初值"
3155
+ })
3156
+ ]
3157
+ }),
3158
+ /* @__PURE__ */ S($, { message: o ? "无法计算" : r })
3159
+ ]
3160
+ });
3161
+ }
3162
+ function Yt({ node: e, visible: t }) {
3163
+ let { runtime: n } = G(), r = q(n, e, "label", "计时器"), i = J(n, e, "duration", 60), a = Math.floor(i), o = Y(n, e), s = typeof o == "number" && Number.isFinite(o) ? Math.max(0, Math.ceil(o)) : a, [c, l] = y(!1), [u, d] = y(!1), f = v(0), m = v(s);
3164
+ m.current = s;
3165
+ let [g, _] = y(null), b = p((t) => {
3166
+ try {
3167
+ let r = n.set(e, t);
3168
+ r.length && _(r.map((e) => e.message).join(";"));
3169
+ } catch {}
3170
+ }, [e, n]);
3171
+ return h(() => {
3172
+ if (!c) return;
3173
+ let e = window.setInterval(() => {
3174
+ let e = Math.max(0, Math.ceil((f.current - performance.now()) / 1e3));
3175
+ e !== m.current && (m.current = e, b(e)), e <= 0 && (l(!1), d(!0));
3176
+ }, 200);
3177
+ return () => window.clearInterval(e);
3178
+ }, [c, b]), h(() => {
3179
+ if (t || !c) return;
3180
+ let e = Math.max(0, Math.ceil((f.current - performance.now()) / 1e3));
3181
+ m.current = e, b(e), l(!1);
3182
+ }, [
3183
+ t,
3184
+ c,
3185
+ b
3186
+ ]), gt(n, e, () => {
3187
+ l(!1), d(!1), _(null);
3188
+ }), !Number.isFinite(i) || a <= 0 ? /* @__PURE__ */ S(Z, { message: "计时时长必须是大于 0 的秒数" }) : /* @__PURE__ */ C("div", {
3189
+ className: "local-timer",
3190
+ role: "group",
3191
+ "aria-label": r,
3192
+ children: [
3193
+ /* @__PURE__ */ C("div", {
3194
+ className: "local-timer-head",
3195
+ children: [/* @__PURE__ */ S("span", {
3196
+ className: "md-label",
3197
+ children: r
3198
+ }), /* @__PURE__ */ S("span", {
3199
+ className: "local-timer-value",
3200
+ role: "timer",
3201
+ "aria-label": `剩余 ${s} 秒`,
3202
+ children: qt(s)
3203
+ })]
3204
+ }),
3205
+ /* @__PURE__ */ C("div", {
3206
+ className: "local-timer-controls",
3207
+ children: [
3208
+ /* @__PURE__ */ S("button", {
3209
+ type: "button",
3210
+ className: "md-button md-button-primary",
3211
+ onClick: () => {
3212
+ if (c) return;
3213
+ let e = s > 0 ? s : a;
3214
+ s <= 0 && (m.current = a, b(a)), f.current = performance.now() + e * 1e3, d(!1), _(null), l(!0);
3215
+ },
3216
+ disabled: c,
3217
+ children: "开始"
3218
+ }),
3219
+ /* @__PURE__ */ S("button", {
3220
+ type: "button",
3221
+ className: "md-button md-button-secondary",
3222
+ onClick: () => {
3223
+ if (!c) return;
3224
+ let e = Math.max(0, Math.ceil((f.current - performance.now()) / 1e3));
3225
+ m.current = e, b(e), l(!1);
3226
+ },
3227
+ disabled: !c,
3228
+ children: "暂停"
3229
+ }),
3230
+ /* @__PURE__ */ S("button", {
3231
+ type: "button",
3232
+ className: "md-button md-button-quiet",
3233
+ onClick: () => {
3234
+ l(!1), d(!1), _(null), m.current = a;
3235
+ try {
3236
+ n.reset(e);
3237
+ } catch {}
3238
+ },
3239
+ children: "重置"
3240
+ })
3241
+ ]
3242
+ }),
3243
+ /* @__PURE__ */ S("span", {
3244
+ className: "local-timer-status",
3245
+ role: "status",
3246
+ "aria-live": "polite",
3247
+ children: u ? "计时完成" : c ? "计时中" : "已暂停"
3248
+ }),
3249
+ /* @__PURE__ */ S($, { message: g })
3250
+ ]
3251
+ });
3252
+ }
3253
+ function Xt({ node: e }) {
3254
+ let { runtime: t } = G(), n = q(t, e, "label", "进度"), r = J(t, e, "max", 100), i = lt(t, e, "value");
3255
+ if (!Number.isFinite(r) || r <= 0) return /* @__PURE__ */ S(Z, { message: "进度上限必须是正数" });
3256
+ if (!i.present || !i.ok) return /* @__PURE__ */ S(Z, {});
3257
+ let a = i.value, o = typeof a == "number" ? a : typeof a == "string" && a.trim() !== "" ? Number(a) : NaN;
3258
+ if (!Number.isFinite(o)) return /* @__PURE__ */ S(Z, {});
3259
+ if (o < 0 || o > r) return /* @__PURE__ */ S(Z, { message: `进度值需要在 0 到 ${r} 之间` });
3260
+ let s = o / r * 100;
3261
+ return /* @__PURE__ */ C("div", {
3262
+ className: "local-progress",
3263
+ children: [/* @__PURE__ */ C("div", {
3264
+ className: "local-progress-head",
3265
+ children: [/* @__PURE__ */ S("span", {
3266
+ className: "md-label",
3267
+ children: n
3268
+ }), /* @__PURE__ */ C("span", {
3269
+ className: "local-progress-value",
3270
+ children: [Math.round(s), "%"]
3271
+ })]
3272
+ }), /* @__PURE__ */ S("div", {
3273
+ className: "local-progress-track",
3274
+ role: "progressbar",
3275
+ "aria-label": n || "进度",
3276
+ "aria-valuemin": 0,
3277
+ "aria-valuemax": r,
3278
+ "aria-valuenow": o,
3279
+ children: /* @__PURE__ */ S("div", {
3280
+ className: "local-progress-fill",
3281
+ style: { width: `${s}%` }
3282
+ })
3283
+ })]
3284
+ });
3285
+ }
3286
+ function Zt({ node: e, visible: t }) {
3287
+ let { runtime: n, render: r } = G(), i = q(n, e, "title", ""), a = ft(n, e, "reset", !0), [o, s] = y(null);
3288
+ return /* @__PURE__ */ C("section", {
3289
+ className: "local-panel",
3290
+ "aria-label": i || "参数面板",
3291
+ children: [
3292
+ i || a ? /* @__PURE__ */ C("div", {
3293
+ className: "local-panel-head",
3294
+ children: [i ? /* @__PURE__ */ S("h3", {
3295
+ className: "local-panel-title",
3296
+ children: i
3297
+ }) : /* @__PURE__ */ S("span", {}), a ? /* @__PURE__ */ S("button", {
3298
+ type: "button",
3299
+ className: "md-button md-button-quiet local-panel-reset",
3300
+ onClick: () => {
3301
+ try {
3302
+ n.reset(e), s(null);
3303
+ } catch (e) {
3304
+ s(e instanceof Error ? e.message : "无法恢复默认");
3305
+ }
3306
+ },
3307
+ "aria-label": i ? `${i} 恢复默认` : "恢复默认",
3308
+ children: "恢复默认"
3309
+ }) : null]
3310
+ }) : null,
3311
+ /* @__PURE__ */ S("div", {
3312
+ className: "local-panel-body",
3313
+ children: r(e.children ?? [], t)
3314
+ }),
3315
+ /* @__PURE__ */ S($, { message: o })
3316
+ ]
3317
+ });
3318
+ }
3319
+ function Qt({ node: e, visible: t }) {
3320
+ let { runtime: n, render: r } = G(), i = q(n, e, "title", "");
3321
+ return /* @__PURE__ */ C("section", {
3322
+ className: "md-card local-card",
3323
+ children: [i ? /* @__PURE__ */ S("h3", {
3324
+ className: "md-card-title",
3325
+ children: i
3326
+ }) : null, /* @__PURE__ */ S("div", {
3327
+ className: "md-card-body",
3328
+ children: r(e.children ?? [], t)
3329
+ })]
3330
+ });
3331
+ }
3332
+ function $t({ node: e, visible: t }) {
3333
+ let { runtime: n, render: r } = G(), i = Math.min(4, Math.max(1, Math.floor(J(n, e, "columns", 2))));
3334
+ return /* @__PURE__ */ S("div", {
3335
+ className: "local-grid",
3336
+ style: { "--local-grid-columns": String(i) },
3337
+ children: r(e.children ?? [], t)
3338
+ });
3339
+ }
3340
+ function en({ node: e, visible: t }) {
3341
+ let { render: n } = G();
3342
+ return /* @__PURE__ */ S("div", {
3343
+ className: "local-tabpanel-body",
3344
+ children: n(e.children ?? [], t)
3345
+ });
3346
+ }
3347
+ function tn() {
3348
+ return null;
3349
+ }
3350
+ function nn({ node: e, visible: t }) {
3351
+ let n = g(), { runtime: r, render: i } = G(), { write: a, error: o } = X(e), s = q(r, e, "label", ""), c = (e.children ?? []).filter((e) => e.type === "component" && e.name === "tab"), l = c.map((e, t) => K(e, "value") ?? `tab-${t + 1}`), u = c.map((e, t) => q(r, e, "label", l[t])), d = K(e, "initial") ?? l[0] ?? "", f = K(e, "bind") !== void 0, p = Y(r, e), m = typeof p == "string" ? p : "", [h, _] = y(() => l.includes(d) ? d : l[0] ?? ""), b = v([]);
3352
+ if (gt(r, e, () => {
3353
+ _(l.includes(d) ? d : l[0] ?? "");
3354
+ }), c.length === 0) return /* @__PURE__ */ S(Z, { message: "标签页至少需要一个 tab" });
3355
+ let x = f ? l.includes(m) ? m : l[0] : l.includes(h) ? h : l[0], w = Math.max(0, l.indexOf(x)), T = (e) => {
3356
+ let t = l[e];
3357
+ t !== void 0 && (f ? a(t) : _(t), b.current[e]?.focus());
3358
+ };
3359
+ return /* @__PURE__ */ C("section", {
3360
+ className: "local-tabs",
3361
+ "aria-label": s || "选项卡",
3362
+ children: [
3363
+ s ? /* @__PURE__ */ S("div", {
3364
+ className: "local-tabs-label",
3365
+ children: s
3366
+ }) : null,
3367
+ /* @__PURE__ */ S("div", {
3368
+ className: "local-tablist",
3369
+ role: "tablist",
3370
+ "aria-label": s || "选项卡",
3371
+ onKeyDown: (e) => {
3372
+ let t = -1;
3373
+ e.key === "ArrowRight" ? t = (w + 1) % c.length : e.key === "ArrowLeft" ? t = (w - 1 + c.length) % c.length : e.key === "Home" ? t = 0 : e.key === "End" && (t = c.length - 1), !(t < 0) && (e.preventDefault(), T(t));
3374
+ },
3375
+ children: c.map((e, t) => {
3376
+ let r = l[t], i = r === x;
3377
+ return /* @__PURE__ */ S("button", {
3378
+ ref: (e) => {
3379
+ b.current[t] = e;
3380
+ },
3381
+ id: `${n}-tab-${t}`,
3382
+ type: "button",
3383
+ role: "tab",
3384
+ className: `local-tab${i ? " is-selected" : ""}`,
3385
+ "aria-selected": i,
3386
+ "aria-controls": `${n}-panel-${t}`,
3387
+ tabIndex: i ? 0 : -1,
3388
+ onClick: () => {
3389
+ f ? a(r) : _(r);
3390
+ },
3391
+ children: u[t]
3392
+ }, e.id);
3393
+ })
3394
+ }),
3395
+ c.map((e, r) => {
3396
+ let a = l[r] === x;
3397
+ return /* @__PURE__ */ S("div", {
3398
+ id: `${n}-panel-${r}`,
3399
+ className: "local-tabpanel",
3400
+ role: "tabpanel",
3401
+ "aria-labelledby": `${n}-tab-${r}`,
3402
+ tabIndex: 0,
3403
+ hidden: !a,
3404
+ children: i(e.children ?? [], t && a)
3405
+ }, e.id);
3406
+ }),
3407
+ /* @__PURE__ */ S($, { message: o })
3408
+ ]
3409
+ });
3410
+ }
3411
+ function rn({ node: e, visible: t }) {
3412
+ let { runtime: n, render: r } = G(), i = q(n, e, "label", "");
3413
+ return /* @__PURE__ */ C("div", {
3414
+ className: "local-accordion",
3415
+ role: "group",
3416
+ "aria-label": i || "折叠面板",
3417
+ children: [i ? /* @__PURE__ */ S("div", {
3418
+ className: "local-accordion-label",
3419
+ children: i
3420
+ }) : null, r(e.children ?? [], t)]
3421
+ });
3422
+ }
3423
+ function an({ node: e, visible: t }) {
3424
+ let n = g(), { runtime: r, render: i } = G(), a = q(r, e, "label", "折叠内容"), o = ft(r, e, "open", !1), [s, c] = y(o);
3425
+ gt(r, e, () => {
3426
+ c(o);
3427
+ });
3428
+ let l = `${n}-disclosure-trigger`, u = `${n}-disclosure-panel`;
3429
+ return /* @__PURE__ */ C("div", {
3430
+ className: "local-disclosure",
3431
+ children: [/* @__PURE__ */ S("h3", {
3432
+ className: "local-disclosure-heading",
3433
+ children: /* @__PURE__ */ C("button", {
3434
+ id: l,
3435
+ type: "button",
3436
+ className: "local-disclosure-trigger",
3437
+ "aria-expanded": s,
3438
+ "aria-controls": u,
3439
+ onClick: () => c((e) => !e),
3440
+ children: [/* @__PURE__ */ S("span", {
3441
+ className: `local-chevron${s ? " is-open" : ""}`,
3442
+ "aria-hidden": "true",
3443
+ children: "▸"
3444
+ }), /* @__PURE__ */ S("span", { children: a })]
3445
+ })
3446
+ }), /* @__PURE__ */ S("div", {
3447
+ id: u,
3448
+ className: "local-disclosure-panel",
3449
+ role: "region",
3450
+ "aria-labelledby": l,
3451
+ hidden: !s,
3452
+ children: i(e.children ?? [], t && s)
3453
+ })]
3454
+ });
3455
+ }
3456
+ function on({ node: e, visible: t }) {
3457
+ let { runtime: n, render: r } = G(), i = dt(n, e, "when", !1), a = i.ok ? i.value : !1, o = !i.ok, s = v(null), c = v(a), l = v(!1);
3458
+ return h(() => {
3459
+ if (c.current && !a) {
3460
+ if (l.current) {
3461
+ let e = s.current?.closest(".local-document");
3462
+ e && (e.tabIndex = -1, e.focus({ preventScroll: !0 }));
3463
+ }
3464
+ l.current = !1;
3465
+ }
3466
+ c.current = a;
3467
+ }, [a]), /* @__PURE__ */ C(x, { children: [o ? /* @__PURE__ */ S(Z, {}) : null, /* @__PURE__ */ S("div", {
3468
+ ref: s,
3469
+ className: "local-if md-if",
3470
+ role: "group",
3471
+ "aria-label": "条件内容",
3472
+ tabIndex: -1,
3473
+ hidden: !a,
3474
+ "aria-hidden": !a,
3475
+ onFocus: () => {
3476
+ l.current = !0;
3477
+ },
3478
+ onBlur: (e) => {
3479
+ s.current?.contains(e.relatedTarget) || (l.current = !1);
3480
+ },
3481
+ children: r(e.children ?? [], t && a)
3482
+ })] });
3483
+ }
3484
+ function sn({ node: e, visible: t }) {
3485
+ let { runtime: n, render: r } = G(), i = q(n, e, "title", ""), a = K(e, "tone") ?? "info", o = a === "success" || a === "warning" ? a : "info", s = o === "warning" ? "alert" : "status";
3486
+ return /* @__PURE__ */ C("div", {
3487
+ className: `local-alert local-alert-${o}`,
3488
+ role: s,
3489
+ children: [i ? /* @__PURE__ */ S("div", {
3490
+ className: "local-alert-title",
3491
+ children: i
3492
+ }) : null, /* @__PURE__ */ S("div", {
3493
+ className: "local-alert-body",
3494
+ children: r(e.children ?? [], t)
3495
+ })]
3496
+ });
3497
+ }
3498
+ function cn({ node: e, visible: t }) {
3499
+ let n = G(), { runtime: r } = n, i = K(e, "tone") ?? "neutral";
3500
+ return /* @__PURE__ */ S("span", {
3501
+ className: `md-badge md-badge-${i === "success" || i === "warning" ? i : "neutral"} local-badge`,
3502
+ children: Ct(n, e.children, t)
3503
+ });
3504
+ }
3505
+ function ln({ node: e, visible: t }) {
3506
+ let n = g(), r = G(), { runtime: i } = r, a = q(i, e, "text", "提示"), [o, s] = y(!1), c = `${n}-tooltip`;
3507
+ return /* @__PURE__ */ C("span", {
3508
+ className: "local-tooltip",
3509
+ onMouseEnter: () => s(!0),
3510
+ onMouseLeave: () => s(!1),
3511
+ children: [/* @__PURE__ */ S("span", {
3512
+ className: "local-tooltip-trigger",
3513
+ tabIndex: 0,
3514
+ "aria-describedby": c,
3515
+ onFocus: () => s(!0),
3516
+ onBlur: () => s(!1),
3517
+ onKeyDown: (e) => {
3518
+ e.key === "Escape" && (e.stopPropagation(), s(!1));
3519
+ },
3520
+ children: Ct(r, e.children, t)
3521
+ }), /* @__PURE__ */ S("span", {
3522
+ id: c,
3523
+ role: "tooltip",
3524
+ className: `local-tooltip-bubble${o ? " is-visible" : ""}`,
3525
+ children: a
3526
+ })]
3527
+ });
3528
+ }
3529
+ var un = {
3530
+ panel: Zt,
3531
+ card: Qt,
3532
+ grid: $t,
3533
+ tabs: nn,
3534
+ tab: en,
3535
+ accordion: rn,
3536
+ disclosure: an,
3537
+ if: on,
3538
+ alert: sn,
3539
+ badge: cn,
3540
+ tooltip: ln,
3541
+ input: kt,
3542
+ textarea: At,
3543
+ number: Nt,
3544
+ slider: Pt,
3545
+ toggle: Ft,
3546
+ checkbox: It,
3547
+ date: Lt,
3548
+ select: Ht,
3549
+ choices: Ut,
3550
+ "radio-group": Wt,
3551
+ option: Vt,
3552
+ node: en,
3553
+ edge: tn,
3554
+ counter: Jt,
3555
+ timer: Yt,
3556
+ checklist: Kt,
3557
+ progress: Xt
3558
+ };
3559
+ function dn({ document: e, runtime: t, onDiagnostics: n, urlPolicy: r }) {
3560
+ let i = g(), a = _(() => at(e, `local-heading-${i}`), [e, i]), o = v(n);
3561
+ o.current = n;
3562
+ let s = p((e) => {
3563
+ o.current?.(e);
3564
+ }, []), c = p((e) => {
3565
+ try {
3566
+ return t.subscribe(e);
3567
+ } catch {
3568
+ return () => {};
3569
+ }
3570
+ }, [t]), l = p(() => {
3571
+ try {
3572
+ return t.snapshot();
3573
+ } catch {
3574
+ return ct;
3575
+ }
3576
+ }, [t]);
3577
+ b(c, l, l);
3578
+ let u = {
3579
+ runtime: t,
3580
+ urlPolicy: r,
3581
+ anchors: a
3582
+ }, d = (e, n = !0) => /* @__PURE__ */ S(ot.Provider, {
3583
+ value: {
3584
+ runtime: t,
3585
+ render: d,
3586
+ visible: n,
3587
+ report: s,
3588
+ urlPolicy: r,
3589
+ anchors: a
3590
+ },
3591
+ children: Q(u, e ?? [], n)
3592
+ });
3593
+ return /* @__PURE__ */ S("article", {
3594
+ className: "md-document local-document",
3595
+ "aria-label": "交互文档",
3596
+ children: d(e.nodes, !0)
3597
+ });
3598
+ }
3599
+ function fn({ source: e, onDiagnostics: t, urlPolicy: n }) {
3600
+ let r = _(() => a(e), [e]), i = _(() => {
3601
+ if (!r.ok) return null;
3602
+ try {
3603
+ return c(r.document);
3604
+ } catch {
3605
+ return null;
3606
+ }
3607
+ }, [r]), o = v(t);
3608
+ o.current = t;
3609
+ let s = v(i);
3610
+ s.current = i;
3611
+ let l = v(0);
3612
+ return h(() => (l.current += 1, () => {
3613
+ --l.current;
3614
+ }), []), h(() => {
3615
+ o.current?.(r.diagnostics);
3616
+ }, [r]), h(() => {
3617
+ let e = i;
3618
+ return () => {
3619
+ queueMicrotask(() => {
3620
+ if (!(s.current === e && l.current > 0)) try {
3621
+ e?.dispose();
3622
+ } catch {}
3623
+ });
3624
+ };
3625
+ }, [i]), !r.ok || !i ? /* @__PURE__ */ C("div", {
3626
+ className: "md-document local-document local-inactive",
3627
+ role: "alert",
3628
+ children: [/* @__PURE__ */ S("p", {
3629
+ className: "local-inactive-title",
3630
+ children: r.ok ? "交互初始化失败,预览已停用。" : "文档包含语法错误,交互预览已停用。"
3631
+ }), r.diagnostics.length ? /* @__PURE__ */ S("ul", {
3632
+ className: "local-inactive-list",
3633
+ children: r.diagnostics.map((e, t) => /* @__PURE__ */ C("li", { children: [
3634
+ e.message,
3635
+ "(第 ",
3636
+ e.line,
3637
+ " 行,第 ",
3638
+ e.column,
3639
+ " 列)"
3640
+ ] }, `${e.code}-${t}`))
3641
+ }) : null]
3642
+ }) : /* @__PURE__ */ S(dn, {
3643
+ document: r.document,
3644
+ runtime: i,
3645
+ onDiagnostics: t,
3646
+ urlPolicy: n
3647
+ }, e);
3648
+ }
3649
+ export { dn as LocalDocumentView, fn as LocalReactiveDocument };