marquee-content 5.0.4 → 6.0.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/README.md CHANGED
@@ -1,23 +1,11 @@
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)
9
-
10
- ---
11
-
12
- ## Features
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`.
19
-
20
- ---
8
+ [Demo](https://codepen.io/nilmuse/pen/dygzqYm)
21
9
 
22
10
  ## Installation
23
11
 
@@ -25,96 +13,134 @@ Simple Web Component for marquee/ticker rows with smooth, continuous motion.
25
13
  npm install marquee-content
26
14
  ```
27
15
 
28
- Optional stylesheet (sidecar):
29
-
30
- ```ts
31
- import 'marquee-content/marquee-content.css';
32
- ```
33
-
34
- ---
16
+ ## Quick start
35
17
 
36
- ## Quick Start
37
-
38
- Import the package once — it registers the custom element and applies bundled Shadow DOM styles automatically:
18
+ Import the package in your browser entry point. This registers the default tag and installs its Shadow DOM styles:
39
19
 
40
20
  ```ts
41
21
  import 'marquee-content';
42
22
  ```
43
23
 
44
24
  ```html
45
- <marquee-content speed="120" mode="auto" direction="rtl">
25
+ <marquee-content speed="120" direction="rtl">
46
26
  <span>News</span>
47
27
  <span>Promotions</span>
48
28
  <span>24/7 Delivery</span>
49
29
  </marquee-content>
50
30
  ```
51
31
 
52
- If you want movement tied to page scroll:
53
-
54
- ```html
55
- <marquee-content speed="120" mode="scroll" direction="ltr">
56
- <span>Discounts up to 40%</span>
57
- <span>Free returns</span>
58
- </marquee-content>
32
+ ```css
33
+ marquee-content {
34
+ --marquee-content-gap: 2rem;
35
+ color: #151515;
36
+ font: 600 2rem / 1.2 system-ui, sans-serif;
37
+ }
59
38
  ```
60
39
 
61
- ---
40
+ In the default `auto` mode, the row moves continuously using CSS animation. Layout updates automatically when source content, images, fonts, or sizes change.
62
41
 
63
42
  ## API
64
43
 
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'`).
44
+ - `MarqueeContent` is the custom element class. Importing the main package automatically registers `<marquee-content>` in a browser.
45
+ - `defineMarqueeContent(tagName?, options?)` registers a tag if it is not already registered. The default name is `'marquee-content'`.
46
+ - `initMarqueeContents(options?)` accepts `tagName` alongside the global style options and delegates to `defineMarqueeContent()`.
47
+ - `MarqueeContent.configureStyles(options)`, `setStylesheet(value)`, and `setStyleOverrides(value)` configure shared component styles. See Styling for the available options.
48
+ - `MARQUEE_CONTENT_TAG` exports the default tag name.
69
49
 
70
- ---
50
+ ```ts
51
+ import { defineMarqueeContent, initMarqueeContents } from 'marquee-content';
71
52
 
72
- ## Options
53
+ // Register an additional custom tag. The default tag remains registered.
54
+ defineMarqueeContent('brand-ticker');
73
55
 
74
- Attributes on `<marquee-content>`:
56
+ // Equivalent registration helper, with global style configuration:
57
+ initMarqueeContents({
58
+ tagName: 'brand-ticker',
59
+ styleOverrides: ':host { --marquee-content-gap: 2.5rem; }',
60
+ });
61
+ ```
75
62
 
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. |
63
+ Calling a registration helper is only needed for an additional tag or global style setup.
82
64
 
83
- Init options (`initMarqueeContents` / `defineMarqueeContent`):
65
+ ### Options
84
66
 
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. |
67
+ | Option (HTML / JavaScript) | Type | Default | Description |
68
+ | --- | --- | --- | --- |
69
+ | `speed` | `number` | `90` | Base speed in px/s, clamped to `10`–`500` before responsive scaling. |
70
+ | `responsive-speed` / `responsiveSpeed` | `boolean` | `true` | Scales the base speed with the component's width. Set to `false` to use the requested base px/s. |
71
+ | `mode` | `'auto' \| 'scroll'` | `'auto'` | `'auto'` for constant movement; `'scroll'` for page-scroll response and inertia. |
72
+ | `direction` | `'rtl' \| 'ltr'` | `'rtl'` | Base direction: right to left or left to right. |
73
+ | `pause-on-hover` / `pauseOnHover` | `boolean` | `false` | Pauses movement while the pointer is over the host. Items remain decorative and inert. |
90
74
 
