@dorsk/tsumikit 0.25.0 → 0.26.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/README.md CHANGED
@@ -145,7 +145,8 @@ for a light theme (`:root` defaults to dark, so dark themes may omit it).
145
145
  ## Components
146
146
 
147
147
  **Atoms:** Text, Heading, Button, Input, Textarea, Select, Switch, Checkbox,
148
- Slider, Progress, Card (`tone` tints the surface for inline banners), Badge
148
+ Slider, Progress, Artwork (lazy cover image with seeded gradient + initials
149
+ fallback, `aspect`, `status` overlay), Card (`tone` tints the surface for inline banners), Badge
149
150
  (`tone` semantic palette or `color` for any CSS colour, `size` xs/sm/md, `dot`,
150
151
  `icon`, `numeric`, `truncate`, `variant="text"`; all tints derive from
151
152
  `--badge-tone`), Dot (`ring` dark halo over artwork), Link (`tone`, `underline`
@@ -174,7 +175,9 @@ the content column only, `stickySidebar` pins it to the viewport, and
174
175
  `sidebarPadding="none" | "sm" | "md"` sets the aside gutter — the header and its
175
176
  children are `min-width: 0` so a wide title/actions row can't widen the grid on
176
177
  mobile), NavItem
177
- (collapses to an icon rail when the sidebar is narrow), Container, Stack
178
+ (collapses to an icon rail when the sidebar is narrow; `icon` from the
179
+ registry, `iconPath` / `iconChildren` for custom glyphs, `activeStyle="bar"`
180
+ for the inset-bar active look), Container, Stack
178
181
  (vertical), Cluster (wrapping row; `stackAt="xs|sm|md|lg"` makes it its own
179
182
  query container and stacks children full-width below 18/30/40/48rem — phone
180
183
  action rows without a viewport query), AutoGrid (intrinsically responsive
@@ -321,6 +324,22 @@ error | done, `onload`, `label`, `loadingLabel`, `errorLabel`, `retryLabel`,
321
324
  </SectionHeader>
322
325
  ```
323
326
 
327
+ ### Artwork
328
+
329
+ `Artwork` is the one cover/thumbnail tile: `src` + `alt` (required) render a
330
+ lazy, async-decoded `<img>`; a missing or failing source swaps to a gradient
331
+ seeded from `seed` (default `alt`) with `fallback` initials | icon | none.
332
+ `aspect` ('1/1', '2/3', '16/9' or any ratio), `size` (width), `radius`
333
+ sm | md | lg | pill, `fit` cover | contain, `hover` for tappable tiles,
334
+ `status` snippet overlaid bottom-right, `onerror`. `artworkGradient(seed)`,
335
+ `artworkHue(seed)` and `initials(text)` are exported for non-component use.
336
+
337
+ ```svelte
338
+ <Artwork src={album.cover} alt={album.title} aspect="1/1" size="9rem" hover>
339
+ {#snippet status()}<Dot status="active" ring />{/snippet}
340
+ </Artwork>
341
+ ```
342
+
324
343
  ## Container queries
325
344
 
326
345
  AppShell's `main` and `sidebar` are query containers (`container-name: main` /
@@ -0,0 +1,7 @@
1
+ /** Hue (0–359) derived from `seed`; stable across runs and environments. */
2
+ export declare function artworkHue(seed: string): number;
3
+ /** CSS `linear-gradient(...)` for the artwork fallback, keyed on `seed`. */
4
+ export declare function artworkGradient(seed: string): string;
5
+ /** Up to two uppercase initials: first letters of the first two words, or the
6
+ * first two characters of a single word. Empty input yields ''. */
7
+ export declare function initials(text: string): string;
@@ -0,0 +1,28 @@
1
+ // Placeholder look for missing artwork: a deterministic hue from `seed` so the
2
+ // same album/show always gets the same tint, tinted over the surface tokens so
3
+ // the fallback tracks the active theme instead of being a fixed dark gradient.
4
+ function hash(text) {
5
+ let h = 0;
6
+ for (const ch of text) {
7
+ h = (h * 31 + (ch.codePointAt(0) ?? 0)) >>> 0;
8
+ }
9
+ return h;
10
+ }
11
+ /** Hue (0–359) derived from `seed`; stable across runs and environments. */
12
+ export function artworkHue(seed) {
13
+ return hash(seed) % 360;
14
+ }
15
+ /** CSS `linear-gradient(...)` for the artwork fallback, keyed on `seed`. */
16
+ export function artworkGradient(seed) {
17
+ const h = artworkHue(seed);
18
+ return `linear-gradient(160deg, color-mix(in srgb, hsl(${h} 60% 55%) 28%, var(--bg-elevated-2)), color-mix(in srgb, hsl(${h} 60% 40%) 16%, var(--bg-elevated)))`;
19
+ }
20
+ /** Up to two uppercase initials: first letters of the first two words, or the
21
+ * first two characters of a single word. Empty input yields ''. */
22
+ export function initials(text) {
23
+ const words = text.trim().split(/\s+/).filter(Boolean);
24
+ if (words.length === 0)
25
+ return '';
26
+ const picked = words.length === 1 ? [...words[0]].slice(0, 2) : words.slice(0, 2).map((w) => [...w][0]);
27
+ return picked.join('').toUpperCase();
28
+ }
@@ -0,0 +1,152 @@
1
+ <script lang="ts">
2
+ // Cover / thumbnail tile: a lazy <img> that swaps to a seeded gradient with
3
+ // initials (or an icon) when there is no source or it fails to load. Width
4
+ // comes from `size`, height from `aspect`; `status` overlays a Dot/Badge in
5
+ // the bottom-right corner.
6
+ import type { Snippet } from 'svelte';
7
+ import { artworkGradient, initials as initialsOf } from '../../artwork';
8
+ import Icon from './Icon.svelte';
9
+ import type { IconName } from './Icon.svelte';
10
+
11
+ let {
12
+ src,
13
+ alt,
14
+ seed,
15
+ aspect = '1/1',
16
+ size,
17
+ radius = 'md',
18
+ fit = 'cover',
19
+ fallback = 'initials',
20
+ icon = 'image',
21
+ status,
22
+ hover = false,
23
+ onerror,
24
+ class: klass = '',
25
+ ...rest
26
+ }: {
27
+ src?: string | null;
28
+ alt: string;
29
+ /** Drives the gradient hue and the initials. Defaults to `alt`. */
30
+ seed?: string;
31
+ /** CSS aspect-ratio, e.g. '1/1', '2/3', '16/9'. */
32
+ aspect?: '1/1' | '2/3' | '16/9' | (string & {});
33
+ /** Width (any CSS length). Omit to fill the container. */
34
+ size?: string;
35
+ radius?: 'sm' | 'md' | 'lg' | 'pill';
36
+ fit?: 'cover' | 'contain';
37
+ fallback?: 'initials' | 'icon' | 'none';
38
+ /** Glyph shown when `fallback="icon"`. */
39
+ icon?: IconName;
40
+ /** Overlay rendered bottom-right (a Dot or Badge). */
41
+ status?: Snippet;
42
+ /** Stronger border + shadow on hover, for tappable tiles. */
43
+ hover?: boolean;
44
+ onerror?: () => void;
45
+ class?: string;
46
+ [key: string]: unknown;
47
+ } = $props();
48
+
49
+ let failed = $state(false);
50
+ $effect(() => {
51
+ src;
52
+ failed = false;
53
+ });
54
+
55
+ const key = $derived(seed ?? alt);
56
+ const showImage = $derived(Boolean(src) && !failed);
57
+ const gradient = $derived(showImage ? undefined : artworkGradient(key));
58
+ const text = $derived(fallback === 'initials' ? initialsOf(key) : '');
59
+
60
+ function fail() {
61
+ failed = true;
62
+ onerror?.();
63
+ }
64
+ </script>
65
+
66
+ <div
67
+ data-tsu="Artwork"
68
+ class="artwork r-{radius} {klass}"
69
+ class:hover
70
+ style:aspect-ratio={aspect}
71
+ style:width={size}
72
+ style:background={gradient}
73
+ role={showImage ? undefined : 'img'}
74
+ aria-label={showImage ? undefined : alt}
75
+ {...rest}
76
+ >
77
+ {#if showImage}
78
+ <img {src} {alt} class="img fit-{fit}" loading="lazy" decoding="async" onerror={fail} />
79
+ {:else if fallback === 'initials' && text}
80
+ <span class="initials" aria-hidden="true">{text}</span>
81
+ {:else if fallback === 'icon'}
82
+ <span class="glyph" aria-hidden="true"><Icon name={icon} /></span>
83
+ {/if}
84
+ {#if status}
85
+ <span class="status">{@render status()}</span>
86
+ {/if}
87
+ </div>
88
+
89
+ <style>
90
+ .artwork {
91
+ position: relative;
92
+ display: flex;
93
+ align-items: center;
94
+ justify-content: center;
95
+ overflow: hidden;
96
+ flex: none;
97
+ background: var(--bg-elevated-2);
98
+ border: 1px solid var(--border);
99
+ color: var(--text-muted);
100
+ container-type: inline-size;
101
+ transition:
102
+ border-color 0.12s var(--ease),
103
+ box-shadow 0.12s var(--ease);
104
+ }
105
+ .r-sm {
106
+ border-radius: var(--r-sm);
107
+ }
108
+ .r-md {
109
+ border-radius: var(--r-md);
110
+ }
111
+ .r-lg {
112
+ border-radius: var(--r-lg);
113
+ }
114
+ .r-pill {
115
+ border-radius: var(--r-pill);
116
+ }
117
+ .hover:hover {
118
+ border-color: var(--border-strong);
119
+ box-shadow: var(--shadow-md);
120
+ }
121
+ .img {
122
+ position: absolute;
123
+ inset: 0;
124
+ width: 100%;
125
+ height: 100%;
126
+ display: block;
127
+ }
128
+ .fit-cover {
129
+ object-fit: cover;
130
+ }
131
+ .fit-contain {
132
+ object-fit: contain;
133
+ }
134
+ .initials {
135
+ font-size: 28cqw;
136
+ font-weight: var(--fw-semibold);
137
+ letter-spacing: 0.04em;
138
+ color: color-mix(in srgb, var(--text) 55%, transparent);
139
+ user-select: none;
140
+ }
141
+ .glyph {
142
+ font-size: 30cqw;
143
+ display: flex;
144
+ color: color-mix(in srgb, var(--text) 40%, transparent);
145
+ }
146
+ .status {
147
+ position: absolute;
148
+ right: var(--sp-2);
149
+ bottom: var(--sp-2);
150
+ display: flex;
151
+ }
152
+ </style>
@@ -0,0 +1,27 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { IconName } from './Icon.svelte';
3
+ type $$ComponentProps = {
4
+ src?: string | null;
5
+ alt: string;
6
+ /** Drives the gradient hue and the initials. Defaults to `alt`. */
7
+ seed?: string;
8
+ /** CSS aspect-ratio, e.g. '1/1', '2/3', '16/9'. */
9
+ aspect?: '1/1' | '2/3' | '16/9' | (string & {});
10
+ /** Width (any CSS length). Omit to fill the container. */
11
+ size?: string;
12
+ radius?: 'sm' | 'md' | 'lg' | 'pill';
13
+ fit?: 'cover' | 'contain';
14
+ fallback?: 'initials' | 'icon' | 'none';
15
+ /** Glyph shown when `fallback="icon"`. */
16
+ icon?: IconName;
17
+ /** Overlay rendered bottom-right (a Dot or Badge). */
18
+ status?: Snippet;
19
+ /** Stronger border + shadow on hover, for tappable tiles. */
20
+ hover?: boolean;
21
+ onerror?: () => void;
22
+ class?: string;
23
+ [key: string]: unknown;
24
+ };
25
+ declare const Artwork: import("svelte").Component<$$ComponentProps, {}, "">;
26
+ type Artwork = ReturnType<typeof Artwork>;
27
+ export default Artwork;
@@ -5,7 +5,7 @@
5
5
  // e.g. a lucide-svelte component's contents — without adding it to the
6
6
  // registry. Sized at 1em so it tracks the surrounding text (and the
7
7
  // --fs-scale font control).
8
- const ICONS = {
8
+ const GLYPHS = {
9
9
  // — navigation / chevrons —
10
10
  back: '<path d="m12 19-7-7 7-7" /><path d="M19 12H5" />',
11
11
  'arrow-right': '<path d="M5 12h14" /><path d="m12 5 7 7-7 7" />',
@@ -55,6 +55,7 @@
55
55
  folder: '<path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z" />',
56
56
  archive: '<rect width="20" height="5" x="2" y="3" rx="1" /><path d="M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8" /><path d="M10 12h4" />',
57
57
  image: '<rect width="18" height="18" x="3" y="3" rx="2" ry="2" /><circle cx="9" cy="9" r="2" /><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" />',
58
+ book: '<path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20" />',
58
59
  markdown: '<rect x="3" y="5" width="18" height="14" rx="2" /><path d="M7 15V9l3 3 3-3v6" /><path d="m15 11 2 2 2-2" />',
59
60
  list: '<path d="M3 5h.01" /><path d="M3 12h.01" /><path d="M3 19h.01" /><path d="M8 5h13" /><path d="M8 12h13" /><path d="M8 19h13" />',
60
61
  grid: '<rect width="7" height="7" x="3" y="3" rx="1" /><rect width="7" height="7" x="14" y="3" rx="1" /><rect width="7" height="7" x="14" y="14" rx="1" /><rect width="7" height="7" x="3" y="14" rx="1" />',
@@ -93,6 +94,9 @@
93
94
  'alert-circle': '<circle cx="12" cy="12" r="10" /><line x1="12" x2="12" y1="8" y2="12" /><line x1="12" x2="12.01" y1="16" y2="16" />',
94
95
  } as const;
95
96
 
97
+ // Alternate names resolving to the same path data.
98
+ const ICONS = { ...GLYPHS, alert: GLYPHS.warning } as const;
99
+
96
100
  export type IconName = keyof typeof ICONS;
97
101
 
98
102
  /** True when `s` is a registered glyph name (vs. e.g. a raw emoji string). */
@@ -1,4 +1,5 @@
1
1
  declare const ICONS: {
2
+ readonly alert: "<path d=\"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3\" /><path d=\"M12 9v4\" /><path d=\"M12 17h.01\" />";
2
3
  readonly back: "<path d=\"m12 19-7-7 7-7\" /><path d=\"M19 12H5\" />";
3
4
  readonly 'arrow-right': "<path d=\"M5 12h14\" /><path d=\"m12 5 7 7-7 7\" />";
4
5
  readonly 'arrow-up': "<path d=\"m5 12 7-7 7 7\" /><path d=\"M12 19V5\" />";
@@ -39,6 +40,7 @@ declare const ICONS: {
39
40
  readonly folder: "<path d=\"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z\" />";
40
41
  readonly archive: "<rect width=\"20\" height=\"5\" x=\"2\" y=\"3\" rx=\"1\" /><path d=\"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8\" /><path d=\"M10 12h4\" />";
41
42
  readonly image: "<rect width=\"18\" height=\"18\" x=\"3\" y=\"3\" rx=\"2\" ry=\"2\" /><circle cx=\"9\" cy=\"9\" r=\"2\" /><path d=\"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21\" />";
43
+ readonly book: "<path d=\"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20\" />";
42
44
  readonly markdown: "<rect x=\"3\" y=\"5\" width=\"18\" height=\"14\" rx=\"2\" /><path d=\"M7 15V9l3 3 3-3v6\" /><path d=\"m15 11 2 2 2-2\" />";
43
45
  readonly list: "<path d=\"M3 5h.01\" /><path d=\"M3 12h.01\" /><path d=\"M3 19h.01\" /><path d=\"M8 5h13\" /><path d=\"M8 12h13\" /><path d=\"M8 19h13\" />";
44
46
  readonly grid: "<rect width=\"7\" height=\"7\" x=\"3\" y=\"3\" rx=\"1\" /><rect width=\"7\" height=\"7\" x=\"14\" y=\"3\" rx=\"1\" /><rect width=\"7\" height=\"7\" x=\"14\" y=\"14\" rx=\"1\" /><rect width=\"7\" height=\"7\" x=\"3\" y=\"14\" rx=\"1\" />";
@@ -6,6 +6,8 @@
6
6
  // collapses to a small dot indicator so the count cue survives the rail.
7
7
  // `title`/`aria-label` carry the name so the icon-only state stays accessible
8
8
  // and shows a tooltip. Renders an <a> when `href` is set, else a <button>.
9
+ // The glyph is `iconChildren` (raw 24×24 SVG content), else `iconPath`
10
+ // (single path d), else the registry `icon`.
9
11
  import type { Snippet } from 'svelte';
10
12
  import Icon from '../atoms/Icon.svelte';
11
13
  import type { IconName } from '../atoms/Icon.svelte';
@@ -15,19 +17,31 @@
15
17
 
16
18
  let {
17
19
  icon,
20
+ iconChildren,
21
+ iconPath,
22
+ iconSize = 18,
18
23
  label,
19
24
  href,
20
25
  active = false,
26
+ activeStyle = 'fill',
21
27
  onclick,
22
28
  badge,
23
29
  badgeTone = 'neutral',
24
30
  children,
25
31
  ...rest
26
32
  }: {
27
- icon: IconName;
33
+ icon?: IconName;
34
+ /** Raw 24×24 SVG content, for glyphs outside the registry. Wins over `iconPath` and `icon`. */
35
+ iconChildren?: Snippet;
36
+ /** Single `<path d>` for a 24×24 outline glyph. Wins over `icon`. */
37
+ iconPath?: string;
38
+ iconSize?: number;
28
39
  label: string;
29
40
  href?: string;
30
41
  active?: boolean;
42
+ /** 'fill' = accent-tinted pill with a rounded left marker; 'bar' = lighter
43
+ * tint with a flat 2px inset accent bar. */
44
+ activeStyle?: 'fill' | 'bar';
31
45
  onclick?: (e: MouseEvent) => void;
32
46
  /** Optional trailing count pill (e.g. unread / missing items). When the
33
47
  * item is `active` it adopts the accent fill; otherwise it uses `badgeTone`. */
@@ -49,13 +63,20 @@
49
63
  type={href ? undefined : 'button'}
50
64
  class="nav-item"
51
65
  class:active
66
+ class:bar={activeStyle === 'bar'}
52
67
  title={label}
53
68
  aria-label={label}
54
69
  aria-current={active ? 'page' : undefined}
55
70
  {onclick}
56
71
  {...rest}
57
72
  >
58
- <Icon name={icon} size={18} />
73
+ {#if iconChildren}
74
+ <Icon size={iconSize}>{@render iconChildren()}</Icon>
75
+ {:else if iconPath}
76
+ <Icon size={iconSize}><path d={iconPath} /></Icon>
77
+ {:else if icon}
78
+ <Icon name={icon} size={iconSize} />
79
+ {/if}
59
80
  <span class="nav-label">{label}</span>
60
81
  {#if hasBadge}
61
82
  <span class="nav-trail">
@@ -101,7 +122,7 @@
101
122
  }
102
123
  /* Active-route accent inset: a left rail marker that survives the icon-rail
103
124
  collapse (the tint background does too, but the marker reads at a glance). */
104
- .nav-item.active::before {
125
+ .nav-item.active:not(.bar)::before {
105
126
  content: '';
106
127
  position: absolute;
107
128
  left: 0;
@@ -112,6 +133,12 @@
112
133
  border-radius: var(--r-pill);
113
134
  background: var(--accent);
114
135
  }
136
+ .nav-item.bar.active {
137
+ background: color-mix(in srgb, var(--accent) 10%, transparent);
138
+ box-shadow: inset 2px 0 0 var(--accent);
139
+ border-start-start-radius: 0;
140
+ border-end-start-radius: 0;
141
+ }
115
142
  .nav-label {
116
143
  flex: 1;
117
144
  min-width: 0; /* allow the label to shrink/ellipsis instead of overflowing */
@@ -2,10 +2,18 @@ import type { Snippet } from 'svelte';
2
2
  import type { IconName } from '../atoms/Icon.svelte';
3
3
  type BadgeTone = 'neutral' | 'ok' | 'warn' | 'danger' | 'info';
4
4
  type $$ComponentProps = {
5
- icon: IconName;
5
+ icon?: IconName;
6
+ /** Raw 24×24 SVG content, for glyphs outside the registry. Wins over `iconPath` and `icon`. */
7
+ iconChildren?: Snippet;
8
+ /** Single `<path d>` for a 24×24 outline glyph. Wins over `icon`. */
9
+ iconPath?: string;
10
+ iconSize?: number;
6
11
  label: string;
7
12
  href?: string;
8
13
  active?: boolean;
14
+ /** 'fill' = accent-tinted pill with a rounded left marker; 'bar' = lighter
15
+ * tint with a flat 2px inset accent bar. */
16
+ activeStyle?: 'fill' | 'bar';
9
17
  onclick?: (e: MouseEvent) => void;
10
18
  /** Optional trailing count pill (e.g. unread / missing items). When the
11
19
  * item is `active` it adopts the accent fill; otherwise it uses `badgeTone`. */
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ export { artworkGradient, artworkHue, initials } from './artwork';
1
2
  export { autoresize } from './autoresize';
2
3
  export { copyToClipboard } from './clipboard';
4
+ export { default as Artwork } from './components/atoms/Artwork.svelte';
3
5
  export { default as Badge } from './components/atoms/Badge.svelte';
4
6
  export { default as Button } from './components/atoms/Button.svelte';
5
7
  export { default as Card } from './components/atoms/Card.svelte';
package/dist/index.js CHANGED
@@ -4,8 +4,10 @@
4
4
  // your app root:
5
5
  // import '@dorsk/tsumikit/styles/app.css';
6
6
  // then use the components below.
7
+ export { artworkGradient, artworkHue, initials } from './artwork';
7
8
  export { autoresize } from './autoresize';
8
9
  export { copyToClipboard } from './clipboard';
10
+ export { default as Artwork } from './components/atoms/Artwork.svelte';
9
11
  export { default as Badge } from './components/atoms/Badge.svelte';
10
12
  export { default as Button } from './components/atoms/Button.svelte';
11
13
  export { default as Card } from './components/atoms/Card.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dorsk/tsumikit",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "Minimal, dependency-free Svelte 5 + pure-CSS UI kit. Token-driven atoms, molecules & layouts with theming out of the box.",
5
5
  "type": "module",
6
6
  "license": "MIT",