@jaaq/jaaq-sdk-js 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +733 -92
  2. package/dist/embed/embed-collection.html +275 -0
  3. package/dist/embed/embed.html +270 -0
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/jaaq-sdk.min.js.map +1 -1
  7. package/dist/ui/index.cjs +5051 -0
  8. package/dist/ui/index.cjs.map +1 -0
  9. package/dist/ui/index.d.ts +378 -0
  10. package/dist/ui/index.mjs +5044 -0
  11. package/dist/ui/index.mjs.map +1 -0
  12. package/dist/ui/jaaq-ui-bundled.min.js +8 -0
  13. package/dist/ui/jaaq-ui-bundled.min.js.map +1 -0
  14. package/dist/ui/jaaq-ui.min.js +8 -0
  15. package/dist/ui/jaaq-ui.min.js.map +1 -0
  16. package/dist/ui/react/index.cjs +4756 -0
  17. package/dist/ui/react/index.cjs.map +1 -0
  18. package/dist/ui/react/index.d.ts +182 -0
  19. package/dist/ui/react/index.mjs +4735 -0
  20. package/dist/ui/react/index.mjs.map +1 -0
  21. package/dist/ui/react/jaaq-ui-react.min.js +8 -0
  22. package/dist/ui/react/jaaq-ui-react.min.js.map +1 -0
  23. package/dist/ui/vanilla/index.cjs +5052 -0
  24. package/dist/ui/vanilla/index.cjs.map +1 -0
  25. package/dist/ui/vanilla/index.d.ts +465 -0
  26. package/dist/ui/vanilla/index.mjs +5044 -0
  27. package/dist/ui/vanilla/index.mjs.map +1 -0
  28. package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js +8 -0
  29. package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js.map +1 -0
  30. package/dist/ui/vanilla/jaaq-vanilla.min.js +8 -0
  31. package/dist/ui/vanilla/jaaq-vanilla.min.js.map +1 -0
  32. package/dist/ui/webcomponents/index.cjs +4619 -0
  33. package/dist/ui/webcomponents/index.cjs.map +1 -0
  34. package/dist/ui/webcomponents/index.d.ts +288 -0
  35. package/dist/ui/webcomponents/index.mjs +4614 -0
  36. package/dist/ui/webcomponents/index.mjs.map +1 -0
  37. package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js +8 -0
  38. package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js.map +1 -0
  39. package/dist/ui/webcomponents/jaaq-webcomponents.min.js +8 -0
  40. package/dist/ui/webcomponents/jaaq-webcomponents.min.js.map +1 -0
  41. package/package.json +42 -2
