marquee-content 5.0.3 → 6.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 ux-ui.pro
3
+ Copyright (c) 2026 Maxim
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,21 +1,29 @@
1
1
  # marquee-content
2
2
 
3
- Simple Web Component for marquee/ticker rows with smooth, continuous motion.
3
+ A Web Component for decorative text tickers, logo strips, and continuous image rows.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/marquee-content.svg?colorB=brightgreen)](https://www.npmjs.com/package/marquee-content)
6
6
  [![NPM Downloads](https://img.shields.io/npm/dm/marquee-content.svg?style=flat)](https://www.npmjs.com/package/marquee-content)
7
7
 
8
- [Demo](https://codepen.io/ux-ui/pen/dygzqYm)
8
+ [Demo](https://codepen.io/nilmuse/pen/dygzqYm)
9
9
 
10
10
  ---
11
11
 
12
12
  ## Features
13
13
 
14
- - Drop-in Custom Element (`<marquee-content>`) that works in plain HTML.
15
- - Two movement modes: `auto` (pure CSS) and `scroll` (reacts to page scroll + inertia).
16
- - `rtl`/`ltr` direction support in both modes.
17
- - Smart pausing on hover, focus, out-of-viewport, and reduced-motion settings.
18
- - Easy style control via CSS variables or runtime `styleOverrides`.
14
+ - A `<marquee-content>` custom element for plain HTML and framework applications.
15
+ - Continuous motion in either direction, using CSS animation in `auto` mode.
16
+ - A `scroll` mode that changes direction and speed with page scrolling, then eases back to its base speed.
17
+ - Optional hover pausing and automatic pausing outside the viewport.
18
+ - A static, wrapping presentation when the user prefers reduced motion.
19
+ - Styling through inherited host properties, CSS variables, and `::part()`.
20
+ - Automatic layout updates for source content, images, fonts, and size changes.
21
+
22
+ ### Supported content
23
+
24
+ Use the component for decorative text and images. The rendered row consists of copies of the supplied content; those copies are hidden from assistive technology and inert. Keep links, buttons, forms, and other interactive controls outside the moving row.
25
+
26
+ Apply text styles to the host and item styles through the exposed CSS parts. The component copies markup, including custom `part` tokens; event listeners, application state, and document-level class selectors are not a styling or interaction contract for the rendered copies.
19
27
 
20
28
  ---
21
29
 
@@ -25,96 +33,146 @@ Simple Web Component for marquee/ticker rows with smooth, continuous motion.
25
33
  npm install marquee-content
26
34
  ```
27
35
 
28
- Optional stylesheet (sidecar):
29
-
30
- ```ts
31
- import 'marquee-content/marquee-content.css';
32
- ```
33
-
34
36
  ---
35
37
 
36
38
  ## Quick Start
37
39
 
38
- Import the package once — it registers the custom element and applies bundled Shadow DOM styles automatically:
40
+ Import the package in your browser entry point. This registers the default tag and installs its Shadow DOM styles:
39
41
 
40
42
  ```ts
41
43
  import 'marquee-content';
42
44
  ```
43
45
 
44
46
  ```html
45
- <marquee-content speed="120" mode="auto" direction="rtl">
47
+ <marquee-content speed="120" direction="rtl">
46
48
  <span>News</span>
47
49
  <span>Promotions</span>
48
50
  <span>24/7 Delivery</span>
49
51
  </marquee-content>
50
52
  ```
51
53
 
52
- If you want movement tied to page scroll:
54
+ ```css
55
+ marquee-content {
56
+ --marquee-content-gap: 2rem;
57
+ color: #151515;
58
+ font: 600 2rem / 1.2 system-ui, sans-serif;
59
+ }
60
+ ```
61
+
62
+ To react to page scrolling:
53
63
 
54
64
  ```html
55
65
  <marquee-content speed="120" mode="scroll" direction="ltr">
56
- <span>Discounts up to 40%</span>
57
- <span>Free returns</span>
66
+ <span>New collection</span>
67
+ <span>Made to move</span>
58
68
  </marquee-content>
59
69
  ```
60
70
 
71
+ `scroll` listens to the window's vertical scroll position. Its direction follows scrolling, and its speed boost decays after scrolling stops. A custom scroll container is not currently configurable.
72
+
61
73
  ---
62
74
 
63
75
  ## API
64
76
 
65
- - `defineMarqueeContent(tagName?, options?)` — manually registers the element (useful for custom tag names or custom styles at setup time).
66
- - `initMarqueeContents(options?)` — convenience wrapper around `defineMarqueeContent`.
67
- - `MarqueeContent.configureStyles({ stylesheet, styleOverrides })` — updates global component styles for every current and future instance.
68
- - `MARQUEE_CONTENT_TAG` — default tag name (`'marquee-content'`).
77
+ - `MarqueeContent` is the custom element class. Importing the main package automatically registers `<marquee-content>` in a browser.
78
+ - `defineMarqueeContent(tagName?, options?)` registers a tag if it is not already registered. The default name is `'marquee-content'`.
79
+ - `initMarqueeContents(options?)` accepts `tagName` alongside the global style options and delegates to `defineMarqueeContent()`.
80
+ - `MarqueeContent.configureStyles(options)`, `setStylesheet(value)`, and `setStyleOverrides(value)` configure shared component styles. See Styling for the available options.
81
+ - `MARQUEE_CONTENT_TAG` exports the default tag name.
82
+
83
+ ```ts
84
+ import { defineMarqueeContent, initMarqueeContents } from 'marquee-content';
85
+
86
+ // Register an additional custom tag. The default tag remains registered.
87
+ defineMarqueeContent('brand-ticker');
88
+
89
+ // Equivalent registration helper, with global style configuration:
90
+ initMarqueeContents({
91
+ tagName: 'brand-ticker',
92
+ styleOverrides: ':host { --marquee-content-gap: 2.5rem; }',
93
+ });
94
+ ```
95
+
96
+ Calling a registration helper is only needed for an additional tag or global style setup.
69
97
 
70
98
  ---
71
99
 
72
100
  ## Options
73
101
 
74
- Attributes on `<marquee-content>`:
102
+ | Option (HTML / JavaScript) | Type | Default | Description |
103
+ | --- | --- | --- | --- |
104
+ | `speed` | `number` | `90` | Base speed in px/s, clamped to `10`–`500` before responsive scaling. |
105
+ | `responsive-speed` / `responsiveSpeed` | `boolean` | `true` | Scales the base speed with the component's width. Set to `false` to use the requested base px/s. |
106
+ | `mode` | `'auto' \| 'scroll'` | `'auto'` | `'auto'` for constant movement; `'scroll'` for page-scroll response and inertia. |
107
+ | `direction` | `'rtl' \| 'ltr'` | `'rtl'` | Base direction: right to left or left to right. |
108
+ | `pause-on-hover` / `pauseOnHover` | `boolean` | `false` | Pauses movement while the pointer is over the host. Items remain decorative and inert. |
109
+
110
+ Boolean attributes accept `true` or `false`; an empty attribute enables the option. Removing an attribute restores its default.
111
+
112
+ ### Speed on narrow screens
113
+
114
+ Responsive speed is enabled by default. It uses the **component's width**, in CSS pixels:
115
+
116
+ ```text
117
+ effective speed = speed × clamp(component width / 1280, 0.55, 1)
118
+ ```
119
+
120
+ At widths up to `704px`, the multiplier is `0.55`: the default `90` becomes `49.5px/s`. At `1280px` and wider, it remains `90px/s`. This preserves the existing slower movement on narrow layouts.
121
+
122
+ For the same base speed on mobile and desktop, disable scaling:
123
+
124
+ ```html
125
+ <marquee-content speed="90" responsive-speed="false">
126
+ <span>Consistent speed across screen sizes</span>
127
+ </marquee-content>
128
+ ```
75
129
 
76
- | Option | Type | Default | Description |
77
- |--------|------|---------|-------------|
78
- | `speed` | `number` | `90` | Base speed in px/s (internally clamped to a safe range). |
79
- | `mode` | `'auto' \| 'scroll'` | `'auto'` | `auto`: always moves at a constant speed, `scroll`: responds to page scroll velocity. |
80
- | `direction` | `'rtl' \| 'ltr'` | `'rtl'` | Base movement direction in both `auto` and `scroll` modes. |
81
- | `pause-on-hover` | `boolean` | `false` | Pauses on hover and enables pointer interactions inside the component. |
130
+ ```ts
131
+ const marquee = document.querySelector('marquee-content');
82
132
 
83
- Init options (`initMarqueeContents` / `defineMarqueeContent`):
133
+ if (marquee) {
134
+ marquee.responsiveSpeed = false;
135
+ marquee.speed = 90;
136
+ // Equivalent: marquee.update({ responsiveSpeed: false, speed: 90 });
137
+ }
138
+ ```
84
139
 
85
- | Option | Type | Default | Description |
86
- |--------|------|---------|-------------|
87
- | `tagName` | `string` | `'marquee-content'` | Custom element tag name (only for `initMarqueeContents`). |
88
- | `stylesheet` | `string \| CSSStyleSheet` | bundled CSS | Replaces the default base stylesheet. |
89
- | `styleOverrides` | `string \| CSSStyleSheet` | none | Extra styles applied after the base stylesheet. |
140
+ In `auto` mode, this gives `90px/s`. In `scroll` mode, `90px/s` is the base speed; scrolling and inertia intentionally change it.
90
141
 
91
142
  ---
92
143
 
93
144
  ## Methods
94
145
 
95
146
  ```ts
96
- import type { MarqueeContent } from 'marquee-content';
147
+ import 'marquee-content';
97
148
 
98
- const marquee = document.querySelector<MarqueeContent>('marquee-content');
149
+ const marquee = document.querySelector('marquee-content');
99
150
 
100
151
  marquee?.update({
101
152
  mode: 'scroll',
102
153
  direction: 'ltr',
103
154
  speed: 120,
155
+ responsiveSpeed: false,
104
156
  pauseOnHover: true,
105
157
  });
106
158
 
107
159
  marquee?.refresh();
108
160
  ```
109
161
 
110
- - `update(options)` — applies options as attributes and rebuilds the track.
111
- - `refresh()` — forces a fresh layout rebuild without changing options.
162
+ - `update(options)` applies options as attributes and updates the animation settings.
163
+ - `refresh()` schedules a fresh layout measurement. Use it after application-driven changes that need an explicit refresh.
112
164
 
113
165
  ---
114
166
 
115
- ## Vue 3 + Vite
167
+ ## Framework integration
168
+
169
+ ### Server-rendered applications
170
+
171
+ The module can be imported when browser globals are unavailable. Custom element registration and construction require a browser. Render the declarative tag in server-generated HTML and ensure the package also runs in the browser entry point; the animated Shadow DOM track is built there.
172
+
173
+ ### Vue 3 + Vite
116
174
 
117
- Tell the Vue compiler that `marquee-content` is a custom element:
175
+ Tell Vue's compiler to treat the tag as a custom element:
118
176
 
119
177
  ```ts
120
178
  import { defineConfig } from 'vite';
@@ -133,7 +191,7 @@ export default defineConfig({
133
191
  });
134
192
  ```
135
193
 
136
- Then import the package once during app startup:
194
+ Then import the package in the browser entry point:
137
195
 
138
196
  ```ts
139
197
  import 'marquee-content';
@@ -143,41 +201,102 @@ import 'marquee-content';
143
201
 
144
202
  ## Styling
145
203
 
146
- Base styles ship with the JS bundle and are adopted into each component's Shadow DOM. You do not need a separate CSS import for the marquee to work.
204
+ Base styles ship in the JavaScript bundle and are adopted into each component's Shadow DOM. No separate CSS import is required. A sidecar stylesheet is also exported as `marquee-content/marquee-content.css` for tooling that needs it.
205
+
206
+ ### Inherited text styles and spacing
207
+
208
+ Set inherited properties such as `font` and `color` on the host. Set the gap through its CSS variable:
209
+
210
+ ```css
211
+ .announcements {
212
+ --marquee-content-gap: 1.5rem;
213
+ color: #4a245f;
214
+ font: 700 1.75rem / 1.2 system-ui, sans-serif;
215
+ }
216
+ ```
217
+
218
+ | CSS variable | Purpose |
219
+ | --- | --- |
220
+ | `--marquee-content-gap` | Spacing between items, including the loop boundary. Default: `2rem`. |
221
+ | `--marquee-content-distance` | Measured loop distance, written by the component at runtime. |
222
+ | `--marquee-content-duration` | Calculated loop duration, written by the component at runtime. |
223
+
224
+ Use `speed` to control movement. The distance and duration variables expose calculated values rather than configuration inputs.
225
+
226
+ ### CSS parts and custom item tokens
227
+
228
+ Rendered items live in Shadow DOM. Use the exposed parts to style them:
229
+
230
+ | Part | Target |
231
+ | --- | --- |
232
+ | `item` | Every copied top-level source element. |
233
+ | `group` | Each repeated group of content. |
234
+ | `viewport` | The container that clips the moving row. |
235
+ | `track` | The animated carrier of the groups. |
236
+
237
+ A source element's existing `part` tokens are preserved alongside `item`, so individual items can have their own styles:
238
+
239
+ ```html
240
+ <marquee-content class="brands" aria-label="Featured brands">
241
+ <img src="/logos/presto.svg" part="presto" alt="Presto" width="140" height="48">
242
+ <img src="/logos/acme.svg" part="acme" alt="Acme" width="120" height="48">
243
+ </marquee-content>
244
+ ```
245
+
246
+ ```css
247
+ .brands {
248
+ --marquee-content-gap: 3rem;
249
+ }
250
+
251
+ .brands::part(item) {
252
+ width: auto;
253
+ height: 3rem;
254
+ object-fit: contain;
255
+ }
256
+
257
+ .brands::part(presto) {
258
+ height: 2.5rem;
259
+ }
260
+ ```
261
+
262
+ Provide image dimensions to reserve space while images load. For a purely decorative image with no information to announce, use `alt=""`.
263
+
264
+ ### Global runtime styles
147
265
 
148
- Runtime style overrides:
266
+ Use `MarqueeContent.configureStyles()` to change styles for all existing and future instances:
149
267
 
150
268
  ```ts
151
269
  import { MarqueeContent } from 'marquee-content';
152
270
 
153
271
  MarqueeContent.configureStyles({
154
272
  styleOverrides: `
155
- :host {
156
- --marquee-content-gap: 1.25rem;
157
- }
273
+ :host { --marquee-content-gap: 1.25rem; }
274
+ [part~="item"] { opacity: 0.85; }
158
275
  `,
159
276
  });
160
277
  ```
161
278
 
162
- Useful CSS variables:
279
+ | Style option | Type | Behavior |
280
+ | --- | --- | --- |
281
+ | `stylesheet` | `string \| CSSStyleSheet \| null` | Replaces the base stylesheet. `null` restores the bundled base stylesheet. |
282
+ | `styleOverrides` | `string \| CSSStyleSheet \| null` | Adds styles after the base stylesheet. `null` removes the overrides. |
163
283
 
164
- - `--marquee-content-gap`
165
- - `--marquee-content-distance` (runtime)
166
- - `--marquee-content-duration` (runtime)
284
+ Use host styles and `::part()` for individual instances. The runtime configuration above is shared globally.
167
285
 
168
286
  ---
169
287
 
170
- ## Accessibility
288
+ ## Accessibility and motion
171
289
 
172
- - Slotted source content stays in the DOM (visually hidden, still available to assistive tech).
173
- - Cloned decorative content is marked with `aria-hidden`, so screen readers do not announce duplicates.
174
- - Animation pauses on focus and respects `prefers-reduced-motion: reduce`.
290
+ - Source content remains available to assistive technology once; repeated visual copies are `aria-hidden` and inert.
291
+ - Use meaningful image `alt` text for informative logos and an empty `alt` for decorative images.
292
+ - `prefers-reduced-motion: reduce` presents one static, wrapping set of the content so all items can be seen without animation. CSS parts continue to apply.
293
+ - Movement pauses outside the viewport, on focus within the component, and on hover when `pause-on-hover` is enabled.
175
294
 
176
295
  ---
177
296
 
178
297
  ## Browser Support
179
298
 
180
- Designed for modern browsers with Shadow DOM and constructable/adopted stylesheets support.
299
+ The component uses Custom Elements, Shadow DOM, constructable/adopted stylesheets, ResizeObserver, IntersectionObserver, and `inert`. The `scroll` mode also uses the Web Animations API. Use a browser that supports these APIs; legacy-browser fallbacks are not included.
181
300
 
182
301
  ---
183
302