dssoca 0.14.0 → 0.16.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.
@@ -25,6 +25,14 @@
25
25
  title?: string
26
26
  /** Token size (sm|md|lg); controls max-width. Inherits the global size when unset. */
27
27
  size?: Size
28
+ /**
29
+ * Fill the viewport instead of rendering a centred, capped panel (DS-0145).
30
+ * The size axis no longer affects width, and — since the panel is full-bleed —
31
+ * there is no backdrop left to click, so `closeOnBackdrop` is unreachable:
32
+ * the close button and Esc are the exits. Drive responsiveness from the
33
+ * caller (`fullscreen={width < 640}`). @default false
34
+ */
35
+ fullscreen?: boolean
28
36
  /** Clicking the backdrop (outside the panel) closes the modal. @default true */
29
37
  closeOnBackdrop?: boolean
30
38
  /** Esc closes the modal. When false, Esc is swallowed (cancel prevented). @default true */
@@ -47,6 +55,7 @@
47
55
  open = $bindable(false),
48
56
  title,
49
57
  size,
58
+ fullscreen = false,
50
59
  closeOnBackdrop = true,
51
60
  closeOnEsc = true,
52
61
  danger = false,
@@ -97,6 +106,7 @@
97
106
  class="ss-modal"
98
107
  class:danger
99
108
  data-size-variant={resolveComponentSize('Modal', size)}
109
+ data-fullscreen={fullscreen ? '' : undefined}
100
110
  aria-labelledby={title ? titleId : undefined}
101
111
  aria-label={title ? undefined : ariaLabel}
102
112
  onclose={onDialogClose}
@@ -148,6 +158,20 @@
148
158
  .ss-modal[data-size-variant=lg] {
149
159
  --ss-modal-w: 48rem;
150
160
  }
161
+ .ss-modal[data-fullscreen] {
162
+ width: 100vw;
163
+ height: 100vh;
164
+ max-width: none;
165
+ max-height: none;
166
+ margin: 0;
167
+ border: 0;
168
+ }
169
+ @supports (height: 100dvh) {
170
+ .ss-modal[data-fullscreen] {
171
+ width: 100dvw;
172
+ height: 100dvh;
173
+ }
174
+ }
151
175
 
152
176
  .panel {
153
177
  display: flex;
@@ -155,6 +179,21 @@
155
179
  max-height: inherit;
156
180
  }
157
181
 
182
+ .ss-modal[data-fullscreen] .panel {
183
+ height: 100%;
184
+ max-height: none;
185
+ }
186
+
187
+ .ss-modal[data-fullscreen] .head,
188
+ .ss-modal[data-fullscreen] .foot {
189
+ flex: none;
190
+ }
191
+
192
+ .ss-modal[data-fullscreen] .body {
193
+ flex: 1 1 auto;
194
+ min-height: 0;
195
+ }
196
+
158
197
  .head {
159
198
  display: flex;
160
199
  align-items: center;
@@ -7,6 +7,14 @@ interface Props {
7
7
  title?: string;
8
8
  /** Token size (sm|md|lg); controls max-width. Inherits the global size when unset. */
9
9
  size?: Size;
10
+ /**
11
+ * Fill the viewport instead of rendering a centred, capped panel (DS-0145).
12
+ * The size axis no longer affects width, and — since the panel is full-bleed —
13
+ * there is no backdrop left to click, so `closeOnBackdrop` is unreachable:
14
+ * the close button and Esc are the exits. Drive responsiveness from the
15
+ * caller (`fullscreen={width < 640}`). @default false
16
+ */
17
+ fullscreen?: boolean;
10
18
  /** Clicking the backdrop (outside the panel) closes the modal. @default true */
11
19
  closeOnBackdrop?: boolean;
12
20
  /** Esc closes the modal. When false, Esc is swallowed (cancel prevented). @default true */
@@ -6,21 +6,46 @@
6
6
  type Placement = 'top' | 'bottom' | 'left' | 'right'
7
7
 
8
8
  interface Props {
9
- /** Tooltip text (the accessible description of the trigger). */
10
- text: string
11
- /** Where the tooltip attaches relative to the trigger. Default `top`. */
9
+ /**
10
+ * Tooltip content (the accessible description of the trigger): a plain string, or a
11
+ * snippet for a small rendered template. Snippets must stay **phrasing content**
12
+ * (`code`, `strong`, `kbd`, `br`, `Icon`, …) and must not contain interactive
13
+ * elements — the tip is `pointer-events: none` and hidden while closed, per the
14
+ * WAI-ARIA tooltip pattern.
15
+ */
16
+ text: string | Snippet
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
+ */
12
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
13
29
  /** Token size (sm|md|lg); inherits the global size when unset. */
14
30
  size?: Size
15
31
  /** Trigger content (wrapped in an inline-block container). */
16
32
  children: Snippet
17
33
  }
18
34
 
19
- let { text, placement = 'top', size, children }: Props = $props()
35
+ let { text, placement = 'top', avoidCollisions = true, size, children }: Props = $props()
20
36
 
21
37
  const tipId = $props.id()
22
38
 
23
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)
24
49
 
25
50
  function show() {
26
51
  open = true
@@ -36,6 +61,113 @@
36
61
  }
37
62
 
38
63
  const sizeAttr = $derived(resolveComponentSize('Tooltip', size))
64
+
65
+ // Snippets are functions, so a runtime typeof check narrows the union.
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
+ })
39
171
  </script>
