@asgard-js/react 0.0.3 → 0.0.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.
Files changed (44) hide show
  1. package/README.md +85 -4
  2. package/dist/components/chatbot/chatbot-body.d.ts.map +1 -1
  3. package/dist/components/chatbot/chatbot-footer/chatbot-footer.d.ts.map +1 -0
  4. package/dist/components/chatbot/chatbot-footer/index.d.ts +2 -0
  5. package/dist/components/chatbot/chatbot-footer/index.d.ts.map +1 -0
  6. package/dist/components/chatbot/chatbot-footer/speech-input-button.d.ts +9 -0
  7. package/dist/components/chatbot/chatbot-footer/speech-input-button.d.ts.map +1 -0
  8. package/dist/components/chatbot/chatbot-header.d.ts +2 -0
  9. package/dist/components/chatbot/chatbot-header.d.ts.map +1 -1
  10. package/dist/components/chatbot/chatbot.d.ts +6 -3
  11. package/dist/components/chatbot/chatbot.d.ts.map +1 -1
  12. package/dist/components/chatbot/profile-icon.d.ts.map +1 -1
  13. package/dist/components/conversation-message-renderer/conversation-message-renderer.d.ts +1 -1
  14. package/dist/components/conversation-message-renderer/conversation-message-renderer.d.ts.map +1 -1
  15. package/dist/components/templates/avatar/avatar.d.ts +5 -1
  16. package/dist/components/templates/avatar/avatar.d.ts.map +1 -1
  17. package/dist/components/templates/bot-typing-box/bot-typing-box.d.ts +2 -2
  18. package/dist/components/templates/bot-typing-box/bot-typing-box.d.ts.map +1 -1
  19. package/dist/components/templates/bot-typing-box/bot-typing-placeholder.d.ts +8 -0
  20. package/dist/components/templates/bot-typing-box/bot-typing-placeholder.d.ts.map +1 -0
  21. package/dist/components/templates/bot-typing-box/index.d.ts +1 -0
  22. package/dist/components/templates/bot-typing-box/index.d.ts.map +1 -1
  23. package/dist/components/templates/button-template/button-template.d.ts +1 -1
  24. package/dist/components/templates/button-template/button-template.d.ts.map +1 -1
  25. package/dist/components/templates/button-template/card.d.ts.map +1 -1
  26. package/dist/components/templates/carousel-template/carousel-template.d.ts +1 -1
  27. package/dist/components/templates/carousel-template/carousel-template.d.ts.map +1 -1
  28. package/dist/components/templates/hint-template/hint-template.d.ts +1 -1
  29. package/dist/components/templates/hint-template/hint-template.d.ts.map +1 -1
  30. package/dist/components/templates/text-template/text-template.d.ts +1 -1
  31. package/dist/components/templates/text-template/text-template.d.ts.map +1 -1
  32. package/dist/context/asgard-service-context.d.ts +8 -3
  33. package/dist/context/asgard-service-context.d.ts.map +1 -1
  34. package/dist/context/asgard-theme-context.d.ts +17 -0
  35. package/dist/context/asgard-theme-context.d.ts.map +1 -0
  36. package/dist/hooks/use-channel.d.ts +9 -8
  37. package/dist/hooks/use-channel.d.ts.map +1 -1
  38. package/dist/index.js +580 -411
  39. package/dist/style.css +1 -1
  40. package/dist/utils/deep-merge.d.ts +3 -0
  41. package/dist/utils/deep-merge.d.ts.map +1 -0
  42. package/package.json +5 -1
  43. package/dist/components/chatbot/chatbot-footer.d.ts.map +0 -1
  44. /package/dist/components/chatbot/{chatbot-footer.d.ts → chatbot-footer/chatbot-footer.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,151 +1,239 @@
1
- import { jsx as n, jsxs as a } from "react/jsx-runtime";
2
- import { useRef as R, useEffect as T, useState as w, useCallback as f, useMemo as N, createContext as W, useContext as X } from "react";
3
- import { AsgardServiceClient as G, Conversation as J, MessageTemplateType as y } from "@asgard-js/core";
4
- function P(o) {
5
- var t, e, s = "";
6
- if (typeof o == "string" || typeof o == "number") s += o;
7
- else if (typeof o == "object") if (Array.isArray(o)) {
8
- var c = o.length;
9
- for (t = 0; t < c; t++) o[t] && (e = P(o[t])) && (s && (s += " "), s += e);
10
- } else for (e in o) o[e] && (s && (s += " "), s += e);
11
- return s;
1
+ import { jsx as s, jsxs as m } from "react/jsx-runtime";
2
+ import * as u from "react";
3
+ import { createContext as tt, useMemo as y, useContext as et, useRef as q, useEffect as L, useState as N, useCallback as g, memo as lt } from "react";
4
+ import { AsgardServiceClient as _t, Conversation as ut, Channel as dt, MessageTemplateType as z } from "@asgard-js/core";
5
+ function ot(e) {
6
+ var t, o, n = "";
7
+ if (typeof e == "string" || typeof e == "number") n += e;
8
+ else if (typeof e == "object") if (Array.isArray(e)) {
9
+ var r = e.length;
10
+ for (t = 0; t < r; t++) e[t] && (o = ot(e[t])) && (n && (n += " "), n += o);
11
+ } else for (o in e) e[o] && (n && (n += " "), n += o);
12
+ return n;
12
13
  }
13
- function u() {
14
- for (var o, t, e = 0, s = "", c = arguments.length; e < c; e++) (o = arguments[e]) && (t = P(o)) && (s && (s += " "), s += t);
15
- return s;
14
+ function R() {
15
+ for (var e, t, o = 0, n = "", r = arguments.length; o < r; o++) (e = arguments[o]) && (t = ot(e)) && (n && (n += " "), n += t);
16
+ return n;
16
17
  }
17
- function Y(o) {
18
- const { config: t } = o, e = R(null);
19
- return e.current || (e.current = new G(t)), T(() => () => {
20
- e.current && (e.current.close(), e.current = null);
21
- }, [t]), e.current;
18
+ function F(e) {
19
+ return e !== null && typeof e == "object" && !Array.isArray(e);
22
20
  }
23
- function tt(o) {
24
- const { client: t, customChannelId: e, initMessages: s, options: c } = o;
21
+ function P(e, t) {
22
+ const o = { ...e };
23
+ if (!t) return o;
24
+ for (const [n, r] of Object.entries(t)) {
25
+ if (!F(r)) {
26
+ o[n] = r;
27
+ continue;
28
+ }
29
+ o[n] = P(F(o[n]) ? o[n] : {}, r);
30
+ }
31
+ return o;
32
+ }
33
+ const nt = {
34
+ chatbot: {
35
+ width: "375px",
36
+ height: "640px",
37
+ backgroundColor: "var(--asg-color-bg)",
38
+ borderColor: "var(--asg-color-border)",
39
+ borderRadius: "var(--asg-radius-md)",
40
+ contentMaxWidth: "1200px"
41
+ },
42
+ botMessage: {
43
+ color: "var(--asg-color-text)",
44
+ backgroundColor: "var(--asg-color-secondary)"
45
+ },
46
+ userMessage: {
47
+ color: "var(--asg-color-text)",
48
+ backgroundColor: "var(--asg-color-primary)"
49
+ }
50
+ }, st = tt(
51
+ nt
52
+ );
53
+ function ht(e) {
54
+ const { children: t, fullScreen: o, theme: n = {} } = e, r = y(
55
+ () => P(
56
+ nt,
57
+ o ? P(n, {
58
+ chatbot: {
59
+ width: "100vw",
60
+ height: "100vh",
61
+ borderRadius: "var(--asg-radius-none)"
62
+ }
63
+ }) : n
64
+ ),
65
+ [o, n]
66
+ );
67
+ return /* @__PURE__ */ s(st.Provider, { value: r, children: t });
68
+ }
69
+ function Z() {
70
+ return et(st);
71
+ }
72
+ function mt(e) {
73
+ const { config: t } = e, o = q(null);
74
+ return o.current || (o.current = new _t(t)), L(() => () => {
75
+ o.current && (o.current.close(), o.current = null);
76
+ }, [t]), o.current;
77
+ }
78
+ function gt(e) {
79
+ const {
80
+ client: t,
81
+ customChannelId: o,
82
+ customMessageId: n,
83
+ initMessages: r,
84
+ showDebugMessage: c
85
+ } = e;
25
86
  if (!t)
26
87
  throw new Error("Client instance is required");
27
- if (!e)
88
+ if (!o)
28
89
  throw new Error("Custom channel id is required");
29
- const [r, _] = w(!1), [i, l] = w(
30
- new J({
90
+ const [i, a] = N(null), [_, b] = N(!0), [v, f] = N(!1), [l, d] = N(!1), [h, p] = N(null), C = g(async () => {
91
+ const x = new ut({
92
+ showDebugMessage: c,
31
93
  messages: new Map(
32
- s == null ? void 0 : s.map((h) => [h.messageId, h])
33
- ),
34
- typingMessages: null
35
- })
36
- );
37
- T(() => {
38
- t.setChannel({
39
- customChannelId: e,
40
- customMessageId: ""
94
+ r == null ? void 0 : r.map((T) => [T.messageId, T])
95
+ )
41
96
  });
42
- }, [t, e]);
43
- const d = f(
44
- (h, b) => {
45
- _(!0), l((C) => {
46
- const x = C.pushMessage(
47
- C,
48
- {
49
- type: "user",
50
- messageId: b ?? crypto.randomUUID(),
51
- text: h,
52
- time: /* @__PURE__ */ new Date()
53
- }
54
- );
55
- return t.sendMessage(
56
- {
57
- customChannelId: e,
58
- customMessageId: b,
59
- text: h
60
- },
61
- {
62
- onSseMessage: (z) => {
63
- l(
64
- (j) => x.onMessage(j, z, {
65
- showDebugMessage: c == null ? void 0 : c.showDebugMessage
66
- })
67
- );
68
- },
69
- onSseCompleted: () => {
70
- _(!1);
71
- }
72
- }
73
- ), x;
74
- });
97
+ f(!0), d(!0), p(x);
98
+ const $ = await dt.reset(
99
+ {
100
+ client: t,
101
+ customChannelId: o,
102
+ customMessageId: n,
103
+ conversation: x,
104
+ statesObserver: (T) => {
105
+ d(T.isConnecting), p(T.conversation);
106
+ }
107
+ },
108
+ {
109
+ onSseCompleted() {
110
+ f(!1);
111
+ }
112
+ }
113
+ );
114
+ a($);
115
+ }, [
116
+ t,
117
+ o,
118
+ n,
119
+ r,
120
+ c
121
+ ]), M = g(() => {
122
+ a((x) => (x == null || x.close(), null)), b(!1), f(!1), d(!1), p(null);
123
+ }, []), k = g(
124
+ (x) => {
125
+ i == null || i.sendMessage({ text: x });
75
126
  },
76
- [t, e, c]
127
+ [i]
77
128
  );
78
- return N(
129
+ return L(() => {
130
+ !i && _ && C();
131
+ }, [i, _, C]), L(() => () => M(), [M]), y(
79
132
  () => ({
80
- isConnecting: r,
81
- messages: i.messages,
82
- typingMessages: i.typingMessages,
83
- sendMessage: d
133
+ isOpen: _,
134
+ isResetting: v,
135
+ isConnecting: l,
136
+ conversation: h,
137
+ sendMessage: k,
138
+ resetChannel: C,
139
+ closeChannel: M
84
140
  }),
85
- [i, r, d]
141
+ [
142
+ _,
143
+ v,
144
+ l,
145
+ h,
146
+ k,
147
+ C,
148
+ M
149
+ ]
86
150
  );
87
151
  }
88
- function et(o, t) {
89
- const [e, s] = w(o);
90
- return T(() => {
91
- const c = window.setTimeout(() => {
92
- s(o);
152
+ function bt(e, t) {
153
+ const [o, n] = N(e);
154
+ return L(() => {
155
+ const r = window.setTimeout(() => {
156
+ n(e);
93
157
  }, t ?? 300);
94
- return () => clearTimeout(c);
95
- }, [o, t]), e;
158
+ return () => clearTimeout(r);
159
+ }, [e, t]), o;
96
160
  }
97
- const L = W({
161
+ const rt = tt({
98
162
  avatar: void 0,
99
163
  client: null,
164
+ isOpen: !1,
165
+ isResetting: !1,
100
166
  isConnecting: !1,
101
167
  messages: null,
102
- typingMessages: null,
103
168
  messageBoxBottomRef: { current: null },
104
- sendMessage: () => {
105
- }
169
+ botTypingPlaceholder: void 0
106
170
  });
107
- function ot(o) {
171
+ function ft(e) {
108
172
  const {
109
173
  avatar: t,
110
- children: e,
111
- config: s,
174
+ children: o,
175
+ config: n,
176
+ botTypingPlaceholder: r,
112
177
  customChannelId: c,
113
- customMessageId: r,
114
- delayTime: _,
115
- initMessages: i,
116
- options: l,
117
- ...d
118
- } = o, h = R(null), b = Y({ config: s }), { messages: C, typingMessages: x, sendMessage: z, isConnecting: j } = tt({
119
- client: b,
178
+ customMessageId: i,
179
+ delayTime: a,
180
+ initMessages: _,
181
+ options: b,
182
+ ...v
183
+ } = e, f = q(null), l = mt({ config: n }), {
184
+ isOpen: d,
185
+ isResetting: h,
186
+ isConnecting: p,
187
+ conversation: C,
188
+ sendMessage: M,
189
+ resetChannel: k,
190
+ closeChannel: x
191
+ } = gt({
192
+ client: l,
120
193
  customChannelId: c,
121
- initMessages: i,
122
- options: l
123
- }), Q = N(
194
+ initMessages: _,
195
+ showDebugMessage: b == null ? void 0 : b.showDebugMessage
196
+ }), $ = y(
124
197
  () => ({
125
198
  avatar: t,
126
- client: b,
127
- isConnecting: j,
128
- messages: C,
129
- typingMessages: x,
130
- sendMessage: z,
131
- messageBoxBottomRef: h
199
+ client: l,
200
+ isOpen: d,
201
+ isResetting: h,
202
+ isConnecting: p,
203
+ messages: (C == null ? void 0 : C.messages) ?? null,
204
+ sendMessage: M,
205
+ resetChannel: k,
206
+ closeChannel: x,
207
+ botTypingPlaceholder: r,
208
+ messageBoxBottomRef: f
132
209
  }),
133
- [t, b, j, C, z, x]
134
- );
135
- return /* @__PURE__ */ n(L.Provider, { value: Q, children: /* @__PURE__ */ n("div", { ...d, children: e }) });
210
+ [
211
+ t,
212
+ l,
213
+ d,
214
+ h,
215
+ p,
216
+ C == null ? void 0 : C.messages,
217
+ M,
218
+ k,
219
+ x,
220
+ r
221
+ ]
222
+ ), T = Z();
223
+ return /* @__PURE__ */ s(rt.Provider, { value: $, children: /* @__PURE__ */ s("div", { style: T == null ? void 0 : T.chatbot, ...v, children: o }) });
136
224
  }
137
- function m() {
138
- return X(L);
225
+ function w() {
226
+ return et(rt);
139
227
  }
140
- const nt = "_chatbot_header_1xj9n_1", st = "_chatbot_header__content_1xj9n_1", ct = "_chatbot_header__title_1xj9n_9", rt = "_chatbot_header__extra_1xj9n_20", k = {
141
- chatbot_header: nt,
142
- chatbot_header__content: st,
143
- chatbot_header__title: ct,
144
- chatbot_header__extra: rt
145
- };
146
- function at(o) {
147
- const { avatar: t } = o;
148
- return t ? /* @__PURE__ */ n(
228
+ const pt = "_chatbot_header_cqlve_1", Ct = "_chatbot_header__content_cqlve_1", vt = "_chatbot_header__title_cqlve_9", xt = "_chatbot_header__extra_cqlve_20", A = {
229
+ chatbot_header: pt,
230
+ chatbot_header__content: Ct,
231
+ chatbot_header__title: vt,
232
+ chatbot_header__extra: xt
233
+ }, yt = (e) => /* @__PURE__ */ u.createElement("svg", { width: 33, height: 32, viewBox: "0 0 33 32", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ u.createElement("g", { clipPath: "url(#clip0_3084_29383)" }, /* @__PURE__ */ u.createElement("path", { d: "M0.410645 16C0.410645 7.16344 7.57409 0 16.4106 0C25.2472 0 32.4106 7.16344 32.4106 16C32.4106 24.8366 25.2472 32 16.4106 32C7.57409 32 0.410645 24.8366 0.410645 16Z", fill: "#333333" }), /* @__PURE__ */ u.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M16.5788 6.33398C19.8925 6.33398 22.5788 9.02028 22.5788 12.334C22.5788 14.2211 21.7075 15.9048 20.3453 17.0047C23.6487 18.3735 26.0607 21.6974 26.4106 25.6673H24.4569C24.0206 21.6274 20.9742 18.4911 17.2591 18.3397L16.9776 18.334H16.5788H15.8437C12.0019 18.334 8.81164 21.5258 8.36437 25.6673H6.41064C6.76857 21.607 9.28344 18.2225 12.7029 16.9143C11.4036 15.8137 10.5788 14.1701 10.5788 12.334C10.5788 9.02028 13.265 6.33398 16.5788 6.33398ZM16.5788 16.334C18.7879 16.334 20.5788 14.5431 20.5788 12.334C20.5788 10.1248 18.7879 8.33398 16.5788 8.33398C14.3696 8.33398 12.5788 10.1248 12.5788 12.334C12.5788 14.5431 14.3696 16.334 16.5788 16.334Z", fill: "#8C8C8C" })), /* @__PURE__ */ u.createElement("defs", null, /* @__PURE__ */ u.createElement("clipPath", { id: "clip0_3084_29383" }, /* @__PURE__ */ u.createElement("path", { d: "M0.410645 16C0.410645 7.16344 7.57409 0 16.4106 0C25.2472 0 32.4106 7.16344 32.4106 16C32.4106 24.8366 25.2472 32 16.4106 32C7.57409 32 0.410645 24.8366 0.410645 16Z", fill: "white" }))));
234
+ function wt(e) {
235
+ const { avatar: t } = e;
236
+ return t ? /* @__PURE__ */ s(
149
237
  "img",
150
238
  {
151
239
  src: t,
@@ -156,209 +244,174 @@ function at(o) {
156
244
  borderRadius: "50%"
157
245
  }
158
246
  }
159
- ) : /* @__PURE__ */ a(
160
- "svg",
161
- {
162
- width: "33",
163
- height: "32",
164
- viewBox: "0 0 33 32",
165
- fill: "none",
166
- xmlns: "http://www.w3.org/2000/svg",
167
- children: [
168
- /* @__PURE__ */ a("g", { "clip-path": "url(#clip0_3084_29383)", children: [
169
- /* @__PURE__ */ n(
170
- "path",
171
- {
172
- d: "M0.410645 16C0.410645 7.16344 7.57409 0 16.4106 0C25.2472 0 32.4106 7.16344 32.4106 16C32.4106 24.8366 25.2472 32 16.4106 32C7.57409 32 0.410645 24.8366 0.410645 16Z",
173
- fill: "#333333"
174
- }
175
- ),
176
- /* @__PURE__ */ n(
177
- "path",
178
- {
179
- "fill-rule": "evenodd",
180
- "clip-rule": "evenodd",
181
- d: "M16.5788 6.33398C19.8925 6.33398 22.5788 9.02028 22.5788 12.334C22.5788 14.2211 21.7075 15.9048 20.3453 17.0047C23.6487 18.3735 26.0607 21.6974 26.4106 25.6673H24.4569C24.0206 21.6274 20.9742 18.4911 17.2591 18.3397L16.9776 18.334H16.5788H15.8437C12.0019 18.334 8.81164 21.5258 8.36437 25.6673H6.41064C6.76857 21.607 9.28344 18.2225 12.7029 16.9143C11.4036 15.8137 10.5788 14.1701 10.5788 12.334C10.5788 9.02028 13.265 6.33398 16.5788 6.33398ZM16.5788 16.334C18.7879 16.334 20.5788 14.5431 20.5788 12.334C20.5788 10.1248 18.7879 8.33398 16.5788 8.33398C14.3696 8.33398 12.5788 10.1248 12.5788 12.334C12.5788 14.5431 14.3696 16.334 16.5788 16.334Z",
182
- fill: "#8C8C8C"
183
- }
184
- )
185
- ] }),
186
- /* @__PURE__ */ n("defs", { children: /* @__PURE__ */ n("clipPath", { id: "clip0_3084_29383", children: /* @__PURE__ */ n(
187
- "path",
188
- {
189
- d: "M0.410645 16C0.410645 7.16344 7.57409 0 16.4106 0C25.2472 0 32.4106 7.16344 32.4106 16C32.4106 24.8366 25.2472 32 16.4106 32C7.57409 32 0.410645 24.8366 0.410645 16Z",
190
- fill: "white"
191
- }
192
- ) }) })
193
- ]
194
- }
195
- );
247
+ ) : /* @__PURE__ */ s(yt, {});
196
248
  }
197
- function it(o) {
198
- const { title: t } = o, { avatar: e } = m();
199
- return /* @__PURE__ */ n("div", { className: k.chatbot_header, children: /* @__PURE__ */ a("div", { className: k.chatbot_header__content, children: [
200
- /* @__PURE__ */ a("div", { className: k.chatbot_header__title, children: [
201
- /* @__PURE__ */ n(at, { avatar: e }),
202
- /* @__PURE__ */ n("h4", { children: t })
249
+ const Tt = (e) => /* @__PURE__ */ u.createElement("svg", { width: 16, height: 16, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ u.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M3.49453 2.3352C6.44049 -0.226723 10.9105 -0.106316 13.7142 2.69633C16.6428 5.62613 16.6428 10.3739 13.7144 13.3035C10.7846 16.2322 6.03581 16.2322 3.1073 13.3036C2.30873 12.505 1.71132 11.5536 1.34188 10.5109L1.78892 10.3525L1.34171 10.5106L1.22791 10.162C1.01752 9.46018 0.910643 8.73159 0.910643 7.9997H2.4542L2.46382 8.33865C2.49584 8.9024 2.60763 9.46037 2.79674 9.99539L2.7968 9.99536L2.90116 10.2683C3.19714 10.9887 3.63414 11.6475 4.19876 12.2121C6.52451 14.5379 10.2961 14.5379 12.6229 12.212C14.9486 9.88539 14.9486 6.11464 12.6227 3.78781C10.3306 1.49653 6.63579 1.46263 4.30292 3.68622L6.68087 3.68698V5.22954H3.49394H1.95141V3.68698V0.5H3.49394L3.49453 2.3352Z", fill: "#8C8C8C" })), Nt = (e) => /* @__PURE__ */ u.createElement("svg", { width: 15, height: 14, viewBox: "0 0 15 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ u.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M13.3496 0L7.41062 5.938L1.47162 0L0.411621 1.06L6.34962 6.999L0.411621 12.938L1.47162 13.999L7.41062 8.059L13.3496 13.999L14.4096 12.938L8.47162 6.999L14.4096 1.06L13.3496 0Z", fill: "#8C8C8C" }));
250
+ function Rt(e) {
251
+ const { title: t, onReset: o, onClose: n } = e, { chatbot: r } = Z(), { avatar: c, isResetting: i, resetChannel: a, closeChannel: _ } = w(), b = y(
252
+ () => ({
253
+ maxWidth: (r == null ? void 0 : r.contentMaxWidth) ?? "1200px"
254
+ }),
255
+ [r]
256
+ ), v = g(
257
+ (l) => {
258
+ i || (l.stopPropagation(), o == null || o(), a == null || a());
259
+ },
260
+ [i, o, a]
261
+ ), f = g(
262
+ (l) => {
263
+ i || (l.stopPropagation(), n == null || n(), _ == null || _());
264
+ },
265
+ [i, n, _]
266
+ );
267
+ return /* @__PURE__ */ s("div", { className: A.chatbot_header, children: /* @__PURE__ */ m("div", { className: A.chatbot_header__content, style: b, children: [
268
+ /* @__PURE__ */ m("div", { className: A.chatbot_header__title, children: [
269
+ /* @__PURE__ */ s(wt, { avatar: c }),
270
+ /* @__PURE__ */ s("h4", { children: t })
203
271
  ] }),
204
- /* @__PURE__ */ n("div", { className: k.chatbot_header__extra })
272
+ /* @__PURE__ */ m("div", { className: A.chatbot_header__extra, children: [
273
+ /* @__PURE__ */ s("div", { onClick: v, children: /* @__PURE__ */ s(Tt, {}) }),
274
+ /* @__PURE__ */ s("div", { onClick: f, children: /* @__PURE__ */ s(Nt, {}) })
275
+ ] })
205
276
  ] }) });
206
277
  }
207
- const lt = "_chatbot_body_1f0gq_1", _t = "_chatbot_body__content_1f0gq_7", S = {
208
- chatbot_body: lt,
209
- chatbot_body__content: _t
210
- }, dt = "_template_box_1ozig_1", g = {
211
- template_box: dt,
278
+ const Mt = "_chatbot_body_1f0gq_1", St = "_chatbot_body__content_1f0gq_7", W = {
279
+ chatbot_body: Mt,
280
+ chatbot_body__content: St
281
+ }, Lt = "_template_box_1ozig_1", E = {
282
+ template_box: Lt,
212
283
  "template_box--bot": "_template_box--bot_1ozig_7",
213
284
  "template_box--horizontal": "_template_box--horizontal_1ozig_7",
214
285
  "template_box--vertical": "_template_box--vertical_1ozig_10",
215
286
  "template_box--user": "_template_box--user_1ozig_14"
216
287
  };
217
- function M(o) {
218
- const { type: t, direction: e = "horizontal", children: s } = o, c = N(() => {
288
+ function V(e) {
289
+ const { type: t, direction: o = "horizontal", children: n } = e, r = y(() => {
219
290
  switch (t) {
220
291
  case "user":
221
- return u(g.template_box, g["template_box--user"]);
292
+ return R(E.template_box, E["template_box--user"]);
222
293
  case "bot":
223
294
  default:
224
- return u(
225
- g.template_box,
226
- g["template_box--bot"],
227
- e === "horizontal" ? g["template_box--horizontal"] : g["template_box--vertical"]
295
+ return R(
296
+ E.template_box,
297
+ E["template_box--bot"],
298
+ o === "horizontal" ? E["template_box--horizontal"] : E["template_box--vertical"]
228
299
  );
229
300
  }
230
- }, [e, t]);
231
- return /* @__PURE__ */ n("div", { className: c, children: s });
301
+ }, [o, t]);
302
+ return /* @__PURE__ */ s("div", { className: r, children: n });
232
303
  }
233
- const ht = "_template_box_content_12ojl_1", ut = "_content_12ojl_7", A = {
234
- template_box_content: ht,
235
- content: ut
236
- }, mt = "_quick_replies_box_zoq7y_1", bt = "_quick_reply_zoq7y_7", Z = {
237
- quick_replies_box: mt,
238
- quick_reply: bt
304
+ const Et = "_template_box_content_12ojl_1", Bt = "_content_12ojl_7", U = {
305
+ template_box_content: Et,
306
+ content: Bt
307
+ }, kt = "_quick_replies_box_zoq7y_1", Ht = "_quick_reply_zoq7y_7", J = {
308
+ quick_replies_box: kt,
309
+ quick_reply: Ht
239
310
  };
240
- function gt(o) {
241
- const { quickReplies: t } = o, { sendMessage: e, isConnecting: s } = m(), c = f(
242
- (r) => {
243
- e(r);
311
+ function zt(e) {
312
+ const { quickReplies: t } = e, { sendMessage: o, isConnecting: n } = w(), r = g(
313
+ (c) => {
314
+ o == null || o(c);
244
315
  },
245
- [e]
316
+ [o]
246
317
  );
247
- return t != null && t.length ? /* @__PURE__ */ n("div", { className: Z.quick_replies_box, children: t.map((r) => /* @__PURE__ */ n(
318
+ return t != null && t.length ? /* @__PURE__ */ s("div", { className: J.quick_replies_box, children: t.map((c) => /* @__PURE__ */ s(
248
319
  "button",
249
320
  {
250
- className: Z.quick_reply,
251
- disabled: s,
252
- onClick: () => c(r.text),
253
- children: r.text
321
+ className: J.quick_reply,
322
+ disabled: n,
323
+ onClick: () => r(c.text),
324
+ children: c.text
254
325
  },
255
- r.text
326
+ c.text
256
327
  )) }) : null;
257
328
  }
258
- function F(o) {
259
- return o.toLocaleTimeString("zh-TW", {
329
+ function ct(e) {
330
+ return e.toLocaleTimeString("zh-TW", {
260
331
  timeZone: "Asia/Taipei",
261
332
  hour: "2-digit",
262
333
  minute: "2-digit",
263
334
  hour12: !1
264
335
  });
265
336
  }
266
- const pt = "_time_rgg92_1", ft = {
267
- time: pt
337
+ const Vt = "_time_rgg92_1", qt = {
338
+ time: Vt
268
339
  };
269
- function q(o) {
270
- const { time: t, className: e } = o;
271
- return t ? /* @__PURE__ */ n("div", { className: u(ft.time, e), children: F(t) }) : null;
340
+ function D(e) {
341
+ const { time: t, className: o } = e;
342
+ return t ? /* @__PURE__ */ s("div", { className: R(qt.time, o), children: ct(t) }) : null;
272
343
  }
273
- function $(o) {
274
- const { quickReplies: t, time: e, children: s } = o;
275
- return /* @__PURE__ */ a("div", { className: A.template_box_content, children: [
276
- /* @__PURE__ */ a("div", { className: A.content, children: [
277
- s,
278
- /* @__PURE__ */ n(q, { time: e })
344
+ function O(e) {
345
+ const { quickReplies: t, time: o, children: n } = e;
346
+ return /* @__PURE__ */ m("div", { className: U.template_box_content, children: [
347
+ /* @__PURE__ */ m("div", { className: U.content, children: [
348
+ n,
349
+ /* @__PURE__ */ s(D, { time: o })
279
350
  ] }),
280
- !!(t != null && t.length) && /* @__PURE__ */ n(gt, { quickReplies: t })
351
+ !!(t != null && t.length) && /* @__PURE__ */ s(zt, { quickReplies: t })
281
352
  ] });
282
353
  }
283
- const Ct = "_bot_avatar_xrs9x_1", U = {
284
- bot_avatar: Ct
285
- };
286
- function H() {
287
- const { avatar: o } = m();
288
- return o ? /* @__PURE__ */ n("img", { src: o, alt: "Bot Avatar", className: U.bot_avatar }) : /* @__PURE__ */ n("div", { className: U.bot_avatar, children: /* @__PURE__ */ a(
289
- "svg",
290
- {
291
- style: { width: "100%", height: "100%" },
292
- viewBox: "0 0 25 24",
293
- fill: "none",
294
- xmlns: "http://www.w3.org/2000/svg",
295
- children: [
296
- /* @__PURE__ */ n(
297
- "path",
298
- {
299
- d: "M0.40625 12C0.40625 5.37258 5.77883 0 12.4062 0C19.0337 0 24.4062 5.37258 24.4062 12C24.4062 18.6274 19.0337 24 12.4062 24C5.77883 24 0.40625 18.6274 0.40625 12Z",
300
- fill: "#585858"
301
- }
302
- ),
303
- /* @__PURE__ */ n(
304
- "path",
305
- {
306
- d: "M6.40625 18.75V15C6.40625 14.5875 6.55313 14.2344 6.84688 13.9406C7.14063 13.6469 7.49375 13.5 7.90625 13.5H16.9062C17.3188 13.5 17.6719 13.6469 17.9656 13.9406C18.2594 14.2344 18.4062 14.5875 18.4062 15V18.75H6.40625ZM10.1562 12.75C9.11875 12.75 8.23438 12.3844 7.50312 11.6531C6.77187 10.9219 6.40625 10.0375 6.40625 9C6.40625 7.9625 6.77187 7.07812 7.50312 6.34687C8.23438 5.61562 9.11875 5.25 10.1562 5.25H14.6562C15.6938 5.25 16.5781 5.61562 17.3094 6.34687C18.0406 7.07812 18.4062 7.9625 18.4062 9C18.4062 10.0375 18.0406 10.9219 17.3094 11.6531C16.5781 12.3844 15.6938 12.75 14.6562 12.75H10.1562ZM7.90625 17.25H16.9062V15H7.90625V17.25ZM10.1562 11.25H14.6562C15.2812 11.25 15.8125 11.0312 16.25 10.5938C16.6875 10.1562 16.9062 9.625 16.9062 9C16.9062 8.375 16.6875 7.84375 16.25 7.40625C15.8125 6.96875 15.2812 6.75 14.6562 6.75H10.1562C9.53125 6.75 9 6.96875 8.5625 7.40625C8.125 7.84375 7.90625 8.375 7.90625 9C7.90625 9.625 8.125 10.1562 8.5625 10.5938C9 11.0312 9.53125 11.25 10.1562 11.25ZM10.1562 9.75C10.3688 9.75 10.5469 9.67812 10.6906 9.53438C10.8344 9.39062 10.9062 9.2125 10.9062 9C10.9062 8.7875 10.8344 8.60938 10.6906 8.46562C10.5469 8.32187 10.3688 8.25 10.1562 8.25C9.94375 8.25 9.76562 8.32187 9.62187 8.46562C9.47812 8.60938 9.40625 8.7875 9.40625 9C9.40625 9.2125 9.47812 9.39062 9.62187 9.53438C9.76562 9.67812 9.94375 9.75 10.1562 9.75ZM14.6562 9.75C14.8687 9.75 15.0469 9.67812 15.1906 9.53438C15.3344 9.39062 15.4062 9.2125 15.4062 9C15.4062 8.7875 15.3344 8.60938 15.1906 8.46562C15.0469 8.32187 14.8687 8.25 14.6562 8.25C14.4438 8.25 14.2656 8.32187 14.1219 8.46562C13.9781 8.60938 13.9062 8.7875 13.9062 9C13.9062 9.2125 13.9781 9.39062 14.1219 9.53438C14.2656 9.67812 14.4438 9.75 14.6562 9.75Z",
307
- fill: "white"
308
- }
309
- )
310
- ]
311
- }
312
- ) });
313
- }
314
- const xt = "_text_1djgp_1", vt = "_dot_1djgp_18", yt = "_blink_1djgp_1", p = {
315
- text: xt,
354
+ const At = "_bot_avatar_xrs9x_1", K = {
355
+ bot_avatar: At
356
+ }, It = (e) => /* @__PURE__ */ u.createElement("svg", { viewBox: "0 0 25 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ u.createElement("path", { d: "M0.40625 12C0.40625 5.37258 5.77883 0 12.4062 0C19.0337 0 24.4062 5.37258 24.4062 12C24.4062 18.6274 19.0337 24 12.4062 24C5.77883 24 0.40625 18.6274 0.40625 12Z", fill: "#585858" }), /* @__PURE__ */ u.createElement("path", { d: "M6.40625 18.75V15C6.40625 14.5875 6.55313 14.2344 6.84688 13.9406C7.14063 13.6469 7.49375 13.5 7.90625 13.5H16.9062C17.3188 13.5 17.6719 13.6469 17.9656 13.9406C18.2594 14.2344 18.4062 14.5875 18.4062 15V18.75H6.40625ZM10.1562 12.75C9.11875 12.75 8.23438 12.3844 7.50312 11.6531C6.77187 10.9219 6.40625 10.0375 6.40625 9C6.40625 7.9625 6.77187 7.07812 7.50312 6.34687C8.23438 5.61562 9.11875 5.25 10.1562 5.25H14.6562C15.6938 5.25 16.5781 5.61562 17.3094 6.34687C18.0406 7.07812 18.4062 7.9625 18.4062 9C18.4062 10.0375 18.0406 10.9219 17.3094 11.6531C16.5781 12.3844 15.6938 12.75 14.6562 12.75H10.1562ZM7.90625 17.25H16.9062V15H7.90625V17.25ZM10.1562 11.25H14.6562C15.2812 11.25 15.8125 11.0312 16.25 10.5938C16.6875 10.1562 16.9062 9.625 16.9062 9C16.9062 8.375 16.6875 7.84375 16.25 7.40625C15.8125 6.96875 15.2812 6.75 14.6562 6.75H10.1562C9.53125 6.75 9 6.96875 8.5625 7.40625C8.125 7.84375 7.90625 8.375 7.90625 9C7.90625 9.625 8.125 10.1562 8.5625 10.5938C9 11.0312 9.53125 11.25 10.1562 11.25ZM10.1562 9.75C10.3688 9.75 10.5469 9.67812 10.6906 9.53438C10.8344 9.39062 10.9062 9.2125 10.9062 9C10.9062 8.7875 10.8344 8.60938 10.6906 8.46562C10.5469 8.32187 10.3688 8.25 10.1562 8.25C9.94375 8.25 9.76562 8.32187 9.62187 8.46562C9.47812 8.60938 9.40625 8.7875 9.40625 9C9.40625 9.2125 9.47812 9.39062 9.62187 9.53438C9.76562 9.67812 9.94375 9.75 10.1562 9.75ZM14.6562 9.75C14.8687 9.75 15.0469 9.67812 15.1906 9.53438C15.3344 9.39062 15.4062 9.2125 15.4062 9C15.4062 8.7875 15.3344 8.60938 15.1906 8.46562C15.0469 8.32187 14.8687 8.25 14.6562 8.25C14.4438 8.25 14.2656 8.32187 14.1219 8.46562C13.9781 8.60938 13.9062 8.7875 13.9062 9C13.9062 9.2125 13.9781 9.39062 14.1219 9.53438C14.2656 9.67812 14.4438 9.75 14.6562 9.75Z", fill: "white" })), j = lt((e) => {
357
+ const { avatar: t } = e;
358
+ return t ? /* @__PURE__ */ s("img", { src: t, alt: "Bot Avatar", className: K.bot_avatar }) : /* @__PURE__ */ s("div", { className: K.bot_avatar, children: /* @__PURE__ */ s(It, {}) });
359
+ }), Zt = "_text_1djgp_1", jt = "_dot_1djgp_18", B = {
360
+ text: Zt,
316
361
  "text--bot": "_text--bot_1djgp_7",
317
362
  "typing-indicator": "_typing-indicator_1djgp_13",
318
- dot: vt,
319
- blink: yt
363
+ dot: jt
320
364
  };
321
- function wt(o) {
322
- const { children: t, onResize: e } = o, s = R(null);
323
- return T(() => {
324
- const c = new ResizeObserver((r) => {
325
- for (const _ of r) {
326
- const { width: i, height: l } = _.contentRect;
327
- e(i, l);
365
+ function $t(e) {
366
+ const { children: t, onResize: o } = e, n = q(null);
367
+ return L(() => {
368
+ const r = new ResizeObserver((c) => {
369
+ for (const i of c) {
370
+ const { width: a, height: _ } = i.contentRect;
371
+ o(a, _);
328
372
  }
329
373
  });
330
- return s.current && c.observe(s.current), () => {
331
- c.disconnect();
374
+ return n.current && r.observe(n.current), () => {
375
+ r.disconnect();
332
376
  };
333
- }, [s, e]), /* @__PURE__ */ n("div", { ref: s, children: t });
377
+ }, [n, o]), /* @__PURE__ */ s("div", { ref: n, children: t });
334
378
  }
335
- function Nt(o) {
336
- const { typingMessage: t } = o, { messageBoxBottomRef: e } = m(), s = f(() => {
337
- var r;
338
- (r = e.current) == null || r.scrollIntoView({ behavior: "smooth" });
339
- }, [e]), c = et(t == null ? void 0 : t.isTyping, 500);
340
- return c ? /* @__PURE__ */ a(M, { type: "bot", direction: "horizontal", children: [
341
- /* @__PURE__ */ n(H, {}),
342
- /* @__PURE__ */ n($, { time: /* @__PURE__ */ new Date(), children: /* @__PURE__ */ n("div", { className: u(p.text, p["text--bot"]), children: /* @__PURE__ */ a(wt, { onResize: s, children: [
343
- /* @__PURE__ */ n("span", { children: (t == null ? void 0 : t.typingText) ?? "" }),
344
- c && /* @__PURE__ */ a("span", { className: p["typing-indicator"], children: [
345
- /* @__PURE__ */ n("div", { className: p.dot }),
346
- /* @__PURE__ */ n("div", { className: p.dot }),
347
- /* @__PURE__ */ n("div", { className: p.dot })
379
+ function it(e) {
380
+ const { isTyping: t, typingText: o } = e, { messageBoxBottomRef: n, avatar: r } = w(), c = g(() => {
381
+ var a;
382
+ (a = n.current) == null || a.scrollIntoView({ behavior: "smooth" });
383
+ }, [n]), i = bt(t, 500);
384
+ return i ? /* @__PURE__ */ m(V, { type: "bot", direction: "horizontal", children: [
385
+ /* @__PURE__ */ s(j, { avatar: r }),
386
+ /* @__PURE__ */ s(O, { time: /* @__PURE__ */ new Date(), children: /* @__PURE__ */ s("div", { className: R(B.text, B["text--bot"]), children: /* @__PURE__ */ m($t, { onResize: c, children: [
387
+ /* @__PURE__ */ s("span", { children: o ?? "" }),
388
+ i && /* @__PURE__ */ m("span", { className: B["typing-indicator"], children: [
389
+ /* @__PURE__ */ s("div", { className: B.dot }),
390
+ /* @__PURE__ */ s("div", { className: B.dot }),
391
+ /* @__PURE__ */ s("div", { className: B.dot })
348
392
  ] })
349
393
  ] }) }) })
350
394
  ] }) : null;
351
395
  }
352
- const Mt = "_card_root_1ygom_1", Tt = "_card_content_1ygom_10", zt = "_card_title_1ygom_17", jt = "_card_description_1ygom_23", kt = "_card_actions_1ygom_37", v = {
353
- card_root: Mt,
354
- card_content: Tt,
355
- card_title: zt,
356
- card_description: jt,
357
- card_actions: kt
396
+ function Pt(e) {
397
+ const { placeholder: t } = e, { isConnecting: o, messages: n } = w(), r = y(
398
+ () => Array.from((n == null ? void 0 : n.values()) ?? []).some(
399
+ (c) => c.type === "bot" && c.isTyping
400
+ ),
401
+ [n]
402
+ );
403
+ return o && !r ? /* @__PURE__ */ s(it, { isTyping: !0, typingText: t }) : null;
404
+ }
405
+ const Dt = "_card_root_1ygom_1", Ot = "_card_content_1ygom_10", Ft = "_card_title_1ygom_17", Wt = "_card_description_1ygom_23", Ut = "_card_actions_1ygom_37", H = {
406
+ card_root: Dt,
407
+ card_content: Ot,
408
+ card_title: Ft,
409
+ card_description: Wt,
410
+ card_actions: Ut
358
411
  };
359
- function K(o) {
360
- var _;
361
- const { template: t } = o, { sendMessage: e } = m(), s = N(() => (t == null ? void 0 : t.thumbnailImageUrl.replace(/^http:/, "").replace(/^https:/, "")) || "https://via.assets.so/img.jpg?w=200&h=270&tc=white&bg=#eeeeee", [t]), c = N(() => {
412
+ function at(e) {
413
+ var i;
414
+ const { template: t } = e, { sendMessage: o } = w(), n = y(() => (t == null ? void 0 : t.thumbnailImageUrl.replace(/^http:/, "").replace(/^https:/, "")) || "https://via.assets.so/img.jpg?w=200&h=270&tc=white&bg=#eeeeee", [t]), r = y(() => {
362
415
  switch (t == null ? void 0 : t.imageAspectRatio) {
363
416
  case "square":
364
417
  return "1 / 1";
@@ -366,215 +419,331 @@ function K(o) {
366
419
  default:
367
420
  return "1.51 / 1";
368
421
  }
369
- }, [t]), r = f(
370
- (i) => function() {
371
- switch (i.type) {
422
+ }, [t]), c = g(
423
+ (a) => function() {
424
+ switch (a.type) {
372
425
  case "message":
373
- e(i.text);
426
+ o == null || o(a.text);
374
427
  return;
375
428
  case "uri":
376
- window.open(i.uri, "_blank");
429
+ window.open(a.uri, "_blank");
377
430
  return;
378
431
  }
379
432
  },
380
- [e]
433
+ [o]
381
434
  );
382
- return /* @__PURE__ */ a("div", { className: v.card_root, children: [
383
- (t == null ? void 0 : t.thumbnailImageUrl) && /* @__PURE__ */ n(
435
+ return /* @__PURE__ */ m("div", { className: H.card_root, children: [
436
+ (t == null ? void 0 : t.thumbnailImageUrl) && /* @__PURE__ */ s(
384
437
  "img",
385
438
  {
386
439
  alt: t == null ? void 0 : t.title,
387
- src: s,
440
+ src: n,
388
441
  style: {
389
442
  display: "block",
390
443
  width: "100%",
444
+ maxHeight: "170px",
391
445
  objectFit: t == null ? void 0 : t.imageSize,
392
- aspectRatio: c
446
+ aspectRatio: r
393
447
  }
394
448
  }
395
449
  ),
396
- /* @__PURE__ */ a("div", { className: v.card_content, children: [
397
- /* @__PURE__ */ n("h5", { className: v.card_title, children: t == null ? void 0 : t.title }),
398
- /* @__PURE__ */ n("div", { className: v.card_description, children: t == null ? void 0 : t.text }),
399
- /* @__PURE__ */ n("div", { className: v.card_actions, children: (_ = t == null ? void 0 : t.buttons) == null ? void 0 : _.map((i, l) => /* @__PURE__ */ n("button", { onClick: r(i.action), children: i.label }, l)) })
450
+ /* @__PURE__ */ m("div", { className: H.card_content, children: [
451
+ /* @__PURE__ */ s("h5", { className: H.card_title, children: t == null ? void 0 : t.title }),
452
+ /* @__PURE__ */ s("div", { className: H.card_description, children: t == null ? void 0 : t.text }),
453
+ /* @__PURE__ */ s("div", { className: H.card_actions, children: (i = t == null ? void 0 : t.buttons) == null ? void 0 : i.map((a, _) => /* @__PURE__ */ s("button", { onClick: c(a.action), children: a.label }, _)) })
400
454
  ] })
401
455
  ] });
402
456
  }
403
- function Bt(o) {
404
- const { conversationMessage: t } = o, e = t.message.template;
405
- return /* @__PURE__ */ a(M, { type: "bot", direction: "horizontal", children: [
406
- /* @__PURE__ */ n(H, {}),
407
- /* @__PURE__ */ n(
408
- $,
457
+ function Jt(e) {
458
+ const { message: t } = e, { avatar: o } = w(), n = t.message.template;
459
+ return /* @__PURE__ */ m(V, { type: "bot", direction: "horizontal", children: [
460
+ /* @__PURE__ */ s(j, { avatar: o }),
461
+ /* @__PURE__ */ s(
462
+ O,
409
463
  {
410
464
  time: t.time,
411
- quickReplies: e == null ? void 0 : e.quickReplies,
412
- children: /* @__PURE__ */ n(K, { template: e })
465
+ quickReplies: n == null ? void 0 : n.quickReplies,
466
+ children: /* @__PURE__ */ s(at, { template: n })
413
467
  }
414
468
  )
415
469
  ] });
416
470
  }
417
- const Ht = "_text_sbjtw_1", It = "_content_sbjtw_19", B = {
418
- text: Ht,
471
+ const Kt = "_text_sbjtw_1", I = {
472
+ text: Kt,
419
473
  "text--user": "_text--user_sbjtw_7",
420
- "text--bot": "_text--bot_sbjtw_13",
421
- content: It
474
+ "text--bot": "_text--bot_sbjtw_13"
422
475
  };
423
- function D(o) {
424
- var e;
425
- const { conversationMessage: t } = o;
426
- return t.type === "user" ? /* @__PURE__ */ a(M, { type: "user", direction: "horizontal", children: [
427
- /* @__PURE__ */ n("div", { className: u(B.text, B["text--user"]), children: t.text }),
428
- /* @__PURE__ */ n(q, { time: t.time })
429
- ] }) : /* @__PURE__ */ a(M, { type: "bot", direction: "horizontal", children: [
430
- /* @__PURE__ */ n(H, {}),
431
- /* @__PURE__ */ n(
432
- $,
476
+ function Q(e) {
477
+ var n;
478
+ const { message: t } = e, { avatar: o } = w();
479
+ return t.type === "user" ? /* @__PURE__ */ m(V, { type: "user", direction: "horizontal", children: [
480
+ /* @__PURE__ */ s("div", { className: R(I.text, I["text--user"]), children: t.text }),
481
+ /* @__PURE__ */ s(D, { time: t.time })
482
+ ] }) : /* @__PURE__ */ m(V, { type: "bot", direction: "horizontal", children: [
483
+ /* @__PURE__ */ s(j, { avatar: o }),
484
+ /* @__PURE__ */ s(
485
+ O,
433
486
  {
434
487
  time: t.time,
435
- quickReplies: (e = t.message.template) == null ? void 0 : e.quickReplies,
436
- children: /* @__PURE__ */ n("div", { className: u(B.text, B["text--bot"]), children: t.message.text })
488
+ quickReplies: (n = t.message.template) == null ? void 0 : n.quickReplies,
489
+ children: /* @__PURE__ */ s("div", { className: R(I.text, I["text--bot"]), children: t.message.text })
437
490
  }
438
491
  )
439
492
  ] });
440
493
  }
441
- const Rt = "_carousel_root_sv1hc_1", qt = "_carousel_time_sv1hc_12", V = {
442
- carousel_root: Rt,
443
- carousel_time: qt
494
+ const Qt = "_carousel_root_sv1hc_1", Xt = "_carousel_time_sv1hc_12", X = {
495
+ carousel_root: Qt,
496
+ carousel_time: Xt
444
497
  };
445
- function $t(o) {
446
- var s;
447
- const { conversationMessage: t } = o, e = t.message.template;
448
- return /* @__PURE__ */ a(M, { type: "bot", direction: "vertical", children: [
449
- /* @__PURE__ */ n(H, {}),
450
- /* @__PURE__ */ n("div", { className: V.carousel_root, children: (s = e.columns) == null ? void 0 : s.map((c, r) => /* @__PURE__ */ n(K, { template: c }, r)) }),
451
- /* @__PURE__ */ n(q, { className: V.carousel_time, time: t.time })
498
+ function Gt(e) {
499
+ var r;
500
+ const { message: t } = e, { avatar: o } = w(), n = t.message.template;
501
+ return /* @__PURE__ */ m(V, { type: "bot", direction: "vertical", children: [
502
+ /* @__PURE__ */ s(j, { avatar: o }),
503
+ /* @__PURE__ */ s("div", { className: X.carousel_root, children: (r = n.columns) == null ? void 0 : r.map((c, i) => /* @__PURE__ */ s(at, { template: c }, i)) }),
504
+ /* @__PURE__ */ s(D, { className: X.carousel_time, time: t.time })
452
505
  ] });
453
506
  }
454
- const St = "_hint_root_g119q_1", At = "_time_g119q_14", E = {
455
- hint_root: St,
456
- time: At
507
+ const Yt = "_hint_root_g119q_1", te = "_time_g119q_14", G = {
508
+ hint_root: Yt,
509
+ time: te
457
510
  };
458
- function Zt(o) {
459
- const { conversationMessage: t } = o;
511
+ function ee(e) {
512
+ const { message: t } = e;
460
513
  if (t.type === "user") return null;
461
- const e = t.message.template;
462
- return e.type !== y.HINT ? null : /* @__PURE__ */ a("div", { className: E.hint_root, children: [
463
- /* @__PURE__ */ n("div", { className: E.time, children: F(t.time) }),
464
- e.text
514
+ const o = t.message.template;
515
+ return o.type !== z.HINT ? null : /* @__PURE__ */ m("div", { className: G.hint_root, children: [
516
+ /* @__PURE__ */ s("div", { className: G.time, children: ct(t.time) }),
517
+ o.text
465
518
  ] });
466
519
  }
467
- function Ut(o) {
468
- const { conversationMessage: t } = o;
520
+ function oe(e) {
521
+ var o;
522
+ const { message: t } = e;
469
523
  if (t.type === "user")
470
- return /* @__PURE__ */ n(D, { conversationMessage: t });
471
- const e = t.message.template;
472
- switch (e == null ? void 0 : e.type) {
473
- case y.TEXT:
474
- return /* @__PURE__ */ n(D, { conversationMessage: t });
475
- case y.HINT:
476
- return /* @__PURE__ */ n(Zt, { conversationMessage: t });
477
- case y.BUTTON:
478
- return /* @__PURE__ */ n(Bt, { conversationMessage: t });
479
- case y.CAROUSEL:
480
- return /* @__PURE__ */ n($t, { conversationMessage: t });
524
+ return /* @__PURE__ */ s(Q, { message: t });
525
+ if (t.isTyping)
526
+ return /* @__PURE__ */ s(
527
+ it,
528
+ {
529
+ isTyping: t.isTyping,
530
+ typingText: t.typingText
531
+ }
532
+ );
533
+ switch ((o = t.message.template) == null ? void 0 : o.type) {
534
+ case z.TEXT:
535
+ return /* @__PURE__ */ s(Q, { message: t });
536
+ case z.HINT:
537
+ return /* @__PURE__ */ s(ee, { message: t });
538
+ case z.BUTTON:
539
+ return /* @__PURE__ */ s(Jt, { message: t });
540
+ case z.CAROUSEL:
541
+ return /* @__PURE__ */ s(Gt, { message: t });
481
542
  default:
482
- return /* @__PURE__ */ n("div", { children: "Unknown template" });
543
+ return /* @__PURE__ */ s("div", {});
483
544
  }
484
545
  }
485
- function Dt() {
486
- const { messages: o, typingMessages: t, messageBoxBottomRef: e } = m();
487
- return T(() => {
488
- var s;
489
- (s = e.current) == null || s.scrollIntoView({ behavior: "smooth" });
490
- }, [o, e]), /* @__PURE__ */ n("div", { className: S.chatbot_body, children: /* @__PURE__ */ a("div", { className: S.chatbot_body__content, children: [
491
- Array.from((o == null ? void 0 : o.values()) ?? []).map((s) => /* @__PURE__ */ n(
492
- Ut,
546
+ function ne() {
547
+ const { chatbot: e } = Z(), { messages: t, messageBoxBottomRef: o, botTypingPlaceholder: n } = w();
548
+ L(() => {
549
+ var c;
550
+ (c = o.current) == null || c.scrollIntoView({ behavior: "smooth" });
551
+ }, [t, o]);
552
+ const r = y(
553
+ () => ({
554
+ maxWidth: (e == null ? void 0 : e.contentMaxWidth) ?? "1200px"
555
+ }),
556
+ [e]
557
+ );
558
+ return /* @__PURE__ */ s("div", { className: W.chatbot_body, children: /* @__PURE__ */ m("div", { className: W.chatbot_body__content, style: r, children: [
559
+ Array.from((t == null ? void 0 : t.values()) ?? []).map((c) => /* @__PURE__ */ s(
560
+ oe,
493
561
  {
494
- conversationMessage: s
562
+ message: c
495
563
  },
496
- crypto.randomUUID()
564
+ c.messageId
497
565
  )),
498
- Array.from((t == null ? void 0 : t.values()) ?? []).map((s) => /* @__PURE__ */ n(
499
- Nt,
566
+ /* @__PURE__ */ s(
567
+ Pt,
500
568
  {
501
- typingMessage: s
502
- },
503
- crypto.randomUUID()
504
- )),
505
- /* @__PURE__ */ n("div", { ref: e })
569
+ placeholder: n ?? "正在輸入訊息"
570
+ }
571
+ ),
572
+ /* @__PURE__ */ s("div", { ref: o })
506
573
  ] }) });
507
574
  }
508
- const Vt = "_chatbot_footer_3box0_1", Et = "_chatbot_footer__content_3box0_1", Ot = "_chatbot_textarea_3box0_8", I = {
509
- chatbot_footer: Vt,
510
- chatbot_footer__content: Et,
511
- chatbot_textarea: Ot
512
- };
513
- function Pt() {
514
- const { sendMessage: o, isConnecting: t } = m(), [e, s] = w(""), [c, r] = w(!1), _ = f(
575
+ const se = "_chatbot_footer_1uvgs_1", re = "_chatbot_footer__content_1uvgs_1", ce = "_chatbot_textarea_1uvgs_11", ie = "_chatbot_submit_button_1uvgs_26", ae = "_chatbot_submit_button__disabled_1uvgs_51", S = {
576
+ chatbot_footer: se,
577
+ chatbot_footer__content: re,
578
+ chatbot_textarea: ce,
579
+ chatbot_submit_button: ie,
580
+ chatbot_submit_button__disabled: ae
581
+ }, le = (e) => /* @__PURE__ */ u.createElement("svg", { width: 15, height: 12, viewBox: "0 0 15 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ u.createElement("path", { d: "M0.823242 11.6953V0.945312L14.3328 6.32031L0.823242 11.6953ZM1.90658 10.0911L11.3649 6.32031L1.90658 2.54948V4.98052L5.92574 6.32031L1.90658 7.6601V10.0911Z", fill: "white" })), _e = (e) => /* @__PURE__ */ u.createElement("svg", { width: 11, height: 16, viewBox: "0 0 11 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ u.createElement("path", { d: "M5.40658 9.90397C4.82435 9.90397 4.33158 9.7023 3.92824 9.29897C3.52491 8.89564 3.32324 8.40286 3.32324 7.82064V2.82064C3.32324 2.23842 3.52491 1.74564 3.92824 1.3423C4.33158 0.938971 4.82435 0.737305 5.40658 0.737305C5.9888 0.737305 6.48158 0.938971 6.88491 1.3423C7.28824 1.74564 7.48991 2.23842 7.48991 2.82064V7.82064C7.48991 8.40286 7.28824 8.89564 6.88491 9.29897C6.48158 9.7023 5.9888 9.90397 5.40658 9.90397ZM4.86491 15.1123V12.8654C3.56213 12.7208 2.47949 12.1724 1.61699 11.2202C0.754492 10.2679 0.323242 9.13467 0.323242 7.82064H1.40658C1.40658 8.92731 1.79706 9.87064 2.57803 10.6506C3.35887 11.4306 4.30331 11.8206 5.41137 11.8206C6.51928 11.8206 7.46213 11.4306 8.23991 10.6506C9.01769 9.87064 9.40658 8.92731 9.40658 7.82064H10.4899C10.4899 9.13467 10.0587 10.2679 9.19616 11.2202C8.33366 12.1724 7.25102 12.7208 5.94824 12.8654V15.1123H4.86491ZM5.40658 8.82064C5.68991 8.82064 5.92741 8.7248 6.11908 8.53314C6.31074 8.34147 6.40658 8.10397 6.40658 7.82064V2.82064C6.40658 2.5373 6.31074 2.2998 6.11908 2.10814C5.92741 1.91647 5.68991 1.82064 5.40658 1.82064C5.12324 1.82064 4.88574 1.91647 4.69408 2.10814C4.50241 2.2998 4.40658 2.5373 4.40658 2.82064V7.82064C4.40658 8.10397 4.50241 8.34147 4.69408 8.53314C4.88574 8.7248 5.12324 8.82064 5.40658 8.82064Z", fill: "white" })), ue = (e) => /* @__PURE__ */ u.createElement("svg", { width: 40, height: 40, viewBox: "0 0 40 40", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ u.createElement("circle", { cx: 20, cy: 20, r: 18, fill: "#D04444" }), /* @__PURE__ */ u.createElement("rect", { x: 12, y: 12, width: 16, height: 16, fill: "#FFFFFF", rx: 2, ry: 2 }));
582
+ function de(e) {
583
+ const { setValue: t, className: o } = e, [n, r] = N(!1), c = q(null);
584
+ L(() => {
585
+ const l = window.SpeechRecognition || window.webkitSpeechRecognition;
586
+ if (!l) return;
587
+ const d = new l();
588
+ d.lang = "zh-TW", d.continuous = !0, d.interimResults = !0, d.onresult = (h) => {
589
+ for (let p = h.resultIndex; p < h.results.length; p++)
590
+ h.results[p].isFinal && t((C) => C + h.results[p][0].transcript);
591
+ }, d.onerror = (h) => {
592
+ alert(`語音識別錯誤: ${JSON.stringify(h.error)}`);
593
+ }, d.onend = () => {
594
+ r(!1);
595
+ }, c.current = d;
596
+ }, [t]);
597
+ const i = g(() => {
598
+ if (!c.current) {
599
+ alert("無法開始辨識: 語音識別器未初始化,請檢查是否有授權使用麥克風");
600
+ return;
601
+ }
602
+ try {
603
+ c.current.start(), r(!0);
604
+ } catch (l) {
605
+ alert(`無法開始辨識: ${JSON.stringify(l)}`);
606
+ }
607
+ }, []), a = g(() => {
608
+ c.current && (c.current.stop(), r(!1));
609
+ }, []), _ = g(
515
610
  (l) => {
516
- const d = l.target, h = d.value;
517
- d.style.height = "20px", h && (d.style.height = `${d.scrollHeight - 16}px`), s(l.target.value);
611
+ n || (l.preventDefault(), i());
518
612
  },
519
- []
520
- ), i = f(
613
+ [n, i]
614
+ ), b = g(
615
+ (l) => {
616
+ n && (l.preventDefault(), a());
617
+ },
618
+ [n, a]
619
+ ), v = g(
620
+ (l) => {
621
+ n || (l.preventDefault(), i());
622
+ },
623
+ [n, i]
624
+ ), f = g(
521
625
  (l) => {
522
- l.key === "Enter" && !c && !t && (o(e), s(""));
626
+ n && (l.preventDefault(), a());
523
627
  },
524
- [c, t, o, e]
628
+ [n, a]
525
629
  );
526
- return /* @__PURE__ */ n("div", { className: I.chatbot_footer, children: /* @__PURE__ */ n("div", { className: I.chatbot_footer__content, children: /* @__PURE__ */ n(
527
- "textarea",
630
+ return /* @__PURE__ */ s(
631
+ "div",
528
632
  {
529
- className: I.chatbot_textarea,
530
- disabled: t,
531
- cols: 40,
532
- value: e,
533
- placeholder: "Enter message",
534
- onChange: _,
535
- onKeyDown: i,
536
- onCompositionStart: () => r(!0),
537
- onCompositionEnd: () => r(!1)
633
+ className: o,
634
+ onMouseDown: _,
635
+ onMouseUp: b,
636
+ onTouchStart: v,
637
+ onTouchEnd: f,
638
+ children: n ? /* @__PURE__ */ s(ue, {}) : /* @__PURE__ */ s(_e, {})
538
639
  }
539
- ) }) });
640
+ );
641
+ }
642
+ function he() {
643
+ const { sendMessage: e, isConnecting: t } = w(), { chatbot: o } = Z(), [n, r] = N(""), [c, i] = N(!1), a = q(null), _ = y(() => t || !n, [t, n]), b = y(
644
+ () => ({
645
+ maxWidth: (o == null ? void 0 : o.contentMaxWidth) ?? "1200px"
646
+ }),
647
+ [o]
648
+ ), v = g(
649
+ (d) => {
650
+ const h = d.target, p = h.value;
651
+ h.style.height = "36px", p && (h.style.height = `${h.scrollHeight}px`), r(d.target.value);
652
+ },
653
+ []
654
+ ), f = g(() => {
655
+ !c && !t && (e == null || e(n), r(""), a.current && (a.current.style.height = "36px"));
656
+ }, [c, t, e, n]), l = g(
657
+ (d) => {
658
+ if (d.key === "Enter" && !c && !t) {
659
+ e == null || e(n), r("");
660
+ const h = d.target;
661
+ h.style.height = "36px";
662
+ }
663
+ },
664
+ [c, t, e, n]
665
+ );
666
+ return /* @__PURE__ */ s("div", { className: S.chatbot_footer, children: /* @__PURE__ */ m("div", { className: S.chatbot_footer__content, style: b, children: [
667
+ /* @__PURE__ */ s(
668
+ "textarea",
669
+ {
670
+ ref: a,
671
+ className: S.chatbot_textarea,
672
+ disabled: t,
673
+ cols: 40,
674
+ value: n,
675
+ placeholder: "Enter message",
676
+ onChange: v,
677
+ onKeyDown: l,
678
+ onCompositionStart: () => i(!0),
679
+ onCompositionEnd: () => i(!1)
680
+ }
681
+ ),
682
+ n ? /* @__PURE__ */ s(
683
+ "button",
684
+ {
685
+ className: R(
686
+ S.chatbot_submit_button,
687
+ _ && S.chatbot_submit_button__disabled
688
+ ),
689
+ disabled: _,
690
+ onClick: f,
691
+ children: /* @__PURE__ */ s(le, {})
692
+ }
693
+ ) : /* @__PURE__ */ s(
694
+ de,
695
+ {
696
+ setValue: r,
697
+ className: R(
698
+ S.chatbot_submit_button,
699
+ t && S.chatbot_submit_button__disabled
700
+ )
701
+ }
702
+ )
703
+ ] }) });
540
704
  }
541
- const Lt = "_chatbot_root_1jllh_1", Ft = "_chatbot_root__fullScreen_1jllh_12", O = {
542
- chatbot_root: Lt,
543
- chatbot_root__fullScreen: Ft
705
+ const me = "_chatbot_root_od4qx_1", ge = "_chatbot_root__fullScreen_od4qx_126", Y = {
706
+ chatbot_root: me,
707
+ chatbot_root__fullScreen: ge
544
708
  };
545
- function Xt(o) {
709
+ function Ce(e) {
546
710
  const {
547
711
  title: t,
548
- config: e,
549
- customChannelId: s,
712
+ theme: o,
713
+ config: n,
714
+ customChannelId: r,
550
715
  initMessages: c,
551
- fullScreen: r = !1,
716
+ debugMode: i = !1,
717
+ fullScreen: a = !1,
552
718
  avatar: _,
553
- options: i
554
- } = o;
555
- return /* @__PURE__ */ a(
556
- ot,
719
+ botTypingPlaceholder: b,
720
+ onReset: v,
721
+ onClose: f
722
+ } = e;
723
+ return /* @__PURE__ */ s(ht, { fullScreen: a, theme: o, children: /* @__PURE__ */ m(
724
+ ft,
557
725
  {
558
- className: u(
559
- O.chatbot_root,
560
- r && O.chatbot_root__fullScreen
726
+ className: R(
727
+ Y.chatbot_root,
728
+ a && Y.chatbot_root__fullScreen
561
729
  ),
562
730
  avatar: _,
563
- config: e,
564
- customChannelId: s,
731
+ config: n,
732
+ customChannelId: r,
565
733
  initMessages: c,
566
- options: i,
734
+ botTypingPlaceholder: b,
735
+ options: { showDebugMessage: i },
567
736
  children: [
568
- /* @__PURE__ */ n(it, { title: t }),
569
- /* @__PURE__ */ n(Dt, {}),
570
- /* @__PURE__ */ n(Pt, {})
737
+ /* @__PURE__ */ s(Rt, { title: t, onReset: v, onClose: f }),
738
+ /* @__PURE__ */ s(ne, {}),
739
+ /* @__PURE__ */ s(he, {})
571
740
  ]
572
741
  }
573
- );
742
+ ) });
574
743
  }
575
744
  export {
576
- Xt as Chatbot,
577
- Y as useAsgardServiceClient,
578
- tt as useChannel,
579
- et as useDebounce
745
+ Ce as Chatbot,
746
+ mt as useAsgardServiceClient,
747
+ gt as useChannel,
748
+ bt as useDebounce
580
749
  };