@vouchfor/embeds 0.0.0-experiment.f112aaa → 0.0.0-experiment.f27fcf4

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 (40) hide show
  1. package/dist/es/embeds.js +1036 -7
  2. package/dist/es/embeds.js.map +1 -1
  3. package/dist/es/src/components/DialogEmbed/DialogOverlay.d.ts +20 -0
  4. package/dist/es/src/components/DialogEmbed/DialogPortal.d.ts +36 -0
  5. package/dist/es/src/components/DialogEmbed/index.d.ts +37 -0
  6. package/dist/es/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +16 -0
  7. package/dist/es/src/components/{Embed → PlayerEmbed}/controllers/fetcher.d.ts +6 -5
  8. package/dist/es/src/components/{Embed/controllers/tracking.d.ts → PlayerEmbed/controllers/tracking/index.d.ts} +16 -12
  9. package/dist/es/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +18 -0
  10. package/dist/es/src/components/PlayerEmbed/index.d.ts +74 -0
  11. package/dist/es/src/components/PlayerEmbed/tests/data.d.ts +5 -0
  12. package/dist/es/src/components/PlayerEmbed/tests/media-data.d.ts +19 -0
  13. package/dist/es/src/index.d.ts +2 -1
  14. package/dist/iife/dialog-embed/embed.iife.js +4078 -0
  15. package/dist/iife/dialog-embed/embed.iife.js.map +1 -0
  16. package/dist/iife/embeds.iife.js +2903 -383
  17. package/dist/iife/embeds.iife.js.map +1 -1
  18. package/dist/iife/player-embed/embed.iife.js +3940 -0
  19. package/dist/iife/player-embed/embed.iife.js.map +1 -0
  20. package/package.json +49 -35
  21. package/src/components/DialogEmbed/Dialog.stories.ts +91 -0
  22. package/src/components/DialogEmbed/DialogOverlay.ts +131 -0
  23. package/src/components/DialogEmbed/DialogPortal.ts +126 -0
  24. package/src/components/DialogEmbed/index.ts +97 -0
  25. package/src/components/PlayerEmbed/MultiEmbed.stories.ts +135 -0
  26. package/src/components/{Embed/Embed.stories.ts → PlayerEmbed/PlayerEmbed.stories.ts} +30 -16
  27. package/src/components/{Embed → PlayerEmbed}/controllers/event-forwarder.ts +6 -5
  28. package/src/components/{Embed → PlayerEmbed}/controllers/fetcher.ts +11 -11
  29. package/src/components/{Embed/controllers/tracking.ts → PlayerEmbed/controllers/tracking/index.ts} +53 -123
  30. package/src/components/PlayerEmbed/controllers/tracking/utils.ts +95 -0
  31. package/src/components/{Embed → PlayerEmbed}/index.ts +84 -39
  32. package/src/components/PlayerEmbed/tests/PlayerEmbed.spec.ts +87 -0
  33. package/src/components/PlayerEmbed/tests/data.ts +227 -0
  34. package/src/components/PlayerEmbed/tests/media-data.ts +22 -0
  35. package/src/index.ts +2 -1
  36. package/dist/es/browser-f5bec026.js +0 -433
  37. package/dist/es/browser-f5bec026.js.map +0 -1
  38. package/dist/es/index-6ce8276f.js +0 -9947
  39. package/dist/es/index-6ce8276f.js.map +0 -1
  40. package/dist/es/src/components/Embed/index.d.ts +0 -70
