@voila.dev/replay 0.1.1 → 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/dist/play/index.d.ts +2 -0
- package/dist/play/mirror.d.ts +5 -0
- package/dist/play.js +5 -2
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/src/play/index.ts +3 -0
- package/src/play/mirror.ts +10 -2
- package/src/testing/oracle.ts +9 -4
package/dist/play/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface PlayerOptions {
|
|
|
9
9
|
readonly skipIdle?: boolean;
|
|
10
10
|
/** Ms of recording between two checkpoints; a seek starts from the nearest one. */
|
|
11
11
|
readonly every?: number;
|
|
12
|
+
/** Where to load a picture or a font from, given its address on the page (see `MirrorHooks`). */
|
|
13
|
+
readonly asset?: (url: string) => string;
|
|
12
14
|
}
|
|
13
15
|
export interface Gap {
|
|
14
16
|
/** Ms from the start of the recording. */
|
package/dist/play/mirror.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export interface MirrorHooks {
|
|
|
5
5
|
readonly size?: (width: number, height: number) => void;
|
|
6
6
|
readonly focus?: (el: Element | null) => void;
|
|
7
7
|
readonly print?: (ok: boolean, at: number, detail: string) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Where to load a picture or a font from, given its address on the page: a copy kept when
|
|
10
|
+
* the page was recorded outlives the file the site later renamed or replaced.
|
|
11
|
+
*/
|
|
12
|
+
readonly asset?: (url: string) => string;
|
|
8
13
|
}
|
|
9
14
|
export interface Mirror {
|
|
10
15
|
/** Runs the tape from `from`, up to the tick that would pass `until`. Returns where it stopped. */
|
package/dist/play.js
CHANGED
|
@@ -46,7 +46,8 @@ function mirror(doc, hooks = {}) {
|
|
|
46
46
|
return url;
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
const
|
|
49
|
+
const kept = (url) => hooks.asset ? hooks.asset(url) : url;
|
|
50
|
+
const css = (text, from = base) => text.replace(CSS_URL, (_m, _q, url) => `url("${kept(absolute(url, from))}")`);
|
|
50
51
|
const local = (el) => localName.call(el);
|
|
51
52
|
function add(n) {
|
|
52
53
|
const top = stack[stack.length - 1];
|
|
@@ -67,10 +68,11 @@ function mirror(doc, hooks = {}) {
|
|
|
67
68
|
if (ADDRESS.test(name)) {
|
|
68
69
|
value = absolute(value);
|
|
69
70
|
if (!SAFE_URL.test(value)) value = "about:blank";
|
|
71
|
+
else if (tag !== "link") value = kept(value);
|
|
70
72
|
} else if (name === "srcset")
|
|
71
73
|
value = value.split(",").map((part) => {
|
|
72
74
|
const [url, ...rest] = part.trim().split(/\s+/);
|
|
73
|
-
return [absolute(url || ""), ...rest].join(" ");
|
|
75
|
+
return [kept(absolute(url || "")), ...rest].join(" ");
|
|
74
76
|
}).join(", ");
|
|
75
77
|
else if (name === "style") value = css(value);
|
|
76
78
|
else if (tag === "a" && name === "target") return;
|
|
@@ -713,6 +715,7 @@ function createPlayer(options) {
|
|
|
713
715
|
let m = make();
|
|
714
716
|
function make() {
|
|
715
717
|
return mirror(doc, {
|
|
718
|
+
asset: options.asset,
|
|
716
719
|
pointer(x, y) {
|
|
717
720
|
cursor.style.display = "block";
|
|
718
721
|
cursor.style.transform = `translate(${x}px,${y}px)`;
|
package/dist/testing.js
CHANGED
|
@@ -791,7 +791,7 @@ function compare(live, copy, o = {}) {
|
|
|
791
791
|
const want = shown(L.value, fieldHidden(L, masked, clear));
|
|
792
792
|
if (want !== R.value) add(p, "textarea.value", want, R.value);
|
|
793
793
|
} else if (tag === "select") {
|
|
794
|
-
const picked = (s) => Array.from(s.options, (x, i) => x.selected ? i : -1).filter((i) => i >= 0).join(",");
|
|
794
|
+
const picked = (s) => s.multiple || s.size > 1 ? Array.from(s.options, (x, i) => x.selected ? i : -1).filter((i) => i >= 0).join(",") : s.selectedIndex < 0 ? "" : String(s.selectedIndex);
|
|
795
795
|
let want = picked(L);
|
|
796
796
|
if (fieldHidden(L, masked, clear)) {
|
|
797
797
|
const options = Array.from(L.options);
|
package/package.json
CHANGED
package/src/play/index.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface PlayerOptions {
|
|
|
16
16
|
readonly skipIdle?: boolean;
|
|
17
17
|
/** Ms of recording between two checkpoints; a seek starts from the nearest one. */
|
|
18
18
|
readonly every?: number;
|
|
19
|
+
/** Where to load a picture or a font from, given its address on the page (see `MirrorHooks`). */
|
|
20
|
+
readonly asset?: (url: string) => string;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export interface Gap {
|
|
@@ -101,6 +103,7 @@ export function createPlayer(options: PlayerOptions): Player {
|
|
|
101
103
|
let m: Mirror = make();
|
|
102
104
|
function make() {
|
|
103
105
|
return mirror(doc, {
|
|
106
|
+
asset: options.asset,
|
|
104
107
|
pointer(x, y) {
|
|
105
108
|
cursor.style.display = "block";
|
|
106
109
|
cursor.style.transform = `translate(${x}px,${y}px)`;
|
package/src/play/mirror.ts
CHANGED
|
@@ -12,6 +12,11 @@ export interface MirrorHooks {
|
|
|
12
12
|
readonly size?: (width: number, height: number) => void;
|
|
13
13
|
readonly focus?: (el: Element | null) => void;
|
|
14
14
|
readonly print?: (ok: boolean, at: number, detail: string) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Where to load a picture or a font from, given its address on the page: a copy kept when
|
|
17
|
+
* the page was recorded outlives the file the site later renamed or replaced.
|
|
18
|
+
*/
|
|
19
|
+
readonly asset?: (url: string) => string;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export interface Mirror {
|
|
@@ -101,8 +106,9 @@ export function mirror(doc: Document, hooks: MirrorHooks = {}): Mirror {
|
|
|
101
106
|
return url;
|
|
102
107
|
}
|
|
103
108
|
};
|
|
109
|
+
const kept = (url: string) => (hooks.asset ? hooks.asset(url) : url);
|
|
104
110
|
const css = (text: string, from = base) =>
|
|
105
|
-
text.replace(CSS_URL, (_m, _q, url: string) => `url("${absolute(url, from)}")`);
|
|
111
|
+
text.replace(CSS_URL, (_m, _q, url: string) => `url("${kept(absolute(url, from))}")`);
|
|
106
112
|
const local = (el: Element) => localName.call(el);
|
|
107
113
|
|
|
108
114
|
function add(n: Node) {
|
|
@@ -126,12 +132,14 @@ export function mirror(doc: Document, hooks: MirrorHooks = {}): Mirror {
|
|
|
126
132
|
if (ADDRESS.test(name)) {
|
|
127
133
|
value = absolute(value);
|
|
128
134
|
if (!SAFE_URL.test(value)) value = "about:blank";
|
|
135
|
+
// A stylesheet's own address stays: its rules came on the tape, read from there.
|
|
136
|
+
else if (tag !== "link") value = kept(value);
|
|
129
137
|
} else if (name === "srcset")
|
|
130
138
|
value = value
|
|
131
139
|
.split(",")
|
|
132
140
|
.map((part) => {
|
|
133
141
|
const [url, ...rest] = part.trim().split(/\s+/);
|
|
134
|
-
return [absolute(url || ""), ...rest].join(" ");
|
|
142
|
+
return [kept(absolute(url || "")), ...rest].join(" ");
|
|
135
143
|
})
|
|
136
144
|
.join(", ");
|
|
137
145
|
else if (name === "style") value = css(value);
|
package/src/testing/oracle.ts
CHANGED
|
@@ -206,13 +206,18 @@ export function compare(live: Document, copy: Document, o: OracleOptions = {}):
|
|
|
206
206
|
const want = shown(L.value, fieldHidden(L, masked, clear));
|
|
207
207
|
if (want !== R.value) add(p, "textarea.value", want, R.value);
|
|
208
208
|
} else if (tag === "select") {
|
|
209
|
+
// A single select shows its `selectedIndex`: Safari 16 may also report as chosen the
|
|
210
|
+
// option given `selected` by script, which it does not show.
|
|
209
211
|
const picked = (s: HTMLSelectElement) =>
|
|
210
|
-
|
|
211
|
-
.
|
|
212
|
-
|
|
212
|
+
s.multiple || s.size > 1
|
|
213
|
+
? Array.from(s.options, (x, i) => (x.selected ? i : -1))
|
|
214
|
+
.filter((i) => i >= 0)
|
|
215
|
+
.join(",")
|
|
216
|
+
: s.selectedIndex < 0
|
|
217
|
+
? ""
|
|
218
|
+
: String(s.selectedIndex);
|
|
213
219
|
let want = picked(L);
|
|
214
220
|
if (fieldHidden(L, masked, clear)) {
|
|
215
|
-
// A hidden choice: the copy shows what the markup alone selects.
|
|
216
221
|
// A hidden choice: the copy shows what the markup alone selects.
|
|
217
222
|
const options = Array.from(L.options as ArrayLike<HTMLOptionElement>);
|
|
218
223
|
if (L.multiple || L.size > 1) want = options.map((x, i) => (hasA(x, "selected") ? i : -1)).filter((i) => i >= 0).join(",");
|