@egjs/flicking 4.11.3-beta.3 → 4.11.3

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.
@@ -4,13 +4,13 @@ name: @egjs/flicking
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-flicking
7
- version: 4.11.0-snapshot
7
+ version: 4.11.3
8
8
  */
9
9
  import Component, { ComponentEvent } from '@egjs/component';
10
10
  import Axes, { PanInput } from '@egjs/axes';
11
11
  import ImReady from '@egjs/imready';
12
12
 
13
- /*! *****************************************************************************
13
+ /******************************************************************************
14
14
  Copyright (c) Microsoft Corporation.
15
15
 
16
16
  Permission to use, copy, modify, and/or distribute this software for any
@@ -24,7 +24,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
24
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
25
  PERFORMANCE OF THIS SOFTWARE.
26
26
  ***************************************************************************** */
27
- /* global Reflect, Promise */
27
+ /* global Reflect, Promise, SuppressedError, Symbol */
28
28
 
29
29
  var extendStatics = function (d, b) {
30
30
  extendStatics = Object.setPrototypeOf || {
@@ -109,7 +109,7 @@ function __generator(thisArg, body) {
109
109
  }
110
110
  function step(op) {
111
111
  if (f) throw new TypeError("Generator is already executing.");
112
- while (_) try {
112
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
113
113
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
114
114
  if (y = 0, t) op = [op[0] & 2, t.value];
115
115
  switch (op[0]) {
@@ -213,6 +213,10 @@ function __spread() {
213
213
  for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
214
214
  return ar;
215
215
  }
216
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
217
+ var e = new Error(message);
218
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
219
+ };
216
220
 
217
221
  /*
218
222
  * Copyright (c) 2015 NAVER Corp.
@@ -396,6 +400,17 @@ var CIRCULAR_FALLBACK = {
396
400
  LINEAR: "linear",
397
401
  BOUND: "bound"
398
402
  };
403
+ /**
404
+ * An object for identifying {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS property applied to the camera element(`.flicking-camera`)
405
+ * @ko 카메라 엘리먼트(`.flicking-camera`)에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성을 구분하기 위한 객체
406
+ * @type {object}
407
+ * @property {string} LTR "ltr"
408
+ * @property {string} RTL "rtl"
409
+ */
410
+ var ORDER = {
411
+ LTR: "ltr",
412
+ RTL: "rtl"
413
+ };
399
414
 
400
415
  // eslint-disable-next-line @typescript-eslint/ban-types
401
416
  var merge = function (target) {
@@ -689,20 +704,22 @@ var getElementSize = function (_a) {
689
704
  useFractionalSize = _a.useFractionalSize,
690
705
  useOffset = _a.useOffset,
691
706
  style = _a.style;
707
+ var size = 0;
692
708
  if (useFractionalSize) {
693
- var baseSize = parseFloat(horizontal ? style.width : style.height);
709
+ var baseSize = parseFloat(horizontal ? style.width : style.height) || 0;
694
710
  var isBorderBoxSizing = style.boxSizing === "border-box";
695
711
  var border = horizontal ? parseFloat(style.borderLeftWidth || "0") + parseFloat(style.borderRightWidth || "0") : parseFloat(style.borderTopWidth || "0") + parseFloat(style.borderBottomWidth || "0");
696
712
  if (isBorderBoxSizing) {
697
- return useOffset ? baseSize : baseSize - border;
713
+ size = useOffset ? baseSize : baseSize - border;
698
714
  } else {
699
715
  var padding = horizontal ? parseFloat(style.paddingLeft || "0") + parseFloat(style.paddingRight || "0") : parseFloat(style.paddingTop || "0") + parseFloat(style.paddingBottom || "0");
700
- return useOffset ? baseSize + padding + border : baseSize + padding;
716
+ size = useOffset ? baseSize + padding + border : baseSize + padding;
701
717
  }
702
718
  } else {
703
719
  var sizeStr = horizontal ? "Width" : "Height";
704
- return useOffset ? el["offset" + sizeStr] : el["client" + sizeStr];
720
+ size = useOffset ? el["offset" + sizeStr] : el["client" + sizeStr];
705
721
  }
722
+ return Math.max(size, 0);
706
723
  };
707
724
  var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
708
725
  obj.__proto__ = proto;
@@ -2086,7 +2103,7 @@ var AxesController = /*#__PURE__*/function () {
2086
2103
  threshold: 1,
2087
2104
  iOSEdgeSwipeThreshold: flicking.iOSEdgeSwipeThreshold,
2088
2105
  preventDefaultOnDrag: flicking.preventDefaultOnDrag,
2089
- scale: flicking.horizontal ? [-1, 0] : [0, -1],
2106
+ scale: flicking.horizontal ? [flicking.camera.panelOrder === ORDER.RTL ? 1 : -1, 0] : [0, -1],
2090
2107
  releaseOnScroll: true
2091
2108
  });
2092
2109
  var axes = this._axes;
@@ -2311,7 +2328,7 @@ var AxesController = /*#__PURE__*/function () {
2311
2328
  var panInput = this._panInput;
2312
2329
  axes.disconnect(panInput);
2313
2330
  axes.connect(flicking.horizontal ? [POSITION_KEY, ""] : ["", POSITION_KEY], panInput);
2314
- panInput.options.scale = flicking.horizontal ? [-1, 0] : [0, -1];
2331
+ panInput.options.scale = flicking.horizontal ? [flicking.camera.panelOrder === ORDER.RTL ? 1 : -1, 0] : [0, -1];
2315
2332
  };
2316
2333
  __proto._resetInternalValues = function () {
2317
2334
  this._flicking = null;
@@ -2576,7 +2593,7 @@ var Control = /*#__PURE__*/function () {
2576
2593
  var position;
2577
2594
  return __generator(this, function (_c) {
2578
2595
  position = this._getPosition(panel, direction);
2579
- this._triggerIndexChangeEvent(panel, panel.position, axesEvent);
2596
+ this._triggerIndexChangeEvent(panel, panel.position, axesEvent, direction);
2580
2597
  return [2 /*return*/, this._animateToPosition({
2581
2598
  position: position,
2582
2599
  duration: duration,
@@ -2593,6 +2610,7 @@ var Control = /*#__PURE__*/function () {
2593
2610
  var _a;
2594
2611
  var flicking = getFlickingAttached(this._flicking);
2595
2612
  this._activePanel = newActivePanel;
2613
+ this._nextPanel = null;
2596
2614
  flicking.camera.updateAdaptiveHeight();
2597
2615
  if (newActivePanel !== prevActivePanel) {
2598
2616
  flicking.trigger(new ComponentEvent(EVENTS.CHANGED, {
@@ -2617,7 +2635,7 @@ var Control = /*#__PURE__*/function () {
2617
2635
  this._activePanel = control._activePanel;
2618
2636
  this._controller = control._controller;
2619
2637
  };
2620
- __proto._triggerIndexChangeEvent = function (panel, position, axesEvent) {
2638
+ __proto._triggerIndexChangeEvent = function (panel, position, axesEvent, direction) {
2621
2639
  var _a;
2622
2640
  var flicking = getFlickingAttached(this._flicking);
2623
2641
  var triggeringEvent = panel !== this._activePanel ? EVENTS.WILL_CHANGE : EVENTS.WILL_RESTORE;
@@ -2627,8 +2645,9 @@ var Control = /*#__PURE__*/function () {
2627
2645
  index: panel.index,
2628
2646
  panel: panel,
2629
2647
  isTrusted: (axesEvent === null || axesEvent === void 0 ? void 0 : axesEvent.isTrusted) || false,
2630
- direction: getDirection((_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.position) !== null && _a !== void 0 ? _a : camera.position, position)
2648
+ direction: direction !== null && direction !== void 0 ? direction : getDirection((_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.position) !== null && _a !== void 0 ? _a : camera.position, position)
2631
2649
  });
2650
+ this._nextPanel = panel;
2632
2651
  flicking.trigger(event);
2633
2652
  if (event.isCanceled()) {
2634
2653
  throw new FlickingError(MESSAGE.STOP_CALLED_BY_USER, CODE.STOP_CALLED_BY_USER);
@@ -2847,7 +2866,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2847
2866
  if (!activeAnchor || !anchorAtCamera) {
2848
2867
  return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
2849
2868
  }
2850
- var snapThreshold = this._calcSnapThreshold(position, activeAnchor);
2869
+ var snapThreshold = this._calcSnapThreshold(flicking.threshold, position, activeAnchor);
2851
2870
  var posDelta = flicking.animating ? state.delta : position - camera.position;
2852
2871
  var absPosDelta = Math.abs(posDelta);
2853
2872
  var snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
@@ -2934,7 +2953,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2934
2953
  var adjacentAnchor = (_a = posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) !== null && _a !== void 0 ? _a : anchorAtCamera;
2935
2954
  return adjacentAnchor;
2936
2955
  };
2937
- __proto._calcSnapThreshold = function (position, activeAnchor) {
2956
+ __proto._calcSnapThreshold = function (threshold, position, activeAnchor) {
2938
2957
  var isNextDirection = position > activeAnchor.position;
2939
2958
  var panel = activeAnchor.panel;
2940
2959
  var panelSize = panel.size;
@@ -2945,7 +2964,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2945
2964
  * |<------>|<------------>|
2946
2965
  * [ |<-Anchor ]
2947
2966
  */
2948
- return isNextDirection ? panelSize - alignPos + panel.margin.next : alignPos + panel.margin.prev;
2967
+ return Math.max(threshold, isNextDirection ? panelSize - alignPos + panel.margin.next : alignPos + panel.margin.prev);
2949
2968
  };
2950
2969
  return SnapControl;
2951
2970
  }(Control);
@@ -3216,19 +3235,20 @@ var StrictControl = /*#__PURE__*/function (_super) {
3216
3235
  * @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
3217
3236
  */
3218
3237
  __proto.moveToPosition = function (position, duration, axesEvent) {
3238
+ var _a;
3219
3239
  var flicking = getFlickingAttached(this._flicking);
3220
3240
  var camera = flicking.camera;
3221
- var activePanel = this._activePanel;
3241
+ var currentPanel = (_a = this._nextPanel) !== null && _a !== void 0 ? _a : this._activePanel;
3222
3242
  var axesRange = this._controller.range;
3223
3243
  var indexRange = this._indexRange;
3224
3244
  var cameraRange = camera.range;
3225
3245
  var state = this._controller.state;
3226
3246
  var clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
3227
3247
  var anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
3228
- if (!anchorAtPosition || !activePanel) {
3248
+ if (!anchorAtPosition || !currentPanel) {
3229
3249
  return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
3230
3250
  }
3231
- var prevPos = activePanel.position;
3251
+ var prevPos = currentPanel.position;
3232
3252
  var posDelta = flicking.animating ? state.delta : position - camera.position;
3233
3253
  var isOverThreshold = Math.abs(posDelta) >= flicking.threshold;
3234
3254
  var adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
@@ -3245,7 +3265,7 @@ var StrictControl = /*#__PURE__*/function (_super) {
3245
3265
  var targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
3246
3266
  targetPanel = targetAnchor.panel;
3247
3267
  targetPos = targetAnchor.position;
3248
- } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
3268
+ } else if (isOverThreshold && anchorAtPosition.position !== currentPanel.position) {
3249
3269
  // Move to anchor at position
3250
3270
  targetPanel = anchorAtPosition.panel;
3251
3271
  targetPos = anchorAtPosition.position;
@@ -3983,6 +4003,19 @@ var Camera = /*#__PURE__*/function () {
3983
4003
  enumerable: false,
3984
4004
  configurable: true
3985
4005
  });
4006
+ Object.defineProperty(__proto, "panelOrder", {
4007
+ /**
4008
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS property applied to the camera element(`.flicking-camera`)
4009
+ * @ko 카메라 엘리먼트(`.flicking-camera`)에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성
4010
+ * @type {string}
4011
+ * @readonly
4012
+ */
4013
+ get: function () {
4014
+ return this._panelOrder;
4015
+ },
4016
+ enumerable: false,
4017
+ configurable: true
4018
+ });
3986
4019
  Object.defineProperty(__proto, "align", {
3987
4020
  // Options Getter
3988
4021
  /**
@@ -4014,6 +4047,7 @@ var Camera = /*#__PURE__*/function () {
4014
4047
  this._el = viewportEl.firstElementChild;
4015
4048
  this._checkTranslateSupport();
4016
4049
  this._updateMode();
4050
+ this.updatePanelOrder();
4017
4051
  return this;
4018
4052
  };
4019
4053
  /**
@@ -4135,11 +4169,13 @@ var Camera = /*#__PURE__*/function () {
4135
4169
  * @return {AnchorPoint | null}
4136
4170
  */
4137
4171
  __proto.findActiveAnchor = function () {
4172
+ var _a;
4138
4173
  var flicking = getFlickingAttached(this._flicking);
4139
- var activeIndex = flicking.control.activeIndex;
4140
- return find(this._anchors, function (anchor) {
4141
- return anchor.panel.index === activeIndex;
4142
- });
4174
+ var activePanel = flicking.control.activePanel;
4175
+ if (!activePanel) return null;
4176
+ return (_a = find(this._anchors, function (anchor) {
4177
+ return anchor.panel.index === activePanel.index;
4178
+ })) !== null && _a !== void 0 ? _a : this.findNearestAnchor(activePanel.position);
4143
4179
  };
4144
4180
  /**
4145
4181
  * Clamp the given position between camera's range
@@ -4256,6 +4292,24 @@ var Camera = /*#__PURE__*/function () {
4256
4292
  this.applyTransform();
4257
4293
  return this;
4258
4294
  };
4295
+ /**
4296
+ * Update direction to match the {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS property applied to the camera element
4297
+ * @ko 카메라 엘리먼트에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성에 맞게 방향을 업데이트합니다
4298
+ * @return {this}
4299
+ */
4300
+ __proto.updatePanelOrder = function () {
4301
+ var flicking = getFlickingAttached(this._flicking);
4302
+ if (!flicking.horizontal) return this;
4303
+ var el = this._el;
4304
+ var direction = getStyle(el).direction;
4305
+ if (direction !== this._panelOrder) {
4306
+ this._panelOrder = direction === ORDER.RTL ? ORDER.RTL : ORDER.LTR;
4307
+ if (flicking.initialized) {
4308
+ flicking.control.controller.updateDirection();
4309
+ }
4310
+ }
4311
+ return this;
4312
+ };
4259
4313
  /**
4260
4314
  * Reset the history of {@link Flicking#event:needPanel needPanel} events so it can be triggered again
4261
4315
  * @ko 발생한 {@link Flicking#event:needPanel needPanel} 이벤트들을 초기화하여 다시 발생할 수 있도록 합니다
@@ -4280,7 +4334,7 @@ var Camera = /*#__PURE__*/function () {
4280
4334
  var renderer = flicking.renderer;
4281
4335
  if (renderer.rendering || !flicking.initialized) return this;
4282
4336
  var actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
4283
- el.style[this._transform] = flicking.horizontal ? "translate(" + -actualPosition + "px)" : "translate(0, " + -actualPosition + "px)";
4337
+ el.style[this._transform] = flicking.horizontal ? "translate(" + (this._panelOrder === ORDER.RTL ? actualPosition : -actualPosition) + "px)" : "translate(0, " + -actualPosition + "px)";
4284
4338
  return this;
4285
4339
  };
4286
4340
  __proto._resetInternalValues = function () {
@@ -7528,15 +7582,24 @@ var Flicking = /*#__PURE__*/function (_super) {
7528
7582
  return [4 /*yield*/, renderer.forceRenderAllPanels()];
7529
7583
  case 1:
7530
7584
  _a.sent(); // Render all panel elements, to update sizes
7585
+ if (!this._initialized) {
7586
+ return [2 /*return*/];
7587
+ }
7588
+
7531
7589
  renderer.updatePanelSize();
7532
7590
  camera.updateAlignPos();
7533
7591
  camera.updateRange();
7534
7592
  camera.updateAnchors();
7535
7593
  camera.updateAdaptiveHeight();
7594
+ camera.updatePanelOrder();
7536
7595
  camera.updateOffset();
7537
7596
  return [4 /*yield*/, renderer.render()];
7538
7597
  case 2:
7539
7598
  _a.sent();
7599
+ if (!this._initialized) {
7600
+ return [2 /*return*/];
7601
+ }
7602
+
7540
7603
  if (control.animating) ; else {
7541
7604
  control.updatePosition(prevProgressInPanel);
7542
7605
  control.updateInput();
@@ -7773,7 +7836,7 @@ var Flicking = /*#__PURE__*/function (_super) {
7773
7836
  * Flicking.VERSION; // ex) 4.0.0
7774
7837
  * ```
7775
7838
  */
7776
- Flicking.VERSION = "4.11.0-snapshot";
7839
+ Flicking.VERSION = "4.11.3";
7777
7840
  return Flicking;
7778
7841
  }(Component);
7779
7842
 
@@ -7991,5 +8054,5 @@ var parseAlign = function (alignVal) {
7991
8054
  * egjs projects are licensed under the MIT license
7992
8055
  */
7993
8056
 
7994
- export { ALIGN, AnchorPoint, AnimatingState, AxesController, BoundCameraMode, CIRCULAR_FALLBACK, CLASS, Camera, CircularCameraMode, Control, DIRECTION, DisabledState, DraggingState, CODE as ERROR_CODE, EVENTS, ExternalRenderer, FlickingError, FreeControl, HoldingState, IdleState, LinearCameraMode, MOVE_TYPE, NormalRenderingStrategy, Panel, Renderer, SnapControl, State, StateMachine, StrictControl, VanillaElementProvider, VanillaRenderer, Viewport, VirtualElementProvider, VirtualManager, VirtualPanel, VirtualRenderingStrategy, checkExistence, circulateIndex, circulatePosition, clamp, Flicking as default, find, findIndex, findRight, getDefaultCameraTransform, getDirection, getElement, getElementSize, getFlickingAttached, getMinusCompensatedIndex, getProgress, getRenderingPanels, getStyle, includes, isBetween, isString, merge, parseAlign$1 as parseAlign, parseArithmeticExpression, parseArithmeticSize, parseBounce, parseCSSSizeValue, parseElement, parsePanelAlign, range, setPrototypeOf, setSize, sync, toArray, withFlickingMethods };
8057
+ export { ALIGN, AnchorPoint, AnimatingState, AxesController, BoundCameraMode, CIRCULAR_FALLBACK, CLASS, Camera, CircularCameraMode, Control, DIRECTION, DisabledState, DraggingState, CODE as ERROR_CODE, EVENTS, ExternalRenderer, FlickingError, FreeControl, HoldingState, IdleState, LinearCameraMode, MOVE_TYPE, NormalRenderingStrategy, ORDER, Panel, Renderer, SnapControl, State, StateMachine, StrictControl, VanillaElementProvider, VanillaRenderer, Viewport, VirtualElementProvider, VirtualManager, VirtualPanel, VirtualRenderingStrategy, checkExistence, circulateIndex, circulatePosition, clamp, Flicking as default, find, findIndex, findRight, getDefaultCameraTransform, getDirection, getElement, getElementSize, getFlickingAttached, getMinusCompensatedIndex, getProgress, getRenderingPanels, getStyle, includes, isBetween, isString, merge, parseAlign$1 as parseAlign, parseArithmeticExpression, parseArithmeticSize, parseBounce, parseCSSSizeValue, parseElement, parsePanelAlign, range, setPrototypeOf, setSize, sync, toArray, withFlickingMethods };
7995
8058
  //# sourceMappingURL=flicking.esm.js.map