@egjs/flicking 4.14.2-beta.0 → 4.14.2-beta.1

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.14.2-beta.0",
3
+ "version": "4.14.2-beta.1",
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",
package/src/Flicking.ts CHANGED
@@ -118,6 +118,8 @@ export interface FlickingOptions {
118
118
  | MoveTypeOptions<ValueOf<typeof MOVE_TYPE>>;
119
119
  threshold: number;
120
120
  dragThreshold: number;
121
+ animationThreshold: number;
122
+ useCSSOrderProperty: boolean;
121
123
  interruptable: boolean;
122
124
  bounce: number | string | [number | string, number | string];
123
125
  iOSEdgeSwipeThreshold: number;
@@ -200,6 +202,9 @@ class Flicking extends Component<FlickingEvents> {
200
202
  private _moveType: FlickingOptions["moveType"];
201
203
  private _threshold: FlickingOptions["threshold"];
202
204
  private _dragThreshold: FlickingOptions["dragThreshold"];
205
+ private _animationThreshold: FlickingOptions["animationThreshold"];
206
+ private _useCSSOrderProperty: FlickingOptions["useCSSOrderProperty"];
207
+
203
208
  private _interruptable: FlickingOptions["interruptable"];
204
209
  private _bounce: FlickingOptions["bounce"];
205
210
  private _iOSEdgeSwipeThreshold: FlickingOptions["iOSEdgeSwipeThreshold"];
@@ -703,6 +708,29 @@ class Flicking extends Component<FlickingEvents> {
703
708
  public get dragThreshold() {
704
709
  return this._dragThreshold;
705
710
  }
711
+ /**
712
+ * The minimum distance for animation to proceed. If the distance to be moved is less than `animationThreshold`, the movement proceeds immediately without animation (duration: 0).
713
+ * @ko animation이 진행되기 위한 최소한의 거리. 이동하려는 거리가 `animationThreshold`보다 적으면 애니메이션 없이(duration: 0) 즉시 이동한다.
714
+ * @type {number}
715
+ * @default 0.5
716
+ * @see {@link https://naver.github.io/egjs-flicking/Options#animationThreshold animationThreshold ( Options )}
717
+ */
718
+ public get animationThreshold() {
719
+ return this._animationThreshold;
720
+ }
721
+ /**
722
+ * When `circular` is used, the DOM order changes depending on the position. Using `useCSSOrderProperty` does not change the DOM order, but the `order` CSS property changes the order on the screen.
723
+ * When using `iframe`, you can prevent reloading when the DOM order changes.
724
+ * @ko `circular`를 사용한 경우 위치에 따라 DOM의 순서가 변경된다. `useCSSOrderProperty`를 사용하면 DOM의 순서는 변경되지 않지만 `order` css가 설정되면서 화면상 순서가 바뀐다.
725
+ * `iframe`을 사용하는 경우 DOM의 순서가 변경되면서 reload가 되는 것을 막을 수 있다.
726
+ * @type {boolean}
727
+ * @requires `circular`
728
+ * @default false
729
+ * @see {@link https://naver.github.io/egjs-flicking/Options#useCSSOrderProperty animationThreshold ( Options )}
730
+ */
731
+ public get useCSSOrderProperty() {
732
+ return this._useCSSOrderProperty;
733
+ }
706
734
 
707
735
  /**
708
736
  * Set animation to be interruptable by click/touch.
@@ -1117,6 +1145,12 @@ class Flicking extends Component<FlickingEvents> {
1117
1145
  panInput.options.threshold = val;
1118
1146
  }
1119
1147
  }
1148
+ public set animationThreshold(val: FlickingOptions["animationThreshold"]) {
1149
+ this._animationThreshold = val;
1150
+ }
1151
+ public set useCSSOrderProperty(val: FlickingOptions["useCSSOrderProperty"]) {
1152
+ this._useCSSOrderProperty = val;
1153
+ }
1120
1154
 
1121
1155
  public set interruptable(val: FlickingOptions["interruptable"]) {
1122
1156
  this._interruptable = val;
@@ -1291,7 +1325,9 @@ class Flicking extends Component<FlickingEvents> {
1291
1325
  useFractionalSize = false,
1292
1326
  externalRenderer = null,
1293
1327
  renderExternal = null,
1294
- optimizeSizeUpdate = false
1328
+ optimizeSizeUpdate = false,
1329
+ animationThreshold = 0.5,
1330
+ useCSSOrderProperty = false,
1295
1331
  }: Partial<FlickingOptions> = {}) {
1296
1332
  super();
1297
1333
 
@@ -1340,6 +1376,8 @@ class Flicking extends Component<FlickingEvents> {
1340
1376
  this._externalRenderer = externalRenderer;
1341
1377
  this._renderExternal = renderExternal;
1342
1378
  this._optimizeSizeUpdate = optimizeSizeUpdate;
1379
+ this._animationThreshold = animationThreshold;
1380
+ this._useCSSOrderProperty = useCSSOrderProperty;
1343
1381
 
1344
1382
  // Create core components
1345
1383
  this._viewport = new Viewport(this, getElement(root));
@@ -12,13 +12,17 @@ export default <T>(flicking: Flicking, diffResult: DiffResult<T>) => {
12
12
  map[prev] = current;
13
13
  return map;
14
14
  }, {});
15
+ const renderingPanels = flicking.panels
16
+ .filter(panel => !removedPanels[panel.index]);
17
+
18
+
19
+ if (!flicking.useCSSOrderProperty) {
20
+ // useCSSOrderProperty를 사용하게 되는 경우 sort를 하지 않는다.
21
+ renderingPanels.sort((panel1, panel2) => (panel1.position + panel1.offset) - (panel2.position + panel2.offset));
22
+ }
15
23
 
16
24
  return [
17
- ...flicking.panels
18
- .filter(panel => !removedPanels[panel.index])
19
- // Sort panels by position
20
- .sort((panel1, panel2) => (panel1.position + panel1.offset) - (panel2.position + panel2.offset))
21
- .map(panel => diffResult.list[maintainedMap[panel.index]]),
25
+ ...renderingPanels.map(panel => diffResult.list[maintainedMap[panel.index]]),
22
26
  ...diffResult.added.map(idx => diffResult.list[idx])
23
27
  ];
24
28
  };
@@ -397,8 +397,8 @@ class AxesController {
397
397
  }
398
398
 
399
399
  /**
400
- * 현재
401
- * @returns
400
+ * Returns the current axes position
401
+ * @ko 현재 axes의 position을 반환합니다.
402
402
  */
403
403
  public getCurrentPosition() {
404
404
  return this._axes?.get([AXES.POSITION_KEY])[AXES.POSITION_KEY] ?? 0;
@@ -384,7 +384,7 @@ abstract class Control {
384
384
  // 거리(1px 미만)가 매우 짧은 경우 duration이 늘어지는걸 방지하기 위해 0으로 바꿔 즉시 변경
385
385
  let nextDuration = duration;
386
386
 
387
- if (Math.abs(nextDuration - position) < 0.5) {
387
+ if (Math.abs(nextDuration - position) < flicking.animationThreshold) {
388
388
  nextDuration = 0;
389
389
  }
390
390
  const animate = () => this._controller.animateTo(position, nextDuration, axesEvent);
@@ -152,6 +152,17 @@ abstract class Renderer {
152
152
  return Promise.resolve();
153
153
  }
154
154
 
155
+ /**
156
+ * Return Rendered Panels
157
+ * @ko 렌더링이 된 패널을 반환합니다.
158
+ * @return {Panel[]}
159
+ */
160
+ public getRenderedPanels() {
161
+ const flicking = getFlickingAttached(this._flicking);
162
+
163
+ return flicking.renderer.panels.filter(panel => panel.rendered);
164
+ }
165
+
155
166
  /**
156
167
  * Update all panel sizes
157
168
  * @ko 모든 패널의 크기를 업데이트합니다
@@ -554,6 +565,15 @@ abstract class Renderer {
554
565
  const flicking = getFlickingAttached(this._flicking);
555
566
 
556
567
  flicking.camera.applyTransform();
568
+
569
+ if (flicking.useCSSOrderProperty) {
570
+ // useCSSOrderProperty를 사용하는 경우 DOM은 변화가 없지만 대신 CSS Order가 추가 된다.
571
+ const panels = flicking.panels;
572
+
573
+ this._strategy.getRenderingIndexesByOrder(flicking).forEach((domIndex, index) => {
574
+ panels[domIndex].element.style.order = `${index}`;
575
+ });
576
+ }
557
577
  }
558
578
  }
559
579
 
@@ -40,9 +40,17 @@ class VanillaRenderer extends Renderer {
40
40
  const cameraEl = flicking.camera.element;
41
41
 
42
42
  // We're using reversed panels here as last panel should be the last element of camera element
43
- const reversedElements = this._strategy
44
- .getRenderingElementsByOrder(flicking)
45
- .reverse();
43
+
44
+ let reversedElements: HTMLElement[] = [];
45
+
46
+ if (flicking.useCSSOrderProperty) {
47
+ // useCSSOrderProperty를 사용하는 경우 원본 그대로 렌더링
48
+ reversedElements = this.getRenderedPanels().map(panel => panel.element).reverse();
49
+ } else {
50
+ reversedElements = this._strategy
51
+ .getRenderingElementsByOrder(flicking)
52
+ .reverse();
53
+ }
46
54
 
47
55
  reversedElements.forEach((el, idx) => {
48
56
  const nextEl = reversedElements[idx - 1] ? reversedElements[idx - 1] : null;