@zenpatient-org/healthspan-marketing-ui 1.0.21 → 1.0.22
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 client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),o=require("react"),l=require("../../components/ChatMessage/chatMessage.module.css"),L=require("../Typography/Typography.cjs.js"),Q="(prefers-reduced-motion: reduce)",z=[900,1150],le=180,ce=130,de=140,ue=36,he=220,fe=new Set("th he in er an re on at en nd ou ea ha to it is or ti as te ng of al ar st se le ve me yo wh ch ll".split(" ")),me=c=>{const n=window.matchMedia(Q);return n.addEventListener("change",c),()=>n.removeEventListener("change",c)},pe=()=>window.matchMedia(Q).matches,ge=c=>{let n=Array.from(c).reduce((e,t)=>Math.imul(e^t.charCodeAt(0),16777619),2166136261);return()=>{n=n+1831565813|0;let e=Math.imul(n^n>>>15,1|n);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}},Se=(c,n)=>{const e=ge(n),t=(d,f)=>d+e()*(f-d);let E=0,u=0;return c.split("").map((d,f)=>{var i;const m=(i=c[f-1])!=null?i:"";let a;return f===0?a=0:/[.?!…]/.test(m)?a=t(180,260):/[,;:—]/.test(m)?a=t(120,180):d===" "?a=t(20,35):u>0?(u--,a=t(22,32)):fe.has((m+d).toLowerCase())?a=t(24,36):e()<.15?(u=2+Math.floor(e()*3),a=t(22,32)):a=t(35,60),m===" "&&e()<.08&&(a+=t(60,110)),E+=a})},ve=c=>{const n=c.querySelector("p"),e=n.firstChild,t=e.textContent,E=n.getBoundingClientRect().left,u=getComputedStyle(c),d=parseFloat(u.paddingLeft)+parseFloat(u.paddingRight),f=document.createRange(),m=[0],a=[];let i,x=0;for(let h=0;h<t.length;h++){if(!/\s/.test(t[h])){f.setStart(e,h),f.setEnd(e,h+1);const y=f.getBoundingClientRect();i!==void 0&&y.top>i+1&&m.push(h),i=y.top,x=Math.max(x,y.right-E)}a.push(x)}return a[a.length-1]=c.getBoundingClientRect().width-d,{lineStarts:m,widths:a,lineHeight:parseFloat(getComputedStyle(n).lineHeight),padX:d,padY:parseFloat(u.paddingTop)+parseFloat(u.paddingBottom)}},J=(c,n)=>c.filter((e,t)=>t===0||e<n),xe=({sender:c,avatar:n,children:e,typing:t=!1,attachment:E,thinking:u,typeOut:d=!1,seed:f,onTyped:m})=>{var V,D;const a=o.useSyncExternalStore(me,pe,()=>!1),[i,x]=o.useState(),[h,y]=o.useState(!1),[T,W]=o.useState(0),[w,Z]=o.useState(!1),[j,k]=o.useState(!d),[ee,$]=o.useState(!d),[p,te]=o.useState(),[B,se]=o.useState(0),[ae,ne]=o.useState(!1),b=o.useRef(null),P=o.useRef(null);u!=null&&u.length?(u!==i&&x(u),h&&y(!1)):i&&!h&&(a?x(void 0):(y(!0),Z(!0)));const g=typeof e=="string"?e:"",X=(t||!!e)&&(!i||h),A=d&&!ee&&!t&&!!g&&X,M=A&&!a,F=(V=i==null?void 0:i.length)!=null?V:0;o.useEffect(()=>{if(h||T>=F-1)return;const r=z[Math.min(T,z.length-1)],S=setTimeout(()=>W(T+1),r);return()=>clearTimeout(S)},[h,T,F]);const I=o.useEffectEvent(()=>{k(!0),m==null||m()});o.useEffect(()=>{d&&!g&&!i&&!j&&I()},[d,g,i,j]),o.useLayoutEffect(()=>{if(!M)return;const r=ve(P.current);b.current.style.width=`${r.padX}px`,b.current.style.height=`${r.padY+r.lineHeight}px`,te(r)},[M,g]),o.useEffect(()=>{if(!A)return;if(a){I(),$(!0);return}if(!p)return;const r=b.current,S=Se(g,f!=null?f:g),_=performance.now()+(w?le:0)+ce;let q=p.padX,C,R,H=0;const K=N=>{var U;const v=S.filter(oe=>oe<=N-_).length,O=S[v]-((U=S[v-1])!=null?U:0),ie=p.padX+(v?p.widths[v-1]:0),re=O<ue?30:45;if(q+=(ie-q)*(1-Math.exp(-(N-(C!=null?C:N))/re)),C=N,r.style.width=`${q}px`,r.style.height=`${p.padY+p.lineHeight*J(p.lineStarts,v).length}px`,se(v),ne(v>0&&O>=de),v===S.length&&(R!=null||(R=N),R===N&&I(),N-R>=he)){r.style.width="",r.style.height="",$(!0);return}H=requestAnimationFrame(K)};return H=requestAnimationFrame(K),()=>cancelAnimationFrame(H)},[A,a,p,g,f,w]);const Y=(D=p==null?void 0:p.lineStarts)!=null?D:[0],G=J(Y,B);return s.jsxs("div",{className:l.root,children:[s.jsx("span",{className:l.avatar,children:s.jsx("img",{src:n,alt:"",className:l.avatarImage})}),s.jsxs("div",{className:l.content,children:[s.jsxs("div",{className:l.message,children:[s.jsx(L.Typography,{as:"p",defaultVariant:"bodySm",weight:"medium",className:l.sender,children:c}),s.jsxs("div",{className:l.slot,children:[i&&s.jsx("div",{className:l.status,"data-leaving":h||void 0,onAnimationEnd:()=>{h&&(y(!1),x(void 0))},children:i.map((r,S)=>s.jsx("span",{className:l.statusLine,"data-active":S===Math.min(T,F-1)||void 0,children:s.jsx(L.Typography,{defaultVariant:"headingXxs",children:r})},r))}),X&&s.jsx("div",{ref:b,className:l.bubble,"aria-live":t?"polite":void 0,"aria-hidden":d&&!t||void 0,"data-enter":M?w?"after-thinking":"direct":void 0,"data-typing":M||void 0,children:s.jsx(L.Typography,{as:"p",defaultVariant:"bodySm",className:l.text,children:t?s.jsxs("span",{role:"img","aria-label":`${c} is typing`,className:l.typing,children:[s.jsx("span",{children:"."}),s.jsx("span",{children:"."}),s.jsx("span",{children:"."})]}):M?G.map((r,S)=>{var _;return s.jsxs("span",{className:l.line,children:[g.slice(r,Math.min((_=Y[S+1])!=null?_:g.length,B)).trimEnd(),S===G.length-1&&s.jsx("span",{className:l.caret,"data-paused":ae&&!j||void 0,"data-ending":j||void 0})]},r)}):e})})]}),M&&s.jsx("div",{ref:P,className:`${l.bubble} ${l.measure}`,"aria-hidden":!0,children:s.jsx(L.Typography,{as:"p",defaultVariant:"bodySm",children:g})}),d&&s.jsx("span",{className:l.srOnly,"aria-live":"polite",children:j?g:""})]}),E]})]})};exports.ChatMessage=xe;
|
|
@@ -1,152 +1,154 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs as R, jsx as
|
|
3
|
-
import { useSyncExternalStore as ue, useState as v, useRef as
|
|
4
|
-
import
|
|
5
|
-
import { Typography as
|
|
2
|
+
import { jsxs as R, jsx as c } from "react/jsx-runtime";
|
|
3
|
+
import { useSyncExternalStore as ue, useState as v, useRef as Q, useEffect as X, useEffectEvent as he, useLayoutEffect as me } from "react";
|
|
4
|
+
import r from "../../components/ChatMessage/chatMessage.module.css";
|
|
5
|
+
import { Typography as C } from "../Typography/Typography.es.js";
|
|
6
6
|
const k = "(prefers-reduced-motion: reduce)", W = [900, 1150], fe = 180, pe = 130, ge = 140, ve = 36, Se = 220, Ne = new Set(
|
|
7
7
|
"th he in er an re on at en nd ou ea ha to it is or ti as te ng of al ar st se le ve me yo wh ch ll".split(" ")
|
|
8
|
-
), Me = (
|
|
8
|
+
), Me = (l) => {
|
|
9
9
|
const a = window.matchMedia(k);
|
|
10
|
-
return a.addEventListener("change",
|
|
11
|
-
}, Ee = () => window.matchMedia(k).matches, ye = (
|
|
12
|
-
let a = Array.from(
|
|
10
|
+
return a.addEventListener("change", l), () => a.removeEventListener("change", l);
|
|
11
|
+
}, Ee = () => window.matchMedia(k).matches, ye = (l) => {
|
|
12
|
+
let a = Array.from(l).reduce((e, t) => Math.imul(e ^ t.charCodeAt(0), 16777619), 2166136261);
|
|
13
13
|
return () => {
|
|
14
14
|
a = a + 1831565813 | 0;
|
|
15
15
|
let e = Math.imul(a ^ a >>> 15, 1 | a);
|
|
16
16
|
return e = e + Math.imul(e ^ e >>> 7, 61 | e) ^ e, ((e ^ e >>> 14) >>> 0) / 4294967296;
|
|
17
17
|
};
|
|
18
|
-
}, Re = (
|
|
19
|
-
const e = ye(a), t = (
|
|
20
|
-
let T = 0,
|
|
21
|
-
return
|
|
22
|
-
var
|
|
23
|
-
const m = (
|
|
18
|
+
}, Re = (l, a) => {
|
|
19
|
+
const e = ye(a), t = (o, h) => o + e() * (h - o);
|
|
20
|
+
let T = 0, d = 0;
|
|
21
|
+
return l.split("").map((o, h) => {
|
|
22
|
+
var n;
|
|
23
|
+
const m = (n = l[h - 1]) != null ? n : "";
|
|
24
24
|
let s;
|
|
25
|
-
return h === 0 ? s = 0 : /[.?!…]/.test(m) ? s = t(180, 260) : /[,;:—]/.test(m) ? s = t(120, 180) :
|
|
25
|
+
return h === 0 ? s = 0 : /[.?!…]/.test(m) ? s = t(180, 260) : /[,;:—]/.test(m) ? s = t(120, 180) : o === " " ? s = t(20, 35) : d > 0 ? (d--, s = t(22, 32)) : Ne.has((m + o).toLowerCase()) ? s = t(24, 36) : e() < 0.15 ? (d = 2 + Math.floor(e() * 3), s = t(22, 32)) : s = t(35, 60), m === " " && e() < 0.08 && (s += t(60, 110)), T += s;
|
|
26
26
|
});
|
|
27
|
-
}, Te = (
|
|
28
|
-
const a =
|
|
29
|
-
let
|
|
27
|
+
}, Te = (l) => {
|
|
28
|
+
const a = l.querySelector("p"), e = a.firstChild, t = e.textContent, T = a.getBoundingClientRect().left, d = getComputedStyle(l), o = parseFloat(d.paddingLeft) + parseFloat(d.paddingRight), h = document.createRange(), m = [0], s = [];
|
|
29
|
+
let n, N = 0;
|
|
30
30
|
for (let u = 0; u < t.length; u++) {
|
|
31
31
|
if (!/\s/.test(t[u])) {
|
|
32
32
|
h.setStart(e, u), h.setEnd(e, u + 1);
|
|
33
33
|
const M = h.getBoundingClientRect();
|
|
34
|
-
|
|
34
|
+
n !== void 0 && M.top > n + 1 && m.push(u), n = M.top, N = Math.max(N, M.right - T);
|
|
35
35
|
}
|
|
36
36
|
s.push(N);
|
|
37
37
|
}
|
|
38
|
-
return s[s.length - 1] =
|
|
38
|
+
return s[s.length - 1] = l.getBoundingClientRect().width - o, {
|
|
39
39
|
lineStarts: m,
|
|
40
40
|
widths: s,
|
|
41
41
|
lineHeight: parseFloat(getComputedStyle(a).lineHeight),
|
|
42
|
-
padX:
|
|
43
|
-
padY: parseFloat(
|
|
42
|
+
padX: o,
|
|
43
|
+
padY: parseFloat(d.paddingTop) + parseFloat(d.paddingBottom)
|
|
44
44
|
};
|
|
45
|
-
}, Z = (
|
|
46
|
-
sender:
|
|
45
|
+
}, Z = (l, a) => l.filter((e, t) => t === 0 || e < a), we = ({
|
|
46
|
+
sender: l,
|
|
47
47
|
avatar: a,
|
|
48
48
|
children: e,
|
|
49
49
|
typing: t = !1,
|
|
50
50
|
attachment: T,
|
|
51
|
-
thinking:
|
|
52
|
-
typeOut:
|
|
51
|
+
thinking: d,
|
|
52
|
+
typeOut: o = !1,
|
|
53
53
|
seed: h,
|
|
54
54
|
onTyped: m
|
|
55
55
|
}) => {
|
|
56
|
-
var
|
|
57
|
-
const s = ue(Me, Ee, () => !1), [
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
56
|
+
var K, U;
|
|
57
|
+
const s = ue(Me, Ee, () => !1), [n, N] = v(), [u, M] = v(!1), [b, ee] = v(0), [F, te] = v(!1), [x, se] = v(!o), [ae, Y] = v(!o), [f, ne] = v(), [q, ie] = v(0), [re, le] = v(!1), _ = Q(null), G = Q(null);
|
|
58
|
+
d != null && d.length ? (d !== n && N(d), u && M(!1)) : n && !u && (s ? N(void 0) : (M(!0), te(!0)));
|
|
59
|
+
const p = typeof e == "string" ? e : "", V = (t || !!e) && (!n || u), I = o && !ae && !t && !!p && V, y = I && !s, H = (K = n == null ? void 0 : n.length) != null ? K : 0;
|
|
60
|
+
X(() => {
|
|
61
61
|
if (u || b >= H - 1) return;
|
|
62
|
-
const
|
|
63
|
-
return () => clearTimeout(
|
|
62
|
+
const i = W[Math.min(b, W.length - 1)], g = setTimeout(() => ee(b + 1), i);
|
|
63
|
+
return () => clearTimeout(g);
|
|
64
64
|
}, [u, b, H]);
|
|
65
|
-
const
|
|
65
|
+
const $ = he(() => {
|
|
66
66
|
se(!0), m == null || m();
|
|
67
67
|
});
|
|
68
|
-
|
|
68
|
+
X(() => {
|
|
69
|
+
o && !p && !n && !x && $();
|
|
70
|
+
}, [o, p, n, x]), me(() => {
|
|
69
71
|
if (!y) return;
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
}, [y,
|
|
72
|
+
const i = Te(G.current);
|
|
73
|
+
_.current.style.width = `${i.padX}px`, _.current.style.height = `${i.padY + i.lineHeight}px`, ne(i);
|
|
74
|
+
}, [y, p]), X(() => {
|
|
73
75
|
if (!I) return;
|
|
74
76
|
if (s) {
|
|
75
|
-
|
|
77
|
+
$(), Y(!0);
|
|
76
78
|
return;
|
|
77
79
|
}
|
|
78
80
|
if (!f) return;
|
|
79
|
-
const
|
|
80
|
-
let
|
|
81
|
-
const
|
|
82
|
-
var
|
|
83
|
-
const S =
|
|
84
|
-
if (
|
|
85
|
-
|
|
81
|
+
const i = _.current, g = Re(p, h != null ? h : p), w = performance.now() + (F ? fe : 0) + pe;
|
|
82
|
+
let B = f.padX, A, L, P = 0;
|
|
83
|
+
const O = (E) => {
|
|
84
|
+
var J;
|
|
85
|
+
const S = g.filter((de) => de <= E - w).length, z = g[S] - ((J = g[S - 1]) != null ? J : 0), oe = f.padX + (S ? f.widths[S - 1] : 0), ce = z < ve ? 30 : 45;
|
|
86
|
+
if (B += (oe - B) * (1 - Math.exp(-(E - (A != null ? A : E)) / ce)), A = E, i.style.width = `${B}px`, i.style.height = `${f.padY + f.lineHeight * Z(f.lineStarts, S).length}px`, ie(S), le(S > 0 && z >= ge), S === g.length && (L != null || (L = E), L === E && $(), E - L >= Se)) {
|
|
87
|
+
i.style.width = "", i.style.height = "", Y(!0);
|
|
86
88
|
return;
|
|
87
89
|
}
|
|
88
|
-
|
|
90
|
+
P = requestAnimationFrame(O);
|
|
89
91
|
};
|
|
90
|
-
return
|
|
91
|
-
}, [I, s, f,
|
|
92
|
-
const
|
|
93
|
-
return /* @__PURE__ */ R("div", { className:
|
|
94
|
-
/* @__PURE__ */
|
|
95
|
-
/* @__PURE__ */ R("div", { className:
|
|
96
|
-
/* @__PURE__ */ R("div", { className:
|
|
97
|
-
/* @__PURE__ */
|
|
98
|
-
/* @__PURE__ */ R("div", { className:
|
|
99
|
-
|
|
92
|
+
return P = requestAnimationFrame(O), () => cancelAnimationFrame(P);
|
|
93
|
+
}, [I, s, f, p, h, F]);
|
|
94
|
+
const D = (U = f == null ? void 0 : f.lineStarts) != null ? U : [0], j = Z(D, q);
|
|
95
|
+
return /* @__PURE__ */ R("div", { className: r.root, children: [
|
|
96
|
+
/* @__PURE__ */ c("span", { className: r.avatar, children: /* @__PURE__ */ c("img", { src: a, alt: "", className: r.avatarImage }) }),
|
|
97
|
+
/* @__PURE__ */ R("div", { className: r.content, children: [
|
|
98
|
+
/* @__PURE__ */ R("div", { className: r.message, children: [
|
|
99
|
+
/* @__PURE__ */ c(C, { as: "p", defaultVariant: "bodySm", weight: "medium", className: r.sender, children: l }),
|
|
100
|
+
/* @__PURE__ */ R("div", { className: r.slot, children: [
|
|
101
|
+
n && /* @__PURE__ */ c(
|
|
100
102
|
"div",
|
|
101
103
|
{
|
|
102
|
-
className:
|
|
104
|
+
className: r.status,
|
|
103
105
|
"data-leaving": u || void 0,
|
|
104
106
|
onAnimationEnd: () => {
|
|
105
107
|
u && (M(!1), N(void 0));
|
|
106
108
|
},
|
|
107
|
-
children:
|
|
109
|
+
children: n.map((i, g) => /* @__PURE__ */ c(
|
|
108
110
|
"span",
|
|
109
111
|
{
|
|
110
|
-
className:
|
|
111
|
-
"data-active":
|
|
112
|
-
children: /* @__PURE__ */
|
|
112
|
+
className: r.statusLine,
|
|
113
|
+
"data-active": g === Math.min(b, H - 1) || void 0,
|
|
114
|
+
children: /* @__PURE__ */ c(C, { defaultVariant: "headingXxs", children: i })
|
|
113
115
|
},
|
|
114
|
-
|
|
116
|
+
i
|
|
115
117
|
))
|
|
116
118
|
}
|
|
117
119
|
),
|
|
118
|
-
|
|
120
|
+
V && /* @__PURE__ */ c(
|
|
119
121
|
"div",
|
|
120
122
|
{
|
|
121
|
-
ref:
|
|
122
|
-
className:
|
|
123
|
+
ref: _,
|
|
124
|
+
className: r.bubble,
|
|
123
125
|
"aria-live": t ? "polite" : void 0,
|
|
124
|
-
"aria-hidden":
|
|
125
|
-
"data-enter": y ?
|
|
126
|
+
"aria-hidden": o && !t || void 0,
|
|
127
|
+
"data-enter": y ? F ? "after-thinking" : "direct" : void 0,
|
|
126
128
|
"data-typing": y || void 0,
|
|
127
|
-
children: /* @__PURE__ */
|
|
128
|
-
/* @__PURE__ */
|
|
129
|
-
/* @__PURE__ */
|
|
130
|
-
/* @__PURE__ */
|
|
131
|
-
] }) : y ?
|
|
132
|
-
var
|
|
133
|
-
return /* @__PURE__ */ R("span", { className:
|
|
134
|
-
|
|
135
|
-
|
|
129
|
+
children: /* @__PURE__ */ c(C, { as: "p", defaultVariant: "bodySm", className: r.text, children: t ? /* @__PURE__ */ R("span", { role: "img", "aria-label": `${l} is typing`, className: r.typing, children: [
|
|
130
|
+
/* @__PURE__ */ c("span", { children: "." }),
|
|
131
|
+
/* @__PURE__ */ c("span", { children: "." }),
|
|
132
|
+
/* @__PURE__ */ c("span", { children: "." })
|
|
133
|
+
] }) : y ? j.map((i, g) => {
|
|
134
|
+
var w;
|
|
135
|
+
return /* @__PURE__ */ R("span", { className: r.line, children: [
|
|
136
|
+
p.slice(i, Math.min((w = D[g + 1]) != null ? w : p.length, q)).trimEnd(),
|
|
137
|
+
g === j.length - 1 && /* @__PURE__ */ c(
|
|
136
138
|
"span",
|
|
137
139
|
{
|
|
138
|
-
className:
|
|
139
|
-
"data-paused": re && !
|
|
140
|
-
"data-ending":
|
|
140
|
+
className: r.caret,
|
|
141
|
+
"data-paused": re && !x || void 0,
|
|
142
|
+
"data-ending": x || void 0
|
|
141
143
|
}
|
|
142
144
|
)
|
|
143
|
-
] },
|
|
145
|
+
] }, i);
|
|
144
146
|
}) : e })
|
|
145
147
|
}
|
|
146
148
|
)
|
|
147
149
|
] }),
|
|
148
|
-
y && /* @__PURE__ */
|
|
149
|
-
|
|
150
|
+
y && /* @__PURE__ */ c("div", { ref: G, className: `${r.bubble} ${r.measure}`, "aria-hidden": !0, children: /* @__PURE__ */ c(C, { as: "p", defaultVariant: "bodySm", children: p }) }),
|
|
151
|
+
o && /* @__PURE__ */ c("span", { className: r.srOnly, "aria-live": "polite", children: x ? p : "" })
|
|
150
152
|
] }),
|
|
151
153
|
T
|
|
152
154
|
] })
|