@cossackframework/renderer 0.9.0 → 0.9.2
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/README.md +171 -29
- package/agent-docs.json +33 -0
- package/dist/attributes.d.ts +824 -0
- package/dist/attributes.js +1 -0
- package/dist/browser.js +10 -8
- package/dist/component-tags.d.ts +69 -0
- package/dist/component-tags.js +106 -0
- package/dist/cossack-element.d.ts +31 -1
- package/dist/cossack-element.js +20 -25
- package/dist/cossack-html.d.ts +2 -3
- package/dist/cossack-html.js +742 -531
- package/dist/css-result.d.ts +9 -0
- package/dist/css-result.js +14 -0
- package/dist/css-scoping.d.ts +4 -0
- package/dist/css-scoping.js +95 -0
- package/dist/css.d.ts +3 -16
- package/dist/css.js +13 -111
- package/dist/diagnostics.d.ts +85 -0
- package/dist/diagnostics.js +465 -0
- package/dist/directives.d.ts +9 -7
- package/dist/directives.js +7 -7
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -7
- package/dist/minify-html.d.ts +22 -0
- package/dist/minify-html.js +123 -18
- package/dist/server.d.ts +3 -1
- package/dist/server.js +6 -4
- package/dist/ssr-form-values.js +4 -3
- package/dist/style-registry.d.ts +42 -0
- package/dist/style-registry.js +73 -0
- package/dist/style-runtime.d.ts +47 -0
- package/dist/style-runtime.js +43 -0
- package/dist/template-analysis.d.ts +224 -0
- package/dist/template-analysis.js +321 -0
- package/dist/template-parse.d.ts +157 -0
- package/dist/template-parse.js +546 -0
- package/dist/template.d.ts +2 -0
- package/dist/template.js +3 -0
- package/package.json +18 -4
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
// @ts-self-types="./template-analysis.d.ts"
|
|
2
|
+
//#region src/template-analysis.ts
|
|
3
|
+
var e = /* @__PURE__ */ new Set([
|
|
4
|
+
"script",
|
|
5
|
+
"style",
|
|
6
|
+
"textarea",
|
|
7
|
+
"title"
|
|
8
|
+
]), t = { runs: 0 }, n = /* @__PURE__ */ new WeakMap(), r = (e, t) => {
|
|
9
|
+
let r = n.get(e);
|
|
10
|
+
r || (r = /* @__PURE__ */ new Map(), n.set(e, r));
|
|
11
|
+
let i = t ?? "", a = r.get(i);
|
|
12
|
+
return a || (a = f(e, t), r.set(i, a)), a;
|
|
13
|
+
}, i = /* @__PURE__ */ function(e) {
|
|
14
|
+
return e[e.Data = 0] = "Data", e[e.TagName = 1] = "TagName", e[e.BeforeAttrName = 2] = "BeforeAttrName", e[e.AttrName = 3] = "AttrName", e[e.AfterAttrName = 4] = "AfterAttrName", e[e.BeforeAttrValue = 5] = "BeforeAttrValue", e[e.AttrValueQuoted = 6] = "AttrValueQuoted", e[e.AttrValueUnquoted = 7] = "AttrValueUnquoted", e[e.EndTag = 8] = "EndTag", e[e.Comment = 9] = "Comment", e[e.BogusComment = 10] = "BogusComment", e[e.RawText = 11] = "RawText", e;
|
|
15
|
+
}({}), a = (e) => e === " " || e === "\n" || e === " " || e === "\r" || e === "\f", o = (e) => !!e && (e >= "a" && e <= "z" || e >= "A" && e <= "Z"), s = () => ({
|
|
16
|
+
state: 0,
|
|
17
|
+
tagName: "",
|
|
18
|
+
rawTextTag: "",
|
|
19
|
+
quote: "\"",
|
|
20
|
+
commentTail: ""
|
|
21
|
+
}), c = (t) => {
|
|
22
|
+
e.has(t.tagName) ? (t.state = 11, t.rawTextTag = t.tagName) : t.state = 0;
|
|
23
|
+
}, l = (e, t, n) => {
|
|
24
|
+
let r = e.indexOf(n, t);
|
|
25
|
+
return r < 0 ? e.length : r;
|
|
26
|
+
}, u = (e, t, n) => {
|
|
27
|
+
for (; t < e.length; t++) {
|
|
28
|
+
let r = e.charCodeAt(t);
|
|
29
|
+
if (r === 32 || r === 9 || r === 10 || r === 12 || r === 13 || r === 47 || r === 62 || r === 61 && n) break;
|
|
30
|
+
}
|
|
31
|
+
return t;
|
|
32
|
+
}, d = (e, t, n) => {
|
|
33
|
+
let r = t[n];
|
|
34
|
+
switch (e.state) {
|
|
35
|
+
case 0: {
|
|
36
|
+
if (r !== "<") return l(t, n, "<");
|
|
37
|
+
let i = t[n + 1];
|
|
38
|
+
if (o(i)) e.state = 1, e.tagName = "";
|
|
39
|
+
else if (i === "/" && o(t[n + 2])) e.state = 8;
|
|
40
|
+
else if (i === "!" && t[n + 2] === "-" && t[n + 3] === "-") return e.state = 9, e.commentTail = "--", n + 4;
|
|
41
|
+
else (i === "!" || i === "?" || i === "/" && t[n + 2] !== void 0) && (e.state = 10);
|
|
42
|
+
return n + 1;
|
|
43
|
+
}
|
|
44
|
+
case 1: {
|
|
45
|
+
let r = u(t, n, !1);
|
|
46
|
+
return r === n ? (e.state = 2, n) : (e.tagName += t.slice(n, r).toLowerCase(), r);
|
|
47
|
+
}
|
|
48
|
+
case 2:
|
|
49
|
+
case 4: return r === ">" ? c(e) : r === "/" ? e.state = 2 : r === "=" && e.state === 4 ? e.state = 5 : a(r) || (e.state = 3), n + 1;
|
|
50
|
+
case 3:
|
|
51
|
+
if (a(r)) e.state = 4;
|
|
52
|
+
else if (r === "/" || r === ">") return e.state = 2, n;
|
|
53
|
+
else if (r === "=") e.state = 5;
|
|
54
|
+
else return u(t, n, !0);
|
|
55
|
+
return n + 1;
|
|
56
|
+
case 5: return r === "\"" || r === "'" ? (e.quote = r, e.state = 6) : r === ">" ? c(e) : a(r) || (e.state = 7), n + 1;
|
|
57
|
+
case 6: return r === e.quote ? (e.state = 2, n + 1) : l(t, n, e.quote);
|
|
58
|
+
case 7: return a(r) || r === ">" || r === "/" && n === 0 && t[1] === ">" ? (e.state = 2, n) : r === "/" ? n + 1 : u(t, n, !1);
|
|
59
|
+
case 8:
|
|
60
|
+
case 10: return r === ">" ? (e.state = 0, n + 1) : l(t, n, ">");
|
|
61
|
+
case 9: {
|
|
62
|
+
if (r === ">" && e.commentTail === "--") return e.state = 0, n + 1;
|
|
63
|
+
let i = Math.max(l(t, n, ">"), n + 1);
|
|
64
|
+
return e.commentTail = (e.commentTail + t.slice(Math.max(n, i - 2), i)).slice(-2), i;
|
|
65
|
+
}
|
|
66
|
+
case 11: {
|
|
67
|
+
if (r !== "<") return l(t, n, "<");
|
|
68
|
+
let i = e.rawTextTag;
|
|
69
|
+
if (t[n + 1] === "/" && t.slice(n + 2, n + 2 + i.length).toLowerCase() === i) {
|
|
70
|
+
let r = t[n + 2 + i.length];
|
|
71
|
+
(r === void 0 || a(r) || r === "/" || r === ">") && (e.state = 8);
|
|
72
|
+
}
|
|
73
|
+
return n + 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, f = (e, n) => {
|
|
77
|
+
t.runs++;
|
|
78
|
+
let r = n ? ` data-cossack-scope="${n}"` : "", i = [], o = [], c = Array.from({ length: Math.max(e.length - 1, 0) }), l = s(), u = !0, f = !0, p = null, m = -1, h = [], g = !1, _ = 0, v = 0;
|
|
79
|
+
for (let t = 0; t < e.length; t++) {
|
|
80
|
+
let n = e[t], s = "", y = (e) => {
|
|
81
|
+
if (p && p.indices.length === 0 && p.name.toLowerCase() === "value" && (g = !0), p && p.indices.length > 0 && p.stringIndex === p.indices[0]) {
|
|
82
|
+
let n = p.indices[p.indices.length - 1], r = t === n + 1 ? e : 0;
|
|
83
|
+
c[p.indices[0]] = Object.freeze({
|
|
84
|
+
indices: Object.freeze(p.indices),
|
|
85
|
+
prefix: p.prefix,
|
|
86
|
+
suffixLength: r
|
|
87
|
+
});
|
|
88
|
+
let i = o[p.indices[0]];
|
|
89
|
+
(p.indices.length > 1 || r !== +!!i.quote) && (i.whole = !1);
|
|
90
|
+
}
|
|
91
|
+
p = null;
|
|
92
|
+
}, b = () => {
|
|
93
|
+
y(0);
|
|
94
|
+
let e = l.tagName !== "textarea" && l.tagName !== "select" && !g;
|
|
95
|
+
for (let n of h) n.directValue = e, n.tagEndString = t, n.tagEndOffset = s.length;
|
|
96
|
+
h = [], l.state === 11 && (u = !0);
|
|
97
|
+
};
|
|
98
|
+
for (let e = 0; e < n.length;) {
|
|
99
|
+
let i = n[e], o = l.state, c = d(l, n, e), x = l.state;
|
|
100
|
+
switch (o) {
|
|
101
|
+
case 0:
|
|
102
|
+
x === 1 && (h = [], g = !1, _ = t, v = s.length);
|
|
103
|
+
break;
|
|
104
|
+
case 1:
|
|
105
|
+
x !== 1 && (s += r, m = -1);
|
|
106
|
+
break;
|
|
107
|
+
case 2:
|
|
108
|
+
case 4:
|
|
109
|
+
if (x === 3) {
|
|
110
|
+
y(e);
|
|
111
|
+
let n = s.length;
|
|
112
|
+
p = {
|
|
113
|
+
name: i,
|
|
114
|
+
stringIndex: t,
|
|
115
|
+
nameStart: n,
|
|
116
|
+
spaceStart: m < 0 ? n : m,
|
|
117
|
+
indices: [],
|
|
118
|
+
prefix: ""
|
|
119
|
+
}, m = -1;
|
|
120
|
+
} else a(i) ? m < 0 && (m = s.length) : i === "/" ? m = -1 : x !== 5 && b();
|
|
121
|
+
break;
|
|
122
|
+
case 3:
|
|
123
|
+
x === 3 ? p && (p.name += n.slice(e, c)) : x === 4 ? m = s.length : x === 2 && (y(e), m = -1);
|
|
124
|
+
break;
|
|
125
|
+
case 5:
|
|
126
|
+
x === 6 ? f = !0 : (x === 0 || x === 11) && (y(e), b());
|
|
127
|
+
break;
|
|
128
|
+
case 6:
|
|
129
|
+
x === 2 ? (y(e + 1), m = -1) : f = !1;
|
|
130
|
+
break;
|
|
131
|
+
case 7:
|
|
132
|
+
x === 2 && (y(e), m = -1);
|
|
133
|
+
break;
|
|
134
|
+
case 11:
|
|
135
|
+
x === 11 && (u = !1);
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
s += n.slice(e, c), e = c;
|
|
139
|
+
}
|
|
140
|
+
if (t < e.length - 1) switch (l.state) {
|
|
141
|
+
case 0:
|
|
142
|
+
n.endsWith("</") ? (o.push({
|
|
143
|
+
kind: "tag",
|
|
144
|
+
closing: !0
|
|
145
|
+
}), l.state = 8) : n.endsWith("<") ? (o.push({
|
|
146
|
+
kind: "tag",
|
|
147
|
+
closing: !1
|
|
148
|
+
}), l.state = 2, l.tagName = "", h = [], g = !1, _ = t, v = s.length - 1, m = -1) : o.push({ kind: "node" });
|
|
149
|
+
break;
|
|
150
|
+
case 9:
|
|
151
|
+
case 10:
|
|
152
|
+
o.push({ kind: "comment" });
|
|
153
|
+
break;
|
|
154
|
+
case 11:
|
|
155
|
+
o.push({
|
|
156
|
+
kind: "raw-text",
|
|
157
|
+
tag: l.rawTextTag,
|
|
158
|
+
first: u
|
|
159
|
+
}), u = !1;
|
|
160
|
+
break;
|
|
161
|
+
case 5:
|
|
162
|
+
case 6:
|
|
163
|
+
case 7: {
|
|
164
|
+
if (!p) {
|
|
165
|
+
o.push({ kind: "element" });
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
let e = p, n = l.state === 6, r = (l.state === 5 || n && f) && e.stringIndex === t;
|
|
169
|
+
e.indices.length === 0 && e.stringIndex === t && (e.prefix = s.slice(e.spaceStart)), e.indices.push(t);
|
|
170
|
+
let i = {
|
|
171
|
+
kind: "attribute",
|
|
172
|
+
name: e.name,
|
|
173
|
+
start: r,
|
|
174
|
+
whole: r,
|
|
175
|
+
quote: n ? l.quote : "",
|
|
176
|
+
prefixStart: r ? e.nameStart : -1,
|
|
177
|
+
directValue: !1,
|
|
178
|
+
tagString: _,
|
|
179
|
+
tagOffset: v,
|
|
180
|
+
tagEndString: -1,
|
|
181
|
+
tagEndOffset: -1
|
|
182
|
+
};
|
|
183
|
+
o.push(i), h.push(i), l.state === 5 && (l.state = 7), f = !1;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
default:
|
|
187
|
+
o.push({ kind: "element" }), (l.state === 3 || l.state === 4) && y(0);
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
i.push(s);
|
|
191
|
+
}
|
|
192
|
+
for (let e of o) Object.freeze(e);
|
|
193
|
+
return Object.freeze({
|
|
194
|
+
strings: Object.freeze(i),
|
|
195
|
+
bindings: Object.freeze(o),
|
|
196
|
+
attributeGroups: Object.freeze(c)
|
|
197
|
+
});
|
|
198
|
+
}, p = (e) => {
|
|
199
|
+
let t = [];
|
|
200
|
+
return m(e, (e) => {
|
|
201
|
+
t.push(e);
|
|
202
|
+
}), t;
|
|
203
|
+
}, m = (e, t) => {
|
|
204
|
+
let n = s(), r = 0, i = -1, o = [], c, l = !1, u = (e, a) => {
|
|
205
|
+
c && c.nameEnd < 0 && (c.nameEnd = e), c && c.valueStart >= 0 && c.valueEnd < 0 && (c.valueEnd = e), t({
|
|
206
|
+
type: "start-tag",
|
|
207
|
+
start: r,
|
|
208
|
+
end: e,
|
|
209
|
+
name: n.tagName,
|
|
210
|
+
nameEnd: i < 0 ? e : i,
|
|
211
|
+
attributes: o,
|
|
212
|
+
selfClosing: a && l,
|
|
213
|
+
closed: a
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
for (let s = 0; s < e.length;) {
|
|
217
|
+
let f = e[s], p = n.state, m = d(n, e, s), h = n.state;
|
|
218
|
+
switch (p) {
|
|
219
|
+
case 0:
|
|
220
|
+
h !== 0 && (s > r && t({
|
|
221
|
+
type: "text",
|
|
222
|
+
start: r,
|
|
223
|
+
end: s
|
|
224
|
+
}), r = s, h === 1 && (i = -1, o = [], c = void 0, l = !1));
|
|
225
|
+
break;
|
|
226
|
+
case 11:
|
|
227
|
+
h === 8 && (s > r && t({
|
|
228
|
+
type: "raw-text",
|
|
229
|
+
start: r,
|
|
230
|
+
end: s,
|
|
231
|
+
tag: n.rawTextTag
|
|
232
|
+
}), r = s);
|
|
233
|
+
break;
|
|
234
|
+
case 8:
|
|
235
|
+
if (h === 0) {
|
|
236
|
+
let n = r + 2;
|
|
237
|
+
for (; n < m && !a(e[n]) && e[n] !== "/" && e[n] !== ">";) n++;
|
|
238
|
+
t({
|
|
239
|
+
type: "end-tag",
|
|
240
|
+
start: r,
|
|
241
|
+
end: m,
|
|
242
|
+
name: e.slice(r + 2, n).toLowerCase(),
|
|
243
|
+
nameEnd: n
|
|
244
|
+
}), r = m;
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
case 9:
|
|
248
|
+
case 10:
|
|
249
|
+
h === 0 && (t({
|
|
250
|
+
type: p === 9 ? "comment" : "other",
|
|
251
|
+
start: r,
|
|
252
|
+
end: m
|
|
253
|
+
}), r = m);
|
|
254
|
+
break;
|
|
255
|
+
case 1:
|
|
256
|
+
h !== 1 && (i = s);
|
|
257
|
+
break;
|
|
258
|
+
case 2:
|
|
259
|
+
case 4:
|
|
260
|
+
h === 3 ? (c = {
|
|
261
|
+
name: "",
|
|
262
|
+
nameStart: s,
|
|
263
|
+
nameEnd: -1,
|
|
264
|
+
valueStart: -1,
|
|
265
|
+
valueEnd: -1,
|
|
266
|
+
quote: ""
|
|
267
|
+
}, o.push(c)) : (h === 0 || h === 11) && (u(m, !0), r = m), l = f === "/";
|
|
268
|
+
break;
|
|
269
|
+
case 3:
|
|
270
|
+
h !== 3 && c && (c.nameEnd = s, c.name = e.slice(c.nameStart, s));
|
|
271
|
+
break;
|
|
272
|
+
case 5:
|
|
273
|
+
if (!c) break;
|
|
274
|
+
h === 6 ? (c.quote = n.quote, c.valueStart = s + 1) : h === 7 ? c.valueStart = s : (h === 0 || h === 11) && (c.valueStart = c.valueEnd = s, u(m, !0), r = m);
|
|
275
|
+
break;
|
|
276
|
+
case 6:
|
|
277
|
+
case 7:
|
|
278
|
+
h === 2 && c && (c.valueEnd = s);
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
s = m;
|
|
282
|
+
}
|
|
283
|
+
if (r < e.length) {
|
|
284
|
+
let i = e.length;
|
|
285
|
+
switch (n.state) {
|
|
286
|
+
case 0:
|
|
287
|
+
t({
|
|
288
|
+
type: "text",
|
|
289
|
+
start: r,
|
|
290
|
+
end: i
|
|
291
|
+
});
|
|
292
|
+
break;
|
|
293
|
+
case 11:
|
|
294
|
+
t({
|
|
295
|
+
type: "raw-text",
|
|
296
|
+
start: r,
|
|
297
|
+
end: i,
|
|
298
|
+
tag: n.rawTextTag
|
|
299
|
+
});
|
|
300
|
+
break;
|
|
301
|
+
case 1:
|
|
302
|
+
case 2:
|
|
303
|
+
case 3:
|
|
304
|
+
case 4:
|
|
305
|
+
case 5:
|
|
306
|
+
case 6:
|
|
307
|
+
case 7:
|
|
308
|
+
c && c.name === "" && (c.name = e.slice(c.nameStart, c.nameEnd < 0 ? i : c.nameEnd)), u(i, !1);
|
|
309
|
+
break;
|
|
310
|
+
default:
|
|
311
|
+
t({
|
|
312
|
+
type: "other",
|
|
313
|
+
start: r,
|
|
314
|
+
end: i
|
|
315
|
+
});
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
//#endregion
|
|
321
|
+
export { e as RAW_TEXT_TAGS, i as State, f as analyzeTemplate, s as createTokenizer, m as forEachHtmlToken, r as getTemplateAnalysis, a as isSpace, d as step, t as templateAnalysisStats, p as tokenizeHtml };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export interface TemplateLocation {
|
|
2
|
+
readonly string: number;
|
|
3
|
+
readonly offset: number;
|
|
4
|
+
}
|
|
5
|
+
export interface TemplateRange {
|
|
6
|
+
readonly start: TemplateLocation;
|
|
7
|
+
readonly end: TemplateLocation;
|
|
8
|
+
}
|
|
9
|
+
export interface TemplateAttribute {
|
|
10
|
+
/** The name as written, including a `.`, `?` or `@` prefix, or `...`. */
|
|
11
|
+
readonly name: string;
|
|
12
|
+
/** From the first character of the name to the end of the value. */
|
|
13
|
+
readonly range: TemplateRange;
|
|
14
|
+
readonly nameRange: TemplateRange;
|
|
15
|
+
/** False for a bare attribute such as `disabled`. */
|
|
16
|
+
readonly hasValue: boolean;
|
|
17
|
+
readonly quote: '"' | "'" | '';
|
|
18
|
+
/**
|
|
19
|
+
* The value's static text around its bindings, as written (entities are
|
|
20
|
+
* not decoded). Always one more entry than `bindings`.
|
|
21
|
+
*/
|
|
22
|
+
readonly segments: readonly string[];
|
|
23
|
+
readonly bindings: readonly number[];
|
|
24
|
+
}
|
|
25
|
+
export type TemplateNamespace = 'html' | 'svg' | 'mathml';
|
|
26
|
+
interface TagNode {
|
|
27
|
+
readonly attributes: readonly TemplateAttribute[];
|
|
28
|
+
/** Bindings in the start tag outside any attribute value. They render nothing. */
|
|
29
|
+
readonly droppedBindings: readonly number[];
|
|
30
|
+
readonly children: readonly TemplateNode[];
|
|
31
|
+
/** From the start tag's `<` to the end of the end tag, or of the start tag. */
|
|
32
|
+
readonly range: TemplateRange;
|
|
33
|
+
readonly startTag: TemplateRange;
|
|
34
|
+
/** The start tag ends with `/>`. */
|
|
35
|
+
readonly selfClosing: boolean;
|
|
36
|
+
readonly namespace: TemplateNamespace;
|
|
37
|
+
}
|
|
38
|
+
export interface TemplateElement extends TagNode {
|
|
39
|
+
readonly type: 'element';
|
|
40
|
+
/** The tag name as written. */
|
|
41
|
+
readonly tag: string;
|
|
42
|
+
/** The lowercase tag name. */
|
|
43
|
+
readonly name: string;
|
|
44
|
+
/** An end tag closed the element. Void and self-closing elements need none. */
|
|
45
|
+
readonly closed: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** `<${Card} ...>children</${Card}>` or `<${Card} ... />`. */
|
|
48
|
+
export interface TemplateComponent extends TagNode {
|
|
49
|
+
readonly type: 'component';
|
|
50
|
+
/** The binding that holds the component class. */
|
|
51
|
+
readonly binding: number;
|
|
52
|
+
/** The binding of the closing tag; null when self-closing or unclosed. */
|
|
53
|
+
readonly closeBinding: number | null;
|
|
54
|
+
/** Where the closing tag's `</` starts; null when self-closing or unclosed. */
|
|
55
|
+
readonly closeStart: TemplateLocation | null;
|
|
56
|
+
}
|
|
57
|
+
export interface TemplateText {
|
|
58
|
+
readonly type: 'text';
|
|
59
|
+
/** As written: entities are not decoded. */
|
|
60
|
+
readonly text: string;
|
|
61
|
+
readonly range: TemplateRange;
|
|
62
|
+
}
|
|
63
|
+
/** A binding in node position, or in the text of a raw-text element. */
|
|
64
|
+
export interface TemplateBindingNode {
|
|
65
|
+
readonly type: 'binding';
|
|
66
|
+
readonly binding: number;
|
|
67
|
+
/** Text of `<script>`, `<style>`, `<textarea>` or `<title>`. */
|
|
68
|
+
readonly rawText: boolean;
|
|
69
|
+
}
|
|
70
|
+
export interface TemplateComment {
|
|
71
|
+
readonly type: 'comment';
|
|
72
|
+
readonly range: TemplateRange;
|
|
73
|
+
readonly bindings: readonly number[];
|
|
74
|
+
}
|
|
75
|
+
export type TemplateNode = TemplateElement | TemplateComponent | TemplateText | TemplateBindingNode | TemplateComment;
|
|
76
|
+
export type TemplateBindingRole = {
|
|
77
|
+
readonly kind: 'node';
|
|
78
|
+
readonly parent: TemplateElement | TemplateComponent | null;
|
|
79
|
+
} | {
|
|
80
|
+
readonly kind: 'raw-text';
|
|
81
|
+
readonly element: TemplateElement | null;
|
|
82
|
+
} | {
|
|
83
|
+
readonly kind: 'attribute';
|
|
84
|
+
readonly owner: TemplateElement | TemplateComponent;
|
|
85
|
+
readonly attribute: TemplateAttribute;
|
|
86
|
+
} | {
|
|
87
|
+
readonly kind: 'tag';
|
|
88
|
+
readonly component: TemplateComponent;
|
|
89
|
+
readonly closing: boolean;
|
|
90
|
+
}
|
|
91
|
+
/** Inside a comment, a tag outside any attribute value, or an end tag. Renders nothing. */
|
|
92
|
+
| {
|
|
93
|
+
readonly kind: 'dropped';
|
|
94
|
+
readonly reason: 'comment' | 'tag' | 'end-tag';
|
|
95
|
+
};
|
|
96
|
+
export type TemplateProblemCode = 'COSSACK_TEMPLATE_UNTERMINATED' | 'COSSACK_TEMPLATE_DROPPED_BINDING' | 'COSSACK_TEMPLATE_UNCLOSED_ELEMENT' | 'COSSACK_TEMPLATE_UNEXPECTED_END_TAG' | 'COSSACK_TEMPLATE_SELF_CLOSING_ELEMENT' | 'COSSACK_TEMPLATE_UNKNOWN_BINDING_PREFIX' | 'COSSACK_TEMPLATE_PREFIX_WITHOUT_BINDING' | 'COSSACK_TEMPLATE_PARTIAL_BINDING' | 'COSSACK_TEMPLATE_DUPLICATE_ATTRIBUTE' | 'COSSACK_TEMPLATE_UNCLOSED_COMPONENT' | 'COSSACK_TEMPLATE_UNEXPECTED_COMPONENT_END' | 'COSSACK_TEMPLATE_INLINE_SCRIPT';
|
|
97
|
+
export interface TemplateProblem {
|
|
98
|
+
readonly code: TemplateProblemCode;
|
|
99
|
+
readonly severity: 'error' | 'warning';
|
|
100
|
+
readonly message: string;
|
|
101
|
+
readonly range: TemplateRange;
|
|
102
|
+
}
|
|
103
|
+
export interface ParsedTemplate {
|
|
104
|
+
readonly nodes: readonly TemplateNode[];
|
|
105
|
+
/** The role of each binding, by index. */
|
|
106
|
+
readonly bindings: readonly TemplateBindingRole[];
|
|
107
|
+
readonly problems: readonly TemplateProblem[];
|
|
108
|
+
}
|
|
109
|
+
/** Elements that never have content or an end tag. */
|
|
110
|
+
export declare const VOID_ELEMENTS: ReadonlySet<string>;
|
|
111
|
+
export declare const parseTemplate: (strings: readonly string[], options?: {
|
|
112
|
+
svg?: boolean;
|
|
113
|
+
}) => ParsedTemplate;
|
|
114
|
+
/** The tag being written at a location: an element (with its namespace) or a component tag. */
|
|
115
|
+
export type TemplateContextTag = {
|
|
116
|
+
readonly component: false;
|
|
117
|
+
readonly tag: string;
|
|
118
|
+
readonly name: string;
|
|
119
|
+
readonly namespace: TemplateNamespace;
|
|
120
|
+
} | {
|
|
121
|
+
readonly component: true;
|
|
122
|
+
readonly binding: number;
|
|
123
|
+
};
|
|
124
|
+
/** What an editor is writing at a location in a template. */
|
|
125
|
+
export type TemplateContext = {
|
|
126
|
+
readonly kind: 'text';
|
|
127
|
+
readonly namespace: TemplateNamespace;
|
|
128
|
+
} | {
|
|
129
|
+
readonly kind: 'tag-name';
|
|
130
|
+
readonly prefix: string;
|
|
131
|
+
readonly namespace: TemplateNamespace;
|
|
132
|
+
} | {
|
|
133
|
+
readonly kind: 'attribute-name';
|
|
134
|
+
readonly prefix: string;
|
|
135
|
+
readonly tag: TemplateContextTag;
|
|
136
|
+
readonly attributes: readonly string[];
|
|
137
|
+
} | {
|
|
138
|
+
readonly kind: 'attribute-value';
|
|
139
|
+
readonly name: string;
|
|
140
|
+
readonly prefix: string;
|
|
141
|
+
readonly quote: '"' | "'" | '';
|
|
142
|
+
readonly tag: TemplateContextTag;
|
|
143
|
+
} | {
|
|
144
|
+
readonly kind: 'end-tag';
|
|
145
|
+
readonly prefix: string;
|
|
146
|
+
readonly open: TemplateElement | null;
|
|
147
|
+
} | {
|
|
148
|
+
readonly kind: 'other';
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* The context at `location` in a template's strings, for editor completions:
|
|
152
|
+
* text, a tag name, an attribute name or value, or an end tag.
|
|
153
|
+
*/
|
|
154
|
+
export declare const templateContextAt: (strings: readonly string[], location: TemplateLocation, options?: {
|
|
155
|
+
svg?: boolean;
|
|
156
|
+
}) => TemplateContext;
|
|
157
|
+
export {};
|