@egjs/flicking 4.8.1 → 4.9.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.
@@ -64,6 +64,7 @@ export interface FlickingOptions {
64
64
  useResizeObserver: boolean;
65
65
  resizeDebounce: number;
66
66
  maxResizeDebounce: number;
67
+ useFractionalSize: boolean;
67
68
  externalRenderer: ExternalRenderer | null;
68
69
  renderExternal: {
69
70
  renderer: new (options: RendererOptions) => ExternalRenderer;
@@ -110,6 +111,7 @@ declare class Flicking extends Component<FlickingEvents> {
110
111
  private _useResizeObserver;
111
112
  private _resizeDebounce;
112
113
  private _maxResizeDebounce;
114
+ private _useFractionalSize;
113
115
  private _externalRenderer;
114
116
  private _renderExternal;
115
117
  private _initialized;
@@ -165,6 +167,7 @@ declare class Flicking extends Component<FlickingEvents> {
165
167
  get useResizeObserver(): FlickingOptions["useResizeObserver"];
166
168
  get resizeDebounce(): number;
167
169
  get maxResizeDebounce(): number;
170
+ get useFractionalSize(): boolean;
168
171
  get externalRenderer(): ExternalRenderer;
169
172
  get renderExternal(): {
170
173
  renderer: new (options: RendererOptions) => ExternalRenderer;
@@ -197,7 +200,7 @@ declare class Flicking extends Component<FlickingEvents> {
197
200
  set renderOnlyVisible(val: FlickingOptions["renderOnlyVisible"]);
198
201
  set autoResize(val: FlickingOptions["autoResize"]);
199
202
  set useResizeObserver(val: FlickingOptions["useResizeObserver"]);
200
- constructor(root: HTMLElement | string, { align, defaultIndex, horizontal, circular, circularFallback, bound, adaptive, panelsPerView, noPanelStyleOverride, resizeOnContentsReady, nested, needPanelThreshold, preventEventsBeforeInit, deceleration, duration, easing, inputType, moveType, threshold, interruptable, bounce, iOSEdgeSwipeThreshold, preventClickOnDrag, disableOnInit, changeOnHold, renderOnlyVisible, virtual, autoInit, autoResize, useResizeObserver, resizeDebounce, maxResizeDebounce, externalRenderer, renderExternal }?: Partial<FlickingOptions>);
203
+ constructor(root: HTMLElement | string, { align, defaultIndex, horizontal, circular, circularFallback, bound, adaptive, panelsPerView, noPanelStyleOverride, resizeOnContentsReady, nested, needPanelThreshold, preventEventsBeforeInit, deceleration, duration, easing, inputType, moveType, threshold, interruptable, bounce, iOSEdgeSwipeThreshold, preventClickOnDrag, disableOnInit, changeOnHold, renderOnlyVisible, virtual, autoInit, autoResize, useResizeObserver, resizeDebounce, maxResizeDebounce, useFractionalSize, externalRenderer, renderExternal }?: Partial<FlickingOptions>);
201
204
  init(): Promise<void>;
202
205
  destroy(): void;
203
206
  prev(duration?: number): Promise<void>;
@@ -27,6 +27,7 @@ declare class AxesController {
27
27
  destroy(): void;
28
28
  enable(): this;
29
29
  disable(): this;
30
+ release(): this;
30
31
  update(controlParams: ControlParams): this;
31
32
  addPreventClickHandler(): this;
32
33
  removePreventClickHandler(): this;
@@ -19,6 +19,7 @@ declare abstract class Control {
19
19
  destroy(): void;
20
20
  enable(): this;
21
21
  disable(): this;
22
+ release(): this;
22
23
  updatePosition(progressInPanel: number): void;
23
24
  updateInput(): this;
24
25
  resetActive(): this;
@@ -1,4 +1,6 @@
1
+ import Flicking from "../Flicking";
1
2
  declare class Viewport {
3
+ private _flicking;
2
4
  private _el;
3
5
  private _width;
4
6
  private _height;
@@ -13,7 +15,7 @@ declare class Viewport {
13
15
  top: number;
14
16
  bottom: number;
15
17
  };
16
- constructor(el: HTMLElement);
18
+ constructor(flicking: Flicking, el: HTMLElement);
17
19
  setSize({ width, height }: Partial<{
18
20
  width: number | string;
19
21
  height: number | string;
@@ -60,7 +60,7 @@ declare class Panel {
60
60
  markForHide(): void;
61
61
  resize(cached?: {
62
62
  size: number;
63
- height: number;
63
+ height?: number;
64
64
  margin: {
65
65
  prev: number;
66
66
  next: number;
@@ -35,4 +35,11 @@ export declare const setSize: (el: HTMLElement, { width, height }: Partial<{
35
35
  export declare const isBetween: (val: number, min: number, max: number) => boolean;
36
36
  export declare const circulateIndex: (index: number, max: number) => number;
37
37
  export declare const range: (end: number) => number[];
38
+ export declare const getElementSize: ({ el, horizontal, useFractionalSize, useOffset, style }: {
39
+ el: HTMLElement;
40
+ horizontal: boolean;
41
+ useFractionalSize: boolean;
42
+ useOffset: boolean;
43
+ style: CSSStyleDeclaration;
44
+ }) => number;
38
45
  export declare const setPrototypeOf: (o: any, proto: object) => any;
@@ -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: 4.8.1
7
+ version: 4.9.2
8
8
  */
9
9
  import Component, { ComponentEvent } from '@egjs/component';
10
10
  import Axes, { PanInput } from '@egjs/axes';
@@ -767,6 +767,29 @@ var range = function (end) {
767
767
 
768
768
  return arr;
769
769
  };
770
+ var getElementSize = function (_a) {
771
+ var el = _a.el,
772
+ horizontal = _a.horizontal,
773
+ useFractionalSize = _a.useFractionalSize,
774
+ useOffset = _a.useOffset,
775
+ style = _a.style;
776
+
777
+ if (useFractionalSize) {
778
+ var baseSize = parseFloat(horizontal ? style.width : style.height);
779
+ var isBorderBoxSizing = style.boxSizing === "border-box";
780
+ var border = horizontal ? parseFloat(style.borderLeftWidth || "0") + parseFloat(style.borderRightWidth || "0") : parseFloat(style.borderTopWidth || "0") + parseFloat(style.borderBottomWidth || "0");
781
+
782
+ if (isBorderBoxSizing) {
783
+ return useOffset ? baseSize : baseSize - border;
784
+ } else {
785
+ var padding = horizontal ? parseFloat(style.paddingLeft || "0") + parseFloat(style.paddingRight || "0") : parseFloat(style.paddingTop || "0") + parseFloat(style.paddingBottom || "0");
786
+ return useOffset ? baseSize + padding + border : baseSize + padding;
787
+ }
788
+ } else {
789
+ var sizeStr = horizontal ? "Width" : "Height";
790
+ return useOffset ? el["offset" + sizeStr] : el["client" + sizeStr];
791
+ }
792
+ };
770
793
  var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
771
794
  obj.__proto__ = proto;
772
795
  return obj;
@@ -817,10 +840,6 @@ function (_super) {
817
840
  return FlickingError;
818
841
  }(Error);
819
842
 
820
- /*
821
- * Copyright (c) 2015 NAVER Corp.
822
- * egjs projects are licensed under the MIT license
823
- */
824
843
  /**
825
844
  * A component that manages viewport size
826
845
  * @ko 뷰포트 크기 정보를 담당하는 컴포넌트
@@ -832,7 +851,8 @@ function () {
832
851
  /**
833
852
  * @param el A viewport element<ko>뷰포트 엘리먼트</ko>
834
853
  */
835
- function Viewport(el) {
854
+ function Viewport(flicking, el) {
855
+ this._flicking = flicking;
836
856
  this._el = el;
837
857
  this._width = 0;
838
858
  this._height = 0;
@@ -948,8 +968,21 @@ function () {
948
968
  __proto.resize = function () {
949
969
  var el = this._el;
950
970
  var elStyle = getStyle(el);
951
- this._width = el.clientWidth;
952
- this._height = el.clientHeight;
971
+ var useFractionalSize = this._flicking.useFractionalSize;
972
+ this._width = getElementSize({
973
+ el: el,
974
+ horizontal: true,
975
+ useFractionalSize: useFractionalSize,
976
+ useOffset: false,
977
+ style: elStyle
978
+ });
979
+ this._height = getElementSize({
980
+ el: el,
981
+ horizontal: false,
982
+ useFractionalSize: useFractionalSize,
983
+ useOffset: false,
984
+ style: elStyle
985
+ });
953
986
  this._padding = {
954
987
  left: elStyle.paddingLeft ? parseFloat(elStyle.paddingLeft) : 0,
955
988
  right: elStyle.paddingRight ? parseFloat(elStyle.paddingRight) : 0,
@@ -2417,6 +2450,20 @@ function () {
2417
2450
  (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.disable();
2418
2451
  return this;
2419
2452
  };
2453
+ /**
2454
+ * Releases ongoing user input (mouse/touch)
2455
+ * @ko 사용자의 현재 입력(마우스/터치)를 중단시킵니다
2456
+ * @chainable
2457
+ * @return {this}
2458
+ */
2459
+
2460
+
2461
+ __proto.release = function () {
2462
+ var _a;
2463
+
2464
+ (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.release();
2465
+ return this;
2466
+ };
2420
2467
  /**
2421
2468
  * Update {@link https://naver.github.io/egjs-axes/ @egjs/axes}'s state
2422
2469
  * @ko {@link https://naver.github.io/egjs-axes/ @egjs/axes}의 상태를 갱신합니다
@@ -2728,6 +2775,19 @@ function () {
2728
2775
 
2729
2776
  return this;
2730
2777
  };
2778
+ /**
2779
+ * Releases ongoing user input (mouse/touch)
2780
+ * @ko 사용자의 현재 입력(마우스/터치)를 중단시킵니다
2781
+ * @chainable
2782
+ * @return {this}
2783
+ */
2784
+
2785
+
2786
+ __proto.release = function () {
2787
+ this._controller.release();
2788
+
2789
+ return this;
2790
+ };
2731
2791
  /**
2732
2792
  * Update position after resizing
2733
2793
  * @ko resize 이후에 position을 업데이트합니다
@@ -5449,11 +5509,13 @@ function () {
5449
5509
  } : {
5450
5510
  height: panelSize
5451
5511
  };
5452
- var firstPanelSizeObj = {
5512
+
5513
+ var firstPanelSizeObj = __assign({
5453
5514
  size: panelSize,
5454
- height: referencePanel.height,
5455
5515
  margin: referencePanel.margin
5456
- };
5516
+ }, !flicking.horizontal && {
5517
+ height: referencePanel.height
5518
+ });
5457
5519
 
5458
5520
  if (!flicking.noPanelStyleOverride) {
5459
5521
  this._strategy.updatePanelSizes(flicking, panelSizeObj);
@@ -5987,17 +6049,32 @@ function () {
5987
6049
 
5988
6050
 
5989
6051
  __proto.resize = function (cached) {
6052
+ var _a;
6053
+
5990
6054
  var el = this.element;
5991
6055
  var flicking = this._flicking;
5992
- var horizontal = flicking.horizontal;
6056
+ var horizontal = flicking.horizontal,
6057
+ useFractionalSize = flicking.useFractionalSize;
5993
6058
 
5994
6059
  if (cached) {
5995
6060
  this._size = cached.size;
5996
6061
  this._margin = __assign({}, cached.margin);
5997
- this._height = cached.height;
6062
+ this._height = (_a = cached.height) !== null && _a !== void 0 ? _a : getElementSize({
6063
+ el: el,
6064
+ horizontal: false,
6065
+ useFractionalSize: useFractionalSize,
6066
+ useOffset: true,
6067
+ style: getStyle(el)
6068
+ });
5998
6069
  } else {
5999
6070
  var elStyle = getStyle(el);
6000
- this._size = horizontal ? el.offsetWidth : el.offsetHeight;
6071
+ this._size = getElementSize({
6072
+ el: el,
6073
+ horizontal: horizontal,
6074
+ useFractionalSize: useFractionalSize,
6075
+ useOffset: true,
6076
+ style: elStyle
6077
+ });
6001
6078
  this._margin = horizontal ? {
6002
6079
  prev: parseFloat(elStyle.marginLeft || "0"),
6003
6080
  next: parseFloat(elStyle.marginRight || "0")
@@ -6005,7 +6082,13 @@ function () {
6005
6082
  prev: parseFloat(elStyle.marginTop || "0"),
6006
6083
  next: parseFloat(elStyle.marginBottom || "0")
6007
6084
  };
6008
- this._height = horizontal ? el.offsetHeight : this._size;
6085
+ this._height = horizontal ? getElementSize({
6086
+ el: el,
6087
+ horizontal: false,
6088
+ useFractionalSize: useFractionalSize,
6089
+ useOffset: true,
6090
+ style: elStyle
6091
+ }) : this._size;
6009
6092
  }
6010
6093
 
6011
6094
  this.updatePosition();
@@ -6701,10 +6784,12 @@ function (_super) {
6701
6784
  resizeDebounce = _8 === void 0 ? 0 : _8,
6702
6785
  _9 = _b.maxResizeDebounce,
6703
6786
  maxResizeDebounce = _9 === void 0 ? 100 : _9,
6704
- _10 = _b.externalRenderer,
6705
- externalRenderer = _10 === void 0 ? null : _10,
6706
- _11 = _b.renderExternal,
6707
- renderExternal = _11 === void 0 ? null : _11;
6787
+ _10 = _b.useFractionalSize,
6788
+ useFractionalSize = _10 === void 0 ? false : _10,
6789
+ _11 = _b.externalRenderer,
6790
+ externalRenderer = _11 === void 0 ? null : _11,
6791
+ _12 = _b.renderExternal,
6792
+ renderExternal = _12 === void 0 ? null : _12;
6708
6793
 
6709
6794
  var _this = _super.call(this) || this; // Internal states
6710
6795
 
@@ -6744,10 +6829,11 @@ function (_super) {
6744
6829
  _this._useResizeObserver = useResizeObserver;
6745
6830
  _this._resizeDebounce = resizeDebounce;
6746
6831
  _this._maxResizeDebounce = maxResizeDebounce;
6832
+ _this._useFractionalSize = useFractionalSize;
6747
6833
  _this._externalRenderer = externalRenderer;
6748
6834
  _this._renderExternal = renderExternal; // Create core components
6749
6835
 
6750
- _this._viewport = new Viewport(getElement(root));
6836
+ _this._viewport = new Viewport(_this, getElement(root));
6751
6837
  _this._autoResizer = new AutoResizer(_this);
6752
6838
  _this._renderer = _this._createRenderer();
6753
6839
  _this._camera = _this._createCamera();
@@ -7660,6 +7746,23 @@ function (_super) {
7660
7746
  enumerable: false,
7661
7747
  configurable: true
7662
7748
  });
7749
+ Object.defineProperty(__proto, "useFractionalSize", {
7750
+ /**
7751
+ * By enabling this, Flicking will calculate all internal size with CSS width computed with getComputedStyle.
7752
+ * This can prevent 1px offset issue in some cases where panel size has the fractional part.
7753
+ * 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.
7754
+ * @ko 이 옵션을 활성화할 경우, Flicking은 내부의 모든 크기를 {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect getBoundingClientRect}를 이용하여 계산합니다.
7755
+ * 이를 통해, 패널 크기에 소수점을 포함할 경우에 발생할 수 있는 일부 1px 오프셋 이슈를 해결 가능합니다.
7756
+ * 모든 크기는 CSS {@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform transform}이 엘리먼트에 적용되기 이전의 크기를 사용할 것입니다.
7757
+ * @type {boolean}
7758
+ * @default false
7759
+ */
7760
+ get: function () {
7761
+ return this._useFractionalSize;
7762
+ },
7763
+ enumerable: false,
7764
+ configurable: true
7765
+ });
7663
7766
  Object.defineProperty(__proto, "externalRenderer", {
7664
7767
  /**
7665
7768
  * This is an option for the frameworks(React, Vue, Angular, ...). Don't set it as it's automatically managed by Flicking.
@@ -7924,6 +8027,10 @@ function (_super) {
7924
8027
  return Promise.reject(new FlickingError(MESSAGE.ANIMATION_ALREADY_PLAYING, CODE.ANIMATION_ALREADY_PLAYING));
7925
8028
  }
7926
8029
 
8030
+ if (this._control.holding) {
8031
+ this._control.controller.release();
8032
+ }
8033
+
7927
8034
  return this._control.moveToPanel(panel, {
7928
8035
  duration: duration,
7929
8036
  direction: direction
@@ -8408,9 +8515,10 @@ function (_super) {
8408
8515
  var renderer = this._renderer;
8409
8516
  var control = this._control;
8410
8517
  var camera = this._camera;
8411
- var initialPanel = renderer.getPanel(this._defaultIndex) || renderer.getPanel(0);
8412
- if (!initialPanel) return;
8413
- var nearestAnchor = camera.findNearestAnchor(initialPanel.position);
8518
+ var defaultPanel = renderer.getPanel(this._defaultIndex) || renderer.getPanel(0);
8519
+ if (!defaultPanel) return;
8520
+ var nearestAnchor = camera.findNearestAnchor(defaultPanel.position);
8521
+ var initialPanel = nearestAnchor && defaultPanel.index !== nearestAnchor.panel.index ? nearestAnchor.panel : defaultPanel;
8414
8522
  control.setActive(initialPanel, null, false);
8415
8523
 
8416
8524
  if (!nearestAnchor) {
@@ -8471,7 +8579,7 @@ function (_super) {
8471
8579
  */
8472
8580
 
8473
8581
 
8474
- Flicking.VERSION = "4.8.1";
8582
+ Flicking.VERSION = "4.9.2";
8475
8583
  return Flicking;
8476
8584
  }(Component);
8477
8585
 
@@ -8725,5 +8833,5 @@ var parseAlign = function (alignVal) {
8725
8833
  * egjs projects are licensed under the MIT license
8726
8834
  */
8727
8835
 
8728
- export { ALIGN, AnchorPoint, AnimatingState, AxesController, BoundCameraMode, CIRCULAR_FALLBACK, CLASS, Camera, CircularCameraMode, Control, DIRECTION, DisabledState, DraggingState, CODE as ERROR_CODE, EVENTS, ExternalRenderer, FlickingError, FreeControl, HoldingState, IdleState, LinearCameraMode, MOVE_TYPE, NormalRenderingStrategy, Panel, Renderer, SnapControl, State, StateMachine, StrictControl, VanillaElementProvider, VanillaRenderer, Viewport, VirtualElementProvider, VirtualManager, VirtualPanel, VirtualRenderingStrategy, checkExistence, circulateIndex, circulatePosition, clamp, Flicking as default, find, findIndex, findRight, getDefaultCameraTransform, getDirection, getElement, getFlickingAttached, getMinusCompensatedIndex, getProgress, getRenderingPanels, getStyle, includes, isBetween, isString, merge, parseAlign$1 as parseAlign, parseArithmeticExpression, parseArithmeticSize, parseBounce, parseCSSSizeValue, parseElement, parsePanelAlign, range, setPrototypeOf, setSize, sync, toArray, withFlickingMethods };
8836
+ export { ALIGN, AnchorPoint, AnimatingState, AxesController, BoundCameraMode, CIRCULAR_FALLBACK, CLASS, Camera, CircularCameraMode, Control, DIRECTION, DisabledState, DraggingState, CODE as ERROR_CODE, EVENTS, ExternalRenderer, FlickingError, FreeControl, HoldingState, IdleState, LinearCameraMode, MOVE_TYPE, NormalRenderingStrategy, Panel, Renderer, SnapControl, State, StateMachine, StrictControl, VanillaElementProvider, VanillaRenderer, Viewport, VirtualElementProvider, VirtualManager, VirtualPanel, VirtualRenderingStrategy, checkExistence, circulateIndex, circulatePosition, clamp, Flicking as default, find, findIndex, findRight, getDefaultCameraTransform, getDirection, getElement, getElementSize, getFlickingAttached, getMinusCompensatedIndex, getProgress, getRenderingPanels, getStyle, includes, isBetween, isString, merge, parseAlign$1 as parseAlign, parseArithmeticExpression, parseArithmeticSize, parseBounce, parseCSSSizeValue, parseElement, parsePanelAlign, range, setPrototypeOf, setSize, sync, toArray, withFlickingMethods };
8729
8837
  //# sourceMappingURL=flicking.esm.js.map