@c2n/progress 0.0.7

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) 2024 Nguyen Thai Vinh
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,28 @@
1
+ # @c2n/progress
2
+
3
+ Progress built with Lit: a linear bar, indeterminate by default or filling to a value, with an optional label and count.
4
+
5
+ ```bash
6
+ npm install @c2n/progress
7
+ ```
8
+
9
+ ```html
10
+ <script type="module">
11
+ import '@c2n/progress'
12
+ </script>
13
+
14
+ <c2-progress></c2-progress>
15
+ <c2-progress>Uploading files</c2-progress>
16
+ <c2-progress value="65" show-value>Uploading files</c2-progress>
17
+ <c2-progress value="3" max="5">Onboarding<span slot="value">Step 3 of 5</span></c2-progress>
18
+ ```
19
+
20
+ - **Indeterminate**: a short indicator sweeps the track; `--c2-progress--animation-duration` sets one cycle.
21
+ - **Determinate**: `value` (out of `max`, default 100) fills the track from the start edge and animates between values; clear it to sweep again.
22
+ - **Label and count**: slotted text sits above the track and is the accessible name; without it, `label` (default "Loading") names the bar. `show-value` prints the percentage on the opposite side, and the `value` slot replaces that text for counts such as "3 of 5" or "1.2 / 4 MB". The label row is absent entirely when there is neither, so a bare bar is exactly `--c2-progress--height` tall.
23
+ - **Accessibility**: the track is `role="progressbar"` with `aria-valuenow` when determinate. The printed count is presentational, so it is free to differ from the announced number.
24
+ - **Reduced motion**: the sweep slows and drops its easing, and the determinate fill jumps instead of transitioning.
25
+
26
+ Theme it with `--c2-progress--height`, `--c2-progress--width`, `--c2-progress--border-radius`, `--c2-progress__track--background-color`, `--c2-progress__indicator--background-color`, `--c2-progress--gap` and the `--c2-progress__label--*` / `--c2-progress__value--*` text variables. The full list is in `custom-elements.json` and on the docs site.
27
+
28
+ Reach for [`@c2n/spinner`](../spinner) when the wait has no natural width to fill.
@@ -0,0 +1,99 @@
1
+ import { LitElement, html, nothing, unsafeCSS } from "lit";
2
+ import { property, state } from "lit/decorators.js";
3
+ import { customElement } from "@c2n/core/element-helper.js";
4
+ import { classMap } from "lit/directives/class-map.js";
5
+ import { ifDefined } from "lit/directives/if-defined.js";
6
+ import { styleMap } from "lit/directives/style-map.js";
7
+ //#region src/progress.scss?inline
8
+ var progress_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: block;\n width: var(--c2-progress--width,100%);\n}\n\n:host([hidden]) {\n display: none;\n}\n\n.c2-progress {\n display: flex;\n flex-direction: column;\n gap: var(--c2-progress--gap,8px);\n}\n\n.c2-progress-header {\n display: flex;\n align-items: baseline;\n justify-content: space-between;\n gap: 12px;\n line-height: 1.4;\n}\n.c2-progress-header[hidden] {\n display: none;\n}\n\n.c2-progress-label {\n color: var(--c2-progress__label--color,#71717a);\n font-size: var(--c2-progress__label--font-size,14px);\n font-weight: var(--c2-progress__label--font-weight);\n min-width: 0;\n}\n.c2-progress-label[hidden] {\n display: none;\n}\n\n.c2-progress-value {\n flex: none;\n color: var(--c2-progress__value--color,#18181b);\n font-size: var(--c2-progress__value--font-size,14px);\n font-weight: var(--c2-progress__value--font-weight,500);\n font-variant-numeric: tabular-nums;\n}\n.c2-progress-value[hidden] {\n display: none;\n}\n\n.c2-progress-track {\n position: relative;\n overflow: hidden;\n height: var(--c2-progress--height,8px);\n border-radius: var(--c2-progress--border-radius,999px);\n background-color: var(--c2-progress__track--background-color,#e4e4e7);\n}\n\n.c2-progress-indicator {\n height: 100%;\n border-radius: inherit;\n background-color: var(--c2-progress__indicator--background-color,#0265dc);\n width: 40%;\n animation: c2-progress-slide var(--c2-progress--animation-duration,1.4s) cubic-bezier(0.4, 0, 0.2, 1) infinite;\n}\n\n.is-determinate .c2-progress-indicator {\n animation: none;\n transition: width calc(var(--c2-progress--animation-duration,1.4s) / 2) cubic-bezier(0.2, 0, 0, 1);\n}\n\n@keyframes c2-progress-slide {\n from {\n transform: translateX(-100%);\n }\n to {\n transform: translateX(250%);\n }\n}\n@media (prefers-reduced-motion: reduce) {\n .c2-progress-indicator {\n animation-duration: 3s;\n animation-timing-function: linear;\n }\n .is-determinate .c2-progress-indicator {\n transition: none;\n }\n}";
9
+ //#endregion
10
+ //#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
11
+ function __decorate(decorators, target, key, desc) {
12
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
14
+ 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;
15
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
16
+ }
17
+ //#endregion
18
+ //#region src/progress.ts
19
+ var Progress = class Progress extends LitElement {
20
+ constructor(..._args) {
21
+ super(..._args);
22
+ this.value = void 0;
23
+ this.max = 100;
24
+ this.label = "";
25
+ this.showValue = false;
26
+ this.hasLabel = false;
27
+ this.hasValueText = false;
28
+ }
29
+ static {
30
+ this.styles = unsafeCSS(progress_default);
31
+ }
32
+ /** Value that fills the track, guarding against a `max` of `0` or less. */
33
+ get effectiveMax() {
34
+ return this.max > 0 ? this.max : 100;
35
+ }
36
+ /** `value` clamped to `0`–`max`; `undefined` while indeterminate. Announced as-is, so it keeps the author's precision. */
37
+ get clampedValue() {
38
+ if (this.value === void 0 || Number.isNaN(this.value)) return void 0;
39
+ return Math.min(this.effectiveMax, Math.max(0, this.value));
40
+ }
41
+ /** Completed fraction, `0` to `1`; `undefined` while indeterminate. */
42
+ get fraction() {
43
+ const value = this.clampedValue;
44
+ return value === void 0 ? void 0 : value / this.effectiveMax;
45
+ }
46
+ handleSlotChange(event) {
47
+ const slot = event.target;
48
+ const filled = slot.assignedNodes({ flatten: true }).some((node) => node.nodeType === Node.ELEMENT_NODE || (node.textContent ?? "").trim() !== "");
49
+ if (slot.name === "value") this.hasValueText = filled;
50
+ else this.hasLabel = filled;
51
+ }
52
+ render() {
53
+ const value = this.clampedValue;
54
+ const fraction = this.fraction;
55
+ const determinate = fraction !== void 0;
56
+ const percent = determinate ? Math.round(fraction * 100) : 0;
57
+ const showValue = this.showValue || this.hasValueText;
58
+ return html`
59
+ <div class=${classMap({
60
+ "c2-progress": true,
61
+ "is-determinate": determinate
62
+ })}>
63
+ <div class="c2-progress-header" part="header" ?hidden=${!this.hasLabel && !showValue}>
64
+ <span id="label" class="c2-progress-label" part="label" ?hidden=${!this.hasLabel}>
65
+ <slot @slotchange=${this.handleSlotChange}></slot>
66
+ </span>
67
+ <span class="c2-progress-value" part="value" ?hidden=${!showValue}>
68
+ <slot name="value" @slotchange=${this.handleSlotChange}>${determinate ? `${percent}%` : nothing}</slot>
69
+ </span>
70
+ </div>
71
+ <div
72
+ class="c2-progress-track"
73
+ part="track"
74
+ role="progressbar"
75
+ aria-label=${this.hasLabel ? nothing : ifDefined(this.label || "Loading")}
76
+ aria-labelledby=${this.hasLabel ? "label" : nothing}
77
+ aria-valuemin=${determinate ? "0" : nothing}
78
+ aria-valuemax=${determinate ? String(this.effectiveMax) : nothing}
79
+ aria-valuenow=${value !== void 0 ? String(value) : nothing}
80
+ >
81
+ <div class="c2-progress-indicator" part="indicator" style=${determinate ? styleMap({ width: `${fraction * 100}%` }) : nothing}></div>
82
+ </div>
83
+ </div>
84
+ `;
85
+ }
86
+ };
87
+ __decorate([property({ type: Number })], Progress.prototype, "value", void 0);
88
+ __decorate([property({ type: Number })], Progress.prototype, "max", void 0);
89
+ __decorate([property()], Progress.prototype, "label", void 0);
90
+ __decorate([property({
91
+ type: Boolean,
92
+ attribute: "show-value",
93
+ reflect: true
94
+ })], Progress.prototype, "showValue", void 0);
95
+ __decorate([state()], Progress.prototype, "hasLabel", void 0);
96
+ __decorate([state()], Progress.prototype, "hasValueText", void 0);
97
+ Progress = __decorate([customElement("c2-progress")], Progress);
98
+ //#endregion
99
+ export { Progress };
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@c2n/progress",
3
+ "version": "0.0.7",
4
+ "type": "module",
5
+ "main": "dist/progress.js",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./types/src/progress.d.ts",
9
+ "default": "./dist/progress.js"
10
+ },
11
+ "./react": {
12
+ "types": "./react.d.ts",
13
+ "default": "./react.js"
14
+ },
15
+ "./vue": {
16
+ "types": "./vue.d.ts",
17
+ "default": "./vue.js"
18
+ },
19
+ "./custom-elements.json": "./custom-elements.json"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "types",
24
+ "react.d.ts",
25
+ "react.js",
26
+ "vue.d.ts",
27
+ "vue.js"
28
+ ],
29
+ "keywords": [
30
+ "progress",
31
+ "web component",
32
+ "lit"
33
+ ],
34
+ "license": "MIT",
35
+ "author": "code2nguyen@gmail.com",
36
+ "publishConfig": {
37
+ "registry": "https://registry.npmjs.org",
38
+ "access": "public"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/code2nguyen/web-components.git"
43
+ },
44
+ "scripts": {
45
+ "dev": "vite",
46
+ "build": "wireit",
47
+ "build:only": "vite build",
48
+ "type-check": "wireit"
49
+ },
50
+ "wireit": {
51
+ "type-check": {
52
+ "dependencies": [
53
+ "../../core:build"
54
+ ],
55
+ "command": "tsc -p tsconfig.lib.json --composite false"
56
+ },
57
+ "build": {
58
+ "dependencies": [
59
+ "type-check"
60
+ ],
61
+ "command": "vite build"
62
+ }
63
+ },
64
+ "dependencies": {
65
+ "@c2n/core": "0.0.7",
66
+ "lit": "3.3.3"
67
+ },
68
+ "devDependencies": {
69
+ "@c2n/config": "*"
70
+ },
71
+ "customElements": "custom-elements.json",
72
+ "gitHead": "c8db398a27f7cd417d665fdf5da455fee2d4e910"
73
+ }
package/react.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // JSX types for the custom elements of @c2n/progress. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/progress/react'
6
+ //
7
+ // Register the elements at module scope before React renders, or React writes an object prop as an
8
+ // attribute and it stringifies.
9
+
10
+ import type { DetailedHTMLProps, HTMLAttributes } from 'react'
11
+ import type { Progress } from '@c2n/progress'
12
+
13
+ /** Standard React host-element attributes plus the element's own public properties. */
14
+ type C2Props<T> = DetailedHTMLProps<HTMLAttributes<T>, T> & Partial<Omit<T, keyof HTMLElement>>
15
+
16
+ declare module 'react' {
17
+ namespace JSX {
18
+ interface IntrinsicElements {
19
+ 'c2-progress': C2Props<Progress>
20
+ }
21
+ }
22
+ }
23
+
24
+ export {}
package/react.js ADDED
@@ -0,0 +1,3 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ // Types only — see the matching .d.ts.
3
+ export {}
@@ -0,0 +1,54 @@
1
+ import { LitElement } from 'lit';
2
+ /**
3
+ * Linear progress bar. Without a `value` the indicator slides across the track indefinitely; with one it fills the
4
+ * track from the start edge and animates between values. Text in the default slot labels the bar and doubles as its
5
+ * accessible name, and `show-value` adds the percentage on the opposite side — override that text with the `value`
6
+ * slot to count something other than percent. Track and indicator are two plain boxes, so height, radius, colours
7
+ * and speed are all variables. Use `c2-spinner` when the wait has no natural width to fill.
8
+ *
9
+ * @tag c2-progress
10
+ *
11
+ * @slot - Label shown above the track (e.g. "Uploading files"). Also used as the accessible name.
12
+ * @slot value - Replaces the percentage shown next to the label, for counts such as "3 of 5" or "1.2 of 4 MB".
13
+ *
14
+ * @cssproperty {pixel} [--c2-progress--height=8px] - Thickness of the track and the indicator.
15
+ * @cssproperty {pixel} [--c2-progress--width=100%] - Width of the bar; the host is a block by default.
16
+ * @cssproperty {border-radius} [--c2-progress--border-radius=999px] - Rounding of both the track and the indicator.
17
+ * @cssproperty {color} [--c2-progress__track--background-color=#e4e4e7] - Colour of the unfilled track.
18
+ * @cssproperty {color} [--c2-progress__indicator--background-color=#0265dc] - Colour of the filled part.
19
+ * @cssproperty {time} [--c2-progress--animation-duration=1.4s] - One indeterminate cycle; the determinate fill takes half of it.
20
+ * @cssproperty {pixel} [--c2-progress--gap=8px] - Space between the label row and the track.
21
+ * @cssproperty {color} [--c2-progress__label--color=#71717a]
22
+ * @cssproperty {font-size} [--c2-progress__label--font-size=14px]
23
+ * @cssproperty {font-weight} --c2-progress__label--font-weight
24
+ * @cssproperty {color} [--c2-progress__value--color=#18181b]
25
+ * @cssproperty {font-size} [--c2-progress__value--font-size=14px]
26
+ * @cssproperty {font-weight} [--c2-progress__value--font-weight=500]
27
+ */
28
+ export declare class Progress extends LitElement {
29
+ static styles: import("lit").CSSResult;
30
+ /** Progress between `0` and `max`. Leave unset for an indeterminate bar. */
31
+ value: number | undefined;
32
+ /** Value that fills the whole track. */
33
+ max: number;
34
+ /** Accessible name when nothing is slotted. Defaults to "Loading". */
35
+ label: string;
36
+ /** Show the completed percentage beside the label. Always on when the `value` slot has content. */
37
+ showValue: boolean;
38
+ private hasLabel;
39
+ private hasValueText;
40
+ /** Value that fills the track, guarding against a `max` of `0` or less. */
41
+ private get effectiveMax();
42
+ /** `value` clamped to `0`–`max`; `undefined` while indeterminate. Announced as-is, so it keeps the author's precision. */
43
+ private get clampedValue();
44
+ /** Completed fraction, `0` to `1`; `undefined` while indeterminate. */
45
+ get fraction(): number | undefined;
46
+ private handleSlotChange;
47
+ render(): import("lit-html").TemplateResult<1>;
48
+ }
49
+ declare global {
50
+ interface HTMLElementTagNameMap {
51
+ 'c2-progress': Progress;
52
+ }
53
+ }
54
+ //# sourceMappingURL=progress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,MAAM,KAAK,CAAA;AAQ1D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBACa,QAAS,SAAQ,UAAU;IACtC,OAAgB,MAAM,0BAAoB;IAE1C,4EAA4E;IAChD,KAAK,EAAE,MAAM,GAAG,SAAS,CAAY;IAEjE,wCAAwC;IACZ,GAAG,SAAM;IAErC,sEAAsE;IAC1D,KAAK,SAAK;IAEtB,mGAAmG;IAC9B,SAAS,UAAQ;IAE7E,OAAO,CAAC,QAAQ,CAAQ;IAExB,OAAO,CAAC,YAAY,CAAQ;IAErC,2EAA2E;IAC3E,OAAO,KAAK,YAAY,GAEvB;IAED,0HAA0H;IAC1H,OAAO,KAAK,YAAY,GAGvB;IAED,uEAAuE;IACvE,IAAI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAGjC;IAGD,OAAO,CAAC,gBAAgB;IAOf,MAAM;CA+BhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,QAAQ,CAAA;KACxB;CACF"}
package/vue.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // Vue template types for the custom elements of @c2n/progress. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/progress/vue'
6
+ //
7
+ // Tell the compiler about the tags as well, or every c2-* tag is resolved as a Vue component and renders
8
+ // nothing: template.compilerOptions.isCustomElement = (tag) => tag.startsWith('c2-') in vite.config.ts.
9
+
10
+ import type { DefineComponent, HTMLAttributes } from 'vue'
11
+ import type { Progress } from '@c2n/progress'
12
+
13
+ /** The element's own public properties, plus every attribute Vue understands on a host element. */
14
+ type C2Props<T> = Partial<Omit<T, keyof HTMLElement>> & HTMLAttributes
15
+
16
+ declare module 'vue' {
17
+ interface GlobalComponents {
18
+ 'c2-progress': DefineComponent<
19
+ C2Props<Progress> & {
20
+ 'show-value'?: unknown
21
+ }
22
+ >
23
+ }
24
+ }
25
+
26
+ declare module '@vue/runtime-dom' {
27
+ interface HTMLAttributes {
28
+ /** Vue's own definition omits it, and slotting a plain element into a component needs it. */
29
+ slot?: string
30
+ }
31
+ }
32
+
33
+ export {}
package/vue.js ADDED
@@ -0,0 +1,3 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ // Types only — see the matching .d.ts.
3
+ export {}