@@ -7,16 +7,19 @@ import {
77
88import Flicking from "../Flicking" ;
99
10+ // Check if Flicking has reached the first panel
1011const getIsReachStart = ( flicking : Flicking ) => ! flicking . circular && flicking . index === 0 ;
1112
13+ // Check if Flicking has reached the last panel
1214const getIsReachEnd = ( flicking : Flicking ) => ! flicking . circular && flicking . index === flicking . panelCount - 1 ;
1315
14-
16+ // Get the total number of panels
1517const getTotalPanelCount = ( flicking : Flicking ) => flicking . panelCount ;
16- const getCurrentPanelIndex = ( flicking : Flicking ) => flicking . index ;
1718
19+ // Get the current active panel index
20+ const getCurrentPanelIndex = ( flicking : Flicking ) => flicking . index ;
1821
19- // Returns the progress percentage based on the current scroll position.
22+ // Calculate the overall scroll progress percentage based on the current camera position
2023const getProgress = ( flicking : Flicking ) => {
2124 const cam = flicking . camera ;
2225
@@ -26,6 +29,8 @@ const getProgress = (flicking: Flicking) => {
2629
2730 return percent ;
2831} ;
32+
33+ // Calculate the progress between panels including decimal values
2934const getIndexProgress = ( flicking : Flicking ) => {
3035 const cam = flicking . camera ;
3136 const anchorPoints = cam . anchorPoints ;
@@ -66,52 +71,107 @@ const getIndexProgress = (flicking: Flicking) => {
6671 return indexProgress ;
6772} ;
6873
74+ /**
75+ * Reactive object type that combines state and methods for Flicking
76+ * This type provides reactive state properties and methods that automatically update
77+ * when the Flicking instance state changes.
78+ * @ko Flicking의 상태와 메서드를 결합한 반응형 객체 타입
79+ * 이 타입은 Flicking 인스턴스의 상태가 변경될 때 자동으로 업데이트되는
80+ * 반응형 상태 속성들과 메서드들을 제공합니다.
81+ * @typedef
82+ *
83+ * @property {boolean } isReachStart - Whether Flicking has reached the first panel<ko>첫 번째 패널에 도달했는지 여부</ko>
84+ * @property {boolean } isReachEnd - Whether Flicking has reached the last panel<ko>마지막 패널에 도달했는지 여부</ko>
85+ * @property {number } totalPanelCount - Total number of panels<ko>전체 패널 개수</ko>
86+ * @property {number } currentPanelIndex - Current active panel index<ko>현재 활성화된 패널의 인덱스</ko>
87+ * @property {number } progress - Overall scroll progress percentage (0-100)<ko>전체 스크롤 진행률 (0-100)</ko>
88+ * @property {number } indexProgress - Panel progress with decimal values<ko>패널 간 진행률 (소수점 포함)</ko>
89+ * @property {function } moveTo - Move to a specific panel index<ko>특정 패널 인덱스로 이동하는 함수</ko>
90+ */
6991export type FlickingReactiveObject = ReactiveObject < FlickingReactiveState & FlickingReactiveMethod > ;
7092
7193/**
72- * @typedef
94+ * Reactive state properties for Flicking
95+ * @ko Flicking의 반응형 상태 속성들
96+ * @interface
97+ * @property {boolean } isReachStart - Whether Flicking has reached the first panel<ko>첫 번째 패널에 도달했는지 여부</ko>
98+ * @property {boolean } isReachEnd - Whether Flicking has reached the last panel<ko>마지막 패널에 도달했는지 여부</ko>
99+ * @property {number } totalPanelCount - Total number of panels<ko>전체 패널 개수</ko>
100+ * @property {number } currentPanelIndex - Current active panel index<ko>현재 활성화된 패널의 인덱스</ko>
101+ * @property {number } progress - Overall scroll progress percentage (0-100)<ko>전체 스크롤 진행률 (0-100)</ko>
102+ * @property {number } indexProgress - Panel progress with decimal values<ko>패널 간 진행률 (소수점 포함)</ko>
73103 */
74104export interface FlickingReactiveState {
75105 /**
76- * isReachStart
77- * @ko isReachStart
106+ * Whether Flicking has reached the first panel
107+ * @ko 첫 번째 패널에 도달했는지 여부
78108 */
79109 isReachStart : boolean ;
80110 /**
81- * isReachEnd
82- * @ko isReachEnd
111+ * Whether Flicking has reached the last panel
112+ * @ko 마지막 패널에 도달했는지 여부
83113 */
84114 isReachEnd : boolean ;
85115 /**
86- * totalPanelCount
87- * @ko totalPanelCount
116+ * Total number of panels
117+ * @ko 전체 패널 개수
88118 */
89119 totalPanelCount : number ;
90120 /**
91- * currentPanelIndex
92- * @ko currentPanelIndex
121+ * Current active panel index
122+ * @ko 현재 활성화된 패널의 인덱스
93123 */
94124 currentPanelIndex : number ;
95125 /**
96- * totalPanelCount
97- * @ko totalPanelCount
126+ * Overall scroll progress percentage (0-100)
127+ * @ko 전체 스크롤 진행률 (0-100)
98128 */
99129 progress : number ;
100130 /**
101- * indexProgress
102- * @ko indexProgress
131+ * Panel progress with decimal values
132+ * @ko 패널 간 진행률 (소수점 포함)
103133 */
104134 indexProgress : number ;
105135}
106136
137+ /**
138+ * Reactive methods for Flicking
139+ * @ko Flicking의 반응형 메서드들
140+ * @interface
141+ * @property {function } moveTo - Move to a specific panel index<ko>특정 패널 인덱스로 이동</ko>
142+ */
107143export interface FlickingReactiveMethod {
144+ /**
145+ * Move to a specific panel index
146+ * @ko 특정 패널 인덱스로 이동합니다
147+ * @param i - Target panel index<ko>목표 패널 인덱스</ko>
148+ * @returns Promise that resolves when movement is complete<ko>이동이 완료되면 resolve되는 Promise</ko>
149+ */
108150 moveTo : ( i : number ) => Promise < void > ;
109151}
110152
153+ /**
154+ * Data required for reactive API setup
155+ * @ko 반응형 API 설정에 필요한 데이터
156+ * @interface
157+ * @property {Flicking | null } flicking - Flicking instance or null<ko>Flicking 인스턴스 또는 null</ko>
158+ */
111159export interface FlickingReactiveData {
112160 flicking : Flicking | null ;
113161}
114162
163+ /**
164+ * Internal reactive API adapter for Flicking that manages state and event listeners
165+ * This adapter is used internally by framework-specific packages (react-flicking, vue-flicking, etc.)
166+ * to provide reactive API support. Users rarely need to use this directly.
167+ * @ko Flicking의 상태와 이벤트 리스너를 관리하는 내부 반응형 API 어댑터
168+ * 이 어댑터는 react-flicking, vue-flicking 등의 프레임워크별 패키지에서 내부적으로 사용되어
169+ * 반응형 API 지원을 제공합니다. 사용자가 직접 사용할 일은 거의 없습니다.
170+ * @param onInit - Callback when reactive object is initialized<ko>반응형 객체가 초기화될 때 호출되는 콜백</ko>
171+ * @param onDestroy - Callback when reactive object is destroyed<ko>반응형 객체가 파괴될 때 호출되는 콜백</ko>
172+ * @param setMethods - Function to set available methods<ko>사용 가능한 메서드를 설정하는 함수</ko>
173+ * @returns Reactive object with Flicking state and methods<ko>Flicking 상태와 메서드를 포함한 반응형 객체</ko>
174+ */
115175const flickingReactiveAPIAdapter : ReactiveSetupAdapter <
116176FlickingReactiveObject ,
117177FlickingReactiveState ,
@@ -120,6 +180,7 @@ FlickingReactiveData
120180> = ( { onInit, onDestroy, setMethods } ) => {
121181 let flicking : Flicking | null = null ;
122182
183+ // Move to a specific panel index
123184 const moveTo = ( i : number ) => {
124185 if ( flicking === null ) {
125186 return Promise . reject ( new Error ( "Flicking instance is not available" ) ) ;
@@ -141,6 +202,7 @@ FlickingReactiveData
141202 moveTo
142203 } ) ;
143204
205+ // Update state when panel changes
144206 const onChanged = ( ) => {
145207 if ( flicking === null ) return ;
146208
@@ -149,13 +211,15 @@ FlickingReactiveData
149211 reactiveObj . currentPanelIndex = getCurrentPanelIndex ( flicking ) ;
150212 } ;
151213
214+ // Update state when panel count changes
152215 const onPanelChange = ( ) => {
153216 if ( flicking === null ) return ;
154217
155218 onChanged ( ) ;
156219 reactiveObj . totalPanelCount = getTotalPanelCount ( flicking ) ;
157220 } ;
158221
222+ // Update progress when camera moves
159223 const onMove = ( ) => {
160224 if ( flicking === null ) return ;
161225
@@ -188,6 +252,35 @@ FlickingReactiveData
188252 return reactiveObj ;
189253} ;
190254
255+ /**
256+ * Connect Flicking instance to reactive API
257+ * @ko Flicking 인스턴스를 반응형 API에 연결합니다
258+ * @param flicking - Flicking instance to connect<ko>연결할 Flicking 인스턴스</ko>
259+ * @returns {FlickingReactiveObject } Reactive object with Flicking state and methods<ko>Flicking 상태와 메서드를 포함한 반응형 객체</ko>
260+ * @example
261+ * ```js
262+ * import Flicking, { connectFlickingReactiveAPI } from "@egjs/flicking";
263+ *
264+ * const flicking = new Flicking("#el");
265+ * const reactiveObj = connectFlickingReactiveAPI(flicking);
266+ *
267+ * // Access reactive state
268+ * console.log("Current panel:", reactiveObj.currentPanelIndex);
269+ * console.log("Progress:", reactiveObj.progress + "%");
270+ * console.log("Is at start:", reactiveObj.isReachStart);
271+ * console.log("Is at end:", reactiveObj.isReachEnd);
272+ * console.log("Total panels:", reactiveObj.totalPanelCount);
273+ * console.log("Index progress:", reactiveObj.indexProgress);
274+ *
275+ * // Subscribe to state changes
276+ * reactiveObj.subscribe("currentPanelIndex", (nextValue) => {
277+ * console.log("Panel changed to:", nextValue);
278+ * });
279+ *
280+ * // Use reactive methods
281+ * reactiveObj.moveTo(2); // Move to third panel
282+ * ```
283+ */
191284const connectFlickingReactiveAPI = ( flicking : Flicking ) => {
192285 const obj = adaptReactive ( flickingReactiveAPIAdapter , ( ) => ( { flicking } ) ) ;
193286 obj . mounted ( ) ;
0 commit comments