@egjs/flicking 4.13.2-beta.1 → 4.14.1-beta.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.
@@ -4,11 +4,12 @@ name: @egjs/flicking
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-flicking
7
- version: 4.13.2-beta.1
7
+ version: 4.14.1-beta.0
8
8
  */
9
9
  import Component, { ComponentEvent } from '@egjs/component';
10
10
  import Axes, { PanInput } from '@egjs/axes';
11
11
  import ImReady from '@egjs/imready';
12
+ import { reactive, adaptReactive } from '@cfcs/core';
12
13
 
13
14
  /******************************************************************************
14
15
  Copyright (c) Microsoft Corporation.
@@ -667,7 +668,7 @@ var findIndex = function (array, checker) {
667
668
  }
668
669
  return -1;
669
670
  };
670
- var getProgress = function (pos, prev, next) {
671
+ var getProgress$1 = function (pos, prev, next) {
671
672
  return (pos - prev) / (next - prev);
672
673
  };
673
674
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
@@ -2796,9 +2797,12 @@ var Control = /*#__PURE__*/function () {
2796
2797
  return __generator(this, function (_a) {
2797
2798
  switch (_a.label) {
2798
2799
  case 0:
2800
+ if (!flicking.initialized) return [3 /*break*/, 2];
2799
2801
  return [4 /*yield*/, flicking.renderer.render()];
2800
2802
  case 1:
2801
2803
  _a.sent();
2804
+ _a.label = 2;
2805
+ case 2:
2802
2806
  return [2 /*return*/];
2803
2807
  }
2804
2808
  });
@@ -4110,7 +4114,7 @@ var Camera = /*#__PURE__*/function () {
4110
4114
  if (prevPosition > panelPos) {
4111
4115
  prevPosition -= rangeDiff;
4112
4116
  }
4113
- return nearestPanel.index - 1 + getProgress(position, prevPosition, panelPos);
4117
+ return nearestPanel.index - 1 + getProgress$1(position, prevPosition, panelPos);
4114
4118
  } else {
4115
4119
  var nextPanel = nearestPanel.next();
4116
4120
  var nextPosition = nextPanel ? nextPanel.position + nextPanel.offset : nextRange + bounceSize[1];
@@ -4118,7 +4122,7 @@ var Camera = /*#__PURE__*/function () {
4118
4122
  if (nextPosition < panelPos) {
4119
4123
  nextPosition += rangeDiff;
4120
4124
  }
4121
- return nearestPanel.index + getProgress(position, panelPos, nextPosition);
4125
+ return nearestPanel.index + getProgress$1(position, panelPos, nextPosition);
4122
4126
  }
4123
4127
  },
4124
4128
  enumerable: false,
@@ -5461,10 +5465,10 @@ var Panel = /*#__PURE__*/function () {
5461
5465
  }
5462
5466
  if (camPos < position) {
5463
5467
  var disappearPosNext = position + (camera.size - camera.alignPosition) + alignPosition;
5464
- return -getProgress(camPos, position, disappearPosNext);
5468
+ return -getProgress$1(camPos, position, disappearPosNext);
5465
5469
  } else {
5466
5470
  var disappearPosPrev = position - (camera.alignPosition + this._size - alignPosition);
5467
- return 1 - getProgress(camPos, disappearPosPrev, position);
5471
+ return 1 - getProgress$1(camPos, disappearPosPrev, position);
5468
5472
  }
5469
5473
  },
5470
5474
  enumerable: false,
