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.
Files changed (157) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +181 -2
  3. package/dist/arrange/Mover.svelte +42 -0
  4. package/dist/arrange/Mover.svelte.d.ts +29 -0
  5. package/dist/arrange/PutAway.svelte +48 -0
  6. package/dist/arrange/PutAway.svelte.d.ts +30 -0
  7. package/dist/arrange/arrangement.svelte.d.ts +27 -0
  8. package/dist/arrange/arrangement.svelte.js +44 -0
  9. package/dist/arrange/order.d.ts +7 -0
  10. package/dist/arrange/order.js +20 -0
  11. package/dist/calendar/Calendar.svelte +328 -0
  12. package/dist/calendar/Calendar.svelte.d.ts +28 -0
  13. package/dist/calendar/MonthPicker.svelte +41 -0
  14. package/dist/calendar/MonthPicker.svelte.d.ts +10 -0
  15. package/dist/calendar/YearPicker.svelte +61 -0
  16. package/dist/calendar/YearPicker.svelte.d.ts +11 -0
  17. package/dist/calendar/dates.d.ts +23 -0
  18. package/dist/calendar/dates.js +54 -0
  19. package/dist/charts/BarChart.svelte +98 -0
  20. package/dist/charts/BarChart.svelte.d.ts +28 -0
  21. package/dist/charts/ChartFrame.svelte +133 -0
  22. package/dist/charts/ChartFrame.svelte.d.ts +21 -0
  23. package/dist/charts/ColumnChart.svelte +79 -0
  24. package/dist/charts/ColumnChart.svelte.d.ts +20 -0
  25. package/dist/charts/HeatGrid.svelte +110 -0
  26. package/dist/charts/HeatGrid.svelte.d.ts +22 -0
  27. package/dist/charts/LineChart.svelte +132 -0
  28. package/dist/charts/LineChart.svelte.d.ts +29 -0
  29. package/dist/charts/StripChart.svelte +80 -0
  30. package/dist/charts/StripChart.svelte.d.ts +27 -0
  31. package/dist/charts/scale.d.ts +17 -0
  32. package/dist/charts/scale.js +35 -0
  33. package/dist/controls/AccentStepper.svelte +24 -0
  34. package/dist/controls/AccentStepper.svelte.d.ts +8 -0
  35. package/dist/controls/Button.svelte +264 -0
  36. package/dist/controls/Button.svelte.d.ts +26 -0
  37. package/dist/controls/Cycle.svelte +27 -0
  38. package/dist/controls/Cycle.svelte.d.ts +31 -0
  39. package/dist/controls/NumberStepper.svelte +28 -0
  40. package/dist/controls/NumberStepper.svelte.d.ts +12 -0
  41. package/dist/controls/OptionStepper.svelte +42 -0
  42. package/dist/controls/OptionStepper.svelte.d.ts +34 -0
  43. package/dist/controls/Segmented.svelte +72 -0
  44. package/dist/controls/Segmented.svelte.d.ts +35 -0
  45. package/dist/controls/SettingRow.svelte +59 -0
  46. package/dist/controls/SettingRow.svelte.d.ts +11 -0
  47. package/dist/controls/Stepper.svelte +151 -0
  48. package/dist/controls/Stepper.svelte.d.ts +17 -0
  49. package/dist/controls/TextInput.svelte +176 -0
  50. package/dist/controls/TextInput.svelte.d.ts +12 -0
  51. package/dist/controls/Toggle.svelte +22 -0
  52. package/dist/controls/Toggle.svelte.d.ts +9 -0
  53. package/dist/data/BarRows.svelte +75 -0
  54. package/dist/data/BarRows.svelte.d.ts +15 -0
  55. package/dist/data/CellBar.svelte +55 -0
  56. package/dist/data/CellBar.svelte.d.ts +13 -0
  57. package/dist/data/Delta.svelte +28 -0
  58. package/dist/data/Delta.svelte.d.ts +11 -0
  59. package/dist/data/Hatch.svelte +9 -0
  60. package/dist/data/Hatch.svelte.d.ts +8 -0
  61. package/dist/data/KeyValues.svelte +56 -0
  62. package/dist/data/KeyValues.svelte.d.ts +14 -0
  63. package/dist/data/Legend.svelte +64 -0
  64. package/dist/data/Legend.svelte.d.ts +15 -0
  65. package/dist/data/Meter.svelte +46 -0
  66. package/dist/data/Meter.svelte.d.ts +9 -0
  67. package/dist/data/StackedBar.svelte +64 -0
  68. package/dist/data/StackedBar.svelte.d.ts +14 -0
  69. package/dist/data/Swatch.svelte +56 -0
  70. package/dist/data/Swatch.svelte.d.ts +11 -0
  71. package/dist/data/Table.svelte +86 -0
  72. package/dist/data/Table.svelte.d.ts +16 -0
  73. package/dist/data/Value.svelte +32 -0
  74. package/dist/data/Value.svelte.d.ts +12 -0
  75. package/dist/data/cells.d.ts +27 -0
  76. package/dist/data/cells.js +41 -0
  77. package/dist/data/fit.d.ts +10 -0
  78. package/dist/data/fit.js +35 -0
  79. package/dist/gestures/drag.d.ts +28 -0
  80. package/dist/gestures/drag.js +110 -0
  81. package/dist/gestures/hold.d.ts +7 -0
  82. package/dist/gestures/hold.js +59 -0
  83. package/dist/gestures/pick.d.ts +5 -0
  84. package/dist/gestures/pick.js +60 -0
  85. package/dist/haptics.d.ts +5 -0
  86. package/dist/haptics.js +16 -0
  87. package/dist/icons/Icon.svelte +52 -0
  88. package/dist/icons/Icon.svelte.d.ts +17 -0
  89. package/dist/icons/material.d.ts +68 -0
  90. package/dist/icons/material.js +69 -0
  91. package/dist/index.d.ts +75 -0
  92. package/dist/index.js +91 -0
  93. package/dist/layout/Alert.svelte +46 -0
  94. package/dist/layout/Alert.svelte.d.ts +12 -0
  95. package/dist/layout/Block.svelte +166 -0
  96. package/dist/layout/Block.svelte.d.ts +22 -0
  97. package/dist/layout/Panes.svelte +41 -0
  98. package/dist/layout/Panes.svelte.d.ts +9 -0
  99. package/dist/layout/Rows.svelte +37 -0
  100. package/dist/layout/Rows.svelte.d.ts +8 -0
  101. package/dist/layout/Split.svelte +18 -0
  102. package/dist/layout/Split.svelte.d.ts +4 -0
  103. package/dist/layout/Stage.svelte +59 -0
  104. package/dist/layout/Stage.svelte.d.ts +10 -0
  105. package/dist/layout/Unfold.svelte +25 -0
  106. package/dist/layout/Unfold.svelte.d.ts +9 -0
  107. package/dist/lists/ListItem.svelte +75 -0
  108. package/dist/lists/ListItem.svelte.d.ts +13 -0
  109. package/dist/lists/SwipeRow.svelte +158 -0
  110. package/dist/lists/SwipeRow.svelte.d.ts +21 -0
  111. package/dist/lists/UndoRow.svelte +37 -0
  112. package/dist/lists/UndoRow.svelte.d.ts +10 -0
  113. package/dist/motion/FlipCard.svelte +197 -0
  114. package/dist/motion/FlipCard.svelte.d.ts +34 -0
  115. package/dist/motion/Hero.svelte +59 -0
  116. package/dist/motion/Hero.svelte.d.ts +9 -0
  117. package/dist/motion/ShuffleText.svelte +42 -0
  118. package/dist/motion/ShuffleText.svelte.d.ts +13 -0
  119. package/dist/motion/TypeText.svelte +68 -0
  120. package/dist/motion/TypeText.svelte.d.ts +11 -0
  121. package/dist/motion/shuffle.d.ts +24 -0
  122. package/dist/motion/shuffle.js +58 -0
  123. package/dist/motion/still.d.ts +2 -0
  124. package/dist/motion/still.js +7 -0
  125. package/dist/motion/sweep.d.ts +14 -0
  126. package/dist/motion/sweep.js +59 -0
  127. package/dist/motion/typing.d.ts +9 -0
  128. package/dist/motion/typing.js +19 -0
  129. package/dist/motion/unfold.d.ts +4 -0
  130. package/dist/motion/unfold.js +13 -0
  131. package/dist/nav/Hang.svelte +194 -0
  132. package/dist/nav/Hang.svelte.d.ts +15 -0
  133. package/dist/nav/Pager.svelte +89 -0
  134. package/dist/nav/Pager.svelte.d.ts +43 -0
  135. package/dist/nav/Pane.svelte +93 -0
  136. package/dist/nav/Pane.svelte.d.ts +15 -0
  137. package/dist/nav/Shell.svelte +40 -0
  138. package/dist/nav/Shell.svelte.d.ts +34 -0
  139. package/dist/nav/TabBar.svelte +139 -0
  140. package/dist/nav/TabBar.svelte.d.ts +15 -0
  141. package/dist/styles/base.css +87 -0
  142. package/dist/styles/tokens.css +253 -0
  143. package/dist/text/Fields.svelte +28 -0
  144. package/dist/text/Fields.svelte.d.ts +8 -0
  145. package/dist/text/fields.d.ts +6 -0
  146. package/dist/text/fields.js +16 -0
  147. package/dist/theme/FlavourButton.svelte +55 -0
  148. package/dist/theme/FlavourButton.svelte.d.ts +13 -0
  149. package/dist/theme/Theme.svelte +48 -0
  150. package/dist/theme/Theme.svelte.d.ts +15 -0
  151. package/dist/theme/palette.d.ts +23 -0
  152. package/dist/theme/palette.js +55 -0
  153. package/dist/theme/reveal.d.ts +10 -0
  154. package/dist/theme/reveal.js +92 -0
  155. package/dist/theme/theme.d.ts +15 -0
  156. package/dist/theme/theme.js +21 -0
  157. package/package.json +72 -4
