reactive-md 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/CONTRIBUTING.md +61 -0
  3. package/LICENSE +21 -0
  4. package/README.en.md +75 -0
  5. package/README.md +87 -2
  6. package/SECURITY.md +68 -0
  7. package/THIRD_PARTY_NOTICES.md +1967 -0
  8. package/dist-library/reactive-md-react.js +3514 -0
  9. package/dist-library/reactive-md.css +2 -0
  10. package/dist-library/reactive-md.js +4 -0
  11. package/dist-library/runtime-D4phFXOr.js +10937 -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/index.d.ts +6 -0
  17. package/dist-library/types/local/limits.d.ts +13 -0
  18. package/dist-library/types/local/math-view.d.ts +14 -0
  19. package/dist-library/types/local/math.d.ts +43 -0
  20. package/dist-library/types/local/parser.d.ts +7 -0
  21. package/dist-library/types/local/render-types.d.ts +12 -0
  22. package/dist-library/types/local/runtime.d.ts +2 -0
  23. package/dist-library/types/local/schema.d.ts +55 -0
  24. package/dist-library/types/local/types.d.ts +76 -0
  25. package/dist-library/types/local/version.d.ts +2 -0
  26. package/dist-library/types/local/visuals.d.ts +3 -0
  27. package/dist-library/types/react/index.d.ts +2 -0
  28. package/docs/compatibility.md +67 -0
  29. package/docs/local-guide.md +936 -0
  30. package/docs/local-integration.md +193 -0
  31. package/docs/local-interaction-syntax.md +437 -0
  32. package/docs/performance.md +30 -0
  33. package/docs/releasing.md +92 -0
  34. package/examples/conformance/README.md +11 -0
  35. package/examples/conformance/local-draft-1.json +49 -0
  36. package/examples/integration/README.md +29 -0
  37. package/examples/integration/core/index.mjs +19 -0
  38. package/examples/integration/core/package.json +7 -0
  39. package/examples/integration/react/index.html +12 -0
  40. package/examples/integration/react/main.jsx +21 -0
  41. package/examples/integration/react/package.json +9 -0
  42. package/examples/local/README.md +66 -0
  43. package/examples/local/catalog.reactive.md +20 -0
  44. package/examples/local/charts.reactive.md +73 -0
  45. package/examples/local/checklist.reactive.md +32 -0
  46. package/examples/local/comparison.reactive.md +47 -0
  47. package/examples/local/components.reactive.md +44 -0
  48. package/examples/local/counter.reactive.md +7 -0
  49. package/examples/local/diagnostics.reactive.md +54 -0
  50. package/examples/local/diagram.reactive.md +44 -0
  51. package/examples/local/gallery.reactive.md +61 -0
  52. package/examples/local/parameters.reactive.md +36 -0
  53. package/examples/local/planning.reactive.md +24 -0
  54. package/examples/local/pricing.reactive.md +20 -0
  55. package/package.json +73 -4
