@egjs/flicking 4.5.1 → 4.6.2
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/TODO.md +3 -0
- package/declaration/Flicking.d.ts +8 -1
- package/declaration/camera/Camera.d.ts +2 -2
- package/declaration/control/Control.d.ts +1 -1
- package/declaration/core/AutoResizer.d.ts +3 -0
- package/declaration/core/ResizeWatcher.d.ts +33 -0
- package/declaration/renderer/Renderer.d.ts +13 -0
- package/dist/flicking-inline.css +45 -2
- package/dist/flicking-inline.min.css +1 -0
- package/dist/flicking.css +44 -2
- package/dist/flicking.esm.js +416 -289
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +416 -289
- package/dist/flicking.js.map +1 -1
- package/dist/flicking.min.css +1 -0
- package/dist/flicking.min.js +2 -2
- package/dist/flicking.min.js.map +1 -1
- package/dist/flicking.pkgd.js +416 -289
- package/dist/flicking.pkgd.js.map +1 -1
- package/dist/flicking.pkgd.min.js +2 -2
- package/dist/flicking.pkgd.min.js.map +1 -1
- package/package.json +13 -4
- package/sass/flicking-inline.sass +30 -0
- package/sass/flicking.sass +23 -0
- package/src/Flicking.ts +102 -21
- package/src/camera/Camera.ts +10 -14
- package/src/cfc/sync.ts +31 -23
- package/src/cfc/withFlickingMethods.ts +1 -1
- package/src/control/Control.ts +2 -2
- package/src/control/FreeControl.ts +1 -1
- package/src/control/SnapControl.ts +1 -1
- package/src/control/StrictControl.ts +1 -1
- package/src/control/states/AnimatingState.ts +4 -1
- package/src/control/states/DraggingState.ts +7 -2
- package/src/core/AutoResizer.ts +33 -0
- package/src/core/ResizeWatcher.ts +133 -0
- package/src/renderer/Renderer.ts +95 -44
- package/css/flicking-inline.css +0 -38
- package/css/flicking.css +0 -28
- package/dist/flicking-inline.css.map +0 -1
- package/dist/flicking.css.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egjs/flicking",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.2",
|
|
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",
|
|
@@ -9,7 +9,14 @@
|
|
|
9
9
|
"types": "declaration/index.d.ts",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"start": "concurrently \"rollup -w --config ./rollup.config.dev.js\" \"http-serve\"",
|
|
12
|
-
"build": "
|
|
12
|
+
"build": "run-s build:bundle build:declaration build:css printsizes",
|
|
13
|
+
"build:bundle": "rm -rf ./dist && rollup -c",
|
|
14
|
+
"build:declaration": "rm -rf ./declaration && tsc -p tsconfig.declaration.json",
|
|
15
|
+
"build:css": "run-s build:css-clear build:sass build:css-prefix build:css-min",
|
|
16
|
+
"build:css-clear": "rm -rf ./dist/*.css",
|
|
17
|
+
"build:sass": "node-sass sass/ -o dist/ -x --output-style expanded",
|
|
18
|
+
"build:css-prefix": "postcss dist/*.css --replace --use autoprefixer --no-map",
|
|
19
|
+
"build:css-min": "postcss dist/*.css --ext .min.css --use postcss-clean -d dist/ --no-map",
|
|
13
20
|
"declaration": "rm -rf declaration && tsc -p tsconfig.declaration.json",
|
|
14
21
|
"css": "postcss css/*.css --use autoprefixer postcss-clean -d dist/ -m",
|
|
15
22
|
"printsizes": "print-sizes ./dist --exclude=\\.map",
|
|
@@ -83,7 +90,7 @@
|
|
|
83
90
|
"@typescript-eslint/eslint-plugin": "^4.18.0",
|
|
84
91
|
"@typescript-eslint/eslint-plugin-tslint": "^4.18.0",
|
|
85
92
|
"@typescript-eslint/parser": "^4.18.0",
|
|
86
|
-
"autoprefixer": "^9.8.
|
|
93
|
+
"autoprefixer": "^9.8.8",
|
|
87
94
|
"babel-loader": "^8.2.2",
|
|
88
95
|
"babel-preset-env": "^1.7.0",
|
|
89
96
|
"concurrently": "^6.0.0",
|
|
@@ -103,8 +110,10 @@
|
|
|
103
110
|
"husky": "^1.3.1",
|
|
104
111
|
"jsdoc-to-mdx": "^1.0.5",
|
|
105
112
|
"karma-typescript-es6-transform": "^5.5.2",
|
|
113
|
+
"node-sass": "^7.0.1",
|
|
114
|
+
"npm-run-all": "^4.1.5",
|
|
106
115
|
"postcss-clean": "^1.2.2",
|
|
107
|
-
"postcss-cli": "^7.1.
|
|
116
|
+
"postcss-cli": "^7.1.2",
|
|
108
117
|
"print-coveralls": "^1.2.2",
|
|
109
118
|
"print-sizes": "0.0.3",
|
|
110
119
|
"pvu": "^0.6.1",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
.flicking-viewport
|
|
2
|
+
position: relative
|
|
3
|
+
overflow: hidden
|
|
4
|
+
&:not(.vertical)
|
|
5
|
+
width: 100%
|
|
6
|
+
height: 100%
|
|
7
|
+
&.vertical,
|
|
8
|
+
&.vertical>.flicking-camera
|
|
9
|
+
display: inline-block
|
|
10
|
+
&.vertical
|
|
11
|
+
&.middle>.flicking-camera>*
|
|
12
|
+
vertical-align: middle
|
|
13
|
+
&.bottom>.flicking-camera>*
|
|
14
|
+
vertical-align: bottom
|
|
15
|
+
>.flicking-camera>*
|
|
16
|
+
display: block
|
|
17
|
+
&.flicking-hidden>.flicking-camera>*
|
|
18
|
+
visibility: hidden
|
|
19
|
+
|
|
20
|
+
.flicking-camera
|
|
21
|
+
width: 100%
|
|
22
|
+
height: 100%
|
|
23
|
+
position: relative
|
|
24
|
+
z-index: 1
|
|
25
|
+
white-space: nowrap
|
|
26
|
+
will-change: transform
|
|
27
|
+
>*
|
|
28
|
+
display: inline-block
|
|
29
|
+
white-space: normal
|
|
30
|
+
vertical-align: top
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.flicking-viewport
|
|
2
|
+
position: relative
|
|
3
|
+
overflow: hidden
|
|
4
|
+
&.vertical
|
|
5
|
+
display: inline-flex
|
|
6
|
+
>.flicking-camera
|
|
7
|
+
display: inline-flex
|
|
8
|
+
flex-direction: column
|
|
9
|
+
&.flicking-hidden
|
|
10
|
+
>.flicking-camera
|
|
11
|
+
>*
|
|
12
|
+
visibility: hidden
|
|
13
|
+
|
|
14
|
+
.flicking-camera
|
|
15
|
+
width: 100%
|
|
16
|
+
height: 100%
|
|
17
|
+
display: flex
|
|
18
|
+
position: relative
|
|
19
|
+
flex-direction: row
|
|
20
|
+
z-index: 1
|
|
21
|
+
will-change: transform
|
|
22
|
+
>*
|
|
23
|
+
flex-shrink: 0
|
package/src/Flicking.ts
CHANGED
|
@@ -58,13 +58,16 @@ export interface FlickingOptions {
|
|
|
58
58
|
panelsPerView: number;
|
|
59
59
|
noPanelStyleOverride: boolean;
|
|
60
60
|
resizeOnContentsReady: boolean;
|
|
61
|
+
|
|
61
62
|
// EVENT
|
|
62
63
|
needPanelThreshold: number;
|
|
63
64
|
preventEventsBeforeInit: boolean;
|
|
65
|
+
|
|
64
66
|
// ANIMATION
|
|
65
67
|
deceleration: number;
|
|
66
68
|
duration: number;
|
|
67
69
|
easing: (x: number) => number;
|
|
70
|
+
|
|
68
71
|
// INPUT
|
|
69
72
|
inputType: string[];
|
|
70
73
|
moveType: ValueOf<typeof MOVE_TYPE> | MoveTypeOptions<ValueOf<typeof MOVE_TYPE>>;
|
|
@@ -74,14 +77,19 @@ export interface FlickingOptions {
|
|
|
74
77
|
iOSEdgeSwipeThreshold: number;
|
|
75
78
|
preventClickOnDrag: boolean;
|
|
76
79
|
disableOnInit: boolean;
|
|
80
|
+
|
|
77
81
|
// PERFORMANCE
|
|
78
82
|
renderOnlyVisible: boolean;
|
|
79
83
|
virtual: VirtualOptions | null;
|
|
84
|
+
|
|
80
85
|
// OTHERS
|
|
81
86
|
autoInit: boolean;
|
|
82
87
|
autoResize: boolean;
|
|
83
88
|
useResizeObserver: boolean;
|
|
89
|
+
resizeDebounce: number;
|
|
90
|
+
maxResizeDebounce: number;
|
|
84
91
|
externalRenderer: ExternalRenderer | null;
|
|
92
|
+
|
|
85
93
|
// @deprecated
|
|
86
94
|
renderExternal: {
|
|
87
95
|
renderer: new (options: RendererOptions) => ExternalRenderer;
|
|
@@ -150,6 +158,8 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
150
158
|
private _autoInit: FlickingOptions["autoInit"];
|
|
151
159
|
private _autoResize: FlickingOptions["autoResize"];
|
|
152
160
|
private _useResizeObserver: FlickingOptions["useResizeObserver"];
|
|
161
|
+
private _resizeDebounce: FlickingOptions["resizeDebounce"];
|
|
162
|
+
private _maxResizeDebounce: FlickingOptions["maxResizeDebounce"];
|
|
153
163
|
private _externalRenderer: FlickingOptions["externalRenderer"];
|
|
154
164
|
private _renderExternal: FlickingOptions["renderExternal"];
|
|
155
165
|
|
|
@@ -613,6 +623,26 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
613
623
|
* @default true
|
|
614
624
|
*/
|
|
615
625
|
public get useResizeObserver() { return this._useResizeObserver; }
|
|
626
|
+
/**
|
|
627
|
+
* Delays size recalculation from `autoResize` by the given time in milisecond.
|
|
628
|
+
* If the size is changed again while being delayed, it cancels the previous one and delays from the beginning again.
|
|
629
|
+
* This can increase performance by preventing `resize` being called too often.
|
|
630
|
+
* @ko `autoResize` 설정시에 호출되는 크기 재계산을 주어진 시간(단위: ms)만큼 지연시킵니다.
|
|
631
|
+
* 지연시키는 도중 크기가 다시 변경되었을 경우, 이전 것을 취소하고 주어진 시간만큼 다시 지연시킵니다.
|
|
632
|
+
* 이를 통해 `resize`가 너무 많이 호출되는 것을 방지하여 성능을 향상시킬 수 있습니다.
|
|
633
|
+
* @type {number}
|
|
634
|
+
* @default 0
|
|
635
|
+
*/
|
|
636
|
+
public get resizeDebounce() { return this._resizeDebounce; }
|
|
637
|
+
/**
|
|
638
|
+
* The maximum time for size recalculation delay when using `resizeDebounce`, in milisecond.
|
|
639
|
+
* This guarantees that size recalculation is performed at least once every (n)ms.
|
|
640
|
+
* @ko `resizeDebounce` 사용시에 크기 재계산이 지연되는 최대 시간을 지정합니다. (단위: ms)
|
|
641
|
+
* 이를 통해, 적어도 (n)ms에 한번은 크기 재계산을 수행하는 것을 보장할 수 있습니다.
|
|
642
|
+
* @type {number}
|
|
643
|
+
* @default 100
|
|
644
|
+
*/
|
|
645
|
+
public get maxResizeDebounce() { return this._maxResizeDebounce; }
|
|
616
646
|
/**
|
|
617
647
|
* This is an option for the frameworks(React, Vue, Angular, ...). Don't set it as it's automatically managed by Flicking.
|
|
618
648
|
* @ko 프레임워크(React, Vue, Angular, ...)에서만 사용하는 옵션으로, 자동으로 설정되므로 따로 사용하실 필요 없습니다!
|
|
@@ -756,6 +786,8 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
756
786
|
autoInit = true,
|
|
757
787
|
autoResize = true,
|
|
758
788
|
useResizeObserver = true,
|
|
789
|
+
resizeDebounce = 0,
|
|
790
|
+
maxResizeDebounce = 100,
|
|
759
791
|
externalRenderer = null,
|
|
760
792
|
renderExternal = null
|
|
761
793
|
}: Partial<FlickingOptions> = {}) {
|
|
@@ -794,6 +826,8 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
794
826
|
this._autoInit = autoInit;
|
|
795
827
|
this._autoResize = autoResize;
|
|
796
828
|
this._useResizeObserver = useResizeObserver;
|
|
829
|
+
this._resizeDebounce = resizeDebounce;
|
|
830
|
+
this._maxResizeDebounce = maxResizeDebounce;
|
|
797
831
|
this._externalRenderer = externalRenderer;
|
|
798
832
|
this._renderExternal = renderExternal;
|
|
799
833
|
|
|
@@ -816,10 +850,10 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
816
850
|
* @ko Flicking을 초기화하고, 디폴트 인덱스로 이동합니다
|
|
817
851
|
* 이 메소드는 `autoInit` 옵션이 true(default)일 경우 Flicking이 생성될 때 자동으로 호출됩니다
|
|
818
852
|
* @fires Flicking#ready
|
|
819
|
-
* @return {
|
|
853
|
+
* @return {Promise<void>}
|
|
820
854
|
*/
|
|
821
|
-
public
|
|
822
|
-
if (this._initialized) return;
|
|
855
|
+
public init(): Promise<void> {
|
|
856
|
+
if (this._initialized) return Promise.resolve();
|
|
823
857
|
|
|
824
858
|
const camera = this._camera;
|
|
825
859
|
const renderer = this._renderer;
|
|
@@ -828,7 +862,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
828
862
|
const originalTrigger = this.trigger;
|
|
829
863
|
const preventEventsBeforeInit = this._preventEventsBeforeInit;
|
|
830
864
|
|
|
831
|
-
camera.init(
|
|
865
|
+
camera.init();
|
|
832
866
|
virtualManager.init();
|
|
833
867
|
renderer.init(this);
|
|
834
868
|
control.init(this);
|
|
@@ -837,10 +871,10 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
837
871
|
this.trigger = () => this;
|
|
838
872
|
}
|
|
839
873
|
|
|
840
|
-
|
|
874
|
+
this._initialResize();
|
|
841
875
|
|
|
842
876
|
// Look at initial panel
|
|
843
|
-
|
|
877
|
+
this._moveToInitialPanel();
|
|
844
878
|
|
|
845
879
|
if (this._autoResize) {
|
|
846
880
|
this._autoResizer.enable();
|
|
@@ -853,16 +887,15 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
853
887
|
}
|
|
854
888
|
renderer.checkPanelContentsReady(renderer.panels);
|
|
855
889
|
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
return;
|
|
890
|
+
return renderer.render().then(() => {
|
|
891
|
+
// Done initializing & emit ready event
|
|
892
|
+
this._plugins.forEach(plugin => plugin.init(this));
|
|
893
|
+
this._initialized = true;
|
|
894
|
+
if (preventEventsBeforeInit) {
|
|
895
|
+
this.trigger = originalTrigger;
|
|
896
|
+
}
|
|
897
|
+
this.trigger(new ComponentEvent(EVENTS.READY));
|
|
898
|
+
});
|
|
866
899
|
}
|
|
867
900
|
|
|
868
901
|
/**
|
|
@@ -1379,7 +1412,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
1379
1412
|
console.warn("\"circular\" and \"bound\" option cannot be used together, ignoring bound.");
|
|
1380
1413
|
}
|
|
1381
1414
|
|
|
1382
|
-
return new Camera({
|
|
1415
|
+
return new Camera(this, {
|
|
1383
1416
|
align: this._align
|
|
1384
1417
|
});
|
|
1385
1418
|
}
|
|
@@ -1420,18 +1453,66 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
1420
1453
|
});
|
|
1421
1454
|
}
|
|
1422
1455
|
|
|
1423
|
-
private
|
|
1456
|
+
private _moveToInitialPanel(): void {
|
|
1424
1457
|
const renderer = this._renderer;
|
|
1425
1458
|
const control = this._control;
|
|
1459
|
+
const camera = this._camera;
|
|
1426
1460
|
const initialPanel = renderer.getPanel(this._defaultIndex) || renderer.getPanel(0);
|
|
1427
1461
|
|
|
1428
1462
|
if (!initialPanel) return;
|
|
1429
1463
|
|
|
1464
|
+
const nearestAnchor = camera.findNearestAnchor(initialPanel.position);
|
|
1430
1465
|
control.setActive(initialPanel, null, false);
|
|
1431
1466
|
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
}
|
|
1467
|
+
if (!nearestAnchor) {
|
|
1468
|
+
throw new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(initialPanel.position), ERROR.CODE.POSITION_NOT_REACHABLE);
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
let position = initialPanel.position;
|
|
1472
|
+
|
|
1473
|
+
if (!camera.canReach(initialPanel)) {
|
|
1474
|
+
position = nearestAnchor.position;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
camera.lookAt(position);
|
|
1478
|
+
control.updateInput();
|
|
1479
|
+
camera.updateOffset();
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
private _initialResize() {
|
|
1483
|
+
const viewport = this._viewport;
|
|
1484
|
+
const renderer = this._renderer;
|
|
1485
|
+
const camera = this._camera;
|
|
1486
|
+
const control = this._control;
|
|
1487
|
+
|
|
1488
|
+
this.trigger(new ComponentEvent(EVENTS.BEFORE_RESIZE, {
|
|
1489
|
+
width: 0,
|
|
1490
|
+
height: 0,
|
|
1491
|
+
element: viewport.element
|
|
1492
|
+
}));
|
|
1493
|
+
|
|
1494
|
+
viewport.resize();
|
|
1495
|
+
renderer.updatePanelSize();
|
|
1496
|
+
camera.updateAlignPos();
|
|
1497
|
+
camera.updateRange();
|
|
1498
|
+
camera.updateAnchors();
|
|
1499
|
+
camera.updateOffset();
|
|
1500
|
+
control.updateInput();
|
|
1501
|
+
|
|
1502
|
+
const newWidth = viewport.width;
|
|
1503
|
+
const newHeight = viewport.height;
|
|
1504
|
+
const sizeChanged = newWidth !== 0 || newHeight !== 0;
|
|
1505
|
+
|
|
1506
|
+
this.trigger(new ComponentEvent(EVENTS.AFTER_RESIZE, {
|
|
1507
|
+
width: viewport.width,
|
|
1508
|
+
height: viewport.height,
|
|
1509
|
+
prev: {
|
|
1510
|
+
width: 0,
|
|
1511
|
+
height: 0
|
|
1512
|
+
},
|
|
1513
|
+
sizeChanged,
|
|
1514
|
+
element: viewport.element
|
|
1515
|
+
}));
|
|
1435
1516
|
}
|
|
1436
1517
|
}
|
|
1437
1518
|
|
package/src/camera/Camera.ts
CHANGED
|
@@ -27,7 +27,7 @@ class Camera {
|
|
|
27
27
|
private _align: FlickingOptions["align"];
|
|
28
28
|
|
|
29
29
|
// Internal states
|
|
30
|
-
private _flicking: Flicking
|
|
30
|
+
private _flicking: Flicking;
|
|
31
31
|
private _mode: CameraMode;
|
|
32
32
|
private _el: HTMLElement;
|
|
33
33
|
private _transform: string;
|
|
@@ -231,10 +231,10 @@ class Camera {
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
/** */
|
|
234
|
-
public constructor({
|
|
234
|
+
public constructor(flicking: Flicking, {
|
|
235
235
|
align = ALIGN.CENTER
|
|
236
236
|
}: Partial<CameraOptions> = {}) {
|
|
237
|
-
this._flicking =
|
|
237
|
+
this._flicking = flicking;
|
|
238
238
|
this._resetInternalValues();
|
|
239
239
|
|
|
240
240
|
// Options
|
|
@@ -244,17 +244,13 @@ class Camera {
|
|
|
244
244
|
/**
|
|
245
245
|
* Initialize Camera
|
|
246
246
|
* @ko Camera를 초기화합니다
|
|
247
|
-
* @param {Flicking} flicking An instance of {@link Flicking}<ko>Flicking의 인스턴스</ko>
|
|
248
|
-
* @chainable
|
|
249
247
|
* @throws {FlickingError}
|
|
250
248
|
* {@link ERROR_CODE VAL_MUST_NOT_NULL} If the camera element(`.flicking-camera`) does not exist inside viewport element
|
|
251
249
|
* <ko>{@link ERROR_CODE VAL_MUST_NOT_NULL} 뷰포트 엘리먼트 내부에 카메라 엘리먼트(`.flicking-camera`)가 존재하지 않을 경우</ko>
|
|
252
250
|
* @return {this}
|
|
253
251
|
*/
|
|
254
|
-
public init(
|
|
255
|
-
this._flicking
|
|
256
|
-
|
|
257
|
-
const viewportEl = flicking.viewport.element;
|
|
252
|
+
public init(): this {
|
|
253
|
+
const viewportEl = this._flicking.viewport.element;
|
|
258
254
|
|
|
259
255
|
checkExistence(viewportEl.firstElementChild, "First element child of the viewport element");
|
|
260
256
|
this._el = viewportEl.firstElementChild as HTMLElement;
|
|
@@ -271,7 +267,6 @@ class Camera {
|
|
|
271
267
|
* @return {void}
|
|
272
268
|
*/
|
|
273
269
|
public destroy(): this {
|
|
274
|
-
this._flicking = null;
|
|
275
270
|
this._resetInternalValues();
|
|
276
271
|
return this;
|
|
277
272
|
}
|
|
@@ -294,12 +289,13 @@ class Camera {
|
|
|
294
289
|
this._refreshVisiblePanels();
|
|
295
290
|
this._checkNeedPanel();
|
|
296
291
|
this._checkReachEnd(prevPos, pos);
|
|
297
|
-
this.applyTransform();
|
|
298
292
|
|
|
299
293
|
if (toggled) {
|
|
300
294
|
void flicking.renderer.render().then(() => {
|
|
301
295
|
this.updateOffset();
|
|
302
296
|
});
|
|
297
|
+
} else {
|
|
298
|
+
this.applyTransform();
|
|
303
299
|
}
|
|
304
300
|
}
|
|
305
301
|
|
|
@@ -476,8 +472,6 @@ class Camera {
|
|
|
476
472
|
panels.forEach(panel => panel.updateCircularToggleDirection());
|
|
477
473
|
}
|
|
478
474
|
|
|
479
|
-
this.updateOffset();
|
|
480
|
-
|
|
481
475
|
return this;
|
|
482
476
|
}
|
|
483
477
|
|
|
@@ -570,12 +564,14 @@ class Camera {
|
|
|
570
564
|
/**
|
|
571
565
|
* Apply "transform" style with the current position to camera element
|
|
572
566
|
* @ko 현재 위치를 기준으로한 transform 스타일을 카메라 엘리먼트에 적용합니다.
|
|
573
|
-
* @chainable
|
|
574
567
|
* @return {this}
|
|
575
568
|
*/
|
|
576
569
|
public applyTransform(): this {
|
|
577
570
|
const el = this._el;
|
|
578
571
|
const flicking = getFlickingAttached(this._flicking);
|
|
572
|
+
const renderer = flicking.renderer;
|
|
573
|
+
|
|
574
|
+
if (renderer.rendering) return this;
|
|
579
575
|
|
|
580
576
|
const actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
|
|
581
577
|
|
package/src/cfc/sync.ts
CHANGED
|
@@ -2,12 +2,16 @@ import { DiffResult } from "@egjs/list-differ";
|
|
|
2
2
|
|
|
3
3
|
import Flicking from "../Flicking";
|
|
4
4
|
import Renderer from "../renderer/Renderer";
|
|
5
|
+
import Panel from "../core/panel/Panel";
|
|
5
6
|
|
|
6
7
|
export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]) => {
|
|
7
8
|
const renderer = flicking.renderer;
|
|
8
9
|
const panels = renderer.panels;
|
|
9
10
|
const prevList = [...diffResult.prevList];
|
|
10
11
|
|
|
12
|
+
const added: Panel[] = [];
|
|
13
|
+
const removed: Panel[] = [];
|
|
14
|
+
|
|
11
15
|
if (diffResult.removed.length > 0) {
|
|
12
16
|
let endIdx = -1;
|
|
13
17
|
let prevIdx = -1;
|
|
@@ -18,7 +22,7 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
|
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
if (prevIdx >= 0 && removedIdx !== prevIdx - 1) {
|
|
21
|
-
batchRemove(renderer, prevIdx, endIdx + 1);
|
|
25
|
+
removed.push(...batchRemove(renderer, prevIdx, endIdx + 1));
|
|
22
26
|
|
|
23
27
|
endIdx = removedIdx;
|
|
24
28
|
prevIdx = removedIdx;
|
|
@@ -29,30 +33,30 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
|
|
|
29
33
|
prevList.splice(removedIdx, 1);
|
|
30
34
|
});
|
|
31
35
|
|
|
32
|
-
batchRemove(renderer, prevIdx, endIdx + 1);
|
|
36
|
+
removed.push(...batchRemove(renderer, prevIdx, endIdx + 1));
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
diffResult.ordered.forEach(([
|
|
36
|
-
const prevPanel = panels[
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (indexDiff > 0) {
|
|
40
|
-
const middlePanels = panels.slice(prevIdx + 1, newIdx + 1);
|
|
41
|
-
|
|
42
|
-
prevPanel.increaseIndex(indexDiff);
|
|
43
|
-
middlePanels.forEach(panel => panel.decreaseIndex(1));
|
|
44
|
-
} else {
|
|
45
|
-
const middlePanels = panels.slice(newIdx, prevIdx);
|
|
46
|
-
|
|
47
|
-
prevPanel.decreaseIndex(-indexDiff);
|
|
48
|
-
middlePanels.forEach(panel => panel.increaseIndex(1));
|
|
49
|
-
}
|
|
50
|
-
// Update position
|
|
51
|
-
prevPanel.resize();
|
|
39
|
+
diffResult.ordered.forEach(([from, to]) => {
|
|
40
|
+
const prevPanel = panels.splice(from, 1)[0];
|
|
41
|
+
panels.splice(to, 0, prevPanel);
|
|
52
42
|
});
|
|
53
43
|
|
|
54
44
|
if (diffResult.ordered.length > 0) {
|
|
45
|
+
panels.forEach((panel, idx) => {
|
|
46
|
+
const indexDiff = idx - panel.index;
|
|
47
|
+
|
|
48
|
+
if (indexDiff > 0) {
|
|
49
|
+
panel.increaseIndex(indexDiff);
|
|
50
|
+
} else {
|
|
51
|
+
panel.decreaseIndex(-indexDiff);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
55
|
panels.sort((panel1, panel2) => panel1.index - panel2.index);
|
|
56
|
+
|
|
57
|
+
panels.forEach(panel => {
|
|
58
|
+
panel.updatePosition();
|
|
59
|
+
});
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
if (diffResult.added.length > 0) {
|
|
@@ -67,7 +71,7 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
|
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
if (prevIdx >= 0 && addedIdx !== prevIdx + 1) {
|
|
70
|
-
batchInsert(renderer, diffResult, addedElements, startIdx, idx + 1);
|
|
74
|
+
added.push(...batchInsert(renderer, diffResult, addedElements, startIdx, idx + 1));
|
|
71
75
|
|
|
72
76
|
startIdx = -1;
|
|
73
77
|
prevIdx = -1;
|
|
@@ -77,13 +81,17 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
|
|
|
77
81
|
});
|
|
78
82
|
|
|
79
83
|
if (startIdx >= 0) {
|
|
80
|
-
batchInsert(renderer, diffResult, addedElements, startIdx);
|
|
84
|
+
added.push(...batchInsert(renderer, diffResult, addedElements, startIdx));
|
|
81
85
|
}
|
|
82
86
|
}
|
|
87
|
+
|
|
88
|
+
if (diffResult.added.length > 0 || diffResult.removed.length > 0) {
|
|
89
|
+
renderer.updateAfterPanelChange(added, removed);
|
|
90
|
+
}
|
|
83
91
|
};
|
|
84
92
|
|
|
85
93
|
const batchInsert = (renderer: Renderer, diffResult: DiffResult<any>, addedElements: any[], startIdx: number, endIdx?: number) => {
|
|
86
|
-
renderer.
|
|
94
|
+
return renderer.batchInsertDefer(
|
|
87
95
|
...diffResult.added.slice(startIdx, endIdx).map((index, elIdx) => ({ index, elements: [addedElements[elIdx]], hasDOMInElements: false }))
|
|
88
96
|
);
|
|
89
97
|
};
|
|
@@ -91,6 +99,6 @@ const batchInsert = (renderer: Renderer, diffResult: DiffResult<any>, addedEleme
|
|
|
91
99
|
const batchRemove = (renderer: Renderer, startIdx: number, endIdx?: number) => {
|
|
92
100
|
const removed = renderer.panels.slice(startIdx, endIdx);
|
|
93
101
|
|
|
94
|
-
renderer.
|
|
102
|
+
return renderer.batchRemoveDefer({ index: startIdx, deleteCount: removed.length, hasDOMInElements: false });
|
|
95
103
|
};
|
|
96
104
|
|
|
@@ -19,7 +19,7 @@ import Flicking from "../Flicking";
|
|
|
19
19
|
*/
|
|
20
20
|
const withFlickingMethods = (prototype: any, flickingName: string) => {
|
|
21
21
|
[Component.prototype, Flicking.prototype].forEach(proto => {
|
|
22
|
-
Object.getOwnPropertyNames(proto).filter(name => !prototype[name] &&
|
|
22
|
+
Object.getOwnPropertyNames(proto).filter(name => !prototype[name] && name.indexOf("_") !== 0 && name !== "constructor")
|
|
23
23
|
.forEach((name: string) => {
|
|
24
24
|
const descriptor = Object.getOwnPropertyDescriptor(proto, name)!;
|
|
25
25
|
|
package/src/control/Control.ts
CHANGED
|
@@ -171,7 +171,7 @@ abstract class Control {
|
|
|
171
171
|
* @chainable
|
|
172
172
|
* @return {Promise<void>}
|
|
173
173
|
*/
|
|
174
|
-
public updatePosition(
|
|
174
|
+
public updatePosition(progressInPanel: number): void { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
175
175
|
const flicking = getFlickingAttached(this._flicking);
|
|
176
176
|
const camera = flicking.camera;
|
|
177
177
|
const activePanel = this._activePanel;
|
|
@@ -321,7 +321,7 @@ abstract class Control {
|
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
protected _triggerIndexChangeEvent(panel: Panel, position: number, axesEvent?: OnRelease)
|
|
324
|
+
protected _triggerIndexChangeEvent(panel: Panel, position: number, axesEvent?: OnRelease) {
|
|
325
325
|
const flicking = getFlickingAttached(this._flicking);
|
|
326
326
|
const triggeringEvent = panel !== this._activePanel ? EVENTS.WILL_CHANGE : EVENTS.WILL_RESTORE;
|
|
327
327
|
const camera = flicking.camera;
|
|
@@ -106,7 +106,7 @@ class FreeControl extends Control {
|
|
|
106
106
|
* </ko>
|
|
107
107
|
* @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
|
|
108
108
|
*/
|
|
109
|
-
public
|
|
109
|
+
public moveToPosition(position: number, duration: number, axesEvent?: OnRelease) {
|
|
110
110
|
const flicking = getFlickingAttached(this._flicking);
|
|
111
111
|
|
|
112
112
|
const camera = flicking.camera;
|
|
@@ -84,7 +84,7 @@ class SnapControl extends Control {
|
|
|
84
84
|
* </ko>
|
|
85
85
|
* @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
|
|
86
86
|
*/
|
|
87
|
-
public
|
|
87
|
+
public moveToPosition(position: number, duration: number, axesEvent?: OnRelease) {
|
|
88
88
|
const flicking = getFlickingAttached(this._flicking);
|
|
89
89
|
const camera = flicking.camera;
|
|
90
90
|
const activeAnchor = camera.findActiveAnchor();
|
|
@@ -187,7 +187,7 @@ class StrictControl extends Control {
|
|
|
187
187
|
* </ko>
|
|
188
188
|
* @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
|
|
189
189
|
*/
|
|
190
|
-
public
|
|
190
|
+
public moveToPosition(position: number, duration: number, axesEvent?: OnRelease) {
|
|
191
191
|
const flicking = getFlickingAttached(this._flicking);
|
|
192
192
|
const camera = flicking.camera;
|
|
193
193
|
const activePanel = this._activePanel;
|
|
@@ -65,7 +65,10 @@ class AnimatingState extends State {
|
|
|
65
65
|
axesEvent
|
|
66
66
|
}));
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
const targetPanel = this._targetPanel;
|
|
69
|
+
if (targetPanel) {
|
|
70
|
+
control.setActive(targetPanel, control.activePanel, axesEvent.isTrusted);
|
|
71
|
+
}
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
|
|
@@ -34,7 +34,7 @@ class DraggingState extends State {
|
|
|
34
34
|
this._moveToChangedPosition(ctx);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
public onRelease(ctx: Parameters<State["onRelease"]>[0])
|
|
37
|
+
public onRelease(ctx: Parameters<State["onRelease"]>[0]) {
|
|
38
38
|
const { flicking, axesEvent, transitTo } = ctx;
|
|
39
39
|
|
|
40
40
|
// Update last position to cope with Axes's animating behavior
|
|
@@ -55,7 +55,12 @@ class DraggingState extends State {
|
|
|
55
55
|
const position = axesEvent.destPos[AXES.POSITION_KEY];
|
|
56
56
|
const duration = Math.max(axesEvent.duration, flicking.duration);
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
try {
|
|
59
|
+
void control.moveToPosition(position, duration, axesEvent);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
transitTo(STATE_TYPE.IDLE);
|
|
62
|
+
axesEvent.setTo({ [AXES.POSITION_KEY]: flicking.camera.position }, 0);
|
|
63
|
+
}
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
|
package/src/core/AutoResizer.ts
CHANGED
|
@@ -8,6 +8,8 @@ class AutoResizer {
|
|
|
8
8
|
private _flicking: Flicking;
|
|
9
9
|
private _enabled: boolean;
|
|
10
10
|
private _resizeObserver: ResizeObserver | null;
|
|
11
|
+
private _resizeTimer: number;
|
|
12
|
+
private _maxResizeDebounceTimer: number;
|
|
11
13
|
|
|
12
14
|
public get enabled() { return this._enabled; }
|
|
13
15
|
|
|
@@ -15,6 +17,8 @@ class AutoResizer {
|
|
|
15
17
|
this._flicking = flicking;
|
|
16
18
|
this._enabled = false;
|
|
17
19
|
this._resizeObserver = null;
|
|
20
|
+
this._resizeTimer = -1;
|
|
21
|
+
this._maxResizeDebounceTimer = -1;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
public enable(): this {
|
|
@@ -61,6 +65,35 @@ class AutoResizer {
|
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
private _onResize = () => {
|
|
68
|
+
const flicking = this._flicking;
|
|
69
|
+
const resizeDebounce = flicking.resizeDebounce;
|
|
70
|
+
const maxResizeDebounce = flicking.maxResizeDebounce;
|
|
71
|
+
|
|
72
|
+
if (resizeDebounce <= 0) {
|
|
73
|
+
void flicking.resize();
|
|
74
|
+
} else {
|
|
75
|
+
if (this._maxResizeDebounceTimer <= 0) {
|
|
76
|
+
if (maxResizeDebounce > 0 && maxResizeDebounce >= resizeDebounce) {
|
|
77
|
+
this._maxResizeDebounceTimer = window.setTimeout(this._doScheduledResize, maxResizeDebounce);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (this._resizeTimer > 0) {
|
|
82
|
+
clearTimeout(this._resizeTimer);
|
|
83
|
+
this._resizeTimer = 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this._resizeTimer = window.setTimeout(this._doScheduledResize, resizeDebounce);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
private _doScheduledResize = () => {
|
|
91
|
+
clearTimeout(this._resizeTimer);
|
|
92
|
+
clearTimeout(this._maxResizeDebounceTimer);
|
|
93
|
+
|
|
94
|
+
this._maxResizeDebounceTimer = -1;
|
|
95
|
+
this._resizeTimer = -1;
|
|
96
|
+
|
|
64
97
|
void this._flicking.resize();
|
|
65
98
|
};
|
|
66
99
|
|