@vouchfor/embeds 0.0.0-experiment.1f98c5e → 0.0.0-experiment.20e29ac
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/es/embeds.js +1151 -7
- package/dist/es/embeds.js.map +1 -1
- package/dist/es/src/components/DialogEmbed/DialogOverlay.d.ts +20 -0
- package/dist/es/src/components/DialogEmbed/DialogPortal.d.ts +36 -0
- package/dist/es/src/components/DialogEmbed/index.d.ts +38 -0
- package/dist/es/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
- package/dist/es/src/components/{Embed → PlayerEmbed}/controllers/fetcher.d.ts +4 -4
- package/dist/es/src/components/{Embed/controllers/tracking.d.ts → PlayerEmbed/controllers/tracking/index.d.ts} +14 -11
- package/dist/es/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
- package/dist/es/src/components/{Embed → PlayerEmbed}/index.d.ts +29 -22
- package/dist/es/src/components/PlayerEmbed/tests/data.d.ts +4 -0
- package/dist/es/src/components/PlayerEmbed/tests/media-data.d.ts +19 -0
- package/dist/es/src/index.d.ts +2 -1
- package/dist/iife/dialog-embed/embed.iife.js +1757 -0
- package/dist/iife/dialog-embed/embed.iife.js.map +1 -0
- package/dist/iife/embeds.iife.js +580 -381
- package/dist/iife/embeds.iife.js.map +1 -1
- package/dist/iife/player-embed/embed.iife.js +1619 -0
- package/dist/iife/player-embed/embed.iife.js.map +1 -0
- package/package.json +43 -32
- package/src/components/DialogEmbed/Dialog.stories.ts +91 -0
- package/src/components/DialogEmbed/DialogOverlay.ts +131 -0
- package/src/components/DialogEmbed/DialogPortal.ts +126 -0
- package/src/components/DialogEmbed/index.ts +97 -0
- package/src/components/PlayerEmbed/MultiEmbed.stories.ts +135 -0
- package/src/components/{Embed/Embed.stories.ts → PlayerEmbed/PlayerEmbed.stories.ts} +30 -16
- package/src/components/{Embed → PlayerEmbed}/controllers/event-forwarder.ts +6 -5
- package/src/components/{Embed → PlayerEmbed}/controllers/fetcher.ts +11 -11
- package/src/components/{Embed/controllers/tracking.ts → PlayerEmbed/controllers/tracking/index.ts} +47 -118
- package/src/components/PlayerEmbed/controllers/tracking/utils.ts +95 -0
- package/src/components/{Embed → PlayerEmbed}/index.ts +71 -23
- package/src/components/PlayerEmbed/tests/PlayerEmbed.spec.ts +87 -0
- package/src/components/PlayerEmbed/tests/data.ts +227 -0
- package/src/components/PlayerEmbed/tests/media-data.ts +22 -0
- package/src/index.ts +2 -1
- package/dist/es/browser-95c87c48.js +0 -433
- package/dist/es/browser-95c87c48.js.map +0 -1
- package/dist/es/index-9dd8a4fa.js +0 -9950
- package/dist/es/index-9dd8a4fa.js.map +0 -1
- package/src/components/Embed/Embed.spec.ts +0 -17
package/dist/es/embeds.js
CHANGED
@@ -1,11 +1,1155 @@
|
|
1
|
-
import {
|
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(type2, fromElement, toElement) {
|
13
|
+
function forwarder(event) {
|
14
|
+
toElement.dispatchEvent(new CustomEvent(event.type, event));
|
15
|
+
}
|
16
|
+
fromElement.addEventListener(type2, forwarder);
|
17
|
+
return () => {
|
18
|
+
fromElement.removeEventListener(type2, 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 name = "@vouchfor/embeds";
|
199
|
+
const version = "0.0.0-experiment.20e29ac";
|
200
|
+
const license = "MIT";
|
201
|
+
const author = "Aaron Williams";
|
202
|
+
const main = "dist/es/embeds.js";
|
203
|
+
const module = "dist/es/embeds.js";
|
204
|
+
const type = "module";
|
205
|
+
const types = "dist/es/src/index.d.ts";
|
206
|
+
const exports = {
|
207
|
+
".": "./dist/es/embeds.js"
|
208
|
+
};
|
209
|
+
const files = [
|
210
|
+
"dist",
|
211
|
+
"src"
|
212
|
+
];
|
213
|
+
const publishConfig = {
|
214
|
+
tag: "experiment",
|
215
|
+
access: "public"
|
216
|
+
};
|
217
|
+
const engines = {
|
218
|
+
node: ">=18.18.0"
|
219
|
+
};
|
220
|
+
const scripts = {
|
221
|
+
build: "rm -rf dist && tsc && yarn build:self",
|
222
|
+
"build:deps": "yarn --cwd ../media-player build",
|
223
|
+
"build:self": "vite build --mode iife && vite build --mode es && node scripts/build.cjs",
|
224
|
+
"build:package": "yarn build",
|
225
|
+
"build:storybook": "yarn prebuild && storybook build",
|
226
|
+
"generate:manifest": "wca src --outFile custom-elements.json",
|
227
|
+
lint: "eslint . --quiet",
|
228
|
+
"lint:fix": "eslint . --fix",
|
229
|
+
"lint:staged": "lint-staged",
|
230
|
+
prepublishOnly: "yarn build",
|
231
|
+
size: "size-limit",
|
232
|
+
storybook: "yarn prebuild && storybook dev -p 6007",
|
233
|
+
prebuild: "yarn build:deps && yarn generate:manifest",
|
234
|
+
test: "rm -rf test/lib && yarn prebuild && vite build --mode test && web-test-runner",
|
235
|
+
"test:ci": "yarn test --config web-test-runner.ci.config.js",
|
236
|
+
"test:watch": "yarn test --watch"
|
237
|
+
};
|
238
|
+
const dependencies = {
|
239
|
+
"@a11y/focus-trap": "^1.0.5",
|
240
|
+
"@lit/task": "^1.0.0",
|
241
|
+
"@vouchfor/canvas-video": "0.0.0-experiment.20e29ac",
|
242
|
+
"@vouchfor/media-player": "0.0.0-experiment.20e29ac",
|
243
|
+
uuid: "^9.0.1"
|
244
|
+
};
|
245
|
+
const peerDependencies = {
|
246
|
+
lit: "^3.1.2"
|
247
|
+
};
|
248
|
+
const devDependencies = {
|
249
|
+
"@esm-bundle/chai": "^4.3.4-fix.0",
|
250
|
+
"@open-wc/testing": "^4.0.0",
|
251
|
+
"@storybook/addon-essentials": "^8.0.4",
|
252
|
+
"@storybook/addon-links": "^8.0.4",
|
253
|
+
"@storybook/blocks": "^8.0.4",
|
254
|
+
"@storybook/web-components": "^8.0.4",
|
255
|
+
"@storybook/web-components-vite": "^8.0.4",
|
256
|
+
"@svgr/core": "^8.1.0",
|
257
|
+
"@types/flat": "^5.0.5",
|
258
|
+
"@types/mocha": "^10.0.6",
|
259
|
+
"@vouchfor/eslint-config": "^1.0.1",
|
260
|
+
"@vouchfor/prettier-config": "^1.0.1",
|
261
|
+
"@vouchfor/video-utils": "0.0.0-experiment.20e29ac",
|
262
|
+
"@web/dev-server-esbuild": "^1.0.2",
|
263
|
+
"@web/test-runner": "^0.18.1",
|
264
|
+
"@web/test-runner-browserstack": "^0.7.1",
|
265
|
+
"@web/test-runner-mocha": "^0.9.0",
|
266
|
+
"@web/test-runner-playwright": "^0.11.0",
|
267
|
+
glob: "^10.3.10",
|
268
|
+
"lint-staged": "^15.2.2",
|
269
|
+
lit: "^3.1.2",
|
270
|
+
lodash: "^4.17.21",
|
271
|
+
react: "^18.2.0",
|
272
|
+
"react-dom": "^18.2.0",
|
273
|
+
"rollup-plugin-tla": "^0.0.2",
|
274
|
+
sinon: "^17.0.1",
|
275
|
+
storybook: "^8.0.4",
|
276
|
+
svgson: "^5.3.1",
|
277
|
+
typescript: "^5.4.3",
|
278
|
+
vite: "^5.2.2",
|
279
|
+
"vite-plugin-commonjs": "^0.10.1",
|
280
|
+
"vite-plugin-dts": "^3.7.3",
|
281
|
+
"web-component-analyzer": "^2.0.0"
|
282
|
+
};
|
283
|
+
const packageJson = {
|
284
|
+
name,
|
285
|
+
version,
|
286
|
+
license,
|
287
|
+
author,
|
288
|
+
main,
|
289
|
+
module,
|
290
|
+
type,
|
291
|
+
types,
|
292
|
+
exports,
|
293
|
+
files,
|
294
|
+
publishConfig,
|
295
|
+
engines,
|
296
|
+
scripts,
|
297
|
+
"lint-staged": {
|
298
|
+
"**/*.{ts,tsx,js}": "eslint --fix --quiet",
|
299
|
+
"**/*.{md,json,yml}": "prettier --write"
|
300
|
+
},
|
301
|
+
dependencies,
|
302
|
+
peerDependencies,
|
303
|
+
devDependencies
|
304
|
+
};
|
305
|
+
function createVisitor(env) {
|
306
|
+
const { publicApiUrl } = getEnvUrls(env);
|
307
|
+
const visitorId = v4();
|
308
|
+
navigator.sendBeacon(`${publicApiUrl}/api/visitor`, JSON.stringify({ visitorId }));
|
309
|
+
return visitorId;
|
310
|
+
}
|
311
|
+
function getUids(env) {
|
312
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
313
|
+
if (typeof window === "undefined") {
|
314
|
+
return {
|
315
|
+
client: null,
|
316
|
+
tab: null,
|
317
|
+
request: v4()
|
318
|
+
};
|
319
|
+
}
|
320
|
+
let visitorId = (_b = (_a = window.localStorage) == null ? void 0 : _a.getItem) == null ? void 0 : _b.call(_a, "vouch-uid-visitor");
|
321
|
+
let clientId = (_d = (_c = window.localStorage) == null ? void 0 : _c.getItem) == null ? void 0 : _d.call(_c, "vouch-uid-client");
|
322
|
+
let tabId = (_f = (_e = window.sessionStorage) == null ? void 0 : _e.getItem) == null ? void 0 : _f.call(_e, "vouch-uid-tab");
|
323
|
+
const requestId = v4();
|
324
|
+
if (!visitorId) {
|
325
|
+
visitorId = createVisitor(env);
|
326
|
+
(_h = (_g = window.localStorage) == null ? void 0 : _g.setItem) == null ? void 0 : _h.call(_g, "vouch-uid-visitor", visitorId);
|
327
|
+
}
|
328
|
+
if (!clientId) {
|
329
|
+
clientId = v4();
|
330
|
+
(_j = (_i = window.localStorage) == null ? void 0 : _i.setItem) == null ? void 0 : _j.call(_i, "vouch-uid-client", clientId);
|
331
|
+
}
|
332
|
+
if (!tabId) {
|
333
|
+
tabId = v4();
|
334
|
+
(_l = (_k = window.sessionStorage) == null ? void 0 : _k.setItem) == null ? void 0 : _l.call(_k, "vouch-uid-tab", tabId);
|
335
|
+
}
|
336
|
+
return {
|
337
|
+
client: clientId,
|
338
|
+
tab: tabId,
|
339
|
+
request: requestId,
|
340
|
+
visitor: visitorId
|
341
|
+
};
|
342
|
+
}
|
343
|
+
function findVouchId(payload, vouch) {
|
344
|
+
if (payload && "vouchId" in payload) {
|
345
|
+
return payload.vouchId;
|
346
|
+
}
|
347
|
+
return (vouch == null ? void 0 : vouch.id) ?? null;
|
348
|
+
}
|
349
|
+
function getReportingMetadata(source = "embedded_player") {
|
350
|
+
var _a, _b;
|
351
|
+
const [country, region] = ((_b = (_a = Intl.DateTimeFormat().resolvedOptions().timeZone) == null ? void 0 : _a.split) == null ? void 0 : _b.call(_a, "/")) ?? [];
|
352
|
+
const utmParams = {};
|
353
|
+
[...new URLSearchParams(location.search).entries()].forEach(([key, value]) => {
|
354
|
+
if (/utm/.test(key)) {
|
355
|
+
const param = key.toLowerCase().replace(/[-_][a-z0-9]/g, (group) => group.slice(-1).toUpperCase());
|
356
|
+
utmParams[param] = value;
|
357
|
+
}
|
358
|
+
});
|
359
|
+
return {
|
360
|
+
source,
|
361
|
+
time: /* @__PURE__ */ new Date(),
|
362
|
+
region,
|
363
|
+
country,
|
364
|
+
screenHeight: window.screen.height,
|
365
|
+
screenWidth: window.screen.width,
|
366
|
+
referrer: document.referrer,
|
367
|
+
currentUrl: location.href,
|
368
|
+
embedType: "media-player-embed",
|
369
|
+
embedVersion: packageJson.version,
|
370
|
+
templateVersion: TEMPLATE_VERSION,
|
371
|
+
...utmParams
|
372
|
+
};
|
373
|
+
}
|
374
|
+
const MINIMUM_SEND_THRESHOLD = 1;
|
375
|
+
class TrackingController {
|
376
|
+
constructor(host) {
|
377
|
+
this._batchedEvents = [];
|
378
|
+
this._hasPlayed = false;
|
379
|
+
this._hasLoaded = {};
|
380
|
+
this._answersViewed = {};
|
381
|
+
this._streamStartTime = {};
|
382
|
+
this._streamLatestTime = {};
|
383
|
+
this._currentlyPlayingVideo = null;
|
384
|
+
this._createTrackingEvent = (event, payload) => {
|
385
|
+
const vouchId = findVouchId(payload, this.host.vouch);
|
386
|
+
if (!vouchId || this.host.disableTracking) {
|
387
|
+
return;
|
388
|
+
}
|
389
|
+
this._batchedEvents.push({
|
390
|
+
event,
|
391
|
+
payload: {
|
392
|
+
...payload,
|
393
|
+
vouchId,
|
394
|
+
time: (/* @__PURE__ */ new Date()).toISOString()
|
395
|
+
}
|
396
|
+
});
|
397
|
+
};
|
398
|
+
this._sendTrackingEvent = () => {
|
399
|
+
if (this._batchedEvents.length <= 0) {
|
400
|
+
return;
|
401
|
+
}
|
402
|
+
const { publicApiUrl } = getEnvUrls(this.host.env);
|
403
|
+
const { client, tab, request, visitor } = getUids(this.host.env);
|
404
|
+
navigator.sendBeacon(
|
405
|
+
`${publicApiUrl}/api/batchevents`,
|
406
|
+
JSON.stringify({
|
407
|
+
payload: {
|
408
|
+
events: this._batchedEvents
|
409
|
+
},
|
410
|
+
context: {
|
411
|
+
"x-uid-client": client,
|
412
|
+
"x-uid-tab": tab,
|
413
|
+
"x-uid-request": request,
|
414
|
+
"x-uid-visitor": visitor,
|
415
|
+
"x-reporting-metadata": getReportingMetadata(this.host.trackingSource)
|
416
|
+
}
|
417
|
+
})
|
418
|
+
);
|
419
|
+
this._batchedEvents = [];
|
420
|
+
};
|
421
|
+
this._streamEnded = () => {
|
422
|
+
if (this._currentlyPlayingVideo) {
|
423
|
+
const { id, key } = this._currentlyPlayingVideo;
|
424
|
+
if (this._streamLatestTime[key] > this._streamStartTime[key] + MINIMUM_SEND_THRESHOLD) {
|
425
|
+
this._createTrackingEvent("VIDEO_STREAMED", {
|
426
|
+
answerId: id,
|
427
|
+
streamStart: this._streamStartTime[key],
|
428
|
+
streamEnd: this._streamLatestTime[key]
|
429
|
+
});
|
430
|
+
}
|
431
|
+
delete this._streamStartTime[key];
|
432
|
+
delete this._streamLatestTime[key];
|
433
|
+
}
|
434
|
+
};
|
435
|
+
this._handleVouchLoaded = ({ detail: vouchId }) => {
|
436
|
+
if (!vouchId) {
|
437
|
+
return;
|
438
|
+
}
|
439
|
+
if (!this._hasLoaded[vouchId]) {
|
440
|
+
this._createTrackingEvent("VOUCH_LOADED", { vouchId });
|
441
|
+
this._hasLoaded[vouchId] = true;
|
442
|
+
}
|
443
|
+
};
|
444
|
+
this._handlePlay = () => {
|
445
|
+
if (!this._hasPlayed) {
|
446
|
+
this._createTrackingEvent("VIDEO_PLAYED", {
|
447
|
+
streamStart: this.host.currentTime
|
448
|
+
});
|
449
|
+
this._hasPlayed = true;
|
450
|
+
}
|
451
|
+
};
|
452
|
+
this._handleVideoPlay = ({ detail: { id, key } }) => {
|
453
|
+
if (!this._answersViewed[key]) {
|
454
|
+
this._createTrackingEvent("VOUCH_RESPONSE_VIEWED", {
|
455
|
+
answerId: id
|
456
|
+
});
|
457
|
+
this._answersViewed[key] = true;
|
458
|
+
}
|
459
|
+
};
|
460
|
+
this._handleVideoTimeUpdate = ({ detail: { id, key, node } }) => {
|
461
|
+
var _a, _b;
|
462
|
+
if (
|
463
|
+
// We only want to count any time that the video is actually playing
|
464
|
+
!this.host.paused && // Only update the latest time if this event fires for the currently active video
|
465
|
+
id === ((_b = (_a = this.host.scene) == null ? void 0 : _a.video) == null ? void 0 : _b.id)
|
466
|
+
) {
|
467
|
+
this._currentlyPlayingVideo = { id, key, node };
|
468
|
+
this._streamLatestTime[key] = node.currentTime;
|
469
|
+
if (!this._streamStartTime[key]) {
|
470
|
+
this._streamStartTime[key] = node.currentTime;
|
471
|
+
this._streamLatestTime[key] = node.currentTime;
|
472
|
+
}
|
473
|
+
}
|
474
|
+
};
|
475
|
+
this._handleVideoPause = ({ detail: { id, key } }) => {
|
476
|
+
if (this._streamLatestTime[key] > this._streamStartTime[key] + MINIMUM_SEND_THRESHOLD) {
|
477
|
+
this._createTrackingEvent("VIDEO_STREAMED", {
|
478
|
+
answerId: id,
|
479
|
+
streamStart: this._streamStartTime[key],
|
480
|
+
streamEnd: this._streamLatestTime[key]
|
481
|
+
});
|
482
|
+
}
|
483
|
+
delete this._streamStartTime[key];
|
484
|
+
delete this._streamLatestTime[key];
|
485
|
+
};
|
486
|
+
this._pageUnloading = () => {
|
487
|
+
this._streamEnded();
|
488
|
+
this._sendTrackingEvent();
|
489
|
+
};
|
490
|
+
this._handleVisibilityChange = () => {
|
491
|
+
if (document.visibilityState === "hidden") {
|
492
|
+
this._pageUnloading();
|
493
|
+
}
|
494
|
+
};
|
495
|
+
this._handlePageHide = () => {
|
496
|
+
this._pageUnloading();
|
497
|
+
};
|
498
|
+
this.host = host;
|
499
|
+
host.addController(this);
|
500
|
+
}
|
501
|
+
hostConnected() {
|
502
|
+
requestAnimationFrame(() => {
|
503
|
+
var _a, _b, _c, _d;
|
504
|
+
if ("onvisibilitychange" in document) {
|
505
|
+
document.addEventListener("visibilitychange", this._handleVisibilityChange);
|
506
|
+
} else {
|
507
|
+
window.addEventListener("pagehide", this._handlePageHide);
|
508
|
+
}
|
509
|
+
this.host.addEventListener("vouch:loaded", this._handleVouchLoaded);
|
510
|
+
(_a = this.host.mediaPlayer) == null ? void 0 : _a.addEventListener("play", this._handlePlay);
|
511
|
+
(_b = this.host.mediaPlayer) == null ? void 0 : _b.addEventListener("video:play", this._handleVideoPlay);
|
512
|
+
(_c = this.host.mediaPlayer) == null ? void 0 : _c.addEventListener("video:pause", this._handleVideoPause);
|
513
|
+
(_d = this.host.mediaPlayer) == null ? void 0 : _d.addEventListener("video:timeupdate", this._handleVideoTimeUpdate);
|
514
|
+
});
|
515
|
+
}
|
516
|
+
hostDisconnected() {
|
517
|
+
var _a, _b, _c, _d;
|
518
|
+
this._pageUnloading();
|
519
|
+
if ("onvisibilitychange" in document) {
|
520
|
+
document.removeEventListener("visibilitychange", this._handleVisibilityChange);
|
521
|
+
} else {
|
522
|
+
window.removeEventListener("pagehide", this._handlePageHide);
|
523
|
+
}
|
524
|
+
this.host.removeEventListener("vouch:loaded", this._handleVouchLoaded);
|
525
|
+
(_a = this.host.mediaPlayer) == null ? void 0 : _a.removeEventListener("play", this._handlePlay);
|
526
|
+
(_b = this.host.mediaPlayer) == null ? void 0 : _b.removeEventListener("video:play", this._handleVideoPlay);
|
527
|
+
(_c = this.host.mediaPlayer) == null ? void 0 : _c.removeEventListener("video:pause", this._handleVideoPause);
|
528
|
+
(_d = this.host.mediaPlayer) == null ? void 0 : _d.removeEventListener("video:timeupdate", this._handleVideoTimeUpdate);
|
529
|
+
}
|
530
|
+
}
|
531
|
+
var __defProp$3 = Object.defineProperty;
|
532
|
+
var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
|
533
|
+
var __decorateClass$3 = (decorators, target, key, kind) => {
|
534
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
|
535
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
536
|
+
if (decorator = decorators[i])
|
537
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
538
|
+
if (kind && result)
|
539
|
+
__defProp$3(target, key, result);
|
540
|
+
return result;
|
541
|
+
};
|
542
|
+
let PlayerEmbed = class extends LitElement {
|
543
|
+
constructor() {
|
544
|
+
super(...arguments);
|
545
|
+
this.env = "prod";
|
546
|
+
this.apiKey = "";
|
547
|
+
this.disableTracking = false;
|
548
|
+
this.trackingSource = "embedded_player";
|
549
|
+
this.preload = "auto";
|
550
|
+
this.autoplay = false;
|
551
|
+
this.aspectRatio = 0;
|
552
|
+
this.eventController = new EventForwardController(this, [
|
553
|
+
"durationchange",
|
554
|
+
"ended",
|
555
|
+
"error",
|
556
|
+
"loadeddata",
|
557
|
+
"pause",
|
558
|
+
"stalled",
|
559
|
+
"play",
|
560
|
+
"playing",
|
561
|
+
"ratechange",
|
562
|
+
"scenechange",
|
563
|
+
"scenesupdate",
|
564
|
+
"seeking",
|
565
|
+
"seeked",
|
566
|
+
"timeupdate",
|
567
|
+
"volumechange",
|
568
|
+
"processing",
|
569
|
+
"waiting",
|
570
|
+
"video:loadeddata",
|
571
|
+
"video:seeking",
|
572
|
+
"video:seeked",
|
573
|
+
"video:play",
|
574
|
+
"video:playing",
|
575
|
+
"video:pause",
|
576
|
+
"video:stalled",
|
577
|
+
"video:timeupdate",
|
578
|
+
"video:ended",
|
579
|
+
"video:error"
|
580
|
+
]);
|
581
|
+
this._fetcherController = new FetcherController(this);
|
582
|
+
this._trackingController = new TrackingController(this);
|
583
|
+
this._mediaPlayerRef = createRef();
|
584
|
+
}
|
585
|
+
get fetching() {
|
586
|
+
return this._fetcherController.fetching;
|
587
|
+
}
|
588
|
+
get waiting() {
|
589
|
+
var _a;
|
590
|
+
return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.waiting;
|
591
|
+
}
|
592
|
+
get initialised() {
|
593
|
+
var _a;
|
594
|
+
return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.initialised;
|
595
|
+
}
|
596
|
+
get seeking() {
|
597
|
+
var _a;
|
598
|
+
return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.seeking;
|
599
|
+
}
|
600
|
+
get paused() {
|
601
|
+
var _a;
|
602
|
+
return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.paused;
|
603
|
+
}
|
604
|
+
get captions() {
|
605
|
+
var _a;
|
606
|
+
return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.captions;
|
607
|
+
}
|
608
|
+
get fullscreen() {
|
609
|
+
var _a;
|
610
|
+
return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.fullscreen;
|
611
|
+
}
|
612
|
+
get duration() {
|
613
|
+
var _a;
|
614
|
+
return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.duration;
|
615
|
+
}
|
616
|
+
set currentTime(value) {
|
617
|
+
if (this._mediaPlayerRef.value) {
|
618
|
+
this._mediaPlayerRef.value.currentTime = value;
|
619
|
+
}
|
620
|
+
}
|
621
|
+
get currentTime() {
|
622
|
+
var _a;
|
623
|
+
return ((_a = this._mediaPlayerRef.value) == null ? void 0 : _a.currentTime) ?? 0;
|
624
|
+
}
|
625
|
+
set playbackRate(value) {
|
626
|
+
if (this._mediaPlayerRef.value) {
|
627
|
+
this._mediaPlayerRef.value.playbackRate = value;
|
628
|
+
}
|
629
|
+
}
|
630
|
+
get playbackRate() {
|
631
|
+
var _a;
|
632
|
+
return ((_a = this._mediaPlayerRef.value) == null ? void 0 : _a.playbackRate) ?? 1;
|
633
|
+
}
|
634
|
+
set volume(value) {
|
635
|
+
if (this._mediaPlayerRef.value) {
|
636
|
+
this._mediaPlayerRef.value.volume = value;
|
637
|
+
}
|
638
|
+
}
|
639
|
+
get volume() {
|
640
|
+
var _a;
|
641
|
+
return ((_a = this._mediaPlayerRef.value) == null ? void 0 : _a.volume) ?? 1;
|
642
|
+
}
|
643
|
+
set muted(value) {
|
644
|
+
if (this._mediaPlayerRef.value) {
|
645
|
+
this._mediaPlayerRef.value.muted = value;
|
646
|
+
}
|
647
|
+
}
|
648
|
+
get muted() {
|
649
|
+
var _a;
|
650
|
+
return ((_a = this._mediaPlayerRef.value) == null ? void 0 : _a.muted) ?? false;
|
651
|
+
}
|
652
|
+
get scene() {
|
653
|
+
var _a;
|
654
|
+
return ((_a = this._mediaPlayerRef.value) == null ? void 0 : _a.scene) ?? null;
|
655
|
+
}
|
656
|
+
get scenes() {
|
657
|
+
var _a;
|
658
|
+
return ((_a = this._mediaPlayerRef.value) == null ? void 0 : _a.scenes) ?? [];
|
659
|
+
}
|
660
|
+
get sceneConfig() {
|
661
|
+
var _a;
|
662
|
+
return ((_a = this._mediaPlayerRef.value) == null ? void 0 : _a.sceneConfig) ?? null;
|
663
|
+
}
|
664
|
+
get videoState() {
|
665
|
+
var _a;
|
666
|
+
return (_a = this._mediaPlayerRef.value) == null ? void 0 : _a.videoState;
|
667
|
+
}
|
668
|
+
get mediaPlayer() {
|
669
|
+
return this._mediaPlayerRef.value;
|
670
|
+
}
|
671
|
+
play() {
|
672
|
+
var _a;
|
673
|
+
(_a = this._mediaPlayerRef.value) == null ? void 0 : _a.play();
|
674
|
+
}
|
675
|
+
pause() {
|
676
|
+
var _a;
|
677
|
+
(_a = this._mediaPlayerRef.value) == null ? void 0 : _a.pause();
|
678
|
+
}
|
679
|
+
reset(time = 0, play = false) {
|
680
|
+
var _a;
|
681
|
+
(_a = this._mediaPlayerRef.value) == null ? void 0 : _a.reset(time, play);
|
682
|
+
}
|
683
|
+
setScene(index) {
|
684
|
+
var _a;
|
685
|
+
(_a = this._mediaPlayerRef.value) == null ? void 0 : _a.setScene(index);
|
686
|
+
}
|
687
|
+
_renderStyles() {
|
688
|
+
if (!this.aspectRatio) {
|
689
|
+
return html`
|
690
|
+
<style>
|
691
|
+
:host {
|
692
|
+
width: 100%;
|
693
|
+
height: 100%;
|
694
|
+
}
|
695
|
+
</style>
|
696
|
+
`;
|
697
|
+
}
|
698
|
+
if (typeof this.aspectRatio === "number") {
|
699
|
+
return html`
|
700
|
+
<style>
|
701
|
+
:host {
|
702
|
+
aspect-ratio: ${this.aspectRatio};
|
703
|
+
}
|
704
|
+
</style>
|
705
|
+
`;
|
706
|
+
}
|
707
|
+
return null;
|
708
|
+
}
|
709
|
+
willUpdate(changedProperties) {
|
710
|
+
if (changedProperties.has("vouchId") && this.vouchId !== changedProperties.get("vouchId")) {
|
711
|
+
this.reset(0, false);
|
712
|
+
}
|
713
|
+
}
|
714
|
+
render() {
|
715
|
+
return html`
|
716
|
+
${this._renderStyles()}
|
717
|
+
<vmp-media-player
|
718
|
+
${ref(this._mediaPlayerRef)}
|
719
|
+
${this.eventController.register()}
|
720
|
+
?autoplay=${this.autoplay}
|
721
|
+
?loading=${this.fetching}
|
722
|
+
.data=${this.vouch}
|
723
|
+
.template=${this.template}
|
724
|
+
aspectRatio=${ifDefined(this.aspectRatio)}
|
725
|
+
preload=${ifDefined(this.preload)}
|
726
|
+
language=${ifDefined(this.language)}
|
727
|
+
.controls=${this.controls}
|
728
|
+
></vmp-media-player>
|
729
|
+
`;
|
730
|
+
}
|
731
|
+
};
|
732
|
+
PlayerEmbed.styles = [
|
733
|
+
css`
|
734
|
+
:host {
|
735
|
+
display: flex;
|
736
|
+
}
|
737
|
+
`
|
738
|
+
];
|
739
|
+
__decorateClass$3([
|
740
|
+
property({ type: Object })
|
741
|
+
], PlayerEmbed.prototype, "data", 2);
|
742
|
+
__decorateClass$3([
|
743
|
+
property({ type: String })
|
744
|
+
], PlayerEmbed.prototype, "vouchId", 2);
|
745
|
+
__decorateClass$3([
|
746
|
+
property({ type: String })
|
747
|
+
], PlayerEmbed.prototype, "templateId", 2);
|
748
|
+
__decorateClass$3([
|
749
|
+
property({ type: Array })
|
750
|
+
], PlayerEmbed.prototype, "questions", 2);
|
751
|
+
__decorateClass$3([
|
752
|
+
property({ type: String })
|
753
|
+
], PlayerEmbed.prototype, "env", 2);
|
754
|
+
__decorateClass$3([
|
755
|
+
property({ type: String })
|
756
|
+
], PlayerEmbed.prototype, "apiKey", 2);
|
757
|
+
__decorateClass$3([
|
758
|
+
property({ type: Boolean })
|
759
|
+
], PlayerEmbed.prototype, "disableTracking", 2);
|
760
|
+
__decorateClass$3([
|
761
|
+
property({ type: String })
|
762
|
+
], PlayerEmbed.prototype, "trackingSource", 2);
|
763
|
+
__decorateClass$3([
|
764
|
+
property({ type: Array })
|
765
|
+
], PlayerEmbed.prototype, "controls", 2);
|
766
|
+
__decorateClass$3([
|
767
|
+
property({ type: String })
|
768
|
+
], PlayerEmbed.prototype, "preload", 2);
|
769
|
+
__decorateClass$3([
|
770
|
+
property({ type: Boolean })
|
771
|
+
], PlayerEmbed.prototype, "autoplay", 2);
|
772
|
+
__decorateClass$3([
|
773
|
+
property({ type: Number })
|
774
|
+
], PlayerEmbed.prototype, "aspectRatio", 2);
|
775
|
+
__decorateClass$3([
|
776
|
+
property({ type: String })
|
777
|
+
], PlayerEmbed.prototype, "language", 2);
|
778
|
+
__decorateClass$3([
|
779
|
+
state()
|
780
|
+
], PlayerEmbed.prototype, "vouch", 2);
|
781
|
+
__decorateClass$3([
|
782
|
+
state()
|
783
|
+
], PlayerEmbed.prototype, "template", 2);
|
784
|
+
PlayerEmbed = __decorateClass$3([
|
785
|
+
customElement("vouch-embed-player")
|
786
|
+
], PlayerEmbed);
|
787
|
+
var __defProp$2 = Object.defineProperty;
|
788
|
+
var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
|
789
|
+
var __decorateClass$2 = (decorators, target, key, kind) => {
|
790
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
|
791
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
792
|
+
if (decorator = decorators[i])
|
793
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
794
|
+
if (kind && result)
|
795
|
+
__defProp$2(target, key, result);
|
796
|
+
return result;
|
797
|
+
};
|
798
|
+
let DialogOverlay = class extends LitElement {
|
799
|
+
constructor() {
|
800
|
+
super(...arguments);
|
801
|
+
this.open = false;
|
802
|
+
this.aspectRatio = 0;
|
803
|
+
}
|
804
|
+
render() {
|
805
|
+
return html`
|
806
|
+
<div
|
807
|
+
class=${classMap({
|
808
|
+
container: true,
|
809
|
+
hidden: !this.open
|
810
|
+
})}
|
811
|
+
>
|
812
|
+
<div
|
813
|
+
class="background"
|
814
|
+
@click=${() => this.dispatchEvent(new CustomEvent("overlay:click", { bubbles: true, composed: true }))}
|
815
|
+
></div>
|
816
|
+
<focus-trap>
|
817
|
+
<div
|
818
|
+
class=${classMap({
|
819
|
+
"video-frame": true,
|
820
|
+
grow: this.aspectRatio === 0
|
821
|
+
})}
|
822
|
+
style=${styleMap({
|
823
|
+
aspectRatio: this.aspectRatio
|
824
|
+
})}
|
825
|
+
>
|
826
|
+
<slot></slot>
|
827
|
+
<vmp-icon-button
|
828
|
+
icon="close"
|
829
|
+
rounded="full"
|
830
|
+
weight="heavy"
|
831
|
+
@click=${() => this.dispatchEvent(new CustomEvent("close:click", { bubbles: true, composed: true }))}
|
832
|
+
></vmp-icon-button>
|
833
|
+
</div>
|
834
|
+
</focus-trap>
|
835
|
+
</div>
|
836
|
+
`;
|
837
|
+
}
|
838
|
+
};
|
839
|
+
DialogOverlay.styles = [
|
840
|
+
css`
|
841
|
+
:host {
|
842
|
+
--vouch-media-player-border-radius: var(--vu-media-player-border-radius, 12px);
|
843
|
+
--overlay-background-color: var(--vu-overlay-background-color, black);
|
844
|
+
--overlay-background-opacity: var(--vu-overlay-background-opacity, 0.4);
|
845
|
+
|
846
|
+
--dialog-width: var(--vu-dialog-width, 890px);
|
847
|
+
--dialog-height: var(--vu-dialog-height, 500px);
|
848
|
+
}
|
849
|
+
|
850
|
+
.container {
|
851
|
+
position: fixed;
|
852
|
+
display: flex;
|
853
|
+
inset: 0;
|
854
|
+
opacity: 1;
|
855
|
+
z-index: 2147483647;
|
856
|
+
align-items: center;
|
857
|
+
justify-content: center;
|
858
|
+
transition: opacity 100ms ease-in;
|
859
|
+
}
|
860
|
+
|
861
|
+
.hidden {
|
862
|
+
opacity: 0;
|
863
|
+
pointer-events: none;
|
864
|
+
}
|
865
|
+
|
866
|
+
.background {
|
867
|
+
position: absolute;
|
868
|
+
inset: 0;
|
869
|
+
opacity: var(--overlay-background-opacity);
|
870
|
+
background-color: var(--overlay-background-color);
|
871
|
+
}
|
872
|
+
|
873
|
+
focus-trap {
|
874
|
+
display: flex;
|
875
|
+
align-items: center;
|
876
|
+
justify-content: center;
|
877
|
+
margin: 40px;
|
878
|
+
width: var(--dialog-width);
|
879
|
+
height: var(--dialog-height);
|
880
|
+
max-width: calc(100% - 80px);
|
881
|
+
max-height: calc(100% - 80px);
|
882
|
+
}
|
883
|
+
|
884
|
+
.video-frame {
|
885
|
+
position: relative;
|
886
|
+
display: flex;
|
887
|
+
align-items: center;
|
888
|
+
justify-content: center;
|
889
|
+
max-width: 100%;
|
890
|
+
max-height: 100%;
|
891
|
+
}
|
892
|
+
|
893
|
+
.video-frame.grow {
|
894
|
+
width: 100%;
|
895
|
+
height: 100%;
|
896
|
+
}
|
897
|
+
|
898
|
+
vmp-icon-button {
|
899
|
+
position: absolute;
|
900
|
+
top: 0;
|
901
|
+
right: 0;
|
902
|
+
margin: 10px;
|
903
|
+
}
|
904
|
+
`
|
905
|
+
];
|
906
|
+
__decorateClass$2([
|
907
|
+
property({ type: Boolean })
|
908
|
+
], DialogOverlay.prototype, "open", 2);
|
909
|
+
__decorateClass$2([
|
910
|
+
property({ type: Number })
|
911
|
+
], DialogOverlay.prototype, "aspectRatio", 2);
|
912
|
+
DialogOverlay = __decorateClass$2([
|
913
|
+
customElement("vouch-embed-dialog-overlay")
|
914
|
+
], DialogOverlay);
|
915
|
+
var __defProp$1 = Object.defineProperty;
|
916
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
917
|
+
var __decorateClass$1 = (decorators, target, key, kind) => {
|
918
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
|
919
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
920
|
+
if (decorator = decorators[i])
|
921
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
922
|
+
if (kind && result)
|
923
|
+
__defProp$1(target, key, result);
|
924
|
+
return result;
|
925
|
+
};
|
926
|
+
let DialogPortal = class extends LitElement {
|
927
|
+
constructor() {
|
928
|
+
super(...arguments);
|
929
|
+
this.env = "prod";
|
930
|
+
this.apiKey = "";
|
931
|
+
this.disableTracking = false;
|
932
|
+
this.trackingSource = "embedded_player";
|
933
|
+
this.preload = "none";
|
934
|
+
this.disableAutoplay = false;
|
935
|
+
this.aspectRatio = 0;
|
936
|
+
this._mediaPlayerRef = createRef();
|
937
|
+
this.open = false;
|
938
|
+
this._handleToggle = ({ detail }) => {
|
939
|
+
var _a, _b, _c;
|
940
|
+
if (this.id === detail) {
|
941
|
+
this.open = !this.open;
|
942
|
+
if (this.open) {
|
943
|
+
if (!this.disableAutoplay && ((_a = this._mediaPlayerRef) == null ? void 0 : _a.value)) {
|
944
|
+
this._mediaPlayerRef.value.muted = false;
|
945
|
+
this._mediaPlayerRef.value.play();
|
946
|
+
}
|
947
|
+
} else {
|
948
|
+
(_c = (_b = this._mediaPlayerRef) == null ? void 0 : _b.value) == null ? void 0 : _c.pause();
|
949
|
+
}
|
950
|
+
}
|
951
|
+
};
|
952
|
+
this._handleClose = () => {
|
953
|
+
var _a, _b;
|
954
|
+
this.open = false;
|
955
|
+
(_b = (_a = this._mediaPlayerRef) == null ? void 0 : _a.value) == null ? void 0 : _b.pause();
|
956
|
+
};
|
957
|
+
this._handleDocumentKeyUp = (e) => {
|
958
|
+
if (e.key === "Escape") {
|
959
|
+
this._handleClose();
|
960
|
+
}
|
961
|
+
};
|
962
|
+
}
|
963
|
+
connectedCallback() {
|
964
|
+
super.connectedCallback();
|
965
|
+
document.addEventListener("dialogembed:click", this._handleToggle);
|
966
|
+
document.addEventListener("keyup", this._handleDocumentKeyUp);
|
967
|
+
document.addEventListener("close:click", this._handleClose);
|
968
|
+
document.addEventListener("overlay:click", this._handleClose);
|
969
|
+
}
|
970
|
+
disconnectedCallback() {
|
971
|
+
super.disconnectedCallback();
|
972
|
+
document.removeEventListener("dialogembed:click", this._handleToggle);
|
973
|
+
document.removeEventListener("keyup", this._handleDocumentKeyUp);
|
974
|
+
document.removeEventListener("close:click", this._handleClose);
|
975
|
+
document.removeEventListener("overlay:click", this._handleClose);
|
976
|
+
}
|
977
|
+
createRenderRoot() {
|
978
|
+
const newNode = document.createElement("div");
|
979
|
+
document.body.appendChild(newNode);
|
980
|
+
return newNode;
|
981
|
+
}
|
982
|
+
render() {
|
983
|
+
return html`
|
984
|
+
<vouch-embed-dialog-overlay ?open=${this.open} aspectRatio=${this.aspectRatio}>
|
985
|
+
<vouch-embed-player
|
986
|
+
${ref(this._mediaPlayerRef)}
|
987
|
+
style=${styleMap({
|
988
|
+
maxWidth: "100%",
|
989
|
+
maxHeight: "100%"
|
990
|
+
})}
|
991
|
+
?autoplay=${false}
|
992
|
+
vouchId=${ifDefined(this.vouchId)}
|
993
|
+
templateId=${ifDefined(this.templateId)}
|
994
|
+
.questions=${this.questions}
|
995
|
+
.controls=${this.controls}
|
996
|
+
env=${ifDefined(this.env)}
|
997
|
+
apiKey=${ifDefined(this.apiKey)}
|
998
|
+
?disableTracking=${this.disableTracking}
|
999
|
+
trackingSource=${ifDefined(this.trackingSource)}
|
1000
|
+
preload=${ifDefined(this.preload)}
|
1001
|
+
aspectRatio=${this.aspectRatio}
|
1002
|
+
></vouch-embed-player>
|
1003
|
+
</vouch-embed-dialog-overlay>
|
1004
|
+
`;
|
1005
|
+
}
|
1006
|
+
};
|
1007
|
+
__decorateClass$1([
|
1008
|
+
property({ type: String })
|
1009
|
+
], DialogPortal.prototype, "vouchId", 2);
|
1010
|
+
__decorateClass$1([
|
1011
|
+
property({ type: String })
|
1012
|
+
], DialogPortal.prototype, "templateId", 2);
|
1013
|
+
__decorateClass$1([
|
1014
|
+
property({ type: Array })
|
1015
|
+
], DialogPortal.prototype, "questions", 2);
|
1016
|
+
__decorateClass$1([
|
1017
|
+
property({ type: String })
|
1018
|
+
], DialogPortal.prototype, "env", 2);
|
1019
|
+
__decorateClass$1([
|
1020
|
+
property({ type: String })
|
1021
|
+
], DialogPortal.prototype, "apiKey", 2);
|
1022
|
+
__decorateClass$1([
|
1023
|
+
property({ type: Boolean })
|
1024
|
+
], DialogPortal.prototype, "disableTracking", 2);
|
1025
|
+
__decorateClass$1([
|
1026
|
+
property({ type: String })
|
1027
|
+
], DialogPortal.prototype, "trackingSource", 2);
|
1028
|
+
__decorateClass$1([
|
1029
|
+
property({ type: Array })
|
1030
|
+
], DialogPortal.prototype, "controls", 2);
|
1031
|
+
__decorateClass$1([
|
1032
|
+
property({ type: String })
|
1033
|
+
], DialogPortal.prototype, "preload", 2);
|
1034
|
+
__decorateClass$1([
|
1035
|
+
property({ type: Boolean })
|
1036
|
+
], DialogPortal.prototype, "disableAutoplay", 2);
|
1037
|
+
__decorateClass$1([
|
1038
|
+
property({ type: Number })
|
1039
|
+
], DialogPortal.prototype, "aspectRatio", 2);
|
1040
|
+
__decorateClass$1([
|
1041
|
+
state()
|
1042
|
+
], DialogPortal.prototype, "open", 2);
|
1043
|
+
DialogPortal = __decorateClass$1([
|
1044
|
+
customElement("vouch-embed-dialog-portal")
|
1045
|
+
], DialogPortal);
|
1046
|
+
var __defProp = Object.defineProperty;
|
1047
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
1048
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
1049
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
1050
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
1051
|
+
if (decorator = decorators[i])
|
1052
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
1053
|
+
if (kind && result)
|
1054
|
+
__defProp(target, key, result);
|
1055
|
+
return result;
|
1056
|
+
};
|
1057
|
+
let DialogEmbed = class extends LitElement {
|
1058
|
+
constructor() {
|
1059
|
+
super(...arguments);
|
1060
|
+
this.env = "prod";
|
1061
|
+
this.apiKey = "";
|
1062
|
+
this.disableTracking = false;
|
1063
|
+
this.trackingSource = "embedded_player";
|
1064
|
+
this.preload = "none";
|
1065
|
+
this.disableAutoplay = false;
|
1066
|
+
this.aspectRatio = 0;
|
1067
|
+
this._id = v4();
|
1068
|
+
this._handleRootClick = () => {
|
1069
|
+
this.dispatchEvent(new CustomEvent("dialogembed:click", { detail: this._id, bubbles: true, composed: true }));
|
1070
|
+
};
|
1071
|
+
}
|
1072
|
+
connectedCallback() {
|
1073
|
+
super.connectedCallback();
|
1074
|
+
this.addEventListener("click", this._handleRootClick);
|
1075
|
+
}
|
1076
|
+
disconnectedCallback() {
|
1077
|
+
super.disconnectedCallback();
|
1078
|
+
this.removeEventListener("click", this._handleRootClick);
|
1079
|
+
}
|
1080
|
+
render() {
|
1081
|
+
return html`
|
1082
|
+
<slot>
|
1083
|
+
<vmp-button size="large">Play</vmp-button>
|
1084
|
+
</slot>
|
1085
|
+
<vouch-embed-dialog-portal
|
1086
|
+
id=${this._id}
|
1087
|
+
?autoplay=${false}
|
1088
|
+
vouchId=${ifDefined(this.vouchId)}
|
1089
|
+
templateId=${ifDefined(this.templateId)}
|
1090
|
+
.questions=${this.questions}
|
1091
|
+
.controls=${this.controls}
|
1092
|
+
env=${ifDefined(this.env)}
|
1093
|
+
apiKey=${ifDefined(this.apiKey)}
|
1094
|
+
?disableTracking=${this.disableTracking}
|
1095
|
+
trackingSource=${ifDefined(this.trackingSource)}
|
1096
|
+
preload=${ifDefined(this.preload)}
|
1097
|
+
aspectRatio=${this.aspectRatio}
|
1098
|
+
></vouch-embed-dialog-portal>
|
1099
|
+
`;
|
1100
|
+
}
|
1101
|
+
};
|
1102
|
+
DialogEmbed.styles = [
|
1103
|
+
css`
|
1104
|
+
:host {
|
1105
|
+
--vu-button-padding: 10px 20px;
|
1106
|
+
--vu-button-background: #287179;
|
1107
|
+
--vu-button-background-hover: #4faab2;
|
1108
|
+
|
1109
|
+
display: flex;
|
1110
|
+
width: fit-content;
|
1111
|
+
height: fit-content;
|
1112
|
+
}
|
1113
|
+
`
|
1114
|
+
];
|
1115
|
+
__decorateClass([
|
1116
|
+
property({ type: String })
|
1117
|
+
], DialogEmbed.prototype, "vouchId", 2);
|
1118
|
+
__decorateClass([
|
1119
|
+
property({ type: String })
|
1120
|
+
], DialogEmbed.prototype, "templateId", 2);
|
1121
|
+
__decorateClass([
|
1122
|
+
property({ type: Array })
|
1123
|
+
], DialogEmbed.prototype, "questions", 2);
|
1124
|
+
__decorateClass([
|
1125
|
+
property({ type: String })
|
1126
|
+
], DialogEmbed.prototype, "env", 2);
|
1127
|
+
__decorateClass([
|
1128
|
+
property({ type: String })
|
1129
|
+
], DialogEmbed.prototype, "apiKey", 2);
|
1130
|
+
__decorateClass([
|
1131
|
+
property({ type: Boolean })
|
1132
|
+
], DialogEmbed.prototype, "disableTracking", 2);
|
1133
|
+
__decorateClass([
|
1134
|
+
property({ type: String })
|
1135
|
+
], DialogEmbed.prototype, "trackingSource", 2);
|
1136
|
+
__decorateClass([
|
1137
|
+
property({ type: Array })
|
1138
|
+
], DialogEmbed.prototype, "controls", 2);
|
1139
|
+
__decorateClass([
|
1140
|
+
property({ type: String })
|
1141
|
+
], DialogEmbed.prototype, "preload", 2);
|
1142
|
+
__decorateClass([
|
1143
|
+
property({ type: Boolean })
|
1144
|
+
], DialogEmbed.prototype, "disableAutoplay", 2);
|
1145
|
+
__decorateClass([
|
1146
|
+
property({ type: Number })
|
1147
|
+
], DialogEmbed.prototype, "aspectRatio", 2);
|
1148
|
+
DialogEmbed = __decorateClass([
|
1149
|
+
customElement("vouch-embed-dialog")
|
1150
|
+
], DialogEmbed);
|
8
1151
|
export {
|
9
|
-
|
1152
|
+
DialogEmbed,
|
1153
|
+
PlayerEmbed
|
10
1154
|
};
|
11
1155
|
//# sourceMappingURL=embeds.js.map
|