@vouchfor/embeds 0.0.0-experiment.b6b97eb → 0.0.0-experiment.b6e21df

Sign up to get free protection for your applications and to get access to all the features.
@@ -2451,7 +2451,7 @@ vec4 transition(vec2 uv) {
2451
2451
  return mix(a, b, step(0.0+p.y,progress));
2452
2452
  }
2453
2453
  `,author:"Jake Nelson",license:"MIT",createdAt:"Wed, 1 Nov 2017 15:24:36 -0500",updatedAt:"Thu, 2 Nov 2017 18:37:42 -0500"}];const rc=ho(ap);var nc;function lp(r){if(typeof r=="string"){const[e,t]=r.split(":");return Math.min(parseFloat(e),parseFloat(t))}return r}function Ap(r){if(typeof r=="string"){const[e,t]=r.split(":"),n=parseFloat(e),i=parseFloat(t);return n/i}return r}function Yo({resolution:r,aspectRatio:e}){const t=lp(r),n=Ap(e),i=n>=1,s=Math.min(i?t*n:t/n,t),o=Math.max(i?t*n:t/n,t);return{resolution:t,aspectRatio:n,height:i?s:o,width:i?o:s}}function cp({source:r,sx:e,sy:t,sw:n,sh:i,dx:s,dy:o,dw:a,dh:l}){const A=(r==null?void 0:r.naturalWidth)??(r==null?void 0:r.videoWidth)??(r==null?void 0:r.width),c=(r==null?void 0:r.naturalHeight)??(r==null?void 0:r.videoHeight)??(r==null?void 0:r.height);e=e??0,t=t??0,n=n??A,i=i??c,n<0&&(e+=n,n=Math.abs(n)),i<0&&(t+=i,i=Math.abs(i)),a<0&&(s+=a,a=Math.abs(a)),l<0&&(o+=l,l=Math.abs(l));const u=Math.max(e,0),h=Math.min(e+n,A),d=Math.max(t,0),f=Math.min(t+i,c),g=a/n,p=l/i;return[r,u,d,h-u,f-d,e<0?s-e*g:s,t<0?o-t*p:o,(h-u)*g,(f-d)*p]}function up({context:r,source:e,crop:t,format:n="letterbox",posX:i,posY:s,drawAreaWidth:o,drawAreaHeight:a,sourceWidth:l,sourceHeight:A,cropCanvas:c}){const{x:u,y:h,width:d,height:f}=t??{},g=l*(u??0),p=A*(h??0),C=l*Math.min(1-(u??0),d??1),Q=A*Math.min(1-(h??0),f??1);let b=g,y=p,x=C,R=Q,k=C,H=Q;if(c.width=C,c.height=Q,n==="crop"){const P=o/a,K=C/Q,re=K>P?C-Q*P:0,ee=K<P?Q-C/P:0;c.width=C+re,c.height=Q+ee,b+=re/2,y+=ee/2,x-=re,R-=ee,k+=re,H+=ee}const V=c.getContext("2d");if(V){const P=cp({source:e,sx:b,sy:y,sw:x,sh:R,dx:0,dy:0,dw:k,dh:H});V.drawImage(...P)}r.drawImage(c,i,s,o,a)}const zr=/(?<value>\d+\.?\d*)(?=px)/;function ic({context:r,word:e,maxW:t=1/0}){const n=[],i=r.measureText(e);if(Math.floor(i.width)<=t)return[{text:e,metrics:i}];for(let s=0;s<e.length;s++){const o=n[n.length-1],a=((o==null?void 0:o.text)??"")+e[s],l=r.measureText(a);l.width<t?n[o?n.length-1:0]={text:a,metrics:l}:n.push({text:e[s],metrics:r.measureText(e[s])})}return n}const Vo=uo(({context:r,fontSizes:e,text:t,maxW:n=1/0})=>{try{return r.save(),r.font=r.font.replace(zr,e[0].toString()),t.split(`
