@puth/core 0.0.2 → 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.
- package/dist/index.cjs +542 -0
- package/dist/index.d.cts +241 -2
- package/dist/index.d.mts +241 -2
- package/dist/index.mjs +534 -1
- package/package.json +7 -2
package/dist/index.cjs
CHANGED
|
@@ -37,8 +37,550 @@ const Constructors = {
|
|
|
37
37
|
};
|
|
38
38
|
const ConstructorValues = Object.values(Constructors);
|
|
39
39
|
|
|
40
|
+
const SNAPSHOT_VERSION = 2;
|
|
41
|
+
|
|
42
|
+
var DomNodeType = /* @__PURE__ */ ((DomNodeType2) => {
|
|
43
|
+
DomNodeType2[DomNodeType2["ELEMENT"] = 1] = "ELEMENT";
|
|
44
|
+
DomNodeType2[DomNodeType2["TEXT"] = 3] = "TEXT";
|
|
45
|
+
DomNodeType2[DomNodeType2["COMMENT"] = 8] = "COMMENT";
|
|
46
|
+
DomNodeType2[DomNodeType2["DOCTYPE"] = 10] = "DOCTYPE";
|
|
47
|
+
return DomNodeType2;
|
|
48
|
+
})(DomNodeType || {});
|
|
49
|
+
var DomNamespace = /* @__PURE__ */ ((DomNamespace2) => {
|
|
50
|
+
DomNamespace2[DomNamespace2["HTML"] = 0] = "HTML";
|
|
51
|
+
DomNamespace2[DomNamespace2["SVG"] = 1] = "SVG";
|
|
52
|
+
DomNamespace2[DomNamespace2["MATHML"] = 2] = "MATHML";
|
|
53
|
+
return DomNamespace2;
|
|
54
|
+
})(DomNamespace || {});
|
|
55
|
+
var DomTopLayer = /* @__PURE__ */ ((DomTopLayer2) => {
|
|
56
|
+
DomTopLayer2[DomTopLayer2["NONE"] = 0] = "NONE";
|
|
57
|
+
DomTopLayer2[DomTopLayer2["MODAL"] = 1] = "MODAL";
|
|
58
|
+
DomTopLayer2[DomTopLayer2["POPOVER"] = 2] = "POPOVER";
|
|
59
|
+
return DomTopLayer2;
|
|
60
|
+
})(DomTopLayer || {});
|
|
61
|
+
var DomOp = /* @__PURE__ */ ((DomOp2) => {
|
|
62
|
+
DomOp2[DomOp2["CHILDREN"] = 1] = "CHILDREN";
|
|
63
|
+
DomOp2[DomOp2["ATTRIBUTES"] = 2] = "ATTRIBUTES";
|
|
64
|
+
DomOp2[DomOp2["TEXT"] = 3] = "TEXT";
|
|
65
|
+
DomOp2[DomOp2["CONTROL"] = 4] = "CONTROL";
|
|
66
|
+
DomOp2[DomOp2["CSS"] = 6] = "CSS";
|
|
67
|
+
DomOp2[DomOp2["SCROLL"] = 7] = "SCROLL";
|
|
68
|
+
DomOp2[DomOp2["VIEWPORT"] = 8] = "VIEWPORT";
|
|
69
|
+
DomOp2[DomOp2["SHADOW"] = 9] = "SHADOW";
|
|
70
|
+
DomOp2[DomOp2["SHEET"] = 10] = "SHEET";
|
|
71
|
+
DomOp2[DomOp2["ADOPT"] = 11] = "ADOPT";
|
|
72
|
+
DomOp2[DomOp2["TOP_LAYER"] = 12] = "TOP_LAYER";
|
|
73
|
+
return DomOp2;
|
|
74
|
+
})(DomOp || {});
|
|
75
|
+
|
|
76
|
+
const NAMESPACES = ["http://www.w3.org/1999/xhtml", "http://www.w3.org/2000/svg", "http://www.w3.org/1998/Math/MathML"];
|
|
77
|
+
const XLINK = "http://www.w3.org/1999/xlink";
|
|
78
|
+
const REWRITTEN_PREFIX = "data-puth-replay-";
|
|
79
|
+
const NO_CHILDREN = /* @__PURE__ */ new Set(["script", "noscript", "template", "iframe", "frame", "object", "embed"]);
|
|
80
|
+
const FRAMES = /* @__PURE__ */ new Set(["iframe", "frame"]);
|
|
81
|
+
const STRIPPED_RELS = /(^|\s)(preconnect|dns-prefetch|prerender|prefetch|modulepreload)(\s|$)/i;
|
|
82
|
+
class DomReplay {
|
|
83
|
+
/**
|
|
84
|
+
* frameSrc is the page recorded iframes load instead of their own, so a caller can build the documents they
|
|
85
|
+
* showed into them. Without it, iframes stay empty.
|
|
86
|
+
*/
|
|
87
|
+
constructor(doc, options = {}) {
|
|
88
|
+
this.options = options;
|
|
89
|
+
this.doc = doc;
|
|
90
|
+
this.base = doc.createElement("base");
|
|
91
|
+
this.own.add(this.base);
|
|
92
|
+
}
|
|
93
|
+
options;
|
|
94
|
+
doc;
|
|
95
|
+
nodes = [];
|
|
96
|
+
base;
|
|
97
|
+
own = /* @__PURE__ */ new WeakSet();
|
|
98
|
+
viewport = [0, 0, 1];
|
|
99
|
+
// The document's string table, from the keyframe and the batches applied since.
|
|
100
|
+
strings = [];
|
|
101
|
+
scroll = /* @__PURE__ */ new Map();
|
|
102
|
+
// Adopted stylesheets by recorded id, constructed in the replay's window, as adoptedStyleSheets requires.
|
|
103
|
+
sheets = /* @__PURE__ */ new Map();
|
|
104
|
+
// The top layer needs connected elements, so it is applied once they are inserted.
|
|
105
|
+
pendingTop = [];
|
|
106
|
+
// Whether a dialog's recorded attributes include open, which closing a modal dialog removes.
|
|
107
|
+
recordedOpen = /* @__PURE__ */ new WeakMap();
|
|
108
|
+
/** Rebuilds the document from a keyframe and the strings that came with it. */
|
|
109
|
+
build(keyframe, strings = []) {
|
|
110
|
+
const doc = this.doc;
|
|
111
|
+
this.strings = strings.slice();
|
|
112
|
+
this.nodes = [];
|
|
113
|
+
this.nodes[keyframe.document] = doc;
|
|
114
|
+
this.scroll.clear();
|
|
115
|
+
this.sheets.clear();
|
|
116
|
+
this.pendingTop = [];
|
|
117
|
+
doc.adoptedStyleSheets = [];
|
|
118
|
+
this.base.href = keyframe.base;
|
|
119
|
+
(doc.documentElement ?? doc).prepend(this.base);
|
|
120
|
+
const children = [];
|
|
121
|
+
const tokens = keyframe.root;
|
|
122
|
+
const cursor = { at: 1 };
|
|
123
|
+
for (let i = 0; i < tokens[0]; i++) {
|
|
124
|
+
const created = this.create(tokens, cursor);
|
|
125
|
+
if (created !== null) {
|
|
126
|
+
children.push(created);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (const child of [...doc.childNodes]) {
|
|
130
|
+
if (child.nodeType !== DomNodeType.DOCTYPE) {
|
|
131
|
+
doc.removeChild(child);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const html = children.find((node) => node.nodeType === DomNodeType.ELEMENT);
|
|
135
|
+
if (html !== void 0) {
|
|
136
|
+
html.prepend(this.base);
|
|
137
|
+
}
|
|
138
|
+
for (const child of children) {
|
|
139
|
+
doc.appendChild(child);
|
|
140
|
+
}
|
|
141
|
+
this.keepBase();
|
|
142
|
+
for (const [id, css] of keyframe.sheets ?? []) {
|
|
143
|
+
this.setSheet(id, css);
|
|
144
|
+
}
|
|
145
|
+
for (const [root, sheets] of keyframe.adopted ?? []) {
|
|
146
|
+
this.adopt(root, sheets);
|
|
147
|
+
}
|
|
148
|
+
this.applyTop();
|
|
149
|
+
this.viewport = keyframe.viewport;
|
|
150
|
+
for (const [id, x, y] of keyframe.scroll) {
|
|
151
|
+
this.scroll.set(id, [x, y]);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** Applies a batch of changes, with the strings it added to the table. */
|
|
155
|
+
apply(changes, strings = []) {
|
|
156
|
+
for (const string of strings) {
|
|
157
|
+
this.strings.push(string);
|
|
158
|
+
}
|
|
159
|
+
for (const change of changes) {
|
|
160
|
+
switch (change[0]) {
|
|
161
|
+
case DomOp.CHILDREN:
|
|
162
|
+
this.setChildren(change[1], change[2]);
|
|
163
|
+
break;
|
|
164
|
+
case DomOp.ATTRIBUTES: {
|
|
165
|
+
const element = this.nodes[change[1]];
|
|
166
|
+
if (element instanceof this.windowOf().Element) {
|
|
167
|
+
this.setAttributes(element, change[2]);
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case DomOp.TEXT: {
|
|
172
|
+
const node = this.nodes[change[1]];
|
|
173
|
+
if (node !== void 0 && "data" in node) {
|
|
174
|
+
node.data = this.string(change[2]);
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
case DomOp.CONTROL: {
|
|
179
|
+
const element = this.nodes[change[1]];
|
|
180
|
+
if (element !== void 0) {
|
|
181
|
+
this.setProps(element, {
|
|
182
|
+
value: change[2] ?? void 0,
|
|
183
|
+
checked: change[3] ?? void 0,
|
|
184
|
+
selectedIndex: change[4] ?? void 0,
|
|
185
|
+
selected: change[5] ?? void 0
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case DomOp.CSS: {
|
|
191
|
+
const element = this.nodes[change[1]];
|
|
192
|
+
if (element !== void 0) {
|
|
193
|
+
element.textContent = change[2];
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case DomOp.SCROLL:
|
|
198
|
+
this.scroll.set(change[1], [change[2], change[3]]);
|
|
199
|
+
break;
|
|
200
|
+
case DomOp.VIEWPORT:
|
|
201
|
+
this.viewport = [change[1], change[2], change[3]];
|
|
202
|
+
break;
|
|
203
|
+
case DomOp.SHADOW: {
|
|
204
|
+
const host = this.nodes[change[1]];
|
|
205
|
+
if (host instanceof this.windowOf().Element) {
|
|
206
|
+
this.attachShadow(host, change[2]);
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
case DomOp.SHEET:
|
|
211
|
+
this.setSheet(change[1], change[2]);
|
|
212
|
+
break;
|
|
213
|
+
case DomOp.ADOPT:
|
|
214
|
+
this.adopt(change[1], change[2]);
|
|
215
|
+
break;
|
|
216
|
+
case DomOp.TOP_LAYER: {
|
|
217
|
+
const element = this.nodes[change[1]];
|
|
218
|
+
if (element instanceof this.windowOf().Element) {
|
|
219
|
+
this.pendingTop.push([element, change[2]]);
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
this.applyTop();
|
|
226
|
+
}
|
|
227
|
+
/** Scroll positions need layout, so they are restored once, after all changes are applied. */
|
|
228
|
+
restoreScroll() {
|
|
229
|
+
const window = this.doc.defaultView;
|
|
230
|
+
for (const [id, [x, y]] of this.scroll) {
|
|
231
|
+
if (id === 0) {
|
|
232
|
+
window?.scrollTo(x, y);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const element = this.nodes[id];
|
|
236
|
+
if (element?.isConnected) {
|
|
237
|
+
element.scrollLeft = x;
|
|
238
|
+
element.scrollTop = y;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/** The iframe elements of the rebuilt document with their recorded ids. */
|
|
243
|
+
frames() {
|
|
244
|
+
const frames = [];
|
|
245
|
+
this.nodes.forEach((node, id) => {
|
|
246
|
+
if (node !== void 0 && node.nodeType === DomNodeType.ELEMENT && FRAMES.has(node.localName) && node.isConnected) {
|
|
247
|
+
frames.push([id, node]);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return frames;
|
|
251
|
+
}
|
|
252
|
+
/** The node a recorded id stands for, like the target of a command. */
|
|
253
|
+
nodeOf(id) {
|
|
254
|
+
return this.nodes[id];
|
|
255
|
+
}
|
|
256
|
+
windowOf() {
|
|
257
|
+
return this.doc.defaultView ?? globalThis;
|
|
258
|
+
}
|
|
259
|
+
string(value) {
|
|
260
|
+
return typeof value === "number" ? this.strings[value] : value;
|
|
261
|
+
}
|
|
262
|
+
// Creates the node that starts at cursor.at and moves the cursor past it, its children included.
|
|
263
|
+
create(tokens, cursor) {
|
|
264
|
+
const doc = this.doc;
|
|
265
|
+
const id = tokens[cursor.at++];
|
|
266
|
+
const type = tokens[cursor.at++];
|
|
267
|
+
let created;
|
|
268
|
+
switch (type) {
|
|
269
|
+
case DomNodeType.ELEMENT: {
|
|
270
|
+
const tag = this.string(tokens[cursor.at++]);
|
|
271
|
+
const namespace = tokens[cursor.at++];
|
|
272
|
+
const count = tokens[cursor.at++];
|
|
273
|
+
const attributes = tokens.slice(cursor.at, cursor.at + count * 2);
|
|
274
|
+
cursor.at += count * 2;
|
|
275
|
+
const props = tokens[cursor.at++];
|
|
276
|
+
const children = tokens[cursor.at++];
|
|
277
|
+
let element;
|
|
278
|
+
try {
|
|
279
|
+
element = namespace ? doc.createElementNS(NAMESPACES[namespace], tag) : doc.createElement(tag);
|
|
280
|
+
} catch {
|
|
281
|
+
element = doc.createElement("puth-replay-unknown");
|
|
282
|
+
}
|
|
283
|
+
this.setAttributes(element, attributes);
|
|
284
|
+
for (let i = 0; i < children; i++) {
|
|
285
|
+
const child = this.create(tokens, cursor);
|
|
286
|
+
if (child !== null && (namespace !== 0 || !NO_CHILDREN.has(element.localName))) {
|
|
287
|
+
element.appendChild(child);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (props) {
|
|
291
|
+
this.setProps(element, props);
|
|
292
|
+
if (props.shadow !== void 0) {
|
|
293
|
+
this.attachShadow(element, props.shadow);
|
|
294
|
+
}
|
|
295
|
+
if (props.top) {
|
|
296
|
+
this.pendingTop.push([element, props.top]);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
created = element;
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
case DomNodeType.TEXT:
|
|
303
|
+
created = doc.createTextNode(this.string(tokens[cursor.at++]));
|
|
304
|
+
break;
|
|
305
|
+
case DomNodeType.COMMENT:
|
|
306
|
+
created = doc.createComment(this.string(tokens[cursor.at++]));
|
|
307
|
+
break;
|
|
308
|
+
default:
|
|
309
|
+
cursor.at += 3;
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
this.nodes[id] = created;
|
|
313
|
+
return created;
|
|
314
|
+
}
|
|
315
|
+
setChildren(parentId, children) {
|
|
316
|
+
const parent = this.nodes[parentId];
|
|
317
|
+
if (parent === void 0 || parent.nodeType === DomNodeType.ELEMENT && NO_CHILDREN.has(parent.localName) && parent.namespaceURI === NAMESPACES[0]) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const wanted = [];
|
|
321
|
+
const reader = { at: 1 };
|
|
322
|
+
for (let i = 0; i < children[0]; i++) {
|
|
323
|
+
const token = children[reader.at];
|
|
324
|
+
const node = typeof token === "number" && token < 0 ? this.nodes[-token] : this.create(children, reader);
|
|
325
|
+
if (typeof token === "number" && token < 0) {
|
|
326
|
+
reader.at++;
|
|
327
|
+
}
|
|
328
|
+
if (node !== void 0 && node !== null) {
|
|
329
|
+
wanted.push(node);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const keep = new Set(wanted);
|
|
333
|
+
for (const child of [...parent.childNodes]) {
|
|
334
|
+
if (!this.own.has(child) && !keep.has(child) && child.nodeType !== DomNodeType.DOCTYPE) {
|
|
335
|
+
parent.removeChild(child);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
let cursor = this.nextRecorded(parent.firstChild);
|
|
339
|
+
for (const node of wanted) {
|
|
340
|
+
if (node === cursor) {
|
|
341
|
+
cursor = this.nextRecorded(cursor.nextSibling);
|
|
342
|
+
} else {
|
|
343
|
+
parent.insertBefore(node, cursor);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (parent === this.doc || parent === this.doc.documentElement) {
|
|
347
|
+
this.keepBase();
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
// Gives host the recorded shadow root, or replaces the children of the one it has.
|
|
351
|
+
attachShadow(host, tokens) {
|
|
352
|
+
let root = host.shadowRoot;
|
|
353
|
+
if (root === null) {
|
|
354
|
+
try {
|
|
355
|
+
root = host.attachShadow({ mode: "open" });
|
|
356
|
+
} catch {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const children = [];
|
|
361
|
+
const cursor = { at: 2 };
|
|
362
|
+
for (let i = 0; i < tokens[1]; i++) {
|
|
363
|
+
const child = this.create(tokens, cursor);
|
|
364
|
+
if (child !== null) {
|
|
365
|
+
children.push(child);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
root.replaceChildren(...children);
|
|
369
|
+
this.nodes[tokens[0]] = root;
|
|
370
|
+
}
|
|
371
|
+
setSheet(id, css) {
|
|
372
|
+
let sheet = this.sheets.get(id);
|
|
373
|
+
if (sheet === void 0) {
|
|
374
|
+
sheet = new (this.windowOf()).CSSStyleSheet({ baseURL: this.base.href });
|
|
375
|
+
this.sheets.set(id, sheet);
|
|
376
|
+
}
|
|
377
|
+
try {
|
|
378
|
+
sheet.replaceSync(css);
|
|
379
|
+
} catch {
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
adopt(rootId, ids) {
|
|
383
|
+
const root = this.nodes[rootId];
|
|
384
|
+
if (root !== void 0 && "adoptedStyleSheets" in root) {
|
|
385
|
+
root.adoptedStyleSheets = ids.map((id) => this.sheets.get(id)).filter((sheet) => sheet !== void 0);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
applyTop() {
|
|
389
|
+
for (const [element, state] of this.pendingTop.splice(0)) {
|
|
390
|
+
if (element.isConnected) {
|
|
391
|
+
this.setTop(element, state);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
// Opens a dialog as modal or a popover the way the page did, or closes them, keeping the recorded attributes.
|
|
396
|
+
setTop(element, state) {
|
|
397
|
+
const matches = (selector) => {
|
|
398
|
+
try {
|
|
399
|
+
return element.matches(selector);
|
|
400
|
+
} catch {
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
if (element.localName === "dialog") {
|
|
405
|
+
const dialog = element;
|
|
406
|
+
const modal = matches(":modal");
|
|
407
|
+
if (state === DomTopLayer.MODAL && !modal) {
|
|
408
|
+
dialog.removeAttribute("open");
|
|
409
|
+
try {
|
|
410
|
+
dialog.showModal();
|
|
411
|
+
} catch {
|
|
412
|
+
if (this.recordedOpen.get(dialog)) dialog.setAttribute("open", "");
|
|
413
|
+
}
|
|
414
|
+
} else if (state !== DomTopLayer.MODAL && modal) {
|
|
415
|
+
dialog.setAttribute("open", "");
|
|
416
|
+
dialog.close();
|
|
417
|
+
if (this.recordedOpen.get(dialog)) {
|
|
418
|
+
dialog.setAttribute("open", "");
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const popover = element;
|
|
423
|
+
const open = matches(":popover-open");
|
|
424
|
+
try {
|
|
425
|
+
if (state === DomTopLayer.POPOVER && !open) {
|
|
426
|
+
popover.showPopover();
|
|
427
|
+
} else if (state !== DomTopLayer.POPOVER && open) {
|
|
428
|
+
popover.hidePopover();
|
|
429
|
+
}
|
|
430
|
+
} catch {
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
nextRecorded(node) {
|
|
434
|
+
while (node !== null && (this.own.has(node) || node.nodeType === DomNodeType.DOCTYPE)) {
|
|
435
|
+
node = node.nextSibling;
|
|
436
|
+
}
|
|
437
|
+
return node;
|
|
438
|
+
}
|
|
439
|
+
// The base must be the first in tree order, also after the recording replaced the root element.
|
|
440
|
+
keepBase() {
|
|
441
|
+
const root = this.doc.documentElement;
|
|
442
|
+
if (root !== null && root.firstChild !== this.base) {
|
|
443
|
+
root.prepend(this.base);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
setAttributes(element, attributes) {
|
|
447
|
+
const wanted = /* @__PURE__ */ new Map();
|
|
448
|
+
for (let i = 0; i < attributes.length; i += 2) {
|
|
449
|
+
const [name, value] = this.rewrite(element, this.string(attributes[i]), this.string(attributes[i + 1]));
|
|
450
|
+
if (name !== null) {
|
|
451
|
+
wanted.set(name, value);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (this.options.frameSrc !== void 0 && FRAMES.has(element.localName)) {
|
|
455
|
+
wanted.delete("src");
|
|
456
|
+
wanted.set("sandbox", "allow-same-origin");
|
|
457
|
+
wanted.set("src", this.options.frameSrc);
|
|
458
|
+
}
|
|
459
|
+
if (element.localName === "dialog") {
|
|
460
|
+
this.recordedOpen.set(element, wanted.has("open"));
|
|
461
|
+
}
|
|
462
|
+
for (const attribute of [...element.attributes]) {
|
|
463
|
+
if (!wanted.has(attribute.name)) {
|
|
464
|
+
element.removeAttributeNode(attribute);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
for (const [name, value] of wanted) {
|
|
468
|
+
if (element.getAttribute(name) === value) {
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
try {
|
|
472
|
+
if (name.startsWith("xlink:")) {
|
|
473
|
+
element.setAttributeNS(XLINK, name, value);
|
|
474
|
+
} else {
|
|
475
|
+
element.setAttribute(name, value);
|
|
476
|
+
}
|
|
477
|
+
} catch {
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
// Returns the attribute to set instead, or null to leave it out.
|
|
482
|
+
rewrite(element, name, value) {
|
|
483
|
+
const tag = element.localName;
|
|
484
|
+
const lower = name.toLowerCase();
|
|
485
|
+
if (lower.startsWith("on")) {
|
|
486
|
+
return [null, value];
|
|
487
|
+
}
|
|
488
|
+
if (FRAMES.has(tag) && (lower === "src" || lower === "srcdoc" || lower === "sandbox")) {
|
|
489
|
+
return [REWRITTEN_PREFIX + lower, value];
|
|
490
|
+
}
|
|
491
|
+
if ((tag === "script" || tag === "embed") && lower === "src") {
|
|
492
|
+
return [REWRITTEN_PREFIX + lower, value];
|
|
493
|
+
}
|
|
494
|
+
if (tag === "object" && lower === "data") {
|
|
495
|
+
return [REWRITTEN_PREFIX + lower, value];
|
|
496
|
+
}
|
|
497
|
+
if (tag === "base" && (lower === "href" || lower === "target")) {
|
|
498
|
+
return [REWRITTEN_PREFIX + lower, value];
|
|
499
|
+
}
|
|
500
|
+
if (tag === "meta" && lower === "http-equiv" && value.toLowerCase() === "refresh") {
|
|
501
|
+
return [REWRITTEN_PREFIX + lower, value];
|
|
502
|
+
}
|
|
503
|
+
if (tag === "link" && lower === "rel" && STRIPPED_RELS.test(value)) {
|
|
504
|
+
return [REWRITTEN_PREFIX + lower, value];
|
|
505
|
+
}
|
|
506
|
+
return [name, value];
|
|
507
|
+
}
|
|
508
|
+
setProps(element, props) {
|
|
509
|
+
const control = element;
|
|
510
|
+
if (props.value !== void 0 && "value" in control && control.value !== props.value) {
|
|
511
|
+
control.value = props.value;
|
|
512
|
+
}
|
|
513
|
+
if (props.checked !== void 0 && "checked" in control) {
|
|
514
|
+
control.checked = props.checked;
|
|
515
|
+
}
|
|
516
|
+
if (props.selectedIndex !== void 0 && "selectedIndex" in control) {
|
|
517
|
+
control.selectedIndex = props.selectedIndex;
|
|
518
|
+
}
|
|
519
|
+
if (props.selected !== void 0 && "options" in control) {
|
|
520
|
+
const selected = new Set(props.selected);
|
|
521
|
+
for (let i = 0; i < control.options.length; i++) {
|
|
522
|
+
control.options[i].selected = selected.has(i);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (props.css !== void 0) {
|
|
526
|
+
element.textContent = props.css;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function domPacketsUntil(packets, seq) {
|
|
531
|
+
let start = -1;
|
|
532
|
+
for (let i = 0; i < packets.length && packets[i].seq <= seq; i++) {
|
|
533
|
+
if (packets[i].kind === "keyframe") {
|
|
534
|
+
start = i;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
if (start === -1) {
|
|
538
|
+
return [];
|
|
539
|
+
}
|
|
540
|
+
const until = [];
|
|
541
|
+
for (let i = start; i < packets.length && packets[i].seq <= seq; i++) {
|
|
542
|
+
until.push(packets[i]);
|
|
543
|
+
}
|
|
544
|
+
return until;
|
|
545
|
+
}
|
|
546
|
+
function domFrameDocument(links, owner, frames, time, recorded = () => true) {
|
|
547
|
+
let flushed;
|
|
548
|
+
let before;
|
|
549
|
+
for (const link of links) {
|
|
550
|
+
if (link.owner !== owner) {
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
if (frames !== void 0 && link.doc in frames) {
|
|
554
|
+
flushed = link.doc;
|
|
555
|
+
}
|
|
556
|
+
if (link.timestamp <= time && recorded(link.doc)) {
|
|
557
|
+
before = link.doc;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return flushed ?? before;
|
|
561
|
+
}
|
|
562
|
+
function domSeqAt(packets, time) {
|
|
563
|
+
let seq;
|
|
564
|
+
for (const packet of packets) {
|
|
565
|
+
if (packet.timestamp > time) {
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
seq = packet.seq;
|
|
569
|
+
}
|
|
570
|
+
return seq;
|
|
571
|
+
}
|
|
572
|
+
|
|
40
573
|
exports.ConstructorValues = ConstructorValues;
|
|
41
574
|
exports.Constructors = Constructors;
|
|
42
575
|
exports.ContextStatus = ContextStatus;
|
|
576
|
+
exports.DomNamespace = DomNamespace;
|
|
577
|
+
exports.DomNodeType = DomNodeType;
|
|
578
|
+
exports.DomOp = DomOp;
|
|
579
|
+
exports.DomReplay = DomReplay;
|
|
580
|
+
exports.DomTopLayer = DomTopLayer;
|
|
581
|
+
exports.SNAPSHOT_VERSION = SNAPSHOT_VERSION;
|
|
43
582
|
exports.SnapshotMode = SnapshotMode;
|
|
44
583
|
exports.SnapshotState = SnapshotState;
|
|
584
|
+
exports.domFrameDocument = domFrameDocument;
|
|
585
|
+
exports.domPacketsUntil = domPacketsUntil;
|
|
586
|
+
exports.domSeqAt = domSeqAt;
|