import*as i18n from"../i18n/i18n.js";const UIStrings={text:"(text)"},str_=i18n.i18n.registerUIStrings("elements/ElementsBreadcrumbsUtils.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export const crumbsToRender=(e,t)=>t?e.filter((e=>e.nodeType!==Node.DOCUMENT_NODE)).map((e=>({title:determineElementTitle(e),selected:e.id===t.id,node:e,originalNode:e.legacyDomNode}))).reverse():[];const makeCrumbTitle=(e,t={})=>({main:e,extras:t});export class NodeSelectedEvent extends Event{constructor(e){super("node-selected",{}),this.data=e.legacyDomNode}}export const determineElementTitle=e=>{switch(e.nodeType){case Node.ELEMENT_NODE:{if(e.pseudoType)return makeCrumbTitle("::"+e.pseudoType);const t=makeCrumbTitle(e.nodeNameNicelyCased),r=e.getAttribute("id");r&&(t.extras.id=r);const s=e.getAttribute("class");if(s){const e=new Set(s.split(/\s+/));t.extras.classes=Array.from(e)}return t}case Node.TEXT_NODE:return makeCrumbTitle(i18nString(UIStrings.text));case Node.COMMENT_NODE:return makeCrumbTitle("\x3c!--\x3e");case Node.DOCUMENT_TYPE_NODE:return makeCrumbTitle("<!doctype>");case Node.DOCUMENT_FRAGMENT_NODE:return makeCrumbTitle(e.shadowRootType?"#shadow-root":e.nodeNameNicelyCased);default:return makeCrumbTitle(e.nodeNameNicelyCased)}};