@finstack-com-public/design 0.7.0 → 0.8.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.
@@ -1372,6 +1372,179 @@ export default `@layer fs.tokens, fs.reset, fs.base, fs.components, fs.utilities
1372
1372
  }
1373
1373
  }
1374
1374
 
1375
+ /* Calendar (spec 02 B): year, month and day views. Usage: calendar.md. Behaviour: createCalendar,
1376
+ which renders the header and the grid into an empty .fs-calendar (D42). */
1377
+ @layer fs.components {
1378
+ .fs-calendar {
1379
+ /* One cell's width: seven make the calendar, so it follows the density. */
1380
+ --fs-calendar-cell: var(--fs-control-h);
1381
+ display: inline-flex;
1382
+ flex-direction: column;
1383
+ gap: var(--fs-space-1);
1384
+ box-sizing: content-box;
1385
+ width: calc(7 * var(--fs-calendar-cell));
1386
+ padding: var(--fs-space-2);
1387
+ font-size: var(--fs-text-body-size);
1388
+ line-height: var(--fs-text-body-line);
1389
+ color: var(--fs-ink);
1390
+ }
1391
+
1392
+ .fs-calendar__header {
1393
+ display: flex;
1394
+ align-items: center;
1395
+ gap: var(--fs-space-1);
1396
+ height: var(--fs-control-h);
1397
+ }
1398
+
1399
+ /* Shows the page's heading; steps up a view. In the top view it is the heading alone. */
1400
+ .fs-calendar__view {
1401
+ display: inline-flex;
1402
+ align-items: center;
1403
+ gap: var(--fs-space-1);
1404
+ box-sizing: border-box;
1405
+ min-width: 0;
1406
+ height: var(--fs-control-h);
1407
+ margin: 0 auto 0 0;
1408
+ padding: 0 var(--fs-pad-x);
1409
+ font: inherit;
1410
+ font-weight: var(--fs-weight-semibold);
1411
+ color: var(--fs-ink);
1412
+ white-space: nowrap;
1413
+ background: transparent;
1414
+ border: 0;
1415
+ border-radius: var(--fs-radius-sm);
1416
+ cursor: pointer;
1417
+ }
1418
+ .fs-calendar__view-icon {
1419
+ width: var(--fs-icon-size);
1420
+ height: var(--fs-icon-size);
1421
+ color: var(--fs-ink-2);
1422
+ }
1423
+
1424
+ .fs-calendar__grid {
1425
+ display: grid;
1426
+ align-content: start;
1427
+ /* A six-week month and the 4 × 3 month and year pages are the same height. */
1428
+ min-height: calc(7 * var(--fs-calendar-cell));
1429
+ }
1430
+ .fs-calendar__row {
1431
+ display: grid;
1432
+ grid-template-columns: repeat(3, 1fr);
1433
+ }
1434
+ .fs-calendar__grid--day .fs-calendar__row {
1435
+ grid-template-columns: repeat(7, 1fr);
1436
+ }
1437
+
1438
+ .fs-calendar__weekday {
1439
+ display: grid;
1440
+ place-items: center;
1441
+ height: var(--fs-calendar-cell);
1442
+ font-size: var(--fs-text-xs-size);
1443
+ line-height: var(--fs-text-xs-line);
1444
+ color: var(--fs-ink-muted);
1445
+ }
1446
+
1447
+ .fs-calendar__cell {
1448
+ position: relative;
1449
+ display: grid;
1450
+ place-items: center;
1451
+ box-sizing: border-box;
1452
+ min-width: 0;
1453
+ height: var(--fs-calendar-cell);
1454
+ margin: 0;
1455
+ padding: 0 2px;
1456
+ font: inherit;
1457
+ font-variant-numeric: tabular-nums;
1458
+ color: var(--fs-ink);
1459
+ white-space: nowrap;
1460
+ background: transparent;
1461
+ border: 0;
1462
+ border-radius: var(--fs-radius-sm);
1463
+ cursor: pointer;
1464
+ }
1465
+ .fs-calendar__grid--month .fs-calendar__cell,
1466
+ .fs-calendar__grid--year .fs-calendar__cell {
1467
+ height: calc(1.75 * var(--fs-calendar-cell));
1468
+ }
1469
+
1470
+ @media (hover: hover) {
1471
+ .fs-calendar__view:not([aria-disabled='true']):hover,
1472
+ .fs-calendar__cell:hover {
1473
+ background-color: var(--fs-bg-hover);
1474
+ }
1475
+ .fs-calendar__cell[aria-selected='true']:not([aria-disabled='true']):hover {
1476
+ background-color: var(--fs-primary-bg-hover);
1477
+ }
1478
+ }
1479
+ .fs-calendar__view:not([aria-disabled='true']):active,
1480
+ .fs-calendar__cell:active {
1481
+ background-color: var(--fs-bg-active);
1482
+ }
1483
+
1484
+ /* Today: an edge, not a fill, drawn inside so it never meets a neighbour's. */
1485
+ .fs-calendar__cell[aria-current='date']::after {
1486
+ content: '';
1487
+ position: absolute;
1488
+ inset: 2px;
1489
+ border: var(--fs-line-width) solid var(--fs-accent);
1490
+ border-radius: var(--fs-radius-sm);
1491
+ pointer-events: none;
1492
+ }
1493
+
1494
+ /* Selected: the accent fill and weight 600, so it never rests on colour alone. */
1495
+ .fs-calendar__cell[aria-selected='true'] {
1496
+ font-weight: var(--fs-weight-semibold);
1497
+ color: var(--fs-primary-ink);
1498
+ background-color: var(--fs-primary-bg);
1499
+ }
1500
+ .fs-calendar__cell[aria-selected='true'][aria-current='date']::after {
1501
+ border-color: var(--fs-primary-ink);
1502
+ }
1503
+
1504
+ /* The ring recipe (D15). The header's own button rings outside; cells touch, so theirs is inside. */
1505
+ .fs-calendar__view:focus-visible {
1506
+ outline: var(--fs-ring-width) solid var(--fs-ring);
1507
+ outline-offset: var(--fs-ring-halo-width);
1508
+ box-shadow: 0 0 0 var(--fs-ring-halo-width) var(--fs-ring-halo);
1509
+ }
1510
+ .fs-calendar__cell:focus-visible {
1511
+ z-index: 1;
1512
+ outline: var(--fs-ring-width) solid var(--fs-ring);
1513
+ outline-offset: calc(-1 * var(--fs-ring-width));
1514
+ box-shadow: inset 0 0 0 calc(var(--fs-ring-width) + var(--fs-ring-halo-width)) var(--fs-ring-halo);
1515
+ }
1516
+
1517
+ /* The top view's heading is not a control. */
1518
+ .fs-calendar__view[aria-disabled='true'] {
1519
+ cursor: default;
1520
+ }
1521
+
1522
+ /* Outside min and max: reachable, never pickable. Last, so it beats hover, press and selected. */
1523
+ .fs-calendar__cell[aria-disabled='true'] {
1524
+ color: var(--fs-ink-disabled);
1525
+ background-color: transparent;
1526
+ cursor: not-allowed;
1527
+ }
1528
+
1529
+ /* Forced colours: washes and fills are erased, so the selected cell takes the Highlight pair, today
1530
+ keeps its edge (borders survive, in the system's colour) and disabled is GrayText. */
1531
+ @media (forced-colors: active) {
1532
+ .fs-calendar__cell[aria-selected='true'] {
1533
+ color: HighlightText;
1534
+ background-color: Highlight;
1535
+ }
1536
+ .fs-calendar__cell[aria-current='date']::after {
1537
+ border-color: CanvasText;
1538
+ }
1539
+ .fs-calendar__cell[aria-selected='true'][aria-current='date']::after {
1540
+ border-color: HighlightText;
1541
+ }
1542
+ .fs-calendar__cell[aria-disabled='true'] {
1543
+ color: GrayText;
1544
+ }
1545
+ }
1546
+ }
1547
+
1375
1548
  /* Card: a whole panel that is one link or button (spec 02 D). Usage: card.md. */
1376
1549
  @layer fs.components {
1377
1550
  .fs-card {
@@ -3324,8 +3497,10 @@ export default `@layer fs.tokens, fs.reset, fs.base, fs.components, fs.utilities
3324
3497
  border-color: var(--fs-danger-fill);
