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