@vouchfor/embeds 0.0.0-experiment.cf82dbe → 0.0.0-experiment.cfa2fea

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. package/dist/es/browser-99a8cab9.js +733 -0
  2. package/dist/es/{browser-ff061c90.js.map → browser-99a8cab9.js.map} +1 -1
  3. package/dist/es/embeds.js +6 -1
  4. package/dist/es/embeds.js.map +1 -1
  5. package/dist/es/index-038b2aee.js +4599 -0
  6. package/dist/es/index-038b2aee.js.map +1 -0
  7. package/dist/es/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
  8. package/dist/es/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
  9. package/dist/es/src/components/DialogEmbed/index.d.ts +36 -0
  10. package/dist/es/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
  11. package/dist/es/src/components/PlayerEmbed/index.d.ts +3 -1
  12. package/dist/es/src/index.d.ts +1 -0
  13. package/dist/{es/browser-ff061c90.js → iife/dialog-embed/browser-3b534a6e.js} +2 -2
  14. package/dist/iife/dialog-embed/browser-3b534a6e.js.map +1 -0
  15. package/dist/iife/dialog-embed/embed.iife.js +1722 -0
  16. package/dist/iife/dialog-embed/embed.iife.js.map +1 -0
  17. package/dist/iife/dialog-embed/embed.js +5 -0
  18. package/dist/iife/dialog-embed/embed.js.map +1 -0
  19. package/dist/iife/dialog-embed/index-85dfb3fa.js +27151 -0
  20. package/dist/iife/dialog-embed/index-85dfb3fa.js.map +1 -0
  21. package/dist/iife/dialog-embed/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
  22. package/dist/iife/dialog-embed/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
  23. package/dist/iife/dialog-embed/src/components/DialogEmbed/index.d.ts +36 -0
  24. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
  25. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/fetcher.d.ts +14 -0
  26. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/tracking/index.d.ts +36 -0
  27. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
  28. package/dist/iife/dialog-embed/src/components/PlayerEmbed/index.d.ts +73 -0
  29. package/dist/iife/dialog-embed/src/components/PlayerEmbed/tests/data.d.ts +3 -0
  30. package/dist/iife/dialog-embed/src/index.d.ts +2 -0
  31. package/dist/iife/dialog-embed/src/utils/env.d.ts +12 -0
  32. package/dist/iife/dialog-embed/src/utils/events.d.ts +2 -0
  33. package/dist/iife/embeds.iife.js +444 -294
  34. package/dist/iife/embeds.iife.js.map +1 -1
  35. package/dist/iife/player-embed/browser-e32f9956.js +433 -0
  36. package/dist/iife/player-embed/browser-e32f9956.js.map +1 -0
  37. package/dist/iife/player-embed/embed.iife.js +1584 -0
  38. package/dist/iife/player-embed/embed.iife.js.map +1 -0
  39. package/dist/iife/player-embed/embed.js +5 -0
  40. package/dist/iife/player-embed/embed.js.map +1 -0
  41. package/dist/iife/player-embed/index-3ce3e134.js +26706 -0
  42. package/dist/iife/player-embed/index-3ce3e134.js.map +1 -0
  43. package/dist/iife/player-embed/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
  44. package/dist/iife/player-embed/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
  45. package/dist/iife/player-embed/src/components/DialogEmbed/index.d.ts +36 -0
  46. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
  47. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/fetcher.d.ts +14 -0
  48. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/tracking/index.d.ts +36 -0
  49. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
  50. package/dist/iife/player-embed/src/components/PlayerEmbed/index.d.ts +73 -0
  51. package/dist/iife/player-embed/src/components/PlayerEmbed/tests/data.d.ts +3 -0
  52. package/dist/iife/player-embed/src/index.d.ts +2 -0
  53. package/dist/iife/player-embed/src/utils/env.d.ts +12 -0
  54. package/dist/iife/player-embed/src/utils/events.d.ts +2 -0
  55. package/package.json +9 -4
  56. package/src/components/DialogEmbed/Dialog.stories.ts +91 -0
  57. package/src/components/DialogEmbed/DialogOverlay.ts +131 -0
  58. package/src/components/DialogEmbed/DialogPortal.ts +126 -0
  59. package/src/components/DialogEmbed/index.ts +97 -0
  60. package/src/components/PlayerEmbed/controllers/event-forwarder.ts +2 -1
  61. package/src/components/PlayerEmbed/index.ts +10 -3
  62. package/src/index.ts +1 -0
  63. package/dist/es/index-b238c0dc.js +0 -9980
  64. package/dist/es/index-b238c0dc.js.map +0 -1
