@egjs/flicking 3.8.1 → 3.9.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.
Files changed (50) hide show
  1. package/declaration/Flicking.d.ts +2 -1
  2. package/declaration/components/AutoResizer.d.ts +12 -0
  3. package/declaration/components/Viewport.d.ts +1 -1
  4. package/declaration/types.d.ts +1 -0
  5. package/dist/flicking.esm.js +105 -20
  6. package/dist/flicking.esm.js.map +1 -1
  7. package/dist/flicking.js +105 -20
  8. package/dist/flicking.js.map +1 -1
  9. package/dist/flicking.min.js +2 -2
  10. package/dist/flicking.min.js.map +1 -1
  11. package/dist/flicking.pkgd.js +105 -20
  12. package/dist/flicking.pkgd.js.map +1 -1
  13. package/dist/flicking.pkgd.min.js +2 -2
  14. package/dist/flicking.pkgd.min.js.map +1 -1
  15. package/doc/eg.Flicking.html +102 -39
  16. package/doc/global.html +1 -1
  17. package/doc/index.html +1 -1
  18. package/doc/node_modules_@egjs_component_src_Component.ts.html +1 -1
  19. package/doc/src_Flicking.ts.html +23 -17
  20. package/doc/src_types.ts.html +2 -1
  21. package/docs/build/release/3.8.4/dist/flicking.esm.js +5055 -0
  22. package/docs/build/release/3.8.4/dist/flicking.esm.js.map +1 -0
  23. package/docs/build/release/3.8.4/dist/flicking.js +5062 -0
  24. package/docs/build/release/3.8.4/dist/flicking.js.map +1 -0
  25. package/docs/build/release/3.8.4/dist/flicking.min.js +10 -0
  26. package/docs/build/release/3.8.4/dist/flicking.min.js.map +1 -0
  27. package/docs/build/release/3.8.4/dist/flicking.pkgd.js +11391 -0
  28. package/docs/build/release/3.8.4/dist/flicking.pkgd.js.map +1 -0
  29. package/docs/build/release/3.8.4/dist/flicking.pkgd.min.js +10 -0
  30. package/docs/build/release/3.8.4/dist/flicking.pkgd.min.js.map +1 -0
  31. package/docs/build/release/3.9.0/dist/flicking.esm.js +5124 -0
  32. package/docs/build/release/3.9.0/dist/flicking.esm.js.map +1 -0
  33. package/docs/build/release/3.9.0/dist/flicking.js +5131 -0
  34. package/docs/build/release/3.9.0/dist/flicking.js.map +1 -0
  35. package/docs/build/release/3.9.0/dist/flicking.min.js +10 -0
  36. package/docs/build/release/3.9.0/dist/flicking.min.js.map +1 -0
  37. package/docs/build/release/3.9.0/dist/flicking.pkgd.js +11460 -0
  38. package/docs/build/release/3.9.0/dist/flicking.pkgd.js.map +1 -0
  39. package/docs/build/release/3.9.0/dist/flicking.pkgd.min.js +10 -0
  40. package/docs/build/release/3.9.0/dist/flicking.pkgd.min.js.map +1 -0
  41. package/package.json +7 -7
  42. package/rollup.config.development.js +26 -0
  43. package/src/Flicking.ts +22 -16
  44. package/src/components/AutoResizer.ts +80 -0
  45. package/src/components/PanelManager.ts +0 -1
  46. package/src/components/Viewport.ts +8 -3
  47. package/src/consts.ts +1 -0
  48. package/src/types.ts +1 -0
  49. package/src/utils.ts +1 -1
  50. package/tsconfig.test.json +1 -0
@@ -1,6 +1,6 @@
1
1
  import Component from "@egjs/component";
2
- import { FlickingOptions, FlickingEvent, Direction, EventType, FlickingPanel, FlickingStatus, Plugin, ElementLike, DestroyOption, BeforeSyncResult, SyncResult, ChangeEvent, SelectEvent, NeedPanelEvent, VisibleChangeEvent, ContentErrorEvent } from "./types";
3
2
  import { DiffResult } from "@egjs/list-differ";
