@egjs/flicking 3.8.4 → 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 (37) hide show
  1. package/declaration/Flicking.d.ts +2 -1
  2. package/declaration/components/AutoResizer.d.ts +12 -0
  3. package/declaration/types.d.ts +1 -0
  4. package/dist/flicking.esm.js +87 -18
  5. package/dist/flicking.esm.js.map +1 -1
  6. package/dist/flicking.js +87 -18
  7. package/dist/flicking.js.map +1 -1
  8. package/dist/flicking.min.js +2 -2
  9. package/dist/flicking.min.js.map +1 -1
  10. package/dist/flicking.pkgd.js +87 -18
  11. package/dist/flicking.pkgd.js.map +1 -1
  12. package/dist/flicking.pkgd.min.js +2 -2
  13. package/dist/flicking.pkgd.min.js.map +1 -1
  14. package/doc/eg.Flicking.html +102 -39
  15. package/doc/global.html +1 -1
  16. package/doc/index.html +1 -1
  17. package/doc/node_modules_@egjs_component_src_Component.ts.html +1 -1
  18. package/doc/src_Flicking.ts.html +9 -16
  19. package/doc/src_types.ts.html +2 -1
  20. package/docs/build/release/3.9.0/dist/flicking.esm.js +5124 -0
  21. package/docs/build/release/3.9.0/dist/flicking.esm.js.map +1 -0
  22. package/docs/build/release/3.9.0/dist/flicking.js +5131 -0
  23. package/docs/build/release/3.9.0/dist/flicking.js.map +1 -0
  24. package/docs/build/release/3.9.0/dist/flicking.min.js +10 -0
  25. package/docs/build/release/3.9.0/dist/flicking.min.js.map +1 -0
  26. package/docs/build/release/3.9.0/dist/flicking.pkgd.js +11460 -0
  27. package/docs/build/release/3.9.0/dist/flicking.pkgd.js.map +1 -0
  28. package/docs/build/release/3.9.0/dist/flicking.pkgd.min.js +10 -0
  29. package/docs/build/release/3.9.0/dist/flicking.pkgd.min.js.map +1 -0
  30. package/package.json +5 -2
  31. package/rollup.config.development.js +26 -0
  32. package/src/Flicking.ts +8 -15
  33. package/src/components/AutoResizer.ts +80 -0
  34. package/src/components/Viewport.ts +7 -2
  35. package/src/consts.ts +1 -0
  36. package/src/types.ts +1 -0
  37. package/tsconfig.test.json +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egjs/flicking",
3
- "version": "3.8.4",
3
+ "version": "3.9.0",
4
4
  "description": "Everyday 30 million people experience. It's reliable, flexible and extendable carousel.",
5
5
  "main": "dist/flicking.js",
6
6
  "module": "dist/flicking.esm.js",
@@ -8,7 +8,7 @@
8
8
  "es2015": "dist/flicking.esm.js",
9
9
  "types": "declaration/index.d.ts",
