{"version":3,"names":["filterNonWhitespaceNodes","nodes","filter","node","nodeName","nodeValue","replace","length","getSlottedElements","slotElement","singleLevelElements","assignedNodes","multiLevelElements","forEach","element","push","hasSlotted","hostElement","slotName","slottedElements","Array","from","childNodes","querySelectorAll","find","slottedElement","isElementWithContent","localName","assignedElements","assignedElement","isSlottedInto","targetElement","slottedNodes","includes","querySelector","toLowerCase"],"sources":["../src/utils/slotted.ts"],"sourcesContent":["const filterNonWhitespaceNodes = (nodes: Node[]) => {\n\treturn nodes.filter(\n\t\t(node) => node.nodeName !== '#text' || (node.nodeValue && node.nodeValue.replace(/[\\n\\r\\t]/g, '').length > 0),\n\t);\n};\n\n/**\n * Return elements in a given slot\n *\n * @param slotElement The element to get nodes of\n */\nexport const getSlottedElements = (slotElement: HTMLSlotElement): HTMLElement[] => {\n\t// Get directly slotted elements (can include other slots)\n\tconst singleLevelElements = filterNonWhitespaceNodes(slotElement.assignedNodes()) as HTMLElement[];\n\n\t// Get all slotted elements, including from multiple levels of slots\n\tconst multiLevelElements: HTMLElement[] = [];\n\tsingleLevelElements.forEach((element) => {\n\t\tif (element.nodeName === 'SLOT') {\n\t\t\tmultiLevelElements.push(...getSlottedElements(element as HTMLSlotElement));\n\t\t} else {\n\t\t\tmultiLevelElements.push(element);\n\t\t}\n\t});\n\n\treturn multiLevelElements;\n};\n\n/**\n * Returns whether a slot of the given host element is filled.\n * Also takes into account slots that as passed on to sub-components.\n *\n * @param {Element} hostElement - The shadow root host element that the slot belongs to\n * @param {string} [slotName] - The name of the slot to search for. If not specified, all slots are checked\n * @returns {boolean} - True if the element has the specified slot assigned, false otherwise\n */\nexport function hasSlotted(hostElement: Element, slotName?: string): boolean {\n\tif (!slotName) {\n\t\t// No slot specified, so check all child nodes\n\t\tconst slottedElements = filterNonWhitespaceNodes(Array.from(hostElement.childNodes));\n\t\treturn slottedElements.length > 0;\n\t}\n\n\t// Query for the first direct child element of hostElement that has a slot attribute with the value of slotName\n\tconst slottedElements: HTMLElement[] = Array.from(hostElement.querySelectorAll(`:scope > [slot=\"${slotName}\"]`));\n\n\treturn !!slottedElements.find((slottedElement) => isElementWithContent(slottedElement));\n}\n\n/** Returns true if this is a non-slot node, or a slot filled with content */\nconst isElementWithContent = (element: HTMLElement): boolean => {\n\tif (element.localName !== 'slot') return true;\n\n\tconst assignedElements = filterNonWhitespaceNodes((element as HTMLSlotElement).assignedElements());\n\treturn !!assignedElements.find((assignedElement) => isElementWithContent(assignedElement as HTMLElement));\n};\n\n/**\n * Returns whether a given target element is slotted in a particular host element.\n * Also takes into account slots that as passed on to sub-components.\n *\n * @param {Element} targetElement - The element to look for\n * @param {Element} hostElement - The shadow root host element that the slot belongs to\n * @param {string} [slotName] - The name of the slot to search for. If not specified, all slots are checked\n * @returns {boolean} - True if the element has the specified slot assigned, false otherwise\n */\nexport function isSlottedInto(targetElement: Element, hostElement: Element, slotName?: string): boolean {\n\tif (!slotName) {\n\t\t// No slot specified, so check all child nodes\n\t\tconst slottedNodes = Array.from(hostElement.childNodes);\n\t\treturn slottedNodes.includes(targetElement);\n\t}\n\n\t// Query for the first direct child element of hostElement that has a slot attribute with the value of slotName\n\tconst slottedElement: HTMLElement | null = hostElement.querySelector(`:scope > [slot=\"${slotName}\"]`);\n\tif (slottedElement === targetElement) {\n\t\treturn true;\n\t}\n\n\tif (slottedElement && slottedElement.nodeName.toLowerCase() === 'slot') {\n\t\t// The slotted element is a slot itself, so check its slotted content\n\t\tconst assignedNodes = (slottedElement as HTMLSlotElement).assignedNodes();\n\t\treturn assignedNodes?.includes(targetElement);\n\t}\n\n\treturn false;\n}\n"],"mappings":"AAAA,MAAMA,EAA4BC,GAC1BA,EAAMC,QACXC,GAASA,EAAKC,WAAa,SAAYD,EAAKE,WAAaF,EAAKE,UAAUC,QAAQ,YAAa,IAAIC,OAAS,I,MAShGC,EAAsBC,IAElC,MAAMC,EAAsBV,EAAyBS,EAAYE,iBAGjE,MAAMC,EAAoC,GAC1CF,EAAoBG,SAASC,IAC5B,GA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