@egjs/flicking 4.11.3-beta.3 → 4.11.3-beta.4

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,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.11.0-snapshot
7
+ version: 4.11.3-beta.4
8
8
  */
9
9
  import Component, { ComponentEvent } from '@egjs/component';
10
10
  import Axes, { PanInput } from '@egjs/axes';
@@ -396,6 +396,17 @@ var CIRCULAR_FALLBACK = {
396
396
  LINEAR: "linear",
397
397
  BOUND: "bound"
398
398
  };
399
+ /**
400
+ * 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`)
401
+ * @ko 카메라 엘리먼트(`.flicking-camera`)에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성을 구분하기 위한 객체
402
+ * @type {object}
403
+ * @property {string} LTR "ltr"
404
+ * @property {string} RTL "rtl"
405
+ */
406
+ var ORDER = {
407
+ LTR: "ltr",
408
+ RTL: "rtl"
409
+ };
399
410
 
400
411
  // eslint-disable-next-line @typescript-eslint/ban-types
401
412
  var merge = function (target) {
@@ -689,20 +700,22 @@ var getElementSize = function (_a) {
689
700
  useFractionalSize = _a.useFractionalSize,
690
701
  useOffset = _a.useOffset,
691
702
  style = _a.style;
703
+ var size = 0;
692
704
  if (useFractionalSize) {
693
- var baseSize = parseFloat(horizontal ? style.width : style.height);
705
+ var baseSize = parseFloat(horizontal ? style.width : style.height) || 0;
694
706
  var isBorderBoxSizing = style.boxSizing === "border-box";
695
707
  var border = horizontal ? parseFloat(style.borderLeftWidth || "0") + parseFloat(style.borderRightWidth || "0") : parseFloat(style.borderTopWidth || "0") + parseFloat(style.borderBottomWidth || "0");
696
708
  if (isBorderBoxSizing) {
697
- return useOffset ? baseSize : baseSize - border;
709
+ size = useOffset ? baseSize : baseSize - border;
698
710
  } else {
699
711
  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;
712
+ size = useOffset ? baseSize + padding + border : baseSize + padding;
701
713
  }
702
714
  } else {
703
715
  var sizeStr = horizontal ? "Width" : "Height";
704
- return useOffset ? el["offset" + sizeStr] : el["client" + sizeStr];
716
+ size = useOffset ? el["offset" + sizeStr] : el["client" + sizeStr];
705
717
  }
718
+ return Math.max(size, 0);
706
719
  };
707
720
  var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
708
721
  obj.__proto__ = proto;
@@ -2086,7 +2099,7 @@ var AxesController = /*#__PURE__*/function () {
2086
2099
  threshold: 1,
2087
2100
  iOSEdgeSwipeThreshold: flicking.iOSEdgeSwipeThreshold,
2088
2101
  preventDefaultOnDrag: flicking.preventDefaultOnDrag,
2089
- scale: flicking.horizontal ? [-1, 0] : [0, -1],
2102
+ scale: flicking.horizontal ? [flicking.camera.panelOrder === ORDER.RTL ? 1 : -1, 0] : [0, -1],
2090
2103
  releaseOnScroll: true
2091
2104
  });
2092
2105
  var axes = this._axes;
@@ -2311,7 +2324,7 @@ var AxesController = /*#__PURE__*/function () {
2311
2324
  var panInput = this._panInput;
2312
2325
  axes.disconnect(panInput);
2313
2326
  axes.connect(flicking.horizontal ? [POSITION_KEY, ""] : ["", POSITION_KEY], panInput);
2314
- panInput.options.scale = flicking.horizontal ? [-1, 0] : [0, -1];
2327
+ panInput.options.scale = flicking.horizontal ? [flicking.camera.panelOrder === ORDER.RTL ? 1 : -1, 0] : [0, -1];
2315
2328
  };
