lyb-pixi-js 1.11.5 → 1.11.7
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/Utils/LibPixiEvent.js +9 -3
- package/Utils/LibPixiIntervalTrigger.d.ts +2 -1
- package/Utils/LibPixiIntervalTrigger.js +3 -1
- package/Utils/LibPixiViteAssetsHash.d.ts +8 -0
- package/Utils/LibPixiViteAssetsHash.js +343 -0
- package/libPixiJs.d.ts +1 -1
- package/lyb-pixi.js +96 -113
- package/package.json +1 -1
package/Utils/LibPixiEvent.js
CHANGED
|
@@ -24,13 +24,19 @@ export const libPixiEvent = (v, eventName, callback, params = {}) => {
|
|
|
24
24
|
const { once = false, debounce = false, debounceTime = 1000, preventDragClick = false } = params;
|
|
25
25
|
v.cursor = "pointer";
|
|
26
26
|
v.eventMode = "static";
|
|
27
|
+
let lastX = 0;
|
|
28
|
+
let lastY = 0;
|
|
27
29
|
let isDragging = false;
|
|
28
30
|
if (preventDragClick) {
|
|
29
|
-
v.on("pointerdown", () => {
|
|
31
|
+
v.on("pointerdown", (e) => {
|
|
30
32
|
isDragging = false;
|
|
33
|
+
lastX = e.globalX;
|
|
34
|
+
lastY = e.globalY;
|
|
31
35
|
});
|
|
32
|
-
v.on("pointermove", () => {
|
|
33
|
-
|
|
36
|
+
v.on("pointermove", (e) => {
|
|
37
|
+
if (e.globalX !== lastX || e.globalY !== lastY) {
|
|
38
|
+
isDragging = true;
|
|
39
|
+
}
|
|
34
40
|
});
|
|
35
41
|
}
|
|
36
42
|
const fn = (e) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @description 间隔触发
|
|
2
2
|
* @param callback 回调函数
|
|
3
3
|
* @param interval 间隔毫秒,或随机范围
|
|
4
|
+
* @param immediately 是否立即执行一次
|
|
4
5
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiIntervalTrigger-间隔触发
|
|
5
6
|
*/
|
|
6
|
-
export declare const libPixiIntervalTrigger: (callback: () => void, interval: number | [number, number]) => () => void;
|
|
7
|
+
export declare const libPixiIntervalTrigger: (callback: () => void, interval: number | [number, number], immediately?: boolean) => () => void;
|
|
@@ -3,9 +3,10 @@ import { libJsRandom } from "lyb-js/Random/LibJsRandom.js";
|
|
|
3
3
|
/** @description 间隔触发
|
|
4
4
|
* @param callback 回调函数
|
|
5
5
|
* @param interval 间隔毫秒,或随机范围
|
|
6
|
+
* @param immediately 是否立即执行一次
|
|
6
7
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiIntervalTrigger-间隔触发
|
|
7
8
|
*/
|
|
8
|
-
export const libPixiIntervalTrigger = (callback, interval) => {
|
|
9
|
+
export const libPixiIntervalTrigger = (callback, interval, immediately = true) => {
|
|
9
10
|
let elapsedTime = 0;
|
|
10
11
|
// 创建一个新的 Ticker 实例
|
|
11
12
|
const ticker = new Ticker();
|
|
@@ -24,6 +25,7 @@ export const libPixiIntervalTrigger = (callback, interval) => {
|
|
|
24
25
|
elapsedTime = 0;
|
|
25
26
|
}
|
|
26
27
|
};
|
|
28
|
+
immediately && callback();
|
|
27
29
|
ticker.add(tickerCallback);
|
|
28
30
|
ticker.start();
|
|
29
31
|
return () => {
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { readdir, readFile, copyFile, mkdir, writeFile, rm, rename } from "fs/promises";
|
|
11
|
+
import { createHash } from "crypto";
|
|
12
|
+
import { extname, basename, join, dirname, relative } from "path";
|
|
13
|
+
/**
|
|
14
|
+
* .fnt文件处理工具类
|
|
15
|
+
*/
|
|
16
|
+
class FntView {
|
|
17
|
+
/**
|
|
18
|
+
* 构造函数
|
|
19
|
+
* @param {Buffer} buffer - .fnt文件内容缓冲区
|
|
20
|
+
*/
|
|
21
|
+
constructor(buffer) {
|
|
22
|
+
this.rawAtlas = buffer.toString();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 获取.fnt文件中引用的所有贴图文件名
|
|
26
|
+
* @returns {string[]} 贴图文件名数组
|
|
27
|
+
*/
|
|
28
|
+
getTextures() {
|
|
29
|
+
const regex = /file="([^"]+\.png)"/g;
|
|
30
|
+
return [...this.rawAtlas.matchAll(regex)].map((m) => m[1]);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 替换.fnt文件中的贴图引用
|
|
34
|
+
* @param filename - 原始贴图文件名
|
|
35
|
+
* @param newFilename - 新的贴图文件名
|
|
36
|
+
*/
|
|
37
|
+
replaceTexture(filename, newFilename) {
|
|
38
|
+
const escaped = filename.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
39
|
+
const regex = new RegExp(`(file=")${escaped}(")`, "g");
|
|
40
|
+
this.rawAtlas = this.rawAtlas.replace(regex, `$1${newFilename}$2`);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 获取处理后的.fnt文件内容缓冲区
|
|
44
|
+
* @returns {Buffer} 文件内容缓冲区
|
|
45
|
+
*/
|
|
46
|
+
get buffer() {
|
|
47
|
+
return Buffer.from(this.rawAtlas);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Pixi.js 资源缓存清除工具
|
|
52
|
+
*
|
|
53
|
+
* 通过为静态资源文件名添加哈希值来实现缓存清除功能,
|
|
54
|
+
* 同时处理特殊文件格式(如.fnt、.atlas)的引用关系。
|
|
55
|
+
*/
|
|
56
|
+
class PixiCacheBuster {
|
|
57
|
+
/**
|
|
58
|
+
* 构造函数
|
|
59
|
+
* @param srcDir - 源文件目录路径
|
|
60
|
+
* @param distDir - 目标输出目录路径
|
|
61
|
+
*/
|
|
62
|
+
constructor(srcDir, distDir) {
|
|
63
|
+
/** main 目录文件映射表(原始文件名 -> 哈希文件名) */
|
|
64
|
+
this.mapMain = {};
|
|
65
|
+
/** preload 目录文件映射表(原始文件名 -> 哈希文件名) */
|
|
66
|
+
this.mapPreload = {};
|
|
67
|
+
/** main 清单文件名 */
|
|
68
|
+
this.manifestMain = "mainManifest.json";
|
|
69
|
+
/** preload 清单文件名 */
|
|
70
|
+
this.manifestPreload = "preloadManifest.json";
|
|
71
|
+
this.srcDir = srcDir;
|
|
72
|
+
this.distDir = distDir;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 标准化路径(将反斜杠转换为正斜杠)
|
|
76
|
+
* @param p - 原始路径
|
|
77
|
+
* @returns 标准化后的路径
|
|
78
|
+
*/
|
|
79
|
+
normalizePath(p) {
|
|
80
|
+
return p.replace(/\\/g, "/");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 检查文件是否为图片
|
|
84
|
+
* @param file - 文件路径
|
|
85
|
+
* @returns {boolean} 是否为图片文件
|
|
86
|
+
*/
|
|
87
|
+
isImage(file) {
|
|
88
|
+
return /\.(png|jpe?g|gif|webp|svg)$/i.test(file);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 递归遍历目录获取所有文件路径
|
|
92
|
+
* @param dir - 要遍历的目录路径
|
|
93
|
+
* @returns {Promise<string[]>} 文件路径数组
|
|
94
|
+
*/
|
|
95
|
+
walk(dir) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const entries = yield readdir(dir, { withFileTypes: true });
|
|
98
|
+
const files = yield Promise.all(entries.map((entry) => {
|
|
99
|
+
const fullPath = join(dir, entry.name);
|
|
100
|
+
return entry.isDirectory() ? this.walk(fullPath) : [fullPath];
|
|
101
|
+
}));
|
|
102
|
+
return files.flat();
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 处理普通文件(添加哈希值到文件名)
|
|
107
|
+
* @param filePath - 文件路径
|
|
108
|
+
* @param srcBase - 源基础目录
|
|
109
|
+
* @param distBase - 目标基础目录
|
|
110
|
+
* @param {Record<string, string>} map - 文件映射表
|
|
111
|
+
*/
|
|
112
|
+
processFile(filePath, srcBase, distBase, map) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const buf = yield readFile(filePath);
|
|
115
|
+
const ext = extname(filePath);
|
|
116
|
+
const relPath = this.normalizePath(relative(srcBase, filePath));
|
|
117
|
+
const relDir = dirname(relPath);
|
|
118
|
+
const base = basename(filePath, ext);
|
|
119
|
+
//生成8位MD5哈希值
|
|
120
|
+
const hash = createHash("md5").update(buf).digest("hex").slice(0, 8);
|
|
121
|
+
const hashedName = ext === ".ttf" ? `${base}${ext}` : `${base}-${hash}${ext}`;
|
|
122
|
+
const distPath = join(distBase, relDir, hashedName);
|
|
123
|
+
//创建目录并写入文件
|
|
124
|
+
yield mkdir(dirname(distPath), { recursive: true });
|
|
125
|
+
yield writeFile(distPath, buf);
|
|
126
|
+
//更新映射表
|
|
127
|
+
map[relPath] = this.normalizePath(join(relDir, hashedName));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 复制原始文件(不添加哈希值)
|
|
132
|
+
* @param srcBase - 源基础目录
|
|
133
|
+
* @param distBase - 目标基础目录
|
|
134
|
+
*/
|
|
135
|
+
copyOriginal(srcBase, distBase) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const files = yield this.walk(srcBase);
|
|
138
|
+
yield Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const relPath = this.normalizePath(relative(srcBase, file));
|
|
140
|
+
const distPath = join(distBase, relPath);
|
|
141
|
+
yield mkdir(dirname(distPath), { recursive: true });
|
|
142
|
+
yield copyFile(file, distPath);
|
|
143
|
+
})));
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 处理.fnt文件(位图字体文件)
|
|
148
|
+
* @param filePath - .fnt文件路径
|
|
149
|
+
* @param srcBase - 源基础目录
|
|
150
|
+
* @param distBase - 目标基础目录
|
|
151
|
+
* @param {Record<string, string>} map - 文件映射表
|
|
152
|
+
*/
|
|
153
|
+
processFntFile(filePath, srcBase, distBase, map) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const buf = yield readFile(filePath);
|
|
156
|
+
const fntView = new FntView(buf);
|
|
157
|
+
const textures = fntView.getTextures();
|
|
158
|
+
//获取.fnt文件所在目录的相对路径
|
|
159
|
+
const fntDir = dirname(this.normalizePath(relative(srcBase, filePath)));
|
|
160
|
+
//替换.fnt文件中引用的所有贴图文件名
|
|
161
|
+
for (const tex of textures) {
|
|
162
|
+
const fullTexPath = this.normalizePath(join(fntDir, tex));
|
|
163
|
+
const newName = map[fullTexPath];
|
|
164
|
+
fntView.replaceTexture(tex, basename(newName));
|
|
165
|
+
}
|
|
166
|
+
//写入处理后的.fnt文件
|
|
167
|
+
const relPath = this.normalizePath(relative(srcBase, filePath));
|
|
168
|
+
const hashedDistPath = join(distBase, dirname(relPath), basename(map[relPath]));
|
|
169
|
+
yield mkdir(dirname(hashedDistPath), { recursive: true });
|
|
170
|
+
yield writeFile(hashedDistPath, fntView.buffer);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 处理.atlas文件(纹理图集文件)
|
|
175
|
+
* @param filePath - .atlas文件路径
|
|
176
|
+
* @param srcBase - 源基础目录
|
|
177
|
+
* @param distBase - 目标基础目录
|
|
178
|
+
* @param {Record<string, string>} map - 文件映射表
|
|
179
|
+
* @param [overrideFileName] - 覆盖输出文件名(不带扩展名)
|
|
180
|
+
*/
|
|
181
|
+
processAtlasFile(filePath, srcBase, distBase, map, overrideFileName) {
|
|
182
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
+
const buf = yield readFile(filePath);
|
|
184
|
+
let content = buf.toString();
|
|
185
|
+
const atlasDir = dirname(this.normalizePath(relative(srcBase, filePath)));
|
|
186
|
+
//替换.atlas文件中引用的所有图片文件名
|
|
187
|
+
for (const [original, hashed] of Object.entries(map)) {
|
|
188
|
+
if (!this.isImage(original))
|
|
189
|
+
continue;
|
|
190
|
+
const imageDir = dirname(original);
|
|
191
|
+
//如果图片目录和.atlas文件目录不一致,则跳过
|
|
192
|
+
if (imageDir !== atlasDir)
|
|
193
|
+
continue;
|
|
194
|
+
const originalBase = basename(original);
|
|
195
|
+
const hashedBase = basename(hashed);
|
|
196
|
+
const regex = new RegExp(`^${originalBase}$`, "gm");
|
|
197
|
+
content = content.replace(regex, hashedBase);
|
|
198
|
+
}
|
|
199
|
+
//写入处理后的.atlas文件
|
|
200
|
+
const relPath = this.normalizePath(relative(srcBase, filePath));
|
|
201
|
+
const finalName = overrideFileName ? `${overrideFileName}.atlas` : basename(relPath);
|
|
202
|
+
const finalDistPath = join(distBase, atlasDir, finalName);
|
|
203
|
+
yield mkdir(dirname(finalDistPath), { recursive: true });
|
|
204
|
+
yield writeFile(finalDistPath, content);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* 处理.json文件(通常是Spine动画文件)
|
|
209
|
+
* @param filePath - .json文件路径
|
|
210
|
+
* @param srcBase - 源基础目录
|
|
211
|
+
* @param distBase - 目标基础目录
|
|
212
|
+
* @param {Record<string, string>} map - 文件映射表
|
|
213
|
+
*/
|
|
214
|
+
processJsonFile(filePath, srcBase, distBase, map) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
const buf = yield readFile(filePath);
|
|
217
|
+
const relPath = this.normalizePath(relative(srcBase, filePath));
|
|
218
|
+
//生成哈希文件名
|
|
219
|
+
const hash = createHash("md5").update(buf).digest("hex").slice(0, 8);
|
|
220
|
+
const ext = extname(filePath);
|
|
221
|
+
const base = basename(filePath, ext);
|
|
222
|
+
const hashedName = `${base}.${hash}${ext}`;
|
|
223
|
+
const distDir = join(distBase, dirname(relPath));
|
|
224
|
+
const hashedDistPath = join(distDir, hashedName);
|
|
225
|
+
//写入哈希后的.json文件
|
|
226
|
+
yield mkdir(distDir, { recursive: true });
|
|
227
|
+
yield writeFile(hashedDistPath, buf);
|
|
228
|
+
//更新映射表
|
|
229
|
+
map[relPath] = this.normalizePath(join(dirname(relPath), hashedName));
|
|
230
|
+
//重命名关联的.atlas文件(如果有)
|
|
231
|
+
const atlasPath = join(distDir, `${base}.atlas`);
|
|
232
|
+
const newAtlasPath = join(distDir, `${base}.${hash}.atlas`);
|
|
233
|
+
try {
|
|
234
|
+
yield rename(atlasPath, newAtlasPath);
|
|
235
|
+
}
|
|
236
|
+
catch (_a) {
|
|
237
|
+
//如果.atlas文件不存在,则忽略错误
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* 处理目录中的所有文件
|
|
243
|
+
* @param srcBase - 源基础目录
|
|
244
|
+
* @param distBase - 目标基础目录
|
|
245
|
+
* @param {Record<string, string>} map - 文件映射表
|
|
246
|
+
*/
|
|
247
|
+
processFiles(srcBase, distBase, map) {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
const files = yield this.walk(srcBase);
|
|
250
|
+
//分类文件类型
|
|
251
|
+
const atlasFiles = files.filter((f) => f.endsWith(".atlas"));
|
|
252
|
+
const jsonFiles = files.filter((f) => f.endsWith(".json"));
|
|
253
|
+
const fntFiles = files.filter((f) => f.endsWith(".fnt"));
|
|
254
|
+
const otherFiles = files.filter((f) => !f.endsWith(".atlas") && !f.endsWith(".json"));
|
|
255
|
+
//1. 先处理非.atlas/.json文件(包括图片和.fnt文件)
|
|
256
|
+
yield Promise.all(otherFiles.map((file) => this.processFile(file, srcBase, distBase, map)));
|
|
257
|
+
//2. 处理.fnt文件(替换其中引用的图片文件名)
|
|
258
|
+
yield Promise.all(fntFiles.map((f) => this.processFntFile(f, srcBase, distBase, map)));
|
|
259
|
+
//3. 处理.json文件,并记录哈希后的文件名
|
|
260
|
+
const jsonNameMap = {};
|
|
261
|
+
yield Promise.all(jsonFiles.map((file) => __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
const relPath = this.normalizePath(relative(srcBase, file));
|
|
263
|
+
const baseName = relPath.slice(0, -5); //去掉.json后缀
|
|
264
|
+
yield this.processJsonFile(file, srcBase, distBase, map);
|
|
265
|
+
jsonNameMap[baseName] = basename(map[relPath], ".json");
|
|
266
|
+
})));
|
|
267
|
+
//4. 处理.atlas文件,使用关联的.json文件的哈希名称
|
|
268
|
+
yield Promise.all(atlasFiles.map((file) => __awaiter(this, void 0, void 0, function* () {
|
|
269
|
+
const relPath = this.normalizePath(relative(srcBase, file));
|
|
270
|
+
const baseName = relPath.slice(0, -6); //去掉.atlas后缀
|
|
271
|
+
const hashedName = jsonNameMap[baseName];
|
|
272
|
+
yield this.processAtlasFile(file, srcBase, distBase, map, hashedName);
|
|
273
|
+
if (hashedName) {
|
|
274
|
+
const distRelPath = join(dirname(relPath), hashedName);
|
|
275
|
+
map[relPath] = this.normalizePath(distRelPath);
|
|
276
|
+
}
|
|
277
|
+
})));
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* 写入清单文件
|
|
282
|
+
* @param {Record<string, string>} map - 文件映射表
|
|
283
|
+
* @param manifestPath - 清单文件路径
|
|
284
|
+
* @param topLevelDir - 顶层目录名(main/preload)
|
|
285
|
+
*/
|
|
286
|
+
writeManifest(map, manifestPath, topLevelDir) {
|
|
287
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
+
const manifest = Object.entries(map)
|
|
289
|
+
.filter(([original]) => {
|
|
290
|
+
const ext = original.slice(original.lastIndexOf("."));
|
|
291
|
+
//排除spine目录下的.png和.atlas文件
|
|
292
|
+
if (original.startsWith("spine/") && (ext === ".png" || ext === ".atlas"))
|
|
293
|
+
return false;
|
|
294
|
+
//排除.fnt文件引用的图片(通常与.fnt同目录)
|
|
295
|
+
if (ext === ".png") {
|
|
296
|
+
const base = original.slice(0, -ext.length);
|
|
297
|
+
const hasFnt = Object.keys(map).some((k) => k.endsWith(".fnt") && k.startsWith(base));
|
|
298
|
+
if (hasFnt)
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
})
|
|
303
|
+
.map(([original, hashed]) => ({
|
|
304
|
+
//生成资源别名(去掉扩展名)和实际路径
|
|
305
|
+
alias: `${topLevelDir}/${original.replace(/\.[^/.]+$/, "")}`,
|
|
306
|
+
src: [`gameAssetsPack/${topLevelDir}/${hashed}`],
|
|
307
|
+
}));
|
|
308
|
+
yield mkdir(dirname(manifestPath), { recursive: true });
|
|
309
|
+
yield writeFile(manifestPath, JSON.stringify(manifest, null, 2));
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* 构建处理流程
|
|
314
|
+
*/
|
|
315
|
+
build() {
|
|
316
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
+
//清空目标目录
|
|
318
|
+
yield rm(this.distDir, { recursive: true, force: true });
|
|
319
|
+
yield mkdir(this.distDir, { recursive: true });
|
|
320
|
+
//处理main和preload目录(添加哈希)
|
|
321
|
+
yield this.processFiles(join(this.srcDir, "main"), join(this.distDir, "main"), this.mapMain);
|
|
322
|
+
yield this.processFiles(join(this.srcDir, "preload"), join(this.distDir, "preload"), this.mapPreload);
|
|
323
|
+
//复制original目录(不添加哈希)
|
|
324
|
+
yield this.copyOriginal(join(this.srcDir, "original"), join(this.distDir, "original"));
|
|
325
|
+
//写入清单文件
|
|
326
|
+
yield this.writeManifest(this.mapMain, join(this.distDir, this.manifestMain), "main");
|
|
327
|
+
yield this.writeManifest(this.mapPreload, join(this.distDir, this.manifestPreload), "preload");
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Vite插件:Pixi.js缓存清除
|
|
333
|
+
* @param srcDir - 源文件目录
|
|
334
|
+
* @param distDir - 目标输出目录
|
|
335
|
+
* @returns {Plugin} Vite插件实例
|
|
336
|
+
*/
|
|
337
|
+
export const LibPixiViteAssetsHash = (srcDir, distDir) => {
|
|
338
|
+
const instance = new PixiCacheBuster(srcDir, distDir);
|
|
339
|
+
instance.build();
|
|
340
|
+
return {
|
|
341
|
+
name: "vite-assets-hash",
|
|
342
|
+
};
|
|
343
|
+
};
|
package/libPixiJs.d.ts
CHANGED
|
@@ -158,7 +158,7 @@ export declare const Utils: {
|
|
|
158
158
|
* @param interval 间隔毫秒,或随机范围
|
|
159
159
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiIntervalTrigger-间隔触发
|
|
160
160
|
*/
|
|
161
|
-
libPixiIntervalTrigger: (callback: () => void, interval: number | [number, number]) => () => void;
|
|
161
|
+
libPixiIntervalTrigger: (callback: () => void, interval: number | [number, number], immediately?: boolean) => () => void;
|
|
162
162
|
/** @description 点击容器外或入口按钮时隐藏
|
|
163
163
|
* @param container 容器
|
|
164
164
|
* @param btn 按钮
|
package/lyb-pixi.js
CHANGED
|
@@ -1315,7 +1315,7 @@
|
|
|
1315
1315
|
var ys = arrObjKeys(obj, inspect2);
|
|
1316
1316
|
var isPlainObject = gPO ? gPO(obj) === Object.prototype : obj instanceof Object || obj.constructor === Object;
|
|
1317
1317
|
var protoTag = obj instanceof Object ? "" : "null prototype";
|
|
1318
|
-
var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? $slice.call(toStr(obj), 8, -1) : protoTag ? "Object" : "";
|
|
1318
|
+
var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? $slice.call(toStr$1(obj), 8, -1) : protoTag ? "Object" : "";
|
|
1319
1319
|
var constructorTag = isPlainObject || typeof obj.constructor !== "function" ? "" : obj.constructor.name ? obj.constructor.name + " " : "";
|
|
1320
1320
|
var tag2 = constructorTag + (stringTag || protoTag ? "[" + $join.call($concat$1.call([], stringTag || [], protoTag || []), ": ") + "] " : "");
|
|
1321
1321
|
if (ys.length === 0) {
|
|
@@ -1337,25 +1337,25 @@
|
|
|
1337
1337
|
return $replace$1.call(String(s2), /"/g, """);
|
|
1338
1338
|
}
|
|
1339
1339
|
function isArray$3(obj) {
|
|
1340
|
-
return toStr(obj) === "[object Array]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1340
|
+
return toStr$1(obj) === "[object Array]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1341
1341
|
}
|
|
1342
1342
|
function isDate(obj) {
|
|
1343
|
-
return toStr(obj) === "[object Date]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1343
|
+
return toStr$1(obj) === "[object Date]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1344
1344
|
}
|
|
1345
1345
|
function isRegExp$1(obj) {
|
|
1346
|
-
return toStr(obj) === "[object RegExp]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1346
|
+
return toStr$1(obj) === "[object RegExp]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1347
1347
|
}
|
|
1348
1348
|
function isError(obj) {
|
|
1349
|
-
return toStr(obj) === "[object Error]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1349
|
+
return toStr$1(obj) === "[object Error]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1350
1350
|
}
|
|
1351
1351
|
function isString(obj) {
|
|
1352
|
-
return toStr(obj) === "[object String]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1352
|
+
return toStr$1(obj) === "[object String]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1353
1353
|
}
|
|
1354
1354
|
function isNumber(obj) {
|
|
1355
|
-
return toStr(obj) === "[object Number]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1355
|
+
return toStr$1(obj) === "[object Number]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1356
1356
|
}
|
|
1357
1357
|
function isBoolean(obj) {
|
|
1358
|
-
return toStr(obj) === "[object Boolean]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1358
|
+
return toStr$1(obj) === "[object Boolean]" && (!toStringTag || !(typeof obj === "object" && toStringTag in obj));
|
|
1359
1359
|
}
|
|
1360
1360
|
function isSymbol(obj) {
|
|
1361
1361
|
if (hasShammedSymbols) {
|
|
@@ -1391,7 +1391,7 @@
|
|
|
1391
1391
|
function has$3(obj, key) {
|
|
1392
1392
|
return hasOwn$1.call(obj, key);
|
|
1393
1393
|
}
|
|
1394
|
-
function toStr(obj) {
|
|
1394
|
+
function toStr$1(obj) {
|
|
1395
1395
|
return objectToString.call(obj);
|
|
1396
1396
|
}
|
|
1397
1397
|
function nameOf(f2) {
|
|
@@ -1700,7 +1700,7 @@
|
|
|
1700
1700
|
var uri = URIError;
|
|
1701
1701
|
var abs$2 = Math.abs;
|
|
1702
1702
|
var floor$2 = Math.floor;
|
|
1703
|
-
var max$
|
|
1703
|
+
var max$3 = Math.max;
|
|
1704
1704
|
var min$2 = Math.min;
|
|
1705
1705
|
var pow$2 = Math.pow;
|
|
1706
1706
|
var round$3 = Math.round;
|
|
@@ -1833,102 +1833,78 @@
|
|
|
1833
1833
|
Object_getPrototypeOf = $Object2.getPrototypeOf || null;
|
|
1834
1834
|
return Object_getPrototypeOf;
|
|
1835
1835
|
}
|
|
1836
|
-
var
|
|
1837
|
-
var
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
var
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
var
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
var joiny = function(arr, joiner) {
|
|
1864
|
-
var str = "";
|
|
1865
|
-
for (var i2 = 0; i2 < arr.length; i2 += 1) {
|
|
1866
|
-
str += arr[i2];
|
|
1867
|
-
if (i2 + 1 < arr.length) {
|
|
1868
|
-
str += joiner;
|
|
1869
|
-
}
|
|
1836
|
+
var ERROR_MESSAGE = "Function.prototype.bind called on incompatible ";
|
|
1837
|
+
var toStr = Object.prototype.toString;
|
|
1838
|
+
var max$2 = Math.max;
|
|
1839
|
+
var funcType = "[object Function]";
|
|
1840
|
+
var concatty = function concatty2(a2, b2) {
|
|
1841
|
+
var arr = [];
|
|
1842
|
+
for (var i2 = 0; i2 < a2.length; i2 += 1) {
|
|
1843
|
+
arr[i2] = a2[i2];
|
|
1844
|
+
}
|
|
1845
|
+
for (var j2 = 0; j2 < b2.length; j2 += 1) {
|
|
1846
|
+
arr[j2 + a2.length] = b2[j2];
|
|
1847
|
+
}
|
|
1848
|
+
return arr;
|
|
1849
|
+
};
|
|
1850
|
+
var slicy = function slicy2(arrLike, offset) {
|
|
1851
|
+
var arr = [];
|
|
1852
|
+
for (var i2 = offset || 0, j2 = 0; i2 < arrLike.length; i2 += 1, j2 += 1) {
|
|
1853
|
+
arr[j2] = arrLike[i2];
|
|
1854
|
+
}
|
|
1855
|
+
return arr;
|
|
1856
|
+
};
|
|
1857
|
+
var joiny = function(arr, joiner) {
|
|
1858
|
+
var str = "";
|
|
1859
|
+
for (var i2 = 0; i2 < arr.length; i2 += 1) {
|
|
1860
|
+
str += arr[i2];
|
|
1861
|
+
if (i2 + 1 < arr.length) {
|
|
1862
|
+
str += joiner;
|
|
1870
1863
|
}
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
);
|
|
1886
|
-
if (Object(result) === result) {
|
|
1887
|
-
return result;
|
|
1888
|
-
}
|
|
1889
|
-
return this;
|
|
1890
|
-
}
|
|
1891
|
-
return target.apply(
|
|
1892
|
-
that,
|
|
1864
|
+
}
|
|
1865
|
+
return str;
|
|
1866
|
+
};
|
|
1867
|
+
var implementation$1 = function bind2(that) {
|
|
1868
|
+
var target = this;
|
|
1869
|
+
if (typeof target !== "function" || toStr.apply(target) !== funcType) {
|
|
1870
|
+
throw new TypeError(ERROR_MESSAGE + target);
|
|
1871
|
+
}
|
|
1872
|
+
var args = slicy(arguments, 1);
|
|
1873
|
+
var bound;
|
|
1874
|
+
var binder = function() {
|
|
1875
|
+
if (this instanceof bound) {
|
|
1876
|
+
var result = target.apply(
|
|
1877
|
+
this,
|
|
1893
1878
|
concatty(args, arguments)
|
|
1894
1879
|
);
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
boundArgs[i2] = "$" + i2;
|
|
1900
|
-
}
|
|
1901
|
-
bound = Function("binder", "return function (" + joiny(boundArgs, ",") + "){ return binder.apply(this,arguments); }")(binder);
|
|
1902
|
-
if (target.prototype) {
|
|
1903
|
-
var Empty = function Empty2() {
|
|
1904
|
-
};
|
|
1905
|
-
Empty.prototype = target.prototype;
|
|
1906
|
-
bound.prototype = new Empty();
|
|
1907
|
-
Empty.prototype = null;
|
|
1880
|
+
if (Object(result) === result) {
|
|
1881
|
+
return result;
|
|
1882
|
+
}
|
|
1883
|
+
return this;
|
|
1908
1884
|
}
|
|
1909
|
-
return
|
|
1885
|
+
return target.apply(
|
|
1886
|
+
that,
|
|
1887
|
+
concatty(args, arguments)
|
|
1888
|
+
);
|
|
1910
1889
|
};
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
functionCall = Function.prototype.call;
|
|
1930
|
-
return functionCall;
|
|
1931
|
-
}
|
|
1890
|
+
var boundLength = max$2(0, target.length - args.length);
|
|
1891
|
+
var boundArgs = [];
|
|
1892
|
+
for (var i2 = 0; i2 < boundLength; i2++) {
|
|
1893
|
+
boundArgs[i2] = "$" + i2;
|
|
1894
|
+
}
|
|
1895
|
+
bound = Function("binder", "return function (" + joiny(boundArgs, ",") + "){ return binder.apply(this,arguments); }")(binder);
|
|
1896
|
+
if (target.prototype) {
|
|
1897
|
+
var Empty = function Empty2() {
|
|
1898
|
+
};
|
|
1899
|
+
Empty.prototype = target.prototype;
|
|
1900
|
+
bound.prototype = new Empty();
|
|
1901
|
+
Empty.prototype = null;
|
|
1902
|
+
}
|
|
1903
|
+
return bound;
|
|
1904
|
+
};
|
|
1905
|
+
var implementation = implementation$1;
|
|
1906
|
+
var functionBind = Function.prototype.bind || implementation;
|
|
1907
|
+
var functionCall = Function.prototype.call;
|
|
1932
1908
|
var functionApply;
|
|
1933
1909
|
var hasRequiredFunctionApply;
|
|
1934
1910
|
function requireFunctionApply() {
|
|
@@ -1939,14 +1915,14 @@
|
|
|
1939
1915
|
return functionApply;
|
|
1940
1916
|
}
|
|
1941
1917
|
var reflectApply = typeof Reflect !== "undefined" && Reflect && Reflect.apply;
|
|
1942
|
-
var bind$2 =
|
|
1918
|
+
var bind$2 = functionBind;
|
|
1943
1919
|
var $apply$1 = requireFunctionApply();
|
|
1944
|
-
var $call$2 =
|
|
1920
|
+
var $call$2 = functionCall;
|
|
1945
1921
|
var $reflectApply = reflectApply;
|
|
1946
1922
|
var actualApply = $reflectApply || bind$2.call($call$2, $apply$1);
|
|
1947
|
-
var bind$1 =
|
|
1923
|
+
var bind$1 = functionBind;
|
|
1948
1924
|
var $TypeError$4 = type;
|
|
1949
|
-
var $call$1 =
|
|
1925
|
+
var $call$1 = functionCall;
|
|
1950
1926
|
var $actualApply = actualApply;
|
|
1951
1927
|
var callBindApplyHelpers = function callBindBasic2(args) {
|
|
1952
1928
|
if (args.length < 1 || typeof args[0] !== "function") {
|
|
@@ -2015,7 +1991,7 @@
|
|
|
2015
1991
|
hasRequiredHasown = 1;
|
|
2016
1992
|
var call = Function.prototype.call;
|
|
2017
1993
|
var $hasOwn = Object.prototype.hasOwnProperty;
|
|
2018
|
-
var bind2 =
|
|
1994
|
+
var bind2 = functionBind;
|
|
2019
1995
|
hasown = bind2.call(call, $hasOwn);
|
|
2020
1996
|
return hasown;
|
|
2021
1997
|
}
|
|
@@ -2030,7 +2006,7 @@
|
|
|
2030
2006
|
var $URIError = uri;
|
|
2031
2007
|
var abs$1 = abs$2;
|
|
2032
2008
|
var floor$1 = floor$2;
|
|
2033
|
-
var max$1 = max$
|
|
2009
|
+
var max$1 = max$3;
|
|
2034
2010
|
var min$1 = min$2;
|
|
2035
2011
|
var pow$1 = pow$2;
|
|
2036
2012
|
var round$2 = round$3;
|
|
@@ -2064,7 +2040,7 @@
|
|
|
2064
2040
|
var $ObjectGPO = requireObject_getPrototypeOf();
|
|
2065
2041
|
var $ReflectGPO = requireReflect_getPrototypeOf();
|
|
2066
2042
|
var $apply = requireFunctionApply();
|
|
2067
|
-
var $call =
|
|
2043
|
+
var $call = functionCall;
|
|
2068
2044
|
var needsEval = {};
|
|
2069
2045
|
var TypedArray = typeof Uint8Array === "undefined" || !getProto ? undefined$1 : getProto(Uint8Array);
|
|
2070
2046
|
var INTRINSICS = {
|
|
@@ -2234,7 +2210,7 @@
|
|
|
2234
2210
|
"%WeakMapPrototype%": ["WeakMap", "prototype"],
|
|
2235
2211
|
"%WeakSetPrototype%": ["WeakSet", "prototype"]
|
|
2236
2212
|
};
|
|
2237
|
-
var bind =
|
|
2213
|
+
var bind = functionBind;
|
|
2238
2214
|
var hasOwn = requireHasown();
|
|
2239
2215
|
var $concat = bind.call($call, Array.prototype.concat);
|
|
2240
2216
|
var $spliceApply = bind.call($apply, Array.prototype.splice);
|
|
@@ -48801,13 +48777,19 @@ void main(void)\r
|
|
|
48801
48777
|
const { once = false, debounce = false, debounceTime = 1e3, preventDragClick = false } = params;
|
|
48802
48778
|
v2.cursor = "pointer";
|
|
48803
48779
|
v2.eventMode = "static";
|
|
48780
|
+
let lastX = 0;
|
|
48781
|
+
let lastY = 0;
|
|
48804
48782
|
let isDragging = false;
|
|
48805
48783
|
if (preventDragClick) {
|
|
48806
|
-
v2.on("pointerdown", () => {
|
|
48784
|
+
v2.on("pointerdown", (e2) => {
|
|
48807
48785
|
isDragging = false;
|
|
48786
|
+
lastX = e2.globalX;
|
|
48787
|
+
lastY = e2.globalY;
|
|
48808
48788
|
});
|
|
48809
|
-
v2.on("pointermove", () => {
|
|
48810
|
-
|
|
48789
|
+
v2.on("pointermove", (e2) => {
|
|
48790
|
+
if (e2.globalX !== lastX || e2.globalY !== lastY) {
|
|
48791
|
+
isDragging = true;
|
|
48792
|
+
}
|
|
48811
48793
|
});
|
|
48812
48794
|
}
|
|
48813
48795
|
const fn = (e2) => {
|
|
@@ -54480,7 +54462,7 @@ void main(void)\r
|
|
|
54480
54462
|
const libJsRandom = (min2, max2, num = 0) => {
|
|
54481
54463
|
return parseFloat((Math.random() * (max2 - min2) + min2).toFixed(num));
|
|
54482
54464
|
};
|
|
54483
|
-
const libPixiIntervalTrigger = (callback, interval) => {
|
|
54465
|
+
const libPixiIntervalTrigger = (callback, interval, immediately = true) => {
|
|
54484
54466
|
let elapsedTime = 0;
|
|
54485
54467
|
const ticker2 = new Ticker();
|
|
54486
54468
|
const tickerCallback = (deltaTime) => {
|
|
@@ -54496,6 +54478,7 @@ void main(void)\r
|
|
|
54496
54478
|
elapsedTime = 0;
|
|
54497
54479
|
}
|
|
54498
54480
|
};
|
|
54481
|
+
immediately && callback();
|
|
54499
54482
|
ticker2.add(tickerCallback);
|
|
54500
54483
|
ticker2.start();
|
|
54501
54484
|
return () => {
|