@@ -0,0 +1,19 @@
1
+ import { LitElement } from 'lit';
2
+ import type { DialogEmbedProps } from '.';
3
+ declare class DialogOverlay extends LitElement {
4
+ static styles: import("lit").CSSResult[];
5
+ open: boolean;
6
+ aspectRatio: DialogEmbedProps['aspectRatio'];
7
+ render(): import("lit").TemplateResult<1>;
8
+ }
9
+ declare global {
10
+ interface HTMLElementTagNameMap {
11
+ 'vouch-embed-dialog-overlay': DialogOverlay;
12
+ }
13
+ namespace JSX {
14
+ interface IntrinsicElements {
15
+ 'vouch-embed-dialog-overlay': DialogOverlay;
16
+ }
17
+ }
18
+ }
19
+ export { DialogOverlay };
@@ -0,0 +1,35 @@
1
+ import { LitElement } from 'lit';
2
+ import type { DialogEmbedProps } from '.';
3
+ declare class DialogPortal extends LitElement {
4
+ vouchId: DialogEmbedProps['vouchId'];
5
+ templateId: DialogEmbedProps['templateId'];
6
+ questions: DialogEmbedProps['questions'];
7
+ env: DialogEmbedProps['env'];
8
+ apiKey: DialogEmbedProps['apiKey'];
9
+ disableTracking: DialogEmbedProps['disableTracking'];
10
+ trackingSource: DialogEmbedProps['trackingSource'];
11
+ controls: DialogEmbedProps['controls'];
12
+ preload: DialogEmbedProps['preload'];
13
+ disableAutoplay: DialogEmbedProps['disableAutoplay'];
14
+ aspectRatio: DialogEmbedProps['aspectRatio'];
15
+ private _mediaPlayerRef;
16
+ open: boolean;
17
+ private _handleToggle;
18
+ private _handleClose;
19
+ private _handleDocumentKeyUp;
20
+ connectedCallback(): void;
21
+ disconnectedCallback(): void;
22
+ protected createRenderRoot(): HTMLElement | DocumentFragment;
23
+ render(): import("lit").TemplateResult<1>;
24
+ }
25
+ declare global {
26
+ interface HTMLElementTagNameMap {
27
+ 'vouch-embed-dialog-portal': DialogPortal;
28
+ }
29
+ namespace JSX {
30
+ interface IntrinsicElements {
31
+ 'vouch-embed-dialog-portal': DialogPortal;
32
+ }
33
+ }
34
+ }
35
+ export { DialogPortal };
@@ -0,0 +1,36 @@
1
+ import { LitElement } from 'lit';
2
+ import type { PlayerEmbedProps } from '../PlayerEmbed';
3
+ type DialogEmbedProps = Omit<PlayerEmbedProps, 'data'> & {
4
+ disableAutoplay?: boolean;
5
+ };
6
+ declare class DialogEmbed extends LitElement {
7
+ static styles: import("lit").CSSResult[];
8
+ vouchId: DialogEmbedProps['vouchId'];
9
+ templateId: DialogEmbedProps['templateId'];
10
+ questions: DialogEmbedProps['questions'];
11
+ env: DialogEmbedProps['env'];
12
+ apiKey: DialogEmbedProps['apiKey'];
13
+ disableTracking: DialogEmbedProps['disableTracking'];
14
+ trackingSource: DialogEmbedProps['trackingSource'];
15
+ controls: DialogEmbedProps['controls'];
16
+ preload: DialogEmbedProps['preload'];
17
+ disableAutoplay: DialogEmbedProps['disableAutoplay'];
18
+ aspectRatio: DialogEmbedProps['aspectRatio'];
19
+ private _id;
20
+ private _handleRootClick;
21
+ connectedCallback(): void;
22
+ disconnectedCallback(): void;
23
+ render(): import("lit").TemplateResult<1>;
24
+ }
25
+ declare global {
26
+ interface HTMLElementTagNameMap {
27
+ 'vouch-embed-dialog': DialogEmbed;
28
+ }
29
+ namespace JSX {
30
+ interface IntrinsicElements {
31
+ 'vouch-embed-dialog': DialogEmbed;
32
+ }
33
+ }
34
+ }
35
+ export { DialogEmbed };
36
+ export type { DialogEmbedProps };
@@ -0,0 +1,15 @@
1
+ import type { PlayerEmbed } from '..';
2
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
3
+ import type { DirectiveResult } from 'lit/directive.js';
4
+ type PlayerEmbedHost = ReactiveControllerHost & PlayerEmbed;
5
+ declare class EventForwardController implements ReactiveController {
6
+ host: PlayerEmbedHost;
7
+ private _events;
8
+ private _cleanup;
9
+ private _forwardElementRef;
10
+ constructor(host: PlayerEmbedHost, events: string[]);
11
+ register(): DirectiveResult;
12
+ hostConnected(): void;
13
+ hostDisconnected(): void;
14
+ }
15
+ export { EventForwardController };
@@ -0,0 +1,14 @@
1
+ import type { PlayerEmbed } from '..';
2
+ import type { ReactiveControllerHost } from 'lit';
3
+ type PlayerEmbedHost = ReactiveControllerHost & PlayerEmbed;
4
+ declare class FetcherController {
5
+ host: PlayerEmbedHost;
6
+ private _fetching;
7
+ private _vouch;
8
+ set fetching(value: boolean);
9
+ get fetching(): boolean;
10
+ private getVouch;
11
+ private getTemplate;
12
+ constructor(host: PlayerEmbedHost);
13
+ }
14
+ export { FetcherController };
@@ -0,0 +1,36 @@
1
+ import type { PlayerEmbed } from '../..';
2
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
3
+ type PlayerEmbedHost = ReactiveControllerHost & PlayerEmbed;
4
+ type TrackingEvent = 'VOUCH_LOADED' | 'VOUCH_RESPONSE_VIEWED' | 'VIDEO_PLAYED' | 'VIDEO_STREAMED';
5
+ type TrackingPayload = {
6
+ vouchId?: string;
7
+ answerId?: string;
8
+ streamStart?: number;
9
+ streamEnd?: number;
10
+ };
11
+ declare class TrackingController implements ReactiveController {
12
+ host: PlayerEmbedHost;
13
+ private _batchedEvents;
14
+ private _hasPlayed;
15
+ private _hasLoaded;
16
+ private _answersViewed;
17
+ private _streamStartTime;
18
+ private _streamLatestTime;
19
+ private _currentlyPlayingVideo;
20
+ constructor(host: PlayerEmbedHost);
21
+ private _createTrackingEvent;
22
+ private _sendTrackingEvent;
23
+ private _streamEnded;
24
+ private _handleVouchLoaded;
25
+ private _handlePlay;
26
+ private _handleVideoPlay;
27
+ private _handleVideoTimeUpdate;
28
+ private _handleVideoPause;
29
+ private _pageUnloading;
30
+ private _handleVisibilityChange;
31
+ private _handlePageHide;
32
+ hostConnected(): void;
33
+ hostDisconnected(): void;
34
+ }
35
+ export { TrackingController };
36
+ export type { TrackingEvent, TrackingPayload };
@@ -0,0 +1,17 @@
1
+ import type { TrackingPayload } from '.';
2
+ import type { Vouch } from '@vouchfor/media-player';
3
+ import type { Environment } from '../../../../utils/env';
4
+ declare function getUids(env: Environment): {
5
+ client: null;
6
+ tab: null;
7
+ request: string;
8
+ visitor?: undefined;
9
+ } | {
10
+ client: string;
11
+ tab: string;
12
+ request: string;
13
+ visitor: string;
14
+ };
15
+ declare function findVouchId(payload?: TrackingPayload, vouch?: Vouch): string | null | undefined;
16
+ declare function getReportingMetadata(source?: string): any;
17
+ export { getUids, findVouchId, getReportingMetadata };
@@ -0,0 +1,73 @@
1
+ import { LitElement } from 'lit';
2
+ import type { Scene, Scenes, TemplateInstance } from '@vouchfor/canvas-video';
3
+ import type { MediaPlayer, MediaPlayerProps } from '@vouchfor/media-player';
4
+ import type { Environment } from '../../utils/env';
5
+ type PlayerEmbedProps = Pick<MediaPlayerProps, 'data' | 'aspectRatio' | 'preload' | 'autoplay' | 'controls'> & {
6
+ env: Environment;
7
+ apiKey: string;
8
+ disableTracking?: boolean;
9
+ trackingSource?: string;
10
+ vouchId?: string;
11
+ templateId?: string;
12
+ questions?: number[];
13
+ };
14
+ declare class PlayerEmbed extends LitElement {
15
+ static styles: import("lit").CSSResult[];
16
+ data: PlayerEmbedProps['data'];
17
+ vouchId: PlayerEmbedProps['vouchId'];
18
+ templateId: PlayerEmbedProps['templateId'];
19
+ questions: PlayerEmbedProps['questions'];
20
+ env: PlayerEmbedProps['env'];
21
+ apiKey: PlayerEmbedProps['apiKey'];
22
+ disableTracking: PlayerEmbedProps['disableTracking'];
23
+ trackingSource: PlayerEmbedProps['trackingSource'];
24
+ controls: PlayerEmbedProps['controls'];
25
+ preload: PlayerEmbedProps['preload'];
26
+ autoplay: PlayerEmbedProps['autoplay'];
27
+ aspectRatio: PlayerEmbedProps['aspectRatio'];
28
+ private eventController;
29
+ private _fetcherController;
30
+ private _trackingController;
31
+ vouch: PlayerEmbedProps['data'];
32
+ template: TemplateInstance | undefined;
33
+ get fetching(): boolean;
34
+ private _mediaPlayerRef;
35
+ get waiting(): boolean | undefined;
36
+ get initialised(): Promise<boolean> | undefined;
37
+ get seeking(): boolean | undefined;
38
+ get paused(): boolean | undefined;
39
+ get captions(): boolean | undefined;
40
+ get fullscreen(): boolean | undefined;
41
+ get duration(): number | undefined;
42
+ set currentTime(value: number);
43
+ get currentTime(): number;
44
+ set playbackRate(value: number);
45
+ get playbackRate(): number;
46
+ set volume(value: number);
47
+ get volume(): number;
48
+ set muted(value: boolean);
49
+ get muted(): boolean;
50
+ get scene(): Scene | null;
51
+ get scenes(): Scene[];
52
+ get sceneConfig(): Scenes | null;
53
+ get videoState(): import("@vouchfor/media-player/dist/src/components/MediaPlayer/controllers/scenes").VideoStateMap | undefined;
54
+ get mediaPlayer(): MediaPlayer | undefined;
55
+ play(): void;
56
+ pause(): void;
57
+ reset(time?: number, play?: boolean): void;
58
+ setScene(index: number): void;
59
+ private _renderStyles;
60
+ render(): import("lit").TemplateResult<1>;
61
+ }
62
+ declare global {
63
+ interface HTMLElementTagNameMap {
64
+ 'vouch-embed-player': PlayerEmbed;
65
+ }
66
+ namespace JSX {
67
+ interface IntrinsicElements {
68
+ 'vouch-embed-player': PlayerEmbed;
69
+ }
70
+ }
71
+ }
72
+ export { PlayerEmbed };
73
+ export type { PlayerEmbedProps };
@@ -0,0 +1,3 @@
1
+ import type { Vouch } from '@vouchfor/media-player';
2
+ declare const data: Vouch;
3
+ export { data };
@@ -0,0 +1,2 @@
1
+ export { PlayerEmbed } from './components/PlayerEmbed';
2
+ export { DialogEmbed } from './components/DialogEmbed';
@@ -0,0 +1,12 @@
1
+ type Environment = 'local' | 'dev' | 'staging' | 'prod';
2
+ type GetEnvUrlsReturn = {
3
+ videoUrl: string;
4
+ publicApiUrl: string;
5
+ embedApiUrl: string;
6
+ };
7
+ declare const devEmbedApiUrl = "https://embed-dev.vouchfor.com/v2";
8
+ declare const stagingEmbedApiUrl = "https://embed-staging.vouchfor.com/v2";
9
+ declare const prodEmbedApiUrl = "https://embed.vouchfor.com/v2";
10
+ declare function getEnvUrls(env: Environment): GetEnvUrlsReturn;
11
+ export { devEmbedApiUrl, stagingEmbedApiUrl, prodEmbedApiUrl, getEnvUrls };
12
+ export type { Environment };
@@ -0,0 +1,2 @@
1
+ declare function forwardEvent(type: string, fromElement: HTMLElement, toElement: HTMLElement): () => void;
2
+ export { forwardEvent };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@vouchfor/embeds",
3
- "version": "0.0.0-experiment.cf82dbe",
3
+ "version": "0.0.0-experiment.cfa2fea",
4
4
  "license": "MIT",
