@vctqs1/nav-progress-bar-react 0.0.2-4 → 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/README.md CHANGED
@@ -4,6 +4,20 @@ React wrapper for [`@vctqs1/nav-progress-bar`](https://www.npmjs.com/package/@vc
4
4
 
5
5
  This package provides a thin React component that renders the `<vctqs1-nav-progress-bar>` custom element with proper TypeScript JSX types and SSR support via Declarative Shadow DOM.
6
6
 
7
+ ## Table of Contents
8
+
9
+ - [Installation](#installation)
10
+ - [Peer Dependencies](#peer-dependencies)
11
+ - [Quick Start](#quick-start)
12
+ - [Next.js App Router](#nextjs-app-router-recommended-setup)
13
+ - [Custom color](#custom-color)
14
+ - [React SPA (Vite, CRA, etc.)](#react-spa-vite-cra-etc)
15
+ - [Props](#props)
16
+ - [How SSR Works](#how-ssr-works)
17
+ - [Why a Separate Package?](#why-a-separate-package)
18
+ - [Related](#related)
19
+ - [License](#license)
20
+
7
21
  ## Installation
8
22
 
9
23
  ```bash
@@ -19,7 +33,7 @@ pnpm add @vctqs1/nav-progress-bar @vctqs1/nav-progress-bar-react
19
33
  | `react` | `>=18.0.0` |
20
34
  | `@vctqs1/nav-progress-bar` | `>=1.0.0` |
21
35
 
22
- ## Usage
36
+ ## Quick Start
23
37
 
24
38
  ### Next.js App Router (recommended setup)
25
39
 
@@ -55,19 +69,11 @@ export function onRouterTransitionStart(
55
69
  }
56
70
  ```
57
71
 
58
- **3. Enable instrumentation** in `next.config.ts`:
59
-
60
- ```ts
61
- const nextConfig = {
62
- experimental: {
63
- instrumentationHook: true,
64
- },
65
- };
72
+ That's it. The bar starts on every route departure and finishes automatically when the new page commits.
66
73
 
67
- export default nextConfig;
68
- ```
74
+ > 🎬 **Demo** — watch the bar in action with Next.js App Router:
69
75
 
70
- That's it. The bar starts on every route departure and finishes automatically when the new page commits.
76
+ <video src="https://github.com/user-attachments/assets/4144ed95-8c25-4aa9-b804-905ac24805b4" controls width="100%"></video>
71
77
 
72
78
  ---
73
79
 
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ let e=require("react/jsx-runtime");function t({primary:t=`#006bde`}){return(0,e.jsx)(`vctqs1-nav-progress-bar`,{primary:t})}module.exports=t;var n=require("@vctqs1/nav-progress-bar");Object.keys(n).forEach(function(e){e!==`default`&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return n[e]}})});
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './lib/nav-progress-bar-react';
1
+ export { default } from './lib/nav-progress-bar-react';
2
2
  export * from '@vctqs1/nav-progress-bar';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvD,cAAc,0BAA0B,CAAA"}
package/dist/index.js CHANGED
@@ -1,112 +1,8 @@
1
- import "react/jsx-runtime";
2
- //#region ../nav-progress-bar/dist/index.js
3
- function e() {
4
- let e = globalThis.navigation;
5
- if (!(!e || typeof e != "object") && !(!("addEventListener" in e) || !("removeEventListener" in e))) return e;
6
- }
7
- var t = class extends HTMLElement {
8
- _layoutSheet = void 0;
9
- _sheet = void 0;
10
- _progressSheet = void 0;
11
- _autoTimer = void 0;
12
- _startTime = void 0;
13
- _options;
14
- static get observedAttributes() {
15
- return ["primary"];
16
- }
17
- constructor(e = {}) {
18
- super(), this._options = e;
19
- }
20
- _onNavigateSuccess = () => this.finish();
21
- _onNavigate = () => this.start();
22
- connectedCallback() {
23
- this._render();
24
- let t = e();
25
- t && (t.addEventListener("navigate", this._onNavigate), t.addEventListener("navigatesuccess", this._onNavigateSuccess));
26
- }
27
- disconnectedCallback() {
28
- let t = e();
29
- t && (t.removeEventListener("navigate", this._onNavigate), t.removeEventListener("navigatesuccess", this._onNavigateSuccess)), this._clearTimer();
30
- }
31
- attributeChangedCallback() {
32
- this._sheet && this._applyColorSheet();
33
- }
34
- _resolveColor(e, t, n) {
35
- let r = e ?? t;
36
- return r ? r.startsWith("--") ? `var(${r}, ${n})` : r : n;
37
- }
38
- _buildColorSheet() {
39
- let e = this._resolveColor(this.getAttribute("primary"), this._options.primary, "#006bde"), t = new CSSStyleSheet();
40
- return t.insertRule(`
41
- .bar {
42
- height: 3px;
43
- background: ${e};
44
- opacity: 0;
45
- transition: width 0.3s ease, opacity 0.4s ease;
46
- box-shadow: 0 0 8px color-mix(in srgb, ${e} 53%, transparent);
47
- }
48
- `), t.insertRule(".bar.active { opacity: 1; }"), t.insertRule("\n .bar.complete {\n opacity: 0;\n transition: width 0.2s ease, opacity 0.5s ease 0.2s;\n }\n "), t;
49
- }
50
- _applyColorSheet() {
51
- !this.shadowRoot || !this._layoutSheet || !this._progressSheet || (this._sheet = this._buildColorSheet(), this.shadowRoot.adoptedStyleSheets = [
52
- this._layoutSheet,
53
- this._sheet,
54
- this._progressSheet
55
- ]);
56
- }
57
- _render() {
58
- let e = this.shadowRoot ?? this.attachShadow({ mode: "open" }), t = new CSSStyleSheet();
59
- t.insertRule("\n :host {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n z-index: 9999;\n pointer-events: none;\n }\n "), this._layoutSheet = t;
60
- let n = new CSSStyleSheet();
61
- if (n.insertRule(".bar { width: 0%; }"), this._progressSheet = n, this._sheet = this._buildColorSheet(), e.adoptedStyleSheets = [
62
- this._layoutSheet,
63
- this._sheet,
64
- this._progressSheet
65
- ], !e.querySelector(".bar")) {
66
- let t = document.createElement("div");
67
- t.className = "bar", e.append(t);
68
- }
69
- }
70
- _setWidth(e) {
71
- this._progressSheet && this._progressSheet.replaceSync(`.bar { width: ${e}%; }`);
72
- }
73
- start() {
74
- this._clearTimer(), this._setWidth(0), this._applyActive(!0);
75
- let e = 0;
76
- return this._autoTimer = setInterval(() => {
77
- e += (85 - e) * .08, this._setWidth(Math.min(e, 85));
78
- }, 200), this;
79
- }
80
- finish() {
81
- this._clearTimer();
82
- let e = this.shadowRoot?.querySelector(".bar");
83
- return e ? (e.classList.remove("active"), e.classList.add("complete"), this._setWidth(100), setTimeout(() => {
84
- e.classList.remove("complete"), this._setWidth(0), this._applyActive(!1);
85
- }, 700), this) : this;
86
- }
87
- _applyActive(e) {
88
- let t = this.shadowRoot?.querySelector(".bar");
89
- if (t && (t.classList.toggle("active", e), e && this._startTime === void 0 && (this._startTime = performance.now()), !e && this._startTime !== void 0)) {
90
- let e = performance.now() - this._startTime;
91
- console.log(`[top-loading-bar] navigation took ${e.toFixed(0)}ms`), this._startTime = void 0;
92
- }
93
- }
94
- _clearTimer() {
95
- this._autoTimer !== void 0 && (clearInterval(this._autoTimer), this._autoTimer = void 0);
96
- }
97
- }, n = "vctqs1-nav-progress-bar";
98
- function r(r) {
99
- if (!(typeof customElements > "u") && e() && !customElements.get("vctqs1-nav-progress-bar")) {
100
- class e extends t {
101
- constructor() {
102
- super(r);
103
- }
104
- }
105
- customElements.define(n, e);
106
- }
107
- }
108
- function i() {
109
- return document.querySelector(n);
1
+ import { jsx as e } from "react/jsx-runtime";
2
+ export * from "@vctqs1/nav-progress-bar";
3
+ //#region src/lib/nav-progress-bar-react.tsx
4
+ function t({ primary: t = "#006bde" }) {
5
+ return /* @__PURE__ */ e("vctqs1-nav-progress-bar", { primary: t });
110
6
  }
111
7
  //#endregion
112
- export { t as NavProgressBar, n as TAG_NAME, i as getNavProgressBar, r as registerNavProgressBar };
8
+ export { t as default };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@vctqs1/nav-progress-bar-react",
3
- "version": "0.0.2-4",
3
+ "version": "0.1.0",
4
+ "repository": "https://github.com/vctqs1/nav-progress-bar",
4
5
  "type": "module",
5
6
  "main": "./dist/index.js",
6
7
  "module": "./dist/index.js",
@@ -20,6 +21,7 @@
20
21
  ],
21
22
  "license": "MIT",
22
23
  "keywords": [
24
+ "toploader",
23
25
  "progress-bar",
24
26
  "navigation",
25
27
  "react",
@@ -35,7 +37,7 @@
35
37
  "access": "public"
36
38
  },
37
39
  "dependencies": {
38
- "@vctqs1/nav-progress-bar": "0.0.2-4"
40
+ "@vctqs1/nav-progress-bar": "0.1.0"
39
41
  },
40
42
  "nx": {
41
43
  "name": "@vctqs1/nav-progress-bar-react",