@rokku-x/react-hook-loading-spinner 0.2.1 → 0.2.5

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
@@ -20,7 +20,6 @@ npm install @rokku-x/react-hook-loading-spinner
20
20
  - 📡 **Event System** - Subscribe to loading state changes
21
21
  - ♿ **Accessibility** - Built-in inert attribute and scroll prevention
22
22
  - 📱 **Zero Dependencies** - Only requires React and Zustand
23
- - 🌐 **SSR-Compatible** - Hooks work in SSR; use `ssrLoading` helper in Server Components
24
23
 
25
24
  ## Bundle Size
26
25
 
@@ -397,28 +396,9 @@ function App() {
397
396
  loadingComponentScale={1.5}
398
397
  />
399
398
  </>
400
-
401
- ### SSR Usage
402
-
403
- For Server Components, use the SSR-safe helper instead of the client hook:
404
-
405
- ```tsx
406
- import { ssrLoading } from '@rokku-x/react-hook-loading-spinner';
407
-
408
- export default function ServerComponent() {
409
- const { startLoading, stopLoading, isLoading } = ssrLoading();
410
-
411
- startLoading();
412
- // ...run your server-side work
413
- stopLoading();
414
-
415
- return <div>{isLoading ? 'Loading…' : 'Done'}</div>;
416
- }
417
- ```
418
-
419
- For Client Components, continue using `useLoading` as shown above.
420
399
  );
421
400
  }
