lostcoords-ui 0.14.11 → 0.14.13

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df62b2154bc5fe1c0561cc8f5a92db48a0dffdb2b6e73afce18ebeefaa5dd50a
4
- data.tar.gz: 986cb18b76430f68a676d6786c65f3c3c4483e23bf445cd3248702df46a3d282
3
+ metadata.gz: 729b5ab883cb06c1a4b067c3b0581b3743341a414dd18daf08c0af2b0a407eca
4
+ data.tar.gz: 1fbe2ad618bc983a2f3ad4b5d86a5bdf6c2481755ec81161351d762118b38a5c
5
5
  SHA512:
6
- metadata.gz: 03ae7326f876da302da67b0ee3f2c6edd98ca240cbe54ec9d7233e954e145593895616c2ac0d52fff637366b32cfa8a57ab01071719a3b7fb4744298335cb085
7
- data.tar.gz: 1e4c6fbccdf6b5a969a37588f1aed9eb4e0847b64e646d53b12d8b554f02301737353e6480e9546b8f2a6585af1273d8ec48e599165d04ab1d295d53e7d84d78
6
+ metadata.gz: ac70042419af37f4ea4b5a5bc6c5d9e835420ac953d8b8225b31a6fff792952cb9b4f54a58075152e2cab7f795f5a771dbea737417d2691efaa83925aa766173
7
+ data.tar.gz: 2cbf0a9ee9680c60c46bac6b88b82853308de0c36375b1b90b5d90bb4c26b22547c06d4740b1e015d71bdc71d4609770271181246c750496f0f3acfd00a6faa2
data/README.md CHANGED
@@ -57,7 +57,7 @@ app's theme and keep your Tailwind theme declarations after the imports.
57
57
  `core.css` holds the tokens, buttons, badges, avatars, cards, alerts, form controls, choices,
58
58
  toggles, layout, typography and navigation. The opt-in entries are `dialog` (with the phone sheet),
59
59
  `menu` (menus and popovers), `toast`, `search`, `tooltip`, `hovercard`, `collapsible`, `code-block`,
60
- `emoji-picker`, `table`, `prose` and `shell` (`lc_app_header`, `lc_sidebar`, `lc_docs_shell` and `lc_dock`; the
60
+ `emoji-picker` (its phone sheet also needs `dialog`), `table`, `prose` and `shell` (`lc_app_header`, `lc_sidebar`, `lc_docs_shell` and `lc_dock`; the
61
61
  dock's action menu and the sidebar's account menu also need `menu`). A component whose entry is missing renders unstyled.
62
62
 
63
63
  The gem's stylesheets write into the `components` and `modules` layers, so the host declares that layer order.
@@ -170,6 +170,43 @@ Omit `only` to register every library controller. Unknown identifiers raise befo
170
170
  registered, and repeated calls on the same application keep later overrides, so register defaults
171
171
  before application overrides.
172
172
 
173
+ ## Changes in 0.14.13
174
+
175
+ Nothing needs an edit. Fixed:
176
+
177
+ - **Overlays animate out in Safari.** WebKit can't transition `overlay` or `display`, so a closing dialog,
178
+ phone sheet, menu, popover or tooltip left the screen in the frame it closed; a sheet released halfway
179
+ down vanished mid-slide. `lc-sheet` now holds a closing dialog in its exit pose (`[data-closing]`) until
180
+ the slide or fade ends, whether `close()`, Escape, the backdrop, a swipe or a `method="dialog"` form
181
+ closed it, and a lifted panel stays in the top layer, shown as it was, until its exit ends. Chrome keeps
182
+ its native exit. Where the exit is held, `close` fires when it ends; `lc-sheet:exit` fires as it starts,
183
+ and the confirm sheet answers then.
184
+ - **A sheet held still before lifting settles back.** It kept the finger's speed from before the pause,
185
+ so a slow drag, a pause and a lift could dismiss it.
186
+ - **A released sheet carries on at the finger's speed**, shortening its slide (to 240ms at least) instead
187
+ of always taking the full 500ms.
188
+
189
+ ## Changes in 0.14.12
190
+
191
+ Needs an edit only if you import component entries one by one: `emoji-picker` now also needs `dialog`,
192
+ which holds the phone sheet. Changed:
193
+
194
+ - **The emoji picker's phone sheet is the shared `lc-sheet`.** It had its own copy with tighter corners,
195
+ a darker backdrop and a faster slide; it now has the radius, scrim and timing of every other sheet.
196
+ - **`lc_list_field` rows are inset like the rows around them** from `sm` up (`px-inset`); they sat 4px
197
+ further out than `lc_list_row` and the section heading.
198
+ - **`lc_icon_button_class` defaults to `shape: :circle`**, as `lc_icon_button` does, so the compact
199
+ pager's arrows are round. Pass `shape: :square` to keep the old look.
200
+ - **The responsive nav's links and indicator are squircles from `sm` up**, like `layout: :row`. Being
201
+ pills on phones had switched the squircle off at every width.
202
+ - **Popovers, hovercards and the emoji popover take their timing from `--lc-motion-feedback`**; they
203
+ wrote the same 160ms as a literal.
204
+
205
+ Fixed:
206
+
207
+ - **An avatar in an `lc_avatar_stack` shows the focus ring.** The stack removed every avatar's outline,
208
+ including the ring of one rendered as a button.
209
+
173
210
  ## Changes in 0.14.11
174
211
 
175
212
  Nothing needs an edit. Changed:
@@ -1436,7 +1473,7 @@ Generated by `bin/rails lostcoords:ui:builders`; `bin/lint` checks this list aga
1436
1473
  - `lc_toggle_class(active: false, ghost: false, size: :md, extra: nil)` (BadgeHelper)
1437
1474
  - `lc_button_class(variant: :primary, tone: :default, size: :md, block: false, extra: nil)` (ButtonHelper)
1438
1475
  - `lc_select_trigger_class(size: :md, block: false, extra: nil)` (ButtonHelper)
1439
- - `lc_icon_button_class(shape: :square, size: :md, icon_size: size, variant: :ghost, tone: :default, extra: nil)` (ButtonHelper)
1476
+ - `lc_icon_button_class(shape: :circle, size: :md, icon_size: size, variant: :ghost, tone: :default, extra: nil)` (ButtonHelper)
1440
1477
  - `lc_card_class(interactive: false, padding: :md, extra: nil)` (CardHelper)
1441
1478
  - `lc_choice_label_class(card: false, extra: nil)` (ChoiceHelper)
1442
1479
  - `lc_checkbox_class(extra: nil)` (ChoiceHelper)
@@ -29,6 +29,12 @@
29
29
  }
