@egjs/flicking 4.11.0 → 4.11.2-beta.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egjs/flicking",
3
- "version": "4.11.0",
3
+ "version": "4.11.2-beta.0",
4
4
  "description": "Everyday 30 million people experience. It's reliable, flexible and extendable carousel.",
5
5
  "main": "dist/flicking.cjs.js",
6
6
  "module": "dist/flicking.esm.js",
@@ -127,7 +127,7 @@
127
127
  "rollup-plugin-prototype-minify": "^1.1.0",
128
128
  "rollup-plugin-serve": "^1.1.0",
129
129
  "rollup-plugin-terser": "^7.0.2",
130
- "rollup-plugin-typescript2": "^0.30.0",
130
+ "rollup-plugin-typescript2": "^0.36.0",
131
131
  "rollup-plugin-visualizer": "^4.2.1",
132
132
  "sync-exec": "^0.6.2",
133
133
  "ts-mock-imports": "^1.3.3",
package/src/Flicking.ts CHANGED
@@ -1075,7 +1075,6 @@ class Flicking extends Component<FlickingEvents> {
1075
1075
 
1076
1076
  // Look at initial panel
1077
1077
  this._moveToInitialPanel();
1078
-
1079
1078
  if (this._autoResize) {
1080
1079
  this._autoResizer.enable();
1081
1080
  }
@@ -1509,6 +1508,7 @@ class Flicking extends Component<FlickingEvents> {
1509
1508
  camera.updateRange();
1510
1509
  camera.updateAnchors();
1511
1510
  camera.updateAdaptiveHeight();
1511
+ camera.updatePanelOrder();
1512
1512
  camera.updateOffset();
1513
1513
  await renderer.render();
1514
1514
 
@@ -9,8 +9,9 @@ import FlickingError from "../core/FlickingError";
9
9
  import Panel from "../core/panel/Panel";
10
10
  import AnchorPoint from "../core/AnchorPoint";
11
11
  import * as ERROR from "../const/error";
12
- import { ALIGN, CIRCULAR_FALLBACK, DIRECTION, EVENTS } from "../const/external";
13
- import { checkExistence, find, getFlickingAttached, getProgress, includes, parseAlign, toArray } from "../utils";
12
+ import { ALIGN, CIRCULAR_FALLBACK, DIRECTION, EVENTS, ORDER } from "../const/external";
13
+ import { checkExistence, find, getFlickingAttached, getProgress, getStyle, includes, parseAlign, toArray } from "../utils";
14
+ import { ValueOf } from "../type/internal";
14
15
 
15
16
  import { CameraMode, BoundCameraMode, CircularCameraMode, LinearCameraMode } from "./mode";
16
17
 
@@ -40,6 +41,7 @@ class Camera {
40
41
  private _visiblePanels: Panel[];
41
42
  private _anchors: AnchorPoint[];
42
43
  private _needPanelTriggered: { prev: boolean; next: boolean };
44
+ private _panelOrder: ValueOf<typeof ORDER>;
43
45
 
44
46
  // Internal states getter
45
47
  /**
@@ -217,6 +219,14 @@ class Camera {
217
219
  }
218
220
  }
219
221
 
222
+ /**
223
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS property applied to the camera element(`.flicking-camera`)
224
+ * @ko 카메라 엘리먼트(`.flicking-camera`)에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성
225
+ * @type {string}
226
+ * @readonly
227
+ */
228
+ public get panelOrder() { return this._panelOrder; }
229
+
220
230
  // Options Getter
221
231
  /**
222
232
  * A value indicating where the {@link Camera#alignPosition alignPosition} should be located at inside the viewport element
@@ -257,6 +267,7 @@ class Camera {
257
267
  this._checkTranslateSupport();
258
268
 
259
269
  this._updateMode();
270
+ this.updatePanelOrder();
260
271
 
261
272
  return this;
262
273
  }
@@ -530,6 +541,28 @@ class Camera {
530
541
  return this;
531
542
  }
532
543
 
544
+ /**
545
+ * Update direction to match the {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS property applied to the camera element
546
+ * @ko 카메라 엘리먼트에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성에 맞게 방향을 업데이트합니다
547
+ * @return {this}
548
+ */
549
+ public updatePanelOrder(): this {
550
+ const flicking = getFlickingAttached(this._flicking);
551
+
552
+ if (!flicking.horizontal) return this;
553
+
554
+ const el = this._el;
555
+ const direction = getStyle(el).direction;
556
+ if (direction !== this._panelOrder) {
557
+ this._panelOrder = direction === ORDER.RTL ? ORDER.RTL : ORDER.LTR;
558
+ if (flicking.initialized) {
559
+ flicking.control.controller.updateDirection();
560
+ }
561
+ }
562
+
563
+ return this;
564
+ }
565
+
533
566
  /**
534
567
  * Reset the history of {@link Flicking#event:needPanel needPanel} events so it can be triggered again
535
568
  * @ko 발생한 {@link Flicking#event:needPanel needPanel} 이벤트들을 초기화하여 다시 발생할 수 있도록 합니다
@@ -556,7 +589,7 @@ class Camera {
556
589
  const actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
557
590
 
558
591
  el.style[this._transform] = flicking.horizontal
559
- ? `translate(${-actualPosition}px)`
592
+ ? `translate(${this._panelOrder === ORDER.RTL ? actualPosition : -actualPosition}px)`
560
593
  : `translate(0, ${-actualPosition}px)`;
561
594
 
562
595
  return this;
@@ -110,3 +110,15 @@ export const CIRCULAR_FALLBACK = {
110
110
  LINEAR: "linear",
111
111
  BOUND: "bound"
112
112
  } as const;
113
+
114
+ /**
115
+ * 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`)
116
+ * @ko 카메라 엘리먼트(`.flicking-camera`)에 적용된 {@link https://developer.mozilla.org/en-US/docs/Web/CSS/direction direction} CSS 속성을 구분하기 위한 객체
117
+ * @type {object}
118
+ * @property {string} LTR "ltr"
119
+ * @property {string} RTL "rtl"
120
+ */
121
+ export const ORDER = {
122
+ LTR: "ltr",
123
+ RTL: "rtl"
124
+ } as const;
@@ -8,6 +8,7 @@ import Flicking from "../Flicking";
8
8
  import FlickingError from "../core/FlickingError";
9
9
  import * as AXES from "../const/axes";
10
10
  import * as ERROR from "../const/error";
11
+ import { ORDER } from "../const/external";
11
12
  import { getFlickingAttached, parseBounce } from "../utils";
12
13
  import { ControlParams } from "../type/external";
13
14
 
@@ -150,7 +151,7 @@ class AxesController {
150
151
  threshold: 1,
151
152
  iOSEdgeSwipeThreshold: flicking.iOSEdgeSwipeThreshold,
152
153
  preventDefaultOnDrag: flicking.preventDefaultOnDrag,
153
- scale: flicking.horizontal ? [-1, 0] : [0, -1],
154
+ scale: flicking.horizontal ? [flicking.camera.panelOrder === ORDER.RTL ? 1 : -1, 0] : [0, -1],
154
155
  releaseOnScroll: true
155
156
  });
156
157
 
@@ -403,7 +404,7 @@ class AxesController {
403
404
  axes.disconnect(panInput);
404
405
  axes.connect(flicking.horizontal ? [AXES.POSITION_KEY, ""] : ["", AXES.POSITION_KEY], panInput);
405
406
 
406
- panInput.options.scale = flicking.horizontal ? [-1, 0] : [0, -1];
407
+ panInput.options.scale = flicking.horizontal ? [flicking.camera.panelOrder === ORDER.RTL ? 1 : -1, 0] : [0, -1];
407
408
  }
408
409
 
409
410
  private _resetInternalValues() {
@@ -23,6 +23,7 @@ abstract class Control {
23
23
  protected _flicking: Flicking | null;
24
24
  protected _controller: AxesController;
25
25
  protected _activePanel: Panel | null;
26
+ protected _nextPanel: Panel | null;
26
27
 
27
28
  /**
28
29
  * A controller that handles the {@link https://naver.github.io/egjs-axes/ @egjs/axes} events
@@ -317,6 +318,7 @@ abstract class Control {
317
318
  const flicking = getFlickingAttached(this._flicking);
318
319
 
319
320
  this._activePanel = newActivePanel;
321
+ this._nextPanel = null;
320
322
 
321
323
  flicking.camera.updateAdaptiveHeight();
322
324
 
@@ -357,6 +359,8 @@ abstract class Control {
357
359
  isTrusted: axesEvent?.isTrusted || false,
358
360
  direction: getDirection(activePanel?.position ?? camera.position, position)
359
361
  });
362
+
363
+ this._nextPanel = panel;
360
364
  flicking.trigger(event);
361
365
 
362
366
  if (event.isCanceled()) {
@@ -190,7 +190,7 @@ class StrictControl extends Control {
190
190
  public moveToPosition(position: number, duration: number, axesEvent?: OnRelease) {
191
191
  const flicking = getFlickingAttached(this._flicking);
192
192
  const camera = flicking.camera;
193
- const activePanel = this._activePanel;
193
+ const currentPanel = this._nextPanel ?? this._activePanel;
194
194
  const axesRange = this._controller.range;
195
195
  const indexRange = this._indexRange;
196
196
  const cameraRange = camera.range;
@@ -199,11 +199,11 @@ class StrictControl extends Control {
199
199
  const clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
200
200
  const anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
201
201
 
202
- if (!anchorAtPosition || !activePanel) {
202
+ if (!anchorAtPosition || !currentPanel) {
203
203
  return Promise.reject(new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE));
204
204
  }
205
205
 
206
- const prevPos = activePanel.position;
206
+ const prevPos = currentPanel.position;
207
207
  const posDelta = flicking.animating
208
208
  ? state.delta
209
209
  : position - camera.position;
@@ -233,7 +233,7 @@ class StrictControl extends Control {
233
233
 
234
234
  targetPanel = targetAnchor.panel;
235
235
  targetPos = targetAnchor.position;
236
- } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
236
+ } else if (isOverThreshold && anchorAtPosition.position !== currentPanel.position) {
237
237
  // Move to anchor at position
238
238
  targetPanel = anchorAtPosition.panel;
239
239
  targetPos = anchorAtPosition.position;
package/src/utils.ts CHANGED
@@ -313,15 +313,16 @@ export const getElementSize = ({
313
313
  useOffset: boolean;
314
314
  style: CSSStyleDeclaration;
315
315
  }): number => {
316
+ let size = 0;
316
317
  if (useFractionalSize) {
317
- const baseSize = parseFloat(horizontal ? style.width : style.height);
318
+ const baseSize = parseFloat(horizontal ? style.width : style.height) || 0;
318
319
  const isBorderBoxSizing = style.boxSizing === "border-box";
319
320
  const border = horizontal
320
321
  ? parseFloat(style.borderLeftWidth || "0") + parseFloat(style.borderRightWidth || "0")
321
322
  : parseFloat(style.borderTopWidth || "0") + parseFloat(style.borderBottomWidth || "0");
322
323
 
323
324
  if (isBorderBoxSizing) {
324
- return useOffset
325
+ size = useOffset
325
326
  ? baseSize
326
327
  : baseSize - border;
327
328
  } else {
@@ -329,17 +330,19 @@ export const getElementSize = ({
329
330
  ? parseFloat(style.paddingLeft || "0") + parseFloat(style.paddingRight || "0")
330
331
  : parseFloat(style.paddingTop || "0") + parseFloat(style.paddingBottom || "0");
331
332
 
332
- return useOffset
333
+ size = useOffset
333
334
  ? baseSize + padding + border
334
335
  : baseSize + padding;
335
336
  }
336
337
  } else {
337
338
  const sizeStr = horizontal ? "Width" : "Height";
338
339
 
339
- return useOffset
340
+ size = useOffset
340
341
  ? el[`offset${sizeStr}`]
341
342
  : el[`client${sizeStr}`];
342
343
  }
344
+
345
+ return Math.max(size, 0);
343
346
  };
344
347
 
345
348
  export const setPrototypeOf = Object.setPrototypeOf || ((obj, proto) => {