@voila.dev/replay 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,317 @@
1
+ // Random mutations of a live page, for the fuzzer: after each round, the copy rebuilt from the
2
+ // tape must be the page. Ported from the three proofs of concept's generators (calque's for
3
+ // structure, écho's and sillage's for what they added), plus zones, fields and templates.
4
+
5
+ /** A small seeded generator (mulberry32), so a failure replays from its seed. */
6
+ export function seeded(seed: number) {
7
+ let s = (seed * 2654435761) | 0;
8
+ const rnd = () => {
9
+ s = (s + 0x6d2b79f5) | 0;
10
+ let t = Math.imul(s ^ (s >>> 15), 1 | s);
11
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
12
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
13
+ };
14
+ return rnd;
15
+ }
16
+
17
+ /** A fictional page with what sites hold: sections, lists, a form, SVG, a template. */
18
+ export const FUZZ_PAGE = `<!DOCTYPE html><html lang="fr"><head><meta charset="utf-8"><title>Jardins de Belleroche</title>
19
+ <style>.carte{border:1px solid #ccc}.x{color:#333}</style></head><body>
20
+ <header><nav><a href="/">Accueil</a> <a href="/services">Services</a> <a href="/contact">Contact</a></nav><h1>Jardins de Belleroche</h1></header>
21
+ <main><section id="services"><h2>Nos services</h2><ul><li class="carte">Taille de haies</li><li class="carte">Tonte</li><li class="carte">Création de massifs</li></ul></section>
22
+ <section id="avis"><h2>Avis</h2><blockquote>Travail soigné <b>et rapide</b>.</blockquote><blockquote data-va-mask>Client : Paul Léger</blockquote></section>
23
+ <section id="devis"><h2>Demander un devis</h2><form><label>Nom <input name="nom" value=""></label><label>Message <textarea name="message">Bonjour</textarea></label>
24
+ <select name="service"><option>Taille</option><option selected>Tonte</option></select><label><input type="checkbox" name="rappel"> Me rappeler</label><button>Envoyer</button></form></section>
25
+ <section id="carte"><svg width="40" height="40"><circle cx="20" cy="20" r="10"/></svg><div data-va-block><p>Carte interactive</p></div></section>
26
+ <template id="modele"><li class="carte">Nouveau service</li></template>
27
+ <div id="editeur" contenteditable="true"><p>Votre message</p></div>
28
+ </main><footer><p>© Jardins de Belleroche</p></footer></body></html>`;
29
+
30
+ const SKIP: Record<string, 1> = { script: 1, noscript: 1, iframe: 1 };
31
+
32
+ export function mutator(d: Document, rnd: () => number) {
33
+ const int = (n: number) => Math.floor(rnd() * n);
34
+ const pick = <T>(list: ReadonlyArray<T>): T | undefined => list[int(list.length)];
35
+ const blocked = (n: Node) => n.nodeType === 1 && (n as Element).hasAttribute("data-va-block");
36
+ function elements(): Array<Element> {
37
+ const out: Array<Element> = [];
38
+ const walk = (n: ParentNode) => {
39
+ for (const c of Array.from(n.children)) {
40
+ if (SKIP[c.localName]) continue;
41
+ out.push(c);
42
+ if (!blocked(c)) {
43
+ walk(c);
44
+ if (c.shadowRoot) walk(c.shadowRoot);
45
+ if (c.localName === "template") walk((c as HTMLTemplateElement).content);
46
+ }
47
+ }
48
+ };
49
+ walk(d.body);
50
+ walk(d.head);
51
+ return out;
52
+ }
53
+ const textNodes = (el: Element) => Array.from(el.childNodes).filter((c) => c.nodeType === 3) as Array<Text>;
54
+ const word = () =>
55
+ pick(["haie", "tonte", "massif", "potager", "allée", "bassin", "serre", " ", "\n\t", "été & hiver", "<b>", ""]) as string;
56
+ const TAGS = ["div", "p", "span", "ul", "li", "b", "section", "em", "a", "button", "table", "tr", "td", "input", "textarea", "select"];
57
+ function make(depth = 0): Node {
58
+ const kind = rnd();
59
+ if (kind < 0.25) return d.createTextNode(word());
60
+ if (kind < 0.3) return d.createComment(word());
61
+ if (kind < 0.33) {
62
+ const sc = d.createElement("script");
63
+ sc.type = "text/plain";
64
+ sc.textContent = "x";
65
+ return sc;
66
+ }
67
+ if (kind < 0.38) {
68
+ const svg = d.createElementNS("http://www.w3.org/2000/svg", "svg");
69
+ const c = d.createElementNS("http://www.w3.org/2000/svg", "circle");
70
+ c.setAttribute("r", String(int(9)));
71
+ svg.append(c);
72
+ if (rnd() < 0.5) {
73
+ const fo = d.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
74
+ fo.append(d.createElement("div"));
75
+ svg.append(fo);
76
+ }
77
+ return svg;
78
+ }
79
+ if (kind < 0.4) {
80
+ const t = d.createElement("template");
81
+ t.content.append(make(depth + 1));
82
+ return t;
83
+ }
84
+ const el = d.createElement(pick(TAGS) as string);
85
+ if (el.localName === "select") {
86
+ for (let i = 1 + int(3); i > 0; i--) {
87
+ const o = d.createElement("option");
88
+ o.textContent = word();
89
+ if (rnd() < 0.3) o.setAttribute("selected", "");
90
+ el.append(o);
91
+ }
92
+ return el;
93
+ }
94
+ if (el.localName === "input" || el.localName === "textarea") {
95
+ if (rnd() < 0.5) el.setAttribute("value", word());
96
+ if (rnd() < 0.3) el.setAttribute("type", pick(["text", "checkbox", "password", "email"]) as string);
97
+ return el;
98
+ }
99
+ if (rnd() < 0.6)
100
+ el.setAttribute(pick(["class", "id", "title", "data-k", "style", "hidden", "alt"]) as string, pick(["a", "b c", "color:red", ""]) as string);
101
+ if (rnd() < 0.06) el.setAttribute("data-va-block", "");
102
+ if (rnd() < 0.06) el.setAttribute("data-va-mask", "");
103
+ if (rnd() < 0.04) el.setAttribute("contenteditable", "true");
104
+ if (rnd() < 0.08 && /^(div|p|span|section)$/.test(el.localName)) {
105
+ const root = el.attachShadow({ mode: "open" });
106
+ root.append(make(depth + 1));
107
+ }
108
+ if (depth < 3) for (let i = int(4); i > 0; i--) el.append(make(depth + 1));
109
+ return el;
110
+ }
111
+ const w = d.defaultView as Window & typeof globalThis;
112
+ const pause = async () => {
113
+ const r = rnd();
114
+ if (r < 0.25) await Promise.resolve();
115
+ else if (r < 0.35) await new Promise((f) => w.setTimeout(f, 0));
116
+ else if (r < 0.37) await new Promise((f) => w.setTimeout(f, 70));
117
+ };
118
+ const shadowHost = (n: Node) => (n.getRootNode({ composed: false }) as ShadowRoot).host;
119
+ async function mutate() {
120
+ const all = elements();
121
+ if (!all.length) return;
122
+ const el = pick(all) as Element;
123
+ const other = pick(all) as Element;
124
+ const safe = (target: Node, node: Element) =>
125
+ !node.contains(target) &&
126
+ !node.shadowRoot?.contains(target) &&
127
+ node !== d.body &&
128
+ node !== d.head &&
129
+ !shadowHost(target) &&
130
+ node.isConnected;
131
+ const op = int(26);
132
+ log.push(`${op}:${el.localName}${el.id ? `#${el.id}` : ""}→${other.localName}`);
133
+ // A select or an option holds options only: the parser never builds anything else there.
134
+ const fieldsOnly = /^(select|option|optgroup)$/.test(el.localName);
135
+ if (fieldsOnly && op !== 2 && op !== 4 && op !== 5 && op !== 20 && op !== 21 && op !== 22) return;
136
+ // Raw text elements hold text only, for the same reason.
137
+ if (/^(style|title|textarea)$/.test(el.localName) && op !== 2 && op !== 4 && op !== 5 && op !== 6 && op !== 14 && op !== 20 && op !== 21) return;
138
+ switch (op) {
139
+ case 0:
140
+ el.append(make());
141
+ break;
142
+ case 1:
143
+ el.insertBefore(make(), pick(Array.from(el.childNodes)) || null);
144
+ break;
145
+ case 2:
146
+ if (el !== d.body && el !== d.head) el.remove();
147
+ break;
148
+ case 3:
149
+ if (safe(el, other)) el.insertBefore(other, pick(Array.from(el.childNodes)) || null);
150
+ break;
151
+ case 4:
152
+ el.setAttribute(pick(["class", "title", "data-k", "style", "aria-label", "alt"]) as string, word());
153
+ break;
154
+ case 5: {
155
+ const names = el.getAttributeNames();
156
+ if (names.length) el.removeAttribute(pick(names) as string);
157
+ break;
158
+ }
159
+ case 6: {
160
+ const t = pick(textNodes(el));
161
+ if (t) t.data = word() + int(100);
162
+ else el.append(word());
163
+ break;
164
+ }
165
+ case 7:
166
+ el.innerHTML = `<p class="x">${word().replace(/[<&]/g, "")}<!-- c --><span>${int(9)}</span></p><script type="text/plain">1</script><svg><path d="M0 0"/></svg>tail`;
167
+ break;
168
+ case 8: {
169
+ const list = Array.from(el.childNodes);
170
+ for (let i = list.length - 1; i > 0; i--) {
171
+ const j = int(i + 1);
172
+ [list[i], list[j]] = [list[j] as ChildNode, list[i] as ChildNode];
173
+ }
174
+ el.replaceChildren(...list);
175
+ break;
176
+ }
177
+ case 9: {
178
+ const n = make();
179
+ el.append(n);
180
+ await pause();
181
+ if (n.nodeType === 1) {
182
+ (n as Element).setAttribute("data-late", "1");
183
+ (n as Element).append(make());
184
+ }
185
+ break;
186
+ }
187
+ case 10: {
188
+ if (el === d.body || el === d.head) break;
189
+ const parent = el.parentNode;
190
+ const next = el.nextSibling;
191
+ el.remove();
192
+ el.setAttribute("data-away", "1");
193
+ await Promise.resolve();
194
+ el.append("changed away");
195
+ el.firstElementChild?.remove();
196
+ await pause();
197
+ if (parent?.isConnected) parent.insertBefore(el, next && next.parentNode === parent ? next : null);
198
+ break;
199
+ }
200
+ case 11:
201
+ el.insertBefore(d.createComment("c"), el.firstChild);
202
+ el.insertBefore(make(), el.firstChild);
203
+ el.append(d.createComment("d"), make());
204
+ break;
205
+ case 12: {
206
+ const t = pick(textNodes(el));
207
+ if (t && t.data.length > 2) t.splitText(1);
208
+ else el.normalize();
209
+ break;
210
+ }
211
+ case 13: {
212
+ if (!safe(el, other)) break;
213
+ const box = d.createElement("div");
214
+ box.append(make(), other, make());
215
+ await pause();
216
+ el.append(box);
217
+ if (rnd() < 0.3) {
218
+ await pause();
219
+ box.remove();
220
+ }
221
+ break;
222
+ }
223
+ case 14:
224
+ el.textContent = rnd() < 0.5 ? "" : word();
225
+ break;
226
+ case 15:
227
+ el.insertAdjacentHTML(pick(["afterbegin", "beforeend"]) as InsertPosition, `<i>${int(9)}</i>text<u></u>`);
228
+ break;
229
+ case 16: {
230
+ const a = el.firstChild;
231
+ const b = el.lastChild;
232
+ if (a && b && a !== b) {
233
+ el.insertBefore(b, a);
234
+ el.append(a);
235
+ }
236
+ break;
237
+ }
238
+ case 17:
239
+ if (!el.shadowRoot && /^(div|p|span|section)$/.test(el.localName) && !shadowHost(el)) {
240
+ try {
241
+ el.attachShadow({ mode: "open" }).append(make(1));
242
+ } catch {}
243
+ }
244
+ break;
245
+ case 18: {
246
+ const box = all.find(blocked);
247
+ if (!box || !safe(box, other) || other === box) break;
248
+ box.append(other);
249
+ if (rnd() < 0.5) {
250
+ await pause();
251
+ if (safe(el, other)) el.append(other);
252
+ }
253
+ break;
254
+ }
255
+ case 19: {
256
+ const kids = Array.from(el.children);
257
+ const a = pick(kids);
258
+ const b = pick(kids);
259
+ if (a && b && a !== b) {
260
+ const ghost = d.createComment("");
261
+ a.replaceWith(ghost);
262
+ b.replaceWith(a);
263
+ ghost.replaceWith(b);
264
+ }
265
+ break;
266
+ }
267
+ // What the three generators lacked: zones toggled, fields changed by script, templates.
268
+ case 20:
269
+ if (el !== d.body && el !== d.documentElement)
270
+ el.toggleAttribute(pick(["data-va-block", "data-va-mask", "data-va-unmask"]) as string);
271
+ break;
272
+ case 21:
273
+ if (el !== d.body) el.toggleAttribute("contenteditable");
274
+ break;
275
+ case 22: {
276
+ const field = pick(all.filter((e) => /^(input|textarea|select)$/.test(e.localName))) as
277
+ | (HTMLInputElement & HTMLSelectElement)
278
+ | undefined;
279
+ if (!field) break;
280
+ if (field.localName === "select") field.selectedIndex = int(field.options.length + 1) - 1;
281
+ else if ((field as HTMLInputElement).type === "checkbox") field.checked = !field.checked;
282
+ else field.value = word() + int(9);
283
+ break;
284
+ }
285
+ case 23: {
286
+ const t = pick(all.filter((e) => e.localName === "template")) as HTMLTemplateElement | undefined;
287
+ if (!t) break;
288
+ if (rnd() < 0.5) t.content.append(make(1));
289
+ else t.content.firstChild?.remove();
290
+ break;
291
+ }
292
+ case 24: {
293
+ const t = pick(all.filter((e) => e.localName === "template")) as HTMLTemplateElement | undefined;
294
+ if (t && el !== t && !t.contains(el) && el.isConnected && !blocked(el)) el.append(t.content.cloneNode(true));
295
+ break;
296
+ }
297
+ case 25:
298
+ if (el !== d.body && el !== d.head && el.localName !== "html") el.replaceWith(make());
299
+ break;
300
+ }
301
+ }
302
+ const log: Array<string> = [];
303
+ return {
304
+ log,
305
+ async round() {
306
+ log.length = 0;
307
+ for (let i = 1 + int(12); i > 0; i--) {
308
+ try {
309
+ await mutate();
310
+ } catch (e) {
311
+ if ((e as Error).name !== "HierarchyRequestError" && (e as Error).name !== "NotSupportedError") throw e;
312
+ }
313
+ await pause();
314
+ }
315
+ },
316
+ };
317
+ }
@@ -0,0 +1,8 @@
1
+ export { CASES, type Case } from "./cases";
2
+ export { compare, type Diff, type OracleOptions } from "./oracle";
3
+
4
+ /** The secrets found in what left the page, in clear: each one is a leak. */
5
+ export function leaks(sent: ReadonlyArray<string>, secrets: ReadonlyArray<string>): Array<string> {
6
+ return secrets.filter((s) => sent.some((body) => body.includes(s)));
7
+ }
8
+ export { FUZZ_PAGE, mutator, seeded } from "./fuzz";
@@ -0,0 +1,318 @@
1
+ // The oracle: a normalized walk of the live page and of the copy, side by side. It knows the
2
+ // masking rule from the outside (what the copy must show), not how the recorder applies it.
3
+ //
4
+ // Ignored on purpose (the player does it by design, or it changes nothing shown): comments,
5
+ // script and noscript, <base>, event handler attributes, `target` on links, iframe src and
6
+ // srcdoc, meta http-equiv, a linked sheet the player serves from a blob, closed shadow roots.
7
+ // Compared: namespace, tag, attributes (URLs resolved), merged text, form state, :modal, the
8
+ // rules of each <style> and of adoptedStyleSheets, template content, open shadow roots,
9
+ // compatMode and the doctype.
10
+ import type { Mask } from "../record/index";
11
+
12
+ export interface OracleOptions {
13
+ readonly mask?: Mask;
14
+ readonly maskAttr?: string;
15
+ readonly blockAttr?: string;
16
+ readonly unmaskAttr?: string;
17
+ readonly max?: number;
18
+ readonly ignoreMode?: boolean;
19
+ }
20
+
21
+ export interface Diff {
22
+ readonly path: string;
23
+ readonly what: string;
24
+ readonly live?: string;
25
+ readonly copy?: string;
26
+ /** The two elements around the difference, as HTML, to read a failure. */
27
+ readonly around?: readonly [string, string];
28
+ }
29
+
30
+ const HTML = "http://www.w3.org/1999/xhtml";
31
+ const VOID = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
32
+ const URL_ATTR = /^(src|href|poster|action|formaction|data|xlink:href|cite|background)$/;
33
+ const SAFE_URL = /^(https?:|data:image\/|blob:|#|mailto:|tel:)/i;
34
+ const CSS_URL = /url\(\s*(['"]?)(?!data:|#|blob:)([^'")]+)\1\s*\)/g;
35
+ /** The attributes a masked zone leaves in clear: everything else shows as stars. */
36
+ const PLAIN =
37
+ /^(class|id|style|type|role|width|height|src|srcset|sizes|href|rel|media|dir|lang|hidden|disabled|checked|selected|open|colspan|rowspan|for|name|contenteditable|tabindex|viewbox|d|fill|stroke|x|y|cx|cy|r|rx|ry|points|transform|xmlns|slot|part|draggable|loading|decoding|crossorigin|referrerpolicy|async|defer|multiple|readonly|required|min|max|step|autocomplete|inputmode|popover)$/i;
38
+ const NOT_TYPED = /^(button|submit|reset|image)$/;
39
+ const TOGGLE = /^(checkbox|radio)$/;
40
+ const STARS = "******";
41
+
42
+ const stars = (s: string) => s.replace(/\S/g, "*");
43
+ // Through the prototype: a form holding a field named `hasAttribute` hides the method.
44
+ const P = Element.prototype;
45
+ const hasA = (el: Element, n: string) => P.hasAttribute.call(el, n);
46
+ const getA = (el: Element, n: string) => P.getAttribute.call(el, n);
47
+ const getter = (name: string) => Object.getOwnPropertyDescriptor(P, name)?.get as (this: Element) => unknown;
48
+ const LOCAL = getter("localName");
49
+ const NS = getter("namespaceURI");
50
+ const ATTRS = getter("attributes");
51
+ const tagOf = (el: Element) => LOCAL.call(el) as string;
52
+ const nsOf = (el: Element) => NS.call(el) as string | null;
53
+ const attrsOf = (el: Element) => ATTRS.call(el) as NamedNodeMap;
54
+ const short = (v: unknown) => {
55
+ const s = typeof v === "string" ? v : JSON.stringify(v);
56
+ return s && s.length > 160 ? `${s.slice(0, 160)}…` : s;
57
+ };
58
+
59
+ export function compare(live: Document, copy: Document, o: OracleOptions = {}): Array<Diff> {
60
+ const mode = o.mask || "inputs";
61
+ const maskAttr = o.maskAttr || "data-va-mask";
62
+ const blockAttr = o.blockAttr || "data-va-block";
63
+ const unmaskAttr = o.unmaskAttr || "data-va-unmask";
64
+ const diffs: Array<Diff> = [];
65
+ const max = o.max || 6;
66
+ const base = live.URL;
67
+ let around: readonly [string, string] | undefined;
68
+ const html = (n: Node) => {
69
+ const s = n.nodeType === 1 ? (n as Element).outerHTML : n.nodeType === 11 ? `#root ${(n as ShadowRoot).innerHTML ?? ""}` : String(n.textContent);
70
+ return s.length > 400 ? `${s.slice(0, 400)}…` : s;
71
+ };
72
+ const add = (path: string, what: string, a?: unknown, b?: unknown) => {
73
+ if (diffs.length < max) diffs.push({ path, what, live: short(a), copy: short(b), ...(around ? { around } : {}) });
74
+ };
75
+ const abs = (u: string) => {
76
+ try {
77
+ return new URL(u, base).href;
78
+ } catch {
79
+ return u;
80
+ }
81
+ };
82
+ const cssAbs = (t: string) => t.replace(CSS_URL, (_m, _q, u: string) => `url("${abs(u)}")`);
83
+ // The player leaves out a name the copy's DOM refuses (`@click`, `:class` where the DOM still
84
+ // holds attribute names to the XML rules): that browser cannot hold it outside the parser.
85
+ const refused = (name: string) => {
86
+ try {
87
+ copy.createAttribute(name);
88
+ return false;
89
+ } catch {
90
+ return true;
91
+ }
92
+ };
93
+ const rules = (sheet: CSSStyleSheet) => {
94
+ try {
95
+ return Array.from(sheet.cssRules, (r) => r.cssText).join("\n");
96
+ } catch {
97
+ return "<illisible>";
98
+ }
99
+ };
100
+ const adopted = (root: Document | ShadowRoot, live: boolean) =>
101
+ Array.from(root.adoptedStyleSheets || [], (s) => (live ? cssAbs(rules(s)) : rules(s))).join(
102
+ "\n---\n",
103
+ );
104
+
105
+ // biome-ignore lint/suspicious/noExplicitAny: form controls.
106
+ const sensitive = (el: any) =>
107
+ /^(password|hidden)$/i.test(el.type || "") ||
108
+ /cc-|one-time-code|password/i.test(getA(el, "autocomplete") || "");
109
+ const fieldHidden = (el: Element, masked: boolean, clear: boolean) => {
110
+ if (sensitive(el)) return true;
111
+ if (mode === "none") return masked;
112
+ return !clear;
113
+ };
114
+ const shown = (v: string, hidden: boolean) => (hidden ? (v ? STARS : "") : v);
115
+ const masksSelf = (el: Element) => {
116
+ if (hasA(el, maskAttr)) return true;
117
+ if (mode === "none") return false;
118
+ const e = getA(el, "contenteditable");
119
+ return e !== null && e.toLowerCase() !== "false" && !hasA(el, unmaskAttr);
120
+ };
121
+
122
+ function path(n: Node): string {
123
+ const p: Array<string> = [];
124
+ for (let x: Node | null = n; x && x.nodeType === 1; x = x.parentNode || (x as ShadowRoot).host || null) {
125
+ const el = x as Element;
126
+ p.unshift(tagOf(el) + (el.id ? `#${el.id}` : ""));
127
+ }
128
+ return p.join(">");
129
+ }
130
+
131
+ type Kid = Element | { nodeType: 3; data: string };
132
+ function kids(n: Node): Array<Kid> {
133
+ const out: Array<Kid> = [];
134
+ const el = n as Element;
135
+ const list =
136
+ n.nodeType === 1 && tagOf(el) === "template" && nsOf(el) === HTML
137
+ ? (el as HTMLTemplateElement).content.childNodes
138
+ : n.childNodes;
139
+ for (const c of Array.from(list)) {
140
+ if (c.nodeType === 3) {
141
+ const data = (c as Text).data;
142
+ if (!data) continue;
143
+ const last = out[out.length - 1];
144
+ if (last && last.nodeType === 3) (last as { data: string }).data += data;
145
+ else out.push({ nodeType: 3, data });
146
+ } else if (c.nodeType === 1) {
147
+ const e = c as Element;
148
+ const tag = tagOf(e);
149
+ if (tag === "script" || tag === "replay-script" || tag === "base" || tag === "replay-base") continue;
150
+ if (tag === "noscript" && nsOf(e) === HTML) continue;
151
+ out.push(e);
152
+ }
153
+ }
154
+ return out;
155
+ }
156
+
157
+ function attrs(el: Element, side: "live" | "copy", masked: boolean) {
158
+ const m = new Map<string, string>();
159
+ const tag = tagOf(el);
160
+ for (const a of Array.from(attrsOf(el))) {
161
+ const name = a.name;
162
+ let v = a.value;
163
+ if (/^on/i.test(name) || name === "http-equiv") continue;
164
+ if (tag === "iframe" && /^(src|srcdoc)$/.test(name)) continue;
165
+ if (tag === "a" && name === "target") continue;
166
+ if (tag === "input" && (name === "value" || name === "checked")) continue;
167
+ if (tag === "textarea" && name === "value") continue;
168
+ if (tag === "option" && name === "selected") continue;
169
+ if (
170
+ tag === "link" &&
171
+ name === "href" &&
172
+ /stylesheet/i.test(getA(el, "rel") || "") &&
173
+ (side === "copy" ? v.startsWith("blob:") : true)
174
+ )
175
+ continue;
176
+ if (side === "live" && masked && !PLAIN.test(name)) v = stars(v);
177
+ if (URL_ATTR.test(name)) {
178
+ v = abs(v);
179
+ if (side === "live" && !SAFE_URL.test(v)) v = "about:blank";
180
+ } else if (name === "srcset")
181
+ v = v
182
+ .split(",")
183
+ .map((p) => {
184
+ const [u, ...s] = p.trim().split(/\s+/);
185
+ return [abs(u || ""), ...s].join(" ");
186
+ })
187
+ .join(", ");
188
+ else if (name === "style" && side === "live") v = cssAbs(v);
189
+ if (side === "live" && refused(name)) continue;
190
+ m.set(name, v);
191
+ }
192
+ return m;
193
+ }
194
+
195
+ // biome-ignore lint/suspicious/noExplicitAny: form controls.
196
+ function state(L: any, R: any, p: string, masked: boolean, clear: boolean) {
197
+ const tag = tagOf(L);
198
+ if (tag === "input") {
199
+ const t = String(L.type);
200
+ if (t !== "file" && t !== "hidden" && !NOT_TYPED.test(t) && !TOGGLE.test(t)) {
201
+ const want = shown(L.value, fieldHidden(L, masked, clear));
202
+ if (want !== R.value) add(p, "input.value", want, R.value);
203
+ }
204
+ if (L.checked !== R.checked) add(p, "input.checked", L.checked, R.checked);
205
+ } else if (tag === "textarea") {
206
+ const want = shown(L.value, fieldHidden(L, masked, clear));
207
+ if (want !== R.value) add(p, "textarea.value", want, R.value);
208
+ } else if (tag === "select") {
209
+ const picked = (s: HTMLSelectElement) =>
210
+ Array.from(s.options, (x, i) => (x.selected ? i : -1))
211
+ .filter((i) => i >= 0)
212
+ .join(",");
213
+ let want = picked(L);
214
+ if (fieldHidden(L, masked, clear)) {
215
+ // A hidden choice: the copy shows what the markup alone selects.
216
+ // A hidden choice: the copy shows what the markup alone selects.
217
+ const options = Array.from(L.options as ArrayLike<HTMLOptionElement>);
218
+ if (L.multiple || L.size > 1) want = options.map((x, i) => (hasA(x, "selected") ? i : -1)).filter((i) => i >= 0).join(",");
219
+ else {
220
+ let k = -1;
221
+ options.forEach((x, i) => {
222
+ if (hasA(x, "selected")) k = i;
223
+ });
224
+ if (k < 0) k = options.findIndex((x) => !x.disabled);
225
+ want = k < 0 ? "" : String(k);
226
+ }
227
+ }
228
+ if (want !== picked(R)) add(p, "select: options choisies", want, picked(R));
229
+ } else if (tag === "dialog") {
230
+ const modal = (d: Element) => {
231
+ try {
232
+ return d.matches(":modal");
233
+ } catch {
234
+ return null;
235
+ }
236
+ };
237
+ if (modal(L) !== modal(R)) add(p, "dialog :modal", modal(L), modal(R));
238
+ if (L.open !== R.open) add(p, "dialog.open", L.open, R.open);
239
+ }
240
+ }
241
+
242
+ function element(L: Element, R: Element, masked: boolean, clear: boolean) {
243
+ around = [html(L), html(R)];
244
+ const p = path(L);
245
+ const name = (e: Element) => `${nsOf(e) === HTML ? "" : `${nsOf(e)} `}<${tagOf(e)}>`;
246
+ if (nsOf(L) !== nsOf(R) || tagOf(L) !== tagOf(R)) {
247
+ add(p, "élément", name(L), name(R));
248
+ return;
249
+ }
250
+ if (hasA(L, blockAttr)) {
251
+ if (!hasA(R, "data-replay-blocked")) add(p, "élément bloqué rejoué", "(boîte)", R.outerHTML);
252
+ return;
253
+ }
254
+ masked = masked || masksSelf(L);
255
+ clear = clear || hasA(L, unmaskAttr);
256
+ const a = attrs(L, "live", masked);
257
+ const b = attrs(R, "copy", masked);
258
+ for (const [k, v] of a) if (b.get(k) !== v) add(p, `@${k}`, v, b.has(k) ? b.get(k) : "(absent)");
259
+ for (const [k, v] of b) if (!a.has(k)) add(p, `@${k}`, "(absent)", v);
260
+ if (nsOf(L) === HTML) state(L, R, p, masked, clear);
261
+ if (tagOf(L) === "style") {
262
+ const x = (L as HTMLStyleElement).sheet ? cssAbs(rules((L as HTMLStyleElement).sheet as CSSStyleSheet)) : L.textContent;
263
+ const y = (R as HTMLStyleElement).sheet ? rules((R as HTMLStyleElement).sheet as CSSStyleSheet) : R.textContent;
264
+ if (x !== y) add(p, "règles CSS", x, y);
265
+ return;
266
+ }
267
+ if (tagOf(L) === "textarea") return;
268
+ if (nsOf(L) === HTML && VOID.test(tagOf(L))) return;
269
+ const ls = L.shadowRoot;
270
+ const rs = R.shadowRoot;
271
+ if (ls) {
272
+ if (!rs) add(p, "shadow root", true, false);
273
+ else {
274
+ list(ls, rs, `${p}/#shadow`, masked, clear);
275
+ if (adopted(ls, true) !== adopted(rs, false))
276
+ add(`${p}/#shadow`, "adoptedStyleSheets", adopted(ls, true), adopted(rs, false));
277
+ }
278
+ }
279
+ list(L, R, p, masked, clear);
280
+ }
281
+
282
+ function list(L: Node, R: Node, p: string, masked: boolean, clear: boolean) {
283
+ around = [html(L), html(R)];
284
+ const x = kids(L);
285
+ const y = kids(R);
286
+ const n = Math.max(x.length, y.length);
287
+ const show = (k: Kid | undefined) =>
288
+ !k ? "" : k.nodeType === 3 ? (k as { data: string }).data : `<${(k as Element).localName}>`;
289
+ for (let i = 0; i < n && diffs.length < max; i++) {
290
+ const a = x[i];
291
+ const b = y[i];
292
+ if (!a || !b) {
293
+ add(`${p}[${i}]`, a ? "nœud absent de la copie" : "nœud en trop dans la copie", show(a), show(b));
294
+ break;
295
+ }
296
+ if (a.nodeType !== b.nodeType) {
297
+ add(`${p}[${i}]`, "type de nœud", show(a), show(b));
298
+ break;
299
+ }
300
+ if (a.nodeType === 3) {
301
+ const parent = L.nodeType === 1 ? (L as Element).localName : "";
302
+ const data = (a as { data: string }).data;
303
+ const want = parent === "style" ? cssAbs(data) : masked ? stars(data) : data;
304
+ if (want !== (b as { data: string }).data) add(`${p}[${i}]`, "texte", want, (b as { data: string }).data);
305
+ } else element(a as Element, b as Element, masked, clear);
306
+ }
307
+ }
308
+
309
+ if (!o.ignoreMode && live.compatMode !== copy.compatMode)
310
+ add("#document", "compatMode", live.compatMode, copy.compatMode);
311
+ const dt = (d: Document) => (d.doctype ? d.doctype.name : null);
312
+ if (dt(live) !== dt(copy)) add("#document", "doctype", dt(live), dt(copy));
313
+ if (adopted(live, true) !== adopted(copy, false))
314
+ add("#document", "adoptedStyleSheets", adopted(live, true), adopted(copy, false));
315
+ if (!copy.documentElement) add("#document", "documentElement", "<html>", null);
316
+ else if (live.documentElement) element(live.documentElement, copy.documentElement, mode === "text", false);
317
+ return diffs;
318
+ }