@idetik/core 0.45.5 → 0.46.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/README.md CHANGED
@@ -35,6 +35,7 @@ This example displays a single slice from [Zebrahub](https://zebrahub.sf.czbiohu
35
35
  import {
36
36
  Idetik,
37
37
  ImageLayer,
38
+ Viewport,
38
39
  OmeZarrImageSource,
39
40
  OrthographicCamera,
40
41
  PanZoomControls,
@@ -56,13 +57,15 @@ const camera = new OrthographicCamera({
56
57
  top: 0, bottom: y.lods[0].size * y.lods[0].scale
57
58
  });
58
59
 
60
+ const canvas = document.querySelector<HTMLCanvasElement>('canvas')!;
59
61
  const idetik = new Idetik({
60
- canvas: document.querySelector('canvas')!,
61
- viewports: [{
62
+ canvas,
63
+ viewports: [new Viewport({
64
+ domElement: canvas,
62
65
  camera,
63
66
  layers: [layer],
64
67
  cameraControls: new PanZoomControls(camera)
65
- }],
68
+ })],
66
69
  });
67
70
 
68
71
  idetik.start();
package/dist/index.d.ts CHANGED
@@ -1065,13 +1065,15 @@ type OrthographicCameraProps = {
1065
1065
  * bottom: 1024
1066
1066
  * });
1067
1067
  *
1068
+ * const canvas = document.querySelector<HTMLCanvasElement>('canvas')!;
1068
1069
  * const idetik = new Idetik({
1069
- * canvas: document.querySelector('canvas')!,
1070
- * viewports: [{
1070
+ * canvas,
1071
+ * viewports: [new Viewport({
1072
+ * domElement: canvas,
1071
1073
  * camera,
1072
1074
  * layers: [imageLayer],
1073
1075
  * cameraControls: new PanZoomControls(camera),
1074
- * }],
1076
+ * })],
1075
1077
  * });
1076
1078
  * ```
1077
1079
  * @group Cameras
@@ -1219,11 +1221,12 @@ type PanZoomControlsProps = {
1219
1221
  *
1220
1222
  * const idetik = new Idetik({
1221
1223
  * canvas,
1222
- * viewports: [{
1224
+ * viewports: [new Viewport({
1225
+ * domElement: canvas,
1223
1226
  * camera,
1224
1227
  * layers: [imageLayer],
1225
1228
  * cameraControls: new PanZoomControls(camera),
1226
- * }],
1229
+ * })],
1227
1230
  * });
1228
1231
  * ```
1229
1232
  *
@@ -1268,8 +1271,8 @@ declare class PanZoomControls implements CameraControls {
1268
1271
  type ViewportProps = {
1269
1272
  /** Unique id. Defaults to the element id or a generated id. */
1270
1273
  id?: string;
1271
- /** Host element. Defaults to the Idetik canvas. */
1272
- element?: HTMLElement;
1274
+ /** Host element. */
1275
+ domElement: HTMLElement;
1273
1276
  /** The camera the viewport renders with. */
1274
1277
  camera: Camera;
1275
1278
  /** Layers to render in order. */
@@ -1277,17 +1280,11 @@ type ViewportProps = {
1277
1280
  /** Input controls driving the camera. */
1278
1281
  cameraControls?: CameraControls;
1279
1282
  };
1280
- interface ResolvedViewportProps extends ViewportProps {
1281
- id: string;
1282
- element: HTMLElement;
1283
- context: IdetikContext;
1284
- }
1285
1283
  /**
1286
1284
  * A region of the canvas that renders a stack of layers through a camera.
1287
1285
  *
1288
1286
  * Every viewport draws into the shared canvas through the area of its host
1289
- * element. The element defaults to the canvas itself and must be unique
1290
- * across viewports.
1287
+ * element. The element must be unique across viewports.
1291
1288
  *
1292
1289
  * Viewports also route input. Pointer and wheel events on the host element
1293
1290
  * are enriched with clip and world coordinates and a picking ray, sent to
@@ -1295,12 +1292,13 @@ interface ResolvedViewportProps extends ViewportProps {
1295
1292
  * propagation.
1296
1293
  *
1297
1294
  * ```ts
1298
- * const idetik = new Idetik({
1299
- * canvas,
1300
- * viewports: [{ id: 'main', camera, layers: [imageLayer] }],
1295
+ * const viewport = new Viewport({
1296
+ * domElement: canvas,
1297
+ * camera,
1298
+ * layers: [imageLayer],
1301
1299
  * });
1300
+ * const idetik = new Idetik({ canvas, viewports: [viewport] });
1302
1301
  *
1303
- * const viewport = idetik.getViewport('main')!;
1304
1302
  * viewport.addLayer(labelLayer);
1305
1303
  * ```
1306
1304
  *
@@ -1310,24 +1308,23 @@ declare class Viewport {
1310
1308
  /** The viewport's unique identifier. */
1311
1309
  readonly id: string;
1312
1310
  /** The host element defining the viewport's area. */
1313
- readonly element: HTMLElement;
1311
+ readonly domElement: HTMLElement;
1314
1312
  /** The camera the viewport renders with. */
1315
1313
  readonly camera: Camera;
1316
1314
  /** The pointer and wheel event dispatcher for the host element. */
1317
1315
  readonly events: EventDispatcher;
1318
1316
  /** Input controls driving the camera. */
1319
1317
  cameraControls?: CameraControls;
1320
- private readonly context_;
1321
1318
  private layers_;
1322
- /** @hidden */
1323
- constructor(props: ResolvedViewportProps);
1319
+ constructor(props: ViewportProps);
1324
1320
  /**
1325
1321
  * The layers rendered by this viewport in order. Layers with `occludes`
1326
1322
  * set draw before non-occluding layers regardless of stack order.
1327
1323
  */
1328
1324
  get layers(): readonly Layer[];
1329
1325
  /**
1330
- * Adds a layer to the top of the stack.
1326
+ * Adds a layer to the top of the stack. Throws if the viewport already
1327
+ * contains the layer.
1331
1328
  *
1332
1329
  * @param layer - The layer to add.
1333
1330
  */
@@ -1346,14 +1343,17 @@ declare class Viewport {
1346
1343
  */
1347
1344
  updateSize(): void;
1348
1345
  /**
1349
- * Computes the viewport's box relative to the given canvas in device pixels.
1346
+ * Computes the viewport's box relative to the given element in device
1347
+ * pixels, with `y` flipped to match WebGL's bottom-left origin.
1350
1348
  *
1351
- * @param canvas - The canvas to compute the box against.
1352
- * @returns The viewport's box in the canvas's coordinate space.
1349
+ * @param element - The element to compute the box against, typically the
1350
+ * canvas.
1351
+ * @returns The viewport's box in the element's coordinate space.
1353
1352
  */
1354
- getBoxRelativeTo(canvas: HTMLCanvasElement): Box2;
1353
+ getBoxRelativeTo(element: HTMLElement): Box2;
1355
1354
  /**
1356
- * The viewport's rectangle in the drawing buffer in device pixels.
1355
+ * The viewport's size in device pixels. Measured relative to its own host
1356
+ * element, so `x` and `y` are always `0`.
1357
1357
  */
1358
1358
  getBufferRect(): {
1359
1359
  x: number;
@@ -1494,6 +1494,8 @@ declare abstract class Layer {
1494
1494
  * @param _event - The event with clip and world coordinates attached.
1495
1495
  */
1496
1496
  onEvent(_event: EventContext): void;
1497
+ /** Whether the layer is attached to a viewport. */
1498
+ get attached(): boolean;
1497
1499
  /**
1498
1500
  * Lifecycle hook that is called automatically when a layer is
1499
1501
  * is attached to a viewport. A layer can only be attached to one viewport
@@ -1652,8 +1654,8 @@ type Overlay = {
1652
1654
  type IdetikProps = {
1653
1655
  /** The canvas element to render into. */
1654
1656
  canvas: HTMLCanvasElement;
1655
- /** Viewport definitions to create at startup. */
1656
- viewports?: ViewportProps[];
1657
+ /** Viewports to render at startup. */
1658
+ viewports?: Viewport[];
1657
1659
  /** Overlays to run each frame. */
1658
1660
  overlays?: Overlay[];
1659
1661
  /** Shows an FPS meter. Defaults to `false`. */
@@ -1692,13 +1694,15 @@ type IdetikContext = {
1692
1694
  * bottom: 1024,
1693
1695
  * });
1694
1696
  *
1697
+ * const canvas = document.querySelector<HTMLCanvasElement>('canvas')!;
1695
1698
  * const idetik = new Idetik({
1696
- * canvas: document.querySelector('canvas')!,
1697
- * viewports: [{
1699
+ * canvas,
1700
+ * viewports: [new Viewport({
1701
+ * domElement: canvas,
1698
1702
  * camera,
1699
1703
  * layers: [layer],
1700
1704
  * cameraControls: new PanZoomControls(camera),
1701
- * }],
1705
+ * })],
1702
1706
  * });
1703
1707
  *
1704
1708
  * idetik.start();
@@ -1719,6 +1723,7 @@ declare class Idetik {
1719
1723
  private readonly context_;
1720
1724
  private readonly renderer_;
1721
1725
  private readonly viewports_;
1726
+ private readonly attachments_;
1722
1727
  private readonly stats_?;
1723
1728
  private readonly sizeObserver_;
1724
1729
  private lastAnimationId_?;
@@ -1747,11 +1752,10 @@ declare class Idetik {
1747
1752
  /**
1748
1753
  * Adds a viewport at runtime.
1749
1754
  *
1750
- * @param props - The viewport definition. The `element` defaults to the
1751
- * canvas and must be unique across viewports.
1752
- * @returns The created viewport.
1755
+ * @param viewport - The viewport to add.
1756
+ * @returns The added viewport.
1753
1757
  */
1754
- addViewport(props: ViewportProps): Viewport;
1758
+ addViewport(viewport: Viewport): Viewport;
1755
1759
  /**
1756
1760
  * Removes a previously added viewport.
1757
1761
  *
@@ -1784,6 +1788,8 @@ declare class Idetik {
1784
1788
  * @returns The instance, for chaining.
1785
1789
  */
1786
1790
  start(): this;
1791
+ private detachRemovedLayers;
1792
+ private renderViewport;
1787
1793
  private animate;
1788
1794
  /**
1789
1795
  * Stops the render loop and disconnects input handlers.
@@ -3435,9 +3441,15 @@ type PerspectiveCameraProps = {
3435
3441
  * target: [0, 0, 0],
3436
3442
  * });
3437
3443
  *
3444
+ * const canvas = document.querySelector<HTMLCanvasElement>('canvas')!;
3438
3445
  * const idetik = new Idetik({
3439
- * canvas: document.querySelector('canvas')!,
3440
- * viewports: [{ camera, layers: [volumeLayer], cameraControls: controls }],
3446
+ * canvas,
3447
+ * viewports: [new Viewport({
3448
+ * domElement: canvas,
3449
+ * camera,
3450
+ * layers: [volumeLayer],
3451
+ * cameraControls: controls
3452
+ * })],
3441
3453
  * });
3442
3454
  * ```
3443
3455
  *
@@ -3511,14 +3523,15 @@ type OrbitControlsProps = {
3511
3523
  *
3512
3524
  * const idetik = new Idetik({
3513
3525
  * canvas,
3514
- * viewports: [{
3526
+ * viewports: [new Viewport({
3527
+ * domElement: canvas,
3515
3528
  * camera,
3516
3529
  * layers: [volumeLayer],
3517
3530
  * cameraControls: new OrbitControls(camera, {
3518
3531
  * radius: 100,
3519
3532
  * target: [40, 40, 10],
3520
3533
  * }),
3521
- * }],
3534
+ * })],
3522
3535
  * });
3523
3536
  * ```
3524
3537
  *