3
+ import { FlickingOptions, FlickingEvent, Direction, EventType, FlickingPanel, FlickingStatus, Plugin, ElementLike, DestroyOption, BeforeSyncResult, SyncResult, ChangeEvent, SelectEvent, NeedPanelEvent, VisibleChangeEvent, ContentErrorEvent } from "./types";
4
4
  declare class Flicking extends Component<{
5
5
  holdStart: FlickingEvent;
6
6
  holdEnd: FlickingEvent;
@@ -20,6 +20,7 @@ declare class Flicking extends Component<{
20
20
  options: FlickingOptions;
21
21
  private wrapper;
22
22
  private viewport;
23
+ private autoResizer;
23
24
  private contentsReadyChecker;
24
25
  private eventContext;
25
26
  private isPanelChangedAtBeforeSync;
@@ -0,0 +1,12 @@
1
+ import Flicking from "../Flicking";
2
+ declare class AutoResizer {
3
+ private flicking;
4
+ private enabled;
5
+ private resizeObserver;
6
+ private skipFirstResize;
7
+ constructor(flicking: Flicking);
8
+ enable(): this;
9
+ disable(): this;
10
+ private onResize;
11
+ }
12
+ export default AutoResizer;
@@ -67,7 +67,7 @@ export default class Viewport {
67
67
  getPositionOffset(): number;
68
68
  getCheckedIndexes(): Array<[number, number]>;
69
69
  getVisiblePanels(): Panel[];
70
- setCurrentPanel(panel: Panel): void;
70
+ setCurrentPanel(panel: Panel | undefined): void;
71
71
  setLastIndex(index: number): void;
72
72
  setVisiblePanels(panels: Panel[]): void;
73
73
  connectAxesHandler(handlers: {
@@ -40,6 +40,7 @@ export interface FlickingOptions {
40
40
  iOSEdgeSwipeThreshold: number;
41
41
  resizeOnContentsReady: boolean;
42
42
  collectStatistics: boolean;
43
+ useResizeObserver: boolean;
43
44
  }
44
45
  export declare type MoveTypeObjectOption = MoveTypeSnapOption | MoveTypeFreeScrollOption;
45
46
  export declare type MoveTypeStringOption = MoveTypeObjectOption["type"];
@@ -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: 3.8.1
7
+ version: 3.9.0
8
8
  */
9
9
  import Component from '@egjs/component';
10
10
  import ImReady from '@egjs/imready';
@@ -113,7 +113,8 @@ var DEFAULT_OPTIONS = {
113
113
  renderExternal: false,
114
114
  resizeOnContentsReady: false,
115
115
  iOSEdgeSwipeThreshold: 30,
116
- collectStatistics: true
116
+ collectStatistics: true,
117
+ useResizeObserver: true
117
118
  };
118
119
  var DEFAULT_VIEWPORT_CSS = {
119
120
  position: "relative",
@@ -375,7 +376,7 @@ function findIndex(iterable, callback) {
375
376
  for (var i = 0; i < iterable.length; i += 1) {
376
377
  var element = iterable[i];
377
378
 
378
- if (element && callback(element)) {
379
+ if (element != null && callback(element)) {
379
380
  return i;
380
381
  }
381
382
  }
@@ -2512,7 +2513,12 @@ function () {
2512
2513
  __proto.disable = function () {
2513
2514
  if (this.panInput) {
2514
2515
  this.panInput.destroy();
2515
- this.panInput = null;
2516
+ this.panInput = null; // Refresh Axes instance
2517
+
2518
+ this.axes.destroy();
2519
+ this.setAxesInstance();
2520
+ this.updateScrollArea();
2521
+ this.updateAxesPosition(this.state.position);
2516
2522
  this.stateMachine.transitTo(STATE_TYPE.IDLE);
2517
2523
  }
2518
2524
  };
@@ -3211,6 +3217,7 @@ function () {
3211
3217
  this.applyCSSValue();
3212
3218
  this.setMoveType();
3213
3219
  this.setAxesInstance();
3220
+ this.createPanInput();
3214
3221
  this.refreshPanels();
3215
3222
  this.setDefaultPanel();
3216
3223
  this.resize();
@@ -3322,7 +3329,6 @@ function () {
3322
3329
  deceleration: options.deceleration,
3323
3330
  interruptable: true
3324
3331
  });
3325
- this.createPanInput();
3326
3332
  };
3327
3333
 
3328
3334
  __proto.refreshPanels = function () {
@@ -4039,6 +4045,77 @@ function () {
4039
4045
  return Viewport;
4040
4046
  }();
4041
4047
 
4048
+ var AutoResizer =
4049
+ /*#__PURE__*/
4050
+ function () {
4051
+ function AutoResizer(flicking) {
4052
+ var _this = this;
4053
+
4054
+ this.skipFirstResize = function () {
4055
+ var isFirstResize = true;
4056
+ return function () {
4057
+ if (isFirstResize) {
4058
+ isFirstResize = false;
4059
+ return;
4060
+ }
4061
+
4062
+ _this.onResize();
4063
+ };
4064
+ }();
4065
+
4066
+ this.onResize = function () {
4067
+ _this.flicking.resize();
4068
+ };
4069
+
4070
+ this.flicking = flicking;
4071
+ this.enabled = false;
4072
+ this.resizeObserver = null;
4073
+ }
4074
+
4075
+ var __proto = AutoResizer.prototype;
4076
+
4077
+ __proto.enable = function () {
4078
+ var flicking = this.flicking;
4079
+
4080
+ if (this.enabled) {
4081
+ this.disable();
4082
+ }
4083
+
4084
+ if (flicking.options.useResizeObserver && !!window.ResizeObserver) {
4085
+ var flickingEl = flicking.getElement();
4086
+ var viewportSizeNot0 = flickingEl.clientWidth !== 0 || flickingEl.clientHeight !== 0;
4087
+ var resizeObserver = viewportSizeNot0 ? new ResizeObserver(this.skipFirstResize) : new ResizeObserver(this.onResize);
4088
+ resizeObserver.observe(flickingEl);
4089
+ this.resizeObserver = resizeObserver;
4090
+ } else {
4091
+ window.addEventListener("resize", this.onResize);
4092
+ }
4093
+
4094
+ this.enabled = true;
4095
+ return this;
4096
+ };
4097
+
4098
+ __proto.disable = function () {
4099
+ if (!this.enabled) {
4100
+ return this;
4101
+ }
4102
+
4103
+ var resizeObserver = this.resizeObserver;
4104
+
4105
+ if (resizeObserver) {
4106
+ resizeObserver.disconnect();
4107
+ this.resizeObserver = null;
4108
+ } else {
4109
+ window.removeEventListener("resize", this.onResize);
4110
+ }
4111
+
4112
+ this.enabled = false;
4113
+ return this;
4114
+ };
4115
+
4116
+ return AutoResizer;
4117
+ }();
4118
+
4042
4119
  /**
4043
4120
  * Copyright (c) 2015 NAVER Corp.
4044
4121
  * egjs projects are licensed under the MIT license
@@ -4088,6 +4165,7 @@ function (_super) {
4088
4165
  * @param {boolean} [options.isConstantSize=false] Whether all panels have a constant size that won't be changed after resize. Enabling this option can increase performance while recalculating panel size.<ko>모든 패널의 크기가 불변인지의 여부. 이 옵션을 'true'로 설정하면 패널 크기 재설정시에 성능을 높일 수 있다.</ko>
4089
4166
  * @param {boolean} [options.renderExternal=false] Whether to use external rendering. It will delegate DOM manipulation and can synchronize the rendered state by calling `sync()` method. You can use this option to use in frameworks like React, Vue, Angular, which has its states and rendering methods.<ko>외부 렌더링을 사용할 지의 여부. 이 옵션을 사용시 렌더링을 외부에 위임할 수 있고, `sync()`를 호출하여 그 상태를 동기화할 수 있다. 이 옵션을 사용하여, React, Vue, Angular 등 자체적인 상태와 렌더링 방법을 갖는 프레임워크에 대응할 수 있다.</ko>
4090
4167
  * @param {boolean} [options.resizeOnContentsReady=false] Whether to resize the Flicking after the image/video elements inside viewport are ready.<br/>Use this property to prevent wrong Flicking layout caused by dynamic image / video sizes.<ko>Flicking 내부의 이미지 / 비디오 엘리먼트들이 전부 로드되었을 때 Flicking의 크기를 재계산하기 위한 옵션.<br/>이미지 / 비디오 크기가 고정 크기가 아닐 경우 사용하여 레이아웃이 잘못되는 것을 방지할 수 있다.</ko>
4168
+ * @param {boolean} [options.useResizeObserver=true] Whether to listen {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver ResizeObserver}'s event instead of Window's {@link https://developer.mozilla.org/ko/docs/Web/API/Window/resize_event resize} event when using the `autoResize` option<ko>autoResize 옵션 사용시 {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver ResizeObserver}의 이벤트를 Window객체의 {@link https://developer.mozilla.org/ko/docs/Web/API/Window/resize_event resize} 이벤트 대신 수신할지 여부를 설정합니다</ko>
4091
4169
  * @param {boolean} [options.collectStatistics=true] Whether to collect statistics on how you are using `Flicking`. These statistical data do not contain any personal information and are used only as a basis for the development of a user-friendly product.<ko>어떻게 `Flicking`을 사용하고 있는지에 대한 통계 수집 여부를 나타낸다. 이 통계자료는 개인정보를 포함하고 있지 않으며 오직 사용자 친화적인 제품으로 발전시키기 위한 근거자료로서 활용한다.</ko>
4092
4170
  */
4093
4171
 
@@ -4117,7 +4195,9 @@ function (_super) {
4117
4195
  var allPanels = viewport.panelManager.allPanels();
4118
4196
 
4119
4197
  if (!options.isConstantSize) {
4120
- allPanels.forEach(function (panel) {
4198
+ allPanels.filter(function (panel) {
4199
+ return !!panel;
4200
+ }).forEach(function (panel) {
4121
4201
  return panel.unCacheBbox();
4122
4202
  });
4123
4203
  }
@@ -4253,18 +4333,13 @@ function (_super) {
4253
4333
 
4254
4334
 
4255
4335
  _this.viewport = new Viewport(_this, _this.options, _this.triggerEvent);
4336
+ _this.autoResizer = new AutoResizer(_this);
4256
4337
 
4257
4338
  _this.listenInput();
4258
4339
 
4259
4340
  _this.listenResize();
4260
4341
 
4261
- return _this; // if (this.options.collectStatistics) {
4262
- // sendEvent(
4263
- // "usage",
4264
- // "options",
4265
- // options,
4266
- // );
4267
- // }
4342
+ return _this;
4268
4343
  }
4269
4344
  /**
4270
4345
  * Move to the previous panel if it exists.
@@ -4598,11 +4673,7 @@ function (_super) {
4598
4673
  }
4599
4674
 
4600
4675
  this.off();
4601
-
4602
- if (this.options.autoResize) {
4603
- window.removeEventListener("resize", this.resize);
4604
- }
4605
-
4676
+ this.autoResizer.disable();
4606
4677
  this.viewport.destroy(option);
4607
4678
  (_a = this.contentsReadyChecker) === null || _a === void 0 ? void 0 : _a.destroy(); // release resources
4608
4679
 
@@ -4755,6 +4826,8 @@ function (_super) {
4755
4826
  __proto.beforeSync = function (diffInfo) {
4756
4827
  var _this = this;
4757
4828
 
4829
+ var _a;
4830
+
4758
4831
  var maintained = diffInfo.maintained,
4759
4832
  added = diffInfo.added,
4760
4833
  changed = diffInfo.changed,
@@ -4762,6 +4835,7 @@ function (_super) {
4762
4835
  var viewport = this.viewport;
4763
4836
  var panelManager = viewport.panelManager;
4764
4837
  var isCircular = this.options.circular;
4838
+ var currentPanel = viewport.getCurrentPanel();
4765
4839
  var cloneCount = panelManager.getCloneCount();
4766
4840
  var prevClonedPanels = panelManager.clonedPanels(); // Update visible panels
4767
4841
 
@@ -4845,6 +4919,17 @@ function (_super) {
4845
4919
  }
4846
4920
 
4847
4921
  panelManager.replacePanels(newPanels, newClones);
4922
+ var currentPanelIndex = (_a = currentPanel === null || currentPanel === void 0 ? void 0 : currentPanel.getIndex()) !== null && _a !== void 0 ? _a : -1;
4923
+ var currentPanelIsRemoved = findIndex(removed, function (index) {
4924
+ return index === currentPanelIndex;
4925
+ }) >= 0;
4926
+
4927
+ if ((!currentPanel || currentPanelIsRemoved) && newPanels.length > 0) {
4928
+ viewport.setCurrentPanel(newPanels[0]);
4929
+ } else if (newPanels.length <= 0) {
4930
+ viewport.setCurrentPanel(undefined);
4931
+ }
4932
+
4848
4933
  this.isPanelChangedAtBeforeSync = true;
4849
4934
  };
4850
4935
  /**
@@ -4960,7 +5045,7 @@ function (_super) {
4960
5045
  var options = this.options;
4961
5046
 
4962
5047
  if (options.autoResize) {
4963
- window.addEventListener("resize", this.resize);
5048
+ this.autoResizer.enable();
4964
5049
  }
4965
5050
 
4966
5051
  if (options.resizeOnContentsReady) {
@@ -5000,7 +5085,7 @@ function (_super) {
5000
5085
  */
5001
5086
 
5002
5087
 
5003
- Flicking.VERSION = "3.8.1";
5088
+ Flicking.VERSION = "3.9.0";
5004
5089
  /**
5005
5090
  * Direction constant - "PREV" or "NEXT"
5006
5091
  * @ko 방향 상수 - "PREV" 또는 "NEXT"