@alulore/kumiko 0.20.2 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/avatar/avatar.js +1 -1
  2. package/dist/badge/badge.css +41 -3
  3. package/dist/badge/badge.js +11 -4
  4. package/dist/button/button.css +21 -7
  5. package/dist/card/card.css +3 -2
  6. package/dist/card/item-card.d.ts +1 -1
  7. package/dist/card/item-card.js +3 -2
  8. package/dist/chip/chip.css +6 -10
  9. package/dist/chip/chip.js +1 -1
  10. package/dist/form/error-line.js +4 -3
  11. package/dist/input/input.css +99 -114
  12. package/dist/list-row/list-row-motion.js +29 -10
  13. package/dist/media-viewer/gesture-press.d.ts +1 -0
  14. package/dist/media-viewer/gesture-press.js +12 -0
  15. package/dist/media-viewer/media-slide.d.ts +3 -1
  16. package/dist/media-viewer/media-slide.js +3 -2
  17. package/dist/media-viewer/media-viewer.css +5 -1
  18. package/dist/media-viewer/media-viewer.js +41 -23
  19. package/dist/media-viewer/stage-rect.d.ts +16 -0
  20. package/dist/media-viewer/stage-rect.js +56 -0
  21. package/dist/media-viewer/view-gesture.d.ts +1 -2
  22. package/dist/media-viewer/view-gesture.js +39 -44
  23. package/dist/media-viewer/viewer-chrome.d.ts +2 -1
  24. package/dist/media-viewer/viewer-chrome.js +3 -1
  25. package/dist/media-viewer/viewer-motion.d.ts +1 -0
  26. package/dist/media-viewer/viewer-motion.js +20 -7
  27. package/dist/media-viewer/zoom-pan.d.ts +1 -0
  28. package/dist/media-viewer/zoom-pan.js +3 -0
  29. package/dist/media-viewer/zoom-store.d.ts +8 -0
  30. package/dist/media-viewer/zoom-store.js +30 -0
  31. package/dist/menu/menu.js +6 -3
  32. package/dist/menu/point-menu.js +32 -12
  33. package/dist/page/page-actions.js +2 -1
  34. package/dist/page/page-breadcrumbs.js +2 -1
  35. package/dist/page/use-measured-fit.d.ts +5 -0
  36. package/dist/page/use-measured-fit.js +47 -5
  37. package/dist/page/use-stuck.js +12 -2
  38. package/dist/pagination/pagination-fit.d.ts +3 -1
  39. package/dist/pagination/pagination-fit.js +4 -3
  40. package/dist/pagination/pagination-motion.js +18 -11
  41. package/dist/pagination/pagination.css +50 -6
  42. package/dist/pagination/pagination.js +20 -3
  43. package/dist/progress/progress.css +3 -2
  44. package/dist/progress/progress.js +15 -3
  45. package/dist/select/select-labels.d.ts +2 -0
  46. package/dist/select/select-labels.js +5 -1
  47. package/dist/select/select.css +7 -11
  48. package/dist/select/select.d.ts +1 -1
  49. package/dist/select/select.js +12 -6
  50. package/dist/shortcuts/hints.js +10 -4
  51. package/dist/shortcuts/provider.d.ts +4 -2
  52. package/dist/shortcuts/provider.js +14 -17
  53. package/dist/skeleton/skeleton.css +22 -9
  54. package/dist/slider/slider-feel.js +18 -6
  55. package/dist/slider/slider.css +9 -10
  56. package/dist/slider/slider.js +13 -10
  57. package/dist/smooth-caret/caret-controller.js +18 -6
  58. package/dist/smooth-caret/caret-geometry.js +18 -7
  59. package/dist/smooth-caret/caret-glide.js +3 -2
  60. package/dist/smooth-caret/remote-carets.js +20 -3
  61. package/dist/smooth-caret/smooth-caret.css +1 -1
  62. package/dist/switch/switch-gesture.d.ts +4 -4
  63. package/dist/switch/switch-gesture.js +52 -14
  64. package/dist/switch/switch.css +12 -13
  65. package/dist/switch/switch.d.ts +2 -1
  66. package/dist/switch/switch.js +4 -6
  67. package/dist/table/data-table.js +32 -12
  68. package/dist/table/table-cells.d.ts +20 -8
  69. package/dist/table/table-cells.js +18 -20
  70. package/dist/table/table-model.d.ts +0 -2
  71. package/dist/table/table-model.js +15 -9
  72. package/dist/table/table-search.d.ts +12 -0
  73. package/dist/table/table-search.js +34 -0
  74. package/dist/table/table-sections.d.ts +3 -2
  75. package/dist/table/table-sections.js +16 -13
  76. package/dist/table/table.css +2 -14
  77. package/dist/table/use-latest.d.ts +6 -0
  78. package/dist/table/use-latest.js +22 -0
  79. package/dist/table/use-table-view.js +36 -24
  80. package/package.json +1 -1
