lyb-pixi-js 1.12.58 → 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
- const value = v;
54
- this._value = value;
55
- if (type === "password") {
56
- this._readonlyInput.text =
57
- (onFormatValue === null || onFormatValue === void 0 ? void 0 : onFormatValue(value)) || "".repeat(value.length);
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.text = (onFormatValue === null || onFormatValue === void 0 ? void 0 : onFormatValue(value)) || value;
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", onInput = () => { }, fontFamily = "", bold = false, } = this._params;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-pixi-js",
3
- "version": "1.12.58",
3
+ "version": "1.12.59",
4
4
  "description": "自用Pixi.JS方法库",
5
5
  "license": "ISC",
6
6
  "exports": {