@egjs/flicking 4.8.1 → 4.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.
package/TODO.md ADDED
@@ -0,0 +1,3 @@
1
+ ## React 18 대응
2
+ - [] updateoffset을 미루기
3
+ - render가 완료되기 전에 updateOffset이 3번 호출되었음
@@ -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>;
@@ -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;
@@ -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.0
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,
@@ -5989,7 +6022,8 @@ function () {
5989
6022
  __proto.resize = function (cached) {
5990
6023
  var el = this.element;
5991
6024
  var flicking = this._flicking;
5992
- var horizontal = flicking.horizontal;
6025
+ var horizontal = flicking.horizontal,
6026
+ useFractionalSize = flicking.useFractionalSize;
5993
6027
 
5994
6028
  if (cached) {
5995
6029
  this._size = cached.size;
@@ -5997,7 +6031,13 @@ function () {
5997
6031
  this._height = cached.height;
5998
6032
  } else {
5999
6033
  var elStyle = getStyle(el);
6000
- this._size = horizontal ? el.offsetWidth : el.offsetHeight;
6034
+ this._size = getElementSize({
6035
+ el: el,
6036
+ horizontal: horizontal,
6037
+ useFractionalSize: useFractionalSize,
6038
+ useOffset: true,
6039
+ style: elStyle
6040
+ });
6001
6041
  this._margin = horizontal ? {
6002
6042
  prev: parseFloat(elStyle.marginLeft || "0"),
6003
6043
  next: parseFloat(elStyle.marginRight || "0")
@@ -6005,7 +6045,13 @@ function () {
6005
6045
  prev: parseFloat(elStyle.marginTop || "0"),
6006
6046
  next: parseFloat(elStyle.marginBottom || "0")
6007
6047
  };
6008
- this._height = horizontal ? el.offsetHeight : this._size;
6048
+ this._height = horizontal ? getElementSize({
6049
+ el: el,
6050
+ horizontal: false,
6051
+ useFractionalSize: useFractionalSize,
6052
+ useOffset: true,
6053
+ style: elStyle
6054
+ }) : this._size;
6009
6055
  }
6010
6056
 
6011
6057
  this.updatePosition();
@@ -6701,10 +6747,12 @@ function (_super) {
6701
6747
  resizeDebounce = _8 === void 0 ? 0 : _8,
6702
6748
  _9 = _b.maxResizeDebounce,
6703
6749
  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;
6750
+ _10 = _b.useFractionalSize,
6751
+ useFractionalSize = _10 === void 0 ? false : _10,
6752
+ _11 = _b.externalRenderer,
6753
+ externalRenderer = _11 === void 0 ? null : _11,
6754
+ _12 = _b.renderExternal,
6755
+ renderExternal = _12 === void 0 ? null : _12;
6708
6756
 
6709
6757
  var _this = _super.call(this) || this; // Internal states
6710
6758
 
@@ -6744,10 +6792,11 @@ function (_super) {
6744
6792
  _this._useResizeObserver = useResizeObserver;
6745
6793
  _this._resizeDebounce = resizeDebounce;
6746
6794
  _this._maxResizeDebounce = maxResizeDebounce;
6795
+ _this._useFractionalSize = useFractionalSize;
6747
6796
  _this._externalRenderer = externalRenderer;
6748
6797
  _this._renderExternal = renderExternal; // Create core components
6749
6798
 
6750
- _this._viewport = new Viewport(getElement(root));
6799
+ _this._viewport = new Viewport(_this, getElement(root));
6751
6800
  _this._autoResizer = new AutoResizer(_this);
6752
6801
  _this._renderer = _this._createRenderer();
6753
6802
  _this._camera = _this._createCamera();
@@ -7660,6 +7709,23 @@ function (_super) {
7660
7709
  enumerable: false,
7661
7710
  configurable: true
7662
7711
  });
7712
+ Object.defineProperty(__proto, "useFractionalSize", {
7713
+ /**
7714
+ * By enabling this, Flicking will calculate all internal size with CSS width computed with getComputedStyle.
7715
+ * This can prevent 1px offset issue in some cases where panel size has the fractional part.
7716
+ * 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.
7717
+ * @ko 이 옵션을 활성화할 경우, Flicking은 내부의 모든 크기를 {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect getBoundingClientRect}를 이용하여 계산합니다.
7718
+ * 이를 통해, 패널 크기에 소수점을 포함할 경우에 발생할 수 있는 일부 1px 오프셋 이슈를 해결 가능합니다.
7719
+ * 모든 크기는 CSS {@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform transform}이 엘리먼트에 적용되기 이전의 크기를 사용할 것입니다.
7720
+ * @type {boolean}
7721
+ * @default false
7722
+ */
7723
+ get: function () {
7724
+ return this._useFractionalSize;
7725
+ },
7726
+ enumerable: false,
7727
+ configurable: true
7728
+ });
7663
7729
  Object.defineProperty(__proto, "externalRenderer", {
7664
7730
  /**
7665
7731
  * This is an option for the frameworks(React, Vue, Angular, ...). Don't set it as it's automatically managed by Flicking.
@@ -8471,7 +8537,7 @@ function (_super) {
8471
8537
  */
8472
8538
 
8473
8539
 
8474
- Flicking.VERSION = "4.8.1";
8540
+ Flicking.VERSION = "4.9.0";
8475
8541
  return Flicking;
8476
8542
  }(Component);
8477
8543
 
@@ -8725,5 +8791,5 @@ var parseAlign = function (alignVal) {
8725
8791
  * egjs projects are licensed under the MIT license
8726
8792
  */
8727
8793
 
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 };
8794
+ 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
8795
  //# sourceMappingURL=flicking.esm.js.map