tuidroid 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 +674 -0
- package/README.md +181 -2
- package/dist/arrange/Mover.svelte +42 -0
- package/dist/arrange/Mover.svelte.d.ts +29 -0
- package/dist/arrange/PutAway.svelte +48 -0
- package/dist/arrange/PutAway.svelte.d.ts +30 -0
- package/dist/arrange/arrangement.svelte.d.ts +27 -0
- package/dist/arrange/arrangement.svelte.js +44 -0
- package/dist/arrange/order.d.ts +7 -0
- package/dist/arrange/order.js +20 -0
- package/dist/calendar/Calendar.svelte +328 -0
- package/dist/calendar/Calendar.svelte.d.ts +28 -0
- package/dist/calendar/MonthPicker.svelte +41 -0
- package/dist/calendar/MonthPicker.svelte.d.ts +10 -0
- package/dist/calendar/YearPicker.svelte +61 -0
- package/dist/calendar/YearPicker.svelte.d.ts +11 -0
- package/dist/calendar/dates.d.ts +23 -0
- package/dist/calendar/dates.js +54 -0
- package/dist/charts/BarChart.svelte +98 -0
- package/dist/charts/BarChart.svelte.d.ts +28 -0
- package/dist/charts/ChartFrame.svelte +133 -0
- package/dist/charts/ChartFrame.svelte.d.ts +21 -0
- package/dist/charts/ColumnChart.svelte +79 -0
- package/dist/charts/ColumnChart.svelte.d.ts +20 -0
- package/dist/charts/HeatGrid.svelte +110 -0
- package/dist/charts/HeatGrid.svelte.d.ts +22 -0
- package/dist/charts/LineChart.svelte +132 -0
- package/dist/charts/LineChart.svelte.d.ts +29 -0
- package/dist/charts/StripChart.svelte +80 -0
- package/dist/charts/StripChart.svelte.d.ts +27 -0
- package/dist/charts/scale.d.ts +17 -0
- package/dist/charts/scale.js +35 -0
- package/dist/controls/AccentStepper.svelte +24 -0
- package/dist/controls/AccentStepper.svelte.d.ts +8 -0
- package/dist/controls/Button.svelte +264 -0
- package/dist/controls/Button.svelte.d.ts +26 -0
- package/dist/controls/Cycle.svelte +27 -0
- package/dist/controls/Cycle.svelte.d.ts +31 -0
- package/dist/controls/NumberStepper.svelte +28 -0
- package/dist/controls/NumberStepper.svelte.d.ts +12 -0
- package/dist/controls/OptionStepper.svelte +42 -0
- package/dist/controls/OptionStepper.svelte.d.ts +34 -0
- package/dist/controls/Segmented.svelte +72 -0
- package/dist/controls/Segmented.svelte.d.ts +35 -0
- package/dist/controls/SettingRow.svelte +59 -0
- package/dist/controls/SettingRow.svelte.d.ts +11 -0
- package/dist/controls/Stepper.svelte +151 -0
- package/dist/controls/Stepper.svelte.d.ts +17 -0
- package/dist/controls/TextInput.svelte +176 -0
- package/dist/controls/TextInput.svelte.d.ts +12 -0
- package/dist/controls/Toggle.svelte +22 -0
- package/dist/controls/Toggle.svelte.d.ts +9 -0
- package/dist/data/BarRows.svelte +75 -0
- package/dist/data/BarRows.svelte.d.ts +15 -0
- package/dist/data/CellBar.svelte +55 -0
- package/dist/data/CellBar.svelte.d.ts +13 -0
- package/dist/data/Delta.svelte +28 -0
- package/dist/data/Delta.svelte.d.ts +11 -0
- package/dist/data/Hatch.svelte +9 -0
- package/dist/data/Hatch.svelte.d.ts +8 -0
- package/dist/data/KeyValues.svelte +56 -0
- package/dist/data/KeyValues.svelte.d.ts +14 -0
- package/dist/data/Legend.svelte +64 -0
- package/dist/data/Legend.svelte.d.ts +15 -0
- package/dist/data/Meter.svelte +46 -0
- package/dist/data/Meter.svelte.d.ts +9 -0
- package/dist/data/StackedBar.svelte +64 -0
- package/dist/data/StackedBar.svelte.d.ts +14 -0
- package/dist/data/Swatch.svelte +56 -0
- package/dist/data/Swatch.svelte.d.ts +11 -0
- package/dist/data/Table.svelte +86 -0
- package/dist/data/Table.svelte.d.ts +16 -0
- package/dist/data/Value.svelte +32 -0
- package/dist/data/Value.svelte.d.ts +12 -0
- package/dist/data/cells.d.ts +27 -0
- package/dist/data/cells.js +41 -0
- package/dist/data/fit.d.ts +10 -0
- package/dist/data/fit.js +35 -0
- package/dist/gestures/drag.d.ts +28 -0
- package/dist/gestures/drag.js +110 -0
- package/dist/gestures/hold.d.ts +7 -0
- package/dist/gestures/hold.js +59 -0
- package/dist/gestures/pick.d.ts +5 -0
- package/dist/gestures/pick.js +60 -0
- package/dist/haptics.d.ts +5 -0
- package/dist/haptics.js +16 -0
- package/dist/icons/Icon.svelte +52 -0
- package/dist/icons/Icon.svelte.d.ts +17 -0
- package/dist/icons/material.d.ts +68 -0
- package/dist/icons/material.js +69 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.js +91 -0
- package/dist/layout/Alert.svelte +46 -0
- package/dist/layout/Alert.svelte.d.ts +12 -0
- package/dist/layout/Block.svelte +166 -0
- package/dist/layout/Block.svelte.d.ts +22 -0
- package/dist/layout/Panes.svelte +41 -0
- package/dist/layout/Panes.svelte.d.ts +9 -0
- package/dist/layout/Rows.svelte +37 -0
- package/dist/layout/Rows.svelte.d.ts +8 -0
- package/dist/layout/Split.svelte +18 -0
- package/dist/layout/Split.svelte.d.ts +4 -0
- package/dist/layout/Stage.svelte +59 -0
- package/dist/layout/Stage.svelte.d.ts +10 -0
- package/dist/layout/Unfold.svelte +25 -0
- package/dist/layout/Unfold.svelte.d.ts +9 -0
- package/dist/lists/ListItem.svelte +75 -0
- package/dist/lists/ListItem.svelte.d.ts +13 -0
- package/dist/lists/SwipeRow.svelte +158 -0
- package/dist/lists/SwipeRow.svelte.d.ts +21 -0
- package/dist/lists/UndoRow.svelte +37 -0
- package/dist/lists/UndoRow.svelte.d.ts +10 -0
- package/dist/motion/FlipCard.svelte +197 -0
- package/dist/motion/FlipCard.svelte.d.ts +34 -0
- package/dist/motion/Hero.svelte +59 -0
- package/dist/motion/Hero.svelte.d.ts +9 -0
- package/dist/motion/ShuffleText.svelte +42 -0
- package/dist/motion/ShuffleText.svelte.d.ts +13 -0
- package/dist/motion/TypeText.svelte +68 -0
- package/dist/motion/TypeText.svelte.d.ts +11 -0
- package/dist/motion/shuffle.d.ts +24 -0
- package/dist/motion/shuffle.js +58 -0
- package/dist/motion/still.d.ts +2 -0
- package/dist/motion/still.js +7 -0
- package/dist/motion/sweep.d.ts +14 -0
- package/dist/motion/sweep.js +59 -0
- package/dist/motion/typing.d.ts +9 -0
- package/dist/motion/typing.js +19 -0
- package/dist/motion/unfold.d.ts +4 -0
- package/dist/motion/unfold.js +13 -0
- package/dist/nav/Hang.svelte +194 -0
- package/dist/nav/Hang.svelte.d.ts +15 -0
- package/dist/nav/Pager.svelte +89 -0
- package/dist/nav/Pager.svelte.d.ts +43 -0
- package/dist/nav/Pane.svelte +93 -0
- package/dist/nav/Pane.svelte.d.ts +15 -0
- package/dist/nav/Shell.svelte +40 -0
- package/dist/nav/Shell.svelte.d.ts +34 -0
- package/dist/nav/TabBar.svelte +139 -0
- package/dist/nav/TabBar.svelte.d.ts +15 -0
- package/dist/styles/base.css +87 -0
- package/dist/styles/tokens.css +253 -0
- package/dist/text/Fields.svelte +28 -0
- package/dist/text/Fields.svelte.d.ts +8 -0
- package/dist/text/fields.d.ts +6 -0
- package/dist/text/fields.js +16 -0
- package/dist/theme/FlavourButton.svelte +55 -0
- package/dist/theme/FlavourButton.svelte.d.ts +13 -0
- package/dist/theme/Theme.svelte +48 -0
- package/dist/theme/Theme.svelte.d.ts +15 -0
- package/dist/theme/palette.d.ts +23 -0
- package/dist/theme/palette.js +55 -0
- package/dist/theme/reveal.d.ts +10 -0
- package/dist/theme/reveal.js +92 -0
- package/dist/theme/theme.d.ts +15 -0
- package/dist/theme/theme.js +21 -0
- package/package.json +72 -4
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
/** What a day shows: bold in `colour` (it has something), hatched behind (a near miss). */
|
|
3
|
+
export interface CalendarDay {
|
|
4
|
+
colour?: string
|
|
5
|
+
hatched?: boolean
|
|
6
|
+
label?: string // what a screen reader hears after the date
|
|
7
|
+
}
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
12
|
+
import Button from '../controls/Button.svelte'
|
|
13
|
+
import { carries, drag } from '../gestures/drag'
|
|
14
|
+
import ShuffleText from '../motion/ShuffleText.svelte'
|
|
15
|
+
import { still } from '../motion/still'
|
|
16
|
+
import { addMonths, dayKey, MONTHS, monthRows, rowWeek, WEEKDAYS, weekdayHeads, type WeekRow, type WeekStart } from './dates'
|
|
17
|
+
|
|
18
|
+
// A month as a grid of days under < [ November ] [ 2026 ] >. Each day is drawn as `day`
|
|
19
|
+
// says: muted with nothing, bold in a colour with something, hatched behind for a near
|
|
20
|
+
// miss; today is underlined in the accent. Tapping a day picks it, and again lets go
|
|
21
|
+
// (bind:selected, its key). < > or a swipe slides the grid to the month either side,
|
|
22
|
+
// the header staying put; the month's and the year's words call `onmonth` and `onyear`
|
|
23
|
+
// (to open a picker; they carry data-pane="month" and "year" for a Hang to swap between).
|
|
24
|
+
// `weekNumbers` puts ISO week numbers before each week, `side` a value after it (the
|
|
25
|
+
// week's hours): the seven days stay in the middle either way. Six rows always, so the
|
|
26
|
+
// grid keeps its height.
|
|
27
|
+
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'onselect'> {
|
|
28
|
+
year: number
|
|
29
|
+
month: number // 0 to 11
|
|
30
|
+
weekStart?: WeekStart
|
|
31
|
+
day?: (date: Date, key: string) => CalendarDay | undefined
|
|
32
|
+
selected?: string | null
|
|
33
|
+
today?: Date
|
|
34
|
+
weekNumbers?: boolean
|
|
35
|
+
side?: (row: WeekRow) => string
|
|
36
|
+
sideHead?: string
|
|
37
|
+
heads?: readonly string[] // weekday names, Sunday first
|
|
38
|
+
months?: readonly string[]
|
|
39
|
+
dateLabel?: (date: Date) => string
|
|
40
|
+
onmonth?: () => void
|
|
41
|
+
onyear?: () => void
|
|
42
|
+
onselect?: (key: string | null) => void
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let {
|
|
46
|
+
year = $bindable(),
|
|
47
|
+
month = $bindable(),
|
|
48
|
+
weekStart = 1,
|
|
49
|
+
day,
|
|
50
|
+
selected = $bindable(null),
|
|
51
|
+
today = new Date(),
|
|
52
|
+
weekNumbers = false,
|
|
53
|
+
side,
|
|
54
|
+
sideHead = '',
|
|
55
|
+
heads = WEEKDAYS,
|
|
56
|
+
months = MONTHS,
|
|
57
|
+
dateLabel = (date) => date.toLocaleDateString('en-GB', { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }),
|
|
58
|
+
onmonth,
|
|
59
|
+
onyear,
|
|
60
|
+
onselect,
|
|
61
|
+
class: className,
|
|
62
|
+
...rest
|
|
63
|
+
}: Props = $props()
|
|
64
|
+
|
|
65
|
+
const todayKey = $derived(dayKey(today))
|
|
66
|
+
const columns = $derived(weekdayHeads(weekStart, heads))
|
|
67
|
+
const sides = $derived(weekNumbers || !!side)
|
|
68
|
+
|
|
69
|
+
function cell(y: number, m: number, n: number) {
|
|
70
|
+
const date = new Date(y, m, n)
|
|
71
|
+
const key = dayKey(date)
|
|
72
|
+
return { date, key, info: day?.(date, key) }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function pick(key: string) {
|
|
76
|
+
selected = selected === key ? null : key
|
|
77
|
+
onselect?.(selected)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function move(by: number) {
|
|
81
|
+
const next = addMonths(year, month, by)
|
|
82
|
+
year = next.year
|
|
83
|
+
month = next.month
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// The grids of the month before, the month shown and the month after sit side by side in
|
|
87
|
+
// a strip. A drag moves the strip one to one; let go, it slides on to a neighbour (whose
|
|
88
|
+
// month is then the one shown, and the strip back in place) or springs back.
|
|
89
|
+
const around = $derived([-1, 0, 1].map((by) => ({ by, ...addMonths(year, month, by) })))
|
|
90
|
+
let swipe = $state<HTMLElement>()
|
|
91
|
+
let width = $state(1)
|
|
92
|
+
let shift = $state(0) // the drag's offset, in px
|
|
93
|
+
let going = $state<-1 | 0 | 1>(0) // the neighbour it slides to
|
|
94
|
+
let sliding = $state(false)
|
|
95
|
+
let slideTimer = 0
|
|
96
|
+
|
|
97
|
+
function glide(by: -1 | 0 | 1) {
|
|
98
|
+
if (still(swipe)) {
|
|
99
|
+
shift = 0
|
|
100
|
+
if (by) move(by)
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
if (!by && !shift) return
|
|
104
|
+
sliding = true
|
|
105
|
+
going = by
|
|
106
|
+
shift = 0
|
|
107
|
+
slideTimer = window.setTimeout(settle, 400) // for a transitionend that never comes
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function settle() {
|
|
111
|
+
clearTimeout(slideTimer)
|
|
112
|
+
if (!sliding) return
|
|
113
|
+
const by = going
|
|
114
|
+
sliding = false
|
|
115
|
+
going = 0
|
|
116
|
+
shift = 0
|
|
117
|
+
if (by) move(by)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const step = (by: -1 | 1) => !sliding && !shift && glide(by)
|
|
121
|
+
|
|
122
|
+
const follow = drag({
|
|
123
|
+
axis: 'x',
|
|
124
|
+
claim: true,
|
|
125
|
+
onStart: settle, // a drag takes over from a slide still going
|
|
126
|
+
onMove: (dx) => (shift = Math.max(-width, Math.min(width, dx))),
|
|
127
|
+
onEnd: (dx, velocity) => glide(carries(dx, width, velocity, 0.2) ? (dx < 0 ? 1 : -1) : 0),
|
|
128
|
+
})
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
{#snippet grid(y: number, m: number)}
|
|
132
|
+
<table class="grid">
|
|
133
|
+
<thead>
|
|
134
|
+
<tr>
|
|
135
|
+
{#if sides}<th scope="col" class="side" aria-label={weekNumbers ? 'Week' : undefined}>{weekNumbers ? 'wk' : ''}</th>{/if}
|
|
136
|
+
{#each columns as head, i (i)}<th scope="col">{head}</th>{/each}
|
|
137
|
+
{#if sides}<th scope="col" class="side">{side ? sideHead : ''}</th>{/if}
|
|
138
|
+
</tr>
|
|
139
|
+
</thead>
|
|
140
|
+
<tbody>
|
|
141
|
+
{#each monthRows(y, m, weekStart) as row, w (w)}
|
|
142
|
+
{const inMonth = $derived(row.days.some((d) => d !== null))}
|
|
143
|
+
<tr>
|
|
144
|
+
{#if sides}<th scope="row" class="side muted">{weekNumbers && inMonth ? rowWeek(row) : ''}</th>{/if}
|
|
145
|
+
{#each row.days as n, d (d)}
|
|
146
|
+
<td>
|
|
147
|
+
{#if n !== null}
|
|
148
|
+
{const c = $derived(cell(y, m, n))}
|
|
149
|
+
<button
|
|
150
|
+
type="button"
|
|
151
|
+
class="day"
|
|
152
|
+
class:marked={c.info?.colour}
|
|
153
|
+
class:hatched={c.info?.hatched}
|
|
154
|
+
class:selected={selected === c.key}
|
|
155
|
+
class:today={todayKey === c.key}
|
|
156
|
+
style:--day={c.info?.colour}
|
|
157
|
+
aria-label="{dateLabel(c.date)}{c.info?.label ? `: ${c.info.label}` : ''}"
|
|
158
|
+
aria-pressed={selected === c.key}
|
|
159
|
+
onclick={() => pick(c.key)}><span class="date">{n}</span></button
|
|
160
|
+
>
|
|
161
|
+
{:else}
|
|
162
|
+
<!-- Holds the row's height, so short months keep the grid's size. -->
|
|
163
|
+
<span class="day" aria-hidden="true"><span class="date"> </span></span>
|
|
164
|
+
{/if}
|
|
165
|
+
</td>
|
|
166
|
+
{/each}
|
|
167
|
+
{#if sides}<td class="side muted">{side && inMonth ? side(row) : ''}</td>{/if}
|
|
168
|
+
</tr>
|
|
169
|
+
{/each}
|
|
170
|
+
</tbody>
|
|
171
|
+
</table>
|
|
172
|
+
{/snippet}
|
|
173
|
+
|
|
174
|
+
<div {...rest} class={['tui-calendar', className]} bind:this={swipe} bind:clientWidth={width} {@attach follow}>
|
|
175
|
+
<div class="month">
|
|
176
|
+
<Button variant="glyph" aria-label="Previous month" title="Previous month" onclick={() => step(-1)}><</Button>
|
|
177
|
+
<span class="when">
|
|
178
|
+
{#if onmonth}<Button variant="word" data-pane="month" aria-label="Pick a month: {months[month]}" onclick={onmonth}
|
|
179
|
+
><ShuffleText text={months[month]} /></Button
|
|
180
|
+
>{:else}<span class="word"><ShuffleText text={months[month]} /></span>{/if}
|
|
181
|
+
{#if onyear}<Button variant="word" data-pane="year" aria-label="Pick a year: {year}" onclick={onyear}
|
|
182
|
+
><ShuffleText text={year} /></Button
|
|
183
|
+
>{:else}<span class="word"><ShuffleText text={year} /></span>{/if}
|
|
184
|
+
</span>
|
|
185
|
+
<Button variant="glyph" aria-label="Next month" title="Next month" onclick={() => step(1)}>></Button>
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
<div class="viewport">
|
|
189
|
+
<div
|
|
190
|
+
class="strip"
|
|
191
|
+
class:sliding
|
|
192
|
+
style:transform="translateX(calc({-100 - 100 * going}% + {shift}px))"
|
|
193
|
+
ontransitionend={(event) => event.target === event.currentTarget && event.propertyName === 'transform' && settle()}
|
|
194
|
+
>
|
|
195
|
+
{#each around as m (m.year * 12 + m.month)}
|
|
196
|
+
<!-- The neighbours wait out of sight: nothing in them is reached by touch or keys. -->
|
|
197
|
+
<div class="panel" inert={m.by !== 0}>{@render grid(m.year, m.month)}</div>
|
|
198
|
+
{/each}
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
|
|
203
|
+
<style>
|
|
204
|
+
@layer tuidroid {
|
|
205
|
+
.tui-calendar {
|
|
206
|
+
touch-action: pan-y;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.month {
|
|
210
|
+
display: flex;
|
|
211
|
+
align-items: center;
|
|
212
|
+
justify-content: space-between;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.when {
|
|
216
|
+
display: flex;
|
|
217
|
+
gap: 1ch;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
span.word {
|
|
221
|
+
color: var(--tui-accent);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* Only the strip moves, and only by transform; the ends are clipped. */
|
|
225
|
+
.viewport {
|
|
226
|
+
overflow-x: clip;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.strip {
|
|
230
|
+
display: flex;
|
|
231
|
+
will-change: transform;
|
|
232
|
+
|
|
233
|
+
&.sliding {
|
|
234
|
+
transition: transform var(--tui-slide);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.panel {
|
|
239
|
+
flex: 0 0 100%;
|
|
240
|
+
min-width: 0;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.grid {
|
|
244
|
+
margin: 0.4em auto 0;
|
|
245
|
+
border-collapse: collapse;
|
|
246
|
+
font-size: 1.1em;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
th,
|
|
250
|
+
td {
|
|
251
|
+
padding: 0.1em 0.3ch;
|
|
252
|
+
text-align: center;
|
|
253
|
+
vertical-align: middle;
|
|
254
|
+
font-weight: normal;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
thead th {
|
|
258
|
+
font-size: 0.85em;
|
|
259
|
+
color: var(--tui-muted);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/* Week numbers before a week, its value after it; both as wide as each other, so the
|
|
263
|
+
seven days stay in the middle. */
|
|
264
|
+
.side {
|
|
265
|
+
font-size: 0.8em;
|
|
266
|
+
width: 4ch;
|
|
267
|
+
color: var(--tui-muted);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/* Every day the same box, button or not: the grid never changes height. */
|
|
271
|
+
.day {
|
|
272
|
+
display: inline-flex;
|
|
273
|
+
align-items: center;
|
|
274
|
+
justify-content: center;
|
|
275
|
+
box-sizing: border-box;
|
|
276
|
+
min-width: 3.4ch;
|
|
277
|
+
height: 1.9em;
|
|
278
|
+
padding: 0;
|
|
279
|
+
font: inherit;
|
|
280
|
+
line-height: 1.1;
|
|
281
|
+
white-space: pre;
|
|
282
|
+
border: 1px solid transparent;
|
|
283
|
+
border-radius: 0.4em;
|
|
284
|
+
vertical-align: middle;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/* A day with nothing is muted; one with something is bold in its colour. */
|
|
288
|
+
button.day {
|
|
289
|
+
background: none;
|
|
290
|
+
color: var(--tui-muted);
|
|
291
|
+
cursor: pointer;
|
|
292
|
+
touch-action: manipulation;
|
|
293
|
+
-webkit-tap-highlight-color: transparent;
|
|
294
|
+
|
|
295
|
+
&.marked .date {
|
|
296
|
+
font-weight: 700;
|
|
297
|
+
color: var(--day);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
&.selected {
|
|
301
|
+
border-color: var(--tui-accent);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
&.hatched {
|
|
305
|
+
background: repeating-linear-gradient(
|
|
306
|
+
-45deg,
|
|
307
|
+
color-mix(in srgb, var(--day, var(--tui-muted)) 45%, transparent) 0 1px,
|
|
308
|
+
transparent 1px 3px
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
&.today:not(.marked) .date {
|
|
313
|
+
color: var(--tui-accent);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
&:focus-visible {
|
|
317
|
+
outline: 1px solid var(--tui-accent);
|
|
318
|
+
outline-offset: 1px;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/* Today is underlined in the accent, keeping its own colour if it has one. */
|
|
323
|
+
.today .date {
|
|
324
|
+
text-decoration: underline 2px var(--tui-accent);
|
|
325
|
+
text-underline-offset: 0.15em;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
</style>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** What a day shows: bold in `colour` (it has something), hatched behind (a near miss). */
|
|
2
|
+
export interface CalendarDay {
|
|
3
|
+
colour?: string;
|
|
4
|
+
hatched?: boolean;
|
|
5
|
+
label?: string;
|
|
6
|
+
}
|
|
7
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
8
|
+
import { type WeekRow, type WeekStart } from './dates';
|
|
9
|
+
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'onselect'> {
|
|
10
|
+
year: number;
|
|
11
|
+
month: number;
|
|
12
|
+
weekStart?: WeekStart;
|
|
13
|
+
day?: (date: Date, key: string) => CalendarDay | undefined;
|
|
14
|
+
selected?: string | null;
|
|
15
|
+
today?: Date;
|
|
16
|
+
weekNumbers?: boolean;
|
|
17
|
+
side?: (row: WeekRow) => string;
|
|
18
|
+
sideHead?: string;
|
|
19
|
+
heads?: readonly string[];
|
|
20
|
+
months?: readonly string[];
|
|
21
|
+
dateLabel?: (date: Date) => string;
|
|
22
|
+
onmonth?: () => void;
|
|
23
|
+
onyear?: () => void;
|
|
24
|
+
onselect?: (key: string | null) => void;
|
|
25
|
+
}
|
|
26
|
+
declare const Calendar: import("svelte").Component<Props, {}, "year" | "month" | "selected">;
|
|
27
|
+
type Calendar = ReturnType<typeof Calendar>;
|
|
28
|
+
export default Calendar;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
3
|
+
import Button from '../controls/Button.svelte'
|
|
4
|
+
import { MONTHS } from './dates'
|
|
5
|
+
|
|
6
|
+
// The twelve months as words, four to a row, the one shown lit. bind:month; `onpick`
|
|
7
|
+
// hears a pick (to close the pane it is in). For a Pane, under a Calendar.
|
|
8
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
month: number
|
|
10
|
+
months?: readonly string[]
|
|
11
|
+
short?: number // letters a name keeps: Jan, Feb
|
|
12
|
+
onpick?: (month: number) => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let { month = $bindable(), months = MONTHS, short = 3, onpick, class: className, ...rest }: Props = $props()
|
|
16
|
+
|
|
17
|
+
function pick(i: number) {
|
|
18
|
+
month = i
|
|
19
|
+
onpick?.(i)
|
|
20
|
+
}
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<div {...rest} class={['tui-months', className]} role="group" aria-label="Months">
|
|
24
|
+
{#each months as name, i (name)}
|
|
25
|
+
<Button variant="word" lit={i === month} aria-pressed={i === month} aria-label={name} onclick={() => pick(i)}
|
|
26
|
+
>{name.slice(0, short)}</Button
|
|
27
|
+
>
|
|
28
|
+
{/each}
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<style>
|
|
32
|
+
@layer tuidroid {
|
|
33
|
+
.tui-months {
|
|
34
|
+
display: grid;
|
|
35
|
+
grid-template-columns: repeat(4, 1fr);
|
|
36
|
+
gap: 0.4em 1ch;
|
|
37
|
+
justify-items: center;
|
|
38
|
+
padding: 0.3em 0 0.5em;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
month: number;
|
|
4
|
+
months?: readonly string[];
|
|
5
|
+
short?: number;
|
|
6
|
+
onpick?: (month: number) => void;
|
|
7
|
+
}
|
|
8
|
+
declare const MonthPicker: import("svelte").Component<Props, {}, "month">;
|
|
9
|
+
type MonthPicker = ReturnType<typeof MonthPicker>;
|
|
10
|
+
export default MonthPicker;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
3
|
+
import Button from '../controls/Button.svelte'
|
|
4
|
+
import ShuffleText from '../motion/ShuffleText.svelte'
|
|
5
|
+
|
|
6
|
+
// A year: < 2026 > a year at a time, and jumps either way under it (-5 -3 -1 +1 +3 +5),
|
|
7
|
+
// between `min` and `max`. Each change shows at once (bind:year). For a Pane, under a
|
|
8
|
+
// Calendar.
|
|
9
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
10
|
+
year: number
|
|
11
|
+
min?: number
|
|
12
|
+
max?: number
|
|
13
|
+
jumps?: readonly number[]
|
|
14
|
+
onpick?: (year: number) => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let { year = $bindable(), min = 1970, max = 2199, jumps = [-5, -3, -1, 1, 3, 5], onpick, class: className, ...rest }: Props = $props()
|
|
18
|
+
|
|
19
|
+
function go(by: number) {
|
|
20
|
+
year = Math.min(max, Math.max(min, year + by))
|
|
21
|
+
onpick?.(year)
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<div {...rest} class={['tui-years', className]}>
|
|
26
|
+
<div class="year">
|
|
27
|
+
<Button variant="glyph" aria-label="Previous year" disabled={year <= min} onclick={() => go(-1)}><</Button>
|
|
28
|
+
<strong><ShuffleText text={year} /></strong>
|
|
29
|
+
<Button variant="glyph" aria-label="Next year" disabled={year >= max} onclick={() => go(1)}>></Button>
|
|
30
|
+
</div>
|
|
31
|
+
<div class="jumps">
|
|
32
|
+
{#each jumps as by (by)}
|
|
33
|
+
<Button
|
|
34
|
+
variant="word"
|
|
35
|
+
aria-label="{by > 0 ? 'Forward' : 'Back'} {Math.abs(by)} {Math.abs(by) === 1 ? 'year' : 'years'}"
|
|
36
|
+
disabled={year + by < min || year + by > max}
|
|
37
|
+
onclick={() => go(by)}>{by > 0 ? `+${by}` : `-${-by}`}</Button
|
|
38
|
+
>
|
|
39
|
+
{/each}
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<style>
|
|
44
|
+
@layer tuidroid {
|
|
45
|
+
.year {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
gap: 2ch;
|
|
50
|
+
font-size: 1.3em;
|
|
51
|
+
padding-top: 0.2em;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.jumps {
|
|
55
|
+
display: flex;
|
|
56
|
+
flex-wrap: wrap;
|
|
57
|
+
justify-content: space-between;
|
|
58
|
+
padding: 0.4em 0 0.5em;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
year: number;
|
|
4
|
+
min?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
jumps?: readonly number[];
|
|
7
|
+
onpick?: (year: number) => void;
|
|
8
|
+
}
|
|
9
|
+
declare const YearPicker: import("svelte").Component<Props, {}, "year">;
|
|
10
|
+
type YearPicker = ReturnType<typeof YearPicker>;
|
|
11
|
+
export default YearPicker;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The weekday a week starts on, as Date.getDay counts: Sunday 0, Monday 1, Saturday 6. */
|
|
2
|
+
export type WeekStart = 0 | 1 | 6;
|
|
3
|
+
export declare const WEEKDAYS: readonly ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
4
|
+
export declare const MONTHS: readonly ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
5
|
+
/** The weekday heads from the first day of the week, in `names` (Sunday first). */
|
|
6
|
+
export declare const weekdayHeads: (start: WeekStart, names?: readonly string[]) => string[];
|
|
7
|
+
export interface WeekRow {
|
|
8
|
+
start: Date;
|
|
9
|
+
days: (number | null)[];
|
|
10
|
+
}
|
|
11
|
+
/** Six week rows for any month. */
|
|
12
|
+
export declare function monthRows(year: number, month: number, start?: WeekStart): WeekRow[];
|
|
13
|
+
/** The ISO 8601 week number of a date. */
|
|
14
|
+
export declare function isoWeek(at: Date): number;
|
|
15
|
+
/** A row's week number: the ISO week of its Thursday, whatever day the row starts on. */
|
|
16
|
+
export declare function rowWeek(row: WeekRow): number;
|
|
17
|
+
/** A day as "2026-11-22", in local time: a key for maps and comparisons. */
|
|
18
|
+
export declare function dayKey(at: Date): string;
|
|
19
|
+
/** The month `by` months from `month` of `year`, across years. */
|
|
20
|
+
export declare function addMonths(year: number, month: number, by: number): {
|
|
21
|
+
year: number;
|
|
22
|
+
month: number;
|
|
23
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// A calendar's arithmetic: months as six week rows from any first weekday, so a grid
|
|
2
|
+
// keeps its height from month to month; ISO week numbers; days as keys.
|
|
3
|
+
export const WEEKDAYS = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
|
|
4
|
+
export const MONTHS = [
|
|
5
|
+
'January',
|
|
6
|
+
'February',
|
|
7
|
+
'March',
|
|
8
|
+
'April',
|
|
9
|
+
'May',
|
|
10
|
+
'June',
|
|
11
|
+
'July',
|
|
12
|
+
'August',
|
|
13
|
+
'September',
|
|
14
|
+
'October',
|
|
15
|
+
'November',
|
|
16
|
+
'December',
|
|
17
|
+
];
|
|
18
|
+
/** The weekday heads from the first day of the week, in `names` (Sunday first). */
|
|
19
|
+
export const weekdayHeads = (start, names = WEEKDAYS) => Array.from({ length: 7 }, (_, i) => names[(start + i) % 7]);
|
|
20
|
+
/** Six week rows for any month. */
|
|
21
|
+
export function monthRows(year, month, start = 1) {
|
|
22
|
+
const lead = (new Date(year, month, 1).getDay() - start + 7) % 7;
|
|
23
|
+
const length = new Date(year, month + 1, 0).getDate();
|
|
24
|
+
return Array.from({ length: 6 }, (_, w) => ({
|
|
25
|
+
start: new Date(year, month, 1 - lead + w * 7),
|
|
26
|
+
days: Array.from({ length: 7 }, (_, d) => {
|
|
27
|
+
const n = 1 - lead + w * 7 + d;
|
|
28
|
+
return n >= 1 && n <= length ? n : null;
|
|
29
|
+
}),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
/** The ISO 8601 week number of a date. */
|
|
33
|
+
export function isoWeek(at) {
|
|
34
|
+
const d = new Date(Date.UTC(at.getFullYear(), at.getMonth(), at.getDate()));
|
|
35
|
+
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7)); // the Thursday of its week
|
|
36
|
+
const yearStart = Date.UTC(d.getUTCFullYear(), 0, 1);
|
|
37
|
+
return Math.ceil(((d.getTime() - yearStart) / 86_400_000 + 1) / 7);
|
|
38
|
+
}
|
|
39
|
+
/** A row's week number: the ISO week of its Thursday, whatever day the row starts on. */
|
|
40
|
+
export function rowWeek(row) {
|
|
41
|
+
const thursday = new Date(row.start);
|
|
42
|
+
thursday.setDate(thursday.getDate() + ((4 - row.start.getDay() + 7) % 7));
|
|
43
|
+
return isoWeek(thursday);
|
|
44
|
+
}
|
|
45
|
+
/** A day as "2026-11-22", in local time: a key for maps and comparisons. */
|
|
46
|
+
export function dayKey(at) {
|
|
47
|
+
const two = (n) => String(n).padStart(2, '0');
|
|
48
|
+
return `${at.getFullYear()}-${two(at.getMonth() + 1)}-${two(at.getDate())}`;
|
|
49
|
+
}
|
|
50
|
+
/** The month `by` months from `month` of `year`, across years. */
|
|
51
|
+
export function addMonths(year, month, by) {
|
|
52
|
+
const d = new Date(year, month + by, 1);
|
|
53
|
+
return { year: d.getFullYear(), month: d.getMonth() };
|
|
54
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export interface ChartBar {
|
|
3
|
+
/** Stacked from the bottom, each in its colour (the accent by default). */
|
|
4
|
+
segments: readonly { value: number; colour?: string }[]
|
|
5
|
+
/** A line across the bar at this value: a goal it fell short of. */
|
|
6
|
+
mark?: number
|
|
7
|
+
label?: string
|
|
8
|
+
}
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import type { Snippet } from 'svelte'
|
|
13
|
+
import ChartFrame, { type ChartSize } from './ChartFrame.svelte'
|
|
14
|
+
import { nextPick, niceScale } from './scale'
|
|
15
|
+
|
|
16
|
+
// Bars side by side, each stacked from its segments (a fast's hours by stage, a day's
|
|
17
|
+
// reviews and new words), newest at the right: as many as fit `minPitch` px apiece. A
|
|
18
|
+
// `mark` draws a line across a bar at that value if the bar falls short of it. Rules at
|
|
19
|
+
// the axis's steps, labelled at the left through `format`. Tap or drag to pick one:
|
|
20
|
+
// `readout` says what it is, `caption` what the chart shows while none is.
|
|
21
|
+
interface Props {
|
|
22
|
+
bars: readonly ChartBar[]
|
|
23
|
+
label: string
|
|
24
|
+
height?: string
|
|
25
|
+
max?: number // the axis's top at least
|
|
26
|
+
step?: number // the axis's step; round by default
|
|
27
|
+
format?: (value: number) => string
|
|
28
|
+
gutter?: number // room at the left for the labels, in characters
|
|
29
|
+
minPitch?: number
|
|
30
|
+
maxPitch?: number
|
|
31
|
+
picked?: number | null
|
|
32
|
+
readout?: Snippet<[ChartBar, number]>
|
|
33
|
+
caption?: Snippet
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let {
|
|
37
|
+
bars,
|
|
38
|
+
label,
|
|
39
|
+
height = '6.5em',
|
|
40
|
+
max = 0,
|
|
41
|
+
step,
|
|
42
|
+
format = String,
|
|
43
|
+
gutter = 5,
|
|
44
|
+
minPitch = 4,
|
|
45
|
+
maxPitch = 16,
|
|
46
|
+
picked = $bindable(null),
|
|
47
|
+
readout,
|
|
48
|
+
caption,
|
|
49
|
+
}: Props = $props()
|
|
50
|
+
|
|
51
|
+
let size = $state<ChartSize>({ width: 0, height: 0, ch: 8, em: 16 })
|
|
52
|
+
|
|
53
|
+
const total = (bar: ChartBar) => bar.segments.reduce((sum, s) => sum + Math.max(0, s.value), 0)
|
|
54
|
+
const scale = $derived(niceScale(0, Math.max(max, ...bars.map((b) => Math.max(total(b), b.mark ?? 0))) || 1, { step }))
|
|
55
|
+
const left = $derived(gutter * size.ch)
|
|
56
|
+
const plot = $derived(Math.max(0, size.width - left))
|
|
57
|
+
const first = $derived(Math.max(0, bars.length - Math.max(1, Math.floor(plot / minPitch))))
|
|
58
|
+
const pitch = $derived(Math.min(maxPitch, plot / Math.max(1, bars.length - first)))
|
|
59
|
+
const barWidth = $derived(Math.max(1, pitch - (pitch > 6 ? 2 : 1)))
|
|
60
|
+
const y = (v: number) => 4 + (1 - (v - scale.from) / (scale.to - scale.from)) * (size.height - 8)
|
|
61
|
+
|
|
62
|
+
// Each shown bar as rects, its segments stacked from the bottom.
|
|
63
|
+
const drawn = $derived(
|
|
64
|
+
bars.slice(first).map((bar, i) => {
|
|
65
|
+
let from = 0
|
|
66
|
+
const rects = bar.segments.map((segment) => {
|
|
67
|
+
const value = Math.max(0, segment.value)
|
|
68
|
+
const rect = { y: y(from + value), height: y(from) - y(from + value), colour: segment.colour ?? 'var(--tui-accent)' }
|
|
69
|
+
from += value
|
|
70
|
+
return rect
|
|
71
|
+
})
|
|
72
|
+
const short = bar.mark !== undefined && from < bar.mark
|
|
73
|
+
return { at: first + i, x: left + i * pitch, rects, mark: short ? y(bar.mark!) - 1 : null, title: bar.label }
|
|
74
|
+
}),
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
function onpick(x: number, _y: number, tap: boolean) {
|
|
78
|
+
const i = Math.floor((x - left) / pitch)
|
|
79
|
+
picked = nextPick(picked, pitch && i >= 0 && i < drawn.length ? first + i : null, tap)
|
|
80
|
+
}
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
{#snippet below()}{#if picked !== null && bars[picked]}{@render readout?.(bars[picked], picked)}{:else}{@render caption?.()}{/if}{/snippet}
|
|
84
|
+
|
|
85
|
+
<ChartFrame {label} {height} bind:size {onpick} below={readout || caption ? below : undefined}>
|
|
86
|
+
{#each scale.ticks.slice(1) as value (value)}
|
|
87
|
+
<line class="rule" x1={left} x2={size.width} y1={y(value)} y2={y(value)} />
|
|
88
|
+
<text class="axis" x={left - size.ch} y={y(value)} text-anchor="end" dominant-baseline="central">{format(value)}</text>
|
|
89
|
+
{/each}
|
|
90
|
+
{#each drawn as bar (bar.at)}
|
|
91
|
+
<g class:dim={picked !== null && picked !== bar.at}>
|
|
92
|
+
{#if bar.title}<title>{bar.title}</title>{/if}
|
|
93
|
+
{#each bar.rects as rect, s (s)}<rect x={bar.x} y={rect.y} width={barWidth} height={rect.height} style:fill={rect.colour} />{/each}
|
|
94
|
+
{#if bar.mark !== null}<rect class="mark" x={bar.x} y={bar.mark} width={barWidth} height="2" />{/if}
|
|
95
|
+
</g>
|
|
96
|
+
{/each}
|
|
97
|
+
<line class="base" x1={left} x2={size.width} y1={y(0)} y2={y(0)} />
|
|
98
|
+
</ChartFrame>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface ChartBar {
|
|
2
|
+
/** Stacked from the bottom, each in its colour (the accent by default). */
|
|
3
|
+
segments: readonly {
|
|
4
|
+
value: number;
|
|
5
|
+
colour?: string;
|
|
6
|
+
}[];
|
|
7
|
+
/** A line across the bar at this value: a goal it fell short of. */
|
|
8
|
+
mark?: number;
|
|
9
|
+
label?: string;
|
|
10
|
+
}
|
|
11
|
+
import type { Snippet } from 'svelte';
|
|
12
|
+
interface Props {
|
|
13
|
+
bars: readonly ChartBar[];
|
|
14
|
+
label: string;
|
|
15
|
+
height?: string;
|
|
16
|
+
max?: number;
|
|
17
|
+
step?: number;
|
|
18
|
+
format?: (value: number) => string;
|
|
19
|
+
gutter?: number;
|
|
20
|
+
minPitch?: number;
|
|
21
|
+
maxPitch?: number;
|
|
22
|
+
picked?: number | null;
|
|
23
|
+
readout?: Snippet<[ChartBar, number]>;
|
|
24
|
+
caption?: Snippet;
|
|
25
|
+
}
|
|
26
|
+
declare const BarChart: import("svelte").Component<Props, {}, "picked">;
|
|
27
|
+
type BarChart = ReturnType<typeof BarChart>;
|
|
28
|
+
export default BarChart;
|