@voila.dev/replay 0.2.0 → 0.3.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.
@@ -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
@@ -14,7 +14,7 @@ import {
14
14
  resolve,
15
15
  span,
16
16
  validate
17
- } from "./shared/chunk-6US53Q3A.js";
17
+ } from "./shared/chunk-3B3R4DHO.js";
18
18
  export {
19
19
  End,
20
20
  FNV_START,
package/dist/modules.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./shared/chunk-6US53Q3A.js";
1
+ import "./shared/chunk-3B3R4DHO.js";
2
2
 
3
3
  // src/modules/index.ts
4
4
  function shadow() {
package/dist/play.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  fnv,
4
4
  join,
5
5
  length
6
- } from "./shared/chunk-6US53Q3A.js";
6
+ } from "./shared/chunk-3B3R4DHO.js";
7
7
 
8
8
  // src/play/mirror.ts
9
9
  var SVG = "http://www.w3.org/2000/svg";
@@ -65,7 +65,8 @@ function mirror(doc, hooks = {}) {
65
65
  if (/^on/i.test(name) || name.toLowerCase() === "http-equiv") return;
66
66
  const tag = local(el);
67
67
  if (tag === "iframe" && (name === "src" || name === "srcdoc")) return;
68
- if (ADDRESS.test(name)) {
68
+ if (ADDRESS.test(name) && value.trim().startsWith("#")) value = value.trim();
69
+ else if (ADDRESS.test(name)) {
69
70
  value = absolute(value);
70
71
  if (!SAFE_URL.test(value)) value = "about:blank";
71
72
  else if (tag !== "link") value = kept(value);
@@ -409,6 +410,18 @@ function mirror(doc, hooks = {}) {
409
410
  image.src = shot;
410
411
  break;
411
412
  }
413
+ case 130 /* SHOWN */: {
414
+ const el = nodes[a(2)];
415
+ const src = a(3);
416
+ if (!el || local(el) !== "img" || typeof src !== "string") break;
417
+ set(el, "srcset", src);
418
+ const picture = el.parentNode;
419
+ if (picture && local(picture) === "picture") {
420
+ for (const s of Array.from(picture.children))
421
+ if (local(s) === "source") set(s, "srcset", src);
422
+ }
423
+ break;
424
+ }
412
425
  }
413
426
  }
414
427
  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-6US53Q3A.js";
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;
@@ -31,6 +31,7 @@ var Op = /* @__PURE__ */ ((Op2) => {
31
31
  Op2[Op2["END"] = 98] = "END";
32
32
  Op2[Op2["SHOT"] = 128] = "SHOT";
33
33
  Op2[Op2["ERR"] = 129] = "ERR";
34
+ Op2[Op2["SHOWN"] = 130] = "SHOWN";
34
35
  return Op2;
35
36
  })(Op || {});
36
37
  var End = /* @__PURE__ */ ((End2) => {
package/dist/testing.js CHANGED
@@ -123,6 +123,21 @@ var CASES = [
123
123
  d.getElementById("b").textContent = "apr\xE8s";
124
124
  }
125
125
  },
126
+ {
127
+ name: 'symbole SVG repris par <use href="#\u2026">, et lien vers une ancre',
128
+ group: "parseur",
129
+ html: D(
130
+ '<svg width="0" height="0"><symbol id="star" viewBox="0 0 10 10"><path d="M5 0L10 10H0z"/></symbol></svg><a href="#b">aller</a><div id="a"></div><div id="b">avant</div>'
131
+ ),
132
+ run: (d) => {
133
+ const svg = d.createElementNS("http://www.w3.org/2000/svg", "svg");
134
+ const use = d.createElementNS("http://www.w3.org/2000/svg", "use");
135
+ use.setAttribute("href", "#star");
136
+ svg.append(use);
137
+ d.getElementById("a")?.append(svg);
138
+ d.getElementById("b").textContent = "apr\xE8s";
139
+ }
140
+ },
126
141
  {
127
142
  name: "les cinq pi\xE8ges, pr\xE9sents d\xE8s le d\xE9part",
128
143
  group: "parseur",
@@ -764,6 +779,11 @@ function compare(live, copy, o = {}) {
764
779
  if (tag === "link" && name === "href" && /stylesheet/i.test(getA(el, "rel") || "") && (side === "copy" ? v.startsWith("blob:") : true))
765
780
  continue;
766
781
  if (side === "live" && masked && !PLAIN.test(name)) v = stars(v);
782
+ if (side === "live" && name === "srcset") {
783
+ const parent = el.parentNode;
784
+ const img = tag === "img" ? el : tag === "source" && parent && tagOf(parent) === "picture" ? Array.from(parent.children).find((c) => tagOf(c) === "img") : void 0;
785
+ if (img?.currentSrc && img.currentSrc !== img.src) v = img.currentSrc;
786
+ }
767
787
  if (URL_ATTR.test(name)) {
768
788
  v = abs(v);
769
789
  if (side === "live" && !SAFE_URL.test(v)) v = "about:blank";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voila.dev/replay",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Session recording and replay for the web: a small recorder, a flat tape format, a DOM-built player.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -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 {
@@ -129,7 +129,10 @@ export function mirror(doc: Document, hooks: MirrorHooks = {}): Mirror {
129
129
  if (/^on/i.test(name) || name.toLowerCase() === "http-equiv") return;
130
130
  const tag = local(el);
131
131
  if (tag === "iframe" && (name === "src" || name === "srcdoc")) return;
132
- if (ADDRESS.test(name)) {
132
+ // A reference inside the page (`<use href="#icon">`, `<a href="#main">`) stays one: made
133
+ // absolute, it would point at the recorded site, which the copy may not load.
134
+ if (ADDRESS.test(name) && value.trim().startsWith("#")) value = value.trim();
135
+ else if (ADDRESS.test(name)) {
133
136
  value = absolute(value);
134
137
  if (!SAFE_URL.test(value)) value = "about:blank";
135
138
  // A stylesheet's own address stays: its rules came on the tape, read from there.
@@ -481,6 +484,18 @@ export function mirror(doc: Document, hooks: MirrorHooks = {}): Mirror {
481
484
  image.src = shot;
482
485
  break;
483
486
  }
487
+ case Op.SHOWN: {
488
+ // The picture the visitor's browser picked, whatever the viewer's screen would.
489
+ const el = nodes[a(2)] as Element | undefined;
490
+ const src: string = a(3);
491
+ if (!el || local(el) !== "img" || typeof src !== "string") break;
492
+ set(el, "srcset", src);
493
+ const picture = el.parentNode as Element | null;
494
+ if (picture && local(picture) === "picture")
495
+ for (const s of Array.from(picture.children))
496
+ if (local(s) === "source") set(s, "srcset", src);
497
+ break;
498
+ }
484
499
  // HIDE, END, ERR and the framed ops this player does not know: nothing to build.
485
500
  }
486
501
  }
@@ -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;
@@ -150,6 +150,21 @@ export const CASES: ReadonlyArray<Case> = [
150
150
  (d.getElementById("b") as Element).textContent = "après";
151
151
  },
152
152
  },
153
+ {
154
+ name: "symbole SVG repris par <use href=\"#…\">, et lien vers une ancre",
155
+ group: "parseur",
156
+ html: D(
157
+ '<svg width="0" height="0"><symbol id="star" viewBox="0 0 10 10"><path d="M5 0L10 10H0z"/></symbol></svg><a href="#b">aller</a><div id="a"></div><div id="b">avant</div>',
158
+ ),
159
+ run: (d) => {
160
+ const svg = d.createElementNS("http://www.w3.org/2000/svg", "svg");
161
+ const use = d.createElementNS("http://www.w3.org/2000/svg", "use");
162
+ use.setAttribute("href", "#star");
163
+ svg.append(use);
164
+ d.getElementById("a")?.append(svg);
165
+ (d.getElementById("b") as Element).textContent = "après";
166
+ },
167
+ },
153
168
  {
154
169
  name: "les cinq pièges, présents dès le départ",
155
170
  group: "parseur",
@@ -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";