@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.
@@ -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;
@@ -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.0
7
+ version: 4.9.1
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,
@@ -2155,7 +2188,9 @@ function () {
2155
2188
  };
2156
2189
 
2157
2190
  this._onAxesChange = function () {
2158
- _this._dragged = true;
2191
+ var _a;
2192
+
2193
+ _this._dragged = !!((_a = _this._panInput) === null || _a === void 0 ? void 0 : _a.isEnabled());
2159
2194
  };
2160
2195
 
2161
2196
  this._preventClickWhenDragged = function (e) {
@@ -3136,10 +3171,13 @@ function (_super) {
3136
3171
  targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
3137
3172
  } else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
3138
3173
  // Move to the adjacent panel
3139
- targetAnchor = this._findAdjacentAnchor(posDelta, anchorAtCamera);
3174
+ targetAnchor = this._findAdjacentAnchor(position, posDelta, anchorAtCamera);
3140
3175
  } else {
3141
3176
  // Restore to active panel
3142
- targetAnchor = anchorAtCamera;
3177
+ return this.moveToPanel(activeAnchor.panel, {
3178
+ duration: duration,
3179
+ axesEvent: axesEvent
3180
+ });
3143
3181
  }
3144
3182
 
3145
3183
  this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
@@ -3210,11 +3248,20 @@ function (_super) {
3210
3248
  }
3211
3249
  };
3212
3250
 
