marquee-content 5.0.0-dev.1 → 5.0.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.
package/dist/index.cjs CHANGED
@@ -1,71 +1,656 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`:host {
2
- --marquee-content-gap: 2rem;
3
- --marquee-content-distance: 0px;
4
- --marquee-content-duration: 20s;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
2
 
6
- display: block;
7
- overflow: hidden;
8
- width: 100%;
9
- color: inherit;
10
- font: inherit;
3
+ //#region src/marquee-content.css?inline
4
+ var marquee_content_default = ":host{--marquee-content-gap:2rem;--marquee-content-distance:0px;--marquee-content-duration:20s;width:100%;color:inherit;font:inherit;pointer-events:none;display:block;position:relative;overflow:hidden}:host([pause-on-hover]:not([pause-on-hover=false])){pointer-events:auto}:host([hidden]){display:none}.marquee-content__viewport{width:100%;overflow:hidden}.marquee-content__track{will-change:transform;width:max-content;display:flex;transform:translate(0,0)}.marquee-content__group{align-items:center;gap:var(--marquee-content-gap);white-space:nowrap;color:inherit;font:inherit;flex:none;padding-inline-end:var(--marquee-content-gap);display:flex}.marquee-content__group>*{flex:none}\n";
11
5
 
12
- /*
13
- По умолчанию компонент не ловит pointer events.
14
- Это удобно для декоративной бегущей строки.
15
- Если включить pause-on-hover, pointer-events включатся автоматически.
16
- */
17
- pointer-events: none;
6
+ //#endregion
7
+ //#region src/styles.ts
8
+ const marqueeContentCssText = marquee_content_default;
9
+ function createConstructableStyleSheet(cssText) {
10
+ if (typeof CSSStyleSheet === "undefined" || typeof CSSStyleSheet.prototype.replaceSync !== "function") return null;
11
+ try {
12
+ const sheet = new CSSStyleSheet();
13
+ sheet.replaceSync(cssText);
14
+ return sheet;
15
+ } catch {
16
+ return null;
17
+ }
18
18
  }
19
-
20
- :host([pause-on-hover]:not([pause-on-hover="false"])) {
21
- pointer-events: auto;
19
+ function cssStyleSheetToText(sheet) {
20
+ try {
21
+ return Array.from(sheet.cssRules).map((rule) => rule.cssText).join("\n");
22
+ } catch {
23
+ return "";
24
+ }
22
25
  }
23
-
24
- :host([hidden]) {
25
- display: none;
26
+ function normalizeStyleInput(input) {
27
+ if (!input) return {
28
+ sheet: null,
29
+ cssText: ""
30
+ };
31
+ if (typeof input === "string") return {
32
+ sheet: createConstructableStyleSheet(input),
33
+ cssText: input
34
+ };
35
+ return {
36
+ sheet: input,
37
+ cssText: cssStyleSheetToText(input)
38
+ };
26
39
  }
27
40
 
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
- }
41
+ //#endregion
42
+ //#region src/marquee-content.ts
43
+ const MARQUEE_CONTENT_TAG = "marquee-content";
44
+ const DEFAULT_OPTIONS = {
45
+ speed: 90,
46
+ mode: "auto",
47
+ direction: "rtl",
48
+ minGroupWidthRatio: 1.05,
49
+ responsiveSpeed: true,
50
+ referenceWidth: 1280,
51
+ minSpeedFactor: .55,
52
+ maxSpeedFactor: 1,
53
+ pauseOnHover: false,
54
+ pauseWhenOutOfView: true,
55
+ recalculateAfterFontsReady: true,
56
+ scrollVelocityFactor: 150,
57
+ scrollMinExtraSpeed: .05,
58
+ scrollMaxExtraSpeed: 5,
59
+ scrollInertiaDuration: 2500
60
+ };
61
+ const OBSERVED_ATTRIBUTES = [
62
+ "speed",
63
+ "mode",
64
+ "direction",
65
+ "pause-on-hover"
66
+ ];
67
+ const OPTION_ATTRIBUTE_MAP = {
68
+ speed: "speed",
69
+ mode: "mode",
70
+ direction: "direction",
71
+ pauseOnHover: "pause-on-hover"
72
+ };
73
+ const MARQUEE_CONTENT_CSS_PROPS = ["--marquee-content-distance", "--marquee-content-duration"];
74
+ const MARQUEE_CONTENT_RUNTIME_CSS = `
75
+ @keyframes marquee-content-auto {
76
+ to {
77
+ transform: translate3d(calc(-1 * var(--marquee-content-distance)), 0, 0);
78
+ }
79
+ }
54
80
 
