marquee-content 4.6.1 → 5.0.0-dev.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/LICENSE +2 -2
- package/README.md +103 -43
- package/dist/index.cjs +71 -0
- package/dist/index.d.ts +4 -28
- package/dist/index.es.js +547 -98
- package/dist/index.umd.js +71 -1
- package/dist/marquee-content.css +1 -0
- package/dist/marquee-content.d.ts +163 -0
- package/dist/styles.d.ts +10 -0
- package/package.json +36 -55
- package/dist/index.cjs.js +0 -1
package/dist/index.umd.js
CHANGED
|
@@ -1 +1,71 @@
|
|
|
1
|
-
(function(
|
|
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;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.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`,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});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:host{--marquee-content-gap:2rem;--marquee-content-distance:0px;--marquee-content-duration:20s;width:100%;color:inherit;font:inherit;pointer-events:none;display:block;overflow:hidden}:host([pause-on-hover]:not([pause-on-hover=false])){pointer-events:auto}:host([hidden]),.marquee-content__source{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}@media (prefers-reduced-motion:reduce){.marquee-content__track{transform:none!important}}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { MarqueeContentStyleInput } from './styles';
|
|
2
|
+
export type MarqueeContentDirection = 'rtl' | 'ltr' | 'scroll';
|
|
3
|
+
export interface MarqueeContentOptions {
|
|
4
|
+
speed?: number | string | null;
|
|
5
|
+
direction?: MarqueeContentDirection | null;
|
|
6
|
+
minGroupWidthRatio?: number | string | null;
|
|
7
|
+
responsiveSpeed?: boolean | string | null;
|
|
8
|
+
referenceWidth?: number | string | null;
|
|
9
|
+
minSpeedFactor?: number | string | null;
|
|
10
|
+
maxSpeedFactor?: number | string | null;
|
|
11
|
+
pauseOnHover?: boolean | string | null;
|
|
12
|
+
pauseWhenOutOfView?: boolean | string | null;
|
|
13
|
+
recalculateAfterFontsReady?: boolean | string | null;
|
|
14
|
+
scrollVelocityFactor?: number | string | null;
|
|
15
|
+
scrollMinExtraSpeed?: number | string | null;
|
|
16
|
+
scrollMaxExtraSpeed?: number | string | null;
|
|
17
|
+
scrollInertiaDuration?: number | string | null;
|
|
18
|
+
debug?: boolean | string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface MarqueeContentResolvedOptions {
|
|
21
|
+
speed: number;
|
|
22
|
+
direction: MarqueeContentDirection;
|
|
23
|
+
minGroupWidthRatio: number;
|
|
24
|
+
responsiveSpeed: boolean;
|
|
25
|
+
referenceWidth: number;
|
|
26
|
+
minSpeedFactor: number;
|
|
27
|
+
maxSpeedFactor: number;
|
|
28
|
+
pauseOnHover: boolean;
|
|
29
|
+
pauseWhenOutOfView: boolean;
|
|
30
|
+
recalculateAfterFontsReady: boolean;
|
|
31
|
+
scrollVelocityFactor: number;
|
|
32
|
+
scrollMinExtraSpeed: number;
|
|
33
|
+
scrollMaxExtraSpeed: number;
|
|
34
|
+
scrollInertiaDuration: number;
|
|
35
|
+
debug: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface DefineMarqueeContentOptions {
|
|
38
|
+
stylesheet?: MarqueeContentStyleInput;
|
|
39
|
+
styleOverrides?: MarqueeContentStyleInput;
|
|
40
|
+
}
|
|
41
|
+
export interface InitMarqueeContentsOptions extends DefineMarqueeContentOptions {
|
|
42
|
+
tagName?: string;
|
|
43
|
+
}
|
|
44
|
+
export declare const MARQUEE_CONTENT_TAG = "marquee-content";
|
|
45
|
+
export declare class MarqueeContent extends HTMLElement {
|
|
46
|
+
static get observedAttributes(): string[];
|
|
47
|
+
private static readonly instances;
|
|
48
|
+
private static stylesheetEntry;
|
|
49
|
+
private static styleOverridesEntry;
|
|
50
|
+
static configureStyles(options?: DefineMarqueeContentOptions): void;
|
|
51
|
+
static setStylesheet(stylesheet: MarqueeContentStyleInput): void;
|
|
52
|
+
static setStyleOverrides(styleOverrides: MarqueeContentStyleInput): void;
|
|
53
|
+
private readonly shadow;
|
|
54
|
+
private readonly sourceSlot;
|
|
55
|
+
private readonly track;
|
|
56
|
+
private options;
|
|
57
|
+
private sourceNodes;
|
|
58
|
+
private resizeObserver;
|
|
59
|
+
private mutationObserver;
|
|
60
|
+
private intersectionObserver;
|
|
61
|
+
private abortController;
|
|
62
|
+
private reducedMotionMediaQuery;
|
|
63
|
+
private animationFrameId;
|
|
64
|
+
private rebuildFrameId;
|
|
65
|
+
private lastFrameTime;
|
|
66
|
+
private mounted;
|
|
67
|
+
private isHovered;
|
|
68
|
+
private isInViewport;
|
|
69
|
+
private reducedMotion;
|
|
70
|
+
private distance;
|
|
71
|
+
private offset;
|
|
72
|
+
private scrollDirectionFactor;
|
|
73
|
+
private scrollBoostStartValue;
|
|
74
|
+
private scrollBoostStartedAt;
|
|
75
|
+
private lastScrollY;
|
|
76
|
+
private lastScrollTime;
|
|
77
|
+
constructor();
|
|
78
|
+
connectedCallback(): void;
|
|
79
|
+
disconnectedCallback(): void;
|
|
80
|
+
attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
|
|
81
|
+
get speed(): number;
|
|
82
|
+
set speed(value: number | string | null | undefined);
|
|
83
|
+
get direction(): MarqueeContentDirection;
|
|
84
|
+
set direction(value: MarqueeContentDirection | null | undefined);
|
|
85
|
+
get minGroupWidthRatio(): number;
|
|
86
|
+
set minGroupWidthRatio(value: number | string | null | undefined);
|
|
87
|
+
get responsiveSpeed(): boolean;
|
|
88
|
+
set responsiveSpeed(value: boolean | string | null | undefined);
|
|
89
|
+
get referenceWidth(): number;
|
|
90
|
+
set referenceWidth(value: number | string | null | undefined);
|
|
91
|
+
get minSpeedFactor(): number;
|
|
92
|
+
set minSpeedFactor(value: number | string | null | undefined);
|
|
93
|
+
get maxSpeedFactor(): number;
|
|
94
|
+
set maxSpeedFactor(value: number | string | null | undefined);
|
|
95
|
+
get pauseOnHover(): boolean;
|
|
96
|
+
set pauseOnHover(value: boolean | string | null | undefined);
|
|
97
|
+
get pauseWhenOutOfView(): boolean;
|
|
98
|
+
set pauseWhenOutOfView(value: boolean | string | null | undefined);
|
|
99
|
+
get recalculateAfterFontsReady(): boolean;
|
|
100
|
+
set recalculateAfterFontsReady(value: boolean | string | null | undefined);
|
|
101
|
+
get scrollVelocityFactor(): number;
|
|
102
|
+
set scrollVelocityFactor(value: number | string | null | undefined);
|
|
103
|
+
get scrollMinExtraSpeed(): number;
|
|
104
|
+
set scrollMinExtraSpeed(value: number | string | null | undefined);
|
|
105
|
+
get scrollMaxExtraSpeed(): number;
|
|
106
|
+
set scrollMaxExtraSpeed(value: number | string | null | undefined);
|
|
107
|
+
get scrollInertiaDuration(): number;
|
|
108
|
+
set scrollInertiaDuration(value: number | string | null | undefined);
|
|
109
|
+
get debug(): boolean;
|
|
110
|
+
set debug(value: boolean | string | null | undefined);
|
|
111
|
+
update(options?: MarqueeContentOptions): void;
|
|
112
|
+
refresh(): void;
|
|
113
|
+
adoptStyles(stylesheet: MarqueeContentStyleInput): void;
|
|
114
|
+
adoptStyleOverrides(styleOverrides: MarqueeContentStyleInput): void;
|
|
115
|
+
private applyAllStyles;
|
|
116
|
+
private applyFallbackStyleElement;
|
|
117
|
+
private removeFallbackStyleElements;
|
|
118
|
+
private teardown;
|
|
119
|
+
private handleSlotChange;
|
|
120
|
+
private handlePointerEnter;
|
|
121
|
+
private handlePointerLeave;
|
|
122
|
+
private handleIntersectionChange;
|
|
123
|
+
private handleReducedMotionChange;
|
|
124
|
+
private handleScroll;
|
|
125
|
+
private scheduleRebuild;
|
|
126
|
+
private cancelScheduledRebuild;
|
|
127
|
+
private rebuild;
|
|
128
|
+
private createGroup;
|
|
129
|
+
private expandGroupToWidth;
|
|
130
|
+
private appendSourceNodes;
|
|
131
|
+
private cloneSourceNode;
|
|
132
|
+
private getSourceNodes;
|
|
133
|
+
private watchSourceNodes;
|
|
134
|
+
private setupReducedMotionWatcher;
|
|
135
|
+
private removeReducedMotionWatcher;
|
|
136
|
+
private updateAnimationLoopState;
|
|
137
|
+
private canAnimate;
|
|
138
|
+
private startAnimationLoop;
|
|
139
|
+
private stopAnimationLoop;
|
|
140
|
+
private tick;
|
|
141
|
+
private getCurrentTimeScale;
|
|
142
|
+
private getScrollBoost;
|
|
143
|
+
private applyTransform;
|
|
144
|
+
private normalizeOffset;
|
|
145
|
+
private getCurrentSpeed;
|
|
146
|
+
private resolveOptions;
|
|
147
|
+
private num;
|
|
148
|
+
private parseNumber;
|
|
149
|
+
private parseBoolean;
|
|
150
|
+
private parseDirection;
|
|
151
|
+
private setNullableAttribute;
|
|
152
|
+
private getScrollY;
|
|
153
|
+
private clamp;
|
|
154
|
+
private easeOutCubic;
|
|
155
|
+
private rebuildAfterFontsReady;
|
|
156
|
+
}
|
|
157
|
+
export declare function defineMarqueeContent(tagName?: string, options?: DefineMarqueeContentOptions): void;
|
|
158
|
+
export declare function initMarqueeContents(options?: InitMarqueeContentsOptions): void;
|
|
159
|
+
declare global {
|
|
160
|
+
interface HTMLElementTagNameMap {
|
|
161
|
+
'marquee-content': MarqueeContent;
|
|
162
|
+
}
|
|
163
|
+
}
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type MarqueeContentStyleInput = CSSStyleSheet | string | null | undefined;
|
|
2
|
+
export interface MarqueeContentStyleEntry {
|
|
3
|
+
sheet: CSSStyleSheet | null;
|
|
4
|
+
cssText: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const marqueeContentCssText: string;
|
|
7
|
+
export declare function createConstructableStyleSheet(cssText: string): CSSStyleSheet | null;
|
|
8
|
+
export declare function cssStyleSheetToText(sheet: CSSStyleSheet): string;
|
|
9
|
+
export declare function normalizeStyleInput(input: MarqueeContentStyleInput): MarqueeContentStyleEntry;
|
|
10
|
+
export declare function canUseAdoptedStyleSheets(root: ShadowRoot): boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marquee-content",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "5.0.0-dev.1",
|
|
4
|
+
"description": "A lightweight marquee Web Component with Shadow DOM style overrides support",
|
|
5
5
|
"author": "ux-ui.pro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -13,77 +13,58 @@
|
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/ux-ui-pro/marquee-content",
|
|
15
15
|
"sideEffects": false,
|
|
16
|
+
"type": "module",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18.0.0"
|
|
19
|
+
},
|
|
16
20
|
"scripts": {
|
|
17
21
|
"clean": "rimraf dist",
|
|
18
22
|
"build": "vite build",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"lint:fix": "
|
|
23
|
+
"dev": "vite",
|
|
24
|
+
"verify": "npm run build && npm run lint && npm run typecheck && npm run test:smoke",
|
|
25
|
+
"lint": "biome check src tests vite.config.ts",
|
|
26
|
+
"lint:fix": "biome check --write src tests vite.config.ts",
|
|
27
|
+
"format": "biome format --write src tests vite.config.ts",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
29
|
+
"test:smoke": "node --test tests/*.js",
|
|
30
|
+
"prepublishOnly": "npm run clean && npm run build && npm run verify"
|
|
23
31
|
},
|
|
24
32
|
"source": "src/index.ts",
|
|
25
|
-
"main": "dist/index.cjs
|
|
33
|
+
"main": "dist/index.cjs",
|
|
26
34
|
"module": "dist/index.es.js",
|
|
27
|
-
"browser": "./dist/index.umd.js",
|
|
28
35
|
"types": "dist/index.d.ts",
|
|
29
36
|
"exports": {
|
|
30
37
|
".": {
|
|
31
|
-
"
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
32
39
|
"import": "./dist/index.es.js",
|
|
33
|
-
"
|
|
40
|
+
"require": "./dist/index.cjs"
|
|
34
41
|
},
|
|
42
|
+
"./marquee-content.css": "./dist/marquee-content.css",
|
|
35
43
|
"./dist/*": "./dist/*"
|
|
36
44
|
},
|
|
37
45
|
"files": [
|
|
38
46
|
"dist/"
|
|
39
47
|
],
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@eslint/js": "9.22.0",
|
|
42
|
-
"@rollup/plugin-terser": "0.4.4",
|
|
43
|
-
"@types/node": "22.13.10",
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "8.26.0",
|
|
45
|
-
"@typescript-eslint/parser": "8.26.0",
|
|
46
|
-
"eslint": "9.22.0",
|
|
47
|
-
"eslint-config-prettier": "10.1.1",
|
|
48
|
-
"eslint-import-resolver-typescript": "3.8.3",
|
|
49
|
-
"eslint-plugin-import": "2.31.0",
|
|
50
|
-
"globals": "16.0.0",
|
|
51
|
-
"prettier": "3.5.3",
|
|
52
|
-
"rimraf": "6.0.1",
|
|
53
|
-
"typescript": "5.8.2",
|
|
54
|
-
"vite": "6.2.1",
|
|
55
|
-
"vite-plugin-dts": "4.5.3",
|
|
56
|
-
"gsap": "3.12.7"
|
|
57
|
-
},
|
|
58
48
|
"keywords": [
|
|
49
|
+
"typescript",
|
|
50
|
+
"web component",
|
|
51
|
+
"web-component",
|
|
52
|
+
"custom elements",
|
|
53
|
+
"custom-elements",
|
|
59
54
|
"marquee",
|
|
60
|
-
"scroller",
|
|
61
|
-
"animation",
|
|
62
55
|
"ticker",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"scrolling text",
|
|
56
|
+
"shadow dom",
|
|
57
|
+
"shadow-dom",
|
|
66
58
|
"ui",
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
"clone",
|
|
79
|
-
"skew",
|
|
80
|
-
"responsive",
|
|
81
|
-
"media queries",
|
|
82
|
-
"javascript",
|
|
83
|
-
"frontend",
|
|
84
|
-
"UX",
|
|
85
|
-
"performance",
|
|
86
|
-
"HTML",
|
|
87
|
-
"CSS"
|
|
88
|
-
]
|
|
59
|
+
"component"
|
|
60
|
+
],
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@biomejs/biome": "2.4.14",
|
|
63
|
+
"@types/node": "25.6.0",
|
|
64
|
+
"lightningcss": "1.32.0",
|
|
65
|
+
"rimraf": "6.1.3",
|
|
66
|
+
"typescript": "6.0.3",
|
|
67
|
+
"vite": "8.0.10",
|
|
68
|
+
"vite-plugin-dts": "5.0.0"
|
|
69
|
+
}
|
|
89
70
|
}
|
package/dist/index.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var h=Object.defineProperty;var d=(r,e,t)=>e in r?h(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>d(r,typeof e!="symbol"?e+"":e,t);const p=require("gsap"),u=require("gsap/ScrollTrigger"),i=class i{constructor({element:e=".marquee"}={}){n(this,"gsapInstance",i._gsap);n(this,"timeline");n(this,"matchMedia");n(this,"element");n(this,"resizeObserver");n(this,"animationFrame");const t=e instanceof HTMLElement?e:document.querySelector(e);if(!t)throw new Error("Target element not found");this.element=t,this.gsapInstance=i._gsap,this.matchMedia=this.gsapInstance.matchMedia(),this.resizeObserver=new ResizeObserver(i.debounce(()=>{this.update()})),this.resizeObserver.observe(this.element)}static registerGSAP(e,t){i._gsap=e,i._ScrollTrigger=t}static debounce(e){let t=null;return(...s)=>{t!==null&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>e(...s))}}init(){this.setup()}destroy(){this.animationFrame!==void 0&&(cancelAnimationFrame(this.animationFrame),this.animationFrame=void 0),this.resizeObserver.disconnect(),this.clearTimeline()}setup(){this.clearTimeline(),this.cloneElements(),this.setBreakpoints(),this.applySkew(),this.timeline=this.createAnimation()}update(){this.animationFrame!==void 0&&cancelAnimationFrame(this.animationFrame),this.animationFrame=requestAnimationFrame(()=>{var e,t;this.setup(),(t=(e=i._ScrollTrigger).refresh)==null||t.call(e)})}createAnimation(){var s;(s=this.timeline)==null||s.kill();const e=this.gsapInstance.timeline({scrollTrigger:{trigger:this.element,start:"top bottom",end:"bottom top",toggleActions:"resume pause resume pause",onUpdate:a=>{const{mcDirection:l}=this.element.dataset;l==="ltr"?e.timeScale(-1):l==="auto"&&e.timeScale(a.direction)}}}),t=this.element.dataset.mcBreakpoint||"";return this.matchMedia.add(t,()=>{const a=parseFloat(this.element.dataset.mcSpeed??"20");return e.to(this.element.children,{duration:a,x:"-100%",repeat:-1,ease:"none"}),e.totalProgress(.5),()=>{e.kill()}}),e}clearTimeline(){var e;(e=this.timeline)==null||e.kill(),this.timeline=void 0,this.gsapInstance.set(this.element.children,{clearProps:"all"})}setBreakpoints(){const{mcMax:e,mcMin:t}=this.element.dataset;this.element.dataset.mcBreakpoint=e?`(max-width: ${parseFloat(e)-.02}px)`:t?`(min-width: ${t}px)`:""}cloneElements(){const e=()=>{for(;this.element.childElementCount>1;)this.element.removeChild(this.element.lastChild)};e();const t=this.element.dataset.mcBreakpoint||"";this.matchMedia.add(t,()=>{const s=this.element.firstElementChild;if(!s)return()=>{};const a=Math.ceil(this.element.scrollWidth/s.clientWidth+2);if(this.element.childElementCount<a){const l=document.createDocumentFragment();for(let o=0;o<a-1;o++){const c=s.cloneNode(!0);l.appendChild(c)}this.element.appendChild(l)}return()=>{e()}})}applySkew(){const{mcSkew:e}=this.element.dataset;e&&(this.element.style.transformOrigin="center center",this.element.style.transform=`skew(0deg, ${e}deg)`)}};n(i,"_gsap",p.gsap),n(i,"_ScrollTrigger",u.ScrollTrigger);let m=i;module.exports=m;
|