import{s as e}from"./rolldown-runtime-C5c2KzVm.js";import{$P as t}from"./lucide-C4oWPzu4.js";var n=e(t(),1),r=`https://www.tiktok.com/player/v1`,i=/tiktok\.com\/(?:player\/v1\/|share\/video\/|@[^/]+\/video\/)([0-9]+)/,a={INIT:-1,ENDED:0,PLAYING:1,PAUSED:2,BUFFERING:3},o={[a.INIT]:`emptied`,[a.PAUSED]:`pause`,[a.ENDED]:`ended`,[a.PLAYING]:`play`,[a.BUFFERING]:`waiting`};function s(e,t={}){let n={src:c(e,t),frameborder:0,width:`100%`,height:`100%`,allow:`accelerometer; autoplay; fullscreen; encrypted-media; gyroscope; picture-in-picture`};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%;
        border:0;
      }
    </style>
    <iframe ${m(n)} title="TikTok video"></iframe>
  `}function c(e,t={}){if(!e.src)return;let n=e.src.match(i);return`${r}/${n&&n[1]}?${p({controls:e.controls===``?null:0,autoplay:e.autoplay,muted:e.muted,loop:e.loop,rel:0,...t.config})}`}var l=class e extends (globalThis.HTMLElement??class{}){static getTemplateHTML=s;static shadowRootOptions={mode:`open`};static get observedAttributes(){return[`src`,`controls`,`loop`,`autoplay`,`muted`]}loadComplete=new u;#loadRequested;#hasLoaded;#muted=!1;#currentTime=0;#paused=!0;#config=null;#volume=100;#duration=0;#iframe;constructor(){super(),this.#upgradeProperty(`config`)}async load(){if(this.#loadRequested)return;this.shadowRoot||this.attachShadow(e.shadowRootOptions);let t=!this.#hasLoaded;if(this.#hasLoaded&&(this.loadComplete=new u),this.#hasLoaded=!0,await(this.#loadRequested=Promise.resolve()),this.#loadRequested=null,this.#currentTime=0,this.#muted=!1,this.#paused=!0,!this.src){this.shadowRoot.innerHTML=``,globalThis.removeEventListener(`message`,this.#onMessage);return}let n=this.shadowRoot.querySelector(`iframe`),r=d(this.attributes);t&&n&&(this.#config=JSON.parse(n.getAttribute(`data-config`)||`{}`)),(!n?.src||n.src!==c(r,this))&&(this.shadowRoot.innerHTML=s(r,this),n=this.shadowRoot.querySelector(`iframe`)),this.#iframe=n,globalThis.addEventListener(`message`,this.#onMessage)}async attributeChangedCallback(e,t,n){if(t!==n)switch(e){case`muted`:await this.loadComplete,this.muted=n!=null;break;case`autoplay`:case`controls`:case`loop`:case`src`:this.load();return}}get config(){return this.#config}set config(e){this.#config=e}#onMessage=e=>{if(e.source!==this.#iframe?.contentWindow)return;let t=e.data;if(t?.[`x-tiktok-player`])switch(t.type){case`onPlayerReady`:this.loadComplete.resolve();break;case`onStateChange`:{this.#paused=[a.INIT,a.PAUSED,a.ENDED].includes(t.value);let e=o[t.value];e&&this.dispatchEvent(new Event(e));break}case`onCurrentTime`:this.#currentTime=t.value.currentTime,this.#duration=t.value.duration,this.dispatchEvent(new Event(`durationchange`)),this.dispatchEvent(new Event(`timeupdate`));break;case`onVolumeChange`:this.#volume=t.value,this.dispatchEvent(new Event(`volumechange`));break;case`onMute`:this.#muted=!!t.value,this.#volume=t.value?0:this.#volume,this.dispatchEvent(new Event(`volumechange`));break;case`onError`:this.dispatchEvent(new Event(`error`));break;default:console.warn(`Unhandled TikTok player message:`,t);break}};#post(e,t){if(!this.#iframe?.contentWindow)return;let n={"x-tiktok-player":!0,type:e,...t===void 0?{}:{value:t}};this.#iframe.contentWindow.postMessage(n,`*`)}async play(){await this.loadComplete,this.#post(`play`)}async pause(){await this.loadComplete,this.#post(`pause`)}async#seekTo(e){await this.loadComplete,this.#post(`seekTo`,Number(e))}async#mute(){await this.loadComplete,this.#post(`mute`)}async#unMute(){await this.loadComplete,this.#post(`unMute`)}get volume(){return this.#volume/100}set volume(e){console.warn(`Volume control is not supported for TikTok videos.`)}get currentTime(){return this.#currentTime}set currentTime(e){this.#seekTo(e)}get muted(){return this.#muted}set muted(e){this.#muted=e,e?this.#mute():this.#unMute()}get defaultMuted(){return this.hasAttribute(`muted`)}set defaultMuted(e){this.toggleAttribute(`muted`,!!e)}get paused(){return this.#paused}get duration(){return this.#duration}get src(){return this.getAttribute(`src`)}set src(e){this.setAttribute(`src`,e??``)}#upgradeProperty(e){if(Object.prototype.hasOwnProperty.call(this,e)){let t=this[e];delete this[e],this[e]=t}}},u=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 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===!0||r===``?t[n]=1:r===!1?t[n]=0:r!=null&&(t[n]=r)}return t}function p(e){return String(new URLSearchParams(f(e)))}function m(e){let t=``;for(let n in e){let r=e[n];r===``?t+=` ${h(n)}`:t+=` ${h(n)}="${h(`${r}`)}"`}return t}function h(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&apos;`).replace(/`/g,`&#x60;`)}globalThis.customElements&&!globalThis.customElements.get(`tiktok-video`)&&globalThis.customElements.define(`tiktok-video`,l);var g=l,_=new Set([`style`,`children`,`ref`,`key`,`suppressContentEditableWarning`,`suppressHydrationWarning`,`dangerouslySetInnerHTML`]),v={className:`class`,htmlFor:`for`};function y(e){return e.toLowerCase()}function b(e){if(typeof e==`boolean`)return e?``:void 0;if(typeof e!=`function`&&!(typeof e==`object`&&e))return e}function x({react:e,tagName:t,elementClass:n,events:r,displayName:i,defaultProps:a,toAttributeName:o=y,toAttributeValue:s=b}){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(_.has(e)){m[e]=t;continue}let r=o(v[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===b(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)S(u.current,t,h[t]),d.current.delete(t),e.set(t,h[t]);for(let[e,t]of d.current)S(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 S(e,t,n){e[t]=n,n==null&&t in(globalThis.HTMLElement?.prototype??{})&&e.removeAttribute(t)}var C=x({react:n.default,tagName:`tiktok-video`,elementClass:g,toAttributeName(e){return e===`muted`?``:e===`defaultMuted`?`muted`:y(e)}});export{C as default};