2454
- `).flatMap(s=>{const o=s.split(" ").filter(Boolean);return o.length?o.slice(1).reduce((a,l,A)=>{const u=`${a[a.length-1].text} ${l}`.trim(),h=r.measureText(u);if(h.width>n)a=[...a,...ic({context:r,word:l,maxW:n})];else{const d=e[A%e.length];r.font=r.font.replace(zr,d.toString()),a[a.length-1]={text:u,metrics:h}}return a},ic({context:r,word:o[0],maxW:n})):{text:"",metrics:r.measureText("")}})}finally{r.restore()}},{cacheKey:([{fontSizes:r,text:e,maxW:t}])=>`${JSON.stringify(r)}_${e}_${t}`}),Ir=1.8;function hp({context:r,x:e,y:t,width:n,height:i,radii:s}){let o,a,l,A;typeof s=="number"?o=a=l=A=s:[o,a,l,A]=s,r.beginPath(),r.moveTo(e+Math.min(i/Ir,o),t),r.lineTo(e+n-Math.min(i/Ir,a),t),r.quadraticCurveTo(e+n,t,e+n,t+Math.min(i/Ir,a)),r.lineTo(e+n,t+i-Math.min(i/Ir,l)),r.quadraticCurveTo(e+n,t+i,e+n-Math.min(i/Ir,l),t+i),r.lineTo(e+Math.min(i/Ir,A),t+i),r.quadraticCurveTo(e,t+i,e,t+i-Math.min(i/Ir,A)),r.lineTo(e,t+Math.min(i/Ir,o)),r.quadraticCurveTo(e,t,e+Math.min(i/Ir,o),t),r.closePath()}function sc({context:r,x:e,y:t,width:n,height:i,radii:s,clip:o=!1,debug:a=!1}){hp({context:r,x:e,y:t,width:n,height:i,radii:s}),a&&(r.strokeStyle="blue",r.stroke()),o&&r.clip()}const oc=[{family:"Noto Arabic",regex:new RegExp("\\p{Script=Arabic}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansArabic-VariableFont_wdth%2Cwght.woff2",style:"normal"},{family:"Noto Chinese",regex:new RegExp("\\p{Script=Han}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansSC-VariableFont_wght.woff2",style:"normal"},{family:"Noto Hebrew",regex:new RegExp("\\p{Script=Hebrew}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansHebrew-VariableFont_wdth%2Cwght.woff2",style:"normal"},{family:"Noto Hindi",regex:new RegExp("\\p{Script=Devanagari}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansDevanagari-VariableFont_wdth%2Cwght.woff2",style:"normal"},{family:"Noto Japanese",regex:new RegExp("\\p{Script=Han}|\\p{Script=Katakana}|\\p{Script=Hiragana}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansJP-VariableFont_wght.woff2",style:"normal"},{family:"Noto Korean",regex:new RegExp("\\p{Script=Hangul}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansKR-VariableFont_wght.woff2",style:"normal"},{family:"Noto Color Emoji",regex:new RegExp("\\p{Extended_Pictographic}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoColorEmoji-Regular.woff2",style:"normal"}];function ss({text:r,font:e}){let t=e;return oc.forEach(({family:n,regex:i})=>{i.exec(r)&&(t+=`, ${n}`)}),t}uo(({context:r,fontSizes:e,maxW:t=1/0,words:n})=>{try{return r.save(),r.font=r.font.replace(zr,e[0].toString()),n.length<=0?[]:n.slice(1).reduce((i,s)=>{var o;const a=s.text,A=`${(o=i[i.length-1])==null?void 0:o.text} ${a}`.trim(),c=r.measureText(A);if(c.width>t){const u=e[i.length%e.length];r.font=r.font.replace(zr,u.toString()),i=[...i,{text:a,metrics:r.measureText(a),words:[s]}]}else i[i.length-1]={text:A,metrics:c,words:[...i[i.length-1].words,s]};return i},[{text:n[0].text,metrics:r.measureText(n[0].text),words:[n[0]]}])}finally{r.restore()}},{cacheKey:([{fontSizes:r,words:e,maxW:t}])=>`${JSON.stringify(r)}_${JSON.stringify(e)}_${t}`});let os;const dp=new Uint8Array(16);function fp(){if(!os&&(os=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!os))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return os(dp)}const Et=[];for(let r=0;r<256;++r)Et.push((r+256).toString(16).slice(1));function gp(r,e=0){return Et[r[e+0]]+Et[r[e+1]]+Et[r[e+2]]+Et[r[e+3]]+"-"+Et[r[e+4]]+Et[r[e+5]]+"-"+Et[r[e+6]]+Et[r[e+7]]+"-"+Et[r[e+8]]+Et[r[e+9]]+"-"+Et[r[e+10]]+Et[r[e+11]]+Et[r[e+12]]+Et[r[e+13]]+Et[r[e+14]]+Et[r[e+15]]}const ac={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function pp(r,e,t){if(ac.randomUUID&&!e&&!r)return ac.randomUUID();r=r||{};const n=r.random||(r.rng||fp)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e){t=t||0;for(let i=0;i<16;++i)e[t+i]=n[i];return e}return gp(n)}const lc=uo(({font:r,scale:e,context:t,maxW:n,maxH:i,text:s,minSize:o,maxSize:a})=>{var l,A;let c=0;if(a){c=(o??0)*e;let h=0;for(;a*e>c+1;){c+=1;const d=Vo({context:t,fontSizes:[c],text:s,maxW:n});if(h=d.reduce((f,g)=>(g.metrics.width>f&&(f=g.metrics.width),f),0),h>n||d.length*c>i){c-=1;break}}}else c=parseFloat(((A=(l=r.match(zr))==null?void 0:l.groups)==null?void 0:A.value)??"0")*e;return c},{cacheKey:([{font:r,text:e,minSize:t,maxSize:n,scale:i,maxW:s,maxH:o}])=>`${r}_${e}_${t}_${n}_${i}_${s}_${o}`}),mp="text",Ac={100:"Thin",200:"ExtraLight",300:"Light",400:"Regular",500:"Medium",600:"SemiBold",700:"Bold",800:"ExtraBold",900:"Black"},Ep={type:mp,options:{value:{type:"textarea",name:"value",label:"Text",rows:4},color:{type:"color",name:"color",label:"Text colour"},"font.size":{type:"number",name:"size",label:"Font size",visible:r=>!r.wrap},"font.weight":{type:"select",name:"weight",label:"Font weight",options:r=>{var e;return((e=r.font.family.data)==null?void 0:e.weights.map(({weight:t})=>({label:Ac[t],value:t,data:t})))??[]}},"font.family":{type:"font",name:"family",label:"Font family"},wrap:{type:"checkbox",name:"wrap",label:"Text wrap"},align:{type:"radio",name:"align",label:"Text align",items:[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],visible:r=>r.wrap},fill:{type:"range",name:"fill",label:"Max font size",min:20,max:400,step:1,visible:r=>r.wrap}},transform:{values:r=>{var e;return{value:r.value,color:r.color??"#000000",font:{size:r.font.size,weight:{label:Ac[r.font.weight],value:r.font.weight,data:r.font.weight},family:{label:r.font.family.name,value:r.font.family.name,data:r.font.family}},wrap:r.wrap??!0,align:r.align??"left",fill:[((e=r.fill)==null?void 0:e.maxSize)??400]}},options:r=>{var e;return{value:r.value,color:r.color,font:{size:r.font.size,weight:r.font.weight.data,family:{name:r.font.family.value,weights:((e=r.font.family.data)==null?void 0:e.weights)??[]}},wrap:r.wrap,align:r.align,fill:{minSize:20,maxSize:r.fill[0]}}}},width:({node:r,options:e,dependencies:t,measureCanvas:n})=>{const{value:i="",align:s="left",wrap:o=!1}=e,{font:a}=t,l=n==null?void 0:n.getContext("2d");if(!l)return r.getComputedWidth();const A=`${a.weight} ${a.size}px ${a.family.name}`,c=ss({font:A,text:i});if(l.font=c,l.textBaseline="top",l.textAlign=s,o){const u=r.getParent(),h=r.getComputedMargin(Zt.Edge.Left)+r.getComputedMargin(Zt.Edge.Right)+((u==null?void 0:u.getComputedPadding(Zt.Edge.Left))??0)+((u==null?void 0:u.getComputedPadding(Zt.Edge.Right))??0);return Math.max(((u==null?void 0:u.getComputedWidth())??0)-h,r.getComputedWidth(),...i.split(" ").map(d=>l.measureText(d).width))}return l.measureText(i).width},height:({node:r,options:e,dependencies:t,measureCanvas:n})=>{var i,s;const{value:o="",fill:a,align:l="left",wrap:A=!1}=e,{font:c}=t,u=`${c.weight} ${c.size}px ${c.family.name}`,h=ss({font:u,text:o}),d=n==null?void 0:n.getContext("2d");if(!d)return r.getComputedHeight();if(d.font=h,d.textBaseline="top",d.textAlign=l,A){const f=r.getParent(),g=r.getComputedMargin(Zt.Edge.Top)+r.getComputedMargin(Zt.Edge.Bottom)+((f==null?void 0:f.getComputedPadding(Zt.Edge.Top))??0)+((f==null?void 0:f.getComputedPadding(Zt.Edge.Bottom))??0),p=r.getComputedWidth(),C=Math.max(((f==null?void 0:f.getComputedHeight())??0)-g,r.getComputedHeight()),Q=lc({font:h,scale:1,context:d,maxW:p,maxH:C,text:o??"",minSize:a==null?void 0:a.minSize,maxSize:a==null?void 0:a.maxSize});return Vo({context:d,fontSizes:[Q],text:o??"",maxW:p}).length*Q}else return parseFloat(((s=(i=h.match(zr))==null?void 0:i.groups)==null?void 0:s.value)??"0")},render:({dx:r,dy:e,dw:t,dh:n,options:i,dependencies:s,canvases:o})=>{const{value:a="",fill:l,color:A,align:c="left",wrap:u=!1}=i,{font:h}=s,d=`${h.weight} ${h.size}px ${h.family.name}`,f=o.sceneCanvas.getContext("2d");if(!f)return;f.save();const g=ss({font:d,text:a});f.font=g,f.textBaseline="top",f.fillStyle=A,f.textAlign=c;const p={left:r,center:r+t/2,right:r+t};if(u){const C=lc({font:g,scale:1,context:f,maxW:t,maxH:n,text:a??"",minSize:l==null?void 0:l.minSize,maxSize:l==null?void 0:l.maxSize});f.font=g.replace(zr,C.toString()),Vo({context:f,fontSizes:[C],text:a,maxW:t}).forEach((b,y)=>{f.fillText(b.text,p[c],e+C*y)})}else f.fillText(a,p[c],e);f.restore()}},Ip={type:"image",width:({node:r,dependencies:e})=>{var t,n,i,s;const o=r.getComputedHeight();if(!o)return r.getComputedWidth();const a=((t=e.image)==null?void 0:t.naturalWidth)??((n=e.image)==null?void 0:n.width),l=((i=e.image)==null?void 0:i.naturalHeight)??((s=e.image)==null?void 0:s.height),A=a/l;return o*A},height:({node:r,dependencies:e})=>{var t,n,i,s;const o=((t=e.image)==null?void 0:t.naturalWidth)??((n=e.image)==null?void 0:n.width),a=((i=e.image)==null?void 0:i.naturalHeight)??((s=e.image)==null?void 0:s.height),l=o/a;return r.getComputedWidth()/l},render:async({dx:r,dy:e,dw:t,dh:n,radius:i,dependencies:s,canvases:o})=>{const a=o.sceneCanvas.getContext("2d");if(!(!a||!s.image)){if(a.save(),i){const{topLeft:l,topRight:A,bottomLeft:c,bottomRight:u}=i;sc({context:a,x:r,y:e,width:t,height:n,radii:[l,A,u,c]}),a.clip()}a.drawImage(s.image,r,e,t,n),a.restore()}}},Cp={type:"video",options:{crop:{type:"crop",name:"crop",label:"Crop"},speed:{type:"slider",name:"speed",label:"Speed",min:.5,max:4,step:.01},volume:{type:"slider",name:"volume",label:"Volume",min:0,max:1,step:.01}},transform:{values:r=>({format:r.format??"crop",crop:r.crop??{x:0,y:0,width:1,height:1},speed:[r.speed??1],volume:[r.volume??1]}),options:r=>({format:r.format,crop:r.crop,speed:r.speed[0],volume:r.volume[0]})},width:async({node:r,options:e,dependencies:t})=>{const{crop:n,format:i}=e,{aspectRatio:s}=t;if(i==="crop")return r.getComputedWidth();const o=s*(((n==null?void 0:n.width)??1)/((n==null?void 0:n.height)??1)),a=r.getComputedWidth(),l=r.getComputedHeight(),A=a/l;return o>A?a:l*o},height:async({node:r,options:e,dependencies:t})=>{const{crop:n,format:i}=e,{aspectRatio:s}=t;if(i==="crop")return r.getComputedHeight();const o=s*(((n==null?void 0:n.width)??1)/((n==null?void 0:n.height)??1));return r.getComputedWidth()/o},render:async({dx:r,dy:e,dw:t,dh:n,radius:i,sceneTime:s,options:o,dependencies:a,canvases:l})=>{const{crop:A,format:c="letterbox"}=o,u=l.sceneCanvas.getContext("2d");if(!u)return;const h=await a.video(s),d=(h==null?void 0:h.videoWidth)??(h==null?void 0:h.naturalWidth)??(h==null?void 0:h.width),f=(h==null?void 0:h.videoHeight)??(h==null?void 0:h.naturalHeight)??(h==null?void 0:h.height);if(d&&f){if(u.save(),i){const{topLeft:g,topRight:p,bottomLeft:C,bottomRight:Q}=i;sc({context:u,x:r,y:e,width:t,height:n,radii:[g,p,Q,C]}),u.clip()}up({context:u,crop:A,format:c,sourceWidth:d,sourceHeight:f,source:h,posX:r,posY:e,drawAreaWidth:t,drawAreaHeight:n,cropCanvas:l.cropCanvas,letterboxCanvas:l.letterboxCanvas}),u.restore()}}},vp={type:"audio",options:{speed:{type:"slider",name:"speed",label:"Speed",min:.5,max:4,step:.01},volume:{type:"slider",name:"volume",label:"Volume",min:0,max:1,step:.01}},transform:{values:r=>({speed:[r.speed??1],volume:[r.volume??1]}),options:r=>({speed:r.speed[0],volume:r.volume[0]})}};function yp(r){if(r===null||typeof r!="object")return!1;if(Object.getPrototypeOf(r)===null)return!0;let e=r;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(r)===e}function Bp(r){return r.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\f/g,"\\f").replace(/"/g,'\\"')}const Tp=Xr(()=>Zt.loadYoga());Lf.filters.define("parse",r=>typeof r>"u"?null:typeof r=="string"?`"${Bp(r)}"`:yp(r)||Array.isArray(r)?JSON.stringify(r):r);const Qp="3";function bp(r){return typeof r=="number"?{topLeft:r,topRight:r,bottomRight:r,bottomLeft:r}:{topLeft:(r==null?void 0:r.topLeft)??0,topRight:(r==null?void 0:r.topRight)??0,bottomRight:(r==null?void 0:r.bottomRight)??0,bottomLeft:(r==null?void 0:r.bottomLeft)??0}}function xp(r,e){return typeof r=="number"?{top:r*e,right:r*e,bottom:r*e,left:r*e}:{top:typeof r.top=="number"?r.top*e:r.top,right:typeof r.right=="number"?r.right*e:r.right,bottom:typeof r.bottom=="number"?r.bottom*e:r.bottom,left:typeof r.left=="number"?r.left*e:r.left}}function cc(r,e){return typeof r=="number"?{top:r*e,right:r*e,bottom:r*e,left:r*e}:{top:(typeof r.top=="number"?r.top*e:r.top)??0,right:(typeof r.right=="number"?r.right*e:r.right)??0,bottom:(typeof r.bottom=="number"?r.bottom*e:r.bottom)??0,left:(typeof r.left=="number"?r.left*e:r.left)??0}}function uc(r,e,{layout:t,scale:n=1}){const{position:i="relative",inset:s,width:o,height:a,minWidth:l,minHeight:A,maxWidth:c,maxHeight:u,flex:h,gap:d,margin:f,padding:g,direction:p="column",align:C="start",alignSelf:Q,justify:b="start"}=t??{},y={static:r.POSITION_TYPE_STATIC,relative:r.POSITION_TYPE_RELATIVE,absolute:r.POSITION_TYPE_ABSOLUTE};if(e.setPositionType(y[i]),s){const{top:H,right:V,bottom:P,left:K}=xp(s,n);typeof H<"u"&&e.setPosition(r.EDGE_TOP,H),typeof V<"u"&&e.setPosition(r.EDGE_RIGHT,V),typeof P<"u"&&e.setPosition(r.EDGE_BOTTOM,P),typeof K<"u"&&e.setPosition(r.EDGE_LEFT,K)}const x={row:r.FLEX_DIRECTION_ROW,column:r.FLEX_DIRECTION_COLUMN,"row-reverse":r.FLEX_DIRECTION_ROW_REVERSE,"column-reverse":r.FLEX_DIRECTION_COLUMN_REVERSE};e.setFlexDirection(x[p]);const R={start:r.ALIGN_FLEX_START,end:r.ALIGN_FLEX_END,center:r.ALIGN_CENTER,stretch:r.ALIGN_STRETCH};e.setAlignItems(R[C]),Q&&e.setAlignSelf(R[Q]);const k={start:r.JUSTIFY_FLEX_START,end:r.JUSTIFY_FLEX_END,center:r.JUSTIFY_CENTER,"space-between":r.JUSTIFY_SPACE_BETWEEN,"space-around":r.JUSTIFY_SPACE_AROUND,"space-evenly":r.JUSTIFY_SPACE_EVENLY};if(e.setJustifyContent(k[b]),f){const{top:H,right:V,bottom:P,left:K}=cc(f,n);e.setMargin(r.EDGE_TOP,H),e.setMargin(r.EDGE_RIGHT,V),e.setMargin(r.EDGE_BOTTOM,P),e.setMargin(r.EDGE_LEFT,K)}if(g){const{top:H,right:V,bottom:P,left:K}=cc(g,n);e.setPadding(r.EDGE_TOP,H),e.setPadding(r.EDGE_RIGHT,V),e.setPadding(r.EDGE_BOTTOM,P),e.setPadding(r.EDGE_LEFT,K)}typeof h<"u"&&e.setFlex(h),e.setGap(r.GUTTER_ALL,(d??0)*n),typeof o<"u"&&e.setWidth(typeof o=="number"?o*n:o),typeof a<"u"&&(typeof a=="function"?e.setHeight("100%"):e.setHeight(typeof a=="number"?a*n:a)),typeof l<"u"&&e.setMinWidth(typeof l=="number"?l*n:l),typeof A<"u"&&e.setMinHeight(typeof A=="number"?A*n:A),typeof c<"u"&&e.setMaxWidth(typeof c=="number"?c*n:c),typeof u<"u"&&e.setMaxHeight(typeof u=="number"?u*n:u)}async function hc({yoga:r,index:e,parent:t,element:n,resolvers:i}){var s,o;const{type:a,layout:l={},config:A,options:c,renderer:u}=n,h=r.Node.create();uc(r,h,{layout:l}),t.insertChild(h,e);let d=null;i&&((u==null?void 0:u.type)==="text"||(u==null?void 0:u.type)==="image"||(u==null?void 0:u.type)==="video")&&(d=await((s=i[u.type])==null?void 0:s.call(i,{config:A,options:c}))??null);const f=[];for await(const[g,p]of((o=n.children)==null?void 0:o.entries())??[])f.push(await hc({yoga:r,index:g,parent:h,element:p,resolvers:i}));return t.calculateLayout(),{type:a,node:h,radius:bp(l.radius),element:n,renderer:u,config:A,options:c,dependencies:d,childNodes:f}}function dc(r,e,t=0,n=0){const{top:i,left:s}=r.getComputedLayout(),{top:o,left:a,width:l,height:A}=e.node.getComputedLayout(),c=t+a,u=n+o,h=e.childNodes.map(d=>dc(r,d,c,u));return{...e,x:s+c,y:i+u,width:l,height:A,childNodes:h}}async function Ko(r,e,t){for await(const{node:n,options:i,dependencies:s,renderer:o,childNodes:a}of e){if(o){const{width:l,height:A}=o;if(l){const c=await l({node:n,options:i,dependencies:s,measureCanvas:t});n.setWidth(c)}if(await Ko(r,a,t),A){const c=await A({node:n,options:i,dependencies:s,measureCanvas:t});n.setHeight(c)}}await Ko(r,a,t)}r.calculateLayout()}async function fc({root:r,resolvers:e,measureCanvas:t}){const n=await Tp(),i=n.Node.create();uc(n,i,{layout:r.layout});const s=await hc({yoga:n,index:0,parent:i,element:r.element,resolvers:e});await Ko(i,[s],t);const{top:o,left:a,width:l,height:A}=i.getComputedLayout(),c={root:{x:a,y:o,width:l,height:A},node:dc(i,s)};return i.freeRecursive(),c}function Cr(r){let e=0;for(const t of r)Array.isArray(t)?e+=Cr(t):e+=t;return e}function Wo(r){return r.map(({type:e,duration:t},n)=>{var i,s,o,a;if(e==="transition"){const l=((i=r[n-2])==null?void 0:i.type)==="transition"?r[n-2]:null,A=((s=r[n-1])==null?void 0:s.duration)??1/0,c=((o=r[n+1])==null?void 0:o.duration)??1/0,u=((a=r[n+2])==null?void 0:a.type)==="transition"?r[n+2]:null;return Math.min(l?A/2:A,t,u?c/2:c)*-1}return t})}function gc(r){var e;return{...r,children:((e=r.children)==null?void 0:e.map(t=>{if(t.type!=="recipe")return gc(t)}).filter(Boolean))??[]}}function pc(r){const e={box:0,image:0,video:0,text:0,audio:0};r.renderer&&(e[r.renderer.type]+=1);for(const t of r.children??[]){const{box:n,image:i,video:s,text:o,audio:a}=pc(t);e.box+=n,e.image+=i,e.video+=s,e.text+=o,e.audio+=a}return e}function wp(r){return r.video>0?Cp.type:r.image>0?Ip.type:r.audio>0?vp.type:Ep.type}function mc({node:r,duration:e}){const t=[];if(r.type==="recipe"){const n=gc({...r.element,layout:{...r.element.layout,position:"static",width:"100%",height:"100%",margin:0}}),i=pc(n);t.push({type:wp(i),id:pp(),x:r.x,y:r.y,width:r.width,height:r.height,duration:e,root:{element:n}})}for(const n of r.childNodes)t.push(...mc({node:n,duration:e}));return t}async function Sp({scene:r,start:e=0}){const{root:t,duration:n}=r,i=await fc({root:t});return{type:r.type,start:e,duration:n,layout:i,id:r.id,config:r}}async function Rp({track:r}){const e=Wo(r),t=await Promise.all(r.reduce((s,o,a)=>{if(o.type!=="audio")return s;const l=Cr(e.slice(0,a));return s.push(Sp({scene:o,start:l})),s},[])),n=r.reduce((s,o,a)=>{if(o.type!=="gap")return s;const l=Cr(e.slice(0,a));return s.push({type:o.type,id:o.id,start:l,config:o,duration:o.duration}),s},[]),i=r.map(({id:s})=>t.find(({id:o})=>o===s)??n.find(({id:o})=>o===s)).filter(Boolean);return{type:"audio",scenes:t,gapScenes:n,mergedScenes:i,config:r,duration:Math.max(...i.map(({start:s,duration:o})=>s+o))}}async function Ec(){return document.createElement("canvas")}async function Ic({node:r,canvases:e,sceneTime:t}){var n,i;await((i=(n=r.renderer)==null?void 0:n.render)==null?void 0:i.call(n,{canvases:e,sceneTime:t,dx:r.x,dy:r.y,dw:r.width,dh:r.height,radius:r.radius,options:r.options,dependencies:r.dependencies}));const{sceneCanvas:s}=e,o=s.getContext("2d");o&&(o.strokeStyle="red",o.strokeRect(r.x,r.y,r.width,r.height));for await(const a of r.childNodes)await Ic({node:a,canvases:e,sceneTime:t})}async function Dp({layout:r,canvases:e,sceneTime:t}){const{node:n}=r;await Ic({node:n,canvases:e,sceneTime:t})}async function Jo({scene:r,start:e=0,resolvers:t,rootWidth:n,rootHeight:i,canvasFactory:s=Ec}){var o,a;const{x:l,y:A,width:c,height:u,root:h,duration:d}=r,f=await s(),g=await s(),p=await s(),C=await s(),Q=await s(),b=await s(),y=await fc({root:{...h,layout:{...h.layout,width:n,height:i},element:{...h.element,layout:{...h.element.layout,...typeof l=="number"&&typeof A=="number"?{position:"absolute",inset:{top:A,left:l}}:{},width:c??((o=h.element.layout)==null?void 0:o.width),height:u??((a=h.element.layout)==null?void 0:a.height)}}},resolvers:t,measureCanvas:b}),x=async R=>{const k=Math.max(0,R-e);f.width=f.height=0,f.width=n,f.height=i,await Dp({layout:y,sceneTime:k,canvases:{sceneCanvas:f,cropCanvas:p,letterboxCanvas:C,posterCanvas:Q}})};return{type:r.type,draw:x,start:e,duration:d,layout:y,sceneCanvas:f,transitionCanvas:g,id:r.id,config:r,childScenes:mc({node:y.node,duration:d})}}async function _p({track:r,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i}){const s=Wo(r),o=await Promise.all(r.reduce((c,u,h)=>{const d=Cr(s.slice(0,h));return u.type==="video"&&c.push(Jo({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i})),u.type==="image"&&c.push(Jo({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i})),c},[])),a=r.reduce((c,u,h)=>{if(u.type!=="gap")return c;const d=Cr(s.slice(0,h));return c.push({type:u.type,id:u.id,start:d,config:u,duration:u.duration}),c},[]),l=r.reduce((c,u,h)=>{if(u.type!=="transition")return c;const d=u.duration,f=Cr(s.slice(0,h))-d;return c.push({type:u.type,id:u.id,name:u.name,start:f,duration:d,config:u,to:o.find(({id:g})=>{var p;return g===((p=r[h+1])==null?void 0:p.id)}),from:o.find(({id:g})=>{var p;return g===((p=r[h-1])==null?void 0:p.id)})}),c},[]),A=r.map(({id:c})=>o.find(({id:u})=>u===c)??a.find(({id:u})=>u===c)??l.find(({id:u})=>u===c)).filter(Boolean);return{type:"picture",scenes:o,gapScenes:a,transitions:l,mergedScenes:A,duration:Math.max(0,...A.map(({start:c,duration:u})=>c+u)),trackCanvas:await i()}}async function Lp({track:r,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i}){const s=Wo(r),o=await Promise.all(r.reduce((c,u,h)=>{const d=Cr(s.slice(0,h));return u.type==="text"&&c.push(Jo({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i})),c},[])),a=r.reduce((c,u,h)=>{if(u.type!=="gap")return c;const d=Cr(s.slice(0,h));return c.push({type:u.type,id:u.id,start:d,config:u,duration:u.duration}),c},[]),l=r.reduce((c,u,h)=>{if(u.type!=="transition")return c;const d=u.duration,f=Cr(s.slice(0,h))-d;return c.push({type:u.type,id:u.id,name:u.name,start:f,duration:d,config:u,to:o.find(({id:g})=>{var p;return g===((p=r[h+1])==null?void 0:p.id)}),from:o.find(({id:g})=>{var p;return g===((p=r[h-1])==null?void 0:p.id)})}),c},[]),A=r.map(({id:c})=>o.find(({id:u})=>u===c)??a.find(({id:u})=>u===c)??l.find(({id:u})=>u===c)).filter(Boolean);return{type:"text",scenes:o,gapScenes:a,transitions:l,mergedScenes:A,duration:Math.max(...A.map(({start:c,duration:u})=>c+u)),trackCanvas:await i()}}function Fp(r){return r.some(({type:e})=>e==="video"||e==="image")}function kp(r){return r.some(({type:e})=>e==="audio")}function Mp(r){return r.some(({type:e})=>e==="text")}function Np(r){return r.type==="audio"}const Pp=(((nc=rc)==null?void 0:nc.default)??rc).reduce((r,e)=>(r[e.name]=e,r),{});function Op({name:r,canvas:e,to:t,from:n,progress:i}){var s,o,a;const l=e.getContext("webgl",{alpha:!0});if(l){l.disable(l.DEPTH_TEST),l.pixelStorei(l.UNPACK_FLIP_Y_WEBGL,!0);const A=l.createBuffer();l.bindBuffer(l.ARRAY_BUFFER,A),l.bufferData(l.ARRAY_BUFFER,new Float32Array([-1,-1,-1,4,4,-1]),l.STATIC_DRAW),l.viewport(0,0,e.width,e.height);const c=(((s=ts)==null?void 0:s.default)??ts)(l,n);c.minFilter=l.LINEAR,c.magFilter=l.LINEAR;const u=(((o=ts)==null?void 0:o.default)??ts)(l,t);u.minFilter=l.LINEAR,u.magFilter=l.LINEAR;const h=(((a=tc)==null?void 0:a.default)??tc)(l,Pp[r]);h.draw(i,c,u,e.width,e.height),c.dispose(),u.dispose(),h.dispose(),l.flush()}}async function Cc({config:r,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i=Ec}){const s=await Promise.all(r.tracks.map(async l=>{if(Fp(l))return{...await _p({track:l,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i}),config:l};if(Mp(l))return{...await Lp({track:l,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i}),config:l};if(kp(l))return{...await Rp({track:l}),config:l};throw new Error("Unknown track type")}));console.log({tracks:s});const o=await i();return{draw:async({canvas:l,currentTime:A})=>{const c=l.getContext("2d");if(c){c.globalAlpha=1,c.globalCompositeOperation="source-over",c.clearRect(0,0,l.width,l.height),c.save(),c.fillStyle="black",c.fillRect(0,0,l.width,l.height),c.restore();for await(const u of s){if(Np(u))continue;const{scenes:h,transitions:d,trackCanvas:f}=u;f.width=f.height=0,f.width=l.width,f.height=l.height;const g=h.filter(({start:C,duration:Q})=>A>=C&&A<C+Q);if(g.length<=0)continue;const p=d.find(({start:C,duration:Q})=>A>=C&&A<C+Q);for await(const{id:C,start:Q,duration:b,sceneCanvas:y,transitionCanvas:x,draw:R}of g)if(await(R==null?void 0:R(A)),!p)c.drawImage(y,0,0,y.width,y.height);else{const{name:k,to:H,from:V,duration:P}=p;o.width=o.height=x.width=x.height=0,o.width=x.width=y.width,o.height=x.height=y.height;const K=(H==null?void 0:H.id)===C,re=(V==null?void 0:V.id)===C,ee=K&&H.sceneCanvas||o,le=re&&V.sceneCanvas||o,D=K?Math.min(1,Math.max(0,(A-Q)/P)):Math.min(1,Math.max(0,1-(Q+b-A)/P));Op({name:k,progress:D,to:ee,from:le,canvas:x});const O=f.getContext("2d");if(!O)return;O.globalCompositeOperation="lighter",O.drawImage(x,0,0,x.width,x.height)}c.drawImage(f,0,0,f.width,f.height)}}},tracks:s,duration:Math.max(...s.map(({duration:l})=>l))}}const Up={name:"@vouchfor/embeds",version:"0.0.0-experiment.b6b97eb",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds.js",module:"dist/es/embeds.js",type:"module",types:"dist/es/src/index.d.ts",exports:{".":"./dist/es/embeds.js"},files:["dist","src"],publishConfig:{tag:"experiment",access:"public"},engines:{node:">=18.18.0"},scripts:{build:"rm -rf dist && tsc && yarn build:self","build:deps":"yarn --cwd ../media-player build","build:self":"vite build --mode iife && vite build --mode es && node scripts/build.cjs","build:package":"yarn build","build:storybook":"yarn prebuild && storybook build","generate:manifest":"wca src --outFile custom-elements.json",lint:"eslint . --quiet","lint:fix":"eslint . --fix","lint:staged":"lint-staged",prepublishOnly:"yarn build",size:"size-limit",storybook:"yarn prebuild && storybook dev -p 6007",prebuild:"yarn build:deps && yarn generate:manifest",test:"rm -rf test/lib && yarn prebuild && vite build --mode test && web-test-runner","test:ci":"yarn test --config web-test-runner.ci.config.js","test:watch":"yarn test --watch"},"lint-staged":{"**/*.{ts,tsx,js}":"eslint --fix --quiet","**/*.{md,json,yml}":"prettier --write"},dependencies:{"@a11y/focus-trap":"^1.0.5","@lit/task":"^1.0.0","@vouchfor/canvas-video":"0.0.0-experiment.b6b97eb","@vouchfor/media-player":"0.0.0-experiment.b6b97eb",uuid:"^9.0.1"},peerDependencies:{lit:"^3.1.2"},devDependencies:{"@esm-bundle/chai":"^4.3.4-fix.0","@open-wc/testing":"^4.0.0","@storybook/addon-essentials":"^8.0.4","@storybook/addon-links":"^8.0.4","@storybook/blocks":"^8.0.4","@storybook/web-components":"^8.0.4","@storybook/web-components-vite":"^8.0.4","@svgr/core":"^8.1.0","@types/flat":"^5.0.5","@types/mocha":"^10.0.6","@vouchfor/eslint-config":"^1.0.1","@vouchfor/prettier-config":"^1.0.1","@vouchfor/video-utils":"0.0.0-experiment.b6b97eb","@web/dev-server-esbuild":"^1.0.2","@web/test-runner":"^0.18.1","@web/test-runner-browserstack":"^0.7.1","@web/test-runner-mocha":"^0.9.0","@web/test-runner-playwright":"^0.11.0",glob:"^10.3.10","lint-staged":"^15.2.2",lit:"^3.1.2",lodash:"^4.17.21",react:"^18.2.0","react-dom":"^18.2.0","rollup-plugin-tla":"^0.0.2",sinon:"^17.0.1",storybook:"^8.0.4",svgson:"^5.3.1",typescript:"^5.4.3",vite:"^5.2.2","vite-plugin-commonjs":"^0.10.1","vite-plugin-dts":"^3.7.3","web-component-analyzer":"^2.0.0"}};function Gp(r){const{publicApiUrl:e}=Pi(r),t=Wr();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function Hp(r){var s,o,a,l,A,c,u,h,d,f,g,p;if(typeof window>"u")return{client:null,tab:null,request:Wr()};let e=(o=(s=window.localStorage)==null?void 0:s.getItem)==null?void 0:o.call(s,"vouch-uid-visitor"),t=(l=(a=window.localStorage)==null?void 0:a.getItem)==null?void 0:l.call(a,"vouch-uid-client"),n=(c=(A=window.sessionStorage)==null?void 0:A.getItem)==null?void 0:c.call(A,"vouch-uid-tab");const i=Wr();return e||(e=Gp(r),(h=(u=window.localStorage)==null?void 0:u.setItem)==null||h.call(u,"vouch-uid-visitor",e)),t||(t=Wr(),(f=(d=window.localStorage)==null?void 0:d.setItem)==null||f.call(d,"vouch-uid-client",t)),n||(n=Wr(),(p=(g=window.sessionStorage)==null?void 0:g.setItem)==null||p.call(g,"vouch-uid-tab",n)),{client:t,tab:n,request:i,visitor:e}}function $p(r,e){return r&&"vouchId"in r?r.vouchId:(e==null?void 0:e.id)??null}function Yp(r="embedded_player"){var i,s;const[e,t]=((s=(i=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:i.split)==null?void 0:s.call(i,"/"))??[],n={};return[...new URLSearchParams(location.search).entries()].forEach(([o,a])=>{if(/utm/.test(o)){const l=o.toLowerCase().replace(/[-_][a-z0-9]/g,A=>A.slice(-1).toUpperCase());n[l]=a}}),{source:r,time:new Date,region:t,country:e,screenHeight:window.screen.height,screenWidth:window.screen.width,referrer:document.referrer,currentUrl:location.href,embedType:"media-player-embed",embedVersion:Up.version,templateVersion:Qp,...n}}const vc=1;class Vp{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,n)=>{const i=$p(n,this.host.vouch);!i||this.host.disableTracking||this._batchedEvents.push({event:t,payload:{...n,vouchId:i,time:new Date().toISOString()}})},this._sendTrackingEvent=()=>{if(this._batchedEvents.length<=0)return;const{publicApiUrl:t}=Pi(this.host.env),{client:n,tab:i,request:s,visitor:o}=Hp(this.host.env);navigator.sendBeacon(`${t}/api/batchevents`,JSON.stringify({payload:{events:this._batchedEvents},context:{"x-uid-client":n,"x-uid-tab":i,"x-uid-request":s,"x-uid-visitor":o,"x-reporting-metadata":Yp(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:n}=this._currentlyPlayingVideo;this._streamLatestTime[n]>this._streamStartTime[n]+vc&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[n],streamEnd:this._streamLatestTime[n]}),delete this._streamStartTime[n],delete this._streamLatestTime[n]}},this._handleVouchLoaded=({detail:t})=>{t&&(this._hasLoaded[t]||(this._createTrackingEvent("VOUCH_LOADED",{vouchId:t}),this._hasLoaded[t]=!0))},this._handlePlay=()=>{this._hasPlayed||(this._createTrackingEvent("VIDEO_PLAYED",{streamStart:this.host.currentTime}),this._hasPlayed=!0)},this._handleVideoPlay=({detail:{id:t,key:n}})=>{this._answersViewed[n]||(this._createTrackingEvent("VOUCH_RESPONSE_VIEWED",{answerId:t}),this._answersViewed[n]=!0)},this._handleVideoTimeUpdate=({detail:{id:t,key:n,node:i}})=>{this.host.paused||(this._currentlyPlayingVideo={id:t,key:n,node:i},this._streamLatestTime[n]=i.currentTime,this._streamStartTime[n]||(this._streamStartTime[n]=i.currentTime,this._streamLatestTime[n]=i.currentTime))},this._handleVideoPause=({detail:{id:t,key:n}})=>{this._streamLatestTime[n]>this._streamStartTime[n]+vc&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[n],streamEnd:this._streamLatestTime[n]}),delete this._streamStartTime[n],delete this._streamLatestTime[n]},this._pageUnloading=()=>{this._streamEnded(),this._sendTrackingEvent()},this._handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this._pageUnloading()},this._handlePageHide=()=>{this._pageUnloading()},this.host=e,e.addController(this)}hostConnected(){requestAnimationFrame(()=>{var e,t,n,i;"onvisibilitychange"in document?document.addEventListener("visibilitychange",this._handleVisibilityChange):window.addEventListener("pagehide",this._handlePageHide),this.host.addEventListener("vouch:loaded",this._handleVouchLoaded),(e=this.host.mediaPlayer)==null||e.addEventListener("play",this._handlePlay),(t=this.host.mediaPlayer)==null||t.addEventListener("video:play",this._handleVideoPlay),(n=this.host.mediaPlayer)==null||n.addEventListener("video:pause",this._handleVideoPause),(i=this.host.mediaPlayer)==null||i.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var e,t,n,i;this._pageUnloading(),"onvisibilitychange"in document?document.removeEventListener("visibilitychange",this._handleVisibilityChange):window.removeEventListener("pagehide",this._handlePageHide),this.host.removeEventListener("vouch:loaded",this._handleVouchLoaded),(e=this.host.mediaPlayer)==null||e.removeEventListener("play",this._handlePlay),(t=this.host.mediaPlayer)==null||t.removeEventListener("video:play",this._handleVideoPlay),(n=this.host.mediaPlayer)==null||n.removeEventListener("video:pause",this._handleVideoPause),(i=this.host.mediaPlayer)==null||i.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}var qo={exports:{}};(function(r,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof En<"u"&&En,n=function(){function s(){this.fetch=!1,this.DOMException=t.DOMException}return s.prototype=t,new s}();(function(s){(function(o){var a=typeof s<"u"&&s||typeof self<"u"&&self||typeof a<"u"&&a,l={searchParams:"URLSearchParams"in a,iterable:"Symbol"in a&&"iterator"in Symbol,blob:"FileReader"in a&&"Blob"in a&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in a,arrayBuffer:"ArrayBuffer"in a};function A(D){return D&&DataView.prototype.isPrototypeOf(D)}if(l.arrayBuffer)var c=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(D){return D&&c.indexOf(Object.prototype.toString.call(D))>-1};function h(D){if(typeof D!="string"&&(D=String(D)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(D)||D==="")throw new TypeError('Invalid character in header field name: "'+D+'"');return D.toLowerCase()}function d(D){return typeof D!="string"&&(D=String(D)),D}function f(D){var O={next:function(){var X=D.shift();return{done:X===void 0,value:X}}};return l.iterable&&(O[Symbol.iterator]=function(){return O}),O}function g(D){this.map={},D instanceof g?D.forEach(function(O,X){this.append(X,O)},this):Array.isArray(D)?D.forEach(function(O){this.append(O[0],O[1])},this):D&&Object.getOwnPropertyNames(D).forEach(function(O){this.append(O,D[O])},this)}g.prototype.append=function(D,O){D=h(D),O=d(O);var X=this.map[D];this.map[D]=X?X+", "+O:O},g.prototype.delete=function(D){delete this.map[h(D)]},g.prototype.get=function(D){return D=h(D),this.has(D)?this.map[D]:null},g.prototype.has=function(D){return this.map.hasOwnProperty(h(D))},g.prototype.set=function(D,O){this.map[h(D)]=d(O)},g.prototype.forEach=function(D,O){for(var X in this.map)this.map.hasOwnProperty(X)&&D.call(O,this.map[X],X,this)},g.prototype.keys=function(){var D=[];return this.forEach(function(O,X){D.push(X)}),f(D)},g.prototype.values=function(){var D=[];return this.forEach(function(O){D.push(O)}),f(D)},g.prototype.entries=function(){var D=[];return this.forEach(function(O,X){D.push([X,O])}),f(D)},l.iterable&&(g.prototype[Symbol.iterator]=g.prototype.entries);function p(D){if(D.bodyUsed)return Promise.reject(new TypeError("Already read"));D.bodyUsed=!0}function C(D){return new Promise(function(O,X){D.onload=function(){O(D.result)},D.onerror=function(){X(D.error)}})}function Q(D){var O=new FileReader,X=C(O);return O.readAsArrayBuffer(D),X}function b(D){var O=new FileReader,X=C(O);return O.readAsText(D),X}function y(D){for(var O=new Uint8Array(D),X=new Array(O.length),_=0;_<O.length;_++)X[_]=String.fromCharCode(O[_]);return X.join("")}function x(D){if(D.slice)return D.slice(0);var O=new Uint8Array(D.byteLength);return O.set(new Uint8Array(D)),O.buffer}function R(){return this.bodyUsed=!1,this._initBody=function(D){this.bodyUsed=this.bodyUsed,this._bodyInit=D,D?typeof D=="string"?this._bodyText=D:l.blob&&Blob.prototype.isPrototypeOf(D)?this._bodyBlob=D:l.formData&&FormData.prototype.isPrototypeOf(D)?this._bodyFormData=D:l.searchParams&&URLSearchParams.prototype.isPrototypeOf(D)?this._bodyText=D.toString():l.arrayBuffer&&l.blob&&A(D)?(this._bodyArrayBuffer=x(D.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):l.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(D)||u(D))?this._bodyArrayBuffer=x(D):this._bodyText=D=Object.prototype.toString.call(D):this._bodyText="",this.headers.get("content-type")||(typeof D=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):l.searchParams&&URLSearchParams.prototype.isPrototypeOf(D)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},l.blob&&(this.blob=function(){var D=p(this);if(D)return D;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){if(this._bodyArrayBuffer){var D=p(this);return D||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else return this.blob().then(Q)}),this.text=function(){var D=p(this);if(D)return D;if(this._bodyBlob)return b(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(y(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},l.formData&&(this.formData=function(){return this.text().then(P)}),this.json=function(){return this.text().then(JSON.parse)},this}var k=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function H(D){var O=D.toUpperCase();return k.indexOf(O)>-1?O:D}function V(D,O){if(!(this instanceof V))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');O=O||{};var X=O.body;if(D instanceof V){if(D.bodyUsed)throw new TypeError("Already read");this.url=D.url,this.credentials=D.credentials,O.headers||(this.headers=new g(D.headers)),this.method=D.method,this.mode=D.mode,this.signal=D.signal,!X&&D._bodyInit!=null&&(X=D._bodyInit,D.bodyUsed=!0)}else this.url=String(D);if(this.credentials=O.credentials||this.credentials||"same-origin",(O.headers||!this.headers)&&(this.headers=new g(O.headers)),this.method=H(O.method||this.method||"GET"),this.mode=O.mode||this.mode||null,this.signal=O.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&X)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(X),(this.method==="GET"||this.method==="HEAD")&&(O.cache==="no-store"||O.cache==="no-cache")){var _=/([?&])_=[^&]*/;if(_.test(this.url))this.url=this.url.replace(_,"$1_="+new Date().getTime());else{var S=/\?/;this.url+=(S.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}V.prototype.clone=function(){return new V(this,{body:this._bodyInit})};function P(D){var O=new FormData;return D.trim().split("&").forEach(function(X){if(X){var _=X.split("="),S=_.shift().replace(/\+/g," "),F=_.join("=").replace(/\+/g," ");O.append(decodeURIComponent(S),decodeURIComponent(F))}}),O}function K(D){var O=new g,X=D.replace(/\r?\n[\t ]+/g," ");return X.split("\r").map(function(_){return _.indexOf(`
2454
+ `).flatMap(s=>{const o=s.split(" ").filter(Boolean);return o.length?o.slice(1).reduce((a,l,A)=>{const u=`${a[a.length-1].text} ${l}`.trim(),h=r.measureText(u);if(h.width>n)a=[...a,...ic({context:r,word:l,maxW:n})];else{const d=e[A%e.length];r.font=r.font.replace(zr,d.toString()),a[a.length-1]={text:u,metrics:h}}return a},ic({context:r,word:o[0],maxW:n})):{text:"",metrics:r.measureText("")}})}finally{r.restore()}},{cacheKey:([{fontSizes:r,text:e,maxW:t}])=>`${JSON.stringify(r)}_${e}_${t}`}),Ir=1.8;function hp({context:r,x:e,y:t,width:n,height:i,radii:s}){let o,a,l,A;typeof s=="number"?o=a=l=A=s:[o,a,l,A]=s,r.beginPath(),r.moveTo(e+Math.min(i/Ir,o),t),r.lineTo(e+n-Math.min(i/Ir,a),t),r.quadraticCurveTo(e+n,t,e+n,t+Math.min(i/Ir,a)),r.lineTo(e+n,t+i-Math.min(i/Ir,l)),r.quadraticCurveTo(e+n,t+i,e+n-Math.min(i/Ir,l),t+i),r.lineTo(e+Math.min(i/Ir,A),t+i),r.quadraticCurveTo(e,t+i,e,t+i-Math.min(i/Ir,A)),r.lineTo(e,t+Math.min(i/Ir,o)),r.quadraticCurveTo(e,t,e+Math.min(i/Ir,o),t),r.closePath()}function sc({context:r,x:e,y:t,width:n,height:i,radii:s,clip:o=!1,debug:a=!1}){hp({context:r,x:e,y:t,width:n,height:i,radii:s}),a&&(r.strokeStyle="blue",r.stroke()),o&&r.clip()}const oc=[{family:"Noto Arabic",regex:new RegExp("\\p{Script=Arabic}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansArabic-VariableFont_wdth%2Cwght.woff2",style:"normal"},{family:"Noto Chinese",regex:new RegExp("\\p{Script=Han}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansSC-VariableFont_wght.woff2",style:"normal"},{family:"Noto Hebrew",regex:new RegExp("\\p{Script=Hebrew}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansHebrew-VariableFont_wdth%2Cwght.woff2",style:"normal"},{family:"Noto Hindi",regex:new RegExp("\\p{Script=Devanagari}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansDevanagari-VariableFont_wdth%2Cwght.woff2",style:"normal"},{family:"Noto Japanese",regex:new RegExp("\\p{Script=Han}|\\p{Script=Katakana}|\\p{Script=Hiragana}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansJP-VariableFont_wght.woff2",style:"normal"},{family:"Noto Korean",regex:new RegExp("\\p{Script=Hangul}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoSansKR-VariableFont_wght.woff2",style:"normal"},{family:"Noto Color Emoji",regex:new RegExp("\\p{Extended_Pictographic}","u"),url:"https://media-player-fonts.s3.ap-southeast-2.amazonaws.com/NotoColorEmoji-Regular.woff2",style:"normal"}];function ss({text:r,font:e}){let t=e;return oc.forEach(({family:n,regex:i})=>{i.exec(r)&&(t+=`, ${n}`)}),t}uo(({context:r,fontSizes:e,maxW:t=1/0,words:n})=>{try{return r.save(),r.font=r.font.replace(zr,e[0].toString()),n.length<=0?[]:n.slice(1).reduce((i,s)=>{var o;const a=s.text,A=`${(o=i[i.length-1])==null?void 0:o.text} ${a}`.trim(),c=r.measureText(A);if(c.width>t){const u=e[i.length%e.length];r.font=r.font.replace(zr,u.toString()),i=[...i,{text:a,metrics:r.measureText(a),words:[s]}]}else i[i.length-1]={text:A,metrics:c,words:[...i[i.length-1].words,s]};return i},[{text:n[0].text,metrics:r.measureText(n[0].text),words:[n[0]]}])}finally{r.restore()}},{cacheKey:([{fontSizes:r,words:e,maxW:t}])=>`${JSON.stringify(r)}_${JSON.stringify(e)}_${t}`});let os;const dp=new Uint8Array(16);function fp(){if(!os&&(os=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!os))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return os(dp)}const Et=[];for(let r=0;r<256;++r)Et.push((r+256).toString(16).slice(1));function gp(r,e=0){return Et[r[e+0]]+Et[r[e+1]]+Et[r[e+2]]+Et[r[e+3]]+"-"+Et[r[e+4]]+Et[r[e+5]]+"-"+Et[r[e+6]]+Et[r[e+7]]+"-"+Et[r[e+8]]+Et[r[e+9]]+"-"+Et[r[e+10]]+Et[r[e+11]]+Et[r[e+12]]+Et[r[e+13]]+Et[r[e+14]]+Et[r[e+15]]}const ac={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function pp(r,e,t){if(ac.randomUUID&&!e&&!r)return ac.randomUUID();r=r||{};const n=r.random||(r.rng||fp)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e){t=t||0;for(let i=0;i<16;++i)e[t+i]=n[i];return e}return gp(n)}const mp={type:"audio",options:{speed:{type:"slider",name:"speed",label:"Speed",min:.5,max:4,step:.01},volume:{type:"slider",name:"volume",label:"Volume",min:0,max:1,step:.01}},transform:{values:r=>({speed:[r.speed??1],volume:[r.volume??1]}),options:r=>({speed:r.speed[0],volume:r.volume[0]})}},Ep={type:"image",width:({node:r,dependencies:e})=>{var t,n,i,s;const o=r.getComputedHeight();if(!o)return r.getComputedWidth();const a=((t=e.image)==null?void 0:t.naturalWidth)??((n=e.image)==null?void 0:n.width),l=((i=e.image)==null?void 0:i.naturalHeight)??((s=e.image)==null?void 0:s.height),A=a/l;return o*A},height:({node:r,dependencies:e})=>{var t,n,i,s;const o=((t=e.image)==null?void 0:t.naturalWidth)??((n=e.image)==null?void 0:n.width),a=((i=e.image)==null?void 0:i.naturalHeight)??((s=e.image)==null?void 0:s.height),l=o/a;return r.getComputedWidth()/l},render:async({dx:r,dy:e,dw:t,dh:n,radius:i,dependencies:s,canvases:o})=>{const a=o.sceneCanvas.getContext("2d");if(!(!a||!s.image)){if(a.save(),i){const{topLeft:l,topRight:A,bottomLeft:c,bottomRight:u}=i;sc({context:a,x:r,y:e,width:t,height:n,radii:[l,A,u,c]}),a.clip()}a.drawImage(s.image,r,e,t,n),a.restore()}}},lc=uo(({font:r,scale:e,context:t,maxW:n,maxH:i,text:s,minSize:o,maxSize:a})=>{var l,A;let c=0;if(a){c=(o??0)*e;let h=0;for(;a*e>c+1;){c+=1;const d=Vo({context:t,fontSizes:[c],text:s,maxW:n});if(h=d.reduce((f,g)=>(g.metrics.width>f&&(f=g.metrics.width),f),0),h>n||d.length*c>i){c-=1;break}}}else c=parseFloat(((A=(l=r.match(zr))==null?void 0:l.groups)==null?void 0:A.value)??"0")*e;return c},{cacheKey:([{font:r,text:e,minSize:t,maxSize:n,scale:i,maxW:s,maxH:o}])=>`${r}_${e}_${t}_${n}_${i}_${s}_${o}`}),Ip="text",Ac={100:"Thin",200:"ExtraLight",300:"Light",400:"Regular",500:"Medium",600:"SemiBold",700:"Bold",800:"ExtraBold",900:"Black"},Cp={type:Ip,options:{value:{type:"textarea",name:"value",label:"Text",rows:4},color:{type:"color",name:"color",label:"Text colour"},"font.size":{type:"number",name:"size",label:"Font size",visible:r=>!r.wrap},"font.weight":{type:"select",name:"weight",label:"Font weight",options:r=>{var e;return((e=r.font.family.data)==null?void 0:e.weights.map(({weight:t})=>({label:Ac[t],value:t,data:t})))??[]}},"font.family":{type:"font",name:"family",label:"Font family"},wrap:{type:"checkbox",name:"wrap",label:"Text wrap"},align:{type:"radio",name:"align",label:"Text align",items:[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],visible:r=>r.wrap},fill:{type:"range",name:"fill",label:"Max font size",min:20,max:400,step:1,visible:r=>r.wrap}},transform:{values:r=>{var e;return{value:r.value,color:r.color??"#000000",font:{size:r.font.size,weight:{label:Ac[r.font.weight],value:r.font.weight,data:r.font.weight},family:{label:r.font.family.name,value:r.font.family.name,data:r.font.family}},wrap:r.wrap??!0,align:r.align??"left",fill:[((e=r.fill)==null?void 0:e.maxSize)??400]}},options:r=>{var e;return{value:r.value,color:r.color,font:{size:r.font.size,weight:r.font.weight.data,family:{name:r.font.family.value,weights:((e=r.font.family.data)==null?void 0:e.weights)??[]}},wrap:r.wrap,align:r.align,fill:{minSize:20,maxSize:r.fill[0]}}}},width:({node:r,options:e,dependencies:t,measureCanvas:n})=>{const{value:i="",align:s="left",wrap:o=!1}=e,{font:a}=t,l=n==null?void 0:n.getContext("2d");if(!l)return r.getComputedWidth();const A=`${a.weight} ${a.size}px ${a.family.name}`,c=ss({font:A,text:i});if(l.font=c,l.textBaseline="top",l.textAlign=s,o){const u=r.getParent(),h=r.getComputedMargin(Zt.Edge.Left)+r.getComputedMargin(Zt.Edge.Right)+((u==null?void 0:u.getComputedPadding(Zt.Edge.Left))??0)+((u==null?void 0:u.getComputedPadding(Zt.Edge.Right))??0);return Math.max(((u==null?void 0:u.getComputedWidth())??0)-h,r.getComputedWidth(),...i.split(" ").map(d=>l.measureText(d).width))}return l.measureText(i).width},height:({node:r,options:e,dependencies:t,measureCanvas:n})=>{var i,s;const{value:o="",fill:a,align:l="left",wrap:A=!1}=e,{font:c}=t,u=`${c.weight} ${c.size}px ${c.family.name}`,h=ss({font:u,text:o}),d=n==null?void 0:n.getContext("2d");if(!d)return r.getComputedHeight();if(d.font=h,d.textBaseline="top",d.textAlign=l,A){const f=r.getParent(),g=r.getComputedMargin(Zt.Edge.Top)+r.getComputedMargin(Zt.Edge.Bottom)+((f==null?void 0:f.getComputedPadding(Zt.Edge.Top))??0)+((f==null?void 0:f.getComputedPadding(Zt.Edge.Bottom))??0),p=r.getComputedWidth(),C=Math.max(((f==null?void 0:f.getComputedHeight())??0)-g,r.getComputedHeight()),Q=lc({font:h,scale:1,context:d,maxW:p,maxH:C,text:o??"",minSize:a==null?void 0:a.minSize,maxSize:a==null?void 0:a.maxSize});return Vo({context:d,fontSizes:[Q],text:o??"",maxW:p}).length*Q}else return parseFloat(((s=(i=h.match(zr))==null?void 0:i.groups)==null?void 0:s.value)??"0")},render:({dx:r,dy:e,dw:t,dh:n,options:i,dependencies:s,canvases:o})=>{const{value:a="",fill:l,color:A,align:c="left",wrap:u=!1}=i,{font:h}=s,d=`${h.weight} ${h.size}px ${h.family.name}`,f=o.sceneCanvas.getContext("2d");if(!f)return;f.save();const g=ss({font:d,text:a});f.font=g,f.textBaseline="top",f.fillStyle=A,f.textAlign=c;const p={left:r,center:r+t/2,right:r+t};if(u){const C=lc({font:g,scale:1,context:f,maxW:t,maxH:n,text:a??"",minSize:l==null?void 0:l.minSize,maxSize:l==null?void 0:l.maxSize});f.font=g.replace(zr,C.toString()),Vo({context:f,fontSizes:[C],text:a,maxW:t}).forEach((b,y)=>{f.fillText(b.text,p[c],e+C*y)})}else f.fillText(a,p[c],e);f.restore()}},vp={type:"video",options:{crop:{type:"crop",name:"crop",label:"Crop"},speed:{type:"slider",name:"speed",label:"Speed",min:.5,max:4,step:.01},volume:{type:"slider",name:"volume",label:"Volume",min:0,max:1,step:.01}},transform:{values:r=>({format:r.format??"crop",crop:r.crop??{x:0,y:0,width:1,height:1},speed:[r.speed??1],volume:[r.volume??1]}),options:r=>({format:r.format,crop:r.crop,speed:r.speed[0],volume:r.volume[0]})},width:async({node:r,options:e,dependencies:t})=>{const{crop:n,format:i}=e,{aspectRatio:s}=t;if(i==="crop")return r.getComputedWidth();const o=s*(((n==null?void 0:n.width)??1)/((n==null?void 0:n.height)??1)),a=r.getComputedWidth(),l=r.getComputedHeight(),A=a/l;return o>A?a:l*o},height:async({node:r,options:e,dependencies:t})=>{const{crop:n,format:i}=e,{aspectRatio:s}=t;if(i==="crop")return r.getComputedHeight();const o=s*(((n==null?void 0:n.width)??1)/((n==null?void 0:n.height)??1));return r.getComputedWidth()/o},render:async({dx:r,dy:e,dw:t,dh:n,radius:i,sceneTime:s,options:o,dependencies:a,canvases:l})=>{const{crop:A,format:c="letterbox"}=o,u=l.sceneCanvas.getContext("2d");if(!u)return;const h=await a.video(s),d=(h==null?void 0:h.videoWidth)??(h==null?void 0:h.naturalWidth)??(h==null?void 0:h.width),f=(h==null?void 0:h.videoHeight)??(h==null?void 0:h.naturalHeight)??(h==null?void 0:h.height);if(d&&f){if(u.save(),i){const{topLeft:g,topRight:p,bottomLeft:C,bottomRight:Q}=i;sc({context:u,x:r,y:e,width:t,height:n,radii:[g,p,Q,C]}),u.clip()}up({context:u,crop:A,format:c,sourceWidth:d,sourceHeight:f,source:h,posX:r,posY:e,drawAreaWidth:t,drawAreaHeight:n,cropCanvas:l.cropCanvas,letterboxCanvas:l.letterboxCanvas}),u.restore()}}};function yp(r){if(r===null||typeof r!="object")return!1;if(Object.getPrototypeOf(r)===null)return!0;let e=r;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(r)===e}function Bp(r){return r.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\f/g,"\\f").replace(/"/g,'\\"')}const Tp=Xr(()=>Zt.loadYoga());Lf.filters.define("parse",r=>typeof r>"u"?null:typeof r=="string"?`"${Bp(r)}"`:yp(r)||Array.isArray(r)?JSON.stringify(r):r);const Qp="3";function bp(r){return typeof r=="number"?{topLeft:r,topRight:r,bottomRight:r,bottomLeft:r}:{topLeft:(r==null?void 0:r.topLeft)??0,topRight:(r==null?void 0:r.topRight)??0,bottomRight:(r==null?void 0:r.bottomRight)??0,bottomLeft:(r==null?void 0:r.bottomLeft)??0}}function xp(r,e){return typeof r=="number"?{top:r*e,right:r*e,bottom:r*e,left:r*e}:{top:typeof r.top=="number"?r.top*e:r.top,right:typeof r.right=="number"?r.right*e:r.right,bottom:typeof r.bottom=="number"?r.bottom*e:r.bottom,left:typeof r.left=="number"?r.left*e:r.left}}function cc(r,e){return typeof r=="number"?{top:r*e,right:r*e,bottom:r*e,left:r*e}:{top:(typeof r.top=="number"?r.top*e:r.top)??0,right:(typeof r.right=="number"?r.right*e:r.right)??0,bottom:(typeof r.bottom=="number"?r.bottom*e:r.bottom)??0,left:(typeof r.left=="number"?r.left*e:r.left)??0}}function uc(r,e,{layout:t,scale:n=1}){const{position:i="relative",inset:s,width:o,height:a,minWidth:l,minHeight:A,maxWidth:c,maxHeight:u,flex:h,gap:d,margin:f,padding:g,direction:p="column",align:C="start",alignSelf:Q,justify:b="start"}=t??{},y={static:r.POSITION_TYPE_STATIC,relative:r.POSITION_TYPE_RELATIVE,absolute:r.POSITION_TYPE_ABSOLUTE};if(e.setPositionType(y[i]),s){const{top:H,right:V,bottom:P,left:K}=xp(s,n);typeof H<"u"&&e.setPosition(r.EDGE_TOP,H),typeof V<"u"&&e.setPosition(r.EDGE_RIGHT,V),typeof P<"u"&&e.setPosition(r.EDGE_BOTTOM,P),typeof K<"u"&&e.setPosition(r.EDGE_LEFT,K)}const x={row:r.FLEX_DIRECTION_ROW,column:r.FLEX_DIRECTION_COLUMN,"row-reverse":r.FLEX_DIRECTION_ROW_REVERSE,"column-reverse":r.FLEX_DIRECTION_COLUMN_REVERSE};e.setFlexDirection(x[p]);const R={start:r.ALIGN_FLEX_START,end:r.ALIGN_FLEX_END,center:r.ALIGN_CENTER,stretch:r.ALIGN_STRETCH};e.setAlignItems(R[C]),Q&&e.setAlignSelf(R[Q]);const k={start:r.JUSTIFY_FLEX_START,end:r.JUSTIFY_FLEX_END,center:r.JUSTIFY_CENTER,"space-between":r.JUSTIFY_SPACE_BETWEEN,"space-around":r.JUSTIFY_SPACE_AROUND,"space-evenly":r.JUSTIFY_SPACE_EVENLY};if(e.setJustifyContent(k[b]),f){const{top:H,right:V,bottom:P,left:K}=cc(f,n);e.setMargin(r.EDGE_TOP,H),e.setMargin(r.EDGE_RIGHT,V),e.setMargin(r.EDGE_BOTTOM,P),e.setMargin(r.EDGE_LEFT,K)}if(g){const{top:H,right:V,bottom:P,left:K}=cc(g,n);e.setPadding(r.EDGE_TOP,H),e.setPadding(r.EDGE_RIGHT,V),e.setPadding(r.EDGE_BOTTOM,P),e.setPadding(r.EDGE_LEFT,K)}typeof h<"u"&&e.setFlex(h),e.setGap(r.GUTTER_ALL,(d??0)*n),typeof o<"u"&&e.setWidth(typeof o=="number"?o*n:o),typeof a<"u"&&(typeof a=="function"?e.setHeight("100%"):e.setHeight(typeof a=="number"?a*n:a)),typeof l<"u"&&e.setMinWidth(typeof l=="number"?l*n:l),typeof A<"u"&&e.setMinHeight(typeof A=="number"?A*n:A),typeof c<"u"&&e.setMaxWidth(typeof c=="number"?c*n:c),typeof u<"u"&&e.setMaxHeight(typeof u=="number"?u*n:u)}async function hc({yoga:r,index:e,parent:t,element:n,resolvers:i}){var s,o;const{type:a,layout:l={},config:A,options:c,renderer:u}=n,h=r.Node.create();uc(r,h,{layout:l}),t.insertChild(h,e);let d=null;i&&((u==null?void 0:u.type)==="text"||(u==null?void 0:u.type)==="image"||(u==null?void 0:u.type)==="video")&&(d=await((s=i[u.type])==null?void 0:s.call(i,{config:A,options:c}))??null);const f=[];for await(const[g,p]of((o=n.children)==null?void 0:o.entries())??[])f.push(await hc({yoga:r,index:g,parent:h,element:p,resolvers:i}));return t.calculateLayout(),{type:a,node:h,radius:bp(l.radius),element:n,renderer:u,config:A,options:c,dependencies:d,childNodes:f}}function dc(r,e,t=0,n=0){const{top:i,left:s}=r.getComputedLayout(),{top:o,left:a,width:l,height:A}=e.node.getComputedLayout(),c=t+a,u=n+o,h=e.childNodes.map(d=>dc(r,d,c,u));return{...e,x:s+c,y:i+u,width:l,height:A,childNodes:h}}async function Ko(r,e,t){for await(const{node:n,options:i,dependencies:s,renderer:o,childNodes:a}of e){if(o){const{width:l,height:A}=o;if(l){const c=await l({node:n,options:i,dependencies:s,measureCanvas:t});n.setWidth(c)}if(await Ko(r,a,t),A){const c=await A({node:n,options:i,dependencies:s,measureCanvas:t});n.setHeight(c)}}await Ko(r,a,t)}r.calculateLayout()}async function fc({root:r,resolvers:e,measureCanvas:t}){const n=await Tp(),i=n.Node.create();uc(n,i,{layout:r.layout});const s=await hc({yoga:n,index:0,parent:i,element:r.element,resolvers:e});await Ko(i,[s],t);const{top:o,left:a,width:l,height:A}=i.getComputedLayout(),c={root:{x:a,y:o,width:l,height:A},node:dc(i,s)};return i.freeRecursive(),c}function Cr(r){let e=0;for(const t of r)Array.isArray(t)?e+=Cr(t):e+=t;return e}function Wo(r){return r.map(({type:e,duration:t},n)=>{var i,s,o,a;if(e==="transition"){const l=((i=r[n-2])==null?void 0:i.type)==="transition"?r[n-2]:null,A=((s=r[n-1])==null?void 0:s.duration)??1/0,c=((o=r[n+1])==null?void 0:o.duration)??1/0,u=((a=r[n+2])==null?void 0:a.type)==="transition"?r[n+2]:null;return Math.min(l?A/2:A,t,u?c/2:c)*-1}return t})}function gc(r){var e;return{...r,children:((e=r.children)==null?void 0:e.map(t=>{if(t.type!=="recipe")return gc(t)}).filter(Boolean))??[]}}function pc(r){const e={box:0,image:0,video:0,text:0,audio:0};r.renderer&&(e[r.renderer.type]+=1);for(const t of r.children??[]){const{box:n,image:i,video:s,text:o,audio:a}=pc(t);e.box+=n,e.image+=i,e.video+=s,e.text+=o,e.audio+=a}return e}function wp(r){return r.video>0?vp.type:r.image>0?Ep.type:r.audio>0?mp.type:Cp.type}function mc({node:r,duration:e}){const t=[];if(r.type==="recipe"){const n=gc({...r.element,layout:{...r.element.layout,position:"static",width:"100%",height:"100%",margin:0}}),i=pc(n);t.push({type:wp(i),id:pp(),x:r.x,y:r.y,width:r.width,height:r.height,duration:e,root:{element:n}})}for(const n of r.childNodes)t.push(...mc({node:n,duration:e}));return t}async function Sp({scene:r,start:e=0}){const{root:t,duration:n}=r,i=await fc({root:t});return{type:r.type,start:e,duration:n,layout:i,id:r.id,config:r}}async function Rp({track:r}){const e=Wo(r),t=await Promise.all(r.reduce((s,o,a)=>{if(o.type!=="audio")return s;const l=Cr(e.slice(0,a));return s.push(Sp({scene:o,start:l})),s},[])),n=r.reduce((s,o,a)=>{if(o.type!=="gap")return s;const l=Cr(e.slice(0,a));return s.push({type:o.type,id:o.id,start:l,config:o,duration:o.duration}),s},[]),i=r.map(({id:s})=>t.find(({id:o})=>o===s)??n.find(({id:o})=>o===s)).filter(Boolean);return{type:"audio",scenes:t,gapScenes:n,mergedScenes:i,config:r,duration:Math.max(...i.map(({start:s,duration:o})=>s+o))}}async function Ec(){return document.createElement("canvas")}async function Ic({node:r,canvases:e,sceneTime:t}){var n,i;await((i=(n=r.renderer)==null?void 0:n.render)==null?void 0:i.call(n,{canvases:e,sceneTime:t,dx:r.x,dy:r.y,dw:r.width,dh:r.height,radius:r.radius,options:r.options,dependencies:r.dependencies}));const{sceneCanvas:s}=e,o=s.getContext("2d");o&&(o.strokeStyle="red",o.strokeRect(r.x,r.y,r.width,r.height));for await(const a of r.childNodes)await Ic({node:a,canvases:e,sceneTime:t})}async function Dp({layout:r,canvases:e,sceneTime:t}){const{node:n}=r;await Ic({node:n,canvases:e,sceneTime:t})}async function Jo({scene:r,start:e=0,resolvers:t,rootWidth:n,rootHeight:i,canvasFactory:s=Ec}){var o,a;const{x:l,y:A,width:c,height:u,root:h,duration:d}=r,f=await s(),g=await s(),p=await s(),C=await s(),Q=await s(),b=await s(),y=await fc({root:{...h,layout:{...h.layout,width:n,height:i},element:{...h.element,layout:{...h.element.layout,...typeof l=="number"&&typeof A=="number"?{position:"absolute",inset:{top:A,left:l}}:{},width:c??((o=h.element.layout)==null?void 0:o.width),height:u??((a=h.element.layout)==null?void 0:a.height)}}},resolvers:t,measureCanvas:b}),x=async R=>{const k=Math.max(0,R-e);f.width=f.height=0,f.width=n,f.height=i,await Dp({layout:y,sceneTime:k,canvases:{sceneCanvas:f,cropCanvas:p,letterboxCanvas:C,posterCanvas:Q}})};return{type:r.type,draw:x,start:e,duration:d,layout:y,sceneCanvas:f,transitionCanvas:g,id:r.id,config:r,childScenes:mc({node:y.node,duration:d})}}async function _p({track:r,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i}){const s=Wo(r),o=await Promise.all(r.reduce((c,u,h)=>{const d=Cr(s.slice(0,h));return u.type==="video"&&c.push(Jo({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i})),u.type==="image"&&c.push(Jo({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i})),c},[])),a=r.reduce((c,u,h)=>{if(u.type!=="gap")return c;const d=Cr(s.slice(0,h));return c.push({type:u.type,id:u.id,start:d,config:u,duration:u.duration}),c},[]),l=r.reduce((c,u,h)=>{if(u.type!=="transition")return c;const d=u.duration,f=Cr(s.slice(0,h))-d;return c.push({type:u.type,id:u.id,name:u.name,start:f,duration:d,config:u,to:o.find(({id:g})=>{var p;return g===((p=r[h+1])==null?void 0:p.id)}),from:o.find(({id:g})=>{var p;return g===((p=r[h-1])==null?void 0:p.id)})}),c},[]),A=r.map(({id:c})=>o.find(({id:u})=>u===c)??a.find(({id:u})=>u===c)??l.find(({id:u})=>u===c)).filter(Boolean);return{type:"picture",scenes:o,gapScenes:a,transitions:l,mergedScenes:A,duration:Math.max(0,...A.map(({start:c,duration:u})=>c+u)),trackCanvas:await i()}}async function Lp({track:r,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i}){const s=Wo(r),o=await Promise.all(r.reduce((c,u,h)=>{const d=Cr(s.slice(0,h));return u.type==="text"&&c.push(Jo({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i})),c},[])),a=r.reduce((c,u,h)=>{if(u.type!=="gap")return c;const d=Cr(s.slice(0,h));return c.push({type:u.type,id:u.id,start:d,config:u,duration:u.duration}),c},[]),l=r.reduce((c,u,h)=>{if(u.type!=="transition")return c;const d=u.duration,f=Cr(s.slice(0,h))-d;return c.push({type:u.type,id:u.id,name:u.name,start:f,duration:d,config:u,to:o.find(({id:g})=>{var p;return g===((p=r[h+1])==null?void 0:p.id)}),from:o.find(({id:g})=>{var p;return g===((p=r[h-1])==null?void 0:p.id)})}),c},[]),A=r.map(({id:c})=>o.find(({id:u})=>u===c)??a.find(({id:u})=>u===c)??l.find(({id:u})=>u===c)).filter(Boolean);return{type:"text",scenes:o,gapScenes:a,transitions:l,mergedScenes:A,duration:Math.max(...A.map(({start:c,duration:u})=>c+u)),trackCanvas:await i()}}function Fp(r){return r.some(({type:e})=>e==="video"||e==="image")}function kp(r){return r.some(({type:e})=>e==="audio")}function Mp(r){return r.some(({type:e})=>e==="text")}function Np(r){return r.type==="audio"}const Pp=(((nc=rc)==null?void 0:nc.default)??rc).reduce((r,e)=>(r[e.name]=e,r),{});function Op({name:r,canvas:e,to:t,from:n,progress:i}){var s,o,a;const l=e.getContext("webgl",{alpha:!0});if(l){l.disable(l.DEPTH_TEST),l.pixelStorei(l.UNPACK_FLIP_Y_WEBGL,!0);const A=l.createBuffer();l.bindBuffer(l.ARRAY_BUFFER,A),l.bufferData(l.ARRAY_BUFFER,new Float32Array([-1,-1,-1,4,4,-1]),l.STATIC_DRAW),l.viewport(0,0,e.width,e.height);const c=(((s=ts)==null?void 0:s.default)??ts)(l,n);c.minFilter=l.LINEAR,c.magFilter=l.LINEAR;const u=(((o=ts)==null?void 0:o.default)??ts)(l,t);u.minFilter=l.LINEAR,u.magFilter=l.LINEAR;const h=(((a=tc)==null?void 0:a.default)??tc)(l,Pp[r]);h.draw(i,c,u,e.width,e.height),c.dispose(),u.dispose(),h.dispose(),l.flush()}}async function Cc({config:r,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i=Ec}){const s=await Promise.all(r.tracks.map(async l=>{if(Fp(l))return{...await _p({track:l,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i}),config:l};if(Mp(l))return{...await Lp({track:l,resolvers:e,rootWidth:t,rootHeight:n,canvasFactory:i}),config:l};if(kp(l))return{...await Rp({track:l}),config:l};throw new Error("Unknown track type")}));console.log({tracks:s});const o=await i();return{draw:async({canvas:l,currentTime:A})=>{const c=l.getContext("2d");if(c){c.globalAlpha=1,c.globalCompositeOperation="source-over",c.clearRect(0,0,l.width,l.height),c.save(),c.fillStyle="black",c.fillRect(0,0,l.width,l.height),c.restore();for await(const u of s){if(Np(u))continue;const{scenes:h,transitions:d,trackCanvas:f}=u;f.width=f.height=0,f.width=l.width,f.height=l.height;const g=h.filter(({start:C,duration:Q})=>A>=C&&A<C+Q);if(g.length<=0)continue;const p=d.find(({start:C,duration:Q})=>A>=C&&A<C+Q);for await(const{id:C,start:Q,duration:b,sceneCanvas:y,transitionCanvas:x,draw:R}of g)if(await(R==null?void 0:R(A)),!p)c.drawImage(y,0,0,y.width,y.height);else{const{name:k,to:H,from:V,duration:P}=p;o.width=o.height=x.width=x.height=0,o.width=x.width=y.width,o.height=x.height=y.height;const K=(H==null?void 0:H.id)===C,re=(V==null?void 0:V.id)===C,ee=K&&H.sceneCanvas||o,le=re&&V.sceneCanvas||o,D=K?Math.min(1,Math.max(0,(A-Q)/P)):Math.min(1,Math.max(0,1-(Q+b-A)/P));Op({name:k,progress:D,to:ee,from:le,canvas:x});const O=f.getContext("2d");if(!O)return;O.globalCompositeOperation="lighter",O.drawImage(x,0,0,x.width,x.height)}c.drawImage(f,0,0,f.width,f.height)}}},tracks:s,duration:Math.max(...s.map(({duration:l})=>l))}}const Up={name:"@vouchfor/embeds",version:"0.0.0-experiment.b6e21df",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds.js",module:"dist/es/embeds.js",type:"module",types:"dist/es/src/index.d.ts",exports:{".":"./dist/es/embeds.js"},files:["dist","src"],publishConfig:{tag:"experiment",access:"public"},engines:{node:">=18.18.0"},scripts:{build:"rm -rf dist && tsc && yarn build:self","build:deps":"yarn --cwd ../media-player build","build:self":"vite build --mode iife && vite build --mode es && node scripts/build.cjs","build:package":"yarn build","build:storybook":"yarn prebuild && storybook build","generate:manifest":"wca src --outFile custom-elements.json",lint:"eslint . --quiet","lint:fix":"eslint . --fix","lint:staged":"lint-staged",prepublishOnly:"yarn build",size:"size-limit",storybook:"yarn prebuild && storybook dev -p 6007",prebuild:"yarn build:deps && yarn generate:manifest",test:"rm -rf test/lib && yarn prebuild && vite build --mode test && web-test-runner","test:ci":"yarn test --config web-test-runner.ci.config.js","test:watch":"yarn test --watch"},"lint-staged":{"**/*.{ts,tsx,js}":"eslint --fix --quiet","**/*.{md,json,yml}":"prettier --write"},dependencies:{"@a11y/focus-trap":"^1.0.5","@lit/task":"^1.0.0","@vouchfor/canvas-video":"0.0.0-experiment.b6e21df","@vouchfor/media-player":"0.0.0-experiment.b6e21df",uuid:"^9.0.1"},peerDependencies:{lit:"^3.1.2"},devDependencies:{"@esm-bundle/chai":"^4.3.4-fix.0","@open-wc/testing":"^4.0.0","@storybook/addon-essentials":"^8.0.4","@storybook/addon-links":"^8.0.4","@storybook/blocks":"^8.0.4","@storybook/web-components":"^8.0.4","@storybook/web-components-vite":"^8.0.4","@svgr/core":"^8.1.0","@types/flat":"^5.0.5","@types/mocha":"^10.0.6","@vouchfor/eslint-config":"^1.0.1","@vouchfor/prettier-config":"^1.0.1","@vouchfor/video-utils":"0.0.0-experiment.b6e21df","@web/dev-server-esbuild":"^1.0.2","@web/test-runner":"^0.18.1","@web/test-runner-browserstack":"^0.7.1","@web/test-runner-mocha":"^0.9.0","@web/test-runner-playwright":"^0.11.0",glob:"^10.3.10","lint-staged":"^15.2.2",lit:"^3.1.2",lodash:"^4.17.21",react:"^18.2.0","react-dom":"^18.2.0","rollup-plugin-tla":"^0.0.2",sinon:"^17.0.1",storybook:"^8.0.4",svgson:"^5.3.1",typescript:"^5.4.3",vite:"^5.2.2","vite-plugin-commonjs":"^0.10.1","vite-plugin-dts":"^3.7.3","web-component-analyzer":"^2.0.0"}};function Gp(r){const{publicApiUrl:e}=Pi(r),t=Wr();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function Hp(r){var s,o,a,l,A,c,u,h,d,f,g,p;if(typeof window>"u")return{client:null,tab:null,request:Wr()};let e=(o=(s=window.localStorage)==null?void 0:s.getItem)==null?void 0:o.call(s,"vouch-uid-visitor"),t=(l=(a=window.localStorage)==null?void 0:a.getItem)==null?void 0:l.call(a,"vouch-uid-client"),n=(c=(A=window.sessionStorage)==null?void 0:A.getItem)==null?void 0:c.call(A,"vouch-uid-tab");const i=Wr();return e||(e=Gp(r),(h=(u=window.localStorage)==null?void 0:u.setItem)==null||h.call(u,"vouch-uid-visitor",e)),t||(t=Wr(),(f=(d=window.localStorage)==null?void 0:d.setItem)==null||f.call(d,"vouch-uid-client",t)),n||(n=Wr(),(p=(g=window.sessionStorage)==null?void 0:g.setItem)==null||p.call(g,"vouch-uid-tab",n)),{client:t,tab:n,request:i,visitor:e}}function $p(r,e){return r&&"vouchId"in r?r.vouchId:(e==null?void 0:e.id)??null}function Yp(r="embedded_player"){var i,s;const[e,t]=((s=(i=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:i.split)==null?void 0:s.call(i,"/"))??[],n={};return[...new URLSearchParams(location.search).entries()].forEach(([o,a])=>{if(/utm/.test(o)){const l=o.toLowerCase().replace(/[-_][a-z0-9]/g,A=>A.slice(-1).toUpperCase());n[l]=a}}),{source:r,time:new Date,region:t,country:e,screenHeight:window.screen.height,screenWidth:window.screen.width,referrer:document.referrer,currentUrl:location.href,embedType:"media-player-embed",embedVersion:Up.version,templateVersion:Qp,...n}}const vc=1;class Vp{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,n)=>{const i=$p(n,this.host.vouch);!i||this.host.disableTracking||this._batchedEvents.push({event:t,payload:{...n,vouchId:i,time:new Date().toISOString()}})},this._sendTrackingEvent=()=>{if(this._batchedEvents.length<=0)return;const{publicApiUrl:t}=Pi(this.host.env),{client:n,tab:i,request:s,visitor:o}=Hp(this.host.env);navigator.sendBeacon(`${t}/api/batchevents`,JSON.stringify({payload:{events:this._batchedEvents},context:{"x-uid-client":n,"x-uid-tab":i,"x-uid-request":s,"x-uid-visitor":o,"x-reporting-metadata":Yp(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:n}=this._currentlyPlayingVideo;this._streamLatestTime[n]>this._streamStartTime[n]+vc&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[n],streamEnd:this._streamLatestTime[n]}),delete this._streamStartTime[n],delete this._streamLatestTime[n]}},this._handleVouchLoaded=({detail:t})=>{t&&(this._hasLoaded[t]||(this._createTrackingEvent("VOUCH_LOADED",{vouchId:t}),this._hasLoaded[t]=!0))},this._handlePlay=()=>{this._hasPlayed||(this._createTrackingEvent("VIDEO_PLAYED",{streamStart:this.host.currentTime}),this._hasPlayed=!0)},this._handleVideoPlay=({detail:{id:t,key:n}})=>{this._answersViewed[n]||(this._createTrackingEvent("VOUCH_RESPONSE_VIEWED",{answerId:t}),this._answersViewed[n]=!0)},this._handleVideoTimeUpdate=({detail:{id:t,key:n,node:i}})=>{this.host.paused||(this._currentlyPlayingVideo={id:t,key:n,node:i},this._streamLatestTime[n]=i.currentTime,this._streamStartTime[n]||(this._streamStartTime[n]=i.currentTime,this._streamLatestTime[n]=i.currentTime))},this._handleVideoPause=({detail:{id:t,key:n}})=>{this._streamLatestTime[n]>this._streamStartTime[n]+vc&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[n],streamEnd:this._streamLatestTime[n]}),delete this._streamStartTime[n],delete this._streamLatestTime[n]},this._pageUnloading=()=>{this._streamEnded(),this._sendTrackingEvent()},this._handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this._pageUnloading()},this._handlePageHide=()=>{this._pageUnloading()},this.host=e,e.addController(this)}hostConnected(){requestAnimationFrame(()=>{var e,t,n,i;"onvisibilitychange"in document?document.addEventListener("visibilitychange",this._handleVisibilityChange):window.addEventListener("pagehide",this._handlePageHide),this.host.addEventListener("vouch:loaded",this._handleVouchLoaded),(e=this.host.mediaPlayer)==null||e.addEventListener("play",this._handlePlay),(t=this.host.mediaPlayer)==null||t.addEventListener("video:play",this._handleVideoPlay),(n=this.host.mediaPlayer)==null||n.addEventListener("video:pause",this._handleVideoPause),(i=this.host.mediaPlayer)==null||i.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var e,t,n,i;this._pageUnloading(),"onvisibilitychange"in document?document.removeEventListener("visibilitychange",this._handleVisibilityChange):window.removeEventListener("pagehide",this._handlePageHide),this.host.removeEventListener("vouch:loaded",this._handleVouchLoaded),(e=this.host.mediaPlayer)==null||e.removeEventListener("play",this._handlePlay),(t=this.host.mediaPlayer)==null||t.removeEventListener("video:play",this._handleVideoPlay),(n=this.host.mediaPlayer)==null||n.removeEventListener("video:pause",this._handleVideoPause),(i=this.host.mediaPlayer)==null||i.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}var qo={exports:{}};(function(r,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof En<"u"&&En,n=function(){function s(){this.fetch=!1,this.DOMException=t.DOMException}return s.prototype=t,new s}();(function(s){(function(o){var a=typeof s<"u"&&s||typeof self<"u"&&self||typeof a<"u"&&a,l={searchParams:"URLSearchParams"in a,iterable:"Symbol"in a&&"iterator"in Symbol,blob:"FileReader"in a&&"Blob"in a&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in a,arrayBuffer:"ArrayBuffer"in a};function A(D){return D&&DataView.prototype.isPrototypeOf(D)}if(l.arrayBuffer)var c=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(D){return D&&c.indexOf(Object.prototype.toString.call(D))>-1};function h(D){if(typeof D!="string"&&(D=String(D)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(D)||D==="")throw new TypeError('Invalid character in header field name: "'+D+'"');return D.toLowerCase()}function d(D){return typeof D!="string"&&(D=String(D)),D}function f(D){var O={next:function(){var X=D.shift();return{done:X===void 0,value:X}}};return l.iterable&&(O[Symbol.iterator]=function(){return O}),O}function g(D){this.map={},D instanceof g?D.forEach(function(O,X){this.append(X,O)},this):Array.isArray(D)?D.forEach(function(O){this.append(O[0],O[1])},this):D&&Object.getOwnPropertyNames(D).forEach(function(O){this.append(O,D[O])},this)}g.prototype.append=function(D,O){D=h(D),O=d(O);var X=this.map[D];this.map[D]=X?X+", "+O:O},g.prototype.delete=function(D){delete this.map[h(D)]},g.prototype.get=function(D){return D=h(D),this.has(D)?this.map[D]:null},g.prototype.has=function(D){return this.map.hasOwnProperty(h(D))},g.prototype.set=function(D,O){this.map[h(D)]=d(O)},g.prototype.forEach=function(D,O){for(var X in this.map)this.map.hasOwnProperty(X)&&D.call(O,this.map[X],X,this)},g.prototype.keys=function(){var D=[];return this.forEach(function(O,X){D.push(X)}),f(D)},g.prototype.values=function(){var D=[];return this.forEach(function(O){D.push(O)}),f(D)},g.prototype.entries=function(){var D=[];return this.forEach(function(O,X){D.push([X,O])}),f(D)},l.iterable&&(g.prototype[Symbol.iterator]=g.prototype.entries);function p(D){if(D.bodyUsed)return Promise.reject(new TypeError("Already read"));D.bodyUsed=!0}function C(D){return new Promise(function(O,X){D.onload=function(){O(D.result)},D.onerror=function(){X(D.error)}})}function Q(D){var O=new FileReader,X=C(O);return O.readAsArrayBuffer(D),X}function b(D){var O=new FileReader,X=C(O);return O.readAsText(D),X}function y(D){for(var O=new Uint8Array(D),X=new Array(O.length),_=0;_<O.length;_++)X[_]=String.fromCharCode(O[_]);return X.join("")}function x(D){if(D.slice)return D.slice(0);var O=new Uint8Array(D.byteLength);return O.set(new Uint8Array(D)),O.buffer}function R(){return this.bodyUsed=!1,this._initBody=function(D){this.bodyUsed=this.bodyUsed,this._bodyInit=D,D?typeof D=="string"?this._bodyText=D:l.blob&&Blob.prototype.isPrototypeOf(D)?this._bodyBlob=D:l.formData&&FormData.prototype.isPrototypeOf(D)?this._bodyFormData=D:l.searchParams&&URLSearchParams.prototype.isPrototypeOf(D)?this._bodyText=D.toString():l.arrayBuffer&&l.blob&&A(D)?(this._bodyArrayBuffer=x(D.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):l.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(D)||u(D))?this._bodyArrayBuffer=x(D):this._bodyText=D=Object.prototype.toString.call(D):this._bodyText="",this.headers.get("content-type")||(typeof D=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):l.searchParams&&URLSearchParams.prototype.isPrototypeOf(D)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},l.blob&&(this.blob=function(){var D=p(this);if(D)return D;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){if(this._bodyArrayBuffer){var D=p(this);return D||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else return this.blob().then(Q)}),this.text=function(){var D=p(this);if(D)return D;if(this._bodyBlob)return b(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(y(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},l.formData&&(this.formData=function(){return this.text().then(P)}),this.json=function(){return this.text().then(JSON.parse)},this}var k=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function H(D){var O=D.toUpperCase();return k.indexOf(O)>-1?O:D}function V(D,O){if(!(this instanceof V))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');O=O||{};var X=O.body;if(D instanceof V){if(D.bodyUsed)throw new TypeError("Already read");this.url=D.url,this.credentials=D.credentials,O.headers||(this.headers=new g(D.headers)),this.method=D.method,this.mode=D.mode,this.signal=D.signal,!X&&D._bodyInit!=null&&(X=D._bodyInit,D.bodyUsed=!0)}else this.url=String(D);if(this.credentials=O.credentials||this.credentials||"same-origin",(O.headers||!this.headers)&&(this.headers=new g(O.headers)),this.method=H(O.method||this.method||"GET"),this.mode=O.mode||this.mode||null,this.signal=O.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&X)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(X),(this.method==="GET"||this.method==="HEAD")&&(O.cache==="no-store"||O.cache==="no-cache")){var _=/([?&])_=[^&]*/;if(_.test(this.url))this.url=this.url.replace(_,"$1_="+new Date().getTime());else{var S=/\?/;this.url+=(S.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}V.prototype.clone=function(){return new V(this,{body:this._bodyInit})};function P(D){var O=new FormData;return D.trim().split("&").forEach(function(X){if(X){var _=X.split("="),S=_.shift().replace(/\+/g," "),F=_.join("=").replace(/\+/g," ");O.append(decodeURIComponent(S),decodeURIComponent(F))}}),O}function K(D){var O=new g,X=D.replace(/\r?\n[\t ]+/g," ");return X.split("\r").map(function(_){return _.indexOf(`
2455
2455
  `)===0?_.substr(1,_.length):_}).forEach(function(_){var S=_.split(":"),F=S.shift().trim();if(F){var J=S.join(":").trim();O.append(F,J)}}),O}R.call(V.prototype);function re(D,O){if(!(this instanceof re))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');O||(O={}),this.type="default",this.status=O.status===void 0?200:O.status,this.ok=this.status>=200&&this.status<300,this.statusText=O.statusText===void 0?"":""+O.statusText,this.headers=new g(O.headers),this.url=O.url||"",this._initBody(D)}R.call(re.prototype),re.prototype.clone=function(){return new re(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new g(this.headers),url:this.url})},re.error=function(){var D=new re(null,{status:0,statusText:""});return D.type="error",D};var ee=[301,302,303,307,308];re.redirect=function(D,O){if(ee.indexOf(O)===-1)throw new RangeError("Invalid status code");return new re(null,{status:O,headers:{location:D}})},o.DOMException=a.DOMException;try{new o.DOMException}catch{o.DOMException=function(O,X){this.message=O,this.name=X;var _=Error(O);this.stack=_.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function le(D,O){return new Promise(function(X,_){var S=new V(D,O);if(S.signal&&S.signal.aborted)return _(new o.DOMException("Aborted","AbortError"));var F=new XMLHttpRequest;function J(){F.abort()}F.onload=function(){var ne={status:F.status,statusText:F.statusText,headers:K(F.getAllResponseHeaders()||"")};ne.url="responseURL"in F?F.responseURL:ne.headers.get("X-Request-URL");var ce="response"in F?F.response:F.responseText;setTimeout(function(){X(new re(ce,ne))},0)},F.onerror=function(){setTimeout(function(){_(new TypeError("Network request failed"))},0)},F.ontimeout=function(){setTimeout(function(){_(new TypeError("Network request failed"))},0)},F.onabort=function(){setTimeout(function(){_(new o.DOMException("Aborted","AbortError"))},0)};function Y(ne){try{return ne===""&&a.location.href?a.location.href:ne}catch{return ne}}F.open(S.method,Y(S.url),!0),S.credentials==="include"?F.withCredentials=!0:S.credentials==="omit"&&(F.withCredentials=!1),"responseType"in F&&(l.blob?F.responseType="blob":l.arrayBuffer&&S.headers.get("Content-Type")&&S.headers.get("Content-Type").indexOf("application/octet-stream")!==-1&&(F.responseType="arraybuffer")),O&&typeof O.headers=="object"&&!(O.headers instanceof g)?Object.getOwnPropertyNames(O.headers).forEach(function(ne){F.setRequestHeader(ne,d(O.headers[ne]))}):S.headers.forEach(function(ne,ce){F.setRequestHeader(ce,ne)}),S.signal&&(S.signal.addEventListener("abort",J),F.onreadystatechange=function(){F.readyState===4&&S.signal.removeEventListener("abort",J)}),F.send(typeof S._bodyInit>"u"?null:S._bodyInit)})}return le.polyfill=!0,a.fetch||(a.fetch=le,a.Headers=g,a.Request=V,a.Response=re),o.Headers=g,o.Request=V,o.Response=re,o.fetch=le,o})({})})(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var i=t.fetch?t:n;e=i.fetch,e.default=i.fetch,e.fetch=i.fetch,e.Headers=i.Headers,e.Request=i.Request,e.Response=i.Response,r.exports=e})(qo,qo.exports);var Kp=qo.exports;const yc=ho(Kp);async function Wp(r){var e;try{if((e=await yc(r,{method:"HEAD"}))!=null&&e.ok)return r}catch{return}}async function Xo({sources:r}){let e=null;const t=r==null?void 0:r.filter(Boolean),n=t==null?void 0:t.find(s=>s.startsWith("blob:")),i=t==null?void 0:t.find(s=>!s.startsWith("http")&&!s.startsWith("blob:"));if(n||i)return n??i;if(t.length>0){const s=t.map(o=>Wp(o));e=(await Promise.all(s)).find(Boolean)}return e}async function Jp(r){try{return(await yc(r)).text()}catch{return null}}async function qp(r){return r=r.trim(),r.startsWith("http")||r.startsWith("blob:")?Jp(r):r}const Xp=Xr(async({original:r,translation:e,originalLanguage:t="",translationLanguage:n=""},{language:i})=>{var s,o;const a={[(s=n==null?void 0:n.split("-"))==null?void 0:s[0]]:e,[(o=t==null?void 0:t.split("-"))==null?void 0:o[0]]:r},l=(i&&a[i])??r;return l?qp(l):null},{cacheKey:([r,{language:e}])=>JSON.stringify({...r,language:e})});function jp(r){var e;return((e=r==null?void 0:r.items)==null?void 0:e.map(t=>{var n;return{text:(n=t.alternatives[0])==null?void 0:n.content,start:t.start_time,end:t.end_time}}))??[]}const zp=Xr(async r=>{var e,t,n,i,s,o,a,l,A,c,u;const[h,d,f]=await Promise.all([Xo({sources:[(t=(e=r==null?void 0:r.answer)==null?void 0:e.media)==null?void 0:t.video,(i=(n=r==null?void 0:r.answer)==null?void 0:n.media)==null?void 0:i.input]}),Xo({sources:[(o=(s=r==null?void 0:r.answer)==null?void 0:s.media)==null?void 0:o.playlist]}),Xo({sources:[((l=(a=r==null?void 0:r.answer)==null?void 0:a.media)==null?void 0:l.reducedQuality)??((u=(c=(A=r==null?void 0:r.answer)==null?void 0:A.media)==null?void 0:c.videos)==null?void 0:u.xs)]})]);return{src:h,playlist:d,preview:f}},{cacheKey:([r])=>{var e,t,n,i,s,o,a,l,A,c,u;return JSON.stringify({video:(t=(e=r==null?void 0:r.answer)==null?void 0:e.media)==null?void 0:t.video,input:(i=(n=r==null?void 0:r.answer)==null?void 0:n.media)==null?void 0:i.input,playlist:(o=(s=r==null?void 0:r.answer)==null?void 0:s.media)==null?void 0:o.playlist,preview:((l=(a=r==null?void 0:r.answer)==null?void 0:a.media)==null?void 0:l.reducedQuality)??((u=(c=(A=r==null?void 0:r.answer)==null?void 0:A.media)==null?void 0:c.videos)==null?void 0:u.xs)})}});function Bc(r){var e,t,n,i,s,o,a,l,A,c,u,h;const d=((t=(e=r==null?void 0:r.answer)==null?void 0:e.contact)==null?void 0:t.name)==="Anonymous"?"":((s=(i=(n=r==null?void 0:r.answer)==null?void 0:n.contact)==null?void 0:i.name)==null?void 0:s.trim())??"",f=((l=(a=(o=r==null?void 0:r.answer)==null?void 0:o.contact)==null?void 0:a.client)==null?void 0:l.name)==="Not Supplied"?"":((h=(u=(c=(A=r==null?void 0:r.answer)==null?void 0:A.contact)==null?void 0:c.client)==null?void 0:u.name)==null?void 0:h.trim())??"",[g,p]=d.split(" ");return{name:d,firstName:g,lastName:p,companyName:f}}const Zp=Xr(async(r,e,t)=>{var n,i,s;const o=(n=e==null?void 0:e.answer)==null?void 0:n.id;return((s=(i=r==null?void 0:r.questions)==null?void 0:i.items)==null?void 0:s.reduce((l,A)=>{var c;return((c=A==null?void 0:A.answer)==null?void 0:c.id)===o?(l??0)+1:l},0))<=1?o:`${o}-${t}`},{cacheKey:([r,e,t])=>{var n;return JSON.stringify({index:t,rootData:e,allQuestions:(n=r==null?void 0:r.questions)==null?void 0:n.items})}});async function jo({data:r,rootData:e,index:t},n){var i,s,o,a,l,A,c,u,h,d,f,g,p,C,Q,b,y,x,R,k,H,V,P,K;const[re,ee,le]=await Promise.all([Zp(r,e,t),zp(e),Xp({original:((s=(i=e==null?void 0:e.answer)==null?void 0:i.media)==null?void 0:s.captions)??((a=(o=e==null?void 0:e.answer)==null?void 0:o.captions)==null?void 0:a.current),translation:((A=(l=e==null?void 0:e.answer)==null?void 0:l.media)==null?void 0:A.translation)??((u=(c=e==null?void 0:e.answer)==null?void 0:c.captions)==null?void 0:u.translation),originalLanguage:(d=(h=e==null?void 0:e.answer)==null?void 0:h.transcription)==null?void 0:d.language,translationLanguage:(p=(g=(f=e==null?void 0:e.answer)==null?void 0:f.transcription)==null?void 0:g.translation)==null?void 0:p.language},n)]),D=Bc(e);return{...ee,...D,key:re,captions:le,wordTimings:jp((C=e==null?void 0:e.answer)==null?void 0:C.transcription),answerLabel:((Q=e==null?void 0:e.answer)==null?void 0:Q.label)??(e==null?void 0:e.title),prevAnswerLabel:t?((R=(x=(y=(b=r==null?void 0:r.questions)==null?void 0:b.items)==null?void 0:y[t-1])==null?void 0:x.answer)==null?void 0:R.label)??((V=(H=(k=r==null?void 0:r.questions)==null?void 0:k.items)==null?void 0:H[t-1])==null?void 0:V.title)??null:null,isFirstInstanceOfName:t?((K=(P=r==null?void 0:r.questions)==null?void 0:P.items)==null?void 0:K.findIndex(O=>Bc(O).name===D.name))===t:!0}}const as={af:"Afrikaans",sq:"Albanian",am:"Amharic",ar:"Arabic",hy:"Armenian",az:"Azerbaijani",eu:"Basque",be:"Belarusian",bn:"Bengali",bs:"Bosnian",bg:"Bulgarian",ca:"Catalan",zh:"Chinese (Simplified)",zh_TW:"Chinese (Traditional)",hr:"Croatian",cs:"Czech",da:"Danish",nl:"Dutch",en:"English",et:"Estonian",fi:"Finnish",fr:"French",fa:"Farsi",tl:"Filipino",ka:"Georgian",de:"German",el:"Greek",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hi:"Hindi",hu:"Hungarian",is:"Icelandic",id:"Indonesian",ga:"Irish",it:"Italian",ja:"Japanese",kn:"Kannada",kk:"Kazakh",ko:"Korean",lv:"Latvian",lt:"Lithuanian",mk:"Macedonian",ms:"Malay",ml:"Malayalam",mt:"Maltese",mr:"Marathi",mn:"Mongolian",no:"Norwegian",ps:"Pashto",pl:"Polish",pt:"Portuguese",pa:"Punjabi",ro:"Romanian",ru:"Russian",sr:"Serbian",si:"Sinhala",sk:"Slovak",sl:"Slovenian",so:"Somali",es:"Spanish",sw:"Swahili",sv:"Swedish",ta:"Tamil",te:"Telugu",th:"Thai",tr:"Turkish",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",vi:"Vietnamese",cy:"Welsh"};function em({data:r}){var e,t;return((t=(e=r==null?void 0:r.questions)==null?void 0:e.items)==null?void 0:t.reduce((n,i)=>{var s,o,a,l,A,c,u;const h=(a=(o=(s=i==null?void 0:i.answer)==null?void 0:s.transcription)==null?void 0:o.language)==null?void 0:a.split("-")[0],d=(u=(c=(A=(l=i==null?void 0:i.answer)==null?void 0:l.transcription)==null?void 0:A.translation)==null?void 0:c.language)==null?void 0:u.split("-")[0];return h&&as[h]&&!n.find(f=>f.value===h)&&n.push({value:h,label:as[h]}),d&&as[d]&&!n.find(f=>f.value===d)&&n.push({value:d,label:as[d]}),n},[]))??[]}/**
2456
2456
  * @license
2457
2457
  * Copyright 2018 Google LLC
@@ -3741,7 +3741,7 @@ vec4 transition(vec2 uv) {
3741
3741
  vmp-captions.hiddenControls {
3742
3742
  transform: translateY(calc(var(--space-small) * -1));
3743
3743
  }
3744
- `],ft([oe({type:Boolean})],at.prototype,"loading",2),ft([oe({type:Boolean})],at.prototype,"playing",2),ft([oe({type:Number})],at.prototype,"volume",2),ft([oe({type:Boolean})],at.prototype,"muted",2),ft([oe({type:Number})],at.prototype,"currentTime",2),ft([oe({type:Number})],at.prototype,"duration",2),ft([oe({type:Array})],at.prototype,"languages",2),ft([oe({type:String})],at.prototype,"language",2),ft([oe({type:Array,attribute:!1})],at.prototype,"levels",2),ft([oe({type:Number})],at.prototype,"level",2),ft([oe({type:Number})],at.prototype,"playbackRate",2),ft([oe({type:String})],at.prototype,"caption",2),ft([oe({type:Array})],at.prototype,"buffer",2),ft([oe({type:Boolean})],at.prototype,"captions",2),ft([oe({type:Boolean})],at.prototype,"fullscreen",2),ft([oe({type:Array})],at.prototype,"controls",2),ft([it()],at.prototype,"showControls",2),at=ft([wt("vmp-player-overlay")],at);var r1=Object.defineProperty,n1=Object.getOwnPropertyDescriptor,et=(r,e,t,n)=>{for(var i=n>1?void 0:n?n1(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&r1(e,t,i),i};const i1=1e3/60,s1=30;let Je=class extends $e{constructor(){super(...arguments),this.debug=!1,this.propAspectRatio=0,this.preload="auto",this.autoplay=!1,this.loading=!1,this.disabled=!1,this.dataResolver=jo,this.languageResolver=em,this._sceneController=new dB(this),this._drawController=new oB(this),this._observer=null,this._wasPlaying=!1,this._manualMute=this.muted,this._seekerRAF=null,this._seekerTimeout=null,this._lastWaiting=!1,this._lastTimestamp=null,this._lastCurrentTime=null,this._playerRef=vt(),this._canvasRef=vt(),this._pageHidden=document.visibilityState==="hidden",this._aspectRatio=this.propAspectRatio,this._processing=!1,this._waiting=!1,this._errors=[],this._seeking=!1,this._language=this.propLanguage,this._languages=[],this._captions=!1,this._fullscreen=!1,this._initialised=null,this._paused=!0,this._playbackRate=1,this._volume=null,this._muted=null,this._videoResolution=-1,this._handleContainerResize=()=>{var r;(r=this.shadowRoot)!=null&&r.host&&!this.propAspectRatio&&(this._aspectRatio=this.shadowRoot.host.clientWidth/this.shadowRoot.host.clientHeight)},this._handleCanvasResize=()=>{this.draw()},this._loop=()=>{this._endLoop(),this._pageHidden?this._seekerTimeout=setTimeout(this._seeker,i1):this._seekerRAF=requestAnimationFrame(this._seeker)},this._endLoop=()=>{this._seekerRAF&&cancelAnimationFrame(this._seekerRAF),this._seekerTimeout&&clearTimeout(this._seekerTimeout),this._seekerRAF=null,this._seekerTimeout=null},this._seeker=(r=performance.now())=>{var e,t;if(this.composition){if(this._waiting=this._drawController.activeScenes.some(n=>xr(n.layout.node).some(({key:s})=>{if(this.media[s]&&this.mediaState[s]){const o=this.media[s],a=this.mediaState[s];return!a||!a.initialised||a.waiting||o.node.readyState<3}})),this.waiting?(this._lastTimestamp=null,this._lastWaiting||this.dispatchEvent(new CustomEvent("waiting"))):this._lastWaiting&&this.dispatchEvent(new CustomEvent("playing")),r-(this._lastTimestamp??0)>1e3/s1){let n=this._drawController.currentTime;const i=(r-(this._lastTimestamp??r))/1e3*this.playbackRate,s=xr((e=this.activeScenes[0])==null?void 0:e.layout.node);s.length>0?((t=this._lastCurrentTime)!=null&&t.every((o,a)=>{const l=s[a].key,A=this.media[l];return o!==A.node.currentTime})&&(n+=i),this._lastCurrentTime=s.map(({key:o})=>this.media[o].node.currentTime)):n+=i,this._drawController.currentTime=n,this._lastTimestamp=r}this._lastWaiting=this._waiting,this._drawController.currentTime>=this.duration&&(this.pause(),this.dispatchEvent(new CustomEvent("ended")))}this.paused||this._loop()},this._handleError=r=>{this._errors=[...this.errors,r.error],r.error.fatal&&this.pause()},this._handleFullscreenChange=()=>{this===document.fullscreenElement?this._fullscreen=!0:this._fullscreen=!1},this._handleVisibilityChange=()=>{this._pageHidden=document.visibilityState==="hidden",this.paused||this._loop()}}get aspectRatio(){return this._aspectRatio}get processing(){return this._processing}get waiting(){return!this.paused&&this._waiting}get errors(){return this._errors}get seeking(){return this._seeking}get language(){return this._language}get languages(){return this._languages}get captions(){return this._captions}get fullscreen(){return this._fullscreen}get initialised(){return this._initialised=this._initialised??new Promise(r=>{const e=setInterval(()=>{!!this.errors.find(n=>n.fatal)&&r(!1),!this.loading&&!this.processing&&this.composition&&this.duration>0&&r(!0)},500);setTimeout(()=>{clearInterval(e),r(!1)},60*1e3)}),this._initialised}get duration(){return this._sceneController.duration}get media(){return this._sceneController.media??{}}get mediaState(){return this._sceneController.mediaState}get composition(){return this._sceneController.composition}get activeScenes(){return this._drawController.activeScenes}set paused(r){r!==this._paused&&(this._paused=r,this.requestUpdate(),this.dispatchEvent(new CustomEvent(r?"pause":"play")))}get paused(){return this._paused}set playbackRate(r){r!==this._playbackRate&&(this._playbackRate=r,Object.values(this.media).forEach(({node:e,speed:t})=>{e.playbackRate=Nr(.1,r*t,4)}),this.requestUpdate(),this.dispatchEvent(new CustomEvent("ratechange",{detail:r})))}get playbackRate(){return this._playbackRate}set volume(r){const e=Nr(0,r,1);e!==this._volume&&(Object.values(this.media).forEach(({node:t,volume:n})=>{t.volume=e*n}),localStorage.setItem("vmp-player-volume",e.toString()),this._volume=e,e>0&&(this.muted=!1),this.requestUpdate(),this.dispatchEvent(new CustomEvent("volumechange",{detail:r})))}get volume(){return this._volume??(this._volume=parseFloat(localStorage.getItem("vmp-player-volume")??"1"))}set muted(r){Object.values(this.media).forEach(({node:e,volume:t})=>{e.muted=t===0||r}),r!==this._muted&&(this._muted=r,localStorage.setItem("vmp-player-muted",r.toString()),this.requestUpdate(),this.dispatchEvent(new CustomEvent("volumechange",{detail:r?0:this.volume})))}get muted(){return this._muted??(this._muted=this.autoplay||localStorage.getItem("vmp-player-muted")==="true")}set videoResolution(r){r!==this._videoResolution&&(this._videoResolution=r,Object.values(this.media).forEach(({hls:e})=>{if(e){const t=e.levels.findIndex(n=>Math.min(n.height,n.width)===r);e.currentLevel=t??-1}}),this.requestUpdate())}get videoResolution(){return this._videoResolution}set currentTime(r){r!==this._drawController.currentTime&&(this._drawController.currentTime=r,this._sceneController.setMediaCurrentTime(r))}get currentTime(){return this._drawController.currentTime}reset(r=0,e=!1){this._lastTimestamp=null,this._lastCurrentTime=null,this._drawController.currentTime=r,this._sceneController.setMediaCurrentTime(r),e?this.play():this.pause()}clear(){this._drawController.clear()}play(){this.paused=!1,this._lastTimestamp=null,this._lastCurrentTime=null,this.duration>0&&this._drawController.currentTime>=this.duration&&this.reset(0,!0),this._loop()}pause(){this._endLoop(),this.paused=!0,Object.values(this.media).forEach(({node:r})=>{r.pause()})}draw(r){return this._drawController.draw(r)}toggleFullscreen(r){r??this.fullscreen?gB():this._playerRef.value&&fB(this._playerRef.value)}connectedCallback(){var r;super.connectedCallback(),this.addEventListener("error",this._handleError),document.addEventListener("fullscreenchange",this._handleFullscreenChange),document.addEventListener("visibilitychange",this._handleVisibilityChange),(r=this.shadowRoot)!=null&&r.host&&(this._observer=new ResizeObserver(this._handleContainerResize),this._observer.observe(this.shadowRoot.host))}willUpdate(r){r.has("propAspectRatio")&&(this._aspectRatio=this.propAspectRatio),r.has("propLanguage")&&(this._language=this.propLanguage)}updated(r){r.has("propAspectRatio")&&!this.propAspectRatio&&this._handleContainerResize(),this.autoplay&&!this._sceneController.hasPlayed&&!this.processing&&r.get("_processing")&&this.play(),r.has("_processing")&&this.processing&&this.dispatchEvent(new CustomEvent("processing"))}disconnectedCallback(){var r;super.disconnectedCallback(),(r=this._observer)==null||r.disconnect(),document.removeEventListener("fullscreenchange",this._handleFullscreenChange),document.removeEventListener("visibilitychange",this._handleVisibilityChange)}_renderStyles(){return this.propAspectRatio?typeof this.propAspectRatio=="number"?Te`
3744
+ `],ft([oe({type:Boolean})],at.prototype,"loading",2),ft([oe({type:Boolean})],at.prototype,"playing",2),ft([oe({type:Number})],at.prototype,"volume",2),ft([oe({type:Boolean})],at.prototype,"muted",2),ft([oe({type:Number})],at.prototype,"currentTime",2),ft([oe({type:Number})],at.prototype,"duration",2),ft([oe({type:Array})],at.prototype,"languages",2),ft([oe({type:String})],at.prototype,"language",2),ft([oe({type:Array,attribute:!1})],at.prototype,"levels",2),ft([oe({type:Number})],at.prototype,"level",2),ft([oe({type:Number})],at.prototype,"playbackRate",2),ft([oe({type:String})],at.prototype,"caption",2),ft([oe({type:Array})],at.prototype,"buffer",2),ft([oe({type:Boolean})],at.prototype,"captions",2),ft([oe({type:Boolean})],at.prototype,"fullscreen",2),ft([oe({type:Array})],at.prototype,"controls",2),ft([it()],at.prototype,"showControls",2),at=ft([wt("vmp-player-overlay")],at);var r1=Object.defineProperty,n1=Object.getOwnPropertyDescriptor,et=(r,e,t,n)=>{for(var i=n>1?void 0:n?n1(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&r1(e,t,i),i};const i1=1e3/60,s1=30;let Je=class extends $e{constructor(){super(...arguments),this.debug=!1,this.propAspectRatio=0,this.preload="auto",this.autoplay=!1,this.loading=!1,this.disabled=!1,this.dataResolver=jo,this.languageResolver=em,this._sceneController=new dB(this),this._drawController=new oB(this),this._observer=null,this._wasPlaying=!1,this._manualMute=this.muted,this._seekerRAF=null,this._seekerTimeout=null,this._lastWaiting=!1,this._lastTimestamp=null,this._lastCurrentTime=null,this._playerRef=vt(),this._canvasRef=vt(),this._pageHidden=document.visibilityState==="hidden",this._aspectRatio=this.propAspectRatio,this._processing=!1,this._waiting=!1,this._errors=[],this._seeking=!1,this._language=this.propLanguage,this._languages=[],this._captions=!1,this._fullscreen=!1,this._initialised=null,this._paused=!0,this._playbackRate=1,this._volume=null,this._muted=null,this._videoResolution=-1,this._handleContainerResize=()=>{var r;(r=this.shadowRoot)!=null&&r.host&&!this.propAspectRatio&&(this._aspectRatio=this.shadowRoot.host.clientWidth/this.shadowRoot.host.clientHeight)},this._handleCanvasResize=()=>{this.draw()},this._loop=()=>{this._endLoop(),this._pageHidden?this._seekerTimeout=setTimeout(this._seeker,i1):this._seekerRAF=requestAnimationFrame(this._seeker)},this._endLoop=()=>{this._seekerRAF&&cancelAnimationFrame(this._seekerRAF),this._seekerTimeout&&clearTimeout(this._seekerTimeout),this._seekerRAF=null,this._seekerTimeout=null},this._seeker=(r=performance.now())=>{if(this.composition){if(this._waiting=this._drawController.activeScenes.some(e=>xr(e.layout.node).some(({key:n})=>{if(this.media[n]&&this.mediaState[n]){const i=this.media[n],s=this.mediaState[n];return!s||!s.initialised||s.waiting||i.node.readyState<3}})),this.waiting?(this._lastTimestamp=null,this._lastWaiting||this.dispatchEvent(new CustomEvent("waiting"))):this._lastWaiting&&this.dispatchEvent(new CustomEvent("playing")),r-(this._lastTimestamp??0)>1e3/s1){let e=this._drawController.currentTime;const t=(r-(this._lastTimestamp??r))/1e3*this.playbackRate;if(this.activeScenes[0]){const n=xr(this.activeScenes[0].layout.node);(n==null?void 0:n.every(({key:s},o)=>{var a;const l=this.media[s];return((a=this._lastCurrentTime)==null?void 0:a[o])!==l.node.currentTime}))&&(e+=t),this._lastCurrentTime=n.map(({key:s})=>this.media[s].node.currentTime)}else e+=t;this._drawController.currentTime=e,this._lastTimestamp=r}this._lastWaiting=this._waiting,this._drawController.currentTime>=this.duration&&(this.pause(),this.dispatchEvent(new CustomEvent("ended")))}this.paused||this._loop()},this._handleError=r=>{this._errors=[...this.errors,r.error],r.error.fatal&&this.pause()},this._handleFullscreenChange=()=>{this===document.fullscreenElement?this._fullscreen=!0:this._fullscreen=!1},this._handleVisibilityChange=()=>{this._pageHidden=document.visibilityState==="hidden",this.paused||this._loop()}}get aspectRatio(){return this._aspectRatio}get processing(){return this._processing}get waiting(){return!this.paused&&this._waiting}get errors(){return this._errors}get seeking(){return this._seeking}get language(){return this._language}get languages(){return this._languages}get captions(){return this._captions}get fullscreen(){return this._fullscreen}get initialised(){return this._initialised=this._initialised??new Promise(r=>{const e=setInterval(()=>{!!this.errors.find(n=>n.fatal)&&r(!1),!this.loading&&!this.processing&&this.composition&&this.duration>0&&r(!0)},500);setTimeout(()=>{clearInterval(e),r(!1)},60*1e3)}),this._initialised}get duration(){return this._sceneController.duration}get media(){return this._sceneController.media??{}}get mediaState(){return this._sceneController.mediaState}get composition(){return this._sceneController.composition}get activeScenes(){return this._drawController.activeScenes}set paused(r){r!==this._paused&&(this._paused=r,this.requestUpdate(),this.dispatchEvent(new CustomEvent(r?"pause":"play")))}get paused(){return this._paused}set playbackRate(r){r!==this._playbackRate&&(this._playbackRate=r,Object.values(this.media).forEach(({node:e,speed:t})=>{e.playbackRate=Nr(.1,r*t,4)}),this.requestUpdate(),this.dispatchEvent(new CustomEvent("ratechange",{detail:r})))}get playbackRate(){return this._playbackRate}set volume(r){const e=Nr(0,r,1);e!==this._volume&&(Object.values(this.media).forEach(({node:t,volume:n})=>{t.volume=e*n}),localStorage.setItem("vmp-player-volume",e.toString()),this._volume=e,e>0&&(this.muted=!1),this.requestUpdate(),this.dispatchEvent(new CustomEvent("volumechange",{detail:r})))}get volume(){return this._volume??(this._volume=parseFloat(localStorage.getItem("vmp-player-volume")??"1"))}set muted(r){Object.values(this.media).forEach(({node:e,volume:t})=>{e.muted=t===0||r}),r!==this._muted&&(this._muted=r,localStorage.setItem("vmp-player-muted",r.toString()),this.requestUpdate(),this.dispatchEvent(new CustomEvent("volumechange",{detail:r?0:this.volume})))}get muted(){return this._muted??(this._muted=this.autoplay||localStorage.getItem("vmp-player-muted")==="true")}set videoResolution(r){r!==this._videoResolution&&(this._videoResolution=r,Object.values(this.media).forEach(({hls:e})=>{if(e){const t=e.levels.findIndex(n=>Math.min(n.height,n.width)===r);e.currentLevel=t??-1}}),this.requestUpdate())}get videoResolution(){return this._videoResolution}set currentTime(r){r!==this._drawController.currentTime&&(this._drawController.currentTime=r,this._sceneController.setMediaCurrentTime(r))}get currentTime(){return this._drawController.currentTime}reset(r=0,e=!1){this._lastTimestamp=null,this._lastCurrentTime=null,this._drawController.currentTime=r,this._sceneController.setMediaCurrentTime(r),e?this.play():this.pause()}clear(){this._drawController.clear()}play(){this.paused=!1,this._lastTimestamp=null,this._lastCurrentTime=null,this.duration>0&&this._drawController.currentTime>=this.duration&&this.reset(0,!0),this._loop()}pause(){this._endLoop(),this.paused=!0,Object.values(this.media).forEach(({node:r})=>{r.pause()})}draw(r){return this._drawController.draw(r)}toggleFullscreen(r){r??this.fullscreen?gB():this._playerRef.value&&fB(this._playerRef.value)}connectedCallback(){var r;super.connectedCallback(),this.addEventListener("error",this._handleError),document.addEventListener("fullscreenchange",this._handleFullscreenChange),document.addEventListener("visibilitychange",this._handleVisibilityChange),(r=this.shadowRoot)!=null&&r.host&&(this._observer=new ResizeObserver(this._handleContainerResize),this._observer.observe(this.shadowRoot.host))}willUpdate(r){r.has("propAspectRatio")&&(this._aspectRatio=this.propAspectRatio),r.has("propLanguage")&&(this._language=this.propLanguage)}updated(r){r.has("propAspectRatio")&&!this.propAspectRatio&&this._handleContainerResize(),this.autoplay&&!this._sceneController.hasPlayed&&!this.processing&&r.get("_processing")&&this.play(),r.has("_processing")&&this.processing&&this.dispatchEvent(new CustomEvent("processing"))}disconnectedCallback(){var r;super.disconnectedCallback(),(r=this._observer)==null||r.disconnect(),document.removeEventListener("fullscreenchange",this._handleFullscreenChange),document.removeEventListener("visibilitychange",this._handleVisibilityChange)}_renderStyles(){return this.propAspectRatio?typeof this.propAspectRatio=="number"?Te`
3745
3745
  <style>
3746
3746
  :host {
3747
3747
  aspect-ratio: ${this.propAspectRatio};