91
- ---
75
+ Boolean attributes accept `true` or `false`; an empty attribute enables the option. Removing an attribute restores its default.
92
76
 
93
- ## Methods
77
+ ### Methods
94
78
 
95
79
  ```ts
96
- import type { MarqueeContent } from 'marquee-content';
80
+ import 'marquee-content';
97
81
 
98
- const marquee = document.querySelector<MarqueeContent>('marquee-content');
82
+ const marquee = document.querySelector('marquee-content');
99
83
 
100
84
  marquee?.update({
101
85
  mode: 'scroll',
102
86
  direction: 'ltr',
103
87
  speed: 120,
88
+ responsiveSpeed: false,
104
89
  pauseOnHover: true,
105
90
  });
106
91
 
107
92
  marquee?.refresh();
108
93
  ```
109
94
 
110
- - `update(options)` — applies options as attributes and rebuilds the track.
111
- - `refresh()` — forces a fresh layout rebuild without changing options.
95
+ - `update(options)` applies options as attributes and updates the animation settings.
96
+ - `refresh()` schedules a fresh layout measurement. Use it after application-driven changes that need an explicit refresh.
97
+
98
+ ## Scroll response
99
+
100
+ To react to page scrolling:
101
+
102
+ ```html
103
+ <marquee-content speed="120" mode="scroll" direction="ltr">
104
+ <span>New collection</span>
105
+ <span>Made to move</span>
106
+ </marquee-content>
107
+ ```
108
+
109
+ `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.
110
+
111
+ ## Speed on narrow screens
112
+
113
+ Responsive speed is enabled by default. It uses the **component's width**, in CSS pixels:
114
+
115
+ ```text
116
+ effective speed = speed × clamp(component width / 1280, 0.55, 1)
117
+ ```
112
118
 
113
- ---
119
+ Below a component width of about `700px`, speed stays at 55% of the configured value — about `50px/s` with the default `speed="90"`. At `1280px` and above, it uses the configured speed without scaling.
114
120
 
115
- ## Vue 3 + Vite
121
+ For the same base speed on mobile and desktop, disable scaling:
116
122
 
117
- Tell the Vue compiler that `marquee-content` is a custom element:
123
+ ```html
124
+ <marquee-content speed="90" responsive-speed="false">
125
+ <span>Consistent speed across screen sizes</span>
126
+ </marquee-content>
127
+ ```
128
+
129
+ ```ts
130
+ const marquee = document.querySelector('marquee-content');
131
+
132
+ if (marquee) {
133
+ marquee.responsiveSpeed = false;
134
+ marquee.speed = 90;
135
+ // Equivalent: marquee.update({ responsiveSpeed: false, speed: 90 });
136
+ }
137
+ ```
138
+
139
+ In `auto` mode, this gives `90px/s`. In `scroll` mode, `90px/s` is the base speed; scrolling and inertia intentionally change it.
140
+
141
+ ## Vue 3 with Vite
142
+
143
+ Tell Vue's compiler to treat the tag as a custom element:
118
144
 
119
145
  ```ts
120
146
  import { defineConfig } from 'vite';
@@ -133,53 +159,125 @@ export default defineConfig({
133
159
  });
134
160
  ```
135
161
 
136
- Then import the package once during app startup:
162
+ Then render it in a component:
137
163
 
138
- ```ts
164
+ ```vue
165
+ <script setup lang="ts">
139
166
  import 'marquee-content';
167
+ </script>
168
+
169
+ <template>
170
+ <marquee-content speed="120">
171
+ <span>New collection</span>
172
+ <span>Made to move</span>
173
+ </marquee-content>
174
+ </template>
140
175
  ```
141
176
 
142
- ---
143
-
144
177
  ## Styling