@@ -0,0 +1,3514 @@
1
+ import { a as e, c as t, d as n, i as r, l as i, n as a, r as o, t as s, u as c } from "./runtime-D4phFXOr.js";
2
+ import { Component as l, createContext as u, createElement as d, useCallback as f, useContext as p, useEffect as m, useId as h, useMemo as g, useRef as _, useState as v, useSyncExternalStore as y } from "react";
3
+ import { Fragment as b, jsx as x, jsxs as S } from "react/jsx-runtime";
4
+ // src/local/math-view.tsx
5
+ var C = (e, t, ...n) => d(e, t, ...n), w = {
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
+ }, T = 5e4, E = 2e4, D = 120, O = 2e3;
20
+ function k(e) {
21
+ return e.length > O ? `${e.slice(0, O)}…` : e;
22
+ }
23
+ function A(e) {
24
+ if (e.length > T) throw Error("数学源码超过长度上限。");
25
+ let t = [], n = (e) => {
26
+ if (t.length >= E) 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(w, t) ? w[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 j = {
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
+ }, M = {
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
+ }, N = /* @__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
+ ]), P = {
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 = A(e);
249
+ }
250
+ enter() {
251
+ if (this.depth += 1, this.depth > D) 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] : C("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 = C("mn", null, e.value)) : e.kind === "letter" ? (this.take(), t = C("mi", null, e.value)) : e.kind === "punct" ? t = this.parsePunctuation(e) : e.kind === "newline" ? (this.take(), t = C("mspace", { linebreak: "newline" })) : e.kind === "command" ? t = this.parseCommand(e) : (this.take(), t = C("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 === "#" ? C("mo", null, e.value) : C("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() ?? C("mrow", null);
312
+ if (t === "begin") return this.take(), this.parseEnvironment();
313
+ if (t === "end") return this.take(), this.readRawGroup(), C("mtext", null, "\\end");
314
+ if (t === "text" || t === "textrm" || t === "mbox" || t === "operatorname") return this.take(), C("mtext", null, this.readRawGroup());
315
+ if (t === "mathrm" || t === "mathbf" || t === "mathit" || t === "mathsf") {
316
+ this.take();
317
+ let e = this.readRawGroup();
318
+ return C("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(), C("mover", { accent: "true" }, this.parseRequiredArgument(), C("mo", { stretchy: "true" }, t === "overline" || t === "bar" ? "¯" : t === "hat" ? "^" : t === "tilde" ? "~" : t === "vec" ? "→" : t === "dot" ? "˙" : "¨"));
321
+ if (ee.has(t)) return this.take(), C("mrow", null);
322
+ if (Object.hasOwn(P, t)) return this.take(), C("mspace", { width: P[t] });
323
+ if (N.has(t)) return this.take(), C("mo", {
324
+ mathvariant: "normal",
325
+ form: "prefix"
326
+ }, t);
327
+ if (Object.hasOwn(j, t)) return this.take(), C("mi", null, j[t]);
328
+ if (Object.hasOwn(M, t)) {
329
+ this.take();
330
+ let e = M[t];
331
+ return C("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(), C("mtext", null, `\\${t}`);
337
+ }
338
+ parseBraceGroup() {
339
+ if (!this.atPunct("{")) return C("mrow", null);
340
+ this.take();
341
+ let e = this.parseRow({ chars: /* @__PURE__ */ new Set(["}"]) });
342
+ return this.atPunct("}") && this.take(), C("mrow", null, ...e);
343
+ }
344
+ parseFraction() {
345
+ return C("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 = C("mrow", null, ...t);
353
+ }
354
+ let t = this.parseRequiredArgument();
355
+ return e ? C("mroot", null, t, e) : C("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 ? C("mrow", null, ...t) : C("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(), C("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(), C("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 C("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(C("mtd", { columnalign: "left" }, ...t)), !this.atPunct("&")) break;
404
+ this.take();
405
+ }
406
+ if (t.push(C("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 = C("mtable", {
414
+ columnalign: "left",
415
+ columnspacing: "1em"
416
+ }, ...t);
417
+ return C("mrow", null, C("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 ? C("msubsup", null, e, t, n) : n === null ? C("msub", null, e, t) : C("msup", null, e, n) : e;
428
+ }
429
+ parseScriptArgument() {
430
+ return this.atPunct("{") ? this.parseBraceGroup() : this.atPunct("+") || this.atPunct("-") ? C("mrow", null, C("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 = k(e), r;
450
+ if (e.length > T) r = C("mtext", null, n);
451
+ else try {
452
+ r = new te(e).render();
453
+ } catch {
454
+ r = C("mtext", null, n);
455
+ }
456
+ let i = e.length > O ? n : e;
457
+ return C("math", {
458
+ display: t ? "block" : "inline",
459
+ className: t ? "local-math local-math-block" : "local-math",
460
+ "aria-label": i
461
+ }, C("semantics", null, C("mrow", null, r), C("annotation", { encoding: "application/x-tex" }, i)));
462
+ }
463
+ // src/local/visuals.tsx
464
+ var F = [
465
+ "#2563eb",
466
+ "#e11d48",
467
+ "#0d9488",
468
+ "#d97706",
469
+ "#7c3aed",
470
+ "#0891b2",
471
+ "#65a30d",
472
+ "#db2777"
473
+ ], re = 520, ie = 320, ae = 520, oe = 320, se = 520, I = 120, ce = 46, L = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/, le = /^\s*\{\{([\s\S]*)\}\}\s*$/;
474
+ function R(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 ue(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 z(e) {
486
+ return e instanceof Error ? e.message : String(e);
487
+ }
488
+ function B(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 de(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 = le.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 V(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 = le.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 fe(e, t, n, r) {
526
+ let i = de(e, t, n, r);
527
+ return i === null || !Number.isFinite(i) ? r : Math.trunc(i);
528
+ }
529
+ function pe(e, t) {
530
+ return e.length > t ? `${e.slice(0, Math.max(1, t - 1))}…` : e;
531
+ }
532
+ function me(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 he(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 ge(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 _e(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 ve(e, t) {
572
+ return Math.max(46, ...e.map((e) => ue(e).length * 6 + (t ? 24 : 10)));
573
+ }
574
+ function ye(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 be(e) {
581
+ return e.key === "Enter" || e.key === " " || e.key === "Spacebar";
582
+ }
583
+ function H(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: R(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 xe(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 = H(t.evaluate((i.value ?? "").trim()));
615
+ e.error && (r ??= e.error), n += e.text;
616
+ } catch (e) {
617
+ r ??= z(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 = xe(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 Se(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 = H(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: z(t)
652
+ };
653
+ }
654
+ let i = xe(n, t);
655
+ if (r.length > 0 && r.every((e) => e.type === "text") && L.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 Ce(e) {
679
+ return e ? e.error ? "无法计算" : e.text : "";
680
+ }
681
+ function we(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) => Se(e, t));
687
+ return {
688
+ tableNode: n,
689
+ header: i,
690
+ headerText: i.map(Ce),
691
+ rows: r.slice(1).map((e, n) => ({
692
+ index: n,
693
+ cells: (e.children ?? []).map((e) => Se(e, t))
694
+ }))
695
+ };
696
+ }
697
+ function Te(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 = h();
710
+ return /* @__PURE__ */ S("figure", {
711
+ className: `local-visual ${e}`,
712
+ "aria-labelledby": r,
713
+ children: [/* @__PURE__ */ x("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__ */ x("p", {
722
+ className: `local-visual-message local-visual-${t}`,
723
+ role: t,
724
+ children: e
725
+ });
726
+ }
727
+ function Ee({ notes: e }) {
728
+ return e.length === 0 ? null : /* @__PURE__ */ x("ul", {
729
+ className: "local-visual-notes",
730
+ role: "status",
731
+ children: e.map((e, t) => /* @__PURE__ */ x("li", { children: e }, `${e}-${t}`))
732
+ });
733
+ }
734
+ function De({ items: e, hidden: t, onToggle: n, label: r }) {
735
+ return /* @__PURE__ */ x("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__ */ S("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__ */ x("span", {
749
+ className: "local-visual-swatch",
750
+ style: { backgroundColor: e.color },
751
+ "aria-hidden": "true"
752
+ }), /* @__PURE__ */ S("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 Oe({ node: e, runtime: t, render: n }) {
761
+ let [r, i] = v(""), [a, o] = v(null), [s, c] = v(1), l = t.resetToken(e);
762
+ m(() => {
763
+ i(""), o(null), c(1);
764
+ }, [l]);
765
+ let u = B(t, e.attrs, "label", "表格"), d = V(t, e.attrs, "searchable", !0), f = V(t, e.attrs, "sortable", !0), p = fe(t, e.attrs, "page-size", 10), h = Math.max(1, p), g = we(e, t);
766
+ if (!g || g.header.length === 0) return /* @__PURE__ */ x(U, {
767
+ className: "local-visual-table-block",
768
+ label: u,
769
+ children: /* @__PURE__ */ x(W, {
770
+ message: "表格需要一个非空的 Markdown 表格。",
771
+ kind: "alert"
772
+ })
773
+ });
774
+ let _ = g.header.map((e, t) => Te(g, t)), y = r.trim().toLowerCase(), b = [...g.rows.filter((e) => !y || e.cells.some((e) => Ce(e).toLowerCase().includes(y)))];
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 = he(Ce(r), Ce(i));
783
+ return o === 0 ? t.index - n.index : a.direction === "asc" ? o : -o;
784
+ });
785
+ }
786
+ let C = Math.max(1, Math.ceil(b.length / h)), w = Math.min(s, C), T = b.slice((w - 1) * h, w * h), 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__ */ S(U, {
796
+ className: "local-visual-table-block",
797
+ label: u,
798
+ children: [
799
+ d ? /* @__PURE__ */ S("label", {
800
+ className: "local-visual-search",
801
+ children: [/* @__PURE__ */ x("span", { children: "搜索" }), /* @__PURE__ */ x("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__ */ x("div", {
812
+ className: "local-visual-table-scroll",
813
+ children: /* @__PURE__ */ S("table", {
814
+ className: "local-visual-table",
815
+ children: [
816
+ /* @__PURE__ */ x("caption", {
817
+ className: "local-visual-sr-only",
818
+ children: u
819
+ }),
820
+ /* @__PURE__ */ x("thead", { children: /* @__PURE__ */ x("tr", { children: g.header.map((e, t) => {
821
+ let n = a && a.column === t ? a.direction === "asc" ? "ascending" : "descending" : "none";
822
+ return /* @__PURE__ */ x("th", {
823
+ scope: "col",
824
+ "aria-sort": n,
825
+ children: f ? /* @__PURE__ */ S("button", {
826
+ type: "button",
827
+ className: `local-visual-sort-button${a && a.column === t ? " is-sorted" : ""}`,
828
+ onClick: () => E(t),
829
+ title: "点击切换升序、降序和原始顺序",
830
+ children: [Ce(e), D(t)]
831
+ }) : Ce(e)
832
+ }, `head-${t}`);
833
+ }) }) }),
834
+ /* @__PURE__ */ x("tbody", { children: T.map((e) => /* @__PURE__ */ x("tr", { children: g.header.map((t, r) => {
835
+ let i = e.cells[r];
836
+ return /* @__PURE__ */ x("td", { children: i?.error ? /* @__PURE__ */ x("span", {
837
+ className: "local-visual-cell-error",
838
+ title: i.error,
839
+ children: "无法计算"
840
+ }) : n(i?.children ?? []) }, `cell-${e.index}-${r}`);
841
+ }) }, `row-${e.index}`)) })
842
+ ]
843
+ })
844
+ }),
845
+ b.length === 0 ? /* @__PURE__ */ x(W, { message: "没有匹配结果" }) : null,
846
+ C > 1 ? /* @__PURE__ */ S("nav", {
847
+ className: "local-visual-pagination",
848
+ "aria-label": "表格分页",
849
+ children: [
850
+ /* @__PURE__ */ x("button", {
851
+ type: "button",
852
+ disabled: w <= 1,
853
+ onClick: () => c((e) => Math.max(1, e - 1)),
854
+ children: "上一页"
855
+ }),
856
+ /* @__PURE__ */ S("span", { children: [
857
+ "第 ",
858
+ w,
859
+ " / ",
860
+ C,
861
+ " 页 · 共 ",
862
+ b.length,
863
+ " 行"
864
+ ] }),
865
+ /* @__PURE__ */ x("button", {
866
+ type: "button",
867
+ disabled: w >= C,
868
+ onClick: () => c((e) => Math.min(C, e + 1)),
869
+ children: "下一页"
870
+ })
871
+ ]
872
+ }) : null
873
+ ]
874
+ });
875
+ }
876
+ var ke = [
877
+ "bar",
878
+ "line",
879
+ "area",
880
+ "scatter",
881
+ "donut"
882
+ ];
883
+ function Ae(e, t, n, r, i, a) {
884
+ 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);
885
+ return [
886
+ `M ${s} ${c}`,
887
+ `A ${n} ${n} 0 ${h} 1 ${l} ${u}`,
888
+ `L ${d} ${f}`,
889
+ `A ${r} ${r} 0 ${h} 0 ${p} ${m}`,
890
+ "Z"
891
+ ].join(" ");
892
+ }
893
+ function je({ node: e, runtime: t }) {
894
+ let [n, r] = v(/* @__PURE__ */ new Set()), [i, a] = v(/* @__PURE__ */ new Set()), [o, s] = v(null), c = t.resetToken(e);
895
+ m(() => {
896
+ r(/* @__PURE__ */ new Set()), a(/* @__PURE__ */ new Set()), s(null);
897
+ }, [c]);
898
+ let l = h(), u = B(t, e.attrs, "title", "") || B(t, e.attrs, "label", "") || "图表", d = (e.attrs?.kind ?? "bar").trim().toLowerCase(), f = ke.includes(d) ? d : null, p = B(t, e.attrs, "x-label", ""), g = B(t, e.attrs, "y-label", ""), _ = we(e, t);
899
+ if (!_ || _.header.length === 0) return /* @__PURE__ */ x(U, {
900
+ className: "local-visual-chart",
901
+ label: u,
902
+ children: /* @__PURE__ */ x(W, {
903
+ message: "chart 正文需要一个非空的 Markdown 表格。",
904
+ kind: "alert"
905
+ })
906
+ });
907
+ let y = _.headerText.map((e) => e.trim()), b = _.rows.map((e) => ({
908
+ index: e.index,
909
+ cells: e.cells,
910
+ texts: y.map((t, n) => Ce(e.cells[n]))
911
+ }));
912
+ if (!f) return /* @__PURE__ */ x(U, {
913
+ className: "local-visual-chart",
914
+ label: u,
915
+ children: /* @__PURE__ */ x(W, {
916
+ message: `未知图表类型“${d}”。`,
917
+ kind: "alert"
918
+ })
919
+ });
920
+ let C = [], w = [], T = (e.attrs?.x ?? "").trim(), E = T ? y.indexOf(T) : 0;
921
+ (E < 0 || E >= y.length) && w.push(`x 列“${T}”不存在。`);
922
+ let D = (e.attrs?.y ?? "").split(",").map((e) => e.trim()).filter(Boolean), O = [];
923
+ if (f === "donut") {
924
+ if (D.length > 1) w.push("donut 只能使用一个数值列,请在 y 中指定唯一列。");
925
+ else if (D.length === 1) {
926
+ let e = y.indexOf(D[0]);
927
+ e < 0 ? w.push(`y 列“${D[0]}”不存在。`) : O = [e];
928
+ } else y.length === 2 ? O = [1] : w.push("donut 多于两列时必须用 y 指定唯一数值列。");
929
+ } else if (D.length > 0) for (let e of D) {
930
+ let t = y.indexOf(e);
931
+ t < 0 ? w.push(`y 列“${e}”不存在。`) : O.includes(t) || O.push(t);
932
+ }
933
+ else O = y.map((e, t) => t).filter((e) => e !== E);
934
+ if (w.length === 0 && O.length === 0 && w.push("图表至少需要一个数值系列。"), w.length > 0) return /* @__PURE__ */ x(U, {
935
+ className: `local-visual-chart local-visual-chart-${f}`,
936
+ label: u,
937
+ children: w.map((e, t) => /* @__PURE__ */ x(W, {
938
+ message: e,
939
+ kind: "alert"
940
+ }, `${e}-${t}`))
941
+ });
942
+ let k = O.map((e) => y[e] || `系列 ${e + 1}`), A = 0, j = 0, M = b.map((e) => {
943
+ let t = e.cells[E], n = e.texts[E] || `第 ${e.index + 1} 项`, r = t && t.numeric !== null ? t.numeric : null, i = O.map((t) => {
944
+ let n = e.cells[t];
945
+ return !n || n.kind === "empty" || n.numeric === null ? (A += 1, null) : (f === "donut" && n.numeric < 0 && (j += 1), n.numeric);
946
+ });
947
+ return {
948
+ index: e.index,
949
+ label: n,
950
+ xValue: r,
951
+ values: i,
952
+ cells: e.cells
953
+ };
954
+ });
955
+ A > 0 && C.push(`${A} 个数值为空或无法计算,图表中保留空缺。`);
956
+ for (let e of O) Te(_, e) || C.push(`列“${y[e]}”不是纯数值列,非数值按空缺处理。`);
957
+ f === "donut" && j > 0 && C.push(`环形图数值必须非负,已忽略 ${j} 个负值。`), f === "scatter" && !Te(_, E) && C.push(`scatter 的横轴列“${y[E]}”需要数值。`);
958
+ let N = (e) => {
959
+ s(null), r((t) => {
960
+ let n = new Set(t);
961
+ return n.has(e) ? n.delete(e) : n.add(e), n;
962
+ });
963
+ }, P = (e) => {
964
+ s(null), a((t) => {
965
+ let n = new Set(t);
966
+ return n.has(e) ? n.delete(e) : n.add(e), n;
967
+ });
968
+ }, ee = k.map((e, t) => ({
969
+ name: e,
970
+ color: F[t % F.length]
971
+ }));
972
+ if (f === "donut") {
973
+ 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) => ({
974
+ name: n.label,
975
+ color: F[r % F.length],
976
+ detail: e[r] === null ? "—" : R(e[r]),
977
+ disabled: t[r] <= 0
978
+ }));
979
+ if (n <= 0) return /* @__PURE__ */ S(U, {
980
+ className: "local-visual-chart local-visual-chart-donut",
981
+ label: u,
982
+ children: [
983
+ /* @__PURE__ */ x(W, { message: "暂无占比" }),
984
+ /* @__PURE__ */ x(Ee, { notes: C }),
985
+ /* @__PURE__ */ x(De, {
986
+ items: r,
987
+ hidden: i,
988
+ onToggle: P,
989
+ label: "图例"
990
+ })
991
+ ]
992
+ });
993
+ let a = re / 2, c = -Math.PI / 2, d = [];
994
+ M.forEach((e, r) => {
995
+ if (i.has(r)) return;
996
+ let o = t[r];
997
+ if (o <= 0) return;
998
+ let s = o / n * Math.PI * 2, l = c, u = c + s;
999
+ c = u, d.push({
1000
+ key: `donut:${r}`,
1001
+ label: e.label,
1002
+ value: o,
1003
+ start: l,
1004
+ end: u,
1005
+ color: F[r % F.length],
1006
+ x: a,
1007
+ y: 140
1008
+ });
1009
+ });
1010
+ let f = o ? `${o.label}:${R(o.value)}` : "聚焦扇区或图例查看数值";
1011
+ return /* @__PURE__ */ S(U, {
1012
+ className: "local-visual-chart local-visual-chart-donut",
1013
+ label: u,
1014
+ children: [
1015
+ /* @__PURE__ */ x("div", {
1016
+ className: "local-visual-readout",
1017
+ id: l,
1018
+ "aria-live": "polite",
1019
+ children: f
1020
+ }),
1021
+ /* @__PURE__ */ x("div", {
1022
+ className: "local-visual-svg-wrap",
1023
+ children: /* @__PURE__ */ S("svg", {
1024
+ className: "local-visual-svg",
1025
+ viewBox: `0 0 ${re} 290`,
1026
+ role: "group",
1027
+ "aria-label": `${u},环形图,共 ${M.length} 项`,
1028
+ "aria-describedby": l,
1029
+ children: [/* @__PURE__ */ S("g", {
1030
+ className: "local-visual-donut-center",
1031
+ "aria-hidden": "true",
1032
+ children: [/* @__PURE__ */ x("text", {
1033
+ x: a,
1034
+ y: 138,
1035
+ textAnchor: "middle",
1036
+ className: "local-visual-donut-total",
1037
+ children: R(n)
1038
+ }), /* @__PURE__ */ x("text", {
1039
+ x: a,
1040
+ y: 158,
1041
+ textAnchor: "middle",
1042
+ className: "local-visual-donut-caption",
1043
+ children: pe(k[0], 14)
1044
+ })]
1045
+ }), d.map((e) => {
1046
+ let t = {
1047
+ key: e.key,
1048
+ series: k[0],
1049
+ label: e.label,
1050
+ value: e.value,
1051
+ x: e.x,
1052
+ y: e.y
1053
+ }, n = {
1054
+ "data-chart-mark": "",
1055
+ tabIndex: 0,
1056
+ role: "img",
1057
+ "aria-label": `${e.label}:${R(e.value)}`,
1058
+ onFocus: () => s(t),
1059
+ onBlur: () => s(null),
1060
+ onPointerEnter: () => s(t),
1061
+ onPointerLeave: () => s(null),
1062
+ onKeyDown: (e) => {
1063
+ e.key === "ArrowRight" || e.key === "ArrowDown" ? ye(e, "[data-chart-mark]", 1) : (e.key === "ArrowLeft" || e.key === "ArrowUp") && ye(e, "[data-chart-mark]", -1);
1064
+ }
1065
+ };
1066
+ return e.end - e.start >= Math.PI * 2 - 1e-6 ? /* @__PURE__ */ x("circle", {
1067
+ className: "local-visual-donut-slice",
1068
+ cx: a,
1069
+ cy: 140,
1070
+ r: 78,
1071
+ fill: "none",
1072
+ stroke: e.color,
1073
+ strokeWidth: 40,
1074
+ ...n,
1075
+ children: /* @__PURE__ */ x("title", { children: `${e.label}:${R(e.value)}` })
1076
+ }, e.key) : /* @__PURE__ */ x("path", {
1077
+ className: "local-visual-donut-slice",
1078
+ d: Ae(a, 140, 98, 58, e.start, e.end),
1079
+ fill: e.color,
1080
+ ...n,
1081
+ children: /* @__PURE__ */ x("title", { children: `${e.label}:${R(e.value)}` })
1082
+ }, e.key);
1083
+ })]
1084
+ })
1085
+ }),
1086
+ /* @__PURE__ */ x(De, {
1087
+ items: r,
1088
+ hidden: i,
1089
+ onToggle: P,
1090
+ label: "图例,可开关扇区"
1091
+ }),
1092
+ /* @__PURE__ */ x(Ee, { notes: C })
1093
+ ]
1094
+ });
1095
+ }
1096
+ let te = k.map((e, t) => t).filter((e) => !n.has(e));
1097
+ if (te.length === 0) return /* @__PURE__ */ S(U, {
1098
+ className: `local-visual-chart local-visual-chart-${f}`,
1099
+ label: u,
1100
+ children: [/* @__PURE__ */ x(W, { message: "所有系列已在图例中关闭" }), /* @__PURE__ */ x(De, {
1101
+ items: ee,
1102
+ hidden: n,
1103
+ onToggle: N,
1104
+ label: "图例,可开关系列"
1105
+ })]
1106
+ });
1107
+ let ne = Te(_, E), ae = f === "scatter" ? !0 : f === "line" || f === "area" ? ne : !1, oe = ae ? M.filter((e) => e.xValue !== null) : M;
1108
+ ae && oe.length < M.length && C.push(`${M.length - oe.length} 行横轴为空或不是数值,未参与绘制。`);
1109
+ let se = [];
1110
+ for (let e of oe) for (let t of te) {
1111
+ let n = e.values[t];
1112
+ n !== null && se.push(n);
1113
+ }
1114
+ if (oe.length === 0) return /* @__PURE__ */ S(U, {
1115
+ className: `local-visual-chart local-visual-chart-${f}`,
1116
+ label: u,
1117
+ children: [
1118
+ /* @__PURE__ */ x(W, { message: "没有可绘制的数据行" }),
1119
+ /* @__PURE__ */ x(Ee, { notes: C }),
1120
+ /* @__PURE__ */ x(De, {
1121
+ items: ee,
1122
+ hidden: n,
1123
+ onToggle: N,
1124
+ label: "图例,可开关系列"
1125
+ })
1126
+ ]
1127
+ });
1128
+ if (se.length === 0) return /* @__PURE__ */ S(U, {
1129
+ className: `local-visual-chart local-visual-chart-${f}`,
1130
+ label: u,
1131
+ children: [
1132
+ /* @__PURE__ */ x(W, { message: "没有可读取的数值" }),
1133
+ /* @__PURE__ */ x(Ee, { notes: C }),
1134
+ /* @__PURE__ */ x(De, {
1135
+ items: ee,
1136
+ hidden: n,
1137
+ onToggle: N,
1138
+ label: "图例,可开关系列"
1139
+ })
1140
+ ]
1141
+ });
1142
+ let I = _e(se, f === "bar" || f === "area"), ce = ge(I.min, I.max, 5), L = ve(ce, !!g), le = 506 - L, z = (e) => 16 + (I.max - e) / (I.max - I.min) * 258, de = z(Math.max(I.min, Math.min(I.max, 0))), V = ae && oe.length > 0 ? _e(oe.map((e) => e.xValue).filter((e) => e !== null), !1) : null, fe = le / Math.max(1, M.length), me = (e) => L + fe * (e + .5), he = (e) => L + (e - V.min) / (V.max - V.min) * le, be = (e, t) => V ? e.xValue === null ? null : he(e.xValue) : me(t), H = [];
1143
+ if (V) H.push(...ge(V.min, V.max, 5));
1144
+ else {
1145
+ let e = Math.max(1, Math.ceil(M.length / 6));
1146
+ for (let t = 0; t < M.length; t += e) H.push(t);
1147
+ let t = M.length - 1;
1148
+ t >= 0 && H[H.length - 1] !== t && (H.length > 1 && t - H[H.length - 1] < e * .6 ? H[H.length - 1] = t : H.push(t));
1149
+ }
1150
+ let xe = (e) => V ? L + (e - V.min) / (V.max - V.min) * le : me(e), Se = o && !V ? null : o ? /* @__PURE__ */ x("line", {
1151
+ className: "local-visual-guide",
1152
+ x1: Math.max(L, Math.min(506, o.x)),
1153
+ x2: Math.max(L, Math.min(506, o.x)),
1154
+ y1: 16,
1155
+ y2: 274
1156
+ }) : null, Oe = (e) => ({
1157
+ "data-chart-mark": "",
1158
+ tabIndex: 0,
1159
+ role: "img",
1160
+ "aria-label": `${e.series},${e.label}:${R(e.value)}`,
1161
+ onFocus: () => s(e),
1162
+ onBlur: () => s(null),
1163
+ onPointerEnter: () => s(e),
1164
+ onPointerLeave: () => s(null),
1165
+ onKeyDown: (e) => {
1166
+ e.key === "ArrowRight" || e.key === "ArrowDown" ? ye(e, "[data-chart-mark]", 1) : (e.key === "ArrowLeft" || e.key === "ArrowUp") && ye(e, "[data-chart-mark]", -1);
1167
+ }
1168
+ }), je = (e, t, n, r, i) => ({
1169
+ key: `${e}:${t.index}`,
1170
+ series: k[e],
1171
+ label: t.label,
1172
+ value: n,
1173
+ x: r,
1174
+ y: i
1175
+ }), Me = [];
1176
+ if (f === "bar") {
1177
+ let e = fe * .76, t = Math.max(1, e / Math.max(1, te.length));
1178
+ M.forEach((n, r) => {
1179
+ te.forEach((i, a) => {
1180
+ let o = n.values[i];
1181
+ if (o === null) return;
1182
+ let s = L + fe * r + (fe - e) / 2 + a * t, c = Math.max(1, Math.abs(z(o) - de)), l = o >= 0 ? de - c : de, u = je(i, n, o, s + t / 2, l + c / 2);
1183
+ Me.push(/* @__PURE__ */ x("rect", {
1184
+ className: "local-visual-bar",
1185
+ x: s,
1186
+ y: l,
1187
+ width: Math.max(1.5, t - 1),
1188
+ height: c,
1189
+ rx: 2,
1190
+ fill: F[i % F.length],
1191
+ ...Oe(u),
1192
+ children: /* @__PURE__ */ x("title", { children: `${u.series},${u.label}:${R(u.value)}` })
1193
+ }, `bar-${i}-${n.index}`));
1194
+ });
1195
+ });
1196
+ }
1197
+ let Ne = [], Pe = [], Fe = [];
1198
+ if (f === "line" || f === "area") for (let e of te) {
1199
+ let t = [], n = [], r = () => {
1200
+ n.length > 0 && t.push(n), n = [];
1201
+ };
1202
+ M.forEach((t, i) => {
1203
+ let a = t.values[e], o = be(t, i);
1204
+ a === null || o === null ? r() : n.push({
1205
+ row: t,
1206
+ value: a,
1207
+ x: o,
1208
+ y: z(a)
1209
+ });
1210
+ }), r();
1211
+ for (let n of t) {
1212
+ if (n.length >= 2) {
1213
+ let t = n.map((e, t) => `${t === 0 ? "M" : "L"} ${e.x} ${e.y}`).join(" ");
1214
+ if (Ne.push(/* @__PURE__ */ x("path", {
1215
+ className: "local-visual-line",
1216
+ d: t,
1217
+ fill: "none",
1218
+ stroke: F[e % F.length],
1219
+ strokeWidth: 2.4,
1220
+ strokeLinejoin: "round",
1221
+ strokeLinecap: "round"
1222
+ }, `line-${e}-${n[0].row.index}`)), f === "area") {
1223
+ 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`;
1224
+ Pe.push(/* @__PURE__ */ x("path", {
1225
+ className: "local-visual-area",
1226
+ d: a,
1227
+ fill: F[e % F.length]
1228
+ }, `area-${e}-${r.row.index}`));
1229
+ }
1230
+ }
1231
+ for (let t of n) {
1232
+ let n = je(e, t.row, t.value, t.x, t.y);
1233
+ Fe.push(/* @__PURE__ */ S("g", {
1234
+ className: "local-visual-point-group",
1235
+ children: [/* @__PURE__ */ x("circle", {
1236
+ className: "local-visual-hit",
1237
+ cx: t.x,
1238
+ cy: t.y,
1239
+ r: 12,
1240
+ fill: "transparent",
1241
+ ...Oe(n),
1242
+ children: /* @__PURE__ */ x("title", { children: `${n.series},${n.label}:${R(n.value)}` })
1243
+ }), /* @__PURE__ */ x("circle", {
1244
+ className: "local-visual-point",
1245
+ cx: t.x,
1246
+ cy: t.y,
1247
+ r: 4.5,
1248
+ fill: F[e % F.length],
1249
+ stroke: "var(--local-surface, #ffffff)",
1250
+ strokeWidth: 1.5,
1251
+ pointerEvents: "none"
1252
+ })]
1253
+ }, `point-${e}-${t.row.index}`));
1254
+ }
1255
+ }
1256
+ }
1257
+ f === "scatter" && M.forEach((e, t) => {
1258
+ let n = be(e, t);
1259
+ n !== null && te.forEach((t) => {
1260
+ let r = e.values[t];
1261
+ if (r === null) return;
1262
+ let i = z(r), a = je(t, e, r, n, i);
1263
+ Fe.push(/* @__PURE__ */ S("g", {
1264
+ className: "local-visual-point-group",
1265
+ children: [/* @__PURE__ */ x("circle", {
1266
+ className: "local-visual-hit",
1267
+ cx: n,
1268
+ cy: i,
1269
+ r: 15,
1270
+ fill: "transparent",
1271
+ ...Oe(a),
1272
+ children: /* @__PURE__ */ x("title", { children: `${a.series},${a.label}:${R(a.value)}` })
1273
+ }), /* @__PURE__ */ x("circle", {
1274
+ className: "local-visual-point",
1275
+ cx: n,
1276
+ cy: i,
1277
+ r: 6,
1278
+ fill: F[t % F.length],
1279
+ stroke: "var(--local-surface, #ffffff)",
1280
+ strokeWidth: 1.5,
1281
+ pointerEvents: "none"
1282
+ })]
1283
+ }, `scatter-${t}-${e.index}`));
1284
+ });
1285
+ });
1286
+ let Ie = o ? `${o.series} · ${o.label}:${R(o.value)}` : "聚焦或指向图形,用方向键切换读数", Le = `${u},${f} 图,共 ${M.length} 项,${te.length} 个系列`;
1287
+ return /* @__PURE__ */ S(U, {
1288
+ className: `local-visual-chart local-visual-chart-${f}`,
1289
+ label: u,
1290
+ children: [
1291
+ /* @__PURE__ */ x("div", {
1292
+ className: "local-visual-readout",
1293
+ id: l,
1294
+ "aria-live": "polite",
1295
+ children: Ie
1296
+ }),
1297
+ /* @__PURE__ */ x("div", {
1298
+ className: "local-visual-svg-wrap",
1299
+ children: /* @__PURE__ */ S("svg", {
1300
+ className: "local-visual-svg",
1301
+ viewBox: `0 0 ${re} ${ie}`,
1302
+ role: "group",
1303
+ "aria-label": Le,
1304
+ "aria-describedby": l,
1305
+ children: [
1306
+ ce.map((e) => /* @__PURE__ */ S("g", { children: [/* @__PURE__ */ x("line", {
1307
+ className: "local-visual-grid-line",
1308
+ x1: L,
1309
+ x2: 506,
1310
+ y1: z(e),
1311
+ y2: z(e)
1312
+ }), /* @__PURE__ */ x("text", {
1313
+ className: "local-visual-axis-label",
1314
+ x: L - 6,
1315
+ y: z(e),
1316
+ textAnchor: "end",
1317
+ dominantBaseline: "middle",
1318
+ children: ue(e)
1319
+ })] }, `y-${e}`)),
1320
+ I.min < 0 && I.max > 0 ? /* @__PURE__ */ x("line", {
1321
+ className: "local-visual-zero-line",
1322
+ x1: L,
1323
+ x2: 506,
1324
+ y1: de,
1325
+ y2: de
1326
+ }) : null,
1327
+ /* @__PURE__ */ x("line", {
1328
+ className: "local-visual-axis-line",
1329
+ x1: L,
1330
+ x2: 506,
1331
+ y1: 274,
1332
+ y2: 274
1333
+ }),
1334
+ H.map((e) => {
1335
+ let t = xe(e), n = V ? ue(e) : pe(M[e]?.label ?? "", 8);
1336
+ return /* @__PURE__ */ S("g", { children: [/* @__PURE__ */ x("line", {
1337
+ className: "local-visual-tick",
1338
+ x1: t,
1339
+ x2: t,
1340
+ y1: 274,
1341
+ y2: 279
1342
+ }), /* @__PURE__ */ S("text", {
1343
+ className: "local-visual-axis-label",
1344
+ x: t,
1345
+ y: 293,
1346
+ textAnchor: "middle",
1347
+ children: [n, !V && M[e] ? /* @__PURE__ */ x("title", { children: M[e].label }) : null]
1348
+ })] }, `x-${e}`);
1349
+ }),
1350
+ p ? /* @__PURE__ */ x("text", {
1351
+ className: "local-visual-axis-title",
1352
+ x: (L + 506) / 2,
1353
+ y: 318,
1354
+ textAnchor: "middle",
1355
+ children: p
1356
+ }) : null,
1357
+ g ? /* @__PURE__ */ x("text", {
1358
+ className: "local-visual-axis-title",
1359
+ transform: "translate(12 145) rotate(-90)",
1360
+ textAnchor: "middle",
1361
+ children: g
1362
+ }) : null,
1363
+ Pe,
1364
+ Ne,
1365
+ Se,
1366
+ Me,
1367
+ Fe
1368
+ ]
1369
+ })
1370
+ }),
1371
+ /* @__PURE__ */ x(De, {
1372
+ items: ee,
1373
+ hidden: n,
1374
+ onToggle: N,
1375
+ label: "图例,可开关系列"
1376
+ }),
1377
+ /* @__PURE__ */ x(Ee, { notes: C })
1378
+ ]
1379
+ });
1380
+ }
1381
+ var Me = /* @__PURE__ */ new WeakMap();
1382
+ function Ne(e, t) {
1383
+ let n = Me.get(e);
1384
+ return n && n.revision === t || (n = {
1385
+ revision: t,
1386
+ requestedPoints: /* @__PURE__ */ new Map(),
1387
+ evaluation: {
1388
+ steps: 0,
1389
+ limit: i
1390
+ },
1391
+ samples: /* @__PURE__ */ new Map()
1392
+ }, Me.set(e, n)), n;
1393
+ }
1394
+ function Pe(n, i, a, s, c, l, u, d, f) {
1395
+ let p = Ne(d, f), m = p.samples.get(i);
1396
+ if (m) return m;
1397
+ let h = (e) => {
1398
+ let t = {
1399
+ ok: !1,
1400
+ message: e
1401
+ };
1402
+ return p.samples.set(i, t), t;
1403
+ };
1404
+ if (a.length > 16) return h(`plot 最多支持 16 条曲线,当前为 ${a.length} 条。`);
1405
+ let g = a.length * u;
1406
+ p.requestedPoints.set(n, g);
1407
+ let _ = 0;
1408
+ for (let e of p.requestedPoints.values()) _ += e;
1409
+ if (_ > 2e4) return h(`整篇文档的绘图采样点超过上限:已请求 ${_} 个,最多 ${t} 个。请减少曲线或采样数。`);
1410
+ let v = [], y = { message: null }, b = a.map((t, n) => {
1411
+ let i = (t.value ?? "").trim(), a = /^y\s*=\s*([\s\S]+)$/.exec(i);
1412
+ if (!a) return v.push(`曲线 ${n + 1}:无法计算(每块公式需写成 y = 表达式)。`), {
1413
+ source: i,
1414
+ expression: null,
1415
+ points: [],
1416
+ endpoint: null,
1417
+ error: "formula"
1418
+ };
1419
+ try {
1420
+ let t = r(a[1].trim()), n = e(t, s, c, l, u, p.evaluation);
1421
+ return {
1422
+ source: i,
1423
+ expression: t,
1424
+ points: n.points,
1425
+ endpoint: n.endpoint,
1426
+ error: null
1427
+ };
1428
+ } catch (e) {
1429
+ return e instanceof o && e.code === "latex-budget" ? (y.message = e.message, {
1430
+ source: i,
1431
+ expression: null,
1432
+ points: [],
1433
+ endpoint: null,
1434
+ error: e.message
1435
+ }) : (v.push(`曲线 ${n + 1}:无法计算(${z(e)})。`), {
1436
+ source: i,
1437
+ expression: null,
1438
+ points: [],
1439
+ endpoint: null,
1440
+ error: z(e)
1441
+ });
1442
+ }
1443
+ });
1444
+ if (y.message !== null) return h(`绘图计算超过共享执行预算:${y.message}`);
1445
+ let x = {
1446
+ ok: !0,
1447
+ curves: b,
1448
+ notes: v
1449
+ };
1450
+ return p.samples.set(i, x), x;
1451
+ }
1452
+ function Fe(e) {
1453
+ if (e.length === 0) return 0;
1454
+ let t = [...e].sort((e, t) => e - t), n = Math.floor(t.length / 2);
1455
+ return t.length % 2 == 0 ? (t[n - 1] + t[n]) / 2 : t[n];
1456
+ }
1457
+ function Ie(e, t, n, r) {
1458
+ let i = [], a = [], o = (e, i) => {
1459
+ 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;
1460
+ return o || s;
1461
+ };
1462
+ for (let t of e) {
1463
+ if (t.y === null) {
1464
+ a.length > 0 && i.push(a), a = [];
1465
+ continue;
1466
+ }
1467
+ let e = {
1468
+ x: t.x,
1469
+ y: t.y
1470
+ }, n = a[a.length - 1];
1471
+ n && o(n, e) && (i.push(a), a = []), a.push(e);
1472
+ }
1473
+ return a.length > 0 && i.push(a), i;
1474
+ }
1475
+ function Le({ node: e, runtime: t }) {
1476
+ let [n, r] = v(null), a = t.resetToken(e);
1477
+ m(() => {
1478
+ r(null);
1479
+ }, [a]);
1480
+ let o = h(), s = B(t, e.attrs, "label", "") || "函数图", c = B(t, e.attrs, "x-label", "x"), l = B(t, e.attrs, "y-label", "y"), u = de(t, e.attrs, "min", -10), d = de(t, e.attrs, "max", 10), f = Math.min(2e3, Math.max(2, fe(t, e.attrs, "samples", 200))), p = (e.children ?? []).filter((e) => e.type === "math" || e.type === "inlineMath"), _ = (() => {
1481
+ try {
1482
+ return { ...t.snapshot().state };
1483
+ } catch {
1484
+ return {};
1485
+ }
1486
+ })(), y = 0;
1487
+ try {
1488
+ y = t.snapshot().revision;
1489
+ } catch {
1490
+ y = 0;
1491
+ }
1492
+ let b = p.map((e) => `${e.id}\u0000${e.value ?? ""}`).join(""), C = `${e.id}\u0000${u}\u0000${d}\u0000${f}\u0000${b}`, w = g(() => p.length === 0 || u === null || d === null || !(d > u) ? {
1493
+ ok: !0,
1494
+ curves: [],
1495
+ notes: []
1496
+ } : Pe(e.id, C, p, _, u, d, f, t, y), [
1497
+ C,
1498
+ e.id,
1499
+ y,
1500
+ t
1501
+ ]);
1502
+ if (p.length === 0) return /* @__PURE__ */ x(U, {
1503
+ className: "local-visual-plot",
1504
+ label: s,
1505
+ children: /* @__PURE__ */ x(W, {
1506
+ message: "plot 正文需要一个或多个 $$ 公式块。",
1507
+ kind: "alert"
1508
+ })
1509
+ });
1510
+ if (u === null || d === null || !(d > u)) return /* @__PURE__ */ x(U, {
1511
+ className: "local-visual-plot",
1512
+ label: s,
1513
+ children: /* @__PURE__ */ x(W, {
1514
+ message: "plot 的 min 必须小于 max。",
1515
+ kind: "alert"
1516
+ })
1517
+ });
1518
+ if (!w.ok) return /* @__PURE__ */ x(U, {
1519
+ className: "local-visual-plot",
1520
+ label: s,
1521
+ children: /* @__PURE__ */ x(W, {
1522
+ message: w.message,
1523
+ kind: "alert"
1524
+ })
1525
+ });
1526
+ let { curves: T, notes: E } = w, D = T.flatMap((e) => e.points.filter((e) => e.y !== null && Number.isFinite(e.y))), O = /* @__PURE__ */ x("div", {
1527
+ className: "local-visual-plot-legend",
1528
+ role: "list",
1529
+ "aria-label": "曲线图例",
1530
+ children: T.map((e, t) => /* @__PURE__ */ S("div", {
1531
+ className: "local-visual-plot-legend-item",
1532
+ role: "listitem",
1533
+ children: [/* @__PURE__ */ x("span", {
1534
+ className: "local-visual-swatch",
1535
+ style: { backgroundColor: F[t % F.length] },
1536
+ "aria-hidden": "true"
1537
+ }), /* @__PURE__ */ S("span", {
1538
+ className: "local-visual-plot-legend-text",
1539
+ children: [/* @__PURE__ */ x("span", {
1540
+ className: "local-visual-plot-formula",
1541
+ children: /* @__PURE__ */ x(ne, { source: e.source })
1542
+ }), /* @__PURE__ */ S("span", {
1543
+ className: "local-visual-endpoint",
1544
+ children: [
1545
+ "终点 x = ",
1546
+ R(d),
1547
+ ":",
1548
+ e.error ? "无法计算" : e.endpoint === null ? "无定义" : R(e.endpoint)
1549
+ ]
1550
+ })]
1551
+ })]
1552
+ }, `curve-legend-${t}`))
1553
+ });
1554
+ if (D.length === 0) return /* @__PURE__ */ S(U, {
1555
+ className: "local-visual-plot",
1556
+ label: s,
1557
+ children: [
1558
+ /* @__PURE__ */ x(W, { message: "当前范围内没有可绘制的值" }),
1559
+ /* @__PURE__ */ x(Ee, { notes: E }),
1560
+ O
1561
+ ]
1562
+ });
1563
+ let k = _e(D.map((e) => e.y), !1), A = ge(k.min, k.max, 5), j = ge(u, d, 5), M = ve(A, !!l), N = 506 - M, P = (e) => M + (e - u) / (d - u) * N, ee = (e) => 16 + (k.max - e) / (k.max - k.min) * 258, te = Fe(D.map((e) => Math.abs(e.y))), re = [];
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 && re.push(Math.abs(r.y - n.y));
1567
+ }
1568
+ let ie = Fe(re), se = k.max - k.min, I = T.map((e) => Ie(e.points, se, te, ie)), 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, _, 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)), z = (d - u) / 100, V = (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
+ }, pe = (e) => {
1585
+ let t = e.shiftKey ? 10 : 1, i = n;
1586
+ if (e.key === "ArrowRight") i = (n ?? (u + d) / 2) + z * t;
1587
+ else if (e.key === "ArrowLeft") i = (n ?? (u + d) / 2) - z * 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
+ }, me = n === null ? null : le(n), he = me === null ? `区间 [${R(u)}, ${R(d)}] · ${f} 个采样点;用方向键或指针读取数值` : `x = ${R(me)};${T.map((e, t) => {
1593
+ let n = L(e, me);
1594
+ return `曲线 ${t + 1}:${e.error ? "无法计算" : n === null ? "无定义" : R(n)}`;
1595
+ }).join(";")}`, ye = me === null ? null : T.map((e, t) => {
1596
+ let n = L(e, me);
1597
+ return n === null || !e.expression ? null : /* @__PURE__ */ x("circle", {
1598
+ className: "local-visual-active-point",
1599
+ cx: P(me),
1600
+ cy: ee(n),
1601
+ r: 4.5,
1602
+ fill: F[t % F.length],
1603
+ stroke: "var(--local-surface, #ffffff)",
1604
+ strokeWidth: 1.5
1605
+ }, `active-${t}`);
1606
+ });
1607
+ return /* @__PURE__ */ S(U, {
1608
+ className: "local-visual-plot",
1609
+ label: s,
1610
+ children: [
1611
+ /* @__PURE__ */ x("div", {
1612
+ className: "local-visual-readout",
1613
+ id: o,
1614
+ "aria-live": "polite",
1615
+ children: he
1616
+ }),
1617
+ /* @__PURE__ */ x("div", {
1618
+ className: "local-visual-svg-wrap",
1619
+ children: /* @__PURE__ */ S("svg", {
1620
+ className: "local-visual-svg",
1621
+ viewBox: `0 0 ${ae} ${oe}`,
1622
+ role: "group",
1623
+ "aria-label": `${s},区间 ${R(u)} 到 ${R(d)},${f} 个采样点`,
1624
+ "aria-describedby": o,
1625
+ tabIndex: 0,
1626
+ onPointerMove: V,
1627
+ onPointerLeave: () => r(null),
1628
+ onFocus: () => r((e) => e ?? (u + d) / 2),
1629
+ onBlur: () => r(null),
1630
+ onKeyDown: pe,
1631
+ children: [
1632
+ A.map((e) => /* @__PURE__ */ S("g", { children: [/* @__PURE__ */ x("line", {
1633
+ className: "local-visual-grid-line",
1634
+ x1: M,
1635
+ x2: 506,
1636
+ y1: ee(e),
1637
+ y2: ee(e)
1638
+ }), /* @__PURE__ */ x("text", {
1639
+ className: "local-visual-axis-label",
1640
+ x: M - 6,
1641
+ y: ee(e),
1642
+ textAnchor: "end",
1643
+ dominantBaseline: "middle",
1644
+ children: ue(e)
1645
+ })] }, `y-${e}`)),
1646
+ k.min < 0 && k.max > 0 ? /* @__PURE__ */ x("line", {
1647
+ className: "local-visual-zero-line",
1648
+ x1: M,
1649
+ x2: 506,
1650
+ y1: ee(0),
1651
+ y2: ee(0)
1652
+ }) : null,
1653
+ /* @__PURE__ */ x("line", {
1654
+ className: "local-visual-axis-line",
1655
+ x1: M,
1656
+ x2: 506,
1657
+ y1: 274,
1658
+ y2: 274
1659
+ }),
1660
+ j.map((e) => /* @__PURE__ */ S("g", { children: [/* @__PURE__ */ x("line", {
1661
+ className: "local-visual-tick",
1662
+ x1: P(e),
1663
+ x2: P(e),
1664
+ y1: 274,
1665
+ y2: 279
1666
+ }), /* @__PURE__ */ x("text", {
1667
+ className: "local-visual-axis-label",
1668
+ x: P(e),
1669
+ y: 293,
1670
+ textAnchor: "middle",
1671
+ children: ue(e)
1672
+ })] }, `x-${e}`)),
1673
+ c ? /* @__PURE__ */ x("text", {
1674
+ className: "local-visual-axis-title",
1675
+ x: (M + 506) / 2,
1676
+ y: 318,
1677
+ textAnchor: "middle",
1678
+ children: c
1679
+ }) : null,
1680
+ l ? /* @__PURE__ */ x("text", {
1681
+ className: "local-visual-axis-title",
1682
+ transform: "translate(12 145) rotate(-90)",
1683
+ textAnchor: "middle",
1684
+ children: l
1685
+ }) : null,
1686
+ I.map((e, t) => e.map((e, n) => {
1687
+ if (e.length < 2) return null;
1688
+ let r = e.map((e, t) => `${t === 0 ? "M" : "L"} ${P(e.x)} ${ee(e.y)}`).join(" ");
1689
+ return /* @__PURE__ */ x("path", {
1690
+ className: "local-visual-plot-line",
1691
+ d: r,
1692
+ fill: "none",
1693
+ stroke: F[t % F.length],
1694
+ strokeWidth: 2.4,
1695
+ strokeLinejoin: "round",
1696
+ strokeLinecap: "round"
1697
+ }, `curve-${t}-${n}`);
1698
+ })),
1699
+ me === null ? null : /* @__PURE__ */ x("line", {
1700
+ className: "local-visual-guide",
1701
+ x1: P(me),
1702
+ x2: P(me),
1703
+ y1: 16,
1704
+ y2: 274
1705
+ }),
1706
+ ye
1707
+ ]
1708
+ })
1709
+ }),
1710
+ /* @__PURE__ */ x(Ee, { notes: E }),
1711
+ O
1712
+ ]
1713
+ });
1714
+ }
1715
+ function Re({ node: e, runtime: t, render: n }) {
1716
+ let [r, i] = v(null), a = t.resetToken(e);
1717
+ m(() => {
1718
+ i(null);
1719
+ }, [a]);
1720
+ let o = B(t, e.attrs, "title", "") || "时间轴", s = B(t, e.attrs, "unit", "分钟"), c = we(e, t);
1721
+ if (!c) return /* @__PURE__ */ x(U, {
1722
+ className: "local-visual-timeline",
1723
+ label: o,
1724
+ children: /* @__PURE__ */ x(W, {
1725
+ message: "timeline 正文需要一个 Markdown 表格。",
1726
+ kind: "alert"
1727
+ })
1728
+ });
1729
+ let l = c.headerText.map((e) => e.trim()), u = l.indexOf("事项"), d = l.indexOf("开始"), f = l.indexOf("时长"), p = l.indexOf("说明");
1730
+ if (u < 0 || d < 0 || f < 0) return /* @__PURE__ */ x(U, {
1731
+ className: "local-visual-timeline",
1732
+ label: o,
1733
+ children: /* @__PURE__ */ x(W, {
1734
+ message: "timeline 表格需要“事项”“开始”“时长”三列。",
1735
+ kind: "alert"
1736
+ })
1737
+ });
1738
+ let h = [], g = [], _ = [];
1739
+ if (c.rows.forEach((e, t) => {
1740
+ let n = e.cells[d], r = e.cells[f], i = n?.numeric ?? null, a = r?.numeric ?? null;
1741
+ if (i === null || a === null || i < 0 || a < 0) {
1742
+ g.push(t + 1);
1743
+ return;
1744
+ }
1745
+ let o = Ce(e.cells[u]) || `事项 ${t + 1}`;
1746
+ _.push({
1747
+ key: `item-${e.index}`,
1748
+ title: o,
1749
+ start: i,
1750
+ duration: a,
1751
+ description: p >= 0 ? e.cells[p]?.children ?? [] : [],
1752
+ sourceIndex: t
1753
+ });
1754
+ }), g.length > 0 && h.push(`第 ${g.join("、")} 行的开始或时长不是非负数字,未显示。`), _.length === 0) return /* @__PURE__ */ S(U, {
1755
+ className: "local-visual-timeline",
1756
+ label: o,
1757
+ children: [/* @__PURE__ */ x(W, { message: "没有有效的时间轴事项。" }), /* @__PURE__ */ x(Ee, { notes: h })]
1758
+ });
1759
+ let y = [..._].sort((e, t) => e.start - t.start || e.sourceIndex - t.sourceIndex), C = y.reduce((e, t) => Math.max(e, t.start + t.duration), 0), w = Math.max(1, C), T = ge(0, w, 5);
1760
+ (T.length === 0 || T[0] !== 0) && T.unshift(0), T[T.length - 1] < w && T.push(w);
1761
+ let E = s ? ` ${s}` : "", D = (e) => `${R(e)}${E}`, O = y.find((e) => e.key === r) ?? null;
1762
+ return /* @__PURE__ */ S(U, {
1763
+ className: "local-visual-timeline",
1764
+ label: o,
1765
+ children: [
1766
+ /* @__PURE__ */ x("div", {
1767
+ className: "local-visual-timeline-axis",
1768
+ "aria-hidden": "true",
1769
+ children: T.map((e, t) => {
1770
+ let n = e / w * 100, r = t === T.length - 1 ? {
1771
+ left: `${n}%`,
1772
+ transform: "translateX(-100%)"
1773
+ } : t === 0 ? { left: "0%" } : {
1774
+ left: `${n}%`,
1775
+ transform: "translateX(-50%)"
1776
+ };
1777
+ return /* @__PURE__ */ x("span", {
1778
+ className: "local-visual-timeline-tick",
1779
+ style: r,
1780
+ children: ue(e)
1781
+ }, `tick-${e}`);
1782
+ })
1783
+ }),
1784
+ /* @__PURE__ */ x("ol", {
1785
+ className: "local-visual-timeline-list",
1786
+ children: y.map((e) => {
1787
+ let t = e.start + e.duration, n = e.start / w * 100, a = e.duration / w * 100, o = y.indexOf(e);
1788
+ return /* @__PURE__ */ S("li", {
1789
+ className: `local-visual-timeline-item${r === e.key ? " is-active" : ""}`,
1790
+ tabIndex: 0,
1791
+ "aria-label": `${e.title},开始 ${D(e.start)},结束 ${D(t)},时长 ${D(e.duration)}${e.description.length > 0 ? ",有说明" : ""}`,
1792
+ onFocus: () => i(e.key),
1793
+ onBlur: () => i((t) => t === e.key ? null : t),
1794
+ onPointerEnter: () => i(e.key),
1795
+ onPointerLeave: () => i((t) => t === e.key ? null : t),
1796
+ onKeyDown: (e) => {
1797
+ e.key === "Escape" && (e.preventDefault(), i(null));
1798
+ },
1799
+ children: [/* @__PURE__ */ S("div", {
1800
+ className: "local-visual-timeline-head",
1801
+ children: [/* @__PURE__ */ S("span", {
1802
+ className: "local-visual-timeline-title",
1803
+ children: [/* @__PURE__ */ x("span", {
1804
+ className: "local-visual-swatch",
1805
+ style: { backgroundColor: F[o % F.length] },
1806
+ "aria-hidden": "true"
1807
+ }), e.title]
1808
+ }), /* @__PURE__ */ S("span", {
1809
+ className: "local-visual-timeline-times",
1810
+ children: [
1811
+ "开始 ",
1812
+ D(e.start),
1813
+ " · 结束 ",
1814
+ D(t),
1815
+ " · 时长",
1816
+ " ",
1817
+ D(e.duration)
1818
+ ]
1819
+ })]
1820
+ }), /* @__PURE__ */ x("div", {
1821
+ className: "local-visual-timeline-track",
1822
+ "aria-hidden": "true",
1823
+ children: /* @__PURE__ */ x("span", {
1824
+ className: `local-visual-timeline-bar${e.duration === 0 ? " is-zero" : ""}`,
1825
+ style: {
1826
+ left: `${n}%`,
1827
+ width: `${a}%`,
1828
+ backgroundColor: F[o % F.length]
1829
+ }
1830
+ })
1831
+ })]
1832
+ }, e.key);
1833
+ })
1834
+ }),
1835
+ /* @__PURE__ */ x("div", {
1836
+ className: "local-visual-timeline-detail",
1837
+ "aria-live": "polite",
1838
+ children: O ? /* @__PURE__ */ S(b, { children: [/* @__PURE__ */ x("strong", { children: O.title }), O.description.length > 0 ? n(O.description) : /* @__PURE__ */ x("span", { children: "没有说明。" })] }) : /* @__PURE__ */ x("span", { children: "聚焦或指向事项查看说明。" })
1839
+ }),
1840
+ /* @__PURE__ */ x(Ee, { notes: h })
1841
+ ]
1842
+ });
1843
+ }
1844
+ function ze(e, t, n) {
1845
+ 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, []]));
1846
+ for (let e of t) e.from !== e.to && a.has(e.from) && a.has(e.to) && o.get(e.from).push(e.to);
1847
+ let s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Set(), u = [], d = [], f = 0, p = (e) => {
1848
+ s.set(e, f), c.set(e, f), f += 1, u.push(e), l.add(e);
1849
+ 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))));
1850
+ if (c.get(e) === s.get(e)) {
1851
+ let t = [], n;
1852
+ do
1853
+ n = u.pop(), l.delete(n), t.push(n);
1854
+ while (n !== e);
1855
+ d.push(t.reverse());
1856
+ }
1857
+ };
1858
+ for (let e of r) s.has(e) || p(e);
1859
+ let m = /* @__PURE__ */ new Map();
1860
+ d.forEach((e, t) => {
1861
+ for (let n of e) m.set(n, t);
1862
+ });
1863
+ let h = d.map(() => /* @__PURE__ */ new Set()), g = d.map(() => 0);
1864
+ for (let e of t) {
1865
+ if (!a.has(e.from) || !a.has(e.to)) continue;
1866
+ let t = m.get(e.from), n = m.get(e.to);
1867
+ t === n || h[t].has(n) || (h[t].add(n), g[n] += 1);
1868
+ }
1869
+ let _ = d.map((e, t) => ({
1870
+ index: t,
1871
+ order: Math.min(...e.map((e) => i.get(e) ?? 0))
1872
+ })), v = _.filter((e) => g[e.index] === 0).map((e) => e.index).sort((e, t) => _[e].order - _[t].order), y = d.map(() => 0);
1873
+ for (; v.length > 0;) {
1874
+ let e = v.shift();
1875
+ for (let t of h[e]) y[t] = Math.max(y[t], y[e] + 1), --g[t], g[t] === 0 && v.push(t);
1876
+ }
1877
+ let b = Math.max(1, ...y) + 1, x = Array.from({ length: b }, () => []);
1878
+ for (let e of r) x[y[m.get(e)]].push(e);
1879
+ let S = x.filter((e) => e.length > 0), C = Math.max(1, ...S.map((e) => e.length)), w = /* @__PURE__ */ new Map();
1880
+ if (n === "down") {
1881
+ let e = se, t = Math.max(240, 106 + (S.length - 1) * 120);
1882
+ return S.forEach((t, n) => {
1883
+ let r = 53 + n * 120;
1884
+ t.forEach((n, i) => {
1885
+ let a = t.length === 1 ? e / 2 : 104 + i * (312 / (t.length - 1));
1886
+ w.set(n, {
1887
+ x: a,
1888
+ y: r
1889
+ });
1890
+ });
1891
+ }), {
1892
+ width: e,
1893
+ height: t,
1894
+ positions: w
1895
+ };
1896
+ }
1897
+ let T = Math.max(se, 208 + (S.length - 1) * 150), E = Math.max(240, 106 + (C - 1) * 74);
1898
+ return S.forEach((e, t) => {
1899
+ let n = S.length === 1 ? T / 2 : 104 + t * ((T - 88 - I) / (S.length - 1));
1900
+ e.forEach((t, r) => {
1901
+ let i = e.length === 1 ? E / 2 : 53 + r * ((E - 60 - ce) / (e.length - 1));
1902
+ w.set(t, {
1903
+ x: n,
1904
+ y: i
1905
+ });
1906
+ });
1907
+ }), {
1908
+ width: T,
1909
+ height: E,
1910
+ positions: w
1911
+ };
1912
+ }
1913
+ function Be(e, t, n, r, i) {
1914
+ let a = I, o = ce;
1915
+ if (i) return e === "right" ? {
1916
+ 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}`,
1917
+ labelX: t.x,
1918
+ labelY: t.y - o / 2 - 46
1919
+ } : {
1920
+ 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}`,
1921
+ labelX: t.x + a / 2 + 44,
1922
+ labelY: t.y
1923
+ };
1924
+ if (e === "right") {
1925
+ if (n.x > t.x) {
1926
+ let e = t.x + a / 2, i = t.y + r, o = n.x - a / 2, s = n.y + r;
1927
+ return {
1928
+ d: `M ${e} ${i} L ${o} ${s}`,
1929
+ labelX: (e + o) / 2,
1930
+ labelY: (i + s) / 2 - 6
1931
+ };
1932
+ }
1933
+ 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);
1934
+ return {
1935
+ d: `M ${e} ${s} C ${e + l} ${s + 86}, ${i - l} ${c + 86}, ${i} ${c}`,
1936
+ labelX: (e + i) / 2,
1937
+ labelY: Math.max(s, c) + 48
1938
+ };
1939
+ }
1940
+ if (n.y > t.y) {
1941
+ let e = t.x + r, i = n.x + r, a = t.y + o / 2, s = n.y - o / 2;
1942
+ return {
1943
+ d: `M ${e} ${a} L ${i} ${s}`,
1944
+ labelX: (e + i) / 2 + 6,
1945
+ labelY: (a + s) / 2
1946
+ };
1947
+ }
1948
+ 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);
1949
+ return {
1950
+ d: `M ${s} ${l} C ${s + 86} ${l + d}, ${c + 86} ${u - d}, ${c} ${u}`,
1951
+ labelX: Math.max(s, c) + 48,
1952
+ labelY: (l + u) / 2
1953
+ };
1954
+ }
1955
+ function Ve({ node: e, runtime: t, render: n }) {
1956
+ let [r, i] = v(null), [a, o] = v(null), s = t.resetToken(e);
1957
+ m(() => {
1958
+ i(null), o(null);
1959
+ }, [s]);
1960
+ let c = `local-diagram-arrow-${h().replace(/[^a-zA-Z0-9_-]/g, "")}`, l = B(t, e.attrs, "label", "") || "图解", u = (e.attrs?.direction ?? "right").trim().toLowerCase() === "down" ? "down" : "right", d = e.children?.filter((e) => e.type === "component") ?? [], f = [], p = [], g = /* @__PURE__ */ new Set();
1961
+ for (let e of d) {
1962
+ if (e.name !== "node") continue;
1963
+ let n = (e.attrs?.id ?? "").trim();
1964
+ if (!n) {
1965
+ f.push("存在缺少 id 的节点,已忽略。");
1966
+ continue;
1967
+ }
1968
+ if (g.has(n)) {
1969
+ f.push(`节点 id 重复:${n},已忽略后续节点。`);
1970
+ continue;
1971
+ }
1972
+ g.add(n);
1973
+ let r = B(t, e.attrs, "tone", "neutral").trim(), i = r === "success" || r === "warning" ? r : "neutral";
1974
+ p.push({
1975
+ id: n,
1976
+ label: B(t, e.attrs, "label", n) || n,
1977
+ tone: i,
1978
+ children: e.children ?? []
1979
+ });
1980
+ }
1981
+ let _ = [], y = /* @__PURE__ */ new Set();
1982
+ for (let e of d) {
1983
+ if (e.name !== "edge") continue;
1984
+ let n = (e.attrs?.from ?? "").trim(), r = (e.attrs?.to ?? "").trim();
1985
+ if (!n || !r || !g.has(n) || !g.has(r)) {
1986
+ f.push(`边 ${n || "?"} → ${r || "?"} 的端点不存在,已忽略。`);
1987
+ continue;
1988
+ }
1989
+ let i = B(t, e.attrs, "label", ""), a = `${n}\u0000${r}\u0000${i}`;
1990
+ y.has(a) ? f.push(`重复的边:${n} → ${r}${i ? `(${i})` : ""},已忽略。`) : (y.add(a), _.push({
1991
+ key: a,
1992
+ from: n,
1993
+ to: r,
1994
+ label: i
1995
+ }));
1996
+ }
1997
+ if (p.length === 0) return /* @__PURE__ */ S(U, {
1998
+ className: "local-visual-diagram",
1999
+ label: l,
2000
+ children: [/* @__PURE__ */ x(W, {
2001
+ message: "diagram 至少需要一个 node。",
2002
+ kind: "alert"
2003
+ }), /* @__PURE__ */ x(Ee, { notes: f })]
2004
+ });
2005
+ let C = null;
2006
+ try {
2007
+ let n = t.get(e);
2008
+ typeof n == "string" && (C = n);
2009
+ } catch {
2010
+ C = null;
2011
+ }
2012
+ let w = new Set(p.map((e) => e.id)), T = (e.attrs?.initial ?? "").trim(), E = T && w.has(T) ? T : p[0].id, D = C && w.has(C) ? C : r && w.has(r) ? r : E, O = p.find((e) => e.id === D) ?? p[0], k = (n) => {
2013
+ i(n), o(null);
2014
+ try {
2015
+ let r = t.set(e, n);
2016
+ r.length > 0 && o(r.map((e) => e.message).join(";"));
2017
+ } catch (e) {
2018
+ o(z(e));
2019
+ }
2020
+ }, A = ze(p, _, u), j = /* @__PURE__ */ new Map();
2021
+ for (let e of _) {
2022
+ let t = `${e.from}\u0000${e.to}`;
2023
+ j.set(t, (j.get(t) ?? 0) + 1);
2024
+ }
2025
+ let M = /* @__PURE__ */ new Map(), N = _.map((e) => {
2026
+ let t = A.positions.get(e.from), n = A.positions.get(e.to);
2027
+ if (!t || !n) return null;
2028
+ let r = `${e.from}\u0000${e.to}`, i = j.get(r) ?? 1, a = M.get(r) ?? 0;
2029
+ M.set(r, a + 1);
2030
+ let o = (a - (i - 1) / 2) * 12, s = Be(u, t, n, o, e.from === e.to);
2031
+ return /* @__PURE__ */ S("g", {
2032
+ className: "local-visual-edge",
2033
+ children: [/* @__PURE__ */ x("path", {
2034
+ d: s.d,
2035
+ fill: "none",
2036
+ stroke: "var(--local-ink-muted, #64748b)",
2037
+ strokeWidth: 1.6,
2038
+ markerEnd: `url(#${c})`
2039
+ }), e.label ? /* @__PURE__ */ x("text", {
2040
+ className: "local-visual-edge-label",
2041
+ x: s.labelX,
2042
+ y: s.labelY,
2043
+ textAnchor: "middle",
2044
+ dominantBaseline: "middle",
2045
+ children: e.label
2046
+ }) : null]
2047
+ }, `edge-${e.key}`);
2048
+ });
2049
+ return /* @__PURE__ */ S(U, {
2050
+ className: "local-visual-diagram",
2051
+ label: l,
2052
+ children: [
2053
+ /* @__PURE__ */ x("div", {
2054
+ className: "local-visual-svg-wrap",
2055
+ children: /* @__PURE__ */ S("svg", {
2056
+ className: "local-visual-svg local-visual-diagram-svg",
2057
+ viewBox: `0 0 ${A.width} ${A.height}`,
2058
+ role: "group",
2059
+ "aria-label": `${l},包含 ${p.length} 个节点和 ${_.length} 条边;用 Tab 聚焦节点,回车选择`,
2060
+ children: [
2061
+ /* @__PURE__ */ x("defs", { children: /* @__PURE__ */ x("marker", {
2062
+ id: c,
2063
+ viewBox: "0 0 10 10",
2064
+ refX: "9",
2065
+ refY: "5",
2066
+ markerWidth: "7",
2067
+ markerHeight: "7",
2068
+ orient: "auto-start-reverse",
2069
+ children: /* @__PURE__ */ x("path", {
2070
+ d: "M 0 0 L 10 5 L 0 10 z",
2071
+ fill: "var(--local-ink-muted, #64748b)"
2072
+ })
2073
+ }) }),
2074
+ N,
2075
+ p.map((e) => {
2076
+ let t = A.positions.get(e.id);
2077
+ if (!t) return null;
2078
+ let n = e.id === D, r = me(e.label, 8, 2);
2079
+ return /* @__PURE__ */ S("g", {
2080
+ className: `local-visual-node local-visual-node-${e.tone}${n ? " is-selected" : ""}`,
2081
+ "data-diagram-node": "",
2082
+ transform: `translate(${t.x} ${t.y})`,
2083
+ role: "button",
2084
+ tabIndex: 0,
2085
+ "aria-pressed": n,
2086
+ "aria-label": e.label,
2087
+ onClick: () => k(e.id),
2088
+ onKeyDown: (t) => {
2089
+ be(t) ? (t.preventDefault(), k(e.id)) : t.key === "ArrowRight" || t.key === "ArrowDown" ? ye(t, "[data-diagram-node]", 1) : (t.key === "ArrowLeft" || t.key === "ArrowUp") && ye(t, "[data-diagram-node]", -1);
2090
+ },
2091
+ children: [
2092
+ /* @__PURE__ */ x("title", { children: e.label }),
2093
+ /* @__PURE__ */ x("rect", {
2094
+ className: "local-visual-node-shape",
2095
+ x: -60,
2096
+ y: -23,
2097
+ width: I,
2098
+ height: ce,
2099
+ rx: 10
2100
+ }),
2101
+ /* @__PURE__ */ x("text", {
2102
+ className: "local-visual-node-text",
2103
+ textAnchor: "middle",
2104
+ children: r.map((e, t) => /* @__PURE__ */ x("tspan", {
2105
+ x: 0,
2106
+ y: (t - (r.length - 1) / 2) * 16 + 4,
2107
+ children: e
2108
+ }, t))
2109
+ })
2110
+ ]
2111
+ }, `node-${e.id}`);
2112
+ })
2113
+ ]
2114
+ })
2115
+ }),
2116
+ /* @__PURE__ */ x("div", {
2117
+ className: "local-visual-diagram-detail",
2118
+ "aria-live": "polite",
2119
+ children: O ? /* @__PURE__ */ S(b, { children: [/* @__PURE__ */ x("strong", { children: O.label }), O.children.length > 0 ? n(O.children) : /* @__PURE__ */ x("span", { children: "该节点没有说明。" })] }) : /* @__PURE__ */ x("span", { children: "点击或用 Tab 聚焦节点后按回车查看说明。" })
2120
+ }),
2121
+ a ? /* @__PURE__ */ x(W, {
2122
+ message: a,
2123
+ kind: "alert"
2124
+ }) : null,
2125
+ /* @__PURE__ */ x(Ee, { notes: f }),
2126
+ /* @__PURE__ */ S("details", {
2127
+ className: "local-visual-details",
2128
+ children: [/* @__PURE__ */ x("summary", { children: "查看节点与连线" }), /* @__PURE__ */ S("ul", {
2129
+ className: "local-visual-diagram-list",
2130
+ children: [p.map((e) => /* @__PURE__ */ x("li", { children: /* @__PURE__ */ x("strong", { children: e.label }) }, `list-${e.id}`)), _.map((e) => {
2131
+ let t = p.find((t) => t.id === e.from), n = p.find((t) => t.id === e.to);
2132
+ return /* @__PURE__ */ S("li", { children: [
2133
+ t?.label ?? e.from,
2134
+ " → ",
2135
+ n?.label ?? e.to,
2136
+ e.label ? `(${e.label})` : ""
2137
+ ] }, `edge-list-${e.key}`);
2138
+ })]
2139
+ })]
2140
+ })
2141
+ ]
2142
+ });
2143
+ }
2144
+ function He(e) {
2145
+ switch (e.node.name) {
2146
+ case "table": return /* @__PURE__ */ x(Oe, { ...e });
2147
+ case "chart": return /* @__PURE__ */ x(je, { ...e });
2148
+ case "plot": return /* @__PURE__ */ x(Le, { ...e });
2149
+ case "timeline": return /* @__PURE__ */ x(Re, { ...e });
2150
+ case "diagram": return /* @__PURE__ */ x(Ve, { ...e });
2151
+ default: return null;
2152
+ }
2153
+ }
2154
+ // src/local/LocalDocumentView.tsx
2155
+ var Ue = u(null);
2156
+ function G() {
2157
+ let e = p(Ue);
2158
+ if (!e) throw Error("LocalViewContext 未初始化");
2159
+ return e;
2160
+ }
2161
+ var We = /^\s*\{\{([\s\S]*)\}\}\s*$/, Ge = {
2162
+ revision: 0,
2163
+ state: {}
2164
+ };
2165
+ function K(e, t) {
2166
+ return e.attrs?.[t];
2167
+ }
2168
+ function Ke(e, t, n) {
2169
+ let r = K(t, n);
2170
+ if (r === void 0) return { present: !1 };
2171
+ let i = We.exec(r);
2172
+ if (!i) return {
2173
+ present: !0,
2174
+ ok: !0,
2175
+ value: r
2176
+ };
2177
+ try {
2178
+ return {
2179
+ present: !0,
2180
+ ok: !0,
2181
+ value: e.evaluate(i[1])
2182
+ };
2183
+ } catch {
2184
+ return {
2185
+ present: !0,
2186
+ ok: !1
2187
+ };
2188
+ }
2189
+ }
2190
+ function qe(e) {
2191
+ return e === null ? "" : typeof e == "string" ? e : typeof e == "number" ? Number.isFinite(e) ? String(e) : null : typeof e == "boolean" ? e ? "true" : "false" : null;
2192
+ }
2193
+ function q(e, t, n, r = "") {
2194
+ let i = K(t, n);
2195
+ if (i === void 0) return r;
2196
+ let a = We.exec(i);
2197
+ try {
2198
+ return a ? qe(e.evaluate(a[1])) ?? "无法计算" : e.text(i);
2199
+ } catch {
2200
+ return "无法计算";
2201
+ }
2202
+ }
2203
+ function Je(e, t, n, r) {
2204
+ let i = K(t, n);
2205
+ if (i === void 0) return {
2206
+ ok: !0,
2207
+ value: r
2208
+ };
2209
+ let a = We.exec(i);
2210
+ if (!a) return {
2211
+ ok: !0,
2212
+ value: i === "true"
2213
+ };
2214
+ try {
2215
+ let t = e.evaluate(a[1]);
2216
+ return typeof t == "boolean" ? {
2217
+ ok: !0,
2218
+ value: t
2219
+ } : { ok: !1 };
2220
+ } catch {
2221
+ return { ok: !1 };
2222
+ }
2223
+ }
2224
+ function Ye(e, t, n, r = !1) {
2225
+ let i = Je(e, t, n, r);
2226
+ return i.ok ? i.value : r;
2227
+ }
2228
+ function Xe(e) {
2229
+ try {
2230
+ return e.snapshot().revision;
2231
+ } catch {
2232
+ return 0;
2233
+ }
2234
+ }
2235
+ function J(e, t, n, r) {
2236
+ let i = K(t, n);
2237
+ if (i === void 0) return r;
2238
+ let a = We.exec(i);
2239
+ try {
2240
+ let t = a ? e.evaluate(a[1]) : Number(i);
2241
+ return typeof t == "number" && Number.isFinite(t) ? t : r;
2242
+ } catch {
2243
+ return r;
2244
+ }
2245
+ }
2246
+ function Y(e, t) {
2247
+ try {
2248
+ return e.get(t);
2249
+ } catch {
2250
+ return null;
2251
+ }
2252
+ }
2253
+ function Ze(e) {
2254
+ return qe(e) ?? "";
2255
+ }
2256
+ function X(e) {
2257
+ let { runtime: t, report: n } = G(), [r, i] = v(null);
2258
+ return {
2259
+ write: f((r) => {
2260
+ try {
2261
+ let a = t.set(e, r);
2262
+ return a.length ? (i(a.map((e) => e.message).join(";")), n(a), !1) : (i(null), !0);
2263
+ } catch (e) {
2264
+ return i(e instanceof Error ? e.message : "无法写入"), !1;
2265
+ }
2266
+ }, [
2267
+ e,
2268
+ n,
2269
+ t
2270
+ ]),
2271
+ error: r,
2272
+ setError: i
2273
+ };
2274
+ }
2275
+ function Qe(e) {
2276
+ let { runtime: t } = G(), n = Je(t, e, "disabled", !1);
2277
+ return n.ok ? {
2278
+ disabled: n.value,
2279
+ invalid: !1
2280
+ } : {
2281
+ disabled: !0,
2282
+ invalid: !0
2283
+ };
2284
+ }
2285
+ function $e(e, t, n) {
2286
+ let r = 0;
2287
+ try {
2288
+ r = e.resetToken(t);
2289
+ } catch {
2290
+ r = 0;
2291
+ }
2292
+ let i = _(r), a = _(n);
2293
+ a.current = n, m(() => {
2294
+ i.current !== r && (i.current = r, a.current());
2295
+ }, [r]);
2296
+ }
2297
+ function Z({ message: e = "无法计算" }) {
2298
+ return /* @__PURE__ */ x("span", {
2299
+ className: "local-error",
2300
+ role: "alert",
2301
+ children: e
2302
+ });
2303
+ }
2304
+ var et = class extends l {
2305
+ state = { failed: !1 };
2306
+ static getDerivedStateFromError() {
2307
+ return { failed: !0 };
2308
+ }
2309
+ componentDidUpdate(e) {
2310
+ this.state.failed && e.revision !== this.props.revision && this.setState({ failed: !1 });
2311
+ }
2312
+ render() {
2313
+ return this.state.failed ? /* @__PURE__ */ x(Z, {}) : this.props.children;
2314
+ }
2315
+ }, tt = /* @__PURE__ */ new Set([
2316
+ "table",
2317
+ "chart",
2318
+ "plot",
2319
+ "timeline",
2320
+ "diagram"
2321
+ ]);
2322
+ function nt(e, t, n) {
2323
+ if (!e) return null;
2324
+ let r = e.trim();
2325
+ if (!r) return null;
2326
+ let i = r.replace(/[\u0000- ]+/g, ""), a = /^([a-z][a-z0-9+.-]*):/i.exec(i);
2327
+ if (a) {
2328
+ let e = a[1].toLowerCase();
2329
+ if (!(t === "image" ? e === "http" || e === "https" : e === "http" || e === "https" || e === "mailto" || e === "tel")) return null;
2330
+ }
2331
+ if (!n) return t === "image" ? null : r;
2332
+ try {
2333
+ return n(r, t) ? r : null;
2334
+ } catch {
2335
+ return null;
2336
+ }
2337
+ }
2338
+ function rt(e) {
2339
+ return `h${Math.min(6, Math.max(1, e ?? 1))}`;
2340
+ }
2341
+ function Q(e, t, n) {
2342
+ return !t || t.length === 0 ? null : t.map((t, r) => at(e, t, r, n));
2343
+ }
2344
+ function it(e, t, n) {
2345
+ return !t || t.length === 0 ? null : t.map((t, r) => t.type === "paragraph" || t.type === "root" ? /* @__PURE__ */ x("span", { children: Q(e, t.children, n) }, t.id || `inline-${r}`) : at(e, t, r, n));
2346
+ }
2347
+ function at(e, t, n, r) {
2348
+ let i = t.id || `${t.type}-${n}`;
2349
+ if (t.type === "component") return /* @__PURE__ */ x(et, {
2350
+ revision: Xe(e.runtime),
2351
+ children: st(t, r)
2352
+ }, i);
2353
+ switch (t.type) {
2354
+ case "root": return /* @__PURE__ */ x("div", { children: Q(e, t.children, r) }, i);
2355
+ case "heading": return d(rt(t.depth), { key: i }, Q(e, t.children, r));
2356
+ case "paragraph": return /* @__PURE__ */ x("p", { children: Q(e, t.children, r) }, i);
2357
+ case "text": return /* @__PURE__ */ x("span", { children: t.value ?? "" }, i);
2358
+ case "emphasis": return /* @__PURE__ */ x("em", { children: Q(e, t.children, r) }, i);
2359
+ case "strong": return /* @__PURE__ */ x("strong", { children: Q(e, t.children, r) }, i);
2360
+ case "delete": return /* @__PURE__ */ x("del", { children: Q(e, t.children, r) }, i);
2361
+ case "inlineCode": return /* @__PURE__ */ x("code", {
2362
+ className: "md-inline-code",
2363
+ children: t.value ?? ""
2364
+ }, i);
2365
+ case "code": {
2366
+ let e = t.lang ? `language-${t.lang}` : void 0;
2367
+ return /* @__PURE__ */ x("pre", {
2368
+ className: "md-code",
2369
+ children: /* @__PURE__ */ x("code", {
2370
+ className: e,
2371
+ children: t.value ?? ""
2372
+ })
2373
+ }, i);
2374
+ }
2375
+ case "blockquote": return /* @__PURE__ */ x("blockquote", { children: Q(e, t.children, r) }, i);
2376
+ case "break": return /* @__PURE__ */ x("br", {}, i);
2377
+ case "thematicBreak": return /* @__PURE__ */ x("hr", {}, i);
2378
+ case "list": return t.ordered ? /* @__PURE__ */ x("ol", {
2379
+ start: t.start ?? 1,
2380
+ className: "md-list",
2381
+ children: Q(e, t.children, r)
2382
+ }, i) : /* @__PURE__ */ x("ul", {
2383
+ className: "md-list",
2384
+ children: Q(e, t.children, r)
2385
+ }, i);
2386
+ case "listItem": {
2387
+ let n = typeof t.checked == "boolean";
2388
+ return /* @__PURE__ */ S("li", {
2389
+ className: n ? "md-list-item md-task-item" : "md-list-item",
2390
+ children: [n ? /* @__PURE__ */ x("input", {
2391
+ type: "checkbox",
2392
+ className: "md-task-checkbox",
2393
+ checked: t.checked === !0,
2394
+ readOnly: !0,
2395
+ tabIndex: -1,
2396
+ "aria-label": t.checked ? "已完成" : "未完成"
2397
+ }) : null, Q(e, t.children, r)]
2398
+ }, i);
2399
+ }
2400
+ case "link": {
2401
+ let n = nt(t.url, "link", e.urlPolicy);
2402
+ if (!n) return /* @__PURE__ */ x("span", {
2403
+ className: "md-link-rejected",
2404
+ title: "已拒绝不安全的链接地址",
2405
+ children: Q(e, t.children, r)
2406
+ }, i);
2407
+ let a = /^https?:/i.test(n);
2408
+ return /* @__PURE__ */ x("a", {
2409
+ href: n,
2410
+ title: t.title ?? void 0,
2411
+ target: a ? "_blank" : void 0,
2412
+ rel: a ? "noopener noreferrer" : void 0,
2413
+ children: Q(e, t.children, r)
2414
+ }, i);
2415
+ }
2416
+ case "image": {
2417
+ let n = nt(t.url, "image", e.urlPolicy);
2418
+ return n ? /* @__PURE__ */ x("img", {
2419
+ className: "md-image",
2420
+ src: n,
2421
+ alt: t.alt ?? "",
2422
+ title: t.title ?? void 0,
2423
+ loading: "lazy",
2424
+ referrerPolicy: "no-referrer"
2425
+ }, i) : /* @__PURE__ */ S("span", {
2426
+ className: "md-image-rejected",
2427
+ children: [
2428
+ "[已拒绝不安全的图片",
2429
+ t.alt ? `:${t.alt}` : "",
2430
+ "]"
2431
+ ]
2432
+ }, i);
2433
+ }
2434
+ case "table": {
2435
+ let [n, ...a] = t.children ?? [];
2436
+ return /* @__PURE__ */ x("div", {
2437
+ className: "md-table-scroll",
2438
+ children: /* @__PURE__ */ S("table", {
2439
+ className: "md-table",
2440
+ children: [n ? /* @__PURE__ */ x("thead", { children: /* @__PURE__ */ x("tr", { children: ot(e, n, "th", t.align, r) }) }) : null, a.length ? /* @__PURE__ */ x("tbody", { children: a.map((n, a) => /* @__PURE__ */ x("tr", { children: ot(e, n, "td", t.align, r) }, n.id || `${i}-row-${a}`)) }) : null]
2441
+ })
2442
+ }, i);
2443
+ }
2444
+ case "tableRow": return /* @__PURE__ */ x("tr", { children: ot(e, t, "td", void 0, r) }, i);
2445
+ case "tableCell": {
2446
+ let n = t.align?.[0] ?? void 0;
2447
+ return /* @__PURE__ */ x("td", {
2448
+ style: { textAlign: n ?? void 0 },
2449
+ children: Q(e, t.children, r)
2450
+ }, i);
2451
+ }
2452
+ case "interpolation": try {
2453
+ let n = qe(e.runtime.evaluate(t.value ?? ""));
2454
+ if (n === null) throw Error("无法显示数组");
2455
+ return /* @__PURE__ */ x("span", {
2456
+ className: "local-interpolation",
2457
+ children: n
2458
+ }, i);
2459
+ } catch {
2460
+ return /* @__PURE__ */ x(Z, {}, i);
2461
+ }
2462
+ case "math":
2463
+ case "inlineMath": {
2464
+ let n = t.type === "math";
2465
+ return /* @__PURE__ */ x("span", {
2466
+ className: n ? "local-math-display" : "local-math-inline",
2467
+ children: /* @__PURE__ */ x(et, {
2468
+ revision: Xe(e.runtime),
2469
+ children: /* @__PURE__ */ x(ne, {
2470
+ source: t.value ?? "",
2471
+ display: n
2472
+ })
2473
+ })
2474
+ }, i);
2475
+ }
2476
+ case "html": return /* @__PURE__ */ x("span", {
2477
+ className: "md-raw-html",
2478
+ children: t.value ?? ""
2479
+ }, i);
2480
+ case "comment":
2481
+ case "definition":
2482
+ case "footnoteDefinition": return null;
2483
+ default: return t.children && t.children.length ? /* @__PURE__ */ x("span", { children: Q(e, t.children, r) }, i) : typeof t.value == "string" ? /* @__PURE__ */ x("span", { children: t.value }, i) : null;
2484
+ }
2485
+ }
2486
+ function ot(e, t, n, r, i) {
2487
+ return (t.children ?? []).map((a, o) => {
2488
+ let s = a.align?.[0] ?? t.align?.[o] ?? r?.[o] ?? void 0;
2489
+ return n === "th" ? /* @__PURE__ */ x("th", {
2490
+ style: { textAlign: s ?? void 0 },
2491
+ children: Q(e, a.children, i)
2492
+ }, a.id || `${t.id}-h-${o}`) : /* @__PURE__ */ x("td", {
2493
+ style: { textAlign: s ?? void 0 },
2494
+ children: Q(e, a.children, i)
2495
+ }, a.id || `${t.id}-c-${o}`);
2496
+ });
2497
+ }
2498
+ function st(e, t) {
2499
+ let n = e.name ?? "";
2500
+ if (tt.has(n)) return /* @__PURE__ */ x(ct, {
2501
+ node: e,
2502
+ visible: t
2503
+ });
2504
+ let r = Wt[n];
2505
+ return r ? /* @__PURE__ */ x(r, {
2506
+ node: e,
2507
+ visible: t
2508
+ }) : /* @__PURE__ */ S("span", {
2509
+ className: "component-error",
2510
+ children: [
2511
+ "未知组件“",
2512
+ n || "(缺少名称)",
2513
+ "”"
2514
+ ]
2515
+ });
2516
+ }
2517
+ function ct({ node: e, visible: t }) {
2518
+ let { runtime: n, render: r } = G();
2519
+ return /* @__PURE__ */ x(He, {
2520
+ node: e,
2521
+ runtime: n,
2522
+ render: r,
2523
+ visible: t
2524
+ });
2525
+ }
2526
+ function $({ message: e }) {
2527
+ return e ? /* @__PURE__ */ x("span", {
2528
+ className: "field-error",
2529
+ role: "alert",
2530
+ children: e
2531
+ }) : null;
2532
+ }
2533
+ function lt(e, t) {
2534
+ if (t.required && e.length === 0) return "请填写此字段";
2535
+ if (e.length > 1e5) return `最多允许 ${c} 个字符`;
2536
+ if (t.email && e !== "" && !n(e)) return "请输入有效的邮箱地址";
2537
+ let r = e.length;
2538
+ 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;
2539
+ }
2540
+ function ut({ node: e }) {
2541
+ let t = h(), { 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 = Ye(n, e, "required", !1), { disabled: u, invalid: d } = Qe(e), f = K(e, "min-length"), p = K(e, "max-length"), g = f === void 0 ? void 0 : Math.max(0, Math.floor(J(n, e, "min-length", 0))), y = p === void 0 ? void 0 : Math.max(0, Math.floor(J(n, e, "max-length", 0))), b = Ze(Y(n, e)), [C, w] = v(b), [T, E] = v(!1), [D, O] = v(!1), [k, A] = v(null), j = _(!1), M = _(b), N = _(b);
2542
+ N.current = b, m(() => {
2543
+ M.current !== b && (M.current = b, !T && !j.current && w(b));
2544
+ }, [b, T]), $e(n, e, () => {
2545
+ j.current = !1, w(N.current), O(!1), A(null), a(null);
2546
+ });
2547
+ let P = (e) => lt(e, {
2548
+ required: l,
2549
+ minLength: g,
2550
+ maxLength: y,
2551
+ email: c
2552
+ });
2553
+ return /* @__PURE__ */ S("div", {
2554
+ className: `md-control local-input${c ? " local-input-email" : ""}`,
2555
+ children: [
2556
+ /* @__PURE__ */ x("label", {
2557
+ className: "md-label",
2558
+ htmlFor: `${t}-input`,
2559
+ children: o
2560
+ }),
2561
+ /* @__PURE__ */ x("input", {
2562
+ id: `${t}-input`,
2563
+ className: "md-text-input",
2564
+ type: c ? "email" : "text",
2565
+ value: C,
2566
+ placeholder: s || void 0,
2567
+ disabled: u,
2568
+ required: l,
2569
+ minLength: g,
2570
+ maxLength: y,
2571
+ "aria-invalid": k || i ? !0 : void 0,
2572
+ onFocus: () => E(!0),
2573
+ onBlur: () => {
2574
+ E(!1), O(!0);
2575
+ let e = P(C);
2576
+ A(e), !e && C !== b && r(C);
2577
+ },
2578
+ onChange: (e) => {
2579
+ let t = e.target.value;
2580
+ w(t), a(null), D && A(P(t)), !j.current && P(t) === null && r(t);
2581
+ },
2582
+ onCompositionStart: () => {
2583
+ j.current = !0;
2584
+ },
2585
+ onCompositionEnd: (e) => {
2586
+ j.current = !1;
2587
+ let t = e.currentTarget.value;
2588
+ w(t), D && A(P(t)), P(t) === null && r(t);
2589
+ }
2590
+ }),
2591
+ /* @__PURE__ */ x($, { message: d ? "无法计算" : k ?? i })
2592
+ ]
2593
+ });
2594
+ }
2595
+ function dt({ node: e }) {
2596
+ let t = h(), { 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 = Ye(n, e, "required", !1), { disabled: u, invalid: d } = Qe(e), f = K(e, "min-length"), p = K(e, "max-length"), g = f === void 0 ? void 0 : Math.max(0, Math.floor(J(n, e, "min-length", 0))), y = p === void 0 ? void 0 : Math.max(0, Math.floor(J(n, e, "max-length", 0))), b = Ze(Y(n, e)), [C, w] = v(b), [T, E] = v(!1), [D, O] = v(!1), [k, A] = v(null), j = _(!1), M = _(b), N = _(b);
2597
+ N.current = b, m(() => {
2598
+ M.current !== b && (M.current = b, !T && !j.current && w(b));
2599
+ }, [b, T]), $e(n, e, () => {
2600
+ j.current = !1, w(N.current), O(!1), A(null), a(null);
2601
+ });
2602
+ let P = (e) => lt(e, {
2603
+ required: l,
2604
+ minLength: g,
2605
+ maxLength: y
2606
+ });
2607
+ return /* @__PURE__ */ S("div", {
2608
+ className: "md-control local-textarea",
2609
+ children: [
2610
+ /* @__PURE__ */ x("label", {
2611
+ className: "md-label",
2612
+ htmlFor: `${t}-textarea`,
2613
+ children: o
2614
+ }),
2615
+ /* @__PURE__ */ x("textarea", {
2616
+ id: `${t}-textarea`,
2617
+ className: "md-text-input",
2618
+ rows: c,
2619
+ value: C,
2620
+ placeholder: s || void 0,
2621
+ disabled: u,
2622
+ required: l,
2623
+ minLength: g,
2624
+ maxLength: y,
2625
+ "aria-invalid": k || i ? !0 : void 0,
2626
+ onFocus: () => E(!0),
2627
+ onBlur: () => {
2628
+ E(!1), O(!0);
2629
+ let e = P(C);
2630
+ A(e), !e && C !== b && r(C);
2631
+ },
2632
+ onChange: (e) => {
2633
+ let t = e.target.value;
2634
+ w(t), a(null), D && A(P(t)), !j.current && P(t) === null && r(t);
2635
+ },
2636
+ onCompositionStart: () => {
2637
+ j.current = !0;
2638
+ },
2639
+ onCompositionEnd: (e) => {
2640
+ j.current = !1;
2641
+ let t = e.currentTarget.value;
2642
+ w(t), D && A(P(t)), P(t) === null && r(t);
2643
+ }
2644
+ }),
2645
+ /* @__PURE__ */ x($, { message: d ? "无法计算" : k ?? i })
2646
+ ]
2647
+ });
2648
+ }
2649
+ function ft(e) {
2650
+ let t = e.trim();
2651
+ if (t === "" || t === "-" || t === "+" || t === "." || t === "-.") return { kind: "empty" };
2652
+ let n = Number(t);
2653
+ return Number.isFinite(n) ? {
2654
+ kind: "valid",
2655
+ value: n
2656
+ } : { kind: "invalid" };
2657
+ }
2658
+ function pt(e, t, n, r) {
2659
+ let i = 1e-9 * Math.max(1, Math.abs(e));
2660
+ if (t !== void 0 && e < t - i) return `不能小于 ${t}`;
2661
+ if (n !== void 0 && e > n + i) return `不能大于 ${n}`;
2662
+ if (!Number.isFinite(r) || r <= 0) return "步长必须大于 0";
2663
+ let a = (e - (t ?? 0)) / r;
2664
+ return Math.abs(a - Math.round(a)) > 1e-9 * Math.max(1, Math.abs(a)) ? `需要按步长 ${r} 取值` : null;
2665
+ }
2666
+ function mt({ node: e }) {
2667
+ let t = h(), { runtime: n } = G(), { write: r, error: i, setError: a } = X(e), o = q(n, e, "label", "数字"), { disabled: s, invalid: c } = Qe(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), g = Y(n, e), y = typeof g == "number" && Number.isFinite(g) ? String(g) : "", [b, C] = v(y), [w, T] = v(!1), [E, D] = v(!1), [O, k] = v(null), A = _(!1), j = _(y), M = _(y);
2668
+ M.current = y, m(() => {
2669
+ j.current !== y && (j.current = y, !w && !A.current && C(y));
2670
+ }, [y, w]), $e(n, e, () => {
2671
+ A.current = !1, C(M.current), D(!1), k(null), a(null);
2672
+ });
2673
+ let N = (e, t) => {
2674
+ let n = ft(e);
2675
+ if (n.kind !== "valid") return t && k("请输入有效数字"), !1;
2676
+ let i = pt(n.value, d, f, p);
2677
+ return i ? (t && k(i), !1) : (k(null), r(n.value));
2678
+ };
2679
+ return /* @__PURE__ */ S("div", {
2680
+ className: "md-control local-number",
2681
+ children: [
2682
+ /* @__PURE__ */ x("label", {
2683
+ className: "md-label",
2684
+ htmlFor: `${t}-number`,
2685
+ children: o
2686
+ }),
2687
+ /* @__PURE__ */ x("input", {
2688
+ id: `${t}-number`,
2689
+ className: "md-text-input",
2690
+ type: "text",
2691
+ inputMode: "decimal",
2692
+ value: b,
2693
+ disabled: s,
2694
+ "aria-invalid": O || i ? !0 : void 0,
2695
+ onFocus: () => T(!0),
2696
+ onBlur: () => {
2697
+ T(!1), D(!0), N(b, !0);
2698
+ },
2699
+ onChange: (e) => {
2700
+ let t = e.target.value;
2701
+ C(t), a(null), A.current || N(t, E);
2702
+ },
2703
+ onCompositionStart: () => {
2704
+ A.current = !0;
2705
+ },
2706
+ onCompositionEnd: (e) => {
2707
+ A.current = !1, N(e.currentTarget.value, E);
2708
+ }
2709
+ }),
2710
+ d !== void 0 || f !== void 0 || p !== void 0 ? /* @__PURE__ */ S("span", {
2711
+ className: "md-hint",
2712
+ children: [
2713
+ d === void 0 ? "" : `最小 ${d}`,
2714
+ d !== void 0 && f !== void 0 ? " · " : "",
2715
+ f === void 0 ? "" : `最大 ${f}`,
2716
+ p === void 0 ? "" : ` · 步长 ${p}`
2717
+ ]
2718
+ }) : null,
2719
+ /* @__PURE__ */ x($, { message: c ? "无法计算" : O ?? i })
2720
+ ]
2721
+ });
2722
+ }
2723
+ function ht({ node: e }) {
2724
+ let t = h(), { runtime: n } = G(), { write: r, error: i } = X(e), a = q(n, e, "label", "滑块"), { disabled: o, invalid: s } = Qe(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));
2725
+ return /* @__PURE__ */ S("div", {
2726
+ className: "md-control md-slider local-slider",
2727
+ children: [
2728
+ /* @__PURE__ */ S("label", {
2729
+ className: "md-label",
2730
+ htmlFor: `${t}-slider`,
2731
+ children: [/* @__PURE__ */ x("span", { children: a }), /* @__PURE__ */ x("span", {
2732
+ className: "md-slider-value",
2733
+ "aria-hidden": "true",
2734
+ children: f
2735
+ })]
2736
+ }),
2737
+ /* @__PURE__ */ x("input", {
2738
+ id: `${t}-slider`,
2739
+ type: "range",
2740
+ min: c,
2741
+ max: l,
2742
+ step: u,
2743
+ value: f,
2744
+ disabled: o,
2745
+ onChange: (e) => r(Number(e.target.value))
2746
+ }),
2747
+ /* @__PURE__ */ x($, { message: s ? "无法计算" : i })
2748
+ ]
2749
+ });
2750
+ }
2751
+ function gt({ node: e }) {
2752
+ let t = h(), { runtime: n } = G(), { write: r, error: i } = X(e), a = q(n, e, "label", "开关"), { disabled: o, invalid: s } = Qe(e), c = Y(n, e) === !0;
2753
+ return /* @__PURE__ */ S("div", {
2754
+ className: "md-control md-toggle local-toggle",
2755
+ children: [/* @__PURE__ */ S("label", {
2756
+ className: "md-toggle-label",
2757
+ htmlFor: `${t}-toggle`,
2758
+ children: [/* @__PURE__ */ x("input", {
2759
+ id: `${t}-toggle`,
2760
+ type: "checkbox",
2761
+ checked: c,
2762
+ disabled: o,
2763
+ onChange: (e) => r(e.target.checked)
2764
+ }), /* @__PURE__ */ x("span", { children: a })]
2765
+ }), /* @__PURE__ */ x($, { message: s ? "无法计算" : i })]
2766
+ });
2767
+ }
2768
+ function _t({ node: e }) {
2769
+ let t = h(), { runtime: n } = G(), { write: r, error: i } = X(e), a = q(n, e, "label", "勾选"), { disabled: o, invalid: s } = Qe(e), c = Y(n, e) === !0;
2770
+ return /* @__PURE__ */ S("div", {
2771
+ className: "md-control local-checkbox",
2772
+ children: [/* @__PURE__ */ S("label", {
2773
+ className: "md-toggle-label",
2774
+ htmlFor: `${t}-checkbox`,
2775
+ children: [/* @__PURE__ */ x("input", {
2776
+ id: `${t}-checkbox`,
2777
+ type: "checkbox",
2778
+ checked: c,
2779
+ disabled: o,
2780
+ onChange: (e) => r(e.target.checked)
2781
+ }), /* @__PURE__ */ x("span", { children: a })]
2782
+ }), /* @__PURE__ */ x($, { message: s ? "无法计算" : i })]
2783
+ });
2784
+ }
2785
+ function vt({ node: e }) {
2786
+ let t = h(), { runtime: n } = G(), { write: r, error: i } = X(e), a = q(n, e, "label", "日期"), { disabled: o, invalid: s } = Qe(e), c = Ye(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] = v(!1), g = p && c && f === "" ? "请选择日期" : null;
2787
+ return /* @__PURE__ */ S("div", {
2788
+ className: "md-control local-date",
2789
+ children: [
2790
+ /* @__PURE__ */ x("label", {
2791
+ className: "md-label",
2792
+ htmlFor: `${t}-date`,
2793
+ children: a
2794
+ }),
2795
+ /* @__PURE__ */ x("input", {
2796
+ id: `${t}-date`,
2797
+ className: "md-text-input",
2798
+ type: "date",
2799
+ value: f,
2800
+ min: l || void 0,
2801
+ max: u || void 0,
2802
+ required: c,
2803
+ disabled: o,
2804
+ "aria-invalid": g || i ? !0 : void 0,
2805
+ onBlur: () => m(!0),
2806
+ onChange: (e) => {
2807
+ m(!0), r(e.target.value);
2808
+ }
2809
+ }),
2810
+ /* @__PURE__ */ x($, { message: s ? "无法计算" : g ?? i })
2811
+ ]
2812
+ });
2813
+ }
2814
+ function yt(e) {
2815
+ return (e.children ?? []).filter((e) => e.type === "component" && e.name === "option").map((e, t) => ({
2816
+ value: K(e, "value") ?? `option-${t + 1}`,
2817
+ node: e
2818
+ }));
2819
+ }
2820
+ function bt(e, t) {
2821
+ if (!t) return "";
2822
+ let n = "";
2823
+ for (let r of t) if (r.type === "text" || r.type === "inlineCode") n += r.value ?? "";
2824
+ else if (r.type === "interpolation") try {
2825
+ n += qe(e.evaluate(r.value ?? "")) ?? "";
2826
+ } catch {
2827
+ n += "无法计算";
2828
+ }
2829
+ else r.type === "break" ? n += " " : n += bt(e, r.children);
2830
+ return n;
2831
+ }
2832
+ function xt(e, t) {
2833
+ return bt(e, t.children) || K(t, "value") || "";
2834
+ }
2835
+ function St() {
2836
+ return null;
2837
+ }
2838
+ function Ct({ node: e }) {
2839
+ let t = h(), { runtime: n } = G(), { write: r, error: i } = X(e), a = q(n, e, "label", "选择"), { disabled: o, invalid: s } = Qe(e), c = yt(e), l = Y(n, e), u = typeof l == "string" ? l : "", d = c.some((e) => e.value === u) ? u : c[0]?.value ?? "";
2840
+ return c.length === 0 ? /* @__PURE__ */ x(Z, { message: "缺少选项" }) : /* @__PURE__ */ S("div", {
2841
+ className: "md-control md-select local-select",
2842
+ children: [
2843
+ /* @__PURE__ */ x("label", {
2844
+ className: "md-label",
2845
+ htmlFor: `${t}-select`,
2846
+ children: a
2847
+ }),
2848
+ /* @__PURE__ */ x("select", {
2849
+ id: `${t}-select`,
2850
+ className: "md-select-input",
2851
+ value: d,
2852
+ disabled: o,
2853
+ onChange: (e) => r(e.target.value),
2854
+ children: c.map((e) => /* @__PURE__ */ x("option", {
2855
+ value: e.value,
2856
+ children: xt(n, e.node) || e.value
2857
+ }, e.node.id))
2858
+ }),
2859
+ /* @__PURE__ */ x($, { message: s ? "无法计算" : i })
2860
+ ]
2861
+ });
2862
+ }
2863
+ function wt({ node: e, visible: t }) {
2864
+ let n = h(), r = G(), { runtime: i } = r, { write: a, error: o } = X(e), s = q(i, e, "label", "选项"), { disabled: c, invalid: l } = Qe(e), u = yt(e), d = Y(i, e), f = typeof d == "string" ? d : "", p = u.findIndex((e) => e.value === f), m = p >= 0 ? p : 0, g = _([]);
2865
+ if (u.length === 0) return /* @__PURE__ */ x(Z, { message: "缺少选项" });
2866
+ let v = (e) => {
2867
+ let t = u[e];
2868
+ t && (a(t.value), g.current[e]?.focus());
2869
+ }, y = (e, t) => {
2870
+ let n = -1;
2871
+ 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(), v(n));
2872
+ };
2873
+ return /* @__PURE__ */ S("div", {
2874
+ className: "md-control local-choices",
2875
+ children: [
2876
+ /* @__PURE__ */ x("span", {
2877
+ className: "md-label",
2878
+ id: `${n}-choices-label`,
2879
+ children: s
2880
+ }),
2881
+ /* @__PURE__ */ x("div", {
2882
+ className: "local-choice-list",
2883
+ role: "radiogroup",
2884
+ "aria-labelledby": `${n}-choices-label`,
2885
+ "aria-disabled": c || void 0,
2886
+ children: u.map((e, n) => {
2887
+ let i = e.value === f;
2888
+ return /* @__PURE__ */ x("button", {
2889
+ ref: (e) => {
2890
+ g.current[n] = e;
2891
+ },
2892
+ type: "button",
2893
+ role: "radio",
2894
+ "aria-checked": i,
2895
+ tabIndex: n === m ? 0 : -1,
2896
+ disabled: c,
2897
+ className: `local-choice${i ? " is-selected" : ""}`,
2898
+ onClick: () => a(e.value),
2899
+ onKeyDown: (e) => y(e, n),
2900
+ children: it(r, e.node.children, t)
2901
+ }, e.node.id);
2902
+ })
2903
+ }),
2904
+ /* @__PURE__ */ x($, { message: l ? "无法计算" : o })
2905
+ ]
2906
+ });
2907
+ }
2908
+ function Tt({ node: e, visible: t }) {
2909
+ let n = h(), r = G(), { runtime: i } = r, { write: a, error: o } = X(e), s = q(i, e, "label", "选项"), { disabled: c, invalid: l } = Qe(e), u = yt(e), d = Y(i, e), f = typeof d == "string" ? d : "", p = n;
2910
+ return u.length === 0 ? /* @__PURE__ */ x(Z, { message: "缺少选项" }) : /* @__PURE__ */ S("fieldset", {
2911
+ className: "md-control local-radio-group",
2912
+ disabled: c,
2913
+ children: [
2914
+ /* @__PURE__ */ x("legend", {
2915
+ className: "md-label",
2916
+ children: s
2917
+ }),
2918
+ u.map((e) => /* @__PURE__ */ S("label", {
2919
+ className: "local-radio-option",
2920
+ children: [/* @__PURE__ */ x("input", {
2921
+ type: "radio",
2922
+ name: p,
2923
+ value: e.value,
2924
+ checked: f === e.value,
2925
+ onChange: () => a(e.value)
2926
+ }), /* @__PURE__ */ x("span", { children: it(r, e.node.children, t) })]
2927
+ }, e.node.id)),
2928
+ /* @__PURE__ */ x($, { message: l ? "无法计算" : o })
2929
+ ]
2930
+ });
2931
+ }
2932
+ function Et(e) {
2933
+ return ((e.children ?? []).find((e) => e.type === "list")?.children ?? []).filter((e) => e.type === "listItem").map((e, t) => ({
2934
+ id: `item-${t + 1}`,
2935
+ node: e
2936
+ }));
2937
+ }
2938
+ function Dt({ node: e, visible: t }) {
2939
+ let n = h(), r = G(), { runtime: i } = r, { write: a, error: o } = X(e), s = q(i, e, "label", "清单"), { disabled: c, invalid: l } = Qe(e), u = Et(e), d = Y(i, e), f = Array.isArray(d) ? d.filter((e) => typeof e == "string") : [];
2940
+ if (u.length === 0) return /* @__PURE__ */ x(Z, { message: "清单需要任务列表" });
2941
+ let p = (e, t) => {
2942
+ let n = new Set(f);
2943
+ t ? n.add(e) : n.delete(e), a(u.filter((e) => n.has(e.id)).map((e) => e.id));
2944
+ };
2945
+ return /* @__PURE__ */ S("fieldset", {
2946
+ className: "local-checklist",
2947
+ disabled: c,
2948
+ children: [
2949
+ /* @__PURE__ */ x("legend", {
2950
+ className: "md-label",
2951
+ children: s
2952
+ }),
2953
+ u.map((e) => /* @__PURE__ */ S("div", {
2954
+ className: "local-checklist-item",
2955
+ children: [/* @__PURE__ */ x("input", {
2956
+ id: `${n}-${e.id}`,
2957
+ type: "checkbox",
2958
+ checked: f.includes(e.id),
2959
+ onChange: (t) => p(e.id, t.target.checked)
2960
+ }), /* @__PURE__ */ x("label", {
2961
+ className: "local-checklist-text",
2962
+ htmlFor: `${n}-${e.id}`,
2963
+ children: it(r, e.node.children, t)
2964
+ })]
2965
+ }, e.id)),
2966
+ /* @__PURE__ */ x($, { message: l ? "无法计算" : o })
2967
+ ]
2968
+ });
2969
+ }
2970
+ function Ot(e) {
2971
+ let t = Math.max(0, Math.floor(e)), n = Math.floor(t / 60), r = t % 60;
2972
+ return n === 0 ? `${r} 秒` : `${n}:${String(r).padStart(2, "0")}`;
2973
+ }
2974
+ function kt({ node: e }) {
2975
+ let { runtime: t } = G(), { write: n, error: r } = X(e), i = q(t, e, "label", "计数"), { disabled: a, invalid: o } = Qe(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) => {
2976
+ let t = Number((d + e * f).toFixed(12));
2977
+ n(t);
2978
+ };
2979
+ return /* @__PURE__ */ S("div", {
2980
+ className: "local-counter",
2981
+ role: "group",
2982
+ "aria-label": i,
2983
+ children: [
2984
+ /* @__PURE__ */ x("span", {
2985
+ className: "md-label",
2986
+ children: i
2987
+ }),
2988
+ /* @__PURE__ */ S("div", {
2989
+ className: "local-counter-row",
2990
+ children: [
2991
+ /* @__PURE__ */ x("button", {
2992
+ type: "button",
2993
+ className: "md-button md-button-secondary local-counter-button",
2994
+ "aria-label": `${i} 减少`,
2995
+ disabled: a || !m,
2996
+ onClick: () => g(-1),
2997
+ children: "−"
2998
+ }),
2999
+ /* @__PURE__ */ x("span", {
3000
+ className: "local-counter-value",
3001
+ "aria-live": "polite",
3002
+ children: d
3003
+ }),
3004
+ /* @__PURE__ */ x("button", {
3005
+ type: "button",
3006
+ className: "md-button md-button-secondary local-counter-button",
3007
+ "aria-label": `${i} 增加`,
3008
+ disabled: a || !h,
3009
+ onClick: () => g(1),
3010
+ children: "+"
3011
+ }),
3012
+ /* @__PURE__ */ x("button", {
3013
+ type: "button",
3014
+ className: "md-button md-button-quiet local-counter-reset",
3015
+ disabled: a,
3016
+ onClick: () => {
3017
+ try {
3018
+ t.reset(e);
3019
+ } catch {}
3020
+ },
3021
+ children: "恢复初值"
3022
+ })
3023
+ ]
3024
+ }),
3025
+ /* @__PURE__ */ x($, { message: o ? "无法计算" : r })
3026
+ ]
3027
+ });
3028
+ }
3029
+ function At({ node: e, visible: t }) {
3030
+ 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] = v(!1), [u, d] = v(!1), p = _(0), h = _(s);
3031
+ h.current = s;
3032
+ let [g, y] = v(null), b = f((t) => {
3033
+ try {
3034
+ let r = n.set(e, t);
3035
+ r.length && y(r.map((e) => e.message).join(";"));
3036
+ } catch {}
3037
+ }, [e, n]);
3038
+ return m(() => {
3039
+ if (!c) return;
3040
+ let e = window.setInterval(() => {
3041
+ let e = Math.max(0, Math.ceil((p.current - performance.now()) / 1e3));
3042
+ e !== h.current && (h.current = e, b(e)), e <= 0 && (l(!1), d(!0));
3043
+ }, 200);
3044
+ return () => window.clearInterval(e);
3045
+ }, [c, b]), m(() => {
3046
+ if (t || !c) return;
3047
+ let e = Math.max(0, Math.ceil((p.current - performance.now()) / 1e3));
3048
+ h.current = e, b(e), l(!1);
3049
+ }, [
3050
+ t,
3051
+ c,
3052
+ b
3053
+ ]), $e(n, e, () => {
3054
+ l(!1), d(!1), y(null);
3055
+ }), !Number.isFinite(i) || a <= 0 ? /* @__PURE__ */ x(Z, { message: "计时时长必须是大于 0 的秒数" }) : /* @__PURE__ */ S("div", {
3056
+ className: "local-timer",
3057
+ role: "group",
3058
+ "aria-label": r,
3059
+ children: [
3060
+ /* @__PURE__ */ S("div", {
3061
+ className: "local-timer-head",
3062
+ children: [/* @__PURE__ */ x("span", {
3063
+ className: "md-label",
3064
+ children: r
3065
+ }), /* @__PURE__ */ x("span", {
3066
+ className: "local-timer-value",
3067
+ role: "timer",
3068
+ "aria-label": `剩余 ${s} 秒`,
3069
+ children: Ot(s)
3070
+ })]
3071
+ }),
3072
+ /* @__PURE__ */ S("div", {
3073
+ className: "local-timer-controls",
3074
+ children: [
3075
+ /* @__PURE__ */ x("button", {
3076
+ type: "button",
3077
+ className: "md-button md-button-primary",
3078
+ onClick: () => {
3079
+ if (c) return;
3080
+ let e = s > 0 ? s : a;
3081
+ s <= 0 && (h.current = a, b(a)), p.current = performance.now() + e * 1e3, d(!1), y(null), l(!0);
3082
+ },
3083
+ disabled: c,
3084
+ children: "开始"
3085
+ }),
3086
+ /* @__PURE__ */ x("button", {
3087
+ type: "button",
3088
+ className: "md-button md-button-secondary",
3089
+ onClick: () => {
3090
+ if (!c) return;
3091
+ let e = Math.max(0, Math.ceil((p.current - performance.now()) / 1e3));
3092
+ h.current = e, b(e), l(!1);
3093
+ },
3094
+ disabled: !c,
3095
+ children: "暂停"
3096
+ }),
3097
+ /* @__PURE__ */ x("button", {
3098
+ type: "button",
3099
+ className: "md-button md-button-quiet",
3100
+ onClick: () => {
3101
+ l(!1), d(!1), y(null), h.current = a;
3102
+ try {
3103
+ n.reset(e);
3104
+ } catch {}
3105
+ },
3106
+ children: "重置"
3107
+ })
3108
+ ]
3109
+ }),
3110
+ /* @__PURE__ */ x("span", {
3111
+ className: "local-timer-status",
3112
+ role: "status",
3113
+ "aria-live": "polite",
3114
+ children: u ? "计时完成" : c ? "计时中" : "已暂停"
3115
+ }),
3116
+ /* @__PURE__ */ x($, { message: g })
3117
+ ]
3118
+ });
3119
+ }
3120
+ function jt({ node: e }) {
3121
+ let { runtime: t } = G(), n = q(t, e, "label", "进度"), r = J(t, e, "max", 100), i = Ke(t, e, "value");
3122
+ if (!Number.isFinite(r) || r <= 0) return /* @__PURE__ */ x(Z, { message: "进度上限必须是正数" });
3123
+ if (!i.present || !i.ok) return /* @__PURE__ */ x(Z, {});
3124
+ let a = i.value, o = typeof a == "number" ? a : typeof a == "string" && a.trim() !== "" ? Number(a) : NaN;
3125
+ if (!Number.isFinite(o)) return /* @__PURE__ */ x(Z, {});
3126
+ if (o < 0 || o > r) return /* @__PURE__ */ x(Z, { message: `进度值需要在 0 到 ${r} 之间` });
3127
+ let s = o / r * 100;
3128
+ return /* @__PURE__ */ S("div", {
3129
+ className: "local-progress",
3130
+ children: [/* @__PURE__ */ S("div", {
3131
+ className: "local-progress-head",
3132
+ children: [/* @__PURE__ */ x("span", {
3133
+ className: "md-label",
3134
+ children: n
3135
+ }), /* @__PURE__ */ S("span", {
3136
+ className: "local-progress-value",
3137
+ children: [Math.round(s), "%"]
3138
+ })]
3139
+ }), /* @__PURE__ */ x("div", {
3140
+ className: "local-progress-track",
3141
+ role: "progressbar",
3142
+ "aria-label": n || "进度",
3143
+ "aria-valuemin": 0,
3144
+ "aria-valuemax": r,
3145
+ "aria-valuenow": o,
3146
+ children: /* @__PURE__ */ x("div", {
3147
+ className: "local-progress-fill",
3148
+ style: { width: `${s}%` }
3149
+ })
3150
+ })]
3151
+ });
3152
+ }
3153
+ function Mt({ node: e, visible: t }) {
3154
+ let { runtime: n, render: r } = G(), i = q(n, e, "title", ""), a = Ye(n, e, "reset", !0), [o, s] = v(null);
3155
+ return /* @__PURE__ */ S("section", {
3156
+ className: "local-panel",
3157
+ "aria-label": i || "参数面板",
3158
+ children: [
3159
+ i || a ? /* @__PURE__ */ S("div", {
3160
+ className: "local-panel-head",
3161
+ children: [i ? /* @__PURE__ */ x("h3", {
3162
+ className: "local-panel-title",
3163
+ children: i
3164
+ }) : /* @__PURE__ */ x("span", {}), a ? /* @__PURE__ */ x("button", {
3165
+ type: "button",
3166
+ className: "md-button md-button-quiet local-panel-reset",
3167
+ onClick: () => {
3168
+ try {
3169
+ n.reset(e), s(null);
3170
+ } catch (e) {
3171
+ s(e instanceof Error ? e.message : "无法恢复默认");
3172
+ }
3173
+ },
3174
+ "aria-label": i ? `${i} 恢复默认` : "恢复默认",
3175
+ children: "恢复默认"
3176
+ }) : null]
3177
+ }) : null,
3178
+ /* @__PURE__ */ x("div", {
3179
+ className: "local-panel-body",
3180
+ children: r(e.children ?? [], t)
3181
+ }),
3182
+ /* @__PURE__ */ x($, { message: o })
3183
+ ]
3184
+ });
3185
+ }
3186
+ function Nt({ node: e, visible: t }) {
3187
+ let { runtime: n, render: r } = G(), i = q(n, e, "title", "");
3188
+ return /* @__PURE__ */ S("section", {
3189
+ className: "md-card local-card",
3190
+ children: [i ? /* @__PURE__ */ x("h3", {
3191
+ className: "md-card-title",
3192
+ children: i
3193
+ }) : null, /* @__PURE__ */ x("div", {
3194
+ className: "md-card-body",
3195
+ children: r(e.children ?? [], t)
3196
+ })]
3197
+ });
3198
+ }
3199
+ function Pt({ node: e, visible: t }) {
3200
+ let { runtime: n, render: r } = G(), i = Math.min(4, Math.max(1, Math.floor(J(n, e, "columns", 2))));
3201
+ return /* @__PURE__ */ x("div", {
3202
+ className: "local-grid",
3203
+ style: { "--local-grid-columns": String(i) },
3204
+ children: r(e.children ?? [], t)
3205
+ });
3206
+ }
3207
+ function Ft({ node: e, visible: t }) {
3208
+ let { render: n } = G();
3209
+ return /* @__PURE__ */ x("div", {
3210
+ className: "local-tabpanel-body",
3211
+ children: n(e.children ?? [], t)
3212
+ });
3213
+ }
3214
+ function It() {
3215
+ return null;
3216
+ }
3217
+ function Lt({ node: e, visible: t }) {
3218
+ let n = h(), { 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 : "", [g, y] = v(() => l.includes(d) ? d : l[0] ?? ""), b = _([]);
3219
+ if ($e(r, e, () => {
3220
+ y(l.includes(d) ? d : l[0] ?? "");
3221
+ }), c.length === 0) return /* @__PURE__ */ x(Z, { message: "标签页至少需要一个 tab" });
3222
+ let C = f ? l.includes(m) ? m : l[0] : l.includes(g) ? g : l[0], w = Math.max(0, l.indexOf(C)), T = (e) => {
3223
+ let t = l[e];
3224
+ t !== void 0 && (f ? a(t) : y(t), b.current[e]?.focus());
3225
+ };
3226
+ return /* @__PURE__ */ S("section", {
3227
+ className: "local-tabs",
3228
+ "aria-label": s || "选项卡",
3229
+ children: [
3230
+ s ? /* @__PURE__ */ x("div", {
3231
+ className: "local-tabs-label",
3232
+ children: s
3233
+ }) : null,
3234
+ /* @__PURE__ */ x("div", {
3235
+ className: "local-tablist",
3236
+ role: "tablist",
3237
+ "aria-label": s || "选项卡",
3238
+ onKeyDown: (e) => {
3239
+ let t = -1;
3240
+ 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));
3241
+ },
3242
+ children: c.map((e, t) => {
3243
+ let r = l[t], i = r === C;
3244
+ return /* @__PURE__ */ x("button", {
3245
+ ref: (e) => {
3246
+ b.current[t] = e;
3247
+ },
3248
+ id: `${n}-tab-${t}`,
3249
+ type: "button",
3250
+ role: "tab",
3251
+ className: `local-tab${i ? " is-selected" : ""}`,
3252
+ "aria-selected": i,
3253
+ "aria-controls": `${n}-panel-${t}`,
3254
+ tabIndex: i ? 0 : -1,
3255
+ onClick: () => {
3256
+ f ? a(r) : y(r);
3257
+ },
3258
+ children: u[t]
3259
+ }, e.id);
3260
+ })
3261
+ }),
3262
+ c.map((e, r) => {
3263
+ let a = l[r] === C;
3264
+ return /* @__PURE__ */ x("div", {
3265
+ id: `${n}-panel-${r}`,
3266
+ className: "local-tabpanel",
3267
+ role: "tabpanel",
3268
+ "aria-labelledby": `${n}-tab-${r}`,
3269
+ tabIndex: 0,
3270
+ hidden: !a,
3271
+ children: i(e.children ?? [], t && a)
3272
+ }, e.id);
3273
+ }),
3274
+ /* @__PURE__ */ x($, { message: o })
3275
+ ]
3276
+ });
3277
+ }
3278
+ function Rt({ node: e, visible: t }) {
3279
+ let { runtime: n, render: r } = G(), i = q(n, e, "label", "");
3280
+ return /* @__PURE__ */ S("div", {
3281
+ className: "local-accordion",
3282
+ role: "group",
3283
+ "aria-label": i || "折叠面板",
3284
+ children: [i ? /* @__PURE__ */ x("div", {
3285
+ className: "local-accordion-label",
3286
+ children: i
3287
+ }) : null, r(e.children ?? [], t)]
3288
+ });
3289
+ }
3290
+ function zt({ node: e, visible: t }) {
3291
+ let n = h(), { runtime: r, render: i } = G(), a = q(r, e, "label", "折叠内容"), o = Ye(r, e, "open", !1), [s, c] = v(o);
3292
+ $e(r, e, () => {
3293
+ c(o);
3294
+ });
3295
+ let l = `${n}-disclosure-trigger`, u = `${n}-disclosure-panel`;
3296
+ return /* @__PURE__ */ S("div", {
3297
+ className: "local-disclosure",
3298
+ children: [/* @__PURE__ */ x("h3", {
3299
+ className: "local-disclosure-heading",
3300
+ children: /* @__PURE__ */ S("button", {
3301
+ id: l,
3302
+ type: "button",
3303
+ className: "local-disclosure-trigger",
3304
+ "aria-expanded": s,
3305
+ "aria-controls": u,
3306
+ onClick: () => c((e) => !e),
3307
+ children: [/* @__PURE__ */ x("span", {
3308
+ className: `local-chevron${s ? " is-open" : ""}`,
3309
+ "aria-hidden": "true",
3310
+ children: "▸"
3311
+ }), /* @__PURE__ */ x("span", { children: a })]
3312
+ })
3313
+ }), /* @__PURE__ */ x("div", {
3314
+ id: u,
3315
+ className: "local-disclosure-panel",
3316
+ role: "region",
3317
+ "aria-labelledby": l,
3318
+ hidden: !s,
3319
+ children: i(e.children ?? [], t && s)
3320
+ })]
3321
+ });
3322
+ }
3323
+ function Bt({ node: e, visible: t }) {
3324
+ let { runtime: n, render: r } = G(), i = Je(n, e, "when", !1), a = i.ok ? i.value : !1, o = !i.ok, s = _(null), c = _(a), l = _(!1);
3325
+ return m(() => {
3326
+ if (c.current && !a) {
3327
+ if (l.current) {
3328
+ let e = s.current?.closest(".local-document");
3329
+ e && (e.tabIndex = -1, e.focus({ preventScroll: !0 }));
3330
+ }
3331
+ l.current = !1;
3332
+ }
3333
+ c.current = a;
3334
+ }, [a]), /* @__PURE__ */ S(b, { children: [o ? /* @__PURE__ */ x(Z, {}) : null, /* @__PURE__ */ x("div", {
3335
+ ref: s,
3336
+ className: "local-if md-if",
3337
+ role: "group",
3338
+ "aria-label": "条件内容",
3339
+ tabIndex: -1,
3340
+ hidden: !a,
3341
+ "aria-hidden": !a,
3342
+ onFocus: () => {
3343
+ l.current = !0;
3344
+ },
3345
+ onBlur: (e) => {
3346
+ s.current?.contains(e.relatedTarget) || (l.current = !1);
3347
+ },
3348
+ children: r(e.children ?? [], t && a)
3349
+ })] });
3350
+ }
3351
+ function Vt({ node: e, visible: t }) {
3352
+ 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";
3353
+ return /* @__PURE__ */ S("div", {
3354
+ className: `local-alert local-alert-${o}`,
3355
+ role: s,
3356
+ children: [i ? /* @__PURE__ */ x("div", {
3357
+ className: "local-alert-title",
3358
+ children: i
3359
+ }) : null, /* @__PURE__ */ x("div", {
3360
+ className: "local-alert-body",
3361
+ children: r(e.children ?? [], t)
3362
+ })]
3363
+ });
3364
+ }
3365
+ function Ht({ node: e, visible: t }) {
3366
+ let n = G(), { runtime: r } = n, i = K(e, "tone") ?? "neutral";
3367
+ return /* @__PURE__ */ x("span", {
3368
+ className: `md-badge md-badge-${i === "success" || i === "warning" ? i : "neutral"} local-badge`,
3369
+ children: it(n, e.children, t)
3370
+ });
3371
+ }
3372
+ function Ut({ node: e, visible: t }) {
3373
+ let n = h(), r = G(), { runtime: i } = r, a = q(i, e, "text", "提示"), [o, s] = v(!1), c = `${n}-tooltip`;
3374
+ return /* @__PURE__ */ S("span", {
3375
+ className: "local-tooltip",
3376
+ onMouseEnter: () => s(!0),
3377
+ onMouseLeave: () => s(!1),
3378
+ children: [/* @__PURE__ */ x("span", {
3379
+ className: "local-tooltip-trigger",
3380
+ tabIndex: 0,
3381
+ "aria-describedby": c,
3382
+ onFocus: () => s(!0),
3383
+ onBlur: () => s(!1),
3384
+ onKeyDown: (e) => {
3385
+ e.key === "Escape" && (e.stopPropagation(), s(!1));
3386
+ },
3387
+ children: it(r, e.children, t)
3388
+ }), /* @__PURE__ */ x("span", {
3389
+ id: c,
3390
+ role: "tooltip",
3391
+ className: `local-tooltip-bubble${o ? " is-visible" : ""}`,
3392
+ children: a
3393
+ })]
3394
+ });
3395
+ }
3396
+ var Wt = {
3397
+ panel: Mt,
3398
+ card: Nt,
3399
+ grid: Pt,
3400
+ tabs: Lt,
3401
+ tab: Ft,
3402
+ accordion: Rt,
3403
+ disclosure: zt,
3404
+ if: Bt,
3405
+ alert: Vt,
3406
+ badge: Ht,
3407
+ tooltip: Ut,
3408
+ input: ut,
3409
+ textarea: dt,
3410
+ number: mt,
3411
+ slider: ht,
3412
+ toggle: gt,
3413
+ checkbox: _t,
3414
+ date: vt,
3415
+ select: Ct,
3416
+ choices: wt,
3417
+ "radio-group": Tt,
3418
+ option: St,
3419
+ node: Ft,
3420
+ edge: It,
3421
+ counter: kt,
3422
+ timer: At,
3423
+ checklist: Dt,
3424
+ progress: jt
3425
+ };
3426
+ function Gt({ document: e, runtime: t, onDiagnostics: n, urlPolicy: r }) {
3427
+ let i = _(n);
3428
+ i.current = n;
3429
+ let a = f((e) => {
3430
+ i.current?.(e);
3431
+ }, []), o = f((e) => {
3432
+ try {
3433
+ return t.subscribe(e);
3434
+ } catch {
3435
+ return () => {};
3436
+ }
3437
+ }, [t]), s = f(() => {
3438
+ try {
3439
+ return t.snapshot();
3440
+ } catch {
3441
+ return Ge;
3442
+ }
3443
+ }, [t]);
3444
+ y(o, s, s);
3445
+ let c = {
3446
+ runtime: t,
3447
+ urlPolicy: r
3448
+ }, l = (e, n = !0) => /* @__PURE__ */ x(Ue.Provider, {
3449
+ value: {
3450
+ runtime: t,
3451
+ render: l,
3452
+ visible: n,
3453
+ report: a,
3454
+ urlPolicy: r
3455
+ },
3456
+ children: Q(c, e ?? [], n)
3457
+ });
3458
+ return /* @__PURE__ */ x("article", {
3459
+ className: "md-document local-document",
3460
+ "aria-label": "交互文档",
3461
+ children: l(e.nodes, !0)
3462
+ });
3463
+ }
3464
+ function Kt({ source: e, onDiagnostics: t, urlPolicy: n }) {
3465
+ let r = g(() => a(e), [e]), i = g(() => {
3466
+ if (!r.ok) return null;
3467
+ try {
3468
+ return s(r.document);
3469
+ } catch {
3470
+ return null;
3471
+ }
3472
+ }, [r]), o = _(t);
3473
+ o.current = t;
3474
+ let c = _(i);
3475
+ c.current = i;
3476
+ let l = _(0);
3477
+ return m(() => (l.current += 1, () => {
3478
+ --l.current;
3479
+ }), []), m(() => {
3480
+ o.current?.(r.diagnostics);
3481
+ }, [r]), m(() => {
3482
+ let e = i;
3483
+ return () => {
3484
+ queueMicrotask(() => {
3485
+ if (!(c.current === e && l.current > 0)) try {
3486
+ e?.dispose();
3487
+ } catch {}
3488
+ });
3489
+ };
3490
+ }, [i]), !r.ok || !i ? /* @__PURE__ */ S("div", {
3491
+ className: "md-document local-document local-inactive",
3492
+ role: "alert",
3493
+ children: [/* @__PURE__ */ x("p", {
3494
+ className: "local-inactive-title",
3495
+ children: r.ok ? "交互初始化失败,预览已停用。" : "文档包含语法错误,交互预览已停用。"
3496
+ }), r.diagnostics.length ? /* @__PURE__ */ x("ul", {
3497
+ className: "local-inactive-list",
3498
+ children: r.diagnostics.map((e, t) => /* @__PURE__ */ S("li", { children: [
3499
+ e.message,
3500
+ "(第 ",
3501
+ e.line,
3502
+ " 行,第 ",
3503
+ e.column,
3504
+ " 列)"
3505
+ ] }, `${e.code}-${t}`))
3506
+ }) : null]
3507
+ }) : /* @__PURE__ */ x(Gt, {
3508
+ document: r.document,
3509
+ runtime: i,
3510
+ onDiagnostics: t,
3511
+ urlPolicy: n
3512
+ }, e);
3513
+ }
3514
+ export { Gt as LocalDocumentView, Kt as LocalReactiveDocument };