lyb-pixi-js 1.0.0

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.
@@ -0,0 +1,151 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { Ticker } from "pixi.js";
17
+ import { Spine } from "@pixi-spine/runtime-3.8";
18
+ import gsap from "gsap";
19
+ /** @description 自定义 Spine 动画 */
20
+ var LibSpine = /** @class */ (function (_super) {
21
+ __extends(LibSpine, _super);
22
+ function LibSpine(texture, params) {
23
+ var _this = this;
24
+ var _a = params || {}, followPointList = _a.followPointList, _b = _a.visible, visible = _b === void 0 ? false : _b;
25
+ _this = _super.call(this, texture.spineData) || this;
26
+ /** 挂点 */
27
+ _this._followDots = [];
28
+ /** 是否已开始 */
29
+ _this._isStart = false;
30
+ _this.visible = visible;
31
+ _this.autoUpdate = false;
32
+ //如果存在挂点
33
+ if (followPointList === null || followPointList === void 0 ? void 0 : followPointList.length) {
34
+ followPointList === null || followPointList === void 0 ? void 0 : followPointList.forEach(function (item) {
35
+ item.follow.alpha = 0;
36
+ _this._followDots.push({
37
+ point: _this.skeleton.findBone(item.boneName),
38
+ follow: item.follow,
39
+ onUpdate: item.onUpdate,
40
+ angleFollow: item.angleFollow || false,
41
+ scaleFollow: item.scaleFollow || true,
42
+ });
43
+ });
44
+ }
45
+ _this._loopFn = _this._loop.bind(_this);
46
+ Ticker.system.add(_this._loopFn);
47
+ return _this;
48
+ }
49
+ /** @description 设置动画
50
+ * @param animationName 动画名称
51
+ * @param loop 是否循环播放
52
+ * @param delay 是否延迟播放
53
+ */
54
+ LibSpine.prototype.setAnimation = function (animationName, loop, delay) {
55
+ var _this = this;
56
+ if (animationName === void 0) { animationName = "Animation"; }
57
+ if (loop === void 0) { loop = false; }
58
+ if (delay === void 0) { delay = true; }
59
+ return new Promise(function (resolve) {
60
+ _this.visible = true;
61
+ _this.state.setAnimation(0, animationName, loop).listener = {
62
+ complete: function () {
63
+ if (delay) {
64
+ requestAnimationFrame(function () {
65
+ resolve();
66
+ });
67
+ }
68
+ else {
69
+ resolve();
70
+ }
71
+ },
72
+ };
73
+ });
74
+ };
75
+ /** @description 添加动画
76
+ * @param animationName 动画名称
77
+ * @param loop 是否循环播放
78
+ * @param delay 延迟播放时间
79
+ */
80
+ LibSpine.prototype.addAnimation = function (animationName, loop, delay) {
81
+ var _this = this;
82
+ if (animationName === void 0) { animationName = "Animation"; }
83
+ if (loop === void 0) { loop = false; }
84
+ if (delay === void 0) { delay = 0; }
85
+ return new Promise(function (resolve) {
86
+ _this.state.addAnimation(0, animationName, loop, delay).listener = {
87
+ complete: function () {
88
+ requestAnimationFrame(function () {
89
+ resolve();
90
+ });
91
+ },
92
+ };
93
+ });
94
+ };
95
+ /** @description 改变骨骼数据 */
96
+ LibSpine.prototype.setSkin = function (skinName) {
97
+ this.skeleton.setSkinByName(skinName);
98
+ };
99
+ /** @description 销毁动画及挂点 */
100
+ LibSpine.prototype.destroyAll = function () {
101
+ Ticker.system.remove(this._loopFn);
102
+ this.destroy();
103
+ this.removeFromParent();
104
+ };
105
+ /** @description 更新渲染 */
106
+ LibSpine.prototype._loop = function () {
107
+ this.update(Ticker.system.deltaMS / 1000);
108
+ this._updateFollowPoint();
109
+ };
110
+ /** @description 更新挂点 */
111
+ LibSpine.prototype._updateFollowPoint = function () {
112
+ if (this._followDots.length === 0)
113
+ return;
114
+ this._followDots.forEach(function (item) {
115
+ var _a = item.point, x = _a.worldX, y = _a.worldY;
116
+ var rotate = item.point.getWorldRotationX() * (Math.PI / 180);
117
+ var scaleX = item.point.getWorldScaleX();
118
+ var scaleY = item.point.getWorldScaleY();
119
+ if (item.onUpdate) {
120
+ item.onUpdate({
121
+ x: x,
122
+ y: y,
123
+ rotate: rotate,
124
+ scaleX: scaleX,
125
+ scaleY: scaleY,
126
+ });
127
+ }
128
+ else {
129
+ if (item.angleFollow) {
130
+ item.follow.rotation = rotate;
131
+ }
132
+ if (item.scaleFollow) {
133
+ item.follow.scale.set(scaleX, scaleY);
134
+ }
135
+ item.follow.position.set(x + 1920 / 2 - item.follow.width / 2, y + 1080 / 2 - item.follow.height / 2);
136
+ }
137
+ });
138
+ if (!this._isStart) {
139
+ this._isStart = true;
140
+ this._followDots.forEach(function (item) {
141
+ gsap.to(item.follow, {
142
+ alpha: 1,
143
+ duration: 0.25,
144
+ delay: 0.15,
145
+ });
146
+ });
147
+ }
148
+ };
149
+ return LibSpine;
150
+ }(Spine));
151
+ export { LibSpine };
@@ -0,0 +1,35 @@
1
+ import { Text, type TextStyleAlign, type TextStyleFontWeight } from "pixi.js";
2
+ export interface LibTextParams {
3
+ /** 文本内容 */
4
+ text: string | number;
5
+ /** 字体大小 */
6
+ fontSize?: number;
7
+ /** 字体颜色 */
8
+ fontColor?: any;
9
+ /** 是否描边 */
10
+ stroke?: boolean;
11
+ /** 描边颜色 */
12
+ strokeColor?: string | number;
13
+ /** 描边宽度 */
14
+ strokeThickness?: number;
15
+ /** 字体样式 */
16
+ fontFamily?: string;
17
+ /** 字体粗细 */
18
+ fontWeight?: TextStyleFontWeight;
19
+ /** 是否换行 */
20
+ wordWrap?: boolean;
21
+ /** 换行宽度 */
22
+ wordWrapWidth?: number;
23
+ /** 行高 */
24
+ lineHeight?: number;
25
+ /** 对齐方式 */
26
+ align?: TextStyleAlign;
27
+ /** 缩进,单位为字数 */
28
+ indent?: number;
29
+ /** 阴影-颜色 角度 模糊度 阴影距离 */
30
+ shadow?: [string, number, number, number];
31
+ }
32
+ /** @description 自定义文本类 */
33
+ export declare class LibText extends Text {
34
+ constructor(options: LibTextParams);
35
+ }
@@ -0,0 +1,50 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { Text, TextStyle } from "pixi.js";
17
+ /** @description 自定义文本类 */
18
+ var LibText = /** @class */ (function (_super) {
19
+ __extends(LibText, _super);
20
+ function LibText(options) {
21
+ var _this = this;
22
+ var text = options.text, _a = options.fontSize, fontSize = _a === void 0 ? 36 : _a, _b = options.fontColor, fontColor = _b === void 0 ? 0xffffff : _b, stroke = options.stroke, strokeColor = options.strokeColor, strokeThickness = options.strokeThickness, _c = options.fontFamily, fontFamily = _c === void 0 ? "MicrosoftYaHei" : _c, _d = options.fontWeight, fontWeight = _d === void 0 ? "normal" : _d, _e = options.wordWrap, wordWrap = _e === void 0 ? false : _e, _f = options.wordWrapWidth, wordWrapWidth = _f === void 0 ? 100 : _f, _g = options.lineHeight, lineHeight = _g === void 0 ? 1.25 : _g, _h = options.align, align = _h === void 0 ? "left" : _h, _j = options.indent, indent = _j === void 0 ? 0 : _j, shadow = options.shadow;
23
+ var style = new TextStyle({
24
+ fontSize: fontSize,
25
+ wordWrap: wordWrap,
26
+ wordWrapWidth: wordWrapWidth,
27
+ fontWeight: fontWeight,
28
+ lineHeight: lineHeight * fontSize,
29
+ breakWords: wordWrap,
30
+ fill: fontColor,
31
+ align: align,
32
+ fontFamily: fontFamily,
33
+ stroke: stroke ? strokeColor : "transparent",
34
+ strokeThickness: stroke ? strokeThickness : 0,
35
+ lineJoin: "round",
36
+ });
37
+ if (shadow) {
38
+ style.dropShadow = true;
39
+ style.dropShadowColor = shadow[0];
40
+ style.dropShadowAngle = shadow[1] * (Math.PI / 180);
41
+ style.dropShadowBlur = shadow[2];
42
+ style.dropShadowDistance = shadow[3];
43
+ }
44
+ _this = _super.call(this, text, style) || this;
45
+ _this.position.x = indent * fontSize;
46
+ return _this;
47
+ }
48
+ return LibText;
49
+ }(Text));
50
+ export { LibText };
@@ -0,0 +1 @@
1
+ export * as LibPixiJs from "./libPixiJs";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * as LibPixiJs from "./libPixiJs";
@@ -0,0 +1,21 @@
1
+ import { LibBitText } from "./Base/LibBitText";
2
+ import { LibContainer } from "./Base/LibContainer";
3
+ import { LibParticleMove } from "./Base/LibParticleMove";
4
+ import { LibRectBgColor } from "./Base/LibRectBgColor";
5
+ import { LibSpine } from "./Base/LibSpine";
6
+ import { LibText } from "./Base/LibText";
7
+ /** @description 基础方法 */
8
+ export declare const Base: {
9
+ /** @description 自定义位图文本 */
10
+ LibBitText: typeof LibBitText;
11
+ /** @description 自定义容器大小及背景色 */
12
+ LibContainer: typeof LibContainer;
13
+ /** @description 粒子移动 */
14
+ LibParticleMove: typeof LibParticleMove;
15
+ /** @description 自定义矩形背景色 */
16
+ LibRectBgColor: typeof LibRectBgColor;
17
+ /** @description 自定义 Spine 动画 */
18
+ LibSpine: typeof LibSpine;
19
+ /** @description 自定义普通文本类 */
20
+ LibText: typeof LibText;
21
+ };
@@ -0,0 +1,21 @@
1
+ import { LibBitText } from "./Base/LibBitText";
2
+ import { LibContainer } from "./Base/LibContainer";
3
+ import { LibParticleMove } from "./Base/LibParticleMove";
4
+ import { LibRectBgColor } from "./Base/LibRectBgColor";
5
+ import { LibSpine } from "./Base/LibSpine";
6
+ import { LibText } from "./Base/LibText";
7
+ /** @description 基础方法 */
8
+ export var Base = {
9
+ /** @description 自定义位图文本 */
10
+ LibBitText: LibBitText,
11
+ /** @description 自定义容器大小及背景色 */
12
+ LibContainer: LibContainer,
13
+ /** @description 粒子移动 */
14
+ LibParticleMove: LibParticleMove,
15
+ /** @description 自定义矩形背景色 */
16
+ LibRectBgColor: LibRectBgColor,
17
+ /** @description 自定义 Spine 动画 */
18
+ LibSpine: LibSpine,
19
+ /** @description 自定义普通文本类 */
20
+ LibText: LibText,
21
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "lyb-pixi-js",
3
+ "version": "1.0.0",
4
+ "description": "自用Pixi.JS方法库",
5
+ "license": "ISC",
6
+ "type": "module",
7
+ "types": "./dist/index.d.ts",
8
+ "main": "./dist/index.js",
9
+ "scripts": {
10
+ "build": "tsc & vite build"
11
+ },
12
+ "exports": {
13
+ "./*": "./dist/*"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "package.json",
19
+ "umd"
20
+ ],
21
+ "author": {
22
+ "name": "冷弋白",
23
+ "email": "1329670984@qq.com"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/lengyibai/lyb-pixi-js.git"
28
+ },
29
+ "keywords": [
30
+ "冷弋白",
31
+ "lengyibai",
32
+ "lyb",
33
+ "lyb-pixi-js"
34
+ ],
35
+ "devDependencies": {
36
+ "@types/node": "^22.10.5",
37
+ "typescript": "^5.7.2"
38
+ },
39
+ "dependencies": {
40
+ "@pixi-spine/runtime-3.8": "^4.0.3",
41
+ "@pixi/particle-emitter": "^5.0.8",
42
+ "dayjs": "^1.11.13",
43
+ "decimal.js": "^10.4.3",
44
+ "gsap": "^3.12.5",
45
+ "pixi.js": "^7.4.2",
46
+ "vite": "^4.5.5"
47
+ }
48
+ }