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,158 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { IconPath } from '../icons/Icon.svelte'
|
|
3
|
+
import type { IconName } from '../icons/material'
|
|
4
|
+
|
|
5
|
+
export interface SwipeAction {
|
|
6
|
+
label: string
|
|
7
|
+
icon?: IconName | IconPath
|
|
8
|
+
colour?: string // the word behind once it would act: --tui-bad for a delete
|
|
9
|
+
run: () => void
|
|
10
|
+
leave?: boolean // the row slides on out first (it is going away)
|
|
11
|
+
}
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import type { Snippet } from 'svelte'
|
|
16
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
17
|
+
import { drag } from '../gestures/drag'
|
|
18
|
+
import { tick } from '../haptics'
|
|
19
|
+
import Icon from '../icons/Icon.svelte'
|
|
20
|
+
import { still } from '../motion/still'
|
|
21
|
+
|
|
22
|
+
// A row that moves with a sideways swipe to uncover an action behind it: `start` at its
|
|
23
|
+
// start edge, uncovered by a swipe towards the end (fast-track's delete), `end` at its
|
|
24
|
+
// end edge (edit). It follows the finger at `resist` of its pace. Pulled past `arm` of
|
|
25
|
+
// its width, or flung once past half that, it acts: the word behind lights in its colour
|
|
26
|
+
// and the phone ticks as it crosses. Short of that it springs back, a little past its
|
|
27
|
+
// place. A side without an action barely gives. The press is kept from a Pager behind.
|
|
28
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
29
|
+
start?: SwipeAction
|
|
30
|
+
end?: SwipeAction
|
|
31
|
+
resist?: number
|
|
32
|
+
arm?: number // a share of the row's width
|
|
33
|
+
children: Snippet
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let { start, end, resist = 0.75, arm = 0.3, children, class: className, ...rest }: Props = $props()
|
|
37
|
+
|
|
38
|
+
const FLING = 0.8 // px per ms
|
|
39
|
+
const LEAVE_MS = 200 // a row sliding out (.row.leaving)
|
|
40
|
+
let width = $state(1)
|
|
41
|
+
let dx = $state(0)
|
|
42
|
+
let moving = $state(false)
|
|
43
|
+
let leaving = $state(false)
|
|
44
|
+
let row = $state<HTMLElement>()
|
|
45
|
+
|
|
46
|
+
const armed = (offset: number) => Math.abs(offset) >= width * arm
|
|
47
|
+
const actionFor = (offset: number) => (offset > 0 ? start : offset < 0 ? end : undefined)
|
|
48
|
+
const acts = (offset: number, velocity: number) =>
|
|
49
|
+
armed(offset) || (Math.abs(offset) >= (width * arm) / 2 && Math.abs(velocity) > FLING && Math.sign(velocity) === Math.sign(offset))
|
|
50
|
+
|
|
51
|
+
const follow = drag({
|
|
52
|
+
axis: 'x',
|
|
53
|
+
claim: true,
|
|
54
|
+
enabled: () => !leaving && !!(start || end),
|
|
55
|
+
onStart: () => (moving = true),
|
|
56
|
+
onMove: (offset) => {
|
|
57
|
+
const shown = actionFor(offset) ? offset * resist : offset / 6
|
|
58
|
+
if (actionFor(shown) && armed(shown) !== armed(dx)) tick()
|
|
59
|
+
dx = shown
|
|
60
|
+
},
|
|
61
|
+
onEnd: (offset, velocity) => {
|
|
62
|
+
moving = false
|
|
63
|
+
const shown = dx
|
|
64
|
+
const action = actionFor(shown)
|
|
65
|
+
if (!action || !acts(shown, velocity * resist)) return void (dx = 0)
|
|
66
|
+
if (!action.leave || still(row)) {
|
|
67
|
+
dx = 0
|
|
68
|
+
return action.run()
|
|
69
|
+
}
|
|
70
|
+
leaving = true
|
|
71
|
+
dx = Math.sign(offset) * width
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
leaving = false
|
|
74
|
+
dx = 0
|
|
75
|
+
action.run()
|
|
76
|
+
}, LEAVE_MS)
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<div {...rest} class={['tui-swipe-row', className]} bind:clientWidth={width} {@attach follow}>
|
|
82
|
+
{#if start}<span
|
|
83
|
+
class="reveal start"
|
|
84
|
+
class:armed={dx > 0 && armed(dx)}
|
|
85
|
+
style:--action={start.colour ?? 'var(--tui-bad)'}
|
|
86
|
+
aria-hidden="true"
|
|
87
|
+
>{#if start.icon}<Icon icon={start.icon} />{/if}
|
|
88
|
+
{start.label}</span
|
|
89
|
+
>{/if}
|
|
90
|
+
{#if end}<span class="reveal end" class:armed={dx < 0 && armed(dx)} style:--action={end.colour ?? 'var(--tui-accent)'} aria-hidden="true"
|
|
91
|
+
>{end.label}
|
|
92
|
+
{#if end.icon}<Icon icon={end.icon} />{/if}</span
|
|
93
|
+
>{/if}
|
|
94
|
+
<div class="row" class:moving class:lifted={dx !== 0} class:leaving style:transform="translateX({dx}px)" bind:this={row}>
|
|
95
|
+
{@render children()}
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
<style>
|
|
100
|
+
@layer tuidroid {
|
|
101
|
+
.tui-swipe-row {
|
|
102
|
+
position: relative;
|
|
103
|
+
overflow: hidden;
|
|
104
|
+
touch-action: pan-y;
|
|
105
|
+
border-radius: var(--tui-radius);
|
|
106
|
+
|
|
107
|
+
/* Off its place, the row shows the track it slides along. */
|
|
108
|
+
&:has(.lifted) {
|
|
109
|
+
background: var(--tui-button);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* Behind the row: muted until the swipe would act, then in the action's colour. */
|
|
114
|
+
.reveal {
|
|
115
|
+
position: absolute;
|
|
116
|
+
top: 50%;
|
|
117
|
+
transform: translateY(-50%);
|
|
118
|
+
color: var(--tui-muted);
|
|
119
|
+
white-space: nowrap;
|
|
120
|
+
transition: color calc(0.15s * var(--tui-motion)) ease;
|
|
121
|
+
|
|
122
|
+
&.start {
|
|
123
|
+
left: 1ch;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
&.end {
|
|
127
|
+
right: 1ch;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
&.armed {
|
|
131
|
+
color: var(--action);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* Let go short of acting, it springs back a little past its place, its outline fading
|
|
136
|
+
as it settles. Under the finger it follows at once. */
|
|
137
|
+
.row {
|
|
138
|
+
position: relative;
|
|
139
|
+
background: var(--tui-block-cut, var(--tui-bg));
|
|
140
|
+
border-radius: var(--tui-radius);
|
|
141
|
+
transition:
|
|
142
|
+
transform calc(0.35s * var(--tui-motion)) cubic-bezier(0.3, 1.4, 0.6, 1),
|
|
143
|
+
box-shadow calc(0.35s * var(--tui-motion)) ease;
|
|
144
|
+
|
|
145
|
+
&.lifted {
|
|
146
|
+
box-shadow: inset 0 0 0 1px var(--tui-accent);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
&.moving {
|
|
150
|
+
transition: box-shadow calc(0.15s * var(--tui-motion)) ease;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
&.leaving {
|
|
154
|
+
transition: transform calc(0.2s * var(--tui-motion)) cubic-bezier(0.32, 0, 0.67, 0);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IconPath } from '../icons/Icon.svelte';
|
|
2
|
+
import type { IconName } from '../icons/material';
|
|
3
|
+
export interface SwipeAction {
|
|
4
|
+
label: string;
|
|
5
|
+
icon?: IconName | IconPath;
|
|
6
|
+
colour?: string;
|
|
7
|
+
run: () => void;
|
|
8
|
+
leave?: boolean;
|
|
9
|
+
}
|
|
10
|
+
import type { Snippet } from 'svelte';
|
|
11
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
12
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
13
|
+
start?: SwipeAction;
|
|
14
|
+
end?: SwipeAction;
|
|
15
|
+
resist?: number;
|
|
16
|
+
arm?: number;
|
|
17
|
+
children: Snippet;
|
|
18
|
+
}
|
|
19
|
+
declare const SwipeRow: import("svelte").Component<Props, {}, "">;
|
|
20
|
+
type SwipeRow = ReturnType<typeof SwipeRow>;
|
|
21
|
+
export default SwipeRow;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte'
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
4
|
+
import Button from '../controls/Button.svelte'
|
|
5
|
+
|
|
6
|
+
// What is left where an entry was deleted: what it was, muted, and [ ↺ undo ] to bring it
|
|
7
|
+
// back. Keep it in the entry's place until the page is left.
|
|
8
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
onundo: () => void
|
|
10
|
+
label?: string
|
|
11
|
+
children: Snippet
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let { onundo, label = 'undo', children, class: className, ...rest }: Props = $props()
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<div {...rest} class={['tui-undo-row', className]} role="status">
|
|
18
|
+
<span class="what">{@render children()}</span>
|
|
19
|
+
<Button variant="word" icon="undo" onclick={onundo}>{label}</Button>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<style>
|
|
23
|
+
@layer tuidroid {
|
|
24
|
+
.tui-undo-row {
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
justify-content: space-between;
|
|
28
|
+
gap: 1ch;
|
|
29
|
+
padding: 0.3em 1ch;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.what {
|
|
33
|
+
color: var(--tui-muted);
|
|
34
|
+
min-width: 0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
onundo: () => void;
|
|
5
|
+
label?: string;
|
|
6
|
+
children: Snippet;
|
|
7
|
+
}
|
|
8
|
+
declare const UndoRow: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type UndoRow = ReturnType<typeof UndoRow>;
|
|
10
|
+
export default UndoRow;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<script lang="ts" generics="T">
|
|
2
|
+
import { tick, untrack, type Snippet } from 'svelte'
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
4
|
+
import { charWidth } from '../data/fit'
|
|
5
|
+
import Block from '../layout/Block.svelte'
|
|
6
|
+
import ShuffleText from './ShuffleText.svelte'
|
|
7
|
+
import { still } from './still'
|
|
8
|
+
import { sweepIn } from './sweep'
|
|
9
|
+
|
|
10
|
+
// A Block that turns over when its `face` changes, as karteikasten's card does: a scan
|
|
11
|
+
// line under the title's first letter carries the title to the right edge, shuffling it
|
|
12
|
+
// into its mirror image, and the back of the card (`back`) comes in behind the line, each
|
|
13
|
+
// character scrambling as it passes; after `hold` ms the line carries the title home and
|
|
14
|
+
// the new front (`front` with the new face) comes in behind it. The old front stays until
|
|
15
|
+
// the back covers it. `flips` says which changes turn the card (all, by default); the rest
|
|
16
|
+
// just show. Motion held still, it just shows.
|
|
17
|
+
interface Props extends Omit<HTMLAttributes<HTMLElement>, 'title'> {
|
|
18
|
+
title: string
|
|
19
|
+
face: T
|
|
20
|
+
front: Snippet<[T]>
|
|
21
|
+
back?: Snippet
|
|
22
|
+
flips?: (from: T, to: T) => boolean
|
|
23
|
+
hold?: number
|
|
24
|
+
below?: Snippet // inside the block, under the card: buttons, hints
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let { title, face, front, back, flips = () => true, hold = 400, below, class: className, ...rest }: Props = $props()
|
|
28
|
+
|
|
29
|
+
const SWEEP_MS = 400 // one pass of the line, with the title's slide (Block's titleEnd)
|
|
30
|
+
const SCRAMBLE_MS = 150 // a character settles this long after the line has passed it
|
|
31
|
+
// The line runs under the title's first letter, this far in from either edge of the card's
|
|
32
|
+
// content: the title's 1ch inset and 0.6ch padding and half a letter, less the block's 1ch.
|
|
33
|
+
const REACH_CH = 1.1
|
|
34
|
+
|
|
35
|
+
let shown = $state.raw(untrack(() => face))
|
|
36
|
+
let covering = $state(false) // the back lies over the card
|
|
37
|
+
let scanning = $state(false)
|
|
38
|
+
let out = $state(false) // the title, the line and the back's edge at the right
|
|
39
|
+
let held = $state(false) // the back covers the card edge to edge
|
|
40
|
+
let flipping = false
|
|
41
|
+
let faceEl = $state<HTMLElement>()
|
|
42
|
+
let backEl = $state<HTMLElement>()
|
|
43
|
+
|
|
44
|
+
$effect(() => {
|
|
45
|
+
void face
|
|
46
|
+
untrack(sync)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
/** Brings the card up to `face`: a flip, or at once. A running flip lands on the latest
|
|
50
|
+
* face itself and calls this again when it is done. */
|
|
51
|
+
function sync() {
|
|
52
|
+
if (flipping || face === shown) return
|
|
53
|
+
if (flips(shown, face) && !still(faceEl)) void flip()
|
|
54
|
+
else shown = face
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
58
|
+
|
|
59
|
+
async function flip() {
|
|
60
|
+
flipping = true
|
|
61
|
+
try {
|
|
62
|
+
covering = true
|
|
63
|
+
await tick()
|
|
64
|
+
await sweep(backEl, true)
|
|
65
|
+
held = true
|
|
66
|
+
await wait(hold)
|
|
67
|
+
shown = face
|
|
68
|
+
held = false
|
|
69
|
+
await tick()
|
|
70
|
+
await sweep(faceEl, false)
|
|
71
|
+
} finally {
|
|
72
|
+
covering = held = out = scanning = false
|
|
73
|
+
flipping = false
|
|
74
|
+
}
|
|
75
|
+
sync()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** One pass of the line: out to the right, the back comes in behind it; home to the left,
|
|
79
|
+
* the back peels away from the new front. The side coming in scrambles into place. */
|
|
80
|
+
async function sweep(incoming: HTMLElement | undefined, outwards: boolean) {
|
|
81
|
+
if (!incoming || !backEl) return
|
|
82
|
+
const reach = REACH_CH * charWidth(backEl)
|
|
83
|
+
getComputedStyle(backEl).clipPath // settle the back's starting edge, so it transitions from there
|
|
84
|
+
sweepIn(incoming, { sweepMs: SWEEP_MS, scrambleMs: SCRAMBLE_MS, fromRight: !outwards, reach })
|
|
85
|
+
out = outwards
|
|
86
|
+
scanning = true
|
|
87
|
+
await wait(SWEEP_MS)
|
|
88
|
+
scanning = false
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The title as seen from the back: Card → draC. */
|
|
92
|
+
const mirrored = (text: string) => [...text].reverse().join('')
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<Block {...rest} class={['tui-flip', className]} titleEnd={out}>
|
|
96
|
+
{#snippet heading()}<ShuffleText text={out ? mirrored(title) : title} stagger={80} />{/snippet}
|
|
97
|
+
<div class="turn" class:out class:held style:--reach="{REACH_CH}ch">
|
|
98
|
+
<div class="face" bind:this={faceEl}>{@render front(shown)}</div>
|
|
99
|
+
{#if covering}
|
|
100
|
+
<div class="back" bind:this={backEl} aria-hidden="true">
|
|
101
|
+
{#if back}{@render back()}{:else}<span class="art">{title}</span>{/if}
|
|
102
|
+
</div>
|
|
103
|
+
{/if}
|
|
104
|
+
<div class="scan" class:scanning aria-hidden="true"></div>
|
|
105
|
+
</div>
|
|
106
|
+
{@render below?.()}
|
|
107
|
+
</Block>
|
|
108
|
+
|
|
109
|
+
<style>
|
|
110
|
+
@layer tuidroid {
|
|
111
|
+
.turn {
|
|
112
|
+
position: relative;
|
|
113
|
+
flex: 1;
|
|
114
|
+
min-height: 0;
|
|
115
|
+
display: flex;
|
|
116
|
+
flex-direction: column;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.face {
|
|
120
|
+
flex: 1;
|
|
121
|
+
min-height: 0;
|
|
122
|
+
overflow-y: auto;
|
|
123
|
+
container-type: inline-size;
|
|
124
|
+
display: flex;
|
|
125
|
+
flex-direction: column;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/* The back covers the card from its left edge up to the line, --reach in from either
|
|
129
|
+
edge, and comes in behind it. */
|
|
130
|
+
.back {
|
|
131
|
+
position: absolute;
|
|
132
|
+
inset: 0;
|
|
133
|
+
display: grid;
|
|
134
|
+
place-items: center;
|
|
135
|
+
padding-inline: var(--reach);
|
|
136
|
+
background: var(--tui-block-cut, var(--tui-bg));
|
|
137
|
+
container-type: inline-size;
|
|
138
|
+
clip-path: inset(0 calc(100% - var(--reach)) 0 0);
|
|
139
|
+
transition: clip-path calc(0.4s * var(--tui-motion)) linear;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.out .back {
|
|
143
|
+
clip-path: inset(0 var(--reach) 0 0);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.held .back {
|
|
147
|
+
clip-path: none;
|
|
148
|
+
transition: none;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* The back by default: the title, large, in a Catppuccin rainbow. */
|
|
152
|
+
.art {
|
|
153
|
+
font-size: 2.5em;
|
|
154
|
+
font-weight: 700;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.back > :global(*) {
|
|
158
|
+
background: linear-gradient(
|
|
159
|
+
to bottom right,
|
|
160
|
+
var(--ctp-red),
|
|
161
|
+
var(--ctp-peach),
|
|
162
|
+
var(--ctp-yellow),
|
|
163
|
+
var(--ctp-green),
|
|
164
|
+
var(--ctp-sapphire),
|
|
165
|
+
var(--ctp-blue),
|
|
166
|
+
var(--ctp-mauve)
|
|
167
|
+
);
|
|
168
|
+
background-clip: text;
|
|
169
|
+
-webkit-background-clip: text;
|
|
170
|
+
color: transparent;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* The scan line: a glowing bar in the accent, reaching up to the title on the border,
|
|
174
|
+
travelling under its first letter from one edge to the other. */
|
|
175
|
+
.scan {
|
|
176
|
+
position: absolute;
|
|
177
|
+
top: -0.15em;
|
|
178
|
+
bottom: 0;
|
|
179
|
+
left: var(--reach);
|
|
180
|
+
width: 0.5ch;
|
|
181
|
+
transform: translateX(-50%);
|
|
182
|
+
background: var(--tui-accent);
|
|
183
|
+
box-shadow: 0 0 0.8em var(--tui-accent);
|
|
184
|
+
pointer-events: none;
|
|
185
|
+
visibility: hidden;
|
|
186
|
+
transition: left calc(0.4s * var(--tui-motion)) linear;
|
|
187
|
+
|
|
188
|
+
&.scanning {
|
|
189
|
+
visibility: visible;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.out .scan {
|
|
194
|
+
left: calc(100% - var(--reach));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
</style>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
declare function $$render<T>(): {
|
|
4
|
+
props: Omit<HTMLAttributes<HTMLElement>, "title"> & {
|
|
5
|
+
title: string;
|
|
6
|
+
face: T;
|
|
7
|
+
front: Snippet<[T]>;
|
|
8
|
+
back?: Snippet;
|
|
9
|
+
flips?: (from: T, to: T) => boolean;
|
|
10
|
+
hold?: number;
|
|
11
|
+
below?: Snippet;
|
|
12
|
+
};
|
|
13
|
+
exports: {};
|
|
14
|
+
bindings: "";
|
|
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(): "";
|
|
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 FlipCard: $$IsomorphicComponent;
|
|
33
|
+
type FlipCard<T> = InstanceType<typeof FlipCard<T>>;
|
|
34
|
+
export default FlipCard;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte'
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
4
|
+
import { plan, runShuffle } from './shuffle'
|
|
5
|
+
import { still } from './still'
|
|
6
|
+
|
|
7
|
+
// The screen's main word or number: bold and fitted to the width it is given, between
|
|
8
|
+
// --tui-hero-min and --tui-hero-max (1.5em and 3em); nothing else on the screen scales.
|
|
9
|
+
// With `animate` it shuffles in when it mounts and calls `onDone` once the last letter
|
|
10
|
+
// locks; later changes show at once, as a ticking clock's should.
|
|
11
|
+
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
12
|
+
text: string
|
|
13
|
+
animate?: boolean
|
|
14
|
+
onDone?: () => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let { text, animate = false, onDone, class: className, ...rest }: Props = $props()
|
|
18
|
+
|
|
19
|
+
let shuffled = $state<string | null>(null) // the frame while it shuffles in
|
|
20
|
+
|
|
21
|
+
// Once, as it mounts: what it reads is untracked, so a new text does not run it again.
|
|
22
|
+
function shuffleIn(node: HTMLSpanElement) {
|
|
23
|
+
return untrack(() => {
|
|
24
|
+
if (!animate || still(node)) return void onDone?.()
|
|
25
|
+
const finish = () => {
|
|
26
|
+
shuffled = null
|
|
27
|
+
onDone?.()
|
|
28
|
+
}
|
|
29
|
+
return runShuffle(text, plan(text), (frame) => (shuffled = frame), finish)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<span {...rest} class={['tui-hero-box', className]} {@attach shuffleIn}
|
|
35
|
+
><span class="tui-hero" style:--chars={text.length}
|
|
36
|
+
>{#if shuffled === null}{text}{:else}<span aria-hidden="true">{shuffled}</span><span class="tui-sr">{text}</span>{/if}</span
|
|
37
|
+
></span
|
|
38
|
+
>
|
|
39
|
+
|
|
40
|
+
<style>
|
|
41
|
+
@layer tuidroid {
|
|
42
|
+
/* The width the hero is fitted to: all its parent gives, even centred in a flex column. */
|
|
43
|
+
.tui-hero-box {
|
|
44
|
+
display: block;
|
|
45
|
+
width: 100%;
|
|
46
|
+
container-type: inline-size;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* Iosevka's characters are half an em wide; the rest is room at the edges. */
|
|
50
|
+
.tui-hero {
|
|
51
|
+
display: block;
|
|
52
|
+
text-align: center;
|
|
53
|
+
white-space: nowrap;
|
|
54
|
+
font-weight: 700;
|
|
55
|
+
line-height: 1.15;
|
|
56
|
+
font-size: clamp(var(--tui-hero-min, 1.5em), calc(100cqi / (var(--chars) * 0.56)), var(--tui-hero-max, 3em));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
</style>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
3
|
+
text: string;
|
|
4
|
+
animate?: boolean;
|
|
5
|
+
onDone?: () => void;
|
|
6
|
+
}
|
|
7
|
+
declare const Hero: import("svelte").Component<Props, {}, "">;
|
|
8
|
+
type Hero = ReturnType<typeof Hero>;
|
|
9
|
+
export default Hero;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte'
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
4
|
+
import { frame, plan, runShuffle, type Pool } from './shuffle'
|
|
5
|
+
import { still } from './still'
|
|
6
|
+
|
|
7
|
+
// Text that runs the letter shuffle whenever it changes: a live value, a status field,
|
|
8
|
+
// a button's word. The first text just appears, unless `intro` shuffles it in too.
|
|
9
|
+
// While `plain`, changes just appear: for a value that changes too fast to shuffle (a
|
|
10
|
+
// held stepper). Screen readers read the text, never the scramble.
|
|
11
|
+
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
12
|
+
text: string | number
|
|
13
|
+
stagger?: number // ms between one letter locking and the next
|
|
14
|
+
max?: number // the longest a shuffle may take, in ms
|
|
15
|
+
intro?: boolean
|
|
16
|
+
plain?: boolean
|
|
17
|
+
pool?: Pool // what each character cycles through
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let { text, stagger = 50, max = 700, intro = false, plain = false, pool, ...rest }: Props = $props()
|
|
21
|
+
|
|
22
|
+
const target = $derived(String(text))
|
|
23
|
+
let shown = $state(untrack(() => String(text)))
|
|
24
|
+
let first = true
|
|
25
|
+
|
|
26
|
+
// Runs again for each new text; the last one's shuffle stops first.
|
|
27
|
+
function shuffle(node: HTMLSpanElement) {
|
|
28
|
+
const next = target
|
|
29
|
+
const options = untrack(() => ({ stagger, max, pool, intro, plain }))
|
|
30
|
+
const run = plan(next, options)
|
|
31
|
+
const quiet = (first && !options.intro) || options.plain || !run.duration || still(node)
|
|
32
|
+
const wasFirst = first
|
|
33
|
+
first = false
|
|
34
|
+
if (quiet) return void (shown = next)
|
|
35
|
+
if (wasFirst) shown = frame(next, run, 0, Math.random, options.pool) // an intro starts scrambled, not blank
|
|
36
|
+
return runShuffle(next, run, (text) => (shown = text), undefined, options.pool)
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<span {...rest} {@attach shuffle}
|
|
41
|
+
>{#if shown === target}{shown}{:else}<span aria-hidden="true">{shown}</span><span class="tui-sr">{target}</span>{/if}</span
|
|
42
|
+
>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
import { type Pool } from './shuffle';
|
|
3
|
+
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
4
|
+
text: string | number;
|
|
5
|
+
stagger?: number;
|
|
6
|
+
max?: number;
|
|
7
|
+
intro?: boolean;
|
|
8
|
+
plain?: boolean;
|
|
9
|
+
pool?: Pool;
|
|
10
|
+
}
|
|
11
|
+
declare const ShuffleText: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type ShuffleText = ReturnType<typeof ShuffleText>;
|
|
13
|
+
export default ShuffleText;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
3
|
+
import { still } from './still'
|
|
4
|
+
import { typingDelay, typingPieces } from './typing'
|
|
5
|
+
|
|
6
|
+
// Text typed out left to right behind a block cursor in the accent, typed again when it
|
|
7
|
+
// changes; `mark` sets a span [start, end) in bold, underlined. The untyped rest holds
|
|
8
|
+
// its place unseen, so lines never rewrap as it types. With `animate` off it is all
|
|
9
|
+
// there at once. Screen readers read the whole text.
|
|
10
|
+
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
11
|
+
text: string
|
|
12
|
+
mark?: readonly [number, number]
|
|
13
|
+
animate?: boolean
|
|
14
|
+
perChar?: number // ms a character
|
|
15
|
+
max?: number // the longest the whole text may take, in ms
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let { text, mark = [0, 0], animate = true, perChar = 30, max = 1000, ...rest }: Props = $props()
|
|
19
|
+
|
|
20
|
+
let typed = $state(0)
|
|
21
|
+
|
|
22
|
+
// Types the text out again whenever it changes.
|
|
23
|
+
function type(node: HTMLSpanElement) {
|
|
24
|
+
const length = text.length
|
|
25
|
+
if (!animate || still(node)) return void (typed = length)
|
|
26
|
+
typed = 0
|
|
27
|
+
const delay = typingDelay(length, perChar, max)
|
|
28
|
+
const start = performance.now()
|
|
29
|
+
let raf = 0
|
|
30
|
+
const tick = (now: number) => {
|
|
31
|
+
typed = Math.min(length, Math.floor((now - start) / delay))
|
|
32
|
+
if (typed < length) raf = requestAnimationFrame(tick)
|
|
33
|
+
}
|
|
34
|
+
raf = requestAnimationFrame(tick)
|
|
35
|
+
return () => cancelAnimationFrame(raf)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const pieces = $derived(typingPieces(text, mark, typed))
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<span {...rest} {@attach type}
|
|
42
|
+
><span aria-hidden="true"
|
|
43
|
+
>{#each pieces as piece, i (i)}{#if piece.mark}<mark class={piece.state}>{piece.text}</mark>{:else}<span class={piece.state}
|
|
44
|
+
>{piece.text}</span
|
|
45
|
+
>{/if}{/each}</span
|
|
46
|
+
><span class="tui-sr">{text}</span></span
|
|
47
|
+
>
|
|
48
|
+
|
|
49
|
+
<style>
|
|
50
|
+
@layer tuidroid {
|
|
51
|
+
mark {
|
|
52
|
+
background: none;
|
|
53
|
+
color: inherit;
|
|
54
|
+
font-weight: 700;
|
|
55
|
+
text-decoration: underline;
|
|
56
|
+
text-underline-offset: 0.2em;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.untyped {
|
|
60
|
+
visibility: hidden;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.cursor {
|
|
64
|
+
background: var(--tui-accent);
|
|
65
|
+
color: transparent;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
3
|
+
text: string;
|
|
4
|
+
mark?: readonly [number, number];
|
|
5
|
+
animate?: boolean;
|
|
6
|
+
perChar?: number;
|
|
7
|
+
max?: number;
|
|
8
|
+
}
|
|
9
|
+
declare const TypeText: import("svelte").Component<Props, {}, "">;
|
|
10
|
+
type TypeText = ReturnType<typeof TypeText>;
|
|
11
|
+
export default TypeText;
|