marquee-content 4.6.1 → 5.0.0-dev.2

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 CHANGED
@@ -1,99 +1,558 @@
1
- var h = Object.defineProperty;
2
- var d = (r, e, t) => e in r ? h(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var n = (r, e, t) => d(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { gsap as p } from "gsap";
5
- import { ScrollTrigger as u } from "gsap/ScrollTrigger";
6
- const i = class i {
7
- constructor({ element: e = ".marquee" } = {}) {
8
- n(this, "gsapInstance", i._gsap);
9
- n(this, "timeline");
10
- n(this, "matchMedia");
11
- n(this, "element");
12
- n(this, "resizeObserver");
13
- n(this, "animationFrame");
14
- const t = e instanceof HTMLElement ? e : document.querySelector(e);
15
- if (!t) throw new Error("Target element not found");
16
- this.element = t, this.gsapInstance = i._gsap, this.matchMedia = this.gsapInstance.matchMedia(), this.resizeObserver = new ResizeObserver(i.debounce(() => {
17
- this.update();
18
- })), this.resizeObserver.observe(this.element);
19
- }
20
- static registerGSAP(e, t) {
21
- i._gsap = e, i._ScrollTrigger = t;
22
- }
23
- static debounce(e) {
24
- let t = null;
25
- return (...s) => {
26
- t !== null && cancelAnimationFrame(t), t = requestAnimationFrame(() => e(...s));
27
- };
28
- }
29
- init() {
30
- this.setup();
31
- }
32
- destroy() {
33
- this.animationFrame !== void 0 && (cancelAnimationFrame(this.animationFrame), this.animationFrame = void 0), this.resizeObserver.disconnect(), this.clearTimeline();
34
- }
35
- setup() {
36
- this.clearTimeline(), this.cloneElements(), this.setBreakpoints(), this.applySkew(), this.timeline = this.createAnimation();
37
- }
38
- update() {
39
- this.animationFrame !== void 0 && cancelAnimationFrame(this.animationFrame), this.animationFrame = requestAnimationFrame(() => {
40
- var e, t;
41
- this.setup(), (t = (e = i._ScrollTrigger).refresh) == null || t.call(e);
42
- });
43
- }
44
- createAnimation() {
45
- var s;
46
- (s = this.timeline) == null || s.kill();
47
- const e = this.gsapInstance.timeline({ scrollTrigger: { trigger: this.element, start: "top bottom", end: "bottom top", toggleActions: "resume pause resume pause", onUpdate: (a) => {
48
- const { mcDirection: l } = this.element.dataset;
49
- l === "ltr" ? e.timeScale(-1) : l === "auto" && e.timeScale(a.direction);
50
- } } }), t = this.element.dataset.mcBreakpoint || "";
51
- return this.matchMedia.add(t, () => {
52
- const a = parseFloat(this.element.dataset.mcSpeed ?? "20");
53
- return e.to(this.element.children, { duration: a, x: "-100%", repeat: -1, ease: "none" }), e.totalProgress(0.5), () => {
54
- e.kill();
55
- };
56
- }), e;
57
- }
58
- clearTimeline() {
59
- var e;
60
- (e = this.timeline) == null || e.kill(), this.timeline = void 0, this.gsapInstance.set(this.element.children, { clearProps: "all" });
61
- }
62
- setBreakpoints() {
63
- const { mcMax: e, mcMin: t } = this.element.dataset;
64
- this.element.dataset.mcBreakpoint = e ? `(max-width: ${parseFloat(e) - 0.02}px)` : t ? `(min-width: ${t}px)` : "";
65
- }
66
- cloneElements() {
67
- const e = () => {
68
- for (; this.element.childElementCount > 1; ) this.element.removeChild(this.element.lastChild);
69
- };
70
- e();
71
- const t = this.element.dataset.mcBreakpoint || "";
72
- this.matchMedia.add(t, () => {
73
- const s = this.element.firstElementChild;
74
- if (!s) return () => {
75
- };
76
- const a = Math.ceil(this.element.scrollWidth / s.clientWidth + 2);
77
- if (this.element.childElementCount < a) {
78
- const l = document.createDocumentFragment();
79
- for (let m = 0; m < a - 1; m++) {
80
- const c = s.cloneNode(!0);
81
- l.appendChild(c);
82
- }
83
- this.element.appendChild(l);
84
- }
85
- return () => {
86
- e();
87
- };
88
- });
89
- }
90
- applySkew() {
91
- const { mcSkew: e } = this.element.dataset;
92
- e && (this.element.style.transformOrigin = "center center", this.element.style.transform = `skew(0deg, ${e}deg)`);
93
- }
94
- };
95
- n(i, "_gsap", p), n(i, "_ScrollTrigger", u);
96
- let o = i;
97
- export {
98
- o as default
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
+ }
99
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 };