@vouchfor/embeds 0.0.0-experiment.8cafed9 → 0.0.0-experiment.8d72879

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.
Files changed (66) hide show
  1. package/dist/es/embeds.js +1042 -1
  2. package/dist/es/embeds.js.map +1 -1
  3. package/dist/es/src/components/DialogEmbed/DialogOverlay.d.ts +4 -4
  4. package/dist/es/src/components/DialogEmbed/DialogPortal.d.ts +3 -3
  5. package/dist/es/src/components/DialogEmbed/index.d.ts +4 -5
  6. package/dist/es/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +4 -3
  7. package/dist/es/src/components/PlayerEmbed/controllers/fetcher.d.ts +3 -2
  8. package/dist/es/src/components/PlayerEmbed/controllers/tracking/index.d.ts +4 -2
  9. package/dist/es/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +4 -3
  10. package/dist/es/src/components/PlayerEmbed/index.d.ts +15 -13
  11. package/dist/es/src/components/PlayerEmbed/tests/data.d.ts +4 -2
  12. package/dist/es/src/components/PlayerEmbed/tests/media-data.d.ts +19 -0
  13. package/dist/iife/dialog-embed/embed.iife.js +2647 -319
  14. package/dist/iife/dialog-embed/embed.iife.js.map +1 -1
  15. package/dist/iife/embeds.iife.js +2647 -319
  16. package/dist/iife/embeds.iife.js.map +1 -1
  17. package/dist/iife/player-embed/embed.iife.js +2624 -296
  18. package/dist/iife/player-embed/embed.iife.js.map +1 -1
  19. package/package.json +30 -28
  20. package/src/components/PlayerEmbed/MultiEmbed.stories.ts +135 -0
  21. package/src/components/PlayerEmbed/PlayerEmbed.stories.ts +18 -2
  22. package/src/components/PlayerEmbed/controllers/tracking/index.ts +10 -10
  23. package/src/components/PlayerEmbed/index.ts +33 -18
  24. package/src/components/PlayerEmbed/tests/PlayerEmbed.spec.ts +14 -7
  25. package/src/components/PlayerEmbed/tests/data.ts +120 -76
  26. package/src/components/PlayerEmbed/tests/media-data.ts +22 -0
  27. package/dist/es/browser-DfO9Pnu7.js +0 -921
  28. package/dist/es/browser-DfO9Pnu7.js.map +0 -1
  29. package/dist/es/index-5G8orrrP.js +0 -2609
  30. package/dist/es/index-5G8orrrP.js.map +0 -1
  31. package/dist/iife/dialog-embed/browser-DCzTItVw.js +0 -429
  32. package/dist/iife/dialog-embed/browser-DCzTItVw.js.map +0 -1
  33. package/dist/iife/dialog-embed/embed.js +0 -5
  34. package/dist/iife/dialog-embed/embed.js.map +0 -1
  35. package/dist/iife/dialog-embed/index-CgdXxP5z.js +0 -27698
  36. package/dist/iife/dialog-embed/index-CgdXxP5z.js.map +0 -1
  37. package/dist/iife/dialog-embed/src/components/DialogEmbed/DialogOverlay.d.ts +0 -20
  38. package/dist/iife/dialog-embed/src/components/DialogEmbed/DialogPortal.d.ts +0 -36
  39. package/dist/iife/dialog-embed/src/components/DialogEmbed/index.d.ts +0 -38
  40. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +0 -15
  41. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/fetcher.d.ts +0 -14
  42. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/tracking/index.d.ts +0 -36
  43. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +0 -17
  44. package/dist/iife/dialog-embed/src/components/PlayerEmbed/index.d.ts +0 -74
  45. package/dist/iife/dialog-embed/src/components/PlayerEmbed/tests/data.d.ts +0 -3
  46. package/dist/iife/dialog-embed/src/index.d.ts +0 -2
  47. package/dist/iife/dialog-embed/src/utils/env.d.ts +0 -12
  48. package/dist/iife/dialog-embed/src/utils/events.d.ts +0 -2
  49. package/dist/iife/player-embed/browser-BBSMddCs.js +0 -429
  50. package/dist/iife/player-embed/browser-BBSMddCs.js.map +0 -1
  51. package/dist/iife/player-embed/embed.js +0 -5
  52. package/dist/iife/player-embed/embed.js.map +0 -1
  53. package/dist/iife/player-embed/index-BGZl_iqR.js +0 -27255
  54. package/dist/iife/player-embed/index-BGZl_iqR.js.map +0 -1
  55. package/dist/iife/player-embed/src/components/DialogEmbed/DialogOverlay.d.ts +0 -20
  56. package/dist/iife/player-embed/src/components/DialogEmbed/DialogPortal.d.ts +0 -36
  57. package/dist/iife/player-embed/src/components/DialogEmbed/index.d.ts +0 -38
  58. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +0 -15
  59. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/fetcher.d.ts +0 -14
  60. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/tracking/index.d.ts +0 -36
  61. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +0 -17
  62. package/dist/iife/player-embed/src/components/PlayerEmbed/index.d.ts +0 -74
  63. package/dist/iife/player-embed/src/components/PlayerEmbed/tests/data.d.ts +0 -3
  64. package/dist/iife/player-embed/src/index.d.ts +0 -2
  65. package/dist/iife/player-embed/src/utils/env.d.ts +0 -12
  66. package/dist/iife/player-embed/src/utils/events.d.ts +0 -2
