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I,QAAQ;IACZ,MAAO,KAAK,OAAO,CAAC,WAAW,EAAG;QAChC,IAAI,CAAA,GAAA,uCAAS,EAAE,MAAM,MAAM,WAAW,GACpC,QAAQ,MAAM,MAAM;QAGtB,MAAM,IAAI,CAAC;YACT,sDAAsD;YACtD,wDAAwD;YACxD,yDAAyD;YACzD,4CAA4C;YAC5C,IAAI,MAAM,MAAM;kBAChB;YACA,WAAW,UAAU,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,QAAQ;QACxD;QAEA,OAAO,KAAK,GAAG,CAAC;YAAC,OAAO;QAAC;IAC3B;IAEA,IAAI,UAAC,MAAM,EAAC,GAAG,CAAA,GAAA,mCAAQ;IACvB,IAAI,YAAY,CAAA,GAAA,oBAAM,EACpB,IAAM,IAAI,KAAK,YAAY,CAAC,QAAQ;YAAC,MAAM;QAAe,GAAG,EAAE,CAAC,SAChE;QAAC;KAAO;IAGV,OAAO;QACL,cAAc;eACd;QACA,UAAU,CAAA;YACR,IAAI,OAAO,MACT,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;QAExC;QACA,OAAO;IACT;AACF","sources":["packages/react-aria/src/calendar/useCalendarYearPicker.ts"],"sourcesContent":["/*\n * Copyright 2026 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CalendarDate, isSameYear, toCalendarDate} from '@internationalized/date';\nimport {CalendarSelectionMode, CalendarState} from 'react-stately/useCalendarState';\nimport {Key} from '@react-types/shared';\nimport {RangeCalendarState} from 'react-stately/useRangeCalendarState';\nimport {useDateFormatter} from '../i18n/useDateFormatter';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useMemo} from 'react';\n\nexport interface CalendarYearPickerFormatOptions {\n year?: 'numeric' | '2-digit';\n era?: 'long' | 'short' | 'narrow';\n}\n\nexport interface CalendarYearPickerProps {\n /**\n * The number of years to display.\n *\n * @default 20\n */\n visibleYears?: number;\n /**\n * The format to display.\n */\n format?: CalendarYearPickerFormatOptions;\n}\n\nexport interface CalendarYearPickerAria {\n 'aria-label': string;\n value: Key;\n onChange: (key: Key | null) => void;\n items: CalendarYearPickerItem[];\n}\n\nexport interface CalendarYearPickerItem {\n id: number;\n date: CalendarDate;\n formatted: string;\n}\n\nexport function useCalendarYearPicker(\n props: CalendarYearPickerProps,\n state: CalendarState<CalendarSelectionMode> | RangeCalendarState\n): CalendarYearPickerAria {\n let formatter = useDateFormatter({\n year: props.format?.year || 'numeric',\n era:\n props.format?.era ||\n (state.focusedDate.calendar.identifier === 'gregory' && state.focusedDate.era === 'BC'\n ? 'short'\n : undefined),\n calendar: state.focusedDate.calendar.identifier,\n timeZone: state.timeZone\n });\n\n // Determine the minimum and maximum date. By default, show an equal number of years on each side of the current year.\n // However, this can be constrained by the calendar's minimum and maximum date.\n let visibleYears = props.visibleYears || 20;\n let minDate = state.focusedDate.subtract({years: Math.floor(visibleYears / 2)});\n let maxDate = state.focusedDate.add({years: Math.ceil(visibleYears / 2)});\n if (state.maxValue && maxDate.compare(state.maxValue) > 0) {\n maxDate = toCalendarDate(state.maxValue);\n minDate = maxDate.subtract({years: visibleYears});\n }\n\n if (state.minValue && minDate.compare(state.minValue) < 0) {\n minDate = toCalendarDate(state.minValue);\n maxDate = minDate.add({years: visibleYears});\n if (state.maxValue && maxDate.compare(state.maxValue) > 0) {\n maxDate = toCalendarDate(state.maxValue);\n }\n }\n\n let years: CalendarYearPickerItem[] = [];\n let date = minDate;\n let value = 0;\n while (date.compare(maxDate) < 0) {\n if (isSameYear(date, state.focusedDate)) {\n value = years.length;\n }\n\n years.push({\n // Use the index as the id so we can retrieve the full\n // date object from the list in onChange. We cannot only\n // store the year number, because in some calendars, such\n // as the Japanese, the era may also change.\n id: years.length,\n date,\n formatted: formatter.format(date.toDate(state.timeZone))\n });\n\n date = date.add({years: 1});\n }\n\n let {locale} = useLocale();\n let ariaLabel = useMemo(\n () => new Intl.DisplayNames(locale, {type: 'dateTimeField'}).of('year')!,\n [locale]\n );\n\n return {\n 'aria-label': ariaLabel,\n value,\n onChange: key => {\n if (key != null) {\n state.setFocusedDate(years[key].date);\n }\n },\n items: years\n };\n}\n"],"names":[],"version":3,"file":"useCalendarYearPicker.cjs.map"}