@tldraw/editor
Version:
tldraw infinite canvas SDK (editor).
8 lines (7 loc) • 2.6 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/lib/exports/domUtils.ts"],
"sourcesContent": ["export function getRenderedChildNodes(node: Element): Iterable<Node> {\n\tif (node.shadowRoot) {\n\t\t// if this is a custom element with a shadow root, then it's the shadow root's children that\n\t\t// are visible in the DOM. This is only accessible if they created the shadow root with\n\t\t// `mode: 'open'` though.\n\t\treturn node.shadowRoot.childNodes\n\t}\n\tif (isShadowSlotElement(node)) {\n\t\t// if this is a `<slot>` within a shadow root, we should render the nodes that are being\n\t\t// templated into the slot instead of the slot children itself.\n\t\tconst assignedNodes = node.assignedNodes()\n\t\tif (assignedNodes?.length) {\n\t\t\treturn assignedNodes\n\t\t}\n\t}\n\treturn node.childNodes\n}\n\nexport function* getRenderedChildren(node: Element) {\n\tfor (const child of getRenderedChildNodes(node)) {\n\t\tif (isElement(child)) yield child\n\t}\n}\n\nfunction getWindow(node: Node) {\n\treturn node.ownerDocument?.defaultView ?? globalThis\n}\n\nexport function isElement(node: Node): node is Element {\n\treturn node instanceof getWindow(node).Element\n}\n\nfunction isShadowRoot(node: Node): node is ShadowRoot {\n\treturn node instanceof getWindow(node).ShadowRoot\n}\n\nfunction isInShadowRoot(node: Node) {\n\treturn 'getRootNode' in node && isShadowRoot(node.getRootNode())\n}\n\nfunction isShadowSlotElement(node: Node): node is HTMLSlotElement {\n\treturn isInShadowRoot(node) && node instanceof getWindow(node).HTMLSlotElement\n}\n\nexport function elementStyle(element: Element) {\n\treturn (element as HTMLElement | SVGElement).style\n}\n\nexport function getComputedStyle(element: Element, pseudoElement?: string) {\n\treturn getWindow(element).getComputedStyle(element, pseudoElement)\n}\n"],
"mappings": "AAAO,SAAS,sBAAsB,MAA+B;AACpE,MAAI,KAAK,YAAY;AAIpB,WAAO,KAAK,WAAW;AAAA,EACxB;AACA,MAAI,oBAAoB,IAAI,GAAG;AAG9B,UAAM,gBAAgB,KAAK,cAAc;AACzC,QAAI,eAAe,QAAQ;AAC1B,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO,KAAK;AACb;AAEO,UAAU,oBAAoB,MAAe;AACnD,aAAW,SAAS,sBAAsB,IAAI,GAAG;AAChD,QAAI,UAAU,KAAK,EAAG,OAAM;AAAA,EAC7B;AACD;AAEA,SAAS,UAAU,MAAY;AAC9B,SAAO,KAAK,eAAe,eAAe;AAC3C;AAEO,SAAS,UAAU,MAA6B;AACtD,SAAO,gBAAgB,UAAU,IAAI,EAAE;AACxC;AAEA,SAAS,aAAa,MAAgC;AACrD,SAAO,gBAAgB,UAAU,IAAI,EAAE;AACxC;AAEA,SAAS,eAAe,MAAY;AACnC,SAAO,iBAAiB,QAAQ,aAAa,KAAK,YAAY,CAAC;AAChE;AAEA,SAAS,oBAAoB,MAAqC;AACjE,SAAO,eAAe,IAAI,KAAK,gBAAgB,UAAU,IAAI,EAAE;AAChE;AAEO,SAAS,aAAa,SAAkB;AAC9C,SAAQ,QAAqC;AAC9C;AAEO,SAAS,iBAAiB,SAAkB,eAAwB;AAC1E,SAAO,UAAU,OAAO,EAAE,iBAAiB,SAAS,aAAa;AAClE;",
"names": []
}