MCPcopy Create free account
hub / github.com/CanadaHonk/shadow / constructLayout

Function constructLayout

engine/layout.js:1607–1663  ·  view source on GitHub ↗
(document, renderer)

Source from the content-addressed store, hash-verified

1605};
1606
1607export const constructLayout = async (document, renderer) => {
1608 const assembleLayoutNodes = x => {
1609 const a = new LayoutNode(x, renderer);
1610 a.children = a.children.map(y => {
1611 const z = assembleLayoutNodes(y);
1612 z.parent = a;
1613 return z;
1614 });
1615
1616 return a;
1617 };
1618
1619 const doc = assembleLayoutNodes(document);
1620 doc.root = doc.querySelector('html');
1621 profileSubstep('assemble');
1622
1623 const reSetDoc = x => {
1624 x.document = doc;
1625 x.root = doc.root; // <html>/:root
1626 for (const y of x.children) reSetDoc(y);
1627 };
1628 reSetDoc(doc);
1629 profileSubstep('reset doc');
1630
1631 removeDeadTextNodes(doc);
1632 profileSubstep('rm dead text');
1633
1634 profileStep('construct layout');
1635
1636 processTime = {
1637 style: 0,
1638 link_stylesheet: 0,
1639 script: 0
1640 };
1641
1642 await doc.process();
1643
1644 for (const x in processTime) {
1645 profileSubsteps[x.replaceAll('_', ' ')] = processTime[x];
1646 }
1647 profile.lastSub = true;
1648
1649 profileStep('process layout');
1650
1651 // go to top of page
1652 scrollY = 0;
1653 if (window.onresize) window.onresize('ignore_last'); // hack: update it
1654
1655 renderer.layout = doc;
1656
1657 const body = doc.querySelector('body');
1658 if (body && body.attrs.onload) setTimeout(() => {
1659 window._js.run(doc, body.attrs.onload);
1660 }, 10);
1661
1662 return doc;
1663};
1664

Callers 1

_loadFunction · 0.90

Calls 6

assembleLayoutNodesFunction · 0.85
reSetDocFunction · 0.85
removeDeadTextNodesFunction · 0.85
setTimeoutFunction · 0.85
processMethod · 0.80
querySelectorMethod · 0.45

Tested by

no test coverage detected