@egjs/flicking 4.8.0 → 4.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.
- package/declaration/Flicking.d.ts +4 -1
- package/declaration/core/Viewport.d.ts +3 -1
- package/declaration/core/panel/Panel.d.ts +1 -1
- package/declaration/utils.d.ts +7 -0
- package/dist/flicking.esm.js +120 -29
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +120 -28
- package/dist/flicking.js.map +1 -1
- package/dist/flicking.min.js +2 -2
- package/dist/flicking.min.js.map +1 -1
- package/dist/flicking.pkgd.js +215 -142
- 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 +3 -3
- package/src/Flicking.ts +20 -4
- package/src/control/AxesController.ts +1 -1
- package/src/control/SnapControl.ts +15 -3
- package/src/core/Viewport.ts +23 -4
- package/src/core/panel/Panel.ts +31 -6
- package/src/renderer/Renderer.ts +2 -2
- package/src/utils.ts +42 -0
- package/TODO.md +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egjs/flicking",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.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",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test": "npm run test --prefix test/unit",
|
|
24
24
|
"test:chrome": "npm run test:chrome --prefix test/unit",
|
|
25
25
|
"test:cfc": "npm run test --prefix test/cfc",
|
|
26
|
-
"lint": "eslint
|
|
26
|
+
"lint": "eslint src/**/*.ts",
|
|
27
27
|
"lint:test": "eslint 'test/unit/**/*.ts'",
|
|
28
28
|
"jsdoc": "jsdoc -c jsdoc.json",
|
|
29
29
|
"jsdoc:watch": "npm-watch jsdoc",
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
"typescript-transform-paths": "^2.2.3"
|
|
137
137
|
},
|
|
138
138
|
"dependencies": {
|
|
139
|
-
"@egjs/axes": "^3.
|
|
139
|
+
"@egjs/axes": "^3.4.0",
|
|
140
140
|
"@egjs/component": "^3.0.1",
|
|
141
141
|
"@egjs/imready": "^1.1.3",
|
|
142
142
|
"@egjs/list-differ": "^1.0.0"
|
package/src/Flicking.ts
CHANGED
|
@@ -90,6 +90,7 @@ export interface FlickingOptions {
|
|
|
90
90
|
useResizeObserver: boolean;
|
|
91
91
|
resizeDebounce: number;
|
|
92
92
|
maxResizeDebounce: number;
|
|
93
|
+
useFractionalSize: boolean;
|
|
93
94
|
externalRenderer: ExternalRenderer | null;
|
|
94
95
|
|
|
95
96
|
// @deprecated
|
|
@@ -164,6 +165,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
164
165
|
private _useResizeObserver: FlickingOptions["useResizeObserver"];
|
|
165
166
|
private _resizeDebounce: FlickingOptions["resizeDebounce"];
|
|
166
167
|
private _maxResizeDebounce: FlickingOptions["maxResizeDebounce"];
|
|
168
|
+
private _useFractionalSize: FlickingOptions["useFractionalSize"];
|
|
167
169
|
private _externalRenderer: FlickingOptions["externalRenderer"];
|
|
168
170
|
private _renderExternal: FlickingOptions["renderExternal"];
|
|
169
171
|
|
|
@@ -665,6 +667,17 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
665
667
|
* @default 100
|
|
666
668
|
*/
|
|
667
669
|
public get maxResizeDebounce() { return this._maxResizeDebounce; }
|
|
670
|
+
/**
|
|
671
|
+
* By enabling this, Flicking will calculate all internal size with CSS width computed with getComputedStyle.
|
|
672
|
+
* This can prevent 1px offset issue in some cases where panel size has the fractional part.
|
|
673
|
+
* All sizes will have the original size before CSS {@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform transform} is applied on the element.
|
|
674
|
+
* @ko 이 옵션을 활성화할 경우, Flicking은 내부의 모든 크기를 {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect getBoundingClientRect}를 이용하여 계산합니다.
|
|
675
|
+
* 이를 통해, 패널 크기에 소수점을 포함할 경우에 발생할 수 있는 일부 1px 오프셋 이슈를 해결 가능합니다.
|
|
676
|
+
* 모든 크기는 CSS {@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform transform}이 엘리먼트에 적용되기 이전의 크기를 사용할 것입니다.
|
|
677
|
+
* @type {boolean}
|
|
678
|
+
* @default false
|
|
679
|
+
*/
|
|
680
|
+
public get useFractionalSize() { return this._useFractionalSize; }
|
|
668
681
|
/**
|
|
669
682
|
* This is an option for the frameworks(React, Vue, Angular, ...). Don't set it as it's automatically managed by Flicking.
|
|
670
683
|
* @ko 프레임워크(React, Vue, Angular, ...)에서만 사용하는 옵션으로, 자동으로 설정되므로 따로 사용하실 필요 없습니다!
|
|
@@ -814,6 +827,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
814
827
|
useResizeObserver = true,
|
|
815
828
|
resizeDebounce = 0,
|
|
816
829
|
maxResizeDebounce = 100,
|
|
830
|
+
useFractionalSize = false,
|
|
817
831
|
externalRenderer = null,
|
|
818
832
|
renderExternal = null
|
|
819
833
|
}: Partial<FlickingOptions> = {}) {
|
|
@@ -856,11 +870,12 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
856
870
|
this._useResizeObserver = useResizeObserver;
|
|
857
871
|
this._resizeDebounce = resizeDebounce;
|
|
858
872
|
this._maxResizeDebounce = maxResizeDebounce;
|
|
873
|
+
this._useFractionalSize = useFractionalSize;
|
|
859
874
|
this._externalRenderer = externalRenderer;
|
|
860
875
|
this._renderExternal = renderExternal;
|
|
861
876
|
|
|
862
877
|
// Create core components
|
|
863
|
-
this._viewport = new Viewport(getElement(root));
|
|
878
|
+
this._viewport = new Viewport(this, getElement(root));
|
|
864
879
|
this._autoResizer = new AutoResizer(this);
|
|
865
880
|
this._renderer = this._createRenderer();
|
|
866
881
|
this._camera = this._createCamera();
|
|
@@ -1487,11 +1502,12 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
1487
1502
|
const renderer = this._renderer;
|
|
1488
1503
|
const control = this._control;
|
|
1489
1504
|
const camera = this._camera;
|
|
1490
|
-
const
|
|
1505
|
+
const defaultPanel = renderer.getPanel(this._defaultIndex) || renderer.getPanel(0);
|
|
1491
1506
|
|
|
1492
|
-
if (!
|
|
1507
|
+
if (!defaultPanel) return;
|
|
1493
1508
|
|
|
1494
|
-
const nearestAnchor = camera.findNearestAnchor(
|
|
1509
|
+
const nearestAnchor = camera.findNearestAnchor(defaultPanel.position);
|
|
1510
|
+
const initialPanel = (nearestAnchor && defaultPanel.index !== nearestAnchor.panel.index) ? nearestAnchor.panel : defaultPanel;
|
|
1495
1511
|
control.setActive(initialPanel, null, false);
|
|
1496
1512
|
|
|
1497
1513
|
if (!nearestAnchor) {
|
|
@@ -111,10 +111,13 @@ class SnapControl extends Control {
|
|
|
111
111
|
targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
|
|
112
112
|
} else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
|
|
113
113
|
// Move to the adjacent panel
|
|
114
|
-
targetAnchor = this._findAdjacentAnchor(posDelta, anchorAtCamera);
|
|
114
|
+
targetAnchor = this._findAdjacentAnchor(position, posDelta, anchorAtCamera);
|
|
115
115
|
} else {
|
|
116
116
|
// Restore to active panel
|
|
117
|
-
|
|
117
|
+
return this.moveToPanel(activeAnchor.panel, {
|
|
118
|
+
duration,
|
|
119
|
+
axesEvent
|
|
120
|
+
});
|
|
118
121
|
}
|
|
119
122
|
|
|
120
123
|
this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
|
|
@@ -190,9 +193,18 @@ class SnapControl extends Control {
|
|
|
190
193
|
}
|
|
191
194
|
}
|
|
192
195
|
|
|
193
|
-
private _findAdjacentAnchor(posDelta: number, anchorAtCamera: AnchorPoint): AnchorPoint {
|
|
196
|
+
private _findAdjacentAnchor(position: number, posDelta: number, anchorAtCamera: AnchorPoint): AnchorPoint {
|
|
194
197
|
const flicking = getFlickingAttached(this._flicking);
|
|
195
198
|
const camera = flicking.camera;
|
|
199
|
+
|
|
200
|
+
if (camera.circularEnabled) {
|
|
201
|
+
const anchorIncludePosition = camera.findAnchorIncludePosition(position);
|
|
202
|
+
|
|
203
|
+
if (anchorIncludePosition && anchorIncludePosition.position !== anchorAtCamera.position) {
|
|
204
|
+
return anchorIncludePosition;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
196
208
|
const adjacentAnchor = (posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) ?? anchorAtCamera;
|
|
197
209
|
|
|
198
210
|
return adjacentAnchor;
|
package/src/core/Viewport.ts
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
* Copyright (c) 2015 NAVER Corp.
|
|
3
3
|
* egjs projects are licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import Flicking from "../Flicking";
|
|
6
|
+
import { getElementSize, getStyle, isString } from "../utils";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* A component that manages viewport size
|
|
9
10
|
* @ko 뷰포트 크기 정보를 담당하는 컴포넌트
|
|
10
11
|
*/
|
|
11
12
|
class Viewport {
|
|
13
|
+
private _flicking: Flicking;
|
|
12
14
|
private _el: HTMLElement;
|
|
13
15
|
private _width: number;
|
|
14
16
|
private _height: number;
|
|
@@ -57,7 +59,8 @@ class Viewport {
|
|
|
57
59
|
/**
|
|
58
60
|
* @param el A viewport element<ko>뷰포트 엘리먼트</ko>
|
|
59
61
|
*/
|
|
60
|
-
public constructor(el: HTMLElement) {
|
|
62
|
+
public constructor(flicking: Flicking, el: HTMLElement) {
|
|
63
|
+
this._flicking = flicking;
|
|
61
64
|
this._el = el;
|
|
62
65
|
this._width = 0;
|
|
63
66
|
this._height = 0;
|
|
@@ -120,9 +123,25 @@ class Viewport {
|
|
|
120
123
|
public resize() {
|
|
121
124
|
const el = this._el;
|
|
122
125
|
const elStyle = getStyle(el);
|
|
126
|
+
const {
|
|
127
|
+
useFractionalSize
|
|
128
|
+
} = this._flicking;
|
|
129
|
+
|
|
130
|
+
this._width = getElementSize({
|
|
131
|
+
el,
|
|
132
|
+
horizontal: true,
|
|
133
|
+
useFractionalSize,
|
|
134
|
+
useOffset: false,
|
|
135
|
+
style: elStyle
|
|
136
|
+
});
|
|
137
|
+
this._height = getElementSize({
|
|
138
|
+
el,
|
|
139
|
+
horizontal: false,
|
|
140
|
+
useFractionalSize,
|
|
141
|
+
useOffset: false,
|
|
142
|
+
style: elStyle
|
|
143
|
+
});
|
|
123
144
|
|
|
124
|
-
this._width = el.clientWidth;
|
|
125
|
-
this._height = el.clientHeight;
|
|
126
145
|
this._padding = {
|
|
127
146
|
left: elStyle.paddingLeft ? parseFloat(elStyle.paddingLeft) : 0,
|
|
128
147
|
right: elStyle.paddingRight ? parseFloat(elStyle.paddingRight) : 0,
|
package/src/core/panel/Panel.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* egjs projects are licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import Flicking from "../../Flicking";
|
|
6
|
-
import { getProgress, getStyle, parseAlign, setSize } from "../../utils";
|
|
6
|
+
import { getElementSize, getProgress, getStyle, parseAlign, setSize } from "../../utils";
|
|
7
7
|
import { ALIGN, DIRECTION } from "../../const/external";
|
|
8
8
|
import { LiteralUnion, ValueOf } from "../../type/internal";
|
|
9
9
|
|
|
@@ -308,21 +308,37 @@ class Panel {
|
|
|
308
308
|
*/
|
|
309
309
|
public resize(cached?: {
|
|
310
310
|
size: number;
|
|
311
|
-
height
|
|
311
|
+
height?: number;
|
|
312
312
|
margin: { prev: number; next: number };
|
|
313
313
|
}): this {
|
|
314
314
|
const el = this.element;
|
|
315
315
|
const flicking = this._flicking;
|
|
316
|
-
const
|
|
316
|
+
const {
|
|
317
|
+
horizontal,
|
|
318
|
+
useFractionalSize
|
|
319
|
+
} = flicking;
|
|
317
320
|
|
|
318
321
|
if (cached) {
|
|
319
322
|
this._size = cached.size;
|
|
320
323
|
this._margin = { ...cached.margin };
|
|
321
|
-
this._height = cached.height
|
|
324
|
+
this._height = cached.height ?? getElementSize({
|
|
325
|
+
el,
|
|
326
|
+
horizontal: false,
|
|
327
|
+
useFractionalSize,
|
|
328
|
+
useOffset: true,
|
|
329
|
+
style: getStyle(el)
|
|
330
|
+
});
|
|
322
331
|
} else {
|
|
323
332
|
const elStyle = getStyle(el);
|
|
324
333
|
|
|
325
|
-
this._size =
|
|
334
|
+
this._size = getElementSize({
|
|
335
|
+
el,
|
|
336
|
+
horizontal,
|
|
337
|
+
useFractionalSize,
|
|
338
|
+
useOffset: true,
|
|
339
|
+
style: elStyle
|
|
340
|
+
});
|
|
341
|
+
|
|
326
342
|
this._margin = horizontal
|
|
327
343
|
? {
|
|
328
344
|
prev: parseFloat(elStyle.marginLeft || "0"),
|
|
@@ -331,7 +347,16 @@ class Panel {
|
|
|
331
347
|
prev: parseFloat(elStyle.marginTop || "0"),
|
|
332
348
|
next: parseFloat(elStyle.marginBottom || "0")
|
|
333
349
|
};
|
|
334
|
-
|
|
350
|
+
|
|
351
|
+
this._height = horizontal
|
|
352
|
+
? getElementSize({
|
|
353
|
+
el,
|
|
354
|
+
horizontal: false,
|
|
355
|
+
useFractionalSize,
|
|
356
|
+
useOffset: true,
|
|
357
|
+
style: elStyle
|
|
358
|
+
})
|
|
359
|
+
: this._size;
|
|
335
360
|
}
|
|
336
361
|
|
|
337
362
|
this.updatePosition();
|
package/src/renderer/Renderer.ts
CHANGED
|
@@ -496,8 +496,8 @@ abstract class Renderer {
|
|
|
496
496
|
: { height: panelSize };
|
|
497
497
|
const firstPanelSizeObj = {
|
|
498
498
|
size: panelSize,
|
|
499
|
-
|
|
500
|
-
|
|
499
|
+
margin: referencePanel.margin,
|
|
500
|
+
...(!flicking.horizontal && { height: referencePanel.height})
|
|
501
501
|
};
|
|
502
502
|
|
|
503
503
|
if (!flicking.noPanelStyleOverride) {
|
package/src/utils.ts
CHANGED
|
@@ -300,6 +300,48 @@ export const range = (end: number): number[] => {
|
|
|
300
300
|
return arr;
|
|
301
301
|
};
|
|
302
302
|
|
|
303
|
+
export const getElementSize = ({
|
|
304
|
+
el,
|
|
305
|
+
horizontal,
|
|
306
|
+
useFractionalSize,
|
|
307
|
+
useOffset,
|
|
308
|
+
style
|
|
309
|
+
}: {
|
|
310
|
+
el: HTMLElement;
|
|
311
|
+
horizontal: boolean;
|
|
312
|
+
useFractionalSize: boolean;
|
|
313
|
+
useOffset: boolean;
|
|
314
|
+
style: CSSStyleDeclaration;
|
|
315
|
+
}): number => {
|
|
316
|
+
if (useFractionalSize) {
|
|
317
|
+
const baseSize = parseFloat(horizontal ? style.width : style.height);
|
|
318
|
+
const isBorderBoxSizing = style.boxSizing === "border-box";
|
|
319
|
+
const border = horizontal
|
|
320
|
+
? parseFloat(style.borderLeftWidth || "0") + parseFloat(style.borderRightWidth || "0")
|
|
321
|
+
: parseFloat(style.borderTopWidth || "0") + parseFloat(style.borderBottomWidth || "0");
|
|
322
|
+
|
|
323
|
+
if (isBorderBoxSizing) {
|
|
324
|
+
return useOffset
|
|
325
|
+
? baseSize
|
|
326
|
+
: baseSize - border;
|
|
327
|
+
} else {
|
|
328
|
+
const padding = horizontal
|
|
329
|
+
? parseFloat(style.paddingLeft || "0") + parseFloat(style.paddingRight || "0")
|
|
330
|
+
: parseFloat(style.paddingTop || "0") + parseFloat(style.paddingBottom || "0");
|
|
331
|
+
|
|
332
|
+
return useOffset
|
|
333
|
+
? baseSize + padding + border
|
|
334
|
+
: baseSize + padding;
|
|
335
|
+
}
|
|
336
|
+
} else {
|
|
337
|
+
const sizeStr = horizontal ? "Width" : "Height";
|
|
338
|
+
|
|
339
|
+
return useOffset
|
|
340
|
+
? el[`offset${sizeStr}`]
|
|
341
|
+
: el[`client${sizeStr}`];
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
|
|
303
345
|
export const setPrototypeOf = Object.setPrototypeOf || ((obj, proto) => {
|
|
304
346
|
obj.__proto__ = proto;
|
|
305
347
|
return obj;
|
package/TODO.md
DELETED