lyb-pixi-js 1.7.0 → 1.7.2

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.
@@ -1,5 +1,5 @@
1
1
  import { Container } from "pixi.js";
2
- import { LibPixiContainer } from "../Base/LibPixiContainer";
2
+ import { LibPixiContainer } from '../Base/LibPixiContainer';
3
3
  export interface LibPixiScrollContainerParams {
4
4
  /** 宽度 */
5
5
  width: number;
@@ -9,6 +9,8 @@ export interface LibPixiScrollContainerParams {
9
9
  scrollContent: Container;
10
10
  /** 底部内边距 */
11
11
  bottomMargin?: number;
12
+ /** 滚动方向,vertical | horizontal,默认vertical */
13
+ direction?: "vertical" | "horizontal";
12
14
  }
13
15
  /** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
14
16
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainer-滚动容器
@@ -26,6 +28,8 @@ export declare class LibPixiScrollContainer extends LibPixiContainer {
26
28
  private _scrollSpeed;
27
29
  /** 是否处于拖动状态 */
28
30
  private _isDragging;
31
+ /** 滚动方向 */
32
+ private _direction;
29
33
  /** 滚动容器 */
30
34
  _scrollContent: Container;
31
35
  /** 遮罩 */
@@ -1,11 +1,12 @@
1
1
  import { Container, Graphics, Sprite, } from "pixi.js";
2
2
  import { gsap } from "gsap";
3
- import { LibPixiContainer } from "../Base/LibPixiContainer";
3
+ import { LibPixiContainer } from '../Base/LibPixiContainer';
4
4
  /** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
5
5
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainer-滚动容器
6
6
  */
7
7
  export class LibPixiScrollContainer extends LibPixiContainer {
8
8
  constructor(params) {
9
+ var _a;
9
10
  const { width, height, scrollContent, bottomMargin = 50 } = params;
10
11
  super(width, height);
11
12
  /** 开始位置 */
@@ -20,7 +21,10 @@ export class LibPixiScrollContainer extends LibPixiContainer {
20
21
  this._scrollSpeed = 200;
21
22
  /** 是否处于拖动状态 */
22
23
  this._isDragging = false;
24
+ /** 滚动方向 */
25
+ this._direction = "vertical";
23
26
  this._scrollContent = scrollContent;
27
+ this._direction = (_a = params.direction) !== null && _a !== void 0 ? _a : "vertical";
24
28
  // 创建内容容器
25
29
  this._content = new Container();
26
30
  this.addChild(this._content);
@@ -73,7 +77,10 @@ export class LibPixiScrollContainer extends LibPixiContainer {
73
77
  if (this._content.height <= this._maskGraphics.height)
74
78
  return;
75
79
  const position = event.getLocalPosition(this);
76
- this._startY = position.y - this._content.y;
80
+ this._startY =
81
+ this._direction === "vertical"
82
+ ? position.y - this._content.y
83
+ : position.x - this._content.x;
77
84
  this._isDragging = true;
78
85
  this._velocity = 0;
79
86
  this._startTime = Date.now();
@@ -84,8 +91,15 @@ export class LibPixiScrollContainer extends LibPixiContainer {
84
91
  _onDragMove(event) {
85
92
  if (this._isDragging) {
86
93
  const position = event.getLocalPosition(this);
87
- const newPosition = position.y - this._startY;
88
- this._content.y = newPosition;
94
+ const newPosition = this._direction === "vertical"
95
+ ? position.y - this._startY
96
+ : position.x - this._startY;
97
+ if (this._direction === "vertical") {
98
+ this._content.y = newPosition;
99
+ }
100
+ else {
101
+ this._content.x = newPosition;
102
+ }
89
103
  }
90
104
  }
91
105
  /** @description 拖动结束 */
@@ -106,61 +120,47 @@ export class LibPixiScrollContainer extends LibPixiContainer {
106
120
  }
107
121
  /** @description 滚轮滚动 */
108
122
  _onWheelScroll(event) {
109
- // 如果内容高度小于遮罩高度,则不滚动
110
- if (this._content.height <= this._maskGraphics.height)
111
- return;
112
- let y = this._content.y - event.deltaY * (this._scrollSpeed / 100);
113
- //如果到达顶部,则不滚动
114
- if (y > 0) {
115
- y = 0;
123
+ if (this._direction === "vertical") {
124
+ if (this._content.height <= this._maskGraphics.height)
125
+ return;
126
+ let y = this._content.y - event.deltaY * (this._scrollSpeed / 100);
127
+ y = Math.min(0, Math.max(y, -(this._content.height - this._maskGraphics.height)));
128
+ gsap.to(this._content, { duration: 0.25, ease: "power1.out", y });
116
129
  }
117
- //如果到达底部,则不滚动
118
- else if (Math.abs(y) >= this._content.height - this._maskGraphics.height) {
119
- y = -(this._content.height - this._maskGraphics.height);
130
+ else {
131
+ if (this._content.width <= this._maskGraphics.width)
132
+ return;
133
+ let x = this._content.x - event.deltaY * (this._scrollSpeed / 100);
134
+ x = Math.min(0, Math.max(x, -(this._content.width - this._maskGraphics.width)));
135
+ gsap.to(this._content, { duration: 0.25, ease: "power1.out", x });
120
136
  }
121
- gsap.to(this._content, {
122
- duration: 0.25,
123
- ease: "power1.out",
124
- y,
125
- });
126
137
  }
127
138
  /** @description 惯性动画 */
128
139
  _applyInertia() {
129
- gsap.to(this._content, {
130
- y: this._content.y + this._velocity * 250,
131
- duration: 0.5,
132
- ease: "power1.out",
133
- onUpdate: this._limitScrollRange.bind(this),
134
- });
140
+ gsap.to(this._content, Object.assign({ duration: 0.5, ease: "power1.out", onUpdate: this._limitScrollRange.bind(this) }, (this._direction === "vertical"
141
+ ? { y: this._content.y + this._velocity * 250 }
142
+ : { x: this._content.x + this._velocity * 250 })));
135
143
  }
136
144
  /** @description 限制滚动范围 */
137
145
  _limitScrollRange() {
138
- //如果内容顶部离开了滚动容器顶部,则归位
139
- if (this._content.y > 0) {
140
- gsap.to(this._content, {
141
- duration: 0.75,
142
- y: 0,
143
- ease: "elastic.out",
144
- });
145
- }
146
- // 如果滚动距离大于内容高度减去遮罩高度
147
- else if (Math.abs(this._content.y) >=
148
- this._content.height - this._maskGraphics.height) {
149
- // 如果内容高度大于遮罩高度,则滚动到底部
150
- if (this._content.height > this._maskGraphics.height) {
146
+ if (this._direction === "vertical") {
147
+ if (this._content.y > 0) {
148
+ gsap.to(this._content, { duration: 0.75, y: 0, ease: "elastic.out" });
149
+ }
150
+ else if (Math.abs(this._content.y) >=
151
+ this._content.height - this._maskGraphics.height) {
151
152
  const y = -(this._content.height - this._maskGraphics.height);
152
- gsap.to(this._content, {
153
- duration: 0.75,
154
- y,
155
- ease: "elastic.out",
156
- });
153
+ gsap.to(this._content, { duration: 0.75, y, ease: "elastic.out" });
157
154
  }
158
- // 否则静止不动
159
- else {
160
- gsap.to(this._content, {
161
- duration: 0.25,
162
- y: 0,
163
- });
155
+ }
156
+ else {
157
+ if (this._content.x > 0) {
158
+ gsap.to(this._content, { duration: 0.75, x: 0, ease: "elastic.out" });
159
+ }
160
+ else if (Math.abs(this._content.x) >=
161
+ this._content.width - this._maskGraphics.width) {
162
+ const x = -(this._content.width - this._maskGraphics.width);
163
+ gsap.to(this._content, { duration: 0.75, x, ease: "elastic.out" });
164
164
  }
165
165
  }
166
166
  }
@@ -7,6 +7,8 @@ interface LibPixiSliderParams {
7
7
  height: number;
8
8
  /** 滑动页列表 */
9
9
  slideList: Container[];
10
+ /** 是否启用循环滑动 */
11
+ loop?: boolean;
10
12
  /** 是否启用景深 */
11
13
  enableDepth?: boolean;
12
14
  /** 景深透明度 */
@@ -26,6 +28,8 @@ export declare class LibPixiSlider extends LibPixiContainer {
26
28
  private _slideWidth;
27
29
  /** 滑动区域高度 */
28
30
  private _slideHeight;
31
+ /** 是否启用循环 */
32
+ private _loop;
29
33
  /** 记录拖动开始时的X坐标 */
30
34
  private _startX;
31
35
  /** 偏移量 */
@@ -1,8 +1,9 @@
1
1
  import { Container } from "pixi.js";
2
2
  import gsap from "gsap";
3
+ import { LibJsLerp } from "lyb-js/Math/LibJsLerp.js";
3
4
  import { libPixiOverflowHidden } from "../../Utils/LibPixiOverflowHidden";
4
5
  import { LibPixiContainer } from "../Base/LibPixiContainer";
5
- import { LibJsLerp } from 'lyb-js/Math/LibJsLerp';
6
+ import { libPixiEvent } from "../../Utils/LibPixiEvent";
6
7
  /** @description 类似轮播图,但是不会自动轮播
7
8
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlider-横向滑动图
8
9
  */
@@ -14,7 +15,7 @@ export class LibPixiSlider extends LibPixiContainer {
14
15
  * @param slideCallback 滑动结束回调
15
16
  */
16
17
  constructor(params) {
17
- const { width, height, slideList, slideCallback, enableDepth = false, depthAlpha = 0.5, depthScale = 0.5, } = params;
18
+ const { width, height, slideList, slideCallback, loop = false, enableDepth = false, depthAlpha = 0.5, depthScale = 0.5, } = params;
18
19
  super(width, height);
19
20
  /** 当前幻灯片索引 */
20
21
  this._currentIndex = 0;
@@ -22,6 +23,8 @@ export class LibPixiSlider extends LibPixiContainer {
22
23
  this._slideWidth = 0;
23
24
  /** 滑动区域高度 */
24
25
  this._slideHeight = 0;
26
+ /** 是否启用循环 */
27
+ this._loop = false;
25
28
  /** 记录拖动开始时的X坐标 */
26
29
  this._startX = 0;
27
30
  /** 偏移量 */
@@ -36,6 +39,7 @@ export class LibPixiSlider extends LibPixiContainer {
36
39
  this._slideArea = new Container();
37
40
  this._slideWidth = width;
38
41
  this._slideHeight = height;
42
+ this._loop = loop;
39
43
  this._slideList = slideList;
40
44
  this._enableDepth = enableDepth;
41
45
  this._depthAlpha = depthAlpha;
@@ -49,10 +53,7 @@ export class LibPixiSlider extends LibPixiContainer {
49
53
  item.pivot.set(this._slideWidth / 2, this._slideHeight / 2);
50
54
  });
51
55
  this.addChild(this._slideArea);
52
- // 监听拖动事件
53
- this.eventMode = "static";
54
- this.cursor = "pointer";
55
- this.on("pointerdown", this._onDragStart);
56
+ libPixiEvent(this, "pointerdown", this._onDragStart.bind(this));
56
57
  window.addEventListener("pointermove", this._onDragMove.bind(this));
57
58
  window.addEventListener("pointerup", this._onDragEnd.bind(this));
58
59
  }
@@ -68,39 +69,36 @@ export class LibPixiSlider extends LibPixiContainer {
68
69
  * @param index 索引
69
70
  */
70
71
  _slideTo(index) {
71
- if (index < 0) {
72
- // 回弹到第一张
73
- gsap.to(this._slideArea, {
74
- x: 0,
75
- duration: 0.25,
76
- onUpdate: () => {
77
- this._setDepth();
78
- },
79
- });
80
- this._currentIndex = 0;
81
- }
82
- else if (index > this._pageNum) {
83
- // 回弹到最后一张
84
- gsap.to(this._slideArea, {
85
- x: -this._pageNum * this._slideWidth,
86
- duration: 0.5,
87
- onUpdate: () => {
88
- this._setDepth();
89
- },
90
- });
91
- this._currentIndex = this._pageNum;
72
+ let x = 0;
73
+ if (this._loop) {
74
+ this._currentIndex =
75
+ (index + this._slideList.length) % this._slideList.length;
76
+ x = -this._currentIndex * this._slideWidth;
92
77
  }
93
78
  else {
94
- // 正常滑动
95
- this._currentIndex = index;
96
- gsap.to(this._slideArea, {
97
- x: -this._currentIndex * this._slideWidth,
98
- duration: 0.25,
99
- onUpdate: () => {
100
- this._setDepth();
101
- },
102
- });
79
+ if (index < 0) {
80
+ // 回弹到第一张
81
+ x = 0;
82
+ this._currentIndex = 0;
83
+ }
84
+ else if (index > this._pageNum) {
85
+ // 回弹到最后一张
86
+ x = -this._pageNum * this._slideWidth;
87
+ this._currentIndex = this._pageNum;
88
+ }
89
+ else {
90
+ // 正常滑动
91
+ x = -index * this._slideWidth;
92
+ this._currentIndex = index;
93
+ }
103
94
  }
95
+ gsap.to(this._slideArea, {
96
+ x,
97
+ duration: 0.25,
98
+ onUpdate: () => {
99
+ this._setDepth();
100
+ },
101
+ });
104
102
  this.slideCallback(this._currentIndex, this._pageNum);
105
103
  }
106
104
  /** @description 开始拖动 */
package/README.md CHANGED
@@ -146,8 +146,6 @@ app.stage.addChild(box);
146
146
 
147
147
  \- [LibPixiPolygonDrawTool-多边形绘制](#LibPixiPolygonDrawTool-多边形绘制)
148
148
 
149
- \- [LibPixiWatchProperty-对象属性监听](#LibPixiWatchProperty-对象属性监听)
150
-
151
149
  ## Base-基础
152
150
 
153
151
  ### LibPixiText-文本
@@ -1019,21 +1017,4 @@ $bus.on("play", () => {
1019
1017
 
1020
1018
  ```ts
1021
1019
  new LibPixiPolygonDrawTool(app);
1022
- ```
1023
-
1024
- ### LibPixiWatchProperty-对象属性监听
1025
-
1026
- > 内部通过 Ticker 每秒调用10次循环判断被监听的属性是否发生改变,当元素被销毁时自动销毁 Ticker,取决于是否传递了元素
1027
-
1028
- ```ts
1029
- LibPixiWatchProperty(
1030
- gameStore,
1031
- ["a", "b"],
1032
- () => {
1033
- warningContainer.visible = a;
1034
- useBtn.eventMode = a || b ? "none" : "static";
1035
- },
1036
- this
1037
- );
1038
- ```
1039
-
1020
+ ```
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 tag = 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, "&quot;");
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$1 = Math.abs;
1702
1702
  var floor$1 = Math.floor;
1703
- var max$1 = Math.max;
1703
+ var max$2 = Math.max;
1704
1704
  var min$1 = Math.min;
1705
1705
  var pow$1 = Math.pow;
1706
1706
  var round$2 = Math.round;
@@ -1833,102 +1833,78 @@
1833
1833
  Object_getPrototypeOf = $Object2.getPrototypeOf || null;
1834
1834
  return Object_getPrototypeOf;
1835
1835
  }
1836
- var implementation;
1837
- var hasRequiredImplementation;
1838
- function requireImplementation() {
1839
- if (hasRequiredImplementation)
1840
- return implementation;
1841
- hasRequiredImplementation = 1;
1842
- var ERROR_MESSAGE = "Function.prototype.bind called on incompatible ";
1843
- var toStr2 = Object.prototype.toString;
1844
- var max2 = Math.max;
1845
- var funcType = "[object Function]";
1846
- var concatty = function concatty2(a2, b2) {
1847
- var arr = [];
1848
- for (var i2 = 0; i2 < a2.length; i2 += 1) {
1849
- arr[i2] = a2[i2];
1850
- }
1851
- for (var j2 = 0; j2 < b2.length; j2 += 1) {
1852
- arr[j2 + a2.length] = b2[j2];
1853
- }
1854
- return arr;
1855
- };
1856
- var slicy = function slicy2(arrLike, offset) {
1857
- var arr = [];
1858
- for (var i2 = offset || 0, j2 = 0; i2 < arrLike.length; i2 += 1, j2 += 1) {
1859
- arr[j2] = arrLike[i2];
1860
- }
1861
- return arr;
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$1 = 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
- return str;
1872
- };
1873
- implementation = function bind2(that) {
1874
- var target = this;
1875
- if (typeof target !== "function" || toStr2.apply(target) !== funcType) {
1876
- throw new TypeError(ERROR_MESSAGE + target);
1877
- }
1878
- var args = slicy(arguments, 1);
1879
- var bound;
1880
- var binder = function() {
1881
- if (this instanceof bound) {
1882
- var result = target.apply(
1883
- this,
1884
- concatty(args, arguments)
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
- var boundLength = max2(0, target.length - args.length);
1897
- var boundArgs = [];
1898
- for (var i2 = 0; i2 < boundLength; i2++) {
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 bound;
1885
+ return target.apply(
1886
+ that,
1887
+ concatty(args, arguments)
1888
+ );
1910
1889
  };
1911
- return implementation;
1912
- }
1913
- var functionBind;
1914
- var hasRequiredFunctionBind;
1915
- function requireFunctionBind() {
1916
- if (hasRequiredFunctionBind)
1917
- return functionBind;
1918
- hasRequiredFunctionBind = 1;
1919
- var implementation2 = requireImplementation();
1920
- functionBind = Function.prototype.bind || implementation2;
1921
- return functionBind;
1922
- }
1923
- var functionCall;
1924
- var hasRequiredFunctionCall;
1925
- function requireFunctionCall() {
1926
- if (hasRequiredFunctionCall)
1927
- return functionCall;
1928
- hasRequiredFunctionCall = 1;
1929
- functionCall = Function.prototype.call;
1930
- return functionCall;
1931
- }
1890
+ var boundLength = max$1(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 = requireFunctionBind();
1918
+ var bind$2 = functionBind;
1943
1919
  var $apply$1 = requireFunctionApply();
1944
- var $call$2 = requireFunctionCall();
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 = requireFunctionBind();
1923
+ var bind$1 = functionBind;
1948
1924
  var $TypeError$4 = type;
1949
- var $call$1 = requireFunctionCall();
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 = requireFunctionBind();
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 = abs$1;
2032
2008
  var floor = floor$1;
2033
- var max = max$1;
2009
+ var max = max$2;
2034
2010
  var min = min$1;
2035
2011
  var pow = pow$1;
2036
2012
  var round$1 = round$2;
@@ -2064,7 +2040,7 @@
2064
2040
  var $ObjectGPO = requireObject_getPrototypeOf();
2065
2041
  var $ReflectGPO = requireReflect_getPrototypeOf();
2066
2042
  var $apply = requireFunctionApply();
2067
- var $call = requireFunctionCall();
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 = requireFunctionBind();
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);
@@ -49124,7 +49100,9 @@ void main(void)\r
49124
49100
  this._startPosition = 0;
49125
49101
  this._scrollSpeed = 200;
49126
49102
  this._isDragging = false;
49103
+ this._direction = "vertical";
49127
49104
  this._scrollContent = scrollContent;
49105
+ this._direction = params.direction ?? "vertical";
49128
49106
  this._content = new Container();
49129
49107
  this.addChild(this._content);
49130
49108
  this._content.addChild(this._scrollContent);
@@ -49172,7 +49150,7 @@ void main(void)\r
49172
49150
  if (this._content.height <= this._maskGraphics.height)
49173
49151
  return;
49174
49152
  const position = event.getLocalPosition(this);
49175
- this._startY = position.y - this._content.y;
49153
+ this._startY = this._direction === "vertical" ? position.y - this._content.y : position.x - this._content.x;
49176
49154
  this._isDragging = true;
49177
49155
  this._velocity = 0;
49178
49156
  this._startTime = Date.now();
@@ -49183,8 +49161,12 @@ void main(void)\r
49183
49161
  _onDragMove(event) {
49184
49162
  if (this._isDragging) {
49185
49163
  const position = event.getLocalPosition(this);
49186
- const newPosition = position.y - this._startY;
49187
- this._content.y = newPosition;
49164
+ const newPosition = this._direction === "vertical" ? position.y - this._startY : position.x - this._startY;
49165
+ if (this._direction === "vertical") {
49166
+ this._content.y = newPosition;
49167
+ } else {
49168
+ this._content.x = newPosition;
49169
+ }
49188
49170
  }
49189
49171
  }
49190
49172
  /** @description 拖动结束 */
@@ -49202,50 +49184,50 @@ void main(void)\r
49202
49184
  }
49203
49185
  /** @description 滚轮滚动 */
49204
49186
  _onWheelScroll(event) {
49205
- if (this._content.height <= this._maskGraphics.height)
49206
- return;
49207
- let y2 = this._content.y - event.deltaY * (this._scrollSpeed / 100);
49208
- if (y2 > 0) {
49209
- y2 = 0;
49210
- } else if (Math.abs(y2) >= this._content.height - this._maskGraphics.height) {
49211
- y2 = -(this._content.height - this._maskGraphics.height);
49187
+ if (this._direction === "vertical") {
49188
+ if (this._content.height <= this._maskGraphics.height)
49189
+ return;
49190
+ let y2 = this._content.y - event.deltaY * (this._scrollSpeed / 100);
49191
+ y2 = Math.min(
49192
+ 0,
49193
+ Math.max(y2, -(this._content.height - this._maskGraphics.height))
49194
+ );
49195
+ gsapWithCSS.to(this._content, { duration: 0.25, ease: "power1.out", y: y2 });
49196
+ } else {
49197
+ if (this._content.width <= this._maskGraphics.width)
49198
+ return;
49199
+ let x2 = this._content.x - event.deltaY * (this._scrollSpeed / 100);
49200
+ x2 = Math.min(
49201
+ 0,
49202
+ Math.max(x2, -(this._content.width - this._maskGraphics.width))
49203
+ );
49204
+ gsapWithCSS.to(this._content, { duration: 0.25, ease: "power1.out", x: x2 });
49212
49205
  }
49213
- gsapWithCSS.to(this._content, {
49214
- duration: 0.25,
49215
- ease: "power1.out",
49216
- y: y2
49217
- });
49218
49206
  }
49219
49207
  /** @description 惯性动画 */
49220
49208
  _applyInertia() {
49221
49209
  gsapWithCSS.to(this._content, {
49222
- y: this._content.y + this._velocity * 250,
49223
49210
  duration: 0.5,
49224
49211
  ease: "power1.out",
49225
- onUpdate: this._limitScrollRange.bind(this)
49212
+ onUpdate: this._limitScrollRange.bind(this),
49213
+ ...this._direction === "vertical" ? { y: this._content.y + this._velocity * 250 } : { x: this._content.x + this._velocity * 250 }
49226
49214
  });
49227
49215
  }
49228
49216
  /** @description 限制滚动范围 */
49229
49217
  _limitScrollRange() {
49230
- if (this._content.y > 0) {
49231
- gsapWithCSS.to(this._content, {
49232
- duration: 0.75,
49233
- y: 0,
49234
- ease: "elastic.out"
49235
- });
49236
- } else if (Math.abs(this._content.y) >= this._content.height - this._maskGraphics.height) {
49237
- if (this._content.height > this._maskGraphics.height) {
49218
+ if (this._direction === "vertical") {
49219
+ if (this._content.y > 0) {
49220
+ gsapWithCSS.to(this._content, { duration: 0.75, y: 0, ease: "elastic.out" });
49221
+ } else if (Math.abs(this._content.y) >= this._content.height - this._maskGraphics.height) {
49238
49222
  const y2 = -(this._content.height - this._maskGraphics.height);
49239
- gsapWithCSS.to(this._content, {
49240
- duration: 0.75,
49241
- y: y2,
49242
- ease: "elastic.out"
49243
- });
49244
- } else {
49245
- gsapWithCSS.to(this._content, {
49246
- duration: 0.25,
49247
- y: 0
49248
- });
49223
+ gsapWithCSS.to(this._content, { duration: 0.75, y: y2, ease: "elastic.out" });
49224
+ }
49225
+ } else {
49226
+ if (this._content.x > 0) {
49227
+ gsapWithCSS.to(this._content, { duration: 0.75, x: 0, ease: "elastic.out" });
49228
+ } else if (Math.abs(this._content.x) >= this._content.width - this._maskGraphics.width) {
49229
+ const x2 = -(this._content.width - this._maskGraphics.width);
49230
+ gsapWithCSS.to(this._content, { duration: 0.75, x: x2, ease: "elastic.out" });
49249
49231
  }
49250
49232
  }
49251
49233
  }
@@ -49438,6 +49420,7 @@ void main(void)\r
49438
49420
  height,
49439
49421
  slideList,
49440
49422
  slideCallback,
49423
+ loop = false,
49441
49424
  enableDepth = false,
49442
49425
  depthAlpha = 0.5,
49443
49426
  depthScale = 0.5
@@ -49446,6 +49429,7 @@ void main(void)\r
49446
49429
  this._currentIndex = 0;
49447
49430
  this._slideWidth = 0;
49448
49431
  this._slideHeight = 0;
49432
+ this._loop = false;
49449
49433
  this._startX = 0;
49450
49434
  this._offsetX = 0;
49451
49435
  this._pageNum = 0;
@@ -49455,6 +49439,7 @@ void main(void)\r
49455
49439
  this._slideArea = new Container();
49456
49440
  this._slideWidth = width;
49457
49441
  this._slideHeight = height;
49442
+ this._loop = loop;
49458
49443
  this._slideList = slideList;
49459
49444
  this._enableDepth = enableDepth;
49460
49445
  this._depthAlpha = depthAlpha;
@@ -49468,9 +49453,7 @@ void main(void)\r
49468
49453
  item.pivot.set(this._slideWidth / 2, this._slideHeight / 2);
49469
49454
  });
49470
49455
  this.addChild(this._slideArea);
49471
- this.eventMode = "static";
49472
- this.cursor = "pointer";
49473
- this.on("pointerdown", this._onDragStart);
49456
+ libPixiEvent(this, "pointerdown", this._onDragStart.bind(this));
49474
49457
  window.addEventListener("pointermove", this._onDragMove.bind(this));
49475
49458
  window.addEventListener("pointerup", this._onDragEnd.bind(this));
49476
49459
  }
@@ -49486,34 +49469,29 @@ void main(void)\r
49486
49469
  * @param index 索引
49487
49470
  */
49488
49471
  _slideTo(index) {
49489
- if (index < 0) {
49490
- gsapWithCSS.to(this._slideArea, {
49491
- x: 0,
49492
- duration: 0.25,
49493
- onUpdate: () => {
49494
- this._setDepth();
49495
- }
49496
- });
49497
- this._currentIndex = 0;
49498
- } else if (index > this._pageNum) {
49499
- gsapWithCSS.to(this._slideArea, {
49500
- x: -this._pageNum * this._slideWidth,
49501
- duration: 0.5,
49502
- onUpdate: () => {
49503
- this._setDepth();
49504
- }
49505
- });
49506
- this._currentIndex = this._pageNum;
49472
+ let x2 = 0;
49473
+ if (this._loop) {
49474
+ this._currentIndex = (index + this._slideList.length) % this._slideList.length;
49475
+ x2 = -this._currentIndex * this._slideWidth;
49507
49476
  } else {
49508
- this._currentIndex = index;
49509
- gsapWithCSS.to(this._slideArea, {
49510
- x: -this._currentIndex * this._slideWidth,
49511
- duration: 0.25,
49512
- onUpdate: () => {
49513
- this._setDepth();
49514
- }
49515
- });
49477
+ if (index < 0) {
49478
+ x2 = 0;
49479
+ this._currentIndex = 0;
49480
+ } else if (index > this._pageNum) {
49481
+ x2 = -this._pageNum * this._slideWidth;
49482
+ this._currentIndex = this._pageNum;
49483
+ } else {
49484
+ x2 = -index * this._slideWidth;
49485
+ this._currentIndex = index;
49486
+ }
49516
49487
  }
49488
+ gsapWithCSS.to(this._slideArea, {
49489
+ x: x2,
49490
+ duration: 0.25,
49491
+ onUpdate: () => {
49492
+ this._setDepth();
49493
+ }
49494
+ });
49517
49495
  this.slideCallback(this._currentIndex, this._pageNum);
49518
49496
  }
49519
49497
  /** @description 开始拖动 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-pixi-js",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "自用Pixi.JS方法库",
5
5
  "license": "ISC",
6
6
  "exports": {