@egjs/flicking 4.6.2 → 4.7.1

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/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  <a href="https://www.npmjs.com/package/@egjs/flicking" target="_blank"><img src="https://img.shields.io/npm/v/@egjs/flicking.svg?style=flat-square&color=007acc&label=version&logo=NPM" alt="version" /></a>
8
8
  <a href="https://www.npmjs.com/package/@egjs/flicking" target="_blank"><img alt="npm bundle size (scoped)" src="https://img.shields.io/bundlephobia/minzip/@egjs/flicking.svg?style=flat-square&label=%F0%9F%92%BE%20gzipped&color=007acc" /></a>
9
9
  <a href="https://coveralls.io/github/naver/egjs-flicking?branch=master&style=flat-square" target="_blank"><img alt="Coveralls github" src="https://img.shields.io/coveralls/github/naver/egjs-flicking.svg?style=flat-square&label=%E2%9C%85%20coverage" /></a>
10
- <a href="https://deepscan.io/dashboard#view=project&tid=3998&pid=5802&bid=46086"><img src="https://deepscan.io/api/teams/3998/projects/5802/branches/46086/badge/grade.svg" alt="DeepScan grade" /></a>
10
+ <a href="https://deepscan.io/dashboard#view=project&tid=3998&pid=5802&bid=46086"><img src="https://flat.badgen.net/deepscan/grade/team/3998/project/5802/branch/46086" alt="DeepScan grade" /></a>
11
11
  </p>
12
12
  <p align="center" style="line-height: 2;">
13
13
  <a href="https://github.com/naver/egjs-flicking/graphs/commit-activity">
