reactive-md 0.3.1 → 0.4.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.
- package/CHANGELOG-ch.md +96 -0
- package/CHANGELOG.md +82 -39
- package/CONTRIBUTING-ch.md +62 -0
- package/CONTRIBUTING.md +64 -65
- package/README-ch.md +122 -0
- package/README-en.md +146 -0
- package/README.md +146 -89
- package/SECURITY-ch.md +80 -0
- package/SECURITY.md +58 -49
- package/THIRD_PARTY_NOTICES.md +85 -1
- package/bin/reactive-md.mjs +40 -0
- package/cli/args.mjs +181 -0
- package/cli/assets.mjs +390 -0
- package/cli/build.mjs +268 -0
- package/cli/document.mjs +130 -0
- package/cli/errors.mjs +61 -0
- package/cli/fs-utils.mjs +133 -0
- package/cli/glob.mjs +203 -0
- package/cli/help.mjs +138 -0
- package/cli/lint.mjs +177 -0
- package/cli/main.mjs +55 -0
- package/cli/migrate.mjs +368 -0
- package/cli/package.mjs +209 -0
- package/dist-library/reactive-md-react.js +3425 -1647
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +1798 -4
- package/dist-library/runtime-DtjdPXxJ.js +15410 -0
- package/dist-library/types/index.d.ts +1 -0
- package/dist-library/types/local/LocalDocumentView.d.ts +66 -3
- package/dist-library/types/local/authoring.d.ts +63 -0
- package/dist-library/types/local/collection-functions.d.ts +4 -0
- package/dist-library/types/local/colors.d.ts +2 -0
- package/dist-library/types/local/computations.d.ts +53 -0
- package/dist-library/types/local/data-functions.d.ts +22 -0
- package/dist-library/types/local/data-table.d.ts +65 -0
- package/dist-library/types/local/dates.d.ts +2 -0
- package/dist-library/types/local/dependencies.d.ts +31 -0
- package/dist-library/types/local/diagnostics.d.ts +1450 -0
- package/dist-library/types/local/expression.d.ts +13 -3
- package/dist-library/types/local/formatting.d.ts +41 -0
- package/dist-library/types/local/heading-anchors.d.ts +13 -2
- package/dist-library/types/local/i18n.d.ts +18 -0
- package/dist-library/types/local/index.d.ts +18 -1
- package/dist-library/types/local/limits.d.ts +32 -1
- package/dist-library/types/local/locale.d.ts +1 -0
- package/dist-library/types/local/math.d.ts +6 -1
- package/dist-library/types/local/parser.d.ts +10 -4
- package/dist-library/types/local/render-types.d.ts +5 -1
- package/dist-library/types/local/retention.d.ts +23 -0
- package/dist-library/types/local/schema.d.ts +25 -3
- package/dist-library/types/local/source-migration.d.ts +35 -0
- package/dist-library/types/local/state.d.ts +80 -0
- package/dist-library/types/local/text-length.d.ts +13 -0
- package/dist-library/types/local/theme.d.ts +30 -0
- package/dist-library/types/local/types.d.ts +112 -4
- package/dist-library/types/local/validation.d.ts +32 -0
- package/dist-library/types/local/version.d.ts +1 -1
- package/dist-library/types/local/worker.d.ts +82 -0
- package/dist-library/types/react/index.d.ts +4 -1
- package/dist-library/types/shareable.d.ts +64 -0
- package/dist-standalone/reactive-md-standalone.css +2 -0
- package/dist-standalone/reactive-md-standalone.js +57 -0
- package/docs/author-tools-ch.md +56 -0
- package/docs/author-tools-en.md +56 -0
- package/docs/compatibility-ch.md +103 -0
- package/docs/compatibility-en.md +103 -0
- package/docs/{component-development.md → component-development-ch.md} +210 -206
- package/docs/component-development-en.md +210 -0
- package/docs/{component-protocol.md → component-protocol-ch.md} +710 -685
- package/docs/component-protocol-en.md +710 -0
- package/docs/computations-formatting-ch.md +87 -0
- package/docs/computations-formatting-en.md +87 -0
- package/docs/constraints-collections-ch.md +84 -0
- package/docs/constraints-collections-en.md +84 -0
- package/docs/diagnostics-counting-ch.md +84 -0
- package/docs/diagnostics-counting-en.md +84 -0
- package/docs/local-components-v2-ch.md +138 -0
- package/docs/local-components-v2-en.md +104 -0
- package/docs/{local-guide.md → local-guide-ch.md} +28 -8
- package/docs/local-guide-en.md +961 -0
- package/docs/local-integration-ch.md +363 -0
- package/docs/local-integration-en.md +363 -0
- package/docs/{local-interaction-syntax.md → local-interaction-syntax-ch.md} +66 -20
- package/docs/local-interaction-syntax-en.md +483 -0
- package/docs/{performance.md → performance-ch.md} +12 -3
- package/docs/performance-en.md +76 -0
- package/docs/release-0.4.0-ch.md +89 -0
- package/docs/release-0.4.0-en.md +89 -0
- package/docs/releasing-ch.md +101 -0
- package/docs/releasing-en.md +101 -0
- package/docs/shareable-export-ch.md +205 -0
- package/docs/shareable-export-en.md +207 -0
- package/docs/source-versioning-ch.md +159 -0
- package/docs/source-versioning-en.md +159 -0
- package/docs/theme-protocol-ch.md +107 -0
- package/docs/theme-protocol-en.md +107 -0
- package/examples/conformance/README.md +33 -31
- package/examples/conformance/component-protocol-1.json +482 -194
- package/examples/conformance/component-protocol-1.schema.json +76 -76
- package/examples/conformance/history/v0.3.1/catalog.reactive.md +20 -0
- package/examples/conformance/history/v0.3.1/charts.reactive.md +73 -0
- package/examples/conformance/history/v0.3.1/checklist.reactive.md +32 -0
- package/examples/conformance/history/v0.3.1/comparison.reactive.md +47 -0
- package/examples/conformance/history/v0.3.1/components.reactive.md +44 -0
- package/examples/conformance/history/v0.3.1/counter.reactive.md +7 -0
- package/examples/conformance/history/v0.3.1/diagnostics.reactive.md +54 -0
- package/examples/conformance/history/v0.3.1/diagram.reactive.md +44 -0
- package/examples/conformance/history/v0.3.1/gallery.reactive.md +61 -0
- package/examples/conformance/history/v0.3.1/local-draft-1.json +50 -0
- package/examples/conformance/history/v0.3.1/parameters.reactive.md +36 -0
- package/examples/conformance/history/v0.3.1/planning.reactive.md +24 -0
- package/examples/conformance/history/v0.3.1/pricing.reactive.md +20 -0
- package/examples/conformance/history/v0.3.1/provenance.json +72 -0
- package/examples/conformance/local-draft-2.json +212 -0
- package/examples/integration/README.md +45 -29
- package/examples/integration/core/index.mjs +32 -19
- package/examples/integration/react/index.html +1 -1
- package/examples/integration/react/main.jsx +5 -5
- package/examples/integration/worker/index.html +19 -0
- package/examples/integration/worker/main.js +61 -0
- package/examples/integration/worker/package.json +13 -0
- package/examples/integration/worker/worker.js +3 -0
- package/examples/local/README.md +64 -58
- package/examples/local/catalog.reactive.md +14 -14
- package/examples/local/charts.reactive.md +34 -34
- package/examples/local/checklist.reactive.md +19 -19
- package/examples/local/comparison.reactive.md +23 -23
- package/examples/local/components.reactive.md +20 -20
- package/examples/local/counter.reactive.md +4 -4
- package/examples/local/diagnostics.reactive.md +25 -25
- package/examples/local/diagram.reactive.md +20 -20
- package/examples/local/gallery.reactive.md +31 -31
- package/examples/local/parameters.reactive.md +19 -19
- package/examples/local/planning.reactive.md +15 -15
- package/examples/local/pricing.reactive.md +10 -10
- package/examples/local/recipes/invoice-zh.reactive.md +36 -0
- package/examples/local/recipes/invoice.reactive.md +36 -0
- package/examples/local/recipes/workshop-zh.reactive.md +33 -0
- package/examples/local/recipes/workshop.reactive.md +33 -0
- package/examples/local/showcase/README.md +25 -0
- package/examples/local/showcase/explore.reactive.md +102 -0
- package/examples/local/showcase/flow.reactive.md +86 -0
- package/examples/local/showcase/forms.reactive.md +126 -0
- package/examples/local/showcase/functions.reactive.md +119 -0
- package/examples/local/showcase/layout.reactive.md +100 -0
- package/examples/local/showcase/statistics.reactive.md +108 -0
- package/examples/local/showcase/tasks.reactive.md +89 -0
- package/examples/local/showcase/zh/explore.reactive.md +102 -0
- package/examples/local/showcase/zh/flow.reactive.md +86 -0
- package/examples/local/showcase/zh/forms.reactive.md +126 -0
- package/examples/local/showcase/zh/functions.reactive.md +119 -0
- package/examples/local/showcase/zh/layout.reactive.md +100 -0
- package/examples/local/showcase/zh/statistics.reactive.md +108 -0
- package/examples/local/showcase/zh/tasks.reactive.md +89 -0
- package/examples/local/zh/catalog.reactive.md +20 -0
- package/examples/local/zh/charts.reactive.md +73 -0
- package/examples/local/zh/checklist.reactive.md +32 -0
- package/examples/local/zh/comparison.reactive.md +47 -0
- package/examples/local/zh/components.reactive.md +44 -0
- package/examples/local/zh/counter.reactive.md +7 -0
- package/examples/local/zh/diagnostics.reactive.md +54 -0
- package/examples/local/zh/diagram.reactive.md +44 -0
- package/examples/local/zh/gallery.reactive.md +61 -0
- package/examples/local/zh/parameters.reactive.md +36 -0
- package/examples/local/zh/planning.reactive.md +24 -0
- package/examples/local/zh/pricing.reactive.md +20 -0
- package/package.json +16 -3
- package/README.en.md +0 -76
- package/dist-library/runtime-CPzMEMcW.js +0 -11111
- package/docs/compatibility.md +0 -68
- package/docs/local-integration.md +0 -218
- package/docs/releasing.md +0 -92
|
@@ -1,4 +1,1798 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// src/local/
|
|
3
|
-
var
|
|
4
|
-
|
|
1
|
+
import { C as e, D as t, E as n, O as r, S as i, T as a, _ as o, a as s, b as c, c as l, g as u, i as d, j as f, k as p, l as m, n as h, o as ee, r as g, s as te, t as _, u as v, v as ne, w as re, x as ie, y as ae } from "./runtime-DtjdPXxJ.js";
|
|
2
|
+
// src/local/authoring.ts
|
|
3
|
+
var oe = /^[A-Za-z_][A-Za-z0-9_]*$/, se = 128, ce = /* @__PURE__ */ new Set([
|
|
4
|
+
"code",
|
|
5
|
+
"inlineCode",
|
|
6
|
+
"math",
|
|
7
|
+
"inlineMath",
|
|
8
|
+
"fallback",
|
|
9
|
+
"comment"
|
|
10
|
+
]), le = /* @__PURE__ */ new Set([
|
|
11
|
+
"local.version.unsupported",
|
|
12
|
+
"local.version.malformed",
|
|
13
|
+
"local.version.duplicate",
|
|
14
|
+
"local.version.placement",
|
|
15
|
+
"local.parse",
|
|
16
|
+
"local.interpolation",
|
|
17
|
+
"local.tag.unclosed",
|
|
18
|
+
"local.tag.mismatch",
|
|
19
|
+
"local.tag.closing",
|
|
20
|
+
"local.tag.shape",
|
|
21
|
+
"local.attribute",
|
|
22
|
+
"local.budget"
|
|
23
|
+
]);
|
|
24
|
+
function y(e) {
|
|
25
|
+
return e !== void 0 && /[A-Za-z_]/.test(e);
|
|
26
|
+
}
|
|
27
|
+
function b(e) {
|
|
28
|
+
return e !== void 0 && /[A-Za-z0-9_]/.test(e);
|
|
29
|
+
}
|
|
30
|
+
function x(e) {
|
|
31
|
+
return e !== void 0 && /\s/.test(e);
|
|
32
|
+
}
|
|
33
|
+
function S(e) {
|
|
34
|
+
return e.length > 0 && e.length <= se && oe.test(e) && !c.has(e);
|
|
35
|
+
}
|
|
36
|
+
function C(e) {
|
|
37
|
+
return {
|
|
38
|
+
start: e.start,
|
|
39
|
+
end: e.end
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function ue(e) {
|
|
43
|
+
try {
|
|
44
|
+
return h(e).diagnostics;
|
|
45
|
+
} catch {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var de = /^<(\/?)([A-Za-z][A-Za-z0-9_-]*)(?=[\s/>])/;
|
|
50
|
+
function w(e, t) {
|
|
51
|
+
if (e[t] !== "<") return null;
|
|
52
|
+
let n = de.exec(e.slice(t));
|
|
53
|
+
if (!n) return null;
|
|
54
|
+
let r = !!n[1], i = n[2], a = t + (r ? 2 : 1), o = "", s = t + n[0].length;
|
|
55
|
+
for (; s < e.length; s += 1) {
|
|
56
|
+
let t = e[s];
|
|
57
|
+
if (o) t === o && (o = "");
|
|
58
|
+
else if (t === "\"" || t === "'") o = t;
|
|
59
|
+
else if (t === ">") break;
|
|
60
|
+
}
|
|
61
|
+
if (s >= e.length) return null;
|
|
62
|
+
let c = s, l = s + 1;
|
|
63
|
+
if (r) return {
|
|
64
|
+
start: t,
|
|
65
|
+
end: l,
|
|
66
|
+
contentEnd: c,
|
|
67
|
+
name: i,
|
|
68
|
+
nameRange: {
|
|
69
|
+
start: a,
|
|
70
|
+
end: a + i.length
|
|
71
|
+
},
|
|
72
|
+
closing: !0,
|
|
73
|
+
selfClosing: !1,
|
|
74
|
+
attrs: []
|
|
75
|
+
};
|
|
76
|
+
let u = [], d = a + i.length;
|
|
77
|
+
for (; d < c;) {
|
|
78
|
+
for (; d < c && x(e[d]);) d += 1;
|
|
79
|
+
if (d >= c) break;
|
|
80
|
+
if (e[d] === "/") {
|
|
81
|
+
d += 1;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
let t = /^[A-Za-z][A-Za-z0-9_-]*/.exec(e.slice(d, c));
|
|
85
|
+
if (!t) {
|
|
86
|
+
d += 1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
let n = d, r = t[0];
|
|
90
|
+
d += r.length;
|
|
91
|
+
let i = d, a = d;
|
|
92
|
+
for (; a < c && x(e[a]);) a += 1;
|
|
93
|
+
if (e[a] !== "=") {
|
|
94
|
+
u.push({
|
|
95
|
+
name: r,
|
|
96
|
+
nameRange: {
|
|
97
|
+
start: n,
|
|
98
|
+
end: n + r.length
|
|
99
|
+
}
|
|
100
|
+
}), d = i;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
for (d = a + 1; d < c && x(e[d]);) d += 1;
|
|
104
|
+
let o = e[d];
|
|
105
|
+
if (o === "\"" || o === "'") {
|
|
106
|
+
let t = d, i = d + 1, a = e.indexOf(o, i);
|
|
107
|
+
if (a < 0 || a > c) {
|
|
108
|
+
u.push({
|
|
109
|
+
name: r,
|
|
110
|
+
nameRange: {
|
|
111
|
+
start: n,
|
|
112
|
+
end: n + r.length
|
|
113
|
+
},
|
|
114
|
+
valueRange: {
|
|
115
|
+
start: i,
|
|
116
|
+
end: c
|
|
117
|
+
},
|
|
118
|
+
quoteStart: t,
|
|
119
|
+
quoteEnd: c
|
|
120
|
+
}), d = c;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
u.push({
|
|
124
|
+
name: r,
|
|
125
|
+
nameRange: {
|
|
126
|
+
start: n,
|
|
127
|
+
end: n + r.length
|
|
128
|
+
},
|
|
129
|
+
valueRange: {
|
|
130
|
+
start: i,
|
|
131
|
+
end: a
|
|
132
|
+
},
|
|
133
|
+
quoteStart: t,
|
|
134
|
+
quoteEnd: a
|
|
135
|
+
}), d = a + 1;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
let s = d;
|
|
139
|
+
for (; d < c && !x(e[d]);) d += 1;
|
|
140
|
+
u.push({
|
|
141
|
+
name: r,
|
|
142
|
+
nameRange: {
|
|
143
|
+
start: n,
|
|
144
|
+
end: n + r.length
|
|
145
|
+
},
|
|
146
|
+
valueRange: {
|
|
147
|
+
start: s,
|
|
148
|
+
end: d
|
|
149
|
+
},
|
|
150
|
+
unquoted: !0
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
start: t,
|
|
155
|
+
end: l,
|
|
156
|
+
contentEnd: c,
|
|
157
|
+
name: i,
|
|
158
|
+
nameRange: {
|
|
159
|
+
start: a,
|
|
160
|
+
end: a + i.length
|
|
161
|
+
},
|
|
162
|
+
closing: !1,
|
|
163
|
+
selfClosing: /\/\s*$/.test(e.slice(a + i.length, c)),
|
|
164
|
+
attrs: u
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function fe(e, t, n) {
|
|
168
|
+
if (t.range.end <= n) return null;
|
|
169
|
+
let r = e.lastIndexOf("</", t.range.end - 1);
|
|
170
|
+
if (r < n) return null;
|
|
171
|
+
let i = w(e, r);
|
|
172
|
+
return !i || !i.closing || i.name !== t.name || i.end > t.range.end ? null : i;
|
|
173
|
+
}
|
|
174
|
+
function pe(e, t, n) {
|
|
175
|
+
let r = [];
|
|
176
|
+
for (let i = t; i < n;) {
|
|
177
|
+
if (e[i] === "\\" && e.startsWith("{{", i + 1)) {
|
|
178
|
+
i += 3;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (!e.startsWith("{{", i)) {
|
|
182
|
+
i += 1;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
let t = "", a = i + 2;
|
|
186
|
+
for (; a < n - 1; a += 1) {
|
|
187
|
+
let n = e[a];
|
|
188
|
+
if (t) n === "\\" ? a += 1 : n === t && (t = "");
|
|
189
|
+
else if (n === "\"" || n === "'") t = n;
|
|
190
|
+
else if (n === "}" && e[a + 1] === "}") break;
|
|
191
|
+
}
|
|
192
|
+
if (a >= n - 1) break;
|
|
193
|
+
r.push({
|
|
194
|
+
start: i,
|
|
195
|
+
end: a + 2,
|
|
196
|
+
innerStart: i + 2,
|
|
197
|
+
innerEnd: a
|
|
198
|
+
}), i = a + 2;
|
|
199
|
+
}
|
|
200
|
+
return r;
|
|
201
|
+
}
|
|
202
|
+
function me(e, t) {
|
|
203
|
+
let n = {
|
|
204
|
+
quot: "\"",
|
|
205
|
+
apos: "'",
|
|
206
|
+
amp: "&",
|
|
207
|
+
lt: "<",
|
|
208
|
+
gt: ">"
|
|
209
|
+
}, r = [t.start], i = "";
|
|
210
|
+
for (let a = t.start; a < t.end;) {
|
|
211
|
+
let o = e[a] === "&" ? /^&(quot|apos|amp|lt|gt);/.exec(e.slice(a, t.end)) : null;
|
|
212
|
+
i += o ? n[o[1]] : e[a], a += o ? o[0].length : 1, r.push(a);
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
text: i,
|
|
216
|
+
offsets: r
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function he(e, t, n) {
|
|
220
|
+
let r = [];
|
|
221
|
+
for (let i = t; i < n;) {
|
|
222
|
+
let t = e[i];
|
|
223
|
+
if (t === "\"" || t === "'") {
|
|
224
|
+
let r = t;
|
|
225
|
+
for (i += 1; i < n;) if (e[i] === "\\") i += 2;
|
|
226
|
+
else {
|
|
227
|
+
if (e[i] === r) {
|
|
228
|
+
i += 1;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
i += 1;
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
if (/[0-9]/.test(t) || t === "." && e[i + 1] !== void 0 && /[0-9]/.test(e[i + 1])) {
|
|
235
|
+
let t = /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(i, n));
|
|
236
|
+
if (t) {
|
|
237
|
+
i += t[0].length;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (y(t)) {
|
|
242
|
+
let t = i;
|
|
243
|
+
for (i += 1; i < n && b(e[i]);) i += 1;
|
|
244
|
+
let a = e.slice(t, i), o = i;
|
|
245
|
+
for (; o < n && x(e[o]);) o += 1;
|
|
246
|
+
if (e[o] === "(" || a === "true" || a === "false" || a === "null" || a === "pi" || a === "e" || c.has(a)) continue;
|
|
247
|
+
r.push({
|
|
248
|
+
name: a,
|
|
249
|
+
range: {
|
|
250
|
+
start: t,
|
|
251
|
+
end: i
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
} else i += 1;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return r;
|
|
258
|
+
}
|
|
259
|
+
function ge(e, t) {
|
|
260
|
+
return Object.hasOwn(e.props, t) ? t === "bind" || !!e.slots?.some((e) => e.bind === t) : !1;
|
|
261
|
+
}
|
|
262
|
+
function T(e, t = []) {
|
|
263
|
+
for (let n of e) ce.has(n.type) && t.push(C(n.range)), n.type !== "fallback" && n.children && T(n.children, t);
|
|
264
|
+
return t;
|
|
265
|
+
}
|
|
266
|
+
function _e(e, t) {
|
|
267
|
+
let n = T(t), r = (t) => {
|
|
268
|
+
for (let i of t) {
|
|
269
|
+
if (i.type === "component") {
|
|
270
|
+
let t = w(e, i.range.start);
|
|
271
|
+
t && n.push({
|
|
272
|
+
start: t.start,
|
|
273
|
+
end: t.end
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
i.type !== "fallback" && i.children && r(i.children);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
r(t), n.sort((e, t) => e.start - t.start || t.end - e.end);
|
|
280
|
+
let i = [], a = 0, o = 0;
|
|
281
|
+
for (; a < e.length;) {
|
|
282
|
+
let t = e.indexOf("<!--", a);
|
|
283
|
+
if (t < 0) break;
|
|
284
|
+
for (; o < n.length && n[o].end <= t;) o++;
|
|
285
|
+
let r = n[o];
|
|
286
|
+
if (r && r.start <= t) {
|
|
287
|
+
a = r.end;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
let s = e.indexOf("-->", t + 4), c = s < 0 ? e.length : s + 3;
|
|
291
|
+
i.push({
|
|
292
|
+
start: t,
|
|
293
|
+
end: c
|
|
294
|
+
}), a = c;
|
|
295
|
+
}
|
|
296
|
+
return i;
|
|
297
|
+
}
|
|
298
|
+
function E(e, t) {
|
|
299
|
+
let n = [], r = /* @__PURE__ */ new Map(), i = [], a = [], s = (t, n) => {
|
|
300
|
+
for (let r of he(e, t, n)) i.push(r);
|
|
301
|
+
}, c = (e, t) => {
|
|
302
|
+
let n = r.get(e);
|
|
303
|
+
n ? n.push(C(t)) : r.set(e, [C(t)]);
|
|
304
|
+
}, l = (t, r) => {
|
|
305
|
+
let a = w(e, t.range.start);
|
|
306
|
+
if (!a || a.closing) return;
|
|
307
|
+
n.push({
|
|
308
|
+
kind: "tag",
|
|
309
|
+
range: C(a.nameRange)
|
|
310
|
+
});
|
|
311
|
+
let o = m(t.name ?? ""), s = a.attrs.some((e) => e.name === "key");
|
|
312
|
+
for (let l of a.attrs) {
|
|
313
|
+
if (n.push({
|
|
314
|
+
kind: "attribute",
|
|
315
|
+
range: C(l.nameRange)
|
|
316
|
+
}), !l.valueRange) continue;
|
|
317
|
+
let a = o?.props[l.name], u = o !== void 0 && ge(o, l.name) && (t.name !== "table" && t.name !== "chart" || !!s), d = (t.name === "computed" || t.name === "const") && l.name === "name", f = e.slice(l.valueRange.start, l.valueRange.end), p = me(e, l.valueRange);
|
|
318
|
+
if (t.name === "validation" && l.name === "fields") {
|
|
319
|
+
for (let e of p.text.matchAll(/\S+/g)) {
|
|
320
|
+
if (!S(e[0])) continue;
|
|
321
|
+
let t = {
|
|
322
|
+
start: p.offsets[e.index],
|
|
323
|
+
end: p.offsets[e.index + e[0].length]
|
|
324
|
+
};
|
|
325
|
+
i.push({
|
|
326
|
+
name: e[0],
|
|
327
|
+
range: t
|
|
328
|
+
}), n.push({
|
|
329
|
+
kind: "binding",
|
|
330
|
+
range: t
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
let m = a && !a.static ? pe(p.text, 0, p.text.length) : [];
|
|
336
|
+
if (m.length > 0) {
|
|
337
|
+
let e = 0;
|
|
338
|
+
for (let a of m) {
|
|
339
|
+
a.start > e && n.push({
|
|
340
|
+
kind: "string",
|
|
341
|
+
range: {
|
|
342
|
+
start: p.offsets[e],
|
|
343
|
+
end: p.offsets[a.start]
|
|
344
|
+
}
|
|
345
|
+
}), n.push({
|
|
346
|
+
kind: "expression",
|
|
347
|
+
range: {
|
|
348
|
+
start: p.offsets[a.start],
|
|
349
|
+
end: p.offsets[a.end]
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
for (let e of he(p.text, a.innerStart, a.innerEnd)) ((r !== "data-table" || t.name !== "column") && (t.name !== "data-table" || l.name !== "key") || e.name !== "item" && e.name !== "index") && i.push({
|
|
353
|
+
name: e.name,
|
|
354
|
+
range: {
|
|
355
|
+
start: p.offsets[e.range.start],
|
|
356
|
+
end: p.offsets[e.range.end]
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
e = a.end;
|
|
360
|
+
}
|
|
361
|
+
e < p.text.length && n.push({
|
|
362
|
+
kind: "string",
|
|
363
|
+
range: {
|
|
364
|
+
start: p.offsets[e],
|
|
365
|
+
end: l.valueRange.end
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
} else (u || d) && S(f) ? (n.push({
|
|
369
|
+
kind: "binding",
|
|
370
|
+
range: C(l.valueRange)
|
|
371
|
+
}), c(f, l.valueRange)) : l.valueRange.end > l.valueRange.start && n.push({
|
|
372
|
+
kind: "string",
|
|
373
|
+
range: C(l.valueRange)
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
let l = fe(e, t, a.end);
|
|
377
|
+
l && n.push({
|
|
378
|
+
kind: "tag",
|
|
379
|
+
range: C(l.nameRange)
|
|
380
|
+
});
|
|
381
|
+
}, u = (t, r) => {
|
|
382
|
+
for (let c of t) {
|
|
383
|
+
if (c.type === "component" && c.name) l(c, r);
|
|
384
|
+
else if (c.type === "interpolation") n.push({
|
|
385
|
+
kind: "expression",
|
|
386
|
+
range: C(c.range)
|
|
387
|
+
}), s(c.range.start + 2, Math.max(c.range.start + 2, c.range.end - 2));
|
|
388
|
+
else if (c.type === "math" || c.type === "inlineMath") {
|
|
389
|
+
if (n.push({
|
|
390
|
+
kind: "math",
|
|
391
|
+
range: C(c.range)
|
|
392
|
+
}), r === "plot" && c.type === "math") {
|
|
393
|
+
let t = c.range.start + 2;
|
|
394
|
+
try {
|
|
395
|
+
for (let n of o(e.slice(t, c.range.end - 2))) {
|
|
396
|
+
let e = {
|
|
397
|
+
name: n.name,
|
|
398
|
+
range: {
|
|
399
|
+
start: t + n.range.start,
|
|
400
|
+
end: t + n.range.end
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
i.push(e), a.push(e);
|
|
404
|
+
}
|
|
405
|
+
} catch {}
|
|
406
|
+
}
|
|
407
|
+
} else c.type === "code" || c.type === "inlineCode" ? n.push({
|
|
408
|
+
kind: "code",
|
|
409
|
+
range: C(c.range)
|
|
410
|
+
}) : c.type === "comment" && n.push({
|
|
411
|
+
kind: "comment",
|
|
412
|
+
range: C(c.range)
|
|
413
|
+
});
|
|
414
|
+
c.type !== "fallback" && c.children && u(c.children, c.name);
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
u(t);
|
|
418
|
+
for (let r of _e(e, t)) n.push({
|
|
419
|
+
kind: "comment",
|
|
420
|
+
range: r
|
|
421
|
+
});
|
|
422
|
+
n.sort((e, t) => e.range.start - t.range.start || e.range.end - t.range.end);
|
|
423
|
+
let d = [];
|
|
424
|
+
for (let e of n) {
|
|
425
|
+
if (e.range.end <= e.range.start) continue;
|
|
426
|
+
let t = d[d.length - 1];
|
|
427
|
+
t && e.range.start < t.range.end || d.push(e);
|
|
428
|
+
}
|
|
429
|
+
let f = [];
|
|
430
|
+
for (let [e, t] of r) {
|
|
431
|
+
let n = [];
|
|
432
|
+
for (let t of i) t.name === e && (n.some((e) => e.start === t.range.start && e.end === t.range.end) || n.push(C(t.range)));
|
|
433
|
+
n.sort((e, t) => e.start - t.start || e.end - t.end), t.sort((e, t) => e.start - t.start || e.end - t.end), f.push({
|
|
434
|
+
name: e,
|
|
435
|
+
declarations: t,
|
|
436
|
+
references: n
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
return f.sort((e, t) => e.declarations[0].start - t.declarations[0].start || e.name.localeCompare(t.name)), {
|
|
440
|
+
tokens: d,
|
|
441
|
+
bindings: f,
|
|
442
|
+
mathReferences: a
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
function ve(e) {
|
|
446
|
+
if (typeof e != "string") return {
|
|
447
|
+
tokens: [],
|
|
448
|
+
bindings: [],
|
|
449
|
+
diagnostics: []
|
|
450
|
+
};
|
|
451
|
+
let t = E(e, g(e).nodes);
|
|
452
|
+
return {
|
|
453
|
+
tokens: t.tokens,
|
|
454
|
+
bindings: t.bindings,
|
|
455
|
+
diagnostics: ue(e)
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function D(e, t, n) {
|
|
459
|
+
let r = /^<(\/?)([A-Za-z][A-Za-z0-9_-]*)/.exec(e.slice(t, Math.min(e.length, n + 1)));
|
|
460
|
+
if (!r) return null;
|
|
461
|
+
let i = !!r[1], a = r[2], o = t + r[0].length, s = [], c = !1, l, u = !1;
|
|
462
|
+
if (!i) {
|
|
463
|
+
let t = o;
|
|
464
|
+
for (; t < n;) {
|
|
465
|
+
for (; t < n && x(e[t]);) t += 1;
|
|
466
|
+
if (t >= n) break;
|
|
467
|
+
if (e[t] === "/") {
|
|
468
|
+
u = !0, t += 1;
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
let r = /^[A-Za-z][A-Za-z0-9_-]*/.exec(e.slice(t, n));
|
|
472
|
+
if (!r) {
|
|
473
|
+
t += 1;
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
let i = r[0], a = t;
|
|
477
|
+
t += i.length;
|
|
478
|
+
let o = t, d = t;
|
|
479
|
+
for (; d < n && x(e[d]);) d += 1;
|
|
480
|
+
if (e[d] !== "=") {
|
|
481
|
+
s.push({
|
|
482
|
+
name: i,
|
|
483
|
+
nameStart: a,
|
|
484
|
+
nameEnd: o,
|
|
485
|
+
nameRange: {
|
|
486
|
+
start: a,
|
|
487
|
+
end: o
|
|
488
|
+
}
|
|
489
|
+
}), t = o;
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
for (t = d + 1; t < n && x(e[t]);) t += 1;
|
|
493
|
+
let f = e[t];
|
|
494
|
+
if (f === "\"" || f === "'") {
|
|
495
|
+
let r = t, u = t + 1, d = e.indexOf(f, u);
|
|
496
|
+
if (d < 0 || d >= n) {
|
|
497
|
+
let e = {
|
|
498
|
+
name: i,
|
|
499
|
+
nameStart: a,
|
|
500
|
+
nameEnd: o,
|
|
501
|
+
nameRange: {
|
|
502
|
+
start: a,
|
|
503
|
+
end: o
|
|
504
|
+
},
|
|
505
|
+
valueRange: {
|
|
506
|
+
start: u,
|
|
507
|
+
end: n
|
|
508
|
+
},
|
|
509
|
+
quoteStart: r,
|
|
510
|
+
quoteEnd: d < 0 ? n : d
|
|
511
|
+
};
|
|
512
|
+
s.push(e), l = e, c = !0, t = n;
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
s.push({
|
|
516
|
+
name: i,
|
|
517
|
+
nameStart: a,
|
|
518
|
+
nameEnd: o,
|
|
519
|
+
nameRange: {
|
|
520
|
+
start: a,
|
|
521
|
+
end: o
|
|
522
|
+
},
|
|
523
|
+
valueRange: {
|
|
524
|
+
start: u,
|
|
525
|
+
end: d
|
|
526
|
+
},
|
|
527
|
+
quoteStart: r,
|
|
528
|
+
quoteEnd: d
|
|
529
|
+
}), t = d + 1;
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
let p = t;
|
|
533
|
+
for (; t < n && !x(e[t]);) t += 1;
|
|
534
|
+
s.push({
|
|
535
|
+
name: i,
|
|
536
|
+
nameStart: a,
|
|
537
|
+
nameEnd: o,
|
|
538
|
+
nameRange: {
|
|
539
|
+
start: a,
|
|
540
|
+
end: o
|
|
541
|
+
},
|
|
542
|
+
valueRange: {
|
|
543
|
+
start: p,
|
|
544
|
+
end: t
|
|
545
|
+
},
|
|
546
|
+
unquoted: !0
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
let d = -1;
|
|
551
|
+
if (!c) {
|
|
552
|
+
let t = n;
|
|
553
|
+
for (; t > o && /[A-Za-z0-9_-]/.test(e[t - 1]);) --t;
|
|
554
|
+
t > o && x(e[t - 1]) && (d = t);
|
|
555
|
+
}
|
|
556
|
+
return {
|
|
557
|
+
name: a,
|
|
558
|
+
closing: i,
|
|
559
|
+
selfClosing: u,
|
|
560
|
+
inValue: c,
|
|
561
|
+
currentAttribute: l,
|
|
562
|
+
attrs: s,
|
|
563
|
+
partialStart: d
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
function O(e, t, n) {
|
|
567
|
+
let r = [], i = (e) => {
|
|
568
|
+
for (let t of e) t.type === "component" && r.push(t.range.start), t.type !== "fallback" && t.children && i(t.children);
|
|
569
|
+
};
|
|
570
|
+
i(n), r.sort((e, t) => e - t);
|
|
571
|
+
for (let n = r.length - 1; n >= 0; --n) {
|
|
572
|
+
let i = r[n];
|
|
573
|
+
if (i >= t) continue;
|
|
574
|
+
let a = w(e, i);
|
|
575
|
+
if (a && t <= a.end) return i;
|
|
576
|
+
if (a && a.end < t) break;
|
|
577
|
+
}
|
|
578
|
+
let a = t;
|
|
579
|
+
for (; a > 0;) {
|
|
580
|
+
let n = e.lastIndexOf("<", a - 1);
|
|
581
|
+
if (n < 0) return -1;
|
|
582
|
+
if (e[n - 1] === "\\") {
|
|
583
|
+
a = n;
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
let r = e[n + 1];
|
|
587
|
+
if (r !== "/" && !y(r)) a = n;
|
|
588
|
+
else if (ye(e, n, t)) a = n;
|
|
589
|
+
else return n;
|
|
590
|
+
}
|
|
591
|
+
return -1;
|
|
592
|
+
}
|
|
593
|
+
function ye(e, t, n) {
|
|
594
|
+
let r = "";
|
|
595
|
+
for (let i = t; i < n; i += 1) {
|
|
596
|
+
let t = e[i];
|
|
597
|
+
if (r) t === r && (r = "");
|
|
598
|
+
else if (t === "\"" || t === "'") r = t;
|
|
599
|
+
else if (t === ">") return !0;
|
|
600
|
+
}
|
|
601
|
+
return !1;
|
|
602
|
+
}
|
|
603
|
+
function be(e, t) {
|
|
604
|
+
let n = t;
|
|
605
|
+
for (; n > 0;) {
|
|
606
|
+
let r = e.lastIndexOf("{{", n - 1);
|
|
607
|
+
if (r < 0) return null;
|
|
608
|
+
if (e[r - 1] === "\\") {
|
|
609
|
+
n = r;
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
let i = "", a = r + 2, o = -1;
|
|
613
|
+
for (; a < e.length - 1; a += 1) {
|
|
614
|
+
let t = e[a];
|
|
615
|
+
if (i) t === "\\" ? a += 1 : t === i && (i = "");
|
|
616
|
+
else if (t === "\"" || t === "'") i = t;
|
|
617
|
+
else if (t === "}" && e[a + 1] === "}") {
|
|
618
|
+
o = a;
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
if (o >= 0 && o + 2 <= t) n = r;
|
|
623
|
+
else return {
|
|
624
|
+
start: r,
|
|
625
|
+
end: o < 0 ? e.length : o + 2,
|
|
626
|
+
innerStart: r + 2,
|
|
627
|
+
innerEnd: o < 0 ? e.length : o
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
return null;
|
|
631
|
+
}
|
|
632
|
+
function xe(e, t, n) {
|
|
633
|
+
let r = "";
|
|
634
|
+
for (let i = t; i < n; i += 1) {
|
|
635
|
+
let t = e[i];
|
|
636
|
+
r ? t === "\\" ? i += 1 : t === r && (r = "") : (t === "\"" || t === "'") && (r = t);
|
|
637
|
+
}
|
|
638
|
+
return r !== "";
|
|
639
|
+
}
|
|
640
|
+
function Se(e, t) {
|
|
641
|
+
let n = 0, r = e.length - 1;
|
|
642
|
+
for (; n <= r;) {
|
|
643
|
+
let i = n + r >> 1, a = e[i];
|
|
644
|
+
if (t < a.start) r = i - 1;
|
|
645
|
+
else if (t >= a.end) n = i + 1;
|
|
646
|
+
else return !0;
|
|
647
|
+
}
|
|
648
|
+
return !1;
|
|
649
|
+
}
|
|
650
|
+
function k(e, t, n, r) {
|
|
651
|
+
let i = e.slice(t, n), a = i && r.startsWith(i) ? r.slice(i.length) : "";
|
|
652
|
+
return {
|
|
653
|
+
start: t,
|
|
654
|
+
end: a && e.startsWith(a, n) ? n + a.length : n
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function Ce(e, t, n, r) {
|
|
658
|
+
if (xe(e, n.innerStart, t)) return [];
|
|
659
|
+
let i = t;
|
|
660
|
+
for (; i > n.innerStart && b(e[i - 1]);) --i;
|
|
661
|
+
if (e[i - 1] === ".") return [];
|
|
662
|
+
let a = e.slice(i, t);
|
|
663
|
+
return a && !y(a[0]) ? [] : r.filter((e) => e.name.startsWith(a)).map((n) => ({
|
|
664
|
+
label: n.name,
|
|
665
|
+
insertText: n.name,
|
|
666
|
+
range: k(e, i, t, n.name),
|
|
667
|
+
kind: "binding",
|
|
668
|
+
detail: `${n.declarations.length} declaration${n.declarations.length === 1 ? "" : "s"}, ${n.references.length} reference${n.references.length === 1 ? "" : "s"}`
|
|
669
|
+
}));
|
|
670
|
+
}
|
|
671
|
+
function we(e, t, n) {
|
|
672
|
+
let r = n.currentAttribute;
|
|
673
|
+
if (!r) return [];
|
|
674
|
+
let i = m(n.name)?.props[r.name];
|
|
675
|
+
if (!i || i.kind !== "enum" || !i.values) return [];
|
|
676
|
+
let a = r.valueRange?.start ?? t, o = e.slice(a, t);
|
|
677
|
+
return i.values.filter((e) => e.startsWith(o)).map((n) => ({
|
|
678
|
+
label: n,
|
|
679
|
+
insertText: n,
|
|
680
|
+
range: k(e, a, t, n),
|
|
681
|
+
kind: "value",
|
|
682
|
+
detail: `${r.name} value`
|
|
683
|
+
}));
|
|
684
|
+
}
|
|
685
|
+
function Te(e, t, n) {
|
|
686
|
+
if (n.closing || n.inValue || n.partialStart < 0) return [];
|
|
687
|
+
let r = m(n.name);
|
|
688
|
+
if (!r) return [];
|
|
689
|
+
let i = e.slice(n.partialStart, t);
|
|
690
|
+
if (i && !/^[A-Za-z0-9_-]*$/.test(i)) return [];
|
|
691
|
+
let a = new Set(n.attrs.filter((e) => e.nameEnd < n.partialStart).map((e) => e.name));
|
|
692
|
+
return Object.entries(r.props).filter(([e]) => !a.has(e) && e.startsWith(i)).map(([r, i]) => ({
|
|
693
|
+
label: r,
|
|
694
|
+
insertText: r,
|
|
695
|
+
range: k(e, n.partialStart, t, r),
|
|
696
|
+
kind: "attribute",
|
|
697
|
+
detail: i.required ? `${i.kind}, required` : i.kind
|
|
698
|
+
}));
|
|
699
|
+
}
|
|
700
|
+
function Ee(e, t) {
|
|
701
|
+
let n = Math.max(0, t - 256), r = e.slice(n, t), i = /<\/?([A-Za-z][A-Za-z0-9-]*)?$/.exec(r);
|
|
702
|
+
if (!i) return [];
|
|
703
|
+
let a = n + i.index;
|
|
704
|
+
if (e[a] !== "<" || e[a - 1] === "\\") return [];
|
|
705
|
+
let o = e[a + 1] === "/", s = a + (o ? 2 : 1);
|
|
706
|
+
if (s > t) return [];
|
|
707
|
+
let c = i[1] ?? "";
|
|
708
|
+
return l.filter((e) => e.startsWith(c)).map((n) => ({
|
|
709
|
+
label: n,
|
|
710
|
+
insertText: n,
|
|
711
|
+
range: k(e, s, t, n),
|
|
712
|
+
kind: "tag",
|
|
713
|
+
detail: o ? "closing tag" : "component"
|
|
714
|
+
}));
|
|
715
|
+
}
|
|
716
|
+
function De(e, t) {
|
|
717
|
+
if (typeof e != "string" || !Number.isFinite(t)) return [];
|
|
718
|
+
let n = Math.max(0, Math.min(e.length, Math.floor(t))), r = g(e), i = [...T(r.nodes), ..._e(e, r.nodes)].sort((e, t) => e.start - t.start);
|
|
719
|
+
if (Se(i, n) || n === e.length && i.some((e) => e.end === n && e.start < n)) return [];
|
|
720
|
+
let a = E(e, r.nodes), o = be(e, n);
|
|
721
|
+
if (o) {
|
|
722
|
+
let t = O(e, n, r.nodes);
|
|
723
|
+
if (t >= 0) {
|
|
724
|
+
let r = D(e, t, n);
|
|
725
|
+
if (r?.inValue && r.currentAttribute && m(r.name)?.props[r.currentAttribute.name]?.static) return [];
|
|
726
|
+
}
|
|
727
|
+
return Ce(e, n, o, a.bindings);
|
|
728
|
+
}
|
|
729
|
+
let s = O(e, n, r.nodes);
|
|
730
|
+
if (s >= 0) {
|
|
731
|
+
let t = D(e, s, n);
|
|
732
|
+
if (t?.inValue) return we(e, n, t);
|
|
733
|
+
}
|
|
734
|
+
let c = Ee(e, n);
|
|
735
|
+
if (c.length > 0) return c;
|
|
736
|
+
if (s >= 0) {
|
|
737
|
+
let t = D(e, s, n);
|
|
738
|
+
if (t) return Te(e, n, t);
|
|
739
|
+
}
|
|
740
|
+
return [];
|
|
741
|
+
}
|
|
742
|
+
function Oe(e, t) {
|
|
743
|
+
let n = "", r = 0;
|
|
744
|
+
for (let i of t) n += e.slice(r, i.range.start) + i.text, r = i.range.end;
|
|
745
|
+
return n + e.slice(r);
|
|
746
|
+
}
|
|
747
|
+
function ke(e, t, n) {
|
|
748
|
+
if (typeof e != "string" || typeof t != "string" || typeof n != "string") throw Error("Rename requires string arguments.");
|
|
749
|
+
if (!S(n)) throw Error(`"${n}" is not a valid binding name. Use [A-Za-z_][A-Za-z0-9_]* and avoid reserved names.`);
|
|
750
|
+
let r = E(e, g(e).nodes), i = r.bindings.find((e) => e.name === t);
|
|
751
|
+
if (!i || i.declarations.length === 0) throw Error(`Binding "${t}" is not declared in this document.`);
|
|
752
|
+
if (t === n) return {
|
|
753
|
+
source: e,
|
|
754
|
+
edits: []
|
|
755
|
+
};
|
|
756
|
+
if (r.bindings.some((e) => e.name === n)) throw Error(`Binding "${n}" already exists.`);
|
|
757
|
+
if (ue(e).some((e) => e.severity === "error" && le.has(e.code))) throw Error("The document cannot be renamed safely while parse errors remain.");
|
|
758
|
+
let a = /* @__PURE__ */ new Set(), o = [];
|
|
759
|
+
for (let e of [...i.declarations, ...i.references]) {
|
|
760
|
+
let t = `${e.start}:${e.end}`;
|
|
761
|
+
a.has(t) || (a.add(t), o.push(C(e)));
|
|
762
|
+
}
|
|
763
|
+
o.sort((e, t) => e.start - t.start || e.end - t.end);
|
|
764
|
+
let s = new Set(r.mathReferences.filter((e) => e.name === t).map((e) => `${e.range.start}:${e.range.end}`)), c = o.map((e) => ({
|
|
765
|
+
range: C(e),
|
|
766
|
+
text: s.has(`${e.start}:${e.end}`) ? `\\mathrm{${n}}` : n
|
|
767
|
+
})), l = Oe(e, c);
|
|
768
|
+
if (h(e).ok && !h(l).ok) throw Error("Rename could not preserve all binding references; the source was left unchanged.");
|
|
769
|
+
return {
|
|
770
|
+
source: l,
|
|
771
|
+
edits: c
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
function Ae(e, t) {
|
|
775
|
+
let n = e.slice(t.nameRange.start, t.nameRange.end), r = t.attrs.map((t) => {
|
|
776
|
+
let n = e.slice(t.nameRange.start, t.nameRange.end);
|
|
777
|
+
return t.valueRange === void 0 ? n : t.quoteStart !== void 0 && t.quoteEnd !== void 0 ? `${n}=${e.slice(t.quoteStart, t.quoteEnd + 1)}` : n;
|
|
778
|
+
}), i = r.length > 0 ? `<${n} ${r.join(" ")}` : `<${n}`;
|
|
779
|
+
return t.selfClosing ? `${i} />` : `${i}>`;
|
|
780
|
+
}
|
|
781
|
+
function je(e) {
|
|
782
|
+
if (typeof e != "string") return e;
|
|
783
|
+
let t;
|
|
784
|
+
try {
|
|
785
|
+
t = h(e);
|
|
786
|
+
} catch {
|
|
787
|
+
return e;
|
|
788
|
+
}
|
|
789
|
+
if (t.diagnostics.some((e) => e.severity === "error")) return e;
|
|
790
|
+
let n = g(e), r = [], i = (t) => {
|
|
791
|
+
for (let n of t) {
|
|
792
|
+
if (n.type === "component" && n.name) {
|
|
793
|
+
let t = w(e, n.range.start);
|
|
794
|
+
if (t && !t.closing && !/[\r\n]/.test(e.slice(t.start, t.end))) {
|
|
795
|
+
let n = Ae(e, t);
|
|
796
|
+
n !== e.slice(t.start, t.end) && r.push({
|
|
797
|
+
start: t.start,
|
|
798
|
+
end: t.end,
|
|
799
|
+
text: n
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
if (t) {
|
|
803
|
+
let i = fe(e, n, t.end);
|
|
804
|
+
if (i && !/[\r\n]/.test(e.slice(i.start, i.end))) {
|
|
805
|
+
let t = `</${e.slice(i.nameRange.start, i.nameRange.end)}>`;
|
|
806
|
+
t !== e.slice(i.start, i.end) && r.push({
|
|
807
|
+
start: i.start,
|
|
808
|
+
end: i.end,
|
|
809
|
+
text: t
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
n.type !== "fallback" && n.children && i(n.children);
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
i(n.nodes), r.sort((e, t) => e.start - t.start || e.end - t.end);
|
|
818
|
+
let a = "", o = 0;
|
|
819
|
+
for (let t of r) t.start < o || (a += e.slice(o, t.start) + t.text, o = t.end);
|
|
820
|
+
return a + e.slice(o);
|
|
821
|
+
}
|
|
822
|
+
// src/local/source-migration.ts
|
|
823
|
+
var A = /* @__PURE__ */ new Set([
|
|
824
|
+
"sum",
|
|
825
|
+
"average",
|
|
826
|
+
"minOf",
|
|
827
|
+
"maxOf",
|
|
828
|
+
"formatNumber",
|
|
829
|
+
"formatPercent",
|
|
830
|
+
"formatScientific",
|
|
831
|
+
"formatCurrency",
|
|
832
|
+
"trim",
|
|
833
|
+
"lower",
|
|
834
|
+
"upper",
|
|
835
|
+
"startsWith",
|
|
836
|
+
"endsWith",
|
|
837
|
+
"replace",
|
|
838
|
+
"slice",
|
|
839
|
+
"dateCompare",
|
|
840
|
+
"dateDiff"
|
|
841
|
+
]), Me = /* @__PURE__ */ new Set([
|
|
842
|
+
"jump",
|
|
843
|
+
"anchor",
|
|
844
|
+
"text",
|
|
845
|
+
"section",
|
|
846
|
+
"multi-select",
|
|
847
|
+
"range-slider",
|
|
848
|
+
"coordinate",
|
|
849
|
+
"quiz",
|
|
850
|
+
"steps",
|
|
851
|
+
"step",
|
|
852
|
+
"computed",
|
|
853
|
+
"const",
|
|
854
|
+
"validation",
|
|
855
|
+
"data-table",
|
|
856
|
+
"column"
|
|
857
|
+
]), j = `<!-- reactive-md: ${v} -->`;
|
|
858
|
+
function M(e) {
|
|
859
|
+
let t = e.diagnostics.filter((t) => t.code.startsWith("local.version.") || t.code === "local.budget" || t.code === "local.parse" && !e.nodes.length), n = e.versionDeclaration?.version ?? null;
|
|
860
|
+
return {
|
|
861
|
+
declaredVersion: n,
|
|
862
|
+
effectiveVersion: n ?? "local-draft-2",
|
|
863
|
+
supported: !t.some((e) => e.severity === "error"),
|
|
864
|
+
range: e.versionDeclaration ? { ...e.versionDeclaration.range } : null,
|
|
865
|
+
diagnostics: t
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
function Ne(e) {
|
|
869
|
+
return M(g(e));
|
|
870
|
+
}
|
|
871
|
+
function Pe(e, n, r, i, a = "error") {
|
|
872
|
+
let o = t(n, i), s = e.slice(0, r.start), c = s.lastIndexOf("\n");
|
|
873
|
+
return {
|
|
874
|
+
code: n,
|
|
875
|
+
severity: a,
|
|
876
|
+
range: { ...r },
|
|
877
|
+
message: re(o),
|
|
878
|
+
line: s.split("\n").length,
|
|
879
|
+
column: r.start - c,
|
|
880
|
+
messageKey: o.key,
|
|
881
|
+
...o.params ? { params: o.params } : {}
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
function N(e, t = {}) {
|
|
885
|
+
let n = g(e), r = M(n), i = typeof t == "object" && !!t && !Array.isArray(t), a = i ? t.fromVersion ?? r.effectiveVersion : r.effectiveVersion, o = typeof a == "string" ? a : "", s = {
|
|
886
|
+
ok: !1,
|
|
887
|
+
fromVersion: o,
|
|
888
|
+
toVersion: v,
|
|
889
|
+
needsMigration: !n.versionDeclaration || o !== "local-draft-2",
|
|
890
|
+
diagnostics: r.diagnostics.filter((e) => e.code !== "local.version.unsupported")
|
|
891
|
+
}, c = {
|
|
892
|
+
report: s,
|
|
893
|
+
declaration: n.versionDeclaration
|
|
894
|
+
};
|
|
895
|
+
if (typeof e != "string" || s.diagnostics.some((e) => e.severity === "error")) return c;
|
|
896
|
+
let l = r.range ?? {
|
|
897
|
+
start: 0,
|
|
898
|
+
end: 0
|
|
899
|
+
}, u = (e) => {
|
|
900
|
+
if (s.diagnostics.length >= 100) {
|
|
901
|
+
if (e.severity === "warning") return;
|
|
902
|
+
let t = s.diagnostics.length - 1;
|
|
903
|
+
for (; t >= 0 && s.diagnostics[t].severity !== "warning";) --t;
|
|
904
|
+
if (t < 0) return;
|
|
905
|
+
s.diagnostics.splice(t, 1);
|
|
906
|
+
}
|
|
907
|
+
s.diagnostics.push(e);
|
|
908
|
+
}, d = (t, n, r, i) => {
|
|
909
|
+
u(Pe(e, t, n, r, i));
|
|
910
|
+
};
|
|
911
|
+
if (!i || typeof a != "string" || !["local-draft-1", "local-draft-2"].includes(o) || t.allowSemanticChanges !== void 0 && typeof t.allowSemanticChanges != "boolean" || t.fromVersion !== void 0 && r.declaredVersion !== null && o !== r.declaredVersion) return d("local.upgrade.from-version", l, {
|
|
912
|
+
from: o,
|
|
913
|
+
detail: "use local-draft-1 or local-draft-2 and match the source declaration"
|
|
914
|
+
}), c;
|
|
915
|
+
let f = n.versionDeclaration ? e.slice(0, l.start) + e.slice(l.start, l.end).replace(/[^\r\n]/g, " ") + e.slice(l.end) : e, p = n.versionDeclaration ? g(f) : n;
|
|
916
|
+
if (o === "local-draft-1") {
|
|
917
|
+
let e = (n) => {
|
|
918
|
+
for (let r of n) {
|
|
919
|
+
if (r.name && Me.has(r.name)) {
|
|
920
|
+
d("local.upgrade.tag", r.range, { name: r.name });
|
|
921
|
+
continue;
|
|
922
|
+
}
|
|
923
|
+
for (let e of [
|
|
924
|
+
"bind",
|
|
925
|
+
"bind-start",
|
|
926
|
+
"bind-end",
|
|
927
|
+
"bind-x",
|
|
928
|
+
"bind-y"
|
|
929
|
+
]) {
|
|
930
|
+
let t = r.attrs?.[e];
|
|
931
|
+
t && A.has(t) && d("local.upgrade.reserved-binding", r.range, { name: t });
|
|
932
|
+
}
|
|
933
|
+
(r.name === "input" || r.name === "textarea") && (r.attrs?.["max-length"] !== void 0 || Number(r.attrs?.["min-length"] ?? 0) > 0) && d("local.upgrade.text-length", r.range, void 0, t.allowSemanticChanges ? "warning" : "error");
|
|
934
|
+
let n = [...r.type === "interpolation" ? [r.value ?? ""] : [], ...Object.values(r.attrs ?? {}).flatMap((e) => [...e.matchAll(/\{\{([\s\S]*?)\}\}/g)].map((e) => e[1]))];
|
|
935
|
+
for (let e of n) {
|
|
936
|
+
let t = e.replace(/'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"/g, "");
|
|
937
|
+
(t.includes("[") || [...A].some((e) => RegExp(`\\b${e}\\s*\\(`).test(t))) && d("local.upgrade.expression", r.range);
|
|
938
|
+
}
|
|
939
|
+
r.type !== "fallback" && r.children && e(r.children);
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
e(p.nodes);
|
|
943
|
+
}
|
|
944
|
+
if (s.diagnostics.some((e) => e.severity === "error")) return c;
|
|
945
|
+
let m = h(f);
|
|
946
|
+
for (let e of m.diagnostics) u(e);
|
|
947
|
+
return m.ok && (!n.versionDeclaration && s.diagnostics.length < 100 && d("local.upgrade.version-missing", {
|
|
948
|
+
start: +(e.charCodeAt(0) === 65279),
|
|
949
|
+
end: +(e.charCodeAt(0) === 65279)
|
|
950
|
+
}, { version: v }, "warning"), s.ok = !0), c;
|
|
951
|
+
}
|
|
952
|
+
function Fe(e, t) {
|
|
953
|
+
return N(e, t).report;
|
|
954
|
+
}
|
|
955
|
+
function Ie(e, t) {
|
|
956
|
+
let { report: n, declaration: r } = N(e, t), i = {
|
|
957
|
+
...n,
|
|
958
|
+
source: e,
|
|
959
|
+
changed: !1,
|
|
960
|
+
edits: []
|
|
961
|
+
};
|
|
962
|
+
if (!n.ok || !n.needsMigration) return i;
|
|
963
|
+
let a = +(e.charCodeAt(0) === 65279), o = r?.range ?? {
|
|
964
|
+
start: a,
|
|
965
|
+
end: a
|
|
966
|
+
}, s = e.includes("\r\n") ? "\r\n" : "\n", c = r ? j : `${j}${s}${s}`, l = e.slice(0, o.start) + c + e.slice(o.end);
|
|
967
|
+
return {
|
|
968
|
+
...n,
|
|
969
|
+
source: l,
|
|
970
|
+
changed: l !== e,
|
|
971
|
+
edits: [{
|
|
972
|
+
range: { ...o },
|
|
973
|
+
text: c
|
|
974
|
+
}]
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
// src/local/state.ts
|
|
978
|
+
var P = "reactive-md-state/v1", F = 1048576, Le = /^fnv1a32:[0-9a-f]{8}$/, Re = 2166136261, ze = 16777619, Be = /* @__PURE__ */ new Set([
|
|
979
|
+
"format",
|
|
980
|
+
"syntax",
|
|
981
|
+
"sourceDigest",
|
|
982
|
+
"parameters",
|
|
983
|
+
"generator"
|
|
984
|
+
]), Ve = /* @__PURE__ */ new Set(["name", "version"]), I = new TextEncoder();
|
|
985
|
+
function L(e, t) {
|
|
986
|
+
return {
|
|
987
|
+
code: e,
|
|
988
|
+
message: t.length > 2e3 ? `${t.slice(0, f - 1)}…` : t,
|
|
989
|
+
severity: "error",
|
|
990
|
+
range: {
|
|
991
|
+
start: 0,
|
|
992
|
+
end: 0
|
|
993
|
+
},
|
|
994
|
+
line: 1,
|
|
995
|
+
column: 1
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
function R(e, t, n) {
|
|
999
|
+
e.length < 100 && e.push(L(t, n));
|
|
1000
|
+
}
|
|
1001
|
+
function z(e) {
|
|
1002
|
+
return e instanceof Error ? e.message : String(e);
|
|
1003
|
+
}
|
|
1004
|
+
function B(e) {
|
|
1005
|
+
for (let t = 0; t < e.length; t += 1) {
|
|
1006
|
+
let n = e.charCodeAt(t);
|
|
1007
|
+
if (n >= 55296 && n <= 56319) {
|
|
1008
|
+
let n = e.charCodeAt(t + 1);
|
|
1009
|
+
if (n >= 56320 && n <= 57343) {
|
|
1010
|
+
t += 1;
|
|
1011
|
+
continue;
|
|
1012
|
+
}
|
|
1013
|
+
return !1;
|
|
1014
|
+
}
|
|
1015
|
+
if (n >= 56320 && n <= 57343) return !1;
|
|
1016
|
+
}
|
|
1017
|
+
return !0;
|
|
1018
|
+
}
|
|
1019
|
+
function V(e) {
|
|
1020
|
+
if (typeof e != "string") throw TypeError("localSourceDigest requires a source string.");
|
|
1021
|
+
let t = I.encode(e), n = Re;
|
|
1022
|
+
for (let e = 0; e < t.length; e += 1) n ^= t[e], n = Math.imul(n, ze) >>> 0;
|
|
1023
|
+
return `fnv1a32:${n.toString(16).padStart(8, "0")}`;
|
|
1024
|
+
}
|
|
1025
|
+
function H(e) {
|
|
1026
|
+
if (typeof e == "string") return B(e) ? {
|
|
1027
|
+
ok: !0,
|
|
1028
|
+
value: e
|
|
1029
|
+
} : {
|
|
1030
|
+
ok: !1,
|
|
1031
|
+
message: "contains malformed Unicode."
|
|
1032
|
+
};
|
|
1033
|
+
if (typeof e == "number") return Number.isFinite(e) ? {
|
|
1034
|
+
ok: !0,
|
|
1035
|
+
value: e
|
|
1036
|
+
} : {
|
|
1037
|
+
ok: !1,
|
|
1038
|
+
message: "must be a finite number."
|
|
1039
|
+
};
|
|
1040
|
+
if (typeof e == "boolean" || e === null) return {
|
|
1041
|
+
ok: !0,
|
|
1042
|
+
value: e
|
|
1043
|
+
};
|
|
1044
|
+
if (Array.isArray(e)) {
|
|
1045
|
+
let t = [];
|
|
1046
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
1047
|
+
let r = e[n];
|
|
1048
|
+
if (typeof r != "string") return {
|
|
1049
|
+
ok: !1,
|
|
1050
|
+
message: "must be an array of strings."
|
|
1051
|
+
};
|
|
1052
|
+
if (!B(r)) return {
|
|
1053
|
+
ok: !1,
|
|
1054
|
+
message: "contains malformed Unicode."
|
|
1055
|
+
};
|
|
1056
|
+
t.push(r);
|
|
1057
|
+
}
|
|
1058
|
+
return {
|
|
1059
|
+
ok: !0,
|
|
1060
|
+
value: Object.freeze(t)
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
return {
|
|
1064
|
+
ok: !1,
|
|
1065
|
+
message: "must be a string, finite number, boolean, null or string array."
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
function U(e) {
|
|
1069
|
+
if (typeof e != "object" || !e || Array.isArray(e)) return !1;
|
|
1070
|
+
let t = Object.getPrototypeOf(e);
|
|
1071
|
+
return t === Object.prototype || t === null;
|
|
1072
|
+
}
|
|
1073
|
+
function He(e) {
|
|
1074
|
+
return Object.freeze(e.parameters), e.generator && Object.freeze(e.generator), Object.freeze(e);
|
|
1075
|
+
}
|
|
1076
|
+
function Ue(e) {
|
|
1077
|
+
if (!e || typeof e != "object" || Array.isArray(e)) throw TypeError("generator must be an object with string name and version.");
|
|
1078
|
+
if (typeof e.name != "string" || typeof e.version != "string") throw TypeError("generator must have string name and version.");
|
|
1079
|
+
if (!B(e.name) || !B(e.version)) throw TypeError("generator name and version must be well-formed Unicode strings.");
|
|
1080
|
+
return Object.freeze({
|
|
1081
|
+
name: e.name,
|
|
1082
|
+
version: e.version
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
function We(e) {
|
|
1086
|
+
return typeof e == "string" ? `"${e.length > 48 ? `${e.slice(0, 48)}…` : e}"` : e === null ? "null" : Array.isArray(e) ? "an array" : typeof e;
|
|
1087
|
+
}
|
|
1088
|
+
function Ge(e, t) {
|
|
1089
|
+
return e.length > t ? e.length : I.encode(e).byteLength;
|
|
1090
|
+
}
|
|
1091
|
+
function Ke(e, t) {
|
|
1092
|
+
let n;
|
|
1093
|
+
try {
|
|
1094
|
+
let t = JSON.stringify(e);
|
|
1095
|
+
if (typeof t != "string") return null;
|
|
1096
|
+
n = t;
|
|
1097
|
+
} catch {
|
|
1098
|
+
return null;
|
|
1099
|
+
}
|
|
1100
|
+
return Ge(n, t);
|
|
1101
|
+
}
|
|
1102
|
+
function qe(e) {
|
|
1103
|
+
if (e === void 0) return F;
|
|
1104
|
+
if (typeof e != "object" || !e) throw TypeError("parseLocalState options must be an object.");
|
|
1105
|
+
let { maxLength: t } = e;
|
|
1106
|
+
if (t === void 0) return F;
|
|
1107
|
+
if (typeof t != "number" || !Number.isSafeInteger(t) || t <= 0) throw RangeError("maxLength must be a finite positive integer.");
|
|
1108
|
+
return t;
|
|
1109
|
+
}
|
|
1110
|
+
function Je(e, t, n) {
|
|
1111
|
+
if (!e || e.syntax !== "local" || typeof e.source != "string") throw TypeError("createLocalStateFile requires a compiled local document.");
|
|
1112
|
+
if (!t || typeof t != "object" || Array.isArray(t)) throw TypeError("createLocalStateFile requires a state object.");
|
|
1113
|
+
let r = Object.keys(e.bindings).filter((e) => !e.startsWith("@")).sort(), i = new Set(r), a = /* @__PURE__ */ new Map();
|
|
1114
|
+
for (let n of Object.keys(t)) {
|
|
1115
|
+
if (Object.hasOwn(e.computations ?? {}, n)) continue;
|
|
1116
|
+
if (n.startsWith("@")) {
|
|
1117
|
+
if (!Object.hasOwn(e.bindings, n)) throw Error(`Cannot persist parameter "${n}": it is not a binding of this document.`);
|
|
1118
|
+
continue;
|
|
1119
|
+
}
|
|
1120
|
+
if (!i.has(n)) throw Error(`Cannot persist parameter "${n}": it is not a public binding of this document.`);
|
|
1121
|
+
let r = H(t[n]);
|
|
1122
|
+
if (!r.ok) throw TypeError(`Cannot persist parameter "${n}": the value ${r.message}`);
|
|
1123
|
+
a.set(n, r.value);
|
|
1124
|
+
}
|
|
1125
|
+
let o = {};
|
|
1126
|
+
for (let e of r) {
|
|
1127
|
+
if (!a.has(e)) throw Error(`Cannot persist the document: parameter "${e}" is missing from the supplied state.`);
|
|
1128
|
+
o[e] = a.get(e);
|
|
1129
|
+
}
|
|
1130
|
+
let s = {
|
|
1131
|
+
format: P,
|
|
1132
|
+
syntax: v,
|
|
1133
|
+
sourceDigest: V(e.source),
|
|
1134
|
+
parameters: o
|
|
1135
|
+
};
|
|
1136
|
+
return n !== void 0 && (s.generator = Ue(n)), He(s);
|
|
1137
|
+
}
|
|
1138
|
+
function Ye(e, t) {
|
|
1139
|
+
let n = [], r = (e, t) => R(n, e, t), i = e;
|
|
1140
|
+
if (typeof e == "string") {
|
|
1141
|
+
if (Ge(e, t) > t) return {
|
|
1142
|
+
ok: !1,
|
|
1143
|
+
diagnostics: [L("local.state.size", `The state payload exceeds the ${t}-byte limit.`)]
|
|
1144
|
+
};
|
|
1145
|
+
if (!B(e)) return {
|
|
1146
|
+
ok: !1,
|
|
1147
|
+
diagnostics: [L("local.state.utf", "The state payload contains malformed Unicode.")]
|
|
1148
|
+
};
|
|
1149
|
+
try {
|
|
1150
|
+
i = JSON.parse(e);
|
|
1151
|
+
} catch (e) {
|
|
1152
|
+
return {
|
|
1153
|
+
ok: !1,
|
|
1154
|
+
diagnostics: [L("local.state.json", `The state payload is not valid JSON: ${z(e)}`)]
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
} else {
|
|
1158
|
+
let n = Ke(e, t);
|
|
1159
|
+
if (n === null) return {
|
|
1160
|
+
ok: !1,
|
|
1161
|
+
diagnostics: [L("local.state.shape", "The state payload must be a JSON object.")]
|
|
1162
|
+
};
|
|
1163
|
+
if (n > t) return {
|
|
1164
|
+
ok: !1,
|
|
1165
|
+
diagnostics: [L("local.state.size", `The state payload exceeds the ${t}-byte limit.`)]
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
if (!U(i)) return {
|
|
1169
|
+
ok: !1,
|
|
1170
|
+
diagnostics: [L("local.state.shape", "The state payload must be a JSON object.")]
|
|
1171
|
+
};
|
|
1172
|
+
Object.getOwnPropertySymbols(i).length > 0 && r("local.state.shape", "The state payload cannot use symbol keys.");
|
|
1173
|
+
for (let e of Object.keys(i)) Be.has(e) || r("local.state.key", `Unknown top-level state key "${e}".`);
|
|
1174
|
+
let a = i.format;
|
|
1175
|
+
a !== "reactive-md-state/v1" && r("local.state.format", `Unsupported state format ${We(a)}; expected "${P}".`);
|
|
1176
|
+
let o = i.syntax;
|
|
1177
|
+
o !== "local-draft-2" && r("local.state.syntax", `Unsupported state syntax ${We(o)}; expected "${v}".`);
|
|
1178
|
+
let s = i.sourceDigest;
|
|
1179
|
+
typeof s == "string" && Le.test(s) || r("local.state.digest", "sourceDigest must match \"fnv1a32:\" followed by 8 lowercase hexadecimal digits.");
|
|
1180
|
+
let c = {}, l = i.parameters;
|
|
1181
|
+
if (!U(l)) r("local.state.parameters", "parameters must be a JSON object of public binding values.");
|
|
1182
|
+
else for (let e of Object.keys(l).sort()) {
|
|
1183
|
+
if (e === "__proto__") {
|
|
1184
|
+
r("local.state.parameter.prototype", "Parameter names cannot be \"__proto__\".");
|
|
1185
|
+
continue;
|
|
1186
|
+
}
|
|
1187
|
+
if (e.startsWith("@")) {
|
|
1188
|
+
r("local.state.parameter.internal", `Internal parameter "${e}" cannot be persisted.`);
|
|
1189
|
+
continue;
|
|
1190
|
+
}
|
|
1191
|
+
let t = H(l[e]);
|
|
1192
|
+
t.ok ? c[e] = t.value : r("local.state.parameter.value", `Parameter "${e}" ${t.message}`);
|
|
1193
|
+
}
|
|
1194
|
+
let u;
|
|
1195
|
+
if (Object.hasOwn(i, "generator")) {
|
|
1196
|
+
let e = i.generator;
|
|
1197
|
+
if (!U(e)) r("local.state.generator", "generator must be an object with string name and version.");
|
|
1198
|
+
else {
|
|
1199
|
+
for (let t of Object.keys(e)) Ve.has(t) || r("local.state.generator", `generator has unknown key "${t}".`);
|
|
1200
|
+
typeof e.name != "string" || typeof e.version != "string" ? r("local.state.generator", "generator must have string name and version.") : !B(e.name) || !B(e.version) ? r("local.state.utf", "generator contains malformed Unicode.") : u = Object.freeze({
|
|
1201
|
+
name: e.name,
|
|
1202
|
+
version: e.version
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
if (n.length) return {
|
|
1207
|
+
ok: !1,
|
|
1208
|
+
diagnostics: n
|
|
1209
|
+
};
|
|
1210
|
+
let d = {
|
|
1211
|
+
format: P,
|
|
1212
|
+
syntax: v,
|
|
1213
|
+
sourceDigest: s,
|
|
1214
|
+
parameters: c
|
|
1215
|
+
};
|
|
1216
|
+
return u && (d.generator = u), {
|
|
1217
|
+
ok: !0,
|
|
1218
|
+
file: He(d)
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
function W(e, t) {
|
|
1222
|
+
let n = qe(t);
|
|
1223
|
+
try {
|
|
1224
|
+
return Ye(e, n);
|
|
1225
|
+
} catch (e) {
|
|
1226
|
+
return {
|
|
1227
|
+
ok: !1,
|
|
1228
|
+
diagnostics: [L("local.state.invalid", `Cannot read the local state: ${z(e)}`)]
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
function Xe(e) {
|
|
1233
|
+
let t = /* @__PURE__ */ new Map(), n = (e) => {
|
|
1234
|
+
for (let r of e) t.set(r.id, r), r.children && n(r.children);
|
|
1235
|
+
};
|
|
1236
|
+
return n(e.nodes), t;
|
|
1237
|
+
}
|
|
1238
|
+
function Ze(e) {
|
|
1239
|
+
let t = Xe(e), n = /* @__PURE__ */ new Map(), r = [];
|
|
1240
|
+
for (let [i, a] of Object.entries(e.bindingSlots ?? {})) {
|
|
1241
|
+
let e = t.get(i);
|
|
1242
|
+
if (!e) continue;
|
|
1243
|
+
let o = {
|
|
1244
|
+
node: e,
|
|
1245
|
+
slots: []
|
|
1246
|
+
};
|
|
1247
|
+
for (let [t, r] of Object.entries(a)) o.slots.push({
|
|
1248
|
+
slot: t,
|
|
1249
|
+
key: r
|
|
1250
|
+
}), r.startsWith("@") || n.set(r, {
|
|
1251
|
+
node: e,
|
|
1252
|
+
slot: t
|
|
1253
|
+
});
|
|
1254
|
+
o.slots.length && r.push(o);
|
|
1255
|
+
}
|
|
1256
|
+
let i = [];
|
|
1257
|
+
for (let [r, a] of Object.entries(e.bindings)) {
|
|
1258
|
+
if (r.startsWith("@")) continue;
|
|
1259
|
+
let e = n.get(r);
|
|
1260
|
+
if (e) {
|
|
1261
|
+
i.push({
|
|
1262
|
+
key: r,
|
|
1263
|
+
binding: a,
|
|
1264
|
+
node: e.node,
|
|
1265
|
+
slot: e.slot
|
|
1266
|
+
});
|
|
1267
|
+
continue;
|
|
1268
|
+
}
|
|
1269
|
+
let o = a.owner && t.has(a.owner) ? a.owner : a.nodeIds.find((e) => t.has(e));
|
|
1270
|
+
i.push({
|
|
1271
|
+
key: r,
|
|
1272
|
+
binding: a,
|
|
1273
|
+
node: o ? t.get(o) : void 0
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
return {
|
|
1277
|
+
plans: i,
|
|
1278
|
+
groups: r
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
function G(e, t, n) {
|
|
1282
|
+
let r = [];
|
|
1283
|
+
for (let i of t.plans) i.slot === void 0 && Object.hasOwn(n, i.key) && (i.node ? Object.is(e.get(i.node), n[i.key]) || r.push(...e.set(i.node, n[i.key])) : r.push(L("local.state.document", `The document has no component for parameter "${i.key}".`)));
|
|
1284
|
+
for (let i of t.groups) {
|
|
1285
|
+
let t = {}, a = !1;
|
|
1286
|
+
for (let { slot: e, key: r } of i.slots) Object.hasOwn(n, r) && (t[e] = n[r], a = !0);
|
|
1287
|
+
a && r.push(...e.setMany(i.node, t));
|
|
1288
|
+
}
|
|
1289
|
+
return r;
|
|
1290
|
+
}
|
|
1291
|
+
function Qe(e, t) {
|
|
1292
|
+
let n = e.snapshot(), r = {};
|
|
1293
|
+
for (let e of t) {
|
|
1294
|
+
let t = n.state[e];
|
|
1295
|
+
r[e] = Array.isArray(t) ? Object.freeze([...t]) : t;
|
|
1296
|
+
}
|
|
1297
|
+
return Object.freeze(r);
|
|
1298
|
+
}
|
|
1299
|
+
function $e(e, t, n, r) {
|
|
1300
|
+
let i = W(t, r);
|
|
1301
|
+
if (!i.ok) return i;
|
|
1302
|
+
if (!e || e.syntax !== "local" || typeof e.source != "string" || !Array.isArray(e.nodes) || !e.bindings) return {
|
|
1303
|
+
ok: !1,
|
|
1304
|
+
diagnostics: [L("local.state.document", "resolveLocalState requires a compiled local document.")]
|
|
1305
|
+
};
|
|
1306
|
+
if (i.file.syntax !== "local-draft-2") return {
|
|
1307
|
+
ok: !1,
|
|
1308
|
+
diagnostics: [L("local.state.syntax", `This state file uses syntax "${i.file.syntax}", but this build accepts "${v}".`)]
|
|
1309
|
+
};
|
|
1310
|
+
if (i.file.sourceDigest !== V(e.source)) return {
|
|
1311
|
+
ok: !1,
|
|
1312
|
+
diagnostics: [L("local.state.source", "This state file was created for a different document (source digest mismatch).")]
|
|
1313
|
+
};
|
|
1314
|
+
let a = Ze(e), o = new Set(a.plans.map((e) => e.key)), s = [];
|
|
1315
|
+
for (let e of Object.keys(i.file.parameters)) o.has(e) || R(s, "local.state.parameter.unknown", `The state contains unknown parameter "${e}" for this document.`);
|
|
1316
|
+
for (let e of o) Object.hasOwn(i.file.parameters, e) || R(s, "local.state.parameter.missing", `The state is missing parameter "${e}".`);
|
|
1317
|
+
if (s.length) return {
|
|
1318
|
+
ok: !1,
|
|
1319
|
+
diagnostics: s
|
|
1320
|
+
};
|
|
1321
|
+
let c;
|
|
1322
|
+
try {
|
|
1323
|
+
c = _(e);
|
|
1324
|
+
} catch (e) {
|
|
1325
|
+
return {
|
|
1326
|
+
ok: !1,
|
|
1327
|
+
diagnostics: [L("local.state.document", `Cannot validate this document: ${z(e)}`)]
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
try {
|
|
1331
|
+
if (n) {
|
|
1332
|
+
let e = G(c, a, n);
|
|
1333
|
+
if (e.length) return {
|
|
1334
|
+
ok: !1,
|
|
1335
|
+
diagnostics: e
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
let e = G(c, a, i.file.parameters);
|
|
1339
|
+
if (e.length) return {
|
|
1340
|
+
ok: !1,
|
|
1341
|
+
diagnostics: e
|
|
1342
|
+
};
|
|
1343
|
+
let t = [...o].sort();
|
|
1344
|
+
return {
|
|
1345
|
+
ok: !0,
|
|
1346
|
+
file: i.file,
|
|
1347
|
+
state: Qe(c, t)
|
|
1348
|
+
};
|
|
1349
|
+
} finally {
|
|
1350
|
+
c.dispose();
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
function et(e, t, n) {
|
|
1354
|
+
try {
|
|
1355
|
+
return $e(e, t, void 0, n);
|
|
1356
|
+
} catch (e) {
|
|
1357
|
+
return {
|
|
1358
|
+
ok: !1,
|
|
1359
|
+
diagnostics: [L("local.state.invalid", `Cannot resolve the local state: ${z(e)}`)]
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
function tt(e, t, n) {
|
|
1364
|
+
let r;
|
|
1365
|
+
try {
|
|
1366
|
+
r = $e(e.document, t, e.snapshot().state, n);
|
|
1367
|
+
} catch (e) {
|
|
1368
|
+
return [L("local.state.invalid", `Cannot apply the local state: ${z(e)}`)];
|
|
1369
|
+
}
|
|
1370
|
+
if (!r.ok) return r.diagnostics;
|
|
1371
|
+
let i = Ze(e.document);
|
|
1372
|
+
try {
|
|
1373
|
+
return G(e, i, r.state);
|
|
1374
|
+
} catch (e) {
|
|
1375
|
+
return [L("local.state.invalid", `Cannot apply the local state: ${z(e)}`)];
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
function nt(e, t) {
|
|
1379
|
+
return Je(e.document, e.getParameters(), t);
|
|
1380
|
+
}
|
|
1381
|
+
function rt(e, t, n) {
|
|
1382
|
+
let r = W(t, n);
|
|
1383
|
+
return r.ok ? tt(e, r.file, n) : r.diagnostics;
|
|
1384
|
+
}
|
|
1385
|
+
function it(e) {
|
|
1386
|
+
if (!e || typeof e != "object" || Array.isArray(e)) throw TypeError("serializeLocalState requires a state file.");
|
|
1387
|
+
if (!e.parameters || typeof e.parameters != "object" || Array.isArray(e.parameters)) throw TypeError("serializeLocalState requires an object of parameters.");
|
|
1388
|
+
let t = Object.create(null);
|
|
1389
|
+
for (let n of Object.keys(e.parameters).sort()) {
|
|
1390
|
+
if (n === "__proto__" || n.startsWith("@")) throw TypeError(`Cannot serialize parameter "${n}".`);
|
|
1391
|
+
let r = H(e.parameters[n]);
|
|
1392
|
+
if (!r.ok) throw TypeError(`Cannot serialize parameter "${n}": the value ${r.message}`);
|
|
1393
|
+
t[n] = r.value;
|
|
1394
|
+
}
|
|
1395
|
+
let n = {
|
|
1396
|
+
format: e.format,
|
|
1397
|
+
syntax: e.syntax,
|
|
1398
|
+
sourceDigest: e.sourceDigest,
|
|
1399
|
+
parameters: t
|
|
1400
|
+
};
|
|
1401
|
+
if (e.generator !== void 0) {
|
|
1402
|
+
let t = Ue(e.generator);
|
|
1403
|
+
n.generator = {
|
|
1404
|
+
name: t.name,
|
|
1405
|
+
version: t.version
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
return JSON.stringify(n);
|
|
1409
|
+
}
|
|
1410
|
+
// src/local/retention.ts
|
|
1411
|
+
function at(e) {
|
|
1412
|
+
let t = /* @__PURE__ */ new Map(), n = (e) => {
|
|
1413
|
+
for (let r of e) t.set(r.id, r), r.children && n(r.children);
|
|
1414
|
+
};
|
|
1415
|
+
return n(e.nodes), t;
|
|
1416
|
+
}
|
|
1417
|
+
function ot(e, t, n) {
|
|
1418
|
+
let r = e.bindingSlots?.[t.id];
|
|
1419
|
+
return r !== void 0 && Object.values(r).includes(n);
|
|
1420
|
+
}
|
|
1421
|
+
function st(e) {
|
|
1422
|
+
let t = at(e), n = /* @__PURE__ */ new Map();
|
|
1423
|
+
for (let [r, i] of Object.entries(e.bindings)) {
|
|
1424
|
+
let a = i.nodeIds.flatMap((e) => {
|
|
1425
|
+
let n = t.get(e);
|
|
1426
|
+
return n ? [n] : [];
|
|
1427
|
+
});
|
|
1428
|
+
if (!a.length || r.startsWith("@") || a.some((t) => t.attrs?.bind !== r && !ot(e, t, r) || t.name === "timer" || t.name === "checklist")) continue;
|
|
1429
|
+
let o = a.flatMap((e) => Object.hasOwn(e.attrs ?? {}, "initial") ? [e.attrs.initial] : []).sort();
|
|
1430
|
+
n.set(r, {
|
|
1431
|
+
type: i.type,
|
|
1432
|
+
initialDefinition: JSON.stringify([i.initial, o])
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
return n;
|
|
1436
|
+
}
|
|
1437
|
+
function K(e, t) {
|
|
1438
|
+
return Object.freeze({
|
|
1439
|
+
name: e,
|
|
1440
|
+
reason: t
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
function ct(e) {
|
|
1444
|
+
let t = st(e.previous), n = st(e.next), r = {}, i = [], a = [];
|
|
1445
|
+
for (let o of Object.keys(e.state).sort()) {
|
|
1446
|
+
if (o.startsWith("@")) {
|
|
1447
|
+
a.push(K(o, "internal"));
|
|
1448
|
+
continue;
|
|
1449
|
+
}
|
|
1450
|
+
if (!Object.hasOwn(e.previous.bindings, o) || !Object.hasOwn(e.next.bindings, o)) {
|
|
1451
|
+
a.push(K(o, "unknown"));
|
|
1452
|
+
continue;
|
|
1453
|
+
}
|
|
1454
|
+
let s = t.get(o), c = n.get(o);
|
|
1455
|
+
if (!s || !c) {
|
|
1456
|
+
a.push(K(o, "unretainable"));
|
|
1457
|
+
continue;
|
|
1458
|
+
}
|
|
1459
|
+
if (s.type !== c.type) {
|
|
1460
|
+
a.push(K(o, "type"));
|
|
1461
|
+
continue;
|
|
1462
|
+
}
|
|
1463
|
+
if (s.initialDefinition !== c.initialDefinition) {
|
|
1464
|
+
a.push(K(o, "initial"));
|
|
1465
|
+
continue;
|
|
1466
|
+
}
|
|
1467
|
+
let l = e.state[o];
|
|
1468
|
+
r[o] = Array.isArray(l) ? Object.freeze([...l]) : l, i.push(o);
|
|
1469
|
+
}
|
|
1470
|
+
return Object.freeze({
|
|
1471
|
+
values: Object.freeze(r),
|
|
1472
|
+
retained: Object.freeze(i),
|
|
1473
|
+
dropped: Object.freeze(a)
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
function lt(e, t, n) {
|
|
1477
|
+
return Object.freeze({
|
|
1478
|
+
retained: Object.freeze([...e]),
|
|
1479
|
+
dropped: Object.freeze(t.map((e) => Object.freeze({ ...e }))),
|
|
1480
|
+
diagnostics: Object.freeze([...n])
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
function ut(e, t) {
|
|
1484
|
+
let n = Object.keys(t.values).sort();
|
|
1485
|
+
if (!e.setParameters(t.values).length) return lt(n, t.dropped, []);
|
|
1486
|
+
let r = [], i = [...t.dropped], a = [];
|
|
1487
|
+
for (let o of n) {
|
|
1488
|
+
let n = e.setParameter(o, t.values[o]);
|
|
1489
|
+
n.length ? (i.push(K(o, "invalid")), a.push(...n)) : r.push(o);
|
|
1490
|
+
}
|
|
1491
|
+
return i.sort((e, t) => e.name < t.name ? -1 : +(e.name > t.name)), lt(r, i, a);
|
|
1492
|
+
}
|
|
1493
|
+
// src/local/worker.ts
|
|
1494
|
+
var dt = 150;
|
|
1495
|
+
function q(e) {
|
|
1496
|
+
return e instanceof Error ? e.message : String(e);
|
|
1497
|
+
}
|
|
1498
|
+
function J() {
|
|
1499
|
+
return typeof performance < "u" ? performance.now() : Date.now();
|
|
1500
|
+
}
|
|
1501
|
+
function Y(e) {
|
|
1502
|
+
return Number.isFinite(e) ? Math.max(0, Math.round(e)) : 0;
|
|
1503
|
+
}
|
|
1504
|
+
function X(e) {
|
|
1505
|
+
return {
|
|
1506
|
+
code: "local.worker.compile",
|
|
1507
|
+
message: `Compilation failed: ${q(e)}`,
|
|
1508
|
+
severity: "error",
|
|
1509
|
+
range: {
|
|
1510
|
+
start: 0,
|
|
1511
|
+
end: 0
|
|
1512
|
+
},
|
|
1513
|
+
line: 1,
|
|
1514
|
+
column: 1
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
var ft = class {
|
|
1518
|
+
options;
|
|
1519
|
+
delay;
|
|
1520
|
+
worker = null;
|
|
1521
|
+
timer = null;
|
|
1522
|
+
queuedSource = null;
|
|
1523
|
+
inFlight = null;
|
|
1524
|
+
nextId = 1;
|
|
1525
|
+
pending = !1;
|
|
1526
|
+
disposed = !1;
|
|
1527
|
+
constructor(e) {
|
|
1528
|
+
this.options = e;
|
|
1529
|
+
let t = e.delay;
|
|
1530
|
+
this.delay = typeof t == "number" && Number.isFinite(t) ? Math.max(0, t) : 150;
|
|
1531
|
+
try {
|
|
1532
|
+
let t = e.createWorker();
|
|
1533
|
+
t.onmessage = (e) => this.receive(e.data), t.onerror = (e) => {
|
|
1534
|
+
let t = e && typeof e.message == "string" ? String(e.message) : "";
|
|
1535
|
+
this.handleWorkerFailure(t || "The compile worker encountered an error");
|
|
1536
|
+
}, t.onmessageerror = () => this.handleWorkerFailure("The compile worker could not deliver the compile result"), this.worker = t;
|
|
1537
|
+
} catch (t) {
|
|
1538
|
+
this.worker = null, e.onModeChange?.("fallback", `Could not start the compile worker: ${q(t)}`);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
schedule(e) {
|
|
1542
|
+
this.disposed || (this.queuedSource = e, this.clearTimer(), this.timer = setTimeout(() => {
|
|
1543
|
+
this.timer = null, this.drain();
|
|
1544
|
+
}, this.delay), this.setPending(!0));
|
|
1545
|
+
}
|
|
1546
|
+
dispose() {
|
|
1547
|
+
if (this.disposed) return;
|
|
1548
|
+
this.disposed = !0, this.clearTimer(), this.queuedSource = null, this.inFlight = null;
|
|
1549
|
+
let e = this.worker;
|
|
1550
|
+
if (this.worker = null, e) {
|
|
1551
|
+
e.onmessage = null, e.onerror = null, e.onmessageerror = null;
|
|
1552
|
+
try {
|
|
1553
|
+
e.terminate();
|
|
1554
|
+
} catch {}
|
|
1555
|
+
}
|
|
1556
|
+
this.pending = !1;
|
|
1557
|
+
}
|
|
1558
|
+
drain() {
|
|
1559
|
+
if (this.disposed || this.timer !== null || this.inFlight !== null) return;
|
|
1560
|
+
let e = this.queuedSource;
|
|
1561
|
+
e === null ? this.setPending(!1) : (this.queuedSource = null, this.compile(e));
|
|
1562
|
+
}
|
|
1563
|
+
compile(e) {
|
|
1564
|
+
let t = this.worker;
|
|
1565
|
+
if (!t) {
|
|
1566
|
+
this.compileFallback(e);
|
|
1567
|
+
return;
|
|
1568
|
+
}
|
|
1569
|
+
let n = this.nextId++;
|
|
1570
|
+
this.inFlight = {
|
|
1571
|
+
id: n,
|
|
1572
|
+
source: e
|
|
1573
|
+
};
|
|
1574
|
+
try {
|
|
1575
|
+
t.postMessage({
|
|
1576
|
+
id: n,
|
|
1577
|
+
source: e
|
|
1578
|
+
});
|
|
1579
|
+
} catch (t) {
|
|
1580
|
+
this.inFlight = null, this.handleWorkerFailure(`Could not send the source to the compile worker: ${q(t)}`), this.compileFallback(e);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
compileFallback(e) {
|
|
1584
|
+
if (this.disposed) return;
|
|
1585
|
+
let t = J(), n;
|
|
1586
|
+
try {
|
|
1587
|
+
n = (this.options.fallbackCompile ?? h)(e);
|
|
1588
|
+
} catch (e) {
|
|
1589
|
+
n = {
|
|
1590
|
+
ok: !1,
|
|
1591
|
+
diagnostics: [X(e)]
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
this.deliver({
|
|
1595
|
+
source: e,
|
|
1596
|
+
result: n,
|
|
1597
|
+
duration: Y(J() - t),
|
|
1598
|
+
mode: "fallback"
|
|
1599
|
+
}), this.finishRun();
|
|
1600
|
+
}
|
|
1601
|
+
receive(e) {
|
|
1602
|
+
if (this.disposed) return;
|
|
1603
|
+
let t = this.inFlight;
|
|
1604
|
+
if (!t || !e || e.id !== t.id) return;
|
|
1605
|
+
this.inFlight = null;
|
|
1606
|
+
let n = this.queuedSource;
|
|
1607
|
+
n !== null && n !== t.source || (n === t.source && (this.queuedSource = null, this.clearTimer()), e.ok ? this.deliver({
|
|
1608
|
+
source: t.source,
|
|
1609
|
+
result: e.result,
|
|
1610
|
+
duration: Y(e.duration),
|
|
1611
|
+
mode: "worker"
|
|
1612
|
+
}) : this.deliver({
|
|
1613
|
+
source: t.source,
|
|
1614
|
+
result: {
|
|
1615
|
+
ok: !1,
|
|
1616
|
+
diagnostics: [X(e.message)]
|
|
1617
|
+
},
|
|
1618
|
+
duration: 0,
|
|
1619
|
+
mode: "worker"
|
|
1620
|
+
})), this.finishRun();
|
|
1621
|
+
}
|
|
1622
|
+
handleWorkerFailure(e) {
|
|
1623
|
+
if (this.disposed) return;
|
|
1624
|
+
this.degrade(e);
|
|
1625
|
+
let t = this.inFlight;
|
|
1626
|
+
this.inFlight = null, t && (this.queuedSource === null || this.queuedSource === t.source) && (this.queuedSource === t.source && (this.queuedSource = null, this.clearTimer()), this.compileFallback(t.source)), this.finishRun();
|
|
1627
|
+
}
|
|
1628
|
+
degrade(e) {
|
|
1629
|
+
let t = this.worker;
|
|
1630
|
+
if (t) {
|
|
1631
|
+
this.worker = null, t.onmessage = null, t.onerror = null, t.onmessageerror = null;
|
|
1632
|
+
try {
|
|
1633
|
+
t.terminate();
|
|
1634
|
+
} catch {}
|
|
1635
|
+
this.options.onModeChange?.("fallback", e);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
finishRun() {
|
|
1639
|
+
this.disposed || (this.drain(), !this.disposed && this.setPending(this.timer !== null || this.inFlight !== null || this.queuedSource !== null));
|
|
1640
|
+
}
|
|
1641
|
+
deliver(e) {
|
|
1642
|
+
this.disposed || this.options.onResult(e);
|
|
1643
|
+
}
|
|
1644
|
+
setPending(e) {
|
|
1645
|
+
this.pending !== e && (this.pending = e, this.options.onPendingChange?.(e));
|
|
1646
|
+
}
|
|
1647
|
+
clearTimer() {
|
|
1648
|
+
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1651
|
+
function pt(e, t, n) {
|
|
1652
|
+
try {
|
|
1653
|
+
e.postMessage({
|
|
1654
|
+
id: t,
|
|
1655
|
+
ok: !1,
|
|
1656
|
+
message: n
|
|
1657
|
+
});
|
|
1658
|
+
} catch {}
|
|
1659
|
+
}
|
|
1660
|
+
function mt(e) {
|
|
1661
|
+
let t = e === void 0 ? globalThis : e;
|
|
1662
|
+
if (!t || typeof t.postMessage != "function") throw TypeError("startLocalCompileWorker requires a worker scope with postMessage");
|
|
1663
|
+
t.onmessage = (e) => {
|
|
1664
|
+
let n = e?.data;
|
|
1665
|
+
if (!n || typeof n.id != "number" || typeof n.source != "string") return;
|
|
1666
|
+
let r = J();
|
|
1667
|
+
try {
|
|
1668
|
+
let e = h(n.source), i = Y(J() - r);
|
|
1669
|
+
try {
|
|
1670
|
+
t.postMessage({
|
|
1671
|
+
id: n.id,
|
|
1672
|
+
ok: !0,
|
|
1673
|
+
result: e,
|
|
1674
|
+
duration: i
|
|
1675
|
+
});
|
|
1676
|
+
} catch (e) {
|
|
1677
|
+
pt(t, n.id, `Could not return the compile result: ${q(e)}`);
|
|
1678
|
+
}
|
|
1679
|
+
} catch (e) {
|
|
1680
|
+
pt(t, n.id, q(e));
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
}
|
|
1684
|
+
// src/shareable.ts
|
|
1685
|
+
var ht = "reactive-md-html/v1", gt = /^[A-Za-z][A-Za-z0-9_-]*$/, _t = /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/, vt = /^data:image\/(?:png|jpeg|gif|webp);base64,[A-Za-z0-9+/]+={0,2}$/, yt = /[\u0000-\u001f\u007f-\u009f]/, bt = 64, xt = 41943040, St = 4096;
|
|
1686
|
+
function Z(e, t = !1) {
|
|
1687
|
+
let n = e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
1688
|
+
return t && (n = n.replace(/"/g, """).replace(/'/g, "'")), n;
|
|
1689
|
+
}
|
|
1690
|
+
function Ct(e) {
|
|
1691
|
+
return e.replace(/<\/style/gi, "<\\/style");
|
|
1692
|
+
}
|
|
1693
|
+
function wt(e) {
|
|
1694
|
+
return e.replace(/<\/script/gi, "<\\/script").replace(/<!--/g, "<\\!--");
|
|
1695
|
+
}
|
|
1696
|
+
function Q(e) {
|
|
1697
|
+
return Z(e, !0);
|
|
1698
|
+
}
|
|
1699
|
+
function Tt(e) {
|
|
1700
|
+
let t = JSON.stringify(e);
|
|
1701
|
+
if (typeof t != "string") throw TypeError("Cannot serialize a non-JSON value for an inline script.");
|
|
1702
|
+
return t.replace(/[<>&\u2028\u2029]/g, (e) => {
|
|
1703
|
+
switch (e) {
|
|
1704
|
+
case "<": return "\\u003c";
|
|
1705
|
+
case ">": return "\\u003e";
|
|
1706
|
+
case "&": return "\\u0026";
|
|
1707
|
+
case "\u2028": return "\\u2028";
|
|
1708
|
+
default: return "\\u2029";
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
function $(e) {
|
|
1713
|
+
return Array.isArray(e) ? e.slice() : e;
|
|
1714
|
+
}
|
|
1715
|
+
function Et(e) {
|
|
1716
|
+
if (e === void 0) return;
|
|
1717
|
+
if (!e || typeof e != "object" || Array.isArray(e)) throw TypeError("images must be an object mapping relative URLs to data: image URLs.");
|
|
1718
|
+
let t = Object.entries(e);
|
|
1719
|
+
if (t.length > bt) throw RangeError(`images cannot contain more than ${bt} entries.`);
|
|
1720
|
+
let n = 0;
|
|
1721
|
+
for (let [e, r] of t) {
|
|
1722
|
+
if (!e || e.length > St || yt.test(e) || e === "__proto__") throw TypeError("Every image key must be a bounded, control-free URL.");
|
|
1723
|
+
if (typeof r != "string" || !vt.test(r)) throw TypeError(`The image map for "${e}" must contain a base64 PNG, JPEG, GIF or WebP data URL.`);
|
|
1724
|
+
if (n += r.length, n > xt) throw RangeError("The embedded image map exceeds the 40 MiB budget.");
|
|
1725
|
+
}
|
|
1726
|
+
return Object.fromEntries(t);
|
|
1727
|
+
}
|
|
1728
|
+
function Dt(e, t) {
|
|
1729
|
+
let n = et(e, t);
|
|
1730
|
+
if (!n.ok) return n;
|
|
1731
|
+
let r = {};
|
|
1732
|
+
for (let [t, i] of Object.entries(e.bindings)) r[t] = Object.hasOwn(n.state, t) ? {
|
|
1733
|
+
...i,
|
|
1734
|
+
initial: $(n.state[t])
|
|
1735
|
+
} : i;
|
|
1736
|
+
let i = { ...e.initialState };
|
|
1737
|
+
for (let [e, t] of Object.entries(n.state)) i[e] = $(t);
|
|
1738
|
+
return {
|
|
1739
|
+
ok: !0,
|
|
1740
|
+
baseline: {
|
|
1741
|
+
document: {
|
|
1742
|
+
...e,
|
|
1743
|
+
bindings: r,
|
|
1744
|
+
initialState: i
|
|
1745
|
+
},
|
|
1746
|
+
state: n.state
|
|
1747
|
+
}
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
var Ot = "\n:root { color-scheme: light; background: #f5f7fb; }\nhtml, body { margin: 0; }\nbody.reactive-md-export {\n min-height: 100vh;\n padding: clamp(16px, 4vw, 48px);\n background: #f5f7fb;\n color: #17233d;\n font-family: system-ui, -apple-system, \"Segoe UI\", sans-serif;\n}\n.reactive-md-export-root { max-width: 840px; margin: 0 auto; }\n@media print {\n :root, html, body.reactive-md-export { background: #fff !important; }\n body.reactive-md-export { min-height: 0; padding: 0 !important; }\n .reactive-md-export-root { max-width: none !important; margin: 0 !important; }\n}\n";
|
|
1751
|
+
function kt(e) {
|
|
1752
|
+
let t = e.targetId ?? "reactive-md-document";
|
|
1753
|
+
if (!gt.test(t)) throw TypeError("targetId must start with a letter and contain only letters, digits, underscores or hyphens.");
|
|
1754
|
+
let n = e.mode === "static" ? "static" : "interactive";
|
|
1755
|
+
if (!e.staticMarkup.trim()) throw TypeError("createShareableHtml requires rendered document markup.");
|
|
1756
|
+
if (!e.css.trim()) throw TypeError("createShareableHtml requires the document stylesheet.");
|
|
1757
|
+
if (e.state.sourceDigest !== V(e.source)) throw Error("The state file does not belong to the exported source.");
|
|
1758
|
+
if (n === "interactive" && !e.runtimeScript?.trim()) throw TypeError("Interactive HTML requires the standalone runtime script.");
|
|
1759
|
+
let r = e.locale === "zh" ? "zh" : "en", i = r === "zh" ? "zh-CN" : "en", a = e.colorScheme === "light" || e.colorScheme === "dark" ? e.colorScheme : "auto", o = e.assets === "omit" ? "omit" : "inline", s = e.generator ?? {
|
|
1760
|
+
name: "reactive-md",
|
|
1761
|
+
version: "unknown"
|
|
1762
|
+
}, c = Et(e.images), l = Number.isSafeInteger(e.imageCount) && (e.imageCount ?? 0) > 0 ? String(e.imageCount) : String(Object.keys(c ?? {}).length), u = n === "interactive", d = {
|
|
1763
|
+
version: 1,
|
|
1764
|
+
target: t,
|
|
1765
|
+
source: e.source,
|
|
1766
|
+
state: e.state,
|
|
1767
|
+
locale: r,
|
|
1768
|
+
colorScheme: a,
|
|
1769
|
+
hydrate: !0,
|
|
1770
|
+
...c ? { images: c } : {}
|
|
1771
|
+
}, f = u ? "default-src 'none'; img-src data:; style-src 'unsafe-inline'; script-src 'unsafe-inline'; font-src data:; connect-src 'none'; media-src 'none'; object-src 'none'; frame-src 'none'; base-uri 'none'; form-action 'none'" : "default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:; object-src 'none'; frame-src 'none'; base-uri 'none'; form-action 'none'", p = u ? `<script type="application/reactive-md+json" data-reactive-md-auto>${Tt(d)}<\/script>
|
|
1772
|
+
<script>${wt(e.runtimeScript)}<\/script>` : "", m = e.notices?.trim() ? `<template id="reactive-md-notices"><pre>${Z(e.notices)}</pre></template>` : "";
|
|
1773
|
+
return `<!doctype html>
|
|
1774
|
+
<html lang="${Z(_t.test(i) ? i : "en", !0)}">
|
|
1775
|
+
<head>
|
|
1776
|
+
<meta charset="utf-8">
|
|
1777
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
1778
|
+
<meta name="referrer" content="no-referrer">
|
|
1779
|
+
<meta http-equiv="Content-Security-Policy" content="${Q(f)}">
|
|
1780
|
+
<meta name="generator" content="${Q(`${s.name} ${s.version}`)}">
|
|
1781
|
+
<meta name="reactive-md-html-format" content="${ht}">
|
|
1782
|
+
<meta name="reactive-md-syntax" content="${Q(e.state.syntax)}">
|
|
1783
|
+
<meta name="reactive-md-output" content="${n}">
|
|
1784
|
+
<meta name="reactive-md-state" content="${Q(e.state.sourceDigest)}">
|
|
1785
|
+
<meta name="reactive-md-images" content="${o}">
|
|
1786
|
+
<meta name="reactive-md-image-count" content="${l}">
|
|
1787
|
+
<title>${Z(e.title || "Reactive MD document")}</title>
|
|
1788
|
+
<style>${Ct(e.css)}${Ot}</style>
|
|
1789
|
+
</head>
|
|
1790
|
+
<body class="reactive-md-export">
|
|
1791
|
+
<div id="${t}" class="reactive-md-export-root">${e.staticMarkup}</div>
|
|
1792
|
+
${p}
|
|
1793
|
+
${m}
|
|
1794
|
+
</body>
|
|
1795
|
+
</html>
|
|
1796
|
+
`;
|
|
1797
|
+
}
|
|
1798
|
+
export { d as DEFAULT_LOCAL_THEME, dt as LOCAL_COMPILE_DELAY_MS, e as LOCAL_DIAGNOSTIC_CODES, P as LOCAL_STATE_FORMAT, v as LOCAL_SYNTAX_VERSION, s as LOCAL_THEME_PROTOCOL, ft as LocalCompileScheduler, ae as LocalExpressionError, ht as SHAREABLE_HTML_FORMAT, ve as analyzeLocalSource, tt as applyLocalState, ut as applyLocalStateRetention, Fe as checkLocalUpgrade, ie as compileExpression, X as compileFailureDiagnostic, u as compileLatex, h as compileLocal, De as completeLocalSource, i as countLocalCodePoints, _ as createLocalRuntime, Je as createLocalStateFile, kt as createShareableHtml, nt as exportLocalState, a as formatLocalDiagnostic, je as formatLocalSource, rt as importLocalState, Ne as inspectLocalSourceVersion, n as isLocalDiagnosticCode, ee as isLocalThemeName, r as localDiagnosticTemplate, p as localDiagnosticTemplateKeys, V as localSourceDigest, Ie as migrateLocalSource, W as parseLocalState, ct as planLocalStateRetention, ke as renameLocalBinding, et as resolveLocalState, Dt as resolveLocalStateBaseline, te as resolveLocalTheme, ne as samplePlot, Tt as serializeForScript, it as serializeLocalState, mt as startLocalCompileWorker };
|