@vouchfor/embeds 0.0.0-experiment.41ff924 → 0.0.0-experiment.4471c1c

Sign up to get free protection for your applications and to get access to all the features.
package/dist/es/embeds.js CHANGED
@@ -1221,7 +1221,7 @@ class ni {
1221
1221
  return this._fetching;
1222
1222
  }
1223
1223
  }
1224
- const oi = "@vouchfor/embeds", ai = "0.0.0-experiment.41ff924", hi = "MIT", li = "Aaron Williams", di = "dist/es/embeds.js", ci = "dist/es/embeds.js", pi = "module", ui = "dist/es/index.d.ts", _i = {
1224
+ const oi = "@vouchfor/embeds", ai = "0.0.0-experiment.4471c1c", hi = "MIT", li = "Aaron Williams", di = "dist/es/embeds.js", ci = "dist/es/embeds.js", pi = "module", ui = "dist/es/index.d.ts", _i = {
1225
1225
  ".": "./dist/es/embeds.js"
1226
1226
  }, mi = [
1227
1227
  "dist",
@@ -1245,7 +1245,7 @@ const oi = "@vouchfor/embeds", ai = "0.0.0-experiment.41ff924", hi = "MIT", li =
1245
1245
  test: "true"
1246
1246
  }, gi = {
1247
1247
  "@lit/task": "^1.0.0",
1248
- "@vouchfor/media-player": "0.0.0-experiment.41ff924",
1248
+ "@vouchfor/media-player": "0.0.0-experiment.4471c1c",
1249
1249
  uuid: "^9.0.1"
1250
1250
  }, vi = {
1251
1251
  lit: "^3.1.0"
@@ -74,7 +74,7 @@ var e3=Object.defineProperty;var i3=(Ge,Yr,_r)=>Yr in Ge?e3(Ge,Yr,{enumerable:!0
74
74
  * @license
75
75
  * Copyright 2017 Google LLC
76
76
  * SPDX-License-Identifier: BSD-3-Clause
77
- */const fg=Symbol();class _l{get taskComplete(){return this.t||(this.status===1?this.t=new Promise((t,e)=>{this.i=t,this.o=e}):this.status===3?this.t=Promise.reject(this.h):this.t=Promise.resolve(this.l)),this.t}constructor(t,e,i){var o;this.u=0,this.status=0,(this.p=t).addController(this);const s=typeof e=="object"?e:{task:e,args:i};this._=s.task,this.v=s.args,this.j=s.argsEqual??pg,this.m=s.onComplete,this.g=s.onError,this.autoRun=s.autoRun??!0,"initialValue"in s&&(this.l=s.initialValue,this.status=2,this.k=(o=this.A)==null?void 0:o.call(this))}hostUpdate(){this.autoRun===!0&&this.O()}hostUpdated(){this.autoRun==="afterUpdate"&&this.O()}A(){if(this.v===void 0)return;const t=this.v();if(!Array.isArray(t))throw Error("The args function must return an array");return t}async O(){const t=this.A(),e=this.k;this.k=t,t===e||t===void 0||e!==void 0&&this.j(e,t)||await this.run(t)}async run(t){var c,d,f,p,g;let e,i;t??(t=this.A()),this.k=t,this.status===1?(c=this.T)==null||c.abort():(this.t=void 0,this.i=void 0,this.o=void 0),this.status=1,this.autoRun==="afterUpdate"?queueMicrotask(()=>this.p.requestUpdate()):this.p.requestUpdate();const s=++this.u;this.T=new AbortController;let o=!1;try{e=await this._(t,{signal:this.T.signal})}catch(v){o=!0,i=v}if(this.u===s){if(e===fg)this.status=0;else{if(o===!1){try{(d=this.m)==null||d.call(this,e)}catch{}this.status=2,(f=this.i)==null||f.call(this,e)}else{try{(p=this.g)==null||p.call(this,i)}catch{}this.status=3,(g=this.o)==null||g.call(this,i)}this.l=e,this.h=i}this.p.requestUpdate()}}abort(t){var e;this.status===1&&((e=this.T)==null||e.abort(t))}get value(){return this.l}get error(){return this.h}render(t){var e,i,s,o;switch(this.status){case 0:return(e=t.initial)==null?void 0:e.call(t);case 1:return(i=t.pending)==null?void 0:i.call(t);case 2:return(s=t.complete)==null?void 0:s.call(t,this.value);case 3:return(o=t.error)==null?void 0:o.call(t,this.error);default:throw Error("Unexpected status: "+this.status)}}}const pg=(n,t)=>n===t||n.length===t.length&&n.every((e,i)=>!Ll(e,t[i]));let qa;const gg=new Uint8Array(16);function mg(){if(!qa&&(qa=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!qa))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return qa(gg)}const yi=[];for(let n=0;n<256;++n)yi.push((n+256).toString(16).slice(1));function vg(n,t=0){return yi[n[t+0]]+yi[n[t+1]]+yi[n[t+2]]+yi[n[t+3]]+"-"+yi[n[t+4]]+yi[n[t+5]]+"-"+yi[n[t+6]]+yi[n[t+7]]+"-"+yi[n[t+8]]+yi[n[t+9]]+"-"+yi[n[t+10]]+yi[n[t+11]]+yi[n[t+12]]+yi[n[t+13]]+yi[n[t+14]]+yi[n[t+15]]}const Dd={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function qs(n,t,e){if(Dd.randomUUID&&!t&&!n)return Dd.randomUUID();n=n||{};const i=n.random||(n.rng||mg)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,t){e=e||0;for(let s=0;s<16;++s)t[e+s]=i[s];return t}return vg(i)}const xd="https://d2rxhdlm2q91uk.cloudfront.net",yg="https://d1ix11aj5kfygl.cloudfront.net",bg="https://d157jlwnudd93d.cloudfront.net",Pd="https://bshyfw4h5a.execute-api.ap-southeast-2.amazonaws.com/dev",Ag="https://gyzw7rpbq3.execute-api.ap-southeast-2.amazonaws.com/staging",Eg="https://vfcjuim1l3.execute-api.ap-southeast-2.amazonaws.com/prod",kg="http://localhost:6060/v2",Tg="https://embed-dev.vouchfor.com/v2",wg="https://embed-staging.vouchfor.com/v2",Sg="https://embed.vouchfor.com/v2";function Qa(n){if(!["local","dev","staging","prod"].includes(n))throw new Error(`Unknown environment: ${n}`);if(n==="local")return{videoUrl:xd,publicApiUrl:Pd,embedApiUrl:kg};if(n==="dev")return{videoUrl:xd,publicApiUrl:Pd,embedApiUrl:Tg};if(n==="staging")return{videoUrl:yg,publicApiUrl:Ag,embedApiUrl:wg};if(n==="prod")return{videoUrl:bg,publicApiUrl:Eg,embedApiUrl:Sg}}class Rg{constructor(t){this._fetching=!1,this.getVouch=async(e,i,s)=>{var g;const{embedApiUrl:o}=Qa(e),c=qs(),d=await fetch(`${o}/vouches/${s}`,{method:"GET",headers:[["X-Api-Key",i],["X-Cache-Check",c]]}),f=await d.json();return this.host.dispatchEvent(new CustomEvent("vouch:loaded",{detail:f==null?void 0:f.id})),((g=d==null?void 0:d.headers)==null?void 0:g.get("X-Cache-Check"))!==c&&fetch(`${o}/vouches/${s}`,{method:"GET",headers:[["X-Api-Key",i],["Cache-Control","max-age=0"]]}),f},this.getTemplate=async(e,i,s)=>{var g;const{embedApiUrl:o}=Qa(e),c=qs(),d=await fetch(`${o}/templates/${s}`,{method:"GET",headers:[["X-Api-Key",i],["X-Cache-Check",c]]}),f=await d.json();return((g=d==null?void 0:d.headers)==null?void 0:g.get("X-Cache-Check"))!==c&&fetch(`${o}/templates/${s}`,{method:"GET",headers:[["X-Api-Key",i],["Cache-Control","max-age=0"]]}),f},this.host=t,new _l(this.host,async([e,i,s,o,c])=>{var d,f,p,g;try{if(t.vouch=void 0,t.template=void 0,s){let v;c&&(this.fetching=!0,v=await this.getTemplate(e,i,c)),t.vouch=s,t.template=v??((f=(d=s==null?void 0:s.settings)==null?void 0:d.template)==null?void 0:f.instance)}else if(o){this.fetching=!0;const[v,b]=await Promise.all([this.getVouch(e,i,o),c?this.getTemplate(e,i,c):null]);t.vouch=v,t.template=b??((g=(p=v==null?void 0:v.settings)==null?void 0:p.template)==null?void 0:g.instance)}}finally{this.fetching=!1}},()=>[t.env,t.apiKey,t.data,t.vouchId,t.templateId])}set fetching(t){this._fetching!==t&&(this._fetching=t,this.host.requestUpdate())}get fetching(){return this._fetching}}const Lg={name:"@vouchfor/embeds",version:"0.0.0-experiment.41ff924",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds.js",module:"dist/es/embeds.js",type:"module",types:"dist/es/index.d.ts",exports:{".":"./dist/es/embeds.js"},files:["dist","src"],publishConfig:{tag:"experiment",access:"public"},scripts:{build:"rm -rf dist && tsc && vite build --mode iife && vite build --mode es","build:deps":"yarn --cwd ../media-player build","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:"true"},"lint-staged":{"**/*.{ts,tsx,js}":"eslint --fix --quiet","**/*.{md,json,yml}":"prettier --write"},dependencies:{"@lit/task":"^1.0.0","@vouchfor/media-player":"0.0.0-experiment.41ff924",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","lint-staged":"^14.0.1",lit:"^3.1.0",prettier:"^3.0.3",react:"^18.2.0","react-dom":"^18.2.0",storybook:"^7.4.5",typescript:"^5.1.3",vite:"^4.4.9","vite-plugin-dts":"^3.6.0","web-component-analyzer":"^1.1.7"}},Od=1;class _g{constructor(t){this._tabId=void 0,this._clientId=void 0,this._visitorId=void 0,this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createVisitor=e=>{var s,o;const{publicApiUrl:i}=Qa(this.host.env);return(o=(s=window.localStorage)==null?void 0:s.setItem)==null||o.call(s,"vouch-uid-visitor",e),navigator.sendBeacon(`${i}/api/visitor`,JSON.stringify({visitorId:e})),e},this._getReportingMetadata=()=>{var o,c;const[e,i]=((c=(o=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:o.split)==null?void 0:c.call(o,"/"))??[],s={};return[...new URLSearchParams(location.search).entries()].forEach(([d,f])=>{if(/utm/.test(d)){const p=d.toLowerCase().replace(/[-_][a-z0-9]/g,g=>g.slice(-1).toUpperCase());s[p]=f}}),{source:this.host.trackingSource,time:new Date,region:i,country:e,screenHeight:window.screen.height,screenWidth:window.screen.width,referrer:document.referrer,currentUrl:location.href,...s}},this._sendTrackingEvent=(e,i)=>{const s=this._findVouchId(i);if(!s||this.host.disableTracking)return;const{publicApiUrl:o}=Qa(this.host.env),{client:c,tab:d,request:f,visitor:p}=this._getUids();navigator.sendBeacon(`${o}/api/v2/events`,JSON.stringify({event:e,payload:{...i,vouchId:s},context:{"x-uid-client":c,"x-uid-tab":d,"x-uid-request":f,"x-uid-visitor":p,"x-reporting-metadata":this._getReportingMetadata(),"x-embeds-version":Lg.version}}))},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:e,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+Od&&this._sendTrackingEvent("VIDEO_STREAMED",{answerId:e,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]}},this._handleVouchLoaded=({detail:e})=>{e&&(this._hasLoaded[e]||(this._sendTrackingEvent("VOUCH_LOADED",{vouchId:e}),this._hasLoaded[e]=!0))},this._handlePlay=()=>{this._hasPlayed||(this._sendTrackingEvent("VIDEO_PLAYED",{streamStart:this.host.currentTime}),this._hasPlayed=!0)},this._handleVideoPlay=({detail:{id:e,key:i,node:s}})=>{this._answersViewed[i]||(this._sendTrackingEvent("VOUCH_RESPONSE_VIEWED",{answerId:e}),this._answersViewed[i]=!0),this._streamStartTime[i]||(this._streamStartTime[i]=s.currentTime,this._streamLatestTime[i]=s.currentTime)},this._handleVideoTimeUpdate=({detail:{id:e,key:i,node:s}})=>{var o,c;!this.host.paused&&e===((c=(o=this.host.scene)==null?void 0:o.video)==null?void 0:c.id)&&(this._currentlyPlayingVideo={id:e,key:i,node:s},this._streamLatestTime[i]=s.currentTime)},this._handleVideoPause=({detail:{id:e,key:i}})=>{this._streamLatestTime[i]>this._streamStartTime[i]+Od&&this._sendTrackingEvent("VIDEO_STREAMED",{answerId:e,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]},this._pageUnloading=()=>{this._streamEnded(),this.host.pause()},this._handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this._pageUnloading()},this._handlePageHide=()=>{this._pageUnloading()},this.host=t,t.addController(this)}_findVouchId(t){return t&&"vouchId"in t?t.vouchId:this.host.vouch?this.host.vouch.id:null}_getUids(){var o,c,d,f,p,g,v,b,E,k,w,L;if(typeof window>"u")return{client:null,tab:null,request:qs()};const t=this._visitorId||((c=(o=window.localStorage)==null?void 0:o.getItem)==null?void 0:c.call(o,"vouch-uid-visitor"))||this._createVisitor(qs()),e=this._clientId||((f=(d=window.localStorage)==null?void 0:d.getItem)==null?void 0:f.call(d,"vouch-uid-client"))||qs(),i=this._tabId||((g=(p=window.sessionStorage)==null?void 0:p.getItem)==null?void 0:g.call(p,"vouch-uid-tab"))||qs(),s=qs();return t!==this._visitorId&&(this._visitorId=t,(b=(v=window.localStorage)==null?void 0:v.setItem)==null||b.call(v,"vouch-uid-visitor",t)),e!==this._clientId&&(this._clientId=e,(k=(E=window.localStorage)==null?void 0:E.setItem)==null||k.call(E,"vouch-uid-client",e)),i!==this._tabId&&(this._tabId=i,(L=(w=window.sessionStorage)==null?void 0:w.setItem)==null||L.call(w,"vouch-uid-tab",i)),{client:e,tab:i,request:s,visitor:t}}hostConnected(){requestAnimationFrame(()=>{var t,e,i,s;"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),(i=this.host.mediaPlayer)==null||i.addEventListener("video:pause",this._handleVideoPause),(s=this.host.mediaPlayer)==null||s.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var t,e,i,s;this._streamEnded(),"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),(i=this.host.mediaPlayer)==null||i.removeEventListener("video:pause",this._handleVideoPause),(s=this.host.mediaPlayer)==null||s.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}const Cg=(n,t,e,i)=>{if(e==="length"||e==="prototype"||e==="arguments"||e==="caller")return;const s=Object.getOwnPropertyDescriptor(n,e),o=Object.getOwnPropertyDescriptor(t,e);!Ig(s,o)&&i||Object.defineProperty(n,e,o)},Ig=function(n,t){return n===void 0||n.configurable||n.writable===t.writable&&n.enumerable===t.enumerable&&n.configurable===t.configurable&&(n.writable||n.value===t.value)},Dg=(n,t)=>{const e=Object.getPrototypeOf(t);e!==Object.getPrototypeOf(n)&&Object.setPrototypeOf(n,e)},xg=(n,t)=>`/* Wrapped ${n}*/
77
+ */const fg=Symbol();class _l{get taskComplete(){return this.t||(this.status===1?this.t=new Promise((t,e)=>{this.i=t,this.o=e}):this.status===3?this.t=Promise.reject(this.h):this.t=Promise.resolve(this.l)),this.t}constructor(t,e,i){var o;this.u=0,this.status=0,(this.p=t).addController(this);const s=typeof e=="object"?e:{task:e,args:i};this._=s.task,this.v=s.args,this.j=s.argsEqual??pg,this.m=s.onComplete,this.g=s.onError,this.autoRun=s.autoRun??!0,"initialValue"in s&&(this.l=s.initialValue,this.status=2,this.k=(o=this.A)==null?void 0:o.call(this))}hostUpdate(){this.autoRun===!0&&this.O()}hostUpdated(){this.autoRun==="afterUpdate"&&this.O()}A(){if(this.v===void 0)return;const t=this.v();if(!Array.isArray(t))throw Error("The args function must return an array");return t}async O(){const t=this.A(),e=this.k;this.k=t,t===e||t===void 0||e!==void 0&&this.j(e,t)||await this.run(t)}async run(t){var c,d,f,p,g;let e,i;t??(t=this.A()),this.k=t,this.status===1?(c=this.T)==null||c.abort():(this.t=void 0,this.i=void 0,this.o=void 0),this.status=1,this.autoRun==="afterUpdate"?queueMicrotask(()=>this.p.requestUpdate()):this.p.requestUpdate();const s=++this.u;this.T=new AbortController;let o=!1;try{e=await this._(t,{signal:this.T.signal})}catch(v){o=!0,i=v}if(this.u===s){if(e===fg)this.status=0;else{if(o===!1){try{(d=this.m)==null||d.call(this,e)}catch{}this.status=2,(f=this.i)==null||f.call(this,e)}else{try{(p=this.g)==null||p.call(this,i)}catch{}this.status=3,(g=this.o)==null||g.call(this,i)}this.l=e,this.h=i}this.p.requestUpdate()}}abort(t){var e;this.status===1&&((e=this.T)==null||e.abort(t))}get value(){return this.l}get error(){return this.h}render(t){var e,i,s,o;switch(this.status){case 0:return(e=t.initial)==null?void 0:e.call(t);case 1:return(i=t.pending)==null?void 0:i.call(t);case 2:return(s=t.complete)==null?void 0:s.call(t,this.value);case 3:return(o=t.error)==null?void 0:o.call(t,this.error);default:throw Error("Unexpected status: "+this.status)}}}const pg=(n,t)=>n===t||n.length===t.length&&n.every((e,i)=>!Ll(e,t[i]));let qa;const gg=new Uint8Array(16);function mg(){if(!qa&&(qa=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!qa))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return qa(gg)}const yi=[];for(let n=0;n<256;++n)yi.push((n+256).toString(16).slice(1));function vg(n,t=0){return yi[n[t+0]]+yi[n[t+1]]+yi[n[t+2]]+yi[n[t+3]]+"-"+yi[n[t+4]]+yi[n[t+5]]+"-"+yi[n[t+6]]+yi[n[t+7]]+"-"+yi[n[t+8]]+yi[n[t+9]]+"-"+yi[n[t+10]]+yi[n[t+11]]+yi[n[t+12]]+yi[n[t+13]]+yi[n[t+14]]+yi[n[t+15]]}const Dd={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function qs(n,t,e){if(Dd.randomUUID&&!t&&!n)return Dd.randomUUID();n=n||{};const i=n.random||(n.rng||mg)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,t){e=e||0;for(let s=0;s<16;++s)t[e+s]=i[s];return t}return vg(i)}const xd="https://d2rxhdlm2q91uk.cloudfront.net",yg="https://d1ix11aj5kfygl.cloudfront.net",bg="https://d157jlwnudd93d.cloudfront.net",Pd="https://bshyfw4h5a.execute-api.ap-southeast-2.amazonaws.com/dev",Ag="https://gyzw7rpbq3.execute-api.ap-southeast-2.amazonaws.com/staging",Eg="https://vfcjuim1l3.execute-api.ap-southeast-2.amazonaws.com/prod",kg="http://localhost:6060/v2",Tg="https://embed-dev.vouchfor.com/v2",wg="https://embed-staging.vouchfor.com/v2",Sg="https://embed.vouchfor.com/v2";function Qa(n){if(!["local","dev","staging","prod"].includes(n))throw new Error(`Unknown environment: ${n}`);if(n==="local")return{videoUrl:xd,publicApiUrl:Pd,embedApiUrl:kg};if(n==="dev")return{videoUrl:xd,publicApiUrl:Pd,embedApiUrl:Tg};if(n==="staging")return{videoUrl:yg,publicApiUrl:Ag,embedApiUrl:wg};if(n==="prod")return{videoUrl:bg,publicApiUrl:Eg,embedApiUrl:Sg}}class Rg{constructor(t){this._fetching=!1,this.getVouch=async(e,i,s)=>{var g;const{embedApiUrl:o}=Qa(e),c=qs(),d=await fetch(`${o}/vouches/${s}`,{method:"GET",headers:[["X-Api-Key",i],["X-Cache-Check",c]]}),f=await d.json();return this.host.dispatchEvent(new CustomEvent("vouch:loaded",{detail:f==null?void 0:f.id})),((g=d==null?void 0:d.headers)==null?void 0:g.get("X-Cache-Check"))!==c&&fetch(`${o}/vouches/${s}`,{method:"GET",headers:[["X-Api-Key",i],["Cache-Control","max-age=0"]]}),f},this.getTemplate=async(e,i,s)=>{var g;const{embedApiUrl:o}=Qa(e),c=qs(),d=await fetch(`${o}/templates/${s}`,{method:"GET",headers:[["X-Api-Key",i],["X-Cache-Check",c]]}),f=await d.json();return((g=d==null?void 0:d.headers)==null?void 0:g.get("X-Cache-Check"))!==c&&fetch(`${o}/templates/${s}`,{method:"GET",headers:[["X-Api-Key",i],["Cache-Control","max-age=0"]]}),f},this.host=t,new _l(this.host,async([e,i,s,o,c])=>{var d,f,p,g;try{if(t.vouch=void 0,t.template=void 0,s){let v;c&&(this.fetching=!0,v=await this.getTemplate(e,i,c)),t.vouch=s,t.template=v??((f=(d=s==null?void 0:s.settings)==null?void 0:d.template)==null?void 0:f.instance)}else if(o){this.fetching=!0;const[v,b]=await Promise.all([this.getVouch(e,i,o),c?this.getTemplate(e,i,c):null]);t.vouch=v,t.template=b??((g=(p=v==null?void 0:v.settings)==null?void 0:p.template)==null?void 0:g.instance)}}finally{this.fetching=!1}},()=>[t.env,t.apiKey,t.data,t.vouchId,t.templateId])}set fetching(t){this._fetching!==t&&(this._fetching=t,this.host.requestUpdate())}get fetching(){return this._fetching}}const Lg={name:"@vouchfor/embeds",version:"0.0.0-experiment.4471c1c",license:"MIT",author:"Aaron Williams",main:"dist/es/embeds.js",module:"dist/es/embeds.js",type:"module",types:"dist/es/index.d.ts",exports:{".":"./dist/es/embeds.js"},files:["dist","src"],publishConfig:{tag:"experiment",access:"public"},scripts:{build:"rm -rf dist && tsc && vite build --mode iife && vite build --mode es","build:deps":"yarn --cwd ../media-player build","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:"true"},"lint-staged":{"**/*.{ts,tsx,js}":"eslint --fix --quiet","**/*.{md,json,yml}":"prettier --write"},dependencies:{"@lit/task":"^1.0.0","@vouchfor/media-player":"0.0.0-experiment.4471c1c",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","lint-staged":"^14.0.1",lit:"^3.1.0",prettier:"^3.0.3",react:"^18.2.0","react-dom":"^18.2.0",storybook:"^7.4.5",typescript:"^5.1.3",vite:"^4.4.9","vite-plugin-dts":"^3.6.0","web-component-analyzer":"^1.1.7"}},Od=1;class _g{constructor(t){this._tabId=void 0,this._clientId=void 0,this._visitorId=void 0,this._hasPlayed=!1,this._hasLoaded={},this._answersViewed={},this._streamStartTime={},this._streamLatestTime={},this._currentlyPlayingVideo=null,this._createVisitor=e=>{var s,o;const{publicApiUrl:i}=Qa(this.host.env);return(o=(s=window.localStorage)==null?void 0:s.setItem)==null||o.call(s,"vouch-uid-visitor",e),navigator.sendBeacon(`${i}/api/visitor`,JSON.stringify({visitorId:e})),e},this._getReportingMetadata=()=>{var o,c;const[e,i]=((c=(o=Intl.DateTimeFormat().resolvedOptions().timeZone)==null?void 0:o.split)==null?void 0:c.call(o,"/"))??[],s={};return[...new URLSearchParams(location.search).entries()].forEach(([d,f])=>{if(/utm/.test(d)){const p=d.toLowerCase().replace(/[-_][a-z0-9]/g,g=>g.slice(-1).toUpperCase());s[p]=f}}),{source:this.host.trackingSource,time:new Date,region:i,country:e,screenHeight:window.screen.height,screenWidth:window.screen.width,referrer:document.referrer,currentUrl:location.href,...s}},this._sendTrackingEvent=(e,i)=>{const s=this._findVouchId(i);if(!s||this.host.disableTracking)return;const{publicApiUrl:o}=Qa(this.host.env),{client:c,tab:d,request:f,visitor:p}=this._getUids();navigator.sendBeacon(`${o}/api/v2/events`,JSON.stringify({event:e,payload:{...i,vouchId:s},context:{"x-uid-client":c,"x-uid-tab":d,"x-uid-request":f,"x-uid-visitor":p,"x-reporting-metadata":this._getReportingMetadata(),"x-embeds-version":Lg.version}}))},this._streamEnded=()=>{if(this._currentlyPlayingVideo){const{id:e,key:i}=this._currentlyPlayingVideo;this._streamLatestTime[i]>this._streamStartTime[i]+Od&&this._sendTrackingEvent("VIDEO_STREAMED",{answerId:e,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]}},this._handleVouchLoaded=({detail:e})=>{e&&(this._hasLoaded[e]||(this._sendTrackingEvent("VOUCH_LOADED",{vouchId:e}),this._hasLoaded[e]=!0))},this._handlePlay=()=>{this._hasPlayed||(this._sendTrackingEvent("VIDEO_PLAYED",{streamStart:this.host.currentTime}),this._hasPlayed=!0)},this._handleVideoPlay=({detail:{id:e,key:i,node:s}})=>{this._answersViewed[i]||(this._sendTrackingEvent("VOUCH_RESPONSE_VIEWED",{answerId:e}),this._answersViewed[i]=!0),this._streamStartTime[i]||(this._streamStartTime[i]=s.currentTime,this._streamLatestTime[i]=s.currentTime)},this._handleVideoTimeUpdate=({detail:{id:e,key:i,node:s}})=>{var o,c;!this.host.paused&&e===((c=(o=this.host.scene)==null?void 0:o.video)==null?void 0:c.id)&&(this._currentlyPlayingVideo={id:e,key:i,node:s},this._streamLatestTime[i]=s.currentTime)},this._handleVideoPause=({detail:{id:e,key:i}})=>{this._streamLatestTime[i]>this._streamStartTime[i]+Od&&this._sendTrackingEvent("VIDEO_STREAMED",{answerId:e,streamStart:this._streamStartTime[i],streamEnd:this._streamLatestTime[i]}),delete this._streamStartTime[i],delete this._streamLatestTime[i]},this._pageUnloading=()=>{this._streamEnded(),this.host.pause()},this._handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this._pageUnloading()},this._handlePageHide=()=>{this._pageUnloading()},this.host=t,t.addController(this)}_findVouchId(t){return t&&"vouchId"in t?t.vouchId:this.host.vouch?this.host.vouch.id:null}_getUids(){var o,c,d,f,p,g,v,b,E,k,w,L;if(typeof window>"u")return{client:null,tab:null,request:qs()};const t=this._visitorId||((c=(o=window.localStorage)==null?void 0:o.getItem)==null?void 0:c.call(o,"vouch-uid-visitor"))||this._createVisitor(qs()),e=this._clientId||((f=(d=window.localStorage)==null?void 0:d.getItem)==null?void 0:f.call(d,"vouch-uid-client"))||qs(),i=this._tabId||((g=(p=window.sessionStorage)==null?void 0:p.getItem)==null?void 0:g.call(p,"vouch-uid-tab"))||qs(),s=qs();return t!==this._visitorId&&(this._visitorId=t,(b=(v=window.localStorage)==null?void 0:v.setItem)==null||b.call(v,"vouch-uid-visitor",t)),e!==this._clientId&&(this._clientId=e,(k=(E=window.localStorage)==null?void 0:E.setItem)==null||k.call(E,"vouch-uid-client",e)),i!==this._tabId&&(this._tabId=i,(L=(w=window.sessionStorage)==null?void 0:w.setItem)==null||L.call(w,"vouch-uid-tab",i)),{client:e,tab:i,request:s,visitor:t}}hostConnected(){requestAnimationFrame(()=>{var t,e,i,s;"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),(i=this.host.mediaPlayer)==null||i.addEventListener("video:pause",this._handleVideoPause),(s=this.host.mediaPlayer)==null||s.addEventListener("video:timeupdate",this._handleVideoTimeUpdate)})}hostDisconnected(){var t,e,i,s;this._streamEnded(),"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),(i=this.host.mediaPlayer)==null||i.removeEventListener("video:pause",this._handleVideoPause),(s=this.host.mediaPlayer)==null||s.removeEventListener("video:timeupdate",this._handleVideoTimeUpdate)}}const Cg=(n,t,e,i)=>{if(e==="length"||e==="prototype"||e==="arguments"||e==="caller")return;const s=Object.getOwnPropertyDescriptor(n,e),o=Object.getOwnPropertyDescriptor(t,e);!Ig(s,o)&&i||Object.defineProperty(n,e,o)},Ig=function(n,t){return n===void 0||n.configurable||n.writable===t.writable&&n.enumerable===t.enumerable&&n.configurable===t.configurable&&(n.writable||n.value===t.value)},Dg=(n,t)=>{const e=Object.getPrototypeOf(t);e!==Object.getPrototypeOf(n)&&Object.setPrototypeOf(n,e)},xg=(n,t)=>`/* Wrapped ${n}*/
78
78
  ${t}`,Pg=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),Og=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),Mg=(n,t,e)=>{const i=e===""?"":`with ${e.trim()}() `,s=xg.bind(null,i,t.toString());Object.defineProperty(s,"name",Og),Object.defineProperty(n,"toString",{...Pg,value:s})};function $g(n,t,{ignoreNonConfigurable:e=!1}={}){const{name:i}=n;for(const s of Reflect.ownKeys(t))Cg(n,t,s,e);return Dg(n,t),Mg(n,t,i),n}const Fg=new WeakMap;function vs(n,{cacheKey:t=([i])=>i,cache:e=new Map}={}){const i=new Map,s=function(...o){const c=t(o);if(i.has(c))return i.get(c);const d=(async()=>{try{if(e&&await e.has(c))return await e.get(c);const p=await n.apply(this,o);try{return p}finally{e&&await e.set(c,p)}}finally{i.delete(c)}})();return i.set(c,d),d};return $g(s,n,{ignoreNonConfigurable:!0}),Fg.set(s,e),s}var Ja=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Cl(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var Il={exports:{}};(function(n,t){(function(e,i){i(t)})(Ja,function(e){function i($){var U,Z,mt=new Error($);return U=mt,Z=i.prototype,Object.setPrototypeOf?Object.setPrototypeOf(U,Z):U.__proto__=Z,mt}function s($,U,Z){var mt=U.slice(0,Z).split(/\n/),bt=mt.length,Dt=mt[bt-1].length+1;throw i($+=" at line "+bt+" col "+Dt+`:
79
79
 
80
80
  `+U.split(/\n/)[bt-1]+`
@@ -560,7 +560,7 @@ ${t}`,Pg=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),Og=Objec
560
560
  height: 32px;
561
561
  width: 32px;
562
562
  }
563
- `],Pn([It({type:Boolean})],Ss.prototype,"active",2),Pn([It({type:String})],Ss.prototype,"size",2),Pn([It({type:String})],Ss.prototype,"rounded",2),Pn([It({type:String})],Ss.prototype,"weight",2),Pn([It({type:String})],Ss.prototype,"icon",2),Ss=Pn([Oi("vmp-new-icon-button")],Ss);var P4=Object.defineProperty,O4=Object.getOwnPropertyDescriptor,Yi=(n,t,e,i)=>{for(var s=i>1?void 0:i?O4(t,e):t,o=n.length-1,c;o>=0;o--)(c=n[o])&&(s=(i?c(t,e,s):c(s))||s);return i&&s&&P4(t,e,s),s};let is=class extends Le{constructor(){super(...arguments),this.disabled=!1,this.aspectRatio=1,this.compilation=xl,this._currentTime=0,this._sceneController=new R4(this),this._canvasRef=wi(),this._previewRef=wi(),this._previewTimeRef=wi(),this._handleScrubberMouseEnter=({detail:{x:n,y:t,elementLeft:e,elementRight:i}})=>{var s,o;if((s=this._previewRef)!=null&&s.value){const c=this._previewRef.value.getBoundingClientRect(),d=(o=this._previewRef.value.getRootNode().host)==null?void 0:o.getBoundingClientRect();c&&d&&(this._previewRef.value.style.opacity="1",this._previewRef.value.style.transform=`translate3d(${Of(e-d.left,n-d.left-c.width/2,i-d.left-c.width)}px, ${t-d.top-c.height-28}px, 0)`)}},this._handleScrubberMouseMove=({detail:{time:n,x:t,elementLeft:e,elementRight:i}})=>{var s,o,c,d,f,p,g;if(this._currentTime=n,(s=this._sceneController.scenes)!=null&&s.scenes.length){const v=(f=(d=(c=(o=this._sceneController.scenes)==null?void 0:o.scenes)==null?void 0:c.find(({start:b,duration:E,video:k})=>k&&n>=b&&n<=b+E))==null?void 0:d.video)==null?void 0:f.node;if(v&&(v.currentTime=n),this._draw(),(p=this._previewRef)!=null&&p.value){const b=this._previewRef.value.getBoundingClientRect(),E=(g=this._previewRef.value.getRootNode().host)==null?void 0:g.getBoundingClientRect();if(b&&E){const k=this._previewRef.value.style.transform,[,w]=Array.from(k.matchAll(/([+-]?([0-9]*[.])?[0-9]+)(?=px)\w+/g));this._previewRef.value.style.transform=`translate3d(${Of(e-E.left,t-E.left-b.width/2,i-E.left-b.width)}px, ${w[1]}px, 0)`}}this._previewTimeRef.value&&this._previewTimeRef.value.setAttribute("content",th(this._currentTime,{includeMs:!0}))}},this._handleScrubberMouseLeave=()=>{var n;(n=this._previewRef)!=null&&n.value&&(this._previewRef.value.style.opacity="0")},this._handleScrubberResize=({detail:{y:n}})=>{var t,e;if((t=this._previewRef)!=null&&t.value){const i=this._previewRef.value.getBoundingClientRect(),s=(e=this._previewRef.value.getRootNode().host)==null?void 0:e.getBoundingClientRect();if(i&&s){const o=this._previewRef.value.style.transform,[c]=Array.from(o.matchAll(/([+-]?([0-9]*[.])?[0-9]+)(?=px)\w+/g));this._previewRef.value.style.transform=`translate3d(${c[1]}px, ${n-s.top-i.height-28}px, 0)`}}}}_draw(n=this._currentTime){var t;this._sceneController.scenes&&this._canvasRef.value&&((t=this.compilation)==null||t.call(this,{currentTime:n,scenes:this._sceneController.scenes,canvas:this._canvasRef.value}))}connectedCallback(){super.connectedCallback(),document.addEventListener("scrubber:resize",this._handleScrubberResize),document.addEventListener("scrubber:mouseenter",this._handleScrubberMouseEnter),document.addEventListener("scrubber:mousemove",this._handleScrubberMouseMove),document.addEventListener("scrubber:mouseleave",this._handleScrubberMouseLeave)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("scrubber:resize",this._handleScrubberResize),document.removeEventListener("scrubber:mouseenter",this._handleScrubberMouseEnter),document.removeEventListener("scrubber:mousemove",this._handleScrubberMouseMove),document.removeEventListener("scrubber:mouseleave",this._handleScrubberMouseLeave)}render(){var n;const{height:t,width:e}=Pl({resolution:180,aspectRatio:this.aspectRatio}),i=((n=this._sceneController.scenes)==null?void 0:n.scenes.length)??0;return!this.disabled&&i>1?ie`
563
+ `],Pn([It({type:Boolean})],Ss.prototype,"active",2),Pn([It({type:String})],Ss.prototype,"size",2),Pn([It({type:String})],Ss.prototype,"rounded",2),Pn([It({type:String})],Ss.prototype,"weight",2),Pn([It({type:String})],Ss.prototype,"icon",2),Ss=Pn([Oi("vmp-new-icon-button")],Ss);var P4=Object.defineProperty,O4=Object.getOwnPropertyDescriptor,Yi=(n,t,e,i)=>{for(var s=i>1?void 0:i?O4(t,e):t,o=n.length-1,c;o>=0;o--)(c=n[o])&&(s=(i?c(t,e,s):c(s))||s);return i&&s&&P4(t,e,s),s};let is=class extends Le{constructor(){super(...arguments),this.disabled=!1,this.aspectRatio=1,this.compilation=xl,this._currentTime=0,this._sceneController=new R4(this),this._canvasRef=wi(),this._previewRef=wi(),this._previewTimeRef=wi(),this._handleScrubberMouseEnter=({detail:{x:n,y:t,elementLeft:e,elementRight:i}})=>{var s,o;if((s=this._previewRef)!=null&&s.value){const c=this._previewRef.value.getBoundingClientRect(),d=(o=this._previewRef.value.getRootNode().host)==null?void 0:o.getBoundingClientRect();c&&d&&(this._previewRef.value.style.opacity="1",this._previewRef.value.style.transform=`translate3d(${Of(e-d.left,n-d.left-c.width/2,i-d.left-c.width)}px, ${t-d.top-c.height-28}px, 0)`)}},this._handleScrubberMouseMove=({detail:{time:n,x:t,elementLeft:e,elementRight:i}})=>{var s,o,c,d,f,p,g;if(this._currentTime=n,(s=this._sceneController.scenes)!=null&&s.scenes.length){const v=(f=(d=(c=(o=this._sceneController.scenes)==null?void 0:o.scenes)==null?void 0:c.find(({start:b,duration:E,video:k})=>k&&n>=b&&n<=b+E))==null?void 0:d.video)==null?void 0:f.node;if(v&&(v.currentTime=n),this._draw(),(p=this._previewRef)!=null&&p.value){const b=this._previewRef.value.getBoundingClientRect(),E=(g=this._previewRef.value.getRootNode().host)==null?void 0:g.getBoundingClientRect();if(b&&E){const k=this._previewRef.value.style.transform||"translate3d(0px, 0px, 0px)",[,w]=Array.from(k.matchAll(/([+-]?([0-9]*[.])?[0-9]+)(?=px)\w+/g));this._previewRef.value.style.transform=`translate3d(${Of(e-E.left,t-E.left-b.width/2,i-E.left-b.width)}px, ${w[1]}px, 0)`}}this._previewTimeRef.value&&this._previewTimeRef.value.setAttribute("content",th(this._currentTime,{includeMs:!0}))}},this._handleScrubberMouseLeave=()=>{var n;(n=this._previewRef)!=null&&n.value&&(this._previewRef.value.style.opacity="0")},this._handleScrubberResize=({detail:{y:n}})=>{var t,e;if((t=this._previewRef)!=null&&t.value){const i=this._previewRef.value.getBoundingClientRect(),s=(e=this._previewRef.value.getRootNode().host)==null?void 0:e.getBoundingClientRect();if(i&&s){const o=this._previewRef.value.style.transform||"translate3d(0px, 0px, 0px)",[c]=Array.from(o.matchAll(/([+-]?([0-9]*[.])?[0-9]+)(?=px)\w+/g));this._previewRef.value.style.transform=`translate3d(${c[1]}px, ${n-s.top-i.height-28}px, 0)`}}}}_draw(n=this._currentTime){var t;this._sceneController.scenes&&this._canvasRef.value&&((t=this.compilation)==null||t.call(this,{currentTime:n,scenes:this._sceneController.scenes,canvas:this._canvasRef.value}))}connectedCallback(){super.connectedCallback(),document.addEventListener("scrubber:resize",this._handleScrubberResize),document.addEventListener("scrubber:mouseenter",this._handleScrubberMouseEnter),document.addEventListener("scrubber:mousemove",this._handleScrubberMouseMove),document.addEventListener("scrubber:mouseleave",this._handleScrubberMouseLeave)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("scrubber:resize",this._handleScrubberResize),document.removeEventListener("scrubber:mouseenter",this._handleScrubberMouseEnter),document.removeEventListener("scrubber:mousemove",this._handleScrubberMouseMove),document.removeEventListener("scrubber:mouseleave",this._handleScrubberMouseLeave)}render(){var n;const{height:t,width:e}=Pl({resolution:180,aspectRatio:this.aspectRatio}),i=((n=this._sceneController.scenes)==null?void 0:n.scenes.length)??0;return!this.disabled&&(this.src||i>1)?ie`
564
564
  <div
565
565
  ${Si(this._previewRef)}
566
566
  class="preview"
@@ -584,7 +584,6 @@ ${t}`,Pg=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),Og=Objec
584
584
  border: 3px solid var(--colors-light-1000);
585
585
  background: var(--colors-dark-1000);
586
586
  border-radius: var(--radii-medium);
587
- transform: translate3d(0px, 0px, 0px);
588
587
  transition: opacity 150ms ease-out;
589
588
  }
590
589