@@ -0,0 +1,56 @@
1
+ <script lang="ts" module>
2
+ import type { Snippet } from 'svelte'
3
+
4
+ export interface KeyValue {
5
+ label: string
6
+ value: string | number
7
+ note?: string | Snippet // when or where, at the right edge
8
+ }
9
+ </script>
10
+
11
+ <script lang="ts">
12
+ import type { HTMLAttributes } from 'svelte/elements'
13
+
14
+ // Records as a table without lines: what, how much in bold accent, and a note (when,
15
+ // where) at the right edge. A row without a note lets its value run on across the line.
16
+ interface Props extends HTMLAttributes<HTMLDivElement> {
17
+ items: readonly KeyValue[]
18
+ separator?: string // after each label: ":"
19
+ }
20
+
21
+ let { items, separator = ':', class: className, ...rest }: Props = $props()
22
+ </script>
23
+
24
+ <div {...rest} class={['tui-keyvalues', className]}>
25
+ {#each items as item (item.label)}
26
+ <span class="label">{item.label}{separator}</span>
27
+ <span class="value" class:rest={!item.note}>{item.value}</span>
28
+ {#if item.note}<span class="note"
29
+ >{#if typeof item.note === 'string'}{item.note}{:else}{@render item.note()}{/if}</span
30
+ >{/if}
31
+ {/each}
32
+ </div>
33
+
34
+ <style>
35
+ @layer tuidroid {
36
+ .tui-keyvalues {
37
+ display: grid;
38
+ grid-template-columns: max-content max-content 1fr;
39
+ column-gap: 1ch;
40
+ row-gap: 0.1em;
41
+ }
42
+
43
+ .value {
44
+ font-weight: 700;
45
+ color: var(--tui-block-tone, var(--tui-accent));
46
+
47
+ &.rest {
48
+ grid-column: 2 / -1;
49
+ }
50
+ }
51
+
52
+ .note {
53
+ text-align: right;
54
+ }
55
+ }
56
+ </style>
@@ -0,0 +1,14 @@
1
+ import type { Snippet } from 'svelte';
2
+ export interface KeyValue {
3
+ label: string;
4
+ value: string | number;
5
+ note?: string | Snippet;
6
+ }
7
+ import type { HTMLAttributes } from 'svelte/elements';
8
+ interface Props extends HTMLAttributes<HTMLDivElement> {
9
+ items: readonly KeyValue[];
10
+ separator?: string;
11
+ }
12
+ declare const KeyValues: import("svelte").Component<Props, {}, "">;
13
+ type KeyValues = ReturnType<typeof KeyValues>;
14
+ export default KeyValues;
@@ -0,0 +1,64 @@
1
+ <script lang="ts" module>
2
+ import type { SwatchKind } from './Swatch.svelte'
3
+
4
+ export interface LegendItem {
5
+ label: string
6
+ colour: string
7
+ kind?: SwatchKind
8
+ }
9
+ </script>
10
+
11
+ <script lang="ts">
12
+ import type { HTMLAttributes } from 'svelte/elements'
13
+ import Swatch from './Swatch.svelte'
14
+
15
+ // What a chart's colours mean: a swatch and its name for each, kept together when the
16
+ // line wraps, with `separator` between them (" · ") or just room. With `edge` it sits in
17
+ // a Block's border (actions), a little smaller, cutting the line like a title.
18
+ interface Props extends HTMLAttributes<HTMLSpanElement> {
19
+ items: LegendItem[]
20
+ separator?: string
21
+ edge?: boolean
22
+ }
23
+
24
+ let { items, separator, edge = false, class: className, ...rest }: Props = $props()
25
+ </script>
26
+
27
+ <span {...rest} class={['tui-legend', className, { edge }]}>
28
+ {#each items as item, i (item.label)}
29
+ {#if separator && i}<span class="separator" aria-hidden="true">{separator}</span>{/if}
30
+ <span class="item"><Swatch colour={item.colour} kind={item.kind} /> {item.label}</span>
31
+ {/each}
32
+ </span>
33
+
34
+ <style>
35
+ @layer tuidroid {
36
+ .tui-legend {
37
+ display: inline-flex;
38
+ flex-wrap: wrap;
39
+ justify-content: center;
40
+ column-gap: 2ch;
41
+ }
42
+
43
+ .tui-legend:has(.separator) {
44
+ column-gap: 0;
45
+ }
46
+
47
+ .edge {
48
+ column-gap: 1.2ch;
49
+ margin: 0 auto;
50
+ padding: 0 0.8ch;
51
+ background: var(--tui-block-cut, var(--tui-bg));
52
+ font-size: 0.85em;
53
+ }
54
+
55
+ .item,
56
+ .separator {
57
+ white-space: pre;
58
+ }
59
+
60
+ .separator {
61
+ color: var(--tui-muted);
62
+ }
63
+ }
64
+ </style>
@@ -0,0 +1,15 @@
1
+ import type { SwatchKind } from './Swatch.svelte';
2
+ export interface LegendItem {
3
+ label: string;
4
+ colour: string;
5
+ kind?: SwatchKind;
6
+ }
7
+ import type { HTMLAttributes } from 'svelte/elements';
8
+ interface Props extends HTMLAttributes<HTMLSpanElement> {
9
+ items: LegendItem[];
10
+ separator?: string;
11
+ edge?: boolean;
12
+ }
13
+ declare const Legend: import("svelte").Component<Props, {}, "">;
14
+ type Legend = ReturnType<typeof Legend>;
15
+ export default Legend;
@@ -0,0 +1,46 @@
1
+ <script lang="ts">
2
+ import type { HTMLAttributes } from 'svelte/elements'
3
+
4
+ // A share as a smooth bar a little under a line high: the filled part in the accent (or
5
+ // `colour`) over a track in the button colour, filling the width it is given. For
6
+ // shares read beside a number (recall, coverage); CellBar draws one in text cells.
7
+ interface Props extends HTMLAttributes<HTMLSpanElement> {
8
+ value: number // 0 to 1
9
+ colour?: string
10
+ label?: string
11
+ }
12
+
13
+ let { value, colour, label, class: className, ...rest }: Props = $props()
14
+ const percent = $derived(Math.max(0, Math.min(1, value)) * 100)
15
+ </script>
16
+
17
+ <span
18
+ {...rest}
19
+ class={['tui-meter', className]}
20
+ role="meter"
21
+ aria-valuemin={0}
22
+ aria-valuemax={100}
23
+ aria-valuenow={Math.round(percent)}
24
+ aria-label={label}
25
+ style:--tui-meter-colour={colour}><span class="fill" style:width="{percent}%"></span></span
26
+ >
27
+
28
+ <style>
29
+ @layer tuidroid {
30
+ .tui-meter {
31
+ display: block;
32
+ height: 0.7em;
33
+ border-radius: 0.2em;
34
+ background: var(--tui-button);
35
+ overflow: hidden;
36
+ }
37
+
38
+ .fill {
39
+ display: block;
40
+ height: 100%;
41
+ border-radius: 0.2em;
42
+ background: var(--tui-meter-colour, var(--tui-accent));
43
+ transition: width var(--tui-tone) ease;
44
+ }
45
+ }
46
+ </style>
@@ -0,0 +1,9 @@
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
+ interface Props extends HTMLAttributes<HTMLSpanElement> {
3
+ value: number;
4
+ colour?: string;
5
+ label?: string;
6
+ }
7
+ declare const Meter: import("svelte").Component<Props, {}, "">;
8
+ type Meter = ReturnType<typeof Meter>;
9
+ export default Meter;
@@ -0,0 +1,64 @@
1
+ <script lang="ts" module>
2
+ export interface Part {
3
+ value: number
4
+ colour: string
5
+ label?: string
6
+ }
7
+ </script>
8
+
9
+ <script lang="ts">
10
+ import type { HTMLAttributes } from 'svelte/elements'
11
+ import { apportion } from './cells'
12
+ import { fit } from './fit'
13
+
14
+ // Shares of a whole as one line of text cells, each part's cells in its colour, the total
15
+ // exact: a fast's hours by stage. `cells` across, or as many as fit the width given.
16
+ interface Props extends HTMLAttributes<HTMLSpanElement> {
17
+ parts: readonly Part[]
18
+ cells?: number
19
+ label?: string
20
+ }
21
+
22
+ let { parts, cells, label, class: className, ...rest }: Props = $props()
23
+
24
+ let fitted = $state(0)
25
+ const counts = $derived(
26
+ apportion(
27
+ parts.map((p) => p.value),
28
+ cells ?? fitted,
29
+ ),
30
+ )
31
+ const total = $derived(parts.reduce((sum, p) => sum + Math.max(0, p.value), 0))
32
+ const described = $derived(
33
+ label ??
34
+ parts
35
+ .filter((p) => p.label)
36
+ .map((p) => `${p.label} ${total ? Math.round((Math.max(0, p.value) / total) * 100) : 0}%`)
37
+ .join(', '),
38
+ )
39
+ </script>
40
+
41
+ <span
42
+ {...rest}
43
+ class={['tui-stackedbar', className, { fill: cells === undefined }]}
44
+ role="img"
45
+ aria-label={described || undefined}
46
+ {@attach cells === undefined && fit((f) => (fitted = f.cells))}
47
+ >{#each parts as part, i (i)}{#if counts[i]}<span style:color={part.colour}>{'█'.repeat(counts[i])}</span>{/if}{/each}</span
48
+ >
49
+
50
+ <style>
51
+ @layer tuidroid {
52
+ .tui-stackedbar {
53
+ position: relative;
54
+ white-space: pre;
55
+ font-variant-ligatures: none;
56
+ line-height: 1.2;
57
+
58
+ &.fill {
59
+ display: block;
60
+ overflow: hidden;
61
+ }
62
+ }
63
+ }
64
+ </style>
@@ -0,0 +1,14 @@
1
+ export interface Part {
2
+ value: number;
3
+ colour: string;
4
+ label?: string;
5
+ }
6
+ import type { HTMLAttributes } from 'svelte/elements';
7
+ interface Props extends HTMLAttributes<HTMLSpanElement> {
8
+ parts: readonly Part[];
9
+ cells?: number;
10
+ label?: string;
11
+ }
12
+ declare const StackedBar: import("svelte").Component<Props, {}, "">;
13
+ type StackedBar = ReturnType<typeof StackedBar>;
14
+ export default StackedBar;
@@ -0,0 +1,56 @@
1
+ <script lang="ts" module>
2
+ /** filled ■, outlined □, or outlined and hatched ▨. */
3
+ export type SwatchKind = 'filled' | 'outline' | 'hatched'
4
+ </script>
5
+
6
+ <script lang="ts">
7
+ import type { SVGAttributes } from 'svelte/elements'
8
+ import Hatch from './Hatch.svelte'
9
+
10
+ // A square of colour at the text's size, for a legend or beside a name: filled, outlined
11
+ // or hatched, in any CSS colour (the text's by default).
12
+ interface Props extends SVGAttributes<SVGSVGElement> {
13
+ colour?: string
14
+ kind?: SwatchKind
15
+ label?: string
16
+ }
17
+
18
+ let { colour = 'currentColor', kind = 'filled', label, class: className, ...rest }: Props = $props()
19
+ const id = $props.id()
20
+ </script>
21
+
22
+ <svg
23
+ {...rest}
24
+ class={['tui-swatch', className]}
25
+ viewBox="0 0 10 10"
26
+ role={label ? 'img' : undefined}
27
+ aria-label={label}
28
+ aria-hidden={label ? undefined : 'true'}
29
+ >
30
+ {#if kind === 'filled'}
31
+ <rect width="10" height="10" rx="2" style:fill={colour} />
32
+ {:else}
33
+ {#if kind === 'hatched'}<defs><Hatch id="{id}-hatch" {colour} /></defs>{/if}
34
+ <rect
35
+ x="0.75"
36
+ y="0.75"
37
+ width="8.5"
38
+ height="8.5"
39
+ rx="2"
40
+ stroke-width="1.5"
41
+ style:stroke={colour}
42
+ style:fill={kind === 'hatched' ? `url(#${id}-hatch)` : 'none'}
43
+ />
44
+ {/if}
45
+ </svg>
46
+
47
+ <style>
48
+ @layer tuidroid {
49
+ .tui-swatch {
50
+ width: 0.7em;
51
+ height: 0.7em;
52
+ flex: none;
53
+ vertical-align: -0.05em;
54
+ }
55
+ }
56
+ </style>
@@ -0,0 +1,11 @@
1
+ /** filled ■, outlined □, or outlined and hatched ▨. */
2
+ export type SwatchKind = 'filled' | 'outline' | 'hatched';
3
+ import type { SVGAttributes } from 'svelte/elements';
4
+ interface Props extends SVGAttributes<SVGSVGElement> {
5
+ colour?: string;
6
+ kind?: SwatchKind;
7
+ label?: string;
8
+ }
9
+ declare const Swatch: import("svelte").Component<Props, {}, "">;
10
+ type Swatch = ReturnType<typeof Swatch>;
11
+ export default Swatch;
@@ -0,0 +1,86 @@
1
+ <script lang="ts" module>
2
+ export interface TableRow {
3
+ head?: string // what the row is, muted at its start: nom, acc
4
+ cells: readonly (string | null)[]
5
+ }
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import type { Snippet } from 'svelte'
10
+ import type { HTMLTableAttributes } from 'svelte/elements'
11
+
12
+ // A table without lines, as a terminal draws one: `columns` heads over the cells and each
13
+ // row's head before them, both muted; an empty cell shows `empty`. `cell` draws a cell
14
+ // when it needs markup (an article in its gender's colour). A noun's forms, a verb's,
15
+ // adjective endings.
16
+ interface Props extends HTMLTableAttributes {
17
+ rows: readonly TableRow[]
18
+ columns?: readonly string[]
19
+ caption?: string
20
+ empty?: string
21
+ cell?: Snippet<[text: string, row: number, column: number]>
22
+ }
23
+
24
+ let { rows, columns, caption, empty = '–', cell, class: className, ...rest }: Props = $props()
25
+
26
+ const headed = $derived(rows.some((row) => row.head !== undefined))
27
+ </script>
28
+
29
+ <table {...rest} class={['tui-table', className]}>
30
+ {#if caption}<caption>{caption}</caption>{/if}
31
+ {#if columns}
32
+ <thead>
33
+ <tr>
34
+ {#if headed}<td></td>{/if}
35
+ {#each columns as column, i (i)}<th scope="col">{column}</th>{/each}
36
+ </tr>
37
+ </thead>
38
+ {/if}
39
+ <tbody>
40
+ {#each rows as row, r (r)}
41
+ <tr>
42
+ {#if headed}<th scope="row">{row.head ?? ''}</th>{/if}
43
+ {#each row.cells as text, c (c)}
44
+ <td
45
+ >{#if text === null}<span class="empty">{empty}</span>{:else if cell}{@render cell(text, r, c)}{:else}{text}{/if}</td
46
+ >
47
+ {/each}
48
+ </tr>
49
+ {/each}
50
+ </tbody>
51
+ </table>
52
+
53
+ <style>
54
+ @layer tuidroid {
55
+ .tui-table {
56
+ border-collapse: collapse;
57
+ font-variant-ligatures: none;
58
+ }
59
+
60
+ caption {
61
+ text-align: left;
62
+ color: var(--tui-muted);
63
+ }
64
+
65
+ th,
66
+ td {
67
+ text-align: left;
68
+ padding: 0.1em 2ch 0.1em 0;
69
+ font-weight: normal;
70
+ vertical-align: top;
71
+ white-space: nowrap;
72
+ }
73
+
74
+ th {
75
+ color: var(--tui-muted);
76
+ }
77
+
78
+ tr > :last-child {
79
+ padding-right: 0;
80
+ }
81
+
82
+ .empty {
83
+ color: var(--tui-muted);
84
+ }
85
+ }
86
+ </style>
@@ -0,0 +1,16 @@
1
+ export interface TableRow {
2
+ head?: string;
3
+ cells: readonly (string | null)[];
4
+ }
5
+ import type { Snippet } from 'svelte';
6
+ import type { HTMLTableAttributes } from 'svelte/elements';
7
+ interface Props extends HTMLTableAttributes {
8
+ rows: readonly TableRow[];
9
+ columns?: readonly string[];
10
+ caption?: string;
11
+ empty?: string;
12
+ cell?: Snippet<[text: string, row: number, column: number]>;
13
+ }
14
+ declare const Table: import("svelte").Component<Props, {}, "">;
15
+ type Table = ReturnType<typeof Table>;
16
+ export default Table;
@@ -0,0 +1,32 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte'
3
+ import type { HTMLAttributes } from 'svelte/elements'
4
+ import ShuffleText from '../motion/ShuffleText.svelte'
5
+ import { tone as toneColour, type Tone } from '../theme/palette'
6
+
7
+ // A live value: bold, in the accent, or in its `tone`, or in the tone of the Block it
8
+ // sits in, fading as the tone changes. With `shuffle` a new value runs the letter
9
+ // shuffle. `children` stand in for `value` when it needs markup.
10
+ interface Props extends HTMLAttributes<HTMLSpanElement> {
11
+ value?: string | number
12
+ tone?: Tone
13
+ shuffle?: boolean
14
+ children?: Snippet
15
+ }
16
+
17
+ let { value = '', tone, shuffle = false, children, class: className, ...rest }: Props = $props()
18
+ </script>
19
+
20
+ <span {...rest} class={['tui-value', className]} style:--tui-value-colour={tone && toneColour(tone)}
21
+ >{#if children}{@render children()}{:else if shuffle}<ShuffleText text={value} />{:else}{value}{/if}</span
22
+ >
23
+
24
+ <style>
25
+ @layer tuidroid {
26
+ .tui-value {
27
+ font-weight: 700;
28
+ color: var(--tui-value-colour, var(--tui-block-tone, var(--tui-accent)));
29
+ transition: color var(--tui-tone) ease;
30
+ }
31
+ }
32
+ </style>
@@ -0,0 +1,12 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import { type Tone } from '../theme/palette';
4
+ interface Props extends HTMLAttributes<HTMLSpanElement> {
5
+ value?: string | number;
6
+ tone?: Tone;
7
+ shuffle?: boolean;
8
+ children?: Snippet;
9
+ }
10
+ declare const Value: import("svelte").Component<Props, {}, "">;
11
+ type Value = ReturnType<typeof Value>;
12
+ export default Value;
@@ -0,0 +1,27 @@
1
+ export declare const FILL = "\u2588";
2
+ export declare const SHADE = "\u2591";
3
+ export declare const HATCH = "\u2571";
4
+ /** From `at` (a share of the bar, 0 to 1) on, cells take `colour`. */
5
+ export interface Stop {
6
+ at: number;
7
+ colour: string;
8
+ }
9
+ export interface Run {
10
+ text: string;
11
+ colour: string | null;
12
+ hatched?: boolean;
13
+ }
14
+ export interface ProgressOptions {
15
+ cells: number;
16
+ stops?: readonly Stop[];
17
+ colour?: string;
18
+ hatchRest?: boolean;
19
+ }
20
+ /** `value` (0 to 1) as `cells` text cells: each filled one in the colour of the stop it
21
+ * falls in, the rest shaded, or hatched in their stops' colours with `hatchRest`. */
22
+ export declare function progressCells(value: number, { cells, stops, colour, hatchRest }: ProgressOptions): Run[];
23
+ /** `cells` shared among `values` by size, the total exact (the largest remainders take the
24
+ * cells rounding leaves over), and a value of nothing getting none. */
25
+ export declare function apportion(values: readonly number[], cells: number): number[];
26
+ /** `cells` shared among spans as `spans` are, each at least one cell, the total exact. */
27
+ export declare const spread: (spans: readonly number[], cells: number) => number[];
@@ -0,0 +1,41 @@
1
+ // Bars drawn in text cells: █ filled, ░ the rest to come, ╱ a near miss's shortfall. Each
2
+ // cell takes the colour of the segment it falls in, and cells of one colour run together
3
+ // so each run is one span.
4
+ export const FILL = '█';
5
+ export const SHADE = '░';
6
+ export const HATCH = '╱';
7
+ /** `value` (0 to 1) as `cells` text cells: each filled one in the colour of the stop it
8
+ * falls in, the rest shaded, or hatched in their stops' colours with `hatchRest`. */
9
+ export function progressCells(value, { cells, stops = [], colour = 'var(--tui-accent)', hatchRest = false }) {
10
+ const count = Math.max(0, Math.floor(cells));
11
+ const filled = Math.round(Math.min(1, Math.max(0, value)) * count);
12
+ const runs = [];
13
+ for (let i = 0; i < count; i++) {
14
+ const mid = (i + 0.5) / count; // the middle of the cell, as a share of the bar
15
+ const reached = stops.reduce((at, stop) => (mid >= stop.at ? stop.colour : at), colour);
16
+ const hatched = i >= filled && hatchRest;
17
+ const cellColour = i < filled || hatched ? reached : null;
18
+ const text = i < filled ? FILL : hatched ? HATCH : SHADE;
19
+ const last = runs.at(-1);
20
+ if (last && last.colour === cellColour && (last.hatched ?? false) === hatched)
21
+ last.text += text;
22
+ else
23
+ runs.push(hatched ? { text, colour: cellColour, hatched } : { text, colour: cellColour });
24
+ }
25
+ return runs;
26
+ }
27
+ /** `cells` shared among `values` by size, the total exact (the largest remainders take the
28
+ * cells rounding leaves over), and a value of nothing getting none. */
29
+ export function apportion(values, cells) {
30
+ const total = values.reduce((sum, v) => sum + Math.max(0, v), 0);
31
+ if (total <= 0)
32
+ return values.map(() => 0);
33
+ const exact = values.map((v) => (Math.max(0, v) / total) * cells);
34
+ const counts = exact.map(Math.floor);
35
+ const order = exact.map((x, i) => [x - Math.floor(x), i]).sort((a, b) => b[0] - a[0]);
36
+ for (let k = 0, left = cells - counts.reduce((a, b) => a + b, 0); k < left; k++)
37
+ counts[order[k][1]]++;
38
+ return counts;
39
+ }
40
+ /** `cells` shared among spans as `spans` are, each at least one cell, the total exact. */
41
+ export const spread = (spans, cells) => apportion(spans, Math.max(0, cells - spans.length)).map((count) => count + 1);
@@ -0,0 +1,10 @@
1
+ import type { Attachment } from 'svelte/attachments';
2
+ export interface Fit {
3
+ cells: number;
4
+ ch: number;
5
+ width: number;
6
+ }
7
+ /** The width of a character in `node`'s font, in px. */
8
+ export declare function charWidth(node: Element): number;
9
+ /** {@attach fit((f) => (cells = f.cells))} on a block-level element. */
10
+ export declare function fit(onFit: (fit: Fit) => void): Attachment<HTMLElement>;
@@ -0,0 +1,35 @@
1
+ // How many characters of the grid's font fit across an element, for text bars that fill
2
+ // the width they are given. The character is measured in the element's own font, off
3
+ // screen, again as the element resizes and once the fonts have loaded.
4
+ let context = null;
5
+ /** The width of a character in `node`'s font, in px. */
6
+ export function charWidth(node) {
7
+ context ??= document.createElement('canvas').getContext('2d');
8
+ if (!context)
9
+ return 8;
10
+ const style = getComputedStyle(node);
11
+ context.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
12
+ return context.measureText('0000000000').width / 10 || 8;
13
+ }
14
+ /** {@attach fit((f) => (cells = f.cells))} on a block-level element. */
15
+ export function fit(onFit) {
16
+ return (node) => {
17
+ let last = '';
18
+ const measure = () => {
19
+ const ch = charWidth(node);
20
+ const style = getComputedStyle(node);
21
+ const width = node.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
22
+ const next = { cells: Math.max(0, Math.floor(width / ch)), ch, width };
23
+ const key = `${next.cells}:${ch}:${width}`;
24
+ if (key === last)
25
+ return;
26
+ last = key;
27
+ onFit(next);
28
+ };
29
+ measure();
30
+ const observer = new ResizeObserver(measure);
31
+ observer.observe(node);
32
+ void document.fonts?.ready.then(measure);
33
+ return () => observer.disconnect();
34
+ };
35
+ }
@@ -0,0 +1,28 @@
1
+ import type { Attachment } from 'svelte/attachments';
2
+ export type Axis = 'x' | 'y';
3
+ /** A press that moves less than this is still a tap. */
4
+ export declare const SLOP_PX = 10;
5
+ /** The axis a drag has committed to, or null while it is within the slop. */
6
+ export declare function lockAxis(dx: number, dy: number, slop?: number): Axis | null;
7
+ /** Past an end, a drag moves a third as far: the edge gives, but resists. */
8
+ export declare const resist: (offset: number, pastEnd: boolean) => number;
9
+ /** Whether a drag carries through: far enough (a `share` of `size`), or flicked fast
10
+ * enough (px per ms) in the direction it went. */
11
+ export declare function carries(offset: number, size: number, velocity: number, share?: number, speed?: number): boolean;
12
+ /** Whole steps a drag has passed, `stepPx` apart, towards zero. */
13
+ export declare const stepsAt: (offset: number, stepPx: number) => number;
14
+ export interface DragOptions {
15
+ axis: Axis;
16
+ /** Whether a drag may start now. */
17
+ enabled?: () => boolean;
18
+ /** Keeps the press from outer drags (a list item's swipe inside a swiping page). */
19
+ claim?: boolean;
20
+ onStart?: () => void;
21
+ /** The offset along the axis, in px, as it moves. */
22
+ onMove: (offset: number) => void;
23
+ /** Where it ended and how fast it was going (px per ms); a cancelled drag ends at 0. */
24
+ onEnd?: (offset: number, velocity: number) => void;
25
+ }
26
+ /** Follows a drag along one axis: {@attach drag({ axis: 'x', onMove, onEnd })}. The
27
+ * click a drag would end in is swallowed, so a swipe across a button does not press it. */
28
+ export declare function drag(options: DragOptions): Attachment<HTMLElement>;