@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.
@@ -1,6 +1,7 @@
1
1
  import Flicking, { FlickingOptions } from "../Flicking";
2
2
  import Panel from "../core/panel/Panel";
3
3
  import AnchorPoint from "../core/AnchorPoint";
4
+ import { ValueOf } from "../type/internal";
4
5
  import { CameraMode } from "./mode";
5
6
  export interface CameraOptions {
6
7
  align: FlickingOptions["align"];
@@ -20,6 +21,7 @@ declare class Camera {
20
21
  private _visiblePanels;
21
22
  private _anchors;
22
23
  private _needPanelTriggered;
24
+ private _panelOrder;
23
25
  get element(): HTMLElement;
24
26
  get children(): HTMLElement[];
25
27
  get position(): number;
@@ -49,6 +51,10 @@ declare class Camera {
49
51
  get atEdge(): boolean;
50
52
  get size(): number;
51
53
  get progress(): number;
54
+ get panelOrder(): ValueOf<{
55
+ readonly LTR: "ltr";
56
+ readonly RTL: "rtl";
57
+ }>;
52
58
  get align(): FlickingOptions["align"];
53
59
  set align(val: FlickingOptions["align"]);
54
60
  constructor(flicking: Flicking, { align }?: Partial<CameraOptions>);
@@ -69,6 +75,7 @@ declare class Camera {
69
75
  updateAnchors(): this;
70
76
  updateAdaptiveHeight(): void;
71
77
  updateOffset(): this;
78
+ updatePanelOrder(): this;
72
79
  resetNeedPanelHistory(): this;
73
80
  applyTransform(): this;
74
81
  private _resetInternalValues;
@@ -42,3 +42,7 @@ export declare const CIRCULAR_FALLBACK: {
42
42
  readonly LINEAR: "linear";
43
43
  readonly BOUND: "bound";
44
44
  };
45
+ export declare const ORDER: {
46
+ readonly LTR: "ltr";
47
+ readonly RTL: "rtl";
48
+ };
@@ -8,6 +8,7 @@ declare abstract class Control {
8
8
  protected _flicking: Flicking | null;
9
9
  protected _controller: AxesController;
10
10
  protected _activePanel: Panel | null;
11
+ protected _nextPanel: Panel | null;
11
12
  get controller(): AxesController;
12
13
  get activeIndex(): number;
13
14
  get activePanel(): Panel;
@@ -32,7 +33,7 @@ declare abstract class Control {
32
33
  }): Promise<void>;
33
34
  setActive(newActivePanel: Panel, prevActivePanel: Panel | null, isTrusted: boolean): void;
34
35
  copy(control: Control): void;
35
- protected _triggerIndexChangeEvent(panel: Panel, position: number, axesEvent?: OnRelease): void;
36
+ protected _triggerIndexChangeEvent(panel: Panel, position: number, axesEvent?: OnRelease, direction?: ValueOf<typeof DIRECTION>): void;
36
37
  protected _animateToPosition({ position, duration, newActivePanel, axesEvent }: {
37
38
  position: number;
38
39
  duration: 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.11.0-snapshot
7
+ version: 4.11.3-beta.4
8
8
  */
9
9
  'use strict';
10
10
 
@@ -398,6 +398,17 @@ var CIRCULAR_FALLBACK = {
398
398
  LINEAR: "linear",
399
399
  BOUND: "bound"
400
400
  };
401
+ /**
402
+ * 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`)
403
+ * @ko 카메라 엘리먼트(`.flicking-camera`)에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성을 구분하기 위한 객체
404
+ * @type {object}
405
+ * @property {string} LTR "ltr"
406
+ * @property {string} RTL "rtl"
407
+ */
408
+ var ORDER = {
409
+ LTR: "ltr",
410
+ RTL: "rtl"
411
+ };
401
412
 
402
413
  // eslint-disable-next-line @typescript-eslint/ban-types
403
414
  var merge = function (target) {
@@ -691,20 +702,22 @@ var getElementSize = function (_a) {
691
702
  useFractionalSize = _a.useFractionalSize,
692
703
  useOffset = _a.useOffset,
693
704
  style = _a.style;
705
+ var size = 0;
694
706
  if (useFractionalSize) {
695
- var baseSize = parseFloat(horizontal ? style.width : style.height);
707
+ var baseSize = parseFloat(horizontal ? style.width : style.height) || 0;
696
708
  var isBorderBoxSizing = style.boxSizing === "border-box";
697
709
  var border = horizontal ? parseFloat(style.borderLeftWidth || "0") + parseFloat(style.borderRightWidth || "0") : parseFloat(style.borderTopWidth || "0") + parseFloat(style.borderBottomWidth || "0");
698
710
  if (isBorderBoxSizing) {
699
- return useOffset ? baseSize : baseSize - border;
711
+ size = useOffset ? baseSize : baseSize - border;
700
712
  } else {
701
713
  var padding = horizontal ? parseFloat(style.paddingLeft || "0") + parseFloat(style.paddingRight || "0") : parseFloat(style.paddingTop || "0") + parseFloat(style.paddingBottom || "0");
702
- return useOffset ? baseSize + padding + border : baseSize + padding;
714
+ size = useOffset ? baseSize + padding + border : baseSize + padding;
703
715
  }
704
716
  } else {
705
717
  var sizeStr = horizontal ? "Width" : "Height";
706
- return useOffset ? el["offset" + sizeStr] : el["client" + sizeStr];
718
+ size = useOffset ? el["offset" + sizeStr] : el["client" + sizeStr];
707
719
  }
720
+ return Math.max(size, 0);
708
721
  };
709
722
  var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
710
723
  obj.__proto__ = proto;
@@ -2088,7 +2101,7 @@ var AxesController = /*#__PURE__*/function () {
2088
2101
  threshold: 1,
2089
2102
  iOSEdgeSwipeThreshold: flicking.iOSEdgeSwipeThreshold,
2090
2103
  preventDefaultOnDrag: flicking.preventDefaultOnDrag,
2091
- scale: flicking.horizontal ? [-1, 0] : [0, -1],
2104
+ scale: flicking.horizontal ? [flicking.camera.panelOrder === ORDER.RTL ? 1 : -1, 0] : [0, -1],
2092
2105
  releaseOnScroll: true
2093
2106
  });
2094
2107
  var axes = this._axes;
@@ -2313,7 +2326,7 @@ var AxesController = /*#__PURE__*/function () {
2313
2326
  var panInput = this._panInput;
2314
2327
  axes.disconnect(panInput);
2315
2328
  axes.connect(flicking.horizontal ? [POSITION_KEY, ""] : ["", POSITION_KEY], panInput);
2316
- panInput.options.scale = flicking.horizontal ? [-1, 0] : [0, -1];
2329
+ panInput.options.scale = flicking.horizontal ? [flicking.camera.panelOrder === ORDER.RTL ? 1 : -1, 0] : [0, -1];
2317
2330
  };
2318
2331
  __proto._resetInternalValues = function () {
2319
2332
  this._flicking = null;
@@ -2578,7 +2591,7 @@ var Control = /*#__PURE__*/function () {
2578
2591
  var position;
2579
2592
  return __generator(this, function (_c) {
2580
2593
  position = this._getPosition(panel, direction);
2581
- this._triggerIndexChangeEvent(panel, panel.position, axesEvent);
2594
+ this._triggerIndexChangeEvent(panel, panel.position, axesEvent, direction);
2582
2595
  return [2 /*return*/, this._animateToPosition({
2583
2596
  position: position,
2584
2597
  duration: duration,
@@ -2595,6 +2608,7 @@ var Control = /*#__PURE__*/function () {
2595
2608
  var _a;
2596
2609
  var flicking = getFlickingAttached(this._flicking);
2597
2610
  this._activePanel = newActivePanel;
2611
+ this._nextPanel = null;
2598
2612
  flicking.camera.updateAdaptiveHeight();
2599
2613
  if (newActivePanel !== prevActivePanel) {
2600
2614
  flicking.trigger(new Component.ComponentEvent(EVENTS.CHANGED, {
@@ -2619,7 +2633,7 @@ var Control = /*#__PURE__*/function () {
2619
2633
  this._activePanel = control._activePanel;
2620
2634
  this._controller = control._controller;
2621
2635
  };
2622
- __proto._triggerIndexChangeEvent = function (panel, position, axesEvent) {
2636
+ __proto._triggerIndexChangeEvent = function (panel, position, axesEvent, direction) {
2623
2637
  var _a;
2624
2638
  var flicking = getFlickingAttached(this._flicking);
2625
2639
  var triggeringEvent = panel !== this._activePanel ? EVENTS.WILL_CHANGE : EVENTS.WILL_RESTORE;
@@ -2629,8 +2643,9 @@ var Control = /*#__PURE__*/function () {
2629
2643
  index: panel.index,
2630
2644
  panel: panel,
2631
2645
  isTrusted: (axesEvent === null || axesEvent === void 0 ? void 0 : axesEvent.isTrusted) || false,
2632
- direction: getDirection((_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.position) !== null && _a !== void 0 ? _a : camera.position, position)
2646
+ 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)
2633
2647
  });
2648
+ this._nextPanel = panel;
2634
2649
  flicking.trigger(event);
2635
2650
  if (event.isCanceled()) {
2636
2651
  throw new FlickingError(MESSAGE.STOP_CALLED_BY_USER, CODE.STOP_CALLED_BY_USER);
@@ -2849,7 +2864,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2849
2864
  if (!activeAnchor || !anchorAtCamera) {
2850
2865
  return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
2851
2866
  }
2852
- var snapThreshold = this._calcSnapThreshold(position, activeAnchor);
2867
+ var snapThreshold = this._calcSnapThreshold(flicking.threshold, position, activeAnchor);
2853
2868
  var posDelta = flicking.animating ? state.delta : position - camera.position;
2854
2869
  var absPosDelta = Math.abs(posDelta);
2855
2870
  var snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
@@ -2936,7 +2951,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2936
2951
  var adjacentAnchor = (_a = posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) !== null && _a !== void 0 ? _a : anchorAtCamera;
2937
2952
  return adjacentAnchor;
2938
2953
  };
2939
- __proto._calcSnapThreshold = function (position, activeAnchor) {
2954
+ __proto._calcSnapThreshold = function (threshold, position, activeAnchor) {
2940
2955
  var isNextDirection = position > activeAnchor.position;
2941
2956
  var panel = activeAnchor.panel;
2942
2957
  var panelSize = panel.size;
@@ -2947,7 +2962,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2947
2962
  * |<------>|<------------>|
2948
2963
  * [ |<-Anchor ]
2949
2964
  */
2950
- return isNextDirection ? panelSize - alignPos + panel.margin.next : alignPos + panel.margin.prev;
2965
+ return Math.max(threshold, isNextDirection ? panelSize - alignPos + panel.margin.next : alignPos + panel.margin.prev);
2951
2966
  };
2952
2967
  return SnapControl;
2953
2968
  }(Control);
@@ -3218,19 +3233,20 @@ var StrictControl = /*#__PURE__*/function (_super) {
3218
3233
  * @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
3219
3234
  */
3220
3235
  __proto.moveToPosition = function (position, duration, axesEvent) {
3236
+ var _a;
3221
3237
  var flicking = getFlickingAttached(this._flicking);
3222
3238
  var camera = flicking.camera;
3223
- var activePanel = this._activePanel;
3239
+ var currentPanel = (_a = this._nextPanel) !== null && _a !== void 0 ? _a : this._activePanel;
3224
3240
  var axesRange = this._controller.range;
3225
3241
  var indexRange = this._indexRange;
3226
3242
  var cameraRange = camera.range;
3227
3243
  var state = this._controller.state;
3228
3244
  var clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
3229
3245
  var anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
3230
- if (!anchorAtPosition || !activePanel) {
3246
+ if (!anchorAtPosition || !currentPanel) {
3231
3247
  return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
3232
3248
  }
3233
- var prevPos = activePanel.position;
3249
+ var prevPos = currentPanel.position;
3234
3250
  var posDelta = flicking.animating ? state.delta : position - camera.position;
3235
3251
  var isOverThreshold = Math.abs(posDelta) >= flicking.threshold;
3236
3252
  var adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
@@ -3247,7 +3263,7 @@ var StrictControl = /*#__PURE__*/function (_super) {
3247
3263
  var targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
3248
3264
  targetPanel = targetAnchor.panel;
3249
3265
  targetPos = targetAnchor.position;
3250
- } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
3266
+ } else if (isOverThreshold && anchorAtPosition.position !== currentPanel.position) {
3251
3267
  // Move to anchor at position
3252
3268
  targetPanel = anchorAtPosition.panel;
3253
3269
  targetPos = anchorAtPosition.position;
@@ -3985,6 +4001,19 @@ var Camera = /*#__PURE__*/function () {
3985
4001
  enumerable: false,
3986
4002
  configurable: true
3987
4003
  });
4004
+ Object.defineProperty(__proto, "panelOrder", {
4005
+ /**
4006
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS property applied to the camera element(`.flicking-camera`)
4007
+ * @ko 카메라 엘리먼트(`.flicking-camera`)에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성
4008
+ * @type {string}
4009
+ * @readonly
4010
+ */
4011
+ get: function () {
4012
+ return this._panelOrder;
4013
+ },
4014
+ enumerable: false,
4015
+ configurable: true
4016
+ });
3988
4017
  Object.defineProperty(__proto, "align", {
3989
4018
  // Options Getter
3990
4019
  /**
@@ -4016,6 +4045,7 @@ var Camera = /*#__PURE__*/function () {
4016
4045
  this._el = viewportEl.firstElementChild;
4017
4046
  this._checkTranslateSupport();
4018
4047
  this._updateMode();
4048
+ this.updatePanelOrder();
4019
4049
  return this;
4020
4050
  };
4021
4051
  /**
@@ -4137,11 +4167,13 @@ var Camera = /*#__PURE__*/function () {
4137
4167
  * @return {AnchorPoint | null}
4138
4168
  */
4139
4169
  __proto.findActiveAnchor = function () {
4170
+ var _a;
4140
4171
  var flicking = getFlickingAttached(this._flicking);
4141
- var activeIndex = flicking.control.activeIndex;
4142
- return find(this._anchors, function (anchor) {
4143
- return anchor.panel.index === activeIndex;
4144
- });
4172
+ var activePanel = flicking.control.activePanel;
4173
+ if (!activePanel) return null;
4174
+ return (_a = find(this._anchors, function (anchor) {
4175
+ return anchor.panel.index === activePanel.index;
4176
+ })) !== null && _a !== void 0 ? _a : this.findNearestAnchor(activePanel.position);
4145
4177
  };
4146
4178
  /**
4147
4179
  * Clamp the given position between camera's range
@@ -4258,6 +4290,24 @@ var Camera = /*#__PURE__*/function () {
4258
4290
  this.applyTransform();
4259
4291
  return this;
4260
4292
  };
4293
+ /**
4294
+ * Update direction to match the {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS property applied to the camera element
4295
+ * @ko 카메라 엘리먼트에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성에 맞게 방향을 업데이트합니다
4296
+ * @return {this}
4297
+ */
4298
+ __proto.updatePanelOrder = function () {
4299
+ var flicking = getFlickingAttached(this._flicking);
4300
+ if (!flicking.horizontal) return this;
4301
+ var el = this._el;
4302
+ var direction = getStyle(el).direction;
4303
+ if (direction !== this._panelOrder) {
4304
+ this._panelOrder = direction === ORDER.RTL ? ORDER.RTL : ORDER.LTR;
4305
+ if (flicking.initialized) {
4306
+ flicking.control.controller.updateDirection();
4307
+ }
4308
+ }
4309
+ return this;
4310
+ };
4261
4311
  /**
4262
4312
  * Reset the history of {@link Flicking#event:needPanel needPanel} events so it can be triggered again
4263
4313
  * @ko 발생한 {@link Flicking#event:needPanel needPanel} 이벤트들을 초기화하여 다시 발생할 수 있도록 합니다
@@ -4282,7 +4332,7 @@ var Camera = /*#__PURE__*/function () {
4282
4332
  var renderer = flicking.renderer;
4283
4333
  if (renderer.rendering || !flicking.initialized) return this;
4284
4334
  var actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
4285
- el.style[this._transform] = flicking.horizontal ? "translate(" + -actualPosition + "px)" : "translate(0, " + -actualPosition + "px)";
4335
+ el.style[this._transform] = flicking.horizontal ? "translate(" + (this._panelOrder === ORDER.RTL ? actualPosition : -actualPosition) + "px)" : "translate(0, " + -actualPosition + "px)";
4286
4336
  return this;
4287
4337
  };
4288
4338
  __proto._resetInternalValues = function () {
@@ -7530,15 +7580,24 @@ var Flicking = /*#__PURE__*/function (_super) {
7530
7580
  return [4 /*yield*/, renderer.forceRenderAllPanels()];
7531
7581
  case 1:
7532
7582
  _a.sent(); // Render all panel elements, to update sizes
7583
+ if (!this._initialized) {
7584
+ return [2 /*return*/];
7585
+ }
7586
+
7533
7587
  renderer.updatePanelSize();
7534
7588
  camera.updateAlignPos();
7535
7589
  camera.updateRange();
7536
7590
  camera.updateAnchors();
7537
7591
  camera.updateAdaptiveHeight();
7592
+ camera.updatePanelOrder();
7538
7593
  camera.updateOffset();
7539
7594
  return [4 /*yield*/, renderer.render()];
7540
7595
  case 2:
7541
7596
  _a.sent();
7597
+ if (!this._initialized) {
7598
+ return [2 /*return*/];
7599
+ }
7600
+
7542
7601
  if (control.animating) ; else {
7543
7602
  control.updatePosition(prevProgressInPanel);
7544
7603
  control.updateInput();
@@ -7775,7 +7834,7 @@ var Flicking = /*#__PURE__*/function (_super) {
7775
7834
  * Flicking.VERSION; // ex) 4.0.0
7776
7835
  * ```
7777
7836
  */
7778
- Flicking.VERSION = "4.11.0-snapshot";
7837
+ Flicking.VERSION = "4.11.3-beta.4";
7779
7838
  return Flicking;
7780
7839
  }(Component);
7781
7840
 
@@ -8032,6 +8091,7 @@ var modules = {
8032
8091
  MOVE_TYPE: MOVE_TYPE,
8033
8092
  CLASS: CLASS,
8034
8093
  CIRCULAR_FALLBACK: CIRCULAR_FALLBACK,
8094
+ ORDER: ORDER,
8035
8095
  withFlickingMethods: withFlickingMethods,
8036
8096
  sync: sync,
8037
8097
  getRenderingPanels: getRenderingPanels,
@@ -8099,6 +8159,7 @@ exports.IdleState = IdleState;
8099
8159
  exports.LinearCameraMode = LinearCameraMode;
8100
8160
  exports.MOVE_TYPE = MOVE_TYPE;
8101
8161
  exports.NormalRenderingStrategy = NormalRenderingStrategy;
8162
+ exports.ORDER = ORDER;
8102
8163
  exports.Panel = Panel;
8103
8164
  exports.Renderer = Renderer;
8104
8165
  exports.SnapControl = SnapControl;