@micrio/client 5.5.6 → 6.0.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/micrio.min.d.ts CHANGED
@@ -12,8 +12,948 @@ declare module '@micrio/client' {
12
12
  * @returns A Promise resolving to the loaded TextureBitmap.
13
13
  */
14
14
  export const loadTexture: (src: string) => Promise<TextureBitmap>;
15
+ /**
16
+ * Engine-wide constants and math values.
17
+ * @author Marcel Duin <marcel@micr.io>
18
+ */
19
+ export const PI: number;
20
+ export const PIh: number;
21
+ export const PI2: number;
22
+ /** Number of horizontal segments for 360 sphere geometry. */
23
+ export const segsX = 16;
24
+ /** Number of vertical segments for 360 sphere geometry. */
25
+ export const segsY = 16;
26
+ /** Base distance for 360 space transitions. */
27
+ export const base360Distance = 8;
28
+ /** Calculates 2 to the power of num (2^num). */
29
+ export function twoNth(num: number): number;
30
+ /** Calculates the positive modulo (floored division remainder). */
31
+ export function mod(n: number, m?: number): number;
32
+ /** Calculates the modulo 1 of a number (keeps the fractional part, positive). @deprecated Use mod(n, 1) */
33
+ export const mod1: (n: number) => number;
34
+ /** Calculates the modulo 2*PI of a number (wraps angles to the range [0, 2*PI)). */
35
+ export function modPI(n: number): number;
36
+ /**
37
+ * Calculates the shortest angular distance between two longitude coordinates.
38
+ * Handles wrapping around the 360-degree sphere.
39
+ * @param from Starting longitude coordinate (0-1).
40
+ * @param to Target longitude coordinate (0-1).
41
+ * @returns The shortest signed distance (-0.5 to 0.5).
42
+ */
43
+ export function longitudeDistance(from: number, to: number): number;
44
+ /**
45
+ * Implements a cubic bezier curve calculation.
46
+ * Used for animation easing functions.
47
+ */
48
+ export class Bicubic {
49
+ private readonly Cx;
50
+ private readonly Bx;
51
+ private readonly Ax;
52
+ private readonly Cy;
53
+ private readonly By;
54
+ private readonly Ay;
55
+ private readonly isLinear;
56
+ constructor(p1: number, p2: number, p3: number, p4: number);
57
+ /** Calculates the X coordinate on the bezier curve for a given parameter t. */
58
+ private bezier_x;
59
+ /** Calculates the Y coordinate on the bezier curve for a given parameter t. */
60
+ private bezier_y;
61
+ /** Calculates the derivative of the bezier curve's X component with respect to t. */
62
+ private bezier_x_der;
63
+ /**
64
+ * Approximates the parameter t that corresponds to a given X coordinate on the curve,
65
+ * using Newton's method.
66
+ * @param x The target X coordinate.
67
+ * @returns The approximated parameter t for the given x.
68
+ */
69
+ private find_x_for;
70
+ /**
71
+ * Gets the eased Y value for a given progress value t (0-1).
72
+ * @param t The progress value (time).
73
+ * @returns The eased Y value.
74
+ */
75
+ get(t: number): number;
76
+ }
77
+ /** Predefined cubic bezier easing: ease-in-out (standard). */
78
+ export const easeInOut: Bicubic;
79
+ /** Predefined cubic bezier easing: ease-in. */
80
+ export const easeIn: Bicubic;
81
+ /** Predefined cubic bezier easing: ease-out. */
82
+ export const easeOut: Bicubic;
83
+ /** Predefined cubic bezier easing: linear. */
84
+ export const linear: Bicubic;
85
+ /**
86
+ * High-performance matrix and vector operations for WebGL.
87
+ * Ported from gl-matrix 3.2.1 (Copyright (c) 2015-2020, Brandon Jones, Colin MacKenzie IV).
88
+ * Originally ported to AssemblyScript/WASM by marcel@micr.io, 2020.
89
+ * Re-ported to TypeScript for the Micrio engine.
90
+ *
91
+ * @license MIT
92
+ */
93
+ /** Represents a 4x4 matrix, tailored for WebGL operations. */
94
+ export class Mat4 {
95
+ a0: number;
96
+ a1: number;
97
+ a2: number;
98
+ a3: number;
99
+ a4: number;
100
+ a5: number;
101
+ a6: number;
102
+ a7: number;
103
+ a8: number;
104
+ a9: number;
105
+ a10: number;
106
+ a11: number;
107
+ a12: number;
108
+ a13: number;
109
+ a14: number;
110
+ a15: number;
111
+ /** Float32Array view for direct use with WebGL uniformMatrix4fv. */
112
+ readonly arr: Float32Array;
113
+ /**
114
+ * Creates a new identity Mat4.
115
+ * Matrix layout (column-major):
116
+ * a0 a4 a8 a12
117
+ * a1 a5 a9 a13
118
+ * a2 a6 a10 a14
119
+ * a3 a7 a11 a15
120
+ */
121
+ constructor(a0?: number, a1?: number, a2?: number, a3?: number, a4?: number, a5?: number, a6?: number, a7?: number, a8?: number, a9?: number, a10?: number, a11?: number, a12?: number, a13?: number, a14?: number, a15?: number);
122
+ /** Updates the internal Float32Array with the current matrix values. */
123
+ toArray(): Float32Array;
124
+ /** Resets the matrix to the identity matrix. */
125
+ identity(): void;
126
+ /** Copies the values from another Mat4 into this one. */
127
+ copy(s: Mat4): void;
128
+ /** Multiplies this matrix by a rotation matrix created from the given angle around the X axis. */
129
+ rotateX(rad: number): void;
130
+ /** Multiplies this matrix by a rotation matrix created from the given angle around the Y axis. */
131
+ rotateY(rad: number): void;
132
+ /** Multiplies this matrix by a rotation matrix created from the given angle around the Z axis. */
133
+ rotateZ(rad: number): void;
134
+ /** Uniform scale applied only to X and Y columns (Z unchanged). */
135
+ scaleFlat(scale: number): void;
136
+ /** Translates the matrix by the given vector [x, y, z]. */
137
+ translate(x: number, y: number, z: number): void;
138
+ /** Generates a perspective projection matrix with the given bounds. */
139
+ perspective(fovy: number, aspect: number, near: number, far: number): void;
140
+ /** Generates a simplified perspective matrix suitable for CSS 3D transforms (no near/far clipping). */
141
+ perspectiveCss(fovy: number): void;
142
+ /** Inverts the matrix. */
143
+ invert(): void;
144
+ /** Multiplies this matrix by another matrix `a` (this = this * a). */
145
+ multiply(a: Mat4): void;
146
+ /** Scales the matrix by the given vector [x, y, z]. */
147
+ scaleXY(x: number, y: number, z?: number): void;
148
+ }
149
+ /** Represents a 4D vector (x, y, z, w). */
150
+ export class Vec4 {
151
+ x: number;
152
+ y: number;
153
+ z: number;
154
+ w: number;
155
+ constructor(x?: number, y?: number, z?: number, w?: number);
156
+ /** Copies the values from another Vec4 into this one. */
157
+ copy(v: Vec4): void;
158
+ /** Transforms the vector by the given Mat4. */
159
+ transformMat4(m: Mat4): void;
160
+ /** Normalizes the vector (scales it to have a length of 1). */
161
+ normalize(): void;
162
+ }
163
+ /**
164
+ * Represents a single image source (tiled or single) within a TileCanvas.
165
+ * Handles tile pyramid, layer management, and tile culling.
166
+ * @author Marcel Duin <marcel@micr.io>
167
+ */
168
+ /** Represents a single resolution layer within an Image. */
169
+ class Layer {
170
+ readonly image: Image;
171
+ readonly index: number;
172
+ readonly start: number;
173
+ readonly end: number;
174
+ readonly tileSize: number;
175
+ readonly cols: number;
176
+ readonly rows: number;
177
+ readonly tileWidth: number;
178
+ readonly tileHeight: number;
179
+ constructor(image: Image, index: number, start: number, end: number, tileSize: number, cols: number, rows: number);
180
+ getTileRect(idx: number, r: DrawRect): DrawRect;
181
+ }
182
+ /** Represents a single image source (tiled or single) within a TileCanvas. */
183
+ export default class Image {
184
+ private readonly canvas;
185
+ readonly index: number;
186
+ readonly localIdx: number;
187
+ readonly width: number;
188
+ readonly height: number;
189
+ readonly tileSize: number;
190
+ readonly isSingle: boolean;
191
+ readonly isVideo: boolean;
192
+ readonly startOffset: number;
193
+ opacity: number;
194
+ tOpacity: number;
195
+ rotX: number;
196
+ rotY: number;
197
+ rotZ: number;
198
+ readonly scale: number;
199
+ readonly fromScale: number;
200
+ private static readonly toDraw;
201
+ private static toDrawSeen;
202
+ private static toDrawSeenBase;
203
+ readonly vec: Vec4;
204
+ readonly mat: Mat4;
205
+ rScale: number;
206
+ readonly layers: Layer[];
207
+ numLayers: number;
208
+ targetLayer: number;
209
+ x0: number;
210
+ y0: number;
211
+ x1: number;
212
+ y1: number;
213
+ rWidth: number;
214
+ rHeight: number;
215
+ areaCenterX: number;
216
+ areaCenterY: number;
217
+ areaWidth: number;
218
+ areaHeight: number;
219
+ sphere3DX: number;
220
+ sphere3DY: number;
221
+ sphere3DZ: number;
222
+ angularWidth: number;
223
+ angularHeight: number;
224
+ gotBase: number;
225
+ readonly endOffset: number;
226
+ aspect: number;
227
+ doneTotal: number;
228
+ doRender: boolean;
229
+ private is360Embed;
230
+ isVideoPlaying: boolean;
231
+ private static sampledXs;
232
+ private static sampledYs;
233
+ private static uniqueXs;
234
+ private static sampledLength;
235
+ private static uniqueLength;
236
+ constructor(canvas: TileCanvas, index: number, localIdx: number, width: number, height: number, tileSize: number, isSingle: boolean, isVideo: boolean, startOffset: number, opacity: number, tOpacity: number, rotX: number, rotY: number, rotZ: number, scale: number, fromScale: number);
237
+ /** Sets the relative area this image occupies within its parent canvas. */
238
+ setArea(x0: number, y0: number, x1: number, y1: number): void;
239
+ /** Converts 2D sphere coordinates to 3D unit sphere position */
240
+ private calculate3DSpherePosition;
241
+ /**
242
+ * Checks if embed's 3D sphere position is within camera's viewing frustum
243
+ */
244
+ private sphere3DOverlap;
245
+ /** Checks if the image's bounding box is completely outside the current view. */
246
+ private outsideView;
247
+ /** Determines if this image should be rendered in the current frame. */
248
+ shouldRender(): boolean;
249
+ /**
250
+ * Steps the opacity animation for this image.
251
+ * @returns True if the opacity changed (animation is active or snapped).
252
+ */
253
+ opacityTick(direct: boolean): boolean;
254
+ /**
255
+ * Calculates the set of tiles needed to render the current view for this image.
256
+ * @returns The number of tiles from this image that are already loaded/drawn.
257
+ */
258
+ getTiles(scale: number): number;
259
+ /** Calculates the target layer index based on the current scale. */
260
+ private getTargetLayer;
261
+ /** Calculates and adds tiles within a given rectangular area for a specific layer. */
262
+ private getTilesRect;
263
+ /**
264
+ * Calculates tiles for 360 embeds using viewport-based coordinates.
265
+ */
266
+ private getTilesViewport;
267
+ private setToDraw;
268
+ /** Calculates the vertex positions for an embedded image within a 360 canvas. */
269
+ setDrawRect(r: DrawRect): void;
270
+ /** Calculates the effective scale of an embedded image based on its projection. */
271
+ private getEmbeddedScale;
272
+ private get360Tiles;
273
+ }
274
+ /**
275
+ * Shared data structures for the Micrio engine: View, Coordinates, Viewport, DrawRect.
276
+ * @author Marcel Duin <marcel@micr.io>
277
+ */
278
+ /** Structure to hold information about a specific tile to be drawn. */
279
+ export class DrawRect {
280
+ /** Left edge of the tile in relative image coordinates (0-1). */
281
+ x0: number;
282
+ /** Top edge of the tile in relative image coordinates (0-1). */
283
+ y0: number;
284
+ /** Right edge of the tile in relative image coordinates (0-1). */
285
+ x1: number;
286
+ /** Bottom edge of the tile in relative image coordinates (0-1). */
287
+ y1: number;
288
+ /** Index of the resolution layer this tile belongs to. */
289
+ layer: number;
290
+ /** Column index of the tile within its layer. */
291
+ x: number;
292
+ /** Row index of the tile within its layer. */
293
+ y: number;
294
+ /** Reference to the Image instance this tile belongs to. */
295
+ image: Image;
296
+ constructor(
297
+ /** Left edge of the tile in relative image coordinates (0-1). */
298
+ x0?: number,
299
+ /** Top edge of the tile in relative image coordinates (0-1). */
300
+ y0?: number,
301
+ /** Right edge of the tile in relative image coordinates (0-1). */
302
+ x1?: number,
303
+ /** Bottom edge of the tile in relative image coordinates (0-1). */
304
+ y1?: number,
305
+ /** Index of the resolution layer this tile belongs to. */
306
+ layer?: number,
307
+ /** Column index of the tile within its layer. */
308
+ x?: number,
309
+ /** Row index of the tile within its layer. */
310
+ y?: number);
311
+ }
312
+ /** Represents the logical view rectangle within an image. */
313
+ export class View {
314
+ private readonly canvas;
315
+ centerX: number;
316
+ centerY: number;
317
+ width: number;
318
+ height: number;
319
+ lCenterX: number;
320
+ lCenterY: number;
321
+ lWidth: number;
322
+ lHeight: number;
323
+ /** Float64Array view of [centerX, centerY, width, height] — for efficient JS access. */
324
+ readonly arr: Float64Array;
325
+ /** Flag indicating if the view coordinates have changed since the last frame. */
326
+ changed: boolean;
327
+ /** Flag indicating if the view limits have changed. */
328
+ limitChanged: boolean;
329
+ constructor(canvas: TileCanvas, centerX?: number, centerY?: number, width?: number, height?: number, lCenterX?: number, lCenterY?: number, lWidth?: number, lHeight?: number);
330
+ get x0(): number;
331
+ get y0(): number;
332
+ get x1(): number;
333
+ get y1(): number;
334
+ get lX0(): number;
335
+ get lY0(): number;
336
+ get lX1(): number;
337
+ get lY1(): number;
338
+ get yaw(): number;
339
+ get pitch(): number;
340
+ get aspect(): number;
341
+ get size(): number;
342
+ set(centerX: number, centerY: number, width: number, height: number, preserveAspect?: boolean): void;
343
+ /** Sets the relative View area of a MicrioImage to render to, animates by default. Used in grids. */
344
+ setArea(x0: number, y0: number, x1: number, y1: number): void;
345
+ setLimit(lCenterX: number, lCenterY: number, lWidth: number, lHeight: number): void;
346
+ copy(v: View, excludeLimit?: boolean): void;
347
+ /** Calculates the perspective value needed to achieve this view height in 360 mode. */
348
+ getPerspective(): number;
349
+ /** Calculates the effective scale factor represented by this view. */
350
+ getScale(): number;
351
+ /** Calculates a distance metric between this view and another view, used for animation duration. */
352
+ getDistance(v: View, correctAspect: boolean): number;
353
+ limit(correctZoom: boolean, noLimit?: boolean, freeMove?: boolean): void;
354
+ correctAspectRatio(): void;
355
+ /** Updates the shared Float64Array with the current view coordinates. */
356
+ toArray(): Float64Array;
357
+ /** Checks if this view is equal to another view. */
358
+ equals(centerX: number, centerY: number, width: number, height: number): boolean;
359
+ /** Checks if this view represents the full image [0,0,1,1]. */
360
+ isFull(): boolean;
361
+ }
362
+ /** Represents coordinates: relative image coordinates or screen pixel coordinates. */
363
+ export class Coordinates {
364
+ x: number;
365
+ y: number;
366
+ scale: number;
367
+ w: number;
368
+ direction: number;
369
+ /** Float64Array view for efficient JS access [x, y, scale, w/depth, direction]. */
370
+ readonly arr: Float64Array;
371
+ constructor(x?: number, y?: number, scale?: number, w?: number, direction?: number);
372
+ /** Checks if the screen coordinate is potentially within the viewport bounds. */
373
+ inView(v: Viewport): boolean;
374
+ /** Updates the shared Float64Array with the current coordinate values. */
375
+ toArray(): Float64Array;
376
+ }
377
+ /** Represents the screen viewport of a TileCanvas element. */
378
+ export class Viewport {
379
+ width: number;
380
+ height: number;
381
+ left: number;
382
+ top: number;
383
+ areaWidth: number;
384
+ areaHeight: number;
385
+ ratio: number;
386
+ scale: number;
387
+ isPortrait: boolean;
388
+ /** Int32Array view for efficient JS access [width, height, left, top]. */
389
+ readonly arr: Int32Array;
390
+ constructor(width?: number, height?: number, left?: number, top?: number, areaWidth?: number, areaHeight?: number, ratio?: number, scale?: number, isPortrait?: boolean);
391
+ get centerX(): number;
392
+ get centerY(): number;
393
+ get aspect(): number;
394
+ /** Updates the shared Int32Array with the current viewport dimensions (integer pixels). */
395
+ toArray(): Int32Array;
396
+ /**
397
+ * Sets the viewport properties, scaling by device pixel ratio.
398
+ * @returns True if any property changed, false otherwise.
399
+ */
400
+ set(w: number, h: number, l: number, t: number, r: number, s: number, p: boolean): boolean;
401
+ /** Copies properties from another Viewport object. */
402
+ copy(v: Viewport): void;
403
+ }
404
+ /**
405
+ * Main controller class for the Micrio engine.
406
+ * Manages all canvases, global settings, and host callbacks.
407
+ * @author Marcel Duin <marcel@micr.io>
408
+ */
409
+ /** Host interface for callbacks from the engine to the JS host. */
410
+ export interface MainHost {
411
+ drawTile: (imgIdx: number, idx: number, layer: number, x: number, y: number, opacity: number, animating: boolean, isTargetLayer: boolean) => boolean;
412
+ drawQuad: (opacity: number) => void;
413
+ getTileOpacity: (idx: number) => number;
414
+ setTileOpacity: (idx: number, direct: boolean, imageOpacity: number) => number;
415
+ setMatrix: (arr: Float32Array) => void;
416
+ setViewport: (x: number, y: number, width: number, height: number) => void;
417
+ aniDone: (c: TileCanvas) => void;
418
+ aniAbort: (c: TileCanvas) => void;
419
+ viewSet: (c: TileCanvas) => void;
420
+ viewportSet: (c: TileCanvas, x: number, y: number, w: number, h: number) => void;
421
+ setCanvasVisible: (c: TileCanvas, visible: boolean) => void;
422
+ setImageVisible: (c: Image, visible: boolean) => void;
423
+ }
424
+ /**
425
+ * Main controller class for the Micrio engine.
426
+ * Manages all canvases, global settings, and the render loop.
427
+ * Host callbacks are provided at construction via {@link MainHost}.
428
+ */
429
+ export class Main {
430
+ /** Viewport representing the main HTML element (<micr-io>). */
431
+ readonly el: Viewport;
432
+ /** Vertex buffer for rendering 2D image tiles (quads). */
433
+ readonly vertexBuffer: Float32Array;
434
+ /** Vertex buffer for rendering 360 sphere geometry. */
435
+ readonly vertexBuffer360: Float32Array;
436
+ /** Array holding all active TileCanvas instances managed by this engine. */
437
+ readonly canvases: TileCanvas[];
438
+ /** Total number of tiles across all images in all canvases. */
439
+ numTiles: number;
440
+ /** Total number of Image instances across all canvases. */
441
+ numImages: number;
442
+ /** Timestamp of the current frame (performance.now()). */
443
+ now: number;
444
+ /** Flag indicating if any animation is active in any canvas this frame. */
445
+ animating: boolean;
446
+ /** Overall loading progress (0-1) based on tiles drawn vs tiles needed. */
447
+ progress: number;
448
+ /** Total number of tiles needed across all canvases this frame. */
449
+ toDrawTotal: number;
450
+ /** Total number of tiles successfully drawn (or already loaded) across all canvases this frame. */
451
+ doneTotal: number;
452
+ /** Default duration (seconds) for crossfade between canvases. */
453
+ crossfadeDuration: number;
454
+ /** Default duration (seconds) for grid item transitions. */
455
+ gridTransitionDuration: number;
456
+ /** Default easing function for grid transitions. */
457
+ gridTransitionTimingFunction: Bicubic;
458
+ /** Default duration (seconds) for transitions between 360 spaces. */
459
+ spacesTransitionDuration: number;
460
+ /** Default duration (seconds) for fading embedded images/videos. */
461
+ embedFadeDuration: number;
462
+ /** Elasticity factor for kinetic dragging (higher = more movement). */
463
+ dragElasticity: number;
464
+ /** Flag indicating if a binary archive is being used. */
465
+ hasArchive: boolean;
466
+ /** Layer offset when using an archive. */
467
+ archiveLayerOffset: number;
468
+ /** Number of "underzoom" levels. */
469
+ underzoomLevels: number;
470
+ /** Number of lowest resolution layers to skip loading initially. */
471
+ skipBaseLevels: number;
472
+ /** Flag for barebone mode (minimal texture loading). */
473
+ bareBone: boolean;
474
+ /** Flag indicating if the current context is a swipe gallery. */
475
+ isSwipe: boolean;
476
+ /** Flag to disable panning during pinch gestures. */
477
+ noPinchPan: boolean;
478
+ /** Target direction for 360 transition. */
479
+ direction: number;
480
+ /** Horizontal distance for 360 transition. */
481
+ distanceX: number;
482
+ /** Vertical distance for 360 transition. */
483
+ distanceY: number;
484
+ /** Estimated time per frame in seconds (used for animation speed normalization). */
485
+ frameTime: number;
486
+ private readonly _host;
487
+ constructor(host: MainHost);
488
+ get drawTile(): (imgIdx: number, idx: number, layer: number, x: number, y: number, opacity: number, animating: boolean, isTargetLayer: boolean) => boolean;
489
+ get drawQuad(): (opacity: number) => void;
490
+ get getTileOpacity(): (idx: number) => number;
491
+ get setTileOpacity(): (idx: number, direct: boolean, imageOpacity: number) => number;
492
+ get setMatrix(): (arr: Float32Array) => void;
493
+ get setViewport(): (x: number, y: number, width: number, height: number) => void;
494
+ get aniDone(): (c: TileCanvas) => void;
495
+ get aniAbort(): (c: TileCanvas) => void;
496
+ get viewSet(): (c: TileCanvas) => void;
497
+ get viewportSet(): (c: TileCanvas, x: number, y: number, w: number, h: number) => void;
498
+ get setCanvasVisible(): (c: TileCanvas, visible: boolean) => void;
499
+ get setImageVisible(): (c: Image, visible: boolean) => void;
500
+ shouldDraw(now: number): boolean;
501
+ draw(): void;
502
+ reset(): void;
503
+ aniStop(): void;
504
+ /**
505
+ * Updates the main element's viewport dimensions and triggers resize on all canvases.
506
+ */
507
+ resize(w: number, h: number, l: number, t: number, r: number, s: number, p: boolean): void;
508
+ /** Removes a specific TileCanvas instance from the managed list. */
509
+ remove(c: TileCanvas): void;
510
+ }
511
+ /**
512
+ * Handles kinetic scrolling/dragging behavior after user interaction stops.
513
+ * @author Marcel Duin <marcel@micr.io>
514
+ */
515
+ /** Handles kinetic scrolling/dragging behavior after user interaction stops. */
516
+ export default class Kinetic {
517
+ private canvas;
518
+ /** Accumulated horizontal delta during drag. */
519
+ private dX;
520
+ /** Accumulated vertical delta during drag. */
521
+ private dY;
522
+ /** Timestamp when the drag interaction started. */
523
+ private startTime;
524
+ /** Timestamp of the previous step added. */
525
+ private prevTime;
526
+ /** Timestamp when the drag interaction ended (kinetic phase started). */
527
+ private endTime;
528
+ /** Timestamp of the last significant interaction step. */
529
+ private lastInteraction;
530
+ /** Current horizontal velocity for kinetic movement. */
531
+ private velocityX;
532
+ /** Current vertical velocity for kinetic movement. */
533
+ private velocityY;
534
+ /** Flag indicating if kinetic movement is currently active. */
535
+ started: boolean;
536
+ constructor(canvas: TileCanvas);
537
+ /**
538
+ * Adds a step (delta) from the user's drag interaction.
539
+ * @param pX Horizontal pixel delta since last step.
540
+ * @param pY Vertical pixel delta since last step.
541
+ * @param time Current timestamp (performance.now()).
542
+ */
543
+ addStep(pX: number, pY: number, time: number): void;
544
+ /** Starts the kinetic movement phase (called when user stops dragging). */
545
+ start(): void;
546
+ /** Stops the kinetic movement and resets state. */
547
+ stop(): void;
548
+ /**
549
+ * Calculates and applies the kinetic movement step for the current frame.
550
+ * @returns Progress towards stopping (0 = max velocity, 1 = stopped).
551
+ */
552
+ step(time: number): number;
553
+ }
554
+ /** Manages camera and view animations (fly-to, zoom). */
555
+ export default class Ani {
556
+ private canvas;
557
+ /** Flag indicating if a view animation (fly-to) is active. */
558
+ private isView;
559
+ /** Starting view state for the animation. */
560
+ private readonly vFrom;
561
+ /** Target view state for the animation. */
562
+ private readonly vTo;
563
+ /** Stores the final target view requested (might differ from vTo during corrections). */
564
+ readonly lastView: View;
565
+ /** Flag indicating if a zoom animation (perspective change in 360) is active. */
566
+ private isZoom;
567
+ /** Flag indicating if the animation is a "jump" (zooms out then in). */
568
+ private isJump;
569
+ /** Starting perspective value for zoom animation. */
570
+ private zFrom;
571
+ /** Target perspective value for zoom animation. */
572
+ private zTo;
573
+ /** Flag to disable perspective limits during zoom animation. */
574
+ private zNoLimit;
575
+ /** Easing function used for the current animation. */
576
+ private fn;
577
+ /** Timestamp when the animation started. */
578
+ private started;
579
+ /** Total duration of the animation in milliseconds. */
580
+ private duration;
581
+ /** Flag indicating if the animation is currently running (not paused). */
582
+ private isRunning;
583
+ /** Flag indicating if the view should be limited during animation (usually false during animation). */
584
+ limit: boolean;
585
+ /** Flag indicating if the current animation step resulted in zooming out. */
586
+ zoomingOut: boolean;
587
+ /** Flag indicating if the animation is a fly-to type. */
588
+ flying: boolean;
589
+ /** Flag indicating if the animation is correcting the view to stay within limits. */
590
+ correcting: boolean;
591
+ /** Timestamp when the animation was paused. 0 if not paused. */
592
+ private pausedAt;
593
+ private fL;
594
+ private fT;
595
+ private fR;
596
+ private fB;
597
+ /** Start point for the ease-in part of the jump animation curve. */
598
+ private mI;
599
+ /** Start point for the ease-out part of the jump animation curve. */
600
+ private mO;
601
+ /** Starting frame index for omni object rotation animation. */
602
+ private omniStartIdx;
603
+ /** Delta (number of frames) to rotate during omni animation. */
604
+ private omniDelta;
605
+ constructor(canvas: TileCanvas);
606
+ /** Pauses the current animation. */
607
+ pause(time: number): void;
608
+ /** Resumes a paused animation. */
609
+ resume(time: number): void;
610
+ /** Stops the current animation completely and resets state. */
611
+ stop(): void;
612
+ /** Checks if a view animation is currently running. */
613
+ isStarted(): boolean;
614
+ /**
615
+ * Starts or updates a "fly-to" animation to a target view rectangle.
616
+ * @returns Calculated or provided animation duration in ms.
617
+ */
618
+ toView(toCenterX: number, toCenterY: number, toWidth: number, toHeight: number, dur: number, speed: number, perc: number, isJump: boolean, limitViewport: boolean, omniIdx: number, fn: number, time: number, correct?: boolean): number;
619
+ /** Updates the target view of a running animation. Used for corrections. */
620
+ updateTarget(toCenterX: number, toCenterY: number, toWidth: number, toHeight: number, limiting?: boolean): void;
621
+ /**
622
+ * Starts a zoom animation (perspective change for 360).
623
+ * @returns Calculated or provided animation duration in ms.
624
+ */
625
+ zoom(to: number, dur: number, speed: number, noLimit: boolean, time: number): number;
626
+ /** Sets the starting view for progress calculation in flyTo animations. */
627
+ setStartView(centerX: number, centerY: number, width: number, height: number, correctRatio: boolean): void;
628
+ /**
629
+ * Calculates and applies the animation step for the current frame.
630
+ * @returns Current animation progress (0-1).
631
+ */
632
+ step(time: number): number;
633
+ }
634
+ /**
635
+ * Handles 2D camera logic, view calculations, and user interactions like pan, zoom, pinch.
636
+ * @author Marcel Duin <marcel@micr.io>
637
+ */
638
+ /** Handles 2D camera logic, view calculations, and user interactions like pan, zoom, pinch. */
639
+ export default class Camera {
640
+ private canvas;
641
+ scale: number;
642
+ minScale: number;
643
+ minSize: number;
644
+ maxScale: number;
645
+ fullScale: number;
646
+ coverScale: number;
647
+ readonly xy: Coordinates;
648
+ readonly coo: Coordinates;
649
+ private readonly startCoo;
650
+ private pinching;
651
+ private inited;
652
+ private hasStartCoo;
653
+ cpw: number;
654
+ cph: number;
655
+ private wasCoverLimit;
656
+ constructor(canvas: TileCanvas);
657
+ /**
658
+ * Converts screen pixel coordinates to relative image coordinates [0-1].
659
+ */
660
+ getCoo(x: number, y: number, abs: boolean, noLimit: boolean): Coordinates;
661
+ /**
662
+ * Converts relative image coordinates [0-1] to screen pixel coordinates.
663
+ */
664
+ getXY(x: number, y: number, abs: boolean): Coordinates;
665
+ getXYOmni(x: number, y: number, radius: number, rotation: number, abs: boolean): Coordinates;
666
+ /**
667
+ * Converts 3D coordinates relative to an omni object's center to screen pixel coordinates.
668
+ */
669
+ getXYOmniCoo(x: number, y: number, z: number, rotation: number, abs: boolean): Coordinates;
670
+ /** Recalculates scale limits (minScale, maxScale, coverScale, fullScale) based on current canvas and image dimensions. */
671
+ setCanvas(): void;
672
+ /** Corrects minScale and maxScale based on coverLimit and focus area. */
673
+ correctMinMax(noLimit?: boolean): void;
674
+ /** Checks if the current scale is below the minimum allowed scale (considering minSize margin). */
675
+ isUnderZoom(): boolean;
676
+ /** Checks if the camera is fully zoomed out (at or below minScale, considering minSize margin). */
677
+ isZoomedOut(b?: boolean): boolean;
678
+ /** Checks if the camera is fully zoomed in (at or above maxScale). */
679
+ isZoomedIn(): boolean;
680
+ /**
681
+ * Calculates and sets the current camera scale and view offsets based on the logical view rectangle.
682
+ * @returns True if the view was successfully set, false if initialization is pending.
683
+ */
684
+ setView(): boolean;
685
+ /** Checks if the current view extends beyond the defined limits or max scale. */
686
+ isOutsideLimit(): boolean;
687
+ /**
688
+ * Pans the view by a given pixel delta.
689
+ */
690
+ pan(xPx: number, yPx: number, duration: number, noLimit: boolean, time: number, force?: boolean, isKinetic?: boolean): void;
691
+ /**
692
+ * Zooms the view by a given delta, centered on screen coordinates.
693
+ * @returns The calculated animation duration.
694
+ */
695
+ zoom(delta: number, xPx: number, yPx: number, duration: number, noLimit: boolean, time: number): number;
696
+ prevSize: number;
697
+ prevCenterX: number;
698
+ prevCenterY: number;
699
+ /** Handles pinch gesture updates. */
700
+ pinch(xPx1: number, yPx1: number, xPx2: number, yPx2: number): void;
701
+ /** Signals the start of a pinch gesture. */
702
+ pinchStart(): void;
703
+ /** Signals the end of a pinch gesture. */
704
+ pinchStop(time: number): void;
705
+ private snapToBounds;
706
+ /**
707
+ * Initiates a fly-to animation to a target view rectangle.
708
+ * @returns The calculated animation duration.
709
+ */
710
+ flyTo(centerX: number, centerY: number, width: number, height: number, dur: number, speed: number, perc: number, isJump: boolean, limit: boolean, limitZoom: boolean, toOmniIdx: number, fn: number, time: number): number;
711
+ /**
712
+ * Sets the view center and scale, optionally animating.
713
+ * @returns The calculated animation duration.
714
+ */
715
+ setCoo(x: number, y: number, scale: number, dur: number, speed: number, limit: boolean, fn: number, time: number): number;
716
+ }
717
+ /** Handles 360 camera logic, perspective, and related SphericalView calculations. */
718
+ export default class SphericalView {
719
+ private canvas;
720
+ readonly pMatrix: Mat4;
721
+ readonly iMatrix: Mat4;
722
+ private readonly cachedInverse;
723
+ private inverseDirty;
724
+ private readonly rMatrix;
725
+ readonly position: Vec4;
726
+ radius: number;
727
+ scale: number;
728
+ scaleY: number;
729
+ offY: number;
730
+ dofY: number;
731
+ limitX: number;
732
+ limitY: number;
733
+ baseYaw: number;
734
+ yaw: number;
735
+ pitch: number;
736
+ defaultPerspective: number;
737
+ perspective: number;
738
+ maxPerspective: number;
739
+ minPerspective: number;
740
+ cameraForwardX: number;
741
+ cameraForwardY: number;
742
+ cameraForwardZ: number;
743
+ cameraUpX: number;
744
+ cameraUpY: number;
745
+ cameraUpZ: number;
746
+ cameraRightX: number;
747
+ cameraRightY: number;
748
+ cameraRightZ: number;
749
+ fieldOfView: number;
750
+ aspectRatio: number;
751
+ readonly vec4: Vec4;
752
+ readonly coo: Coordinates;
753
+ offX: number;
754
+ constructor(canvas: TileCanvas);
755
+ /** Sets the horizontal and vertical movement limits. */
756
+ setLimits(x: number, y: number): void;
757
+ /** Updates the projection and rotation matrices based on current state. */
758
+ update(noPersp?: boolean): void;
759
+ /**
760
+ * Applies rotation based on pixel delta from mouse/touch drag.
761
+ */
762
+ rotate(xPx: number, yPx: number, duration: number, time: number): void;
763
+ /** Clamps the pitch value based on perspective and vertical limits. */
764
+ private limitPitch;
765
+ /** Clamps the yaw value based on horizontal limits. */
766
+ private limitYaw;
767
+ /**
768
+ * Applies zoom by adjusting the perspective.
769
+ */
770
+ zoom(factor: number, dur: number, speed: number, noLimit: boolean, t: number, pxX?: number, pxY?: number): number;
771
+ /** Sets the perspective (FoV) and updates related state. */
772
+ setPerspective(perspective: number, noLimit: boolean): void;
773
+ /** Recalculates the effective scale based on coordinate conversion. */
774
+ readScale(): void;
775
+ /** Sets the camera orientation directly. */
776
+ setDirection(yaw: number, pitch: number, persp: number): void;
777
+ /** Sets the camera orientation using viewport format (center + dimensions). */
778
+ setView(centerX: number, centerY: number, _width: number, height: number, noLimit?: boolean, correctNorth?: boolean): void;
779
+ /** Synchronizes the logical view with the current camera state for 360 images. */
780
+ private syncLogicalView;
781
+ /** Calculates 3D camera frustum for accurate 360 embed visibility detection */
782
+ calculate3DFrustum(): void;
783
+ /** Applies translation offset for 360 space transitions. */
784
+ moveTo(distance: number, distanceY: number, direction: number, addYaw: number): void;
785
+ /** Handles canvas resize events for 360 mode. */
786
+ resize(): void;
787
+ /** Ensures the cached inverse projection matrix is up to date. */
788
+ private ensureInverse;
789
+ /** Converts screen pixel coordinates to 360 image coordinates [0-1]. */
790
+ getCoo(pxX: number, pxY: number): Coordinates;
791
+ /** Converts 360 image coordinates [0-1] to screen pixel coordinates. */
792
+ getXYZ(x: number, y: number): Coordinates;
793
+ /**
794
+ * Calculates the 3D vector corresponding to a point on the 360 sphere.
795
+ */
796
+ getVec3(x: number, y: number, abs?: boolean, rad?: number): Vec4;
797
+ /**
798
+ * Calculates the combined transformation matrix for placing an element
799
+ * at a specific point on the 360 sphere.
800
+ */
801
+ getMatrix(x: number, y: number, scale: number, radius: number, rX: number, rY: number, rZ: number, transY: number, sX?: number, sY?: number, _noCorrectNorth?: boolean): Mat4;
802
+ /** Generates vertex data for a segment of the 360 sphere geometry. */
803
+ setTile360(x: number, y: number, w: number, h: number): void;
804
+ }
805
+ /**
806
+ * Represents a single rendering canvas within the Micrio engine.
807
+ * Orchestrates image loading, tile calculation, camera control, and drawing.
808
+ * @author Marcel Duin <marcel@micr.io>
809
+ */
810
+ export interface TileCanvasConfig {
811
+ tileSize: number;
812
+ is360: boolean;
813
+ noImage: boolean;
814
+ isSingle: boolean;
815
+ freeMove: boolean;
816
+ coverStart: boolean;
817
+ maxScale: number;
818
+ scaleMultiplier: number;
819
+ camSpeed: number;
820
+ rotationY: number;
821
+ isGallerySwitch: boolean;
822
+ pagesHaveBackground: boolean;
823
+ isOmni: boolean;
824
+ pinchZoomOutLimit: boolean;
825
+ omniNumLayers: number;
826
+ omniStartLayer: number;
827
+ }
828
+ export default class TileCanvas {
829
+ readonly main: Main;
830
+ width: number;
831
+ height: number;
832
+ targetOpacity: number;
833
+ coverLimit: boolean;
834
+ readonly hasParent: boolean;
835
+ readonly view: View;
836
+ readonly focus: View;
837
+ readonly ani: Ani;
838
+ readonly kinetic: Kinetic;
839
+ readonly camera: Camera;
840
+ readonly webgl: SphericalView;
841
+ readonly rect: DrawRect;
842
+ readonly el: Viewport;
843
+ readonly images: Image[];
844
+ private readonly children;
845
+ readonly area: View;
846
+ readonly currentArea: View;
847
+ readonly targetArea: View;
848
+ readonly visible: View;
849
+ readonly full: View;
850
+ private areaAniPerc;
851
+ private areaAniPaused;
852
+ private _zIndex;
853
+ private childrenDirty;
854
+ get zIndex(): number;
855
+ set zIndex(v: number);
856
+ readonly toDraw: number[];
857
+ readonly aspect: number;
858
+ private index;
859
+ private isVisible;
860
+ opacity: number;
861
+ bOpacity: number;
862
+ isReady: boolean;
863
+ activeImageIdx: number;
864
+ omniFieldOfView: number;
865
+ omniVerticalAngle: number;
866
+ omniDistance: number;
867
+ omniOffsetX: number;
868
+ limited: boolean;
869
+ layer: number;
870
+ readonly tileSize: number;
871
+ readonly is360: boolean;
872
+ readonly noImage: boolean;
873
+ readonly isSingle: boolean;
874
+ readonly freeMove: boolean;
875
+ readonly coverStart: boolean;
876
+ readonly maxScale: number;
877
+ readonly scaleMultiplier: number;
878
+ readonly camSpeed: number;
879
+ readonly rotationY: number;
880
+ readonly isGallerySwitch: boolean;
881
+ readonly pagesHaveBackground: boolean;
882
+ readonly isOmni: boolean;
883
+ readonly pinchZoomOutLimit: boolean;
884
+ readonly omniNumLayers: number;
885
+ readonly omniStartLayer: number;
886
+ constructor(main: Main, width: number, height: number, targetOpacity: number, coverLimit: boolean, cfg: TileCanvasConfig, hasParent?: boolean);
887
+ /** Reference to the parent canvas (if this is a child/grid item). */
888
+ parent: TileCanvas;
889
+ /** Sets the parent canvas for a child canvas. */
890
+ setParent(parent: TileCanvas): void;
891
+ /**
892
+ * Adds an image source (usually tiled) to this canvas.
893
+ */
894
+ addImage(x0: number, y0: number, x1: number, y1: number, w: number, h: number, tileSize: number, isSingle: boolean, isVideo: boolean, opa: number, rotX: number, rotY: number, rotZ: number, scale: number, fromScale: number): Image;
895
+ addChild(x0: number, y0: number, x1: number, y1: number, width: number, height: number): TileCanvas;
896
+ /** Steps the opacity fade animation and applies 360 transition movement. */
897
+ private stepOpacity;
898
+ /** Notifies the JS host about visibility changes. */
899
+ setCanvasVisible(b: boolean): void;
900
+ /** Initiates a fade-out animation. */
901
+ fadeOut(): void;
902
+ /** Initiates a fade-in animation. */
903
+ fadeIn(): void;
904
+ /** Checks if the canvas area is currently animating. */
905
+ areaAnimating(): boolean;
906
+ /** Checks if the canvas is effectively hidden. */
907
+ isHidden(): boolean;
908
+ /** Determines if the canvas needs to be drawn in the next frame and calculates tiles needed. */
909
+ shouldDraw(): void;
910
+ /** Executes the drawing commands for the current frame for this canvas. */
911
+ draw(): void;
912
+ private partialView;
913
+ /** Sets the target area for this canvas within its parent, optionally animating. */
914
+ setArea(x0: number, y0: number, x1: number, y1: number, direct: boolean, noDispatch: boolean): void;
915
+ /** Calculates the vertex positions for a given tile index and updates the vertex buffer. */
916
+ private setTile;
917
+ /** Notifies JS host about the current screen viewport details. */
918
+ sendViewport(): void;
919
+ /** Finds the Image, Layer, and calculates the DrawRect for a given global tile index. */
920
+ private findTileRect;
921
+ /** Handles resizing of the canvas element. */
922
+ resize(): void;
923
+ /** Resets the canvas state. */
924
+ reset(): void;
925
+ /** Removes this canvas instance from the main controller. */
926
+ remove(): void;
927
+ /** Re-adds this canvas instance to the main controller. */
928
+ replace(): void;
929
+ /** Sets the active layer for multi-layer omni objects. */
930
+ setActiveLayer(idx: number): void;
931
+ /** Sets the active image(s) for gallery/omni canvases. */
932
+ setActiveImage(idx: number, num: number): void;
933
+ /** Sets the focus area for gallery/grid canvases. */
934
+ setFocus(x0: number, y0: number, x1: number, y1: number, noLimit: boolean): void;
935
+ /** Gets image coordinates from screen coordinates. */
936
+ getCoo(x: number, y: number, abs: boolean, noLimit: boolean): Float64Array;
937
+ /** Gets screen coordinates from image coordinates. */
938
+ getXY(x: number, y: number, abs: boolean, radius: number, rotation: number): Float64Array;
939
+ /** Gets the current logical view array. */
940
+ getView(): Float64Array;
941
+ /** Sets the logical view directly. */
942
+ setView(centerX: number, centerY: number, width: number, height: number, noLimit: boolean, noLastView: boolean, correctNorth?: boolean, forceLimit?: boolean): void;
943
+ getScale(): number;
944
+ isZoomedIn(): boolean;
945
+ isZoomedOut(b?: boolean): boolean;
946
+ setDirection(yaw: number, pitch: number, resetPersp: boolean): void;
947
+ getMatrix(x: number, y: number, s: number, r: number, rX: number, rY: number, rZ: number, t: number, sX?: number, sY?: number, noCorrectNorth?: boolean): Float32Array;
948
+ aniPause(time: number): void;
949
+ aniResume(time: number): void;
950
+ aniStop(): void;
951
+ aniDone(): void;
952
+ aniAbort(): void;
953
+ }
15
954
  /** Type for error codes */
16
955
  export type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
956
+ export { mod } from "engine/utils/utils";
17
957
  /**
18
958
  * Converts seconds into a human-readable time string (hh?:mm:ss).
19
959
  * @param s Time in seconds. Can be negative for remaining time display.
@@ -182,6 +1122,9 @@ declare module '@micrio/client' {
182
1122
  readonly center: Models.Camera.Coords;
183
1123
  /** CORRECT view: [x0, y0, width, height] */
184
1124
  private readonly view;
1125
+ private _getXY;
1126
+ private _getCoo;
1127
+ private _setMinScale;
185
1128
  /**
186
1129
  * Gets the current image view rectangle.
187
1130
  * @returns A copy of the current screen viewport array, or undefined if not initialized.
@@ -207,7 +1150,7 @@ declare module '@micrio/client' {
207
1150
  noLimit?: boolean;
208
1151
  /** If true (for 360), corrects the view based on the `trueNorth` setting. */
209
1152
  correctNorth?: boolean;
210
- /** If true, prevents triggering a Wasm render after setting the view. */
1153
+ /** If true, prevents triggering a render after setting the view. */
211
1154
  noRender?: boolean;
212
1155
  /** If provided, interprets `view` relative to this sub-area instead of the full image. */
213
1156
  area?: Models.Camera.ViewRect;
@@ -265,29 +1208,10 @@ declare module '@micrio/client' {
265
1208
  setScale: (s: number) => void;
266
1209
  /** Gets the scale at which the image fully covers the viewport. */
267
1210
  getCoverScale: () => number;
268
- /**
269
- * Gets the minimum allowed zoom scale for the image.
270
- * @returns The minimum scale.
271
- */
272
1211
  getMinScale: () => number;
273
- /**
274
- * Sets the minimum allowed zoom scale.
275
- * @param s The minimum scale to set.
276
- */
277
1212
  setMinScale(s: number): void;
278
- /**
279
- * Sets the minimum screen size the image should occupy when zooming out (0-1).
280
- * Allows zooming out further than the image boundaries, creating margins.
281
- * Note: Does not work with albums.
282
- * @param s The minimum screen size fraction (0-1).
283
- */
284
1213
  setMinScreenSize(s: number): void;
285
- /** Returns true if the camera is currently zoomed in to its maximum limit. */
286
1214
  isZoomedIn: () => boolean;
287
- /**
288
- * Returns true if the camera is currently zoomed out to its minimum limit.
289
- * @param full If true, checks against the absolute minimum scale (ignoring `setMinScreenSize`).
290
- */
291
1215
  isZoomedOut: (full?: boolean) => boolean;
292
1216
  /**
293
1217
  * Sets a rectangular limit for camera navigation within the image.
@@ -299,14 +1223,12 @@ declare module '@micrio/client' {
299
1223
  * @param b If true, limits the view to cover the screen.
300
1224
  */
301
1225
  setCoverLimit(b: boolean): void;
302
- /** Gets whether the cover limit is currently enabled. */
303
1226
  getCoverLimit: () => boolean;
304
- /**
305
- * Limits the horizontal and vertical viewing range for 360 images.
306
- * @param xPerc The horizontal arc limit as a percentage (0-1, where 1 = 360°). 0 disables horizontal limit.
307
- * @param yPerc The vertical arc limit as a percentage (0-1, where 1 = 180°). 0 disables vertical limit.
308
- */
1227
+ stop(): void;
1228
+ pause(): void;
1229
+ resume(): void;
309
1230
  set360RangeLimit(xPerc?: number, yPerc?: number): void;
1231
+ aniIsKinetic(): boolean;
310
1232
  /**
311
1233
  * Animates the camera smoothly to a target viewport.
312
1234
  * @param view The target viewport as either a View [x0, y0, x1, y1] or View {centerX, centerY, width, height}.
@@ -358,7 +1280,7 @@ declare module '@micrio/client' {
358
1280
  * @param noLimit If true, allows zooming beyond image boundaries.
359
1281
  * @returns A Promise that resolves when the zoom animation completes.
360
1282
  */
361
- zoom: (delta: number, duration?: number, x?: number | undefined, y?: number | undefined, speed?: number, noLimit?: boolean) => Promise<void>;
1283
+ zoom: (delta: number, duration?: number, x?: number | undefined, y?: number | undefined, _speed?: number, noLimit?: boolean) => Promise<void>;
362
1284
  /**
363
1285
  * Zooms in by a specified factor.
364
1286
  * @param factor Zoom factor (e.g., 1 = standard zoom step).
@@ -386,29 +1308,12 @@ declare module '@micrio/client' {
386
1308
  render?: boolean;
387
1309
  noLimit?: boolean;
388
1310
  }): void;
389
- /** Stops any currently running camera animation immediately. */
390
- stop(): void;
391
- /** Pauses the current camera animation. */
392
- pause(): void;
393
- /** Resumes a paused camera animation. */
394
- resume(): void;
395
- /** Returns true if the camera is currently performing a kinetic pan/zoom (coasting). */
396
- aniIsKinetic(): boolean;
397
1311
  /** Gets the current viewing direction (yaw) in 360 mode.
398
1312
  * @returns The current yaw in radians.
399
1313
  */
400
1314
  getDirection: () => number;
401
- /**
402
- * Sets the viewing direction (yaw and optionally pitch) instantly in 360 mode.
403
- * @param yaw The target yaw in radians.
404
- * @param pitch Optional target pitch in radians.
405
- */
406
- setDirection(yaw: number, pitch?: number): void;
407
- /**
408
- * Gets the current viewing pitch in 360 mode.
409
- * @returns The current pitch in radians.
410
- */
411
1315
  getPitch: () => number;
1316
+ setDirection(yaw: number, pitch?: number): void;
412
1317
  /**
413
1318
  * Sets the rendering area for this image within the main canvas.
414
1319
  * Used for split-screen and potentially other layout effects. Animates by default.
@@ -420,7 +1325,7 @@ declare module '@micrio/client' {
420
1325
  direct?: boolean;
421
1326
  /** If true, prevents dispatching view updates during the animation. */
422
1327
  noDispatch?: boolean;
423
- /** If true, prevents triggering a Wasm render after setting the area. */
1328
+ /** If true, prevents triggering a render after setting the area. */
424
1329
  noRender?: boolean;
425
1330
  }): void;
