@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,309 @@
|
|
|
1
|
+
import { styleValue } from "./style.js";
|
|
2
|
+
import { HTML_NAMESPACE, MATHML_NAMESPACE, SVG_NAMESPACE, getAttribute } from "./tree.js";
|
|
3
|
+
//#region src/normalize/display.ts
|
|
4
|
+
/**
|
|
5
|
+
* The live DOM path's side table. It normalises a tree parsed again from serialised HTML
|
|
6
|
+
* (`normalizeDomWithIds`), which carries no computed style, so the walk that checks the parsed
|
|
7
|
+
* tree against the live one records each live element's values under its parsed element. An
|
|
8
|
+
* element without an entry, on the server path (L6) or in a `<template>`'s inert content, keeps
|
|
9
|
+
* the static reading.
|
|
10
|
+
*/
|
|
11
|
+
const computedLayouts = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
/** Records the computed values of the live element a parsed element was rebuilt from. */
|
|
13
|
+
function recordComputedLayout(element, layout) {
|
|
14
|
+
computedLayouts.set(element, layout);
|
|
15
|
+
}
|
|
16
|
+
const words = (list) => new Set(list.split(" "));
|
|
17
|
+
/** HTML elements with a block-level display (block, table parts) by default. */
|
|
18
|
+
const BLOCK_TAGS = words("address article aside blockquote body caption center col colgroup dd details dialog dir div dl dt fieldset figcaption figure footer form frame frameset h1 h2 h3 h4 h5 h6 header hgroup hr html legend listing main menu nav ol optgroup option p plaintext pre search section summary table tbody td tfoot th thead tr ul xmp");
|
|
19
|
+
/** HTML elements whose default display is a table, a table row or section, or a column. */
|
|
20
|
+
const TABLE_TAGS = words("col colgroup table tbody tfoot thead tr");
|
|
21
|
+
/** HTML elements whose default display is table-internal (see `Box.tableInternal`). */
|
|
22
|
+
const TABLE_INTERNAL_TAGS = words("caption col colgroup tbody td tfoot th thead tr");
|
|
23
|
+
/** HTML elements that are replaced or inline-block by default. */
|
|
24
|
+
const ATOMIC_TAGS = words("audio button canvas embed iframe img input marquee meter object progress select textarea video");
|
|
25
|
+
/** HTML elements with `display: none` by default. */
|
|
26
|
+
const NONE_TAGS = words("area base basefont datalist head link meta noembed noframes param rp script style template title");
|
|
27
|
+
/**
|
|
28
|
+
* HTML elements whose content keeps its whitespace: `white-space: pre` (`pre-wrap` for
|
|
29
|
+
* `<textarea>`) in the user-agent stylesheet, and raw-text elements, whose text is code or is
|
|
30
|
+
* not rendered as flowing text.
|
|
31
|
+
*/
|
|
32
|
+
const PRESERVING_TAGS = words("iframe listing noembed noframes noscript plaintext pre script style textarea title xmp");
|
|
33
|
+
/** The preserving elements whose text is raw text or a `<textarea>`'s value. */
|
|
34
|
+
const KEPT_TEXT_TAGS = words("iframe noembed noframes noscript plaintext script style textarea title xmp");
|
|
35
|
+
/** `white-space` and `white-space-collapse` keywords that keep spaces or line breaks. */
|
|
36
|
+
const PRESERVING_KEYWORDS = words("pre pre-wrap pre-line break-spaces preserve preserve-breaks preserve-spaces");
|
|
37
|
+
const COLLAPSING_KEYWORDS = words("normal nowrap collapse");
|
|
38
|
+
/** SVG elements whose text flows inline inside a `<text>`; other SVG elements act as blocks. */
|
|
39
|
+
const SVG_INLINE_TAGS = words("a tspan textPath");
|
|
40
|
+
/** SVG elements whose text is code, kept exactly as it is, like HTML's raw-text elements. */
|
|
41
|
+
const SVG_PRESERVING_TAGS = words("script style");
|
|
42
|
+
/** `float` values that take a box out of flow. */
|
|
43
|
+
const FLOATING_KEYWORDS = words("left right inline-start inline-end");
|
|
44
|
+
/** `position` values that take a box out of flow. */
|
|
45
|
+
const OUT_OF_FLOW_POSITIONS = words("absolute fixed");
|
|
46
|
+
/** `unicode-bidi` values that wrap an element's content in bidi controls. */
|
|
47
|
+
const BIDI_KEYWORDS = words("embed isolate bidi-override isolate-override plaintext");
|
|
48
|
+
/** HTML elements whose `unicode-bidi` is not `normal` by default. */
|
|
49
|
+
const BIDI_TAGS = words("bdi bdo li output");
|
|
50
|
+
/** The `dir` values that make an HTML element `unicode-bidi: isolate` by default. */
|
|
51
|
+
const DIRECTIONS = words("ltr rtl auto");
|
|
52
|
+
/**
|
|
53
|
+
* A box; by default its children are neither blockified nor dropped, ruby nor a list item, and
|
|
54
|
+
* it is not table-internal.
|
|
55
|
+
*/
|
|
56
|
+
function box(outer, traits = {}) {
|
|
57
|
+
const blockifiesChildren = traits.blockifiesChildren ?? false;
|
|
58
|
+
return {
|
|
59
|
+
outer,
|
|
60
|
+
blockifiesChildren,
|
|
61
|
+
dropsWhitespaceChildren: traits.dropsWhitespaceChildren ?? blockifiesChildren,
|
|
62
|
+
rubyContent: traits.rubyContent ?? false,
|
|
63
|
+
rubyAnnotation: traits.rubyAnnotation ?? false,
|
|
64
|
+
listItem: traits.listItem ?? false,
|
|
65
|
+
tableInternal: traits.tableInternal ?? false,
|
|
66
|
+
opaqueStart: false,
|
|
67
|
+
opaqueEnd: false
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** Whether a node is the HTML element `<tag>`. */
|
|
71
|
+
function isHtmlElement(node, tag) {
|
|
72
|
+
return node !== null && "tagName" in node && node.namespaceURI === HTML_NAMESPACE && node.tagName === tag;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Display a user-agent rule sets with `!important`, which no inline style overrides: hidden
|
|
76
|
+
* inputs, and `<noscript>` (the parser and the browser both run with scripting enabled).
|
|
77
|
+
*/
|
|
78
|
+
function forcedBox(element) {
|
|
79
|
+
if (element.namespaceURI !== HTML_NAMESPACE) return void 0;
|
|
80
|
+
if (element.tagName === "noscript") return box("none");
|
|
81
|
+
if (element.tagName === "input" && getAttribute(element, "type")?.toLowerCase() === "hidden") return box("none");
|
|
82
|
+
}
|
|
83
|
+
/** The user-agent stylesheet's display for an element, per the HTML rendering section. */
|
|
84
|
+
function defaultBox(element) {
|
|
85
|
+
const tag = element.tagName;
|
|
86
|
+
if (element.namespaceURI === SVG_NAMESPACE) {
|
|
87
|
+
if (tag === "svg") return box("atomic");
|
|
88
|
+
if (tag === "style" || tag === "script") return box("none");
|
|
89
|
+
return box(SVG_INLINE_TAGS.has(tag) ? "inline" : "block");
|
|
90
|
+
}
|
|
91
|
+
if (element.namespaceURI === MATHML_NAMESPACE) {
|
|
92
|
+
if (tag !== "math") return box("block");
|
|
93
|
+
return box(getAttribute(element, "display")?.toLowerCase() === "block" ? "block" : "atomic");
|
|
94
|
+
}
|
|
95
|
+
const hidden = getAttribute(element, "hidden");
|
|
96
|
+
if (hidden !== void 0 && hidden.toLowerCase() !== "until-found" && tag !== "embed") return box("none");
|
|
97
|
+
if (tag === "dialog" && getAttribute(element, "open") === void 0) return box("none");
|
|
98
|
+
if (tag === "audio" && getAttribute(element, "controls") === void 0) return box("none");
|
|
99
|
+
if (tag === "br") return box("break");
|
|
100
|
+
if (tag === "slot") return box("contents");
|
|
101
|
+
if (tag === "ruby") return box("inline", { rubyContent: true });
|
|
102
|
+
if (tag === "rt" && isHtmlElement(element.parentNode, "ruby")) return box("inline", {
|
|
103
|
+
rubyContent: true,
|
|
104
|
+
rubyAnnotation: true
|
|
105
|
+
});
|
|
106
|
+
if (tag === "li") return box("block", { listItem: true });
|
|
107
|
+
if (NONE_TAGS.has(tag)) return box("none");
|
|
108
|
+
const tableInternal = TABLE_INTERNAL_TAGS.has(tag);
|
|
109
|
+
if (TABLE_TAGS.has(tag)) return box("block", {
|
|
110
|
+
dropsWhitespaceChildren: true,
|
|
111
|
+
tableInternal
|
|
112
|
+
});
|
|
113
|
+
if (BLOCK_TAGS.has(tag)) return box("block", { tableInternal });
|
|
114
|
+
if (ATOMIC_TAGS.has(tag)) return box("atomic");
|
|
115
|
+
return box("inline");
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Reads a `display` value, single keyword or multi-keyword (`inline flow-root`). Returns
|
|
119
|
+
* `undefined` for a value that defers to the user-agent default (`revert`, `inherit`, which
|
|
120
|
+
* needs the parent's computed value) or that Chromium rejects (`run-in`, `ruby-base`).
|
|
121
|
+
* `math` is a MathML layout: on any other element it computes to `flow`.
|
|
122
|
+
*/
|
|
123
|
+
function boxFromDisplay(value, mathml = false) {
|
|
124
|
+
const keywords = value.trim().split(/\s+/);
|
|
125
|
+
if (keywords.length === 1) switch (keywords[0]) {
|
|
126
|
+
case "none": return box("none");
|
|
127
|
+
case "contents": return box("contents");
|
|
128
|
+
case "inline":
|
|
129
|
+
case "initial":
|
|
130
|
+
case "unset": return box("inline");
|
|
131
|
+
case "ruby": return box("inline", { rubyContent: true });
|
|
132
|
+
case "ruby-text": return box("inline", {
|
|
133
|
+
rubyContent: true,
|
|
134
|
+
rubyAnnotation: true
|
|
135
|
+
});
|
|
136
|
+
case "math": return box(mathml ? "atomic" : "inline");
|
|
137
|
+
case "inline-block": return box("atomic");
|
|
138
|
+
case "inline-table": return box("atomic", { dropsWhitespaceChildren: true });
|
|
139
|
+
case "inline-flex":
|
|
140
|
+
case "inline-grid": return box("atomic", { blockifiesChildren: true });
|
|
141
|
+
case "table": return box("block", { dropsWhitespaceChildren: true });
|
|
142
|
+
case "table-row-group":
|
|
143
|
+
case "table-header-group":
|
|
144
|
+
case "table-footer-group":
|
|
145
|
+
case "table-row":
|
|
146
|
+
case "table-column-group":
|
|
147
|
+
case "table-column": return box("block", {
|
|
148
|
+
dropsWhitespaceChildren: true,
|
|
149
|
+
tableInternal: true
|
|
150
|
+
});
|
|
151
|
+
case "table-cell":
|
|
152
|
+
case "table-caption": return box("block", { tableInternal: true });
|
|
153
|
+
case "block":
|
|
154
|
+
case "flow":
|
|
155
|
+
case "flow-root": return box("block");
|
|
156
|
+
case "list-item": return box("block", { listItem: true });
|
|
157
|
+
case "flex":
|
|
158
|
+
case "grid": return box("block", { blockifiesChildren: true });
|
|
159
|
+
default: return;
|
|
160
|
+
}
|
|
161
|
+
const has = (keyword) => keywords.includes(keyword);
|
|
162
|
+
if (has("run-in")) return void 0;
|
|
163
|
+
const inner = keywords.find((keyword) => [
|
|
164
|
+
"flow",
|
|
165
|
+
"flow-root",
|
|
166
|
+
"table",
|
|
167
|
+
"flex",
|
|
168
|
+
"grid",
|
|
169
|
+
"ruby",
|
|
170
|
+
"math"
|
|
171
|
+
].includes(keyword));
|
|
172
|
+
const traits = {
|
|
173
|
+
blockifiesChildren: inner === "flex" || inner === "grid",
|
|
174
|
+
dropsWhitespaceChildren: inner === "flex" || inner === "grid" || inner === "table",
|
|
175
|
+
rubyContent: inner === "ruby",
|
|
176
|
+
listItem: has("list-item")
|
|
177
|
+
};
|
|
178
|
+
const flows = inner === void 0 || inner === "flow" || inner === "math" && !mathml;
|
|
179
|
+
if (has("inline")) return box(flows || inner === "ruby" ? "inline" : "atomic", traits);
|
|
180
|
+
if (has("block") || has("list-item")) return box("block", traits);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The element's box: its `display` if it has a valid one, else the user-agent default, as its
|
|
184
|
+
* parent lays it out:
|
|
185
|
+
*
|
|
186
|
+
* - A float or an absolutely positioned box (its `float`, `position`) is out of flow, apart
|
|
187
|
+
* from `none` and `contents`, which have no box to take out.
|
|
188
|
+
* - Inside a flex or grid container every other child is blockified.
|
|
189
|
+
* - Blockified (out of flow, or in a flex or grid container), a table-internal box is a plain
|
|
190
|
+
* block container: no anonymous table wraps it, and its children are laid out as a block's.
|
|
191
|
+
* - Inside a ruby, Chromium inlinifies: a block-level box becomes an inline-block (atomic),
|
|
192
|
+
* or an inline box if it is a list item or a ruby (`block ruby` becomes `inline ruby`); a
|
|
193
|
+
* float loses its float and is inlinified the same way; a `<br>` is content that does not break the line (`ruby-break`). An absolutely
|
|
194
|
+
* positioned box stays out of flow.
|
|
195
|
+
*
|
|
196
|
+
* The live DOM path reads `display`, `float`, `position` and `unicode-bidi` from Chromium's
|
|
197
|
+
* computed styles (`recordComputedLayout`), so a stylesheet that changes them counts, as it
|
|
198
|
+
* does `white-space` (see `preservesWhitespace`). The
|
|
199
|
+
* server path, L6, has no computed styles: it reads the inline style and the user-agent
|
|
200
|
+
* defaults, and a class whose stylesheet changes the layout is invisible there.
|
|
201
|
+
*/
|
|
202
|
+
function boxOf(element, parent) {
|
|
203
|
+
const placed = placedBox(element, parent);
|
|
204
|
+
const bidi = isolatesBidi(element);
|
|
205
|
+
return {
|
|
206
|
+
...placed,
|
|
207
|
+
opaqueStart: placed.rubyContent && !(placed.rubyAnnotation && parent.rubyContainer) || bidi,
|
|
208
|
+
opaqueEnd: placed.rubyContent || bidi
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/** The box an inline `display` gives, or the user-agent default. */
|
|
212
|
+
function declaredBox(element, display) {
|
|
213
|
+
return (display !== void 0 ? boxFromDisplay(display, element.namespaceURI === MATHML_NAMESPACE) : void 0) ?? defaultBox(element);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The box Chromium's computed `display` gives. Some elements compute a `display` that their
|
|
217
|
+
* layout ignores, so they keep their user-agent box:
|
|
218
|
+
*
|
|
219
|
+
* - A replaced element (`<img>`, `<video>`, `<svg>`) computes `inline` but is atomic, and `<br>`
|
|
220
|
+
* computes `inline` but is a break.
|
|
221
|
+
* - `<wbr>` lays out as text, an empty one, which a flex or grid container does not blockify,
|
|
222
|
+
* though its computed `display` is blockified.
|
|
223
|
+
* - An element inside `<svg>` is laid out by SVG.
|
|
224
|
+
*
|
|
225
|
+
* The last two read only `display: none`.
|
|
226
|
+
*/
|
|
227
|
+
function computedBox(element, display) {
|
|
228
|
+
const fallback = defaultBox(element);
|
|
229
|
+
if (isHtmlElement(element, "wbr") || element.namespaceURI === SVG_NAMESPACE && element.tagName !== "svg") return display === "none" ? box("none") : fallback;
|
|
230
|
+
if (display === "inline" && (fallback.outer === "atomic" || fallback.outer === "break")) return fallback;
|
|
231
|
+
return boxFromDisplay(display, element.namespaceURI === MATHML_NAMESPACE) ?? fallback;
|
|
232
|
+
}
|
|
233
|
+
/** The element's box, laid out by its parent (see `boxOf`), its edges aside. */
|
|
234
|
+
function placedBox(element, parent) {
|
|
235
|
+
const forced = forcedBox(element);
|
|
236
|
+
if (forced) return forced;
|
|
237
|
+
const computed = computedLayouts.get(element);
|
|
238
|
+
const style = getAttribute(element, "style");
|
|
239
|
+
const declared = computed ? computedBox(element, computed.display) : declaredBox(element, styleValue(style, "display"));
|
|
240
|
+
if (declared.outer === "none" || declared.outer === "contents") return declared;
|
|
241
|
+
const position = computed ? computed.position : styleValue(style, "position");
|
|
242
|
+
const float = computed ? computed.float : styleValue(style, "float");
|
|
243
|
+
const floats = float !== void 0 && FLOATING_KEYWORDS.has(float);
|
|
244
|
+
const positioned = position !== void 0 && OUT_OF_FLOW_POSITIONS.has(position);
|
|
245
|
+
const own = declared.tableInternal && (floats || positioned || parent.blockifies) ? box("block") : declared;
|
|
246
|
+
if (positioned) return {
|
|
247
|
+
...own,
|
|
248
|
+
outer: "out-of-flow"
|
|
249
|
+
};
|
|
250
|
+
if (parent.ruby) {
|
|
251
|
+
if (floats || own.outer === "block") return {
|
|
252
|
+
...own,
|
|
253
|
+
outer: own.listItem || own.rubyContent ? "inline" : "atomic"
|
|
254
|
+
};
|
|
255
|
+
return own.outer === "break" ? {
|
|
256
|
+
...own,
|
|
257
|
+
outer: "ruby-break"
|
|
258
|
+
} : own;
|
|
259
|
+
}
|
|
260
|
+
if (floats) return {
|
|
261
|
+
...own,
|
|
262
|
+
outer: "out-of-flow"
|
|
263
|
+
};
|
|
264
|
+
if (parent.blockifies && (own.outer === "inline" || own.outer === "atomic" || own.outer === "break")) return {
|
|
265
|
+
...own,
|
|
266
|
+
outer: "block"
|
|
267
|
+
};
|
|
268
|
+
return own;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Whether the element's `unicode-bidi` is not `normal`: its computed value on the live DOM path,
|
|
272
|
+
* else its inline style, else the user-agent default, which isolates `<bdi>`, `<bdo>`,
|
|
273
|
+
* `<output>`, `<li>` and every HTML element with a valid `dir` (`inherit` and `revert` defer to
|
|
274
|
+
* the default, as Chromium computes them).
|
|
275
|
+
*/
|
|
276
|
+
function isolatesBidi(element) {
|
|
277
|
+
const computed = computedLayouts.get(element);
|
|
278
|
+
if (computed) return BIDI_KEYWORDS.has(computed.unicodeBidi);
|
|
279
|
+
const value = styleValue(getAttribute(element, "style"), "unicode-bidi");
|
|
280
|
+
if (value === "normal" || value === "initial" || value === "unset") return false;
|
|
281
|
+
if (value !== void 0 && BIDI_KEYWORDS.has(value)) return true;
|
|
282
|
+
if (element.namespaceURI !== HTML_NAMESPACE) return false;
|
|
283
|
+
const dir = getAttribute(element, "dir")?.toLowerCase();
|
|
284
|
+
return BIDI_TAGS.has(element.tagName) || dir !== void 0 && DIRECTIONS.has(dir);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Whether the element's text keeps its whitespace. Inherited, and overridden by an inline
|
|
288
|
+
* `white-space` or `white-space-collapse`. `pre-line` (`preserve-breaks`) counts as
|
|
289
|
+
* preserving: keeping more whitespace than the browser renders never hides a difference.
|
|
290
|
+
*
|
|
291
|
+
* On the live DOM path, Chromium's computed `white-space-collapse` decides, inheritance and
|
|
292
|
+
* stylesheets included, with two exceptions. Raw text and a `<textarea>`'s value always keep
|
|
293
|
+
* their whitespace: they are not laid out as flowing text. A `<select>` keeps the static
|
|
294
|
+
* reading: Chromium never renders its own text, whatever its user-agent `white-space: pre` says.
|
|
295
|
+
*/
|
|
296
|
+
function preservesWhitespace(element, inherited) {
|
|
297
|
+
const computed = computedLayouts.get(element);
|
|
298
|
+
if (computed && !isHtmlElement(element, "select")) return PRESERVING_KEYWORDS.has(computed.whiteSpaceCollapse) || keepsText(element);
|
|
299
|
+
const keywords = styleValue(getAttribute(element, "style"), "white-space", "white-space-collapse")?.split(/\s+/) ?? [];
|
|
300
|
+
if (keywords.some((keyword) => PRESERVING_KEYWORDS.has(keyword))) return true;
|
|
301
|
+
if (keywords.some((keyword) => COLLAPSING_KEYWORDS.has(keyword))) return false;
|
|
302
|
+
return inherited || keepsText(element) || element.namespaceURI === HTML_NAMESPACE && PRESERVING_TAGS.has(element.tagName);
|
|
303
|
+
}
|
|
304
|
+
/** Whether the element's text is raw text or a value, which is never laid out as flowing text. */
|
|
305
|
+
function keepsText(element) {
|
|
306
|
+
return element.namespaceURI === HTML_NAMESPACE && KEPT_TEXT_TAGS.has(element.tagName) || element.namespaceURI === SVG_NAMESPACE && SVG_PRESERVING_TAGS.has(element.tagName);
|
|
307
|
+
}
|
|
308
|
+
//#endregion
|
|
309
|
+
export { boxFromDisplay, boxOf, preservesWhitespace, recordComputedLayout };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { NORMALIZE_TARGETS, NormalizeTarget, isNormalizeTarget } from "./targets.js";
|
|
2
|
+
import { NormalizeOptions } from "./pipeline.js";
|
|
3
|
+
//#region src/normalize/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Normalises an HTML fragment (a component's server HTML, or `serializeDom` of a mount
|
|
6
|
+
* container) into the canonical text of `print.ts`: one node per line, attributes sorted,
|
|
7
|
+
* text quoted.
|
|
8
|
+
*
|
|
9
|
+
* The HTML is parsed as `innerHTML` of an element in `<body>`, and markup the parser would
|
|
10
|
+
* have to repair (a duplicate attribute, a stray end tag, a table part outside a table, a
|
|
11
|
+
* document shell) throws, because normalising the repaired tree would hide it. The rules run
|
|
12
|
+
* in the order their numbers give:
|
|
13
|
+
*
|
|
14
|
+
* 1. comments are removed (`removeComments`);
|
|
15
|
+
* 2. attributes the target's framework adds are removed (`removeFrameworkAttributes`), and so
|
|
16
|
+
* are Qwik's `q:template` elements (2b, `removeQwikTemplates`) and its `<style q:style>`
|
|
17
|
+
* elements (2c, `removeQwikStyles`, which runs first: it finds them by that attribute);
|
|
18
|
+
* 3. Angular's `uf-*` host elements with `display: contents` are unwrapped
|
|
19
|
+
* (`unwrapAngularHosts`), and with an `engine`, the properties that engine serialises under
|
|
20
|
+
* its own alias take Chromium's name (3b, `renameEngineAliases`: Firefox's
|
|
21
|
+
* `-moz-box-orient`, ADR-0081);
|
|
22
|
+
* 4. style declarations (4a, `canonicalizeStyles`), boolean attributes (4b,
|
|
23
|
+
* `canonicalizeBooleanAttributes`) and class tokens (4c, `canonicalizeClasses`) get one
|
|
24
|
+
* canonical form, and a `class` or `style` that holds nothing goes; the markup of a control's
|
|
25
|
+
* initial state that its `uf:*` state repeats goes too (4d, `removeSettledValues`), and on
|
|
26
|
+
* React a `checked` or `selected` beside its `uf:*` state (4e, `removeReactDefaultStates`);
|
|
27
|
+
* 5. attributes are sorted by name (`sortAttributes`), before ids are numbered, so the
|
|
28
|
+
* numbering never depends on a framework's attribute order;
|
|
29
|
+
* 6. whitespace collapses as the browser renders it (`collapseWhitespace`);
|
|
30
|
+
* 7. generated ids become `uf-id-1`, `uf-id-2`… (`canonicalizeGeneratedIds`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function normalizeHtml(html: string, options?: NormalizeOptions): string;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { NORMALIZE_TARGETS, type NormalizeOptions, type NormalizeTarget, isNormalizeTarget };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { parseHtml } from "./tree.js";
|
|
2
|
+
import { NORMALIZE_TARGETS, isNormalizeTarget } from "./targets.js";
|
|
3
|
+
import { checkOptions, normalizeTree } from "./pipeline.js";
|
|
4
|
+
//#region src/normalize/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* Normalises an HTML fragment (a component's server HTML, or `serializeDom` of a mount
|
|
7
|
+
* container) into the canonical text of `print.ts`: one node per line, attributes sorted,
|
|
8
|
+
* text quoted.
|
|
9
|
+
*
|
|
10
|
+
* The HTML is parsed as `innerHTML` of an element in `<body>`, and markup the parser would
|
|
11
|
+
* have to repair (a duplicate attribute, a stray end tag, a table part outside a table, a
|
|
12
|
+
* document shell) throws, because normalising the repaired tree would hide it. The rules run
|
|
13
|
+
* in the order their numbers give:
|
|
14
|
+
*
|
|
15
|
+
* 1. comments are removed (`removeComments`);
|
|
16
|
+
* 2. attributes the target's framework adds are removed (`removeFrameworkAttributes`), and so
|
|
17
|
+
* are Qwik's `q:template` elements (2b, `removeQwikTemplates`) and its `<style q:style>`
|
|
18
|
+
* elements (2c, `removeQwikStyles`, which runs first: it finds them by that attribute);
|
|
19
|
+
* 3. Angular's `uf-*` host elements with `display: contents` are unwrapped
|
|
20
|
+
* (`unwrapAngularHosts`), and with an `engine`, the properties that engine serialises under
|
|
21
|
+
* its own alias take Chromium's name (3b, `renameEngineAliases`: Firefox's
|
|
22
|
+
* `-moz-box-orient`, ADR-0081);
|
|
23
|
+
* 4. style declarations (4a, `canonicalizeStyles`), boolean attributes (4b,
|
|
24
|
+
* `canonicalizeBooleanAttributes`) and class tokens (4c, `canonicalizeClasses`) get one
|
|
25
|
+
* canonical form, and a `class` or `style` that holds nothing goes; the markup of a control's
|
|
26
|
+
* initial state that its `uf:*` state repeats goes too (4d, `removeSettledValues`), and on
|
|
27
|
+
* React a `checked` or `selected` beside its `uf:*` state (4e, `removeReactDefaultStates`);
|
|
28
|
+
* 5. attributes are sorted by name (`sortAttributes`), before ids are numbered, so the
|
|
29
|
+
* numbering never depends on a framework's attribute order;
|
|
30
|
+
* 6. whitespace collapses as the browser renders it (`collapseWhitespace`);
|
|
31
|
+
* 7. generated ids become `uf-id-1`, `uf-id-2`… (`canonicalizeGeneratedIds`).
|
|
32
|
+
*/
|
|
33
|
+
function normalizeHtml(html, options = {}) {
|
|
34
|
+
checkOptions(options);
|
|
35
|
+
return normalizeTree(parseHtml(html), options);
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { NORMALIZE_TARGETS, isNormalizeTarget, normalizeHtml };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BrowserEngine } from "../harness.js";
|
|
2
|
+
import { NormalizeTarget } from "./targets.js";
|
|
3
|
+
import "./tree.js";
|
|
4
|
+
//#region src/normalize/pipeline.d.ts
|
|
5
|
+
export interface NormalizeOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The target that rendered the HTML. Its framework's noise (attributes it adds on its own,
|
|
8
|
+
* Angular's component hosts) is removed, and no other framework's: without a target nothing
|
|
9
|
+
* is noise, so the reference's output is never rewritten by another framework's rules.
|
|
10
|
+
*/
|
|
11
|
+
target?: NormalizeTarget;
|
|
12
|
+
/**
|
|
13
|
+
* The engine the live DOM was read in (`UF_BROWSER`, ADR-0081). The properties it serialises
|
|
14
|
+
* under its own alias take the name Chromium writes, and nothing else changes. Without an
|
|
15
|
+
* engine, or in Chromium, no property is renamed.
|
|
16
|
+
*/
|
|
17
|
+
engine?: BrowserEngine;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BROWSER_ENGINES } from "../harness.js";
|
|
2
|
+
import { printTree } from "./print.js";
|
|
3
|
+
import { removeFrameworkAttributes } from "./rules/framework-attributes.js";
|
|
4
|
+
import { unwrapAngularHosts } from "./rules/angular-hosts.js";
|
|
5
|
+
import { removeComments } from "./rules/comments.js";
|
|
6
|
+
import { removeReactDefaultStates, removeSettledValues } from "./rules/control-values.js";
|
|
7
|
+
import { renameEngineAliases } from "./rules/engine-aliases.js";
|
|
8
|
+
import { canonicalizeGeneratedIds } from "./rules/generated-ids.js";
|
|
9
|
+
import { canonicalizeClasses, sortAttributes } from "./rules/ordering.js";
|
|
10
|
+
import { removeQwikStyles } from "./rules/qwik-styles.js";
|
|
11
|
+
import { removeQwikTemplates } from "./rules/qwik-templates.js";
|
|
12
|
+
import { canonicalizeBooleanAttributes, canonicalizeStyles } from "./rules/values.js";
|
|
13
|
+
import { collapseWhitespace } from "./rules/whitespace.js";
|
|
14
|
+
import { isNormalizeTarget } from "./targets.js";
|
|
15
|
+
//#region src/normalize/pipeline.ts
|
|
16
|
+
/** Refuses a target the normaliser does not know, from an untyped caller. */
|
|
17
|
+
function checkOptions(options) {
|
|
18
|
+
if (options.target !== void 0 && !isNormalizeTarget(options.target)) throw new TypeError(`normalizeHtml: unknown target ${JSON.stringify(options.target)}`);
|
|
19
|
+
if (options.engine !== void 0 && !BROWSER_ENGINES.includes(options.engine)) throw new TypeError(`normalizeHtml: unknown engine ${JSON.stringify(options.engine)}`);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Runs the rules over a parsed fragment, in place, and prints it (see `normalizeHtml`). `ids`,
|
|
23
|
+
* when given, receives the generated ids' renaming (see `canonicalizeGeneratedIds`).
|
|
24
|
+
*/
|
|
25
|
+
function normalizeTree(root, options, ids) {
|
|
26
|
+
checkOptions(options);
|
|
27
|
+
const { target, engine } = options;
|
|
28
|
+
removeComments(root);
|
|
29
|
+
removeQwikStyles(root, target);
|
|
30
|
+
removeFrameworkAttributes(root, target);
|
|
31
|
+
removeQwikTemplates(root, target);
|
|
32
|
+
unwrapAngularHosts(root, target);
|
|
33
|
+
renameEngineAliases(root, engine);
|
|
34
|
+
canonicalizeStyles(root);
|
|
35
|
+
canonicalizeBooleanAttributes(root, target);
|
|
36
|
+
canonicalizeClasses(root);
|
|
37
|
+
removeSettledValues(root);
|
|
38
|
+
removeReactDefaultStates(root, target);
|
|
39
|
+
sortAttributes(root);
|
|
40
|
+
collapseWhitespace(root);
|
|
41
|
+
canonicalizeGeneratedIds(root, ids);
|
|
42
|
+
return printTree(root);
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { checkOptions, normalizeTree };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { HTML_NAMESPACE, attributeName, childrenOf, isElement, isText } from "./tree.js";
|
|
2
|
+
//#region src/normalize/print.ts
|
|
3
|
+
/**
|
|
4
|
+
* Elements that never have children or an end tag, including the obsolete ones the HTML parser
|
|
5
|
+
* still treats as void.
|
|
6
|
+
*/
|
|
7
|
+
const VOID_ELEMENTS = new Set("area base basefont bgsound br col embed frame hr img input keygen link meta param source track wbr".split(" "));
|
|
8
|
+
const NAMED_ESCAPES = {
|
|
9
|
+
"\"": "\\\"",
|
|
10
|
+
"\\": "\\\\",
|
|
11
|
+
"\b": "\\b",
|
|
12
|
+
"\f": "\\f",
|
|
13
|
+
"\n": "\\n",
|
|
14
|
+
"\r": "\\r",
|
|
15
|
+
" ": "\\t"
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Characters a reader could not see or tell apart: quotes and backslashes, every control,
|
|
19
|
+
* format, private-use, unassigned and surrogate code point, every space other than U+0020
|
|
20
|
+
* (U+00A0 and the other Unicode spaces, and the line and paragraph separators), and the
|
|
21
|
+
* variation selectors, which change a glyph without a visible character of their own.
|
|
22
|
+
*/
|
|
23
|
+
const NEEDS_ESCAPE = /["\\\p{C}\p{Zl}\p{Zp}\p{Variation_Selector}\u{a0}\u{1680}\u{2000}-\u{200a}\u{202f}\u{205f}\u{3000}]/gu;
|
|
24
|
+
/** {@link NEEDS_ESCAPE} and every combining mark, for text that is not in NFC. */
|
|
25
|
+
const NEEDS_ESCAPE_DECOMPOSED = /["\\\p{C}\p{Zl}\p{Zp}\p{Variation_Selector}\p{M}\u{a0}\u{1680}\u{2000}-\u{200a}\u{202f}\u{205f}\u{3000}]/gu;
|
|
26
|
+
/**
|
|
27
|
+
* Writes a string as a JSON string literal in which every invisible or ambiguous character is
|
|
28
|
+
* escaped, so `JSON.parse` reads it back exactly. Code points above U+FFFF that need escaping
|
|
29
|
+
* are written as their two UTF-16 escapes, as JSON requires.
|
|
30
|
+
*
|
|
31
|
+
* Text that is not in Unicode Normalization Form C has its combining marks escaped as well, so
|
|
32
|
+
* a decomposed `é` (`e` and U+0301) never prints like the composed one; text in NFC keeps its
|
|
33
|
+
* marks as they are, so scripts that need them stay readable.
|
|
34
|
+
*/
|
|
35
|
+
function quote(text) {
|
|
36
|
+
return `"${text.replace(text.normalize("NFC") === text ? NEEDS_ESCAPE : NEEDS_ESCAPE_DECOMPOSED, (char) => NAMED_ESCAPES[char] ?? Array.from({ length: char.length }, (_, index) => `\\u${char.charCodeAt(index).toString(16).padStart(4, "0")}`).join(""))}"`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Prints a tree in the canonical text format of the reviewed expectation files (`ssr.*.html`,
|
|
40
|
+
* `dom.*.html`). It is deterministic, unambiguous and diff-friendly:
|
|
41
|
+
*
|
|
42
|
+
* - One node per line, indented by two spaces per level.
|
|
43
|
+
* - An element with children is its start tag on one line, its children one level deeper, and
|
|
44
|
+
* its end tag on its own line. An element without children is `<tag …></tag>` on one line; a
|
|
45
|
+
* void element is `<tag …>`.
|
|
46
|
+
* - Attributes are written `name="value"` in the tree's order (the normaliser sorts them).
|
|
47
|
+
* - Attribute values and text are JSON string literals with invisible characters escaped (see
|
|
48
|
+
* `quote`): `"Hello, world!"` is one text node, its spaces visible at both ends; `"a\u00a0b"`
|
|
49
|
+
* holds a no-break space. Entities are decoded, so `&` is `"&"` and `"<b>"` is text.
|
|
50
|
+
* - A text line holds all the text between two non-text siblings: adjacent text nodes print as
|
|
51
|
+
* one, because HTML cannot tell them apart. Only the whitespace rule leaves an empty text
|
|
52
|
+
* node, where Chromium's layout still sees one (beside a ruby), and it prints as `""`.
|
|
53
|
+
* - Comments are not printed (the normaliser drops them anyway).
|
|
54
|
+
* - A `<template>` prints its content as its children.
|
|
55
|
+
* - Every line ends with a line break; an empty tree prints the empty string.
|
|
56
|
+
*
|
|
57
|
+
* ```
|
|
58
|
+
* <p class="greeting">
|
|
59
|
+
* "Hello, "
|
|
60
|
+
* <b>
|
|
61
|
+
* "world"
|
|
62
|
+
* </b>
|
|
63
|
+
* "!"
|
|
64
|
+
* </p>
|
|
65
|
+
* <img alt="" src="/a.png">
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
function printTree(root) {
|
|
69
|
+
const lines = [];
|
|
70
|
+
printChildren(root, "", lines);
|
|
71
|
+
return lines.length === 0 ? "" : `${lines.join("\n")}\n`;
|
|
72
|
+
}
|
|
73
|
+
function printChildren(parent, indent, lines) {
|
|
74
|
+
let text;
|
|
75
|
+
const flush = () => {
|
|
76
|
+
if (text !== void 0) lines.push(indent + quote(text));
|
|
77
|
+
text = void 0;
|
|
78
|
+
};
|
|
79
|
+
for (const node of childrenOf(parent)) if (isText(node)) text = (text ?? "") + node.value;
|
|
80
|
+
else if (isElement(node)) {
|
|
81
|
+
flush();
|
|
82
|
+
printElement(node, indent, lines);
|
|
83
|
+
}
|
|
84
|
+
flush();
|
|
85
|
+
}
|
|
86
|
+
function printElement(element, indent, lines) {
|
|
87
|
+
const attributes = element.attrs.map((attribute) => ` ${attributeName(attribute)}=${quote(attribute.value)}`).join("");
|
|
88
|
+
const start = `${indent}<${element.tagName}${attributes}>`;
|
|
89
|
+
if (element.namespaceURI === HTML_NAMESPACE && VOID_ELEMENTS.has(element.tagName)) {
|
|
90
|
+
lines.push(start);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const end = `</${element.tagName}>`;
|
|
94
|
+
if (!childrenOf(element).some((node) => isElement(node) || isText(node))) {
|
|
95
|
+
lines.push(start + end);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
lines.push(start);
|
|
99
|
+
printChildren(element, `${indent} `, lines);
|
|
100
|
+
lines.push(indent + end);
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { printTree, quote };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { dedupeDeclarations, parseStyle } from "../style.js";
|
|
2
|
+
import { HTML_NAMESPACE, attributeName, childrenOf, isElement, replaceChildren } from "../tree.js";
|
|
3
|
+
import { isFrameworkAttribute } from "./framework-attributes.js";
|
|
4
|
+
//#region src/normalize/rules/angular-hosts.ts
|
|
5
|
+
/**
|
|
6
|
+
* Whether an element is the host of an Angular component under D6: an element selector
|
|
7
|
+
* `uf-<name>` whose only styling is `display: contents`, so it renders no box. A host that
|
|
8
|
+
* carries anything else (an authored or fallthrough attribute, another declaration) is not
|
|
9
|
+
* unwrapped, so the difference it makes stays visible.
|
|
10
|
+
*/
|
|
11
|
+
function isAngularHost(element) {
|
|
12
|
+
if (element.namespaceURI !== HTML_NAMESPACE || !element.tagName.startsWith("uf-")) return false;
|
|
13
|
+
let contents = false;
|
|
14
|
+
for (const attribute of element.attrs) {
|
|
15
|
+
const name = attributeName(attribute);
|
|
16
|
+
if (name === "style") {
|
|
17
|
+
const declarations = dedupeDeclarations(parseStyle(attribute.value));
|
|
18
|
+
contents = declarations.length === 1 && declarations[0].property === "display" && declarations[0].value?.toLowerCase() === "contents";
|
|
19
|
+
if (!contents) return false;
|
|
20
|
+
} else if (!isFrameworkAttribute(name, "angular")) return false;
|
|
21
|
+
}
|
|
22
|
+
return contents;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Rule 3: replaces every Angular host element (see `isAngularHost`) in Angular's output with its
|
|
26
|
+
* children. A `display: contents` host renders no box, so its children lay out as the other
|
|
27
|
+
* targets' do; nested hosts are unwrapped too. Only Angular emits hosts (D6): the same wrapper
|
|
28
|
+
* in another target's output is a real element that selectors and child indices see, so it
|
|
29
|
+
* stays.
|
|
30
|
+
*/
|
|
31
|
+
function unwrapAngularHosts(root, target) {
|
|
32
|
+
if (target !== "angular") return;
|
|
33
|
+
unwrap(root);
|
|
34
|
+
}
|
|
35
|
+
function unwrap(root) {
|
|
36
|
+
const children = childrenOf(root);
|
|
37
|
+
const unwrapped = [];
|
|
38
|
+
let changed = false;
|
|
39
|
+
for (const node of children) {
|
|
40
|
+
if (!isElement(node)) {
|
|
41
|
+
unwrapped.push(node);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
unwrap(node);
|
|
45
|
+
if (isAngularHost(node)) {
|
|
46
|
+
unwrapped.push(...childrenOf(node));
|
|
47
|
+
changed = true;
|
|
48
|
+
} else unwrapped.push(node);
|
|
49
|
+
}
|
|
50
|
+
if (changed) replaceChildren(root, unwrapped);
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { isAngularHost, unwrapAngularHosts };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/normalize/rules/aria-hosts.ts
|
|
2
|
+
/** The `display` values whose children are flex or grid items, which CSS makes boxes. */
|
|
3
|
+
const ITEM_LAYOUTS = /* @__PURE__ */ new Set([
|
|
4
|
+
"flex",
|
|
5
|
+
"inline-flex",
|
|
6
|
+
"grid",
|
|
7
|
+
"inline-grid"
|
|
8
|
+
]);
|
|
9
|
+
/**
|
|
10
|
+
* The ARIA snapshot rule: on Angular only, sets each host under `root` to `display: inline` until
|
|
11
|
+
* the returned function puts its `style` back (ADR-0060). Take the snapshot in between.
|
|
12
|
+
*
|
|
13
|
+
* Playwright's ARIA snapshot puts a space at the start and the end of every element whose
|
|
14
|
+
* `display` isn't `inline`, and Angular's host is `display: contents` (ADR-0010), so two
|
|
15
|
+
* components rendered side by side as inline content read "Build passing" where every other
|
|
16
|
+
* target reads "Buildpassing". An inline host adds no space, so the snapshot comes out as the
|
|
17
|
+
* other targets' does, and Playwright still lays out everything else: no text is edited, so a
|
|
18
|
+
* missing word still differs. The hosts are Angular's `uf-` elements whose computed `display` is
|
|
19
|
+
* `contents`, found in the live DOM.
|
|
20
|
+
*
|
|
21
|
+
* A host whose box parent lays its children out as flex or grid items stays as it is: set inline,
|
|
22
|
+
* CSS would make the host itself a box, and its children inline. Its element children are items,
|
|
23
|
+
* and so boxes, on every target, so the snapshot spaces them anyway.
|
|
24
|
+
*/
|
|
25
|
+
function inlineHosts(root, target) {
|
|
26
|
+
if (target !== "angular") return () => {};
|
|
27
|
+
const hosts = [...root.querySelectorAll("*")].filter((element) => element instanceof HTMLElement && element.localName.startsWith("uf-") && getComputedStyle(element).display === "contents" && !ITEM_LAYOUTS.has(getComputedStyle(boxParent(element)).display));
|
|
28
|
+
const styles = hosts.map((host) => host.getAttribute("style"));
|
|
29
|
+
hosts.forEach((host, index) => {
|
|
30
|
+
const style = styles[index];
|
|
31
|
+
host.setAttribute("style", `${style ? `${style};` : ""}display: inline !important`);
|
|
32
|
+
});
|
|
33
|
+
return () => {
|
|
34
|
+
hosts.forEach((host, index) => {
|
|
35
|
+
const style = styles[index];
|
|
36
|
+
if (style === null) host.removeAttribute("style");
|
|
37
|
+
else host.setAttribute("style", style);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** The element whose box holds `element`'s: its nearest parent that isn't `display: contents`. */
|
|
42
|
+
function boxParent(element) {
|
|
43
|
+
let parent = element.parentElement;
|
|
44
|
+
while (parent.parentElement && getComputedStyle(parent).display === "contents") parent = parent.parentElement;
|
|
45
|
+
return parent;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { inlineHosts };
|