@@ -8098,7 +8102,7 @@ var Flicking = /*#__PURE__*/function (_super) {
8098
8102
  * Flicking.VERSION; // ex) 4.0.0
8099
8103
  * ```
8100
8104
  */
8101
- Flicking.VERSION = "4.13.2-beta.1";
8105
+ Flicking.VERSION = "4.14.1-beta.0";
8102
8106
  return Flicking;
8103
8107
  }(Component);
8104
8108
 
@@ -8654,10 +8658,194 @@ var parseAlign = function (alignVal) {
8654
8658
  }
8655
8659
  };
8656
8660
 
8661
+ // Check if Flicking has reached the first panel
8662
+ var getIsReachStart = function (flicking) {
8663
+ return !flicking.circular && flicking.index === 0;
8664
+ };
8665
+ // Check if Flicking has reached the last panel
8666
+ var getIsReachEnd = function (flicking) {
8667
+ return !flicking.circular && flicking.index === flicking.panelCount - 1;
8668
+ };
8669
+ // Get the total number of panels
8670
+ var getTotalPanelCount = function (flicking) {
8671
+ return flicking.panelCount;
8672
+ };
8673
+ // Get the current active panel index
8674
+ var getCurrentPanelIndex = function (flicking) {
8675
+ return flicking.index;
8676
+ };
8677
+ // Calculate the overall scroll progress percentage based on the current camera position
8678
+ var getProgress = function (flicking) {
8679
+ var cam = flicking.camera;
8680
+ var progressRatio = (cam.position - cam.range.min) / (cam.range.max - cam.range.min);
8681
+ var percent = Math.min(Math.max(progressRatio, 0), 1) * 100;
8682
+ return percent;
8683
+ };
8684
+ // Calculate the progress between panels including decimal values
8685
+ var getIndexProgress = function (flicking) {
8686
+ var cam = flicking.camera;
8687
+ var anchorPoints = cam.anchorPoints;
8688
+ var length = anchorPoints.length;
8689
+ var cameraPosition = cam.position;
8690
+ var isCircular = flicking.circularEnabled;
8691
+ var indexProgress = 0;
8692
+ var _a = cam.range,
8693
+ min = _a.min,
8694
+ max = _a.max;
8695
+ var firstAnchorPoint = anchorPoints[0];
8696
+ var lastAnchorPoint = anchorPoints[length - 1];
8697
+ var distanceLastToFirst = max - lastAnchorPoint.position + (firstAnchorPoint.position - min);
8698
+ anchorPoints.some(function (anchorPoint, index) {
8699
+ var anchorPosition = anchorPoint.position;
8700
+ var nextAnchorPoint = anchorPoints[index + 1];
8701
+ if (index === 0 && cameraPosition <= anchorPosition) {
8702
+ if (isCircular) {
8703
+ indexProgress = (cameraPosition - anchorPosition) / distanceLastToFirst;
8704
+ } else {
8705
+ indexProgress = (cameraPosition - anchorPosition) / anchorPoint.panel.size;
8706
+ }
8707
+ } else if (index === length - 1 && cameraPosition >= anchorPosition) {
8708
+ if (isCircular) {
8709
+ indexProgress = index + (cameraPosition - anchorPosition) / distanceLastToFirst;
8710
+ } else {
8711
+ indexProgress = index + (cameraPosition - anchorPosition) / anchorPoint.panel.size;
8712
+ }
8713
+ } else if (nextAnchorPoint && anchorPosition <= cameraPosition && cameraPosition <= nextAnchorPoint.position) {
8714
+ indexProgress = index + (cameraPosition - anchorPosition) / (nextAnchorPoint.position - anchorPosition);
8715
+ } else {
8716
+ return false;
8717
+ }
8718
+ return true;
8719
+ });
8720
+ return indexProgress;
8721
+ };
8722
+ /**
8723
+ * Internal reactive API adapter for Flicking that manages state and event listeners
8724
+ * This adapter is used internally by framework-specific packages (react-flicking, vue-flicking, etc.)
8725
+ * to provide reactive API support. Users rarely need to use this directly.
8726
+ * @ko Flicking의 상태와 이벤트 리스너를 관리하는 내부 반응형 API 어댑터
8727
+ * 이 어댑터는 react-flicking, vue-flicking 등의 프레임워크별 패키지에서 내부적으로 사용되어
8728
+ * 반응형 API 지원을 제공합니다. 사용자가 직접 사용할 일은 거의 없습니다.
8729
+ * @param onInit - Callback when reactive object is initialized<ko>반응형 객체가 초기화될 때 호출되는 콜백</ko>
8730
+ * @param onDestroy - Callback when reactive object is destroyed<ko>반응형 객체가 파괴될 때 호출되는 콜백</ko>
8731
+ * @param setMethods - Function to set available methods<ko>사용 가능한 메서드를 설정하는 함수</ko>
8732
+ * @returns Reactive object with Flicking state and methods<ko>Flicking 상태와 메서드를 포함한 반응형 객체</ko>
8733
+ */
8734
+ var flickingReactiveAPIAdapter = function (_a) {
8735
+ var _b, _c, _d;
8736
+ var onInit = _a.onInit,
8737
+ onDestroy = _a.onDestroy,
8738
+ setMethods = _a.setMethods,
8739
+ getProps = _a.getProps;
8740
+ var flicking;
8741
+ // Move to a specific panel index
8742
+ var moveTo = function (i) {
8743
+ if (flicking == null) {
8744
+ return Promise.reject(new Error("Flicking instance is not available"));
8745
+ }
8746
+ if (flicking === null || flicking === void 0 ? void 0 : flicking.animating) {
8747
+ return Promise.resolve();
8748
+ }
8749
+ return flicking.moveTo(i);
8750
+ };
8751
+ setMethods(["moveTo"]);
8752
+ var options = getProps().options;
8753
+ // options를 고려하지 않고 초기값을 설정해도 동작에는 아무런 문제가 없으나, 이 시점의 초기값과 컴포넌트 init 단계에서의 초기값이 다르면 화면 리렌더링이 발생할 수 있으므로
8754
+ // 이렇게 미리 옵션을 통해서 예측할 수 있는 부분들은 맞춰둔다.
8755
+ var reactiveObj = reactive({
8756
+ isReachStart: (options === null || options === void 0 ? void 0 : options.defaultIndex) ? (options === null || options === void 0 ? void 0 : options.defaultIndex) === 0 : true,
8757
+ isReachEnd: (options === null || options === void 0 ? void 0 : options.totalPanelCount) && (options === null || options === void 0 ? void 0 : options.defaultIndex) ? options.defaultIndex === options.totalPanelCount - 1 : false,
8758
+ totalPanelCount: (_b = options === null || options === void 0 ? void 0 : options.totalPanelCount) !== null && _b !== void 0 ? _b : 0,
8759
+ currentPanelIndex: (_c = options === null || options === void 0 ? void 0 : options.defaultIndex) !== null && _c !== void 0 ? _c : 0,
8760
+ progress: 0,
8761
+ indexProgress: (_d = options === null || options === void 0 ? void 0 : options.defaultIndex) !== null && _d !== void 0 ? _d : 0,
8762
+ moveTo: moveTo
8763
+ });
8764
+ // Update state when panel changes
8765
+ var onChanged = function () {
8766
+ if (flicking === undefined) return;
8767
+ reactiveObj.isReachStart = getIsReachStart(flicking);
8768
+ reactiveObj.isReachEnd = getIsReachEnd(flicking);
8769
+ reactiveObj.currentPanelIndex = getCurrentPanelIndex(flicking);
8770
+ };
8771
+ // Update state when panel count changes
8772
+ var onPanelChange = function () {
8773
+ if (flicking === undefined) return;
8774
+ onChanged();
8775
+ reactiveObj.totalPanelCount = getTotalPanelCount(flicking);
8776
+ };
8777
+ // Update progress when camera moves
8778
+ var onMove = function () {
8779
+ if (flicking === undefined) return;
8780
+ reactiveObj.progress = getProgress(flicking);
8781
+ reactiveObj.indexProgress = getIndexProgress(flicking);
8782
+ };
8783
+ onInit(function (inst, data) {
8784
+ flicking = data.flicking;
8785
+ if (flicking === undefined) return;
8786
+ reactiveObj.isReachStart = getIsReachStart(flicking);
8787
+ reactiveObj.isReachEnd = getIsReachEnd(flicking);
8788
+ reactiveObj.currentPanelIndex = getCurrentPanelIndex(flicking);
8789
+ reactiveObj.progress = getProgress(flicking);
8790
+ reactiveObj.totalPanelCount = getTotalPanelCount(flicking);
8791
+ flicking === null || flicking === void 0 ? void 0 : flicking.on("changed", onChanged);
8792
+ flicking === null || flicking === void 0 ? void 0 : flicking.on("panelChange", onPanelChange);
8793
+ flicking === null || flicking === void 0 ? void 0 : flicking.on("move", onMove);
8794
+ });
8795
+ onDestroy(function () {
8796
+ flicking === null || flicking === void 0 ? void 0 : flicking.off("changed", onChanged);
8797
+ flicking === null || flicking === void 0 ? void 0 : flicking.off("panelChange", onPanelChange);
8798
+ flicking === null || flicking === void 0 ? void 0 : flicking.off("move", onMove);
8799
+ });
8800
+ return reactiveObj;
8801
+ };
8802
+ /**
8803
+ * Connect Flicking instance to reactive API
8804
+ * @ko Flicking 인스턴스를 반응형 API에 연결합니다
8805
+ * @param {Flicking} flicking - Flicking instance to connect<ko>연결할 Flicking 인스턴스</ko>
8806
+ * @param {FlickingReactiveAPIOptions} [options] - Flicking options<ko>Flicking 옵션</ko>
8807
+ * @returns {FlickingReactiveObject} Reactive object with Flicking state and methods<ko>Flicking 상태와 메서드를 포함한 반응형 객체</ko>
8808
+ * @example
8809
+ * ```js
8810
+ * import Flicking, { connectFlickingReactiveAPI } from "@egjs/flicking";
8811
+ *
8812
+ * const flicking = new Flicking("#el");
8813
+ * const reactiveObj = connectFlickingReactiveAPI(flicking);
8814
+ *
8815
+ * // Access reactive state
8816
+ * console.log("Current panel:", reactiveObj.currentPanelIndex);
8817
+ * console.log("Progress:", reactiveObj.progress + "%");
8818
+ * console.log("Is at start:", reactiveObj.isReachStart);
8819
+ * console.log("Is at end:", reactiveObj.isReachEnd);
8820
+ * console.log("Total panels:", reactiveObj.totalPanelCount);
8821
+ * console.log("Index progress:", reactiveObj.indexProgress);
8822
+ *
8823
+ * // Subscribe to state changes
8824
+ * reactiveObj.subscribe("currentPanelIndex", (nextValue) => {
8825
+ * console.log("Panel changed to:", nextValue);
8826
+ * });
8827
+ *
8828
+ * // Use reactive methods
8829
+ * reactiveObj.moveTo(2); // Move to third panel
8830
+ * ```
8831
+ */
8832
+ var connectFlickingReactiveAPI = function (flicking, options) {
8833
+ var obj = adaptReactive(flickingReactiveAPIAdapter, function () {
8834
+ return {
8835
+ flicking: flicking,
8836
+ options: options
8837
+ };
8838
+ });
8839
+ obj.mounted();
8840
+ var instance = obj.instance();
8841
+ obj.init();
8842
+ return instance;
8843
+ };
8844
+
8657
8845
  /*
8658
8846
  * Copyright (c) 2015 NAVER Corp.
8659
8847
  * egjs projects are licensed under the MIT license
8660
8848
  */
8661
8849
 
8662
- export { ALIGN, AnchorPoint, AnimatingState, AxesController, BoundCameraMode, CIRCULAR_FALLBACK, CLASS, Camera, CircularCameraMode, Control, CrossFlicking, DIRECTION, DisabledState, DraggingState, CODE as ERROR_CODE, EVENTS, ExternalRenderer, FlickingError, FreeControl, HoldingState, IdleState, LinearCameraMode, MOVE_DIRECTION, MOVE_TYPE, NormalRenderingStrategy, ORDER, Panel, Renderer, SIDE_EVENTS, SnapControl, State, StateMachine, StrictControl, VanillaElementProvider, VanillaRenderer, Viewport, VirtualElementProvider, VirtualManager, VirtualPanel, VirtualRenderingStrategy, camelize, checkExistence, circulateIndex, circulatePosition, clamp, Flicking as default, find, findIndex, findRight, getDataAttributes, 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 };
8850
+ export { ALIGN, AnchorPoint, AnimatingState, AxesController, BoundCameraMode, CIRCULAR_FALLBACK, CLASS, Camera, CircularCameraMode, Control, CrossFlicking, DIRECTION, DisabledState, DraggingState, CODE as ERROR_CODE, EVENTS, ExternalRenderer, FlickingError, FreeControl, HoldingState, IdleState, LinearCameraMode, MOVE_DIRECTION, MOVE_TYPE, NormalRenderingStrategy, ORDER, Panel, Renderer, SIDE_EVENTS, SnapControl, State, StateMachine, StrictControl, VanillaElementProvider, VanillaRenderer, Viewport, VirtualElementProvider, VirtualManager, VirtualPanel, VirtualRenderingStrategy, camelize, checkExistence, circulateIndex, circulatePosition, clamp, connectFlickingReactiveAPI, Flicking as default, find, findIndex, findRight, flickingReactiveAPIAdapter, getDataAttributes, getDefaultCameraTransform, getDirection, getElement, getElementSize, getFlickingAttached, getMinusCompensatedIndex, getProgress$1 as getProgress, getRenderingPanels, getStyle, includes, isBetween, isString, merge, parseAlign$1 as parseAlign, parseArithmeticExpression, parseArithmeticSize, parseBounce, parseCSSSizeValue, parseElement, parsePanelAlign, range, setPrototypeOf, setSize, sync, toArray, withFlickingMethods };
8663
8851
  //# sourceMappingURL=flicking.esm.js.map