Skip to content

Commit 627d205

Browse files
committed
Rebase and merge
2 parents b798019 + e4f680e commit 627d205

40 files changed

+456
-390
lines changed

packages/rrdom/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rrdom",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"scripts": {
55
"dev": "rollup -c -w",
66
"bundle": "rollup --config",
@@ -33,7 +33,7 @@
3333
"rollup": "^2.56.3",
3434
"rollup-plugin-terser": "^7.0.2",
3535
"rollup-plugin-typescript2": "^0.30.0",
36-
"rrweb-snapshot": "^1.1.13",
36+
"rrweb-snapshot": "^1.1.14",
3737
"ts-jest": "^27.0.5",
3838
"typescript": "^3.9.5"
3939
},

packages/rrweb-player/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rrweb-player",
3-
"version": "0.7.13",
3+
"version": "0.7.14",
44
"devDependencies": {
55
"@rollup/plugin-commonjs": "^11.0.0",
66
"@rollup/plugin-node-resolve": "^7.0.0",
@@ -25,7 +25,7 @@
2525
},
2626
"dependencies": {
2727
"@tsconfig/svelte": "^1.0.0",
28-
"rrweb": "^1.1.2"
28+
"rrweb": "^1.1.3"
2929
},
3030
"scripts": {
3131
"build": "rollup -c",

packages/rrweb-snapshot/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ There are several things will be done during rebuild:
3737

3838
#### buildNodeWithSN
3939

40-
`buildNodeWithSN` will build DOM from serialized node and store serialized information in `__sn` property.
40+
`buildNodeWithSN` will build DOM from serialized node and store serialized information in the `mirror.getMeta(node)`.

packages/rrweb-snapshot/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rrweb-snapshot",
3-
"version": "1.1.13",
3+
"version": "1.1.14",
44
"description": "rrweb's component to take a snapshot of DOM, aka DOM serializer",
55
"scripts": {
66
"prepare": "npm run prepack",

packages/rrweb-snapshot/src/css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ function addParent(obj: Stylesheet, parent?: Stylesheet) {
892892
addParent(v, childParent);
893893
});
894894
} else if (value && typeof value === 'object') {
895-
addParent((value as unknown) as Stylesheet, childParent);
895+
addParent(value as Stylesheet, childParent);
896896
}
897897
}
898898

packages/rrweb-snapshot/src/rebuild.ts

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import {
44
NodeType,
55
tagMap,
66
elementNode,
7-
idNodeMap,
8-
INode,
97
BuildCache,
108
} from './types';
11-
import { isElement } from './utils';
9+
import { isElement, Mirror } from './utils';
1210

1311
const tagMap: tagMap = {
1412
script: 'noscript',
@@ -215,7 +213,10 @@ function buildNode(
215213
n.attributes.rr_dataURL
216214
) {
217215
// backup original img srcset
218-
node.setAttribute('rrweb-original-srcset', n.attributes.srcset as string);
216+
node.setAttribute(
217+
'rrweb-original-srcset',
218+
n.attributes.srcset as string,
219+
);
219220
} else {
220221
node.setAttribute(name, value);
221222
}
@@ -307,16 +308,16 @@ export function buildNodeWithSN(
307308
n: serializedNodeWithId,
308309
options: {
309310
doc: Document;
310-
map: idNodeMap;
311+
mirror: Mirror;
311312
skipChild?: boolean;
312313
hackCss: boolean;
313-
afterAppend?: (n: INode) => unknown;
314+
afterAppend?: (n: Node) => unknown;
314315
cache: BuildCache;
315316
},
316-
): INode | null {
317+
): Node | null {
317318
const {
318319
doc,
319-
map,
320+
mirror,
320321
skipChild = false,
321322
hackCss = true,
322323
afterAppend,
@@ -328,7 +329,7 @@ export function buildNodeWithSN(
328329
}
329330
if (n.rootId) {
330331
console.assert(
331-
((map[n.rootId] as unknown) as Document) === doc,
332+
(mirror.getNode(n.rootId) as Document) === doc,
332333
'Target document should has the same root id.',
333334
);
334335
}
@@ -362,8 +363,7 @@ export function buildNodeWithSN(
362363
node = doc;
363364
}
364365

365-
(node as INode).__sn = n;
366-
map[n.id] = node as INode;
366+
mirror.add(node, n);
367367

368368
if (
369369
(n.type === NodeType.Document || n.type === NodeType.Element) &&
@@ -372,7 +372,7 @@ export function buildNodeWithSN(
372372
for (const childN of n.childNodes) {
373373
const childNode = buildNodeWithSN(childN, {
374374
doc,
375-
map,
375+
mirror,
376376
skipChild: false,
377377
hackCss,
378378
afterAppend,
@@ -394,27 +394,27 @@ export function buildNodeWithSN(
394394
}
395395
}
396396

397-
return node as INode;
397+
return node;
398398
}
399399

400-
function visit(idNodeMap: idNodeMap, onVisit: (node: INode) => void) {
401-
function walk(node: INode) {
400+
function visit(mirror: Mirror, onVisit: (node: Node) => void) {
401+
function walk(node: Node) {
402402
onVisit(node);
403403
}
404404

405-
for (const key in idNodeMap) {
406-
if (idNodeMap[key]) {
407-
walk(idNodeMap[key]);
405+
for (const id of mirror.getIds()) {
406+
if (mirror.has(id)) {
407+
walk(mirror.getNode(id)!);
408408
}
409409
}
410410
}
411411

412-
function handleScroll(node: INode) {
413-
const n = node.__sn;
414-
if (n.type !== NodeType.Element) {
412+
function handleScroll(node: Node, mirror: Mirror) {
413+
const n = mirror.getMeta(node);
414+
if (n?.type !== NodeType.Element) {
415415
return;
416416
}
417-
const el = (node as Node) as HTMLElement;
417+
const el = node as HTMLElement;
418418
for (const name in n.attributes) {
419419
if (!(n.attributes.hasOwnProperty(name) && name.startsWith('rr_'))) {
420420
continue;
@@ -433,29 +433,36 @@ function rebuild(
433433
n: serializedNodeWithId,
434434
options: {
435435
doc: Document;
436-
onVisit?: (node: INode) => unknown;
436+
onVisit?: (node: Node) => unknown;
437437
hackCss?: boolean;
438-
afterAppend?: (n: INode) => unknown;
438+
afterAppend?: (n: Node) => unknown;
439439
cache: BuildCache;
440+
mirror: Mirror;
440441
},
441-
): [Node | null, idNodeMap] {
442-
const { doc, onVisit, hackCss = true, afterAppend, cache } = options;
443-
const idNodeMap: idNodeMap = {};
442+
): Node | null {
443+
const {
444+
doc,
445+
onVisit,
446+
hackCss = true,
447+
afterAppend,
448+
cache,
449+
mirror = new Mirror(),
450+
} = options;
444451
const node = buildNodeWithSN(n, {
445452
doc,
446-
map: idNodeMap,
453+
mirror,
447454
skipChild: false,
448455
hackCss,
449456
afterAppend,
450457
cache,
451458
});
452-
visit(idNodeMap, (visitedNode) => {
459+
visit(mirror, (visitedNode) => {
453460
if (onVisit) {
454461
onVisit(visitedNode);
455462
}
456-
handleScroll(visitedNode);
463+
handleScroll(visitedNode, mirror);
457464
});
458-
return [node, idNodeMap];
465+
return node;
459466
}
460467

461468
export default rebuild;

0 commit comments

Comments
 (0)