2316
2329
  __proto._resetInternalValues = function () {
2317
2330
  this._flicking = null;
@@ -2576,7 +2589,7 @@ var Control = /*#__PURE__*/function () {
2576
2589
  var position;
2577
2590
  return __generator(this, function (_c) {
2578
2591
  position = this._getPosition(panel, direction);
2579
- this._triggerIndexChangeEvent(panel, panel.position, axesEvent);
2592
+ this._triggerIndexChangeEvent(panel, panel.position, axesEvent, direction);
2580
2593
  return [2 /*return*/, this._animateToPosition({
2581
2594
  position: position,
2582
2595
  duration: duration,
@@ -2593,6 +2606,7 @@ var Control = /*#__PURE__*/function () {
2593
2606
  var _a;
2594
2607
  var flicking = getFlickingAttached(this._flicking);
2595
2608
  this._activePanel = newActivePanel;
2609
+ this._nextPanel = null;
2596
2610
  flicking.camera.updateAdaptiveHeight();
2597
2611
  if (newActivePanel !== prevActivePanel) {
2598
2612
  flicking.trigger(new ComponentEvent(EVENTS.CHANGED, {
@@ -2617,7 +2631,7 @@ var Control = /*#__PURE__*/function () {
2617
2631
  this._activePanel = control._activePanel;
2618
2632
  this._controller = control._controller;
2619
2633
  };
2620
- __proto._triggerIndexChangeEvent = function (panel, position, axesEvent) {
2634
+ __proto._triggerIndexChangeEvent = function (panel, position, axesEvent, direction) {
2621
2635
  var _a;
2622
2636
  var flicking = getFlickingAttached(this._flicking);
2623
2637
  var triggeringEvent = panel !== this._activePanel ? EVENTS.WILL_CHANGE : EVENTS.WILL_RESTORE;
@@ -2627,8 +2641,9 @@ var Control = /*#__PURE__*/function () {
2627
2641
  index: panel.index,
2628
2642
  panel: panel,
2629
2643
  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)
2644
+ 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
2645
  });
2646
+ this._nextPanel = panel;
2632
2647
  flicking.trigger(event);
2633
2648
  if (event.isCanceled()) {
2634
2649
  throw new FlickingError(MESSAGE.STOP_CALLED_BY_USER, CODE.STOP_CALLED_BY_USER);
@@ -2847,7 +2862,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2847
2862
  if (!activeAnchor || !anchorAtCamera) {
2848
2863
  return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
2849
2864
  }
2850
- var snapThreshold = this._calcSnapThreshold(position, activeAnchor);
2865
+ var snapThreshold = this._calcSnapThreshold(flicking.threshold, position, activeAnchor);
2851
2866
  var posDelta = flicking.animating ? state.delta : position - camera.position;
2852
2867
  var absPosDelta = Math.abs(posDelta);
2853
2868
  var snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
@@ -2934,7 +2949,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2934
2949
  var adjacentAnchor = (_a = posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) !== null && _a !== void 0 ? _a : anchorAtCamera;
2935
2950
  return adjacentAnchor;
2936
2951
  };
2937
- __proto._calcSnapThreshold = function (position, activeAnchor) {
2952
+ __proto._calcSnapThreshold = function (threshold, position, activeAnchor) {
2938
2953
  var isNextDirection = position > activeAnchor.position;
2939
2954
  var panel = activeAnchor.panel;
2940
2955
  var panelSize = panel.size;
@@ -2945,7 +2960,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2945
2960
  * |<------>|<------------>|
2946
2961
  * [ |<-Anchor ]
2947
2962
  */
2948
- return isNextDirection ? panelSize - alignPos + panel.margin.next : alignPos + panel.margin.prev;
2963
+ return Math.max(threshold, isNextDirection ? panelSize - alignPos + panel.margin.next : alignPos + panel.margin.prev);
2949
2964
  };
2950
2965
  return SnapControl;
2951
2966
  }(Control);
@@ -3216,19 +3231,20 @@ var StrictControl = /*#__PURE__*/function (_super) {
3216
3231
  * @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
3217
3232
  */
3218
3233
  __proto.moveToPosition = function (position, duration, axesEvent) {
3234
+ var _a;
3219
3235
  var flicking = getFlickingAttached(this._flicking);
3220
3236
  var camera = flicking.camera;
3221
- var activePanel = this._activePanel;
3237
+ var currentPanel = (_a = this._nextPanel) !== null && _a !== void 0 ? _a : this._activePanel;
3222
3238
  var axesRange = this._controller.range;
3223
3239
  var indexRange = this._indexRange;
3224
3240
  var cameraRange = camera.range;
3225
3241
  var state = this._controller.state;
3226
3242
  var clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
3227
3243
  var anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
3228
- if (!anchorAtPosition || !activePanel) {
3244
+ if (!anchorAtPosition || !currentPanel) {
3229
3245
  return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
3230
3246
  }
3231
- var prevPos = activePanel.position;
3247
+ var prevPos = currentPanel.position;
3232
3248
  var posDelta = flicking.animating ? state.delta : position - camera.position;
3233
3249
  var isOverThreshold = Math.abs(posDelta) >= flicking.threshold;
3234
3250
  var adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
@@ -3245,7 +3261,7 @@ var StrictControl = /*#__PURE__*/function (_super) {
3245
3261
  var targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
3246
3262
  targetPanel = targetAnchor.panel;
3247
3263
  targetPos = targetAnchor.position;
3248
- } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
3264
+ } else if (isOverThreshold && anchorAtPosition.position !== currentPanel.position) {
3249
3265
  // Move to anchor at position
3250
3266
  targetPanel = anchorAtPosition.panel;
3251
3267
  targetPos = anchorAtPosition.position;
@@ -3983,6 +3999,19 @@ var Camera = /*#__PURE__*/function () {
3983
3999
  enumerable: false,
3984
4000
  configurable: true
3985
4001
  });
4002
+ Object.defineProperty(__proto, "panelOrder", {
4003
+ /**
4004
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS property applied to the camera element(`.flicking-camera`)
4005
+ * @ko 카메라 엘리먼트(`.flicking-camera`)에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성
4006
+ * @type {string}
4007
+ * @readonly
4008
+ */
4009
+ get: function () {
4010
+ return this._panelOrder;
4011
+ },
4012
+ enumerable: false,
4013
+ configurable: true
4014
+ });
3986
4015
  Object.defineProperty(__proto, "align", {
3987
4016
  // Options Getter
3988
4017
  /**
@@ -4014,6 +4043,7 @@ var Camera = /*#__PURE__*/function () {
4014
4043
  this._el = viewportEl.firstElementChild;
4015
4044
  this._checkTranslateSupport();
4016
4045
  this._updateMode();
4046
+ this.updatePanelOrder();
4017
4047
  return this;
4018
4048
  };
4019
4049
  /**
@@ -4135,11 +4165,13 @@ var Camera = /*#__PURE__*/function () {
4135
4165
  * @return {AnchorPoint | null}
4136
4166
  */
4137
4167
  __proto.findActiveAnchor = function () {
4168
+ var _a;
4138
4169
  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
- });
4170
+ var activePanel = flicking.control.activePanel;
4171
+ if (!activePanel) return null;
4172
+ return (_a = find(this._anchors, function (anchor) {
4173
+ return anchor.panel.index === activePanel.index;
4174
+ })) !== null && _a !== void 0 ? _a : this.findNearestAnchor(activePanel.position);
4143
4175
  };
4144
4176
  /**
4145
4177
  * Clamp the given position between camera's range
@@ -4256,6 +4288,24 @@ var Camera = /*#__PURE__*/function () {
4256
4288
  this.applyTransform();
4257
4289
  return this;
4258
4290
  };
4291
+ /**
4292
+ * Update direction to match the {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS property applied to the camera element
4293
+ * @ko 카메라 엘리먼트에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성에 맞게 방향을 업데이트합니다
4294
+ * @return {this}
4295
+ */
4296
+ __proto.updatePanelOrder = function () {
4297
+ var flicking = getFlickingAttached(this._flicking);
4298
+ if (!flicking.horizontal) return this;
4299
+ var el = this._el;
4300
+ var direction = getStyle(el).direction;
4301
+ if (direction !== this._panelOrder) {
4302
+ this._panelOrder = direction === ORDER.RTL ? ORDER.RTL : ORDER.LTR;
4303
+ if (flicking.initialized) {
4304
+ flicking.control.controller.updateDirection();
4305
+ }
4306
+ }
4307
+ return this;
4308
+ };
4259
4309
  /**
4260
4310
  * Reset the history of {@link Flicking#event:needPanel needPanel} events so it can be triggered again
4261
4311
  * @ko 발생한 {@link Flicking#event:needPanel needPanel} 이벤트들을 초기화하여 다시 발생할 수 있도록 합니다
@@ -4280,7 +4330,7 @@ var Camera = /*#__PURE__*/function () {
4280
4330
  var renderer = flicking.renderer;
4281
4331
  if (renderer.rendering || !flicking.initialized) return this;
4282
4332
  var actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
4283
- el.style[this._transform] = flicking.horizontal ? "translate(" + -actualPosition + "px)" : "translate(0, " + -actualPosition + "px)";
4333
+ el.style[this._transform] = flicking.horizontal ? "translate(" + (this._panelOrder === ORDER.RTL ? actualPosition : -actualPosition) + "px)" : "translate(0, " + -actualPosition + "px)";
4284
4334
  return this;
4285
4335
  };
4286
4336
  __proto._resetInternalValues = function () {
@@ -7528,15 +7578,24 @@ var Flicking = /*#__PURE__*/function (_super) {
7528
7578
  return [4 /*yield*/, renderer.forceRenderAllPanels()];
7529
7579
  case 1:
7530
7580
  _a.sent(); // Render all panel elements, to update sizes
7581
+ if (!this._initialized) {
7582
+ return [2 /*return*/];
7583
+ }
7584
+
7531
7585
  renderer.updatePanelSize();
7532
7586
  camera.updateAlignPos();
7533
7587
  camera.updateRange();
7534
7588
  camera.updateAnchors();
7535
7589
  camera.updateAdaptiveHeight();
7590
+ camera.updatePanelOrder();
7536
7591
  camera.updateOffset();
7537
7592
  return [4 /*yield*/, renderer.render()];
7538
7593
  case 2:
7539
7594
  _a.sent();
7595
+ if (!this._initialized) {
7596
+ return [2 /*return*/];
7597
+ }
7598
+
7540
7599
  if (control.animating) ; else {
7541
7600
  control.updatePosition(prevProgressInPanel);
7542
7601
  control.updateInput();
@@ -7773,7 +7832,7 @@ var Flicking = /*#__PURE__*/function (_super) {
7773
7832
  * Flicking.VERSION; // ex) 4.0.0
7774
7833
  * ```
7775
7834
  */
7776
- Flicking.VERSION = "4.11.0-snapshot";
7835
+ Flicking.VERSION = "4.11.3-beta.4";
7777
7836
  return Flicking;
7778
7837
  }(Component);
7779
7838
 
@@ -7991,5 +8050,5 @@ var parseAlign = function (alignVal) {
7991
8050
  * egjs projects are licensed under the MIT license
7992
8051
  */
7993
8052
 
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 };
8053
+ 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
8054
  //# sourceMappingURL=flicking.esm.js.map