@ahoy-ai/web 0.0.0-stage → 0.1.1
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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +91 -2
- package/dist/ahoy.js +2 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/loader/ahoy.d.ts +166 -0
- package/dist/esm/loader/ahoy.d.ts.map +1 -0
- package/dist/esm/loader/ahoy.js +513 -0
- package/dist/esm/loader/ahoy.js.map +1 -0
- package/dist/esm/loader/global.d.ts +12 -0
- package/dist/esm/loader/global.d.ts.map +1 -0
- package/dist/esm/loader/global.js +65 -0
- package/dist/esm/loader/global.js.map +1 -0
- package/dist/esm/loader/launcher.d.ts +34 -0
- package/dist/esm/loader/launcher.d.ts.map +1 -0
- package/dist/esm/loader/launcher.js +135 -0
- package/dist/esm/loader/launcher.js.map +1 -0
- package/dist/esm/loader/navigation.d.ts +2 -0
- package/dist/esm/loader/navigation.d.ts.map +1 -0
- package/dist/esm/loader/navigation.js +37 -0
- package/dist/esm/loader/navigation.js.map +1 -0
- package/dist/esm/loader/style.d.ts +9 -0
- package/dist/esm/loader/style.d.ts.map +1 -0
- package/dist/esm/loader/style.js +13 -0
- package/dist/esm/loader/style.js.map +1 -0
- package/dist/esm/protocol.d.ts +120 -0
- package/dist/esm/protocol.d.ts.map +1 -0
- package/dist/esm/protocol.js +58 -0
- package/dist/esm/protocol.js.map +1 -0
- package/dist/esm/version.d.ts +3 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +68 -3
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { PANEL_TYPES, PROTOCOL, envelope, originOf, readMessage, } from '../protocol.js';
|
|
2
|
+
import { Launcher } from './launcher.js';
|
|
3
|
+
import { watchNavigation } from './navigation.js';
|
|
4
|
+
import { Z_INDEX, css } from './style.js';
|
|
5
|
+
/**
|
|
6
|
+
* Where the panel is served when nothing else says (the npm route, `@ahoy-ai/react`): production.
|
|
7
|
+
* Local and dev setups pass `cdnUrl` (CONTRACT C11).
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_CDN_URL = 'https://cdn.ahoysupport.com';
|
|
10
|
+
/** The panel of this loader's major (ADR 0017: loader and panel always match on `/v1/`). */
|
|
11
|
+
export const FRAME_PATH = '/web/v1/frame.html';
|
|
12
|
+
const APP_ID = /^app_[A-Za-z0-9]+$/;
|
|
13
|
+
/** Desktop panel size and the width under which the panel covers the viewport (ADR 0017). */
|
|
14
|
+
const PANEL_WIDTH = 400;
|
|
15
|
+
const PANEL_HEIGHT = 700;
|
|
16
|
+
const EDGE = 20;
|
|
17
|
+
/** The launcher's bottom offset range (px), as the published design allows. */
|
|
18
|
+
const MAX_BOTTOM_OFFSET = 200;
|
|
19
|
+
export const FULL_SCREEN_BELOW = 640;
|
|
20
|
+
/** Without `ready` this long after the frame loaded, the panel is probably blocked. */
|
|
21
|
+
const READY_TIMEOUT_MS = 10_000;
|
|
22
|
+
/** How often `configure` is sent again until `ready`. */
|
|
23
|
+
const HANDSHAKE_MS = 500;
|
|
24
|
+
let frameCounter = 0;
|
|
25
|
+
/** The loader behind `window.Ahoy`: launcher, iframe, postMessage and the queue. */
|
|
26
|
+
export class AhoyLoader {
|
|
27
|
+
env;
|
|
28
|
+
scriptSrc;
|
|
29
|
+
options = null;
|
|
30
|
+
frameUrl = '';
|
|
31
|
+
frameOrigin = '';
|
|
32
|
+
iframe = null;
|
|
33
|
+
launcher = null;
|
|
34
|
+
state = { ready: false, open: false, unread: 0 };
|
|
35
|
+
listeners = new Set();
|
|
36
|
+
subscribers = new Set();
|
|
37
|
+
queue = [];
|
|
38
|
+
wantOpen = false;
|
|
39
|
+
mode = 'panel';
|
|
40
|
+
panelHeight = PANEL_HEIGHT;
|
|
41
|
+
/** The launcher's place, from the panel's `ready` (site option, else published design). */
|
|
42
|
+
position = 'right';
|
|
43
|
+
bottomOffset = EDGE;
|
|
44
|
+
title = 'Support';
|
|
45
|
+
currentAppearance = {};
|
|
46
|
+
cleanups = [];
|
|
47
|
+
idleHandle = null;
|
|
48
|
+
returnFocus = null;
|
|
49
|
+
/** The panel stopped for good (`stopped`): no launcher, nothing sent, until a reload. */
|
|
50
|
+
stopped = false;
|
|
51
|
+
warned = new Set();
|
|
52
|
+
frameId = `ahoy-frame-${++frameCounter}`;
|
|
53
|
+
constructor(env = { window, document },
|
|
54
|
+
/** The script tag's `src`: the panel comes from the same CDN. */
|
|
55
|
+
scriptSrc = null) {
|
|
56
|
+
this.env = env;
|
|
57
|
+
this.scriptSrc = scriptSrc;
|
|
58
|
+
}
|
|
59
|
+
configure(options) {
|
|
60
|
+
if (!options || typeof options.appId !== 'string' || !APP_ID.test(options.appId)) {
|
|
61
|
+
console.error('[Ahoy] configure: appId must look like "app_XXXX".');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const previous = this.options;
|
|
65
|
+
this.options = { ...options };
|
|
66
|
+
if (options.appearance)
|
|
67
|
+
this.currentAppearance = { ...options.appearance };
|
|
68
|
+
const frameUrl = this.resolveFrameUrl(options);
|
|
69
|
+
if (previous &&
|
|
70
|
+
previous.appId === options.appId &&
|
|
71
|
+
previous.apiUrl === options.apiUrl &&
|
|
72
|
+
frameUrl === this.frameUrl &&
|
|
73
|
+
(this.iframe || this.idleHandle)) {
|
|
74
|
+
// Same app: forward the new settings without reloading the panel; its `ready` answers
|
|
75
|
+
// with the launcher's place.
|
|
76
|
+
this.applyLauncherVisibility();
|
|
77
|
+
if (this.state.ready)
|
|
78
|
+
this.sendConfigure();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Calls queued before the first configure (the snippet's stub, `identify` before mount) stay.
|
|
82
|
+
this.teardown(previous === null);
|
|
83
|
+
this.frameUrl = frameUrl;
|
|
84
|
+
this.frameOrigin = originOf(frameUrl) ?? '';
|
|
85
|
+
const onMessage = (event) => this.onMessage(event);
|
|
86
|
+
this.env.window.addEventListener('message', onMessage);
|
|
87
|
+
const onResize = () => this.layout();
|
|
88
|
+
this.env.window.addEventListener('resize', onResize);
|
|
89
|
+
this.cleanups.push(() => this.env.window.removeEventListener('message', onMessage), () => this.env.window.removeEventListener('resize', onResize));
|
|
90
|
+
// Hidden at page idle, so the unread badge is right before the first open (ADR 0017).
|
|
91
|
+
if (this.wantOpen)
|
|
92
|
+
this.mount();
|
|
93
|
+
else
|
|
94
|
+
this.idleHandle = whenIdle(this.env.window, () => this.mount());
|
|
95
|
+
}
|
|
96
|
+
identify(identity) {
|
|
97
|
+
this.send({ type: 'identify', payload: [identity] });
|
|
98
|
+
return Promise.resolve();
|
|
99
|
+
}
|
|
100
|
+
setMetadata(metadata, options) {
|
|
101
|
+
this.send({ type: 'setMetadata', payload: options ? [metadata, options] : [metadata] });
|
|
102
|
+
return Promise.resolve();
|
|
103
|
+
}
|
|
104
|
+
track(name, propsOrOptions, options) {
|
|
105
|
+
const args = [name];
|
|
106
|
+
if (propsOrOptions !== undefined || options !== undefined)
|
|
107
|
+
args.push(propsOrOptions);
|
|
108
|
+
if (options !== undefined)
|
|
109
|
+
args.push(options);
|
|
110
|
+
this.send({ type: 'track', payload: args });
|
|
111
|
+
}
|
|
112
|
+
open() {
|
|
113
|
+
if (this.stopped)
|
|
114
|
+
return;
|
|
115
|
+
this.wantOpen = true;
|
|
116
|
+
if (!this.options)
|
|
117
|
+
return;
|
|
118
|
+
if (!this.iframe)
|
|
119
|
+
this.mount();
|
|
120
|
+
if (this.state.ready)
|
|
121
|
+
this.post({ type: 'open' });
|
|
122
|
+
}
|
|
123
|
+
close() {
|
|
124
|
+
this.wantOpen = false;
|
|
125
|
+
if (this.state.ready)
|
|
126
|
+
this.post({ type: 'close' });
|
|
127
|
+
}
|
|
128
|
+
onEvent(listener) {
|
|
129
|
+
this.listeners.add(listener);
|
|
130
|
+
return () => {
|
|
131
|
+
this.listeners.delete(listener);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
logout() {
|
|
135
|
+
this.send({ type: 'logout' });
|
|
136
|
+
return Promise.resolve();
|
|
137
|
+
}
|
|
138
|
+
deleteData() {
|
|
139
|
+
this.send({ type: 'deleteData' });
|
|
140
|
+
return Promise.resolve();
|
|
141
|
+
}
|
|
142
|
+
get appearance() {
|
|
143
|
+
return this.currentAppearance;
|
|
144
|
+
}
|
|
145
|
+
set appearance(value) {
|
|
146
|
+
this.currentAppearance = { ...(value ?? {}) };
|
|
147
|
+
if (this.options)
|
|
148
|
+
this.options.appearance = this.currentAppearance;
|
|
149
|
+
if (this.state.ready)
|
|
150
|
+
this.sendConfigure();
|
|
151
|
+
}
|
|
152
|
+
runSetupCheck() {
|
|
153
|
+
this.send({ type: 'runSetupCheck' });
|
|
154
|
+
return Promise.resolve();
|
|
155
|
+
}
|
|
156
|
+
registerPush() {
|
|
157
|
+
this.warnOnce('registerPush', '[Ahoy] registerPush: push is not available on web yet.');
|
|
158
|
+
return Promise.resolve({ registered: false, reason: 'unsupported' });
|
|
159
|
+
}
|
|
160
|
+
notificationBehavior() {
|
|
161
|
+
this.warnOnce('notificationBehavior', '[Ahoy] notificationBehavior: not available on web.');
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
onOffer(handler) {
|
|
165
|
+
void handler;
|
|
166
|
+
this.warnOnce('onOffer', '[Ahoy] onOffer: offer cards are not shown on web.');
|
|
167
|
+
return () => { };
|
|
168
|
+
}
|
|
169
|
+
setPaywalls(paywalls) {
|
|
170
|
+
void paywalls;
|
|
171
|
+
this.warnOnce('setPaywalls', '[Ahoy] setPaywalls: paywall offers are not shown on web.');
|
|
172
|
+
}
|
|
173
|
+
getState() {
|
|
174
|
+
return this.state;
|
|
175
|
+
}
|
|
176
|
+
subscribe(listener) {
|
|
177
|
+
this.subscribers.add(listener);
|
|
178
|
+
return () => {
|
|
179
|
+
this.subscribers.delete(listener);
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
destroy() {
|
|
183
|
+
this.teardown();
|
|
184
|
+
this.options = null;
|
|
185
|
+
this.wantOpen = false;
|
|
186
|
+
}
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
resolveFrameUrl(options) {
|
|
189
|
+
// `cdnUrl`, else the CDN this ahoy.js was built for, else the host it was loaded from.
|
|
190
|
+
const built = typeof __AHOY_CDN_URL__ === 'string' && __AHOY_CDN_URL__ ? __AHOY_CDN_URL__ : null;
|
|
191
|
+
const base = options.cdnUrl ?? built ?? originOf(this.scriptSrc) ?? DEFAULT_CDN_URL;
|
|
192
|
+
return `${base.replace(/\/+$/, '')}${FRAME_PATH}`;
|
|
193
|
+
}
|
|
194
|
+
mount() {
|
|
195
|
+
this.idleHandle?.();
|
|
196
|
+
this.idleHandle = null;
|
|
197
|
+
if (this.iframe || !this.options)
|
|
198
|
+
return;
|
|
199
|
+
const doc = this.env.document;
|
|
200
|
+
const iframe = doc.createElement('iframe');
|
|
201
|
+
iframe.id = this.frameId;
|
|
202
|
+
iframe.title = this.title;
|
|
203
|
+
iframe.src = this.frameUrl;
|
|
204
|
+
// The panel reads the host origin from the referrer even when the site sends none.
|
|
205
|
+
iframe.referrerPolicy = 'origin';
|
|
206
|
+
iframe.setAttribute('allow', 'clipboard-write');
|
|
207
|
+
iframe.setAttribute('data-ahoy', 'panel');
|
|
208
|
+
css(iframe, {
|
|
209
|
+
position: 'fixed',
|
|
210
|
+
border: '0',
|
|
211
|
+
margin: '0',
|
|
212
|
+
padding: '0',
|
|
213
|
+
'z-index': String(Z_INDEX + 1),
|
|
214
|
+
background: 'transparent',
|
|
215
|
+
'color-scheme': 'normal',
|
|
216
|
+
'max-width': '100vw',
|
|
217
|
+
display: 'none',
|
|
218
|
+
});
|
|
219
|
+
// `configure` until the panel answers `ready`: a load event can belong to the iframe's initial
|
|
220
|
+
// about:blank (Firefox, while the page is still loading), and a message to it is dropped.
|
|
221
|
+
// The panel treats a repeated configure for the same app as a no-op.
|
|
222
|
+
const startedAt = Date.now();
|
|
223
|
+
const handshake = setInterval(() => {
|
|
224
|
+
if (this.state.ready || this.stopped) {
|
|
225
|
+
clearInterval(handshake);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (Date.now() - startedAt > READY_TIMEOUT_MS) {
|
|
229
|
+
clearInterval(handshake);
|
|
230
|
+
this.warnOnce('not_ready', `[Ahoy] The chat panel (${this.frameUrl}) did not start. A Content-Security-Policy ` +
|
|
231
|
+
`without frame-src ${this.frameOrigin}, an ad blocker or a network error can cause this.`);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
this.sendConfigure();
|
|
235
|
+
}, HANDSHAKE_MS);
|
|
236
|
+
iframe.addEventListener('load', () => {
|
|
237
|
+
if (!this.state.ready && !this.stopped)
|
|
238
|
+
this.sendConfigure();
|
|
239
|
+
});
|
|
240
|
+
(doc.body ?? doc.documentElement).appendChild(iframe);
|
|
241
|
+
this.iframe = iframe;
|
|
242
|
+
this.cleanups.push(() => {
|
|
243
|
+
iframe.remove();
|
|
244
|
+
clearInterval(handshake);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
sendConfigure() {
|
|
248
|
+
const options = this.options;
|
|
249
|
+
if (!options)
|
|
250
|
+
return;
|
|
251
|
+
const doc = this.env.document;
|
|
252
|
+
this.postNow({
|
|
253
|
+
type: 'configure',
|
|
254
|
+
payload: {
|
|
255
|
+
appId: options.appId,
|
|
256
|
+
environment: options.environment === 'development' ? 'development' : 'production',
|
|
257
|
+
hostOrigin: this.env.window.location.origin,
|
|
258
|
+
language: options.language,
|
|
259
|
+
pageLanguage: doc.documentElement.lang || undefined,
|
|
260
|
+
appearance: this.currentAppearance,
|
|
261
|
+
apiUrl: options.apiUrl,
|
|
262
|
+
position: options.position === 'left' || options.position === 'right'
|
|
263
|
+
? options.position
|
|
264
|
+
: undefined,
|
|
265
|
+
protocol: PROTOCOL,
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
onMessage(event) {
|
|
270
|
+
if (!this.iframe || event.source !== this.iframe.contentWindow)
|
|
271
|
+
return;
|
|
272
|
+
if (event.origin !== this.frameOrigin)
|
|
273
|
+
return;
|
|
274
|
+
const message = readMessage(event.data, PANEL_TYPES);
|
|
275
|
+
if (!message)
|
|
276
|
+
return;
|
|
277
|
+
switch (message.type) {
|
|
278
|
+
case 'ready':
|
|
279
|
+
return this.onReady(message.payload);
|
|
280
|
+
case 'unread':
|
|
281
|
+
return this.setState({ unread: Math.max(0, Number(message.payload?.count) || 0) });
|
|
282
|
+
case 'resize':
|
|
283
|
+
this.mode = message.payload?.mode === 'full' ? 'full' : 'panel';
|
|
284
|
+
if (typeof message.payload?.height === 'number' && message.payload.height > 0) {
|
|
285
|
+
this.panelHeight = Math.min(PANEL_HEIGHT, message.payload.height);
|
|
286
|
+
}
|
|
287
|
+
return this.layout();
|
|
288
|
+
case 'event':
|
|
289
|
+
return this.dispatch(message.payload);
|
|
290
|
+
case 'opened':
|
|
291
|
+
return this.onOpened();
|
|
292
|
+
case 'closed':
|
|
293
|
+
return this.onClosed();
|
|
294
|
+
case 'stopped':
|
|
295
|
+
return this.onStopped();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* The panel refused to run (its console line says why): the launcher goes, the frame stays
|
|
300
|
+
* hidden and loaded so `open()` doesn't start it again, and later calls are dropped.
|
|
301
|
+
*/
|
|
302
|
+
onStopped() {
|
|
303
|
+
this.stopped = true;
|
|
304
|
+
this.queue = [];
|
|
305
|
+
this.wantOpen = false;
|
|
306
|
+
this.launcher?.remove();
|
|
307
|
+
this.launcher = null;
|
|
308
|
+
this.setState({ ready: false, open: false, unread: 0 });
|
|
309
|
+
this.layout();
|
|
310
|
+
}
|
|
311
|
+
onReady(payload) {
|
|
312
|
+
if (typeof payload?.title === 'string' && payload.title)
|
|
313
|
+
this.title = payload.title;
|
|
314
|
+
if (payload?.position === 'left' || payload?.position === 'right') {
|
|
315
|
+
this.position = payload.position;
|
|
316
|
+
}
|
|
317
|
+
if (typeof payload?.bottomOffset === 'number' && Number.isFinite(payload.bottomOffset)) {
|
|
318
|
+
this.bottomOffset = Math.min(MAX_BOTTOM_OFFSET, Math.max(0, Math.round(payload.bottomOffset)));
|
|
319
|
+
}
|
|
320
|
+
const accent = typeof payload?.accent === 'string' ? payload.accent : '#0A6FD8';
|
|
321
|
+
if (this.iframe)
|
|
322
|
+
this.iframe.title = this.title;
|
|
323
|
+
if (this.options?.launcher !== false) {
|
|
324
|
+
if (!this.launcher) {
|
|
325
|
+
this.launcher = new Launcher(this.env.document, {
|
|
326
|
+
position: this.position,
|
|
327
|
+
bottomOffset: this.bottomOffset,
|
|
328
|
+
accent,
|
|
329
|
+
label: this.title,
|
|
330
|
+
controls: this.frameId,
|
|
331
|
+
onClick: () => this.open(),
|
|
332
|
+
});
|
|
333
|
+
(this.env.document.body ?? this.env.document.documentElement).appendChild(this.launcher.host);
|
|
334
|
+
const launcher = this.launcher;
|
|
335
|
+
this.cleanups.push(() => launcher.remove());
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
this.launcher.setAccent(accent);
|
|
339
|
+
this.launcher.setPosition(this.position, this.bottomOffset);
|
|
340
|
+
this.launcher.setLabel(this.title);
|
|
341
|
+
}
|
|
342
|
+
this.launcher.setUnread(this.state.unread);
|
|
343
|
+
}
|
|
344
|
+
const firstReady = !this.state.ready;
|
|
345
|
+
this.setState({ ready: true });
|
|
346
|
+
this.applyLauncherVisibility();
|
|
347
|
+
this.layout();
|
|
348
|
+
if (!firstReady)
|
|
349
|
+
return;
|
|
350
|
+
const queued = this.queue;
|
|
351
|
+
this.queue = [];
|
|
352
|
+
for (const message of queued)
|
|
353
|
+
this.post(message);
|
|
354
|
+
this.cleanups.push(watchNavigation(this.env.window, (path) => this.post({ type: 'page', payload: { path } })));
|
|
355
|
+
if (this.wantOpen)
|
|
356
|
+
this.post({ type: 'open' });
|
|
357
|
+
}
|
|
358
|
+
onOpened() {
|
|
359
|
+
const active = this.env.document.activeElement;
|
|
360
|
+
this.returnFocus = active instanceof HTMLElement && active !== this.iframe ? active : null;
|
|
361
|
+
this.wantOpen = true;
|
|
362
|
+
this.setState({ open: true });
|
|
363
|
+
this.launcher?.setExpanded(true);
|
|
364
|
+
this.applyLauncherVisibility();
|
|
365
|
+
this.layout();
|
|
366
|
+
// Focus moves into the dialog; the panel then focuses its composer.
|
|
367
|
+
this.iframe?.focus();
|
|
368
|
+
}
|
|
369
|
+
onClosed() {
|
|
370
|
+
this.wantOpen = false;
|
|
371
|
+
this.mode = 'panel';
|
|
372
|
+
this.setState({ open: false });
|
|
373
|
+
this.launcher?.setExpanded(false);
|
|
374
|
+
this.applyLauncherVisibility();
|
|
375
|
+
this.layout();
|
|
376
|
+
// Focus goes back to the launcher (or what had it before the chat opened).
|
|
377
|
+
const target = this.launcher ? null : this.returnFocus;
|
|
378
|
+
if (this.launcher)
|
|
379
|
+
this.launcher.focus();
|
|
380
|
+
else if (target?.isConnected)
|
|
381
|
+
target.focus();
|
|
382
|
+
this.returnFocus = null;
|
|
383
|
+
}
|
|
384
|
+
applyLauncherVisibility() {
|
|
385
|
+
if (!this.launcher)
|
|
386
|
+
return;
|
|
387
|
+
const show = this.options?.launcher !== false && this.state.ready && !this.state.open;
|
|
388
|
+
this.launcher.setVisible(show);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Sizes the iframe: the panel (400 × 700, 20 px from the side, as high above the bottom as the
|
|
392
|
+
* launcher) or the whole viewport.
|
|
393
|
+
*/
|
|
394
|
+
layout() {
|
|
395
|
+
const iframe = this.iframe;
|
|
396
|
+
if (!iframe)
|
|
397
|
+
return;
|
|
398
|
+
if (!this.state.open) {
|
|
399
|
+
css(iframe, { display: 'none' });
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const win = this.env.window;
|
|
403
|
+
const full = this.mode === 'full' || win.innerWidth < FULL_SCREEN_BELOW;
|
|
404
|
+
iframe.setAttribute('data-mode', full ? 'full' : 'panel');
|
|
405
|
+
if (full) {
|
|
406
|
+
css(iframe, {
|
|
407
|
+
display: 'block',
|
|
408
|
+
top: '0',
|
|
409
|
+
left: '0',
|
|
410
|
+
right: 'auto',
|
|
411
|
+
bottom: 'auto',
|
|
412
|
+
width: '100%',
|
|
413
|
+
height: '100%',
|
|
414
|
+
'border-radius': '0',
|
|
415
|
+
'box-shadow': 'none',
|
|
416
|
+
});
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const height = Math.max(320, Math.min(this.panelHeight, win.innerHeight - this.bottomOffset - EDGE));
|
|
420
|
+
css(iframe, {
|
|
421
|
+
display: 'block',
|
|
422
|
+
top: 'auto',
|
|
423
|
+
bottom: `${this.bottomOffset}px`,
|
|
424
|
+
left: this.position === 'left' ? `${EDGE}px` : 'auto',
|
|
425
|
+
right: this.position === 'left' ? 'auto' : `${EDGE}px`,
|
|
426
|
+
width: `${PANEL_WIDTH}px`,
|
|
427
|
+
height: `${height}px`,
|
|
428
|
+
'border-radius': '16px',
|
|
429
|
+
'box-shadow': '0 12px 48px rgba(15, 23, 42, 0.28)',
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
send(message) {
|
|
433
|
+
if (this.stopped)
|
|
434
|
+
return;
|
|
435
|
+
if (this.state.ready)
|
|
436
|
+
this.post(message);
|
|
437
|
+
else
|
|
438
|
+
this.queue.push(message);
|
|
439
|
+
}
|
|
440
|
+
post(message) {
|
|
441
|
+
this.postNow(message);
|
|
442
|
+
}
|
|
443
|
+
postNow(message) {
|
|
444
|
+
const target = this.iframe?.contentWindow;
|
|
445
|
+
if (!target || !this.frameOrigin)
|
|
446
|
+
return;
|
|
447
|
+
try {
|
|
448
|
+
target.postMessage(envelope(message), this.frameOrigin);
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
// The frame is gone or navigating; the handshake or the next call sends again.
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
dispatch(event) {
|
|
455
|
+
if (!event || typeof event.type !== 'string')
|
|
456
|
+
return;
|
|
457
|
+
for (const listener of [...this.listeners]) {
|
|
458
|
+
try {
|
|
459
|
+
listener(event);
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
console.warn('[Ahoy] onEvent listener threw', error);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
setState(patch) {
|
|
467
|
+
const next = { ...this.state, ...patch };
|
|
468
|
+
if (next.ready === this.state.ready &&
|
|
469
|
+
next.open === this.state.open &&
|
|
470
|
+
next.unread === this.state.unread) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
this.state = next;
|
|
474
|
+
this.launcher?.setUnread(next.unread);
|
|
475
|
+
for (const listener of [...this.subscribers])
|
|
476
|
+
listener();
|
|
477
|
+
}
|
|
478
|
+
warnOnce(key, message) {
|
|
479
|
+
if (this.options?.environment !== 'development' || this.warned.has(key))
|
|
480
|
+
return;
|
|
481
|
+
this.warned.add(key);
|
|
482
|
+
console.warn(message);
|
|
483
|
+
}
|
|
484
|
+
teardown(keepQueue = false) {
|
|
485
|
+
this.idleHandle?.();
|
|
486
|
+
this.idleHandle = null;
|
|
487
|
+
for (const cleanup of this.cleanups.splice(0))
|
|
488
|
+
cleanup();
|
|
489
|
+
this.iframe = null;
|
|
490
|
+
this.launcher = null;
|
|
491
|
+
this.stopped = false;
|
|
492
|
+
this.mode = 'panel';
|
|
493
|
+
if (!keepQueue)
|
|
494
|
+
this.queue = [];
|
|
495
|
+
this.setState({ ready: false, open: false, unread: 0 });
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/** Runs `run` when the page is idle (or soon, where `requestIdleCallback` is missing). */
|
|
499
|
+
function whenIdle(win, run) {
|
|
500
|
+
const ric = win
|
|
501
|
+
.requestIdleCallback;
|
|
502
|
+
if (typeof ric === 'function') {
|
|
503
|
+
const handle = ric.call(win, run, { timeout: 3_000 });
|
|
504
|
+
return () => win.cancelIdleCallback?.(handle);
|
|
505
|
+
}
|
|
506
|
+
const timer = setTimeout(run, 200);
|
|
507
|
+
return () => clearTimeout(timer);
|
|
508
|
+
}
|
|
509
|
+
/** A new loader for this page (the npm route; the script tag uses `install`). */
|
|
510
|
+
export function createAhoy() {
|
|
511
|
+
return new AhoyLoader();
|
|
512
|
+
}
|
|
513
|
+
//# sourceMappingURL=ahoy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ahoy.js","sourceRoot":"","sources":["../../../src/loader/ahoy.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,WAAW,GAMZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAE1C;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,6BAA6B,CAAC;AAG7D,4FAA4F;AAC5F,MAAM,CAAC,MAAM,UAAU,GAAG,oBAAoB,CAAC;AAE/C,MAAM,MAAM,GAAG,oBAAoB,CAAC;AACpC,6FAA6F;AAC7F,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,IAAI,GAAG,EAAE,CAAC;AAChB,+EAA+E;AAC/E,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AACrC,uFAAuF;AACvF,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,yDAAyD;AACzD,MAAM,YAAY,GAAG,GAAG,CAAC;AAmFzB,IAAI,YAAY,GAAG,CAAC,CAAC;AAErB,oFA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,GAAW,EAAE,GAAe;IAC5C,MAAM,GAAG,GAAI,GAAwE;SAClF,mBAAmB,CAAC;IACvB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QACtD,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IACD,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnC,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,UAAU;IACxB,OAAO,IAAI,UAAU,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type AhoyWeb, type AhoyWebOptions } from './ahoy.js';
|
|
2
|
+
/**
|
|
3
|
+
* The page's `window.Ahoy`: the loader already there (a script tag, or an earlier call), or a new
|
|
4
|
+
* one that replaces the snippet's queue stub, is configured with `options` (the script tag's
|
|
5
|
+
* attributes) and then replays the stub's calls in order, so they reach the configured app.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getAhoy(win?: Window, scriptSrc?: string | null, options?: AhoyWebOptions | null): AhoyWeb;
|
|
8
|
+
/** Replays `[name, arguments]` entries from the stub; unknown names are ignored. */
|
|
9
|
+
export declare function replay(ahoy: AhoyWeb, queue: readonly unknown[]): void;
|
|
10
|
+
/** `data-*` attributes of the script tag as configure options, or null without `data-app-id`. */
|
|
11
|
+
export declare function optionsFromScript(script: HTMLOrSVGScriptElement | null): AhoyWebOptions | null;
|
|
12
|
+
//# sourceMappingURL=global.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../../src/loader/global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAe1E;;;;GAIG;AACH,wBAAgB,OAAO,CACrB,GAAG,GAAE,MAAe,EACpB,SAAS,GAAE,MAAM,GAAG,IAAW,EAC/B,OAAO,GAAE,cAAc,GAAG,IAAW,GACpC,OAAO,CAUT;AAED,oFAAoF;AACpF,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI,CAarE;AAED,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI,GAAG,cAAc,GAAG,IAAI,CAiB9F"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AhoyLoader } from './ahoy.js';
|
|
2
|
+
function isLoader(value) {
|
|
3
|
+
return (value instanceof AhoyLoader || (!!value && typeof value.subscribe === 'function'));
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The page's `window.Ahoy`: the loader already there (a script tag, or an earlier call), or a new
|
|
7
|
+
* one that replaces the snippet's queue stub, is configured with `options` (the script tag's
|
|
8
|
+
* attributes) and then replays the stub's calls in order, so they reach the configured app.
|
|
9
|
+
*/
|
|
10
|
+
export function getAhoy(win = window, scriptSrc = null, options = null) {
|
|
11
|
+
const g = win;
|
|
12
|
+
const existing = g.Ahoy;
|
|
13
|
+
if (isLoader(existing))
|
|
14
|
+
return existing;
|
|
15
|
+
const ahoy = new AhoyLoader({ window: win, document: win.document }, scriptSrc);
|
|
16
|
+
g.Ahoy = ahoy;
|
|
17
|
+
if (options)
|
|
18
|
+
ahoy.configure(options);
|
|
19
|
+
const stub = existing;
|
|
20
|
+
replay(ahoy, stub && Array.isArray(stub.q) ? stub.q : []);
|
|
21
|
+
return ahoy;
|
|
22
|
+
}
|
|
23
|
+
/** Replays `[name, arguments]` entries from the stub; unknown names are ignored. */
|
|
24
|
+
export function replay(ahoy, queue) {
|
|
25
|
+
for (const entry of queue) {
|
|
26
|
+
if (!Array.isArray(entry) || typeof entry[0] !== 'string')
|
|
27
|
+
continue;
|
|
28
|
+
const method = ahoy[entry[0]];
|
|
29
|
+
if (typeof method !== 'function')
|
|
30
|
+
continue;
|
|
31
|
+
const args = entry[1] && typeof entry[1] === 'object' ? Array.from(entry[1]) : [];
|
|
32
|
+
try {
|
|
33
|
+
method.apply(ahoy, args);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.warn(`[Ahoy] Ahoy.${entry[0]} from the snippet failed`, error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** `data-*` attributes of the script tag as configure options, or null without `data-app-id`. */
|
|
41
|
+
export function optionsFromScript(script) {
|
|
42
|
+
if (!script)
|
|
43
|
+
return null;
|
|
44
|
+
const data = (name) => script.getAttribute(`data-${name}`) ?? undefined;
|
|
45
|
+
const appId = data('app-id');
|
|
46
|
+
if (!appId)
|
|
47
|
+
return null;
|
|
48
|
+
const options = { appId };
|
|
49
|
+
const environment = data('environment');
|
|
50
|
+
if (environment === 'development' || environment === 'production')
|
|
51
|
+
options.environment = environment;
|
|
52
|
+
const apiUrl = data('api-url');
|
|
53
|
+
if (apiUrl)
|
|
54
|
+
options.apiUrl = apiUrl;
|
|
55
|
+
const language = data('language');
|
|
56
|
+
if (language)
|
|
57
|
+
options.language = language;
|
|
58
|
+
if (data('launcher') === 'false')
|
|
59
|
+
options.launcher = false;
|
|
60
|
+
const position = data('position');
|
|
61
|
+
if (position === 'left' || position === 'right')
|
|
62
|
+
options.position = position;
|
|
63
|
+
return options;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../../src/loader/global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqC,MAAM,WAAW,CAAC;AAS1E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AI,IAAI,CAAC,UAAU,CAAC,KAAK,OAAO;QAAE,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC;IAC3D,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,OAAO;QAAE,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7E,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LauncherPosition } from '../protocol.js';
|
|
2
|
+
export interface LauncherOptions {
|
|
3
|
+
position: LauncherPosition;
|
|
4
|
+
/** Distance from the bottom of the window, px. */
|
|
5
|
+
bottomOffset: number;
|
|
6
|
+
accent: string;
|
|
7
|
+
label: string;
|
|
8
|
+
/** The panel's id, for `aria-controls`. */
|
|
9
|
+
controls: string;
|
|
10
|
+
onClick: () => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The round accent button with a chat icon and an unread badge (ADR 0017 D4), in a shadow
|
|
14
|
+
* root so the site's CSS can't reach it.
|
|
15
|
+
*/
|
|
16
|
+
export declare class Launcher {
|
|
17
|
+
private readonly doc;
|
|
18
|
+
readonly host: HTMLElement;
|
|
19
|
+
readonly button: HTMLButtonElement;
|
|
20
|
+
private readonly badge;
|
|
21
|
+
private label;
|
|
22
|
+
private unread;
|
|
23
|
+
constructor(doc: Document, options: LauncherOptions);
|
|
24
|
+
setPosition(position: LauncherPosition, bottomOffset: number): void;
|
|
25
|
+
setAccent(accent: string): void;
|
|
26
|
+
setLabel(label: string): void;
|
|
27
|
+
setUnread(count: number): void;
|
|
28
|
+
setExpanded(expanded: boolean): void;
|
|
29
|
+
setVisible(visible: boolean): void;
|
|
30
|
+
focus(): void;
|
|
31
|
+
remove(): void;
|
|
32
|
+
private render;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=launcher.d.ts.map
|