pts 0.12.7 → 0.12.9

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.mts CHANGED
@@ -128,13 +128,6 @@ interface MultiTouchElement {
128
128
  addEventListener(evt: any, callback: Function): any;
129
129
  removeEventListener(evt: any, callback: Function): any;
130
130
  }
131
- interface PtsCanvasRenderingContext2D extends CanvasRenderingContext2D {
132
- webkitBackingStorePixelRatio?: number;
133
- mozBackingStorePixelRatio?: number;
134
- msBackingStorePixelRatio?: number;
135
- oBackingStorePixelRatio?: number;
136
- backingStorePixelRatio?: number;
137
- }
138
131
  type CanvasSpaceOptions = {
139
132
  bgcolor?: string;
140
133
  resize?: boolean;
@@ -202,6 +195,7 @@ type DefaultFormStyle = {
202
195
  globalAlpha?: number;
203
196
  };
204
197
  type CanvasPatternRepetition = "repeat" | "repeat-x" | "repeat-y" | "no-repeat";
198
+ type RenderingContext2D = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
205
199
 
206
200
  /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
207
201
 
@@ -318,14 +312,12 @@ declare class Group extends Array<Pt> {
318
312
  $matrixMultiply(g: GroupLike | number, transposed?: boolean, elementwise?: boolean): Group;
319
313
  zipSlice(index: number, defaultValue?: number | boolean): Pt;
320
314
  $zip(defaultValue?: number | boolean, useLongest?: boolean): Group;
321
- toBound(): Group;
315
+ toBound(): Bound;
322
316
  toString(): string;
323
317
  }
324
318
  declare class Bound extends Group implements IPt {
325
319
  protected _center: Pt;
326
320
  protected _size: Pt;
327
- protected _topLeft: Pt;
328
- protected _bottomRight: Pt;
329
321
  protected _inited: boolean;
330
322
  constructor(...args: Pt[]);
331
323
  static fromBoundingRect(rect: ClientRect): Bound;
@@ -539,7 +531,7 @@ declare class Img {
539
531
  protected _img: HTMLImageElement;
540
532
  protected _data: ImageData;
541
533
  protected _cv: HTMLCanvasElement;
542
- protected _ctx: CanvasRenderingContext2D;
534
+ protected _ctx: RenderingContext2D;
543
535
  protected _scale: number;
544
536
  protected _loaded: boolean;
545
537
  protected _editable: boolean;
@@ -570,7 +562,7 @@ declare class Img {
570
562
  get image(): HTMLImageElement;
571
563
  get canvas(): HTMLCanvasElement;
572
564
  get data(): ImageData;
573
- get ctx(): CanvasRenderingContext2D;
565
+ get ctx(): RenderingContext2D;
574
566
  get loaded(): boolean;
575
567
  get pixelScale(): number;
576
568
  get imageSize(): Pt;
@@ -584,12 +576,13 @@ declare class CanvasSpace extends MultiTouchSpace {
584
576
  protected _canvas: HTMLCanvasElement;
585
577
  protected _container: Element;
586
578
  protected _pixelScale: number;
587
- protected _autoResize: boolean;
588
579
  protected _bgcolor: string;
589
- protected _ctx: PtsCanvasRenderingContext2D;
580
+ protected _ctx: CanvasRenderingContext2D;
590
581
  protected _offscreen: boolean;
591
582
  protected _offCanvas: HTMLCanvasElement;
592
- protected _offCtx: PtsCanvasRenderingContext2D;
583
+ protected _offCtx: RenderingContext2D;
584
+ protected _resizeObserver: ResizeObserver;
585
+ protected _autoResize: boolean;
593
586
  protected _initialResize: boolean;
594
587
  constructor(elem: string | Element, callback?: Function);
595
588
  protected _createElement(elem: string, id: any): HTMLElement;
@@ -603,13 +596,13 @@ declare class CanvasSpace extends MultiTouchSpace {
603
596
  get background(): string;
604
597
  get pixelScale(): number;
605
598
  get hasOffscreen(): boolean;
606
- get offscreenCtx(): PtsCanvasRenderingContext2D;
599
+ get offscreenCtx(): RenderingContext2D;
607
600
  get offscreenCanvas(): HTMLCanvasElement;
608
601
  getForm(): CanvasForm;
609
602
  get element(): HTMLCanvasElement;
610
603
  get parent(): Element;
611
604
  get ready(): boolean;
612
- get ctx(): PtsCanvasRenderingContext2D;
605
+ get ctx(): CanvasRenderingContext2D;
613
606
  clear(bg?: string): this;
614
607
  clearOffscreen(bg?: string): this;
615
608
  protected playItems(time: number): void;
@@ -618,12 +611,12 @@ declare class CanvasSpace extends MultiTouchSpace {
618
611
  }
619
612
  declare class CanvasForm extends VisualForm {
620
613
  protected _space: CanvasSpace;
621
- protected _ctx: CanvasRenderingContext2D;
614
+ protected _ctx: RenderingContext2D;
622
615
  protected _estimateTextWidth: (string: any) => number;
623
616
  protected _style: DefaultFormStyle;
624
- constructor(space?: CanvasSpace | CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D);
617
+ constructor(space?: CanvasSpace | RenderingContext2D);
625
618
  get space(): CanvasSpace;
626
- get ctx(): PtsCanvasRenderingContext2D;
619
+ get ctx(): RenderingContext2D;
627
620
  useOffscreen(off?: boolean, clear?: boolean | string): this;
628
621
  renderOffscreen(offset?: PtLike): void;
629
622
  alpha(a: number): this;
@@ -643,27 +636,27 @@ declare class CanvasForm extends VisualForm {
643
636
  protected _textAlign(box: PtLikeIterable, vertical: string, offset?: PtLike, center?: Pt): Pt;
644
637
  reset(): this;
645
638
  protected _paint(): void;
646
- static point(ctx: CanvasRenderingContext2D, p: PtLike, radius?: number, shape?: string): void;
639
+ static point(ctx: RenderingContext2D, p: PtLike, radius?: number, shape?: string): void;
647
640
  point(p: PtLike, radius?: number, shape?: string): this;
648
- static circle(ctx: CanvasRenderingContext2D, pt: PtLike, radius?: number): void;
641
+ static circle(ctx: RenderingContext2D, pt: PtLike, radius?: number): void;
649
642
  circle(pts: PtLikeIterable): this;
650
- static ellipse(ctx: CanvasRenderingContext2D, pt: PtLike, radius: PtLike, rotation?: number, startAngle?: number, endAngle?: number, cc?: boolean): void;
643
+ static ellipse(ctx: RenderingContext2D, pt: PtLike, radius: PtLike, rotation?: number, startAngle?: number, endAngle?: number, cc?: boolean): void;
651
644
  ellipse(pt: PtLike, radius: PtLike, rotation?: number, startAngle?: number, endAngle?: number, cc?: boolean): this;
652
- static arc(ctx: CanvasRenderingContext2D, pt: PtLike, radius: number, startAngle: number, endAngle: number, cc?: boolean): void;
645
+ static arc(ctx: RenderingContext2D, pt: PtLike, radius: number, startAngle: number, endAngle: number, cc?: boolean): void;
653
646
  arc(pt: PtLike, radius: number, startAngle: number, endAngle: number, cc?: boolean): this;
654
- static square(ctx: CanvasRenderingContext2D, pt: PtLike, halfsize: number): void;
647
+ static square(ctx: RenderingContext2D, pt: PtLike, halfsize: number): void;
655
648
  square(pt: PtLike, halfsize: number): this;
656
- static line(ctx: CanvasRenderingContext2D, pts: PtLikeIterable): void;
649
+ static line(ctx: RenderingContext2D, pts: PtLikeIterable): void;
657
650
  line(pts: PtLikeIterable): this;
658
- static polygon(ctx: CanvasRenderingContext2D, pts: PtLikeIterable): void;
651
+ static polygon(ctx: RenderingContext2D, pts: PtLikeIterable): void;
659
652
  polygon(pts: PtLikeIterable): this;
660
- static rect(ctx: CanvasRenderingContext2D, pts: PtLikeIterable): void;
653
+ static rect(ctx: RenderingContext2D, pts: PtLikeIterable): void;
661
654
  rect(pts: PtLikeIterable): this;
662
- static image(ctx: CanvasRenderingContext2D, ptOrRect: PtLike | PtLikeIterable, img: CanvasImageSource | Img, orig?: PtLikeIterable): void;
655
+ static image(ctx: RenderingContext2D, ptOrRect: PtLike | PtLikeIterable, img: CanvasImageSource | Img, orig?: PtLikeIterable): void;
663
656
  image(ptOrRect: PtLike | PtLikeIterable, img: CanvasImageSource | Img, orig?: PtLikeIterable): this;
664
- static imageData(ctx: CanvasRenderingContext2D, ptOrRect: PtLike | PtLikeIterable, img: ImageData): void;
657
+ static imageData(ctx: RenderingContext2D, ptOrRect: PtLike | PtLikeIterable, img: ImageData): void;
665
658
  imageData(ptOrRect: PtLike | PtLikeIterable, img: ImageData): this;
666
- static text(ctx: CanvasRenderingContext2D, pt: PtLike, txt: string, maxWidth?: number): void;
659
+ static text(ctx: RenderingContext2D, pt: PtLike, txt: string, maxWidth?: number): void;
667
660
  text(pt: PtLike, txt: string, maxWidth?: number): this;
668
661
  textBox(box: PtIterable, txt: string, verticalAlign?: string, tail?: string, overrideBaseline?: boolean): this;
669
662
  paragraphBox(box: PtLikeIterable, txt: string, lineHeight?: number, verticalAlign?: string, crop?: boolean): this;
@@ -831,7 +824,7 @@ declare class Rectangle {
831
824
  static from(topLeft: PtLike, widthOrSize: number | PtLike, height?: number): Group;
832
825
  static fromTopLeft(topLeft: PtLike, widthOrSize: number | PtLike, height?: number): Group;
833
826
  static fromCenter(center: PtLike, widthOrSize: number | PtLike, height?: number): Group;
834
- static toCircle(pts: PtIterable, within?: boolean): Group;
827
+ static toCircle(pts: PtIterable, enclose?: boolean): Group;
835
828
  static toSquare(pts: PtIterable, enclose?: boolean): Group;
836
829
  static size(pts: PtIterable): Pt;
837
830
  static center(pts: PtIterable): Pt;
@@ -1376,4 +1369,4 @@ declare class Sound {
1376
1369
  toggle(): this;
1377
1370
  }
1378
1371
 
1379
- export { type AnimateCallbackFn, Body, Bound, CanvasForm, type CanvasPatternRepetition, CanvasSpace, type CanvasSpaceOptions, Circle, Color, type ColorType, Const, Create, Curve, type DOMFormContext, DOMSpace, type DefaultFormStyle, Delaunay, type DelaunayMesh, type DelaunayShape, Font, Form, Geom, Group, type GroupLike, HTMLForm, HTMLSpace, type IPlayer, type IPt, type ISoundAnalyzer, type ISpacePlayers, type ITempoListener, type ITempoProgressFn, type ITempoResponses, type ITempoStartFn, type ITimer, Img, type IntersectContext, Line, Mat, type MultiTouchElement, MultiTouchSpace, Noise, Num, Particle, Polygon, Pt, type PtIterable, type PtLike, type PtLikeIterable, type PtsCanvasRenderingContext2D, Range, Rectangle, SVGForm, SVGSpace, Shaping, Sound, type SoundType, Space, Tempo, type TouchPointsKey, Triangle, Typography, UI, UIButton, UIDragger, type UIHandler, UIPointerActions, UIShape, Util, Vec, VisualForm, type WarningType, World };
1372
+ export { type AnimateCallbackFn, Body, Bound, CanvasForm, type CanvasPatternRepetition, CanvasSpace, type CanvasSpaceOptions, Circle, Color, type ColorType, Const, Create, Curve, type DOMFormContext, DOMSpace, type DefaultFormStyle, Delaunay, type DelaunayMesh, type DelaunayShape, Font, Form, Geom, Group, type GroupLike, HTMLForm, HTMLSpace, type IPlayer, type IPt, type ISoundAnalyzer, type ISpacePlayers, type ITempoListener, type ITempoProgressFn, type ITempoResponses, type ITempoStartFn, type ITimer, Img, type IntersectContext, Line, Mat, type MultiTouchElement, MultiTouchSpace, Noise, Num, Particle, Polygon, Pt, type PtIterable, type PtLike, type PtLikeIterable, Range, Rectangle, type RenderingContext2D, SVGForm, SVGSpace, Shaping, Sound, type SoundType, Space, Tempo, type TouchPointsKey, Triangle, Typography, UI, UIButton, UIDragger, type UIHandler, UIPointerActions, UIShape, Util, Vec, VisualForm, type WarningType, World };
package/dist/index.d.ts CHANGED
@@ -128,13 +128,6 @@ interface MultiTouchElement {
128
128
  addEventListener(evt: any, callback: Function): any;
129
129
  removeEventListener(evt: any, callback: Function): any;
130
130
  }
131
- interface PtsCanvasRenderingContext2D extends CanvasRenderingContext2D {
132
- webkitBackingStorePixelRatio?: number;
133
- mozBackingStorePixelRatio?: number;
134
- msBackingStorePixelRatio?: number;
135
- oBackingStorePixelRatio?: number;
136
- backingStorePixelRatio?: number;
137
- }
138
131
  type CanvasSpaceOptions = {
139
132
  bgcolor?: string;
140
133
  resize?: boolean;
@@ -202,6 +195,7 @@ type DefaultFormStyle = {
202
195
  globalAlpha?: number;
203
196
  };
204
197
  type CanvasPatternRepetition = "repeat" | "repeat-x" | "repeat-y" | "no-repeat";
198
+ type RenderingContext2D = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
205
199
 
206
200
  /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
207
201
 
@@ -318,14 +312,12 @@ declare class Group extends Array<Pt> {
318
312
  $matrixMultiply(g: GroupLike | number, transposed?: boolean, elementwise?: boolean): Group;
319
313
  zipSlice(index: number, defaultValue?: number | boolean): Pt;
320
314
  $zip(defaultValue?: number | boolean, useLongest?: boolean): Group;
321
- toBound(): Group;
315
+ toBound(): Bound;
322
316
  toString(): string;
323
317
  }
324
318
  declare class Bound extends Group implements IPt {
325
319
  protected _center: Pt;
326
320
  protected _size: Pt;
327
- protected _topLeft: Pt;
328
- protected _bottomRight: Pt;
329
321
  protected _inited: boolean;
330
322
  constructor(...args: Pt[]);
331
323
  static fromBoundingRect(rect: ClientRect): Bound;
@@ -539,7 +531,7 @@ declare class Img {
539
531
  protected _img: HTMLImageElement;
540
532
  protected _data: ImageData;
541
533
  protected _cv: HTMLCanvasElement;
542
- protected _ctx: CanvasRenderingContext2D;
534
+ protected _ctx: RenderingContext2D;
543
535
  protected _scale: number;
544
536
  protected _loaded: boolean;
545
537
  protected _editable: boolean;
@@ -570,7 +562,7 @@ declare class Img {
570
562
  get image(): HTMLImageElement;
571
563
  get canvas(): HTMLCanvasElement;
572
564
  get data(): ImageData;
573
- get ctx(): CanvasRenderingContext2D;
565
+ get ctx(): RenderingContext2D;
574
566
  get loaded(): boolean;
575
567
  get pixelScale(): number;
576
568
  get imageSize(): Pt;
@@ -584,12 +576,13 @@ declare class CanvasSpace extends MultiTouchSpace {
584
576
  protected _canvas: HTMLCanvasElement;
585
577
  protected _container: Element;
586
578
  protected _pixelScale: number;
587
- protected _autoResize: boolean;
588
579
  protected _bgcolor: string;
589
- protected _ctx: PtsCanvasRenderingContext2D;
580
+ protected _ctx: CanvasRenderingContext2D;
590
581
  protected _offscreen: boolean;
591
582
  protected _offCanvas: HTMLCanvasElement;
592
- protected _offCtx: PtsCanvasRenderingContext2D;
583
+ protected _offCtx: RenderingContext2D;
584
+ protected _resizeObserver: ResizeObserver;
585
+ protected _autoResize: boolean;
593
586
  protected _initialResize: boolean;
594
587
  constructor(elem: string | Element, callback?: Function);
595
588
  protected _createElement(elem: string, id: any): HTMLElement;
@@ -603,13 +596,13 @@ declare class CanvasSpace extends MultiTouchSpace {
603
596
  get background(): string;
604
597
  get pixelScale(): number;
605
598
  get hasOffscreen(): boolean;
606
- get offscreenCtx(): PtsCanvasRenderingContext2D;
599
+ get offscreenCtx(): RenderingContext2D;
607
600
  get offscreenCanvas(): HTMLCanvasElement;
608
601
  getForm(): CanvasForm;
609
602
  get element(): HTMLCanvasElement;
610
603
  get parent(): Element;
611
604
  get ready(): boolean;
612
- get ctx(): PtsCanvasRenderingContext2D;
605
+ get ctx(): CanvasRenderingContext2D;
613
606
  clear(bg?: string): this;
614
607
  clearOffscreen(bg?: string): this;
615
608
  protected playItems(time: number): void;
@@ -618,12 +611,12 @@ declare class CanvasSpace extends MultiTouchSpace {
618
611
  }
619
612
  declare class CanvasForm extends VisualForm {
620
613
  protected _space: CanvasSpace;
621
- protected _ctx: CanvasRenderingContext2D;
614
+ protected _ctx: RenderingContext2D;
622
615
  protected _estimateTextWidth: (string: any) => number;
623
616
  protected _style: DefaultFormStyle;
624
- constructor(space?: CanvasSpace | CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D);
617
+ constructor(space?: CanvasSpace | RenderingContext2D);
625
618
  get space(): CanvasSpace;
626
- get ctx(): PtsCanvasRenderingContext2D;
619
+ get ctx(): RenderingContext2D;
627
620
  useOffscreen(off?: boolean, clear?: boolean | string): this;
628
621
  renderOffscreen(offset?: PtLike): void;
629
622
  alpha(a: number): this;
@@ -643,27 +636,27 @@ declare class CanvasForm extends VisualForm {
643
636
  protected _textAlign(box: PtLikeIterable, vertical: string, offset?: PtLike, center?: Pt): Pt;
644
637
  reset(): this;
645
638
  protected _paint(): void;
646
- static point(ctx: CanvasRenderingContext2D, p: PtLike, radius?: number, shape?: string): void;
639
+ static point(ctx: RenderingContext2D, p: PtLike, radius?: number, shape?: string): void;
647
640
  point(p: PtLike, radius?: number, shape?: string): this;
648
- static circle(ctx: CanvasRenderingContext2D, pt: PtLike, radius?: number): void;
641
+ static circle(ctx: RenderingContext2D, pt: PtLike, radius?: number): void;
649
642
  circle(pts: PtLikeIterable): this;
650
- static ellipse(ctx: CanvasRenderingContext2D, pt: PtLike, radius: PtLike, rotation?: number, startAngle?: number, endAngle?: number, cc?: boolean): void;
643
+ static ellipse(ctx: RenderingContext2D, pt: PtLike, radius: PtLike, rotation?: number, startAngle?: number, endAngle?: number, cc?: boolean): void;
651
644
  ellipse(pt: PtLike, radius: PtLike, rotation?: number, startAngle?: number, endAngle?: number, cc?: boolean): this;
652
- static arc(ctx: CanvasRenderingContext2D, pt: PtLike, radius: number, startAngle: number, endAngle: number, cc?: boolean): void;
645
+ static arc(ctx: RenderingContext2D, pt: PtLike, radius: number, startAngle: number, endAngle: number, cc?: boolean): void;
653
646
  arc(pt: PtLike, radius: number, startAngle: number, endAngle: number, cc?: boolean): this;
654
- static square(ctx: CanvasRenderingContext2D, pt: PtLike, halfsize: number): void;
647
+ static square(ctx: RenderingContext2D, pt: PtLike, halfsize: number): void;
655
648
  square(pt: PtLike, halfsize: number): this;
656
- static line(ctx: CanvasRenderingContext2D, pts: PtLikeIterable): void;
649
+ static line(ctx: RenderingContext2D, pts: PtLikeIterable): void;
657
650
  line(pts: PtLikeIterable): this;
658
- static polygon(ctx: CanvasRenderingContext2D, pts: PtLikeIterable): void;
651
+ static polygon(ctx: RenderingContext2D, pts: PtLikeIterable): void;
659
652
  polygon(pts: PtLikeIterable): this;
660
- static rect(ctx: CanvasRenderingContext2D, pts: PtLikeIterable): void;
653
+ static rect(ctx: RenderingContext2D, pts: PtLikeIterable): void;
661
654
  rect(pts: PtLikeIterable): this;
662
- static image(ctx: CanvasRenderingContext2D, ptOrRect: PtLike | PtLikeIterable, img: CanvasImageSource | Img, orig?: PtLikeIterable): void;
655
+ static image(ctx: RenderingContext2D, ptOrRect: PtLike | PtLikeIterable, img: CanvasImageSource | Img, orig?: PtLikeIterable): void;
663
656
  image(ptOrRect: PtLike | PtLikeIterable, img: CanvasImageSource | Img, orig?: PtLikeIterable): this;
664
- static imageData(ctx: CanvasRenderingContext2D, ptOrRect: PtLike | PtLikeIterable, img: ImageData): void;
657
+ static imageData(ctx: RenderingContext2D, ptOrRect: PtLike | PtLikeIterable, img: ImageData): void;
665
658
  imageData(ptOrRect: PtLike | PtLikeIterable, img: ImageData): this;
666
- static text(ctx: CanvasRenderingContext2D, pt: PtLike, txt: string, maxWidth?: number): void;
659
+ static text(ctx: RenderingContext2D, pt: PtLike, txt: string, maxWidth?: number): void;
667
660
  text(pt: PtLike, txt: string, maxWidth?: number): this;
668
661
  textBox(box: PtIterable, txt: string, verticalAlign?: string, tail?: string, overrideBaseline?: boolean): this;
669
662
  paragraphBox(box: PtLikeIterable, txt: string, lineHeight?: number, verticalAlign?: string, crop?: boolean): this;
@@ -831,7 +824,7 @@ declare class Rectangle {
831
824
  static from(topLeft: PtLike, widthOrSize: number | PtLike, height?: number): Group;
832
825
  static fromTopLeft(topLeft: PtLike, widthOrSize: number | PtLike, height?: number): Group;
833
826
  static fromCenter(center: PtLike, widthOrSize: number | PtLike, height?: number): Group;
834
- static toCircle(pts: PtIterable, within?: boolean): Group;
827
+ static toCircle(pts: PtIterable, enclose?: boolean): Group;
835
828
  static toSquare(pts: PtIterable, enclose?: boolean): Group;
836
829
  static size(pts: PtIterable): Pt;
837
830
  static center(pts: PtIterable): Pt;
@@ -1376,4 +1369,4 @@ declare class Sound {
1376
1369
  toggle(): this;
1377
1370
  }
1378
1371
 
1379
- export { type AnimateCallbackFn, Body, Bound, CanvasForm, type CanvasPatternRepetition, CanvasSpace, type CanvasSpaceOptions, Circle, Color, type ColorType, Const, Create, Curve, type DOMFormContext, DOMSpace, type DefaultFormStyle, Delaunay, type DelaunayMesh, type DelaunayShape, Font, Form, Geom, Group, type GroupLike, HTMLForm, HTMLSpace, type IPlayer, type IPt, type ISoundAnalyzer, type ISpacePlayers, type ITempoListener, type ITempoProgressFn, type ITempoResponses, type ITempoStartFn, type ITimer, Img, type IntersectContext, Line, Mat, type MultiTouchElement, MultiTouchSpace, Noise, Num, Particle, Polygon, Pt, type PtIterable, type PtLike, type PtLikeIterable, type PtsCanvasRenderingContext2D, Range, Rectangle, SVGForm, SVGSpace, Shaping, Sound, type SoundType, Space, Tempo, type TouchPointsKey, Triangle, Typography, UI, UIButton, UIDragger, type UIHandler, UIPointerActions, UIShape, Util, Vec, VisualForm, type WarningType, World };
1372
+ export { type AnimateCallbackFn, Body, Bound, CanvasForm, type CanvasPatternRepetition, CanvasSpace, type CanvasSpaceOptions, Circle, Color, type ColorType, Const, Create, Curve, type DOMFormContext, DOMSpace, type DefaultFormStyle, Delaunay, type DelaunayMesh, type DelaunayShape, Font, Form, Geom, Group, type GroupLike, HTMLForm, HTMLSpace, type IPlayer, type IPt, type ISoundAnalyzer, type ISpacePlayers, type ITempoListener, type ITempoProgressFn, type ITempoResponses, type ITempoStartFn, type ITimer, Img, type IntersectContext, Line, Mat, type MultiTouchElement, MultiTouchSpace, Noise, Num, Particle, Polygon, Pt, type PtIterable, type PtLike, type PtLikeIterable, Range, Rectangle, type RenderingContext2D, SVGForm, SVGSpace, Shaping, Sound, type SoundType, Space, Tempo, type TouchPointsKey, Triangle, Typography, UI, UIButton, UIDragger, type UIHandler, UIPointerActions, UIShape, Util, Vec, VisualForm, type WarningType, World };
package/dist/index.js CHANGED
@@ -892,11 +892,11 @@ var Rectangle = class _Rectangle {
892
892
  /**
893
893
  * Create a new circle that either fits within or encloses the rectangle. Same as [`Circle.fromRect`](#link).
894
894
  * @param pts a Group or an Iterable<Pt> with 2 Pt representing a rectangle
895
- * @param within if `true`, the circle will be within the rectangle. If `false`, the circle will enclose the rectangle.
895
+ * @param enclose if `true`, the circle will enclose the rectangle. If `false`, the circle will fit inside the rectangle.
896
896
  * @returns a Group that represents a circle
897
897
  */
898
- static toCircle(pts, within = true) {
899
- return Circle.fromRect(pts, within);
898
+ static toCircle(pts, enclose = true) {
899
+ return Circle.fromRect(pts, enclose);
900
900
  }
901
901
  /**
902
902
  * Create a square that either fits within or encloses a rectangle.
@@ -4092,8 +4092,6 @@ var Bound = class _Bound extends Group {
4092
4092
  super(...args);
4093
4093
  this._center = new Pt();
4094
4094
  this._size = new Pt();
4095
- this._topLeft = new Pt();
4096
- this._bottomRight = new Pt();
4097
4095
  this._inited = false;
4098
4096
  this.init();
4099
4097
  }
@@ -4127,10 +4125,6 @@ var Bound = class _Bound extends Group {
4127
4125
  this._inited = true;
4128
4126
  }
4129
4127
  if (this.p1 && this.p2) {
4130
- const a = this.p1;
4131
- const b = this.p2;
4132
- this.topLeft = a.$min(b);
4133
- this._bottomRight = a.$max(b);
4134
4128
  this._updateSize();
4135
4129
  this._inited = true;
4136
4130
  }
@@ -4139,33 +4133,33 @@ var Bound = class _Bound extends Group {
4139
4133
  * Clone this bound and return a new one.
4140
4134
  */
4141
4135
  clone() {
4142
- return new _Bound(this._topLeft.clone(), this._bottomRight.clone());
4136
+ return new _Bound(this.topLeft.clone(), this.bottomRight.clone());
4143
4137
  }
4144
4138
  /**
4145
4139
  * Recalculte size and center.
4146
4140
  */
4147
4141
  _updateSize() {
4148
- this._size = this._bottomRight.$subtract(this._topLeft).abs();
4142
+ this._size = this.bottomRight.$subtract(this.topLeft).abs();
4149
4143
  this._updateCenter();
4150
4144
  }
4151
4145
  /**
4152
4146
  * Recalculate center.
4153
4147
  */
4154
4148
  _updateCenter() {
4155
- this._center = this._size.$multiply(0.5).add(this._topLeft);
4149
+ this._center = this._size.$multiply(0.5).add(this.topLeft);
4156
4150
  }
4157
4151
  /**
4158
4152
  * Recalculate based on top-left position and size.
4159
4153
  */
4160
4154
  _updatePosFromTop() {
4161
- this._bottomRight = this._topLeft.$add(this._size);
4155
+ this.bottomRight = this.topLeft.$add(this._size);
4162
4156
  this._updateCenter();
4163
4157
  }
4164
4158
  /**
4165
4159
  * Recalculate based on bottom-right position and size.
4166
4160
  */
4167
4161
  _updatePosFromBottom() {
4168
- this._topLeft = this._bottomRight.$subtract(this._size);
4162
+ this.topLeft = this.bottomRight.$subtract(this._size);
4169
4163
  this._updateCenter();
4170
4164
  }
4171
4165
  /**
@@ -4173,8 +4167,8 @@ var Bound = class _Bound extends Group {
4173
4167
  */
4174
4168
  _updatePosFromCenter() {
4175
4169
  const half = this._size.$multiply(0.5);
4176
- this._topLeft = this._center.$subtract(half);
4177
- this._bottomRight = this._center.$add(half);
4170
+ this.topLeft = this._center.$subtract(half);
4171
+ this.bottomRight = this._center.$add(half);
4178
4172
  }
4179
4173
  /**
4180
4174
  * Size of this Bound
@@ -4200,22 +4194,20 @@ var Bound = class _Bound extends Group {
4200
4194
  * Top-left position of this Bound
4201
4195
  */
4202
4196
  get topLeft() {
4203
- return new Pt(this._topLeft);
4197
+ return new Pt(this[0]);
4204
4198
  }
4205
4199
  set topLeft(p) {
4206
- this._topLeft = new Pt(p);
4207
- this[0] = this._topLeft;
4200
+ this[0] = new Pt(p);
4208
4201
  this._updateSize();
4209
4202
  }
4210
4203
  /**
4211
4204
  * Bottom-right position of this Bound
4212
4205
  */
4213
4206
  get bottomRight() {
4214
- return new Pt(this._bottomRight);
4207
+ return new Pt(this[1]);
4215
4208
  }
4216
4209
  set bottomRight(p) {
4217
- this._bottomRight = new Pt(p);
4218
- this[1] = this._bottomRight;
4210
+ this[1] = new Pt(p);
4219
4211
  this._updateSize();
4220
4212
  }
4221
4213
  /**
@@ -4277,8 +4269,8 @@ var Bound = class _Bound extends Group {
4277
4269
  * It's simpler and preferable to change the Bound's properties (eg, topLeft, bottomRight) instead of updating the Bound's Pts.
4278
4270
  */
4279
4271
  update() {
4280
- this._topLeft = this[0];
4281
- this._bottomRight = this[1];
4272
+ this.topLeft = this[0];
4273
+ this.bottomRight = this[1];
4282
4274
  this._updateSize();
4283
4275
  return this;
4284
4276
  }
@@ -5863,9 +5855,9 @@ var CanvasSpace2 = class extends MultiTouchSpace {
5863
5855
  constructor(elem, callback) {
5864
5856
  super();
5865
5857
  this._pixelScale = 1;
5866
- this._autoResize = true;
5867
5858
  this._bgcolor = "#e1e9f0";
5868
5859
  this._offscreen = false;
5860
+ this._autoResize = true;
5869
5861
  this._initialResize = false;
5870
5862
  let _selector = null;
5871
5863
  let _existed = false;
@@ -5956,8 +5948,7 @@ var CanvasSpace2 = class extends MultiTouchSpace {
5956
5948
  this.autoResize = opt.resize != void 0 ? opt.resize : false;
5957
5949
  if (opt.retina !== false) {
5958
5950
  const r1 = window ? window.devicePixelRatio || 1 : 1;
5959
- const r2 = this._ctx.webkitBackingStorePixelRatio || this._ctx.mozBackingStorePixelRatio || this._ctx.msBackingStorePixelRatio || this._ctx.oBackingStorePixelRatio || this._ctx.backingStorePixelRatio || 1;
5960
- this._pixelScale = Math.max(1, r1 / r2);
5951
+ this._pixelScale = Math.max(1, r1);
5961
5952
  }
5962
5953
  if (opt.offscreen) {
5963
5954
  this._offscreen = true;
@@ -5976,13 +5967,15 @@ var CanvasSpace2 = class extends MultiTouchSpace {
5976
5967
  * @param auto a boolean value indicating if auto size is set
5977
5968
  */
5978
5969
  set autoResize(auto) {
5979
- if (!window)
5980
- return;
5981
5970
  this._autoResize = auto;
5982
5971
  if (auto) {
5983
- window.addEventListener("resize", this._resizeHandler.bind(this));
5972
+ this._resizeObserver = new ResizeObserver((entries) => {
5973
+ this._resizeHandler(null);
5974
+ });
5975
+ this._resizeObserver.observe(this._container);
5984
5976
  } else {
5985
- window.removeEventListener("resize", this._resizeHandler.bind(this));
5977
+ if (this._resizeObserver)
5978
+ this._resizeObserver.disconnect();
5986
5979
  }
5987
5980
  }
5988
5981
  get autoResize() {
@@ -6027,12 +6020,10 @@ var CanvasSpace2 = class extends MultiTouchSpace {
6027
6020
  * @param evt
6028
6021
  */
6029
6022
  _resizeHandler(evt) {
6030
- if (!window)
6031
- return;
6032
6023
  const b = this._autoResize || this._initialResize ? this._container.getBoundingClientRect() : this._canvas.getBoundingClientRect();
6033
6024
  if (b) {
6034
6025
  const box = Bound.fromBoundingRect(b);
6035
- box.center = box.center.add(window.pageXOffset, window.pageYOffset);
6026
+ box.center = box.center.add((window == null ? void 0 : window.scrollX) || 0, (window == null ? void 0 : window.scrollY) || 0);
6036
6027
  this.resize(box, evt);
6037
6028
  }
6038
6029
  }
@@ -6159,9 +6150,7 @@ var CanvasSpace2 = class extends MultiTouchSpace {
6159
6150
  * Dispose of browser resources held by this space and remove all players. Call this before unmounting the canvas.
6160
6151
  */
6161
6152
  dispose() {
6162
- if (!window)
6163
- return;
6164
- window.removeEventListener("resize", this._resizeHandler.bind(this));
6153
+ this._resizeObserver.disconnect();
6165
6154
  this.stop();
6166
6155
  this.removeAll();
6167
6156
  return this;