dssoca 0.21.0 → 0.22.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.
@@ -3,14 +3,21 @@
3
3
  // Popover — DS-0197. A non-modal floating panel anchored to a trigger button:
4
4
  // Menu's sibling for arbitrary content (filters, a short form, details).
5
5
  // Opening moves focus into the panel; Escape, an outside press or tabbing out
6
- // dismiss it. Every decision is made in `core/popover.ts`, shared with
7
- // vanilla/popover.ts. Placement is CSS-only (side / align), like Menu.
6
+ // dismiss it. `openOn="hover"` makes it a hover card (DS-0206): hover or focus
7
+ // peeks it open without moving focus, a press runs `onactivate`. Every
8
+ // decision is made in `core/popover.ts`, shared with vanilla/popover.ts.
9
+ // Placement is side / align, kept inside the viewport by `avoidCollisions`.
8
10
  // ─────────────────────────────────────────────────────────────────────────
9
- import { untrack, type Snippet } from 'svelte'
11
+ import { tick, untrack, type Snippet } from 'svelte'
10
12
  import { resolveComponentSize, type Size } from '../config.js'
11
13
  import { focusPopoverPanel } from '../vanilla/popover.js'
12
14
  import {
15
+ POPOVER_HOVER_CLOSE_DELAY,
16
+ POPOVER_HOVER_OPEN_DELAY,
17
+ popoverFocusIn,
13
18
  popoverFocusOut,
19
+ popoverHoverEnter,
20
+ popoverHoverLeave,
14
21
  popoverKey,
15
22
  popoverOutsidePress,
16
23
  popoverPanelAttrs,
@@ -18,6 +25,7 @@
18
25
  popoverTriggerPress,
19
26
  type PopoverAction,
20
27
  type PopoverOpenChangeDetails,
28
+ type PopoverOpenOn,
21
29
  type PopoverState,
22
30
  } from '../core/popover.js'
23
31
 
@@ -33,9 +41,28 @@
33
41
  open?: boolean
34
42
  /**
35
43
  * Fired when the popover opens or closes itself, with the new state and why
36
- * (`details.reason`: trigger · escape · outside · tab).
44
+ * (`details.reason`: trigger · escape · outside · tab, plus hover · focus · leave in
45
+ * hover mode).
37
46
  */
38
47
  onOpenChange?: (open: boolean, details: PopoverOpenChangeDetails) => void
48
+ /**
49
+ * What opens the panel. `press` (default): the trigger toggles it and focus moves in.
50
+ * `hover`: a hover card — hovering or focusing the trigger shows it without moving focus,
51
+ * the pointer can travel onto the panel, leaving both closes it; a touch tap shows it.
52
+ */
53
+ openOn?: PopoverOpenOn
54
+ /**
55
+ * Hover mode only: the trigger's own action, run when it is pressed (a click, Enter /
56
+ * Space, or a second tap on touch) — e.g. open a details view. Without it a press
57
+ * toggles the card.
58
+ */
59
+ onactivate?: (e: MouseEvent) => void
60
+ /**
61
+ * Keep the panel inside the viewport: flip to the other side / edge when the preferred
62
+ * one has no room, then shift along the inline axis. `false` pins `side` / `align`.
63
+ * Default `true`.
64
+ */
65
+ avoidCollisions?: boolean
39
66
  /** Vertical side the panel opens toward. */
40
67
  side?: Side
41
68
  /** Horizontal edge the panel aligns to. */
