import{Runtime as e}from"../../root/root.js";import{ThemeSupport as t}from"../../theme_support/theme_support.js";function n(n,o,c={enableLegacyPatching:!1}){const s=e.cachedResources.get(o)||"";s||console.error(o+" not preloaded. Check module.json");let i=document.createElement("style");if(i.textContent=s,n.appendChild(i),c.enableLegacyPatching){const c=t.instance().themeStyleSheet(o,s);c&&(i=document.createElement("style"),i.textContent=c+"\n"+e.Runtime.resolveSourceURL(o+".theme"),n.appendChild(i))}}function o(e){const t=e.target&&e.target.ownerDocument,n=t?t.deepActiveElement():null;!function(e){for(;e&&!e.__widget;)e=e.parentNodeOrShadowHost();if(!e)return;let t=e.__widget;for(;t._parentWidget;)t._parentWidget._defaultFocusedChild=t,t=t._parentWidget}(n),function(e){e=e&&e.parentNodeOrShadowHost();const t=customElements.get("x-widget");let n=null;for(;e;)e instanceof t&&(n&&(e._defaultFocusedElement=n),n=e),e=e.parentNodeOrShadowHost()}(n)}function c(e){n(e,"ui/inspectorCommon.css",{enableLegacyPatching:!0}),n(e,"ui/textButton.css",{enableLegacyPatching:!0}),t.instance().injectHighlightStyleSheets(e),t.instance().injectCustomStyleSheets(e)}function s(e,t={delegatesFocus:void 0,cssFile:void 0,enableLegacyPatching:!1}){const{cssFile:s,delegatesFocus:i,enableLegacyPatching:r}=t,a=e.attachShadow({mode:"open",delegatesFocus:i});return c(a),s&&n(a,s,{enableLegacyPatching:r}),a.addEventListener("focus",o,!0),a}let i;function r(e){if("number"==typeof i)return i;if(!e)return 16;const t=e.createElement("div"),n=e.createElement("div");return t.setAttribute("style","display: block; width: 100px; height: 100px; overflow: scroll;"),n.setAttribute("style","height: 200px"),t.appendChild(n),e.body.appendChild(t),i=t.offsetWidth-t.clientWidth,e.body.removeChild(t),i}function a(e,t,n){return self.customElements.define(t,class extends n{constructor(){super(),this.setAttribute("is",t)}},{extends:e}),()=>document.createElement(e,{is:t})}export{n as appendStyle,s as createShadowRootWithCoreStyles,o as focusChanged,c as injectCoreStyles,r as measuredScrollbarWidth,a as registerCustomElement};
