@asgard-js/react 0.0.2 → 0.0.4

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 (79) hide show
  1. package/dist/index.js +543 -337
  2. package/dist/style.css +1 -1
  3. package/package.json +5 -1
  4. package/dist/components/chatbot/chatbot-body.d.ts +0 -4
  5. package/dist/components/chatbot/chatbot-body.d.ts.map +0 -1
  6. package/dist/components/chatbot/chatbot-footer.d.ts +0 -4
  7. package/dist/components/chatbot/chatbot-footer.d.ts.map +0 -1
  8. package/dist/components/chatbot/chatbot-header.d.ts +0 -8
  9. package/dist/components/chatbot/chatbot-header.d.ts.map +0 -1
  10. package/dist/components/chatbot/chatbot.d.ts +0 -16
  11. package/dist/components/chatbot/chatbot.d.ts.map +0 -1
  12. package/dist/components/chatbot/profile-icon.d.ts +0 -4
  13. package/dist/components/chatbot/profile-icon.d.ts.map +0 -1
  14. package/dist/components/conversation-message-renderer/conversation-message-renderer.d.ts +0 -9
  15. package/dist/components/conversation-message-renderer/conversation-message-renderer.d.ts.map +0 -1
  16. package/dist/components/conversation-message-renderer/index.d.ts +0 -2
  17. package/dist/components/conversation-message-renderer/index.d.ts.map +0 -1
  18. package/dist/components/index.d.ts +0 -2
  19. package/dist/components/index.d.ts.map +0 -1
  20. package/dist/components/templates/avatar/avatar.d.ts +0 -4
  21. package/dist/components/templates/avatar/avatar.d.ts.map +0 -1
  22. package/dist/components/templates/avatar/index.d.ts +0 -2
  23. package/dist/components/templates/avatar/index.d.ts.map +0 -1
  24. package/dist/components/templates/bot-typing-box/bot-typing-box.d.ts +0 -9
  25. package/dist/components/templates/bot-typing-box/bot-typing-box.d.ts.map +0 -1
  26. package/dist/components/templates/bot-typing-box/index.d.ts +0 -2
  27. package/dist/components/templates/bot-typing-box/index.d.ts.map +0 -1
  28. package/dist/components/templates/bot-typing-box/resize-observer-box.d.ts +0 -9
  29. package/dist/components/templates/bot-typing-box/resize-observer-box.d.ts.map +0 -1
  30. package/dist/components/templates/button-template/button-template.d.ts +0 -9
  31. package/dist/components/templates/button-template/button-template.d.ts.map +0 -1
  32. package/dist/components/templates/button-template/card.d.ts +0 -9
  33. package/dist/components/templates/button-template/card.d.ts.map +0 -1
  34. package/dist/components/templates/button-template/index.d.ts +0 -2
  35. package/dist/components/templates/button-template/index.d.ts.map +0 -1
  36. package/dist/components/templates/carousel-template/carousel-template.d.ts +0 -9
  37. package/dist/components/templates/carousel-template/carousel-template.d.ts.map +0 -1
  38. package/dist/components/templates/carousel-template/index.d.ts +0 -2
  39. package/dist/components/templates/carousel-template/index.d.ts.map +0 -1
  40. package/dist/components/templates/hint-template/hint-template.d.ts +0 -9
  41. package/dist/components/templates/hint-template/hint-template.d.ts.map +0 -1
  42. package/dist/components/templates/hint-template/index.d.ts +0 -2
  43. package/dist/components/templates/hint-template/index.d.ts.map +0 -1
  44. package/dist/components/templates/index.d.ts +0 -8
  45. package/dist/components/templates/index.d.ts.map +0 -1
  46. package/dist/components/templates/quick-replies/index.d.ts +0 -2
  47. package/dist/components/templates/quick-replies/index.d.ts.map +0 -1
  48. package/dist/components/templates/quick-replies/quick-replies.d.ts +0 -10
  49. package/dist/components/templates/quick-replies/quick-replies.d.ts.map +0 -1
  50. package/dist/components/templates/template-box/index.d.ts +0 -3
  51. package/dist/components/templates/template-box/index.d.ts.map +0 -1
  52. package/dist/components/templates/template-box/template-box-content.d.ts +0 -12
  53. package/dist/components/templates/template-box/template-box-content.d.ts.map +0 -1
  54. package/dist/components/templates/template-box/template-box.d.ts +0 -14
  55. package/dist/components/templates/template-box/template-box.d.ts.map +0 -1
  56. package/dist/components/templates/text-template/index.d.ts +0 -2
  57. package/dist/components/templates/text-template/index.d.ts.map +0 -1
  58. package/dist/components/templates/text-template/text-template.d.ts +0 -9
  59. package/dist/components/templates/text-template/text-template.d.ts.map +0 -1
  60. package/dist/components/templates/time/index.d.ts +0 -2
  61. package/dist/components/templates/time/index.d.ts.map +0 -1
  62. package/dist/components/templates/time/time.d.ts +0 -9
  63. package/dist/components/templates/time/time.d.ts.map +0 -1
  64. package/dist/context/asgard-service-context.d.ts +0 -28
  65. package/dist/context/asgard-service-context.d.ts.map +0 -1
  66. package/dist/hooks/index.d.ts +0 -4
  67. package/dist/hooks/index.d.ts.map +0 -1
  68. package/dist/hooks/use-asgard-service-client.d.ts +0 -8
  69. package/dist/hooks/use-asgard-service-client.d.ts.map +0 -1
  70. package/dist/hooks/use-channel.d.ts +0 -19
  71. package/dist/hooks/use-channel.d.ts.map +0 -1
  72. package/dist/hooks/use-debounce.d.ts +0 -2
  73. package/dist/hooks/use-debounce.d.ts.map +0 -1
  74. package/dist/index.d.ts +0 -3
  75. package/dist/index.d.ts.map +0 -1
  76. package/dist/utils/format-time.d.ts +0 -2
  77. package/dist/utils/format-time.d.ts.map +0 -1
  78. package/dist/utils/index.d.ts +0 -2
  79. package/dist/utils/index.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,143 +1,206 @@