55
- .marquee-content__group > * {
56
- flex: 0 0 auto;
57
- }
81
+ .marquee-content__source {
82
+ position: absolute;
83
+ width: 0;
84
+ height: 0;
85
+ overflow: hidden;
86
+ }
58
87
 
59
- @media (prefers-reduced-motion: reduce) {
60
- .marquee-content__track {
61
- transform: none !important;
88
+ .marquee-content__source::slotted(*) {
89
+ position: absolute;
90
+ width: 1px;
91
+ height: 1px;
92
+ padding: 0;
93
+ margin: -1px;
94
+ overflow: hidden;
95
+ clip-path: inset(50%);
96
+ white-space: nowrap;
97
+ border: 0;
62
98
  }
63
- }
64
- `;function t(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 n(e){try{return Array.from(e.cssRules).map(e=>e.cssText).join(`
65
- `)}catch{return``}}function r(e){return e?typeof e==`string`?{sheet:t(e),cssText:e}:{sheet:e,cssText:n(e)}:{sheet:null,cssText:``}}function i(e){return typeof CSSStyleSheet<`u`&&`adoptedStyleSheets`in e&&typeof CSSStyleSheet.prototype.replaceSync==`function`}var a=`marquee-content`,o={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},s=[`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`],c={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`},l=[`--marquee-content-distance`,`--marquee-content-duration`],u=`
99
+ `;
100
+ const TEMPLATE = `
66
101
  <slot class="marquee-content__source"></slot>
67
102
 
68
103
  <div class="marquee-content__viewport" part="viewport">
69
- <div class="marquee-content__track" part="track"></div>
104
+ <div class="marquee-content__track" part="track" aria-hidden="true"></div>
70
105
  </div>
71
- `,d=class t extends HTMLElement{static get observedAttributes(){return[...s]}static instances=new Set;static stylesheetEntry=r(e);static styleOverridesEntry=r(null);static configureStyles(n={}){`stylesheet`in n&&(t.stylesheetEntry=r(n.stylesheet??e)),`styleOverrides`in n&&(t.styleOverridesEntry=r(n.styleOverrides)),t.instances.forEach(e=>{e.applyAllStyles()})}static setStylesheet(e){t.configureStyles({stylesheet:e})}static setStyleOverrides(e){t.configureStyles({styleOverrides:e})}shadow;sourceSlot;track;options={...o};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;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=u,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||(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,{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(),t.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=c[e];n&&this.setNullableAttribute(n,t)}),this.options=this.resolveOptions(),this.scheduleRebuild()}refresh(){this.scheduleRebuild()}adoptStyles(e){t.setStylesheet(e)}adoptStyleOverrides(e){t.setStyleOverrides(e)}applyAllStyles(){let e=t.stylesheetEntry,n=t.styleOverridesEntry;if(i(this.shadow)){let t=[];e.sheet&&t.push(e.sheet),n.sheet&&t.push(n.sheet),this.shadow.adoptedStyleSheets=t,this.removeFallbackStyleElements();return}this.applyFallbackStyleElement(`base`,e.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`),l.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.distance=0,this.track.replaceChildren(),this.updateAnimationLoopState();return}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})}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`,o.minSpeedFactor,.1,2),t=this.num(`max-speed-factor`,o.maxSpeedFactor,.1,3);return{speed:this.num(`speed`,o.speed,10,500),direction:this.parseDirection(this.getAttribute(`direction`),o.direction),minGroupWidthRatio:this.num(`min-group-width-ratio`,o.minGroupWidthRatio,1,5),responsiveSpeed:this.parseBoolean(this.getAttribute(`responsive-speed`),o.responsiveSpeed),referenceWidth:this.num(`reference-width`,o.referenceWidth,320,1e4),minSpeedFactor:Math.min(e,t),maxSpeedFactor:Math.max(e,t),pauseOnHover:this.parseBoolean(this.getAttribute(`pause-on-hover`),o.pauseOnHover),pauseWhenOutOfView:this.parseBoolean(this.getAttribute(`pause-when-out-of-view`),o.pauseWhenOutOfView),recalculateAfterFontsReady:this.parseBoolean(this.getAttribute(`recalculate-after-fonts-ready`),o.recalculateAfterFontsReady),scrollVelocityFactor:this.num(`scroll-velocity-factor`,o.scrollVelocityFactor,50,5e3),scrollMinExtraSpeed:this.num(`scroll-min-extra-speed`,o.scrollMinExtraSpeed,0,5),scrollMaxExtraSpeed:this.num(`scroll-max-extra-speed`,o.scrollMaxExtraSpeed,0,10),scrollInertiaDuration:this.num(`scroll-inertia-duration`,o.scrollInertiaDuration,0,5e3),debug:this.parseBoolean(this.getAttribute(`debug`),o.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 f(e=a,t={}){typeof window>`u`||!window.customElements||(d.configureStyles(t),window.customElements.get(e)||window.customElements.define(e,d))}function p(e={}){let{tagName:t=a,...n}=e;f(t,n)}f(),exports.MARQUEE_CONTENT_TAG=a,exports.MarqueeContent=d,exports.createConstructableStyleSheet=t,exports.cssStyleSheetToText=n,exports.defineMarqueeContent=f,exports.initMarqueeContents=p,exports.marqueeContentCssText=e,exports.normalizeStyleInput=r;
106
+ `;
107
+ var MarqueeContent = class MarqueeContent extends HTMLElement {
108
+ static get observedAttributes() {
109
+ return [...OBSERVED_ATTRIBUTES];
110
+ }
111
+ static instances = /* @__PURE__ */ new Set();
112
+ static runtimeStylesheetEntry = normalizeStyleInput(MARQUEE_CONTENT_RUNTIME_CSS);
113
+ static stylesheetEntry = normalizeStyleInput(marqueeContentCssText);
114
+ static styleOverridesEntry = normalizeStyleInput(null);
115
+ static configureStyles(options = {}) {
116
+ if ("stylesheet" in options) MarqueeContent.stylesheetEntry = normalizeStyleInput(options.stylesheet ?? marqueeContentCssText);
117
+ if ("styleOverrides" in options) MarqueeContent.styleOverridesEntry = normalizeStyleInput(options.styleOverrides);
118
+ MarqueeContent.instances.forEach((instance) => {
119
+ instance.applyAllStyles();
120
+ });
121
+ }
122
+ static setStylesheet(stylesheet) {
123
+ MarqueeContent.configureStyles({ stylesheet });
124
+ }
125
+ static setStyleOverrides(styleOverrides) {
126
+ MarqueeContent.configureStyles({ styleOverrides });
127
+ }
128
+ shadow;
129
+ sourceSlot;
130
+ track;
131
+ options = { ...DEFAULT_OPTIONS };
132
+ sourceNodes = [];
133
+ resizeObserver = null;
134
+ mutationObserver = null;
135
+ intersectionObserver = null;
136
+ abortController = null;
137
+ reducedMotionMediaQuery = null;
138
+ animationFrameId = null;
139
+ rebuildFrameId = null;
140
+ lastFrameTime = null;
141
+ mounted = false;
142
+ isHovered = false;
143
+ isFocused = false;
144
+ isInViewport = true;
145
+ reducedMotion = false;
146
+ isListeningToScroll = false;
147
+ distance = 0;
148
+ offset = 0;
149
+ scrollDirectionFactor = 1;
150
+ scrollBoostStartValue = 0;
151
+ scrollBoostStartedAt = 0;
152
+ lastScrollY = 0;
153
+ lastScrollTime = 0;
154
+ constructor() {
155
+ super();
156
+ this.shadow = this.attachShadow({ mode: "open" });
157
+ this.applyAllStyles();
158
+ const template = document.createElement("template");
159
+ template.innerHTML = TEMPLATE;
160
+ this.shadow.appendChild(template.content.cloneNode(true));
161
+ const sourceSlot = this.shadow.querySelector("slot.marquee-content__source");
162
+ const track = this.shadow.querySelector(".marquee-content__track");
163
+ if (!sourceSlot) throw new Error("[MarqueeContent] Source slot was not found.");
164
+ if (!track) throw new Error("[MarqueeContent] Track element was not found.");
165
+ this.sourceSlot = sourceSlot;
166
+ this.track = track;
167
+ }
168
+ connectedCallback() {
169
+ if (this.mounted) return;
170
+ MarqueeContent.instances.add(this);
171
+ this.mounted = true;
172
+ this.abortController = new AbortController();
173
+ this.options = this.resolveOptions();
174
+ this.lastScrollY = this.getScrollY();
175
+ this.lastScrollTime = performance.now();
176
+ this.sourceSlot.addEventListener("slotchange", this.handleSlotChange, { signal: this.abortController.signal });
177
+ this.shadow.addEventListener("load", this.scheduleRebuild, {
178
+ capture: true,
179
+ signal: this.abortController.signal
180
+ });
181
+ this.addEventListener("pointerenter", this.handlePointerEnter, { signal: this.abortController.signal });
182
+ this.addEventListener("pointerleave", this.handlePointerLeave, { signal: this.abortController.signal });
183
+ this.addEventListener("focusin", this.handleFocusIn, { signal: this.abortController.signal });
184
+ this.addEventListener("focusout", this.handleFocusOut, { signal: this.abortController.signal });
185
+ window.addEventListener("orientationchange", this.scheduleRebuild, { signal: this.abortController.signal });
186
+ this.resizeObserver = new ResizeObserver(this.scheduleRebuild);
187
+ this.resizeObserver.observe(this);
188
+ this.intersectionObserver = new IntersectionObserver(this.handleIntersectionChange);
189
+ this.intersectionObserver.observe(this);
190
+ this.setupReducedMotionWatcher();
191
+ this.watchSourceNodes();
192
+ this.updateScrollListener();
193
+ this.rebuild();
194
+ if (this.options.recalculateAfterFontsReady) this.rebuildAfterFontsReady();
195
+ }
196
+ disconnectedCallback() {
197
+ this.teardown();
198
+ MarqueeContent.instances.delete(this);
199
+ }
200
+ attributeChangedCallback(_name, oldValue, newValue) {
201
+ if (oldValue === newValue) return;
202
+ this.options = this.resolveOptions();
203
+ if (!this.mounted) return;
204
+ this.updateScrollListener();
205
+ this.scheduleRebuild();
206
+ }
207
+ get speed() {
208
+ return this.options.speed;
209
+ }
210
+ set speed(value) {
211
+ this.setNullableAttribute("speed", value);
212
+ }
213
+ get mode() {
214
+ return this.options.mode;
215
+ }
216
+ set mode(value) {
217
+ this.setNullableAttribute("mode", value);
218
+ }
219
+ get direction() {
220
+ return this.options.direction;
221
+ }
222
+ set direction(value) {
223
+ this.setNullableAttribute("direction", value);
224
+ }
225
+ get pauseOnHover() {
226
+ return this.options.pauseOnHover;
227
+ }
228
+ set pauseOnHover(value) {
229
+ this.setNullableAttribute("pause-on-hover", value);
230
+ }
231
+ update(options = {}) {
232
+ Object.entries(options).forEach(([key, value]) => {
233
+ const attributeName = OPTION_ATTRIBUTE_MAP[key];
234
+ if (attributeName) this.setNullableAttribute(attributeName, value);
235
+ });
236
+ this.options = this.resolveOptions();
237
+ this.updateScrollListener();
238
+ this.scheduleRebuild();
239
+ }
240
+ refresh() {
241
+ this.scheduleRebuild();
242
+ }
243
+ applyAllStyles() {
244
+ const runtime = MarqueeContent.runtimeStylesheetEntry;
245
+ const base = MarqueeContent.stylesheetEntry;
246
+ const overrides = MarqueeContent.styleOverridesEntry;
247
+ const sheets = [];
248
+ if (runtime.sheet) sheets.push(runtime.sheet);
249
+ if (base.sheet) sheets.push(base.sheet);
250
+ if (overrides.sheet) sheets.push(overrides.sheet);
251
+ this.shadow.adoptedStyleSheets = sheets;
252
+ }
253
+ teardown() {
254
+ if (!this.mounted) return;
255
+ this.mounted = false;
256
+ this.stopAnimationLoop();
257
+ this.stopCssAnimation();
258
+ this.cancelScheduledRebuild();
259
+ this.updateScrollListener(false);
260
+ this.resizeObserver?.disconnect();
261
+ this.mutationObserver?.disconnect();
262
+ this.intersectionObserver?.disconnect();
263
+ this.removeReducedMotionWatcher();
264
+ this.abortController?.abort();
265
+ this.resizeObserver = null;
266
+ this.mutationObserver = null;
267
+ this.intersectionObserver = null;
268
+ this.abortController = null;
269
+ this.track.replaceChildren();
270
+ this.removeAttribute("data-marquee-content-ready");
271
+ this.removeAttribute("data-marquee-content-mode");
272
+ this.removeAttribute("data-marquee-content-pause-on-hover");
273
+ MARQUEE_CONTENT_CSS_PROPS.forEach((prop) => {
274
+ this.style.removeProperty(prop);
275
+ });
276
+ this.distance = 0;
277
+ this.offset = 0;
278
+ this.lastFrameTime = null;
279
+ }
280
+ handleSlotChange = () => {
281
+ this.watchSourceNodes();
282
+ this.scheduleRebuild();
283
+ };
284
+ handlePointerEnter = () => {
285
+ this.isHovered = true;
286
+ this.updateAnimationLoopState();
287
+ };
288
+ handlePointerLeave = () => {
289
+ this.isHovered = false;
290
+ this.updateAnimationLoopState();
291
+ };
292
+ handleFocusIn = () => {
293
+ this.isFocused = true;
294
+ this.updateAnimationLoopState();
295
+ };
296
+ handleFocusOut = () => {
297
+ this.isFocused = false;
298
+ this.updateAnimationLoopState();
299
+ };
300
+ handleIntersectionChange = (entries) => {
301
+ const entry = entries[0];
302
+ if (!entry) return;
303
+ this.isInViewport = entry.isIntersecting;
304
+ this.updateAnimationLoopState();
305
+ };
306
+ handleReducedMotionChange = (event) => {
307
+ this.reducedMotion = event.matches;
308
+ if (this.reducedMotion) this.track.style.transform = "none";
309
+ else if (this.options.mode === "scroll") this.applyTransform();
310
+ this.updateAnimationLoopState();
311
+ };
312
+ handleScroll = () => {
313
+ if (this.options.mode !== "scroll") return;
314
+ const now = performance.now();
315
+ const currentScrollY = this.getScrollY();
316
+ const deltaY = currentScrollY - this.lastScrollY;
317
+ const deltaTime = Math.max((now - this.lastScrollTime) / 1e3, .016);
318
+ this.lastScrollY = currentScrollY;
319
+ this.lastScrollTime = now;
320
+ if (Math.abs(deltaY) < .5) return;
321
+ const velocity = deltaY / deltaTime;
322
+ this.scrollDirectionFactor = velocity >= 0 ? 1 : -1;
323
+ const extraSpeed = this.clamp(velocity / this.options.scrollVelocityFactor, -this.options.scrollMaxExtraSpeed, this.options.scrollMaxExtraSpeed);
324
+ if (Math.abs(extraSpeed) >= this.options.scrollMinExtraSpeed) {
325
+ this.scrollBoostStartValue = extraSpeed;
326
+ this.scrollBoostStartedAt = now;
327
+ } else this.scrollBoostStartValue = 0;
328
+ this.updateAnimationLoopState();
329
+ };
330
+ updateScrollListener(shouldListen = this.mounted && this.options.mode === "scroll") {
331
+ if (shouldListen === this.isListeningToScroll) return;
332
+ if (shouldListen) {
333
+ this.lastScrollY = this.getScrollY();
334
+ this.lastScrollTime = performance.now();
335
+ window.addEventListener("scroll", this.handleScroll, { passive: true });
336
+ } else window.removeEventListener("scroll", this.handleScroll);
337
+ this.isListeningToScroll = shouldListen;
338
+ }
339
+ scheduleRebuild = () => {
340
+ if (!this.mounted) return;
341
+ this.cancelScheduledRebuild();
342
+ this.rebuildFrameId = requestAnimationFrame(() => {
343
+ this.rebuildFrameId = null;
344
+ this.rebuild();
345
+ });
346
+ };
347
+ cancelScheduledRebuild() {
348
+ if (this.rebuildFrameId === null) return;
349
+ cancelAnimationFrame(this.rebuildFrameId);
350
+ this.rebuildFrameId = null;
351
+ }
352
+ rebuild() {
353
+ if (!this.mounted) return;
354
+ this.options = this.resolveOptions();
355
+ this.updateScrollListener();
356
+ this.removeAttribute("data-marquee-content-ready");
357
+ this.setAttribute("data-marquee-content-mode", this.options.mode);
358
+ if (this.options.pauseOnHover) this.setAttribute("data-marquee-content-pause-on-hover", "true");
359
+ else this.removeAttribute("data-marquee-content-pause-on-hover");
360
+ const containerWidth = this.clientWidth;
361
+ if (containerWidth <= 0) {
362
+ this.distance = 0;
363
+ this.track.replaceChildren();
364
+ this.updateAnimationLoopState();
365
+ return;
366
+ }
367
+ this.sourceNodes = this.getSourceNodes();
368
+ if (this.sourceNodes.length === 0) {
369
+ this.distance = 0;
370
+ this.track.replaceChildren();
371
+ this.updateAnimationLoopState();
372
+ return;
373
+ }
374
+ const group = this.createGroup();
375
+ const targetWidth = containerWidth * this.options.minGroupWidthRatio;
376
+ this.track.replaceChildren(group);
377
+ this.expandGroupToWidth(group, targetWidth);
378
+ const clone = group.cloneNode(true);
379
+ clone.setAttribute("aria-hidden", "true");
380
+ this.track.appendChild(clone);
381
+ this.distance = group.scrollWidth;
382
+ this.offset = this.normalizeOffset(this.offset);
383
+ if (this.distance <= 0) {
384
+ this.track.replaceChildren();
385
+ this.updateAnimationLoopState();
386
+ return;
387
+ }
388
+ const currentSpeed = this.getCurrentSpeed(containerWidth);
389
+ const duration = this.distance / currentSpeed;
390
+ this.style.setProperty("--marquee-content-distance", `${this.distance}px`);
391
+ this.style.setProperty("--marquee-content-duration", `${duration}s`);
392
+ if (this.reducedMotion) this.track.style.transform = "none";
393
+ else if (this.options.mode === "scroll") this.applyTransform();
394
+ else this.track.style.transform = "";
395
+ this.setAttribute("data-marquee-content-ready", "true");
396
+ this.updateAnimationLoopState();
397
+ }
398
+ createGroup() {
399
+ const group = document.createElement("div");
400
+ group.className = "marquee-content__group";
401
+ group.setAttribute("part", "group");
402
+ this.appendSourceNodes(group);
403
+ return group;
404
+ }
405
+ expandGroupToWidth(group, targetWidth) {
406
+ const sourceSetWidth = group.scrollWidth;
407
+ if (sourceSetWidth <= 0) return;
408
+ const repeatCount = Math.ceil(targetWidth / sourceSetWidth);
409
+ for (let index = 1; index < repeatCount; index += 1) this.appendSourceNodes(group);
410
+ }
411
+ appendSourceNodes(target) {
412
+ const fragment = document.createDocumentFragment();
413
+ this.sourceNodes.forEach((node) => {
414
+ fragment.append(this.cloneSourceNode(node));
415
+ });
416
+ target.appendChild(fragment);
417
+ }
418
+ cloneSourceNode(node) {
419
+ const clone = node.cloneNode(true);
420
+ if (clone instanceof Element) {
421
+ const currentPart = clone.getAttribute("part");
422
+ clone.setAttribute("part", currentPart ? `${currentPart} item` : "item");
423
+ }
424
+ return clone;
425
+ }
426
+ getSourceNodes() {
427
+ return this.sourceSlot.assignedNodes({ flatten: true }).filter((node) => {
428
+ if (node.nodeType === Node.TEXT_NODE) return Boolean(node.textContent?.trim());
429
+ return node.nodeType === Node.ELEMENT_NODE;
430
+ });
431
+ }
432
+ watchSourceNodes() {
433
+ this.mutationObserver?.disconnect();
434
+ this.mutationObserver = new MutationObserver(this.scheduleRebuild);
435
+ this.getSourceNodes().forEach((node) => {
436
+ if (node.nodeType === Node.ELEMENT_NODE) {
437
+ this.mutationObserver?.observe(node, {
438
+ attributes: true,
439
+ childList: true,
440
+ characterData: true,
441
+ subtree: true
442
+ });
443
+ return;
444
+ }
445
+ if (node.nodeType === Node.TEXT_NODE) this.mutationObserver?.observe(node, { characterData: true });
446
+ });
447
+ }
448
+ setupReducedMotionWatcher() {
449
+ if (!("matchMedia" in window)) return;
450
+ this.reducedMotionMediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
451
+ this.reducedMotion = this.reducedMotionMediaQuery.matches;
452
+ this.reducedMotionMediaQuery.addEventListener("change", this.handleReducedMotionChange, { signal: this.abortController?.signal });
453
+ }
454
+ removeReducedMotionWatcher() {
455
+ if (!this.reducedMotionMediaQuery) return;
456
+ this.reducedMotionMediaQuery.removeEventListener("change", this.handleReducedMotionChange);
457
+ this.reducedMotionMediaQuery = null;
458
+ }
459
+ updateAnimationLoopState() {
460
+ if (!this.mounted || this.distance <= 0 || this.reducedMotion) {
461
+ this.stopAnimationLoop();
462
+ this.stopCssAnimation();
463
+ if (this.reducedMotion) this.track.style.transform = "none";
464
+ return;
465
+ }
466
+ if (this.options.mode === "scroll") {
467
+ this.stopCssAnimation();
468
+ if (this.canAnimate()) this.startAnimationLoop();
469
+ else this.stopAnimationLoop();
470
+ return;
471
+ }
472
+ this.stopAnimationLoop();
473
+ this.startCssAnimation();
474
+ this.track.style.animationPlayState = this.canAnimate() ? "running" : "paused";
475
+ }
476
+ canAnimate() {
477
+ if (this.options.pauseOnHover && this.isHovered) return false;
478
+ if (this.isFocused) return false;
479
+ if (this.options.pauseWhenOutOfView && !this.isInViewport) return false;
480
+ return true;
481
+ }
482
+ startAnimationLoop() {
483
+ if (this.animationFrameId !== null) return;
484
+ this.lastFrameTime = performance.now();
485
+ this.animationFrameId = requestAnimationFrame(this.tick);
486
+ }
487
+ stopAnimationLoop() {
488
+ if (this.animationFrameId === null) {
489
+ this.lastFrameTime = null;
490
+ return;
491
+ }
492
+ cancelAnimationFrame(this.animationFrameId);
493
+ this.animationFrameId = null;
494
+ this.lastFrameTime = null;
495
+ }
496
+ startCssAnimation() {
497
+ const animationDirection = this.options.direction === "ltr" ? "reverse" : "normal";
498
+ this.track.style.transform = "";
499
+ if (this.track.style.animationName !== "marquee-content-auto") {
500
+ this.track.style.animationName = "marquee-content-auto";
501
+ this.track.style.animationDuration = "var(--marquee-content-duration)";
502
+ this.track.style.animationTimingFunction = "linear";
503
+ this.track.style.animationIterationCount = "infinite";
504
+ }
505
+ if (this.track.style.animationDirection !== animationDirection) this.track.style.animationDirection = animationDirection;
506
+ }
507
+ stopCssAnimation() {
508
+ this.track.style.animationName = "";
509
+ this.track.style.animationDuration = "";
510
+ this.track.style.animationTimingFunction = "";
511
+ this.track.style.animationIterationCount = "";
512
+ this.track.style.animationDirection = "";
513
+ this.track.style.animationPlayState = "";
514
+ }
515
+ tick = (now) => {
516
+ this.animationFrameId = null;
517
+ if (!this.mounted || this.options.mode !== "scroll" || this.distance <= 0 || this.reducedMotion || !this.canAnimate()) {
518
+ this.stopAnimationLoop();
519
+ return;
520
+ }
521
+ const previousTime = this.lastFrameTime ?? now;
522
+ const deltaTime = Math.min((now - previousTime) / 1e3, .064);
523
+ this.lastFrameTime = now;
524
+ const currentSpeed = this.getCurrentSpeed(this.clientWidth);
525
+ const timeScale = this.getCurrentTimeScale(now);
526
+ this.offset = this.normalizeOffset(this.offset + currentSpeed * timeScale * deltaTime);
527
+ this.applyTransform();
528
+ this.animationFrameId = requestAnimationFrame(this.tick);
529
+ };
530
+ getCurrentTimeScale(now) {
531
+ const directionFactor = this.getDirectionFactor();
532
+ if (this.options.mode !== "scroll") return directionFactor;
533
+ const boost = this.getScrollBoost(now);
534
+ const scrollTimeScale = this.scrollDirectionFactor + boost;
535
+ return this.clamp(directionFactor * scrollTimeScale, -1 - this.options.scrollMaxExtraSpeed, 1 + this.options.scrollMaxExtraSpeed);
536
+ }
537
+ getDirectionFactor() {
538
+ return this.options.direction === "ltr" ? -1 : 1;
539
+ }
540
+ getScrollBoost(now) {
541
+ if (this.scrollBoostStartValue === 0) return 0;
542
+ const duration = this.options.scrollInertiaDuration;
543
+ if (duration <= 0) {
544
+ this.scrollBoostStartValue = 0;
545
+ return 0;
546
+ }
547
+ const progress = this.clamp((now - this.scrollBoostStartedAt) / duration, 0, 1);
548
+ if (progress >= 1) {
549
+ this.scrollBoostStartValue = 0;
550
+ return 0;
551
+ }
552
+ const easedProgress = this.easeOutCubic(progress);
553
+ return this.scrollBoostStartValue * (1 - easedProgress);
554
+ }
555
+ applyTransform() {
556
+ this.track.style.transform = `translate3d(${-this.offset}px, 0, 0)`;
557
+ }
558
+ normalizeOffset(value) {
559
+ if (this.distance <= 0) return 0;
560
+ const normalized = value % this.distance;
561
+ return normalized < 0 ? normalized + this.distance : normalized;
562
+ }
563
+ getCurrentSpeed(containerWidth) {
564
+ if (!this.options.responsiveSpeed) return this.options.speed;
565
+ const factor = this.clamp(containerWidth / this.options.referenceWidth, this.options.minSpeedFactor, this.options.maxSpeedFactor);
566
+ return this.options.speed * factor;
567
+ }
568
+ resolveOptions() {
569
+ return {
570
+ ...DEFAULT_OPTIONS,
571
+ speed: this.num("speed", DEFAULT_OPTIONS.speed, 10, 500),
572
+ mode: this.parseMode(this.getAttribute("mode"), DEFAULT_OPTIONS.mode),
573
+ direction: this.parseDirection(this.getAttribute("direction"), DEFAULT_OPTIONS.direction),
574
+ pauseOnHover: this.parseBoolean(this.getAttribute("pause-on-hover"), DEFAULT_OPTIONS.pauseOnHover)
575
+ };
576
+ }
577
+ num(attributeName, fallback, min, max) {
578
+ return this.clamp(this.parseNumber(this.getAttribute(attributeName), fallback), min, max);
579
+ }
580
+ parseNumber(value, fallback) {
581
+ if (value === null || value.trim() === "") return fallback;
582
+ const parsed = Number(value);
583
+ return Number.isFinite(parsed) ? parsed : fallback;
584
+ }
585
+ parseBoolean(value, fallback) {
586
+ if (value === null) return fallback;
587
+ const normalizedValue = value.trim().toLowerCase();
588
+ if (normalizedValue === "") return true;
589
+ if ([
590
+ "true",
591
+ "1",
592
+ "yes",
593
+ "on"
594
+ ].includes(normalizedValue)) return true;
595
+ if ([
596
+ "false",
597
+ "0",
598
+ "no",
599
+ "off"
600
+ ].includes(normalizedValue)) return false;
601
+ return fallback;
602
+ }
603
+ parseMode(value, fallback) {
604
+ if (value === "auto" || value === "scroll") return value;
605
+ return fallback;
606
+ }
607
+ parseDirection(value, fallback) {
608
+ if (value === "rtl" || value === "ltr") return value;
609
+ return fallback;
610
+ }
611
+ setNullableAttribute(name, value) {
612
+ if (value === null || value === void 0) {
613
+ this.removeAttribute(name);
614
+ return;
615
+ }
616
+ this.setAttribute(name, String(value));
617
+ }
618
+ getScrollY() {
619
+ return window.scrollY || window.pageYOffset || 0;
620
+ }
621
+ clamp(value, min, max) {
622
+ return Math.min(Math.max(value, min), max);
623
+ }
624
+ easeOutCubic(value) {
625
+ return 1 - (1 - value) ** 3;
626
+ }
627
+ rebuildAfterFontsReady() {
628
+ const fonts = document.fonts;
629
+ if (!fonts?.ready) return;
630
+ fonts.ready.then(this.scheduleRebuild).catch(() => void 0);
631
+ }
632
+ };
633
+ function defineMarqueeContent(tagName = MARQUEE_CONTENT_TAG, options = {}) {
634
+ if (typeof window === "undefined" || !window.customElements) return;
635
+ MarqueeContent.configureStyles(options);
636
+ if (!window.customElements.get(tagName)) window.customElements.define(tagName, MarqueeContent);
637
+ }
638
+ function initMarqueeContents(options = {}) {
639
+ const { tagName = MARQUEE_CONTENT_TAG, ...styleOptions } = options;
640
+ defineMarqueeContent(tagName, styleOptions);
641
+ }
642
+
643
+ //#endregion
644
+ //#region src/index.ts
645
+ defineMarqueeContent();
646
+
647
+ //#endregion
648
+ exports.MARQUEE_CONTENT_TAG = MARQUEE_CONTENT_TAG;
649
+ exports.MarqueeContent = MarqueeContent;
650
+ exports.createConstructableStyleSheet = createConstructableStyleSheet;
651
+ exports.cssStyleSheetToText = cssStyleSheetToText;
652
+ exports.defineMarqueeContent = defineMarqueeContent;
653
+ exports.initMarqueeContents = initMarqueeContents;
654
+ exports.marqueeContentCssText = marqueeContentCssText;
655
+ exports.normalizeStyleInput = normalizeStyleInput;
656
+ //# sourceMappingURL=index.cjs.map