40
172
 
41
173
  <!--
@@ -44,6 +176,13 @@
44
176
  tooltip; Escape dismisses it. While open the wrapper carries aria-describedby
45
177
  pointing at the tooltip; the tip itself is kept in the DOM but hidden (and
46
178
  given `hidden`) when closed so it is never announced.
179
+
180
+ `text` is either a string or a snippet (DS-0144); a snippet renders inside the
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.
47
186
  -->
48
187
  <!-- svelte-ignore a11y_no_static_element_interactions -- the wrapper is a passive
49
188
  container; the real interactive element is the trigger snippet inside it, and the
@@ -51,7 +190,7 @@
51
190
  <span
52
191
  class="ss-tooltip"
53
192
  data-size-variant={sizeAttr}
54
- data-placement={placement}
193
+ data-placement={resolved}
55
194
  aria-describedby={open ? tipId : undefined}
56
195
  onmouseenter={show}
57
196
  onmouseleave={hide}
@@ -59,8 +198,18 @@
59
198
  onfocusout={hide}
60
199
  onkeydown={onKeydown}
61
200
  >
62
- <span class="trigger">{@render children()}</span>
63
- <span id={tipId} class="tip" class:open role="tooltip" hidden={!open}>{text}</span>
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
+ >
211
+ {#if tipSnippet}{@render tipSnippet()}{:else}{text}{/if}
212
+ </span>
64
213
  </span>
65
214
 
66
215
  <style>.ss-tooltip {
@@ -73,8 +222,10 @@
73
222
  }
74
223
 
75
224
  .tip {
225
+ --shift: 0px;
76
226
  position: absolute;
77
227
  z-index: 60;
228
+ display: block;
78
229
  width: max-content;
79
230
  max-width: var(--ss-tooltip-max-w, 240px);
80
231
  padding: var(--ss-tooltip-py, 4px) var(--ss-tooltip-px, 8px);
@@ -100,45 +251,45 @@
100
251
  .ss-tooltip[data-placement=top] .tip {
101
252
  bottom: calc(100% + var(--ss-tooltip-offset, 6px));
102
253
  left: 50%;
103
- transform: translateX(-50%) scale(0.98);
254
+ transform: translateX(calc(-50% + var(--shift))) scale(0.98);
104
255
  transform-origin: bottom center;
105
256
  }
106
257
 
107
258
  .ss-tooltip[data-placement=top] .tip.open {
108
- transform: translateX(-50%) scale(1);
259
+ transform: translateX(calc(-50% + var(--shift))) scale(1);
109
260
  }
110
261
 
111
262
  .ss-tooltip[data-placement=bottom] .tip {
112
263
  top: calc(100% + var(--ss-tooltip-offset, 6px));
113
264
  left: 50%;
114
- transform: translateX(-50%) scale(0.98);
265
+ transform: translateX(calc(-50% + var(--shift))) scale(0.98);
115
266
  transform-origin: top center;
116
267
  }
117
268
 
118
269
  .ss-tooltip[data-placement=bottom] .tip.open {
119
- transform: translateX(-50%) scale(1);
270
+ transform: translateX(calc(-50% + var(--shift))) scale(1);
120
271
  }
121
272
 
122
273
  .ss-tooltip[data-placement=left] .tip {
123
274
  right: calc(100% + var(--ss-tooltip-offset, 6px));
124
275
  top: 50%;
125
- transform: translateY(-50%) scale(0.98);
276
+ transform: translateY(calc(-50% + var(--shift))) scale(0.98);
126
277
  transform-origin: right center;
127
278
  }
128
279
 
129
280
  .ss-tooltip[data-placement=left] .tip.open {
130
- transform: translateY(-50%) scale(1);
281
+ transform: translateY(calc(-50% + var(--shift))) scale(1);
131
282
  }
132
283
 
133
284
  .ss-tooltip[data-placement=right] .tip {
134
285
  left: calc(100% + var(--ss-tooltip-offset, 6px));
135
286
  top: 50%;
136
- transform: translateY(-50%) scale(0.98);
287
+ transform: translateY(calc(-50% + var(--shift))) scale(0.98);
137
288
  transform-origin: left center;
138
289
  }
139
290
 
140
291
  .ss-tooltip[data-placement=right] .tip.open {
141
- transform: translateY(-50%) scale(1);
292
+ transform: translateY(calc(-50% + var(--shift))) scale(1);
142
293
  }
143
294
 
144
295
  @media (prefers-reduced-motion: reduce) {
@@ -151,12 +302,12 @@
151
302
  .ss-tooltip[data-placement=top] .tip.open,
152
303
  .ss-tooltip[data-placement=bottom] .tip,
153
304
  .ss-tooltip[data-placement=bottom] .tip.open {
154
- transform: translateX(-50%);
305
+ transform: translateX(calc(-50% + var(--shift)));
155
306
  }
156
307
  .ss-tooltip[data-placement=left] .tip,
157
308
  .ss-tooltip[data-placement=left] .tip.open,
158
309
  .ss-tooltip[data-placement=right] .tip,
159
310
  .ss-tooltip[data-placement=right] .tip.open {
160
- transform: translateY(-50%);
311
+ transform: translateY(calc(-50% + var(--shift)));
161
312
  }
162
313
  }</style>
@@ -3,10 +3,26 @@ import { type Size } from '../config.js';
3
3
  /** Side the tooltip attaches to relative to the trigger. */
4
4
  type Placement = 'top' | 'bottom' | 'left' | 'right';
5
5
  interface Props {
6
- /** Tooltip text (the accessible description of the trigger). */
7
- text: string;
8
- /** Where the tooltip attaches relative to the trigger. Default `top`. */
6
+ /**
7
+ * Tooltip content (the accessible description of the trigger): a plain string, or a
8
+ * snippet for a small rendered template. Snippets must stay **phrasing content**
9
+ * (`code`, `strong`, `kbd`, `br`, `Icon`, …) and must not contain interactive
10
+ * elements — the tip is `pointer-events: none` and hidden while closed, per the
11
+ * WAI-ARIA tooltip pattern.
12
+ */
13
+ text: string | Snippet;
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
+ */
9
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;
10
26
  /** Token size (sm|md|lg); inherits the global size when unset. */
11
27
  size?: Size;
12
28
  /** Trigger content (wrapped in an inline-block container). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dssoca",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "Svelte 5 design system — signal green on near-black, monospace-forward, zero border-radius; configured along two axes (color: dark/light, density: comfy/compact).",
5
5
  "license": "MIT",
6
6
  "author": "Rafael Passoca",