1
- import { jsx as o, jsxs as r } from "react/jsx-runtime";
2
- import { useRef as H, useEffect as y, useState as k, useCallback as g, useMemo as x, createContext as F, useContext as K } from "react";
3
- import { AsgardServiceClient as Q, Conversation as W, MessageTemplateType as C } from "@asgard-js/core";
4
- function V(n) {
5
- var t, e, s = "";
6
- if (typeof n == "string" || typeof n == "number") s += n;
7
- else if (typeof n == "object") if (Array.isArray(n)) {
8
- var c = n.length;
9
- for (t = 0; t < c; t++) n[t] && (e = V(n[t])) && (s && (s += " "), s += e);
10
- } else for (e in n) n[e] && (s && (s += " "), s += e);
11
- return s;
1
+ import { jsx as o, jsxs as _ } from "react/jsx-runtime";
2
+ import * as x from "react";
3
+ import { useRef as z, useEffect as R, useState as N, useCallback as d, useMemo as B, createContext as ot, useContext as st, memo as ct } from "react";
4
+ import { AsgardServiceClient as rt, Channel as it, Conversation as at, MessageTemplateType as j } from "@asgard-js/core";
5
+ function G(e) {
6
+ var t, s, n = "";
7
+ if (typeof e == "string" || typeof e == "number") n += e;
8
+ else if (typeof e == "object") if (Array.isArray(e)) {
9
+ var c = e.length;
10
+ for (t = 0; t < c; t++) e[t] && (s = G(e[t])) && (n && (n += " "), n += s);
11
+ } else for (s in e) e[s] && (n && (n += " "), n += s);
12
+ return n;
12
13
  }
13
- function u() {
14
- for (var n, t, e = 0, s = "", c = arguments.length; e < c; e++) (n = arguments[e]) && (t = V(n)) && (s && (s += " "), s += t);
15
- return s;
14
+ function T() {
15
+ for (var e, t, s = 0, n = "", c = arguments.length; s < c; s++) (e = arguments[s]) && (t = G(e)) && (n && (n += " "), n += t);
16
+ return n;
16
17
  }
17
- function X(n) {
18
- const { config: t } = n, e = H(null);
19
- return e.current || (e.current = new Q(t)), y(() => () => {
20
- e.current && (e.current.close(), e.current = null);
21
- }, [t]), e.current;
18
+ function lt(e) {
19
+ const { config: t } = e, s = z(null);
20
+ return s.current || (s.current = new rt(t)), R(() => () => {
21
+ s.current && (s.current.close(), s.current = null);
22
+ }, [t]), s.current;
22
23
  }
23
- function G(n) {
24
- const { client: t, customChannelId: e, initMessages: s, options: c } = n;
24
+ function _t(e) {
25
+ const {
26
+ client: t,
27
+ customChannelId: s,
28
+ customMessageId: n,
29
+ initMessages: c,
30
+ showDebugMessage: r
31
+ } = e;
25
32
  if (!t)
26
33
  throw new Error("Client instance is required");
27
- if (!e)
34
+ if (!s)
28
35
  throw new Error("Custom channel id is required");
29
- const [a, _] = k(
30
- new W({
31
- messages: new Map(
32
- s == null ? void 0 : s.map((i) => [i.messageId, i])
33
- ),
34
- typingMessages: null
35
- })
36
- );
37
- y(() => {
38
- t.setChannel({
39
- customChannelId: e,
40
- customMessageId: ""
41
- });
42
- }, [t, e]);
43
- const l = g(
44
- (i, h) => {
45
- _((d) => {
46
- const p = d.pushMessage(
47
- d,
48
- {
49
- type: "user",
50
- messageId: h ?? crypto.randomUUID(),
51
- text: i,
52
- time: /* @__PURE__ */ new Date()
53
- }
54
- );
55
- return t.sendMessage(
56
- {
57
- customChannelId: e,
58
- customMessageId: h,
59
- text: i
60
- },
61
- {
62
- onSseMessage: (N) => {
63
- _(
64
- (M) => p.onMessage(M, N, {
65
- showDebugMessage: c == null ? void 0 : c.showDebugMessage
66
- })
67
- );
68
- }
69
- }
70
- ), p;
71
- });
36
+ const [i, a] = N(null), [u, p] = N(!0), [m, b] = N(!1), [l, h] = N(!1), [f, v] = N(null), C = z(null), L = d(() => {
37
+ b(!0), t == null || t.resetChannel(
38
+ { customChannelId: s, customMessageId: n },
39
+ {
40
+ onSseCompleted: () => {
41
+ b(!1), a(() => {
42
+ const g = new it({
43
+ client: t,
44
+ customChannelId: s,
45
+ conversation: new at({
46
+ showDebugMessage: r,
47
+ messages: new Map(
48
+ c == null ? void 0 : c.map((w) => [w.messageId, w])
49
+ )
50
+ })
51
+ });
52
+ return p(!0), h(g.isConnecting$.value), v(g.conversation$.value), g;
53
+ });
54
+ }
55
+ }
56
+ );
57
+ }, [
58
+ t,
59
+ s,
60
+ n,
61
+ c,
62
+ r
63
+ ]), M = d(() => {
64
+ var g;
65
+ a((w) => (w == null || w.close(), null)), p(!1), b(!1), h(!1), v(null), (g = C.current) == null || g.forEach(
66
+ (w) => w.unsubscribe()
67
+ );
68
+ }, []), $ = d(
69
+ (g) => {
70
+ i == null || i.sendMessage({ text: g });
72
71
  },
73
- [t, e, c]
72
+ [i]
74
73
  );
75
- return x(
74
+ return R(() => {
75
+ if (i)
76
+ return C.current = [
77
+ i == null ? void 0 : i.isConnecting$.subscribe(h),
78
+ i == null ? void 0 : i.conversation$.subscribe(v)
79
+ ], () => {
80
+ var g;
81
+ (g = C.current) == null || g.forEach(
82
+ (w) => w.unsubscribe()
83
+ );
84
+ };
85
+ }, [i]), R(() => {
86
+ !i && u && L();
87
+ }, [i, u, L]), R(() => () => M(), [M]), B(
76
88
  () => ({
77
- messages: a.messages,
78
- typingMessages: a.typingMessages,
79
- sendMessage: l
89
+ isOpen: u,
90
+ isResetting: m,
91
+ isConnecting: l,
92
+ conversation: f,
93
+ sendMessage: $,
94
+ resetChannel: L,
95
+ closeChannel: M
80
96
  }),
81
- [a, l]
97
+ [
98
+ u,
99
+ m,
100
+ l,
101
+ f,
102
+ $,
103
+ L,
104
+ M
105
+ ]
82
106
  );
83
107
  }
84
- function J(n, t) {
85
- const [e, s] = k(n);
86
- return y(() => {
108
+ function ut(e, t) {
109
+ const [s, n] = N(e);
110
+ return R(() => {
87
111
  const c = window.setTimeout(() => {
88
- s(n);
112
+ n(e);
89
113
  }, t ?? 300);
90
114
  return () => clearTimeout(c);
91
- }, [n, t]), e;
115
+ }, [e, t]), s;
92
116
  }
93
- const E = F({
117
+ const Y = ot({
118
+ avatar: void 0,
94
119
  client: null,
120
+ isOpen: !1,
121
+ isResetting: !1,
95
122
  isConnecting: !1,
96
123
  messages: null,
97
- typingMessages: null,
98
124
  messageBoxBottomRef: { current: null },
99
- sendMessage: () => {
100
- }
125
+ botTypingPlaceholder: void 0
101
126
  });
102
- function Y(n) {
127
+ function dt(e) {
103
128
  const {
104
- children: t,
105
- config: e,
106
- customChannelId: s,
107
- customMessageId: c,
129
+ avatar: t,
130
+ children: s,
131
+ config: n,
132
+ botTypingPlaceholder: c,
133
+ customChannelId: r,
134
+ customMessageId: i,
108
135
  delayTime: a,
109
- initMessages: _,
110
- options: l,
111
- ...i
112
- } = n, h = H(null), d = X({ config: e }), { messages: p, typingMessages: N, sendMessage: M } = G({
113
- client: d,
114
- customChannelId: s,
115
- initMessages: _,
116
- options: l
117
- }), L = x(
136
+ initMessages: u,
137
+ options: p,
138
+ ...m
139
+ } = e, b = z(null), l = lt({ config: n }), {
140
+ isOpen: h,
141
+ isResetting: f,
142
+ isConnecting: v,
143
+ conversation: C,
144
+ sendMessage: L,
145
+ resetChannel: M,
146
+ closeChannel: $
147
+ } = _t({
148
+ client: l,
149
+ customChannelId: r,
150
+ initMessages: u,
151
+ showDebugMessage: p == null ? void 0 : p.showDebugMessage
152
+ }), g = B(
118
153
  () => ({
119
- client: d,
120
- isConnecting: (d == null ? void 0 : d.isConnecting) ?? !1,
121
- messages: p,
122
- typingMessages: N,
123
- sendMessage: M,
124
- messageBoxBottomRef: h
154
+ avatar: t,
155
+ client: l,
156
+ isOpen: h,
157
+ isResetting: f,
158
+ isConnecting: v,
159
+ messages: (C == null ? void 0 : C.messages) ?? null,
160
+ sendMessage: L,
161
+ resetChannel: M,
162
+ closeChannel: $,
163
+ botTypingPlaceholder: c,
164
+ messageBoxBottomRef: b
125
165
  }),
126
- [d, p, M, N]
166
+ [
167
+ t,
168
+ l,
169
+ h,
170
+ f,
171
+ v,
172
+ C == null ? void 0 : C.messages,
173
+ L,
174
+ M,
175
+ $,
176
+ c
177
+ ]
127
178
  );
128
- return /* @__PURE__ */ o(E.Provider, { value: L, children: /* @__PURE__ */ o("div", { ...i, children: t }) });
179
+ return /* @__PURE__ */ o(Y.Provider, { value: g, children: /* @__PURE__ */ o("div", { ...m, children: s }) });
129
180
  }
130
- function w() {
131
- return K(E);
181
+ function y() {
182
+ return st(Y);
132
183
  }
133
- const tt = "_chatbot_header_1xj9n_1", et = "_chatbot_header__content_1xj9n_1", ot = "_chatbot_header__title_1xj9n_9", nt = "_chatbot_header__extra_1xj9n_20", T = {
134
- chatbot_header: tt,
135
- chatbot_header__content: et,
136
- chatbot_header__title: ot,
137
- chatbot_header__extra: nt
184
+ const ht = "_chatbot_header_f3p4c_1", mt = "_chatbot_header__content_f3p4c_1", bt = "_chatbot_header__title_f3p4c_9", gt = "_chatbot_header__extra_f3p4c_20", I = {
185
+ chatbot_header: ht,
186
+ chatbot_header__content: mt,
187
+ chatbot_header__title: bt,
188
+ chatbot_header__extra: gt
138
189
  };
139
- function st() {
140
- return /* @__PURE__ */ r(
190
+ function pt(e) {
191
+ const { avatar: t } = e;
192
+ return t ? /* @__PURE__ */ o(
193
+ "img",
194
+ {
195
+ src: t,
196
+ alt: "avatar",
197
+ style: {
198
+ width: 33,
199
+ height: 32,
200
+ borderRadius: "50%"
201
+ }
202
+ }
203
+ ) : /* @__PURE__ */ _(
141
204
  "svg",
142
205
  {
143
206
  width: "33",
@@ -146,7 +209,7 @@ function st() {
146
209
  fill: "none",
147
210
  xmlns: "http://www.w3.org/2000/svg",
148
211
  children: [
149
- /* @__PURE__ */ r("g", { "clip-path": "url(#clip0_3084_29383)", children: [
212
+ /* @__PURE__ */ _("g", { "clip-path": "url(#clip0_3084_29383)", children: [
150
213
  /* @__PURE__ */ o(
151
214
  "path",
152
215
  {
@@ -175,96 +238,116 @@ function st() {
175
238
  }
176
239
  );
177
240
  }
178
- function ct(n) {
179
- const { title: t } = n;
180
- return /* @__PURE__ */ o("div", { className: T.chatbot_header, children: /* @__PURE__ */ r("div", { className: T.chatbot_header__content, children: [
181
- /* @__PURE__ */ r("div", { className: T.chatbot_header__title, children: [
182
- /* @__PURE__ */ o(st, {}),
241
+ const ft = (e) => /* @__PURE__ */ x.createElement("svg", { width: 16, height: 16, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ x.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" })), Ct = (e) => /* @__PURE__ */ x.createElement("svg", { width: 15, height: 14, viewBox: "0 0 15 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ x.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" }));
242
+ function vt(e) {
243
+ const { title: t } = e, { avatar: s, isOpen: n, isResetting: c, resetChannel: r, closeChannel: i } = y(), a = d(
244
+ (m) => {
245
+ !n && !c && (m.stopPropagation(), r == null || r());
246
+ },
247
+ [n, c, r]
248
+ ), u = d(
249
+ (m) => {
250
+ n && !c && (m.stopPropagation(), r == null || r());
251
+ },
252
+ [n, c, r]
253
+ ), p = d(
254
+ (m) => {
255
+ c || (m.stopPropagation(), i == null || i());
256
+ },
257
+ [c, i]
258
+ );
259
+ return /* @__PURE__ */ o("div", { className: I.chatbot_header, onClick: a, children: /* @__PURE__ */ _("div", { className: I.chatbot_header__content, children: [
260
+ /* @__PURE__ */ _("div", { className: I.chatbot_header__title, children: [
261
+ /* @__PURE__ */ o(pt, { avatar: s }),
183
262
  /* @__PURE__ */ o("h4", { children: t })
184
263
  ] }),
185
- /* @__PURE__ */ o("div", { className: T.chatbot_header__extra })
264
+ /* @__PURE__ */ _("div", { className: I.chatbot_header__extra, children: [
265
+ /* @__PURE__ */ o("div", { onClick: u, children: /* @__PURE__ */ o(ft, {}) }),
266
+ /* @__PURE__ */ o("div", { onClick: p, children: /* @__PURE__ */ o(Ct, {}) })
267
+ ] })
186
268
  ] }) });
187
269
  }
188
- const rt = "_chatbot_body_1f0gq_1", at = "_chatbot_body__content_1f0gq_7", $ = {
189
- chatbot_body: rt,
190
- chatbot_body__content: at
191
- }, it = "_template_box_1ozig_1", m = {
192
- template_box: it,
270
+ const xt = "_chatbot_body_1f0gq_1", yt = "_chatbot_body__content_1f0gq_7", P = {
271
+ chatbot_body: xt,
272
+ chatbot_body__content: yt
273
+ }, wt = "_template_box_1ozig_1", k = {
274
+ template_box: wt,
193
275
  "template_box--bot": "_template_box--bot_1ozig_7",
194
276
  "template_box--horizontal": "_template_box--horizontal_1ozig_7",
195
277
  "template_box--vertical": "_template_box--vertical_1ozig_10",
196
278
  "template_box--user": "_template_box--user_1ozig_14"
197
279
  };
198
- function v(n) {
199
- const { type: t, direction: e = "horizontal", children: s } = n, c = x(() => {
280
+ function E(e) {
281
+ const { type: t, direction: s = "horizontal", children: n } = e, c = B(() => {
200
282
  switch (t) {
201
283
  case "user":
202
- return u(m.template_box, m["template_box--user"]);
284
+ return T(k.template_box, k["template_box--user"]);
203
285
  case "bot":
204
286
  default:
205
- return u(
206
- m.template_box,
207
- m["template_box--bot"],
208
- e === "horizontal" ? m["template_box--horizontal"] : m["template_box--vertical"]
287
+ return T(
288
+ k.template_box,
289
+ k["template_box--bot"],
290
+ s === "horizontal" ? k["template_box--horizontal"] : k["template_box--vertical"]
209
291
  );
210
292
  }
211
- }, [e, t]);
212
- return /* @__PURE__ */ o("div", { className: c, children: s });
293
+ }, [s, t]);
294
+ return /* @__PURE__ */ o("div", { className: c, children: n });
213
295
  }
214
- const lt = "_template_box_content_12ojl_1", _t = "_content_12ojl_7", q = {
215
- template_box_content: lt,
216
- content: _t
217
- }, dt = "_quick_replies_box_19pe0_1", ht = "_quick_reply_19pe0_7", S = {
218
- quick_replies_box: dt,
219
- quick_reply: ht
296
+ const Nt = "_template_box_content_12ojl_1", Tt = "_content_12ojl_7", F = {
297
+ template_box_content: Nt,
298
+ content: Tt
299
+ }, Rt = "_quick_replies_box_zoq7y_1", Lt = "_quick_reply_zoq7y_7", U = {
300
+ quick_replies_box: Rt,
301
+ quick_reply: Lt
220
302
  };
221
- function ut(n) {
222
- const { quickReplies: t } = n, { sendMessage: e } = w(), s = g(
223
- (c) => {
224
- e(c);
303
+ function Mt(e) {
304
+ const { quickReplies: t } = e, { sendMessage: s, isConnecting: n } = y(), c = d(
305
+ (r) => {
306
+ s == null || s(r);
225
307
  },
226
- [e]
308
+ [s]
227
309
  );
228
- return t != null && t.length ? /* @__PURE__ */ o("div", { className: S.quick_replies_box, children: t.map((c) => /* @__PURE__ */ o(
229
- "div",
310
+ return t != null && t.length ? /* @__PURE__ */ o("div", { className: U.quick_replies_box, children: t.map((r) => /* @__PURE__ */ o(
311
+ "button",
230
312
  {
231
- className: S.quick_reply,
232
- onClick: () => s(c.text),
233
- children: c.text
313
+ className: U.quick_reply,
314
+ disabled: n,
315
+ onClick: () => c(r.text),
316
+ children: r.text
234
317
  },
235
- c.text
318
+ r.text
236
319
  )) }) : null;
237
320
  }
238
- function O(n) {
239
- return n.toLocaleTimeString("zh-TW", {
321
+ function tt(e) {
322
+ return e.toLocaleTimeString("zh-TW", {
240
323
  timeZone: "Asia/Taipei",
241
324
  hour: "2-digit",
242
325
  minute: "2-digit",
243
326
  hour12: !1
244
327
  });
245
328
  }
246
- const mt = "_time_rgg92_1", bt = {
247
- time: mt
329
+ const St = "_time_rgg92_1", Bt = {
330
+ time: St
248
331
  };
249
- function I(n) {
250
- const { time: t, className: e } = n;
251
- return t ? /* @__PURE__ */ o("div", { className: u(bt.time, e), children: O(t) }) : null;
332
+ function D(e) {
333
+ const { time: t, className: s } = e;
334
+ return t ? /* @__PURE__ */ o("div", { className: T(Bt.time, s), children: tt(t) }) : null;
252
335
  }
253
- function R(n) {
254
- const { quickReplies: t, time: e, children: s } = n;
255
- return /* @__PURE__ */ r("div", { className: q.template_box_content, children: [
256
- /* @__PURE__ */ r("div", { className: q.content, children: [
257
- s,
258
- /* @__PURE__ */ o(I, { time: e })
336
+ function O(e) {
337
+ const { quickReplies: t, time: s, children: n } = e;
338
+ return /* @__PURE__ */ _("div", { className: F.template_box_content, children: [
339
+ /* @__PURE__ */ _("div", { className: F.content, children: [
340
+ n,
341
+ /* @__PURE__ */ o(D, { time: s })
259
342
  ] }),
260
- !!(t != null && t.length) && /* @__PURE__ */ o(ut, { quickReplies: t })
343
+ !!(t != null && t.length) && /* @__PURE__ */ o(Mt, { quickReplies: t })
261
344
  ] });
262
345
  }
263
- const gt = "_bot_avatar_14r1r_1", pt = {
264
- bot_avatar: gt
265
- };
266
- function z() {
267
- return /* @__PURE__ */ o("div", { className: pt.bot_avatar, children: /* @__PURE__ */ r(
346
+ const kt = "_bot_avatar_xrs9x_1", J = {
347
+ bot_avatar: kt
348
+ }, A = ct((e) => {
349
+ const { avatar: t } = e;
350
+ return t ? /* @__PURE__ */ o("img", { src: t, alt: "Bot Avatar", className: J.bot_avatar }) : /* @__PURE__ */ o("div", { className: J.bot_avatar, children: /* @__PURE__ */ _(
268
351
  "svg",
269
352
  {
270
353
  style: { width: "100%", height: "100%" },
@@ -289,55 +372,63 @@ function z() {
289
372
  ]
290
373
  }
291
374
  ) });
292
- }
293
- const ft = "_text_1djgp_1", Ct = "_dot_1djgp_18", xt = "_blink_1djgp_1", b = {
294
- text: ft,
375
+ }), Ht = "_text_1djgp_1", zt = "_dot_1djgp_18", $t = "_blink_1djgp_1", H = {
376
+ text: Ht,
295
377
  "text--bot": "_text--bot_1djgp_7",
296
378
  "typing-indicator": "_typing-indicator_1djgp_13",
297
- dot: Ct,
298
- blink: xt
379
+ dot: zt,
380
+ blink: $t
299
381
  };
300
- function vt(n) {
301
- const { children: t, onResize: e } = n, s = H(null);
302
- return y(() => {
303
- const c = new ResizeObserver((a) => {
304
- for (const _ of a) {
305
- const { width: l, height: i } = _.contentRect;
306
- e(l, i);
382
+ function Vt(e) {
383
+ const { children: t, onResize: s } = e, n = z(null);
384
+ return R(() => {
385
+ const c = new ResizeObserver((r) => {
386
+ for (const i of r) {
387
+ const { width: a, height: u } = i.contentRect;
388
+ s(a, u);
307
389
  }
308
390
  });
309
- return s.current && c.observe(s.current), () => {
391
+ return n.current && c.observe(n.current), () => {
310
392
  c.disconnect();
311
393
  };
312
- }, [s, e]), /* @__PURE__ */ o("div", { ref: s, children: t });
394
+ }, [n, s]), /* @__PURE__ */ o("div", { ref: n, children: t });
313
395
  }
314
- function yt(n) {
315
- const { typingMessage: t } = n, { messageBoxBottomRef: e } = w(), s = g(() => {
396
+ function et(e) {
397
+ const { isTyping: t, typingText: s } = e, { messageBoxBottomRef: n, avatar: c } = y(), r = d(() => {
316
398
  var a;
317
- (a = e.current) == null || a.scrollIntoView({ behavior: "smooth" });
318
- }, [e]), c = J(t == null ? void 0 : t.isTyping, 500);
319
- return c ? /* @__PURE__ */ r(v, { type: "bot", direction: "horizontal", children: [
320
- /* @__PURE__ */ o(z, {}),
321
- /* @__PURE__ */ o(R, { time: /* @__PURE__ */ new Date(), children: /* @__PURE__ */ o("div", { className: u(b.text, b["text--bot"]), children: /* @__PURE__ */ r(vt, { onResize: s, children: [
322
- /* @__PURE__ */ o("span", { children: (t == null ? void 0 : t.typingText) ?? "" }),
323
- c && /* @__PURE__ */ r("span", { className: b["typing-indicator"], children: [
324
- /* @__PURE__ */ o("div", { className: b.dot }),
325
- /* @__PURE__ */ o("div", { className: b.dot }),
326
- /* @__PURE__ */ o("div", { className: b.dot })
399
+ (a = n.current) == null || a.scrollIntoView({ behavior: "smooth" });
400
+ }, [n]), i = ut(t, 500);
401
+ return i ? /* @__PURE__ */ _(E, { type: "bot", direction: "horizontal", children: [
402
+ /* @__PURE__ */ o(A, { avatar: c }),
403
+ /* @__PURE__ */ o(O, { time: /* @__PURE__ */ new Date(), children: /* @__PURE__ */ o("div", { className: T(H.text, H["text--bot"]), children: /* @__PURE__ */ _(Vt, { onResize: r, children: [
404
+ /* @__PURE__ */ o("span", { children: s ?? "" }),
405
+ i && /* @__PURE__ */ _("span", { className: H["typing-indicator"], children: [
406
+ /* @__PURE__ */ o("div", { className: H.dot }),
407
+ /* @__PURE__ */ o("div", { className: H.dot }),
408
+ /* @__PURE__ */ o("div", { className: H.dot })
327
409
  ] })
328
410
  ] }) }) })
329
411
  ] }) : null;
330
412
  }
331
- const wt = "_card_root_1ygom_1", Nt = "_card_content_1ygom_10", Mt = "_card_title_1ygom_17", Tt = "_card_description_1ygom_23", jt = "_card_actions_1ygom_37", f = {
332
- card_root: wt,
333
- card_content: Nt,
334
- card_title: Mt,
335
- card_description: Tt,
336
- card_actions: jt
413
+ function jt(e) {
414
+ const { placeholder: t } = e, { isConnecting: s, messages: n } = y(), c = B(
415
+ () => Array.from((n == null ? void 0 : n.values()) ?? []).some(
416
+ (r) => r.type === "bot" && r.isTyping
417
+ ),
418
+ [n]
419
+ );
420
+ return s && !c ? /* @__PURE__ */ o(et, { isTyping: !0, typingText: t }) : null;
421
+ }
422
+ const Et = "_card_root_1ygom_1", It = "_card_content_1ygom_10", Zt = "_card_title_1ygom_17", qt = "_card_description_1ygom_23", At = "_card_actions_1ygom_37", V = {
423
+ card_root: Et,
424
+ card_content: It,
425
+ card_title: Zt,
426
+ card_description: qt,
427
+ card_actions: At
337
428
  };
338
- function P(n) {
339
- var _;
340
- const { template: t } = n, { sendMessage: e } = w(), s = x(() => (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 = x(() => {
429
+ function nt(e) {
430
+ var i;
431
+ const { template: t } = e, { sendMessage: s } = y(), n = B(() => (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 = B(() => {
341
432
  switch (t == null ? void 0 : t.imageAspectRatio) {
342
433
  case "square":
343
434
  return "1 / 1";
@@ -345,25 +436,25 @@ function P(n) {
345
436
  default:
346
437
  return "1.51 / 1";
347
438
  }
348
- }, [t]), a = g(
349
- (l) => function() {
350
- switch (l.type) {
439
+ }, [t]), r = d(
440
+ (a) => function() {
441
+ switch (a.type) {
351
442
  case "message":
352
- e(l.text);
443
+ s(a.text);
353
444
  return;
354
445
  case "uri":
355
- window.open(l.uri, "_blank");
446
+ window.open(a.uri, "_blank");
356
447
  return;
357
448
  }
358
449
  },
359
- [e]
450
+ [s]
360
451
  );
361
- return /* @__PURE__ */ r("div", { className: f.card_root, children: [
452
+ return /* @__PURE__ */ _("div", { className: V.card_root, children: [
362
453
  (t == null ? void 0 : t.thumbnailImageUrl) && /* @__PURE__ */ o(
363
454
  "img",
364
455
  {
365
456
  alt: t == null ? void 0 : t.title,
366
- src: s,
457
+ src: n,
367
458
  style: {
368
459
  display: "block",
369
460
  width: "100%",
@@ -372,186 +463,301 @@ function P(n) {
372
463
  }
373
464
  }
374
465
  ),
375
- /* @__PURE__ */ r("div", { className: f.card_content, children: [
376
- /* @__PURE__ */ o("h5", { className: f.card_title, children: t == null ? void 0 : t.title }),
377
- /* @__PURE__ */ o("div", { className: f.card_description, children: t == null ? void 0 : t.text }),
378
- /* @__PURE__ */ o("div", { className: f.card_actions, children: (_ = t == null ? void 0 : t.buttons) == null ? void 0 : _.map((l, i) => /* @__PURE__ */ o("button", { onClick: a(l.action), children: l.label }, i)) })
466
+ /* @__PURE__ */ _("div", { className: V.card_content, children: [
467
+ /* @__PURE__ */ o("h5", { className: V.card_title, children: t == null ? void 0 : t.title }),
468
+ /* @__PURE__ */ o("div", { className: V.card_description, children: t == null ? void 0 : t.text }),
469
+ /* @__PURE__ */ o("div", { className: V.card_actions, children: (i = t == null ? void 0 : t.buttons) == null ? void 0 : i.map((a, u) => /* @__PURE__ */ o("button", { onClick: r(a.action), children: a.label }, u)) })
379
470
  ] })
380
471
  ] });
381
472
  }
382
- function kt(n) {
383
- const { conversationMessage: t } = n, e = t.message.template;
384
- return /* @__PURE__ */ r(v, { type: "bot", direction: "horizontal", children: [
385
- /* @__PURE__ */ o(z, {}),
473
+ function Dt(e) {
474
+ const { message: t } = e, { avatar: s } = y(), n = t.message.template;
475
+ return /* @__PURE__ */ _(E, { type: "bot", direction: "horizontal", children: [
476
+ /* @__PURE__ */ o(A, { avatar: s }),
386
477
  /* @__PURE__ */ o(
387
- R,
478
+ O,
388
479
  {
389
480
  time: t.time,
390
- quickReplies: e == null ? void 0 : e.quickReplies,
391
- children: /* @__PURE__ */ o(P, { template: e })
481
+ quickReplies: n == null ? void 0 : n.quickReplies,
482
+ children: /* @__PURE__ */ o(nt, { template: n })
392
483
  }
393
484
  )
394
485
  ] });
395
486
  }
396
- const zt = "_text_sbjtw_1", Bt = "_content_sbjtw_19", j = {
397
- text: zt,
487
+ const Ot = "_text_sbjtw_1", Pt = "_content_sbjtw_19", Z = {
488
+ text: Ot,
398
489
  "text--user": "_text--user_sbjtw_7",
399
490
  "text--bot": "_text--bot_sbjtw_13",
400
- content: Bt
491
+ content: Pt
401
492
  };
402
- function A(n) {
403
- var e;
404
- const { conversationMessage: t } = n;
405
- return t.type === "user" ? /* @__PURE__ */ r(v, { type: "user", direction: "horizontal", children: [
406
- /* @__PURE__ */ o("div", { className: u(j.text, j["text--user"]), children: t.text }),
407
- /* @__PURE__ */ o(I, { time: t.time })
408
- ] }) : /* @__PURE__ */ r(v, { type: "bot", direction: "horizontal", children: [
409
- /* @__PURE__ */ o(z, {}),
493
+ function W(e) {
494
+ var n;
495
+ const { message: t } = e, { avatar: s } = y();
496
+ return t.type === "user" ? /* @__PURE__ */ _(E, { type: "user", direction: "horizontal", children: [
497
+ /* @__PURE__ */ o("div", { className: T(Z.text, Z["text--user"]), children: t.text }),
498
+ /* @__PURE__ */ o(D, { time: t.time })
499
+ ] }) : /* @__PURE__ */ _(E, { type: "bot", direction: "horizontal", children: [
500
+ /* @__PURE__ */ o(A, { avatar: s }),
410
501
  /* @__PURE__ */ o(
411
- R,
502
+ O,
412
503
  {
413
504
  time: t.time,
414
- quickReplies: (e = t.message.template) == null ? void 0 : e.quickReplies,
415
- children: /* @__PURE__ */ o("div", { className: u(j.text, j["text--bot"]), children: t.message.text })
505
+ quickReplies: (n = t.message.template) == null ? void 0 : n.quickReplies,
506
+ children: /* @__PURE__ */ o("div", { className: T(Z.text, Z["text--bot"]), children: t.message.text })
416
507
  }
417
508
  )
418
509
  ] });
419
510
  }
420
- const Ht = "_carousel_root_sv1hc_1", It = "_carousel_time_sv1hc_12", Z = {
421
- carousel_root: Ht,
422
- carousel_time: It
511
+ const Ft = "_carousel_root_sv1hc_1", Ut = "_carousel_time_sv1hc_12", K = {
512
+ carousel_root: Ft,
513
+ carousel_time: Ut
423
514
  };
424
- function Rt(n) {
425
- var s;
426
- const { conversationMessage: t } = n, e = t.message.template;
427
- return /* @__PURE__ */ r(v, { type: "bot", direction: "vertical", children: [
428
- /* @__PURE__ */ o(z, {}),
429
- /* @__PURE__ */ o("div", { className: Z.carousel_root, children: (s = e.columns) == null ? void 0 : s.map((c, a) => /* @__PURE__ */ o(P, { template: c }, a)) }),
430
- /* @__PURE__ */ o(I, { className: Z.carousel_time, time: t.time })
515
+ function Jt(e) {
516
+ var c;
517
+ const { message: t } = e, { avatar: s } = y(), n = t.message.template;
518
+ return /* @__PURE__ */ _(E, { type: "bot", direction: "vertical", children: [
519
+ /* @__PURE__ */ o(A, { avatar: s }),
520
+ /* @__PURE__ */ o("div", { className: K.carousel_root, children: (c = n.columns) == null ? void 0 : c.map((r, i) => /* @__PURE__ */ o(nt, { template: r }, i)) }),
521
+ /* @__PURE__ */ o(D, { className: K.carousel_time, time: t.time })
431
522
  ] });
432
523
  }
433
- const $t = "_hint_root_g119q_1", qt = "_time_g119q_14", U = {
434
- hint_root: $t,
435
- time: qt
524
+ const Wt = "_hint_root_g119q_1", Kt = "_time_g119q_14", Q = {
525
+ hint_root: Wt,
526
+ time: Kt
436
527
  };
437
- function St(n) {
438
- const { conversationMessage: t } = n;
528
+ function Qt(e) {
529
+ const { message: t } = e;
439
530
  if (t.type === "user") return null;
440
- const e = t.message.template;
441
- return e.type !== C.HINT ? null : /* @__PURE__ */ r("div", { className: U.hint_root, children: [
442
- /* @__PURE__ */ o("div", { className: U.time, children: O(t.time) }),
443
- e.text
531
+ const s = t.message.template;
532
+ return s.type !== j.HINT ? null : /* @__PURE__ */ _("div", { className: Q.hint_root, children: [
533
+ /* @__PURE__ */ o("div", { className: Q.time, children: tt(t.time) }),
534
+ s.text
444
535
  ] });
445
536
  }
446
- function At(n) {
447
- const { conversationMessage: t } = n;
537
+ function Xt(e) {
538
+ var s;
539
+ const { message: t } = e;
448
540
  if (t.type === "user")
449
- return /* @__PURE__ */ o(A, { conversationMessage: t });
450
- const e = t.message.template;
451
- switch (e == null ? void 0 : e.type) {
452
- case C.TEXT:
453
- return /* @__PURE__ */ o(A, { conversationMessage: t });
454
- case C.HINT:
455
- return /* @__PURE__ */ o(St, { conversationMessage: t });
456
- case C.BUTTON:
457
- return /* @__PURE__ */ o(kt, { conversationMessage: t });
458
- case C.CAROUSEL:
459
- return /* @__PURE__ */ o(Rt, { conversationMessage: t });
541
+ return /* @__PURE__ */ o(W, { message: t });
542
+ if (t.isTyping)
543
+ return /* @__PURE__ */ o(
544
+ et,
545
+ {
546
+ isTyping: t.isTyping,
547
+ typingText: t.typingText
548
+ }
549
+ );
550
+ switch ((s = t.message.template) == null ? void 0 : s.type) {
551
+ case j.TEXT:
552
+ return /* @__PURE__ */ o(W, { message: t });
553
+ case j.HINT:
554
+ return /* @__PURE__ */ o(Qt, { message: t });
555
+ case j.BUTTON:
556
+ return /* @__PURE__ */ o(Dt, { message: t });
557
+ case j.CAROUSEL:
558
+ return /* @__PURE__ */ o(Jt, { message: t });
460
559
  default:
461
- return /* @__PURE__ */ o("div", { children: "Unknown template" });
560
+ return /* @__PURE__ */ o("div", {});
462
561
  }
463
562
  }
464
- function Zt() {
465
- const { messages: n, typingMessages: t, messageBoxBottomRef: e } = w();
466
- return y(() => {
467
- var s;
468
- (s = e.current) == null || s.scrollIntoView({ behavior: "smooth" });
469
- }, [n, e]), /* @__PURE__ */ o("div", { className: $.chatbot_body, children: /* @__PURE__ */ r("div", { className: $.chatbot_body__content, children: [
470
- Array.from((n == null ? void 0 : n.values()) ?? []).map((s) => /* @__PURE__ */ o(
471
- At,
563
+ function Gt() {
564
+ const { messages: e, messageBoxBottomRef: t, botTypingPlaceholder: s } = y();
565
+ return R(() => {
566
+ var n;
567
+ (n = t.current) == null || n.scrollIntoView({ behavior: "smooth" });
568
+ }, [e, t]), /* @__PURE__ */ o("div", { className: P.chatbot_body, children: /* @__PURE__ */ _("div", { className: P.chatbot_body__content, children: [
569
+ Array.from((e == null ? void 0 : e.values()) ?? []).map((n) => /* @__PURE__ */ o(
570
+ Xt,
472
571
  {
473
- conversationMessage: s
572
+ message: n
474
573
  },
475
- crypto.randomUUID()
574
+ n.messageId
476
575
  )),
477
- Array.from((t == null ? void 0 : t.values()) ?? []).map((s) => /* @__PURE__ */ o(
478
- yt,
576
+ /* @__PURE__ */ o(
577
+ jt,
479
578
  {
480
- typingMessage: s
481
- },
482
- crypto.randomUUID()
483
- )),
484
- /* @__PURE__ */ o("div", { ref: e })
579
+ placeholder: s ?? "正在輸入訊息"
580
+ }
581
+ ),
582
+ /* @__PURE__ */ o("div", { ref: t })
485
583
  ] }) });
486
584
  }
487
- const Ut = "_chatbot_footer_3box0_1", Dt = "_chatbot_footer__content_3box0_1", Vt = "_chatbot_textarea_3box0_8", B = {
488
- chatbot_footer: Ut,
489
- chatbot_footer__content: Dt,
490
- chatbot_textarea: Vt
491
- };
492
- function Et() {
493
- const { sendMessage: n, isConnecting: t } = w(), [e, s] = k(""), [c, a] = k(!1), _ = g(
494
- (i) => {
495
- const h = i.target, d = h.value;
496
- h.style.height = "20px", d && (h.style.height = `${h.scrollHeight - 16}px`), s(i.target.value);
585
+ const Yt = "_chatbot_footer_aa5it_1", te = "_chatbot_footer__content_aa5it_1", ee = "_chatbot_textarea_aa5it_12", ne = "_chatbot_submit_button_aa5it_27", oe = "_chatbot_submit_button__disabled_aa5it_52", S = {
586
+ chatbot_footer: Yt,
587
+ chatbot_footer__content: te,
588
+ chatbot_textarea: ee,
589
+ chatbot_submit_button: ne,
590
+ chatbot_submit_button__disabled: oe
591
+ }, se = (e) => /* @__PURE__ */ x.createElement("svg", { width: 15, height: 12, viewBox: "0 0 15 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ x.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" })), ce = (e) => /* @__PURE__ */ x.createElement("svg", { width: 11, height: 16, viewBox: "0 0 11 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ x.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" })), re = (e) => /* @__PURE__ */ x.createElement("svg", { width: 40, height: 40, viewBox: "0 0 40 40", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ x.createElement("circle", { cx: 20, cy: 20, r: 18, fill: "#D04444" }), /* @__PURE__ */ x.createElement("rect", { x: 12, y: 12, width: 16, height: 16, fill: "#FFFFFF", rx: 2, ry: 2 }));
592
+ function ie(e) {
593
+ const { setValue: t, className: s } = e, [n, c] = N(!1), r = z(null);
594
+ R(() => {
595
+ const l = window.SpeechRecognition || window.webkitSpeechRecognition;
596
+ if (!l) return;
597
+ const h = new l();
598
+ h.lang = "zh-TW", h.continuous = !0, h.interimResults = !0, h.onresult = (f) => {
599
+ for (let v = f.resultIndex; v < f.results.length; v++)
600
+ f.results[v].isFinal && t((C) => C + f.results[v][0].transcript);
601
+ }, h.onerror = (f) => {
602
+ alert(`語音識別錯誤: ${JSON.stringify(f.error)}`);
603
+ }, h.onend = () => {
604
+ c(!1);
605
+ }, r.current = h;
606
+ }, [t]);
607
+ const i = d(() => {
608
+ if (!r.current) {
609
+ alert("無法開始辨識: 語音識別器未初始化,請檢查是否有授權使用麥克風");
610
+ return;
611
+ }
612
+ try {
613
+ r.current.start(), c(!0);
614
+ } catch (l) {
615
+ alert(`無法開始辨識: ${JSON.stringify(l)}`);
616
+ }
617
+ }, []), a = d(() => {
618
+ r.current && (r.current.stop(), c(!1));
619
+ }, []), u = d(
620
+ (l) => {
621
+ n || (l.preventDefault(), i());
497
622
  },
498
- []
499
- ), l = g(
500
- (i) => {
501
- i.key === "Enter" && !c && !t && (n(e), s(""));
623
+ [n, i]
624
+ ), p = d(
625
+ (l) => {
626
+ n && (l.preventDefault(), a());
627
+ },
628
+ [n, a]
629
+ ), m = d(
630
+ (l) => {
631
+ n || (l.preventDefault(), i());
502
632
  },
503
- [c, t, n, e]
633
+ [n, i]
634
+ ), b = d(
635
+ (l) => {
636
+ n && (l.preventDefault(), a());
637
+ },
638
+ [n, a]
504
639
  );
505
- return /* @__PURE__ */ o("div", { className: B.chatbot_footer, children: /* @__PURE__ */ o("div", { className: B.chatbot_footer__content, children: /* @__PURE__ */ o(
506
- "textarea",
640
+ return /* @__PURE__ */ o(
641
+ "div",
507
642
  {
508
- className: B.chatbot_textarea,
509
- disabled: t,
510
- cols: 40,
511
- value: e,
512
- placeholder: "Enter message",
513
- onChange: _,
514
- onKeyDown: l,
515
- onCompositionStart: () => a(!0),
516
- onCompositionEnd: () => a(!1)
643
+ className: s,
644
+ onMouseDown: u,
645
+ onMouseUp: p,
646
+ onTouchStart: m,
647
+ onTouchEnd: b,
648
+ children: n ? /* @__PURE__ */ o(re, {}) : /* @__PURE__ */ o(ce, {})
517
649
  }
518
- ) }) });
650
+ );
519
651
  }
520
- const Ot = "_chatbot_root_1jllh_1", Pt = "_chatbot_root__fullScreen_1jllh_12", D = {
521
- chatbot_root: Ot,
522
- chatbot_root__fullScreen: Pt
652
+ function ae() {
653
+ const { sendMessage: e, isConnecting: t } = y(), [s, n] = N(""), [c, r] = N(!1), i = z(null), a = B(() => t || !s, [t, s]), u = d(
654
+ (b) => {
655
+ const l = b.target, h = l.value;
656
+ l.style.height = "20px", h && (l.style.height = `${l.scrollHeight - 16}px`), n(b.target.value);
657
+ },
658
+ []
659
+ ), p = d(() => {
660
+ !c && !t && (e == null || e(s), n(""), i.current && (i.current.style.height = "20px"));
661
+ }, [c, t, e, s]), m = d(
662
+ (b) => {
663
+ if (b.key === "Enter" && !c && !t) {
664
+ e == null || e(s), n("");
665
+ const l = b.target;
666
+ l.style.height = "20px";
667
+ }
668
+ },
669
+ [c, t, e, s]
670
+ );
671
+ return /* @__PURE__ */ o("div", { className: S.chatbot_footer, children: /* @__PURE__ */ _("div", { className: S.chatbot_footer__content, children: [
672
+ /* @__PURE__ */ o(
673
+ "textarea",
674
+ {
675
+ ref: i,
676
+ className: S.chatbot_textarea,
677
+ disabled: t,
678
+ cols: 40,
679
+ value: s,
680
+ placeholder: "Enter message",
681
+ onChange: u,
682
+ onKeyDown: m,
683
+ onCompositionStart: () => r(!0),
684
+ onCompositionEnd: () => r(!1)
685
+ }
686
+ ),
687
+ s ? /* @__PURE__ */ o(
688
+ "button",
689
+ {
690
+ className: T(
691
+ S.chatbot_submit_button,
692
+ a && S.chatbot_submit_button__disabled
693
+ ),
694
+ disabled: a,
695
+ onClick: p,
696
+ children: /* @__PURE__ */ o(se, {})
697
+ }
698
+ ) : /* @__PURE__ */ o(
699
+ ie,
700
+ {
701
+ setValue: n,
702
+ className: T(
703
+ S.chatbot_submit_button,
704
+ t && S.chatbot_submit_button__disabled
705
+ )
706
+ }
707
+ )
708
+ ] }) });
709
+ }
710
+ const le = "_chatbot_root_18brc_1", _e = "_chatbot_root__fullScreen_18brc_13", X = {
711
+ chatbot_root: le,
712
+ chatbot_root__fullScreen: _e
713
+ }, ue = "_loading_16ajc_1", de = "_spinner_16ajc_14", he = "_spinner_svg_16ajc_19", me = "_rotate_16ajc_1", be = "_spinner_circle_16ajc_25", ge = "_dash_16ajc_1", q = {
714
+ loading: ue,
715
+ spinner: de,
716
+ spinner_svg: he,
717
+ rotate: me,
718
+ spinner_circle: be,
719
+ dash: ge
523
720
  };
524
- function Qt(n) {
721
+ function pe() {
722
+ const { isResetting: e } = y();
723
+ return e ? /* @__PURE__ */ o("div", { className: q.loading, children: /* @__PURE__ */ o("div", { className: q.spinner, children: /* @__PURE__ */ o("svg", { className: q.spinner_svg, viewBox: "0 0 50 50", children: /* @__PURE__ */ o("circle", { className: q.spinner_circle, cx: "25", cy: "25", r: "20" }) }) }) }) : null;
724
+ }
725
+ function xe(e) {
525
726
  const {
526
727
  title: t,
527
- config: e,
528
- customChannelId: s,
728
+ config: s,
729
+ customChannelId: n,
529
730
  initMessages: c,
530
- fullScreen: a = !1,
531
- options: _
532
- } = n;
533
- return /* @__PURE__ */ r(
534
- Y,
731
+ fullScreen: r = !1,
732
+ avatar: i,
733
+ options: a,
734
+ botTypingPlaceholder: u
735
+ } = e;
736
+ return /* @__PURE__ */ _(
737
+ dt,
535
738
  {
536
- className: u(
537
- D.chatbot_root,
538
- a && D.chatbot_root__fullScreen
739
+ className: T(
740
+ X.chatbot_root,
741
+ r && X.chatbot_root__fullScreen
539
742
  ),
540
- config: e,
541
- customChannelId: s,
743
+ avatar: i,
744
+ config: s,
745
+ customChannelId: n,
542
746
  initMessages: c,
543
- options: _,
747
+ botTypingPlaceholder: u,
748
+ options: a,
544
749
  children: [
545
- /* @__PURE__ */ o(ct, { title: t }),
546
- /* @__PURE__ */ o(Zt, {}),
547
- /* @__PURE__ */ o(Et, {})
750
+ /* @__PURE__ */ o(pe, {}),
751
+ /* @__PURE__ */ o(vt, { title: t }),
752
+ /* @__PURE__ */ o(Gt, {}),
753
+ /* @__PURE__ */ o(ae, {})
548
754
  ]
549
755
  }
550
756
  );
551
757
  }
552
758
  export {
553
- Qt as Chatbot,
554
- X as useAsgardServiceClient,
555
- G as useChannel,
556
- J as useDebounce
759
+ xe as Chatbot,
760
+ lt as useAsgardServiceClient,
761
+ _t as useChannel,
762
+ ut as useDebounce
557
763
  };