marquee-content 5.0.0-dev.2 → 5.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,157 +1,185 @@
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
28
+ Optional stylesheet (sidecar):
23
29
 
24
30
  ```ts
25
- import { initMarqueeContents } from 'marquee-content';
31
+ import 'marquee-content/marquee-content.css';
32
+ ```
33
+
34
+ ---
26
35
 
27
- initMarqueeContents();
36
+ ## Quick Start
37
+
38
+ Import the package once — it registers the custom element and applies bundled Shadow DOM styles automatically:
39
+
40
+ ```ts
41
+ import 'marquee-content';
28
42
  ```
29
43
 
30
44
  ```html
31
- <marquee-content direction="scroll" speed="120" min-group-width-ratio="1.1">
45
+ <marquee-content speed="120" mode="auto" direction="rtl">
32
46
  <span>News</span>
33
47
  <span>Promotions</span>
34
48
  <span>24/7 Delivery</span>
49
+ </marquee-content>
50
+ ```
51
+
52
+ If you want movement tied to page scroll:
53
+
54
+ ```html
55
+ <marquee-content speed="120" mode="scroll" direction="ltr">
35
56
  <span>Discounts up to 40%</span>
57
+ <span>Free returns</span>
36
58
  </marquee-content>
37
59
  ```
38
60
 
39
- ### Vue 3 + Vite
61
+ ---
40
62
 
41
- Vue must treat `marquee-content` as a Custom Element. Add `isCustomElement` to Vue plugin config:
63
+ ## API
42
64
 
43
- ```ts
44
- // vite.config.ts
45
- import { defineConfig } from 'vite';
46
- import vue from '@vitejs/plugin-vue';
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'`).
47
69
 
48
- export default defineConfig({
49
- plugins: [
50
- vue({
51
- template: {
52
- compilerOptions: {
53
- isCustomElement: (tag) => tag === 'marquee-content',
54
- },
55
- },
56
- }),
57
- ],
58
- });
59
- ```
70
+ ---
60
71
 
61
- Then initialize the component once on app startup:
72
+ ## Options
62
73
 
63
- ```ts
64
- import { initMarqueeContents } from 'marquee-content';
74
+ Attributes on `<marquee-content>`:
65
75
 
66
- initMarqueeContents();
67
- ```
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. |
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
+ Init options (`initMarqueeContents` / `defineMarqueeContent`):
70
84
 
71
- ### Style overrides
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. |
90
+
91
+ ---
92
+
93
+ ## Methods
72
94
 
73
95
  ```ts
74
- import MarqueeOverrides from './marquee-content.overrides.css?raw';
75
- import { initMarqueeContents } from 'marquee-content';
96
+ import type { MarqueeContent } from 'marquee-content'
97
+
98
+ const marquee = document.querySelector<MarqueeContent>('marquee-content')
76
99
 
77
- initMarqueeContents({
78
- styleOverrides: MarqueeOverrides,
79
- });
100
+ marquee?.update({
101
+ mode: 'scroll',
102
+ direction: 'ltr',
103
+ speed: 120,
104
+ pauseOnHover: true,
105
+ })
106
+
107
+ marquee?.refresh()
80
108
  ```
81
109
 
82
- ```css
83
- /* marquee-content.overrides.css */
84
- :host {
85
- --marquee-content-gap: 2rem;
86
- }
110
+ - `update(options)` — applies options as attributes and rebuilds the track.
111
+ - `refresh()` — forces a fresh layout rebuild without changing options.
112
+
113
+ ---
114
+
115
+ ## Styling
87
116
 
88
- :host([pause-on-hover]:not([pause-on-hover="false"])) {
89
- cursor: default;
90
- }
117
+ 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.
91
118
 
92
- .marquee-content__group > * {
93
- white-space: nowrap;
94
- }
119
+ Runtime style overrides:
95
120
 
96
- .marquee-content__track {
97
- will-change: transform;
98
- }
121
+ ```ts
122
+ import { MarqueeContent } from 'marquee-content';
123
+
124
+ MarqueeContent.configureStyles({
125
+ styleOverrides: `
126
+ :host {
127
+ --marquee-content-gap: 1.25rem;
128
+ }
129
+ `,
130
+ })
99
131
  ```
100
132
 
101
- ## Options
133
+ Useful CSS variables:
102
134
 
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
135
+ - `--marquee-content-gap`
136
+ - `--marquee-content-distance` (runtime)
137
+ - `--marquee-content-duration` (runtime)
122
138
 
123
- ```ts
124
- import type { MarqueeContent } from 'marquee-content';
139
+ ---
140
+
141
+ ## Vue 3 + Vite
125
142
 
126
- const marquee = document.querySelector<MarqueeContent>('marquee-content');
143
+ Tell the Vue compiler that `marquee-content` is a custom element:
127
144
 
128
- if (marquee) {
129
- marquee.update({
130
- direction: 'scroll',
131
- speed: 120,
132
- pauseOnHover: true,
133
- });
145
+ ```ts
146
+ import { defineConfig } from 'vite'
147
+ import vue from '@vitejs/plugin-vue'
134
148
 
135
- marquee.refresh();
136
- }
149
+ export default defineConfig({
150
+ plugins: [
151
+ vue({
152
+ template: {
153
+ compilerOptions: {
154
+ isCustomElement: (tag) => tag === 'marquee-content',
155
+ },
156
+ },
157
+ }),
158
+ ],
159
+ })
137
160
  ```
138
161
 
139
- ## Methods
162
+ Then import the package once during app startup:
140
163
 
141
164
  ```ts
142
- import type { MarqueeContent } from 'marquee-content';
165
+ import 'marquee-content';
166
+ ```
143
167
 
144
- const marquee = document.querySelector<MarqueeContent>('marquee-content');
168
+ ---
145
169
 
146
- marquee?.update({
147
- speed: 110,
148
- direction: 'rtl',
149
- });
170
+ ## Accessibility
150
171
 
151
- marquee?.refresh();
152
- marquee?.adoptStyleOverrides(':host { --marquee-content-gap: 1.25rem; }');
153
- marquee?.adoptStyles(':host { color: #fff; }');
154
- ```
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`.
175
+
176
+ ---
177
+
178
+ ## Browser Support
179
+
180
+ Designed for modern browsers with Shadow DOM and constructable/adopted stylesheets support.
181
+
182
+ ---
155
183
 
156
184
  ## License
157
185