@@ -1,6 +1,32 @@
1
1
  import { createMenuController } from "@ui-sdk/react/menu";
2
2
  import { useState } from "react";
3
3
  const inMenu = (el) => el?.closest('[data-slot="menu-content"]') !== null && el !== null;
4
+ /** Calls `run` once focus is outside the menu. Starting again drops the wait before it, so only one is ever pending. */
5
+ function createFocusWait(run) {
6
+ let stopWaiting = null;
7
+ const stop = () => {
8
+ stopWaiting?.();
9
+ stopWaiting = null;
10
+ };
11
+ const start = () => {
12
+ stop();
13
+ if (!inMenu(document.activeElement)) {
14
+ run();
15
+ return;
16
+ }
17
+ const moved = (event) => {
18
+ if (event.target instanceof Element && !inMenu(event.target)) {
19
+ stop();
20
+ run();
21
+ }
22
+ };
23
+ document.addEventListener("focusin", moved, true);
24
+ stopWaiting = () => {
25
+ document.removeEventListener("focusin", moved, true);
26
+ };
27
+ };
28
+ return { start, stop };
29
+ }
4
30
  export function createPointMenu() {
5
31
  const controller = createMenuController();
6
32
  let queued = null;
@@ -9,26 +35,20 @@ export function createPointMenu() {
9
35
  queued = null;
10
36
  action?.();
11
37
  };
38
+ const wait = createFocusWait(run);
12
39
  // Focus comes back just after ui-sdk says the menu closed, so a queued action waits for that.
13
40
  const whenFocusLeaves = () => {
14
- if (!queued) {
15
- return;
41
+ if (queued) {
42
+ wait.start();
16
43
  }
17
- if (!inMenu(document.activeElement)) {
18
- run();
19
- return;
44
+ else {
45
+ wait.stop();
20
46
  }
21
- const moved = (event) => {
22
- if (event.target instanceof Element && !inMenu(event.target)) {
23
- document.removeEventListener("focusin", moved, true);
24
- run();
25
- }
26
- };
27
- document.addEventListener("focusin", moved, true);
28
47
  };
29
48
  return {
30
49
  controller,
31
50
  open(at, payload, options = {}) {
51
+ wait.stop();
32
52
  if (controller.isOpen()) {
33
53
  controller.close();
34
54
  }
@@ -6,7 +6,7 @@ import { PageAction, linkElement } from "./page-action";
6
6
  import { useInStickyBar, usePageLabels } from "./page-context";
7
7
  import { foldedActions } from "./page-fit";
8
8
  import { MoreIcon } from "./page-icons";
9
- import { useMeasuredFit } from "./use-measured-fit";
9
+ import { fitSignature, useMeasuredFit } from "./use-measured-fit";
10
10
  /** A guess at the menu button's width, until it has been on screen once. */
11
11
  const moreGuess = 40;
12
12
  function actionProps(item) {
@@ -46,6 +46,7 @@ export function PageActions({ children }) {
46
46
  const { value, rootRef } = useMeasuredFit({
47
47
  enabled: !sticky,
48
48
  initial: "",
49
+ signature: fitSignature(items),
49
50
  decide: (sizes) => foldedActions({
50
51
  widths: items.map((_, index) => sizes.widths[index]),
51
52
  foldable,
@@ -4,7 +4,7 @@ import { Menu, MenuContent, MenuItem, MenuTrigger } from "../menu";
4
4
  import { usePageLabels } from "./page-context";
5
5
  import { hiddenCrumbs } from "./page-fit";
6
6
  import { MoreIcon } from "./page-icons";
7
- import { useMeasuredFit } from "./use-measured-fit";
7
+ import { fitSignature, useMeasuredFit } from "./use-measured-fit";
8
8
  /** A guess at the "…" button's width, until it has been on screen once. */
9
9
  const moreGuess = 48;
10
10
  /** One page on the way to this one. It lives in a `PageBreadcrumbs`. */
@@ -44,6 +44,7 @@ export function PageBreadcrumbs({ children }) {
44
44
  const { value, rootRef } = useMeasuredFit({
45
45
  enabled: true,
46
46
  initial: "0",
47
+ signature: fitSignature(crumbs),
47
48
  decide: (sizes) => String(hiddenCrumbs({
48
49
  widths: crumbs.map((_, index) => sizes.widths[index]),
49
50
  room: sizes.room,
@@ -1,3 +1,4 @@
1
+ import { type ReactNode } from "react";
1
2
  /** What a fitting part reads off the page: its own room, and how wide each item was last seen. */
2
3
  export interface Sizes {
3
4
  room: number;
@@ -6,6 +7,8 @@ export interface Sizes {
6
7
  /** The extra button's width ("More actions", "…"), once seen. */
7
8
  extra: number | undefined;
8
9
  }
10
+ /** What decides the size of the items: which there are, and what they say. A part measures again when it changes. */
11
+ export declare function fitSignature(items: readonly ReactNode[]): string;
9
12
  /**
10
13
  * Keeps a part's items sized to the room it has. The items carry `data-fit-index`, and the extra button
11
14
  * `data-fit-extra`. Each width is remembered from the last time the item was on screen, so an item that has folded
@@ -15,6 +18,8 @@ export interface Sizes {
15
18
  export declare function useMeasuredFit(options: {
16
19
  enabled: boolean;
17
20
  initial: string;
21
+ /** What the items are and say (`fitSignature`): the part measures again when it changes, and when the room does. */
22
+ signature: string;
18
23
  decide: (sizes: Sizes) => string;
19
24
  }): {
20
25
  value: string;
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
1
+ import { Children, isValidElement, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
2
2
  import { flushSync } from "react-dom";
3
3
  /** The width an item needs: an item that is cut short has shrunk, so it needs what its label lost as well. */
4
4
  function neededWidth(item) {
@@ -27,6 +27,49 @@ function readSizes(root, widths, extra) {
27
27
  extra: extra.current
28
28
  };
29
29
  }
30
+ function textOf(node) {
31
+ if (typeof node === "string" || typeof node === "number") {
32
+ return String(node);
33
+ }
34
+ if (!isValidElement(node)) {
35
+ return "";
36
+ }
37
+ const own = Object.entries(node.props)
38
+ .filter(([name]) => name !== "children")
39
+ .map(([name, prop]) => {
40
+ if (isValidElement(prop)) {
41
+ return `${name}=${textOf(prop)}`;
42
+ }
43
+ return ["string", "number", "boolean"].includes(typeof prop)
44
+ ? `${name}=${String(prop)}`
45
+ : "";
46
+ });
47
+ const type = typeof node.type === "string" ? node.type : node.type.name;
48
+ const inner = Children.toArray(node.props.children).map((child) => textOf(child));
49
+ return `<${type} ${own.join(" ")}>${inner.join("")}</>`;
50
+ }
51
+ /** What decides the size of the items: which there are, and what they say. A part measures again when it changes. */
52
+ export function fitSignature(items) {
53
+ return items
54
+ .map((item, index) => `${isValidElement(item) ? (item.key ?? index) : index}:${textOf(item)}`)
55
+ .join("|");
56
+ }
57
+ /**
58
+ * Measures after a render only when something that decides the fit changed: the items, the fit itself, or the room
59
+ * the part has. The room is read once; the other reads wait for a change.
60
+ */
61
+ function useMeasureOnChange(root, measure, key) {
62
+ const seen = useRef(null);
63
+ useLayoutEffect(() => {
64
+ const room = root ? root.clientWidth : 0;
65
+ const last = seen.current;
66
+ if (last?.measure === measure && last.key === key && last.room === room) {
67
+ return;
68
+ }
69
+ seen.current = { measure, key, room };
70
+ measure(false);
71
+ });
72
+ }
30
73
  /**
31
74
  * Keeps a part's items sized to the room it has. The items carry `data-fit-index`, and the extra button
32
75
  * `data-fit-extra`. Each width is remembered from the last time the item was on screen, so an item that has folded
@@ -34,7 +77,7 @@ function readSizes(root, widths, extra) {
34
77
  * first paint, and a resize runs it before the next. The server, and any render before the first fit, get `initial`.
35
78
  */
36
79
  export function useMeasuredFit(options) {
37
- const { enabled, initial, decide } = options;
80
+ const { enabled, initial, signature, decide } = options;
38
81
  const [value, setValue] = useState(initial);
39
82
  const [root, setRoot] = useState(null);
40
83
  const current = useRef(initial);
@@ -60,9 +103,8 @@ export function useMeasuredFit(options) {
60
103
  setValue(next);
61
104
  }
62
105
  }, [enabled, root]);
63
- useLayoutEffect(() => {
64
- measure(false);
65
- });
106
+ useMeasureOnChange(root, measure, `${signature}
107
+ ${value}`);
66
108
  useEffect(() => {
67
109
  if (!root || !enabled) {
68
110
  return undefined;
@@ -15,13 +15,23 @@ export function useStuck(enabled, header, holder) {
15
15
  const update = () => {
16
16
  setStuck(head.getBoundingClientRect().bottom <= hold.getBoundingClientRect().top + 0.5);
17
17
  };
18
+ let frame = 0;
19
+ const onScroll = () => {
20
+ if (frame === 0) {
21
+ frame = requestAnimationFrame(() => {
22
+ frame = 0;
23
+ update();
24
+ });
25
+ }
26
+ };
18
27
  update();
19
- document.addEventListener("scroll", update, { capture: true, passive: true });
28
+ document.addEventListener("scroll", onScroll, { capture: true, passive: true });
20
29
  window.addEventListener("resize", update);
21
30
  const observer = new ResizeObserver(update);
22
31
  observer.observe(head);
23
32
  return () => {
24
- document.removeEventListener("scroll", update, { capture: true });
33
+ cancelAnimationFrame(frame);
34
+ document.removeEventListener("scroll", onScroll, { capture: true });
25
35
  window.removeEventListener("resize", update);
26
36
  observer.disconnect();
27
37
  setStuck(false);
@@ -7,9 +7,11 @@ export type PaginationFit = 0 | 1 | 2;
7
7
  export declare function nextFit(current: PaginationFit, needs: readonly (number | undefined)[], room: number): PaginationFit;
8
8
  /**
9
9
  * Watches the pagination's width and steps it down a level whenever its list of pages overflows, and back up
10
- * once the room comes back. The server and the first paint get level 0.
10
+ * once the room comes back. The server and the first paint get level 0. The list is measured when it is found
11
+ * and whenever the returned `measure` is called, which what the pagination shows does.
11
12
  */
12
13
  export declare function usePaginationFit(enabled: boolean): {
13
14
  fit: PaginationFit;
14
15
  rootRef: (element: HTMLElement | null) => void;
16
+ measure: () => void;
15
17
  };
@@ -20,7 +20,8 @@ export function nextFit(current, needs, room) {
20
20
  const listSelector = ':scope > [data-slot="pagination-list"]';
21
21
  /**
22
22
  * Watches the pagination's width and steps it down a level whenever its list of pages overflows, and back up
23
- * once the room comes back. The server and the first paint get level 0.
23
+ * once the room comes back. The server and the first paint get level 0. The list is measured when it is found
24
+ * and whenever the returned `measure` is called, which what the pagination shows does.
24
25
  */
25
26
  export function usePaginationFit(enabled) {
26
27
  const [fit, setFit] = useState(0);
@@ -39,7 +40,7 @@ export function usePaginationFit(enabled) {
39
40
  setFit(next);
40
41
  }
41
42
  }, [enabled, root]);
42
- useLayoutEffect(measure);
43
+ useLayoutEffect(measure, [measure]);
43
44
  useEffect(() => {
44
45
  if (!root || !enabled) {
45
46
  return undefined;
@@ -48,5 +49,5 @@ export function usePaginationFit(enabled) {
48
49
  observer.observe(root);
49
50
  return () => observer.disconnect();
50
51
  }, [root, enabled, measure]);
51
- return { fit: enabled ? fit : 0, rootRef: setRoot };
52
+ return { fit: enabled ? fit : 0, rootRef: setRoot, measure };
52
53
  }
@@ -5,7 +5,8 @@ const indicatorSelector = ':scope > [data-slot="pagination-indicator"]';
5
5
  /**
6
6
  * Puts the indicator over the current page's link, measured within the landmark. The link is found by its page,
7
7
  * since ui-sdk marks it current only after this runs. Layout offsets ignore the
8
- * `translate` a sliding page carries, so it goes straight to where the page comes to rest. With no current link
8
+ * `translate` a sliding page carries, so it goes straight to where the page comes to rest. Every layout read
9
+ * comes before the first write, so the browser lays out once. With no current link
9
10
  * in sight (the simple and compact layouts) it hides.
10
11
  */
11
12
  function placeIndicator(list, page, instant) {
@@ -17,19 +18,25 @@ function placeIndicator(list, page, instant) {
17
18
  const item = list.querySelector(`:scope > [data-flip-key="${page}"]`);
18
19
  const link = item?.firstElementChild;
19
20
  const shown = item !== null && link instanceof HTMLElement && link.offsetParent !== null;
20
- indicator.toggleAttribute("data-hidden", !shown);
21
- root.toggleAttribute("data-indicator", shown);
22
21
  if (!shown) {
22
+ indicator.toggleAttribute("data-hidden", true);
23
+ root.toggleAttribute("data-indicator", false);
23
24
  return;
24
25
  }
25
- indicator.toggleAttribute("data-instant", instant || !Object.hasOwn(indicator.dataset, "placed"));
26
- // A sliding item is the link's offset parent while its translate runs.
27
- const within = link.offsetParent === item ? 0 : -item.offsetLeft;
28
- const withinTop = link.offsetParent === item ? 0 : -item.offsetTop;
29
- indicator.style.setProperty("--_x", `${list.offsetLeft + item.offsetLeft + link.offsetLeft + within}px`);
30
- indicator.style.setProperty("--_y", `${list.offsetTop + item.offsetTop + link.offsetTop + withinTop}px`);
31
- indicator.style.setProperty("--_w", `${link.offsetWidth}px`);
32
- indicator.style.setProperty("--_ih", `${link.offsetHeight}px`);
26
+ /* A sliding item is the link's offset parent while its translate runs. */
27
+ const gliding = link.offsetParent !== item;
28
+ const x = list.offsetLeft + item.offsetLeft + link.offsetLeft + (gliding ? -item.offsetLeft : 0);
29
+ const y = list.offsetTop + item.offsetTop + link.offsetTop + (gliding ? -item.offsetTop : 0);
30
+ const width = link.offsetWidth;
31
+ const height = link.offsetHeight;
32
+ const unplaced = !Object.hasOwn(indicator.dataset, "placed");
33
+ indicator.toggleAttribute("data-hidden", false);
34
+ root.toggleAttribute("data-indicator", true);
35
+ indicator.toggleAttribute("data-instant", instant || unplaced);
36
+ indicator.style.setProperty("--_x", `${x}px`);
37
+ indicator.style.setProperty("--_y", `${y}px`);
38
+ indicator.style.setProperty("--_w", `${width}px`);
39
+ indicator.style.setProperty("--_ih", `${height}px`);
33
40
  indicator.dataset.placed = "";
34
41
  }
35
42
  /**
@@ -207,19 +207,41 @@
207
207
  background: transparent;
208
208
  }
209
209
 
210
- :where([data-slot^="pagination-"]:is(a, button)):focus-visible {
210
+ :where(
211
+ :is(
212
+ [data-slot="pagination-link"],
213
+ [data-slot="pagination-previous"],
214
+ [data-slot="pagination-next"],
215
+ [data-slot="pagination-first"],
216
+ [data-slot="pagination-last"]
217
+ ):is(a, button)
218
+ ):focus-visible {
211
219
  outline: 2px solid var(--kumiko-pagination-focus-ring);
212
220
  outline-offset: 2px;
213
221
  z-index: 1;
214
222
  }
215
223
 
216
- :where([data-slot^="pagination-"]:is(a, button)[aria-disabled="true"]) {
224
+ :where(
225
+ :is(
226
+ [data-slot="pagination-link"],
227
+ [data-slot="pagination-previous"],
228
+ [data-slot="pagination-next"],
229
+ [data-slot="pagination-first"],
230
+ [data-slot="pagination-last"]
231
+ ):is(a, button)[aria-disabled="true"]
232
+ ) {
217
233
  opacity: var(--kumiko-pagination-disabled-opacity);
218
234
  cursor: not-allowed;
219
235
  }
220
236
 
221
237
  :where(
222
- [data-slot^="pagination-"]:is(a, button):not([aria-disabled="true"], [data-current])
238
+ :is(
239
+ [data-slot="pagination-link"],
240
+ [data-slot="pagination-previous"],
241
+ [data-slot="pagination-next"],
242
+ [data-slot="pagination-first"],
243
+ [data-slot="pagination-last"]
244
+ ):is(a, button):not([aria-disabled="true"], [data-current])
223
245
  ):active {
224
246
  scale: var(--kumiko-press-scale);
225
247
  transition-duration:
@@ -232,7 +254,13 @@
232
254
 
233
255
  @media (hover: hover) and (pointer: fine) {
234
256
  :where(
235
- [data-slot^="pagination-"]:is(a, button):not([aria-disabled="true"], [data-current])
257
+ :is(
258
+ [data-slot="pagination-link"],
259
+ [data-slot="pagination-previous"],
260
+ [data-slot="pagination-next"],
261
+ [data-slot="pagination-first"],
262
+ [data-slot="pagination-last"]
263
+ ):is(a, button):not([aria-disabled="true"], [data-current])
236
264
  ):hover {
237
265
  background: var(--kumiko-pagination-hover-bg);
238
266
  color: var(--kumiko-pagination-hover-fg);
@@ -256,7 +284,15 @@
256
284
 
257
285
  /* A finger gets a full-size target, wider than the button where needed. */
258
286
  @media (pointer: coarse) {
259
- :where([data-slot^="pagination-"]:is(a, button))::after {
287
+ :where(
288
+ :is(
289
+ [data-slot="pagination-link"],
290
+ [data-slot="pagination-previous"],
291
+ [data-slot="pagination-next"],
292
+ [data-slot="pagination-first"],
293
+ [data-slot="pagination-last"]
294
+ ):is(a, button)
295
+ )::after {
260
296
  content: "";
261
297
  position: absolute;
262
298
  inset: 50% auto auto 50%;
@@ -447,7 +483,15 @@
447
483
  color: HighlightText;
448
484
  }
449
485
 
450
- :where([data-slot^="pagination-"]:is(a, button)[aria-disabled="true"]) {
486
+ :where(
487
+ :is(
488
+ [data-slot="pagination-link"],
489
+ [data-slot="pagination-previous"],
490
+ [data-slot="pagination-next"],
491
+ [data-slot="pagination-first"],
492
+ [data-slot="pagination-last"]
493
+ ):is(a, button)[aria-disabled="true"]
494
+ ) {
451
495
  color: GrayText;
452
496
  opacity: 1;
453
497
  }
@@ -1,6 +1,6 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { createPaginationController, Pagination as SdkPagination, PaginationEllipsis, PaginationFirst, PaginationItem, PaginationLast, PaginationLink, PaginationList, PaginationNext, PaginationPrevious } from "@ui-sdk/react/pagination";
3
- import { useMemo, useState } from "react";
3
+ import { useLayoutEffect, useMemo, useState } from "react";
4
4
  import { PaginationJump, PaginationPageSize, PaginationRange } from "./pagination-extras";
5
5
  import { usePaginationFit } from "./pagination-fit";
6
6
  import { FirstIcon, LastIcon, NextIcon, PreviousIcon } from "./pagination-icons";
@@ -44,10 +44,26 @@ function Trailing({ state, options, controller, perPage, changeSize, words, form
44
44
  const { pageSizes, disabled = false } = options;
45
45
  return (_jsxs("div", { "data-slot": "pagination-trailing", children: [pageSizes && (_jsx(PaginationPageSize, { sizes: pageSizes, value: perPage, onChange: changeSize, words: words, format: format, disabled: disabled })), options.jump && (_jsx(PaginationJump, { controller: controller, pageCount: state.pageCount, words: words, disabled: disabled }))] }));
46
46
  }
47
+ /** Everything the pages and what sits beside them show, which decides how wide the list is. */
48
+ function widthKey({ state, options, perPage, appearance }) {
49
+ return [
50
+ appearance,
51
+ state.page,
52
+ state.pageCount,
53
+ state.items.join(","),
54
+ perPage,
55
+ options.total,
56
+ options.pageSizes?.join(","),
57
+ options.firstLast,
58
+ options.range,
59
+ options.jump
60
+ ].join("|");
61
+ }
47
62
  function Body(props) {
48
63
  const { state, options, perPage, words, format } = props;
49
64
  const { renderLink, getHref, total } = options;
50
65
  const [list, setList] = useState(null);
66
+ useLayoutEffect(props.measure, [props.measure, widthKey(props)]);
51
67
  usePaginationMotion(list, state.page, state.items.join(","));
52
68
  const trailing = Boolean(options.range || options.pageSizes || options.jump);
53
69
  const link = renderLink && getHref
@@ -72,6 +88,7 @@ export function Pagination(props) {
72
88
  const [own] = useState(createPaginationController);
73
89
  const controller = given ?? own;
74
90
  const { perPage, changeSize } = usePageSize(props, controller);
75
- const { fit, rootRef } = usePaginationFit(fitting);
76
- return (_jsx(SdkPagination, { "aria-label": words.navigation, ...rest, ref: rootRef, pageSize: rest.total === undefined ? undefined : perPage, siblings: fit >= 1 ? 0 : siblings, controller: controller, "data-layout": layout, "data-look": look, "data-size": size, "data-fit": fitWords[fit] || undefined, children: (state) => (_jsx(Body, { state: state, options: props, controller: controller, perPage: perPage, changeSize: changeSize, words: words, format: format })) }));
91
+ const { fit, rootRef, measure } = usePaginationFit(fitting);
92
+ const appearance = [fit, size, layout, look, siblings, locale, ...Object.values(words)].join("|");
93
+ return (_jsx(SdkPagination, { "aria-label": words.navigation, ...rest, ref: rootRef, pageSize: rest.total === undefined ? undefined : perPage, siblings: fit >= 1 ? 0 : siblings, controller: controller, "data-layout": layout, "data-look": look, "data-size": size, "data-fit": fitWords[fit] || undefined, children: (state) => (_jsx(Body, { state: state, options: props, controller: controller, perPage: perPage, changeSize: changeSize, words: words, format: format, measure: measure, appearance: appearance })) }));
77
94
  }
@@ -181,7 +181,8 @@
181
181
  }
182
182
 
183
183
  /* A soft glow at the leading end of the fill, which is its inline end. It moves with the fill. */
184
- [data-slot="progress-glow"] {
184
+ [data-slot="progress-indicator"]::before {
185
+ content: "";
185
186
  position: absolute;
186
187
  inset-block: 0;
187
188
  inset-inline-end: 0;
@@ -224,7 +225,7 @@
224
225
  animation: kumiko-progress-sheen var(--kumiko-progress-sheen-duration) ease-in-out infinite;
225
226
  }
226
227
 
227
- [data-slot="progress-indicator"][data-indeterminate] > [data-slot="progress-glow"],
228
+ [data-slot="progress-indicator"][data-indeterminate]::before,
228
229
  [data-slot="progress-indicator"][data-indeterminate] > [data-slot="progress-sheen"],
229
230
  [data-slot="progress-indicator"][data-complete] > [data-slot="progress-sheen"] {
230
231
  display: none;
@@ -1,17 +1,29 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Progress as SdkProgress, ProgressIndicator, ProgressLabel, ProgressTrack, ProgressValue } from "@ui-sdk/react/progress";
3
3
  import { useEffect, useLayoutEffect, useRef, useState } from "react";
4
+ const formatters = new Map();
5
+ /** One formatter per locale and options, so counting up does not build a new one every frame. */
6
+ function formatterFor(locale, options) {
7
+ const key = `${locale ?? ""}|${JSON.stringify(options)}`;
8
+ const known = formatters.get(key);
9
+ if (known) {
10
+ return known;
11
+ }
12
+ const made = new Intl.NumberFormat(locale, options);
13
+ formatters.set(key, made);
14
+ return made;
15
+ }
4
16
  /** The text ui-sdk would show for a value, for the numbers in between while counting. */
5
17
  function formatAt(value, { min = 0, max = 100, format, locale }) {
6
18
  if (typeof format === "function") {
7
19
  return format(value);
8
20
  }
9
21
  if (format && format.style !== "percent") {
10
- return new Intl.NumberFormat(locale, format).format(value);
22
+ return formatterFor(locale, format).format(value);
11
23
  }
12
24
  const span = max - min;
13
25
  const share = span === 0 ? 0 : (Math.min(max, Math.max(min, value)) - min) / span;
14
- return new Intl.NumberFormat(locale, format ?? { style: "percent" }).format(share);
26
+ return formatterFor(locale, format ?? { style: "percent" }).format(share);
15
27
  }
16
28
  /** The move duration, in milliseconds, that the tokens give an element. */
17
29
  function moveDuration(element) {
@@ -103,5 +115,5 @@ export function Progress({ size = "md", label, showValue = false, indeterminate
103
115
  };
104
116
  return (_jsxs(SdkProgress, { "data-size": size, "data-indeterminate-style": indeterminate, "data-kumiko-progress": looks({ recessed, floating, sheen, completeGlow, lit }), "data-finished": finished ? "" : undefined, ...props, children: [named ? _jsx(ProgressLabel, { children: label }) : null, showValue ? (_jsx(ProgressValue, { children: countUp
105
117
  ? (state) => (_jsx(CountedValue, { state: state, settings: settings }))
106
- : undefined })) : null, _jsx(ProgressTrack, { children: _jsx("div", { "data-slot": "progress-clip", children: _jsxs(ProgressIndicator, { children: [_jsx("span", { "data-slot": "progress-glow", "aria-hidden": "true" }), _jsx("span", { "data-slot": "progress-sheen", "aria-hidden": "true" })] }) }) })] }));
118
+ : undefined })) : null, _jsx(ProgressTrack, { children: _jsx("div", { "data-slot": "progress-clip", children: _jsx(ProgressIndicator, { children: _jsx("span", { "data-slot": "progress-sheen", "aria-hidden": "true" }) }) }) })] }));
107
119
  }
@@ -4,3 +4,5 @@ import { type ReactNode } from "react";
4
4
  export declare const LabelsContext: import("react").Context<readonly string[]>;
5
5
  /** Every option label that a select's `items` and children give, and its placeholder. */
6
6
  export declare function labelsOf(items: ListData<unknown> | undefined, children: ReactNode, placeholder: string | undefined): string[];
7
+ /** Whether two label lists hold the same labels in the same order. */
8
+ export declare function sameLabels(left: readonly string[], right: readonly string[]): boolean;
@@ -60,5 +60,9 @@ export function labelsOf(items, children, placeholder) {
60
60
  if (found.length > 0 && placeholder) {
61
61
  found.push(placeholder);
62
62
  }
63
- return [...new Set(found)];
63
+ return [...new Set(found.map((label) => label.replaceAll(/\s+/gu, " ").trim()))];
64
+ }
65
+ /** Whether two label lists hold the same labels in the same order. */
66
+ export function sameLabels(left, right) {
67
+ return left.length === right.length && left.every((label, at) => label === right[at]);
64
68
  }
@@ -79,7 +79,7 @@
79
79
  }
80
80
 
81
81
  /* Without a sizer, the trigger fits its value, up to the cap. */
82
- :where([data-slot="select-trigger"]:not(:has(> [data-slot="select-sizer"]))) {
82
+ :where([data-slot="select-trigger"]:not([data-sized])) {
83
83
  max-inline-size: min(var(--kumiko-select-trigger-max-width), 100%);
84
84
  }
85
85
 
@@ -93,25 +93,21 @@
93
93
  }
94
94
 
95
95
  /*
96
- * The sizer is an invisible copy of every option label, stacked in the value's cell, so the widest
97
- * one sets the trigger's own width and choosing never resizes it. Its cap is the only cap: a width
98
- * the page gives the trigger is honoured, and the value fills it.
96
+ * The sizer is an invisible copy of every option label, one per line and no taller than nothing, in
97
+ * the value's cell, so the widest one sets the trigger's own width and choosing never resizes it.
98
+ * Its cap is the only cap: a width the page gives the trigger is honoured, and the value fills it.
99
99
  */
100
100
  :where([data-slot="select-sizer"]) {
101
- display: grid;
101
+ block-size: 1lh;
102
102
  grid-area: 1 / 2;
103
103
  max-inline-size: var(--kumiko-select-trigger-max-width);
104
104
  overflow: hidden;
105
105
  pointer-events: none;
106
106
  visibility: hidden;
107
- white-space: nowrap;
108
- }
109
-
110
- :where([data-slot="select-sizer"] > *) {
111
- grid-area: 1 / 1;
107
+ white-space: pre;
112
108
  }
113
109
 
114
- :where([data-slot="select-trigger"]:has(> [data-slot="select-sizer"])) {
110
+ :where([data-slot="select-trigger"][data-sized]) {
115
111
  --_select-value-contain: inline-size;
116
112
  }
117
113
 
@@ -18,7 +18,7 @@ export type SelectTriggerProps = SdkTriggerProps & {
18
18
  };
19
19
  /**
20
20
  * The ui-sdk select trigger, with a chevron after its children unless `chevron` is `false`. It is as wide as its
21
- * longest option, which an invisible copy of every label (a sizer) gives it, so choosing never resizes it.
21
+ * longest option, which an invisible copy of every label, one per line (a sizer) gives it, so choosing never resizes it.
22
22
  */
23
23
  export declare function SelectTrigger({ chevron, tooltip, children, ref: callerRef, ...props }: SelectTriggerProps): React.JSX.Element;
24
24
  type SdkContentProps = Parameters<typeof SdkSelectContent>[0];
@@ -1,12 +1,17 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Select as SdkSelect, SelectItemText, SelectContent as SdkSelectContent, SelectItem as SdkSelectItem, SelectItemIndicator, SelectTrigger as SdkSelectTrigger } from "@ui-sdk/react/select";
3
- import { useCallback, useContext, useRef, useState } from "react";
3
+ import { useCallback, useContext, useMemo, useRef, useState } from "react";
4
4
  import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip";
5
- import { labelsOf, LabelsContext } from "./select-labels";
5
+ import { labelsOf, LabelsContext, sameLabels } from "./select-labels";
6
6
  import { SearchContext, SearchedList } from "./select-search";
7
7
  /** The ui-sdk select, which opens as a bottom sheet on small touch screens instead of always as a popover. Any `presentation` still overrides it. */
8
8
  export function Select(props) {
9
- const labels = labelsOf(props.items, props.children, props.placeholder);
9
+ const found = useMemo(() => labelsOf(props.items, props.children, props.placeholder), [props.items, props.children, props.placeholder]);
10
+ const kept = useRef(found);
11
+ if (!sameLabels(kept.current, found)) {
12
+ kept.current = found;
13
+ }
14
+ const labels = kept.current;
10
15
  return (_jsx(LabelsContext.Provider, { value: labels, children: _jsx(SdkSelect, { ...props, presentation: props.presentation ?? "auto" }) }));
11
16
  }
12
17
  /** Children with something added after them, whether they are nodes or a function of the part's state. */
@@ -53,7 +58,7 @@ function CutOffTip({ trigger, triggerRef }) {
53
58
  }
54
59
  /**
55
60
  * The ui-sdk select trigger, with a chevron after its children unless `chevron` is `false`. It is as wide as its
56
- * longest option, which an invisible copy of every label (a sizer) gives it, so choosing never resizes it.
61
+ * longest option, which an invisible copy of every label, one per line (a sizer) gives it, so choosing never resizes it.
57
62
  */
58
63
  export function SelectTrigger({ chevron = true, tooltip = true, children, ref: callerRef, ...props }) {
59
64
  const ref = useRef(null);
@@ -75,8 +80,9 @@ export function SelectTrigger({ chevron = true, tooltip = true, children, ref: c
75
80
  return undefined;
76
81
  }, [callerRef]);
77
82
  const labels = useContext(LabelsContext);
78
- const extra = (_jsxs(_Fragment, { children: [labels.length > 0 ? (_jsx("span", { "data-slot": "select-sizer", "aria-hidden": "true", children: labels.map((label) => (_jsx("span", { children: label }, label))) })) : null, chevron ? _jsx("span", { "data-slot": "select-chevron", "aria-hidden": "true" }) : null] }));
79
- const trigger = (_jsx(SdkSelectTrigger, { ...props, ref: both, children: followedBy(children, extra) }));
83
+ const sized = labels.length > 0;
84
+ const extra = (_jsxs(_Fragment, { children: [sized ? (_jsx("span", { "data-slot": "select-sizer", "aria-hidden": "true", children: labels.join("\n") })) : null, chevron ? _jsx("span", { "data-slot": "select-chevron", "aria-hidden": "true" }) : null] }));
85
+ const trigger = (_jsx(SdkSelectTrigger, { ...props, "data-sized": sized ? "" : undefined, ref: both, children: followedBy(children, extra) }));
80
86
  return tooltip ? _jsx(CutOffTip, { trigger: trigger, triggerRef: ref }) : trigger;
81
87
  }
82
88
  /** The ui-sdk select content, which opens below its trigger, aligned to its start, with a small gap. */