lyb-pixi-js 1.12.58 → 1.12.60
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.
|
@@ -31,8 +31,6 @@ interface Params {
|
|
|
31
31
|
maxLength?: number;
|
|
32
32
|
/** 对齐方式 */
|
|
33
33
|
align?: "left" | "center";
|
|
34
|
-
/** 输入回调 */
|
|
35
|
-
onInput?: (text: number | string) => void;
|
|
36
34
|
/** 失去焦点回调 */
|
|
37
35
|
onValue?: (text: number | string) => void;
|
|
38
36
|
/** 格式化显示值 */
|
|
@@ -67,11 +65,11 @@ export declare class LibPixiInput extends LibPixiContainer {
|
|
|
67
65
|
private _createInput;
|
|
68
66
|
/** @description 创建只读输入框 */
|
|
69
67
|
private _createReadOnlyInput;
|
|
70
|
-
/** @description 失焦 */
|
|
71
|
-
private _blur;
|
|
72
68
|
/** @description 失去焦点处理 */
|
|
73
69
|
private _onBlurHandler;
|
|
74
70
|
/** @description 实时更新输入框位置 */
|
|
75
71
|
private _updateInputPosition;
|
|
72
|
+
/** @description 失焦 */
|
|
73
|
+
private _blur;
|
|
76
74
|
}
|
|
77
75
|
export {};
|
|
@@ -49,20 +49,32 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
49
49
|
}
|
|
50
50
|
/** @description 设置值 */
|
|
51
51
|
setValue(v) {
|
|
52
|
-
const { onFormatValue, type = "text" } = this._params;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
const { onFormatValue, type = "text", onValue, width } = this._params;
|
|
53
|
+
this._value = v;
|
|
54
|
+
const formatted = onFormatValue === null || onFormatValue === void 0 ? void 0 : onFormatValue(v);
|
|
55
|
+
const displayText = type === "password" ? formatted || "●".repeat(v.length) : formatted || v;
|
|
56
|
+
this._readonlyInput.text = displayText;
|
|
57
|
+
this._input.style.display = "none";
|
|
58
|
+
libPixiScaleContainer(this._readonlyInput, width);
|
|
59
|
+
const isEmpty = v === "";
|
|
60
|
+
const isNumber = type === "number";
|
|
61
|
+
const num = Number(v);
|
|
62
|
+
if (isNumber) {
|
|
63
|
+
const validNum = !isNaN(num) && num !== 0;
|
|
64
|
+
this._readonlyInput.visible = validNum;
|
|
65
|
+
this._placeholder.visible = !validNum;
|
|
66
|
+
onValue === null || onValue === void 0 ? void 0 : onValue(num);
|
|
58
67
|
}
|
|
59
68
|
else {
|
|
60
|
-
this._readonlyInput.
|
|
69
|
+
this._readonlyInput.visible = !isEmpty;
|
|
70
|
+
this._placeholder.visible = isEmpty;
|
|
71
|
+
onValue === null || onValue === void 0 ? void 0 : onValue(v);
|
|
61
72
|
}
|
|
62
73
|
}
|
|
63
74
|
/** @description 更改输入框描述 */
|
|
64
75
|
setPlaceholder(v) {
|
|
65
76
|
this._placeholder.text = v;
|
|
77
|
+
libPixiScaleContainer(this._placeholder, this._params.width);
|
|
66
78
|
}
|
|
67
79
|
/** @description 聚焦 */
|
|
68
80
|
focus() {
|
|
@@ -87,13 +99,11 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
87
99
|
/** @description 清空输入框 */
|
|
88
100
|
clear() {
|
|
89
101
|
this._input.value = "";
|
|
90
|
-
this._placeholder.visible = true;
|
|
91
|
-
this._readonlyInput.visible = false;
|
|
92
102
|
this._blur();
|
|
93
103
|
}
|
|
94
104
|
/** @description 创建输入框 */
|
|
95
105
|
_createInput() {
|
|
96
|
-
const { color = "#fff", maxLength = 999999, align = "left", type = "text",
|
|
106
|
+
const { color = "#fff", maxLength = 999999, align = "left", type = "text", fontFamily = "", bold = false, } = this._params;
|
|
97
107
|
this._input = document.createElement("input");
|
|
98
108
|
this._input.type = type;
|
|
99
109
|
this._input.maxLength = maxLength;
|
|
@@ -113,7 +123,6 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
113
123
|
if (this.value.length > maxLength && type === "number") {
|
|
114
124
|
this.value = this.value.slice(0, maxLength);
|
|
115
125
|
}
|
|
116
|
-
onInput(this.value.trim());
|
|
117
126
|
});
|
|
118
127
|
this._input.addEventListener("paste", function (e) {
|
|
119
128
|
var _a, _b;
|
|
@@ -140,6 +149,7 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
140
149
|
this._placeholder.visible = !value;
|
|
141
150
|
this._placeholder.anchor.set(align === "left" ? 0 : 0.5, 0.5);
|
|
142
151
|
this._placeholder.position.set(align === "left" ? 0 : width / 2, height / 2);
|
|
152
|
+
libPixiScaleContainer(this._placeholder, this._params.width);
|
|
143
153
|
//创建实际显示的文本
|
|
144
154
|
this._readonlyInput = new LibPixiText({
|
|
145
155
|
text: value,
|
|
@@ -153,28 +163,6 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
153
163
|
this._readonlyInput.anchor.set(align === "left" ? 0 : 0.5, 0.5);
|
|
154
164
|
this._readonlyInput.position.set(align === "left" ? 0 : width / 2, height / 2);
|
|
155
165
|
}
|
|
156
|
-
/** @description 失焦 */
|
|
157
|
-
_blur() {
|
|
158
|
-
const { onValue, width } = this._params;
|
|
159
|
-
const value = this._onBlurHandler();
|
|
160
|
-
this.setValue(value);
|
|
161
|
-
this._input.style.display = "none";
|
|
162
|
-
libPixiScaleContainer(this._readonlyInput, width);
|
|
163
|
-
if (this._params.type === "number" && value !== "") {
|
|
164
|
-
this._readonlyInput.visible = true;
|
|
165
|
-
onValue === null || onValue === void 0 ? void 0 : onValue(Number(value));
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
onValue === null || onValue === void 0 ? void 0 : onValue(value);
|
|
169
|
-
//如果输入的值为空,并且启用了描述,并且没有默认值,则显示描述
|
|
170
|
-
if (value === "" && this._placeholder) {
|
|
171
|
-
this._placeholder.visible = true;
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
this._readonlyInput.visible = true;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
166
|
/** @description 实时更新输入框位置 */
|
|
179
167
|
_updateInputPosition() {
|
|
180
168
|
const { width, height, x, y } = this.getBounds();
|
|
@@ -201,4 +189,9 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
201
189
|
this._input.style.transform = `rotate(90deg)`;
|
|
202
190
|
}
|
|
203
191
|
}
|
|
192
|
+
/** @description 失焦 */
|
|
193
|
+
_blur() {
|
|
194
|
+
const value = this._onBlurHandler();
|
|
195
|
+
this.setValue(value);
|
|
196
|
+
}
|
|
204
197
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Container, type HTMLText, type Text } from "pixi.js";
|
|
2
|
+
interface Params {
|
|
3
|
+
/** 高度 */
|
|
4
|
+
width: number;
|
|
5
|
+
/** 宽度 */
|
|
6
|
+
height: number;
|
|
7
|
+
/** 速度,px/s,默认100 */
|
|
8
|
+
speed?: number;
|
|
9
|
+
/** 可见性回调 */
|
|
10
|
+
onVisable: (v: boolean) => void;
|
|
11
|
+
}
|
|
12
|
+
/** @description 滚动通知栏 */
|
|
13
|
+
export declare class LibPixiNoticeBar extends Container {
|
|
14
|
+
/** 当前参数 */
|
|
15
|
+
private _params;
|
|
16
|
+
/** 文本队列 */
|
|
17
|
+
private _textQueue;
|
|
18
|
+
/** 当前显示的文本 */
|
|
19
|
+
private _currentText?;
|
|
20
|
+
constructor(params: Params);
|
|
21
|
+
/** @description 添加到队列 */
|
|
22
|
+
addText(...text: (Text | HTMLText)[]): void;
|
|
23
|
+
/** @description 显示文本 */
|
|
24
|
+
private _showText;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import gsap from "gsap";
|
|
2
|
+
import { Container } from "pixi.js";
|
|
3
|
+
import { LibPixiRectangle } from "../Base/LibPixiRectangle";
|
|
4
|
+
/** @description 滚动通知栏 */
|
|
5
|
+
export class LibPixiNoticeBar extends Container {
|
|
6
|
+
constructor(params) {
|
|
7
|
+
super();
|
|
8
|
+
/** 文本队列 */
|
|
9
|
+
this._textQueue = [];
|
|
10
|
+
this._params = params;
|
|
11
|
+
const { width, height } = params;
|
|
12
|
+
const rectangle = new LibPixiRectangle(width, height);
|
|
13
|
+
this.addChild(rectangle);
|
|
14
|
+
this.mask = rectangle;
|
|
15
|
+
}
|
|
16
|
+
/** @description 添加到队列 */
|
|
17
|
+
addText(...text) {
|
|
18
|
+
this._textQueue.push(...text);
|
|
19
|
+
if (this._currentText)
|
|
20
|
+
return;
|
|
21
|
+
this._showText();
|
|
22
|
+
}
|
|
23
|
+
/** @description 显示文本 */
|
|
24
|
+
_showText() {
|
|
25
|
+
this._currentText = this._textQueue.shift();
|
|
26
|
+
if (!this._currentText)
|
|
27
|
+
return;
|
|
28
|
+
this._params.onVisable(true);
|
|
29
|
+
this.addChild(this._currentText);
|
|
30
|
+
this._currentText.anchor.y = 0.5;
|
|
31
|
+
this._currentText.position.set(this._params.width, this._params.height / 2);
|
|
32
|
+
gsap.to(this._currentText, {
|
|
33
|
+
x: -this._currentText.width,
|
|
34
|
+
duration: (this._params.width + this._currentText.width) /
|
|
35
|
+
(this._params.speed || 100),
|
|
36
|
+
ease: "none",
|
|
37
|
+
onComplete: () => {
|
|
38
|
+
this._currentText.destroy();
|
|
39
|
+
this._currentText = undefined;
|
|
40
|
+
if (this._textQueue.length) {
|
|
41
|
+
this._showText();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this._params.onVisable(false);
|
|
45
|
+
this._currentText = undefined;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
package/README.md
CHANGED