@virtualdisplay.io/client 4.0.0-alpha.2 → 4.0.0-alpha.20
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 +138 -0
- package/README.md +85 -158
- package/dist/browser-DfB_An57.cjs +8 -0
- package/dist/browser-ey6Iih3j.js +1540 -0
- package/dist/index.d.ts +1026 -1
- package/dist/virtualdisplay.client.cjs.js +461 -1
- package/dist/virtualdisplay.client.es.js +3370 -794
- package/dist/virtualdisplay.client.umd.js +468 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,1026 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Virtualdisplay iframe messaging protocol
|
|
3
|
+
*
|
|
4
|
+
* All message types exchanged between client (parent page)
|
|
5
|
+
* and server (iframe viewer engine) via postMessage.
|
|
6
|
+
*/
|
|
7
|
+
declare const MESSAGE_TYPES: {
|
|
8
|
+
readonly HANDSHAKE: "handshake";
|
|
9
|
+
readonly SESSION: "session";
|
|
10
|
+
readonly MUTATION: "mutation";
|
|
11
|
+
readonly STATE: "state";
|
|
12
|
+
readonly LOADING_INDICATOR: "loading_indicator";
|
|
13
|
+
readonly CAMERA: "camera";
|
|
14
|
+
readonly SNAPSHOT: "snapshot";
|
|
15
|
+
readonly MAPPING: "mapping";
|
|
16
|
+
readonly AR_ACTIVATE: "ar_activate";
|
|
17
|
+
readonly FULLSCREEN: "fullscreen";
|
|
18
|
+
readonly CONFIG: "config";
|
|
19
|
+
readonly ANNOTATION_TOGGLE: "annotation_toggle";
|
|
20
|
+
readonly FOCUS: "focus";
|
|
21
|
+
readonly PRICING: "pricing";
|
|
22
|
+
};
|
|
23
|
+
interface MutationDto {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly value: string;
|
|
26
|
+
}
|
|
27
|
+
interface MutationResult {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly value: string;
|
|
30
|
+
readonly success: boolean;
|
|
31
|
+
readonly error?: string;
|
|
32
|
+
}
|
|
33
|
+
interface MutationMessage {
|
|
34
|
+
readonly type: typeof MESSAGE_TYPES.MUTATION;
|
|
35
|
+
readonly mutations: MutationDto[];
|
|
36
|
+
readonly isInitial: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface MutationResultMessage {
|
|
39
|
+
readonly type: typeof MESSAGE_TYPES.MUTATION;
|
|
40
|
+
readonly results: MutationResult[];
|
|
41
|
+
readonly isInitial: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Viewer settings from model metadata (server → client via MAPPING).
|
|
45
|
+
* Customer-configured in the portal.
|
|
46
|
+
*/
|
|
47
|
+
interface ViewerSettings$1 {
|
|
48
|
+
readonly ar?: boolean;
|
|
49
|
+
readonly fullscreen?: boolean;
|
|
50
|
+
readonly screenshot?: boolean;
|
|
51
|
+
readonly cameraControls?: boolean;
|
|
52
|
+
readonly annotations?: boolean;
|
|
53
|
+
readonly language?: string;
|
|
54
|
+
/** Where the attribute controls sit: in-frame bottom-left (default) or a docked right panel. */
|
|
55
|
+
readonly configuratorLayout?: 'inframe-bottom-left' | 'sidebar-right' | 'hidden';
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Camera movement limits sent to the client via CONFIG.
|
|
59
|
+
* Used to disable camera control buttons when a limit is reached.
|
|
60
|
+
* Units match the camera position: zoom = percentage (0–200), tilt/rotate = degrees.
|
|
61
|
+
*/
|
|
62
|
+
interface CameraLimits {
|
|
63
|
+
readonly minZoom?: number;
|
|
64
|
+
readonly maxZoom?: number;
|
|
65
|
+
readonly minTilt?: number;
|
|
66
|
+
readonly maxTilt?: number;
|
|
67
|
+
readonly minRotate?: number;
|
|
68
|
+
readonly maxRotate?: number;
|
|
69
|
+
}
|
|
70
|
+
interface CameraCommand {
|
|
71
|
+
readonly action: 'rotate' | 'tilt' | 'zoom' | 'reset';
|
|
72
|
+
readonly value?: number;
|
|
73
|
+
}
|
|
74
|
+
interface CameraParameter {
|
|
75
|
+
readonly type: 'rotation' | 'tilt' | 'zoom';
|
|
76
|
+
readonly value: number;
|
|
77
|
+
}
|
|
78
|
+
interface CameraCommandMessage {
|
|
79
|
+
readonly type: typeof MESSAGE_TYPES.CAMERA;
|
|
80
|
+
readonly commands: CameraCommand[];
|
|
81
|
+
}
|
|
82
|
+
interface CameraPositionMessage {
|
|
83
|
+
readonly type: typeof MESSAGE_TYPES.CAMERA;
|
|
84
|
+
readonly transforms: CameraParameter[];
|
|
85
|
+
}
|
|
86
|
+
interface SnapshotRequestMessage {
|
|
87
|
+
readonly type: typeof MESSAGE_TYPES.SNAPSHOT;
|
|
88
|
+
readonly filename: string;
|
|
89
|
+
}
|
|
90
|
+
interface SnapshotResultMessage {
|
|
91
|
+
readonly type: typeof MESSAGE_TYPES.SNAPSHOT;
|
|
92
|
+
readonly filename: string;
|
|
93
|
+
readonly data?: string;
|
|
94
|
+
readonly error?: string;
|
|
95
|
+
}
|
|
96
|
+
interface AttributeDefinition {
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly values: string[];
|
|
99
|
+
readonly defaultValue?: string;
|
|
100
|
+
}
|
|
101
|
+
interface MappingMessage {
|
|
102
|
+
readonly type: typeof MESSAGE_TYPES.MAPPING;
|
|
103
|
+
readonly attributes: AttributeDefinition[];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Loading indicator (server → client): progress percentage, phase label, or error.
|
|
107
|
+
* Sent during model download and parse so the client loading indicator can update.
|
|
108
|
+
*/
|
|
109
|
+
interface LoadingIndicatorMessage {
|
|
110
|
+
readonly type: typeof MESSAGE_TYPES.LOADING_INDICATOR;
|
|
111
|
+
/** 0–100 */
|
|
112
|
+
readonly progress: number;
|
|
113
|
+
/** Human-readable phase label, e.g. "downloading" */
|
|
114
|
+
readonly phase: string;
|
|
115
|
+
/** Set when loading failed; client shows error state instead of hiding the overlay. */
|
|
116
|
+
readonly error?: string;
|
|
117
|
+
}
|
|
118
|
+
/** AR activate (client → server): user clicked the AR button. Server handles activation. */
|
|
119
|
+
interface ArActivateMessage {
|
|
120
|
+
readonly type: typeof MESSAGE_TYPES.AR_ACTIVATE;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Fullscreen (client → server): the user entered fullscreen via the client's
|
|
124
|
+
* toolbar button. Fullscreen itself is handled client-side; this only lets the
|
|
125
|
+
* server record the engagement against the tracking session it owns.
|
|
126
|
+
*/
|
|
127
|
+
interface FullscreenMessage {
|
|
128
|
+
readonly type: typeof MESSAGE_TYPES.FULLSCREEN;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Config (server → client): viewer settings and camera limits from model metadata.
|
|
132
|
+
* Sent early — before MAPPING — so the client can show/hide controls and disable
|
|
133
|
+
* camera buttons at limits as soon as metadata is available.
|
|
134
|
+
*/
|
|
135
|
+
interface ConfigMessage {
|
|
136
|
+
readonly type: typeof MESSAGE_TYPES.CONFIG;
|
|
137
|
+
readonly viewerSettings: ViewerSettings$1;
|
|
138
|
+
readonly cameraLimits?: CameraLimits;
|
|
139
|
+
}
|
|
140
|
+
interface HandshakeMessage {
|
|
141
|
+
readonly type: typeof MESSAGE_TYPES.HANDSHAKE;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Session (server → client): the tracking session id, announced once the viewer
|
|
145
|
+
* has established it (the id is generated in the iframe, so this is how the
|
|
146
|
+
* client learns it). The client exposes it so a host page can correlate its own
|
|
147
|
+
* actions (e.g. a configurator conversion) with the viewer session.
|
|
148
|
+
*/
|
|
149
|
+
interface SessionMessage {
|
|
150
|
+
readonly type: typeof MESSAGE_TYPES.SESSION;
|
|
151
|
+
readonly sessionId: string;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Annotation toggle (parent → server): show or hide annotation markers.
|
|
155
|
+
* Only works when annotations exist in metadata (grand switch).
|
|
156
|
+
*/
|
|
157
|
+
interface AnnotationToggleMessage {
|
|
158
|
+
readonly type: typeof MESSAGE_TYPES.ANNOTATION_TOGGLE;
|
|
159
|
+
readonly enabled: boolean;
|
|
160
|
+
}
|
|
161
|
+
/** Focus actions (client → server). */
|
|
162
|
+
declare const FOCUS_ACTIONS: {
|
|
163
|
+
readonly FOCUS: "focus";
|
|
164
|
+
readonly UNFOCUS: "unfocus";
|
|
165
|
+
};
|
|
166
|
+
/** Focus states (server → client). */
|
|
167
|
+
declare const FOCUS_STATES: {
|
|
168
|
+
readonly FOCUSED: "focused";
|
|
169
|
+
readonly UNFOCUSED: "unfocused";
|
|
170
|
+
};
|
|
171
|
+
type FocusAction = typeof FOCUS_ACTIONS[keyof typeof FOCUS_ACTIONS];
|
|
172
|
+
type FocusStateValue = typeof FOCUS_STATES[keyof typeof FOCUS_STATES];
|
|
173
|
+
/**
|
|
174
|
+
* Focus (client → server): isolate and frame a component, or return to overview.
|
|
175
|
+
* Programmatic — the API, the (future) component menu, and the portal editors all
|
|
176
|
+
* send this. `component` is a name from the `components` metadata, or a raw mesh
|
|
177
|
+
* name as a fallback (resolved server-side); required when action is `focus`.
|
|
178
|
+
*/
|
|
179
|
+
interface FocusMessage {
|
|
180
|
+
readonly type: typeof MESSAGE_TYPES.FOCUS;
|
|
181
|
+
readonly action: FocusAction;
|
|
182
|
+
readonly component?: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Focus state (server → client): confirms the focus state after the camera and
|
|
186
|
+
* opacity transition. `attributes` lists which attributes are relevant to the
|
|
187
|
+
* focused component, so a custom UI can filter its selectors.
|
|
188
|
+
*/
|
|
189
|
+
interface FocusStateMessage {
|
|
190
|
+
readonly type: typeof MESSAGE_TYPES.FOCUS;
|
|
191
|
+
readonly state: FocusStateValue;
|
|
192
|
+
readonly component?: string;
|
|
193
|
+
readonly attributes?: string[];
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* What the configurator does with a matched configuration. Mirrors the backend
|
|
197
|
+
* `availability` enum (pricing rule provenance lives on `PricingRule.source`).
|
|
198
|
+
*/
|
|
199
|
+
declare const AVAILABILITY$1: {
|
|
200
|
+
/** Price and submit button both shown (default). */
|
|
201
|
+
readonly AVAILABLE: "available";
|
|
202
|
+
/** Price shown, submit hidden (sold out / coming soon). */
|
|
203
|
+
readonly VIEW_ONLY: "view_only";
|
|
204
|
+
/** Behaves exactly like an unpriced combination: no price, no button. */
|
|
205
|
+
readonly HIDDEN: "hidden";
|
|
206
|
+
};
|
|
207
|
+
type Availability$1 = typeof AVAILABILITY$1[keyof typeof AVAILABILITY$1];
|
|
208
|
+
/**
|
|
209
|
+
* One pricing rule: a subset of attribute values mapped to a reference + price.
|
|
210
|
+
* Matches the backend pricing read contract (`GET /api/public/models/.../pricing`).
|
|
211
|
+
*/
|
|
212
|
+
interface PricingRule$1 {
|
|
213
|
+
/**
|
|
214
|
+
* The attribute name→value pairs this rule names. `{}` is a catch-all;
|
|
215
|
+
* omitted names are wildcards. A rule matches when every pair equals the
|
|
216
|
+
* current selection; the rule naming the most attributes wins.
|
|
217
|
+
*/
|
|
218
|
+
readonly attributes: Record<string, string>;
|
|
219
|
+
/** The customer's own identifier (SKU, EAN, artikelnummer, name code). */
|
|
220
|
+
readonly reference: string;
|
|
221
|
+
/** Price in minor units (cents), exactly as the source displays it. */
|
|
222
|
+
readonly priceCents: number;
|
|
223
|
+
readonly availability: Availability$1;
|
|
224
|
+
/** Provenance (manual | imported); audit-only, unused by the resolver. */
|
|
225
|
+
readonly source: 'manual' | 'imported';
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* A model's pricing document. The viewer's fetcher merges it into the model
|
|
229
|
+
* metadata and the server forwards it to the client via {@link PricingMessage}.
|
|
230
|
+
*/
|
|
231
|
+
interface PricingDocument$1 {
|
|
232
|
+
/** Optimistic-concurrency version from the editor; unused by the viewer. */
|
|
233
|
+
readonly version: number;
|
|
234
|
+
/** Customer-authored CTA label; null when the adapter's defaultLabel fills in. */
|
|
235
|
+
readonly buttonLabel: string | null;
|
|
236
|
+
/** ISO 4217 currency code for price formatting. */
|
|
237
|
+
readonly currency: string;
|
|
238
|
+
/** VAT label for bare embeds, e.g. "incl. btw". */
|
|
239
|
+
readonly vatDisplay: string;
|
|
240
|
+
readonly rules: PricingRule$1[];
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Pricing (server → client): the model's pricing document. Sent once at startup
|
|
244
|
+
* after MAPPING so the client's resolver can price the current configuration.
|
|
245
|
+
*/
|
|
246
|
+
interface PricingMessage {
|
|
247
|
+
readonly type: typeof MESSAGE_TYPES.PRICING;
|
|
248
|
+
readonly pricing: PricingDocument$1;
|
|
249
|
+
}
|
|
250
|
+
type Message = HandshakeMessage | SessionMessage | MutationMessage | MutationResultMessage | CameraCommandMessage | CameraPositionMessage | SnapshotRequestMessage | SnapshotResultMessage | MappingMessage | LoadingIndicatorMessage | ArActivateMessage | FullscreenMessage | ConfigMessage | AnnotationToggleMessage | FocusMessage | FocusStateMessage | PricingMessage;
|
|
251
|
+
type MessageCallback = (message: Message) => void | Promise<void>;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Options for IframeMessenger
|
|
255
|
+
*/
|
|
256
|
+
interface MessengerOptions {
|
|
257
|
+
/**
|
|
258
|
+
* Buffer incoming messages until markConsumerReady().
|
|
259
|
+
* When false (default), incoming messages are processed immediately.
|
|
260
|
+
*/
|
|
261
|
+
bufferIncoming?: boolean;
|
|
262
|
+
/**
|
|
263
|
+
* When buffering, messages where this returns false bypass the buffer
|
|
264
|
+
* and are routed to handlers immediately. Used for urgent messages
|
|
265
|
+
* like CONFIG that must be handled before the model loads.
|
|
266
|
+
*/
|
|
267
|
+
shouldBuffer?: (message: Message) => boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Restrict postMessage to a specific origin (e.g. 'https://example.com').
|
|
270
|
+
* Defaults to '*' when not set. Set this when the target origin is known
|
|
271
|
+
* to prevent messages from being intercepted by unintended recipients.
|
|
272
|
+
*/
|
|
273
|
+
targetOrigin?: string;
|
|
274
|
+
/**
|
|
275
|
+
* Which protocol to validate incoming messages against — not whether to validate.
|
|
276
|
+
* Both sides always reject browser-extension noise and unknown message types. The
|
|
277
|
+
* default (`isValidMessageData`) accepts the public protocol; the studio side passes
|
|
278
|
+
* `isValidStudioMessageData`, which accepts the public protocol plus the studio
|
|
279
|
+
* messages (e.g. annotation placement), so the public bundle stays lean.
|
|
280
|
+
*/
|
|
281
|
+
isValid?: (data: unknown) => boolean;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Bidirectional iframe message port
|
|
285
|
+
*
|
|
286
|
+
* Handles sending and receiving messages via postMessage between
|
|
287
|
+
* a parent page and an iframe. Both client and server use this —
|
|
288
|
+
* the only difference is the target window.
|
|
289
|
+
*
|
|
290
|
+
* Features:
|
|
291
|
+
* - Publisher queue: outgoing messages buffered until markReady()
|
|
292
|
+
* - Consumer queue: incoming messages buffered until markConsumerReady() (opt-in)
|
|
293
|
+
* - Handler registration: route incoming messages by type
|
|
294
|
+
* - Echo prevention: tags outgoing messages to filter self-delivery
|
|
295
|
+
* - Cleanup: removes listener on destroy
|
|
296
|
+
*
|
|
297
|
+
* @example Client (parent page — publisher queue only)
|
|
298
|
+
* ```ts
|
|
299
|
+
* const messenger = new IframeMessenger(() => iframe.contentWindow);
|
|
300
|
+
* messenger.on('mutation', handleMutationResult);
|
|
301
|
+
* messenger.on('mapping', handleMapping);
|
|
302
|
+
* messenger.start();
|
|
303
|
+
* // When iframe loads:
|
|
304
|
+
* messenger.markReady();
|
|
305
|
+
* messenger.send({ type: 'mutation', mutations, isInitial: true });
|
|
306
|
+
* ```
|
|
307
|
+
*
|
|
308
|
+
* @example Server (inside iframe — both queues, CONFIG bypasses consumer)
|
|
309
|
+
* ```ts
|
|
310
|
+
* const messenger = new IframeMessenger(
|
|
311
|
+
* () => window.parent !== window ? window.parent : null,
|
|
312
|
+
* { bufferIncoming: true, shouldBuffer: (msg) => msg.type !== 'config' },
|
|
313
|
+
* );
|
|
314
|
+
* messenger.on('mutation', processMutation);
|
|
315
|
+
* messenger.on('config', applyConfig);
|
|
316
|
+
* messenger.start();
|
|
317
|
+
* messenger.markReady();
|
|
318
|
+
* // When model loads:
|
|
319
|
+
* messenger.markConsumerReady();
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
declare class IframeMessenger {
|
|
323
|
+
private readonly getTarget;
|
|
324
|
+
private readonly handlers;
|
|
325
|
+
private readonly publisher;
|
|
326
|
+
private readonly consumer;
|
|
327
|
+
private readonly shouldBuffer;
|
|
328
|
+
private listener;
|
|
329
|
+
private readonly sourceId;
|
|
330
|
+
private targetOrigin;
|
|
331
|
+
private readonly isValid;
|
|
332
|
+
constructor(getTarget: () => Window | null, options?: MessengerOptions);
|
|
333
|
+
/**
|
|
334
|
+
* Register a handler for a specific message type
|
|
335
|
+
*/
|
|
336
|
+
on(type: string, handler: MessageCallback): void;
|
|
337
|
+
/**
|
|
338
|
+
* Remove a handler for a specific message type
|
|
339
|
+
*/
|
|
340
|
+
off(type: string): void;
|
|
341
|
+
/**
|
|
342
|
+
* Update the target origin for outgoing postMessage calls.
|
|
343
|
+
* Use when the target origin is discovered at runtime (e.g. from the first incoming message).
|
|
344
|
+
*/
|
|
345
|
+
setTargetOrigin(origin: string): void;
|
|
346
|
+
/**
|
|
347
|
+
* Send a message to the target window
|
|
348
|
+
* Queued until markReady() is called
|
|
349
|
+
*/
|
|
350
|
+
send(message: Message): void;
|
|
351
|
+
/**
|
|
352
|
+
* Enable sending and flush queued outgoing messages
|
|
353
|
+
*/
|
|
354
|
+
markReady(): void;
|
|
355
|
+
/**
|
|
356
|
+
* Enable processing of buffered incoming messages
|
|
357
|
+
* Only relevant when constructed with bufferIncoming: true
|
|
358
|
+
*/
|
|
359
|
+
markConsumerReady(): void;
|
|
360
|
+
/**
|
|
361
|
+
* Check if an incoming message of a specific type is pending in the consumer buffer
|
|
362
|
+
*/
|
|
363
|
+
consumerHasPending(type: string): boolean;
|
|
364
|
+
/**
|
|
365
|
+
* Start listening for incoming messages
|
|
366
|
+
*/
|
|
367
|
+
start(): void;
|
|
368
|
+
/**
|
|
369
|
+
* Stop listening and clean up all state
|
|
370
|
+
*/
|
|
371
|
+
destroy(): void;
|
|
372
|
+
/**
|
|
373
|
+
* Whether the messenger is ready to send
|
|
374
|
+
*/
|
|
375
|
+
get ready(): boolean;
|
|
376
|
+
/**
|
|
377
|
+
* Number of messages waiting in the outgoing queue
|
|
378
|
+
*/
|
|
379
|
+
get pendingCount(): number;
|
|
380
|
+
private post;
|
|
381
|
+
private routeToHandler;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
type SendFn$1 = (message: Message) => void;
|
|
385
|
+
/**
|
|
386
|
+
* Annotation display controls for the viewer: show or hide existing markers.
|
|
387
|
+
*
|
|
388
|
+
* Placement (click-to-place for the editor) is a studio capability and lives in
|
|
389
|
+
* `@virtualdisplay.io/client-studio`, never in the public client or its engine surface.
|
|
390
|
+
*/
|
|
391
|
+
declare class Annotations {
|
|
392
|
+
private readonly send;
|
|
393
|
+
constructor(send: SendFn$1);
|
|
394
|
+
setEnabled(enabled: boolean): void;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Camera control API for positioning and zoom
|
|
399
|
+
* Uses chaining pattern for building commands
|
|
400
|
+
*/
|
|
401
|
+
declare class Camera {
|
|
402
|
+
private readonly send;
|
|
403
|
+
private commands;
|
|
404
|
+
constructor(send: MessageCallback);
|
|
405
|
+
/**
|
|
406
|
+
* Rotate camera horizontally
|
|
407
|
+
* @param degrees - Absolute rotation in degrees (0 = front view)
|
|
408
|
+
* @throws VirtualdisplayError if value is not a finite number
|
|
409
|
+
*/
|
|
410
|
+
rotate(degrees: number): this;
|
|
411
|
+
/**
|
|
412
|
+
* Tilt camera vertically
|
|
413
|
+
* @param degrees - Absolute tilt in degrees (0 = top view, 90 = horizontal)
|
|
414
|
+
* @throws VirtualdisplayError if value is not a finite number
|
|
415
|
+
*/
|
|
416
|
+
tilt(degrees: number): this;
|
|
417
|
+
/**
|
|
418
|
+
* Zoom camera
|
|
419
|
+
* @param percentage - Zoom percentage (100 = normal, >100 = zoom in, <100 = zoom out)
|
|
420
|
+
* @throws VirtualdisplayError if value is not a finite number
|
|
421
|
+
*/
|
|
422
|
+
zoom(percentage: number): this;
|
|
423
|
+
/**
|
|
424
|
+
* Execute accumulated camera commands
|
|
425
|
+
* @throws VirtualdisplayError if no commands have been accumulated
|
|
426
|
+
*/
|
|
427
|
+
set(): void;
|
|
428
|
+
private validateFiniteNumber;
|
|
429
|
+
/**
|
|
430
|
+
* Reset camera to initial position
|
|
431
|
+
* This is not chainable and executes immediately
|
|
432
|
+
*/
|
|
433
|
+
reset(): void;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Camera position state object
|
|
438
|
+
*/
|
|
439
|
+
interface CameraPositionState {
|
|
440
|
+
rotation: number;
|
|
441
|
+
tilt: number;
|
|
442
|
+
zoom: number;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Camera position state
|
|
446
|
+
* Tracks current rotation, tilt, zoom, and movement limits from server updates.
|
|
447
|
+
*/
|
|
448
|
+
declare class CameraPosition {
|
|
449
|
+
private readonly state;
|
|
450
|
+
private limitsState;
|
|
451
|
+
private readonly changeCallbacks;
|
|
452
|
+
constructor();
|
|
453
|
+
/**
|
|
454
|
+
* Get current rotation in degrees
|
|
455
|
+
*/
|
|
456
|
+
get rotation(): number;
|
|
457
|
+
/**
|
|
458
|
+
* Get current tilt in degrees
|
|
459
|
+
*/
|
|
460
|
+
get tilt(): number;
|
|
461
|
+
/**
|
|
462
|
+
* Get current zoom percentage
|
|
463
|
+
*/
|
|
464
|
+
get zoom(): number;
|
|
465
|
+
/**
|
|
466
|
+
* Subscribe to camera position changes.
|
|
467
|
+
* Also fires when limits are applied via applyLimits() so components
|
|
468
|
+
* can re-evaluate disabled states without a separate callback.
|
|
469
|
+
*/
|
|
470
|
+
onChange(callback: (position: CameraPositionState) => void): void;
|
|
471
|
+
/**
|
|
472
|
+
* Current camera movement limits (set from CONFIG message).
|
|
473
|
+
* Undefined until the server sends limits in its CONFIG payload.
|
|
474
|
+
*/
|
|
475
|
+
get limits(): CameraLimits | undefined;
|
|
476
|
+
/**
|
|
477
|
+
* Apply camera limits received from the server CONFIG message.
|
|
478
|
+
* Fires onChange callbacks so button disabled states update immediately.
|
|
479
|
+
*/
|
|
480
|
+
applyLimits(limits: CameraLimits | undefined): void;
|
|
481
|
+
/**
|
|
482
|
+
* Handle incoming camera position message from server
|
|
483
|
+
*/
|
|
484
|
+
handlePositionUpdate(message: CameraPositionMessage): void;
|
|
485
|
+
/**
|
|
486
|
+
* Update camera position from server transforms
|
|
487
|
+
*/
|
|
488
|
+
update(transforms: CameraParameter[]): void;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** The buyer's current configuration as attribute name→value pairs. */
|
|
492
|
+
type Selection = Record<string, string>;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* The buyer's current configuration once it resolves to a price. `availability`
|
|
496
|
+
* is `available` (price + submit) or `view_only` (price, no submit); a matched
|
|
497
|
+
* `hidden` rule and a no-match both surface as `undefined` instead.
|
|
498
|
+
*/
|
|
499
|
+
interface ResolvedConfiguration {
|
|
500
|
+
readonly attributes: Record<string, string>;
|
|
501
|
+
readonly reference: string;
|
|
502
|
+
/** Price in minor units (cents), exactly as the source displays it. */
|
|
503
|
+
readonly price: number;
|
|
504
|
+
readonly currency: string;
|
|
505
|
+
readonly availability: 'available' | 'view_only';
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* What submit hands to the host: the buyer's selection and the reference to act
|
|
509
|
+
* on. Deliberately carries no price — the shop's checkout price is binding and
|
|
510
|
+
* ours is display-only, so handing it into the cart hand-off would only invite a
|
|
511
|
+
* wrong-price error. Price stays on the display side (`current`, `onChange`).
|
|
512
|
+
*/
|
|
513
|
+
interface SubmittedConfiguration {
|
|
514
|
+
readonly attributes: Record<string, string>;
|
|
515
|
+
readonly reference: string;
|
|
516
|
+
}
|
|
517
|
+
type ChangeCallback = (configuration: ResolvedConfiguration | undefined) => void;
|
|
518
|
+
type SubmitCallback = (configuration: SubmittedConfiguration) => void | Promise<unknown>;
|
|
519
|
+
type Dispatch<T> = (detail: T) => void;
|
|
520
|
+
/** Options for {@link Configuration.onSubmit}. */
|
|
521
|
+
interface SubmitOptions {
|
|
522
|
+
/** Fallback button label when the customer authored none (the adapter brings it). */
|
|
523
|
+
readonly defaultLabel?: string;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Configuration API — resolves the buyer's selection to a reference + price and
|
|
527
|
+
* carries it to the host page.
|
|
528
|
+
*
|
|
529
|
+
* Follows the existing facade style (`client.camera`, `client.focus`). It holds
|
|
530
|
+
* the pricing document and the latest selection, re-resolving on every change.
|
|
531
|
+
* `onChange` fires with the resolved configuration (or `undefined` when nothing
|
|
532
|
+
* matches); alongside it the container dispatches a bubbling `vd:configuration-change`
|
|
533
|
+
* CustomEvent so a page reacts without registering a callback. `onSubmit` registers
|
|
534
|
+
* the host handler that the CTA hands the configuration to.
|
|
535
|
+
*/
|
|
536
|
+
declare class Configuration {
|
|
537
|
+
private readonly dispatchChange;
|
|
538
|
+
private readonly dispatchSubmit;
|
|
539
|
+
private pricing;
|
|
540
|
+
private selection;
|
|
541
|
+
private resolved;
|
|
542
|
+
private readonly changeCallbacks;
|
|
543
|
+
private readonly renderCallbacks;
|
|
544
|
+
private submitCallback;
|
|
545
|
+
private submitDefaultLabel;
|
|
546
|
+
constructor(dispatchChange: Dispatch<ResolvedConfiguration | undefined>, dispatchSubmit: Dispatch<SubmittedConfiguration>);
|
|
547
|
+
/** The resolved configuration, or undefined when nothing matches. */
|
|
548
|
+
get current(): ResolvedConfiguration | undefined;
|
|
549
|
+
/** The VAT label for bare embeds (e.g. "incl. btw"), or undefined without pricing. */
|
|
550
|
+
get vatDisplay(): string | undefined;
|
|
551
|
+
/**
|
|
552
|
+
* The CTA label: the customer's `button_label`, or the adapter's `defaultLabel`
|
|
553
|
+
* when that is empty. Undefined when neither is set — a button must know what
|
|
554
|
+
* it says, so the CTA does not render.
|
|
555
|
+
*/
|
|
556
|
+
get buttonLabel(): string | undefined;
|
|
557
|
+
/**
|
|
558
|
+
* Whether the current configuration may be submitted: a handler is registered
|
|
559
|
+
* and the configuration is either price-less or an `available` priced one. The
|
|
560
|
+
* CTA's visibility ({@link submitEnabled}) layers a label requirement on top of
|
|
561
|
+
* this; a programmatic `submit()` does not need a label.
|
|
562
|
+
*/
|
|
563
|
+
private get submittable();
|
|
564
|
+
/**
|
|
565
|
+
* Whether the CTA should render: the configuration is submittable and a label
|
|
566
|
+
* exists. A button must say something, so an empty label hides the CTA rather
|
|
567
|
+
* than rendering blank.
|
|
568
|
+
*/
|
|
569
|
+
get submitEnabled(): boolean;
|
|
570
|
+
/**
|
|
571
|
+
* Subscribe to configuration changes. Fires after every selection change with
|
|
572
|
+
* the resolved configuration, including undefined when nothing matches.
|
|
573
|
+
*/
|
|
574
|
+
onChange(callback: ChangeCallback): void;
|
|
575
|
+
/**
|
|
576
|
+
* Register the submit handler the CTA hands the configuration to. Registering
|
|
577
|
+
* one is what switches the button on (capability driven). `defaultLabel` fills
|
|
578
|
+
* in when the customer authored no button label.
|
|
579
|
+
*/
|
|
580
|
+
onSubmit(callback: SubmitCallback, options?: SubmitOptions): void;
|
|
581
|
+
/**
|
|
582
|
+
* Subscribe the built-in UI to re-render the price + CTA. Fires on every
|
|
583
|
+
* resolve and when a submit handler is registered (which can switch the button
|
|
584
|
+
* on without a configuration change). Separate from `onChange`, which stays the
|
|
585
|
+
* host-facing, mutation-driven contract. Returns a disposer.
|
|
586
|
+
*/
|
|
587
|
+
onRender(callback: () => void): () => void;
|
|
588
|
+
/**
|
|
589
|
+
* Hand the current configuration to the registered handler and fire the
|
|
590
|
+
* bubbling `vd:configuration-submit` event. No-op without a handler or a
|
|
591
|
+
* resolved configuration. Returns the handler's promise so the caller can
|
|
592
|
+
* reflect the result (bezig / gelukt / mislukt).
|
|
593
|
+
*/
|
|
594
|
+
submit(): Promise<void>;
|
|
595
|
+
/** Called by the client when a PRICING message arrives from the viewer. */
|
|
596
|
+
handlePricingReceived(pricing: PricingDocument$1): void;
|
|
597
|
+
/** Called by the client after every mutation result, with the full selection. */
|
|
598
|
+
handleSelectionChanged(selection: Selection): void;
|
|
599
|
+
private recompute;
|
|
600
|
+
private notifyRender;
|
|
601
|
+
private resolve;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/** The focus state reported to `onChange` and the `vd:focus-change` event. */
|
|
605
|
+
interface FocusState {
|
|
606
|
+
readonly component: string;
|
|
607
|
+
readonly attributes: string[];
|
|
608
|
+
}
|
|
609
|
+
type FocusChange = FocusState | null;
|
|
610
|
+
type FocusChangeCallback = (state: FocusChange) => void;
|
|
611
|
+
type DispatchFn = (state: FocusChange) => void;
|
|
612
|
+
/**
|
|
613
|
+
* Focus control API — isolate and frame a component, or return to overview.
|
|
614
|
+
*
|
|
615
|
+
* Programmatic by design: `set('Seat')` needs no user selection, which is how the
|
|
616
|
+
* (future) component menu and the portal/admin editors drive it over the same
|
|
617
|
+
* message bus. Alongside `onChange`, the container dispatches a bubbling
|
|
618
|
+
* `vd:focus-change` CustomEvent so a page can react without registering a callback.
|
|
619
|
+
*/
|
|
620
|
+
declare class Focus {
|
|
621
|
+
private readonly send;
|
|
622
|
+
private readonly dispatch;
|
|
623
|
+
private focused;
|
|
624
|
+
private attributes;
|
|
625
|
+
private readonly changeCallbacks;
|
|
626
|
+
constructor(send: MessageCallback, dispatch: DispatchFn);
|
|
627
|
+
/** The focused component name, or null in overview. */
|
|
628
|
+
get current(): string | null;
|
|
629
|
+
/**
|
|
630
|
+
* Focus a component by name. Sends a focus message to the viewer.
|
|
631
|
+
* @throws VirtualdisplayError if component is not a non-empty string
|
|
632
|
+
*/
|
|
633
|
+
set(component: string): void;
|
|
634
|
+
/** Return to the overview — unfocus the current component. */
|
|
635
|
+
clear(): void;
|
|
636
|
+
/**
|
|
637
|
+
* Subscribe to focus changes. The callback fires with the focus state when a
|
|
638
|
+
* component is focused, and with null when returning to overview.
|
|
639
|
+
*/
|
|
640
|
+
onChange(callback: FocusChangeCallback): void;
|
|
641
|
+
/** Called by the client when a FocusStateMessage is received from the viewer. */
|
|
642
|
+
handleStateReceived(message: FocusStateMessage): void;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Error codes for Virtualdisplay client errors
|
|
647
|
+
*/
|
|
648
|
+
declare const ERROR_CODES: {
|
|
649
|
+
readonly NO_MAPPING: "NO_MAPPING";
|
|
650
|
+
readonly ATTRIBUTE_NOT_FOUND: "ATTRIBUTE_NOT_FOUND";
|
|
651
|
+
readonly VALUE_NOT_FOUND: "VALUE_NOT_FOUND";
|
|
652
|
+
readonly PARENT_NOT_FOUND: "PARENT_NOT_FOUND";
|
|
653
|
+
readonly INVALID_PARAMETER: "INVALID_PARAMETER";
|
|
654
|
+
readonly SNAPSHOT_FAILED: "SNAPSHOT_FAILED";
|
|
655
|
+
};
|
|
656
|
+
type ErrorCode = typeof ERROR_CODES[keyof typeof ERROR_CODES];
|
|
657
|
+
/**
|
|
658
|
+
* Custom error class for Virtualdisplay client errors
|
|
659
|
+
*/
|
|
660
|
+
declare class VirtualdisplayError extends Error {
|
|
661
|
+
readonly code: ErrorCode;
|
|
662
|
+
constructor(message: string, code: ErrorCode);
|
|
663
|
+
static valueNotFound(attributeName: string, valueName: string): VirtualdisplayError;
|
|
664
|
+
static parentNotFound(selector: string): VirtualdisplayError;
|
|
665
|
+
static invalidParameter(reason: string): VirtualdisplayError;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
interface PhotoData {
|
|
669
|
+
readonly filename: string;
|
|
670
|
+
readonly data: string;
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Represents a photo being captured
|
|
674
|
+
* Pure domain object that manages callbacks for when the photo is developed
|
|
675
|
+
*/
|
|
676
|
+
declare class Photo {
|
|
677
|
+
private readonly filename;
|
|
678
|
+
private readonly developedCallbacks;
|
|
679
|
+
private readonly errorCallbacks;
|
|
680
|
+
private developed;
|
|
681
|
+
private failed;
|
|
682
|
+
private photoData;
|
|
683
|
+
constructor(filename: string);
|
|
684
|
+
/**
|
|
685
|
+
* Register a callback for when the photo is developed
|
|
686
|
+
* If the photo is already developed, the callback is called immediately
|
|
687
|
+
*
|
|
688
|
+
* @param callback Function to call with photo data
|
|
689
|
+
* @returns This Photo instance for chaining
|
|
690
|
+
*/
|
|
691
|
+
onDeveloped(callback: (photo: PhotoData) => void): this;
|
|
692
|
+
/**
|
|
693
|
+
* Register a callback for when the photo capture fails
|
|
694
|
+
*
|
|
695
|
+
* @param callback Function to call with error
|
|
696
|
+
* @returns This Photo instance for chaining
|
|
697
|
+
*/
|
|
698
|
+
onError(callback: (error: VirtualdisplayError) => void): this;
|
|
699
|
+
/**
|
|
700
|
+
* Get the filename for this photo
|
|
701
|
+
*/
|
|
702
|
+
getFilename(): string;
|
|
703
|
+
/**
|
|
704
|
+
* Mark the photo as developed and notify all callbacks
|
|
705
|
+
* This method is called by Snapshot when the photo data arrives from the server
|
|
706
|
+
*/
|
|
707
|
+
develop(photoData: PhotoData): void;
|
|
708
|
+
/**
|
|
709
|
+
* Mark the photo as failed and notify error callbacks
|
|
710
|
+
*/
|
|
711
|
+
fail(error: VirtualdisplayError): void;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* API for taking screenshots of the 3D model
|
|
716
|
+
* Following the camera analogy: take() triggers capture, onDeveloped() gets result
|
|
717
|
+
*/
|
|
718
|
+
declare class Snapshot {
|
|
719
|
+
private readonly send;
|
|
720
|
+
private readonly validExtensions;
|
|
721
|
+
private readonly pendingPhotos;
|
|
722
|
+
constructor(send: MessageCallback);
|
|
723
|
+
/**
|
|
724
|
+
* Take a snapshot of the current 3D model view
|
|
725
|
+
*
|
|
726
|
+
* @param filename The filename for the snapshot (must include valid extension)
|
|
727
|
+
* @returns Photo object for registering callbacks
|
|
728
|
+
* @throws VirtualdisplayError if filename is invalid
|
|
729
|
+
*/
|
|
730
|
+
take(filename: string): Photo;
|
|
731
|
+
/**
|
|
732
|
+
* Handle incoming snapshot result from server
|
|
733
|
+
* Matches the message to a pending photo by filename, then develops or fails it
|
|
734
|
+
*/
|
|
735
|
+
handleSnapshotResult(message: SnapshotResultMessage): void;
|
|
736
|
+
/**
|
|
737
|
+
* Fail any pending photos and forget them. Called from client destroy
|
|
738
|
+
* so callers awaiting onError() see a deterministic outcome instead of
|
|
739
|
+
* leaking captures whose results will never arrive.
|
|
740
|
+
*/
|
|
741
|
+
clear(): void;
|
|
742
|
+
/**
|
|
743
|
+
* Validate filename has a valid image extension
|
|
744
|
+
*/
|
|
745
|
+
private validateFilename;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Pure domain entity representing a single attribute value
|
|
750
|
+
* No side effects - only state
|
|
751
|
+
*/
|
|
752
|
+
declare class AttributeValue {
|
|
753
|
+
readonly value: string;
|
|
754
|
+
readonly attribute: string;
|
|
755
|
+
private isSelectedValue;
|
|
756
|
+
constructor(value: string, attribute: string);
|
|
757
|
+
get isSelected(): boolean;
|
|
758
|
+
setSelected(selected: boolean): void;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
interface AttributeOptions {
|
|
762
|
+
readonly name: string;
|
|
763
|
+
readonly values: string[];
|
|
764
|
+
readonly onSelect: (name: string, value: string) => void;
|
|
765
|
+
readonly defaultValue?: string;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Represents a single attribute with its available values
|
|
769
|
+
* Flat API - no source/target translation, works with server values directly
|
|
770
|
+
*/
|
|
771
|
+
declare class Attribute {
|
|
772
|
+
readonly name: string;
|
|
773
|
+
readonly defaultValue: string | undefined;
|
|
774
|
+
private readonly values;
|
|
775
|
+
private readonly onSelect;
|
|
776
|
+
private onChangeCallback?;
|
|
777
|
+
constructor(options: AttributeOptions);
|
|
778
|
+
/**
|
|
779
|
+
* Select a value for this attribute
|
|
780
|
+
* @throws {VirtualdisplayError} When value not found
|
|
781
|
+
*/
|
|
782
|
+
select(value: string): void;
|
|
783
|
+
getValues(): AttributeValue[];
|
|
784
|
+
getValue(value: string): AttributeValue | undefined;
|
|
785
|
+
/** The currently selected value, or undefined before any selection lands. */
|
|
786
|
+
get selected(): string | undefined;
|
|
787
|
+
/**
|
|
788
|
+
* Register callback that fires when selection changes
|
|
789
|
+
* Receives the newly selected AttributeValue
|
|
790
|
+
*/
|
|
791
|
+
onChange(callback: (selectedValue: AttributeValue) => void): void;
|
|
792
|
+
/**
|
|
793
|
+
* Update selection state from server mutation result
|
|
794
|
+
* Direct value comparison - no source/target translation
|
|
795
|
+
*/
|
|
796
|
+
handleResult(serverValue: string): void;
|
|
797
|
+
private createValues;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Configuration options for VirtualdisplayClient
|
|
802
|
+
*/
|
|
803
|
+
interface ClientOptions {
|
|
804
|
+
readonly parent: string | HTMLElement;
|
|
805
|
+
readonly model: string;
|
|
806
|
+
readonly license: string;
|
|
807
|
+
readonly debug?: boolean;
|
|
808
|
+
readonly language?: string;
|
|
809
|
+
/** W3C traceparent string to propagate to the viewer iframe for end-to-end tracing. */
|
|
810
|
+
readonly traceparent?: string;
|
|
811
|
+
/**
|
|
812
|
+
* Override viewer settings from metadata. Omitted fields use the metadata value.
|
|
813
|
+
* A warning is logged when an override differs from the metadata value.
|
|
814
|
+
*/
|
|
815
|
+
readonly viewerSettings?: Partial<ViewerSettings$1>;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* The Virtualdisplay client's DOM event names, in one registry.
|
|
820
|
+
*
|
|
821
|
+
* - `ui:*` events dispatch on the container (non-bubbling). They are the typed
|
|
822
|
+
* surface of `client.on(...)` — payloads in `VirtualdisplayUiEventMap` (./types).
|
|
823
|
+
* - `vd:*` events bubble into the customer's page, so a page can react with
|
|
824
|
+
* `addEventListener` without registering a client callback.
|
|
825
|
+
*/
|
|
826
|
+
declare const VD_EVENTS: {
|
|
827
|
+
/** Attribute selection requested (cancelable). `detail`: `{ attribute, value }`. */
|
|
828
|
+
readonly SELECT: "ui:select";
|
|
829
|
+
/** Attribute selection applied. `detail`: `{ attribute, value }`. */
|
|
830
|
+
readonly SELECTED: "ui:selected";
|
|
831
|
+
/** Focus changed (bubbles). `detail`: `{ component, attributes }`, or `null` for the overview. */
|
|
832
|
+
readonly FOCUS_CHANGE: "vd:focus-change";
|
|
833
|
+
/** Resolved configuration changed (bubbles). `detail`: the resolved configuration, or `null` when nothing matches. */
|
|
834
|
+
readonly CONFIGURATION_CHANGE: "vd:configuration-change";
|
|
835
|
+
/** Configuration submitted (bubbles). `detail`: the resolved configuration handed to the host. */
|
|
836
|
+
readonly CONFIGURATION_SUBMIT: "vd:configuration-submit";
|
|
837
|
+
};
|
|
838
|
+
type VdEvent = typeof VD_EVENTS[keyof typeof VD_EVENTS];
|
|
839
|
+
|
|
840
|
+
interface MutationFailedEvent {
|
|
841
|
+
readonly attribute: string;
|
|
842
|
+
readonly value: string;
|
|
843
|
+
}
|
|
844
|
+
interface VirtualdisplaySelectEvent {
|
|
845
|
+
readonly attribute: string;
|
|
846
|
+
readonly value: string;
|
|
847
|
+
preventDefault(): void;
|
|
848
|
+
}
|
|
849
|
+
interface VirtualdisplaySelectedEvent {
|
|
850
|
+
readonly attribute: string;
|
|
851
|
+
readonly value: string;
|
|
852
|
+
}
|
|
853
|
+
type VirtualdisplayUiEventMap = {
|
|
854
|
+
[VD_EVENTS.SELECT]: VirtualdisplaySelectEvent;
|
|
855
|
+
[VD_EVENTS.SELECTED]: VirtualdisplaySelectedEvent;
|
|
856
|
+
};
|
|
857
|
+
type VirtualdisplayUiEventType = keyof VirtualdisplayUiEventMap;
|
|
858
|
+
|
|
859
|
+
type SendFn = (message: Message) => void;
|
|
860
|
+
/**
|
|
861
|
+
* Extensions a subclass (the studio client) layers onto the base composition without
|
|
862
|
+
* re-implementing it: a custom incoming-message validator and extra message handlers.
|
|
863
|
+
*/
|
|
864
|
+
interface BaseClientExtensions {
|
|
865
|
+
readonly messengerOptions?: MessengerOptions;
|
|
866
|
+
readonly registerHandlers?: (messenger: IframeMessenger, send: SendFn) => void;
|
|
867
|
+
/**
|
|
868
|
+
* The server host this client's viewer iframe targets — a fixed fact per client
|
|
869
|
+
* type, injected like the validator, not a per-instance setting. The studio client
|
|
870
|
+
* fixes it to the studio viewer build; the public client leaves it unset and uses
|
|
871
|
+
* the default public viewer. Both clients are bundled into one portal/admin build,
|
|
872
|
+
* so the host cannot be a single build-time env shared by both.
|
|
873
|
+
*/
|
|
874
|
+
readonly serverHost?: string;
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* The shared client composition root. Wires the engine (transport, facades, UI) and exposes
|
|
878
|
+
* the buyer-facing API. The public `VirtualdisplayClient` is this base as-is; the studio
|
|
879
|
+
* client extends it with the studio facades via {@link BaseClientExtensions}.
|
|
880
|
+
*/
|
|
881
|
+
declare class BaseClient {
|
|
882
|
+
private readonly attributes;
|
|
883
|
+
private readonly readyStateTracker;
|
|
884
|
+
private readonly messenger;
|
|
885
|
+
private readonly cameraApi;
|
|
886
|
+
private readonly cameraPositionApi;
|
|
887
|
+
private readonly focusApi;
|
|
888
|
+
private readonly configurationApi;
|
|
889
|
+
private readonly snapshotApi;
|
|
890
|
+
private readonly annotationsApi;
|
|
891
|
+
private readonly eventBus;
|
|
892
|
+
private readonly ui;
|
|
893
|
+
private readonly qrModal;
|
|
894
|
+
private readonly options;
|
|
895
|
+
private readonly serverHost;
|
|
896
|
+
private iframe;
|
|
897
|
+
private container;
|
|
898
|
+
private readyCallbacks;
|
|
899
|
+
private readonly mutationFailedCallbacks;
|
|
900
|
+
/** The viewer's tracking session id, once the server announces it (SESSION). */
|
|
901
|
+
private viewerSessionId;
|
|
902
|
+
constructor(options: ClientOptions, extensions?: BaseClientExtensions);
|
|
903
|
+
/** Wire the inbound viewer protocol to the facades. */
|
|
904
|
+
private wireIncomingMessages;
|
|
905
|
+
/**
|
|
906
|
+
* Dispatch a bubbling `vd:focus-change` event on the container so a page can
|
|
907
|
+
* react to focus without registering an `onChange` callback.
|
|
908
|
+
*/
|
|
909
|
+
private dispatchFocusChange;
|
|
910
|
+
/**
|
|
911
|
+
* Dispatch a bubbling `vd:configuration-change` event on the container so a
|
|
912
|
+
* page or tag manager can react to price changes without a client callback.
|
|
913
|
+
*/
|
|
914
|
+
private dispatchConfigurationChange;
|
|
915
|
+
/** Dispatch a bubbling `vd:configuration-submit` event when the CTA is used. */
|
|
916
|
+
private dispatchConfigurationSubmit;
|
|
917
|
+
private handleConfig;
|
|
918
|
+
private activateAr;
|
|
919
|
+
/** Tell the viewer the user entered fullscreen, so it records the engagement. */
|
|
920
|
+
private trackFullscreen;
|
|
921
|
+
private initializeLogging;
|
|
922
|
+
private createAndConnectIframe;
|
|
923
|
+
select(name: string, value: string): void;
|
|
924
|
+
getValues(name: string): AttributeValue[];
|
|
925
|
+
getValue(name: string, value: string): AttributeValue | undefined;
|
|
926
|
+
onChange(name: string, callback: (selectedValue: AttributeValue) => void): void;
|
|
927
|
+
getAttribute(name: string): Attribute | undefined;
|
|
928
|
+
get isReady(): boolean;
|
|
929
|
+
onReady(callback: (client: this) => void): void;
|
|
930
|
+
onMutationFailed(callback: (event: MutationFailedEvent) => void): void;
|
|
931
|
+
on<T extends VirtualdisplayUiEventType>(type: T, callback: (event: VirtualdisplayUiEventMap[T]) => void): void;
|
|
932
|
+
get annotations(): Annotations;
|
|
933
|
+
get camera(): Camera;
|
|
934
|
+
get focus(): Focus;
|
|
935
|
+
get configuration(): Configuration;
|
|
936
|
+
get cameraPosition(): CameraPosition;
|
|
937
|
+
get snapshot(): Snapshot;
|
|
938
|
+
/** The viewer's tracking session id, for a host page to correlate its own actions. */
|
|
939
|
+
get sessionId(): string | undefined;
|
|
940
|
+
get viewerSettings(): ViewerSettings$1;
|
|
941
|
+
destroy(): void;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
type Attrs = Record<string, unknown> | unknown;
|
|
945
|
+
declare let logger: {
|
|
946
|
+
debug: (msg: string, attrs?: Attrs) => void;
|
|
947
|
+
info: (msg: string, attrs?: Attrs) => void;
|
|
948
|
+
warn: (msg: string, attrs?: Attrs) => void;
|
|
949
|
+
error: (msg: string, attrs?: Attrs) => void;
|
|
950
|
+
};
|
|
951
|
+
declare function enableDebugMode(): void;
|
|
952
|
+
declare function isDebugMode(): boolean;
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* The public Virtualdisplay client: the shared base composition (transport, facades, the
|
|
956
|
+
* standard interface) with no studio capability. This is the buyer-facing SDK published as
|
|
957
|
+
* `@virtualdisplay.io/client`. The internal studio client adds the editing facades over the
|
|
958
|
+
* same base in `@virtualdisplay.io/client-studio`.
|
|
959
|
+
*/
|
|
960
|
+
declare class VirtualdisplayClient extends BaseClient {
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Viewer settings from model metadata (server → client via MAPPING).
|
|
965
|
+
* Customer-configured in the portal.
|
|
966
|
+
*/
|
|
967
|
+
interface ViewerSettings {
|
|
968
|
+
readonly ar?: boolean;
|
|
969
|
+
readonly fullscreen?: boolean;
|
|
970
|
+
readonly screenshot?: boolean;
|
|
971
|
+
readonly cameraControls?: boolean;
|
|
972
|
+
readonly annotations?: boolean;
|
|
973
|
+
readonly language?: string;
|
|
974
|
+
/** Where the attribute controls sit: in-frame bottom-left (default) or a docked right panel. */
|
|
975
|
+
readonly configuratorLayout?: 'inframe-bottom-left' | 'sidebar-right' | 'hidden';
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* What the configurator does with a matched configuration. Mirrors the backend
|
|
979
|
+
* `availability` enum (pricing rule provenance lives on `PricingRule.source`).
|
|
980
|
+
*/
|
|
981
|
+
declare const AVAILABILITY: {
|
|
982
|
+
/** Price and submit button both shown (default). */
|
|
983
|
+
readonly AVAILABLE: "available";
|
|
984
|
+
/** Price shown, submit hidden (sold out / coming soon). */
|
|
985
|
+
readonly VIEW_ONLY: "view_only";
|
|
986
|
+
/** Behaves exactly like an unpriced combination: no price, no button. */
|
|
987
|
+
readonly HIDDEN: "hidden";
|
|
988
|
+
};
|
|
989
|
+
type Availability = typeof AVAILABILITY[keyof typeof AVAILABILITY];
|
|
990
|
+
/**
|
|
991
|
+
* One pricing rule: a subset of attribute values mapped to a reference + price.
|
|
992
|
+
* Matches the backend pricing read contract (`GET /api/public/models/.../pricing`).
|
|
993
|
+
*/
|
|
994
|
+
interface PricingRule {
|
|
995
|
+
/**
|
|
996
|
+
* The attribute name→value pairs this rule names. `{}` is a catch-all;
|
|
997
|
+
* omitted names are wildcards. A rule matches when every pair equals the
|
|
998
|
+
* current selection; the rule naming the most attributes wins.
|
|
999
|
+
*/
|
|
1000
|
+
readonly attributes: Record<string, string>;
|
|
1001
|
+
/** The customer's own identifier (SKU, EAN, artikelnummer, name code). */
|
|
1002
|
+
readonly reference: string;
|
|
1003
|
+
/** Price in minor units (cents), exactly as the source displays it. */
|
|
1004
|
+
readonly priceCents: number;
|
|
1005
|
+
readonly availability: Availability;
|
|
1006
|
+
/** Provenance (manual | imported); audit-only, unused by the resolver. */
|
|
1007
|
+
readonly source: 'manual' | 'imported';
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* A model's pricing document. The viewer's fetcher merges it into the model
|
|
1011
|
+
* metadata and the server forwards it to the client via {@link PricingMessage}.
|
|
1012
|
+
*/
|
|
1013
|
+
interface PricingDocument {
|
|
1014
|
+
/** Optimistic-concurrency version from the editor; unused by the viewer. */
|
|
1015
|
+
readonly version: number;
|
|
1016
|
+
/** Customer-authored CTA label; null when the adapter's defaultLabel fills in. */
|
|
1017
|
+
readonly buttonLabel: string | null;
|
|
1018
|
+
/** ISO 4217 currency code for price formatting. */
|
|
1019
|
+
readonly currency: string;
|
|
1020
|
+
/** VAT label for bare embeds, e.g. "incl. btw". */
|
|
1021
|
+
readonly vatDisplay: string;
|
|
1022
|
+
readonly rules: PricingRule[];
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
export { Annotations, Attribute, AttributeValue, Camera, Configuration, ERROR_CODES, Focus, Photo, Snapshot, VD_EVENTS, VirtualdisplayClient, VirtualdisplayError, enableDebugMode, isDebugMode, logger };
|
|
1026
|
+
export type { Availability, ClientOptions, ErrorCode, FocusState, MutationFailedEvent, PhotoData, PricingDocument, PricingRule, ResolvedConfiguration, SubmitOptions, SubmittedConfiguration, VdEvent, ViewerSettings, VirtualdisplaySelectEvent, VirtualdisplaySelectedEvent, VirtualdisplayUiEventMap, VirtualdisplayUiEventType };
|