30
30
  }
31
31
 
32
+ /* Where `overlay` can't transition, lc-sheet holds a closing dialog open in its exit pose. */
33
+ &[open][data-closing] {
34
+ opacity: 0;
35
+ transform: var(--lc-dialog-from);
36
+ }
37
+
32
38
  /* Fades the tint and the blur, not opacity: Chrome applies a backdrop-filter
33
39
  under opacity < 1 to only some of the page's layers. */
34
40
  &::backdrop {
@@ -73,6 +79,12 @@
73
79
  backdrop-filter: none;
74
80
  }
75
81
 
82
+ /* After the context scrim, which it must outrank. */
83
+ &[open][data-closing]::backdrop {
84
+ background: transparent;
85
+ backdrop-filter: blur(0);
86
+ }
87
+
76
88
  /* The dialog still fades; it no longer moves or grows. */
77
89
  @media (prefers-reduced-motion: reduce) {
78
90
  transform: none;
@@ -46,90 +46,16 @@
46
46
  display: inline-flex;
47
47
  }
48
48
 
49
- /* ==================================================================== */
50
-
51
- /* Mobile-first: the picker opens as a bottom half-sheet. */
52
-
53
- /* ==================================================================== */
54
-
55
- /* The sheet renders in the top layer (Popover API), so this ::backdrop
56
- dims everything beneath it — including the app nav. The allow-discrete
57
- transitions keep it in the top layer while it eases out, so it fades
58
- both ways instead of snapping away on close. */
59
- .lc-emoji-picker__popover::backdrop {
60
- background: var(--lc-scrim);
61
- opacity: 0;
62
- transition:
63
- opacity 220ms var(--lc-ease-out),
64
- display 220ms allow-discrete,
65
- overlay 220ms allow-discrete;
66
-
67
- @media (prefers-reduced-motion: reduce) { transition: none; }
68
- }
69
-
70
- /* Only the phone sheet dims the page; the desktop popover rides the top
71
- layer too (so nothing paints over it) but floats over an undimmed page. */
72
- @media (width < 40rem) {
73
- .lc-emoji-picker__popover:popover-open::backdrop {
74
- opacity: 1;
75
-
76
- @starting-style { opacity: 0; }
77
- }
78
- }
79
-
80
- /* Phones get a solid sheet; on desktop the host paints the popover as a
81
- floating surface (glass in wariwari), so the gem leaves it unpainted. */
82
- @media (width < 40rem) {
83
- .lc-emoji-picker__popover {
84
- border: 1px solid var(--lc-glass-edge, var(--border));
85
- border-block-end: 0;
86
- background: var(--background);
87
- box-shadow: 0 -12px 40px -12px color-mix(in oklab, var(--foreground) 45%, transparent);
88
- }
89
- }
90
-
49
+ /* On a phone the popover is an lc-sheet, which owns its place, edge, backdrop and slide. From sm
50
+ up it is an anchored popover (below), painted by the host. */
91
51
  .lc-emoji-picker__popover {
92
- position: fixed;
93
- inset: auto 0 0;
94
52
  margin: 0;
95
53
  z-index: var(--lc-z-overlay);
96
54
  display: none;
55
+ flex-direction: column;
97
56
  max-inline-size: none;
98
57
  color: var(--foreground);
99
- flex-direction: column;
100
- inline-size: 100%;
101
-
102
- /* A set height, not a maximum: the catalog arrives after the panel opens, and the panel would
103
- grow under the reader's finger, or jump to the other side of its trigger on desktop. */
104
- block-size: min(72svh, 34rem);
105
- padding-block-end: max(env(safe-area-inset-bottom), 8px);
106
- border-start-start-radius: var(--radius-3xl, 1.5rem);
107
- border-start-end-radius: var(--radius-3xl, 1.5rem);
108
58
  overscroll-behavior: contain;
109
- transform: translateY(100%);
110
- transition:
111
- transform 260ms var(--lc-ease-out-expo),
112
- display 260ms allow-discrete,
113
- overlay 260ms allow-discrete;
114
-
115
- /* Top-layer (Popover API) drives display, so showPopover()/hidePopover()
116
- animate the slide in AND out via the allow-discrete transitions. */
117
- &:popover-open {
118
- display: flex;
119
- transform: translateY(0);
120
-
121
- @starting-style { transform: translateY(100%); }
122
- }
123
-
124
- @media (prefers-reduced-motion: reduce) { transition: none; }
125
- }
126
-
127
- /* Fallback for browsers without the Popover API: class-driven display. */
128
- @supports not selector(:popover-open) {
129
- .lc-emoji-picker__popover[data-open] {
130
- display: flex;
131
- transform: translateY(0);
132
- }
133
59
  }
