@egjs/flicking 3.8.2 → 3.9.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.
Files changed (59) 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 +101 -24
  5. package/dist/flicking.esm.js.map +1 -1
  6. package/dist/flicking.js +101 -24
  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 +101 -24
  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 +16 -18
  19. package/doc/src_types.ts.html +2 -1
  20. package/docs/build/release/3.8.4/dist/flicking.esm.js +5055 -0
  21. package/docs/build/release/3.8.4/dist/flicking.esm.js.map +1 -0
  22. package/docs/build/release/3.8.4/dist/flicking.js +5062 -0
  23. package/docs/build/release/3.8.4/dist/flicking.js.map +1 -0
  24. package/docs/build/release/3.8.4/dist/flicking.min.js +10 -0
  25. package/docs/build/release/3.8.4/dist/flicking.min.js.map +1 -0
  26. package/docs/build/release/3.8.4/dist/flicking.pkgd.js +11391 -0
  27. package/docs/build/release/3.8.4/dist/flicking.pkgd.js.map +1 -0
  28. package/docs/build/release/3.8.4/dist/flicking.pkgd.min.js +10 -0
  29. package/docs/build/release/3.8.4/dist/flicking.pkgd.min.js.map +1 -0
  30. package/docs/build/release/3.9.0/dist/flicking.esm.js +5124 -0
  31. package/docs/build/release/3.9.0/dist/flicking.esm.js.map +1 -0
  32. package/docs/build/release/3.9.0/dist/flicking.js +5131 -0
  33. package/docs/build/release/3.9.0/dist/flicking.js.map +1 -0
  34. package/docs/build/release/3.9.0/dist/flicking.min.js +10 -0
  35. package/docs/build/release/3.9.0/dist/flicking.min.js.map +1 -0
  36. package/docs/build/release/3.9.0/dist/flicking.pkgd.js +11460 -0
  37. package/docs/build/release/3.9.0/dist/flicking.pkgd.js.map +1 -0
  38. package/docs/build/release/3.9.0/dist/flicking.pkgd.min.js +10 -0
  39. package/docs/build/release/3.9.0/dist/flicking.pkgd.min.js.map +1 -0
  40. package/docs/build/release/3.9.1/dist/flicking.esm.js +5124 -0
  41. package/docs/build/release/3.9.1/dist/flicking.esm.js.map +1 -0
  42. package/docs/build/release/3.9.1/dist/flicking.js +5131 -0
  43. package/docs/build/release/3.9.1/dist/flicking.js.map +1 -0
  44. package/docs/build/release/3.9.1/dist/flicking.min.js +10 -0
  45. package/docs/build/release/3.9.1/dist/flicking.min.js.map +1 -0
  46. package/docs/build/release/3.9.1/dist/flicking.pkgd.js +11460 -0
  47. package/docs/build/release/3.9.1/dist/flicking.pkgd.js.map +1 -0
  48. package/docs/build/release/3.9.1/dist/flicking.pkgd.min.js +10 -0
  49. package/docs/build/release/3.9.1/dist/flicking.pkgd.min.js.map +1 -0
  50. package/package.json +8 -12
  51. package/rollup.config.development.js +26 -0
  52. package/src/Flicking.ts +15 -17
  53. package/src/components/AutoResizer.ts +80 -0
  54. package/src/components/PanelManager.ts +0 -1
  55. package/src/components/Viewport.ts +11 -5
  56. package/src/consts.ts +1 -0
  57. package/src/types.ts +1 -0
  58. package/src/utils.ts +1 -1
  59. 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.2",
3
+ "version": "3.9.1",
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",
@@ -18,18 +18,11 @@
18
18
  "lint": "tslint -c tslint.json 'src/**/*.ts'",
19
19
  "jsdoc": "rm -rf ./doc && jsdoc -c jsdoc.json",
20
20
  "demo:build": "npm run build && cpx 'dist/**/*' demo/release/latest/dist --clean",
21
- "demo:prebuild-version": "cpx 'dist/**/*' demo/release/$npm_package_version/dist --clean && cpx 'doc/**/*' demo/release/$npm_package_version/doc --clean",
22
- "demo:prebuild-latest": "cpx 'dist/**/*' demo/release/latest/dist --clean && cpx 'doc/**/*' demo/release/latest/doc --clean",
23
- "demo:origin": "npm run build && npm run jsdoc && npm run demo:prebuild-version && npm run demo:prebuild-latest && gh-pages -d demo/",
24
- "demo:deploy": "npm run build && npm run jsdoc && npm run demo:prebuild-version && npm run demo:prebuild-latest && gh-pages -d demo/ --add --remote upstream",
25
- "demo:setup": "cpx 'node_modules/@egjs/common-demo/**/*' 'demo/' && rm demo/package.json",
21
+ "demo:prebuild-version": "cpx 'dist/**/*' docs/build/release/$npm_package_version/dist --clean",
22
+ "demo:deploy": "npm run build && npm run jsdoc && npm run demo:prebuild-version && gh-pages -d docs/build/ --add --remote upstream",
26
23
  "release": "release-helper upstream",
27
24
  "changelog": "node ./config/changelog.js",
