@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,71 @@
|
|
|
1
|
+
// Edge fades for scroll areas: a mask softens the top edge while there's content above and the bottom edge while
|
|
2
|
+
// there's more below, each easing away at its end. Hovering or keyboard-focusing inside clears them.
|
|
3
|
+
// Styles live in css/effects.css ([data-scroll-fade]). A sticky header's band, reserved with scroll-padding-top, stays solid.
|
|
4
|
+
//
|
|
5
|
+
// <div class="list" {@attach scrollFade()}>…</div>
|
|
6
|
+
// <div class="list" {@attach scrollFade({ size: 64 })}>…</div>
|
|
7
|
+
//
|
|
8
|
+
// The mask fades everything the element paints, its own background and border included, so put it on a scroller
|
|
9
|
+
// without either (wrap the scroller in the card instead). Scrollbars are kept out of the mask.
|
|
10
|
+
|
|
11
|
+
import { observeSize } from './observe.js';
|
|
12
|
+
|
|
13
|
+
/** @param {{ size?: number }} [opts] fade height in px (default: --scroll-fade, 48px) */
|
|
14
|
+
export function scrollFade({ size } = {}) {
|
|
15
|
+
return (node) => {
|
|
16
|
+
if (size != null) node.style.setProperty('--scroll-fade', `${size}px`);
|
|
17
|
+
|
|
18
|
+
let frame = 0;
|
|
19
|
+
const update = () => {
|
|
20
|
+
frame = 0;
|
|
21
|
+
const { scrollTop, scrollHeight, clientHeight } = node;
|
|
22
|
+
const cs = getComputedStyle(node);
|
|
23
|
+
// Only while it actually scrolls: some areas hand scrolling to a child or the page at certain layouts.
|
|
24
|
+
if (scrollHeight - clientHeight < 1 || !/auto|scroll/.test(cs.overflowY)) {
|
|
25
|
+
node.removeAttribute('data-scroll-fade');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Scrollbars sit inside the border; measure them so the mask can leave them solid.
|
|
29
|
+
const bx = parseFloat(cs.borderLeftWidth) + parseFloat(cs.borderRightWidth);
|
|
30
|
+
const by = parseFloat(cs.borderTopWidth) + parseFloat(cs.borderBottomWidth);
|
|
31
|
+
node.style.setProperty('--scroll-fade-sb-w', `${Math.max(0, node.offsetWidth - node.clientWidth - bx)}px`);
|
|
32
|
+
node.style.setProperty('--scroll-fade-sb-h', `${Math.max(0, node.offsetHeight - node.clientHeight - by)}px`);
|
|
33
|
+
node.style.setProperty('--scroll-fade-inset', `${parseFloat(cs.scrollPaddingTop) || 0}px`);
|
|
34
|
+
// Fractional scroll offsets (zoom, high-DPI) can leave a pixel short of either end.
|
|
35
|
+
const edges = [];
|
|
36
|
+
if (scrollTop > 1) edges.push('above');
|
|
37
|
+
if (scrollHeight - clientHeight - scrollTop > 1) edges.push('below');
|
|
38
|
+
node.dataset.scrollFade = edges.join(' ');
|
|
39
|
+
};
|
|
40
|
+
const schedule = () => { frame ||= requestAnimationFrame(update); };
|
|
41
|
+
|
|
42
|
+
// The content can grow without the box resizing, so watch the children too (and the ones added later).
|
|
43
|
+
/** @type {(() => void)[]} */
|
|
44
|
+
let sized = [];
|
|
45
|
+
const unwatch = () => {
|
|
46
|
+
for (const stop of sized) stop();
|
|
47
|
+
sized = [];
|
|
48
|
+
};
|
|
49
|
+
const watch = () => {
|
|
50
|
+
unwatch();
|
|
51
|
+
sized = [node, ...node.children].map((el) => observeSize(el, schedule));
|
|
52
|
+
schedule();
|
|
53
|
+
};
|
|
54
|
+
const mutations = new MutationObserver(watch);
|
|
55
|
+
mutations.observe(node, { childList: true });
|
|
56
|
+
node.addEventListener('scroll', schedule, { passive: true });
|
|
57
|
+
watch();
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
cancelAnimationFrame(frame);
|
|
61
|
+
unwatch();
|
|
62
|
+
mutations.disconnect();
|
|
63
|
+
node.removeEventListener('scroll', schedule);
|
|
64
|
+
node.removeAttribute('data-scroll-fade');
|
|
65
|
+
node.style.removeProperty('--scroll-fade');
|
|
66
|
+
node.style.removeProperty('--scroll-fade-sb-w');
|
|
67
|
+
node.style.removeProperty('--scroll-fade-sb-h');
|
|
68
|
+
node.style.removeProperty('--scroll-fade-inset');
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Spotlight: point at one element on screen (a setting someone was sent to) with a brief accent flash.
|
|
2
|
+
// Styles live in css/effects.css ([data-spotlight]). Nothing is needed on the components involved; call it right after
|
|
3
|
+
// opening whatever holds the element:
|
|
4
|
+
//
|
|
5
|
+
// openSettings();
|
|
6
|
+
// spotlight('settings-access');
|
|
7
|
+
//
|
|
8
|
+
// Waits (up to `timeout` ms) for the element with that id to be in the page, or for a collapsed toggle that names it in
|
|
9
|
+
// aria-controls (Collapsible's header, which drops its body while closed), so whatever holds it may still be opening or
|
|
10
|
+
// loading. It then reveals the element: the toggle is clicked, so the section opens the way a click would, state
|
|
11
|
+
// callbacks included, and any closed <details> around it (CollapsibleAdvanced, or a plain one) is opened. Once any
|
|
12
|
+
// opening animation has finished it scrolls the element into view and flashes it. Under reduced motion the flash is a
|
|
13
|
+
// static tint for the same time. Resolves to the element, or null if it never turned up.
|
|
14
|
+
|
|
15
|
+
import { tick } from 'svelte'
|
|
16
|
+
|
|
17
|
+
const DURATION = 1800 // keep in step with the animation in css/effects.css
|
|
18
|
+
const SWEEP = 900 // keep in step with spotlight-sweep in css/effects.css
|
|
19
|
+
|
|
20
|
+
const LINES = 3 // rings closing in on the element, each started a little after the last (see .spotlight-line)
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The quick shimmer round the element's edge as the flash comes up, with a few lines closing in on it one after another:
|
|
24
|
+
* overlays laid over it in the top layer (so they show inside a dialog, and leave the element's own ::before / ::after
|
|
25
|
+
* alone), animated once by CSS and then removed. They follow the element every frame, since the page may still be
|
|
26
|
+
* scrolling to it.
|
|
27
|
+
* @param {HTMLElement} node
|
|
28
|
+
*/
|
|
29
|
+
function sweep(node) {
|
|
30
|
+
const radius = getComputedStyle(node).borderRadius
|
|
31
|
+
const host = node.closest('dialog') ?? document.body
|
|
32
|
+
const overlays = [{ className: 'spotlight-ring' }, ...Array.from({ length: LINES }, (_, i) => ({ className: 'spotlight-line', i }))].map(({ className, i }) => {
|
|
33
|
+
const el = document.createElement('span')
|
|
34
|
+
el.className = className
|
|
35
|
+
el.setAttribute('aria-hidden', 'true')
|
|
36
|
+
el.setAttribute('popover', 'manual')
|
|
37
|
+
el.setAttribute('data-top-layer', '')
|
|
38
|
+
el.style.borderRadius = radius
|
|
39
|
+
if (i !== undefined) el.style.setProperty('--i', String(i))
|
|
40
|
+
host.append(el)
|
|
41
|
+
el.showPopover?.()
|
|
42
|
+
return el
|
|
43
|
+
})
|
|
44
|
+
let frameId = 0
|
|
45
|
+
const place = () => {
|
|
46
|
+
const r = node.getBoundingClientRect()
|
|
47
|
+
for (const el of overlays) {
|
|
48
|
+
Object.assign(el.style, { top: `${r.top}px`, left: `${r.left}px`, width: `${r.width}px`, height: `${r.height}px` })
|
|
49
|
+
}
|
|
50
|
+
frameId = requestAnimationFrame(place)
|
|
51
|
+
}
|
|
52
|
+
place()
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
cancelAnimationFrame(frameId)
|
|
55
|
+
for (const el of overlays) el.remove()
|
|
56
|
+
}, SWEEP)
|
|
57
|
+
}
|
|
58
|
+
const frame = () => new Promise((resolve) => requestAnimationFrame(() => resolve()))
|
|
59
|
+
const reduced = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
60
|
+
|
|
61
|
+
/** Resolves to what `find` returns once it returns something, checking on every DOM change; null after `timeout` ms. */
|
|
62
|
+
function waitFor(find, timeout) {
|
|
63
|
+
const found = find()
|
|
64
|
+
if (found) return Promise.resolve(found)
|
|
65
|
+
return new Promise((resolve) => {
|
|
66
|
+
const done = (value) => {
|
|
67
|
+
observer.disconnect()
|
|
68
|
+
clearTimeout(timer)
|
|
69
|
+
resolve(value)
|
|
70
|
+
}
|
|
71
|
+
const observer = new MutationObserver(() => {
|
|
72
|
+
const value = find()
|
|
73
|
+
if (value) done(value)
|
|
74
|
+
})
|
|
75
|
+
observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['aria-expanded', 'id'] })
|
|
76
|
+
const timer = setTimeout(() => done(null), timeout)
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** @param {string} id @param {{ timeout?: number }} [opts] how long to wait for it to appear (default 5000ms) */
|
|
81
|
+
export async function spotlight(id, { timeout = 5000 } = {}) {
|
|
82
|
+
const toggleSelector = `[aria-controls~="${CSS.escape(id)}"][aria-expanded="false"]`
|
|
83
|
+
const found = await waitFor(() => document.getElementById(id) ?? document.querySelector(toggleSelector), timeout)
|
|
84
|
+
if (!(found instanceof HTMLElement)) return null
|
|
85
|
+
let node = found
|
|
86
|
+
if (node.id !== id) {
|
|
87
|
+
node.click()
|
|
88
|
+
await tick()
|
|
89
|
+
node = document.getElementById(id)
|
|
90
|
+
if (!node) return null
|
|
91
|
+
}
|
|
92
|
+
for (let details = node.closest('details:not([open])'); details; details = details.parentElement?.closest('details:not([open])') ?? null) {
|
|
93
|
+
details.open = true
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Let an opening transition start, then finish, so the scroll lands on the element's full height.
|
|
97
|
+
await frame()
|
|
98
|
+
await Promise.all(node.getAnimations().map((animation) => animation.finished.catch(() => {})))
|
|
99
|
+
node.scrollIntoView({ block: 'nearest', behavior: reduced() ? 'auto' : 'smooth' })
|
|
100
|
+
|
|
101
|
+
// Restart the flash if it is already running.
|
|
102
|
+
node.removeAttribute('data-spotlight')
|
|
103
|
+
void node.offsetWidth
|
|
104
|
+
node.setAttribute('data-spotlight', '')
|
|
105
|
+
if (!reduced()) sweep(node)
|
|
106
|
+
const target = node
|
|
107
|
+
setTimeout(() => target.removeAttribute('data-spotlight'), DURATION)
|
|
108
|
+
return node
|
|
109
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The values a slider's ticks mark: every stop from min to max (and max itself when the range isn't a whole number of
|
|
3
|
+
* steps). With 'auto', only when there are 3 to MAX_TICKS of them; with true, always (up to 200); with false, none.
|
|
4
|
+
* @param {number} min
|
|
5
|
+
* @param {number} max
|
|
6
|
+
* @param {number} step
|
|
7
|
+
* @param {'auto' | boolean} [ticks]
|
|
8
|
+
* @returns {number[]}
|
|
9
|
+
*/
|
|
10
|
+
export function sliderTicks(min: number, max: number, step: number, ticks?: "auto" | boolean): number[];
|
|
11
|
+
/** The most stops a slider shows ticks for with `ticks: 'auto'`: 11, such as 0–10, or 0–100 in tens. */
|
|
12
|
+
export const MAX_TICKS: 11;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Tick marks for a slider's stops (Slider, RangeSlider): drawn under the track when there are few enough stops to tell
|
|
2
|
+
// apart and to aim for (a rating of 1–5, years 0–10, a range in tens), left out when they would only draw a comb.
|
|
3
|
+
|
|
4
|
+
/** The most stops a slider shows ticks for with `ticks: 'auto'`: 11, such as 0–10, or 0–100 in tens. */
|
|
5
|
+
export const MAX_TICKS = 11
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The values a slider's ticks mark: every stop from min to max (and max itself when the range isn't a whole number of
|
|
9
|
+
* steps). With 'auto', only when there are 3 to MAX_TICKS of them; with true, always (up to 200); with false, none.
|
|
10
|
+
* @param {number} min
|
|
11
|
+
* @param {number} max
|
|
12
|
+
* @param {number} step
|
|
13
|
+
* @param {'auto' | boolean} [ticks]
|
|
14
|
+
* @returns {number[]}
|
|
15
|
+
*/
|
|
16
|
+
export function sliderTicks(min, max, step, ticks = 'auto') {
|
|
17
|
+
if (!ticks || !(step > 0) || !(max > min)) return []
|
|
18
|
+
const whole = Math.floor((max - min) / step + 1e-9)
|
|
19
|
+
const count = whole + 1 + ((max - min) / step - whole > 1e-9 ? 1 : 0)
|
|
20
|
+
if (count > (ticks === 'auto' ? MAX_TICKS : 200) || count < 3) return []
|
|
21
|
+
const values = Array.from({ length: whole + 1 }, (_, i) => min + i * step)
|
|
22
|
+
if (count > whole + 1) values.push(max)
|
|
23
|
+
return values
|
|
24
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attachment: a small tooltip for a control, on hover and on keyboard focus. Required on every button whose
|
|
3
|
+
* meaning is not spelled out in visible text: icon-only buttons, and terse toggles such as "Live".
|
|
4
|
+
*
|
|
5
|
+
* <button class="icon-btn" aria-label="Refresh" {@attach tooltip('Refresh')}>…</button>
|
|
6
|
+
* <button class="icon-btn" aria-label="Search" {@attach tooltip('Search', { shortcut: '/' })}>…</button>
|
|
7
|
+
* <button … {@attach tooltip('Replace', { detail: file.name })}>…</button>
|
|
8
|
+
*
|
|
9
|
+
* text: what the control does, sentence case. No text, no tooltip. shortcut: shown as a key cap after it.
|
|
10
|
+
* detail: a second line under the text, which then turns bold: what the action applies to, in full where the control
|
|
11
|
+
* cuts it short (a long file name). It wraps anywhere, so a name with no spaces still fits.
|
|
12
|
+
* The tooltip is not the accessible name: keep the aria-label. When the text says more than the name, it is
|
|
13
|
+
* also announced as the control's description.
|
|
14
|
+
*
|
|
15
|
+
* It opens in the top layer (Popover API), so it shows above modal dialogs, under the control or above it when
|
|
16
|
+
* there is no room, with an arrow pointing at the control. Escape, a press, scrolling or leaving the control closes it. Touch input never opens it.
|
|
17
|
+
* It fades in and out (css/atoms.css); a closing tip is removed once its fade has ended.
|
|
18
|
+
*/
|
|
19
|
+
let count = 0
|
|
20
|
+
|
|
21
|
+
export function tooltip(text, { shortcut = null, detail = null } = {}) {
|
|
22
|
+
return (node) => {
|
|
23
|
+
if (!text) return
|
|
24
|
+
const id = `tooltip-${++count}`
|
|
25
|
+
const said = detail ? `${text} ${detail}` : text
|
|
26
|
+
const describes = said !== node.getAttribute('aria-label') && said !== node.textContent?.trim()
|
|
27
|
+
let tip = null
|
|
28
|
+
let leaving = null // the tip fading out, if any
|
|
29
|
+
|
|
30
|
+
function show() {
|
|
31
|
+
if (tip) return
|
|
32
|
+
// Coming straight back: the old tip goes at once, so there is never two with this id.
|
|
33
|
+
leaving?.remove()
|
|
34
|
+
leaving = null
|
|
35
|
+
tip = document.createElement('div')
|
|
36
|
+
tip.id = id
|
|
37
|
+
tip.className = 'tooltip'
|
|
38
|
+
tip.setAttribute('role', 'tooltip')
|
|
39
|
+
tip.setAttribute('popover', 'manual')
|
|
40
|
+
if (detail) {
|
|
41
|
+
// Two lines. The space between them isn't drawn (they are grid items) but keeps the words apart when the tip
|
|
42
|
+
// is read out as the control's description.
|
|
43
|
+
const lines = document.createElement('span')
|
|
44
|
+
lines.className = 'tooltip-lines'
|
|
45
|
+
const head = document.createElement('strong')
|
|
46
|
+
head.textContent = text
|
|
47
|
+
const rest = document.createElement('span')
|
|
48
|
+
rest.textContent = detail
|
|
49
|
+
lines.append(head, ' ', rest)
|
|
50
|
+
tip.append(lines)
|
|
51
|
+
} else tip.textContent = text
|
|
52
|
+
if (shortcut) {
|
|
53
|
+
const key = document.createElement('kbd')
|
|
54
|
+
key.textContent = shortcut
|
|
55
|
+
tip.append(key)
|
|
56
|
+
}
|
|
57
|
+
// Inside a modal dialog everything outside it is inert, so the tooltip joins the dialog.
|
|
58
|
+
;(node.closest('dialog') ?? document.body).append(tip)
|
|
59
|
+
tip.showPopover?.()
|
|
60
|
+
const r = node.getBoundingClientRect()
|
|
61
|
+
const w = tip.offsetWidth
|
|
62
|
+
const h = tip.offsetHeight
|
|
63
|
+
const above = r.bottom + h + 16 > innerHeight && r.top > h + 16
|
|
64
|
+
const left = Math.max(8, Math.min(r.left + r.width / 2 - w / 2, innerWidth - w - 8))
|
|
65
|
+
tip.style.left = `${left}px`
|
|
66
|
+
tip.style.top = `${above ? r.top - h - 8 : r.bottom + 8}px`
|
|
67
|
+
// The arrow points back at the control's centre, even when the tip is pushed in from the window's edge.
|
|
68
|
+
tip.dataset.arrow = above ? 'down' : 'up'
|
|
69
|
+
tip.style.setProperty('--arrow-x', `${r.left + r.width / 2 - left}px`)
|
|
70
|
+
if (describes) node.setAttribute('aria-describedby', id)
|
|
71
|
+
addEventListener('scroll', hide, true)
|
|
72
|
+
}
|
|
73
|
+
function hide() {
|
|
74
|
+
if (!tip) return
|
|
75
|
+
// Closed first, so it fades out (css/atoms.css), then removed when that has ended;
|
|
76
|
+
// at once with no fade (reduced motion, or no popover support).
|
|
77
|
+
const old = (leaving = tip)
|
|
78
|
+
tip = null
|
|
79
|
+
if (old.hidePopover && old.matches(':popover-open')) old.hidePopover()
|
|
80
|
+
Promise.all(old.getAnimations().map((a) => a.finished))
|
|
81
|
+
.catch(() => {})
|
|
82
|
+
.finally(() => {
|
|
83
|
+
old.remove()
|
|
84
|
+
if (leaving === old) leaving = null
|
|
85
|
+
})
|
|
86
|
+
if (describes) node.removeAttribute('aria-describedby')
|
|
87
|
+
removeEventListener('scroll', hide, true)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const enter = (event) => event.pointerType !== 'touch' && show()
|
|
91
|
+
const focus = () => node.matches(':focus-visible') && show()
|
|
92
|
+
const key = (event) => event.key === 'Escape' && hide()
|
|
93
|
+
|
|
94
|
+
node.addEventListener('pointerenter', enter)
|
|
95
|
+
node.addEventListener('pointerleave', hide)
|
|
96
|
+
node.addEventListener('pointerdown', hide)
|
|
97
|
+
node.addEventListener('focus', focus)
|
|
98
|
+
node.addEventListener('blur', hide)
|
|
99
|
+
node.addEventListener('keydown', key)
|
|
100
|
+
return () => {
|
|
101
|
+
hide()
|
|
102
|
+
node.removeEventListener('pointerenter', enter)
|
|
103
|
+
node.removeEventListener('pointerleave', hide)
|
|
104
|
+
node.removeEventListener('pointerdown', hide)
|
|
105
|
+
node.removeEventListener('focus', focus)
|
|
106
|
+
node.removeEventListener('blur', hide)
|
|
107
|
+
node.removeEventListener('keydown', key)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attachment that ties an <input> or <textarea> to the browser's constraint validation, so a field has one
|
|
3
|
+
* invalid state whether the app or a native constraint (required, pattern, minlength…) found the problem.
|
|
4
|
+
*
|
|
5
|
+
* <input {@attach validity(() => error, (message) => (native = message))} />
|
|
6
|
+
*
|
|
7
|
+
* error(): the app's own message, '' when there is none. It becomes the control's custom validity, so the
|
|
8
|
+
* control matches :invalid / :user-invalid and the form's checkValidity() fails while it is set.
|
|
9
|
+
* report(message): called with the browser's message when a native constraint fails, and with '' once the
|
|
10
|
+
* field is edited or the app clears its error. A field is checked only when its form is validated (submit,
|
|
11
|
+
* checkValidity, reportValidity), never for being left or while it is typed in.
|
|
12
|
+
*
|
|
13
|
+
* The browser's own bubble is suppressed, since the field shows the message itself; in its place the first
|
|
14
|
+
* invalid control of the form takes the focus.
|
|
15
|
+
*/
|
|
16
|
+
export function validity(error: any, report: any): (node: any) => () => void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attachment that ties an <input> or <textarea> to the browser's constraint validation, so a field has one
|
|
3
|
+
* invalid state whether the app or a native constraint (required, pattern, minlength…) found the problem.
|
|
4
|
+
*
|
|
5
|
+
* <input {@attach validity(() => error, (message) => (native = message))} />
|
|
6
|
+
*
|
|
7
|
+
* error(): the app's own message, '' when there is none. It becomes the control's custom validity, so the
|
|
8
|
+
* control matches :invalid / :user-invalid and the form's checkValidity() fails while it is set.
|
|
9
|
+
* report(message): called with the browser's message when a native constraint fails, and with '' once the
|
|
10
|
+
* field is edited or the app clears its error. A field is checked only when its form is validated (submit,
|
|
11
|
+
* checkValidity, reportValidity), never for being left or while it is typed in.
|
|
12
|
+
*
|
|
13
|
+
* The browser's own bubble is suppressed, since the field shows the message itself; in its place the first
|
|
14
|
+
* invalid control of the form takes the focus.
|
|
15
|
+
*/
|
|
16
|
+
export function validity(error, report) {
|
|
17
|
+
return (node) => {
|
|
18
|
+
const message = error() || ''
|
|
19
|
+
node.setCustomValidity(message)
|
|
20
|
+
if (!message) report('')
|
|
21
|
+
|
|
22
|
+
const invalid = (event) => {
|
|
23
|
+
event.preventDefault()
|
|
24
|
+
report(node.validity.customError ? '' : node.validationMessage)
|
|
25
|
+
if (node.form?.querySelector(':invalid') === node) node.focus()
|
|
26
|
+
}
|
|
27
|
+
const clear = () => report('')
|
|
28
|
+
|
|
29
|
+
node.addEventListener('invalid', invalid)
|
|
30
|
+
node.addEventListener('input', clear)
|
|
31
|
+
return () => {
|
|
32
|
+
node.removeEventListener('invalid', invalid)
|
|
33
|
+
node.removeEventListener('input', clear)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xerios/design-system",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Linear-style design system for Svelte 5: theme tokens, global CSS and generic components",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"svelte",
|
|
7
|
+
"svelte5",
|
|
8
|
+
"design-system",
|
|
9
|
+
"components",
|
|
10
|
+
"ui"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Xerios",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/Xerios/design-system.git"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/Xerios/design-system#readme",
|
|
19
|
+
"bugs": "https://github.com/Xerios/design-system/issues",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": [
|
|
25
|
+
"./dist/fonts.js",
|
|
26
|
+
"**/*.css",
|
|
27
|
+
"**/*.svelte"
|
|
28
|
+
],
|
|
29
|
+
"svelte": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"svelte": "./dist/index.js",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./fonts.js": "./dist/fonts.js",
|
|
38
|
+
"./css/*": "./dist/css/*",
|
|
39
|
+
"./components/*": {
|
|
40
|
+
"svelte": "./dist/components/*",
|
|
41
|
+
"default": "./dist/components/*"
|
|
42
|
+
},
|
|
43
|
+
"./lib/*": {
|
|
44
|
+
"svelte": "./dist/lib/*",
|
|
45
|
+
"default": "./dist/lib/*"
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@fontsource-variable/inter": "^5.3.0",
|
|
54
|
+
"@fontsource-variable/jetbrains-mono": "^5.3.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"svelte": "^5.29.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@phosphor-icons/core": "^2.1.1",
|
|
61
|
+
"@sveltejs/package": "^3.0.3",
|
|
62
|
+
"publint": "^0.3.25",
|
|
63
|
+
"svelte": "^5.58.0",
|
|
64
|
+
"typescript": "^6.0.3"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"dev": "pnpm --filter kitchensink dev",
|
|
68
|
+
"build": "svelte-package --input src --output dist && publint",
|
|
69
|
+
"build:kitchensink": "pnpm --filter kitchensink build",
|
|
70
|
+
"icons": "node scripts/icons.js"
|
|
71
|
+
}
|
|
6
72
|
}
|