@oxvo/ai-live-assist 7.3.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/LICENSE +21 -0
- package/README.md +17 -0
- package/cjs/AiLiveAssist.d.ts +108 -0
- package/cjs/AiLiveAssist.js +1774 -0
- package/cjs/client.d.ts +53 -0
- package/cjs/client.js +193 -0
- package/cjs/context.d.ts +58 -0
- package/cjs/context.js +979 -0
- package/cjs/control.d.ts +31 -0
- package/cjs/control.js +190 -0
- package/cjs/experienceState.d.ts +18 -0
- package/cjs/experienceState.js +82 -0
- package/cjs/index.d.ts +13 -0
- package/cjs/index.js +32 -0
- package/cjs/media.d.ts +34 -0
- package/cjs/media.js +207 -0
- package/cjs/messages.d.ts +2 -0
- package/cjs/messages.js +95 -0
- package/cjs/package.json +1 -0
- package/cjs/placement.d.ts +52 -0
- package/cjs/placement.js +293 -0
- package/cjs/presentation.d.ts +41 -0
- package/cjs/presentation.js +483 -0
- package/cjs/recordingPolicy.d.ts +2 -0
- package/cjs/recordingPolicy.js +12 -0
- package/cjs/safeSvg.d.ts +1 -0
- package/cjs/safeSvg.js +157 -0
- package/cjs/tabLock.d.ts +31 -0
- package/cjs/tabLock.js +260 -0
- package/cjs/types.d.ts +299 -0
- package/cjs/types.js +2 -0
- package/cjs/ui.d.ts +184 -0
- package/cjs/ui.js +2353 -0
- package/cjs/version.d.ts +1 -0
- package/cjs/version.js +4 -0
- package/cjs/visualContext.d.ts +21 -0
- package/cjs/visualContext.js +72 -0
- package/cjs/voicePresenceUi.d.ts +148 -0
- package/cjs/voicePresenceUi.js +2182 -0
- package/lib/AiLiveAssist.d.ts +108 -0
- package/lib/AiLiveAssist.js +1769 -0
- package/lib/client.d.ts +53 -0
- package/lib/client.js +187 -0
- package/lib/context.d.ts +58 -0
- package/lib/context.js +975 -0
- package/lib/control.d.ts +31 -0
- package/lib/control.js +186 -0
- package/lib/experienceState.d.ts +18 -0
- package/lib/experienceState.js +78 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +26 -0
- package/lib/media.d.ts +34 -0
- package/lib/media.js +203 -0
- package/lib/messages.d.ts +2 -0
- package/lib/messages.js +92 -0
- package/lib/placement.d.ts +52 -0
- package/lib/placement.js +286 -0
- package/lib/presentation.d.ts +41 -0
- package/lib/presentation.js +478 -0
- package/lib/recordingPolicy.d.ts +2 -0
- package/lib/recordingPolicy.js +8 -0
- package/lib/safeSvg.d.ts +1 -0
- package/lib/safeSvg.js +153 -0
- package/lib/tabLock.d.ts +31 -0
- package/lib/tabLock.js +256 -0
- package/lib/types.d.ts +299 -0
- package/lib/types.js +1 -0
- package/lib/ui.d.ts +184 -0
- package/lib/ui.js +2349 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +1 -0
- package/lib/visualContext.d.ts +21 -0
- package/lib/visualContext.js +68 -0
- package/lib/voicePresenceUi.d.ts +148 -0
- package/lib/voicePresenceUi.js +2178 -0
- package/package.json +58 -0
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PresentationPlane = exports.parsePresentationIntent = void 0;
|
|
4
|
+
const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
5
|
+
const OPAQUE_ID = /^[A-Za-z0-9_.:-]{8,128}$/;
|
|
6
|
+
const KINDS = new Set([
|
|
7
|
+
'pointer',
|
|
8
|
+
'spotlight',
|
|
9
|
+
'underline',
|
|
10
|
+
'circle',
|
|
11
|
+
'arrow',
|
|
12
|
+
'connector',
|
|
13
|
+
'sequence_marker',
|
|
14
|
+
'callout',
|
|
15
|
+
'clear',
|
|
16
|
+
]);
|
|
17
|
+
const INTENT_KEYS = new Set([
|
|
18
|
+
'presentationId',
|
|
19
|
+
'groupId',
|
|
20
|
+
'kind',
|
|
21
|
+
'targetId',
|
|
22
|
+
'secondaryTargetId',
|
|
23
|
+
'domRevision',
|
|
24
|
+
'message',
|
|
25
|
+
'emphasis',
|
|
26
|
+
'ttlMs',
|
|
27
|
+
'replaceGroup',
|
|
28
|
+
]);
|
|
29
|
+
const parsePresentationIntent = (input) => {
|
|
30
|
+
if (Object.keys(input).some((key) => !INTENT_KEYS.has(key)))
|
|
31
|
+
return null;
|
|
32
|
+
const kind = input.kind;
|
|
33
|
+
const emphasis = input.emphasis;
|
|
34
|
+
const presentationId = input.presentationId;
|
|
35
|
+
const groupId = input.groupId;
|
|
36
|
+
const targetId = input.targetId;
|
|
37
|
+
const secondaryTargetId = input.secondaryTargetId;
|
|
38
|
+
const message = input.message;
|
|
39
|
+
const domRevision = input.domRevision;
|
|
40
|
+
const ttlMs = input.ttlMs;
|
|
41
|
+
if (typeof presentationId !== 'string' ||
|
|
42
|
+
!OPAQUE_ID.test(presentationId) ||
|
|
43
|
+
!KINDS.has(kind) ||
|
|
44
|
+
(groupId !== null &&
|
|
45
|
+
(typeof groupId !== 'string' || !OPAQUE_ID.test(groupId))) ||
|
|
46
|
+
(targetId !== null &&
|
|
47
|
+
(typeof targetId !== 'string' || !OPAQUE_ID.test(targetId))) ||
|
|
48
|
+
(secondaryTargetId !== null &&
|
|
49
|
+
(typeof secondaryTargetId !== 'string' ||
|
|
50
|
+
!OPAQUE_ID.test(secondaryTargetId))) ||
|
|
51
|
+
(message !== null &&
|
|
52
|
+
(typeof message !== 'string' ||
|
|
53
|
+
message.length > 240 ||
|
|
54
|
+
/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/u.test(message))) ||
|
|
55
|
+
!Number.isSafeInteger(domRevision) ||
|
|
56
|
+
domRevision < 0 ||
|
|
57
|
+
!Number.isSafeInteger(ttlMs) ||
|
|
58
|
+
ttlMs < 750 ||
|
|
59
|
+
ttlMs > 15000 ||
|
|
60
|
+
!['subtle', 'normal', 'strong'].includes(emphasis) ||
|
|
61
|
+
typeof input.replaceGroup !== 'boolean') {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if ((kind === 'clear' && (targetId !== null || secondaryTargetId !== null)) ||
|
|
65
|
+
(kind !== 'clear' && targetId === null) ||
|
|
66
|
+
(kind === 'connector' && secondaryTargetId === null) ||
|
|
67
|
+
(kind !== 'connector' && secondaryTargetId !== null) ||
|
|
68
|
+
(kind === 'callout' && (typeof message !== 'string' || !message.trim())) ||
|
|
69
|
+
(kind !== 'callout' && message !== null)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
presentationId,
|
|
74
|
+
groupId: groupId,
|
|
75
|
+
kind,
|
|
76
|
+
targetId: targetId,
|
|
77
|
+
secondaryTargetId: secondaryTargetId,
|
|
78
|
+
domRevision: domRevision,
|
|
79
|
+
message: message,
|
|
80
|
+
emphasis,
|
|
81
|
+
ttlMs: ttlMs,
|
|
82
|
+
replaceGroup: input.replaceGroup,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
exports.parsePresentationIntent = parsePresentationIntent;
|
|
86
|
+
const style = `
|
|
87
|
+
:host {
|
|
88
|
+
all: initial;
|
|
89
|
+
position: fixed;
|
|
90
|
+
inset: 0;
|
|
91
|
+
z-index: 2147483645;
|
|
92
|
+
pointer-events: none;
|
|
93
|
+
contain: strict;
|
|
94
|
+
--presentation-accent: #2563eb;
|
|
95
|
+
}
|
|
96
|
+
svg { width: 100%; height: 100%; overflow: visible; pointer-events: none; }
|
|
97
|
+
.cue { opacity: 0; animation: cue-in 180ms ease-out forwards; }
|
|
98
|
+
.cue.suspended { opacity: .16; transition: opacity 120ms ease; }
|
|
99
|
+
.stroke { fill: none; stroke: var(--presentation-accent); stroke-width: 2.75; filter: drop-shadow(0 2px 3px rgba(15, 23, 42, .16)); vector-effect: non-scaling-stroke; }
|
|
100
|
+
.spatial-trail { fill: none; stroke: color-mix(in srgb, var(--presentation-accent) 78%, white); stroke-width: 2.25; stroke-linecap: round; stroke-dasharray: 5 5; opacity: .86; filter: drop-shadow(0 1px 2px rgba(15, 23, 42, .12)); vector-effect: non-scaling-stroke; }
|
|
101
|
+
.glass { fill: color-mix(in srgb, var(--presentation-accent) 16%, transparent); stroke: color-mix(in srgb, var(--presentation-accent) 88%, white); stroke-width: 2.25; filter: drop-shadow(0 3px 7px rgba(15, 23, 42, .14)); vector-effect: non-scaling-stroke; }
|
|
102
|
+
.pointer-core { fill: white; stroke: var(--presentation-accent); stroke-width: 2.25; filter: drop-shadow(0 5px 10px rgba(15, 23, 42, .25)); }
|
|
103
|
+
.pointer-mark { fill: var(--presentation-accent); font: 700 8px system-ui, sans-serif; text-anchor: middle; dominant-baseline: central; }
|
|
104
|
+
.callout-box { fill: rgba(255, 255, 255, .98); stroke: color-mix(in srgb, var(--presentation-accent) 72%, #d1d5db); stroke-width: 1.25; filter: drop-shadow(0 6px 14px rgba(15, 23, 42, .20)); }
|
|
105
|
+
.callout-text { fill: #17212b; font: 500 12px/1.35 system-ui, sans-serif; }
|
|
106
|
+
.sequence-text { fill: white; font: 700 11px system-ui, sans-serif; text-anchor: middle; dominant-baseline: central; }
|
|
107
|
+
@keyframes cue-in { to { opacity: 1; } }
|
|
108
|
+
@media (prefers-reduced-motion: reduce) {
|
|
109
|
+
.cue { animation: none; opacity: 1; }
|
|
110
|
+
}
|
|
111
|
+
@media (forced-colors: active) {
|
|
112
|
+
.stroke, .glass, .pointer-core { stroke: Highlight; }
|
|
113
|
+
.glass { fill: Canvas; }
|
|
114
|
+
}
|
|
115
|
+
`;
|
|
116
|
+
const svgElement = (name) => document.createElementNS(SVG_NAMESPACE, name);
|
|
117
|
+
const setAttributes = (element, attributes) => {
|
|
118
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
119
|
+
element.setAttribute(name, String(value));
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const overlapArea = (first, second) => Math.max(0, Math.min(first.right, second.right) - Math.max(first.left, second.left)) *
|
|
123
|
+
Math.max(0, Math.min(first.bottom, second.bottom) - Math.max(first.top, second.top));
|
|
124
|
+
class PresentationPlane {
|
|
125
|
+
constructor(accent, maxActiveCues, reducedMotion, callbacks) {
|
|
126
|
+
this.maxActiveCues = maxActiveCues;
|
|
127
|
+
this.reducedMotion = reducedMotion;
|
|
128
|
+
this.callbacks = callbacks;
|
|
129
|
+
this.cues = new Map();
|
|
130
|
+
this.raf = null;
|
|
131
|
+
this.suspendedUntil = 0;
|
|
132
|
+
this.resumeTimer = null;
|
|
133
|
+
this.destroyed = false;
|
|
134
|
+
this.scheduleFrame = () => {
|
|
135
|
+
if (this.raf !== null || this.cues.size === 0 || document.hidden)
|
|
136
|
+
return;
|
|
137
|
+
this.raf = requestAnimationFrame(() => {
|
|
138
|
+
this.raf = null;
|
|
139
|
+
if (Date.now() < this.suspendedUntil)
|
|
140
|
+
return;
|
|
141
|
+
for (const cue of this.cues.values())
|
|
142
|
+
this.draw(cue);
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
this.onVisitorActivity = (event) => {
|
|
146
|
+
if (event.composedPath().some((target) => target instanceof HTMLElement &&
|
|
147
|
+
target.dataset.oxvoAiLiveAssistRoot === 'true')) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
this.suspendedUntil = Date.now() + 750;
|
|
151
|
+
for (const cue of this.cues.values())
|
|
152
|
+
cue.group.classList.add('suspended');
|
|
153
|
+
if (this.resumeTimer)
|
|
154
|
+
clearTimeout(this.resumeTimer);
|
|
155
|
+
this.resumeTimer = setTimeout(() => {
|
|
156
|
+
this.resumeTimer = null;
|
|
157
|
+
for (const cue of this.cues.values())
|
|
158
|
+
cue.group.classList.remove('suspended');
|
|
159
|
+
this.scheduleFrame();
|
|
160
|
+
}, 750);
|
|
161
|
+
};
|
|
162
|
+
this.onVisibilityChange = () => {
|
|
163
|
+
if (document.hidden) {
|
|
164
|
+
if (this.raf !== null)
|
|
165
|
+
cancelAnimationFrame(this.raf);
|
|
166
|
+
this.raf = null;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.scheduleFrame();
|
|
170
|
+
};
|
|
171
|
+
this.host = document.createElement('div');
|
|
172
|
+
this.host.dataset.oxvoAiLiveAssistRoot = 'true';
|
|
173
|
+
this.host.setAttribute('aria-hidden', 'true');
|
|
174
|
+
const shadow = this.host.attachShadow({ mode: 'closed' });
|
|
175
|
+
const sheet = document.createElement('style');
|
|
176
|
+
sheet.textContent = style;
|
|
177
|
+
this.svg = svgElement('svg');
|
|
178
|
+
this.svg.setAttribute('aria-hidden', 'true');
|
|
179
|
+
shadow.append(sheet, this.svg);
|
|
180
|
+
this.host.style.setProperty('--presentation-accent', accent);
|
|
181
|
+
document.documentElement.append(this.host);
|
|
182
|
+
document.addEventListener('pointerdown', this.onVisitorActivity, true);
|
|
183
|
+
document.addEventListener('keydown', this.onVisitorActivity, true);
|
|
184
|
+
document.addEventListener('input', this.onVisitorActivity, true);
|
|
185
|
+
window.addEventListener('wheel', this.onVisitorActivity, { passive: true });
|
|
186
|
+
window.addEventListener('touchstart', this.onVisitorActivity, {
|
|
187
|
+
passive: true,
|
|
188
|
+
capture: true,
|
|
189
|
+
});
|
|
190
|
+
window.addEventListener('resize', this.scheduleFrame, { passive: true });
|
|
191
|
+
document.addEventListener('scroll', this.scheduleFrame, {
|
|
192
|
+
capture: true,
|
|
193
|
+
passive: true,
|
|
194
|
+
});
|
|
195
|
+
window.visualViewport?.addEventListener('resize', this.scheduleFrame, {
|
|
196
|
+
passive: true,
|
|
197
|
+
});
|
|
198
|
+
window.visualViewport?.addEventListener('scroll', this.scheduleFrame, {
|
|
199
|
+
passive: true,
|
|
200
|
+
});
|
|
201
|
+
document.addEventListener('visibilitychange', this.onVisibilityChange);
|
|
202
|
+
}
|
|
203
|
+
render(intent) {
|
|
204
|
+
if (intent.kind === 'clear') {
|
|
205
|
+
this.clear(intent.groupId ? 'group' : 'all', intent.groupId);
|
|
206
|
+
return this.result(intent, 'cleared', 'OK', null);
|
|
207
|
+
}
|
|
208
|
+
if (!OPAQUE_ID.test(intent.presentationId) ||
|
|
209
|
+
!intent.targetId ||
|
|
210
|
+
!OPAQUE_ID.test(intent.targetId) ||
|
|
211
|
+
intent.ttlMs < 750 ||
|
|
212
|
+
intent.ttlMs > 15000 ||
|
|
213
|
+
(intent.message?.length ?? 0) > 240) {
|
|
214
|
+
return this.result(intent, 'blocked', 'PRESENTATION_TARGET_BLOCKED', null);
|
|
215
|
+
}
|
|
216
|
+
if (this.callbacks.kindEnabled && !this.callbacks.kindEnabled(intent.kind)) {
|
|
217
|
+
return this.result(intent, 'unsupported', 'PRESENTATION_DISABLED', null);
|
|
218
|
+
}
|
|
219
|
+
if (Date.now() < this.suspendedUntil) {
|
|
220
|
+
return this.result(intent, 'blocked', 'VISITOR_ACTIVITY', null);
|
|
221
|
+
}
|
|
222
|
+
const target = this.callbacks.resolveTarget(intent.targetId, intent.domRevision);
|
|
223
|
+
const secondaryTarget = intent.secondaryTargetId
|
|
224
|
+
? this.callbacks.resolveTarget(intent.secondaryTargetId, intent.domRevision)
|
|
225
|
+
: null;
|
|
226
|
+
if (!target || (intent.secondaryTargetId && !secondaryTarget)) {
|
|
227
|
+
return this.result(intent, 'stale', 'PRESENTATION_TARGET_STALE', target);
|
|
228
|
+
}
|
|
229
|
+
if (!target.safe || (secondaryTarget && !secondaryTarget.safe)) {
|
|
230
|
+
return this.result(intent, 'blocked', 'PRESENTATION_TARGET_BLOCKED', target);
|
|
231
|
+
}
|
|
232
|
+
if (intent.replaceGroup && intent.groupId)
|
|
233
|
+
this.clear('group', intent.groupId);
|
|
234
|
+
if (this.cues.has(intent.presentationId)) {
|
|
235
|
+
return this.result(intent, 'shown', 'OK', target);
|
|
236
|
+
}
|
|
237
|
+
while (this.cues.size >= Math.max(1, Math.min(5, this.maxActiveCues))) {
|
|
238
|
+
const oldest = this.cues.keys().next().value;
|
|
239
|
+
if (typeof oldest !== 'string')
|
|
240
|
+
break;
|
|
241
|
+
this.remove(oldest);
|
|
242
|
+
}
|
|
243
|
+
const group = svgElement('g');
|
|
244
|
+
group.classList.add('cue');
|
|
245
|
+
group.dataset.presentationId = intent.presentationId;
|
|
246
|
+
this.svg.append(group);
|
|
247
|
+
const timer = setTimeout(() => this.remove(intent.presentationId), intent.ttlMs);
|
|
248
|
+
const cue = { intent, group, target, secondaryTarget, timer };
|
|
249
|
+
this.cues.set(intent.presentationId, cue);
|
|
250
|
+
this.draw(cue);
|
|
251
|
+
this.emitVisibility();
|
|
252
|
+
this.scheduleFrame();
|
|
253
|
+
return this.result(intent, 'shown', this.reducedMotion ? 'REDUCED_MOTION_FALLBACK' : 'OK', target);
|
|
254
|
+
}
|
|
255
|
+
clear(reason, groupId = null) {
|
|
256
|
+
for (const [presentationId, cue] of this.cues) {
|
|
257
|
+
if (reason === 'group' && cue.intent.groupId !== groupId)
|
|
258
|
+
continue;
|
|
259
|
+
this.remove(presentationId);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
destroy() {
|
|
263
|
+
if (this.destroyed)
|
|
264
|
+
return;
|
|
265
|
+
this.destroyed = true;
|
|
266
|
+
this.clear('all');
|
|
267
|
+
if (this.raf !== null)
|
|
268
|
+
cancelAnimationFrame(this.raf);
|
|
269
|
+
if (this.resumeTimer)
|
|
270
|
+
clearTimeout(this.resumeTimer);
|
|
271
|
+
document.removeEventListener('pointerdown', this.onVisitorActivity, true);
|
|
272
|
+
document.removeEventListener('keydown', this.onVisitorActivity, true);
|
|
273
|
+
document.removeEventListener('input', this.onVisitorActivity, true);
|
|
274
|
+
window.removeEventListener('wheel', this.onVisitorActivity);
|
|
275
|
+
window.removeEventListener('touchstart', this.onVisitorActivity, true);
|
|
276
|
+
window.removeEventListener('resize', this.scheduleFrame);
|
|
277
|
+
document.removeEventListener('scroll', this.scheduleFrame, true);
|
|
278
|
+
window.visualViewport?.removeEventListener('resize', this.scheduleFrame);
|
|
279
|
+
window.visualViewport?.removeEventListener('scroll', this.scheduleFrame);
|
|
280
|
+
document.removeEventListener('visibilitychange', this.onVisibilityChange);
|
|
281
|
+
this.host.remove();
|
|
282
|
+
}
|
|
283
|
+
draw(cue) {
|
|
284
|
+
const current = this.callbacks.resolveTarget(cue.intent.targetId ?? '', cue.intent.domRevision);
|
|
285
|
+
if (!current?.safe) {
|
|
286
|
+
this.remove(cue.intent.presentationId);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
cue.target = current;
|
|
290
|
+
if (cue.intent.secondaryTargetId) {
|
|
291
|
+
const secondary = this.callbacks.resolveTarget(cue.intent.secondaryTargetId, cue.intent.domRevision);
|
|
292
|
+
if (!secondary?.safe) {
|
|
293
|
+
this.remove(cue.intent.presentationId);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
cue.secondaryTarget = secondary;
|
|
297
|
+
}
|
|
298
|
+
cue.group.replaceChildren();
|
|
299
|
+
const rect = cue.target.rect;
|
|
300
|
+
const padding = cue.intent.emphasis === 'strong' ? 10 : 7;
|
|
301
|
+
const centerX = rect.left + rect.width / 2;
|
|
302
|
+
const centerY = rect.top + rect.height / 2;
|
|
303
|
+
if (this.callbacks.spatialTrail &&
|
|
304
|
+
!this.reducedMotion &&
|
|
305
|
+
!['connector', 'sequence_marker'].includes(cue.intent.kind)) {
|
|
306
|
+
this.drawSpatialTrail(cue.group, centerX, centerY);
|
|
307
|
+
}
|
|
308
|
+
if (cue.intent.kind === 'pointer') {
|
|
309
|
+
const core = svgElement('circle');
|
|
310
|
+
core.classList.add('pointer-core');
|
|
311
|
+
setAttributes(core, { cx: rect.right + 9, cy: rect.top - 7, r: 11 });
|
|
312
|
+
const mark = svgElement('text');
|
|
313
|
+
mark.classList.add('pointer-mark');
|
|
314
|
+
setAttributes(mark, { x: rect.right + 9, y: rect.top - 7 });
|
|
315
|
+
mark.textContent = 'AI';
|
|
316
|
+
cue.group.append(core, mark);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (cue.intent.kind === 'spotlight' || cue.intent.kind === 'circle') {
|
|
320
|
+
const shape = svgElement('rect');
|
|
321
|
+
shape.classList.add(cue.intent.kind === 'spotlight' ? 'glass' : 'stroke');
|
|
322
|
+
setAttributes(shape, {
|
|
323
|
+
x: rect.left - padding,
|
|
324
|
+
y: rect.top - padding,
|
|
325
|
+
width: rect.width + padding * 2,
|
|
326
|
+
height: rect.height + padding * 2,
|
|
327
|
+
rx: Math.min(12, Math.max(4, rect.height / 4)),
|
|
328
|
+
});
|
|
329
|
+
cue.group.append(shape);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (cue.intent.kind === 'underline') {
|
|
333
|
+
const line = svgElement('path');
|
|
334
|
+
line.classList.add('stroke');
|
|
335
|
+
setAttributes(line, {
|
|
336
|
+
d: `M ${rect.left} ${rect.bottom + 5} Q ${centerX} ${rect.bottom + 8} ${rect.right} ${rect.bottom + 4}`,
|
|
337
|
+
});
|
|
338
|
+
cue.group.append(line);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (cue.intent.kind === 'arrow' || cue.intent.kind === 'connector') {
|
|
342
|
+
const secondary = cue.secondaryTarget?.rect;
|
|
343
|
+
const destinationX = secondary ? secondary.left + secondary.width / 2 : centerX;
|
|
344
|
+
const destinationY = secondary ? secondary.top + secondary.height / 2 : centerY;
|
|
345
|
+
const originX = secondary ? centerX : Math.max(16, rect.left - 42);
|
|
346
|
+
const originY = secondary ? centerY : Math.max(16, rect.top - 28);
|
|
347
|
+
const line = svgElement('path');
|
|
348
|
+
line.classList.add('stroke');
|
|
349
|
+
setAttributes(line, {
|
|
350
|
+
d: `M ${originX} ${originY} Q ${(originX + destinationX) / 2} ${Math.min(originY, destinationY) - 18} ${destinationX} ${destinationY}`,
|
|
351
|
+
});
|
|
352
|
+
cue.group.append(line);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (cue.intent.kind === 'sequence_marker') {
|
|
356
|
+
const marker = svgElement('circle');
|
|
357
|
+
marker.classList.add('glass');
|
|
358
|
+
marker.style.fill = 'var(--presentation-accent)';
|
|
359
|
+
setAttributes(marker, { cx: rect.left - 9, cy: centerY, r: 12 });
|
|
360
|
+
const label = svgElement('text');
|
|
361
|
+
label.classList.add('sequence-text');
|
|
362
|
+
setAttributes(label, { x: rect.left - 9, y: centerY });
|
|
363
|
+
const sequence = Array.from(this.cues.values())
|
|
364
|
+
.filter((candidate) => candidate.intent.kind === 'sequence_marker' &&
|
|
365
|
+
candidate.intent.groupId === cue.intent.groupId)
|
|
366
|
+
.findIndex((candidate) => candidate.intent.presentationId === cue.intent.presentationId);
|
|
367
|
+
label.textContent = String(Math.max(1, sequence + 1));
|
|
368
|
+
cue.group.append(marker, label);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
if (cue.intent.kind === 'callout') {
|
|
372
|
+
const text = (cue.intent.message ?? '').replace(/\s+/g, ' ').trim().slice(0, 120);
|
|
373
|
+
const availableWidth = Math.max(72, (window.visualViewport?.width ?? window.innerWidth) - 16);
|
|
374
|
+
const width = Math.min(260, availableWidth, Math.max(120, text.length * 6.2 + 20));
|
|
375
|
+
const placement = this.calloutPlacement(rect, width, 34);
|
|
376
|
+
const box = svgElement('rect');
|
|
377
|
+
box.classList.add('callout-box');
|
|
378
|
+
setAttributes(box, {
|
|
379
|
+
x: placement.left,
|
|
380
|
+
y: placement.top,
|
|
381
|
+
width,
|
|
382
|
+
height: 34,
|
|
383
|
+
rx: 7,
|
|
384
|
+
});
|
|
385
|
+
const label = svgElement('text');
|
|
386
|
+
label.classList.add('callout-text');
|
|
387
|
+
setAttributes(label, { x: placement.left + 10, y: placement.top + 21 });
|
|
388
|
+
const maximumCharacters = Math.max(8, Math.floor((width - 20) / 6.2));
|
|
389
|
+
label.textContent =
|
|
390
|
+
text.length > maximumCharacters
|
|
391
|
+
? `${text.slice(0, maximumCharacters - 3).trimEnd()}...`
|
|
392
|
+
: text;
|
|
393
|
+
cue.group.append(box, label);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
drawSpatialTrail(group, targetX, targetY) {
|
|
397
|
+
const launcher = this.callbacks.launcherRect?.();
|
|
398
|
+
if (!launcher || launcher.width < 1 || launcher.height < 1)
|
|
399
|
+
return;
|
|
400
|
+
const launcherX = launcher.left + launcher.width / 2;
|
|
401
|
+
const launcherY = launcher.top + launcher.height / 2;
|
|
402
|
+
const deltaX = launcherX - targetX;
|
|
403
|
+
const deltaY = launcherY - targetY;
|
|
404
|
+
const distance = Math.hypot(deltaX, deltaY);
|
|
405
|
+
if (distance < 24)
|
|
406
|
+
return;
|
|
407
|
+
const trailLength = Math.min(112, distance * 0.34);
|
|
408
|
+
const originX = targetX + (deltaX / distance) * trailLength;
|
|
409
|
+
const originY = targetY + (deltaY / distance) * trailLength;
|
|
410
|
+
const normalX = (-deltaY / distance) * Math.min(14, trailLength * 0.12);
|
|
411
|
+
const normalY = (deltaX / distance) * Math.min(14, trailLength * 0.12);
|
|
412
|
+
const trail = svgElement('path');
|
|
413
|
+
trail.classList.add('spatial-trail');
|
|
414
|
+
setAttributes(trail, {
|
|
415
|
+
d: `M ${originX} ${originY} Q ${(originX + targetX) / 2 + normalX} ${(originY + targetY) / 2 + normalY} ${targetX} ${targetY}`,
|
|
416
|
+
});
|
|
417
|
+
group.append(trail);
|
|
418
|
+
}
|
|
419
|
+
calloutPlacement(target, width, height) {
|
|
420
|
+
const visual = window.visualViewport;
|
|
421
|
+
const viewport = {
|
|
422
|
+
left: visual?.offsetLeft ?? 0,
|
|
423
|
+
top: visual?.offsetTop ?? 0,
|
|
424
|
+
right: (visual?.offsetLeft ?? 0) + (visual?.width ?? window.innerWidth),
|
|
425
|
+
bottom: (visual?.offsetTop ?? 0) + (visual?.height ?? window.innerHeight),
|
|
426
|
+
};
|
|
427
|
+
const centerX = target.left + target.width / 2;
|
|
428
|
+
const centerY = target.top + target.height / 2;
|
|
429
|
+
const rawCandidates = [
|
|
430
|
+
{ left: centerX - width / 2, top: target.top - height - 12 },
|
|
431
|
+
{ left: centerX - width / 2, top: target.bottom + 12 },
|
|
432
|
+
{ left: target.right + 12, top: centerY - height / 2 },
|
|
433
|
+
{ left: target.left - width - 12, top: centerY - height / 2 },
|
|
434
|
+
];
|
|
435
|
+
const obstacles = [target, ...(this.callbacks.obstacleRects?.() ?? [])];
|
|
436
|
+
const candidates = rawCandidates.map((candidate, index) => {
|
|
437
|
+
const left = Math.max(viewport.left + 8, Math.min(viewport.right - width - 8, candidate.left));
|
|
438
|
+
const top = Math.max(viewport.top + 8, Math.min(viewport.bottom - height - 8, candidate.top));
|
|
439
|
+
const value = {
|
|
440
|
+
x: left,
|
|
441
|
+
y: top,
|
|
442
|
+
left,
|
|
443
|
+
top,
|
|
444
|
+
right: left + width,
|
|
445
|
+
bottom: top + height,
|
|
446
|
+
width,
|
|
447
|
+
height,
|
|
448
|
+
toJSON: () => ({}),
|
|
449
|
+
};
|
|
450
|
+
const overlap = obstacles.reduce((total, obstacle) => total + overlapArea(value, obstacle), 0);
|
|
451
|
+
return { value, score: overlap * 1000 + index };
|
|
452
|
+
});
|
|
453
|
+
return candidates.sort((first, second) => first.score - second.score)[0].value;
|
|
454
|
+
}
|
|
455
|
+
result(intent, status, reasonCode, target) {
|
|
456
|
+
return {
|
|
457
|
+
presentationId: intent.presentationId,
|
|
458
|
+
status,
|
|
459
|
+
reasonCode,
|
|
460
|
+
pageId: target?.pageId ?? this.callbacks.currentPage().pageId,
|
|
461
|
+
domRevision: intent.domRevision,
|
|
462
|
+
shownAt: status === 'shown' ? new Date().toISOString() : null,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
remove(presentationId) {
|
|
466
|
+
const cue = this.cues.get(presentationId);
|
|
467
|
+
if (!cue)
|
|
468
|
+
return;
|
|
469
|
+
clearTimeout(cue.timer);
|
|
470
|
+
cue.group.remove();
|
|
471
|
+
this.cues.delete(presentationId);
|
|
472
|
+
if (this.cues.size === 0 && this.raf !== null) {
|
|
473
|
+
cancelAnimationFrame(this.raf);
|
|
474
|
+
this.raf = null;
|
|
475
|
+
}
|
|
476
|
+
this.emitVisibility();
|
|
477
|
+
}
|
|
478
|
+
emitVisibility() {
|
|
479
|
+
const first = this.cues.values().next().value;
|
|
480
|
+
this.callbacks.onVisibility(first?.target.pageId ?? 'page_unknown', first?.intent.domRevision ?? 0, [...this.cues.keys()]);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
exports.PresentationPlane = PresentationPlane;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.disableReplayRecording = void 0;
|
|
4
|
+
const disabledApps = new WeakSet();
|
|
5
|
+
const disableReplayRecording = (app) => {
|
|
6
|
+
if (disabledApps.has(app))
|
|
7
|
+
return;
|
|
8
|
+
disabledApps.add(app);
|
|
9
|
+
app.stop();
|
|
10
|
+
app.attachStartCallback(() => window.setTimeout(() => app.stop(), 0), true);
|
|
11
|
+
};
|
|
12
|
+
exports.disableReplayRecording = disableReplayRecording;
|
package/cjs/safeSvg.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createSafeSvgIcon: (value: string | null | undefined, targetDocument?: Document) => SVGSVGElement | null;
|
package/cjs/safeSvg.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSafeSvgIcon = void 0;
|
|
4
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
5
|
+
const MAX_SVG_BYTES = 16384;
|
|
6
|
+
const MAX_SVG_ELEMENTS = 64;
|
|
7
|
+
const SAFE_TAGS = new Set([
|
|
8
|
+
"svg",
|
|
9
|
+
"g",
|
|
10
|
+
"path",
|
|
11
|
+
"circle",
|
|
12
|
+
"ellipse",
|
|
13
|
+
"line",
|
|
14
|
+
"polyline",
|
|
15
|
+
"polygon",
|
|
16
|
+
"rect",
|
|
17
|
+
]);
|
|
18
|
+
const SAFE_ATTRIBUTES = new Set([
|
|
19
|
+
"viewBox",
|
|
20
|
+
"d",
|
|
21
|
+
"x",
|
|
22
|
+
"y",
|
|
23
|
+
"x1",
|
|
24
|
+
"y1",
|
|
25
|
+
"x2",
|
|
26
|
+
"y2",
|
|
27
|
+
"cx",
|
|
28
|
+
"cy",
|
|
29
|
+
"r",
|
|
30
|
+
"rx",
|
|
31
|
+
"ry",
|
|
32
|
+
"width",
|
|
33
|
+
"height",
|
|
34
|
+
"points",
|
|
35
|
+
"transform",
|
|
36
|
+
"fill",
|
|
37
|
+
"stroke",
|
|
38
|
+
"stroke-width",
|
|
39
|
+
"stroke-linecap",
|
|
40
|
+
"stroke-linejoin",
|
|
41
|
+
"fill-rule",
|
|
42
|
+
"clip-rule",
|
|
43
|
+
"opacity",
|
|
44
|
+
]);
|
|
45
|
+
const IGNORED_ATTRIBUTES = new Set(["class", "aria-hidden", "focusable"]);
|
|
46
|
+
const PATH_VALUE = /^[\s,0-9+\-.eEaAcChHlLmMqQsStTvVzZ]+$/;
|
|
47
|
+
const NUMBER_LIST = /^[\s,0-9+\-.eE]+$/;
|
|
48
|
+
const TRANSFORM_VALUE = /^(?:(?:matrix|translate|scale|rotate|skewX|skewY)\([\s,0-9+\-.eE]+\)\s*)+$/;
|
|
49
|
+
const COLOR_VALUE = /^(?:none|currentColor|transparent|#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8}))$/i;
|
|
50
|
+
const utf8ByteLength = (value) => {
|
|
51
|
+
let length = 0;
|
|
52
|
+
for (const character of value) {
|
|
53
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
54
|
+
length +=
|
|
55
|
+
codePoint <= 0x7f
|
|
56
|
+
? 1
|
|
57
|
+
: codePoint <= 0x7ff
|
|
58
|
+
? 2
|
|
59
|
+
: codePoint <= 0xffff
|
|
60
|
+
? 3
|
|
61
|
+
: 4;
|
|
62
|
+
}
|
|
63
|
+
return length;
|
|
64
|
+
};
|
|
65
|
+
const hasInvalidControlCharacter = (value) => Array.from(value).some((character) => {
|
|
66
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
67
|
+
return (codePoint < 32 && codePoint !== 9 && codePoint !== 10 && codePoint !== 13);
|
|
68
|
+
});
|
|
69
|
+
const safeAttribute = (name, value) => {
|
|
70
|
+
if (value.length > 4096 || hasInvalidControlCharacter(value)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (name === "d")
|
|
74
|
+
return value.length > 0 && PATH_VALUE.test(value);
|
|
75
|
+
if (name === "points")
|
|
76
|
+
return NUMBER_LIST.test(value);
|
|
77
|
+
if (name === "viewBox") {
|
|
78
|
+
const values = value
|
|
79
|
+
.trim()
|
|
80
|
+
.split(/[\s,]+/)
|
|
81
|
+
.map(Number);
|
|
82
|
+
return values.length === 4 && values.every(Number.isFinite);
|
|
83
|
+
}
|
|
84
|
+
if (name === "transform")
|
|
85
|
+
return TRANSFORM_VALUE.test(value.trim());
|
|
86
|
+
if (name === "fill" || name === "stroke")
|
|
87
|
+
return COLOR_VALUE.test(value);
|
|
88
|
+
if (name === "stroke-linecap")
|
|
89
|
+
return ["butt", "round", "square"].includes(value);
|
|
90
|
+
if (name === "stroke-linejoin")
|
|
91
|
+
return ["miter", "round", "bevel"].includes(value);
|
|
92
|
+
if (name === "fill-rule" || name === "clip-rule") {
|
|
93
|
+
return value === "nonzero" || value === "evenodd";
|
|
94
|
+
}
|
|
95
|
+
if (name === "opacity") {
|
|
96
|
+
const parsed = Number(value);
|
|
97
|
+
return Number.isFinite(parsed) && parsed >= 0 && parsed <= 1;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
const copyElement = (source, targetDocument, counter) => {
|
|
102
|
+
if (!SAFE_TAGS.has(source.localName) || counter.value >= MAX_SVG_ELEMENTS)
|
|
103
|
+
return null;
|
|
104
|
+
counter.value += 1;
|
|
105
|
+
const target = targetDocument.createElementNS(SVG_NAMESPACE, source.localName);
|
|
106
|
+
for (const attribute of Array.from(source.attributes)) {
|
|
107
|
+
if (attribute.name === "xmlns" && attribute.value === SVG_NAMESPACE) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (attribute.namespaceURI)
|
|
111
|
+
return null;
|
|
112
|
+
if (IGNORED_ATTRIBUTES.has(attribute.name))
|
|
113
|
+
continue;
|
|
114
|
+
if (!SAFE_ATTRIBUTES.has(attribute.name) ||
|
|
115
|
+
!safeAttribute(attribute.name, attribute.value.trim())) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (source.localName === "svg" &&
|
|
119
|
+
["width", "height"].includes(attribute.name))
|
|
120
|
+
continue;
|
|
121
|
+
target.setAttribute(attribute.name, attribute.value.trim());
|
|
122
|
+
}
|
|
123
|
+
for (const child of Array.from(source.childNodes)) {
|
|
124
|
+
if (child.nodeType === Node.TEXT_NODE && !child.textContent?.trim())
|
|
125
|
+
continue;
|
|
126
|
+
if (child.nodeType !== Node.ELEMENT_NODE)
|
|
127
|
+
return null;
|
|
128
|
+
const copied = copyElement(child, targetDocument, counter);
|
|
129
|
+
if (!copied)
|
|
130
|
+
return null;
|
|
131
|
+
target.append(copied);
|
|
132
|
+
}
|
|
133
|
+
return target;
|
|
134
|
+
};
|
|
135
|
+
const createSafeSvgIcon = (value, targetDocument = document) => {
|
|
136
|
+
const source = value?.trim();
|
|
137
|
+
if (!source || utf8ByteLength(source) > MAX_SVG_BYTES)
|
|
138
|
+
return null;
|
|
139
|
+
if (/<!doctype|<!entity|<\?xml-stylesheet/i.test(source))
|
|
140
|
+
return null;
|
|
141
|
+
const parsed = new DOMParser().parseFromString(source, "image/svg+xml");
|
|
142
|
+
if (parsed.querySelector("parsererror") ||
|
|
143
|
+
parsed.documentElement.localName !== "svg") {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const copied = copyElement(parsed.documentElement, targetDocument, {
|
|
147
|
+
value: 0,
|
|
148
|
+
});
|
|
149
|
+
if (!copied || copied.localName !== "svg")
|
|
150
|
+
return null;
|
|
151
|
+
if (!copied.hasAttribute("viewBox"))
|
|
152
|
+
copied.setAttribute("viewBox", "0 0 24 24");
|
|
153
|
+
copied.setAttribute("aria-hidden", "true");
|
|
154
|
+
copied.setAttribute("focusable", "false");
|
|
155
|
+
return copied;
|
|
156
|
+
};
|
|
157
|
+
exports.createSafeSvgIcon = createSafeSvgIcon;
|