@vouchfor/embeds-legacy 0.0.0-experiment.2df224d → 0.0.0-experiment.8f3c7fb

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.
@@ -196,7 +196,7 @@ class FetcherController {
196
196
  }
197
197
  }
198
198
  const name = "@vouchfor/embeds-legacy";
199
- const version = "0.0.0-experiment.2df224d";
199
+ const version = "0.0.0-experiment.8f3c7fb";
200
200
  const license = "MIT";
201
201
  const author = "Aaron Williams";
202
202
  const main = "dist/es/embeds-legacy.js";
@@ -239,7 +239,7 @@ const dependencies = {
239
239
  "@a11y/focus-trap": "^1.0.5",
240
240
  "@lit/task": "^1.0.0",
241
241
  "@vouchfor/canvas-video-legacy": "^8.2.2",
242
- "@vouchfor/media-player-legacy": "0.0.0-experiment.2df224d",
242
+ "@vouchfor/media-player-legacy": "0.0.0-experiment.8f3c7fb",
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-legacy": "0.0.0-experiment.2df224d",
261
+ "@vouchfor/video-utils-legacy": "0.0.0-experiment.8f3c7fb",
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",
@@ -149,7 +149,7 @@ ${e}`,$g=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),Yg=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 gf(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Zh);return new s.Image}return new Image}const Nl=Kt(async function(e){return e?new Promise((t,i)=>{gf().then(r=>{r.onload=()=>{t(r)},r.onerror=n=>{i(n)},r.src=e})}):null});async function Lo({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 Nl(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 Nl(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=>Lo({element:l,meta:e},t,i)))),s.elements&&(a.elements=await Promise.all(s.elements.map(l=>Lo({element:l,meta:e},t,i)))),a}async function tn(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Zh),e=new s.Canvas;return e.gpu=!1,e}return document.createElement("canvas")}function ir(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=ir(t==null?void 0:t.elements);if(i)return i}}function ff(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 pf(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 Ef(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 sn(s){return s.flatMap(e=>Array.isArray(e)?e.flatMap(t=>t):e).reduce((e,t)=>e+t,0)}const If=Kt(()=>Il.loadYoga());vo.filters.define("parse",s=>typeof s>"u"?null:typeof s=="string"?`"${Ef(s)}"`:pf(s)||Array.isArray(s)?JSON.stringify(s):s);const hs=(s,e,t)=>vo.render(s,e,vo.getConfig({autoEscape:!1,defaultFilter:"parse",...t}));async function ds({data:s,template:e,burnCaptions:t=!1,debug:i=!1},r,n,o){var a,A,l,c;const u=await If(),h=e??df;if(!((a=h.templates)!=null&&a.length))throw new Error(`No templates found for template instance: ${h.id}`);let d=h.templates.find(({version:k})=>k===_o);if(!d){const k=h.templates.map(({version:M})=>`"${M}"`).join(", ");console.warn(`Template renderer expects template version "${_o}" but got ${k}`),d=h.templates[h.templates.length-1]}const g=await Promise.all(d.content.map(async({scenes:k,root:M})=>{const j={...h.options,...s,intro:h.intro,outro:h.outro};async function V(z,R){return Promise.all(k.map(async({layout:x,duration:G,data:S,derived:w,options:T})=>{var Y,U,q;const se={...j,_index:R,_root:z,_derived:await r({data:s,rootData:z,index:R})},ce=S?JSON.parse(await hs(S,se)):{},ne=w?JSON.parse(await hs(w,se)):{},me=T?JSON.parse(await hs(T,se)):{},be=G?parseFloat(await hs(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 hs(we,{...ce,...ne,...me})),de=await Promise.all(oe.flatMap(ge=>Lo({element:ge,meta:h.meta},n,o))),Be=ir(de);return{duration:(isNaN(be)?null:be)??((U=Be==null?void 0:Be.meta)==null?void 0:U.duration)??0,captions:(q=Be==null?void 0:Be.meta)==null?void 0:q.captions,elements:de}}))}if(M){const z=JSON.parse(await hs(M,j));return Array.isArray(z)?Promise.all(z.map(async(R,x)=>V(R,x))):Promise.all([V(z,null)])}return Promise.all([V(s,null)])}));if(g.every(k=>k.every(M=>M.every(j=>{const V=ir(j.elements);return!(V!=null&&V.value.src)&&!(V!=null&&V.value.playlist)})))){const k=g.flatMap(M=>M.flatMap(j=>j.map(V=>{const z=ir(V.elements);return!(z!=null&&z.value.src)&&!(z!=null&&z.value.playlist)&&(z==null?void 0:z.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(j=>j.duration<=0))))throw new Error("No scenes have any duration, video can not be processed");const y=g.reduce((k,M)=>{const j=M.reduce((V,z)=>{const R=z.filter(x=>x.duration>0);return R.length>0?[...V,R]:V},[]);return j.length>0?[...k,j]:k},[]),v=((A=h.meta)==null?void 0:A.frameRate)??30,b=((l=h.meta)==null?void 0:l.resolution)??1080,C=((c=h.meta)==null?void 0:c.transitionDuration)??1/3,Q=ff(y,C),B=sn(Q),L=await Promise.all(y.map((k,M)=>{const j=sn(Q[M]),V=sn(Q.slice(0,M));return Promise.all(k.map((z,R)=>Promise.all(z.map(async({duration:x,captions:G,elements:S},w)=>{var T,Y;const U=await tn(),q=await tn(),se=await tn(),ce=await tn(),ne=ir(S),me=sn([...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);Do({yoga:u,debug:i,canvas:we,cropCanvas:U,posterCanvas:ce,letterboxCanvas:q,elements:S,currentTime:oe,contentTime:de,sceneTime:Be,totalDuration:B,contentDuration:j,sceneDuration:x}),G&&t&&Af({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:hf(),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:v,resolution:b,transitionDuration:C,fonts:d.fonts??[],duration:B}}const _o="3",mf={name:"@vouchfor/embeds-legacy",version:"0.0.0-experiment.2df224d",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds-legacy.js",module:"dist/es/embeds-legacy.js",type:"module",types:"dist/es/src/index.d.ts",exports:{".":"./dist/es/embeds-legacy.js"},files:["dist","src"],publishConfig:{tag:"experiment",access:"public"},engines:{node:">=18.18.0"},scripts:{build:"rm -rf dist && tsc && yarn build:self","build:deps":"yarn --cwd ../media-player-legacy 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-legacy":"^8.2.2","@vouchfor/media-player-legacy":"0.0.0-experiment.2df224d",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-legacy":"0.0.0-experiment.2df224d","@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 Cf(s){const{publicApiUrl:e}=kr(s),t=_i();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function yf(s){var n,o,a,A,l,c,u,h,d,g,f,p;if(typeof window>"u")return{client:null,tab:null,request:_i()};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=_i();return e||(e=Cf(s),(h=(u=window.localStorage)==null?void 0:u.setItem)==null||h.call(u,"vouch-uid-visitor",e)),t||(t=_i(),(g=(d=window.localStorage)==null?void 0:d.setItem)==null||g.call(d,"vouch-uid-client",t)),i||(i=_i(),(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 vf(s,e){return s&&"vouchId"in s?s.vouchId:(e==null?void 0:e.id)??null}function Bf(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:mf.version,templateVersion:_o,...i}}const Ml=1;class Qf{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const r=vf(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}=kr(this.host.env),{client:i,tab:r,request:n,visitor:o}=yf(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":Bf(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+Ml&&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]+Ml&&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 ko={exports:{}};(function(s,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof Ur<"u"&&Ur,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]"],u=ArrayBuffer.isView||function(R){return R&&c.indexOf(Object.prototype.toString.call(R))>-1};function h(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=h(R),x=d(x);var G=this.map[R];this.map[R]=G?G+", "+x:x},f.prototype.delete=function(R){delete this.map[h(R)]},f.prototype.get=function(R){return R=h(R),this.has(R)?this.map[R]:null},f.prototype.has=function(R){return this.map.hasOwnProperty(h(R))},f.prototype.set=function(R,x){this.map[h(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 y(R){return new Promise(function(x,G){R.onload=function(){x(R.result)},R.onerror=function(){G(R.error)}})}function v(R){var x=new FileReader,G=y(x);return x.readAsArrayBuffer(R),G}function b(R){var x=new FileReader,G=y(x);return x.readAsText(R),G}function C(R){for(var x=new Uint8Array(R),G=new Array(x.length),S=0;S<x.length;S++)G[S]=String.fromCharCode(x[S]);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)||u(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(v)}),this.text=function(){var R=p(this);if(R)return R;if(this._bodyBlob)return b(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 S=/([?&])_=[^&]*/;if(S.test(this.url))this.url=this.url.replace(S,"$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 S=G.split("="),w=S.shift().replace(/\+/g," "),T=S.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(S){return S.indexOf(`
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 gf(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Zh);return new s.Image}return new Image}const Nl=Kt(async function(e){return e?new Promise((t,i)=>{gf().then(r=>{r.onload=()=>{t(r)},r.onerror=n=>{i(n)},r.src=e})}):null});async function Lo({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 Nl(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 Nl(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=>Lo({element:l,meta:e},t,i)))),s.elements&&(a.elements=await Promise.all(s.elements.map(l=>Lo({element:l,meta:e},t,i)))),a}async function tn(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Zh),e=new s.Canvas;return e.gpu=!1,e}return document.createElement("canvas")}function ir(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=ir(t==null?void 0:t.elements);if(i)return i}}function ff(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 pf(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 Ef(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 sn(s){return s.flatMap(e=>Array.isArray(e)?e.flatMap(t=>t):e).reduce((e,t)=>e+t,0)}const If=Kt(()=>Il.loadYoga());vo.filters.define("parse",s=>typeof s>"u"?null:typeof s=="string"?`"${Ef(s)}"`:pf(s)||Array.isArray(s)?JSON.stringify(s):s);const hs=(s,e,t)=>vo.render(s,e,vo.getConfig({autoEscape:!1,defaultFilter:"parse",...t}));async function ds({data:s,template:e,burnCaptions:t=!1,debug:i=!1},r,n,o){var a,A,l,c;const u=await If(),h=e??df;if(!((a=h.templates)!=null&&a.length))throw new Error(`No templates found for template instance: ${h.id}`);let d=h.templates.find(({version:k})=>k===_o);if(!d){const k=h.templates.map(({version:M})=>`"${M}"`).join(", ");console.warn(`Template renderer expects template version "${_o}" but got ${k}`),d=h.templates[h.templates.length-1]}const g=await Promise.all(d.content.map(async({scenes:k,root:M})=>{const j={...h.options,...s,intro:h.intro,outro:h.outro};async function V(z,R){return Promise.all(k.map(async({layout:x,duration:G,data:S,derived:w,options:T})=>{var Y,U,q;const se={...j,_index:R,_root:z,_derived:await r({data:s,rootData:z,index:R})},ce=S?JSON.parse(await hs(S,se)):{},ne=w?JSON.parse(await hs(w,se)):{},me=T?JSON.parse(await hs(T,se)):{},be=G?parseFloat(await hs(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 hs(we,{...ce,...ne,...me})),de=await Promise.all(oe.flatMap(ge=>Lo({element:ge,meta:h.meta},n,o))),Be=ir(de);return{duration:(isNaN(be)?null:be)??((U=Be==null?void 0:Be.meta)==null?void 0:U.duration)??0,captions:(q=Be==null?void 0:Be.meta)==null?void 0:q.captions,elements:de}}))}if(M){const z=JSON.parse(await hs(M,j));return Array.isArray(z)?Promise.all(z.map(async(R,x)=>V(R,x))):Promise.all([V(z,null)])}return Promise.all([V(s,null)])}));if(g.every(k=>k.every(M=>M.every(j=>{const V=ir(j.elements);return!(V!=null&&V.value.src)&&!(V!=null&&V.value.playlist)})))){const k=g.flatMap(M=>M.flatMap(j=>j.map(V=>{const z=ir(V.elements);return!(z!=null&&z.value.src)&&!(z!=null&&z.value.playlist)&&(z==null?void 0:z.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(j=>j.duration<=0))))throw new Error("No scenes have any duration, video can not be processed");const y=g.reduce((k,M)=>{const j=M.reduce((V,z)=>{const R=z.filter(x=>x.duration>0);return R.length>0?[...V,R]:V},[]);return j.length>0?[...k,j]:k},[]),v=((A=h.meta)==null?void 0:A.frameRate)??30,b=((l=h.meta)==null?void 0:l.resolution)??1080,C=((c=h.meta)==null?void 0:c.transitionDuration)??1/3,Q=ff(y,C),B=sn(Q),L=await Promise.all(y.map((k,M)=>{const j=sn(Q[M]),V=sn(Q.slice(0,M));return Promise.all(k.map((z,R)=>Promise.all(z.map(async({duration:x,captions:G,elements:S},w)=>{var T,Y;const U=await tn(),q=await tn(),se=await tn(),ce=await tn(),ne=ir(S),me=sn([...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);Do({yoga:u,debug:i,canvas:we,cropCanvas:U,posterCanvas:ce,letterboxCanvas:q,elements:S,currentTime:oe,contentTime:de,sceneTime:Be,totalDuration:B,contentDuration:j,sceneDuration:x}),G&&t&&Af({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:hf(),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:v,resolution:b,transitionDuration:C,fonts:d.fonts??[],duration:B}}const _o="3",mf={name:"@vouchfor/embeds-legacy",version:"0.0.0-experiment.8f3c7fb",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds-legacy.js",module:"dist/es/embeds-legacy.js",type:"module",types:"dist/es/src/index.d.ts",exports:{".":"./dist/es/embeds-legacy.js"},files:["dist","src"],publishConfig:{tag:"experiment",access:"public"},engines:{node:">=18.18.0"},scripts:{build:"rm -rf dist && tsc && yarn build:self","build:deps":"yarn --cwd ../media-player-legacy 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-legacy":"^8.2.2","@vouchfor/media-player-legacy":"0.0.0-experiment.8f3c7fb",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-legacy":"0.0.0-experiment.8f3c7fb","@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 Cf(s){const{publicApiUrl:e}=kr(s),t=_i();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function yf(s){var n,o,a,A,l,c,u,h,d,g,f,p;if(typeof window>"u")return{client:null,tab:null,request:_i()};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=_i();return e||(e=Cf(s),(h=(u=window.localStorage)==null?void 0:u.setItem)==null||h.call(u,"vouch-uid-visitor",e)),t||(t=_i(),(g=(d=window.localStorage)==null?void 0:d.setItem)==null||g.call(d,"vouch-uid-client",t)),i||(i=_i(),(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 vf(s,e){return s&&"vouchId"in s?s.vouchId:(e==null?void 0:e.id)??null}function Bf(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:mf.version,templateVersion:_o,...i}}const Ml=1;class Qf{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const r=vf(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}=kr(this.host.env),{client:i,tab:r,request:n,visitor:o}=yf(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":Bf(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+Ml&&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]+Ml&&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 ko={exports:{}};(function(s,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof Ur<"u"&&Ur,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]"],u=ArrayBuffer.isView||function(R){return R&&c.indexOf(Object.prototype.toString.call(R))>-1};function h(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=h(R),x=d(x);var G=this.map[R];this.map[R]=G?G+", "+x:x},f.prototype.delete=function(R){delete this.map[h(R)]},f.prototype.get=function(R){return R=h(R),this.has(R)?this.map[R]:null},f.prototype.has=function(R){return this.map.hasOwnProperty(h(R))},f.prototype.set=function(R,x){this.map[h(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 y(R){return new Promise(function(x,G){R.onload=function(){x(R.result)},R.onerror=function(){G(R.error)}})}function v(R){var x=new FileReader,G=y(x);return x.readAsArrayBuffer(R),G}function b(R){var x=new FileReader,G=y(x);return x.readAsText(R),G}function C(R){for(var x=new Uint8Array(R),G=new Array(x.length),S=0;S<x.length;S++)G[S]=String.fromCharCode(x[S]);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)||u(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(v)}),this.text=function(){var R=p(this);if(R)return R;if(this._bodyBlob)return b(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 S=/([?&])_=[^&]*/;if(S.test(this.url))this.url=this.url.replace(S,"$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 S=G.split("="),w=S.shift().replace(/\+/g," "),T=S.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(S){return S.indexOf(`
153
153
  `)===0?S.substr(1,S.length):S}).forEach(function(S){var w=S.split(":"),T=w.shift().trim();if(T){var Y=w.join(":").trim();x.append(T,Y)}}),x}B.call($.prototype);function j(R,x){if(!(this instanceof j))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(j.prototype),j.prototype.clone=function(){return new j(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},j.error=function(){var R=new j(null,{status:0,statusText:""});return R.type="error",R};var V=[301,302,303,307,308];j.redirect=function(R,x){if(V.indexOf(x)===-1)throw new RangeError("Invalid status code");return new j(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 S=Error(x);this.stack=S.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function z(R,x){return new Promise(function(G,S){var w=new $(R,x);if(w.signal&&w.signal.aborted)return S(new o.DOMException("Aborted","AbortError"));var T=new XMLHttpRequest;function Y(){T.abort()}T.onload=function(){var q={status:T.status,statusText:T.statusText,headers:M(T.getAllResponseHeaders()||"")};q.url="responseURL"in T?T.responseURL:q.headers.get("X-Request-URL");var se="response"in T?T.response:T.responseText;setTimeout(function(){G(new j(se,q))},0)},T.onerror=function(){setTimeout(function(){S(new TypeError("Network request failed"))},0)},T.ontimeout=function(){setTimeout(function(){S(new TypeError("Network request failed"))},0)},T.onabort=function(){setTimeout(function(){S(new o.DOMException("Aborted","AbortError"))},0)};function U(q){try{return q===""&&a.location.href?a.location.href:q}catch{return q}}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(q){T.setRequestHeader(q,d(x.headers[q]))}):w.headers.forEach(function(q,se){T.setRequestHeader(se,q)}),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 z.polyfill=!0,a.fetch||(a.fetch=z,a.Headers=f,a.Request=$,a.Response=j),o.Headers=f,o.Request=$,o.Response=j,o.fetch=z,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})(ko,ko.exports);var bf=ko.exports;const Ol=El(bf);async function Sf(s){var e;try{if((e=await Ol(s,{method:"HEAD"}))!=null&&e.ok)return s}catch{return}}async function Fo({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=>Sf(o));e=(await Promise.all(n)).find(Boolean)}return e}async function wf(s){try{return(await Ol(s)).text()}catch{return null}}async function Rf(s){return s=s.trim(),s.startsWith("http")||s.startsWith("blob:")?wf(s):s}const xf=Kt(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?Rf(A):null},{cacheKey:([s,{language:e}])=>JSON.stringify({...s,language:e})}),Tf=Kt(async s=>{var e,t,i,r,n,o,a,A,l,c,u;const[h,d,g]=await Promise.all([Fo({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]}),Fo({sources:[(o=(n=s==null?void 0:s.answer)==null?void 0:n.media)==null?void 0:o.playlist]}),Fo({sources:[((A=(a=s==null?void 0:s.answer)==null?void 0:a.media)==null?void 0:A.reducedQuality)??((u=(c=(l=s==null?void 0:s.answer)==null?void 0:l.media)==null?void 0:c.videos)==null?void 0:u.xs)]})]);return{src:h,playlist:d,preview:g}},{cacheKey:([s])=>{var e,t,i,r,n,o,a,A,l,c,u;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)??((u=(c=(l=s==null?void 0:s.answer)==null?void 0:l.media)==null?void 0:c.videos)==null?void 0:u.xs)})}});function Pl(s){var e,t,i,r,n,o,a,A,l,c,u,h;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"?"":((h=(u=(c=(l=s==null?void 0:s.answer)==null?void 0:l.contact)==null?void 0:c.client)==null?void 0:u.name)==null?void 0:h.trim())??"",[f,p]=d.split(" ");return{name:d,firstName:f,lastName:p,companyName:g}}const Df=Kt(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 No({data:s,rootData:e,index:t},i){var r,n,o,a,A,l,c,u,h,d,g,f,p,y,v,b,C,Q,B,L,_,$,k;const[M,j,V]=await Promise.all([Df(s,e,t),Tf(e),xf({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)??((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=(f=(g=e==null?void 0:e.answer)==null?void 0:g.transcription)==null?void 0:f.translation)==null?void 0:p.language},i)]),z=Pl(e);return{...j,...z,key:M,captions:V,answerLabel:((y=e==null?void 0:e.answer)==null?void 0:y.label)??(e==null?void 0:e.title),prevAnswerLabel:t?((Q=(C=(b=(v=s==null?void 0:s.questions)==null?void 0:v.items)==null?void 0:b[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=>Pl(R).name===z.name))===t:!0}}const rn={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 Lf({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,u;const h=(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=(u=(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:u.split("-")[0];return h&&rn[h]&&!i.find(g=>g.value===h)&&i.push({value:h,label:rn[h]}),d&&rn[d]&&!i.find(g=>g.value===d)&&i.push({value:d,label:rn[d]}),i},[]))??[]}/**
154
154
  * @license
155
155
  * Copyright 2018 Google LLC
@@ -149,7 +149,7 @@ ${e}`,Hg=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 df(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>zh);return new s.Image}return new Image}const Fl=Yt(async function(e){return e?new Promise((t,i)=>{df().then(r=>{r.onload=()=>{t(r)},r.onerror=n=>{i(n)},r.src=e})}):null});async function Do({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 Fl(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 Fl(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=>Do({element:l,meta:e},t,i)))),s.elements&&(a.elements=await Promise.all(s.elements.map(l=>Do({element:l,meta:e},t,i)))),a}async function en(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>zh),e=new s.Canvas;return e.gpu=!1,e}return document.createElement("canvas")}function tr(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=tr(t==null?void 0:t.elements);if(i)return i}}function gf(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 ff(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 pf(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 tn(s){return s.flatMap(e=>Array.isArray(e)?e.flatMap(t=>t):e).reduce((e,t)=>e+t,0)}const Ef=Yt(()=>El.loadYoga());yo.filters.define("parse",s=>typeof s>"u"?null:typeof s=="string"?`"${pf(s)}"`:ff(s)||Array.isArray(s)?JSON.stringify(s):s);const us=(s,e,t)=>yo.render(s,e,yo.getConfig({autoEscape:!1,defaultFilter:"parse",...t}));async function hs({data:s,template:e,burnCaptions:t=!1,debug:i=!1},r,n,o){var a,A,l,c;const u=await Ef(),h=e??hf;if(!((a=h.templates)!=null&&a.length))throw new Error(`No templates found for template instance: ${h.id}`);let d=h.templates.find(({version:k})=>k===Lo);if(!d){const k=h.templates.map(({version:M})=>`"${M}"`).join(", ");console.warn(`Template renderer expects template version "${Lo}" but got ${k}`),d=h.templates[h.templates.length-1]}const g=await Promise.all(d.content.map(async({scenes:k,root:M})=>{const j={...h.options,...s,intro:h.intro,outro:h.outro};async function V(z,R){return Promise.all(k.map(async({layout:x,duration:G,data:S,derived:w,options:T})=>{var Y,U,q;const se={...j,_index:R,_root:z,_derived:await r({data:s,rootData:z,index:R})},ce=S?JSON.parse(await us(S,se)):{},ne=w?JSON.parse(await us(w,se)):{},me=T?JSON.parse(await us(T,se)):{},Se=G?parseFloat(await us(G,se)):NaN,Re=(Y=d.layouts.find(ge=>ge.name===x))==null?void 0:Y.tree;if(!Re)throw new Error(`Layout tree "${x}" not found in template "${d.id}" layouts.`);const oe=JSON.parse(await us(Re,{...ce,...ne,...me})),de=await Promise.all(oe.flatMap(ge=>Do({element:ge,meta:h.meta},n,o))),Qe=tr(de);return{duration:(isNaN(Se)?null:Se)??((U=Qe==null?void 0:Qe.meta)==null?void 0:U.duration)??0,captions:(q=Qe==null?void 0:Qe.meta)==null?void 0:q.captions,elements:de}}))}if(M){const z=JSON.parse(await us(M,j));return Array.isArray(z)?Promise.all(z.map(async(R,x)=>V(R,x))):Promise.all([V(z,null)])}return Promise.all([V(s,null)])}));if(g.every(k=>k.every(M=>M.every(j=>{const V=tr(j.elements);return!(V!=null&&V.value.src)&&!(V!=null&&V.value.playlist)})))){const k=g.flatMap(M=>M.flatMap(j=>j.map(V=>{const z=tr(V.elements);return!(z!=null&&z.value.src)&&!(z!=null&&z.value.playlist)&&(z==null?void 0:z.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(j=>j.duration<=0))))throw new Error("No scenes have any duration, video can not be processed");const y=g.reduce((k,M)=>{const j=M.reduce((V,z)=>{const R=z.filter(x=>x.duration>0);return R.length>0?[...V,R]:V},[]);return j.length>0?[...k,j]:k},[]),v=((A=h.meta)==null?void 0:A.frameRate)??30,b=((l=h.meta)==null?void 0:l.resolution)??1080,C=((c=h.meta)==null?void 0:c.transitionDuration)??1/3,Q=gf(y,C),B=tn(Q),L=await Promise.all(y.map((k,M)=>{const j=tn(Q[M]),V=tn(Q.slice(0,M));return Promise.all(k.map((z,R)=>Promise.all(z.map(async({duration:x,captions:G,elements:S},w)=>{var T,Y;const U=await en(),q=await en(),se=await en(),ce=await en(),ne=tr(S),me=tn([...Q.slice(0,M),...Q[M].slice(0,R),...Q[M][R].slice(0,w)]);return{draw:({canvas:Re,currentTime:oe})=>{const de=Math.max(0,oe-V),Qe=Math.max(0,oe-me);To({yoga:u,debug:i,canvas:Re,cropCanvas:U,posterCanvas:ce,letterboxCanvas:q,elements:S,currentTime:oe,contentTime:de,sceneTime:Qe,totalDuration:B,contentDuration:j,sceneDuration:x}),G&&t&&af({canvas:Re,dx:0,dy:0,dw:Re.width,dh:Re.height,vttCaptions:G,sceneTime:Qe+((ne==null?void 0:ne.meta.start)??0)})},duration:x,transitionCanvas:se,id:uf(),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:v,resolution:b,transitionDuration:C,fonts:d.fonts??[],duration:B}}const Lo="3",If={name:"@vouchfor/embeds-legacy",version:"0.0.0-experiment.2df224d",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds-legacy.js",module:"dist/es/embeds-legacy.js",type:"module",types:"dist/es/src/index.d.ts",exports:{".":"./dist/es/embeds-legacy.js"},files:["dist","src"],publishConfig:{tag:"experiment",access:"public"},engines:{node:">=18.18.0"},scripts:{build:"rm -rf dist && tsc && yarn build:self","build:deps":"yarn --cwd ../media-player-legacy 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-legacy":"^8.2.2","@vouchfor/media-player-legacy":"0.0.0-experiment.2df224d",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-legacy":"0.0.0-experiment.2df224d","@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 mf(s){const{publicApiUrl:e}=_r(s),t=Li();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function Cf(s){var n,o,a,A,l,c,u,h,d,g,f,p;if(typeof window>"u")return{client:null,tab:null,request:Li()};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=Li();return e||(e=mf(s),(h=(u=window.localStorage)==null?void 0:u.setItem)==null||h.call(u,"vouch-uid-visitor",e)),t||(t=Li(),(g=(d=window.localStorage)==null?void 0:d.setItem)==null||g.call(d,"vouch-uid-client",t)),i||(i=Li(),(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 yf(s,e){return s&&"vouchId"in s?s.vouchId:(e==null?void 0:e.id)??null}function vf(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:If.version,templateVersion:Lo,...i}}const Nl=1;class Bf{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const r=yf(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}=_r(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":vf(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+Nl&&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]+Nl&&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 _o={exports:{}};(function(s,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof Or<"u"&&Or,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]"],u=ArrayBuffer.isView||function(R){return R&&c.indexOf(Object.prototype.toString.call(R))>-1};function h(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=h(R),x=d(x);var G=this.map[R];this.map[R]=G?G+", "+x:x},f.prototype.delete=function(R){delete this.map[h(R)]},f.prototype.get=function(R){return R=h(R),this.has(R)?this.map[R]:null},f.prototype.has=function(R){return this.map.hasOwnProperty(h(R))},f.prototype.set=function(R,x){this.map[h(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 y(R){return new Promise(function(x,G){R.onload=function(){x(R.result)},R.onerror=function(){G(R.error)}})}function v(R){var x=new FileReader,G=y(x);return x.readAsArrayBuffer(R),G}function b(R){var x=new FileReader,G=y(x);return x.readAsText(R),G}function C(R){for(var x=new Uint8Array(R),G=new Array(x.length),S=0;S<x.length;S++)G[S]=String.fromCharCode(x[S]);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)||u(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(v)}),this.text=function(){var R=p(this);if(R)return R;if(this._bodyBlob)return b(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 S=/([?&])_=[^&]*/;if(S.test(this.url))this.url=this.url.replace(S,"$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 S=G.split("="),w=S.shift().replace(/\+/g," "),T=S.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(S){return S.indexOf(`
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 df(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>zh);return new s.Image}return new Image}const Fl=Yt(async function(e){return e?new Promise((t,i)=>{df().then(r=>{r.onload=()=>{t(r)},r.onerror=n=>{i(n)},r.src=e})}):null});async function Do({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 Fl(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 Fl(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=>Do({element:l,meta:e},t,i)))),s.elements&&(a.elements=await Promise.all(s.elements.map(l=>Do({element:l,meta:e},t,i)))),a}async function en(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>zh),e=new s.Canvas;return e.gpu=!1,e}return document.createElement("canvas")}function tr(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=tr(t==null?void 0:t.elements);if(i)return i}}function gf(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 ff(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 pf(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 tn(s){return s.flatMap(e=>Array.isArray(e)?e.flatMap(t=>t):e).reduce((e,t)=>e+t,0)}const Ef=Yt(()=>El.loadYoga());yo.filters.define("parse",s=>typeof s>"u"?null:typeof s=="string"?`"${pf(s)}"`:ff(s)||Array.isArray(s)?JSON.stringify(s):s);const us=(s,e,t)=>yo.render(s,e,yo.getConfig({autoEscape:!1,defaultFilter:"parse",...t}));async function hs({data:s,template:e,burnCaptions:t=!1,debug:i=!1},r,n,o){var a,A,l,c;const u=await Ef(),h=e??hf;if(!((a=h.templates)!=null&&a.length))throw new Error(`No templates found for template instance: ${h.id}`);let d=h.templates.find(({version:k})=>k===Lo);if(!d){const k=h.templates.map(({version:M})=>`"${M}"`).join(", ");console.warn(`Template renderer expects template version "${Lo}" but got ${k}`),d=h.templates[h.templates.length-1]}const g=await Promise.all(d.content.map(async({scenes:k,root:M})=>{const j={...h.options,...s,intro:h.intro,outro:h.outro};async function V(z,R){return Promise.all(k.map(async({layout:x,duration:G,data:S,derived:w,options:T})=>{var Y,U,q;const se={...j,_index:R,_root:z,_derived:await r({data:s,rootData:z,index:R})},ce=S?JSON.parse(await us(S,se)):{},ne=w?JSON.parse(await us(w,se)):{},me=T?JSON.parse(await us(T,se)):{},Se=G?parseFloat(await us(G,se)):NaN,Re=(Y=d.layouts.find(ge=>ge.name===x))==null?void 0:Y.tree;if(!Re)throw new Error(`Layout tree "${x}" not found in template "${d.id}" layouts.`);const oe=JSON.parse(await us(Re,{...ce,...ne,...me})),de=await Promise.all(oe.flatMap(ge=>Do({element:ge,meta:h.meta},n,o))),Qe=tr(de);return{duration:(isNaN(Se)?null:Se)??((U=Qe==null?void 0:Qe.meta)==null?void 0:U.duration)??0,captions:(q=Qe==null?void 0:Qe.meta)==null?void 0:q.captions,elements:de}}))}if(M){const z=JSON.parse(await us(M,j));return Array.isArray(z)?Promise.all(z.map(async(R,x)=>V(R,x))):Promise.all([V(z,null)])}return Promise.all([V(s,null)])}));if(g.every(k=>k.every(M=>M.every(j=>{const V=tr(j.elements);return!(V!=null&&V.value.src)&&!(V!=null&&V.value.playlist)})))){const k=g.flatMap(M=>M.flatMap(j=>j.map(V=>{const z=tr(V.elements);return!(z!=null&&z.value.src)&&!(z!=null&&z.value.playlist)&&(z==null?void 0:z.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(j=>j.duration<=0))))throw new Error("No scenes have any duration, video can not be processed");const y=g.reduce((k,M)=>{const j=M.reduce((V,z)=>{const R=z.filter(x=>x.duration>0);return R.length>0?[...V,R]:V},[]);return j.length>0?[...k,j]:k},[]),v=((A=h.meta)==null?void 0:A.frameRate)??30,b=((l=h.meta)==null?void 0:l.resolution)??1080,C=((c=h.meta)==null?void 0:c.transitionDuration)??1/3,Q=gf(y,C),B=tn(Q),L=await Promise.all(y.map((k,M)=>{const j=tn(Q[M]),V=tn(Q.slice(0,M));return Promise.all(k.map((z,R)=>Promise.all(z.map(async({duration:x,captions:G,elements:S},w)=>{var T,Y;const U=await en(),q=await en(),se=await en(),ce=await en(),ne=tr(S),me=tn([...Q.slice(0,M),...Q[M].slice(0,R),...Q[M][R].slice(0,w)]);return{draw:({canvas:Re,currentTime:oe})=>{const de=Math.max(0,oe-V),Qe=Math.max(0,oe-me);To({yoga:u,debug:i,canvas:Re,cropCanvas:U,posterCanvas:ce,letterboxCanvas:q,elements:S,currentTime:oe,contentTime:de,sceneTime:Qe,totalDuration:B,contentDuration:j,sceneDuration:x}),G&&t&&af({canvas:Re,dx:0,dy:0,dw:Re.width,dh:Re.height,vttCaptions:G,sceneTime:Qe+((ne==null?void 0:ne.meta.start)??0)})},duration:x,transitionCanvas:se,id:uf(),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:v,resolution:b,transitionDuration:C,fonts:d.fonts??[],duration:B}}const Lo="3",If={name:"@vouchfor/embeds-legacy",version:"0.0.0-experiment.8f3c7fb",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds-legacy.js",module:"dist/es/embeds-legacy.js",type:"module",types:"dist/es/src/index.d.ts",exports:{".":"./dist/es/embeds-legacy.js"},files:["dist","src"],publishConfig:{tag:"experiment",access:"public"},engines:{node:">=18.18.0"},scripts:{build:"rm -rf dist && tsc && yarn build:self","build:deps":"yarn --cwd ../media-player-legacy 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-legacy":"^8.2.2","@vouchfor/media-player-legacy":"0.0.0-experiment.8f3c7fb",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-legacy":"0.0.0-experiment.8f3c7fb","@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 mf(s){const{publicApiUrl:e}=_r(s),t=Li();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function Cf(s){var n,o,a,A,l,c,u,h,d,g,f,p;if(typeof window>"u")return{client:null,tab:null,request:Li()};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=Li();return e||(e=mf(s),(h=(u=window.localStorage)==null?void 0:u.setItem)==null||h.call(u,"vouch-uid-visitor",e)),t||(t=Li(),(g=(d=window.localStorage)==null?void 0:d.setItem)==null||g.call(d,"vouch-uid-client",t)),i||(i=Li(),(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 yf(s,e){return s&&"vouchId"in s?s.vouchId:(e==null?void 0:e.id)??null}function vf(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:If.version,templateVersion:Lo,...i}}const Nl=1;class Bf{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const r=yf(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}=_r(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":vf(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+Nl&&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]+Nl&&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 _o={exports:{}};(function(s,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof Or<"u"&&Or,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]"],u=ArrayBuffer.isView||function(R){return R&&c.indexOf(Object.prototype.toString.call(R))>-1};function h(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=h(R),x=d(x);var G=this.map[R];this.map[R]=G?G+", "+x:x},f.prototype.delete=function(R){delete this.map[h(R)]},f.prototype.get=function(R){return R=h(R),this.has(R)?this.map[R]:null},f.prototype.has=function(R){return this.map.hasOwnProperty(h(R))},f.prototype.set=function(R,x){this.map[h(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 y(R){return new Promise(function(x,G){R.onload=function(){x(R.result)},R.onerror=function(){G(R.error)}})}function v(R){var x=new FileReader,G=y(x);return x.readAsArrayBuffer(R),G}function b(R){var x=new FileReader,G=y(x);return x.readAsText(R),G}function C(R){for(var x=new Uint8Array(R),G=new Array(x.length),S=0;S<x.length;S++)G[S]=String.fromCharCode(x[S]);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)||u(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(v)}),this.text=function(){var R=p(this);if(R)return R;if(this._bodyBlob)return b(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 S=/([?&])_=[^&]*/;if(S.test(this.url))this.url=this.url.replace(S,"$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 S=G.split("="),w=S.shift().replace(/\+/g," "),T=S.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(S){return S.indexOf(`
153
153
  `)===0?S.substr(1,S.length):S}).forEach(function(S){var w=S.split(":"),T=w.shift().trim();if(T){var Y=w.join(":").trim();x.append(T,Y)}}),x}B.call($.prototype);function j(R,x){if(!(this instanceof j))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(j.prototype),j.prototype.clone=function(){return new j(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},j.error=function(){var R=new j(null,{status:0,statusText:""});return R.type="error",R};var V=[301,302,303,307,308];j.redirect=function(R,x){if(V.indexOf(x)===-1)throw new RangeError("Invalid status code");return new j(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 S=Error(x);this.stack=S.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function z(R,x){return new Promise(function(G,S){var w=new $(R,x);if(w.signal&&w.signal.aborted)return S(new o.DOMException("Aborted","AbortError"));var T=new XMLHttpRequest;function Y(){T.abort()}T.onload=function(){var q={status:T.status,statusText:T.statusText,headers:M(T.getAllResponseHeaders()||"")};q.url="responseURL"in T?T.responseURL:q.headers.get("X-Request-URL");var se="response"in T?T.response:T.responseText;setTimeout(function(){G(new j(se,q))},0)},T.onerror=function(){setTimeout(function(){S(new TypeError("Network request failed"))},0)},T.ontimeout=function(){setTimeout(function(){S(new TypeError("Network request failed"))},0)},T.onabort=function(){setTimeout(function(){S(new o.DOMException("Aborted","AbortError"))},0)};function U(q){try{return q===""&&a.location.href?a.location.href:q}catch{return q}}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(q){T.setRequestHeader(q,d(x.headers[q]))}):w.headers.forEach(function(q,se){T.setRequestHeader(se,q)}),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 z.polyfill=!0,a.fetch||(a.fetch=z,a.Headers=f,a.Request=$,a.Response=j),o.Headers=f,o.Request=$,o.Response=j,o.fetch=z,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})(_o,_o.exports);var Qf=_o.exports;const Ml=pl(Qf);async function bf(s){var e;try{if((e=await Ml(s,{method:"HEAD"}))!=null&&e.ok)return s}catch{return}}async function ko({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=>bf(o));e=(await Promise.all(n)).find(Boolean)}return e}async function Sf(s){try{return(await Ml(s)).text()}catch{return null}}async function wf(s){return s=s.trim(),s.startsWith("http")||s.startsWith("blob:")?Sf(s):s}const Rf=Yt(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?wf(A):null},{cacheKey:([s,{language:e}])=>JSON.stringify({...s,language:e})}),xf=Yt(async s=>{var e,t,i,r,n,o,a,A,l,c,u;const[h,d,g]=await Promise.all([ko({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]}),ko({sources:[(o=(n=s==null?void 0:s.answer)==null?void 0:n.media)==null?void 0:o.playlist]}),ko({sources:[((A=(a=s==null?void 0:s.answer)==null?void 0:a.media)==null?void 0:A.reducedQuality)??((u=(c=(l=s==null?void 0:s.answer)==null?void 0:l.media)==null?void 0:c.videos)==null?void 0:u.xs)]})]);return{src:h,playlist:d,preview:g}},{cacheKey:([s])=>{var e,t,i,r,n,o,a,A,l,c,u;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)??((u=(c=(l=s==null?void 0:s.answer)==null?void 0:l.media)==null?void 0:c.videos)==null?void 0:u.xs)})}});function Pl(s){var e,t,i,r,n,o,a,A,l,c,u,h;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"?"":((h=(u=(c=(l=s==null?void 0:s.answer)==null?void 0:l.contact)==null?void 0:c.client)==null?void 0:u.name)==null?void 0:h.trim())??"",[f,p]=d.split(" ");return{name:d,firstName:f,lastName:p,companyName:g}}const Tf=Yt(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 Fo({data:s,rootData:e,index:t},i){var r,n,o,a,A,l,c,u,h,d,g,f,p,y,v,b,C,Q,B,L,_,$,k;const[M,j,V]=await Promise.all([Tf(s,e,t),xf(e),Rf({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)??((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=(f=(g=e==null?void 0:e.answer)==null?void 0:g.transcription)==null?void 0:f.translation)==null?void 0:p.language},i)]),z=Pl(e);return{...j,...z,key:M,captions:V,answerLabel:((y=e==null?void 0:e.answer)==null?void 0:y.label)??(e==null?void 0:e.title),prevAnswerLabel:t?((Q=(C=(b=(v=s==null?void 0:s.questions)==null?void 0:v.items)==null?void 0:b[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=>Pl(R).name===z.name))===t:!0}}const sn={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 Df({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,u;const h=(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=(u=(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:u.split("-")[0];return h&&sn[h]&&!i.find(g=>g.value===h)&&i.push({value:h,label:sn[h]}),d&&sn[d]&&!i.find(g=>g.value===d)&&i.push({value:d,label:sn[d]}),i},[]))??[]}/**
154
154
  * @license
155
155
  * Copyright 2018 Google LLC
@@ -149,7 +149,7 @@ ${e}`,_g=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),kg=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 rf(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Hu);return new s.Image}return new Image}const wl=Ut(async function(e){return e?new Promise((t,i)=>{rf().then(r=>{r.onload=()=>{t(r)},r.onerror=n=>{i(n)},r.src=e})}):null});async function Qo({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 wl(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 wl(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=>Qo({element:l,meta:e},t,i)))),s.elements&&(a.elements=await Promise.all(s.elements.map(l=>Qo({element:l,meta:e},t,i)))),a}async function Wr(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Hu),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 nf(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 of(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 af(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 qr(s){return s.flatMap(e=>Array.isArray(e)?e.flatMap(t=>t):e).reduce((e,t)=>e+t,0)}const Af=Ut(()=>ll.loadYoga());go.filters.define("parse",s=>typeof s>"u"?null:typeof s=="string"?`"${af(s)}"`:of(s)||Array.isArray(s)?JSON.stringify(s):s);const As=(s,e,t)=>go.render(s,e,go.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??sf;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===So);if(!d){const k=u.templates.map(({version:M})=>`"${M}"`).join(", ");console.warn(`Template renderer expects template version "${So}" 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=>Qo({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 y=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},[]),v=((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=nf(y,C),B=qr(Q),L=await Promise.all(y.map((k,M)=>{const q=qr(Q[M]),V=qr(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 Wr(),W=await Wr(),se=await Wr(),ce=await Wr(),ne=zs(b),me=qr([...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);Bo({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&&Xg({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:tf(),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:v,resolution:S,transitionDuration:C,fonts:d.fonts??[],duration:B}}const So="3",lf={name:"@vouchfor/embeds-legacy",version:"0.0.0-experiment.2df224d",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds-legacy.js",module:"dist/es/embeds-legacy.js",type:"module",types:"dist/es/src/index.d.ts",exports:{".":"./dist/es/embeds-legacy.js"},files:["dist","src"],publishConfig:{tag:"experiment",access:"public"},engines:{node:">=18.18.0"},scripts:{build:"rm -rf dist && tsc && yarn build:self","build:deps":"yarn --cwd ../media-player-legacy 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-legacy":"^8.2.2","@vouchfor/media-player-legacy":"0.0.0-experiment.2df224d",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-legacy":"0.0.0-experiment.2df224d","@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 cf(s){const{publicApiUrl:e}=wr(s),t=Gi();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function hf(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=cf(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 uf(s,e){return s&&"vouchId"in s?s.vouchId:(e==null?void 0:e.id)??null}function df(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:lf.version,templateVersion:So,...i}}const Rl=1;class gf{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const r=uf(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}=wr(this.host.env),{client:i,tab:r,request:n,visitor:o}=hf(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":df(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+Rl&&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]+Rl&&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 bo={exports:{}};(function(s,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof _r<"u"&&_r,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 y(R){return new Promise(function(x,G){R.onload=function(){x(R.result)},R.onerror=function(){G(R.error)}})}function v(R){var x=new FileReader,G=y(x);return x.readAsArrayBuffer(R),G}function S(R){var x=new FileReader,G=y(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(v)}),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(`
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 rf(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Hu);return new s.Image}return new Image}const wl=Ut(async function(e){return e?new Promise((t,i)=>{rf().then(r=>{r.onload=()=>{t(r)},r.onerror=n=>{i(n)},r.src=e})}):null});async function Qo({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 wl(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 wl(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=>Qo({element:l,meta:e},t,i)))),s.elements&&(a.elements=await Promise.all(s.elements.map(l=>Qo({element:l,meta:e},t,i)))),a}async function Wr(){if(typeof window>"u"){const s=await Promise.resolve().then(()=>Hu),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 nf(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 of(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 af(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 qr(s){return s.flatMap(e=>Array.isArray(e)?e.flatMap(t=>t):e).reduce((e,t)=>e+t,0)}const Af=Ut(()=>ll.loadYoga());go.filters.define("parse",s=>typeof s>"u"?null:typeof s=="string"?`"${af(s)}"`:of(s)||Array.isArray(s)?JSON.stringify(s):s);const As=(s,e,t)=>go.render(s,e,go.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??sf;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===So);if(!d){const k=u.templates.map(({version:M})=>`"${M}"`).join(", ");console.warn(`Template renderer expects template version "${So}" 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=>Qo({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 y=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},[]),v=((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=nf(y,C),B=qr(Q),L=await Promise.all(y.map((k,M)=>{const q=qr(Q[M]),V=qr(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 Wr(),W=await Wr(),se=await Wr(),ce=await Wr(),ne=zs(b),me=qr([...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);Bo({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&&Xg({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:tf(),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:v,resolution:S,transitionDuration:C,fonts:d.fonts??[],duration:B}}const So="3",lf={name:"@vouchfor/embeds-legacy",version:"0.0.0-experiment.8f3c7fb",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds-legacy.js",module:"dist/es/embeds-legacy.js",type:"module",types:"dist/es/src/index.d.ts",exports:{".":"./dist/es/embeds-legacy.js"},files:["dist","src"],publishConfig:{tag:"experiment",access:"public"},engines:{node:">=18.18.0"},scripts:{build:"rm -rf dist && tsc && yarn build:self","build:deps":"yarn --cwd ../media-player-legacy 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-legacy":"^8.2.2","@vouchfor/media-player-legacy":"0.0.0-experiment.8f3c7fb",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-legacy":"0.0.0-experiment.8f3c7fb","@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 cf(s){const{publicApiUrl:e}=wr(s),t=Gi();return navigator.sendBeacon(`${e}/api/visitor`,JSON.stringify({visitorId:t})),t}function hf(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=cf(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 uf(s,e){return s&&"vouchId"in s?s.vouchId:(e==null?void 0:e.id)??null}function df(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:lf.version,templateVersion:So,...i}}const Rl=1;class gf{constructor(e){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(t,i)=>{const r=uf(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}=wr(this.host.env),{client:i,tab:r,request:n,visitor:o}=hf(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":df(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:t,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+Rl&&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]+Rl&&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 bo={exports:{}};(function(s,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof _r<"u"&&_r,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 y(R){return new Promise(function(x,G){R.onload=function(){x(R.result)},R.onerror=function(){G(R.error)}})}function v(R){var x=new FileReader,G=y(x);return x.readAsArrayBuffer(R),G}function S(R){var x=new FileReader,G=y(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(v)}),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
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})(bo,bo.exports);var ff=bo.exports;const xl=Al(ff);async function pf(s){var e;try{if((e=await xl(s,{method:"HEAD"}))!=null&&e.ok)return s}catch{return}}async function wo({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=>pf(o));e=(await Promise.all(n)).find(Boolean)}return e}async function Ef(s){try{return(await xl(s)).text()}catch{return null}}async function If(s){return s=s.trim(),s.startsWith("http")||s.startsWith("blob:")?Ef(s):s}const mf=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?If(A):null},{cacheKey:([s,{language:e}])=>JSON.stringify({...s,language:e})}),Cf=Ut(async s=>{var e,t,i,r,n,o,a,A,l,c,h;const[u,d,g]=await Promise.all([wo({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]}),wo({sources:[(o=(n=s==null?void 0:s.answer)==null?void 0:n.media)==null?void 0:o.playlist]}),wo({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 Tl(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 yf=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 Ro({data:s,rootData:e,index:t},i){var r,n,o,a,A,l,c,h,u,d,g,f,p,y,v,S,C,Q,B,L,_,$,k;const[M,q,V]=await Promise.all([yf(s,e,t),Cf(e),mf({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=Tl(e);return{...q,...X,key:M,captions:V,answerLabel:((y=e==null?void 0:e.answer)==null?void 0:y.label)??(e==null?void 0:e.title),prevAnswerLabel:t?((Q=(C=(S=(v=s==null?void 0:s.questions)==null?void 0:v.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=>Tl(R).name===X.name))===t:!0}}const jr={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&&jr[u]&&!i.find(g=>g.value===u)&&i.push({value:u,label:jr[u]}),d&&jr[d]&&!i.find(g=>g.value===d)&&i.push({value:d,label:jr[d]}),i},[]))??[]}/**
154
154
  * @license
155
155
  * Copyright 2018 Google LLC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vouchfor/embeds-legacy",
3
- "version": "0.0.0-experiment.2df224d",
3
+ "version": "0.0.0-experiment.8f3c7fb",
4
4
  "license": "MIT",
5
5
  "author": "Aaron Williams",
6
6
  "main": "dist/es/embeds-legacy.js",
@@ -44,7 +44,7 @@
44
44
  "@a11y/focus-trap": "^1.0.5",
45
45
  "@lit/task": "^1.0.0",
46
46
  "@vouchfor/canvas-video-legacy": "^8.2.2",
47
- "@vouchfor/media-player-legacy": "0.0.0-experiment.2df224d",
47
+ "@vouchfor/media-player-legacy": "0.0.0-experiment.8f3c7fb",
48
48
  "uuid": "^9.0.1"
49
49
  },
50
50
  "peerDependencies": {
@@ -63,7 +63,7 @@
63
63
  "@types/mocha": "^10.0.6",
64
64
  "@vouchfor/eslint-config": "^1.0.1",
65
65
  "@vouchfor/prettier-config": "^1.0.1",
66
- "@vouchfor/video-utils-legacy": "0.0.0-experiment.2df224d",
66
+ "@vouchfor/video-utils-legacy": "0.0.0-experiment.8f3c7fb",
67
67
  "@web/dev-server-esbuild": "^1.0.2",
68
68
  "@web/test-runner": "^0.18.1",
69
69
  "@web/test-runner-browserstack": "^0.7.1",