@egjs/flicking 4.13.2-beta.1 → 4.14.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,13 +4,13 @@ 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.0
8
8
  */
9
9
  (function (global, factory) {
10
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@egjs/component'), require('@egjs/axes'), require('@egjs/imready')) :
11
- typeof define === 'function' && define.amd ? define(['@egjs/component', '@egjs/axes', '@egjs/imready'], factory) :
12
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Flicking = factory(global.eg.Component, global.eg.Axes, global.eg.ImReady));
13
- })(this, (function (Component, Axes, ImReady) { 'use strict';
10
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@egjs/component'), require('@egjs/axes'), require('@egjs/imready'), require('@cfcs/core')) :
11
+ typeof define === 'function' && define.amd ? define(['@egjs/component', '@egjs/axes', '@egjs/imready', '@cfcs/core'], factory) :
12
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Flicking = factory(global.eg.Component, global.eg.Axes, global.eg.ImReady, global.core));
13
+ })(this, (function (Component, Axes, ImReady, core) { 'use strict';
14
14
 
15
15
  /******************************************************************************
16
16
  Copyright (c) Microsoft Corporation.
@@ -682,7 +682,7 @@ version: 4.13.2-beta.1
682
682
  }
683
683
  return -1;
684
684
  };
685
- var getProgress = function (pos, prev, next) {
685
+ var getProgress$1 = function (pos, prev, next) {
686
686
  return (pos - prev) / (next - prev);
687
687
  };
688
688
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
@@ -803,7 +803,7 @@ version: 4.13.2-beta.1
803
803
  find: find,
804
804
  findRight: findRight,
805
805
  findIndex: findIndex,
806
- getProgress: getProgress,
806
+ getProgress: getProgress$1,
807
807
  getStyle: getStyle,
808
808
  setSize: setSize,
809
809
  isBetween: isBetween,
@@ -4181,7 +4181,7 @@ version: 4.13.2-beta.1
4181
4181
  if (prevPosition > panelPos) {
4182
4182
  prevPosition -= rangeDiff;
4183
4183
  }
4184
- return nearestPanel.index - 1 + getProgress(position, prevPosition, panelPos);
4184
+ return nearestPanel.index - 1 + getProgress$1(position, prevPosition, panelPos);
4185
4185
  } else {
4186
4186
  var nextPanel = nearestPanel.next();
4187
4187
  var nextPosition = nextPanel ? nextPanel.position + nextPanel.offset : nextRange + bounceSize[1];
@@ -4189,7 +4189,7 @@ version: 4.13.2-beta.1
4189
4189
  if (nextPosition < panelPos) {
4190
4190
  nextPosition += rangeDiff;
4191
4191
  }
4192
- return nearestPanel.index + getProgress(position, panelPos, nextPosition);
4192
+ return nearestPanel.index + getProgress$1(position, panelPos, nextPosition);
4193
4193
  }
4194
4194
  },
4195
4195
  enumerable: false,
@@ -5545,10 +5545,10 @@ version: 4.13.2-beta.1
5545
5545
  }
5546
5546
  if (camPos < position) {
5547
5547
  var disappearPosNext = position + (camera.size - camera.alignPosition) + alignPosition;
5548
- return -getProgress(camPos, position, disappearPosNext);
5548
+ return -getProgress$1(camPos, position, disappearPosNext);
5549
5549
  } else {
5550
5550
  var disappearPosPrev = position - (camera.alignPosition + this._size - alignPosition);
5551
- return 1 - getProgress(camPos, disappearPosPrev, position);
5551
+ return 1 - getProgress$1(camPos, disappearPosPrev, position);
5552
5552
  }
5553
5553
  },
5554
5554
  enumerable: false,
@@ -8196,7 +8196,7 @@ version: 4.13.2-beta.1
8196
8196
  * Flicking.VERSION; // ex) 4.0.0
8197
8197
  * ```
8198
8198
  */
8199
- Flicking.VERSION = "4.13.2-beta.1";
8199
+ Flicking.VERSION = "4.14.0";
8200
8200
  return Flicking;
8201
8201
  }(Component);
8202
8202
 
@@ -8783,6 +8783,196 @@ version: 4.13.2-beta.1
8783
8783
  getDefaultCameraTransform: getDefaultCameraTransform
8784
8784
  };
8785
8785
 
8786
+ // Check if Flicking has reached the first panel
8787
+ var getIsReachStart = function (flicking) {
8788
+ return !flicking.circular && flicking.index === 0;
8789
+ };
8790
+ // Check if Flicking has reached the last panel
8791
+ var getIsReachEnd = function (flicking) {
8792
+ return !flicking.circular && flicking.index === flicking.panelCount - 1;
8793
+ };
8794
+ // Get the total number of panels
8795
+ var getTotalPanelCount = function (flicking) {
8796
+ return flicking.panelCount;
8797
+ };
8798
+ // Get the current active panel index
8799
+ var getCurrentPanelIndex = function (flicking) {
8800
+ return flicking.index;
8801
+ };
8802
+ // Calculate the overall scroll progress percentage based on the current camera position
8803
+ var getProgress = function (flicking) {
8804
+ var cam = flicking.camera;
8805
+ var progressRatio = (cam.position - cam.range.min) / (cam.range.max - cam.range.min);
8806
+ var percent = Math.min(Math.max(progressRatio, 0), 1) * 100;
8807
+ return percent;
8808
+ };
8809
+ // Calculate the progress between panels including decimal values
8810
+ var getIndexProgress = function (flicking) {
8811
+ var cam = flicking.camera;
8812
+ var anchorPoints = cam.anchorPoints;
8813
+ var length = anchorPoints.length;
8814
+ var cameraPosition = cam.position;
8815
+ var isCircular = flicking.circularEnabled;
8816
+ var indexProgress = 0;
8817
+ var _a = cam.range,
8818
+ min = _a.min,
8819
+ max = _a.max;
8820
+ var firstAnchorPoint = anchorPoints[0];
8821
+ var lastAnchorPoint = anchorPoints[length - 1];
8822
+ var distanceLastToFirst = max - lastAnchorPoint.position + (firstAnchorPoint.position - min);
8823
+ anchorPoints.some(function (anchorPoint, index) {
8824
+ var anchorPosition = anchorPoint.position;
8825
+ var nextAnchorPoint = anchorPoints[index + 1];
8826
+ if (index === 0 && cameraPosition <= anchorPosition) {
8827
+ if (isCircular) {
8828
+ indexProgress = (cameraPosition - anchorPosition) / distanceLastToFirst;
8829
+ } else {
8830
+ indexProgress = (cameraPosition - anchorPosition) / anchorPoint.panel.size;
8831
+ }
8832
+ } else if (index === length - 1 && cameraPosition >= anchorPosition) {
8833
+ if (isCircular) {
8834
+ indexProgress = index + (cameraPosition - anchorPosition) / distanceLastToFirst;
8835
+ } else {
8836
+ indexProgress = index + (cameraPosition - anchorPosition) / anchorPoint.panel.size;
8837
+ }
8838
+ } else if (nextAnchorPoint && anchorPosition <= cameraPosition && cameraPosition <= nextAnchorPoint.position) {
8839
+ indexProgress = index + (cameraPosition - anchorPosition) / (nextAnchorPoint.position - anchorPosition);
8840
+ } else {
8841
+ return false;
8842
+ }
8843
+ return true;
8844
+ });
8845
+ return indexProgress;
8846
+ };
8847
+ /**
8848
+ * Internal reactive API adapter for Flicking that manages state and event listeners
8849
+ * This adapter is used internally by framework-specific packages (react-flicking, vue-flicking, etc.)
8850
+ * to provide reactive API support. Users rarely need to use this directly.
8851
+ * @ko Flicking의 상태와 이벤트 리스너를 관리하는 내부 반응형 API 어댑터
8852
+ * 이 어댑터는 react-flicking, vue-flicking 등의 프레임워크별 패키지에서 내부적으로 사용되어
8853
+ * 반응형 API 지원을 제공합니다. 사용자가 직접 사용할 일은 거의 없습니다.
8854
+ * @param onInit - Callback when reactive object is initialized<ko>반응형 객체가 초기화될 때 호출되는 콜백</ko>
8855
+ * @param onDestroy - Callback when reactive object is destroyed<ko>반응형 객체가 파괴될 때 호출되는 콜백</ko>
8856
+ * @param setMethods - Function to set available methods<ko>사용 가능한 메서드를 설정하는 함수</ko>
8857
+ * @returns Reactive object with Flicking state and methods<ko>Flicking 상태와 메서드를 포함한 반응형 객체</ko>
8858
+ */
8859
+ var flickingReactiveAPIAdapter = function (_a) {
8860
+ var _b, _c, _d;
8861
+ var onInit = _a.onInit,
8862
+ onDestroy = _a.onDestroy,
8863
+ setMethods = _a.setMethods,
8864
+ getProps = _a.getProps;
8865
+ var flicking;
8866
+ // Move to a specific panel index
8867
+ var moveTo = function (i) {
8868
+ if (flicking == null) {
8869
+ return Promise.reject(new Error("Flicking instance is not available"));
8870
+ }
8871
+ if (flicking === null || flicking === void 0 ? void 0 : flicking.animating) {
8872
+ return Promise.resolve();
8873
+ }
8874
+ return flicking.moveTo(i);
8875
+ };
8876
+ setMethods(["moveTo"]);
8877
+ var options = getProps().options;
8878
+ // options를 고려하지 않고 초기값을 설정해도 동작에는 아무런 문제가 없으나, 이 시점의 초기값과 컴포넌트 init 단계에서의 초기값이 다르면 화면 리렌더링이 발생할 수 있으므로
8879
+ // 이렇게 미리 옵션을 통해서 예측할 수 있는 부분들은 맞춰둔다.
8880
+ var reactiveObj = core.reactive({
8881
+ isReachStart: (options === null || options === void 0 ? void 0 : options.defaultIndex) ? (options === null || options === void 0 ? void 0 : options.defaultIndex) === 0 : true,
8882
+ 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,
8883
+ totalPanelCount: (_b = options === null || options === void 0 ? void 0 : options.totalPanelCount) !== null && _b !== void 0 ? _b : 0,
8884
+ currentPanelIndex: (_c = options === null || options === void 0 ? void 0 : options.defaultIndex) !== null && _c !== void 0 ? _c : 0,
8885
+ progress: 0,
8886
+ indexProgress: (_d = options === null || options === void 0 ? void 0 : options.defaultIndex) !== null && _d !== void 0 ? _d : 0,
8887
+ moveTo: moveTo
8888
+ });
8889
+ // Update state when panel changes
8890
+ var onChanged = function () {
8891
+ if (flicking === undefined) return;
8892
+ reactiveObj.isReachStart = getIsReachStart(flicking);
8893
+ reactiveObj.isReachEnd = getIsReachEnd(flicking);
8894
+ reactiveObj.currentPanelIndex = getCurrentPanelIndex(flicking);
8895
+ };
8896
+ // Update state when panel count changes
8897
+ var onPanelChange = function () {
8898
+ if (flicking === undefined) return;
8899
+ onChanged();
8900
+ reactiveObj.totalPanelCount = getTotalPanelCount(flicking);
8901
+ };
8902
+ // Update progress when camera moves
8903
+ var onMove = function () {
8904
+ if (flicking === undefined) return;
8905
+ reactiveObj.progress = getProgress(flicking);
8906
+ reactiveObj.indexProgress = getIndexProgress(flicking);
8907
+ };
8908
+ onInit(function (inst, data) {
8909
+ flicking = data.flicking;
8910
+ if (flicking === undefined) return;
8911
+ reactiveObj.isReachStart = getIsReachStart(flicking);
8912
+ reactiveObj.isReachEnd = getIsReachEnd(flicking);
8913
+ reactiveObj.currentPanelIndex = getCurrentPanelIndex(flicking);
8914
+ reactiveObj.progress = getProgress(flicking);
8915
+ reactiveObj.totalPanelCount = getTotalPanelCount(flicking);
8916
+ flicking === null || flicking === void 0 ? void 0 : flicking.on("changed", onChanged);
8917
+ flicking === null || flicking === void 0 ? void 0 : flicking.on("panelChange", onPanelChange);
8918
+ flicking === null || flicking === void 0 ? void 0 : flicking.on("move", onMove);
8919
+ });
8920
+ onDestroy(function () {
8921
+ flicking === null || flicking === void 0 ? void 0 : flicking.off("changed", onChanged);
8922
+ flicking === null || flicking === void 0 ? void 0 : flicking.off("panelChange", onPanelChange);
8923
+ flicking === null || flicking === void 0 ? void 0 : flicking.off("move", onMove);
8924
+ });
8925
+ return reactiveObj;
8926
+ };
8927
+ /**
8928
+ * Connect Flicking instance to reactive API
8929
+ * @ko Flicking 인스턴스를 반응형 API에 연결합니다
8930
+ * @param {Flicking} flicking - Flicking instance to connect<ko>연결할 Flicking 인스턴스</ko>
8931
+ * @param {FlickingReactiveAPIOptions} [options] - Flicking options<ko>Flicking 옵션</ko>
8932
+ * @returns {FlickingReactiveObject} Reactive object with Flicking state and methods<ko>Flicking 상태와 메서드를 포함한 반응형 객체</ko>
8933
+ * @example
8934
+ * ```js
8935
+ * import Flicking, { connectFlickingReactiveAPI } from "@egjs/flicking";
8936
+ *
8937
+ * const flicking = new Flicking("#el");
8938
+ * const reactiveObj = connectFlickingReactiveAPI(flicking);
8939
+ *
8940
+ * // Access reactive state
8941
+ * console.log("Current panel:", reactiveObj.currentPanelIndex);
8942
+ * console.log("Progress:", reactiveObj.progress + "%");
8943
+ * console.log("Is at start:", reactiveObj.isReachStart);
8944
+ * console.log("Is at end:", reactiveObj.isReachEnd);
8945
+ * console.log("Total panels:", reactiveObj.totalPanelCount);
8946
+ * console.log("Index progress:", reactiveObj.indexProgress);
8947
+ *
8948
+ * // Subscribe to state changes
8949
+ * reactiveObj.subscribe("currentPanelIndex", (nextValue) => {
8950
+ * console.log("Panel changed to:", nextValue);
8951
+ * });
8952
+ *
8953
+ * // Use reactive methods
8954
+ * reactiveObj.moveTo(2); // Move to third panel
8955
+ * ```
8956
+ */
8957
+ var connectFlickingReactiveAPI = function (flicking, options) {
8958
+ var obj = core.adaptReactive(flickingReactiveAPIAdapter, function () {
8959
+ return {
8960
+ flicking: flicking,
8961
+ options: options
8962
+ };
8963
+ });
8964
+ obj.mounted();
8965
+ var instance = obj.instance();
8966
+ obj.init();
8967
+ return instance;
8968
+ };
8969
+
8970
+ var FlickingReactiveAPI = {
8971
+ __proto__: null,
8972
+ flickingReactiveAPIAdapter: flickingReactiveAPIAdapter,
8973
+ connectFlickingReactiveAPI: connectFlickingReactiveAPI
8974
+ };
8975
+
8786
8976
  /*
8787
8977
  * Copyright (c) 2015 NAVER Corp.
8788
8978
  * egjs projects are licensed under the MIT license
@@ -8795,6 +8985,7 @@ version: 4.13.2-beta.1
8795
8985
  merge(Flicking, CFC);
8796
8986
  merge(Flicking, Utils);
8797
8987
  merge(Flicking, CrossFlicking$1);
8988
+ merge(Flicking, FlickingReactiveAPI);
8798
8989
 
8799
8990
  return Flicking;
8800
8991