UNPKG

@mux/mux-video

Version:

A custom mux video element for the browser that Just Works™

13 lines (11 loc) 2.92 kB
"use client";import R from"@mux/mux-video/ads";import W from"react";var S=new Set(["style","children","ref","key","suppressContentEditableWarning","suppressHydrationWarning","dangerouslySetInnerHTML"]),x={className:"class",htmlFor:"for"};function O(t){return t.toLowerCase()}function M(t){if(typeof t=="boolean")return t?"":void 0;if(typeof t!="function"&&!(typeof t=="object"&&t!==null))return t}function k({react:t,tagName:d,elementClass:r,events:a,displayName:f,defaultProps:N,toAttributeName:_=O,toAttributeValue:I=M}){let m=Number.parseInt(t.version)>=19,g=t.forwardRef((w,p)=>{var T,E,v,L,P;let i=t.useRef(null),y=t.useRef(new Map),b={},h={},c={},l={};for(let[o,e]of Object.entries(w)){if(S.has(o)){c[o]=e;continue}let n=_((T=x[o])!=null?T:o);if(r.prototype&&o in r.prototype&&!(o in((v=(E=globalThis.HTMLElement)==null?void 0:E.prototype)!=null?v:{}))&&!((L=r.observedAttributes)!=null&&L.some(s=>s===n))){l[o]=e;continue}if(o.startsWith("on")){b[o]=e;continue}let u=I(e);if(n&&u!=null&&(h[n]=String(u),m||(c[n]=u)),n&&m){let s=M(e);u!==s?c[n]=u:c[n]=e}}if(typeof window!="undefined"){for(let o in b){let e=b[o],n=o.endsWith("Capture"),u=((P=a==null?void 0:a[o])!=null?P:o.slice(2).toLowerCase()).slice(0,n?-7:void 0);t.useLayoutEffect(()=>{let s=i==null?void 0:i.current;if(!(!s||typeof e!="function"))return s.addEventListener(u,e,n),()=>{s.removeEventListener(u,e,n)}},[i==null?void 0:i.current,e])}t.useLayoutEffect(()=>{if(i.current===null)return;let o=new Map;for(let e in l)A(i.current,e,l[e]),y.current.delete(e),o.set(e,l[e]);for(let[e,n]of y.current)A(i.current,e,void 0);y.current=o})}if(typeof window=="undefined"&&(r!=null&&r.getTemplateHTML)&&(r!=null&&r.shadowRootOptions)){let{mode:o,delegatesFocus:e}=r.shadowRootOptions,n=t.createElement("template",{shadowrootmode:o,shadowrootdelegatesfocus:e,dangerouslySetInnerHTML:{__html:r.getTemplateHTML(h,w)},key:"ce-la-react-ssr-template-shadow-root"});c.children=[n,c.children]}return t.createElement(d,{...N,...c,ref:t.useCallback(o=>{i.current=o,typeof p=="function"?p(o):p!==null&&(p.current=o)},[p])},c.children)});return g.displayName=f!=null?f:r.name,g}function A(t,d,r){var a,f;t[d]=r,r==null&&d in((f=(a=globalThis.HTMLElement)==null?void 0:a.prototype)!=null?f:{})&&t.removeAttribute(d)}var q=k({react:W,tagName:"mux-video",displayName:"MuxVideoAds",elementClass:R,toAttributeName:F}),H={autoPlay:"autoplay",controlsList:"controlslist",crossOrigin:"crossorigin",playsInline:"playsinline",disablePictureInPicture:"disablepictureinpicture",disableRemotePlayback:"disableremoteplayback"};function F(t){return H[t]?H[t]:t.replace(/([A-Z])/g,"-$1").toLowerCase()}export{q as default}; /*! 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. *) */