@@ -42,6 +42,7 @@ export interface FlickingOptions {
42
42
  panelsPerView: number;
43
43
  noPanelStyleOverride: boolean;
44
44
  resizeOnContentsReady: boolean;
45
+ nested: boolean;
45
46
  needPanelThreshold: number;
46
47
  preventEventsBeforeInit: boolean;
47
48
  deceleration: number;
@@ -87,6 +88,7 @@ declare class Flicking extends Component<FlickingEvents> {
87
88
  private _noPanelStyleOverride;
88
89
  private _resizeOnContentsReady;
89
90
  private _virtual;
91
+ private _nested;
90
92
  private _needPanelThreshold;
91
93
  private _preventEventsBeforeInit;
92
94
  private _deceleration;
@@ -139,6 +141,7 @@ declare class Flicking extends Component<FlickingEvents> {
139
141
  get panelsPerView(): FlickingOptions["panelsPerView"];
140
142
  get noPanelStyleOverride(): FlickingOptions["noPanelStyleOverride"];
141
143
  get resizeOnContentsReady(): FlickingOptions["resizeOnContentsReady"];
144
+ get nested(): FlickingOptions["nested"];
142
145
  get needPanelThreshold(): FlickingOptions["needPanelThreshold"];
143
146
  get preventEventsBeforeInit(): FlickingOptions["preventEventsBeforeInit"];
144
147
  get deceleration(): FlickingOptions["deceleration"];
@@ -173,6 +176,7 @@ declare class Flicking extends Component<FlickingEvents> {
173
176
  set panelsPerView(val: FlickingOptions["panelsPerView"]);
174
177
  set noPanelStyleOverride(val: FlickingOptions["noPanelStyleOverride"]);
175
178
  set resizeOnContentsReady(val: FlickingOptions["resizeOnContentsReady"]);
179
+ set nested(val: FlickingOptions["nested"]);
176
180
  set needPanelThreshold(val: FlickingOptions["needPanelThreshold"]);
177
181
  set preventEventsBeforeInit(val: FlickingOptions["preventEventsBeforeInit"]);
178
182
  set deceleration(val: FlickingOptions["deceleration"]);
@@ -189,7 +193,7 @@ declare class Flicking extends Component<FlickingEvents> {
189
193
  set renderOnlyVisible(val: FlickingOptions["renderOnlyVisible"]);
190
194
  set autoResize(val: FlickingOptions["autoResize"]);
191
195
  set useResizeObserver(val: FlickingOptions["useResizeObserver"]);
192
- constructor(root: HTMLElement | string, { align, defaultIndex, horizontal, circular, circularFallback, bound, adaptive, panelsPerView, noPanelStyleOverride, resizeOnContentsReady, needPanelThreshold, preventEventsBeforeInit, deceleration, duration, easing, inputType, moveType, threshold, interruptable, bounce, iOSEdgeSwipeThreshold, preventClickOnDrag, disableOnInit, renderOnlyVisible, virtual, autoInit, autoResize, useResizeObserver, resizeDebounce, maxResizeDebounce, externalRenderer, renderExternal }?: Partial<FlickingOptions>);
196
+ constructor(root: HTMLElement | string, { align, defaultIndex, horizontal, circular, circularFallback, bound, adaptive, panelsPerView, noPanelStyleOverride, resizeOnContentsReady, nested, needPanelThreshold, preventEventsBeforeInit, deceleration, duration, easing, inputType, moveType, threshold, interruptable, bounce, iOSEdgeSwipeThreshold, preventClickOnDrag, disableOnInit, renderOnlyVisible, virtual, autoInit, autoResize, useResizeObserver, resizeDebounce, maxResizeDebounce, externalRenderer, renderExternal }?: Partial<FlickingOptions>);
193
197
  init(): Promise<void>;
194
198
  destroy(): void;
195
199
  prev(duration?: number): Promise<void>;
@@ -11,6 +11,7 @@ declare abstract class CameraMode {
11
11
  };
12
12
  getAnchors(): AnchorPoint[];
13
13
  findAnchorIncludePosition(position: number): AnchorPoint | null;
14
+ findNearestAnchor(position: number): AnchorPoint | null;
14
15
  clampToReachablePosition(position: number): number;
15
16
  getCircularOffset(): number;
16
17
  canReach(panel: Panel): boolean;
@@ -8,6 +8,7 @@ declare class CircularCameraMode extends CameraMode {
8
8
  max: number;
9
9
  };
10
10
  getAnchors(): AnchorPoint[];
11
+ findNearestAnchor(position: number): AnchorPoint | null;
11
12
  findAnchorIncludePosition(position: number): AnchorPoint | null;
12
13
  getCircularOffset(): number;
13
14
  clampToReachablePosition(position: number): number;
@@ -4,7 +4,7 @@ name: @egjs/flicking
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-flicking
7
- version: 4.6.2
7
+ version: 4.7.1
8
8
  */
9
9
  import Component, { ComponentEvent } from '@egjs/component';
10
10
  import Axes, { PanInput } from '@egjs/axes';
@@ -2261,7 +2261,7 @@ function () {
2261
2261
  get: function () {
2262
2262
  var _a, _b;
2263
2263
 
2264
- return (_b = (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.isEnable()) !== null && _b !== void 0 ? _b : false;
2264
+ return (_b = (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.isEnabled()) !== null && _b !== void 0 ? _b : false;
2265
2265
  },
2266
2266
  enumerable: false,
2267
2267
  configurable: true
@@ -2332,6 +2332,7 @@ function () {
2332
2332
  }, _a), {
2333
2333
  deceleration: flicking.deceleration,
2334
2334
  interruptable: flicking.interruptable,
2335
+ nested: flicking.nested,
2335
2336
  easing: flicking.easing
2336
2337
  });
2337
2338
  this._panInput = new PanInput(flicking.viewport.element, {
@@ -2428,7 +2429,7 @@ function () {
2428
2429
  axis.circular = [controlParams.circular, controlParams.circular];
2429
2430
  axis.range = [controlParams.range.min, controlParams.range.max];
2430
2431
  axis.bounce = parseBounce(flicking.bounce, camera.size);
2431
- axes.axm.set((_a = {}, _a[POSITION_KEY] = controlParams.position, _a));
2432
+ axes.axisManager.set((_a = {}, _a[POSITION_KEY] = controlParams.position, _a));
2432
2433
  return this;
2433
2434
  };
2434
2435
  /**
@@ -2544,7 +2545,7 @@ function () {
2544
2545
  var camera = flicking.camera;
2545
2546
  animate();
2546
2547
  var newPos = flicking.circularEnabled ? circulatePosition(position, camera.range.min, camera.range.max) : position;
2547
- axes.axm.set((_a = {}, _a[POSITION_KEY] = newPos, _a));
2548
+ axes.axisManager.set((_a = {}, _a[POSITION_KEY] = newPos, _a));
2548
2549
  return Promise.resolve();
2549
2550
  } else {
2550
2551
  return new Promise(function (resolve, reject) {
@@ -3569,6 +3570,7 @@ function (_super) {
3569
3570
  var lastAnchor = anchors[anchors.length - 1];
3570
3571
  var shouldBounceToFirst = position <= cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
3571
3572
  var shouldBounceToLast = position >= cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
3573
+ var isAdjacent = adjacentAnchor && (indexRange.min <= indexRange.max ? isBetween(adjacentAnchor.index, indexRange.min, indexRange.max) : adjacentAnchor.index >= indexRange.min || adjacentAnchor.index <= indexRange.max);
3572
3574
 
3573
3575
  if (shouldBounceToFirst || shouldBounceToLast) {
3574
3576
  // In bounce area
@@ -3579,7 +3581,7 @@ function (_super) {
3579
3581
  // Move to anchor at position
3580
3582
  targetPanel = anchorAtPosition.panel;
3581
3583
  targetPos = anchorAtPosition.position;
3582
- } else if (isOverThreshold && adjacentAnchor && isBetween(adjacentAnchor.index, indexRange.min, indexRange.max)) {
3584
+ } else if (isOverThreshold && isAdjacent) {
3583
3585
  // Move to adjacent anchor
3584
3586
  targetPanel = adjacentAnchor.panel;
3585
3587
  targetPos = adjacentAnchor.position;
@@ -3645,6 +3647,27 @@ function () {
3645
3647
  }, null);
3646
3648
  };
3647
3649
 
3650
+ __proto.findNearestAnchor = function (position) {
3651
+ var anchors = this._flicking.camera.anchorPoints;
3652
+ if (anchors.length <= 0) return null;
3653
+ var prevDist = Infinity;
3654
+
3655
+ for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
3656
+ var anchor = anchors[anchorIdx];
3657
+ var dist = Math.abs(anchor.position - position);
3658
+
3659
+ if (dist > prevDist) {
3660
+ // Return previous anchor
3661
+ return anchors[anchorIdx - 1];
3662
+ }
3663
+
3664
+ prevDist = dist;
3665
+ } // Return last anchor
3666
+
3667
+
3668
+ return anchors[anchors.length - 1];
3669
+ };
3670
+
3648
3671
  __proto.clampToReachablePosition = function (position) {
3649
3672
  var camera = this._flicking.camera;
3650
3673
  var range = camera.range;
@@ -3774,6 +3797,28 @@ function (_super) {
3774
3797
  });
3775
3798
  };
3776
3799
 
3800
+ __proto.findNearestAnchor = function (position) {
3801
+ var camera = this._flicking.camera;
3802
+ var anchors = camera.anchorPoints;
3803
+ if (anchors.length <= 0) return null;
3804
+ var camRange = camera.range;
3805
+ var minDist = Infinity;
3806
+ var minDistIndex = -1;
3807
+
3808
+ for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
3809
+ var anchor = anchors[anchorIdx];
3810
+ var dist = Math.min(Math.abs(anchor.position - position), Math.abs(anchor.position - camRange.min + camRange.max - position), Math.abs(position - camRange.min + camRange.max - anchor.position));
3811
+
3812
+ if (dist < minDist) {
3813
+ minDist = dist;
3814
+ minDistIndex = anchorIdx;
3815
+ }
3816
+ } // Return last anchor
3817
+
3818
+
3819
+ return anchors[minDistIndex];
3820
+ };
3821
+
3777
3822
  __proto.findAnchorIncludePosition = function (position) {
3778
3823
  var camera = this._flicking.camera;
3779
3824
  var range = camera.range;
@@ -4542,24 +4587,7 @@ function () {
4542
4587
 
4543
4588
 
4544
4589
  __proto.findNearestAnchor = function (position) {
4545
- var anchors = this._anchors;
4546
- if (anchors.length <= 0) return null;
4547
- var prevDist = Infinity;
4548
-
4549
- for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
4550
- var anchor = anchors[anchorIdx];
4551
- var dist = Math.abs(anchor.position - position);
4552
-
4553
- if (dist > prevDist) {
4554
- // Return previous anchor
4555
- return anchors[anchorIdx - 1];
4556
- }
4557
-
4558
- prevDist = dist;
4559
- } // Return last anchor
4560
-
4561
-
4562
- return anchors[anchors.length - 1];
4590
+ return this._mode.findNearestAnchor(position);
4563
4591
  };
4564
4592
  /**
4565
4593
  * Return {@link AnchorPoint} that matches {@link Flicking#currentPanel}
@@ -5294,7 +5322,7 @@ function () {
5294
5322
  if (!resizeOnContentsReady || flicking.virtualEnabled) return;
5295
5323
 
5296
5324
  var hasContents = function (panel) {
5297
- return !!panel.element.querySelector("img, video");
5325
+ return panel.element && !!panel.element.querySelector("img, video");
5298
5326
  };
5299
5327
 
5300
5328
  checkingPanels = checkingPanels.filter(function (panel) {
@@ -6604,52 +6632,54 @@ function (_super) {
6604
6632
  noPanelStyleOverride = _l === void 0 ? false : _l,
6605
6633
  _m = _b.resizeOnContentsReady,
6606
6634
  resizeOnContentsReady = _m === void 0 ? false : _m,
6607
- _o = _b.needPanelThreshold,
6608
- needPanelThreshold = _o === void 0 ? 0 : _o,
6609
- _p = _b.preventEventsBeforeInit,
6610
- preventEventsBeforeInit = _p === void 0 ? true : _p,
6611
- _q = _b.deceleration,
6612
- deceleration = _q === void 0 ? 0.0075 : _q,
6613
- _r = _b.duration,
6614
- duration = _r === void 0 ? 500 : _r,
6615
- _s = _b.easing,
6616
- easing = _s === void 0 ? function (x) {
6635
+ _o = _b.nested,
6636
+ nested = _o === void 0 ? false : _o,
6637
+ _p = _b.needPanelThreshold,
6638
+ needPanelThreshold = _p === void 0 ? 0 : _p,
6639
+ _q = _b.preventEventsBeforeInit,
6640
+ preventEventsBeforeInit = _q === void 0 ? true : _q,
6641
+ _r = _b.deceleration,
6642
+ deceleration = _r === void 0 ? 0.0075 : _r,
6643
+ _s = _b.duration,
6644
+ duration = _s === void 0 ? 500 : _s,
6645
+ _t = _b.easing,
6646
+ easing = _t === void 0 ? function (x) {
6617
6647
  return 1 - Math.pow(1 - x, 3);
6618
- } : _s,
6619
- _t = _b.inputType,
6620
- inputType = _t === void 0 ? ["mouse", "touch"] : _t,
6621
- _u = _b.moveType,
6622
- moveType = _u === void 0 ? "snap" : _u,
6623
- _v = _b.threshold,
6624
- threshold = _v === void 0 ? 40 : _v,
6625
- _w = _b.interruptable,
6626
- interruptable = _w === void 0 ? true : _w,
6627
- _x = _b.bounce,
6628
- bounce = _x === void 0 ? "20%" : _x,
6629
- _y = _b.iOSEdgeSwipeThreshold,
6630
- iOSEdgeSwipeThreshold = _y === void 0 ? 30 : _y,
6631
- _z = _b.preventClickOnDrag,
6632
- preventClickOnDrag = _z === void 0 ? true : _z,
6633
- _0 = _b.disableOnInit,
6634
- disableOnInit = _0 === void 0 ? false : _0,
6635
- _1 = _b.renderOnlyVisible,
6636
- renderOnlyVisible = _1 === void 0 ? false : _1,
6637
- _2 = _b.virtual,
6638
- virtual = _2 === void 0 ? null : _2,
6639
- _3 = _b.autoInit,
6640
- autoInit = _3 === void 0 ? true : _3,
6641
- _4 = _b.autoResize,
6642
- autoResize = _4 === void 0 ? true : _4,
6643
- _5 = _b.useResizeObserver,
6644
- useResizeObserver = _5 === void 0 ? true : _5,
6645
- _6 = _b.resizeDebounce,
6646
- resizeDebounce = _6 === void 0 ? 0 : _6,
6647
- _7 = _b.maxResizeDebounce,
6648
- maxResizeDebounce = _7 === void 0 ? 100 : _7,
6649
- _8 = _b.externalRenderer,
6650
- externalRenderer = _8 === void 0 ? null : _8,
6651
- _9 = _b.renderExternal,
6652
- renderExternal = _9 === void 0 ? null : _9;
6648
+ } : _t,
6649
+ _u = _b.inputType,
6650
+ inputType = _u === void 0 ? ["mouse", "touch"] : _u,
6651
+ _v = _b.moveType,
6652
+ moveType = _v === void 0 ? "snap" : _v,
6653
+ _w = _b.threshold,
6654
+ threshold = _w === void 0 ? 40 : _w,
6655
+ _x = _b.interruptable,
6656
+ interruptable = _x === void 0 ? true : _x,
6657
+ _y = _b.bounce,
6658
+ bounce = _y === void 0 ? "20%" : _y,
6659
+ _z = _b.iOSEdgeSwipeThreshold,
6660
+ iOSEdgeSwipeThreshold = _z === void 0 ? 30 : _z,
6661
+ _0 = _b.preventClickOnDrag,
6662
+ preventClickOnDrag = _0 === void 0 ? true : _0,
6663
+ _1 = _b.disableOnInit,
6664
+ disableOnInit = _1 === void 0 ? false : _1,
6665
+ _2 = _b.renderOnlyVisible,
6666
+ renderOnlyVisible = _2 === void 0 ? false : _2,
6667
+ _3 = _b.virtual,
6668
+ virtual = _3 === void 0 ? null : _3,
6669
+ _4 = _b.autoInit,
6670
+ autoInit = _4 === void 0 ? true : _4,
6671
+ _5 = _b.autoResize,
6672
+ autoResize = _5 === void 0 ? true : _5,
6673
+ _6 = _b.useResizeObserver,
6674
+ useResizeObserver = _6 === void 0 ? true : _6,
6675
+ _7 = _b.resizeDebounce,
6676
+ resizeDebounce = _7 === void 0 ? 0 : _7,
6677
+ _8 = _b.maxResizeDebounce,
6678
+ maxResizeDebounce = _8 === void 0 ? 100 : _8,
6679
+ _9 = _b.externalRenderer,
6680
+ externalRenderer = _9 === void 0 ? null : _9,
6681
+ _10 = _b.renderExternal,
6682
+ renderExternal = _10 === void 0 ? null : _10;
6653
6683
 
6654
6684
  var _this = _super.call(this) || this; // Internal states
6655
6685
 
@@ -6667,6 +6697,7 @@ function (_super) {
6667
6697
  _this._panelsPerView = panelsPerView;
6668
6698
  _this._noPanelStyleOverride = noPanelStyleOverride;
6669
6699
  _this._resizeOnContentsReady = resizeOnContentsReady;
6700
+ _this._nested = nested;
6670
6701
  _this._virtual = virtual;
6671
6702
  _this._needPanelThreshold = needPanelThreshold;
6672
6703
  _this._preventEventsBeforeInit = preventEventsBeforeInit;
@@ -7140,6 +7171,24 @@ function (_super) {
7140
7171
  enumerable: false,
7141
7172
  configurable: true
7142
7173
  });
7174
+ Object.defineProperty(__proto, "nested", {
7175
+ /**
7176
+ * If you enable this option on child Flicking when the Flicking is placed inside the Flicking, the parent Flicking will move in the same direction after the child Flicking reaches the first/last panel.
7177
+ * If the parent Flicking and child Flicking have different horizontal option, you do not need to set this option.
7178
+ * @ko Flicking 내부에 Flicking이 배치될 때 하위 Flicking에서 이 옵션을 활성화하면 하위 Flicking이 첫/마지막 패널에 도달한 뒤부터 같은 방향으로 상위 Flicking이 움직입니다.
7179
+ * 만약 상위 Flicking과 하위 Flicking이 서로 다른 horizontal 옵션을 가지고 있다면 이 옵션을 설정할 필요가 없습니다.
7180
+ * @type {boolean}
7181
+ * @default false
7182
+ */
7183
+ get: function () {
7184
+ return this._nested;
7185
+ },
7186
+ set: function (val) {
7187
+ this._nested = val;
7188
+ },
7189
+ enumerable: false,
7190
+ configurable: true
7191
+ });
7143
7192
  Object.defineProperty(__proto, "needPanelThreshold", {
7144
7193
  // EVENTS
7145
7194
 
@@ -8376,7 +8425,7 @@ function (_super) {
8376
8425
  */
8377
8426
 
8378
8427
 
8379
- Flicking.VERSION = "4.6.2";
8428
+ Flicking.VERSION = "4.7.1";
8380
8429
  return Flicking;
8381
8430
  }(Component);
8382
8431