@xerios/design-system 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 +21 -0
- package/README.md +403 -2
- package/dist/components/AnchorHeading.svelte +79 -0
- package/dist/components/AnchorHeading.svelte.d.ts +28 -0
- package/dist/components/Breadcrumbs.svelte +216 -0
- package/dist/components/Breadcrumbs.svelte.d.ts +37 -0
- package/dist/components/Button.svelte +178 -0
- package/dist/components/Button.svelte.d.ts +58 -0
- package/dist/components/Canvas.svelte +248 -0
- package/dist/components/Canvas.svelte.d.ts +91 -0
- package/dist/components/Collapsible.svelte +139 -0
- package/dist/components/Collapsible.svelte.d.ts +52 -0
- package/dist/components/CollapsibleAdvanced.svelte +174 -0
- package/dist/components/CollapsibleAdvanced.svelte.d.ts +43 -0
- package/dist/components/DashOutline.svelte +47 -0
- package/dist/components/DashOutline.svelte.d.ts +6 -0
- package/dist/components/Dialogs.svelte +123 -0
- package/dist/components/Dialogs.svelte.d.ts +6 -0
- package/dist/components/Drawer.svelte +231 -0
- package/dist/components/Drawer.svelte.d.ts +62 -0
- package/dist/components/ErrorMessage.svelte +140 -0
- package/dist/components/ErrorMessage.svelte.d.ts +41 -0
- package/dist/components/Icon.svelte +94 -0
- package/dist/components/Icon.svelte.d.ts +33 -0
- package/dist/components/InfoTip.svelte +183 -0
- package/dist/components/InfoTip.svelte.d.ts +28 -0
- package/dist/components/Md.svelte +28 -0
- package/dist/components/Md.svelte.d.ts +11 -0
- package/dist/components/Modal.svelte +91 -0
- package/dist/components/Modal.svelte.d.ts +41 -0
- package/dist/components/Notice.svelte +50 -0
- package/dist/components/Notice.svelte.d.ts +30 -0
- package/dist/components/Popover.svelte +212 -0
- package/dist/components/Popover.svelte.d.ts +70 -0
- package/dist/components/Shimmer.svelte +27 -0
- package/dist/components/Shimmer.svelte.d.ts +22 -0
- package/dist/components/Splitter.svelte +152 -0
- package/dist/components/Splitter.svelte.d.ts +41 -0
- package/dist/components/Table.svelte +448 -0
- package/dist/components/Table.svelte.d.ts +268 -0
- package/dist/components/Toast.svelte +273 -0
- package/dist/components/Toast.svelte.d.ts +31 -0
- package/dist/components/Tooltip.svelte +97 -0
- package/dist/components/Tooltip.svelte.d.ts +19 -0
- package/dist/components/WorkingBorder.svelte +105 -0
- package/dist/components/WorkingBorder.svelte.d.ts +26 -0
- package/dist/components/empty/Empty.svelte +55 -0
- package/dist/components/empty/Empty.svelte.d.ts +39 -0
- package/dist/components/empty/EmptyError.svelte +47 -0
- package/dist/components/empty/EmptyError.svelte.d.ts +28 -0
- package/dist/components/empty/index.d.ts +18 -0
- package/dist/components/empty/index.js +10 -0
- package/dist/components/filters/DateFilter.svelte +59 -0
- package/dist/components/filters/DateFilter.svelte.d.ts +23 -0
- package/dist/components/filters/FilterBar.svelte +342 -0
- package/dist/components/filters/FilterBar.svelte.d.ts +283 -0
- package/dist/components/filters/FilterChip.svelte +235 -0
- package/dist/components/filters/FilterChip.svelte.d.ts +68 -0
- package/dist/components/filters/OptionList.svelte +352 -0
- package/dist/components/filters/OptionList.svelte.d.ts +91 -0
- package/dist/components/filters/Panel.svelte +123 -0
- package/dist/components/filters/Panel.svelte.d.ts +25 -0
- package/dist/components/filters/index.d.ts +288 -0
- package/dist/components/filters/index.js +12 -0
- package/dist/components/icons.d.ts +54 -0
- package/dist/components/icons.js +58 -0
- package/dist/components/inputs/ButtonGroup.svelte +104 -0
- package/dist/components/inputs/ButtonGroup.svelte.d.ts +40 -0
- package/dist/components/inputs/Calendar.svelte +535 -0
- package/dist/components/inputs/Calendar.svelte.d.ts +45 -0
- package/dist/components/inputs/DateField.svelte +247 -0
- package/dist/components/inputs/DateField.svelte.d.ts +74 -0
- package/dist/components/inputs/DateInput.svelte +118 -0
- package/dist/components/inputs/DateInput.svelte.d.ts +43 -0
- package/dist/components/inputs/DatePicker.svelte +102 -0
- package/dist/components/inputs/DatePicker.svelte.d.ts +67 -0
- package/dist/components/inputs/DateRangePicker.svelte +208 -0
- package/dist/components/inputs/DateRangePicker.svelte.d.ts +76 -0
- package/dist/components/inputs/DateRangeSelect.svelte +548 -0
- package/dist/components/inputs/DateRangeSelect.svelte.d.ts +70 -0
- package/dist/components/inputs/FieldLabel.svelte +43 -0
- package/dist/components/inputs/FieldLabel.svelte.d.ts +28 -0
- package/dist/components/inputs/ListSearch.svelte +142 -0
- package/dist/components/inputs/ListSearch.svelte.d.ts +35 -0
- package/dist/components/inputs/RadioGroup.svelte +153 -0
- package/dist/components/inputs/RadioGroup.svelte.d.ts +49 -0
- package/dist/components/inputs/RangeShortcuts.svelte +90 -0
- package/dist/components/inputs/RangeShortcuts.svelte.d.ts +31 -0
- package/dist/components/inputs/RangeSlider.svelte +225 -0
- package/dist/components/inputs/RangeSlider.svelte.d.ts +37 -0
- package/dist/components/inputs/SearchField.svelte +24 -0
- package/dist/components/inputs/SearchField.svelte.d.ts +41 -0
- package/dist/components/inputs/Segmented.svelte +76 -0
- package/dist/components/inputs/Segmented.svelte.d.ts +43 -0
- package/dist/components/inputs/Select.svelte +552 -0
- package/dist/components/inputs/Select.svelte.d.ts +100 -0
- package/dist/components/inputs/Slider.svelte +177 -0
- package/dist/components/inputs/Slider.svelte.d.ts +33 -0
- package/dist/components/inputs/SliderTicks.svelte +62 -0
- package/dist/components/inputs/SliderTicks.svelte.d.ts +23 -0
- package/dist/components/inputs/Switch.svelte +120 -0
- package/dist/components/inputs/Switch.svelte.d.ts +31 -0
- package/dist/components/inputs/TagInput.svelte +296 -0
- package/dist/components/inputs/TagInput.svelte.d.ts +61 -0
- package/dist/components/inputs/TextArea.svelte +86 -0
- package/dist/components/inputs/TextArea.svelte.d.ts +56 -0
- package/dist/components/inputs/TextField.svelte +170 -0
- package/dist/components/inputs/TextField.svelte.d.ts +80 -0
- package/dist/components/menu/ContextMenu.svelte +25 -0
- package/dist/components/menu/ContextMenu.svelte.d.ts +26 -0
- package/dist/components/menu/MenuButton.svelte +46 -0
- package/dist/components/menu/MenuButton.svelte.d.ts +16 -0
- package/dist/components/menu/MenuList.svelte +319 -0
- package/dist/components/menu/MenuList.svelte.d.ts +30 -0
- package/dist/components/metadata/Metadata.svelte +38 -0
- package/dist/components/metadata/Metadata.svelte.d.ts +31 -0
- package/dist/components/metadata/MetadataRow.svelte +84 -0
- package/dist/components/metadata/MetadataRow.svelte.d.ts +26 -0
- package/dist/components/metadata/index.d.ts +8 -0
- package/dist/components/metadata/index.js +13 -0
- package/dist/components/side-menu/SideMenu.svelte +138 -0
- package/dist/components/side-menu/SideMenu.svelte.d.ts +25 -0
- package/dist/components/side-menu/SideMenuGroup.svelte +108 -0
- package/dist/components/side-menu/SideMenuGroup.svelte.d.ts +31 -0
- package/dist/components/side-menu/SideMenuItem.svelte +221 -0
- package/dist/components/side-menu/SideMenuItem.svelte.d.ts +46 -0
- package/dist/components/side-menu/context.d.ts +1 -0
- package/dist/components/side-menu/context.js +3 -0
- package/dist/components/side-menu/index.d.ts +62 -0
- package/dist/components/side-menu/index.js +15 -0
- package/dist/components/tiles/Tile.svelte +419 -0
- package/dist/components/tiles/Tile.svelte.d.ts +58 -0
- package/dist/components/tiles/TileGroup.svelte +135 -0
- package/dist/components/tiles/TileGroup.svelte.d.ts +45 -0
- package/dist/components/tiles/context.d.ts +35 -0
- package/dist/components/tiles/context.js +14 -0
- package/dist/components/tiles/index.d.ts +6 -0
- package/dist/components/tiles/index.js +13 -0
- package/dist/components/upload/FileCard.svelte +301 -0
- package/dist/components/upload/FileCard.svelte.d.ts +127 -0
- package/dist/components/upload/Thumb.svelte +274 -0
- package/dist/components/upload/Thumb.svelte.d.ts +101 -0
- package/dist/components/upload/UploadFile.svelte +123 -0
- package/dist/components/upload/UploadFile.svelte.d.ts +48 -0
- package/dist/components/upload/UploadFiles.svelte +177 -0
- package/dist/components/upload/UploadFiles.svelte.d.ts +50 -0
- package/dist/components/upload/UploadFolder.svelte +153 -0
- package/dist/components/upload/UploadFolder.svelte.d.ts +63 -0
- package/dist/components/upload/UploadImage.svelte +137 -0
- package/dist/components/upload/UploadImage.svelte.d.ts +52 -0
- package/dist/components/upload/UploadImages.svelte +172 -0
- package/dist/components/upload/UploadImages.svelte.d.ts +52 -0
- package/dist/components/upload/UploadZone.svelte +130 -0
- package/dist/components/upload/UploadZone.svelte.d.ts +41 -0
- package/dist/components/upload/common.d.ts +31 -0
- package/dist/components/upload/common.js +103 -0
- package/dist/components/upload/context.d.ts +18 -0
- package/dist/components/upload/context.js +10 -0
- package/dist/components/upload/index.d.ts +16 -0
- package/dist/components/upload/index.js +18 -0
- package/dist/css/atoms.css +892 -0
- package/dist/css/base.css +333 -0
- package/dist/css/effects.css +430 -0
- package/dist/css/index.css +10 -0
- package/dist/css/tokens.css +296 -0
- package/dist/fonts.d.ts +1 -0
- package/dist/fonts.js +7 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +77 -0
- package/dist/lib/announce.d.ts +8 -0
- package/dist/lib/announce.js +48 -0
- package/dist/lib/controls.d.ts +10 -0
- package/dist/lib/controls.js +42 -0
- package/dist/lib/dates.d.ts +104 -0
- package/dist/lib/dates.js +235 -0
- package/dist/lib/dialogs.svelte.d.ts +8 -0
- package/dist/lib/dialogs.svelte.js +45 -0
- package/dist/lib/dom.d.ts +34 -0
- package/dist/lib/dom.js +90 -0
- package/dist/lib/field-errors.svelte.d.ts +40 -0
- package/dist/lib/field-errors.svelte.js +89 -0
- package/dist/lib/files.d.ts +74 -0
- package/dist/lib/files.js +215 -0
- package/dist/lib/inline-md.d.ts +1 -0
- package/dist/lib/inline-md.js +36 -0
- package/dist/lib/invalid.d.ts +4 -0
- package/dist/lib/invalid.js +35 -0
- package/dist/lib/list-search.d.ts +9 -0
- package/dist/lib/list-search.js +27 -0
- package/dist/lib/menu.svelte.d.ts +39 -0
- package/dist/lib/menu.svelte.js +98 -0
- package/dist/lib/morph.svelte.d.ts +17 -0
- package/dist/lib/morph.svelte.js +46 -0
- package/dist/lib/motion.d.ts +115 -0
- package/dist/lib/motion.js +174 -0
- package/dist/lib/observe.d.ts +36 -0
- package/dist/lib/observe.js +142 -0
- package/dist/lib/reveal.d.ts +7 -0
- package/dist/lib/reveal.js +28 -0
- package/dist/lib/roving.d.ts +16 -0
- package/dist/lib/roving.js +35 -0
- package/dist/lib/runs.d.ts +18 -0
- package/dist/lib/runs.js +25 -0
- package/dist/lib/scroll-fade.d.ts +4 -0
- package/dist/lib/scroll-fade.js +71 -0
- package/dist/lib/spotlight.d.ts +4 -0
- package/dist/lib/spotlight.js +109 -0
- package/dist/lib/ticks.d.ts +12 -0
- package/dist/lib/ticks.js +24 -0
- package/dist/lib/tooltip.d.ts +4 -0
- package/dist/lib/tooltip.js +110 -0
- package/dist/lib/validity.d.ts +16 -0
- package/dist/lib/validity.js +36 -0
- package/package.json +69 -3
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* A canvas that fills its box and draws with a callback: the backing store follows the box's size at the screen's
|
|
4
|
+
* pixel density, and `draw` paints in CSS pixels. It animates on requestAnimationFrame by default, or draws on demand.
|
|
5
|
+
* For charts, sparklines, generative backgrounds and small visualisations; not a scene graph.
|
|
6
|
+
*
|
|
7
|
+
* <Canvas class="wave" draw={(ctx, { width, height, time }) => {
|
|
8
|
+
* ctx.beginPath()
|
|
9
|
+
* for (let x = 0; x <= width; x += 4) ctx.lineTo(x, height / 2 + Math.sin(x / 40 + time / 400) * height / 4)
|
|
10
|
+
* ctx.stroke()
|
|
11
|
+
* }} />
|
|
12
|
+
*
|
|
13
|
+
* <!-- Static: redrawn when its size or any $state the draw reads changes, and by redraw(). -->
|
|
14
|
+
* <Canvas animate={false} label="Requests per minute" draw={(ctx, f) => plot(ctx, f, points)} />
|
|
15
|
+
*
|
|
16
|
+
* The box is the component's own element: a block as wide as its container that takes the container's height when that
|
|
17
|
+
* is set, and is 2:1 otherwise. Size it with a class (`height`, `aspect-ratio`). Drawing stops while the box is out of
|
|
18
|
+
* view, the page is hidden, or it has no size, and starts again when it returns.
|
|
19
|
+
*
|
|
20
|
+
* Props:
|
|
21
|
+
* draw(ctx, frame) Paints one frame. `frame` holds `width` and `height` (CSS px), `pixelRatio` (device pixels per
|
|
22
|
+
* CSS px), `time` (ms of drawing so far, paused time left out), `delta` (ms since the last frame,
|
|
23
|
+
* 0 on the first and on static draws, capped at 100 so a stall doesn't make a simulation leap),
|
|
24
|
+
* `frame` (a count from 0) and `canvas`. For a 2d context the transform is reset to CSS pixels and
|
|
25
|
+
* the canvas cleared before each call; for WebGL the viewport is set to the whole canvas.
|
|
26
|
+
* animate Redraw every frame (default true). False draws once, then again when the size changes, when any
|
|
27
|
+
* $state the draw reads changes, or on redraw(). Reduced motion turns animation into that, drawn at
|
|
28
|
+
* the end of `duration` when one is set.
|
|
29
|
+
* running False holds the current frame (default true).
|
|
30
|
+
* duration Stop animating after this many ms (default Infinity), for an intro that settles. The clock
|
|
31
|
+
* starts again when drawing resumes: the box comes back into view, is resized, or running turns on.
|
|
32
|
+
* fps Cap on frames per second (default: the display's rate).
|
|
33
|
+
* pixelRatio Device pixels per CSS pixel for the backing store (default: the screen's, kept exact as it
|
|
34
|
+
* changes). 1 is cheapest; a cap such as Math.min(2, devicePixelRatio) suits heavy fills.
|
|
35
|
+
* type '2d' (default), 'webgl' or 'webgl2'. A new canvas is made when it changes.
|
|
36
|
+
* options Context attributes, such as { alpha: false }; read when the context is made.
|
|
37
|
+
* clear Clear a 2d canvas before each frame (default true); false paints over the last one, for trails.
|
|
38
|
+
* label What the drawing shows, for screen readers (role="img"). Without it the canvas is decorative and
|
|
39
|
+
* hidden from them. Children are the canvas's fallback content, for a longer text alternative.
|
|
40
|
+
* canvas, width, height Bindable, read only: the element and its size in CSS px.
|
|
41
|
+
*
|
|
42
|
+
* Methods, through bind:this: redraw() paints one frame on the next animation frame (for data that isn't $state);
|
|
43
|
+
* restart() sets `time` back to 0 and runs the `duration` clock again.
|
|
44
|
+
*
|
|
45
|
+
* Keyboard: none; it isn't interactive. A consumer that makes it so adds the tabindex, handlers and label.
|
|
46
|
+
*/
|
|
47
|
+
import { untrack } from 'svelte'
|
|
48
|
+
import { prefersReducedMotion } from 'svelte/motion'
|
|
49
|
+
import { devicePixelRatio } from 'svelte/reactivity/window'
|
|
50
|
+
import { observeSize, observeVisibility } from '../lib/observe.js'
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @typedef {object} Frame
|
|
54
|
+
* @property {number} width
|
|
55
|
+
* @property {number} height
|
|
56
|
+
* @property {number} pixelRatio
|
|
57
|
+
* @property {number} time
|
|
58
|
+
* @property {number} delta
|
|
59
|
+
* @property {number} frame
|
|
60
|
+
* @property {HTMLCanvasElement} canvas
|
|
61
|
+
*/
|
|
62
|
+
/** @typedef {CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext} Context */
|
|
63
|
+
/**
|
|
64
|
+
* @typedef {object} Props
|
|
65
|
+
* @property {(ctx: any, frame: Frame) => void} draw ctx is a CanvasRenderingContext2D, or a WebGL(2)RenderingContext by `type`
|
|
66
|
+
* @property {boolean} [animate]
|
|
67
|
+
* @property {boolean} [running]
|
|
68
|
+
* @property {number} [duration]
|
|
69
|
+
* @property {number} [fps]
|
|
70
|
+
* @property {number} [pixelRatio]
|
|
71
|
+
* @property {'2d' | 'webgl' | 'webgl2'} [type]
|
|
72
|
+
* @property {CanvasRenderingContext2DSettings | WebGLContextAttributes} [options]
|
|
73
|
+
* @property {boolean} [clear]
|
|
74
|
+
* @property {string} [label]
|
|
75
|
+
* @property {HTMLCanvasElement} [canvas]
|
|
76
|
+
* @property {number} [width]
|
|
77
|
+
* @property {number} [height]
|
|
78
|
+
* @property {import('svelte').Snippet} [children]
|
|
79
|
+
*/
|
|
80
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
|
|
81
|
+
let {
|
|
82
|
+
draw,
|
|
83
|
+
animate = true,
|
|
84
|
+
running = true,
|
|
85
|
+
duration = Infinity,
|
|
86
|
+
fps,
|
|
87
|
+
pixelRatio,
|
|
88
|
+
type = '2d',
|
|
89
|
+
options,
|
|
90
|
+
clear = true,
|
|
91
|
+
label,
|
|
92
|
+
canvas = $bindable(),
|
|
93
|
+
width = $bindable(0),
|
|
94
|
+
height = $bindable(0),
|
|
95
|
+
class: className,
|
|
96
|
+
children,
|
|
97
|
+
...rest
|
|
98
|
+
} = $props()
|
|
99
|
+
|
|
100
|
+
/** @type {Context | null} */
|
|
101
|
+
let ctx = $state.raw(null)
|
|
102
|
+
/** The box's size in device pixels, when the browser reports it (not Safari). */
|
|
103
|
+
let deviceSize = $state.raw(/** @type {[number, number] | null} */ (null))
|
|
104
|
+
let inView = $state(false)
|
|
105
|
+
let pageVisible = $state(true)
|
|
106
|
+
|
|
107
|
+
const active = $derived(!!ctx && running && inView && pageVisible && width > 0 && height > 0)
|
|
108
|
+
/** Whether `duration` has run out. Resets, starting the clock again, when drawing resumes or the box is resized. */
|
|
109
|
+
let settled = $derived.by(() => {
|
|
110
|
+
void [width, height, active]
|
|
111
|
+
return false
|
|
112
|
+
})
|
|
113
|
+
const looping = $derived(active && animate && !settled && !prefersReducedMotion.current)
|
|
114
|
+
|
|
115
|
+
let time = 0
|
|
116
|
+
let since = 0
|
|
117
|
+
let count = 0
|
|
118
|
+
let last = -1
|
|
119
|
+
let request = 0
|
|
120
|
+
let pending = 0
|
|
121
|
+
|
|
122
|
+
/** Sizes the backing store to the box; returns its device pixels per CSS pixel, across and down. @param {HTMLCanvasElement} el */
|
|
123
|
+
function fit(el) {
|
|
124
|
+
const ratio = pixelRatio ?? devicePixelRatio.current ?? 1
|
|
125
|
+
const [w, h] =
|
|
126
|
+
pixelRatio == null && deviceSize ? deviceSize : [Math.max(1, Math.round(width * ratio)), Math.max(1, Math.round(height * ratio))]
|
|
127
|
+
if (el.width !== w || el.height !== h) {
|
|
128
|
+
el.width = w
|
|
129
|
+
el.height = h
|
|
130
|
+
}
|
|
131
|
+
return [w / width, h / height]
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** @param {number} delta */
|
|
135
|
+
function paint(delta) {
|
|
136
|
+
if (!ctx || !canvas || width <= 0 || height <= 0) return
|
|
137
|
+
const [sx, sy] = fit(canvas)
|
|
138
|
+
if (ctx instanceof CanvasRenderingContext2D) {
|
|
139
|
+
ctx.setTransform(sx, 0, 0, sy, 0, 0)
|
|
140
|
+
if (clear) ctx.clearRect(0, 0, width, height)
|
|
141
|
+
} else {
|
|
142
|
+
ctx.viewport(0, 0, canvas.width, canvas.height)
|
|
143
|
+
}
|
|
144
|
+
draw(ctx, { width, height, pixelRatio: sx, time, delta, frame: count++, canvas })
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** @param {number} now */
|
|
148
|
+
function tick(now) {
|
|
149
|
+
request = requestAnimationFrame(tick)
|
|
150
|
+
const delta = last < 0 ? 0 : now - last
|
|
151
|
+
// Skip frames that come early for the cap, with a millisecond's grace for the display's jitter.
|
|
152
|
+
if (fps && last >= 0 && delta < 1000 / fps - 1) return
|
|
153
|
+
last = now
|
|
154
|
+
const step = Math.min(delta, 100)
|
|
155
|
+
time += step
|
|
156
|
+
since += step
|
|
157
|
+
paint(step)
|
|
158
|
+
if (since >= duration) settled = true
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// The loop: runs while looping, and restarts its clock each time it resumes.
|
|
162
|
+
$effect(() => {
|
|
163
|
+
if (!looping) return
|
|
164
|
+
last = -1
|
|
165
|
+
since = 0
|
|
166
|
+
request = requestAnimationFrame(tick)
|
|
167
|
+
return () => cancelAnimationFrame(request)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
// A still frame when not looping: tracked, so a resize or a change to any $state the draw reads paints again.
|
|
171
|
+
// Under reduced motion, an animation with a duration shows how it ends rather than how it starts.
|
|
172
|
+
$effect(() => {
|
|
173
|
+
if (!active || looping) return
|
|
174
|
+
if (animate && prefersReducedMotion.current && Number.isFinite(duration)) time = duration
|
|
175
|
+
paint(0)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
export function redraw() {
|
|
179
|
+
if (looping || pending) return
|
|
180
|
+
pending = requestAnimationFrame(() => {
|
|
181
|
+
pending = 0
|
|
182
|
+
if (active) paint(0)
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function restart() {
|
|
187
|
+
time = 0
|
|
188
|
+
since = 0
|
|
189
|
+
settled = false
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Makes the context and watches the box's size and visibility. @param {HTMLCanvasElement} el */
|
|
193
|
+
function setup(el) {
|
|
194
|
+
const own = untrack(() => el.getContext(type, options))
|
|
195
|
+
canvas = el
|
|
196
|
+
ctx = own
|
|
197
|
+
pageVisible = !document.hidden
|
|
198
|
+
|
|
199
|
+
const stopSize = observeSize(
|
|
200
|
+
el,
|
|
201
|
+
(entry) => {
|
|
202
|
+
width = entry.contentRect.width
|
|
203
|
+
height = entry.contentRect.height
|
|
204
|
+
const device = entry.devicePixelContentBoxSize?.[0]
|
|
205
|
+
deviceSize = device ? [device.inlineSize, device.blockSize] : null
|
|
206
|
+
},
|
|
207
|
+
{ box: 'device-pixel-content-box' },
|
|
208
|
+
)
|
|
209
|
+
const stopView = observeVisibility(el, (entry) => (inView = entry.isIntersecting))
|
|
210
|
+
|
|
211
|
+
return () => {
|
|
212
|
+
stopSize()
|
|
213
|
+
stopView()
|
|
214
|
+
cancelAnimationFrame(pending)
|
|
215
|
+
pending = 0
|
|
216
|
+
if (ctx === own) ctx = null
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
</script>
|
|
220
|
+
|
|
221
|
+
<svelte:document onvisibilitychange={() => (pageVisible = !document.hidden)} />
|
|
222
|
+
|
|
223
|
+
<div class={['canvas', className]} {...rest}>
|
|
224
|
+
{#key type}
|
|
225
|
+
<canvas {@attach setup} role={label ? 'img' : undefined} aria-label={label} aria-hidden={label ? undefined : 'true'}>
|
|
226
|
+
{@render children?.()}
|
|
227
|
+
</canvas>
|
|
228
|
+
{/key}
|
|
229
|
+
</div>
|
|
230
|
+
|
|
231
|
+
<style>
|
|
232
|
+
/* The canvas is taken out of flow, so its backing store's size never feeds back into the box's. */
|
|
233
|
+
.canvas {
|
|
234
|
+
position: relative;
|
|
235
|
+
display: block;
|
|
236
|
+
width: 100%;
|
|
237
|
+
height: 100%;
|
|
238
|
+
aspect-ratio: 2 / 1;
|
|
239
|
+
min-width: 0;
|
|
240
|
+
}
|
|
241
|
+
canvas {
|
|
242
|
+
position: absolute;
|
|
243
|
+
inset: 0;
|
|
244
|
+
display: block;
|
|
245
|
+
width: 100%;
|
|
246
|
+
height: 100%;
|
|
247
|
+
}
|
|
248
|
+
</style>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export default Canvas;
|
|
2
|
+
type Canvas = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLAttributes<HTMLDivElement>, keyof Props>>): void;
|
|
5
|
+
} & {
|
|
6
|
+
redraw: () => void;
|
|
7
|
+
restart: () => void;
|
|
8
|
+
};
|
|
9
|
+
declare const Canvas: import("svelte").Component<{
|
|
10
|
+
/**
|
|
11
|
+
* ctx is a CanvasRenderingContext2D, or a WebGL(2)RenderingContext by `type`
|
|
12
|
+
*/
|
|
13
|
+
draw: (ctx: any, frame: {
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
pixelRatio: number;
|
|
17
|
+
time: number;
|
|
18
|
+
delta: number;
|
|
19
|
+
frame: number;
|
|
20
|
+
canvas: HTMLCanvasElement;
|
|
21
|
+
}) => void;
|
|
22
|
+
animate?: boolean | undefined;
|
|
23
|
+
running?: boolean | undefined;
|
|
24
|
+
duration?: number | undefined;
|
|
25
|
+
fps?: number | undefined;
|
|
26
|
+
pixelRatio?: number | undefined;
|
|
27
|
+
type?: "2d" | "webgl" | "webgl2" | undefined;
|
|
28
|
+
options?: CanvasRenderingContext2DSettings | WebGLContextAttributes | undefined;
|
|
29
|
+
clear?: boolean | undefined;
|
|
30
|
+
label?: string | undefined;
|
|
31
|
+
canvas?: HTMLCanvasElement | undefined;
|
|
32
|
+
width?: number | undefined;
|
|
33
|
+
height?: number | undefined;
|
|
34
|
+
children?: import("svelte").Snippet<[]> | undefined;
|
|
35
|
+
} & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, keyof {
|
|
36
|
+
/**
|
|
37
|
+
* ctx is a CanvasRenderingContext2D, or a WebGL(2)RenderingContext by `type`
|
|
38
|
+
*/
|
|
39
|
+
draw: (ctx: any, frame: {
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
pixelRatio: number;
|
|
43
|
+
time: number;
|
|
44
|
+
delta: number;
|
|
45
|
+
frame: number;
|
|
46
|
+
canvas: HTMLCanvasElement;
|
|
47
|
+
}) => void;
|
|
48
|
+
animate?: boolean | undefined;
|
|
49
|
+
running?: boolean | undefined;
|
|
50
|
+
duration?: number | undefined;
|
|
51
|
+
fps?: number | undefined;
|
|
52
|
+
pixelRatio?: number | undefined;
|
|
53
|
+
type?: "2d" | "webgl" | "webgl2" | undefined;
|
|
54
|
+
options?: CanvasRenderingContext2DSettings | WebGLContextAttributes | undefined;
|
|
55
|
+
clear?: boolean | undefined;
|
|
56
|
+
label?: string | undefined;
|
|
57
|
+
canvas?: HTMLCanvasElement | undefined;
|
|
58
|
+
width?: number | undefined;
|
|
59
|
+
height?: number | undefined;
|
|
60
|
+
children?: import("svelte").Snippet<[]> | undefined;
|
|
61
|
+
}>, {
|
|
62
|
+
redraw: () => void;
|
|
63
|
+
restart: () => void;
|
|
64
|
+
}, "canvas" | "width" | "height">;
|
|
65
|
+
type Props = {
|
|
66
|
+
/**
|
|
67
|
+
* ctx is a CanvasRenderingContext2D, or a WebGL(2)RenderingContext by `type`
|
|
68
|
+
*/
|
|
69
|
+
draw: (ctx: any, frame: {
|
|
70
|
+
width: number;
|
|
71
|
+
height: number;
|
|
72
|
+
pixelRatio: number;
|
|
73
|
+
time: number;
|
|
74
|
+
delta: number;
|
|
75
|
+
frame: number;
|
|
76
|
+
canvas: HTMLCanvasElement;
|
|
77
|
+
}) => void;
|
|
78
|
+
animate?: boolean | undefined;
|
|
79
|
+
running?: boolean | undefined;
|
|
80
|
+
duration?: number | undefined;
|
|
81
|
+
fps?: number | undefined;
|
|
82
|
+
pixelRatio?: number | undefined;
|
|
83
|
+
type?: "2d" | "webgl" | "webgl2" | undefined;
|
|
84
|
+
options?: CanvasRenderingContext2DSettings | WebGLContextAttributes | undefined;
|
|
85
|
+
clear?: boolean | undefined;
|
|
86
|
+
label?: string | undefined;
|
|
87
|
+
canvas?: HTMLCanvasElement | undefined;
|
|
88
|
+
width?: number | undefined;
|
|
89
|
+
height?: number | undefined;
|
|
90
|
+
children?: import("svelte").Snippet<[]> | undefined;
|
|
91
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* Collapsible section with a full-width header button, for stacking inside a panel.
|
|
4
|
+
*
|
|
5
|
+
* <Collapsible title="Requirements" count={8}>…</Collapsible> opens and closes on its own
|
|
6
|
+
* <Collapsible title="…" bind:open>…</Collapsible> the parent holds the state
|
|
7
|
+
* <Collapsible title="…" open={saved} ontoggle={(next) => save(next)}>… …or stores it somewhere (preferences)
|
|
8
|
+
*
|
|
9
|
+
* `count` shows a number pill after the title; `meta` is an optional snippet at the right of the header.
|
|
10
|
+
* `info`: what the section is for, behind an ⓘ right after the title (see InfoTip).
|
|
11
|
+
* `id` names the body for aria-controls (one is made up if you leave it out).
|
|
12
|
+
* Sections run edge to edge: set --bleed on the container to its side padding.
|
|
13
|
+
*/
|
|
14
|
+
import Icon from './Icon.svelte'
|
|
15
|
+
import InfoTip from './InfoTip.svelte'
|
|
16
|
+
import { slide } from '../lib/motion.js'
|
|
17
|
+
|
|
18
|
+
const uid = $props.id()
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {object} Props
|
|
21
|
+
* @property {string} [id] the body's id (generated when not given)
|
|
22
|
+
* @property {string} title
|
|
23
|
+
* @property {boolean} [open] bindable
|
|
24
|
+
* @property {(open: boolean) => void} [ontoggle]
|
|
25
|
+
* @property {number | string | null} [count]
|
|
26
|
+
* @property {import('svelte').Snippet} [meta]
|
|
27
|
+
* @property {string} [info]
|
|
28
|
+
* @property {import('svelte').Snippet} children
|
|
29
|
+
*/
|
|
30
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLElement>, keyof Props>} */
|
|
31
|
+
let { id = 'c-' + uid, title, open = $bindable(true), ontoggle, count = null, meta, info = '', class: className, children, ...rest } = $props()
|
|
32
|
+
const toggle = () => {
|
|
33
|
+
open = !open
|
|
34
|
+
ontoggle?.(open)
|
|
35
|
+
}
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<section class={['collapsible', className]} class:open {...rest}>
|
|
39
|
+
<!-- The toggle is an empty button stretched over the whole header and named by the parts it covers, so the ⓘ can sit
|
|
40
|
+
right after the title without being a button inside a button. -->
|
|
41
|
+
<h3>
|
|
42
|
+
<button
|
|
43
|
+
type="button"
|
|
44
|
+
class="hit"
|
|
45
|
+
aria-expanded={open}
|
|
46
|
+
aria-controls={id}
|
|
47
|
+
aria-labelledby={[`${id}-title`, count != null && `${id}-count`, meta && `${id}-meta`].filter(Boolean).join(' ')}
|
|
48
|
+
onclick={toggle}
|
|
49
|
+
></button>
|
|
50
|
+
<span class="chev" aria-hidden="true"><Icon name="caretRight" size="sm" /></span>
|
|
51
|
+
<span class="title" id="{id}-title" aria-hidden="true">{title}</span>
|
|
52
|
+
{#if info}<InfoTip lines={[{ text: info }]} label="About {title}" />{/if}
|
|
53
|
+
{#if count != null}<span class="count" id="{id}-count" aria-hidden="true">{count}</span>{/if}
|
|
54
|
+
{#if meta}<span class="meta" id="{id}-meta" aria-hidden="true">{@render meta()}</span>{/if}
|
|
55
|
+
</h3>
|
|
56
|
+
{#if open}
|
|
57
|
+
<div {id} class="body" transition:slide>
|
|
58
|
+
<div class="inner">{@render children()}</div>
|
|
59
|
+
</div>
|
|
60
|
+
{/if}
|
|
61
|
+
</section>
|
|
62
|
+
|
|
63
|
+
<style>
|
|
64
|
+
/* Sections run edge to edge across the panel they're in: the container sets --bleed to its side padding, the section
|
|
65
|
+
extends into it with negative margins and pads back by the same amount, so the hairlines and the header's hover fill
|
|
66
|
+
reach both edges while the chevron, title and content stay where they were. */
|
|
67
|
+
.collapsible {
|
|
68
|
+
--pad: calc(var(--bleed, 0px) + var(--space-1));
|
|
69
|
+
margin-inline: calc(-1 * var(--bleed, 0px));
|
|
70
|
+
border-top: 1px solid var(--line);
|
|
71
|
+
}
|
|
72
|
+
.collapsible:last-child {
|
|
73
|
+
border-bottom: 1px solid var(--line);
|
|
74
|
+
}
|
|
75
|
+
/* The header row draws everything; the stretched .hit button on top of it takes the clicks, hover and focus ring.
|
|
76
|
+
The ⓘ comes after .hit and is positioned, so it paints above it and keeps its own pointer. */
|
|
77
|
+
h3 {
|
|
78
|
+
position: relative;
|
|
79
|
+
display: flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
gap: var(--space-2);
|
|
82
|
+
min-height: 32px;
|
|
83
|
+
margin: 0;
|
|
84
|
+
padding: 0 var(--pad);
|
|
85
|
+
color: var(--fg-2);
|
|
86
|
+
font: var(--w-medium) 12px var(--font-body);
|
|
87
|
+
transition:
|
|
88
|
+
color var(--dur-fast) var(--ease-out),
|
|
89
|
+
background-color var(--dur-fast) var(--ease-out);
|
|
90
|
+
}
|
|
91
|
+
h3:has(> .hit:hover) {
|
|
92
|
+
background: var(--control-2);
|
|
93
|
+
}
|
|
94
|
+
.hit {
|
|
95
|
+
position: absolute;
|
|
96
|
+
inset: 0;
|
|
97
|
+
padding: 0;
|
|
98
|
+
background: none;
|
|
99
|
+
border: 0;
|
|
100
|
+
border-radius: 0;
|
|
101
|
+
}
|
|
102
|
+
.hit:focus-visible {
|
|
103
|
+
outline-offset: -2px;
|
|
104
|
+
border-radius: 0;
|
|
105
|
+
}
|
|
106
|
+
/* Tucked against the title (the row's gap is for the other parts); its 24px box overlaps the row's padding. */
|
|
107
|
+
h3 > :global(.info) {
|
|
108
|
+
position: relative;
|
|
109
|
+
margin: -4px 0 -4px calc(2px - var(--space-2));
|
|
110
|
+
}
|
|
111
|
+
.chev {
|
|
112
|
+
display: inline-flex;
|
|
113
|
+
rotate: 0deg;
|
|
114
|
+
transition: rotate var(--dur) var(--ease-out);
|
|
115
|
+
}
|
|
116
|
+
.open .chev {
|
|
117
|
+
rotate: 90deg;
|
|
118
|
+
}
|
|
119
|
+
.title {
|
|
120
|
+
color: var(--fg);
|
|
121
|
+
}
|
|
122
|
+
.count {
|
|
123
|
+
font: var(--w-medium) 11px var(--font-data);
|
|
124
|
+
font-variant-numeric: tabular-nums;
|
|
125
|
+
color: var(--muted);
|
|
126
|
+
background: var(--fill-3);
|
|
127
|
+
border-radius: var(--r-pill);
|
|
128
|
+
padding: 1px 7px;
|
|
129
|
+
}
|
|
130
|
+
.meta {
|
|
131
|
+
margin-left: auto;
|
|
132
|
+
font: 400 12px var(--font-body);
|
|
133
|
+
}
|
|
134
|
+
.inner {
|
|
135
|
+
padding: var(--space-1) var(--pad) var(--space-4);
|
|
136
|
+
display: grid;
|
|
137
|
+
gap: var(--space-3);
|
|
138
|
+
}
|
|
139
|
+
</style>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export default Collapsible;
|
|
2
|
+
type Collapsible = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLAttributes<HTMLElement>, keyof Props>>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Collapsible: import("svelte").Component<{
|
|
7
|
+
/**
|
|
8
|
+
* the body's id (generated when not given)
|
|
9
|
+
*/
|
|
10
|
+
id?: string | undefined;
|
|
11
|
+
title: string;
|
|
12
|
+
/**
|
|
13
|
+
* bindable
|
|
14
|
+
*/
|
|
15
|
+
open?: boolean | undefined;
|
|
16
|
+
ontoggle?: ((open: boolean) => void) | undefined;
|
|
17
|
+
count?: string | number | null | undefined;
|
|
18
|
+
meta?: import("svelte").Snippet<[]> | undefined;
|
|
19
|
+
info?: string | undefined;
|
|
20
|
+
children: import("svelte").Snippet;
|
|
21
|
+
} & Omit<import("svelte/elements").HTMLAttributes<HTMLElement>, keyof {
|
|
22
|
+
/**
|
|
23
|
+
* the body's id (generated when not given)
|
|
24
|
+
*/
|
|
25
|
+
id?: string | undefined;
|
|
26
|
+
title: string;
|
|
27
|
+
/**
|
|
28
|
+
* bindable
|
|
29
|
+
*/
|
|
30
|
+
open?: boolean | undefined;
|
|
31
|
+
ontoggle?: ((open: boolean) => void) | undefined;
|
|
32
|
+
count?: string | number | null | undefined;
|
|
33
|
+
meta?: import("svelte").Snippet<[]> | undefined;
|
|
34
|
+
info?: string | undefined;
|
|
35
|
+
children: import("svelte").Snippet;
|
|
36
|
+
}>, {}, "open">;
|
|
37
|
+
type Props = {
|
|
38
|
+
/**
|
|
39
|
+
* the body's id (generated when not given)
|
|
40
|
+
*/
|
|
41
|
+
id?: string | undefined;
|
|
42
|
+
title: string;
|
|
43
|
+
/**
|
|
44
|
+
* bindable
|
|
45
|
+
*/
|
|
46
|
+
open?: boolean | undefined;
|
|
47
|
+
ontoggle?: ((open: boolean) => void) | undefined;
|
|
48
|
+
count?: string | number | null | undefined;
|
|
49
|
+
meta?: import("svelte").Snippet<[]> | undefined;
|
|
50
|
+
info?: string | undefined;
|
|
51
|
+
children: import("svelte").Snippet;
|
|
52
|
+
};
|