reactive-md 0.5.1 → 0.5.3
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 +29 -0
- package/CHANGELOG.md +29 -0
- package/README-ch.md +7 -6
- package/README-en.md +8 -6
- package/README.md +8 -6
- package/cli/build.mjs +1 -1
- package/cli/package.mjs +1 -0
- package/dist-library/authoring-DJJjKYg9.js +842 -0
- package/dist-library/{runtime-CXBdLQ3A.js → compiler-UyPwGzJZ.js} +4374 -3730
- package/dist-library/react-fizgU3i8.js +12764 -0
- package/dist-library/reactive-md-authoring.js +1514 -0
- package/dist-library/reactive-md-editor.js +577 -571
- package/dist-library/reactive-md-print.css +284 -0
- package/dist-library/reactive-md-react-unstyled.js +1 -0
- package/dist-library/reactive-md-react.js +1 -13177
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +260 -1062
- package/dist-library/runtime-DXtle_6c.js +498 -0
- package/dist-library/types/authoring/index.d.ts +24 -0
- package/dist-library/types/editor/command-types.d.ts +10 -0
- package/dist-library/types/editor/editor-commands.d.ts +2 -2
- package/dist-library/types/editor/editor-i18n.d.ts +1 -1
- package/dist-library/types/editor/native-components.d.ts +1 -1
- package/dist-library/types/editor/source-authoring.d.ts +5 -3
- package/dist-library/types/editor/types.d.ts +5 -10
- package/dist-library/types/local/LocalDocumentView.d.ts +14 -4
- package/dist-library/types/local/authoring.d.ts +9 -5
- package/dist-library/types/local/diagnostics.d.ts +80 -0
- package/dist-library/types/local/html-names.d.ts +6 -0
- package/dist-library/types/local/index.d.ts +2 -1
- package/dist-library/types/local/limits.d.ts +8 -0
- package/dist-library/types/local/math-display.d.ts +72 -0
- package/dist-library/types/local/math-view.d.ts +2 -0
- package/dist-library/types/local/options.d.ts +9 -2
- package/dist-library/types/local/render-types.d.ts +11 -0
- package/dist-library/types/local/types.d.ts +28 -0
- package/dist-library/types/local/worker.d.ts +5 -1
- package/dist-library/types/react/index.d.ts +1 -1
- package/dist-standalone/reactive-md-standalone.js +54 -50
- package/docs/author-tools-ch.md +11 -5
- package/docs/author-tools-en.md +11 -5
- package/docs/compatibility-ch.md +7 -5
- package/docs/compatibility-en.md +7 -5
- package/docs/component-development-ch.md +4 -4
- package/docs/component-development-en.md +3 -3
- package/docs/component-protocol-ch.md +48 -11
- package/docs/component-protocol-en.md +48 -11
- package/docs/editor-ch.md +237 -235
- package/docs/editor-en.md +237 -235
- package/docs/local-integration-ch.md +392 -366
- package/docs/local-integration-en.md +392 -366
- package/docs/release-0.5.2-ch.md +35 -0
- package/docs/release-0.5.2-en.md +35 -0
- package/docs/release-0.5.3-ch.md +25 -0
- package/docs/release-0.5.3-en.md +25 -0
- package/docs/releasing-ch.md +7 -7
- package/docs/releasing-en.md +8 -8
- package/examples/conformance/README.md +1 -1
- package/package.json +12 -2
|
@@ -0,0 +1,842 @@
|
|
|
1
|
+
import { S as e, W as t, d as n, m as r, q as i, t as a, w as o } from "./compiler-UyPwGzJZ.js";
|
|
2
|
+
// src/local/authoring.ts
|
|
3
|
+
var s = /^[A-Za-z_][A-Za-z0-9_]*$/, c = 128, l = /* @__PURE__ */ new Set([
|
|
4
|
+
"code",
|
|
5
|
+
"inlineCode",
|
|
6
|
+
"math",
|
|
7
|
+
"inlineMath",
|
|
8
|
+
"fallback",
|
|
9
|
+
"comment",
|
|
10
|
+
"footnoteDefinition"
|
|
11
|
+
]), u = /* @__PURE__ */ new Set([
|
|
12
|
+
"local.version.unsupported",
|
|
13
|
+
"local.version.malformed",
|
|
14
|
+
"local.version.duplicate",
|
|
15
|
+
"local.version.placement",
|
|
16
|
+
"local.parse",
|
|
17
|
+
"local.interpolation",
|
|
18
|
+
"local.tag.unclosed",
|
|
19
|
+
"local.tag.mismatch",
|
|
20
|
+
"local.tag.closing",
|
|
21
|
+
"local.tag.shape",
|
|
22
|
+
"local.attribute",
|
|
23
|
+
"local.budget"
|
|
24
|
+
]);
|
|
25
|
+
function d(e) {
|
|
26
|
+
return e !== void 0 && /[A-Za-z_]/.test(e);
|
|
27
|
+
}
|
|
28
|
+
function f(e) {
|
|
29
|
+
return e !== void 0 && /[A-Za-z0-9_]/.test(e);
|
|
30
|
+
}
|
|
31
|
+
function p(e) {
|
|
32
|
+
return e !== void 0 && /\s/.test(e);
|
|
33
|
+
}
|
|
34
|
+
function m(e) {
|
|
35
|
+
return e.length > 0 && e.length <= c && s.test(e) && !i.has(e);
|
|
36
|
+
}
|
|
37
|
+
function h(e) {
|
|
38
|
+
return {
|
|
39
|
+
start: e.start,
|
|
40
|
+
end: e.end
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function g(e, t) {
|
|
44
|
+
try {
|
|
45
|
+
return a(e, t).diagnostics;
|
|
46
|
+
} catch {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function _(e) {
|
|
51
|
+
let t = r(e);
|
|
52
|
+
return t.ok ? t.htmlActive ? "html" : "markdown" : "invalid";
|
|
53
|
+
}
|
|
54
|
+
var v = /^<(\/?)([A-Za-z][A-Za-z0-9_-]*)(?=[\s/>])/;
|
|
55
|
+
function y(e, t) {
|
|
56
|
+
if (e[t] !== "<") return null;
|
|
57
|
+
let n = v.exec(e.slice(t));
|
|
58
|
+
if (!n) return null;
|
|
59
|
+
let r = !!n[1], i = n[2], a = t + (r ? 2 : 1), o = "", s = t + n[0].length;
|
|
60
|
+
for (; s < e.length; s += 1) {
|
|
61
|
+
let t = e[s];
|
|
62
|
+
if (o) t === o && (o = "");
|
|
63
|
+
else if (t === "\"" || t === "'") o = t;
|
|
64
|
+
else if (t === ">") break;
|
|
65
|
+
}
|
|
66
|
+
if (s >= e.length) return null;
|
|
67
|
+
let c = s, l = s + 1;
|
|
68
|
+
if (r) return {
|
|
69
|
+
start: t,
|
|
70
|
+
end: l,
|
|
71
|
+
contentEnd: c,
|
|
72
|
+
name: i,
|
|
73
|
+
nameRange: {
|
|
74
|
+
start: a,
|
|
75
|
+
end: a + i.length
|
|
76
|
+
},
|
|
77
|
+
closing: !0,
|
|
78
|
+
selfClosing: !1,
|
|
79
|
+
attrs: []
|
|
80
|
+
};
|
|
81
|
+
let u = [], d = a + i.length;
|
|
82
|
+
for (; d < c;) {
|
|
83
|
+
for (; d < c && p(e[d]);) d += 1;
|
|
84
|
+
if (d >= c) break;
|
|
85
|
+
if (e[d] === "/") {
|
|
86
|
+
d += 1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
let t = /^[A-Za-z][A-Za-z0-9_-]*/.exec(e.slice(d, c));
|
|
90
|
+
if (!t) {
|
|
91
|
+
d += 1;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
let n = d, r = t[0];
|
|
95
|
+
d += r.length;
|
|
96
|
+
let i = d, a = d;
|
|
97
|
+
for (; a < c && p(e[a]);) a += 1;
|
|
98
|
+
if (e[a] !== "=") {
|
|
99
|
+
u.push({
|
|
100
|
+
name: r,
|
|
101
|
+
nameRange: {
|
|
102
|
+
start: n,
|
|
103
|
+
end: n + r.length
|
|
104
|
+
}
|
|
105
|
+
}), d = i;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
for (d = a + 1; d < c && p(e[d]);) d += 1;
|
|
109
|
+
let o = e[d];
|
|
110
|
+
if (o === "\"" || o === "'") {
|
|
111
|
+
let t = d, i = d + 1, a = e.indexOf(o, i);
|
|
112
|
+
if (a < 0 || a > c) {
|
|
113
|
+
u.push({
|
|
114
|
+
name: r,
|
|
115
|
+
nameRange: {
|
|
116
|
+
start: n,
|
|
117
|
+
end: n + r.length
|
|
118
|
+
},
|
|
119
|
+
valueRange: {
|
|
120
|
+
start: i,
|
|
121
|
+
end: c
|
|
122
|
+
},
|
|
123
|
+
quoteStart: t,
|
|
124
|
+
quoteEnd: c
|
|
125
|
+
}), d = c;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
u.push({
|
|
129
|
+
name: r,
|
|
130
|
+
nameRange: {
|
|
131
|
+
start: n,
|
|
132
|
+
end: n + r.length
|
|
133
|
+
},
|
|
134
|
+
valueRange: {
|
|
135
|
+
start: i,
|
|
136
|
+
end: a
|
|
137
|
+
},
|
|
138
|
+
quoteStart: t,
|
|
139
|
+
quoteEnd: a
|
|
140
|
+
}), d = a + 1;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
let s = d;
|
|
144
|
+
for (; d < c && !p(e[d]);) d += 1;
|
|
145
|
+
u.push({
|
|
146
|
+
name: r,
|
|
147
|
+
nameRange: {
|
|
148
|
+
start: n,
|
|
149
|
+
end: n + r.length
|
|
150
|
+
},
|
|
151
|
+
valueRange: {
|
|
152
|
+
start: s,
|
|
153
|
+
end: d
|
|
154
|
+
},
|
|
155
|
+
unquoted: !0
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
start: t,
|
|
160
|
+
end: l,
|
|
161
|
+
contentEnd: c,
|
|
162
|
+
name: i,
|
|
163
|
+
nameRange: {
|
|
164
|
+
start: a,
|
|
165
|
+
end: a + i.length
|
|
166
|
+
},
|
|
167
|
+
closing: !1,
|
|
168
|
+
selfClosing: /\/\s*$/.test(e.slice(a + i.length, c)),
|
|
169
|
+
attrs: u
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function b(e, t, n) {
|
|
173
|
+
if (t.range.end <= n) return null;
|
|
174
|
+
let r = e.lastIndexOf("</", t.range.end - 1);
|
|
175
|
+
if (r < n) return null;
|
|
176
|
+
let i = y(e, r);
|
|
177
|
+
return !i || !i.closing || i.name !== t.name || i.end > t.range.end ? null : i;
|
|
178
|
+
}
|
|
179
|
+
function x(e, t, n) {
|
|
180
|
+
let r = [];
|
|
181
|
+
for (let i = t; i < n;) {
|
|
182
|
+
if (e[i] === "\\" && e.startsWith("{{", i + 1)) {
|
|
183
|
+
i += 3;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (!e.startsWith("{{", i)) {
|
|
187
|
+
i += 1;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
let t = "", a = i + 2;
|
|
191
|
+
for (; a < n - 1; a += 1) {
|
|
192
|
+
let n = e[a];
|
|
193
|
+
if (t) n === "\\" ? a += 1 : n === t && (t = "");
|
|
194
|
+
else if (n === "\"" || n === "'") t = n;
|
|
195
|
+
else if (n === "}" && e[a + 1] === "}") break;
|
|
196
|
+
}
|
|
197
|
+
if (a >= n - 1) break;
|
|
198
|
+
r.push({
|
|
199
|
+
start: i,
|
|
200
|
+
end: a + 2,
|
|
201
|
+
innerStart: i + 2,
|
|
202
|
+
innerEnd: a
|
|
203
|
+
}), i = a + 2;
|
|
204
|
+
}
|
|
205
|
+
return r;
|
|
206
|
+
}
|
|
207
|
+
function S(e, t) {
|
|
208
|
+
let n = {
|
|
209
|
+
quot: "\"",
|
|
210
|
+
apos: "'",
|
|
211
|
+
amp: "&",
|
|
212
|
+
lt: "<",
|
|
213
|
+
gt: ">"
|
|
214
|
+
}, r = [t.start], i = "";
|
|
215
|
+
for (let a = t.start; a < t.end;) {
|
|
216
|
+
let o = e[a] === "&" ? /^&(quot|apos|amp|lt|gt);/.exec(e.slice(a, t.end)) : null;
|
|
217
|
+
i += o ? n[o[1]] : e[a], a += o ? o[0].length : 1, r.push(a);
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
text: i,
|
|
221
|
+
offsets: r
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function C(e, t, n) {
|
|
225
|
+
let r = [];
|
|
226
|
+
for (let a = t; a < n;) {
|
|
227
|
+
let t = e[a];
|
|
228
|
+
if (t === "\"" || t === "'") {
|
|
229
|
+
let r = t;
|
|
230
|
+
for (a += 1; a < n;) if (e[a] === "\\") a += 2;
|
|
231
|
+
else {
|
|
232
|
+
if (e[a] === r) {
|
|
233
|
+
a += 1;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
a += 1;
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
if (/[0-9]/.test(t) || t === "." && e[a + 1] !== void 0 && /[0-9]/.test(e[a + 1])) {
|
|
240
|
+
let t = /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(a, n));
|
|
241
|
+
if (t) {
|
|
242
|
+
a += t[0].length;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (d(t)) {
|
|
247
|
+
let t = a;
|
|
248
|
+
for (a += 1; a < n && f(e[a]);) a += 1;
|
|
249
|
+
let o = e.slice(t, a), s = a;
|
|
250
|
+
for (; s < n && p(e[s]);) s += 1;
|
|
251
|
+
if (e[s] === "(" || o === "true" || o === "false" || o === "null" || o === "pi" || o === "e" || i.has(o)) continue;
|
|
252
|
+
r.push({
|
|
253
|
+
name: o,
|
|
254
|
+
range: {
|
|
255
|
+
start: t,
|
|
256
|
+
end: a
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
} else a += 1;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return r;
|
|
263
|
+
}
|
|
264
|
+
function w(e, t) {
|
|
265
|
+
return Object.hasOwn(e.props, t) ? t === "bind" || !!e.slots?.some((e) => e.bind === t) : !1;
|
|
266
|
+
}
|
|
267
|
+
function T(e, t = []) {
|
|
268
|
+
for (let n of e) l.has(n.type) && t.push(h(n.range)), n.type !== "fallback" && n.children && T(n.children, t);
|
|
269
|
+
return t;
|
|
270
|
+
}
|
|
271
|
+
function E(e, t) {
|
|
272
|
+
let n = T(t), r = (t) => {
|
|
273
|
+
for (let i of t) {
|
|
274
|
+
if (i.type === "component" || i.type === "hostComponent") {
|
|
275
|
+
let t = y(e, i.range.start);
|
|
276
|
+
t && n.push({
|
|
277
|
+
start: t.start,
|
|
278
|
+
end: t.end
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
i.type !== "fallback" && i.children && r(i.children);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
r(t), n.sort((e, t) => e.start - t.start || t.end - e.end);
|
|
285
|
+
let i = [], a = 0, o = 0;
|
|
286
|
+
for (; a < e.length;) {
|
|
287
|
+
let t = e.indexOf("<!--", a);
|
|
288
|
+
if (t < 0) break;
|
|
289
|
+
for (; o < n.length && n[o].end <= t;) o++;
|
|
290
|
+
let r = n[o];
|
|
291
|
+
if (r && r.start <= t) {
|
|
292
|
+
a = r.end;
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
let s = e.indexOf("-->", t + 4), c = s < 0 ? e.length : s + 3;
|
|
296
|
+
i.push({
|
|
297
|
+
start: t,
|
|
298
|
+
end: c
|
|
299
|
+
}), a = c;
|
|
300
|
+
}
|
|
301
|
+
return i;
|
|
302
|
+
}
|
|
303
|
+
function D(e, t) {
|
|
304
|
+
let n = o(e);
|
|
305
|
+
if (n) return n.props;
|
|
306
|
+
let r = t?.hostComponents?.find((t) => t.name === e);
|
|
307
|
+
return r ? Object.fromEntries(Object.entries(r.props).map(([e, t]) => [e, {
|
|
308
|
+
...t,
|
|
309
|
+
values: t.enum
|
|
310
|
+
}])) : void 0;
|
|
311
|
+
}
|
|
312
|
+
function O(e, n, r) {
|
|
313
|
+
let i = [], a = /* @__PURE__ */ new Map(), s = [], c = [], l = (t, n) => {
|
|
314
|
+
for (let r of C(e, t, n)) s.push(r);
|
|
315
|
+
}, u = (e, t) => {
|
|
316
|
+
let n = a.get(e);
|
|
317
|
+
n ? n.push(h(t)) : a.set(e, [h(t)]);
|
|
318
|
+
}, d = (t, n) => {
|
|
319
|
+
let a = y(e, t.range.start);
|
|
320
|
+
if (!a || a.closing) return;
|
|
321
|
+
i.push({
|
|
322
|
+
kind: "tag",
|
|
323
|
+
range: h(a.nameRange)
|
|
324
|
+
});
|
|
325
|
+
let c = o(t.name ?? ""), l = a.attrs.some((e) => e.name === "key");
|
|
326
|
+
for (let o of a.attrs) {
|
|
327
|
+
if (i.push({
|
|
328
|
+
kind: "attribute",
|
|
329
|
+
range: h(o.nameRange)
|
|
330
|
+
}), !o.valueRange) continue;
|
|
331
|
+
let a = D(t.name ?? "", r)?.[o.name], d = c !== void 0 && w(c, o.name) && (t.name !== "table" && t.name !== "chart" || !!l), f = (t.name === "computed" || t.name === "const") && o.name === "name", p = e.slice(o.valueRange.start, o.valueRange.end), g = S(e, o.valueRange);
|
|
332
|
+
if (t.name === "validation" && o.name === "fields") {
|
|
333
|
+
for (let e of g.text.matchAll(/\S+/g)) {
|
|
334
|
+
if (!m(e[0])) continue;
|
|
335
|
+
let t = {
|
|
336
|
+
start: g.offsets[e.index],
|
|
337
|
+
end: g.offsets[e.index + e[0].length]
|
|
338
|
+
};
|
|
339
|
+
s.push({
|
|
340
|
+
name: e[0],
|
|
341
|
+
range: t
|
|
342
|
+
}), i.push({
|
|
343
|
+
kind: "binding",
|
|
344
|
+
range: t
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
let _ = a && !a.static ? x(g.text, 0, g.text.length) : [];
|
|
350
|
+
if (_.length > 0) {
|
|
351
|
+
let e = 0;
|
|
352
|
+
for (let r of _) {
|
|
353
|
+
r.start > e && i.push({
|
|
354
|
+
kind: "string",
|
|
355
|
+
range: {
|
|
356
|
+
start: g.offsets[e],
|
|
357
|
+
end: g.offsets[r.start]
|
|
358
|
+
}
|
|
359
|
+
}), i.push({
|
|
360
|
+
kind: "expression",
|
|
361
|
+
range: {
|
|
362
|
+
start: g.offsets[r.start],
|
|
363
|
+
end: g.offsets[r.end]
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
for (let e of C(g.text, r.innerStart, r.innerEnd)) ((n !== "data-table" || t.name !== "column") && (t.name !== "data-table" || o.name !== "key") || e.name !== "item" && e.name !== "index") && s.push({
|
|
367
|
+
name: e.name,
|
|
368
|
+
range: {
|
|
369
|
+
start: g.offsets[e.range.start],
|
|
370
|
+
end: g.offsets[e.range.end]
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
e = r.end;
|
|
374
|
+
}
|
|
375
|
+
e < g.text.length && i.push({
|
|
376
|
+
kind: "string",
|
|
377
|
+
range: {
|
|
378
|
+
start: g.offsets[e],
|
|
379
|
+
end: o.valueRange.end
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
} else (d || f) && m(p) ? (i.push({
|
|
383
|
+
kind: "binding",
|
|
384
|
+
range: h(o.valueRange)
|
|
385
|
+
}), u(p, o.valueRange)) : o.valueRange.end > o.valueRange.start && i.push({
|
|
386
|
+
kind: "string",
|
|
387
|
+
range: h(o.valueRange)
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
let d = b(e, t, a.end);
|
|
391
|
+
d && i.push({
|
|
392
|
+
kind: "tag",
|
|
393
|
+
range: h(d.nameRange)
|
|
394
|
+
});
|
|
395
|
+
}, f = (n, r) => {
|
|
396
|
+
for (let a of n) {
|
|
397
|
+
if ((a.type === "component" || a.type === "hostComponent") && a.name) d(a, r);
|
|
398
|
+
else if (a.type === "interpolation") i.push({
|
|
399
|
+
kind: "expression",
|
|
400
|
+
range: h(a.range)
|
|
401
|
+
}), l(a.range.start + 2, Math.max(a.range.start + 2, a.range.end - 2));
|
|
402
|
+
else if (a.type === "math" || a.type === "inlineMath") {
|
|
403
|
+
if (i.push({
|
|
404
|
+
kind: "math",
|
|
405
|
+
range: h(a.range)
|
|
406
|
+
}), r === "plot" && a.type === "math") {
|
|
407
|
+
let n = a.range.start + 2;
|
|
408
|
+
try {
|
|
409
|
+
for (let r of t(e.slice(n, a.range.end - 2))) {
|
|
410
|
+
let e = {
|
|
411
|
+
name: r.name,
|
|
412
|
+
range: {
|
|
413
|
+
start: n + r.range.start,
|
|
414
|
+
end: n + r.range.end
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
s.push(e), c.push(e);
|
|
418
|
+
}
|
|
419
|
+
} catch {}
|
|
420
|
+
}
|
|
421
|
+
} else a.type === "code" || a.type === "inlineCode" ? i.push({
|
|
422
|
+
kind: "code",
|
|
423
|
+
range: h(a.range)
|
|
424
|
+
}) : a.type === "comment" && i.push({
|
|
425
|
+
kind: "comment",
|
|
426
|
+
range: h(a.range)
|
|
427
|
+
});
|
|
428
|
+
a.type !== "fallback" && a.children && f(a.children, a.name);
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
f(n);
|
|
432
|
+
for (let t of E(e, n)) i.push({
|
|
433
|
+
kind: "comment",
|
|
434
|
+
range: t
|
|
435
|
+
});
|
|
436
|
+
i.sort((e, t) => e.range.start - t.range.start || e.range.end - t.range.end);
|
|
437
|
+
let p = [];
|
|
438
|
+
for (let e of i) {
|
|
439
|
+
if (e.range.end <= e.range.start) continue;
|
|
440
|
+
let t = p[p.length - 1];
|
|
441
|
+
t && e.range.start < t.range.end || p.push(e);
|
|
442
|
+
}
|
|
443
|
+
let g = [];
|
|
444
|
+
for (let [e, t] of a) {
|
|
445
|
+
let n = [];
|
|
446
|
+
for (let t of s) t.name === e && (n.some((e) => e.start === t.range.start && e.end === t.range.end) || n.push(h(t.range)));
|
|
447
|
+
n.sort((e, t) => e.start - t.start || e.end - t.end), t.sort((e, t) => e.start - t.start || e.end - t.end), g.push({
|
|
448
|
+
name: e,
|
|
449
|
+
declarations: t,
|
|
450
|
+
references: n
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
return g.sort((e, t) => e.declarations[0].start - t.declarations[0].start || e.name.localeCompare(t.name)), {
|
|
454
|
+
tokens: p,
|
|
455
|
+
bindings: g,
|
|
456
|
+
mathReferences: c
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function k(e, t) {
|
|
460
|
+
if (typeof e != "string") return {
|
|
461
|
+
tokens: [],
|
|
462
|
+
bindings: [],
|
|
463
|
+
diagnostics: []
|
|
464
|
+
};
|
|
465
|
+
if (_(t) !== "markdown") return {
|
|
466
|
+
tokens: [],
|
|
467
|
+
bindings: [],
|
|
468
|
+
diagnostics: g(e, t)
|
|
469
|
+
};
|
|
470
|
+
let r = O(e, n(e, t).nodes, t);
|
|
471
|
+
return {
|
|
472
|
+
tokens: r.tokens,
|
|
473
|
+
bindings: r.bindings,
|
|
474
|
+
diagnostics: g(e, t)
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
function A(e, t, n) {
|
|
478
|
+
let r = /^<(\/?)([A-Za-z][A-Za-z0-9_-]*)/.exec(e.slice(t, Math.min(e.length, n + 1)));
|
|
479
|
+
if (!r) return null;
|
|
480
|
+
let i = !!r[1], a = r[2], o = t + r[0].length, s = [], c = !1, l, u = !1;
|
|
481
|
+
if (!i) {
|
|
482
|
+
let t = o;
|
|
483
|
+
for (; t < n;) {
|
|
484
|
+
for (; t < n && p(e[t]);) t += 1;
|
|
485
|
+
if (t >= n) break;
|
|
486
|
+
if (e[t] === "/") {
|
|
487
|
+
u = !0, t += 1;
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
let r = /^[A-Za-z][A-Za-z0-9_-]*/.exec(e.slice(t, n));
|
|
491
|
+
if (!r) {
|
|
492
|
+
t += 1;
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
let i = r[0], a = t;
|
|
496
|
+
t += i.length;
|
|
497
|
+
let o = t, d = t;
|
|
498
|
+
for (; d < n && p(e[d]);) d += 1;
|
|
499
|
+
if (e[d] !== "=") {
|
|
500
|
+
s.push({
|
|
501
|
+
name: i,
|
|
502
|
+
nameStart: a,
|
|
503
|
+
nameEnd: o,
|
|
504
|
+
nameRange: {
|
|
505
|
+
start: a,
|
|
506
|
+
end: o
|
|
507
|
+
}
|
|
508
|
+
}), t = o;
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
for (t = d + 1; t < n && p(e[t]);) t += 1;
|
|
512
|
+
let f = e[t];
|
|
513
|
+
if (f === "\"" || f === "'") {
|
|
514
|
+
let r = t, u = t + 1, d = e.indexOf(f, u);
|
|
515
|
+
if (d < 0 || d >= n) {
|
|
516
|
+
let e = {
|
|
517
|
+
name: i,
|
|
518
|
+
nameStart: a,
|
|
519
|
+
nameEnd: o,
|
|
520
|
+
nameRange: {
|
|
521
|
+
start: a,
|
|
522
|
+
end: o
|
|
523
|
+
},
|
|
524
|
+
valueRange: {
|
|
525
|
+
start: u,
|
|
526
|
+
end: n
|
|
527
|
+
},
|
|
528
|
+
quoteStart: r,
|
|
529
|
+
quoteEnd: d < 0 ? n : d
|
|
530
|
+
};
|
|
531
|
+
s.push(e), l = e, c = !0, t = n;
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
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: u,
|
|
544
|
+
end: d
|
|
545
|
+
},
|
|
546
|
+
quoteStart: r,
|
|
547
|
+
quoteEnd: d
|
|
548
|
+
}), t = d + 1;
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
let m = t;
|
|
552
|
+
for (; t < n && !p(e[t]);) t += 1;
|
|
553
|
+
s.push({
|
|
554
|
+
name: i,
|
|
555
|
+
nameStart: a,
|
|
556
|
+
nameEnd: o,
|
|
557
|
+
nameRange: {
|
|
558
|
+
start: a,
|
|
559
|
+
end: o
|
|
560
|
+
},
|
|
561
|
+
valueRange: {
|
|
562
|
+
start: m,
|
|
563
|
+
end: t
|
|
564
|
+
},
|
|
565
|
+
unquoted: !0
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
let d = -1;
|
|
570
|
+
if (!c) {
|
|
571
|
+
let t = n;
|
|
572
|
+
for (; t > o && /[A-Za-z0-9_-]/.test(e[t - 1]);) --t;
|
|
573
|
+
t > o && p(e[t - 1]) && (d = t);
|
|
574
|
+
}
|
|
575
|
+
return {
|
|
576
|
+
name: a,
|
|
577
|
+
closing: i,
|
|
578
|
+
selfClosing: u,
|
|
579
|
+
inValue: c,
|
|
580
|
+
currentAttribute: l,
|
|
581
|
+
attrs: s,
|
|
582
|
+
partialStart: d
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function j(e, t, n) {
|
|
586
|
+
let r = [], i = (e) => {
|
|
587
|
+
for (let t of e) t.type === "component" && r.push(t.range.start), t.type !== "fallback" && t.children && i(t.children);
|
|
588
|
+
};
|
|
589
|
+
i(n), r.sort((e, t) => e - t);
|
|
590
|
+
for (let n = r.length - 1; n >= 0; --n) {
|
|
591
|
+
let i = r[n];
|
|
592
|
+
if (i >= t) continue;
|
|
593
|
+
let a = y(e, i);
|
|
594
|
+
if (a && t <= a.end) return i;
|
|
595
|
+
if (a && a.end < t) break;
|
|
596
|
+
}
|
|
597
|
+
let a = t;
|
|
598
|
+
for (; a > 0;) {
|
|
599
|
+
let n = e.lastIndexOf("<", a - 1);
|
|
600
|
+
if (n < 0) return -1;
|
|
601
|
+
if (e[n - 1] === "\\") {
|
|
602
|
+
a = n;
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
let r = e[n + 1];
|
|
606
|
+
if (r !== "/" && !d(r)) a = n;
|
|
607
|
+
else if (M(e, n, t)) a = n;
|
|
608
|
+
else return n;
|
|
609
|
+
}
|
|
610
|
+
return -1;
|
|
611
|
+
}
|
|
612
|
+
function M(e, t, n) {
|
|
613
|
+
let r = "";
|
|
614
|
+
for (let i = t; i < n; i += 1) {
|
|
615
|
+
let t = e[i];
|
|
616
|
+
if (r) t === r && (r = "");
|
|
617
|
+
else if (t === "\"" || t === "'") r = t;
|
|
618
|
+
else if (t === ">") return !0;
|
|
619
|
+
}
|
|
620
|
+
return !1;
|
|
621
|
+
}
|
|
622
|
+
function N(e, t) {
|
|
623
|
+
let n = t;
|
|
624
|
+
for (; n > 0;) {
|
|
625
|
+
let r = e.lastIndexOf("{{", n - 1);
|
|
626
|
+
if (r < 0) return null;
|
|
627
|
+
if (e[r - 1] === "\\") {
|
|
628
|
+
n = r;
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
let i = "", a = r + 2, o = -1;
|
|
632
|
+
for (; a < e.length - 1; a += 1) {
|
|
633
|
+
let t = e[a];
|
|
634
|
+
if (i) t === "\\" ? a += 1 : t === i && (i = "");
|
|
635
|
+
else if (t === "\"" || t === "'") i = t;
|
|
636
|
+
else if (t === "}" && e[a + 1] === "}") {
|
|
637
|
+
o = a;
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if (o >= 0 && o + 2 <= t) n = r;
|
|
642
|
+
else return {
|
|
643
|
+
start: r,
|
|
644
|
+
end: o < 0 ? e.length : o + 2,
|
|
645
|
+
innerStart: r + 2,
|
|
646
|
+
innerEnd: o < 0 ? e.length : o
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
function P(e, t, n) {
|
|
652
|
+
let r = "";
|
|
653
|
+
for (let i = t; i < n; i += 1) {
|
|
654
|
+
let t = e[i];
|
|
655
|
+
r ? t === "\\" ? i += 1 : t === r && (r = "") : (t === "\"" || t === "'") && (r = t);
|
|
656
|
+
}
|
|
657
|
+
return r !== "";
|
|
658
|
+
}
|
|
659
|
+
function F(e, t) {
|
|
660
|
+
let n = 0, r = e.length - 1;
|
|
661
|
+
for (; n <= r;) {
|
|
662
|
+
let i = n + r >> 1, a = e[i];
|
|
663
|
+
if (t < a.start) r = i - 1;
|
|
664
|
+
else if (t >= a.end) n = i + 1;
|
|
665
|
+
else return !0;
|
|
666
|
+
}
|
|
667
|
+
return !1;
|
|
668
|
+
}
|
|
669
|
+
function I(e, t, n, r) {
|
|
670
|
+
let i = e.slice(t, n), a = i && r.startsWith(i) ? r.slice(i.length) : "";
|
|
671
|
+
return {
|
|
672
|
+
start: t,
|
|
673
|
+
end: a && e.startsWith(a, n) ? n + a.length : n
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
function L(e, t, n, r) {
|
|
677
|
+
if (P(e, n.innerStart, t)) return [];
|
|
678
|
+
let i = t;
|
|
679
|
+
for (; i > n.innerStart && f(e[i - 1]);) --i;
|
|
680
|
+
if (e[i - 1] === ".") return [];
|
|
681
|
+
let a = e.slice(i, t);
|
|
682
|
+
return a && !d(a[0]) ? [] : r.filter((e) => e.name.startsWith(a)).map((n) => ({
|
|
683
|
+
label: n.name,
|
|
684
|
+
insertText: n.name,
|
|
685
|
+
range: I(e, i, t, n.name),
|
|
686
|
+
kind: "binding",
|
|
687
|
+
detail: `${n.declarations.length} declaration${n.declarations.length === 1 ? "" : "s"}, ${n.references.length} reference${n.references.length === 1 ? "" : "s"}`
|
|
688
|
+
}));
|
|
689
|
+
}
|
|
690
|
+
function R(e, t, n, r) {
|
|
691
|
+
let i = n.currentAttribute;
|
|
692
|
+
if (!i) return [];
|
|
693
|
+
let a = D(n.name, r)?.[i.name];
|
|
694
|
+
if (!a || a.kind !== "enum" || !a.values) return [];
|
|
695
|
+
let o = i.valueRange?.start ?? t, s = e.slice(o, t);
|
|
696
|
+
return a.values.filter((e) => e.startsWith(s)).map((n) => ({
|
|
697
|
+
label: n,
|
|
698
|
+
insertText: n,
|
|
699
|
+
range: I(e, o, t, n),
|
|
700
|
+
kind: "value",
|
|
701
|
+
detail: `${i.name} value`
|
|
702
|
+
}));
|
|
703
|
+
}
|
|
704
|
+
function z(e, t, n, r) {
|
|
705
|
+
if (n.closing || n.inValue || n.partialStart < 0) return [];
|
|
706
|
+
let i = D(n.name, r);
|
|
707
|
+
if (!i) return [];
|
|
708
|
+
let a = e.slice(n.partialStart, t);
|
|
709
|
+
if (a && !/^[A-Za-z0-9_-]*$/.test(a)) return [];
|
|
710
|
+
let o = new Set(n.attrs.filter((e) => e.nameEnd < n.partialStart).map((e) => e.name));
|
|
711
|
+
return Object.entries(i).filter(([e]) => !o.has(e) && e.startsWith(a)).map(([r, i]) => ({
|
|
712
|
+
label: r,
|
|
713
|
+
insertText: r,
|
|
714
|
+
range: I(e, n.partialStart, t, r),
|
|
715
|
+
kind: "attribute",
|
|
716
|
+
detail: i.required ? `${i.kind}, required` : i.kind
|
|
717
|
+
}));
|
|
718
|
+
}
|
|
719
|
+
function B(t, n, r) {
|
|
720
|
+
let i = Math.max(0, n - 256), a = t.slice(i, n), o = /<\/?([A-Za-z][A-Za-z0-9-]*)?$/.exec(a);
|
|
721
|
+
if (!o) return [];
|
|
722
|
+
let s = i + o.index;
|
|
723
|
+
if (t[s] !== "<" || t[s - 1] === "\\") return [];
|
|
724
|
+
let c = t[s + 1] === "/", l = s + (c ? 2 : 1);
|
|
725
|
+
if (l > n) return [];
|
|
726
|
+
let u = o[1] ?? "";
|
|
727
|
+
return [...e, ...c ? [] : r?.hostComponents?.map((e) => e.name) ?? []].filter((e) => e.startsWith(u)).map((e) => ({
|
|
728
|
+
label: e,
|
|
729
|
+
insertText: e,
|
|
730
|
+
range: I(t, l, n, e),
|
|
731
|
+
kind: "tag",
|
|
732
|
+
detail: c ? "closing tag" : "component"
|
|
733
|
+
}));
|
|
734
|
+
}
|
|
735
|
+
function V(e, t, r) {
|
|
736
|
+
if (typeof e != "string" || !Number.isFinite(t) || _(r) !== "markdown") return [];
|
|
737
|
+
let i = Math.max(0, Math.min(e.length, Math.floor(t))), a = n(e, r), o = [...T(a.nodes), ...E(e, a.nodes)].sort((e, t) => e.start - t.start);
|
|
738
|
+
if (F(o, i) || i === e.length && o.some((e) => e.end === i && e.start < i)) return [];
|
|
739
|
+
let s = O(e, a.nodes, r), c = N(e, i);
|
|
740
|
+
if (c) {
|
|
741
|
+
let t = j(e, i, a.nodes);
|
|
742
|
+
if (t >= 0) {
|
|
743
|
+
let n = A(e, t, i);
|
|
744
|
+
if (n?.inValue && n.currentAttribute && D(n.name, r)?.[n.currentAttribute.name]?.static) return [];
|
|
745
|
+
}
|
|
746
|
+
return L(e, i, c, s.bindings);
|
|
747
|
+
}
|
|
748
|
+
let l = j(e, i, a.nodes);
|
|
749
|
+
if (l >= 0) {
|
|
750
|
+
let t = A(e, l, i);
|
|
751
|
+
if (t?.inValue) return R(e, i, t, r);
|
|
752
|
+
}
|
|
753
|
+
let u = B(e, i, r);
|
|
754
|
+
if (u.length > 0) return u;
|
|
755
|
+
if (l >= 0) {
|
|
756
|
+
let t = A(e, l, i);
|
|
757
|
+
if (t) return z(e, i, t, r);
|
|
758
|
+
}
|
|
759
|
+
return [];
|
|
760
|
+
}
|
|
761
|
+
function H(e, t) {
|
|
762
|
+
let n = "", r = 0;
|
|
763
|
+
for (let i of t) n += e.slice(r, i.range.start) + i.text, r = i.range.end;
|
|
764
|
+
return n + e.slice(r);
|
|
765
|
+
}
|
|
766
|
+
function U(e, t, r, i) {
|
|
767
|
+
if (typeof e != "string" || typeof t != "string" || typeof r != "string") throw Error("Rename requires string arguments.");
|
|
768
|
+
if (_(i) === "html") throw Error("Bindings cannot be renamed in HTML mode.");
|
|
769
|
+
if (!m(r)) throw Error(`"${r}" is not a valid binding name. Use [A-Za-z_][A-Za-z0-9_]* and avoid reserved names.`);
|
|
770
|
+
let o = O(e, n(e, i).nodes, i), s = o.bindings.find((e) => e.name === t);
|
|
771
|
+
if (!s || s.declarations.length === 0) throw Error(`Binding "${t}" is not declared in this document.`);
|
|
772
|
+
if (t === r) return {
|
|
773
|
+
source: e,
|
|
774
|
+
edits: []
|
|
775
|
+
};
|
|
776
|
+
if (o.bindings.some((e) => e.name === r)) throw Error(`Binding "${r}" already exists.`);
|
|
777
|
+
if (g(e, i).some((e) => e.severity === "error" && u.has(e.code))) throw Error("The document cannot be renamed safely while parse errors remain.");
|
|
778
|
+
let c = /* @__PURE__ */ new Set(), l = [];
|
|
779
|
+
for (let e of [...s.declarations, ...s.references]) {
|
|
780
|
+
let t = `${e.start}:${e.end}`;
|
|
781
|
+
c.has(t) || (c.add(t), l.push(h(e)));
|
|
782
|
+
}
|
|
783
|
+
l.sort((e, t) => e.start - t.start || e.end - t.end);
|
|
784
|
+
let d = new Set(o.mathReferences.filter((e) => e.name === t).map((e) => `${e.range.start}:${e.range.end}`)), f = l.map((e) => ({
|
|
785
|
+
range: h(e),
|
|
786
|
+
text: d.has(`${e.start}:${e.end}`) ? `\\mathrm{${r}}` : r
|
|
787
|
+
})), p = H(e, f);
|
|
788
|
+
if (a(e, i).ok && !a(p, i).ok) throw Error("Rename could not preserve all binding references; the source was left unchanged.");
|
|
789
|
+
return {
|
|
790
|
+
source: p,
|
|
791
|
+
edits: f
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
function W(e, t) {
|
|
795
|
+
let n = e.slice(t.nameRange.start, t.nameRange.end), r = t.attrs.map((t) => {
|
|
796
|
+
let n = e.slice(t.nameRange.start, t.nameRange.end);
|
|
797
|
+
return t.valueRange === void 0 ? n : t.quoteStart !== void 0 && t.quoteEnd !== void 0 ? `${n}=${e.slice(t.quoteStart, t.quoteEnd + 1)}` : n;
|
|
798
|
+
}), i = r.length > 0 ? `<${n} ${r.join(" ")}` : `<${n}`;
|
|
799
|
+
return t.selfClosing ? `${i} />` : `${i}>`;
|
|
800
|
+
}
|
|
801
|
+
function G(e, t) {
|
|
802
|
+
if (typeof e != "string" || _(t) !== "markdown") return e;
|
|
803
|
+
let r;
|
|
804
|
+
try {
|
|
805
|
+
r = a(e, t);
|
|
806
|
+
} catch {
|
|
807
|
+
return e;
|
|
808
|
+
}
|
|
809
|
+
if (r.diagnostics.some((e) => e.severity === "error")) return e;
|
|
810
|
+
let i = n(e, t), o = [], s = (t) => {
|
|
811
|
+
for (let n of t) {
|
|
812
|
+
if ((n.type === "component" || n.type === "hostComponent") && n.name) {
|
|
813
|
+
let t = y(e, n.range.start);
|
|
814
|
+
if (t && !t.closing && !/[\r\n]/.test(e.slice(t.start, t.end))) {
|
|
815
|
+
let n = W(e, t);
|
|
816
|
+
n !== e.slice(t.start, t.end) && o.push({
|
|
817
|
+
start: t.start,
|
|
818
|
+
end: t.end,
|
|
819
|
+
text: n
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
if (t) {
|
|
823
|
+
let r = b(e, n, t.end);
|
|
824
|
+
if (r && !/[\r\n]/.test(e.slice(r.start, r.end))) {
|
|
825
|
+
let t = `</${e.slice(r.nameRange.start, r.nameRange.end)}>`;
|
|
826
|
+
t !== e.slice(r.start, r.end) && o.push({
|
|
827
|
+
start: r.start,
|
|
828
|
+
end: r.end,
|
|
829
|
+
text: t
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
n.type !== "fallback" && n.children && s(n.children);
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
s(i.nodes), o.sort((e, t) => e.start - t.start || e.end - t.end);
|
|
838
|
+
let c = "", l = 0;
|
|
839
|
+
for (let t of o) t.start < l || (c += e.slice(l, t.start) + t.text, l = t.end);
|
|
840
|
+
return c + e.slice(l);
|
|
841
|
+
}
|
|
842
|
+
export { U as i, V as n, G as r, k as t };
|