134
60
 
135
61
  /* ---- Search row --------------------------------------------------- */
@@ -413,10 +339,10 @@
413
339
  transform: translateY(-4px) scale(0.98);
414
340
  opacity: 0;
415
341
  transition:
416
- opacity 160ms var(--lc-ease-out-expo),
417
- transform 160ms var(--lc-ease-out-expo),
418
- display 160ms allow-discrete,
419
- overlay 160ms allow-discrete;
342
+ opacity var(--lc-motion-feedback) var(--lc-ease-out-expo),
343
+ transform var(--lc-motion-feedback) var(--lc-ease-out-expo),
344
+ display var(--lc-motion-feedback) allow-discrete,
345
+ overlay var(--lc-motion-feedback) allow-discrete;
420
346
 
421
347
  &[data-open] {
422
348
  display: flex;
@@ -438,3 +364,13 @@
438
364
  }
439
365
  }
440
366
  }
367
+
368
+ @layer modules {
369
+ /* A set height, not the sheet's fit to content: the catalog arrives after the sheet opens, and
370
+ it would grow under the reader's finger. */
371
+ @media (width < 40rem) {
372
+ .lc-emoji-picker__popover.lc-sheet {
373
+ block-size: min(calc(var(--lc-sheet-floor, 100svh) * 0.72), 34rem);
374
+ }
375
+ }
376
+ }
@@ -22,11 +22,11 @@
22
22
 
23
23
  /* allow-discrete keeps a lifted card in the top layer while it fades out. */
24
24
  transition:
25
- opacity 160ms var(--lc-ease-out-expo),
26
- transform 160ms var(--lc-ease-out-expo),
27
- visibility 160ms,
28
- display 160ms allow-discrete,
29
- overlay 160ms allow-discrete;
25
+ opacity var(--lc-motion-feedback) var(--lc-ease-out-expo),
26
+ transform var(--lc-motion-feedback) var(--lc-ease-out-expo),
27
+ visibility var(--lc-motion-feedback),
28
+ display var(--lc-motion-feedback) allow-discrete,
29
+ overlay var(--lc-motion-feedback) allow-discrete;
30
30
  }
31
31
 
