loseta 0.19.0 → 0.20.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/README.md +84 -20
- package/dist/cli.js +3 -4
- package/dist/cli.js.map +1 -1
- package/dist/command-context.d.ts +20 -0
- package/dist/command-context.js +26 -0
- package/dist/command-context.js.map +1 -0
- package/dist/command-errors.d.ts +2 -0
- package/dist/command-errors.js +42 -0
- package/dist/command-errors.js.map +1 -0
- package/dist/commands/add.d.ts +8 -0
- package/dist/commands/add.js +189 -61
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/init.d.ts +8 -0
- package/dist/commands/init.js +70 -27
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list.d.ts +8 -0
- package/dist/commands/list.js +42 -3
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/style.d.ts +10 -1
- package/dist/commands/style.js +58 -10
- package/dist/commands/style.js.map +1 -1
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +10 -0
- package/dist/constants.js.map +1 -0
- package/dist/fetch.d.ts +28 -0
- package/dist/fetch.js +135 -0
- package/dist/fetch.js.map +1 -0
- package/dist/imports.d.ts +6 -6
- package/dist/imports.js +42 -32
- package/dist/imports.js.map +1 -1
- package/dist/install.d.ts +17 -14
- package/dist/install.js +67 -41
- package/dist/install.js.map +1 -1
- package/dist/local-registry.d.ts +20 -0
- package/dist/local-registry.js +58 -0
- package/dist/local-registry.js.map +1 -0
- package/dist/manifest.d.ts +1 -1
- package/dist/manifest.js +14 -2
- package/dist/manifest.js.map +1 -1
- package/dist/package-info.d.ts +2 -0
- package/dist/package-info.js +5 -0
- package/dist/package-info.js.map +1 -0
- package/dist/payload.d.ts +31 -0
- package/dist/payload.js +155 -0
- package/dist/payload.js.map +1 -0
- package/dist/registry-url.d.ts +14 -0
- package/dist/registry-url.js +63 -0
- package/dist/registry-url.js.map +1 -0
- package/dist/remote-registry.d.ts +36 -0
- package/dist/remote-registry.js +232 -0
- package/dist/remote-registry.js.map +1 -0
- package/dist/resolve.d.ts +23 -0
- package/dist/resolve.js +106 -0
- package/dist/resolve.js.map +1 -0
- package/{registry/schema.json → dist/schema-catalog.json} +31 -9
- package/dist/schema-item.json +119 -0
- package/dist/source-types.d.ts +15 -0
- package/dist/source-types.js +2 -0
- package/dist/source-types.js.map +1 -0
- package/dist/style-switch.d.ts +4 -1
- package/dist/style-switch.js +12 -2
- package/dist/style-switch.js.map +1 -1
- package/dist/types.d.ts +55 -3
- package/dist/validate-content.d.ts +20 -0
- package/dist/validate-content.js +385 -0
- package/dist/validate-content.js.map +1 -0
- package/dist/validation-rules.json +121 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.js +26 -0
- package/dist/version.js.map +1 -0
- package/package.json +4 -4
- package/registry/base.css +0 -20
- package/registry/behaviors/calendar.js +0 -855
- package/registry/behaviors/carousel.js +0 -280
- package/registry/behaviors/code-block.js +0 -106
- package/registry/behaviors/combobox.js +0 -237
- package/registry/behaviors/command.js +0 -105
- package/registry/behaviors/core.js +0 -302
- package/registry/behaviors/dialog.js +0 -97
- package/registry/behaviors/hover-overlay.js +0 -180
- package/registry/behaviors/listbox.js +0 -135
- package/registry/behaviors/menu.js +0 -586
- package/registry/behaviors/message-scroller.js +0 -147
- package/registry/behaviors/popover.js +0 -127
- package/registry/behaviors/questionnaire.js +0 -91
- package/registry/behaviors/resizable.js +0 -463
- package/registry/behaviors/select.js +0 -196
- package/registry/behaviors/tabs.js +0 -95
- package/registry/behaviors/toast.js +0 -137
- package/registry/components/accordion.css +0 -65
- package/registry/components/alert-dialog.css +0 -104
- package/registry/components/alert.css +0 -41
- package/registry/components/aspect-ratio.css +0 -25
- package/registry/components/attachment.css +0 -84
- package/registry/components/avatar.css +0 -63
- package/registry/components/badge.css +0 -22
- package/registry/components/breadcrumb.css +0 -65
- package/registry/components/bubble.css +0 -92
- package/registry/components/button-group.css +0 -98
- package/registry/components/button.css +0 -32
- package/registry/components/calendar.css +0 -96
- package/registry/components/card.css +0 -51
- package/registry/components/carousel.css +0 -96
- package/registry/components/chart.css +0 -65
- package/registry/components/checkbox.css +0 -39
- package/registry/components/code-block.css +0 -192
- package/registry/components/collapsible.css +0 -57
- package/registry/components/combobox.css +0 -42
- package/registry/components/command.css +0 -27
- package/registry/components/context-menu.css +0 -37
- package/registry/components/dialog.css +0 -87
- package/registry/components/drawer.css +0 -30
- package/registry/components/dropdown-menu.css +0 -14
- package/registry/components/empty.css +0 -66
- package/registry/components/field.css +0 -169
- package/registry/components/hover-card.css +0 -18
- package/registry/components/input-group.css +0 -56
- package/registry/components/input-otp.css +0 -119
- package/registry/components/input.css +0 -31
- package/registry/components/item.css +0 -102
- package/registry/components/kbd.css +0 -19
- package/registry/components/label.css +0 -31
- package/registry/components/marker.css +0 -47
- package/registry/components/menubar.css +0 -52
- package/registry/components/message-scroller.css +0 -56
- package/registry/components/message.css +0 -61
- package/registry/components/native-select.css +0 -27
- package/registry/components/navigation-menu.css +0 -52
- package/registry/components/pagination.css +0 -49
- package/registry/components/popover.css +0 -7
- package/registry/components/progress.css +0 -13
- package/registry/components/questionnaire.css +0 -92
- package/registry/components/radio.css +0 -40
- package/registry/components/resizable.css +0 -100
- package/registry/components/scroll-area.css +0 -16
- package/registry/components/select.css +0 -50
- package/registry/components/separator.css +0 -12
- package/registry/components/sheet.css +0 -31
- package/registry/components/sidebar.css +0 -107
- package/registry/components/skeleton.css +0 -11
- package/registry/components/slider.css +0 -13
- package/registry/components/spinner.css +0 -8
- package/registry/components/switch.css +0 -41
- package/registry/components/table.css +0 -73
- package/registry/components/tabs.css +0 -61
- package/registry/components/textarea.css +0 -25
- package/registry/components/toast.css +0 -47
- package/registry/components/toggle-group.css +0 -25
- package/registry/components/toggle.css +0 -31
- package/registry/components/tooltip.css +0 -437
- package/registry/components/trace.css +0 -78
- package/registry/examples/accordion.html +0 -56
- package/registry/examples/alert-dialog.html +0 -146
- package/registry/examples/alert.html +0 -62
- package/registry/examples/aspect-ratio.html +0 -14
- package/registry/examples/attachment.html +0 -53
- package/registry/examples/avatar.html +0 -66
- package/registry/examples/badge.html +0 -49
- package/registry/examples/breadcrumb.html +0 -103
- package/registry/examples/bubble.html +0 -26
- package/registry/examples/button-group.html +0 -141
- package/registry/examples/button.html +0 -66
- package/registry/examples/calendar.html +0 -757
- package/registry/examples/card.html +0 -204
- package/registry/examples/carousel.html +0 -127
- package/registry/examples/chart.html +0 -39
- package/registry/examples/checkbox.html +0 -111
- package/registry/examples/code-block.html +0 -84
- package/registry/examples/collapsible.html +0 -22
- package/registry/examples/combobox.html +0 -43
- package/registry/examples/command.html +0 -365
- package/registry/examples/context-menu.html +0 -179
- package/registry/examples/dialog.html +0 -187
- package/registry/examples/drawer.html +0 -234
- package/registry/examples/dropdown-menu.html +0 -272
- package/registry/examples/empty.html +0 -117
- package/registry/examples/field.html +0 -247
- package/registry/examples/hover-card.html +0 -13
- package/registry/examples/input-group.html +0 -110
- package/registry/examples/input-otp.html +0 -182
- package/registry/examples/input.html +0 -80
- package/registry/examples/item.html +0 -32
- package/registry/examples/kbd.html +0 -94
- package/registry/examples/label.html +0 -5
- package/registry/examples/marker.html +0 -20
- package/registry/examples/menubar.html +0 -372
- package/registry/examples/message-scroller.html +0 -54
- package/registry/examples/message.html +0 -47
- package/registry/examples/native-select.html +0 -91
- package/registry/examples/navigation-menu.html +0 -207
- package/registry/examples/pagination.html +0 -39
- package/registry/examples/popover.html +0 -163
- package/registry/examples/progress.html +0 -68
- package/registry/examples/questionnaire.html +0 -99
- package/registry/examples/radio.html +0 -127
- package/registry/examples/resizable.html +0 -107
- package/registry/examples/scroll-area.html +0 -34
- package/registry/examples/select.html +0 -250
- package/registry/examples/separator.html +0 -18
- package/registry/examples/sheet.html +0 -240
- package/registry/examples/sidebar.html +0 -407
- package/registry/examples/skeleton.html +0 -6
- package/registry/examples/slider.html +0 -56
- package/registry/examples/spinner.html +0 -15
- package/registry/examples/switch.html +0 -73
- package/registry/examples/table.html +0 -218
- package/registry/examples/tabs.html +0 -27
- package/registry/examples/textarea.html +0 -36
- package/registry/examples/toast.html +0 -28
- package/registry/examples/toggle-group.html +0 -73
- package/registry/examples/toggle.html +0 -40
- package/registry/examples/tooltip.html +0 -106
- package/registry/examples/trace.html +0 -54
- package/registry/primitives/dialog-shell.css +0 -129
- package/registry/primitives/listbox.css +0 -82
- package/registry/primitives/menu.css +0 -109
- package/registry/primitives/popover.css +0 -162
- package/registry/registry.json +0 -5349
- package/registry/reset.css +0 -400
- package/registry/styles/luma/accordion.css +0 -59
- package/registry/styles/luma/alert-dialog.css +0 -82
- package/registry/styles/luma/alert.css +0 -98
- package/registry/styles/luma/aspect-ratio.css +0 -6
- package/registry/styles/luma/attachment.css +0 -176
- package/registry/styles/luma/avatar.css +0 -132
- package/registry/styles/luma/badge.css +0 -112
- package/registry/styles/luma/breadcrumb.css +0 -62
- package/registry/styles/luma/bubble.css +0 -147
- package/registry/styles/luma/button-group.css +0 -63
- package/registry/styles/luma/button.css +0 -222
- package/registry/styles/luma/calendar.css +0 -140
- package/registry/styles/luma/card.css +0 -82
- package/registry/styles/luma/carousel.css +0 -63
- package/registry/styles/luma/chart.css +0 -51
- package/registry/styles/luma/checkbox.css +0 -58
- package/registry/styles/luma/code-block.css +0 -186
- package/registry/styles/luma/collapsible.css +0 -50
- package/registry/styles/luma/combobox.css +0 -59
- package/registry/styles/luma/command.css +0 -27
- package/registry/styles/luma/context-menu.css +0 -19
- package/registry/styles/luma/dialog.css +0 -64
- package/registry/styles/luma/drawer.css +0 -68
- package/registry/styles/luma/dropdown-menu.css +0 -8
- package/registry/styles/luma/empty.css +0 -52
- package/registry/styles/luma/field.css +0 -120
- package/registry/styles/luma/hover-card.css +0 -22
- package/registry/styles/luma/input-group.css +0 -98
- package/registry/styles/luma/input-otp.css +0 -102
- package/registry/styles/luma/input.css +0 -61
- package/registry/styles/luma/item.css +0 -133
- package/registry/styles/luma/kbd.css +0 -22
- package/registry/styles/luma/label.css +0 -74
- package/registry/styles/luma/marker.css +0 -35
- package/registry/styles/luma/menubar.css +0 -48
- package/registry/styles/luma/message-scroller.css +0 -47
- package/registry/styles/luma/message.css +0 -39
- package/registry/styles/luma/native-select.css +0 -80
- package/registry/styles/luma/navigation-menu.css +0 -90
- package/registry/styles/luma/pagination.css +0 -46
- package/registry/styles/luma/popover.css +0 -25
- package/registry/styles/luma/primitives/dialog-shell.css +0 -19
- package/registry/styles/luma/primitives/listbox.css +0 -79
- package/registry/styles/luma/primitives/menu.css +0 -108
- package/registry/styles/luma/primitives/popover.css +0 -16
- package/registry/styles/luma/progress.css +0 -92
- package/registry/styles/luma/questionnaire.css +0 -141
- package/registry/styles/luma/radio.css +0 -48
- package/registry/styles/luma/resizable.css +0 -44
- package/registry/styles/luma/scroll-area.css +0 -30
- package/registry/styles/luma/select.css +0 -80
- package/registry/styles/luma/separator.css +0 -14
- package/registry/styles/luma/sheet.css +0 -74
- package/registry/styles/luma/sidebar.css +0 -211
- package/registry/styles/luma/skeleton.css +0 -7
- package/registry/styles/luma/slider.css +0 -15
- package/registry/styles/luma/spinner.css +0 -35
- package/registry/styles/luma/switch.css +0 -110
- package/registry/styles/luma/table.css +0 -91
- package/registry/styles/luma/tabs.css +0 -133
- package/registry/styles/luma/textarea.css +0 -53
- package/registry/styles/luma/toast.css +0 -62
- package/registry/styles/luma/toggle-group.css +0 -59
- package/registry/styles/luma/toggle.css +0 -128
- package/registry/styles/luma/tooltip.css +0 -35
- package/registry/styles/luma/trace.css +0 -85
- package/registry/styles/lyra/accordion.css +0 -59
- package/registry/styles/lyra/alert-dialog.css +0 -82
- package/registry/styles/lyra/alert.css +0 -98
- package/registry/styles/lyra/aspect-ratio.css +0 -6
- package/registry/styles/lyra/attachment.css +0 -176
- package/registry/styles/lyra/avatar.css +0 -132
- package/registry/styles/lyra/badge.css +0 -112
- package/registry/styles/lyra/breadcrumb.css +0 -62
- package/registry/styles/lyra/bubble.css +0 -147
- package/registry/styles/lyra/button-group.css +0 -62
- package/registry/styles/lyra/button.css +0 -221
- package/registry/styles/lyra/calendar.css +0 -140
- package/registry/styles/lyra/card.css +0 -81
- package/registry/styles/lyra/carousel.css +0 -63
- package/registry/styles/lyra/chart.css +0 -51
- package/registry/styles/lyra/checkbox.css +0 -58
- package/registry/styles/lyra/code-block.css +0 -186
- package/registry/styles/lyra/collapsible.css +0 -50
- package/registry/styles/lyra/combobox.css +0 -59
- package/registry/styles/lyra/command.css +0 -27
- package/registry/styles/lyra/context-menu.css +0 -19
- package/registry/styles/lyra/dialog.css +0 -64
- package/registry/styles/lyra/drawer.css +0 -68
- package/registry/styles/lyra/dropdown-menu.css +0 -8
- package/registry/styles/lyra/empty.css +0 -52
- package/registry/styles/lyra/field.css +0 -120
- package/registry/styles/lyra/hover-card.css +0 -22
- package/registry/styles/lyra/input-group.css +0 -98
- package/registry/styles/lyra/input-otp.css +0 -102
- package/registry/styles/lyra/input.css +0 -62
- package/registry/styles/lyra/item.css +0 -133
- package/registry/styles/lyra/kbd.css +0 -22
- package/registry/styles/lyra/label.css +0 -74
- package/registry/styles/lyra/marker.css +0 -35
- package/registry/styles/lyra/menubar.css +0 -48
- package/registry/styles/lyra/message-scroller.css +0 -47
- package/registry/styles/lyra/message.css +0 -39
- package/registry/styles/lyra/native-select.css +0 -79
- package/registry/styles/lyra/navigation-menu.css +0 -90
- package/registry/styles/lyra/pagination.css +0 -46
- package/registry/styles/lyra/popover.css +0 -25
- package/registry/styles/lyra/primitives/dialog-shell.css +0 -19
- package/registry/styles/lyra/primitives/listbox.css +0 -79
- package/registry/styles/lyra/primitives/menu.css +0 -108
- package/registry/styles/lyra/primitives/popover.css +0 -16
- package/registry/styles/lyra/progress.css +0 -92
- package/registry/styles/lyra/questionnaire.css +0 -141
- package/registry/styles/lyra/radio.css +0 -48
- package/registry/styles/lyra/resizable.css +0 -44
- package/registry/styles/lyra/scroll-area.css +0 -30
- package/registry/styles/lyra/select.css +0 -80
- package/registry/styles/lyra/separator.css +0 -14
- package/registry/styles/lyra/sheet.css +0 -74
- package/registry/styles/lyra/sidebar.css +0 -211
- package/registry/styles/lyra/skeleton.css +0 -7
- package/registry/styles/lyra/slider.css +0 -15
- package/registry/styles/lyra/spinner.css +0 -35
- package/registry/styles/lyra/switch.css +0 -110
- package/registry/styles/lyra/table.css +0 -91
- package/registry/styles/lyra/tabs.css +0 -133
- package/registry/styles/lyra/textarea.css +0 -53
- package/registry/styles/lyra/toast.css +0 -62
- package/registry/styles/lyra/toggle-group.css +0 -48
- package/registry/styles/lyra/toggle.css +0 -126
- package/registry/styles/lyra/tooltip.css +0 -35
- package/registry/styles/lyra/trace.css +0 -85
- package/registry/styles/maia/accordion.css +0 -59
- package/registry/styles/maia/alert-dialog.css +0 -82
- package/registry/styles/maia/alert.css +0 -98
- package/registry/styles/maia/aspect-ratio.css +0 -6
- package/registry/styles/maia/attachment.css +0 -176
- package/registry/styles/maia/avatar.css +0 -132
- package/registry/styles/maia/badge.css +0 -113
- package/registry/styles/maia/breadcrumb.css +0 -62
- package/registry/styles/maia/bubble.css +0 -147
- package/registry/styles/maia/button-group.css +0 -63
- package/registry/styles/maia/button.css +0 -222
- package/registry/styles/maia/calendar.css +0 -140
- package/registry/styles/maia/card.css +0 -81
- package/registry/styles/maia/carousel.css +0 -63
- package/registry/styles/maia/chart.css +0 -51
- package/registry/styles/maia/checkbox.css +0 -58
- package/registry/styles/maia/code-block.css +0 -186
- package/registry/styles/maia/collapsible.css +0 -50
- package/registry/styles/maia/combobox.css +0 -59
- package/registry/styles/maia/command.css +0 -27
- package/registry/styles/maia/context-menu.css +0 -19
- package/registry/styles/maia/dialog.css +0 -64
- package/registry/styles/maia/drawer.css +0 -68
- package/registry/styles/maia/dropdown-menu.css +0 -8
- package/registry/styles/maia/empty.css +0 -52
- package/registry/styles/maia/field.css +0 -120
- package/registry/styles/maia/hover-card.css +0 -22
- package/registry/styles/maia/input-group.css +0 -98
- package/registry/styles/maia/input-otp.css +0 -102
- package/registry/styles/maia/input.css +0 -61
- package/registry/styles/maia/item.css +0 -133
- package/registry/styles/maia/kbd.css +0 -22
- package/registry/styles/maia/label.css +0 -74
- package/registry/styles/maia/marker.css +0 -35
- package/registry/styles/maia/menubar.css +0 -48
- package/registry/styles/maia/message-scroller.css +0 -47
- package/registry/styles/maia/message.css +0 -39
- package/registry/styles/maia/native-select.css +0 -80
- package/registry/styles/maia/navigation-menu.css +0 -90
- package/registry/styles/maia/pagination.css +0 -46
- package/registry/styles/maia/popover.css +0 -25
- package/registry/styles/maia/primitives/dialog-shell.css +0 -19
- package/registry/styles/maia/primitives/listbox.css +0 -79
- package/registry/styles/maia/primitives/menu.css +0 -108
- package/registry/styles/maia/primitives/popover.css +0 -16
- package/registry/styles/maia/progress.css +0 -92
- package/registry/styles/maia/questionnaire.css +0 -141
- package/registry/styles/maia/radio.css +0 -48
- package/registry/styles/maia/resizable.css +0 -44
- package/registry/styles/maia/scroll-area.css +0 -30
- package/registry/styles/maia/select.css +0 -80
- package/registry/styles/maia/separator.css +0 -14
- package/registry/styles/maia/sheet.css +0 -74
- package/registry/styles/maia/sidebar.css +0 -211
- package/registry/styles/maia/skeleton.css +0 -7
- package/registry/styles/maia/slider.css +0 -15
- package/registry/styles/maia/spinner.css +0 -35
- package/registry/styles/maia/switch.css +0 -110
- package/registry/styles/maia/table.css +0 -91
- package/registry/styles/maia/tabs.css +0 -133
- package/registry/styles/maia/textarea.css +0 -53
- package/registry/styles/maia/toast.css +0 -62
- package/registry/styles/maia/toggle-group.css +0 -59
- package/registry/styles/maia/toggle.css +0 -128
- package/registry/styles/maia/tooltip.css +0 -35
- package/registry/styles/maia/trace.css +0 -85
- package/registry/styles/mira/accordion.css +0 -59
- package/registry/styles/mira/alert-dialog.css +0 -82
- package/registry/styles/mira/alert.css +0 -98
- package/registry/styles/mira/aspect-ratio.css +0 -6
- package/registry/styles/mira/attachment.css +0 -176
- package/registry/styles/mira/avatar.css +0 -132
- package/registry/styles/mira/badge.css +0 -116
- package/registry/styles/mira/breadcrumb.css +0 -62
- package/registry/styles/mira/bubble.css +0 -147
- package/registry/styles/mira/button-group.css +0 -63
- package/registry/styles/mira/button.css +0 -222
- package/registry/styles/mira/calendar.css +0 -140
- package/registry/styles/mira/card.css +0 -81
- package/registry/styles/mira/carousel.css +0 -63
- package/registry/styles/mira/chart.css +0 -51
- package/registry/styles/mira/checkbox.css +0 -58
- package/registry/styles/mira/code-block.css +0 -186
- package/registry/styles/mira/collapsible.css +0 -50
- package/registry/styles/mira/combobox.css +0 -59
- package/registry/styles/mira/command.css +0 -27
- package/registry/styles/mira/context-menu.css +0 -19
- package/registry/styles/mira/dialog.css +0 -64
- package/registry/styles/mira/drawer.css +0 -68
- package/registry/styles/mira/dropdown-menu.css +0 -8
- package/registry/styles/mira/empty.css +0 -52
- package/registry/styles/mira/field.css +0 -120
- package/registry/styles/mira/hover-card.css +0 -22
- package/registry/styles/mira/input-group.css +0 -98
- package/registry/styles/mira/input-otp.css +0 -102
- package/registry/styles/mira/input.css +0 -62
- package/registry/styles/mira/item.css +0 -133
- package/registry/styles/mira/kbd.css +0 -22
- package/registry/styles/mira/label.css +0 -74
- package/registry/styles/mira/marker.css +0 -35
- package/registry/styles/mira/menubar.css +0 -48
- package/registry/styles/mira/message-scroller.css +0 -47
- package/registry/styles/mira/message.css +0 -39
- package/registry/styles/mira/native-select.css +0 -80
- package/registry/styles/mira/navigation-menu.css +0 -90
- package/registry/styles/mira/pagination.css +0 -46
- package/registry/styles/mira/popover.css +0 -25
- package/registry/styles/mira/primitives/dialog-shell.css +0 -19
- package/registry/styles/mira/primitives/listbox.css +0 -79
- package/registry/styles/mira/primitives/menu.css +0 -109
- package/registry/styles/mira/primitives/popover.css +0 -16
- package/registry/styles/mira/progress.css +0 -92
- package/registry/styles/mira/questionnaire.css +0 -141
- package/registry/styles/mira/radio.css +0 -48
- package/registry/styles/mira/resizable.css +0 -44
- package/registry/styles/mira/scroll-area.css +0 -30
- package/registry/styles/mira/select.css +0 -80
- package/registry/styles/mira/separator.css +0 -14
- package/registry/styles/mira/sheet.css +0 -74
- package/registry/styles/mira/sidebar.css +0 -211
- package/registry/styles/mira/skeleton.css +0 -7
- package/registry/styles/mira/slider.css +0 -15
- package/registry/styles/mira/spinner.css +0 -35
- package/registry/styles/mira/switch.css +0 -110
- package/registry/styles/mira/table.css +0 -91
- package/registry/styles/mira/tabs.css +0 -133
- package/registry/styles/mira/textarea.css +0 -53
- package/registry/styles/mira/toast.css +0 -62
- package/registry/styles/mira/toggle-group.css +0 -59
- package/registry/styles/mira/toggle.css +0 -128
- package/registry/styles/mira/tooltip.css +0 -35
- package/registry/styles/mira/trace.css +0 -85
- package/registry/styles/nova/accordion.css +0 -59
- package/registry/styles/nova/alert-dialog.css +0 -82
- package/registry/styles/nova/alert.css +0 -98
- package/registry/styles/nova/aspect-ratio.css +0 -6
- package/registry/styles/nova/attachment.css +0 -176
- package/registry/styles/nova/avatar.css +0 -132
- package/registry/styles/nova/badge.css +0 -112
- package/registry/styles/nova/breadcrumb.css +0 -62
- package/registry/styles/nova/bubble.css +0 -147
- package/registry/styles/nova/button-group.css +0 -62
- package/registry/styles/nova/button.css +0 -221
- package/registry/styles/nova/calendar.css +0 -140
- package/registry/styles/nova/card.css +0 -84
- package/registry/styles/nova/carousel.css +0 -55
- package/registry/styles/nova/chart.css +0 -42
- package/registry/styles/nova/checkbox.css +0 -58
- package/registry/styles/nova/code-block.css +0 -186
- package/registry/styles/nova/collapsible.css +0 -50
- package/registry/styles/nova/combobox.css +0 -59
- package/registry/styles/nova/command.css +0 -27
- package/registry/styles/nova/context-menu.css +0 -19
- package/registry/styles/nova/dialog.css +0 -64
- package/registry/styles/nova/drawer.css +0 -68
- package/registry/styles/nova/dropdown-menu.css +0 -8
- package/registry/styles/nova/empty.css +0 -52
- package/registry/styles/nova/field.css +0 -120
- package/registry/styles/nova/hover-card.css +0 -22
- package/registry/styles/nova/input-group.css +0 -98
- package/registry/styles/nova/input-otp.css +0 -102
- package/registry/styles/nova/input.css +0 -61
- package/registry/styles/nova/item.css +0 -133
- package/registry/styles/nova/kbd.css +0 -22
- package/registry/styles/nova/label.css +0 -74
- package/registry/styles/nova/marker.css +0 -35
- package/registry/styles/nova/menubar.css +0 -48
- package/registry/styles/nova/message-scroller.css +0 -47
- package/registry/styles/nova/message.css +0 -39
- package/registry/styles/nova/native-select.css +0 -82
- package/registry/styles/nova/navigation-menu.css +0 -90
- package/registry/styles/nova/pagination.css +0 -46
- package/registry/styles/nova/popover.css +0 -25
- package/registry/styles/nova/primitives/dialog-shell.css +0 -23
- package/registry/styles/nova/primitives/listbox.css +0 -79
- package/registry/styles/nova/primitives/menu.css +0 -108
- package/registry/styles/nova/primitives/popover.css +0 -16
- package/registry/styles/nova/progress.css +0 -92
- package/registry/styles/nova/questionnaire.css +0 -141
- package/registry/styles/nova/radio.css +0 -48
- package/registry/styles/nova/resizable.css +0 -43
- package/registry/styles/nova/scroll-area.css +0 -30
- package/registry/styles/nova/select.css +0 -80
- package/registry/styles/nova/separator.css +0 -14
- package/registry/styles/nova/sheet.css +0 -74
- package/registry/styles/nova/sidebar.css +0 -211
- package/registry/styles/nova/skeleton.css +0 -7
- package/registry/styles/nova/slider.css +0 -15
- package/registry/styles/nova/spinner.css +0 -35
- package/registry/styles/nova/switch.css +0 -110
- package/registry/styles/nova/table.css +0 -91
- package/registry/styles/nova/tabs.css +0 -133
- package/registry/styles/nova/textarea.css +0 -53
- package/registry/styles/nova/toast.css +0 -62
- package/registry/styles/nova/toggle-group.css +0 -48
- package/registry/styles/nova/toggle.css +0 -124
- package/registry/styles/nova/tooltip.css +0 -35
- package/registry/styles/nova/trace.css +0 -85
- package/registry/styles/rhea/accordion.css +0 -59
- package/registry/styles/rhea/alert-dialog.css +0 -82
- package/registry/styles/rhea/alert.css +0 -98
- package/registry/styles/rhea/aspect-ratio.css +0 -6
- package/registry/styles/rhea/attachment.css +0 -176
- package/registry/styles/rhea/avatar.css +0 -132
- package/registry/styles/rhea/badge.css +0 -112
- package/registry/styles/rhea/breadcrumb.css +0 -62
- package/registry/styles/rhea/bubble.css +0 -147
- package/registry/styles/rhea/button-group.css +0 -63
- package/registry/styles/rhea/button.css +0 -222
- package/registry/styles/rhea/calendar.css +0 -140
- package/registry/styles/rhea/card.css +0 -82
- package/registry/styles/rhea/carousel.css +0 -63
- package/registry/styles/rhea/chart.css +0 -51
- package/registry/styles/rhea/checkbox.css +0 -58
- package/registry/styles/rhea/code-block.css +0 -186
- package/registry/styles/rhea/collapsible.css +0 -50
- package/registry/styles/rhea/combobox.css +0 -59
- package/registry/styles/rhea/command.css +0 -27
- package/registry/styles/rhea/context-menu.css +0 -19
- package/registry/styles/rhea/dialog.css +0 -64
- package/registry/styles/rhea/drawer.css +0 -68
- package/registry/styles/rhea/dropdown-menu.css +0 -8
- package/registry/styles/rhea/empty.css +0 -52
- package/registry/styles/rhea/field.css +0 -120
- package/registry/styles/rhea/hover-card.css +0 -22
- package/registry/styles/rhea/input-group.css +0 -98
- package/registry/styles/rhea/input-otp.css +0 -102
- package/registry/styles/rhea/input.css +0 -61
- package/registry/styles/rhea/item.css +0 -133
- package/registry/styles/rhea/kbd.css +0 -22
- package/registry/styles/rhea/label.css +0 -74
- package/registry/styles/rhea/marker.css +0 -35
- package/registry/styles/rhea/menubar.css +0 -48
- package/registry/styles/rhea/message-scroller.css +0 -47
- package/registry/styles/rhea/message.css +0 -39
- package/registry/styles/rhea/native-select.css +0 -80
- package/registry/styles/rhea/navigation-menu.css +0 -90
- package/registry/styles/rhea/pagination.css +0 -46
- package/registry/styles/rhea/popover.css +0 -25
- package/registry/styles/rhea/primitives/dialog-shell.css +0 -19
- package/registry/styles/rhea/primitives/listbox.css +0 -79
- package/registry/styles/rhea/primitives/menu.css +0 -109
- package/registry/styles/rhea/primitives/popover.css +0 -16
- package/registry/styles/rhea/progress.css +0 -92
- package/registry/styles/rhea/questionnaire.css +0 -141
- package/registry/styles/rhea/radio.css +0 -48
- package/registry/styles/rhea/resizable.css +0 -44
- package/registry/styles/rhea/scroll-area.css +0 -30
- package/registry/styles/rhea/select.css +0 -80
- package/registry/styles/rhea/separator.css +0 -14
- package/registry/styles/rhea/sheet.css +0 -74
- package/registry/styles/rhea/sidebar.css +0 -211
- package/registry/styles/rhea/skeleton.css +0 -7
- package/registry/styles/rhea/slider.css +0 -15
- package/registry/styles/rhea/spinner.css +0 -35
- package/registry/styles/rhea/switch.css +0 -110
- package/registry/styles/rhea/table.css +0 -91
- package/registry/styles/rhea/tabs.css +0 -133
- package/registry/styles/rhea/textarea.css +0 -53
- package/registry/styles/rhea/toast.css +0 -62
- package/registry/styles/rhea/toggle-group.css +0 -59
- package/registry/styles/rhea/toggle.css +0 -128
- package/registry/styles/rhea/tooltip.css +0 -35
- package/registry/styles/rhea/trace.css +0 -85
- package/registry/styles/sera/accordion.css +0 -59
- package/registry/styles/sera/alert-dialog.css +0 -84
- package/registry/styles/sera/alert.css +0 -98
- package/registry/styles/sera/aspect-ratio.css +0 -6
- package/registry/styles/sera/attachment.css +0 -176
- package/registry/styles/sera/avatar.css +0 -132
- package/registry/styles/sera/badge.css +0 -143
- package/registry/styles/sera/breadcrumb.css +0 -62
- package/registry/styles/sera/bubble.css +0 -147
- package/registry/styles/sera/button-group.css +0 -63
- package/registry/styles/sera/button.css +0 -222
- package/registry/styles/sera/calendar.css +0 -148
- package/registry/styles/sera/card.css +0 -84
- package/registry/styles/sera/carousel.css +0 -63
- package/registry/styles/sera/chart.css +0 -51
- package/registry/styles/sera/checkbox.css +0 -58
- package/registry/styles/sera/code-block.css +0 -186
- package/registry/styles/sera/collapsible.css +0 -50
- package/registry/styles/sera/combobox.css +0 -60
- package/registry/styles/sera/command.css +0 -27
- package/registry/styles/sera/context-menu.css +0 -19
- package/registry/styles/sera/dialog.css +0 -67
- package/registry/styles/sera/drawer.css +0 -70
- package/registry/styles/sera/dropdown-menu.css +0 -8
- package/registry/styles/sera/empty.css +0 -52
- package/registry/styles/sera/field.css +0 -120
- package/registry/styles/sera/hover-card.css +0 -22
- package/registry/styles/sera/input-group.css +0 -99
- package/registry/styles/sera/input-otp.css +0 -103
- package/registry/styles/sera/input.css +0 -62
- package/registry/styles/sera/item.css +0 -133
- package/registry/styles/sera/kbd.css +0 -22
- package/registry/styles/sera/label.css +0 -74
- package/registry/styles/sera/marker.css +0 -35
- package/registry/styles/sera/menubar.css +0 -48
- package/registry/styles/sera/message-scroller.css +0 -47
- package/registry/styles/sera/message.css +0 -39
- package/registry/styles/sera/native-select.css +0 -81
- package/registry/styles/sera/navigation-menu.css +0 -90
- package/registry/styles/sera/pagination.css +0 -46
- package/registry/styles/sera/popover.css +0 -25
- package/registry/styles/sera/primitives/dialog-shell.css +0 -19
- package/registry/styles/sera/primitives/listbox.css +0 -79
- package/registry/styles/sera/primitives/menu.css +0 -108
- package/registry/styles/sera/primitives/popover.css +0 -16
- package/registry/styles/sera/progress.css +0 -92
- package/registry/styles/sera/questionnaire.css +0 -147
- package/registry/styles/sera/radio.css +0 -48
- package/registry/styles/sera/resizable.css +0 -44
- package/registry/styles/sera/scroll-area.css +0 -30
- package/registry/styles/sera/select.css +0 -81
- package/registry/styles/sera/separator.css +0 -14
- package/registry/styles/sera/sheet.css +0 -76
- package/registry/styles/sera/sidebar.css +0 -217
- package/registry/styles/sera/skeleton.css +0 -7
- package/registry/styles/sera/slider.css +0 -15
- package/registry/styles/sera/spinner.css +0 -35
- package/registry/styles/sera/switch.css +0 -111
- package/registry/styles/sera/table.css +0 -92
- package/registry/styles/sera/tabs.css +0 -133
- package/registry/styles/sera/textarea.css +0 -54
- package/registry/styles/sera/toast.css +0 -64
- package/registry/styles/sera/toggle-group.css +0 -58
- package/registry/styles/sera/toggle.css +0 -128
- package/registry/styles/sera/tooltip.css +0 -35
- package/registry/styles/sera/trace.css +0 -87
- package/registry/styles/vega/accordion.css +0 -59
- package/registry/styles/vega/alert-dialog.css +0 -82
- package/registry/styles/vega/alert.css +0 -98
- package/registry/styles/vega/aspect-ratio.css +0 -6
- package/registry/styles/vega/attachment.css +0 -176
- package/registry/styles/vega/avatar.css +0 -132
- package/registry/styles/vega/badge.css +0 -112
- package/registry/styles/vega/breadcrumb.css +0 -62
- package/registry/styles/vega/bubble.css +0 -147
- package/registry/styles/vega/button-group.css +0 -63
- package/registry/styles/vega/button.css +0 -222
- package/registry/styles/vega/calendar.css +0 -140
- package/registry/styles/vega/card.css +0 -82
- package/registry/styles/vega/carousel.css +0 -63
- package/registry/styles/vega/chart.css +0 -51
- package/registry/styles/vega/checkbox.css +0 -59
- package/registry/styles/vega/code-block.css +0 -186
- package/registry/styles/vega/collapsible.css +0 -50
- package/registry/styles/vega/combobox.css +0 -59
- package/registry/styles/vega/command.css +0 -27
- package/registry/styles/vega/context-menu.css +0 -19
- package/registry/styles/vega/dialog.css +0 -64
- package/registry/styles/vega/drawer.css +0 -68
- package/registry/styles/vega/dropdown-menu.css +0 -8
- package/registry/styles/vega/empty.css +0 -52
- package/registry/styles/vega/field.css +0 -120
- package/registry/styles/vega/hover-card.css +0 -22
- package/registry/styles/vega/input-group.css +0 -98
- package/registry/styles/vega/input-otp.css +0 -102
- package/registry/styles/vega/input.css +0 -62
- package/registry/styles/vega/item.css +0 -133
- package/registry/styles/vega/kbd.css +0 -22
- package/registry/styles/vega/label.css +0 -74
- package/registry/styles/vega/marker.css +0 -35
- package/registry/styles/vega/menubar.css +0 -48
- package/registry/styles/vega/message-scroller.css +0 -47
- package/registry/styles/vega/message.css +0 -39
- package/registry/styles/vega/native-select.css +0 -81
- package/registry/styles/vega/navigation-menu.css +0 -90
- package/registry/styles/vega/pagination.css +0 -46
- package/registry/styles/vega/popover.css +0 -25
- package/registry/styles/vega/primitives/dialog-shell.css +0 -19
- package/registry/styles/vega/primitives/listbox.css +0 -79
- package/registry/styles/vega/primitives/menu.css +0 -108
- package/registry/styles/vega/primitives/popover.css +0 -16
- package/registry/styles/vega/progress.css +0 -92
- package/registry/styles/vega/questionnaire.css +0 -141
- package/registry/styles/vega/radio.css +0 -48
- package/registry/styles/vega/resizable.css +0 -44
- package/registry/styles/vega/scroll-area.css +0 -30
- package/registry/styles/vega/select.css +0 -80
- package/registry/styles/vega/separator.css +0 -14
- package/registry/styles/vega/sheet.css +0 -74
- package/registry/styles/vega/sidebar.css +0 -211
- package/registry/styles/vega/skeleton.css +0 -7
- package/registry/styles/vega/slider.css +0 -15
- package/registry/styles/vega/spinner.css +0 -35
- package/registry/styles/vega/switch.css +0 -111
- package/registry/styles/vega/table.css +0 -91
- package/registry/styles/vega/tabs.css +0 -133
- package/registry/styles/vega/textarea.css +0 -54
- package/registry/styles/vega/toast.css +0 -62
- package/registry/styles/vega/toggle-group.css +0 -59
- package/registry/styles/vega/toggle.css +0 -128
- package/registry/styles/vega/tooltip.css +0 -35
- package/registry/styles/vega/trace.css +0 -85
- package/registry/tokens.css +0 -125
- package/registry/utilities.css +0 -14
|
@@ -1,855 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { emit, init, isRTL, on } from "./core.js";
|
|
4
|
-
|
|
5
|
-
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
6
|
-
const ISO_MONTH = /^\d{4}-\d{2}$/;
|
|
7
|
-
const DAY_SELECTOR = "button[data-date]";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {"single" | "range" | "multiple"} SelectionMode
|
|
11
|
-
* @typedef {object} CalendarState
|
|
12
|
-
* @property {SelectionMode} selection
|
|
13
|
-
* @property {number} year
|
|
14
|
-
* @property {number} month
|
|
15
|
-
* @property {string | null} value
|
|
16
|
-
* @property {string[]} values
|
|
17
|
-
* @property {string | null} rangeStart
|
|
18
|
-
* @property {string | null} rangeEnd
|
|
19
|
-
* @property {Set<string>} unavailable
|
|
20
|
-
* @property {string | null} min
|
|
21
|
-
* @property {string | null} max
|
|
22
|
-
* @property {string | null} today
|
|
23
|
-
* @property {boolean} weekNumbers
|
|
24
|
-
* @property {number[]} weekOrder
|
|
25
|
-
* @property {string} locale
|
|
26
|
-
* @property {string | null} focused
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/** @type {WeakMap<HTMLElement, CalendarState>} */
|
|
30
|
-
const states = new WeakMap();
|
|
31
|
-
/** @type {WeakSet<HTMLElement>} */
|
|
32
|
-
const skipped = new WeakSet();
|
|
33
|
-
|
|
34
|
-
/** @param {number} value */
|
|
35
|
-
const pad = (value) => String(value).padStart(2, "0");
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {number} year
|
|
39
|
-
* @param {number} month
|
|
40
|
-
* @param {number} day
|
|
41
|
-
*/
|
|
42
|
-
function isoDate(year, month, day) {
|
|
43
|
-
return `${year}-${pad(month + 1)}-${pad(day)}`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** @param {string} value */
|
|
47
|
-
function parseDate(value) {
|
|
48
|
-
if (!ISO_DATE.test(value)) return null;
|
|
49
|
-
const [yearText, monthText, dayText] = value.split("-");
|
|
50
|
-
const year = Number(yearText);
|
|
51
|
-
const month = Number(monthText) - 1;
|
|
52
|
-
const day = Number(dayText);
|
|
53
|
-
if (
|
|
54
|
-
!Number.isInteger(year) ||
|
|
55
|
-
!Number.isInteger(month) ||
|
|
56
|
-
!Number.isInteger(day)
|
|
57
|
-
) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
if (month < 0 || month > 11 || day < 1 || day > 31) return null;
|
|
61
|
-
const date = new Date(Date.UTC(year, month, day));
|
|
62
|
-
if (
|
|
63
|
-
date.getUTCFullYear() !== year ||
|
|
64
|
-
date.getUTCMonth() !== month ||
|
|
65
|
-
date.getUTCDate() !== day
|
|
66
|
-
) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
return { year, month, day };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** @param {string} value */
|
|
73
|
-
function parseMonth(value) {
|
|
74
|
-
if (!ISO_MONTH.test(value)) return null;
|
|
75
|
-
const [yearText, monthText] = value.split("-");
|
|
76
|
-
const year = Number(yearText);
|
|
77
|
-
const month = Number(monthText) - 1;
|
|
78
|
-
if (!Number.isInteger(year) || month < 0 || month > 11) return null;
|
|
79
|
-
return { year, month };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** @param {string} value */
|
|
83
|
-
function dateFromIso(value) {
|
|
84
|
-
return new Date(`${value}T00:00:00Z`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** @param {string} value @param {number} days */
|
|
88
|
-
function addDays(value, days) {
|
|
89
|
-
const date = dateFromIso(value);
|
|
90
|
-
date.setUTCDate(date.getUTCDate() + days);
|
|
91
|
-
return isoDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** @param {number} year @param {number} month */
|
|
95
|
-
function daysInMonth(year, month) {
|
|
96
|
-
return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** @param {number} year @param {number} month @param {number} day */
|
|
100
|
-
function weekdayOf(year, month, day) {
|
|
101
|
-
return new Date(Date.UTC(year, month, day)).getUTCDay();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** @param {string} value @param {number} year @param {number} month */
|
|
105
|
-
function sameMonth(value, year, month) {
|
|
106
|
-
const parsed = parseDate(value);
|
|
107
|
-
return parsed !== null && parsed.year === year && parsed.month === month;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** @param {Date} date */
|
|
111
|
-
function isoWeek(date) {
|
|
112
|
-
const target = new Date(
|
|
113
|
-
Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate())
|
|
114
|
-
);
|
|
115
|
-
const dayNumber = (target.getUTCDay() + 6) % 7;
|
|
116
|
-
target.setUTCDate(target.getUTCDate() - dayNumber + 3);
|
|
117
|
-
const firstThursday = new Date(Date.UTC(target.getUTCFullYear(), 0, 4));
|
|
118
|
-
const firstDayNumber = (firstThursday.getUTCDay() + 6) % 7;
|
|
119
|
-
firstThursday.setUTCDate(firstThursday.getUTCDate() - firstDayNumber + 3);
|
|
120
|
-
return (
|
|
121
|
-
1 +
|
|
122
|
-
Math.round((target.getTime() - firstThursday.getTime()) / 604800000)
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** @param {string} locale */
|
|
127
|
-
function latin(locale) {
|
|
128
|
-
const tag = locale.trim() || "en";
|
|
129
|
-
return tag.includes("-u-") ? tag : `${tag}-u-nu-latn`;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/** @param {string} locale */
|
|
133
|
-
function dayLabelFormatter(locale) {
|
|
134
|
-
return new Intl.DateTimeFormat(latin(locale), {
|
|
135
|
-
year: "numeric",
|
|
136
|
-
month: "long",
|
|
137
|
-
day: "numeric",
|
|
138
|
-
timeZone: "UTC"
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/** @param {string} locale @param {string} value */
|
|
143
|
-
function dayLabel(locale, value) {
|
|
144
|
-
return dayLabelFormatter(locale).format(dateFromIso(value));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/** @param {string} locale @param {number} year @param {number} month */
|
|
148
|
-
function monthLabel(locale, year, month) {
|
|
149
|
-
return new Intl.DateTimeFormat(latin(locale), {
|
|
150
|
-
month: "long",
|
|
151
|
-
year: "numeric",
|
|
152
|
-
timeZone: "UTC"
|
|
153
|
-
}).format(new Date(Date.UTC(year, month, 1)));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/** @param {string} locale */
|
|
157
|
-
function weekdayLabels(locale) {
|
|
158
|
-
const full = new Intl.DateTimeFormat(latin(locale), {
|
|
159
|
-
weekday: "long",
|
|
160
|
-
timeZone: "UTC"
|
|
161
|
-
});
|
|
162
|
-
const short = new Intl.DateTimeFormat(latin(locale), {
|
|
163
|
-
weekday: "short",
|
|
164
|
-
timeZone: "UTC"
|
|
165
|
-
});
|
|
166
|
-
const names = { full: /** @type {string[]} */ ([]), short: /** @type {string[]} */ ([]) };
|
|
167
|
-
|
|
168
|
-
for (let index = 0; index < 7; index += 1) {
|
|
169
|
-
const date = new Date(Date.UTC(2024, 0, 7 + index));
|
|
170
|
-
names.full.push(full.format(date));
|
|
171
|
-
names.short.push(short.format(date));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return names;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/** @param {string} locale */
|
|
178
|
-
function firstDayOfWeek(locale) {
|
|
179
|
-
try {
|
|
180
|
-
const info = /** @type {{ weekInfo?: { firstDay?: number } }} */ (
|
|
181
|
-
/** @type {unknown} */ (new Intl.Locale(locale))
|
|
182
|
-
);
|
|
183
|
-
const firstDay = info.weekInfo?.firstDay;
|
|
184
|
-
if (typeof firstDay === "number") return firstDay % 7;
|
|
185
|
-
} catch {
|
|
186
|
-
// Intl.Locale or weekInfo is unavailable; fall back to Sunday.
|
|
187
|
-
}
|
|
188
|
-
return 0;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/** @param {Element} calendar @param {string} locale */
|
|
192
|
-
function weekOrderFor(calendar, locale) {
|
|
193
|
-
const cells = [...calendar.querySelectorAll("thead th[scope='col']")];
|
|
194
|
-
const labels = cells
|
|
195
|
-
.map(
|
|
196
|
-
(cell) =>
|
|
197
|
-
cell.getAttribute("aria-label") ?? cell.textContent?.trim() ?? ""
|
|
198
|
-
)
|
|
199
|
-
.filter((label) => label !== "" && label !== "Week");
|
|
200
|
-
const names = weekdayLabels(locale);
|
|
201
|
-
const matched = labels
|
|
202
|
-
.map((label) => {
|
|
203
|
-
const fullIndex = names.full.indexOf(label);
|
|
204
|
-
if (fullIndex !== -1) return fullIndex;
|
|
205
|
-
return names.short.indexOf(label);
|
|
206
|
-
})
|
|
207
|
-
.filter((index) => index !== -1);
|
|
208
|
-
|
|
209
|
-
if (matched.length === 7) return matched;
|
|
210
|
-
|
|
211
|
-
const first = firstDayOfWeek(locale);
|
|
212
|
-
return Array.from({ length: 7 }, (_, index) => (first + index) % 7);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/** @param {Element} calendar */
|
|
216
|
-
function hasWeekNumbers(calendar) {
|
|
217
|
-
return [...calendar.querySelectorAll("thead th[scope='col']")].some((cell) => {
|
|
218
|
-
if (cell.getAttribute("aria-label") === "Week") return true;
|
|
219
|
-
return (cell.textContent ?? "").trim() === "";
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** @param {string | null} value */
|
|
224
|
-
function parseDateAttribute(value) {
|
|
225
|
-
if (!value) return null;
|
|
226
|
-
return parseDate(value) ? value : null;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/** @param {string | null} value */
|
|
230
|
-
function parseList(value) {
|
|
231
|
-
if (!value) return [];
|
|
232
|
-
return value
|
|
233
|
-
.split(",")
|
|
234
|
-
.map((part) => part.trim())
|
|
235
|
-
.filter((part) => parseDate(part) !== null);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/** @param {Element} calendar */
|
|
239
|
-
function initialMonth(calendar) {
|
|
240
|
-
const explicit = parseMonth(calendar.getAttribute("data-month") ?? "");
|
|
241
|
-
if (explicit) return explicit;
|
|
242
|
-
|
|
243
|
-
const first = calendar.querySelector(DAY_SELECTOR)?.getAttribute("data-date");
|
|
244
|
-
if (first) {
|
|
245
|
-
const parsed = parseDate(first);
|
|
246
|
-
if (parsed) return { year: parsed.year, month: parsed.month };
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const monthSelect = calendar.querySelector(
|
|
250
|
-
"[data-slot='month'], select[aria-label='Month']"
|
|
251
|
-
);
|
|
252
|
-
const yearSelect = calendar.querySelector(
|
|
253
|
-
"[data-slot='year'], select[aria-label='Year']"
|
|
254
|
-
);
|
|
255
|
-
if (monthSelect instanceof HTMLSelectElement) {
|
|
256
|
-
const month = Number(monthSelect.value) - 1;
|
|
257
|
-
const year =
|
|
258
|
-
yearSelect instanceof HTMLSelectElement
|
|
259
|
-
? Number(yearSelect.value)
|
|
260
|
-
: new Date().getFullYear();
|
|
261
|
-
if (Number.isInteger(year) && month >= 0 && month < 12) {
|
|
262
|
-
return { year, month };
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const today = new Date();
|
|
267
|
-
return { year: today.getFullYear(), month: today.getMonth() };
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/** @param {Element} calendar */
|
|
271
|
-
function initialValues(calendar) {
|
|
272
|
-
const values = [...calendar.querySelectorAll("td[aria-selected='true']")]
|
|
273
|
-
.map((cell) => cell.querySelector(DAY_SELECTOR)?.getAttribute("data-date"))
|
|
274
|
-
.filter((value) => typeof value === "string" && parseDate(value) !== null);
|
|
275
|
-
|
|
276
|
-
return /** @type {string[]} */ ([...new Set(values)]).sort();
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/** @param {Element} calendar @param {number} year @param {number} month */
|
|
280
|
-
function initialUnavailable(calendar, year, month) {
|
|
281
|
-
const unavailable = new Set(parseList(calendar.getAttribute("data-unavailable")));
|
|
282
|
-
|
|
283
|
-
for (const button of calendar.querySelectorAll(DAY_SELECTOR)) {
|
|
284
|
-
if (button.getAttribute("aria-disabled") !== "true") continue;
|
|
285
|
-
const value = button.getAttribute("data-date");
|
|
286
|
-
if (!value) continue;
|
|
287
|
-
const parsed = parseDate(value);
|
|
288
|
-
if (parsed && parsed.year === year && parsed.month === month) {
|
|
289
|
-
unavailable.add(value);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return unavailable;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/** @param {Element} calendar */
|
|
297
|
-
function initialToday(calendar) {
|
|
298
|
-
const current = calendar
|
|
299
|
-
.querySelector("button[aria-current='date'][data-date]")
|
|
300
|
-
?.getAttribute("data-date");
|
|
301
|
-
if (current && parseDate(current)) return current;
|
|
302
|
-
|
|
303
|
-
const today = new Date();
|
|
304
|
-
return isoDate(today.getFullYear(), today.getMonth(), today.getDate());
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/** @param {Element} calendar */
|
|
308
|
-
function readSelection(calendar) {
|
|
309
|
-
const value = calendar.getAttribute("data-selection");
|
|
310
|
-
if (value === "range" || value === "multiple") return value;
|
|
311
|
-
|
|
312
|
-
const grid = calendar.querySelector("table[role='grid']");
|
|
313
|
-
if (grid?.getAttribute("aria-multiselectable") === "true") return "range";
|
|
314
|
-
return "single";
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/** @param {Element} calendar @param {string | null} focus */
|
|
318
|
-
function setRovingTabindex(calendar, focus) {
|
|
319
|
-
for (const button of calendar.querySelectorAll(DAY_SELECTOR)) {
|
|
320
|
-
button.setAttribute(
|
|
321
|
-
"tabindex",
|
|
322
|
-
focus !== null && button.getAttribute("data-date") === focus ? "0" : "-1"
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/** @param {Element} calendar */
|
|
328
|
-
function hasCustomDayContent(calendar) {
|
|
329
|
-
for (const cell of calendar.querySelectorAll("td[role='gridcell']")) {
|
|
330
|
-
const button = cell.querySelector(":scope > button");
|
|
331
|
-
if (!button) return true;
|
|
332
|
-
if (button.children.length > 0) return true;
|
|
333
|
-
if (cell.children.length !== 1) return true;
|
|
334
|
-
}
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* @param {Element} calendar
|
|
340
|
-
* @returns {CalendarState | null}
|
|
341
|
-
*/
|
|
342
|
-
function ensure(calendar) {
|
|
343
|
-
if (!(calendar instanceof HTMLElement)) {
|
|
344
|
-
throw new Error("calendar root must be an HTMLElement");
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const existing = states.get(calendar);
|
|
348
|
-
if (existing) return existing;
|
|
349
|
-
if (skipped.has(calendar)) return null;
|
|
350
|
-
if (hasCustomDayContent(calendar)) {
|
|
351
|
-
skipped.add(calendar);
|
|
352
|
-
return null;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
const month = initialMonth(calendar);
|
|
356
|
-
const values = initialValues(calendar);
|
|
357
|
-
const selection = readSelection(calendar);
|
|
358
|
-
const locale =
|
|
359
|
-
calendar.closest("[lang]")?.getAttribute("lang") ??
|
|
360
|
-
document.documentElement.lang ??
|
|
361
|
-
"en";
|
|
362
|
-
const state = /** @type {CalendarState} */ ({
|
|
363
|
-
selection,
|
|
364
|
-
year: month.year,
|
|
365
|
-
month: month.month,
|
|
366
|
-
value: null,
|
|
367
|
-
values: [],
|
|
368
|
-
rangeStart: null,
|
|
369
|
-
rangeEnd: null,
|
|
370
|
-
unavailable: initialUnavailable(calendar, month.year, month.month),
|
|
371
|
-
min: parseDateAttribute(calendar.getAttribute("data-min")),
|
|
372
|
-
max: parseDateAttribute(calendar.getAttribute("data-max")),
|
|
373
|
-
today: initialToday(calendar),
|
|
374
|
-
weekNumbers: hasWeekNumbers(calendar),
|
|
375
|
-
weekOrder: weekOrderFor(calendar, locale),
|
|
376
|
-
locale,
|
|
377
|
-
focused: null
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
if (selection === "single") {
|
|
381
|
-
state.value = values[0] ?? null;
|
|
382
|
-
state.values = state.value ? [state.value] : [];
|
|
383
|
-
} else if (selection === "multiple") {
|
|
384
|
-
state.values = values;
|
|
385
|
-
} else {
|
|
386
|
-
state.rangeStart = values[0] ?? null;
|
|
387
|
-
state.rangeEnd = values.length > 1 ? values[values.length - 1] ?? null : null;
|
|
388
|
-
state.value = state.rangeStart;
|
|
389
|
-
if (state.rangeStart) state.values.push(state.rangeStart);
|
|
390
|
-
if (state.rangeEnd) state.values.push(state.rangeEnd);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const focused =
|
|
394
|
-
calendar
|
|
395
|
-
.querySelector("button[tabindex='0'][data-date]")
|
|
396
|
-
?.getAttribute("data-date") ?? null;
|
|
397
|
-
state.focused =
|
|
398
|
-
focused && parseDate(focused)
|
|
399
|
-
? focused
|
|
400
|
-
: state.value ?? state.today ?? isoDate(state.year, state.month, 1);
|
|
401
|
-
|
|
402
|
-
states.set(calendar, state);
|
|
403
|
-
|
|
404
|
-
const grid = calendar.querySelector("table[role='grid']");
|
|
405
|
-
if (grid) {
|
|
406
|
-
if (state.selection === "single") {
|
|
407
|
-
grid.removeAttribute("aria-multiselectable");
|
|
408
|
-
} else {
|
|
409
|
-
grid.setAttribute("aria-multiselectable", "true");
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
setRovingTabindex(calendar, state.focused);
|
|
414
|
-
return state;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
/** @param {CalendarState} state @param {string} value */
|
|
418
|
-
function isDisabled(state, value) {
|
|
419
|
-
const parsed = parseDate(value);
|
|
420
|
-
if (!parsed) return true;
|
|
421
|
-
if (state.min && value < state.min) return true;
|
|
422
|
-
if (state.max && value > state.max) return true;
|
|
423
|
-
return state.unavailable.has(value);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/** @param {CalendarState} state @param {string} value */
|
|
427
|
-
function isSelected(state, value) {
|
|
428
|
-
if (state.selection === "single") return state.value === value;
|
|
429
|
-
if (state.selection === "multiple") return state.values.includes(value);
|
|
430
|
-
if (!state.rangeStart) return false;
|
|
431
|
-
if (!state.rangeEnd) return state.rangeStart === value;
|
|
432
|
-
return value >= state.rangeStart && value <= state.rangeEnd;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* @param {Element} calendar
|
|
437
|
-
* @param {CalendarState} state
|
|
438
|
-
* @param {string} value
|
|
439
|
-
* @param {boolean} extend
|
|
440
|
-
*/
|
|
441
|
-
function selectDate(calendar, state, value, extend) {
|
|
442
|
-
if (state.selection === "single") {
|
|
443
|
-
state.value = value;
|
|
444
|
-
state.values = [value];
|
|
445
|
-
state.rangeStart = null;
|
|
446
|
-
state.rangeEnd = null;
|
|
447
|
-
} else if (state.selection === "multiple") {
|
|
448
|
-
const index = state.values.indexOf(value);
|
|
449
|
-
if (index === -1) {
|
|
450
|
-
state.values = [...state.values, value];
|
|
451
|
-
} else {
|
|
452
|
-
state.values = state.values.filter((candidate) => candidate !== value);
|
|
453
|
-
}
|
|
454
|
-
state.value = null;
|
|
455
|
-
state.rangeStart = null;
|
|
456
|
-
state.rangeEnd = null;
|
|
457
|
-
} else if (extend && state.rangeStart) {
|
|
458
|
-
const start = state.rangeStart;
|
|
459
|
-
state.rangeStart = value < start ? value : start;
|
|
460
|
-
state.rangeEnd = value < start ? start : value;
|
|
461
|
-
state.values = [state.rangeStart, state.rangeEnd];
|
|
462
|
-
state.value = state.rangeStart;
|
|
463
|
-
} else if (state.rangeStart && state.rangeEnd) {
|
|
464
|
-
state.rangeStart = value;
|
|
465
|
-
state.rangeEnd = null;
|
|
466
|
-
state.values = [value];
|
|
467
|
-
state.value = value;
|
|
468
|
-
} else if (state.rangeStart) {
|
|
469
|
-
const start = state.rangeStart;
|
|
470
|
-
state.rangeStart = value < start ? value : start;
|
|
471
|
-
state.rangeEnd = value < start ? start : value;
|
|
472
|
-
state.values = [state.rangeStart, state.rangeEnd];
|
|
473
|
-
state.value = state.rangeStart;
|
|
474
|
-
} else {
|
|
475
|
-
state.rangeStart = value;
|
|
476
|
-
state.rangeEnd = null;
|
|
477
|
-
state.values = [value];
|
|
478
|
-
state.value = value;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
state.focused = value;
|
|
482
|
-
emit(calendar, "change", {
|
|
483
|
-
value: state.value,
|
|
484
|
-
values: [...state.values],
|
|
485
|
-
range:
|
|
486
|
-
state.rangeStart && state.rangeEnd
|
|
487
|
-
? { start: state.rangeStart, end: state.rangeEnd }
|
|
488
|
-
: null
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* @param {Element} calendar
|
|
494
|
-
* @param {CalendarState} state
|
|
495
|
-
* @param {string | null} focusDate
|
|
496
|
-
*/
|
|
497
|
-
function render(calendar, state, focusDate) {
|
|
498
|
-
const table = calendar.querySelector("table[role='grid']");
|
|
499
|
-
if (!table) return;
|
|
500
|
-
|
|
501
|
-
for (const value of parseList(calendar.getAttribute("data-unavailable"))) {
|
|
502
|
-
state.unavailable.add(value);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
const names = weekdayLabels(state.locale);
|
|
506
|
-
const thead = table.querySelector("thead");
|
|
507
|
-
const tbody = table.querySelector("tbody");
|
|
508
|
-
if (!thead || !tbody) return;
|
|
509
|
-
|
|
510
|
-
const headerRow = document.createElement("tr");
|
|
511
|
-
if (state.weekNumbers) {
|
|
512
|
-
const week = document.createElement("th");
|
|
513
|
-
week.scope = "col";
|
|
514
|
-
week.setAttribute("aria-label", "Week");
|
|
515
|
-
headerRow.append(week);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
for (const index of state.weekOrder) {
|
|
519
|
-
const cell = document.createElement("th");
|
|
520
|
-
cell.scope = "col";
|
|
521
|
-
cell.setAttribute("aria-label", names.full[index] ?? "");
|
|
522
|
-
cell.textContent = names.short[index] ?? "";
|
|
523
|
-
headerRow.append(cell);
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
thead.replaceChildren(headerRow);
|
|
527
|
-
tbody.replaceChildren();
|
|
528
|
-
|
|
529
|
-
const firstWeekday = weekdayOf(state.year, state.month, 1);
|
|
530
|
-
const startOffset =
|
|
531
|
-
(firstWeekday - (state.weekOrder[0] ?? 0) + 7) % 7;
|
|
532
|
-
const days = daysInMonth(state.year, state.month);
|
|
533
|
-
const cellCount = Math.ceil((startOffset + days) / 7) * 7;
|
|
534
|
-
|
|
535
|
-
let focus =
|
|
536
|
-
focusDate && sameMonth(focusDate, state.year, state.month)
|
|
537
|
-
? focusDate
|
|
538
|
-
: state.focused && sameMonth(state.focused, state.year, state.month)
|
|
539
|
-
? state.focused
|
|
540
|
-
: state.value && sameMonth(state.value, state.year, state.month)
|
|
541
|
-
? state.value
|
|
542
|
-
: state.today && sameMonth(state.today, state.year, state.month)
|
|
543
|
-
? state.today
|
|
544
|
-
: isoDate(state.year, state.month, 1);
|
|
545
|
-
|
|
546
|
-
if (isDisabled(state, focus)) {
|
|
547
|
-
for (let day = 1; day <= days; day += 1) {
|
|
548
|
-
const candidate = isoDate(state.year, state.month, day);
|
|
549
|
-
if (!isDisabled(state, candidate)) {
|
|
550
|
-
focus = candidate;
|
|
551
|
-
break;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
state.focused = focus;
|
|
556
|
-
|
|
557
|
-
for (let index = 0; index < cellCount; index += 7) {
|
|
558
|
-
const row = document.createElement("tr");
|
|
559
|
-
const rowStart = new Date(
|
|
560
|
-
Date.UTC(state.year, state.month, 1 - startOffset + index)
|
|
561
|
-
);
|
|
562
|
-
|
|
563
|
-
if (state.weekNumbers) {
|
|
564
|
-
const week = document.createElement("th");
|
|
565
|
-
week.scope = "row";
|
|
566
|
-
const number = isoWeek(rowStart);
|
|
567
|
-
week.setAttribute("aria-label", `Week ${number}`);
|
|
568
|
-
week.textContent = pad(number);
|
|
569
|
-
row.append(week);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
for (let offset = 0; offset < 7; offset += 1) {
|
|
573
|
-
const date = new Date(rowStart);
|
|
574
|
-
date.setUTCDate(date.getUTCDate() + offset);
|
|
575
|
-
const year = date.getUTCFullYear();
|
|
576
|
-
const month = date.getUTCMonth();
|
|
577
|
-
const day = date.getUTCDate();
|
|
578
|
-
const value = isoDate(year, month, day);
|
|
579
|
-
const currentMonth = year === state.year && month === state.month;
|
|
580
|
-
const selected = isSelected(state, value);
|
|
581
|
-
const disabled = !currentMonth || isDisabled(state, value);
|
|
582
|
-
const current = value === state.today;
|
|
583
|
-
|
|
584
|
-
const cell = document.createElement("td");
|
|
585
|
-
cell.setAttribute("role", "gridcell");
|
|
586
|
-
cell.setAttribute("aria-selected", String(selected));
|
|
587
|
-
|
|
588
|
-
const button = document.createElement("button");
|
|
589
|
-
button.type = "button";
|
|
590
|
-
button.setAttribute("data-date", value);
|
|
591
|
-
button.setAttribute("aria-label", dayLabel(state.locale, value));
|
|
592
|
-
button.setAttribute("tabindex", value === focus ? "0" : "-1");
|
|
593
|
-
if (disabled) button.setAttribute("aria-disabled", "true");
|
|
594
|
-
if (current) button.setAttribute("aria-current", "date");
|
|
595
|
-
button.textContent = String(day);
|
|
596
|
-
|
|
597
|
-
cell.append(button);
|
|
598
|
-
row.append(cell);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
tbody.append(row);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
const caption = table.querySelector("caption");
|
|
605
|
-
if (caption) {
|
|
606
|
-
caption.textContent = monthLabel(state.locale, state.year, state.month);
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
const title = calendar.querySelector(
|
|
610
|
-
":scope > header > [data-slot='title']"
|
|
611
|
-
);
|
|
612
|
-
if (title) {
|
|
613
|
-
title.textContent = monthLabel(state.locale, state.year, state.month);
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
const monthSelect = calendar.querySelector(
|
|
617
|
-
"[data-slot='month'], select[aria-label='Month']"
|
|
618
|
-
);
|
|
619
|
-
if (monthSelect instanceof HTMLSelectElement) {
|
|
620
|
-
const monthFormatter = new Intl.DateTimeFormat(latin(state.locale), {
|
|
621
|
-
month: "long",
|
|
622
|
-
timeZone: "UTC"
|
|
623
|
-
});
|
|
624
|
-
const namesByMonth = Array.from({ length: 12 }, (_, index) =>
|
|
625
|
-
monthFormatter.format(new Date(Date.UTC(2024, index, 1)))
|
|
626
|
-
);
|
|
627
|
-
|
|
628
|
-
if (monthSelect.options.length !== 12) {
|
|
629
|
-
monthSelect.replaceChildren();
|
|
630
|
-
for (let index = 0; index < 12; index += 1) {
|
|
631
|
-
const option = document.createElement("option");
|
|
632
|
-
option.value = String(index + 1);
|
|
633
|
-
option.textContent = namesByMonth[index] ?? "";
|
|
634
|
-
monthSelect.append(option);
|
|
635
|
-
}
|
|
636
|
-
} else {
|
|
637
|
-
for (let index = 0; index < 12; index += 1) {
|
|
638
|
-
const option = monthSelect.options[index];
|
|
639
|
-
if (!option) continue;
|
|
640
|
-
option.value = String(index + 1);
|
|
641
|
-
option.textContent = namesByMonth[index] ?? "";
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
monthSelect.value = String(state.month + 1);
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
const yearSelect = calendar.querySelector(
|
|
648
|
-
"[data-slot='year'], select[aria-label='Year']"
|
|
649
|
-
);
|
|
650
|
-
if (yearSelect instanceof HTMLSelectElement) {
|
|
651
|
-
const value = String(state.year);
|
|
652
|
-
if (![...yearSelect.options].some((option) => option.value === value)) {
|
|
653
|
-
const option = document.createElement("option");
|
|
654
|
-
option.value = value;
|
|
655
|
-
option.textContent = value;
|
|
656
|
-
yearSelect.append(option);
|
|
657
|
-
}
|
|
658
|
-
yearSelect.value = value;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
calendar.setAttribute("data-month", `${state.year}-${pad(state.month + 1)}`);
|
|
662
|
-
|
|
663
|
-
const target = calendar.querySelector(`button[data-date="${focus}"]`);
|
|
664
|
-
if (target instanceof HTMLElement) {
|
|
665
|
-
target.focus({ preventScroll: true });
|
|
666
|
-
target.scrollIntoView({ block: "nearest" });
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
* @param {Element} calendar
|
|
672
|
-
* @param {CalendarState} state
|
|
673
|
-
* @param {string} value
|
|
674
|
-
*/
|
|
675
|
-
function moveFocus(calendar, state, value) {
|
|
676
|
-
const parsed = parseDate(value);
|
|
677
|
-
if (!parsed) return;
|
|
678
|
-
|
|
679
|
-
if (parsed.year !== state.year || parsed.month !== state.month) {
|
|
680
|
-
state.year = parsed.year;
|
|
681
|
-
state.month = parsed.month;
|
|
682
|
-
render(calendar, state, value);
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
state.focused = value;
|
|
687
|
-
setRovingTabindex(calendar, value);
|
|
688
|
-
const target = calendar.querySelector(`button[data-date="${value}"]`);
|
|
689
|
-
if (target instanceof HTMLElement) {
|
|
690
|
-
target.focus({ preventScroll: true });
|
|
691
|
-
target.scrollIntoView({ block: "nearest" });
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
/**
|
|
696
|
-
* @param {Element} calendar
|
|
697
|
-
* @param {CalendarState} state
|
|
698
|
-
* @param {number} months
|
|
699
|
-
*/
|
|
700
|
-
function shiftMonth(calendar, state, months) {
|
|
701
|
-
const date = new Date(Date.UTC(state.year, state.month + months, 1));
|
|
702
|
-
state.year = date.getUTCFullYear();
|
|
703
|
-
state.month = date.getUTCMonth();
|
|
704
|
-
const focus =
|
|
705
|
-
state.focused && sameMonth(state.focused, state.year, state.month)
|
|
706
|
-
? state.focused
|
|
707
|
-
: isoDate(state.year, state.month, 1);
|
|
708
|
-
render(calendar, state, focus);
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
on("focusin", ".calendar", (event, element) => {
|
|
712
|
-
if (!(element instanceof HTMLElement)) return;
|
|
713
|
-
const state = ensure(element);
|
|
714
|
-
if (!state) return;
|
|
715
|
-
if (!(event.target instanceof HTMLElement)) return;
|
|
716
|
-
if (!event.target.matches(DAY_SELECTOR)) return;
|
|
717
|
-
const value = event.target.getAttribute("data-date");
|
|
718
|
-
if (value && parseDate(value)) state.focused = value;
|
|
719
|
-
});
|
|
720
|
-
|
|
721
|
-
on("click", ".calendar button[data-date]", (event, element) => {
|
|
722
|
-
if (!(element instanceof HTMLElement)) return;
|
|
723
|
-
const calendar = element.closest(".calendar");
|
|
724
|
-
if (!(calendar instanceof HTMLElement)) return;
|
|
725
|
-
const value = element.getAttribute("data-date");
|
|
726
|
-
if (!value) return;
|
|
727
|
-
|
|
728
|
-
const state = ensure(calendar);
|
|
729
|
-
if (!state) return;
|
|
730
|
-
const parsed = parseDate(value);
|
|
731
|
-
if (
|
|
732
|
-
!parsed ||
|
|
733
|
-
parsed.year !== state.year ||
|
|
734
|
-
parsed.month !== state.month ||
|
|
735
|
-
isDisabled(state, value)
|
|
736
|
-
) {
|
|
737
|
-
event.preventDefault();
|
|
738
|
-
return true;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
selectDate(calendar, state, value, event instanceof MouseEvent && event.shiftKey);
|
|
742
|
-
render(calendar, state, value);
|
|
743
|
-
event.preventDefault();
|
|
744
|
-
return true;
|
|
745
|
-
});
|
|
746
|
-
|
|
747
|
-
on(
|
|
748
|
-
"click",
|
|
749
|
-
".calendar [data-slot='previous'], .calendar [data-slot='next']",
|
|
750
|
-
(event, element) => {
|
|
751
|
-
if (!(element instanceof HTMLElement)) return;
|
|
752
|
-
const calendar = element.closest(".calendar");
|
|
753
|
-
if (!(calendar instanceof HTMLElement)) return;
|
|
754
|
-
const state = ensure(calendar);
|
|
755
|
-
if (!state) return;
|
|
756
|
-
shiftMonth(
|
|
757
|
-
calendar,
|
|
758
|
-
state,
|
|
759
|
-
element.getAttribute("data-slot") === "next" ? 1 : -1
|
|
760
|
-
);
|
|
761
|
-
event.preventDefault();
|
|
762
|
-
return true;
|
|
763
|
-
}
|
|
764
|
-
);
|
|
765
|
-
|
|
766
|
-
on(
|
|
767
|
-
"change",
|
|
768
|
-
".calendar [data-slot='month'], .calendar [data-slot='year']",
|
|
769
|
-
(_event, element) => {
|
|
770
|
-
if (!(element instanceof HTMLElement)) return;
|
|
771
|
-
const calendar = element.closest(".calendar");
|
|
772
|
-
if (!(calendar instanceof HTMLElement)) return;
|
|
773
|
-
const state = ensure(calendar);
|
|
774
|
-
if (!state) return;
|
|
775
|
-
const monthSelect = calendar.querySelector(
|
|
776
|
-
"[data-slot='month'], select[aria-label='Month']"
|
|
777
|
-
);
|
|
778
|
-
const yearSelect = calendar.querySelector(
|
|
779
|
-
"[data-slot='year'], select[aria-label='Year']"
|
|
780
|
-
);
|
|
781
|
-
|
|
782
|
-
if (monthSelect instanceof HTMLSelectElement) {
|
|
783
|
-
const month = Number(monthSelect.value) - 1;
|
|
784
|
-
if (Number.isInteger(month) && month >= 0 && month < 12) {
|
|
785
|
-
state.month = month;
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
if (yearSelect instanceof HTMLSelectElement) {
|
|
789
|
-
const year = Number(yearSelect.value);
|
|
790
|
-
if (Number.isInteger(year)) state.year = year;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
render(calendar, state, isoDate(state.year, state.month, 1));
|
|
794
|
-
}
|
|
795
|
-
);
|
|
796
|
-
|
|
797
|
-
on("keydown", ".calendar", (event, element) => {
|
|
798
|
-
if (!(event instanceof KeyboardEvent)) return;
|
|
799
|
-
if (!(element instanceof HTMLElement)) return;
|
|
800
|
-
if (!(event.target instanceof HTMLElement)) return;
|
|
801
|
-
if (!event.target.matches(DAY_SELECTOR)) return;
|
|
802
|
-
|
|
803
|
-
const value = event.target.getAttribute("data-date");
|
|
804
|
-
if (!value) return;
|
|
805
|
-
const parsed = parseDate(value);
|
|
806
|
-
if (!parsed) return;
|
|
807
|
-
|
|
808
|
-
const calendar = element;
|
|
809
|
-
const state = ensure(calendar);
|
|
810
|
-
if (!state) return;
|
|
811
|
-
const rtl = isRTL(calendar);
|
|
812
|
-
let next = value;
|
|
813
|
-
|
|
814
|
-
if (event.key === "ArrowRight") {
|
|
815
|
-
next = addDays(value, rtl ? -1 : 1);
|
|
816
|
-
} else if (event.key === "ArrowLeft") {
|
|
817
|
-
next = addDays(value, rtl ? 1 : -1);
|
|
818
|
-
} else if (event.key === "ArrowDown") {
|
|
819
|
-
next = addDays(value, 7);
|
|
820
|
-
} else if (event.key === "ArrowUp") {
|
|
821
|
-
next = addDays(value, -7);
|
|
822
|
-
} else if (event.key === "Home" || event.key === "End") {
|
|
823
|
-
const offset =
|
|
824
|
-
(weekdayOf(parsed.year, parsed.month, parsed.day) -
|
|
825
|
-
(state.weekOrder[0] ?? 0) +
|
|
826
|
-
7) %
|
|
827
|
-
7;
|
|
828
|
-
const day =
|
|
829
|
-
event.key === "Home"
|
|
830
|
-
? Math.max(1, parsed.day - offset)
|
|
831
|
-
: Math.min(daysInMonth(parsed.year, parsed.month), parsed.day + (6 - offset));
|
|
832
|
-
next = isoDate(parsed.year, parsed.month, day);
|
|
833
|
-
} else if (event.key === "PageUp" || event.key === "PageDown") {
|
|
834
|
-
const direction = event.key === "PageDown" ? 1 : -1;
|
|
835
|
-
const target = new Date(
|
|
836
|
-
Date.UTC(
|
|
837
|
-
parsed.year + (event.shiftKey ? direction : 0),
|
|
838
|
-
parsed.month + (event.shiftKey ? 0 : direction),
|
|
839
|
-
1
|
|
840
|
-
)
|
|
841
|
-
);
|
|
842
|
-
const year = target.getUTCFullYear();
|
|
843
|
-
const month = target.getUTCMonth();
|
|
844
|
-
const day = Math.min(parsed.day, daysInMonth(year, month));
|
|
845
|
-
next = isoDate(year, month, day);
|
|
846
|
-
} else {
|
|
847
|
-
return;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
event.preventDefault();
|
|
851
|
-
moveFocus(calendar, state, next);
|
|
852
|
-
return true;
|
|
853
|
-
});
|
|
854
|
-
|
|
855
|
-
init();
|