@@ -56,6 +83,9 @@
56
83
  let {
57
84
  open = $bindable(false),
58
85
  onOpenChange,
86
+ openOn = 'press',
87
+ onactivate,
88
+ avoidCollisions = true,
59
89
  side = 'bottom',
60
90
  align = 'start',
61
91
  label,
@@ -76,18 +106,120 @@
76
106
  // a PopoverAction comes out, and `run` applies it to this component's state.
77
107
  const popover = $derived<PopoverState>({ open })
78
108
 
79
- function run(action: PopoverAction | null) {
109
+ // A `peek` opens without moving focus (hover mode); a returned focus must not
110
+ // re-peek the card through the trigger's focusin.
111
+ let focusOnOpen = true
112
+ let quietFocus = false
113
+
114
+ function run(action: PopoverAction | null, e?: MouseEvent) {
80
115
  if (!action) return
81
- if (action.type === 'open') {
116
+ clearTimers()
117
+ if (action.type === 'activate') {
118
+ if (e) onactivate?.(e)
119
+ } else if (action.type === 'open' || action.type === 'peek') {
120
+ focusOnOpen = action.type === 'open'
82
121
  open = true
83
122
  onOpenChange?.(true, { reason: action.reason })
84
123
  } else {
85
124
  open = false
86
125
  onOpenChange?.(false, { reason: action.reason })
87
- if (action.returnFocus) triggerEl?.focus()
126
+ if (action.returnFocus) {
127
+ quietFocus = true
128
+ triggerEl?.focus()
129
+ quietFocus = false
130
+ }
88
131
  }
89
132
  }
90
133
 
134
+ // --- hover mode -------------------------------------------------------------
135
+ let openTimer: ReturnType<typeof setTimeout> | undefined
136
+ let closeTimer: ReturnType<typeof setTimeout> | undefined
137
+ function clearTimers() {
138
+ clearTimeout(openTimer)
139
+ clearTimeout(closeTimer)
140
+ }
141
+ $effect(() => clearTimers)
142
+
143
+ function onPointerEnter(e: PointerEvent) {
144
+ if (openOn !== 'hover' || e.pointerType !== 'mouse') return
145
+ clearTimeout(closeTimer)
146
+ if (open) return
147
+ openTimer = setTimeout(() => run(popoverHoverEnter(popover)), POPOVER_HOVER_OPEN_DELAY)
148
+ }
149
+ function onPointerLeave(e: PointerEvent) {
150
+ if (openOn !== 'hover' || e.pointerType !== 'mouse') return
151
+ clearTimeout(openTimer)
152
+ closeTimer = setTimeout(() => run(popoverHoverLeave(popover)), POPOVER_HOVER_CLOSE_DELAY)
153
+ }
154
+ function onFocusIn(e: FocusEvent) {
155
+ if (quietFocus || e.target !== triggerEl) return
156
+ run(popoverFocusIn(popover, openOn))
157
+ }
158
+
159
+ // The pointer type of the press that becomes the next click ('' = keyboard).
160
+ // Listened on the trigger itself: a Svelte `onpointerdown` attribute would be
161
+ // delegated to the document, which must stay listener-free while closed.
162
+ let pressType = ''
163
+ $effect(() => {
164
+ const el = triggerEl
165
+ if (!el) return
166
+ const onDown = (e: PointerEvent) => (pressType = e.pointerType)
167
+ el.addEventListener('pointerdown', onDown)
168
+ return () => el.removeEventListener('pointerdown', onDown)
169
+ })
170
+ function onTriggerClick(e: MouseEvent) {
171
+ const action = popoverTriggerPress(popover, {
172
+ openOn,
173
+ pointerType: pressType,
174
+ hasAction: Boolean(onactivate),
175
+ })
176
+ pressType = ''
177
+ run(action, e)
178
+ }
179
+
180
+ // --- collision avoidance ------------------------------------------------------
181
+ // Measured when the panel opens: flip side / align toward the room, then shift
182
+ // along the inline axis so the panel never overhangs the viewport.
183
+ let flippedSide = $state<Side | null>(null)
184
+ let flippedAlign = $state<Align | null>(null)
185
+ let shift = $state(0)
186
+ const resolvedSide = $derived(flippedSide ?? side)
187
+ const resolvedAlign = $derived(flippedAlign ?? align)
188
+ const VIEWPORT_MARGIN = 8
189
+
190
+ async function place() {
191
+ flippedSide = null
192
+ flippedAlign = null
193
+ shift = 0
194
+ if (!avoidCollisions || !rootEl || !panelEl || typeof window === 'undefined') return
195
+ const r = rootEl.getBoundingClientRect()
196
+ const w = panelEl.offsetWidth
197
+ const h = panelEl.offsetHeight
198
+ const vw = window.innerWidth
199
+ const vh = window.innerHeight
200
+ const below = vh - r.bottom
201
+ const above = r.top
202
+ if (side === 'bottom' && below < h + VIEWPORT_MARGIN && above > below) flippedSide = 'top'
203
+ if (side === 'top' && above < h + VIEWPORT_MARGIN && below > above) flippedSide = 'bottom'
204
+ const rtl = getComputedStyle(rootEl).direction === 'rtl'
205
+ // Physical left edge of the panel for an inline alignment.
206
+ const leftFor = (a: Align) => ((a === 'start') !== rtl ? r.left : r.right - w)
207
+ const fits = (left: number) => left >= VIEWPORT_MARGIN && left + w <= vw - VIEWPORT_MARGIN
208
+ let a: Align = align
209
+ if (!fits(leftFor(a))) {
210
+ const other: Align = a === 'start' ? 'end' : 'start'
211
+ if (fits(leftFor(other))) {
212
+ a = other
213
+ flippedAlign = other
214
+ }
215
+ }
216
+ const left = leftFor(a)
217
+ const min = VIEWPORT_MARGIN
218
+ const max = vw - VIEWPORT_MARGIN - w
219
+ shift = left < min ? min - left : left > max ? Math.max(min, max) - left : 0
220
+ await tick()
221
+ }
222
+
91
223
  // Opening moves focus into the panel: its first focusable element, else the panel itself
92
224
  // (`focusPopoverPanel`, shared with the vanilla path, which also covers content that is not
93
225
  // focusable on the first frame). Runs after the DOM reflects `open` (the closed panel is inert), for an open the component
@@ -96,7 +228,11 @@
96
228
  let wasOpen = untrack(() => open)
97
229
  $effect(() => {
98
230
  const isOpen = open
99
- if (isOpen && !wasOpen && panelEl) focusPopoverPanel(panelEl)
231
+ if (isOpen && !wasOpen && panelEl) {
232
+ untrack(() => place())
233
+ if (focusOnOpen) focusPopoverPanel(panelEl)
234
+ }
235
+ focusOnOpen = true
100
236
  wasOpen = isOpen
101
237
  })
102
238
 
@@ -137,10 +273,14 @@
137
273
  bind:this={rootEl}
138
274
  class="ss-popover"
139
275
  data-size-variant={sizeAttr}
140
- data-align={align}
141
- data-side={side}
276
+ data-align={resolvedAlign}
277
+ data-side={resolvedSide}
278
+ data-open-on={openOn}
142
279
  onkeydown={onKeydown}
280
+ onfocusin={onFocusIn}
143
281
  onfocusout={onFocusOut}
282
+ onpointerenter={onPointerEnter}
283
+ onpointerleave={onPointerLeave}
144
284
  >
145
285
  <button
146
286
  bind:this={triggerEl}
@@ -149,7 +289,7 @@
149
289
  class="trigger"
150
290
  {...popoverTriggerAttrs(open)}
151
291
  aria-controls={panelId}
152
- onclick={() => run(popoverTriggerPress(popover))}
292
+ onclick={onTriggerClick}
153
293
  >
154
294
  {@render trigger?.()}
155
295
  </button>
@@ -163,6 +303,7 @@
163
303
  aria-labelledby={label ? undefined : triggerId}
164
304
  {...popoverPanelAttrs()}
165
305
  inert={!open || undefined}
306
+ style:--ss-popover-shift={shift ? `${shift}px` : undefined}
166
307
  >
167
308
  {@render children?.()}
168
309
  </div>
@@ -207,6 +348,7 @@
207
348
  background: var(--ss-bg-elev);
208
349
  border: 1px solid var(--ss-line);
209
350
  box-shadow: var(--ss-shadow-pop);
351
+ translate: var(--ss-popover-shift, 0px) 0;
210
352
  opacity: 0;
211
353
  visibility: hidden;
212
354
  pointer-events: none;
@@ -244,4 +386,19 @@
244
386
 
245
387
  .ss-popover[data-align=end] .panel {
246
388
  inset-inline-end: 0;
389
+ }
390
+
391
+ .ss-popover[data-open-on=hover] .panel.open::before {
392
+ content: "";
393
+ position: absolute;
394
+ inset-inline: 0;
395
+ height: var(--ss-popover-offset);
396
+ }
397
+
398
+ .ss-popover[data-open-on=hover][data-side=bottom] .panel.open::before {
399
+ bottom: 100%;
400
+ }
401
+
402
+ .ss-popover[data-open-on=hover][data-side=top] .panel.open::before {
403
+ top: 100%;
247
404
  }</style>
@@ -1,6 +1,6 @@
1
1
  import { type Snippet } from 'svelte';
2
2
  import { type Size } from '../config.js';
3
- import { type PopoverOpenChangeDetails } from '../core/popover.js';
3
+ import { type PopoverOpenChangeDetails, type PopoverOpenOn } from '../core/popover.js';
4
4
  /** Where the panel attaches relative to the trigger. */
5
5
  type Align = 'start' | 'end';
6
6
  type Side = 'bottom' | 'top';
@@ -12,9 +12,28 @@ interface Props {
12
12
  open?: boolean;
13
13
  /**
14
14
  * Fired when the popover opens or closes itself, with the new state and why
15
- * (`details.reason`: trigger · escape · outside · tab).
15
+ * (`details.reason`: trigger · escape · outside · tab, plus hover · focus · leave in
16
+ * hover mode).
16
17
  */
17
18
  onOpenChange?: (open: boolean, details: PopoverOpenChangeDetails) => void;
19
+ /**
20
+ * What opens the panel. `press` (default): the trigger toggles it and focus moves in.
21
+ * `hover`: a hover card — hovering or focusing the trigger shows it without moving focus,
22
+ * the pointer can travel onto the panel, leaving both closes it; a touch tap shows it.
23
+ */
24
+ openOn?: PopoverOpenOn;
25
+ /**
26
+ * Hover mode only: the trigger's own action, run when it is pressed (a click, Enter /
27
+ * Space, or a second tap on touch) — e.g. open a details view. Without it a press
28
+ * toggles the card.
29
+ */
30
+ onactivate?: (e: MouseEvent) => void;
31
+ /**
32
+ * Keep the panel inside the viewport: flip to the other side / edge when the preferred
33
+ * one has no room, then shift along the inline axis. `false` pins `side` / `align`.
34
+ * Default `true`.
35
+ */
36
+ avoidCollisions?: boolean;
18
37
  /** Vertical side the panel opens toward. */
19
38
  side?: Side;
20
39
  /** Horizontal edge the panel aligns to. */
@@ -388,6 +388,7 @@
388
388
  onkeydown={(e) => onTileKeydown(e, item)}
389
389
  onblur={() => onTileBlur(item)}
390
390
  onpointerdown={(e) => onPointerDown(e, item)}
391
+ ondragstart={(e) => e.preventDefault()}
391
392
  onclick={() => onTileClick(item)}
392
393
  >
393
394
  {@render tileBody(item)}
@@ -540,6 +541,8 @@
540
541
  width: 100%;
541
542
  height: 100%;
542
543
  object-fit: cover;
544
+ pointer-events: none;
545
+ -webkit-user-drag: none;
543
546
  }
544
547
  .ss-tierlist .name {
545
548
  padding: var(--ss-s-1);
@@ -4,8 +4,21 @@
4
4
  * {@link PopoverAction} comes out, and the caller applies it (Popover.svelte to its `$state`,
5
5
  * `vanilla/popover.ts` to the DOM). No DOM, no Svelte. Sibling of `menu.ts`.
6
6
  */
7
- /** Why the popover opened or closed; passed to `onOpenChange` / `ss:openchange`. */
8
- export type PopoverReason = 'trigger' | 'escape' | 'outside' | 'tab';
7
+ /**
8
+ * Why the popover opened or closed; passed to `onOpenChange` / `ss:openchange`. `hover`,
9
+ * `focus` and `leave` only occur with `openOn: 'hover'` (DS-0206).
10
+ */
11
+ export type PopoverReason = 'trigger' | 'escape' | 'outside' | 'tab' | 'hover' | 'focus' | 'leave';
12
+ /**
13
+ * What opens the panel. `press` (default): the trigger toggles it and opening moves focus in.
14
+ * `hover`: a hover card — pointer hover or keyboard focus on the trigger *peeks* it open
15
+ * without moving focus, the pointer may travel onto the panel, and leaving both closes it
16
+ * after a grace period; a press on the trigger *activates* it instead (DS-0206).
17
+ */
18
+ export type PopoverOpenOn = 'press' | 'hover';
19
+ /** Hover-mode timing (ms): a short intent delay before opening, a grace period before closing. */
20
+ export declare const POPOVER_HOVER_OPEN_DELAY = 100;
21
+ export declare const POPOVER_HOVER_CLOSE_DELAY = 150;
9
22
  export interface PopoverOpenChangeDetails {
10
23
  reason: PopoverReason;
11
24
  }
@@ -17,10 +30,19 @@ export type PopoverAction =
17
30
  {
18
31
  type: 'open';
19
32
  reason: PopoverReason;
33
+ }
34
+ /** Show the panel and leave focus where it is (hover mode: hover, focus, a touch tap). */
35
+ | {
36
+ type: 'peek';
37
+ reason: PopoverReason;
20
38
  } | {
21
39
  type: 'close';
22
40
  returnFocus: boolean;
23
41
  reason: PopoverReason;
42
+ }
43
+ /** Hover mode: the trigger was pressed — run the trigger's own action (`onactivate`). */
44
+ | {
45
+ type: 'activate';
24
46
  };
25
47
  /** A key the popover handles: its action, and whether the browser default must be cancelled. */
26
48
  export interface PopoverKeyResult {
@@ -37,8 +59,29 @@ export type PopoverFocusTarget = 'inside' | 'outside' | 'nowhere';
37
59
  export declare function popoverOpen(state: PopoverState): PopoverAction | null;
38
60
  /** Close from code (`closePopover`). */
39
61
  export declare function popoverClose(state: PopoverState, returnFocus?: boolean): PopoverAction | null;
40
- /** The trigger was pressed: toggle. */
41
- export declare function popoverTriggerPress(state: PopoverState): PopoverAction | null;
62
+ /** How a hover-mode press arrived, for {@link popoverTriggerPress}. */
63
+ export interface PopoverPressOptions {
64
+ openOn?: PopoverOpenOn;
65
+ /** `PointerEvent.pointerType` of the press, or `''` for a keyboard click. */
66
+ pointerType?: string;
67
+ /** The trigger has its own action (`onactivate` / an `ss:activate` listener). */
68
+ hasAction?: boolean;
69
+ }
70
+ /**
71
+ * The trigger was pressed. Press mode: toggle. Hover mode: a touch or pen tap on a closed card
72
+ * peeks it open (there is no hover to do it); otherwise the press activates the trigger's own
73
+ * action when it has one, and toggles the card (without moving focus) when it does not.
74
+ */
75
+ export declare function popoverTriggerPress(state: PopoverState, options?: PopoverPressOptions): PopoverAction | null;
76
+ /** Hover mode: the pointer rested on the trigger or the panel (after the open delay). */
77
+ export declare function popoverHoverEnter(state: PopoverState): PopoverAction | null;
78
+ /** Hover mode: the pointer left the trigger and the panel (after the close grace period). */
79
+ export declare function popoverHoverLeave(state: PopoverState): PopoverAction | null;
80
+ /**
81
+ * Focus arrived on the trigger. Hover mode peeks the card open so keyboard users get what a
82
+ * hover shows; Tab then moves on into the panel. Press mode ignores it.
83
+ */
84
+ export declare function popoverFocusIn(state: PopoverState, openOn?: PopoverOpenOn): PopoverAction | null;
42
85
  /**
43
86
  * A key anywhere in the popover (trigger or panel). Escape closes an open popover and hands
44
87
  * focus back to the trigger. `null` = not a popover key (or nothing to close): let it through,
@@ -4,6 +4,9 @@
4
4
  * {@link PopoverAction} comes out, and the caller applies it (Popover.svelte to its `$state`,
5
5
  * `vanilla/popover.ts` to the DOM). No DOM, no Svelte. Sibling of `menu.ts`.
6
6
  */
7
+ /** Hover-mode timing (ms): a short intent delay before opening, a grace period before closing. */
8
+ export const POPOVER_HOVER_OPEN_DELAY = 100;
9
+ export const POPOVER_HOVER_CLOSE_DELAY = 150;
7
10
  const open = (state, reason) => state.open ? null : { type: 'open', reason };
8
11
  const close = (state, returnFocus, reason) => (state.open ? { type: 'close', returnFocus, reason } : null);
9
12
  /** Open from code (`openPopover`). */
@@ -14,9 +17,37 @@ export function popoverOpen(state) {
14
17
  export function popoverClose(state, returnFocus = true) {
15
18
  return close(state, returnFocus, 'trigger');
16
19
  }
17
- /** The trigger was pressed: toggle. */
18
- export function popoverTriggerPress(state) {
19
- return state.open ? close(state, true, 'trigger') : open(state, 'trigger');
20
+ const peek = (state, reason) => state.open ? null : { type: 'peek', reason };
21
+ /**
22
+ * The trigger was pressed. Press mode: toggle. Hover mode: a touch or pen tap on a closed card
23
+ * peeks it open (there is no hover to do it); otherwise the press activates the trigger's own
24
+ * action when it has one, and toggles the card (without moving focus) when it does not.
25
+ */
26
+ export function popoverTriggerPress(state, options = {}) {
27
+ if (options.openOn !== 'hover') {
28
+ return state.open ? close(state, true, 'trigger') : open(state, 'trigger');
29
+ }
30
+ const touch = options.pointerType === 'touch' || options.pointerType === 'pen';
31
+ if (touch && !state.open)
32
+ return peek(state, 'trigger');
33
+ if (options.hasAction)
34
+ return { type: 'activate' };
35
+ return state.open ? close(state, false, 'trigger') : peek(state, 'trigger');
36
+ }
37
+ /** Hover mode: the pointer rested on the trigger or the panel (after the open delay). */
38
+ export function popoverHoverEnter(state) {
39
+ return peek(state, 'hover');
40
+ }
41
+ /** Hover mode: the pointer left the trigger and the panel (after the close grace period). */
42
+ export function popoverHoverLeave(state) {
43
+ return close(state, false, 'leave');
44
+ }
45
+ /**
46
+ * Focus arrived on the trigger. Hover mode peeks the card open so keyboard users get what a
47
+ * hover shows; Tab then moves on into the panel. Press mode ignores it.
48
+ */
49
+ export function popoverFocusIn(state, openOn = 'press') {
50
+ return openOn === 'hover' ? peek(state, 'focus') : null;
20
51
  }
21
52
  /**
22
53
  * A key anywhere in the popover (trigger or panel). Escape closes an open popover and hands
package/dist/index.d.ts CHANGED
@@ -60,7 +60,7 @@ export { default as RadioGroup, type RadioOption } from './components/RadioGroup
60
60
  export { default as Tabs, type TabItem } from './components/Tabs.svelte';
61
61
  export type { TabsReason, TabsActivation, TabsChangeDetails } from './core/tabs.js';
62
62
  export { default as Popover } from './components/Popover.svelte';
63
- export type { PopoverReason, PopoverOpenChangeDetails } from './core/popover.js';
63
+ export type { PopoverReason, PopoverOpenChangeDetails, PopoverOpenOn } from './core/popover.js';
64
64
  export { default as Kbd } from './components/Kbd.svelte';
65
65
  export { default as ShortcutsHelp } from './components/ShortcutsHelp.svelte';
66
66
  export { shortcuts, shortcut, formatShortcut, ariaKeyshortcuts, type ShortcutOptions, type ShortcutInfo, type ShortcutOverride, type ShortcutOverrides, type ShortcutScope, type ShortcutPlatform, type ShortcutFormat, type FormatShortcutOptions, } from './shortcuts.svelte.js';
@@ -8,10 +8,16 @@
8
8
  * closed panel is `inert`. Emits `ss:openchange` on the root with `{ open, reason }`. A panel
9
9
  * with neither `aria-label` nor `aria-labelledby` gets `aria-labelledby` pointing at its
10
10
  * trigger on first open (an id is minted if needed).
11
+ *
12
+ * Hover mode (DS-0206): `data-open-on="hover"` on the root makes it a hover card — a mouse
13
+ * resting on the trigger or panel, or focus on the trigger, peeks it open without moving focus;
14
+ * leaving closes it after a grace period; a touch tap peeks it. A press on the trigger emits
15
+ * `ss:activate` on the root when the root carries `data-ss-activate`, and toggles otherwise.
16
+ * (No collision avoidance on this path, as with Tooltip.)
11
17
  */
12
18
  import { on, emit, all, setAttrs } from './delegate.js';
13
19
  import { FOCUSABLE_SELECTOR } from '../core/behaviors/focusable.js';
14
- import { popoverClose, popoverFocusOut, popoverKey, popoverOpen, popoverOutsidePress, popoverPanelAttrs, popoverTriggerAttrs, popoverTriggerPress, } from '../core/popover.js';
20
+ import { POPOVER_HOVER_CLOSE_DELAY, POPOVER_HOVER_OPEN_DELAY, popoverClose, popoverFocusIn, popoverFocusOut, popoverHoverEnter, popoverHoverLeave, popoverKey, popoverOpen, popoverOutsidePress, popoverPanelAttrs, popoverTriggerAttrs, popoverTriggerPress, } from '../core/popover.js';
15
21
  const TRIGGER = '.ss-popover > .trigger';
16
22
  const OPEN_TRIGGER = `${TRIGGER}[aria-expanded="true"]`;
17
23
  function parts(el) {
@@ -55,12 +61,25 @@ export function focusPopoverPanel(panel) {
55
61
  };
56
62
  attempt();
57
63
  }
64
+ const openOnOf = (root) => root.dataset.openOn === 'hover' ? 'hover' : 'press';
65
+ // A trigger getting focus back from Escape must not re-peek its card.
66
+ let quietFocus = false;
67
+ const timers = new WeakMap();
68
+ function clearTimer(root) {
69
+ clearTimeout(timers.get(root));
70
+ timers.delete(root);
71
+ }
58
72
  /** Apply a core action to the DOM. */
59
73
  function run(p, action) {
60
74
  if (!action)
61
75
  return;
62
76
  const { root, trigger, panel } = p;
63
- const open = action.type === 'open';
77
+ clearTimer(root);
78
+ if (action.type === 'activate') {
79
+ emit(root, 'ss:activate', {});
80
+ return;
81
+ }
82
+ const open = action.type === 'open' || action.type === 'peek';
64
83
  if (open)
65
84
  ensureName(trigger, panel);
66
85
  setAttrs(trigger, popoverTriggerAttrs(open));
@@ -71,8 +90,10 @@ function run(p, action) {
71
90
  if (action.type === 'open') {
72
91
  queueMicrotask(() => focusPopoverPanel(panel));
73
92
  }
74
- else if (action.returnFocus) {
93
+ else if (action.type === 'close' && action.returnFocus) {
94
+ quietFocus = true;
75
95
  trigger.focus();
96
+ quietFocus = false;
76
97
  }
77
98
  }
78
99
  export function openPopover(trigger) {
@@ -92,10 +113,59 @@ function openPopovers() {
92
113
  .filter((p) => p !== null);
93
114
  }
94
115
  export function installPopover() {
116
+ // The pointer type of the press that becomes the next click ('' = keyboard).
117
+ let pressType = '';
118
+ document.addEventListener('pointerdown', (e) => (pressType = e.pointerType), true);
95
119
  on('click', TRIGGER, (trigger) => {
96
120
  const p = parts(trigger);
121
+ if (!p)
122
+ return;
123
+ const action = popoverTriggerPress(read(p), {
124
+ openOn: openOnOf(p.root),
125
+ pointerType: pressType,
126
+ hasAction: p.root.hasAttribute('data-ss-activate'),
127
+ });
128
+ pressType = '';
129
+ run(p, action);
130
+ });
131
+ // Hover mode: pointerover/out stand in for enter/leave (they bubble, so delegation
132
+ // works); moves between the trigger and the panel stay inside the root and are ignored.
133
+ const HOVER_ROOT = '.ss-popover[data-open-on="hover"]';
134
+ document.addEventListener('pointerover', (e) => {
135
+ if (e.pointerType !== 'mouse')
136
+ return;
137
+ const root = e.target?.closest(HOVER_ROOT);
138
+ if (!root || root.contains(e.relatedTarget))
139
+ return;
140
+ const p = parts(root);
141
+ if (!p)
142
+ return;
143
+ clearTimer(root);
144
+ if (read(p).open)
145
+ return;
146
+ timers.set(root, setTimeout(() => run(p, popoverHoverEnter(read(p))), POPOVER_HOVER_OPEN_DELAY));
147
+ });
148
+ document.addEventListener('pointerout', (e) => {
149
+ if (e.pointerType !== 'mouse')
150
+ return;
151
+ const root = e.target?.closest(HOVER_ROOT);
152
+ if (!root || root.contains(e.relatedTarget))
153
+ return;
154
+ const p = parts(root);
155
+ if (!p)
156
+ return;
157
+ clearTimer(root);
158
+ timers.set(root, setTimeout(() => run(p, popoverHoverLeave(read(p))), POPOVER_HOVER_CLOSE_DELAY));
159
+ });
160
+ document.addEventListener('focusin', (e) => {
161
+ if (quietFocus)
162
+ return;
163
+ const t = e.target;
164
+ if (!t?.matches(TRIGGER))
165
+ return;
166
+ const p = parts(t);
97
167
  if (p)
98
- run(p, popoverTriggerPress(read(p)));
168
+ run(p, popoverFocusIn(read(p), openOnOf(p.root)));
99
169
  });
100
170
  on('keydown', '.ss-popover', (root, e) => {
101
171
  // Something inside (a nested menu, say) already used this key.
@@ -249,6 +249,9 @@ export function installTierlist() {
249
249
  cancelGrab(root, false);
250
250
  }, 0);
251
251
  });
252
+ // A native drag (an <img> inside the tile) would fire pointercancel and kill the
253
+ // pointer drag — the tile moves by pointer events only (DS-0207).
254
+ on('dragstart', TILE, (_tile, e) => e.preventDefault());
252
255
  on('pointerdown', TILE, (tile, e) => {
253
256
  const root = rootOf(tile);
254
257
  if (!root)
package/dist/vanilla.css CHANGED
@@ -2835,6 +2835,7 @@
2835
2835
  background: var(--ss-bg-elev);
2836
2836
  border: 1px solid var(--ss-line);
2837
2837
  box-shadow: var(--ss-shadow-pop);
2838
+ translate: var(--ss-popover-shift, 0px) 0;
2838
2839
  opacity: 0;
2839
2840
  visibility: hidden;
2840
2841
  pointer-events: none;
@@ -2868,6 +2869,18 @@
2868
2869
  :where(:scope).ss-popover[data-align=end] .panel {
2869
2870
  inset-inline-end: 0;
2870
2871
  }
2872
+ :where(:scope).ss-popover[data-open-on=hover] .panel.open::before {
2873
+ content: "";
2874
+ position: absolute;
2875
+ inset-inline: 0;
2876
+ height: var(--ss-popover-offset);
2877
+ }
2878
+ :where(:scope).ss-popover[data-open-on=hover][data-side=bottom] .panel.open::before {
2879
+ bottom: 100%;
2880
+ }
2881
+ :where(:scope).ss-popover[data-open-on=hover][data-side=top] .panel.open::before {
2882
+ top: 100%;
2883
+ }
2871
2884
  }
2872
2885
  /* ── RadioGroup ── */
2873
2886
  @scope (.ss-radio-group) to (.ss-accordion, .ss-avatar, .ss-badge, .ss-bottom-nav, .ss-boxplot, .ss-bump, .ss-btn, .ss-card, .ss-chart, .ss-checkbox, .ss-container, .ss-datefield, .ss-empty, .ss-filedrop, .ss-heading, .ss-heatmap, .ss-icon, .ss-image, .ss-image-lightbox, .ss-field, .ss-kbd, .ss-link, .ss-logs, .ss-menu, .ss-metric, .ss-modal, .ss-numberfield, .ss-pagination, .ss-popover, .ss-scatter, .ss-search-palette, .ss-segmented, .ss-select, .ss-svc, .ss-shortcuts-help, .ss-side, .ss-spark, .ss-spinner, .ss-switch, .ss-table, .ss-tabs, .ss-textarea, .ss-tierlist, .ss-toaster, .ss-tooltip, .ss-topbar) {
@@ -4669,6 +4682,8 @@
4669
4682
  width: 100%;
4670
4683
  height: 100%;
4671
4684
  object-fit: cover;
4685
+ pointer-events: none;
4686
+ -webkit-user-drag: none;
4672
4687
  }
4673
4688
  /* ── Toaster ── */
4674
4689
  @keyframes ss-toast-spin {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dssoca",
3
- "version": "0.21.0",
3
+ "version": "0.22.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, size: sm/md/lg). Also consumable from plain HTML via vanilla.css + vanilla.js.",
5
5
  "license": "MIT",
6
6
  "author": "Rafael Passoca",