magic-pill 9.4.0-next.3 → 9.4.0-next.5

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 (45) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +10 -7
  3. package/dist/MagicPill/MagicPill.d.mts +2 -1
  4. package/dist/MagicPill/MagicPill.d.ts +2 -1
  5. package/dist/MagicPill/MagicPill.js +11 -3
  6. package/dist/MagicPill/MagicPill.mjs +11 -3
  7. package/dist/Pill/Pill.js +1 -0
  8. package/dist/Pill/Pill.mjs +1 -0
  9. package/dist/Pill/goo.js +90 -37
  10. package/dist/Pill/goo.mjs +90 -37
  11. package/dist/Pill/modal.js +3 -1
  12. package/dist/Pill/modal.mjs +3 -1
  13. package/dist/Pill/morph.js +56 -2
  14. package/dist/Pill/morph.mjs +56 -3
  15. package/dist/PillForm/PillForm.js +6 -1
  16. package/dist/PillForm/PillForm.mjs +7 -2
  17. package/dist/PillForm/dates.js +14 -3
  18. package/dist/PillForm/dates.mjs +14 -3
  19. package/dist/PillForm/room.js +46 -0
  20. package/dist/PillForm/room.mjs +46 -0
  21. package/dist/PillNavbar/PillNavbar.js +3 -1
  22. package/dist/PillNavbar/PillNavbar.mjs +4 -2
  23. package/dist/PillNavbar/room.js +66 -11
  24. package/dist/PillNavbar/room.mjs +66 -12
  25. package/dist/PillNotification/PillNotification.js +2 -4
  26. package/dist/PillNotification/PillNotification.mjs +2 -4
  27. package/dist/PillNotification/RowsBody.js +77 -0
  28. package/dist/PillNotification/RowsBody.mjs +77 -0
  29. package/dist/forms.css +14 -0
  30. package/dist/satellites/Actions.js +269 -16
  31. package/dist/satellites/Actions.mjs +270 -17
  32. package/dist/satellites/Orbitals.js +68 -18
  33. package/dist/satellites/Orbitals.mjs +70 -20
  34. package/dist/satellites/Satellites.js +404 -190
  35. package/dist/satellites/Satellites.mjs +404 -192
  36. package/dist/satellites/handoff.js +36 -0
  37. package/dist/satellites/handoff.mjs +34 -0
  38. package/dist/satellites/measure.js +22 -0
  39. package/dist/satellites/measure.mjs +22 -1
  40. package/dist/satellites/orbits.js +12 -0
  41. package/dist/satellites/orbits.mjs +12 -1
  42. package/dist/satellites/types.d.mts +9 -1
  43. package/dist/satellites/types.d.ts +9 -1
  44. package/dist/styles.css +78 -15
  45. package/package.json +1 -1