@@ -0,0 +1,4735 @@
1
+ import * as React from 'react';
2
+ import { forwardRef, useRef, useImperativeHandle, useEffect } from 'react';
3
+ import Hls from 'hls.js';
4
+
5
+ async function parseJson(res) {
6
+ if (!res.ok) {
7
+ const text = await res.text().catch(() => '');
8
+ throw new Error(`HTTP ${res.status}: ${text || res.statusText}`);
9
+ }
10
+ if (res.status === 204)
11
+ return undefined;
12
+ return res.json();
13
+ }
14
+ function joinUrl(baseUrl, clientId, path) {
15
+ // return path if it is an absolute URL
16
+ if (/^https?:\/\//i.test(path))
17
+ return path;
18
+ const base = baseUrl.replace(/\/+$/, '');
19
+ const relative = path.replace(/^\/+/, '');
20
+ return `${base}/b2b/v1/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;
21
+ }
22
+ function createHttpClient(config) {
23
+ const { baseUrl, apiKey, clientId, fetch: fetchImpl } = config;
24
+ const f = fetchImpl ?? globalThis.fetch;
25
+ if (!f) {
26
+ throw new Error('No fetch implementation found. Provide one in SDKConfig.fetch for Node or custom environments.');
27
+ }
28
+ const baseHeaders = {
29
+ 'Content-Type': 'application/json',
30
+ 'x-api-key': apiKey,
31
+ };
32
+ const fullUrl = (path) => joinUrl(baseUrl, clientId, path);
33
+ const request = async (method, path, init, body) => {
34
+ const reqInit = {
35
+ method,
36
+ headers: {
37
+ ...baseHeaders,
38
+ ...init?.headers,
39
+ },
40
+ ...init,
41
+ };
42
+ if (body !== undefined)
43
+ reqInit.body = JSON.stringify(body);
44
+ const res = await f(fullUrl(path), reqInit);
45
+ return parseJson(res);
46
+ };
47
+ return {
48
+ get: (path, init) => request('GET', path, init),
49
+ post: (path, body, init) => request('POST', path, init, body),
50
+ put: (path, body, init) => request('PUT', path, init, body),
51
+ patch: (path, body, init) => request('PATCH', path, init, body),
52
+ delete: (path, init) => request('DELETE', path, init),
53
+ };
54
+ }
55
+
56
+ function createVideosResource(http) {
57
+ return {
58
+ async getById(id) {
59
+ const path = `/videos/${encodeURIComponent(id)}`;
60
+ const response = await http.get(path);
61
+ return response.video;
62
+ },
63
+ };
64
+ }
65
+
66
+ function createCollectionsResource(http) {
67
+ return {
68
+ async list() {
69
+ const path = '/collections';
70
+ const response = await http.get(path);
71
+ return response.collections;
72
+ },
73
+ async getById(id) {
74
+ const path = `/collections/${encodeURIComponent(id)}`;
75
+ const response = await http.get(path);
76
+ return response.collection;
77
+ },
78
+ };
79
+ }
80
+
81
+ const BASE_URL = "https://api.jaaq.app";
82
+ class JaaqClient {
83
+ // Keep constructor private to enforce controlled instantiation.
84
+ constructor(http) {
85
+ this.videos = createVideosResource(http);
86
+ this.collections = createCollectionsResource(http);
87
+ }
88
+ /**
89
+ * Public "friend" constructor that remains inside the class boundary.
90
+ * This method is callable from the module-level build function
91
+ * without exposing `new JaaqClient(...)` to consumers.
92
+ */
93
+ static fromHttp(http) {
94
+ return new JaaqClient(http);
95
+ }
96
+ /**
97
+ * OO-friendly static initializer.
98
+ * Delegates to the single source of truth: `buildClient`.
99
+ */
100
+ static init(config) {
101
+ return buildClient(config);
102
+ }
103
+ }
104
+ /**
105
+ * Canonical factory (idiomatic for JS/TS).
106
+ * Delegates to the single source of truth: `buildClient`.
107
+ */
108
+ function createJaaqClient(config) {
109
+ return buildClient(config);
110
+ }
111
+ /**
112
+ * Single source of truth for constructing the client.
113
+ * Both `createJaaqClient` and `JaaqClient.init` call this function.
114
+ * The constructor stays private; instantiation is funneled via `JaaqClient.fromHttp`.
115
+ */
116
+ function buildClient(config) {
117
+ const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl } = config;
118
+ const http = createHttpClient({
119
+ baseUrl,
120
+ apiKey,
121
+ clientId,
122
+ fetch: fetchImpl ?? globalThis.fetch,
123
+ });
124
+ return JaaqClient.fromHttp(http);
125
+ }
126
+
127
+ /**
128
+ * Formats a time value in seconds to a human-readable string (M:SS format)
129
+ * @param seconds - Time in seconds to format
130
+ * @returns Formatted time string in M:SS format, or "0:00" if invalid
131
+ * @example
132
+ * formatTime(65) // "1:05"
133
+ * formatTime(0) // "0:00"
134
+ * formatTime(125) // "2:05"
135
+ */
136
+ /**
137
+ * Checks if a video URL is an HLS (HTTP Live Streaming) source
138
+ * @param url - Video URL to check
139
+ * @returns True if the URL contains .m3u8 extension, false otherwise
140
+ */
141
+ function isHLSSource(url) {
142
+ return url.includes('.m3u8');
143
+ }
144
+ /**
145
+ * Toggles fullscreen mode for the given element
146
+ * If not in fullscreen, requests fullscreen for the element
147
+ * If already in fullscreen, exits fullscreen mode
148
+ * @param element - HTML element to toggle fullscreen for
149
+ * @returns Promise that resolves when fullscreen state changes
150
+ */
151
+ function toggleFullscreen(element) {
152
+ if (!document.fullscreenElement) {
153
+ return element.requestFullscreen();
154
+ }
155
+ else {
156
+ return document.exitFullscreen();
157
+ }
158
+ }
159
+ /**
160
+ * Clamps a numeric value between a minimum and maximum value
161
+ * @param value - Value to clamp
162
+ * @param min - Minimum allowed value
163
+ * @param max - Maximum allowed value
164
+ * @returns The clamped value
165
+ * @example
166
+ * clamp(5, 0, 10) // 5
167
+ * clamp(-5, 0, 10) // 0
168
+ * clamp(15, 0, 10) // 10
169
+ */
170
+ function clamp$1(value, min, max) {
171
+ return Math.max(min, Math.min(max, value));
172
+ }
173
+
174
+ var sharedStyles = ".jaaq-video-player {\n position: relative;\n width: 100%;\n max-width: none;\n margin: 0;\n background: #000;\n border-radius: 12px;\n overflow: hidden;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;\n aspect-ratio: 9 / 16;\n}\n\n.jaaq-video-player video {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: block;\n background: #000;\n object-fit: cover;\n}\n\n.jaaq-video-player.fullscreen {\n max-width: 100%;\n border-radius: 0;\n aspect-ratio: auto;\n}\n\n.jaaq-controls {\n position: absolute;\n bottom: 0;\n left: 0;\n right: 0;\n background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);\n padding: 40px 16px 16px;\n opacity: 1;\n z-index: 5;\n}\n\n.jaaq-progress-bar {\n width: 100%;\n flex: 1 1 0;\n min-width: 80px;\n height: 4px;\n background: rgba(255, 255, 255, 0.3);\n border-radius: 2px;\n cursor: pointer;\n position: relative;\n}\n\n.jaaq-progress-filled {\n height: 100%;\n background: #007bff;\n border-radius: 2px;\n width: 0%;\n transition: width 0.1s linear;\n}\n\n.jaaq-progress-bar:hover .jaaq-progress-filled {\n background: #0056b3;\n}\n\n.jaaq-controls-bottom {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 12px;\n color: white;\n}\n\n.jaaq-control-btn {\n background: transparent;\n border: none;\n color: white;\n cursor: pointer;\n padding: 8px;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: transform 0.2s;\n font-size: 20px;\n line-height: 1;\n}\n\n.jaaq-control-btn:hover {\n transform: scale(1.1);\n}\n\n.jaaq-control-btn:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n}\n\n.jaaq-loading {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 50px;\n height: 50px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #007bff;\n border-radius: 50%;\n animation: jaaq-spin 1s linear infinite;\n}\n\n@keyframes jaaq-spin {\n to {\n transform: translate(-50%, -50%) rotate(360deg);\n }\n}\n\n.jaaq-error {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n background: rgba(220, 53, 69, 0.9);\n color: white;\n padding: 16px 24px;\n border-radius: 8px;\n max-width: 80%;\n text-align: center;\n font-size: 14px;\n}\n\n.jaaq-video-info {\n padding: 16px;\n background: #f8f9fa;\n border-radius: 0 0 12px 12px;\n margin-top: -12px;\n}\n\n.jaaq-video-info h3 {\n margin: 0 0 8px 0;\n color: #333;\n font-size: 18px;\n font-weight: 600;\n}\n\n.jaaq-video-info p {\n margin: 4px 0;\n color: #666;\n font-size: 14px;\n}\n\n.jaaq-video-info strong {\n color: #333;\n}\n\n.jaaq-logo {\n position: absolute;\n top: 20px;\n left: 22px;\n color: white;\n font-size: 16px;\n font-weight: 600;\n z-index: 10;\n font-family:\n 'Archivo',\n -apple-system,\n BlinkMacSystemFont,\n 'Segoe UI',\n Roboto,\n sans-serif;\n letter-spacing: 0.5px;\n pointer-events: none;\n}\n\n.jaaq-center-play-btn {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 84px;\n height: 84px;\n background: transparent;\n border: none;\n cursor: pointer;\n z-index: 15;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: transform 0.2s;\n padding: 0;\n}\n\n.jaaq-center-play-btn:hover {\n transform: translate(-50%, -50%) scale(1.1);\n}\n\n.jaaq-center-play-btn svg {\n width: 100%;\n height: 100%;\n filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));\n}\n\n.jaaq-video-player.is-playing .jaaq-center-play-btn {\n display: none;\n}\n\n.jaaq-gradient-overlay {\n position: absolute;\n bottom: 0;\n left: 0;\n right: 0;\n background: linear-gradient(180deg, transparent 0%, #0f0f0f 100%);\n padding: 80px 22px 85px;\n pointer-events: none;\n z-index: 5;\n}\n\n.jaaq-caption-display {\n font-family:\n 'Archivo',\n -apple-system,\n BlinkMacSystemFont,\n 'Segoe UI',\n Roboto,\n sans-serif;\n font-weight: 400;\n font-size: 16px;\n line-height: 20px;\n color: white;\n background: rgba(0, 0, 0, 0.8);\n padding: 8px 16px;\n margin-bottom: 12px;\n border-radius: 4px;\n text-align: center;\n max-width: 90%;\n margin-left: auto;\n margin-right: auto;\n}\n\n.jaaq-video-title {\n font-family:\n 'Archivo',\n -apple-system,\n BlinkMacSystemFont,\n 'Segoe UI',\n Roboto,\n sans-serif;\n font-weight: 600;\n font-size: 18.695px;\n line-height: 21.5px;\n color: white;\n margin-bottom: 8px;\n letter-spacing: 0.37px;\n}\n\n.jaaq-video-author {\n font-family:\n 'Archivo',\n -apple-system,\n BlinkMacSystemFont,\n 'Segoe UI',\n Roboto,\n sans-serif;\n font-weight: 500;\n font-size: 14.021px;\n line-height: 16.825px;\n color: white;\n opacity: 0.7;\n margin-bottom: 8px;\n letter-spacing: -0.14px;\n}\n\n.jaaq-video-description {\n font-family:\n 'Archivo',\n -apple-system,\n BlinkMacSystemFont,\n 'Segoe UI',\n Roboto,\n sans-serif;\n font-weight: 400;\n font-size: 11px;\n line-height: 16px;\n color: #aaa8aa;\n letter-spacing: -0.11px;\n}\n\n.jaaq-description-text {\n color: #aaa8aa;\n}\n\n.jaaq-read-more {\n color: white;\n cursor: pointer;\n pointer-events: auto;\n}\n\n.jaaq-read-more:hover {\n text-decoration: underline;\n}\n\n.jaaq-progress-bar {\n background: rgba(255, 255, 255, 0.2);\n}\n\n.jaaq-progress-filled {\n background: white;\n}\n\n.jaaq-captions-btn {\n font-size: 14px;\n font-weight: 600;\n border: 1.5px solid white;\n border-radius: 3px;\n padding: 4px 6px;\n line-height: 1;\n}\n\n.jaaq-captions-btn.active {\n background: white;\n color: #000;\n}\n";
175
+
176
+ var vanillaStyles = ".jaaq-vanilla-player {\n user-select: none;\n}\n\n.jaaq-vanilla-player video {\n outline: none;\n}\n\n.jaaq-collection-player {\n width: 100%;\n max-width: 1400px;\n margin: 0 auto;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;\n}\n\n.jaaq-collection-loading {\n display: flex;\n justify-content: center;\n align-items: center;\n min-height: 400px;\n}\n\n.jaaq-collection-spinner {\n width: 50px;\n height: 50px;\n border: 4px solid rgba(0, 123, 255, 0.3);\n border-top-color: #007bff;\n border-radius: 50%;\n animation: jaaq-collection-spin 1s linear infinite;\n}\n\n@keyframes jaaq-collection-spin {\n to {\n transform: rotate(360deg);\n }\n}\n\n.jaaq-collection-error {\n background: rgba(220, 53, 69, 0.9);\n color: white;\n padding: 16px 24px;\n border-radius: 8px;\n text-align: center;\n font-size: 14px;\n margin: 20px;\n}\n\n.jaaq-collection-carousel .splide__track {\n padding: 40px 0;\n}\n\n.jaaq-collection-carousel .splide__slide {\n opacity: 0.7;\n transition: all 0.3s ease;\n display: flex;\n align-items: center;\n justify-content: center;\n}\n\n.jaaq-collection-carousel .splide__slide.is-active {\n opacity: 1;\n}\n\n.jaaq-collection-carousel .splide__slide jaaq-video-player {\n width: 100%;\n max-width: 600px;\n transition: all 0.3s ease;\n}\n\n.jaaq-collection-carousel .splide__slide.is-active jaaq-video-player {\n max-width: 800px;\n}\n\n.jaaq-collection-carousel .splide__arrow {\n background: rgba(0, 0, 0, 0.5);\n border: none;\n width: 48px;\n height: 48px;\n border-radius: 50%;\n color: white;\n cursor: pointer;\n transition: all 0.2s;\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 20px;\n}\n\n.jaaq-collection-carousel .splide__arrow:hover {\n background: rgba(0, 0, 0, 0.8);\n transform: scale(1.1);\n}\n\n.jaaq-collection-carousel .splide__arrow:disabled {\n opacity: 0.3;\n cursor: not-allowed;\n}\n\n.jaaq-collection-carousel .splide__arrow svg {\n fill: white;\n width: 20px;\n height: 20px;\n}\n\n.jaaq-collection-carousel .splide__pagination {\n bottom: -30px;\n}\n\n.jaaq-collection-carousel .splide__pagination__page {\n background: #ccc;\n border: none;\n width: 10px;\n height: 10px;\n margin: 0 4px;\n border-radius: 50%;\n transition: all 0.2s;\n cursor: pointer;\n}\n\n.jaaq-collection-carousel .splide__pagination__page.is-active {\n background: #007bff;\n transform: scale(1.3);\n}\n\n@media (max-width: 1024px) {\n .jaaq-collection-carousel .splide__slide jaaq-video-player {\n max-width: 500px;\n }\n\n .jaaq-collection-carousel .splide__slide.is-active jaaq-video-player {\n max-width: 650px;\n }\n}\n\n@media (max-width: 768px) {\n .jaaq-collection-carousel .splide__track {\n padding: 20px 0;\n }\n\n .jaaq-collection-carousel .splide__slide jaaq-video-player {\n max-width: 400px;\n }\n\n .jaaq-collection-carousel .splide__slide.is-active jaaq-video-player {\n max-width: 500px;\n }\n\n .jaaq-collection-carousel .splide__arrow {\n width: 40px;\n height: 40px;\n }\n}\n\n@media (max-width: 480px) {\n .jaaq-collection-carousel .splide__slide jaaq-video-player {\n max-width: 100%;\n }\n\n .jaaq-collection-carousel .splide__slide.is-active jaaq-video-player {\n max-width: 100%;\n }\n}\n";
177
+
178
+ class JaaqVideoPlayer {
179
+ /**
180
+ * Creates a new video player instance
181
+ * @param container - HTML element or CSS selector to render the player into
182
+ * @param config - Player configuration options
183
+ * @throws {Error} If container element is not found or if authentication credentials are missing
184
+ */
185
+ constructor(container, config) {
186
+ this.client = null;
187
+ this.hls = null;
188
+ this.videoElement = null;
189
+ this.listeners = new Map();
190
+ this.captionCues = [];
191
+ this.elements = {};
192
+ this.container = typeof container === 'string' ? document.querySelector(container) : container;
193
+ if (!this.container) {
194
+ throw new Error('Container element not found');
195
+ }
196
+ this.config = config;
197
+ this.state = {
198
+ isPlaying: false,
199
+ currentTime: 0,
200
+ duration: 0,
201
+ volume: 1,
202
+ isMuted: false,
203
+ isFullscreen: false,
204
+ isLoading: true,
205
+ error: null,
206
+ videoData: null,
207
+ captionsEnabled: false,
208
+ };
209
+ if (config.client) {
210
+ this.client = config.client;
211
+ }
212
+ else if (config.apiKey && config.clientId) {
213
+ this.client = createJaaqClient({
214
+ apiKey: config.apiKey,
215
+ clientId: config.clientId,
216
+ baseUrl: config.baseUrl,
217
+ });
218
+ }
219
+ else {
220
+ throw new Error('Please provide either a client instance or apiKey and clientId');
221
+ }
222
+ this.init();
223
+ }
224
+ async init() {
225
+ this.createDOM();
226
+ await this.loadVideo();
227
+ this.attachEventListeners();
228
+ }
229
+ createDOM() {
230
+ this.container.innerHTML = '';
231
+ const wrapper = document.createElement('div');
232
+ wrapper.style.width = this.config.width || '100%';
233
+ wrapper.style.height = this.config.height || 'auto';
234
+ const player = document.createElement('div');
235
+ player.className = `jaaq-video-player jaaq-vanilla-player ${this.config.className || ''}`;
236
+ this.elements.player = player;
237
+ const video = document.createElement('video');
238
+ this.videoElement = video;
239
+ player.appendChild(video);
240
+ const logo = document.createElement('div');
241
+ logo.className = 'jaaq-logo';
242
+ logo.innerHTML = `
243
+ <svg xmlns="http://www.w3.org/2000/svg" width="50" height="15" viewBox="0 0 50 15" fill="none">
244
+ <path d="M48.0329 10.7826C48.7578 9.6622 49.1402 8.37108 49.1402 7.02322C49.1402 3.19784 46.0283 0.0859375 42.2029 0.0859375C38.3775 0.0859375 35.2656 3.19784 35.2656 7.02322C35.2656 10.8486 38.3753 13.9578 42.1985 13.9605C42.1991 13.9605 42.2002 13.9605 42.2007 13.9605H42.2029C43.8475 13.9605 45.4305 13.3687 46.6698 12.3285L49.9971 14.56V12.0999L48.0334 10.7826H48.0329ZM37.309 7.02322C37.309 4.32479 39.5045 2.12927 42.2035 2.12927C44.9024 2.12927 47.0974 4.32479 47.0974 7.02322C47.0974 7.96252 46.8345 8.862 46.3359 9.64475L43.9817 8.06561C43.4531 7.71378 42.8373 7.52778 42.2002 7.52778C40.4394 7.52778 39.0054 8.95036 38.9846 10.7062C37.9586 9.80839 37.3084 8.49053 37.3084 7.02322H37.309ZM42.2035 11.9172C42.2035 11.9172 42.2002 11.9172 42.1985 11.9172C41.5527 11.9161 41.0274 11.3903 41.0274 10.7439C41.0274 10.0975 41.5538 9.57056 42.2007 9.57056C42.4331 9.57056 42.6578 9.6382 42.8493 9.76584L44.8714 11.1224C44.0853 11.633 43.1586 11.9172 42.2029 11.9172H42.2035Z" fill="white"/>
245
+ <path d="M31.0751 0.686201C30.9856 0.579834 30.8858 0.483286 30.7767 0.39983C30.4374 0.138004 30.0283 0 29.5946 0C29.161 0 28.7524 0.138549 28.4126 0.39983C28.2304 0.540561 28.0755 0.711838 27.9533 0.909844C27.8835 1.02276 27.8257 1.14003 27.7815 1.25785L23.1172 13.7317H25.4551L29.5946 2.66135L33.7342 13.7317H36.0721L31.4078 1.25785C31.3303 1.05003 31.218 0.858024 31.0745 0.686746L31.0751 0.686201Z" fill="white"/>
246
+ <path d="M17.4969 0.686201C17.4075 0.579834 17.3076 0.483286 17.1986 0.39983C16.8593 0.138004 16.4502 0 16.0165 0C15.5829 0 15.1743 0.138549 14.8345 0.39983C14.6523 0.540561 14.4974 0.711838 14.3752 0.909844C14.3054 1.02276 14.2476 1.14003 14.2034 1.25785L9.53906 13.7317H11.8769L16.0165 2.66135L20.1561 13.7317H22.494L17.8302 1.25731C17.7527 1.04948 17.6404 0.857478 17.4969 0.686201Z" fill="white"/>
247
+ <path d="M9.86046 0.511825V0.371094H7.82204V9.02333C7.82204 10.6248 6.51891 11.928 4.91741 11.928C3.47028 11.928 2.23261 10.849 2.03897 9.41771L2.01988 9.27807L1.88024 9.29716L0.13964 9.5328L0 9.5519L0.0190914 9.69154C0.348555 12.1292 2.45462 13.9669 4.91741 13.9669C7.64313 13.9669 9.86046 11.7496 9.86046 9.02388V0.511825Z" fill="white"/>
248
+ </svg>
249
+ `;
250
+ this.elements.logo = logo;
251
+ player.appendChild(logo);
252
+ const centerPlayBtn = document.createElement('button');
253
+ centerPlayBtn.className = 'jaaq-center-play-btn';
254
+ centerPlayBtn.innerHTML = `
255
+ <svg viewBox="0 0 84 84" fill="none">
256
+ <circle cx="42" cy="42" r="42" fill="white" fill-opacity="0.9"/>
257
+ <path d="M33 28L56 42L33 56V28Z" fill="#000"/>
258
+ </svg>
259
+ `;
260
+ centerPlayBtn.setAttribute('aria-label', 'Play video');
261
+ this.elements.centerPlayBtn = centerPlayBtn;
262
+ player.appendChild(centerPlayBtn);
263
+ const gradientOverlay = document.createElement('div');
264
+ gradientOverlay.className = 'jaaq-gradient-overlay';
265
+ this.elements.gradientOverlay = gradientOverlay;
266
+ const captionDisplay = document.createElement('div');
267
+ captionDisplay.className = 'jaaq-caption-display';
268
+ captionDisplay.style.display = 'none';
269
+ this.elements.captionDisplay = captionDisplay;
270
+ gradientOverlay.appendChild(captionDisplay);
271
+ const videoTitle = document.createElement('div');
272
+ videoTitle.className = 'jaaq-video-title';
273
+ this.elements.videoTitle = videoTitle;
274
+ gradientOverlay.appendChild(videoTitle);
275
+ const videoAuthor = document.createElement('div');
276
+ videoAuthor.className = 'jaaq-video-author';
277
+ this.elements.videoAuthor = videoAuthor;
278
+ gradientOverlay.appendChild(videoAuthor);
279
+ const videoDescription = document.createElement('div');
280
+ videoDescription.className = 'jaaq-video-description';
281
+ this.elements.videoDescription = videoDescription;
282
+ gradientOverlay.appendChild(videoDescription);
283
+ player.appendChild(gradientOverlay);
284
+ const loading = document.createElement('div');
285
+ loading.className = 'jaaq-loading';
286
+ this.elements.loading = loading;
287
+ player.appendChild(loading);
288
+ const error = document.createElement('div');
289
+ error.className = 'jaaq-error';
290
+ error.style.display = 'none';
291
+ this.elements.error = error;
292
+ player.appendChild(error);
293
+ const controls = document.createElement('div');
294
+ controls.className = 'jaaq-controls';
295
+ this.elements.controls = controls;
296
+ const controlsBottom = document.createElement('div');
297
+ controlsBottom.className = 'jaaq-controls-bottom';
298
+ const playPauseBtn = document.createElement('button');
299
+ playPauseBtn.className = 'jaaq-control-btn';
300
+ playPauseBtn.textContent = '▶';
301
+ playPauseBtn.setAttribute('aria-label', 'Play');
302
+ this.elements.playPauseBtn = playPauseBtn;
303
+ controlsBottom.appendChild(playPauseBtn);
304
+ const volumeBtn = document.createElement('button');
305
+ volumeBtn.className = 'jaaq-control-btn';
306
+ volumeBtn.innerHTML = `
307
+ <svg xmlns="http://www.w3.org/2000/svg" width="22" height="20" viewBox="0 0 22 20" fill="none">
308
+ <path d="M11.2168 19.9287L4.20801 13.7031H0V6.22559H4.20898L11.2168 0V19.9287ZM14.0215 0.150391C16.2405 0.150468 18.1409 1.39074 19.4385 3.17676C20.7365 4.9634 21.499 7.36811 21.499 9.96484C21.499 12.5613 20.7363 14.9654 19.4385 16.752C18.1409 18.538 16.2405 19.7792 14.0215 19.7793V17.1025C15.2032 17.1025 16.3824 16.4464 17.3135 15.165C18.2442 13.8839 18.8593 12.0493 18.8594 9.96484C18.8594 7.88034 18.2442 6.04581 17.3135 4.76465C16.3824 3.4832 15.2033 2.82723 14.0215 2.82715V0.150391ZM14.0215 5.75879C15.5701 5.75896 16.8252 7.64189 16.8252 9.96484C16.8251 12.2877 15.57 14.1707 14.0215 14.1709V5.75879Z" fill="white"/>
309
+ </svg>
310
+ `;
311
+ volumeBtn.setAttribute('aria-label', 'Mute');
312
+ this.elements.volumeBtn = volumeBtn;
313
+ controlsBottom.appendChild(volumeBtn);
314
+ const progressBar = document.createElement('div');
315
+ progressBar.className = 'jaaq-progress-bar';
316
+ this.elements.progressBar = progressBar;
317
+ const progressFilled = document.createElement('div');
318
+ progressFilled.className = 'jaaq-progress-filled';
319
+ this.elements.progressFilled = progressFilled;
320
+ progressBar.appendChild(progressFilled);
321
+ controlsBottom.appendChild(progressBar);
322
+ const captionsBtn = document.createElement('button');
323
+ captionsBtn.className = 'jaaq-control-btn jaaq-captions-btn';
324
+ captionsBtn.innerHTML = 'CC';
325
+ captionsBtn.setAttribute('aria-label', 'Captions');
326
+ this.elements.captionsBtn = captionsBtn;
327
+ controlsBottom.appendChild(captionsBtn);
328
+ const fullscreenBtn = document.createElement('button');
329
+ fullscreenBtn.className = 'jaaq-control-btn';
330
+ fullscreenBtn.textContent = '⛶';
331
+ fullscreenBtn.setAttribute('aria-label', 'Fullscreen');
332
+ this.elements.fullscreenBtn = fullscreenBtn;
333
+ controlsBottom.appendChild(fullscreenBtn);
334
+ controls.appendChild(controlsBottom);
335
+ player.appendChild(controls);
336
+ wrapper.appendChild(player);
337
+ this.container.appendChild(wrapper);
338
+ this.updateControlsVisibility();
339
+ }
340
+ updateControlsVisibility() {
341
+ const showControls = this.config.controls !== false;
342
+ if (this.elements.controls) {
343
+ this.elements.controls.style.display = showControls ? '' : 'none';
344
+ }
345
+ }
346
+ async loadVideo() {
347
+ if (!this.client || !this.videoElement)
348
+ return;
349
+ try {
350
+ this.setState({ isLoading: true, error: null });
351
+ const video = await this.client.videos.getById(this.config.videoId);
352
+ this.setState({ videoData: video });
353
+ if (video.subtitle) {
354
+ this.captionCues = this.parseWebVTT(video.subtitle);
355
+ }
356
+ this.updateOverlayContent(video);
357
+ this.emit('loaded', video);
358
+ const videoUrl = video.videoUrl;
359
+ if (isHLSSource(videoUrl)) {
360
+ if (Hls.isSupported()) {
361
+ if (this.hls) {
362
+ this.hls.destroy();
363
+ }
364
+ const hls = new Hls({
365
+ enableWorker: true,
366
+ lowLatencyMode: true,
367
+ });
368
+ hls.loadSource(videoUrl);
369
+ hls.attachMedia(this.videoElement);
370
+ hls.on(Hls.Events.MANIFEST_PARSED, () => {
371
+ this.setState({ isLoading: false });
372
+ if (this.elements.loading) {
373
+ this.elements.loading.style.display = 'none';
374
+ }
375
+ if (this.config.autoplay) {
376
+ this.play();
377
+ }
378
+ });
379
+ hls.on(Hls.Events.ERROR, (_event, data) => {
380
+ if (data.fatal) {
381
+ const errorMsg = `HLS Error: ${data.type} - ${data.details}`;
382
+ this.showError(errorMsg);
383
+ this.emit('error', new Error(errorMsg));
384
+ }
385
+ });
386
+ this.hls = hls;
387
+ }
388
+ else if (this.videoElement.canPlayType('application/vnd.apple.mpegurl')) {
389
+ this.videoElement.src = videoUrl;
390
+ this.setState({ isLoading: false });
391
+ if (this.elements.loading) {
392
+ this.elements.loading.style.display = 'none';
393
+ }
394
+ if (this.config.autoplay) {
395
+ this.play();
396
+ }
397
+ }
398
+ else {
399
+ throw new Error('HLS is not supported in this browser');
400
+ }
401
+ }
402
+ else {
403
+ this.videoElement.src = videoUrl;
404
+ this.setState({ isLoading: false });
405
+ if (this.elements.loading) {
406
+ this.elements.loading.style.display = 'none';
407
+ }
408
+ if (this.config.autoplay) {
409
+ this.play();
410
+ }
411
+ }
412
+ }
413
+ catch (err) {
414
+ const errorMsg = err instanceof Error ? err.message : 'Failed to load video';
415
+ this.showError(errorMsg);
416
+ this.setState({ isLoading: false });
417
+ this.emit('error', err instanceof Error ? err : new Error(errorMsg));
418
+ }
419
+ }
420
+ parseWebVTT(webvtt) {
421
+ const cues = [];
422
+ const lines = webvtt.split('\n');
423
+ let i = 0;
424
+ while (i < lines.length) {
425
+ const line = lines[i].trim();
426
+ if (line.includes('-->')) {
427
+ const [startTime, endTime] = line.split('-->').map((t) => t.trim());
428
+ const parseTimestamp = (timestamp) => {
429
+ const parts = timestamp.split(':');
430
+ if (parts.length === 3) {
431
+ const hours = parseFloat(parts[0]);
432
+ const minutes = parseFloat(parts[1]);
433
+ const seconds = parseFloat(parts[2]);
434
+ return hours * 3600 + minutes * 60 + seconds;
435
+ }
436
+ else if (parts.length === 2) {
437
+ const minutes = parseFloat(parts[0]);
438
+ const seconds = parseFloat(parts[1]);
439
+ return minutes * 60 + seconds;
440
+ }
441
+ return 0;
442
+ };
443
+ const start = parseTimestamp(startTime);
444
+ const end = parseTimestamp(endTime);
445
+ i++;
446
+ const textLines = [];
447
+ while (i < lines.length && lines[i].trim() !== '') {
448
+ textLines.push(lines[i].trim());
449
+ i++;
450
+ }
451
+ if (textLines.length > 0) {
452
+ cues.push({
453
+ start,
454
+ end,
455
+ text: textLines.join(' '),
456
+ });
457
+ }
458
+ }
459
+ i++;
460
+ }
461
+ return cues;
462
+ }
463
+ updateOverlayContent(video) {
464
+ const showLogo = this.config.showLogo !== false;
465
+ const showTitle = this.config.showTitle !== false;
466
+ const showAuthor = this.config.showAuthor !== false;
467
+ const showDescription = this.config.showDescription !== false;
468
+ const showCaptions = this.config.showCaptions !== false;
469
+ if (this.elements.logo) {
470
+ this.elements.logo.style.display = showLogo ? 'block' : 'none';
471
+ }
472
+ if (this.elements.videoTitle) {
473
+ this.elements.videoTitle.textContent = video.question || '';
474
+ this.elements.videoTitle.style.display = showTitle && video.question ? 'block' : 'none';
475
+ }
476
+ if (this.elements.videoAuthor) {
477
+ const authorData = video.author || video.creator || video.userName || '';
478
+ this.elements.videoAuthor.textContent = authorData;
479
+ this.elements.videoAuthor.style.display = showAuthor && authorData ? 'block' : 'none';
480
+ }
481
+ if (this.elements.videoDescription) {
482
+ if (video.description) {
483
+ const maxLength = 150;
484
+ const truncated = video.description.length > maxLength ? video.description.substring(0, maxLength) + '...' : video.description;
485
+ this.elements.videoDescription.innerHTML = `
486
+ <span class="jaaq-description-text">${truncated}</span>
487
+ ${video.description.length > maxLength ? '<span class="jaaq-read-more"> Read more</span>' : ''}
488
+ `;
489
+ }
490
+ this.elements.videoDescription.style.display = showDescription && video.description ? 'block' : 'none';
491
+ }
492
+ if (this.elements.captionsBtn) {
493
+ this.elements.captionsBtn.style.display = showCaptions ? 'flex' : 'none';
494
+ }
495
+ }
496
+ attachEventListeners() {
497
+ if (!this.videoElement)
498
+ return;
499
+ this.videoElement.addEventListener('play', () => {
500
+ this.setState({ isPlaying: true });
501
+ this.updatePlayPauseButton();
502
+ if (this.elements.centerPlayBtn) {
503
+ this.elements.centerPlayBtn.style.display = 'none';
504
+ }
505
+ this.emit('play', undefined);
506
+ });
507
+ this.videoElement.addEventListener('pause', () => {
508
+ this.setState({ isPlaying: false });
509
+ this.updatePlayPauseButton();
510
+ if (this.elements.centerPlayBtn) {
511
+ this.elements.centerPlayBtn.style.display = 'flex';
512
+ }
513
+ this.emit('pause', undefined);
514
+ });
515
+ this.videoElement.addEventListener('timeupdate', () => {
516
+ this.setState({ currentTime: this.videoElement.currentTime });
517
+ this.updateProgress();
518
+ this.updateCaptions();
519
+ this.emit('timeupdate', this.videoElement.currentTime);
520
+ });
521
+ this.videoElement.addEventListener('durationchange', () => {
522
+ this.setState({ duration: this.videoElement.duration });
523
+ });
524
+ this.videoElement.addEventListener('volumechange', () => {
525
+ this.setState({
526
+ volume: this.videoElement.volume,
527
+ isMuted: this.videoElement.muted,
528
+ });
529
+ this.updateVolumeUI();
530
+ this.emit('volumechange', this.videoElement.volume);
531
+ });
532
+ this.videoElement.addEventListener('ended', () => {
533
+ this.emit('ended', undefined);
534
+ });
535
+ this.elements.playPauseBtn?.addEventListener('click', () => {
536
+ this.togglePlayPause();
537
+ });
538
+ this.elements.centerPlayBtn?.addEventListener('click', () => {
539
+ this.play();
540
+ if (this.elements.centerPlayBtn) {
541
+ this.elements.centerPlayBtn.style.display = 'none';
542
+ }
543
+ });
544
+ this.elements.progressBar?.addEventListener('click', (e) => {
545
+ this.handleSeek(e);
546
+ });
547
+ this.elements.volumeBtn?.addEventListener('click', () => {
548
+ this.toggleMute();
549
+ });
550
+ this.elements.captionsBtn?.addEventListener('click', () => {
551
+ this.toggleCaptions();
552
+ });
553
+ this.elements.fullscreenBtn?.addEventListener('click', () => {
554
+ this.toggleFullscreen();
555
+ });
556
+ document.addEventListener('fullscreenchange', () => {
557
+ const isFullscreen = !!document.fullscreenElement;
558
+ this.setState({ isFullscreen });
559
+ this.elements.player?.classList.toggle('fullscreen', isFullscreen);
560
+ this.emit('fullscreenchange', isFullscreen);
561
+ });
562
+ this.elements.player?.addEventListener('mousemove', () => {
563
+ this.elements.player?.classList.remove('is-paused');
564
+ });
565
+ this.videoElement.addEventListener('pause', () => {
566
+ this.elements.player?.classList.add('is-paused');
567
+ });
568
+ this.videoElement.addEventListener('play', () => {
569
+ this.elements.player?.classList.remove('is-paused');
570
+ });
571
+ }
572
+ setState(newState) {
573
+ this.state = { ...this.state, ...newState };
574
+ }
575
+ updatePlayPauseButton() {
576
+ if (this.elements.playPauseBtn) {
577
+ this.elements.playPauseBtn.textContent = this.state.isPlaying ? '⏸' : '▶';
578
+ this.elements.playPauseBtn.setAttribute('aria-label', this.state.isPlaying ? 'Pause' : 'Play');
579
+ }
580
+ }
581
+ updateProgress() {
582
+ if (this.elements.progressFilled && this.state.duration > 0) {
583
+ const progress = (this.state.currentTime / this.state.duration) * 100;
584
+ this.elements.progressFilled.style.width = `${progress}%`;
585
+ }
586
+ }
587
+ updateVolumeUI() {
588
+ if (this.elements.volumeBtn) {
589
+ const { isMuted, volume } = this.state;
590
+ if (isMuted || volume === 0) {
591
+ this.elements.volumeBtn.innerHTML = `
592
+ <svg xmlns="http://www.w3.org/2000/svg" width="22" height="20" viewBox="0 0 22 20" fill="none">
593
+ <path d="M11.2168 19.9287L4.20801 13.7031H0V6.22559H4.20898L11.2168 0V19.9287Z" fill="white"/>
594
+ </svg>
595
+ `;
596
+ }
597
+ else {
598
+ this.elements.volumeBtn.innerHTML = `
599
+ <svg xmlns="http://www.w3.org/2000/svg" width="22" height="20" viewBox="0 0 22 20" fill="none">
600
+ <path d="M11.2168 19.9287L4.20801 13.7031H0V6.22559H4.20898L11.2168 0V19.9287ZM14.0215 0.150391C16.2405 0.150468 18.1409 1.39074 19.4385 3.17676C20.7365 4.9634 21.499 7.36811 21.499 9.96484C21.499 12.5613 20.7363 14.9654 19.4385 16.752C18.1409 18.538 16.2405 19.7792 14.0215 19.7793V17.1025C15.2032 17.1025 16.3824 16.4464 17.3135 15.165C18.2442 13.8839 18.8593 12.0493 18.8594 9.96484C18.8594 7.88034 18.2442 6.04581 17.3135 4.76465C16.3824 3.4832 15.2033 2.82723 14.0215 2.82715V0.150391ZM14.0215 5.75879C15.5701 5.75896 16.8252 7.64189 16.8252 9.96484C16.8251 12.2877 15.57 14.1707 14.0215 14.1709V5.75879Z" fill="white"/>
601
+ </svg>
602
+ `;
603
+ }
604
+ }
605
+ }
606
+ updateCaptions() {
607
+ if (!this.elements.captionDisplay || !this.state.captionsEnabled) {
608
+ if (this.elements.captionDisplay) {
609
+ this.elements.captionDisplay.style.display = 'none';
610
+ }
611
+ return;
612
+ }
613
+ const currentTime = this.state.currentTime;
614
+ const currentCue = this.captionCues.find((cue) => currentTime >= cue.start && currentTime <= cue.end);
615
+ if (currentCue) {
616
+ this.elements.captionDisplay.textContent = currentCue.text;
617
+ this.elements.captionDisplay.style.display = 'block';
618
+ }
619
+ else {
620
+ this.elements.captionDisplay.style.display = 'none';
621
+ }
622
+ }
623
+ handleSeek(e) {
624
+ if (!this.videoElement || !this.state.duration || !this.elements.progressBar)
625
+ return;
626
+ const rect = this.elements.progressBar.getBoundingClientRect();
627
+ const percent = (e.clientX - rect.left) / rect.width;
628
+ this.videoElement.currentTime = this.state.duration * clamp$1(percent, 0, 1);
629
+ }
630
+ showError(message) {
631
+ this.setState({ error: message, isLoading: false });
632
+ if (this.elements.error) {
633
+ this.elements.error.textContent = message;
634
+ this.elements.error.style.display = 'block';
635
+ }
636
+ if (this.elements.loading) {
637
+ this.elements.loading.style.display = 'none';
638
+ }
639
+ }
640
+ togglePlayPause() {
641
+ if (this.state.isPlaying) {
642
+ this.pause();
643
+ }
644
+ else {
645
+ this.play();
646
+ }
647
+ }
648
+ toggleCaptions() {
649
+ this.setState({ captionsEnabled: !this.state.captionsEnabled });
650
+ this.updateCaptionsButton();
651
+ this.updateCaptions();
652
+ }
653
+ updateCaptionsButton() {
654
+ if (this.elements.captionsBtn) {
655
+ if (this.state.captionsEnabled) {
656
+ this.elements.captionsBtn.classList.add('active');
657
+ }
658
+ else {
659
+ this.elements.captionsBtn.classList.remove('active');
660
+ }
661
+ }
662
+ }
663
+ toggleFullscreen() {
664
+ if (this.elements.player) {
665
+ toggleFullscreen(this.elements.player);
666
+ }
667
+ }
668
+ /**
669
+ * Starts or resumes video playback
670
+ */
671
+ play() {
672
+ this.videoElement?.play();
673
+ }
674
+ /**
675
+ * Pauses video playback
676
+ */
677
+ pause() {
678
+ this.videoElement?.pause();
679
+ }
680
+ /**
681
+ * Sets the playback volume
682
+ * @param volume - Volume level between 0 (silent) and 1 (maximum)
683
+ */
684
+ setVolume(volume) {
685
+ if (this.videoElement) {
686
+ this.videoElement.volume = clamp$1(volume, 0, 1);
687
+ this.videoElement.muted = volume === 0;
688
+ }
689
+ }
690
+ /**
691
+ * Toggles audio mute state
692
+ */
693
+ toggleMute() {
694
+ if (this.videoElement) {
695
+ this.videoElement.muted = !this.videoElement.muted;
696
+ }
697
+ }
698
+ /**
699
+ * Seeks to a specific time in the video
700
+ * @param time - Target time in seconds
701
+ */
702
+ seek(time) {
703
+ if (this.videoElement) {
704
+ this.videoElement.currentTime = clamp$1(time, 0, this.state.duration);
705
+ }
706
+ }
707
+ setFeatures(features) {
708
+ this.config = { ...this.config, ...features };
709
+ if (features.controls !== undefined) {
710
+ this.updateControlsVisibility();
711
+ }
712
+ if (this.state.videoData) {
713
+ this.updateOverlayContent(this.state.videoData);
714
+ }
715
+ else {
716
+ if (features.showLogo !== undefined && this.elements.logo) {
717
+ this.elements.logo.style.display = features.showLogo ? 'block' : 'none';
718
+ }
719
+ if (features.showCaptions !== undefined && this.elements.captionsBtn) {
720
+ this.elements.captionsBtn.style.display = features.showCaptions ? 'flex' : 'none';
721
+ }
722
+ }
723
+ }
724
+ /**
725
+ * Returns a copy of the current player state
726
+ * @returns Current player state object
727
+ */
728
+ getState() {
729
+ return { ...this.state };
730
+ }
731
+ /**
732
+ * Registers an event listener for player events
733
+ * @param event - Event name to listen for
734
+ * @param callback - Function to call when event fires
735
+ */
736
+ on(event, callback) {
737
+ if (!this.listeners.has(event)) {
738
+ this.listeners.set(event, new Set());
739
+ }
740
+ this.listeners.get(event).add(callback);
741
+ }
742
+ /**
743
+ * Removes an event listener for player events
744
+ * @param event - Event name to stop listening for
745
+ * @param callback - Function to remove from listeners
746
+ */
747
+ off(event, callback) {
748
+ const callbacks = this.listeners.get(event);
749
+ if (callbacks) {
750
+ callbacks.delete(callback);
751
+ }
752
+ }
753
+ emit(event, data) {
754
+ const callbacks = this.listeners.get(event);
755
+ if (callbacks) {
756
+ callbacks.forEach((callback) => callback(data));
757
+ }
758
+ }
759
+ /**
760
+ * Destroys the player instance and cleans up resources
761
+ * Removes all event listeners, stops playback, and clears the DOM
762
+ */
763
+ destroy() {
764
+ if (this.hls) {
765
+ this.hls.destroy();
766
+ this.hls = null;
767
+ }
768
+ if (this.videoElement) {
769
+ this.videoElement.pause();
770
+ this.videoElement.src = '';
771
+ this.videoElement = null;
772
+ }
773
+ this.listeners.clear();
774
+ this.container.innerHTML = '';
775
+ }
776
+ }
777
+
778
+ const COMPONENT_STYLES$1 = `
779
+ :host {
780
+ display: block;
781
+ width: 100%;
782
+ }
783
+
784
+ :host([hidden]) {
785
+ display: none;
786
+ }
787
+ `;
788
+ /**
789
+ * Custom web component for JAAQ video player with Shadow DOM encapsulation
790
+ * Provides a framework-agnostic video player with custom controls and HLS support
791
+ *
792
+ * @example
793
+ * // Declarative usage
794
+ * <jaaq-video-player
795
+ * video-id="video-123"
796
+ * api-key="key"
797
+ * client-id="client"
798
+ * autoplay="false">
799
+ * </jaaq-video-player>
800
+ *
801
+ * @example
802
+ * // Programmatic usage
803
+ * const player = document.createElement('jaaq-video-player');
804
+ * player.setAttribute('video-id', 'video-123');
805
+ * player.addEventListener('jaaq:play', () => console.log('Playing'));
806
+ * document.body.appendChild(player);
807
+ */
808
+ class JaaqVideoPlayerElement extends HTMLElement {
809
+ static get observedAttributes() {
810
+ return [
811
+ 'video-id',
812
+ 'api-key',
813
+ 'client-id',
814
+ 'autoplay',
815
+ 'base-url',
816
+ 'width',
817
+ 'height',
818
+ 'controls',
819
+ 'show-logo',
820
+ 'show-title',
821
+ 'show-author',
822
+ 'show-description',
823
+ 'show-captions',
824
+ ];
825
+ }
826
+ constructor() {
827
+ super();
828
+ this.player = null;
829
+ this.container = null;
830
+ this.clientInstance = null;
831
+ this.connected = false;
832
+ this.attachShadow({ mode: 'open' });
833
+ }
834
+ connectedCallback() {
835
+ this.connected = true;
836
+ this.render();
837
+ this.initPlayer();
838
+ }
839
+ disconnectedCallback() {
840
+ this.connected = false;
841
+ this.destroyPlayer();
842
+ }
843
+ attributeChangedCallback(name, oldValue, newValue) {
844
+ if (!this.connected || oldValue === newValue)
845
+ return;
846
+ if (name === 'video-id' && this.player) {
847
+ this.destroyPlayer();
848
+ this.initPlayer();
849
+ }
850
+ else if (name === 'width' || name === 'height') {
851
+ this.updateContainerStyles();
852
+ }
853
+ else if (name === 'controls' ||
854
+ name === 'show-logo' ||
855
+ name === 'show-title' ||
856
+ name === 'show-author' ||
857
+ name === 'show-description' ||
858
+ name === 'show-captions') {
859
+ if (this.player) {
860
+ const features = {};
861
+ if (name === 'controls') {
862
+ features.controls = !this.hasAttribute('controls') || this.getAttribute('controls') !== 'false';
863
+ }
864
+ else if (name === 'show-logo') {
865
+ features.showLogo = !this.hasAttribute('show-logo') || this.getAttribute('show-logo') !== 'false';
866
+ }
867
+ else if (name === 'show-title') {
868
+ features.showTitle = !this.hasAttribute('show-title') || this.getAttribute('show-title') !== 'false';
869
+ }
870
+ else if (name === 'show-author') {
871
+ features.showAuthor = !this.hasAttribute('show-author') || this.getAttribute('show-author') !== 'false';
872
+ }
873
+ else if (name === 'show-description') {
874
+ features.showDescription = !this.hasAttribute('show-description') || this.getAttribute('show-description') !== 'false';
875
+ }
876
+ else if (name === 'show-captions') {
877
+ features.showCaptions = !this.hasAttribute('show-captions') || this.getAttribute('show-captions') !== 'false';
878
+ }
879
+ this.player.setFeatures(features);
880
+ }
881
+ }
882
+ }
883
+ render() {
884
+ if (!this.shadowRoot)
885
+ return;
886
+ const styleSheet = document.createElement('style');
887
+ styleSheet.textContent = `
888
+ ${sharedStyles}
889
+ ${vanillaStyles}
890
+ ${COMPONENT_STYLES$1}
891
+ `;
892
+ this.container = document.createElement('div');
893
+ this.container.className = 'jaaq-webcomponent-container';
894
+ this.shadowRoot.appendChild(styleSheet);
895
+ this.shadowRoot.appendChild(this.container);
896
+ this.updateContainerStyles();
897
+ }
898
+ updateContainerStyles() {
899
+ if (!this.container)
900
+ return;
901
+ const width = this.getAttribute('width') || '100%';
902
+ const height = this.getAttribute('height') || 'auto';
903
+ this.container.style.width = width;
904
+ this.container.style.height = height;
905
+ }
906
+ async initPlayer() {
907
+ if (!this.container || this.player)
908
+ return;
909
+ const videoId = this.getAttribute('video-id');
910
+ if (!videoId) {
911
+ this.emitError(new Error('video-id attribute is required'));
912
+ return;
913
+ }
914
+ const apiKey = this.getAttribute('api-key');
915
+ const clientId = this.getAttribute('client-id');
916
+ const baseUrl = this.getAttribute('base-url') || undefined;
917
+ const autoplay = this.hasAttribute('autoplay') && this.getAttribute('autoplay') !== 'false';
918
+ const controls = !this.hasAttribute('controls') || this.getAttribute('controls') !== 'false';
919
+ const showLogo = !this.hasAttribute('show-logo') || this.getAttribute('show-logo') !== 'false';
920
+ const showTitle = !this.hasAttribute('show-title') || this.getAttribute('show-title') !== 'false';
921
+ const showAuthor = !this.hasAttribute('show-author') || this.getAttribute('show-author') !== 'false';
922
+ const showDescription = !this.hasAttribute('show-description') || this.getAttribute('show-description') !== 'false';
923
+ const showCaptions = !this.hasAttribute('show-captions') || this.getAttribute('show-captions') !== 'false';
924
+ if (!this.clientInstance && !apiKey && !clientId) {
925
+ this.emitError(new Error('Either client property or api-key and client-id attributes are required'));
926
+ return;
927
+ }
928
+ try {
929
+ this.player = new JaaqVideoPlayer(this.container, {
930
+ videoId: videoId ?? undefined,
931
+ apiKey: apiKey ?? undefined,
932
+ clientId: clientId ?? undefined,
933
+ client: this.clientInstance || undefined,
934
+ baseUrl,
935
+ autoplay,
936
+ controls,
937
+ showLogo,
938
+ showTitle,
939
+ showAuthor,
940
+ showDescription,
941
+ showCaptions,
942
+ });
943
+ this.attachPlayerEvents();
944
+ }
945
+ catch (error) {
946
+ this.emitError(error instanceof Error ? error : new Error('Failed to initialize player'));
947
+ }
948
+ }
949
+ attachPlayerEvents() {
950
+ if (!this.player)
951
+ return;
952
+ this.player.on('loaded', (video) => {
953
+ this.dispatchEvent(new CustomEvent('jaaq:loaded', {
954
+ detail: video,
955
+ bubbles: true,
956
+ composed: true,
957
+ }));
958
+ });
959
+ this.player.on('play', () => {
960
+ this.dispatchEvent(new CustomEvent('jaaq:play', {
961
+ bubbles: true,
962
+ composed: true,
963
+ }));
964
+ });
965
+ this.player.on('pause', () => {
966
+ this.dispatchEvent(new CustomEvent('jaaq:pause', {
967
+ bubbles: true,
968
+ composed: true,
969
+ }));
970
+ });
971
+ this.player.on('timeupdate', (time) => {
972
+ this.dispatchEvent(new CustomEvent('jaaq:timeupdate', {
973
+ detail: time,
974
+ bubbles: true,
975
+ composed: true,
976
+ }));
977
+ });
978
+ this.player.on('volumechange', (volume) => {
979
+ this.dispatchEvent(new CustomEvent('jaaq:volumechange', {
980
+ detail: volume,
981
+ bubbles: true,
982
+ composed: true,
983
+ }));
984
+ });
985
+ this.player.on('ended', () => {
986
+ this.dispatchEvent(new CustomEvent('jaaq:ended', {
987
+ bubbles: true,
988
+ composed: true,
989
+ }));
990
+ });
991
+ this.player.on('error', (error) => {
992
+ this.emitError(error);
993
+ });
994
+ this.player.on('fullscreenchange', (isFullscreen) => {
995
+ this.dispatchEvent(new CustomEvent('jaaq:fullscreenchange', {
996
+ detail: isFullscreen,
997
+ bubbles: true,
998
+ composed: true,
999
+ }));
1000
+ });
1001
+ }
1002
+ emitError(error) {
1003
+ this.dispatchEvent(new CustomEvent('jaaq:error', {
1004
+ detail: error,
1005
+ bubbles: true,
1006
+ composed: true,
1007
+ }));
1008
+ }
1009
+ destroyPlayer() {
1010
+ if (this.player) {
1011
+ this.player.destroy();
1012
+ this.player = null;
1013
+ }
1014
+ }
1015
+ /**
1016
+ * Gets the current JaaqClient instance
1017
+ */
1018
+ get client() {
1019
+ return this.clientInstance;
1020
+ }
1021
+ /**
1022
+ * Sets a JaaqClient instance for the player to use
1023
+ * Reinitializes the player if already connected
1024
+ */
1025
+ set client(value) {
1026
+ this.clientInstance = value;
1027
+ if (this.connected) {
1028
+ this.destroyPlayer();
1029
+ this.initPlayer();
1030
+ }
1031
+ }
1032
+ /**
1033
+ * Gets the current video ID
1034
+ */
1035
+ get videoId() {
1036
+ return this.getAttribute('video-id');
1037
+ }
1038
+ /**
1039
+ * Sets the video ID
1040
+ * Updates the video-id attribute and triggers player reinitialization
1041
+ */
1042
+ set videoId(value) {
1043
+ if (value) {
1044
+ this.setAttribute('video-id', value);
1045
+ }
1046
+ else {
1047
+ this.removeAttribute('video-id');
1048
+ }
1049
+ }
1050
+ /**
1051
+ * Starts or resumes video playback
1052
+ */
1053
+ play() {
1054
+ this.player?.play();
1055
+ }
1056
+ /**
1057
+ * Pauses video playback
1058
+ */
1059
+ pause() {
1060
+ this.player?.pause();
1061
+ }
1062
+ /**
1063
+ * Sets the playback volume
1064
+ * @param volume - Volume level between 0 (silent) and 1 (maximum)
1065
+ */
1066
+ setVolume(volume) {
1067
+ this.player?.setVolume(volume);
1068
+ }
1069
+ /**
1070
+ * Toggles audio mute state
1071
+ */
1072
+ toggleMute() {
1073
+ this.player?.toggleMute();
1074
+ }
1075
+ /**
1076
+ * Seeks to a specific time in the video
1077
+ * @param time - Target time in seconds
1078
+ */
1079
+ seek(time) {
1080
+ this.player?.seek(time);
1081
+ }
1082
+ /**
1083
+ * Returns the current player state
1084
+ * @returns Current player state object or null if player not initialized
1085
+ */
1086
+ getState() {
1087
+ return this.player?.getState() || null;
1088
+ }
1089
+ /**
1090
+ * Destroys the player instance and cleans up resources
1091
+ */
1092
+ destroy() {
1093
+ this.destroyPlayer();
1094
+ }
1095
+ }
1096
+
1097
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
1098
+
1099
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1100
+
1101
+ /*!
1102
+ * Splide.js
1103
+ * Version : 4.1.4
1104
+ * License : MIT
1105
+ * Copyright: 2022 Naotoshi Fujita
1106
+ */
1107
+ var MEDIA_PREFERS_REDUCED_MOTION = "(prefers-reduced-motion: reduce)";
1108
+ var CREATED = 1;
1109
+ var MOUNTED = 2;
1110
+ var IDLE = 3;
1111
+ var MOVING = 4;
1112
+ var SCROLLING = 5;
1113
+ var DRAGGING = 6;
1114
+ var DESTROYED = 7;
1115
+ var STATES = {
1116
+ CREATED: CREATED,
1117
+ MOUNTED: MOUNTED,
1118
+ IDLE: IDLE,
1119
+ MOVING: MOVING,
1120
+ SCROLLING: SCROLLING,
1121
+ DRAGGING: DRAGGING,
1122
+ DESTROYED: DESTROYED
1123
+ };
1124
+
1125
+ function empty(array) {
1126
+ array.length = 0;
1127
+ }
1128
+
1129
+ function slice(arrayLike, start, end) {
1130
+ return Array.prototype.slice.call(arrayLike, start, end);
1131
+ }
1132
+
1133
+ function apply(func) {
1134
+ return func.bind.apply(func, [null].concat(slice(arguments, 1)));
1135
+ }
1136
+
1137
+ var nextTick = setTimeout;
1138
+
1139
+ var noop = function noop() {};
1140
+
1141
+ function raf(func) {
1142
+ return requestAnimationFrame(func);
1143
+ }
1144
+
1145
+ function typeOf(type, subject) {
1146
+ return typeof subject === type;
1147
+ }
1148
+
1149
+ function isObject(subject) {
1150
+ return !isNull(subject) && typeOf("object", subject);
1151
+ }
1152
+
1153
+ var isArray = Array.isArray;
1154
+ var isFunction = apply(typeOf, "function");
1155
+ var isString = apply(typeOf, "string");
1156
+ var isUndefined = apply(typeOf, "undefined");
1157
+
1158
+ function isNull(subject) {
1159
+ return subject === null;
1160
+ }
1161
+
1162
+ function isHTMLElement(subject) {
1163
+ try {
1164
+ return subject instanceof (subject.ownerDocument.defaultView || window).HTMLElement;
1165
+ } catch (e) {
1166
+ return false;
1167
+ }
1168
+ }
1169
+
1170
+ function toArray(value) {
1171
+ return isArray(value) ? value : [value];
1172
+ }
1173
+
1174
+ function forEach(values, iteratee) {
1175
+ toArray(values).forEach(iteratee);
1176
+ }
1177
+
1178
+ function includes(array, value) {
1179
+ return array.indexOf(value) > -1;
1180
+ }
1181
+
1182
+ function push(array, items) {
1183
+ array.push.apply(array, toArray(items));
1184
+ return array;
1185
+ }
1186
+
1187
+ function toggleClass(elm, classes, add) {
1188
+ if (elm) {
1189
+ forEach(classes, function (name) {
1190
+ if (name) {
1191
+ elm.classList[add ? "add" : "remove"](name);
1192
+ }
1193
+ });
1194
+ }
1195
+ }
1196
+
1197
+ function addClass(elm, classes) {
1198
+ toggleClass(elm, isString(classes) ? classes.split(" ") : classes, true);
1199
+ }
1200
+
1201
+ function append(parent, children) {
1202
+ forEach(children, parent.appendChild.bind(parent));
1203
+ }
1204
+
1205
+ function before(nodes, ref) {
1206
+ forEach(nodes, function (node) {
1207
+ var parent = (ref || node).parentNode;
1208
+
1209
+ if (parent) {
1210
+ parent.insertBefore(node, ref);
1211
+ }
1212
+ });
1213
+ }
1214
+
1215
+ function matches(elm, selector) {
1216
+ return isHTMLElement(elm) && (elm["msMatchesSelector"] || elm.matches).call(elm, selector);
1217
+ }
1218
+
1219
+ function children(parent, selector) {
1220
+ var children2 = parent ? slice(parent.children) : [];
1221
+ return selector ? children2.filter(function (child) {
1222
+ return matches(child, selector);
1223
+ }) : children2;
1224
+ }
1225
+
1226
+ function child(parent, selector) {
1227
+ return selector ? children(parent, selector)[0] : parent.firstElementChild;
1228
+ }
1229
+
1230
+ var ownKeys = Object.keys;
1231
+
1232
+ function forOwn(object, iteratee, right) {
1233
+ if (object) {
1234
+ (right ? ownKeys(object).reverse() : ownKeys(object)).forEach(function (key) {
1235
+ key !== "__proto__" && iteratee(object[key], key);
1236
+ });
1237
+ }
1238
+
1239
+ return object;
1240
+ }
1241
+
1242
+ function assign(object) {
1243
+ slice(arguments, 1).forEach(function (source) {
1244
+ forOwn(source, function (value, key) {
1245
+ object[key] = source[key];
1246
+ });
1247
+ });
1248
+ return object;
1249
+ }
1250
+
1251
+ function merge(object) {
1252
+ slice(arguments, 1).forEach(function (source) {
1253
+ forOwn(source, function (value, key) {
1254
+ if (isArray(value)) {
1255
+ object[key] = value.slice();
1256
+ } else if (isObject(value)) {
1257
+ object[key] = merge({}, isObject(object[key]) ? object[key] : {}, value);
1258
+ } else {
1259
+ object[key] = value;
1260
+ }
1261
+ });
1262
+ });
1263
+ return object;
1264
+ }
1265
+
1266
+ function omit(object, keys) {
1267
+ forEach(keys || ownKeys(object), function (key) {
1268
+ delete object[key];
1269
+ });
1270
+ }
1271
+
1272
+ function removeAttribute(elms, attrs) {
1273
+ forEach(elms, function (elm) {
1274
+ forEach(attrs, function (attr) {
1275
+ elm && elm.removeAttribute(attr);
1276
+ });
1277
+ });
1278
+ }
1279
+
1280
+ function setAttribute(elms, attrs, value) {
1281
+ if (isObject(attrs)) {
1282
+ forOwn(attrs, function (value2, name) {
1283
+ setAttribute(elms, name, value2);
1284
+ });
1285
+ } else {
1286
+ forEach(elms, function (elm) {
1287
+ isNull(value) || value === "" ? removeAttribute(elm, attrs) : elm.setAttribute(attrs, String(value));
1288
+ });
1289
+ }
1290
+ }
1291
+
1292
+ function create(tag, attrs, parent) {
1293
+ var elm = document.createElement(tag);
1294
+
1295
+ if (attrs) {
1296
+ isString(attrs) ? addClass(elm, attrs) : setAttribute(elm, attrs);
1297
+ }
1298
+
1299
+ parent && append(parent, elm);
1300
+ return elm;
1301
+ }
1302
+
1303
+ function style(elm, prop, value) {
1304
+ if (isUndefined(value)) {
1305
+ return getComputedStyle(elm)[prop];
1306
+ }
1307
+
1308
+ if (!isNull(value)) {
1309
+ elm.style[prop] = "" + value;
1310
+ }
1311
+ }
1312
+
1313
+ function display(elm, display2) {
1314
+ style(elm, "display", display2);
1315
+ }
1316
+
1317
+ function focus(elm) {
1318
+ elm["setActive"] && elm["setActive"]() || elm.focus({
1319
+ preventScroll: true
1320
+ });
1321
+ }
1322
+
1323
+ function getAttribute(elm, attr) {
1324
+ return elm.getAttribute(attr);
1325
+ }
1326
+
1327
+ function hasClass(elm, className) {
1328
+ return elm && elm.classList.contains(className);
1329
+ }
1330
+
1331
+ function rect(target) {
1332
+ return target.getBoundingClientRect();
1333
+ }
1334
+
1335
+ function remove(nodes) {
1336
+ forEach(nodes, function (node) {
1337
+ if (node && node.parentNode) {
1338
+ node.parentNode.removeChild(node);
1339
+ }
1340
+ });
1341
+ }
1342
+
1343
+ function parseHtml(html) {
1344
+ return child(new DOMParser().parseFromString(html, "text/html").body);
1345
+ }
1346
+
1347
+ function prevent(e, stopPropagation) {
1348
+ e.preventDefault();
1349
+
1350
+ if (stopPropagation) {
1351
+ e.stopPropagation();
1352
+ e.stopImmediatePropagation();
1353
+ }
1354
+ }
1355
+
1356
+ function query(parent, selector) {
1357
+ return parent && parent.querySelector(selector);
1358
+ }
1359
+
1360
+ function queryAll(parent, selector) {
1361
+ return selector ? slice(parent.querySelectorAll(selector)) : [];
1362
+ }
1363
+
1364
+ function removeClass(elm, classes) {
1365
+ toggleClass(elm, classes, false);
1366
+ }
1367
+
1368
+ function timeOf(e) {
1369
+ return e.timeStamp;
1370
+ }
1371
+
1372
+ function unit(value) {
1373
+ return isString(value) ? value : value ? value + "px" : "";
1374
+ }
1375
+
1376
+ var PROJECT_CODE = "splide";
1377
+ var DATA_ATTRIBUTE = "data-" + PROJECT_CODE;
1378
+
1379
+ function assert(condition, message) {
1380
+ if (!condition) {
1381
+ throw new Error("[" + PROJECT_CODE + "] " + (message || ""));
1382
+ }
1383
+ }
1384
+
1385
+ var min = Math.min,
1386
+ max = Math.max,
1387
+ floor = Math.floor,
1388
+ ceil = Math.ceil,
1389
+ abs = Math.abs;
1390
+
1391
+ function approximatelyEqual(x, y, epsilon) {
1392
+ return abs(x - y) < epsilon;
1393
+ }
1394
+
1395
+ function between(number, x, y, exclusive) {
1396
+ var minimum = min(x, y);
1397
+ var maximum = max(x, y);
1398
+ return exclusive ? minimum < number && number < maximum : minimum <= number && number <= maximum;
1399
+ }
1400
+
1401
+ function clamp(number, x, y) {
1402
+ var minimum = min(x, y);
1403
+ var maximum = max(x, y);
1404
+ return min(max(minimum, number), maximum);
1405
+ }
1406
+
1407
+ function sign(x) {
1408
+ return +(x > 0) - +(x < 0);
1409
+ }
1410
+
1411
+ function format(string, replacements) {
1412
+ forEach(replacements, function (replacement) {
1413
+ string = string.replace("%s", "" + replacement);
1414
+ });
1415
+ return string;
1416
+ }
1417
+
1418
+ function pad(number) {
1419
+ return number < 10 ? "0" + number : "" + number;
1420
+ }
1421
+
1422
+ var ids = {};
1423
+
1424
+ function uniqueId(prefix) {
1425
+ return "" + prefix + pad(ids[prefix] = (ids[prefix] || 0) + 1);
1426
+ }
1427
+
1428
+ function EventBinder() {
1429
+ var listeners = [];
1430
+
1431
+ function bind(targets, events, callback, options) {
1432
+ forEachEvent(targets, events, function (target, event, namespace) {
1433
+ var isEventTarget = ("addEventListener" in target);
1434
+ var remover = isEventTarget ? target.removeEventListener.bind(target, event, callback, options) : target["removeListener"].bind(target, callback);
1435
+ isEventTarget ? target.addEventListener(event, callback, options) : target["addListener"](callback);
1436
+ listeners.push([target, event, namespace, callback, remover]);
1437
+ });
1438
+ }
1439
+
1440
+ function unbind(targets, events, callback) {
1441
+ forEachEvent(targets, events, function (target, event, namespace) {
1442
+ listeners = listeners.filter(function (listener) {
1443
+ if (listener[0] === target && listener[1] === event && listener[2] === namespace && (!callback || listener[3] === callback)) {
1444
+ listener[4]();
1445
+ return false;
1446
+ }
1447
+
1448
+ return true;
1449
+ });
1450
+ });
1451
+ }
1452
+
1453
+ function dispatch(target, type, detail) {
1454
+ var e;
1455
+ var bubbles = true;
1456
+
1457
+ if (typeof CustomEvent === "function") {
1458
+ e = new CustomEvent(type, {
1459
+ bubbles: bubbles,
1460
+ detail: detail
1461
+ });
1462
+ } else {
1463
+ e = document.createEvent("CustomEvent");
1464
+ e.initCustomEvent(type, bubbles, false, detail);
1465
+ }
1466
+
1467
+ target.dispatchEvent(e);
1468
+ return e;
1469
+ }
1470
+
1471
+ function forEachEvent(targets, events, iteratee) {
1472
+ forEach(targets, function (target) {
1473
+ target && forEach(events, function (events2) {
1474
+ events2.split(" ").forEach(function (eventNS) {
1475
+ var fragment = eventNS.split(".");
1476
+ iteratee(target, fragment[0], fragment[1]);
1477
+ });
1478
+ });
1479
+ });
1480
+ }
1481
+
1482
+ function destroy() {
1483
+ listeners.forEach(function (data) {
1484
+ data[4]();
1485
+ });
1486
+ empty(listeners);
1487
+ }
1488
+
1489
+ return {
1490
+ bind: bind,
1491
+ unbind: unbind,
1492
+ dispatch: dispatch,
1493
+ destroy: destroy
1494
+ };
1495
+ }
1496
+
1497
+ var EVENT_MOUNTED = "mounted";
1498
+ var EVENT_READY = "ready";
1499
+ var EVENT_MOVE = "move";
1500
+ var EVENT_MOVED = "moved";
1501
+ var EVENT_CLICK = "click";
1502
+ var EVENT_ACTIVE = "active";
1503
+ var EVENT_INACTIVE = "inactive";
1504
+ var EVENT_VISIBLE = "visible";
1505
+ var EVENT_HIDDEN = "hidden";
1506
+ var EVENT_REFRESH = "refresh";
1507
+ var EVENT_UPDATED = "updated";
1508
+ var EVENT_RESIZE = "resize";
1509
+ var EVENT_RESIZED = "resized";
1510
+ var EVENT_DRAG = "drag";
1511
+ var EVENT_DRAGGING = "dragging";
1512
+ var EVENT_DRAGGED = "dragged";
1513
+ var EVENT_SCROLL = "scroll";
1514
+ var EVENT_SCROLLED = "scrolled";
1515
+ var EVENT_OVERFLOW = "overflow";
1516
+ var EVENT_DESTROY = "destroy";
1517
+ var EVENT_ARROWS_MOUNTED = "arrows:mounted";
1518
+ var EVENT_ARROWS_UPDATED = "arrows:updated";
1519
+ var EVENT_PAGINATION_MOUNTED = "pagination:mounted";
1520
+ var EVENT_PAGINATION_UPDATED = "pagination:updated";
1521
+ var EVENT_NAVIGATION_MOUNTED = "navigation:mounted";
1522
+ var EVENT_AUTOPLAY_PLAY = "autoplay:play";
1523
+ var EVENT_AUTOPLAY_PLAYING = "autoplay:playing";
1524
+ var EVENT_AUTOPLAY_PAUSE = "autoplay:pause";
1525
+ var EVENT_LAZYLOAD_LOADED = "lazyload:loaded";
1526
+ var EVENT_SLIDE_KEYDOWN = "sk";
1527
+ var EVENT_SHIFTED = "sh";
1528
+ var EVENT_END_INDEX_CHANGED = "ei";
1529
+
1530
+ function EventInterface(Splide2) {
1531
+ var bus = Splide2 ? Splide2.event.bus : document.createDocumentFragment();
1532
+ var binder = EventBinder();
1533
+
1534
+ function on(events, callback) {
1535
+ binder.bind(bus, toArray(events).join(" "), function (e) {
1536
+ callback.apply(callback, isArray(e.detail) ? e.detail : []);
1537
+ });
1538
+ }
1539
+
1540
+ function emit(event) {
1541
+ binder.dispatch(bus, event, slice(arguments, 1));
1542
+ }
1543
+
1544
+ if (Splide2) {
1545
+ Splide2.event.on(EVENT_DESTROY, binder.destroy);
1546
+ }
1547
+
1548
+ return assign(binder, {
1549
+ bus: bus,
1550
+ on: on,
1551
+ off: apply(binder.unbind, bus),
1552
+ emit: emit
1553
+ });
1554
+ }
1555
+
1556
+ function RequestInterval(interval, onInterval, onUpdate, limit) {
1557
+ var now = Date.now;
1558
+ var startTime;
1559
+ var rate = 0;
1560
+ var id;
1561
+ var paused = true;
1562
+ var count = 0;
1563
+
1564
+ function update() {
1565
+ if (!paused) {
1566
+ rate = interval ? min((now() - startTime) / interval, 1) : 1;
1567
+ onUpdate && onUpdate(rate);
1568
+
1569
+ if (rate >= 1) {
1570
+ onInterval();
1571
+ startTime = now();
1572
+
1573
+ if (limit && ++count >= limit) {
1574
+ return pause();
1575
+ }
1576
+ }
1577
+
1578
+ id = raf(update);
1579
+ }
1580
+ }
1581
+
1582
+ function start(resume) {
1583
+ resume || cancel();
1584
+ startTime = now() - (resume ? rate * interval : 0);
1585
+ paused = false;
1586
+ id = raf(update);
1587
+ }
1588
+
1589
+ function pause() {
1590
+ paused = true;
1591
+ }
1592
+
1593
+ function rewind() {
1594
+ startTime = now();
1595
+ rate = 0;
1596
+
1597
+ if (onUpdate) {
1598
+ onUpdate(rate);
1599
+ }
1600
+ }
1601
+
1602
+ function cancel() {
1603
+ id && cancelAnimationFrame(id);
1604
+ rate = 0;
1605
+ id = 0;
1606
+ paused = true;
1607
+ }
1608
+
1609
+ function set(time) {
1610
+ interval = time;
1611
+ }
1612
+
1613
+ function isPaused() {
1614
+ return paused;
1615
+ }
1616
+
1617
+ return {
1618
+ start: start,
1619
+ rewind: rewind,
1620
+ pause: pause,
1621
+ cancel: cancel,
1622
+ set: set,
1623
+ isPaused: isPaused
1624
+ };
1625
+ }
1626
+
1627
+ function State(initialState) {
1628
+ var state = initialState;
1629
+
1630
+ function set(value) {
1631
+ state = value;
1632
+ }
1633
+
1634
+ function is(states) {
1635
+ return includes(toArray(states), state);
1636
+ }
1637
+
1638
+ return {
1639
+ set: set,
1640
+ is: is
1641
+ };
1642
+ }
1643
+
1644
+ function Throttle(func, duration) {
1645
+ var interval = RequestInterval(0, func, null, 1);
1646
+ return function () {
1647
+ interval.isPaused() && interval.start();
1648
+ };
1649
+ }
1650
+
1651
+ function Media(Splide2, Components2, options) {
1652
+ var state = Splide2.state;
1653
+ var breakpoints = options.breakpoints || {};
1654
+ var reducedMotion = options.reducedMotion || {};
1655
+ var binder = EventBinder();
1656
+ var queries = [];
1657
+
1658
+ function setup() {
1659
+ var isMin = options.mediaQuery === "min";
1660
+ ownKeys(breakpoints).sort(function (n, m) {
1661
+ return isMin ? +n - +m : +m - +n;
1662
+ }).forEach(function (key) {
1663
+ register(breakpoints[key], "(" + (isMin ? "min" : "max") + "-width:" + key + "px)");
1664
+ });
1665
+ register(reducedMotion, MEDIA_PREFERS_REDUCED_MOTION);
1666
+ update();
1667
+ }
1668
+
1669
+ function destroy(completely) {
1670
+ if (completely) {
1671
+ binder.destroy();
1672
+ }
1673
+ }
1674
+
1675
+ function register(options2, query) {
1676
+ var queryList = matchMedia(query);
1677
+ binder.bind(queryList, "change", update);
1678
+ queries.push([options2, queryList]);
1679
+ }
1680
+
1681
+ function update() {
1682
+ var destroyed = state.is(DESTROYED);
1683
+ var direction = options.direction;
1684
+ var merged = queries.reduce(function (merged2, entry) {
1685
+ return merge(merged2, entry[1].matches ? entry[0] : {});
1686
+ }, {});
1687
+ omit(options);
1688
+ set(merged);
1689
+
1690
+ if (options.destroy) {
1691
+ Splide2.destroy(options.destroy === "completely");
1692
+ } else if (destroyed) {
1693
+ destroy(true);
1694
+ Splide2.mount();
1695
+ } else {
1696
+ direction !== options.direction && Splide2.refresh();
1697
+ }
1698
+ }
1699
+
1700
+ function reduce(enable) {
1701
+ if (matchMedia(MEDIA_PREFERS_REDUCED_MOTION).matches) {
1702
+ enable ? merge(options, reducedMotion) : omit(options, ownKeys(reducedMotion));
1703
+ }
1704
+ }
1705
+
1706
+ function set(opts, base, notify) {
1707
+ merge(options, opts);
1708
+ base && merge(Object.getPrototypeOf(options), opts);
1709
+
1710
+ if (notify || !state.is(CREATED)) {
1711
+ Splide2.emit(EVENT_UPDATED, options);
1712
+ }
1713
+ }
1714
+
1715
+ return {
1716
+ setup: setup,
1717
+ destroy: destroy,
1718
+ reduce: reduce,
1719
+ set: set
1720
+ };
1721
+ }
1722
+
1723
+ var ARROW = "Arrow";
1724
+ var ARROW_LEFT = ARROW + "Left";
1725
+ var ARROW_RIGHT = ARROW + "Right";
1726
+ var ARROW_UP = ARROW + "Up";
1727
+ var ARROW_DOWN = ARROW + "Down";
1728
+ var RTL = "rtl";
1729
+ var TTB = "ttb";
1730
+ var ORIENTATION_MAP = {
1731
+ width: ["height"],
1732
+ left: ["top", "right"],
1733
+ right: ["bottom", "left"],
1734
+ x: ["y"],
1735
+ X: ["Y"],
1736
+ Y: ["X"],
1737
+ ArrowLeft: [ARROW_UP, ARROW_RIGHT],
1738
+ ArrowRight: [ARROW_DOWN, ARROW_LEFT]
1739
+ };
1740
+
1741
+ function Direction(Splide2, Components2, options) {
1742
+ function resolve(prop, axisOnly, direction) {
1743
+ direction = direction || options.direction;
1744
+ var index = direction === RTL && !axisOnly ? 1 : direction === TTB ? 0 : -1;
1745
+ return ORIENTATION_MAP[prop] && ORIENTATION_MAP[prop][index] || prop.replace(/width|left|right/i, function (match, offset) {
1746
+ var replacement = ORIENTATION_MAP[match.toLowerCase()][index] || match;
1747
+ return offset > 0 ? replacement.charAt(0).toUpperCase() + replacement.slice(1) : replacement;
1748
+ });
1749
+ }
1750
+
1751
+ function orient(value) {
1752
+ return value * (options.direction === RTL ? 1 : -1);
1753
+ }
1754
+
1755
+ return {
1756
+ resolve: resolve,
1757
+ orient: orient
1758
+ };
1759
+ }
1760
+
1761
+ var ROLE = "role";
1762
+ var TAB_INDEX = "tabindex";
1763
+ var DISABLED = "disabled";
1764
+ var ARIA_PREFIX = "aria-";
1765
+ var ARIA_CONTROLS = ARIA_PREFIX + "controls";
1766
+ var ARIA_CURRENT = ARIA_PREFIX + "current";
1767
+ var ARIA_SELECTED = ARIA_PREFIX + "selected";
1768
+ var ARIA_LABEL = ARIA_PREFIX + "label";
1769
+ var ARIA_LABELLEDBY = ARIA_PREFIX + "labelledby";
1770
+ var ARIA_HIDDEN = ARIA_PREFIX + "hidden";
1771
+ var ARIA_ORIENTATION = ARIA_PREFIX + "orientation";
1772
+ var ARIA_ROLEDESCRIPTION = ARIA_PREFIX + "roledescription";
1773
+ var ARIA_LIVE = ARIA_PREFIX + "live";
1774
+ var ARIA_BUSY = ARIA_PREFIX + "busy";
1775
+ var ARIA_ATOMIC = ARIA_PREFIX + "atomic";
1776
+ var ALL_ATTRIBUTES = [ROLE, TAB_INDEX, DISABLED, ARIA_CONTROLS, ARIA_CURRENT, ARIA_LABEL, ARIA_LABELLEDBY, ARIA_HIDDEN, ARIA_ORIENTATION, ARIA_ROLEDESCRIPTION];
1777
+ var CLASS_PREFIX = PROJECT_CODE + "__";
1778
+ var STATUS_CLASS_PREFIX = "is-";
1779
+ var CLASS_ROOT = PROJECT_CODE;
1780
+ var CLASS_TRACK = CLASS_PREFIX + "track";
1781
+ var CLASS_LIST = CLASS_PREFIX + "list";
1782
+ var CLASS_SLIDE = CLASS_PREFIX + "slide";
1783
+ var CLASS_CLONE = CLASS_SLIDE + "--clone";
1784
+ var CLASS_CONTAINER = CLASS_SLIDE + "__container";
1785
+ var CLASS_ARROWS = CLASS_PREFIX + "arrows";
1786
+ var CLASS_ARROW = CLASS_PREFIX + "arrow";
1787
+ var CLASS_ARROW_PREV = CLASS_ARROW + "--prev";
1788
+ var CLASS_ARROW_NEXT = CLASS_ARROW + "--next";
1789
+ var CLASS_PAGINATION = CLASS_PREFIX + "pagination";
1790
+ var CLASS_PAGINATION_PAGE = CLASS_PAGINATION + "__page";
1791
+ var CLASS_PROGRESS = CLASS_PREFIX + "progress";
1792
+ var CLASS_PROGRESS_BAR = CLASS_PROGRESS + "__bar";
1793
+ var CLASS_TOGGLE = CLASS_PREFIX + "toggle";
1794
+ var CLASS_SPINNER = CLASS_PREFIX + "spinner";
1795
+ var CLASS_SR = CLASS_PREFIX + "sr";
1796
+ var CLASS_INITIALIZED = STATUS_CLASS_PREFIX + "initialized";
1797
+ var CLASS_ACTIVE = STATUS_CLASS_PREFIX + "active";
1798
+ var CLASS_PREV = STATUS_CLASS_PREFIX + "prev";
1799
+ var CLASS_NEXT = STATUS_CLASS_PREFIX + "next";
1800
+ var CLASS_VISIBLE = STATUS_CLASS_PREFIX + "visible";
1801
+ var CLASS_LOADING = STATUS_CLASS_PREFIX + "loading";
1802
+ var CLASS_FOCUS_IN = STATUS_CLASS_PREFIX + "focus-in";
1803
+ var CLASS_OVERFLOW = STATUS_CLASS_PREFIX + "overflow";
1804
+ var STATUS_CLASSES = [CLASS_ACTIVE, CLASS_VISIBLE, CLASS_PREV, CLASS_NEXT, CLASS_LOADING, CLASS_FOCUS_IN, CLASS_OVERFLOW];
1805
+ var CLASSES = {
1806
+ slide: CLASS_SLIDE,
1807
+ clone: CLASS_CLONE,
1808
+ arrows: CLASS_ARROWS,
1809
+ arrow: CLASS_ARROW,
1810
+ prev: CLASS_ARROW_PREV,
1811
+ next: CLASS_ARROW_NEXT,
1812
+ pagination: CLASS_PAGINATION,
1813
+ page: CLASS_PAGINATION_PAGE,
1814
+ spinner: CLASS_SPINNER
1815
+ };
1816
+
1817
+ function closest(from, selector) {
1818
+ if (isFunction(from.closest)) {
1819
+ return from.closest(selector);
1820
+ }
1821
+
1822
+ var elm = from;
1823
+
1824
+ while (elm && elm.nodeType === 1) {
1825
+ if (matches(elm, selector)) {
1826
+ break;
1827
+ }
1828
+
1829
+ elm = elm.parentElement;
1830
+ }
1831
+
1832
+ return elm;
1833
+ }
1834
+
1835
+ var FRICTION = 5;
1836
+ var LOG_INTERVAL = 200;
1837
+ var POINTER_DOWN_EVENTS = "touchstart mousedown";
1838
+ var POINTER_MOVE_EVENTS = "touchmove mousemove";
1839
+ var POINTER_UP_EVENTS = "touchend touchcancel mouseup click";
1840
+
1841
+ function Elements(Splide2, Components2, options) {
1842
+ var _EventInterface = EventInterface(Splide2),
1843
+ on = _EventInterface.on,
1844
+ bind = _EventInterface.bind;
1845
+
1846
+ var root = Splide2.root;
1847
+ var i18n = options.i18n;
1848
+ var elements = {};
1849
+ var slides = [];
1850
+ var rootClasses = [];
1851
+ var trackClasses = [];
1852
+ var track;
1853
+ var list;
1854
+ var isUsingKey;
1855
+
1856
+ function setup() {
1857
+ collect();
1858
+ init();
1859
+ update();
1860
+ }
1861
+
1862
+ function mount() {
1863
+ on(EVENT_REFRESH, destroy);
1864
+ on(EVENT_REFRESH, setup);
1865
+ on(EVENT_UPDATED, update);
1866
+ bind(document, POINTER_DOWN_EVENTS + " keydown", function (e) {
1867
+ isUsingKey = e.type === "keydown";
1868
+ }, {
1869
+ capture: true
1870
+ });
1871
+ bind(root, "focusin", function () {
1872
+ toggleClass(root, CLASS_FOCUS_IN, !!isUsingKey);
1873
+ });
1874
+ }
1875
+
1876
+ function destroy(completely) {
1877
+ var attrs = ALL_ATTRIBUTES.concat("style");
1878
+ empty(slides);
1879
+ removeClass(root, rootClasses);
1880
+ removeClass(track, trackClasses);
1881
+ removeAttribute([track, list], attrs);
1882
+ removeAttribute(root, completely ? attrs : ["style", ARIA_ROLEDESCRIPTION]);
1883
+ }
1884
+
1885
+ function update() {
1886
+ removeClass(root, rootClasses);
1887
+ removeClass(track, trackClasses);
1888
+ rootClasses = getClasses(CLASS_ROOT);
1889
+ trackClasses = getClasses(CLASS_TRACK);
1890
+ addClass(root, rootClasses);
1891
+ addClass(track, trackClasses);
1892
+ setAttribute(root, ARIA_LABEL, options.label);
1893
+ setAttribute(root, ARIA_LABELLEDBY, options.labelledby);
1894
+ }
1895
+
1896
+ function collect() {
1897
+ track = find("." + CLASS_TRACK);
1898
+ list = child(track, "." + CLASS_LIST);
1899
+ assert(track && list, "A track/list element is missing.");
1900
+ push(slides, children(list, "." + CLASS_SLIDE + ":not(." + CLASS_CLONE + ")"));
1901
+ forOwn({
1902
+ arrows: CLASS_ARROWS,
1903
+ pagination: CLASS_PAGINATION,
1904
+ prev: CLASS_ARROW_PREV,
1905
+ next: CLASS_ARROW_NEXT,
1906
+ bar: CLASS_PROGRESS_BAR,
1907
+ toggle: CLASS_TOGGLE
1908
+ }, function (className, key) {
1909
+ elements[key] = find("." + className);
1910
+ });
1911
+ assign(elements, {
1912
+ root: root,
1913
+ track: track,
1914
+ list: list,
1915
+ slides: slides
1916
+ });
1917
+ }
1918
+
1919
+ function init() {
1920
+ var id = root.id || uniqueId(PROJECT_CODE);
1921
+ var role = options.role;
1922
+ root.id = id;
1923
+ track.id = track.id || id + "-track";
1924
+ list.id = list.id || id + "-list";
1925
+
1926
+ if (!getAttribute(root, ROLE) && root.tagName !== "SECTION" && role) {
1927
+ setAttribute(root, ROLE, role);
1928
+ }
1929
+
1930
+ setAttribute(root, ARIA_ROLEDESCRIPTION, i18n.carousel);
1931
+ setAttribute(list, ROLE, "presentation");
1932
+ }
1933
+
1934
+ function find(selector) {
1935
+ var elm = query(root, selector);
1936
+ return elm && closest(elm, "." + CLASS_ROOT) === root ? elm : void 0;
1937
+ }
1938
+
1939
+ function getClasses(base) {
1940
+ return [base + "--" + options.type, base + "--" + options.direction, options.drag && base + "--draggable", options.isNavigation && base + "--nav", base === CLASS_ROOT && CLASS_ACTIVE];
1941
+ }
1942
+
1943
+ return assign(elements, {
1944
+ setup: setup,
1945
+ mount: mount,
1946
+ destroy: destroy
1947
+ });
1948
+ }
1949
+
1950
+ var SLIDE = "slide";
1951
+ var LOOP = "loop";
1952
+ var FADE = "fade";
1953
+
1954
+ function Slide$1(Splide2, index, slideIndex, slide) {
1955
+ var event = EventInterface(Splide2);
1956
+ var on = event.on,
1957
+ emit = event.emit,
1958
+ bind = event.bind;
1959
+ var Components = Splide2.Components,
1960
+ root = Splide2.root,
1961
+ options = Splide2.options;
1962
+ var isNavigation = options.isNavigation,
1963
+ updateOnMove = options.updateOnMove,
1964
+ i18n = options.i18n,
1965
+ pagination = options.pagination,
1966
+ slideFocus = options.slideFocus;
1967
+ var resolve = Components.Direction.resolve;
1968
+ var styles = getAttribute(slide, "style");
1969
+ var label = getAttribute(slide, ARIA_LABEL);
1970
+ var isClone = slideIndex > -1;
1971
+ var container = child(slide, "." + CLASS_CONTAINER);
1972
+ var destroyed;
1973
+
1974
+ function mount() {
1975
+ if (!isClone) {
1976
+ slide.id = root.id + "-slide" + pad(index + 1);
1977
+ setAttribute(slide, ROLE, pagination ? "tabpanel" : "group");
1978
+ setAttribute(slide, ARIA_ROLEDESCRIPTION, i18n.slide);
1979
+ setAttribute(slide, ARIA_LABEL, label || format(i18n.slideLabel, [index + 1, Splide2.length]));
1980
+ }
1981
+
1982
+ listen();
1983
+ }
1984
+
1985
+ function listen() {
1986
+ bind(slide, "click", apply(emit, EVENT_CLICK, self));
1987
+ bind(slide, "keydown", apply(emit, EVENT_SLIDE_KEYDOWN, self));
1988
+ on([EVENT_MOVED, EVENT_SHIFTED, EVENT_SCROLLED], update);
1989
+ on(EVENT_NAVIGATION_MOUNTED, initNavigation);
1990
+
1991
+ if (updateOnMove) {
1992
+ on(EVENT_MOVE, onMove);
1993
+ }
1994
+ }
1995
+
1996
+ function destroy() {
1997
+ destroyed = true;
1998
+ event.destroy();
1999
+ removeClass(slide, STATUS_CLASSES);
2000
+ removeAttribute(slide, ALL_ATTRIBUTES);
2001
+ setAttribute(slide, "style", styles);
2002
+ setAttribute(slide, ARIA_LABEL, label || "");
2003
+ }
2004
+
2005
+ function initNavigation() {
2006
+ var controls = Splide2.splides.map(function (target) {
2007
+ var Slide2 = target.splide.Components.Slides.getAt(index);
2008
+ return Slide2 ? Slide2.slide.id : "";
2009
+ }).join(" ");
2010
+ setAttribute(slide, ARIA_LABEL, format(i18n.slideX, (isClone ? slideIndex : index) + 1));
2011
+ setAttribute(slide, ARIA_CONTROLS, controls);
2012
+ setAttribute(slide, ROLE, slideFocus ? "button" : "");
2013
+ slideFocus && removeAttribute(slide, ARIA_ROLEDESCRIPTION);
2014
+ }
2015
+
2016
+ function onMove() {
2017
+ if (!destroyed) {
2018
+ update();
2019
+ }
2020
+ }
2021
+
2022
+ function update() {
2023
+ if (!destroyed) {
2024
+ var curr = Splide2.index;
2025
+ updateActivity();
2026
+ updateVisibility();
2027
+ toggleClass(slide, CLASS_PREV, index === curr - 1);
2028
+ toggleClass(slide, CLASS_NEXT, index === curr + 1);
2029
+ }
2030
+ }
2031
+
2032
+ function updateActivity() {
2033
+ var active = isActive();
2034
+
2035
+ if (active !== hasClass(slide, CLASS_ACTIVE)) {
2036
+ toggleClass(slide, CLASS_ACTIVE, active);
2037
+ setAttribute(slide, ARIA_CURRENT, isNavigation && active || "");
2038
+ emit(active ? EVENT_ACTIVE : EVENT_INACTIVE, self);
2039
+ }
2040
+ }
2041
+
2042
+ function updateVisibility() {
2043
+ var visible = isVisible();
2044
+ var hidden = !visible && (!isActive() || isClone);
2045
+
2046
+ if (!Splide2.state.is([MOVING, SCROLLING])) {
2047
+ setAttribute(slide, ARIA_HIDDEN, hidden || "");
2048
+ }
2049
+
2050
+ setAttribute(queryAll(slide, options.focusableNodes || ""), TAB_INDEX, hidden ? -1 : "");
2051
+
2052
+ if (slideFocus) {
2053
+ setAttribute(slide, TAB_INDEX, hidden ? -1 : 0);
2054
+ }
2055
+
2056
+ if (visible !== hasClass(slide, CLASS_VISIBLE)) {
2057
+ toggleClass(slide, CLASS_VISIBLE, visible);
2058
+ emit(visible ? EVENT_VISIBLE : EVENT_HIDDEN, self);
2059
+ }
2060
+
2061
+ if (!visible && document.activeElement === slide) {
2062
+ var Slide2 = Components.Slides.getAt(Splide2.index);
2063
+ Slide2 && focus(Slide2.slide);
2064
+ }
2065
+ }
2066
+
2067
+ function style$1(prop, value, useContainer) {
2068
+ style(useContainer && container || slide, prop, value);
2069
+ }
2070
+
2071
+ function isActive() {
2072
+ var curr = Splide2.index;
2073
+ return curr === index || options.cloneStatus && curr === slideIndex;
2074
+ }
2075
+
2076
+ function isVisible() {
2077
+ if (Splide2.is(FADE)) {
2078
+ return isActive();
2079
+ }
2080
+
2081
+ var trackRect = rect(Components.Elements.track);
2082
+ var slideRect = rect(slide);
2083
+ var left = resolve("left", true);
2084
+ var right = resolve("right", true);
2085
+ return floor(trackRect[left]) <= ceil(slideRect[left]) && floor(slideRect[right]) <= ceil(trackRect[right]);
2086
+ }
2087
+
2088
+ function isWithin(from, distance) {
2089
+ var diff = abs(from - index);
2090
+
2091
+ if (!isClone && (options.rewind || Splide2.is(LOOP))) {
2092
+ diff = min(diff, Splide2.length - diff);
2093
+ }
2094
+
2095
+ return diff <= distance;
2096
+ }
2097
+
2098
+ var self = {
2099
+ index: index,
2100
+ slideIndex: slideIndex,
2101
+ slide: slide,
2102
+ container: container,
2103
+ isClone: isClone,
2104
+ mount: mount,
2105
+ destroy: destroy,
2106
+ update: update,
2107
+ style: style$1,
2108
+ isWithin: isWithin
2109
+ };
2110
+ return self;
2111
+ }
2112
+
2113
+ function Slides(Splide2, Components2, options) {
2114
+ var _EventInterface2 = EventInterface(Splide2),
2115
+ on = _EventInterface2.on,
2116
+ emit = _EventInterface2.emit,
2117
+ bind = _EventInterface2.bind;
2118
+
2119
+ var _Components2$Elements = Components2.Elements,
2120
+ slides = _Components2$Elements.slides,
2121
+ list = _Components2$Elements.list;
2122
+ var Slides2 = [];
2123
+
2124
+ function mount() {
2125
+ init();
2126
+ on(EVENT_REFRESH, destroy);
2127
+ on(EVENT_REFRESH, init);
2128
+ }
2129
+
2130
+ function init() {
2131
+ slides.forEach(function (slide, index) {
2132
+ register(slide, index, -1);
2133
+ });
2134
+ }
2135
+
2136
+ function destroy() {
2137
+ forEach$1(function (Slide2) {
2138
+ Slide2.destroy();
2139
+ });
2140
+ empty(Slides2);
2141
+ }
2142
+
2143
+ function update() {
2144
+ forEach$1(function (Slide2) {
2145
+ Slide2.update();
2146
+ });
2147
+ }
2148
+
2149
+ function register(slide, index, slideIndex) {
2150
+ var object = Slide$1(Splide2, index, slideIndex, slide);
2151
+ object.mount();
2152
+ Slides2.push(object);
2153
+ Slides2.sort(function (Slide1, Slide2) {
2154
+ return Slide1.index - Slide2.index;
2155
+ });
2156
+ }
2157
+
2158
+ function get(excludeClones) {
2159
+ return excludeClones ? filter(function (Slide2) {
2160
+ return !Slide2.isClone;
2161
+ }) : Slides2;
2162
+ }
2163
+
2164
+ function getIn(page) {
2165
+ var Controller = Components2.Controller;
2166
+ var index = Controller.toIndex(page);
2167
+ var max = Controller.hasFocus() ? 1 : options.perPage;
2168
+ return filter(function (Slide2) {
2169
+ return between(Slide2.index, index, index + max - 1);
2170
+ });
2171
+ }
2172
+
2173
+ function getAt(index) {
2174
+ return filter(index)[0];
2175
+ }
2176
+
2177
+ function add(items, index) {
2178
+ forEach(items, function (slide) {
2179
+ if (isString(slide)) {
2180
+ slide = parseHtml(slide);
2181
+ }
2182
+
2183
+ if (isHTMLElement(slide)) {
2184
+ var ref = slides[index];
2185
+ ref ? before(slide, ref) : append(list, slide);
2186
+ addClass(slide, options.classes.slide);
2187
+ observeImages(slide, apply(emit, EVENT_RESIZE));
2188
+ }
2189
+ });
2190
+ emit(EVENT_REFRESH);
2191
+ }
2192
+
2193
+ function remove$1(matcher) {
2194
+ remove(filter(matcher).map(function (Slide2) {
2195
+ return Slide2.slide;
2196
+ }));
2197
+ emit(EVENT_REFRESH);
2198
+ }
2199
+
2200
+ function forEach$1(iteratee, excludeClones) {
2201
+ get(excludeClones).forEach(iteratee);
2202
+ }
2203
+
2204
+ function filter(matcher) {
2205
+ return Slides2.filter(isFunction(matcher) ? matcher : function (Slide2) {
2206
+ return isString(matcher) ? matches(Slide2.slide, matcher) : includes(toArray(matcher), Slide2.index);
2207
+ });
2208
+ }
2209
+
2210
+ function style(prop, value, useContainer) {
2211
+ forEach$1(function (Slide2) {
2212
+ Slide2.style(prop, value, useContainer);
2213
+ });
2214
+ }
2215
+
2216
+ function observeImages(elm, callback) {
2217
+ var images = queryAll(elm, "img");
2218
+ var length = images.length;
2219
+
2220
+ if (length) {
2221
+ images.forEach(function (img) {
2222
+ bind(img, "load error", function () {
2223
+ if (! --length) {
2224
+ callback();
2225
+ }
2226
+ });
2227
+ });
2228
+ } else {
2229
+ callback();
2230
+ }
2231
+ }
2232
+
2233
+ function getLength(excludeClones) {
2234
+ return excludeClones ? slides.length : Slides2.length;
2235
+ }
2236
+
2237
+ function isEnough() {
2238
+ return Slides2.length > options.perPage;
2239
+ }
2240
+
2241
+ return {
2242
+ mount: mount,
2243
+ destroy: destroy,
2244
+ update: update,
2245
+ register: register,
2246
+ get: get,
2247
+ getIn: getIn,
2248
+ getAt: getAt,
2249
+ add: add,
2250
+ remove: remove$1,
2251
+ forEach: forEach$1,
2252
+ filter: filter,
2253
+ style: style,
2254
+ getLength: getLength,
2255
+ isEnough: isEnough
2256
+ };
2257
+ }
2258
+
2259
+ function Layout(Splide2, Components2, options) {
2260
+ var _EventInterface3 = EventInterface(Splide2),
2261
+ on = _EventInterface3.on,
2262
+ bind = _EventInterface3.bind,
2263
+ emit = _EventInterface3.emit;
2264
+
2265
+ var Slides = Components2.Slides;
2266
+ var resolve = Components2.Direction.resolve;
2267
+ var _Components2$Elements2 = Components2.Elements,
2268
+ root = _Components2$Elements2.root,
2269
+ track = _Components2$Elements2.track,
2270
+ list = _Components2$Elements2.list;
2271
+ var getAt = Slides.getAt,
2272
+ styleSlides = Slides.style;
2273
+ var vertical;
2274
+ var rootRect;
2275
+ var overflow;
2276
+
2277
+ function mount() {
2278
+ init();
2279
+ bind(window, "resize load", Throttle(apply(emit, EVENT_RESIZE)));
2280
+ on([EVENT_UPDATED, EVENT_REFRESH], init);
2281
+ on(EVENT_RESIZE, resize);
2282
+ }
2283
+
2284
+ function init() {
2285
+ vertical = options.direction === TTB;
2286
+ style(root, "maxWidth", unit(options.width));
2287
+ style(track, resolve("paddingLeft"), cssPadding(false));
2288
+ style(track, resolve("paddingRight"), cssPadding(true));
2289
+ resize(true);
2290
+ }
2291
+
2292
+ function resize(force) {
2293
+ var newRect = rect(root);
2294
+
2295
+ if (force || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
2296
+ style(track, "height", cssTrackHeight());
2297
+ styleSlides(resolve("marginRight"), unit(options.gap));
2298
+ styleSlides("width", cssSlideWidth());
2299
+ styleSlides("height", cssSlideHeight(), true);
2300
+ rootRect = newRect;
2301
+ emit(EVENT_RESIZED);
2302
+
2303
+ if (overflow !== (overflow = isOverflow())) {
2304
+ toggleClass(root, CLASS_OVERFLOW, overflow);
2305
+ emit(EVENT_OVERFLOW, overflow);
2306
+ }
2307
+ }
2308
+ }
2309
+
2310
+ function cssPadding(right) {
2311
+ var padding = options.padding;
2312
+ var prop = resolve(right ? "right" : "left");
2313
+ return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
2314
+ }
2315
+
2316
+ function cssTrackHeight() {
2317
+ var height = "";
2318
+
2319
+ if (vertical) {
2320
+ height = cssHeight();
2321
+ assert(height, "height or heightRatio is missing.");
2322
+ height = "calc(" + height + " - " + cssPadding(false) + " - " + cssPadding(true) + ")";
2323
+ }
2324
+
2325
+ return height;
2326
+ }
2327
+
2328
+ function cssHeight() {
2329
+ return unit(options.height || rect(list).width * options.heightRatio);
2330
+ }
2331
+
2332
+ function cssSlideWidth() {
2333
+ return options.autoWidth ? null : unit(options.fixedWidth) || (vertical ? "" : cssSlideSize());
2334
+ }
2335
+
2336
+ function cssSlideHeight() {
2337
+ return unit(options.fixedHeight) || (vertical ? options.autoHeight ? null : cssSlideSize() : cssHeight());
2338
+ }
2339
+
2340
+ function cssSlideSize() {
2341
+ var gap = unit(options.gap);
2342
+ return "calc((100%" + (gap && " + " + gap) + ")/" + (options.perPage || 1) + (gap && " - " + gap) + ")";
2343
+ }
2344
+
2345
+ function listSize() {
2346
+ return rect(list)[resolve("width")];
2347
+ }
2348
+
2349
+ function slideSize(index, withoutGap) {
2350
+ var Slide = getAt(index || 0);
2351
+ return Slide ? rect(Slide.slide)[resolve("width")] + (withoutGap ? 0 : getGap()) : 0;
2352
+ }
2353
+
2354
+ function totalSize(index, withoutGap) {
2355
+ var Slide = getAt(index);
2356
+
2357
+ if (Slide) {
2358
+ var right = rect(Slide.slide)[resolve("right")];
2359
+ var left = rect(list)[resolve("left")];
2360
+ return abs(right - left) + (withoutGap ? 0 : getGap());
2361
+ }
2362
+
2363
+ return 0;
2364
+ }
2365
+
2366
+ function sliderSize(withoutGap) {
2367
+ return totalSize(Splide2.length - 1) - totalSize(0) + slideSize(0, withoutGap);
2368
+ }
2369
+
2370
+ function getGap() {
2371
+ var Slide = getAt(0);
2372
+ return Slide && parseFloat(style(Slide.slide, resolve("marginRight"))) || 0;
2373
+ }
2374
+
2375
+ function getPadding(right) {
2376
+ return parseFloat(style(track, resolve("padding" + (right ? "Right" : "Left")))) || 0;
2377
+ }
2378
+
2379
+ function isOverflow() {
2380
+ return Splide2.is(FADE) || sliderSize(true) > listSize();
2381
+ }
2382
+
2383
+ return {
2384
+ mount: mount,
2385
+ resize: resize,
2386
+ listSize: listSize,
2387
+ slideSize: slideSize,
2388
+ sliderSize: sliderSize,
2389
+ totalSize: totalSize,
2390
+ getPadding: getPadding,
2391
+ isOverflow: isOverflow
2392
+ };
2393
+ }
2394
+
2395
+ var MULTIPLIER = 2;
2396
+
2397
+ function Clones(Splide2, Components2, options) {
2398
+ var event = EventInterface(Splide2);
2399
+ var on = event.on;
2400
+ var Elements = Components2.Elements,
2401
+ Slides = Components2.Slides;
2402
+ var resolve = Components2.Direction.resolve;
2403
+ var clones = [];
2404
+ var cloneCount;
2405
+
2406
+ function mount() {
2407
+ on(EVENT_REFRESH, remount);
2408
+ on([EVENT_UPDATED, EVENT_RESIZE], observe);
2409
+
2410
+ if (cloneCount = computeCloneCount()) {
2411
+ generate(cloneCount);
2412
+ Components2.Layout.resize(true);
2413
+ }
2414
+ }
2415
+
2416
+ function remount() {
2417
+ destroy();
2418
+ mount();
2419
+ }
2420
+
2421
+ function destroy() {
2422
+ remove(clones);
2423
+ empty(clones);
2424
+ event.destroy();
2425
+ }
2426
+
2427
+ function observe() {
2428
+ var count = computeCloneCount();
2429
+
2430
+ if (cloneCount !== count) {
2431
+ if (cloneCount < count || !count) {
2432
+ event.emit(EVENT_REFRESH);
2433
+ }
2434
+ }
2435
+ }
2436
+
2437
+ function generate(count) {
2438
+ var slides = Slides.get().slice();
2439
+ var length = slides.length;
2440
+
2441
+ if (length) {
2442
+ while (slides.length < count) {
2443
+ push(slides, slides);
2444
+ }
2445
+
2446
+ push(slides.slice(-count), slides.slice(0, count)).forEach(function (Slide, index) {
2447
+ var isHead = index < count;
2448
+ var clone = cloneDeep(Slide.slide, index);
2449
+ isHead ? before(clone, slides[0].slide) : append(Elements.list, clone);
2450
+ push(clones, clone);
2451
+ Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
2452
+ });
2453
+ }
2454
+ }
2455
+
2456
+ function cloneDeep(elm, index) {
2457
+ var clone = elm.cloneNode(true);
2458
+ addClass(clone, options.classes.clone);
2459
+ clone.id = Splide2.root.id + "-clone" + pad(index + 1);
2460
+ return clone;
2461
+ }
2462
+
2463
+ function computeCloneCount() {
2464
+ var clones2 = options.clones;
2465
+
2466
+ if (!Splide2.is(LOOP)) {
2467
+ clones2 = 0;
2468
+ } else if (isUndefined(clones2)) {
2469
+ var fixedSize = options[resolve("fixedWidth")] && Components2.Layout.slideSize(0);
2470
+ var fixedCount = fixedSize && ceil(rect(Elements.track)[resolve("width")] / fixedSize);
2471
+ clones2 = fixedCount || options[resolve("autoWidth")] && Splide2.length || options.perPage * MULTIPLIER;
2472
+ }
2473
+
2474
+ return clones2;
2475
+ }
2476
+
2477
+ return {
2478
+ mount: mount,
2479
+ destroy: destroy
2480
+ };
2481
+ }
2482
+
2483
+ function Move(Splide2, Components2, options) {
2484
+ var _EventInterface4 = EventInterface(Splide2),
2485
+ on = _EventInterface4.on,
2486
+ emit = _EventInterface4.emit;
2487
+
2488
+ var set = Splide2.state.set;
2489
+ var _Components2$Layout = Components2.Layout,
2490
+ slideSize = _Components2$Layout.slideSize,
2491
+ getPadding = _Components2$Layout.getPadding,
2492
+ totalSize = _Components2$Layout.totalSize,
2493
+ listSize = _Components2$Layout.listSize,
2494
+ sliderSize = _Components2$Layout.sliderSize;
2495
+ var _Components2$Directio = Components2.Direction,
2496
+ resolve = _Components2$Directio.resolve,
2497
+ orient = _Components2$Directio.orient;
2498
+ var _Components2$Elements3 = Components2.Elements,
2499
+ list = _Components2$Elements3.list,
2500
+ track = _Components2$Elements3.track;
2501
+ var Transition;
2502
+
2503
+ function mount() {
2504
+ Transition = Components2.Transition;
2505
+ on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
2506
+ }
2507
+
2508
+ function reposition() {
2509
+ if (!Components2.Controller.isBusy()) {
2510
+ Components2.Scroll.cancel();
2511
+ jump(Splide2.index);
2512
+ Components2.Slides.update();
2513
+ }
2514
+ }
2515
+
2516
+ function move(dest, index, prev, callback) {
2517
+ if (dest !== index && canShift(dest > prev)) {
2518
+ cancel();
2519
+ translate(shift(getPosition(), dest > prev), true);
2520
+ }
2521
+
2522
+ set(MOVING);
2523
+ emit(EVENT_MOVE, index, prev, dest);
2524
+ Transition.start(index, function () {
2525
+ set(IDLE);
2526
+ emit(EVENT_MOVED, index, prev, dest);
2527
+ callback && callback();
2528
+ });
2529
+ }
2530
+
2531
+ function jump(index) {
2532
+ translate(toPosition(index, true));
2533
+ }
2534
+
2535
+ function translate(position, preventLoop) {
2536
+ if (!Splide2.is(FADE)) {
2537
+ var destination = preventLoop ? position : loop(position);
2538
+ style(list, "transform", "translate" + resolve("X") + "(" + destination + "px)");
2539
+ position !== destination && emit(EVENT_SHIFTED);
2540
+ }
2541
+ }
2542
+
2543
+ function loop(position) {
2544
+ if (Splide2.is(LOOP)) {
2545
+ var index = toIndex(position);
2546
+ var exceededMax = index > Components2.Controller.getEnd();
2547
+ var exceededMin = index < 0;
2548
+
2549
+ if (exceededMin || exceededMax) {
2550
+ position = shift(position, exceededMax);
2551
+ }
2552
+ }
2553
+
2554
+ return position;
2555
+ }
2556
+
2557
+ function shift(position, backwards) {
2558
+ var excess = position - getLimit(backwards);
2559
+ var size = sliderSize();
2560
+ position -= orient(size * (ceil(abs(excess) / size) || 1)) * (backwards ? 1 : -1);
2561
+ return position;
2562
+ }
2563
+
2564
+ function cancel() {
2565
+ translate(getPosition(), true);
2566
+ Transition.cancel();
2567
+ }
2568
+
2569
+ function toIndex(position) {
2570
+ var Slides = Components2.Slides.get();
2571
+ var index = 0;
2572
+ var minDistance = Infinity;
2573
+
2574
+ for (var i = 0; i < Slides.length; i++) {
2575
+ var slideIndex = Slides[i].index;
2576
+ var distance = abs(toPosition(slideIndex, true) - position);
2577
+
2578
+ if (distance <= minDistance) {
2579
+ minDistance = distance;
2580
+ index = slideIndex;
2581
+ } else {
2582
+ break;
2583
+ }
2584
+ }
2585
+
2586
+ return index;
2587
+ }
2588
+
2589
+ function toPosition(index, trimming) {
2590
+ var position = orient(totalSize(index - 1) - offset(index));
2591
+ return trimming ? trim(position) : position;
2592
+ }
2593
+
2594
+ function getPosition() {
2595
+ var left = resolve("left");
2596
+ return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
2597
+ }
2598
+
2599
+ function trim(position) {
2600
+ if (options.trimSpace && Splide2.is(SLIDE)) {
2601
+ position = clamp(position, 0, orient(sliderSize(true) - listSize()));
2602
+ }
2603
+
2604
+ return position;
2605
+ }
2606
+
2607
+ function offset(index) {
2608
+ var focus = options.focus;
2609
+ return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
2610
+ }
2611
+
2612
+ function getLimit(max) {
2613
+ return toPosition(max ? Components2.Controller.getEnd() : 0, !!options.trimSpace);
2614
+ }
2615
+
2616
+ function canShift(backwards) {
2617
+ var shifted = orient(shift(getPosition(), backwards));
2618
+ return backwards ? shifted >= 0 : shifted <= list[resolve("scrollWidth")] - rect(track)[resolve("width")];
2619
+ }
2620
+
2621
+ function exceededLimit(max, position) {
2622
+ position = isUndefined(position) ? getPosition() : position;
2623
+ var exceededMin = max !== true && orient(position) < orient(getLimit(false));
2624
+ var exceededMax = max !== false && orient(position) > orient(getLimit(true));
2625
+ return exceededMin || exceededMax;
2626
+ }
2627
+
2628
+ return {
2629
+ mount: mount,
2630
+ move: move,
2631
+ jump: jump,
2632
+ translate: translate,
2633
+ shift: shift,
2634
+ cancel: cancel,
2635
+ toIndex: toIndex,
2636
+ toPosition: toPosition,
2637
+ getPosition: getPosition,
2638
+ getLimit: getLimit,
2639
+ exceededLimit: exceededLimit,
2640
+ reposition: reposition
2641
+ };
2642
+ }
2643
+
2644
+ function Controller(Splide2, Components2, options) {
2645
+ var _EventInterface5 = EventInterface(Splide2),
2646
+ on = _EventInterface5.on,
2647
+ emit = _EventInterface5.emit;
2648
+
2649
+ var Move = Components2.Move;
2650
+ var getPosition = Move.getPosition,
2651
+ getLimit = Move.getLimit,
2652
+ toPosition = Move.toPosition;
2653
+ var _Components2$Slides = Components2.Slides,
2654
+ isEnough = _Components2$Slides.isEnough,
2655
+ getLength = _Components2$Slides.getLength;
2656
+ var omitEnd = options.omitEnd;
2657
+ var isLoop = Splide2.is(LOOP);
2658
+ var isSlide = Splide2.is(SLIDE);
2659
+ var getNext = apply(getAdjacent, false);
2660
+ var getPrev = apply(getAdjacent, true);
2661
+ var currIndex = options.start || 0;
2662
+ var endIndex;
2663
+ var prevIndex = currIndex;
2664
+ var slideCount;
2665
+ var perMove;
2666
+ var perPage;
2667
+
2668
+ function mount() {
2669
+ init();
2670
+ on([EVENT_UPDATED, EVENT_REFRESH, EVENT_END_INDEX_CHANGED], init);
2671
+ on(EVENT_RESIZED, onResized);
2672
+ }
2673
+
2674
+ function init() {
2675
+ slideCount = getLength(true);
2676
+ perMove = options.perMove;
2677
+ perPage = options.perPage;
2678
+ endIndex = getEnd();
2679
+ var index = clamp(currIndex, 0, omitEnd ? endIndex : slideCount - 1);
2680
+
2681
+ if (index !== currIndex) {
2682
+ currIndex = index;
2683
+ Move.reposition();
2684
+ }
2685
+ }
2686
+
2687
+ function onResized() {
2688
+ if (endIndex !== getEnd()) {
2689
+ emit(EVENT_END_INDEX_CHANGED);
2690
+ }
2691
+ }
2692
+
2693
+ function go(control, allowSameIndex, callback) {
2694
+ if (!isBusy()) {
2695
+ var dest = parse(control);
2696
+ var index = loop(dest);
2697
+
2698
+ if (index > -1 && (allowSameIndex || index !== currIndex)) {
2699
+ setIndex(index);
2700
+ Move.move(dest, index, prevIndex, callback);
2701
+ }
2702
+ }
2703
+ }
2704
+
2705
+ function scroll(destination, duration, snap, callback) {
2706
+ Components2.Scroll.scroll(destination, duration, snap, function () {
2707
+ var index = loop(Move.toIndex(getPosition()));
2708
+ setIndex(omitEnd ? min(index, endIndex) : index);
2709
+ callback && callback();
2710
+ });
2711
+ }
2712
+
2713
+ function parse(control) {
2714
+ var index = currIndex;
2715
+
2716
+ if (isString(control)) {
2717
+ var _ref = control.match(/([+\-<>])(\d+)?/) || [],
2718
+ indicator = _ref[1],
2719
+ number = _ref[2];
2720
+
2721
+ if (indicator === "+" || indicator === "-") {
2722
+ index = computeDestIndex(currIndex + +("" + indicator + (+number || 1)), currIndex);
2723
+ } else if (indicator === ">") {
2724
+ index = number ? toIndex(+number) : getNext(true);
2725
+ } else if (indicator === "<") {
2726
+ index = getPrev(true);
2727
+ }
2728
+ } else {
2729
+ index = isLoop ? control : clamp(control, 0, endIndex);
2730
+ }
2731
+
2732
+ return index;
2733
+ }
2734
+
2735
+ function getAdjacent(prev, destination) {
2736
+ var number = perMove || (hasFocus() ? 1 : perPage);
2737
+ var dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex, !(perMove || hasFocus()));
2738
+
2739
+ if (dest === -1 && isSlide) {
2740
+ if (!approximatelyEqual(getPosition(), getLimit(!prev), 1)) {
2741
+ return prev ? 0 : endIndex;
2742
+ }
2743
+ }
2744
+
2745
+ return destination ? dest : loop(dest);
2746
+ }
2747
+
2748
+ function computeDestIndex(dest, from, snapPage) {
2749
+ if (isEnough() || hasFocus()) {
2750
+ var index = computeMovableDestIndex(dest);
2751
+
2752
+ if (index !== dest) {
2753
+ from = dest;
2754
+ dest = index;
2755
+ snapPage = false;
2756
+ }
2757
+
2758
+ if (dest < 0 || dest > endIndex) {
2759
+ if (!perMove && (between(0, dest, from, true) || between(endIndex, from, dest, true))) {
2760
+ dest = toIndex(toPage(dest));
2761
+ } else {
2762
+ if (isLoop) {
2763
+ dest = snapPage ? dest < 0 ? -(slideCount % perPage || perPage) : slideCount : dest;
2764
+ } else if (options.rewind) {
2765
+ dest = dest < 0 ? endIndex : 0;
2766
+ } else {
2767
+ dest = -1;
2768
+ }
2769
+ }
2770
+ } else {
2771
+ if (snapPage && dest !== from) {
2772
+ dest = toIndex(toPage(from) + (dest < from ? -1 : 1));
2773
+ }
2774
+ }
2775
+ } else {
2776
+ dest = -1;
2777
+ }
2778
+
2779
+ return dest;
2780
+ }
2781
+
2782
+ function computeMovableDestIndex(dest) {
2783
+ if (isSlide && options.trimSpace === "move" && dest !== currIndex) {
2784
+ var position = getPosition();
2785
+
2786
+ while (position === toPosition(dest, true) && between(dest, 0, Splide2.length - 1, !options.rewind)) {
2787
+ dest < currIndex ? --dest : ++dest;
2788
+ }
2789
+ }
2790
+
2791
+ return dest;
2792
+ }
2793
+
2794
+ function loop(index) {
2795
+ return isLoop ? (index + slideCount) % slideCount || 0 : index;
2796
+ }
2797
+
2798
+ function getEnd() {
2799
+ var end = slideCount - (hasFocus() || isLoop && perMove ? 1 : perPage);
2800
+
2801
+ while (omitEnd && end-- > 0) {
2802
+ if (toPosition(slideCount - 1, true) !== toPosition(end, true)) {
2803
+ end++;
2804
+ break;
2805
+ }
2806
+ }
2807
+
2808
+ return clamp(end, 0, slideCount - 1);
2809
+ }
2810
+
2811
+ function toIndex(page) {
2812
+ return clamp(hasFocus() ? page : perPage * page, 0, endIndex);
2813
+ }
2814
+
2815
+ function toPage(index) {
2816
+ return hasFocus() ? min(index, endIndex) : floor((index >= endIndex ? slideCount - 1 : index) / perPage);
2817
+ }
2818
+
2819
+ function toDest(destination) {
2820
+ var closest = Move.toIndex(destination);
2821
+ return isSlide ? clamp(closest, 0, endIndex) : closest;
2822
+ }
2823
+
2824
+ function setIndex(index) {
2825
+ if (index !== currIndex) {
2826
+ prevIndex = currIndex;
2827
+ currIndex = index;
2828
+ }
2829
+ }
2830
+
2831
+ function getIndex(prev) {
2832
+ return prev ? prevIndex : currIndex;
2833
+ }
2834
+
2835
+ function hasFocus() {
2836
+ return !isUndefined(options.focus) || options.isNavigation;
2837
+ }
2838
+
2839
+ function isBusy() {
2840
+ return Splide2.state.is([MOVING, SCROLLING]) && !!options.waitForTransition;
2841
+ }
2842
+
2843
+ return {
2844
+ mount: mount,
2845
+ go: go,
2846
+ scroll: scroll,
2847
+ getNext: getNext,
2848
+ getPrev: getPrev,
2849
+ getAdjacent: getAdjacent,
2850
+ getEnd: getEnd,
2851
+ setIndex: setIndex,
2852
+ getIndex: getIndex,
2853
+ toIndex: toIndex,
2854
+ toPage: toPage,
2855
+ toDest: toDest,
2856
+ hasFocus: hasFocus,
2857
+ isBusy: isBusy
2858
+ };
2859
+ }
2860
+
2861
+ var XML_NAME_SPACE = "http://www.w3.org/2000/svg";
2862
+ var PATH = "m15.5 0.932-4.3 4.38 14.5 14.6-14.5 14.5 4.3 4.4 14.6-14.6 4.4-4.3-4.4-4.4-14.6-14.6z";
2863
+ var SIZE = 40;
2864
+
2865
+ function Arrows(Splide2, Components2, options) {
2866
+ var event = EventInterface(Splide2);
2867
+ var on = event.on,
2868
+ bind = event.bind,
2869
+ emit = event.emit;
2870
+ var classes = options.classes,
2871
+ i18n = options.i18n;
2872
+ var Elements = Components2.Elements,
2873
+ Controller = Components2.Controller;
2874
+ var placeholder = Elements.arrows,
2875
+ track = Elements.track;
2876
+ var wrapper = placeholder;
2877
+ var prev = Elements.prev;
2878
+ var next = Elements.next;
2879
+ var created;
2880
+ var wrapperClasses;
2881
+ var arrows = {};
2882
+
2883
+ function mount() {
2884
+ init();
2885
+ on(EVENT_UPDATED, remount);
2886
+ }
2887
+
2888
+ function remount() {
2889
+ destroy();
2890
+ mount();
2891
+ }
2892
+
2893
+ function init() {
2894
+ var enabled = options.arrows;
2895
+
2896
+ if (enabled && !(prev && next)) {
2897
+ createArrows();
2898
+ }
2899
+
2900
+ if (prev && next) {
2901
+ assign(arrows, {
2902
+ prev: prev,
2903
+ next: next
2904
+ });
2905
+ display(wrapper, enabled ? "" : "none");
2906
+ addClass(wrapper, wrapperClasses = CLASS_ARROWS + "--" + options.direction);
2907
+
2908
+ if (enabled) {
2909
+ listen();
2910
+ update();
2911
+ setAttribute([prev, next], ARIA_CONTROLS, track.id);
2912
+ emit(EVENT_ARROWS_MOUNTED, prev, next);
2913
+ }
2914
+ }
2915
+ }
2916
+
2917
+ function destroy() {
2918
+ event.destroy();
2919
+ removeClass(wrapper, wrapperClasses);
2920
+
2921
+ if (created) {
2922
+ remove(placeholder ? [prev, next] : wrapper);
2923
+ prev = next = null;
2924
+ } else {
2925
+ removeAttribute([prev, next], ALL_ATTRIBUTES);
2926
+ }
2927
+ }
2928
+
2929
+ function listen() {
2930
+ on([EVENT_MOUNTED, EVENT_MOVED, EVENT_REFRESH, EVENT_SCROLLED, EVENT_END_INDEX_CHANGED], update);
2931
+ bind(next, "click", apply(go, ">"));
2932
+ bind(prev, "click", apply(go, "<"));
2933
+ }
2934
+
2935
+ function go(control) {
2936
+ Controller.go(control, true);
2937
+ }
2938
+
2939
+ function createArrows() {
2940
+ wrapper = placeholder || create("div", classes.arrows);
2941
+ prev = createArrow(true);
2942
+ next = createArrow(false);
2943
+ created = true;
2944
+ append(wrapper, [prev, next]);
2945
+ !placeholder && before(wrapper, track);
2946
+ }
2947
+
2948
+ function createArrow(prev2) {
2949
+ var arrow = "<button class=\"" + classes.arrow + " " + (prev2 ? classes.prev : classes.next) + "\" type=\"button\"><svg xmlns=\"" + XML_NAME_SPACE + "\" viewBox=\"0 0 " + SIZE + " " + SIZE + "\" width=\"" + SIZE + "\" height=\"" + SIZE + "\" focusable=\"false\"><path d=\"" + (options.arrowPath || PATH) + "\" />";
2950
+ return parseHtml(arrow);
2951
+ }
2952
+
2953
+ function update() {
2954
+ if (prev && next) {
2955
+ var index = Splide2.index;
2956
+ var prevIndex = Controller.getPrev();
2957
+ var nextIndex = Controller.getNext();
2958
+ var prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
2959
+ var nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
2960
+ prev.disabled = prevIndex < 0;
2961
+ next.disabled = nextIndex < 0;
2962
+ setAttribute(prev, ARIA_LABEL, prevLabel);
2963
+ setAttribute(next, ARIA_LABEL, nextLabel);
2964
+ emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
2965
+ }
2966
+ }
2967
+
2968
+ return {
2969
+ arrows: arrows,
2970
+ mount: mount,
2971
+ destroy: destroy,
2972
+ update: update
2973
+ };
2974
+ }
2975
+
2976
+ var INTERVAL_DATA_ATTRIBUTE = DATA_ATTRIBUTE + "-interval";
2977
+
2978
+ function Autoplay(Splide2, Components2, options) {
2979
+ var _EventInterface6 = EventInterface(Splide2),
2980
+ on = _EventInterface6.on,
2981
+ bind = _EventInterface6.bind,
2982
+ emit = _EventInterface6.emit;
2983
+
2984
+ var interval = RequestInterval(options.interval, Splide2.go.bind(Splide2, ">"), onAnimationFrame);
2985
+ var isPaused = interval.isPaused;
2986
+ var Elements = Components2.Elements,
2987
+ _Components2$Elements4 = Components2.Elements,
2988
+ root = _Components2$Elements4.root,
2989
+ toggle = _Components2$Elements4.toggle;
2990
+ var autoplay = options.autoplay;
2991
+ var hovered;
2992
+ var focused;
2993
+ var stopped = autoplay === "pause";
2994
+
2995
+ function mount() {
2996
+ if (autoplay) {
2997
+ listen();
2998
+ toggle && setAttribute(toggle, ARIA_CONTROLS, Elements.track.id);
2999
+ stopped || play();
3000
+ update();
3001
+ }
3002
+ }
3003
+
3004
+ function listen() {
3005
+ if (options.pauseOnHover) {
3006
+ bind(root, "mouseenter mouseleave", function (e) {
3007
+ hovered = e.type === "mouseenter";
3008
+ autoToggle();
3009
+ });
3010
+ }
3011
+
3012
+ if (options.pauseOnFocus) {
3013
+ bind(root, "focusin focusout", function (e) {
3014
+ focused = e.type === "focusin";
3015
+ autoToggle();
3016
+ });
3017
+ }
3018
+
3019
+ if (toggle) {
3020
+ bind(toggle, "click", function () {
3021
+ stopped ? play() : pause(true);
3022
+ });
3023
+ }
3024
+
3025
+ on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
3026
+ on(EVENT_MOVE, onMove);
3027
+ }
3028
+
3029
+ function play() {
3030
+ if (isPaused() && Components2.Slides.isEnough()) {
3031
+ interval.start(!options.resetProgress);
3032
+ focused = hovered = stopped = false;
3033
+ update();
3034
+ emit(EVENT_AUTOPLAY_PLAY);
3035
+ }
3036
+ }
3037
+
3038
+ function pause(stop) {
3039
+ if (stop === void 0) {
3040
+ stop = true;
3041
+ }
3042
+
3043
+ stopped = !!stop;
3044
+ update();
3045
+
3046
+ if (!isPaused()) {
3047
+ interval.pause();
3048
+ emit(EVENT_AUTOPLAY_PAUSE);
3049
+ }
3050
+ }
3051
+
3052
+ function autoToggle() {
3053
+ if (!stopped) {
3054
+ hovered || focused ? pause(false) : play();
3055
+ }
3056
+ }
3057
+
3058
+ function update() {
3059
+ if (toggle) {
3060
+ toggleClass(toggle, CLASS_ACTIVE, !stopped);
3061
+ setAttribute(toggle, ARIA_LABEL, options.i18n[stopped ? "play" : "pause"]);
3062
+ }
3063
+ }
3064
+
3065
+ function onAnimationFrame(rate) {
3066
+ var bar = Elements.bar;
3067
+ bar && style(bar, "width", rate * 100 + "%");
3068
+ emit(EVENT_AUTOPLAY_PLAYING, rate);
3069
+ }
3070
+
3071
+ function onMove(index) {
3072
+ var Slide = Components2.Slides.getAt(index);
3073
+ interval.set(Slide && +getAttribute(Slide.slide, INTERVAL_DATA_ATTRIBUTE) || options.interval);
3074
+ }
3075
+
3076
+ return {
3077
+ mount: mount,
3078
+ destroy: interval.cancel,
3079
+ play: play,
3080
+ pause: pause,
3081
+ isPaused: isPaused
3082
+ };
3083
+ }
3084
+
3085
+ function Cover(Splide2, Components2, options) {
3086
+ var _EventInterface7 = EventInterface(Splide2),
3087
+ on = _EventInterface7.on;
3088
+
3089
+ function mount() {
3090
+ if (options.cover) {
3091
+ on(EVENT_LAZYLOAD_LOADED, apply(toggle, true));
3092
+ on([EVENT_MOUNTED, EVENT_UPDATED, EVENT_REFRESH], apply(cover, true));
3093
+ }
3094
+ }
3095
+
3096
+ function cover(cover2) {
3097
+ Components2.Slides.forEach(function (Slide) {
3098
+ var img = child(Slide.container || Slide.slide, "img");
3099
+
3100
+ if (img && img.src) {
3101
+ toggle(cover2, img, Slide);
3102
+ }
3103
+ });
3104
+ }
3105
+
3106
+ function toggle(cover2, img, Slide) {
3107
+ Slide.style("background", cover2 ? "center/cover no-repeat url(\"" + img.src + "\")" : "", true);
3108
+ display(img, cover2 ? "none" : "");
3109
+ }
3110
+
3111
+ return {
3112
+ mount: mount,
3113
+ destroy: apply(cover, false)
3114
+ };
3115
+ }
3116
+
3117
+ var BOUNCE_DIFF_THRESHOLD = 10;
3118
+ var BOUNCE_DURATION = 600;
3119
+ var FRICTION_FACTOR = 0.6;
3120
+ var BASE_VELOCITY = 1.5;
3121
+ var MIN_DURATION = 800;
3122
+
3123
+ function Scroll(Splide2, Components2, options) {
3124
+ var _EventInterface8 = EventInterface(Splide2),
3125
+ on = _EventInterface8.on,
3126
+ emit = _EventInterface8.emit;
3127
+
3128
+ var set = Splide2.state.set;
3129
+ var Move = Components2.Move;
3130
+ var getPosition = Move.getPosition,
3131
+ getLimit = Move.getLimit,
3132
+ exceededLimit = Move.exceededLimit,
3133
+ translate = Move.translate;
3134
+ var isSlide = Splide2.is(SLIDE);
3135
+ var interval;
3136
+ var callback;
3137
+ var friction = 1;
3138
+
3139
+ function mount() {
3140
+ on(EVENT_MOVE, clear);
3141
+ on([EVENT_UPDATED, EVENT_REFRESH], cancel);
3142
+ }
3143
+
3144
+ function scroll(destination, duration, snap, onScrolled, noConstrain) {
3145
+ var from = getPosition();
3146
+ clear();
3147
+
3148
+ if (snap && (!isSlide || !exceededLimit())) {
3149
+ var size = Components2.Layout.sliderSize();
3150
+ var offset = sign(destination) * size * floor(abs(destination) / size) || 0;
3151
+ destination = Move.toPosition(Components2.Controller.toDest(destination % size)) + offset;
3152
+ }
3153
+
3154
+ var noDistance = approximatelyEqual(from, destination, 1);
3155
+ friction = 1;
3156
+ duration = noDistance ? 0 : duration || max(abs(destination - from) / BASE_VELOCITY, MIN_DURATION);
3157
+ callback = onScrolled;
3158
+ interval = RequestInterval(duration, onEnd, apply(update, from, destination, noConstrain), 1);
3159
+ set(SCROLLING);
3160
+ emit(EVENT_SCROLL);
3161
+ interval.start();
3162
+ }
3163
+
3164
+ function onEnd() {
3165
+ set(IDLE);
3166
+ callback && callback();
3167
+ emit(EVENT_SCROLLED);
3168
+ }
3169
+
3170
+ function update(from, to, noConstrain, rate) {
3171
+ var position = getPosition();
3172
+ var target = from + (to - from) * easing(rate);
3173
+ var diff = (target - position) * friction;
3174
+ translate(position + diff);
3175
+
3176
+ if (isSlide && !noConstrain && exceededLimit()) {
3177
+ friction *= FRICTION_FACTOR;
3178
+
3179
+ if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
3180
+ scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, callback, true);
3181
+ }
3182
+ }
3183
+ }
3184
+
3185
+ function clear() {
3186
+ if (interval) {
3187
+ interval.cancel();
3188
+ }
3189
+ }
3190
+
3191
+ function cancel() {
3192
+ if (interval && !interval.isPaused()) {
3193
+ clear();
3194
+ onEnd();
3195
+ }
3196
+ }
3197
+
3198
+ function easing(t) {
3199
+ var easingFunc = options.easingFunc;
3200
+ return easingFunc ? easingFunc(t) : 1 - Math.pow(1 - t, 4);
3201
+ }
3202
+
3203
+ return {
3204
+ mount: mount,
3205
+ destroy: clear,
3206
+ scroll: scroll,
3207
+ cancel: cancel
3208
+ };
3209
+ }
3210
+
3211
+ var SCROLL_LISTENER_OPTIONS = {
3212
+ passive: false,
3213
+ capture: true
3214
+ };
3215
+
3216
+ function Drag(Splide2, Components2, options) {
3217
+ var _EventInterface9 = EventInterface(Splide2),
3218
+ on = _EventInterface9.on,
3219
+ emit = _EventInterface9.emit,
3220
+ bind = _EventInterface9.bind,
3221
+ unbind = _EventInterface9.unbind;
3222
+
3223
+ var state = Splide2.state;
3224
+ var Move = Components2.Move,
3225
+ Scroll = Components2.Scroll,
3226
+ Controller = Components2.Controller,
3227
+ track = Components2.Elements.track,
3228
+ reduce = Components2.Media.reduce;
3229
+ var _Components2$Directio2 = Components2.Direction,
3230
+ resolve = _Components2$Directio2.resolve,
3231
+ orient = _Components2$Directio2.orient;
3232
+ var getPosition = Move.getPosition,
3233
+ exceededLimit = Move.exceededLimit;
3234
+ var basePosition;
3235
+ var baseEvent;
3236
+ var prevBaseEvent;
3237
+ var isFree;
3238
+ var dragging;
3239
+ var exceeded = false;
3240
+ var clickPrevented;
3241
+ var disabled;
3242
+ var target;
3243
+
3244
+ function mount() {
3245
+ bind(track, POINTER_MOVE_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
3246
+ bind(track, POINTER_UP_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
3247
+ bind(track, POINTER_DOWN_EVENTS, onPointerDown, SCROLL_LISTENER_OPTIONS);
3248
+ bind(track, "click", onClick, {
3249
+ capture: true
3250
+ });
3251
+ bind(track, "dragstart", prevent);
3252
+ on([EVENT_MOUNTED, EVENT_UPDATED], init);
3253
+ }
3254
+
3255
+ function init() {
3256
+ var drag = options.drag;
3257
+ disable(!drag);
3258
+ isFree = drag === "free";
3259
+ }
3260
+
3261
+ function onPointerDown(e) {
3262
+ clickPrevented = false;
3263
+
3264
+ if (!disabled) {
3265
+ var isTouch = isTouchEvent(e);
3266
+
3267
+ if (isDraggable(e.target) && (isTouch || !e.button)) {
3268
+ if (!Controller.isBusy()) {
3269
+ target = isTouch ? track : window;
3270
+ dragging = state.is([MOVING, SCROLLING]);
3271
+ prevBaseEvent = null;
3272
+ bind(target, POINTER_MOVE_EVENTS, onPointerMove, SCROLL_LISTENER_OPTIONS);
3273
+ bind(target, POINTER_UP_EVENTS, onPointerUp, SCROLL_LISTENER_OPTIONS);
3274
+ Move.cancel();
3275
+ Scroll.cancel();
3276
+ save(e);
3277
+ } else {
3278
+ prevent(e, true);
3279
+ }
3280
+ }
3281
+ }
3282
+ }
3283
+
3284
+ function onPointerMove(e) {
3285
+ if (!state.is(DRAGGING)) {
3286
+ state.set(DRAGGING);
3287
+ emit(EVENT_DRAG);
3288
+ }
3289
+
3290
+ if (e.cancelable) {
3291
+ if (dragging) {
3292
+ Move.translate(basePosition + constrain(diffCoord(e)));
3293
+ var expired = diffTime(e) > LOG_INTERVAL;
3294
+ var hasExceeded = exceeded !== (exceeded = exceededLimit());
3295
+
3296
+ if (expired || hasExceeded) {
3297
+ save(e);
3298
+ }
3299
+
3300
+ clickPrevented = true;
3301
+ emit(EVENT_DRAGGING);
3302
+ prevent(e);
3303
+ } else if (isSliderDirection(e)) {
3304
+ dragging = shouldStart(e);
3305
+ prevent(e);
3306
+ }
3307
+ }
3308
+ }
3309
+
3310
+ function onPointerUp(e) {
3311
+ if (state.is(DRAGGING)) {
3312
+ state.set(IDLE);
3313
+ emit(EVENT_DRAGGED);
3314
+ }
3315
+
3316
+ if (dragging) {
3317
+ move(e);
3318
+ prevent(e);
3319
+ }
3320
+
3321
+ unbind(target, POINTER_MOVE_EVENTS, onPointerMove);
3322
+ unbind(target, POINTER_UP_EVENTS, onPointerUp);
3323
+ dragging = false;
3324
+ }
3325
+
3326
+ function onClick(e) {
3327
+ if (!disabled && clickPrevented) {
3328
+ prevent(e, true);
3329
+ }
3330
+ }
3331
+
3332
+ function save(e) {
3333
+ prevBaseEvent = baseEvent;
3334
+ baseEvent = e;
3335
+ basePosition = getPosition();
3336
+ }
3337
+
3338
+ function move(e) {
3339
+ var velocity = computeVelocity(e);
3340
+ var destination = computeDestination(velocity);
3341
+ var rewind = options.rewind && options.rewindByDrag;
3342
+ reduce(false);
3343
+
3344
+ if (isFree) {
3345
+ Controller.scroll(destination, 0, options.snap);
3346
+ } else if (Splide2.is(FADE)) {
3347
+ Controller.go(orient(sign(velocity)) < 0 ? rewind ? "<" : "-" : rewind ? ">" : "+");
3348
+ } else if (Splide2.is(SLIDE) && exceeded && rewind) {
3349
+ Controller.go(exceededLimit(true) ? ">" : "<");
3350
+ } else {
3351
+ Controller.go(Controller.toDest(destination), true);
3352
+ }
3353
+
3354
+ reduce(true);
3355
+ }
3356
+
3357
+ function shouldStart(e) {
3358
+ var thresholds = options.dragMinThreshold;
3359
+ var isObj = isObject(thresholds);
3360
+ var mouse = isObj && thresholds.mouse || 0;
3361
+ var touch = (isObj ? thresholds.touch : +thresholds) || 10;
3362
+ return abs(diffCoord(e)) > (isTouchEvent(e) ? touch : mouse);
3363
+ }
3364
+
3365
+ function isSliderDirection(e) {
3366
+ return abs(diffCoord(e)) > abs(diffCoord(e, true));
3367
+ }
3368
+
3369
+ function computeVelocity(e) {
3370
+ if (Splide2.is(LOOP) || !exceeded) {
3371
+ var time = diffTime(e);
3372
+
3373
+ if (time && time < LOG_INTERVAL) {
3374
+ return diffCoord(e) / time;
3375
+ }
3376
+ }
3377
+
3378
+ return 0;
3379
+ }
3380
+
3381
+ function computeDestination(velocity) {
3382
+ return getPosition() + sign(velocity) * min(abs(velocity) * (options.flickPower || 600), isFree ? Infinity : Components2.Layout.listSize() * (options.flickMaxPages || 1));
3383
+ }
3384
+
3385
+ function diffCoord(e, orthogonal) {
3386
+ return coordOf(e, orthogonal) - coordOf(getBaseEvent(e), orthogonal);
3387
+ }
3388
+
3389
+ function diffTime(e) {
3390
+ return timeOf(e) - timeOf(getBaseEvent(e));
3391
+ }
3392
+
3393
+ function getBaseEvent(e) {
3394
+ return baseEvent === e && prevBaseEvent || baseEvent;
3395
+ }
3396
+
3397
+ function coordOf(e, orthogonal) {
3398
+ return (isTouchEvent(e) ? e.changedTouches[0] : e)["page" + resolve(orthogonal ? "Y" : "X")];
3399
+ }
3400
+
3401
+ function constrain(diff) {
3402
+ return diff / (exceeded && Splide2.is(SLIDE) ? FRICTION : 1);
3403
+ }
3404
+
3405
+ function isDraggable(target2) {
3406
+ var noDrag = options.noDrag;
3407
+ return !matches(target2, "." + CLASS_PAGINATION_PAGE + ", ." + CLASS_ARROW) && (!noDrag || !matches(target2, noDrag));
3408
+ }
3409
+
3410
+ function isTouchEvent(e) {
3411
+ return typeof TouchEvent !== "undefined" && e instanceof TouchEvent;
3412
+ }
3413
+
3414
+ function isDragging() {
3415
+ return dragging;
3416
+ }
3417
+
3418
+ function disable(value) {
3419
+ disabled = value;
3420
+ }
3421
+
3422
+ return {
3423
+ mount: mount,
3424
+ disable: disable,
3425
+ isDragging: isDragging
3426
+ };
3427
+ }
3428
+
3429
+ var NORMALIZATION_MAP = {
3430
+ Spacebar: " ",
3431
+ Right: ARROW_RIGHT,
3432
+ Left: ARROW_LEFT,
3433
+ Up: ARROW_UP,
3434
+ Down: ARROW_DOWN
3435
+ };
3436
+
3437
+ function normalizeKey(key) {
3438
+ key = isString(key) ? key : key.key;
3439
+ return NORMALIZATION_MAP[key] || key;
3440
+ }
3441
+
3442
+ var KEYBOARD_EVENT = "keydown";
3443
+
3444
+ function Keyboard(Splide2, Components2, options) {
3445
+ var _EventInterface10 = EventInterface(Splide2),
3446
+ on = _EventInterface10.on,
3447
+ bind = _EventInterface10.bind,
3448
+ unbind = _EventInterface10.unbind;
3449
+
3450
+ var root = Splide2.root;
3451
+ var resolve = Components2.Direction.resolve;
3452
+ var target;
3453
+ var disabled;
3454
+
3455
+ function mount() {
3456
+ init();
3457
+ on(EVENT_UPDATED, destroy);
3458
+ on(EVENT_UPDATED, init);
3459
+ on(EVENT_MOVE, onMove);
3460
+ }
3461
+
3462
+ function init() {
3463
+ var keyboard = options.keyboard;
3464
+
3465
+ if (keyboard) {
3466
+ target = keyboard === "global" ? window : root;
3467
+ bind(target, KEYBOARD_EVENT, onKeydown);
3468
+ }
3469
+ }
3470
+
3471
+ function destroy() {
3472
+ unbind(target, KEYBOARD_EVENT);
3473
+ }
3474
+
3475
+ function disable(value) {
3476
+ disabled = value;
3477
+ }
3478
+
3479
+ function onMove() {
3480
+ var _disabled = disabled;
3481
+ disabled = true;
3482
+ nextTick(function () {
3483
+ disabled = _disabled;
3484
+ });
3485
+ }
3486
+
3487
+ function onKeydown(e) {
3488
+ if (!disabled) {
3489
+ var key = normalizeKey(e);
3490
+
3491
+ if (key === resolve(ARROW_LEFT)) {
3492
+ Splide2.go("<");
3493
+ } else if (key === resolve(ARROW_RIGHT)) {
3494
+ Splide2.go(">");
3495
+ }
3496
+ }
3497
+ }
3498
+
3499
+ return {
3500
+ mount: mount,
3501
+ destroy: destroy,
3502
+ disable: disable
3503
+ };
3504
+ }
3505
+
3506
+ var SRC_DATA_ATTRIBUTE = DATA_ATTRIBUTE + "-lazy";
3507
+ var SRCSET_DATA_ATTRIBUTE = SRC_DATA_ATTRIBUTE + "-srcset";
3508
+ var IMAGE_SELECTOR = "[" + SRC_DATA_ATTRIBUTE + "], [" + SRCSET_DATA_ATTRIBUTE + "]";
3509
+
3510
+ function LazyLoad(Splide2, Components2, options) {
3511
+ var _EventInterface11 = EventInterface(Splide2),
3512
+ on = _EventInterface11.on,
3513
+ off = _EventInterface11.off,
3514
+ bind = _EventInterface11.bind,
3515
+ emit = _EventInterface11.emit;
3516
+
3517
+ var isSequential = options.lazyLoad === "sequential";
3518
+ var events = [EVENT_MOVED, EVENT_SCROLLED];
3519
+ var entries = [];
3520
+
3521
+ function mount() {
3522
+ if (options.lazyLoad) {
3523
+ init();
3524
+ on(EVENT_REFRESH, init);
3525
+ }
3526
+ }
3527
+
3528
+ function init() {
3529
+ empty(entries);
3530
+ register();
3531
+
3532
+ if (isSequential) {
3533
+ loadNext();
3534
+ } else {
3535
+ off(events);
3536
+ on(events, check);
3537
+ check();
3538
+ }
3539
+ }
3540
+
3541
+ function register() {
3542
+ Components2.Slides.forEach(function (Slide) {
3543
+ queryAll(Slide.slide, IMAGE_SELECTOR).forEach(function (img) {
3544
+ var src = getAttribute(img, SRC_DATA_ATTRIBUTE);
3545
+ var srcset = getAttribute(img, SRCSET_DATA_ATTRIBUTE);
3546
+
3547
+ if (src !== img.src || srcset !== img.srcset) {
3548
+ var className = options.classes.spinner;
3549
+ var parent = img.parentElement;
3550
+ var spinner = child(parent, "." + className) || create("span", className, parent);
3551
+ entries.push([img, Slide, spinner]);
3552
+ img.src || display(img, "none");
3553
+ }
3554
+ });
3555
+ });
3556
+ }
3557
+
3558
+ function check() {
3559
+ entries = entries.filter(function (data) {
3560
+ var distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
3561
+ return data[1].isWithin(Splide2.index, distance) ? load(data) : true;
3562
+ });
3563
+ entries.length || off(events);
3564
+ }
3565
+
3566
+ function load(data) {
3567
+ var img = data[0];
3568
+ addClass(data[1].slide, CLASS_LOADING);
3569
+ bind(img, "load error", apply(onLoad, data));
3570
+ setAttribute(img, "src", getAttribute(img, SRC_DATA_ATTRIBUTE));
3571
+ setAttribute(img, "srcset", getAttribute(img, SRCSET_DATA_ATTRIBUTE));
3572
+ removeAttribute(img, SRC_DATA_ATTRIBUTE);
3573
+ removeAttribute(img, SRCSET_DATA_ATTRIBUTE);
3574
+ }
3575
+
3576
+ function onLoad(data, e) {
3577
+ var img = data[0],
3578
+ Slide = data[1];
3579
+ removeClass(Slide.slide, CLASS_LOADING);
3580
+
3581
+ if (e.type !== "error") {
3582
+ remove(data[2]);
3583
+ display(img, "");
3584
+ emit(EVENT_LAZYLOAD_LOADED, img, Slide);
3585
+ emit(EVENT_RESIZE);
3586
+ }
3587
+
3588
+ isSequential && loadNext();
3589
+ }
3590
+
3591
+ function loadNext() {
3592
+ entries.length && load(entries.shift());
3593
+ }
3594
+
3595
+ return {
3596
+ mount: mount,
3597
+ destroy: apply(empty, entries),
3598
+ check: check
3599
+ };
3600
+ }
3601
+
3602
+ function Pagination(Splide2, Components2, options) {
3603
+ var event = EventInterface(Splide2);
3604
+ var on = event.on,
3605
+ emit = event.emit,
3606
+ bind = event.bind;
3607
+ var Slides = Components2.Slides,
3608
+ Elements = Components2.Elements,
3609
+ Controller = Components2.Controller;
3610
+ var hasFocus = Controller.hasFocus,
3611
+ getIndex = Controller.getIndex,
3612
+ go = Controller.go;
3613
+ var resolve = Components2.Direction.resolve;
3614
+ var placeholder = Elements.pagination;
3615
+ var items = [];
3616
+ var list;
3617
+ var paginationClasses;
3618
+
3619
+ function mount() {
3620
+ destroy();
3621
+ on([EVENT_UPDATED, EVENT_REFRESH, EVENT_END_INDEX_CHANGED], mount);
3622
+ var enabled = options.pagination;
3623
+ placeholder && display(placeholder, enabled ? "" : "none");
3624
+
3625
+ if (enabled) {
3626
+ on([EVENT_MOVE, EVENT_SCROLL, EVENT_SCROLLED], update);
3627
+ createPagination();
3628
+ update();
3629
+ emit(EVENT_PAGINATION_MOUNTED, {
3630
+ list: list,
3631
+ items: items
3632
+ }, getAt(Splide2.index));
3633
+ }
3634
+ }
3635
+
3636
+ function destroy() {
3637
+ if (list) {
3638
+ remove(placeholder ? slice(list.children) : list);
3639
+ removeClass(list, paginationClasses);
3640
+ empty(items);
3641
+ list = null;
3642
+ }
3643
+
3644
+ event.destroy();
3645
+ }
3646
+
3647
+ function createPagination() {
3648
+ var length = Splide2.length;
3649
+ var classes = options.classes,
3650
+ i18n = options.i18n,
3651
+ perPage = options.perPage;
3652
+ var max = hasFocus() ? Controller.getEnd() + 1 : ceil(length / perPage);
3653
+ list = placeholder || create("ul", classes.pagination, Elements.track.parentElement);
3654
+ addClass(list, paginationClasses = CLASS_PAGINATION + "--" + getDirection());
3655
+ setAttribute(list, ROLE, "tablist");
3656
+ setAttribute(list, ARIA_LABEL, i18n.select);
3657
+ setAttribute(list, ARIA_ORIENTATION, getDirection() === TTB ? "vertical" : "");
3658
+
3659
+ for (var i = 0; i < max; i++) {
3660
+ var li = create("li", null, list);
3661
+ var button = create("button", {
3662
+ class: classes.page,
3663
+ type: "button"
3664
+ }, li);
3665
+ var controls = Slides.getIn(i).map(function (Slide) {
3666
+ return Slide.slide.id;
3667
+ });
3668
+ var text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
3669
+ bind(button, "click", apply(onClick, i));
3670
+
3671
+ if (options.paginationKeyboard) {
3672
+ bind(button, "keydown", apply(onKeydown, i));
3673
+ }
3674
+
3675
+ setAttribute(li, ROLE, "presentation");
3676
+ setAttribute(button, ROLE, "tab");
3677
+ setAttribute(button, ARIA_CONTROLS, controls.join(" "));
3678
+ setAttribute(button, ARIA_LABEL, format(text, i + 1));
3679
+ setAttribute(button, TAB_INDEX, -1);
3680
+ items.push({
3681
+ li: li,
3682
+ button: button,
3683
+ page: i
3684
+ });
3685
+ }
3686
+ }
3687
+
3688
+ function onClick(page) {
3689
+ go(">" + page, true);
3690
+ }
3691
+
3692
+ function onKeydown(page, e) {
3693
+ var length = items.length;
3694
+ var key = normalizeKey(e);
3695
+ var dir = getDirection();
3696
+ var nextPage = -1;
3697
+
3698
+ if (key === resolve(ARROW_RIGHT, false, dir)) {
3699
+ nextPage = ++page % length;
3700
+ } else if (key === resolve(ARROW_LEFT, false, dir)) {
3701
+ nextPage = (--page + length) % length;
3702
+ } else if (key === "Home") {
3703
+ nextPage = 0;
3704
+ } else if (key === "End") {
3705
+ nextPage = length - 1;
3706
+ }
3707
+
3708
+ var item = items[nextPage];
3709
+
3710
+ if (item) {
3711
+ focus(item.button);
3712
+ go(">" + nextPage);
3713
+ prevent(e, true);
3714
+ }
3715
+ }
3716
+
3717
+ function getDirection() {
3718
+ return options.paginationDirection || options.direction;
3719
+ }
3720
+
3721
+ function getAt(index) {
3722
+ return items[Controller.toPage(index)];
3723
+ }
3724
+
3725
+ function update() {
3726
+ var prev = getAt(getIndex(true));
3727
+ var curr = getAt(getIndex());
3728
+
3729
+ if (prev) {
3730
+ var button = prev.button;
3731
+ removeClass(button, CLASS_ACTIVE);
3732
+ removeAttribute(button, ARIA_SELECTED);
3733
+ setAttribute(button, TAB_INDEX, -1);
3734
+ }
3735
+
3736
+ if (curr) {
3737
+ var _button = curr.button;
3738
+ addClass(_button, CLASS_ACTIVE);
3739
+ setAttribute(_button, ARIA_SELECTED, true);
3740
+ setAttribute(_button, TAB_INDEX, "");
3741
+ }
3742
+
3743
+ emit(EVENT_PAGINATION_UPDATED, {
3744
+ list: list,
3745
+ items: items
3746
+ }, prev, curr);
3747
+ }
3748
+
3749
+ return {
3750
+ items: items,
3751
+ mount: mount,
3752
+ destroy: destroy,
3753
+ getAt: getAt,
3754
+ update: update
3755
+ };
3756
+ }
3757
+
3758
+ var TRIGGER_KEYS = [" ", "Enter"];
3759
+
3760
+ function Sync(Splide2, Components2, options) {
3761
+ var isNavigation = options.isNavigation,
3762
+ slideFocus = options.slideFocus;
3763
+ var events = [];
3764
+
3765
+ function mount() {
3766
+ Splide2.splides.forEach(function (target) {
3767
+ if (!target.isParent) {
3768
+ sync(Splide2, target.splide);
3769
+ sync(target.splide, Splide2);
3770
+ }
3771
+ });
3772
+
3773
+ if (isNavigation) {
3774
+ navigate();
3775
+ }
3776
+ }
3777
+
3778
+ function destroy() {
3779
+ events.forEach(function (event) {
3780
+ event.destroy();
3781
+ });
3782
+ empty(events);
3783
+ }
3784
+
3785
+ function remount() {
3786
+ destroy();
3787
+ mount();
3788
+ }
3789
+
3790
+ function sync(splide, target) {
3791
+ var event = EventInterface(splide);
3792
+ event.on(EVENT_MOVE, function (index, prev, dest) {
3793
+ target.go(target.is(LOOP) ? dest : index);
3794
+ });
3795
+ events.push(event);
3796
+ }
3797
+
3798
+ function navigate() {
3799
+ var event = EventInterface(Splide2);
3800
+ var on = event.on;
3801
+ on(EVENT_CLICK, onClick);
3802
+ on(EVENT_SLIDE_KEYDOWN, onKeydown);
3803
+ on([EVENT_MOUNTED, EVENT_UPDATED], update);
3804
+ events.push(event);
3805
+ event.emit(EVENT_NAVIGATION_MOUNTED, Splide2.splides);
3806
+ }
3807
+
3808
+ function update() {
3809
+ setAttribute(Components2.Elements.list, ARIA_ORIENTATION, options.direction === TTB ? "vertical" : "");
3810
+ }
3811
+
3812
+ function onClick(Slide) {
3813
+ Splide2.go(Slide.index);
3814
+ }
3815
+
3816
+ function onKeydown(Slide, e) {
3817
+ if (includes(TRIGGER_KEYS, normalizeKey(e))) {
3818
+ onClick(Slide);
3819
+ prevent(e);
3820
+ }
3821
+ }
3822
+
3823
+ return {
3824
+ setup: apply(Components2.Media.set, {
3825
+ slideFocus: isUndefined(slideFocus) ? isNavigation : slideFocus
3826
+ }, true),
3827
+ mount: mount,
3828
+ destroy: destroy,
3829
+ remount: remount
3830
+ };
3831
+ }
3832
+
3833
+ function Wheel(Splide2, Components2, options) {
3834
+ var _EventInterface12 = EventInterface(Splide2),
3835
+ bind = _EventInterface12.bind;
3836
+
3837
+ var lastTime = 0;
3838
+
3839
+ function mount() {
3840
+ if (options.wheel) {
3841
+ bind(Components2.Elements.track, "wheel", onWheel, SCROLL_LISTENER_OPTIONS);
3842
+ }
3843
+ }
3844
+
3845
+ function onWheel(e) {
3846
+ if (e.cancelable) {
3847
+ var deltaY = e.deltaY;
3848
+ var backwards = deltaY < 0;
3849
+ var timeStamp = timeOf(e);
3850
+
3851
+ var _min = options.wheelMinThreshold || 0;
3852
+
3853
+ var sleep = options.wheelSleep || 0;
3854
+
3855
+ if (abs(deltaY) > _min && timeStamp - lastTime > sleep) {
3856
+ Splide2.go(backwards ? "<" : ">");
3857
+ lastTime = timeStamp;
3858
+ }
3859
+
3860
+ shouldPrevent(backwards) && prevent(e);
3861
+ }
3862
+ }
3863
+
3864
+ function shouldPrevent(backwards) {
3865
+ return !options.releaseWheel || Splide2.state.is(MOVING) || Components2.Controller.getAdjacent(backwards) !== -1;
3866
+ }
3867
+
3868
+ return {
3869
+ mount: mount
3870
+ };
3871
+ }
3872
+
3873
+ var SR_REMOVAL_DELAY = 90;
3874
+
3875
+ function Live(Splide2, Components2, options) {
3876
+ var _EventInterface13 = EventInterface(Splide2),
3877
+ on = _EventInterface13.on;
3878
+
3879
+ var track = Components2.Elements.track;
3880
+ var enabled = options.live && !options.isNavigation;
3881
+ var sr = create("span", CLASS_SR);
3882
+ var interval = RequestInterval(SR_REMOVAL_DELAY, apply(toggle, false));
3883
+
3884
+ function mount() {
3885
+ if (enabled) {
3886
+ disable(!Components2.Autoplay.isPaused());
3887
+ setAttribute(track, ARIA_ATOMIC, true);
3888
+ sr.textContent = "\u2026";
3889
+ on(EVENT_AUTOPLAY_PLAY, apply(disable, true));
3890
+ on(EVENT_AUTOPLAY_PAUSE, apply(disable, false));
3891
+ on([EVENT_MOVED, EVENT_SCROLLED], apply(toggle, true));
3892
+ }
3893
+ }
3894
+
3895
+ function toggle(active) {
3896
+ setAttribute(track, ARIA_BUSY, active);
3897
+
3898
+ if (active) {
3899
+ append(track, sr);
3900
+ interval.start();
3901
+ } else {
3902
+ remove(sr);
3903
+ interval.cancel();
3904
+ }
3905
+ }
3906
+
3907
+ function destroy() {
3908
+ removeAttribute(track, [ARIA_LIVE, ARIA_ATOMIC, ARIA_BUSY]);
3909
+ remove(sr);
3910
+ }
3911
+
3912
+ function disable(disabled) {
3913
+ if (enabled) {
3914
+ setAttribute(track, ARIA_LIVE, disabled ? "off" : "polite");
3915
+ }
3916
+ }
3917
+
3918
+ return {
3919
+ mount: mount,
3920
+ disable: disable,
3921
+ destroy: destroy
3922
+ };
3923
+ }
3924
+
3925
+ var ComponentConstructors = /*#__PURE__*/Object.freeze({
3926
+ __proto__: null,
3927
+ Media: Media,
3928
+ Direction: Direction,
3929
+ Elements: Elements,
3930
+ Slides: Slides,
3931
+ Layout: Layout,
3932
+ Clones: Clones,
3933
+ Move: Move,
3934
+ Controller: Controller,
3935
+ Arrows: Arrows,
3936
+ Autoplay: Autoplay,
3937
+ Cover: Cover,
3938
+ Scroll: Scroll,
3939
+ Drag: Drag,
3940
+ Keyboard: Keyboard,
3941
+ LazyLoad: LazyLoad,
3942
+ Pagination: Pagination,
3943
+ Sync: Sync,
3944
+ Wheel: Wheel,
3945
+ Live: Live
3946
+ });
3947
+ var I18N = {
3948
+ prev: "Previous slide",
3949
+ next: "Next slide",
3950
+ first: "Go to first slide",
3951
+ last: "Go to last slide",
3952
+ slideX: "Go to slide %s",
3953
+ pageX: "Go to page %s",
3954
+ play: "Start autoplay",
3955
+ pause: "Pause autoplay",
3956
+ carousel: "carousel",
3957
+ slide: "slide",
3958
+ select: "Select a slide to show",
3959
+ slideLabel: "%s of %s"
3960
+ };
3961
+ var DEFAULTS = {
3962
+ type: "slide",
3963
+ role: "region",
3964
+ speed: 400,
3965
+ perPage: 1,
3966
+ cloneStatus: true,
3967
+ arrows: true,
3968
+ pagination: true,
3969
+ paginationKeyboard: true,
3970
+ interval: 5e3,
3971
+ pauseOnHover: true,
3972
+ pauseOnFocus: true,
3973
+ resetProgress: true,
3974
+ easing: "cubic-bezier(0.25, 1, 0.5, 1)",
3975
+ drag: true,
3976
+ direction: "ltr",
3977
+ trimSpace: true,
3978
+ focusableNodes: "a, button, textarea, input, select, iframe",
3979
+ live: true,
3980
+ classes: CLASSES,
3981
+ i18n: I18N,
3982
+ reducedMotion: {
3983
+ speed: 0,
3984
+ rewindSpeed: 0,
3985
+ autoplay: "pause"
3986
+ }
3987
+ };
3988
+
3989
+ function Fade(Splide2, Components2, options) {
3990
+ var Slides = Components2.Slides;
3991
+
3992
+ function mount() {
3993
+ EventInterface(Splide2).on([EVENT_MOUNTED, EVENT_REFRESH], init);
3994
+ }
3995
+
3996
+ function init() {
3997
+ Slides.forEach(function (Slide) {
3998
+ Slide.style("transform", "translateX(-" + 100 * Slide.index + "%)");
3999
+ });
4000
+ }
4001
+
4002
+ function start(index, done) {
4003
+ Slides.style("transition", "opacity " + options.speed + "ms " + options.easing);
4004
+ nextTick(done);
4005
+ }
4006
+
4007
+ return {
4008
+ mount: mount,
4009
+ start: start,
4010
+ cancel: noop
4011
+ };
4012
+ }
4013
+
4014
+ function Slide(Splide2, Components2, options) {
4015
+ var Move = Components2.Move,
4016
+ Controller = Components2.Controller,
4017
+ Scroll = Components2.Scroll;
4018
+ var list = Components2.Elements.list;
4019
+ var transition = apply(style, list, "transition");
4020
+ var endCallback;
4021
+
4022
+ function mount() {
4023
+ EventInterface(Splide2).bind(list, "transitionend", function (e) {
4024
+ if (e.target === list && endCallback) {
4025
+ cancel();
4026
+ endCallback();
4027
+ }
4028
+ });
4029
+ }
4030
+
4031
+ function start(index, done) {
4032
+ var destination = Move.toPosition(index, true);
4033
+ var position = Move.getPosition();
4034
+ var speed = getSpeed(index);
4035
+
4036
+ if (abs(destination - position) >= 1 && speed >= 1) {
4037
+ if (options.useScroll) {
4038
+ Scroll.scroll(destination, speed, false, done);
4039
+ } else {
4040
+ transition("transform " + speed + "ms " + options.easing);
4041
+ Move.translate(destination, true);
4042
+ endCallback = done;
4043
+ }
4044
+ } else {
4045
+ Move.jump(index);
4046
+ done();
4047
+ }
4048
+ }
4049
+
4050
+ function cancel() {
4051
+ transition("");
4052
+ Scroll.cancel();
4053
+ }
4054
+
4055
+ function getSpeed(index) {
4056
+ var rewindSpeed = options.rewindSpeed;
4057
+
4058
+ if (Splide2.is(SLIDE) && rewindSpeed) {
4059
+ var prev = Controller.getIndex(true);
4060
+ var end = Controller.getEnd();
4061
+
4062
+ if (prev === 0 && index >= end || prev >= end && index === 0) {
4063
+ return rewindSpeed;
4064
+ }
4065
+ }
4066
+
4067
+ return options.speed;
4068
+ }
4069
+
4070
+ return {
4071
+ mount: mount,
4072
+ start: start,
4073
+ cancel: cancel
4074
+ };
4075
+ }
4076
+
4077
+ var _Splide = /*#__PURE__*/function () {
4078
+ function _Splide(target, options) {
4079
+ this.event = EventInterface();
4080
+ this.Components = {};
4081
+ this.state = State(CREATED);
4082
+ this.splides = [];
4083
+ this._o = {};
4084
+ this._E = {};
4085
+ var root = isString(target) ? query(document, target) : target;
4086
+ assert(root, root + " is invalid.");
4087
+ this.root = root;
4088
+ options = merge({
4089
+ label: getAttribute(root, ARIA_LABEL) || "",
4090
+ labelledby: getAttribute(root, ARIA_LABELLEDBY) || ""
4091
+ }, DEFAULTS, _Splide.defaults, options || {});
4092
+
4093
+ try {
4094
+ merge(options, JSON.parse(getAttribute(root, DATA_ATTRIBUTE)));
4095
+ } catch (e) {
4096
+ assert(false, "Invalid JSON");
4097
+ }
4098
+
4099
+ this._o = Object.create(merge({}, options));
4100
+ }
4101
+
4102
+ var _proto = _Splide.prototype;
4103
+
4104
+ _proto.mount = function mount(Extensions, Transition) {
4105
+ var _this = this;
4106
+
4107
+ var state = this.state,
4108
+ Components2 = this.Components;
4109
+ assert(state.is([CREATED, DESTROYED]), "Already mounted!");
4110
+ state.set(CREATED);
4111
+ this._C = Components2;
4112
+ this._T = Transition || this._T || (this.is(FADE) ? Fade : Slide);
4113
+ this._E = Extensions || this._E;
4114
+ var Constructors = assign({}, ComponentConstructors, this._E, {
4115
+ Transition: this._T
4116
+ });
4117
+ forOwn(Constructors, function (Component, key) {
4118
+ var component = Component(_this, Components2, _this._o);
4119
+ Components2[key] = component;
4120
+ component.setup && component.setup();
4121
+ });
4122
+ forOwn(Components2, function (component) {
4123
+ component.mount && component.mount();
4124
+ });
4125
+ this.emit(EVENT_MOUNTED);
4126
+ addClass(this.root, CLASS_INITIALIZED);
4127
+ state.set(IDLE);
4128
+ this.emit(EVENT_READY);
4129
+ return this;
4130
+ };
4131
+
4132
+ _proto.sync = function sync(splide) {
4133
+ this.splides.push({
4134
+ splide: splide
4135
+ });
4136
+ splide.splides.push({
4137
+ splide: this,
4138
+ isParent: true
4139
+ });
4140
+
4141
+ if (this.state.is(IDLE)) {
4142
+ this._C.Sync.remount();
4143
+
4144
+ splide.Components.Sync.remount();
4145
+ }
4146
+
4147
+ return this;
4148
+ };
4149
+
4150
+ _proto.go = function go(control) {
4151
+ this._C.Controller.go(control);
4152
+
4153
+ return this;
4154
+ };
4155
+
4156
+ _proto.on = function on(events, callback) {
4157
+ this.event.on(events, callback);
4158
+ return this;
4159
+ };
4160
+
4161
+ _proto.off = function off(events) {
4162
+ this.event.off(events);
4163
+ return this;
4164
+ };
4165
+
4166
+ _proto.emit = function emit(event) {
4167
+ var _this$event;
4168
+
4169
+ (_this$event = this.event).emit.apply(_this$event, [event].concat(slice(arguments, 1)));
4170
+
4171
+ return this;
4172
+ };
4173
+
4174
+ _proto.add = function add(slides, index) {
4175
+ this._C.Slides.add(slides, index);
4176
+
4177
+ return this;
4178
+ };
4179
+
4180
+ _proto.remove = function remove(matcher) {
4181
+ this._C.Slides.remove(matcher);
4182
+
4183
+ return this;
4184
+ };
4185
+
4186
+ _proto.is = function is(type) {
4187
+ return this._o.type === type;
4188
+ };
4189
+
4190
+ _proto.refresh = function refresh() {
4191
+ this.emit(EVENT_REFRESH);
4192
+ return this;
4193
+ };
4194
+
4195
+ _proto.destroy = function destroy(completely) {
4196
+ if (completely === void 0) {
4197
+ completely = true;
4198
+ }
4199
+
4200
+ var event = this.event,
4201
+ state = this.state;
4202
+
4203
+ if (state.is(CREATED)) {
4204
+ EventInterface(this).on(EVENT_READY, this.destroy.bind(this, completely));
4205
+ } else {
4206
+ forOwn(this._C, function (component) {
4207
+ component.destroy && component.destroy(completely);
4208
+ }, true);
4209
+ event.emit(EVENT_DESTROY);
4210
+ event.destroy();
4211
+ completely && empty(this.splides);
4212
+ state.set(DESTROYED);
4213
+ }
4214
+
4215
+ return this;
4216
+ };
4217
+
4218
+ _createClass(_Splide, [{
4219
+ key: "options",
4220
+ get: function get() {
4221
+ return this._o;
4222
+ },
4223
+ set: function set(options) {
4224
+ this._C.Media.set(options, true, true);
4225
+ }
4226
+ }, {
4227
+ key: "length",
4228
+ get: function get() {
4229
+ return this._C.Slides.getLength(true);
4230
+ }
4231
+ }, {
4232
+ key: "index",
4233
+ get: function get() {
4234
+ return this._C.Controller.getIndex();
4235
+ }
4236
+ }]);
4237
+
4238
+ return _Splide;
4239
+ }();
4240
+
4241
+ var Splide = _Splide;
4242
+ Splide.defaults = {};
4243
+ Splide.STATES = STATES;
4244
+
4245
+ var collectionStyles = ".jaaq-collection-player {\n width: 100%;\n max-width: 1400px;\n margin: 0 auto;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;\n}\n\n.jaaq-collection-loading {\n display: flex;\n justify-content: center;\n align-items: center;\n min-height: 400px;\n}\n\n.jaaq-collection-spinner {\n width: 50px;\n height: 50px;\n border: 4px solid rgba(0, 123, 255, 0.3);\n border-top-color: #007bff;\n border-radius: 50%;\n animation: jaaq-collection-spin 1s linear infinite;\n}\n\n@keyframes jaaq-collection-spin {\n to {\n transform: rotate(360deg);\n }\n}\n\n.jaaq-collection-error {\n background: rgba(220, 53, 69, 0.9);\n color: white;\n padding: 16px 24px;\n border-radius: 8px;\n text-align: center;\n font-size: 14px;\n margin: 20px;\n}\n\n.jaaq-collection-carousel .splide__track {\n padding: 40px 0;\n}\n\n.jaaq-collection-carousel .splide__slide {\n opacity: 0.7;\n transition: all 0.3s ease;\n display: flex;\n align-items: center;\n justify-content: center;\n}\n\n.jaaq-collection-carousel .splide__slide.is-active {\n opacity: 1;\n}\n\n.jaaq-collection-carousel .splide__slide jaaq-video-player {\n width: 100%;\n max-width: 600px;\n transition: all 0.3s ease;\n}\n\n.jaaq-collection-carousel .splide__slide.is-active jaaq-video-player {\n max-width: 800px;\n}\n\n.jaaq-collection-carousel .splide__arrow {\n background: rgba(0, 0, 0, 0.5);\n border: none;\n width: 48px;\n height: 48px;\n border-radius: 50%;\n color: white;\n cursor: pointer;\n transition: all 0.2s;\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 20px;\n}\n\n.jaaq-collection-carousel .splide__arrow:hover {\n background: rgba(0, 0, 0, 0.8);\n transform: scale(1.1);\n}\n\n.jaaq-collection-carousel .splide__arrow:disabled {\n opacity: 0.3;\n cursor: not-allowed;\n}\n\n.jaaq-collection-carousel .splide__arrow svg {\n fill: white;\n width: 20px;\n height: 20px;\n}\n\n.jaaq-collection-carousel .splide__pagination {\n bottom: -30px;\n}\n\n.jaaq-collection-carousel .splide__pagination__page {\n background: #ccc;\n border: none;\n width: 10px;\n height: 10px;\n margin: 0 4px;\n border-radius: 50%;\n transition: all 0.2s;\n cursor: pointer;\n}\n\n.jaaq-collection-carousel .splide__pagination__page.is-active {\n background: white;\n transform: scale(1.3);\n}\n\n@media (max-width: 1024px) {\n .jaaq-collection-carousel .splide__slide jaaq-video-player {\n max-width: 500px;\n }\n\n .jaaq-collection-carousel .splide__slide.is-active jaaq-video-player {\n max-width: 650px;\n }\n}\n\n@media (max-width: 768px) {\n .jaaq-collection-carousel .splide__track {\n padding: 20px 0;\n }\n\n .jaaq-collection-carousel .splide__slide jaaq-video-player {\n max-width: 400px;\n }\n\n .jaaq-collection-carousel .splide__slide.is-active jaaq-video-player {\n max-width: 500px;\n }\n\n .jaaq-collection-carousel .splide__arrow {\n width: 40px;\n height: 40px;\n }\n}\n\n@media (max-width: 480px) {\n .jaaq-collection-carousel .splide__slide jaaq-video-player {\n max-width: 100%;\n }\n\n .jaaq-collection-carousel .splide__slide.is-active jaaq-video-player {\n max-width: 100%;\n }\n}\n";
4246
+
4247
+ var splideStyles = ".splide__container{box-sizing:border-box;position:relative}.splide__list{backface-visibility:hidden;display:-ms-flexbox;display:flex;height:100%;margin:0!important;padding:0!important}.splide.is-initialized:not(.is-active) .splide__list{display:block}.splide__pagination{-ms-flex-align:center;align-items:center;display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;-ms-flex-pack:center;justify-content:center;margin:0;pointer-events:none}.splide__pagination li{display:inline-block;line-height:1;list-style-type:none;margin:0;pointer-events:auto}.splide:not(.is-overflow) .splide__pagination{display:none}.splide__progress__bar{width:0}.splide{position:relative;visibility:hidden}.splide.is-initialized,.splide.is-rendered{visibility:visible}.splide__slide{backface-visibility:hidden;box-sizing:border-box;-ms-flex-negative:0;flex-shrink:0;list-style-type:none!important;margin:0;position:relative}.splide__slide img{vertical-align:bottom}.splide__spinner{animation:splide-loading 1s linear infinite;border:2px solid #999;border-left-color:transparent;border-radius:50%;bottom:0;contain:strict;display:inline-block;height:20px;left:0;margin:auto;position:absolute;right:0;top:0;width:20px}.splide__sr{clip:rect(0 0 0 0);border:0;height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.splide__toggle.is-active .splide__toggle__play,.splide__toggle__pause{display:none}.splide__toggle.is-active .splide__toggle__pause{display:inline}.splide__track{overflow:hidden;position:relative;z-index:0}@keyframes splide-loading{0%{transform:rotate(0)}to{transform:rotate(1turn)}}.splide__track--draggable{-webkit-touch-callout:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}.splide__track--fade>.splide__list>.splide__slide{margin:0!important;opacity:0;z-index:0}.splide__track--fade>.splide__list>.splide__slide.is-active{opacity:1;z-index:1}.splide--rtl{direction:rtl}.splide__track--ttb>.splide__list{display:block}.splide__arrow{-ms-flex-align:center;align-items:center;background:#ccc;border:0;border-radius:50%;cursor:pointer;display:-ms-flexbox;display:flex;height:2em;-ms-flex-pack:center;justify-content:center;opacity:.7;padding:0;position:absolute;top:50%;transform:translateY(-50%);width:2em;z-index:1}.splide__arrow svg{fill:#000;height:1.2em;width:1.2em}.splide__arrow:hover:not(:disabled){opacity:.9}.splide__arrow:disabled{opacity:.3}.splide__arrow:focus-visible{outline:3px solid #0bf;outline-offset:3px}.splide__arrow--prev{left:1em}.splide__arrow--prev svg{transform:scaleX(-1)}.splide__arrow--next{right:1em}.splide.is-focus-in .splide__arrow:focus{outline:3px solid #0bf;outline-offset:3px}.splide__pagination{bottom:.5em;left:0;padding:0 1em;position:absolute;right:0;z-index:1}.splide__pagination__page{background:#ccc;border:0;border-radius:50%;display:inline-block;height:8px;margin:3px;opacity:.7;padding:0;position:relative;transition:transform .2s linear;width:8px}.splide__pagination__page.is-active{background:#fff;transform:scale(1.4);z-index:1}.splide__pagination__page:hover{cursor:pointer;opacity:.9}.splide__pagination__page:focus-visible{outline:3px solid #0bf;outline-offset:3px}.splide.is-focus-in .splide__pagination__page:focus{outline:3px solid #0bf;outline-offset:3px}.splide__progress__bar{background:#ccc;height:3px}.splide__slide{-webkit-tap-highlight-color:rgba(0,0,0,0)}.splide__slide:focus{outline:0}@supports(outline-offset:-3px){.splide__slide:focus-visible{outline:3px solid #0bf;outline-offset:-3px}}@media screen and (-ms-high-contrast:none){.splide__slide:focus-visible{border:3px solid #0bf}}@supports(outline-offset:-3px){.splide.is-focus-in .splide__slide:focus{outline:3px solid #0bf;outline-offset:-3px}}@media screen and (-ms-high-contrast:none){.splide.is-focus-in .splide__slide:focus{border:3px solid #0bf}.splide.is-focus-in .splide__track>.splide__list>.splide__slide:focus{border-color:#0bf}}.splide__toggle{cursor:pointer}.splide__toggle:focus-visible{outline:3px solid #0bf;outline-offset:3px}.splide.is-focus-in .splide__toggle:focus{outline:3px solid #0bf;outline-offset:3px}.splide__track--nav>.splide__list>.splide__slide{border:3px solid transparent;cursor:pointer}.splide__track--nav>.splide__list>.splide__slide.is-active{border:3px solid #000}.splide__arrows--rtl .splide__arrow--prev{left:auto;right:1em}.splide__arrows--rtl .splide__arrow--prev svg{transform:scaleX(1)}.splide__arrows--rtl .splide__arrow--next{left:1em;right:auto}.splide__arrows--rtl .splide__arrow--next svg{transform:scaleX(-1)}.splide__arrows--ttb .splide__arrow{left:50%;transform:translate(-50%)}.splide__arrows--ttb .splide__arrow--prev{top:1em}.splide__arrows--ttb .splide__arrow--prev svg{transform:rotate(-90deg)}.splide__arrows--ttb .splide__arrow--next{bottom:1em;top:auto}.splide__arrows--ttb .splide__arrow--next svg{transform:rotate(90deg)}.splide__pagination--ttb{bottom:0;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;left:auto;padding:1em 0;right:.5em;top:0}";
4248
+
4249
+ const COMPONENT_STYLES = `
4250
+ :host {
4251
+ display: block;
4252
+ width: 100%;
4253
+ }
4254
+
4255
+ :host([hidden]) {
4256
+ display: none;
4257
+ }
4258
+ `;
4259
+ class JaaqCollectionPlayerElement extends HTMLElement {
4260
+ static get observedAttributes() {
4261
+ return ['collection-id', 'api-key', 'client-id', 'subscription-id', 'base-url', 'autoplay', 'show-arrows', 'show-dots'];
4262
+ }
4263
+ constructor() {
4264
+ super();
4265
+ this.splide = null;
4266
+ this.container = null;
4267
+ this.carouselElement = null;
4268
+ this.clientInstance = null;
4269
+ this.connected = false;
4270
+ this.collectionData = null;
4271
+ this.autoplayTimeoutId = null;
4272
+ this.attachShadow({ mode: 'open' });
4273
+ }
4274
+ connectedCallback() {
4275
+ this.connected = true;
4276
+ this.render();
4277
+ this.initCarousel();
4278
+ }
4279
+ disconnectedCallback() {
4280
+ this.connected = false;
4281
+ this.destroyCarousel();
4282
+ }
4283
+ attributeChangedCallback(name, oldValue, newValue) {
4284
+ if (!this.connected || oldValue === newValue)
4285
+ return;
4286
+ if (name === 'collection-id') {
4287
+ this.destroyCarousel();
4288
+ this.initCarousel();
4289
+ }
4290
+ if (name === 'show-arrows' || name === 'show-dots') {
4291
+ this.destroyCarousel();
4292
+ this.initCarousel();
4293
+ }
4294
+ }
4295
+ getBooleanAttr(name, defaultValue) {
4296
+ const v = this.getAttribute(name);
4297
+ if (v === null)
4298
+ return defaultValue;
4299
+ return v !== 'false';
4300
+ }
4301
+ render() {
4302
+ if (!this.shadowRoot)
4303
+ return;
4304
+ const styleSheet = document.createElement('style');
4305
+ styleSheet.textContent = `
4306
+ ${sharedStyles}
4307
+ ${collectionStyles}
4308
+ ${splideStyles}
4309
+ ${COMPONENT_STYLES}
4310
+ `;
4311
+ this.container = document.createElement('div');
4312
+ this.container.className = 'jaaq-collection-player';
4313
+ this.shadowRoot.appendChild(styleSheet);
4314
+ this.shadowRoot.appendChild(this.container);
4315
+ }
4316
+ async initCarousel() {
4317
+ if (!this.container)
4318
+ return;
4319
+ const collectionId = this.getAttribute('collection-id');
4320
+ if (!collectionId) {
4321
+ this.emitError(new Error('collection-id attribute is required'));
4322
+ return;
4323
+ }
4324
+ const apiKey = this.getAttribute('api-key');
4325
+ const clientId = this.getAttribute('client-id');
4326
+ const baseUrl = this.getAttribute('base-url') || undefined;
4327
+ if (!this.clientInstance && !apiKey && !clientId) {
4328
+ this.emitError(new Error('Either client property or api-key and client-id attributes are required'));
4329
+ return;
4330
+ }
4331
+ this.showLoading();
4332
+ try {
4333
+ const client = this.clientInstance ||
4334
+ JaaqClient.init({
4335
+ apiKey: apiKey,
4336
+ clientId: clientId,
4337
+ baseUrl: baseUrl || BASE_URL,
4338
+ });
4339
+ this.collectionData = await client.collections.getById(collectionId);
4340
+ if (!this.collectionData.videos || this.collectionData.videos.length === 0) {
4341
+ this.emitError(new Error('No videos found in collection'));
4342
+ return;
4343
+ }
4344
+ this.renderCarousel();
4345
+ this.initSplide();
4346
+ this.dispatchEvent(new CustomEvent('jaaq:collection:loaded', {
4347
+ detail: this.collectionData,
4348
+ bubbles: true,
4349
+ composed: true,
4350
+ }));
4351
+ }
4352
+ catch (error) {
4353
+ this.emitError(error instanceof Error ? error : new Error('Failed to load collection'));
4354
+ }
4355
+ }
4356
+ showLoading() {
4357
+ if (!this.container)
4358
+ return;
4359
+ this.container.innerHTML = `
4360
+ <div class="jaaq-collection-loading">
4361
+ <div class="jaaq-collection-spinner"></div>
4362
+ </div>
4363
+ `;
4364
+ }
4365
+ renderCarousel() {
4366
+ if (!this.container || !this.collectionData)
4367
+ return;
4368
+ this.container.innerHTML = '';
4369
+ this.carouselElement = document.createElement('div');
4370
+ this.carouselElement.className = 'splide jaaq-collection-carousel';
4371
+ const track = document.createElement('div');
4372
+ track.className = 'splide__track';
4373
+ const list = document.createElement('ul');
4374
+ list.className = 'splide__list';
4375
+ const apiKey = this.getAttribute('api-key');
4376
+ const clientId = this.getAttribute('client-id');
4377
+ const baseUrl = this.getAttribute('base-url');
4378
+ this.collectionData.videos.forEach((video) => {
4379
+ const slide = document.createElement('li');
4380
+ slide.className = 'splide__slide';
4381
+ const player = document.createElement('jaaq-video-player');
4382
+ player.setAttribute('video-id', video.videoId);
4383
+ if (apiKey)
4384
+ player.setAttribute('api-key', apiKey);
4385
+ if (clientId)
4386
+ player.setAttribute('client-id', clientId);
4387
+ if (baseUrl)
4388
+ player.setAttribute('base-url', baseUrl);
4389
+ player.setAttribute('autoplay', 'false');
4390
+ player.setAttribute('width', '100%');
4391
+ slide.appendChild(player);
4392
+ list.appendChild(slide);
4393
+ });
4394
+ track.appendChild(list);
4395
+ this.carouselElement.appendChild(track);
4396
+ this.container.appendChild(this.carouselElement);
4397
+ }
4398
+ initSplide() {
4399
+ if (!this.carouselElement)
4400
+ return;
4401
+ const showArrows = this.getBooleanAttr('show-arrows', true);
4402
+ const showDots = this.getBooleanAttr('show-dots', true);
4403
+ this.splide = new Splide(this.carouselElement, {
4404
+ type: 'loop',
4405
+ perPage: 3,
4406
+ focus: 'center',
4407
+ gap: '0.5rem',
4408
+ perMove: 1,
4409
+ autoHeight: true,
4410
+ updateOnMove: true,
4411
+ padding: '5 rem',
4412
+ breakpoints: {
4413
+ 768: {
4414
+ perPage: 1,
4415
+ },
4416
+ 1024: {
4417
+ perPage: 2,
4418
+ },
4419
+ },
4420
+ arrows: showArrows,
4421
+ pagination: showDots,
4422
+ autoplay: false,
4423
+ });
4424
+ this.splide.on('moved', (newIndex) => {
4425
+ console.log('[CollectionPlayer] Splide moved event', {
4426
+ newIndex,
4427
+ splideIndex: this.splide?.index,
4428
+ Components: this.splide?.Components,
4429
+ });
4430
+ this.handleSlideChange(newIndex);
4431
+ this.dispatchEvent(new CustomEvent('jaaq:collection:slidechange', {
4432
+ detail: { index: newIndex, video: this.collectionData?.videos[newIndex] },
4433
+ bubbles: true,
4434
+ composed: true,
4435
+ }));
4436
+ });
4437
+ this.splide.mount();
4438
+ console.log('[CollectionPlayer] After mount', {
4439
+ splideIndex: this.splide.index,
4440
+ length: this.splide.length,
4441
+ });
4442
+ setTimeout(() => {
4443
+ if (this.splide) {
4444
+ console.log('[CollectionPlayer] Initial handleSlideChange after DOM update');
4445
+ this.handleSlideChange(this.splide.index);
4446
+ }
4447
+ }, 100);
4448
+ }
4449
+ handleSlideChange(activeIndex) {
4450
+ if (!this.carouselElement)
4451
+ return;
4452
+ const isAutoplayEnabled = this.hasAttribute('autoplay') && this.getAttribute('autoplay') !== 'false';
4453
+ console.log('[CollectionPlayer] handleSlideChange called', { activeIndex, isAutoplayEnabled });
4454
+ if (this.autoplayTimeoutId !== null) {
4455
+ console.log('[CollectionPlayer] Clearing existing autoplay timeout', { timeoutId: this.autoplayTimeoutId });
4456
+ clearTimeout(this.autoplayTimeoutId);
4457
+ this.autoplayTimeoutId = null;
4458
+ }
4459
+ const activeSlide = this.carouselElement.querySelector('.splide__slide.is-active:not(.splide__slide--clone)');
4460
+ const activePlayer = activeSlide?.querySelector('jaaq-video-player');
4461
+ const activeVideoId = activePlayer?.getAttribute('video-id');
4462
+ console.log('[CollectionPlayer] Active slide from DOM:', {
4463
+ activeIndex,
4464
+ activeVideoId,
4465
+ foundActiveSlide: !!activeSlide,
4466
+ });
4467
+ const originalSlides = this.carouselElement.querySelectorAll('.splide__slide:not(.splide__slide--clone)');
4468
+ Array.from(originalSlides).map((slide, idx) => {
4469
+ const player = slide.querySelector('jaaq-video-player');
4470
+ const videoId = player?.getAttribute('video-id') || 'unknown';
4471
+ const isActive = slide.classList.contains('is-active');
4472
+ return {
4473
+ index: idx,
4474
+ videoId,
4475
+ isActive,
4476
+ };
4477
+ });
4478
+ originalSlides.forEach((slide, index) => {
4479
+ const player = slide.querySelector('jaaq-video-player');
4480
+ if (!player)
4481
+ return;
4482
+ const videoId = player.getAttribute('video-id');
4483
+ const isActive = slide.classList.contains('is-active');
4484
+ if (isActive) {
4485
+ if (isAutoplayEnabled) {
4486
+ this.autoplayTimeoutId = window.setTimeout(() => {
4487
+ console.log('[CollectionPlayer] 1s delay complete, playing video', {
4488
+ index,
4489
+ videoId,
4490
+ });
4491
+ player.play?.();
4492
+ }, 1000);
4493
+ }
4494
+ }
4495
+ else {
4496
+ player.pause?.();
4497
+ }
4498
+ });
4499
+ }
4500
+ destroyCarousel() {
4501
+ if (this.autoplayTimeoutId !== null) {
4502
+ clearTimeout(this.autoplayTimeoutId);
4503
+ this.autoplayTimeoutId = null;
4504
+ }
4505
+ if (this.splide) {
4506
+ this.splide.destroy();
4507
+ this.splide = null;
4508
+ }
4509
+ if (this.container) {
4510
+ this.container.innerHTML = '';
4511
+ }
4512
+ this.collectionData = null;
4513
+ }
4514
+ emitError(error) {
4515
+ if (this.container) {
4516
+ this.container.innerHTML = `
4517
+ <div class="jaaq-collection-error">
4518
+ ${error.message}
4519
+ </div>
4520
+ `;
4521
+ }
4522
+ this.dispatchEvent(new CustomEvent('jaaq:collection:error', {
4523
+ detail: error,
4524
+ bubbles: true,
4525
+ composed: true,
4526
+ }));
4527
+ }
4528
+ get client() {
4529
+ return this.clientInstance;
4530
+ }
4531
+ set client(value) {
4532
+ this.clientInstance = value;
4533
+ if (this.connected) {
4534
+ this.destroyCarousel();
4535
+ this.initCarousel();
4536
+ }
4537
+ }
4538
+ get collectionId() {
4539
+ return this.getAttribute('collection-id');
4540
+ }
4541
+ set collectionId(value) {
4542
+ if (value) {
4543
+ this.setAttribute('collection-id', value);
4544
+ }
4545
+ else {
4546
+ this.removeAttribute('collection-id');
4547
+ }
4548
+ }
4549
+ refresh() {
4550
+ this.destroyCarousel();
4551
+ this.initCarousel();
4552
+ }
4553
+ next() {
4554
+ this.splide?.go('+1');
4555
+ }
4556
+ prev() {
4557
+ this.splide?.go('-1');
4558
+ }
4559
+ go(index) {
4560
+ this.splide?.go(index);
4561
+ }
4562
+ destroy() {
4563
+ this.destroyCarousel();
4564
+ }
4565
+ getCollection() {
4566
+ return this.collectionData;
4567
+ }
4568
+ }
4569
+
4570
+ const COMPONENT_TAGS = {
4571
+ VIDEO_PLAYER: 'jaaq-video-player',
4572
+ COLLECTION_PLAYER: 'jaaq-collection-player',
4573
+ };
4574
+ /**
4575
+ * Registers JAAQ custom elements (<jaaq-video-player> and <jaaq-collection-player>)
4576
+ * Safe to call multiple times - only registers if not already registered
4577
+ *
4578
+ * @example
4579
+ * import { registerJaaqComponents } from '@jaaq/jaaq-sdk-js/ui/webcomponents';
4580
+ * registerJaaqComponents();
4581
+ */
4582
+ function registerJaaqComponents() {
4583
+ if (typeof window === 'undefined' || typeof customElements === 'undefined') {
4584
+ console.warn('Custom Elements API is not available. Web components cannot be registered.');
4585
+ return;
4586
+ }
4587
+ if (!customElements.get(COMPONENT_TAGS.VIDEO_PLAYER)) {
4588
+ customElements.define(COMPONENT_TAGS.VIDEO_PLAYER, JaaqVideoPlayerElement);
4589
+ }
4590
+ if (!customElements.get(COMPONENT_TAGS.COLLECTION_PLAYER)) {
4591
+ customElements.define(COMPONENT_TAGS.COLLECTION_PLAYER, JaaqCollectionPlayerElement);
4592
+ }
4593
+ }
4594
+ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
4595
+ if (document.readyState === 'loading') {
4596
+ document.addEventListener('DOMContentLoaded', () => {
4597
+ registerJaaqComponents();
4598
+ });
4599
+ }
4600
+ else {
4601
+ registerJaaqComponents();
4602
+ }
4603
+ }
4604
+
4605
+ if (typeof window !== 'undefined') {
4606
+ registerJaaqComponents();
4607
+ }
4608
+ function VideoPlayerComponent({ videoId, apiKey, clientId, client, baseUrl, autoplay = false, controls = true, width = '100%', height = 'auto', className = '', showLogo = true, showTitle = true, showAuthor = true, showDescription = true, showCaptions = true, onPlay, onPause, onError, onLoaded, onTimeUpdate, onVolumeChange, onEnded, onFullscreenChange, showInfo = false, }, ref) {
4609
+ const playerRef = useRef(null);
4610
+ const videoDataRef = useRef(null);
4611
+ useImperativeHandle(ref, () => ({
4612
+ play: () => playerRef.current?.play(),
4613
+ pause: () => playerRef.current?.pause(),
4614
+ setVolume: (volume) => playerRef.current?.setVolume(volume),
4615
+ toggleMute: () => playerRef.current?.toggleMute(),
4616
+ seek: (time) => playerRef.current?.seek(time),
4617
+ getState: () => playerRef.current?.getState() || null,
4618
+ destroy: () => playerRef.current?.destroy(),
4619
+ }));
4620
+ const handleLoaded = (e) => {
4621
+ const detail = e.detail;
4622
+ videoDataRef.current = detail;
4623
+ onLoaded?.(detail);
4624
+ };
4625
+ const handlePlay = () => onPlay?.();
4626
+ const handlePause = () => onPause?.();
4627
+ const handleTimeUpdate = (e) => {
4628
+ const time = e.detail;
4629
+ onTimeUpdate?.(time);
4630
+ };
4631
+ const handleVolumeChange = (e) => {
4632
+ const volume = e.detail;
4633
+ onVolumeChange?.(volume);
4634
+ };
4635
+ const handleEnded = () => onEnded?.();
4636
+ const handleError = (e) => {
4637
+ const error = e.detail;
4638
+ onError?.(error);
4639
+ };
4640
+ const handleFullscreenChange = (e) => {
4641
+ const isFullscreen = e.detail;
4642
+ onFullscreenChange?.(isFullscreen);
4643
+ };
4644
+ useEffect(() => {
4645
+ const player = playerRef.current;
4646
+ if (!player)
4647
+ return;
4648
+ if (client) {
4649
+ player.client = client;
4650
+ }
4651
+ player.addEventListener('jaaq:loaded', handleLoaded);
4652
+ player.addEventListener('jaaq:play', handlePlay);
4653
+ player.addEventListener('jaaq:pause', handlePause);
4654
+ player.addEventListener('jaaq:timeupdate', handleTimeUpdate);
4655
+ player.addEventListener('jaaq:volumechange', handleVolumeChange);
4656
+ player.addEventListener('jaaq:ended', handleEnded);
4657
+ player.addEventListener('jaaq:error', handleError);
4658
+ player.addEventListener('jaaq:fullscreenchange', handleFullscreenChange);
4659
+ return () => {
4660
+ player.removeEventListener('jaaq:loaded', handleLoaded);
4661
+ player.removeEventListener('jaaq:play', handlePlay);
4662
+ player.removeEventListener('jaaq:pause', handlePause);
4663
+ player.removeEventListener('jaaq:timeupdate', handleTimeUpdate);
4664
+ player.removeEventListener('jaaq:volumechange', handleVolumeChange);
4665
+ player.removeEventListener('jaaq:ended', handleEnded);
4666
+ player.removeEventListener('jaaq:error', handleError);
4667
+ player.removeEventListener('jaaq:fullscreenchange', handleFullscreenChange);
4668
+ };
4669
+ }, [client, onPlay, onPause, onError, onLoaded, onTimeUpdate, onVolumeChange, onEnded, onFullscreenChange]);
4670
+ return (React.createElement("div", { style: { width, height }, className: className },
4671
+ React.createElement("jaaq-video-player", { ref: playerRef, "video-id": videoId, "api-key": apiKey, "client-id": clientId, "base-url": baseUrl, autoplay: autoplay ? 'true' : 'false', controls: controls ? 'true' : 'false', "show-logo": showLogo ? 'true' : 'false', "show-title": showTitle ? 'true' : 'false', "show-author": showAuthor ? 'true' : 'false', "show-description": showDescription ? 'true' : 'false', "show-captions": showCaptions ? 'true' : 'false', width: "100%", height: "auto" }),
4672
+ showInfo && videoDataRef.current && (React.createElement("div", { className: "jaaq-video-info", style: { marginTop: '16px', padding: '16px', background: '#f8f9fa', borderRadius: '8px' } },
4673
+ React.createElement("h3", { style: { margin: '0 0 12px 0', fontSize: '18px' } }, videoDataRef.current.question || videoDataRef.current.description || 'Untitled Video'),
4674
+ React.createElement("p", { style: { margin: '0 0 8px 0' } },
4675
+ React.createElement("strong", null, "Video ID:"),
4676
+ " ",
4677
+ videoDataRef.current.id),
4678
+ React.createElement("p", { style: { margin: '0 0 8px 0' } },
4679
+ React.createElement("strong", null, "Duration:"),
4680
+ " ",
4681
+ videoDataRef.current.duration || 'Unknown',
4682
+ " seconds")))));
4683
+ }
4684
+ VideoPlayerComponent.displayName = 'VideoPlayer';
4685
+ const VideoPlayer = forwardRef(VideoPlayerComponent);
4686
+
4687
+ if (typeof window !== 'undefined') {
4688
+ registerJaaqComponents();
4689
+ }
4690
+ function CollectionPlayerComponent({ collectionId, apiKey, clientId, subscriptionId, client, baseUrl, autoplay = false, showArrows = true, showDots = true, className = '', onLoaded, onError, onSlideChange, }, ref) {
4691
+ const playerRef = useRef(null);
4692
+ useImperativeHandle(ref, () => ({
4693
+ refresh: () => playerRef.current?.refresh(),
4694
+ next: () => playerRef.current?.next(),
4695
+ prev: () => playerRef.current?.prev(),
4696
+ go: (index) => playerRef.current?.go(index),
4697
+ destroy: () => playerRef.current?.destroy(),
4698
+ getCollection: () => playerRef.current?.getCollection() || null,
4699
+ }));
4700
+ const handleLoaded = (e) => {
4701
+ const collection = e.detail;
4702
+ onLoaded?.(collection);
4703
+ };
4704
+ const handleError = (e) => {
4705
+ const error = e.detail;
4706
+ onError?.(error);
4707
+ };
4708
+ const handleSlideChange = (e) => {
4709
+ const data = e.detail;
4710
+ onSlideChange?.(data);
4711
+ };
4712
+ useEffect(() => {
4713
+ const player = playerRef.current;
4714
+ if (!player)
4715
+ return;
4716
+ if (client) {
4717
+ player.client = client;
4718
+ }
4719
+ player.addEventListener('jaaq:collection:loaded', handleLoaded);
4720
+ player.addEventListener('jaaq:collection:error', handleError);
4721
+ player.addEventListener('jaaq:collection:slidechange', handleSlideChange);
4722
+ return () => {
4723
+ player.removeEventListener('jaaq:collection:loaded', handleLoaded);
4724
+ player.removeEventListener('jaaq:collection:error', handleError);
4725
+ player.removeEventListener('jaaq:collection:slidechange', handleSlideChange);
4726
+ };
4727
+ }, [client, onLoaded, onError, onSlideChange]);
4728
+ return (React.createElement("div", { className: className },
4729
+ React.createElement("jaaq-collection-player", { ref: playerRef, "collection-id": collectionId, "api-key": apiKey, "client-id": clientId, "subscription-id": subscriptionId, "base-url": baseUrl, autoplay: autoplay ? 'true' : 'false', "show-arrows": showArrows ? 'true' : 'false', "show-dots": showDots ? 'true' : 'false' })));
4730
+ }
4731
+ CollectionPlayerComponent.displayName = 'CollectionPlayer';
4732
+ const CollectionPlayer = forwardRef(CollectionPlayerComponent);
4733
+
4734
+ export { CollectionPlayer, VideoPlayer };
4735
+ //# sourceMappingURL=index.mjs.map