UNPKG

@porsche-design-system/components-js

Version:

Porsche Design System is a component library designed to help developers create the best experience for software or services distributed by Dr. Ing. h.c. F. Porsche AG.

1 lines 2.37 kB
const e="porscheDesignSystem";function t(){return document[e]||(document[e]={}),document[e]}function n({script:n,version:s,prefix:o}){const c=function(e){const n=t(),{[e]:s}=n;if(!s){let t=()=>{};const s=new Promise((e=>t=e));n[e]={isInjected:!1,isReady:()=>s,readyResolve:t,prefixes:[],registerCustomElements:null}}return n[e]}(s),{isInjected:r,prefixes:i=[],registerCustomElements:d}=c,[m]=Object.entries(t()).filter((([e,t])=>e!==s&&"object"==typeof t&&t.prefixes.includes(o)));if(m)throw new Error(`[Porsche Design System v${s}] prefix '${o}' is already registered with version '${m[0]}' of the Porsche Design System. Please use a different one.\nTake a look at document.${e} for more details.`);r||(function(e){const t=document.createElement("script");t.src=e,t.setAttribute("crossorigin",""),document.body.appendChild(t)}(n),c.isInjected=!0),i.includes(o)||(i.push(o),d&&d(o))}const s=(e={})=>{const t="PORSCHE_DESIGN_SYSTEM_CDN";window[t]=e.cdn||window[t]||(window.location.origin.match(/\.cn$/)?"cn":"auto");const s="porscheDesignSystem";document[s]||(document[s]={}),document[s].cdn={url:"https://cdn.ui.porsche."+("cn"===window[t]?"cn":"com"),prefixes:[]},n({version:"3.35.0",script:document[s].cdn.url+"/porsche-design-system/components/porsche-design-system.v3.35.0.fc0e5167830f415f8a1c.js",prefix:e.prefix||""})},o={loading:0,interactive:1,complete:2},c=(e=document.body,t="complete")=>{let n;const s=new Promise((e=>n=e)),o=()=>{i().then((()=>d(e,n)))};if(r(t))o();else{const e="readystatechange",n=()=>{r(t)&&(document.removeEventListener(e,n),o())};document.addEventListener(e,n)}return s},r=e=>o[document.readyState]>=o[e],i=()=>{if(document.porscheDesignSystem?.["3.35.0"]?.isReady)return document.porscheDesignSystem["3.35.0"].isReady();let e;const t=new Promise((t=>e=t)),n={set(t,n,s){return"3.35.0"===n&&s.isReady().then(e),Reflect.set(...arguments)}};return document.porscheDesignSystem=new Proxy(document.porscheDesignSystem||{},n),t},d=(e,t)=>{const n=m(e);Promise.all(n).then((e=>t(e.length))).catch((e=>console.error("[Porsche Design System]",e)))},m=e=>{const t=[],n=[e];for(;n.length>0;){const e=n.pop();e.nodeType===Node.ELEMENT_NODE&&(p(e)&&t.push(e.componentOnReady()),n.push(...Array.from(e.children)))}return t},u=/^(.*-)?P-(.*)$/,p=e=>u.test(e.tagName)&&"function"==typeof e.componentOnReady;export{c as componentsReady,s as load};