lyb-pixi-js 1.1.10 → 1.1.11

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.
Files changed (63) hide show
  1. package/README.md +72 -40
  2. package/package.json +1 -1
  3. package/Components/Base/LibPixiBitText.d.ts +0 -20
  4. package/Components/Base/LibPixiBitText.js +0 -26
  5. package/Components/Base/LibPixiContainer.d.ts +0 -22
  6. package/Components/Base/LibPixiContainer.js +0 -51
  7. package/Components/Base/LibPixiParticleMove.d.ts +0 -39
  8. package/Components/Base/LibPixiParticleMove.js +0 -100
  9. package/Components/Base/LibPixiRectBgColor.d.ts +0 -45
  10. package/Components/Base/LibPixiRectBgColor.js +0 -98
  11. package/Components/Base/LibPixiSpine.d.ts +0 -57
  12. package/Components/Base/LibPixiSpine.js +0 -122
  13. package/Components/Base/LibPixiText.d.ts +0 -37
  14. package/Components/Base/LibPixiText.js +0 -32
  15. package/Components/Custom/LibPixiButtonHover.d.ts +0 -32
  16. package/Components/Custom/LibPixiButtonHover.js +0 -44
  17. package/Components/Custom/LibPixiCloseBtn.d.ts +0 -14
  18. package/Components/Custom/LibPixiCloseBtn.js +0 -35
  19. package/Components/Custom/LibPixiDrawer.d.ts +0 -16
  20. package/Components/Custom/LibPixiDrawer.js +0 -59
  21. package/Components/Custom/LibPixiPerforMon.d.ts +0 -31
  22. package/Components/Custom/LibPixiPerforMon.js +0 -107
  23. package/Components/Custom/LibPixiProgress.d.ts +0 -29
  24. package/Components/Custom/LibPixiProgress.js +0 -36
  25. package/Components/Custom/LibPixiScrollContainer.d.ts +0 -57
  26. package/Components/Custom/LibPixiScrollContainer.js +0 -166
  27. package/Components/Custom/LibPixiScrollNum.d.ts +0 -62
  28. package/Components/Custom/LibPixiScrollNum.js +0 -146
  29. package/Components/Custom/LibPixiSlider.d.ts +0 -45
  30. package/Components/Custom/LibPixiSlider.js +0 -111
  31. package/Components/Custom/LibPixiSubAddMinMax.d.ts +0 -49
  32. package/Components/Custom/LibPixiSubAddMinMax.js +0 -76
  33. package/Components/Custom/LibPixiTable.d.ts +0 -52
  34. package/Components/Custom/LibPixiTable.js +0 -70
  35. package/Utils/LibPixiAudio.d.ts +0 -34
  36. package/Utils/LibPixiAudio.js +0 -140
  37. package/Utils/LibPixiCreateNineGrid.d.ts +0 -15
  38. package/Utils/LibPixiCreateNineGrid.js +0 -19
  39. package/Utils/LibPixiEvent.d.ts +0 -9
  40. package/Utils/LibPixiEvent.js +0 -22
  41. package/Utils/LibPixiEventControlled.d.ts +0 -8
  42. package/Utils/LibPixiEventControlled.js +0 -21
  43. package/Utils/LibPixiFilter.d.ts +0 -9
  44. package/Utils/LibPixiFilter.js +0 -30
  45. package/Utils/LibPixiIntervalTrigger.d.ts +0 -6
  46. package/Utils/LibPixiIntervalTrigger.js +0 -33
  47. package/Utils/LibPixiOutsideClick.d.ts +0 -8
  48. package/Utils/LibPixiOutsideClick.js +0 -22
  49. package/Utils/LibPixiOverflowHidden.d.ts +0 -6
  50. package/Utils/LibPixiOverflowHidden.js +0 -14
  51. package/Utils/LibPixiPromiseTickerTimeout.d.ts +0 -6
  52. package/Utils/LibPixiPromiseTickerTimeout.js +0 -22
  53. package/Utils/LibPixiScaleContainer.d.ts +0 -8
  54. package/Utils/LibPixiScaleContainer.js +0 -14
  55. package/Utils/LibPixiShadow.d.ts +0 -17
  56. package/Utils/LibPixiShadow.js +0 -18
  57. package/Utils/LibPixiTickerTimeout.d.ts +0 -6
  58. package/Utils/LibPixiTickerTimeout.js +0 -28
  59. package/index.d.ts +0 -1
  60. package/index.js +0 -2
  61. package/libPixiJs.d.ts +0 -163
  62. package/libPixiJs.js +0 -174
  63. package/lyb-pixi.js +0 -1263
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Lib自用PixiJS组件&工具方法
1
+ # Lib 自用 PixiJS 组件&工具方法
2
2
 
