@voila.dev/replay 0.2.0 → 0.3.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/dist/format/index.d.ts +3 -1
- package/dist/format.js +1 -1
- package/dist/modules.js +1 -1
- package/dist/play.js +13 -1
- package/dist/record.js +21 -1
- package/dist/shared/{chunk-6US53Q3A.js → chunk-3B3R4DHO.js} +1 -0
- package/dist/testing.js +5 -0
- package/package.json +1 -1
- package/src/format/index.ts +2 -0
- package/src/play/mirror.ts +12 -0
- package/src/record/index.ts +26 -0
- package/src/testing/oracle.ts +12 -0
package/dist/format/index.d.ts
CHANGED
|
@@ -59,7 +59,9 @@ export declare enum Op {
|
|
|
59
59
|
/** framed: id, a canvas as a data URL */
|
|
60
60
|
SHOT = 128,
|
|
61
61
|
/** framed: the name of a module cut off after it threw */
|
|
62
|
-
ERR = 129
|
|
62
|
+
ERR = 129,
|
|
63
|
+
/** framed: id, the address of the picture an image shows, picked from its `srcset` or its `<picture>` */
|
|
64
|
+
SHOWN = 130
|
|
63
65
|
}
|
|
64
66
|
export declare enum End {
|
|
65
67
|
Consent = 1,
|
package/dist/format.js
CHANGED
package/dist/modules.js
CHANGED
package/dist/play.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
fnv,
|
|
4
4
|
join,
|
|
5
5
|
length
|
|
6
|
-
} from "./shared/chunk-
|
|
6
|
+
} from "./shared/chunk-3B3R4DHO.js";
|
|
7
7
|
|
|
8
8
|
// src/play/mirror.ts
|
|
9
9
|
var SVG = "http://www.w3.org/2000/svg";
|
|
@@ -409,6 +409,18 @@ function mirror(doc, hooks = {}) {
|
|
|
409
409
|
image.src = shot;
|
|
410
410
|
break;
|
|
411
411
|
}
|
|
412
|
+
case 130 /* SHOWN */: {
|
|
413
|
+
const el = nodes[a(2)];
|
|
414
|
+
const src = a(3);
|
|
415
|
+
if (!el || local(el) !== "img" || typeof src !== "string") break;
|
|
416
|
+
set(el, "srcset", src);
|
|
417
|
+
const picture = el.parentNode;
|
|
418
|
+
if (picture && local(picture) === "picture") {
|
|
419
|
+
for (const s of Array.from(picture.children))
|
|
420
|
+
if (local(s) === "source") set(s, "srcset", src);
|
|
421
|
+
}
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
412
424
|
}
|
|
413
425
|
}
|
|
414
426
|
return i;
|
package/dist/record.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
FNV_START,
|
|
3
3
|
VERSION,
|
|
4
4
|
fnv
|
|
5
|
-
} from "./shared/chunk-
|
|
5
|
+
} from "./shared/chunk-3B3R4DHO.js";
|
|
6
6
|
|
|
7
7
|
// src/record/natives.ts
|
|
8
8
|
var NATIVE = /\{\s*\[native code\]\s*\}\s*$/;
|
|
@@ -130,10 +130,13 @@ function record(w, o = {}) {
|
|
|
130
130
|
const owner = /* @__PURE__ */ new WeakMap();
|
|
131
131
|
const fields = /* @__PURE__ */ new Set();
|
|
132
132
|
const written = /* @__PURE__ */ new WeakMap();
|
|
133
|
+
const pictures = /* @__PURE__ */ new Set();
|
|
134
|
+
let shown = /* @__PURE__ */ new WeakMap();
|
|
133
135
|
const recordedIn = /* @__PURE__ */ new WeakMap();
|
|
134
136
|
const stars = (s) => s.replace(/\S/g, "*");
|
|
135
137
|
const isEl = (n) => n.nodeType === 1;
|
|
136
138
|
const has = (el, name) => N.has(el, name);
|
|
139
|
+
const isPicture = (n) => !!n && isEl(n) && N.local(n) === "picture";
|
|
137
140
|
function up(n) {
|
|
138
141
|
const p = N.parent(n);
|
|
139
142
|
if (p) return p;
|
|
@@ -329,6 +332,9 @@ function record(w, o = {}) {
|
|
|
329
332
|
} else if (tag === "dialog" || has(el, "popover")) {
|
|
330
333
|
fields.add(el);
|
|
331
334
|
written.set(el, tag === "dialog" && has(el, "open") ? 1 : 0);
|
|
335
|
+
} else if (tag === "img" && (has(el, "srcset") || isPicture(N.parent(el)))) {
|
|
336
|
+
pictures.add(el);
|
|
337
|
+
shown.delete(el);
|
|
332
338
|
} else if (tag === "style" || tag === "link" && /stylesheet/i.test(N.get(el, "rel") || ""))
|
|
333
339
|
sheetQueue.push(el);
|
|
334
340
|
}
|
|
@@ -491,6 +497,10 @@ function record(w, o = {}) {
|
|
|
491
497
|
stamp();
|
|
492
498
|
tape.push(53 /* FOCUS */, 0);
|
|
493
499
|
});
|
|
500
|
+
on("load", (e) => {
|
|
501
|
+
const t = target(e);
|
|
502
|
+
if (t && pictures.has(t)) kick();
|
|
503
|
+
});
|
|
494
504
|
const typed = () => kick();
|
|
495
505
|
on("input", typed);
|
|
496
506
|
on("change", typed);
|
|
@@ -668,6 +678,14 @@ function record(w, o = {}) {
|
|
|
668
678
|
written.set(el, v);
|
|
669
679
|
tape.push(op, id, v);
|
|
670
680
|
});
|
|
681
|
+
pictures.forEach((img) => {
|
|
682
|
+
const id = ids.get(img);
|
|
683
|
+
if (!id || !img.isConnected) return void pictures.delete(img);
|
|
684
|
+
const src = img.currentSrc;
|
|
685
|
+
if (!src || src === img.src || shown.get(img) === src) return;
|
|
686
|
+
shown.set(img, src);
|
|
687
|
+
tape.push(130 /* SHOWN */, 2, id, src);
|
|
688
|
+
});
|
|
671
689
|
readSheets();
|
|
672
690
|
for (const m of modules) if (m.onSync) guard(m, () => m.onSync?.());
|
|
673
691
|
if (cut2) resume();
|
|
@@ -810,6 +828,8 @@ function record(w, o = {}) {
|
|
|
810
828
|
left.clear();
|
|
811
829
|
gone.clear();
|
|
812
830
|
fields.clear();
|
|
831
|
+
pictures.clear();
|
|
832
|
+
shown = /* @__PURE__ */ new WeakMap();
|
|
813
833
|
observer.takeRecords();
|
|
814
834
|
last = now();
|
|
815
835
|
t0 = Date.now() - last;
|
package/dist/testing.js
CHANGED
|
@@ -764,6 +764,11 @@ function compare(live, copy, o = {}) {
|
|
|
764
764
|
if (tag === "link" && name === "href" && /stylesheet/i.test(getA(el, "rel") || "") && (side === "copy" ? v.startsWith("blob:") : true))
|
|
765
765
|
continue;
|
|
766
766
|
if (side === "live" && masked && !PLAIN.test(name)) v = stars(v);
|
|
767
|
+
if (side === "live" && name === "srcset") {
|
|
768
|
+
const parent = el.parentNode;
|
|
769
|
+
const img = tag === "img" ? el : tag === "source" && parent && tagOf(parent) === "picture" ? Array.from(parent.children).find((c) => tagOf(c) === "img") : void 0;
|
|
770
|
+
if (img?.currentSrc && img.currentSrc !== img.src) v = img.currentSrc;
|
|
771
|
+
}
|
|
767
772
|
if (URL_ATTR.test(name)) {
|
|
768
773
|
v = abs(v);
|
|
769
774
|
if (side === "live" && !SAFE_URL.test(v)) v = "about:blank";
|
package/package.json
CHANGED
package/src/format/index.ts
CHANGED
|
@@ -74,6 +74,8 @@ export enum Op {
|
|
|
74
74
|
SHOT = 128,
|
|
75
75
|
/** framed: the name of a module cut off after it threw */
|
|
76
76
|
ERR = 129,
|
|
77
|
+
/** framed: id, the address of the picture an image shows, picked from its `srcset` or its `<picture>` */
|
|
78
|
+
SHOWN = 130,
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
export enum End {
|
package/src/play/mirror.ts
CHANGED
|
@@ -481,6 +481,18 @@ export function mirror(doc: Document, hooks: MirrorHooks = {}): Mirror {
|
|
|
481
481
|
image.src = shot;
|
|
482
482
|
break;
|
|
483
483
|
}
|
|
484
|
+
case Op.SHOWN: {
|
|
485
|
+
// The picture the visitor's browser picked, whatever the viewer's screen would.
|
|
486
|
+
const el = nodes[a(2)] as Element | undefined;
|
|
487
|
+
const src: string = a(3);
|
|
488
|
+
if (!el || local(el) !== "img" || typeof src !== "string") break;
|
|
489
|
+
set(el, "srcset", src);
|
|
490
|
+
const picture = el.parentNode as Element | null;
|
|
491
|
+
if (picture && local(picture) === "picture")
|
|
492
|
+
for (const s of Array.from(picture.children))
|
|
493
|
+
if (local(s) === "source") set(s, "srcset", src);
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
484
496
|
// HIDE, END, ERR and the framed ops this player does not know: nothing to build.
|
|
485
497
|
}
|
|
486
498
|
}
|
package/src/record/index.ts
CHANGED
|
@@ -175,12 +175,16 @@ export function record(w: Window, o: Options = {}): Recorder | null {
|
|
|
175
175
|
/** Form controls, dialogs and popovers, and the value last written for each. */
|
|
176
176
|
const fields = new Set<Element>();
|
|
177
177
|
const written = new WeakMap<Element, string | number>();
|
|
178
|
+
/** Images that pick their picture, and the address last written for each. */
|
|
179
|
+
const pictures = new Set<HTMLImageElement>();
|
|
180
|
+
let shown = new WeakMap<Element, string>();
|
|
178
181
|
/** The zone each node was recorded under: a node moved to another zone is recorded again. */
|
|
179
182
|
const recordedIn = new WeakMap<Node, Zone>();
|
|
180
183
|
|
|
181
184
|
const stars = (s: string) => s.replace(/\S/g, "*");
|
|
182
185
|
const isEl = (n: Node): n is Element => n.nodeType === 1;
|
|
183
186
|
const has = (el: Element, name: string) => N.has(el, name);
|
|
187
|
+
const isPicture = (n: Node | null) => !!n && isEl(n) && N.local(n) === "picture";
|
|
184
188
|
|
|
185
189
|
// --- Zones and masking -------------------------------------------------------------
|
|
186
190
|
|
|
@@ -419,6 +423,12 @@ export function record(w: Window, o: Options = {}): Recorder | null {
|
|
|
419
423
|
} else if (tag === "dialog" || has(el, "popover")) {
|
|
420
424
|
fields.add(el);
|
|
421
425
|
written.set(el, tag === "dialog" && has(el, "open") ? 1 : 0);
|
|
426
|
+
} else if (
|
|
427
|
+
tag === "img" &&
|
|
428
|
+
(has(el, "srcset") || isPicture(N.parent(el)))
|
|
429
|
+
) {
|
|
430
|
+
pictures.add(el as HTMLImageElement);
|
|
431
|
+
shown.delete(el);
|
|
422
432
|
} else if (
|
|
423
433
|
tag === "style" ||
|
|
424
434
|
(tag === "link" && /stylesheet/i.test(N.get(el, "rel") || ""))
|
|
@@ -602,6 +612,10 @@ export function record(w: Window, o: Options = {}): Recorder | null {
|
|
|
602
612
|
stamp();
|
|
603
613
|
tape.push(Op.FOCUS, 0);
|
|
604
614
|
});
|
|
615
|
+
on("load", (e: Event) => {
|
|
616
|
+
const t = target(e);
|
|
617
|
+
if (t && pictures.has(t as HTMLImageElement)) kick();
|
|
618
|
+
});
|
|
605
619
|
const typed = () => kick();
|
|
606
620
|
on("input", typed);
|
|
607
621
|
on("change", typed);
|
|
@@ -815,6 +829,16 @@ export function record(w: Window, o: Options = {}): Recorder | null {
|
|
|
815
829
|
tape.push(op, id, v);
|
|
816
830
|
});
|
|
817
831
|
|
|
832
|
+
// The picture the browser picked, never in the copy's choice: the viewer's screen is another.
|
|
833
|
+
pictures.forEach((img) => {
|
|
834
|
+
const id = ids.get(img);
|
|
835
|
+
if (!id || !img.isConnected) return void pictures.delete(img);
|
|
836
|
+
const src = img.currentSrc;
|
|
837
|
+
if (!src || src === img.src || shown.get(img) === src) return;
|
|
838
|
+
shown.set(img, src);
|
|
839
|
+
tape.push(Op.SHOWN, 2, id, src);
|
|
840
|
+
});
|
|
841
|
+
|
|
818
842
|
readSheets();
|
|
819
843
|
for (const m of modules) if (m.onSync) guard(m, () => m.onSync?.());
|
|
820
844
|
|
|
@@ -973,6 +997,8 @@ export function record(w: Window, o: Options = {}): Recorder | null {
|
|
|
973
997
|
left.clear();
|
|
974
998
|
gone.clear();
|
|
975
999
|
fields.clear();
|
|
1000
|
+
pictures.clear();
|
|
1001
|
+
shown = new WeakMap();
|
|
976
1002
|
observer.takeRecords();
|
|
977
1003
|
last = now();
|
|
978
1004
|
t0 = Date.now() - last;
|
package/src/testing/oracle.ts
CHANGED
|
@@ -174,6 +174,18 @@ export function compare(live: Document, copy: Document, o: OracleOptions = {}):
|
|
|
174
174
|
)
|
|
175
175
|
continue;
|
|
176
176
|
if (side === "live" && masked && !PLAIN.test(name)) v = stars(v);
|
|
177
|
+
// The copy shows the picture the visitor's browser picked, whatever its own would.
|
|
178
|
+
if (side === "live" && name === "srcset") {
|
|
179
|
+
const parent = el.parentNode as Element | null;
|
|
180
|
+
const img = (
|
|
181
|
+
tag === "img"
|
|
182
|
+
? el
|
|
183
|
+
: tag === "source" && parent && tagOf(parent) === "picture"
|
|
184
|
+
? Array.from(parent.children).find((c) => tagOf(c) === "img")
|
|
185
|
+
: undefined
|
|
186
|
+
) as HTMLImageElement | undefined;
|
|
187
|
+
if (img?.currentSrc && img.currentSrc !== img.src) v = img.currentSrc;
|
|
188
|
+
}
|
|
177
189
|
if (URL_ATTR.test(name)) {
|
|
178
190
|
v = abs(v);
|
|
179
191
|
if (side === "live" && !SAFE_URL.test(v)) v = "about:blank";
|