3213
- __proto._findAdjacentAnchor = function (posDelta, anchorAtCamera) {
3251
+ __proto._findAdjacentAnchor = function (position, posDelta, anchorAtCamera) {
3214
3252
  var _a;
3215
3253
 
3216
3254
  var flicking = getFlickingAttached(this._flicking);
3217
3255
  var camera = flicking.camera;
3256
+
3257
+ if (camera.circularEnabled) {
3258
+ var anchorIncludePosition = camera.findAnchorIncludePosition(position);
3259
+
3260
+ if (anchorIncludePosition && anchorIncludePosition.position !== anchorAtCamera.position) {
3261
+ return anchorIncludePosition;
3262
+ }
3263
+ }
3264
+
3218
3265
  var adjacentAnchor = (_a = posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) !== null && _a !== void 0 ? _a : anchorAtCamera;
3219
3266
  return adjacentAnchor;
3220
3267
  };
@@ -5435,11 +5482,13 @@ function () {
5435
5482
  } : {
5436
5483
  height: panelSize
5437
5484
  };
5438
- var firstPanelSizeObj = {
5485
+
5486
+ var firstPanelSizeObj = __assign({
5439
5487
  size: panelSize,
5440
- height: referencePanel.height,
5441
5488
  margin: referencePanel.margin
5442
- };
5489
+ }, !flicking.horizontal && {
5490
+ height: referencePanel.height
5491
+ });
5443
5492
 
5444
5493
  if (!flicking.noPanelStyleOverride) {
5445
5494
  this._strategy.updatePanelSizes(flicking, panelSizeObj);
@@ -5973,17 +6022,32 @@ function () {
5973
6022
 
5974
6023
 
5975
6024
  __proto.resize = function (cached) {
6025
+ var _a;
6026
+
5976
6027
  var el = this.element;
5977
6028
  var flicking = this._flicking;
5978
- var horizontal = flicking.horizontal;
6029
+ var horizontal = flicking.horizontal,
6030
+ useFractionalSize = flicking.useFractionalSize;
5979
6031
 
5980
6032
  if (cached) {
5981
6033
  this._size = cached.size;
5982
6034
  this._margin = __assign({}, cached.margin);
5983
- this._height = cached.height;
6035
+ this._height = (_a = cached.height) !== null && _a !== void 0 ? _a : getElementSize({
6036
+ el: el,
6037
+ horizontal: false,
6038
+ useFractionalSize: useFractionalSize,
6039
+ useOffset: true,
6040
+ style: getStyle(el)
6041
+ });
5984
6042
  } else {
5985
6043
  var elStyle = getStyle(el);
5986
- this._size = horizontal ? el.offsetWidth : el.offsetHeight;
6044
+ this._size = getElementSize({
6045
+ el: el,
6046
+ horizontal: horizontal,
6047
+ useFractionalSize: useFractionalSize,
6048
+ useOffset: true,
6049
+ style: elStyle
6050
+ });
5987
6051
  this._margin = horizontal ? {
5988
6052
  prev: parseFloat(elStyle.marginLeft || "0"),
5989
6053
  next: parseFloat(elStyle.marginRight || "0")
@@ -5991,7 +6055,13 @@ function () {
5991
6055
  prev: parseFloat(elStyle.marginTop || "0"),
5992
6056
  next: parseFloat(elStyle.marginBottom || "0")
5993
6057
  };
5994
- this._height = horizontal ? el.offsetHeight : this._size;
6058
+ this._height = horizontal ? getElementSize({
6059
+ el: el,
6060
+ horizontal: false,
6061
+ useFractionalSize: useFractionalSize,
6062
+ useOffset: true,
6063
+ style: elStyle
6064
+ }) : this._size;
5995
6065
  }
5996
6066
 
5997
6067
  this.updatePosition();
@@ -6687,10 +6757,12 @@ function (_super) {
6687
6757
  resizeDebounce = _8 === void 0 ? 0 : _8,
6688
6758
  _9 = _b.maxResizeDebounce,
6689
6759
  maxResizeDebounce = _9 === void 0 ? 100 : _9,
6690
- _10 = _b.externalRenderer,
6691
- externalRenderer = _10 === void 0 ? null : _10,
6692
- _11 = _b.renderExternal,
6693
- renderExternal = _11 === void 0 ? null : _11;
6760
+ _10 = _b.useFractionalSize,
6761
+ useFractionalSize = _10 === void 0 ? false : _10,
6762
+ _11 = _b.externalRenderer,
6763
+ externalRenderer = _11 === void 0 ? null : _11,
6764
+ _12 = _b.renderExternal,
6765
+ renderExternal = _12 === void 0 ? null : _12;
6694
6766
 
6695
6767
  var _this = _super.call(this) || this; // Internal states
6696
6768
 
@@ -6730,10 +6802,11 @@ function (_super) {
6730
6802
  _this._useResizeObserver = useResizeObserver;
6731
6803
  _this._resizeDebounce = resizeDebounce;
6732
6804
  _this._maxResizeDebounce = maxResizeDebounce;
6805
+ _this._useFractionalSize = useFractionalSize;
6733
6806
  _this._externalRenderer = externalRenderer;
6734
6807
  _this._renderExternal = renderExternal; // Create core components
6735
6808
 
6736
- _this._viewport = new Viewport(getElement(root));
6809
+ _this._viewport = new Viewport(_this, getElement(root));
6737
6810
  _this._autoResizer = new AutoResizer(_this);
6738
6811
  _this._renderer = _this._createRenderer();
6739
6812
  _this._camera = _this._createCamera();
@@ -7646,6 +7719,23 @@ function (_super) {
7646
7719
  enumerable: false,
7647
7720
  configurable: true
7648
7721
  });
7722
+ Object.defineProperty(__proto, "useFractionalSize", {
7723
+ /**
7724
+ * By enabling this, Flicking will calculate all internal size with CSS width computed with getComputedStyle.
7725
+ * This can prevent 1px offset issue in some cases where panel size has the fractional part.
7726
+ * 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.
7727
+ * @ko 이 옵션을 활성화할 경우, Flicking은 내부의 모든 크기를 {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect getBoundingClientRect}를 이용하여 계산합니다.
7728
+ * 이를 통해, 패널 크기에 소수점을 포함할 경우에 발생할 수 있는 일부 1px 오프셋 이슈를 해결 가능합니다.
7729
+ * 모든 크기는 CSS {@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform transform}이 엘리먼트에 적용되기 이전의 크기를 사용할 것입니다.
7730
+ * @type {boolean}
7731
+ * @default false
7732
+ */
7733
+ get: function () {
7734
+ return this._useFractionalSize;
7735
+ },
7736
+ enumerable: false,
7737
+ configurable: true
7738
+ });
7649
7739
  Object.defineProperty(__proto, "externalRenderer", {
7650
7740
  /**
7651
7741
  * This is an option for the frameworks(React, Vue, Angular, ...). Don't set it as it's automatically managed by Flicking.
@@ -8394,9 +8484,10 @@ function (_super) {
8394
8484
  var renderer = this._renderer;
8395
8485
  var control = this._control;
8396
8486
  var camera = this._camera;
8397
- var initialPanel = renderer.getPanel(this._defaultIndex) || renderer.getPanel(0);
8398
- if (!initialPanel) return;
8399
- var nearestAnchor = camera.findNearestAnchor(initialPanel.position);
8487
+ var defaultPanel = renderer.getPanel(this._defaultIndex) || renderer.getPanel(0);
8488
+ if (!defaultPanel) return;
8489
+ var nearestAnchor = camera.findNearestAnchor(defaultPanel.position);
8490
+ var initialPanel = nearestAnchor && defaultPanel.index !== nearestAnchor.panel.index ? nearestAnchor.panel : defaultPanel;
8400
8491
  control.setActive(initialPanel, null, false);
8401
8492
 
8402
8493
  if (!nearestAnchor) {
@@ -8457,7 +8548,7 @@ function (_super) {
8457
8548
  */
8458
8549
 
8459
8550
 
8460
- Flicking.VERSION = "4.8.0";
8551
+ Flicking.VERSION = "4.9.1";
8461
8552
  return Flicking;
8462
8553
  }(Component);
8463
8554
 
@@ -8711,5 +8802,5 @@ var parseAlign = function (alignVal) {
8711
8802
  * egjs projects are licensed under the MIT license
8712
8803
  */
8713
8804
 
8714
- 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 };
8805
+ 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 };
8715
8806
  //# sourceMappingURL=flicking.esm.js.map