dssoca 0.15.0 → 0.17.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 (44) hide show
  1. package/README.md +19 -0
  2. package/dist/components/Icon.svelte +9 -61
  3. package/dist/components/Icon.svelte.d.ts +4 -47
  4. package/dist/components/LogStream.svelte +2 -2
  5. package/dist/components/MetricTile.svelte +2 -2
  6. package/dist/components/ServiceCard.svelte +2 -2
  7. package/dist/components/Spinner.svelte +7 -34
  8. package/dist/components/Spinner.svelte.d.ts +2 -59
  9. package/dist/components/Tooltip.svelte +151 -15
  10. package/dist/components/Tooltip.svelte.d.ts +11 -1
  11. package/dist/icons.d.ts +54 -0
  12. package/dist/icons.js +56 -0
  13. package/dist/index.d.ts +4 -3
  14. package/dist/index.js +4 -2
  15. package/dist/spinner-frames.d.ts +59 -0
  16. package/dist/spinner-frames.js +15 -0
  17. package/dist/toast-core.d.ts +61 -0
  18. package/dist/toast-core.js +73 -0
  19. package/dist/toast.svelte.d.ts +2 -33
  20. package/dist/toast.svelte.js +3 -66
  21. package/dist/vanilla/accordion.d.ts +2 -0
  22. package/dist/vanilla/accordion.js +57 -0
  23. package/dist/vanilla/delegate.d.ts +16 -0
  24. package/dist/vanilla/delegate.js +33 -0
  25. package/dist/vanilla/fields.d.ts +6 -0
  26. package/dist/vanilla/fields.js +89 -0
  27. package/dist/vanilla/icons.d.ts +17 -0
  28. package/dist/vanilla/icons.js +78 -0
  29. package/dist/vanilla/index.d.ts +16 -0
  30. package/dist/vanilla/index.js +60 -0
  31. package/dist/vanilla/menu.d.ts +3 -0
  32. package/dist/vanilla/menu.js +133 -0
  33. package/dist/vanilla/modal.d.ts +3 -0
  34. package/dist/vanilla/modal.js +42 -0
  35. package/dist/vanilla/segmented.d.ts +2 -0
  36. package/dist/vanilla/segmented.js +62 -0
  37. package/dist/vanilla/switch.d.ts +2 -0
  38. package/dist/vanilla/switch.js +22 -0
  39. package/dist/vanilla/toast.d.ts +37 -0
  40. package/dist/vanilla/toast.js +196 -0
  41. package/dist/vanilla/tooltip.d.ts +3 -0
  42. package/dist/vanilla/tooltip.js +54 -0
  43. package/dist/vanilla.css +4433 -0
  44. package/package.json +14 -5
package/README.md CHANGED
@@ -75,6 +75,25 @@ SSR / no-flash — spread the attributes directly in markup instead of mutating
75
75
  <html {...designAttributes({ sizeVariant: 'sm' })}>
