@auvyx/ui 0.0.0-stage → 0.1.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 +48 -0
- package/README.md +43 -2
- package/dist/auvyx.bundle.css +5941 -0
- package/dist/auvyx.chart.min.js +2 -0
- package/dist/auvyx.corners.min.js +2 -0
- package/dist/auvyx.css +10880 -0
- package/dist/auvyx.js +3222 -0
- package/dist/auvyx.min.css +2 -0
- package/dist/auvyx.min.js +19 -0
- package/dist/custom-elements.json +948 -0
- package/dist/elements/calendar.min.js +2 -0
- package/dist/elements/context-menu.min.js +2 -0
- package/dist/elements/data-table.min.js +2 -0
- package/dist/elements/date-picker.min.js +2 -0
- package/dist/elements/index.min.js +2 -0
- package/dist/elements/menu.min.js +2 -0
- package/dist/elements/resizable.min.js +2 -0
- package/dist/js/accordion.min.js +2 -0
- package/dist/js/calendar.min.js +2 -0
- package/dist/js/combobox.min.js +2 -0
- package/dist/js/command.min.js +2 -0
- package/dist/js/context-menu.min.js +2 -0
- package/dist/js/copy.min.js +2 -0
- package/dist/js/data-table.min.js +2 -0
- package/dist/js/date-picker.min.js +2 -0
- package/dist/js/drawer.min.js +2 -0
- package/dist/js/dropdown-menu.min.js +2 -0
- package/dist/js/manifest.json +114 -0
- package/dist/js/menu.min.js +2 -0
- package/dist/js/popover.min.js +2 -0
- package/dist/js/resizable.min.js +2 -0
- package/dist/js/select.min.js +2 -0
- package/dist/js/sidebar.min.js +2 -0
- package/dist/js/slider.min.js +2 -0
- package/dist/js/tabs.min.js +2 -0
- package/dist/js/toast.min.js +19 -0
- package/dist/styles/auvyx-luma.min.css +3 -0
- package/dist/styles/auvyx-lyra.min.css +3 -0
- package/dist/styles/auvyx-maia.min.css +3 -0
- package/dist/styles/auvyx-mira.min.css +3 -0
- package/dist/styles/auvyx-nova.min.css +3 -0
- package/dist/styles/auvyx-rhea.min.css +3 -0
- package/dist/styles/auvyx-sera.min.css +3 -0
- package/dist/styles/auvyx-vega.min.css +3 -0
- package/dist/types/elements.d.ts +262 -0
- package/dist/types/react.d.ts +181 -0
- package/dist/types/vue.d.ts +155 -0
- package/dist/ui/accordion.css +91 -0
- package/dist/ui/accordion.js +249 -0
- package/dist/ui/accordion.native.css +24 -0
- package/dist/ui/alert.css +119 -0
- package/dist/ui/aspect-ratio.css +38 -0
- package/dist/ui/attachment.css +211 -0
- package/dist/ui/avatar.css +204 -0
- package/dist/ui/badge.css +183 -0
- package/dist/ui/base.css +1200 -0
- package/dist/ui/breadcrumb.css +90 -0
- package/dist/ui/bubble.css +171 -0
- package/dist/ui/button-group.css +110 -0
- package/dist/ui/button.css +328 -0
- package/dist/ui/calendar.css +260 -0
- package/dist/ui/calendar.js +317 -0
- package/dist/ui/card.css +126 -0
- package/dist/ui/carousel.css +172 -0
- package/dist/ui/chart.css +130 -0
- package/dist/ui/checkbox.css +119 -0
- package/dist/ui/code-block.css +235 -0
- package/dist/ui/combobox.css +500 -0
- package/dist/ui/combobox.js +757 -0
- package/dist/ui/command.css +366 -0
- package/dist/ui/command.js +382 -0
- package/dist/ui/context-menu.css +17 -0
- package/dist/ui/context-menu.js +52 -0
- package/dist/ui/copy.js +56 -0
- package/dist/ui/data-table.css +114 -0
- package/dist/ui/data-table.js +140 -0
- package/dist/ui/date-picker.css +14 -0
- package/dist/ui/date-picker.js +101 -0
- package/dist/ui/dialog.css +363 -0
- package/dist/ui/dialog.native.css +6 -0
- package/dist/ui/drawer.css +238 -0
- package/dist/ui/drawer.js +265 -0
- package/dist/ui/dropdown-menu.css +193 -0
- package/dist/ui/dropdown-menu.js +388 -0
- package/dist/ui/empty.css +111 -0
- package/dist/ui/field.css +293 -0
- package/dist/ui/hover-card.css +85 -0
- package/dist/ui/input-group.css +269 -0
- package/dist/ui/input-otp.css +101 -0
- package/dist/ui/input.css +117 -0
- package/dist/ui/item.css +223 -0
- package/dist/ui/kbd.css +50 -0
- package/dist/ui/label.css +48 -0
- package/dist/ui/manifest.json +667 -0
- package/dist/ui/marker.css +66 -0
- package/dist/ui/menu.js +161 -0
- package/dist/ui/menubar.css +55 -0
- package/dist/ui/message-scroller.css +83 -0
- package/dist/ui/message.css +69 -0
- package/dist/ui/native-select.css +130 -0
- package/dist/ui/navigation-menu.css +166 -0
- package/dist/ui/popover.css +154 -0
- package/dist/ui/popover.js +268 -0
- package/dist/ui/popover.native.css +84 -0
- package/dist/ui/progress.css +29 -0
- package/dist/ui/questionnaire.css +188 -0
- package/dist/ui/radio-group.css +115 -0
- package/dist/ui/resizable.css +94 -0
- package/dist/ui/resizable.js +95 -0
- package/dist/ui/scroll-area.css +43 -0
- package/dist/ui/select.css +289 -0
- package/dist/ui/select.js +646 -0
- package/dist/ui/sheet.css +219 -0
- package/dist/ui/sidebar.css +716 -0
- package/dist/ui/sidebar.js +287 -0
- package/dist/ui/skeleton.css +13 -0
- package/dist/ui/slider.css +184 -0
- package/dist/ui/slider.js +206 -0
- package/dist/ui/switch.css +156 -0
- package/dist/ui/table.css +157 -0
- package/dist/ui/tabs.css +240 -0
- package/dist/ui/tabs.js +288 -0
- package/dist/ui/textarea.css +91 -0
- package/dist/ui/toast.css +110 -0
- package/dist/ui/toast.js +378 -0
- package/dist/ui/toggle-group.css +42 -0
- package/dist/ui/toggle.css +150 -0
- package/dist/ui/tooltip.css +319 -0
- package/dist/ui/trace.css +142 -0
- package/dist/ui/typography.css +184 -0
- package/dist/wc/accordion.min.js +2 -0
- package/dist/wc/combobox.min.js +2 -0
- package/dist/wc/command.min.js +2 -0
- package/dist/wc/drawer.min.js +2 -0
- package/dist/wc/dropdown-menu.min.js +2 -0
- package/dist/wc/manifest.json +154 -0
- package/dist/wc/popover.min.js +2 -0
- package/dist/wc/select.min.js +2 -0
- package/dist/wc/sidebar.min.js +2 -0
- package/dist/wc/slider.min.js +2 -0
- package/dist/wc/tabs.min.js +2 -0
- package/dist/wc/toast.min.js +19 -0
- package/package.json +62 -4
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/* @auvyx/ui calendar | order 57 */
|
|
2
|
+
@layer components {
|
|
3
|
+
.calendar {
|
|
4
|
+
--cell-size: 2rem;
|
|
5
|
+
display: inline-block;
|
|
6
|
+
width: fit-content;
|
|
7
|
+
}
|
|
8
|
+
.calendar-months {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-wrap: wrap;
|
|
11
|
+
gap: calc(var(--spacing) * 4);
|
|
12
|
+
}
|
|
13
|
+
.calendar-month {
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
> header {
|
|
17
|
+
position: relative;
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: space-between;
|
|
21
|
+
gap: var(--spacing);
|
|
22
|
+
block-size: var(--cell-size);
|
|
23
|
+
> h2 {
|
|
24
|
+
margin: 0;
|
|
25
|
+
flex: 1;
|
|
26
|
+
text-align: center;
|
|
27
|
+
-webkit-user-select: none;
|
|
28
|
+
user-select: none;
|
|
29
|
+
}
|
|
30
|
+
> button, > span:empty {
|
|
31
|
+
display: inline-flex;
|
|
32
|
+
flex: none;
|
|
33
|
+
align-items: center;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
--tw-outline-style: none;
|
|
36
|
+
outline-style: none;
|
|
37
|
+
-webkit-user-select: none;
|
|
38
|
+
user-select: none;
|
|
39
|
+
inline-size: var(--cell-size);
|
|
40
|
+
block-size: var(--cell-size);
|
|
41
|
+
}
|
|
42
|
+
> button > svg {
|
|
43
|
+
width: calc(var(--spacing) * 4);
|
|
44
|
+
height: calc(var(--spacing) * 4);
|
|
45
|
+
&:where(:dir(rtl), [dir="rtl"], [dir="rtl"] *) {
|
|
46
|
+
rotate: 180deg;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
> button:disabled {
|
|
50
|
+
pointer-events: none;
|
|
51
|
+
opacity: 50%;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
.calendar-caption {
|
|
55
|
+
display: flex;
|
|
56
|
+
flex: 1;
|
|
57
|
+
align-items: center;
|
|
58
|
+
justify-content: center;
|
|
59
|
+
gap: calc(var(--spacing) * 1.5);
|
|
60
|
+
> select {
|
|
61
|
+
width: auto;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
> table {
|
|
65
|
+
margin-top: calc(var(--spacing) * 2);
|
|
66
|
+
border-collapse: collapse;
|
|
67
|
+
th {
|
|
68
|
+
padding: 0;
|
|
69
|
+
--tw-font-weight: var(--font-weight-normal);
|
|
70
|
+
font-weight: var(--font-weight-normal);
|
|
71
|
+
-webkit-user-select: none;
|
|
72
|
+
user-select: none;
|
|
73
|
+
inline-size: var(--cell-size);
|
|
74
|
+
}
|
|
75
|
+
td {
|
|
76
|
+
position: relative;
|
|
77
|
+
padding: 0;
|
|
78
|
+
text-align: center;
|
|
79
|
+
block-size: var(--cell-size);
|
|
80
|
+
}
|
|
81
|
+
td > button {
|
|
82
|
+
display: inline-flex;
|
|
83
|
+
flex-direction: column;
|
|
84
|
+
align-items: center;
|
|
85
|
+
justify-content: center;
|
|
86
|
+
--tw-numeric-spacing: tabular-nums;
|
|
87
|
+
font-variant-numeric: var(--tw-ordinal,) var(--tw-slashed-zero,) var(--tw-numeric-figure,) var(--tw-numeric-spacing,) var(--tw-numeric-fraction,);
|
|
88
|
+
--tw-outline-style: none;
|
|
89
|
+
outline-style: none;
|
|
90
|
+
-webkit-user-select: none;
|
|
91
|
+
user-select: none;
|
|
92
|
+
inline-size: var(--cell-size);
|
|
93
|
+
min-block-size: var(--cell-size);
|
|
94
|
+
> small {
|
|
95
|
+
display: block;
|
|
96
|
+
--tw-leading: 1;
|
|
97
|
+
line-height: 1;
|
|
98
|
+
}
|
|
99
|
+
&:disabled {
|
|
100
|
+
pointer-events: none;
|
|
101
|
+
opacity: 50%;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
td[data-booked] > button {
|
|
105
|
+
text-decoration-line: line-through;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
.date-picker {
|
|
110
|
+
position: relative;
|
|
111
|
+
display: inline-flex;
|
|
112
|
+
> input[type='date'][hidden] {
|
|
113
|
+
display: none;
|
|
114
|
+
}
|
|
115
|
+
> button:first-child {
|
|
116
|
+
justify-content: flex-start;
|
|
117
|
+
text-align: start;
|
|
118
|
+
}
|
|
119
|
+
> [data-popover] {
|
|
120
|
+
width: auto;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@layer components {
|
|
126
|
+
.calendar {
|
|
127
|
+
padding: calc(var(--spacing) * 3);
|
|
128
|
+
}
|
|
129
|
+
.calendar-month > header > h2 {
|
|
130
|
+
font-size: var(--text-sm);
|
|
131
|
+
line-height: var(--tw-leading, var(--text-sm--line-height));
|
|
132
|
+
--tw-font-weight: var(--font-weight-medium);
|
|
133
|
+
font-weight: var(--font-weight-medium);
|
|
134
|
+
}
|
|
135
|
+
.calendar-month > header > button {
|
|
136
|
+
border-radius: var(--auvyx-r-control);
|
|
137
|
+
&:hover {
|
|
138
|
+
@media (hover: hover) {
|
|
139
|
+
background-color: var(--color-muted);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
&:focus-visible {
|
|
143
|
+
--tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(3px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);
|
|
144
|
+
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
|
145
|
+
}
|
|
146
|
+
&:focus-visible {
|
|
147
|
+
--tw-ring-color: var(--color-ring);
|
|
148
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
149
|
+
--tw-ring-color: color-mix(in oklab, var(--color-ring) 50%, transparent);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
.calendar-month .calendar-caption > select {
|
|
154
|
+
height: calc(var(--spacing) * 8);
|
|
155
|
+
padding-block: 0;
|
|
156
|
+
font-size: var(--text-sm);
|
|
157
|
+
line-height: var(--tw-leading, var(--text-sm--line-height));
|
|
158
|
+
--tw-font-weight: var(--font-weight-medium);
|
|
159
|
+
font-weight: var(--font-weight-medium);
|
|
160
|
+
}
|
|
161
|
+
.calendar-month > table th {
|
|
162
|
+
padding-bottom: var(--spacing);
|
|
163
|
+
font-size: 0.8rem;
|
|
164
|
+
color: var(--color-muted-foreground);
|
|
165
|
+
}
|
|
166
|
+
.calendar-month > table th[data-week-number] {
|
|
167
|
+
padding-inline-end: var(--spacing);
|
|
168
|
+
padding-bottom: 0;
|
|
169
|
+
vertical-align: middle;
|
|
170
|
+
font-size: 0.75rem;
|
|
171
|
+
color: var(--color-muted-foreground);
|
|
172
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
173
|
+
color: color-mix(in oklab, var(--color-muted-foreground) 70%, transparent);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
.calendar-month > table td > button {
|
|
177
|
+
border-radius: var(--auvyx-r-control);
|
|
178
|
+
font-size: var(--text-sm);
|
|
179
|
+
line-height: var(--tw-leading, var(--text-sm--line-height));
|
|
180
|
+
--tw-font-weight: var(--font-weight-normal);
|
|
181
|
+
font-weight: var(--font-weight-normal);
|
|
182
|
+
&:hover {
|
|
183
|
+
@media (hover: hover) {
|
|
184
|
+
background-color: var(--color-muted);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
&:focus-visible {
|
|
188
|
+
position: relative;
|
|
189
|
+
}
|
|
190
|
+
&:focus-visible {
|
|
191
|
+
z-index: 10;
|
|
192
|
+
}
|
|
193
|
+
&:focus-visible {
|
|
194
|
+
--tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(3px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);
|
|
195
|
+
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
|
196
|
+
}
|
|
197
|
+
&:focus-visible {
|
|
198
|
+
--tw-ring-color: var(--color-ring);
|
|
199
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
200
|
+
--tw-ring-color: color-mix(in oklab, var(--color-ring) 50%, transparent);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
.calendar-month > table td > button > small {
|
|
205
|
+
margin-top: calc(var(--spacing) * 0.5);
|
|
206
|
+
font-size: 0.625rem;
|
|
207
|
+
color: var(--color-muted-foreground);
|
|
208
|
+
}
|
|
209
|
+
.calendar-month > table td[data-outside] > button {
|
|
210
|
+
color: var(--color-muted-foreground);
|
|
211
|
+
}
|
|
212
|
+
.calendar-month > table td > button[aria-current='date'] {
|
|
213
|
+
background-color: var(--color-muted);
|
|
214
|
+
color: var(--color-foreground);
|
|
215
|
+
}
|
|
216
|
+
.calendar-month > table td:is([aria-selected='true'], [data-range-start], [data-range-end]) > button {
|
|
217
|
+
background-color: var(--color-primary);
|
|
218
|
+
color: var(--color-primary-foreground);
|
|
219
|
+
&:hover {
|
|
220
|
+
@media (hover: hover) {
|
|
221
|
+
background-color: var(--color-primary);
|
|
222
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
223
|
+
background-color: color-mix(in oklab, var(--color-primary) 90%, transparent);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
.calendar-month > table td:is([aria-selected='true'], [data-range-start], [data-range-end]) > button > small {
|
|
229
|
+
color: var(--color-primary-foreground);
|
|
230
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
231
|
+
color: color-mix(in oklab, var(--color-primary-foreground) 80%, transparent);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
.calendar-month > table td[data-range-middle] {
|
|
235
|
+
background-color: var(--color-muted);
|
|
236
|
+
}
|
|
237
|
+
.calendar-month > table td[data-range-middle] > button {
|
|
238
|
+
border-radius: 0;
|
|
239
|
+
background-color: transparent;
|
|
240
|
+
color: var(--color-foreground);
|
|
241
|
+
&:hover {
|
|
242
|
+
@media (hover: hover) {
|
|
243
|
+
background-color: var(--color-accent);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
.calendar-month > table td[data-range-middle] > button > small {
|
|
248
|
+
color: var(--color-muted-foreground);
|
|
249
|
+
}
|
|
250
|
+
.calendar-month > table td[data-range-start]:not([data-range-end]) {
|
|
251
|
+
border-start-start-radius: var(--auvyx-r-control);
|
|
252
|
+
border-end-start-radius: var(--auvyx-r-control);
|
|
253
|
+
background-color: var(--color-muted);
|
|
254
|
+
}
|
|
255
|
+
.calendar-month > table td[data-range-end]:not([data-range-start]) {
|
|
256
|
+
border-start-end-radius: var(--auvyx-r-control);
|
|
257
|
+
border-end-end-radius: var(--auvyx-r-control);
|
|
258
|
+
background-color: var(--color-muted);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/* @auvyx/ui v0.1.0 | MIT | based on Basecoat (MIT) */
|
|
2
|
+
(() => {
|
|
3
|
+
// ../elements/src/calendar.js
|
|
4
|
+
var pad = (n) => String(n).padStart(2, "0");
|
|
5
|
+
var toISO = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
6
|
+
var fromISO = (s) => {
|
|
7
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec((s || "").trim());
|
|
8
|
+
return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null;
|
|
9
|
+
};
|
|
10
|
+
var dayKey = (d) => d.getFullYear() * 1e4 + d.getMonth() * 100 + d.getDate();
|
|
11
|
+
var sameDay = (a, b) => !!a && !!b && dayKey(a) === dayKey(b);
|
|
12
|
+
var addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
|
|
13
|
+
var addMonths = (d, n) => {
|
|
14
|
+
const last = new Date(d.getFullYear(), d.getMonth() + n + 1, 0).getDate();
|
|
15
|
+
return new Date(d.getFullYear(), d.getMonth() + n, Math.min(d.getDate(), last));
|
|
16
|
+
};
|
|
17
|
+
var monthStart = (d) => new Date(d.getFullYear(), d.getMonth(), 1);
|
|
18
|
+
var daysBetween = (a, b) => Math.round((new Date(b.getFullYear(), b.getMonth(), b.getDate()) - new Date(a.getFullYear(), a.getMonth(), a.getDate())) / 864e5);
|
|
19
|
+
var isoWeek = (d) => {
|
|
20
|
+
const t = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
|
|
21
|
+
t.setUTCDate(t.getUTCDate() + 4 - (t.getUTCDay() || 7));
|
|
22
|
+
return Math.ceil(((t - Date.UTC(t.getUTCFullYear(), 0, 1)) / 864e5 + 1) / 7);
|
|
23
|
+
};
|
|
24
|
+
var parseList = (s) => (s || "").split(",").map((x) => x.trim()).filter(Boolean).map((x) => {
|
|
25
|
+
const [a, b] = x.split("/");
|
|
26
|
+
const from = fromISO(a);
|
|
27
|
+
return from ? [from, fromISO(b) || from] : null;
|
|
28
|
+
}).filter(Boolean);
|
|
29
|
+
var inList = (list, d) => list.some(([a, b]) => d >= a && d <= b);
|
|
30
|
+
var chevron = (path) => `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${path}"/></svg>`;
|
|
31
|
+
var esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
|
32
|
+
var AuvyxCalendar = class extends HTMLElement {
|
|
33
|
+
static observedAttributes = ["value", "min", "max", "mode", "months", "month", "disabled-dates", "disabled-days", "booked", "min-days", "max-days", "caption", "week-numbers", "lang"];
|
|
34
|
+
connectedCallback() {
|
|
35
|
+
this.readAll();
|
|
36
|
+
const first = this.selected[0] || this.start || /* @__PURE__ */ new Date();
|
|
37
|
+
this.focused ||= this.clamp(first);
|
|
38
|
+
const m = /^(\d{4})-(\d{2})$/.exec(this.getAttribute("month") || "");
|
|
39
|
+
this.view ||= m ? new Date(+m[1], +m[2] - 1, 1) : monthStart(this.focused);
|
|
40
|
+
if (!this._init) {
|
|
41
|
+
this._init = true;
|
|
42
|
+
this.addEventListener("click", (e) => this.onClick(e));
|
|
43
|
+
this.addEventListener("keydown", (e) => this.onKey(e));
|
|
44
|
+
this.addEventListener("change", (e) => this.onSelectChange(e));
|
|
45
|
+
}
|
|
46
|
+
this.render();
|
|
47
|
+
}
|
|
48
|
+
attributeChangedCallback(name, oldValue, value) {
|
|
49
|
+
if (!this._init || oldValue === value || this._writing) return;
|
|
50
|
+
this.readAll();
|
|
51
|
+
if (name === "value") {
|
|
52
|
+
const first = this.selected[0] || this.start;
|
|
53
|
+
if (first) {
|
|
54
|
+
this.focused = first;
|
|
55
|
+
this.view = monthStart(first);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (name === "month") {
|
|
59
|
+
const m = /^(\d{4})-(\d{2})$/.exec(value || "");
|
|
60
|
+
if (m) this.view = new Date(+m[1], +m[2] - 1, 1);
|
|
61
|
+
}
|
|
62
|
+
this.render();
|
|
63
|
+
}
|
|
64
|
+
// ---- state
|
|
65
|
+
readAll() {
|
|
66
|
+
const mode = this.getAttribute("mode");
|
|
67
|
+
this.mode = mode === "range" || mode === "multiple" ? mode : "single";
|
|
68
|
+
this.monthsShown = Math.max(1, Math.min(12, parseInt(this.getAttribute("months"), 10) || 1));
|
|
69
|
+
this.min = fromISO(this.getAttribute("min"));
|
|
70
|
+
this.max = fromISO(this.getAttribute("max"));
|
|
71
|
+
this.disabledDates = parseList(this.getAttribute("disabled-dates"));
|
|
72
|
+
this.bookedDates = parseList(this.getAttribute("booked"));
|
|
73
|
+
this.disabledDays = (this.getAttribute("disabled-days") || "").split(",").map((x) => parseInt(x, 10)).filter((x) => x >= 0 && x <= 6);
|
|
74
|
+
this.minDays = parseInt(this.getAttribute("min-days"), 10) || 0;
|
|
75
|
+
this.maxDays = parseInt(this.getAttribute("max-days"), 10) || 0;
|
|
76
|
+
const raw = this.getAttribute("value") || "";
|
|
77
|
+
this.start = this.end = null;
|
|
78
|
+
this.selected = [];
|
|
79
|
+
if (this.mode === "range") {
|
|
80
|
+
const [a, b] = raw.split("/");
|
|
81
|
+
this.start = fromISO(a);
|
|
82
|
+
this.end = fromISO(b);
|
|
83
|
+
} else if (this.mode === "multiple") {
|
|
84
|
+
this.selected = raw.split(",").map(fromISO).filter(Boolean);
|
|
85
|
+
} else {
|
|
86
|
+
this.start = fromISO(raw);
|
|
87
|
+
if (this.start) this.selected = [this.start];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
get value() {
|
|
91
|
+
if (this.mode === "range") return this.start ? `${toISO(this.start)}/${this.end ? toISO(this.end) : ""}` : "";
|
|
92
|
+
if (this.mode === "multiple") return this.selected.map(toISO).join(",");
|
|
93
|
+
return this.start ? toISO(this.start) : "";
|
|
94
|
+
}
|
|
95
|
+
set value(v) {
|
|
96
|
+
this.setAttribute("value", v ?? "");
|
|
97
|
+
}
|
|
98
|
+
get dates() {
|
|
99
|
+
if (this.mode === "range") return [this.start, this.end].filter(Boolean);
|
|
100
|
+
return [...this.selected];
|
|
101
|
+
}
|
|
102
|
+
set renderDay(fn) {
|
|
103
|
+
this._renderDay = fn;
|
|
104
|
+
if (this._init) this.render();
|
|
105
|
+
}
|
|
106
|
+
get renderDay() {
|
|
107
|
+
return this._renderDay;
|
|
108
|
+
}
|
|
109
|
+
locale() {
|
|
110
|
+
return this.getAttribute("lang") || this.closest("[lang]")?.getAttribute("lang") || navigator.language;
|
|
111
|
+
}
|
|
112
|
+
weekStart() {
|
|
113
|
+
const n = parseInt(this.dataset.weekStart, 10);
|
|
114
|
+
return Number.isFinite(n) ? (n % 7 + 7) % 7 : 1;
|
|
115
|
+
}
|
|
116
|
+
clamp(d) {
|
|
117
|
+
if (this.min && d < this.min) return this.min;
|
|
118
|
+
if (this.max && d > this.max) return this.max;
|
|
119
|
+
return d;
|
|
120
|
+
}
|
|
121
|
+
isDisabled(d) {
|
|
122
|
+
if (this.min && d < this.min || this.max && d > this.max) return true;
|
|
123
|
+
if (this.disabledDays.includes(d.getDay())) return true;
|
|
124
|
+
if (inList(this.disabledDates, d) || inList(this.bookedDates, d)) return true;
|
|
125
|
+
if (this.mode === "range" && this.start && !this.end && d > this.start) {
|
|
126
|
+
const len = daysBetween(this.start, d) + 1;
|
|
127
|
+
if (this.minDays && len < this.minDays) return true;
|
|
128
|
+
if (this.maxDays && len > this.maxDays) return true;
|
|
129
|
+
for (let x = addDays(this.start, 1); x < d; x = addDays(x, 1)) {
|
|
130
|
+
if (this.disabledDays.includes(x.getDay()) || inList(this.disabledDates, x) || inList(this.bookedDates, x)) return true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
// ---- rendering
|
|
136
|
+
render() {
|
|
137
|
+
const locale = this.locale();
|
|
138
|
+
const fmtMonth = new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" });
|
|
139
|
+
const fmtMonthOnly = new Intl.DateTimeFormat(locale, { month: "short" });
|
|
140
|
+
const fmtWeekday = new Intl.DateTimeFormat(locale, { weekday: "short" });
|
|
141
|
+
const fmtWeekdayLong = new Intl.DateTimeFormat(locale, { weekday: "long" });
|
|
142
|
+
const fmtDay = new Intl.DateTimeFormat(locale, { dateStyle: "full" });
|
|
143
|
+
const today = /* @__PURE__ */ new Date();
|
|
144
|
+
const ws = this.weekStart();
|
|
145
|
+
const id = this.id || (this._uid ||= `cal-${Math.random().toString(36).slice(2, 8)}`);
|
|
146
|
+
const weekNums = this.hasAttribute("week-numbers");
|
|
147
|
+
const dropdown = this.getAttribute("caption") === "dropdown";
|
|
148
|
+
const prevDisabled = this.min && addMonths(this.view, -1) < monthStart(this.min);
|
|
149
|
+
const nextDisabled = this.max && addMonths(this.view, this.monthsShown) > this.max;
|
|
150
|
+
const hadFocus = this.contains(document.activeElement) && document.activeElement.matches("td > button");
|
|
151
|
+
let html = "";
|
|
152
|
+
for (let m = 0; m < this.monthsShown; m++) {
|
|
153
|
+
const first = addMonths(this.view, m);
|
|
154
|
+
const lead = (first.getDay() - ws + 7) % 7;
|
|
155
|
+
const gridStart = addDays(first, -lead);
|
|
156
|
+
const dim = new Date(first.getFullYear(), first.getMonth() + 1, 0).getDate();
|
|
157
|
+
const weeks = Math.ceil((lead + dim) / 7);
|
|
158
|
+
const titleId = `${id}-title-${m}`;
|
|
159
|
+
let caption = `<h2 id="${titleId}" aria-live="polite">${esc(fmtMonth.format(first))}</h2>`;
|
|
160
|
+
if (dropdown && m === 0) {
|
|
161
|
+
const y0 = (this.min || addMonths(today, -12 * 10)).getFullYear();
|
|
162
|
+
const y1 = (this.max || addMonths(today, 12 * 10)).getFullYear();
|
|
163
|
+
let months = "";
|
|
164
|
+
for (let i = 0; i < 12; i++) {
|
|
165
|
+
const d = new Date(first.getFullYear(), i, 1);
|
|
166
|
+
const off = this.min && new Date(first.getFullYear(), i + 1, 0) < this.min || this.max && d > this.max;
|
|
167
|
+
months += `<option value="${i}"${i === first.getMonth() ? " selected" : ""}${off ? " disabled" : ""}>${esc(fmtMonthOnly.format(d))}</option>`;
|
|
168
|
+
}
|
|
169
|
+
let years = "";
|
|
170
|
+
for (let y = y0; y <= y1; y++) years += `<option value="${y}"${y === first.getFullYear() ? " selected" : ""}>${y}</option>`;
|
|
171
|
+
caption = `<div class="calendar-caption" id="${titleId}" aria-label="${esc(fmtMonth.format(first))}" role="group"><select class="select" data-calendar-month aria-label="${esc(this.dataset.labelMonth || "Month")}">${months}</select><select class="select" data-calendar-year aria-label="${esc(this.dataset.labelYear || "Year")}">${years}</select></div>`;
|
|
172
|
+
}
|
|
173
|
+
const prev = m === 0 ? `<button type="button" data-nav="-1" aria-label="${esc(this.dataset.labelPrev || "Previous month")}"${prevDisabled ? " disabled" : ""}>${chevron("m15 18-6-6 6-6")}</button>` : "<span></span>";
|
|
174
|
+
const next = m === this.monthsShown - 1 ? `<button type="button" data-nav="1" aria-label="${esc(this.dataset.labelNext || "Next month")}"${nextDisabled ? " disabled" : ""}>${chevron("m9 18 6-6-6-6")}</button>` : "<span></span>";
|
|
175
|
+
let head = weekNums ? `<th scope="col" data-week-number><span class="sr-only">${esc(this.dataset.labelWeek || "Week")}</span></th>` : "";
|
|
176
|
+
for (let i = 0; i < 7; i++) {
|
|
177
|
+
const d = addDays(gridStart, i);
|
|
178
|
+
head += `<th scope="col" abbr="${esc(fmtWeekdayLong.format(d))}">${esc(fmtWeekday.format(d))}</th>`;
|
|
179
|
+
}
|
|
180
|
+
let body = "";
|
|
181
|
+
for (let w = 0; w < weeks; w++) {
|
|
182
|
+
body += "<tr>";
|
|
183
|
+
if (weekNums) body += `<th scope="row" data-week-number>${isoWeek(addDays(gridStart, w * 7 + (8 - ws) % 7))}</th>`;
|
|
184
|
+
for (let i = 0; i < 7; i++) {
|
|
185
|
+
const d = addDays(gridStart, w * 7 + i);
|
|
186
|
+
const outside = d.getMonth() !== first.getMonth();
|
|
187
|
+
const hideOutside = outside && this.monthsShown > 1;
|
|
188
|
+
const attrs = [];
|
|
189
|
+
if (outside) attrs.push("data-outside");
|
|
190
|
+
if (inList(this.bookedDates, d)) attrs.push("data-booked");
|
|
191
|
+
if (!hideOutside) {
|
|
192
|
+
if (this.mode !== "range" && this.selected.some((s) => sameDay(s, d))) attrs.push('aria-selected="true"');
|
|
193
|
+
if (this.mode === "range" && this.start) {
|
|
194
|
+
const end = this.end || this.start;
|
|
195
|
+
if (sameDay(d, this.start)) attrs.push("data-range-start");
|
|
196
|
+
if (sameDay(d, end)) attrs.push("data-range-end");
|
|
197
|
+
if (d > this.start && d < end) attrs.push("data-range-middle");
|
|
198
|
+
if (d >= this.start && d <= end) attrs.push('aria-selected="true"');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (hideOutside) {
|
|
202
|
+
body += `<td ${attrs.join(" ")} aria-hidden="true"></td>`;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const tab = sameDay(d, this.focused) && !outside ? "0" : "-1";
|
|
206
|
+
const extra = this._renderDay ? this._renderDay(d) : null;
|
|
207
|
+
body += `<td ${attrs.join(" ")}><button type="button" data-date="${toISO(d)}" tabindex="${tab}" aria-label="${esc(fmtDay.format(d))}"${sameDay(d, today) ? ' aria-current="date"' : ""}${this.isDisabled(d) ? " disabled" : ""}><span>${d.getDate()}</span>${extra ? `<small>${extra}</small>` : ""}</button></td>`;
|
|
208
|
+
}
|
|
209
|
+
body += "</tr>";
|
|
210
|
+
}
|
|
211
|
+
html += `<section class="calendar-month"><header>${prev}${caption}${next}</header><table role="grid" aria-labelledby="${titleId}"${weekNums ? " data-week-numbers" : ""}><thead><tr>${head}</tr></thead><tbody>${body}</tbody></table></section>`;
|
|
212
|
+
}
|
|
213
|
+
const hidden = this.getAttribute("name") ? `<input type="hidden" name="${esc(this.getAttribute("name"))}" value="${esc(this.value)}">` : "";
|
|
214
|
+
this.innerHTML = `<div class="calendar-months">${html}</div>${hidden}`;
|
|
215
|
+
if (!this.querySelector('td > button[tabindex="0"]')) {
|
|
216
|
+
const b = this.querySelector("td:not([data-outside]) > button:not(:disabled)") || this.querySelector("td > button");
|
|
217
|
+
if (b) b.tabIndex = 0;
|
|
218
|
+
}
|
|
219
|
+
if (hadFocus) this.focusDate();
|
|
220
|
+
}
|
|
221
|
+
focusDate() {
|
|
222
|
+
const b = this.querySelector(`td:not([data-outside]) > button[data-date="${toISO(this.focused)}"]`) || this.querySelector('td > button[tabindex="0"]');
|
|
223
|
+
b?.focus({ preventScroll: true });
|
|
224
|
+
}
|
|
225
|
+
goTo(date) {
|
|
226
|
+
const d = typeof date === "string" ? fromISO(date) : date;
|
|
227
|
+
if (!d) return;
|
|
228
|
+
this.view = monthStart(d);
|
|
229
|
+
this.focused = d;
|
|
230
|
+
this.render();
|
|
231
|
+
}
|
|
232
|
+
visible(d) {
|
|
233
|
+
const last = addMonths(this.view, this.monthsShown - 1);
|
|
234
|
+
return d >= this.view && d < addMonths(last, 1);
|
|
235
|
+
}
|
|
236
|
+
moveFocus(d) {
|
|
237
|
+
if (this.min && d < this.min || this.max && d > this.max) return;
|
|
238
|
+
this.focused = d;
|
|
239
|
+
if (!this.visible(d)) {
|
|
240
|
+
this.view = d < this.view ? monthStart(d) : monthStart(addMonths(d, -(this.monthsShown - 1)));
|
|
241
|
+
this.render();
|
|
242
|
+
} else {
|
|
243
|
+
this.querySelectorAll("td > button").forEach((b) => {
|
|
244
|
+
b.tabIndex = b.dataset.date === toISO(d) && !b.closest("[data-outside]") ? 0 : -1;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
this.focusDate();
|
|
248
|
+
}
|
|
249
|
+
select(d) {
|
|
250
|
+
if (this.mode === "range") {
|
|
251
|
+
if (!this.start || this.end || d < this.start) {
|
|
252
|
+
this.start = d;
|
|
253
|
+
this.end = null;
|
|
254
|
+
} else this.end = d;
|
|
255
|
+
} else if (this.mode === "multiple") {
|
|
256
|
+
const i = this.selected.findIndex((s) => sameDay(s, d));
|
|
257
|
+
if (i >= 0) this.selected.splice(i, 1);
|
|
258
|
+
else this.selected.push(d);
|
|
259
|
+
this.selected.sort((a, b) => a - b);
|
|
260
|
+
} else {
|
|
261
|
+
this.start = d;
|
|
262
|
+
this.selected = [d];
|
|
263
|
+
}
|
|
264
|
+
this.focused = d;
|
|
265
|
+
this._writing = true;
|
|
266
|
+
this.setAttribute("value", this.value);
|
|
267
|
+
this._writing = false;
|
|
268
|
+
this.render();
|
|
269
|
+
this.focusDate();
|
|
270
|
+
this.dispatchEvent(new CustomEvent("change", { bubbles: true, detail: { value: this.value, dates: this.dates, complete: this.mode !== "range" || !!this.end } }));
|
|
271
|
+
}
|
|
272
|
+
// ---- events
|
|
273
|
+
onClick(event) {
|
|
274
|
+
const nav = event.target.closest("button[data-nav]");
|
|
275
|
+
if (nav && !nav.disabled) {
|
|
276
|
+
this.view = addMonths(this.view, +nav.dataset.nav);
|
|
277
|
+
const dim = new Date(this.view.getFullYear(), this.view.getMonth() + 1, 0).getDate();
|
|
278
|
+
this.focused = this.clamp(new Date(this.view.getFullYear(), this.view.getMonth(), Math.min(this.focused.getDate(), dim)));
|
|
279
|
+
this.render();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const day = event.target.closest("button[data-date]");
|
|
283
|
+
if (day && !day.disabled) this.select(fromISO(day.dataset.date));
|
|
284
|
+
}
|
|
285
|
+
onSelectChange(event) {
|
|
286
|
+
const t = event.target;
|
|
287
|
+
if (!(t instanceof HTMLSelectElement) || !t.closest(".calendar-caption")) return;
|
|
288
|
+
event.stopPropagation();
|
|
289
|
+
const month = +this.querySelector("[data-calendar-month]").value;
|
|
290
|
+
const year = +this.querySelector("[data-calendar-year]").value;
|
|
291
|
+
this.view = new Date(year, month, 1);
|
|
292
|
+
this.focused = this.clamp(new Date(year, month, Math.min(this.focused.getDate(), new Date(year, month + 1, 0).getDate())));
|
|
293
|
+
this.render();
|
|
294
|
+
this.querySelector(t.hasAttribute("data-calendar-month") ? "[data-calendar-month]" : "[data-calendar-year]")?.focus();
|
|
295
|
+
}
|
|
296
|
+
onKey(event) {
|
|
297
|
+
if (!event.target.matches("td > button")) return;
|
|
298
|
+
const rtl = getComputedStyle(this).direction === "rtl";
|
|
299
|
+
const d = this.focused;
|
|
300
|
+
const offset = (d.getDay() - this.weekStart() + 7) % 7;
|
|
301
|
+
const moves = {
|
|
302
|
+
ArrowLeft: addDays(d, rtl ? 1 : -1),
|
|
303
|
+
ArrowRight: addDays(d, rtl ? -1 : 1),
|
|
304
|
+
ArrowUp: addDays(d, -7),
|
|
305
|
+
ArrowDown: addDays(d, 7),
|
|
306
|
+
Home: addDays(d, -offset),
|
|
307
|
+
End: addDays(d, 6 - offset),
|
|
308
|
+
PageUp: addMonths(d, event.shiftKey ? -12 : -1),
|
|
309
|
+
PageDown: addMonths(d, event.shiftKey ? 12 : 1)
|
|
310
|
+
};
|
|
311
|
+
if (!(event.key in moves)) return;
|
|
312
|
+
event.preventDefault();
|
|
313
|
+
this.moveFocus(moves[event.key]);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
if (!customElements.get("auvyx-calendar")) customElements.define("auvyx-calendar", AuvyxCalendar);
|
|
317
|
+
})();
|