@quinninc/pixi-transformer 0.0.7 → 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.
- package/dist/Transformer.d.ts +2 -1
- package/dist/Transformer.js +28 -3
- package/package.json +1 -1
package/dist/Transformer.d.ts
CHANGED
|
@@ -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;
|
package/dist/Transformer.js
CHANGED
|
@@ -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;
|
|
@@ -449,6 +458,12 @@ export class Transformer extends Pixi.Container {
|
|
|
449
458
|
keyCodes.includes(e.code) && (that[property] = false);
|
|
450
459
|
keyCodes.includes(e.key) && (that[property] = false);
|
|
451
460
|
}));
|
|
461
|
+
window.addEventListener("blur", () => {
|
|
462
|
+
that[property] = false;
|
|
463
|
+
});
|
|
464
|
+
window.addEventListener("focus", () => {
|
|
465
|
+
that[property] = false;
|
|
466
|
+
});
|
|
452
467
|
}
|
|
453
468
|
createHandle({ cursor, name, shape = "square", }) {
|
|
454
469
|
const handle = new Pixi.Graphics();
|
|
@@ -495,6 +510,9 @@ export class Transformer extends Pixi.Container {
|
|
|
495
510
|
this.unselect();
|
|
496
511
|
return;
|
|
497
512
|
}
|
|
513
|
+
if (this.target) {
|
|
514
|
+
this.unselect();
|
|
515
|
+
}
|
|
498
516
|
// console.log("select this - ", this);
|
|
499
517
|
this.target = target;
|
|
500
518
|
let _anchor;
|
|
@@ -520,14 +538,18 @@ export class Transformer extends Pixi.Container {
|
|
|
520
538
|
unselect() {
|
|
521
539
|
this.target = null;
|
|
522
540
|
this.visible = false;
|
|
523
|
-
this.
|
|
541
|
+
this.pivotKey = false;
|
|
542
|
+
this.snapKey = false;
|
|
543
|
+
this.dragging = false;
|
|
544
|
+
for (const cb of this.updateCallbacks) {
|
|
545
|
+
cb(this);
|
|
546
|
+
}
|
|
524
547
|
}
|
|
525
548
|
update() {
|
|
526
549
|
if (!this.target) {
|
|
527
550
|
console.log("no target, returning...");
|
|
528
551
|
return;
|
|
529
552
|
}
|
|
530
|
-
this.onUpdate();
|
|
531
553
|
// copy object translation/transformation
|
|
532
554
|
const bounds = this.target.getLocalBounds();
|
|
533
555
|
this.width = bounds.width;
|
|
@@ -624,6 +646,9 @@ export class Transformer extends Pixi.Container {
|
|
|
624
646
|
allHandles.forEach((handle) => {
|
|
625
647
|
this.deScale(handle);
|
|
626
648
|
});
|
|
649
|
+
for (const cb of this.updateCallbacks) {
|
|
650
|
+
cb(this);
|
|
651
|
+
}
|
|
627
652
|
}
|
|
628
653
|
setTitle(title) {
|
|
629
654
|
title = title || "";
|