remarqueeble 0.2.0 → 0.3.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.
@@ -1,4 +1,4 @@
1
- /*! remarqueeble v0.2.0 | (c) 2026 Rémino Rem <https://remino.net/> | ISC Licence */
1
+ /*! remarqueeble v0.3.0 | (c) 2026 Rémino Rem <https://remino.net/> | ISC Licence */
2
2
  //#region src/lib/remarqueeble.ts
3
3
  var DEFAULT_DIRECTION = "left";
4
4
  var DEFAULT_BEHAVIOR = "scroll";
@@ -23,6 +23,15 @@ var CSS_VAR_HEIGHT = "--attr-height";
23
23
  var CSS_VAR_HSPACE = "--attr-hspace";
24
24
  var CSS_VAR_VSPACE = "--attr-vspace";
25
25
  var CSS_VAR_BG_COLOR = "--attr-bgcolor";
26
+ var CSS_VAR_ANIMATION_DURATION = "--animation-duration";
27
+ var CSS_VAR_ANIMATION_DIRECTION = "--animation-direction";
28
+ var CSS_VAR_ANIMATION_ITERATION_COUNT = "--animation-iteration-count";
29
+ var CSS_VAR_ANIMATION_PLAY_STATE = "--animation-play-state";
30
+ var CSS_VAR_ANIMATION_TIMING_FUNCTION = "--animation-timing-function";
31
+ var CSS_VAR_TRANSLATE_X_END = "--translate-x-end";
32
+ var CSS_VAR_TRANSLATE_X_START = "--translate-x-start";
33
+ var CSS_VAR_TRANSLATE_Y_END = "--translate-y-end";
34
+ var CSS_VAR_TRANSLATE_Y_START = "--translate-y-start";
26
35
  var HTMLElementBase = globalThis.HTMLElement ?? class {};