10
10
  "scripts": {
11
- "start": "rollup -c -w",
11
+ "start": "rollup -w -c rollup.config.development.js",
12
12
  "build": "rm -rf ./dist ./declaration && rollup -c && npm run declaration && npm run printsizes",
13
13
  "declaration": "rm -rf declaration && tsc -p tsconfig.declaration.json",
14
14
  "printsizes": "print-sizes ./dist --exclude=\\.map",
@@ -51,6 +51,7 @@
51
51
  "@types/karma-chai": "^0.1.1",
52
52
  "@types/mocha": "^5.2.5",
53
53
  "@types/node": "^14.0.27",
54
+ "@types/resize-observer-browser": "^0.1.6",
54
55
  "@types/sinon": "^7.0.3",
55
56
  "chai": "^4.2.0",
56
57
  "chalk": "^2.4.2",
@@ -73,6 +74,8 @@
73
74
  "print-coveralls": "^1.2.2",
74
75
  "print-sizes": "0.0.3",
75
76
  "pvu": "^0.4.1",
77
+ "rollup-plugin-livereload": "^2.0.5",
78
+ "rollup-plugin-serve": "^1.1.0",
76
79
  "sinon": "^7.2.3",
77
80
  "sync-exec": "^0.6.2",
78
81
  "ts-mock-imports": "^1.2.2",
@@ -0,0 +1,26 @@
1
+ import buildHelper from "@egjs/build-helper";
2
+ import serve from "rollup-plugin-serve";
3
+ import livereload from "rollup-plugin-livereload";
4
+
5
+ const name = "eg.Flicking";
6
+
7
+ export default buildHelper([
8
+ {
9
+ name,
10
+ input: "./src/index.umd.ts",
11
+ output: "./test/manual/lib/flicking.pkgd.js",
12
+ format: "umd",
13
+ resolve: true,
14
+ plugins: [
15
+ serve({
16
+ open: true,
17
+ openPage: "/html/default.html",
18
+ contentBase: "test/manual"
19
+ }),
20
+ livereload({
21
+ watch: "./test/manual/lib/flicking.pkgd.js"
22
+ }),
23
+ ]
24
+ }
25
+ ]);
26
+
package/src/Flicking.ts CHANGED
@@ -5,8 +5,10 @@
5
5
 
6
6
  import Component from "@egjs/component";
7
7
  import ImReady from "@egjs/imready";
8
+ import { DiffResult } from "@egjs/list-differ";
8
9
  import Viewport from "./components/Viewport";
9
10
  import Panel from "./components/Panel";
11
+ import AutoResizer from "./components/AutoResizer";
10
12
 
11
13
  import { merge, getProgress, parseElement, isString, counter, findIndex } from "./utils";
12
14
  import { DEFAULT_OPTIONS, EVENTS, DIRECTION, AXES_EVENTS, STATE_TYPE, DEFAULT_MOVE_TYPE_OPTIONS } from "./consts";
@@ -32,8 +34,6 @@ import {
32
34
  MoveTypeStringOption,
33
35
  ValueOf,
34
36
  } from "./types";
35
- // import { sendEvent } from "./ga/ga";
36
- import { DiffResult } from "@egjs/list-differ";
37
37
 
38
38
  /**
39
39
  * @memberof eg
@@ -98,6 +98,7 @@ class Flicking extends Component<{
98
98
 
99
99
  private wrapper: HTMLElement;
100
100
  private viewport: Viewport;
101
+ private autoResizer: AutoResizer;
101
102
  private contentsReadyChecker: ImReady | null = null;
102
103
 
103
104
  private eventContext: FlickingContext;
@@ -135,6 +136,7 @@ class Flicking extends Component<{
135
136
  * @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>
136
137
  * @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>
137
138
  * @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>
139
+ * @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>
138
140
  * @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>
139
141
  */
140
142
  constructor(
@@ -169,16 +171,10 @@ class Flicking extends Component<{
169
171
 
170
172
  // Make viewport instance with panel container element
171
173
  this.viewport = new Viewport(this, this.options, this.triggerEvent);
174
+ this.autoResizer = new AutoResizer(this);
175
+
172
176
  this.listenInput();
173
177
  this.listenResize();
174
-
175
- // if (this.options.collectStatistics) {
176
- // sendEvent(
177
- // "usage",
178
- // "options",
179
- // options,
180
- // );
181
- // }
182
178
  }
183
179
 
184
180
  /**
@@ -506,10 +502,7 @@ class Flicking extends Component<{
506
502
  public destroy(option: Partial<DestroyOption> = {}): void {
507
503
  this.off();
508
504
 
509
- if (this.options.autoResize) {
510
- window.removeEventListener("resize", this.resize);
511
- }
512
-
505
+ this.autoResizer.disable();
513
506
  this.viewport.destroy(option);
514
507
  this.contentsReadyChecker?.destroy();
515
508
 
@@ -872,7 +865,7 @@ class Flicking extends Component<{
872
865
  const options = this.options;
873
866
 
874
867
  if (options.autoResize) {
875
- window.addEventListener("resize", this.resize);
868
+ this.autoResizer.enable();
876
869
  }
877
870
 
878
871
  if (options.resizeOnContentsReady) {
@@ -0,0 +1,80 @@
1
+ /*
2
+ * Copyright (c) 2015 NAVER Corp.
3
+ * egjs projects are licensed under the MIT license
4
+ */
5
+ import Flicking from "../Flicking";
6
+
7
+ class AutoResizer {
8
+ private flicking: Flicking;
9
+ private enabled: boolean;
10
+ private resizeObserver: ResizeObserver | null;
11
+
12
+ private skipFirstResize = (() => {
13
+ let isFirstResize = true;
14
+
15
+ return (() => {
16
+ if (isFirstResize) {
17
+ isFirstResize = false;
18
+ return;
19
+ }
20
+ this.onResize();
21
+ });
22
+ })();
23
+
24
+ public constructor(flicking: Flicking) {
25
+ this.flicking = flicking;
26
+ this.enabled = false;
27
+ this.resizeObserver = null;
28
+ }
29
+
30
+ public enable(): this {
31
+ const flicking = this.flicking;
32
+
33
+ if (this.enabled) {
34
+ this.disable();
35
+ }
36
+
37
+ if (flicking.options.useResizeObserver && !!window.ResizeObserver) {
38
+ const flickingEl = flicking.getElement();
39
+ const viewportSizeNot0 = flickingEl.clientWidth !== 0 || flickingEl.clientHeight !== 0;
40
+
41
+ const resizeObserver = viewportSizeNot0
42
+ ? new ResizeObserver(this.skipFirstResize)
43
+ : new ResizeObserver(this.onResize);
44
+
45
+ resizeObserver.observe(flickingEl);
46
+
47
+ this.resizeObserver = resizeObserver;
48
+ } else {
49
+ window.addEventListener("resize", this.onResize);
50
+ }
51
+
52
+ this.enabled = true;
53
+
54
+ return this;
55
+ }
56
+
57
+ public disable(): this {
58
+ if (!this.enabled) {
59
+ return this;
60
+ }
61
+
62
+ const resizeObserver = this.resizeObserver;
63
+ if (resizeObserver) {
64
+ resizeObserver.disconnect();
65
+ this.resizeObserver = null;
66
+ } else {
67
+ window.removeEventListener("resize", this.onResize);
68
+ }
69
+
70
+ this.enabled = false;
71
+
72
+ return this;
73
+ }
74
+
75
+ private onResize = () => {
76
+ this.flicking.resize();
77
+ }
78
+ }
79
+
80
+ export default AutoResizer;
@@ -394,6 +394,12 @@ export default class Viewport {
394
394
  this.panInput.destroy();
395
395
  this.panInput = null;
396
396
 
397
+ // Refresh Axes instance
398
+ this.axes.destroy();
399
+ this.setAxesInstance();
400
+ this.updateScrollArea();
401
+ this.updateAxesPosition(this.state.position);
402
+
397
403
  this.stateMachine.transitTo(STATE_TYPE.IDLE);
398
404
  }
399
405
  }
@@ -1089,6 +1095,7 @@ export default class Viewport {
1089
1095
  this.applyCSSValue();
1090
1096
  this.setMoveType();
1091
1097
  this.setAxesInstance();
1098
+ this.createPanInput();
1092
1099
  this.refreshPanels();
1093
1100
  this.setDefaultPanel();
1094
1101
  this.resize();
@@ -1215,8 +1222,6 @@ export default class Viewport {
1215
1222
  deceleration: options.deceleration,
1216
1223
  interruptable: true,
1217
1224
  });
1218
-
1219
- this.createPanInput();
1220
1225
  }
1221
1226
 
1222
1227
  private refreshPanels(): void {
package/src/consts.ts CHANGED
@@ -65,6 +65,7 @@ export const DEFAULT_OPTIONS: Readonly<FlickingOptions> = {
65
65
  resizeOnContentsReady: false,
66
66
  iOSEdgeSwipeThreshold: 30,
67
67
  collectStatistics: true,
68
+ useResizeObserver: true,
68
69
  };
69
70
 
70
71
  export const DEFAULT_VIEWPORT_CSS = {
package/src/types.ts CHANGED
@@ -87,6 +87,7 @@ export interface FlickingOptions {
87
87
  iOSEdgeSwipeThreshold: number;
88
88
  resizeOnContentsReady: boolean;
89
89
  collectStatistics: boolean;
90
+ useResizeObserver: boolean;
90
91
  }
91
92
 
92
93
  export type MoveTypeObjectOption = MoveTypeSnapOption | MoveTypeFreeScrollOption;
@@ -9,6 +9,7 @@
9
9
  "types": [
10
10
  "karma-chai",
11
11
  "mocha",
12
+ "resize-observer-browser"
12
13
  ]
13
14
  },
14
15
  "include": [