lyb-pixi-js 1.12.57 → 1.12.59
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
|
}
|
|
@@ -15,6 +15,8 @@ export interface LibPixiScrollContainerXParams {
|
|
|
15
15
|
maskX?: number;
|
|
16
16
|
/** 遮罩Y坐标 */
|
|
17
17
|
maskY?: number;
|
|
18
|
+
/** 滚动触发 */
|
|
19
|
+
onScroll?: (x: number) => void;
|
|
18
20
|
}
|
|
19
21
|
/** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹 */
|
|
20
22
|
export declare class LibPixiScrollContainerX extends LibPixiContainer {
|
|
@@ -42,6 +44,8 @@ export declare class LibPixiScrollContainerX extends LibPixiContainer {
|
|
|
42
44
|
private _maskGraphics;
|
|
43
45
|
/** 滚动的内容 */
|
|
44
46
|
private _content;
|
|
47
|
+
/** 滚动触发 */
|
|
48
|
+
private _onScroll?;
|
|
45
49
|
constructor(params: LibPixiScrollContainerXParams);
|
|
46
50
|
/** @description 添加边距 */
|
|
47
51
|
addMargin(leftMargin: number, rightMargin?: number): void;
|
|
@@ -6,7 +6,7 @@ import { LibPixiRectangle } from "../Base/LibPixiRectangle";
|
|
|
6
6
|
/** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹 */
|
|
7
7
|
export class LibPixiScrollContainerX extends LibPixiContainer {
|
|
8
8
|
constructor(params) {
|
|
9
|
-
const { width, height, scrollContent, bgColor, maskTexture, maskX = 0, maskY = 0, } = params;
|
|
9
|
+
const { width, height, scrollContent, bgColor, maskTexture, maskX = 0, maskY = 0, onScroll, } = params;
|
|
10
10
|
super(width, height, bgColor);
|
|
11
11
|
/** 开始位置 */
|
|
12
12
|
this._startX = 0;
|
|
@@ -23,6 +23,7 @@ export class LibPixiScrollContainerX extends LibPixiContainer {
|
|
|
23
23
|
/** 左边距 */
|
|
24
24
|
this._leftMargin = 0;
|
|
25
25
|
this._scrollContent = scrollContent;
|
|
26
|
+
this._onScroll = onScroll;
|
|
26
27
|
// 创建内容容器
|
|
27
28
|
this._content = new Container();
|
|
28
29
|
this.addChild(this._content);
|
|
@@ -113,10 +114,12 @@ export class LibPixiScrollContainerX extends LibPixiContainer {
|
|
|
113
114
|
}
|
|
114
115
|
/** @description 拖动 */
|
|
115
116
|
_onDragMove(event) {
|
|
117
|
+
var _a;
|
|
116
118
|
if (this._isDragging) {
|
|
117
119
|
const { x } = event.getLocalPosition(this);
|
|
118
120
|
const newPosition = x - this._startX;
|
|
119
121
|
this._content.x = newPosition;
|
|
122
|
+
(_a = this._onScroll) === null || _a === void 0 ? void 0 : _a.call(this, this._content.x);
|
|
120
123
|
}
|
|
121
124
|
}
|
|
122
125
|
/** @description 拖动结束 */
|
|
@@ -164,6 +167,8 @@ export class LibPixiScrollContainerX extends LibPixiContainer {
|
|
|
164
167
|
}
|
|
165
168
|
/** @description 限制滚动范围 */
|
|
166
169
|
_limitScrollRange() {
|
|
170
|
+
var _a;
|
|
171
|
+
(_a = this._onScroll) === null || _a === void 0 ? void 0 : _a.call(this, this._content.x);
|
|
167
172
|
//如果内容顶部离开了滚动容器顶部,则归位
|
|
168
173
|
if (this._content.x > 0) {
|
|
169
174
|
//回弹
|
|
@@ -171,6 +176,10 @@ export class LibPixiScrollContainerX extends LibPixiContainer {
|
|
|
171
176
|
duration: 0.2,
|
|
172
177
|
ease: "power1.out",
|
|
173
178
|
x: 0,
|
|
179
|
+
onUpdate: () => {
|
|
180
|
+
var _a;
|
|
181
|
+
(_a = this._onScroll) === null || _a === void 0 ? void 0 : _a.call(this, this._content.x);
|
|
182
|
+
},
|
|
174
183
|
});
|
|
175
184
|
}
|
|
176
185
|
// 如果滚动距离大于内容高度减去遮罩高度
|
|
@@ -184,6 +193,10 @@ export class LibPixiScrollContainerX extends LibPixiContainer {
|
|
|
184
193
|
duration: 0.2,
|
|
185
194
|
ease: "power1.out",
|
|
186
195
|
x,
|
|
196
|
+
onUpdate: () => {
|
|
197
|
+
var _a;
|
|
198
|
+
(_a = this._onScroll) === null || _a === void 0 ? void 0 : _a.call(this, this._content.x);
|
|
199
|
+
},
|
|
187
200
|
});
|
|
188
201
|
}
|
|
189
202
|
// 否则静止不动
|
|
@@ -191,6 +204,10 @@ export class LibPixiScrollContainerX extends LibPixiContainer {
|
|
|
191
204
|
gsap.to(this._content, {
|
|
192
205
|
duration: 0.25,
|
|
193
206
|
x: 0,
|
|
207
|
+
onUpdate: () => {
|
|
208
|
+
var _a;
|
|
209
|
+
(_a = this._onScroll) === null || _a === void 0 ? void 0 : _a.call(this, this._content.x);
|
|
210
|
+
},
|
|
194
211
|
});
|
|
195
212
|
}
|
|
196
213
|
}
|