27
36
  var parsePresentationalDimension = (value) => {
28
37
  if (value === null) return null;
@@ -83,11 +92,6 @@ var RemarqueebleElement = class extends HTMLElementBase {
83
92
  ];
84
93
  track;
85
94
  running = false;
86
- position = 0;
87
- lastTime = null;
88
- loopsDone = 0;
89
- forward = true;
90
- rafId = null;
91
95
  constructor() {
92
96
  super();
93
97
  const shadowRoot = this.attachShadow({ mode: "open" });
@@ -112,9 +116,32 @@ var RemarqueebleElement = class extends HTMLElementBase {
112
116
  }
113
117
 
114
118
  .track {
119
+ animation: remarqueeble-motion
120
+ var(${CSS_VAR_ANIMATION_DURATION}, 10s)
121
+ var(${CSS_VAR_ANIMATION_TIMING_FUNCTION}, linear)
122
+ var(${CSS_VAR_ANIMATION_ITERATION_COUNT}, infinite)
123
+ var(${CSS_VAR_ANIMATION_DIRECTION}, normal)
124
+ both;
125
+ animation-play-state: var(${CSS_VAR_ANIMATION_PLAY_STATE}, running);
115
126
  display: inline-block;
116
127
  will-change: transform;
117
128
  }
129
+
130
+ @keyframes remarqueeble-motion {
131
+ from {
132
+ transform: translate(
133
+ var(${CSS_VAR_TRANSLATE_X_START}, 100%),
134
+ var(${CSS_VAR_TRANSLATE_Y_START}, 0px)
135
+ );
136
+ }
137
+
138
+ to {
139
+ transform: translate(
140
+ var(${CSS_VAR_TRANSLATE_X_END}, -100%),
141
+ var(${CSS_VAR_TRANSLATE_Y_END}, 0px)
142
+ );
143
+ }
144
+ }
118
145
  </style>
119
146
 
120
147
  <span class="track"><slot></slot></span>
@@ -122,6 +149,7 @@ var RemarqueebleElement = class extends HTMLElementBase {
122
149
  const track = shadowRoot.querySelector(".track");
123
150
  if (!track) throw new Error("Remarqueeble track element was not created.");
124
151
  this.track = track;
152
+ this.track.addEventListener("animationend", () => this.handleAnimationEnd());
125
153
  }
126
154
  connectedCallback() {
127
155
  this.running = true;
@@ -129,16 +157,10 @@ var RemarqueebleElement = class extends HTMLElementBase {
129
157
  requestAnimationFrame(() => {
130
158
  if (!this.isConnected || !this.running) return;
131
159
  this.reset();
132
- this.tick();
133
160
  });
134
161
  }
135
162
  disconnectedCallback() {
136
163
  this.running = false;
137
- this.lastTime = null;
138
- if (this.rafId !== null) {
139
- cancelAnimationFrame(this.rafId);
140
- this.rafId = null;
141
- }
142
164
  }
143
165
  attributeChangedCallback(_name, oldValue, newValue) {
144
166
  if (oldValue === newValue) return;
@@ -176,18 +198,16 @@ var RemarqueebleElement = class extends HTMLElementBase {
176
198
  start() {
177
199
  if (this.running) return;
178
200
  this.running = true;
179
- this.lastTime = null;
180
- this.tick();
201
+ this.reset();
202
+ this.syncAnimationPlayState();
181
203
  }
182
204
  stop() {
183
205
  this.running = false;
184
- if (this.rafId !== null) {
185
- cancelAnimationFrame(this.rafId);
186
- this.rafId = null;
187
- }
206
+ this.syncAnimationPlayState();
188
207
  }
189
208
  syncPresentationalHints() {
190
209
  for (const hint of ATTRIBUTE_HINTS) this.syncVar(hint);
210
+ this.syncAnimationPlayState();
191
211
  }
192
212
  syncVar(hint) {
193
213
  const raw = this.getAttribute(hint.attribute);
@@ -203,10 +223,7 @@ var RemarqueebleElement = class extends HTMLElementBase {
203
223
  reset() {
204
224
  const hostSize = this.getHostSize();
205
225
  const trackSize = this.getTrackSize();
206
- this.loopsDone = 0;
207
- this.forward = true;
208
- this.position = this.behavior === "alternate" ? this.getAlternateStartPosition(hostSize, trackSize) : this.getStartPosition(hostSize, trackSize);
209
- this.render();
226
+ this.syncAnimation(hostSize, trackSize);
210
227
  }
211
228
  getHostSize() {
212
229
  return this.isVerticalDirection ? this.clientHeight : this.clientWidth;
@@ -229,69 +246,53 @@ var RemarqueebleElement = class extends HTMLElementBase {
229
246
  getAlternateStartPosition(hostSize, trackSize) {
230
247
  return this.directionSign < 0 ? hostSize - trackSize : 0;
231
248
  }
232
- tick(time = performance.now()) {
233
- if (!this.running) return;
234
- if (this.lastTime === null) this.lastTime = time;
235
- if (time - this.lastTime >= this.scrollDelay) {
236
- this.step();
237
- this.lastTime = time;
238
- }
239
- if (!this.running) return;
240
- this.rafId = requestAnimationFrame((nextTime) => this.tick(nextTime));
249
+ syncAnimationPlayState() {
250
+ this.style.setProperty(CSS_VAR_ANIMATION_PLAY_STATE, this.running ? "running" : "paused");
241
251
  }
242
- step() {
243
- const hostSize = this.getHostSize();
244
- const trackSize = this.getTrackSize();
245
- const startPosition = this.getStartPosition(hostSize, trackSize);
246
- const flushEndPosition = this.getFlushEndPosition(hostSize, trackSize);
247
- const offEndPosition = this.getOffEndPosition(hostSize, trackSize);
248
- const slideEndPosition = this.getSlideEndPosition(hostSize, trackSize);
249
- const alternateStartPosition = this.getAlternateStartPosition(hostSize, trackSize);
250
- const amount = this.scrollAmount;
251
- const delta = this.directionSign * amount;
252
- if (this.behavior === "alternate") {
253
- this.position += this.forward ? delta : -delta;
254
- if (this.forward) {
255
- if (this.directionSign < 0 && this.position <= flushEndPosition || this.directionSign > 0 && this.position >= flushEndPosition) {
256
- this.position = flushEndPosition;
257
- this.forward = false;
258
- this.incrementLoopCount();
259
- if (this.shouldStopAfterLoop()) this.stop();
260
- }
261
- } else if (this.directionSign < 0 && this.position >= alternateStartPosition || this.directionSign > 0 && this.position <= alternateStartPosition) {
262
- this.position = alternateStartPosition;
263
- this.forward = true;
264
- this.incrementLoopCount();
265
- if (this.shouldStopAfterLoop()) this.stop();
266
- }
267
- } else if (this.behavior === "slide") {
268
- this.position += delta;
269
- if (this.directionSign < 0 && this.position <= slideEndPosition || this.directionSign > 0 && this.position >= slideEndPosition) {
270
- this.position = slideEndPosition;
271
- this.incrementLoopCount();
272
- if (!this.hasAttribute(ATTR_LOOP) || this.loop <= 0) this.stop();
273
- else if (this.shouldStopAfterLoop()) this.stop();
274
- else this.position = startPosition;
275
- }
252
+ syncAnimation(hostSize, trackSize) {
253
+ const startPosition = this.behavior === "alternate" ? this.getAlternateStartPosition(hostSize, trackSize) : this.getStartPosition(hostSize, trackSize);
254
+ const endPosition = this.behavior === "slide" ? this.getSlideEndPosition(hostSize, trackSize) : this.behavior === "alternate" ? this.getFlushEndPosition(hostSize, trackSize) : this.getOffEndPosition(hostSize, trackSize);
255
+ const distance = Math.abs(endPosition - startPosition);
256
+ const steps = Math.max(1, Math.ceil(distance / Math.max(1, this.scrollAmount)));
257
+ const duration = Math.max(1, steps * this.scrollDelay);
258
+ const iterationCount = this.getCssIterationCount();
259
+ this.track.style.removeProperty("transform");
260
+ this.style.setProperty(CSS_VAR_ANIMATION_DURATION, `${duration}ms`);
261
+ this.style.setProperty(CSS_VAR_ANIMATION_DIRECTION, this.behavior === "alternate" ? "alternate" : "normal");
262
+ this.style.setProperty(CSS_VAR_ANIMATION_ITERATION_COUNT, iterationCount);
263
+ this.style.setProperty(CSS_VAR_ANIMATION_TIMING_FUNCTION, `steps(${steps}, end)`);
264
+ if (this.isVerticalDirection) {
265
+ this.style.setProperty(CSS_VAR_TRANSLATE_X_START, "0px");
266
+ this.style.setProperty(CSS_VAR_TRANSLATE_X_END, "0px");
267
+ this.style.setProperty(CSS_VAR_TRANSLATE_Y_START, `${startPosition}px`);
268
+ this.style.setProperty(CSS_VAR_TRANSLATE_Y_END, `${endPosition}px`);
276
269
  } else {
277
- this.position += delta;
278
- if (this.directionSign < 0 && this.position <= offEndPosition || this.directionSign > 0 && this.position >= offEndPosition) {
279
- this.position = startPosition;
280
- this.incrementLoopCount();
281
- if (this.shouldStopAfterLoop()) this.stop();
282
- }
270
+ this.style.setProperty(CSS_VAR_TRANSLATE_X_START, `${startPosition}px`);
271
+ this.style.setProperty(CSS_VAR_TRANSLATE_X_END, `${endPosition}px`);
272
+ this.style.setProperty(CSS_VAR_TRANSLATE_Y_START, "0px");
273
+ this.style.setProperty(CSS_VAR_TRANSLATE_Y_END, "0px");
283
274
  }
284
- this.render();
275
+ this.restartAnimation();
285
276
  }
286
- incrementLoopCount() {
287
- this.loopsDone++;
277
+ getCssIterationCount() {
278
+ if (this.behavior === "slide" && !this.hasAttribute(ATTR_LOOP)) return "1";
279
+ if (!this.hasAttribute(ATTR_LOOP)) return "infinite";
280
+ if (Number.isFinite(this.loop) && this.loop > 0) return String(this.loop);
281
+ return "infinite";
282
+ }
283
+ handleAnimationEnd() {
284
+ if (!this.hasFiniteAnimation()) return;
285
+ this.running = false;
286
+ this.syncAnimationPlayState();
288
287
  }
289
- shouldStopAfterLoop() {
290
- return this.hasAttribute(ATTR_LOOP) && this.loop > 0 && this.loopsDone >= this.loop;
288
+ restartAnimation() {
289
+ this.track.style.animationName = "none";
290
+ this.track.offsetWidth;
291
+ this.track.style.removeProperty("animation-name");
291
292
  }
292
- render() {
293
- if (this.isVerticalDirection) this.track.style.transform = `translateY(${this.position}px)`;
294
- else this.track.style.transform = `translateX(${this.position}px)`;
293
+ hasFiniteAnimation() {
294
+ if (this.behavior === "slide" && !this.hasAttribute(ATTR_LOOP)) return true;
295
+ return this.hasAttribute(ATTR_LOOP) && Number.isFinite(this.loop) && this.loop > 0;
295
296
  }
296
297
  };
297
298
  var defineRemarqueebleElements = () => {
package/package.json CHANGED
@@ -3,17 +3,15 @@
3
3
  "name": "Rémino Rem",
4
4
  "url": "https://remino.net/"
5
5
  },
6
- "browser": "dist/remarqueeble.umd.js",
6
+ "browser": "dist/remarqueeble.cjs",
7
7
  "description": "Custom element tribute to the cursed glory of marquee.",
8
- "dependencies": {
9
- "@remino/astro-image-variants": "^0.1.1",
10
- "@remino/astro-middleware": "^0.1.0",
11
- "@remino/astro-site-nav": "^0.4.2",
12
- "@remino/directive": "^5.3.4"
13
- },
14
8
  "devDependencies": {
15
9
  "@astrojs/check": "^0.9.4",
16
10
  "@eslint/js": "^10.0.1",
11
+ "@remino/astro-image-variants": "^0.1.1",
12
+ "@remino/astro-middleware": "^0.1.0",
13
+ "@remino/astro-site-nav": "^0.4.2",
14
+ "@remino/directive": "^5.3.4",
17
15
  "astro": "^7.0.0",
18
16
  "astro-compressor": "^1.3.0",
19
17
  "astro-eslint-parser": "^1.4.0",
@@ -55,6 +53,10 @@
55
53
  "main": "dist/remarqueeble.cjs",
56
54
  "module": "dist/remarqueeble.mjs",
57
55
  "name": "remarqueeble",
56
+ "sideEffects": [
57
+ "./dist/remarqueeble-auto.*",
58
+ "./src/lib/auto.ts"
59
+ ],
58
60
  "scripts": {
59
61
  "build": "npm run js:build && npm run site:assets && astro build",
60
62
  "dev": "astro dev",
@@ -78,5 +80,5 @@
78
80
  },
79
81
  "type": "module",
80
82
  "types": "dist/remarqueeble.d.ts",
81
- "version": "0.2.0"
83
+ "version": "0.3.0"
82
84
  }
@@ -1,29 +0,0 @@
1
- /*! remarqueeble v0.2.0 | (c) 2026 Rémino Rem <https://remino.net/> | ISC Licence */
2
- (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.remarqueeble={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=`left`,n=`scroll`,r=6,i=85,a=60,o=`200px`,s=`calc(100% - (var(--attr-hspace, 0px) * 2))`,c=`direction`,l=`behavior`,u=`scrollamount`,d=`scrolldelay`,f=`truespeed`,p=`loop`,m=`bgcolor`,h=`width`,g=`height`,_=`hspace`,v=`vspace`,y=`--attr-width`,b=`--attr-height`,x=`--attr-hspace`,S=`--attr-vspace`,C=`--attr-bgcolor`,w=globalThis.HTMLElement??class{},T=e=>{if(e===null)return null;let t=e.trim();return t===``?null:/^[+-]?(?:\d+|\d*\.\d+)$/.test(t)?`${t}px`:globalThis.CSS?.supports(`width`,t)?t:null},E=[{attribute:h,cssVar:y,parser:T},{attribute:g,cssVar:b,parser:T,fallback(e){return e.isVerticalDirection&&!e.hasAttribute(g)?o:null}},{attribute:_,cssVar:x,parser:T},{attribute:v,cssVar:S,parser:T},{attribute:m,cssVar:C,parser:e=>{if(e===null)return null;let t=e.trim();return t===``?null:globalThis.CSS?.supports(`background-color`,t)?t:null}}],D=class extends w{static observedAttributes=[c,l,u,d,f,p,m,h,g,_,v];track;running=!1;position=0;lastTime=null;loopsDone=0;forward=!0;rafId=null;constructor(){super();let e=this.attachShadow({mode:`open`});e.innerHTML=`
3
- <style>
4
- :host {
5
- display: inline-block;
6
- text-align: initial;
7
- overflow: hidden !important;
8
- white-space: nowrap;
9
- width: var(${y}, ${s});
10
- height: var(${b}, auto);
11
- margin-inline: var(${x}, 0px);
12
- margin-block: var(${S}, 0px);
13
- background-color: var(${C}, transparent);
14
- box-sizing: border-box;
15
- }
16
-
17
- :host([direction="up"]),
18
- :host([direction="down"]) {
19
- white-space: normal;
20
- }
21
-
22
- .track {
23
- display: inline-block;
24
- will-change: transform;
25
- }
26
- </style>
27
-
28
- <span class="track"><slot></slot></span>
29
- `;let t=e.querySelector(`.track`);if(!t)throw Error(`Remarqueeble track element was not created.`);this.track=t}connectedCallback(){this.running=!0,this.syncPresentationalHints(),requestAnimationFrame(()=>{!this.isConnected||!this.running||(this.reset(),this.tick())})}disconnectedCallback(){this.running=!1,this.lastTime=null,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}attributeChangedCallback(e,t,n){t!==n&&(this.syncPresentationalHints(),this.isConnected&&this.reset())}get direction(){return this.getAttribute(c)||t}get behavior(){return this.getAttribute(l)||n}get scrollAmount(){let e=this.getAttribute(u),t=e===null||e.trim()===``?NaN:Number(e);return Number.isFinite(t)&&t>=0?t:r}get scrollDelay(){let e=this.getAttribute(d),t=e===null||e.trim()===``?NaN:Number(e),n=Number.isFinite(t)&&t>=0?t:i;return this.hasAttribute(f)?n:Math.max(n,a)}get loop(){let e=this.getAttribute(p);return e===null?-1:Number(e)}get directionSign(){return this.direction===`right`||this.direction===`down`?1:-1}get isVerticalDirection(){return this.direction===`up`||this.direction===`down`}start(){this.running||(this.running=!0,this.lastTime=null,this.tick())}stop(){this.running=!1,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}syncPresentationalHints(){for(let e of E)this.syncVar(e)}syncVar(e){let t=this.getAttribute(e.attribute),n=e.parser(t),r=e.fallback?e.fallback(this):null;if(n==null){r==null?this.style.removeProperty(e.cssVar):this.style.setProperty(e.cssVar,r);return}this.style.setProperty(e.cssVar,n)}reset(){let e=this.getHostSize(),t=this.getTrackSize();this.loopsDone=0,this.forward=!0,this.position=this.behavior===`alternate`?this.getAlternateStartPosition(e,t):this.getStartPosition(e,t),this.render()}getHostSize(){return this.isVerticalDirection?this.clientHeight:this.clientWidth}getTrackSize(){return this.isVerticalDirection?this.track.offsetHeight:this.track.offsetWidth}getStartPosition(e,t){return this.directionSign<0?e:-t}getFlushEndPosition(e,t){return this.directionSign<0?0:e-t}getOffEndPosition(e,t){return this.directionSign<0?-t:e}getSlideEndPosition(e,t){return this.directionSign<0?0:e-t}getAlternateStartPosition(e,t){return this.directionSign<0?e-t:0}tick(e=performance.now()){this.running&&(this.lastTime===null&&(this.lastTime=e),e-this.lastTime>=this.scrollDelay&&(this.step(),this.lastTime=e),this.running&&(this.rafId=requestAnimationFrame(e=>this.tick(e))))}step(){let e=this.getHostSize(),t=this.getTrackSize(),n=this.getStartPosition(e,t),r=this.getFlushEndPosition(e,t),i=this.getOffEndPosition(e,t),a=this.getSlideEndPosition(e,t),o=this.getAlternateStartPosition(e,t),s=this.scrollAmount,c=this.directionSign*s;this.behavior===`alternate`?(this.position+=this.forward?c:-c,this.forward?(this.directionSign<0&&this.position<=r||this.directionSign>0&&this.position>=r)&&(this.position=r,this.forward=!1,this.incrementLoopCount(),this.shouldStopAfterLoop()&&this.stop()):(this.directionSign<0&&this.position>=o||this.directionSign>0&&this.position<=o)&&(this.position=o,this.forward=!0,this.incrementLoopCount(),this.shouldStopAfterLoop()&&this.stop())):this.behavior===`slide`?(this.position+=c,(this.directionSign<0&&this.position<=a||this.directionSign>0&&this.position>=a)&&(this.position=a,this.incrementLoopCount(),!this.hasAttribute(p)||this.loop<=0||this.shouldStopAfterLoop()?this.stop():this.position=n)):(this.position+=c,(this.directionSign<0&&this.position<=i||this.directionSign>0&&this.position>=i)&&(this.position=n,this.incrementLoopCount(),this.shouldStopAfterLoop()&&this.stop())),this.render()}incrementLoopCount(){this.loopsDone++}shouldStopAfterLoop(){return this.hasAttribute(p)&&this.loop>0&&this.loopsDone>=this.loop}render(){this.isVerticalDirection?this.track.style.transform=`translateY(${this.position}px)`:this.track.style.transform=`translateX(${this.position}px)`}},O=()=>{typeof customElements>`u`||(customElements.get(`re-marquee`)||customElements.define(`re-marquee`,D),customElements.get(`re-marquee-ble`)||customElements.define(`re-marquee-ble`,D))};O(),e.defineRemarqueebleElements=O});