5
5
  "author": "Aaron Williams",
6
6
  "main": "dist/es/embeds.js",
7
7
  "module": "dist/es/embeds.js",
8
8
  "type": "module",
9
- "types": "dist/es/index.d.ts",
9
+ "types": "dist/es/src/index.d.ts",
10
10
  "exports": {
11
11
  ".": "./dist/es/embeds.js"
12
12
  },
@@ -16,8 +16,9 @@
16
16
  "access": "public"
17
17
  },
18
18
  "scripts": {
19
- "build": "rm -rf dist && tsc && vite build --mode iife && vite build --mode es",
19
+ "build": "rm -rf dist && tsc && yarn build:self",
20
20
  "build:deps": "yarn --cwd ../media-player build",
21
+ "build:self": "vite build --mode iife && vite build --mode es && node scripts/build.cjs",
21
22
  "build:package": "yarn build",
22
23
  "build:storybook": "yarn prebuild && storybook build",
23
24
  "generate:manifest": "wca src --outFile custom-elements.json",
@@ -36,8 +37,9 @@
36
37
  "**/*.{md,json,yml}": "prettier --write"
37
38
  },
38
39
  "dependencies": {
40
+ "@a11y/focus-trap": "^1.0.5",
39
41
  "@lit/task": "^1.0.0",
40
- "@vouchfor/media-player": "0.0.0-experiment.cf82dbe",
42
+ "@vouchfor/media-player": "0.0.0-experiment.cfa2fea",
41
43
  "uuid": "^9.0.1"
42
44
  },