3
3
  ## 介绍
4
4
 
@@ -18,7 +18,7 @@ import { LibPixiJs } from "lyb-pixi-js";
18
18
  const text = new LibPixiJs.Base.LibPixiText({
19
19
  text: "Hello World!",
20
20
  fontSize: 50,
21
- fontColor:"red",
21
+ fontColor: "red",
22
22
  });
23
23
  app.stage.addChild(text);
24
24
  ```
@@ -44,12 +44,12 @@ export * from "lyb-pixi-js/Base/LibPixiText";
44
44
  export * from "lyb-pixi-js/Base/LibPixiRectBgColor";
45
45
 
46
46
  //你的项目文件 index.ts
47
- import { LibText,LibRectBgColor } from "utils";
47
+ import { LibText, LibRectBgColor } from "utils";
48
48
 
49
49
  const text = new LibPixiText({
50
50
  text: "Hello World!",
51
51
  fontSize: 50,
52
- fontColor:"red",
52
+ fontColor: "red",
53
53
  });
54
54
  app.stage.addChild(text);
55
55
 
@@ -69,18 +69,18 @@ app.stage.addChild(box);
69
69
  <script src="https://unpkg.com/lyb-pixi-js/lyb-pixi.js"></script>
70
70
 
71
71
  <script>
72
- const text = new LibPixiJs.Base.LibPixiText({
73
- text: "Hello World!",
74
- fontSize: 50,
75
- fontColor:"red",
76
- });
77
- app.stage.addChild(text);
72
+ const text = new LibPixiJs.Base.LibPixiText({
73
+ text: "Hello World!",
74
+ fontSize: 50,
75
+ fontColor: "red",
76
+ });
77
+ app.stage.addChild(text);
78
78
  </script>
79
79
  ```
80
80
 
81
81
  ## 目录
82
82
 
83
- ### 基础
83
+ ### 组件
84
84
 
