@seyalhub/chat-widget 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -2
- package/dist/auto.d.ts +1 -0
- package/dist/element.cjs +380 -0
- package/dist/element.cjs.map +7 -0
- package/dist/element.d.ts +14 -0
- package/dist/element.js +357 -0
- package/dist/element.js.map +7 -0
- package/dist/index.cjs +329 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +306 -0
- package/dist/index.js.map +7 -0
- package/dist/react.cjs +343 -0
- package/dist/react.cjs.map +7 -0
- package/dist/react.d.ts +5 -0
- package/dist/react.js +322 -0
- package/dist/react.js.map +7 -0
- package/dist/seyalhub-chat.js +34 -0
- package/dist/seyalhub-chat.js.map +7 -0
- package/dist/styles.d.ts +2 -0
- package/dist/widget.d.ts +27 -0
- package/package.json +69 -4
package/dist/react.js
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// src/react.ts
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
|
|
4
|
+
// src/styles.ts
|
|
5
|
+
var CSS = `
|
|
6
|
+
:host { all: initial; }
|
|
7
|
+
* { box-sizing: border-box; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
|
|
8
|
+
.root { position: fixed; bottom: 20px; z-index: 2147483000; --c: #4f46e5; }
|
|
9
|
+
.root.right { right: 20px; } .root.left { left: 20px; }
|
|
10
|
+
.launcher { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--c); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 20px rgba(0,0,0,.25); position: relative; }
|
|
11
|
+
.launcher:focus-visible, button:focus-visible, textarea:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
|
|
12
|
+
.launcher svg { width: 26px; height: 26px; fill: currentColor; }
|
|
13
|
+
.dot { position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%; background: #ef4444; border: 2px solid #fff; display: none; }
|
|
14
|
+
.dot.on { display: block; }
|
|
15
|
+
.panel { position: absolute; bottom: 70px; width: min(380px, calc(100vw - 24px)); height: min(560px, calc(100vh - 110px)); background: #fff; border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.28); display: none; flex-direction: column; overflow: hidden; color: #0f172a; }
|
|
16
|
+
.right .panel { right: 0; } .left .panel { left: 0; }
|
|
17
|
+
.panel.open { display: flex; }
|
|
18
|
+
.head { background: var(--c); color: #fff; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; }
|
|
19
|
+
.head h2 { margin: 0; font-size: 16px; font-weight: 600; }
|
|
20
|
+
.head .sub { font-size: 12px; opacity: .85; }
|
|
21
|
+
.close { background: transparent; border: 0; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
|
|
22
|
+
.log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #f8fafc; }
|
|
23
|
+
.msg { max-width: 82%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
24
|
+
.msg.them { background: #fff; border: 1px solid #e2e8f0; align-self: flex-start; border-bottom-left-radius: 4px; }
|
|
25
|
+
.msg.me { background: var(--c); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
|
|
26
|
+
.msg.failed { opacity: .75; outline: 2px solid #ef4444; cursor: pointer; }
|
|
27
|
+
.note { align-self: center; font-size: 12px; color: #64748b; text-align: center; }
|
|
28
|
+
.typing { align-self: flex-start; color: #64748b; font-size: 13px; padding: 4px 8px; }
|
|
29
|
+
.error { background: #fef2f2; color: #991b1b; font-size: 13px; padding: 8px 12px; display: none; }
|
|
30
|
+
.error.on { display: block; }
|
|
31
|
+
form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #e2e8f0; background: #fff; }
|
|
32
|
+
textarea { flex: 1; resize: none; border: 1px solid #cbd5e1; border-radius: 10px; padding: 9px 10px; font-size: 14px; max-height: 96px; min-height: 40px; }
|
|
33
|
+
.send { border: 0; border-radius: 10px; background: var(--c); color: #fff; padding: 0 16px; font-size: 14px; font-weight: 600; cursor: pointer; }
|
|
34
|
+
.send:disabled { opacity: .5; cursor: default; }
|
|
35
|
+
.foot { text-align: center; font-size: 11px; color: #94a3b8; padding: 0 0 8px; background: #fff; }
|
|
36
|
+
@media (prefers-reduced-motion: no-preference) { .panel.open { animation: rise .15s ease-out; } @keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } } }
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
// src/widget.ts
|
|
40
|
+
var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
41
|
+
var COLOR = /^#[0-9a-fA-F]{6}$/;
|
|
42
|
+
var BACKGROUND_POLL_MS = 1e4;
|
|
43
|
+
var MAX_BACKOFF_MS = 15e3;
|
|
44
|
+
var TYPING_TIMEOUT_MS = 6e4;
|
|
45
|
+
function randomId(length) {
|
|
46
|
+
var _a, _b, _c;
|
|
47
|
+
const bytes = new Uint8Array(length);
|
|
48
|
+
(_c = (_b = (_a = globalThis.crypto) != null ? _a : {}).getRandomValues) == null ? void 0 : _c.call(_b, bytes);
|
|
49
|
+
if (!bytes.some((b) => b !== 0)) for (let i = 0; i < length; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
50
|
+
return Array.from(bytes, (b) => ALPHABET[b % ALPHABET.length]).join("");
|
|
51
|
+
}
|
|
52
|
+
function safeStorage(custom) {
|
|
53
|
+
const memory = /* @__PURE__ */ new Map();
|
|
54
|
+
const fallback = { getItem: (k) => {
|
|
55
|
+
var _a;
|
|
56
|
+
return (_a = memory.get(k)) != null ? _a : null;
|
|
57
|
+
}, setItem: (k, v) => void memory.set(k, v) };
|
|
58
|
+
try {
|
|
59
|
+
const s = custom != null ? custom : window.localStorage;
|
|
60
|
+
s.setItem("seyalhub:probe", "1");
|
|
61
|
+
return s;
|
|
62
|
+
} catch {
|
|
63
|
+
return fallback;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function el(tag, className, text) {
|
|
67
|
+
const node = document.createElement(tag);
|
|
68
|
+
if (className) node.className = className;
|
|
69
|
+
if (text !== void 0) node.textContent = text;
|
|
70
|
+
return node;
|
|
71
|
+
}
|
|
72
|
+
function createChatWidget(options) {
|
|
73
|
+
var _a, _b, _c;
|
|
74
|
+
const doFetch = (_a = options.fetch) != null ? _a : ((...args) => fetch(...args));
|
|
75
|
+
const base = `${options.apiUrl.replace(/\/+$/, "")}/api/v1/public/webchat/${encodeURIComponent(options.siteKey)}`;
|
|
76
|
+
const storage = safeStorage(options.storage);
|
|
77
|
+
const keyVisitor = `seyalhub:visitor:${options.siteKey}`;
|
|
78
|
+
const keyStarted = `seyalhub:started:${options.siteKey}`;
|
|
79
|
+
let visitor = (_b = storage.getItem(keyVisitor)) != null ? _b : "";
|
|
80
|
+
if (!/^[A-Za-z0-9_-]{32,64}$/.test(visitor)) {
|
|
81
|
+
visitor = randomId(40);
|
|
82
|
+
storage.setItem(keyVisitor, visitor);
|
|
83
|
+
}
|
|
84
|
+
let destroyed = false;
|
|
85
|
+
let isOpen = false;
|
|
86
|
+
let loadedHistory = false;
|
|
87
|
+
let lastId = "";
|
|
88
|
+
let backoff = 0;
|
|
89
|
+
let timer;
|
|
90
|
+
let typingTimer;
|
|
91
|
+
const rendered = /* @__PURE__ */ new Map();
|
|
92
|
+
const pendingBubbles = /* @__PURE__ */ new Map();
|
|
93
|
+
const host = el("div");
|
|
94
|
+
host.setAttribute("data-seyalhub-chat", "");
|
|
95
|
+
const shadow = host.attachShadow({ mode: "open" });
|
|
96
|
+
const style = el("style");
|
|
97
|
+
style.textContent = CSS;
|
|
98
|
+
const root = el("div", `root ${options.position === "left" ? "left" : "right"}`);
|
|
99
|
+
const panel = el("section", "panel");
|
|
100
|
+
panel.setAttribute("role", "dialog");
|
|
101
|
+
panel.setAttribute("aria-label", "Chat");
|
|
102
|
+
const head = el("div", "head");
|
|
103
|
+
const headText = el("div");
|
|
104
|
+
const titleEl = el("h2", void 0, (_c = options.title) != null ? _c : "Chat with us");
|
|
105
|
+
const subEl = el("div", "sub");
|
|
106
|
+
headText.append(titleEl, subEl);
|
|
107
|
+
const closeBtn = el("button", "close", "\xD7");
|
|
108
|
+
closeBtn.type = "button";
|
|
109
|
+
closeBtn.setAttribute("aria-label", "Close chat");
|
|
110
|
+
head.append(headText, closeBtn);
|
|
111
|
+
const log = el("div", "log");
|
|
112
|
+
log.setAttribute("role", "log");
|
|
113
|
+
log.setAttribute("aria-live", "polite");
|
|
114
|
+
const typing = el("div", "typing", "Typing\u2026");
|
|
115
|
+
const errorBar = el("div", "error");
|
|
116
|
+
errorBar.setAttribute("role", "alert");
|
|
117
|
+
const form = el("form");
|
|
118
|
+
const input = el("textarea");
|
|
119
|
+
input.rows = 1;
|
|
120
|
+
input.maxLength = 1e3;
|
|
121
|
+
input.placeholder = "Type your message";
|
|
122
|
+
input.setAttribute("aria-label", "Your message");
|
|
123
|
+
const sendBtn = el("button", "send", "Send");
|
|
124
|
+
sendBtn.type = "submit";
|
|
125
|
+
form.append(input, sendBtn);
|
|
126
|
+
const foot = el("div", "foot", "Powered by SeyalHub");
|
|
127
|
+
panel.append(head, log, errorBar, form, foot);
|
|
128
|
+
const launcher = el("button", "launcher");
|
|
129
|
+
launcher.type = "button";
|
|
130
|
+
launcher.setAttribute("aria-label", "Open chat");
|
|
131
|
+
launcher.setAttribute("aria-expanded", "false");
|
|
132
|
+
launcher.innerHTML = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 4h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-5 4v-4H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z"/></svg>';
|
|
133
|
+
const dot = el("span", "dot");
|
|
134
|
+
launcher.append(dot);
|
|
135
|
+
root.append(panel, launcher);
|
|
136
|
+
shadow.append(style, root);
|
|
137
|
+
function applyColor(color) {
|
|
138
|
+
if (color && COLOR.test(color)) root.style.setProperty("--c", color);
|
|
139
|
+
}
|
|
140
|
+
applyColor(options.color);
|
|
141
|
+
const scrollDown = () => {
|
|
142
|
+
log.scrollTop = log.scrollHeight;
|
|
143
|
+
};
|
|
144
|
+
function showError(message) {
|
|
145
|
+
errorBar.textContent = message != null ? message : "";
|
|
146
|
+
errorBar.classList.toggle("on", Boolean(message));
|
|
147
|
+
}
|
|
148
|
+
function setTyping(on) {
|
|
149
|
+
if (typingTimer) clearTimeout(typingTimer);
|
|
150
|
+
if (on) {
|
|
151
|
+
log.append(typing);
|
|
152
|
+
scrollDown();
|
|
153
|
+
typingTimer = setTimeout(() => typing.remove(), TYPING_TIMEOUT_MS);
|
|
154
|
+
} else typing.remove();
|
|
155
|
+
}
|
|
156
|
+
function bubble(text, kind) {
|
|
157
|
+
const b = el("div", kind === "note" ? "note" : `msg ${kind}`, text);
|
|
158
|
+
typing.remove();
|
|
159
|
+
log.append(b);
|
|
160
|
+
scrollDown();
|
|
161
|
+
return b;
|
|
162
|
+
}
|
|
163
|
+
function addServerLine(line) {
|
|
164
|
+
if (rendered.has(line.id)) return;
|
|
165
|
+
lastId = line.id > lastId ? line.id : lastId;
|
|
166
|
+
if (line.direction === "inbound") {
|
|
167
|
+
const mine = line.client_id ? pendingBubbles.get(line.client_id) : void 0;
|
|
168
|
+
if (mine) {
|
|
169
|
+
rendered.set(line.id, mine);
|
|
170
|
+
pendingBubbles.delete(line.client_id);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
rendered.set(line.id, bubble(line.text, "me"));
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
rendered.set(line.id, bubble(line.text, "them"));
|
|
177
|
+
setTyping(false);
|
|
178
|
+
if (!isOpen) dot.classList.add("on");
|
|
179
|
+
}
|
|
180
|
+
async function api(path, init) {
|
|
181
|
+
var _a2;
|
|
182
|
+
return doFetch(`${base}${path}`, { ...init, headers: { "content-type": "application/json", ...(_a2 = init == null ? void 0 : init.headers) != null ? _a2 : {} } });
|
|
183
|
+
}
|
|
184
|
+
async function poll() {
|
|
185
|
+
var _a2;
|
|
186
|
+
if (destroyed) return;
|
|
187
|
+
let delay = isOpen ? (_a2 = options.pollMs) != null ? _a2 : 2e3 : BACKGROUND_POLL_MS;
|
|
188
|
+
try {
|
|
189
|
+
const qs = new URLSearchParams({ visitor_id: visitor });
|
|
190
|
+
if (lastId) qs.set("after", lastId);
|
|
191
|
+
const res = await api(`/messages?${qs}`);
|
|
192
|
+
if (res.ok) {
|
|
193
|
+
const body = await res.json();
|
|
194
|
+
body.messages.forEach(addServerLine);
|
|
195
|
+
subEl.textContent = body.human ? "You are chatting with our team" : "";
|
|
196
|
+
backoff = 0;
|
|
197
|
+
showError(null);
|
|
198
|
+
} else if (res.status === 403 || res.status === 404) {
|
|
199
|
+
return void destroy();
|
|
200
|
+
} else throw new Error(String(res.status));
|
|
201
|
+
} catch {
|
|
202
|
+
backoff = Math.min(MAX_BACKOFF_MS, (backoff || 1e3) * 2);
|
|
203
|
+
delay = Math.max(delay, backoff);
|
|
204
|
+
}
|
|
205
|
+
if (!destroyed && (isOpen || storage.getItem(keyStarted))) timer = setTimeout(() => void poll(), delay);
|
|
206
|
+
}
|
|
207
|
+
function restartPolling() {
|
|
208
|
+
if (timer) clearTimeout(timer);
|
|
209
|
+
void poll();
|
|
210
|
+
}
|
|
211
|
+
async function loadHistory() {
|
|
212
|
+
var _a2;
|
|
213
|
+
if (loadedHistory) return;
|
|
214
|
+
loadedHistory = true;
|
|
215
|
+
await poll();
|
|
216
|
+
if (rendered.size === 0) bubble((_a2 = options.greeting) != null ? _a2 : greeting, "them");
|
|
217
|
+
}
|
|
218
|
+
let greeting = "Hi! How can we help?";
|
|
219
|
+
async function send(text, clientId, node) {
|
|
220
|
+
node.classList.remove("failed");
|
|
221
|
+
try {
|
|
222
|
+
const res = await api("/messages", { method: "POST", body: JSON.stringify({ visitor_id: visitor, text, client_message_id: clientId }) });
|
|
223
|
+
if (res.status === 429) throw new Error("You are sending messages too fast. Please wait a moment.");
|
|
224
|
+
if (!res.ok) throw new Error(res.status === 503 ? "Chat is not available right now. Please try again shortly." : "Your message could not be sent. Tap it to try again.");
|
|
225
|
+
storage.setItem(keyStarted, "1");
|
|
226
|
+
showError(null);
|
|
227
|
+
setTyping(true);
|
|
228
|
+
restartPolling();
|
|
229
|
+
} catch (err) {
|
|
230
|
+
node.classList.add("failed");
|
|
231
|
+
node.onclick = () => void send(text, clientId, node);
|
|
232
|
+
showError(err instanceof Error && err.message ? err.message : "Your message could not be sent. Tap it to try again.");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
form.addEventListener("submit", (e) => {
|
|
236
|
+
e.preventDefault();
|
|
237
|
+
const text = input.value.trim();
|
|
238
|
+
if (!text) return;
|
|
239
|
+
input.value = "";
|
|
240
|
+
const clientId = `cm_${randomId(16)}`;
|
|
241
|
+
const node = bubble(text, "me");
|
|
242
|
+
pendingBubbles.set(clientId, node);
|
|
243
|
+
void send(text, clientId, node);
|
|
244
|
+
});
|
|
245
|
+
input.addEventListener("keydown", (e) => {
|
|
246
|
+
if (e.key === "Enter" && !e.shiftKey && !e.isComposing) {
|
|
247
|
+
e.preventDefault();
|
|
248
|
+
form.requestSubmit();
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
panel.addEventListener("keydown", (e) => {
|
|
252
|
+
if (e.key === "Escape") close();
|
|
253
|
+
});
|
|
254
|
+
function open() {
|
|
255
|
+
if (destroyed || isOpen) return;
|
|
256
|
+
isOpen = true;
|
|
257
|
+
panel.classList.add("open");
|
|
258
|
+
launcher.setAttribute("aria-expanded", "true");
|
|
259
|
+
launcher.setAttribute("aria-label", "Close chat");
|
|
260
|
+
dot.classList.remove("on");
|
|
261
|
+
void loadHistory().then(() => {
|
|
262
|
+
if (isOpen) restartPolling();
|
|
263
|
+
});
|
|
264
|
+
input.focus();
|
|
265
|
+
}
|
|
266
|
+
function close() {
|
|
267
|
+
if (!isOpen) return;
|
|
268
|
+
isOpen = false;
|
|
269
|
+
panel.classList.remove("open");
|
|
270
|
+
launcher.setAttribute("aria-expanded", "false");
|
|
271
|
+
launcher.setAttribute("aria-label", "Open chat");
|
|
272
|
+
launcher.focus();
|
|
273
|
+
}
|
|
274
|
+
function toggle() {
|
|
275
|
+
isOpen ? close() : open();
|
|
276
|
+
}
|
|
277
|
+
function destroy() {
|
|
278
|
+
destroyed = true;
|
|
279
|
+
if (timer) clearTimeout(timer);
|
|
280
|
+
if (typingTimer) clearTimeout(typingTimer);
|
|
281
|
+
host.remove();
|
|
282
|
+
}
|
|
283
|
+
launcher.addEventListener("click", toggle);
|
|
284
|
+
closeBtn.addEventListener("click", close);
|
|
285
|
+
void (async () => {
|
|
286
|
+
var _a2, _b2, _c2, _d;
|
|
287
|
+
try {
|
|
288
|
+
const res = await api("/config");
|
|
289
|
+
if (!res.ok) {
|
|
290
|
+
if (typeof console !== "undefined") console.warn(`[SeyalHub chat] not shown (${res.status}): check the site key and that this website is listed in the portal.`);
|
|
291
|
+
return void destroy();
|
|
292
|
+
}
|
|
293
|
+
const cfg = await res.json();
|
|
294
|
+
titleEl.textContent = (_a2 = options.title) != null ? _a2 : cfg.title;
|
|
295
|
+
greeting = (_b2 = options.greeting) != null ? _b2 : cfg.greeting;
|
|
296
|
+
applyColor((_c2 = options.color) != null ? _c2 : cfg.color);
|
|
297
|
+
} catch {
|
|
298
|
+
}
|
|
299
|
+
if (destroyed) return;
|
|
300
|
+
((_d = options.container) != null ? _d : document.body).append(host);
|
|
301
|
+
if (storage.getItem(keyStarted)) void poll();
|
|
302
|
+
if (options.open) open();
|
|
303
|
+
})();
|
|
304
|
+
return { open, close, toggle, destroy };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// src/react.ts
|
|
308
|
+
function SeyalHubChat(props) {
|
|
309
|
+
const { siteKey, apiUrl, title, greeting, color, position, open, pollMs } = props;
|
|
310
|
+
useEffect(() => {
|
|
311
|
+
if (!siteKey || !apiUrl) return;
|
|
312
|
+
const widget = createChatWidget({ siteKey, apiUrl, title, greeting, color, position, open, pollMs });
|
|
313
|
+
return () => widget.destroy();
|
|
314
|
+
}, [siteKey, apiUrl, title, greeting, color, position, open, pollMs]);
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
var react_default = SeyalHubChat;
|
|
318
|
+
export {
|
|
319
|
+
SeyalHubChat,
|
|
320
|
+
react_default as default
|
|
321
|
+
};
|
|
322
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/react.ts", "../src/styles.ts", "../src/widget.ts"],
|
|
4
|
+
"sourcesContent": ["import { useEffect } from \"react\";\nimport { createChatWidget, type ChatOptions } from \"./widget\";\n\nexport type SeyalHubChatProps = Omit<ChatOptions, \"container\" | \"fetch\" | \"storage\">;\n\n/** `<SeyalHubChat siteKey=\"wc_...\" apiUrl=\"https://api.example.com\" />`. Renders nothing itself: the widget attaches to the page. Safe in strict mode and server rendering. */\nexport function SeyalHubChat(props: SeyalHubChatProps): null {\n const { siteKey, apiUrl, title, greeting, color, position, open, pollMs } = props;\n useEffect(() => {\n if (!siteKey || !apiUrl) return;\n const widget = createChatWidget({ siteKey, apiUrl, title, greeting, color, position, open, pollMs });\n return () => widget.destroy();\n }, [siteKey, apiUrl, title, greeting, color, position, open, pollMs]);\n return null;\n}\n\nexport default SeyalHubChat;\n", "/** All styles live inside the widget's shadow root, so the host page's CSS cannot break the widget and the widget's CSS cannot touch the page. */\nexport const CSS = `\n:host { all: initial; }\n* { box-sizing: border-box; font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; }\n.root { position: fixed; bottom: 20px; z-index: 2147483000; --c: #4f46e5; }\n.root.right { right: 20px; } .root.left { left: 20px; }\n.launcher { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--c); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 20px rgba(0,0,0,.25); position: relative; }\n.launcher:focus-visible, button:focus-visible, textarea:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }\n.launcher svg { width: 26px; height: 26px; fill: currentColor; }\n.dot { position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%; background: #ef4444; border: 2px solid #fff; display: none; }\n.dot.on { display: block; }\n.panel { position: absolute; bottom: 70px; width: min(380px, calc(100vw - 24px)); height: min(560px, calc(100vh - 110px)); background: #fff; border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.28); display: none; flex-direction: column; overflow: hidden; color: #0f172a; }\n.right .panel { right: 0; } .left .panel { left: 0; }\n.panel.open { display: flex; }\n.head { background: var(--c); color: #fff; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; }\n.head h2 { margin: 0; font-size: 16px; font-weight: 600; }\n.head .sub { font-size: 12px; opacity: .85; }\n.close { background: transparent; border: 0; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }\n.log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #f8fafc; }\n.msg { max-width: 82%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }\n.msg.them { background: #fff; border: 1px solid #e2e8f0; align-self: flex-start; border-bottom-left-radius: 4px; }\n.msg.me { background: var(--c); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }\n.msg.failed { opacity: .75; outline: 2px solid #ef4444; cursor: pointer; }\n.note { align-self: center; font-size: 12px; color: #64748b; text-align: center; }\n.typing { align-self: flex-start; color: #64748b; font-size: 13px; padding: 4px 8px; }\n.error { background: #fef2f2; color: #991b1b; font-size: 13px; padding: 8px 12px; display: none; }\n.error.on { display: block; }\nform { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #e2e8f0; background: #fff; }\ntextarea { flex: 1; resize: none; border: 1px solid #cbd5e1; border-radius: 10px; padding: 9px 10px; font-size: 14px; max-height: 96px; min-height: 40px; }\n.send { border: 0; border-radius: 10px; background: var(--c); color: #fff; padding: 0 16px; font-size: 14px; font-weight: 600; cursor: pointer; }\n.send:disabled { opacity: .5; cursor: default; }\n.foot { text-align: center; font-size: 11px; color: #94a3b8; padding: 0 0 8px; background: #fff; }\n@media (prefers-reduced-motion: no-preference) { .panel.open { animation: rise .15s ease-out; } @keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } } }\n`;\n", "import { CSS } from \"./styles\";\n\nexport interface ChatOptions {\n /** The site key from the portal (Settings, Channels). Starts with `wc_`. */\n siteKey: string;\n /** Where the SeyalHub API lives, for example `https://api.example.com`. No path. */\n apiUrl: string;\n /** Override the title, greeting or colour set in the portal. */\n title?: string;\n greeting?: string;\n color?: string;\n position?: \"right\" | \"left\";\n /** Open the chat as soon as it is ready. */\n open?: boolean;\n /** Where to attach the widget. Default: document.body. */\n container?: HTMLElement;\n /** How often to look for new messages while the chat is open. Default 2000 ms. */\n pollMs?: number;\n /** Test hooks. */\n fetch?: typeof fetch;\n storage?: Pick<Storage, \"getItem\" | \"setItem\">;\n}\n\nexport interface ChatWidget {\n open(): void;\n close(): void;\n toggle(): void;\n destroy(): void;\n}\n\ninterface Line {\n id: string;\n direction: \"inbound\" | \"outbound\";\n text: string;\n sent_by?: string | null;\n client_id?: string | null;\n}\n\nconst ALPHABET = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\nconst COLOR = /^#[0-9a-fA-F]{6}$/;\nconst BACKGROUND_POLL_MS = 10_000;\nconst MAX_BACKOFF_MS = 15_000;\nconst TYPING_TIMEOUT_MS = 60_000;\n\nfunction randomId(length: number): string {\n const bytes = new Uint8Array(length);\n (globalThis.crypto ?? ({} as Crypto)).getRandomValues?.(bytes);\n if (!bytes.some((b) => b !== 0)) for (let i = 0; i < length; i++) bytes[i] = Math.floor(Math.random() * 256); // very old browsers: fall back\n return Array.from(bytes, (b) => ALPHABET[b % ALPHABET.length]).join(\"\");\n}\n\nfunction safeStorage(custom?: ChatOptions[\"storage\"]): Pick<Storage, \"getItem\" | \"setItem\"> {\n const memory = new Map<string, string>();\n const fallback = { getItem: (k: string) => memory.get(k) ?? null, setItem: (k: string, v: string) => void memory.set(k, v) };\n try {\n const s = custom ?? window.localStorage;\n s.setItem(\"seyalhub:probe\", \"1\");\n return s;\n } catch {\n return fallback; // private mode or storage blocked: the chat still works, it just does not survive a reload\n }\n}\n\nfunction el<K extends keyof HTMLElementTagNameMap>(tag: K, className?: string, text?: string): HTMLElementTagNameMap[K] {\n const node = document.createElement(tag);\n if (className) node.className = className;\n if (text !== undefined) node.textContent = text; // always textContent: a message can never inject markup\n return node;\n}\n\nexport function createChatWidget(options: ChatOptions): ChatWidget {\n const doFetch = options.fetch ?? ((...args: Parameters<typeof fetch>) => fetch(...args));\n const base = `${options.apiUrl.replace(/\\/+$/, \"\")}/api/v1/public/webchat/${encodeURIComponent(options.siteKey)}`;\n const storage = safeStorage(options.storage);\n const keyVisitor = `seyalhub:visitor:${options.siteKey}`;\n const keyStarted = `seyalhub:started:${options.siteKey}`;\n let visitor = storage.getItem(keyVisitor) ?? \"\";\n if (!/^[A-Za-z0-9_-]{32,64}$/.test(visitor)) {\n visitor = randomId(40); // long and random: it is the only thing that lets this browser read this conversation\n storage.setItem(keyVisitor, visitor);\n }\n\n let destroyed = false;\n let isOpen = false;\n let loadedHistory = false;\n let lastId = \"\";\n let backoff = 0;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let typingTimer: ReturnType<typeof setTimeout> | undefined;\n const rendered = new Map<string, HTMLElement>(); // server id or client id -> bubble\n const pendingBubbles = new Map<string, HTMLElement>(); // client id -> bubble waiting for the server's copy\n\n // --- DOM -----------------------------------------------------------------------------------------------------\n const host = el(\"div\");\n host.setAttribute(\"data-seyalhub-chat\", \"\");\n const shadow = host.attachShadow({ mode: \"open\" });\n const style = el(\"style\");\n style.textContent = CSS;\n const root = el(\"div\", `root ${options.position === \"left\" ? \"left\" : \"right\"}`);\n const panel = el(\"section\", \"panel\");\n panel.setAttribute(\"role\", \"dialog\");\n panel.setAttribute(\"aria-label\", \"Chat\");\n const head = el(\"div\", \"head\");\n const headText = el(\"div\");\n const titleEl = el(\"h2\", undefined, options.title ?? \"Chat with us\");\n const subEl = el(\"div\", \"sub\");\n headText.append(titleEl, subEl);\n const closeBtn = el(\"button\", \"close\", \"\u00D7\");\n closeBtn.type = \"button\";\n closeBtn.setAttribute(\"aria-label\", \"Close chat\");\n head.append(headText, closeBtn);\n const log = el(\"div\", \"log\");\n log.setAttribute(\"role\", \"log\");\n log.setAttribute(\"aria-live\", \"polite\");\n const typing = el(\"div\", \"typing\", \"Typing\u2026\");\n const errorBar = el(\"div\", \"error\");\n errorBar.setAttribute(\"role\", \"alert\");\n const form = el(\"form\");\n const input = el(\"textarea\");\n input.rows = 1;\n input.maxLength = 1000;\n input.placeholder = \"Type your message\";\n input.setAttribute(\"aria-label\", \"Your message\");\n const sendBtn = el(\"button\", \"send\", \"Send\");\n sendBtn.type = \"submit\";\n form.append(input, sendBtn);\n const foot = el(\"div\", \"foot\", \"Powered by SeyalHub\");\n panel.append(head, log, errorBar, form, foot);\n const launcher = el(\"button\", \"launcher\");\n launcher.type = \"button\";\n launcher.setAttribute(\"aria-label\", \"Open chat\");\n launcher.setAttribute(\"aria-expanded\", \"false\");\n launcher.innerHTML = '<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M4 4h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-5 4v-4H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z\"/></svg>'; // static markup, no user data\n const dot = el(\"span\", \"dot\");\n launcher.append(dot);\n root.append(panel, launcher);\n shadow.append(style, root);\n\n function applyColor(color?: string) {\n if (color && COLOR.test(color)) root.style.setProperty(\"--c\", color);\n }\n applyColor(options.color);\n\n // --- helpers ---------------------------------------------------------------------------------------------------\n const scrollDown = () => { log.scrollTop = log.scrollHeight; };\n function showError(message: string | null) {\n errorBar.textContent = message ?? \"\";\n errorBar.classList.toggle(\"on\", Boolean(message));\n }\n function setTyping(on: boolean) {\n if (typingTimer) clearTimeout(typingTimer);\n if (on) {\n log.append(typing);\n scrollDown();\n typingTimer = setTimeout(() => typing.remove(), TYPING_TIMEOUT_MS);\n } else typing.remove();\n }\n function bubble(text: string, kind: \"me\" | \"them\" | \"note\"): HTMLElement {\n const b = el(\"div\", kind === \"note\" ? \"note\" : `msg ${kind}`, text);\n typing.remove();\n log.append(b);\n scrollDown();\n return b;\n }\n\n function addServerLine(line: Line) {\n if (rendered.has(line.id)) return;\n lastId = line.id > lastId ? line.id : lastId;\n if (line.direction === \"inbound\") {\n const mine = line.client_id ? pendingBubbles.get(line.client_id) : undefined;\n if (mine) { // the server's copy of a message this page sent: keep the bubble, remember its id\n rendered.set(line.id, mine);\n pendingBubbles.delete(line.client_id!);\n return;\n }\n rendered.set(line.id, bubble(line.text, \"me\"));\n return;\n }\n rendered.set(line.id, bubble(line.text, \"them\"));\n setTyping(false);\n if (!isOpen) dot.classList.add(\"on\");\n }\n\n // --- talking to the API ----------------------------------------------------------------------------------------\n async function api(path: string, init?: RequestInit): Promise<Response> {\n return doFetch(`${base}${path}`, { ...init, headers: { \"content-type\": \"application/json\", ...(init?.headers ?? {}) } });\n }\n\n async function poll(): Promise<void> {\n if (destroyed) return;\n let delay = isOpen ? options.pollMs ?? 2000 : BACKGROUND_POLL_MS;\n try {\n const qs = new URLSearchParams({ visitor_id: visitor });\n if (lastId) qs.set(\"after\", lastId);\n const res = await api(`/messages?${qs}`);\n if (res.ok) {\n const body = (await res.json()) as { messages: Line[]; human?: boolean };\n body.messages.forEach(addServerLine);\n subEl.textContent = body.human ? \"You are chatting with our team\" : \"\";\n backoff = 0;\n showError(null);\n } else if (res.status === 403 || res.status === 404) {\n return void destroy(); // not allowed here (website not listed) or the chat was switched off: stop quietly\n } else throw new Error(String(res.status));\n } catch {\n backoff = Math.min(MAX_BACKOFF_MS, (backoff || 1000) * 2);\n delay = Math.max(delay, backoff);\n }\n if (!destroyed && (isOpen || storage.getItem(keyStarted))) timer = setTimeout(() => void poll(), delay);\n }\n\n function restartPolling() {\n if (timer) clearTimeout(timer);\n void poll();\n }\n\n async function loadHistory(): Promise<void> {\n if (loadedHistory) return;\n loadedHistory = true;\n await poll();\n if (rendered.size === 0) bubble(options.greeting ?? greeting, \"them\"); // the greeting is only a first line, not stored as a message\n }\n let greeting = \"Hi! How can we help?\";\n\n async function send(text: string, clientId: string, node: HTMLElement): Promise<void> {\n node.classList.remove(\"failed\");\n try {\n const res = await api(\"/messages\", { method: \"POST\", body: JSON.stringify({ visitor_id: visitor, text, client_message_id: clientId }) });\n if (res.status === 429) throw new Error(\"You are sending messages too fast. Please wait a moment.\");\n if (!res.ok) throw new Error(res.status === 503 ? \"Chat is not available right now. Please try again shortly.\" : \"Your message could not be sent. Tap it to try again.\");\n storage.setItem(keyStarted, \"1\");\n showError(null);\n setTyping(true);\n restartPolling();\n } catch (err) {\n node.classList.add(\"failed\");\n node.onclick = () => void send(text, clientId, node);\n showError(err instanceof Error && err.message ? err.message : \"Your message could not be sent. Tap it to try again.\");\n }\n }\n\n form.addEventListener(\"submit\", (e) => {\n e.preventDefault();\n const text = input.value.trim();\n if (!text) return;\n input.value = \"\";\n const clientId = `cm_${randomId(16)}`;\n const node = bubble(text, \"me\");\n pendingBubbles.set(clientId, node);\n void send(text, clientId, node);\n });\n input.addEventListener(\"keydown\", (e) => {\n if (e.key === \"Enter\" && !e.shiftKey && !e.isComposing) {\n e.preventDefault();\n form.requestSubmit();\n }\n });\n panel.addEventListener(\"keydown\", (e) => { if (e.key === \"Escape\") close(); });\n\n // --- open / close ----------------------------------------------------------------------------------------------\n function open() {\n if (destroyed || isOpen) return;\n isOpen = true;\n panel.classList.add(\"open\");\n launcher.setAttribute(\"aria-expanded\", \"true\");\n launcher.setAttribute(\"aria-label\", \"Close chat\");\n dot.classList.remove(\"on\");\n void loadHistory().then(() => { if (isOpen) restartPolling(); });\n input.focus();\n }\n function close() {\n if (!isOpen) return;\n isOpen = false;\n panel.classList.remove(\"open\");\n launcher.setAttribute(\"aria-expanded\", \"false\");\n launcher.setAttribute(\"aria-label\", \"Open chat\");\n launcher.focus();\n }\n function toggle() { isOpen ? close() : open(); }\n function destroy() {\n destroyed = true;\n if (timer) clearTimeout(timer);\n if (typingTimer) clearTimeout(typingTimer);\n host.remove();\n }\n launcher.addEventListener(\"click\", toggle);\n closeBtn.addEventListener(\"click\", close);\n\n // --- start: fetch the portal's settings, then show the launcher --------------------------------------------------\n void (async () => {\n try {\n const res = await api(\"/config\");\n if (!res.ok) {\n if (typeof console !== \"undefined\") console.warn(`[SeyalHub chat] not shown (${res.status}): check the site key and that this website is listed in the portal.`);\n return void destroy();\n }\n const cfg = (await res.json()) as { title: string; greeting: string; color: string };\n titleEl.textContent = options.title ?? cfg.title;\n greeting = options.greeting ?? cfg.greeting;\n applyColor(options.color ?? cfg.color);\n } catch {\n // the settings are optional: show the chat with defaults, and let sending report any real problem\n }\n if (destroyed) return;\n (options.container ?? document.body).append(host);\n if (storage.getItem(keyStarted)) void poll(); // a returning visitor: look for replies while closed, to show the unread dot\n if (options.open) open();\n })();\n\n return { open, close, toggle, destroy };\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iBAAiB;;;ACCnB,IAAM,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACqCnB,IAAM,WAAW;AACjB,IAAM,QAAQ;AACd,IAAM,qBAAqB;AAC3B,IAAM,iBAAiB;A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names": ["_a", "_b", "_c"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";(()=>{var de=`
|
|
2
|
+
:host { all: initial; }
|
|
3
|
+
* { box-sizing: border-box; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
|
|
4
|
+
.root { position: fixed; bottom: 20px; z-index: 2147483000; --c: #4f46e5; }
|
|
5
|
+
.root.right { right: 20px; } .root.left { left: 20px; }
|
|
6
|
+
.launcher { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--c); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 20px rgba(0,0,0,.25); position: relative; }
|
|
7
|
+
.launcher:focus-visible, button:focus-visible, textarea:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
|
|
8
|
+
.launcher svg { width: 26px; height: 26px; fill: currentColor; }
|
|
9
|
+
.dot { position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%; background: #ef4444; border: 2px solid #fff; display: none; }
|
|
10
|
+
.dot.on { display: block; }
|
|
11
|
+
.panel { position: absolute; bottom: 70px; width: min(380px, calc(100vw - 24px)); height: min(560px, calc(100vh - 110px)); background: #fff; border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.28); display: none; flex-direction: column; overflow: hidden; color: #0f172a; }
|
|
12
|
+
.right .panel { right: 0; } .left .panel { left: 0; }
|
|
13
|
+
.panel.open { display: flex; }
|
|
14
|
+
.head { background: var(--c); color: #fff; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; }
|
|
15
|
+
.head h2 { margin: 0; font-size: 16px; font-weight: 600; }
|
|
16
|
+
.head .sub { font-size: 12px; opacity: .85; }
|
|
17
|
+
.close { background: transparent; border: 0; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
|
|
18
|
+
.log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #f8fafc; }
|
|
19
|
+
.msg { max-width: 82%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
20
|
+
.msg.them { background: #fff; border: 1px solid #e2e8f0; align-self: flex-start; border-bottom-left-radius: 4px; }
|
|
21
|
+
.msg.me { background: var(--c); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
|
|
22
|
+
.msg.failed { opacity: .75; outline: 2px solid #ef4444; cursor: pointer; }
|
|
23
|
+
.note { align-self: center; font-size: 12px; color: #64748b; text-align: center; }
|
|
24
|
+
.typing { align-self: flex-start; color: #64748b; font-size: 13px; padding: 4px 8px; }
|
|
25
|
+
.error { background: #fef2f2; color: #991b1b; font-size: 13px; padding: 8px 12px; display: none; }
|
|
26
|
+
.error.on { display: block; }
|
|
27
|
+
form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #e2e8f0; background: #fff; }
|
|
28
|
+
textarea { flex: 1; resize: none; border: 1px solid #cbd5e1; border-radius: 10px; padding: 9px 10px; font-size: 14px; max-height: 96px; min-height: 40px; }
|
|
29
|
+
.send { border: 0; border-radius: 10px; background: var(--c); color: #fff; padding: 0 16px; font-size: 14px; font-weight: 600; cursor: pointer; }
|
|
30
|
+
.send:disabled { opacity: .5; cursor: default; }
|
|
31
|
+
.foot { text-align: center; font-size: 11px; color: #94a3b8; padding: 0 0 8px; background: #fff; }
|
|
32
|
+
@media (prefers-reduced-motion: no-preference) { .panel.open { animation: rise .15s ease-out; } @keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } } }
|
|
33
|
+
`;var le="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",ye=/^#[0-9a-fA-F]{6}$/,xe=1e4,ve=15e3,we=6e4;function ce(t){var p,n,c;let o=new Uint8Array(t);if((c=(n=(p=globalThis.crypto)!=null?p:{}).getRandomValues)==null||c.call(n,o),!o.some(l=>l!==0))for(let l=0;l<t;l++)o[l]=Math.floor(Math.random()*256);return Array.from(o,l=>le[l%le.length]).join("")}function Ce(t){let o=new Map,p={getItem:n=>{var c;return(c=o.get(n))!=null?c:null},setItem:(n,c)=>void o.set(n,c)};try{let n=t!=null?t:window.localStorage;return n.setItem("seyalhub:probe","1"),n}catch{return p}}function a(t,o,p){let n=document.createElement(t);return o&&(n.className=o),p!==void 0&&(n.textContent=p),n}function P(t){var re,se,ae;let o=(re=t.fetch)!=null?re:((...e)=>fetch(...e)),p=`${t.apiUrl.replace(/\/+$/,"")}/api/v1/public/webchat/${encodeURIComponent(t.siteKey)}`,n=Ce(t.storage),c=`seyalhub:visitor:${t.siteKey}`,l=`seyalhub:started:${t.siteKey}`,x=(se=n.getItem(c))!=null?se:"";/^[A-Za-z0-9_-]{32,64}$/.test(x)||(x=ce(40),n.setItem(c,x));let v=!1,g=!1,N=!1,w="",L=0,C,k,T=new Map,K=new Map,A=a("div");A.setAttribute("data-seyalhub-chat","");let ge=A.attachShadow({mode:"open"}),F=a("style");F.textContent=de;let $=a("div",`root ${t.position==="left"?"left":"right"}`),b=a("section","panel");b.setAttribute("role","dialog"),b.setAttribute("aria-label","Chat");let q=a("div","head"),V=a("div"),G=a("h2",void 0,(ae=t.title)!=null?ae:"Chat with us"),J=a("div","sub");V.append(G,J);let E=a("button","close","\xD7");E.type="button",E.setAttribute("aria-label","Close chat"),q.append(V,E);let m=a("div","log");m.setAttribute("role","log"),m.setAttribute("aria-live","polite");let M=a("div","typing","Typing\u2026"),S=a("div","error");S.setAttribute("role","alert");let H=a("form"),h=a("textarea");h.rows=1,h.maxLength=1e3,h.placeholder="Type your message",h.setAttribute("aria-label","Your message");let X=a("button","send","Send");X.type="submit",H.append(h,X);let he=a("div","foot","Powered by SeyalHub");b.append(q,m,S,H,he);let f=a("button","launcher");f.type="button",f.setAttribute("aria-label","Open chat"),f.setAttribute("aria-expanded","false"),f.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 4h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-5 4v-4H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z"/></svg>';let U=a("span","dot");f.append(U),$.append(b,f),ge.append(F,$);function Z(e){e&&ye.test(e)&&$.style.setProperty("--c",e)}Z(t.color);let Q=()=>{m.scrollTop=m.scrollHeight};function R(e){S.textContent=e!=null?e:"",S.classList.toggle("on",!!e)}function ee(e){k&&clearTimeout(k),e?(m.append(M),Q(),k=setTimeout(()=>M.remove(),we)):M.remove()}function I(e,i){let r=a("div",i==="note"?"note":`msg ${i}`,e);return M.remove(),m.append(r),Q(),r}function be(e){if(!T.has(e.id)){if(w=e.id>w?e.id:w,e.direction==="inbound"){let i=e.client_id?K.get(e.client_id):void 0;if(i){T.set(e.id,i),K.delete(e.client_id);return}T.set(e.id,I(e.text,"me"));return}T.set(e.id,I(e.text,"them")),ee(!1),g||U.classList.add("on")}}async function W(e,i){var r;return o(`${p}${e}`,{...i,headers:{"content-type":"application/json",...(r=i==null?void 0:i.headers)!=null?r:{}}})}async function _(){var i;if(v)return;let e=g?(i=t.pollMs)!=null?i:2e3:xe;try{let r=new URLSearchParams({visitor_id:x});w&&r.set("after",w);let s=await W(`/messages?${r}`);if(s.ok){let y=await s.json();y.messages.forEach(be),J.textContent=y.human?"You are chatting with our team":"",L=0,R(null)}else{if(s.status===403||s.status===404)return void Y();throw new Error(String(s.status))}}catch{L=Math.min(ve,(L||1e3)*2),e=Math.max(e,L)}!v&&(g||n.getItem(l))&&(C=setTimeout(()=>void _(),e))}function te(){C&&clearTimeout(C),_()}async function me(){var e;N||(N=!0,await _(),T.size===0&&I((e=t.greeting)!=null?e:oe,"them"))}let oe="Hi! How can we help?";async function ie(e,i,r){r.classList.remove("failed");try{let s=await W("/messages",{method:"POST",body:JSON.stringify({visitor_id:x,text:e,client_message_id:i})});if(s.status===429)throw new Error("You are sending messages too fast. Please wait a moment.");if(!s.ok)throw new Error(s.status===503?"Chat is not available right now. Please try again shortly.":"Your message could not be sent. Tap it to try again.");n.setItem(l,"1"),R(null),ee(!0),te()}catch(s){r.classList.add("failed"),r.onclick=()=>void ie(e,i,r),R(s instanceof Error&&s.message?s.message:"Your message could not be sent. Tap it to try again.")}}H.addEventListener("submit",e=>{e.preventDefault();let i=h.value.trim();if(!i)return;h.value="";let r=`cm_${ce(16)}`,s=I(i,"me");K.set(r,s),ie(i,r,s)}),h.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),H.requestSubmit())}),b.addEventListener("keydown",e=>{e.key==="Escape"&&O()});function B(){v||g||(g=!0,b.classList.add("open"),f.setAttribute("aria-expanded","true"),f.setAttribute("aria-label","Close chat"),U.classList.remove("on"),me().then(()=>{g&&te()}),h.focus())}function O(){g&&(g=!1,b.classList.remove("open"),f.setAttribute("aria-expanded","false"),f.setAttribute("aria-label","Open chat"),f.focus())}function ne(){g?O():B()}function Y(){v=!0,C&&clearTimeout(C),k&&clearTimeout(k),A.remove()}return f.addEventListener("click",ne),E.addEventListener("click",O),(async()=>{var e,i,r,s;try{let y=await W("/config");if(!y.ok)return typeof console!="undefined"&&console.warn(`[SeyalHub chat] not shown (${y.status}): check the site key and that this website is listed in the portal.`),void Y();let j=await y.json();G.textContent=(e=t.title)!=null?e:j.title,oe=(i=t.greeting)!=null?i:j.greeting,Z((r=t.color)!=null?r:j.color)}catch{}v||(((s=t.container)!=null?s:document.body).append(A),n.getItem(l)&&_(),t.open&&B())})(),{open:B,close:O,toggle:ne,destroy:Y}}var z=class extends HTMLElement{connectedCallback(){this.start()}disconnectedCallback(){this.stop()}attributeChangedCallback(){this.isConnected&&(this.stop(),this.start())}open(){var o;(o=this.widget)==null||o.open()}close(){var o;(o=this.widget)==null||o.close()}start(){var n,c,l;let o=this.getAttribute("site-key"),p=this.getAttribute("api-url");!o||!p||(this.widget=P({siteKey:o,apiUrl:p,title:(n=this.getAttribute("title"))!=null?n:void 0,greeting:(c=this.getAttribute("greeting"))!=null?c:void 0,color:(l=this.getAttribute("color"))!=null?l:void 0,position:this.getAttribute("position")==="left"?"left":"right",open:this.hasAttribute("open")}))}stop(){var o;(o=this.widget)==null||o.destroy(),this.widget=void 0}};z.observedAttributes=["site-key","api-url","title","greeting","color","position","open"];function D(){typeof customElements!="undefined"&&!customElements.get("seyalhub-chat")&&customElements.define("seyalhub-chat",z)}D();D();var d;function ue(t){return d==null||d.destroy(),d=P(t),d}var ke={init:ue,destroy:()=>{d==null||d.destroy(),d=void 0},open:()=>d==null?void 0:d.open(),close:()=>d==null?void 0:d.close()};globalThis.SeyalHubChat=ke;var u=typeof document!="undefined"?document.currentScript:null,pe=u==null?void 0:u.dataset.siteKey,fe=u==null?void 0:u.dataset.apiUrl;if(pe&&fe){let t=()=>ue({siteKey:pe,apiUrl:fe,title:u.dataset.title,greeting:u.dataset.greeting,color:u.dataset.color,position:u.dataset.position==="left"?"left":"right",open:u.dataset.open==="true"});document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}})();
|
|
34
|
+
//# sourceMappingURL=seyalhub-chat.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/styles.ts", "../src/widget.ts", "../src/element.ts", "../src/auto.ts"],
|
|
4
|
+
"sourcesContent": ["/** All styles live inside the widget's shadow root, so the host page's CSS cannot break the widget and the widget's CSS cannot touch the page. */\nexport const CSS = `\n:host { all: initial; }\n* { box-sizing: border-box; font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; }\n.root { position: fixed; bottom: 20px; z-index: 2147483000; --c: #4f46e5; }\n.root.right { right: 20px; } .root.left { left: 20px; }\n.launcher { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--c); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 20px rgba(0,0,0,.25); position: relative; }\n.launcher:focus-visible, button:focus-visible, textarea:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }\n.launcher svg { width: 26px; height: 26px; fill: currentColor; }\n.dot { position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%; background: #ef4444; border: 2px solid #fff; display: none; }\n.dot.on { display: block; }\n.panel { position: absolute; bottom: 70px; width: min(380px, calc(100vw - 24px)); height: min(560px, calc(100vh - 110px)); background: #fff; border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.28); display: none; flex-direction: column; overflow: hidden; color: #0f172a; }\n.right .panel { right: 0; } .left .panel { left: 0; }\n.panel.open { display: flex; }\n.head { background: var(--c); color: #fff; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; }\n.head h2 { margin: 0; font-size: 16px; font-weight: 600; }\n.head .sub { font-size: 12px; opacity: .85; }\n.close { background: transparent; border: 0; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }\n.log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #f8fafc; }\n.msg { max-width: 82%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }\n.msg.them { background: #fff; border: 1px solid #e2e8f0; align-self: flex-start; border-bottom-left-radius: 4px; }\n.msg.me { background: var(--c); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }\n.msg.failed { opacity: .75; outline: 2px solid #ef4444; cursor: pointer; }\n.note { align-self: center; font-size: 12px; color: #64748b; text-align: center; }\n.typing { align-self: flex-start; color: #64748b; font-size: 13px; padding: 4px 8px; }\n.error { background: #fef2f2; color: #991b1b; font-size: 13px; padding: 8px 12px; display: none; }\n.error.on { display: block; }\nform { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #e2e8f0; background: #fff; }\ntextarea { flex: 1; resize: none; border: 1px solid #cbd5e1; border-radius: 10px; padding: 9px 10px; font-size: 14px; max-height: 96px; min-height: 40px; }\n.send { border: 0; border-radius: 10px; background: var(--c); color: #fff; padding: 0 16px; font-size: 14px; font-weight: 600; cursor: pointer; }\n.send:disabled { opacity: .5; cursor: default; }\n.foot { text-align: center; font-size: 11px; color: #94a3b8; padding: 0 0 8px; background: #fff; }\n@media (prefers-reduced-motion: no-preference) { .panel.open { animation: rise .15s ease-out; } @keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } } }\n`;\n", "import { CSS } from \"./styles\";\n\nexport interface ChatOptions {\n /** The site key from the portal (Settings, Channels). Starts with `wc_`. */\n siteKey: string;\n /** Where the SeyalHub API lives, for example `https://api.example.com`. No path. */\n apiUrl: string;\n /** Override the title, greeting or colour set in the portal. */\n title?: string;\n greeting?: string;\n color?: string;\n position?: \"right\" | \"left\";\n /** Open the chat as soon as it is ready. */\n open?: boolean;\n /** Where to attach the widget. Default: document.body. */\n container?: HTMLElement;\n /** How often to look for new messages while the chat is open. Default 2000 ms. */\n pollMs?: number;\n /** Test hooks. */\n fetch?: typeof fetch;\n storage?: Pick<Storage, \"getItem\" | \"setItem\">;\n}\n\nexport interface ChatWidget {\n open(): void;\n close(): void;\n toggle(): void;\n destroy(): void;\n}\n\ninterface Line {\n id: string;\n direction: \"inbound\" | \"outbound\";\n text: string;\n sent_by?: string | null;\n client_id?: string | null;\n}\n\nconst ALPHABET = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\nconst COLOR = /^#[0-9a-fA-F]{6}$/;\nconst BACKGROUND_POLL_MS = 10_000;\nconst MAX_BACKOFF_MS = 15_000;\nconst TYPING_TIMEOUT_MS = 60_000;\n\nfunction randomId(length: number): string {\n const bytes = new Uint8Array(length);\n (globalThis.crypto ?? ({} as Crypto)).getRandomValues?.(bytes);\n if (!bytes.some((b) => b !== 0)) for (let i = 0; i < length; i++) bytes[i] = Math.floor(Math.random() * 256); // very old browsers: fall back\n return Array.from(bytes, (b) => ALPHABET[b % ALPHABET.length]).join(\"\");\n}\n\nfunction safeStorage(custom?: ChatOptions[\"storage\"]): Pick<Storage, \"getItem\" | \"setItem\"> {\n const memory = new Map<string, string>();\n const fallback = { getItem: (k: string) => memory.get(k) ?? null, setItem: (k: string, v: string) => void memory.set(k, v) };\n try {\n const s = custom ?? window.localStorage;\n s.setItem(\"seyalhub:probe\", \"1\");\n return s;\n } catch {\n return fallback; // private mode or storage blocked: the chat still works, it just does not survive a reload\n }\n}\n\nfunction el<K extends keyof HTMLElementTagNameMap>(tag: K, className?: string, text?: string): HTMLElementTagNameMap[K] {\n const node = document.createElement(tag);\n if (className) node.className = className;\n if (text !== undefined) node.textContent = text; // always textContent: a message can never inject markup\n return node;\n}\n\nexport function createChatWidget(options: ChatOptions): ChatWidget {\n const doFetch = options.fetch ?? ((...args: Parameters<typeof fetch>) => fetch(...args));\n const base = `${options.apiUrl.replace(/\\/+$/, \"\")}/api/v1/public/webchat/${encodeURIComponent(options.siteKey)}`;\n const storage = safeStorage(options.storage);\n const keyVisitor = `seyalhub:visitor:${options.siteKey}`;\n const keyStarted = `seyalhub:started:${options.siteKey}`;\n let visitor = storage.getItem(keyVisitor) ?? \"\";\n if (!/^[A-Za-z0-9_-]{32,64}$/.test(visitor)) {\n visitor = randomId(40); // long and random: it is the only thing that lets this browser read this conversation\n storage.setItem(keyVisitor, visitor);\n }\n\n let destroyed = false;\n let isOpen = false;\n let loadedHistory = false;\n let lastId = \"\";\n let backoff = 0;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let typingTimer: ReturnType<typeof setTimeout> | undefined;\n const rendered = new Map<string, HTMLElement>(); // server id or client id -> bubble\n const pendingBubbles = new Map<string, HTMLElement>(); // client id -> bubble waiting for the server's copy\n\n // --- DOM -----------------------------------------------------------------------------------------------------\n const host = el(\"div\");\n host.setAttribute(\"data-seyalhub-chat\", \"\");\n const shadow = host.attachShadow({ mode: \"open\" });\n const style = el(\"style\");\n style.textContent = CSS;\n const root = el(\"div\", `root ${options.position === \"left\" ? \"left\" : \"right\"}`);\n const panel = el(\"section\", \"panel\");\n panel.setAttribute(\"role\", \"dialog\");\n panel.setAttribute(\"aria-label\", \"Chat\");\n const head = el(\"div\", \"head\");\n const headText = el(\"div\");\n const titleEl = el(\"h2\", undefined, options.title ?? \"Chat with us\");\n const subEl = el(\"div\", \"sub\");\n headText.append(titleEl, subEl);\n const closeBtn = el(\"button\", \"close\", \"\u00D7\");\n closeBtn.type = \"button\";\n closeBtn.setAttribute(\"aria-label\", \"Close chat\");\n head.append(headText, closeBtn);\n const log = el(\"div\", \"log\");\n log.setAttribute(\"role\", \"log\");\n log.setAttribute(\"aria-live\", \"polite\");\n const typing = el(\"div\", \"typing\", \"Typing\u2026\");\n const errorBar = el(\"div\", \"error\");\n errorBar.setAttribute(\"role\", \"alert\");\n const form = el(\"form\");\n const input = el(\"textarea\");\n input.rows = 1;\n input.maxLength = 1000;\n input.placeholder = \"Type your message\";\n input.setAttribute(\"aria-label\", \"Your message\");\n const sendBtn = el(\"button\", \"send\", \"Send\");\n sendBtn.type = \"submit\";\n form.append(input, sendBtn);\n const foot = el(\"div\", \"foot\", \"Powered by SeyalHub\");\n panel.append(head, log, errorBar, form, foot);\n const launcher = el(\"button\", \"launcher\");\n launcher.type = \"button\";\n launcher.setAttribute(\"aria-label\", \"Open chat\");\n launcher.setAttribute(\"aria-expanded\", \"false\");\n launcher.innerHTML = '<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M4 4h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-5 4v-4H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z\"/></svg>'; // static markup, no user data\n const dot = el(\"span\", \"dot\");\n launcher.append(dot);\n root.append(panel, launcher);\n shadow.append(style, root);\n\n function applyColor(color?: string) {\n if (color && COLOR.test(color)) root.style.setProperty(\"--c\", color);\n }\n applyColor(options.color);\n\n // --- helpers ---------------------------------------------------------------------------------------------------\n const scrollDown = () => { log.scrollTop = log.scrollHeight; };\n function showError(message: string | null) {\n errorBar.textContent = message ?? \"\";\n errorBar.classList.toggle(\"on\", Boolean(message));\n }\n function setTyping(on: boolean) {\n if (typingTimer) clearTimeout(typingTimer);\n if (on) {\n log.append(typing);\n scrollDown();\n typingTimer = setTimeout(() => typing.remove(), TYPING_TIMEOUT_MS);\n } else typing.remove();\n }\n function bubble(text: string, kind: \"me\" | \"them\" | \"note\"): HTMLElement {\n const b = el(\"div\", kind === \"note\" ? \"note\" : `msg ${kind}`, text);\n typing.remove();\n log.append(b);\n scrollDown();\n return b;\n }\n\n function addServerLine(line: Line) {\n if (rendered.has(line.id)) return;\n lastId = line.id > lastId ? line.id : lastId;\n if (line.direction === \"inbound\") {\n const mine = line.client_id ? pendingBubbles.get(line.client_id) : undefined;\n if (mine) { // the server's copy of a message this page sent: keep the bubble, remember its id\n rendered.set(line.id, mine);\n pendingBubbles.delete(line.client_id!);\n return;\n }\n rendered.set(line.id, bubble(line.text, \"me\"));\n return;\n }\n rendered.set(line.id, bubble(line.text, \"them\"));\n setTyping(false);\n if (!isOpen) dot.classList.add(\"on\");\n }\n\n // --- talking to the API ----------------------------------------------------------------------------------------\n async function api(path: string, init?: RequestInit): Promise<Response> {\n return doFetch(`${base}${path}`, { ...init, headers: { \"content-type\": \"application/json\", ...(init?.headers ?? {}) } });\n }\n\n async function poll(): Promise<void> {\n if (destroyed) return;\n let delay = isOpen ? options.pollMs ?? 2000 : BACKGROUND_POLL_MS;\n try {\n const qs = new URLSearchParams({ visitor_id: visitor });\n if (lastId) qs.set(\"after\", lastId);\n const res = await api(`/messages?${qs}`);\n if (res.ok) {\n const body = (await res.json()) as { messages: Line[]; human?: boolean };\n body.messages.forEach(addServerLine);\n subEl.textContent = body.human ? \"You are chatting with our team\" : \"\";\n backoff = 0;\n showError(null);\n } else if (res.status === 403 || res.status === 404) {\n return void destroy(); // not allowed here (website not listed) or the chat was switched off: stop quietly\n } else throw new Error(String(res.status));\n } catch {\n backoff = Math.min(MAX_BACKOFF_MS, (backoff || 1000) * 2);\n delay = Math.max(delay, backoff);\n }\n if (!destroyed && (isOpen || storage.getItem(keyStarted))) timer = setTimeout(() => void poll(), delay);\n }\n\n function restartPolling() {\n if (timer) clearTimeout(timer);\n void poll();\n }\n\n async function loadHistory(): Promise<void> {\n if (loadedHistory) return;\n loadedHistory = true;\n await poll();\n if (rendered.size === 0) bubble(options.greeting ?? greeting, \"them\"); // the greeting is only a first line, not stored as a message\n }\n let greeting = \"Hi! How can we help?\";\n\n async function send(text: string, clientId: string, node: HTMLElement): Promise<void> {\n node.classList.remove(\"failed\");\n try {\n const res = await api(\"/messages\", { method: \"POST\", body: JSON.stringify({ visitor_id: visitor, text, client_message_id: clientId }) });\n if (res.status === 429) throw new Error(\"You are sending messages too fast. Please wait a moment.\");\n if (!res.ok) throw new Error(res.status === 503 ? \"Chat is not available right now. Please try again shortly.\" : \"Your message could not be sent. Tap it to try again.\");\n storage.setItem(keyStarted, \"1\");\n showError(null);\n setTyping(true);\n restartPolling();\n } catch (err) {\n node.classList.add(\"failed\");\n node.onclick = () => void send(text, clientId, node);\n showError(err instanceof Error && err.message ? err.message : \"Your message could not be sent. Tap it to try again.\");\n }\n }\n\n form.addEventListener(\"submit\", (e) => {\n e.preventDefault();\n const text = input.value.trim();\n if (!text) return;\n input.value = \"\";\n const clientId = `cm_${randomId(16)}`;\n const node = bubble(text, \"me\");\n pendingBubbles.set(clientId, node);\n void send(text, clientId, node);\n });\n input.addEventListener(\"keydown\", (e) => {\n if (e.key === \"Enter\" && !e.shiftKey && !e.isComposing) {\n e.preventDefault();\n form.requestSubmit();\n }\n });\n panel.addEventListener(\"keydown\", (e) => { if (e.key === \"Escape\") close(); });\n\n // --- open / close ----------------------------------------------------------------------------------------------\n function open() {\n if (destroyed || isOpen) return;\n isOpen = true;\n panel.classList.add(\"open\");\n launcher.setAttribute(\"aria-expanded\", \"true\");\n launcher.setAttribute(\"aria-label\", \"Close chat\");\n dot.classList.remove(\"on\");\n void loadHistory().then(() => { if (isOpen) restartPolling(); });\n input.focus();\n }\n function close() {\n if (!isOpen) return;\n isOpen = false;\n panel.classList.remove(\"open\");\n launcher.setAttribute(\"aria-expanded\", \"false\");\n launcher.setAttribute(\"aria-label\", \"Open chat\");\n launcher.focus();\n }\n function toggle() { isOpen ? close() : open(); }\n function destroy() {\n destroyed = true;\n if (timer) clearTimeout(timer);\n if (typingTimer) clearTimeout(typingTimer);\n host.remove();\n }\n launcher.addEventListener(\"click\", toggle);\n closeBtn.addEventListener(\"click\", close);\n\n // --- start: fetch the portal's settings, then show the launcher --------------------------------------------------\n void (async () => {\n try {\n const res = await api(\"/config\");\n if (!res.ok) {\n if (typeof console !== \"undefined\") console.warn(`[SeyalHub chat] not shown (${res.status}): check the site key and that this website is listed in the portal.`);\n return void destroy();\n }\n const cfg = (await res.json()) as { title: string; greeting: string; color: string };\n titleEl.textContent = options.title ?? cfg.title;\n greeting = options.greeting ?? cfg.greeting;\n applyColor(options.color ?? cfg.color);\n } catch {\n // the settings are optional: show the chat with defaults, and let sending report any real problem\n }\n if (destroyed) return;\n (options.container ?? document.body).append(host);\n if (storage.getItem(keyStarted)) void poll(); // a returning visitor: look for replies while closed, to show the unread dot\n if (options.open) open();\n })();\n\n return { open, close, toggle, destroy };\n}\n", "import { createChatWidget, type ChatWidget } from \"./widget\";\n\n/** `<seyalhub-chat site-key=\"wc_...\" api-url=\"https://api.example.com\"></seyalhub-chat>`: works in plain HTML, Angular, Vue, Svelte, anywhere. */\nexport class SeyalHubChatElement extends HTMLElement {\n static observedAttributes = [\"site-key\", \"api-url\", \"title\", \"greeting\", \"color\", \"position\", \"open\"];\n private widget?: ChatWidget;\n\n connectedCallback() { this.start(); }\n disconnectedCallback() { this.stop(); }\n attributeChangedCallback() { if (this.isConnected) { this.stop(); this.start(); } }\n\n /** Same object API as `createChatWidget`, for code that holds the element. */\n open() { this.widget?.open(); }\n close() { this.widget?.close(); }\n\n private start() {\n const siteKey = this.getAttribute(\"site-key\");\n const apiUrl = this.getAttribute(\"api-url\");\n if (!siteKey || !apiUrl) return;\n this.widget = createChatWidget({\n siteKey, apiUrl, title: this.getAttribute(\"title\") ?? undefined, greeting: this.getAttribute(\"greeting\") ?? undefined, color: this.getAttribute(\"color\") ?? undefined,\n position: this.getAttribute(\"position\") === \"left\" ? \"left\" : \"right\", open: this.hasAttribute(\"open\"),\n });\n }\n private stop() { this.widget?.destroy(); this.widget = undefined; }\n}\n\nexport function defineChatElement(): void {\n if (typeof customElements !== \"undefined\" && !customElements.get(\"seyalhub-chat\")) customElements.define(\"seyalhub-chat\", SeyalHubChatElement);\n}\n\ndefineChatElement(); // importing \"@seyalhub/chat-widget/element\" is enough to register it\n", "import { createChatWidget, type ChatOptions, type ChatWidget } from \"./widget\";\nimport { defineChatElement } from \"./element\";\n\n/**\n * The plain <script> build. Either configure it on the tag:\n * <script src=\".../seyalhub-chat.js\" data-site-key=\"wc_...\" data-api-url=\"https://api.example.com\" defer></script>\n * or call `SeyalHubChat.init({ siteKey, apiUrl })` yourself.\n */\ndefineChatElement();\nlet current: ChatWidget | undefined;\n\nfunction init(options: ChatOptions): ChatWidget {\n current?.destroy();\n current = createChatWidget(options);\n return current;\n}\n\nconst api = { init, destroy: () => { current?.destroy(); current = undefined; }, open: () => current?.open(), close: () => current?.close() };\n(globalThis as unknown as { SeyalHubChat: typeof api }).SeyalHubChat = api;\n\nconst script = typeof document !== \"undefined\" ? (document.currentScript as HTMLScriptElement | null) : null;\nconst siteKey = script?.dataset.siteKey;\nconst apiUrl = script?.dataset.apiUrl;\nif (siteKey && apiUrl) {\n const start = () => init({ siteKey, apiUrl, title: script.dataset.title, greeting: script.dataset.greeting, color: script.dataset.color, position: script.dataset.position === \"left\" ? \"left\" : \"right\", open: script.dataset.open === \"true\" });\n if (document.readyState === \"loading\") document.addEventListener(\"DOMContentLoaded\", start, { once: true });\n else start();\n}\n"],
|
|
5
|
+
"mappings": "mBACO,IAAMA,GAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AW,EAAG,KAAM,IAAMA,GAAA,YAAAA,EAAS,OAAQ,MAAO,IAAMA,GAAA,YAAAA,EAAS,OAAQ,EAC3I,WAAuD,aAAeI,GAEvE,IAAMC,EAAS,OAAO,UAAa,YAAe,SAAS,cAA6C,KAClGC,GAAUD,GAAA,YAAAA,EAAQ,QAAQ,QAC1BE,GAASF,GAAA,YAAAA,EAAQ,QAAQ,OAC/B,GAAIC,IAAWC,GAAQ,CACrB,IAAMC,EAAQ,IAAMP,GAAK,CAAE,QAAAK,GAAS,OAAAC,GAAQ,MAAOF,EAAO,QAAQ,MAAO,SAAUA,EAAO,QAAQ,SAAU,MAAOA,EAAO,QAAQ,MAAO,SAAUA,EAAO,QAAQ,WAAa,OAAS,OAAS,QAAS,KAAMA,EAAO,QAAQ,OAAS,MAAO,CAAC,EAC5O,SAAS,aAAe,UAAW,SAAS,iBAAiB,mBAAoBG,EAAO,CAAE,KAAM,EAAK,CAAC,EACrGA,EAAM,CACb",
|
|
6
|
+
"names": ["CSS", "ALPHABET", "COLOR", "BACKGROUND_POLL_MS", "MAX_BACKOFF_MS", "TYPING_TIMEOUT_MS", "randomId", "length", "_a", "_b", "_c", "bytes", "b", "i", "safeStorage", "custom", "memory", "fallback", "k", "v", "s", "el", "tag", "className", "text", "node", "createChatWidget", "options", "doFetch", "args", "base", "storage", "keyVisitor", "keyStarted", "visitor", "destroyed", "isOpen", "loadedHistory", "lastId", "backoff", "timer", "typingTimer", "rendered", "pendingBubbles", "host", "shadow", "style", "CSS", "root", "panel", "head", "headText", "titleEl", "subEl", "closeBtn", "log", "typing", "errorBar", "form", "input", "sendBtn", "foot", "launcher", "dot", "applyColor", "color", "scrollDown", "showError", "message", "setTyping", "on", "bubble", "kind", "addServerLine", "line", "mine", "api", "path", "init", "poll", "delay", "qs", "res", "body", "destroy", "restartPolling", "loadHistory", "greeting", "send", "clientId", "err", "close", "open", "toggle", "_d", "cfg", "SeyalHubChatElement", "_a", "_b", "_c", "siteKey", "apiUrl", "createChatWidget", "defineChatElement", "defineChatElement", "current", "init", "options", "createChatWidget", "api", "script", "siteKey", "apiUrl", "start"]
|
|
7
|
+
}
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** All styles live inside the widget's shadow root, so the host page's CSS cannot break the widget and the widget's CSS cannot touch the page. */
|
|
2
|
+
export declare const CSS = "\n:host { all: initial; }\n* { box-sizing: border-box; font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; }\n.root { position: fixed; bottom: 20px; z-index: 2147483000; --c: #4f46e5; }\n.root.right { right: 20px; } .root.left { left: 20px; }\n.launcher { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--c); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 20px rgba(0,0,0,.25); position: relative; }\n.launcher:focus-visible, button:focus-visible, textarea:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }\n.launcher svg { width: 26px; height: 26px; fill: currentColor; }\n.dot { position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%; background: #ef4444; border: 2px solid #fff; display: none; }\n.dot.on { display: block; }\n.panel { position: absolute; bottom: 70px; width: min(380px, calc(100vw - 24px)); height: min(560px, calc(100vh - 110px)); background: #fff; border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.28); display: none; flex-direction: column; overflow: hidden; color: #0f172a; }\n.right .panel { right: 0; } .left .panel { left: 0; }\n.panel.open { display: flex; }\n.head { background: var(--c); color: #fff; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; }\n.head h2 { margin: 0; font-size: 16px; font-weight: 600; }\n.head .sub { font-size: 12px; opacity: .85; }\n.close { background: transparent; border: 0; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }\n.log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #f8fafc; }\n.msg { max-width: 82%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }\n.msg.them { background: #fff; border: 1px solid #e2e8f0; align-self: flex-start; border-bottom-left-radius: 4px; }\n.msg.me { background: var(--c); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }\n.msg.failed { opacity: .75; outline: 2px solid #ef4444; cursor: pointer; }\n.note { align-self: center; font-size: 12px; color: #64748b; text-align: center; }\n.typing { align-self: flex-start; color: #64748b; font-size: 13px; padding: 4px 8px; }\n.error { background: #fef2f2; color: #991b1b; font-size: 13px; padding: 8px 12px; display: none; }\n.error.on { display: block; }\nform { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #e2e8f0; background: #fff; }\ntextarea { flex: 1; resize: none; border: 1px solid #cbd5e1; border-radius: 10px; padding: 9px 10px; font-size: 14px; max-height: 96px; min-height: 40px; }\n.send { border: 0; border-radius: 10px; background: var(--c); color: #fff; padding: 0 16px; font-size: 14px; font-weight: 600; cursor: pointer; }\n.send:disabled { opacity: .5; cursor: default; }\n.foot { text-align: center; font-size: 11px; color: #94a3b8; padding: 0 0 8px; background: #fff; }\n@media (prefers-reduced-motion: no-preference) { .panel.open { animation: rise .15s ease-out; } @keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } } }\n";
|
package/dist/widget.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface ChatOptions {
|
|
2
|
+
/** The site key from the portal (Settings, Channels). Starts with `wc_`. */
|
|
3
|
+
siteKey: string;
|
|
4
|
+
/** Where the SeyalHub API lives, for example `https://api.example.com`. No path. */
|
|
5
|
+
apiUrl: string;
|
|
6
|
+
/** Override the title, greeting or colour set in the portal. */
|
|
7
|
+
title?: string;
|
|
8
|
+
greeting?: string;
|
|
9
|
+
color?: string;
|
|
10
|
+
position?: "right" | "left";
|
|
11
|
+
/** Open the chat as soon as it is ready. */
|
|
12
|
+
open?: boolean;
|
|
13
|
+
/** Where to attach the widget. Default: document.body. */
|
|
14
|
+
container?: HTMLElement;
|
|
15
|
+
/** How often to look for new messages while the chat is open. Default 2000 ms. */
|
|
16
|
+
pollMs?: number;
|
|
17
|
+
/** Test hooks. */
|
|
18
|
+
fetch?: typeof fetch;
|
|
19
|
+
storage?: Pick<Storage, "getItem" | "setItem">;
|
|
20
|
+
}
|
|
21
|
+
export interface ChatWidget {
|
|
22
|
+
open(): void;
|
|
23
|
+
close(): void;
|
|
24
|
+
toggle(): void;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare function createChatWidget(options: ChatOptions): ChatWidget;
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seyalhub/chat-widget",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SeyalHub website chat: a small, framework-free chat widget for any website, with a custom element and a React component.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"private": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"./dist/element.js",
|
|
10
|
+
"./dist/element.cjs",
|
|
11
|
+
"./dist/seyalhub-chat.js"
|
|
12
|
+
],
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"unpkg": "./dist/seyalhub-chat.js",
|
|
17
|
+
"jsdelivr": "./dist/seyalhub-chat.js",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./element": {
|
|
25
|
+
"types": "./dist/element.d.ts",
|
|
26
|
+
"import": "./dist/element.js",
|
|
27
|
+
"require": "./dist/element.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./react": {
|
|
30
|
+
"types": "./dist/react.d.ts",
|
|
31
|
+
"import": "./dist/react.js",
|
|
32
|
+
"require": "./dist/react.cjs"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "node build.mjs",
|
|
42
|
+
"typecheck": "tsc --noEmit -p .",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": ">=17"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"react": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/react": "^18.3.0",
|
|
56
|
+
"@types/react-dom": "^18.3.7",
|
|
57
|
+
"esbuild": "^0.25.0",
|
|
58
|
+
"jsdom": "^26.0.0",
|
|
59
|
+
"react": "^18.3.1",
|
|
60
|
+
"react-dom": "^18.3.1",
|
|
61
|
+
"typescript": "~5.6.2",
|
|
62
|
+
"vitest": "^3.0.0"
|
|
63
|
+
},
|
|
64
|
+
"keywords": [
|
|
65
|
+
"chat",
|
|
66
|
+
"widget",
|
|
67
|
+
"seyalhub",
|
|
68
|
+
"customer-support",
|
|
69
|
+
"ai-agent"
|
|
70
|
+
]
|
|
71
|
+
}
|