@@ -42,19 +42,28 @@ import { computed, h, provide, ref, useAttrs, useId, watch } from 'vue';
4242import { CdrFilmstripEventKey } from ' ../../types/symbols' ;
4343
4444/**
45- * Configures the options for the CdrFilmstrip component.
46- */
45+ * Responsive, accessible filmstrip for displaying a horizontal list of content frames.
46+ * @uses CdrFilmstripEngine
47+ **/
4748defineOptions ({ name: ' CdrFilmstrip' });
4849
4950/**
5051 * Emits an event with a specified name and optional payload.
52+ * These events are used for communication between the filmstrip component and its consumers.
53+ *
54+ * @event arrowClick - Emitted when a navigation arrow is clicked.
55+ * @event ariaMessage - Emitted to update screen readers with the current frame information.
5156 */
5257const emit = defineEmits <{
5358 (e : string , payload ? : unknown ): void ;
5459}>();
5560
5661/**
5762 * Provides a centralized event emitter function for the filmstrip and its frames.
63+ * This enables child components to dispatch events upward.
64+ *
65+ * @param {string} eventName - The name of the event to emit.
66+ * @param {unknown} payload - The data payload to emit with the event.
5867 */
5968const emitEvent: CdrFilmstripEventEmitter = (eventName , payload ) => {
6069 emit (eventName , payload );
@@ -63,16 +72,25 @@ const emitEvent: CdrFilmstripEventEmitter = (eventName, payload) => {
6372const attrs = useAttrs ();
6473/**
6574 * Extracts the class attribute from the component's attributes.
75+ * This class is applied to the CdrFilmstripEngine for styling purposes.
6676 */
6777const classAttr = attrs .class || ' ' ;
6878
6979/**
70- * Provides the event emitter function to child components.
80+ * Provides the event emitter function to child components via dependency injection.
81+ * This allows descendant components to trigger events on the filmstrip component.
7182 */
7283provide (CdrFilmstripEventKey , emitEvent );
7384
7485/**
7586 * Defines the props for the CdrFilmstrip component.
87+ *
88+ * @prop {unknown} model - The data model representing the filmstrip content.
89+ * @prop {Function} adapter - A function that transforms the model into a filmstrip configuration.
90+ *
91+ * @default
92+ * model: {}
93+ * adapter: A function that logs a warning and returns a default filmstrip configuration.
7694 */
7795const props = withDefaults (defineProps <CdrFilmstrip <unknown >>(), {
7896 model : () => ({}),
@@ -94,46 +112,69 @@ const FRAMES_TO_SHOW_DEFAULT = 6;
94112
95113/**
96114 * Resolves and transforms the filmstrip model.
115+ * The adapter function is applied to the model to obtain a consistent filmstrip configuration.
116+ *
117+ * @returns {CdrFilmstripConfig<unknown>} The transformed filmstrip configuration.
97118 */
98119const filmstripConfig = computed <CdrFilmstripConfig <unknown >>(() => props .adapter (props .model ));
99120
100121/**
101122 * Number of frames to display at a time.
123+ * Defaults to FRAMES_TO_SHOW_DEFAULT if the adapter does not specify a value.
124+ *
125+ * @default FRAMES_TO_SHOW_DEFAULT
102126 */
103127const framesToShow = ref <number >(filmstripConfig ?.value ?.framesToShow ?? FRAMES_TO_SHOW_DEFAULT );
104128
105129/**
106130 * Number of frames to scroll at a time.
131+ * Typically matches the number of frames displayed unless overridden.
107132 */
108133const framesToScroll = ref <number >(framesToShow .value );
109134
110135/**
111136 * Extracts frames from the resolved filmstrip model.
137+ *
138+ * @returns {CdrFilmstripFrame<never>[]} An array of frames to be rendered by the filmstrip engine.
112139 */
113140const frames = computed (() => filmstripConfig .value .frames as CdrFilmstripFrame <never >[]);
114141
115142/**
116- * Checks if the filmstrip has frames.
143+ * Checks if the filmstrip has any frames to display.
144+ *
145+ * @returns {boolean} True if there is at least one frame, false otherwise.
117146 */
118147const hasFilmstripFrames = computed (() => frames .value .length > 0 );
119148
120149/**
121- * Retrieves filmstrip metadata.
150+ * Retrieves filmstrip metadata and generates a unique filmstrip ID.
151+ * The unique ID is used for accessibility and to prevent DOM conflicts.
152+ *
153+ * @returns {string} A unique identifier for the filmstrip.
122154 */
123155const filmstripId = computed (() => ` ${filmstripConfig .value .filmstripId }-${useId ()} ` );
124156
125157/**
126158 * Retrieves the description for the filmstrip.
159+ * This description is used to provide context for screen readers.
160+ *
161+ * @returns {string} The filmstrip's description.
127162 */
128163const description = computed (() => filmstripConfig .value .description );
129164
130165/**
131- * Retrieves the gap between frames.
166+ * Retrieves the gap between frames as defined in the filmstrip configuration.
167+ *
168+ * @returns {number} The gap (in pixels) between individual frames.
132169 */
133170const framesGap = computed (() => filmstripConfig ?.value ?.framesGap || 0 );
134171
135172/**
136173 * Determines if the filmstrip should use the default resize strategy.
174+ * This flag controls whether the component automatically adjusts the number
175+ * of frames displayed based on the window size.
176+ *
177+ * @returns {boolean} True if the default resize strategy is enabled, false otherwise.
137178 */
138179const useDefaultResizeStrategy = ref <boolean >(
139180 typeof filmstripConfig ?.value ?.useDefaultResizeStrategy === ' boolean'
@@ -143,16 +184,24 @@ const useDefaultResizeStrategy = ref<boolean>(
143184
144185/**
145186 * Retrieves the focus selector for the filmstrip.
187+ * This selector determines which element within a frame should receive focus for accessibility.
188+ *
189+ * @returns {string} The CSS selector for the focusable element.
146190 */
147191const focusSelector = computed (() => filmstripConfig ?.value ?.focusSelector || ' :first-child' );
148192
149193/**
150- * Retrieves the data attributes for the filmstrip.
194+ * Retrieves additional data attributes for the filmstrip container.
195+ *
196+ * @returns {Record<string, unknown>} An object containing data attributes to be applied to the container.
151197 */
152198const dataAttributes = computed (() => filmstripConfig .value ?.dataAttributes || {});
153199
154200/**
155- * Handles arrow click events.
201+ * Handles arrow click events for navigating through the filmstrip.
202+ * Constructs an arrow click payload and emits the 'arrowClick' event.
203+ *
204+ * @param {CdrFilmstripArrowClickPayload} param0 - The arrow click event payload.
156205 */
157206function onArrowClick({ event , direction }: CdrFilmstripArrowClickPayload ) {
158207 const arrowClickPayload: CdrFilmstripArrowClickPayload = {
@@ -164,8 +213,8 @@ function onArrowClick({ event, direction }: CdrFilmstripArrowClickPayload) {
164213}
165214
166215/**
167- * Updates the number of frames dynamically based on screen size .
168- * Used only when no `resizeStrategy` is provided in `filmstripConfig` .
216+ * Updates the number of frames displayed based on the current screen width .
217+ * This function implements a default resize strategy in the absence of a custom strategy .
169218 */
170219function defaultResizeStrategy() {
171220 const screenWidth = window .innerWidth ;
@@ -174,7 +223,8 @@ function defaultResizeStrategy() {
174223}
175224
176225/**
177- * Handles window resize events.
226+ * Handles window resize events and updates the filmstrip layout accordingly.
227+ * The resize handling is debounced to improve performance.
178228 */
179229const onResize = useDebounceFn (() => {
180230 const resizePayload: CdrFilmstripResizePayload = {
@@ -189,7 +239,8 @@ const onResize = useDebounceFn(() => {
189239}, 25 );
190240
191241/**
192- * Sets up the resize observer for the filmstrip container.
242+ * Sets up a resize observer on the filmstrip container element.
243+ * This ensures that the filmstrip layout updates automatically when the container size changes.
193244 */
194245watch (
195246 () => CdrFilmstripContainer .value ,
0 commit comments