3325
3498
  }
3326
3499
 
3327
- /* Read-only: no control edge, the value in full ink. */
3328
- .fs-input:read-only,
3500
+ /* Read-only: no control edge, the value in full ink. \`:read-only\` matches anything not editable, a
3501
+ <button> too, so the picker button is left out (T84); \`:where\` keeps the specificity at (0,2,0), so
3502
+ disabled still wins. */
3503
+ .fs-input:where(:not(.fs-input--picker)):read-only,
3329
3504
  .fs-textarea:read-only {
3330
3505
  background-color: transparent;
3331
3506
  border-color: transparent;
@@ -4259,6 +4434,13 @@ export default `@layer fs.tokens, fs.reset, fs.base, fs.components, fs.utilities
4259
4434
  margin-top: var(--fs-space-3);
4260
4435
  }
4261
4436
 
4437
+ /* Fits its content and leaves the padding to it: a picker's calendar (T84). */
4438
+ .fs-popover--fit {
4439
+ width: max-content;
4440
+ max-width: calc(100vw - 16px);
4441
+ padding: 0;
4442
+ }
4443
+
4262
4444
  /* The ring recipe (D15), when the panel itself takes focus. */
4263
4445
  .fs-popover:focus-visible {
4264
4446
  outline: var(--fs-ring-width) solid var(--fs-ring);
@@ -5976,9 +6158,12 @@ export default `@layer fs.tokens, fs.reset, fs.base, fs.components, fs.utilities
5976
6158
  @layer fs.components {
5977
6159
  /* An empty, aria-hidden band: a wave of dots, cyan at the left to blue at the right. The
5978
6160
  wave is an image (motifs/wave.webp, D33): the owner's ChatGPT image as white on transparent,
5979
- used as a mask over the brand colours, so its colour comes from the roles. It covers the band
5980
- from the bottom up: a band shorter than the image loses the far rows at the top, a narrow one
5981
- the sides. \`--fs-wave-image\` points it at a self-hosted copy. */
6161
+ used as a mask over the brand colours, so its colour comes from the roles. The whole wave
6162
+ shows: the image is fitted to the band's height (its ratio is 5.716), centred and anchored at
6163
+ the bottom. A band narrower than that ratio times its height is filled by the image
6164
+ (\`cover\`: the sides are cropped, never the crest). A wider band gets a box exactly as wide as
6165
+ the image, centred, with both edges fading out instead of ending in a cut. \`--fs-wave-image\`
6166
+ points it at a self-hosted copy (keep the ratio). */
5982
6167
  .fs-wave {
5983
6168
  display: block;
5984
6169
  height: var(--fs-wave-height, 160px);
@@ -5992,9 +6177,21 @@ export default `@layer fs.tokens, fs.reset, fs.base, fs.components, fs.utilities
5992
6177
  content: '';
5993
6178
  display: block;
5994
6179
  height: 100%;
6180
+ /* --fs-wave-height is read here, on the host's own value, so a custom height moves the cap too. */
6181
+ max-width: calc(var(--fs-wave-height, 160px) * 5.716);
6182
+ margin-inline: auto;
5995
6183
  background: linear-gradient(90deg, var(--fs-brand-end), var(--fs-brand-start) 65%);
5996
- -webkit-mask: var(--fs-wave-image, url('${new URL('../motifs/wave.webp', import.meta.url).href}')) center bottom / cover no-repeat;
5997
- mask: var(--fs-wave-image, url('${new URL('../motifs/wave.webp', import.meta.url).href}')) center bottom / cover no-repeat;
6184
+ /* Two mask layers, intersected: the soft right edge, then the image. */
6185
+ -webkit-mask:
6186
+ linear-gradient(90deg, transparent, currentcolor 5%, currentcolor 90%, transparent) center bottom / 100% 100%
6187
+ no-repeat,
6188
+ var(--fs-wave-image, url('${new URL('../motifs/wave.webp', import.meta.url).href}')) center bottom / cover no-repeat;
6189
+ -webkit-mask-composite: source-in;
6190
+ mask:
6191
+ linear-gradient(90deg, transparent, currentcolor 5%, currentcolor 90%, transparent) center bottom / 100% 100%
6192
+ no-repeat,
6193
+ var(--fs-wave-image, url('${new URL('../motifs/wave.webp', import.meta.url).href}')) center bottom / cover no-repeat;
6194
+ mask-composite: intersect;
5998
6195
  }
5999
6196
  /* Decoration: nothing to show in forced colours, nothing to print. */
6000
6197
  @media (forced-colors: active) {
@@ -1 +1 @@
1
- export default "/* Popover (spec 02 D). Usage: popover.md. Behaviour: createPopover. */\n@layer fs.components {\n .fs-popover {\n box-sizing: border-box;\n width: min(var(--fs-size-popover), calc(100vw - 16px));\n inset: auto;\n z-index: var(--fs-z-dropdown);\n margin: 0;\n padding: var(--fs-space-4);\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n color: var(--fs-ink);\n background: var(--fs-bg-surface);\n border: var(--fs-line-width) solid var(--fs-line-strong);\n border-radius: var(--fs-radius-md);\n box-shadow: var(--fs-shadow-2);\n }\n .fs-popover__kicker {\n display: block;\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n font-weight: var(--fs-weight-semibold);\n letter-spacing: var(--fs-tracking-caps);\n text-transform: uppercase;\n color: var(--fs-ink-2);\n }\n .fs-popover__title {\n display: flex;\n align-items: center;\n gap: var(--fs-space-2);\n margin: var(--fs-space-1) 0 var(--fs-space-2);\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n font-weight: var(--fs-weight-semibold);\n color: var(--fs-ink-2);\n }\n .fs-popover__body {\n display: grid;\n gap: var(--fs-space-2);\n color: var(--fs-ink-2);\n }\n .fs-popover__actions {\n display: flex;\n justify-content: flex-end;\n gap: var(--fs-space-2);\n margin-top: var(--fs-space-3);\n }\n\n /* The ring recipe (D15), when the panel itself takes focus. */\n .fs-popover:focus-visible {\n outline: var(--fs-ring-width) solid var(--fs-ring);\n outline-offset: var(--fs-ring-halo-width);\n box-shadow: 0 0 0 var(--fs-ring-halo-width) var(--fs-ring-halo);\n }\n}\n";
1
+ export default "/* Popover (spec 02 D). Usage: popover.md. Behaviour: createPopover. */\n@layer fs.components {\n .fs-popover {\n box-sizing: border-box;\n width: min(var(--fs-size-popover), calc(100vw - 16px));\n inset: auto;\n z-index: var(--fs-z-dropdown);\n margin: 0;\n padding: var(--fs-space-4);\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n color: var(--fs-ink);\n background: var(--fs-bg-surface);\n border: var(--fs-line-width) solid var(--fs-line-strong);\n border-radius: var(--fs-radius-md);\n box-shadow: var(--fs-shadow-2);\n }\n .fs-popover__kicker {\n display: block;\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n font-weight: var(--fs-weight-semibold);\n letter-spacing: var(--fs-tracking-caps);\n text-transform: uppercase;\n color: var(--fs-ink-2);\n }\n .fs-popover__title {\n display: flex;\n align-items: center;\n gap: var(--fs-space-2);\n margin: var(--fs-space-1) 0 var(--fs-space-2);\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n font-weight: var(--fs-weight-semibold);\n color: var(--fs-ink-2);\n }\n .fs-popover__body {\n display: grid;\n gap: var(--fs-space-2);\n color: var(--fs-ink-2);\n }\n .fs-popover__actions {\n display: flex;\n justify-content: flex-end;\n gap: var(--fs-space-2);\n margin-top: var(--fs-space-3);\n }\n\n /* Fits its content and leaves the padding to it: a picker's calendar (T84). */\n .fs-popover--fit {\n width: max-content;\n max-width: calc(100vw - 16px);\n padding: 0;\n }\n\n /* The ring recipe (D15), when the panel itself takes focus. */\n .fs-popover:focus-visible {\n outline: var(--fs-ring-width) solid var(--fs-ring);\n outline-offset: var(--fs-ring-halo-width);\n box-shadow: 0 0 0 var(--fs-ring-halo-width) var(--fs-ring-halo);\n }\n}\n";
@@ -2,9 +2,12 @@ export default `/* Wave (spec 02 I). Usage: wave.md. */
2
2
  @layer fs.components {
3
3
  /* An empty, aria-hidden band: a wave of dots, cyan at the left to blue at the right. The
4
4
  wave is an image (motifs/wave.webp, D33): the owner's ChatGPT image as white on transparent,
5
- used as a mask over the brand colours, so its colour comes from the roles. It covers the band
6
- from the bottom up: a band shorter than the image loses the far rows at the top, a narrow one
7
- the sides. \`--fs-wave-image\` points it at a self-hosted copy. */
5
+ used as a mask over the brand colours, so its colour comes from the roles. The whole wave
6
+ shows: the image is fitted to the band's height (its ratio is 5.716), centred and anchored at
7
+ the bottom. A band narrower than that ratio times its height is filled by the image
8
+ (\`cover\`: the sides are cropped, never the crest). A wider band gets a box exactly as wide as
9
+ the image, centred, with both edges fading out instead of ending in a cut. \`--fs-wave-image\`
10
+ points it at a self-hosted copy (keep the ratio). */
8
11
  .fs-wave {
9
12
  display: block;
10
13
  height: var(--fs-wave-height, 160px);
@@ -18,9 +21,21 @@ export default `/* Wave (spec 02 I). Usage: wave.md. */
18
21
  content: '';
19
22
  display: block;
20
23
  height: 100%;
24
+ /* --fs-wave-height is read here, on the host's own value, so a custom height moves the cap too. */
25
+ max-width: calc(var(--fs-wave-height, 160px) * 5.716);
26
+ margin-inline: auto;
21
27
  background: linear-gradient(90deg, var(--fs-brand-end), var(--fs-brand-start) 65%);
22
- -webkit-mask: var(--fs-wave-image, url('${new URL('../motifs/wave.webp', import.meta.url).href}')) center bottom / cover no-repeat;
23
- mask: var(--fs-wave-image, url('${new URL('../motifs/wave.webp', import.meta.url).href}')) center bottom / cover no-repeat;
28
+ /* Two mask layers, intersected: the soft right edge, then the image. */
29
+ -webkit-mask:
30
+ linear-gradient(90deg, transparent, currentcolor 5%, currentcolor 90%, transparent) center bottom / 100% 100%
31
+ no-repeat,
32
+ var(--fs-wave-image, url('${new URL('../motifs/wave.webp', import.meta.url).href}')) center bottom / cover no-repeat;
33
+ -webkit-mask-composite: source-in;
34
+ mask:
35
+ linear-gradient(90deg, transparent, currentcolor 5%, currentcolor 90%, transparent) center bottom / 100% 100%
36
+ no-repeat,
37
+ var(--fs-wave-image, url('${new URL('../motifs/wave.webp', import.meta.url).href}')) center bottom / cover no-repeat;
38
+ mask-composite: intersect;
24
39
  }
25
40
  /* Decoration: nothing to show in forced colours, nothing to print. */
26
41
  @media (forced-colors: active) {
@@ -0,0 +1,45 @@
1
+ export type Granularity = 'month' | 'day';
2
+ export interface YMD {
3
+ year: number;
4
+ month: number;
5
+ day: number;
6
+ }
7
+ export declare function isLeapYear(year: number): boolean;
8
+ /** Days in a month (1–12). */
9
+ export declare function daysInMonth(year: number, month: number): number;
10
+ export declare const formatMonth: (year: number, month: number) => string;
11
+ export declare const formatDay: (year: number, month: number, day: number) => string;
12
+ /** `YYYY-MM` to its parts, or null when malformed or out of range. */
13
+ export declare function parseMonth(iso: string): {
14
+ year: number;
15
+ month: number;
16
+ } | null;
17
+ /** `YYYY-MM-DD` to its parts, or null when malformed or not a real day. */
18
+ export declare function parseDay(iso: string): YMD | null;
19
+ /** The weekday of a day, 0 = Sunday. */
20
+ export declare function weekday(year: number, month: number, day: number): number;
21
+ /** A day `n` days on (or back), held inside years 1–9999. */
22
+ export declare function addDays(iso: string, n: number): string;
23
+ /** A month or day `n` months on; a day keeps its number, clamped to the month's length. */
24
+ export declare function addMonths(iso: string, n: number): string;
25
+ export declare const addYears: (iso: string, n: number) => string;
26
+ /**
27
+ * Holds `iso` between `min` and `max` (either may be missing). Same-form ISO strings sort as
28
+ * text, because years are always four digits.
29
+ */
30
+ export declare function clampIso(iso: string, min?: string, max?: string): string;
31
+ /**
32
+ * A month in weeks of seven, starting on `weekStart` (0 = Sunday): each entry is the day number,
33
+ * or null for a day of a neighbouring month.
34
+ */
35
+ export declare function monthGrid(year: number, month: number, weekStart: number): (number | null)[][];
36
+ /** The page of twelve years that holds `year`: pages start at multiples of 12 (2016–2027). */
37
+ export declare function yearPage(year: number): {
38
+ from: number;
39
+ to: number;
40
+ };
41
+ /**
42
+ * Today in the user's own time zone, as a month or a day. The one place the calendar reads the
43
+ * clock, and only when the product passes no `today`.
44
+ */
45
+ export declare function localToday(granularity: Granularity, now?: Date): string;
@@ -0,0 +1,129 @@
1
+ // Date arithmetic for the calendar (D42; spec 03 §3.2), on ISO strings: `YYYY-MM` for a month,
2
+ // `YYYY-MM-DD` for a day. No `Date` is ever made from a value, so no time zone can move one by a
3
+ // day. Months are 1–12, weekdays 0 (Sunday) to 6, years 1–9999.
4
+ const MIN_YEAR = 1;
5
+ const MAX_YEAR = 9999;
6
+ const pad = (n, width) => String(n).padStart(width, '0');
7
+ const mod = (a, b) => ((a % b) + b) % b;
8
+ export function isLeapYear(year) {
9
+ return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
10
+ }
11
+ /** Days in a month (1–12). */
12
+ export function daysInMonth(year, month) {
13
+ return month === 2 ? (isLeapYear(year) ? 29 : 28) : [4, 6, 9, 11].includes(month) ? 30 : 31;
14
+ }
15
+ export const formatMonth = (year, month) => `${pad(year, 4)}-${pad(month, 2)}`;
16
+ export const formatDay = (year, month, day) => `${formatMonth(year, month)}-${pad(day, 2)}`;
17
+ /** `YYYY-MM` to its parts, or null when malformed or out of range. */
18
+ export function parseMonth(iso) {
19
+ const m = /^(\d{4})-(\d{2})$/.exec(iso);
20
+ if (!m)
21
+ return null;
22
+ const year = Number(m[1]);
23
+ const month = Number(m[2]);
24
+ return year >= MIN_YEAR && month >= 1 && month <= 12 ? { year, month } : null;
25
+ }
26
+ /** `YYYY-MM-DD` to its parts, or null when malformed or not a real day. */
27
+ export function parseDay(iso) {
28
+ const m = /^(\d{4}-\d{2})-(\d{2})$/.exec(iso);
29
+ const ym = m && parseMonth(m[1]);
30
+ if (!ym)
31
+ return null;
32
+ const day = Number(m[2]);
33
+ return day >= 1 && day <= daysInMonth(ym.year, ym.month) ? { ...ym, day } : null;
34
+ }
35
+ /** Parses either form, by length; a month comes back as its first day. */
36
+ function parts(iso) {
37
+ const d = iso.length > 7 ? parseDay(iso) : null;
38
+ if (d)
39
+ return d;
40
+ const m = parseMonth(iso.slice(0, 7));
41
+ if (!m)
42
+ throw new RangeError(`[fs] not an ISO month or day: "${iso}"`);
43
+ return { ...m, day: 1 };
44
+ }
45
+ // Days since 1970-01-01 and back (H. Hinnant's civil-from-days), so adding days never builds a Date.
46
+ function toDayNumber({ year, month, day }) {
47
+ const y = month <= 2 ? year - 1 : year;
48
+ const era = Math.floor(y / 400);
49
+ const yoe = y - era * 400;
50
+ const doy = Math.floor((153 * (month + (month > 2 ? -3 : 9)) + 2) / 5) + day - 1;
51
+ const doe = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + doy;
52
+ return era * 146097 + doe - 719468;
53
+ }
54
+ function fromDayNumber(n) {
55
+ const z = n + 719468;
56
+ const era = Math.floor(z / 146097);
57
+ const doe = z - era * 146097;
58
+ const yoe = Math.floor((doe - Math.floor(doe / 1460) + Math.floor(doe / 36524) - Math.floor(doe / 146096)) / 365);
59
+ const doy = doe - (365 * yoe + Math.floor(yoe / 4) - Math.floor(yoe / 100));
60
+ const mp = Math.floor((5 * doy + 2) / 153);
61
+ const day = doy - Math.floor((153 * mp + 2) / 5) + 1;
62
+ const month = mp < 10 ? mp + 3 : mp - 9;
63
+ return { year: yoe + era * 400 + (month <= 2 ? 1 : 0), month, day };
64
+ }
65
+ /** The weekday of a day, 0 = Sunday. */
66
+ export function weekday(year, month, day) {
67
+ return mod(toDayNumber({ year, month, day }) + 4, 7); // 1970-01-01 was a Thursday
68
+ }
69
+ /** A day `n` days on (or back), held inside years 1–9999. */
70
+ export function addDays(iso, n) {
71
+ const first = toDayNumber({ year: MIN_YEAR, month: 1, day: 1 });
72
+ const last = toDayNumber({ year: MAX_YEAR, month: 12, day: 31 });
73
+ const { year, month, day } = fromDayNumber(Math.min(Math.max(toDayNumber(parts(iso)) + n, first), last));
74
+ return formatDay(year, month, day);
75
+ }
76
+ /** A month or day `n` months on; a day keeps its number, clamped to the month's length. */
77
+ export function addMonths(iso, n) {
78
+ const p = parts(iso);
79
+ const index = Math.min(Math.max(p.year * 12 + p.month - 1 + n, MIN_YEAR * 12), MAX_YEAR * 12 + 11);
80
+ const year = Math.floor(index / 12);
81
+ const month = (index % 12) + 1;
82
+ if (iso.length <= 7)
83
+ return formatMonth(year, month);
84
+ // Clamped at either end of time, the day goes to that end too.
85
+ const atEdge = index !== p.year * 12 + p.month - 1 + n;
86
+ const day = atEdge ? (n < 0 ? 1 : daysInMonth(year, month)) : Math.min(p.day, daysInMonth(year, month));
87
+ return formatDay(year, month, day);
88
+ }
89
+ export const addYears = (iso, n) => addMonths(iso, n * 12);
90
+ /**
91
+ * Holds `iso` between `min` and `max` (either may be missing). Same-form ISO strings sort as
92
+ * text, because years are always four digits.
93
+ */
94
+ export function clampIso(iso, min, max) {
95
+ if (min !== undefined && iso < min)
96
+ return min;
97
+ if (max !== undefined && iso > max)
98
+ return max;
99
+ return iso;
100
+ }
101
+ /**
102
+ * A month in weeks of seven, starting on `weekStart` (0 = Sunday): each entry is the day number,
103
+ * or null for a day of a neighbouring month.
104
+ */
105
+ export function monthGrid(year, month, weekStart) {
106
+ const lead = mod(weekday(year, month, 1) - weekStart, 7);
107
+ const cells = [...Array(lead).fill(null)];
108
+ for (let d = 1; d <= daysInMonth(year, month); d++)
109
+ cells.push(d);
110
+ while (cells.length % 7)
111
+ cells.push(null);
112
+ const weeks = [];
113
+ for (let i = 0; i < cells.length; i += 7)
114
+ weeks.push(cells.slice(i, i + 7));
115
+ return weeks;
116
+ }
117
+ /** The page of twelve years that holds `year`: pages start at multiples of 12 (2016–2027). */
118
+ export function yearPage(year) {
119
+ const from = year - mod(year, 12);
120
+ return { from, to: from + 11 };
121
+ }
122
+ /**
123
+ * Today in the user's own time zone, as a month or a day. The one place the calendar reads the
124
+ * clock, and only when the product passes no `today`.
125
+ */
126
+ export function localToday(granularity, now = new Date()) {
127
+ const month = formatMonth(now.getFullYear(), now.getMonth() + 1);
128
+ return granularity === 'month' ? month : `${month}-${pad(now.getDate(), 2)}`;
129
+ }
@@ -0,0 +1,79 @@
1
+ import { type Granularity } from './calendar-dates.ts';
2
+ export type { Granularity };
3
+ export type CalendarView = 'year' | 'month' | 'day';
4
+ /** What a page of the calendar shows, for the heading. Months are 1–12. */
5
+ export type CalendarPage = {
6
+ view: 'day';
7
+ year: number;
8
+ month: number;
9
+ } | {
10
+ view: 'month';
11
+ year: number;
12
+ } | {
13
+ view: 'year';
14
+ from: number;
15
+ to: number;
16
+ };
17
+ /**
18
+ * A day cell, for its accessible name: `value` is `YYYY-MM-DD`, `weekday` 0 (Sunday) to 6. Only day
19
+ * cells take a name: a month or year cell is named by its visible text, and the grid by the heading,
20
+ * which carries the year (WCAG 2.5.3: a short "Jan" must not hide behind "January 2026").
21
+ */
22
+ export interface CalendarDay {
23
+ value: string;
24
+ year: number;
25
+ month: number;
26
+ day: number;
27
+ weekday: number;
28
+ }
29
+ export interface CalendarLabels {
30
+ /** The previous-page button's name in each view ("Előző hónap", "Előző év", "Előző 12 év"). */
31
+ prev: Record<CalendarView, string>;
32
+ /** The next-page button's name in each view. */
33
+ next: Record<CalendarView, string>;
34
+ /** Optional: said after the heading in the view button's name ("2026. november, hónap választása"). */
35
+ up?: Partial<Record<'day' | 'month', string>>;
36
+ }
37
+ export interface CalendarOptions {
38
+ /** The picked day (`YYYY-MM-DD`) or month (`YYYY-MM`), or null. */
39
+ value?: string | null;
40
+ /** The first and last pickable day or month; either form is read at the granularity. */
41
+ min?: string;
42
+ max?: string;
43
+ /** Default: the local date, read from the clock once. */
44
+ today?: string;
45
+ /** The lowest view, and the form of the value. Default `day`. */
46
+ granularity?: Granularity;
47
+ /** The first column, 0 = Sunday. Default 1 (Monday). */
48
+ weekStart?: number;
49
+ /** Twelve names the month cells show, January first. Short forms fit ("jan.", "febr."). */
50
+ monthNames: readonly string[];
51
+ /** Seven column headers, Sunday first whatever the week start ("V", "H", "K", "Sze", …). */
52
+ weekdayNames: readonly string[];
53
+ /** The heading of a page: "2026. november", "2026", "2016–2027". */
54
+ heading(page: CalendarPage): string;
55
+ /** A day cell's full accessible name, which must contain the day number: "2026. november 9., hétfő". */
56
+ cellLabel(day: CalendarDay): string;
57
+ labels: CalendarLabels;
58
+ /** The host's live region (CE §7). Without one the calendar keeps its own, visually hidden. */
59
+ announcer?: HTMLElement;
60
+ }
61
+ export interface CalendarChangeDetail {
62
+ value: string;
63
+ }
64
+ export interface Calendar {
65
+ readonly value: string | null;
66
+ readonly view: CalendarView;
67
+ /** Sets the value and shows its page, without an `fs-change` event; null clears it. */
68
+ setValue(value: string | null): void;
69
+ /** Shows a view (not one below the granularity). */
70
+ setView(view: CalendarView): void;
71
+ /** Focuses the grid's one tab stop. */
72
+ focus(): void;
73
+ /** Takes new options; a `value` among them moves to its page as `setValue` does. */
74
+ update(options: Partial<CalendarOptions>): void;
75
+ /** Removes every listener and empties the root. */
76
+ destroy(): void;
77
+ }
78
+ /** `root` is an empty `.fs-calendar` element; the helper renders the header and the grid into it. */
79
+ export declare function createCalendar(root: HTMLElement, options: CalendarOptions): Calendar;