@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 CHANGED
@@ -1,3 +1,118 @@
1
- # Temporary Holding Version
1
+ # @seyalhub/chat-widget
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A small chat widget that puts your SeyalHub agents on any website. About 4 KB gzipped, no dependencies, styled inside a shadow root so your site's CSS cannot break it.
4
+
5
+ **Before you start** (in the SeyalHub portal, Settings, Channels): create a *Website chat* channel and list the website addresses allowed to use it (for example `https://www.myhotel.com`). The portal gives you a **site key** that starts with `wc_`. The key is public; it is the allowed addresses that keep other sites from using it.
6
+
7
+ You also need your API address (for example `https://api.seyalhub.com`).
8
+
9
+ ## 1. Any website: one script tag
10
+
11
+ ```html
12
+ <script src="https://cdn.jsdelivr.net/npm/@seyalhub/chat-widget@0/dist/seyalhub-chat.js"
13
+ data-site-key="wc_xxxxxxxxxxxxxxxxxxxxxxxx"
14
+ data-api-url="https://api.seyalhub.com" defer></script>
15
+ ```
16
+
17
+ Optional attributes: `data-title`, `data-greeting`, `data-color` (`#4f46e5`), `data-position` (`right` or `left`), `data-open="true"`.
18
+ The portal's settings are used for anything you leave out. Pin the version (`@0.1.0`) in production.
19
+
20
+ Or start it yourself:
21
+
22
+ ```html
23
+ <script src=".../seyalhub-chat.js"></script>
24
+ <script>SeyalHubChat.init({ siteKey: "wc_...", apiUrl: "https://api.seyalhub.com" });</script>
25
+ ```
26
+
27
+ `SeyalHubChat.open()`, `.close()` and `.destroy()` are available afterwards.
28
+
29
+ ## 2. React (17, 18, 19), Next.js, Vite
30
+
31
+ ```bash
32
+ npm install @seyalhub/chat-widget
33
+ ```
34
+
35
+ ```tsx
36
+ import { SeyalHubChat } from "@seyalhub/chat-widget/react";
37
+
38
+ export function App() {
39
+ return (
40
+ <>
41
+ {/* your app */}
42
+ <SeyalHubChat siteKey="wc_..." apiUrl="https://api.seyalhub.com" />
43
+ </>
44
+ );
45
+ }
46
+ ```
47
+
48
+ It renders nothing itself and only touches the page in the browser, so it is safe with server rendering. In Next.js, put it in a client component (`"use client"`).
49
+
50
+ ## 3. Angular (standalone or modules)
51
+
52
+ The widget is a standard custom element, so Angular needs no extra library.
53
+
54
+ ```ts
55
+ // main.ts (or any file that loads once)
56
+ import "@seyalhub/chat-widget/element";
57
+ ```
58
+
59
+ ```ts
60
+ // app.component.ts
61
+ import { Component, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
62
+
63
+ @Component({
64
+ selector: "app-root",
65
+ standalone: true,
66
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
67
+ template: `<router-outlet /><seyalhub-chat site-key="wc_..." api-url="https://api.seyalhub.com"></seyalhub-chat>`,
68
+ })
69
+ export class AppComponent {}
70
+ ```
71
+
72
+ For NgModule apps, add `schemas: [CUSTOM_ELEMENTS_SCHEMA]` to the module. To control it from code instead:
73
+
74
+ ```ts
75
+ import { createChatWidget, ChatWidget } from "@seyalhub/chat-widget";
76
+ // ngAfterViewInit: this.chat = createChatWidget({ siteKey, apiUrl }); ngOnDestroy: this.chat.destroy();
77
+ ```
78
+
79
+ ## 4. Vue, Svelte, plain modules
80
+
81
+ ```ts
82
+ import { createChatWidget } from "@seyalhub/chat-widget";
83
+ const chat = createChatWidget({ siteKey: "wc_...", apiUrl: "https://api.seyalhub.com", color: "#0f766e" });
84
+ // chat.open(); chat.close(); chat.destroy();
85
+ ```
86
+
87
+ Vue: `app.config.compilerOptions.isCustomElement = (tag) => tag === "seyalhub-chat"` lets you use the element in templates.
88
+
89
+ ## Options
90
+
91
+ | Option | Meaning |
92
+ |---|---|
93
+ | `siteKey` | The `wc_` key from the portal. Required |
94
+ | `apiUrl` | The SeyalHub API address, with no path. Required |
95
+ | `title`, `greeting`, `color` | Override what the portal says |
96
+ | `position` | `right` (default) or `left` |
97
+ | `open` | Open as soon as it is ready |
98
+ | `pollMs` | How often to look for replies while open (default 2000) |
99
+
100
+ ## How it behaves
101
+
102
+ - The visitor gets a long random id, kept in the browser's `localStorage`, so a returning visitor sees their chat again. Clearing site data starts a new chat.
103
+ - Messages are shown as plain text only. Links and HTML in a message are never turned into markup.
104
+ - If the website is not on the allowed list, or the key is wrong, nothing is shown and one line is written to the browser console.
105
+ - A message that fails to send is marked and can be tapped to retry. A retry never makes the agent answer twice.
106
+ - When a person from your team takes over in the Inbox, the chat says so and their replies arrive in the same window.
107
+ - Keyboard and screen reader friendly: Escape closes, the log is announced, focus returns to the launcher.
108
+
109
+ ## Develop
110
+
111
+ ```bash
112
+ npm install
113
+ npm test # vitest + jsdom
114
+ npm run typecheck
115
+ npm run build # dist/: ESM, CJS, the one-file script build and the type declarations
116
+ ```
117
+
118
+ Open `examples/index.html` after a build to try it against a running API.
package/dist/auto.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,380 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/element.ts
21
+ var element_exports = {};
22
+ __export(element_exports, {
23
+ SeyalHubChatElement: () => SeyalHubChatElement,
24
+ defineChatElement: () => defineChatElement
25
+ });
26
+ module.exports = __toCommonJS(element_exports);
27
+
28
+ // src/styles.ts
29
+ var CSS = `
30
+ :host { all: initial; }
31
+ * { box-sizing: border-box; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
32
+ .root { position: fixed; bottom: 20px; z-index: 2147483000; --c: #4f46e5; }
33
+ .root.right { right: 20px; } .root.left { left: 20px; }
34
+ .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; }
35
+ .launcher:focus-visible, button:focus-visible, textarea:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
36
+ .launcher svg { width: 26px; height: 26px; fill: currentColor; }
37
+ .dot { position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%; background: #ef4444; border: 2px solid #fff; display: none; }
38
+ .dot.on { display: block; }
39
+ .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; }
40
+ .right .panel { right: 0; } .left .panel { left: 0; }
41
+ .panel.open { display: flex; }
42
+ .head { background: var(--c); color: #fff; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; }
43
+ .head h2 { margin: 0; font-size: 16px; font-weight: 600; }
44
+ .head .sub { font-size: 12px; opacity: .85; }
45
+ .close { background: transparent; border: 0; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
46
+ .log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #f8fafc; }
47
+ .msg { max-width: 82%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
48
+ .msg.them { background: #fff; border: 1px solid #e2e8f0; align-self: flex-start; border-bottom-left-radius: 4px; }
49
+ .msg.me { background: var(--c); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
50
+ .msg.failed { opacity: .75; outline: 2px solid #ef4444; cursor: pointer; }
51
+ .note { align-self: center; font-size: 12px; color: #64748b; text-align: center; }
52
+ .typing { align-self: flex-start; color: #64748b; font-size: 13px; padding: 4px 8px; }
53
+ .error { background: #fef2f2; color: #991b1b; font-size: 13px; padding: 8px 12px; display: none; }
54
+ .error.on { display: block; }
55
+ form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #e2e8f0; background: #fff; }
56
+ textarea { flex: 1; resize: none; border: 1px solid #cbd5e1; border-radius: 10px; padding: 9px 10px; font-size: 14px; max-height: 96px; min-height: 40px; }
57
+ .send { border: 0; border-radius: 10px; background: var(--c); color: #fff; padding: 0 16px; font-size: 14px; font-weight: 600; cursor: pointer; }
58
+ .send:disabled { opacity: .5; cursor: default; }
59
+ .foot { text-align: center; font-size: 11px; color: #94a3b8; padding: 0 0 8px; background: #fff; }
60
+ @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; } } }
61
+ `;
62
+
63
+ // src/widget.ts
64
+ var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
65
+ var COLOR = /^#[0-9a-fA-F]{6}$/;
66
+ var BACKGROUND_POLL_MS = 1e4;
67
+ var MAX_BACKOFF_MS = 15e3;
68
+ var TYPING_TIMEOUT_MS = 6e4;
69
+ function randomId(length) {
70
+ var _a, _b, _c;
71
+ const bytes = new Uint8Array(length);
72
+ (_c = (_b = (_a = globalThis.crypto) != null ? _a : {}).getRandomValues) == null ? void 0 : _c.call(_b, bytes);
73
+ if (!bytes.some((b) => b !== 0)) for (let i = 0; i < length; i++) bytes[i] = Math.floor(Math.random() * 256);
74
+ return Array.from(bytes, (b) => ALPHABET[b % ALPHABET.length]).join("");
75
+ }
76
+ function safeStorage(custom) {
77
+ const memory = /* @__PURE__ */ new Map();
78
+ const fallback = { getItem: (k) => {
79
+ var _a;
80
+ return (_a = memory.get(k)) != null ? _a : null;
81
+ }, setItem: (k, v) => void memory.set(k, v) };
82
+ try {
83
+ const s = custom != null ? custom : window.localStorage;
84
+ s.setItem("seyalhub:probe", "1");
85
+ return s;
86
+ } catch {
87
+ return fallback;
88
+ }
89
+ }
90
+ function el(tag, className, text) {
91
+ const node = document.createElement(tag);
92
+ if (className) node.className = className;
93
+ if (text !== void 0) node.textContent = text;
94
+ return node;
95
+ }
96
+ function createChatWidget(options) {
97
+ var _a, _b, _c;
98
+ const doFetch = (_a = options.fetch) != null ? _a : ((...args) => fetch(...args));
99
+ const base = `${options.apiUrl.replace(/\/+$/, "")}/api/v1/public/webchat/${encodeURIComponent(options.siteKey)}`;
100
+ const storage = safeStorage(options.storage);
101
+ const keyVisitor = `seyalhub:visitor:${options.siteKey}`;
102
+ const keyStarted = `seyalhub:started:${options.siteKey}`;
103
+ let visitor = (_b = storage.getItem(keyVisitor)) != null ? _b : "";
104
+ if (!/^[A-Za-z0-9_-]{32,64}$/.test(visitor)) {
105
+ visitor = randomId(40);
106
+ storage.setItem(keyVisitor, visitor);
107
+ }
108
+ let destroyed = false;
109
+ let isOpen = false;
110
+ let loadedHistory = false;
111
+ let lastId = "";
112
+ let backoff = 0;
113
+ let timer;
114
+ let typingTimer;
115
+ const rendered = /* @__PURE__ */ new Map();
116
+ const pendingBubbles = /* @__PURE__ */ new Map();
117
+ const host = el("div");
118
+ host.setAttribute("data-seyalhub-chat", "");
119
+ const shadow = host.attachShadow({ mode: "open" });
120
+ const style = el("style");
121
+ style.textContent = CSS;
122
+ const root = el("div", `root ${options.position === "left" ? "left" : "right"}`);
123
+ const panel = el("section", "panel");
124
+ panel.setAttribute("role", "dialog");
125
+ panel.setAttribute("aria-label", "Chat");
126
+ const head = el("div", "head");
127
+ const headText = el("div");
128
+ const titleEl = el("h2", void 0, (_c = options.title) != null ? _c : "Chat with us");
129
+ const subEl = el("div", "sub");
130
+ headText.append(titleEl, subEl);
131
+ const closeBtn = el("button", "close", "\xD7");
132
+ closeBtn.type = "button";
133
+ closeBtn.setAttribute("aria-label", "Close chat");
134
+ head.append(headText, closeBtn);
135
+ const log = el("div", "log");
136
+ log.setAttribute("role", "log");
137
+ log.setAttribute("aria-live", "polite");
138
+ const typing = el("div", "typing", "Typing\u2026");
139
+ const errorBar = el("div", "error");
140
+ errorBar.setAttribute("role", "alert");
141
+ const form = el("form");
142
+ const input = el("textarea");
143
+ input.rows = 1;
144
+ input.maxLength = 1e3;
145
+ input.placeholder = "Type your message";
146
+ input.setAttribute("aria-label", "Your message");
147
+ const sendBtn = el("button", "send", "Send");
148
+ sendBtn.type = "submit";
149
+ form.append(input, sendBtn);
150
+ const foot = el("div", "foot", "Powered by SeyalHub");
151
+ panel.append(head, log, errorBar, form, foot);
152
+ const launcher = el("button", "launcher");
153
+ launcher.type = "button";
154
+ launcher.setAttribute("aria-label", "Open chat");
155
+ launcher.setAttribute("aria-expanded", "false");
156
+ 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>';
157
+ const dot = el("span", "dot");
158
+ launcher.append(dot);
159
+ root.append(panel, launcher);
160
+ shadow.append(style, root);
161
+ function applyColor(color) {
162
+ if (color && COLOR.test(color)) root.style.setProperty("--c", color);
163
+ }
164
+ applyColor(options.color);
165
+ const scrollDown = () => {
166
+ log.scrollTop = log.scrollHeight;
167
+ };
168
+ function showError(message) {
169
+ errorBar.textContent = message != null ? message : "";
170
+ errorBar.classList.toggle("on", Boolean(message));
171
+ }
172
+ function setTyping(on) {
173
+ if (typingTimer) clearTimeout(typingTimer);
174
+ if (on) {
175
+ log.append(typing);
176
+ scrollDown();
177
+ typingTimer = setTimeout(() => typing.remove(), TYPING_TIMEOUT_MS);
178
+ } else typing.remove();
179
+ }
180
+ function bubble(text, kind) {
181
+ const b = el("div", kind === "note" ? "note" : `msg ${kind}`, text);
182
+ typing.remove();
183
+ log.append(b);
184
+ scrollDown();
185
+ return b;
186
+ }
187
+ function addServerLine(line) {
188
+ if (rendered.has(line.id)) return;
189
+ lastId = line.id > lastId ? line.id : lastId;
190
+ if (line.direction === "inbound") {
191
+ const mine = line.client_id ? pendingBubbles.get(line.client_id) : void 0;
192
+ if (mine) {
193
+ rendered.set(line.id, mine);
194
+ pendingBubbles.delete(line.client_id);
195
+ return;
196
+ }
197
+ rendered.set(line.id, bubble(line.text, "me"));
198
+ return;
199
+ }
200
+ rendered.set(line.id, bubble(line.text, "them"));
201
+ setTyping(false);
202
+ if (!isOpen) dot.classList.add("on");
203
+ }
204
+ async function api(path, init) {
205
+ var _a2;
206
+ return doFetch(`${base}${path}`, { ...init, headers: { "content-type": "application/json", ...(_a2 = init == null ? void 0 : init.headers) != null ? _a2 : {} } });
207
+ }
208
+ async function poll() {
209
+ var _a2;
210
+ if (destroyed) return;
211
+ let delay = isOpen ? (_a2 = options.pollMs) != null ? _a2 : 2e3 : BACKGROUND_POLL_MS;
212
+ try {
213
+ const qs = new URLSearchParams({ visitor_id: visitor });
214
+ if (lastId) qs.set("after", lastId);
215
+ const res = await api(`/messages?${qs}`);
216
+ if (res.ok) {
217
+ const body = await res.json();
218
+ body.messages.forEach(addServerLine);
219
+ subEl.textContent = body.human ? "You are chatting with our team" : "";
220
+ backoff = 0;
221
+ showError(null);
222
+ } else if (res.status === 403 || res.status === 404) {
223
+ return void destroy();
224
+ } else throw new Error(String(res.status));
225
+ } catch {
226
+ backoff = Math.min(MAX_BACKOFF_MS, (backoff || 1e3) * 2);
227
+ delay = Math.max(delay, backoff);
228
+ }
229
+ if (!destroyed && (isOpen || storage.getItem(keyStarted))) timer = setTimeout(() => void poll(), delay);
230
+ }
231
+ function restartPolling() {
232
+ if (timer) clearTimeout(timer);
233
+ void poll();
234
+ }
235
+ async function loadHistory() {
236
+ var _a2;
237
+ if (loadedHistory) return;
238
+ loadedHistory = true;
239
+ await poll();
240
+ if (rendered.size === 0) bubble((_a2 = options.greeting) != null ? _a2 : greeting, "them");
241
+ }
242
+ let greeting = "Hi! How can we help?";
243
+ async function send(text, clientId, node) {
244
+ node.classList.remove("failed");
245
+ try {
246
+ const res = await api("/messages", { method: "POST", body: JSON.stringify({ visitor_id: visitor, text, client_message_id: clientId }) });
247
+ if (res.status === 429) throw new Error("You are sending messages too fast. Please wait a moment.");
248
+ 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.");
249
+ storage.setItem(keyStarted, "1");
250
+ showError(null);
251
+ setTyping(true);
252
+ restartPolling();
253
+ } catch (err) {
254
+ node.classList.add("failed");
255
+ node.onclick = () => void send(text, clientId, node);
256
+ showError(err instanceof Error && err.message ? err.message : "Your message could not be sent. Tap it to try again.");
257
+ }
258
+ }
259
+ form.addEventListener("submit", (e) => {
260
+ e.preventDefault();
261
+ const text = input.value.trim();
262
+ if (!text) return;
263
+ input.value = "";
264
+ const clientId = `cm_${randomId(16)}`;
265
+ const node = bubble(text, "me");
266
+ pendingBubbles.set(clientId, node);
267
+ void send(text, clientId, node);
268
+ });
269
+ input.addEventListener("keydown", (e) => {
270
+ if (e.key === "Enter" && !e.shiftKey && !e.isComposing) {
271
+ e.preventDefault();
272
+ form.requestSubmit();
273
+ }
274
+ });
275
+ panel.addEventListener("keydown", (e) => {
276
+ if (e.key === "Escape") close();
277
+ });
278
+ function open() {
279
+ if (destroyed || isOpen) return;
280
+ isOpen = true;
281
+ panel.classList.add("open");
282
+ launcher.setAttribute("aria-expanded", "true");
283
+ launcher.setAttribute("aria-label", "Close chat");
284
+ dot.classList.remove("on");
285
+ void loadHistory().then(() => {
286
+ if (isOpen) restartPolling();
287
+ });
288
+ input.focus();
289
+ }
290
+ function close() {
291
+ if (!isOpen) return;
292
+ isOpen = false;
293
+ panel.classList.remove("open");
294
+ launcher.setAttribute("aria-expanded", "false");
295
+ launcher.setAttribute("aria-label", "Open chat");
296
+ launcher.focus();
297
+ }
298
+ function toggle() {
299
+ isOpen ? close() : open();
300
+ }
301
+ function destroy() {
302
+ destroyed = true;
303
+ if (timer) clearTimeout(timer);
304
+ if (typingTimer) clearTimeout(typingTimer);
305
+ host.remove();
306
+ }
307
+ launcher.addEventListener("click", toggle);
308
+ closeBtn.addEventListener("click", close);
309
+ void (async () => {
310
+ var _a2, _b2, _c2, _d;
311
+ try {
312
+ const res = await api("/config");
313
+ if (!res.ok) {
314
+ 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.`);
315
+ return void destroy();
316
+ }
317
+ const cfg = await res.json();
318
+ titleEl.textContent = (_a2 = options.title) != null ? _a2 : cfg.title;
319
+ greeting = (_b2 = options.greeting) != null ? _b2 : cfg.greeting;
320
+ applyColor((_c2 = options.color) != null ? _c2 : cfg.color);
321
+ } catch {
322
+ }
323
+ if (destroyed) return;
324
+ ((_d = options.container) != null ? _d : document.body).append(host);
325
+ if (storage.getItem(keyStarted)) void poll();
326
+ if (options.open) open();
327
+ })();
328
+ return { open, close, toggle, destroy };
329
+ }
330
+
331
+ // src/element.ts
332
+ var SeyalHubChatElement = class extends HTMLElement {
333
+ connectedCallback() {
334
+ this.start();
335
+ }
336
+ disconnectedCallback() {
337
+ this.stop();
338
+ }
339
+ attributeChangedCallback() {
340
+ if (this.isConnected) {
341
+ this.stop();
342
+ this.start();
343
+ }
344
+ }
345
+ /** Same object API as `createChatWidget`, for code that holds the element. */
346
+ open() {
347
+ var _a;
348
+ (_a = this.widget) == null ? void 0 : _a.open();
349
+ }
350
+ close() {
351
+ var _a;
352
+ (_a = this.widget) == null ? void 0 : _a.close();
353
+ }
354
+ start() {
355
+ var _a, _b, _c;
356
+ const siteKey = this.getAttribute("site-key");
357
+ const apiUrl = this.getAttribute("api-url");
358
+ if (!siteKey || !apiUrl) return;
359
+ this.widget = createChatWidget({
360
+ siteKey,
361
+ apiUrl,
362
+ title: (_a = this.getAttribute("title")) != null ? _a : void 0,
363
+ greeting: (_b = this.getAttribute("greeting")) != null ? _b : void 0,
364
+ color: (_c = this.getAttribute("color")) != null ? _c : void 0,
365
+ position: this.getAttribute("position") === "left" ? "left" : "right",
366
+ open: this.hasAttribute("open")
367
+ });
368
+ }
369
+ stop() {
370
+ var _a;
371
+ (_a = this.widget) == null ? void 0 : _a.destroy();
372
+ this.widget = void 0;
373
+ }
374
+ };
375
+ SeyalHubChatElement.observedAttributes = ["site-key", "api-url", "title", "greeting", "color", "position", "open"];
376
+ function defineChatElement() {
377
+ if (typeof customElements !== "undefined" && !customElements.get("seyalhub-chat")) customElements.define("seyalhub-chat", SeyalHubChatElement);
378
+ }
379
+ defineChatElement();
380
+ //# sourceMappingURL=element.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/element.ts", "../src/styles.ts", "../src/widget.ts"],
4
+ "sourcesContent": ["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", "/** 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;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCO,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;AACvB,IAAM,oBAAoB;AAE1B,SAAS,SAAS,QAAwB;AA5C1C;AA6CE,QAAM,QAAQ,IAAI,WAAW,MAAM;AACnC,GAAC,4BAAW,WAAX,YAAsB,CAAC,GAAc,oBAArC,4BAAuD;AACxD,MAAI,CAAC,MAAM,KAAK,CAAC,MAAM,MAAM,CAAC,EAAG,UAAS,IAAI,GAAG,IAAI,QAAQ,IAAK,OAAM,CAAC,IAAI,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG;AAC3G,SAAO,MAAM,KAAK,OAAO,CAAC,MAAM,SAAS,IAAI,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE;AACxE;AAEA,SAAS,YAAY,QAAuE;AAC1F,QAAM,SAAS,oBAAI,IAAoB;AACvC,QAAM,WAAW,EAAE,SAAS,CAAC,MAAW;AArD1C;AAqD6C,wBAAO,IAAI,CAAC,MAAZ,YAAiB;AAAA,KAAM,SAAS,CAAC,GAAW,MAAc,KAAK,OAAO,IAAI,GAAG,CAAC,EAAE;AAC3H,MAAI;AACF,UAAM,IAAI,0BAAU,OAAO;AAC3B,MAAE,QAAQ,kBA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iB,mBAAmB;AAC/I;AAEA,kBAAkB;",
6
+ "names": ["_a", "_b", "_c"]
7
+ }
@@ -0,0 +1,14 @@
1
+ /** `<seyalhub-chat site-key="wc_..." api-url="https://api.example.com"></seyalhub-chat>`: works in plain HTML, Angular, Vue, Svelte, anywhere. */
2
+ export declare class SeyalHubChatElement extends HTMLElement {
3
+ static observedAttributes: string[];
4
+ private widget?;
5
+ connectedCallback(): void;
6
+ disconnectedCallback(): void;
7
+ attributeChangedCallback(): void;
8
+ /** Same object API as `createChatWidget`, for code that holds the element. */
9
+ open(): void;
10
+ close(): void;
11
+ private start;
12
+ private stop;
13
+ }
14
+ export declare function defineChatElement(): void;