@caperjs/core 0.2.3 → 0.2.4
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/lib/caper.mjs +15 -10
- package/lib/caper.mjs.map +1 -1
- package/lib/ui/Button.d.ts +8 -1
- package/lib/ui/Button.d.ts.map +1 -1
- package/lib/ui/Button.test.d.ts +2 -0
- package/lib/ui/Button.test.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/ui/Button.test.ts +236 -0
- package/src/ui/Button.ts +41 -10
- package/src/version.ts +1 -1
package/lib/caper.mjs
CHANGED
|
@@ -289,7 +289,7 @@ function un(e, t) {
|
|
|
289
289
|
}
|
|
290
290
|
//#endregion
|
|
291
291
|
//#region src/version.ts
|
|
292
|
-
var dn = "0.2.
|
|
292
|
+
var dn = "0.2.4", fn = "8.19.0", pn = " ........ ..... ............ ............. ........... \n ............. ....... ................ ............. .............. \n .............. ......... ............... ............. .............. \n ..... ........... .............. ............ .............. \n ..... ...... ...... .............. ............. ............. \n .............. ...... ..... ............ ............. ..... ...... \n ................... ..... ..... ............. ..... ....... \n ................ .......... ............. ..... ..... ";
|
|
293
293
|
function mn() {
|
|
294
294
|
let e = `\n${pn}\n\n v${dn} | %cPixi.js v${fn} %c| %chttps://github.com/anthonysapp/caper\n\n`;
|
|
295
295
|
console.log(e, "color: #E91E63; font-weight: 600;", "color: inherit;", "color: #00BCD4; text-decoration: underline;");
|
|
@@ -1060,17 +1060,20 @@ var Qn = [
|
|
|
1060
1060
|
}, e), this.id = this.config.id, e.layout === void 0 ? this.layout = !1 : this.layout = e.layout, this.view = this.add.sprite({
|
|
1061
1061
|
asset: this.config.textures.default,
|
|
1062
1062
|
sheet: this.config.sheet ?? void 0
|
|
1063
|
-
}), this.cursor = this.config.cursor, this.enabled = e.enabled !== !1, this.layout?.style.transformOrigin !== "top left" && (this.layout = { transformOrigin: "top left" }, this.app.renderer.layout && this.app.renderer.layout.update(this)), this.config.textLabel && this.addLabel(this.config.textLabel), this.addSignalConnection(this.onInteraction("pointerover").connect(this.handlePointerOver, -1), this.onInteraction("pointerout").connect(this.handlePointerOut, -1), this.onInteraction("pointerup").connect(this.handlePointerUp, -1), this.onInteraction("click").connect(this.handleClick, -1), this.onInteraction("tap").connect(this.handleClick, -1), this.onInteraction("pointerdown").connect(this.handlePointerDown, -1));
|
|
1063
|
+
}), this.cursor = this.config.cursor, this.enabled = e.enabled !== !1, this.layout?.style.transformOrigin !== "top left" && (this.layout = { transformOrigin: "top left" }, this.app.renderer.layout && this.app.renderer.layout.update(this)), this.config.textLabel && this.addLabel(this.config.textLabel), this.addSignalConnection(this.onInteraction("pointerover").connect(this.handlePointerOver, -1), this.onInteraction("pointerout").connect(this.handlePointerOut, -1), this.onInteraction("pointerup").connect(this.handlePointerUp, -1), this.onInteraction("click").connect(this.handleClick, -1), this.onInteraction("tap").connect(this.handleClick, -1), this.onInteraction("pointerdown").connect(this.handlePointerDown, -1)), this.on("removed", this._resetPressState);
|
|
1064
1064
|
}
|
|
1065
1065
|
set enabled(e) {
|
|
1066
1066
|
this._enabled !== e && (this._enabled = e, this.cursor = this._enabled ? this.config.cursor : this.config.disabledCursor, this.focusEnabled = e, this._enabled ? (this.view.texture = this.make.texture({
|
|
1067
1067
|
asset: this.config.textures.default,
|
|
1068
1068
|
sheet: this.config.sheet ?? void 0
|
|
1069
|
-
}), this.onEnabled.emit()) : (this.view.texture = this.make.texture({
|
|
1069
|
+
}), this.onEnabled.emit()) : (this._resetPressState(), this.view.texture = this.make.texture({
|
|
1070
1070
|
asset: this.config.textures.disabled || this.config.textures.default,
|
|
1071
1071
|
sheet: this.config.sheet ?? void 0
|
|
1072
1072
|
}), this.onDisabled.emit()));
|
|
1073
1073
|
}
|
|
1074
|
+
_resetPressState() {
|
|
1075
|
+
window.removeEventListener("pointerup", this.handlePointerUpOutside), this.off("pointerupoutside", this.handlePointerUpOutside), this.isDown = !1, this._pointerId = void 0;
|
|
1076
|
+
}
|
|
1074
1077
|
addLabel(e) {
|
|
1075
1078
|
if (e instanceof O || e instanceof St || e instanceof w) e.anchor.set(.5, .5), this._textLabel = this.add.existing(e), this._textLabel.layout = !1;
|
|
1076
1079
|
else switch (e.anchor = .5, e.type) {
|
|
@@ -1105,7 +1108,7 @@ var Qn = [
|
|
|
1105
1108
|
return S.getInstance();
|
|
1106
1109
|
}
|
|
1107
1110
|
destroy(e) {
|
|
1108
|
-
this.onDestroy.emit(), super.destroy(e);
|
|
1111
|
+
this.onDestroy.emit(), this._resetPressState(), this._isDownListenerAdded &&= (this.app.ticker.remove(this._handleIsDownCallbacks), !1), super.destroy(e);
|
|
1109
1112
|
}
|
|
1110
1113
|
focusOut() {
|
|
1111
1114
|
super.focusOut(), this.isDown = !1, this.isOver = !1;
|
|
@@ -1120,7 +1123,7 @@ var Qn = [
|
|
|
1120
1123
|
this._isDownCallbacks.set(e, t), this._checkIsDownCallbacks();
|
|
1121
1124
|
}
|
|
1122
1125
|
removeIsDownCallback(e) {
|
|
1123
|
-
this._isDownCallbacks.delete(e);
|
|
1126
|
+
this._isDownCallbacks.delete(e), this._checkIsDownCallbacks();
|
|
1124
1127
|
}
|
|
1125
1128
|
setTexture(e, t) {
|
|
1126
1129
|
this.config.textures[e] = t, e === "default" && (this.view.texture = this.make.texture({
|
|
@@ -1152,20 +1155,22 @@ var Qn = [
|
|
|
1152
1155
|
sheet: this.config.sheet
|
|
1153
1156
|
}), this.onUp.emit(), this._pointerId = void 0);
|
|
1154
1157
|
}
|
|
1155
|
-
handleClick() {
|
|
1156
|
-
this._enabled && (this.isDown = !1, this.onClick.emit(), this.config.sounds?.click && this.app.audio.play(this.config.sounds.click, "sfx"), this.config.actions?.click && this._doAction(this.config.actions.click));
|
|
1158
|
+
handleClick(e) {
|
|
1159
|
+
this._enabled && (e?.pointerId !== void 0 && !this.isDown || e !== void 0 && e === this._lastClickEvent || (this._lastClickEvent = e, this.isDown = !1, this.onClick.emit(), this.config.sounds?.click && this.app.audio.play(this.config.sounds.click, "sfx"), this.config.actions?.click && this._doAction(this.config.actions.click)));
|
|
1157
1160
|
}
|
|
1158
1161
|
handlePointerUpOutside(e) {
|
|
1159
|
-
|
|
1162
|
+
if (e.pointerId !== this._pointerId) return;
|
|
1163
|
+
let t = this._enabled;
|
|
1164
|
+
this._resetPressState(), this.isOver = !1, t && (this.view.texture = this.make.texture({
|
|
1160
1165
|
asset: this.config.textures.default,
|
|
1161
1166
|
sheet: this.config.sheet
|
|
1162
|
-
}), this.
|
|
1167
|
+
}), this.onUpOutside.emit());
|
|
1163
1168
|
}
|
|
1164
1169
|
_doAction(e) {
|
|
1165
1170
|
typeof e == "function" ? e() : (e.data.button || (e.data.button = this), this.app.action(e.id, e.data));
|
|
1166
1171
|
}
|
|
1167
1172
|
_checkIsDownCallbacks() {
|
|
1168
|
-
!this._isDownListenerAdded && this._isDownCallbacks.size > 0 ? (this._isDownListenerAdded = !0, this.app.ticker.add(this._handleIsDownCallbacks)) : (this.app.ticker.remove(this._handleIsDownCallbacks), this._isDownListenerAdded = !1);
|
|
1173
|
+
!this._isDownListenerAdded && this._isDownCallbacks.size > 0 ? (this._isDownListenerAdded = !0, this.app.ticker.add(this._handleIsDownCallbacks)) : this._isDownListenerAdded && this._isDownCallbacks.size === 0 && (this.app.ticker.remove(this._handleIsDownCallbacks), this._isDownListenerAdded = !1);
|
|
1169
1174
|
}
|
|
1170
1175
|
_handleIsDownCallbacks() {
|
|
1171
1176
|
this.isDown && this._isDownCallbacks.forEach((e) => {
|