32
32
  .lc-hovercard[data-side="top"] > .lc-hovercard__content {
@@ -1,18 +1,19 @@
1
1
  /* Closed is the exit pose, so closing animates too; allow-discrete holds
2
2
  display/overlay until it ends. Open is FloatingPanel's [data-open] or a
3
- native [popover]'s :popover-open. --lc-popover-from sets the closed pose;
3
+ native [popover]'s :popover-open; a panel lifted to the top layer
4
+ ([data-lc-lifted]) follows [data-open] alone. --lc-popover-from sets the closed pose;
4
5
  origin-* utilities set where it grows from. */
5
6
  @utility lc-popover-shell {
6
7
  opacity: 0;
7
8
  transform: var(--lc-popover-from, translateY(--spacing(-1)) scale(0.98));
8
9
  pointer-events: none;
9
10
  transition:
10
- opacity 160ms var(--lc-ease-out-expo),
11
- transform 160ms var(--lc-ease-out-expo),
12
- display 160ms allow-discrete,
13
- overlay 160ms allow-discrete;
11
+ opacity var(--lc-motion-feedback) var(--lc-ease-out-expo),
12
+ transform var(--lc-motion-feedback) var(--lc-ease-out-expo),
13
+ display var(--lc-motion-feedback) allow-discrete,
14
+ overlay var(--lc-motion-feedback) allow-discrete;
14
15
 
15
- &:is([data-open], :popover-open) {
16
+ &:is([data-open], :popover-open:not([data-lc-lifted])) {
16
17
  opacity: 1;
17
18
  transform: translateY(0) scale(1);
18
19
  pointer-events: auto;
@@ -28,7 +29,7 @@
28
29
  /* stylelint-disable-next-line no-invalid-position-declaration -- an @utility body nests like a rule */
29
30
  transform: none;
30
31
 
31
- &:is([data-open], :popover-open) {
32
+ &:is([data-open], :popover-open:not([data-lc-lifted])) {
32
33
  @starting-style { transform: none; }
33
34
  }
34
35
  }
@@ -65,6 +65,10 @@
65
65
  @starting-style { transform: translateY(var(--lc-sheet-offscreen)); }
66
66
  }
67
67
 
68
+ /* Where `overlay` can't transition, lc-sheet holds a closing dialog open
69
+ in its exit pose until the slide ends. */
70
+ &[open][data-closing] { transform: translateY(var(--lc-sheet-offscreen)); }
71
+
68
72
  &::backdrop {
69
73
  background: var(--lc-scrim-sheet);
70
74
  backdrop-filter: none;
@@ -81,6 +85,8 @@
81
85
  @starting-style { opacity: 0; }
82
86
  }
83
87
 
88
+ &[open][data-closing]::backdrop { opacity: 0; }
89
+
84
90
  /* The sheet appears in place; lc-sheet's own slides already skip under reduced motion. */
85
91
  @media (prefers-reduced-motion: reduce) {
86
92
  transition: none;
@@ -1,12 +1,20 @@
1
1
  /* Squircle corners where the browser supports corner-shape. WebKit keeps plain
2
2
  rounded corners. A squircle reads tighter than a circular arc of the same
3
3
  radius, so its radius grows by a third. Library surfaces carry this class;
4
- host elements are never matched by their rounded-* classes. */
4
+ host elements are never matched by their rounded-* classes. A pill is never
5
+ a squircle; an element that is a pill only on phones (max-sm:) is one from sm up. */
5
6
  @utility lc-squircle {
6
7
  @supports (corner-shape: squircle) {
7
8
  &:not([class*="rounded-full"], [class*="rounded-pill"]) {
8
9
  --lc-corner-scale: 1.333;
9
10
  corner-shape: squircle;
10
11
  }
12
+
13
+ @media (width >= 40rem) {
14
+ &:is([class~="max-sm:rounded-pill"], [class~="max-sm:rounded-full"]):not([class~="rounded-pill"], [class~="rounded-full"]) {
15
+ --lc-corner-scale: 1.333;
16
+ corner-shape: squircle;
17
+ }
18
+ }
11
19
  }
12
20
  }
@@ -52,7 +52,7 @@ module Lostcoords::Ui
52
52
  # its avatars, so a context's own `[&_.lc-avatar]:` override still wins. The border cuts each
53
53
  # avatar out of the one beneath, so it takes the fill it sits on (--lc-avatar-cutout).
54
54
  AVATAR_STACK_BASE =
55
- "lc-avatar-stack relative inline-flex items-center min-w-0 [&_.lc-avatar]:outline-none " \
55
+ "lc-avatar-stack relative inline-flex items-center min-w-0 [&_.lc-avatar:not(:focus-visible)]:outline-none " \
56
56
  "[--lc-avatar-size:--spacing(8)] [--lc-avatar-border:--spacing(0.5)] [--lc-avatar-ring-gap:1] " \
57
57
  "[--lc-avatar-stack-overlap:--spacing(1.5)]"
58
58
 
@@ -139,7 +139,7 @@ module Lostcoords::Ui
139
139
  end
140
140
 
141
141
  # The base is already a ghost button, so variant: :ghost adds nothing; tone: recolours any variant.
142
- def lc_icon_button_class(shape: :square, size: :md, icon_size: size, variant: :ghost, tone: :default, extra: nil)
142
+ def lc_icon_button_class(shape: :circle, size: :md, icon_size: size, variant: :ghost, tone: :default, extra: nil)
143
143
  shape = lc_option!(:shape, shape, ICON_BUTTON_SHAPES.keys)
144
144
  size = lc_option!(:size, size, ICON_BUTTON_SIZES.keys)
145
145
  icon_size = lc_option!(:icon_size, icon_size, ICON_BUTTON_ICON_SIZES.keys)
@@ -25,7 +25,7 @@ module Lostcoords::Ui
25
25
  "hover:bg-accent has-checked:bg-primary-soft has-checked:font-semibold has-lc-disabled:cursor-not-allowed has-lc-pending:cursor-progress has-lc-disabled:opacity-45"
26
26
  LIST_ROW_CHOICE_CHECK = "ms-auto size-4 shrink-0 text-primary invisible group-has-checked/choice:visible"
27
27
  LIST_FIELD_ELEMENTS = %i[div fieldset span].freeze
28
- LIST_FIELD = "@container px-content py-2.5 transition-colors duration-(--lc-motion-quick) has-[[data-plain]:focus]:bg-accent has-[[data-plain]:focus-visible]:lc-focus-ring"
28
+ LIST_FIELD = "@container px-content py-2.5 sm:px-inset transition-colors duration-(--lc-motion-quick) has-[[data-plain]:focus]:bg-accent has-[[data-plain]:focus-visible]:lc-focus-ring"
29
29
  LIST_FIELD_GRID = "grid min-h-9 grid-cols-[1.25rem_minmax(0,1fr)] items-center gap-x-heading gap-y-related @md:grid-cols-[8rem_minmax(0,1fr)]"
30
30
  LIST_FIELD_LABEL =
31
31
  "flex items-center gap-related text-label font-semibold text-muted-foreground " \
@@ -3,7 +3,6 @@ import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
3
3
  import { settleFocus } from "lostcoords/ui/helpers/focus"
4
4
  import { menuItems, navigateMenu } from "lostcoords/ui/helpers/menu_keys"
5
5
  import { navigate } from "lostcoords/ui/helpers/roving_focus"
6
- import { prefersReducedMotion } from "lostcoords/ui/helpers/viewport"
7
6
 
8
7
  const TONE_MODIFIERS = ["", "\u{1F3FB}", "\u{1F3FC}", "\u{1F3FD}", "\u{1F3FE}", "\u{1F3FF}"]
9
8
  const TONE_STORAGE_KEY = "lostcoords_ui:lc-emoji-picker:tone"
@@ -357,16 +356,6 @@ export default class extends CatalogPicker {
357
356
  return this.hasRecentTarget ? this.recentTarget : null
358
357
  }
359
358
 
360
- get sheetMotion() {
361
- const duration = prefersReducedMotion() ? 0 : 260
362
- return {
363
- duration,
364
- settle: duration && 280,
365
- transition: "transform 260ms var(--lc-ease-out-expo, ease-out)",
366
- offscreen: "translateY(100%)",
367
- }
368
- }
369
-
370
359
  get quickButtons() {
371
360
  return Array.from(this.element.querySelectorAll(":scope > button[data-emoji]"))
372
361
  }
@@ -8,6 +8,16 @@ const MEDIUM_FRACTION = 0.5
8
8
  const NO_DRAG = "input[type=range], [data-lc-sheet-no-drag]"
9
9
  const DRAG_ZONE = 28
10
10
  const KEYBOARD_FREE = 0.5
11
+ // A finger held still this long before lifting has no fling left in it.
12
+ const STILL_MS = 80
13
+ // --lc-ease-sheet, cubic-bezier(0.32, 0.72, 0, 1), starts at 0.72 / 0.32 = 2.25×
14
+ // its average speed. Change both together.
15
+ const EASE_START = 0.72 / 0.32
16
+ const FASTEST_MS = 240
17
+ // Safari and Firefox can't transition `overlay`, so a closing <dialog> leaves
18
+ // the top layer at once and vanishes mid-slide. There the controller plays the
19
+ // exit pose ([data-closing]) first and closes when it ends.
20
+ const EXITS_NATIVELY = CSS.supports("overlay", "auto")
11
21
 
12
22
  export default class extends Controller {
13
23
  static values = { detents: { type: String, default: "fit" } }
@@ -25,6 +35,7 @@ export default class extends Controller {
25
35
  this.element.addEventListener("touchend", this.onTouchEnd)
26
36
  this.element.addEventListener("touchcancel", this.onTouchEnd)
27
37
  this.element.addEventListener("pointerdown", this.onPointerDown)
38
+ if (this.isDialog && !EXITS_NATIVELY) this.holdClose()
28
39
 
29
40
  this.sync = this.sync.bind(this)
30
41
  this.shown = false
@@ -52,6 +63,7 @@ export default class extends Controller {
52
63
  this.element.removeEventListener("touchend", this.onTouchEnd)
53
64
  this.element.removeEventListener("touchcancel", this.onTouchEnd)
54
65
  this.element.removeEventListener("pointerdown", this.onPointerDown)
66
+ this.releaseClose()
55
67
  this.stopMouseTracking()
56
68
  clearTimeout(this.settleTimer)
57
69
  clearTimeout(this.transitionTimer)
@@ -113,7 +125,7 @@ export default class extends Controller {
113
125
  }
114
126
 
115
127
  onTouchEnd(event) {
116
- if (this.gesture?.dragging) this.release()
128
+ if (this.gesture?.dragging) this.release(event?.timeStamp ?? performance.now())
117
129
  else if (this.gesture && event?.type === "touchend") this.focusInPlace(event)
118
130
  this.gesture = null
119
131
  }
@@ -156,7 +168,8 @@ export default class extends Controller {
156
168
  onPointerUp(event) {
157
169
  this.stopMouseTracking()
158
170
  if (this.gesture && Math.abs(event.clientY - this.gesture.startY) > 4) swallowNextClick()
159
- this.onTouchEnd()
171
+ if (this.gesture?.dragging) this.release(event.timeStamp)
172
+ this.gesture = null
160
173
  }
161
174
 
162
175
  stopMouseTracking() {
@@ -212,18 +225,37 @@ export default class extends Controller {
212
225
  )
213
226
  }
214
227
 
215
- release() {
216
- const { detents, velocity } = this.gesture
217
- const projected = this.visibleHeight() - velocity * PROJECTION_MS
228
+ release(time) {
229
+ const { detents, lastT } = this.gesture
230
+ const velocity = time - lastT > STILL_MS ? 0 : this.gesture.velocity
231
+ const visible = this.visibleHeight()
232
+ const projected = visible - velocity * PROJECTION_MS
218
233
 
219
- if (velocity >= 0 && projected < detents[0].height * 0.6) return this.dismiss()
234
+ if (velocity >= 0 && projected < detents[0].height * 0.6) {
235
+ this.pace(visible + this.offscreenGap, velocity)
236
+ return this.dismiss()
237
+ }
220
238
 
221
239
  const target = detents.reduce((best, detent) =>
222
240
  Math.abs(detent.height - projected) < Math.abs(best.height - projected) ? detent : best,
223
241
  )
242
+ // A fling away from the target, or a lift in place, gets the full beat.
243
+ const toward = Math.sign(visible - target.height) === Math.sign(velocity)
244
+ this.pace(visible - target.height, toward ? velocity : 0)
224
245
  this.settle(target, detents)
225
246
  }
226
247
 
248
+ // UIKit hands a released sheet on at the finger's speed. The sheet curve opens
249
+ // at EASE_START times its average speed, so a beat of EASE_START × distance ÷
250
+ // speed carries the fling on without a jolt; a slow lift keeps the full beat.
251
+ pace(distance, velocity) {
252
+ const full = sheetDuration()
253
+ const speed = Math.abs(velocity)
254
+ if (!full || !speed) return this.element.style.removeProperty("--lc-sheet-duration")
255
+ const ms = Math.min(full, Math.max(FASTEST_MS, (EASE_START * Math.abs(distance)) / speed))
256
+ this.element.style.setProperty("--lc-sheet-duration", `${Math.round(ms)}ms`)
257
+ }
258
+
227
259
  settle(detent, detents = this.detents()) {
228
260
  this.detent = detent
229
261
  this.transition()
@@ -242,15 +274,69 @@ export default class extends Controller {
242
274
  })
243
275
  }
244
276
 
277
+ // The cancel may close the dialog, or keep it open (a listener asking to
278
+ // discard changes): then the sheet settles back.
245
279
  dismissDialog() {
280
+ this.transition()
246
281
  const cancel = new Event("cancel", { cancelable: true })
247
282
  this.element.dispatchEvent(cancel)
248
283
  if (!cancel.defaultPrevented) this.element.close()
249
284
 
250
- if (this.element.open) return this.settle(this.detent || this.detents()[0])
285
+ if (this.element.open && !this.closing) return this.settle(this.detent || this.detents()[0])
286
+ this.element.style.transform = ""
287
+ }
251
288
 
252
- this.transition()
289
+ // Every close() then goes through the exit, whoever calls it, and so does a
290
+ // method=dialog form, which the browser would close at once. A native Escape
291
+ // on a dialog no dismiss stack handles still closes at once.
292
+ holdClose() {
293
+ const close = HTMLDialogElement.prototype.close
294
+ this.closeNow = (value) => close.call(this.element, value)
295
+ this.element.close = (value) => this.closeAfterExit(value)
296
+ this.onDialogSubmit = (event) => {
297
+ const method = event.submitter?.getAttribute("formmethod") || event.target.method
298
+ if (method !== "dialog" || event.target.closest("dialog") !== this.element) return
299
+ event.preventDefault()
300
+ this.element.close(event.submitter?.value)
301
+ }
302
+ this.element.addEventListener("submit", this.onDialogSubmit)
303
+ }
304
+
305
+ releaseClose() {
306
+ if (!this.closeNow) return
307
+ delete this.element.close
308
+ this.element.removeEventListener("submit", this.onDialogSubmit)
309
+ clearTimeout(this.exitTimer)
310
+ if (this.closing) this.finishClose()
311
+ }
312
+
313
+ closeAfterExit(value) {
314
+ if (!this.element.open || this.closing) return
315
+ this.closing = { value }
316
+ if (value !== undefined) this.element.returnValue = value
317
+ this.element.toggleAttribute("data-closing", true)
318
+ // close fires once the slide ends; lc-sheet:exit tells a caller waiting on the answer now.
319
+ this.dispatch("exit", { bubbles: false })
253
320
  this.element.style.transform = ""
321
+ this.exitTimer = setTimeout(() => this.finishClose(), this.exitDuration())
322
+ }
323
+
324
+ finishClose() {
325
+ const { value } = this.closing
326
+ this.closing = null
327
+ this.closeNow(value)
328
+ this.element.removeAttribute("data-closing")
329
+ }
330
+
331
+ exitDuration() {
332
+ const { transitionDuration, transitionDelay } = getComputedStyle(this.element)
333
+ const ms = (list) =>
334
+ list.split(",").map((time) => parseFloat(time) * (time.trim().endsWith("ms") ? 1 : 1000))
335
+ const delays = ms(transitionDelay)
336
+ return Math.max(
337
+ 0,
338
+ ...ms(transitionDuration).map((duration, i) => duration + (delays[i % delays.length] || 0)),
339
+ )
254
340
  }
255
341
 
256
342
  detents() {
@@ -324,12 +410,17 @@ export default class extends Controller {
324
410
  this.transitionTimer = setTimeout(() => {
325
411
  this.element.style.transition = ""
326
412
  this.element.style.willChange = ""
327
- }, sheetDuration())
413
+ this.element.style.removeProperty("--lc-sheet-duration")
414
+ }, sheetDuration(this.element))
328
415
  }
329
416
 
330
417
  later(callback) {
331
418
  clearTimeout(this.settleTimer)
332
- this.settleTimer = setTimeout(callback, sheetDuration())
419
+ this.settleTimer = setTimeout(callback, sheetDuration(this.element))
420
+ }
421
+
422
+ get offscreenGap() {
423
+ return parseFloat(getComputedStyle(document.documentElement).fontSize) * 2
333
424
  }
334
425
 
335
426
  resetSurface() {
@@ -339,6 +430,7 @@ export default class extends Controller {
339
430
  style.willChange = ""
340
431
  style.blockSize = ""
341
432
  style.removeProperty("--lc-sheet-floor")
433
+ style.removeProperty("--lc-sheet-duration")
342
434
  }
343
435
 
344
436
  scrollerFor(target) {
@@ -44,9 +44,14 @@ export function ask(
44
44
 
45
45
  return new Promise((resolve) => {
46
46
  dialog.returnValue = ""
47
- dialog.addEventListener("close", () => resolve(dialog.returnValue === "confirm"), {
48
- once: true,
49
- })
47
+ // lc-sheet:exit comes first where the sheet holds its close for the exit slide.
48
+ const answer = () => {
49
+ dialog.removeEventListener("close", answer)
50
+ dialog.removeEventListener("lc-sheet:exit", answer)
51
+ resolve(dialog.returnValue === "confirm")
52
+ }
53
+ dialog.addEventListener("close", answer)
54
+ dialog.addEventListener("lc-sheet:exit", answer)
50
55
  dialog.style.removeProperty("--lc-dialog-origin")
51
56
  showContextDialog(dialog, anchor)
52
57
  registerDialog(dialog, { lockScroll: false })
@@ -4,10 +4,9 @@ import { prefersReducedMotion } from "lostcoords/ui/helpers/viewport"
4
4
  // directly; timers need the duration in milliseconds.
5
5
  export const SHEET_TIMING = "var(--lc-sheet-duration) var(--lc-ease-sheet)"
6
6
 
7
- export function sheetDuration() {
7
+ // A released sheet sets its own --lc-sheet-duration; pass it to read that beat.
8
+ export function sheetDuration(element = document.documentElement) {
8
9
  if (prefersReducedMotion()) return 0
9
- const value = getComputedStyle(document.documentElement)
10
- .getPropertyValue("--lc-sheet-duration")
11
- .trim()
10
+ const value = getComputedStyle(element).getPropertyValue("--lc-sheet-duration").trim()
12
11
  return value.endsWith("ms") ? parseFloat(value) : parseFloat(value) * 1000
13
12
  }
@@ -14,6 +14,11 @@
14
14
  // pinned to a trigger, and onPageLeave to close them before Turbo caches a page.
15
15
 
16
16
  const MARGIN = 8
17
+ // Safari and Firefox can't transition `overlay`: a hidden popover leaves the top
18
+ // layer, and the screen, at once. WebKit doesn't hold `display` for an exit
19
+ // either. There a lifted panel stays in the top layer, shown as it was, until
20
+ // its exit transition ends.
21
+ const EXITS_NATIVELY = CSS.supports("overlay", "auto")
17
22
  const PAGE_LEAVES = ["turbo:before-cache", "turbo:before-visit", "turbo:before-render"]
18
23
 
19
24
  export const supportsTopLayer = () => typeof HTMLElement.prototype.showPopover === "function"
@@ -41,7 +46,16 @@ export function onPageLeave(close) {
41
46
  window.removeEventListener("pagehide", close)
42
47
  }
43
48
  }
44
- const PLACEMENT = ["position", "inset", "top", "left", "margin", "translate", "inlineSize"]
49
+ const PLACEMENT = [
50
+ "position",
51
+ "inset",
52
+ "top",
53
+ "left",
54
+ "margin",
55
+ "translate",
56
+ "inlineSize",
57
+ "display",
58
+ ]
45
59
 
46
60
  const lifts = new WeakMap()
47
61
  const pinned = new WeakSet()
@@ -60,8 +74,12 @@ export function liftToTopLayer(panel, trigger) {
60
74
  // other panel flips above when it would leave the bottom.
61
75
  const above = placed.bottom <= anchor.top + 1
62
76
  const gap = above ? anchor.top - placed.bottom : placed.top - anchor.bottom
77
+ const shown = getComputedStyle(panel).display
63
78
 
64
79
  showTopLayer(panel)
80
+ // A lifted panel is open while [data-open], not while :popover-open, so it can
81
+ // play its exit pose before it leaves the top layer.
82
+ panel.toggleAttribute("data-lc-lifted", true)
65
83
  Object.assign(panel.style, {
66
84
  position: "fixed",
67
85
  inset: "auto",
@@ -114,10 +132,14 @@ export function liftToTopLayer(panel, trigger) {
114
132
 
115
133
  // Keep the pinned spot while the closing transition plays out, then hand
116
134
  // the panel back to its stylesheet unless it has been lifted again.
117
- Promise.allSettled(panel.getAnimations().map((animation) => animation.finished)).then(() => {
135
+ // The caller has just hidden the panel and no style has been read since, so
136
+ // holding its display here starts the exit transition from the open pose.
137
+ if (!EXITS_NATIVELY) panel.style.display = shown
138
+ const exits = panel.getAnimations().map((animation) => animation.finished)
139
+ if (EXITS_NATIVELY) hideTopLayer(panel)
140
+ Promise.allSettled(exits).then(() => {
118
141
  if (!lifts.has(panel)) reset(panel)
119
142
  })
120
- hideTopLayer(panel)
121
143
  }
122
144
  lifts.set(panel, release)
123
145
  return release
@@ -127,6 +149,7 @@ function reset(panel) {
127
149
  pinned.delete(panel)
128
150
  hideTopLayer(panel)
129
151
  panel.removeAttribute("popover")
152
+ panel.removeAttribute("data-lc-lifted")
130
153
  for (const property of PLACEMENT) panel.style[property] = ""
131
154
  }
132
155
 
@@ -40,7 +40,7 @@
40
40
  </button>
41
41
 
42
42
  <div
43
- class="lc-emoji-picker__popover <%= popover_class %>"
43
+ class="lc-emoji-picker__popover lc-sheet <%= popover_class %>"
44
44
  data-lc-emoji-picker-target="popover"
45
45
  data-controller="lc-sheet"
46
46
  data-action="click->lc-emoji-picker#select pointerover->lc-emoji-picker#preview focusin->lc-emoji-picker#preview lc-sheet:dismiss->lc-emoji-picker#close"
@@ -1,5 +1,5 @@
1
1
  module Lostcoords
2
2
  module Ui
3
- VERSION = "0.14.11"
3
+ VERSION = "0.14.13"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lostcoords-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.11
4
+ version: 0.14.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lost Coordinates