@vouchfor/embeds 4.0.2 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/embeds.js CHANGED
@@ -196,7 +196,7 @@ class FetcherController {
196
196
  }
197
197
  }
198
198
  const name = "@vouchfor/embeds";
199
- const version = "4.0.2";
199
+ const version = "4.0.3";
200
200
  const license = "MIT";
201
201
  const author = "Aaron Williams";
202
202
  const main = "dist/es/embeds.js";
@@ -238,8 +238,8 @@ const scripts = {
238
238
  const dependencies = {
239
239
  "@a11y/focus-trap": "^1.0.5",
240
240
  "@lit/task": "^1.0.0",
241
- "@vouchfor/canvas-video": "^9.0.1",
242
- "@vouchfor/media-player": "^5.0.2",
241
+ "@vouchfor/canvas-video": "^9.0.2",
242
+ "@vouchfor/media-player": "^5.0.3",
243
243
  uuid: "^9.0.1"
244
244
  };
245
245
  const peerDependencies = {
@@ -258,7 +258,7 @@ const devDependencies = {
258
258
  "@types/mocha": "^10.0.6",
259
259
  "@vouchfor/eslint-config": "^1.0.1",
260
260
  "@vouchfor/prettier-config": "^1.0.1",
261
- "@vouchfor/video-utils": "^2.0.0",
261
+ "@vouchfor/video-utils": "^2.0.2",
262
262
  "@web/dev-server-esbuild": "^1.0.2",
263
263
  "@web/test-runner": "^0.18.1",
264
264
  "@web/test-runner-browserstack": "^0.7.1",
@@ -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 cc=Co(gp);var uc;function pp(r){if(typeof r=="string"){const[e,t]=r.split(":");return Math.min(parseFloat(e),parseFloat(t))}return r}function mp(r){if(typeof r=="string"){const[e,t]=r.split(":"),i=parseFloat(e),n=parseFloat(t);return i/n}return r}function zo({resolution:r,aspectRatio:e}){const t=pp(r),i=mp(e),n=i>=1,s=Math.min(n?t*i:t/i,t),o=Math.max(n?t*i:t/i,t);return{resolution:t,aspectRatio:i,height:n?s:o,width:n?o:s}}function Ep({source:r,sx:e,sy:t,sw:i,sh:n,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,i=i??A,n=n??c,i<0&&(e+=i,i=Math.abs(i)),n<0&&(t+=n,n=Math.abs(n)),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+i,A),d=Math.max(t,0),f=Math.min(t+n,c),g=a/i,p=l/n;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 Ip({context:r,source:e,crop:t,format:i="letterbox",posX:n,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),v=l*Math.min(1-(u??0),d??1),Q=A*Math.min(1-(h??0),f??1);let b=g,y=p,w=v,R=Q,k=v,$=Q;if(c.width=v,c.height=Q,i==="crop"){const P=o/a,J=v/Q,ie=J>P?v-Q*P:0,ee=J<P?Q-v/P:0;c.width=v+ie,c.height=Q+ee,b+=ie/2,y+=ee/2,w-=ie,R-=ee,k+=ie,$+=ee}const W=c.getContext("2d");if(W){const P=Ep({source:e,sx:b,sy:y,sw:w,sh:R,dx:0,dy:0,dw:k,dh:$});W.drawImage(...P)}r.drawImage(c,n,s,o,a)}const ii=/(?<value>\d+\.?\d*)(?=px)/;function hc({context:r,word:e,maxW:t=1/0}){const i=[],n=r.measureText(e);if(Math.floor(n.width)<=t)return[{text:e,metrics:n}];for(let s=0;s<e.length;s++){const o=i[i.length-1],a=((o==null?void 0:o.text)??"")+e[s],l=r.measureText(a);l.width<t?i[o?i.length-1:0]={text:a,metrics:l}:i.push({text:e[s],metrics:r.measureText(e[s])})}return i}const Zo=vo(({context:r,fontSizes:e,text:t,maxW:i=1/0})=>{try{return r.save(),r.font=r.font.replace(ii,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>i)a=[...a,...hc({context:r,word:l,maxW:i})];else{const d=e[A%e.length];r.font=r.font.replace(ii,d.toString()),a[a.length-1]={text:u,metrics:h}}return a},hc({context:r,word:o[0],maxW:i})):{text:"",metrics:r.measureText("")}})}finally{r.restore()}},{cacheKey:([{fontSizes:r,text:e,maxW:t}])=>`${JSON.stringify(r)}_${e}_${t}`}),br=1.8;function vp({context:r,x:e,y:t,width:i,height:n,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(n/br,o),t),r.lineTo(e+i-Math.min(n/br,a),t),r.quadraticCurveTo(e+i,t,e+i,t+Math.min(n/br,a)),r.lineTo(e+i,t+n-Math.min(n/br,l)),r.quadraticCurveTo(e+i,t+n,e+i-Math.min(n/br,l),t+n),r.lineTo(e+Math.min(n/br,A),t+n),r.quadraticCurveTo(e,t+n,e,t+n-Math.min(n/br,A)),r.lineTo(e,t+Math.min(n/br,o)),r.quadraticCurveTo(e,t,e+Math.min(n/br,o),t),r.closePath()}function dc({context:r,x:e,y:t,width:i,height:n,radii:s,clip:o=!1,debug:a=!1}){vp({context:r,x:e,y:t,width:i,height:n,radii:s}),a&&(r.strokeStyle="blue",r.stroke()),o&&r.clip()}const fc=[{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 hs({text:r,font:e}){let t=e;return fc.forEach(({family:i,regex:n})=>{n.exec(r)&&(t+=`, ${i}`)}),t}vo(({context:r,fontSizes:e,maxW:t=1/0,words:i})=>{try{return r.save(),r.font=r.font.replace(ii,e[0].toString()),i.length<=0?[]:i.slice(1).reduce((n,s)=>{var o;const a=s.text,A=`${(o=n[n.length-1])==null?void 0:o.text} ${a}`.trim(),c=r.measureText(A);if(c.width>t){const u=e[n.length%e.length];r.font=r.font.replace(ii,u.toString()),n=[...n,{text:a,metrics:r.measureText(a),words:[s]}]}else n[n.length-1]={text:A,metrics:c,words:[...n[n.length-1].words,s]};return n},[{text:i[0].text,metrics:r.measureText(i[0].text),words:[i[0]]}])}finally{r.restore()}},{cacheKey:([{fontSizes:r,words:e,maxW:t}])=>`${JSON.stringify(r)}_${JSON.stringify(e)}_${t}`});let ds;const Cp=new Uint8Array(16);function yp(){if(!ds&&(ds=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ds))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ds(Cp)}const yt=[];for(let r=0;r<256;++r)yt.push((r+256).toString(16).slice(1));function Bp(r,e=0){return yt[r[e+0]]+yt[r[e+1]]+yt[r[e+2]]+yt[r[e+3]]+"-"+yt[r[e+4]]+yt[r[e+5]]+"-"+yt[r[e+6]]+yt[r[e+7]]+"-"+yt[r[e+8]]+yt[r[e+9]]+"-"+yt[r[e+10]]+yt[r[e+11]]+yt[r[e+12]]+yt[r[e+13]]+yt[r[e+14]]+yt[r[e+15]]}const gc={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Tp(r,e,t){if(gc.randomUUID&&!e&&!r)return gc.randomUUID();r=r||{};const i=r.random||(r.rng||yp)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){t=t||0;for(let n=0;n<16;++n)e[t+n]=i[n];return e}return Bp(i)}const Qp={type:"audio",options:{speed:{type:"slider",name:"speed",label:"Speed",min:.5,max:2,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]})}},bp={type:"image",width:({node:r,options:e,dependencies:t})=>{var i,n,s,o;const{format:a}=e;if(!t)return 0;const l=((i=t.image)==null?void 0:i.naturalWidth)??((n=t.image)==null?void 0:n.width),A=((s=t.image)==null?void 0:s.naturalHeight)??((o=t.image)==null?void 0:o.height),c=l/A;if(a==="letterbox"){const h=r.getComputedWidth(),d=r.getComputedHeight(),f=h/d;return c>f?h:d*c}const u=r.getComputedHeight();return u?u*c:r.getComputedWidth()},height:({node:r,options:e,dependencies:t})=>{var i,n,s,o;const{format:a}=e;if(!t)return 0;const l=((i=t.image)==null?void 0:i.naturalWidth)??((n=t.image)==null?void 0:n.width),A=((s=t.image)==null?void 0:s.naturalHeight)??((o=t.image)==null?void 0:o.height),c=l/A;return r.getComputedWidth()/c},render:({dx:r,dy:e,dw:t,dh:i,radius:n,dependencies:s,canvases:o})=>{const a=o.sceneCanvas.getContext("2d");if(!(!a||!(s!=null&&s.image))){if(a.save(),n){const{topLeft:l,topRight:A,bottomLeft:c,bottomRight:u}=n;dc({context:a,x:r,y:e,width:t,height:i,radii:[l,A,u,c]}),a.clip()}a.drawImage(s.image,r,e,t,i),a.restore()}}},pc=vo(({font:r,scale:e,context:t,maxW:i,maxH:n,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=Zo({context:t,fontSizes:[c],text:s,maxW:i});if(h=d.reduce((f,g)=>(g.metrics.width>f&&(f=g.metrics.width),f),0),h>i||d.length*c>n){c-=1;break}}}else c=parseFloat(((A=(l=r.match(ii))==null?void 0:l.groups)==null?void 0:A.value)??"0")*e;return c},{cacheKey:([{font:r,text:e,minSize:t,maxSize:i,scale:n,maxW:s,maxH:o}])=>`${r}_${e}_${t}_${i}_${n}_${s}_${o}`}),xp={type:"text",options:{value:{type:"textarea",name:"value",label:"Text",rows:4},color:{type:"color",name:"color",label:"Text colour"},font:{type:"font",name:"font",label:"Font"},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.minSize":{type:"slider",name:"minSize",label:"Min font size",min:20,max:400,step:1,visible:r=>r.wrap},"fill.maxSize":{type:"slider",name:"maxSize",label:"Max font size",min:20,max:400,step:1,visible:r=>r.wrap}},transform:{values:r=>{var e,t;return{value:r.value,color:r.color??"#000000",font:r.font,wrap:r.wrap??!0,align:r.align??"left",fill:{minSize:[((e=r.fill)==null?void 0:e.minSize)??20],maxSize:[((t=r.fill)==null?void 0:t.maxSize)??400]}}},options:r=>({value:r.value,color:r.color,font:r.font,wrap:r.wrap,align:r.align,fill:{minSize:r.fill.minSize[0],maxSize:r.fill.maxSize[0]}})},width:({node:r,options:e,dependencies:t,measureCanvas:i})=>{const{value:n="",align:s="left",wrap:o=!1}=e,a=r.getParent(),l=i==null?void 0:i.getContext("2d");if(!t||!l||!a||!a.getParent())return r.getComputedWidth();const A=`${t.font.weight} ${t.font.size}px ${t.font.family.name}`,c=hs({font:A,text:n});if(l.font=c,l.textBaseline="top",l.textAlign=s,o){const u=r.getComputedMargin(nr.Edge.Left)+r.getComputedMargin(nr.Edge.Right)+((a==null?void 0:a.getComputedPadding(nr.Edge.Left))??0)+((a==null?void 0:a.getComputedPadding(nr.Edge.Right))??0);return Math.max(((a==null?void 0:a.getComputedWidth())??0)-u,r.getComputedWidth(),...n.split(" ").map(h=>l.measureText(h).width))}return l.measureText(n).width},height:({node:r,options:e,dependencies:t,measureCanvas:i})=>{var n,s;const{value:o="",fill:a,align:l="left",wrap:A=!1}=e,c=r.getParent(),u=i==null?void 0:i.getContext("2d");if(!t||!u||!c||!c.getParent())return r.getComputedHeight();const h=`${t.font.weight} ${t.font.size}px ${t.font.family.name}`,d=hs({font:h,text:o});if(u.font=d,u.textBaseline="top",u.textAlign=l,A){const f=r.getComputedMargin(nr.Edge.Top)+r.getComputedMargin(nr.Edge.Bottom)+((c==null?void 0:c.getComputedPadding(nr.Edge.Top))??0)+((c==null?void 0:c.getComputedPadding(nr.Edge.Bottom))??0),g=r.getComputedWidth(),p=Math.max(((c==null?void 0:c.getComputedHeight())??0)-f,r.getComputedHeight()),v=pc({font:d,scale:1,context:u,maxW:g,maxH:p,text:o??"",minSize:a==null?void 0:a.minSize,maxSize:a==null?void 0:a.maxSize});return Zo({context:u,fontSizes:[v],text:o??"",maxW:g}).length*v}else return parseFloat(((s=(n=d.match(ii))==null?void 0:n.groups)==null?void 0:s.value)??"0")},render:({dx:r,dy:e,dw:t,dh:i,options:n,dependencies:s,canvases:o})=>{const{value:a="",fill:l,color:A,align:c="left",wrap:u=!1}=n,h=o.sceneCanvas.getContext("2d");if(!s||!h)return;h.save();const d=`${s.font.weight} ${s.font.size}px ${s.font.family.name}`,f=hs({font:d,text:a});h.font=f,h.textBaseline="top",h.fillStyle=A,h.textAlign=c;const g={left:r,center:r+t/2,right:r+t};if(u){const p=pc({font:f,scale:1,context:h,maxW:t,maxH:i,text:a??"",minSize:l==null?void 0:l.minSize,maxSize:l==null?void 0:l.maxSize});h.font=f.replace(ii,p.toString()),Zo({context:h,fontSizes:[p],text:a,maxW:t}).forEach((Q,b)=>{h.fillText(Q.text,g[c],e+p*b)})}else h.fillText(a,g[c],e);h.restore()}},wp={type:"video",options:{crop:{type:"crop",name:"crop",label:"Crop"},speed:{type:"slider",name:"speed",label:"Speed",min:.5,max:2,step:.01},volume:{type:"slider",name:"volume",label:"Volume",min:0,max:1,step:.01}},transform:{values:r=>({format:r.format??"letterbox",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:({node:r,options:e,dependencies:t})=>{const{crop:i,format:n}=e;if(!t||n==="crop")return r.getComputedWidth();const s=t.aspectRatio*(((i==null?void 0:i.width)??1)/((i==null?void 0:i.height)??1)),o=r.getComputedWidth(),a=r.getComputedHeight(),l=o/a;return s>l?o:a*s},height:({node:r,options:e,dependencies:t})=>{const{crop:i,format:n}=e;if(!t||n==="crop")return r.getComputedHeight();const s=t.aspectRatio*(((i==null?void 0:i.width)??1)/((i==null?void 0:i.height)??1));return r.getComputedWidth()/s},render:async({dx:r,dy:e,dw:t,dh:i,radius:n,sceneTime:s,options:o,dependencies:a,canvases:l})=>{const{crop:A,format:c="letterbox",speed:u=1}=o,h=l.sceneCanvas.getContext("2d");if(!h||!(a!=null&&a.video))return;const d=await a.video(s*u),f=(d==null?void 0:d.videoWidth)??(d==null?void 0:d.naturalWidth)??(d==null?void 0:d.width),g=(d==null?void 0:d.videoHeight)??(d==null?void 0:d.naturalHeight)??(d==null?void 0:d.height);if(f&&g){h.save();const{topLeft:p,topRight:v,bottomLeft:Q,bottomRight:b}=n;dc({context:h,x:r,y:e,width:t,height:i,radii:[p,v,b,Q]}),h.clip(),Ip({context:h,crop:A,format:c,sourceWidth:f,sourceHeight:g,source:d,posX:r,posY:e,drawAreaWidth:t,drawAreaHeight:i,cropCanvas:l.cropCanvas,letterboxCanvas:l.letterboxCanvas}),h.restore()}}};function Sp(r,e){return Object.keys(r).reduce((t,i)=>(e.includes(i)||(t[i]=r[i]),t),{})}function xr(r){let e=0;for(const t of r)Array.isArray(t)?e+=xr(t):e+=t;return e}function ea(r){return r.map(({type:e,duration:t},i)=>{var n,s,o,a;if(e==="transition"){const l=((n=r[i-2])==null?void 0:n.type)==="transition"?r[i-2]:null,A=((s=r[i-1])==null?void 0:s.duration)??1/0,c=((o=r[i+1])==null?void 0:o.duration)??1/0,u=((a=r[i+2])==null?void 0:a.type)==="transition"?r[i+2]:null;return Math.min(l?A/2:A,t,u?c/2:c)*-1}return t})}function mc(r){var e;return{...r,children:((e=r.children)==null?void 0:e.map(t=>{if(!t.renderer)return mc(t)}).filter(Boolean))??[]}}function Ec(r){const e={box:0,image:0,video:0,text:0,audio:0,gradient:0};r.renderer&&(e[r.renderer.type]+=1);for(const t of r.children??[]){const{box:i,image:n,video:s,text:o,audio:a,gradient:l}=Ec(t);e.box+=i,e.image+=n,e.video+=s,e.text+=o,e.audio+=a,e.gradient+=l}return e}function Rp(r){return r.video>0?wp.type:r.image>0?bp.type:r.audio>0?Qp.type:xp.type}function Ic({node:r,duration:e}){const t=[];if(r.renderer){const i=mc({...r.element,layout:{...r.element.layout?Sp(r.element.layout,["maxWidth","maxHeight"]):{},width:"100%",height:"100%",margin:0}}),n=Ec(i);t.push({type:Rp(n),id:Tp(),x:r.x,y:r.y,width:r.width,height:r.height,duration:e,root:{element:i}})}for(const i of r.childNodes)t.push(...Ic({node:i,duration:e}));return t}function Dp(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 _p(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 Lp=ti(()=>nr.loadYoga());Gf.filters.define("parse",r=>typeof r>"u"?null:typeof r=="string"?`"${_p(r)}"`:Dp(r)||Array.isArray(r)?JSON.stringify(r):r);const Fp="3";function kp(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 Mp(r,e){return typeof r=="number"?{top:r*e,right:r*e,bottom:r*e,left:r*e}:typeof r=="string"?{top:r,right:r,bottom:r,left:r}:{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 Np(r,e){return typeof r=="number"?{top:r*e,right:r*e,bottom:r*e,left:r*e}:typeof r=="string"?{top:r,right:r,bottom:r,left:r}:{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 Pp(r,e){return typeof r=="number"?{top:r*e,right:r*e,bottom:r*e,left:r*e}:typeof r=="string"?{top:r,right:r,bottom:r,left:r}:{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 vc(r,e,{layout:t,scale:i=1}){const{position:n="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:v="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[n]),s){const{top:$,right:W,bottom:P,left:J}=Mp(s,i);typeof $<"u"&&e.setPosition(r.EDGE_TOP,$),typeof W<"u"&&e.setPosition(r.EDGE_RIGHT,W),typeof P<"u"&&e.setPosition(r.EDGE_BOTTOM,P),typeof J<"u"&&e.setPosition(r.EDGE_LEFT,J)}const w={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(w[p]);const R={start:r.ALIGN_FLEX_START,end:r.ALIGN_FLEX_END,center:r.ALIGN_CENTER,stretch:r.ALIGN_STRETCH};e.setAlignItems(R[v]),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:$,right:W,bottom:P,left:J}=Np(f,i);e.setMargin(r.EDGE_TOP,$),e.setMargin(r.EDGE_RIGHT,W),e.setMargin(r.EDGE_BOTTOM,P),e.setMargin(r.EDGE_LEFT,J)}if(g){const{top:$,right:W,bottom:P,left:J}=Pp(g,i);e.setPadding(r.EDGE_TOP,$),e.setPadding(r.EDGE_RIGHT,W),e.setPadding(r.EDGE_BOTTOM,P),e.setPadding(r.EDGE_LEFT,J)}typeof h<"u"&&e.setFlex(h),e.setGap(r.GUTTER_ALL,(d??0)*i),typeof o<"u"&&e.setWidth(typeof o=="number"?o*i:o),typeof a<"u"&&(typeof a=="function"?e.setHeight("100%"):e.setHeight(typeof a=="number"?a*i:a)),typeof l<"u"&&e.setMinWidth(typeof l=="number"?l*i:l),typeof A<"u"&&e.setMinHeight(typeof A=="number"?A*i:A),typeof c<"u"&&e.setMaxWidth(typeof c=="number"?c*i:c),typeof u<"u"&&e.setMaxHeight(typeof u=="number"?u*i:u)}async function Cc({yoga:r,index:e,parent:t,element:i,resolvers:n}){var s,o;const{layout:a={},config:l={},options:A={},renderer:c}=i,u=r.Node.create();vc(r,u,{layout:a}),t.insertChild(u,e);let h=null;n&&((c==null?void 0:c.type)==="text"||(c==null?void 0:c.type)==="image"||(c==null?void 0:c.type)==="video")&&(h=await((s=n[c.type])==null?void 0:s.call(n,{config:l,options:A}))??null);const d=[];for await(const[f,g]of((o=i.children)==null?void 0:o.entries())??[])d.push(await Cc({yoga:r,index:f,parent:u,element:g,resolvers:n}));return{node:u,radius:kp(a.radius),element:i,renderer:c,config:l,options:A,dependencies:h,childNodes:d}}function yc(r,e,t=0,i=0){const{top:n,left:s}=r.getComputedLayout(),{top:o,left:a,width:l,height:A}=e.node.getComputedLayout(),c=t+a,u=i+o,h=e.childNodes.map(d=>yc(r,d,c,u));return{...e,x:s+c,y:n+u,width:l,height:A,childNodes:h}}async function Bc(r,e,t){for await(const{node:i,options:n,dependencies:s,renderer:o,childNodes:a}of e){if(o){const{width:l,height:A}=o;if(l){r.calculateLayout();const c=await l({node:i,options:n,dependencies:s,measureCanvas:t});i.setWidth(c)}if(A){r.calculateLayout();const c=await A({node:i,options:n,dependencies:s,measureCanvas:t});i.setHeight(c)}}r.calculateLayout(),await Bc(r,a,t)}}async function Tc({root:r,resolvers:e,measureCanvas:t}){const i=await Lp(),n=i.Node.create();vc(i,n,{layout:r.layout});const s=await Cc({yoga:i,index:0,parent:n,element:r.element,resolvers:e});await Bc(n,[s],t);const{top:o,left:a,width:l,height:A}=n.getComputedLayout(),c={root:{x:a,y:o,width:l,height:A},node:yc(n,s)};return n.freeRecursive(),c}async function Op({scene:r,start:e=0}){const{root:t,duration:i}=r,n=await Tc({root:t});return{type:r.type,start:e,duration:i,layout:n,id:r.id,config:r}}async function Up({track:r}){const e=ea(r),t=await Promise.all(r.reduce((s,o,a)=>{if(o.type!=="audio")return s;const l=xr(e.slice(0,a));return s.push(Op({scene:o,start:l})),s},[])),i=r.reduce((s,o,a)=>{if(o.type!=="gap")return s;const l=xr(e.slice(0,a));return s.push({type:o.type,id:o.id,start:l,config:o,duration:o.duration}),s},[]),n=r.map(({id:s})=>t.find(({id:o})=>o===s)??i.find(({id:o})=>o===s)).filter(Boolean);return{type:"audio",scenes:t,gapScenes:i,mergedScenes:n,config:r,duration:Math.max(...n.map(({start:s,duration:o})=>s+o))}}function Qc(){return document.createElement("canvas")}async function bc({node:r,canvases:e,sceneTime:t}){var i,n;await((n=(i=r.renderer)==null?void 0:i.render)==null?void 0:n.call(i,{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}));for await(const s of r.childNodes)await bc({node:s,canvases:e,sceneTime:t})}async function Gp({layout:r,canvases:e,sceneTime:t}){const{node:i}=r;await bc({node:i,canvases:e,sceneTime:t})}async function ta({scene:r,start:e=0,resolvers:t,rootWidth:i,rootHeight:n,canvasFactory:s=Qc}){var o,a;const{x:l,y:A,width:c,height:u,root:h,duration:d}=r,f=s(),g=s(),p=s(),v=s(),Q=s(),b=await Tc({root:{...h,layout:{...h.layout,width:i,height:n},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:Q}),y=async w=>{const R=Math.max(0,w-e);f.width=f.height=0,f.width=i,f.height=n,await Gp({layout:b,sceneTime:R,canvases:{sceneCanvas:f,cropCanvas:g,letterboxCanvas:p,posterCanvas:v}})};return{type:r.type,start:e,duration:d,layout:b,sceneCanvas:f,draw:y,id:r.id,config:r,childScenes:Ic({node:b.node,duration:d})}}async function Hp({track:r,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n}){const s=ea(r),o=await Promise.all(r.reduce((c,u,h)=>{const d=xr(s.slice(0,h));return u.type==="video"&&c.push(ta({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n})),u.type==="image"&&c.push(ta({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n})),c},[])),a=r.reduce((c,u,h)=>{if(u.type!=="gap")return c;const d=xr(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=xr(s.slice(0,h))-d;return c.push({type:u.type,id:u.id,name:u.name,start:f,duration:d,config:u,transitionCanvas:n(),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:n()}}async function $p({track:r,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n}){const s=ea(r),o=await Promise.all(r.reduce((c,u,h)=>{const d=xr(s.slice(0,h));return u.type==="text"&&c.push(ta({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n})),c},[])),a=r.reduce((c,u,h)=>{if(u.type!=="gap")return c;const d=xr(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=xr(s.slice(0,h))-d;return c.push({type:u.type,id:u.id,name:u.name,start:f,duration:d,config:u,transitionCanvas:n(),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:n()}}function Yp(r){return r.some(({type:e})=>e==="text")}function Vp(r){return r.some(({type:e})=>e==="audio")}function Kp(r){return r.some(({type:e})=>e==="video"||e==="image")}function Wp(r){return r.type==="audio"}const Jp=(((uc=cc)==null?void 0:uc.default)??cc).reduce((r,e)=>(r[e.name]=e,r),{});function qp({name:r,to:e,from:t,progress:i,width:n,height:s,glContext:o}){var a,l,A;o.disable(o.DEPTH_TEST);const c=o.createBuffer();o.bindBuffer(o.ARRAY_BUFFER,c),o.bufferData(o.ARRAY_BUFFER,new Float32Array([-1,-1,-1,4,4,-1]),o.STATIC_DRAW),o.viewport(0,0,n,s);const u=(((a=ls)==null?void 0:a.default)??ls)(o,t);u.minFilter=o.LINEAR,u.magFilter=o.LINEAR;const h=(((l=ls)==null?void 0:l.default)??ls)(o,e);h.minFilter=o.LINEAR,h.magFilter=o.LINEAR;const d=(((A=Ac)==null?void 0:A.default)??Ac)(o,Jp[r]);d.draw(i,u,h,n,s);const f=new Uint8Array(n*s*4);return o.readPixels(0,0,n,s,o.RGBA,o.UNSIGNED_BYTE,f),u.dispose(),h.dispose(),d.dispose(),o.flush(),f}function Xp({name:r,to:e,from:t,progress:i,canvas:n}){const s=n.getContext("webgl");s&&(s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!0),qp({name:r,to:e,from:t,progress:i,width:n.width,height:n.height,glContext:s}))}async function xc({config:r,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n=Qc,drawTransition:s=Xp}){const o=await Promise.all(r.tracks.map(async l=>{if(Kp(l))return{...await Hp({track:l,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n}),config:l};if(Yp(l))return{...await $p({track:l,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n}),config:l};if(Vp(l))return{...await Up({track:l}),config:l};throw new Error("Unknown track type")}));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 o){if(Wp(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=f.getContext("2d"),p=h.filter(({start:Q,duration:b})=>A>=Q&&A<Q+b);if(!g||p.length<=0)continue;const v=d.find(({start:Q,duration:b})=>A>=Q&&A<Q+b);for await(const{sceneCanvas:Q,draw:b}of p)await(b==null?void 0:b(A)),(!v||v&&(!v.to||!v.from))&&g.drawImage(Q,0,0,Q.width,Q.height);if(v&&v.to&&v.from){const{name:Q,to:b,from:y,duration:w,transitionCanvas:R}=v;R.width=R.height=0,R.width=f.width,R.height=f.height;const k=Math.min(1,Math.max(0,(A-b.start)/w));await s({name:Q,progress:k,to:b.sceneCanvas,from:y.sceneCanvas,canvas:R}),g.globalCompositeOperation="lighter",g.drawImage(R,0,0,R.width,R.height)}c.drawImage(f,0,0,f.width,f.height)}}},tracks:o,aspectRatio:r.aspectRatio,duration:Math.max(...o.map(({duration:l})=>l))}}const jp={name:"@vouchfor/embeds",version:"4.0.2",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:"latest",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":"^9.0.1","@vouchfor/media-player":"^5.0.2",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":"^2.0.0","@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 zp(r){const{publicApiUrl:e}=Vn(r),t=Br();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function Zp(r){var s,o,a,l,A,c,u,h,d,f,g,p;if(typeof window>"u")return{client:null,tab:null,request:Br()};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"),i=(c=(A=window.sessionStorage)==null?void 0:A.getItem)==null?void 0:c.call(A,"vouch-uid-tab");const n=Br();return e||(e=zp(r),(h=(u=window.localStorage)==null?void 0:u.setItem)==null||h.call(u,"vouch-uid-visitor",e)),t||(t=Br(),(f=(d=window.localStorage)==null?void 0:d.setItem)==null||f.call(d,"vouch-uid-client",t)),i||(i=Br(),(p=(g=window.sessionStorage)==null?void 0:g.setItem)==null||p.call(g,"vouch-uid-tab",i)),{client:t,tab:i,request:n,visitor:e}}function em(r,e){return r&&"vouchId"in r?r.vouchId:(e==null?void 0:e.id)??null}function tm(r="embedded_player"){var n,s;const[e,t]=((s=(n=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:n.split)==null?void 0:s.call(n,"/"))??[],i={};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());i[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:jp.version,templateVersion:Fp,...i}}const wc=1;class rm{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const n=em(i,this.host.vouch);!n||this.host.disableTracking||this._batchedEvents.push({event:t,payload:{...i,vouchId:n,time:new Date().toISOString()}})},this._sendTrackingEvent=()=>{if(this._batchedEvents.length<=0)return;const{publicApiUrl:t}=Vn(this.host.env),{client:i,tab:n,request:s,visitor:o}=Zp(this.host.env);navigator.sendBeacon(`${t}/api/batchevents`,JSON.stringify({payload:{events:this._batchedEvents},context:{"x-uid-client":i,"x-uid-tab":n,"x-uid-request":s,"x-uid-visitor":o,"x-reporting-metadata":tm(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+wc&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]}},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:i}})=>{this._answersViewed[i]||(this._createTrackingEvent("VOUCH_RESPONSE_VIEWED",{answerId:t}),this._answersViewed[i]=!0)},this._handleVideoTimeUpdate=({detail:{id:t,key:i,node:n}})=>{this.host.paused||(this._currentlyPlayingVideo={id:t,key:i,node:n},this._streamLatestTime[i]=n.currentTime,this._streamStartTime[i]||(this._streamStartTime[i]=n.currentTime,this._streamLatestTime[i]=n.currentTime))},this._handleVideoPause=({detail:{id:t,key:i}})=>{this._streamLatestTime[i]>this._streamStartTime[i]+wc&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]},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,i,n;"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),(i=this.host.mediaPlayer)==null||i.addEventListener("video:pause",this._handleVideoPause),(n=this.host.mediaPlayer)==null||n.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var e,t,i,n;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),(i=this.host.mediaPlayer)==null||i.removeEventListener("video:pause",this._handleVideoPause),(n=this.host.mediaPlayer)==null||n.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}var ra={exports:{}};(function(r,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof Ci<"u"&&Ci,i=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 v(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=v(O);return O.readAsArrayBuffer(D),X}function b(D){var O=new FileReader,X=v(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 w(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=w(D.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):l.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(D)||u(D))?this._bodyArrayBuffer=w(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 $(D){var O=D.toUpperCase();return k.indexOf(O)>-1?O:D}function W(D,O){if(!(this instanceof W))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 W){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=$(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()}}}W.prototype.clone=function(){return new W(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 J(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>i)a=[...a,...hc({context:r,word:l,maxW:i})];else{const d=e[A%e.length];r.font=r.font.replace(ii,d.toString()),a[a.length-1]={text:u,metrics:h}}return a},hc({context:r,word:o[0],maxW:i})):{text:"",metrics:r.measureText("")}})}finally{r.restore()}},{cacheKey:([{fontSizes:r,text:e,maxW:t}])=>`${JSON.stringify(r)}_${e}_${t}`}),br=1.8;function vp({context:r,x:e,y:t,width:i,height:n,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(n/br,o),t),r.lineTo(e+i-Math.min(n/br,a),t),r.quadraticCurveTo(e+i,t,e+i,t+Math.min(n/br,a)),r.lineTo(e+i,t+n-Math.min(n/br,l)),r.quadraticCurveTo(e+i,t+n,e+i-Math.min(n/br,l),t+n),r.lineTo(e+Math.min(n/br,A),t+n),r.quadraticCurveTo(e,t+n,e,t+n-Math.min(n/br,A)),r.lineTo(e,t+Math.min(n/br,o)),r.quadraticCurveTo(e,t,e+Math.min(n/br,o),t),r.closePath()}function dc({context:r,x:e,y:t,width:i,height:n,radii:s,clip:o=!1,debug:a=!1}){vp({context:r,x:e,y:t,width:i,height:n,radii:s}),a&&(r.strokeStyle="blue",r.stroke()),o&&r.clip()}const fc=[{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 hs({text:r,font:e}){let t=e;return fc.forEach(({family:i,regex:n})=>{n.exec(r)&&(t+=`, ${i}`)}),t}vo(({context:r,fontSizes:e,maxW:t=1/0,words:i})=>{try{return r.save(),r.font=r.font.replace(ii,e[0].toString()),i.length<=0?[]:i.slice(1).reduce((n,s)=>{var o;const a=s.text,A=`${(o=n[n.length-1])==null?void 0:o.text} ${a}`.trim(),c=r.measureText(A);if(c.width>t){const u=e[n.length%e.length];r.font=r.font.replace(ii,u.toString()),n=[...n,{text:a,metrics:r.measureText(a),words:[s]}]}else n[n.length-1]={text:A,metrics:c,words:[...n[n.length-1].words,s]};return n},[{text:i[0].text,metrics:r.measureText(i[0].text),words:[i[0]]}])}finally{r.restore()}},{cacheKey:([{fontSizes:r,words:e,maxW:t}])=>`${JSON.stringify(r)}_${JSON.stringify(e)}_${t}`});let ds;const Cp=new Uint8Array(16);function yp(){if(!ds&&(ds=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ds))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ds(Cp)}const yt=[];for(let r=0;r<256;++r)yt.push((r+256).toString(16).slice(1));function Bp(r,e=0){return yt[r[e+0]]+yt[r[e+1]]+yt[r[e+2]]+yt[r[e+3]]+"-"+yt[r[e+4]]+yt[r[e+5]]+"-"+yt[r[e+6]]+yt[r[e+7]]+"-"+yt[r[e+8]]+yt[r[e+9]]+"-"+yt[r[e+10]]+yt[r[e+11]]+yt[r[e+12]]+yt[r[e+13]]+yt[r[e+14]]+yt[r[e+15]]}const gc={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Tp(r,e,t){if(gc.randomUUID&&!e&&!r)return gc.randomUUID();r=r||{};const i=r.random||(r.rng||yp)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){t=t||0;for(let n=0;n<16;++n)e[t+n]=i[n];return e}return Bp(i)}const Qp={type:"audio",options:{speed:{type:"slider",name:"speed",label:"Speed",min:.5,max:2,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]})}},bp={type:"image",width:({node:r,options:e,dependencies:t})=>{var i,n,s,o;const{format:a}=e;if(!t)return 0;const l=((i=t.image)==null?void 0:i.naturalWidth)??((n=t.image)==null?void 0:n.width),A=((s=t.image)==null?void 0:s.naturalHeight)??((o=t.image)==null?void 0:o.height),c=l/A;if(a==="letterbox"){const h=r.getComputedWidth(),d=r.getComputedHeight(),f=h/d;return c>f?h:d*c}const u=r.getComputedHeight();return u?u*c:r.getComputedWidth()},height:({node:r,options:e,dependencies:t})=>{var i,n,s,o;const{format:a}=e;if(!t)return 0;const l=((i=t.image)==null?void 0:i.naturalWidth)??((n=t.image)==null?void 0:n.width),A=((s=t.image)==null?void 0:s.naturalHeight)??((o=t.image)==null?void 0:o.height),c=l/A;return r.getComputedWidth()/c},render:({dx:r,dy:e,dw:t,dh:i,radius:n,dependencies:s,canvases:o})=>{const a=o.sceneCanvas.getContext("2d");if(!(!a||!(s!=null&&s.image))){if(a.save(),n){const{topLeft:l,topRight:A,bottomLeft:c,bottomRight:u}=n;dc({context:a,x:r,y:e,width:t,height:i,radii:[l,A,u,c]}),a.clip()}a.drawImage(s.image,r,e,t,i),a.restore()}}},pc=vo(({font:r,scale:e,context:t,maxW:i,maxH:n,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=Zo({context:t,fontSizes:[c],text:s,maxW:i});if(h=d.reduce((f,g)=>(g.metrics.width>f&&(f=g.metrics.width),f),0),h>i||d.length*c>n){c-=1;break}}}else c=parseFloat(((A=(l=r.match(ii))==null?void 0:l.groups)==null?void 0:A.value)??"0")*e;return c},{cacheKey:([{font:r,text:e,minSize:t,maxSize:i,scale:n,maxW:s,maxH:o}])=>`${r}_${e}_${t}_${i}_${n}_${s}_${o}`}),xp={type:"text",options:{value:{type:"textarea",name:"value",label:"Text",rows:4},color:{type:"color",name:"color",label:"Text colour"},font:{type:"font",name:"font",label:"Font"},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.minSize":{type:"slider",name:"minSize",label:"Min font size",min:20,max:400,step:1,visible:r=>r.wrap},"fill.maxSize":{type:"slider",name:"maxSize",label:"Max font size",min:20,max:400,step:1,visible:r=>r.wrap}},transform:{values:r=>{var e,t;return{value:r.value,color:r.color??"#000000",font:r.font,wrap:r.wrap??!0,align:r.align??"left",fill:{minSize:[((e=r.fill)==null?void 0:e.minSize)??20],maxSize:[((t=r.fill)==null?void 0:t.maxSize)??400]}}},options:r=>({value:r.value,color:r.color,font:r.font,wrap:r.wrap,align:r.align,fill:{minSize:r.fill.minSize[0],maxSize:r.fill.maxSize[0]}})},width:({node:r,options:e,dependencies:t,measureCanvas:i})=>{const{value:n="",align:s="left",wrap:o=!1}=e,a=r.getParent(),l=i==null?void 0:i.getContext("2d");if(!t||!l||!a||!a.getParent())return r.getComputedWidth();const A=`${t.font.weight} ${t.font.size}px ${t.font.family.name}`,c=hs({font:A,text:n});if(l.font=c,l.textBaseline="top",l.textAlign=s,o){const u=r.getComputedMargin(nr.Edge.Left)+r.getComputedMargin(nr.Edge.Right)+((a==null?void 0:a.getComputedPadding(nr.Edge.Left))??0)+((a==null?void 0:a.getComputedPadding(nr.Edge.Right))??0);return Math.max(((a==null?void 0:a.getComputedWidth())??0)-u,r.getComputedWidth(),...n.split(" ").map(h=>l.measureText(h).width))}return l.measureText(n).width},height:({node:r,options:e,dependencies:t,measureCanvas:i})=>{var n,s;const{value:o="",fill:a,align:l="left",wrap:A=!1}=e,c=r.getParent(),u=i==null?void 0:i.getContext("2d");if(!t||!u||!c||!c.getParent())return r.getComputedHeight();const h=`${t.font.weight} ${t.font.size}px ${t.font.family.name}`,d=hs({font:h,text:o});if(u.font=d,u.textBaseline="top",u.textAlign=l,A){const f=r.getComputedMargin(nr.Edge.Top)+r.getComputedMargin(nr.Edge.Bottom)+((c==null?void 0:c.getComputedPadding(nr.Edge.Top))??0)+((c==null?void 0:c.getComputedPadding(nr.Edge.Bottom))??0),g=r.getComputedWidth(),p=Math.max(((c==null?void 0:c.getComputedHeight())??0)-f,r.getComputedHeight()),v=pc({font:d,scale:1,context:u,maxW:g,maxH:p,text:o??"",minSize:a==null?void 0:a.minSize,maxSize:a==null?void 0:a.maxSize});return Zo({context:u,fontSizes:[v],text:o??"",maxW:g}).length*v}else return parseFloat(((s=(n=d.match(ii))==null?void 0:n.groups)==null?void 0:s.value)??"0")},render:({dx:r,dy:e,dw:t,dh:i,options:n,dependencies:s,canvases:o})=>{const{value:a="",fill:l,color:A,align:c="left",wrap:u=!1}=n,h=o.sceneCanvas.getContext("2d");if(!s||!h)return;h.save();const d=`${s.font.weight} ${s.font.size}px ${s.font.family.name}`,f=hs({font:d,text:a});h.font=f,h.textBaseline="top",h.fillStyle=A,h.textAlign=c;const g={left:r,center:r+t/2,right:r+t};if(u){const p=pc({font:f,scale:1,context:h,maxW:t,maxH:i,text:a??"",minSize:l==null?void 0:l.minSize,maxSize:l==null?void 0:l.maxSize});h.font=f.replace(ii,p.toString()),Zo({context:h,fontSizes:[p],text:a,maxW:t}).forEach((Q,b)=>{h.fillText(Q.text,g[c],e+p*b)})}else h.fillText(a,g[c],e);h.restore()}},wp={type:"video",options:{crop:{type:"crop",name:"crop",label:"Crop"},speed:{type:"slider",name:"speed",label:"Speed",min:.5,max:2,step:.01},volume:{type:"slider",name:"volume",label:"Volume",min:0,max:1,step:.01}},transform:{values:r=>({format:r.format??"letterbox",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:({node:r,options:e,dependencies:t})=>{const{crop:i,format:n}=e;if(!t||n==="crop")return r.getComputedWidth();const s=t.aspectRatio*(((i==null?void 0:i.width)??1)/((i==null?void 0:i.height)??1)),o=r.getComputedWidth(),a=r.getComputedHeight(),l=o/a;return s>l?o:a*s},height:({node:r,options:e,dependencies:t})=>{const{crop:i,format:n}=e;if(!t||n==="crop")return r.getComputedHeight();const s=t.aspectRatio*(((i==null?void 0:i.width)??1)/((i==null?void 0:i.height)??1));return r.getComputedWidth()/s},render:async({dx:r,dy:e,dw:t,dh:i,radius:n,sceneTime:s,options:o,dependencies:a,canvases:l})=>{const{crop:A,format:c="letterbox",speed:u=1}=o,h=l.sceneCanvas.getContext("2d");if(!h||!(a!=null&&a.video))return;const d=await a.video(s*u),f=(d==null?void 0:d.videoWidth)??(d==null?void 0:d.naturalWidth)??(d==null?void 0:d.width),g=(d==null?void 0:d.videoHeight)??(d==null?void 0:d.naturalHeight)??(d==null?void 0:d.height);if(f&&g){h.save();const{topLeft:p,topRight:v,bottomLeft:Q,bottomRight:b}=n;dc({context:h,x:r,y:e,width:t,height:i,radii:[p,v,b,Q]}),h.clip(),Ip({context:h,crop:A,format:c,sourceWidth:f,sourceHeight:g,source:d,posX:r,posY:e,drawAreaWidth:t,drawAreaHeight:i,cropCanvas:l.cropCanvas,letterboxCanvas:l.letterboxCanvas}),h.restore()}}};function Sp(r,e){return Object.keys(r).reduce((t,i)=>(e.includes(i)||(t[i]=r[i]),t),{})}function xr(r){let e=0;for(const t of r)Array.isArray(t)?e+=xr(t):e+=t;return e}function ea(r){return r.map(({type:e,duration:t},i)=>{var n,s,o,a;if(e==="transition"){const l=((n=r[i-2])==null?void 0:n.type)==="transition"?r[i-2]:null,A=((s=r[i-1])==null?void 0:s.duration)??1/0,c=((o=r[i+1])==null?void 0:o.duration)??1/0,u=((a=r[i+2])==null?void 0:a.type)==="transition"?r[i+2]:null;return Math.min(l?A/2:A,t,u?c/2:c)*-1}return t})}function mc(r){var e;return{...r,children:((e=r.children)==null?void 0:e.map(t=>{if(!t.renderer)return mc(t)}).filter(Boolean))??[]}}function Ec(r){const e={box:0,image:0,video:0,text:0,audio:0,gradient:0};r.renderer&&(e[r.renderer.type]+=1);for(const t of r.children??[]){const{box:i,image:n,video:s,text:o,audio:a,gradient:l}=Ec(t);e.box+=i,e.image+=n,e.video+=s,e.text+=o,e.audio+=a,e.gradient+=l}return e}function Rp(r){return r.video>0?wp.type:r.image>0?bp.type:r.audio>0?Qp.type:xp.type}function Ic({node:r,duration:e}){const t=[];if(r.renderer){const i=mc({...r.element,layout:{...r.element.layout?Sp(r.element.layout,["maxWidth","maxHeight"]):{},width:"100%",height:"100%",margin:0}}),n=Ec(i);t.push({type:Rp(n),id:Tp(),x:r.x,y:r.y,width:r.width,height:r.height,duration:e,root:{element:i}})}for(const i of r.childNodes)t.push(...Ic({node:i,duration:e}));return t}function Dp(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 _p(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 Lp=ti(()=>nr.loadYoga());Gf.filters.define("parse",r=>typeof r>"u"?null:typeof r=="string"?`"${_p(r)}"`:Dp(r)||Array.isArray(r)?JSON.stringify(r):r);const Fp="3";function kp(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 Mp(r,e){return typeof r=="number"?{top:r*e,right:r*e,bottom:r*e,left:r*e}:typeof r=="string"?{top:r,right:r,bottom:r,left:r}:{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 Np(r,e){return typeof r=="number"?{top:r*e,right:r*e,bottom:r*e,left:r*e}:typeof r=="string"?{top:r,right:r,bottom:r,left:r}:{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 Pp(r,e){return typeof r=="number"?{top:r*e,right:r*e,bottom:r*e,left:r*e}:typeof r=="string"?{top:r,right:r,bottom:r,left:r}:{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 vc(r,e,{layout:t,scale:i=1}){const{position:n="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:v="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[n]),s){const{top:$,right:W,bottom:P,left:J}=Mp(s,i);typeof $<"u"&&e.setPosition(r.EDGE_TOP,$),typeof W<"u"&&e.setPosition(r.EDGE_RIGHT,W),typeof P<"u"&&e.setPosition(r.EDGE_BOTTOM,P),typeof J<"u"&&e.setPosition(r.EDGE_LEFT,J)}const w={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(w[p]);const R={start:r.ALIGN_FLEX_START,end:r.ALIGN_FLEX_END,center:r.ALIGN_CENTER,stretch:r.ALIGN_STRETCH};e.setAlignItems(R[v]),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:$,right:W,bottom:P,left:J}=Np(f,i);e.setMargin(r.EDGE_TOP,$),e.setMargin(r.EDGE_RIGHT,W),e.setMargin(r.EDGE_BOTTOM,P),e.setMargin(r.EDGE_LEFT,J)}if(g){const{top:$,right:W,bottom:P,left:J}=Pp(g,i);e.setPadding(r.EDGE_TOP,$),e.setPadding(r.EDGE_RIGHT,W),e.setPadding(r.EDGE_BOTTOM,P),e.setPadding(r.EDGE_LEFT,J)}typeof h<"u"&&e.setFlex(h),e.setGap(r.GUTTER_ALL,(d??0)*i),typeof o<"u"&&e.setWidth(typeof o=="number"?o*i:o),typeof a<"u"&&(typeof a=="function"?e.setHeight("100%"):e.setHeight(typeof a=="number"?a*i:a)),typeof l<"u"&&e.setMinWidth(typeof l=="number"?l*i:l),typeof A<"u"&&e.setMinHeight(typeof A=="number"?A*i:A),typeof c<"u"&&e.setMaxWidth(typeof c=="number"?c*i:c),typeof u<"u"&&e.setMaxHeight(typeof u=="number"?u*i:u)}async function Cc({yoga:r,index:e,parent:t,element:i,resolvers:n}){var s,o;const{layout:a={},config:l={},options:A={},renderer:c}=i,u=r.Node.create();vc(r,u,{layout:a}),t.insertChild(u,e);let h=null;n&&((c==null?void 0:c.type)==="text"||(c==null?void 0:c.type)==="image"||(c==null?void 0:c.type)==="video")&&(h=await((s=n[c.type])==null?void 0:s.call(n,{config:l,options:A}))??null);const d=[];for await(const[f,g]of((o=i.children)==null?void 0:o.entries())??[])d.push(await Cc({yoga:r,index:f,parent:u,element:g,resolvers:n}));return{node:u,radius:kp(a.radius),element:i,renderer:c,config:l,options:A,dependencies:h,childNodes:d}}function yc(r,e,t=0,i=0){const{top:n,left:s}=r.getComputedLayout(),{top:o,left:a,width:l,height:A}=e.node.getComputedLayout(),c=t+a,u=i+o,h=e.childNodes.map(d=>yc(r,d,c,u));return{...e,x:s+c,y:n+u,width:l,height:A,childNodes:h}}async function Bc(r,e,t){for await(const{node:i,options:n,dependencies:s,renderer:o,childNodes:a}of e){if(o){const{width:l,height:A}=o;if(l){r.calculateLayout();const c=await l({node:i,options:n,dependencies:s,measureCanvas:t});i.setWidth(c)}if(A){r.calculateLayout();const c=await A({node:i,options:n,dependencies:s,measureCanvas:t});i.setHeight(c)}}r.calculateLayout(),await Bc(r,a,t)}}async function Tc({root:r,resolvers:e,measureCanvas:t}){const i=await Lp(),n=i.Node.create();vc(i,n,{layout:r.layout});const s=await Cc({yoga:i,index:0,parent:n,element:r.element,resolvers:e});await Bc(n,[s],t);const{top:o,left:a,width:l,height:A}=n.getComputedLayout(),c={root:{x:a,y:o,width:l,height:A},node:yc(n,s)};return n.freeRecursive(),c}async function Op({scene:r,start:e=0}){const{root:t,duration:i}=r,n=await Tc({root:t});return{type:r.type,start:e,duration:i,layout:n,id:r.id,config:r}}async function Up({track:r}){const e=ea(r),t=await Promise.all(r.reduce((s,o,a)=>{if(o.type!=="audio")return s;const l=xr(e.slice(0,a));return s.push(Op({scene:o,start:l})),s},[])),i=r.reduce((s,o,a)=>{if(o.type!=="gap")return s;const l=xr(e.slice(0,a));return s.push({type:o.type,id:o.id,start:l,config:o,duration:o.duration}),s},[]),n=r.map(({id:s})=>t.find(({id:o})=>o===s)??i.find(({id:o})=>o===s)).filter(Boolean);return{type:"audio",scenes:t,gapScenes:i,mergedScenes:n,config:r,duration:Math.max(...n.map(({start:s,duration:o})=>s+o))}}function Qc(){return document.createElement("canvas")}async function bc({node:r,canvases:e,sceneTime:t}){var i,n;await((n=(i=r.renderer)==null?void 0:i.render)==null?void 0:n.call(i,{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}));for await(const s of r.childNodes)await bc({node:s,canvases:e,sceneTime:t})}async function Gp({layout:r,canvases:e,sceneTime:t}){const{node:i}=r;await bc({node:i,canvases:e,sceneTime:t})}async function ta({scene:r,start:e=0,resolvers:t,rootWidth:i,rootHeight:n,canvasFactory:s=Qc}){var o,a;const{x:l,y:A,width:c,height:u,root:h,duration:d}=r,f=s(),g=s(),p=s(),v=s(),Q=s(),b=await Tc({root:{...h,layout:{...h.layout,width:i,height:n},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:Q}),y=async w=>{const R=Math.max(0,w-e);f.width=f.height=0,f.width=i,f.height=n,await Gp({layout:b,sceneTime:R,canvases:{sceneCanvas:f,cropCanvas:g,letterboxCanvas:p,posterCanvas:v}})};return{type:r.type,start:e,duration:d,layout:b,sceneCanvas:f,draw:y,id:r.id,config:r,childScenes:Ic({node:b.node,duration:d})}}async function Hp({track:r,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n}){const s=ea(r),o=await Promise.all(r.reduce((c,u,h)=>{const d=xr(s.slice(0,h));return u.type==="video"&&c.push(ta({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n})),u.type==="image"&&c.push(ta({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n})),c},[])),a=r.reduce((c,u,h)=>{if(u.type!=="gap")return c;const d=xr(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=xr(s.slice(0,h))-d;return c.push({type:u.type,id:u.id,name:u.name,start:f,duration:d,config:u,transitionCanvas:n(),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:n()}}async function $p({track:r,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n}){const s=ea(r),o=await Promise.all(r.reduce((c,u,h)=>{const d=xr(s.slice(0,h));return u.type==="text"&&c.push(ta({scene:u,start:d,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n})),c},[])),a=r.reduce((c,u,h)=>{if(u.type!=="gap")return c;const d=xr(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=xr(s.slice(0,h))-d;return c.push({type:u.type,id:u.id,name:u.name,start:f,duration:d,config:u,transitionCanvas:n(),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:n()}}function Yp(r){return r.some(({type:e})=>e==="text")}function Vp(r){return r.some(({type:e})=>e==="audio")}function Kp(r){return r.some(({type:e})=>e==="video"||e==="image")}function Wp(r){return r.type==="audio"}const Jp=(((uc=cc)==null?void 0:uc.default)??cc).reduce((r,e)=>(r[e.name]=e,r),{});function qp({name:r,to:e,from:t,progress:i,width:n,height:s,glContext:o}){var a,l,A;o.disable(o.DEPTH_TEST);const c=o.createBuffer();o.bindBuffer(o.ARRAY_BUFFER,c),o.bufferData(o.ARRAY_BUFFER,new Float32Array([-1,-1,-1,4,4,-1]),o.STATIC_DRAW),o.viewport(0,0,n,s);const u=(((a=ls)==null?void 0:a.default)??ls)(o,t);u.minFilter=o.LINEAR,u.magFilter=o.LINEAR;const h=(((l=ls)==null?void 0:l.default)??ls)(o,e);h.minFilter=o.LINEAR,h.magFilter=o.LINEAR;const d=(((A=Ac)==null?void 0:A.default)??Ac)(o,Jp[r]);d.draw(i,u,h,n,s);const f=new Uint8Array(n*s*4);return o.readPixels(0,0,n,s,o.RGBA,o.UNSIGNED_BYTE,f),u.dispose(),h.dispose(),d.dispose(),o.flush(),f}function Xp({name:r,to:e,from:t,progress:i,canvas:n}){const s=n.getContext("webgl");s&&(s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!0),qp({name:r,to:e,from:t,progress:i,width:n.width,height:n.height,glContext:s}))}async function xc({config:r,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n=Qc,drawTransition:s=Xp}){const o=await Promise.all(r.tracks.map(async l=>{if(Kp(l))return{...await Hp({track:l,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n}),config:l};if(Yp(l))return{...await $p({track:l,resolvers:e,rootWidth:t,rootHeight:i,canvasFactory:n}),config:l};if(Vp(l))return{...await Up({track:l}),config:l};throw new Error("Unknown track type")}));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 o){if(Wp(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=f.getContext("2d"),p=h.filter(({start:Q,duration:b})=>A>=Q&&A<Q+b);if(!g||p.length<=0)continue;const v=d.find(({start:Q,duration:b})=>A>=Q&&A<Q+b);for await(const{sceneCanvas:Q,draw:b}of p)await(b==null?void 0:b(A)),(!v||v&&(!v.to||!v.from))&&g.drawImage(Q,0,0,Q.width,Q.height);if(v&&v.to&&v.from){const{name:Q,to:b,from:y,duration:w,transitionCanvas:R}=v;R.width=R.height=0,R.width=f.width,R.height=f.height;const k=Math.min(1,Math.max(0,(A-b.start)/w));await s({name:Q,progress:k,to:b.sceneCanvas,from:y.sceneCanvas,canvas:R}),g.globalCompositeOperation="lighter",g.drawImage(R,0,0,R.width,R.height)}c.drawImage(f,0,0,f.width,f.height)}}},tracks:o,aspectRatio:r.aspectRatio,duration:Math.max(...o.map(({duration:l})=>l))}}const jp={name:"@vouchfor/embeds",version:"4.0.3",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:"latest",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":"^9.0.2","@vouchfor/media-player":"^5.0.3",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":"^2.0.2","@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 zp(r){const{publicApiUrl:e}=Vn(r),t=Br();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function Zp(r){var s,o,a,l,A,c,u,h,d,f,g,p;if(typeof window>"u")return{client:null,tab:null,request:Br()};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"),i=(c=(A=window.sessionStorage)==null?void 0:A.getItem)==null?void 0:c.call(A,"vouch-uid-tab");const n=Br();return e||(e=zp(r),(h=(u=window.localStorage)==null?void 0:u.setItem)==null||h.call(u,"vouch-uid-visitor",e)),t||(t=Br(),(f=(d=window.localStorage)==null?void 0:d.setItem)==null||f.call(d,"vouch-uid-client",t)),i||(i=Br(),(p=(g=window.sessionStorage)==null?void 0:g.setItem)==null||p.call(g,"vouch-uid-tab",i)),{client:t,tab:i,request:n,visitor:e}}function em(r,e){return r&&"vouchId"in r?r.vouchId:(e==null?void 0:e.id)??null}function tm(r="embedded_player"){var n,s;const[e,t]=((s=(n=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:n.split)==null?void 0:s.call(n,"/"))??[],i={};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());i[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:jp.version,templateVersion:Fp,...i}}const wc=1;class rm{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const n=em(i,this.host.vouch);!n||this.host.disableTracking||this._batchedEvents.push({event:t,payload:{...i,vouchId:n,time:new Date().toISOString()}})},this._sendTrackingEvent=()=>{if(this._batchedEvents.length<=0)return;const{publicApiUrl:t}=Vn(this.host.env),{client:i,tab:n,request:s,visitor:o}=Zp(this.host.env);navigator.sendBeacon(`${t}/api/batchevents`,JSON.stringify({payload:{events:this._batchedEvents},context:{"x-uid-client":i,"x-uid-tab":n,"x-uid-request":s,"x-uid-visitor":o,"x-reporting-metadata":tm(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+wc&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]}},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:i}})=>{this._answersViewed[i]||(this._createTrackingEvent("VOUCH_RESPONSE_VIEWED",{answerId:t}),this._answersViewed[i]=!0)},this._handleVideoTimeUpdate=({detail:{id:t,key:i,node:n}})=>{this.host.paused||(this._currentlyPlayingVideo={id:t,key:i,node:n},this._streamLatestTime[i]=n.currentTime,this._streamStartTime[i]||(this._streamStartTime[i]=n.currentTime,this._streamLatestTime[i]=n.currentTime))},this._handleVideoPause=({detail:{id:t,key:i}})=>{this._streamLatestTime[i]>this._streamStartTime[i]+wc&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:t,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]},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,i,n;"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),(i=this.host.mediaPlayer)==null||i.addEventListener("video:pause",this._handleVideoPause),(n=this.host.mediaPlayer)==null||n.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var e,t,i,n;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),(i=this.host.mediaPlayer)==null||i.removeEventListener("video:pause",this._handleVideoPause),(n=this.host.mediaPlayer)==null||n.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}var ra={exports:{}};(function(r,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof Ci<"u"&&Ci,i=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 v(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=v(O);return O.readAsArrayBuffer(D),X}function b(D){var O=new FileReader,X=v(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 w(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=w(D.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):l.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(D)||u(D))?this._bodyArrayBuffer=w(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 $(D){var O=D.toUpperCase();return k.indexOf(O)>-1?O:D}function W(D,O){if(!(this instanceof W))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 W){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=$(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()}}}W.prototype.clone=function(){return new W(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 J(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 K=S.join(":").trim();O.append(F,K)}}),O}R.call(W.prototype);function ie(D,O){if(!(this instanceof ie))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(ie.prototype),ie.prototype.clone=function(){return new ie(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new g(this.headers),url:this.url})},ie.error=function(){var D=new ie(null,{status:0,statusText:""});return D.type="error",D};var ee=[301,302,303,307,308];ie.redirect=function(D,O){if(ee.indexOf(O)===-1)throw new RangeError("Invalid status code");return new ie(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 W(D,O);if(S.signal&&S.signal.aborted)return _(new o.DOMException("Aborted","AbortError"));var F=new XMLHttpRequest;function K(){F.abort()}F.onload=function(){var ne={status:F.status,statusText:F.statusText,headers:J(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 ie(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",K),F.onreadystatechange=function(){F.readyState===4&&S.signal.removeEventListener("abort",K)}),F.send(typeof S._bodyInit>"u"?null:S._bodyInit)})}return le.polyfill=!0,a.fetch||(a.fetch=le,a.Headers=g,a.Request=W,a.Response=ie),o.Headers=g,o.Request=W,o.Response=ie,o.fetch=le,o})({})})(i),i.fetch.ponyfill=!0,delete i.fetch.polyfill;var n=t.fetch?t:i;e=n.fetch,e.default=n.fetch,e.fetch=n.fetch,e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response,r.exports=e})(ra,ra.exports);var im=ra.exports;const Sc=Co(im);async function nm(r){var e;try{if((e=await Sc(r,{method:"HEAD"}))!=null&&e.ok)return r}catch{return}}async function ia({sources:r}){let e=null;const t=r==null?void 0:r.filter(Boolean),i=t==null?void 0:t.find(s=>s.startsWith("blob:")),n=t==null?void 0:t.find(s=>!s.startsWith("http")&&!s.startsWith("blob:"));if(i||n)return i??n;if(t.length>0){const s=t.map(o=>nm(o));e=(await Promise.all(s)).find(Boolean)}return e}async function sm(r){try{return(await Sc(r)).text()}catch{return null}}async function om(r){return r=r.trim(),r.startsWith("http")||r.startsWith("blob:")?sm(r):r}const am=ti(async({original:r,translation:e,originalLanguage:t="",translationLanguage:i=""},{language:n})=>{var s,o;const a={[(s=i==null?void 0:i.split("-"))==null?void 0:s[0]]:e,[(o=t==null?void 0:t.split("-"))==null?void 0:o[0]]:r},l=(n&&a[n])??r;return l?om(l):null},{cacheKey:([r,{language:e}])=>JSON.stringify({...r,language:e})});function lm(r){var e;return((e=r==null?void 0:r.items)==null?void 0:e.map(t=>{var i;return{text:(i=t.alternatives[0])==null?void 0:i.content,start:t.start_time,end:t.end_time}}))??[]}const Am=ti(async r=>{var e,t,i,n,s,o,a,l,A,c,u;const[h,d,f]=await Promise.all([ia({sources:[(t=(e=r==null?void 0:r.answer)==null?void 0:e.media)==null?void 0:t.video,(n=(i=r==null?void 0:r.answer)==null?void 0:i.media)==null?void 0:n.input]}),ia({sources:[(o=(s=r==null?void 0:r.answer)==null?void 0:s.media)==null?void 0:o.playlist]}),ia({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,i,n,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:(n=(i=r==null?void 0:r.answer)==null?void 0:i.media)==null?void 0:n.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 Rc(r){var e,t,i,n,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=(n=(i=r==null?void 0:r.answer)==null?void 0:i.contact)==null?void 0:n.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 cm=ti(async(r,e,t)=>{var i,n,s;const o=(i=e==null?void 0:e.answer)==null?void 0:i.id;return((s=(n=r==null?void 0:r.questions)==null?void 0:n.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 i;return JSON.stringify({index:t,rootData:e,allQuestions:(i=r==null?void 0:r.questions)==null?void 0:i.items})}});async function na({data:r,rootData:e,index:t},i){var n,s,o,a,l,A,c,u,h,d,f,g,p,v,Q,b,y,w,R,k,$,W,P,J;const[ie,ee,le]=await Promise.all([cm(r,e,t),Am(e),am({original:((s=(n=e==null?void 0:e.answer)==null?void 0:n.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},i)]),D=Rc(e);return{...ee,...D,key:ie,captions:le,wordTimings:lm((v=e==null?void 0:e.answer)==null?void 0:v.transcription),answerLabel:((Q=e==null?void 0:e.answer)==null?void 0:Q.label)??(e==null?void 0:e.title),prevAnswerLabel:t?((R=(w=(y=(b=r==null?void 0:r.questions)==null?void 0:b.items)==null?void 0:y[t-1])==null?void 0:w.answer)==null?void 0:R.label)??((W=($=(k=r==null?void 0:r.questions)==null?void 0:k.items)==null?void 0:$[t-1])==null?void 0:W.title)??null:null,isFirstInstanceOfName:t?((J=(P=r==null?void 0:r.questions)==null?void 0:P.items)==null?void 0:J.findIndex(O=>Rc(O).name===D.name))===t:!0}}const fs={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 um({data:r}){var e,t;return((t=(e=r==null?void 0:r.questions)==null?void 0:e.items)==null?void 0:t.reduce((i,n)=>{var s,o,a,l,A,c,u;const h=(a=(o=(s=n==null?void 0:n.answer)==null?void 0:s.transcription)==null?void 0:o.language)==null?void 0:a.split("-")[0],d=(u=(c=(A=(l=n==null?void 0:n.answer)==null?void 0:l.transcription)==null?void 0:A.translation)==null?void 0:c.language)==null?void 0:u.split("-")[0];return h&&fs[h]&&!i.find(f=>f.value===h)&&i.push({value:h,label:fs[h]}),d&&fs[d]&&!i.find(f=>f.value===d)&&i.push({value:d,label:fs[d]}),i},[]))??[]}/**
2456
2456
  * @license
2457
2457
  * Copyright 2018 Google LLC