43
45
  "peerDependencies": {
@@ -62,11 +64,14 @@
62
64
  "dotenv": "^16.3.1",
63
65
  "eslint": "^8.50.0",
64
66
  "eslint-plugin-import": "^2.28.1",
67
+ "glob": "^10.3.10",
65
68
  "lint-staged": "^14.0.1",
66
69
  "lit": "^3.1.0",
70
+ "lodash": "^4.17.21",
67
71
  "prettier": "^3.0.3",
68
72
  "react": "^18.2.0",
69
73
  "react-dom": "^18.2.0",
74
+ "rollup-plugin-internal": "^1.0.4",
70
75
  "sinon": "^17.0.1",
71
76
  "storybook": "^7.4.5",
72
77
  "typescript": "^5.1.3",
@@ -0,0 +1,91 @@
1
+ import { html } from 'lit';
2
+ import { ifDefined } from 'lit/directives/if-defined.js';
3
+
4
+ import type { DialogEmbedProps } from '.';
5
+ import type { Meta, StoryObj } from '@storybook/web-components';
6
+
7
+ import '.';
8
+
9
+ type DialogEmbedArgs = DialogEmbedProps & {
10
+ showVouch?: boolean;
11
+ };
12
+
13
+ const _DialogEmbed = ({
14
+ vouchId,
15
+ templateId,
16
+ questions,
17
+ preload,
18
+ autoplay,
19
+ env,
20
+ apiKey,
21
+ controls,
22
+ aspectRatio
23
+ }: DialogEmbedArgs) => {
24
+ return html`
25
+ <div style="padding: 20px;">
26
+ <vouch-embed-dialog
27
+ env=${ifDefined(env)}
28
+ apiKey=${ifDefined(apiKey)}
29
+ vouchId=${ifDefined(vouchId)}
30
+ templateId=${ifDefined(templateId)}
31
+ .questions=${questions}
32
+ .controls=${controls}
33
+ ?autoplay=${autoplay}
34
+ preload=${ifDefined(preload)}
35
+ aspectRatio=${ifDefined(aspectRatio)}
36
+ @error=${console.log}
37
+ ></vouch-embed-dialog>
38
+ <vouch-embed-dialog
39
+ env=${ifDefined(env)}
40
+ apiKey=${ifDefined(apiKey)}
41
+ vouchId=${ifDefined(vouchId)}
42
+ templateId=${ifDefined(templateId)}
43
+ .questions=${questions}
44
+ .controls=${controls}
45
+ ?autoplay=${autoplay}
46
+ preload=${ifDefined(preload)}
47
+ aspectRatio=${ifDefined(aspectRatio)}
48
+ @error=${console.log}
49
+ ></vouch-embed-dialog>
50
+ </div>
51
+ `;
52
+ };
53
+
54
+ // More on how to set up stories at: https://storybook.js.org/docs/web-components/writing-stories/introduction
55
+ const meta = {
56
+ title: 'Dialog',
57
+ tags: ['autodocs'],
58
+ render: (args) => _DialogEmbed(args),
59
+ component: 'vouch-embed-dialog'
60
+ } satisfies Meta<DialogEmbedProps>;
61
+
62
+ type Story = StoryObj<DialogEmbedArgs>;
63
+
64
+ const Dialog: Story = {
65
+ args: {
66
+ env: 'dev',
67
+ apiKey: 'TVik9uTMgE-PD25UTHIS6gyl0hMBWC7AT4dkpdlLBT4VIfDWZJrQiCk6Ak7m1',
68
+ vouchId: '6JQEIPeStt',
69
+ templateId: '357fc118-e179-4171-9446-ff2b8e9d1b29',
70
+ questions: [],
71
+ aspectRatio: 0,
72
+ preload: 'none',
73
+ autoplay: false
74
+ },
75
+ argTypes: {
76
+ env: {
77
+ control: 'radio',
78
+ options: ['local', 'dev', 'staging', 'prod']
79
+ },
80
+ preload: {
81
+ control: 'radio',
82
+ options: ['auto', 'none']
83
+ }
84
+ },
85
+ parameters: {
86
+ layout: 'fullscreen'
87
+ }
88
+ };
89
+
90
+ export default meta;
91
+ export { Dialog };
@@ -0,0 +1,131 @@
1
+ import { css, html, LitElement } from 'lit';
2
+ import { customElement, property } from 'lit/decorators.js';
3
+ import { classMap } from 'lit/directives/class-map.js';
4
+ import { styleMap } from 'lit/directives/style-map.js';
5
+
6
+ import type { DialogEmbedProps } from '.';
7
+
8
+ import '@a11y/focus-trap';
9
+
10
+ @customElement('vouch-embed-dialog-overlay')
11
+ class DialogOverlay extends LitElement {
12
+ static styles = [
13
+ css`
14
+ :host {
15
+ --vouch-media-player-border-radius: var(--vu-media-player-border-radius, 12px);
16
+ --overlay-background-color: var(--vu-overlay-background-color, black);
17
+ --overlay-background-opacity: var(--vu-overlay-background-opacity, 0.4);
18
+
19
+ --dialog-width: var(--vu-dialog-width, 890px);
20
+ --dialog-height: var(--vu-dialog-height, 500px);
21
+ }
22
+
23
+ .container {
24
+ position: fixed;
25
+ display: flex;
26
+ inset: 0;
27
+ opacity: 1;
28
+ z-index: 2147483647;
29
+ align-items: center;
30
+ justify-content: center;
31
+ transition: opacity 100ms ease-in;
32
+ }
33
+
34
+ .hidden {
35
+ opacity: 0;
36
+ pointer-events: none;
37
+ }
38
+
39
+ .background {
40
+ position: absolute;
41
+ inset: 0;
42
+ opacity: var(--overlay-background-opacity);
43
+ background-color: var(--overlay-background-color);
44
+ }
45
+
46
+ focus-trap {
47
+ display: flex;
48
+ align-items: center;
49
+ justify-content: center;
50
+ margin: 40px;
51
+ width: var(--dialog-width);
52
+ height: var(--dialog-height);
53
+ max-width: calc(100% - 80px);
54
+ max-height: calc(100% - 80px);
55
+ }
56
+
57
+ .video-frame {
58
+ position: relative;
59
+ display: flex;
60
+ align-items: center;
61
+ justify-content: center;
62
+ max-width: 100%;
63
+ max-height: 100%;
64
+ }
65
+
66
+ .video-frame.grow {
67
+ width: 100%;
68
+ height: 100%;
69
+ }
70
+
71
+ vmp-icon-button {
72
+ position: absolute;
73
+ top: 0;
74
+ right: 0;
75
+ margin: 10px;
76
+ }
77
+ `
78
+ ];
79
+
80
+ @property({ type: Boolean }) open = false;
81
+ @property({ type: Number }) aspectRatio: DialogEmbedProps['aspectRatio'] = 0;
82
+
83
+ render() {
84
+ return html`
85
+ <div
86
+ class=${classMap({
87
+ container: true,
88
+ hidden: !this.open
89
+ })}
90
+ >
91
+ <div
92
+ class="background"
93
+ @click=${() => this.dispatchEvent(new CustomEvent('overlay:click', { bubbles: true, composed: true }))}
94
+ ></div>
95
+ <focus-trap>
96
+ <div
97
+ class=${classMap({
98
+ 'video-frame': true,
99
+ grow: this.aspectRatio === 0
100
+ })}
101
+ style=${styleMap({
102
+ aspectRatio: this.aspectRatio
103
+ })}
104
+ >
105
+ <slot></slot>
106
+ <vmp-icon-button
107
+ icon="close"
108
+ rounded="full"
109
+ weight="heavy"
110
+ @click=${() => this.dispatchEvent(new CustomEvent('close:click', { bubbles: true, composed: true }))}
111
+ ></vmp-icon-button>
112
+ </div>
113
+ </focus-trap>
114
+ </div>
115
+ `;
116
+ }
117
+ }
118
+
119
+ declare global {
120
+ interface HTMLElementTagNameMap {
121
+ 'vouch-embed-dialog-overlay': DialogOverlay;
122
+ }
123
+
124
+ namespace JSX {
125
+ interface IntrinsicElements {
126
+ 'vouch-embed-dialog-overlay': DialogOverlay;
127
+ }
128
+ }
129
+ }
130
+
131
+ export { DialogOverlay };
@@ -0,0 +1,126 @@
1
+ import { html, LitElement } from 'lit';
2
+ import { customElement, property, state } from 'lit/decorators.js';
3
+ import { ifDefined } from 'lit/directives/if-defined.js';
4
+ import { createRef, ref } from 'lit/directives/ref.js';
5
+ import { styleMap } from 'lit/directives/style-map.js';
6
+
7
+ import type { DialogEmbedProps } from '.';
8
+ import type { MediaPlayer } from '@vouchfor/media-player';
9
+
10
+ import './DialogOverlay';
11
+
12
+ @customElement('vouch-embed-dialog-portal')
13
+ class DialogPortal extends LitElement {
14
+ @property({ type: String }) vouchId: DialogEmbedProps['vouchId'];
15
+ @property({ type: String }) templateId: DialogEmbedProps['templateId'];
16
+ @property({ type: Array }) questions: DialogEmbedProps['questions'];
17
+
18
+ @property({ type: String }) env: DialogEmbedProps['env'] = 'prod';
19
+ @property({ type: String }) apiKey: DialogEmbedProps['apiKey'] = '';
20
+ @property({ type: Boolean }) disableTracking: DialogEmbedProps['disableTracking'] = false;
21
+ @property({ type: String }) trackingSource: DialogEmbedProps['trackingSource'] = 'embedded_player';
22
+
23
+ @property({ type: Array }) controls: DialogEmbedProps['controls'];
24
+ @property({ type: String }) preload: DialogEmbedProps['preload'] = 'none';
25
+ @property({ type: Boolean }) disableAutoplay: DialogEmbedProps['disableAutoplay'] = false;
26
+ @property({ type: Number }) aspectRatio: DialogEmbedProps['aspectRatio'] = 0;
27
+
28
+ private _mediaPlayerRef = createRef<MediaPlayer>();
29
+
30
+ @state() open = false;
31
+
32
+ private _handleToggle = ({ detail }: CustomEvent<string>) => {
33
+ // Because we have to attach this listener to the document since this element is portalled outside of the button,
34
+ // we also have to make sure that this player is actually the one we want to open and play by passing in an ID
35
+ // from the button wrapper parent and checking against that same ID we pass as the event detail
36
+ if (this.id === detail) {
37
+ this.open = !this.open;
38
+
39
+ if (this.open) {
40
+ if (!this.disableAutoplay && this._mediaPlayerRef?.value) {
41
+ this._mediaPlayerRef.value.muted = false;
42
+ this._mediaPlayerRef.value.play();
43
+ }
44
+ } else {
45
+ this._mediaPlayerRef?.value?.pause();
46
+ }
47
+ }
48
+ };
49
+
50
+ // We could do the same thing on close and check for the correct ID but it doesn't really matter
51
+ private _handleClose = () => {
52
+ this.open = false;
53
+ this._mediaPlayerRef?.value?.pause();
54
+ };
55
+
56
+ private _handleDocumentKeyUp = (e: KeyboardEvent) => {
57
+ if (e.key === 'Escape') {
58
+ this._handleClose();
59
+ }
60
+ };
61
+
62
+ connectedCallback(): void {
63
+ super.connectedCallback();
64
+ document.addEventListener('dialogembed:click', this._handleToggle);
65
+ document.addEventListener('keyup', this._handleDocumentKeyUp);
66
+ document.addEventListener('close:click', this._handleClose);
67
+ document.addEventListener('overlay:click', this._handleClose);
68
+ }
69
+
70
+ disconnectedCallback(): void {
71
+ super.disconnectedCallback();
72
+ document.removeEventListener('dialogembed:click', this._handleToggle);
73
+ document.removeEventListener('keyup', this._handleDocumentKeyUp);
74
+ document.removeEventListener('close:click', this._handleClose);
75
+ document.removeEventListener('overlay:click', this._handleClose);
76
+ }
77
+
78
+ protected createRenderRoot(): HTMLElement | DocumentFragment {
79
+ // We must create a new node here because portalling into the same node (document.body) causes the second
80
+ // element to overwrite the first for some reason (not behaviour really stated in the docs)
81
+ // I am fairly certain this function is only run once as the default behaviour creates the open shadow root
82
+ // and returns that shadow root in this function: https://lit.dev/docs/components/shadow-dom/#implementing-createrenderroot
83
+ const newNode = document.createElement('div');
84
+ document.body.appendChild(newNode);
85
+ return newNode;
86
+ }
87
+
88
+ render() {
89
+ return html`
90
+ <vouch-embed-dialog-overlay ?open=${this.open} aspectRatio=${this.aspectRatio}>
91
+ <vouch-embed-player
92
+ ${ref(this._mediaPlayerRef)}
93
+ style=${styleMap({
94
+ maxWidth: '100%',
95
+ maxHeight: '100%'
96
+ })}
97
+ ?autoplay=${false}
98
+ vouchId=${ifDefined(this.vouchId)}
99
+ templateId=${ifDefined(this.templateId)}
100
+ .questions=${this.questions}
101
+ .controls=${this.controls}
102
+ env=${ifDefined(this.env)}
103
+ apiKey=${ifDefined(this.apiKey)}
104
+ ?disableTracking=${this.disableTracking}
105
+ trackingSource=${ifDefined(this.trackingSource)}
106
+ preload=${ifDefined(this.preload)}
107
+ aspectRatio=${this.aspectRatio}
108
+ ></vouch-embed-player>
109
+ </vouch-embed-dialog-overlay>
110
+ `;
111
+ }
112
+ }
113
+
114
+ declare global {
115
+ interface HTMLElementTagNameMap {
116
+ 'vouch-embed-dialog-portal': DialogPortal;
117
+ }
118
+
119
+ namespace JSX {
120
+ interface IntrinsicElements {
121
+ 'vouch-embed-dialog-portal': DialogPortal;
122
+ }
123
+ }
124
+ }
125
+
126
+ export { DialogPortal };