tuidroid 0.0.0-stage → 0.1.1
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,35 @@
|
|
|
1
|
+
// Axes for the charts: round steps a person reads at a glance (1, 2, 2.5 or 5 times a
|
|
2
|
+
// power of ten), and the picking of a mark by tap or drag.
|
|
3
|
+
import { tick } from '../haptics';
|
|
4
|
+
/** A step near `span / count`, rounded to 1, 2, 2.5 or 5 times a power of ten. */
|
|
5
|
+
export function niceStep(span, count = 4) {
|
|
6
|
+
if (!(span > 0))
|
|
7
|
+
return 1;
|
|
8
|
+
const raw = span / count;
|
|
9
|
+
const power = 10 ** Math.floor(Math.log10(raw));
|
|
10
|
+
const fraction = raw / power;
|
|
11
|
+
const nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 2.5 ? 2.5 : fraction <= 5 ? 5 : 10;
|
|
12
|
+
return nice * power;
|
|
13
|
+
}
|
|
14
|
+
/** An axis from `min` to `max` widened to whole steps, about `count` of them. A given
|
|
15
|
+
* `step` is used as it is (12 for hours, say). */
|
|
16
|
+
export function niceScale(min, max, { count = 4, step } = {}) {
|
|
17
|
+
const span = max > min ? max - min : Math.abs(max) || 1;
|
|
18
|
+
const by = step ?? niceStep(span, count);
|
|
19
|
+
const from = Math.floor(min / by) * by;
|
|
20
|
+
const to = Math.max(from + by, Math.ceil(max / by) * by);
|
|
21
|
+
const decimals = (String(by).split('.')[1] ?? '').length;
|
|
22
|
+
const ticks = Array.from({ length: Math.round((to - from) / by) + 1 }, (_, i) => Number((from + i * by).toFixed(decimals)));
|
|
23
|
+
return { from, to, step: by, ticks };
|
|
24
|
+
}
|
|
25
|
+
/** What is picked after a tap or a drag lands `at` a mark: a tap on the picked one lets
|
|
26
|
+
* go of it, a drag onto another picks it with a haptic tick. */
|
|
27
|
+
export function nextPick(current, at, tap) {
|
|
28
|
+
if (at === null)
|
|
29
|
+
return current;
|
|
30
|
+
if (tap)
|
|
31
|
+
return current === at ? null : at;
|
|
32
|
+
if (current !== at)
|
|
33
|
+
tick();
|
|
34
|
+
return at;
|
|
35
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ACCENTS, colourName, ctp, type Accent } from '../theme/palette'
|
|
3
|
+
import OptionStepper, { type OptionStepperProps } from './OptionStepper.svelte'
|
|
4
|
+
|
|
5
|
+
// A colour picked from Catppuccin's fourteen accents with < >: a bar in the colour and
|
|
6
|
+
// its name, round the ends. bind:value.
|
|
7
|
+
interface Props extends Omit<OptionStepperProps<Accent>, 'options' | 'format' | 'wrap' | 'children'> {
|
|
8
|
+
value: Accent
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let { value = $bindable(), ...rest }: Props = $props()
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<OptionStepper {...rest} bind:value options={ACCENTS} format={colourName} wrap>
|
|
15
|
+
{#snippet children(accent)}<span style:color={ctp(accent)}>████</span> <span class="name">{colourName(accent)}</span>{/snippet}
|
|
16
|
+
</OptionStepper>
|
|
17
|
+
|
|
18
|
+
<style>
|
|
19
|
+
@layer tuidroid {
|
|
20
|
+
.name {
|
|
21
|
+
color: var(--tui-fg);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
</style>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Accent } from '../theme/palette';
|
|
2
|
+
import { type OptionStepperProps } from './OptionStepper.svelte';
|
|
3
|
+
interface Props extends Omit<OptionStepperProps<Accent>, 'options' | 'format' | 'wrap' | 'children'> {
|
|
4
|
+
value: Accent;
|
|
5
|
+
}
|
|
6
|
+
declare const AccentStepper: import("svelte").Component<Props, {}, "value">;
|
|
7
|
+
type AccentStepper = ReturnType<typeof AccentStepper>;
|
|
8
|
+
export default AccentStepper;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
/** How a button is drawn:
|
|
3
|
+
* - box: a surface fill in a rounded border, the default
|
|
4
|
+
* - word: [ on ], brackets muted and the word in the accent; a press lights it
|
|
5
|
+
* - glyph: a bare character or icon (< > ✕) with room around it for a finger
|
|
6
|
+
* - edge: words set into a Block's border, cut out of the line like a title
|
|
7
|
+
* - gate: large text in the accent filling its area, the whole area the button
|
|
8
|
+
* - link: in running text, accent with a dotted underline */
|
|
9
|
+
export type ButtonVariant = 'box' | 'word' | 'glyph' | 'edge' | 'gate' | 'link'
|
|
10
|
+
|
|
11
|
+
export interface ButtonProps extends HTMLButtonAttributes {
|
|
12
|
+
variant?: ButtonVariant
|
|
13
|
+
icon?: IconName | IconPath
|
|
14
|
+
primary?: boolean
|
|
15
|
+
quit?: boolean
|
|
16
|
+
lead?: boolean // a word starting its own line: its bracket in line with the text above
|
|
17
|
+
lit?: boolean // a word lit like a press that stays: the month a picker shows
|
|
18
|
+
confirm?: string
|
|
19
|
+
armMs?: number
|
|
20
|
+
children?: Snippet
|
|
21
|
+
}
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<script lang="ts">
|
|
25
|
+
import { onDestroy, type Snippet } from 'svelte'
|
|
26
|
+
import type { HTMLButtonAttributes } from 'svelte/elements'
|
|
27
|
+
import Icon, { type IconPath } from '../icons/Icon.svelte'
|
|
28
|
+
import type { IconName } from '../icons/material'
|
|
29
|
+
|
|
30
|
+
// A button, TUI style. `icon` goes before the words in the accent; `primary` is the one
|
|
31
|
+
// action the screen is for; `quit` closes, cancels, discards or deletes, its icon in red.
|
|
32
|
+
// With `confirm` it acts on a second press: the first arms it, showing that text in red,
|
|
33
|
+
// until a press elsewhere, a blur or `armMs` passes.
|
|
34
|
+
let {
|
|
35
|
+
variant = 'box',
|
|
36
|
+
icon,
|
|
37
|
+
primary = false,
|
|
38
|
+
quit = false,
|
|
39
|
+
lead = false,
|
|
40
|
+
lit = false,
|
|
41
|
+
confirm,
|
|
42
|
+
armMs = 3000,
|
|
43
|
+
type = 'button',
|
|
44
|
+
children,
|
|
45
|
+
onclick,
|
|
46
|
+
onblur,
|
|
47
|
+
class: className,
|
|
48
|
+
...rest
|
|
49
|
+
}: ButtonProps = $props()
|
|
50
|
+
|
|
51
|
+
let armed = $state(false)
|
|
52
|
+
let disarm = 0
|
|
53
|
+
|
|
54
|
+
function click(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
|
|
55
|
+
if (confirm && !armed) {
|
|
56
|
+
armed = true
|
|
57
|
+
clearTimeout(disarm)
|
|
58
|
+
disarm = window.setTimeout(() => (armed = false), armMs)
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
armed = false
|
|
62
|
+
clearTimeout(disarm)
|
|
63
|
+
onclick?.(event)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function blur(event: FocusEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
|
|
67
|
+
armed = false
|
|
68
|
+
onblur?.(event)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
onDestroy(() => clearTimeout(disarm))
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
<button {...rest} {type} class={['tui-button', variant, className, { primary, quit, lead, lit, armed }]} onclick={click} onblur={blur}
|
|
75
|
+
>{#if variant === 'word'}<span class="bracket" aria-hidden="true">{'[ '}</span>{/if}{#if icon}<span class="tui-button-icon"
|
|
76
|
+
><Icon {icon} /></span
|
|
77
|
+
>{/if}{#if armed}{confirm}{:else}{@render children?.()}{/if}{#if variant === 'word'}<span class="bracket" aria-hidden="true"
|
|
78
|
+
>{' ]'}</span
|
|
79
|
+
>{/if}</button
|
|
80
|
+
>
|
|
81
|
+
|
|
82
|
+
<style>
|
|
83
|
+
@layer tuidroid {
|
|
84
|
+
.tui-button {
|
|
85
|
+
font: inherit;
|
|
86
|
+
color: inherit;
|
|
87
|
+
touch-action: manipulation;
|
|
88
|
+
-webkit-tap-highlight-color: transparent;
|
|
89
|
+
cursor: pointer;
|
|
90
|
+
transition:
|
|
91
|
+
color var(--tui-fade) ease,
|
|
92
|
+
background-color var(--tui-fade) ease-out;
|
|
93
|
+
|
|
94
|
+
&:disabled {
|
|
95
|
+
cursor: default;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
&:focus-visible {
|
|
99
|
+
outline: 1px solid var(--tui-accent);
|
|
100
|
+
outline-offset: 2px;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
&.armed {
|
|
104
|
+
color: var(--tui-bad);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* A Material icon before the words, in the accent; red on what quits. */
|
|
109
|
+
.tui-button-icon {
|
|
110
|
+
color: var(--tui-accent);
|
|
111
|
+
margin-right: 0.6ch;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.quit .tui-button-icon {
|
|
115
|
+
color: var(--tui-bad);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* box: surface fill, rounded 1px border, a 1px press. */
|
|
119
|
+
.box {
|
|
120
|
+
background: var(--tui-button);
|
|
121
|
+
border: 1px solid var(--tui-button-border);
|
|
122
|
+
border-radius: var(--tui-radius);
|
|
123
|
+
padding: 0.3em 1ch;
|
|
124
|
+
|
|
125
|
+
&.primary {
|
|
126
|
+
border-color: var(--tui-accent);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
&:active:not(:disabled) {
|
|
130
|
+
transform: translateY(1px);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
&:disabled {
|
|
134
|
+
opacity: 0.45;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* word: [ on ]. The brackets muted, the word in the accent; a press lights it all in
|
|
139
|
+
the accent and the light fades once released, so a tap is seen landing. Not
|
|
140
|
+
pressed (aria-pressed="false"), it reads muted, so what is on stands out. */
|
|
141
|
+
.word {
|
|
142
|
+
padding: 0.35em 0.3ch;
|
|
143
|
+
background: none;
|
|
144
|
+
border: none;
|
|
145
|
+
border-radius: 0.3em;
|
|
146
|
+
color: var(--tui-accent);
|
|
147
|
+
white-space: nowrap;
|
|
148
|
+
|
|
149
|
+
/* Drawn, not read: hidden from screen readers, so the name is the word alone. */
|
|
150
|
+
& .bracket {
|
|
151
|
+
color: var(--tui-muted);
|
|
152
|
+
white-space: pre;
|
|
153
|
+
transition: color var(--tui-fade) ease-out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
&[aria-pressed='false'] {
|
|
157
|
+
color: var(--tui-muted);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
&.primary {
|
|
161
|
+
font-weight: 700;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
&.lead {
|
|
165
|
+
margin-left: -0.3ch;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
&.armed {
|
|
169
|
+
color: var(--tui-bad);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
&:active:not(:disabled),
|
|
173
|
+
&:active:not(:disabled) .bracket,
|
|
174
|
+
&.lit,
|
|
175
|
+
&.lit .bracket {
|
|
176
|
+
background: var(--tui-accent);
|
|
177
|
+
color: var(--tui-bg);
|
|
178
|
+
transition: none;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
&:disabled {
|
|
182
|
+
opacity: 0.45;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* glyph: a bare character as a button, in the accent, room around it for a finger. */
|
|
187
|
+
.glyph {
|
|
188
|
+
min-width: 2.4em;
|
|
189
|
+
padding: 0.35em 0.6ch;
|
|
190
|
+
background: none;
|
|
191
|
+
border: none;
|
|
192
|
+
color: var(--tui-accent);
|
|
193
|
+
font-size: 1.15em;
|
|
194
|
+
line-height: 1;
|
|
195
|
+
user-select: none;
|
|
196
|
+
-webkit-user-select: none;
|
|
197
|
+
|
|
198
|
+
& .tui-button-icon {
|
|
199
|
+
margin: 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
&.quit {
|
|
203
|
+
color: var(--tui-bad);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
&:disabled {
|
|
207
|
+
opacity: 0.45;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/* edge: on a Block's border, cut out of the line by the background like a title, with
|
|
212
|
+
a tap area reaching above and below the line. The primary one is bold in the
|
|
213
|
+
accent; a disabled one turns muted, as opacity would let the line show through. */
|
|
214
|
+
.edge {
|
|
215
|
+
background: var(--tui-block-cut, var(--tui-bg));
|
|
216
|
+
border: none;
|
|
217
|
+
border-radius: 0;
|
|
218
|
+
padding: 0.6em 0.7ch;
|
|
219
|
+
line-height: 1.2;
|
|
220
|
+
white-space: nowrap;
|
|
221
|
+
|
|
222
|
+
&.primary {
|
|
223
|
+
color: var(--tui-accent);
|
|
224
|
+
font-weight: 700;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
&:disabled {
|
|
228
|
+
color: var(--tui-muted);
|
|
229
|
+
|
|
230
|
+
& .tui-button-icon {
|
|
231
|
+
color: inherit;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/* gate: plain large text in the accent; the whole area is the button. */
|
|
237
|
+
.gate {
|
|
238
|
+
width: 100%;
|
|
239
|
+
height: 100%;
|
|
240
|
+
padding: 0;
|
|
241
|
+
font-size: 2.5em;
|
|
242
|
+
color: var(--tui-accent);
|
|
243
|
+
background: none;
|
|
244
|
+
border: none;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/* link: in running text, part of the sentence and still something to tap. */
|
|
248
|
+
.link {
|
|
249
|
+
padding: 0;
|
|
250
|
+
background: none;
|
|
251
|
+
border: none;
|
|
252
|
+
border-radius: 0;
|
|
253
|
+
color: var(--tui-accent);
|
|
254
|
+
text-decoration: underline dotted;
|
|
255
|
+
text-underline-offset: 0.2em;
|
|
256
|
+
transition: none;
|
|
257
|
+
|
|
258
|
+
&:active:not(:disabled) {
|
|
259
|
+
background: var(--tui-accent);
|
|
260
|
+
color: var(--tui-bg);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
</style>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** How a button is drawn:
|
|
2
|
+
* - box: a surface fill in a rounded border, the default
|
|
3
|
+
* - word: [ on ], brackets muted and the word in the accent; a press lights it
|
|
4
|
+
* - glyph: a bare character or icon (< > ✕) with room around it for a finger
|
|
5
|
+
* - edge: words set into a Block's border, cut out of the line like a title
|
|
6
|
+
* - gate: large text in the accent filling its area, the whole area the button
|
|
7
|
+
* - link: in running text, accent with a dotted underline */
|
|
8
|
+
export type ButtonVariant = 'box' | 'word' | 'glyph' | 'edge' | 'gate' | 'link';
|
|
9
|
+
export interface ButtonProps extends HTMLButtonAttributes {
|
|
10
|
+
variant?: ButtonVariant;
|
|
11
|
+
icon?: IconName | IconPath;
|
|
12
|
+
primary?: boolean;
|
|
13
|
+
quit?: boolean;
|
|
14
|
+
lead?: boolean;
|
|
15
|
+
lit?: boolean;
|
|
16
|
+
confirm?: string;
|
|
17
|
+
armMs?: number;
|
|
18
|
+
children?: Snippet;
|
|
19
|
+
}
|
|
20
|
+
import { type Snippet } from 'svelte';
|
|
21
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
22
|
+
import { type IconPath } from '../icons/Icon.svelte';
|
|
23
|
+
import type { IconName } from '../icons/material';
|
|
24
|
+
declare const Button: import("svelte").Component<ButtonProps, {}, "">;
|
|
25
|
+
type Button = ReturnType<typeof Button>;
|
|
26
|
+
export default Button;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script lang="ts" generics="T">
|
|
2
|
+
import ShuffleText from '../motion/ShuffleText.svelte'
|
|
3
|
+
import Button, { type ButtonProps } from './Button.svelte'
|
|
4
|
+
|
|
5
|
+
// A choice as a word that steps to the next of its `options` on each press, round the
|
|
6
|
+
// end: [ System ] → [ On ] → [ Off ]. Its word shuffles into the new one. bind:value.
|
|
7
|
+
// `name` is what a screen reader hears before the choice.
|
|
8
|
+
interface Props extends Omit<ButtonProps, 'variant' | 'children' | 'onchange' | 'value'> {
|
|
9
|
+
value: T
|
|
10
|
+
options: readonly T[]
|
|
11
|
+
format?: (option: T) => string
|
|
12
|
+
name?: string
|
|
13
|
+
onchange?: (value: T) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let { value = $bindable(), options, format = String, name, onchange, onclick, ...rest }: Props = $props()
|
|
17
|
+
|
|
18
|
+
function next(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
|
|
19
|
+
value = options[(options.indexOf(value) + 1) % options.length]
|
|
20
|
+
onchange?.(value)
|
|
21
|
+
onclick?.(event)
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<Button {...rest} variant="word" aria-label={name && `${name}: ${format(value)}`} onclick={next}
|
|
26
|
+
><ShuffleText text={format(value)} /></Button
|
|
27
|
+
>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ButtonProps } from './Button.svelte';
|
|
2
|
+
declare function $$render<T>(): {
|
|
3
|
+
props: Omit<ButtonProps, "children" | "onchange" | "value" | "variant"> & {
|
|
4
|
+
value: T;
|
|
5
|
+
options: readonly T[];
|
|
6
|
+
format?: (option: T) => string;
|
|
7
|
+
name?: string;
|
|
8
|
+
onchange?: (value: T) => void;
|
|
9
|
+
};
|
|
10
|
+
exports: {};
|
|
11
|
+
bindings: "value";
|
|
12
|
+
slots: {};
|
|
13
|
+
events: {};
|
|
14
|
+
};
|
|
15
|
+
declare class __sveltets_Render<T> {
|
|
16
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
17
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
18
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
19
|
+
bindings(): "value";
|
|
20
|
+
exports(): {};
|
|
21
|
+
}
|
|
22
|
+
interface $$IsomorphicComponent {
|
|
23
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
24
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
25
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
26
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
27
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
28
|
+
}
|
|
29
|
+
declare const Cycle: $$IsomorphicComponent;
|
|
30
|
+
type Cycle<T> = InstanceType<typeof Cycle<T>>;
|
|
31
|
+
export default Cycle;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Stepper, { type StepperProps } from './Stepper.svelte'
|
|
3
|
+
|
|
4
|
+
// A number set with < >, from `min` to `max` by `step`, shown through `format` ("16h",
|
|
5
|
+
// "180 cm"). It holds the value: bind:value. `onchange` hears each change, with whether
|
|
6
|
+
// it was one of a repeat or a scrub.
|
|
7
|
+
interface Props extends Omit<StepperProps, 'value' | 'onstep' | 'atStart' | 'atEnd' | 'onchange'> {
|
|
8
|
+
value: number
|
|
9
|
+
min?: number
|
|
10
|
+
max?: number
|
|
11
|
+
step?: number
|
|
12
|
+
format?: (value: number) => string
|
|
13
|
+
onchange?: (value: number, repeating: boolean) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let { value = $bindable(), min = -Infinity, max = Infinity, step = 1, format = String, onchange, ...rest }: Props = $props()
|
|
17
|
+
|
|
18
|
+
// Steps land on the grid of `step` from `min`, so float error never builds up.
|
|
19
|
+
const decimals = $derived((String(step).split('.')[1] ?? '').length)
|
|
20
|
+
function onstep(direction: -1 | 1, repeating: boolean) {
|
|
21
|
+
const next = Number(Math.min(max, Math.max(min, value + direction * step)).toFixed(decimals))
|
|
22
|
+
if (next === value) return
|
|
23
|
+
value = next
|
|
24
|
+
onchange?.(next, repeating)
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<Stepper {...rest} value={format(value)} {onstep} atStart={value <= min} atEnd={value >= max} />
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type StepperProps } from './Stepper.svelte';
|
|
2
|
+
interface Props extends Omit<StepperProps, 'value' | 'onstep' | 'atStart' | 'atEnd' | 'onchange'> {
|
|
3
|
+
value: number;
|
|
4
|
+
min?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
step?: number;
|
|
7
|
+
format?: (value: number) => string;
|
|
8
|
+
onchange?: (value: number, repeating: boolean) => void;
|
|
9
|
+
}
|
|
10
|
+
declare const NumberStepper: import("svelte").Component<Props, {}, "value">;
|
|
11
|
+
type NumberStepper = ReturnType<typeof NumberStepper>;
|
|
12
|
+
export default NumberStepper;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte'
|
|
3
|
+
import type { StepperProps } from './Stepper.svelte'
|
|
4
|
+
|
|
5
|
+
export interface OptionStepperProps<T> extends Omit<StepperProps, 'value' | 'onstep' | 'atStart' | 'atEnd' | 'onchange' | 'children'> {
|
|
6
|
+
value: T
|
|
7
|
+
options: readonly T[]
|
|
8
|
+
format?: (option: T) => string
|
|
9
|
+
wrap?: boolean
|
|
10
|
+
onchange?: (value: T, repeating: boolean) => void
|
|
11
|
+
children?: Snippet<[T]>
|
|
12
|
+
}
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script lang="ts" generics="T">
|
|
16
|
+
import Stepper from './Stepper.svelte'
|
|
17
|
+
|
|
18
|
+
// One of a list of `options` set with < >, shown through `format`, or `children` for
|
|
19
|
+
// markup (a colour's bar). With `wrap` it goes round the ends; without, the ends stop it.
|
|
20
|
+
// It holds the choice: bind:value.
|
|
21
|
+
let { value = $bindable(), options, format = String, wrap = false, onchange, children, ...rest }: OptionStepperProps<T> = $props()
|
|
22
|
+
|
|
23
|
+
const at = $derived(options.indexOf(value))
|
|
24
|
+
function onstep(direction: -1 | 1, repeating: boolean) {
|
|
25
|
+
const n = options.length
|
|
26
|
+
const next = wrap ? (at + direction + n) % n : Math.min(n - 1, Math.max(0, at + direction))
|
|
27
|
+
if (next === at) return
|
|
28
|
+
value = options[next]
|
|
29
|
+
onchange?.(value, repeating)
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
{#snippet shown()}{@render children?.(value)}{/snippet}
|
|
34
|
+
|
|
35
|
+
<Stepper
|
|
36
|
+
{...rest}
|
|
37
|
+
value={format(value)}
|
|
38
|
+
children={children ? shown : undefined}
|
|
39
|
+
{onstep}
|
|
40
|
+
atStart={!wrap && at <= 0}
|
|
41
|
+
atEnd={!wrap && at >= options.length - 1}
|
|
42
|
+
/>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { StepperProps } from './Stepper.svelte';
|
|
3
|
+
export interface OptionStepperProps<T> extends Omit<StepperProps, 'value' | 'onstep' | 'atStart' | 'atEnd' | 'onchange' | 'children'> {
|
|
4
|
+
value: T;
|
|
5
|
+
options: readonly T[];
|
|
6
|
+
format?: (option: T) => string;
|
|
7
|
+
wrap?: boolean;
|
|
8
|
+
onchange?: (value: T, repeating: boolean) => void;
|
|
9
|
+
children?: Snippet<[T]>;
|
|
10
|
+
}
|
|
11
|
+
declare function $$render<T>(): {
|
|
12
|
+
props: OptionStepperProps<T>;
|
|
13
|
+
exports: {};
|
|
14
|
+
bindings: "value";
|
|
15
|
+
slots: {};
|
|
16
|
+
events: {};
|
|
17
|
+
};
|
|
18
|
+
declare class __sveltets_Render<T> {
|
|
19
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
20
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
21
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
22
|
+
bindings(): "value";
|
|
23
|
+
exports(): {};
|
|
24
|
+
}
|
|
25
|
+
interface $$IsomorphicComponent {
|
|
26
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
27
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
28
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
29
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
30
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
31
|
+
}
|
|
32
|
+
declare const OptionStepper: $$IsomorphicComponent;
|
|
33
|
+
type OptionStepper<T> = InstanceType<typeof OptionStepper<T>>;
|
|
34
|
+
export default OptionStepper;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export interface Segment<T> {
|
|
3
|
+
value: T
|
|
4
|
+
label: string
|
|
5
|
+
}
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<script lang="ts" generics="T">
|
|
9
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
10
|
+
|
|
11
|
+
// A few choices side by side as bare words, the chosen one bold in the accent, the rest
|
|
12
|
+
// muted: Stats' 30d 90d 1y all. Made to sit in a Block's top edge (headingRight), its
|
|
13
|
+
// tap areas reaching above and below the line. bind:value; pressing the chosen one
|
|
14
|
+
// again calls `onreselect` (to fold a range open again, say).
|
|
15
|
+
interface Props extends Omit<HTMLAttributes<HTMLSpanElement>, 'onchange'> {
|
|
16
|
+
value: T
|
|
17
|
+
options: readonly Segment<T>[]
|
|
18
|
+
label: string // what the group is, for a screen reader
|
|
19
|
+
onchange?: (value: T) => void
|
|
20
|
+
onreselect?: (value: T) => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let { value = $bindable(), options, label, onchange, onreselect, class: className, ...rest }: Props = $props()
|
|
24
|
+
|
|
25
|
+
function choose(option: T) {
|
|
26
|
+
if (option === value) return onreselect?.(option)
|
|
27
|
+
value = option
|
|
28
|
+
onchange?.(option)
|
|
29
|
+
}
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<span {...rest} class={['tui-segmented', className]} role="group" aria-label={label}>
|
|
33
|
+
{#each options as option (option.value)}
|
|
34
|
+
<button type="button" class:on={option.value === value} aria-pressed={option.value === value} onclick={() => choose(option.value)}
|
|
35
|
+
>{option.label}</button
|
|
36
|
+
>
|
|
37
|
+
{/each}
|
|
38
|
+
</span>
|
|
39
|
+
|
|
40
|
+
<style>
|
|
41
|
+
@layer tuidroid {
|
|
42
|
+
.tui-segmented {
|
|
43
|
+
display: inline-flex;
|
|
44
|
+
gap: 0.4ch;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
button {
|
|
48
|
+
margin: -0.45em 0;
|
|
49
|
+
padding: 0.45em 0.5ch;
|
|
50
|
+
font: inherit;
|
|
51
|
+
line-height: 1.2;
|
|
52
|
+
background: none;
|
|
53
|
+
border: none;
|
|
54
|
+
border-radius: 0;
|
|
55
|
+
color: var(--tui-muted);
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
touch-action: manipulation;
|
|
58
|
+
-webkit-tap-highlight-color: transparent;
|
|
59
|
+
transition: color var(--tui-fade) ease;
|
|
60
|
+
|
|
61
|
+
&.on {
|
|
62
|
+
color: var(--tui-accent);
|
|
63
|
+
font-weight: 700;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&:focus-visible {
|
|
67
|
+
outline: 1px solid var(--tui-accent);
|
|
68
|
+
outline-offset: -2px;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
</style>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface Segment<T> {
|
|
2
|
+
value: T;
|
|
3
|
+
label: string;
|
|
4
|
+
}
|
|
5
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
|
+
declare function $$render<T>(): {
|
|
7
|
+
props: Omit<HTMLAttributes<HTMLSpanElement>, "onchange"> & {
|
|
8
|
+
value: T;
|
|
9
|
+
options: readonly Segment<T>[];
|
|
10
|
+
label: string;
|
|
11
|
+
onchange?: (value: T) => void;
|
|
12
|
+
onreselect?: (value: T) => void;
|
|
13
|
+
};
|
|
14
|
+
exports: {};
|
|
15
|
+
bindings: "value";
|
|
16
|
+
slots: {};
|
|
17
|
+
events: {};
|
|
18
|
+
};
|
|
19
|
+
declare class __sveltets_Render<T> {
|
|
20
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
21
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
22
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
23
|
+
bindings(): "value";
|
|
24
|
+
exports(): {};
|
|
25
|
+
}
|
|
26
|
+
interface $$IsomorphicComponent {
|
|
27
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
28
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
29
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
30
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
31
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
32
|
+
}
|
|
33
|
+
declare const Segmented: $$IsomorphicComponent;
|
|
34
|
+
type Segmented<T> = InstanceType<typeof Segmented<T>>;
|
|
35
|
+
export default Segmented;
|