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,24 @@
|
|
|
1
|
+
/** Glyphs change at most this often: a terminal's pace, not the display's. */
|
|
2
|
+
export declare const FRAME_MS = 40;
|
|
3
|
+
/** What a character cycles through while it shuffles, or null to stay still. */
|
|
4
|
+
export type Pool = (ch: string) => string | null;
|
|
5
|
+
/** Digits cycle digits and letters letters of their case; the rest stays still. */
|
|
6
|
+
export declare const pool: Pool;
|
|
7
|
+
export interface ShufflePlan {
|
|
8
|
+
lockAt: number[];
|
|
9
|
+
duration: number;
|
|
10
|
+
}
|
|
11
|
+
export interface PlanOptions {
|
|
12
|
+
/** Milliseconds between one character locking and the next. */
|
|
13
|
+
stagger?: number;
|
|
14
|
+
/** The longest the whole text may take; the stagger shrinks to fit. */
|
|
15
|
+
max?: number;
|
|
16
|
+
pool?: Pool;
|
|
17
|
+
}
|
|
18
|
+
/** When each character of `text` locks: `stagger` apart, compressed to take at most `max`. */
|
|
19
|
+
export declare function plan(text: string, { stagger, max, pool: pick }?: PlanOptions): ShufflePlan;
|
|
20
|
+
/** The text as shown `elapsed` ms into its shuffle. */
|
|
21
|
+
export declare function frame(text: string, shuffle: ShufflePlan, elapsed: number, random?: () => number, pick?: Pool): string;
|
|
22
|
+
/** Runs `shuffle` over `text`, calling `show` with each frame (at most every FRAME_MS)
|
|
23
|
+
* and last with `text` itself, then `onDone`. Returns a function that stops it. */
|
|
24
|
+
export declare function runShuffle(text: string, shuffle: ShufflePlan, show: (text: string) => void, onDone?: () => void, pick?: Pool): () => void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// The letter shuffle: every letter cycles random letters of its own case, every digit
|
|
2
|
+
// random digits, and each locks in place from left to right. Spaces and punctuation stay
|
|
3
|
+
// still. Letters outside A–Z (ä, ß, é) cycle A–Z of their case and lock to themselves.
|
|
4
|
+
const UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
5
|
+
const LOWER = 'abcdefghijklmnopqrstuvwxyz';
|
|
6
|
+
const DIGITS = '0123456789';
|
|
7
|
+
/** Glyphs change at most this often: a terminal's pace, not the display's. */
|
|
8
|
+
export const FRAME_MS = 40;
|
|
9
|
+
/** Digits cycle digits and letters letters of their case; the rest stays still. */
|
|
10
|
+
export const pool = (ch) => {
|
|
11
|
+
if (DIGITS.includes(ch))
|
|
12
|
+
return DIGITS;
|
|
13
|
+
if (ch.toLowerCase() === ch.toUpperCase())
|
|
14
|
+
return null;
|
|
15
|
+
return ch === ch.toLowerCase() ? LOWER : UPPER;
|
|
16
|
+
};
|
|
17
|
+
/** When each character of `text` locks: `stagger` apart, compressed to take at most `max`. */
|
|
18
|
+
export function plan(text, { stagger = 50, max = 700, pool: pick = pool } = {}) {
|
|
19
|
+
const chars = [...text];
|
|
20
|
+
const moving = chars.filter((ch) => pick(ch) !== null).length;
|
|
21
|
+
const step = moving ? Math.min(stagger, max / moving) : 0;
|
|
22
|
+
let locked = 0;
|
|
23
|
+
const lockAt = chars.map((ch) => (pick(ch) !== null ? step * ++locked : 0));
|
|
24
|
+
return { lockAt, duration: step * moving };
|
|
25
|
+
}
|
|
26
|
+
/** The text as shown `elapsed` ms into its shuffle. */
|
|
27
|
+
export function frame(text, shuffle, elapsed, random = Math.random, pick = pool) {
|
|
28
|
+
return [...text]
|
|
29
|
+
.map((ch, i) => {
|
|
30
|
+
const chars = pick(ch);
|
|
31
|
+
if (!chars || elapsed >= shuffle.lockAt[i])
|
|
32
|
+
return ch;
|
|
33
|
+
return chars[Math.floor(random() * chars.length)];
|
|
34
|
+
})
|
|
35
|
+
.join('');
|
|
36
|
+
}
|
|
37
|
+
/** Runs `shuffle` over `text`, calling `show` with each frame (at most every FRAME_MS)
|
|
38
|
+
* and last with `text` itself, then `onDone`. Returns a function that stops it. */
|
|
39
|
+
export function runShuffle(text, shuffle, show, onDone, pick = pool) {
|
|
40
|
+
const start = performance.now();
|
|
41
|
+
let lastSwap = -Infinity;
|
|
42
|
+
let raf = 0;
|
|
43
|
+
const tick = (now) => {
|
|
44
|
+
const elapsed = now - start;
|
|
45
|
+
if (elapsed >= shuffle.duration) {
|
|
46
|
+
show(text);
|
|
47
|
+
onDone?.();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (now - lastSwap >= FRAME_MS) {
|
|
51
|
+
show(frame(text, shuffle, elapsed, Math.random, pick));
|
|
52
|
+
lastSwap = now;
|
|
53
|
+
}
|
|
54
|
+
raf = requestAnimationFrame(tick);
|
|
55
|
+
};
|
|
56
|
+
raf = requestAnimationFrame(tick);
|
|
57
|
+
return () => cancelAnimationFrame(raf);
|
|
58
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Whether to hold motion still. CSS decides (tokens.css): --tui-motion is 0 where the
|
|
2
|
+
// system asks for reduced motion, or under data-motion="off", and 1 elsewhere. Scripted
|
|
3
|
+
// motion (the letter shuffle, typing, unfolds) asks here, so it agrees with the CSS.
|
|
4
|
+
/** Whether motion is held still at `node` (the page, by default). */
|
|
5
|
+
export function still(node = document.documentElement) {
|
|
6
|
+
return getComputedStyle(node).getPropertyValue('--tui-motion').trim() === '0';
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Pool } from './shuffle';
|
|
2
|
+
/** What ASCII art is drawn with: these scramble among themselves. */
|
|
3
|
+
export declare const MARKS = "_|/\\()',.-`";
|
|
4
|
+
/** Letters and digits as the shuffle has them, and ASCII art's marks among themselves. */
|
|
5
|
+
export declare const sweepPool: Pool;
|
|
6
|
+
export interface SweepOptions {
|
|
7
|
+
sweepMs: number;
|
|
8
|
+
scrambleMs: number;
|
|
9
|
+
fromRight?: boolean;
|
|
10
|
+
reach?: number;
|
|
11
|
+
pick?: Pool;
|
|
12
|
+
}
|
|
13
|
+
/** Scrambles `root`'s text in behind a line crossing it. */
|
|
14
|
+
export declare function sweepIn(root: HTMLElement, { sweepMs, scrambleMs, fromRight, reach, pick }: SweepOptions): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Text that scrambles in behind a line sweeping across it (FlipCard's scan line): every
|
|
2
|
+
// character of an element's text scrambles from the start and settles a moment after the
|
|
3
|
+
// line has passed it. The element's own text nodes are written to directly, and left
|
|
4
|
+
// alone once something else writes to them.
|
|
5
|
+
import { FRAME_MS, frame, pool } from './shuffle';
|
|
6
|
+
/** What ASCII art is drawn with: these scramble among themselves. */
|
|
7
|
+
export const MARKS = "_|/\\()',.-`";
|
|
8
|
+
/** Letters and digits as the shuffle has them, and ASCII art's marks among themselves. */
|
|
9
|
+
export const sweepPool = (ch) => pool(ch) ?? (MARKS.includes(ch) ? MARKS : null);
|
|
10
|
+
function textNodes(root) {
|
|
11
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
12
|
+
const nodes = [];
|
|
13
|
+
while (walker.nextNode()) {
|
|
14
|
+
const node = walker.currentNode;
|
|
15
|
+
if (node.data.trim())
|
|
16
|
+
nodes.push(node);
|
|
17
|
+
}
|
|
18
|
+
return nodes;
|
|
19
|
+
}
|
|
20
|
+
/** Scrambles `root`'s text in behind a line crossing it. */
|
|
21
|
+
export function sweepIn(root, { sweepMs, scrambleMs, fromRight = false, reach = 0, pick = sweepPool }) {
|
|
22
|
+
const box = root.getBoundingClientRect();
|
|
23
|
+
const span = box.width - 2 * reach;
|
|
24
|
+
if (span <= 0)
|
|
25
|
+
return;
|
|
26
|
+
const range = document.createRange();
|
|
27
|
+
const moving = textNodes(root).map((node) => {
|
|
28
|
+
const lockAt = [];
|
|
29
|
+
let offset = 0;
|
|
30
|
+
for (const ch of node.data) {
|
|
31
|
+
range.setStart(node, offset);
|
|
32
|
+
range.setEnd(node, offset + ch.length);
|
|
33
|
+
const rect = range.getBoundingClientRect();
|
|
34
|
+
const x = Math.min(1, Math.max(0, (rect.left + rect.width / 2 - box.left - reach) / span));
|
|
35
|
+
lockAt.push((fromRight ? 1 - x : x) * sweepMs + scrambleMs);
|
|
36
|
+
offset += ch.length;
|
|
37
|
+
}
|
|
38
|
+
const shuffle = { lockAt, duration: sweepMs + scrambleMs };
|
|
39
|
+
return { node, target: node.data, shuffle, written: node.data };
|
|
40
|
+
});
|
|
41
|
+
const start = performance.now();
|
|
42
|
+
let lastSwap = -Infinity;
|
|
43
|
+
const tick = (now) => {
|
|
44
|
+
const elapsed = now - start;
|
|
45
|
+
const done = elapsed >= sweepMs + scrambleMs;
|
|
46
|
+
if (!done && now - lastSwap < FRAME_MS)
|
|
47
|
+
return void requestAnimationFrame(tick);
|
|
48
|
+
lastSwap = now;
|
|
49
|
+
for (const item of moving) {
|
|
50
|
+
if (item.node.data !== item.written)
|
|
51
|
+
continue; // written to since
|
|
52
|
+
item.written = done ? item.target : frame(item.target, item.shuffle, elapsed, Math.random, pick);
|
|
53
|
+
item.node.data = item.written;
|
|
54
|
+
}
|
|
55
|
+
if (!done)
|
|
56
|
+
requestAnimationFrame(tick);
|
|
57
|
+
};
|
|
58
|
+
tick(start);
|
|
59
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Piece {
|
|
2
|
+
text: string;
|
|
3
|
+
mark: boolean;
|
|
4
|
+
state: 'typed' | 'cursor' | 'untyped';
|
|
5
|
+
}
|
|
6
|
+
/** Milliseconds per character: `perChar`, faster for long text so it takes at most `max`. */
|
|
7
|
+
export declare function typingDelay(length: number, perChar?: number, max?: number): number;
|
|
8
|
+
/** `text` after `typed` characters, cut so the highlight [start, end) stays whole. */
|
|
9
|
+
export declare function typingPieces(text: string, mark: readonly [number, number], typed: number): Piece[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Text typed out left to right. Characters not yet typed stay in the layout, invisible,
|
|
2
|
+
// so lines never rewrap while it types; the next one shows as the cursor.
|
|
3
|
+
/** Milliseconds per character: `perChar`, faster for long text so it takes at most `max`. */
|
|
4
|
+
export function typingDelay(length, perChar = 30, max = 1000) {
|
|
5
|
+
return length ? Math.min(perChar, max / length) : 0;
|
|
6
|
+
}
|
|
7
|
+
/** `text` after `typed` characters, cut so the highlight [start, end) stays whole. */
|
|
8
|
+
export function typingPieces(text, mark, typed) {
|
|
9
|
+
const cuts = [...new Set([0, mark[0], mark[1], typed, typed + 1, text.length])]
|
|
10
|
+
.filter((i) => i >= 0 && i <= text.length)
|
|
11
|
+
.sort((a, b) => a - b);
|
|
12
|
+
const pieces = [];
|
|
13
|
+
for (let i = 0; i + 1 < cuts.length; i++) {
|
|
14
|
+
const [from, to] = [cuts[i], cuts[i + 1]];
|
|
15
|
+
const state = to <= typed ? 'typed' : from === typed ? 'cursor' : 'untyped';
|
|
16
|
+
pieces.push({ text: text.slice(from, to), mark: mark[0] < mark[1] && from >= mark[0] && to <= mark[1], state });
|
|
17
|
+
}
|
|
18
|
+
return pieces;
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// A block that unfolds below the one that opens it, in a column (Panes): it grows from
|
|
2
|
+
// nothing and pushes what is below it down, and folds back up when it closes. Put the
|
|
3
|
+
// column's gap inside what unfolds (Panes' Unfold does), so nothing jumps at either end.
|
|
4
|
+
import { cubicOut } from 'svelte/easing';
|
|
5
|
+
import { still } from './still';
|
|
6
|
+
export function unfold(node, { duration = 240 } = {}) {
|
|
7
|
+
const height = node.offsetHeight;
|
|
8
|
+
return {
|
|
9
|
+
duration: still(node) ? 0 : duration,
|
|
10
|
+
easing: cubicOut,
|
|
11
|
+
css: (t) => `height: ${t * height}px; overflow: clip`,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte'
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
4
|
+
import { carries, drag } from '../gestures/drag'
|
|
5
|
+
import { still } from '../motion/still'
|
|
6
|
+
|
|
7
|
+
// A page with a pane that hangs off it: just below it (`from` below) or above it. Opening
|
|
8
|
+
// the pane pushes the page by the pane's height, its far edge flowing off the screen;
|
|
9
|
+
// closing it lets the page fall back, the pane drawn until it is out of sight. While it
|
|
10
|
+
// is open, what is left of the page is one button that closes it, and a drag away from
|
|
11
|
+
// the page, on the pane or on what is left, pulls it and closes it when pulled a third of
|
|
12
|
+
// its height or flicked. The pane is yours: usually a Pane, its height its content's.
|
|
13
|
+
//
|
|
14
|
+
// Panes that open from the same place swap instead: give each opener data-pane="<id>"
|
|
15
|
+
// and the open pane's id as `paneId`. A tap above the pane that lands on another opener
|
|
16
|
+
// calls `onswap` with its id (rather than `onclose`), and the new pane slides in from
|
|
17
|
+
// the side its button is on as the old one slides out the other way.
|
|
18
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
19
|
+
open: boolean
|
|
20
|
+
from?: 'below' | 'above'
|
|
21
|
+
paneId?: string
|
|
22
|
+
onclose: () => void
|
|
23
|
+
onswap?: (id: string) => void
|
|
24
|
+
closeLabel?: string
|
|
25
|
+
pane: Snippet
|
|
26
|
+
children: Snippet
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let { open, from = 'below', paneId, onclose, onswap, closeLabel = 'Close', pane, children, class: className, ...rest }: Props = $props()
|
|
30
|
+
|
|
31
|
+
const OUT_MS = 240 // the page's fall back (.host's transition)
|
|
32
|
+
const SWAP_MS = 220
|
|
33
|
+
let side = $state<1 | -1>(1) // where the next pane comes in from: 1 the right
|
|
34
|
+
let main = $state<HTMLElement>()
|
|
35
|
+
|
|
36
|
+
/** A tap on what is left of the page: another pane's opener under it swaps, else close. */
|
|
37
|
+
function above(event: MouseEvent) {
|
|
38
|
+
const inside = (el: Element) => {
|
|
39
|
+
const r = el.getBoundingClientRect()
|
|
40
|
+
return event.clientX >= r.left && event.clientX <= r.right && event.clientY >= r.top && event.clientY <= r.bottom
|
|
41
|
+
}
|
|
42
|
+
const openers = [...(main?.querySelectorAll<HTMLButtonElement>('[data-pane]') ?? [])]
|
|
43
|
+
const hit = openers.find((el) => !el.disabled && inside(el))
|
|
44
|
+
const id = hit?.dataset.pane
|
|
45
|
+
const current = openers.find((el) => el.dataset.pane === paneId)
|
|
46
|
+
if (!onswap || !hit || !id || id === paneId || !current) return onclose()
|
|
47
|
+
side = hit.getBoundingClientRect().left < current.getBoundingClientRect().left ? -1 : 1
|
|
48
|
+
onswap(id)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const ease = (t: number) => 1 - (1 - t) ** 3
|
|
52
|
+
|
|
53
|
+
/** A swapped-in pane, sliding in from its button's side. */
|
|
54
|
+
function slideIn(node: Element) {
|
|
55
|
+
return {
|
|
56
|
+
duration: still(node) ? 0 : SWAP_MS,
|
|
57
|
+
easing: ease,
|
|
58
|
+
css: (_t: number, u: number) => `transform: translateX(${side * u * 100}%)`,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The pane it replaces, out of the flow (the new one sets the height), sliding out the other way. */
|
|
63
|
+
function slideOut(node: HTMLElement) {
|
|
64
|
+
Object.assign(node.style, { position: 'absolute', left: '0', right: '0', [from === 'above' ? 'bottom' : 'top']: '0' })
|
|
65
|
+
return {
|
|
66
|
+
duration: still(node) ? 0 : SWAP_MS,
|
|
67
|
+
easing: ease,
|
|
68
|
+
css: (_t: number, u: number) => `transform: translateX(${-side * u * 100}%)`,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
let height = $state(0)
|
|
72
|
+
let pull = $state(0)
|
|
73
|
+
let pulling = $state(false)
|
|
74
|
+
const away = (dy: number) => (from === 'above' ? dy < 0 : dy > 0)
|
|
75
|
+
|
|
76
|
+
const pulls = drag({
|
|
77
|
+
axis: 'y',
|
|
78
|
+
enabled: () => open,
|
|
79
|
+
onStart: () => (pulling = true),
|
|
80
|
+
// Away from the page closes it; towards it, it barely gives.
|
|
81
|
+
onMove: (dy) => (pull = away(dy) ? dy : dy / 4),
|
|
82
|
+
onEnd: (dy, velocity) => {
|
|
83
|
+
pulling = false
|
|
84
|
+
pull = 0
|
|
85
|
+
if (away(dy) && carries(dy, height, velocity, 0.3)) onclose()
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// The pane stays drawn while the page falls back over it.
|
|
90
|
+
function stay(node: Element) {
|
|
91
|
+
return { duration: still(node) ? 0 : OUT_MS }
|
|
92
|
+
}
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<div {...rest} class={['tui-hang', className]}>
|
|
96
|
+
<div class="host" class:pushed={open} class:pulling style:--push="{from === 'above' ? -height : height}px" style:--pull="{pull}px">
|
|
97
|
+
<div class="main" inert={open} bind:this={main}>{@render children()}</div>
|
|
98
|
+
{#if open}
|
|
99
|
+
<button type="button" class="dismiss" aria-label={closeLabel} tabindex="-1" onclick={above} {@attach pulls}></button>
|
|
100
|
+
{/if}
|
|
101
|
+
{#if open}
|
|
102
|
+
<div class="pane {from}" bind:offsetHeight={height} out:stay {@attach pulls}>
|
|
103
|
+
{#key paneId}<div class="slot" in:slideIn out:slideOut>{@render pane()}</div>{/key}
|
|
104
|
+
</div>
|
|
105
|
+
{/if}
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
<style>
|
|
110
|
+
@layer tuidroid {
|
|
111
|
+
/* The pushed page flows off the edge, but titles and edge buttons standing out of a
|
|
112
|
+
block by up to a line still show, as they do in a page's padding. */
|
|
113
|
+
.tui-hang {
|
|
114
|
+
flex: 1;
|
|
115
|
+
height: 100%;
|
|
116
|
+
min-height: 0;
|
|
117
|
+
overflow: clip;
|
|
118
|
+
overflow-clip-margin: var(--tui-hang-bleed, 1.3em);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.host {
|
|
122
|
+
position: relative;
|
|
123
|
+
height: 100%;
|
|
124
|
+
/* Back when the pane closes: easing in, like falling back. */
|
|
125
|
+
transition: transform calc(0.24s * var(--tui-motion)) cubic-bezier(0.32, 0, 0.67, 0);
|
|
126
|
+
|
|
127
|
+
/* Pushed by the pane: easing out, like the pages' slide. */
|
|
128
|
+
&.pushed {
|
|
129
|
+
transform: translateY(calc(-1 * var(--push) + var(--pull)));
|
|
130
|
+
transition: transform calc(0.32s * var(--tui-motion)) cubic-bezier(0.33, 1, 0.68, 1);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
&.pulling {
|
|
134
|
+
transition: none;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.main {
|
|
139
|
+
height: 100%;
|
|
140
|
+
display: flex;
|
|
141
|
+
flex-direction: column;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* What is left of the page above an open pane: a tap closes it, a drag pulls it. */
|
|
145
|
+
.dismiss {
|
|
146
|
+
position: absolute;
|
|
147
|
+
inset: 0;
|
|
148
|
+
padding: 0;
|
|
149
|
+
background: none;
|
|
150
|
+
border: none;
|
|
151
|
+
border-radius: 0;
|
|
152
|
+
touch-action: none;
|
|
153
|
+
cursor: default;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* Just past the page's edge, as tall as its pane, at most the page's height. Vertical
|
|
157
|
+
drags here pull the pane rather than scroll it, unless its content scrolls. */
|
|
158
|
+
.pane {
|
|
159
|
+
position: absolute;
|
|
160
|
+
left: 0;
|
|
161
|
+
right: 0;
|
|
162
|
+
max-height: 100%;
|
|
163
|
+
display: flex;
|
|
164
|
+
flex-direction: column;
|
|
165
|
+
overflow-x: clip;
|
|
166
|
+
touch-action: none;
|
|
167
|
+
|
|
168
|
+
&.below {
|
|
169
|
+
top: 100%;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
&.above {
|
|
173
|
+
bottom: 100%;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* The room a page leaves for its blocks' edge buttons and titles comes with the pane,
|
|
178
|
+
so the push brings it into view too; each slot carries it, so two side by side while
|
|
179
|
+
they swap stand level. */
|
|
180
|
+
.slot {
|
|
181
|
+
min-height: 0;
|
|
182
|
+
display: flex;
|
|
183
|
+
flex-direction: column;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.below > .slot {
|
|
187
|
+
padding-top: var(--tui-hang-gap, 1.3em);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.above > .slot {
|
|
191
|
+
padding-bottom: var(--tui-hang-gap, 1em);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
open: boolean;
|
|
5
|
+
from?: 'below' | 'above';
|
|
6
|
+
paneId?: string;
|
|
7
|
+
onclose: () => void;
|
|
8
|
+
onswap?: (id: string) => void;
|
|
9
|
+
closeLabel?: string;
|
|
10
|
+
pane: Snippet;
|
|
11
|
+
children: Snippet;
|
|
12
|
+
}
|
|
13
|
+
declare const Hang: import("svelte").Component<Props, {}, "">;
|
|
14
|
+
type Hang = ReturnType<typeof Hang>;
|
|
15
|
+
export default Hang;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends { id: string }">
|
|
2
|
+
import type { Snippet } from 'svelte'
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
4
|
+
import { carries, drag, resist } from '../gestures/drag'
|
|
5
|
+
|
|
6
|
+
// Pages side by side, one in view, sliding to `index` as it changes (a TabBar beside it,
|
|
7
|
+
// bound to the same index). A sideways drag pulls the next page in and settles on release:
|
|
8
|
+
// on it when the drag went far or fast enough, else back; past the first or last page the
|
|
9
|
+
// drag resists. Up and down are left to scroll. Pages out of view are inert. Each page is
|
|
10
|
+
// the panel `{prefix}-page-{id}`, labelled by TabBar's tab.
|
|
11
|
+
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onchange'> {
|
|
12
|
+
pages: readonly T[]
|
|
13
|
+
index: number
|
|
14
|
+
page: Snippet<[T, number]>
|
|
15
|
+
swipe?: boolean
|
|
16
|
+
prefix?: string
|
|
17
|
+
onchange?: (index: number) => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let { pages, index = $bindable(0), page, swipe = true, prefix = 'tui', onchange, class: className, ...rest }: Props = $props()
|
|
21
|
+
|
|
22
|
+
let width = $state(1)
|
|
23
|
+
let dragX = $state(0)
|
|
24
|
+
let dragging = $state(false)
|
|
25
|
+
const pastEnd = (dx: number) => (index === 0 && dx > 0) || (index === pages.length - 1 && dx < 0)
|
|
26
|
+
|
|
27
|
+
function go(next: number) {
|
|
28
|
+
const clamped = Math.min(pages.length - 1, Math.max(0, next))
|
|
29
|
+
if (clamped === index) return
|
|
30
|
+
index = clamped
|
|
31
|
+
onchange?.(clamped)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const follow = drag({
|
|
35
|
+
axis: 'x',
|
|
36
|
+
enabled: () => swipe,
|
|
37
|
+
onStart: () => (dragging = true),
|
|
38
|
+
onMove: (dx) => (dragX = resist(dx, pastEnd(dx))),
|
|
39
|
+
onEnd: (dx, velocity) => {
|
|
40
|
+
dragging = false
|
|
41
|
+
dragX = 0
|
|
42
|
+
if (!pastEnd(dx) && carries(dx, width, velocity)) go(index + (dx < 0 ? 1 : -1))
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<div {...rest} class={['tui-pager', className]} bind:clientWidth={width} {@attach follow}>
|
|
48
|
+
<div class="track" class:dragging style:transform="translateX(calc({-index * 100}% + {dragX}px))">
|
|
49
|
+
{#each pages as item, i (item.id)}
|
|
50
|
+
<div class="page" id="{prefix}-page-{item.id}" role="tabpanel" aria-labelledby="{prefix}-tab-{item.id}" inert={i !== index}>
|
|
51
|
+
{@render page(item, i)}
|
|
52
|
+
</div>
|
|
53
|
+
{/each}
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
<style>
|
|
58
|
+
@layer tuidroid {
|
|
59
|
+
.tui-pager {
|
|
60
|
+
min-width: 0;
|
|
61
|
+
min-height: 0;
|
|
62
|
+
overflow: clip;
|
|
63
|
+
touch-action: pan-y;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.track {
|
|
67
|
+
display: flex;
|
|
68
|
+
height: 100%;
|
|
69
|
+
transition: transform var(--tui-slide);
|
|
70
|
+
|
|
71
|
+
/* Under the finger, the track follows without easing. */
|
|
72
|
+
&.dragging {
|
|
73
|
+
transition: none;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* Room above each page's blocks for the titles in their top edge, and below for the
|
|
78
|
+
buttons in their bottom edge, inside the page so the slide does not clip them. */
|
|
79
|
+
.page {
|
|
80
|
+
flex: 0 0 100%;
|
|
81
|
+
min-width: 0;
|
|
82
|
+
height: 100%;
|
|
83
|
+
box-sizing: border-box;
|
|
84
|
+
padding: 1em 0.6em 1.3em;
|
|
85
|
+
display: flex;
|
|
86
|
+
flex-direction: column;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
</style>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
declare function $$render<T extends {
|
|
4
|
+
id: string;
|
|
5
|
+
}>(): {
|
|
6
|
+
props: Omit<HTMLAttributes<HTMLDivElement>, "children" | "onchange"> & {
|
|
7
|
+
pages: readonly T[];
|
|
8
|
+
index: number;
|
|
9
|
+
page: Snippet<[T, number]>;
|
|
10
|
+
swipe?: boolean;
|
|
11
|
+
prefix?: string;
|
|
12
|
+
onchange?: (index: number) => void;
|
|
13
|
+
};
|
|
14
|
+
exports: {};
|
|
15
|
+
bindings: "index";
|
|
16
|
+
slots: {};
|
|
17
|
+
events: {};
|
|
18
|
+
};
|
|
19
|
+
declare class __sveltets_Render<T extends {
|
|
20
|
+
id: string;
|
|
21
|
+
}> {
|
|
22
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
23
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
24
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
25
|
+
bindings(): "index";
|
|
26
|
+
exports(): {};
|
|
27
|
+
}
|
|
28
|
+
interface $$IsomorphicComponent {
|
|
29
|
+
new <T extends {
|
|
30
|
+
id: string;
|
|
31
|
+
}>(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']>> & {
|
|
32
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
33
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
34
|
+
<T extends {
|
|
35
|
+
id: string;
|
|
36
|
+
}>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
37
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
38
|
+
}
|
|
39
|
+
declare const Pager: $$IsomorphicComponent;
|
|
40
|
+
type Pager<T extends {
|
|
41
|
+
id: string;
|
|
42
|
+
}> = InstanceType<typeof Pager<T>>;
|
|
43
|
+
export default Pager;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
import type { IconPath } from '../icons/Icon.svelte'
|
|
6
|
+
import type { IconName } from '../icons/material'
|
|
7
|
+
import Block from '../layout/Block.svelte'
|
|
8
|
+
|
|
9
|
+
// A pane: a Block as a dialog, with ✕ Close set into the right of its top edge and its own
|
|
10
|
+
// `action` (an edge button) at the right of its bottom edge. Escape closes it, and it
|
|
11
|
+
// takes the focus as it opens. Its content scrolls once it is taller than its room;
|
|
12
|
+
// until then a drag on it is left to the Hang around it, which pulls it closed.
|
|
13
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
14
|
+
title: string
|
|
15
|
+
icon?: IconName | IconPath
|
|
16
|
+
onclose: () => void
|
|
17
|
+
closeLabel?: string
|
|
18
|
+
action?: Snippet
|
|
19
|
+
children: Snippet
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let { title, icon, onclose, closeLabel = 'Close', action, children, class: className, ...rest }: Props = $props()
|
|
23
|
+
|
|
24
|
+
let scrolls = $state(false)
|
|
25
|
+
|
|
26
|
+
// Whether its content outgrows its room, so a drag scrolls it rather than pulling.
|
|
27
|
+
function overflow(content: HTMLElement) {
|
|
28
|
+
const measure = () => (scrolls = content.scrollHeight > content.clientHeight + 1)
|
|
29
|
+
const observer = new ResizeObserver(measure)
|
|
30
|
+
observer.observe(content)
|
|
31
|
+
measure()
|
|
32
|
+
return () => observer.disconnect()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Takes the focus as it opens, and gives it back to what had it (the button that opened
|
|
36
|
+
// it) as it closes.
|
|
37
|
+
function focus(node: HTMLElement) {
|
|
38
|
+
const before = document.activeElement
|
|
39
|
+
node.focus({ preventScroll: true })
|
|
40
|
+
return () => {
|
|
41
|
+
if (before instanceof HTMLElement && before.isConnected) requestAnimationFrame(() => before.focus({ preventScroll: true }))
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function keydown(event: KeyboardEvent) {
|
|
46
|
+
if (event.key === 'Escape') onclose()
|
|
47
|
+
}
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<svelte:window onkeydown={keydown} />
|
|
51
|
+
|
|
52
|
+
<!-- Its own button at the right of the bottom edge. -->
|
|
53
|
+
{#snippet edge()}{@render action?.()}{/snippet}
|
|
54
|
+
|
|
55
|
+
{#snippet close()}<Button variant="edge" icon="close" quit onclick={onclose}>{closeLabel}</Button>{/snippet}
|
|
56
|
+
|
|
57
|
+
<div {...rest} class={['tui-pane', className]} role="dialog" aria-modal="true" aria-label={title} tabindex="-1" {@attach focus}>
|
|
58
|
+
<Block {title} {icon} headingRight={close} actions={action ? edge : undefined} actionsAlign="end" class="tui-pane-block">
|
|
59
|
+
<div class="content" class:scrolls {@attach overflow}>{@render children()}</div>
|
|
60
|
+
</Block>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<style>
|
|
64
|
+
@layer tuidroid {
|
|
65
|
+
/* Room for the title above and the buttons below; across, it is as wide as the page's
|
|
66
|
+
blocks. */
|
|
67
|
+
.tui-pane {
|
|
68
|
+
min-height: 0;
|
|
69
|
+
display: flex;
|
|
70
|
+
flex-direction: column;
|
|
71
|
+
box-sizing: border-box;
|
|
72
|
+
padding: 1em 0 1.3em;
|
|
73
|
+
outline: none;
|
|
74
|
+
|
|
75
|
+
& :global(.tui-pane-block) {
|
|
76
|
+
min-height: 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.content {
|
|
81
|
+
flex: 1;
|
|
82
|
+
min-height: 0;
|
|
83
|
+
overflow: hidden auto;
|
|
84
|
+
overscroll-behavior: contain;
|
|
85
|
+
padding-top: 0.3em;
|
|
86
|
+
touch-action: none;
|
|
87
|
+
|
|
88
|
+
&.scrolls {
|
|
89
|
+
touch-action: pan-y;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { IconPath } from '../icons/Icon.svelte';
|
|
4
|
+
import type { IconName } from '../icons/material';
|
|
5
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
6
|
+
title: string;
|
|
7
|
+
icon?: IconName | IconPath;
|
|
8
|
+
onclose: () => void;
|
|
9
|
+
closeLabel?: string;
|
|
10
|
+
action?: Snippet;
|
|
11
|
+
children: Snippet;
|
|
12
|
+
}
|
|
13
|
+
declare const Pane: import("svelte").Component<Props, {}, "">;
|
|
14
|
+
type Pane = ReturnType<typeof Pane>;
|
|
15
|
+
export default Pane;
|