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 i=e.cachedResources.get(o)||"";i||console.error(o+" not preloaded. Check module.json");let s=createElement("style");if(s.textContent=i,n.appendChild(s),c.enableLegacyPatching){const c=t.instance().themeStyleSheet(o,i);c&&(s=createElement("style"),s.textContent=c+"\n"+e.Runtime.resolveSourceURL(o+".theme"),n.appendChild(s))}}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 i(e,t={delegatesFocus:void 0,cssFile:void 0,enableLegacyPatching:!1}){const{cssFile:i,delegatesFocus:s,enableLegacyPatching:r}=t,a=e.attachShadow({mode:"open",delegatesFocus:s});return c(a),i&&n(a,i,{enableLegacyPatching:r}),a.addEventListener("focus",o.bind(UI),!0),a}let s;function r(e){if("number"==typeof s)return s;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),s=t.offsetWidth-t.clientWidth,e.body.removeChild(t),s}function a(e,t,n){return self.customElements.define(t,class extends n{constructor(){super(),this.setAttribute("is",t)}},{extends:e}),()=>createElement(e,t)}export{n as appendStyle,i as createShadowRootWithCoreStyles,o as focusChanged,c as injectCoreStyles,r as measuredScrollbarWidth,a as registerCustomElement};
