@unframework.dev/testing 0.0.0-stage → 0.2.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/README.md +536 -2
- package/dist/browser/axe.js +34 -0
- package/dist/browser/behaviour.js +59 -0
- package/dist/browser/capabilities.js +58 -0
- package/dist/browser/clock.d.ts +17 -0
- package/dist/browser/clock.js +69 -0
- package/dist/browser/console.d.ts +27 -0
- package/dist/browser/console.js +142 -0
- package/dist/browser/determinism.js +108 -0
- package/dist/browser/element-timeout.js +28 -0
- package/dist/browser/events.js +68 -0
- package/dist/browser/geometry.js +135 -0
- package/dist/browser/keys.js +62 -0
- package/dist/browser/matchers.d.ts +39 -0
- package/dist/browser/matchers.js +78 -0
- package/dist/browser/navigation.js +38 -0
- package/dist/browser/parity.d.ts +10 -0
- package/dist/browser/parity.js +93 -0
- package/dist/browser/spec.d.ts +25 -0
- package/dist/browser/spec.js +38 -0
- package/dist/browser/target.d.ts +16 -0
- package/dist/browser/target.js +27 -0
- package/dist/browser/text-runs.js +68 -0
- package/dist/browser/thrown.js +71 -0
- package/dist/browser/trace.d.ts +21 -0
- package/dist/browser/trace.js +73 -0
- package/dist/browser/user.d.ts +45 -0
- package/dist/browser/user.js +184 -0
- package/dist/browser/view.d.ts +114 -0
- package/dist/browser/view.js +282 -0
- package/dist/browser/visual.d.ts +20 -0
- package/dist/browser/visual.js +36 -0
- package/dist/cli.d.ts +23 -0
- package/dist/cli.js +90 -0
- package/dist/commands.d.ts +107 -0
- package/dist/config/broadcast.js +29 -0
- package/dist/config/cases.d.ts +28 -0
- package/dist/config/cases.js +94 -0
- package/dist/config/index.d.ts +82 -0
- package/dist/config/index.js +295 -0
- package/dist/config/project-vite.d.ts +40 -0
- package/dist/config/project-vite.js +152 -0
- package/dist/diff.d.ts +14 -0
- package/dist/diff.js +92 -0
- package/dist/dom/serialize.js +236 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +38 -0
- package/dist/harness.d.ts +189 -0
- package/dist/harness.js +53 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +12 -0
- package/dist/internal.d.ts +8 -0
- package/dist/internal.js +6 -0
- package/dist/layers.d.ts +183 -0
- package/dist/layers.js +241 -0
- package/dist/node/browser.d.ts +33 -0
- package/dist/node/browser.js +64 -0
- package/dist/node/commands.d.ts +137 -0
- package/dist/node/commands.js +139 -0
- package/dist/node/context.d.ts +28 -0
- package/dist/node/context.js +55 -0
- package/dist/node/events.d.ts +25 -0
- package/dist/node/events.js +50 -0
- package/dist/node/finished.d.ts +12 -0
- package/dist/node/finished.js +28 -0
- package/dist/node/index.d.ts +21 -0
- package/dist/node/index.js +20 -0
- package/dist/node/matrix.d.ts +219 -0
- package/dist/node/matrix.js +309 -0
- package/dist/node/mode.d.ts +103 -0
- package/dist/node/mode.js +204 -0
- package/dist/node/names.d.ts +4 -0
- package/dist/node/names.js +5 -0
- package/dist/node/policy.d.ts +44 -0
- package/dist/node/policy.js +140 -0
- package/dist/node/reporter.d.ts +101 -0
- package/dist/node/reporter.js +251 -0
- package/dist/node/summary.d.ts +99 -0
- package/dist/node/summary.js +352 -0
- package/dist/node/thrown.js +78 -0
- package/dist/node/viewport.d.ts +7 -0
- package/dist/node/viewport.js +8 -0
- package/dist/node/visual.d.ts +85 -0
- package/dist/node/visual.js +373 -0
- package/dist/node_modules/.pnpm/playwright-core@1.63.0/node_modules/playwright-core/types/protocol.d.ts +23930 -0
- package/dist/node_modules/.pnpm/playwright-core@1.63.0/node_modules/playwright-core/types/structs.d.ts +22 -0
- package/dist/node_modules/.pnpm/playwright-core@1.63.0/node_modules/playwright-core/types/types.d.ts +22221 -0
- package/dist/normalize/display.js +309 -0
- package/dist/normalize/index.d.ts +34 -0
- package/dist/normalize/index.js +38 -0
- package/dist/normalize/pipeline.d.ts +19 -0
- package/dist/normalize/pipeline.js +45 -0
- package/dist/normalize/print.js +103 -0
- package/dist/normalize/rules/angular-hosts.js +53 -0
- package/dist/normalize/rules/aria-hosts.js +48 -0
- package/dist/normalize/rules/comments.js +16 -0
- package/dist/normalize/rules/control-values.js +65 -0
- package/dist/normalize/rules/engine-aliases.js +34 -0
- package/dist/normalize/rules/framework-attributes.js +85 -0
- package/dist/normalize/rules/generated-ids.js +64 -0
- package/dist/normalize/rules/ordering.js +39 -0
- package/dist/normalize/rules/qwik-styles.js +21 -0
- package/dist/normalize/rules/qwik-templates.js +20 -0
- package/dist/normalize/rules/values.js +125 -0
- package/dist/normalize/rules/whitespace.js +381 -0
- package/dist/normalize/style.js +121 -0
- package/dist/normalize/targets.d.ts +8 -0
- package/dist/normalize/targets.js +17 -0
- package/dist/normalize/tree.d.ts +1 -0
- package/dist/normalize/tree.js +151 -0
- package/dist/setup.d.ts +1 -0
- package/dist/setup.js +149 -0
- package/dist/ssr/index.d.ts +10 -0
- package/dist/ssr/index.js +103 -0
- package/dist/ssr/spec.d.ts +1 -0
- package/dist/ssr/spec.js +7 -0
- package/dist/targets/angular.d.ts +1 -0
- package/dist/targets/angular.js +5 -0
- package/dist/targets/astro.d.ts +1 -0
- package/dist/targets/astro.js +5 -0
- package/dist/targets/qwik.d.ts +1 -0
- package/dist/targets/qwik.js +5 -0
- package/dist/targets/react.d.ts +1 -0
- package/dist/targets/react.js +5 -0
- package/dist/targets/solid.d.ts +1 -0
- package/dist/targets/solid.js +5 -0
- package/dist/targets/svelte.d.ts +1 -0
- package/dist/targets/svelte.js +5 -0
- package/dist/targets/vue.d.ts +1 -0
- package/dist/targets/vue.js +5 -0
- package/dist/visual-types.d.ts +92 -0
- package/dist/visual-types.js +24 -0
- package/package.json +146 -3
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { HTML_NAMESPACE, childrenOf, isElement, isText, replaceChildren } from "../tree.js";
|
|
2
|
+
import { boxOf, preservesWhitespace } from "../display.js";
|
|
3
|
+
//#region src/normalize/rules/whitespace.ts
|
|
4
|
+
/** The whitespace `white-space: normal` collapses: spaces, tabs and line breaks (not U+00A0). */
|
|
5
|
+
const COLLAPSIBLE = /[ \t\n\r]+/g;
|
|
6
|
+
/** A segment break: a line break in the source text. */
|
|
7
|
+
const SEGMENT_BREAK = /[\n\r]/;
|
|
8
|
+
/** Text that is nothing but collapsible whitespace. */
|
|
9
|
+
const WHITESPACE_ONLY = /^[ \t\n\r]*$/;
|
|
10
|
+
/** Text whose last character is ASCII whitespace, as Chromium's layout tree builder tests it. */
|
|
11
|
+
const ENDS_WITH_WHITESPACE = /[ \t\n\f\r]$/;
|
|
12
|
+
/** U+200B ZERO WIDTH SPACE, next to which a segment break is removed, not rendered as a space. */
|
|
13
|
+
const ZWSP = "";
|
|
14
|
+
/**
|
|
15
|
+
* Texts that collapsed away beside a ruby, which stay in the tree, empty (see `emptied`). Only
|
|
16
|
+
* this rule leaves empty text, which prints as `""`.
|
|
17
|
+
*/
|
|
18
|
+
const keptEmpty = /* @__PURE__ */ new WeakSet();
|
|
19
|
+
/**
|
|
20
|
+
* Rule 6: collapses whitespace the way Chromium renders it under `white-space: normal` (CSS
|
|
21
|
+
* Text 3, phases I and II, as Blink's inline items builder implements them), so markup that
|
|
22
|
+
* renders the same text prints the same, and markup that renders differently stays different.
|
|
23
|
+
* Where the result depends on more than a static reading can see, whitespace is kept as
|
|
24
|
+
* written: two outputs then compare equal only if they wrote it alike, a loud difference rather
|
|
25
|
+
* than a hidden one.
|
|
26
|
+
*
|
|
27
|
+
* - Runs of spaces, tabs and line breaks become one space, and a space that follows another
|
|
28
|
+
* collapsible space on the same line goes, even across inline element boundaries
|
|
29
|
+
* (`a <b> b</b>` is `"a "`, `<b>"b"</b>`). Line breaks become spaces, as Chromium renders
|
|
30
|
+
* them (CSS's East Asian segment-break rules are not applied).
|
|
31
|
+
* - Next to a zero-width space, a line break goes with the spaces around it: in a text, a run
|
|
32
|
+
* with a line break between U+200B (or a `<wbr>`) and anything, or before U+200B, renders
|
|
33
|
+
* nothing, and so does the pending space of an earlier text when this one starts so. The
|
|
34
|
+
* edge of a ruby or a bidi isolate (`dir`, `<bdi>`), and the end of a ruby annotation, hides
|
|
35
|
+
* a U+200B from a line break on its other side (`Box.opaqueStart`, `Box.opaqueEnd`).
|
|
36
|
+
* - A whitespace-only text Chromium does not render at all (after text that ends in
|
|
37
|
+
* whitespace, after a block or `<br>`, as the first child of a block; in a table or a flex or
|
|
38
|
+
* grid container, anywhere but after text) takes no part, not even in those removals.
|
|
39
|
+
* - Spaces at the start and end of a line go: at the edges of a block's inline content, next
|
|
40
|
+
* to a block-level sibling, and around `<br>` (not before one in preserved whitespace). So Svelte's `" "` between two blocks vanishes,
|
|
41
|
+
* and Vue's condensed `<p>\n Line one<br>Line two\n</p>` equals React's
|
|
42
|
+
* `<p>Line one<br>Line two</p>`.
|
|
43
|
+
* - A space next to an atomic inline (an image, a control, an inline-block) is content and
|
|
44
|
+
* stays: `<img> <input>` and `<img><input>` stay different, as they render differently. So
|
|
45
|
+
* does a space inside a `<q>`, next to the quotation marks it generates.
|
|
46
|
+
* - A float or an absolutely positioned box is not there as far as the line is concerned:
|
|
47
|
+
* whitespace collapses across it, and its own content is laid out on its own.
|
|
48
|
+
* - Each element's box comes from its inline `display` or the user-agent default (see
|
|
49
|
+
* `display.ts`): block-level boxes break lines, inline boxes are transparent, `display:
|
|
50
|
+
* contents` children take its place, flex and grid children are blockified, and elements
|
|
51
|
+
* that are not rendered are normalised on their own. A ruby lays its content out on one
|
|
52
|
+
* line: a `<br>`, a block or a float inside it, or a preserved line break, does not end it;
|
|
53
|
+
* a list item there is an inline that starts with its marker.
|
|
54
|
+
* - A table-internal box (a cell, a row, a caption, …) whose parent is an inline box sits in
|
|
55
|
+
* an anonymous inline table, which Chromium builds with whitespace rules of its own (a
|
|
56
|
+
* whitespace-only text after it renders nothing, and the next table-internal sibling joins
|
|
57
|
+
* it): every whitespace of that line, and of the box's own content, is kept as written. In
|
|
58
|
+
* a block container it is a block-level table, a block; blockified, a block container.
|
|
59
|
+
* - Text that keeps its whitespace (`pre`, `textarea`, `listing`, `plaintext`, raw-text
|
|
60
|
+
* elements, SVG `<style>` and `<script>`, and inline `white-space: pre`, `pre-wrap`,
|
|
61
|
+
* `pre-line` or `break-spaces`, which is inherited) is left exactly as it is. A collapsible
|
|
62
|
+
* line break after a preserved space or tab is kept as written: Chromium removes it, with
|
|
63
|
+
* the spaces before it, or renders it, depending on the texts around it.
|
|
64
|
+
*
|
|
65
|
+
* Text this rule empties is removed, except beside a ruby, where it stays, empty (`emptied`).
|
|
66
|
+
* Soft wraps depend on the viewport, so a space at the end of a wrapped line stays.
|
|
67
|
+
*/
|
|
68
|
+
function collapseWhitespace(root) {
|
|
69
|
+
formatBlock(root, {
|
|
70
|
+
preserve: false,
|
|
71
|
+
blockify: false,
|
|
72
|
+
dropsWhitespace: false,
|
|
73
|
+
ruby: false,
|
|
74
|
+
rubyContainer: false
|
|
75
|
+
});
|
|
76
|
+
removeEmptyText(root);
|
|
77
|
+
}
|
|
78
|
+
/** Lays out a block container's content as one inline formatting context. */
|
|
79
|
+
function formatBlock(container, context, quotes = false) {
|
|
80
|
+
const line = {
|
|
81
|
+
atStart: true,
|
|
82
|
+
trailing: null,
|
|
83
|
+
trailingBreak: false,
|
|
84
|
+
trailingAfterZeroWidthSpace: false,
|
|
85
|
+
trailingAfterUncollapsed: false,
|
|
86
|
+
afterZeroWidthSpace: false,
|
|
87
|
+
afterUncollapsed: false,
|
|
88
|
+
emptied: null,
|
|
89
|
+
afterRuby: false
|
|
90
|
+
};
|
|
91
|
+
const keep = holdsInlineTable(container, {
|
|
92
|
+
...context,
|
|
93
|
+
inline: false
|
|
94
|
+
});
|
|
95
|
+
if (quotes) renderContent(line);
|
|
96
|
+
flow(container, line, {
|
|
97
|
+
...context,
|
|
98
|
+
inline: false,
|
|
99
|
+
keep,
|
|
100
|
+
previous: quotes ? "inline" : "none"
|
|
101
|
+
});
|
|
102
|
+
if (quotes) renderContent(line);
|
|
103
|
+
endLine(line);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Whether a table-internal box sits in an anonymous inline table: its parent is an inline box
|
|
107
|
+
* (CSS 2.1 §17.2.1), a blockified ruby's inline ruby included. A blockified one is a block
|
|
108
|
+
* container already (see `boxOf`).
|
|
109
|
+
*/
|
|
110
|
+
function inInlineTable(box, context) {
|
|
111
|
+
return box.tableInternal && (context.inline || context.ruby);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Whether a block container's line holds a box in an anonymous inline table, through inline
|
|
115
|
+
* boxes and `display: contents`, as `flow` lays them out: if so, the line's whitespace is
|
|
116
|
+
* kept as written.
|
|
117
|
+
*/
|
|
118
|
+
function holdsInlineTable(parent, context) {
|
|
119
|
+
return childrenOf(parent).some((node) => {
|
|
120
|
+
if (!isElement(node)) return false;
|
|
121
|
+
const box = childBox(node, context);
|
|
122
|
+
if (inInlineTable(box, context)) return true;
|
|
123
|
+
if (box.outer === "contents") return holdsInlineTable(node, context);
|
|
124
|
+
return box.outer === "inline" && holdsInlineTable(node, {
|
|
125
|
+
blockify: false,
|
|
126
|
+
ruby: context.ruby || box.rubyContent,
|
|
127
|
+
rubyContainer: isRubyContainer(box),
|
|
128
|
+
inline: true
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** A child's box, as its parent lays it out. */
|
|
133
|
+
function childBox(node, context) {
|
|
134
|
+
return boxOf(node, {
|
|
135
|
+
blockifies: context.blockify && !isHtml(node, "wbr"),
|
|
136
|
+
ruby: context.ruby,
|
|
137
|
+
rubyContainer: context.rubyContainer
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/** Whether a box is a ruby container, not an annotation (see `ParentLayout.rubyContainer`). */
|
|
141
|
+
function isRubyContainer(box) {
|
|
142
|
+
return box.rubyContent && !box.rubyAnnotation;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Lays out a node's children into the current line. Returns what came last among them, for a
|
|
146
|
+
* `display: contents` parent's next sibling.
|
|
147
|
+
*/
|
|
148
|
+
function flow(parent, line, context) {
|
|
149
|
+
let previous = context.previous;
|
|
150
|
+
for (const node of childrenOf(parent)) {
|
|
151
|
+
if (isText(node)) {
|
|
152
|
+
if (context.keep) continue;
|
|
153
|
+
const text = node.value;
|
|
154
|
+
if (!rendersText(text, previous, context)) {
|
|
155
|
+
node.value = "";
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (context.preserve) renderPreserved(node, line, context.ruby);
|
|
159
|
+
else collapseText(node, line);
|
|
160
|
+
if (node.value === "") emptied(node, line);
|
|
161
|
+
previous = ENDS_WITH_WHITESPACE.test(text) ? "text-ending-in-whitespace" : "text";
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (!isElement(node)) continue;
|
|
165
|
+
const box = childBox(node, context);
|
|
166
|
+
if (inInlineTable(box, context)) continue;
|
|
167
|
+
const inner = {
|
|
168
|
+
preserve: preservesWhitespace(node, context.preserve),
|
|
169
|
+
blockify: box.blockifiesChildren,
|
|
170
|
+
dropsWhitespace: box.dropsWhitespaceChildren,
|
|
171
|
+
ruby: box.rubyContent,
|
|
172
|
+
rubyContainer: isRubyContainer(box)
|
|
173
|
+
};
|
|
174
|
+
const quotes = generatesQuotes(node);
|
|
175
|
+
switch (box.outer) {
|
|
176
|
+
case "none":
|
|
177
|
+
case "out-of-flow":
|
|
178
|
+
formatBlock(node, inner, quotes);
|
|
179
|
+
break;
|
|
180
|
+
case "contents":
|
|
181
|
+
previous = flow(node, line, {
|
|
182
|
+
...context,
|
|
183
|
+
preserve: inner.preserve,
|
|
184
|
+
previous
|
|
185
|
+
});
|
|
186
|
+
break;
|
|
187
|
+
case "inline":
|
|
188
|
+
if (quotes) renderContent(line);
|
|
189
|
+
if (box.opaqueStart) line.afterZeroWidthSpace = false;
|
|
190
|
+
if (box.rubyContent && line.emptied) keptEmpty.add(line.emptied);
|
|
191
|
+
if (box.listItem) {
|
|
192
|
+
renderContent(line);
|
|
193
|
+
line.atStart = true;
|
|
194
|
+
}
|
|
195
|
+
flow(node, line, {
|
|
196
|
+
...inner,
|
|
197
|
+
blockify: false,
|
|
198
|
+
dropsWhitespace: false,
|
|
199
|
+
inline: true,
|
|
200
|
+
ruby: context.ruby || inner.ruby,
|
|
201
|
+
keep: context.keep,
|
|
202
|
+
previous: quotes ? "inline" : "none"
|
|
203
|
+
});
|
|
204
|
+
if (quotes) renderContent(line);
|
|
205
|
+
if (box.opaqueEnd) line.afterZeroWidthSpace = false;
|
|
206
|
+
if (box.rubyContent) line.afterRuby = true;
|
|
207
|
+
if (isHtml(node, "wbr")) {
|
|
208
|
+
line.afterZeroWidthSpace = true;
|
|
209
|
+
previous = "text";
|
|
210
|
+
} else previous = "inline";
|
|
211
|
+
break;
|
|
212
|
+
case "atomic":
|
|
213
|
+
renderContent(line);
|
|
214
|
+
formatBlock(node, inner, quotes);
|
|
215
|
+
previous = "inline";
|
|
216
|
+
break;
|
|
217
|
+
case "ruby-break":
|
|
218
|
+
renderContent(line);
|
|
219
|
+
previous = "other";
|
|
220
|
+
break;
|
|
221
|
+
case "break":
|
|
222
|
+
if (inner.preserve) {
|
|
223
|
+
renderContent(line);
|
|
224
|
+
line.atStart = true;
|
|
225
|
+
} else endLine(line);
|
|
226
|
+
previous = "other";
|
|
227
|
+
break;
|
|
228
|
+
case "block":
|
|
229
|
+
endLine(line);
|
|
230
|
+
formatBlock(node, inner, quotes);
|
|
231
|
+
endLine(line);
|
|
232
|
+
previous = "other";
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return previous;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Whether Chromium renders a text at all (`Text::TextLayoutObjectIsNeeded`). A text with more
|
|
239
|
+
* than collapsible whitespace always renders; a whitespace-only one renders after text that
|
|
240
|
+
* does not end in whitespace, and, in a parent that is not a table, flex or grid container,
|
|
241
|
+
* after an inline box, or first in an inline box.
|
|
242
|
+
*/
|
|
243
|
+
function rendersText(text, previous, context) {
|
|
244
|
+
if (text === "") return false;
|
|
245
|
+
if (context.preserve || !WHITESPACE_ONLY.test(text)) return true;
|
|
246
|
+
if (previous === "text") return true;
|
|
247
|
+
if (context.dropsWhitespace) return false;
|
|
248
|
+
return previous === "inline" || previous === "none" && context.inline;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Collapses one text's whitespace against the line so far, run by run, as Blink's inline items
|
|
252
|
+
* builder does (`AppendCollapseWhitespace`). A run inside the text knows its neighbours; the
|
|
253
|
+
* text's first run meets the line: the pending space of an earlier text, or what was rendered
|
|
254
|
+
* last.
|
|
255
|
+
*/
|
|
256
|
+
function collapseText(node, line) {
|
|
257
|
+
const source = node.value;
|
|
258
|
+
const whitespaceOnly = WHITESPACE_ONLY.test(source);
|
|
259
|
+
let out = "";
|
|
260
|
+
let previous = "";
|
|
261
|
+
let index = 0;
|
|
262
|
+
const glyphs = (text) => {
|
|
263
|
+
if (text === "") return;
|
|
264
|
+
if (index === 0 && line.trailing !== null && line.trailingBreak && (line.trailingAfterZeroWidthSpace || text.startsWith(ZWSP))) line.trailing.value = line.trailing.value.slice(0, -1);
|
|
265
|
+
out += text;
|
|
266
|
+
renderContent(line);
|
|
267
|
+
line.afterZeroWidthSpace = text.endsWith(ZWSP);
|
|
268
|
+
previous = text;
|
|
269
|
+
};
|
|
270
|
+
for (const match of source.matchAll(COLLAPSIBLE)) {
|
|
271
|
+
glyphs(source.slice(index, match.index));
|
|
272
|
+
const run = match[0];
|
|
273
|
+
const first = match.index === 0;
|
|
274
|
+
index = match.index + run.length;
|
|
275
|
+
const segmentBreak = SEGMENT_BREAK.test(run);
|
|
276
|
+
const nextIsZeroWidthSpace = source.startsWith(ZWSP, index);
|
|
277
|
+
if (!first) {
|
|
278
|
+
if (segmentBreak && (previous.endsWith(ZWSP) || nextIsZeroWidthSpace)) continue;
|
|
279
|
+
out += " ";
|
|
280
|
+
pend(line, node, segmentBreak, previous.endsWith(ZWSP));
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (line.atStart) continue;
|
|
284
|
+
if (line.trailing !== null) {
|
|
285
|
+
const breaks = segmentBreak || line.trailingBreak;
|
|
286
|
+
if (segmentBreak && line.trailingAfterUncollapsed) {
|
|
287
|
+
out += run;
|
|
288
|
+
renderUncollapsed(line);
|
|
289
|
+
} else if (breaks && (line.trailingAfterZeroWidthSpace || nextIsZeroWidthSpace) && !whitespaceOnly) dropTrailing(line);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (segmentBreak && line.afterUncollapsed) {
|
|
293
|
+
out += run;
|
|
294
|
+
renderUncollapsed(line);
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (segmentBreak && (line.afterZeroWidthSpace || nextIsZeroWidthSpace)) continue;
|
|
298
|
+
out += " ";
|
|
299
|
+
pend(line, node, segmentBreak, line.afterZeroWidthSpace);
|
|
300
|
+
}
|
|
301
|
+
glyphs(source.slice(index));
|
|
302
|
+
node.value = out;
|
|
303
|
+
}
|
|
304
|
+
/** Records the collapsible space just written at the end of `node` as the line's pending one. */
|
|
305
|
+
function pend(line, node, segmentBreak, afterZeroWidthSpace) {
|
|
306
|
+
const afterUncollapsed = line.afterUncollapsed;
|
|
307
|
+
renderContent(line);
|
|
308
|
+
line.trailing = node;
|
|
309
|
+
line.trailingBreak = segmentBreak;
|
|
310
|
+
line.trailingAfterZeroWidthSpace = afterZeroWidthSpace;
|
|
311
|
+
line.trailingAfterUncollapsed = afterUncollapsed;
|
|
312
|
+
}
|
|
313
|
+
/** Removes the pending space; the line is back to what was rendered before it. */
|
|
314
|
+
function dropTrailing(line) {
|
|
315
|
+
const afterZeroWidthSpace = line.trailingAfterZeroWidthSpace;
|
|
316
|
+
line.trailing.value = line.trailing.value.slice(0, -1);
|
|
317
|
+
renderContent(line);
|
|
318
|
+
line.afterZeroWidthSpace = afterZeroWidthSpace;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Lays out text that keeps its whitespace: every character of it is rendered. A preserved line
|
|
322
|
+
* break ends the line, except in a ruby, which lays its content out on one line; what a line
|
|
323
|
+
* break after preserved text in a ruby renders is not modelled, so it is kept as written.
|
|
324
|
+
*/
|
|
325
|
+
function renderPreserved(node, line, ruby) {
|
|
326
|
+
renderContent(line);
|
|
327
|
+
line.atStart = !ruby && node.value.endsWith("\n");
|
|
328
|
+
line.afterZeroWidthSpace = node.value.endsWith(ZWSP);
|
|
329
|
+
line.afterUncollapsed = ruby || /[ \t]$/.test(node.value);
|
|
330
|
+
}
|
|
331
|
+
/** Whitespace was kept as written: a line break after it is not known either. */
|
|
332
|
+
function renderUncollapsed(line) {
|
|
333
|
+
renderContent(line);
|
|
334
|
+
line.afterUncollapsed = true;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* A text Chromium lays out stays an item of the line when all of it collapses away, and beside a
|
|
338
|
+
* ruby (or an annotation) that item shows: an annotation overhangs the space next to it only
|
|
339
|
+
* when nothing comes between them. So a text that collapses away right before or after a ruby
|
|
340
|
+
* stays in the tree, empty.
|
|
341
|
+
*/
|
|
342
|
+
function emptied(node, line) {
|
|
343
|
+
if (line.afterRuby) keptEmpty.add(node);
|
|
344
|
+
line.emptied = node;
|
|
345
|
+
}
|
|
346
|
+
/** Something visible was rendered: the pending space stays, and the line has begun. */
|
|
347
|
+
function renderContent(line) {
|
|
348
|
+
line.emptied = null;
|
|
349
|
+
line.afterRuby = false;
|
|
350
|
+
line.atStart = false;
|
|
351
|
+
line.trailing = null;
|
|
352
|
+
line.trailingBreak = false;
|
|
353
|
+
line.trailingAfterZeroWidthSpace = false;
|
|
354
|
+
line.trailingAfterUncollapsed = false;
|
|
355
|
+
line.afterZeroWidthSpace = false;
|
|
356
|
+
line.afterUncollapsed = false;
|
|
357
|
+
}
|
|
358
|
+
/** Ends the line: its trailing collapsible space is not rendered. */
|
|
359
|
+
function endLine(line) {
|
|
360
|
+
if (line.trailing !== null) line.trailing.value = line.trailing.value.slice(0, -1);
|
|
361
|
+
renderContent(line);
|
|
362
|
+
line.atStart = true;
|
|
363
|
+
}
|
|
364
|
+
/** HTML's `<q>`, whose user-agent `::before` and `::after` render quotation marks. */
|
|
365
|
+
function generatesQuotes(element) {
|
|
366
|
+
return isHtml(element, "q");
|
|
367
|
+
}
|
|
368
|
+
function isHtml(element, tag) {
|
|
369
|
+
return element.namespaceURI === HTML_NAMESPACE && element.tagName === tag;
|
|
370
|
+
}
|
|
371
|
+
/** Whether a node is text this rule emptied and does not keep (see `emptied`). */
|
|
372
|
+
function isRemovable(node) {
|
|
373
|
+
return isText(node) && node.value === "" && !keptEmpty.has(node);
|
|
374
|
+
}
|
|
375
|
+
function removeEmptyText(parent) {
|
|
376
|
+
const children = childrenOf(parent);
|
|
377
|
+
if (children.some(isRemovable)) replaceChildren(parent, children.filter((node) => !isRemovable(node)));
|
|
378
|
+
for (const node of childrenOf(parent)) if (isElement(node)) removeEmptyText(node);
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
export { collapseWhitespace };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { cssPropertiesOverlap } from "@unframework.dev/ir";
|
|
2
|
+
//#region src/normalize/style.ts
|
|
3
|
+
/** CSS whitespace (not every Unicode space: U+00A0 is part of a value). */
|
|
4
|
+
const CSS_SPACE = /[ \t\n\r\f]/;
|
|
5
|
+
/**
|
|
6
|
+
* Walks `text` outside strings, escapes and comments (which become one space), calling
|
|
7
|
+
* `onChar` for each top-level character with the current parenthesis depth. Returns the text
|
|
8
|
+
* with comments replaced.
|
|
9
|
+
*/
|
|
10
|
+
function scan(text, onChar) {
|
|
11
|
+
let out = "";
|
|
12
|
+
let quote = "";
|
|
13
|
+
let depth = 0;
|
|
14
|
+
for (let index = 0; index < text.length; index++) {
|
|
15
|
+
const char = text[index];
|
|
16
|
+
if (char === "\\" && index + 1 < text.length) out += char + text[++index];
|
|
17
|
+
else if (quote) {
|
|
18
|
+
out += char;
|
|
19
|
+
if (char === quote) quote = "";
|
|
20
|
+
} else if (char === "/" && text[index + 1] === "*") {
|
|
21
|
+
const end = text.indexOf("*/", index + 2);
|
|
22
|
+
index = end === -1 ? text.length : end + 1;
|
|
23
|
+
out = onChar(" ", depth, out);
|
|
24
|
+
} else {
|
|
25
|
+
if (char === "\"" || char === "'") quote = char;
|
|
26
|
+
else if (char === "(") depth++;
|
|
27
|
+
else if (char === ")" && depth > 0) depth--;
|
|
28
|
+
out = onChar(char, depth, out);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
/** Splits at top-level `separator`s, at most `limit` parts. */
|
|
34
|
+
function split(text, separator, limit) {
|
|
35
|
+
const parts = [];
|
|
36
|
+
const last = scan(text, (char, depth, out) => {
|
|
37
|
+
if (char === separator && depth === 0 && parts.length < limit - 1) {
|
|
38
|
+
parts.push(out);
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
return out + char;
|
|
42
|
+
});
|
|
43
|
+
parts.push(last);
|
|
44
|
+
return parts;
|
|
45
|
+
}
|
|
46
|
+
/** Collapses runs of whitespace outside strings to one space, and trims. */
|
|
47
|
+
function collapse(text) {
|
|
48
|
+
return scan(text, (char, _depth, out) => CSS_SPACE.test(char) ? out.endsWith(" ") ? out : `${out} ` : out + char).trim();
|
|
49
|
+
}
|
|
50
|
+
const IMPORTANT = /\s*!\s*important$/i;
|
|
51
|
+
/** Parses a declaration list (the value of a `style` attribute). */
|
|
52
|
+
function parseStyle(text) {
|
|
53
|
+
const declarations = [];
|
|
54
|
+
for (const chunk of split(text, ";", Number.POSITIVE_INFINITY)) {
|
|
55
|
+
if (collapse(chunk) === "") continue;
|
|
56
|
+
const [name, rest] = split(chunk, ":", 2);
|
|
57
|
+
if (rest === void 0) {
|
|
58
|
+
declarations.push({
|
|
59
|
+
property: collapse(chunk),
|
|
60
|
+
value: void 0,
|
|
61
|
+
important: false
|
|
62
|
+
});
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const property = collapse(name);
|
|
66
|
+
const value = collapse(rest);
|
|
67
|
+
const important = IMPORTANT.test(value);
|
|
68
|
+
declarations.push({
|
|
69
|
+
property: property.startsWith("--") ? property : property.toLowerCase(),
|
|
70
|
+
value: important ? value.replace(IMPORTANT, "") : value,
|
|
71
|
+
important
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return declarations;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Drops each declaration a later one overrides, as the cascade inside one block does: the later
|
|
78
|
+
* declaration of a property wins unless only the earlier one is `!important`. The winner keeps
|
|
79
|
+
* its own position, as in the CSSOM. Order is otherwise kept, because shorthands and longhands
|
|
80
|
+
* (`margin` and `margin-top`) make it significant.
|
|
81
|
+
*
|
|
82
|
+
* It assumes every declaration is valid, which only a browser can check, so it only reads
|
|
83
|
+
* values (`styleValue`, the Angular host check) and never rewrites a `style` attribute.
|
|
84
|
+
*/
|
|
85
|
+
function dedupeDeclarations(declarations) {
|
|
86
|
+
const winners = /* @__PURE__ */ new Map();
|
|
87
|
+
for (const declaration of declarations) {
|
|
88
|
+
if (declaration.value === void 0) continue;
|
|
89
|
+
const previous = winners.get(declaration.property);
|
|
90
|
+
if (!previous || declaration.important || !previous.important) winners.set(declaration.property, declaration);
|
|
91
|
+
}
|
|
92
|
+
return declarations.filter((declaration) => declaration.value === void 0 || winners.get(declaration.property) === declaration);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Prints declarations the way the CSSOM serialises `style.cssText`: `property: value;`,
|
|
96
|
+
* separated by one space, with ` !important` before the semicolon.
|
|
97
|
+
*/
|
|
98
|
+
function printStyle(declarations) {
|
|
99
|
+
return declarations.map(({ property, value, important }) => value === void 0 ? `${property};` : `${property}: ${value}${important ? " !important" : ""};`).join(" ");
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The lowercased value of the last applying declaration of any of `properties` (a shorthand
|
|
103
|
+
* and its longhand: whichever comes last wins), if any.
|
|
104
|
+
*/
|
|
105
|
+
function styleValue(style, ...properties) {
|
|
106
|
+
if (style === void 0) return void 0;
|
|
107
|
+
return dedupeDeclarations(parseStyle(style)).findLast((declaration) => properties.includes(declaration.property))?.value?.toLowerCase();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Sorts declarations by property name, unless the order of two of them decides what renders
|
|
111
|
+
* (`cssPropertiesOverlap` of `@unframework.dev/ir`: the same property, a shorthand and one of its
|
|
112
|
+
* longhands, two shorthands that share one, `all`, or a flow-relative longhand and a physical
|
|
113
|
+
* one that can be the same): then it keeps them as they are. A declaration list without such a
|
|
114
|
+
* pair renders the same in any order, and the targets write it in theirs (an object's key order,
|
|
115
|
+
* the CSSOM's, or static declarations first).
|
|
116
|
+
*/
|
|
117
|
+
function sortDeclarations(declarations) {
|
|
118
|
+
return declarations.some((declaration, index) => declarations.slice(index + 1).some((other) => cssPropertiesOverlap(declaration.property, other.property))) ? [...declarations] : declarations.toSorted((a, b) => a.property < b.property ? -1 : a.property > b.property ? 1 : 0);
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
export { dedupeDeclarations, parseStyle, printStyle, sortDeclarations, styleValue };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/normalize/targets.d.ts
|
|
2
|
+
/** The seven targets whose output the normaliser knows. */
|
|
3
|
+
export declare const NORMALIZE_TARGETS: readonly ["react", "vue", "svelte", "solid", "angular", "qwik", "astro"];
|
|
4
|
+
/** A target the normaliser knows the framework noise of. */
|
|
5
|
+
export type NormalizeTarget = (typeof NORMALIZE_TARGETS)[number];
|
|
6
|
+
/** Whether `target` names one of the seven targets (a stub or third-party target does not). */
|
|
7
|
+
export declare function isNormalizeTarget(target: string): target is NormalizeTarget;
|
|
8
|
+
//#endregion
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/normalize/targets.ts
|
|
2
|
+
/** The seven targets whose output the normaliser knows. */
|
|
3
|
+
const NORMALIZE_TARGETS = [
|
|
4
|
+
"react",
|
|
5
|
+
"vue",
|
|
6
|
+
"svelte",
|
|
7
|
+
"solid",
|
|
8
|
+
"angular",
|
|
9
|
+
"qwik",
|
|
10
|
+
"astro"
|
|
11
|
+
];
|
|
12
|
+
/** Whether `target` names one of the seven targets (a stub or third-party target does not). */
|
|
13
|
+
function isNormalizeTarget(target) {
|
|
14
|
+
return NORMALIZE_TARGETS.includes(target);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { NORMALIZE_TARGETS, isNormalizeTarget };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { html } from "parse5";
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { defaultTreeAdapter, html, parseFragment } from "parse5";
|
|
2
|
+
//#region src/normalize/tree.ts
|
|
3
|
+
const HTML_NAMESPACE = html.NS.HTML;
|
|
4
|
+
const SVG_NAMESPACE = html.NS.SVG;
|
|
5
|
+
const MATHML_NAMESPACE = html.NS.MATHML;
|
|
6
|
+
/**
|
|
7
|
+
* Parse errors that only flag a character the parser keeps as it is (a control character, a
|
|
8
|
+
* noncharacter or a lone surrogate in the text). Every other error means the parser read the
|
|
9
|
+
* markup differently from how it was written.
|
|
10
|
+
*/
|
|
11
|
+
const CHARACTER_ERRORS = /* @__PURE__ */ new Set([
|
|
12
|
+
"control-character-in-input-stream",
|
|
13
|
+
"noncharacter-in-input-stream",
|
|
14
|
+
"surrogate-in-input-stream"
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* Elements the parser creates without a tag in the source, for markup HTML allows: a `<tbody>`
|
|
18
|
+
* around rows written directly in a `<table>`, a `<colgroup>` around `<col>`s. Their start
|
|
19
|
+
* tags are optional, so for HTML text this is not a repair: `<table><tr>` and
|
|
20
|
+
* `<table><tbody><tr>` are the same document, as a browser builds it from server HTML. A live
|
|
21
|
+
* DOM built without them is a different tree, which `normalizeDom` rejects.
|
|
22
|
+
*/
|
|
23
|
+
const IMPLIED_ELEMENTS = /* @__PURE__ */ new Set(["colgroup", "tbody"]);
|
|
24
|
+
/** A source excerpt for an error message. */
|
|
25
|
+
function excerpt(text) {
|
|
26
|
+
return JSON.stringify(text.length > 60 ? `${text.slice(0, 57)}...` : text);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parses HTML the way `element.innerHTML = html` does for an element in `<body>`: as a fragment
|
|
30
|
+
* in a body context, with entities decoded and implied end tags closed.
|
|
31
|
+
*
|
|
32
|
+
* Markup the parser has to repair is rejected rather than normalised, because the repaired
|
|
33
|
+
* tree would hide the difference. That is every tokenizer error (a duplicate attribute,
|
|
34
|
+
* `<div/>`, an unterminated character reference) and every repair of the tree builder (see
|
|
35
|
+
* `treeRepairs`).
|
|
36
|
+
*/
|
|
37
|
+
function parseHtml(source) {
|
|
38
|
+
const errors = [];
|
|
39
|
+
const context = defaultTreeAdapter.createElement("body", html.NS.HTML, []);
|
|
40
|
+
const fragment = parseFragment(context, source, {
|
|
41
|
+
sourceCodeLocationInfo: true,
|
|
42
|
+
onParseError: (error) => {
|
|
43
|
+
if (!CHARACTER_ERRORS.has(error.code)) errors.push(error);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const problems = [...errors.map((error) => ({
|
|
47
|
+
offset: error.startOffset,
|
|
48
|
+
message: error.code
|
|
49
|
+
})), ...treeRepairs(source, fragment)].toSorted((a, b) => a.offset - b.offset);
|
|
50
|
+
if (problems.length > 0) {
|
|
51
|
+
const lines = problems.map(({ offset, message }) => ` ${position(source, offset)} ${message}`);
|
|
52
|
+
throw new Error(`normalizeHtml: the HTML parser had to repair this markup, and normalising the repaired tree would hide the difference:\n${lines.join("\n")}`);
|
|
53
|
+
}
|
|
54
|
+
return fragment;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The tree builder's repairs, which it makes without reporting an error, found from the source
|
|
58
|
+
* locations of the tree's nodes:
|
|
59
|
+
* - `dropped`: source no node came from (a stray `</p>`, a table part outside a table, a
|
|
60
|
+
* document's `<html>`/`<head>`/`<body>`, a nested `<form>`);
|
|
61
|
+
* - `moved`: a node out of source order (text foster-parented out of a `<table>`);
|
|
62
|
+
* - `inserted`: an element with no tag in the source (a formatting element reopened after
|
|
63
|
+
* misnested tags, a `<tr>` around cells), apart from `IMPLIED_ELEMENTS`.
|
|
64
|
+
*/
|
|
65
|
+
function treeRepairs(source, fragment) {
|
|
66
|
+
const problems = [];
|
|
67
|
+
const covered = new Uint8Array(source.length);
|
|
68
|
+
const quoted = (location) => excerpt(source.slice(location.startOffset, location.endOffset));
|
|
69
|
+
let furthest;
|
|
70
|
+
const locate = (location) => {
|
|
71
|
+
if (!location) return;
|
|
72
|
+
covered.fill(1, location.startOffset, location.endOffset);
|
|
73
|
+
if (furthest && location.startOffset < furthest.startOffset) problems.push({
|
|
74
|
+
offset: furthest.startOffset,
|
|
75
|
+
message: `moved ${quoted(furthest)} before ${quoted(location)}`
|
|
76
|
+
});
|
|
77
|
+
else furthest = location;
|
|
78
|
+
};
|
|
79
|
+
const visit = (parent) => {
|
|
80
|
+
for (const node of childrenOf(parent)) if (!isElement(node)) locate(node.sourceCodeLocation);
|
|
81
|
+
else if (node.sourceCodeLocation) {
|
|
82
|
+
locate(node.sourceCodeLocation.startTag);
|
|
83
|
+
visit(node);
|
|
84
|
+
locate(node.sourceCodeLocation.endTag);
|
|
85
|
+
} else {
|
|
86
|
+
if (!IMPLIED_ELEMENTS.has(node.tagName)) problems.push({
|
|
87
|
+
offset: furthest?.endOffset ?? 0,
|
|
88
|
+
message: `inserted <${node.tagName}>`
|
|
89
|
+
});
|
|
90
|
+
visit(node);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
visit(fragment);
|
|
94
|
+
let start = -1;
|
|
95
|
+
for (let index = 0; index <= source.length; index++) if (index < source.length && covered[index] === 0) {
|
|
96
|
+
if (start < 0) start = index;
|
|
97
|
+
} else if (start >= 0) {
|
|
98
|
+
const text = source.slice(start, index);
|
|
99
|
+
if (text.trim() !== "") problems.push({
|
|
100
|
+
offset: start,
|
|
101
|
+
message: `dropped ${excerpt(text)}`
|
|
102
|
+
});
|
|
103
|
+
start = -1;
|
|
104
|
+
}
|
|
105
|
+
return problems;
|
|
106
|
+
}
|
|
107
|
+
/** `line:column` (1-based) of an offset, for error messages. */
|
|
108
|
+
function position(source, offset) {
|
|
109
|
+
const before = source.slice(0, offset);
|
|
110
|
+
return `${before.split("\n").length}:${offset - before.lastIndexOf("\n")}`;
|
|
111
|
+
}
|
|
112
|
+
function isElement(node) {
|
|
113
|
+
return "tagName" in node;
|
|
114
|
+
}
|
|
115
|
+
function isText(node) {
|
|
116
|
+
return node.nodeName === "#text";
|
|
117
|
+
}
|
|
118
|
+
/** The node that holds a node's children: a `<template>`'s content fragment, or the node. */
|
|
119
|
+
function holderOf(node) {
|
|
120
|
+
return "content" in node && node.namespaceURI === HTML_NAMESPACE ? node.content : node;
|
|
121
|
+
}
|
|
122
|
+
/** The children of a node; a `<template>`'s are those of its content fragment. */
|
|
123
|
+
function childrenOf(node) {
|
|
124
|
+
return holderOf(node).childNodes;
|
|
125
|
+
}
|
|
126
|
+
/** Replaces a node's children (a `<template>`'s content) with `children`, in place. */
|
|
127
|
+
function replaceChildren(node, children) {
|
|
128
|
+
const holder = holderOf(node);
|
|
129
|
+
holder.childNodes.length = 0;
|
|
130
|
+
for (const child of children) {
|
|
131
|
+
child.parentNode = holder;
|
|
132
|
+
holder.childNodes.push(child);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** Calls `visit` for every element under `root`, parents before children, in document order. */
|
|
136
|
+
function forEachElement(root, visit) {
|
|
137
|
+
for (const node of childrenOf(root)) if (isElement(node)) {
|
|
138
|
+
visit(node);
|
|
139
|
+
forEachElement(node, visit);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** The attribute's name as written: `xlink:href` keeps its prefix. */
|
|
143
|
+
function attributeName(attribute) {
|
|
144
|
+
return attribute.prefix ? `${attribute.prefix}:${attribute.name}` : attribute.name;
|
|
145
|
+
}
|
|
146
|
+
/** An attribute's value, or `undefined` when the element does not have it. */
|
|
147
|
+
function getAttribute(element, name) {
|
|
148
|
+
return element.attrs.find((attribute) => attributeName(attribute) === name)?.value;
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
export { HTML_NAMESPACE, MATHML_NAMESPACE, SVG_NAMESPACE, attributeName, childrenOf, forEachElement, getAttribute, isElement, isText, parseHtml, replaceChildren };
|
package/dist/setup.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./commands.js";
|