@virtualdisplay.io/client 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,503 @@
1
+ import { Logger } from '@virtualdisplay-io/logger';
2
+
3
+ /**
4
+ * Pure domain aggregate for managing attribute values
5
+ * No side effects - only business logic and state management
6
+ */
7
+ declare class Attribute {
8
+ private readonly attributeName;
9
+ private readonly values;
10
+ constructor(name: string);
11
+ addValue(attributeValue: AttributeValue): void;
12
+ /**
13
+ * Select a value - returns mutations needed for the change
14
+ * Pure function - no side effects
15
+ */
16
+ select(value: string): Mutation[];
17
+ getDefaultMutations(): Mutation[];
18
+ getCurrentValue(): AttributeValue | undefined;
19
+ getValue(valueName: string): AttributeValue | undefined;
20
+ getAllValues(): AttributeValue[];
21
+ hasValue(valueName: string): boolean;
22
+ get name(): string;
23
+ get currentSelection(): string | undefined;
24
+ }
25
+
26
+ /**
27
+ * Configuration for a single attribute
28
+ */
29
+ export declare interface AttributeConfig {
30
+ readonly name: string;
31
+ readonly values: AttributeValueConfig[];
32
+ }
33
+
34
+ /**
35
+ * Public API for selecting attribute values
36
+ * Provides fluent interface for client usage
37
+ */
38
+ export declare class AttributeSelector {
39
+ private readonly attributeService;
40
+ private readonly attributeName;
41
+ constructor(attributeService: AttributeService, attributeName: string);
42
+ /**
43
+ * Select a value for this attribute
44
+ * Fire-and-forget: returns immediately, 3D updates asynchronously
45
+ * @returns this AttributeSelector for method chaining
46
+ * @throws {VirtualdisplayError} When value not found for attribute
47
+ */
48
+ select(value: string): AttributeSelector;
49
+ get name(): string;
50
+ get currentValue(): string | undefined;
51
+ get availableValues(): string[];
52
+ /**
53
+ * Register a callback to be called when any value's selection state changes
54
+ * This registers the callback on all AttributeValue objects for this attribute
55
+ * @param callback Function to call when selection state changes
56
+ * @returns this AttributeSelector for method chaining
57
+ */
58
+ onChange(callback: () => void): AttributeSelector;
59
+ /**
60
+ * Get all AttributeValue objects for direct property access
61
+ * @returns Array of AttributeValue objects
62
+ */
63
+ getValues(): AttributeValue[];
64
+ /**
65
+ * Get a specific AttributeValue object by value name
66
+ * @param value The value name to find
67
+ * @returns AttributeValue object or undefined if not found
68
+ */
69
+ getValue(value: string): AttributeValue | undefined;
70
+ private getAttribute;
71
+ }
72
+
73
+ /**
74
+ * Application service for managing attributes
75
+ * Handles business logic and coordinates with other domains via events
76
+ */
77
+ declare class AttributeService {
78
+ private readonly attributes;
79
+ private readonly eventBus;
80
+ private isInitialized;
81
+ constructor(eventBus: EventBus);
82
+ /**
83
+ * Load mapping configuration and apply defaults
84
+ * @throws {VirtualdisplayError} When mapping configuration is invalid
85
+ */
86
+ loadMapping(config: MappingConfiguration): void;
87
+ selectAttributeValue(attributeName: string, value: string): void;
88
+ getAttribute(name: string): Attribute | undefined;
89
+ getAllAttributes(): Attribute[];
90
+ get initialized(): boolean;
91
+ private syncStateWithAttributes;
92
+ private getAttributeValueForNode;
93
+ clear(): void;
94
+ }
95
+
96
+ /**
97
+ * Pure domain entity representing a single attribute value
98
+ * No side effects - only business logic and data
99
+ */
100
+ declare class AttributeValue {
101
+ private readonly attributeValue;
102
+ private readonly nodeIds;
103
+ private selected;
104
+ onChange?: () => void;
105
+ constructor(value: string, nodeIds: string[], isSelected?: boolean);
106
+ getMutations(): Mutation[];
107
+ setSelected(selected: boolean): void;
108
+ get value(): string;
109
+ get nodeList(): string[];
110
+ hasNode(nodeId: string): boolean;
111
+ get isSelected(): boolean;
112
+ setOnChange(callback: () => void): void;
113
+ }
114
+
115
+ /**
116
+ * Configuration for a single attribute value
117
+ */
118
+ export declare interface AttributeValueConfig {
119
+ readonly value: string;
120
+ readonly nodeIds: string[];
121
+ readonly isSelected?: boolean;
122
+ }
123
+
124
+ /**
125
+ * Base message interface
126
+ */
127
+ declare interface BaseMessage {
128
+ readonly type: MessageType;
129
+ }
130
+
131
+ /**
132
+ * Configuration options for VirtualdisplayClient
133
+ */
134
+ export declare interface ClientOptions {
135
+ readonly parent: string | HTMLElement;
136
+ readonly model: string;
137
+ readonly license: string;
138
+ readonly debug?: boolean;
139
+ readonly language?: string;
140
+ }
141
+
142
+ declare interface CreateNodeParams {
143
+ id: string;
144
+ name: string;
145
+ type: NodeType;
146
+ visible: boolean;
147
+ }
148
+
149
+ /**
150
+ * Central Event Registry
151
+ */
152
+ export declare interface DomainEvents extends Record<string, unknown> {
153
+ [EVENT_NAMES.IFRAME_READY]: VoidEvent;
154
+ [EVENT_NAMES.MUTATION_MESSAGE]: MutationMessageEvent;
155
+ [EVENT_NAMES.MESSAGE_RECEIVED]: MessageReceivedEvent;
156
+ [EVENT_NAMES.STATE_CHANGED]: StateChangedEvent;
157
+ }
158
+
159
+ export declare function enableDebugMode(): void;
160
+
161
+ /**
162
+ * Error codes for Virtualdisplay client errors
163
+ */
164
+ export declare const ERROR_CODES: {
165
+ readonly NO_MAPPING: "NO_MAPPING";
166
+ readonly ATTRIBUTE_NOT_FOUND: "ATTRIBUTE_NOT_FOUND";
167
+ readonly VALUE_NOT_FOUND: "VALUE_NOT_FOUND";
168
+ readonly INVALID_MAPPING: "INVALID_MAPPING";
169
+ readonly PARENT_NOT_FOUND: "PARENT_NOT_FOUND";
170
+ readonly INVALID_MUTATIONS: "INVALID_MUTATIONS";
171
+ };
172
+
173
+ export declare type ErrorCode = typeof ERROR_CODES[keyof typeof ERROR_CODES];
174
+
175
+ /**
176
+ * Event name constants for type-safe event communication
177
+ */
178
+ export declare const EVENT_NAMES: {
179
+ readonly IFRAME_READY: "iframe:ready";
180
+ readonly MUTATION_MESSAGE: "mutation:message";
181
+ readonly MESSAGE_RECEIVED: "message:received";
182
+ readonly STATE_CHANGED: "state:changed";
183
+ };
184
+
185
+ /**
186
+ * EventBus for domain coordination
187
+ * Provides loose coupling between domains via events
188
+ */
189
+ declare class EventBus {
190
+ private readonly listeners;
191
+ on<K extends keyof DomainEvents>(event: K, listener: EventListener_2<DomainEvents[K]>): void;
192
+ emit<K extends keyof DomainEvents>(event: K, payload: DomainEvents[K]): void;
193
+ once<K extends keyof DomainEvents>(event: K, listener: EventListener_2<DomainEvents[K]>): void;
194
+ off<K extends keyof DomainEvents>(event: K, listener: EventListener_2<DomainEvents[K]>): void;
195
+ }
196
+
197
+ declare type EventListener_2<T> = (payload: T) => void;
198
+
199
+ export declare function isDebugMode(): boolean;
200
+
201
+ export declare const logger: Logger;
202
+
203
+ /**
204
+ * Complete mapping configuration
205
+ * Defines how product attributes map to 3D nodes
206
+ */
207
+ export declare interface MappingConfiguration {
208
+ readonly attributes: AttributeConfig[];
209
+ }
210
+
211
+ export declare const mappingSchema: {
212
+ "$schema": "http://json-schema.org/draft-07/schema#",
213
+ "title": "Virtualdisplay mapping configuration",
214
+ "description": "Schema for attribute-based 3D model configuration",
215
+ "type": "object",
216
+ "required": ["attributes"],
217
+ "definitions": {
218
+ "attribute": {
219
+ "type": "object",
220
+ "description": "A configurable attribute with multiple possible values",
221
+ "required": ["name", "values"],
222
+ "properties": {
223
+ "name": {
224
+ "type": "string",
225
+ "description": "Unique attribute name (e.g., 'Color', 'Size')",
226
+ "minLength": 1,
227
+ "pattern": "^\\S.*\\S$|^\\S$"
228
+ },
229
+ "values": {
230
+ "type": "array",
231
+ "description": "Possible values for this attribute",
232
+ "minItems": 1,
233
+ "items": {
234
+ "$ref": "#/definitions/attributeValue"
235
+ }
236
+ }
237
+ }
238
+ },
239
+ "attributeValue": {
240
+ "type": "object",
241
+ "description": "A single value option for an attribute",
242
+ "required": ["value", "nodeIds"],
243
+ "properties": {
244
+ "value": {
245
+ "type": "string",
246
+ "description": "Display value (e.g., 'Red', 'Large')",
247
+ "minLength": 1,
248
+ "pattern": "^\\S.*\\S$|^\\S$"
249
+ },
250
+ "nodeIds": {
251
+ "type": "array",
252
+ "description": "3D model node IDs controlled by this value",
253
+ "items": {
254
+ "type": "string",
255
+ "description": "Node ID in the 3D model"
256
+ }
257
+ },
258
+ "isSelected": {
259
+ "type": "boolean",
260
+ "description": "Whether this value is selected by default",
261
+ "default": false
262
+ }
263
+ }
264
+ }
265
+ },
266
+ "properties": {
267
+ "attributes": {
268
+ "type": "array",
269
+ "description": "List of all configurable attributes",
270
+ "minItems": 1,
271
+ "items": {
272
+ "$ref": "#/definitions/attribute"
273
+ }
274
+ }
275
+ }
276
+ };
277
+
278
+ /**
279
+ * Validator for mapping configuration using AJV
280
+ */
281
+ export declare class MappingValidator {
282
+ private static readonly ajv;
283
+ private static readonly validateFn;
284
+ /**
285
+ * Validate complete mapping configuration
286
+ * @throws {VirtualdisplayError} When mapping configuration is invalid
287
+ */
288
+ static validate(config: MappingConfiguration): void;
289
+ }
290
+
291
+ /**
292
+ * Union of all possible messages
293
+ */
294
+ export declare type Message = MutationMessage | StateMessage;
295
+
296
+ /**
297
+ * Types of messages exchanged between client and server
298
+ * Using lowercase format to match server
299
+ */
300
+ export declare const MESSAGE_TYPES: {
301
+ readonly MUTATION: "mutation";
302
+ readonly STATE: "state";
303
+ };
304
+
305
+ /**
306
+ * State Flow Events (Server → Client)
307
+ */
308
+ declare interface MessageReceivedEvent {
309
+ message: unknown;
310
+ }
311
+
312
+ declare type MessageType = typeof MESSAGE_TYPES[keyof typeof MESSAGE_TYPES];
313
+
314
+ /**
315
+ * Represents a 3D node in the scene
316
+ * Live object that can be updated to reflect state changes
317
+ */
318
+ export declare class ModelNode {
319
+ readonly id: string;
320
+ readonly name: string;
321
+ readonly type: NodeType;
322
+ private visible;
323
+ constructor(params: CreateNodeParams);
324
+ get isVisible(): boolean;
325
+ show(): void;
326
+ hide(): void;
327
+ }
328
+
329
+ /**
330
+ * DTO for model node data received from server
331
+ */
332
+ export declare interface ModelNodeDto {
333
+ readonly id: string;
334
+ readonly name: string;
335
+ readonly type: string;
336
+ readonly visible: boolean;
337
+ }
338
+
339
+ /**
340
+ * A mutation represents a change to be applied to a 3D node
341
+ * This is a pure data class with no side effects
342
+ */
343
+ export declare class Mutation {
344
+ readonly type: MutationType;
345
+ readonly nodeId: string;
346
+ constructor(type: MutationType, nodeId: string);
347
+ static show(nodeId: string): Mutation;
348
+ static hide(nodeId: string): Mutation;
349
+ inverse(): Mutation;
350
+ equals(other: Mutation): boolean;
351
+ toDto(): MutationDto;
352
+ }
353
+
354
+ /**
355
+ * Types of mutations that can be applied to 3D nodes
356
+ */
357
+ export declare const MUTATION_TYPES: {
358
+ readonly SHOW: "show";
359
+ readonly HIDE: "hide";
360
+ };
361
+
362
+ /**
363
+ * Data Transfer Object for mutations
364
+ * Plain object for client-server communication without methods
365
+ */
366
+ export declare interface MutationDto {
367
+ readonly type: MutationType;
368
+ readonly nodeId: string;
369
+ }
370
+
371
+ /**
372
+ * Mutation message sent to server
373
+ */
374
+ export declare interface MutationMessage extends BaseMessage {
375
+ readonly type: typeof MESSAGE_TYPES.MUTATION;
376
+ readonly mutations: MutationDto[];
377
+ }
378
+
379
+ /**
380
+ * Mutation Flow Events (Client → Server)
381
+ */
382
+ declare interface MutationMessageEvent {
383
+ message: MutationMessage;
384
+ }
385
+
386
+ export declare type MutationType = typeof MUTATION_TYPES[keyof typeof MUTATION_TYPES];
387
+
388
+ /**
389
+ * Types of nodes in the 3D scene
390
+ */
391
+ export declare const NODE_TYPES: {
392
+ readonly MESH: "mesh";
393
+ readonly VARIANT: "variant";
394
+ };
395
+
396
+ /**
397
+ * Public API for controlling individual nodes
398
+ * Provides direct node manipulation without attribute mapping
399
+ */
400
+ export declare class NodeSelector {
401
+ private readonly eventBus;
402
+ private readonly stateService;
403
+ private readonly nodeId;
404
+ constructor(eventBus: EventBus, stateService: StateService, nodeId: string);
405
+ show(): void;
406
+ hide(): void;
407
+ toggle(): void;
408
+ get id(): string;
409
+ get isVisible(): boolean;
410
+ getNode(): ModelNode | undefined;
411
+ get type(): string | undefined;
412
+ get name(): string | undefined;
413
+ private emitMutation;
414
+ }
415
+
416
+ declare type NodeType = typeof NODE_TYPES[keyof typeof NODE_TYPES];
417
+
418
+ declare interface StateChangedEvent {
419
+ nodes: ModelNode[];
420
+ }
421
+
422
+ /**
423
+ * State message received from server
424
+ * Contains array of model node DTOs
425
+ */
426
+ export declare interface StateMessage extends BaseMessage {
427
+ readonly type: typeof MESSAGE_TYPES.STATE;
428
+ readonly nodes: ModelNodeDto[];
429
+ }
430
+
431
+ /**
432
+ * Application service for managing node state
433
+ * Handles state updates from server and emits node change events
434
+ */
435
+ declare class StateService {
436
+ private readonly nodes;
437
+ private readonly eventBus;
438
+ constructor(eventBus: EventBus);
439
+ private handleMessage;
440
+ private updateState;
441
+ private updateOrCreateNode;
442
+ private createNewNode;
443
+ getNode(id: string): ModelNode | undefined;
444
+ getAllNodes(): ModelNode[];
445
+ get isReady(): boolean;
446
+ get nodeCount(): number;
447
+ private get hasInitialState();
448
+ clear(): void;
449
+ }
450
+
451
+ /**
452
+ * Main Virtualdisplay Client
453
+ * Provides the public API for 3D product visualization
454
+ */
455
+ export declare class VirtualdisplayClient {
456
+ private readonly eventBus;
457
+ private readonly attributeService;
458
+ private readonly stateService;
459
+ private readonly messageHandler;
460
+ private readonly options;
461
+ private iframe;
462
+ constructor(options: ClientOptions);
463
+ private initializeLogging;
464
+ private createAndConnectIframe;
465
+ /**
466
+ * Load attribute mapping configuration
467
+ * @throws {VirtualdisplayError} When mapping configuration is invalid
468
+ */
469
+ setMapping(config: MappingConfiguration): void;
470
+ /**
471
+ * Get attribute selector for fluent API
472
+ * @throws {VirtualdisplayError} When no mapping is configured or attribute not found
473
+ */
474
+ getAttribute(name: string): AttributeSelector;
475
+ /**
476
+ * Get node selector for direct node control
477
+ * @param nodeId The node ID to control
478
+ * @returns NodeSelector if node exists, undefined otherwise
479
+ */
480
+ getNodeSelector(nodeId: string): NodeSelector | undefined;
481
+ getNode(id: string): ModelNode | undefined;
482
+ getNodes(): ModelNode[];
483
+ destroy(): void;
484
+ }
485
+
486
+ /**
487
+ * Custom error class for Virtualdisplay client errors
488
+ */
489
+ export declare class VirtualdisplayError extends Error {
490
+ readonly code: ErrorCode;
491
+ constructor(message: string, code: ErrorCode);
492
+ static noMapping(): VirtualdisplayError;
493
+ static attributeNotFound(attributeName: string): VirtualdisplayError;
494
+ static valueNotFound(attributeName: string, valueName: string): VirtualdisplayError;
495
+ static invalidMapping(reason?: string): VirtualdisplayError;
496
+ static parentNotFound(selector: string): VirtualdisplayError;
497
+ static invalidMutations(reason?: string): VirtualdisplayError;
498
+ }
499
+
500
+ declare interface VoidEvent {
501
+ }
502
+
503
+ export { }