@uibit/scroll-progress 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 +21 -0
- package/README.md +27 -0
- package/custom-elements.json +198 -0
- package/dist/frameworks/angular/index.ts +21 -0
- package/dist/frameworks/astro/index.d.ts +10 -0
- package/dist/frameworks/nuxt/index.ts +7 -0
- package/dist/frameworks/preact/index.d.ts +13 -0
- package/dist/frameworks/qwik/index.tsx +10 -0
- package/dist/frameworks/react/index.d.ts +17 -0
- package/dist/frameworks/solid/index.d.ts +14 -0
- package/dist/frameworks/stencil/index.d.ts +12 -0
- package/dist/frameworks/svelte/index.svelte +31 -0
- package/dist/frameworks/vue/index.ts +22 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/scroll-progress.d.ts +27 -0
- package/dist/scroll-progress.d.ts.map +1 -0
- package/dist/scroll-progress.js +111 -0
- package/dist/scroll-progress.js.map +1 -0
- package/dist/styles.d.ts +2 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +17 -0
- package/dist/styles.js.map +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 UIBit Contributors
|
|
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
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Scroll Progress
|
|
2
|
+
|
|
3
|
+
[Interactive Demonstration](https://rawlings.github.io/uibit/components/scroll-progress)
|
|
4
|
+
|
|
5
|
+
Scroll Progress is a reading indicator component that displays content navigation progress. As users scroll through long-form articles, documentation, or reports, a subtle progress indicator shows their position, providing context and encouraging reading completion.
|
|
6
|
+
|
|
7
|
+
## Value Delivery
|
|
8
|
+
|
|
9
|
+
- **Reading Context** – Provides users with a clear sense of remaining content length, improving completion rates on long pages.
|
|
10
|
+
- **Subtle Visual Feedback** – Quietly tracks reading position at the top or bottom of the viewport without distracting from the text.
|
|
11
|
+
- **Hardware Accelerated Performance** – Optimizes scroll listener logic and rendering to prevent browser layout thrashing or stuttering.
|
|
12
|
+
- **Adaptive Layout Support** – Automatically recalibrates dimensions when dynamic content loads or screen sizes resize.
|
|
13
|
+
|
|
14
|
+
## Ideal Applications
|
|
15
|
+
|
|
16
|
+
- **Long-Form Articles & Editorial Pages** – Enhancing user engagement on blogs, news portals, and feature pieces.
|
|
17
|
+
- **Technical Documentation** – Helping users track their progress through guides and references.
|
|
18
|
+
- **Annual Reports & Case Studies** – Providing orientation for data-heavy corporate communications.
|
|
19
|
+
|
|
20
|
+
## Further Information
|
|
21
|
+
|
|
22
|
+
Detailed design guidelines, customizable attributes, and integration examples are available on our documentation site.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Changelog
|
|
26
|
+
|
|
27
|
+
Please see the [Changelog](CHANGELOG.md) for version history.
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": "1.0.0",
|
|
3
|
+
"readme": "",
|
|
4
|
+
"modules": [
|
|
5
|
+
{
|
|
6
|
+
"kind": "javascript-module",
|
|
7
|
+
"path": "src/index.ts",
|
|
8
|
+
"declarations": [],
|
|
9
|
+
"exports": [
|
|
10
|
+
{
|
|
11
|
+
"kind": "js",
|
|
12
|
+
"name": "default",
|
|
13
|
+
"declaration": {
|
|
14
|
+
"name": "default",
|
|
15
|
+
"module": "./scroll-progress"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"kind": "js",
|
|
20
|
+
"name": "ScrollProgress",
|
|
21
|
+
"declaration": {
|
|
22
|
+
"name": "ScrollProgress",
|
|
23
|
+
"module": "./scroll-progress"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"kind": "js",
|
|
28
|
+
"name": "ScrollProgressConfig",
|
|
29
|
+
"declaration": {
|
|
30
|
+
"name": "ScrollProgressConfig",
|
|
31
|
+
"module": "./types"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"kind": "javascript-module",
|
|
38
|
+
"path": "src/scroll-progress.ts",
|
|
39
|
+
"declarations": [
|
|
40
|
+
{
|
|
41
|
+
"kind": "class",
|
|
42
|
+
"description": "Thin progress bar that tracks scroll position — either the page or a\ncustom scrollable element — and fills as the user scrolls down.",
|
|
43
|
+
"name": "ScrollProgress",
|
|
44
|
+
"cssProperties": [
|
|
45
|
+
{
|
|
46
|
+
"description": "Height of the progress bar",
|
|
47
|
+
"name": "--uibit-scroll-progress-height",
|
|
48
|
+
"default": "0.1875rem"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"description": "Background (track) color",
|
|
52
|
+
"name": "--uibit-scroll-progress-bg",
|
|
53
|
+
"default": "transparent"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"description": "Fill color of the progress indicator",
|
|
57
|
+
"name": "--uibit-scroll-progress-color",
|
|
58
|
+
"default": "#000000"
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"members": [
|
|
62
|
+
{
|
|
63
|
+
"kind": "field",
|
|
64
|
+
"name": "targetSelector",
|
|
65
|
+
"type": {
|
|
66
|
+
"text": "string | undefined"
|
|
67
|
+
},
|
|
68
|
+
"description": "CSS selector of a custom scrollable container to track. Defaults to the page (`window`).",
|
|
69
|
+
"attribute": "target-selector"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"kind": "field",
|
|
73
|
+
"name": "progressPercent",
|
|
74
|
+
"type": {
|
|
75
|
+
"text": "number"
|
|
76
|
+
},
|
|
77
|
+
"privacy": "private",
|
|
78
|
+
"default": "0"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"kind": "field",
|
|
82
|
+
"name": "_scrollUnlisten",
|
|
83
|
+
"type": {
|
|
84
|
+
"text": "() => void | undefined"
|
|
85
|
+
},
|
|
86
|
+
"privacy": "private"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"kind": "field",
|
|
90
|
+
"name": "_cachedTarget",
|
|
91
|
+
"type": {
|
|
92
|
+
"text": "HTMLElement | Window | undefined"
|
|
93
|
+
},
|
|
94
|
+
"privacy": "private"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"kind": "field",
|
|
98
|
+
"name": "_rafId",
|
|
99
|
+
"type": {
|
|
100
|
+
"text": "number | undefined"
|
|
101
|
+
},
|
|
102
|
+
"privacy": "private"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"kind": "method",
|
|
106
|
+
"name": "_getTargetElement",
|
|
107
|
+
"privacy": "private",
|
|
108
|
+
"return": {
|
|
109
|
+
"type": {
|
|
110
|
+
"text": "HTMLElement | Window"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"kind": "method",
|
|
116
|
+
"name": "_attachScrollListener",
|
|
117
|
+
"privacy": "private"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"kind": "method",
|
|
121
|
+
"name": "updateProgress",
|
|
122
|
+
"privacy": "private"
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
"attributes": [
|
|
126
|
+
{
|
|
127
|
+
"name": "target-selector",
|
|
128
|
+
"type": {
|
|
129
|
+
"text": "string | undefined"
|
|
130
|
+
},
|
|
131
|
+
"description": "CSS selector of a custom scrollable container to track. Defaults to the page (`window`).",
|
|
132
|
+
"fieldName": "targetSelector"
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
"superclass": {
|
|
136
|
+
"name": "UIBitElement",
|
|
137
|
+
"package": "@uibit/core"
|
|
138
|
+
},
|
|
139
|
+
"tagName": "uibit-scroll-progress",
|
|
140
|
+
"customElement": true
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
"exports": [
|
|
144
|
+
{
|
|
145
|
+
"kind": "js",
|
|
146
|
+
"name": "ScrollProgress",
|
|
147
|
+
"declaration": {
|
|
148
|
+
"name": "ScrollProgress",
|
|
149
|
+
"module": "src/scroll-progress.ts"
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"kind": "custom-element-definition",
|
|
154
|
+
"name": "uibit-scroll-progress",
|
|
155
|
+
"declaration": {
|
|
156
|
+
"name": "ScrollProgress",
|
|
157
|
+
"module": "src/scroll-progress.ts"
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"kind": "js",
|
|
162
|
+
"name": "default",
|
|
163
|
+
"declaration": {
|
|
164
|
+
"name": "ScrollProgress",
|
|
165
|
+
"module": "src/scroll-progress.ts"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"kind": "javascript-module",
|
|
172
|
+
"path": "src/styles.ts",
|
|
173
|
+
"declarations": [
|
|
174
|
+
{
|
|
175
|
+
"kind": "variable",
|
|
176
|
+
"name": "styles",
|
|
177
|
+
"default": "css` :host { display: block; width: 100%; height: var(--uibit-scroll-progress-height, 0.1875rem); background: var(--uibit-scroll-progress-bg, transparent); } .progress { height: 100%; background: var(--uibit-scroll-progress-color, var(--uibit-focus-color, var(--uibit-color-black, #000000))); width: 0%; transition: width 150ms ease; } `"
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
"exports": [
|
|
181
|
+
{
|
|
182
|
+
"kind": "js",
|
|
183
|
+
"name": "styles",
|
|
184
|
+
"declaration": {
|
|
185
|
+
"name": "styles",
|
|
186
|
+
"module": "src/styles.ts"
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"kind": "javascript-module",
|
|
193
|
+
"path": "src/types.ts",
|
|
194
|
+
"declarations": [],
|
|
195
|
+
"exports": []
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Component, ChangeDetectionStrategy, ElementRef, input, effect } from '@angular/core';
|
|
2
|
+
import '@uibit/scroll-progress';
|
|
3
|
+
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
4
|
+
|
|
5
|
+
@Component({
|
|
6
|
+
selector: 'uibit-scroll-progress',
|
|
7
|
+
template: '<ng-content></ng-content>',
|
|
8
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
9
|
+
standalone: true
|
|
10
|
+
})
|
|
11
|
+
export class NgxScrollProgress {
|
|
12
|
+
constructor(private el: ElementRef<HTMLElementClass>) {
|
|
13
|
+
effect(() => {
|
|
14
|
+
if (this.el.nativeElement) {
|
|
15
|
+
this.el.nativeElement.targetSelector = this.targetSelector();
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
readonly targetSelector = input<string | undefined, any>('');
|
|
21
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
2
|
+
import '@uibit/scroll-progress';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
namespace astroHTML.JSX {
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
'uibit-scroll-progress': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JSX } from 'preact';
|
|
2
|
+
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
3
|
+
import '@uibit/scroll-progress';
|
|
4
|
+
|
|
5
|
+
declare module 'preact' {
|
|
6
|
+
namespace JSX {
|
|
7
|
+
interface IntrinsicElements {
|
|
8
|
+
'uibit-scroll-progress': JSX.HTMLAttributes<HTMLElementClass> & {
|
|
9
|
+
targetSelector?: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HTMLAttributes, ClassAttributes } from 'react';
|
|
2
|
+
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
3
|
+
import '@uibit/scroll-progress';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
namespace React {
|
|
7
|
+
namespace JSX {
|
|
8
|
+
interface IntrinsicElements {
|
|
9
|
+
'uibit-scroll-progress': ClassAttributes<HTMLElementClass> & HTMLAttributes<HTMLElementClass> & {
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
class?: string;
|
|
12
|
+
targetSelector?: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { JSX } from 'solid-js';
|
|
2
|
+
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
3
|
+
import '@uibit/scroll-progress';
|
|
4
|
+
|
|
5
|
+
declare module 'solid-js' {
|
|
6
|
+
namespace JSX {
|
|
7
|
+
interface IntrinsicElements {
|
|
8
|
+
'uibit-scroll-progress': Partial<HTMLElementClass> & JSX.HTMLAttributes<HTMLElementClass> & {
|
|
9
|
+
targetSelector?: string | undefined;
|
|
10
|
+
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
2
|
+
import '@uibit/scroll-progress';
|
|
3
|
+
|
|
4
|
+
declare module '@stencil/core' {
|
|
5
|
+
export namespace JSX {
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
'uibit-scroll-progress': HTMLElementClass & {
|
|
8
|
+
targetSelector?: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import '@uibit/scroll-progress';
|
|
3
|
+
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
targetSelector = undefined,
|
|
7
|
+
children
|
|
8
|
+
} = $props<{
|
|
9
|
+
children?: any;
|
|
10
|
+
targetSelector?: string | undefined;
|
|
11
|
+
|
|
12
|
+
}>();
|
|
13
|
+
|
|
14
|
+
let elementRef: HTMLElementClass | null = $state(null);
|
|
15
|
+
|
|
16
|
+
$effect(() => {
|
|
17
|
+
if (elementRef && targetSelector !== undefined) {
|
|
18
|
+
elementRef.targetSelector = targetSelector;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<uibit-scroll-progress bind:this={elementRef} {...$$restProps}>
|
|
25
|
+
|
|
26
|
+
{#if children}
|
|
27
|
+
{@render children()}
|
|
28
|
+
{:else}
|
|
29
|
+
<slot />
|
|
30
|
+
{/if}
|
|
31
|
+
</uibit-scroll-progress>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineComponent, h } from 'vue';
|
|
2
|
+
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
3
|
+
import '@uibit/scroll-progress';
|
|
4
|
+
|
|
5
|
+
export const ScrollProgress = defineComponent({
|
|
6
|
+
name: 'ScrollProgress',
|
|
7
|
+
props: {
|
|
8
|
+
targetSelector: { type: [String, Number, Boolean, Array, Object] as any }
|
|
9
|
+
},
|
|
10
|
+
emits: [],
|
|
11
|
+
setup(props, { slots, emit }) {
|
|
12
|
+
return () => {
|
|
13
|
+
const eventListeners: Record<string, any> = {};
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
return h('uibit-scroll-progress', {
|
|
17
|
+
...props,
|
|
18
|
+
...eventListeners
|
|
19
|
+
}, slots.default?.());
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC5D,YAAY,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { UIBitElement } from '@uibit/core';
|
|
2
|
+
/**
|
|
3
|
+
* Thin progress bar that tracks scroll position — either the page or a
|
|
4
|
+
* custom scrollable element — and fills as the user scrolls down.
|
|
5
|
+
*
|
|
6
|
+
* @cssprop [--uibit-scroll-progress-height=0.1875rem] - Height of the progress bar
|
|
7
|
+
* @cssprop [--uibit-scroll-progress-bg=transparent] - Background (track) color
|
|
8
|
+
* @cssprop [--uibit-scroll-progress-color=#000000] - Fill color of the progress indicator
|
|
9
|
+
*/
|
|
10
|
+
export declare class ScrollProgress extends UIBitElement {
|
|
11
|
+
static styles: import("lit").CSSResult;
|
|
12
|
+
/** CSS selector of a custom scrollable container to track. Defaults to the page (`window`). */
|
|
13
|
+
targetSelector?: string;
|
|
14
|
+
private progressPercent;
|
|
15
|
+
private _scrollUnlisten?;
|
|
16
|
+
private _cachedTarget?;
|
|
17
|
+
private _rafId?;
|
|
18
|
+
connectedCallback(): void;
|
|
19
|
+
disconnectedCallback(): void;
|
|
20
|
+
updated(changedProperties: Map<string, unknown>): void;
|
|
21
|
+
private _getTargetElement;
|
|
22
|
+
private _attachScrollListener;
|
|
23
|
+
private updateProgress;
|
|
24
|
+
render(): import("lit").TemplateResult<1>;
|
|
25
|
+
}
|
|
26
|
+
export default ScrollProgress;
|
|
27
|
+
//# sourceMappingURL=scroll-progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-progress.d.ts","sourceRoot":"","sources":["../src/scroll-progress.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,YAAY,EAAE,MAAM,aAAa,CAAC;AAI/D;;;;;;;GAOG;AACH,qBACa,cAAe,SAAQ,YAAY;IAC9C,MAAM,CAAC,MAAM,0BAAU;IAEvB,+FAA+F;IACrC,cAAc,CAAC,EAAE,MAAM,CAAC;IAEzE,OAAO,CAAC,eAAe,CAAK;IAErC,OAAO,CAAC,eAAe,CAAC,CAAa;IACrC,OAAO,CAAC,aAAa,CAAC,CAAuB;IAC7C,OAAO,CAAC,MAAM,CAAC,CAAS;IAExB,iBAAiB,SAIhB;IAED,oBAAoB,SAGnB;IAED,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,QAM9C;IAED,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,qBAAqB;IAc7B,OAAO,CAAC,cAAc;IAiBtB,MAAM,oCAaL;CACF;eAEc,cAAc"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html } from 'lit';
|
|
8
|
+
import { customElement, msg, UIBitElement } from '@uibit/core';
|
|
9
|
+
import { property, state } from 'lit/decorators.js';
|
|
10
|
+
import { styles } from './styles';
|
|
11
|
+
/**
|
|
12
|
+
* Thin progress bar that tracks scroll position — either the page or a
|
|
13
|
+
* custom scrollable element — and fills as the user scrolls down.
|
|
14
|
+
*
|
|
15
|
+
* @cssprop [--uibit-scroll-progress-height=0.1875rem] - Height of the progress bar
|
|
16
|
+
* @cssprop [--uibit-scroll-progress-bg=transparent] - Background (track) color
|
|
17
|
+
* @cssprop [--uibit-scroll-progress-color=#000000] - Fill color of the progress indicator
|
|
18
|
+
*/
|
|
19
|
+
let ScrollProgress = class ScrollProgress extends UIBitElement {
|
|
20
|
+
constructor() {
|
|
21
|
+
super(...arguments);
|
|
22
|
+
this.progressPercent = 0;
|
|
23
|
+
}
|
|
24
|
+
static { this.styles = styles; }
|
|
25
|
+
connectedCallback() {
|
|
26
|
+
super.connectedCallback();
|
|
27
|
+
this._attachScrollListener();
|
|
28
|
+
this.updateProgress();
|
|
29
|
+
}
|
|
30
|
+
disconnectedCallback() {
|
|
31
|
+
super.disconnectedCallback();
|
|
32
|
+
if (this._rafId)
|
|
33
|
+
cancelAnimationFrame(this._rafId);
|
|
34
|
+
}
|
|
35
|
+
updated(changedProperties) {
|
|
36
|
+
if (changedProperties.has('targetSelector')) {
|
|
37
|
+
this._cachedTarget = undefined;
|
|
38
|
+
this._attachScrollListener();
|
|
39
|
+
this.updateProgress();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
_getTargetElement() {
|
|
43
|
+
if (typeof window === 'undefined')
|
|
44
|
+
return window;
|
|
45
|
+
if (!this._cachedTarget) {
|
|
46
|
+
if (this.targetSelector) {
|
|
47
|
+
const el = document.querySelector(this.targetSelector);
|
|
48
|
+
this._cachedTarget = el ? el : window;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this._cachedTarget = window;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return this._cachedTarget;
|
|
55
|
+
}
|
|
56
|
+
_attachScrollListener() {
|
|
57
|
+
if (this._scrollUnlisten)
|
|
58
|
+
this._scrollUnlisten();
|
|
59
|
+
const target = this._getTargetElement();
|
|
60
|
+
const handler = () => {
|
|
61
|
+
if (!this._rafId) {
|
|
62
|
+
this._rafId = requestAnimationFrame(() => {
|
|
63
|
+
this._rafId = undefined;
|
|
64
|
+
this.updateProgress();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
this._scrollUnlisten = this.listen(target, 'scroll', handler, { passive: true });
|
|
69
|
+
}
|
|
70
|
+
updateProgress() {
|
|
71
|
+
let scrollTop = 0;
|
|
72
|
+
let docHeight = 0;
|
|
73
|
+
const target = this._cachedTarget ?? this._getTargetElement();
|
|
74
|
+
if (target === window) {
|
|
75
|
+
scrollTop = window.scrollY;
|
|
76
|
+
docHeight = document.documentElement.scrollHeight - window.innerHeight;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const el = target;
|
|
80
|
+
scrollTop = el.scrollTop;
|
|
81
|
+
docHeight = el.scrollHeight - el.clientHeight;
|
|
82
|
+
}
|
|
83
|
+
this.progressPercent = docHeight > 0 ? (scrollTop / docHeight) * 100 : 0;
|
|
84
|
+
}
|
|
85
|
+
render() {
|
|
86
|
+
return html `
|
|
87
|
+
<div
|
|
88
|
+
part="progress"
|
|
89
|
+
class="progress"
|
|
90
|
+
style="width: ${this.progressPercent}%"
|
|
91
|
+
role="progressbar"
|
|
92
|
+
aria-valuemin="0"
|
|
93
|
+
aria-valuemax="100"
|
|
94
|
+
aria-valuenow="${Math.round(this.progressPercent)}"
|
|
95
|
+
aria-label=${msg('Scroll progress indicator')}
|
|
96
|
+
></div>
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
__decorate([
|
|
101
|
+
property({ type: String, attribute: 'target-selector' })
|
|
102
|
+
], ScrollProgress.prototype, "targetSelector", void 0);
|
|
103
|
+
__decorate([
|
|
104
|
+
state()
|
|
105
|
+
], ScrollProgress.prototype, "progressPercent", void 0);
|
|
106
|
+
ScrollProgress = __decorate([
|
|
107
|
+
customElement('uibit-scroll-progress')
|
|
108
|
+
], ScrollProgress);
|
|
109
|
+
export { ScrollProgress };
|
|
110
|
+
export default ScrollProgress;
|
|
111
|
+
//# sourceMappingURL=scroll-progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-progress.js","sourceRoot":"","sources":["../src/scroll-progress.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,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GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAA;;;;wBAIS,IAAI,CAAC,eAAe;;;;yBAInB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC;qBACpC,GAAG,CAAC,2BAA2B,CAAC;;KAEhD,CAAC;IACJ,CAAC;CACF,CAAA;AArF2D;IAAzD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC;sDAAyB;AAEjE;IAAhB,KAAK,EAAE;uDAA6B;AAN1B,cAAc;IAD1B,aAAa,CAAC,uBAAuB,CAAC;GAC1B,cAAc,CAyF1B;;AAED,eAAe,cAAc,CAAC"}
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,yBAclB,CAAC"}
|
package/dist/styles.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
export const styles = css `
|
|
3
|
+
:host {
|
|
4
|
+
display: block;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: var(--uibit-scroll-progress-height, 0.1875rem);
|
|
7
|
+
background: var(--uibit-scroll-progress-bg, transparent);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.progress {
|
|
11
|
+
height: 100%;
|
|
12
|
+
background: var(--uibit-scroll-progress-color, var(--uibit-focus-color, var(--uibit-color-black, #000000)));
|
|
13
|
+
width: 0%;
|
|
14
|
+
transition: width 150ms ease;
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;CAcxB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type ScrollProgress from './scroll-progress';
|
|
2
|
+
export interface ScrollProgressConfig {
|
|
3
|
+
height?: number;
|
|
4
|
+
color?: string;
|
|
5
|
+
backgroundColor?: string;
|
|
6
|
+
position?: 'top' | 'bottom';
|
|
7
|
+
}
|
|
8
|
+
declare global {
|
|
9
|
+
interface HTMLElementTagNameMap {
|
|
10
|
+
'uibit-scroll-progress': ScrollProgress;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AAEpD,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;CAC7B;AAED,OAAO,CAAC,MAAM,CAAC;IACf,UAAU,qBAAqB;QAC3B,uBAAuB,EAAE,cAAc,CAAC;KAC3C;CACA"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uibit/scroll-progress",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Lightweight, accessible scroll progress indicator. Tracks viewport scrolling by default, or can be targeting a specific scrollable element using selectors.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./custom-elements.json": "./custom-elements.json",
|
|
14
|
+
"./react": "./dist/frameworks/react/index.d.ts",
|
|
15
|
+
"./vue": "./dist/frameworks/vue/index.ts",
|
|
16
|
+
"./svelte": "./dist/frameworks/svelte/index.svelte",
|
|
17
|
+
"./angular": "./dist/frameworks/angular/index.ts",
|
|
18
|
+
"./solid": "./dist/frameworks/solid/index.d.ts",
|
|
19
|
+
"./astro": "./dist/frameworks/astro/index.astro",
|
|
20
|
+
"./qwik": "./dist/frameworks/qwik/index.tsx",
|
|
21
|
+
"./nuxt": "./dist/frameworks/nuxt/index.ts",
|
|
22
|
+
"./preact": "./dist/frameworks/preact/index.d.ts",
|
|
23
|
+
"./stencil": "./dist/frameworks/stencil/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"package.json",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE",
|
|
30
|
+
"custom-elements.json"
|
|
31
|
+
],
|
|
32
|
+
"keywords": [
|
|
33
|
+
"scroll-progress",
|
|
34
|
+
"progress-bar",
|
|
35
|
+
"web-component",
|
|
36
|
+
"lit",
|
|
37
|
+
"scroll"
|
|
38
|
+
],
|
|
39
|
+
"author": "Jonathan Rawlings",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/Rawlings/uibit",
|
|
44
|
+
"directory": "packages/components/scroll-progress"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@uibit/core": "0.1.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^20.19.43",
|
|
51
|
+
"lit": "^3.3.3",
|
|
52
|
+
"typescript": "7.0.2",
|
|
53
|
+
"@uibit/codegen": "0.1.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"lit": "^3.0.0",
|
|
57
|
+
"react": ">=18",
|
|
58
|
+
"vue": ">=3",
|
|
59
|
+
"svelte": ">=4 || ^5",
|
|
60
|
+
"@angular/core": ">=14"
|
|
61
|
+
},
|
|
62
|
+
"customElements": "custom-elements.json",
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"react": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"vue": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"svelte": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"@angular/core": {
|
|
74
|
+
"optional": true
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"uibit": {
|
|
78
|
+
"id": "scroll-progress",
|
|
79
|
+
"title": "Scroll Progress",
|
|
80
|
+
"category": "Data",
|
|
81
|
+
"tagName": "uibit-scroll-progress"
|
|
82
|
+
},
|
|
83
|
+
"scripts": {
|
|
84
|
+
"build": "cem analyze --globs 'src/**/*.ts' --litelement && uibit-codegen --package . && tsc",
|
|
85
|
+
"dev": "concurrently \"cem analyze --globs 'src/**/*.ts' --litelement --watch\" \"tsc --watch\"",
|
|
86
|
+
"analyze": "cem analyze --globs 'src/**/*.ts' --litelement",
|
|
87
|
+
"typecheck": "tsc --noEmit"
|
|
88
|
+
}
|
|
89
|
+
}
|