@voila.dev/replay 0.0.0-stage → 0.1.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.
@@ -0,0 +1,1197 @@
1
+ // src/testing/cases.ts
2
+ var D = (body, head = "") => `<!DOCTYPE html><html lang="fr"><head><meta charset="utf-8"><title>Cas</title>${head}</head><body>${body}</body></html>`;
3
+ var AB = D('<div id="a"></div><div id="b">avant</div>');
4
+ var hazards = (d) => {
5
+ const a = d.getElementById("a");
6
+ const t = d.createElement("table");
7
+ const tr = d.createElement("tr");
8
+ const td = d.createElement("td");
9
+ td.textContent = "cellule";
10
+ tr.append(td);
11
+ t.append(tr);
12
+ a.append(t);
13
+ const p = d.createElement("p");
14
+ const div = d.createElement("div");
15
+ div.textContent = "bloc";
16
+ p.append(div);
17
+ a.append(p);
18
+ const l1 = d.createElement("a");
19
+ const l2 = d.createElement("a");
20
+ l1.href = "/x";
21
+ l2.href = "/y";
22
+ l2.textContent = "lien";
23
+ l1.append(l2);
24
+ a.append(l1);
25
+ const ul = d.createElement("ul");
26
+ const li = d.createElement("li");
27
+ const li2 = d.createElement("li");
28
+ li2.textContent = "sous";
29
+ li.append(li2);
30
+ ul.append(li);
31
+ a.append(ul);
32
+ const svg = d.createElementNS("http://www.w3.org/2000/svg", "svg");
33
+ const h = d.createElement("div");
34
+ h.textContent = "html dans svg";
35
+ svg.append(h);
36
+ a.append(svg);
37
+ };
38
+ var CASES = [
39
+ {
40
+ name: "t\xE9moin",
41
+ group: "base",
42
+ html: D('<header><h1>Titre</h1></header><main><p id="p">Texte <b>gras</b></p><ul id="u"><li>un</li></ul></main>'),
43
+ run: (d) => {
44
+ d.getElementById("p")?.append(" ajout\xE9");
45
+ const li = d.createElement("li");
46
+ li.textContent = "deux";
47
+ d.getElementById("u")?.append(li);
48
+ d.querySelector("h1").className = "x";
49
+ }
50
+ },
51
+ {
52
+ name: "table sans tbody",
53
+ group: "parseur",
54
+ html: AB,
55
+ run: (d) => {
56
+ const t = d.createElement("table");
57
+ const tr = d.createElement("tr");
58
+ const td = d.createElement("td");
59
+ td.textContent = "c";
60
+ tr.append(td);
61
+ t.append(tr);
62
+ d.getElementById("a")?.append(t);
63
+ d.getElementById("b").textContent = "apr\xE8s";
64
+ }
65
+ },
66
+ {
67
+ name: "div dans p",
68
+ group: "parseur",
69
+ html: AB,
70
+ run: (d) => {
71
+ const p = d.createElement("p");
72
+ const x = d.createElement("div");
73
+ x.textContent = "bloc";
74
+ p.append(x, "suite");
75
+ d.getElementById("a")?.append(p);
76
+ d.getElementById("b").textContent = "apr\xE8s";
77
+ }
78
+ },
79
+ {
80
+ name: "a dans a",
81
+ group: "parseur",
82
+ html: AB,
83
+ run: (d) => {
84
+ const a = d.createElement("a");
85
+ const b = d.createElement("a");
86
+ a.href = "/x";
87
+ b.href = "/y";
88
+ b.textContent = "lien";
89
+ a.append(b, "fin");
90
+ d.getElementById("a")?.append(a);
91
+ d.getElementById("b").textContent = "apr\xE8s";
92
+ }
93
+ },
94
+ {
95
+ name: "li dans li",
96
+ group: "parseur",
97
+ html: AB,
98
+ run: (d) => {
99
+ const ul = d.createElement("ul");
100
+ const li = d.createElement("li");
101
+ const x = d.createElement("li");
102
+ x.textContent = "sous";
103
+ li.append(x);
104
+ ul.append(li);
105
+ d.getElementById("a")?.append(ul);
106
+ d.getElementById("b").textContent = "apr\xE8s";
107
+ }
108
+ },
109
+ {
110
+ name: "HTML cr\xE9\xE9 par script dans SVG",
111
+ group: "parseur",
112
+ html: AB,
113
+ run: (d) => {
114
+ const svg = d.createElementNS("http://www.w3.org/2000/svg", "svg");
115
+ const x = d.createElement("div");
116
+ x.textContent = "html";
117
+ const g = d.createElementNS("http://www.w3.org/2000/svg", "g");
118
+ const s = d.createElement("span");
119
+ s.textContent = "s";
120
+ g.append(s);
121
+ svg.append(x, g);
122
+ d.getElementById("a")?.append(svg);
123
+ d.getElementById("b").textContent = "apr\xE8s";
124
+ }
125
+ },
126
+ {
127
+ name: "les cinq pi\xE8ges, pr\xE9sents d\xE8s le d\xE9part",
128
+ group: "parseur",
129
+ html: AB,
130
+ before: hazards,
131
+ run: (d) => {
132
+ d.getElementById("b").textContent = "apr\xE8s";
133
+ }
134
+ },
135
+ {
136
+ name: "MathML",
137
+ group: "parseur",
138
+ html: D('<p id="p">x</p><math id="m"><mi>a</mi><mo>+</mo><mn>2</mn></math>'),
139
+ run: (d) => {
140
+ const mi = d.createElementNS("http://www.w3.org/1998/Math/MathML", "mi");
141
+ mi.textContent = "b";
142
+ d.getElementById("m")?.append(mi);
143
+ }
144
+ },
145
+ {
146
+ name: "d\xE9tach\xE9, modifi\xE9, r\xE9ins\xE9r\xE9",
147
+ group: "mutations",
148
+ html: D('<section id="s"><div id="x" class="a"><span>un</span><i>deux</i></div><p id="y">p</p></section>'),
149
+ run: async (d, _w, wait) => {
150
+ const s = d.getElementById("s");
151
+ const x = d.getElementById("x");
152
+ const y = d.getElementById("y");
153
+ x.remove();
154
+ x.setAttribute("data-away", "1");
155
+ x.firstChild.textContent = "chang\xE9";
156
+ x.append(d.createElement("em"));
157
+ await Promise.resolve();
158
+ x.lastElementChild.textContent = "nouveau";
159
+ await wait(40);
160
+ x.querySelector("i")?.remove();
161
+ s.append(x);
162
+ y.remove();
163
+ y.textContent = "m\xEAme t\xE2che";
164
+ y.title = "t";
165
+ s.prepend(y);
166
+ }
167
+ },
168
+ {
169
+ name: "d\xE9placements",
170
+ group: "mutations",
171
+ html: D('<div id="a"><p>1</p><p>2</p><p>3</p></div><div id="b"><span>x</span><span>y</span></div>'),
172
+ run: async (d, _w, wait) => {
173
+ const a = d.getElementById("a");
174
+ const b = d.getElementById("b");
175
+ b.append(a.firstElementChild);
176
+ a.append(a.firstElementChild);
177
+ const box = d.createElement("div");
178
+ box.id = "box";
179
+ box.append(b.firstElementChild);
180
+ await wait(40);
181
+ a.prepend(box);
182
+ const [p, q] = Array.from(b.children);
183
+ const ghost = d.createComment("");
184
+ p?.replaceWith(ghost);
185
+ if (p) q?.replaceWith(p);
186
+ if (q) ghost.replaceWith(q);
187
+ b.append(a);
188
+ await Promise.resolve();
189
+ d.body.prepend(box);
190
+ }
191
+ },
192
+ {
193
+ name: "innerHTML massif",
194
+ group: "mutations",
195
+ html: D('<main id="m"><p>avant</p></main><p id="z">z</p>'),
196
+ run: async (d, _w, wait) => {
197
+ const m = d.getElementById("m");
198
+ let h = "";
199
+ for (let i = 0; i < 1500; i++)
200
+ h += `<div class="r${i % 7}" data-i="${i}"><span>ligne ${i}</span> <b>${i}</b>${i % 50 ? "" : "<table><tr><td>t</td></tr></table>"}</div>`;
201
+ m.innerHTML = h;
202
+ await wait(40);
203
+ m.innerHTML = h.replace(/ligne/g, "rang");
204
+ d.getElementById("z").textContent = "fin";
205
+ }
206
+ },
207
+ {
208
+ name: "shadow DOM attach\xE9 plus tard",
209
+ group: "mutations",
210
+ html: D('<div id="h"><span>clair</span></div><p id="q">d\xE9plac\xE9</p>'),
211
+ run: async (d, _w, wait) => {
212
+ const r = d.getElementById("h").attachShadow({ mode: "open" });
213
+ r.innerHTML = "<style>b{color:red}</style><b>ombre</b><slot></slot>";
214
+ await wait(40);
215
+ r.querySelector("b").textContent = "ombre modifi\xE9e";
216
+ r.append(d.getElementById("q"));
217
+ }
218
+ },
219
+ {
220
+ name: "shadow DOM pr\xE9sent au d\xE9part",
221
+ group: "mutations",
222
+ html: D('<div id="h"><span>clair</span></div>'),
223
+ before: (d) => {
224
+ d.getElementById("h").attachShadow({ mode: "open" }).innerHTML = "<i>avant</i>";
225
+ },
226
+ run: (d) => {
227
+ const r = d.getElementById("h").shadowRoot;
228
+ r.querySelector("i").textContent = "apr\xE8s";
229
+ r.append(d.createElement("u"));
230
+ }
231
+ },
232
+ {
233
+ name: "shadow DOM attach\xE9 dans un <template>",
234
+ group: "mutations",
235
+ html: D('<template id="t"><p class="x">haie<span>1</span></p></template><p id="z">z</p>'),
236
+ run: (d) => {
237
+ const t = d.getElementById("t");
238
+ t.content.querySelector("p").attachShadow({ mode: "open" }).append("ombre");
239
+ }
240
+ },
241
+ {
242
+ name: "shadow DOM attach\xE9, \xE9l\xE9ment cr\xE9\xE9 par innerHTML",
243
+ group: "mutations",
244
+ html: D('<div id="a"></div>'),
245
+ run: async (_d, _w, wait) => {
246
+ const a = _d.getElementById("a");
247
+ a.innerHTML = "<p><span>6</span></p>";
248
+ await wait(80);
249
+ a.querySelector("span").attachShadow({ mode: "open" }).append("ombre");
250
+ }
251
+ },
252
+ {
253
+ name: "accesseurs du DOM d\xE9tourn\xE9s par la page",
254
+ group: "robustesse",
255
+ html: D('<ul id="u"><li>un</li></ul>'),
256
+ before: (d, w) => {
257
+ const P2 = w.Node.prototype;
258
+ const desc = Object.getOwnPropertyDescriptor(P2, "firstChild");
259
+ Object.defineProperty(P2, "firstChild", { configurable: true, get() {
260
+ return desc.get?.call(this);
261
+ } });
262
+ },
263
+ run: async (d, w, wait) => {
264
+ const li = d.createElement("li");
265
+ li.textContent = "deux";
266
+ d.getElementById("u").append(li);
267
+ await wait(120);
268
+ const first = d.getElementById("u").firstElementChild;
269
+ if (!(first instanceof w.HTMLElement) || !(li instanceof w.HTMLElement)) throw new Error("prototypes \xE9trangers");
270
+ }
271
+ },
272
+ {
273
+ name: "<template>",
274
+ group: "nouveaux",
275
+ html: D('<template id="t"><b>mod\xE8le</b><p>x</p></template><div id="a"></div>'),
276
+ run: (d) => {
277
+ const t = d.getElementById("t");
278
+ t.content.querySelector("b").textContent = "chang\xE9";
279
+ t.content.append(d.createElement("hr"));
280
+ d.getElementById("a").innerHTML = '<template id="t2"><i>nouveau</i></template>';
281
+ }
282
+ },
283
+ {
284
+ name: "<select> chang\xE9 par script",
285
+ group: "nouveaux",
286
+ o: { mask: "none" },
287
+ html: D(
288
+ '<select id="s1"><option>a<option selected>b<option>c</select><select id="s2" multiple><option>x<option>y<option>z</select><select id="s3"><option>p<option>q</select>'
289
+ ),
290
+ run: (d) => {
291
+ d.getElementById("s1").value = "c";
292
+ const s2 = d.getElementById("s2");
293
+ s2.options[0].selected = true;
294
+ s2.options[2].selected = true;
295
+ d.getElementById("s3").options[1].defaultSelected = true;
296
+ }
297
+ },
298
+ {
299
+ name: "<select> masqu\xE9",
300
+ group: "masquage",
301
+ html: D('<select id="s1"><option>a<option selected>b<option>c</select>'),
302
+ run: (d) => {
303
+ d.getElementById("s1").value = "c";
304
+ }
305
+ },
306
+ {
307
+ name: ".value chang\xE9 sans \xE9v\xE9nement",
308
+ group: "nouveaux",
309
+ o: { mask: "none" },
310
+ html: D('<input id="i" value="d\xE9part"><input id="c" type="checkbox"><textarea id="t">texte</textarea><input id="r" type="range" min="0" max="10" value="2">'),
311
+ run: (d) => {
312
+ d.getElementById("i").value = "nouveau";
313
+ d.getElementById("c").checked = true;
314
+ d.getElementById("t").value = "autre";
315
+ d.getElementById("r").value = "8";
316
+ }
317
+ },
318
+ {
319
+ name: "valeurs chang\xE9es avant le d\xE9part",
320
+ group: "nouveaux",
321
+ o: { mask: "none" },
322
+ html: D('<input id="i" value="d\xE9part"><input id="c" type="checkbox"><textarea id="t">texte</textarea><select id="s"><option>a<option>b</select>'),
323
+ before: (d) => {
324
+ d.getElementById("i").value = "nouveau";
325
+ d.getElementById("c").checked = true;
326
+ d.getElementById("t").value = "autre";
327
+ d.getElementById("s").value = "b";
328
+ },
329
+ run: (d) => {
330
+ d.body.dataset.x = "1";
331
+ }
332
+ },
333
+ {
334
+ name: "saisie au clavier, masqu\xE9e",
335
+ group: "masquage",
336
+ html: D('<input id="i"><textarea id="t"></textarea><input id="c" type="checkbox"><select id="s"><option>a<option>b</select>'),
337
+ keys: [
338
+ ["#i", "Bonjour Camille"],
339
+ ["#t", "ligne\nsuite"]
340
+ ],
341
+ clicks: ["#c"],
342
+ select: [["#s", "b"]],
343
+ secrets: ["Bonjour", "Camille", "suite"]
344
+ },
345
+ {
346
+ name: "saisie au clavier, en clair",
347
+ group: "nouveaux",
348
+ o: { mask: "none" },
349
+ html: D('<input id="i"><textarea id="t"></textarea><input id="c" type="checkbox"><select id="s"><option>a<option>b</select>'),
350
+ keys: [
351
+ ["#i", "Bonjour"],
352
+ ["#t", "ligne\nsuite"]
353
+ ],
354
+ clicks: ["#c"],
355
+ select: [["#s", "b"]]
356
+ },
357
+ {
358
+ name: "mot de passe, carte, champ cach\xE9",
359
+ group: "masquage",
360
+ o: { mask: "none" },
361
+ html: D(
362
+ '<form><input id="p" type="password"><input id="cc" autocomplete="cc-number"><input type="hidden" name="csrf" value="jeton-secret-123"><input id="u" value="visible"></form>'
363
+ ),
364
+ keys: [
365
+ ["#p", "motdepasse42"],
366
+ ["#cc", "4970101010101010"]
367
+ ],
368
+ secrets: ["motdepasse42", "4970101010101010", "jeton-secret-123"]
369
+ },
370
+ {
371
+ name: "champ autoris\xE9 en clair",
372
+ group: "masquage",
373
+ html: D('<div data-va-unmask><input id="q" placeholder="Rechercher"></div><input id="n">'),
374
+ keys: [
375
+ ["#q", "taille de haie"],
376
+ ["#n", "Dupont"]
377
+ ],
378
+ secrets: ["Dupont"]
379
+ },
380
+ {
381
+ name: "zone masqu\xE9e : texte et attributs",
382
+ group: "masquage",
383
+ html: D(
384
+ '<section data-va-mask><h2 title="Jeanne Martin">Jeanne Martin</h2><img alt="Photo de Jeanne" src="a.png"><p aria-label="adresse">12 rue des Lilas</p></section><p id="z">public</p>'
385
+ ),
386
+ run: (d) => {
387
+ d.querySelector("h2").setAttribute("data-client", "Jeanne Martin");
388
+ d.getElementById("z").textContent = "toujours public";
389
+ },
390
+ secrets: ["Jeanne", "Martin", "Lilas", "Photo"]
391
+ },
392
+ {
393
+ name: "tout le texte masqu\xE9",
394
+ group: "masquage",
395
+ o: { mask: "text" },
396
+ html: D('<h1>Bonjour Camille</h1><p id="p">Votre devis</p>'),
397
+ run: (d) => {
398
+ d.getElementById("p").textContent = "Votre devis est pr\xEAt";
399
+ },
400
+ secrets: ["Camille", "devis"]
401
+ },
402
+ {
403
+ name: "bloqu\xE9 apr\xE8s coup",
404
+ group: "masquage",
405
+ html: D('<div id="x"><p>avant</p></div><p id="z">z</p>'),
406
+ run: async (d, _w, wait) => {
407
+ const x = d.getElementById("x");
408
+ x.setAttribute("data-va-block", "");
409
+ await wait(80);
410
+ x.setAttribute("title", "Secret Durand");
411
+ x.firstElementChild.textContent = "Secret Durand";
412
+ },
413
+ secrets: ["Durand"]
414
+ },
415
+ {
416
+ // The fuzzer's WebKit seed 2, round 50, reduced: the zone change and the move arrive in the
417
+ // same batch, and forgetting the zone took the moved node along.
418
+ name: "bloqu\xE9, puis un n\u0153ud y entre",
419
+ group: "masquage",
420
+ html: D('<div id="a"><b>gras</b><i>reste</i></div><div id="x"><p>avant</p></div>'),
421
+ run: (d) => {
422
+ const x = d.getElementById("x");
423
+ x.setAttribute("data-va-block", "");
424
+ x.append(d.querySelector("b"));
425
+ }
426
+ },
427
+ {
428
+ // The fuzzer's seed 16, round 22, reduced: a field changed by script keeps its value when
429
+ // its default goes; a copy that only got the attribute loses it.
430
+ name: "champ chang\xE9 par script, puis son attribut retir\xE9",
431
+ group: "mutations",
432
+ html: D('<input id="f" value="haie"><input id="c" type="checkbox" checked>'),
433
+ run: async (d, _w, wait) => {
434
+ const f = d.getElementById("f");
435
+ const c = d.getElementById("c");
436
+ f.value = "haie";
437
+ c.checked = true;
438
+ await wait(80);
439
+ f.removeAttribute("value");
440
+ c.removeAttribute("checked");
441
+ },
442
+ o: { mask: "none" }
443
+ },
444
+ {
445
+ name: "<select> : l'attribut selected retir\xE9, puis vid\xE9 par script",
446
+ group: "mutations",
447
+ html: D('<div id="a"></div>'),
448
+ run: async (d, _w, wait) => {
449
+ d.getElementById("a").innerHTML = '<select id="s"><option>taille</option><option id="o" selected>serre</option></select>';
450
+ await wait(80);
451
+ d.getElementById("o").removeAttribute("selected");
452
+ d.getElementById("s").selectedIndex = -1;
453
+ },
454
+ o: { mask: "none" }
455
+ },
456
+ {
457
+ name: "d\xE9bloqu\xE9 apr\xE8s coup",
458
+ group: "masquage",
459
+ html: D('<div id="x" data-va-block><p>cach\xE9</p></div>'),
460
+ run: (d) => {
461
+ d.getElementById("x").removeAttribute("data-va-block");
462
+ }
463
+ },
464
+ {
465
+ name: "<dialog open> dans le HTML",
466
+ group: "nouveaux",
467
+ html: D('<dialog id="d1" open><p>ouvert</p></dialog><p id="p">x</p>'),
468
+ run: (d) => {
469
+ d.getElementById("p").textContent = "y";
470
+ }
471
+ },
472
+ {
473
+ name: "dialog.showModal()",
474
+ group: "nouveaux",
475
+ html: D('<dialog id="d2"><p>modale</p></dialog>'),
476
+ run: (d) => {
477
+ d.getElementById("d2").showModal();
478
+ }
479
+ },
480
+ {
481
+ name: "attributs : guillemets, caract\xE8res de contr\xF4le",
482
+ group: "nouveaux",
483
+ html: D(`<div id="a" title='il a dit "oui" &amp; &lt;b&gt;' data-q="l'apostrophe" @click="go" :class="k" x.y="1"></div><p id="p">a</p>`),
484
+ run: (d) => {
485
+ const a = d.getElementById("a");
486
+ a.setAttribute("data-x", `a"b'c<d>&e\x07
487
+ \v f`);
488
+ a.setAttribute("data-cr", "x\r\ny\rz");
489
+ a.setAttribute("data-nul", "a\0b");
490
+ d.getElementById("p").textContent = "texte\r\nretour\0nul\x07";
491
+ }
492
+ },
493
+ {
494
+ name: "champs nomm\xE9s localName et hasAttribute",
495
+ group: "nouveaux",
496
+ html: D('<form id="f"><input name="localName" value="x"><input name="hasAttribute"><input name="attributes"></form><p id="p">a</p>'),
497
+ run: (d) => {
498
+ d.getElementById("p").textContent = "b";
499
+ d.getElementById("f").setAttribute("data-k", "1");
500
+ }
501
+ },
502
+ {
503
+ name: "\xE9l\xE9ments personnalis\xE9s",
504
+ group: "nouveaux",
505
+ html: D('<x-carte id="c" titre="Bonjour"></x-carte><p>p</p>'),
506
+ run: async (d, w, wait) => {
507
+ w.customElements.define(
508
+ "x-carte",
509
+ class extends w.HTMLElement {
510
+ connectedCallback() {
511
+ if (this.shadowRoot) return;
512
+ const r = this.attachShadow({ mode: "open" });
513
+ r.innerHTML = `<h3>${this.getAttribute("titre")}</h3><slot></slot>`;
514
+ this.innerHTML = "<p>lumi\xE8re</p>";
515
+ }
516
+ }
517
+ );
518
+ await wait(40);
519
+ const e = d.createElement("x-carte");
520
+ e.setAttribute("titre", "second");
521
+ d.body.append(e);
522
+ }
523
+ },
524
+ {
525
+ name: "contenteditable, en clair",
526
+ group: "contenteditable",
527
+ o: { mask: "none" },
528
+ html: D('<div id="e" contenteditable="true"><p>d\xE9but</p></div>'),
529
+ keys: [["#e", " tap\xE9\nligne deux"]]
530
+ },
531
+ {
532
+ name: "contenteditable, masqu\xE9 par d\xE9faut",
533
+ group: "contenteditable",
534
+ html: D('<div id="e" contenteditable="true"><p>d\xE9but</p></div><p id="z">z</p>'),
535
+ keys: [["#e", " Dupont"]],
536
+ after: (d) => {
537
+ d.getElementById("z").textContent = "apr\xE8s la saisie";
538
+ },
539
+ secrets: ["Dupont"]
540
+ },
541
+ {
542
+ name: "contenteditable : gras, liste, collage",
543
+ group: "contenteditable",
544
+ html: D('<div id="e" contenteditable="true"><p>Bonjour</p></div>'),
545
+ run: async (d, _w, wait) => {
546
+ const e = d.getElementById("e");
547
+ const b = d.createElement("b");
548
+ b.textContent = "important";
549
+ e.firstElementChild.append(" ", b);
550
+ await wait(60);
551
+ e.insertAdjacentHTML("beforeend", "<ul><li>un</li><li>deux</li></ul>");
552
+ await wait(60);
553
+ e.querySelector("li").remove();
554
+ }
555
+ },
556
+ {
557
+ name: "contenteditable, champ autoris\xE9",
558
+ group: "contenteditable",
559
+ html: D('<div id="e" contenteditable="true" data-va-unmask><p>d\xE9but</p></div>'),
560
+ keys: [["#e", " visible"]]
561
+ },
562
+ {
563
+ name: "srcset et <picture>",
564
+ group: "nouveaux",
565
+ html: D('<picture id="pi"><source srcset="a.webp 1x, b.webp 2x" type="image/webp"><img id="im" src="c.png" srcset="c.png 1x, d.png 2x" alt=""></picture>'),
566
+ run: (d) => {
567
+ const im = d.getElementById("im");
568
+ im.srcset = "e.png 1x, f.png 3x";
569
+ im.sizes = "50vw";
570
+ const s = d.createElement("source");
571
+ s.srcset = "g.avif";
572
+ s.type = "image/avif";
573
+ d.getElementById("pi")?.prepend(s);
574
+ }
575
+ },
576
+ {
577
+ name: "<noscript>",
578
+ group: "nouveaux",
579
+ html: D('<noscript><p id="n">Activez JavaScript</p></noscript><p>apr\xE8s</p>', "<noscript><style>body{background:red}</style></noscript>"),
580
+ run: (d) => {
581
+ const n = d.createElement("noscript");
582
+ n.innerHTML = "<b>vu sans script</b>";
583
+ d.body.append(n);
584
+ }
585
+ },
586
+ {
587
+ name: "document en mode quirks",
588
+ group: "nouveaux",
589
+ html: '<html><head><title>q</title></head><body><table id="t"><tr><td>quirks</td></tr></table><p id="p">x</p></body></html>',
590
+ run: (d) => {
591
+ d.getElementById("p").textContent = "y";
592
+ }
593
+ },
594
+ {
595
+ name: "liens javascript: d\xE9sarm\xE9s",
596
+ group: "nouveaux",
597
+ html: D('<a id="a" href="javascript:alert(1)" onclick="alert(2)" target="_top">x</a>'),
598
+ run: (d) => {
599
+ d.getElementById("a").setAttribute("href", "javascript:alert(3)");
600
+ }
601
+ },
602
+ {
603
+ name: "CSSOM insertRule",
604
+ group: "styles",
605
+ html: D('<p class="a">a</p><p class="b">b</p>', '<style id="s">.a{color:red}</style>'),
606
+ run: async (d, _w, wait) => {
607
+ d.getElementById("s").sheet.insertRule(".b { color: blue; }", 1);
608
+ const e = d.createElement("style");
609
+ d.head.append(e);
610
+ e.sheet.insertRule(".a { font-weight: 700; }");
611
+ await wait(200);
612
+ d.getElementById("s").sheet.deleteRule(0);
613
+ }
614
+ },
615
+ {
616
+ name: "adoptedStyleSheets",
617
+ group: "styles",
618
+ html: D('<p class="a">a</p><div id="h"></div>'),
619
+ run: async (d, w, wait) => {
620
+ const s1 = new w.CSSStyleSheet();
621
+ s1.replaceSync(".a { color: green; }");
622
+ d.adoptedStyleSheets = [s1];
623
+ const r = d.getElementById("h").attachShadow({ mode: "open" });
624
+ const s2 = new w.CSSStyleSheet();
625
+ s2.replaceSync("b { color: red; }");
626
+ r.adoptedStyleSheets = [s2];
627
+ r.innerHTML = "<b>ombre</b>";
628
+ await wait(60);
629
+ s1.insertRule(".a { color: blue; }", 1);
630
+ }
631
+ },
632
+ {
633
+ name: "CSS-in-JS au d\xE9part",
634
+ group: "styles",
635
+ html: D('<p class="a">a</p>', '<style id="s"></style>'),
636
+ before: (d) => {
637
+ d.getElementById("s").sheet.insertRule(".a { color: purple; }");
638
+ }
639
+ }
640
+ ];
641
+
642
+ // src/testing/oracle.ts
643
+ var HTML = "http://www.w3.org/1999/xhtml";
644
+ var VOID = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
645
+ var URL_ATTR = /^(src|href|poster|action|formaction|data|xlink:href|cite|background)$/;
646
+ var SAFE_URL = /^(https?:|data:image\/|blob:|#|mailto:|tel:)/i;
647
+ var CSS_URL = /url\(\s*(['"]?)(?!data:|#|blob:)([^'")]+)\1\s*\)/g;
648
+ var PLAIN = /^(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;
649
+ var NOT_TYPED = /^(button|submit|reset|image)$/;
650
+ var TOGGLE = /^(checkbox|radio)$/;
651
+ var STARS = "******";
652
+ var stars = (s) => s.replace(/\S/g, "*");
653
+ var P = Element.prototype;
654
+ var hasA = (el, n) => P.hasAttribute.call(el, n);
655
+ var getA = (el, n) => P.getAttribute.call(el, n);
656
+ var getter = (name) => Object.getOwnPropertyDescriptor(P, name)?.get;
657
+ var LOCAL = getter("localName");
658
+ var NS = getter("namespaceURI");
659
+ var ATTRS = getter("attributes");
660
+ var tagOf = (el) => LOCAL.call(el);
661
+ var nsOf = (el) => NS.call(el);
662
+ var attrsOf = (el) => ATTRS.call(el);
663
+ var short = (v) => {
664
+ const s = typeof v === "string" ? v : JSON.stringify(v);
665
+ return s && s.length > 160 ? `${s.slice(0, 160)}\u2026` : s;
666
+ };
667
+ function compare(live, copy, o = {}) {
668
+ const mode = o.mask || "inputs";
669
+ const maskAttr = o.maskAttr || "data-va-mask";
670
+ const blockAttr = o.blockAttr || "data-va-block";
671
+ const unmaskAttr = o.unmaskAttr || "data-va-unmask";
672
+ const diffs = [];
673
+ const max = o.max || 6;
674
+ const base = live.URL;
675
+ let around;
676
+ const html = (n) => {
677
+ const s = n.nodeType === 1 ? n.outerHTML : n.nodeType === 11 ? `#root ${n.innerHTML ?? ""}` : String(n.textContent);
678
+ return s.length > 400 ? `${s.slice(0, 400)}\u2026` : s;
679
+ };
680
+ const add = (path2, what, a, b) => {
681
+ if (diffs.length < max) diffs.push({ path: path2, what, live: short(a), copy: short(b), ...around ? { around } : {} });
682
+ };
683
+ const abs = (u) => {
684
+ try {
685
+ return new URL(u, base).href;
686
+ } catch {
687
+ return u;
688
+ }
689
+ };
690
+ const cssAbs = (t) => t.replace(CSS_URL, (_m, _q, u) => `url("${abs(u)}")`);
691
+ const rules = (sheet) => {
692
+ try {
693
+ return Array.from(sheet.cssRules, (r) => r.cssText).join("\n");
694
+ } catch {
695
+ return "<illisible>";
696
+ }
697
+ };
698
+ const adopted = (root, live2) => Array.from(root.adoptedStyleSheets || [], (s) => live2 ? cssAbs(rules(s)) : rules(s)).join(
699
+ "\n---\n"
700
+ );
701
+ const sensitive = (el) => /^(password|hidden)$/i.test(el.type || "") || /cc-|one-time-code|password/i.test(getA(el, "autocomplete") || "");
702
+ const fieldHidden = (el, masked, clear) => {
703
+ if (sensitive(el)) return true;
704
+ if (mode === "none") return masked;
705
+ return !clear;
706
+ };
707
+ const shown = (v, hidden) => hidden ? v ? STARS : "" : v;
708
+ const masksSelf = (el) => {
709
+ if (hasA(el, maskAttr)) return true;
710
+ if (mode === "none") return false;
711
+ const e = getA(el, "contenteditable");
712
+ return e !== null && e.toLowerCase() !== "false" && !hasA(el, unmaskAttr);
713
+ };
714
+ function path(n) {
715
+ const p = [];
716
+ for (let x = n; x && x.nodeType === 1; x = x.parentNode || x.host || null) {
717
+ const el = x;
718
+ p.unshift(tagOf(el) + (el.id ? `#${el.id}` : ""));
719
+ }
720
+ return p.join(">");
721
+ }
722
+ function kids(n) {
723
+ const out = [];
724
+ const el = n;
725
+ const list2 = n.nodeType === 1 && tagOf(el) === "template" && nsOf(el) === HTML ? el.content.childNodes : n.childNodes;
726
+ for (const c of Array.from(list2)) {
727
+ if (c.nodeType === 3) {
728
+ const data = c.data;
729
+ if (!data) continue;
730
+ const last = out[out.length - 1];
731
+ if (last && last.nodeType === 3) last.data += data;
732
+ else out.push({ nodeType: 3, data });
733
+ } else if (c.nodeType === 1) {
734
+ const e = c;
735
+ const tag = tagOf(e);
736
+ if (tag === "script" || tag === "replay-script" || tag === "base" || tag === "replay-base") continue;
737
+ if (tag === "noscript" && nsOf(e) === HTML) continue;
738
+ out.push(e);
739
+ }
740
+ }
741
+ return out;
742
+ }
743
+ function attrs(el, side, masked) {
744
+ const m = /* @__PURE__ */ new Map();
745
+ const tag = tagOf(el);
746
+ for (const a of Array.from(attrsOf(el))) {
747
+ const name = a.name;
748
+ let v = a.value;
749
+ if (/^on/i.test(name) || name === "http-equiv") continue;
750
+ if (tag === "iframe" && /^(src|srcdoc)$/.test(name)) continue;
751
+ if (tag === "a" && name === "target") continue;
752
+ if (tag === "input" && (name === "value" || name === "checked")) continue;
753
+ if (tag === "textarea" && name === "value") continue;
754
+ if (tag === "option" && name === "selected") continue;
755
+ if (tag === "link" && name === "href" && /stylesheet/i.test(getA(el, "rel") || "") && (side === "copy" ? v.startsWith("blob:") : true))
756
+ continue;
757
+ if (side === "live" && masked && !PLAIN.test(name)) v = stars(v);
758
+ if (URL_ATTR.test(name)) {
759
+ v = abs(v);
760
+ if (side === "live" && !SAFE_URL.test(v)) v = "about:blank";
761
+ } else if (name === "srcset")
762
+ v = v.split(",").map((p) => {
763
+ const [u, ...s] = p.trim().split(/\s+/);
764
+ return [abs(u || ""), ...s].join(" ");
765
+ }).join(", ");
766
+ else if (name === "style" && side === "live") v = cssAbs(v);
767
+ m.set(name, v);
768
+ }
769
+ return m;
770
+ }
771
+ function state(L, R, p, masked, clear) {
772
+ const tag = tagOf(L);
773
+ if (tag === "input") {
774
+ const t = String(L.type);
775
+ if (t !== "file" && t !== "hidden" && !NOT_TYPED.test(t) && !TOGGLE.test(t)) {
776
+ const want = shown(L.value, fieldHidden(L, masked, clear));
777
+ if (want !== R.value) add(p, "input.value", want, R.value);
778
+ }
779
+ if (L.checked !== R.checked) add(p, "input.checked", L.checked, R.checked);
780
+ } else if (tag === "textarea") {
781
+ const want = shown(L.value, fieldHidden(L, masked, clear));
782
+ if (want !== R.value) add(p, "textarea.value", want, R.value);
783
+ } else if (tag === "select") {
784
+ const picked = (s) => Array.from(s.options, (x, i) => x.selected ? i : -1).filter((i) => i >= 0).join(",");
785
+ let want = picked(L);
786
+ if (fieldHidden(L, masked, clear)) {
787
+ const options = Array.from(L.options);
788
+ if (L.multiple || L.size > 1) want = options.map((x, i) => hasA(x, "selected") ? i : -1).filter((i) => i >= 0).join(",");
789
+ else {
790
+ let k = -1;
791
+ options.forEach((x, i) => {
792
+ if (hasA(x, "selected")) k = i;
793
+ });
794
+ if (k < 0) k = options.findIndex((x) => !x.disabled);
795
+ want = k < 0 ? "" : String(k);
796
+ }
797
+ }
798
+ if (want !== picked(R)) add(p, "select: options choisies", want, picked(R));
799
+ } else if (tag === "dialog") {
800
+ const modal = (d) => {
801
+ try {
802
+ return d.matches(":modal");
803
+ } catch {
804
+ return null;
805
+ }
806
+ };
807
+ if (modal(L) !== modal(R)) add(p, "dialog :modal", modal(L), modal(R));
808
+ if (L.open !== R.open) add(p, "dialog.open", L.open, R.open);
809
+ }
810
+ }
811
+ function element(L, R, masked, clear) {
812
+ around = [html(L), html(R)];
813
+ const p = path(L);
814
+ const name = (e) => `${nsOf(e) === HTML ? "" : `${nsOf(e)} `}<${tagOf(e)}>`;
815
+ if (nsOf(L) !== nsOf(R) || tagOf(L) !== tagOf(R)) {
816
+ add(p, "\xE9l\xE9ment", name(L), name(R));
817
+ return;
818
+ }
819
+ if (hasA(L, blockAttr)) {
820
+ if (!hasA(R, "data-replay-blocked")) add(p, "\xE9l\xE9ment bloqu\xE9 rejou\xE9", "(bo\xEEte)", R.outerHTML);
821
+ return;
822
+ }
823
+ masked = masked || masksSelf(L);
824
+ clear = clear || hasA(L, unmaskAttr);
825
+ const a = attrs(L, "live", masked);
826
+ const b = attrs(R, "copy", masked);
827
+ for (const [k, v] of a) if (b.get(k) !== v) add(p, `@${k}`, v, b.has(k) ? b.get(k) : "(absent)");
828
+ for (const [k, v] of b) if (!a.has(k)) add(p, `@${k}`, "(absent)", v);
829
+ if (nsOf(L) === HTML) state(L, R, p, masked, clear);
830
+ if (tagOf(L) === "style") {
831
+ const x = L.sheet ? cssAbs(rules(L.sheet)) : L.textContent;
832
+ const y = R.sheet ? rules(R.sheet) : R.textContent;
833
+ if (x !== y) add(p, "r\xE8gles CSS", x, y);
834
+ return;
835
+ }
836
+ if (tagOf(L) === "textarea") return;
837
+ if (nsOf(L) === HTML && VOID.test(tagOf(L))) return;
838
+ const ls = L.shadowRoot;
839
+ const rs = R.shadowRoot;
840
+ if (ls) {
841
+ if (!rs) add(p, "shadow root", true, false);
842
+ else {
843
+ list(ls, rs, `${p}/#shadow`, masked, clear);
844
+ if (adopted(ls, true) !== adopted(rs, false))
845
+ add(`${p}/#shadow`, "adoptedStyleSheets", adopted(ls, true), adopted(rs, false));
846
+ }
847
+ }
848
+ list(L, R, p, masked, clear);
849
+ }
850
+ function list(L, R, p, masked, clear) {
851
+ around = [html(L), html(R)];
852
+ const x = kids(L);
853
+ const y = kids(R);
854
+ const n = Math.max(x.length, y.length);
855
+ const show = (k) => !k ? "" : k.nodeType === 3 ? k.data : `<${k.localName}>`;
856
+ for (let i = 0; i < n && diffs.length < max; i++) {
857
+ const a = x[i];
858
+ const b = y[i];
859
+ if (!a || !b) {
860
+ add(`${p}[${i}]`, a ? "n\u0153ud absent de la copie" : "n\u0153ud en trop dans la copie", show(a), show(b));
861
+ break;
862
+ }
863
+ if (a.nodeType !== b.nodeType) {
864
+ add(`${p}[${i}]`, "type de n\u0153ud", show(a), show(b));
865
+ break;
866
+ }
867
+ if (a.nodeType === 3) {
868
+ const parent = L.nodeType === 1 ? L.localName : "";
869
+ const data = a.data;
870
+ const want = parent === "style" ? cssAbs(data) : masked ? stars(data) : data;
871
+ if (want !== b.data) add(`${p}[${i}]`, "texte", want, b.data);
872
+ } else element(a, b, masked, clear);
873
+ }
874
+ }
875
+ if (!o.ignoreMode && live.compatMode !== copy.compatMode)
876
+ add("#document", "compatMode", live.compatMode, copy.compatMode);
877
+ const dt = (d) => d.doctype ? d.doctype.name : null;
878
+ if (dt(live) !== dt(copy)) add("#document", "doctype", dt(live), dt(copy));
879
+ if (adopted(live, true) !== adopted(copy, false))
880
+ add("#document", "adoptedStyleSheets", adopted(live, true), adopted(copy, false));
881
+ if (!copy.documentElement) add("#document", "documentElement", "<html>", null);
882
+ else if (live.documentElement) element(live.documentElement, copy.documentElement, mode === "text", false);
883
+ return diffs;
884
+ }
885
+
886
+ // src/testing/fuzz.ts
887
+ function seeded(seed) {
888
+ let s = seed * 2654435761 | 0;
889
+ const rnd = () => {
890
+ s = s + 1831565813 | 0;
891
+ let t = Math.imul(s ^ s >>> 15, 1 | s);
892
+ t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
893
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
894
+ };
895
+ return rnd;
896
+ }
897
+ var FUZZ_PAGE = `<!DOCTYPE html><html lang="fr"><head><meta charset="utf-8"><title>Jardins de Belleroche</title>
898
+ <style>.carte{border:1px solid #ccc}.x{color:#333}</style></head><body>
899
+ <header><nav><a href="/">Accueil</a> <a href="/services">Services</a> <a href="/contact">Contact</a></nav><h1>Jardins de Belleroche</h1></header>
900
+ <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\xE9ation de massifs</li></ul></section>
901
+ <section id="avis"><h2>Avis</h2><blockquote>Travail soign\xE9 <b>et rapide</b>.</blockquote><blockquote data-va-mask>Client : Paul L\xE9ger</blockquote></section>
902
+ <section id="devis"><h2>Demander un devis</h2><form><label>Nom <input name="nom" value=""></label><label>Message <textarea name="message">Bonjour</textarea></label>
903
+ <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>
904
+ <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>
905
+ <template id="modele"><li class="carte">Nouveau service</li></template>
906
+ <div id="editeur" contenteditable="true"><p>Votre message</p></div>
907
+ </main><footer><p>\xA9 Jardins de Belleroche</p></footer></body></html>`;
908
+ var SKIP = { script: 1, noscript: 1, iframe: 1 };
909
+ function mutator(d, rnd) {
910
+ const int = (n) => Math.floor(rnd() * n);
911
+ const pick = (list) => list[int(list.length)];
912
+ const blocked = (n) => n.nodeType === 1 && n.hasAttribute("data-va-block");
913
+ function elements() {
914
+ const out = [];
915
+ const walk = (n) => {
916
+ for (const c of Array.from(n.children)) {
917
+ if (SKIP[c.localName]) continue;
918
+ out.push(c);
919
+ if (!blocked(c)) {
920
+ walk(c);
921
+ if (c.shadowRoot) walk(c.shadowRoot);
922
+ if (c.localName === "template") walk(c.content);
923
+ }
924
+ }
925
+ };
926
+ walk(d.body);
927
+ walk(d.head);
928
+ return out;
929
+ }
930
+ const textNodes = (el) => Array.from(el.childNodes).filter((c) => c.nodeType === 3);
931
+ const word = () => pick(["haie", "tonte", "massif", "potager", "all\xE9e", "bassin", "serre", " ", "\n ", "\xE9t\xE9 & hiver", "<b>", ""]);
932
+ const TAGS = ["div", "p", "span", "ul", "li", "b", "section", "em", "a", "button", "table", "tr", "td", "input", "textarea", "select"];
933
+ function make(depth = 0) {
934
+ const kind = rnd();
935
+ if (kind < 0.25) return d.createTextNode(word());
936
+ if (kind < 0.3) return d.createComment(word());
937
+ if (kind < 0.33) {
938
+ const sc = d.createElement("script");
939
+ sc.type = "text/plain";
940
+ sc.textContent = "x";
941
+ return sc;
942
+ }
943
+ if (kind < 0.38) {
944
+ const svg = d.createElementNS("http://www.w3.org/2000/svg", "svg");
945
+ const c = d.createElementNS("http://www.w3.org/2000/svg", "circle");
946
+ c.setAttribute("r", String(int(9)));
947
+ svg.append(c);
948
+ if (rnd() < 0.5) {
949
+ const fo = d.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
950
+ fo.append(d.createElement("div"));
951
+ svg.append(fo);
952
+ }
953
+ return svg;
954
+ }
955
+ if (kind < 0.4) {
956
+ const t = d.createElement("template");
957
+ t.content.append(make(depth + 1));
958
+ return t;
959
+ }
960
+ const el = d.createElement(pick(TAGS));
961
+ if (el.localName === "select") {
962
+ for (let i = 1 + int(3); i > 0; i--) {
963
+ const o = d.createElement("option");
964
+ o.textContent = word();
965
+ if (rnd() < 0.3) o.setAttribute("selected", "");
966
+ el.append(o);
967
+ }
968
+ return el;
969
+ }
970
+ if (el.localName === "input" || el.localName === "textarea") {
971
+ if (rnd() < 0.5) el.setAttribute("value", word());
972
+ if (rnd() < 0.3) el.setAttribute("type", pick(["text", "checkbox", "password", "email"]));
973
+ return el;
974
+ }
975
+ if (rnd() < 0.6)
976
+ el.setAttribute(pick(["class", "id", "title", "data-k", "style", "hidden", "alt"]), pick(["a", "b c", "color:red", ""]));
977
+ if (rnd() < 0.06) el.setAttribute("data-va-block", "");
978
+ if (rnd() < 0.06) el.setAttribute("data-va-mask", "");
979
+ if (rnd() < 0.04) el.setAttribute("contenteditable", "true");
980
+ if (rnd() < 0.08 && /^(div|p|span|section)$/.test(el.localName)) {
981
+ const root = el.attachShadow({ mode: "open" });
982
+ root.append(make(depth + 1));
983
+ }
984
+ if (depth < 3) for (let i = int(4); i > 0; i--) el.append(make(depth + 1));
985
+ return el;
986
+ }
987
+ const w = d.defaultView;
988
+ const pause = async () => {
989
+ const r = rnd();
990
+ if (r < 0.25) await Promise.resolve();
991
+ else if (r < 0.35) await new Promise((f) => w.setTimeout(f, 0));
992
+ else if (r < 0.37) await new Promise((f) => w.setTimeout(f, 70));
993
+ };
994
+ const shadowHost = (n) => n.getRootNode({ composed: false }).host;
995
+ async function mutate() {
996
+ const all = elements();
997
+ if (!all.length) return;
998
+ const el = pick(all);
999
+ const other = pick(all);
1000
+ const safe = (target, node) => !node.contains(target) && !node.shadowRoot?.contains(target) && node !== d.body && node !== d.head && !shadowHost(target) && node.isConnected;
1001
+ const op = int(26);
1002
+ log.push(`${op}:${el.localName}${el.id ? `#${el.id}` : ""}\u2192${other.localName}`);
1003
+ const fieldsOnly = /^(select|option|optgroup)$/.test(el.localName);
1004
+ if (fieldsOnly && op !== 2 && op !== 4 && op !== 5 && op !== 20 && op !== 21 && op !== 22) return;
1005
+ if (/^(style|title|textarea)$/.test(el.localName) && op !== 2 && op !== 4 && op !== 5 && op !== 6 && op !== 14 && op !== 20 && op !== 21) return;
1006
+ switch (op) {
1007
+ case 0:
1008
+ el.append(make());
1009
+ break;
1010
+ case 1:
1011
+ el.insertBefore(make(), pick(Array.from(el.childNodes)) || null);
1012
+ break;
1013
+ case 2:
1014
+ if (el !== d.body && el !== d.head) el.remove();
1015
+ break;
1016
+ case 3:
1017
+ if (safe(el, other)) el.insertBefore(other, pick(Array.from(el.childNodes)) || null);
1018
+ break;
1019
+ case 4:
1020
+ el.setAttribute(pick(["class", "title", "data-k", "style", "aria-label", "alt"]), word());
1021
+ break;
1022
+ case 5: {
1023
+ const names = el.getAttributeNames();
1024
+ if (names.length) el.removeAttribute(pick(names));
1025
+ break;
1026
+ }
1027
+ case 6: {
1028
+ const t = pick(textNodes(el));
1029
+ if (t) t.data = word() + int(100);
1030
+ else el.append(word());
1031
+ break;
1032
+ }
1033
+ case 7:
1034
+ 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`;
1035
+ break;
1036
+ case 8: {
1037
+ const list = Array.from(el.childNodes);
1038
+ for (let i = list.length - 1; i > 0; i--) {
1039
+ const j = int(i + 1);
1040
+ [list[i], list[j]] = [list[j], list[i]];
1041
+ }
1042
+ el.replaceChildren(...list);
1043
+ break;
1044
+ }
1045
+ case 9: {
1046
+ const n = make();
1047
+ el.append(n);
1048
+ await pause();
1049
+ if (n.nodeType === 1) {
1050
+ n.setAttribute("data-late", "1");
1051
+ n.append(make());
1052
+ }
1053
+ break;
1054
+ }
1055
+ case 10: {
1056
+ if (el === d.body || el === d.head) break;
1057
+ const parent = el.parentNode;
1058
+ const next = el.nextSibling;
1059
+ el.remove();
1060
+ el.setAttribute("data-away", "1");
1061
+ await Promise.resolve();
1062
+ el.append("changed away");
1063
+ el.firstElementChild?.remove();
1064
+ await pause();
1065
+ if (parent?.isConnected) parent.insertBefore(el, next && next.parentNode === parent ? next : null);
1066
+ break;
1067
+ }
1068
+ case 11:
1069
+ el.insertBefore(d.createComment("c"), el.firstChild);
1070
+ el.insertBefore(make(), el.firstChild);
1071
+ el.append(d.createComment("d"), make());
1072
+ break;
1073
+ case 12: {
1074
+ const t = pick(textNodes(el));
1075
+ if (t && t.data.length > 2) t.splitText(1);
1076
+ else el.normalize();
1077
+ break;
1078
+ }
1079
+ case 13: {
1080
+ if (!safe(el, other)) break;
1081
+ const box = d.createElement("div");
1082
+ box.append(make(), other, make());
1083
+ await pause();
1084
+ el.append(box);
1085
+ if (rnd() < 0.3) {
1086
+ await pause();
1087
+ box.remove();
1088
+ }
1089
+ break;
1090
+ }
1091
+ case 14:
1092
+ el.textContent = rnd() < 0.5 ? "" : word();
1093
+ break;
1094
+ case 15:
1095
+ el.insertAdjacentHTML(pick(["afterbegin", "beforeend"]), `<i>${int(9)}</i>text<u></u>`);
1096
+ break;
1097
+ case 16: {
1098
+ const a = el.firstChild;
1099
+ const b = el.lastChild;
1100
+ if (a && b && a !== b) {
1101
+ el.insertBefore(b, a);
1102
+ el.append(a);
1103
+ }
1104
+ break;
1105
+ }
1106
+ case 17:
1107
+ if (!el.shadowRoot && /^(div|p|span|section)$/.test(el.localName) && !shadowHost(el)) {
1108
+ try {
1109
+ el.attachShadow({ mode: "open" }).append(make(1));
1110
+ } catch {
1111
+ }
1112
+ }
1113
+ break;
1114
+ case 18: {
1115
+ const box = all.find(blocked);
1116
+ if (!box || !safe(box, other) || other === box) break;
1117
+ box.append(other);
1118
+ if (rnd() < 0.5) {
1119
+ await pause();
1120
+ if (safe(el, other)) el.append(other);
1121
+ }
1122
+ break;
1123
+ }
1124
+ case 19: {
1125
+ const kids = Array.from(el.children);
1126
+ const a = pick(kids);
1127
+ const b = pick(kids);
1128
+ if (a && b && a !== b) {
1129
+ const ghost = d.createComment("");
1130
+ a.replaceWith(ghost);
1131
+ b.replaceWith(a);
1132
+ ghost.replaceWith(b);
1133
+ }
1134
+ break;
1135
+ }
1136
+ // What the three generators lacked: zones toggled, fields changed by script, templates.
1137
+ case 20:
1138
+ if (el !== d.body && el !== d.documentElement)
1139
+ el.toggleAttribute(pick(["data-va-block", "data-va-mask", "data-va-unmask"]));
1140
+ break;
1141
+ case 21:
1142
+ if (el !== d.body) el.toggleAttribute("contenteditable");
1143
+ break;
1144
+ case 22: {
1145
+ const field = pick(all.filter((e) => /^(input|textarea|select)$/.test(e.localName)));
1146
+ if (!field) break;
1147
+ if (field.localName === "select") field.selectedIndex = int(field.options.length + 1) - 1;
1148
+ else if (field.type === "checkbox") field.checked = !field.checked;
1149
+ else field.value = word() + int(9);
1150
+ break;
1151
+ }
1152
+ case 23: {
1153
+ const t = pick(all.filter((e) => e.localName === "template"));
1154
+ if (!t) break;
1155
+ if (rnd() < 0.5) t.content.append(make(1));
1156
+ else t.content.firstChild?.remove();
1157
+ break;
1158
+ }
1159
+ case 24: {
1160
+ const t = pick(all.filter((e) => e.localName === "template"));
1161
+ if (t && el !== t && !t.contains(el) && el.isConnected && !blocked(el)) el.append(t.content.cloneNode(true));
1162
+ break;
1163
+ }
1164
+ case 25:
1165
+ if (el !== d.body && el !== d.head && el.localName !== "html") el.replaceWith(make());
1166
+ break;
1167
+ }
1168
+ }
1169
+ const log = [];
1170
+ return {
1171
+ log,
1172
+ async round() {
1173
+ log.length = 0;
1174
+ for (let i = 1 + int(12); i > 0; i--) {
1175
+ try {
1176
+ await mutate();
1177
+ } catch (e) {
1178
+ if (e.name !== "HierarchyRequestError" && e.name !== "NotSupportedError") throw e;
1179
+ }
1180
+ await pause();
1181
+ }
1182
+ }
1183
+ };
1184
+ }
1185
+
1186
+ // src/testing/index.ts
1187
+ function leaks(sent, secrets) {
1188
+ return secrets.filter((s) => sent.some((body) => body.includes(s)));
1189
+ }
1190
+ export {
1191
+ CASES,
1192
+ FUZZ_PAGE,
1193
+ compare,
1194
+ leaks,
1195
+ mutator,
1196
+ seeded
1197
+ };