@expofp/renderer 1.5.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +90 -36
- package/dist/index.js +734 -379
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare interface ControlsAPI {
|
|
|
48
48
|
* @param immediate If true, applies the change immediately without animation
|
|
49
49
|
* @returns Promise that resolves when the zoom animation completes
|
|
50
50
|
*/
|
|
51
|
-
zoomBy(zoom: number, immediate?: boolean)
|
|
51
|
+
zoomBy: (zoom: number, immediate?: boolean) => Promise<void>;
|
|
52
52
|
/**
|
|
53
53
|
* Zooms the camera to fit the given rectangle.
|
|
54
54
|
* @param rect Rectangle to zoom to in SVG coordinates
|
|
@@ -56,7 +56,7 @@ export declare interface ControlsAPI {
|
|
|
56
56
|
* @param immediate If true, applies the change immediately without animation
|
|
57
57
|
* @returns Promise that resolves when the zoom animation completes
|
|
58
58
|
*/
|
|
59
|
-
zoomTo(rect: Rect, options?: Partial<ZoomToOptions>, immediate?: boolean)
|
|
59
|
+
zoomTo: (rect: Rect, options?: Partial<ZoomToOptions>, immediate?: boolean) => Promise<void>;
|
|
60
60
|
/**
|
|
61
61
|
* Pans the camera by the given offset in SVG space.
|
|
62
62
|
* @param x X offset in SVG space
|
|
@@ -64,7 +64,7 @@ export declare interface ControlsAPI {
|
|
|
64
64
|
* @param immediate If true, applies the change immediately without animation
|
|
65
65
|
* @returns Promise that resolves when the pan animation completes
|
|
66
66
|
*/
|
|
67
|
-
panBy(x: number, y: number, immediate?: boolean)
|
|
67
|
+
panBy: (x: number, y: number, immediate?: boolean) => Promise<void>;
|
|
68
68
|
/**
|
|
69
69
|
* Pans the camera to the given coordinates in SVG space.
|
|
70
70
|
* @param x X coordinate in SVG space
|
|
@@ -72,7 +72,7 @@ export declare interface ControlsAPI {
|
|
|
72
72
|
* @param immediate If true, applies the change immediately without animation
|
|
73
73
|
* @returns Promise that resolves when the pan animation completes
|
|
74
74
|
*/
|
|
75
|
-
panTo(x: number, y: number, immediate?: boolean)
|
|
75
|
+
panTo: (x: number, y: number, immediate?: boolean) => Promise<void>;
|
|
76
76
|
/**
|
|
77
77
|
* Rolls the camera by the given angle in degrees.
|
|
78
78
|
* Note: This method won't work if {@link ControlsAPI.handlers | handlers.roll} is disabled.
|
|
@@ -80,7 +80,7 @@ export declare interface ControlsAPI {
|
|
|
80
80
|
* @param immediate If true, applies the change immediately without animation
|
|
81
81
|
* @returns Promise that resolves when the roll animation completes
|
|
82
82
|
*/
|
|
83
|
-
rollBy(angle: number, immediate?: boolean)
|
|
83
|
+
rollBy: (angle: number, immediate?: boolean) => Promise<void>;
|
|
84
84
|
/**
|
|
85
85
|
* Rolls the camera to the given angle in degrees.
|
|
86
86
|
* Note: This method won't work if {@link ControlsAPI.handlers | handlers.roll} is disabled.
|
|
@@ -88,7 +88,7 @@ export declare interface ControlsAPI {
|
|
|
88
88
|
* @param immediate If true, applies the change immediately without animation
|
|
89
89
|
* @returns Promise that resolves when the roll animation completes
|
|
90
90
|
*/
|
|
91
|
-
rollTo(angle: number, immediate?: boolean)
|
|
91
|
+
rollTo: (angle: number, immediate?: boolean) => Promise<void>;
|
|
92
92
|
/**
|
|
93
93
|
* Pitches the camera by the given angle in degrees.
|
|
94
94
|
* Positive angles increase pitch, negative angles decrease pitch.
|
|
@@ -97,7 +97,7 @@ export declare interface ControlsAPI {
|
|
|
97
97
|
* @param immediate If true, applies the change immediately without animation
|
|
98
98
|
* @returns Promise that resolves when the pitch animation completes
|
|
99
99
|
*/
|
|
100
|
-
pitchBy(angle: number, immediate?: boolean)
|
|
100
|
+
pitchBy: (angle: number, immediate?: boolean) => Promise<void>;
|
|
101
101
|
/**
|
|
102
102
|
* Pitches the camera to the given angle in degrees.
|
|
103
103
|
* The angle is clamped to the 0-90 degree range.
|
|
@@ -106,30 +106,30 @@ export declare interface ControlsAPI {
|
|
|
106
106
|
* @param immediate If true, applies the change immediately without animation
|
|
107
107
|
* @returns Promise that resolves when the pitch animation completes
|
|
108
108
|
*/
|
|
109
|
-
pitchTo(angle: number, immediate?: boolean)
|
|
109
|
+
pitchTo: (angle: number, immediate?: boolean) => Promise<void>;
|
|
110
110
|
/**
|
|
111
111
|
* Resets the camera to the starting state.
|
|
112
112
|
* @param options Configuration for which handlers to reset
|
|
113
113
|
* @param immediate If true, applies the change immediately without animation
|
|
114
114
|
* @returns Promise that resolves when all reset animations complete
|
|
115
115
|
*/
|
|
116
|
-
resetCamera(options?: Partial<ResetCameraOptions>, immediate?: boolean)
|
|
116
|
+
resetCamera: (options?: Partial<ResetCameraOptions>, immediate?: boolean) => Promise<void>;
|
|
117
117
|
/**
|
|
118
118
|
* Configures smooth time values for camera operations.
|
|
119
119
|
* @param options Partial configuration object with time values in seconds
|
|
120
120
|
*/
|
|
121
|
-
configure(options: Partial<ConfigureOptions>)
|
|
121
|
+
configure: (options: Partial<ConfigureOptions>) => void;
|
|
122
122
|
/**
|
|
123
123
|
* Sets the camera bounds to restrict camera movement.
|
|
124
124
|
* Note: This method must be called after the viewport is initialized by `renderer.start()`.
|
|
125
125
|
* @param rect Rectangle in SVG coordinates defining the camera boundary or `undefined` to remove the boundary
|
|
126
126
|
*/
|
|
127
|
-
setCameraBounds(rect?: Rect)
|
|
127
|
+
setCameraBounds: (rect?: Rect) => void;
|
|
128
128
|
/**
|
|
129
129
|
* Gets the current camera state.
|
|
130
130
|
* @returns Camera state object with center, zoom, roll, pitch, and ptScale
|
|
131
131
|
*/
|
|
132
|
-
getCameraState()
|
|
132
|
+
getCameraState: () => CameraState;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/**
|
|
@@ -170,9 +170,27 @@ export declare type EventHandler<Payload> = (payload: Payload) => void;
|
|
|
170
170
|
* Public API for interacting with the event system
|
|
171
171
|
*/
|
|
172
172
|
export declare interface EventsAPI {
|
|
173
|
+
/**
|
|
174
|
+
* Add an event listener for a specific event
|
|
175
|
+
* @param event - The event to listen for
|
|
176
|
+
* @param handler - The handler to call when the event is emitted
|
|
177
|
+
*/
|
|
173
178
|
addEventListener<E extends keyof EngineEvents>(event: E, handler: EventHandler<EngineEvents[E]>): void;
|
|
179
|
+
/**
|
|
180
|
+
* Remove an event listener for a specific event
|
|
181
|
+
* @param event - The event to remove the listener for
|
|
182
|
+
* @param handler - The handler to remove
|
|
183
|
+
*/
|
|
174
184
|
removeEventListener<E extends keyof EngineEvents>(event: E, handler: EventHandler<EngineEvents[E]>): void;
|
|
185
|
+
/**
|
|
186
|
+
* Check if there are any listeners for a specific event
|
|
187
|
+
* @param event - The event to check
|
|
188
|
+
* @returns true if there are listeners, false otherwise
|
|
189
|
+
*/
|
|
175
190
|
hasListeners<E extends keyof EngineEvents>(event: E): boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Clear all event listeners
|
|
193
|
+
*/
|
|
176
194
|
clear(): void;
|
|
177
195
|
}
|
|
178
196
|
|
|
@@ -390,8 +408,6 @@ export declare type RenderableDefCollection<T = RenderableDef> = T extends Rende
|
|
|
390
408
|
* Main class for rendering the content of a {@link SceneDef}
|
|
391
409
|
*/
|
|
392
410
|
export declare class Renderer {
|
|
393
|
-
/** Whether to log debug information */
|
|
394
|
-
readonly debugLog: boolean;
|
|
395
411
|
/** {@link HTMLCanvasElement} that this renderer is rendering to */
|
|
396
412
|
readonly canvas: HTMLCanvasElement;
|
|
397
413
|
private ui?;
|
|
@@ -401,12 +417,17 @@ export declare class Renderer {
|
|
|
401
417
|
private viewportSystem;
|
|
402
418
|
private interactionsSystem;
|
|
403
419
|
private controlsSystem;
|
|
420
|
+
private controlsAPI?;
|
|
421
|
+
private eventsAPI?;
|
|
422
|
+
private viewportAPI?;
|
|
404
423
|
private clock;
|
|
405
424
|
private renderer;
|
|
406
|
-
private
|
|
407
|
-
private needsRedraw;
|
|
425
|
+
private visibleRectValue?;
|
|
408
426
|
private memoryInfoExtension;
|
|
409
|
-
private memoryInfo
|
|
427
|
+
private memoryInfo?;
|
|
428
|
+
private initialized;
|
|
429
|
+
private disposed;
|
|
430
|
+
private needsRedraw;
|
|
410
431
|
/**
|
|
411
432
|
* @param opts {@link RendererOptions}
|
|
412
433
|
*/
|
|
@@ -419,6 +440,10 @@ export declare class Renderer {
|
|
|
419
440
|
* {@link EventsAPI} instance for subscribing to internal events
|
|
420
441
|
*/
|
|
421
442
|
get events(): EventsAPI;
|
|
443
|
+
/**
|
|
444
|
+
* {@link ViewportAPI} instance for view transforms and external transforms.
|
|
445
|
+
*/
|
|
446
|
+
get viewport(): ViewportAPI;
|
|
422
447
|
/**
|
|
423
448
|
* Optional sub-rectangle of the viewport that is used for positioning scene's viewbox
|
|
424
449
|
*/
|
|
@@ -433,34 +458,37 @@ export declare class Renderer {
|
|
|
433
458
|
get context(): WebGLRenderer;
|
|
434
459
|
/* Excluded from this release type: size */
|
|
435
460
|
/**
|
|
436
|
-
*
|
|
437
|
-
*
|
|
461
|
+
* Returns true if the renderer is in external mode, meaning that webgl context is managed outside of the renderer
|
|
462
|
+
* (for example, when using Mapbox GL JS as a host context). In this mode renderer will not clear the canvas before
|
|
463
|
+
* rendering, and will not automatically compute scene and camera transformations. Clients are responsible for setting
|
|
464
|
+
* the matrices manually by using {@link Renderer.viewport} methods.
|
|
438
465
|
*/
|
|
439
|
-
|
|
466
|
+
get isExternalMode(): boolean;
|
|
440
467
|
/**
|
|
441
|
-
*
|
|
442
|
-
|
|
468
|
+
* Returns true if the renderer is initialized, meaning that the viewport and scene have been set up.
|
|
469
|
+
*/
|
|
470
|
+
get isInitialized(): boolean;
|
|
471
|
+
/**
|
|
472
|
+
* Returns true if the renderer is disposed, meaning that all WebGL resources have been released.
|
|
443
473
|
*/
|
|
444
|
-
|
|
474
|
+
get isDisposed(): boolean;
|
|
445
475
|
/**
|
|
446
|
-
*
|
|
476
|
+
* Initializes viewport and scene with the given scene definition.
|
|
477
|
+
* Should be called once on startup. Repeated calls will produce console warnings.
|
|
447
478
|
* @param sceneDef {@link SceneDef} to render
|
|
448
|
-
* @param startLoop whether to start the rendering loop
|
|
449
479
|
*/
|
|
450
|
-
|
|
480
|
+
init(sceneDef: SceneDef): void;
|
|
481
|
+
/**
|
|
482
|
+
* Start the rendering loop
|
|
483
|
+
*/
|
|
484
|
+
start(): void;
|
|
451
485
|
/**
|
|
452
486
|
* Update the given defs to make them reflect the current state
|
|
453
487
|
* @param defs {@link RenderableDef} array to update
|
|
454
488
|
*/
|
|
455
489
|
update(...defs: RenderableDef[]): void;
|
|
456
490
|
/**
|
|
457
|
-
*
|
|
458
|
-
* @param point point in canvas space (relative to the canvas's top left corner), in css pixels
|
|
459
|
-
* @returns point in SVG space
|
|
460
|
-
*/
|
|
461
|
-
screenToSvg(point: Vector2Like): Vector2Like;
|
|
462
|
-
/**
|
|
463
|
-
* Main rendering loop
|
|
491
|
+
* Render a single frame
|
|
464
492
|
*/
|
|
465
493
|
render(): void;
|
|
466
494
|
/**
|
|
@@ -468,13 +496,21 @@ export declare class Renderer {
|
|
|
468
496
|
*/
|
|
469
497
|
stop(): void;
|
|
470
498
|
/**
|
|
471
|
-
* Dispose all WebGL resources
|
|
499
|
+
* Dispose all WebGL resources. This calls {@link Renderer.stop} internally.
|
|
500
|
+
* WARNING: This method is final and cannot be undone. Attempting to use the renderer after calling this method
|
|
501
|
+
* will result in a console warning and no-op methods. If you need to re-initialize the renderer, create a new instance.
|
|
472
502
|
*/
|
|
473
503
|
dispose(): void;
|
|
474
504
|
private resizeCanvasToDisplaySize;
|
|
475
505
|
private updateMemoryInfo;
|
|
476
506
|
private onContextLost;
|
|
477
507
|
private onContextRestored;
|
|
508
|
+
private initContext;
|
|
509
|
+
private assertNotDisposed;
|
|
510
|
+
private assertInitialized;
|
|
511
|
+
private assertNotInitialized;
|
|
512
|
+
private assertNotExternalMode;
|
|
513
|
+
private assertExternalMode;
|
|
478
514
|
}
|
|
479
515
|
|
|
480
516
|
/**
|
|
@@ -485,8 +521,6 @@ export declare interface RendererOptions {
|
|
|
485
521
|
canvas: HTMLCanvasElement;
|
|
486
522
|
/** Optional {@link WebGLRenderingContext} to use (e.g. for Mapbox GL JS) */
|
|
487
523
|
gl?: WebGLRenderingContext;
|
|
488
|
-
/** Whether to log debug information */
|
|
489
|
-
debugLog?: boolean;
|
|
490
524
|
/** Optional partial {@link UI} configuration */
|
|
491
525
|
ui?: Partial<UI>;
|
|
492
526
|
}
|
|
@@ -595,6 +629,26 @@ export declare interface UI {
|
|
|
595
629
|
memoryInfoPanel: HTMLDivElement;
|
|
596
630
|
}
|
|
597
631
|
|
|
632
|
+
/** Viewport system public API. */
|
|
633
|
+
export declare interface ViewportAPI {
|
|
634
|
+
/**
|
|
635
|
+
* Convert canvas coordinates (CSS pixels, relative to canvas top-left) to SVG coordinates.
|
|
636
|
+
* @param point point in canvas space (CSS pixels)
|
|
637
|
+
* @returns point in SVG coordinates or undefined if point is outside the SVG plane
|
|
638
|
+
*/
|
|
639
|
+
canvasToSvg: (point: Vector2Like) => Vector2Like | undefined;
|
|
640
|
+
/**
|
|
641
|
+
* Set static part of an svg -> px transform matrix
|
|
642
|
+
* @param staticTransformMatrix static transform matrix to apply to the scene
|
|
643
|
+
*/
|
|
644
|
+
setStaticTransform: (staticTransformMatrix: number[]) => void;
|
|
645
|
+
/**
|
|
646
|
+
* Set dynamic part of an svg -> px transform matrix. Should be called every frame.
|
|
647
|
+
* @param dynamicTransformMatrix dynamic transform matrix (changes every frame)
|
|
648
|
+
*/
|
|
649
|
+
setDynamicTransform: (dynamicTransformMatrix: number[]) => void;
|
|
650
|
+
}
|
|
651
|
+
|
|
598
652
|
/** Options for the {@link ControlsAPI.zoomTo} method. */
|
|
599
653
|
export declare interface ZoomToOptions {
|
|
600
654
|
/** Maximum zoom factor. */
|