145
178
 
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.
179
+ 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.
180
+
181
+ ### Inherited text styles and spacing
182
+
183
+ Set inherited properties such as `font` and `color` on the host. Set the gap through its CSS variable:
184
+
185
+ ```css
186
+ .announcements {
187
+ --marquee-content-gap: 1.5rem;
188
+ color: #4a245f;
189
+ font: 700 1.75rem / 1.2 system-ui, sans-serif;
190
+ }
191
+ ```
192
+
193
+ | CSS variable | Purpose |
194
+ | --- | --- |
195
+ | `--marquee-content-gap` | Spacing between items, including the loop boundary. Default: `2rem`. |
196
+ | `--marquee-content-distance` | Measured loop distance, written by the component at runtime. |
197
+ | `--marquee-content-duration` | Calculated loop duration, written by the component at runtime. |
198
+
199
+ Use `speed` to control movement. The distance and duration variables expose calculated values rather than configuration inputs.
200
+
201
+ ### CSS parts and custom item tokens
147
202
 
148
- Runtime style overrides:
203
+ Rendered items live in Shadow DOM. Use the exposed parts to style them:
204
+
205
+ | Part | Target |
206
+ | --- | --- |
207
+ | `item` | Every copied top-level source element. |
208
+ | `group` | Each repeated group of content. |
209
+ | `viewport` | The container that clips the moving row. |
210
+ | `track` | The animated carrier of the groups. |
211
+
212
+ A source element's existing `part` tokens are preserved alongside `item`, so individual items can have their own styles:
213
+
214
+ ```html
215
+ <marquee-content class="brands" aria-label="Featured brands">
216
+ <img src="/logos/presto.svg" part="presto" alt="Presto" width="140" height="48">
217
+ <img src="/logos/acme.svg" part="acme" alt="Acme" width="120" height="48">
218
+ </marquee-content>
219
+ ```
220
+
221
+ ```css
222
+ .brands {
223
+ --marquee-content-gap: 3rem;
224
+ }
225
+
226
+ .brands::part(item) {
227
+ width: auto;
228
+ height: 3rem;
229
+ object-fit: contain;
230
+ }
231
+
232
+ .brands::part(presto) {
233
+ height: 2.5rem;
234
+ }
235
+ ```
236
+
237
+ Provide image dimensions to reserve space while images load. For a purely decorative image with no information to announce, use `alt=""`.
238
+
239
+ ### Global runtime styles
240
+
241
+ Use `MarqueeContent.configureStyles()` to change styles for all existing and future instances:
149
242
 
150
243
  ```ts
151
244
  import { MarqueeContent } from 'marquee-content';
152
245
 
153
246
  MarqueeContent.configureStyles({
154
247
  styleOverrides: `
155
- :host {
156
- --marquee-content-gap: 1.25rem;
157
- }
248
+ :host { --marquee-content-gap: 1.25rem; }
249
+ [part~="item"] { opacity: 0.85; }
158
250
  `,
159
251
  });
160
252
  ```
161
253
 
162
- Useful CSS variables:
254
+ | Style option | Type | Behavior |
255
+ | --- | --- | --- |
256
+ | `stylesheet` | `string \| CSSStyleSheet \| null` | Replaces the base stylesheet. `null` restores the bundled base stylesheet. |
257
+ | `styleOverrides` | `string \| CSSStyleSheet \| null` | Adds styles after the base stylesheet. `null` removes the overrides. |
258
+
259
+ Use host styles and `::part()` for individual instances. The runtime configuration above is shared globally.
260
+
261
+ ## Supported content
163
262
 
164
- - `--marquee-content-gap`
165
- - `--marquee-content-distance` (runtime)
166
- - `--marquee-content-duration` (runtime)
263
+ 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.
167
264
 
168
- ---
265
+ 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.
169
266
 
170
- ## Accessibility
267
+ ## Accessibility and motion
171
268
 
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`.
269
+ - Source content remains available to assistive technology once; repeated visual copies are `aria-hidden` and inert.
270
+ - Use meaningful image `alt` text for informative logos and an empty `alt` for decorative images.
271
+ - `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.
272
+ - Movement pauses outside the viewport, on focus within the component, and on hover when `pause-on-hover` is enabled.
175
273
 
176
- ---
274
+ ## Server-rendered applications
177
275
 
178
- ## Browser Support
276
+ 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.
179
277
 
180
- Designed for modern browsers with Shadow DOM and constructable/adopted stylesheets support.
278
+ ## Browser support
181
279
 
182
- ---
280
+ 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.
183
281
 
184
282
  ## License
185
283