marquee-content 5.0.0-dev.2 → 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,158 +1,188 @@
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
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`.
15
19
 
16
- ## Install
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
+ ---
26
33
 
27
- initMarqueeContents();
34
+ ## Quick Start
35
+
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
- ### Vue 3 + Vite
59
+ ---
40
60
 
41
- Vue must treat `marquee-content` as a Custom Element. Add `isCustomElement` to Vue plugin config:
61
+ ## API
42
62
 
43
- ```ts
44
- // vite.config.ts
45
- import { defineConfig } from 'vite';
46
- import vue from '@vitejs/plugin-vue';
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'`).
47
67
 
48
- export default defineConfig({
49
- plugins: [
50
- vue({
51
- template: {
52
- compilerOptions: {
53
- isCustomElement: (tag) => tag === 'marquee-content',
54
- },
55
- },
56
- }),
57
- ],
58
- });
59
- ```
68
+ ---
60
69
 
61
- Then initialize the component once on app startup:
70
+ ## Options
62
71
 
63
- ```ts
64
- import { initMarqueeContents } from 'marquee-content';
72
+ Attributes on `<marquee-content>`:
65
73
 
66
- initMarqueeContents();
67
- ```
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`):
68
82
 
69
- If this config is missing, Vue can compile `<marquee-content>` as a Vue component and the Web Component may receive no source nodes (empty/0x0 track).
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. |
70
88
 
71
- ### Style overrides
89
+ ---
90
+
91
+ ## Methods
72
92
 
73
93
  ```ts
74
- import MarqueeOverrides from './marquee-content.overrides.css?raw';
75
- 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
+ })
76
104
 
77
- initMarqueeContents({
78
- styleOverrides: MarqueeOverrides,
79
- });
105
+ marquee?.refresh()
80
106
  ```
81
107
 
82
- ```css
83
- /* marquee-content.overrides.css */
84
- :host {
85
- --marquee-content-gap: 2rem;
86
- }
108
+ - `update(options)` — applies options as attributes and rebuilds the track.
109
+ - `refresh()` — forces a fresh layout rebuild without changing options.
87
110
 
88
- :host([pause-on-hover]:not([pause-on-hover="false"])) {
89
- cursor: default;
90
- }
111
+ ---
91
112
 
92
- .marquee-content__group > * {
93
- white-space: nowrap;
94
- }
113
+ ## Styling
95
114
 
96
- .marquee-content__track {
97
- will-change: transform;
98
- }
99
- ```
115
+ Optional stylesheet import:
100
116
 
101
- ## Options
117
+ ```ts
118
+ import 'marquee-content/marquee-content.css'
119
+ ```
102
120
 
103
- | Attribute | Type | Default | Description |
104
- |:--|:--|:--|:--|
105
- | `speed` | `number` | `90` | Base speed in px/sec. |
106
- | `direction` | `'rtl' \| 'ltr' \| 'scroll'` | `'rtl'` | Marquee direction mode. |
107
- | `min-group-width-ratio` | `number` | `1.05` | Minimum content group width relative to container. |
108
- | `responsive-speed` | `boolean` | `true` | Enables speed scaling by container width. |
109
- | `reference-width` | `number` | `1280` | Reference width used for responsive speed factor. |
110
- | `min-speed-factor` | `number` | `0.55` | Lower bound for responsive speed multiplier. |
111
- | `max-speed-factor` | `number` | `1` | Upper bound for responsive speed multiplier. |
112
- | `pause-on-hover` | `boolean` | `false` | Pauses animation while hovered. |
113
- | `pause-when-out-of-view` | `boolean` | `true` | Pauses animation when not visible in viewport. |
114
- | `recalculate-after-fonts-ready` | `boolean` | `true` | Rebuilds marquee when document fonts are ready. |
115
- | `scroll-velocity-factor` | `number` | `400` | Normalizes scroll velocity for `direction="scroll"`. |
116
- | `scroll-min-extra-speed` | `number` | `0.15` | Minimum scroll boost threshold. |
117
- | `scroll-max-extra-speed` | `number` | `3` | Maximum absolute scroll boost. |
118
- | `scroll-inertia-duration` | `number` | `1600` | Inertia duration (ms) for scroll boost fade-out. |
119
- | `debug` | `boolean` | `false` | Enables debug logs in console. |
120
-
121
- ### Programmatic update
121
+ Runtime style overrides:
122
122
 
123
123
  ```ts
124
- 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
+ ```
125
134
 
126
- const marquee = document.querySelector<MarqueeContent>('marquee-content');
135
+ Useful CSS variables:
127
136
 
128
- if (marquee) {
129
- marquee.update({
130
- direction: 'scroll',
131
- speed: 120,
132
- pauseOnHover: true,
133
- });
137
+ - `--marquee-content-gap`
138
+ - `--marquee-content-distance` (runtime)
139
+ - `--marquee-content-duration` (runtime)
134
140
 
135
- marquee.refresh();
136
- }
137
- ```
141
+ ---
138
142
 
139
- ## Methods
143
+ ## Vue 3 + Vite
144
+
145
+ Tell the Vue compiler that `marquee-content` is a custom element:
140
146
 
141
147
  ```ts
142
- import type { MarqueeContent } from 'marquee-content';
148
+ import { defineConfig } from 'vite'
149
+ import vue from '@vitejs/plugin-vue'
143
150
 
144
- const marquee = document.querySelector<MarqueeContent>('marquee-content');
151
+ export default defineConfig({
152
+ plugins: [
153
+ vue({
154
+ template: {
155
+ compilerOptions: {
156
+ isCustomElement: (tag) => tag === 'marquee-content',
157
+ },
158
+ },
159
+ }),
160
+ ],
161
+ })
162
+ ```
145
163
 
146
- marquee?.update({
147
- speed: 110,
148
- direction: 'rtl',
149
- });
164
+ Then import the package once during app startup:
150
165
 
151
- marquee?.refresh();
152
- marquee?.adoptStyleOverrides(':host { --marquee-content-gap: 1.25rem; }');
153
- marquee?.adoptStyles(':host { color: #fff; }');
166
+ ```ts
167
+ import 'marquee-content'
154
168
  ```
155
169
 
170
+ ---
171
+
172
+ ## Accessibility
173
+
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
+ ---
185
+
156
186
  ## License
157
187
 
158
188
  MIT