426
1331
  /** Sets the 3D rotation for an embedded image (used for placing embeds in 360 space). */
@@ -431,52 +1336,92 @@ declare module '@micrio/client' {
431
1336
  getOmniFrame(rot?: number): number | undefined;
432
1337
  /** [Omni] Gets the screen coordinates [x, y, scale, depth] for given 3D object coordinates. */
433
1338
  getOmniXY(x: number, y: number, z: number): Float64Array;
434
- /** [Omni] Applies Omni-specific camera settings (distance, FoV, angle) to Wasm. */
1339
+ /** [Omni] Applies Omni-specific camera settings (distance, FoV, angle) to the engine canvas. */
435
1340
  setOmniSettings(): void;
436
1341
  }
437
1342
  /**
438
- * The main WebAssembly controller class. Handles interaction between JavaScript
439
- * and the compiled C++ core of Micrio. Accessed via `micrio.wasm`.
1343
+ * The main Micrio compute controller class. Handles the engine lifecycle,
1344
+ * render loop, tile management, and WebGL integration.
1345
+ * Accessed via `micrio.engine`.
440
1346
  */
441
- export class Wasm {
1347
+ export class Engine {
442
1348
  micrio: HTMLMicrioElement;
443
- /** Flag indicating if the Wasm module has been loaded and initialized. */
444
1349
  ready: boolean;
445
- /** Shared WebAssembly memory instance. */
446
- private memory;
447
1350
  /** Forget in-memory tiles after X seconds not drawn */
448
1351
  private deleteAfterSeconds;
449
- /**
450
- * Creates the Wasm controller instance.
451
- * @param micrio The main HTMLMicrioElement instance.
452
- */
1352
+ preventDirectionSet: boolean;
1353
+ /** Shared Float32Array for standard tile vertex data. */
1354
+ _vertexBuffer: Float32Array;
1355
+ /** Static Float32Array holding texture coordinates for a standard quad. */
1356
+ static readonly _textureBuffer: Float32Array;
1357
+ /** Shared Float32Array for 360 tile vertex data. */
1358
+ _vertexBuffer360: Float32Array;
1359
+ /** Static Float32Array holding texture coordinates for the 360 sphere. */
1360
+ static _textureBuffer360: Float32Array;
1361
+ /** Flag indicating if the current context is a gallery. */
1362
+ private isGallery;
1363
+ private now;
1364
+ private raf;
1365
+ private drawing;
1366
+ /** Returns the engine TileCanvas for a MicrioImage, or undefined. */
1367
+ getCanvas(img: MicrioImage | Models.Omni.Frame): TileCanvas | undefined;
453
1368
  constructor(micrio: HTMLMicrioElement);
454
1369
  /**
455
- * Loads and instantiates the WebAssembly module.
456
- * @returns A Promise that resolves when the Wasm module is ready.
457
- * @throws Error if WebAssembly binary loading or instantiation fails
458
- */
1370
+ * Initializes the engine (replaces WebAssembly loading).
1371
+ * @throws Error if engine initialization fails
1372
+ */
459
1373
  load(): Promise<void>;
1374
+ private _hostDrawQuad;
1375
+ private _hostGetTileOpacity;
1376
+ private _hostSetTileOpacity;
1377
+ private _hostSetMatrix;
1378
+ private _hostSetViewport;
1379
+ private _hostAniDone;
1380
+ private _hostAniAbort;
1381
+ private _hostViewSet;
1382
+ private _hostViewportSet;
1383
+ private _hostSetCanvasVisible;
1384
+ private _hostSetImageVisible;
460
1385
  /** Unbinds event listeners, stops rendering, and cleans up resources. */
461
1386
  unbind(): void;
462
1387
  /**
463
- * Sets the currently active canvas/image instance in the Wasm module.
464
- * Handles adding the canvas to Wasm if it's not already initialized.
465
- * @param canvas The MicrioImage instance to set as active.
466
- */
1388
+ * Sets the currently active canvas/image instance in the engine.
1389
+ */
467
1390
  setCanvas(canvas?: MicrioImage): void;
468
- /** Removes a canvas instance from the Wasm module. */
1391
+ /** Removes a canvas instance from the engine. */
469
1392
  removeCanvas(c: MicrioImage): void;
470
- /** Requests the next animation frame to trigger the `draw` method. */
1393
+ /** Requests the next animation frame. */
471
1394
  render(): void;
1395
+ /**
1396
+ * Callback for the engine to request drawing a tile.
1397
+ * @returns True if the tile texture is ready and drawn, false otherwise.
1398
+ */
1399
+ private drawTile;
472
1400
  /** Add a child image to the current canvas, either embed or independent canvas */
473
1401
  private addImage;
474
- /** Add a child independent canvas to the current canvas, used for grid images
475
- * @param image The image
476
- * @param parent The parent image
477
- * @returns Promise when the image is added
478
- */
1402
+ /** Add a child independent canvas to the current canvas */
479
1403
  addChild: (image: MicrioImage, parent: MicrioImage) => Promise<void>;
1404
+ setZIndex(ptr: number, z: number): void;
1405
+ setGridTransitionDuration(dur: number): void;
1406
+ setGridTransitionTimingFunction(fn: number): void;
1407
+ setCrossfadeDuration(dur: number): void;
1408
+ fadeTo(ptr: number, opacity: number, direct: boolean): void;
1409
+ fadeIn(ptr: number): void;
1410
+ fadeOut(ptr: number): void;
1411
+ areaAnimating(ptr: number): boolean;
1412
+ getActiveImageIdx(ptr: number): number;
1413
+ setNoPinchPan(v: boolean): void;
1414
+ setIsSwipe(v: boolean): void;
1415
+ ease(p: number): number;
1416
+ panStart(ptr: number): void;
1417
+ panStop(ptr: number): void;
1418
+ pinchStart(ptr: number): void;
1419
+ pinch(ptr: number, x0: number, y0: number, x1: number, y1: number): void;
1420
+ pinchStop(ptr: number, t: number): void;
1421
+ setLimited(ptr: number, v: boolean): void;
1422
+ set360Orientation(d: number, dX: number, dY: number): void;
1423
+ setCanvasArea(w: number, h: number): void;
1424
+ setImageVideoPlaying(ptr: number, playing: boolean): void;
480
1425
  }
481
1426
  /**
482
1427
  * Handles swipe gestures for navigating image sequences, particularly for
@@ -488,7 +1433,7 @@ declare module '@micrio/client' {
488
1433
  private length;
489
1434
  goto: (i: number) => void;
490
1435
  private opts;
491
- /** Getter for the current active image/frame index from the Wasm module. */
1436
+ /** Getter for the current active image/frame index from the engine. */
492
1437
  get currentIndex(): number;
493
1438
  /**
494
1439
  * Creates a GallerySwiper instance.
@@ -644,7 +1589,7 @@ declare module '@micrio/client' {
644
1589
  /**
645
1590
  * Represents and controls a single Micrio image instance within the viewer.
646
1591
  * This class manages the image's metadata (info), cultural data (data),
647
- * settings, camera, state, and interactions with the WebAssembly module
1592
+ * settings, camera, state, and interactions with the compute engine
648
1593
  * for rendering and processing. It handles loading image tiles, embeds,
649
1594
  * markers, tours, and galleries associated with the image.
650
1595
  *
@@ -652,7 +1597,7 @@ declare module '@micrio/client' {
652
1597
  * @author Marcel Duin <marcel@micr.io>
653
1598
  */
654
1599
  export class MicrioImage {
655
- wasm: Wasm;
1600
+ engine: Engine;
656
1601
  private attr;
657
1602
  opts: {
658
1603
  /** Optional sub area [x0, y0, x1, y1] defining placement within a parent canvas (for embeds/galleries). */
@@ -2462,7 +3407,7 @@ declare module '@micrio/client' {
2462
3407
  */
2463
3408
  getRatio: (s?: Partial<Models.ImageInfo.Settings>) => number;
2464
3409
  /**
2465
- * Sets virtual offset margins in the Wasm controller.
3410
+ * Sets virtual offset margins in the engine controller.
2466
3411
  * This likely affects how viewports are calculated or limited.
2467
3412
  * @param width The horizontal offset margin in pixels.
2468
3413
  * @param height The vertical offset margin in pixels.
@@ -2931,7 +3876,7 @@ declare module '@micrio/client' {
2931
3876
  /**
2932
3877
  * The main Micrio custom HTML element `<micr-io>`.
2933
3878
  * This class acts as the central controller for the Micrio viewer, managing
2934
- * the WebGL canvas, WebAssembly module, Svelte UI, state, events, and image loading.
3879
+ * the WebGL canvas, compute engine, Svelte UI, state, events, and image loading.
2935
3880
  *
2936
3881
  * It orchestrates the interaction between different parts of the library and
2937
3882
  * exposes methods and properties for controlling the viewer.
@@ -3025,7 +3970,7 @@ declare module '@micrio/client' {
3025
3970
  /**
3026
3971
  * Closes an opened MicrioImage.
3027
3972
  * For split-screen images, it triggers the split-end transition.
3028
- * For main images, it removes the canvas from the Wasm controller.
3973
+ * For main images, it removes the canvas from the engine.
3029
3974
  * @param img The {@link MicrioImage} instance to close.
3030
3975
  */
3031
3976
  close(img: MicrioImage): void;
@@ -3071,20 +4016,20 @@ declare module '@micrio/client' {
3071
4016
  * Handles HLS playback via hls.js if necessary.
3072
4017
  */
3073
4018
  export class GLEmbedVideo {
3074
- private wasm;
4019
+ private engine;
3075
4020
  private image;
3076
4021
  private embed;
3077
4022
  private paused;
3078
4023
  private moved;
3079
4024
  /**
3080
4025
  * Creates a GLEmbedVideo instance.
3081
- * @param wasm The Wasm controller instance.
4026
+ * @param engine The Engine controller instance.
3082
4027
  * @param image The parent MicrioImage instance where the video is embedded.
3083
4028
  * @param embed The embed data object.
3084
4029
  * @param paused Initial paused state (e.g., due to pause-on-zoom).
3085
- * @param moved Callback function to notify when position/state changes (triggers Wasm render).
4030
+ * @param moved Callback function to notify when position/state changes (triggers Engine render).
3086
4031
  */
3087
- constructor(wasm: Wasm, image: MicrioImage, embed: Models.ImageData.Embed, paused: boolean, // Initial paused state
4032
+ constructor(engine: Engine, image: MicrioImage, embed: Models.ImageData.Embed, paused: boolean, // Initial paused state
3088
4033
  moved: () => void);
3089
4034
  /** Cleans up resources when the parent Embed component is unmounted. */
3090
4035
  unmount(): void;
@@ -3264,13 +4209,34 @@ declare module '@micrio/client' {
3264
4209
  export { Router } from "ts/nav/router";
3265
4210
  export { Grid } from "ts/nav/grid";
3266
4211
  export { GallerySwiper } from "ts/nav/swiper";
3267
- export { Wasm } from "ts/render/wasm";
4212
+ export { Engine } from "ts/render/engine";
3268
4213
  export { WebGL } from "ts/render/webgl";
3269
4214
  export { Canvas } from "ts/render/canvas";
3270
4215
  export { PostProcessor } from "ts/render/postprocess";
3271
4216
  export { archive } from "ts/render/archive";
3272
4217
  export { loadTexture, runningThreads, numThreads, abortDownload } from "ts/render/textures";
3273
4218
  export type { TextureBitmap } from "ts/render/textures";
4219
+ /**
4220
+ * Micrio Engine — TypeScript compute core for the Micrio image viewer.
4221
+ *
4222
+ * This module replaces the WebAssembly/AssemblyScript compute layer.
4223
+ * It provides the same computational logic (camera math, tile pyramid
4224
+ * management, animation engine, 360 sphere geometry, matrix/vector math)
4225
+ * as pure TypeScript classes.
4226
+ *
4227
+ * @author Marcel Duin <marcel@micr.io>
4228
+ */
4229
+ export { Main } from "engine/main";
4230
+ export { default as TileCanvas } from "engine/canvas/canvas";
4231
+ export { default as Image } from "engine/canvas/image";
4232
+ export { default as SphericalView } from "engine/webgl/webgl";
4233
+ export { default as Camera } from "engine/camera/camera";
4234
+ export { default as Ani } from "engine/camera/ani";
4235
+ export { default as Kinetic } from "engine/camera/kinetic";
4236
+ export { View, Coordinates, Viewport, DrawRect } from "engine/shared/shared";
4237
+ export { Mat4, Vec4 } from "engine/webgl/mat";
4238
+ export { Bicubic, easeInOut, easeIn, easeOut, linear, mod1, modPI, twoNth, longitudeDistance } from "engine/utils/utils";
4239
+ export { PI, PI2, PIh, segsX, segsY, base360Distance } from "engine/globals";
3274
4240
  }declare module "svelte/store" {
3275
4241
  /** Callback to inform of a value updates.
3276
4242
  */