85
85
  \- [LibPixiText-文本](#LibPixiText-文本)
86
86
 
@@ -114,6 +114,31 @@ app.stage.addChild(text);
114
114
 
115
115
  \- [LibPixiTable-数字表格](#LibPixiTable-数字表格)
116
116
 
117
+ ### 方法
118
+
119
+ \- [LibPixiAudio-音频播放器](#LibPixiAudio-音频播放器)
120
+
121
+ \- [LibPixiCreateNineGrid-九宫格图](#LibPixiCreateNineGrid-九宫格图)
122
+
123
+ \- [LibPixiEvent-事件注册](#LibPixiEvent-事件注册)
124
+
125
+ \- [LibPixiEventControlled-可关闭的事件](#LibPixiEventControlled-可关闭的事件)
126
+
127
+ \- [LibPixiFilter-滤镜](#LibPixiFilter-滤镜)
128
+
129
+ \- [LibPixiIntervalTrigger-间隔触发](#LibPixiIntervalTrigger-间隔触发)
130
+
131
+ \- [LibPixiOutsideClick-失焦隐藏](#LibPixiOutsideClick-失焦隐藏)
132
+
133
+ \- [LibPixiOverflowHidden-溢出裁剪](#LibPixiOverflowHidden-溢出裁剪)
134
+
135
+ \- [LibPixiPromiseTickerTimeout-TickerPromise 定时器](#LibPixiPromiseTickerTimeout-TickerPromise定时器)
136
+
137
+ \- [LibPixiScaleContainer-超出缩放](#LibPixiScaleContainer-超出缩放)
138
+
139
+ \- [LibPixiShadow-阴影](#LibPixiShadow-阴影)
140
+
141
+ \- [LibPixiTickerTimeout-Ticker 定时器](#LibPixiTickerTimeout-Ticker定时器)
117
142
 
118
143
  ## Base-基础
119
144
 
@@ -125,7 +150,7 @@ app.stage.addChild(text);
125
150
  const text = new LibPixiJs.Base.LibPixiText({
126
151
  text: "Hello World!",
127
152
  fontSize: 50,
128
- fontColor:"red",
153
+ fontColor: "red",
129
154
  });
130
155
  this.addChild(text);
131
156
  ```
@@ -194,7 +219,7 @@ this.bgSpine = new LibPixiSpine("spine_buyfree", {
194
219
  onUpdate: ({ x, y, rotate, scaleX, scaleY }) => {
195
220
  followContainer2.position.set(
196
221
  x + 1920 / 2 - followContainer2.width / 2,
197
- y + 1080 / 2 - followContainer2.height / 2,
222
+ y + 1080 / 2 - followContainer2.height / 2
198
223
  );
199
224
  followContainer2.rotation = rotate;
200
225
  followContainer2.scale.set(scaleX, scaleY);
@@ -219,7 +244,7 @@ const libPixiParticleMove = new LibPixiJs.Base.LibPixiParticleMove({
219
244
  json: PIXI.Assets.get("fly.json"),
220
245
  duration: 1,
221
246
  showControl: true,
222
- ease:"power1.in",
247
+ ease: "power1.in",
223
248
  loop: true,
224
249
  });
225
250
  ```
@@ -252,7 +277,10 @@ button.setDisabled(true); //禁用按钮
252
277
  app.stage.addChild(button);
253
278
 
254
279
  //切换按钮材质
255
- button.toggleTexture(Texture.from("new-default.png"), Texture.from("new-hover.png"));
280
+ button.toggleTexture(
281
+ Texture.from("new-default.png"),
282
+ Texture.from("new-hover.png")
283
+ );
256
284
  ```
257
285
 
258
286
  ### LibPixiCloseBtn-关闭按钮
@@ -525,13 +553,12 @@ stage.addChild(table);
525
553
  const audioPlayer = new LibPixiAudio();
526
554
 
527
555
  // 播放音效
528
- audioPlayer.playEffect('effect-link')
529
- .then(() => {
530
- console.log('音效播放完成');
531
- });
556
+ audioPlayer.playEffect("effect-link").then(() => {
557
+ console.log("音效播放完成");
558
+ });
532
559
 
533
560
  // 播放音乐
534
- audioPlayer.playMusic('music-link');
561
+ audioPlayer.playMusic("music-link");
535
562
 
536
563
  // 暂停音乐
537
564
  audioPlayer.pauseMusic();
@@ -540,7 +567,7 @@ audioPlayer.pauseMusic();
540
567
  audioPlayer.resumeMusic();
541
568
 
542
569
  // 停止指定音效
543
- audioPlayer.stopEffect('effect-link');
570
+ audioPlayer.stopEffect("effect-link");
544
571
 
545
572
  // 设置启用音效
546
573
  audioPlayer.setEffectEnabled(false);
@@ -567,14 +594,19 @@ const nineGrid = libPixiCreateNineGrid({
567
594
  > 事件注册
568
595
 
569
596
  ```ts
570
- libPixiEvent(container, 'pointerdown', (e) => {
571
- console.log('Pointer down event triggered', e);
597
+ libPixiEvent(container, "pointerdown", (e) => {
598
+ console.log("Pointer down event triggered", e);
572
599
  });
573
600
 
574
601
  // 只执行一次的事件
575
- libPixiEvent(container, 'pointerup', (e) => {
576
- console.log('Pointer up event triggered', e);
577
- }, true);
602
+ libPixiEvent(
603
+ container,
604
+ "pointerup",
605
+ (e) => {
606
+ console.log("Pointer up event triggered", e);
607
+ },
608
+ true
609
+ );
578
610
  ```
579
611
 
580
612
  ### LibPixiEventControlled-可关闭的事件
@@ -582,8 +614,8 @@ libPixiEvent(container, 'pointerup', (e) => {
582
614
  > 设置可关闭的事件监听,调用自身后不再触发
583
615
 
584
616
  ```ts
585
- const closeEvent = libPixiEventControlled(container, 'pointerdown', (e) => {
586
- console.log('Pointer down event triggered', e);
617
+ const closeEvent = libPixiEventControlled(container, "pointerdown", (e) => {
618
+ console.log("Pointer down event triggered", e);
587
619
  });
588
620
 
589
621
  // 调用返回的函数关闭事件监听
@@ -595,10 +627,10 @@ closeEvent();
595
627
  > 滤镜
596
628
 
597
629
  ```ts
598
- const brightnessFilter = libPixiFilter('brightness', 1.2); // 设置亮度为1.2
599
- const blurFilter = libPixiFilter('blur'); // 设置模糊滤镜
600
- const desaturateFilter = libPixiFilter('desaturate'); // 设置去饱和滤镜
601
- const contrastFilter = libPixiFilter('contrast', 1.5); // 设置对比度为1.5
630
+ const brightnessFilter = libPixiFilter("brightness", 1.2); // 设置亮度为1.2
631
+ const blurFilter = libPixiFilter("blur"); // 设置模糊滤镜
632
+ const desaturateFilter = libPixiFilter("desaturate"); // 设置去饱和滤镜
633
+ const contrastFilter = libPixiFilter("contrast", 1.5); // 设置对比度为1.5
602
634
  ```
603
635
 
604
636
  ### LibPixiIntervalTrigger-间隔触发
@@ -607,13 +639,13 @@ const contrastFilter = libPixiFilter('contrast', 1.5); // 设置对比度为1.5
607
639
 
608
640
  ```ts
609
641
  const stopInterval = libPixiIntervalTrigger(() => {
610
- console.log('Triggered interval callback');
642
+ console.log("Triggered interval callback");
611
643
  }, [500, 1000]); // 随机间隔 500ms 到 1000ms
612
644
 
613
645
  //or
614
646
 
615
647
  const stopInterval = libPixiIntervalTrigger(() => {
616
- console.log('Triggered interval callback');
648
+ console.log("Triggered interval callback");
617
649
  }, 500); // 间隔 500ms
618
650
 
619
651
  // 停止间隔触发
@@ -626,7 +658,7 @@ stopInterval();
626
658
 
627
659
  ```ts
628
660
  const stopOutsideClick = libPixiOutsideClick(container, button, () => {
629
- console.log('Container closed');
661
+ console.log("Container closed");
630
662
  });
631
663
 
632
664
  // 停止监听点击事件
@@ -641,15 +673,15 @@ stopOutsideClick();
641
673
  const mask = libPixiOverflowHidden(container); // 为容器创建并应用矩形蒙版
642
674
  ```
643
675
 
644
- ### LibPixiPromiseTickerTimeout-TickerPromise定时器
676
+ ### LibPixiPromiseTickerTimeout-TickerPromise 定时器
645
677
 
646
678
  > 基于 Ticker 和 Promise 的定时器
647
679
 
648
680
  ```ts
649
681
  libPixiPromiseTickerTimeout(1000, () => {
650
- console.log('Callback after 1000ms');
682
+ console.log("Callback after 1000ms");
651
683
  }).then(() => {
652
- console.log('Timer completed');
684
+ console.log("Timer completed");
653
685
  });
654
686
  ```
655
687
 
@@ -675,13 +707,13 @@ libPixiShadow(container, {
675
707
  });
676
708
  ```
677
709
 
678
- ### LibPixiTickerTimeout-Ticker定时器
710
+ ### LibPixiTickerTimeout-Ticker 定时器
679
711
 
680
712
  > 基于 Ticker 的定时器
681
713
 
682
714
  ```ts
683
715
  const stopTimer = libPixiTickerTimeout(() => {
684
- console.log('Callback after delay');
716
+ console.log("Callback after delay");
685
717
  }, 1000);
686
718
 
687
719
  // 停止定时器
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-pixi-js",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
4
4
  "description": "自用Pixi.JS方法库",
5
5
  "license": "ISC",
6
6
  "exports": {
@@ -1,20 +0,0 @@
1
- import { BitmapText } from "pixi.js";
2
- /** @description 自定义位图文本
3
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiBitText-位图
4
- */
5
- export declare class LibPixiBitText {
6
- /** 字体名称 */
7
- private _fontName;
8
- private _defaultFontSize?;
9
- /**
10
- * @param fontName 字体名称
11
- * @param defaultFontSize 默认字体大小
12
- */
13
- constructor(fontName: string, defaultFontSize?: number);
14
- /** @description 创建位图文本
15
- * @param text 文本内容
16
- * @param fontSize 字体大小,不填则使用默认大小
17
- * @returns 位图实例
18
- */
19
- createText(text: string | number, fontSize?: number): BitmapText;
20
- }
@@ -1,26 +0,0 @@
1
- import { BitmapText } from "pixi.js";
2
- /** @description 自定义位图文本
3
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiBitText-位图
4
- */
5
- export class LibPixiBitText {
6
- /**
7
- * @param fontName 字体名称
8
- * @param defaultFontSize 默认字体大小
9
- */
10
- constructor(fontName, defaultFontSize) {
11
- this._fontName = fontName;
12
- this._defaultFontSize = defaultFontSize;
13
- }
14
- /** @description 创建位图文本
15
- * @param text 文本内容
16
- * @param fontSize 字体大小,不填则使用默认大小
17
- * @returns 位图实例
18
- */
19
- createText(text, fontSize) {
20
- const bitMapText = new BitmapText(text.toString(), {
21
- fontName: this._fontName,
22
- fontSize: this._defaultFontSize || fontSize,
23
- });
24
- return bitMapText;
25
- }
26
- }
@@ -1,22 +0,0 @@
1
- import { Container } from "pixi.js";
2
- /** @description 自定义容器大小及背景色
3
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiContainer-容器
4
- */
5
- export declare class LibPixiContainer extends Container {
6
- /** 填充容器 */
7
- private _fill?;
8
- /** 背景色填充 */
9
- private _bgColorFill?;
10
- /**
11
- * @param width 容器宽度
12
- * @param height 容器高度
13
- * @param bgColor 背景色
14
- * @param overHidden 是否溢出裁剪
15
- */
16
- constructor(width: number, height: number, bgColor?: string, overHidden?: boolean);
17
- /** @description 设置容器大小
18
- * @param width 容器宽度
19
- * @param height 容器高度
20
- */
21
- setSize(width: number, height: number): void;
22
- }
@@ -1,51 +0,0 @@
1
- import { Container, Graphics, Sprite } from "pixi.js";
2
- import { LibPixiRectBgColor } from './LibPixiRectBgColor';
3
- /** @description 自定义容器大小及背景色
4
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiContainer-容器
5
- */
6
- export class LibPixiContainer extends Container {
7
- /**
8
- * @param width 容器宽度
9
- * @param height 容器高度
10
- * @param bgColor 背景色
11
- * @param overHidden 是否溢出裁剪
12
- */
13
- constructor(width, height, bgColor, overHidden) {
14
- super();
15
- if (overHidden) {
16
- const mask = new Graphics();
17
- mask.beginFill(0xffffff);
18
- mask.drawRect(0, 0, width, height);
19
- mask.endFill();
20
- this.addChild(mask);
21
- this.mask = mask;
22
- }
23
- if (bgColor) {
24
- this._bgColorFill = new LibPixiRectBgColor({
25
- width,
26
- height,
27
- bgColor,
28
- });
29
- this.addChild(this._bgColorFill);
30
- }
31
- else {
32
- this._fill = new Sprite();
33
- this._fill.width = width;
34
- this._fill.height = height;
35
- this.addChild(this._fill);
36
- }
37
- }
38
- /** @description 设置容器大小
39
- * @param width 容器宽度
40
- * @param height 容器高度
41
- */
42
- setSize(width, height) {
43
- if (this._fill) {
44
- this._fill.width = width;
45
- this._fill.height = height;
46
- }
47
- if (this._bgColorFill) {
48
- this._bgColorFill.renderBg(width, height);
49
- }
50
- }
51
- }
@@ -1,39 +0,0 @@
1
- import { Container } from "pixi.js";
2
- import { type EmitterConfigV3 } from "@pixi/particle-emitter";
3
- export interface LibPixiParticleMoveParams {
4
- /** 粒子JSON资源 */
5
- json: EmitterConfigV3;
6
- /** 运动时长 */
7
- duration: number;
8
- /** 粒子开始位置 */
9
- start: {
10
- x: number;
11
- y: number;
12
- };
13
- /** 粒子控制点 */
14
- control: {
15
- x: number;
16
- y: number;
17
- }[];
18
- /** 粒子结束点 */
19
- end: {
20
- x: number;
21
- y: number;
22
- };
23
- /** 运动曲线 */
24
- ease?: gsap.EaseString;
25
- /** 是否显示控制点,调试使用 */
26
- showControl?: boolean;
27
- /** 是否循环,调试使用 */
28
- loop?: boolean;
29
- }
30
- /** @description 利用贝塞尔曲线实现粒子移动
31
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiParticleMove-粒子容器
32
- */
33
- export declare class LibPixiParticleMove extends Container {
34
- private _particleContainer;
35
- constructor(params: LibPixiParticleMoveParams);
36
- private _createBezierPoints;
37
- private _multiPointBezier;
38
- private _binomial;
39
- }
@@ -1,100 +0,0 @@
1
- import { Container, ParticleContainer, Ticker } from "pixi.js";
2
- import { Emitter } from "@pixi/particle-emitter";
3
- import gsap from "gsap";
4
- import { LibPixiText } from "./LibPixiText";
5
- /** @description 利用贝塞尔曲线实现粒子移动
6
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiParticleMove-粒子容器
7
- */
8
- export class LibPixiParticleMove extends Container {
9
- constructor(params) {
10
- super();
11
- const { start, control, end, json, duration, ease = "power1.out", showControl = false, loop = false, } = params;
12
- this._particleContainer = new ParticleContainer();
13
- this.addChild(this._particleContainer);
14
- // 初始化粒子发射器
15
- const flyParticle = new Emitter(this._particleContainer, json);
16
- // 创建贝塞尔曲线的路径
17
- const path = this._createBezierPoints([start, ...control, end], 100, showControl);
18
- // 用来控制路径动画的对象
19
- const flyObj = { pathThrough: 0 };
20
- gsap.to(flyObj, {
21
- duration,
22
- pathThrough: path.length - 1,
23
- repeat: loop ? -1 : 0,
24
- ease,
25
- onStart: () => {
26
- flyParticle.emit = true;
27
- },
28
- onUpdate: () => {
29
- const i = Math.floor(flyObj.pathThrough);
30
- const p = path[i];
31
- flyParticle.updateOwnerPos(p.x, p.y);
32
- },
33
- onComplete: () => {
34
- gsap.to(this, {
35
- alpha: 0,
36
- duration: 0.5,
37
- onComplete: () => {
38
- flyParticle.emit = false;
39
- ticker.destroy();
40
- this.removeFromParent();
41
- },
42
- });
43
- },
44
- });
45
- const ticker = new Ticker();
46
- ticker.add(() => {
47
- flyParticle.update(1 / 75);
48
- });
49
- ticker.start();
50
- }
51
- _createBezierPoints(anchorPoints, pointsAmount, showControl) {
52
- const points = [];
53
- // 渲染控制点
54
- if (showControl) {
55
- anchorPoints.forEach((item, index) => {
56
- //创建一个小圆点
57
- const text = new LibPixiText({
58
- text: index + 1,
59
- fontSize: 16,
60
- });
61
- text.position.set(item.x, item.y);
62
- this.addChild(text);
63
- });
64
- }
65
- // 计算并存储贝塞尔曲线上的点
66
- for (let i = 0; i < pointsAmount; i++) {
67
- const point = this._multiPointBezier(anchorPoints, i / pointsAmount);
68
- points.push(point);
69
- }
70
- return points;
71
- }
72
- _multiPointBezier(points, t) {
73
- const len = points.length;
74
- let x = 0, y = 0;
75
- // 预计算组合数
76
- const binomials = [];
77
- for (let i = 0; i < len; i++) {
78
- binomials[i] = this._binomial(len - 1, i);
79
- }
80
- // 计算贝塞尔曲线上的点
81
- for (let i = 0; i < len; i++) {
82
- const point = points[i];
83
- const binom = binomials[i];
84
- const factorT = Math.pow(t, i);
85
- const factor1MinusT = Math.pow(1 - t, len - 1 - i);
86
- x += point.x * factor1MinusT * factorT * binom;
87
- y += point.y * factor1MinusT * factorT * binom;
88
- }
89
- return { x, y };
90
- }
91
- _binomial(n, k) {
92
- if (k === 0 || k === n)
93
- return 1;
94
- let res = 1;
95
- for (let i = 1; i <= k; i++) {
96
- res = (res * (n - i + 1)) / i;
97
- }
98
- return res;
99
- }
100
- }
@@ -1,45 +0,0 @@
1
- import { Graphics } from "pixi.js";
2
- export interface LibPixiRectBgColorParams {
3
- /** 宽度 */
4
- width?: number;
5
- /** 高度 */
6
- height?: number;
7
- /** 背景颜色 */
8
- bgColor?: string | number;
9
- /** x轴偏移 */
10
- x?: number;
11
- /** y轴偏移 */
12
- y?: number;
13
- /** 透明度 */
14
- alpha?: number;
15
- /** 圆角半径 */
16
- radius?: number | number[];
17
- /** 边框宽度 */
18
- borderWidth?: number;
19
- /** 边框颜色 */
20
- borderColor?: string;
21
- /** 是否启用变色功能 */
22
- enableTint?: boolean;
23
- }
24
- /** @description 自定义矩形背景色
25
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiRectBgColor-矩形
26
- */
27
- export declare class LibPixiRectBgColor extends Graphics {
28
- /** 圆边大小 */
29
- private radius;
30
- /** 启用着色 */
31
- private enableTint;
32
- /** 背景颜色 */
33
- private bgColor;
34
- /** 边框宽度 */
35
- private borderWidth;
36
- /** 边框颜色 */
37
- private borderColor;
38
- /** 背景色 */
39
- private bgAlpha;
40
- constructor(options: LibPixiRectBgColorParams);
41
- /** @description 重新绘制并添加颜色 */
42
- updateColor(tint: string): void;
43
- /** @description 更新宽度 */
44
- renderBg(width: number, height: number): void;
45
- }
@@ -1,98 +0,0 @@
1
- import { Graphics } from "pixi.js";
2
- import gsap from "gsap";
3
- /** @description 自定义矩形背景色
4
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiRectBgColor-矩形
5
- */
6
- export class LibPixiRectBgColor extends Graphics {
7
- constructor(options) {
8
- super();
9
- /** 圆边大小 */
10
- this.radius = 0;
11
- /** 启用着色 */
12
- this.enableTint = true;
13
- /** 背景颜色 */
14
- this.bgColor = "#fff";
15
- /** 边框宽度 */
16
- this.borderWidth = 0;
17
- /** 边框颜色 */
18
- this.borderColor = "black";
19
- /** 背景色 */
20
- this.bgAlpha = 1;
21
- const { x = 0, y = 0, width = 0, height = 0, bgColor = "#fff", alpha = 1, radius = 0, borderWidth = 0, borderColor = "black", enableTint = true, } = options;
22
- this.x = x;
23
- this.y = y;
24
- this.bgAlpha = alpha;
25
- this.radius = radius;
26
- this.enableTint = enableTint;
27
- this.bgColor = bgColor;
28
- this.borderWidth = borderWidth;
29
- this.borderColor = borderColor;
30
- this.renderBg(width, height);
31
- }
32
- /** @description 重新绘制并添加颜色 */
33
- updateColor(tint) {
34
- gsap.to(this, { tint, duration: 0.25 });
35
- }
36
- /** @description 更新宽度 */
37
- renderBg(width, height) {
38
- this.clear();
39
- if (this.enableTint) {
40
- this.beginFill("#fff", this.bgAlpha);
41
- this.tint = this.bgColor;
42
- }
43
- else {
44
- this.beginFill(this.bgColor, this.bgAlpha);
45
- this.borderWidth && this.lineStyle(this.borderWidth, this.borderColor, 1);
46
- }
47
- this.borderWidth && this.lineStyle(this.borderWidth, this.borderColor, 1);
48
- if (this.radius !== 0) {
49
- if (typeof this.radius === "number") {
50
- this.drawRoundedRect(0, 0, width, height, this.radius);
51
- }
52
- else {
53
- // 绘制顶部边
54
- this.moveTo(0 + this.radius[0], 0);
55
- this.lineTo(0 + width - this.radius[1], 0);
56
- // 绘制右上角的圆角
57
- if (this.radius[1] > 0) {
58
- this.arcTo(0 + width, 0, 0 + width, 0 + this.radius[1], this.radius[1]);
59
- }
60
- else {
61
- this.lineTo(0 + width, 0);
62
- }
63
- // 绘制右侧边
64
- this.lineTo(0 + width, 0 + height - this.radius[2]);
65
- // 绘制右下角的圆角
66
- if (this.radius[2] > 0) {
67
- this.arcTo(0 + width, 0 + height, 0 + width - this.radius[2], 0 + height, this.radius[2]);
68
- }
69
- else {
70
- this.lineTo(0 + width, 0 + height);
71
- }
72
- // 绘制底部边
73
- this.lineTo(0 + this.radius[3], 0 + height);
74
- // 绘制左下角的圆角
75
- if (this.radius[3] > 0) {
76
- this.arcTo(0, 0 + height, 0, 0 + height - this.radius[3], this.radius[3]);
77
- }
78
- else {
79
- this.lineTo(0, 0 + height);
80
- }
81
- // 绘制左侧边
82
- this.lineTo(0, 0 + this.radius[0]);
83
- // 绘制左上角的圆角
84
- if (this.radius[0] > 0) {
85
- this.arcTo(0, 0, 0 + this.radius[0], 0, this.radius[0]);
86
- }
87
- else {
88
- this.lineTo(0, 0);
89
- }
90
- this.closePath();
91
- }
92
- }
93
- else {
94
- this.drawRect(0, 0, width, height);
95
- }
96
- this.endFill();
97
- }
98
- }