import{d3 as H}from"./index-Cq8aT7Ma.js";const D="https://www.tiktok.com/player/v1",O=/tiktok\.com\/(?:@[^/]+\/video\/)?(\d+)(?:\/([\w-]+))?/,c={INIT:-1,ENDED:0,PLAYING:1,PAUSED:2,BUFFERING:3},x={[c.INIT]:"emptied",[c.PAUSED]:"pause",[c.ENDED]:"ended",[c.PLAYING]:"play",[c.BUFFERING]:"waiting"};function N(o,e={}){const t={src:R(o,e),frameborder:0,width:"100%",height:"100%",allow:"accelerometer; autoplay; fullscreen; encrypted-media; gyroscope; picture-in-picture"};return e.config&&(t["data-config"]=JSON.stringify(e.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 ${W(t)} title="TikTok video"></iframe>
  `}function R(o,e={}){if(!o.src)return;const t=o.src.match(O),i=t&&t[1],a={controls:o.controls===""?null:0,autoplay:o.autoplay,muted:o.muted,loop:o.loop,rel:0,...e.config};return`${D}/${i}?${$(a)}`}class v extends(globalThis.HTMLElement??class{}){static getTemplateHTML=N;static shadowRootOptions={mode:"open"};static get observedAttributes(){return["src","controls","loop","autoplay","muted"]}loadComplete=new A;#i;#s;#e=!1;#n=0;#r=!0;#a=null;#o=100;#u=0;#l;constructor(){super(),this.#m("config")}async load(){if(this.#i)return;this.shadowRoot||this.attachShadow(v.shadowRootOptions);const e=!this.#s;if(this.#s&&(this.loadComplete=new A),this.#s=!0,await(this.#i=Promise.resolve()),this.#i=null,this.#n=0,this.#e=!1,this.#r=!0,!this.src){this.shadowRoot.innerHTML="",globalThis.removeEventListener("message",this.#c);return}let t=this.shadowRoot.querySelector("iframe");const i=F(this.attributes);e&&t&&(this.#a=JSON.parse(t.getAttribute("data-config")||"{}")),(!t?.src||t.src!==R(i,this))&&(this.shadowRoot.innerHTML=N(i,this),t=this.shadowRoot.querySelector("iframe")),this.#l=t,globalThis.addEventListener("message",this.#c)}async attributeChangedCallback(e,t,i){if(t!==i)switch(e){case"muted":{await this.loadComplete,this.muted=i!=null;break}case"autoplay":case"controls":case"loop":case"src":{this.load();return}}}get config(){return this.#a}set config(e){this.#a=e}#c=e=>{const t=e.data;if(t?.["x-tiktok-player"])switch(t.type){case"onPlayerReady":this.loadComplete.resolve();break;case"onStateChange":{this.#r=[c.INIT,c.PAUSED,c.ENDED].includes(t.value);const i=x[t.value];i&&this.dispatchEvent(new Event(i));break}case"onCurrentTime":this.#n=t.value.currentTime,this.#u=t.value.duration,this.dispatchEvent(new Event("durationchange")),this.dispatchEvent(new Event("timeupdate"));break;case"onVolumeChange":this.#o=t.value,this.dispatchEvent(new Event("volumechange"));break;case"onMute":this.#e=!!t.value,this.#o=t.value?0:this.#o,this.dispatchEvent(new Event("volumechange"));break;case"onError":this.dispatchEvent(new Event("error"));break;default:console.warn("Unhandled TikTok player message:",t);break}};#t(e,t){var i;if(!((i=this.#l)!=null&&i.contentWindow))return;const a={"x-tiktok-player":!0,type:e,...t!==void 0?{value:t}:{}};this.#l.contentWindow.postMessage(a,"*")}async play(){await this.loadComplete,this.#t("play")}async pause(){await this.loadComplete,this.#t("pause")}async#d(e){await this.loadComplete,this.#t("seekTo",Number(e))}async#h(){await this.loadComplete,this.#t("mute")}async#f(){await this.loadComplete,this.#t("unMute")}get volume(){return this.#o/100}set volume(e){console.warn("Volume control is not supported for TikTok videos.")}get currentTime(){return this.#n}set currentTime(e){this.#d(e)}get muted(){return this.#e}set muted(e){this.#e=e,e?this.#h():this.#f()}get defaultMuted(){return this.hasAttribute("muted")}set defaultMuted(e){this.toggleAttribute("muted",!!e)}get paused(){return this.#r}get duration(){return this.#u}get src(){return this.getAttribute("src")}set src(e){this.setAttribute("src",e??"")}#m(e){if(Object.prototype.hasOwnProperty.call(this,e)){const t=this[e];delete this[e],this[e]=t}}}class A extends Promise{constructor(e=()=>{}){let t,i;super((a,m)=>{e(a,m),t=a,i=m}),this.resolve=t,this.reject=i}}function F(o){let e={};for(let t of o)e[t.name]=t.value;return e}function U(o){let e={};for(let t in o){let i=o[t];i===!0||i===""?e[t]=1:i===!1?e[t]=0:i!=null&&(e[t]=i)}return e}function $(o){return String(new URLSearchParams(U(o)))}function W(o){let e="";for(const t in o){const i=o[t];i===""?e+=` ${w(t)}`:e+=` ${w(t)}="${w(`${i}`)}"`}return e}function w(o){return o.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",v);var j=v,B=new Set(["style","children","ref","key","suppressContentEditableWarning","suppressHydrationWarning","dangerouslySetInnerHTML"]),q={className:"class",htmlFor:"for"};function C(o){return o.toLowerCase()}function P(o){if(typeof o=="boolean")return o?"":void 0;if(typeof o!="function"&&!(typeof o=="object"&&o!==null))return o}function G({react:o,tagName:e,elementClass:t,events:i,displayName:a,defaultProps:m,toAttributeName:_=C,toAttributeValue:I=P}){const b=Number.parseInt(o.version)>=19,E=o.forwardRef((T,f)=>{var k,M;const l=o.useRef(null),g=o.useRef(new Map),y={},L={},d={},p={};for(const[s,n]of Object.entries(T)){if(B.has(s)){d[s]=n;continue}const r=_(q[s]??s);if(s in t.prototype&&!(s in(((k=globalThis.HTMLElement)==null?void 0:k.prototype)??{}))&&!((M=t.observedAttributes)!=null&&M.some(h=>h===r))){p[s]=n;continue}if(s.startsWith("on")){y[s]=n;continue}const u=I(n);if(r&&u!=null&&(L[r]=String(u),b||(d[r]=u)),r&&b){const h=P(n);u!==h?d[r]=u:d[r]=n}}if(typeof window<"u"){for(const s in y){const n=y[s],r=s.endsWith("Capture"),u=(i?.[s]??s.slice(2).toLowerCase()).slice(0,r?-7:void 0);o.useLayoutEffect(()=>{const h=l?.current;if(!(!h||typeof n!="function"))return h.addEventListener(u,n,r),()=>{h.removeEventListener(u,n,r)}},[l?.current,n])}o.useLayoutEffect(()=>{if(l.current===null)return;const s=new Map;for(const n in p)S(l.current,n,p[n]),g.current.delete(n),s.set(n,p[n]);for(const[n,r]of g.current)S(l.current,n,void 0);g.current=s})}if(typeof window>"u"&&t?.getTemplateHTML&&t?.shadowRootOptions){const{mode:s,delegatesFocus:n}=t.shadowRootOptions,r=o.createElement("template",{shadowrootmode:s,shadowrootdelegatesfocus:n,dangerouslySetInnerHTML:{__html:t.getTemplateHTML(L,T)}});d.children=[r,d.children]}return o.createElement(e,{...m,...d,ref:o.useCallback(s=>{l.current=s,typeof f=="function"?f(s):f!==null&&(f.current=s)},[f])})});return E.displayName=a??t.name,E}function S(o,e,t){var i;o[e]=t,t==null&&e in(((i=globalThis.HTMLElement)==null?void 0:i.prototype)??{})&&o.removeAttribute(e)}var J=G({react:H,tagName:"tiktok-video",elementClass:j,toAttributeName(o){return o==="muted"?"":o==="defaultMuted"?"muted":C(o)}});/*! 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{J as default};
