feat(vom): discover canvas candidates and resolve visible regions

This commit is contained in:
Ljy-0827
2026-09-10 12:21:19 +08:00
committed by GitHub
parent ba6a14de7c
commit eb6cc0419b
11 changed files with 1446 additions and 17 deletions
@@ -80,6 +80,19 @@ describe("document facts", () => {
boundsSpace: "snapshot-document-layout",
bounds: [10, 20, 120, 40],
styles: {
rotate: "auto",
scale: "auto",
perspective: "auto",
clip: "auto",
contain: "auto",
"overflow-clip-margin": "auto",
display: "auto",
"overflow-x": "auto",
"overflow-y": "auto",
transform: "auto",
zoom: "auto",
"clip-path": "auto",
"mask-image": "auto",
position: "static",
"pointer-events": "auto",
cursor: "auto",
@@ -125,3 +138,42 @@ describe("document facts", () => {
expect(reads).toBeLessThanOrEqual(356);
});
});
describe("visual ancestry facts", () => {
it("distinguishes document roots, malformed roots, missing parents and cycles", async () => {
const input = [
{ ...node(0, null), nodeType: 9 },
{ ...node(1, 0), nodeType: 1 },
{ ...node(2, 1), nodeType: 11 },
node(3, 2),
node(4, 99),
node(5, 6),
node(6, 5),
node(7, 5),
{ ...node(8, null), nodeType: 1 },
{ ...node(9, null), nodeType: 9, parentMissing: true },
];
const index = await buildDocumentIndex(input.reverse());
for (const id of [0, 1, 2, 3]) expect(index.ancestryComplete.get(id)).toBe(true);
for (const id of [4, 5, 6, 7, 8, 9]) expect(index.ancestryComplete.get(id)).toBe(false);
});
it("retains client offsets in their source units and does not disguise missing parent indices", async () => {
const decoded = await decodeDocument(
{
nodes: { backendNodeId: [1, 2], nodeType: [1, 1], nodeName: [0, 0], parentIndex: [99] },
layout: {
nodeIndex: [0],
bounds: [[745, 455.625, 97, 59.5]],
clientRects: [[5, 5, 68, 38]],
},
},
["div"],
);
expect(decoded.nodes[0].layout?.clientRect).toEqual([5, 5, 68, 38]);
expect(decoded.nodes[0].layout?.bounds).toEqual([745, 455.625, 97, 59.5]);
expect(decoded.nodes.every((node) => node.parentMissing)).toBe(true);
const index = await buildDocumentIndex(decoded.nodes);
expect([...index.ancestryComplete.values()]).toEqual([false, false]);
});
});