package/dist/es/embeds.js CHANGED
@@ -1,2 +1,1043 @@
1
- export { D as DialogEmbed, P as PlayerEmbed } from './index-5G8orrrP.js';
1
+ import { css, LitElement, html } from "lit";
2
+ import { property, state, customElement } from "lit/decorators.js";
3
+ import { ifDefined } from "lit/directives/if-defined.js";
4
+ import { createRef, ref } from "lit/directives/ref.js";
5
+ import { Task } from "@lit/task";
6
+ import { v4 } from "uuid";
7
+ import { TEMPLATE_VERSION } from "@vouchfor/canvas-video";
8
+ import "@vouchfor/media-player";
9
+ import { styleMap } from "lit/directives/style-map.js";
10
+ import { classMap } from "lit/directives/class-map.js";
11
+ import "@a11y/focus-trap";
12
+ function forwardEvent(type, fromElement, toElement) {
13
+ function forwarder(event) {
14
+ toElement.dispatchEvent(new CustomEvent(event.type, event));
15
+ }
16
+ fromElement.addEventListener(type, forwarder);
17
+ return () => {
18
+ fromElement.removeEventListener(type, forwarder);
19
+ };
20
+ }
21
+ class EventForwardController {
22
+ constructor(host, events) {
23
+ this._events = [];
24
+ this._cleanup = [];
25
+ this._forwardElementRef = createRef();
26
+ this.host = host;
27
+ this._events = events;
28
+ host.addController(this);
29
+ }
30
+ register() {
31
+ return ref(this._forwardElementRef);
32
+ }
33
+ hostConnected() {
34
+ requestAnimationFrame(() => {
35
+ this._events.forEach((event) => {
36
+ if (this._forwardElementRef.value) {
37
+ this._cleanup.push(forwardEvent(event, this._forwardElementRef.value, this.host));
38
+ }
39
+ });
40
+ });
41
+ }
42
+ hostDisconnected() {
43
+ this._cleanup.forEach((fn) => {
44
+ fn();
45
+ });
46
+ this._cleanup = [];
47
+ }
48
+ }
49
+ const devVideoUrl = "https://d2rxhdlm2q91uk.cloudfront.net";
50
+ const stagingVideoUrl = "https://d1ix11aj5kfygl.cloudfront.net";
51
+ const prodVideoUrl = "https://d157jlwnudd93d.cloudfront.net";
52
+ const devPublicApiUrl = "https://bshyfw4h5a.execute-api.ap-southeast-2.amazonaws.com/dev";
53
+ const stagingPublicApiUrl = "https://gyzw7rpbq3.execute-api.ap-southeast-2.amazonaws.com/staging";
54
+ const prodPublicApiUrl = "https://vfcjuim1l3.execute-api.ap-southeast-2.amazonaws.com/prod";
55
+ const localEmbedApiUrl = "http://localhost:6060/v2";
56
+ const devEmbedApiUrl = "https://embed-dev.vouchfor.com/v2";
57
+ const stagingEmbedApiUrl = "https://embed-staging.vouchfor.com/v2";
58
+ const prodEmbedApiUrl = "https://embed.vouchfor.com/v2";
59
+ function getEnvUrls(env) {
60
+ if (!["local", "dev", "staging", "prod"].includes(env)) {
61
+ throw new Error(`Unknown environment: ${env}`);
62
+ }
63
+ if (env === "local") {
64
+ return {
65
+ videoUrl: devVideoUrl,
66
+ publicApiUrl: devPublicApiUrl,
67
+ embedApiUrl: localEmbedApiUrl
68
+ };
69
+ }
70
+ if (env === "dev") {
71
+ return {
72
+ videoUrl: devVideoUrl,
73
+ publicApiUrl: devPublicApiUrl,
74
+ embedApiUrl: devEmbedApiUrl
75
+ };
76
+ }
77
+ if (env === "staging") {
78
+ return {
79
+ videoUrl: stagingVideoUrl,
80
+ publicApiUrl: stagingPublicApiUrl,
81
+ embedApiUrl: stagingEmbedApiUrl
82
+ };
83
+ }
84
+ if (env === "prod") {
85
+ return {
86
+ videoUrl: prodVideoUrl,
87
+ publicApiUrl: prodPublicApiUrl,
88
+ embedApiUrl: prodEmbedApiUrl
89
+ };
90
+ }
91
+ }
92
+ class FetcherController {
93
+ constructor(host) {
94
+ this._fetching = false;
95
+ this.getVouch = async (env, apiKey, vouchId) => {
96
+ var _a;
97
+ const { embedApiUrl } = getEnvUrls(env);
98
+ const cacheCheck = v4();
99
+ const res = await fetch(`${embedApiUrl}/vouches/${vouchId}`, {
100
+ method: "GET",
101
+ headers: [
102
+ ["X-Api-Key", apiKey],
103
+ ["X-Cache-Check", cacheCheck]
104
+ ]
105
+ });
106
+ const vouch = await res.json();
107
+ this.host.dispatchEvent(new CustomEvent("vouch:loaded", { detail: vouch == null ? void 0 : vouch.id }));
108
+ const resCacheCheck = (_a = res == null ? void 0 : res.headers) == null ? void 0 : _a.get("X-Cache-Check");
109
+ if (resCacheCheck !== cacheCheck) {
110
+ fetch(`${embedApiUrl}/vouches/${vouchId}`, {
111
+ method: "GET",
112
+ headers: [
113
+ ["X-Api-Key", apiKey],
114
+ ["Cache-Control", "max-age=0"]
115
+ ]
116
+ });
117
+ }
118
+ return vouch;
119
+ };
120
+ this.getTemplate = async (env, apiKey, templateId) => {
121
+ var _a;
122
+ const { embedApiUrl } = getEnvUrls(env);
123
+ const cacheCheck = v4();
124
+ const res = await fetch(`${embedApiUrl}/templates/${templateId}`, {
125
+ method: "GET",
126
+ headers: [
127
+ ["X-Api-Key", apiKey],
128
+ ["X-Cache-Check", cacheCheck]
129
+ ]
130
+ });
131
+ const template = await res.json();
132
+ const resCacheCheck = (_a = res == null ? void 0 : res.headers) == null ? void 0 : _a.get("X-Cache-Check");
133
+ if (resCacheCheck !== cacheCheck) {
134
+ fetch(`${embedApiUrl}/templates/${templateId}`, {
135
+ method: "GET",
136
+ headers: [
137
+ ["X-Api-Key", apiKey],
138
+ ["Cache-Control", "max-age=0"]
139
+ ]
140
+ });
141
+ }
142
+ return template;
143
+ };
144
+ this.host = host;
145
+ new Task(
146
+ this.host,
147
+ async ([env, apiKey, data, vouchId, templateId]) => {
148
+ var _a, _b, _c, _d;
149
+ try {
150
+ host.vouch = void 0;
151
+ host.template = void 0;
152
+ if (data) {
153
+ let template;
154
+ if (templateId) {
155
+ this.fetching = true;
156
+ template = await this.getTemplate(env, apiKey, templateId);
157
+ }
158
+ this._vouch = data;
159
+ host.template = template ?? ((_b = (_a = data == null ? void 0 : data.settings) == null ? void 0 : _a.template) == null ? void 0 : _b.instance);
160
+ } else if (vouchId) {
161
+ this.fetching = true;
162
+ const [vouch, template] = await Promise.all([
163
+ this.getVouch(env, apiKey, vouchId),
164
+ templateId ? this.getTemplate(env, apiKey, templateId) : null
165
+ ]);
166
+ this._vouch = vouch;
167
+ host.template = template ?? ((_d = (_c = vouch == null ? void 0 : vouch.settings) == null ? void 0 : _c.template) == null ? void 0 : _d.instance);
168
+ }
169
+ } finally {
170
+ this.fetching = false;
171
+ }
172
+ },
173
+ () => [host.env, host.apiKey, host.data, host.vouchId, host.templateId]
174
+ );
175
+ new Task(
176
+ this.host,
177
+ ([vouch, questions]) => {
178
+ host.vouch = vouch ? {
179
+ ...vouch,
180
+ questions: {
181
+ items: vouch == null ? void 0 : vouch.questions.items.filter((_, index) => !(questions == null ? void 0 : questions.length) || (questions == null ? void 0 : questions.includes(index + 1)))
182
+ }
183
+ } : void 0;
184
+ },
185
+ () => [this._vouch, host.questions]
186
+ );
187
+ }
188
+ set fetching(value) {
189
+ if (this._fetching !== value) {
190
+ this._fetching = value;
191
+ this.host.requestUpdate();
192
+ }
193
+ }
194
+ get fetching() {
195
+ return this._fetching;
196
+ }
197
+ }
198
+ const version = "0.0.0-experiment.8d72879";
199
+ const packageJson = {
200
+ version
201
+ };
202
+ function createVisitor(env) {
203
+ const { publicApiUrl } = getEnvUrls(env);
204
+ const visitorId = v4();
205
+ navigator.sendBeacon(`${publicApiUrl}/api/visitor`, JSON.stringify({ visitorId }));
206
+ return visitorId;
207
+ }
208
+ function getUids(env) {
209
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
210
+ if (typeof window === "undefined") {
211
+ return {
212
+ client: null,
213
+ tab: null,
214
+ request: v4()
215
+ };
216
+ }
217
+ let visitorId = (_b = (_a = window.localStorage) == null ? void 0 : _a.getItem) == null ? void 0 : _b.call(_a, "vouch-uid-visitor");
218
+ let clientId = (_d = (_c = window.localStorage) == null ? void 0 : _c.getItem) == null ? void 0 : _d.call(_c, "vouch-uid-client");
219
+ let tabId = (_f = (_e = window.sessionStorage) == null ? void 0 : _e.getItem) == null ? void 0 : _f.call(_e, "vouch-uid-tab");
220
+ const requestId = v4();
221
+ if (!visitorId) {
222
+ visitorId = createVisitor(env);
223
+ (_h = (_g = window.localStorage) == null ? void 0 : _g.setItem) == null ? void 0 : _h.call(_g, "vouch-uid-visitor", visitorId);
224
+ }
225
+ if (!clientId) {
226
+ clientId = v4();
227
+ (_j = (_i = window.localStorage) == null ? void 0 : _i.setItem) == null ? void 0 : _j.call(_i, "vouch-uid-client", clientId);
228
+ }
229
+ if (!tabId) {
230
+ tabId = v4();
231
+ (_l = (_k = window.sessionStorage) == null ? void 0 : _k.setItem) == null ? void 0 : _l.call(_k, "vouch-uid-tab", tabId);
232
+ }
233
+ return {
234
+ client: clientId,
235
+ tab: tabId,
236
+ request: requestId,
237
+ visitor: visitorId
238
+ };
239
+ }
240
+ function findVouchId(payload, vouch) {
241
+ if (payload && "vouchId" in payload) {
242
+ return payload.vouchId;
243
+ }
244
+ return (vouch == null ? void 0 : vouch.id) ?? null;
245
+ }
246
+ function getReportingMetadata(source = "embedded_player") {
247
+ var _a, _b;
248
+ const [country, region] = ((_b = (_a = Intl.DateTimeFormat().resolvedOptions().timeZone) == null ? void 0 : _a.split) == null ? void 0 : _b.call(_a, "/")) ?? [];
249
+ const utmParams = {};
250
+ [...new URLSearchParams(location.search).entries()].forEach(([key, value]) => {
251
+ if (/utm/.test(key)) {
252
+ const param = key.toLowerCase().replace(/[-_][a-z0-9]/g, (group) => group.slice(-1).toUpperCase());
253
+ utmParams[param] = value;
254
+ }
255
+ });
256
+ return {
257
+ source,
258
+ time: /* @__PURE__ */ new Date(),
259
+ region,
260
+ country,
261
+ screenHeight: window.screen.height,
262
+ screenWidth: window.screen.width,
263
+ referrer: document.referrer,
264
+ currentUrl: location.href,
265
+ embedType: "media-player-embed",
266
+ embedVersion: packageJson.version,
267
+ templateVersion: TEMPLATE_VERSION,
268
+ ...utmParams
269
+ };
270
+ }
271
+ const MINIMUM_SEND_THRESHOLD = 1;
272
+ class TrackingController {
273
+ constructor(host) {
274
+ this._batchedEvents = [];
275
+ this._hasPlayed = false;
276
+ this._hasLoaded = {};
277
+ this._answersViewed = {};
278
+ this._streamStartTime = {};
279
+ this._streamLatestTime = {};
280
+ this._currentlyPlayingVideo = null;
281
+ this._createTrackingEvent = (event, payload) => {
282
+ const vouchId = findVouchId(payload, this.host.vouch);
283
+ if (!vouchId || this.host.disableTracking) {
284
+ return;
285
+ }
286
+ this._batchedEvents.push({
287
+ event,
288
+ payload: {
289
+ ...payload,
290
+ senderId: this.host.senderId,
291
+ vouchId,
292
+ time: (/* @__PURE__ */ new Date()).toISOString()
293
+ }
294
+ });
295
+ };
296
+ this._sendTrackingEvent = () => {
297
+ if (this._batchedEvents.length <= 0) {
298
+ return;
299
+ }
300
+ const { publicApiUrl } = getEnvUrls(this.host.env);
301
+ const { client, tab, request, visitor } = getUids(this.host.env);
302
+ navigator.sendBeacon(
303
+ `${publicApiUrl}/api/batchevents`,
304
+ JSON.stringify({
305
+ payload: {
306
+ events: this._batchedEvents
307
+ },
308
+ context: {
309
+ "x-uid-client": client,
310
+ "x-uid-tab": tab,
311
+ "x-uid-request": request,
312
+ "x-uid-visitor": visitor,
313
+ "x-reporting-metadata": getReportingMetadata(this.host.trackingSource)
314
+ }
315
+ })
316
+ );
317
+ this._batchedEvents = [];
318
+ };
319
+ this._streamEnded = () => {
320
+ if (this._currentlyPlayingVideo) {
321
+ const { id, key } = this._currentlyPlayingVideo;
322
+ if (this._streamLatestTime[key] > this._streamStartTime[key] + MINIMUM_SEND_THRESHOLD) {
323
+ this._createTrackingEvent("VIDEO_STREAMED", {
324
+ answerId: id,
325
+ streamStart: this._streamStartTime[key],
326
+ streamEnd: this._streamLatestTime[key]
327
+ });
328
+ }
329
+ delete this._streamStartTime[key];
330
+ delete this._streamLatestTime[key];
331
+ }
332
+ };
333
+ this._handleVouchLoaded = ({ detail: vouchId }) => {
334
+ if (!vouchId) {
335
+ return;
336
+ }
337
+ if (!this._hasLoaded[vouchId]) {
338
+ this._createTrackingEvent("VOUCH_LOADED", { vouchId });
339
+ this._hasLoaded[vouchId] = true;
340
+ }
341
+ };
342
+ this._handlePlay = () => {
343
+ if (!this._hasPlayed) {
344
+ this._createTrackingEvent("VIDEO_PLAYED", { streamStart: this.host.currentTime });
345
+ this._hasPlayed = true;
346
+ }
347
+ };
348
+ this._handleVideoPlay = ({ detail: { id, key } }) => {
349
+ if (!this._answersViewed[key]) {
350
+ this._createTrackingEvent("VOUCH_RESPONSE_VIEWED", {
351
+ answerId: id
352
+ });
353
+ this._answersViewed[key] = true;
354
+ }
355
+ };
356
+ this._handleVideoTimeUpdate = ({ detail: { id, key, node } }) => {
357
+ if (
358
+ // We only want to count any time that the video is actually playing
359
+ !this.host.paused
360
+ ) {
361
+ this._currentlyPlayingVideo = { id, key, node };
362
+ this._streamLatestTime[key] = node.currentTime;
363
+ if (!this._streamStartTime[key]) {
364
+ this._streamStartTime[key] = node.currentTime;
365
+ this._streamLatestTime[key] = node.currentTime;
366
+ }
367
+ }
368
+ };
369
+ this._handleVideoPause = ({ detail: { id, key } }) => {
370
+ if (this._streamLatestTime[key] > this._streamStartTime[key] + MINIMUM_SEND_THRESHOLD) {
371
+ this._createTrackingEvent("VIDEO_STREAMED", {
372
+ answerId: id,
373
+ streamStart: this._streamStartTime[key],
374
+ streamEnd: this._streamLatestTime[key]
375
+ });
376
+ }
377
+ delete this._streamStartTime[key];
378
+ delete this._streamLatestTime[key];
379
+ };
380
+ this._pageUnloading = () => {
381
+ this._streamEnded();
382
+ this._sendTrackingEvent();
383
+ };
384
+ this._handleVisibilityChange = () => {
385
+ if (document.visibilityState === "hidden") {
386
+ this._pageUnloading();
387
+ }
388
+ };
389
+ this._handlePageHide = () => {
390
+ this._pageUnloading();
391
+ };
392
+ this.host = host;
393
+ host.addController(this);
394
+ }
395
+ hostConnected() {
396
+ requestAnimationFrame(() => {
397
+ var _a, _b, _c, _d;
398
+ if ("onvisibilitychange" in document) {
399
+ document.addEventListener("visibilitychange", this._handleVisibilityChange);
400
+ } else {
401
+ window.addEventListener("pagehide", this._handlePageHide);
402
+ }
403
+ this.host.addEventListener("vouch:loaded", this._handleVouchLoaded);
404
+ (_a = this.host.mediaPlayer) == null ? void 0 : _a.addEventListener("play", this._handlePlay);
405
+ (_b = this.host.mediaPlayer) == null ? void 0 : _b.addEventListener("video:play", this._handleVideoPlay);
406
+ (_c = this.host.mediaPlayer) == null ? void 0 : _c.addEventListener("video:pause", this._handleVideoPause);
407
+ (_d = this.host.mediaPlayer) == null ? void 0 : _d.addEventListener("video:timeupdate", this._handleVideoTimeUpdate);
408
+ });
409
+ }
410
+ hostDisconnected() {
411
+ var _a, _b, _c, _d;
412
+ this._pageUnloading();
413
+ if ("onvisibilitychange" in document) {
414
+ document.removeEventListener("visibilitychange", this._handleVisibilityChange);
415
+ } else {
416
+ window.removeEventListener("pagehide", this._handlePageHide);
417
+ }
418
+ this.host.removeEventListener("vouch:loaded", this._handleVouchLoaded);
419
+ (_a = this.host.mediaPlayer) == null ? void 0 : _a.removeEventListener("play", this._handlePlay);
420
+ (_b = this.host.mediaPlayer) == null ? void 0 : _b.removeEventListener("video:play", this._handleVideoPlay);
421
+ (_c = this.host.mediaPlayer) == null ? void 0 : _c.removeEventListener("video:pause", this._handleVideoPause);
422
+ (_d = this.host.mediaPlayer) == null ? void 0 : _d.removeEventListener("video:timeupdate", this._handleVideoTimeUpdate);
423
+ }
424
+ }
425
+ var __defProp$3 = Object.defineProperty;
426
+ var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
427
+ var __decorateClass$3 = (decorators, target, key, kind) => {
428
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
429
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
430
+ if (decorator = decorators[i])
431
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
432
+ if (kind && result) __defProp$3(target, key, result);
433
+ return result;
434
+ };
435
+ let PlayerEmbed = class extends LitElement {
436
+ constructor() {
437
+ super(...arguments);
438
+ this.env = "prod";
439
+ this.apiKey = "";
440
+ this.disableTracking = false;
441
+ this.trackingSource = "embedded_player";
442
+ this.preload = "auto";
443
+ this.autoplay = false;
444
+ this.aspectRatio = 0;
445
+ this.eventController = new EventForwardController(this, [
446
+ "durationchange",
447
+ "ended",
448
+ "error",
449
+ "loadeddata",
450
+ "pause",
451
+ "stalled",
452
+ "play",
453
+ "playing",
454
+ "ratechange",
455
+ "scenechange",
456
+ "scenesupdate",
457
+ "seeking",
458
+ "seeked",
459
+ "timeupdate",
460
+ "volumechange",
461
+ "processing",
462
+ "waiting",
463
+ "video:loadeddata",
464
+ "video:seeking",
465
+ "video:seeked",
466
+ "video:play",
467
+ "video:playing",
468
+ "video:pause",
469
+ "video:waiting",
470
+ "video:stalled",
471
+ "video:timeupdate",
472
+ "video:ended",
473
+ "video:error"
474
+ ]);
475
+ this._fetcherController = new FetcherController(this);
476
+ this._trackingController = new TrackingController(this);
477
+ this._mediaPlayerRef = createRef();
478
+ }
479
+ get fetching() {
480
+ return this._fetcherController.fetching;
481
+ }
482
+ get waiting() {
483
+ var _a;
484
+ return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.waiting;
485
+ }
486
+ get initialised() {
487
+ var _a;
488
+ return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.initialised;
489
+ }
490
+ get seeking() {
491
+ var _a;
492
+ return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.seeking;
493
+ }
494
+ get paused() {
495
+ var _a;
496
+ return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.paused;
497
+ }
498
+ get captions() {
499
+ var _a;
500
+ return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.captions;
501
+ }
502
+ get fullscreen() {
503
+ var _a;
504
+ return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.fullscreen;
505
+ }
506
+ get duration() {
507
+ var _a;
508
+ return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.duration;
509
+ }
510
+ set currentTime(value) {
511
+ if (this._mediaPlayerRef.value) {
512
+ this._mediaPlayerRef.value.currentTime = value;
513
+ }
514
+ }
515
+ get currentTime() {
516
+ var _a;
517
+ return ((_a = this._mediaPlayerRef.value) == null ? void 0 : _a.currentTime) ?? 0;
518
+ }
519
+ set playbackRate(value) {
520
+ if (this._mediaPlayerRef.value) {
521
+ this._mediaPlayerRef.value.playbackRate = value;
522
+ }
523
+ }
524
+ get playbackRate() {
525
+ var _a;
526
+ return ((_a = this._mediaPlayerRef.value) == null ? void 0 : _a.playbackRate) ?? 1;
527
+ }
528
+ set volume(value) {
529
+ if (this._mediaPlayerRef.value) {
530
+ this._mediaPlayerRef.value.volume = value;
531
+ }
532
+ }
533
+ get volume() {
534
+ var _a;
535
+ return ((_a = this._mediaPlayerRef.value) == null ? void 0 : _a.volume) ?? 1;
536
+ }
537
+ set muted(value) {
538
+ if (this._mediaPlayerRef.value) {
539
+ this._mediaPlayerRef.value.muted = value;
540
+ }
541
+ }
542
+ get muted() {
543
+ var _a;
544
+ return ((_a = this._mediaPlayerRef.value) == null ? void 0 : _a.muted) ?? false;
545
+ }
546
+ // get scene(): Scene | null {
547
+ // return this._mediaPlayerRef.value?.scene ?? null;
548
+ // }
549
+ // get scenes(): Scene[] {
550
+ // return this._mediaPlayerRef.value?.scenes ?? [];
551
+ // }
552
+ // get sceneConfig(): Scenes | null {
553
+ // return this._mediaPlayerRef.value?.sceneConfig ?? null;
554
+ // }
555
+ get mediaState() {
556
+ var _a;
557
+ return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.mediaState;
558
+ }
559
+ get mediaPlayer() {
560
+ return this._mediaPlayerRef.value;
561
+ }
562
+ play() {
563
+ var _a;
564
+ (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.play();
565
+ }
566
+ pause() {
567
+ var _a;
568
+ (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.pause();
569
+ }
570
+ reset(time = 0, play = false) {
571
+ var _a;
572
+ (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.reset(time, play);
573
+ }
574
+ // setScene(index: number) {
575
+ // this._mediaPlayerRef.value?.setScene(index);
576
+ // }
577
+ _renderStyles() {
578
+ if (!this.aspectRatio) {
579
+ return html`
580
+ <style>
581
+ :host {
582
+ width: 100%;
583
+ height: 100%;
584
+ }
585
+ </style>
586
+ `;
587
+ }
588
+ if (typeof this.aspectRatio === "number") {
589
+ return html`
590
+ <style>
591
+ :host {
592
+ aspect-ratio: ${this.aspectRatio};
593
+ }
594
+ </style>
595
+ `;
596
+ }
597
+ return null;
598
+ }
599
+ willUpdate(changedProperties) {
600
+ if (changedProperties.has("vouchId") && this.vouchId !== changedProperties.get("vouchId")) {
601
+ this.reset(0, false);
602
+ }
603
+ }
604
+ render() {
605
+ return html`
606
+ ${this._renderStyles()}
607
+ <vmp-media-player
608
+ ${ref(this._mediaPlayerRef)}
609
+ ${this.eventController.register()}
610
+ ?autoplay=${this.autoplay}
611
+ ?loading=${this.fetching}
612
+ aspectRatio=${ifDefined(this.aspectRatio)}
613
+ preload=${ifDefined(this.preload)}
614
+ language=${ifDefined(this.language)}
615
+ .controls=${this.controls}
616
+ ></vmp-media-player>
617
+ `;
618
+ }
619
+ };
620
+ PlayerEmbed.styles = [
621
+ css`
622
+ :host {
623
+ display: flex;
624
+ }
625
+ `
626
+ ];
627
+ __decorateClass$3([
628
+ property({ type: Object })
629
+ ], PlayerEmbed.prototype, "data", 2);
630
+ __decorateClass$3([
631
+ property({ type: String })
632
+ ], PlayerEmbed.prototype, "vouchId", 2);
633
+ __decorateClass$3([
634
+ property({ type: String })
635
+ ], PlayerEmbed.prototype, "templateId", 2);
636
+ __decorateClass$3([
637
+ property({ type: Array })
638
+ ], PlayerEmbed.prototype, "questions", 2);
639
+ __decorateClass$3([
640
+ property({ type: String })
641
+ ], PlayerEmbed.prototype, "env", 2);
642
+ __decorateClass$3([
643
+ property({ type: String })
644
+ ], PlayerEmbed.prototype, "apiKey", 2);
645
+ __decorateClass$3([
646
+ property({ type: Boolean })
647
+ ], PlayerEmbed.prototype, "disableTracking", 2);
648
+ __decorateClass$3([
649
+ property({ type: String })
650
+ ], PlayerEmbed.prototype, "trackingSource", 2);
651
+ __decorateClass$3([
652
+ property({ type: Array })
653
+ ], PlayerEmbed.prototype, "controls", 2);
654
+ __decorateClass$3([
655
+ property({ type: String })
656
+ ], PlayerEmbed.prototype, "preload", 2);
657
+ __decorateClass$3([
658
+ property({ type: Boolean })
659
+ ], PlayerEmbed.prototype, "autoplay", 2);
660
+ __decorateClass$3([
661
+ property({ type: Number })
662
+ ], PlayerEmbed.prototype, "aspectRatio", 2);
663
+ __decorateClass$3([
664
+ property({ type: String })
665
+ ], PlayerEmbed.prototype, "language", 2);
666
+ __decorateClass$3([
667
+ property({ type: String })
668
+ ], PlayerEmbed.prototype, "senderId", 2);
669
+ __decorateClass$3([
670
+ state()
671
+ ], PlayerEmbed.prototype, "vouch", 2);
672
+ __decorateClass$3([
673
+ state()
674
+ ], PlayerEmbed.prototype, "template", 2);
675
+ PlayerEmbed = __decorateClass$3([
676
+ customElement("vouch-embed-player")
677
+ ], PlayerEmbed);
678
+ var __defProp$2 = Object.defineProperty;
679
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
680
+ var __decorateClass$2 = (decorators, target, key, kind) => {
681
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
682
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
683
+ if (decorator = decorators[i])
684
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
685
+ if (kind && result) __defProp$2(target, key, result);
686
+ return result;
687
+ };
688
+ let DialogOverlay = class extends LitElement {
689
+ constructor() {
690
+ super(...arguments);
691
+ this.open = false;
692
+ this.aspectRatio = 0;
693
+ }
694
+ render() {
695
+ return html`
696
+ <div
697
+ class=${classMap({
698
+ container: true,
699
+ hidden: !this.open
700
+ })}
701
+ >
702
+ <div
703
+ class="background"
704
+ @click=${() => this.dispatchEvent(new CustomEvent("overlay:click", { bubbles: true, composed: true }))}
705
+ ></div>
706
+ <focus-trap>
707
+ <div
708
+ class=${classMap({
709
+ "video-frame": true,
710
+ grow: this.aspectRatio === 0
711
+ })}
712
+ style=${styleMap({
713
+ aspectRatio: this.aspectRatio
714
+ })}
715
+ >
716
+ <slot></slot>
717
+ <vmp-icon-button
718
+ icon="close"
719
+ rounded="full"
720
+ weight="heavy"
721
+ @click=${() => this.dispatchEvent(new CustomEvent("close:click", { bubbles: true, composed: true }))}
722
+ ></vmp-icon-button>
723
+ </div>
724
+ </focus-trap>
725
+ </div>
726
+ `;
727
+ }
728
+ };
729
+ DialogOverlay.styles = [
730
+ css`
731
+ :host {
732
+ --vouch-media-player-border-radius: var(--vu-media-player-border-radius, 12px);
733
+ --overlay-background-color: var(--vu-overlay-background-color, black);
734
+ --overlay-background-opacity: var(--vu-overlay-background-opacity, 0.4);
735
+
736
+ --dialog-width: var(--vu-dialog-width, 890px);
737
+ --dialog-height: var(--vu-dialog-height, 500px);
738
+ }
739
+
740
+ .container {
741
+ position: fixed;
742
+ display: flex;
743
+ inset: 0;
744
+ opacity: 1;
745
+ z-index: 2147483647;
746
+ align-items: center;
747
+ justify-content: center;
748
+ transition: opacity 100ms ease-in;
749
+ }
750
+
751
+ .hidden {
752
+ opacity: 0;
753
+ pointer-events: none;
754
+ }
755
+
756
+ .background {
757
+ position: absolute;
758
+ inset: 0;
759
+ opacity: var(--overlay-background-opacity);
760
+ background-color: var(--overlay-background-color);
761
+ }
762
+
763
+ focus-trap {
764
+ display: flex;
765
+ align-items: center;
766
+ justify-content: center;
767
+ margin: 40px;
768
+ width: var(--dialog-width);
769
+ height: var(--dialog-height);
770
+ max-width: calc(100% - 80px);
771
+ max-height: calc(100% - 80px);
772
+ }
773
+
774
+ .video-frame {
775
+ position: relative;
776
+ display: flex;
777
+ align-items: center;
778
+ justify-content: center;
779
+ max-width: 100%;
780
+ max-height: 100%;
781
+ }
782
+
783
+ .video-frame.grow {
784
+ width: 100%;
785
+ height: 100%;
786
+ }
787
+
788
+ vmp-icon-button {
789
+ position: absolute;
790
+ top: 0;
791
+ right: 0;
792
+ margin: 10px;
793
+ }
794
+ `
795
+ ];
796
+ __decorateClass$2([
797
+ property({ type: Boolean })
798
+ ], DialogOverlay.prototype, "open", 2);
799
+ __decorateClass$2([
800
+ property({ type: Number })
801
+ ], DialogOverlay.prototype, "aspectRatio", 2);
802
+ DialogOverlay = __decorateClass$2([
803
+ customElement("vouch-embed-dialog-overlay")
804
+ ], DialogOverlay);
805
+ var __defProp$1 = Object.defineProperty;
806
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
807
+ var __decorateClass$1 = (decorators, target, key, kind) => {
808
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
809
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
810
+ if (decorator = decorators[i])
811
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
812
+ if (kind && result) __defProp$1(target, key, result);
813
+ return result;
814
+ };
815
+ let DialogPortal = class extends LitElement {
816
+ constructor() {
817
+ super(...arguments);
818
+ this.env = "prod";
819
+ this.apiKey = "";
820
+ this.disableTracking = false;
821
+ this.trackingSource = "embedded_player";
822
+ this.preload = "none";
823
+ this.disableAutoplay = false;
824
+ this.aspectRatio = 0;
825
+ this._mediaPlayerRef = createRef();
826
+ this.open = false;
827
+ this._handleToggle = ({ detail }) => {
828
+ var _a, _b, _c;
829
+ if (this.id === detail) {
830
+ this.open = !this.open;
831
+ if (this.open) {
832
+ if (!this.disableAutoplay && ((_a = this._mediaPlayerRef) == null ? void 0 : _a.value)) {
833
+ this._mediaPlayerRef.value.muted = false;
834
+ this._mediaPlayerRef.value.play();
835
+ }
836
+ } else {
837
+ (_c = (_b = this._mediaPlayerRef) == null ? void 0 : _b.value) == null ? void 0 : _c.pause();
838
+ }
839
+ }
840
+ };
841
+ this._handleClose = () => {
842
+ var _a, _b;
843
+ this.open = false;
844
+ (_b = (_a = this._mediaPlayerRef) == null ? void 0 : _a.value) == null ? void 0 : _b.pause();
845
+ };
846
+ this._handleDocumentKeyUp = (e) => {
847
+ if (e.key === "Escape") {
848
+ this._handleClose();
849
+ }
850
+ };
851
+ }
852
+ connectedCallback() {
853
+ super.connectedCallback();
854
+ document.addEventListener("dialogembed:click", this._handleToggle);
855
+ document.addEventListener("keyup", this._handleDocumentKeyUp);
856
+ document.addEventListener("close:click", this._handleClose);
857
+ document.addEventListener("overlay:click", this._handleClose);
858
+ }
859
+ disconnectedCallback() {
860
+ super.disconnectedCallback();
861
+ document.removeEventListener("dialogembed:click", this._handleToggle);
862
+ document.removeEventListener("keyup", this._handleDocumentKeyUp);
863
+ document.removeEventListener("close:click", this._handleClose);
864
+ document.removeEventListener("overlay:click", this._handleClose);
865
+ }
866
+ createRenderRoot() {
867
+ const newNode = document.createElement("div");
868
+ document.body.appendChild(newNode);
869
+ return newNode;
870
+ }
871
+ render() {
872
+ return html`
873
+ <vouch-embed-dialog-overlay ?open=${this.open} aspectRatio=${this.aspectRatio}>
874
+ <vouch-embed-player
875
+ ${ref(this._mediaPlayerRef)}
876
+ style=${styleMap({
877
+ maxWidth: "100%",
878
+ maxHeight: "100%"
879
+ })}
880
+ ?autoplay=${false}
881
+ vouchId=${ifDefined(this.vouchId)}
882
+ templateId=${ifDefined(this.templateId)}
883
+ .questions=${this.questions}
884
+ .controls=${this.controls}
885
+ env=${ifDefined(this.env)}
886
+ apiKey=${ifDefined(this.apiKey)}
887
+ ?disableTracking=${this.disableTracking}
888
+ trackingSource=${ifDefined(this.trackingSource)}
889
+ preload=${ifDefined(this.preload)}
890
+ aspectRatio=${this.aspectRatio}
891
+ ></vouch-embed-player>
892
+ </vouch-embed-dialog-overlay>
893
+ `;
894
+ }
895
+ };
896
+ __decorateClass$1([
897
+ property({ type: String })
898
+ ], DialogPortal.prototype, "vouchId", 2);
899
+ __decorateClass$1([
900
+ property({ type: String })
901
+ ], DialogPortal.prototype, "templateId", 2);
902
+ __decorateClass$1([
903
+ property({ type: Array })
904
+ ], DialogPortal.prototype, "questions", 2);
905
+ __decorateClass$1([
906
+ property({ type: String })
907
+ ], DialogPortal.prototype, "env", 2);
908
+ __decorateClass$1([
909
+ property({ type: String })
910
+ ], DialogPortal.prototype, "apiKey", 2);
911
+ __decorateClass$1([
912
+ property({ type: Boolean })
913
+ ], DialogPortal.prototype, "disableTracking", 2);
914
+ __decorateClass$1([
915
+ property({ type: String })
916
+ ], DialogPortal.prototype, "trackingSource", 2);
917
+ __decorateClass$1([
918
+ property({ type: Array })
919
+ ], DialogPortal.prototype, "controls", 2);
920
+ __decorateClass$1([
921
+ property({ type: String })
922
+ ], DialogPortal.prototype, "preload", 2);
923
+ __decorateClass$1([
924
+ property({ type: Boolean })
925
+ ], DialogPortal.prototype, "disableAutoplay", 2);
926
+ __decorateClass$1([
927
+ property({ type: Number })
928
+ ], DialogPortal.prototype, "aspectRatio", 2);
929
+ __decorateClass$1([
930
+ state()
931
+ ], DialogPortal.prototype, "open", 2);
932
+ DialogPortal = __decorateClass$1([
933
+ customElement("vouch-embed-dialog-portal")
934
+ ], DialogPortal);
935
+ var __defProp = Object.defineProperty;
936
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
937
+ var __decorateClass = (decorators, target, key, kind) => {
938
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
939
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
940
+ if (decorator = decorators[i])
941
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
942
+ if (kind && result) __defProp(target, key, result);
943
+ return result;
944
+ };
945
+ let DialogEmbed = class extends LitElement {
946
+ constructor() {
947
+ super(...arguments);
948
+ this.env = "prod";
949
+ this.apiKey = "";
950
+ this.disableTracking = false;
951
+ this.trackingSource = "embedded_player";
952
+ this.preload = "none";
953
+ this.disableAutoplay = false;
954
+ this.aspectRatio = 0;
955
+ this._id = v4();
956
+ this._handleRootClick = () => {
957
+ this.dispatchEvent(new CustomEvent("dialogembed:click", { detail: this._id, bubbles: true, composed: true }));
958
+ };
959
+ }
960
+ connectedCallback() {
961
+ super.connectedCallback();
962
+ this.addEventListener("click", this._handleRootClick);
963
+ }
964
+ disconnectedCallback() {
965
+ super.disconnectedCallback();
966
+ this.removeEventListener("click", this._handleRootClick);
967
+ }
968
+ render() {
969
+ return html`
970
+ <slot>
971
+ <vmp-button size="large">Play</vmp-button>
972
+ </slot>
973
+ <vouch-embed-dialog-portal
974
+ id=${this._id}
975
+ ?autoplay=${false}
976
+ vouchId=${ifDefined(this.vouchId)}
977
+ templateId=${ifDefined(this.templateId)}
978
+ .questions=${this.questions}
979
+ .controls=${this.controls}
980
+ env=${ifDefined(this.env)}
981
+ apiKey=${ifDefined(this.apiKey)}
982
+ ?disableTracking=${this.disableTracking}
983
+ trackingSource=${ifDefined(this.trackingSource)}
984
+ preload=${ifDefined(this.preload)}
985
+ aspectRatio=${this.aspectRatio}
986
+ ></vouch-embed-dialog-portal>
987
+ `;
988
+ }
989
+ };
990
+ DialogEmbed.styles = [
991
+ css`
992
+ :host {
993
+ --vu-button-padding: 10px 20px;
994
+ --vu-button-background: #287179;
995
+ --vu-button-background-hover: #4faab2;
996
+
997
+ display: flex;
998
+ width: fit-content;
999
+ height: fit-content;
1000
+ }
1001
+ `
1002
+ ];
1003
+ __decorateClass([
1004
+ property({ type: String })
1005
+ ], DialogEmbed.prototype, "vouchId", 2);
1006
+ __decorateClass([
1007
+ property({ type: String })
1008
+ ], DialogEmbed.prototype, "templateId", 2);
1009
+ __decorateClass([
1010
+ property({ type: Array })
1011
+ ], DialogEmbed.prototype, "questions", 2);
1012
+ __decorateClass([
1013
+ property({ type: String })
1014
+ ], DialogEmbed.prototype, "env", 2);
1015
+ __decorateClass([
1016
+ property({ type: String })
1017
+ ], DialogEmbed.prototype, "apiKey", 2);
1018
+ __decorateClass([
1019
+ property({ type: Boolean })
1020
+ ], DialogEmbed.prototype, "disableTracking", 2);
1021
+ __decorateClass([
1022
+ property({ type: String })
1023
+ ], DialogEmbed.prototype, "trackingSource", 2);
1024
+ __decorateClass([
1025
+ property({ type: Array })
1026
+ ], DialogEmbed.prototype, "controls", 2);
1027
+ __decorateClass([
1028
+ property({ type: String })
1029
+ ], DialogEmbed.prototype, "preload", 2);
1030
+ __decorateClass([
1031
+ property({ type: Boolean })
1032
+ ], DialogEmbed.prototype, "disableAutoplay", 2);
1033
+ __decorateClass([
1034
+ property({ type: Number })
1035
+ ], DialogEmbed.prototype, "aspectRatio", 2);
1036
+ DialogEmbed = __decorateClass([
1037
+ customElement("vouch-embed-dialog")
1038
+ ], DialogEmbed);
1039
+ export {
1040
+ DialogEmbed,
1041
+ PlayerEmbed
1042
+ };
2
1043
  //# sourceMappingURL=embeds.js.map