@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.
@@ -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
8
8
  */
9
9
  'use strict';
10
10
 
@@ -12,7 +12,7 @@ var Component = require('@egjs/component');
12
12
  var Axes = require('@egjs/axes');
13
13
  var ImReady = require('@egjs/imready');
14
14
 
15
- /*! *****************************************************************************
15
+ /******************************************************************************
16
16
  Copyright (c) Microsoft Corporation.
17
17
 
18
18
  Permission to use, copy, modify, and/or distribute this software for any
@@ -26,7 +26,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26
26
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27
27
  PERFORMANCE OF THIS SOFTWARE.
28
28
  ***************************************************************************** */
29
- /* global Reflect, Promise */
29
+ /* global Reflect, Promise, SuppressedError, Symbol */
30
30
 
31
31
  var extendStatics = function (d, b) {
32
32
  extendStatics = Object.setPrototypeOf || {
@@ -111,7 +111,7 @@ function __generator(thisArg, body) {
111
111
  }
112
112
  function step(op) {
113
113
  if (f) throw new TypeError("Generator is already executing.");
114
- while (_) try {
114
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
115
115
  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;
116
116
  if (y = 0, t) op = [op[0] & 2, t.value];
117
117
  switch (op[0]) {
@@ -215,6 +215,10 @@ function __spread() {
215
215
  for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
216
216
  return ar;
217
217
  }
218
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
219
+ var e = new Error(message);
220
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
221
+ };
218
222
 
219
223
  /*
220
224
  * Copyright (c) 2015 NAVER Corp.
@@ -398,6 +402,17 @@ var CIRCULAR_FALLBACK = {
398
402
  LINEAR: "linear",
399
403
  BOUND: "bound"
400
404
  };
405
+ /**
406
+ * 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`)
407
+ * @ko 카메라 엘리먼트(`.flicking-camera`)에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성을 구분하기 위한 객체
408
+ * @type {object}
409
+ * @property {string} LTR "ltr"
410
+ * @property {string} RTL "rtl"
411
+ */
412
+ var ORDER = {
413
+ LTR: "ltr",
414
+ RTL: "rtl"
415
+ };
401
416
 
402
417
  // eslint-disable-next-line @typescript-eslint/ban-types
403
418
  var merge = function (target) {
@@ -691,20 +706,22 @@ var getElementSize = function (_a) {
691
706
  useFractionalSize = _a.useFractionalSize,
692
707
  useOffset = _a.useOffset,
693
708
  style = _a.style;
709
+ var size = 0;
694
710
  if (useFractionalSize) {
695
- var baseSize = parseFloat(horizontal ? style.width : style.height);
711
+ var baseSize = parseFloat(horizontal ? style.width : style.height) || 0;
696
712
  var isBorderBoxSizing = style.boxSizing === "border-box";
697
713
  var border = horizontal ? parseFloat(style.borderLeftWidth || "0") + parseFloat(style.borderRightWidth || "0") : parseFloat(style.borderTopWidth || "0") + parseFloat(style.borderBottomWidth || "0");
698
714
  if (isBorderBoxSizing) {
699
- return useOffset ? baseSize : baseSize - border;
715
+ size = useOffset ? baseSize : baseSize - border;
700
716
  } else {
701
717
  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;
718
+ size = useOffset ? baseSize + padding + border : baseSize + padding;
703
719
  }
704
720
  } else {
705
721
  var sizeStr = horizontal ? "Width" : "Height";
706
- return useOffset ? el["offset" + sizeStr] : el["client" + sizeStr];
722
+ size = useOffset ? el["offset" + sizeStr] : el["client" + sizeStr];
707
723
  }
724
+ return Math.max(size, 0);
708
725
  };
709
726
  var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
710
727
  obj.__proto__ = proto;
@@ -2088,7 +2105,7 @@ var AxesController = /*#__PURE__*/function () {
2088
2105
  threshold: 1,
2089
2106
  iOSEdgeSwipeThreshold: flicking.iOSEdgeSwipeThreshold,
2090
2107
  preventDefaultOnDrag: flicking.preventDefaultOnDrag,
2091
- scale: flicking.horizontal ? [-1, 0] : [0, -1],
2108
+ scale: flicking.horizontal ? [flicking.camera.panelOrder === ORDER.RTL ? 1 : -1, 0] : [0, -1],
2092
2109
  releaseOnScroll: true
2093
2110
  });
2094
2111
  var axes = this._axes;
@@ -2313,7 +2330,7 @@ var AxesController = /*#__PURE__*/function () {
2313
2330
  var panInput = this._panInput;
2314
2331
  axes.disconnect(panInput);
2315
2332
  axes.connect(flicking.horizontal ? [POSITION_KEY, ""] : ["", POSITION_KEY], panInput);
2316
- panInput.options.scale = flicking.horizontal ? [-1, 0] : [0, -1];
2333
+ panInput.options.scale = flicking.horizontal ? [flicking.camera.panelOrder === ORDER.RTL ? 1 : -1, 0] : [0, -1];
2317
2334
  };
2318
2335
  __proto._resetInternalValues = function () {
2319
2336
  this._flicking = null;
@@ -2578,7 +2595,7 @@ var Control = /*#__PURE__*/function () {
2578
2595
  var position;
2579
2596
  return __generator(this, function (_c) {
2580
2597
  position = this._getPosition(panel, direction);
2581
- this._triggerIndexChangeEvent(panel, panel.position, axesEvent);
2598
+ this._triggerIndexChangeEvent(panel, panel.position, axesEvent, direction);
2582
2599
  return [2 /*return*/, this._animateToPosition({
2583
2600
  position: position,
2584
2601
  duration: duration,
@@ -2595,6 +2612,7 @@ var Control = /*#__PURE__*/function () {
2595
2612
  var _a;
2596
2613
  var flicking = getFlickingAttached(this._flicking);
2597
2614
  this._activePanel = newActivePanel;
2615
+ this._nextPanel = null;
2598
2616
  flicking.camera.updateAdaptiveHeight();
2599
2617
  if (newActivePanel !== prevActivePanel) {
2600
2618
  flicking.trigger(new Component.ComponentEvent(EVENTS.CHANGED, {
@@ -2619,7 +2637,7 @@ var Control = /*#__PURE__*/function () {
2619
2637
  this._activePanel = control._activePanel;
2620
2638
  this._controller = control._controller;
2621
2639
  };
2622
- __proto._triggerIndexChangeEvent = function (panel, position, axesEvent) {
2640
+ __proto._triggerIndexChangeEvent = function (panel, position, axesEvent, direction) {
2623
2641
  var _a;
2624
2642
  var flicking = getFlickingAttached(this._flicking);
2625
2643
  var triggeringEvent = panel !== this._activePanel ? EVENTS.WILL_CHANGE : EVENTS.WILL_RESTORE;
@@ -2629,8 +2647,9 @@ var Control = /*#__PURE__*/function () {
2629
2647
  index: panel.index,
2630
2648
  panel: panel,
2631
2649
  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)
2650
+ 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
2651
  });
2652
+ this._nextPanel = panel;
2634
2653
  flicking.trigger(event);
2635
2654
  if (event.isCanceled()) {
2636
2655
  throw new FlickingError(MESSAGE.STOP_CALLED_BY_USER, CODE.STOP_CALLED_BY_USER);
@@ -2849,7 +2868,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2849
2868
  if (!activeAnchor || !anchorAtCamera) {
2850
2869
  return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
2851
2870
  }
2852
- var snapThreshold = this._calcSnapThreshold(position, activeAnchor);
2871
+ var snapThreshold = this._calcSnapThreshold(flicking.threshold, position, activeAnchor);
2853
2872
  var posDelta = flicking.animating ? state.delta : position - camera.position;
2854
2873
  var absPosDelta = Math.abs(posDelta);
2855
2874
  var snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
@@ -2936,7 +2955,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2936
2955
  var adjacentAnchor = (_a = posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) !== null && _a !== void 0 ? _a : anchorAtCamera;
2937
2956
  return adjacentAnchor;
2938
2957
  };
2939
- __proto._calcSnapThreshold = function (position, activeAnchor) {
2958
+ __proto._calcSnapThreshold = function (threshold, position, activeAnchor) {
2940
2959
  var isNextDirection = position > activeAnchor.position;
2941
2960
  var panel = activeAnchor.panel;
2942
2961
  var panelSize = panel.size;
@@ -2947,7 +2966,7 @@ var SnapControl = /*#__PURE__*/function (_super) {
2947
2966
  * |<------>|<------------>|
2948
2967
  * [ |<-Anchor ]
2949
2968
  */
2950
- return isNextDirection ? panelSize - alignPos + panel.margin.next : alignPos + panel.margin.prev;
2969
+ return Math.max(threshold, isNextDirection ? panelSize - alignPos + panel.margin.next : alignPos + panel.margin.prev);
2951
2970
  };
2952
2971
  return SnapControl;
2953
2972
  }(Control);
@@ -3218,19 +3237,20 @@ var StrictControl = /*#__PURE__*/function (_super) {
3218
3237
  * @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
3219
3238
  */
3220
3239
  __proto.moveToPosition = function (position, duration, axesEvent) {
3240
+ var _a;
3221
3241
  var flicking = getFlickingAttached(this._flicking);
3222
3242
  var camera = flicking.camera;
3223
- var activePanel = this._activePanel;
3243
+ var currentPanel = (_a = this._nextPanel) !== null && _a !== void 0 ? _a : this._activePanel;
3224
3244
  var axesRange = this._controller.range;
3225
3245
  var indexRange = this._indexRange;
3226
3246
  var cameraRange = camera.range;
3227
3247
  var state = this._controller.state;
3228
3248
  var clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
3229
3249
  var anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
3230
- if (!anchorAtPosition || !activePanel) {
3250
+ if (!anchorAtPosition || !currentPanel) {
3231
3251
  return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
3232
3252
  }
3233
- var prevPos = activePanel.position;
3253
+ var prevPos = currentPanel.position;
3234
3254
  var posDelta = flicking.animating ? state.delta : position - camera.position;
3235
3255
  var isOverThreshold = Math.abs(posDelta) >= flicking.threshold;
3236
3256
  var adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
@@ -3247,7 +3267,7 @@ var StrictControl = /*#__PURE__*/function (_super) {
3247
3267
  var targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
3248
3268
  targetPanel = targetAnchor.panel;
3249
3269
  targetPos = targetAnchor.position;
3250
- } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
3270
+ } else if (isOverThreshold && anchorAtPosition.position !== currentPanel.position) {
3251
3271
  // Move to anchor at position
3252
3272
  targetPanel = anchorAtPosition.panel;
3253
3273
  targetPos = anchorAtPosition.position;
@@ -3985,6 +4005,19 @@ var Camera = /*#__PURE__*/function () {
3985
4005
  enumerable: false,
3986
4006
  configurable: true
3987
4007
  });
4008
+ Object.defineProperty(__proto, "panelOrder", {
4009
+ /**
4010
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS property applied to the camera element(`.flicking-camera`)
4011
+ * @ko 카메라 엘리먼트(`.flicking-camera`)에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성
4012
+ * @type {string}
4013
+ * @readonly
4014
+ */
4015
+ get: function () {
4016
+ return this._panelOrder;
4017
+ },
4018
+ enumerable: false,
4019
+ configurable: true
4020
+ });
3988
4021
  Object.defineProperty(__proto, "align", {
3989
4022
  // Options Getter
3990
4023
  /**
@@ -4016,6 +4049,7 @@ var Camera = /*#__PURE__*/function () {
4016
4049
  this._el = viewportEl.firstElementChild;
4017
4050
  this._checkTranslateSupport();
4018
4051
  this._updateMode();
4052
+ this.updatePanelOrder();
4019
4053
  return this;
4020
4054
  };
4021
4055
  /**
@@ -4137,11 +4171,13 @@ var Camera = /*#__PURE__*/function () {
4137
4171
  * @return {AnchorPoint | null}
4138
4172
  */
4139
4173
  __proto.findActiveAnchor = function () {
4174
+ var _a;
4140
4175
  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
- });
4176
+ var activePanel = flicking.control.activePanel;
4177
+ if (!activePanel) return null;
4178
+ return (_a = find(this._anchors, function (anchor) {
4179
+ return anchor.panel.index === activePanel.index;
4180
+ })) !== null && _a !== void 0 ? _a : this.findNearestAnchor(activePanel.position);
4145
4181
  };
4146
4182
  /**
4147
4183
  * Clamp the given position between camera's range
@@ -4258,6 +4294,24 @@ var Camera = /*#__PURE__*/function () {
4258
4294
  this.applyTransform();
4259
4295
  return this;
4260
4296
  };
4297
+ /**
4298
+ * Update direction to match the {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS property applied to the camera element
4299
+ * @ko 카메라 엘리먼트에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성에 맞게 방향을 업데이트합니다
4300
+ * @return {this}
4301
+ */
4302
+ __proto.updatePanelOrder = function () {
4303
+ var flicking = getFlickingAttached(this._flicking);
4304
+ if (!flicking.horizontal) return this;
4305
+ var el = this._el;
4306
+ var direction = getStyle(el).direction;
4307
+ if (direction !== this._panelOrder) {
4308
+ this._panelOrder = direction === ORDER.RTL ? ORDER.RTL : ORDER.LTR;
4309
+ if (flicking.initialized) {
4310
+ flicking.control.controller.updateDirection();
4311
+ }
4312
+ }
4313
+ return this;
4314
+ };
4261
4315
  /**
4262
4316
  * Reset the history of {@link Flicking#event:needPanel needPanel} events so it can be triggered again
4263
4317
  * @ko 발생한 {@link Flicking#event:needPanel needPanel} 이벤트들을 초기화하여 다시 발생할 수 있도록 합니다
@@ -4282,7 +4336,7 @@ var Camera = /*#__PURE__*/function () {
4282
4336
  var renderer = flicking.renderer;
4283
4337
  if (renderer.rendering || !flicking.initialized) return this;
4284
4338
  var actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
4285
- el.style[this._transform] = flicking.horizontal ? "translate(" + -actualPosition + "px)" : "translate(0, " + -actualPosition + "px)";
4339
+ el.style[this._transform] = flicking.horizontal ? "translate(" + (this._panelOrder === ORDER.RTL ? actualPosition : -actualPosition) + "px)" : "translate(0, " + -actualPosition + "px)";
4286
4340
  return this;
4287
4341
  };
4288
4342
  __proto._resetInternalValues = function () {
@@ -7530,15 +7584,24 @@ var Flicking = /*#__PURE__*/function (_super) {
7530
7584
  return [4 /*yield*/, renderer.forceRenderAllPanels()];
7531
7585
  case 1:
7532
7586
  _a.sent(); // Render all panel elements, to update sizes
7587
+ if (!this._initialized) {
7588
+ return [2 /*return*/];
7589
+ }
7590
+
7533
7591
  renderer.updatePanelSize();
7534
7592
  camera.updateAlignPos();
7535
7593
  camera.updateRange();
7536
7594
  camera.updateAnchors();
7537
7595
  camera.updateAdaptiveHeight();
7596
+ camera.updatePanelOrder();
7538
7597
  camera.updateOffset();
7539
7598
  return [4 /*yield*/, renderer.render()];
7540
7599
  case 2:
7541
7600
  _a.sent();
7601
+ if (!this._initialized) {
7602
+ return [2 /*return*/];
7603
+ }
7604
+
7542
7605
  if (control.animating) ; else {
7543
7606
  control.updatePosition(prevProgressInPanel);
7544
7607
  control.updateInput();
@@ -7775,7 +7838,7 @@ var Flicking = /*#__PURE__*/function (_super) {
7775
7838
  * Flicking.VERSION; // ex) 4.0.0
7776
7839
  * ```
7777
7840
  */
7778
- Flicking.VERSION = "4.11.0-snapshot";
7841
+ Flicking.VERSION = "4.11.3";
7779
7842
  return Flicking;
7780
7843
  }(Component);
7781
7844
 
@@ -8032,6 +8095,7 @@ var modules = {
8032
8095
  MOVE_TYPE: MOVE_TYPE,
8033
8096
  CLASS: CLASS,
8034
8097
  CIRCULAR_FALLBACK: CIRCULAR_FALLBACK,
8098
+ ORDER: ORDER,
8035
8099
  withFlickingMethods: withFlickingMethods,
8036
8100
  sync: sync,
8037
8101
  getRenderingPanels: getRenderingPanels,
@@ -8099,6 +8163,7 @@ exports.IdleState = IdleState;
8099
8163
  exports.LinearCameraMode = LinearCameraMode;
8100
8164
  exports.MOVE_TYPE = MOVE_TYPE;
8101
8165
  exports.NormalRenderingStrategy = NormalRenderingStrategy;
8166
+ exports.ORDER = ORDER;
8102
8167
  exports.Panel = Panel;
8103
8168
  exports.Renderer = Renderer;
8104
8169
  exports.SnapControl = SnapControl;