@expofp/renderer 2.1.2 → 2.2.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +70 -26
  2. package/dist/index.js +656 -567
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -256,7 +256,7 @@ export declare interface ImageDef extends SharedDef {
256
256
 
257
257
  export declare type ImageSource = HTMLImageElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas;
258
258
 
259
- export declare type Index = [number, number, number];
259
+ export declare type Index = readonly [number, number, number];
260
260
 
261
261
  export declare function isImageDef(def: RenderableDef): def is ImageDef;
262
262
 
@@ -278,9 +278,9 @@ export declare function isTextDef(def: RenderableDef): def is TextDef;
278
278
 
279
279
  export declare function isTextLayer(layer: LayerDef): layer is TypedLayerDef<TextDef>;
280
280
 
281
- export declare type IVector2 = Vector2 | Vector2Like | Vector2Tuple;
281
+ export declare type IVector2 = Vector2Like | Vector2Tuple;
282
282
 
283
- export declare type IVector3 = Vector3 | Vector3Like | Vector3Tuple;
283
+ export declare type IVector3 = Vector3Like | Vector3Tuple;
284
284
 
285
285
  /** Layer definition */
286
286
  export declare interface LayerDef extends SharedDef {
@@ -334,15 +334,20 @@ export declare interface PitchHandlerOptions {
334
334
 
335
335
  /** Polygon shape instance. */
336
336
  export declare class Polygon {
337
- /** Array of polygon vertices. */
338
- readonly vertices: Vector3[];
339
- /** Array of polygon indices. Each index is a triplet of vertex indices forming a triangle. */
340
- readonly indices: Index[];
337
+ private _indices;
338
+ private _vertices;
339
+ private _bbox;
341
340
  /**
342
341
  * @param vertices Array of polygon vertices.
343
342
  * @param indices Array of polygon indices. Each index is a triplet of vertex indices forming a triangle.
344
343
  */
345
344
  constructor(vertices: (IVector3 | IVector2)[], indices: Index[]);
345
+ /** Array of polygon vertices. */
346
+ get vertices(): readonly Vector3Like[];
347
+ /** Array of polygon indices. Each index is a triplet of vertex indices forming a triangle. */
348
+ get indices(): readonly Index[];
349
+ /** Bounding rectangle of the polygon. */
350
+ get bounds(): Rect;
346
351
  /**
347
352
  * Converts a {@link Rect} to a {@link Polygon}.
348
353
  * @param rect {@link Rect} instance
@@ -356,34 +361,58 @@ export declare class Polygon {
356
361
  */
357
362
  static merge(...polygons: Polygon[]): Polygon;
358
363
  /**
359
- * Rotates all vertices of the polygon around the given center.
364
+ * Translates all vertices of the polygon by the given offset.
365
+ * @param offset Offset to translate the polygon by. Can be a 2D or 3D vector.
366
+ * @returns this {@link Polygon} instance
367
+ */
368
+ translate(offset: Vector2Like | Vector3Like): Polygon;
369
+ /**
370
+ * Rotates all vertices of the polygon around the given center. Only 2D rotation (around Z axis) is supported.
360
371
  * @param rotation Rotation angle in radians. Positive values rotate clockwise.
361
- * @param center Center of the rotation.
372
+ * @param center Center of the rotation. If omitted, defaults to the bounding rectangle center.
362
373
  * @returns this {@link Polygon} instance
363
374
  */
364
- rotate(rotation: number, center: Vector2Like): Polygon;
375
+ rotate(rotation: number, center?: Vector2Like): Polygon;
376
+ /**
377
+ * Scales the polygon around the given origin.
378
+ * @param scaleFactor Can be a single number or a 2D vector. If a single number is provided, both horizontal and vertical axes will be scaled by the same factor.
379
+ * @param origin Origin of the scaling. If omitted, defaults to the bounding rectangle center.
380
+ * @returns this {@link Polygon} instance
381
+ */
382
+ scale(scaleFactor: number | Vector2Like, origin?: Vector2Like): Polygon;
383
+ private computeBoundingRect;
365
384
  }
366
385
 
367
386
  /** Rectangle shape instance. */
368
387
  export declare class Rect {
369
- /** Top left corner of the rectangle. */
370
- readonly min: Vector2;
371
- /** Bottom right corner of the rectangle. */
372
- readonly max: Vector2;
373
388
  /** Optional rotation of the rectangle. In radians, around center. Positive values rotate clockwise. */
374
389
  rotation: number;
375
- private _center?;
376
- private _size?;
390
+ private _min;
391
+ private _max;
392
+ private _center;
393
+ private _size;
377
394
  /**
378
395
  * @param min Top left corner of the rectangle.
379
396
  * @param max Bottom right corner of the rectangle.
380
397
  * @param rotation Optional rotation of the rectangle. In radians, around center. Positive values rotate clockwise.
381
398
  */
382
399
  constructor(min: IVector2, max: IVector2, rotation?: number);
383
- /** Center of the rectangle. Read-only, calculated on demand. */
384
- get center(): Vector2;
385
- /** Size of the rectangle. Read-only, calculated on demand. */
386
- get size(): Vector2;
400
+ /** Top left corner of the rectangle. */
401
+ get min(): Vector2Like;
402
+ /** Set top left corner of the rectangle. */
403
+ set min(min: Vector2Like);
404
+ /** Bottom right corner of the rectangle. */
405
+ get max(): Vector2Like;
406
+ /** Set bottom right corner of the rectangle. */
407
+ set max(max: Vector2Like);
408
+ /** Center of the rectangle. */
409
+ get center(): Vector2Like;
410
+ /** Set center of the rectangle. */
411
+ set center(center: Vector2Like);
412
+ /** Size of the rectangle. */
413
+ get size(): Vector2Like;
414
+ /** Set size of the rectangle. */
415
+ set size(size: Vector2Like);
387
416
  /**
388
417
  * Creates a rectangle from an SVG rectangle element.
389
418
  * @param rect {@link SVGRectElement} or {@link SVGImageElement}
@@ -392,12 +421,20 @@ export declare class Rect {
392
421
  */
393
422
  static fromSvg(rect: SVGRectElement | SVGImageElement, rotation?: number): Rect;
394
423
  /**
395
- * Increases the size of the rectangle by the given amount. Padding is added to both sides of the rectangle.
396
- * @param x Horizontal padding.
397
- * @param y Vertical padding. If omitted, defaults to the same value as `x`.
424
+ * Moves the rectangle by the given offset.
425
+ * @param offset Offset to move the rectangle by.
426
+ * @returns this {@link Rect} instance
427
+ */
428
+ translate(offset: Vector2Like): Rect;
429
+ /**
430
+ * Expands the rectangle by the given amount on all sides.
431
+ * Use positive values to increase the size of the rectangle, negative values to decrease it.
432
+ * @param expansion Can be a single number or a 2D vector. If a single number is provided, both horizontal and vertical sizes will be expanded by the same amount.
398
433
  * @returns this {@link Rect} instance
399
434
  */
400
- addPadding(x: number, y?: number): this;
435
+ expand(expansion: number | Vector2Like): Rect;
436
+ private updateCenterAndSize;
437
+ private updateMinAndMax;
401
438
  }
402
439
 
403
440
  export declare type RenderableDef = LayerDef | ShapeDef | ImageDef | TextDef | LineDef;
@@ -505,7 +542,7 @@ export declare class Renderer {
505
542
  private updateMemoryInfo;
506
543
  private onContextLost;
507
544
  private onContextRestored;
508
- private initContext;
545
+ private initStatsContext;
509
546
  private assertNotDisposed;
510
547
  private assertInitialized;
511
548
  private assertNotInitialized;
@@ -561,7 +598,10 @@ export declare type Shape = Rect | Polygon;
561
598
 
562
599
  /** Shape definition. */
563
600
  export declare interface ShapeDef extends SharedDef {
564
- /** Shape to render. Not updatable. */
601
+ /**
602
+ * Shape to render. Updating partially supported, you can't add or remove polygon's vertices or indices.
603
+ * Also it's not possible to change the shape type (i.e. from polygon to rect and vice versa).
604
+ */
565
605
  shape: Shape;
566
606
  /** Shape's color in css format */
567
607
  color: ColorInput;
@@ -629,6 +669,10 @@ export declare interface UI {
629
669
  memoryInfoPanel: HTMLDivElement;
630
670
  }
631
671
 
672
+ export { Vector2Like }
673
+
674
+ export { Vector3Like }
675
+
632
676
  /** Viewport system public API. */
633
677
  export declare interface ViewportAPI {
634
678
  /**