import{defineSmartComponent as e}from"./lib/smart/define-smart-component.js";import"./cc-smart-container.js";import"./cc-web-features-tracker.js";e({selector:"cc-web-features-tracker",params:{trackedWebFeatures:{type:Object}},onContextUpdate({context:e,updateComponent:s,signal:a}){const{trackedWebFeatures:n}=e,o=new t(n,a);s("state",{type:"loading",webFeatures:Object.values(n).flat().map((e=>({featureId:e.featureId,featureName:e.featureId,comment:e.comment,category:e.category,canBeUsedWithPolyfill:e.canBeUsedWithPolyfill,isProgressiveEnhancement:e.isProgressiveEnhancement})))}),o.getWebFeaturesData().then((({rawBaselineFeatures:e,rawBcdFeatures:t,bcdBrowserInfos:a})=>{const o=new r({trackedWebFeatures:n,rawBcdFeatures:t,rawBaselineFeatures:e,bcdBrowserInfos:a});s("state",{type:"loaded",webFeatures:o.getFormattedFeatures()})})).catch((e=>{console.error(e),s("state",{type:"error"})}))}});class t{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async#r(){const e=await fetch("https://unpkg.com/@mdn/browser-compat-data/data.json",{signal:this.#t});if(!e.ok)throw new Error(e.status.toString());const t=await e.json();return{bcdBrowserInfos:t.browsers,rawBcdFeatures:this.#s(t)}}#s(e){return this.#e.bcdFeatures.map((({featureId:t})=>{const r=t.split(".");let s=e;for(const e of r)s=s[e];return{id:t,...s.__compat}}))}#a(){const e=this.#e.baselineFeatures.map((e=>`https://api.webstatus.dev/v1/features/${e.featureId}`));return Promise.all(e.map((e=>fetch(e,{signal:this.#t}).then((e=>{if(e.ok)return e.json();throw new Error(e.status.toString())})))))}async getWebFeaturesData(){const{bcdBrowserInfos:e,rawBcdFeatures:t}=await this.#r();return{bcdBrowserInfos:e,rawBcdFeatures:t,rawBaselineFeatures:await this.#a()}}}class r{#e;#n;#o;#i;constructor({trackedWebFeatures:e,rawBaselineFeatures:t,rawBcdFeatures:r,bcdBrowserInfos:s}){this.#e=e,this.#n=t,this.#o=r,this.#i=s}getFormattedFeatures(){return[...this.#u(this.#n),...this.#c(this.#o,this.#i)].sort(((e,t)=>e.featureName.localeCompare(t.featureName)))}#u(e){return e.map((e=>{const t=e.baseline.status,{featureId:r,isProgressiveEnhancement:s,canBeUsedWithPolyfill:a,comment:n,category:o}=this.#e.baselineFeatures.find((t=>t.featureId===e.feature_id));return{featureId:r,featureName:e.name,currentStatus:t,comment:n,category:o,isProgressiveEnhancement:s,canBeUsedWithPolyfill:a,canBeUsed:this.#d({currentStatus:t,isProgressiveEnhancement:s,canBeUsedWithPolyfill:a}),chromeSupport:this.#l("chrome",e),firefoxSupport:this.#l("firefox",e),safariSupport:this.#l("safari",e)}}))}#c(e,t){return e.map((e=>{const r={chrome:this.#f("chrome",e,t),firefox:this.#f("firefox",e,t),safari:this.#f("safari",e,t)},s=Object.values(r),{featureId:a,isProgressiveEnhancement:n,canBeUsedWithPolyfill:o,comment:i,category:u}=this.#e.bcdFeatures.find((t=>t.featureId===e.id)),c=this.#h(s);return{featureId:a,featureName:e.description??e.id,currentStatus:c,comment:i,category:u,isProgressiveEnhancement:n,canBeUsedWithPolyfill:o,canBeUsed:this.#d({currentStatus:c,isProgressiveEnhancement:n,canBeUsedWithPolyfill:o}),chromeSupport:r.chrome,firefoxSupport:r.firefox,safariSupport:r.safari}}))}#d({currentStatus:e,isProgressiveEnhancement:t,canBeUsedWithPolyfill:r}){return!("widely"!==e&&!r)||t&&"newly"===e}#l(e,t){const r=t.browser_implementations?.[e];return null==r?{isSupported:!1}:{isSupported:!0,version:r.version,releaseDate:new Date(r.date)}}#f(e,t,r){const s=t.support[e].version_added;return!1===s?{isSupported:!1}:{isSupported:!0,version:s,releaseDate:new Date(r[e].releases[s].release_date)}}#h(e){if(e.some((e=>!e.isSupported)))return"limited";return e.every((e=>e.isSupported&&this.#m(e.releaseDate)))?"widely":"newly"}#m(e){const t=Date.now(),r=new Date;return r.setFullYear(r.getFullYear()-2),r.setMonth(r.getMonth()-6),t-e.getTime()>=t-r.getTime()}}
//# sourceMappingURL=cc-web-features-tracker.smart.js.map
