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/README.md CHANGED
@@ -1,125 +1,187 @@
1
1
  # marquee-content
2
2
 
3
- A lightweight marquee Web Component for continuous scrolling content with Shadow DOM style overrides.
4
-
5
- - Works with plain HTML via custom element registration.
6
- - Supports `rtl`, `ltr`, and `scroll` direction modes.
7
- - Supports `pause-on-hover`, viewport pause, reduced motion, and responsive speed.
8
- - Supports CSS overrides via `styleOverrides`.
9
- - 6kB gzipped.
10
- - [Demo](https://codepen.io/ux-ui/pen/dygzqYm).
3
+ Simple Web Component for marquee/ticker rows with smooth, continuous motion.
11
4
 
12
5
  [![npm](https://img.shields.io/npm/v/marquee-content.svg?colorB=brightgreen)](https://www.npmjs.com/package/marquee-content)
13
- [![GitHub package version](https://img.shields.io/github/package-json/v/ux-ui-pro/marquee-content.svg)](https://github.com/ux-ui-pro/marquee-content)
14
- [![NPM Downloads](https://img.shields.io/npm/dm/marquee-content.svg?style=flat)](https://www.npmjs.org/package/marquee-content)
6
+ [![NPM Downloads](https://img.shields.io/npm/dm/marquee-content.svg?style=flat)](https://www.npmjs.com/package/marquee-content)
7
+
8
+ [Demo](https://codepen.io/ux-ui/pen/dygzqYm)
9
+
10
+ ---
11
+
12
+ ## Features
15
13
 
16
- ## Install
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
+ ---
21
+
22
+ ## Installation
17
23
 
18
24
  ```bash
19
- npm i marquee-content
25
+ npm install marquee-content
20
26
  ```
21
27
 
22
- ## Usage
23
-
24
28
  ```ts
25
- import { initMarqueeContents } from 'marquee-content';
29
+ import 'marquee-content/marquee-content.css'
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Quick Start
26
35
 
27
- initMarqueeContents();
36
+ Just import the package once - it registers the custom element automatically:
37
+
38
+ ```ts
39
+ import 'marquee-content'
28
40
  ```
29
41
 
30
42
  ```html
31
- <marquee-content direction="scroll" speed="120" min-group-width-ratio="1.1">
43
+ <marquee-content speed="120" mode="auto" direction="rtl">
32
44
  <span>News</span>
33
45
  <span>Promotions</span>
34
46
  <span>24/7 Delivery</span>
47
+ </marquee-content>
48
+ ```
49
+
50
+ If you want movement tied to page scroll:
51
+
52
+ ```html
53
+ <marquee-content speed="120" mode="scroll" direction="ltr">
35
54
  <span>Discounts up to 40%</span>
55
+ <span>Free returns</span>
36
56
  </marquee-content>
37
57
  ```
38
58
 
39
- ### Style overrides
59
+ ---
60
+
61
+ ## API
62
+
63
+ - `defineMarqueeContent(tagName?, options?)` — manually registers the element (useful for custom tag names or custom styles at setup time).
64
+ - `initMarqueeContents(options?)` — convenience wrapper around `defineMarqueeContent`.
65
+ - `MarqueeContent.configureStyles({ stylesheet, styleOverrides })` — updates global component styles for every current and future instance.
66
+ - `MARQUEE_CONTENT_TAG` — default tag name (`'marquee-content'`).
67
+
68
+ ---
69
+
70
+ ## Options
71
+
72
+ Attributes on `<marquee-content>`:
73
+
74
+ | Option | Type | Default | Description |
75
+ |--------|------|---------|-------------|
76
+ | `speed` | `number` | `90` | Base speed in px/s (internally clamped to a safe range). |
77
+ | `mode` | `'auto' \| 'scroll'` | `'auto'` | `auto`: always moves at a constant speed, `scroll`: responds to page scroll velocity. |
78
+ | `direction` | `'rtl' \| 'ltr'` | `'rtl'` | Base movement direction in both `auto` and `scroll` modes. |
79
+ | `pause-on-hover` | `boolean` | `false` | Pauses on hover and enables pointer interactions inside the component. |
80
+
81
+ Init options (`initMarqueeContents` / `defineMarqueeContent`):
82
+
83
+ | Option | Type | Default | Description |
84
+ |--------|------|---------|-------------|
85
+ | `tagName` | `string` | `'marquee-content'` | Custom element tag name (only for `initMarqueeContents`). |
86
+ | `stylesheet` | `string \| CSSStyleSheet` | bundled CSS | Replaces the default base stylesheet. |
87
+ | `styleOverrides` | `string \| CSSStyleSheet` | none | Extra styles applied after the base stylesheet. |
88
+
89
+ ---
90
+
91
+ ## Methods
40
92
 
41
93
  ```ts
42
- import MarqueeOverrides from './marquee-content.overrides.css?raw';
43
- import { initMarqueeContents } from 'marquee-content';
94
+ import type { MarqueeContent } from 'marquee-content'
95
+
96
+ const marquee = document.querySelector<MarqueeContent>('marquee-content')
97
+
98
+ marquee?.update({
99
+ mode: 'scroll',
100
+ direction: 'ltr',
101
+ speed: 120,
102
+ pauseOnHover: true,
103
+ })
44
104
 
45
- initMarqueeContents({
46
- styleOverrides: MarqueeOverrides,
47
- });
105
+ marquee?.refresh()
48
106
  ```
49
107
 
50
- ```css
51
- /* marquee-content.overrides.css */
52
- :host {
53
- --marquee-content-gap: 2rem;
54
- }
108
+ - `update(options)` — applies options as attributes and rebuilds the track.
109
+ - `refresh()` — forces a fresh layout rebuild without changing options.
55
110
 
56
- :host([pause-on-hover]:not([pause-on-hover="false"])) {
57
- cursor: default;
58
- }
111
+ ---
59
112
 
60
- .marquee-content__group > * {
61
- white-space: nowrap;
62
- }
113
+ ## Styling
63
114
 
64
- .marquee-content__track {
65
- will-change: transform;
66
- }
67
- ```
115
+ Optional stylesheet import:
68
116
 
69
- ## Options
117
+ ```ts
118
+ import 'marquee-content/marquee-content.css'
119
+ ```
70
120
 
71
- | Attribute | Type | Default | Description |
72
- |:--|:--|:--|:--|
73
- | `speed` | `number` | `90` | Base speed in px/sec. |
74
- | `direction` | `'rtl' \| 'ltr' \| 'scroll'` | `'rtl'` | Marquee direction mode. |
75
- | `min-group-width-ratio` | `number` | `1.05` | Minimum content group width relative to container. |
76
- | `responsive-speed` | `boolean` | `true` | Enables speed scaling by container width. |
77
- | `reference-width` | `number` | `1280` | Reference width used for responsive speed factor. |
78
- | `min-speed-factor` | `number` | `0.55` | Lower bound for responsive speed multiplier. |
79
- | `max-speed-factor` | `number` | `1` | Upper bound for responsive speed multiplier. |
80
- | `pause-on-hover` | `boolean` | `false` | Pauses animation while hovered. |
81
- | `pause-when-out-of-view` | `boolean` | `true` | Pauses animation when not visible in viewport. |
82
- | `recalculate-after-fonts-ready` | `boolean` | `true` | Rebuilds marquee when document fonts are ready. |
83
- | `scroll-velocity-factor` | `number` | `400` | Normalizes scroll velocity for `direction="scroll"`. |
84
- | `scroll-min-extra-speed` | `number` | `0.15` | Minimum scroll boost threshold. |
85
- | `scroll-max-extra-speed` | `number` | `3` | Maximum absolute scroll boost. |
86
- | `scroll-inertia-duration` | `number` | `1600` | Inertia duration (ms) for scroll boost fade-out. |
87
- | `debug` | `boolean` | `false` | Enables debug logs in console. |
88
-
89
- ### Programmatic update
121
+ Runtime style overrides:
90
122
 
91
123
  ```ts
92
- import type { MarqueeContent } from 'marquee-content';
124
+ import { MarqueeContent } from 'marquee-content'
125
+
126
+ MarqueeContent.configureStyles({
127
+ styleOverrides: `
128
+ :host {
129
+ --marquee-content-gap: 1.25rem;
130
+ }
131
+ `,
132
+ })
133
+ ```
93
134
 
94
- const marquee = document.querySelector<MarqueeContent>('marquee-content');
135
+ Useful CSS variables:
95
136
 
96
- if (marquee) {
97
- marquee.update({
98
- direction: 'scroll',
99
- speed: 120,
100
- pauseOnHover: true,
101
- });
137
+ - `--marquee-content-gap`
138
+ - `--marquee-content-distance` (runtime)
139
+ - `--marquee-content-duration` (runtime)
102
140
 
103
- marquee.refresh();
104
- }
141
+ ---
142
+
143
+ ## Vue 3 + Vite
144
+
145
+ Tell the Vue compiler that `marquee-content` is a custom element:
146
+
147
+ ```ts
148
+ import { defineConfig } from 'vite'
149
+ import vue from '@vitejs/plugin-vue'
150
+
151
+ export default defineConfig({
152
+ plugins: [
153
+ vue({
154
+ template: {
155
+ compilerOptions: {
156
+ isCustomElement: (tag) => tag === 'marquee-content',
157
+ },
158
+ },
159
+ }),
160
+ ],
161
+ })
105
162
  ```
106
163
 
107
- ## Methods
164
+ Then import the package once during app startup:
108
165
 
109
166
  ```ts
110
- import type { MarqueeContent } from 'marquee-content';
167
+ import 'marquee-content'
168
+ ```
111
169
 
112
- const marquee = document.querySelector<MarqueeContent>('marquee-content');
170
+ ---
113
171
 
114
- marquee?.update({
115
- speed: 110,
116
- direction: 'rtl',
117
- });
172
+ ## Accessibility
118
173
 
119
- marquee?.refresh();
120
- marquee?.adoptStyleOverrides(':host { --marquee-content-gap: 1.25rem; }');
121
- marquee?.adoptStyles(':host { color: #fff; }');
122
- ```
174
+ - Slotted source content stays in the DOM (visually hidden, still available to assistive tech).
175
+ - Cloned decorative content is marked with `aria-hidden`, so screen readers do not announce duplicates.
176
+ - Animation pauses on focus and respects `prefers-reduced-motion: reduce`.
177
+
178
+ ---
179
+
180
+ ## Browser Support
181
+
182
+ Designed for modern browsers with Shadow DOM and constructable/adopted stylesheets support.
183
+
184
+ ---
123
185
 
124
186
  ## License
125
187