76
76
  ```
77
77
 
78
+ ## Plain HTML (no Svelte)
79
+
80
+ Static sites and quick demos can use the same look without a build step: `dssoca/vanilla.css`
81
+ carries every component's styles (generated from the components themselves — the markup contract
82
+ is the exact DOM they render) and `dssoca/vanilla.js` is an optional, dependency-free module that
83
+ wires the interactive parts (modal, menu, accordion, tooltip, switch, toasts, icons…). Load the CSS
84
+ **after** `theme.css`; it needs CSS `@scope` (Chrome/Edge 118+, Safari 17.4+, Firefox 2026+).
85
+
86
+ ```html
87
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.17/dist/theme.css" />
88
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.17/dist/vanilla.css" />
89
+ <script type="module" src="https://cdn.jsdelivr.net/npm/dssoca@0.17/dist/vanilla/index.js"></script>
90
+
91
+ <button class="ss-btn primary" type="button" data-ss-modal="#confirm">deploy</button>
92
+ ```
93
+
94
+ Every component page in the docs has an **HTML** section with copy-paste markup; the full contract
95
+ is in the _Plain HTML & CSS_ guide.
96
+
78
97
  ## What's in the box
79
98
 
80
99
  **Components (23):** `Icon`, `Badge`, `Button`, `Input`, `Textarea`, `Card`, `Sparkline`,
@@ -1,67 +1,15 @@
1
1
  <script module lang="ts">
2
- /** Curated glyph set. `target`'s centre dot is a filled circle in the *outline*
3
- * variant — handled by the `variant` switch in markup, not a per-glyph fill hack. */
4
- const BUILTIN_PATHS = {
5
- grid: '<rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/>',
6
- activity: '<path d="M3 12h4l3-8 4 16 3-8h4"/>',
7
- database: '<rect x="3" y="4" width="18" height="16"/><path d="M3 9h18M8 4v5"/>',
8
- logs: '<path d="M4 6h16M4 12h16M4 18h10"/>',
9
- terminal: '<rect x="3" y="5" width="18" height="14"/><path d="M3 9h18M7 14h4"/>',
10
- settings:
11
- '<circle cx="12" cy="12" r="3"/><path d="M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M4.9 19.1L7 17M17 7l2.1-2.1"/>',
12
- user: '<circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-7 8-7s8 3 8 7"/>',
13
- arrow: '<path d="M5 12h14M13 5l7 7-7 7"/>',
14
- chevron: '<path d="M8 10l4 4 4-4"/>',
15
- external: '<path d="M7 17L17 7M9 7h8v8"/>',
16
- film: '<rect x="3" y="4" width="18" height="16"/><path d="M3 8h4M3 16h4M17 8h4M17 16h4M3 12h18"/>',
17
- note: '<rect x="4" y="3" width="16" height="18"/><path d="M8 8h8M8 12h8M8 16h6"/>',
18
- book: '<path d="M6 4h11a1 1 0 011 1v15H7a1 1 0 01-1-1z"/><path d="M17 20a2 2 0 002-2V6a2 2 0 00-2-2"/><path d="M9 8h5"/>',
19
- check: '<path d="M5 12l4 4L19 6"/>',
20
- cup: '<path d="M4 8h12v6a4 4 0 01-4 4H8a4 4 0 01-4-4z"/><path d="M16 10h2a2 2 0 010 4h-2M6 4v2M10 4v2M14 4v2"/>',
21
- wallet: '<rect x="3" y="6" width="18" height="14"/><path d="M3 10h18M17 14h2"/>',
22
- target:
23
- '<circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1.5" class="ss-icon-dot"/>',
24
- spinner: '<path d="M12 3a9 9 0 1 0 9 9" stroke-linecap="round"/>',
25
- home: '<path d="M4 11l8-8 8 8"/><path d="M6 9v12h12V9"/><path d="M10 21v-6h4v6"/>',
26
- briefcase: '<rect x="3" y="7" width="18" height="13"/><path d="M9 7V4h6v3M3 12h18"/>',
27
- folder: '<path d="M3 5h7l2 3h9v13H3z"/><path d="M3 8h9"/>',
28
- github:
29
- '<path d="M7 3h10l2 2v6l-2 3h-4l1 2v5h-4v-5l1-2H7l-2-3V5l2-2z"/><path d="M9 8h1M14 8h1"/>',
30
- linkedin:
31
- '<rect x="3" y="3" width="18" height="18"/><path d="M8 16v-5M8 8v.01M12 16v-5h2l2 2v3"/>',
32
- language: '<circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3L8 12l4 9M12 3l4 9-4 9"/>',
33
- 'color-swatch':
34
- '<rect x="3" y="3" width="8" height="18"/><path d="M7 17v.01"/><path d="M11 19l8-8 2 2-8 8"/><path d="M13 21h8"/>',
35
- } as const
36
-
37
- export type IconName = keyof typeof BUILTIN_PATHS
38
-
39
- /**
40
- * The curated built-in glyphs plus any runtime-registered ones.
41
- * (`PATHS` is kept as the public name for backward compatibility.)
42
- */
43
- export const PATHS: Record<string, string> = { ...BUILTIN_PATHS }
44
-
45
- /**
46
- * Register (or override) a glyph at runtime so `<Icon name="foo" />` resolves
47
- * raw SVG inner markup that isn't part of the curated {@link IconName} union.
48
- * The markup is rendered verbatim inside the icon's `<svg viewBox="0 0 24 24">`.
49
- *
50
- * registerIcon('heart', '<path d="M12 21 4 13a5 5 0 0 1 7-7l1 1 1-1a5 5 0 0 1 7 7z"/>')
51
- * <Icon name={'heart' as IconName} />
52
- */
53
- export function registerIcon(name: string, paths: string): void {
54
- PATHS[name] = paths
55
- }
56
-
57
- /** Look a glyph up; built-ins first, then runtime registrations. */
58
- export function resolveIcon(name: string): string | undefined {
59
- return PATHS[name]
60
- }
2
+ // Glyph table + registry live in `../icons.ts` (DS-0148) so the vanilla build can share
3
+ // them without importing a .svelte file. Re-exported here for backward compatibility.
4
+ export { PATHS, registerIcon, resolveIcon } from '../icons.js'
5
+ export type { IconName } from '../icons.js'
61
6
  </script>
62
7
 
63
8
  <script lang="ts">
64
9
  import { resolveComponentSize, type Size } from '../config.js'
10
+ // Aliased: the module script re-exports the same names, and eslint-plugin-svelte
11
+ // merges both scopes.
12
+ import { resolveIcon as lookupIcon, type IconName as GlyphName } from '../icons.js'
65
13
 
66
14
  /**
67
15
  * Icon-local size scale (DS-0109). Distinct from the global `Size` axis
@@ -76,7 +24,7 @@
76
24
  const DEFAULT_PX = SIZE_PX.md
77
25
 
78
26
  interface Props {
79
- name: IconName
27
+ name: GlyphName
80
28
  /**
81
29
  * Icon-local size (`xs | sm | md | lg`, a fixed px scale); inherits the
82
30
  * active `--ss-icon` token when unset. `xs` (12px) is Icon-only and has no
@@ -141,7 +89,7 @@
141
89
  // Resolve the glyph: explicit `paths` escape hatch → registered/built-in → warn.
142
90
  const markup = $derived.by(() => {
143
91
  if (paths != null) return paths
144
- const found = resolveIcon(name)
92
+ const found = lookupIcon(name)
145
93
  if (found != null) return found
146
94
  if (typeof console !== 'undefined') {
147
95
  console.warn(
@@ -1,50 +1,7 @@
1
- /** Curated glyph set. `target`'s centre dot is a filled circle in the *outline*
2
- * variant — handled by the `variant` switch in markup, not a per-glyph fill hack. */
3
- declare const BUILTIN_PATHS: {
4
- readonly grid: "<rect x=\"3\" y=\"3\" width=\"7\" height=\"7\"/><rect x=\"14\" y=\"3\" width=\"7\" height=\"7\"/><rect x=\"3\" y=\"14\" width=\"7\" height=\"7\"/><rect x=\"14\" y=\"14\" width=\"7\" height=\"7\"/>";
5
- readonly activity: "<path d=\"M3 12h4l3-8 4 16 3-8h4\"/>";
6
- readonly database: "<rect x=\"3\" y=\"4\" width=\"18\" height=\"16\"/><path d=\"M3 9h18M8 4v5\"/>";
7
- readonly logs: "<path d=\"M4 6h16M4 12h16M4 18h10\"/>";
8
- readonly terminal: "<rect x=\"3\" y=\"5\" width=\"18\" height=\"14\"/><path d=\"M3 9h18M7 14h4\"/>";
9
- readonly settings: "<circle cx=\"12\" cy=\"12\" r=\"3\"/><path d=\"M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M4.9 19.1L7 17M17 7l2.1-2.1\"/>";
10
- readonly user: "<circle cx=\"12\" cy=\"8\" r=\"4\"/><path d=\"M4 21c0-4 4-7 8-7s8 3 8 7\"/>";
11
- readonly arrow: "<path d=\"M5 12h14M13 5l7 7-7 7\"/>";
12
- readonly chevron: "<path d=\"M8 10l4 4 4-4\"/>";
13
- readonly external: "<path d=\"M7 17L17 7M9 7h8v8\"/>";
14
- readonly film: "<rect x=\"3\" y=\"4\" width=\"18\" height=\"16\"/><path d=\"M3 8h4M3 16h4M17 8h4M17 16h4M3 12h18\"/>";
15
- readonly note: "<rect x=\"4\" y=\"3\" width=\"16\" height=\"18\"/><path d=\"M8 8h8M8 12h8M8 16h6\"/>";
16
- readonly book: "<path d=\"M6 4h11a1 1 0 011 1v15H7a1 1 0 01-1-1z\"/><path d=\"M17 20a2 2 0 002-2V6a2 2 0 00-2-2\"/><path d=\"M9 8h5\"/>";
17
- readonly check: "<path d=\"M5 12l4 4L19 6\"/>";
18
- readonly cup: "<path d=\"M4 8h12v6a4 4 0 01-4 4H8a4 4 0 01-4-4z\"/><path d=\"M16 10h2a2 2 0 010 4h-2M6 4v2M10 4v2M14 4v2\"/>";
19
- readonly wallet: "<rect x=\"3\" y=\"6\" width=\"18\" height=\"14\"/><path d=\"M3 10h18M17 14h2\"/>";
20
- readonly target: "<circle cx=\"12\" cy=\"12\" r=\"9\"/><circle cx=\"12\" cy=\"12\" r=\"5\"/><circle cx=\"12\" cy=\"12\" r=\"1.5\" class=\"ss-icon-dot\"/>";
21
- readonly spinner: "<path d=\"M12 3a9 9 0 1 0 9 9\" stroke-linecap=\"round\"/>";
22
- readonly home: "<path d=\"M4 11l8-8 8 8\"/><path d=\"M6 9v12h12V9\"/><path d=\"M10 21v-6h4v6\"/>";
23
- readonly briefcase: "<rect x=\"3\" y=\"7\" width=\"18\" height=\"13\"/><path d=\"M9 7V4h6v3M3 12h18\"/>";
24
- readonly folder: "<path d=\"M3 5h7l2 3h9v13H3z\"/><path d=\"M3 8h9\"/>";
25
- readonly github: "<path d=\"M7 3h10l2 2v6l-2 3h-4l1 2v5h-4v-5l1-2H7l-2-3V5l2-2z\"/><path d=\"M9 8h1M14 8h1\"/>";
26
- readonly linkedin: "<rect x=\"3\" y=\"3\" width=\"18\" height=\"18\"/><path d=\"M8 16v-5M8 8v.01M12 16v-5h2l2 2v3\"/>";
27
- readonly language: "<circle cx=\"12\" cy=\"12\" r=\"9\"/><path d=\"M3 12h18M12 3L8 12l4 9M12 3l4 9-4 9\"/>";
28
- readonly 'color-swatch': "<rect x=\"3\" y=\"3\" width=\"8\" height=\"18\"/><path d=\"M7 17v.01\"/><path d=\"M11 19l8-8 2 2-8 8\"/><path d=\"M13 21h8\"/>";
29
- };
30
- export type IconName = keyof typeof BUILTIN_PATHS;
31
- /**
32
- * The curated built-in glyphs plus any runtime-registered ones.
33
- * (`PATHS` is kept as the public name for backward compatibility.)
34
- */
35
- export declare const PATHS: Record<string, string>;
36
- /**
37
- * Register (or override) a glyph at runtime so `<Icon name="foo" />` resolves
38
- * raw SVG inner markup that isn't part of the curated {@link IconName} union.
39
- * The markup is rendered verbatim inside the icon's `<svg viewBox="0 0 24 24">`.
40
- *
41
- * registerIcon('heart', '<path d="M12 21 4 13a5 5 0 0 1 7-7l1 1 1-1a5 5 0 0 1 7 7z"/>')
42
- * <Icon name={'heart' as IconName} />
43
- */
44
- export declare function registerIcon(name: string, paths: string): void;
45
- /** Look a glyph up; built-ins first, then runtime registrations. */
46
- export declare function resolveIcon(name: string): string | undefined;
1
+ export { PATHS, registerIcon, resolveIcon } from '../icons.js';
2
+ export type { IconName } from '../icons.js';
47
3
  import { type Size } from '../config.js';
4
+ import { type IconName as GlyphName } from '../icons.js';
48
5
  /**
49
6
  * Icon-local size scale (DS-0109). Distinct from the global `Size` axis
50
7
  * (`sm | md | lg`): Icon adds an `xs` (12px) dense step that has *no* global
@@ -53,7 +10,7 @@ import { type Size } from '../config.js';
53
10
  */
54
11
  export type IconSize = 'xs' | Size;
55
12
  interface Props {
56
- name: IconName;
13
+ name: GlyphName;
57
14
  /**
58
15
  * Icon-local size (`xs | sm | md | lg`, a fixed px scale); inherits the
59
16
  * active `--ss-icon` token when unset. `xs` (12px) is Icon-only and has no
@@ -424,10 +424,10 @@
424
424
  width: var(--ss-s-2);
425
425
  height: var(--ss-s-2);
426
426
  background: var(--ss-primary);
427
- animation: pulse var(--ss-dur-xslow) var(--ss-ease) infinite;
427
+ animation: ss-logs-pulse var(--ss-dur-xslow) var(--ss-ease) infinite;
428
428
  }
429
429
 
430
- @keyframes pulse {
430
+ @keyframes ss-logs-pulse {
431
431
  0%, 100% {
432
432
  opacity: 0.3;
433
433
  }
@@ -148,7 +148,7 @@
148
148
  .ss-metric .skeleton {
149
149
  background: var(--ss-skeleton);
150
150
  border-radius: var(--ss-radius-0);
151
- animation: skeleton-pulse var(--ss-dur-xslow) var(--ss-ease) infinite alternate;
151
+ animation: ss-metric-skeleton-pulse var(--ss-dur-xslow) var(--ss-ease) infinite alternate;
152
152
  }
153
153
  .ss-metric .skeleton-val {
154
154
  height: var(--ss-metric-val);
@@ -159,7 +159,7 @@
159
159
  width: 35%;
160
160
  }
161
161
 
162
- @keyframes skeleton-pulse {
162
+ @keyframes ss-metric-skeleton-pulse {
163
163
  from {
164
164
  opacity: 1;
165
165
  }
@@ -280,7 +280,7 @@ a.ss-svc:focus-visible,
280
280
  inset: 0;
281
281
  transform: translateX(-100%);
282
282
  background: linear-gradient(90deg, transparent, var(--ss-hover), transparent);
283
- animation: sk-shimmer var(--ss-dur-xslow) var(--ss-ease) infinite;
283
+ animation: ss-svc-shimmer var(--ss-dur-xslow) var(--ss-ease) infinite;
284
284
  }
285
285
 
286
286
  .sk-name {
@@ -304,7 +304,7 @@ a.ss-svc:focus-visible,
304
304
  height: var(--ss-icon);
305
305
  }
306
306
 
307
- @keyframes sk-shimmer {
307
+ @keyframes ss-svc-shimmer {
308
308
  100% {
309
309
  transform: translateX(100%);
310
310
  }
@@ -7,43 +7,16 @@
7
7
  export { SPINNER_VARIANT_NAMES } from '../dssoca.config.js'
8
8
  export type SpinnerVariant = SpinnerVariantName
9
9
 
10
- /**
11
- * Text-frame spinner variants. Frames + intervals are embedded verbatim from
12
- * sindresorhus/cli-spinners (MIT — https://github.com/sindresorhus/cli-spinners),
13
- * curated for the squared/blocky glyphs that fit the DS's zero-radius look.
14
- * No runtime fetch, no dependency — just data.
15
- *
16
- * The *variant names* are owned by `dssoca.config.ts` (`SpinnerVariant`,
17
- * derived from the `spinner` manifest axis — DS-0108); this object holds the
18
- * frame data and is pinned to that union via `satisfies Record<SpinnerVariant,
19
- * …>`, so the two cannot drift.
20
- */
21
- export interface SpinnerFrames {
22
- /** Milliseconds between frames (cli-spinners' recommended cadence). */
23
- interval: number
24
- /** The glyph sequence, cycled in order. */
25
- frames: readonly string[]
26
- }
27
-
28
- export const SPINNER_VARIANTS = {
29
- boxBounce2: { interval: 100, frames: ['▌', '▀', '▐', '▄'] },
30
- boxBounce: { interval: 120, frames: ['▖', '▘', '▝', '▗'] },
31
- squareCorners: { interval: 180, frames: ['◰', '◳', '◲', '◱'] },
32
- toggle2: { interval: 80, frames: ['▫', '▪'] },
33
- toggle3: { interval: 120, frames: ['□', '■'] },
34
- toggle4: { interval: 100, frames: ['■', '□', '▪', '▫'] },
35
- pipe: { interval: 100, frames: ['┤', '┘', '┴', '└', '├', '┌', '┬', '┐'] },
36
- line: { interval: 130, frames: ['-', '\\', '|', '/'] },
37
- growVertical: { interval: 120, frames: ['▁', '▃', '▄', '▅', '▆', '▇', '▆', '▅', '▄', '▃'] },
38
- growHorizontal: {
39
- interval: 120,
40
- frames: ['▏', '▎', '▍', '▌', '▋', '▊', '▉', '▊', '▋', '▌', '▍', '▎'],
41
- },
42
- } as const satisfies Record<SpinnerVariantName, SpinnerFrames>
10
+ // Frame data lives in `../spinner-frames.ts` (DS-0148) so the vanilla CSS generator can
11
+ // share it without importing a .svelte file. Re-exported here for backward compatibility.
12
+ export { SPINNER_VARIANTS } from '../spinner-frames.js'
13
+ export type { SpinnerFrames } from '../spinner-frames.js'
43
14
  </script>
44
15
 
45
16
  <script lang="ts">
46
17
  import { resolveComponentSize, resolveSpinnerVariant, type Size } from '../config.js'
18
+ // Aliased: the module script re-exports the same name (eslint-plugin-svelte merges scopes).
19
+ import { SPINNER_VARIANTS as VARIANTS } from '../spinner-frames.js'
47
20
 
48
21
  interface Props {
49
22
  /**
@@ -68,7 +41,7 @@
68
41
  // An explicit `variant` prop wins; otherwise fall back to the configured
69
42
  // house default (`spinnerVariant`, from the manifest) — DS-0108.
70
43
  const resolvedVariant = $derived(resolveSpinnerVariant(variant))
71
- const spinner = $derived(SPINNER_VARIANTS[resolvedVariant])
44
+ const spinner = $derived(VARIANTS[resolvedVariant])
72
45
  const interval = $derived(speed ?? spinner.interval)
73
46
  const resolvedSize = $derived(resolveComponentSize('Spinner', size))
74
47
 
@@ -1,65 +1,8 @@
1
1
  import { type SpinnerVariant as SpinnerVariantName } from '../dssoca.config.js';
2
2
  export { SPINNER_VARIANT_NAMES } from '../dssoca.config.js';
3
3
  export type SpinnerVariant = SpinnerVariantName;
4
- /**
5
- * Text-frame spinner variants. Frames + intervals are embedded verbatim from
6
- * sindresorhus/cli-spinners (MIT — https://github.com/sindresorhus/cli-spinners),
7
- * curated for the squared/blocky glyphs that fit the DS's zero-radius look.
8
- * No runtime fetch, no dependency — just data.
9
- *
10
- * The *variant names* are owned by `dssoca.config.ts` (`SpinnerVariant`,
11
- * derived from the `spinner` manifest axis — DS-0108); this object holds the
12
- * frame data and is pinned to that union via `satisfies Record<SpinnerVariant,
13
- * …>`, so the two cannot drift.
14
- */
15
- export interface SpinnerFrames {
16
- /** Milliseconds between frames (cli-spinners' recommended cadence). */
17
- interval: number;
18
- /** The glyph sequence, cycled in order. */
19
- frames: readonly string[];
20
- }
21
- export declare const SPINNER_VARIANTS: {
22
- readonly boxBounce2: {
23
- readonly interval: 100;
24
- readonly frames: readonly ["▌", "▀", "▐", "▄"];
25
- };
26
- readonly boxBounce: {
27
- readonly interval: 120;
28
- readonly frames: readonly ["▖", "▘", "▝", "▗"];
29
- };
30
- readonly squareCorners: {
31
- readonly interval: 180;
32
- readonly frames: readonly ["◰", "◳", "◲", "◱"];
33
- };
34
- readonly toggle2: {
35
- readonly interval: 80;
36
- readonly frames: readonly ["▫", "▪"];
37
- };
38
- readonly toggle3: {
39
- readonly interval: 120;
40
- readonly frames: readonly ["□", "■"];
41
- };
42
- readonly toggle4: {
43
- readonly interval: 100;
44
- readonly frames: readonly ["■", "□", "▪", "▫"];
45
- };
46
- readonly pipe: {
47
- readonly interval: 100;
48
- readonly frames: readonly ["┤", "┘", "┴", "└", "├", "┌", "┬", "┐"];
49
- };
50
- readonly line: {
51
- readonly interval: 130;
52
- readonly frames: readonly ["-", "\\", "|", "/"];
53
- };
54
- readonly growVertical: {
55
- readonly interval: 120;
56
- readonly frames: readonly ["▁", "▃", "▄", "▅", "▆", "▇", "▆", "▅", "▄", "▃"];
57
- };
58
- readonly growHorizontal: {
59
- readonly interval: 120;
60
- readonly frames: readonly ["▏", "▎", "▍", "▌", "▋", "▊", "▉", "▊", "▋", "▌", "▍", "▎"];
61
- };
62
- };
4
+ export { SPINNER_VARIANTS } from '../spinner-frames.js';
5
+ export type { SpinnerFrames } from '../spinner-frames.js';
63
6
  import { type Size } from '../config.js';
64
7
  interface Props {
65
8
  /**
@@ -14,19 +14,38 @@
14
14
  * WAI-ARIA tooltip pattern.
15
15
  */
16
16
  text: string | Snippet
17
- /** Where the tooltip attaches relative to the trigger. Default `top`. */
17
+ /**
18
+ * Preferred side the tooltip attaches to relative to the trigger. Default `top`.
19
+ * With `avoidCollisions` (the default) this is only a preference — see below.
20
+ */
18
21
  placement?: Placement
22
+ /**
23
+ * Keep the tip visible when the preferred side has no room (DS-0146): flip to the
24
+ * opposite side, then to the perpendicular side with the most room, then shift along
25
+ * the cross axis so the tip never overhangs the viewport or an `overflow`-clipping
26
+ * ancestor. `false` pins the tip to `placement`. Default `true`.
27
+ */
28
+ avoidCollisions?: boolean
19
29
  /** Token size (sm|md|lg); inherits the global size when unset. */
20
30
  size?: Size
21
31
  /** Trigger content (wrapped in an inline-block container). */
22
32
  children: Snippet
23
33
  }
24
34
 
25
- let { text, placement = 'top', size, children }: Props = $props()
35
+ let { text, placement = 'top', avoidCollisions = true, size, children }: Props = $props()
26
36
 
27
37
  const tipId = $props.id()
28
38
 
29
39
  let open = $state(false)
40
+ let triggerEl = $state<HTMLElement | undefined>()
41
+ let tipEl = $state<HTMLElement | undefined>()
42
+
43
+ /** Side chosen by collision avoidance while open; `null` = use the preferred side. */
44
+ let flipped = $state<Placement | null>(null)
45
+ /** Side actually in use (the preferred side unless collision avoidance moved it). */
46
+ const resolved = $derived(flipped ?? placement)
47
+ /** Cross-axis nudge in px (x for top/bottom, y for left/right). */
48
+ let shift = $state(0)
30
49
 
31
50
  function show() {
32
51
  open = true
@@ -45,6 +64,110 @@
45
64
 
46
65
  // Snippets are functions, so a runtime typeof check narrows the union.
47
66
  const tipSnippet = $derived(typeof text === 'function' ? text : undefined)
67
+
68
+ // --- collision avoidance ---------------------------------------------------
69
+ // Manual measurement (what Floating UI's `flip` + `shift` do internally) rather
70
+ // than a dependency or CSS anchor positioning: zero deps, every browser, and
71
+ // exercisable in jsdom. The closed tip already has layout (its `display: block`
72
+ // beats the UA `[hidden]` rule; hiding is visibility/opacity), so it can be
73
+ // measured before it is revealed.
74
+
75
+ type Rect = { top: number; right: number; bottom: number; left: number }
76
+
77
+ const OPPOSITE: Record<Placement, Placement> = {
78
+ top: 'bottom',
79
+ bottom: 'top',
80
+ left: 'right',
81
+ right: 'left',
82
+ }
83
+
84
+ /** Viewport ∩ every ancestor that clips overflow (a scrolling Panel, Modal body…). */
85
+ function clippingBoundary(from: HTMLElement): Rect {
86
+ const r: Rect = { top: 0, left: 0, right: window.innerWidth, bottom: window.innerHeight }
87
+ let el: HTMLElement | null = from.parentElement
88
+ while (el && el !== document.body) {
89
+ const cs = getComputedStyle(el)
90
+ if (cs.overflowX !== 'visible' || cs.overflowY !== 'visible') {
91
+ const b = el.getBoundingClientRect()
92
+ r.top = Math.max(r.top, b.top)
93
+ r.left = Math.max(r.left, b.left)
94
+ r.right = Math.min(r.right, b.right)
95
+ r.bottom = Math.min(r.bottom, b.bottom)
96
+ }
97
+ el = el.parentElement
98
+ }
99
+ return r
100
+ }
101
+
102
+ function position() {
103
+ if (!avoidCollisions || !triggerEl || !tipEl) {
104
+ flipped = null
105
+ shift = 0
106
+ return
107
+ }
108
+ const boundary = clippingBoundary(triggerEl)
109
+ const t = triggerEl.getBoundingClientRect()
110
+ const w = tipEl.offsetWidth
111
+ const h = tipEl.offsetHeight
112
+ const gap = parseFloat(getComputedStyle(tipEl).getPropertyValue('--ss-tooltip-offset')) || 6
113
+
114
+ const space: Record<Placement, number> = {
115
+ top: t.top - boundary.top,
116
+ bottom: boundary.bottom - t.bottom,
117
+ left: t.left - boundary.left,
118
+ right: boundary.right - t.right,
119
+ }
120
+ const need = (p: Placement) => (p === 'top' || p === 'bottom' ? h : w) + gap
121
+
122
+ // Preferred → opposite → perpendicular sides (roomier first) → most room overall.
123
+ const perpendicular: Placement[] =
124
+ placement === 'top' || placement === 'bottom' ? ['left', 'right'] : ['top', 'bottom']
125
+ perpendicular.sort((a, b) => space[b] - space[a])
126
+ const order: Placement[] = [placement, OPPOSITE[placement], ...perpendicular]
127
+ const side =
128
+ order.find((p) => space[p] >= need(p)) ??
129
+ order.reduce((best, p) => (space[p] > space[best] ? p : best))
130
+ flipped = side
131
+
132
+ // Cross-axis shift: the tip is centred on the trigger; clamp its edges inside the
133
+ // boundary (padded by the same gap it keeps from the trigger).
134
+ if (side === 'top' || side === 'bottom') {
135
+ const center = t.left + t.width / 2
136
+ const left = center - w / 2
137
+ const right = center + w / 2
138
+ const min = boundary.left + gap
139
+ const max = boundary.right - gap
140
+ shift = left < min ? min - left : right > max ? max - right : 0
141
+ } else {
142
+ const center = t.top + t.height / 2
143
+ const top = center - h / 2
144
+ const bottom = center + h / 2
145
+ const min = boundary.top + gap
146
+ const max = boundary.bottom - gap
147
+ shift = top < min ? min - top : bottom > max ? max - bottom : 0
148
+ }
149
+ }
150
+
151
+ // Client-only: while open, (re)position on show / prop change and on any scroll
152
+ // (capture catches nested scroll containers) or resize; on close, reset.
153
+ $effect(() => {
154
+ if (!open) {
155
+ flipped = null
156
+ shift = 0
157
+ return
158
+ }
159
+ // Read the props here so a change while open re-runs the effect.
160
+ void placement
161
+ void avoidCollisions
162
+ position()
163
+ const onMove = () => position()
164
+ window.addEventListener('scroll', onMove, { capture: true, passive: true })
165
+ window.addEventListener('resize', onMove, { passive: true })
166
+ return () => {
167
+ window.removeEventListener('scroll', onMove, { capture: true })
168
+ window.removeEventListener('resize', onMove)
169
+ }
170
+ })
48
171
  </script>
49
172
 
50
173
  <!--
@@ -56,6 +179,10 @@
56
179
 
57
180
  `text` is either a string or a snippet (DS-0144); a snippet renders inside the
58
181
  same tip element, so the accessible description stays whatever the tip contains.
182
+
183
+ `data-placement` is the *resolved* side (DS-0146): the preferred `placement`
184
+ unless collision avoidance flipped it. `--shift` nudges the tip along the cross
185
+ axis so it stays inside the viewport / clipping ancestor.
59
186
  -->
60
187
  <!-- svelte-ignore a11y_no_static_element_interactions -- the wrapper is a passive
61
188
  container; the real interactive element is the trigger snippet inside it, and the
@@ -63,7 +190,7 @@
63
190
  <span
64
191
  class="ss-tooltip"
65
192
  data-size-variant={sizeAttr}
66
- data-placement={placement}
193
+ data-placement={resolved}
67
194
  aria-describedby={open ? tipId : undefined}
68
195
  onmouseenter={show}
69
196
  onmouseleave={hide}
@@ -71,8 +198,16 @@
71
198
  onfocusout={hide}
72
199
  onkeydown={onKeydown}
73
200
  >
74
- <span class="trigger">{@render children()}</span>
75
- <span id={tipId} class="tip" class:open role="tooltip" hidden={!open}>
201
+ <span class="trigger" bind:this={triggerEl}>{@render children()}</span>
202
+ <span
203
+ id={tipId}
204
+ class="tip"
205
+ class:open
206
+ role="tooltip"
207
+ hidden={!open}
208
+ style:--shift="{shift}px"
209
+ bind:this={tipEl}
210
+ >
76
211
  {#if tipSnippet}{@render tipSnippet()}{:else}{text}{/if}
77
212
  </span>
78
213
  </span>
@@ -87,6 +222,7 @@
87
222
  }
88
223
 
89
224
  .tip {
225
+ --shift: 0px;
90
226
  position: absolute;
91
227
  z-index: 60;
92
228
  display: block;
@@ -115,45 +251,45 @@
115
251
  .ss-tooltip[data-placement=top] .tip {
116
252
  bottom: calc(100% + var(--ss-tooltip-offset, 6px));
117
253
  left: 50%;
118
- transform: translateX(-50%) scale(0.98);
254
+ transform: translateX(calc(-50% + var(--shift))) scale(0.98);
119
255
  transform-origin: bottom center;
120
256
  }
121
257
 
122
258
  .ss-tooltip[data-placement=top] .tip.open {
123
- transform: translateX(-50%) scale(1);
259
+ transform: translateX(calc(-50% + var(--shift))) scale(1);
124
260
  }
125
261
 
126
262
  .ss-tooltip[data-placement=bottom] .tip {
127
263
  top: calc(100% + var(--ss-tooltip-offset, 6px));
128
264
  left: 50%;
129
- transform: translateX(-50%) scale(0.98);
265
+ transform: translateX(calc(-50% + var(--shift))) scale(0.98);
130
266
  transform-origin: top center;
131
267
  }
132
268
 
133
269
  .ss-tooltip[data-placement=bottom] .tip.open {
134
- transform: translateX(-50%) scale(1);
270
+ transform: translateX(calc(-50% + var(--shift))) scale(1);
135
271
  }
136
272
 
137
273
  .ss-tooltip[data-placement=left] .tip {
138
274
  right: calc(100% + var(--ss-tooltip-offset, 6px));
139
275
  top: 50%;
140
- transform: translateY(-50%) scale(0.98);
276
+ transform: translateY(calc(-50% + var(--shift))) scale(0.98);
141
277
  transform-origin: right center;
142
278
  }
143
279
 
144
280
  .ss-tooltip[data-placement=left] .tip.open {
145
- transform: translateY(-50%) scale(1);
281
+ transform: translateY(calc(-50% + var(--shift))) scale(1);
146
282
  }
147
283
 
148
284
  .ss-tooltip[data-placement=right] .tip {
149
285
  left: calc(100% + var(--ss-tooltip-offset, 6px));
150
286
  top: 50%;
151
- transform: translateY(-50%) scale(0.98);
287
+ transform: translateY(calc(-50% + var(--shift))) scale(0.98);
152
288
  transform-origin: left center;
153
289
  }
154
290
 
155
291
  .ss-tooltip[data-placement=right] .tip.open {
156
- transform: translateY(-50%) scale(1);
292
+ transform: translateY(calc(-50% + var(--shift))) scale(1);
157
293
  }
158
294
 
159
295
  @media (prefers-reduced-motion: reduce) {
@@ -166,12 +302,12 @@
166
302
  .ss-tooltip[data-placement=top] .tip.open,
167
303
  .ss-tooltip[data-placement=bottom] .tip,
168
304
  .ss-tooltip[data-placement=bottom] .tip.open {
169
- transform: translateX(-50%);
305
+ transform: translateX(calc(-50% + var(--shift)));
170
306
  }
171
307
  .ss-tooltip[data-placement=left] .tip,
172
308
  .ss-tooltip[data-placement=left] .tip.open,
173
309
  .ss-tooltip[data-placement=right] .tip,
174
310
  .ss-tooltip[data-placement=right] .tip.open {
175
- transform: translateY(-50%);
311
+ transform: translateY(calc(-50% + var(--shift)));
176
312
  }
177
313
  }</style>
@@ -11,8 +11,18 @@ interface Props {
11
11
  * WAI-ARIA tooltip pattern.
12
12
  */
13
13
  text: string | Snippet;
14
- /** Where the tooltip attaches relative to the trigger. Default `top`. */
14
+ /**
15
+ * Preferred side the tooltip attaches to relative to the trigger. Default `top`.
16
+ * With `avoidCollisions` (the default) this is only a preference — see below.
17
+ */
15
18
  placement?: Placement;
19
+ /**
20
+ * Keep the tip visible when the preferred side has no room (DS-0146): flip to the
21
+ * opposite side, then to the perpendicular side with the most room, then shift along
22
+ * the cross axis so the tip never overhangs the viewport or an `overflow`-clipping
23
+ * ancestor. `false` pins the tip to `placement`. Default `true`.
24
+ */
25
+ avoidCollisions?: boolean;
16
26
  /** Token size (sm|md|lg); inherits the global size when unset. */
17
27
  size?: Size;
18
28
  /** Trigger content (wrapped in an inline-block container). */