@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/dist/flicking.js CHANGED
@@ -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
  (function (global, factory) {
10
10
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@egjs/component'), require('@egjs/axes'), require('@egjs/imready')) :
@@ -780,6 +780,29 @@ version: 4.8.1
780
780
 
781
781
  return arr;
782
782
  };
783
+ var getElementSize = function (_a) {
784
+ var el = _a.el,
785
+ horizontal = _a.horizontal,
786
+ useFractionalSize = _a.useFractionalSize,
787
+ useOffset = _a.useOffset,
788
+ style = _a.style;
789
+
790
+ if (useFractionalSize) {
791
+ var baseSize = parseFloat(horizontal ? style.width : style.height);
792
+ var isBorderBoxSizing = style.boxSizing === "border-box";
793
+ var border = horizontal ? parseFloat(style.borderLeftWidth || "0") + parseFloat(style.borderRightWidth || "0") : parseFloat(style.borderTopWidth || "0") + parseFloat(style.borderBottomWidth || "0");
794
+
795
+ if (isBorderBoxSizing) {
796
+ return useOffset ? baseSize : baseSize - border;
797
+ } else {
798
+ var padding = horizontal ? parseFloat(style.paddingLeft || "0") + parseFloat(style.paddingRight || "0") : parseFloat(style.paddingTop || "0") + parseFloat(style.paddingBottom || "0");
799
+ return useOffset ? baseSize + padding + border : baseSize + padding;
800
+ }
801
+ } else {
802
+ var sizeStr = horizontal ? "Width" : "Height";
803
+ return useOffset ? el["offset" + sizeStr] : el["client" + sizeStr];
804
+ }
805
+ };
783
806
  var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
784
807
  obj.__proto__ = proto;
785
808
  return obj;
@@ -814,6 +837,7 @@ version: 4.8.1
814
837
  isBetween: isBetween,
815
838
  circulateIndex: circulateIndex,
816
839
  range: range,
840
+ getElementSize: getElementSize,
817
841
  setPrototypeOf: setPrototypeOf
818
842
  };
819
843
 
@@ -862,10 +886,6 @@ version: 4.8.1
862
886
  return FlickingError;
863
887
  }(Error);
864
888
 
865
- /*
866
- * Copyright (c) 2015 NAVER Corp.
867
- * egjs projects are licensed under the MIT license
868
- */
869
889
  /**
870
890
  * A component that manages viewport size
871
891
  * @ko 뷰포트 크기 정보를 담당하는 컴포넌트
@@ -877,7 +897,8 @@ version: 4.8.1
877
897
  /**
878
898
  * @param el A viewport element<ko>뷰포트 엘리먼트</ko>
879
899
  */