package/dist/Pill/goo.mjs CHANGED
@@ -111,26 +111,43 @@ function dropShadow(boxShadow) {
111
111
  const running = /* @__PURE__ */ new WeakMap();
112
112
  let overlays = 0;
113
113
  const SVG = "http://www.w3.org/2000/svg";
114
+ /**
115
+ * The z-index a pill is drawn at: its own, or the one of the nearest element around it that has one
116
+ * (an orbital's menu). 50 (the library's default) when none says.
117
+ */
118
+ function stackLevel(element) {
119
+ for (let node = element; node; node = node.parentElement) {
120
+ const level = Number.parseInt(getComputedStyle(node).zIndex, 10);
121
+ if (Number.isFinite(level)) return level;
122
+ }
123
+ return 50;
124
+ }
125
+ /**
126
+ * The area a goo filter works on: its layer, a little past it. The layer leaves room for the blur and
127
+ * the shadow already (`margin`); the filter worked on twice its width and height, four times its area,
128
+ * at every frame, and filters cost by the pixel (WebKit's most of all)
129
+ */
130
+ const FILTER_REGION = {
131
+ x: "-10%",
132
+ y: "-10%",
133
+ width: "120%",
134
+ height: "120%",
135
+ "color-interpolation-filters": "sRGB"
136
+ };
114
137
  /** The overlay: a filter (blur, threshold, the anchor's inside cut out, a fill, a shadow) and two shapes. */
115
138
  function createOverlay(zIndex, color, shadow) {
116
139
  const id = `mp-goo-${++overlays}`;
117
140
  const root = document.createElement("div");
118
141
  root.setAttribute("data-mp", "goo");
119
142
  root.setAttribute("aria-hidden", "true");
120
- root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;z-index:${zIndex};`;
143
+ root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;overflow:hidden;pointer-events:none;z-index:${zIndex};`;
121
144
  const svg = document.createElementNS(SVG, "svg");
122
145
  svg.setAttribute("width", "0");
123
146
  svg.setAttribute("height", "0");
124
147
  svg.style.position = "absolute";
125
148
  const filter = document.createElementNS(SVG, "filter");
126
149
  filter.id = id;
127
- for (const [name, value] of Object.entries({
128
- x: "-50%",
129
- y: "-50%",
130
- width: "200%",
131
- height: "200%",
132
- "color-interpolation-filters": "sRGB"
133
- })) filter.setAttribute(name, value);
150
+ for (const [name, value] of Object.entries(FILTER_REGION)) filter.setAttribute(name, value);
134
151
  filter.innerHTML = `
135
152
  <feGaussianBlur in="SourceAlpha" stdDeviation="0" result="blur"/>
136
153
  <feComponentTransfer in="blur" result="goo"><feFuncA type="linear" slope="24" intercept="-12"/></feComponentTransfer>
@@ -173,24 +190,38 @@ function createOverlay(zIndex, color, shadow) {
173
190
  * Puts the overlay around the two pills (with `margin` for the blur and the
174
191
  * shadow), and each shape where its pill is, with its rounded corners at its
175
192
  * current scale (`radius`: read once, at its full size).
193
+ *
194
+ * Around the moving pill only, as far as a neck can reach: a sidebar a flag
195
+ * comes out of is as tall as the screen, and the filter ran over all of it at
196
+ * every frame (slow on a phone). Its shape still runs past the overlay, which
197
+ * clips it, so its ends (rounded by the blur) never show.
176
198
  */
177
199
  function placeAll(overlay, pills, radii, margin) {
178
200
  const a = pills.anchor.getBoundingClientRect();
179
201
  const m = pills.moving.getBoundingClientRect();
180
- const left = Math.min(a.left, m.left) - margin;
181
- const top = Math.min(a.top, m.top) - margin;
202
+ const reach = margin;
203
+ const left = Math.max(Math.min(a.left, m.left), m.left - reach) - margin;
204
+ const top = Math.max(Math.min(a.top, m.top), m.top - reach) - margin;
205
+ const right = Math.min(Math.max(a.right, m.right), m.right + reach) + margin;
206
+ const bottom = Math.min(Math.max(a.bottom, m.bottom), m.bottom + reach) + margin;
182
207
  const root = overlay.root.style;
183
208
  root.transform = `translate(${left}px, ${top}px)`;
184
- root.width = `${Math.max(a.right, m.right) + margin - left}px`;
185
- root.height = `${Math.max(a.bottom, m.bottom) + margin - top}px`;
186
- const put = (shape, rect, element, radius) => {
209
+ root.width = `${right - left}px`;
210
+ root.height = `${bottom - top}px`;
211
+ const put = (shape, rect, element, radius, cut = false) => {
187
212
  const scale = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
188
- shape.style.width = `${rect.width}px`;
189
- shape.style.height = `${rect.height}px`;
190
- shape.style.transform = `translate(${rect.left - left}px, ${rect.top - top}px)`;
191
- shape.style.borderRadius = `${Math.min(radius * scale, rect.width / 2, rect.height / 2)}px`;
213
+ const corner = Math.min(radius * scale, rect.width / 2, rect.height / 2);
214
+ const spare = cut ? margin + corner : Number.POSITIVE_INFINITY;
215
+ const x = Math.max(rect.left, left - spare);
216
+ const y = Math.max(rect.top, top - spare);
217
+ const width = Math.max(0, Math.min(rect.right, right + spare) - x);
218
+ const height = Math.max(0, Math.min(rect.bottom, bottom + spare) - y);
219
+ shape.style.width = `${width}px`;
220
+ shape.style.height = `${height}px`;
221
+ shape.style.transform = `translate(${x - left}px, ${y - top}px)`;
222
+ shape.style.borderRadius = `${corner}px`;
192
223
  };
193
- put(overlay.anchor, a, pills.anchor, radii.anchor);
224
+ put(overlay.anchor, a, pills.anchor, radii.anchor, true);
194
225
  put(overlay.moving, m, pills.moving, radii.moving);
195
226
  }
196
227
  const OWN_LOOK = {
@@ -309,7 +340,11 @@ function playSplit(anchor, moving, kind, timing) {
309
340
  easing: POP
310
341
  });
311
342
  }
312
- const content = [...moving.children].filter((child) => !["panel", "outgoing"].includes(child.getAttribute("data-mp") ?? ""));
343
+ const circle = kind === "split" && ["rest", "hidden"].includes(moving.dataset.presence ?? "");
344
+ const content = [...moving.children].filter((child) => {
345
+ const part = child.getAttribute("data-mp") ?? "";
346
+ return !["panel", "outgoing"].includes(part) && (!circle || part === "icon");
347
+ });
313
348
  const total = timing.duration + fade;
314
349
  for (const child of content) if (kind === "split") child.animate([
315
350
  { opacity: 0 },
@@ -409,6 +444,16 @@ const budding = /* @__PURE__ */ new WeakMap();
409
444
  * electron out of its host or out of the one next to it, the page's actions.
410
445
  */
411
446
  function playOrbit(electron, items, kind, timing) {
447
+ const drawn = /* @__PURE__ */ new Map();
448
+ for (const { element } of items) {
449
+ if (kind !== "close" || !(element.getAnimations?.() ?? []).some((animation) => animation.id === "mp-split" && animation.playState === "running")) continue;
450
+ const now = getComputedStyle(element);
451
+ drawn.set(element, {
452
+ translate: !now.translate || now.translate === "none" ? "0px 0px" : now.translate,
453
+ scale: !now.scale || now.scale === "none" ? "1" : now.scale,
454
+ opacity: Number.parseFloat(now.opacity) || 0
455
+ });
456
+ }
412
457
  for (const { element } of items) {
413
458
  budding.get(element)?.();
414
459
  for (const animation of element.getAnimations?.({ subtree: true }) ?? []) if (animation.id === "mp-split") animation.cancel();
@@ -420,6 +465,21 @@ function playOrbit(electron, items, kind, timing) {
420
465
  const cx = centre.left + centre.width / 2;
421
466
  const cy = centre.top + centre.height / 2;
422
467
  const longest = Math.max(...items.map(({ delay }) => delay)) + timing.duration;
468
+ const anchorLevel = stackLevel(electron);
469
+ const lowered = [];
470
+ for (const { element } of items) {
471
+ if (stackLevel(element) < anchorLevel) continue;
472
+ lowered.push([element, element.style.zIndex]);
473
+ element.style.zIndex = String(anchorLevel - 1);
474
+ }
475
+ let restored = false;
476
+ const restore = () => {
477
+ if (restored) return;
478
+ restored = true;
479
+ clearTimeout(timer);
480
+ for (const [element, zIndex] of lowered) element.style.zIndex = zIndex;
481
+ };
482
+ const timer = lowered.length > 0 ? setTimeout(restore, longest) : void 0;
423
483
  for (const { element, delay, shown = 1, from = atPoint(cx, cy), droplet = false, opaque = droplet } of items) {
424
484
  if (shown <= 0) continue;
425
485
  const start = from(element.getBoundingClientRect(), element);
@@ -429,7 +489,7 @@ function playOrbit(electron, items, kind, timing) {
429
489
  scale: String(start.scale),
430
490
  opacity: opaque ? shown : 0
431
491
  };
432
- const out = {
492
+ const out = drawn.get(element) ?? {
433
493
  translate: "0px 0px",
434
494
  scale: end === "none" ? "1" : end,
435
495
  opacity: shown
@@ -453,7 +513,7 @@ function playOrbit(electron, items, kind, timing) {
453
513
  id: SPLIT,
454
514
  duration: timing.duration,
455
515
  delay,
456
- fill: kind === "open" ? "backwards" : "forwards"
516
+ fill: kind === "open" ? "backwards" : "both"
457
517
  };
458
518
  const ends = (kind === "open" ? [inside, out] : [out, inside]).map(({ translate, scale }) => ({
459
519
  translate,
@@ -497,14 +557,10 @@ function playOrbit(electron, items, kind, timing) {
497
557
  offset: .7
498
558
  },
499
559
  { opacity: 1 }
500
- ] : [
501
- { opacity: 1 },
502
- {
503
- opacity: 0,
504
- offset: .3
505
- },
506
- { opacity: 0 }
507
- ];
560
+ ] : [{
561
+ opacity: 0,
562
+ offset: .3
563
+ }, { opacity: 0 }];
508
564
  for (const child of element.children) child.animate(content, {
509
565
  ...options,
510
566
  easing: "linear"
@@ -514,6 +570,7 @@ function playOrbit(electron, items, kind, timing) {
514
570
  const stop = playNecks([electron, ...items.filter(({ shown = 1 }) => shown > 0).map(({ element }) => element)], longest);
515
571
  const stopAll = () => {
516
572
  stop();
573
+ restore();
517
574
  for (const { element } of items) if (budding.get(element) === stopAll) budding.delete(element);
518
575
  };
519
576
  for (const { element } of items) budding.set(element, stopAll);
@@ -535,20 +592,15 @@ function playNecks(pills, duration) {
535
592
  const root = document.createElement("div");
536
593
  root.setAttribute("data-mp", "goo");
537
594
  root.setAttribute("aria-hidden", "true");
538
- root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;z-index:${(Number.parseInt(style.zIndex, 10) || 50) - 1};`;
595
+ const level = Math.min(...pills.map(stackLevel)) - 1;
596
+ root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;z-index:${level};`;
539
597
  const svg = document.createElementNS(SVG, "svg");
540
598
  svg.setAttribute("width", "0");
541
599
  svg.setAttribute("height", "0");
542
600
  svg.style.position = "absolute";
543
601
  const filter = document.createElementNS(SVG, "filter");
544
602
  filter.id = id;
545
- for (const [name, value] of Object.entries({
546
- x: "-50%",
547
- y: "-50%",
548
- width: "200%",
549
- height: "200%",
550
- "color-interpolation-filters": "sRGB"
551
- })) filter.setAttribute(name, value);
603
+ for (const [name, value] of Object.entries(FILTER_REGION)) filter.setAttribute(name, value);
552
604
  filter.innerHTML = `
553
605
  <feGaussianBlur in="SourceAlpha" stdDeviation="0" result="blur"/>
554
606
  <feComponentTransfer in="blur" result="goo"><feFuncA type="linear" slope="24" intercept="-12"/></feComponentTransfer>
@@ -596,6 +648,7 @@ function playNecks(pills, duration) {
596
648
  shape.height = `${rect.height}px`;
597
649
  shape.transform = `translate(${rect.left - left}px, ${rect.top - top}px)`;
598
650
  shape.borderRadius = `${Math.min(radii[index] * scale, rect.width / 2, rect.height / 2)}px`;
651
+ shape.opacity = getComputedStyle(pills[index]).opacity;
599
652
  });
600
653
  blur.setAttribute("stdDeviation", (goo * gooAmount(Math.min(1, elapsed / longest))).toFixed(2));
601
654
  if (elapsed >= longest) return stop();
@@ -21,6 +21,7 @@ function useModal(rootRef, isOverlay, presence, lastSize) {
21
21
  const show = () => {
22
22
  const dialog = rootRef.current;
23
23
  if (!isOverlay || !isVisible || !dialog?.isConnected || typeof dialog.showModal !== "function") return;
24
+ let opening = false;
24
25
  if (!dialog.open) {
25
26
  dialog.dataset.presence = "hidden";
26
27
  dialog.showModal();
@@ -29,8 +30,9 @@ function useModal(rootRef, isOverlay, presence, lastSize) {
29
30
  height: dialog.offsetHeight
30
31
  };
31
32
  dialog.dataset.presence = presence;
33
+ opening = true;
32
34
  }
33
- if (presence === "rest" || !dialog.contains(document.activeElement)) dialog.focus();
35
+ if (opening || presence === "rest" || !dialog.contains(document.activeElement)) dialog.focus();
34
36
  };
35
37
  require_react.useIsomorphicLayoutEffect(() => {
36
38
  show();
@@ -21,6 +21,7 @@ function useModal(rootRef, isOverlay, presence, lastSize) {
21
21
  const show = () => {
22
22
  const dialog = rootRef.current;
23
23
  if (!isOverlay || !isVisible || !dialog?.isConnected || typeof dialog.showModal !== "function") return;
24
+ let opening = false;
24
25
  if (!dialog.open) {
25
26
  dialog.dataset.presence = "hidden";
26
27
  dialog.showModal();
@@ -29,8 +30,9 @@ function useModal(rootRef, isOverlay, presence, lastSize) {
29
30
  height: dialog.offsetHeight
30
31
  };
31
32
  dialog.dataset.presence = presence;
33
+ opening = true;
32
34
  }
33
- if (presence === "rest" || !dialog.contains(document.activeElement)) dialog.focus();
35
+ if (opening || presence === "rest" || !dialog.contains(document.activeElement)) dialog.focus();
34
36
  };
35
37
  useIsomorphicLayoutEffect(() => {
36
38
  show();
@@ -187,6 +187,44 @@ const readSize = (element) => ({
187
187
  width: element.offsetWidth,
188
188
  height: element.offsetHeight
189
189
  });
190
+ /**
191
+ * Its size once what's changing inside it has got there: a label folding as a panel closes is still
192
+ * open when the pill measures where it's going (a transition). Measured then on a copy laid out with
193
+ * no transitions, so the pill goes there in one motion, instead of shrinking, then jumping (or
194
+ * settling in a second step) as the label folds.
195
+ */
196
+ function readSettledSize(element) {
197
+ if (!(typeof CSSTransition !== "undefined" && (element.getAnimations?.({ subtree: true }) ?? []).some((animation) => animation instanceof CSSTransition && animation.effect instanceof KeyframeEffect && animation.effect.target !== element)) || element.tagName === "DIALOG") return readSize(element);
198
+ return onCopy(element, readSize, (copy) => {
199
+ const actions = element.querySelectorAll("[data-mp=\"action\"]");
200
+ copy.querySelectorAll("[data-mp=\"action\"]").forEach((action, index) => {
201
+ if (actions[index]?.matches(":hover, :focus-visible")) action.setAttribute("data-pointed", "");
202
+ });
203
+ });
204
+ }
205
+ /**
206
+ * A copy of the pill laid out next to it as it ends up: hidden, with no transitions nor animations
207
+ * (`[data-mp-measure]`), sharing no id or radio group with it. `read` measures it, then it's gone.
208
+ */
209
+ function onCopy(element, read, prepare) {
210
+ const copy = element.cloneNode(true);
211
+ copy.querySelectorAll("[id], [name]").forEach((node) => {
212
+ node.removeAttribute("id");
213
+ node.removeAttribute("name");
214
+ });
215
+ copy.removeAttribute("id");
216
+ copy.setAttribute("data-mp-measure", "");
217
+ copy.inert = true;
218
+ copy.style.visibility = "hidden";
219
+ copy.style.pointerEvents = "none";
220
+ prepare?.(copy);
221
+ element.after(copy);
222
+ try {
223
+ return read(copy);
224
+ } finally {
225
+ copy.remove();
226
+ }
227
+ }
190
228
  /** Stops the pill's animations with this id (and the ones in it). Returns whether anything ran. */
191
229
  function cancel(element, id, subtree) {
192
230
  let cancelled = false;
@@ -442,7 +480,7 @@ function useSizeMorph(rootRef, presence, enabled, lastSize) {
442
480
  const from = stopMorphs(element) || running.current.length > 0 ? current : lastSize.current;
443
481
  running.current.forEach((animation) => animation.cancel());
444
482
  running.current = [];
445
- const to = readSize(element);
483
+ const to = readSettledSize(element);
446
484
  lastSize.current = to;
447
485
  if (!from) return;
448
486
  const panel = readPanel(element);
@@ -476,7 +514,22 @@ function useSizeMorph(rootRef, presence, enabled, lastSize) {
476
514
  if (animations.length === 0) return;
477
515
  running.current = animations;
478
516
  animations[0].finished.then(() => {
479
- if (running.current === animations) running.current = [];
517
+ if (running.current !== animations) return;
518
+ running.current = [];
519
+ const now = readSize(element);
520
+ if (CLOSED.has(presence) || Math.abs(now.width - to.width) <= 1 && Math.abs(now.height - to.height) <= 1) return;
521
+ lastSize.current = now;
522
+ running.current = [element.animate([{
523
+ width: `${to.width}px`,
524
+ height: `${to.height}px`
525
+ }, {
526
+ width: `${now.width}px`,
527
+ height: `${now.height}px`
528
+ }], {
529
+ id: MORPH,
530
+ duration: timings.change,
531
+ easing: "ease-in-out"
532
+ })];
480
533
  }).catch(() => {});
481
534
  }, [
482
535
  rootRef,
@@ -574,6 +627,7 @@ exports.PlacementWatch = PlacementWatch;
574
627
  exports.animateMove = animateMove;
575
628
  exports.cancel = cancel;
576
629
  exports.captureSwap = captureSwap;
630
+ exports.onCopy = onCopy;
577
631
  exports.planExit = planExit;
578
632
  exports.planMorph = planMorph;
579
633
  exports.planSwap = planSwap;
@@ -187,6 +187,44 @@ const readSize = (element) => ({
187
187
  width: element.offsetWidth,
188
188
  height: element.offsetHeight
189
189
  });
190
+ /**
191
+ * Its size once what's changing inside it has got there: a label folding as a panel closes is still
192
+ * open when the pill measures where it's going (a transition). Measured then on a copy laid out with
193
+ * no transitions, so the pill goes there in one motion, instead of shrinking, then jumping (or
194
+ * settling in a second step) as the label folds.
195
+ */
196
+ function readSettledSize(element) {
197
+ if (!(typeof CSSTransition !== "undefined" && (element.getAnimations?.({ subtree: true }) ?? []).some((animation) => animation instanceof CSSTransition && animation.effect instanceof KeyframeEffect && animation.effect.target !== element)) || element.tagName === "DIALOG") return readSize(element);
198
+ return onCopy(element, readSize, (copy) => {
199
+ const actions = element.querySelectorAll("[data-mp=\"action\"]");
200
+ copy.querySelectorAll("[data-mp=\"action\"]").forEach((action, index) => {
201
+ if (actions[index]?.matches(":hover, :focus-visible")) action.setAttribute("data-pointed", "");
202
+ });
203
+ });
204
+ }
205
+ /**
206
+ * A copy of the pill laid out next to it as it ends up: hidden, with no transitions nor animations
207
+ * (`[data-mp-measure]`), sharing no id or radio group with it. `read` measures it, then it's gone.
208
+ */
209
+ function onCopy(element, read, prepare) {
210
+ const copy = element.cloneNode(true);
211
+ copy.querySelectorAll("[id], [name]").forEach((node) => {
212
+ node.removeAttribute("id");
213
+ node.removeAttribute("name");
214
+ });
215
+ copy.removeAttribute("id");
216
+ copy.setAttribute("data-mp-measure", "");
217
+ copy.inert = true;
218
+ copy.style.visibility = "hidden";
219
+ copy.style.pointerEvents = "none";
220
+ prepare?.(copy);
221
+ element.after(copy);
222
+ try {
223
+ return read(copy);
224
+ } finally {
225
+ copy.remove();
226
+ }
227
+ }
190
228
  /** Stops the pill's animations with this id (and the ones in it). Returns whether anything ran. */
191
229
  function cancel(element, id, subtree) {
192
230
  let cancelled = false;
@@ -442,7 +480,7 @@ function useSizeMorph(rootRef, presence, enabled, lastSize) {
442
480
  const from = stopMorphs(element) || running.current.length > 0 ? current : lastSize.current;
443
481
  running.current.forEach((animation) => animation.cancel());
444
482
  running.current = [];
445
- const to = readSize(element);
483
+ const to = readSettledSize(element);
446
484
  lastSize.current = to;
447
485
  if (!from) return;
448
486
  const panel = readPanel(element);
@@ -476,7 +514,22 @@ function useSizeMorph(rootRef, presence, enabled, lastSize) {
476
514
  if (animations.length === 0) return;
477
515
  running.current = animations;
478
516
  animations[0].finished.then(() => {
479
- if (running.current === animations) running.current = [];
517
+ if (running.current !== animations) return;
518
+ running.current = [];
519
+ const now = readSize(element);
520
+ if (CLOSED.has(presence) || Math.abs(now.width - to.width) <= 1 && Math.abs(now.height - to.height) <= 1) return;
521
+ lastSize.current = now;
522
+ running.current = [element.animate([{
523
+ width: `${to.width}px`,
524
+ height: `${to.height}px`
525
+ }, {
526
+ width: `${now.width}px`,
527
+ height: `${now.height}px`
528
+ }], {
529
+ id: MORPH,
530
+ duration: timings.change,
531
+ easing: "ease-in-out"
532
+ })];
480
533
  }).catch(() => {});
481
534
  }, [
482
535
  rootRef,
@@ -565,4 +618,4 @@ var PlacementWatch = class extends Component {
565
618
  }
566
619
  };
567
620
 
568
- export { EASING, EXIT, ExitWatch, MORPH, MOVE, PlacementWatch, animateMove, cancel, captureSwap, planExit, planMorph, planSwap, playSwap, readMorphTimings, useSizeMorph };
621
+ export { EASING, EXIT, ExitWatch, MORPH, MOVE, PlacementWatch, animateMove, cancel, captureSwap, onCopy, planExit, planMorph, planSwap, playSwap, readMorphTimings, useSizeMorph };
@@ -5,7 +5,9 @@ const require_glyphs = require("./glyphs.js");
5
5
  const require_send = require("./send.js");
6
6
  const require_FormContext = require("./FormContext.js");
7
7
  const require_keyboard = require("./keyboard.js");
8
+ const require_room = require("./room.js");
8
9
  const require_PillContext = require("../Pill/PillContext.js");
10
+ const require_react = require("../utils/react.js");
9
11
  let react_jsx_runtime = require("react/jsx-runtime");
10
12
 
11
13
  // src/PillForm/PillForm.tsx
@@ -24,11 +26,14 @@ const PillForm = (0, react.forwardRef)(function PillForm({ look, layout, errors
24
26
  errors,
25
27
  isBusy
26
28
  ]);
29
+ const formRef = (0, react.useRef)(null);
30
+ require_room.useFormRoom(formRef);
31
+ const refs = (0, react.useMemo)(() => require_react.mergeRefs(ref, formRef), [ref]);
27
32
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_FormContext.FormContext.Provider, {
28
33
  value: context,
29
34
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("form", {
30
35
  ...rest,
31
- ref,
36
+ ref: refs,
32
37
  "data-mp": "form",
33
38
  "data-look": look,
34
39
  "data-failed": sending.failure ? "" : void 0,
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
 
3
- import { forwardRef, useMemo } from "react";
3
+ import { forwardRef, useMemo, useRef } from "react";
4
4
  import { AlertGlyph } from "./glyphs.mjs";
5
5
  import { useSend } from "./send.mjs";
6
6
  import { FormContext } from "./FormContext.mjs";
7
7
  import { useKeyboard } from "./keyboard.mjs";
8
+ import { useFormRoom } from "./room.mjs";
8
9
  import { useInternalPill } from "../Pill/PillContext.mjs";
10
+ import { mergeRefs } from "../utils/react.mjs";
9
11
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
10
12
 
11
13
  // src/PillForm/PillForm.tsx
@@ -24,11 +26,14 @@ const PillForm = forwardRef(function PillForm({ look, layout, errors = "inline",
24
26
  errors,
25
27
  isBusy
26
28
  ]);
29
+ const formRef = useRef(null);
30
+ useFormRoom(formRef);
31
+ const refs = useMemo(() => mergeRefs(ref, formRef), [ref]);
27
32
  return /* @__PURE__ */ jsx(FormContext.Provider, {
28
33
  value: context,
29
34
  children: /* @__PURE__ */ jsx("form", {
30
35
  ...rest,
31
- ref,
36
+ ref: refs,
32
37
  "data-mp": "form",
33
38
  "data-look": look,
34
39
  "data-failed": sending.failure ? "" : void 0,
@@ -112,7 +112,18 @@ const FORMATS = {
112
112
  timeStyle: "short"
113
113
  }
114
114
  };
115
- /** A value, as it's written there. */
115
+ /**
116
+ * Starts with a capital, as a label does: some languages write their days and
117
+ * months in lowercase ("jeudi 24 décembre", "décembre 2026"), which reads as
118
+ * a broken label once it stands alone in a field or a calendar.
119
+ */
120
+ function asLabel(text, locale) {
121
+ const first = text.codePointAt(0);
122
+ if (first === void 0) return text;
123
+ const letter = String.fromCodePoint(first);
124
+ return letter.toLocaleUpperCase(locale) + text.slice(letter.length);
125
+ }
126
+ /** A value, as it's written there, starting with a capital. */
116
127
  function formatValue(value, type, locale, options) {
117
128
  if (!value) return "";
118
129
  const formatter = new Intl.DateTimeFormat(locale, {
@@ -127,13 +138,13 @@ function formatValue(value, type, locale, options) {
127
138
  if (type === "week") {
128
139
  const monday = parseDay(day);
129
140
  const sunday = parseDay(addDays(day, 6));
130
- return monday && sunday ? formatter.formatRange(monday, sunday) : value;
141
+ return monday && sunday ? asLabel(formatter.formatRange(monday, sunday), locale) : value;
131
142
  }
132
143
  const date = parseDay(day || "2000-01-01");
133
144
  if (!date || !day && type !== "time") return value;
134
145
  const [hours, minutes] = timeOf(value, type).split(":").map(Number);
135
146
  date.setUTCHours(hours || 0, minutes || 0);
136
- return formatter.format(date);
147
+ return asLabel(formatter.format(date), locale);
137
148
  }
138
149
 
139
150
  exports.addDays = addDays;
@@ -112,7 +112,18 @@ const FORMATS = {
112
112
  timeStyle: "short"
113
113
  }
114
114
  };
115
- /** A value, as it's written there. */
115
+ /**
116
+ * Starts with a capital, as a label does: some languages write their days and
117
+ * months in lowercase ("jeudi 24 décembre", "décembre 2026"), which reads as
118
+ * a broken label once it stands alone in a field or a calendar.
119
+ */
120
+ function asLabel(text, locale) {
121
+ const first = text.codePointAt(0);
122
+ if (first === void 0) return text;
123
+ const letter = String.fromCodePoint(first);
124
+ return letter.toLocaleUpperCase(locale) + text.slice(letter.length);
125
+ }
126
+ /** A value, as it's written there, starting with a capital. */
116
127
  function formatValue(value, type, locale, options) {
117
128
  if (!value) return "";
118
129
  const formatter = new Intl.DateTimeFormat(locale, {
@@ -127,13 +138,13 @@ function formatValue(value, type, locale, options) {
127
138
  if (type === "week") {
128
139
  const monday = parseDay(day);
129
140
  const sunday = parseDay(addDays(day, 6));
130
- return monday && sunday ? formatter.formatRange(monday, sunday) : value;
141
+ return monday && sunday ? asLabel(formatter.formatRange(monday, sunday), locale) : value;
131
142
  }
132
143
  const date = parseDay(day || "2000-01-01");
133
144
  if (!date || !day && type !== "time") return value;
134
145
  const [hours, minutes] = timeOf(value, type).split(":").map(Number);
135
146
  date.setUTCHours(hours || 0, minutes || 0);
136
- return formatter.format(date);
147
+ return asLabel(formatter.format(date), locale);
137
148
  }
138
149
 
139
150
  export { addDays, addMonths, dayOf, firstDayOfWeek, formatDay, formatValue, isDayOutside, isOutside, localFirstDay, monthGrid, monthOf, parseDay, timeOf, toValue, today, usesTwelveHours, weekOf };
@@ -0,0 +1,46 @@
1
+ "use client";
2
+
3
+ let react = require("react");
4
+
5
+ // src/PillForm/room.ts
6
+ /** A field narrower than this has no room to type in, in rem */
7
+ const LEAST = 9;
8
+ function useFormRoom(formRef) {
9
+ (0, react.useEffect)(() => {
10
+ const form = formRef.current;
11
+ if (!form || form.parentElement?.getAttribute("data-mp") !== "pill") return;
12
+ let open = 0;
13
+ const update = () => {
14
+ const pill = form.parentElement;
15
+ const field = form.querySelector("[data-mp=\"field\"]");
16
+ const submit = form.querySelector("[data-mp=\"action\"][type=\"submit\"][data-expanded]");
17
+ if (!field || !submit) return form.removeAttribute("data-tight");
18
+ const least = LEAST * (Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16);
19
+ const max = Number.parseFloat(getComputedStyle(pill).maxInlineSize);
20
+ let room = Number.isFinite(max) ? max - pill.offsetWidth : Number.POSITIVE_INFINITY;
21
+ const container = pill.parentElement;
22
+ if (pill.dataset.placement === "inline" && container) {
23
+ const style = getComputedStyle(container);
24
+ const inside = container.clientWidth - (Number.parseFloat(style.paddingLeft) || 0) - (Number.parseFloat(style.paddingRight) || 0);
25
+ room = Math.min(room, inside - pill.offsetWidth);
26
+ }
27
+ const could = field.offsetWidth + Math.max(0, room);
28
+ if (!form.hasAttribute("data-tight")) {
29
+ if (could >= least) return;
30
+ open = submit.offsetWidth;
31
+ form.setAttribute("data-tight", "");
32
+ } else if (could - Math.max(0, open - submit.offsetWidth) >= least + 1) form.removeAttribute("data-tight");
33
+ };
34
+ update();
35
+ const sizes = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
36
+ sizes?.observe(form);
37
+ window.addEventListener("resize", update);
38
+ return () => {
39
+ sizes?.disconnect();
40
+ window.removeEventListener("resize", update);
41
+ form.removeAttribute("data-tight");
42
+ };
43
+ }, [formRef]);
44
+ }
45
+
46
+ exports.useFormRoom = useFormRoom;
@@ -0,0 +1,46 @@
1
+ "use client";
2
+
3
+ import { useEffect } from "react";
4
+
5
+ // src/PillForm/room.ts
6
+ /** A field narrower than this has no room to type in, in rem */
7
+ const LEAST = 9;
8
+ function useFormRoom(formRef) {
9
+ useEffect(() => {
10
+ const form = formRef.current;
11
+ if (!form || form.parentElement?.getAttribute("data-mp") !== "pill") return;
12
+ let open = 0;
13
+ const update = () => {
14
+ const pill = form.parentElement;
15
+ const field = form.querySelector("[data-mp=\"field\"]");
16
+ const submit = form.querySelector("[data-mp=\"action\"][type=\"submit\"][data-expanded]");
17
+ if (!field || !submit) return form.removeAttribute("data-tight");
18
+ const least = LEAST * (Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16);
19
+ const max = Number.parseFloat(getComputedStyle(pill).maxInlineSize);
20
+ let room = Number.isFinite(max) ? max - pill.offsetWidth : Number.POSITIVE_INFINITY;
21
+ const container = pill.parentElement;
22
+ if (pill.dataset.placement === "inline" && container) {
23
+ const style = getComputedStyle(container);
24
+ const inside = container.clientWidth - (Number.parseFloat(style.paddingLeft) || 0) - (Number.parseFloat(style.paddingRight) || 0);
25
+ room = Math.min(room, inside - pill.offsetWidth);
26
+ }
27
+ const could = field.offsetWidth + Math.max(0, room);
28
+ if (!form.hasAttribute("data-tight")) {
29
+ if (could >= least) return;
30
+ open = submit.offsetWidth;
31
+ form.setAttribute("data-tight", "");
32
+ } else if (could - Math.max(0, open - submit.offsetWidth) >= least + 1) form.removeAttribute("data-tight");
33
+ };
34
+ update();
35
+ const sizes = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
36
+ sizes?.observe(form);
37
+ window.addEventListener("resize", update);
38
+ return () => {
39
+ sizes?.disconnect();
40
+ window.removeEventListener("resize", update);
41
+ form.removeAttribute("data-tight");
42
+ };
43
+ }, [formRef]);
44
+ }
45
+
46
+ export { useFormRoom };