import{d3 as D}from"./index-Cq8aT7Ma.js";const j="https://www.youtube.com/embed",Y="https://www.youtube-nocookie.com/embed",V="https://www.youtube.com/iframe_api",x="YT",F="onYouTubeIframeAPIReady",M=/(?:youtu\.be\/|youtube(?:-nocookie)?\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=|shorts\/|live\/))((\w|-){11})/,G=/(?:youtu\.be\/|youtube(?:-nocookie)?\.com\/.*?[?&]list=)([\w_-]+)/;function C(i,e={}){const t={src:B(i,e),frameborder:0,width:"100%",height:"100%",allow:"accelerometer; fullscreen; autoplay; encrypted-media; gyroscope; picture-in-picture"};return e.config&&(t["data-config"]=JSON.stringify(e.config)),`
    <style>
      :host {
        display: inline-block;
        line-height: 0;
        position: relative;
        min-width: 300px;
        min-height: 150px;
      }
      iframe {
        position: absolute;
        top: 0;
        left: 0;
      }
    </style>
    <iframe${U(t)}></iframe>
  `}function B(i,e){if(!i.src)return;const t=i.src.includes("-nocookie")?Y:j,n={controls:i.controls===""?null:0,autoplay:i.autoplay,loop:i.loop,mute:i.muted,playsinline:i.playsinline,preload:i.preload??"metadata",enablejsapi:1,showinfo:0,rel:0,iv_load_policy:3,modestbranding:1,...e.config};if(M.test(i.src)){const f=i.src.match(M),m=f&&f[1];return`${t}/${m}?${I(n)}`}const a=i.src.match(G),c={listType:"playlist",list:a&&a[1],...n};return`${t}?${I(c)}`}class H extends(globalThis.HTMLElement??class{}){static getTemplateHTML=C;static shadowRootOptions={mode:"open"};static observedAttributes=["autoplay","controls","crossorigin","loop","muted","playsinline","poster","preload","src"];loadComplete=new P;#n;#s;#t=0;#i=!1;#e;isLoaded=!1;#r=null;#o=null;constructor(){super(),this.#a("config")}get config(){return this.#o}set config(e){this.#o=e}async load(){if(this.#n)return;this.shadowRoot||this.attachShadow({mode:"open"});const e=!this.#s;this.#s&&(this.loadComplete=new P,this.isLoaded=!1),this.#s=!0,await(this.#n=Promise.resolve()),this.#n=null,this.#t=0,this.dispatchEvent(new Event("emptied"));let t=this.api;if(this.api=null,!this.src){t?.destroy();return}this.dispatchEvent(new Event("loadstart"));let n=this.shadowRoot.querySelector("iframe"),a=q(this.attributes);e&&n&&(this.#o=JSON.parse(n.getAttribute("data-config")||"{}")),(!n?.src||n.src!==B(a,this))&&(this.shadowRoot.innerHTML=C(a,this),n=this.shadowRoot.querySelector("iframe"));const r=await z(V,x,F);this.api=new r.Player(n,{events:{onReady:()=>{this.#t=1,this.dispatchEvent(new Event("loadedmetadata")),this.dispatchEvent(new Event("durationchange")),this.dispatchEvent(new Event("volumechange")),this.dispatchEvent(new Event("loadcomplete")),this.isLoaded=!0,this.loadComplete.resolve()},onError:l=>{console.error(l),this.#r={code:l.data,message:`YouTube iframe player error #${l.data}; visit https://developers.google.com/youtube/iframe_api_reference#onError for the full error message.`},this.dispatchEvent(new Event("error"))}}});let c=!1;this.api.addEventListener("onStateChange",l=>{var d;const h=l.data;if((h===r.PlayerState.PLAYING||h===r.PlayerState.BUFFERING)&&(c||(c=!0,this.dispatchEvent(new Event("play")))),h===r.PlayerState.PLAYING)this.seeking&&(this.#i=!1,(d=this.#e)==null||d.resolve(),this.dispatchEvent(new Event("seeked"))),this.#t=3,this.dispatchEvent(new Event("playing"));else if(h===r.PlayerState.PAUSED){const E=Math.abs(this.currentTime-f);!this.seeking&&E>.1&&(this.#i=!0,this.dispatchEvent(new Event("seeking"))),c=!1,this.dispatchEvent(new Event("pause"))}h===r.PlayerState.ENDED&&(c=!1,this.dispatchEvent(new Event("pause")),this.dispatchEvent(new Event("ended")),this.loop&&this.play())}),this.api.addEventListener("onPlaybackRateChange",()=>{this.dispatchEvent(new Event("ratechange"))}),this.api.addEventListener("onVolumeChange",()=>{this.dispatchEvent(new Event("volumechange"))}),this.api.addEventListener("onVideoProgress",()=>{this.dispatchEvent(new Event("timeupdate"))}),await this.loadComplete;let f=0;setInterval(()=>{var l;const d=Math.abs(this.currentTime-f),h=this.buffered.end(this.buffered.length-1);this.seeking&&h>.1?(this.#i=!1,(l=this.#e)==null||l.resolve(),this.dispatchEvent(new Event("seeked"))):!this.seeking&&d>.1&&(this.#i=!0,this.dispatchEvent(new Event("seeking"))),f=this.currentTime},50);let m;const b=setInterval(()=>{const l=this.buffered.end(this.buffered.length-1);l>=this.duration&&(clearInterval(b),this.#t=4),m!=l&&(m=l,this.dispatchEvent(new Event("progress")))},100)}async attributeChangedCallback(e,t,n){if(t!==n)switch(e){case"src":case"autoplay":case"controls":case"loop":case"playsinline":this.load()}}async play(){var e;return this.#e=null,await this.loadComplete,(e=this.api)==null||e.playVideo(),Q(this)}async pause(){var e;return await this.loadComplete,(e=this.api)==null?void 0:e.pauseVideo()}get seeking(){return this.#i}get readyState(){return this.#t}get src(){return this.getAttribute("src")}set src(e){this.src!=e&&this.setAttribute("src",e)}get error(){return this.#r}get paused(){var e,t;return this.isLoaded?[-1,0,2,5].includes((t=(e=this.api)==null?void 0:e.getPlayerState)==null?void 0:t.call(e)):!this.autoplay}get duration(){var e,t;return((t=(e=this.api)==null?void 0:e.getDuration)==null?void 0:t.call(e))??NaN}get autoplay(){return this.hasAttribute("autoplay")}set autoplay(e){this.autoplay!=e&&this.toggleAttribute("autoplay",!!e)}get buffered(){var e,t;if(!this.isLoaded)return k();const n=((e=this.api)==null?void 0:e.getVideoLoadedFraction())*((t=this.api)==null?void 0:t.getDuration());return n>0?k(0,n):k()}get controls(){return this.hasAttribute("controls")}set controls(e){this.controls!=e&&this.toggleAttribute("controls",!!e)}get currentTime(){var e,t;return((t=(e=this.api)==null?void 0:e.getCurrentTime)==null?void 0:t.call(e))??0}set currentTime(e){this.currentTime!=e&&(this.#e=new P,this.loadComplete.then(()=>{var t,n;(t=this.api)==null||t.seekTo(e,!0),this.paused&&((n=this.#e)==null||n.then(()=>{var a;this.#e&&((a=this.api)==null||a.pauseVideo())}))}))}set defaultMuted(e){this.defaultMuted!=e&&this.toggleAttribute("muted",!!e)}get defaultMuted(){return this.hasAttribute("muted")}get loop(){return this.hasAttribute("loop")}set loop(e){this.loop!=e&&this.toggleAttribute("loop",!!e)}set muted(e){this.muted!=e&&this.loadComplete.then(()=>{var t,n;e?(t=this.api)==null||t.mute():(n=this.api)==null||n.unMute()})}get muted(){var e,t;return this.isLoaded?(t=(e=this.api)==null?void 0:e.isMuted)==null?void 0:t.call(e):this.defaultMuted}get playbackRate(){var e,t;return((t=(e=this.api)==null?void 0:e.getPlaybackRate)==null?void 0:t.call(e))??1}set playbackRate(e){this.playbackRate!=e&&this.loadComplete.then(()=>{var t;(t=this.api)==null||t.setPlaybackRate(e)})}get playsInline(){return this.hasAttribute("playsinline")}set playsInline(e){this.playsInline!=e&&this.toggleAttribute("playsinline",!!e)}get poster(){return this.getAttribute("poster")}set poster(e){this.poster!=e&&this.setAttribute("poster",`${e}`)}set volume(e){this.volume!=e&&this.loadComplete.then(()=>{var t;(t=this.api)==null||t.setVolume(e*100)})}get volume(){var e;return this.isLoaded?((e=this.api)==null?void 0:e.getVolume())/100:1}#a(e){if(Object.prototype.hasOwnProperty.call(this,e)){const t=this[e];delete this[e],this[e]=t}}}function U(i){let e="";for(const t in i){const n=i[t];n===""?e+=` ${A(t)}`:e+=` ${A(t)}="${A(`${n}`)}"`}return e}function A(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/`/g,"&#x60;")}function I(i){return String(new URLSearchParams(W(i)))}function W(i){let e={};for(let t in i){let n=i[t];n===!0||n===""?e[t]=1:n===!1?e[t]=0:n!=null&&(e[t]=n)}return e}function q(i){let e={};for(let t of i)e[t.name]=t.value;return e}const L={};async function z(i,e,t){return L[i]?L[i]:self[e]?(await J(0),self[e]):L[i]=new Promise(function(n,a){const r=document.createElement("script");r.src=i;const c=()=>n(self[e]);self[t]=c,r.onload=()=>!t,r.onerror=a,document.head.append(r)})}const J=i=>new Promise(e=>setTimeout(e,i));function K(i){return(...e)=>new Promise(t=>{i(...e,(...n)=>{n.length>1?t(n):t(n[0])})})}function Q(i){return K((e,t)=>{let n;i.addEventListener(e,n=()=>{i.removeEventListener(e,n),t()})})("playing")}class P extends Promise{constructor(e=()=>{}){let t,n;super((a,r)=>{e(a,r),t=a,n=r}),this.resolve=t,this.reject=n}}function k(i,e){return Array.isArray(i)?S(i):i==null||e==null||i===0&&e===0?S([[0,0]]):S([[i,e]])}function S(i){return Object.defineProperties(i,{start:{value:e=>i[e][0]},end:{value:e=>i[e][1]}}),i}globalThis.customElements&&!globalThis.customElements.get("youtube-video")&&globalThis.customElements.define("youtube-video",H);var X=H,Z=new Set(["style","children","ref","key","suppressContentEditableWarning","suppressHydrationWarning","dangerouslySetInnerHTML"]),ee={className:"class",htmlFor:"for"};function $(i){return i.toLowerCase()}function O(i){if(typeof i=="boolean")return i?"":void 0;if(typeof i!="function"&&!(typeof i=="object"&&i!==null))return i}function te({react:i,tagName:e,elementClass:t,events:n,displayName:a,defaultProps:r,toAttributeName:c=$,toAttributeValue:f=O}){const m=Number.parseInt(i.version)>=19,b=i.forwardRef((l,d)=>{var h,E;const p=i.useRef(null),_=i.useRef(new Map),T={},R={},g={},w={};for(const[s,o]of Object.entries(l)){if(Z.has(s)){g[s]=o;continue}const u=c(ee[s]??s);if(s in t.prototype&&!(s in(((h=globalThis.HTMLElement)==null?void 0:h.prototype)??{}))&&!((E=t.observedAttributes)!=null&&E.some(y=>y===u))){w[s]=o;continue}if(s.startsWith("on")){T[s]=o;continue}const v=f(o);if(u&&v!=null&&(R[u]=String(v),m||(g[u]=v)),u&&m){const y=O(o);v!==y?g[u]=v:g[u]=o}}if(typeof window<"u"){for(const s in T){const o=T[s],u=s.endsWith("Capture"),v=(n?.[s]??s.slice(2).toLowerCase()).slice(0,u?-7:void 0);i.useLayoutEffect(()=>{const y=p?.current;if(!(!y||typeof o!="function"))return y.addEventListener(v,o,u),()=>{y.removeEventListener(v,o,u)}},[p?.current,o])}i.useLayoutEffect(()=>{if(p.current===null)return;const s=new Map;for(const o in w)N(p.current,o,w[o]),_.current.delete(o),s.set(o,w[o]);for(const[o,u]of _.current)N(p.current,o,void 0);_.current=s})}if(typeof window>"u"&&t?.getTemplateHTML&&t?.shadowRootOptions){const{mode:s,delegatesFocus:o}=t.shadowRootOptions,u=i.createElement("template",{shadowrootmode:s,shadowrootdelegatesfocus:o,dangerouslySetInnerHTML:{__html:t.getTemplateHTML(R,l)}});g.children=[u,g.children]}return i.createElement(e,{...r,...g,ref:i.useCallback(s=>{p.current=s,typeof d=="function"?d(s):d!==null&&(d.current=s)},[d])})});return b.displayName=a??t.name,b}function N(i,e,t){var n;i[e]=t,t==null&&e in(((n=globalThis.HTMLElement)==null?void 0:n.prototype)??{})&&i.removeAttribute(e)}var ne=te({react:D,tagName:"youtube-video",elementClass:X,toAttributeName(i){return i==="muted"?"":i==="defaultMuted"?"muted":$(i)}});/*! Bundled license information:

ce-la-react/dist/ce-la-react.js:
  (**
   * @license
   * Copyright 2018 Google LLC
   * SPDX-License-Identifier: BSD-3-Clause
   *
   * Modified version of `@lit/react` for vanilla custom elements with support for SSR.
   *)
*/export{ne as default};
