@georgepxto/step-timeline 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 georgepxto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,154 @@
1
- # Temporary Holding Version
1
+ # `<step-timeline>`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A dependency-free web component for the steps of a process. By default the steps sit side by side on a line that fills in sequence when they come into view. In pinned mode the component holds the screen while the reader scrolls, showing one step at a time with a large counter. Works in any stack: plain HTML, React, Vue, Svelte, Astro, Rails templates.
4
+
5
+ <picture>
6
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/georgepxto/web-components/main/step-timeline/screenshots/reveal-dark.png">
7
+ <img alt="Four numbered circles joined by a green line, each with a step title and a short description below" src="https://raw.githubusercontent.com/georgepxto/web-components/main/step-timeline/screenshots/reveal-light.png" width="880">
8
+ </picture>
9
+
10
+ - No runtime dependencies, Shadow DOM, under 5 kB gzipped
11
+ - Steps written as plain HTML with `<step-item>`, so the content is in the page even before the script loads
12
+ - Two modes: a timeline that fills in when it scrolls into view, and a pinned, scroll-driven presentation
13
+ - Stacks vertically in narrow containers, and pinned mode turns into a plain list on small screens and for reduced motion
14
+ - Accessible: a real list, a live region for the active step and a full list of steps for screen readers in pinned mode
15
+
16
+ <!-- TODO: add a GIF of the line filling in and of the pinned mode advancing while scrolling (screenshots/reveal.gif, screenshots/pinned.gif) -->
17
+
18
+ ## Install
19
+
20
+ ```sh
21
+ npm install @georgepxto/step-timeline
22
+ ```
23
+
24
+ ```js
25
+ import '@georgepxto/step-timeline';
26
+ ```
27
+
28
+ Or load it from a CDN with no build step:
29
+
30
+ ```html
31
+ <script type="module" src="https://cdn.jsdelivr.net/gh/georgepxto/web-components@main/step-timeline/dist/index.js"></script>
32
+ ```
33
+
34
+ The package registers both `<step-timeline>` and `<step-item>`.
35
+
36
+ ## Usage
37
+
38
+ Each step is a `<step-item>` with its title in `title` and its text as content. The content can hold any inline HTML, like links or emphasis:
39
+
40
+ ```html
41
+ <step-timeline>
42
+ <step-item title="Conversa">Você conta pelo WhatsApp o que precisa resolver.</step-item>
43
+ <step-item title="Proposta">Envio por escrito o que será feito, o prazo e o valor.</step-item>
44
+ <step-item title="Desenvolvimento">Você acompanha versões que já dá para testar.</step-item>
45
+ <step-item title="Entrega">Coloco no ar e mostro como usar.</step-item>
46
+ </step-timeline>
47
+ ```
48
+
49
+ The component reads the steps and renders its own copy, and it re-renders when you add, remove or edit them.
50
+
51
+ ### Reveal mode
52
+
53
+ The default. The numbered circles sit on a horizontal line that fills in green, one segment after the other, the first time at least 35% of the timeline is in view. Below 640px of container width the steps stack and the line runs down the left side.
54
+
55
+ <img alt="The same four steps stacked on a phone, with the green line running down the left through the numbered circles" src="https://raw.githubusercontent.com/georgepxto/web-components/main/step-timeline/screenshots/mobile-light.png" width="328">
56
+
57
+ ### Pinned mode
58
+
59
+ ```html
60
+ <step-timeline mode="pinned" step-height="80vh">
61
+ …
62
+ </step-timeline>
63
+ ```
64
+
65
+ The component becomes `steps × step-height` tall and its inner stage sticks to the top of the window while the page scrolls through it. On the left, a large counter (`02 / 04`) and a progress bar; on the right, the title and text of the active step, crossfading as it changes. The active step is the share of the scroll inside the component: with four steps, the first quarter shows step 1, the second quarter step 2, and so on.
66
+
67
+ <picture>
68
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/georgepxto/web-components/main/step-timeline/screenshots/pinned-dark.png">
69
+ <img alt="Pinned mode on the second step: a large 02 / 04 counter over a quarter-filled bar on the left, the title Proposta and its text on the right" src="https://raw.githubusercontent.com/georgepxto/web-components/main/step-timeline/screenshots/pinned-light.png" width="880">
70
+ </picture>
71
+
72
+ Below 768px of window width, or with `prefers-reduced-motion: reduce`, pinned mode falls back to a plain vertical list that doesn't hold the screen. The `layout` attribute tells you which one is showing.
73
+
74
+ If a fixed header covers the top of the window, push the stage below it with `--step-sticky-top`.
75
+
76
+ ## API
77
+
78
+ ### Attributes
79
+
80
+ | Attribute | Default | Description |
81
+ | --- | --- | --- |
82
+ | `mode` | `reveal` | `reveal` or `pinned` |
83
+ | `step-height` | `70vh` | Scroll length of each step in pinned mode. Accepts `px`, `vh`, `svh`, `lvh`, `dvh`, `rem` and `em` |
84
+ | `theme` | `auto` | `light`, `dark` or `auto` (follows `prefers-color-scheme`) |
85
+ | `layout` | | Set by the component: `reveal`, `pinned` or `list` (pinned mode's fallback) |
86
+
87
+ `<step-item>` takes a `title` attribute and any content.
88
+
89
+ ### Properties
90
+
91
+ | Property | Description |
92
+ | --- | --- |
93
+ | `layout` | The layout currently shown: `reveal`, `pinned` or `list` |
94
+ | `index` | Index of the active step in pinned mode, `-1` otherwise |
95
+
96
+ ### Events
97
+
98
+ | Event | Detail | Description |
99
+ | --- | --- | --- |
100
+ | `stepchange` | `{ index, title }` | Fired in pinned mode when the active step changes |
101
+
102
+ ## Theming
103
+
104
+ | Property | Default (light / dark) | Description |
105
+ | --- | --- | --- |
106
+ | `--step-accent` | `#1d8049` / `#43c97e` | Filled line, active circles and progress bar |
107
+ | `--step-text` | `#0d1310` / `#e9eeea` | Titles and counter |
108
+ | `--step-muted` | `#4a5650` / `#a3ada6` | Step text, pending numbers and counter total |
109
+ | `--step-border` | `#c3ccc6` / `#2c352f` | Empty line, pending circles and progress track |
110
+ | `--step-bg` | `#f6f8f6` / `#0b0e0c` | Inside of the circles. Match your page background |
111
+ | `--step-font` | `inherit` | Font of titles and text |
112
+ | `--step-mono-font` | `ui-monospace` stack | Font of the numbers and counter |
113
+ | `--step-gap` | `32px` | Space between steps |
114
+ | `--step-circle-size` | `40px` | Diameter of the numbered circles |
115
+ | `--step-stagger` | `0.45s` | Time between one step lighting up and the next |
116
+ | `--step-title-size` | `18px` | Step titles |
117
+ | `--step-text-size` | `15px` | Step text |
118
+ | `--step-counter-size` | `clamp(3rem, 8vw, 6rem)` | Counter in pinned mode |
119
+ | `--step-active-title-size` | `clamp(1.5rem, 2.6vw, 2.25rem)` | Active title in pinned mode |
120
+ | `--step-active-text-size` | `18px` | Active text in pinned mode |
121
+ | `--step-sticky-top` | `0px` | Offset of the pinned stage from the top of the window |
122
+
123
+ ```css
124
+ step-timeline {
125
+ --step-accent: #7c3aed;
126
+ --step-circle-size: 48px;
127
+ --step-font: 'Inter', sans-serif;
128
+ }
129
+ ```
130
+
131
+ Style the internals with `::part()`: `steps`, `step`, `number`, `title`, `text`, and in pinned mode `pinned`, `stage`, `meter`, `counter`, `bar`, `active`.
132
+
133
+ ## Accessibility
134
+
135
+ - The steps are an ordered list. The circles' numbers are hidden from screen readers, which announce the list position instead
136
+ - In pinned mode the active step is in an `aria-live="polite"` region, so the change is announced, and a visually hidden list with every step is always available. The counter and bar are decorative and hidden
137
+ - Pinned mode doesn't hold the screen on small screens or for visitors who prefer reduced motion. In reveal mode, reduced motion shows the line already filled
138
+
139
+ ## Browser support
140
+
141
+ All current browsers. The component uses custom elements, Shadow DOM, container queries, `position: sticky` and the `svh` unit.
142
+
143
+ ## Development
144
+
145
+ ```sh
146
+ npm install
147
+ npm test
148
+ ```
149
+
150
+ `npm test` builds `dist/` and runs the unit tests. To try the demo, serve the package folder over HTTP and open `/demo/`.
151
+
152
+ ## License
153
+
154
+ MIT
@@ -0,0 +1,2 @@
1
+ export { StepItem, StepTimeline, type StepChangeDetail } from './step-timeline.js';
2
+ export { activeIndex, pad, readMode, readStepHeight, resolveLayout, scrollProgress, type Layout, type Mode } from './steps.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { StepItem, StepTimeline } from './step-timeline.js';
2
+ export { activeIndex, pad, readMode, readStepHeight, resolveLayout, scrollProgress } from './steps.js';
@@ -0,0 +1,25 @@
1
+ import { type Layout } from './steps.js';
2
+ export interface StepChangeDetail {
3
+ index: number;
4
+ title: string;
5
+ }
6
+ declare const Base: typeof HTMLElement;
7
+ export declare class StepItem extends Base {
8
+ }
9
+ export declare class StepTimeline extends Base {
10
+ #private;
11
+ static observedAttributes: string[];
12
+ constructor();
13
+ get layout(): Layout | null;
14
+ get index(): number;
15
+ connectedCallback(): void;
16
+ disconnectedCallback(): void;
17
+ attributeChangedCallback(_name: string, previous: string | null, value: string | null): void;
18
+ }
19
+ declare global {
20
+ interface HTMLElementTagNameMap {
21
+ 'step-timeline': StepTimeline;
22
+ 'step-item': StepItem;
23
+ }
24
+ }
25
+ export {};
@@ -0,0 +1,271 @@
1
+ import { activeIndex, pad, readMode, readStepHeight, resolveLayout, scrollProgress } from './steps.js';
2
+ import { styles } from './styles.js';
3
+ const TAG = 'step-timeline';
4
+ const ITEM_TAG = 'step-item';
5
+ const NARROW = '(max-width: 767.98px)';
6
+ const REVEAL_THRESHOLD = 0.35;
7
+ const FADE_OUT = 140;
8
+ const FADE_IN = 260;
9
+ const Base = (typeof HTMLElement === 'undefined' ? class {
10
+ } : HTMLElement);
11
+ let sharedSheet;
12
+ const adoptStyles = (shadow) => {
13
+ try {
14
+ if (!sharedSheet) {
15
+ sharedSheet = new CSSStyleSheet();
16
+ sharedSheet.replaceSync(styles);
17
+ }
18
+ shadow.adoptedStyleSheets = [sharedSheet];
19
+ }
20
+ catch {
21
+ const style = document.createElement('style');
22
+ style.textContent = styles;
23
+ shadow.append(style);
24
+ }
25
+ };
26
+ const element = (tag, className, part) => {
27
+ const node = document.createElement(tag);
28
+ node.className = className;
29
+ if (part)
30
+ node.setAttribute('part', part);
31
+ return node;
32
+ };
33
+ export class StepItem extends Base {
34
+ }
35
+ export class StepTimeline extends Base {
36
+ static observedAttributes = ['mode', 'step-height'];
37
+ #root;
38
+ #steps = [];
39
+ #layout = null;
40
+ #controller;
41
+ #mutation;
42
+ #intersection;
43
+ #narrow;
44
+ #reducedMotion;
45
+ #frame = 0;
46
+ #near = false;
47
+ #index = -1;
48
+ #token = 0;
49
+ #fade = [];
50
+ #stage = null;
51
+ constructor() {
52
+ super();
53
+ const shadow = this.attachShadow({ mode: 'open' });
54
+ adoptStyles(shadow);
55
+ this.#root = element('div', 'root');
56
+ shadow.append(this.#root);
57
+ }
58
+ get layout() {
59
+ return this.#layout;
60
+ }
61
+ get index() {
62
+ return this.#index;
63
+ }
64
+ connectedCallback() {
65
+ this.#controller?.abort();
66
+ this.#controller = new AbortController();
67
+ const { signal } = this.#controller;
68
+ this.#narrow = matchMedia(NARROW);
69
+ this.#reducedMotion = matchMedia('(prefers-reduced-motion: reduce)');
70
+ this.#narrow.addEventListener('change', () => this.#render(), { signal });
71
+ this.#reducedMotion.addEventListener('change', () => this.#render(), { signal });
72
+ window.addEventListener('scroll', () => this.#schedule(), { passive: true, signal });
73
+ window.addEventListener('resize', () => this.#schedule(), { passive: true, signal });
74
+ this.#mutation = new MutationObserver(() => this.#render());
75
+ this.#mutation.observe(this, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ['title'] });
76
+ if (document.readyState === 'loading') {
77
+ document.addEventListener('DOMContentLoaded', () => this.#render(), { once: true, signal });
78
+ }
79
+ this.#render();
80
+ }
81
+ disconnectedCallback() {
82
+ this.#controller?.abort();
83
+ this.#controller = undefined;
84
+ this.#mutation?.disconnect();
85
+ this.#mutation = undefined;
86
+ this.#intersection?.disconnect();
87
+ this.#intersection = undefined;
88
+ cancelAnimationFrame(this.#frame);
89
+ this.#frame = 0;
90
+ this.#stopFade();
91
+ }
92
+ attributeChangedCallback(_name, previous, value) {
93
+ if (previous !== value && this.isConnected)
94
+ this.#render();
95
+ }
96
+ #readSteps() {
97
+ return Array.from(this.children)
98
+ .filter((child) => child.localName === ITEM_TAG)
99
+ .map((item) => ({
100
+ title: item.getAttribute('title')?.trim() ?? '',
101
+ content: Array.from(item.childNodes),
102
+ }));
103
+ }
104
+ #render() {
105
+ this.#intersection?.disconnect();
106
+ this.#intersection = undefined;
107
+ cancelAnimationFrame(this.#frame);
108
+ this.#frame = 0;
109
+ this.#stopFade();
110
+ this.#stage = null;
111
+ this.#index = -1;
112
+ this.#near = false;
113
+ this.#steps = this.#readSteps();
114
+ const layout = resolveLayout(readMode(this.getAttribute('mode')), this.#narrow?.matches ?? false, this.#reducedMotion?.matches ?? false);
115
+ this.#layout = layout;
116
+ if (this.getAttribute('layout') !== layout)
117
+ this.setAttribute('layout', layout);
118
+ this.#root.replaceChildren();
119
+ this.#root.style.setProperty('--count', String(Math.max(1, this.#steps.length)));
120
+ if (!this.#steps.length)
121
+ return;
122
+ if (layout === 'pinned')
123
+ this.#renderPinned();
124
+ else
125
+ this.#renderList(layout);
126
+ }
127
+ #stepList(className, part) {
128
+ const list = element('ol', className, part);
129
+ list.setAttribute('role', 'list');
130
+ this.#steps.forEach((step, index) => {
131
+ const item = element('li', 'step', 'step');
132
+ item.style.setProperty('--i', String(index));
133
+ const number = element('span', 'number', 'number');
134
+ number.textContent = pad(index + 1);
135
+ number.setAttribute('aria-hidden', 'true');
136
+ const title = element('p', 'title', 'title');
137
+ title.textContent = step.title;
138
+ const text = element('div', 'text', 'text');
139
+ text.append(...step.content.map((node) => node.cloneNode(true)));
140
+ item.append(number, title, text);
141
+ list.append(item);
142
+ });
143
+ return list;
144
+ }
145
+ #renderList(layout) {
146
+ const list = this.#stepList(layout === 'list' ? 'steps list revealed' : 'steps', 'steps');
147
+ this.#root.append(list);
148
+ if (layout === 'list')
149
+ return;
150
+ if (this.#reducedMotion?.matches || !('IntersectionObserver' in window)) {
151
+ list.classList.add('revealed');
152
+ return;
153
+ }
154
+ this.#intersection = new IntersectionObserver((entries) => {
155
+ if (!entries.some((entry) => entry.isIntersecting))
156
+ return;
157
+ list.classList.add('revealed');
158
+ this.#intersection?.disconnect();
159
+ this.#intersection = undefined;
160
+ }, { threshold: REVEAL_THRESHOLD });
161
+ this.#intersection.observe(list);
162
+ }
163
+ #renderPinned() {
164
+ const pinned = element('div', 'pinned', 'pinned');
165
+ pinned.style.setProperty('--step-height', readStepHeight(this.getAttribute('step-height')));
166
+ const stage = element('div', 'stage', 'stage');
167
+ const meter = element('div', 'meter', 'meter');
168
+ meter.setAttribute('aria-hidden', 'true');
169
+ const counter = element('p', 'counter', 'counter');
170
+ const current = element('span', 'current');
171
+ current.textContent = pad(1);
172
+ const total = element('span', 'total');
173
+ total.textContent = ` / ${pad(this.#steps.length)}`;
174
+ counter.append(current, total);
175
+ const bar = element('div', 'bar', 'bar');
176
+ const fill = element('span', 'bar-fill');
177
+ bar.append(fill);
178
+ meter.append(counter, bar);
179
+ const active = element('div', 'active', 'active');
180
+ active.setAttribute('aria-live', 'polite');
181
+ stage.append(meter, active);
182
+ pinned.append(stage, this.#stepList('visually-hidden'));
183
+ this.#root.append(pinned);
184
+ this.#stage = { pinned, current, fill, active };
185
+ if ('IntersectionObserver' in window) {
186
+ this.#intersection = new IntersectionObserver((entries) => {
187
+ this.#near = entries.some((entry) => entry.isIntersecting);
188
+ if (this.#near)
189
+ this.#schedule();
190
+ });
191
+ this.#intersection.observe(pinned);
192
+ }
193
+ else {
194
+ this.#near = true;
195
+ }
196
+ this.#update();
197
+ }
198
+ #schedule() {
199
+ if (this.#frame || !this.#stage || !this.#near)
200
+ return;
201
+ this.#frame = requestAnimationFrame(() => {
202
+ this.#frame = 0;
203
+ this.#update();
204
+ });
205
+ }
206
+ #update() {
207
+ const stage = this.#stage;
208
+ if (!stage)
209
+ return;
210
+ const rect = stage.pinned.getBoundingClientRect();
211
+ const stageHeight = stage.pinned.firstElementChild?.offsetHeight ?? window.innerHeight;
212
+ const progress = scrollProgress(rect.top, rect.height, stageHeight);
213
+ stage.fill.style.transform = `scaleX(${progress})`;
214
+ this.#show(activeIndex(progress, this.#steps.length));
215
+ }
216
+ #fill(target, index) {
217
+ const step = this.#steps[index];
218
+ const title = element('p', 'title', 'title');
219
+ title.textContent = step.title;
220
+ const text = element('div', 'text', 'text');
221
+ text.append(...step.content.map((node) => node.cloneNode(true)));
222
+ target.replaceChildren(title, text);
223
+ }
224
+ #stopFade() {
225
+ this.#token++;
226
+ this.#fade.forEach((animation) => animation.cancel());
227
+ this.#fade = [];
228
+ }
229
+ #show(index) {
230
+ const stage = this.#stage;
231
+ if (!stage || index === this.#index || index < 0)
232
+ return;
233
+ const first = this.#index === -1;
234
+ this.#index = index;
235
+ stage.current.textContent = pad(index + 1);
236
+ this.dispatchEvent(new CustomEvent('stepchange', {
237
+ bubbles: true,
238
+ detail: { index, title: this.#steps[index].title },
239
+ }));
240
+ this.#stopFade();
241
+ if (first || typeof stage.active.animate !== 'function') {
242
+ this.#fill(stage.active, index);
243
+ return;
244
+ }
245
+ const token = this.#token;
246
+ const out = stage.active.animate([{ opacity: 1 }, { opacity: 0 }], { duration: FADE_OUT, easing: 'ease-in', fill: 'forwards' });
247
+ this.#fade = [out];
248
+ out.finished
249
+ .then(() => {
250
+ if (token !== this.#token)
251
+ return;
252
+ this.#fill(stage.active, index);
253
+ out.cancel();
254
+ const fadeIn = stage.active.animate([
255
+ { opacity: 0, transform: 'translateY(8px)' },
256
+ { opacity: 1, transform: 'none' },
257
+ ], { duration: FADE_IN, easing: 'cubic-bezier(.2, .7, .2, 1)' });
258
+ this.#fade = [fadeIn];
259
+ })
260
+ .catch(() => {
261
+ if (token === this.#token)
262
+ this.#fill(stage.active, index);
263
+ });
264
+ }
265
+ }
266
+ if (typeof customElements !== 'undefined') {
267
+ if (!customElements.get(ITEM_TAG))
268
+ customElements.define(ITEM_TAG, StepItem);
269
+ if (!customElements.get(TAG))
270
+ customElements.define(TAG, StepTimeline);
271
+ }
@@ -0,0 +1,8 @@
1
+ export type Mode = 'reveal' | 'pinned';
2
+ export type Layout = Mode | 'list';
3
+ export declare const pad: (value: number) => string;
4
+ export declare const readMode: (value: string | null | undefined) => Mode;
5
+ export declare const readStepHeight: (value: string | null | undefined, fallback?: string) => string;
6
+ export declare const resolveLayout: (mode: Mode, narrow: boolean, reducedMotion: boolean) => Layout;
7
+ export declare const scrollProgress: (top: number, height: number, viewport: number) => number;
8
+ export declare const activeIndex: (progress: number, count: number) => number;
package/dist/steps.js ADDED
@@ -0,0 +1,19 @@
1
+ const LENGTH = /^\d+(\.\d+)?(px|vh|svh|lvh|dvh|rem|em)$/;
2
+ export const pad = (value) => String(value).padStart(2, '0');
3
+ export const readMode = (value) => (value === 'pinned' ? 'pinned' : 'reveal');
4
+ export const readStepHeight = (value, fallback = '70vh') => {
5
+ const trimmed = value?.trim().toLowerCase();
6
+ return trimmed && LENGTH.test(trimmed) ? trimmed : fallback;
7
+ };
8
+ export const resolveLayout = (mode, narrow, reducedMotion) => mode === 'pinned' && (narrow || reducedMotion) ? 'list' : mode;
9
+ export const scrollProgress = (top, height, viewport) => {
10
+ const distance = height - viewport;
11
+ if (distance <= 0)
12
+ return top <= 0 ? 1 : 0;
13
+ return Math.min(1, Math.max(0, -top / distance));
14
+ };
15
+ export const activeIndex = (progress, count) => {
16
+ if (count <= 0)
17
+ return -1;
18
+ return Math.min(count - 1, Math.max(0, Math.floor(progress * count)));
19
+ };
@@ -0,0 +1 @@
1
+ export declare const styles = "\n :host {\n \n --_accent: var(--step-accent, #1d8049);\n --_text: var(--step-text, #0d1310);\n --_muted: var(--step-muted, #4a5650);\n --_border: var(--step-border, #c3ccc6);\n --_bg: var(--step-bg, #f6f8f6);\n\n --_font: var(--step-font, inherit);\n --_mono: var(--step-mono-font, ui-monospace, 'JetBrains Mono', Menlo, Consolas, monospace);\n --_gap: var(--step-gap, 32px);\n --_circle: var(--step-circle-size, 40px);\n --_stagger: var(--step-stagger, 0.45s);\n --_title-size: var(--step-title-size, 18px);\n --_text-size: var(--step-text-size, 15px);\n --_counter-size: var(--step-counter-size, clamp(3rem, 8vw, 6rem));\n --_sticky-top: var(--step-sticky-top, 0px);\n display: block;\n container-type: inline-size;\n color: var(--_text);\n font-family: var(--_font);\n line-height: 1.5;\n }\n\n :host([theme='dark']) {\n \n --_accent: var(--step-accent, #43c97e);\n --_text: var(--step-text, #e9eeea);\n --_muted: var(--step-muted, #a3ada6);\n --_border: var(--step-border, #2c352f);\n --_bg: var(--step-bg, #0b0e0c);\n\n }\n\n @media (prefers-color-scheme: dark) {\n :host(:not([theme='light'])) {\n \n --_accent: var(--step-accent, #43c97e);\n --_text: var(--step-text, #e9eeea);\n --_muted: var(--step-muted, #a3ada6);\n --_border: var(--step-border, #2c352f);\n --_bg: var(--step-bg, #0b0e0c);\n\n }\n }\n\n :host([hidden]) {\n display: none;\n }\n\n *,\n *::before,\n *::after {\n box-sizing: border-box;\n }\n\n .steps {\n display: grid;\n grid-template-columns: repeat(var(--count), minmax(0, 1fr));\n gap: var(--_gap);\n margin: 0;\n padding: 0;\n list-style: none;\n }\n\n .step {\n position: relative;\n min-width: 0;\n }\n\n .number {\n position: relative;\n z-index: 1;\n display: grid;\n place-items: center;\n width: var(--_circle);\n height: var(--_circle);\n margin-bottom: 20px;\n border: 1px solid var(--_border);\n border-radius: 50%;\n background: var(--_bg);\n color: var(--_muted);\n font-family: var(--_mono);\n font-size: 13px;\n font-weight: 500;\n line-height: 1;\n transition:\n color 0.3s ease,\n border-color 0.3s ease;\n transition-delay: calc(var(--i) * var(--_stagger));\n }\n\n .step:not(:last-child)::before,\n .step:not(:last-child)::after {\n content: '';\n position: absolute;\n top: calc(var(--_circle) / 2 - 1px);\n left: var(--_circle);\n right: calc(-1 * var(--_gap));\n height: 2px;\n }\n\n .step:not(:last-child)::before {\n background: var(--_border);\n }\n\n .step:not(:last-child)::after {\n background: var(--_accent);\n transform: scaleX(0);\n transform-origin: left center;\n transition: transform calc(var(--_stagger) - 0.1s) ease-in-out;\n transition-delay: calc(var(--i) * var(--_stagger) + 0.1s);\n }\n\n .revealed .number {\n border-color: var(--_accent);\n color: var(--_accent);\n }\n\n .title {\n margin: 0 0 6px;\n color: var(--_text);\n font-size: var(--_title-size);\n font-weight: 600;\n line-height: 1.3;\n }\n\n .text {\n color: var(--_muted);\n font-size: var(--_text-size);\n }\n\n .text > :first-child {\n margin-top: 0;\n }\n\n .text > :last-child {\n margin-bottom: 0;\n }\n\n @container (max-width: 639px) {\n .steps {\n grid-template-columns: minmax(0, 1fr);\n }\n\n .step {\n padding-left: calc(var(--_circle) + 20px);\n min-height: var(--_circle);\n }\n\n .number {\n position: absolute;\n top: 0;\n left: 0;\n margin: 0;\n }\n\n .title {\n padding-top: calc((var(--_circle) - var(--_title-size) * 1.3) / 2);\n }\n\n .step:not(:last-child)::before,\n .step:not(:last-child)::after {\n top: var(--_circle);\n right: auto;\n bottom: calc(-1 * var(--_gap));\n left: calc(var(--_circle) / 2 - 1px);\n width: 2px;\n height: auto;\n }\n\n .step:not(:last-child)::after {\n transform: scaleY(0);\n transform-origin: center top;\n }\n }\n\n .steps.list {\n grid-template-columns: minmax(0, 1fr);\n }\n\n .list .step {\n padding-left: calc(var(--_circle) + 20px);\n min-height: var(--_circle);\n }\n\n .list .number {\n position: absolute;\n top: 0;\n left: 0;\n margin: 0;\n }\n\n .list .title {\n padding-top: calc((var(--_circle) - var(--_title-size) * 1.3) / 2);\n }\n\n .list .step:not(:last-child)::before,\n .list .step:not(:last-child)::after {\n top: var(--_circle);\n right: auto;\n bottom: calc(-1 * var(--_gap));\n left: calc(var(--_circle) / 2 - 1px);\n width: 2px;\n height: auto;\n }\n\n .list .step:not(:last-child)::after {\n transform: scaleY(0);\n transform-origin: center top;\n }\n\n .list .step::after,\n .list .number {\n transition: none;\n }\n\n .revealed .step:not(:last-child)::after {\n transform: none;\n }\n\n .pinned {\n position: relative;\n height: calc(var(--count) * var(--step-height));\n }\n\n .stage {\n position: sticky;\n top: var(--_sticky-top);\n display: grid;\n grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);\n align-items: center;\n gap: calc(var(--_gap) * 1.5);\n height: calc(100svh - var(--_sticky-top));\n }\n\n .counter {\n margin: 0;\n font-family: var(--_mono);\n font-size: var(--_counter-size);\n font-weight: 500;\n line-height: 1;\n letter-spacing: -0.04em;\n word-spacing: -0.4em;\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n .total {\n color: var(--_muted);\n opacity: 0.6;\n }\n\n .bar {\n position: relative;\n height: 2px;\n max-width: 280px;\n margin-top: 28px;\n background: var(--_border);\n overflow: hidden;\n }\n\n .bar-fill {\n position: absolute;\n inset: 0;\n background: var(--_accent);\n transform: scaleX(0);\n transform-origin: left center;\n }\n\n .active .title {\n margin-bottom: 12px;\n font-size: var(--step-active-title-size, clamp(1.5rem, 2.6vw, 2.25rem));\n line-height: 1.2;\n letter-spacing: -0.02em;\n }\n\n .active .text {\n max-width: 46ch;\n font-size: var(--step-active-text-size, 18px);\n }\n\n .visually-hidden {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0 0 0 0);\n white-space: nowrap;\n border: 0;\n }\n\n @media (prefers-reduced-motion: reduce) {\n .number,\n .step::after {\n transition: none !important;\n }\n }\n";
package/dist/styles.js ADDED
@@ -0,0 +1,298 @@
1
+ const light = `
2
+ --_accent: var(--step-accent, #1d8049);
3
+ --_text: var(--step-text, #0d1310);
4
+ --_muted: var(--step-muted, #4a5650);
5
+ --_border: var(--step-border, #c3ccc6);
6
+ --_bg: var(--step-bg, #f6f8f6);
7
+ `;
8
+ const dark = `
9
+ --_accent: var(--step-accent, #43c97e);
10
+ --_text: var(--step-text, #e9eeea);
11
+ --_muted: var(--step-muted, #a3ada6);
12
+ --_border: var(--step-border, #2c352f);
13
+ --_bg: var(--step-bg, #0b0e0c);
14
+ `;
15
+ export const styles = `
16
+ :host {
17
+ ${light}
18
+ --_font: var(--step-font, inherit);
19
+ --_mono: var(--step-mono-font, ui-monospace, 'JetBrains Mono', Menlo, Consolas, monospace);
20
+ --_gap: var(--step-gap, 32px);
21
+ --_circle: var(--step-circle-size, 40px);
22
+ --_stagger: var(--step-stagger, 0.45s);
23
+ --_title-size: var(--step-title-size, 18px);
24
+ --_text-size: var(--step-text-size, 15px);
25
+ --_counter-size: var(--step-counter-size, clamp(3rem, 8vw, 6rem));
26
+ --_sticky-top: var(--step-sticky-top, 0px);
27
+ display: block;
28
+ container-type: inline-size;
29
+ color: var(--_text);
30
+ font-family: var(--_font);
31
+ line-height: 1.5;
32
+ }
33
+
34
+ :host([theme='dark']) {
35
+ ${dark}
36
+ }
37
+
38
+ @media (prefers-color-scheme: dark) {
39
+ :host(:not([theme='light'])) {
40
+ ${dark}
41
+ }
42
+ }
43
+
44
+ :host([hidden]) {
45
+ display: none;
46
+ }
47
+
48
+ *,
49
+ *::before,
50
+ *::after {
51
+ box-sizing: border-box;
52
+ }
53
+
54
+ .steps {
55
+ display: grid;
56
+ grid-template-columns: repeat(var(--count), minmax(0, 1fr));
57
+ gap: var(--_gap);
58
+ margin: 0;
59
+ padding: 0;
60
+ list-style: none;
61
+ }
62
+
63
+ .step {
64
+ position: relative;
65
+ min-width: 0;
66
+ }
67
+
68
+ .number {
69
+ position: relative;
70
+ z-index: 1;
71
+ display: grid;
72
+ place-items: center;
73
+ width: var(--_circle);
74
+ height: var(--_circle);
75
+ margin-bottom: 20px;
76
+ border: 1px solid var(--_border);
77
+ border-radius: 50%;
78
+ background: var(--_bg);
79
+ color: var(--_muted);
80
+ font-family: var(--_mono);
81
+ font-size: 13px;
82
+ font-weight: 500;
83
+ line-height: 1;
84
+ transition:
85
+ color 0.3s ease,
86
+ border-color 0.3s ease;
87
+ transition-delay: calc(var(--i) * var(--_stagger));
88
+ }
89
+
90
+ .step:not(:last-child)::before,
91
+ .step:not(:last-child)::after {
92
+ content: '';
93
+ position: absolute;
94
+ top: calc(var(--_circle) / 2 - 1px);
95
+ left: var(--_circle);
96
+ right: calc(-1 * var(--_gap));
97
+ height: 2px;
98
+ }
99
+
100
+ .step:not(:last-child)::before {
101
+ background: var(--_border);
102
+ }
103
+
104
+ .step:not(:last-child)::after {
105
+ background: var(--_accent);
106
+ transform: scaleX(0);
107
+ transform-origin: left center;
108
+ transition: transform calc(var(--_stagger) - 0.1s) ease-in-out;
109
+ transition-delay: calc(var(--i) * var(--_stagger) + 0.1s);
110
+ }
111
+
112
+ .revealed .number {
113
+ border-color: var(--_accent);
114
+ color: var(--_accent);
115
+ }
116
+
117
+ .title {
118
+ margin: 0 0 6px;
119
+ color: var(--_text);
120
+ font-size: var(--_title-size);
121
+ font-weight: 600;
122
+ line-height: 1.3;
123
+ }
124
+
125
+ .text {
126
+ color: var(--_muted);
127
+ font-size: var(--_text-size);
128
+ }
129
+
130
+ .text > :first-child {
131
+ margin-top: 0;
132
+ }
133
+
134
+ .text > :last-child {
135
+ margin-bottom: 0;
136
+ }
137
+
138
+ @container (max-width: 639px) {
139
+ .steps {
140
+ grid-template-columns: minmax(0, 1fr);
141
+ }
142
+
143
+ .step {
144
+ padding-left: calc(var(--_circle) + 20px);
145
+ min-height: var(--_circle);
146
+ }
147
+
148
+ .number {
149
+ position: absolute;
150
+ top: 0;
151
+ left: 0;
152
+ margin: 0;
153
+ }
154
+
155
+ .title {
156
+ padding-top: calc((var(--_circle) - var(--_title-size) * 1.3) / 2);
157
+ }
158
+
159
+ .step:not(:last-child)::before,
160
+ .step:not(:last-child)::after {
161
+ top: var(--_circle);
162
+ right: auto;
163
+ bottom: calc(-1 * var(--_gap));
164
+ left: calc(var(--_circle) / 2 - 1px);
165
+ width: 2px;
166
+ height: auto;
167
+ }
168
+
169
+ .step:not(:last-child)::after {
170
+ transform: scaleY(0);
171
+ transform-origin: center top;
172
+ }
173
+ }
174
+
175
+ .steps.list {
176
+ grid-template-columns: minmax(0, 1fr);
177
+ }
178
+
179
+ .list .step {
180
+ padding-left: calc(var(--_circle) + 20px);
181
+ min-height: var(--_circle);
182
+ }
183
+
184
+ .list .number {
185
+ position: absolute;
186
+ top: 0;
187
+ left: 0;
188
+ margin: 0;
189
+ }
190
+
191
+ .list .title {
192
+ padding-top: calc((var(--_circle) - var(--_title-size) * 1.3) / 2);
193
+ }
194
+
195
+ .list .step:not(:last-child)::before,
196
+ .list .step:not(:last-child)::after {
197
+ top: var(--_circle);
198
+ right: auto;
199
+ bottom: calc(-1 * var(--_gap));
200
+ left: calc(var(--_circle) / 2 - 1px);
201
+ width: 2px;
202
+ height: auto;
203
+ }
204
+
205
+ .list .step:not(:last-child)::after {
206
+ transform: scaleY(0);
207
+ transform-origin: center top;
208
+ }
209
+
210
+ .list .step::after,
211
+ .list .number {
212
+ transition: none;
213
+ }
214
+
215
+ .revealed .step:not(:last-child)::after {
216
+ transform: none;
217
+ }
218
+
219
+ .pinned {
220
+ position: relative;
221
+ height: calc(var(--count) * var(--step-height));
222
+ }
223
+
224
+ .stage {
225
+ position: sticky;
226
+ top: var(--_sticky-top);
227
+ display: grid;
228
+ grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
229
+ align-items: center;
230
+ gap: calc(var(--_gap) * 1.5);
231
+ height: calc(100svh - var(--_sticky-top));
232
+ }
233
+
234
+ .counter {
235
+ margin: 0;
236
+ font-family: var(--_mono);
237
+ font-size: var(--_counter-size);
238
+ font-weight: 500;
239
+ line-height: 1;
240
+ letter-spacing: -0.04em;
241
+ word-spacing: -0.4em;
242
+ font-variant-numeric: tabular-nums;
243
+ white-space: nowrap;
244
+ }
245
+
246
+ .total {
247
+ color: var(--_muted);
248
+ opacity: 0.6;
249
+ }
250
+
251
+ .bar {
252
+ position: relative;
253
+ height: 2px;
254
+ max-width: 280px;
255
+ margin-top: 28px;
256
+ background: var(--_border);
257
+ overflow: hidden;
258
+ }
259
+
260
+ .bar-fill {
261
+ position: absolute;
262
+ inset: 0;
263
+ background: var(--_accent);
264
+ transform: scaleX(0);
265
+ transform-origin: left center;
266
+ }
267
+
268
+ .active .title {
269
+ margin-bottom: 12px;
270
+ font-size: var(--step-active-title-size, clamp(1.5rem, 2.6vw, 2.25rem));
271
+ line-height: 1.2;
272
+ letter-spacing: -0.02em;
273
+ }
274
+
275
+ .active .text {
276
+ max-width: 46ch;
277
+ font-size: var(--step-active-text-size, 18px);
278
+ }
279
+
280
+ .visually-hidden {
281
+ position: absolute;
282
+ width: 1px;
283
+ height: 1px;
284
+ margin: -1px;
285
+ padding: 0;
286
+ overflow: hidden;
287
+ clip: rect(0 0 0 0);
288
+ white-space: nowrap;
289
+ border: 0;
290
+ }
291
+
292
+ @media (prefers-reduced-motion: reduce) {
293
+ .number,
294
+ .step::after {
295
+ transition: none !important;
296
+ }
297
+ }
298
+ `;
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
- {
2
- "name": "@georgepxto/step-timeline",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@georgepxto/step-timeline",
3
+ "version": "0.1.0",
4
+ "description": "A dependency-free <step-timeline> web component: process steps that fill in sequence when they come into view, or pin to the screen and advance as the page scrolls.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "georgepxto",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/georgepxto/web-components.git",
11
+ "directory": "step-timeline"
12
+ },
13
+ "keywords": [
14
+ "web-component",
15
+ "custom-element",
16
+ "timeline",
17
+ "steps",
18
+ "process",
19
+ "scrollytelling"
20
+ ],
21
+ "main": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "sideEffects": [
33
+ "./dist/index.js",
34
+ "./dist/step-timeline.js"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsc -p tsconfig.json",
38
+ "test": "npm run build && node --test test/*.test.js",
39
+ "prepublishOnly": "npm test"
40
+ },
41
+ "devDependencies": {
42
+ "typescript": "^7.0.2"
43
+ }
44
+ }