import{o as e}from"./rolldown-runtime-Bhmf7a9N.js";import{KM as t}from"./lucide-7srpeIMw.js";import{t as n}from"./dist-BVGwaJGV.js";var r=e(t(),1),i=`https://www.youtube.com/embed`,a=`https://www.youtube-nocookie.com/embed`,o=`https://www.youtube.com/iframe_api`,s=`YT`,c=`onYouTubeIframeAPIReady`,l=/(?:youtu\.be\/|youtube(?:-nocookie)?\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=|shorts\/|live\/))((\w|-){11})/,u=/(?:youtu\.be\/|youtube(?:-nocookie)?\.com\/.*?[?&]list=)([\w_-]+)/;function d(e){if(!e)return;let t=e.match(/[?&]t=([\dms]+)/i);if(!t)return;let n=t[1].toLowerCase(),r=0,i=!1,a=n.match(/(\d+)m/);a&&(r+=parseInt(a[1],10)*60,i=!0);let o=n.match(/(\d+)s?$/);return o&&(r+=parseInt(o[1],10),i=!0),i?r:void 0}function f(e,t={}){let n={src:p(e,t),frameborder:0,width:`100%`,height:`100%`,allow:`accelerometer; fullscreen; autoplay; encrypted-media; gyroscope; picture-in-picture`};return t.config?.referrerpolicy&&(n.referrerpolicy=t.config.referrerpolicy),t.config&&(n[`data-config`]=JSON.stringify(t.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${h(n)}></iframe>
  `}function p(e,t){if(!e.src)return;let n=e.src.includes(`-nocookie`)?a:i,r={controls:e.controls===``?null:0,autoplay:e.autoplay,loop:e.loop,mute:e.muted,playsinline:e.playsinline,preload:e.preload??`metadata`,enablejsapi:1,cc_load_policy:1,showinfo:0,rel:0,iv_load_policy:3,modestbranding:1,start:d(e.src),...t.config};if(l.test(e.src)){let t=e.src.match(l);return`${n}/${t&&t[1]}?${_(r)}`}let o=e.src.match(u);return`${n}?${_({listType:`playlist`,list:o&&o[1],...r})}`}var m=class extends n(globalThis.HTMLElement??class{}){static getTemplateHTML=f;static shadowRootOptions={mode:`open`};static observedAttributes=[`autoplay`,`controls`,`crossorigin`,`loop`,`muted`,`playsinline`,`poster`,`preload`,`src`];loadComplete=new T;#loadRequested;#hasLoaded;#readyState=0;#seeking=!1;#seekComplete;isLoaded=!1;#error=null;#config=null;#textTracksVideo=null;#initialVolume=1;constructor(){super(),this.#upgradeProperty(`config`)}get config(){return this.#config}set config(e){this.#config=e}async load(){if(this.#loadRequested)return;this.shadowRoot||this.attachShadow({mode:`open`});let e=!this.#hasLoaded;this.#hasLoaded&&(this.loadComplete=new T,this.isLoaded=!1),this.#hasLoaded=!0,await(this.#loadRequested=Promise.resolve()),this.#loadRequested=null,this.#readyState=0,this.dispatchEvent(new Event(`emptied`));let t=this.api;if(this.api=null,!this.src){t?.destroy();return}this.#textTracksVideo=document.createElement(`video`),this.textTracks=this.#textTracksVideo.textTracks,this.textTracks.addEventListener(`change`,()=>{var e;let t=Array.from(this.textTracks).find(e=>e.mode===`showing`);(e=this.api)==null||e.setOption(`captions`,`track`,t?{languageCode:t.language}:{})}),this.dispatchEvent(new Event(`loadstart`));let n=this.shadowRoot.querySelector(`iframe`),r=y(this.attributes);e&&n&&(this.#config=JSON.parse(n.getAttribute(`data-config`)||`{}`)),(!n?.src||n.src!==p(r,this))&&(this.shadowRoot.innerHTML=f(r,this),n=this.shadowRoot.querySelector(`iframe`));let i=await x(o,s,c);this.api=new i.Player(n,{events:{onReady:()=>{var e;this.#readyState=1,this.dispatchEvent(new Event(`loadedmetadata`)),this.dispatchEvent(new Event(`durationchange`)),this.#initialVolume!==1&&((e=this.api)==null||e.setVolume(this.#initialVolume*100)),this.dispatchEvent(new Event(`volumechange`)),this.dispatchEvent(new Event(`loadcomplete`)),this.isLoaded=!0,this.loadComplete.resolve()},onError:e=>{console.error(e),this.#error={code:e.data,message:`YouTube iframe player error #${e.data}; visit https://developers.google.com/youtube/iframe_api_reference#onError for the full error message.`},this.dispatchEvent(new Event(`error`))}}});let a=!1;this.api.addEventListener(`onStateChange`,e=>{var t;let n=e.data;if((n===i.PlayerState.PLAYING||n===i.PlayerState.BUFFERING)&&(a||(a=!0,this.dispatchEvent(new Event(`play`))),(this.api.getOption(`captions`,`tracklist`)||[]).forEach(e=>{[...this.textTracks].some(t=>t.language===e.languageCode)||this.#textTracksVideo.addTextTrack(`subtitles`,e.displayName,e.languageCode),this.textTracks=this.#textTracksVideo.textTracks}),this.dispatchEvent(new Event(`loadstart`))),n===i.PlayerState.PLAYING)this.seeking&&(this.#seeking=!1,(t=this.#seekComplete)==null||t.resolve(),this.dispatchEvent(new Event(`seeked`))),this.#readyState=3,this.dispatchEvent(new Event(`playing`));else if(n===i.PlayerState.PAUSED){let e=Math.abs(this.currentTime-l);!this.seeking&&e>.1&&(this.#seeking=!0,this.dispatchEvent(new Event(`seeking`))),a=!1,this.dispatchEvent(new Event(`pause`))}n===i.PlayerState.ENDED&&(a=!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.#initialVolume=this.api?.getVolume()/100,this.dispatchEvent(new Event(`volumechange`))}),this.api.addEventListener(`onVideoProgress`,()=>{this.dispatchEvent(new Event(`timeupdate`))}),await this.loadComplete;let l=0;setInterval(()=>{var e;let t=Math.abs(this.currentTime-l),n=this.buffered.end(this.buffered.length-1);this.seeking&&n>.1?(this.#seeking=!1,(e=this.#seekComplete)==null||e.resolve(),this.dispatchEvent(new Event(`seeked`))):!this.seeking&&t>.1&&(this.#seeking=!0,this.dispatchEvent(new Event(`seeking`))),l=this.currentTime},50);let u,d=setInterval(()=>{let e=this.buffered.end(this.buffered.length-1);e>=this.duration&&(clearInterval(d),this.#readyState=4),u!=e&&(u=e,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.#seekComplete=null,await this.loadComplete,(e=this.api)==null||e.playVideo(),w(this)}async pause(){return await this.loadComplete,this.api?.pauseVideo()}get seeking(){return this.#seeking}get readyState(){return this.#readyState}get src(){return this.getAttribute(`src`)}set src(e){this.src!=e&&this.setAttribute(`src`,e)}get error(){return this.#error}get paused(){var e;return this.isLoaded?[-1,0,2,5].includes(((e=this.api)?.getPlayerState)?.call(e)):!this.autoplay}get duration(){var e;return((e=this.api)?.getDuration)?.call(e)??NaN}get autoplay(){return this.hasAttribute(`autoplay`)}set autoplay(e){this.autoplay!=e&&this.toggleAttribute(`autoplay`,!!e)}get buffered(){if(!this.isLoaded)return E();let e=this.api?.getVideoLoadedFraction()*this.api?.getDuration();return e>0?E(0,e):E()}get controls(){return this.hasAttribute(`controls`)}set controls(e){this.controls!=e&&this.toggleAttribute(`controls`,!!e)}get currentTime(){var e;return((e=this.api)?.getCurrentTime)?.call(e)??0}set currentTime(e){this.currentTime!=e&&(this.#seekComplete=new T,this.loadComplete.then(()=>{var t,n;(t=this.api)==null||t.seekTo(e,!0),this.paused&&((n=this.#seekComplete)==null||n.then(()=>{var e;this.#seekComplete&&((e=this.api)==null||e.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;return this.isLoaded?((e=this.api)?.isMuted)?.call(e):this.defaultMuted}get playbackRate(){var e;return((e=this.api)?.getPlaybackRate)?.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.#initialVolume=e,this.loadComplete.then(()=>{var t;(t=this.api)==null||t.setVolume(e*100)}))}get volume(){return this.isLoaded?this.api?.getVolume()/100:this.#initialVolume}#upgradeProperty(e){if(Object.prototype.hasOwnProperty.call(this,e)){let t=this[e];delete this[e],this[e]=t}}};function h(e){let t=``;for(let n in e){let r=e[n];r===``?t+=` ${g(n)}`:t+=` ${g(n)}="${g(`${r}`)}"`}return t}function g(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&apos;`).replace(/`/g,`&#x60;`)}function _(e){return String(new URLSearchParams(v(e)))}function v(e){let t={};for(let n in e){let r=e[n];r===!0||r===``?t[n]=1:r===!1?t[n]=0:r!=null&&(t[n]=r)}return t}function y(e){let t={};for(let n of e)t[n.name]=n.value;return t}var b={};async function x(e,t,n){return b[e]?b[e]:t&&self[t]?(await S(0),self[t]):b[e]=new Promise(function(r,i){let a=document.createElement(`script`);a.src=e;let o=()=>r(self[t]);n&&(self[n]=o),a.onload=()=>!n&&o(),a.onerror=i,document.head.append(a)})}var S=e=>new Promise(t=>setTimeout(t,e));function C(e){return(...t)=>new Promise(n=>{e(...t,(...e)=>{e.length>1?n(e):n(e[0])})})}function w(e){return C((t,n)=>{let r;e.addEventListener(t,r=()=>{e.removeEventListener(t,r),n()})})(`playing`)}var T=class extends Promise{constructor(e=()=>{}){let t,n;super((r,i)=>{e(r,i),t=r,n=i}),this.resolve=t,this.reject=n}};function E(e,t){return D(Array.isArray(e)?e:e==null||t==null||e===0&&t===0?[[0,0]]:[[e,t]])}function D(e){return Object.defineProperties(e,{start:{value:t=>e[t][0]},end:{value:t=>e[t][1]}}),e}globalThis.customElements&&!globalThis.customElements.get(`youtube-video`)&&globalThis.customElements.define(`youtube-video`,m);var O=m,k=new Set([`style`,`children`,`ref`,`key`,`suppressContentEditableWarning`,`suppressHydrationWarning`,`dangerouslySetInnerHTML`]),A={className:`class`,htmlFor:`for`};function j(e){return e.toLowerCase()}function M(e){if(typeof e==`boolean`)return e?``:void 0;if(typeof e!=`function`&&!(typeof e==`object`&&e))return e}function N({react:e,tagName:t,elementClass:n,events:r,displayName:i,defaultProps:a,toAttributeName:o=j,toAttributeValue:s=M}){let c=Number.parseInt(e.version)>=19,l=e.forwardRef((i,l)=>{let u=e.useRef(null),d=e.useRef(new Map),f={},p={},m={},h={};for(let[e,t]of Object.entries(i)){if(k.has(e)){m[e]=t;continue}let r=o(A[e]??e);if(n.prototype&&e in n.prototype&&!(e in(globalThis.HTMLElement?.prototype??{}))&&!n.observedAttributes?.some(e=>e===r)){h[e]=t;continue}if(e.startsWith(`on`)){f[e]=t;continue}let i=s(t);r&&i!=null&&(p[r]=String(i),c||(m[r]=i)),r&&c&&(i===M(t)?m[r]=t:m[r]=i)}if(typeof window<`u`){for(let t in f){let n=f[t],i=t.endsWith(`Capture`),a=(r?.[t]??t.slice(2).toLowerCase()).slice(0,i?-7:void 0);e.useLayoutEffect(()=>{let e=u?.current;if(!(!e||typeof n!=`function`))return e.addEventListener(a,n,i),()=>{e.removeEventListener(a,n,i)}},[u?.current,n])}e.useLayoutEffect(()=>{if(u.current===null)return;let e=new Map;for(let t in h)P(u.current,t,h[t]),d.current.delete(t),e.set(t,h[t]);for(let[e,t]of d.current)P(u.current,e,void 0);d.current=e})}if(typeof window>`u`&&n?.getTemplateHTML&&n?.shadowRootOptions){let{mode:t,delegatesFocus:r}=n.shadowRootOptions;m.children=[e.createElement(`template`,{shadowrootmode:t,shadowrootdelegatesfocus:r,dangerouslySetInnerHTML:{__html:n.getTemplateHTML(p,i)},key:`ce-la-react-ssr-template-shadow-root`}),m.children]}return e.createElement(t,{...a,...m,ref:e.useCallback(e=>{u.current=e,typeof l==`function`?l(e):l!==null&&(l.current=e)},[l])},m.children)});return l.displayName=i??n.name,l}function P(e,t,n){e[t]=n,n==null&&t in(globalThis.HTMLElement?.prototype??{})&&e.removeAttribute(t)}var F=N({react:r.default,tagName:`youtube-video`,elementClass:O,toAttributeName(e){return e===`muted`?``:e===`defaultMuted`?`muted`:j(e)}});export{F as default};