@quinninc/pixi-transformer 0.0.8 → 0.0.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.
@@ -18,6 +18,7 @@ export declare class Transformer extends Pixi.Container {
18
18
  private toPoint;
19
19
  private target;
20
20
  private movedThreshold;
21
+ private updateCallbacks;
21
22
  private handleOpacity;
22
23
  private controlsSize;
23
24
  private controlsDimOpacity;
@@ -77,7 +78,7 @@ export declare class Transformer extends Pixi.Container {
77
78
  private deScale;
78
79
  select(target: Pixi.Container): void;
79
80
  unselect(): void;
80
- onUpdate: () => void;
81
+ onUpdate: (cb: (t?: Transformer) => void) => () => void;
81
82
  update(): void;
82
83
  setTitle(title: string): void;
83
84
  setCursor(cursor: string): void;
@@ -32,6 +32,7 @@ export class Transformer extends Pixi.Container {
32
32
  super();
33
33
  // target Pixi.Container
34
34
  this.target = null;
35
+ this.updateCallbacks = [];
35
36
  // position state
36
37
  this.left = 0;
37
38
  this.top = 0;
@@ -41,7 +42,15 @@ export class Transformer extends Pixi.Container {
41
42
  this.dragging = false;
42
43
  this.snapKey = false;
43
44
  this.pivotKey = false;
44
- this.onUpdate = () => { };
45
+ this.onUpdate = (cb) => {
46
+ this.updateCallbacks.push(cb);
47
+ return () => {
48
+ const index = this.updateCallbacks.indexOf(cb);
49
+ if (index > -1) {
50
+ this.updateCallbacks.splice(index, 1);
51
+ }
52
+ };
53
+ };
45
54
  const that = this;
46
55
  this._id = id;
47
56
  this.debug = debug;
@@ -532,14 +541,15 @@ export class Transformer extends Pixi.Container {
532
541
  this.pivotKey = false;
533
542
  this.snapKey = false;
534
543
  this.dragging = false;
535
- this.onUpdate();
544
+ for (const cb of this.updateCallbacks) {
545
+ cb(this);
546
+ }
536
547
  }
537
548
  update() {
538
549
  if (!this.target) {
539
550
  console.log("no target, returning...");
540
551
  return;
541
552
  }
542
- this.onUpdate();
543
553
  // copy object translation/transformation
544
554
  const bounds = this.target.getLocalBounds();
545
555
  this.width = bounds.width;
@@ -636,6 +646,9 @@ export class Transformer extends Pixi.Container {
636
646
  allHandles.forEach((handle) => {
637
647
  this.deScale(handle);
638
648
  });
649
+ for (const cb of this.updateCallbacks) {
650
+ cb(this);
651
+ }
639
652
  }
640
653
  setTitle(title) {
641
654
  title = title || "";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quinninc/pixi-transformer",
3
3
  "private": false,
4
- "version": "0.0.8",
4
+ "version": "0.0.9",
5
5
  "repository": {
6
6
  "url": "https://github.com/Quinn-Care-Private-Limited/pixi-transformer"
7
7
  },