28
- "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
29
- "packages": "npm run packages:update && npm run packages:build && npm run packages:publish",
30
- "packages:update": "pvu --update=react-flicking,ngx-flicking/projects/ngx-flicking,vue-flicking",
31
- "packages:build": "pvu --build=react-flicking,ngx-flicking,vue-flicking",
32
- "packages:publish": "pvu --publish=react-flicking,ngx-flicking/dist/ngx-flicking,vue-flicking"
25
+ "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
33
26
  },
34
27
  "repository": {
35
28
  "type": "git",
@@ -54,6 +47,7 @@
54
47
  "@types/karma-chai": "^0.1.1",
55
48
  "@types/mocha": "^5.2.5",
56
49
  "@types/node": "^14.0.27",
50
+ "@types/resize-observer-browser": "^0.1.6",
57
51
  "@types/sinon": "^7.0.3",
58
52
  "chai": "^4.2.0",
59
53
  "chalk": "^2.4.2",
@@ -76,6 +70,8 @@
76
70
  "print-coveralls": "^1.2.2",
77
71
  "print-sizes": "0.0.3",
78
72
  "pvu": "^0.4.1",
73
+ "rollup-plugin-livereload": "^2.0.5",
74
+ "rollup-plugin-serve": "^1.1.0",
79
75
  "sinon": "^7.2.3",
80
76
  "sync-exec": "^0.6.2",
81
77
  "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
 
@@ -532,7 +525,9 @@ class Flicking extends Component<{
532
525
 
533
526
  const allPanels = viewport.panelManager.allPanels();
534
527
  if (!options.isConstantSize) {
535
- allPanels.forEach(panel => panel.unCacheBbox());
528
+ allPanels
529
+ .filter(panel => !!panel)
530
+ .forEach(panel => panel.unCacheBbox());
536
531
  }
537
532
 
538
533
  const shouldResetElements = options.renderOnlyVisible
@@ -767,7 +762,10 @@ class Flicking extends Component<{
767
762
  }
768
763
  panelManager.replacePanels(newPanels, newClones);
769
764
 
770
- if (!currentPanel && newPanels.length > 0) {
765
+ const currentPanelIndex = currentPanel?.getIndex() ?? -1;
766
+ const currentPanelIsRemoved = findIndex(removed, index => index === currentPanelIndex) >= 0;
767
+
768
+ if ((!currentPanel || currentPanelIsRemoved) && newPanels.length > 0) {
771
769
  viewport.setCurrentPanel(newPanels[0]);
772
770
  } else if (newPanels.length <= 0) {
773
771
  viewport.setCurrentPanel(undefined);
@@ -867,7 +865,7 @@ class Flicking extends Component<{
867
865
  const options = this.options;
868
866
 
869
867
  if (options.autoResize) {
870
- window.addEventListener("resize", this.resize);
868
+ this.autoResizer.enable();
871
869
  }
872
870
 
873
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;
@@ -242,7 +242,6 @@ class PanelManager {
242
242
  // Temporarily insert null at index to use splice()
243
243
  (panels[index] as any) = null;
244
244
  }
245
-
246
245
  const replacedPanels = panels.splice(index, newPanels.length, ...newPanels);
247
246
  const wasNonEmptyCount = replacedPanels.filter(panel => Boolean(panel)).length;
248
247
 
@@ -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 {
@@ -1267,7 +1272,7 @@ export default class Viewport {
1267
1272
 
1268
1273
  const areaPrev = (relativeHangerPosition - relativeAnchorPosition) % sumOriginalPanelSize;
1269
1274
  let sizeSum = 0;
1270
- let panelAtLeftBoundary!: Panel;
1275
+ let panelAtLeftBoundary: Panel | null = null;
1271
1276
  for (const panel of reversedPanels) {
1272
1277
  if (!panel) {
1273
1278
  continue;
@@ -1281,7 +1286,7 @@ export default class Viewport {
1281
1286
 
1282
1287
  const areaNext = (viewportSize - relativeHangerPosition + relativeAnchorPosition) % sumOriginalPanelSize;
1283
1288
  sizeSum = 0;
1284
- let panelAtRightBoundary!: Panel;
1289
+ let panelAtRightBoundary: Panel | null = null;
1285
1290
  for (const panel of panels) {
1286
1291
  if (!panel) {
1287
1292
  continue;
@@ -1294,7 +1299,8 @@ export default class Viewport {
1294
1299
  }
1295
1300
 
1296
1301
  // Need one more set of clones on prev area of original panel 0
1297
- const needCloneOnPrev = panelAtLeftBoundary.getIndex() !== 0
1302
+ const needCloneOnPrev = (panelAtLeftBoundary && panelAtRightBoundary)
1303
+ && panelAtLeftBoundary.getIndex() !== 0
1298
1304
  && panelAtLeftBoundary.getIndex() <= panelAtRightBoundary.getIndex();
1299
1305
 
1300
1306
  // Visible count of panel 0 on first screen
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;
package/src/utils.ts CHANGED
@@ -169,7 +169,7 @@ export function getProgress(pos: number, range: number[]) {
169
169
  export function findIndex<T>(iterable: T[], callback: (el: T) => boolean): number {
170
170
  for (let i = 0; i < iterable.length; i += 1) {
171
171
  const element = iterable[i];
172
- if (element && callback(element)) {
172
+ if (element != null && callback(element)) {
173
173
  return i;
174
174
  }
175
175
  }
@@ -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": [