880
- function Viewport(el) {
900
+ function Viewport(flicking, el) {
901
+ this._flicking = flicking;
881
902
  this._el = el;
882
903
  this._width = 0;
883
904
  this._height = 0;
@@ -993,8 +1014,21 @@ version: 4.8.1
993
1014
  __proto.resize = function () {
994
1015
  var el = this._el;
995
1016
  var elStyle = getStyle(el);
996
- this._width = el.clientWidth;
997
- this._height = el.clientHeight;
1017
+ var useFractionalSize = this._flicking.useFractionalSize;
1018
+ this._width = getElementSize({
1019
+ el: el,
1020
+ horizontal: true,
1021
+ useFractionalSize: useFractionalSize,
1022
+ useOffset: false,
1023
+ style: elStyle
1024
+ });
1025
+ this._height = getElementSize({
1026
+ el: el,
1027
+ horizontal: false,
1028
+ useFractionalSize: useFractionalSize,
1029
+ useOffset: false,
1030
+ style: elStyle
1031
+ });
998
1032
  this._padding = {
999
1033
  left: elStyle.paddingLeft ? parseFloat(elStyle.paddingLeft) : 0,
1000
1034
  right: elStyle.paddingRight ? parseFloat(elStyle.paddingRight) : 0,
@@ -6068,7 +6102,8 @@ version: 4.8.1
6068
6102
  __proto.resize = function (cached) {
6069
6103
  var el = this.element;
6070
6104
  var flicking = this._flicking;
6071
- var horizontal = flicking.horizontal;
6105
+ var horizontal = flicking.horizontal,
6106
+ useFractionalSize = flicking.useFractionalSize;
6072
6107
 
6073
6108
  if (cached) {
6074
6109
  this._size = cached.size;
@@ -6076,7 +6111,13 @@ version: 4.8.1
6076
6111
  this._height = cached.height;
6077
6112
  } else {
6078
6113
  var elStyle = getStyle(el);
6079
- this._size = horizontal ? el.offsetWidth : el.offsetHeight;
6114
+ this._size = getElementSize({
6115
+ el: el,
6116
+ horizontal: horizontal,
6117
+ useFractionalSize: useFractionalSize,
6118
+ useOffset: true,
6119
+ style: elStyle
6120
+ });
6080
6121
  this._margin = horizontal ? {
6081
6122
  prev: parseFloat(elStyle.marginLeft || "0"),
6082
6123
  next: parseFloat(elStyle.marginRight || "0")
@@ -6084,7 +6125,13 @@ version: 4.8.1
6084
6125
  prev: parseFloat(elStyle.marginTop || "0"),
6085
6126
  next: parseFloat(elStyle.marginBottom || "0")
6086
6127
  };
6087
- this._height = horizontal ? el.offsetHeight : this._size;
6128
+ this._height = horizontal ? getElementSize({
6129
+ el: el,
6130
+ horizontal: false,
6131
+ useFractionalSize: useFractionalSize,
6132
+ useOffset: true,
6133
+ style: elStyle
6134
+ }) : this._size;
6088
6135
  }
6089
6136
 
6090
6137
  this.updatePosition();
@@ -6794,10 +6841,12 @@ version: 4.8.1
6794
6841
  resizeDebounce = _8 === void 0 ? 0 : _8,
6795
6842
  _9 = _b.maxResizeDebounce,
6796
6843
  maxResizeDebounce = _9 === void 0 ? 100 : _9,
6797
- _10 = _b.externalRenderer,
6798
- externalRenderer = _10 === void 0 ? null : _10,
6799
- _11 = _b.renderExternal,
6800
- renderExternal = _11 === void 0 ? null : _11;
6844
+ _10 = _b.useFractionalSize,
6845
+ useFractionalSize = _10 === void 0 ? false : _10,
6846
+ _11 = _b.externalRenderer,
6847
+ externalRenderer = _11 === void 0 ? null : _11,
6848
+ _12 = _b.renderExternal,
6849
+ renderExternal = _12 === void 0 ? null : _12;
6801
6850
 
6802
6851
  var _this = _super.call(this) || this; // Internal states
6803
6852
 
@@ -6837,10 +6886,11 @@ version: 4.8.1
6837
6886
  _this._useResizeObserver = useResizeObserver;
6838
6887
  _this._resizeDebounce = resizeDebounce;
6839
6888
  _this._maxResizeDebounce = maxResizeDebounce;
6889
+ _this._useFractionalSize = useFractionalSize;
6840
6890
  _this._externalRenderer = externalRenderer;
6841
6891
  _this._renderExternal = renderExternal; // Create core components
6842
6892
 
6843
- _this._viewport = new Viewport(getElement(root));
6893
+ _this._viewport = new Viewport(_this, getElement(root));
6844
6894
  _this._autoResizer = new AutoResizer(_this);
6845
6895
  _this._renderer = _this._createRenderer();
6846
6896
  _this._camera = _this._createCamera();
@@ -7753,6 +7803,23 @@ version: 4.8.1
7753
7803
  enumerable: false,
7754
7804
  configurable: true
7755
7805
  });
7806
+ Object.defineProperty(__proto, "useFractionalSize", {
7807
+ /**
7808
+ * By enabling this, Flicking will calculate all internal size with CSS width computed with getComputedStyle.
7809
+ * This can prevent 1px offset issue in some cases where panel size has the fractional part.
7810
+ * 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.
7811
+ * @ko 이 옵션을 활성화할 경우, Flicking은 내부의 모든 크기를 {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect getBoundingClientRect}를 이용하여 계산합니다.
7812
+ * 이를 통해, 패널 크기에 소수점을 포함할 경우에 발생할 수 있는 일부 1px 오프셋 이슈를 해결 가능합니다.
7813
+ * 모든 크기는 CSS {@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform transform}이 엘리먼트에 적용되기 이전의 크기를 사용할 것입니다.
7814
+ * @type {boolean}
7815
+ * @default false
7816
+ */
7817
+ get: function () {
7818
+ return this._useFractionalSize;
7819
+ },
7820
+ enumerable: false,
7821
+ configurable: true
7822
+ });
7756
7823
  Object.defineProperty(__proto, "externalRenderer", {
7757
7824
  /**
7758
7825
  * This is an option for the frameworks(React, Vue, Angular, ...). Don't set it as it's automatically managed by Flicking.
@@ -8564,7 +8631,7 @@ version: 4.8.1
8564
8631
  */
8565
8632
 
8566
8633
 
8567
- Flicking.VERSION = "4.8.1";
8634
+ Flicking.VERSION = "4.9.0";
8568
8635
  return Flicking;
8569
8636
  }(Component);
8570
8637