@vouchfor/embeds 1.2.0 → 1.2.1

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.
@@ -168,7 +168,7 @@ ${t}`,t1=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),e1=Objec
168
168
  "width": {{ it.root?.answer?.settings?.crop?.width }},
169
169
  "height": {{ it.root?.answer?.settings?.crop?.height }}
170
170
  }
171
- }`}],root:"{{ it.outro?.questions?.items }}"}],system:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()},tv={id:"073977ec-6384-4329-b7c5-8275fb513e74",name:"None",entityId:"none",templateId:"a95e537e-fb4d-4d2f-9c72-86c0925c7176",templates:[J1],meta:{frameRate:30,resolution:720,transitionDuration:1/3},system:!0,default:0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};async function ev(){if(typeof window>"u"){const i=await Promise.resolve().then(()=>e2);return new i.Image}return new Image}const e0=ks(async function(i){return i?new Promise((t,e)=>{ev().then(r=>{r.onload=()=>{t(r)},r.onerror=n=>{e(n)},r.src=i})}):null});async function vc({element:i,meta:t},e,r){var n,o,l;let d={...i};const{node:f}=i;if((f==null?void 0:f.type)==="video"&&((n=f==null?void 0:f.value)!=null&&n.src||(o=f==null?void 0:f.value)!=null&&o.playlist)){const p=await e(f.value,t);let g;try{g=await e0(f.value.poster)}catch{g=null}d={...d,node:{...f,video:p,poster:g,meta:await r(f.value,p.node,t)}}}if((f==null?void 0:f.type)==="image"&&f.value){let p;try{p=await e0(f.value)}catch{p=null}d={...d,node:{...f,image:p}}}return d.node&&(l=i.node)!=null&&l.elements&&(d.node.elements=await Promise.all(i.node.elements.map(p=>vc({element:p,meta:t},e,r)))),i.elements&&(d.elements=await Promise.all(i.elements.map(p=>vc({element:p,meta:t},e,r)))),d}async function Po(){if(typeof window>"u"){const i=await Promise.resolve().then(()=>e2),t=new i.Canvas;return t.gpu=!1,t}return document.createElement("canvas")}async function rv(i){var t;try{if((t=await Km(i,{method:"HEAD"}))!=null&&t.ok)return i}catch{return}}async function iv({sources:i}){let t=null;if(i){const e=i.filter(Boolean).map(r=>rv(r));t=(await Promise.all(e)).find(Boolean)}return t}function Aa(i=[]){var t;for(const e of i){if(((t=e==null?void 0:e.node)==null?void 0:t.type)==="video")return e.node;const r=Aa(e==null?void 0:e.elements);if(r)return r}}function sv(i,t){return i.reduce((e,r,n)=>[...e,r.map(({duration:o},l)=>n===i.length-1&&l===r.length-1?o:o-t)],[])}function nv(i){if(i===null||typeof i!="object")return!1;if(Object.getPrototypeOf(i)===null)return!0;let t=i;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(i)===t}function av(i){return i.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\f/g,"\\f").replace(/"/g,'\\"')}function Oo(i){return i.flatMap(t=>t).reduce((t,e)=>t+e,0)}po.filters.define("parse",i=>typeof i>"u"?null:typeof i=="string"?`"${av(i)}"`:nv(i)||Array.isArray(i)?JSON.stringify(i):i),po.helpers.define("resolve-source",ks(async i=>{const{sources:t}=i.params[0]??{},e=t==null?void 0:t.filter(Boolean),r=e==null?void 0:e.find(l=>l.includes("blob:")),n=e==null?void 0:e.find(l=>!l.includes("http")),o=r??n??await iv({sources:t});return o?`"${o}"`:"null"},{cacheKey:([i])=>JSON.stringify(i.params[0]??{})}));const Ta=(i,t,e)=>po.render(i,t,po.getConfig({autoEscape:!1,defaultFilter:"parse",async:!0,asyncHelpers:["resolve-source"],...e}));async function Sn({data:i,template:t,burnCaptions:e=!1,debug:r=!1},n,o){var l,d,f,p;const g=t??tv;if(!((l=g.templates)!=null&&l.length))throw new Error(`No templates found for template instance: ${g.id}`);let v=g.templates.find(({version:U})=>U===yc);if(!v){const U=g.templates.map(({version:x})=>`"${x}"`).join(", ");console.warn(`Template renderer expects template version "${yc}" but got ${U}`),v=g.templates[g.templates.length-1]}const E=await Promise.all(v.content.map(async({scenes:U,root:x})=>{const O={...g.options,...i,intro:g.intro,outro:g.outro};async function K(B,at){return Promise.all(U.map(async({layout:st,duration:J,data:kt,options:ft})=>{var wt,Pt,F;const j={...O,index:at,root:B},bt=kt?JSON.parse(await Ta(kt,j)):{},N=ft?JSON.parse(await Ta(ft,j)):{},G=J?parseFloat(await Ta(J,j)):NaN,Z=(wt=v.layouts.find(Bt=>Bt.name===st))==null?void 0:wt.tree;if(!Z)throw new Error(`Layout tree "${st}" not found in template "${v.id}" layouts.`);const gt=JSON.parse(await Ta(Z,{...bt,...N})),vt=await Promise.all(gt.flatMap(Bt=>vc({element:Bt,meta:g.meta},n,o))),It=Aa(vt);return{duration:(isNaN(G)?null:G)??((Pt=It==null?void 0:It.meta)==null?void 0:Pt.duration)??0,captions:(F=It==null?void 0:It.meta)==null?void 0:F.captions,elements:vt}}))}if(x){const B=JSON.parse(await Ta(x,O));return Array.isArray(B)?(await Promise.all(B.map(async(at,st)=>K(at,st)))).flatMap(at=>at):K(B,null)}return K(i,null)}));if(E.every(U=>U.every(x=>{const O=Aa(x.elements);return!(O!=null&&O.value.src)&&!(O!=null&&O.value.playlist)}))){const U=E.flatMap(x=>x.map(O=>{const K=Aa(O.elements);return!(K!=null&&K.value.src)&&!(K!=null&&K.value.playlist)&&(K==null?void 0:K.value.id)}).filter(Boolean)).join(", ");throw new Error(`Video(s) with ID ${U} failed to load, video can not be processed`)}if(E.every(U=>U.every(x=>x.duration<=0)))throw new Error("No scenes have any duration, video can not be processed");const A=E.reduce((U,x)=>{const O=x.filter(K=>K.duration>0);return O.length>0&&(U=[...U,O]),U},[]),T=((d=g.meta)==null?void 0:d.frameRate)??30,w=((f=g.meta)==null?void 0:f.resolution)??720,C=((p=g.meta)==null?void 0:p.transitionDuration)??1/3,D=sv(A,C),M=Oo(D);return{scenes:(await Promise.all(A.map((U,x)=>{const O=Oo(D[x]),K=Oo(D.slice(0,x));return Promise.all(U.map(async({duration:B,captions:at,elements:st},J)=>{var kt,ft;const wt=await Po(),Pt=await Po(),F=await Po(),j=await Po(),bt=Aa(st),N=Oo([...D.slice(0,x),...D[x].slice(0,J)]);return{draw:({canvas:G,currentTime:Z})=>{const gt=Math.max(0,Z-K),vt=Math.max(0,Z-N);mc({debug:r,canvas:G,cropCanvas:wt,posterCanvas:j,letterboxCanvas:Pt,elements:st,currentTime:Z,contentTime:gt,sceneTime:vt,totalDuration:M,contentDuration:O,sceneDuration:B}),at&&e&&Q1({canvas:G,dx:0,dy:0,dw:G.width,dh:G.height,vttCaptions:at,sceneTime:vt+((bt==null?void 0:bt.meta.start)??0)})},duration:B,transitionCanvas:F,start:N,video:bt==null?void 0:bt.video,videoMeta:bt==null?void 0:bt.meta,audio:{duration:B,src:(kt=bt==null?void 0:bt.value)==null?void 0:kt.src,start:(ft=bt==null?void 0:bt.meta)==null?void 0:ft.start}}}))}))).flatMap(U=>U),frameRate:T,resolution:w,transitionDuration:C,fonts:v.fonts??[],duration:M}}const yc="2",ov={name:"@vouchfor/embeds",version:"1.2.0",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds.js",module:"dist/es/embeds.js",type:"module",types:"dist/es/src/index.d.ts",exports:{".":"./dist/es/embeds.js"},files:["dist","src"],publishConfig:{tag:"latest",access:"public"},scripts:{build:"rm -rf dist && tsc && yarn build:self","build:deps":"yarn --cwd ../media-player build","build:self":"vite build --mode iife && vite build --mode es && node scripts/build.cjs","build:package":"yarn build","build:storybook":"yarn prebuild && storybook build","generate:manifest":"wca src --outFile custom-elements.json",lint:"eslint . --quiet","lint:fix":"eslint . --fix","lint:staged":"lint-staged",prepublishOnly:"yarn build",size:"size-limit",storybook:"yarn prebuild && storybook dev -p 6007",prebuild:"yarn build:deps && yarn generate:manifest",test:"rm -rf test/lib && yarn prebuild && vite build --mode test && web-test-runner","test:ci":"yarn test --config web-test-runner.ci.config.js"},"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/media-player":"^2.1.0",uuid:"^9.0.1"},peerDependencies:{lit:"^3.1.0"},devDependencies:{"@esm-bundle/chai":"^4.3.4-fix.0","@open-wc/testing":"^3.2.0","@storybook/addon-essentials":"^7.4.5","@storybook/addon-links":"^7.4.5","@storybook/blocks":"^7.4.5","@storybook/web-components":"^7.4.5","@storybook/web-components-vite":"^7.4.5","@types/mocha":"^10.0.1","@vouchfor/eslint-config":"^1.0.0","@vouchfor/prettier-config":"^1.0.0","@web/dev-server-esbuild":"^0.4.1","@web/test-runner":"^0.17.1","@web/test-runner-browserstack":"^0.6.1","@web/test-runner-mocha":"^0.8.1","@web/test-runner-playwright":"^0.10.1",dotenv:"^16.3.1",eslint:"^8.50.0","eslint-plugin-import":"^2.28.1",glob:"^10.3.10","lint-staged":"^14.0.1",lit:"^3.1.0",lodash:"^4.17.21",prettier:"^3.0.3",react:"^18.2.0","react-dom":"^18.2.0","rollup-plugin-internal":"^1.0.4",sinon:"^17.0.1",storybook:"^7.4.5",typescript:"^5.1.3",vite:"^4.4.9","vite-plugin-commonjs":"^0.10.0","vite-plugin-dts":"^3.6.0","web-component-analyzer":"^1.1.7"}};function lv(i){const{publicApiUrl:t}=uo(i),e=rn();return navigator.sendBeacon(`${t}/api/visitor`,JSON.stringify({visitorId:e})),e}function cv(i){var o,l,d,f,p,g,v,E,A,T,w,C;if(typeof window>"u")return{client:null,tab:null,request:rn()};let t=(l=(o=window.localStorage)==null?void 0:o.getItem)==null?void 0:l.call(o,"vouch-uid-visitor"),e=(f=(d=window.localStorage)==null?void 0:d.getItem)==null?void 0:f.call(d,"vouch-uid-client"),r=(g=(p=window.sessionStorage)==null?void 0:p.getItem)==null?void 0:g.call(p,"vouch-uid-tab");const n=rn();return t||(t=lv(i),(E=(v=window.localStorage)==null?void 0:v.setItem)==null||E.call(v,"vouch-uid-visitor",t)),e||(e=rn(),(T=(A=window.localStorage)==null?void 0:A.setItem)==null||T.call(A,"vouch-uid-client",e)),r||(r=rn(),(C=(w=window.sessionStorage)==null?void 0:w.setItem)==null||C.call(w,"vouch-uid-tab",r)),{client:e,tab:r,request:n,visitor:t}}function hv(i,t){return i&&"vouchId"in i?i.vouchId:(t==null?void 0:t.id)??null}function dv(i="embedded_player"){var n,o;const[t,e]=((o=(n=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:n.split)==null?void 0:o.call(n,"/"))??[],r={};return[...new URLSearchParams(location.search).entries()].forEach(([l,d])=>{if(/utm/.test(l)){const f=l.toLowerCase().replace(/[-_][a-z0-9]/g,p=>p.slice(-1).toUpperCase());r[f]=d}}),{source:i,time:new Date,region:e,country:t,screenHeight:window.screen.height,screenWidth:window.screen.width,referrer:document.referrer,currentUrl:location.href,embedType:"media-player-embed",embedVersion:ov.version,templateVersion:yc,...r}}const r0=1;class uv{constructor(t){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(e,r)=>{const n=hv(r,this.host.vouch);!n||this.host.disableTracking||this._batchedEvents.push({event:e,payload:{...r,vouchId:n,time:new Date().toISOString()}})},this._sendTrackingEvent=()=>{if(this._batchedEvents.length<=0)return;const{publicApiUrl:e}=uo(this.host.env),{client:r,tab:n,request:o,visitor:l}=cv(this.host.env);navigator.sendBeacon(`${e}/api/batchevents`,JSON.stringify({payload:{events:this._batchedEvents},context:{"x-uid-client":r,"x-uid-tab":n,"x-uid-request":o,"x-uid-visitor":l,"x-reporting-metadata":dv(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:e,key:r}=this._currentlyPlayingVideo;this._streamLatestTime[r]>this._streamStartTime[r]+r0&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:e,streamStart:this._streamStartTime[r],streamEnd:this._streamLatestTime[r]}),delete this._streamStartTime[r],delete this._streamLatestTime[r]}},this._handleVouchLoaded=({detail:e})=>{e&&(this._hasLoaded[e]||(this._createTrackingEvent("VOUCH_LOADED",{vouchId:e}),this._hasLoaded[e]=!0))},this._handlePlay=()=>{this._hasPlayed||(this._createTrackingEvent("VIDEO_PLAYED",{streamStart:this.host.currentTime}),this._hasPlayed=!0)},this._handleVideoPlay=({detail:{id:e,key:r}})=>{this._answersViewed[r]||(this._createTrackingEvent("VOUCH_RESPONSE_VIEWED",{answerId:e}),this._answersViewed[r]=!0)},this._handleVideoTimeUpdate=({detail:{id:e,key:r,node:n}})=>{var o,l;!this.host.paused&&e===((l=(o=this.host.scene)==null?void 0:o.video)==null?void 0:l.id)&&(this._currentlyPlayingVideo={id:e,key:r,node:n},this._streamLatestTime[r]=n.currentTime,this._streamStartTime[r]||(this._streamStartTime[r]=n.currentTime,this._streamLatestTime[r]=n.currentTime))},this._handleVideoPause=({detail:{id:e,key:r}})=>{this._streamLatestTime[r]>this._streamStartTime[r]+r0&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:e,streamStart:this._streamStartTime[r],streamEnd:this._streamLatestTime[r]}),delete this._streamStartTime[r],delete this._streamLatestTime[r]},this._pageUnloading=()=>{this._streamEnded(),this._sendTrackingEvent()},this._handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this._pageUnloading()},this._handlePageHide=()=>{this._pageUnloading()},this.host=t,t.addController(this)}hostConnected(){requestAnimationFrame(()=>{var t,e,r,n;"onvisibilitychange"in document?document.addEventListener("visibilitychange",this._handleVisibilityChange):window.addEventListener("pagehide",this._handlePageHide),this.host.addEventListener("vouch:loaded",this._handleVouchLoaded),(t=this.host.mediaPlayer)==null||t.addEventListener("play",this._handlePlay),(e=this.host.mediaPlayer)==null||e.addEventListener("video:play",this._handleVideoPlay),(r=this.host.mediaPlayer)==null||r.addEventListener("video:pause",this._handleVideoPause),(n=this.host.mediaPlayer)==null||n.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var t,e,r,n;this._pageUnloading(),"onvisibilitychange"in document?document.removeEventListener("visibilitychange",this._handleVisibilityChange):window.removeEventListener("pagehide",this._handlePageHide),this.host.removeEventListener("vouch:loaded",this._handleVouchLoaded),(t=this.host.mediaPlayer)==null||t.removeEventListener("play",this._handlePlay),(e=this.host.mediaPlayer)==null||e.removeEventListener("video:play",this._handleVideoPlay),(r=this.host.mediaPlayer)==null||r.removeEventListener("video:pause",this._handleVideoPause),(n=this.host.mediaPlayer)==null||n.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}const fv=i=>{class t extends i{constructor(){super(...arguments),this._mediaPlayerRef=wr()}get waiting(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.waiting}get initialised(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.initialised}get seeking(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.seeking}get paused(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.paused}get captions(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.captions}get fullscreen(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.fullscreen}get duration(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.duration}set currentTime(r){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.currentTime=r)}get currentTime(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.currentTime)??0}set playbackRate(r){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.playbackRate=r)}get playbackRate(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.playbackRate)??1}set volume(r){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.volume=r)}get volume(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.volume)??1}set muted(r){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.muted=r)}get muted(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.muted)??!1}get scene(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.scene)??null}get scenes(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.scenes)??[]}get sceneConfig(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.sceneConfig)??null}get videoState(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.videoState}get mediaPlayer(){return this._mediaPlayerRef.value}play(){var r;(r=this._mediaPlayerRef.value)==null||r.play()}pause(){var r;(r=this._mediaPlayerRef.value)==null||r.pause()}reset(r=0,n=!1){var o;(o=this._mediaPlayerRef.value)==null||o.reset(r,n)}setScene(r){var n;(n=this._mediaPlayerRef.value)==null||n.setScene(r)}}return t};/**
171
+ }`}],root:"{{ it.outro?.questions?.items }}"}],system:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()},tv={id:"073977ec-6384-4329-b7c5-8275fb513e74",name:"None",entityId:"none",templateId:"a95e537e-fb4d-4d2f-9c72-86c0925c7176",templates:[J1],meta:{frameRate:30,resolution:720,transitionDuration:1/3},system:!0,default:0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};async function ev(){if(typeof window>"u"){const i=await Promise.resolve().then(()=>e2);return new i.Image}return new Image}const e0=ks(async function(i){return i?new Promise((t,e)=>{ev().then(r=>{r.onload=()=>{t(r)},r.onerror=n=>{e(n)},r.src=i})}):null});async function vc({element:i,meta:t},e,r){var n,o,l;let d={...i};const{node:f}=i;if((f==null?void 0:f.type)==="video"&&((n=f==null?void 0:f.value)!=null&&n.src||(o=f==null?void 0:f.value)!=null&&o.playlist)){const p=await e(f.value,t);let g;try{g=await e0(f.value.poster)}catch{g=null}d={...d,node:{...f,video:p,poster:g,meta:await r(f.value,p.node,t)}}}if((f==null?void 0:f.type)==="image"&&f.value){let p;try{p=await e0(f.value)}catch{p=null}d={...d,node:{...f,image:p}}}return d.node&&(l=i.node)!=null&&l.elements&&(d.node.elements=await Promise.all(i.node.elements.map(p=>vc({element:p,meta:t},e,r)))),i.elements&&(d.elements=await Promise.all(i.elements.map(p=>vc({element:p,meta:t},e,r)))),d}async function Po(){if(typeof window>"u"){const i=await Promise.resolve().then(()=>e2),t=new i.Canvas;return t.gpu=!1,t}return document.createElement("canvas")}async function rv(i){var t;try{if((t=await Km(i,{method:"HEAD"}))!=null&&t.ok)return i}catch{return}}async function iv({sources:i}){let t=null;if(i){const e=i.filter(Boolean).map(r=>rv(r));t=(await Promise.all(e)).find(Boolean)}return t}function Aa(i=[]){var t;for(const e of i){if(((t=e==null?void 0:e.node)==null?void 0:t.type)==="video")return e.node;const r=Aa(e==null?void 0:e.elements);if(r)return r}}function sv(i,t){return i.reduce((e,r,n)=>[...e,r.map(({duration:o},l)=>n===i.length-1&&l===r.length-1?o:o-t)],[])}function nv(i){if(i===null||typeof i!="object")return!1;if(Object.getPrototypeOf(i)===null)return!0;let t=i;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(i)===t}function av(i){return i.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\f/g,"\\f").replace(/"/g,'\\"')}function Oo(i){return i.flatMap(t=>t).reduce((t,e)=>t+e,0)}po.filters.define("parse",i=>typeof i>"u"?null:typeof i=="string"?`"${av(i)}"`:nv(i)||Array.isArray(i)?JSON.stringify(i):i),po.helpers.define("resolve-source",ks(async i=>{const{sources:t}=i.params[0]??{},e=t==null?void 0:t.filter(Boolean),r=e==null?void 0:e.find(l=>l.includes("blob:")),n=e==null?void 0:e.find(l=>!l.includes("http")),o=r??n??await iv({sources:t});return o?`"${o}"`:"null"},{cacheKey:([i])=>JSON.stringify(i.params[0]??{})}));const Ta=(i,t,e)=>po.render(i,t,po.getConfig({autoEscape:!1,defaultFilter:"parse",async:!0,asyncHelpers:["resolve-source"],...e}));async function Sn({data:i,template:t,burnCaptions:e=!1,debug:r=!1},n,o){var l,d,f,p;const g=t??tv;if(!((l=g.templates)!=null&&l.length))throw new Error(`No templates found for template instance: ${g.id}`);let v=g.templates.find(({version:U})=>U===yc);if(!v){const U=g.templates.map(({version:x})=>`"${x}"`).join(", ");console.warn(`Template renderer expects template version "${yc}" but got ${U}`),v=g.templates[g.templates.length-1]}const E=await Promise.all(v.content.map(async({scenes:U,root:x})=>{const O={...g.options,...i,intro:g.intro,outro:g.outro};async function K(B,at){return Promise.all(U.map(async({layout:st,duration:J,data:kt,options:ft})=>{var wt,Pt,F;const j={...O,index:at,root:B},bt=kt?JSON.parse(await Ta(kt,j)):{},N=ft?JSON.parse(await Ta(ft,j)):{},G=J?parseFloat(await Ta(J,j)):NaN,Z=(wt=v.layouts.find(Bt=>Bt.name===st))==null?void 0:wt.tree;if(!Z)throw new Error(`Layout tree "${st}" not found in template "${v.id}" layouts.`);const gt=JSON.parse(await Ta(Z,{...bt,...N})),vt=await Promise.all(gt.flatMap(Bt=>vc({element:Bt,meta:g.meta},n,o))),It=Aa(vt);return{duration:(isNaN(G)?null:G)??((Pt=It==null?void 0:It.meta)==null?void 0:Pt.duration)??0,captions:(F=It==null?void 0:It.meta)==null?void 0:F.captions,elements:vt}}))}if(x){const B=JSON.parse(await Ta(x,O));return Array.isArray(B)?(await Promise.all(B.map(async(at,st)=>K(at,st)))).flatMap(at=>at):K(B,null)}return K(i,null)}));if(E.every(U=>U.every(x=>{const O=Aa(x.elements);return!(O!=null&&O.value.src)&&!(O!=null&&O.value.playlist)}))){const U=E.flatMap(x=>x.map(O=>{const K=Aa(O.elements);return!(K!=null&&K.value.src)&&!(K!=null&&K.value.playlist)&&(K==null?void 0:K.value.id)}).filter(Boolean)).join(", ");throw new Error(`Video(s) with ID ${U} failed to load, video can not be processed`)}if(E.every(U=>U.every(x=>x.duration<=0)))throw new Error("No scenes have any duration, video can not be processed");const A=E.reduce((U,x)=>{const O=x.filter(K=>K.duration>0);return O.length>0&&(U=[...U,O]),U},[]),T=((d=g.meta)==null?void 0:d.frameRate)??30,w=((f=g.meta)==null?void 0:f.resolution)??720,C=((p=g.meta)==null?void 0:p.transitionDuration)??1/3,D=sv(A,C),M=Oo(D);return{scenes:(await Promise.all(A.map((U,x)=>{const O=Oo(D[x]),K=Oo(D.slice(0,x));return Promise.all(U.map(async({duration:B,captions:at,elements:st},J)=>{var kt,ft;const wt=await Po(),Pt=await Po(),F=await Po(),j=await Po(),bt=Aa(st),N=Oo([...D.slice(0,x),...D[x].slice(0,J)]);return{draw:({canvas:G,currentTime:Z})=>{const gt=Math.max(0,Z-K),vt=Math.max(0,Z-N);mc({debug:r,canvas:G,cropCanvas:wt,posterCanvas:j,letterboxCanvas:Pt,elements:st,currentTime:Z,contentTime:gt,sceneTime:vt,totalDuration:M,contentDuration:O,sceneDuration:B}),at&&e&&Q1({canvas:G,dx:0,dy:0,dw:G.width,dh:G.height,vttCaptions:at,sceneTime:vt+((bt==null?void 0:bt.meta.start)??0)})},duration:B,transitionCanvas:F,start:N,video:bt==null?void 0:bt.video,videoMeta:bt==null?void 0:bt.meta,audio:{duration:B,src:(kt=bt==null?void 0:bt.value)==null?void 0:kt.src,start:(ft=bt==null?void 0:bt.meta)==null?void 0:ft.start}}}))}))).flatMap(U=>U),frameRate:T,resolution:w,transitionDuration:C,fonts:v.fonts??[],duration:M}}const yc="2",ov={name:"@vouchfor/embeds",version:"1.2.1",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds.js",module:"dist/es/embeds.js",type:"module",types:"dist/es/src/index.d.ts",exports:{".":"./dist/es/embeds.js"},files:["dist","src"],publishConfig:{tag:"latest",access:"public"},scripts:{build:"rm -rf dist && tsc && yarn build:self","build:deps":"yarn --cwd ../media-player build","build:self":"vite build --mode iife && vite build --mode es && node scripts/build.cjs","build:package":"yarn build","build:storybook":"yarn prebuild && storybook build","generate:manifest":"wca src --outFile custom-elements.json",lint:"eslint . --quiet","lint:fix":"eslint . --fix","lint:staged":"lint-staged",prepublishOnly:"yarn build",size:"size-limit",storybook:"yarn prebuild && storybook dev -p 6007",prebuild:"yarn build:deps && yarn generate:manifest",test:"rm -rf test/lib && yarn prebuild && vite build --mode test && web-test-runner","test:ci":"yarn test --config web-test-runner.ci.config.js"},"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/media-player":"^2.1.0",uuid:"^9.0.1"},peerDependencies:{lit:"^3.1.0"},devDependencies:{"@esm-bundle/chai":"^4.3.4-fix.0","@open-wc/testing":"^3.2.0","@storybook/addon-essentials":"^7.4.5","@storybook/addon-links":"^7.4.5","@storybook/blocks":"^7.4.5","@storybook/web-components":"^7.4.5","@storybook/web-components-vite":"^7.4.5","@types/mocha":"^10.0.1","@vouchfor/eslint-config":"^1.0.0","@vouchfor/prettier-config":"^1.0.0","@web/dev-server-esbuild":"^0.4.1","@web/test-runner":"^0.17.1","@web/test-runner-browserstack":"^0.6.1","@web/test-runner-mocha":"^0.8.1","@web/test-runner-playwright":"^0.10.1",dotenv:"^16.3.1",eslint:"^8.50.0","eslint-plugin-import":"^2.28.1",glob:"^10.3.10","lint-staged":"^14.0.1",lit:"^3.1.0",lodash:"^4.17.21",prettier:"^3.0.3",react:"^18.2.0","react-dom":"^18.2.0","rollup-plugin-internal":"^1.0.4",sinon:"^17.0.1",storybook:"^7.4.5",typescript:"^5.1.3",vite:"^4.4.9","vite-plugin-commonjs":"^0.10.0","vite-plugin-dts":"^3.6.0","web-component-analyzer":"^1.1.7"}};function lv(i){const{publicApiUrl:t}=uo(i),e=rn();return navigator.sendBeacon(`${t}/api/visitor`,JSON.stringify({visitorId:e})),e}function cv(i){var o,l,d,f,p,g,v,E,A,T,w,C;if(typeof window>"u")return{client:null,tab:null,request:rn()};let t=(l=(o=window.localStorage)==null?void 0:o.getItem)==null?void 0:l.call(o,"vouch-uid-visitor"),e=(f=(d=window.localStorage)==null?void 0:d.getItem)==null?void 0:f.call(d,"vouch-uid-client"),r=(g=(p=window.sessionStorage)==null?void 0:p.getItem)==null?void 0:g.call(p,"vouch-uid-tab");const n=rn();return t||(t=lv(i),(E=(v=window.localStorage)==null?void 0:v.setItem)==null||E.call(v,"vouch-uid-visitor",t)),e||(e=rn(),(T=(A=window.localStorage)==null?void 0:A.setItem)==null||T.call(A,"vouch-uid-client",e)),r||(r=rn(),(C=(w=window.sessionStorage)==null?void 0:w.setItem)==null||C.call(w,"vouch-uid-tab",r)),{client:e,tab:r,request:n,visitor:t}}function hv(i,t){return i&&"vouchId"in i?i.vouchId:(t==null?void 0:t.id)??null}function dv(i="embedded_player"){var n,o;const[t,e]=((o=(n=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:n.split)==null?void 0:o.call(n,"/"))??[],r={};return[...new URLSearchParams(location.search).entries()].forEach(([l,d])=>{if(/utm/.test(l)){const f=l.toLowerCase().replace(/[-_][a-z0-9]/g,p=>p.slice(-1).toUpperCase());r[f]=d}}),{source:i,time:new Date,region:e,country:t,screenHeight:window.screen.height,screenWidth:window.screen.width,referrer:document.referrer,currentUrl:location.href,embedType:"media-player-embed",embedVersion:ov.version,templateVersion:yc,...r}}const r0=1;class uv{constructor(t){this._batchedEvents=[],this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createTrackingEvent=(e,r)=>{const n=hv(r,this.host.vouch);!n||this.host.disableTracking||this._batchedEvents.push({event:e,payload:{...r,vouchId:n,time:new Date().toISOString()}})},this._sendTrackingEvent=()=>{if(this._batchedEvents.length<=0)return;const{publicApiUrl:e}=uo(this.host.env),{client:r,tab:n,request:o,visitor:l}=cv(this.host.env);navigator.sendBeacon(`${e}/api/batchevents`,JSON.stringify({payload:{events:this._batchedEvents},context:{"x-uid-client":r,"x-uid-tab":n,"x-uid-request":o,"x-uid-visitor":l,"x-reporting-metadata":dv(this.host.trackingSource)}})),this._batchedEvents=[]},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:e,key:r}=this._currentlyPlayingVideo;this._streamLatestTime[r]>this._streamStartTime[r]+r0&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:e,streamStart:this._streamStartTime[r],streamEnd:this._streamLatestTime[r]}),delete this._streamStartTime[r],delete this._streamLatestTime[r]}},this._handleVouchLoaded=({detail:e})=>{e&&(this._hasLoaded[e]||(this._createTrackingEvent("VOUCH_LOADED",{vouchId:e}),this._hasLoaded[e]=!0))},this._handlePlay=()=>{this._hasPlayed||(this._createTrackingEvent("VIDEO_PLAYED",{streamStart:this.host.currentTime}),this._hasPlayed=!0)},this._handleVideoPlay=({detail:{id:e,key:r}})=>{this._answersViewed[r]||(this._createTrackingEvent("VOUCH_RESPONSE_VIEWED",{answerId:e}),this._answersViewed[r]=!0)},this._handleVideoTimeUpdate=({detail:{id:e,key:r,node:n}})=>{var o,l;!this.host.paused&&e===((l=(o=this.host.scene)==null?void 0:o.video)==null?void 0:l.id)&&(this._currentlyPlayingVideo={id:e,key:r,node:n},this._streamLatestTime[r]=n.currentTime,this._streamStartTime[r]||(this._streamStartTime[r]=n.currentTime,this._streamLatestTime[r]=n.currentTime))},this._handleVideoPause=({detail:{id:e,key:r}})=>{this._streamLatestTime[r]>this._streamStartTime[r]+r0&&this._createTrackingEvent("VIDEO_STREAMED",{answerId:e,streamStart:this._streamStartTime[r],streamEnd:this._streamLatestTime[r]}),delete this._streamStartTime[r],delete this._streamLatestTime[r]},this._pageUnloading=()=>{this._streamEnded(),this._sendTrackingEvent()},this._handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this._pageUnloading()},this._handlePageHide=()=>{this._pageUnloading()},this.host=t,t.addController(this)}hostConnected(){requestAnimationFrame(()=>{var t,e,r,n;"onvisibilitychange"in document?document.addEventListener("visibilitychange",this._handleVisibilityChange):window.addEventListener("pagehide",this._handlePageHide),this.host.addEventListener("vouch:loaded",this._handleVouchLoaded),(t=this.host.mediaPlayer)==null||t.addEventListener("play",this._handlePlay),(e=this.host.mediaPlayer)==null||e.addEventListener("video:play",this._handleVideoPlay),(r=this.host.mediaPlayer)==null||r.addEventListener("video:pause",this._handleVideoPause),(n=this.host.mediaPlayer)==null||n.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var t,e,r,n;this._pageUnloading(),"onvisibilitychange"in document?document.removeEventListener("visibilitychange",this._handleVisibilityChange):window.removeEventListener("pagehide",this._handlePageHide),this.host.removeEventListener("vouch:loaded",this._handleVouchLoaded),(t=this.host.mediaPlayer)==null||t.removeEventListener("play",this._handlePlay),(e=this.host.mediaPlayer)==null||e.removeEventListener("video:play",this._handleVideoPlay),(r=this.host.mediaPlayer)==null||r.removeEventListener("video:pause",this._handleVideoPause),(n=this.host.mediaPlayer)==null||n.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}const fv=i=>{class t extends i{constructor(){super(...arguments),this._mediaPlayerRef=wr()}get waiting(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.waiting}get initialised(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.initialised}get seeking(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.seeking}get paused(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.paused}get captions(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.captions}get fullscreen(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.fullscreen}get duration(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.duration}set currentTime(r){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.currentTime=r)}get currentTime(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.currentTime)??0}set playbackRate(r){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.playbackRate=r)}get playbackRate(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.playbackRate)??1}set volume(r){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.volume=r)}get volume(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.volume)??1}set muted(r){this._mediaPlayerRef.value&&(this._mediaPlayerRef.value.muted=r)}get muted(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.muted)??!1}get scene(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.scene)??null}get scenes(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.scenes)??[]}get sceneConfig(){var r;return((r=this._mediaPlayerRef.value)==null?void 0:r.sceneConfig)??null}get videoState(){var r;return(r=this._mediaPlayerRef.value)==null?void 0:r.videoState}get mediaPlayer(){return this._mediaPlayerRef.value}play(){var r;(r=this._mediaPlayerRef.value)==null||r.play()}pause(){var r;(r=this._mediaPlayerRef.value)==null||r.pause()}reset(r=0,n=!1){var o;(o=this._mediaPlayerRef.value)==null||o.reset(r,n)}setScene(r){var n;(n=this._mediaPlayerRef.value)==null||n.setScene(r)}}return t};/**
172
172
  * @license
173
173
  * Copyright 2018 Google LLC
174
174
  * SPDX-License-Identifier: BSD-3-Clause
@@ -1620,10 +1620,11 @@ ${t}`,t1=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),e1=Objec
1620
1620
  }
1621
1621
 
1622
1622
  .container {
1623
- position: absolute;
1623
+ position: fixed;
1624
1624
  display: flex;
1625
1625
  inset: 0;
1626
1626
  opacity: 1;
1627
+ z-index: 2147483647;
1627
1628
  align-items: center;
1628
1629
  justify-content: center;
1629
1630
  transition: opacity 100ms ease-in;