"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./core.cjs");let l=!1,c=null;function h(e,n=document.documentElement,t=null){return n instanceof ShadowRoot&&console.warn("[Dialtone] You passed a ShadowRoot directly to setTheme(). Please pass the host element instead. The function will access shadowRoot automatically."),e.base?b(e,n,t):f(e,n)}function b(e,n=document.documentElement,t=null){w(e.base.name,e.brand.name,n),n!=null&&n.shadowRoot&&(n=n.shadowRoot),s("dialtone-css-theme",e.base.css,n),s("dialtone-css-brand",e.brand.css,n),t?(s("dialtone-css-contrast",t.css,n),n==null||n.setAttribute("data-dt-contrast","high")):(i("dialtone-css-contrast",n),n==null||n.setAttribute("data-dt-contrast","default"))}function f(e,n=document.documentElement){n!=null&&n.shadowRoot&&(n=n.shadowRoot),e.core&&!l&&(s("dialtone-css-core",e.core,n),l=!0),e.baseColors&&!(n!=null&&n.querySelector("#dialtone-css-base-colors"))&&s("dialtone-css-base-colors",e.baseColors,n),e.brand&&(s("dialtone-css-brand-colors",e.brand.css,n),n==null||n.setAttribute("data-dt-brand",e.brand.name)),e.contrast&&(s("dialtone-css-contrast",e.contrast.css,n),n==null||n.setAttribute("data-dt-contrast",e.contrast.name))}function s(e,n,t){if(t!=null&&t.querySelector("#"+e)){const a=t.querySelector("#"+e);a.innerHTML=n}else{const a=document.createElement("style");a.setAttribute("type","text/css"),a.setAttribute("id",e),a.innerHTML=n,t!=null&&t.querySelector("head")?t.querySelector("head").appendChild(a):t==null||t.appendChild(a)}}function i(e,n){const t=n==null?void 0:n.querySelector("#"+e);t&&t.remove()}function w(e,n,t){t==null||t.setAttribute("data-dt-theme",e),t==null||t.setAttribute("data-dt-brand",n)}function u(e,n=document.documentElement){if(e!=="light"&&e!=="dark"){console.warn(`Invalid mode: ${e}. Must be 'light' or 'dark'`);return}n instanceof ShadowRoot&&console.warn("[Dialtone] You passed a ShadowRoot directly to setMode(). Please pass the host element instead. The function will access shadowRoot automatically."),n!=null&&n.shadowRoot&&(n=n.shadowRoot),n==null||n.setAttribute("data-dt-mode",e)}function r(e,n=document.documentElement){if(!e||typeof e!="object")throw new TypeError("[Dialtone] setBrand: brandTheme must be an object. Import a brand theme like: import Dp from '@dialpad/dialtone-tokens/themes/dp';");if(!e.brand||typeof e.brand!="object")throw new TypeError("[Dialtone] setBrand: brandTheme.brand must be an object with {name, css} properties.");if(typeof e.brand.name!="string"||!e.brand.name)throw new TypeError("[Dialtone] setBrand: brandTheme.brand.name must be a non-empty string.");if(typeof e.brand.css!="string")throw new TypeError("[Dialtone] setBrand: brandTheme.brand.css must be a string containing CSS.");n instanceof ShadowRoot&&console.warn("[Dialtone] You passed a ShadowRoot directly to setBrand(). Please pass the host element instead. The function will access shadowRoot automatically."),n!=null&&n.shadowRoot&&(n=n.shadowRoot),s("dialtone-css-brand-colors",e.brand.css,n),n==null||n.setAttribute("data-dt-brand",e.brand.name)}function d(e,n=document.documentElement){n instanceof ShadowRoot&&console.warn("[Dialtone] You passed a ShadowRoot directly to setContrast(). Please pass the host element instead. The function will access shadowRoot automatically."),n!=null&&n.shadowRoot&&(n=n.shadowRoot),e&&e.contrast?(s("dialtone-css-contrast",e.contrast.css,n),n==null||n.setAttribute("data-dt-contrast",e.contrast.name)):(i("dialtone-css-contrast",n),n==null||n.setAttribute("data-dt-contrast","default"))}function y(e,n="light",t=document.documentElement){if(!e||typeof e!="object")throw new TypeError("[Dialtone] initDialtoneTheme: brandTheme must be an object. Import a brand theme like: import Dp from '@dialpad/dialtone-tokens/themes/dp';");if(!e.brand||typeof e.brand!="object")throw new TypeError("[Dialtone] initDialtoneTheme: brandTheme.brand must be an object with {name, css} properties. Ensure you're importing a valid brand theme.");if(typeof e.brand.name!="string"||!e.brand.name)throw new TypeError("[Dialtone] initDialtoneTheme: brandTheme.brand.name must be a non-empty string.");if(typeof e.brand.css!="string")throw new TypeError("[Dialtone] initDialtoneTheme: brandTheme.brand.css must be a string containing CSS.");if(n!=="light"&&n!=="dark")throw new TypeError(`[Dialtone] initDialtoneTheme: mode must be 'light' or 'dark', got '${n}'.`);if(!t||typeof t!="object")throw new TypeError("[Dialtone] initDialtoneTheme: rootNode must be an HTMLElement or host element with shadowRoot.");if(t instanceof ShadowRoot&&console.warn(`[Dialtone] You passed a ShadowRoot directly to initDialtoneTheme(). Please pass the host element instead. The function will access shadowRoot automatically.
Correct: initDialtoneTheme(brand, mode, hostElement)
Incorrect: initDialtoneTheme(brand, mode, hostElement.shadowRoot)`),t!=null&&t.shadowRoot&&(t=t.shadowRoot),t===document.documentElement&&document.querySelector("#dialtone-css-core")!==null)throw new Error("[Dialtone] Cannot initialize theme on document.documentElement because theme styles already exist. You are likely in an embedded app/micro-frontend. You MUST pass your own container element as the rootNode parameter. Example: initDialtoneTheme(brandTheme, mode, myAppContainerElement)");const a=c;if(a)if(a.brand===e.brand.name&&a.mode===n){console.warn(`[Dialtone] Theme already initialized with brand '${e.brand.name}' and mode '${n}'. Re-applying the same theme may be unnecessary. If you need to switch themes dynamically, use setBrand() or setMode() instead of calling initDialtoneTheme() again.`);return}else{console.warn(`[Dialtone] Theme already initialized. Previous: brand='${a.brand}', mode='${a.mode}'. New: brand='${e.brand.name}', mode='${n}'. Re-initializing with different parameters. Consider using setBrand()/setMode() for dynamic switching.`);return}s("dialtone-css-core",m.core,t),l=!0,s("dialtone-css-base-colors",m.baseColors,t),u(n,t),r(e,t),t==null||t.setAttribute("data-dt-contrast","default"),c={brand:e.brand.name,mode:n,contrast:"default"}}function p(e=document.documentElement){const n=(e==null?void 0:e.shadowRoot)||e;c=null,l=!1,i("dialtone-css-core",n),i("dialtone-css-base-colors",n),i("dialtone-css-brand-colors",n),i("dialtone-css-contrast",n),n==null||n.removeAttribute("data-dt-mode"),n==null||n.removeAttribute("data-dt-brand"),n==null||n.removeAttribute("data-dt-contrast")}exports.initDialtoneTheme=y;exports.resetTheme=p;exports.setBrand=r;exports.setContrast=d;exports.setMode=u;exports.setTheme=h;
