@forgedevstack/bear 1.1.0 → 1.1.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),t=require("react"),X=require("../../utils/cn.cjs"),e=require("./Typewriter.const.cjs"),k=g=>{const{text:I,speed:T=e.DEFAULT_SPEED,startDelay:C=e.DEFAULT_START_DELAY,deleteDelay:N=e.DEFAULT_DELETE_DELAY,deleteSpeed:R=e.DEFAULT_DELETE_SPEED,loop:d=!1,cursor:f=!0,cursorChar:U=e.DEFAULT_CURSOR_CHAR,cursorBlinkSpeed:y=e.DEFAULT_CURSOR_BLINK_SPEED,onComplete:n,onWordComplete:o,as:j="span",className:w,style:F,testId:H}=g,a=t.useMemo(()=>Array.isArray(I)?I:[I],[I]),[v,L]=t.useState(""),[p,S]=t.useState(e.INITIAL_TEXT_INDEX),[m,E]=t.useState(e.INITIAL_CHAR_INDEX),[b,h]=t.useState(!1),[B,q]=t.useState(!0),s=t.useRef(),_=t.useRef(p),c=t.useRef(m),D=t.useRef(b);_.current=p,c.current=m,D.current=b,t.useEffect(()=>{if(!f)return;const l=setInterval(()=>q(i=>!i),y);return()=>clearInterval(l)},[f,y]);const u=t.useCallback(()=>{const l=_.current,i=c.current,P=D.current,A=a[l];if(P)if(i>0){const r=i-1;E(r),c.current=r,L(A.slice(0,r)),s.current=setTimeout(u,R)}else{h(!1),D.current=!1;const r=l+1;r>=a.length?d?(S(e.INITIAL_TEXT_INDEX),_.current=e.INITIAL_TEXT_INDEX,E(e.INITIAL_CHAR_INDEX),c.current=e.INITIAL_CHAR_INDEX,s.current=setTimeout(u,T)):n==null||n():(S(r),_.current=r,E(e.INITIAL_CHAR_INDEX),c.current=e.INITIAL_CHAR_INDEX,s.current=setTimeout(u,T))}else if(i<A.length){const r=i+1;L(A.slice(0,r)),E(r),c.current=r,s.current=setTimeout(u,T)}else{if(o==null||o(l),a.length===1&&!d){n==null||n();return}s.current=setTimeout(()=>{h(!0),D.current=!0,u()},N)}},[a,T,R,N,d,n,o]);return t.useEffect(()=>(s.current=setTimeout(u,C),()=>{s.current&&clearTimeout(s.current)}),[]),x.jsxs(j,{className:X.cn("Bear-Typewriter","bear-inline",w),style:F,"data-testid":H,"aria-label":a.join(", "),children:[x.jsx("span",{className:"Bear-Typewriter__text",children:v}),f&&x.jsx("span",{className:X.cn("Bear-Typewriter__cursor","bear-inline-block bear-ml-0.5","bear-text-[var(--bear-primary-500)]"),style:{opacity:B?1:0},"aria-hidden":"true",children:U})]})};exports.Typewriter=k;
|
|
@@ -1,82 +1,76 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { cn as
|
|
4
|
-
import { DEFAULT_SPEED as
|
|
5
|
-
const
|
|
1
|
+
import { jsxs as K, jsx as U } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as M, useState as u, useRef as D, useEffect as F, useCallback as q } from "react";
|
|
3
|
+
import { cn as B } from "../../utils/cn.js";
|
|
4
|
+
import { DEFAULT_SPEED as z, DEFAULT_START_DELAY as G, DEFAULT_DELETE_DELAY as J, DEFAULT_DELETE_SPEED as Q, DEFAULT_CURSOR_CHAR as Z, DEFAULT_CURSOR_BLINK_SPEED as $, INITIAL_TEXT_INDEX as p, INITIAL_CHAR_INDEX as l } from "./Typewriter.const.js";
|
|
5
|
+
const se = (v) => {
|
|
6
6
|
const {
|
|
7
|
-
text:
|
|
8
|
-
speed:
|
|
9
|
-
startDelay:
|
|
10
|
-
deleteDelay:
|
|
11
|
-
deleteSpeed:
|
|
12
|
-
loop:
|
|
13
|
-
cursor:
|
|
14
|
-
cursorChar:
|
|
15
|
-
cursorBlinkSpeed:
|
|
16
|
-
onComplete:
|
|
17
|
-
onWordComplete:
|
|
18
|
-
as:
|
|
19
|
-
className:
|
|
20
|
-
style:
|
|
21
|
-
testId:
|
|
22
|
-
} =
|
|
23
|
-
|
|
24
|
-
if (!
|
|
25
|
-
const
|
|
26
|
-
return () => clearInterval(
|
|
27
|
-
}, [
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
if (c > 0)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
7
|
+
text: o,
|
|
8
|
+
speed: T = z,
|
|
9
|
+
startDelay: w = G,
|
|
10
|
+
deleteDelay: y = J,
|
|
11
|
+
deleteSpeed: A = Q,
|
|
12
|
+
loop: I = !1,
|
|
13
|
+
cursor: _ = !0,
|
|
14
|
+
cursorChar: C = Z,
|
|
15
|
+
cursorBlinkSpeed: L = $,
|
|
16
|
+
onComplete: r,
|
|
17
|
+
onWordComplete: E,
|
|
18
|
+
as: j = "span",
|
|
19
|
+
className: k,
|
|
20
|
+
style: P,
|
|
21
|
+
testId: X
|
|
22
|
+
} = v, i = M(() => Array.isArray(o) ? o : [o], [o]), [H, R] = u(""), [h, b] = u(p), [N, d] = u(l), [S, g] = u(!1), [O, V] = u(!0), t = D(), f = D(h), s = D(N), x = D(S);
|
|
23
|
+
f.current = h, s.current = N, x.current = S, F(() => {
|
|
24
|
+
if (!_) return;
|
|
25
|
+
const a = setInterval(() => V((c) => !c), L);
|
|
26
|
+
return () => clearInterval(a);
|
|
27
|
+
}, [_, L]);
|
|
28
|
+
const n = q(() => {
|
|
29
|
+
const a = f.current, c = s.current, Y = x.current, m = i[a];
|
|
30
|
+
if (Y)
|
|
31
|
+
if (c > 0) {
|
|
32
|
+
const e = c - 1;
|
|
33
|
+
d(e), s.current = e, R(m.slice(0, e)), t.current = setTimeout(n, A);
|
|
34
|
+
} else {
|
|
35
|
+
g(!1), x.current = !1;
|
|
36
|
+
const e = a + 1;
|
|
37
|
+
e >= i.length ? I ? (b(p), f.current = p, d(l), s.current = l, t.current = setTimeout(n, T)) : r == null || r() : (b(e), f.current = e, d(l), s.current = l, t.current = setTimeout(n, T));
|
|
37
38
|
}
|
|
38
|
-
else if (c <
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
else if (c < m.length) {
|
|
40
|
+
const e = c + 1;
|
|
41
|
+
R(m.slice(0, e)), d(e), s.current = e, t.current = setTimeout(n, T);
|
|
42
|
+
} else {
|
|
43
|
+
if (E == null || E(a), i.length === 1 && !I) {
|
|
44
|
+
r == null || r();
|
|
43
45
|
return;
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
47
|
+
t.current = setTimeout(() => {
|
|
48
|
+
g(!0), x.current = !0, n();
|
|
49
|
+
}, y);
|
|
48
50
|
}
|
|
49
|
-
}, [i,
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
}, []), _(() => {
|
|
56
|
-
if (D.current)
|
|
57
|
-
return e.current && clearTimeout(e.current), e.current = setTimeout(s, T ? E : n), () => {
|
|
58
|
-
e.current && clearTimeout(e.current);
|
|
59
|
-
};
|
|
60
|
-
}, [T, a]), /* @__PURE__ */ P(
|
|
61
|
-
F,
|
|
51
|
+
}, [i, T, A, y, I, r, E]);
|
|
52
|
+
return F(() => (t.current = setTimeout(n, w), () => {
|
|
53
|
+
t.current && clearTimeout(t.current);
|
|
54
|
+
}), []), /* @__PURE__ */ K(
|
|
55
|
+
j,
|
|
62
56
|
{
|
|
63
|
-
className:
|
|
64
|
-
style:
|
|
65
|
-
"data-testid":
|
|
57
|
+
className: B("Bear-Typewriter", "bear-inline", k),
|
|
58
|
+
style: P,
|
|
59
|
+
"data-testid": X,
|
|
66
60
|
"aria-label": i.join(", "),
|
|
67
61
|
children: [
|
|
68
|
-
/* @__PURE__ */
|
|
69
|
-
|
|
62
|
+
/* @__PURE__ */ U("span", { className: "Bear-Typewriter__text", children: H }),
|
|
63
|
+
_ && /* @__PURE__ */ U(
|
|
70
64
|
"span",
|
|
71
65
|
{
|
|
72
|
-
className:
|
|
66
|
+
className: B(
|
|
73
67
|
"Bear-Typewriter__cursor",
|
|
74
68
|
"bear-inline-block bear-ml-0.5",
|
|
75
69
|
"bear-text-[var(--bear-primary-500)]"
|
|
76
70
|
),
|
|
77
|
-
style: { opacity:
|
|
71
|
+
style: { opacity: O ? 1 : 0 },
|
|
78
72
|
"aria-hidden": "true",
|
|
79
|
-
children:
|
|
73
|
+
children: C
|
|
80
74
|
}
|
|
81
75
|
)
|
|
82
76
|
]
|
|
@@ -84,5 +78,5 @@ const Z = (S) => {
|
|
|
84
78
|
);
|
|
85
79
|
};
|
|
86
80
|
export {
|
|
87
|
-
|
|
81
|
+
se as Typewriter
|
|
88
82
|
};
|
package/package.json
CHANGED