@vouchfor/embeds 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -149,8 +149,8 @@ ${e}`,Lg=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),_g=Objec
149
149
  "playlist": {{ it._derived?.playlist }},
150
150
  "preview": {{ it._derived?.preview }},
151
151
  "captions": {{ it._derived?.captions }}
152
- }`}],root:"{{ it.outro?.questions?.items }}"}],system:!0}],meta:{frameRate:30,resolution:1080,transitionDuration:1/3},options:{videoFormat:"letterbox-video"},default:0,system:!0};async function sf(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Gu);return new s.Image}return new Image}const bl=Ut(async function(e){return e?new Promise((t,i)=>{sf().then(r=>{r.onload=()=>{t(r)},r.onerror=n=>{i(n)},r.src=e})}):null});async function Bo({element:s,meta:e},t,i){var r,n,o;let a={...s};const{node:A}=s;if((A==null?void 0:A.type)==="video"&&((r=A==null?void 0:A.value)!=null&&r.src||(n=A==null?void 0:A.value)!=null&&n.playlist)){const l=await t(A.value,e);let c;try{c=await bl(A.value.poster)}catch{c=null}a={...a,node:{...A,video:l,poster:c,meta:await i(A.value,l.node,e)}}}if((A==null?void 0:A.type)==="image"&&A.value){let l;try{l=await bl(A.value)}catch{l=null}a={...a,node:{...A,image:l}}}return a.node&&((o=s.node)!=null&&o.elements)&&(a.node.elements=await Promise.all(s.node.elements.map(l=>Bo({element:l,meta:e},t,i)))),s.elements&&(a.elements=await Promise.all(s.elements.map(l=>Bo({element:l,meta:e},t,i)))),a}async function Jr(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Gu),e=new s.Canvas;return e.gpu=!1,e}return document.createElement("canvas")}function zs(s=[]){var e;for(const t of s){if(((e=t==null?void 0:t.node)==null?void 0:e.type)==="video")return t.node;const i=zs(t==null?void 0:t.elements);if(i)return i}}function rf(s,e){return s.reduce((t,i,r)=>[...t,i.map((n,o)=>n.map(({duration:a},A)=>r===s.length-1&&o===i.length-1&&A===n.length-1?a:a-e))],[])}function nf(s){if(s===null||typeof s!="object")return!1;if(Object.getPrototypeOf(s)===null)return!0;let e=s;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(s)===e}function of(s){return s.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\f/g,"\\f").replace(/"/g,'\\"')}function Wr(s){return s.flatMap(e=>Array.isArray(e)?e.flatMap(t=>t):e).reduce((e,t)=>e+t,0)}const af=Ut(()=>Al.loadYoga());uo.filters.define("parse",s=>typeof s>"u"?null:typeof s=="string"?`"${of(s)}"`:nf(s)||Array.isArray(s)?JSON.stringify(s):s);const As=(s,e,t)=>uo.render(s,e,uo.getConfig({autoEscape:!1,defaultFilter:"parse",...t}));async function ls({data:s,template:e,burnCaptions:t=!1,debug:i=!1},r,n,o){var a,A,l,c;const h=await af(),u=e??tf;if(!((a=u.templates)!=null&&a.length))throw new Error(`No templates found for template instance: ${u.id}`);let d=u.templates.find(({version:k})=>k===Qo);if(!d){const k=u.templates.map(({version:M})=>`"${M}"`).join(", ");console.warn(`Template renderer expects template version "${Qo}" but got ${k}`),d=u.templates[u.templates.length-1]}const g=await Promise.all(d.content.map(async({scenes:k,root:M})=>{const q={...u.options,...s,intro:u.intro,outro:u.outro};async function V(X,R){return Promise.all(k.map(async({layout:x,duration:G,data:b,derived:w,options:T})=>{var Y,U,W;const se={...q,_index:R,_root:X,_derived:await r({data:s,rootData:X,index:R})},ce=b?JSON.parse(await As(b,se)):{},ne=w?JSON.parse(await As(w,se)):{},me=T?JSON.parse(await As(T,se)):{},Se=G?parseFloat(await As(G,se)):NaN,we=(Y=d.layouts.find(ge=>ge.name===x))==null?void 0:Y.tree;if(!we)throw new Error(`Layout tree "${x}" not found in template "${d.id}" layouts.`);const oe=JSON.parse(await As(we,{...ce,...ne,...me})),de=await Promise.all(oe.flatMap(ge=>Bo({element:ge,meta:u.meta},n,o))),Be=zs(de);return{duration:(isNaN(Se)?null:Se)??((U=Be==null?void 0:Be.meta)==null?void 0:U.duration)??0,captions:(W=Be==null?void 0:Be.meta)==null?void 0:W.captions,elements:de}}))}if(M){const X=JSON.parse(await As(M,q));return Array.isArray(X)?Promise.all(X.map(async(R,x)=>V(R,x))):Promise.all([V(X,null)])}return Promise.all([V(s,null)])}));if(g.every(k=>k.every(M=>M.every(q=>{const V=zs(q.elements);return!(V!=null&&V.value.src)&&!(V!=null&&V.value.playlist)})))){const k=g.flatMap(M=>M.flatMap(q=>q.map(V=>{const X=zs(V.elements);return!(X!=null&&X.value.src)&&!(X!=null&&X.value.playlist)&&(X==null?void 0:X.value.id)}).filter(Boolean))).join(", ");throw new Error(`Video(s) with ID ${k} failed to load, video can not be processed`)}if(g.every(k=>k.every(M=>M.every(q=>q.duration<=0))))throw new Error("No scenes have any duration, video can not be processed");const v=g.reduce((k,M)=>{const q=M.reduce((V,X)=>{const R=X.filter(x=>x.duration>0);return R.length>0?[...V,R]:V},[]);return q.length>0?[...k,q]:k},[]),y=((A=u.meta)==null?void 0:A.frameRate)??30,S=((l=u.meta)==null?void 0:l.resolution)??1080,C=((c=u.meta)==null?void 0:c.transitionDuration)??1/3,Q=rf(v,C),B=Wr(Q),L=await Promise.all(v.map((k,M)=>{const q=Wr(Q[M]),V=Wr(Q.slice(0,M));return Promise.all(k.map((X,R)=>Promise.all(X.map(async({duration:x,captions:G,elements:b},w)=>{var T,Y;const U=await Jr(),W=await Jr(),se=await Jr(),ce=await Jr(),ne=zs(b),me=Wr([...Q.slice(0,M),...Q[M].slice(0,R),...Q[M][R].slice(0,w)]);return{draw:({canvas:we,currentTime:oe})=>{const de=Math.max(0,oe-V),Be=Math.max(0,oe-me);yo({yoga:h,debug:i,canvas:we,cropCanvas:U,posterCanvas:ce,letterboxCanvas:W,elements:b,currentTime:oe,contentTime:de,sceneTime:Be,totalDuration:B,contentDuration:q,sceneDuration:x}),G&&t&&jg({canvas:we,dx:0,dy:0,dw:we.width,dh:we.height,vttCaptions:G,sceneTime:Be+((ne==null?void 0:ne.meta.start)??0)})},duration:x,transitionCanvas:se,id:ef(),start:me,video:ne==null?void 0:ne.video,videoMeta:ne==null?void 0:ne.meta,audio:{duration:x,src:(T=ne==null?void 0:ne.value)==null?void 0:T.src,start:(Y=ne==null?void 0:ne.meta)==null?void 0:Y.start}}}))))})),_=L.flatMap(k=>k);return{scenes:_.flatMap(k=>k),sections:_,contents:L,frameRate:y,resolution:S,transitionDuration:C,fonts:d.fonts??[],duration:B}}const Qo="3",Af={name:"@vouchfor/embeds",version:"3.2.0",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":"^8.2.2","@vouchfor/media-player":"^4.2.0",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":"^1.4.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 lf(s){const{publicApiUrl:e}=br(s),t=Gi();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function cf(s){var n,o,a,A,l,c,h,u,d,g,f,p;if(typeof window>"u")return{client:null,tab:null,request:Gi()};let e=(o=(n=window.localStorage)==null?void 0:n.getItem)==null?void 0:o.call(n,"vouch-uid-visitor"),t=(A=(a=window.localStorage)==null?void 0:a.getItem)==null?void 0:A.call(a,"vouch-uid-client"),i=(c=(l=window.sessionStorage)==null?void 0:l.getItem)==null?void 0:c.call(l,"vouch-uid-tab");const r=Gi();return e||(e=lf(s),(u=(h=window.localStorage)==null?void 0:h.setItem)==null||u.call(h,"vouch-uid-visitor",e)),t||(t=Gi(),(g=(d=window.localStorage)==null?void 0:d.setItem)==null||g.call(d,"vouch-uid-client",t)),i||(i=Gi(),(p=(f=window.sessionStorage)==null?void 0:f.setItem)==null||p.call(f,"vouch-uid-tab",i)),{client:t,tab:i,request:r,visitor:e}}function hf(s,e){return s&&"vouchId"in s?s.vouchId:(e==null?void 0:e.id)??null}function uf(s="embedded_player"){var r,n;const[e,t]=((n=(r=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:r.split)==null?void 0:n.call(r,"/"))??[],i={};return[...new URLSearchParams(location.search).entries()].forEach(([o,a])=>{if(/utm/.test(o)){const A=o.toLowerCase().replace(/[-_][a-z0-9]/g,l=>l.slice(-1).toUpperCase());i[A]=a}}),{source:s,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:Af.version,templateVersion:Qo,...i}}const wl=1;class df{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const r=hf(i,this.host.vouch);!r||this.host.disableTracking||this._batchedEvents.push({event:t,payload:{...i,vouchId:r,time:new Date().toISOString()}})},this._sendTrackingEvent=()=>{if(this._batchedEvents.length<=0)return;const{publicApiUrl:t}=br(this.host.env),{client:i,tab:r,request:n,visitor:o}=cf(this.host.env);navigator.sendBeacon(`${t}/api/batchevents`,JSON.stringify({payload:{events:this._batchedEvents},context:{"x-uid-client":i,"x-uid-tab":r,"x-uid-request":n,"x-uid-visitor":o,"x-reporting-metadata":uf(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+wl&&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:r}})=>{var n,o;!this.host.paused&&t===((o=(n=this.host.scene)==null?void 0:n.video)==null?void 0:o.id)&&(this._currentlyPlayingVideo={id:t,key:i,node:r},this._streamLatestTime[i]=r.currentTime,this._streamStartTime[i]||(this._streamStartTime[i]=r.currentTime,this._streamLatestTime[i]=r.currentTime))},this._handleVideoPause=({detail:{id:t,key:i}})=>{this._streamLatestTime[i]>this._streamStartTime[i]+wl&&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,r;"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),(r=this.host.mediaPlayer)==null||r.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var e,t,i,r;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),(r=this.host.mediaPlayer)==null||r.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}var So={exports:{}};(function(s,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof Lr<"u"&&Lr,i=function(){function n(){this.fetch=!1,this.DOMException=t.DOMException}return n.prototype=t,new n}();(function(n){(function(o){var a=typeof n<"u"&&n||typeof self<"u"&&self||typeof a<"u"&&a,A={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 l(R){return R&&DataView.prototype.isPrototypeOf(R)}if(A.arrayBuffer)var c=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],h=ArrayBuffer.isView||function(R){return R&&c.indexOf(Object.prototype.toString.call(R))>-1};function u(R){if(typeof R!="string"&&(R=String(R)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(R)||R==="")throw new TypeError('Invalid character in header field name: "'+R+'"');return R.toLowerCase()}function d(R){return typeof R!="string"&&(R=String(R)),R}function g(R){var x={next:function(){var G=R.shift();return{done:G===void 0,value:G}}};return A.iterable&&(x[Symbol.iterator]=function(){return x}),x}function f(R){this.map={},R instanceof f?R.forEach(function(x,G){this.append(G,x)},this):Array.isArray(R)?R.forEach(function(x){this.append(x[0],x[1])},this):R&&Object.getOwnPropertyNames(R).forEach(function(x){this.append(x,R[x])},this)}f.prototype.append=function(R,x){R=u(R),x=d(x);var G=this.map[R];this.map[R]=G?G+", "+x:x},f.prototype.delete=function(R){delete this.map[u(R)]},f.prototype.get=function(R){return R=u(R),this.has(R)?this.map[R]:null},f.prototype.has=function(R){return this.map.hasOwnProperty(u(R))},f.prototype.set=function(R,x){this.map[u(R)]=d(x)},f.prototype.forEach=function(R,x){for(var G in this.map)this.map.hasOwnProperty(G)&&R.call(x,this.map[G],G,this)},f.prototype.keys=function(){var R=[];return this.forEach(function(x,G){R.push(G)}),g(R)},f.prototype.values=function(){var R=[];return this.forEach(function(x){R.push(x)}),g(R)},f.prototype.entries=function(){var R=[];return this.forEach(function(x,G){R.push([G,x])}),g(R)},A.iterable&&(f.prototype[Symbol.iterator]=f.prototype.entries);function p(R){if(R.bodyUsed)return Promise.reject(new TypeError("Already read"));R.bodyUsed=!0}function v(R){return new Promise(function(x,G){R.onload=function(){x(R.result)},R.onerror=function(){G(R.error)}})}function y(R){var x=new FileReader,G=v(x);return x.readAsArrayBuffer(R),G}function S(R){var x=new FileReader,G=v(x);return x.readAsText(R),G}function C(R){for(var x=new Uint8Array(R),G=new Array(x.length),b=0;b<x.length;b++)G[b]=String.fromCharCode(x[b]);return G.join("")}function Q(R){if(R.slice)return R.slice(0);var x=new Uint8Array(R.byteLength);return x.set(new Uint8Array(R)),x.buffer}function B(){return this.bodyUsed=!1,this._initBody=function(R){this.bodyUsed=this.bodyUsed,this._bodyInit=R,R?typeof R=="string"?this._bodyText=R:A.blob&&Blob.prototype.isPrototypeOf(R)?this._bodyBlob=R:A.formData&&FormData.prototype.isPrototypeOf(R)?this._bodyFormData=R:A.searchParams&&URLSearchParams.prototype.isPrototypeOf(R)?this._bodyText=R.toString():A.arrayBuffer&&A.blob&&l(R)?(this._bodyArrayBuffer=Q(R.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):A.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(R)||h(R))?this._bodyArrayBuffer=Q(R):this._bodyText=R=Object.prototype.toString.call(R):this._bodyText="",this.headers.get("content-type")||(typeof R=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):A.searchParams&&URLSearchParams.prototype.isPrototypeOf(R)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},A.blob&&(this.blob=function(){var R=p(this);if(R)return R;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 R=p(this);return R||(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(y)}),this.text=function(){var R=p(this);if(R)return R;if(this._bodyBlob)return S(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(C(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},A.formData&&(this.formData=function(){return this.text().then(k)}),this.json=function(){return this.text().then(JSON.parse)},this}var L=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function _(R){var x=R.toUpperCase();return L.indexOf(x)>-1?x:R}function $(R,x){if(!(this instanceof $))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');x=x||{};var G=x.body;if(R instanceof $){if(R.bodyUsed)throw new TypeError("Already read");this.url=R.url,this.credentials=R.credentials,x.headers||(this.headers=new f(R.headers)),this.method=R.method,this.mode=R.mode,this.signal=R.signal,!G&&R._bodyInit!=null&&(G=R._bodyInit,R.bodyUsed=!0)}else this.url=String(R);if(this.credentials=x.credentials||this.credentials||"same-origin",(x.headers||!this.headers)&&(this.headers=new f(x.headers)),this.method=_(x.method||this.method||"GET"),this.mode=x.mode||this.mode||null,this.signal=x.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&G)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(G),(this.method==="GET"||this.method==="HEAD")&&(x.cache==="no-store"||x.cache==="no-cache")){var b=/([?&])_=[^&]*/;if(b.test(this.url))this.url=this.url.replace(b,"$1_="+new Date().getTime());else{var w=/\?/;this.url+=(w.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}$.prototype.clone=function(){return new $(this,{body:this._bodyInit})};function k(R){var x=new FormData;return R.trim().split("&").forEach(function(G){if(G){var b=G.split("="),w=b.shift().replace(/\+/g," "),T=b.join("=").replace(/\+/g," ");x.append(decodeURIComponent(w),decodeURIComponent(T))}}),x}function M(R){var x=new f,G=R.replace(/\r?\n[\t ]+/g," ");return G.split("\r").map(function(b){return b.indexOf(`
153
- `)===0?b.substr(1,b.length):b}).forEach(function(b){var w=b.split(":"),T=w.shift().trim();if(T){var Y=w.join(":").trim();x.append(T,Y)}}),x}B.call($.prototype);function q(R,x){if(!(this instanceof q))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');x||(x={}),this.type="default",this.status=x.status===void 0?200:x.status,this.ok=this.status>=200&&this.status<300,this.statusText=x.statusText===void 0?"":""+x.statusText,this.headers=new f(x.headers),this.url=x.url||"",this._initBody(R)}B.call(q.prototype),q.prototype.clone=function(){return new q(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},q.error=function(){var R=new q(null,{status:0,statusText:""});return R.type="error",R};var V=[301,302,303,307,308];q.redirect=function(R,x){if(V.indexOf(x)===-1)throw new RangeError("Invalid status code");return new q(null,{status:x,headers:{location:R}})},o.DOMException=a.DOMException;try{new o.DOMException}catch{o.DOMException=function(x,G){this.message=x,this.name=G;var b=Error(x);this.stack=b.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function X(R,x){return new Promise(function(G,b){var w=new $(R,x);if(w.signal&&w.signal.aborted)return b(new o.DOMException("Aborted","AbortError"));var T=new XMLHttpRequest;function Y(){T.abort()}T.onload=function(){var W={status:T.status,statusText:T.statusText,headers:M(T.getAllResponseHeaders()||"")};W.url="responseURL"in T?T.responseURL:W.headers.get("X-Request-URL");var se="response"in T?T.response:T.responseText;setTimeout(function(){G(new q(se,W))},0)},T.onerror=function(){setTimeout(function(){b(new TypeError("Network request failed"))},0)},T.ontimeout=function(){setTimeout(function(){b(new TypeError("Network request failed"))},0)},T.onabort=function(){setTimeout(function(){b(new o.DOMException("Aborted","AbortError"))},0)};function U(W){try{return W===""&&a.location.href?a.location.href:W}catch{return W}}T.open(w.method,U(w.url),!0),w.credentials==="include"?T.withCredentials=!0:w.credentials==="omit"&&(T.withCredentials=!1),"responseType"in T&&(A.blob?T.responseType="blob":A.arrayBuffer&&w.headers.get("Content-Type")&&w.headers.get("Content-Type").indexOf("application/octet-stream")!==-1&&(T.responseType="arraybuffer")),x&&typeof x.headers=="object"&&!(x.headers instanceof f)?Object.getOwnPropertyNames(x.headers).forEach(function(W){T.setRequestHeader(W,d(x.headers[W]))}):w.headers.forEach(function(W,se){T.setRequestHeader(se,W)}),w.signal&&(w.signal.addEventListener("abort",Y),T.onreadystatechange=function(){T.readyState===4&&w.signal.removeEventListener("abort",Y)}),T.send(typeof w._bodyInit>"u"?null:w._bodyInit)})}return X.polyfill=!0,a.fetch||(a.fetch=X,a.Headers=f,a.Request=$,a.Response=q),o.Headers=f,o.Request=$,o.Response=q,o.fetch=X,o})({})})(i),i.fetch.ponyfill=!0,delete i.fetch.polyfill;var r=t.fetch?t:i;e=r.fetch,e.default=r.fetch,e.fetch=r.fetch,e.Headers=r.Headers,e.Request=r.Request,e.Response=r.Response,s.exports=e})(So,So.exports);var gf=So.exports;const Rl=al(gf);async function ff(s){var e;try{if((e=await Rl(s,{method:"HEAD"}))!=null&&e.ok)return s}catch{return}}async function bo({sources:s}){let e=null;const t=s==null?void 0:s.filter(Boolean),i=t==null?void 0:t.find(n=>n.startsWith("blob:")),r=t==null?void 0:t.find(n=>!n.startsWith("http")&&!n.startsWith("blob:"));if(i||r)return i??r;if(t.length>0){const n=t.map(o=>ff(o));e=(await Promise.all(n)).find(Boolean)}return e}async function pf(s){try{return(await Rl(s)).text()}catch{return null}}async function Ef(s){return s=s.trim(),s.startsWith("http")||s.startsWith("blob:")?pf(s):s}const If=Ut(async({original:s,translation:e,originalLanguage:t="",translationLanguage:i=""},{language:r})=>{var n,o;const a={[(n=i==null?void 0:i.split("-"))==null?void 0:n[0]]:e,[(o=t==null?void 0:t.split("-"))==null?void 0:o[0]]:s},A=(r&&a[r])??s;return A?Ef(A):null},{cacheKey:([s,{language:e}])=>JSON.stringify({...s,language:e})}),mf=Ut(async s=>{var e,t,i,r,n,o,a,A,l,c,h;const[u,d,g]=await Promise.all([bo({sources:[(t=(e=s==null?void 0:s.answer)==null?void 0:e.media)==null?void 0:t.video,(r=(i=s==null?void 0:s.answer)==null?void 0:i.media)==null?void 0:r.input]}),bo({sources:[(o=(n=s==null?void 0:s.answer)==null?void 0:n.media)==null?void 0:o.playlist]}),bo({sources:[((A=(a=s==null?void 0:s.answer)==null?void 0:a.media)==null?void 0:A.reducedQuality)??((h=(c=(l=s==null?void 0:s.answer)==null?void 0:l.media)==null?void 0:c.videos)==null?void 0:h.xs)]})]);return{src:u,playlist:d,preview:g}},{cacheKey:([s])=>{var e,t,i,r,n,o,a,A,l,c,h;return JSON.stringify({video:(t=(e=s==null?void 0:s.answer)==null?void 0:e.media)==null?void 0:t.video,input:(r=(i=s==null?void 0:s.answer)==null?void 0:i.media)==null?void 0:r.input,playlist:(o=(n=s==null?void 0:s.answer)==null?void 0:n.media)==null?void 0:o.playlist,preview:((A=(a=s==null?void 0:s.answer)==null?void 0:a.media)==null?void 0:A.reducedQuality)??((h=(c=(l=s==null?void 0:s.answer)==null?void 0:l.media)==null?void 0:c.videos)==null?void 0:h.xs)})}});function xl(s){var e,t,i,r,n,o,a,A,l,c,h,u;const d=((t=(e=s==null?void 0:s.answer)==null?void 0:e.contact)==null?void 0:t.name)==="Anonymous"?"":((n=(r=(i=s==null?void 0:s.answer)==null?void 0:i.contact)==null?void 0:r.name)==null?void 0:n.trim())??"",g=((A=(a=(o=s==null?void 0:s.answer)==null?void 0:o.contact)==null?void 0:a.client)==null?void 0:A.name)==="Not Supplied"?"":((u=(h=(c=(l=s==null?void 0:s.answer)==null?void 0:l.contact)==null?void 0:c.client)==null?void 0:h.name)==null?void 0:u.trim())??"",[f,p]=d.split(" ");return{name:d,firstName:f,lastName:p,companyName:g}}const Cf=Ut(async(s,e,t)=>{var i,r,n;const o=(i=e==null?void 0:e.answer)==null?void 0:i.id;return((n=(r=s==null?void 0:s.questions)==null?void 0:r.items)==null?void 0:n.reduce((A,l)=>{var c;return((c=l==null?void 0:l.answer)==null?void 0:c.id)===o?(A??0)+1:A},0))<=1?o:`${o}-${t}`},{cacheKey:([s,e,t])=>{var i;return JSON.stringify({index:t,rootData:e,allQuestions:(i=s==null?void 0:s.questions)==null?void 0:i.items})}});async function wo({data:s,rootData:e,index:t},i){var r,n,o,a,A,l,c,h,u,d,g,f,p,v,y,S,C,Q,B,L,_,$,k,M;const[q,V,X]=await Promise.all([Cf(s,e,t),mf(e),If({original:((n=(r=e==null?void 0:e.answer)==null?void 0:r.media)==null?void 0:n.captions)??((a=(o=e==null?void 0:e.answer)==null?void 0:o.captions)==null?void 0:a.current),translation:((l=(A=e==null?void 0:e.answer)==null?void 0:A.media)==null?void 0:l.translation)??((h=(c=e==null?void 0:e.answer)==null?void 0:c.captions)==null?void 0:h.translation),originalLanguage:(d=(u=e==null?void 0:e.answer)==null?void 0:u.transcription)==null?void 0:d.language,translationLanguage:(p=(f=(g=e==null?void 0:e.answer)==null?void 0:g.transcription)==null?void 0:f.translation)==null?void 0:p.language},i)]),R=xl(e);return{...V,...R,key:q,captions:X,answerLabel:((v=e==null?void 0:e.answer)==null?void 0:v.label)??(e==null?void 0:e.title),prevAnswerLabel:t?((Q=(C=(S=(y=s==null?void 0:s.questions)==null?void 0:y.items)==null?void 0:S[t-1])==null?void 0:C.answer)==null?void 0:Q.label)??((_=(L=(B=s==null?void 0:s.questions)==null?void 0:B.items)==null?void 0:L[t-1])==null?void 0:_.title)??null:null,isFirstInstanceOfName:t?((M=(k=($=s==null?void 0:s.questions)==null?void 0:$.items)==null?void 0:k.map(x=>xl(x)))==null?void 0:M.indexOf(x=>x.name===R.name))===t:!0}}const qr={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 vf({data:s}){var e,t;return((t=(e=s==null?void 0:s.questions)==null?void 0:e.items)==null?void 0:t.reduce((i,r)=>{var n,o,a,A,l,c,h;const u=(a=(o=(n=r==null?void 0:r.answer)==null?void 0:n.transcription)==null?void 0:o.language)==null?void 0:a.split("-")[0],d=(h=(c=(l=(A=r==null?void 0:r.answer)==null?void 0:A.transcription)==null?void 0:l.translation)==null?void 0:c.language)==null?void 0:h.split("-")[0];return u&&qr[u]&&!i.find(g=>g.value===u)&&i.push({value:u,label:qr[u]}),d&&qr[d]&&!i.find(g=>g.value===d)&&i.push({value:d,label:qr[d]}),i},[]))??[]}/**
152
+ }`}],root:"{{ it.outro?.questions?.items }}"}],system:!0}],meta:{frameRate:30,resolution:1080,transitionDuration:1/3},options:{videoFormat:"letterbox-video"},default:0,system:!0};async function sf(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Gu);return new s.Image}return new Image}const bl=Ut(async function(e){return e?new Promise((t,i)=>{sf().then(r=>{r.onload=()=>{t(r)},r.onerror=n=>{i(n)},r.src=e})}):null});async function Bo({element:s,meta:e},t,i){var r,n,o;let a={...s};const{node:A}=s;if((A==null?void 0:A.type)==="video"&&((r=A==null?void 0:A.value)!=null&&r.src||(n=A==null?void 0:A.value)!=null&&n.playlist)){const l=await t(A.value,e);let c;try{c=await bl(A.value.poster)}catch{c=null}a={...a,node:{...A,video:l,poster:c,meta:await i(A.value,l.node,e)}}}if((A==null?void 0:A.type)==="image"&&A.value){let l;try{l=await bl(A.value)}catch{l=null}a={...a,node:{...A,image:l}}}return a.node&&((o=s.node)!=null&&o.elements)&&(a.node.elements=await Promise.all(s.node.elements.map(l=>Bo({element:l,meta:e},t,i)))),s.elements&&(a.elements=await Promise.all(s.elements.map(l=>Bo({element:l,meta:e},t,i)))),a}async function Jr(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Gu),e=new s.Canvas;return e.gpu=!1,e}return document.createElement("canvas")}function zs(s=[]){var e;for(const t of s){if(((e=t==null?void 0:t.node)==null?void 0:e.type)==="video")return t.node;const i=zs(t==null?void 0:t.elements);if(i)return i}}function rf(s,e){return s.reduce((t,i,r)=>[...t,i.map((n,o)=>n.map(({duration:a},A)=>r===s.length-1&&o===i.length-1&&A===n.length-1?a:a-e))],[])}function nf(s){if(s===null||typeof s!="object")return!1;if(Object.getPrototypeOf(s)===null)return!0;let e=s;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(s)===e}function of(s){return s.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\f/g,"\\f").replace(/"/g,'\\"')}function Wr(s){return s.flatMap(e=>Array.isArray(e)?e.flatMap(t=>t):e).reduce((e,t)=>e+t,0)}const af=Ut(()=>Al.loadYoga());uo.filters.define("parse",s=>typeof s>"u"?null:typeof s=="string"?`"${of(s)}"`:nf(s)||Array.isArray(s)?JSON.stringify(s):s);const As=(s,e,t)=>uo.render(s,e,uo.getConfig({autoEscape:!1,defaultFilter:"parse",...t}));async function ls({data:s,template:e,burnCaptions:t=!1,debug:i=!1},r,n,o){var a,A,l,c;const h=await af(),u=e??tf;if(!((a=u.templates)!=null&&a.length))throw new Error(`No templates found for template instance: ${u.id}`);let d=u.templates.find(({version:k})=>k===Qo);if(!d){const k=u.templates.map(({version:M})=>`"${M}"`).join(", ");console.warn(`Template renderer expects template version "${Qo}" but got ${k}`),d=u.templates[u.templates.length-1]}const g=await Promise.all(d.content.map(async({scenes:k,root:M})=>{const q={...u.options,...s,intro:u.intro,outro:u.outro};async function V(X,R){return Promise.all(k.map(async({layout:x,duration:G,data:b,derived:w,options:T})=>{var Y,U,W;const se={...q,_index:R,_root:X,_derived:await r({data:s,rootData:X,index:R})},ce=b?JSON.parse(await As(b,se)):{},ne=w?JSON.parse(await As(w,se)):{},me=T?JSON.parse(await As(T,se)):{},Se=G?parseFloat(await As(G,se)):NaN,we=(Y=d.layouts.find(ge=>ge.name===x))==null?void 0:Y.tree;if(!we)throw new Error(`Layout tree "${x}" not found in template "${d.id}" layouts.`);const oe=JSON.parse(await As(we,{...ce,...ne,...me})),de=await Promise.all(oe.flatMap(ge=>Bo({element:ge,meta:u.meta},n,o))),Be=zs(de);return{duration:(isNaN(Se)?null:Se)??((U=Be==null?void 0:Be.meta)==null?void 0:U.duration)??0,captions:(W=Be==null?void 0:Be.meta)==null?void 0:W.captions,elements:de}}))}if(M){const X=JSON.parse(await As(M,q));return Array.isArray(X)?Promise.all(X.map(async(R,x)=>V(R,x))):Promise.all([V(X,null)])}return Promise.all([V(s,null)])}));if(g.every(k=>k.every(M=>M.every(q=>{const V=zs(q.elements);return!(V!=null&&V.value.src)&&!(V!=null&&V.value.playlist)})))){const k=g.flatMap(M=>M.flatMap(q=>q.map(V=>{const X=zs(V.elements);return!(X!=null&&X.value.src)&&!(X!=null&&X.value.playlist)&&(X==null?void 0:X.value.id)}).filter(Boolean))).join(", ");throw new Error(`Video(s) with ID ${k} failed to load, video can not be processed`)}if(g.every(k=>k.every(M=>M.every(q=>q.duration<=0))))throw new Error("No scenes have any duration, video can not be processed");const v=g.reduce((k,M)=>{const q=M.reduce((V,X)=>{const R=X.filter(x=>x.duration>0);return R.length>0?[...V,R]:V},[]);return q.length>0?[...k,q]:k},[]),y=((A=u.meta)==null?void 0:A.frameRate)??30,S=((l=u.meta)==null?void 0:l.resolution)??1080,C=((c=u.meta)==null?void 0:c.transitionDuration)??1/3,Q=rf(v,C),B=Wr(Q),L=await Promise.all(v.map((k,M)=>{const q=Wr(Q[M]),V=Wr(Q.slice(0,M));return Promise.all(k.map((X,R)=>Promise.all(X.map(async({duration:x,captions:G,elements:b},w)=>{var T,Y;const U=await Jr(),W=await Jr(),se=await Jr(),ce=await Jr(),ne=zs(b),me=Wr([...Q.slice(0,M),...Q[M].slice(0,R),...Q[M][R].slice(0,w)]);return{draw:({canvas:we,currentTime:oe})=>{const de=Math.max(0,oe-V),Be=Math.max(0,oe-me);yo({yoga:h,debug:i,canvas:we,cropCanvas:U,posterCanvas:ce,letterboxCanvas:W,elements:b,currentTime:oe,contentTime:de,sceneTime:Be,totalDuration:B,contentDuration:q,sceneDuration:x}),G&&t&&jg({canvas:we,dx:0,dy:0,dw:we.width,dh:we.height,vttCaptions:G,sceneTime:Be+((ne==null?void 0:ne.meta.start)??0)})},duration:x,transitionCanvas:se,id:ef(),start:me,video:ne==null?void 0:ne.video,videoMeta:ne==null?void 0:ne.meta,audio:{duration:x,src:(T=ne==null?void 0:ne.value)==null?void 0:T.src,start:(Y=ne==null?void 0:ne.meta)==null?void 0:Y.start}}}))))})),_=L.flatMap(k=>k);return{scenes:_.flatMap(k=>k),sections:_,contents:L,frameRate:y,resolution:S,transitionDuration:C,fonts:d.fonts??[],duration:B}}const Qo="3",Af={name:"@vouchfor/embeds",version:"3.2.1",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":"^8.2.2","@vouchfor/media-player":"^4.2.1",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":"^1.4.1","@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 lf(s){const{publicApiUrl:e}=br(s),t=Gi();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function cf(s){var n,o,a,A,l,c,h,u,d,g,f,p;if(typeof window>"u")return{client:null,tab:null,request:Gi()};let e=(o=(n=window.localStorage)==null?void 0:n.getItem)==null?void 0:o.call(n,"vouch-uid-visitor"),t=(A=(a=window.localStorage)==null?void 0:a.getItem)==null?void 0:A.call(a,"vouch-uid-client"),i=(c=(l=window.sessionStorage)==null?void 0:l.getItem)==null?void 0:c.call(l,"vouch-uid-tab");const r=Gi();return e||(e=lf(s),(u=(h=window.localStorage)==null?void 0:h.setItem)==null||u.call(h,"vouch-uid-visitor",e)),t||(t=Gi(),(g=(d=window.localStorage)==null?void 0:d.setItem)==null||g.call(d,"vouch-uid-client",t)),i||(i=Gi(),(p=(f=window.sessionStorage)==null?void 0:f.setItem)==null||p.call(f,"vouch-uid-tab",i)),{client:t,tab:i,request:r,visitor:e}}function hf(s,e){return s&&"vouchId"in s?s.vouchId:(e==null?void 0:e.id)??null}function uf(s="embedded_player"){var r,n;const[e,t]=((n=(r=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:r.split)==null?void 0:n.call(r,"/"))??[],i={};return[...new URLSearchParams(location.search).entries()].forEach(([o,a])=>{if(/utm/.test(o)){const A=o.toLowerCase().replace(/[-_][a-z0-9]/g,l=>l.slice(-1).toUpperCase());i[A]=a}}),{source:s,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:Af.version,templateVersion:Qo,...i}}const wl=1;class df{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const r=hf(i,this.host.vouch);!r||this.host.disableTracking||this._batchedEvents.push({event:t,payload:{...i,vouchId:r,time:new Date().toISOString()}})},this._sendTrackingEvent=()=>{if(this._batchedEvents.length<=0)return;const{publicApiUrl:t}=br(this.host.env),{client:i,tab:r,request:n,visitor:o}=cf(this.host.env);navigator.sendBeacon(`${t}/api/batchevents`,JSON.stringify({payload:{events:this._batchedEvents},context:{"x-uid-client":i,"x-uid-tab":r,"x-uid-request":n,"x-uid-visitor":o,"x-reporting-metadata":uf(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+wl&&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:r}})=>{var n,o;!this.host.paused&&t===((o=(n=this.host.scene)==null?void 0:n.video)==null?void 0:o.id)&&(this._currentlyPlayingVideo={id:t,key:i,node:r},this._streamLatestTime[i]=r.currentTime,this._streamStartTime[i]||(this._streamStartTime[i]=r.currentTime,this._streamLatestTime[i]=r.currentTime))},this._handleVideoPause=({detail:{id:t,key:i}})=>{this._streamLatestTime[i]>this._streamStartTime[i]+wl&&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,r;"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),(r=this.host.mediaPlayer)==null||r.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var e,t,i,r;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),(r=this.host.mediaPlayer)==null||r.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}var So={exports:{}};(function(s,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof Lr<"u"&&Lr,i=function(){function n(){this.fetch=!1,this.DOMException=t.DOMException}return n.prototype=t,new n}();(function(n){(function(o){var a=typeof n<"u"&&n||typeof self<"u"&&self||typeof a<"u"&&a,A={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 l(R){return R&&DataView.prototype.isPrototypeOf(R)}if(A.arrayBuffer)var c=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],h=ArrayBuffer.isView||function(R){return R&&c.indexOf(Object.prototype.toString.call(R))>-1};function u(R){if(typeof R!="string"&&(R=String(R)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(R)||R==="")throw new TypeError('Invalid character in header field name: "'+R+'"');return R.toLowerCase()}function d(R){return typeof R!="string"&&(R=String(R)),R}function g(R){var x={next:function(){var G=R.shift();return{done:G===void 0,value:G}}};return A.iterable&&(x[Symbol.iterator]=function(){return x}),x}function f(R){this.map={},R instanceof f?R.forEach(function(x,G){this.append(G,x)},this):Array.isArray(R)?R.forEach(function(x){this.append(x[0],x[1])},this):R&&Object.getOwnPropertyNames(R).forEach(function(x){this.append(x,R[x])},this)}f.prototype.append=function(R,x){R=u(R),x=d(x);var G=this.map[R];this.map[R]=G?G+", "+x:x},f.prototype.delete=function(R){delete this.map[u(R)]},f.prototype.get=function(R){return R=u(R),this.has(R)?this.map[R]:null},f.prototype.has=function(R){return this.map.hasOwnProperty(u(R))},f.prototype.set=function(R,x){this.map[u(R)]=d(x)},f.prototype.forEach=function(R,x){for(var G in this.map)this.map.hasOwnProperty(G)&&R.call(x,this.map[G],G,this)},f.prototype.keys=function(){var R=[];return this.forEach(function(x,G){R.push(G)}),g(R)},f.prototype.values=function(){var R=[];return this.forEach(function(x){R.push(x)}),g(R)},f.prototype.entries=function(){var R=[];return this.forEach(function(x,G){R.push([G,x])}),g(R)},A.iterable&&(f.prototype[Symbol.iterator]=f.prototype.entries);function p(R){if(R.bodyUsed)return Promise.reject(new TypeError("Already read"));R.bodyUsed=!0}function v(R){return new Promise(function(x,G){R.onload=function(){x(R.result)},R.onerror=function(){G(R.error)}})}function y(R){var x=new FileReader,G=v(x);return x.readAsArrayBuffer(R),G}function S(R){var x=new FileReader,G=v(x);return x.readAsText(R),G}function C(R){for(var x=new Uint8Array(R),G=new Array(x.length),b=0;b<x.length;b++)G[b]=String.fromCharCode(x[b]);return G.join("")}function Q(R){if(R.slice)return R.slice(0);var x=new Uint8Array(R.byteLength);return x.set(new Uint8Array(R)),x.buffer}function B(){return this.bodyUsed=!1,this._initBody=function(R){this.bodyUsed=this.bodyUsed,this._bodyInit=R,R?typeof R=="string"?this._bodyText=R:A.blob&&Blob.prototype.isPrototypeOf(R)?this._bodyBlob=R:A.formData&&FormData.prototype.isPrototypeOf(R)?this._bodyFormData=R:A.searchParams&&URLSearchParams.prototype.isPrototypeOf(R)?this._bodyText=R.toString():A.arrayBuffer&&A.blob&&l(R)?(this._bodyArrayBuffer=Q(R.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):A.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(R)||h(R))?this._bodyArrayBuffer=Q(R):this._bodyText=R=Object.prototype.toString.call(R):this._bodyText="",this.headers.get("content-type")||(typeof R=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):A.searchParams&&URLSearchParams.prototype.isPrototypeOf(R)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},A.blob&&(this.blob=function(){var R=p(this);if(R)return R;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 R=p(this);return R||(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(y)}),this.text=function(){var R=p(this);if(R)return R;if(this._bodyBlob)return S(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(C(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},A.formData&&(this.formData=function(){return this.text().then(k)}),this.json=function(){return this.text().then(JSON.parse)},this}var L=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function _(R){var x=R.toUpperCase();return L.indexOf(x)>-1?x:R}function $(R,x){if(!(this instanceof $))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');x=x||{};var G=x.body;if(R instanceof $){if(R.bodyUsed)throw new TypeError("Already read");this.url=R.url,this.credentials=R.credentials,x.headers||(this.headers=new f(R.headers)),this.method=R.method,this.mode=R.mode,this.signal=R.signal,!G&&R._bodyInit!=null&&(G=R._bodyInit,R.bodyUsed=!0)}else this.url=String(R);if(this.credentials=x.credentials||this.credentials||"same-origin",(x.headers||!this.headers)&&(this.headers=new f(x.headers)),this.method=_(x.method||this.method||"GET"),this.mode=x.mode||this.mode||null,this.signal=x.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&G)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(G),(this.method==="GET"||this.method==="HEAD")&&(x.cache==="no-store"||x.cache==="no-cache")){var b=/([?&])_=[^&]*/;if(b.test(this.url))this.url=this.url.replace(b,"$1_="+new Date().getTime());else{var w=/\?/;this.url+=(w.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}$.prototype.clone=function(){return new $(this,{body:this._bodyInit})};function k(R){var x=new FormData;return R.trim().split("&").forEach(function(G){if(G){var b=G.split("="),w=b.shift().replace(/\+/g," "),T=b.join("=").replace(/\+/g," ");x.append(decodeURIComponent(w),decodeURIComponent(T))}}),x}function M(R){var x=new f,G=R.replace(/\r?\n[\t ]+/g," ");return G.split("\r").map(function(b){return b.indexOf(`
153
+ `)===0?b.substr(1,b.length):b}).forEach(function(b){var w=b.split(":"),T=w.shift().trim();if(T){var Y=w.join(":").trim();x.append(T,Y)}}),x}B.call($.prototype);function q(R,x){if(!(this instanceof q))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');x||(x={}),this.type="default",this.status=x.status===void 0?200:x.status,this.ok=this.status>=200&&this.status<300,this.statusText=x.statusText===void 0?"":""+x.statusText,this.headers=new f(x.headers),this.url=x.url||"",this._initBody(R)}B.call(q.prototype),q.prototype.clone=function(){return new q(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},q.error=function(){var R=new q(null,{status:0,statusText:""});return R.type="error",R};var V=[301,302,303,307,308];q.redirect=function(R,x){if(V.indexOf(x)===-1)throw new RangeError("Invalid status code");return new q(null,{status:x,headers:{location:R}})},o.DOMException=a.DOMException;try{new o.DOMException}catch{o.DOMException=function(x,G){this.message=x,this.name=G;var b=Error(x);this.stack=b.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function X(R,x){return new Promise(function(G,b){var w=new $(R,x);if(w.signal&&w.signal.aborted)return b(new o.DOMException("Aborted","AbortError"));var T=new XMLHttpRequest;function Y(){T.abort()}T.onload=function(){var W={status:T.status,statusText:T.statusText,headers:M(T.getAllResponseHeaders()||"")};W.url="responseURL"in T?T.responseURL:W.headers.get("X-Request-URL");var se="response"in T?T.response:T.responseText;setTimeout(function(){G(new q(se,W))},0)},T.onerror=function(){setTimeout(function(){b(new TypeError("Network request failed"))},0)},T.ontimeout=function(){setTimeout(function(){b(new TypeError("Network request failed"))},0)},T.onabort=function(){setTimeout(function(){b(new o.DOMException("Aborted","AbortError"))},0)};function U(W){try{return W===""&&a.location.href?a.location.href:W}catch{return W}}T.open(w.method,U(w.url),!0),w.credentials==="include"?T.withCredentials=!0:w.credentials==="omit"&&(T.withCredentials=!1),"responseType"in T&&(A.blob?T.responseType="blob":A.arrayBuffer&&w.headers.get("Content-Type")&&w.headers.get("Content-Type").indexOf("application/octet-stream")!==-1&&(T.responseType="arraybuffer")),x&&typeof x.headers=="object"&&!(x.headers instanceof f)?Object.getOwnPropertyNames(x.headers).forEach(function(W){T.setRequestHeader(W,d(x.headers[W]))}):w.headers.forEach(function(W,se){T.setRequestHeader(se,W)}),w.signal&&(w.signal.addEventListener("abort",Y),T.onreadystatechange=function(){T.readyState===4&&w.signal.removeEventListener("abort",Y)}),T.send(typeof w._bodyInit>"u"?null:w._bodyInit)})}return X.polyfill=!0,a.fetch||(a.fetch=X,a.Headers=f,a.Request=$,a.Response=q),o.Headers=f,o.Request=$,o.Response=q,o.fetch=X,o})({})})(i),i.fetch.ponyfill=!0,delete i.fetch.polyfill;var r=t.fetch?t:i;e=r.fetch,e.default=r.fetch,e.fetch=r.fetch,e.Headers=r.Headers,e.Request=r.Request,e.Response=r.Response,s.exports=e})(So,So.exports);var gf=So.exports;const Rl=al(gf);async function ff(s){var e;try{if((e=await Rl(s,{method:"HEAD"}))!=null&&e.ok)return s}catch{return}}async function bo({sources:s}){let e=null;const t=s==null?void 0:s.filter(Boolean),i=t==null?void 0:t.find(n=>n.startsWith("blob:")),r=t==null?void 0:t.find(n=>!n.startsWith("http")&&!n.startsWith("blob:"));if(i||r)return i??r;if(t.length>0){const n=t.map(o=>ff(o));e=(await Promise.all(n)).find(Boolean)}return e}async function pf(s){try{return(await Rl(s)).text()}catch{return null}}async function Ef(s){return s=s.trim(),s.startsWith("http")||s.startsWith("blob:")?pf(s):s}const If=Ut(async({original:s,translation:e,originalLanguage:t="",translationLanguage:i=""},{language:r})=>{var n,o;const a={[(n=i==null?void 0:i.split("-"))==null?void 0:n[0]]:e,[(o=t==null?void 0:t.split("-"))==null?void 0:o[0]]:s},A=(r&&a[r])??s;return A?Ef(A):null},{cacheKey:([s,{language:e}])=>JSON.stringify({...s,language:e})}),mf=Ut(async s=>{var e,t,i,r,n,o,a,A,l,c,h;const[u,d,g]=await Promise.all([bo({sources:[(t=(e=s==null?void 0:s.answer)==null?void 0:e.media)==null?void 0:t.video,(r=(i=s==null?void 0:s.answer)==null?void 0:i.media)==null?void 0:r.input]}),bo({sources:[(o=(n=s==null?void 0:s.answer)==null?void 0:n.media)==null?void 0:o.playlist]}),bo({sources:[((A=(a=s==null?void 0:s.answer)==null?void 0:a.media)==null?void 0:A.reducedQuality)??((h=(c=(l=s==null?void 0:s.answer)==null?void 0:l.media)==null?void 0:c.videos)==null?void 0:h.xs)]})]);return{src:u,playlist:d,preview:g}},{cacheKey:([s])=>{var e,t,i,r,n,o,a,A,l,c,h;return JSON.stringify({video:(t=(e=s==null?void 0:s.answer)==null?void 0:e.media)==null?void 0:t.video,input:(r=(i=s==null?void 0:s.answer)==null?void 0:i.media)==null?void 0:r.input,playlist:(o=(n=s==null?void 0:s.answer)==null?void 0:n.media)==null?void 0:o.playlist,preview:((A=(a=s==null?void 0:s.answer)==null?void 0:a.media)==null?void 0:A.reducedQuality)??((h=(c=(l=s==null?void 0:s.answer)==null?void 0:l.media)==null?void 0:c.videos)==null?void 0:h.xs)})}});function xl(s){var e,t,i,r,n,o,a,A,l,c,h,u;const d=((t=(e=s==null?void 0:s.answer)==null?void 0:e.contact)==null?void 0:t.name)==="Anonymous"?"":((n=(r=(i=s==null?void 0:s.answer)==null?void 0:i.contact)==null?void 0:r.name)==null?void 0:n.trim())??"",g=((A=(a=(o=s==null?void 0:s.answer)==null?void 0:o.contact)==null?void 0:a.client)==null?void 0:A.name)==="Not Supplied"?"":((u=(h=(c=(l=s==null?void 0:s.answer)==null?void 0:l.contact)==null?void 0:c.client)==null?void 0:h.name)==null?void 0:u.trim())??"",[f,p]=d.split(" ");return{name:d,firstName:f,lastName:p,companyName:g}}const Cf=Ut(async(s,e,t)=>{var i,r,n;const o=(i=e==null?void 0:e.answer)==null?void 0:i.id;return((n=(r=s==null?void 0:s.questions)==null?void 0:r.items)==null?void 0:n.reduce((A,l)=>{var c;return((c=l==null?void 0:l.answer)==null?void 0:c.id)===o?(A??0)+1:A},0))<=1?o:`${o}-${t}`},{cacheKey:([s,e,t])=>{var i;return JSON.stringify({index:t,rootData:e,allQuestions:(i=s==null?void 0:s.questions)==null?void 0:i.items})}});async function wo({data:s,rootData:e,index:t},i){var r,n,o,a,A,l,c,h,u,d,g,f,p,v,y,S,C,Q,B,L,_,$,k;const[M,q,V]=await Promise.all([Cf(s,e,t),mf(e),If({original:((n=(r=e==null?void 0:e.answer)==null?void 0:r.media)==null?void 0:n.captions)??((a=(o=e==null?void 0:e.answer)==null?void 0:o.captions)==null?void 0:a.current),translation:((l=(A=e==null?void 0:e.answer)==null?void 0:A.media)==null?void 0:l.translation)??((h=(c=e==null?void 0:e.answer)==null?void 0:c.captions)==null?void 0:h.translation),originalLanguage:(d=(u=e==null?void 0:e.answer)==null?void 0:u.transcription)==null?void 0:d.language,translationLanguage:(p=(f=(g=e==null?void 0:e.answer)==null?void 0:g.transcription)==null?void 0:f.translation)==null?void 0:p.language},i)]),X=xl(e);return{...q,...X,key:M,captions:V,answerLabel:((v=e==null?void 0:e.answer)==null?void 0:v.label)??(e==null?void 0:e.title),prevAnswerLabel:t?((Q=(C=(S=(y=s==null?void 0:s.questions)==null?void 0:y.items)==null?void 0:S[t-1])==null?void 0:C.answer)==null?void 0:Q.label)??((_=(L=(B=s==null?void 0:s.questions)==null?void 0:B.items)==null?void 0:L[t-1])==null?void 0:_.title)??null:null,isFirstInstanceOfName:t?((k=($=s==null?void 0:s.questions)==null?void 0:$.items)==null?void 0:k.findIndex(R=>xl(R).name===X.name))===t:!0}}const qr={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 vf({data:s}){var e,t;return((t=(e=s==null?void 0:s.questions)==null?void 0:e.items)==null?void 0:t.reduce((i,r)=>{var n,o,a,A,l,c,h;const u=(a=(o=(n=r==null?void 0:r.answer)==null?void 0:n.transcription)==null?void 0:o.language)==null?void 0:a.split("-")[0],d=(h=(c=(l=(A=r==null?void 0:r.answer)==null?void 0:A.transcription)==null?void 0:l.translation)==null?void 0:c.language)==null?void 0:h.split("-")[0];return u&&qr[u]&&!i.find(g=>g.value===u)&&i.push({value:u,label:qr[u]}),d&&qr[d]&&!i.find(g=>g.value===d)&&i.push({value:d,label:qr[d]}),i},[]))??[]}/**
154
154
  * @license
155
155
  * Copyright 2018 Google LLC
156
156
  * SPDX-License-Identifier: BSD-3-Clause