@fragiola/primitives 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +50 -2
- package/dist/async-list-Bv6ff5Oj.js +81 -0
- package/dist/async-list-Bv6ff5Oj.js.map +1 -0
- package/dist/async-list.d.ts +2 -0
- package/dist/async-list.js +1 -0
- package/dist/calendar-keys-DGYpjLwv.d.ts +12 -0
- package/dist/calendar-system-B5U5HcPQ.d.ts +415 -0
- package/dist/calendar-systems-Daa6Q_ca.js +659 -0
- package/dist/calendar-systems-Daa6Q_ca.js.map +1 -0
- package/dist/calendar-systems.d.ts +3 -0
- package/dist/calendar-systems.js +1 -0
- package/dist/carousel-LRbWqbAx.js +375 -0
- package/dist/carousel-LRbWqbAx.js.map +1 -0
- package/dist/carousel.d.ts +2 -0
- package/dist/carousel.js +1 -0
- package/dist/cascade-B155Xvvv.js +64 -0
- package/dist/cascade-B155Xvvv.js.map +1 -0
- package/dist/cascade.d.ts +2 -0
- package/dist/cascade.js +1 -0
- package/dist/clipboard-Cy2cbGEW.js +33 -0
- package/dist/clipboard-Cy2cbGEW.js.map +1 -0
- package/dist/clipboard.d.ts +2 -0
- package/dist/clipboard.js +1 -0
- package/dist/collection-Dbk-PB5S.js +609 -0
- package/dist/collection-Dbk-PB5S.js.map +1 -0
- package/dist/collection.d.ts +2 -0
- package/dist/collection.js +3 -0
- package/dist/color-sURV5Irg.js +699 -0
- package/dist/color-sURV5Irg.js.map +1 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +1 -0
- package/dist/command-DueCXi65.js +104 -0
- package/dist/command-DueCXi65.js.map +1 -0
- package/dist/command.d.ts +2 -0
- package/dist/command.js +1 -0
- package/dist/date-CrbFSJKQ.js +215 -0
- package/dist/date-CrbFSJKQ.js.map +1 -0
- package/dist/date.d.ts +4 -0
- package/dist/date.js +1 -0
- package/dist/direction-CTnVLpmd.d.ts +8 -0
- package/dist/direction-DJDPvnxJ.js +13 -0
- package/dist/direction-DJDPvnxJ.js.map +1 -0
- package/dist/direction.d.ts +2 -0
- package/dist/direction.js +1 -0
- package/dist/drag-session-CSr06B5v.js +41 -0
- package/dist/drag-session-CSr06B5v.js.map +1 -0
- package/dist/file-DSLtfzbi.js +263 -0
- package/dist/file-DSLtfzbi.js.map +1 -0
- package/dist/file.d.ts +2 -0
- package/dist/file.js +1 -0
- package/dist/focus-BI-VvM0f.js +75 -0
- package/dist/focus-BI-VvM0f.js.map +1 -0
- package/dist/focus.d.ts +2 -0
- package/dist/focus.js +3 -0
- package/dist/form-DovwKtqz.js +501 -0
- package/dist/form-DovwKtqz.js.map +1 -0
- package/dist/form.d.ts +2 -0
- package/dist/form.js +1 -0
- package/dist/hover-BakyPYnC.js +62 -0
- package/dist/hover-BakyPYnC.js.map +1 -0
- package/dist/hover.d.ts +2 -0
- package/dist/hover.js +1 -0
- package/dist/id-B0Y8iZrc.js +13 -0
- package/dist/id-B0Y8iZrc.js.map +1 -0
- package/dist/id.d.ts +2 -0
- package/dist/id.js +1 -0
- package/dist/image-D4X_yRYw.js +44 -0
- package/dist/image-D4X_yRYw.js.map +1 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +1 -0
- package/dist/index-B0rwIZw9.d.ts +51 -0
- package/dist/index-B4wF1isn.d.ts +128 -0
- package/dist/index-BHiBRE01.d.ts +20 -0
- package/dist/index-BNlMm-0u.d.ts +17 -0
- package/dist/index-BapNrjY9.d.ts +48 -0
- package/dist/index-Bd-tVb7C.d.ts +6 -0
- package/dist/index-BjE8nDiX.d.ts +125 -0
- package/dist/index-BpbT-FsX.d.ts +117 -0
- package/dist/index-CBgGcTeX.d.ts +37 -0
- package/dist/index-CGThV_Md.d.ts +100 -0
- package/dist/index-CMig3TXL.d.ts +28 -0
- package/dist/index-CWFRduRd.d.ts +212 -0
- package/dist/index-CkrHWyU_.d.ts +33 -0
- package/dist/index-Cwu6f7y1.d.ts +18 -0
- package/dist/index-D10LDdR6.d.ts +139 -0
- package/dist/index-D146vm21.d.ts +104 -0
- package/dist/index-DGKhEvNr.d.ts +107 -0
- package/dist/index-DbAu4s16.d.ts +48 -0
- package/dist/index-DdaCj6IO.d.ts +54 -0
- package/dist/index-DeHcNdjC.d.ts +68 -0
- package/dist/index-DeR4ncrW.d.ts +93 -0
- package/dist/index-HIksgK0e.d.ts +70 -0
- package/dist/index-IZB0mlZl.d.ts +71 -0
- package/dist/index-IfDZj87U.d.ts +28 -0
- package/dist/index-SrTuVBms.d.ts +75 -0
- package/dist/index-T9UcYvkf.d.ts +339 -0
- package/dist/index-fRTojAoR.d.ts +31 -0
- package/dist/index-fuLUke9n.d.ts +6 -0
- package/dist/index-l63esAck.d.ts +104 -0
- package/dist/index-raSUg9U7.d.ts +38 -0
- package/dist/index-twgzPKvZ.d.ts +278 -0
- package/dist/index-wBpjRykh.d.ts +125 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +42 -0
- package/dist/inert-DlGToy3q.js +80 -0
- package/dist/inert-DlGToy3q.js.map +1 -0
- package/dist/inert.d.ts +2 -0
- package/dist/inert.js +1 -0
- package/dist/layer-stack-BEtzaFC1.js +118 -0
- package/dist/layer-stack-BEtzaFC1.js.map +1 -0
- package/dist/layers-C-N4rrZX.js +24 -0
- package/dist/layers-C-N4rrZX.js.map +1 -0
- package/dist/layers.d.ts +2 -0
- package/dist/layers.js +3 -0
- package/dist/list-navigation-CbWv4DK5.js +40 -0
- package/dist/list-navigation-CbWv4DK5.js.map +1 -0
- package/dist/month-year-BG5imFUq.js +108 -0
- package/dist/month-year-BG5imFUq.js.map +1 -0
- package/dist/month-year.d.ts +3 -0
- package/dist/month-year.js +1 -0
- package/dist/number-BFUio97d.js +316 -0
- package/dist/number-BFUio97d.js.map +1 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +1 -0
- package/dist/overlay-BwPyiM3T.js +78 -0
- package/dist/overlay-BwPyiM3T.js.map +1 -0
- package/dist/overlay.d.ts +2 -0
- package/dist/overlay.js +1 -0
- package/dist/pagination-BkVzaIGP.js +51 -0
- package/dist/pagination-BkVzaIGP.js.map +1 -0
- package/dist/pagination.d.ts +2 -0
- package/dist/pagination.js +1 -0
- package/dist/plain-date-idQH1P6X.d.ts +29 -0
- package/dist/plain-date-time-B8PGahhe.d.ts +99 -0
- package/dist/pointer-CuDtD9XA.js +189 -0
- package/dist/pointer-CuDtD9XA.js.map +1 -0
- package/dist/pointer.d.ts +2 -0
- package/dist/pointer.js +3 -0
- package/dist/positioning-DDUQ75mB.js +148 -0
- package/dist/positioning-DDUQ75mB.js.map +1 -0
- package/dist/positioning.d.ts +2 -0
- package/dist/positioning.js +1 -0
- package/dist/presence-BhKDOmII.js +86 -0
- package/dist/presence-BhKDOmII.js.map +1 -0
- package/dist/presence.d.ts +2 -0
- package/dist/presence.js +1 -0
- package/dist/range-o0_GBhyY.js +158 -0
- package/dist/range-o0_GBhyY.js.map +1 -0
- package/dist/range.d.ts +2 -0
- package/dist/range.js +1 -0
- package/dist/scroll-area-BYNhv36t.js +447 -0
- package/dist/scroll-area-BYNhv36t.js.map +1 -0
- package/dist/scroll-area.d.ts +2 -0
- package/dist/scroll-area.js +1 -0
- package/dist/scroll-lock-JzRNOA1O.js +42 -0
- package/dist/scroll-lock-JzRNOA1O.js.map +1 -0
- package/dist/scroll-lock.d.ts +2 -0
- package/dist/scroll-lock.js +1 -0
- package/dist/segments-eRu5G_Bd.js +587 -0
- package/dist/segments-eRu5G_Bd.js.map +1 -0
- package/dist/segments.d.ts +3 -0
- package/dist/segments.js +1 -0
- package/dist/selection-Cor67w_V.js +287 -0
- package/dist/selection-Cor67w_V.js.map +1 -0
- package/dist/selection.d.ts +2 -0
- package/dist/selection.js +1 -0
- package/dist/swipe.d.ts +2 -0
- package/dist/swipe.js +1 -0
- package/dist/tabbable-BPiLssIv.js +35 -0
- package/dist/tabbable-BPiLssIv.js.map +1 -0
- package/dist/time-Ct6oq9kt.js +208 -0
- package/dist/time-Ct6oq9kt.js.map +1 -0
- package/dist/time-zone-DegkzwST.js +305 -0
- package/dist/time-zone-DegkzwST.js.map +1 -0
- package/dist/time-zone.d.ts +2 -0
- package/dist/time-zone.js +1 -0
- package/dist/time.d.ts +2 -0
- package/dist/time.js +1 -0
- package/dist/toast-BjRpJalM.js +400 -0
- package/dist/toast-BjRpJalM.js.map +1 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +1 -0
- package/dist/unit-grid-DJy8lb5D.d.ts +21 -0
- package/dist/virtual-BlX1RuHD.js +306 -0
- package/dist/virtual-BlX1RuHD.js.map +1 -0
- package/dist/virtual.d.ts +2 -0
- package/dist/virtual.js +1 -0
- package/dist/watch-swipe-BIucfr9O.js +301 -0
- package/dist/watch-swipe-BIucfr9O.js.map +1 -0
- package/package.json +234 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { t as createAsyncList } from "./async-list-Bv6ff5Oj.js";
|
|
2
|
+
import { a as gregory, c as islamicCivil, d as japanese, f as persian, i as ethiopic, l as islamicTbla, n as coptic, o as hebrew, p as roc, r as ethioaa, s as indian, t as buddhist, u as islamicUmalqura } from "./calendar-systems-Daa6Q_ca.js";
|
|
3
|
+
import { a as slideScrollPosition, c as slidesInView, i as nearestCarouselPage, l as stepCarouselPage, n as createRotationTimer, o as carouselPages, r as groupScrollPosition, s as clampCarouselPage, t as watchCarousel } from "./carousel-LRbWqbAx.js";
|
|
4
|
+
import { t as getDirection } from "./direction-DJDPvnxJ.js";
|
|
5
|
+
import { n as nextTabbableAfter, r as previousTabbableBefore, t as getTabbables } from "./tabbable-BPiLssIv.js";
|
|
6
|
+
import { t as startDrag } from "./drag-session-CSr06B5v.js";
|
|
7
|
+
import { a as swipeDisplacement, c as swipeRelease, i as resolveSnapPoints, n as watchSwipe, o as swipeMovement, s as swipeProgress, t as SWIPE_LOCK_DISTANCE } from "./watch-swipe-BIucfr9O.js";
|
|
8
|
+
import { i as cascadeKeyAction, n as cascadePathItems, r as hasCascadeChildren, t as cascadeLevels } from "./cascade-B155Xvvv.js";
|
|
9
|
+
import { n as announceText, t as writeClipboard } from "./clipboard-Cy2cbGEW.js";
|
|
10
|
+
import { A as textContains, C as flattenItems, D as itemLabel, E as itemFormValue, M as chipArrows, N as chipKeyTarget, O as itemsEqual, P as activationDirection, S as filterItems, T as isItemGroup, _ as menuKeyTarget, a as tagsInputTagKeyTarget, b as tabsKeyTarget, c as placeSegmentIndicator, d as inDocumentOrder, f as rovingKeyTarget, g as accordionKeyTarget, h as textFieldKeepsKey, i as tagsInputInputKeyTarget, j as toggleItem, k as queryIsLabel, l as segmentIndicatorBox, m as rovingTabStop, n as removalFocusIndex, o as placeTabsIndicator, p as rovingKeys, r as tagGroupKeyTarget, s as tabsIndicatorBox, t as createTypeahead, u as scrollIntoViewWithin, v as radioKeyTarget, w as includesItem, x as containsFilter, y as submenuKeys } from "./collection-Dbk-PB5S.js";
|
|
11
|
+
import { n as stepIndex, r as stepThroughNone, t as edgeIndex } from "./list-navigation-CbWv4DK5.js";
|
|
12
|
+
import { C as hasColorChannel, S as getColorChannel, T as setColorChannel, _ as clampColorChannel, a as hueAtPoint, b as colorChannels, c as colorWheelKeyTarget, d as colorChannelGradient, f as colorWheelGradient, g as convertColor, h as formatColorChannel, i as colorWheelThumbOffset, l as wrapHue, m as formatColor, n as supportsEyeDropper, o as isOnColorWheel, p as colorChannelFormat, r as parseColor, s as colorAreaKeyTarget, t as openEyeDropper, u as colorAreaBackground, v as colorAreaChannels, w as isSameColor, x as colorSpaceFor, y as colorChannelRange } from "./color-sURV5Irg.js";
|
|
13
|
+
import { a as commandKeyTarget, i as commandScore, n as commandItemScore, r as commandMatches, t as bestMatch } from "./command-DueCXi65.js";
|
|
14
|
+
import { C as fromIsoDate, D as toIsoDate, E as plainDate, O as toLocalDate, S as compareDates, T as isSameMonth, _ as isBetween, a as formatFullDate, b as startOfMonth, c as calendarKeyTarget, d as addYears, f as clampDate, g as endOfWeek, h as endOfMonth, i as formatDayNumber, k as today, l as addDays, m as daysInMonth, n as monthGrid, o as formatMonthYear, p as dayOfWeek, r as firstDayOfWeek, s as weekdays, t as watchDocumentLanguage, u as addMonths, v as isWithinBounds, w as isSameDate, x as startOfWeek, y as monthsBetween } from "./date-CrbFSJKQ.js";
|
|
15
|
+
import "./direction.js";
|
|
16
|
+
import { a as fieldFiles, c as acceptAttribute, i as formatFileSize, l as acceptFiles, n as watchFileDrop, o as checkFiles, r as openFileDialog, s as assignFiles, t as dragHasFiles, u as acceptsFile } from "./file-DSLtfzbi.js";
|
|
17
|
+
import { n as focusInitial, r as trapFocus, t as isKeyboardModality } from "./focus-BI-VvM0f.js";
|
|
18
|
+
import { A as validateField, C as fieldDescribedBy, D as UNVALIDATED, E as CLEARED, O as VALIDITY_KEYS, S as fieldErrorShown, T as validatesOnChange, _ as formErrorsFor, a as onSubmitAttempt, b as fieldStateAttributes, c as otpInputMode, d as replaceOtp, f as labelFocusTarget, g as guardFormSubmit, h as focusFieldControl, i as typesDelimiter, k as createFieldValidator, l as otpPattern, m as firstInDocumentOrder, n as editTag, o as normalizeOtp, p as preventLabelSelection, r as takeTags, s as otpAccepts, t as VISUALLY_HIDDEN_INPUT_STYLE, u as removeOtpCharacter, v as withoutFormErrors, w as shownAfterChange, x as fieldErrorMessages, y as bridgeForm } from "./form-DovwKtqz.js";
|
|
19
|
+
import { n as createDelayGroup, t as createHoverIntent } from "./hover-BakyPYnC.js";
|
|
20
|
+
import { t as createId } from "./id-B0Y8iZrc.js";
|
|
21
|
+
import { t as watchImageStatus } from "./image-D4X_yRYw.js";
|
|
22
|
+
import { n as blockOutsidePointer, t as inertOutside } from "./inert-DlGToy3q.js";
|
|
23
|
+
import { n as watchFocusOutside, t as pushLayer } from "./layer-stack-BEtzaFC1.js";
|
|
24
|
+
import { t as interceptEscape } from "./layers-C-N4rrZX.js";
|
|
25
|
+
import { a as UNIT_PAGE_SIZE, c as unitRows, d as monthIndex, f as toIsoYear, i as formatYearSpan, l as currentYearMonth, n as formatYear, o as unitKeyTarget, p as toIsoYearMonth, r as formatYearMonth, s as unitPageStart, t as formatMonthName, u as fromMonthIndex } from "./month-year-BG5imFUq.js";
|
|
26
|
+
import { a as parseNumber, c as watchAutoRepeat, i as isNumberText, n as clampNumber, o as formatNumber, r as stepNumber, s as numberFormatOptions, t as watchScrub } from "./number-BFUio97d.js";
|
|
27
|
+
import { t as openOverlaySession } from "./overlay-BwPyiM3T.js";
|
|
28
|
+
import { n as pageCount, r as paginationRange, t as clampPage } from "./pagination-BkVzaIGP.js";
|
|
29
|
+
import { a as isInHoverBridge, i as watchLongPress, n as watchPointerExit, r as isInSafeArea, t as trackHoverBridge } from "./pointer-CuDtD9XA.js";
|
|
30
|
+
import { i as toPlacement, n as virtualAnchor, r as fromPlacement, t as anchorFloating } from "./positioning-DDUQ75mB.js";
|
|
31
|
+
import { a as measurePanelSize, i as freezePanelSize, n as nextFrame, o as panelSizeVariables, r as waitForAnimations, s as watchBeforeMatch, t as isAnimating } from "./presence-BhKDOmII.js";
|
|
32
|
+
import { a as progressValue, c as nearestThumb, d as valueAtFraction, f as valueToPercent, i as ratingValueAt, l as snapToStep, n as ratingItemState, o as fractionAlong, r as ratingKeyTarget, s as moveThumb, t as sliderKeyTarget, u as thumbBounds } from "./range-o0_GBhyY.js";
|
|
33
|
+
import { a as scrollForThumbOffset, i as MIN_THUMB_SIZE, n as initialScrollAreaState, o as scrollFromStart, r as normalizeScrollAreaThreshold, s as thumbGeometry, t as createScrollArea } from "./scroll-area-BYNhv36t.js";
|
|
34
|
+
import { t as lockScroll } from "./scroll-lock-JzRNOA1O.js";
|
|
35
|
+
import { _ as segmentsToTime, a as focusOnLabelPress, b as stepSegment, c as dateSegments, d as isSegmentsComplete, f as segmentRange, g as segmentsToDateTime, h as segmentsToDate, i as typeSegment, l as SEGMENT_PAGE_STEPS, m as segmentValuesOf, n as eraseSegment, o as segmentTarget, p as segmentToEdge, r as segmentDigit, s as SEGMENT_PLACEHOLDER, t as segmentKeyDown, u as displayHour, v as setSegment, x as segmentFormat, y as shownValue } from "./segments-eRu5G_Bd.js";
|
|
36
|
+
import { a as pageTarget, c as listPressSelection, i as rowTarget, n as inModelOrder, o as createListModel, r as sameSelection, s as listKeyTarget, t as applySelection } from "./selection-Cor67w_V.js";
|
|
37
|
+
import "./swipe.js";
|
|
38
|
+
import { _ as toIsoTime, a as isSameDateTime, c as toPlainDate, d as compareTimes, f as currentTime, g as plainTime, h as isSameTime, i as fromIsoDateTime, l as toPlainTime, m as fromIsoTime, n as compareDateTimes, o as plainDateTime, p as cycleTime, r as currentDateTime, s as toIsoDateTime, t as addDateTime, u as addTime } from "./time-Ct6oq9kt.js";
|
|
39
|
+
import { a as formatTimeZoneName, c as localTimeZone, d as toIsoOffset, f as toIsoZoned, i as cycleZoned, l as offsetAt, m as toZoned, n as addZoned, o as fromInstant, p as toTimeZone, r as compareZoned, s as fromIsoZoned, t as timeZone, u as toInstant } from "./time-zone-DegkzwST.js";
|
|
40
|
+
import { n as createToastManager, r as measureToastHeight, t as watchToastViewport } from "./toast-BjRpJalM.js";
|
|
41
|
+
import { a as rowAt, i as pageIndex, n as scrollContainer, o as rowStarts, r as activeSticky, s as virtualLayout, t as createVirtualizer } from "./virtual-BlX1RuHD.js";
|
|
42
|
+
export { CLEARED, MIN_THUMB_SIZE, SEGMENT_PAGE_STEPS, SEGMENT_PLACEHOLDER, SWIPE_LOCK_DISTANCE, UNIT_PAGE_SIZE, UNVALIDATED, VALIDITY_KEYS, VISUALLY_HIDDEN_INPUT_STYLE, acceptAttribute, acceptFiles, acceptsFile, accordionKeyTarget, activationDirection, activeSticky, addDateTime, addDays, addMonths, addTime, addYears, addZoned, anchorFloating, announceText, applySelection, assignFiles, bestMatch, blockOutsidePointer, bridgeForm, buddhist, calendarKeyTarget, carouselPages, cascadeKeyAction, cascadeLevels, cascadePathItems, checkFiles, chipArrows, chipKeyTarget, clampCarouselPage, clampColorChannel, clampDate, clampNumber, clampPage, colorAreaBackground, colorAreaChannels, colorAreaKeyTarget, colorChannelFormat, colorChannelGradient, colorChannelRange, colorChannels, colorSpaceFor, colorWheelGradient, colorWheelKeyTarget, colorWheelThumbOffset, commandItemScore, commandKeyTarget, commandMatches, commandScore, compareDateTimes, compareDates, compareTimes, compareZoned, containsFilter, convertColor, coptic, createAsyncList, createDelayGroup, createFieldValidator, createHoverIntent, createId, createListModel, createRotationTimer, createScrollArea, createToastManager, createTypeahead, createVirtualizer, currentDateTime, currentTime, currentYearMonth, cycleTime, cycleZoned, dateSegments, dayOfWeek, daysInMonth, displayHour, dragHasFiles, edgeIndex, editTag, endOfMonth, endOfWeek, eraseSegment, ethioaa, ethiopic, fieldDescribedBy, fieldErrorMessages, fieldErrorShown, fieldFiles, fieldStateAttributes, filterItems, firstDayOfWeek, firstInDocumentOrder, flattenItems, focusFieldControl, focusInitial, focusOnLabelPress, formErrorsFor, formatColor, formatColorChannel, formatDayNumber, formatFileSize, formatFullDate, formatMonthName, formatMonthYear, formatNumber, formatTimeZoneName, formatYear, formatYearMonth, formatYearSpan, fractionAlong, freezePanelSize, fromInstant, fromIsoDate, fromIsoDateTime, fromIsoTime, fromIsoZoned, fromMonthIndex, fromPlacement, getColorChannel, getDirection, getTabbables, gregory, groupScrollPosition, guardFormSubmit, hasCascadeChildren, hasColorChannel, hebrew, hueAtPoint, inDocumentOrder, inModelOrder, includesItem, indian, inertOutside, initialScrollAreaState, interceptEscape, isAnimating, isBetween, isInHoverBridge, isInSafeArea, isItemGroup, isKeyboardModality, isNumberText, isOnColorWheel, isSameColor, isSameDate, isSameDateTime, isSameMonth, isSameTime, isSegmentsComplete, isWithinBounds, islamicCivil, islamicTbla, islamicUmalqura, itemFormValue, itemLabel, itemsEqual, japanese, labelFocusTarget, listKeyTarget, listPressSelection, localTimeZone, lockScroll, measurePanelSize, measureToastHeight, menuKeyTarget, monthGrid, monthIndex, monthsBetween, moveThumb, nearestCarouselPage, nearestThumb, nextFrame, nextTabbableAfter, normalizeOtp, normalizeScrollAreaThreshold, numberFormatOptions, offsetAt, onSubmitAttempt, openEyeDropper, openFileDialog, openOverlaySession, otpAccepts, otpInputMode, otpPattern, pageCount, pageIndex, pageTarget, paginationRange, panelSizeVariables, parseColor, parseNumber, persian, placeSegmentIndicator, placeTabsIndicator, plainDate, plainDateTime, plainTime, preventLabelSelection, previousTabbableBefore, progressValue, pushLayer, queryIsLabel, radioKeyTarget, ratingItemState, ratingKeyTarget, ratingValueAt, removalFocusIndex, removeOtpCharacter, replaceOtp, resolveSnapPoints, roc, rovingKeyTarget, rovingKeys, rovingTabStop, rowAt, rowStarts, rowTarget, sameSelection, scrollContainer, scrollForThumbOffset, scrollFromStart, scrollIntoViewWithin, segmentDigit, segmentFormat, segmentIndicatorBox, segmentKeyDown, segmentRange, segmentTarget, segmentToEdge, segmentValuesOf, segmentsToDate, segmentsToDateTime, segmentsToTime, setColorChannel, setSegment, shownAfterChange, shownValue, slideScrollPosition, sliderKeyTarget, slidesInView, snapToStep, startDrag, startOfMonth, startOfWeek, stepCarouselPage, stepIndex, stepNumber, stepSegment, stepThroughNone, submenuKeys, supportsEyeDropper, swipeDisplacement, swipeMovement, swipeProgress, swipeRelease, tabsIndicatorBox, tabsKeyTarget, tagGroupKeyTarget, tagsInputInputKeyTarget, tagsInputTagKeyTarget, takeTags, textContains, textFieldKeepsKey, thumbBounds, thumbGeometry, timeZone, toInstant, toIsoDate, toIsoDateTime, toIsoOffset, toIsoTime, toIsoYear, toIsoYearMonth, toIsoZoned, toLocalDate, toPlacement, toPlainDate, toPlainTime, toTimeZone, toZoned, today, toggleItem, trackHoverBridge, trapFocus, typeSegment, typesDelimiter, unitKeyTarget, unitPageStart, unitRows, validateField, validatesOnChange, valueAtFraction, valueToPercent, virtualAnchor, virtualLayout, waitForAnimations, watchAutoRepeat, watchBeforeMatch, watchCarousel, watchDocumentLanguage, watchFileDrop, watchFocusOutside, watchImageStatus, watchLongPress, watchPointerExit, watchScrub, watchSwipe, watchToastViewport, weekdays, withoutFormErrors, wrapHue, writeClipboard };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/inert/block-outside-pointer.ts
|
|
2
|
+
const blocks = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
/**
|
|
4
|
+
* Blocks the pointer outside a modal overlay (spec/menu.md, "Modal"): the body stops taking
|
|
5
|
+
* pointer events (`pointer-events: none`), so a press outside reaches no element of the page and
|
|
6
|
+
* only dismisses the overlay; the overlay's own elements opt back in with `pointer-events: auto`.
|
|
7
|
+
* Nested blocks are counted. Returns the restore.
|
|
8
|
+
*/
|
|
9
|
+
function blockOutsidePointer(doc) {
|
|
10
|
+
const existing = blocks.get(doc);
|
|
11
|
+
if (existing !== void 0) existing.count += 1;
|
|
12
|
+
else {
|
|
13
|
+
const body = doc.body;
|
|
14
|
+
const previous = body.style.pointerEvents;
|
|
15
|
+
body.style.pointerEvents = "none";
|
|
16
|
+
blocks.set(doc, {
|
|
17
|
+
count: 1,
|
|
18
|
+
restore: () => {
|
|
19
|
+
body.style.pointerEvents = previous;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
let released = false;
|
|
24
|
+
return () => {
|
|
25
|
+
if (released) return;
|
|
26
|
+
released = true;
|
|
27
|
+
const block = blocks.get(doc);
|
|
28
|
+
if (block === void 0) return;
|
|
29
|
+
block.count -= 1;
|
|
30
|
+
if (block.count === 0) {
|
|
31
|
+
block.restore();
|
|
32
|
+
blocks.delete(doc);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// src/inert/inert-outside.ts
|
|
37
|
+
/** A closed kept-mounted overlay's portal content. */
|
|
38
|
+
function isHiddenPart(element) {
|
|
39
|
+
return element.hidden && element.hasAttribute("data-primitives-part");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Makes everything outside `keep` inert (spec/dialog.md, "Focus"): each sibling of each ancestor
|
|
43
|
+
* of the kept elements, up to `body`. Elements added later (a child layer's portal) are not
|
|
44
|
+
* touched, nor a hidden overlay part (`hidden` and `data-primitives-part`: a kept-mounted
|
|
45
|
+
* overlay's portal content, closed): it takes no interaction while hidden, and an overlay opened
|
|
46
|
+
* from the kept elements later shows it again, which an inert would leave unusable. Returns the
|
|
47
|
+
* restore.
|
|
48
|
+
*/
|
|
49
|
+
function inertOutside(keep) {
|
|
50
|
+
const first = keep[0];
|
|
51
|
+
if (first === void 0) return () => {};
|
|
52
|
+
const body = first.ownerDocument.body;
|
|
53
|
+
const marked = [];
|
|
54
|
+
const keepSet = /* @__PURE__ */ new Set();
|
|
55
|
+
for (const element of keep) {
|
|
56
|
+
let node = element;
|
|
57
|
+
while (node !== null && node !== body) {
|
|
58
|
+
keepSet.add(node);
|
|
59
|
+
node = node.parentElement;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const walk = (parent) => {
|
|
63
|
+
for (const child of [...parent.children]) {
|
|
64
|
+
if (!(child instanceof HTMLElement) || child.tagName === "SCRIPT") continue;
|
|
65
|
+
if (keep.includes(child) || isHiddenPart(child)) continue;
|
|
66
|
+
if (keepSet.has(child)) walk(child);
|
|
67
|
+
else if (!child.hasAttribute("inert")) {
|
|
68
|
+
child.setAttribute("inert", "");
|
|
69
|
+
marked.push(child);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
walk(body);
|
|
74
|
+
return () => {
|
|
75
|
+
for (const element of marked) element.removeAttribute("inert");
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export { blockOutsidePointer as n, inertOutside as t };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=inert-DlGToy3q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inert-DlGToy3q.js","names":[],"sources":["../src/inert/block-outside-pointer.ts","../src/inert/inert-outside.ts"],"sourcesContent":["const blocks = new WeakMap<Document, { count: number; restore: () => void }>();\n\n/**\n * Blocks the pointer outside a modal overlay (spec/menu.md, \"Modal\"): the body stops taking\n * pointer events (`pointer-events: none`), so a press outside reaches no element of the page and\n * only dismisses the overlay; the overlay's own elements opt back in with `pointer-events: auto`.\n * Nested blocks are counted. Returns the restore.\n */\nexport function blockOutsidePointer(doc: Document): () => void {\n const existing = blocks.get(doc);\n if (existing !== undefined) {\n existing.count += 1;\n } else {\n const body = doc.body;\n const previous = body.style.pointerEvents;\n body.style.pointerEvents = \"none\";\n blocks.set(doc, {\n count: 1,\n restore: () => {\n body.style.pointerEvents = previous;\n },\n });\n }\n let released = false;\n return () => {\n if (released) {\n return;\n }\n released = true;\n const block = blocks.get(doc);\n if (block === undefined) {\n return;\n }\n block.count -= 1;\n if (block.count === 0) {\n block.restore();\n blocks.delete(doc);\n }\n };\n}\n","/** A closed kept-mounted overlay's portal content. */\nfunction isHiddenPart(element: HTMLElement): boolean {\n return element.hidden && element.hasAttribute(\"data-primitives-part\");\n}\n\n/**\n * Makes everything outside `keep` inert (spec/dialog.md, \"Focus\"): each sibling of each ancestor\n * of the kept elements, up to `body`. Elements added later (a child layer's portal) are not\n * touched, nor a hidden overlay part (`hidden` and `data-primitives-part`: a kept-mounted\n * overlay's portal content, closed): it takes no interaction while hidden, and an overlay opened\n * from the kept elements later shows it again, which an inert would leave unusable. Returns the\n * restore.\n */\nexport function inertOutside(keep: readonly Element[]): () => void {\n const first = keep[0];\n if (first === undefined) {\n return () => {};\n }\n const body = first.ownerDocument.body;\n const marked: HTMLElement[] = [];\n const keepSet = new Set<Element>();\n for (const element of keep) {\n let node: Element | null = element;\n while (node !== null && node !== body) {\n keepSet.add(node);\n node = node.parentElement;\n }\n }\n const walk = (parent: Element) => {\n for (const child of [...parent.children]) {\n if (!(child instanceof HTMLElement) || child.tagName === \"SCRIPT\") {\n continue;\n }\n if (keep.includes(child) || isHiddenPart(child)) {\n continue;\n }\n if (keepSet.has(child)) {\n walk(child);\n } else if (!child.hasAttribute(\"inert\")) {\n child.setAttribute(\"inert\", \"\");\n marked.push(child);\n }\n }\n };\n walk(body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C1C;GAEJ,IAAI,QAAQ,IAAI,KAAK,GACjB,KAAK,KAAK;QACP,IAAI,CAAC,MAAM,aAAa,OAAO,GAAG;IACrC,MAAM,aAAa,SAAS,EAAE;IAC9B,OAAO,KAAK,KAAK;GACrB;EACJ;CACJ;CACA,KAAK,IAAI;CACT,aAAa;EACT,KAAK,MAAM,WAAW,QAClB,QAAQ,gBAAgB,OAAO;CAEvC;AACJ"}
|
package/dist/inert.d.ts
ADDED
package/dist/inert.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as blockOutsidePointer, t as inertOutside } from "./inert-DlGToy3q.js";
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// src/layers/focus-outside.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calls `onFocusOutside` when focus moves to an element outside every element of `elements()`
|
|
4
|
+
* (spec/popover.md: a non-modal overlay closes when focus leaves it). Returns the cleanup.
|
|
5
|
+
*/
|
|
6
|
+
function watchFocusOutside(doc, elements, onFocusOutside) {
|
|
7
|
+
const onFocusIn = (event) => {
|
|
8
|
+
const target = event.target;
|
|
9
|
+
if (!(target instanceof Node)) return;
|
|
10
|
+
if (!elements().some((element) => element?.contains(target) === true)) onFocusOutside(event);
|
|
11
|
+
};
|
|
12
|
+
doc.addEventListener("focusin", onFocusIn);
|
|
13
|
+
return () => doc.removeEventListener("focusin", onFocusIn);
|
|
14
|
+
}
|
|
15
|
+
// src/layers/layer-stack.ts
|
|
16
|
+
const trees = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
function contains(list, target) {
|
|
18
|
+
return list !== void 0 && target instanceof Node && list().some((element) => element?.contains(target) === true);
|
|
19
|
+
}
|
|
20
|
+
function depth(node) {
|
|
21
|
+
let count = 0;
|
|
22
|
+
for (let at = node.parent; at !== null; at = at.parent) count += 1;
|
|
23
|
+
return count;
|
|
24
|
+
}
|
|
25
|
+
function isAncestorOrSelf(candidate, node) {
|
|
26
|
+
for (let at = node; at !== null; at = at.parent) if (at === candidate) return true;
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
/** The deepest layer a press on `target` is inside of (null: outside every layer). */
|
|
30
|
+
function layerOfPress(tree, target) {
|
|
31
|
+
let found = null;
|
|
32
|
+
let foundDepth = -1;
|
|
33
|
+
const consider = (node) => {
|
|
34
|
+
if (node === null) return;
|
|
35
|
+
const nodeDepth = depth(node);
|
|
36
|
+
if (nodeDepth >= foundDepth) {
|
|
37
|
+
found = node;
|
|
38
|
+
foundDepth = nodeDepth;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
for (const node of tree.nodes) if (contains(node.options.elements, target) || contains(node.options.ignore, target)) consider(node);
|
|
42
|
+
else if (contains(node.options.backdrops, target)) consider(node.parent);
|
|
43
|
+
return found;
|
|
44
|
+
}
|
|
45
|
+
function createTree(doc) {
|
|
46
|
+
const tree = {
|
|
47
|
+
nodes: [],
|
|
48
|
+
teardown: () => {}
|
|
49
|
+
};
|
|
50
|
+
const onKeyDown = (event) => {
|
|
51
|
+
if (event.key !== "Escape" || event.defaultPrevented) return;
|
|
52
|
+
const top = tree.nodes.at(-1);
|
|
53
|
+
if (top?.options.onEscape) {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
event.stopPropagation();
|
|
56
|
+
top.options.onEscape(event);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const onPointerDown = (event) => {
|
|
60
|
+
let inside = layerOfPress(tree, event.target);
|
|
61
|
+
const modal = [...tree.nodes].reverse().find((node) => node.options.modal === true);
|
|
62
|
+
if (modal !== void 0 && !isAncestorOrSelf(modal, inside)) inside = modal.parent;
|
|
63
|
+
for (const node of [...tree.nodes].reverse()) if (!isAncestorOrSelf(node, inside)) node.options.onOutsidePress?.(event);
|
|
64
|
+
};
|
|
65
|
+
doc.addEventListener("keydown", onKeyDown, true);
|
|
66
|
+
doc.addEventListener("pointerdown", onPointerDown, true);
|
|
67
|
+
tree.teardown = () => {
|
|
68
|
+
doc.removeEventListener("keydown", onKeyDown, true);
|
|
69
|
+
doc.removeEventListener("pointerdown", onPointerDown, true);
|
|
70
|
+
};
|
|
71
|
+
return tree;
|
|
72
|
+
}
|
|
73
|
+
/** The newest open layer that contains one of `elements`. */
|
|
74
|
+
function newestContaining(tree, elements) {
|
|
75
|
+
for (const node of [...tree.nodes].reverse()) {
|
|
76
|
+
const own = node.options.elements();
|
|
77
|
+
if (elements.some((element) => element != null && own.some((part) => part?.contains(element) === true))) return node;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
function descendants(tree, node) {
|
|
82
|
+
return tree.nodes.filter((candidate) => candidate !== node && isAncestorOrSelf(node, candidate.parent));
|
|
83
|
+
}
|
|
84
|
+
/** Pushes a layer on its document's tree; `remove` takes it out (in any order). */
|
|
85
|
+
function pushLayer(doc, options) {
|
|
86
|
+
let tree = trees.get(doc);
|
|
87
|
+
if (tree === void 0) {
|
|
88
|
+
tree = createTree(doc);
|
|
89
|
+
trees.set(doc, tree);
|
|
90
|
+
}
|
|
91
|
+
const current = tree;
|
|
92
|
+
const node = {
|
|
93
|
+
options,
|
|
94
|
+
parent: newestContaining(current, options.owner?.() ?? []) ?? newestContaining(current, [doc.activeElement])
|
|
95
|
+
};
|
|
96
|
+
current.nodes.push(node);
|
|
97
|
+
let removed = false;
|
|
98
|
+
return {
|
|
99
|
+
isTop: () => current.nodes.at(-1) === node,
|
|
100
|
+
elementsAbove: () => descendants(current, node).flatMap((child) => child.options.elements()).filter((element) => element != null),
|
|
101
|
+
remove: () => {
|
|
102
|
+
if (removed) return;
|
|
103
|
+
removed = true;
|
|
104
|
+
const below = descendants(current, node);
|
|
105
|
+
const index = current.nodes.indexOf(node);
|
|
106
|
+
if (index !== -1) current.nodes.splice(index, 1);
|
|
107
|
+
for (const child of current.nodes) if (child.parent === node) child.parent = node.parent;
|
|
108
|
+
if (current.nodes.length === 0) {
|
|
109
|
+
current.teardown();
|
|
110
|
+
trees.delete(doc);
|
|
111
|
+
}
|
|
112
|
+
for (const child of below.reverse()) if (current.nodes.includes(child)) child.options.onParentClose?.();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export { watchFocusOutside as n, pushLayer as t };
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=layer-stack-BEtzaFC1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer-stack-BEtzaFC1.js","names":[],"sources":["../src/layers/focus-outside.ts","../src/layers/layer-stack.ts"],"sourcesContent":["/**\n * Calls `onFocusOutside` when focus moves to an element outside every element of `elements()`\n * (spec/popover.md: a non-modal overlay closes when focus leaves it). Returns the cleanup.\n */\nexport function watchFocusOutside(\n doc: Document,\n elements: () => readonly (Element | null | undefined)[],\n onFocusOutside: (event: FocusEvent) => void,\n): () => void {\n const onFocusIn = (event: FocusEvent) => {\n const target = event.target;\n if (!(target instanceof Node)) {\n return;\n }\n if (!elements().some((element) => element?.contains(target) === true)) {\n onFocusOutside(event);\n }\n };\n doc.addEventListener(\"focusin\", onFocusIn);\n return () => doc.removeEventListener(\"focusin\", onFocusIn);\n}\n","/**\n * The tree of open overlays of a document (spec/README.md, \"The nested overlay tree\"). A layer's\n * parent is decided when it is pushed: the newest open layer that contains one of its owner\n * elements (the triggers it was opened from), else the newest that contains the focused element,\n * else none. So a trigger inside a portaled popup makes its overlay a child of that popup's\n * overlay, wherever the child's own portal sits in the DOM.\n *\n * - Escape closes the newest layer (with an `onEscape`) only;\n * - an outside press keeps the deepest layer that contains the press (its elements, or its\n * `ignore` list: a press on an overlay's own trigger toggles it itself) and its ancestors, and\n * dismisses every other open layer, newest first; a press outside every layer dismisses all;\n * - but while a `modal` layer is open (a dialog, which makes the page inert), a press outside the\n * newest modal layer and its descendants lands in that layer's parent: the layers it was opened\n * from stay open, the modal layer and the other layers above them are dismissed;\n * - removing a layer re-parents its children to its parent, and tells each descendant still open\n * that an ancestor closed (`onParentClose`), newest first.\n */\ntype Elements = () => readonly (Element | null | undefined)[];\n\nexport interface LayerOptions {\n /** The elements that make up the layer (its popup, positioner). */\n elements: Elements;\n /** Elements a press on does not dismiss the layer (its trigger, which toggles it itself). */\n ignore?: Elements;\n /**\n * Elements that cover the page under the layer (a dialog's backdrop and viewport): a press on\n * one is outside this layer, but inside its parent.\n */\n backdrops?: Elements;\n /** The elements the overlay was opened from (its triggers), which decide its parent. */\n owner?: Elements;\n /**\n * A modal layer (a dialog: the page under it is inert, so a press outside it reaches no\n * layer): while it is the newest modal layer open, a press outside it and its descendants\n * counts as a press inside its parent, which keeps the layers it was opened from.\n */\n modal?: boolean;\n onEscape?: (event: KeyboardEvent) => void;\n onOutsidePress?: (event: PointerEvent) => void;\n /** An ancestor layer was removed while this one is still open. */\n onParentClose?: () => void;\n}\n\nexport interface Layer {\n /** Whether the layer is the newest open layer of its document. */\n isTop: () => boolean;\n /** The elements of the layer's descendants (its child layers, recursively). */\n elementsAbove: () => Element[];\n remove: () => void;\n}\n\ninterface LayerNode {\n options: LayerOptions;\n parent: LayerNode | null;\n}\n\ninterface Tree {\n /** Every open layer, oldest first. */\n nodes: LayerNode[];\n teardown: () => void;\n}\n\nconst trees = new WeakMap<Document, Tree>();\n\nfunction contains(list: Elements | undefined, target: unknown): boolean {\n return (\n list !== undefined &&\n target instanceof Node &&\n list().some((element) => element?.contains(target) === true)\n );\n}\n\nfunction depth(node: LayerNode): number {\n let count = 0;\n for (let at = node.parent; at !== null; at = at.parent) {\n count += 1;\n }\n return count;\n}\n\nfunction isAncestorOrSelf(\n candidate: LayerNode,\n node: LayerNode | null,\n): boolean {\n for (let at = node; at !== null; at = at.parent) {\n if (at === candidate) {\n return true;\n }\n }\n return false;\n}\n\n/** The deepest layer a press on `target` is inside of (null: outside every layer). */\nfunction layerOfPress(\n tree: Tree,\n target: EventTarget | null,\n): LayerNode | null {\n let found: LayerNode | null = null;\n let foundDepth = -1;\n const consider = (node: LayerNode | null) => {\n if (node === null) {\n return;\n }\n const nodeDepth = depth(node);\n // the newest wins a tie: the nodes are walked oldest first\n if (nodeDepth >= foundDepth) {\n found = node;\n foundDepth = nodeDepth;\n }\n };\n for (const node of tree.nodes) {\n if (\n contains(node.options.elements, target) ||\n contains(node.options.ignore, target)\n ) {\n consider(node);\n } else if (contains(node.options.backdrops, target)) {\n // a press on a layer's backdrop is outside it, inside its parent\n consider(node.parent);\n }\n }\n return found;\n}\n\nfunction createTree(doc: Document): Tree {\n const tree: Tree = { nodes: [], teardown: () => {} };\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key !== \"Escape\" || event.defaultPrevented) {\n return;\n }\n const top = tree.nodes.at(-1);\n if (top?.options.onEscape) {\n event.preventDefault();\n event.stopPropagation();\n top.options.onEscape(event);\n }\n };\n const onPointerDown = (event: PointerEvent) => {\n let inside = layerOfPress(tree, event.target);\n const modal = [...tree.nodes]\n .reverse()\n .find((node) => node.options.modal === true);\n if (modal !== undefined && !isAncestorOrSelf(modal, inside)) {\n inside = modal.parent;\n }\n for (const node of [...tree.nodes].reverse()) {\n if (!isAncestorOrSelf(node, inside)) {\n node.options.onOutsidePress?.(event);\n }\n }\n };\n doc.addEventListener(\"keydown\", onKeyDown, true);\n doc.addEventListener(\"pointerdown\", onPointerDown, true);\n tree.teardown = () => {\n doc.removeEventListener(\"keydown\", onKeyDown, true);\n doc.removeEventListener(\"pointerdown\", onPointerDown, true);\n };\n return tree;\n}\n\n/** The newest open layer that contains one of `elements`. */\nfunction newestContaining(\n tree: Tree,\n elements: readonly (Element | null | undefined)[],\n): LayerNode | null {\n for (const node of [...tree.nodes].reverse()) {\n const own = node.options.elements();\n if (\n elements.some(\n (element) =>\n element != null &&\n own.some((part) => part?.contains(element) === true),\n )\n ) {\n return node;\n }\n }\n return null;\n}\n\nfunction descendants(tree: Tree, node: LayerNode): LayerNode[] {\n return tree.nodes.filter(\n (candidate) =>\n candidate !== node && isAncestorOrSelf(node, candidate.parent),\n );\n}\n\n/** Pushes a layer on its document's tree; `remove` takes it out (in any order). */\nexport function pushLayer(doc: Document, options: LayerOptions): Layer {\n let tree = trees.get(doc);\n if (tree === undefined) {\n tree = createTree(doc);\n trees.set(doc, tree);\n }\n const current = tree;\n const parent =\n newestContaining(current, options.owner?.() ?? []) ??\n newestContaining(current, [doc.activeElement]);\n const node: LayerNode = { options, parent };\n current.nodes.push(node);\n let removed = false;\n return {\n isTop: () => current.nodes.at(-1) === node,\n elementsAbove: () =>\n descendants(current, node)\n .flatMap((child) => child.options.elements())\n .filter((element): element is Element => element != null),\n remove: () => {\n if (removed) {\n return;\n }\n removed = true;\n const below = descendants(current, node);\n const index = current.nodes.indexOf(node);\n if (index !== -1) {\n current.nodes.splice(index, 1);\n }\n for (const child of current.nodes) {\n if (child.parent === node) {\n child.parent = node.parent;\n }\n }\n if (current.nodes.length === 0) {\n current.teardown();\n trees.delete(doc);\n }\n // closing an overlay closes the overlays opened from it, newest first\n for (const child of below.reverse()) {\n if (current.nodes.includes(child)) {\n child.options.onParentClose?.();\n }\n }\n },\n };\n}\n"],"mappings":";;;;;AAIA,SAAgB,kBACZ,KACA,UACA,gBACU;CACV,MAAM,aAAa,UAAsB;EACrC,MAAM,SAAS,MAAM;EACrB,IAAI,EAAE,kBAAkB,OACpB;EAEJ,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,YAAY,SAAS,SAAS,MAAM,MAAM,IAAI,GAChE,eAAe,KAAK;CAE5B;CACA,IAAI,iBAAiB,WAAW,SAAS;CACzC,aAAa,IAAI,oBAAoB,WAAW,SAAS;AAC7D;;AC0CA,MAAM,wBAAQ,IAAI,QAAwB;AAE1C,SAAS,SAAS,MAA4B,QAA0B;CACpE,OACI,SAAS,KAAA,KACT,kBAAkB,QAClB,KAAK,CAAC,CAAC,MAAM,YAAY,SAAS,SAAS,MAAM,MAAM,IAAI;AAEnE;AAEA,SAAS,MAAM,MAAyB;CACpC,IAAI,QAAQ;CACZ,KAAK,IAAI,KAAK,KAAK,QAAQ,OAAO,MAAM,KAAK,GAAG,QAC5C,SAAS;CAEb,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,YAAY,SAAS,IAAI;GACvC,MAAM,QAAQ,QAAQ,MAAM,QAAQ,IAAI;GACxC,IAAI,UAAU,IACV,QAAQ,MAAM,OAAO,OAAO,CAAC;GAEjC,KAAK,MAAM,SAAS,QAAQ,OACxB,IAAI,MAAM,WAAW,MACjB,MAAM,SAAS,KAAK;GAG5B,IAAI,QAAQ,MAAM,WAAW,GAAG;IAC5B,QAAQ,SAAS;IACjB,MAAM,OAAO,GAAG;GACpB;GAEA,KAAK,MAAM,SAAS,MAAM,QAAQ,GAC9B,IAAI,QAAQ,MAAM,SAAS,KAAK,GAC5B,MAAM,QAAQ,gBAAgB;EAG1C;CACJ;AACJ"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/layers/intercept-escape.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calls `onEscape` on Escape before the document's overlay layers see the key, and consumes it
|
|
4
|
+
* (spec/tooltip.md: "Escape closes it and stops there"). It listens in the capture phase of the
|
|
5
|
+
* document's window, which runs before the layer stack's listener on the document; the key is
|
|
6
|
+
* then prevented and stopped, and the stack ignores a prevented key, so an enclosing dialog,
|
|
7
|
+
* popover or menu stays open. `when` limits it to some keys (a RangeCalendar takes only the
|
|
8
|
+
* Escape pressed inside its grid, spec/calendar.md); the others go on to the layers. Returns the
|
|
9
|
+
* cleanup.
|
|
10
|
+
*/
|
|
11
|
+
function interceptEscape(doc, onEscape, options = {}) {
|
|
12
|
+
const target = doc.defaultView ?? doc;
|
|
13
|
+
const onKeyDown = (event) => {
|
|
14
|
+
if (!(event instanceof KeyboardEvent) || event.key !== "Escape" || event.defaultPrevented || options.when !== void 0 && !options.when(event)) return;
|
|
15
|
+
event.preventDefault();
|
|
16
|
+
event.stopPropagation();
|
|
17
|
+
onEscape(event);
|
|
18
|
+
};
|
|
19
|
+
target.addEventListener("keydown", onKeyDown, true);
|
|
20
|
+
return () => target.removeEventListener("keydown", onKeyDown, true);
|
|
21
|
+
}
|
|
22
|
+
export { interceptEscape as t };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=layers-C-N4rrZX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layers-C-N4rrZX.js","names":[],"sources":["../src/layers/intercept-escape.ts"],"sourcesContent":["/**\n * Calls `onEscape` on Escape before the document's overlay layers see the key, and consumes it\n * (spec/tooltip.md: \"Escape closes it and stops there\"). It listens in the capture phase of the\n * document's window, which runs before the layer stack's listener on the document; the key is\n * then prevented and stopped, and the stack ignores a prevented key, so an enclosing dialog,\n * popover or menu stays open. `when` limits it to some keys (a RangeCalendar takes only the\n * Escape pressed inside its grid, spec/calendar.md); the others go on to the layers. Returns the\n * cleanup.\n */\nexport function interceptEscape(\n doc: Document,\n onEscape: (event: KeyboardEvent) => void,\n options: { when?: (event: KeyboardEvent) => boolean } = {},\n): () => void {\n const target: Document | Window = doc.defaultView ?? doc;\n const onKeyDown = (event: Event) => {\n if (\n !(event instanceof KeyboardEvent) ||\n event.key !== \"Escape\" ||\n event.defaultPrevented ||\n (options.when !== undefined && !options.when(event))\n ) {\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n onEscape(event);\n };\n target.addEventListener(\"keydown\", onKeyDown, true);\n return () => target.removeEventListener(\"keydown\", onKeyDown, true);\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,gBACZ,KACA,UACA,UAAwD,CAAC,GAC/C;CACV,MAAM,SAA4B,IAAI,eAAe;CACrD,MAAM,aAAa,UAAiB;EAChC,IACI,EAAE,iBAAiB,kBACnB,MAAM,QAAQ,YACd,MAAM,oBACL,QAAQ,SAAS,KAAA,KAAa,CAAC,QAAQ,KAAK,KAAK,GAElD;EAEJ,MAAM,eAAe;EACrB,MAAM,gBAAgB;EACtB,SAAS,KAAK;CAClB;CACA,OAAO,iBAAiB,WAAW,WAAW,IAAI;CAClD,aAAa,OAAO,oBAAoB,WAAW,WAAW,IAAI;AACtE"}
|
package/dist/layers.d.ts
ADDED
package/dist/layers.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/collection/list-navigation.ts
|
|
2
|
+
/**
|
|
3
|
+
* The index `delta` steps from `current` in a list of `count` items (spec: menus, tabs). From no
|
|
4
|
+
* item (`current` -1), +1 goes to the first and -1 to the last. Returns `current` when there is
|
|
5
|
+
* nowhere to go.
|
|
6
|
+
*/
|
|
7
|
+
function stepIndex(count, current, delta, options = {}) {
|
|
8
|
+
const { loop = true, skip = () => false } = options;
|
|
9
|
+
if (count === 0) return -1;
|
|
10
|
+
let index = current;
|
|
11
|
+
for (let tries = 0; tries < count; tries++) {
|
|
12
|
+
if (index === -1) index = delta === 1 ? 0 : count - 1;
|
|
13
|
+
else {
|
|
14
|
+
index += delta;
|
|
15
|
+
if (index < 0 || index >= count) {
|
|
16
|
+
if (!loop) return current;
|
|
17
|
+
index = (index + count) % count;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!skip(index)) return index;
|
|
21
|
+
}
|
|
22
|
+
return current;
|
|
23
|
+
}
|
|
24
|
+
/** The first (or last) index not skipped, or -1. */
|
|
25
|
+
function edgeIndex(count, edge, skip = () => false) {
|
|
26
|
+
return Array.from({ length: count }, (_, index) => edge === "first" ? index : count - 1 - index).find((index) => !skip(index)) ?? -1;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A step through a list where "no item" sits between the ends (spec/combobox.md): from the last
|
|
30
|
+
* item +1 gives -1 (back to the input), from -1 it gives the first item; -1 mirrors it.
|
|
31
|
+
*/
|
|
32
|
+
function stepThroughNone(count, current, delta) {
|
|
33
|
+
if (count === 0) return -1;
|
|
34
|
+
if (current === -1) return delta === 1 ? 0 : count - 1;
|
|
35
|
+
const next = current + delta;
|
|
36
|
+
return next < 0 || next >= count ? -1 : next;
|
|
37
|
+
}
|
|
38
|
+
export { stepIndex as n, stepThroughNone as r, edgeIndex as t };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=list-navigation-CbWv4DK5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-navigation-CbWv4DK5.js","names":[],"sources":["../src/collection/list-navigation.ts"],"sourcesContent":["export interface NavigationOptions {\n /** Wrap from the last item to the first, and back (default `true`). */\n loop?: boolean;\n /** Items the navigation passes over (default: none). */\n skip?: (index: number) => boolean;\n}\n\n/**\n * The index `delta` steps from `current` in a list of `count` items (spec: menus, tabs). From no\n * item (`current` -1), +1 goes to the first and -1 to the last. Returns `current` when there is\n * nowhere to go.\n */\nexport function stepIndex(\n count: number,\n current: number,\n delta: 1 | -1,\n options: NavigationOptions = {},\n): number {\n const { loop = true, skip = () => false } = options;\n if (count === 0) {\n return -1;\n }\n let index = current;\n for (let tries = 0; tries < count; tries++) {\n if (index === -1) {\n index = delta === 1 ? 0 : count - 1;\n } else {\n index += delta;\n if (index < 0 || index >= count) {\n if (!loop) {\n return current;\n }\n index = (index + count) % count;\n }\n }\n if (!skip(index)) {\n return index;\n }\n }\n return current;\n}\n\n/** The first (or last) index not skipped, or -1. */\nexport function edgeIndex(\n count: number,\n edge: \"first\" | \"last\",\n skip: (index: number) => boolean = () => false,\n): number {\n const order = Array.from({ length: count }, (_, index) =>\n edge === \"first\" ? index : count - 1 - index,\n );\n return order.find((index) => !skip(index)) ?? -1;\n}\n\n/**\n * A step through a list where \"no item\" sits between the ends (spec/combobox.md): from the last\n * item +1 gives -1 (back to the input), from -1 it gives the first item; -1 mirrors it.\n */\nexport function stepThroughNone(\n count: number,\n current: number,\n delta: 1 | -1,\n): number {\n if (count === 0) {\n return -1;\n }\n if (current === -1) {\n return delta === 1 ? 0 : count - 1;\n }\n const next = current + delta;\n return next < 0 || next >= count ? -1 : next;\n}\n"],"mappings":";;;;;;AAYA,SAAgB,UACZ,OACA,SACA,OACA,UAA6B,CAAC,GACxB;CACN,MAAM,EAAE,OAAO,MAAM,aAAa,UAAU;CAC5C,IAAI,UAAU,GACV,OAAO;CAEX,IAAI,QAAQ;CACZ,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,SAAS;EACxC,IAAI,UAAU,IACV,QAAQ,UAAU,IAAI,IAAI,QAAQ;OAC/B;GACH,SAAS;GACT,IAAI,QAAQ,KAAK,SAAS,OAAO;IAC7B,IAAI,CAAC,MACD,OAAO;IAEX,SAAS,QAAQ,SAAS;GAC9B;EACJ;EACA,IAAI,CAAC,KAAK,KAAK,GACX,OAAO;CAEf;CACA,OAAO;AACX;;AAGA,SAAgB,UACZ,OACA,MACA,aAAyC,OACnC;CAIN,OAHc,MAAM,KAAK,EAAE,QAAQ,MAAM,IAAI,GAAG,UAC5C,SAAS,UAAU,QAAQ,QAAQ,IAAI,KAEhC,CAAC,CAAC,MAAM,UAAU,CAAC,KAAK,KAAK,CAAC,KAAK;AAClD;;;;;AAMA,SAAgB,gBACZ,OACA,SACA,OACM;CACN,IAAI,UAAU,GACV,OAAO;CAEX,IAAI,YAAY,IACZ,OAAO,UAAU,IAAI,IAAI,QAAQ;CAErC,MAAM,OAAO,UAAU;CACvB,OAAO,OAAO,KAAK,QAAQ,QAAQ,KAAK;AAC5C"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// src/month-year/plain-year-month.ts
|
|
2
|
+
/**
|
|
3
|
+
* A month as one number (`year * 12 + month - 1`), so the month grid moves by adding: the next
|
|
4
|
+
* month is `+ 1`, the same month of the next year `+ 12`. A year's index is the year itself.
|
|
5
|
+
*/
|
|
6
|
+
function monthIndex(month) {
|
|
7
|
+
return month.year * 12 + month.month - 1;
|
|
8
|
+
}
|
|
9
|
+
/** The month of a {@link monthIndex}. */
|
|
10
|
+
function fromMonthIndex(index) {
|
|
11
|
+
const year = Math.floor(index / 12);
|
|
12
|
+
return {
|
|
13
|
+
year,
|
|
14
|
+
month: index - year * 12 + 1
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** The local month of `now` (the clock the page sees). */
|
|
18
|
+
function currentYearMonth(now = /* @__PURE__ */ new Date()) {
|
|
19
|
+
return {
|
|
20
|
+
year: now.getFullYear(),
|
|
21
|
+
month: now.getMonth() + 1
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const pad = (value, size) => String(Math.abs(value)).padStart(size, "0");
|
|
25
|
+
/** `2026-11` (ISO 8601, as `<input type="month">`). */
|
|
26
|
+
function toIsoYearMonth(month) {
|
|
27
|
+
return `${month.year < 0 ? "-" : ""}${pad(month.year, 4)}-${pad(month.month, 2)}`;
|
|
28
|
+
}
|
|
29
|
+
/** `2026` (ISO 8601's year: 4 digits). */
|
|
30
|
+
function toIsoYear(year) {
|
|
31
|
+
return `${year.year < 0 ? "-" : ""}${pad(year.year, 4)}`;
|
|
32
|
+
}
|
|
33
|
+
// src/month-year/unit-grid.ts
|
|
34
|
+
/**
|
|
35
|
+
* The grid of a month or year calendar (spec/month-calendar.md): a page of 12 items (the months
|
|
36
|
+
* of a year, or 12 years starting at a multiple of 12), in rows of `columns`. Items are numbers:
|
|
37
|
+
* a month's `monthIndex`, or the year.
|
|
38
|
+
*/
|
|
39
|
+
const UNIT_PAGE_SIZE = 12;
|
|
40
|
+
/** The first item of the page holding `index` (January of its year; 2016 for 2026). */
|
|
41
|
+
function unitPageStart(index) {
|
|
42
|
+
return Math.floor(index / 12) * 12;
|
|
43
|
+
}
|
|
44
|
+
/** The page starting at `start`, in rows of `columns` items. */
|
|
45
|
+
function unitRows(start, columns) {
|
|
46
|
+
const size = Math.max(1, Math.floor(columns));
|
|
47
|
+
const rows = [];
|
|
48
|
+
for (let offset = 0; offset < 12; offset += size) rows.push(Array.from({ length: Math.min(size, 12 - offset) }, (_, column) => start + offset + column));
|
|
49
|
+
return rows;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The item a key moves the focused item to in a month or year grid (spec/month-calendar.md,
|
|
53
|
+
* "Keyboard": the Calendar's keys mapped to the grid), or `null` when the key does not move it.
|
|
54
|
+
*/
|
|
55
|
+
function unitKeyTarget(key, focused, { rtl, columns }) {
|
|
56
|
+
const size = Math.max(1, Math.floor(columns));
|
|
57
|
+
const page = unitPageStart(focused);
|
|
58
|
+
const rowStart = page + Math.floor((focused - page) / size) * size;
|
|
59
|
+
switch (key) {
|
|
60
|
+
case "ArrowRight": return focused + (rtl ? -1 : 1);
|
|
61
|
+
case "ArrowLeft": return focused + (rtl ? 1 : -1);
|
|
62
|
+
case "ArrowDown": return focused + size;
|
|
63
|
+
case "ArrowUp": return focused - size;
|
|
64
|
+
case "Home": return rowStart;
|
|
65
|
+
case "End": return Math.min(rowStart + size, page + 12) - 1;
|
|
66
|
+
case "PageDown": return focused + 12;
|
|
67
|
+
case "PageUp": return focused - 12;
|
|
68
|
+
default: return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// src/month-year/unit-locale-data.ts
|
|
72
|
+
function utcDate(year, month) {
|
|
73
|
+
const date = new Date(Date.UTC(2e3, month - 1, 1));
|
|
74
|
+
date.setUTCFullYear(year);
|
|
75
|
+
return date;
|
|
76
|
+
}
|
|
77
|
+
function format(locale, options) {
|
|
78
|
+
return new Intl.DateTimeFormat(locale, {
|
|
79
|
+
...options,
|
|
80
|
+
timeZone: "UTC"
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** "Nov" (`Intl` `month: "short"`), or "November" with `"long"`. */
|
|
84
|
+
function formatMonthName(locale, month, width = "short") {
|
|
85
|
+
return format(locale, { month: width }).format(utcDate(month.year, month.month));
|
|
86
|
+
}
|
|
87
|
+
/** "November 2026" (`Intl` `month: "long", year: "numeric"`). */
|
|
88
|
+
function formatYearMonth(locale, month) {
|
|
89
|
+
return format(locale, {
|
|
90
|
+
month: "long",
|
|
91
|
+
year: "numeric"
|
|
92
|
+
}).format(utcDate(month.year, month.month));
|
|
93
|
+
}
|
|
94
|
+
/** "2026" (`Intl` `year: "numeric"`). */
|
|
95
|
+
function formatYear(locale, year) {
|
|
96
|
+
return format(locale, { year: "numeric" }).format(utcDate(year, 1));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* "2016 – 2027" (`Intl.DateTimeFormat#formatRange` of two years), every space written as U+0020:
|
|
100
|
+
* engines differ on the spaces around the dash (Node's ICU and Chromium's), and a server's text
|
|
101
|
+
* must be the hydrating browser's (the date fields' literals, Epic #73).
|
|
102
|
+
*/
|
|
103
|
+
function formatYearSpan(locale, first, last) {
|
|
104
|
+
return format(locale, { year: "numeric" }).formatRange(utcDate(first, 1), utcDate(last, 1)).replace(/[\u00a0\u2009\u202f]/g, " ");
|
|
105
|
+
}
|
|
106
|
+
export { UNIT_PAGE_SIZE as a, unitRows as c, monthIndex as d, toIsoYear as f, formatYearSpan as i, currentYearMonth as l, formatYear as n, unitKeyTarget as o, toIsoYearMonth as p, formatYearMonth as r, unitPageStart as s, formatMonthName as t, fromMonthIndex as u };
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=month-year-BG5imFUq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"month-year-BG5imFUq.js","names":[],"sources":["../src/month-year/plain-year-month.ts","../src/month-year/unit-grid.ts","../src/month-year/unit-locale-data.ts"],"sourcesContent":["/**\n * A month with no day, no time and no time zone (spec/month-calendar.md, \"Values\"), Temporal's\n * `PlainYearMonth` shape. `month` is 1–12.\n */\nexport interface PlainYearMonth {\n readonly year: number;\n readonly month: number;\n}\n\n/** A year with no month (an object, so a calendar system can extend it). */\nexport interface PlainYear {\n readonly year: number;\n}\n\n/** A range of months, `start <= end`. */\nexport interface YearMonthRange {\n readonly start: PlainYearMonth;\n readonly end: PlainYearMonth;\n}\n\n/** A range of years, `start <= end`. */\nexport interface YearRange {\n readonly start: PlainYear;\n readonly end: PlainYear;\n}\n\n/**\n * A month as one number (`year * 12 + month - 1`), so the month grid moves by adding: the next\n * month is `+ 1`, the same month of the next year `+ 12`. A year's index is the year itself.\n */\nexport function monthIndex(month: PlainYearMonth): number {\n return month.year * 12 + month.month - 1;\n}\n\n/** The month of a {@link monthIndex}. */\nexport function fromMonthIndex(index: number): PlainYearMonth {\n const year = Math.floor(index / 12);\n return { year, month: index - year * 12 + 1 };\n}\n\n/** The local month of `now` (the clock the page sees). */\nexport function currentYearMonth(now: Date = new Date()): PlainYearMonth {\n return { year: now.getFullYear(), month: now.getMonth() + 1 };\n}\n\nconst pad = (value: number, size: number) =>\n String(Math.abs(value)).padStart(size, \"0\");\n\n/** `2026-11` (ISO 8601, as `<input type=\"month\">`). */\nexport function toIsoYearMonth(month: PlainYearMonth): string {\n return `${month.year < 0 ? \"-\" : \"\"}${pad(month.year, 4)}-${pad(month.month, 2)}`;\n}\n\n/** `2026` (ISO 8601's year: 4 digits). */\nexport function toIsoYear(year: PlainYear): string {\n return `${year.year < 0 ? \"-\" : \"\"}${pad(year.year, 4)}`;\n}\n","/**\n * The grid of a month or year calendar (spec/month-calendar.md): a page of 12 items (the months\n * of a year, or 12 years starting at a multiple of 12), in rows of `columns`. Items are numbers:\n * a month's `monthIndex`, or the year.\n */\nexport const UNIT_PAGE_SIZE = 12;\n\n/** The first item of the page holding `index` (January of its year; 2016 for 2026). */\nexport function unitPageStart(index: number): number {\n return Math.floor(index / UNIT_PAGE_SIZE) * UNIT_PAGE_SIZE;\n}\n\n/** The page starting at `start`, in rows of `columns` items. */\nexport function unitRows(start: number, columns: number): number[][] {\n const size = Math.max(1, Math.floor(columns));\n const rows: number[][] = [];\n for (let offset = 0; offset < UNIT_PAGE_SIZE; offset += size) {\n rows.push(\n Array.from(\n { length: Math.min(size, UNIT_PAGE_SIZE - offset) },\n (_, column) => start + offset + column,\n ),\n );\n }\n return rows;\n}\n\nexport interface UnitKeyOptions {\n rtl: boolean;\n /** Items per row. */\n columns: number;\n}\n\n/**\n * The item a key moves the focused item to in a month or year grid (spec/month-calendar.md,\n * \"Keyboard\": the Calendar's keys mapped to the grid), or `null` when the key does not move it.\n */\nexport function unitKeyTarget(\n key: string,\n focused: number,\n { rtl, columns }: UnitKeyOptions,\n): number | null {\n const size = Math.max(1, Math.floor(columns));\n const page = unitPageStart(focused);\n const rowStart = page + Math.floor((focused - page) / size) * size;\n switch (key) {\n case \"ArrowRight\":\n return focused + (rtl ? -1 : 1);\n case \"ArrowLeft\":\n return focused + (rtl ? 1 : -1);\n case \"ArrowDown\":\n return focused + size;\n case \"ArrowUp\":\n return focused - size;\n case \"Home\":\n return rowStart;\n case \"End\":\n return Math.min(rowStart + size, page + UNIT_PAGE_SIZE) - 1;\n case \"PageDown\":\n return focused + UNIT_PAGE_SIZE;\n case \"PageUp\":\n return focused - UNIT_PAGE_SIZE;\n default:\n return null;\n }\n}\n","import type { PlainYearMonth } from \"./plain-year-month.ts\";\n\n// Formatted from UTC dates with `timeZone: \"UTC\"`, so no host time zone moves a month\n// (the `/time` entry's way).\nfunction utcDate(year: number, month: number): Date {\n const date = new Date(Date.UTC(2000, month - 1, 1));\n date.setUTCFullYear(year);\n return date;\n}\n\nfunction format(\n locale: string,\n options: Intl.DateTimeFormatOptions,\n): Intl.DateTimeFormat {\n return new Intl.DateTimeFormat(locale, { ...options, timeZone: \"UTC\" });\n}\n\n/** \"Nov\" (`Intl` `month: \"short\"`), or \"November\" with `\"long\"`. */\nexport function formatMonthName(\n locale: string,\n month: PlainYearMonth,\n width: \"short\" | \"long\" = \"short\",\n): string {\n return format(locale, { month: width }).format(\n utcDate(month.year, month.month),\n );\n}\n\n/** \"November 2026\" (`Intl` `month: \"long\", year: \"numeric\"`). */\nexport function formatYearMonth(locale: string, month: PlainYearMonth): string {\n return format(locale, { month: \"long\", year: \"numeric\" }).format(\n utcDate(month.year, month.month),\n );\n}\n\n/** \"2026\" (`Intl` `year: \"numeric\"`). */\nexport function formatYear(locale: string, year: number): string {\n return format(locale, { year: \"numeric\" }).format(utcDate(year, 1));\n}\n\n/**\n * \"2016 – 2027\" (`Intl.DateTimeFormat#formatRange` of two years), every space written as U+0020:\n * engines differ on the spaces around the dash (Node's ICU and Chromium's), and a server's text\n * must be the hydrating browser's (the date fields' literals, Epic #73).\n */\nexport function formatYearSpan(\n locale: string,\n first: number,\n last: number,\n): string {\n return format(locale, {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,eACZ,QACA,OACA,MACM;CACN,OAAO,OAAO,QAAQ,EAAE,MAAM,UAAU,CAAC,CAAC,CACrC,YAAY,QAAQ,OAAO,CAAC,GAAG,QAAQ,MAAM,CAAC,CAAC,CAAC,CAChD,QAAQ,yBAAyB,GAAG;AAC7C"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as unitRows, i as unitPageStart, n as UnitKeyOptions, r as unitKeyTarget, t as UNIT_PAGE_SIZE } from "./unit-grid-DJy8lb5D.js";
|
|
2
|
+
import { a as PlainYear, c as YearRange, d as monthIndex, f as toIsoYear, i as formatYearSpan, l as currentYearMonth, n as formatYear, o as PlainYearMonth, p as toIsoYearMonth, r as formatYearMonth, s as YearMonthRange, t as formatMonthName, u as fromMonthIndex } from "./index-BapNrjY9.js";
|
|
3
|
+
export { type PlainYear, type PlainYearMonth, UNIT_PAGE_SIZE, type UnitKeyOptions, type YearMonthRange, type YearRange, currentYearMonth, formatMonthName, formatYear, formatYearMonth, formatYearSpan, fromMonthIndex, monthIndex, toIsoYear, toIsoYearMonth, unitKeyTarget, unitPageStart, unitRows };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { a as UNIT_PAGE_SIZE, l as currentYearMonth, t as formatMonthName, n as formatYear, r as formatYearMonth, i as formatYearSpan, u as fromMonthIndex, d as monthIndex, f as toIsoYear, p as toIsoYearMonth, o as unitKeyTarget, s as unitPageStart, c as unitRows } from "./month-year-BG5imFUq.js";
|