import{s as e}from"./rolldown-runtime-C5c2KzVm.js";import{$P as t}from"./lucide-C4oWPzu4.js";var n=e(t(),1),r=`https://player.twitch.tv`,i=/(?:www\.|go\.)?twitch\.tv\/(?:videos?\/|\?video=)(\d+)($|\?)/,a=/(?:www\.|go\.)?twitch\.tv\/([a-zA-Z0-9_]+)($|\?)/,o={IDLE:`Idle`,READY:`Ready`,BUFFERING:`Buffering`,PLAYING:`Playing`,ENDED:`Ended`},s={DISABLE_CAPTIONS:0,ENABLE_CAPTIONS:1,PAUSE:2,PLAY:3,SEEK:4,SET_CHANNEL:5,SET_CHANNEL_ID:6,SET_COLLECTION:7,SET_QUALITY:8,SET_VIDEO:9,SET_MUTED:10,SET_VOLUME:11};function c(e,t={}){let n={src:l(e,t),frameborder:`0`,width:`100%`,height:`100%`,allow:`accelerometer; fullscreen; autoplay; encrypted-media; picture-in-picture;`,sandbox:`allow-modals allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox`,scrolling:`no`};return t.config&&(n[`data-config`]=JSON.stringify(t.config)),`
    <style>
      :host {
        display: inline-block;
        min-width: 300px;
        min-height: 150px;
        position: relative;
      }
      iframe {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
      }
      :host(:not([controls])) {
        pointer-events: none;
      }
    </style>
    <iframe${f(n)}></iframe>
  `}function l(e,t){if(!e.src)return;let n=e.src.match(i),o=e.src.match(a),s={parent:globalThis.location?.hostname,controls:e.controls===``?null:!1,autoplay:e.autoplay===``?null:!1,muted:e.muted,preload:e.preload,...t.config};return n?`${r}/?video=v${n[1]}&${m(s)}`:o?`${r}/?channel=${o[1]}&${m(s)}`:``}var u=class extends (globalThis.HTMLElement??class{}){static getTemplateHTML=c;static shadowRootOptions={mode:`open`};static observedAttributes=[`autoplay`,`controls`,`loop`,`muted`,`playsinline`,`preload`,`src`];loadComplete=new g;#loadRequested;#hasLoaded;#iframe;#playerState={};#currentTime=0;#muted=!1;#volume=1;#paused=!this.autoplay;#seeking=!1;#readyState=0;#config=null;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;if(this.#hasLoaded&&(this.loadComplete=new g),this.#hasLoaded=!0,await(this.#loadRequested=Promise.resolve()),this.#loadRequested=null,this.#readyState=0,this.dispatchEvent(new Event(`emptied`)),!this.src){this.shadowRoot.innerHTML=``,globalThis.removeEventListener(`message`,this.#onMessage);return}this.dispatchEvent(new Event(`loadstart`));let t=this.shadowRoot.querySelector(`iframe`),n=d(this.attributes);e&&t&&(this.#config=JSON.parse(t.getAttribute(`data-config`)||`{}`)),(!t?.src||t.src!==l(n,this))&&(this.shadowRoot.innerHTML=c(n,this),t=this.shadowRoot.querySelector(`iframe`)),this.#iframe=t,globalThis.addEventListener(`message`,this.#onMessage)}attributeChangedCallback(e,t,n){if(t!==n)switch(e){case`src`:case`controls`:this.load();break}}getVideoPlaybackQuality(){return this.#playerState.stats.videoStats}get src(){return this.getAttribute(`src`)}set src(e){this.setAttribute(`src`,e)}get readyState(){return this.#readyState}get seeking(){return this.#seeking}get buffered(){return _(0,this.#playerState.stats?.videoStats?.bufferSize??0)}get paused(){return this.#playerState.playback?this.#playerState.playback===o.IDLE:this.#paused}get ended(){return this.#playerState.playback?this.#playerState.playback===o.ENDED:!1}get duration(){return this.#playerState.duration??NaN}get autoplay(){return this.hasAttribute(`autoplay`)}set autoplay(e){this.autoplay!=e&&this.toggleAttribute(`autoplay`,!!e)}get controls(){return this.hasAttribute(`controls`)}set controls(e){this.controls!=e&&this.toggleAttribute(`controls`,!!e)}get currentTime(){return this.#playerState.currentTime?this.#playerState.currentTime:this.#currentTime}set currentTime(e){this.#currentTime=e,this.loadComplete.then(()=>{this.#sendCommand(s.SEEK,e)})}get defaultMuted(){return this.hasAttribute(`muted`)}set defaultMuted(e){this.toggleAttribute(`muted`,!!e)}get loop(){return this.hasAttribute(`loop`)}set loop(e){this.toggleAttribute(`loop`,!!e)}get muted(){return this.#muted}set muted(e){this.#muted=e,this.loadComplete.then(()=>{this.#sendCommand(s.SET_MUTED,e)})}get volume(){return this.#volume}set volume(e){this.#volume=e,this.loadComplete.then(()=>{this.#sendCommand(s.SET_VOLUME,e)})}get playsInline(){return this.hasAttribute(`playsinline`)}set playsInline(e){this.toggleAttribute(`playsinline`,!!e)}play(){this.#paused=!1,this.#sendCommand(s.PLAY)}pause(){this.#paused=!0,this.#sendCommand(s.PAUSE)}#onMessage=async e=>{if(!this.#iframe.contentWindow)return;let{data:t,source:n}=e;if(n===this.#iframe.contentWindow){if(t.namespace===`twitch-embed`)await new Promise(e=>setTimeout(e,10)),t.eventName===`ready`?(this.dispatchEvent(new Event(`loadcomplete`)),this.loadComplete.resolve(),this.#readyState=1,this.dispatchEvent(new Event(`loadedmetadata`))):t.eventName===`seek`?(this.#seeking=!0,this.dispatchEvent(new Event(`seeking`))):t.eventName===`playing`?(this.#seeking&&(this.#seeking=!1,this.dispatchEvent(new Event(`seeked`))),this.#readyState=3,this.dispatchEvent(new Event(`playing`))):this.dispatchEvent(new Event(t.eventName));else if(t.namespace===`twitch-embed-player-proxy`&&t.eventName===`UPDATE_STATE`){let e=this.#playerState.duration,n=this.#playerState.currentTime,r=this.#playerState.volume,i=this.#playerState.muted,a=this.#playerState.stats?.videoStats?.bufferSize;this.#playerState={...this.#playerState,...t.params},e!==this.#playerState.duration&&this.dispatchEvent(new Event(`durationchange`)),n!==this.#playerState.currentTime&&this.dispatchEvent(new Event(`timeupdate`)),(r!==this.#playerState.volume||i!==this.#playerState.muted)&&(this.#playerState.volume!==void 0&&(this.#volume=this.#playerState.volume),this.#playerState.muted!==void 0&&(this.#muted=this.#playerState.muted),this.dispatchEvent(new Event(`volumechange`))),a!==this.#playerState.stats?.videoStats?.bufferSize&&this.dispatchEvent(new Event(`progress`))}}};#sendCommand(e,t){if(!this.#iframe.contentWindow)return;let n={eventName:e,params:t,namespace:`twitch-embed-player-proxy`};this.#iframe.contentWindow.postMessage(n,r)}#upgradeProperty(e){if(Object.prototype.hasOwnProperty.call(this,e)){let t=this[e];delete this[e],this[e]=t}}};function d(e){let t={};for(let n of e)t[n.name]=n.value;return t}function f(e){let t=``;for(let n in e){let r=e[n];r===``?t+=` ${p(n)}`:t+=` ${p(n)}="${p(`${r}`)}"`}return t}function p(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&apos;`).replace(/`/g,`&#x60;`)}function m(e){return String(new URLSearchParams(h(e)))}function h(e){let t={};for(let n in e){let r=e[n];r===!0||r===``?t[n]=!0:r===!1?t[n]=!1:r!=null&&(t[n]=r)}return t}var g=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,t){return v(Array.isArray(e)?e:e==null||t==null||e===0&&t===0?[[0,0]]:[[e,t]])}function v(e){return Object.defineProperties(e,{start:{value:t=>e[t][0]},end:{value:t=>e[t][1]}}),e}globalThis.customElements&&!globalThis.customElements.get(`twitch-video`)&&globalThis.customElements.define(`twitch-video`,u);var y=u,b=new Set([`style`,`children`,`ref`,`key`,`suppressContentEditableWarning`,`suppressHydrationWarning`,`dangerouslySetInnerHTML`]),x={className:`class`,htmlFor:`for`};function S(e){return e.toLowerCase()}function C(e){if(typeof e==`boolean`)return e?``:void 0;if(typeof e!=`function`&&!(typeof e==`object`&&e))return e}function w({react:e,tagName:t,elementClass:n,events:r,displayName:i,defaultProps:a,toAttributeName:o=S,toAttributeValue:s=C}){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(b.has(e)){m[e]=t;continue}let r=o(x[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===C(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)T(u.current,t,h[t]),d.current.delete(t),e.set(t,h[t]);for(let[e,t]of d.current)T(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 T(e,t,n){e[t]=n,n==null&&t in(globalThis.HTMLElement?.prototype??{})&&e.removeAttribute(t)}var E=w({react:n.default,tagName:`twitch-video`,elementClass:y,toAttributeName(e){return e===`muted`?``:e===`defaultMuted`?`muted`:S(e)}});export{E as default};