401
+ }
422
402
  ```
423
403
 
424
404
  ### Example 7: Fade Animation
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),O=require("crypto"),L=require("react/jsx-runtime"),A=require("react-dom"),y=n=>{let t;const e=new Set,o=(s,l)=>{const d=typeof s=="function"?s(t):s;if(!Object.is(d,t)){const p=t;t=l??(typeof d!="object"||d===null)?d:Object.assign({},t,d),e.forEach(m=>m(t,p))}},r=()=>t,f={setState:o,getState:r,getInitialState:()=>b,subscribe:s=>(e.add(s),()=>e.delete(s))},b=t=n(o,r,f);return f},R=(n=>n?y(n):y),$=n=>n;function F(n,t=$){const e=a.useSyncExternalStore(n.subscribe,a.useCallback(()=>t(n.getState()),[n,t]),a.useCallback(()=>t(n.getInitialState()),[n,t]));return a.useDebugValue(e),e}const x=n=>{const t=R(n),e=o=>F(t,o);return Object.assign(e,t),e},k=(n=>n?x(n):x);class C extends EventTarget{constructor(){super(...arguments),this.controller=new AbortController}on(t,e){return this.addEventListener(t,o=>e(o.detail),{signal:this.controller.signal}),this}once(t,e){return this.addEventListener(t,o=>e(o.detail),{signal:this.controller.signal,once:!0}),this}emit(t,e){return this.dispatchEvent(new CustomEvent(t,{detail:e}))}removeAllListeners(){this.controller.abort(),this.controller=new AbortController}}const g=new C,v=k()((n,t)=>({loadingCount:0,overrideState:null,localCounters:{},isLoading(){return t().overrideState??t().loadingCount>0},actions:{isGlobalLoading(){return t().isLoading()},startLoading:e=>{const o=t().isLoading();n(i=>({loadingCount:i.loadingCount+1})),e&&n(i=>({localCounters:{...i.localCounters,[e]:(i.localCounters[e]??0)+1}}));const r=t().isLoading();r&&!o&&g.emit("start",null),g.emit("change",{isLoading:r,isOverrideState:t().overrideState!==null})},stopLoading:e=>{const o=t().isLoading(),r=e?t().localCounters[e]??0:0;e&&r>0&&n(u=>({loadingCount:Math.max(0,u.loadingCount-1),localCounters:{...u.localCounters,[e]:Math.max(0,u.localCounters[e]-1)}}));const i=t().isLoading();!i&&o&&g.emit("stop",null),g.emit("change",{isLoading:i,isOverrideState:t().overrideState!==null})},overrideLoading:e=>{const o=t().isLoading();n({overrideState:e});const r=t().isLoading();r&&!o?g.emit("start",null):!r&&o&&g.emit("stop",null),g.emit("change",{isLoading:r,isOverrideState:e!==null})},getLocalCounter:e=>t().localCounters[e]??0,isLocalLoading:e=>(t().localCounters[e]??0)>0}}));function w(){const n=a.useId(),{actions:t}=v(i=>i),e=()=>{t.startLoading(n)},o=()=>{t.isLocalLoading(n)&&t.stopLoading(n)},r=async i=>{e();try{return await i}finally{o()}};return{overrideLoading:t.overrideLoading,startLoading:e,stopLoading:o,get isLocalLoading(){return t.isLocalLoading(n)},asyncUseLoading:r,get isLoading(){return t.isGlobalLoading()}}}function M(){const n=O.randomUUID(),{actions:t}=v(i=>i),e=()=>{t.startLoading(n)},o=()=>{t.isLocalLoading(n)&&t.stopLoading(n)},r=async i=>{e();try{return await i}finally{o()}};return{overrideLoading:t.overrideLoading,startLoading:e,stopLoading:o,get isLocalLoading(){return t.isLocalLoading(n)},asyncUseLoading:r,get isLoading(){return t.isGlobalLoading()}}}const c={Spin:"spin",FadeInOut:"fadeInOut",None:"none"},N=({scale:n=1,animationType:t=c.Spin,animationDuration:e,children:o,style:r,className:i,id:u,prefix:f})=>{const b=t,s=t===c.Spin?1:t===c.FadeInOut?2:0,l=e||s,d=t===c.Spin?"linear":t===c.FadeInOut?"ease-in-out":"linear",p=t===c.None?"none":`${f}-${b} ${l}s ${d} infinite`;return L.jsx("div",{style:{animation:p,...n!==1?{zoom:n}:{},...r},className:i,id:u,children:o})},E=n=>L.jsx("div",{id:"loading-circle",style:{width:"90px",height:"90px",border:"15px solid #f3f3f3",borderTop:"15px solid #009b4bff",borderRadius:"50%",boxSizing:"border-box"},...n}),I=n=>L.jsx("div",{style:{padding:"20px",fontSize:"25px",color:"#333",fontFamily:"system-ui, sans-serif"},...n,children:"Please wait..."});function P({loadingComponent:n,loadingComponentScale:t=1,animationType:e=c.Spin,animationDuration:o,wrapperStyle:r,wrapperClassName:i,wrapperId:u,animationWrapperStyle:f,animationWrapperClassName:b,animationWrapperId:s}){n=n||(e===c.Spin?E:I);const l=a.useRef(Math.random().toString(36).substring(2,6).replace(/[0-9]/g,"")),{loadingCount:d,overrideState:p}=v(j=>j),m=p??d>0,S=a.useRef(null);a.useEffect(()=>{m?(S.current?.showModal(),document.body.setAttribute("inert","")):(S.current?.close(),document.body.removeAttribute("inert"))},[m]);const h=u||"loading-wrapper-"+l.current;return m?A.createPortal(L.jsxs(L.Fragment,{children:[L.jsx("style",{children:`
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),L=require("react/jsx-runtime"),O=require("react-dom"),v=e=>{let t;const n=new Set,o=(a,l)=>{const d=typeof a=="function"?a(t):a;if(!Object.is(d,t)){const m=t;t=l??(typeof d!="object"||d===null)?d:Object.assign({},t,d),n.forEach(p=>p(t,m))}},i=()=>t,f={setState:o,getState:i,getInitialState:()=>b,subscribe:a=>(n.add(a),()=>n.delete(a))},b=t=e(o,i,f);return f},A=(e=>e?v(e):v),R=e=>e;function $(e,t=R){const n=s.useSyncExternalStore(e.subscribe,s.useCallback(()=>t(e.getState()),[e,t]),s.useCallback(()=>t(e.getInitialState()),[e,t]));return s.useDebugValue(n),n}const x=e=>{const t=A(e),n=o=>$(t,o);return Object.assign(n,t),n},F=(e=>e?x(e):x);class y extends EventTarget{constructor(){super(...arguments),this.controller=new AbortController}on(t,n){return this.addEventListener(t,o=>n(o.detail),{signal:this.controller.signal}),this}once(t,n){return this.addEventListener(t,o=>n(o.detail),{signal:this.controller.signal,once:!0}),this}emit(t,n){return this.dispatchEvent(new CustomEvent(t,{detail:n}))}removeAllListeners(){this.controller.abort(),this.controller=new AbortController}}const g=new y,C=F()((e,t)=>({loadingCount:0,overrideState:null,localCounters:{},isLoading(){return t().overrideState??t().loadingCount>0},actions:{isGlobalLoading(){return t().isLoading()},startLoading:n=>{const o=t().isLoading();e(r=>({loadingCount:r.loadingCount+1})),n&&e(r=>({localCounters:{...r.localCounters,[n]:(r.localCounters[n]??0)+1}}));const i=t().isLoading();i&&!o&&g.emit("start",null),g.emit("change",{isLoading:i,isOverrideState:t().overrideState!==null})},stopLoading:n=>{const o=t().isLoading(),i=n?t().localCounters[n]??0:0;n&&i>0&&e(u=>({loadingCount:Math.max(0,u.loadingCount-1),localCounters:{...u.localCounters,[n]:Math.max(0,u.localCounters[n]-1)}}));const r=t().isLoading();!r&&o&&g.emit("stop",null),g.emit("change",{isLoading:r,isOverrideState:t().overrideState!==null})},overrideLoading:n=>{const o=t().isLoading();e({overrideState:n});const i=t().isLoading();i&&!o?g.emit("start",null):!i&&o&&g.emit("stop",null),g.emit("change",{isLoading:i,isOverrideState:n!==null})},getLocalCounter:n=>t().localCounters[n]??0,isLocalLoading:n=>(t().localCounters[n]??0)>0}}));function w(){const e=s.useId(),{actions:t}=C(r=>r),n=()=>{t.startLoading(e)},o=()=>{t.isLocalLoading(e)&&t.stopLoading(e)},i=async r=>{n();try{return await r}finally{o()}};return{overrideLoading:t.overrideLoading,startLoading:n,stopLoading:o,get isLocalLoading(){return t.isLocalLoading(e)},asyncUseLoading:i,get isLoading(){return t.isGlobalLoading()}}}const c={Spin:"spin",FadeInOut:"fadeInOut",None:"none"},k=({scale:e=1,animationType:t=c.Spin,animationDuration:n,children:o,style:i,className:r,id:u,prefix:f})=>{const b=t,a=t===c.Spin?1:t===c.FadeInOut?2:0,l=n||a,d=t===c.Spin?"linear":t===c.FadeInOut?"ease-in-out":"linear",m=t===c.None?"none":`${f}-${b} ${l}s ${d} infinite`;return L.jsx("div",{style:{animation:m,...e!==1?{zoom:e}:{},...i},className:r,id:u,children:o})},E=e=>L.jsx("div",{id:"loading-circle",style:{width:"90px",height:"90px",border:"15px solid #f3f3f3",borderTop:"15px solid #009b4bff",borderRadius:"50%",boxSizing:"border-box"},...e}),j=e=>L.jsx("div",{style:{padding:"20px",fontSize:"25px",color:"#333",fontFamily:"system-ui, sans-serif"},...e,children:"Please wait..."});function M({loadingComponent:e,loadingComponentScale:t=1,animationType:n=c.Spin,animationDuration:o,wrapperStyle:i,wrapperClassName:r,wrapperId:u,animationWrapperStyle:f,animationWrapperClassName:b,animationWrapperId:a}){e=e||(n===c.Spin?E:j);const l=s.useRef(Math.random().toString(36).substring(2,6).replace(/[0-9]/g,"")),{loadingCount:d,overrideState:m}=C(I=>I),p=m??d>0,S=s.useRef(null);s.useEffect(()=>{p?(S.current?.showModal(),document.body.setAttribute("inert","")):(S.current?.close(),document.body.removeAttribute("inert"))},[p]);const h=u||"loading-wrapper-"+l.current;return p?O.createPortal(L.jsxs(L.Fragment,{children:[L.jsx("style",{children:`
2
2
  dialog#${h}[open] {
3
3
  display: flex !important;
4
4
  justify-content: center;
@@ -22,4 +22,4 @@
22
22
  body {
23
23
  scrollbar-gutter: stable;
24
24
  }
25
- `}),L.jsx("dialog",{ref:S,style:{border:"none",padding:0,backgroundColor:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)",...r},className:i,id:h,children:L.jsx(N,{scale:t,animationType:e,animationDuration:o,style:f,className:b,id:s,prefix:l.current,children:a.isValidElement(n)?n:a.createElement(n)})})]}),document.body):null}function q({isLoading:n=!1}){const{startLoading:t,stopLoading:e}=w();return a.useEffect(()=>(n?t():e(),()=>{n&&e()}),[n]),null}exports.AnimationType=c;exports.EventEmitter=C;exports.Loading=q;exports.LoadingCircle=E;exports.LoadingPleaseWait=I;exports.LoadingRenderer=P;exports.loadingEventTarget=g;exports.ssrLoading=M;exports.useLoading=w;
25
+ `}),L.jsx("dialog",{ref:S,style:{border:"none",padding:0,backgroundColor:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)",...i},className:r,id:h,children:L.jsx(k,{scale:t,animationType:n,animationDuration:o,style:f,className:b,id:a,prefix:l.current,children:s.isValidElement(e)?e:s.createElement(e)})})]}),document.body):null}function N({isLoading:e=!1}){const{startLoading:t,stopLoading:n}=w();return s.useEffect(()=>(e?t():n(),()=>{e&&n()}),[e]),null}exports.AnimationType=c;exports.EventEmitter=y;exports.Loading=N;exports.LoadingCircle=E;exports.LoadingPleaseWait=j;exports.LoadingRenderer=M;exports.loadingEventTarget=g;exports.useLoading=w;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { default as useLoading } from './hooks/useLoading';
2
- export { default as ssrLoading } from './hooks/ssrLoading';
3
2
  export { LoadingCircle, LoadingPleaseWait, AnimationType } from './components/LoadingRenderer';
4
3
  export type { AnimationType as AnimationTypeType } from './components/LoadingRenderer';
5
4
  export { default as Loading } from './components/Loading';
package/dist/index.esm.js CHANGED
@@ -1,60 +1,59 @@
1
1
  "use client";
2
- import L, { useId as E, useRef as y, useEffect as w } from "react";
3
- import { randomUUID as O } from "crypto";
4
- import { jsx as f, jsxs as $, Fragment as j } from "react/jsx-runtime";
5
- import { createPortal as A } from "react-dom";
6
- const x = (n) => {
2
+ import L, { useId as E, useRef as v, useEffect as C } from "react";
3
+ import { jsx as f, jsxs as O, Fragment as $ } from "react/jsx-runtime";
4
+ import { createPortal as j } from "react-dom";
5
+ const y = (n) => {
7
6
  let t;
8
- const o = /* @__PURE__ */ new Set(), e = (a, s) => {
9
- const l = typeof a == "function" ? a(t) : a;
7
+ const e = /* @__PURE__ */ new Set(), o = (s, a) => {
8
+ const l = typeof s == "function" ? s(t) : s;
10
9
  if (!Object.is(l, t)) {
11
- const p = t;
12
- t = s ?? (typeof l != "object" || l === null) ? l : Object.assign({}, t, l), o.forEach((b) => b(t, p));
10
+ const m = t;
11
+ t = a ?? (typeof l != "object" || l === null) ? l : Object.assign({}, t, l), e.forEach((p) => p(t, m));
13
12
  }
14
- }, r = () => t, g = { setState: e, getState: r, getInitialState: () => m, subscribe: (a) => (o.add(a), () => o.delete(a)) }, m = t = n(e, r, g);
13
+ }, i = () => t, g = { setState: o, getState: i, getInitialState: () => b, subscribe: (s) => (e.add(s), () => e.delete(s)) }, b = t = n(o, i, g);
15
14
  return g;
16
- }, F = ((n) => n ? x(n) : x), k = (n) => n;
17
- function N(n, t = k) {
18
- const o = L.useSyncExternalStore(
15
+ }, A = ((n) => n ? y(n) : y), F = (n) => n;
16
+ function k(n, t = F) {
17
+ const e = L.useSyncExternalStore(
19
18
  n.subscribe,
20
19
  L.useCallback(() => t(n.getState()), [n, t]),
21
20
  L.useCallback(() => t(n.getInitialState()), [n, t])
22
21
  );
23
- return L.useDebugValue(o), o;
22
+ return L.useDebugValue(e), e;
24
23
  }
25
- const C = (n) => {
26
- const t = F(n), o = (e) => N(t, e);
27
- return Object.assign(o, t), o;
28
- }, R = ((n) => n ? C(n) : C);
29
- class M extends EventTarget {
24
+ const x = (n) => {
25
+ const t = A(n), e = (o) => k(t, o);
26
+ return Object.assign(e, t), e;
27
+ }, N = ((n) => n ? x(n) : x);
28
+ class R extends EventTarget {
30
29
  constructor() {
31
30
  super(...arguments), this.controller = new AbortController();
32
31
  }
33
- on(t, o) {
32
+ on(t, e) {
34
33
  return this.addEventListener(
35
34
  t,
36
- (e) => o(e.detail),
35
+ (o) => e(o.detail),
37
36
  { signal: this.controller.signal }
38
37
  ), this;
39
38
  }
40
- once(t, o) {
39
+ once(t, e) {
41
40
  return this.addEventListener(
42
41
  t,
43
- (e) => o(e.detail),
42
+ (o) => e(o.detail),
44
43
  {
45
44
  signal: this.controller.signal,
46
45
  once: !0
47
46
  }
48
47
  ), this;
49
48
  }
50
- emit(t, o) {
51
- return this.dispatchEvent(new CustomEvent(t, { detail: o }));
49
+ emit(t, e) {
50
+ return this.dispatchEvent(new CustomEvent(t, { detail: e }));
52
51
  }
53
52
  removeAllListeners() {
54
53
  this.controller.abort(), this.controller = new AbortController();
55
54
  }
56
55
  }
57
- const u = new M(), v = R()((n, t) => ({
56
+ const u = new R(), w = N()((n, t) => ({
58
57
  loadingCount: 0,
59
58
  overrideState: null,
60
59
  localCounters: {},
@@ -65,86 +64,60 @@ const u = new M(), v = R()((n, t) => ({
65
64
  isGlobalLoading() {
66
65
  return t().isLoading();
67
66
  },
68
- startLoading: (o) => {
69
- const e = t().isLoading();
70
- n((i) => ({ loadingCount: i.loadingCount + 1 })), o && n((i) => ({
67
+ startLoading: (e) => {
68
+ const o = t().isLoading();
69
+ n((r) => ({ loadingCount: r.loadingCount + 1 })), e && n((r) => ({
71
70
  localCounters: {
72
- ...i.localCounters,
73
- [o]: (i.localCounters[o] ?? 0) + 1
71
+ ...r.localCounters,
72
+ [e]: (r.localCounters[e] ?? 0) + 1
74
73
  }
75
74
  }));
76
- const r = t().isLoading();
77
- r && !e && u.emit("start", null), u.emit("change", { isLoading: r, isOverrideState: t().overrideState !== null });
75
+ const i = t().isLoading();
76
+ i && !o && u.emit("start", null), u.emit("change", { isLoading: i, isOverrideState: t().overrideState !== null });
78
77
  },
79
- stopLoading: (o) => {
80
- const e = t().isLoading(), r = o ? t().localCounters[o] ?? 0 : 0;
81
- o && r > 0 && n((d) => ({
78
+ stopLoading: (e) => {
79
+ const o = t().isLoading(), i = e ? t().localCounters[e] ?? 0 : 0;
80
+ e && i > 0 && n((d) => ({
82
81
  loadingCount: Math.max(0, d.loadingCount - 1),
83
82
  localCounters: {
84
83
  ...d.localCounters,
85
- [o]: Math.max(0, d.localCounters[o] - 1)
84
+ [e]: Math.max(0, d.localCounters[e] - 1)
86
85
  }
87
86
  }));
88
- const i = t().isLoading();
89
- !i && e && u.emit("stop", null), u.emit("change", { isLoading: i, isOverrideState: t().overrideState !== null });
90
- },
91
- overrideLoading: (o) => {
92
- const e = t().isLoading();
93
- n({ overrideState: o });
94
87
  const r = t().isLoading();
95
- r && !e ? u.emit("start", null) : !r && e && u.emit("stop", null), u.emit("change", { isLoading: r, isOverrideState: o !== null });
88
+ !r && o && u.emit("stop", null), u.emit("change", { isLoading: r, isOverrideState: t().overrideState !== null });
96
89
  },
97
- getLocalCounter: (o) => t().localCounters[o] ?? 0,
98
- isLocalLoading: (o) => (t().localCounters[o] ?? 0) > 0
90
+ overrideLoading: (e) => {
91
+ const o = t().isLoading();
92
+ n({ overrideState: e });
93
+ const i = t().isLoading();
94
+ i && !o ? u.emit("start", null) : !i && o && u.emit("stop", null), u.emit("change", { isLoading: i, isOverrideState: e !== null });
95
+ },
96
+ getLocalCounter: (e) => t().localCounters[e] ?? 0,
97
+ isLocalLoading: (e) => (t().localCounters[e] ?? 0) > 0
99
98
  }
100
99
  }));
101
- function U() {
102
- const n = E(), { actions: t } = v((i) => i), o = () => {
103
- t.startLoading(n);
104
- }, e = () => {
105
- t.isLocalLoading(n) && t.stopLoading(n);
106
- }, r = async (i) => {
107
- o();
108
- try {
109
- return await i;
110
- } finally {
111
- e();
112
- }
113
- };
114
- return {
115
- overrideLoading: t.overrideLoading,
116
- startLoading: o,
117
- stopLoading: e,
118
- get isLocalLoading() {
119
- return t.isLocalLoading(n);
120
- },
121
- asyncUseLoading: r,
122
- get isLoading() {
123
- return t.isGlobalLoading();
124
- }
125
- };
126
- }
127
- function q() {
128
- const n = O(), { actions: t } = v((i) => i), o = () => {
100
+ function M() {
101
+ const n = E(), { actions: t } = w((r) => r), e = () => {
129
102
  t.startLoading(n);
130
- }, e = () => {
103
+ }, o = () => {
131
104
  t.isLocalLoading(n) && t.stopLoading(n);
132
- }, r = async (i) => {
133
- o();
105
+ }, i = async (r) => {
106
+ e();
134
107
  try {
135
- return await i;
108
+ return await r;
136
109
  } finally {
137
- e();
110
+ o();
138
111
  }
139
112
  };
140
113
  return {
141
114
  overrideLoading: t.overrideLoading,
142
- startLoading: o,
143
- stopLoading: e,
115
+ startLoading: e,
116
+ stopLoading: o,
144
117
  get isLocalLoading() {
145
118
  return t.isLocalLoading(n);
146
119
  },
147
- asyncUseLoading: r,
120
+ asyncUseLoading: i,
148
121
  get isLoading() {
149
122
  return t.isGlobalLoading();
150
123
  }
@@ -154,32 +127,32 @@ const c = {
154
127
  Spin: "spin",
155
128
  FadeInOut: "fadeInOut",
156
129
  None: "none"
157
- }, z = ({ scale: n = 1, animationType: t = c.Spin, animationDuration: o, children: e, style: r, className: i, id: d, prefix: g }) => {
158
- const m = t, a = t === c.Spin ? 1 : t === c.FadeInOut ? 2 : 0, s = o || a, l = t === c.Spin ? "linear" : t === c.FadeInOut ? "ease-in-out" : "linear", p = t === c.None ? "none" : `${g}-${m} ${s}s ${l} infinite`;
159
- return /* @__PURE__ */ f("div", { style: { animation: p, ...n !== 1 ? { zoom: n } : {}, ...r }, className: i, id: d, children: e });
160
- }, D = (n) => /* @__PURE__ */ f("div", { id: "loading-circle", style: { width: "90px", height: "90px", border: "15px solid #f3f3f3", borderTop: "15px solid #009b4bff", borderRadius: "50%", boxSizing: "border-box" }, ...n }), G = (n) => /* @__PURE__ */ f("div", { style: { padding: "20px", fontSize: "25px", color: "#333", fontFamily: "system-ui, sans-serif" }, ...n, children: "Please wait..." });
161
- function H({
130
+ }, z = ({ scale: n = 1, animationType: t = c.Spin, animationDuration: e, children: o, style: i, className: r, id: d, prefix: g }) => {
131
+ const b = t, s = t === c.Spin ? 1 : t === c.FadeInOut ? 2 : 0, a = e || s, l = t === c.Spin ? "linear" : t === c.FadeInOut ? "ease-in-out" : "linear", m = t === c.None ? "none" : `${g}-${b} ${a}s ${l} infinite`;
132
+ return /* @__PURE__ */ f("div", { style: { animation: m, ...n !== 1 ? { zoom: n } : {}, ...i }, className: r, id: d, children: o });
133
+ }, P = (n) => /* @__PURE__ */ f("div", { id: "loading-circle", style: { width: "90px", height: "90px", border: "15px solid #f3f3f3", borderTop: "15px solid #009b4bff", borderRadius: "50%", boxSizing: "border-box" }, ...n }), D = (n) => /* @__PURE__ */ f("div", { style: { padding: "20px", fontSize: "25px", color: "#333", fontFamily: "system-ui, sans-serif" }, ...n, children: "Please wait..." });
134
+ function B({
162
135
  loadingComponent: n,
163
136
  loadingComponentScale: t = 1,
164
- animationType: o = c.Spin,
165
- animationDuration: e,
166
- wrapperStyle: r,
167
- wrapperClassName: i,
137
+ animationType: e = c.Spin,
138
+ animationDuration: o,
139
+ wrapperStyle: i,
140
+ wrapperClassName: r,
168
141
  wrapperId: d,
169
142
  animationWrapperStyle: g,
170
- animationWrapperClassName: m,
171
- animationWrapperId: a
143
+ animationWrapperClassName: b,
144
+ animationWrapperId: s
172
145
  }) {
173
- n = n || (o === c.Spin ? D : G);
174
- const s = y(Math.random().toString(36).substring(2, 6).replace(/[0-9]/g, "")), { loadingCount: l, overrideState: p } = v((I) => I), b = p ?? l > 0, S = y(null);
175
- w(() => {
176
- b ? (S.current?.showModal(), document.body.setAttribute("inert", "")) : (S.current?.close(), document.body.removeAttribute("inert"));
177
- }, [b]);
178
- const h = d || "loading-wrapper-" + s.current;
179
- return b ? A(
180
- /* @__PURE__ */ $(j, { children: [
146
+ n = n || (e === c.Spin ? P : D);
147
+ const a = v(Math.random().toString(36).substring(2, 6).replace(/[0-9]/g, "")), { loadingCount: l, overrideState: m } = w((I) => I), p = m ?? l > 0, h = v(null);
148
+ C(() => {
149
+ p ? (h.current?.showModal(), document.body.setAttribute("inert", "")) : (h.current?.close(), document.body.removeAttribute("inert"));
150
+ }, [p]);
151
+ const S = d || "loading-wrapper-" + a.current;
152
+ return p ? j(
153
+ /* @__PURE__ */ O($, { children: [
181
154
  /* @__PURE__ */ f("style", { children: `
182
- dialog#${h}[open] {
155
+ dialog#${S}[open] {
183
156
  display: flex !important;
184
157
  justify-content: center;
185
158
  align-items: center;
@@ -188,15 +161,15 @@ function H({
188
161
  max-width: 100%;
189
162
  max-height: 100%;
190
163
  }
191
- @keyframes ${s.current}-spin {
164
+ @keyframes ${a.current}-spin {
192
165
  0% { transform: rotate(0deg); }
193
166
  100% { transform: rotate(360deg); }
194
167
  }
195
- @keyframes ${s.current}-fadeInOut {
168
+ @keyframes ${a.current}-fadeInOut {
196
169
  0%, 100% { opacity: 0.2; }
197
170
  50% { opacity: 1; }
198
171
  }
199
- body:has(dialog#${h}[open]) {
172
+ body:has(dialog#${S}[open]) {
200
173
  overflow: hidden;
201
174
  }
202
175
  body {
@@ -206,37 +179,36 @@ function H({
206
179
  /* @__PURE__ */ f(
207
180
  "dialog",
208
181
  {
209
- ref: S,
182
+ ref: h,
210
183
  style: {
211
184
  border: "none",
212
185
  padding: 0,
213
186
  backgroundColor: "rgba(0, 0, 0, 0.5)",
214
187
  backdropFilter: "blur(2px)",
215
- ...r
188
+ ...i
216
189
  },
217
- className: i,
218
- id: h,
219
- children: /* @__PURE__ */ f(z, { scale: t, animationType: o, animationDuration: e, style: g, className: m, id: a, prefix: s.current, children: L.isValidElement(n) ? n : L.createElement(n) })
190
+ className: r,
191
+ id: S,
192
+ children: /* @__PURE__ */ f(z, { scale: t, animationType: e, animationDuration: o, style: g, className: b, id: s, prefix: a.current, children: L.isValidElement(n) ? n : L.createElement(n) })
220
193
  }
221
194
  )
222
195
  ] }),
223
196
  document.body
224
197
  ) : null;
225
198
  }
226
- function J({ isLoading: n = !1 }) {
227
- const { startLoading: t, stopLoading: o } = U();
228
- return w(() => (n ? t() : o(), () => {
229
- n && o();
199
+ function U({ isLoading: n = !1 }) {
200
+ const { startLoading: t, stopLoading: e } = M();
201
+ return C(() => (n ? t() : e(), () => {
202
+ n && e();
230
203
  }), [n]), null;
231
204
  }
232
205
  export {
233
206
  c as AnimationType,
234
- M as EventEmitter,
235
- J as Loading,
236
- D as LoadingCircle,
237
- G as LoadingPleaseWait,
238
- H as LoadingRenderer,
207
+ R as EventEmitter,
208
+ U as Loading,
209
+ P as LoadingCircle,
210
+ D as LoadingPleaseWait,
211
+ B as LoadingRenderer,
239
212
  u as loadingEventTarget,
240
- q as ssrLoading,
241
- U as useLoading
213
+ M as useLoading
242
214
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokku-x/react-hook-loading-spinner",
3
- "version": "0.2.1",
3
+ "version": "0.2.5",
4
4
  "description": "A lightweight and flexible React loading state hook library with built-in spinner components, global state management, and zero dependencies (except React and Zustand).",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -1,9 +0,0 @@
1
- export default function ssrLoading(): {
2
- overrideLoading: (state: boolean | null) => void;
3
- startLoading: () => void;
4
- stopLoading: () => void;
5
- readonly isLocalLoading: boolean;
6
- asyncUseLoading: <R, _ extends any[]>(asyncFunction: Promise<R>) => Promise<R>;
7
- readonly isLoading: boolean;
8
- };
9
- export * from '../store/loadingStore';