marquee-content 5.0.0-dev.2 → 5.0.1

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.
package/dist/index.es.js DELETED
@@ -1,558 +0,0 @@
1
- //#endregion
2
- //#region src/styles.ts
3
- var e = ":host {\n --marquee-content-gap: 2rem;\n --marquee-content-distance: 0px;\n --marquee-content-duration: 20s;\n\n display: block;\n overflow: hidden;\n width: 100%;\n color: inherit;\n font: inherit;\n\n /*\n По умолчанию компонент не ловит pointer events.\n Это удобно для декоративной бегущей строки.\n Если включить pause-on-hover, pointer-events включатся автоматически.\n */\n pointer-events: none;\n}\n\n:host([pause-on-hover]:not([pause-on-hover=\"false\"])) {\n pointer-events: auto;\n}\n\n:host([hidden]) {\n display: none;\n}\n\n.marquee-content__source {\n display: none;\n}\n\n.marquee-content__viewport {\n overflow: hidden;\n width: 100%;\n}\n\n.marquee-content__track {\n display: flex;\n width: max-content;\n transform: translate3d(0, 0, 0);\n will-change: transform;\n}\n\n.marquee-content__group {\n display: flex;\n flex: 0 0 auto;\n align-items: center;\n gap: var(--marquee-content-gap);\n padding-inline-end: var(--marquee-content-gap);\n white-space: nowrap;\n color: inherit;\n font: inherit;\n}\n\n.marquee-content__group > * {\n flex: 0 0 auto;\n}\n\n@media (prefers-reduced-motion: reduce) {\n .marquee-content__track {\n transform: none !important;\n }\n}\n";
4
- function t(e) {
5
- if (typeof CSSStyleSheet > "u" || typeof CSSStyleSheet.prototype.replaceSync != "function") return null;
6
- try {
7
- let t = new CSSStyleSheet();
8
- return t.replaceSync(e), t;
9
- } catch {
10
- return null;
11
- }
12
- }
13
- function n(e) {
14
- try {
15
- return Array.from(e.cssRules).map((e) => e.cssText).join("\n");
16
- } catch {
17
- return "";
18
- }
19
- }
20
- function r(e) {
21
- return e ? typeof e == "string" ? {
22
- sheet: t(e),
23
- cssText: e
24
- } : {
25
- sheet: e,
26
- cssText: n(e)
27
- } : {
28
- sheet: null,
29
- cssText: ""
30
- };
31
- }
32
- function i(e) {
33
- return typeof CSSStyleSheet < "u" && "adoptedStyleSheets" in e && typeof CSSStyleSheet.prototype.replaceSync == "function";
34
- }
35
- //#endregion
36
- //#region src/marquee-content.ts
37
- var a = "marquee-content", o = {
38
- speed: 90,
39
- direction: "rtl",
40
- minGroupWidthRatio: 1.05,
41
- responsiveSpeed: !0,
42
- referenceWidth: 1280,
43
- minSpeedFactor: .55,
44
- maxSpeedFactor: 1,
45
- pauseOnHover: !1,
46
- pauseWhenOutOfView: !0,
47
- recalculateAfterFontsReady: !0,
48
- scrollVelocityFactor: 400,
49
- scrollMinExtraSpeed: .15,
50
- scrollMaxExtraSpeed: 3,
51
- scrollInertiaDuration: 1600,
52
- debug: !1
53
- }, s = [
54
- "speed",
55
- "direction",
56
- "min-group-width-ratio",
57
- "responsive-speed",
58
- "reference-width",
59
- "min-speed-factor",
60
- "max-speed-factor",
61
- "pause-on-hover",
62
- "pause-when-out-of-view",
63
- "recalculate-after-fonts-ready",
64
- "scroll-velocity-factor",
65
- "scroll-min-extra-speed",
66
- "scroll-max-extra-speed",
67
- "scroll-inertia-duration",
68
- "debug"
69
- ], c = {
70
- speed: "speed",
71
- direction: "direction",
72
- minGroupWidthRatio: "min-group-width-ratio",
73
- responsiveSpeed: "responsive-speed",
74
- referenceWidth: "reference-width",
75
- minSpeedFactor: "min-speed-factor",
76
- maxSpeedFactor: "max-speed-factor",
77
- pauseOnHover: "pause-on-hover",
78
- pauseWhenOutOfView: "pause-when-out-of-view",
79
- recalculateAfterFontsReady: "recalculate-after-fonts-ready",
80
- scrollVelocityFactor: "scroll-velocity-factor",
81
- scrollMinExtraSpeed: "scroll-min-extra-speed",
82
- scrollMaxExtraSpeed: "scroll-max-extra-speed",
83
- scrollInertiaDuration: "scroll-inertia-duration",
84
- debug: "debug"
85
- }, l = ["--marquee-content-distance", "--marquee-content-duration"], u = "\n <slot class=\"marquee-content__source\"></slot>\n\n <div class=\"marquee-content__viewport\" part=\"viewport\">\n <div class=\"marquee-content__track\" part=\"track\"></div>\n </div>\n", d = class t extends HTMLElement {
86
- static get observedAttributes() {
87
- return [...s];
88
- }
89
- static instances = /* @__PURE__ */ new Set();
90
- static stylesheetEntry = r(e);
91
- static styleOverridesEntry = r(null);
92
- static configureStyles(n = {}) {
93
- "stylesheet" in n && (t.stylesheetEntry = r(n.stylesheet ?? e)), "styleOverrides" in n && (t.styleOverridesEntry = r(n.styleOverrides)), t.instances.forEach((e) => {
94
- e.applyAllStyles();
95
- });
96
- }
97
- static setStylesheet(e) {
98
- t.configureStyles({ stylesheet: e });
99
- }
100
- static setStyleOverrides(e) {
101
- t.configureStyles({ styleOverrides: e });
102
- }
103
- shadow;
104
- sourceSlot;
105
- track;
106
- options = { ...o };
107
- sourceNodes = [];
108
- resizeObserver = null;
109
- mutationObserver = null;
110
- intersectionObserver = null;
111
- abortController = null;
112
- reducedMotionMediaQuery = null;
113
- animationFrameId = null;
114
- rebuildFrameId = null;
115
- lastFrameTime = null;
116
- mounted = !1;
117
- isHovered = !1;
118
- isInViewport = !0;
119
- reducedMotion = !1;
120
- distance = 0;
121
- offset = 0;
122
- emptySourceRebuildCount = 0;
123
- hasWarnedMissingSourceNodes = !1;
124
- scrollDirectionFactor = 1;
125
- scrollBoostStartValue = 0;
126
- scrollBoostStartedAt = 0;
127
- lastScrollY = 0;
128
- lastScrollTime = 0;
129
- constructor() {
130
- super(), this.shadow = this.attachShadow({ mode: "open" }), this.applyAllStyles();
131
- let e = document.createElement("template");
132
- e.innerHTML = u, this.shadow.appendChild(e.content.cloneNode(!0));
133
- let t = this.shadow.querySelector("slot.marquee-content__source"), n = this.shadow.querySelector(".marquee-content__track");
134
- if (!t) throw Error("[MarqueeContent] Source slot was not found.");
135
- if (!n) throw Error("[MarqueeContent] Track element was not found.");
136
- this.sourceSlot = t, this.track = n;
137
- }
138
- connectedCallback() {
139
- this.mounted || (t.instances.add(this), this.mounted = !0, this.abortController = new AbortController(), this.options = this.resolveOptions(), this.lastScrollY = this.getScrollY(), this.lastScrollTime = performance.now(), this.sourceSlot.addEventListener("slotchange", this.handleSlotChange, { signal: this.abortController.signal }), this.shadow.addEventListener("load", this.scheduleRebuild, {
140
- capture: !0,
141
- signal: this.abortController.signal
142
- }), this.addEventListener("pointerenter", this.handlePointerEnter, { signal: this.abortController.signal }), this.addEventListener("pointerleave", this.handlePointerLeave, { signal: this.abortController.signal }), window.addEventListener("scroll", this.handleScroll, {
143
- passive: !0,
144
- signal: this.abortController.signal
145
- }), window.addEventListener("orientationchange", this.scheduleRebuild, { signal: this.abortController.signal }), typeof ResizeObserver < "u" ? (this.resizeObserver = new ResizeObserver(this.scheduleRebuild), this.resizeObserver.observe(this)) : window.addEventListener("resize", this.scheduleRebuild, { signal: this.abortController.signal }), "IntersectionObserver" in window && (this.intersectionObserver = new IntersectionObserver(this.handleIntersectionChange), this.intersectionObserver.observe(this)), this.setupReducedMotionWatcher(), this.watchSourceNodes(), this.rebuild(), this.options.recalculateAfterFontsReady && this.rebuildAfterFontsReady());
146
- }
147
- disconnectedCallback() {
148
- this.teardown(), t.instances.delete(this);
149
- }
150
- attributeChangedCallback(e, t, n) {
151
- t !== n && (this.options = this.resolveOptions(), this.mounted && this.scheduleRebuild());
152
- }
153
- get speed() {
154
- return this.options.speed;
155
- }
156
- set speed(e) {
157
- this.setNullableAttribute("speed", e);
158
- }
159
- get direction() {
160
- return this.options.direction;
161
- }
162
- set direction(e) {
163
- this.setNullableAttribute("direction", e);
164
- }
165
- get minGroupWidthRatio() {
166
- return this.options.minGroupWidthRatio;
167
- }
168
- set minGroupWidthRatio(e) {
169
- this.setNullableAttribute("min-group-width-ratio", e);
170
- }
171
- get responsiveSpeed() {
172
- return this.options.responsiveSpeed;
173
- }
174
- set responsiveSpeed(e) {
175
- this.setNullableAttribute("responsive-speed", e);
176
- }
177
- get referenceWidth() {
178
- return this.options.referenceWidth;
179
- }
180
- set referenceWidth(e) {
181
- this.setNullableAttribute("reference-width", e);
182
- }
183
- get minSpeedFactor() {
184
- return this.options.minSpeedFactor;
185
- }
186
- set minSpeedFactor(e) {
187
- this.setNullableAttribute("min-speed-factor", e);
188
- }
189
- get maxSpeedFactor() {
190
- return this.options.maxSpeedFactor;
191
- }
192
- set maxSpeedFactor(e) {
193
- this.setNullableAttribute("max-speed-factor", e);
194
- }
195
- get pauseOnHover() {
196
- return this.options.pauseOnHover;
197
- }
198
- set pauseOnHover(e) {
199
- this.setNullableAttribute("pause-on-hover", e);
200
- }
201
- get pauseWhenOutOfView() {
202
- return this.options.pauseWhenOutOfView;
203
- }
204
- set pauseWhenOutOfView(e) {
205
- this.setNullableAttribute("pause-when-out-of-view", e);
206
- }
207
- get recalculateAfterFontsReady() {
208
- return this.options.recalculateAfterFontsReady;
209
- }
210
- set recalculateAfterFontsReady(e) {
211
- this.setNullableAttribute("recalculate-after-fonts-ready", e);
212
- }
213
- get scrollVelocityFactor() {
214
- return this.options.scrollVelocityFactor;
215
- }
216
- set scrollVelocityFactor(e) {
217
- this.setNullableAttribute("scroll-velocity-factor", e);
218
- }
219
- get scrollMinExtraSpeed() {
220
- return this.options.scrollMinExtraSpeed;
221
- }
222
- set scrollMinExtraSpeed(e) {
223
- this.setNullableAttribute("scroll-min-extra-speed", e);
224
- }
225
- get scrollMaxExtraSpeed() {
226
- return this.options.scrollMaxExtraSpeed;
227
- }
228
- set scrollMaxExtraSpeed(e) {
229
- this.setNullableAttribute("scroll-max-extra-speed", e);
230
- }
231
- get scrollInertiaDuration() {
232
- return this.options.scrollInertiaDuration;
233
- }
234
- set scrollInertiaDuration(e) {
235
- this.setNullableAttribute("scroll-inertia-duration", e);
236
- }
237
- get debug() {
238
- return this.options.debug;
239
- }
240
- set debug(e) {
241
- this.setNullableAttribute("debug", e);
242
- }
243
- update(e = {}) {
244
- Object.entries(e).forEach(([e, t]) => {
245
- let n = c[e];
246
- n && this.setNullableAttribute(n, t);
247
- }), this.options = this.resolveOptions(), this.scheduleRebuild();
248
- }
249
- refresh() {
250
- this.scheduleRebuild();
251
- }
252
- adoptStyles(e) {
253
- t.setStylesheet(e);
254
- }
255
- adoptStyleOverrides(e) {
256
- t.setStyleOverrides(e);
257
- }
258
- applyAllStyles() {
259
- let e = t.stylesheetEntry, n = t.styleOverridesEntry;
260
- if (i(this.shadow)) {
261
- let t = [];
262
- e.sheet && t.push(e.sheet), n.sheet && t.push(n.sheet), this.shadow.adoptedStyleSheets = t, this.removeFallbackStyleElements();
263
- return;
264
- }
265
- this.applyFallbackStyleElement("base", e.cssText), this.applyFallbackStyleElement("overrides", n.cssText);
266
- }
267
- applyFallbackStyleElement(e, t) {
268
- let n = `data-marquee-content-style-${e}`, r = this.shadow.querySelector(`style[${n}]`);
269
- if (!t) {
270
- r?.remove();
271
- return;
272
- }
273
- r || (r = document.createElement("style"), r.setAttribute(n, ""), this.shadow.prepend(r)), r.textContent !== t && (r.textContent = t);
274
- }
275
- removeFallbackStyleElements() {
276
- this.shadow.querySelectorAll("style[data-marquee-content-style-base], style[data-marquee-content-style-overrides]").forEach((e) => {
277
- e.remove();
278
- });
279
- }
280
- teardown() {
281
- this.mounted && (this.mounted = !1, this.stopAnimationLoop(), this.cancelScheduledRebuild(), this.resizeObserver?.disconnect(), this.mutationObserver?.disconnect(), this.intersectionObserver?.disconnect(), this.removeReducedMotionWatcher(), this.abortController?.abort(), this.resizeObserver = null, this.mutationObserver = null, this.intersectionObserver = null, this.abortController = null, this.track.replaceChildren(), this.removeAttribute("data-marquee-content-ready"), this.removeAttribute("data-marquee-content-pause-on-hover"), l.forEach((e) => {
282
- this.style.removeProperty(e);
283
- }), this.distance = 0, this.offset = 0, this.lastFrameTime = null);
284
- }
285
- handleSlotChange = () => {
286
- this.watchSourceNodes(), this.scheduleRebuild();
287
- };
288
- handlePointerEnter = () => {
289
- this.isHovered = !0, this.updateAnimationLoopState();
290
- };
291
- handlePointerLeave = () => {
292
- this.isHovered = !1, this.updateAnimationLoopState();
293
- };
294
- handleIntersectionChange = (e) => {
295
- let t = e[0];
296
- t && (this.isInViewport = t.isIntersecting, this.updateAnimationLoopState());
297
- };
298
- handleReducedMotionChange = (e) => {
299
- this.reducedMotion = e.matches, this.reducedMotion ? this.track.style.transform = "none" : this.applyTransform(), this.updateAnimationLoopState();
300
- };
301
- handleScroll = () => {
302
- if (this.options.direction !== "scroll") return;
303
- let e = performance.now(), t = this.getScrollY(), n = t - this.lastScrollY, r = Math.max((e - this.lastScrollTime) / 1e3, .016);
304
- if (this.lastScrollY = t, this.lastScrollTime = e, Math.abs(n) < .5) return;
305
- let i = n / r;
306
- this.scrollDirectionFactor = i >= 0 ? 1 : -1;
307
- let a = this.clamp(i / this.options.scrollVelocityFactor, -this.options.scrollMaxExtraSpeed, this.options.scrollMaxExtraSpeed);
308
- Math.abs(a) >= this.options.scrollMinExtraSpeed ? (this.scrollBoostStartValue = a, this.scrollBoostStartedAt = e) : this.scrollBoostStartValue = 0, this.updateAnimationLoopState(), this.options.debug && console.info("[MarqueeContent] Scroll update", {
309
- velocity: i,
310
- directionFactor: this.scrollDirectionFactor,
311
- extraSpeed: a
312
- });
313
- };
314
- scheduleRebuild = () => {
315
- this.mounted && (this.cancelScheduledRebuild(), this.rebuildFrameId = requestAnimationFrame(() => {
316
- this.rebuildFrameId = null, this.rebuild();
317
- }));
318
- };
319
- cancelScheduledRebuild() {
320
- this.rebuildFrameId !== null && (cancelAnimationFrame(this.rebuildFrameId), this.rebuildFrameId = null);
321
- }
322
- rebuild() {
323
- if (!this.mounted) return;
324
- this.options = this.resolveOptions(), this.removeAttribute("data-marquee-content-ready"), this.options.pauseOnHover ? this.setAttribute("data-marquee-content-pause-on-hover", "true") : this.removeAttribute("data-marquee-content-pause-on-hover");
325
- let e = this.clientWidth;
326
- if (e <= 0) {
327
- this.distance = 0, this.track.replaceChildren(), this.updateAnimationLoopState();
328
- return;
329
- }
330
- if (this.sourceNodes = this.getSourceNodes(), this.sourceNodes.length === 0) {
331
- this.emptySourceRebuildCount += 1, this.warnAboutMissingSourceNodes(), this.distance = 0, this.track.replaceChildren(), this.updateAnimationLoopState();
332
- return;
333
- }
334
- this.emptySourceRebuildCount = 0, this.hasWarnedMissingSourceNodes = !1;
335
- let t = this.createGroup(), n = e * this.options.minGroupWidthRatio;
336
- this.track.replaceChildren(t), this.expandGroupToWidth(t, n);
337
- let r = t.cloneNode(!0);
338
- if (r.setAttribute("aria-hidden", "true"), this.track.appendChild(r), this.distance = t.scrollWidth, this.offset = this.normalizeOffset(this.offset), this.distance <= 0) {
339
- this.track.replaceChildren(), this.updateAnimationLoopState();
340
- return;
341
- }
342
- let i = this.getCurrentSpeed(e), a = this.distance / i;
343
- this.style.setProperty("--marquee-content-distance", `${this.distance}px`), this.style.setProperty("--marquee-content-duration", `${a}s`), this.reducedMotion ? this.track.style.transform = "none" : this.applyTransform(), this.setAttribute("data-marquee-content-ready", "true"), this.updateAnimationLoopState(), this.options.debug && console.info("[MarqueeContent] Rebuilt", {
344
- containerWidth: e,
345
- distance: this.distance,
346
- baseSpeed: this.options.speed,
347
- currentSpeed: i,
348
- duration: a,
349
- direction: this.options.direction,
350
- responsiveSpeed: this.options.responsiveSpeed
351
- });
352
- }
353
- warnAboutMissingSourceNodes() {
354
- this.hasWarnedMissingSourceNodes || this.emptySourceRebuildCount < 2 || (this.hasWarnedMissingSourceNodes = !0, console.warn([
355
- "[MarqueeContent] No source nodes were detected for <marquee-content>.",
356
- "If you use Vue + Vite, configure compilerOptions.isCustomElement for \"marquee-content\",",
357
- "otherwise Vue may treat it as a Vue component and slot content will not be exposed to the Web Component."
358
- ].join(" ")));
359
- }
360
- createGroup() {
361
- let e = document.createElement("div");
362
- return e.className = "marquee-content__group", e.setAttribute("part", "group"), this.appendSourceNodes(e), e;
363
- }
364
- expandGroupToWidth(e, t) {
365
- let n = 0;
366
- for (; e.scrollWidth < t && n < 100;) {
367
- let t = e.scrollWidth;
368
- if (this.appendSourceNodes(e), e.scrollWidth <= t) break;
369
- n += 1;
370
- }
371
- }
372
- appendSourceNodes(e) {
373
- let t = document.createDocumentFragment();
374
- this.sourceNodes.forEach((e) => {
375
- t.append(this.cloneSourceNode(e));
376
- }), e.appendChild(t);
377
- }
378
- cloneSourceNode(e) {
379
- let t = e.cloneNode(!0);
380
- if (t instanceof Element) {
381
- let e = t.getAttribute("part");
382
- t.setAttribute("part", e ? `${e} item` : "item");
383
- }
384
- return t;
385
- }
386
- getSourceNodes() {
387
- return this.sourceSlot.assignedNodes({ flatten: !0 }).filter((e) => e.nodeType === Node.TEXT_NODE ? !!e.textContent?.trim() : e.nodeType === Node.ELEMENT_NODE);
388
- }
389
- watchSourceNodes() {
390
- this.mutationObserver?.disconnect(), "MutationObserver" in window && (this.mutationObserver = new MutationObserver(this.scheduleRebuild), this.getSourceNodes().forEach((e) => {
391
- if (e.nodeType === Node.ELEMENT_NODE) {
392
- this.mutationObserver?.observe(e, {
393
- attributes: !0,
394
- childList: !0,
395
- characterData: !0,
396
- subtree: !0
397
- });
398
- return;
399
- }
400
- e.nodeType === Node.TEXT_NODE && this.mutationObserver?.observe(e, { characterData: !0 });
401
- }));
402
- }
403
- setupReducedMotionWatcher() {
404
- if (!("matchMedia" in window)) return;
405
- if (this.reducedMotionMediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)"), this.reducedMotion = this.reducedMotionMediaQuery.matches, typeof this.reducedMotionMediaQuery.addEventListener == "function") {
406
- this.reducedMotionMediaQuery.addEventListener("change", this.handleReducedMotionChange, { signal: this.abortController?.signal });
407
- return;
408
- }
409
- let e = this.reducedMotionMediaQuery;
410
- typeof e.addListener == "function" && e.addListener(this.handleReducedMotionChange);
411
- }
412
- removeReducedMotionWatcher() {
413
- if (this.reducedMotionMediaQuery) {
414
- if (typeof this.reducedMotionMediaQuery.removeEventListener == "function") this.reducedMotionMediaQuery.removeEventListener("change", this.handleReducedMotionChange);
415
- else {
416
- let e = this.reducedMotionMediaQuery;
417
- typeof e.removeListener == "function" && e.removeListener(this.handleReducedMotionChange);
418
- }
419
- this.reducedMotionMediaQuery = null;
420
- }
421
- }
422
- updateAnimationLoopState() {
423
- if (!this.mounted || this.distance <= 0 || this.reducedMotion || !this.canAnimate()) {
424
- this.stopAnimationLoop();
425
- return;
426
- }
427
- this.startAnimationLoop();
428
- }
429
- canAnimate() {
430
- return !(this.options.pauseOnHover && this.isHovered || this.options.pauseWhenOutOfView && !this.isInViewport);
431
- }
432
- startAnimationLoop() {
433
- this.animationFrameId === null && (this.lastFrameTime = performance.now(), this.animationFrameId = requestAnimationFrame(this.tick));
434
- }
435
- stopAnimationLoop() {
436
- if (this.animationFrameId === null) {
437
- this.lastFrameTime = null;
438
- return;
439
- }
440
- cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null, this.lastFrameTime = null;
441
- }
442
- tick = (e) => {
443
- if (this.animationFrameId = null, !this.mounted || this.distance <= 0 || this.reducedMotion || !this.canAnimate()) {
444
- this.stopAnimationLoop();
445
- return;
446
- }
447
- let t = this.lastFrameTime ?? e, n = Math.min((e - t) / 1e3, .064);
448
- this.lastFrameTime = e;
449
- let r = this.getCurrentSpeed(this.clientWidth), i = this.getCurrentTimeScale(e);
450
- this.offset = this.normalizeOffset(this.offset + r * i * n), this.applyTransform(), this.animationFrameId = requestAnimationFrame(this.tick);
451
- };
452
- getCurrentTimeScale(e) {
453
- if (this.options.direction === "rtl") return 1;
454
- if (this.options.direction === "ltr") return -1;
455
- let t = this.getScrollBoost(e);
456
- return this.clamp(this.scrollDirectionFactor + t, -1 - this.options.scrollMaxExtraSpeed, 1 + this.options.scrollMaxExtraSpeed);
457
- }
458
- getScrollBoost(e) {
459
- if (this.scrollBoostStartValue === 0) return 0;
460
- let t = this.options.scrollInertiaDuration;
461
- if (t <= 0) return this.scrollBoostStartValue = 0, 0;
462
- let n = this.clamp((e - this.scrollBoostStartedAt) / t, 0, 1);
463
- if (n >= 1) return this.scrollBoostStartValue = 0, 0;
464
- let r = this.easeOutCubic(n);
465
- return this.scrollBoostStartValue * (1 - r);
466
- }
467
- applyTransform() {
468
- this.track.style.transform = `translate3d(${-this.offset}px, 0, 0)`;
469
- }
470
- normalizeOffset(e) {
471
- if (this.distance <= 0) return 0;
472
- let t = e % this.distance;
473
- return t < 0 ? t + this.distance : t;
474
- }
475
- getCurrentSpeed(e) {
476
- if (!this.options.responsiveSpeed) return this.options.speed;
477
- let t = this.clamp(e / this.options.referenceWidth, this.options.minSpeedFactor, this.options.maxSpeedFactor);
478
- return this.options.speed * t;
479
- }
480
- resolveOptions() {
481
- let e = this.num("min-speed-factor", o.minSpeedFactor, .1, 2), t = this.num("max-speed-factor", o.maxSpeedFactor, .1, 3);
482
- return {
483
- speed: this.num("speed", o.speed, 10, 500),
484
- direction: this.parseDirection(this.getAttribute("direction"), o.direction),
485
- minGroupWidthRatio: this.num("min-group-width-ratio", o.minGroupWidthRatio, 1, 5),
486
- responsiveSpeed: this.parseBoolean(this.getAttribute("responsive-speed"), o.responsiveSpeed),
487
- referenceWidth: this.num("reference-width", o.referenceWidth, 320, 1e4),
488
- minSpeedFactor: Math.min(e, t),
489
- maxSpeedFactor: Math.max(e, t),
490
- pauseOnHover: this.parseBoolean(this.getAttribute("pause-on-hover"), o.pauseOnHover),
491
- pauseWhenOutOfView: this.parseBoolean(this.getAttribute("pause-when-out-of-view"), o.pauseWhenOutOfView),
492
- recalculateAfterFontsReady: this.parseBoolean(this.getAttribute("recalculate-after-fonts-ready"), o.recalculateAfterFontsReady),
493
- scrollVelocityFactor: this.num("scroll-velocity-factor", o.scrollVelocityFactor, 50, 5e3),
494
- scrollMinExtraSpeed: this.num("scroll-min-extra-speed", o.scrollMinExtraSpeed, 0, 5),
495
- scrollMaxExtraSpeed: this.num("scroll-max-extra-speed", o.scrollMaxExtraSpeed, 0, 10),
496
- scrollInertiaDuration: this.num("scroll-inertia-duration", o.scrollInertiaDuration, 0, 5e3),
497
- debug: this.parseBoolean(this.getAttribute("debug"), o.debug)
498
- };
499
- }
500
- num(e, t, n, r) {
501
- return this.clamp(this.parseNumber(this.getAttribute(e), t), n, r);
502
- }
503
- parseNumber(e, t) {
504
- if (e === null || e.trim() === "") return t;
505
- let n = Number(e);
506
- return Number.isFinite(n) ? n : t;
507
- }
508
- parseBoolean(e, t) {
509
- if (e === null) return t;
510
- let n = e.trim().toLowerCase();
511
- return n === "" || [
512
- "true",
513
- "1",
514
- "yes",
515
- "on"
516
- ].includes(n) ? !0 : [
517
- "false",
518
- "0",
519
- "no",
520
- "off"
521
- ].includes(n) ? !1 : t;
522
- }
523
- parseDirection(e, t) {
524
- return e === "rtl" || e === "ltr" || e === "scroll" ? e : t;
525
- }
526
- setNullableAttribute(e, t) {
527
- if (t == null) {
528
- this.removeAttribute(e);
529
- return;
530
- }
531
- this.setAttribute(e, String(t));
532
- }
533
- getScrollY() {
534
- return window.scrollY || window.pageYOffset || 0;
535
- }
536
- clamp(e, t, n) {
537
- return Math.min(Math.max(e, t), n);
538
- }
539
- easeOutCubic(e) {
540
- return 1 - (1 - e) ** 3;
541
- }
542
- rebuildAfterFontsReady() {
543
- let e = document.fonts;
544
- e?.ready && e.ready.then(this.scheduleRebuild).catch(() => void 0);
545
- }
546
- };
547
- function f(e = a, t = {}) {
548
- typeof window > "u" || !window.customElements || (d.configureStyles(t), window.customElements.get(e) || window.customElements.define(e, d));
549
- }
550
- function p(e = {}) {
551
- let { tagName: t = a, ...n } = e;
552
- f(t, n);
553
- }
554
- //#endregion
555
- //#region src/index.ts
556
- f();
557
- //#endregion
558
- export { a as MARQUEE_CONTENT_TAG, d as MarqueeContent, t as createConstructableStyleSheet, n as cssStyleSheetToText, f as defineMarqueeContent, p as initMarqueeContents, e as marqueeContentCssText, r as normalizeStyleInput };
package/dist/index.umd.js DELETED
@@ -1,71 +0,0 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.MarqueeContent={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=`:host {
2
- --marquee-content-gap: 2rem;
3
- --marquee-content-distance: 0px;
4
- --marquee-content-duration: 20s;
5
-
6
- display: block;
7
- overflow: hidden;
8
- width: 100%;
9
- color: inherit;
10
- font: inherit;
11
-
12
- /*
13
- По умолчанию компонент не ловит pointer events.
14
- Это удобно для декоративной бегущей строки.
15
- Если включить pause-on-hover, pointer-events включатся автоматически.
16
- */
17
- pointer-events: none;
18
- }
19
-
20
- :host([pause-on-hover]:not([pause-on-hover="false"])) {
21
- pointer-events: auto;
22
- }
23
-
24
- :host([hidden]) {
25
- display: none;
26
- }
27
-
28
- .marquee-content__source {
29
- display: none;
30
- }
31
-
32
- .marquee-content__viewport {
33
- overflow: hidden;
34
- width: 100%;
35
- }
36
-
37
- .marquee-content__track {
38
- display: flex;
39
- width: max-content;
40
- transform: translate3d(0, 0, 0);
41
- will-change: transform;
42
- }
43
-
44
- .marquee-content__group {
45
- display: flex;
46
- flex: 0 0 auto;
47
- align-items: center;
48
- gap: var(--marquee-content-gap);
49
- padding-inline-end: var(--marquee-content-gap);
50
- white-space: nowrap;
51
- color: inherit;
52
- font: inherit;
53
- }
54
-
55
- .marquee-content__group > * {
56
- flex: 0 0 auto;
57
- }
58
-
59
- @media (prefers-reduced-motion: reduce) {
60
- .marquee-content__track {
61
- transform: none !important;
62
- }
63
- }
64
- `;function n(e){if(typeof CSSStyleSheet>`u`||typeof CSSStyleSheet.prototype.replaceSync!=`function`)return null;try{let t=new CSSStyleSheet;return t.replaceSync(e),t}catch{return null}}function r(e){try{return Array.from(e.cssRules).map(e=>e.cssText).join(`
65
- `)}catch{return``}}function i(e){return e?typeof e==`string`?{sheet:n(e),cssText:e}:{sheet:e,cssText:r(e)}:{sheet:null,cssText:``}}function a(e){return typeof CSSStyleSheet<`u`&&`adoptedStyleSheets`in e&&typeof CSSStyleSheet.prototype.replaceSync==`function`}var o=`marquee-content`,s={speed:90,direction:`rtl`,minGroupWidthRatio:1.05,responsiveSpeed:!0,referenceWidth:1280,minSpeedFactor:.55,maxSpeedFactor:1,pauseOnHover:!1,pauseWhenOutOfView:!0,recalculateAfterFontsReady:!0,scrollVelocityFactor:400,scrollMinExtraSpeed:.15,scrollMaxExtraSpeed:3,scrollInertiaDuration:1600,debug:!1},c=[`speed`,`direction`,`min-group-width-ratio`,`responsive-speed`,`reference-width`,`min-speed-factor`,`max-speed-factor`,`pause-on-hover`,`pause-when-out-of-view`,`recalculate-after-fonts-ready`,`scroll-velocity-factor`,`scroll-min-extra-speed`,`scroll-max-extra-speed`,`scroll-inertia-duration`,`debug`],l={speed:`speed`,direction:`direction`,minGroupWidthRatio:`min-group-width-ratio`,responsiveSpeed:`responsive-speed`,referenceWidth:`reference-width`,minSpeedFactor:`min-speed-factor`,maxSpeedFactor:`max-speed-factor`,pauseOnHover:`pause-on-hover`,pauseWhenOutOfView:`pause-when-out-of-view`,recalculateAfterFontsReady:`recalculate-after-fonts-ready`,scrollVelocityFactor:`scroll-velocity-factor`,scrollMinExtraSpeed:`scroll-min-extra-speed`,scrollMaxExtraSpeed:`scroll-max-extra-speed`,scrollInertiaDuration:`scroll-inertia-duration`,debug:`debug`},u=[`--marquee-content-distance`,`--marquee-content-duration`],d=`
66
- <slot class="marquee-content__source"></slot>
67
-
68
- <div class="marquee-content__viewport" part="viewport">
69
- <div class="marquee-content__track" part="track"></div>
70
- </div>
71
- `,f=class e extends HTMLElement{static get observedAttributes(){return[...c]}static instances=new Set;static stylesheetEntry=i(t);static styleOverridesEntry=i(null);static configureStyles(n={}){`stylesheet`in n&&(e.stylesheetEntry=i(n.stylesheet??t)),`styleOverrides`in n&&(e.styleOverridesEntry=i(n.styleOverrides)),e.instances.forEach(e=>{e.applyAllStyles()})}static setStylesheet(t){e.configureStyles({stylesheet:t})}static setStyleOverrides(t){e.configureStyles({styleOverrides:t})}shadow;sourceSlot;track;options={...s};sourceNodes=[];resizeObserver=null;mutationObserver=null;intersectionObserver=null;abortController=null;reducedMotionMediaQuery=null;animationFrameId=null;rebuildFrameId=null;lastFrameTime=null;mounted=!1;isHovered=!1;isInViewport=!0;reducedMotion=!1;distance=0;offset=0;emptySourceRebuildCount=0;hasWarnedMissingSourceNodes=!1;scrollDirectionFactor=1;scrollBoostStartValue=0;scrollBoostStartedAt=0;lastScrollY=0;lastScrollTime=0;constructor(){super(),this.shadow=this.attachShadow({mode:`open`}),this.applyAllStyles();let e=document.createElement(`template`);e.innerHTML=d,this.shadow.appendChild(e.content.cloneNode(!0));let t=this.shadow.querySelector(`slot.marquee-content__source`),n=this.shadow.querySelector(`.marquee-content__track`);if(!t)throw Error(`[MarqueeContent] Source slot was not found.`);if(!n)throw Error(`[MarqueeContent] Track element was not found.`);this.sourceSlot=t,this.track=n}connectedCallback(){this.mounted||(e.instances.add(this),this.mounted=!0,this.abortController=new AbortController,this.options=this.resolveOptions(),this.lastScrollY=this.getScrollY(),this.lastScrollTime=performance.now(),this.sourceSlot.addEventListener(`slotchange`,this.handleSlotChange,{signal:this.abortController.signal}),this.shadow.addEventListener(`load`,this.scheduleRebuild,{capture:!0,signal:this.abortController.signal}),this.addEventListener(`pointerenter`,this.handlePointerEnter,{signal:this.abortController.signal}),this.addEventListener(`pointerleave`,this.handlePointerLeave,{signal:this.abortController.signal}),window.addEventListener(`scroll`,this.handleScroll,{passive:!0,signal:this.abortController.signal}),window.addEventListener(`orientationchange`,this.scheduleRebuild,{signal:this.abortController.signal}),typeof ResizeObserver<`u`?(this.resizeObserver=new ResizeObserver(this.scheduleRebuild),this.resizeObserver.observe(this)):window.addEventListener(`resize`,this.scheduleRebuild,{signal:this.abortController.signal}),`IntersectionObserver`in window&&(this.intersectionObserver=new IntersectionObserver(this.handleIntersectionChange),this.intersectionObserver.observe(this)),this.setupReducedMotionWatcher(),this.watchSourceNodes(),this.rebuild(),this.options.recalculateAfterFontsReady&&this.rebuildAfterFontsReady())}disconnectedCallback(){this.teardown(),e.instances.delete(this)}attributeChangedCallback(e,t,n){t!==n&&(this.options=this.resolveOptions(),this.mounted&&this.scheduleRebuild())}get speed(){return this.options.speed}set speed(e){this.setNullableAttribute(`speed`,e)}get direction(){return this.options.direction}set direction(e){this.setNullableAttribute(`direction`,e)}get minGroupWidthRatio(){return this.options.minGroupWidthRatio}set minGroupWidthRatio(e){this.setNullableAttribute(`min-group-width-ratio`,e)}get responsiveSpeed(){return this.options.responsiveSpeed}set responsiveSpeed(e){this.setNullableAttribute(`responsive-speed`,e)}get referenceWidth(){return this.options.referenceWidth}set referenceWidth(e){this.setNullableAttribute(`reference-width`,e)}get minSpeedFactor(){return this.options.minSpeedFactor}set minSpeedFactor(e){this.setNullableAttribute(`min-speed-factor`,e)}get maxSpeedFactor(){return this.options.maxSpeedFactor}set maxSpeedFactor(e){this.setNullableAttribute(`max-speed-factor`,e)}get pauseOnHover(){return this.options.pauseOnHover}set pauseOnHover(e){this.setNullableAttribute(`pause-on-hover`,e)}get pauseWhenOutOfView(){return this.options.pauseWhenOutOfView}set pauseWhenOutOfView(e){this.setNullableAttribute(`pause-when-out-of-view`,e)}get recalculateAfterFontsReady(){return this.options.recalculateAfterFontsReady}set recalculateAfterFontsReady(e){this.setNullableAttribute(`recalculate-after-fonts-ready`,e)}get scrollVelocityFactor(){return this.options.scrollVelocityFactor}set scrollVelocityFactor(e){this.setNullableAttribute(`scroll-velocity-factor`,e)}get scrollMinExtraSpeed(){return this.options.scrollMinExtraSpeed}set scrollMinExtraSpeed(e){this.setNullableAttribute(`scroll-min-extra-speed`,e)}get scrollMaxExtraSpeed(){return this.options.scrollMaxExtraSpeed}set scrollMaxExtraSpeed(e){this.setNullableAttribute(`scroll-max-extra-speed`,e)}get scrollInertiaDuration(){return this.options.scrollInertiaDuration}set scrollInertiaDuration(e){this.setNullableAttribute(`scroll-inertia-duration`,e)}get debug(){return this.options.debug}set debug(e){this.setNullableAttribute(`debug`,e)}update(e={}){Object.entries(e).forEach(([e,t])=>{let n=l[e];n&&this.setNullableAttribute(n,t)}),this.options=this.resolveOptions(),this.scheduleRebuild()}refresh(){this.scheduleRebuild()}adoptStyles(t){e.setStylesheet(t)}adoptStyleOverrides(t){e.setStyleOverrides(t)}applyAllStyles(){let t=e.stylesheetEntry,n=e.styleOverridesEntry;if(a(this.shadow)){let e=[];t.sheet&&e.push(t.sheet),n.sheet&&e.push(n.sheet),this.shadow.adoptedStyleSheets=e,this.removeFallbackStyleElements();return}this.applyFallbackStyleElement(`base`,t.cssText),this.applyFallbackStyleElement(`overrides`,n.cssText)}applyFallbackStyleElement(e,t){let n=`data-marquee-content-style-${e}`,r=this.shadow.querySelector(`style[${n}]`);if(!t){r?.remove();return}r||(r=document.createElement(`style`),r.setAttribute(n,``),this.shadow.prepend(r)),r.textContent!==t&&(r.textContent=t)}removeFallbackStyleElements(){this.shadow.querySelectorAll(`style[data-marquee-content-style-base], style[data-marquee-content-style-overrides]`).forEach(e=>{e.remove()})}teardown(){this.mounted&&(this.mounted=!1,this.stopAnimationLoop(),this.cancelScheduledRebuild(),this.resizeObserver?.disconnect(),this.mutationObserver?.disconnect(),this.intersectionObserver?.disconnect(),this.removeReducedMotionWatcher(),this.abortController?.abort(),this.resizeObserver=null,this.mutationObserver=null,this.intersectionObserver=null,this.abortController=null,this.track.replaceChildren(),this.removeAttribute(`data-marquee-content-ready`),this.removeAttribute(`data-marquee-content-pause-on-hover`),u.forEach(e=>{this.style.removeProperty(e)}),this.distance=0,this.offset=0,this.lastFrameTime=null)}handleSlotChange=()=>{this.watchSourceNodes(),this.scheduleRebuild()};handlePointerEnter=()=>{this.isHovered=!0,this.updateAnimationLoopState()};handlePointerLeave=()=>{this.isHovered=!1,this.updateAnimationLoopState()};handleIntersectionChange=e=>{let t=e[0];t&&(this.isInViewport=t.isIntersecting,this.updateAnimationLoopState())};handleReducedMotionChange=e=>{this.reducedMotion=e.matches,this.reducedMotion?this.track.style.transform=`none`:this.applyTransform(),this.updateAnimationLoopState()};handleScroll=()=>{if(this.options.direction!==`scroll`)return;let e=performance.now(),t=this.getScrollY(),n=t-this.lastScrollY,r=Math.max((e-this.lastScrollTime)/1e3,.016);if(this.lastScrollY=t,this.lastScrollTime=e,Math.abs(n)<.5)return;let i=n/r;this.scrollDirectionFactor=i>=0?1:-1;let a=this.clamp(i/this.options.scrollVelocityFactor,-this.options.scrollMaxExtraSpeed,this.options.scrollMaxExtraSpeed);Math.abs(a)>=this.options.scrollMinExtraSpeed?(this.scrollBoostStartValue=a,this.scrollBoostStartedAt=e):this.scrollBoostStartValue=0,this.updateAnimationLoopState(),this.options.debug&&console.info(`[MarqueeContent] Scroll update`,{velocity:i,directionFactor:this.scrollDirectionFactor,extraSpeed:a})};scheduleRebuild=()=>{this.mounted&&(this.cancelScheduledRebuild(),this.rebuildFrameId=requestAnimationFrame(()=>{this.rebuildFrameId=null,this.rebuild()}))};cancelScheduledRebuild(){this.rebuildFrameId!==null&&(cancelAnimationFrame(this.rebuildFrameId),this.rebuildFrameId=null)}rebuild(){if(!this.mounted)return;this.options=this.resolveOptions(),this.removeAttribute(`data-marquee-content-ready`),this.options.pauseOnHover?this.setAttribute(`data-marquee-content-pause-on-hover`,`true`):this.removeAttribute(`data-marquee-content-pause-on-hover`);let e=this.clientWidth;if(e<=0){this.distance=0,this.track.replaceChildren(),this.updateAnimationLoopState();return}if(this.sourceNodes=this.getSourceNodes(),this.sourceNodes.length===0){this.emptySourceRebuildCount+=1,this.warnAboutMissingSourceNodes(),this.distance=0,this.track.replaceChildren(),this.updateAnimationLoopState();return}this.emptySourceRebuildCount=0,this.hasWarnedMissingSourceNodes=!1;let t=this.createGroup(),n=e*this.options.minGroupWidthRatio;this.track.replaceChildren(t),this.expandGroupToWidth(t,n);let r=t.cloneNode(!0);if(r.setAttribute(`aria-hidden`,`true`),this.track.appendChild(r),this.distance=t.scrollWidth,this.offset=this.normalizeOffset(this.offset),this.distance<=0){this.track.replaceChildren(),this.updateAnimationLoopState();return}let i=this.getCurrentSpeed(e),a=this.distance/i;this.style.setProperty(`--marquee-content-distance`,`${this.distance}px`),this.style.setProperty(`--marquee-content-duration`,`${a}s`),this.reducedMotion?this.track.style.transform=`none`:this.applyTransform(),this.setAttribute(`data-marquee-content-ready`,`true`),this.updateAnimationLoopState(),this.options.debug&&console.info(`[MarqueeContent] Rebuilt`,{containerWidth:e,distance:this.distance,baseSpeed:this.options.speed,currentSpeed:i,duration:a,direction:this.options.direction,responsiveSpeed:this.options.responsiveSpeed})}warnAboutMissingSourceNodes(){this.hasWarnedMissingSourceNodes||this.emptySourceRebuildCount<2||(this.hasWarnedMissingSourceNodes=!0,console.warn([`[MarqueeContent] No source nodes were detected for <marquee-content>.`,`If you use Vue + Vite, configure compilerOptions.isCustomElement for "marquee-content",`,`otherwise Vue may treat it as a Vue component and slot content will not be exposed to the Web Component.`].join(` `)))}createGroup(){let e=document.createElement(`div`);return e.className=`marquee-content__group`,e.setAttribute(`part`,`group`),this.appendSourceNodes(e),e}expandGroupToWidth(e,t){let n=0;for(;e.scrollWidth<t&&n<100;){let t=e.scrollWidth;if(this.appendSourceNodes(e),e.scrollWidth<=t)break;n+=1}}appendSourceNodes(e){let t=document.createDocumentFragment();this.sourceNodes.forEach(e=>{t.append(this.cloneSourceNode(e))}),e.appendChild(t)}cloneSourceNode(e){let t=e.cloneNode(!0);if(t instanceof Element){let e=t.getAttribute(`part`);t.setAttribute(`part`,e?`${e} item`:`item`)}return t}getSourceNodes(){return this.sourceSlot.assignedNodes({flatten:!0}).filter(e=>e.nodeType===Node.TEXT_NODE?!!e.textContent?.trim():e.nodeType===Node.ELEMENT_NODE)}watchSourceNodes(){this.mutationObserver?.disconnect(),`MutationObserver`in window&&(this.mutationObserver=new MutationObserver(this.scheduleRebuild),this.getSourceNodes().forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){this.mutationObserver?.observe(e,{attributes:!0,childList:!0,characterData:!0,subtree:!0});return}e.nodeType===Node.TEXT_NODE&&this.mutationObserver?.observe(e,{characterData:!0})}))}setupReducedMotionWatcher(){if(!(`matchMedia`in window))return;if(this.reducedMotionMediaQuery=window.matchMedia(`(prefers-reduced-motion: reduce)`),this.reducedMotion=this.reducedMotionMediaQuery.matches,typeof this.reducedMotionMediaQuery.addEventListener==`function`){this.reducedMotionMediaQuery.addEventListener(`change`,this.handleReducedMotionChange,{signal:this.abortController?.signal});return}let e=this.reducedMotionMediaQuery;typeof e.addListener==`function`&&e.addListener(this.handleReducedMotionChange)}removeReducedMotionWatcher(){if(this.reducedMotionMediaQuery){if(typeof this.reducedMotionMediaQuery.removeEventListener==`function`)this.reducedMotionMediaQuery.removeEventListener(`change`,this.handleReducedMotionChange);else{let e=this.reducedMotionMediaQuery;typeof e.removeListener==`function`&&e.removeListener(this.handleReducedMotionChange)}this.reducedMotionMediaQuery=null}}updateAnimationLoopState(){if(!this.mounted||this.distance<=0||this.reducedMotion||!this.canAnimate()){this.stopAnimationLoop();return}this.startAnimationLoop()}canAnimate(){return!(this.options.pauseOnHover&&this.isHovered||this.options.pauseWhenOutOfView&&!this.isInViewport)}startAnimationLoop(){this.animationFrameId===null&&(this.lastFrameTime=performance.now(),this.animationFrameId=requestAnimationFrame(this.tick))}stopAnimationLoop(){if(this.animationFrameId===null){this.lastFrameTime=null;return}cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null,this.lastFrameTime=null}tick=e=>{if(this.animationFrameId=null,!this.mounted||this.distance<=0||this.reducedMotion||!this.canAnimate()){this.stopAnimationLoop();return}let t=this.lastFrameTime??e,n=Math.min((e-t)/1e3,.064);this.lastFrameTime=e;let r=this.getCurrentSpeed(this.clientWidth),i=this.getCurrentTimeScale(e);this.offset=this.normalizeOffset(this.offset+r*i*n),this.applyTransform(),this.animationFrameId=requestAnimationFrame(this.tick)};getCurrentTimeScale(e){if(this.options.direction===`rtl`)return 1;if(this.options.direction===`ltr`)return-1;let t=this.getScrollBoost(e);return this.clamp(this.scrollDirectionFactor+t,-1-this.options.scrollMaxExtraSpeed,1+this.options.scrollMaxExtraSpeed)}getScrollBoost(e){if(this.scrollBoostStartValue===0)return 0;let t=this.options.scrollInertiaDuration;if(t<=0)return this.scrollBoostStartValue=0,0;let n=this.clamp((e-this.scrollBoostStartedAt)/t,0,1);if(n>=1)return this.scrollBoostStartValue=0,0;let r=this.easeOutCubic(n);return this.scrollBoostStartValue*(1-r)}applyTransform(){this.track.style.transform=`translate3d(${-this.offset}px, 0, 0)`}normalizeOffset(e){if(this.distance<=0)return 0;let t=e%this.distance;return t<0?t+this.distance:t}getCurrentSpeed(e){if(!this.options.responsiveSpeed)return this.options.speed;let t=this.clamp(e/this.options.referenceWidth,this.options.minSpeedFactor,this.options.maxSpeedFactor);return this.options.speed*t}resolveOptions(){let e=this.num(`min-speed-factor`,s.minSpeedFactor,.1,2),t=this.num(`max-speed-factor`,s.maxSpeedFactor,.1,3);return{speed:this.num(`speed`,s.speed,10,500),direction:this.parseDirection(this.getAttribute(`direction`),s.direction),minGroupWidthRatio:this.num(`min-group-width-ratio`,s.minGroupWidthRatio,1,5),responsiveSpeed:this.parseBoolean(this.getAttribute(`responsive-speed`),s.responsiveSpeed),referenceWidth:this.num(`reference-width`,s.referenceWidth,320,1e4),minSpeedFactor:Math.min(e,t),maxSpeedFactor:Math.max(e,t),pauseOnHover:this.parseBoolean(this.getAttribute(`pause-on-hover`),s.pauseOnHover),pauseWhenOutOfView:this.parseBoolean(this.getAttribute(`pause-when-out-of-view`),s.pauseWhenOutOfView),recalculateAfterFontsReady:this.parseBoolean(this.getAttribute(`recalculate-after-fonts-ready`),s.recalculateAfterFontsReady),scrollVelocityFactor:this.num(`scroll-velocity-factor`,s.scrollVelocityFactor,50,5e3),scrollMinExtraSpeed:this.num(`scroll-min-extra-speed`,s.scrollMinExtraSpeed,0,5),scrollMaxExtraSpeed:this.num(`scroll-max-extra-speed`,s.scrollMaxExtraSpeed,0,10),scrollInertiaDuration:this.num(`scroll-inertia-duration`,s.scrollInertiaDuration,0,5e3),debug:this.parseBoolean(this.getAttribute(`debug`),s.debug)}}num(e,t,n,r){return this.clamp(this.parseNumber(this.getAttribute(e),t),n,r)}parseNumber(e,t){if(e===null||e.trim()===``)return t;let n=Number(e);return Number.isFinite(n)?n:t}parseBoolean(e,t){if(e===null)return t;let n=e.trim().toLowerCase();return n===``||[`true`,`1`,`yes`,`on`].includes(n)?!0:[`false`,`0`,`no`,`off`].includes(n)?!1:t}parseDirection(e,t){return e===`rtl`||e===`ltr`||e===`scroll`?e:t}setNullableAttribute(e,t){if(t==null){this.removeAttribute(e);return}this.setAttribute(e,String(t))}getScrollY(){return window.scrollY||window.pageYOffset||0}clamp(e,t,n){return Math.min(Math.max(e,t),n)}easeOutCubic(e){return 1-(1-e)**3}rebuildAfterFontsReady(){let e=document.fonts;e?.ready&&e.ready.then(this.scheduleRebuild).catch(()=>void 0)}};function p(e=o,t={}){typeof window>`u`||!window.customElements||(f.configureStyles(t),window.customElements.get(e)||window.customElements.define(e,f))}function m(e={}){let{tagName:t=o,...n}=e;p(t,n)}p(),e.MARQUEE_CONTENT_TAG=o,e.MarqueeContent=f,e.createConstructableStyleSheet=n,e.cssStyleSheetToText=r,e.defineMarqueeContent=p,e.initMarqueeContents=m,e.marqueeContentCssText=t,e.normalizeStyleInput=i});