package/dist/es/embeds.js CHANGED
@@ -1,11 +1,1040 @@
1
- import { E as a } from "./index-6ce8276f.js";
2
- import "lit/decorators.js";
3
- import "lit/directives/if-defined.js";
4
- import "lit/directives/ref.js";
5
- import "@lit/task";
6
- import "uuid";
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";
7
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.f27fcf4";
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
+ vouchId,
291
+ time: (/* @__PURE__ */ new Date()).toISOString()
292
+ }
293
+ });
294
+ };
295
+ this._sendTrackingEvent = () => {
296
+ if (this._batchedEvents.length <= 0) {
297
+ return;
298
+ }
299
+ const { publicApiUrl } = getEnvUrls(this.host.env);
300
+ const { client, tab, request, visitor } = getUids(this.host.env);
301
+ navigator.sendBeacon(
302
+ `${publicApiUrl}/api/batchevents`,
303
+ JSON.stringify({
304
+ payload: {
305
+ events: this._batchedEvents
306
+ },
307
+ context: {
308
+ "x-uid-client": client,
309
+ "x-uid-tab": tab,
310
+ "x-uid-request": request,
311
+ "x-uid-visitor": visitor,
312
+ "x-reporting-metadata": getReportingMetadata(this.host.trackingSource)
313
+ }
314
+ })
315
+ );
316
+ this._batchedEvents = [];
317
+ };
318
+ this._streamEnded = () => {
319
+ if (this._currentlyPlayingVideo) {
320
+ const { id, key } = this._currentlyPlayingVideo;
321
+ if (this._streamLatestTime[key] > this._streamStartTime[key] + MINIMUM_SEND_THRESHOLD) {
322
+ this._createTrackingEvent("VIDEO_STREAMED", {
323
+ answerId: id,
324
+ streamStart: this._streamStartTime[key],
325
+ streamEnd: this._streamLatestTime[key]
326
+ });
327
+ }
328
+ delete this._streamStartTime[key];
329
+ delete this._streamLatestTime[key];
330
+ }
331
+ };
332
+ this._handleVouchLoaded = ({ detail: vouchId }) => {
333
+ if (!vouchId) {
334
+ return;
335
+ }
336
+ if (!this._hasLoaded[vouchId]) {
337
+ this._createTrackingEvent("VOUCH_LOADED", { vouchId });
338
+ this._hasLoaded[vouchId] = true;
339
+ }
340
+ };
341
+ this._handlePlay = () => {
342
+ if (!this._hasPlayed) {
343
+ this._createTrackingEvent("VIDEO_PLAYED", {
344
+ streamStart: this.host.currentTime
345
+ });
346
+ this._hasPlayed = true;
347
+ }
348
+ };
349
+ this._handleVideoPlay = ({ detail: { id, key } }) => {
350
+ if (!this._answersViewed[key]) {
351
+ this._createTrackingEvent("VOUCH_RESPONSE_VIEWED", {
352
+ answerId: id
353
+ });
354
+ this._answersViewed[key] = true;
355
+ }
356
+ };
357
+ this._handleVideoTimeUpdate = ({ detail: { id, key, node } }) => {
358
+ if (
359
+ // We only want to count any time that the video is actually playing
360
+ !this.host.paused
361
+ ) {
362
+ this._currentlyPlayingVideo = { id, key, node };
363
+ this._streamLatestTime[key] = node.currentTime;
364
+ if (!this._streamStartTime[key]) {
365
+ this._streamStartTime[key] = node.currentTime;
366
+ this._streamLatestTime[key] = node.currentTime;
367
+ }
368
+ }
369
+ };
370
+ this._handleVideoPause = ({ detail: { id, key } }) => {
371
+ if (this._streamLatestTime[key] > this._streamStartTime[key] + MINIMUM_SEND_THRESHOLD) {
372
+ this._createTrackingEvent("VIDEO_STREAMED", {
373
+ answerId: id,
374
+ streamStart: this._streamStartTime[key],
375
+ streamEnd: this._streamLatestTime[key]
376
+ });
377
+ }
378
+ delete this._streamStartTime[key];
379
+ delete this._streamLatestTime[key];
380
+ };
381
+ this._pageUnloading = () => {
382
+ this._streamEnded();
383
+ this._sendTrackingEvent();
384
+ };
385
+ this._handleVisibilityChange = () => {
386
+ if (document.visibilityState === "hidden") {
387
+ this._pageUnloading();
388
+ }
389
+ };
390
+ this._handlePageHide = () => {
391
+ this._pageUnloading();
392
+ };
393
+ this.host = host;
394
+ host.addController(this);
395
+ }
396
+ hostConnected() {
397
+ requestAnimationFrame(() => {
398
+ var _a, _b, _c, _d;
399
+ if ("onvisibilitychange" in document) {
400
+ document.addEventListener("visibilitychange", this._handleVisibilityChange);
401
+ } else {
402
+ window.addEventListener("pagehide", this._handlePageHide);
403
+ }
404
+ this.host.addEventListener("vouch:loaded", this._handleVouchLoaded);
405
+ (_a = this.host.mediaPlayer) == null ? void 0 : _a.addEventListener("play", this._handlePlay);
406
+ (_b = this.host.mediaPlayer) == null ? void 0 : _b.addEventListener("video:play", this._handleVideoPlay);
407
+ (_c = this.host.mediaPlayer) == null ? void 0 : _c.addEventListener("video:pause", this._handleVideoPause);
408
+ (_d = this.host.mediaPlayer) == null ? void 0 : _d.addEventListener("video:timeupdate", this._handleVideoTimeUpdate);
409
+ });
410
+ }
411
+ hostDisconnected() {
412
+ var _a, _b, _c, _d;
413
+ this._pageUnloading();
414
+ if ("onvisibilitychange" in document) {
415
+ document.removeEventListener("visibilitychange", this._handleVisibilityChange);
416
+ } else {
417
+ window.removeEventListener("pagehide", this._handlePageHide);
418
+ }
419
+ this.host.removeEventListener("vouch:loaded", this._handleVouchLoaded);
420
+ (_a = this.host.mediaPlayer) == null ? void 0 : _a.removeEventListener("play", this._handlePlay);
421
+ (_b = this.host.mediaPlayer) == null ? void 0 : _b.removeEventListener("video:play", this._handleVideoPlay);
422
+ (_c = this.host.mediaPlayer) == null ? void 0 : _c.removeEventListener("video:pause", this._handleVideoPause);
423
+ (_d = this.host.mediaPlayer) == null ? void 0 : _d.removeEventListener("video:timeupdate", this._handleVideoTimeUpdate);
424
+ }
425
+ }
426
+ var __defProp$3 = Object.defineProperty;
427
+ var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
428
+ var __decorateClass$3 = (decorators, target, key, kind) => {
429
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
430
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
431
+ if (decorator = decorators[i])
432
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
433
+ if (kind && result) __defProp$3(target, key, result);
434
+ return result;
435
+ };
436
+ let PlayerEmbed = class extends LitElement {
437
+ constructor() {
438
+ super(...arguments);
439
+ this.env = "prod";
440
+ this.apiKey = "";
441
+ this.disableTracking = false;
442
+ this.trackingSource = "embedded_player";
443
+ this.preload = "auto";
444
+ this.autoplay = false;
445
+ this.aspectRatio = 0;
446
+ this.eventController = new EventForwardController(this, [
447
+ "durationchange",
448
+ "ended",
449
+ "error",
450
+ "loadeddata",
451
+ "pause",
452
+ "stalled",
453
+ "play",
454
+ "playing",
455
+ "ratechange",
456
+ "scenechange",
457
+ "scenesupdate",
458
+ "seeking",
459
+ "seeked",
460
+ "timeupdate",
461
+ "volumechange",
462
+ "processing",
463
+ "waiting",
464
+ "video:loadeddata",
465
+ "video:seeking",
466
+ "video:seeked",
467
+ "video:play",
468
+ "video:playing",
469
+ "video:pause",
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
+ state()
668
+ ], PlayerEmbed.prototype, "vouch", 2);
669
+ __decorateClass$3([
670
+ state()
671
+ ], PlayerEmbed.prototype, "template", 2);
672
+ PlayerEmbed = __decorateClass$3([
673
+ customElement("vouch-embed-player")
674
+ ], PlayerEmbed);
675
+ var __defProp$2 = Object.defineProperty;
676
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
677
+ var __decorateClass$2 = (decorators, target, key, kind) => {
678
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
679
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
680
+ if (decorator = decorators[i])
681
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
682
+ if (kind && result) __defProp$2(target, key, result);
683
+ return result;
684
+ };
685
+ let DialogOverlay = class extends LitElement {
686
+ constructor() {
687
+ super(...arguments);
688
+ this.open = false;
689
+ this.aspectRatio = 0;
690
+ }
691
+ render() {
692
+ return html`
693
+ <div
694
+ class=${classMap({
695
+ container: true,
696
+ hidden: !this.open
697
+ })}
698
+ >
699
+ <div
700
+ class="background"
701
+ @click=${() => this.dispatchEvent(new CustomEvent("overlay:click", { bubbles: true, composed: true }))}
702
+ ></div>
703
+ <focus-trap>
704
+ <div
705
+ class=${classMap({
706
+ "video-frame": true,
707
+ grow: this.aspectRatio === 0
708
+ })}
709
+ style=${styleMap({
710
+ aspectRatio: this.aspectRatio
711
+ })}
712
+ >
713
+ <slot></slot>
714
+ <vmp-icon-button
715
+ icon="close"
716
+ rounded="full"
717
+ weight="heavy"
718
+ @click=${() => this.dispatchEvent(new CustomEvent("close:click", { bubbles: true, composed: true }))}
719
+ ></vmp-icon-button>
720
+ </div>
721
+ </focus-trap>
722
+ </div>
723
+ `;
724
+ }
725
+ };
726
+ DialogOverlay.styles = [
727
+ css`
728
+ :host {
729
+ --vouch-media-player-border-radius: var(--vu-media-player-border-radius, 12px);
730
+ --overlay-background-color: var(--vu-overlay-background-color, black);
731
+ --overlay-background-opacity: var(--vu-overlay-background-opacity, 0.4);
732
+
733
+ --dialog-width: var(--vu-dialog-width, 890px);
734
+ --dialog-height: var(--vu-dialog-height, 500px);
735
+ }
736
+
737
+ .container {
738
+ position: fixed;
739
+ display: flex;
740
+ inset: 0;
741
+ opacity: 1;
742
+ z-index: 2147483647;
743
+ align-items: center;
744
+ justify-content: center;
745
+ transition: opacity 100ms ease-in;
746
+ }
747
+
748
+ .hidden {
749
+ opacity: 0;
750
+ pointer-events: none;
751
+ }
752
+
753
+ .background {
754
+ position: absolute;
755
+ inset: 0;
756
+ opacity: var(--overlay-background-opacity);
757
+ background-color: var(--overlay-background-color);
758
+ }
759
+
760
+ focus-trap {
761
+ display: flex;
762
+ align-items: center;
763
+ justify-content: center;
764
+ margin: 40px;
765
+ width: var(--dialog-width);
766
+ height: var(--dialog-height);
767
+ max-width: calc(100% - 80px);
768
+ max-height: calc(100% - 80px);
769
+ }
770
+
771
+ .video-frame {
772
+ position: relative;
773
+ display: flex;
774
+ align-items: center;
775
+ justify-content: center;
776
+ max-width: 100%;
777
+ max-height: 100%;
778
+ }
779
+
780
+ .video-frame.grow {
781
+ width: 100%;
782
+ height: 100%;
783
+ }
784
+
785
+ vmp-icon-button {
786
+ position: absolute;
787
+ top: 0;
788
+ right: 0;
789
+ margin: 10px;
790
+ }
791
+ `
792
+ ];
793
+ __decorateClass$2([
794
+ property({ type: Boolean })
795
+ ], DialogOverlay.prototype, "open", 2);
796
+ __decorateClass$2([
797
+ property({ type: Number })
798
+ ], DialogOverlay.prototype, "aspectRatio", 2);
799
+ DialogOverlay = __decorateClass$2([
800
+ customElement("vouch-embed-dialog-overlay")
801
+ ], DialogOverlay);
802
+ var __defProp$1 = Object.defineProperty;
803
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
804
+ var __decorateClass$1 = (decorators, target, key, kind) => {
805
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
806
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
807
+ if (decorator = decorators[i])
808
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
809
+ if (kind && result) __defProp$1(target, key, result);
810
+ return result;
811
+ };
812
+ let DialogPortal = class extends LitElement {
813
+ constructor() {
814
+ super(...arguments);
815
+ this.env = "prod";
816
+ this.apiKey = "";
817
+ this.disableTracking = false;
818
+ this.trackingSource = "embedded_player";
819
+ this.preload = "none";
820
+ this.disableAutoplay = false;
821
+ this.aspectRatio = 0;
822
+ this._mediaPlayerRef = createRef();
823
+ this.open = false;
824
+ this._handleToggle = ({ detail }) => {
825
+ var _a, _b, _c;
826
+ if (this.id === detail) {
827
+ this.open = !this.open;
828
+ if (this.open) {
829
+ if (!this.disableAutoplay && ((_a = this._mediaPlayerRef) == null ? void 0 : _a.value)) {
830
+ this._mediaPlayerRef.value.muted = false;
831
+ this._mediaPlayerRef.value.play();
832
+ }
833
+ } else {
834
+ (_c = (_b = this._mediaPlayerRef) == null ? void 0 : _b.value) == null ? void 0 : _c.pause();
835
+ }
836
+ }
837
+ };
838
+ this._handleClose = () => {
839
+ var _a, _b;
840
+ this.open = false;
841
+ (_b = (_a = this._mediaPlayerRef) == null ? void 0 : _a.value) == null ? void 0 : _b.pause();
842
+ };
843
+ this._handleDocumentKeyUp = (e) => {
844
+ if (e.key === "Escape") {
845
+ this._handleClose();
846
+ }
847
+ };
848
+ }
849
+ connectedCallback() {
850
+ super.connectedCallback();
851
+ document.addEventListener("dialogembed:click", this._handleToggle);
852
+ document.addEventListener("keyup", this._handleDocumentKeyUp);
853
+ document.addEventListener("close:click", this._handleClose);
854
+ document.addEventListener("overlay:click", this._handleClose);
855
+ }
856
+ disconnectedCallback() {
857
+ super.disconnectedCallback();
858
+ document.removeEventListener("dialogembed:click", this._handleToggle);
859
+ document.removeEventListener("keyup", this._handleDocumentKeyUp);
860
+ document.removeEventListener("close:click", this._handleClose);
861
+ document.removeEventListener("overlay:click", this._handleClose);
862
+ }
863
+ createRenderRoot() {
864
+ const newNode = document.createElement("div");
865
+ document.body.appendChild(newNode);
866
+ return newNode;
867
+ }
868
+ render() {
869
+ return html`
870
+ <vouch-embed-dialog-overlay ?open=${this.open} aspectRatio=${this.aspectRatio}>
871
+ <vouch-embed-player
872
+ ${ref(this._mediaPlayerRef)}
873
+ style=${styleMap({
874
+ maxWidth: "100%",
875
+ maxHeight: "100%"
876
+ })}
877
+ ?autoplay=${false}
878
+ vouchId=${ifDefined(this.vouchId)}
879
+ templateId=${ifDefined(this.templateId)}
880
+ .questions=${this.questions}
881
+ .controls=${this.controls}
882
+ env=${ifDefined(this.env)}
883
+ apiKey=${ifDefined(this.apiKey)}
884
+ ?disableTracking=${this.disableTracking}
885
+ trackingSource=${ifDefined(this.trackingSource)}
886
+ preload=${ifDefined(this.preload)}
887
+ aspectRatio=${this.aspectRatio}
888
+ ></vouch-embed-player>
889
+ </vouch-embed-dialog-overlay>
890
+ `;
891
+ }
892
+ };
893
+ __decorateClass$1([
894
+ property({ type: String })
895
+ ], DialogPortal.prototype, "vouchId", 2);
896
+ __decorateClass$1([
897
+ property({ type: String })
898
+ ], DialogPortal.prototype, "templateId", 2);
899
+ __decorateClass$1([
900
+ property({ type: Array })
901
+ ], DialogPortal.prototype, "questions", 2);
902
+ __decorateClass$1([
903
+ property({ type: String })
904
+ ], DialogPortal.prototype, "env", 2);
905
+ __decorateClass$1([
906
+ property({ type: String })
907
+ ], DialogPortal.prototype, "apiKey", 2);
908
+ __decorateClass$1([
909
+ property({ type: Boolean })
910
+ ], DialogPortal.prototype, "disableTracking", 2);
911
+ __decorateClass$1([
912
+ property({ type: String })
913
+ ], DialogPortal.prototype, "trackingSource", 2);
914
+ __decorateClass$1([
915
+ property({ type: Array })
916
+ ], DialogPortal.prototype, "controls", 2);
917
+ __decorateClass$1([
918
+ property({ type: String })
919
+ ], DialogPortal.prototype, "preload", 2);
920
+ __decorateClass$1([
921
+ property({ type: Boolean })
922
+ ], DialogPortal.prototype, "disableAutoplay", 2);
923
+ __decorateClass$1([
924
+ property({ type: Number })
925
+ ], DialogPortal.prototype, "aspectRatio", 2);
926
+ __decorateClass$1([
927
+ state()
928
+ ], DialogPortal.prototype, "open", 2);
929
+ DialogPortal = __decorateClass$1([
930
+ customElement("vouch-embed-dialog-portal")
931
+ ], DialogPortal);
932
+ var __defProp = Object.defineProperty;
933
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
934
+ var __decorateClass = (decorators, target, key, kind) => {
935
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
936
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
937
+ if (decorator = decorators[i])
938
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
939
+ if (kind && result) __defProp(target, key, result);
940
+ return result;
941
+ };
942
+ let DialogEmbed = class extends LitElement {
943
+ constructor() {
944
+ super(...arguments);
945
+ this.env = "prod";
946
+ this.apiKey = "";
947
+ this.disableTracking = false;
948
+ this.trackingSource = "embedded_player";
949
+ this.preload = "none";
950
+ this.disableAutoplay = false;
951
+ this.aspectRatio = 0;
952
+ this._id = v4();
953
+ this._handleRootClick = () => {
954
+ this.dispatchEvent(new CustomEvent("dialogembed:click", { detail: this._id, bubbles: true, composed: true }));
955
+ };
956
+ }
957
+ connectedCallback() {
958
+ super.connectedCallback();
959
+ this.addEventListener("click", this._handleRootClick);
960
+ }
961
+ disconnectedCallback() {
962
+ super.disconnectedCallback();
963
+ this.removeEventListener("click", this._handleRootClick);
964
+ }
965
+ render() {
966
+ return html`
967
+ <slot>
968
+ <vmp-button size="large">Play</vmp-button>
969
+ </slot>
970
+ <vouch-embed-dialog-portal
971
+ id=${this._id}
972
+ ?autoplay=${false}
973
+ vouchId=${ifDefined(this.vouchId)}
974
+ templateId=${ifDefined(this.templateId)}
975
+ .questions=${this.questions}
976
+ .controls=${this.controls}
977
+ env=${ifDefined(this.env)}
978
+ apiKey=${ifDefined(this.apiKey)}
979
+ ?disableTracking=${this.disableTracking}
980
+ trackingSource=${ifDefined(this.trackingSource)}
981
+ preload=${ifDefined(this.preload)}
982
+ aspectRatio=${this.aspectRatio}
983
+ ></vouch-embed-dialog-portal>
984
+ `;
985
+ }
986
+ };
987
+ DialogEmbed.styles = [
988
+ css`
989
+ :host {
990
+ --vu-button-padding: 10px 20px;
991
+ --vu-button-background: #287179;
992
+ --vu-button-background-hover: #4faab2;
993
+
994
+ display: flex;
995
+ width: fit-content;
996
+ height: fit-content;
997
+ }
998
+ `
999
+ ];
1000
+ __decorateClass([
1001
+ property({ type: String })
1002
+ ], DialogEmbed.prototype, "vouchId", 2);
1003
+ __decorateClass([
1004
+ property({ type: String })
1005
+ ], DialogEmbed.prototype, "templateId", 2);
1006
+ __decorateClass([
1007
+ property({ type: Array })
1008
+ ], DialogEmbed.prototype, "questions", 2);
1009
+ __decorateClass([
1010
+ property({ type: String })
1011
+ ], DialogEmbed.prototype, "env", 2);
1012
+ __decorateClass([
1013
+ property({ type: String })
1014
+ ], DialogEmbed.prototype, "apiKey", 2);
1015
+ __decorateClass([
1016
+ property({ type: Boolean })
1017
+ ], DialogEmbed.prototype, "disableTracking", 2);
1018
+ __decorateClass([
1019
+ property({ type: String })
1020
+ ], DialogEmbed.prototype, "trackingSource", 2);
1021
+ __decorateClass([
1022
+ property({ type: Array })
1023
+ ], DialogEmbed.prototype, "controls", 2);
1024
+ __decorateClass([
1025
+ property({ type: String })
1026
+ ], DialogEmbed.prototype, "preload", 2);
1027
+ __decorateClass([
1028
+ property({ type: Boolean })
1029
+ ], DialogEmbed.prototype, "disableAutoplay", 2);
1030
+ __decorateClass([
1031
+ property({ type: Number })
1032
+ ], DialogEmbed.prototype, "aspectRatio", 2);
1033
+ DialogEmbed = __decorateClass([
1034
+ customElement("vouch-embed-dialog")
1035
+ ], DialogEmbed);
8
1036
  export {
9
- a as Embed
1037
+ DialogEmbed,
1038
+ PlayerEmbed
10
1039
  };
11
1040
  //# sourceMappingURL=embeds.js.map