@kanso-labs/kanso-ui 0.45.20 → 0.45.22

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 (46) hide show
  1. package/dist/calendar/index.js +119 -11
  2. package/dist/calendar/index.js.map +1 -1
  3. package/dist/calendar/styles.js +19 -1
  4. package/dist/calendar/styles.js.map +1 -1
  5. package/dist/components/app-bar/index.d.ts +8 -2
  6. package/dist/components/app-bar/index.js +123 -73
  7. package/dist/components/app-bar/index.js.map +1 -1
  8. package/dist/components/calendar/index.d.ts +3 -3
  9. package/dist/components/calendar/index.js +8 -19
  10. package/dist/components/calendar/index.js.map +1 -1
  11. package/dist/components/carousel/index.d.ts +22 -3
  12. package/dist/components/carousel/index.js +26 -14
  13. package/dist/components/carousel/index.js.map +1 -1
  14. package/dist/components/chip-group/index.js +3 -0
  15. package/dist/components/chip-group/index.js.map +1 -1
  16. package/dist/components/color-picker/index.js +64 -46
  17. package/dist/components/color-picker/index.js.map +1 -1
  18. package/dist/components/color-swatch/index.js +20 -16
  19. package/dist/components/color-swatch/index.js.map +1 -1
  20. package/dist/components/copy-field/index.js +1 -0
  21. package/dist/components/copy-field/index.js.map +1 -1
  22. package/dist/components/date-range-picker/index.js +165 -81
  23. package/dist/components/date-range-picker/index.js.map +1 -1
  24. package/dist/components/index.d.ts +2 -2
  25. package/dist/components/popover/index.js +14 -4
  26. package/dist/components/popover/index.js.map +1 -1
  27. package/dist/components/range-calendar/index.js +53 -80
  28. package/dist/components/range-calendar/index.js.map +1 -1
  29. package/dist/components/segmented-button/index.js +261 -145
  30. package/dist/components/segmented-button/index.js.map +1 -1
  31. package/dist/components/sheet/index.js +149 -82
  32. package/dist/components/sheet/index.js.map +1 -1
  33. package/dist/components/table/index.js +251 -123
  34. package/dist/components/table/index.js.map +1 -1
  35. package/dist/hooks/useRipple.js +3 -2
  36. package/dist/hooks/useRipple.js.map +1 -1
  37. package/dist/index.d.ts +2 -2
  38. package/dist/segments/index.js +2 -1
  39. package/dist/segments/index.js.map +1 -1
  40. package/dist/segments/styles.js +5 -1
  41. package/dist/segments/styles.js.map +1 -1
  42. package/dist/styles/focus.js.map +1 -1
  43. package/dist/styles.css +40 -8
  44. package/dist/swatch/index.js +19 -0
  45. package/dist/swatch/index.js.map +1 -0
  46. package/package.json +3 -3
@@ -8,12 +8,16 @@ import { focus } from "../../styles/focus.js";
8
8
  import { mergeStatefulStyles } from "../../styles/merge.js";
9
9
  import { spacing } from "../../tokens/design.tokens.stylex.js";
10
10
  import { c } from "react/compiler-runtime";
11
- import { createContext, createElement, useContext, useLayoutEffect, useState } from "react";
11
+ import { createContext, createElement, useContext, useEffect, useLayoutEffect, useState } from "react";
12
12
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
13
13
  import { SelectionIndicator, ToggleButton, ToggleButtonGroup } from "react-aria-components";
14
14
  // src/components/segmented-button/index.tsx
15
15
  const ShowSelectedIconContext = createContext(true);
16
16
  const SelectionModeContext = createContext("single");
17
+ const CrowdingContext = createContext({
18
+ crowded: false,
19
+ report: () => void 0
20
+ });
17
21
  function keyOf(segment) {
18
22
  const written = segment.dataset.key;
19
23
  if (written === void 0) return null;
@@ -181,14 +185,16 @@ function indicatorClassName(isDisabled, selectionMode, marked) {
181
185
  15: { className: "xrldhhw x12tjb6f x1g25zgg xleywy5 x9f619 x1jz8bvi x47corl x10l6tqk x8knxv4 x12w9bfk x1qno0dh x19991ni xpc4ca7 xepofeg x9yvj25 xmnqt3w xx61lck x2h6xq1 xg01cxk" }
182
186
  })[!!(selectionMode === "multiple") << 3 | !!!marked << 2 | !!isDisabled << 1 | !!(state.isEntering || state.isExiting) << 0].className ?? "";
183
187
  }
184
- function segmentContent(children, icon, ripple, selectionMode, marked, labelRef, labelTitle) {
188
+ function segmentContent(children, icon, ripple, selectionMode, marked, crowded, labelRef, labelTitle) {
185
189
  const labelled = hasLabel(children);
186
190
  const reserves = marked || icon !== void 0;
191
+ const checks = marked && !crowded;
192
+ const shown = crowded && labelled ? void 0 : icon;
187
193
  return (state) => {
188
- const glyph = glyphFor(state, icon, marked);
194
+ const glyph = glyphFor(state, shown, checks);
189
195
  const drawn = glyph !== null;
190
196
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
191
- /* @__PURE__ */ jsx(SelectionIndicator, { className: indicatorClassName(state.isDisabled, selectionMode, marked) }),
197
+ /* @__PURE__ */ jsx(SelectionIndicator, { className: indicatorClassName(state.isDisabled, selectionMode, checks) }),
192
198
  /* @__PURE__ */ jsx("span", { ...{
193
199
  0: { className: "x12w9bfk xtwfq29 x1pjcqnp x9f619 x1jz8bvi xg01cxk x47corl x10l6tqk x1qno0dh x19991ni xpc4ca7 x8knxv4" },
194
200
  4: { className: "x12w9bfk xtwfq29 x1pjcqnp x9f619 x1jz8bvi x47corl x10l6tqk x1qno0dh x19991ni xpc4ca7 x8knxv4 xe2qvxb" },
@@ -215,10 +221,10 @@ function segmentContent(children, icon, ripple, selectionMode, marked, labelRef,
215
221
  ref: labelRef,
216
222
  title: labelTitle,
217
223
  ...{
218
- 0: { className: "x12w9bfk x2lah0s x193iq5w xeuugli xb3r6kr xlyipyv x1qno0dh xrtqwew xpc4ca7 xuxw1ft" },
219
- 2: { className: "x12w9bfk x2lah0s xeuugli xb3r6kr xlyipyv x1qno0dh xrtqwew xpc4ca7 xuxw1ft x1tpxo8" },
220
- 1: { className: "x12w9bfk x2lah0s x193iq5w xeuugli xb3r6kr xlyipyv x1qno0dh xrtqwew xpc4ca7 xuxw1ft x1g12otp" },
221
- 3: { className: "x12w9bfk x2lah0s xeuugli xb3r6kr xlyipyv x1qno0dh xrtqwew xpc4ca7 xuxw1ft x1tpxo8 x1g12otp" }
224
+ 0: { className: "x12w9bfk x2lah0s x193iq5w xeuugli xb3r6kr x37ujze xlyipyv x1qno0dh xrtqwew xpc4ca7 xuxw1ft" },
225
+ 2: { className: "x12w9bfk x2lah0s xeuugli xb3r6kr x37ujze xlyipyv x1qno0dh xrtqwew xpc4ca7 xuxw1ft x1tpxo8" },
226
+ 1: { className: "x12w9bfk x2lah0s x193iq5w xeuugli xb3r6kr x37ujze xlyipyv x1qno0dh xrtqwew xpc4ca7 xuxw1ft x1g12otp" },
227
+ 3: { className: "x12w9bfk x2lah0s xeuugli xb3r6kr x37ujze xlyipyv x1qno0dh xrtqwew xpc4ca7 xuxw1ft x1tpxo8 x1g12otp" }
222
228
  }[!!drawn << 1 | !!(state.isSelected && !state.isDisabled) << 0],
223
229
  children
224
230
  }),
@@ -262,123 +268,194 @@ function segmentContent(children, icon, ripple, selectionMode, marked, labelRef,
262
268
  * element a layout positions.
263
269
  */
264
270
  function SegmentedButton(t0) {
265
- const $ = c(29);
266
- let T0;
267
- let T1;
268
- let T2;
269
- let t1;
270
- let t2;
271
+ const $ = c(25);
272
+ const { disallowEmptySelection, render, selectionMode: t1, showSelectedIcon: t2, ...props } = t0;
273
+ const selectionMode = t1 === void 0 ? "single" : t1;
274
+ const showSelectedIcon = t2 === void 0 ? true : t2;
275
+ const single = selectionMode === "single";
276
+ const [crowding, setCrowding] = useState(NONE_CROWDED);
271
277
  let t3;
278
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
279
+ t3 = (key, crowds) => {
280
+ setCrowding((current) => {
281
+ if (current.has(key) === crowds) return current;
282
+ const next = new Set(current);
283
+ if (crowds) next.add(key);
284
+ else next.delete(key);
285
+ return next;
286
+ });
287
+ };
288
+ $[0] = t3;
289
+ } else t3 = $[0];
290
+ const report = t3;
291
+ const crowded = crowding.size > 0;
272
292
  let t4;
273
- let t5;
293
+ if ($[1] !== crowded) {
294
+ t4 = {
295
+ crowded,
296
+ report
297
+ };
298
+ $[1] = crowded;
299
+ $[2] = t4;
300
+ } else t4 = $[2];
301
+ const crowdingValue = t4;
302
+ const T0 = ShowSelectedIconContext;
303
+ const T1 = SelectionModeContext;
304
+ const T2 = CrowdingContext;
305
+ const T3 = ToggleButtonGroup;
306
+ const t5 = disallowEmptySelection ?? single;
274
307
  let t6;
275
- let t7;
276
- if ($[0] !== t0) {
277
- const { disallowEmptySelection, render, selectionMode: t8, showSelectedIcon: t9, ...props } = t0;
278
- const selectionMode = t8 === void 0 ? "single" : t8;
279
- const showSelectedIcon = t9 === void 0 ? true : t9;
280
- const single = selectionMode === "single";
281
- T2 = ShowSelectedIconContext;
282
- t7 = showSelectedIcon;
283
- T1 = SelectionModeContext;
284
- t6 = selectionMode;
285
- T0 = ToggleButtonGroup;
286
- t1 = props;
287
- t2 = disallowEmptySelection ?? single;
288
- if ($[11] !== render || $[12] !== single) {
289
- t3 = single ? radioGroupRenderer(render) : render;
290
- $[11] = render;
291
- $[12] = single;
292
- $[13] = t3;
293
- } else t3 = $[13];
294
- t4 = selectionMode;
295
- t5 = mergeStatefulStyles({ className: "x9f619 xwz0xwf xu6a5m6 x1mt1orb xc8icb0" }, props);
296
- $[0] = t0;
297
- $[1] = T0;
298
- $[2] = T1;
299
- $[3] = T2;
300
- $[4] = t1;
301
- $[5] = t2;
302
- $[6] = t3;
303
- $[7] = t4;
304
- $[8] = t5;
305
- $[9] = t6;
306
- $[10] = t7;
307
- } else {
308
- T0 = $[1];
309
- T1 = $[2];
310
- T2 = $[3];
311
- t1 = $[4];
312
- t2 = $[5];
313
- t3 = $[6];
314
- t4 = $[7];
315
- t5 = $[8];
316
- t6 = $[9];
317
- t7 = $[10];
318
- }
308
+ if ($[3] !== render || $[4] !== single) {
309
+ t6 = single ? radioGroupRenderer(render) : render;
310
+ $[3] = render;
311
+ $[4] = single;
312
+ $[5] = t6;
313
+ } else t6 = $[5];
314
+ const t7 = mergeStatefulStyles({ className: "x9f619 xwz0xwf xu6a5m6 x1mt1orb xc8icb0" }, props);
319
315
  let t8;
320
- if ($[14] !== T0 || $[15] !== t1 || $[16] !== t2 || $[17] !== t3 || $[18] !== t4 || $[19] !== t5) {
321
- t8 = /* @__PURE__ */ jsx(T0, {
322
- ...t1,
323
- disallowEmptySelection: t2,
324
- render: t3,
325
- selectionMode: t4,
326
- ...t5
316
+ if ($[6] !== T3 || $[7] !== props || $[8] !== selectionMode || $[9] !== t5 || $[10] !== t6 || $[11] !== t7) {
317
+ t8 = /* @__PURE__ */ jsx(T3, {
318
+ ...props,
319
+ disallowEmptySelection: t5,
320
+ render: t6,
321
+ selectionMode,
322
+ ...t7
327
323
  });
328
- $[14] = T0;
329
- $[15] = t1;
330
- $[16] = t2;
331
- $[17] = t3;
332
- $[18] = t4;
333
- $[19] = t5;
334
- $[20] = t8;
335
- } else t8 = $[20];
324
+ $[6] = T3;
325
+ $[7] = props;
326
+ $[8] = selectionMode;
327
+ $[9] = t5;
328
+ $[10] = t6;
329
+ $[11] = t7;
330
+ $[12] = t8;
331
+ } else t8 = $[12];
336
332
  let t9;
337
- if ($[21] !== T1 || $[22] !== t6 || $[23] !== t8) {
338
- t9 = /* @__PURE__ */ jsx(T1, {
339
- value: t6,
333
+ if ($[13] !== T2 || $[14] !== crowdingValue || $[15] !== t8) {
334
+ t9 = /* @__PURE__ */ jsx(T2, {
335
+ value: crowdingValue,
340
336
  children: t8
341
337
  });
342
- $[21] = T1;
343
- $[22] = t6;
344
- $[23] = t8;
345
- $[24] = t9;
346
- } else t9 = $[24];
338
+ $[13] = T2;
339
+ $[14] = crowdingValue;
340
+ $[15] = t8;
341
+ $[16] = t9;
342
+ } else t9 = $[16];
347
343
  let t10;
348
- if ($[25] !== T2 || $[26] !== t7 || $[27] !== t9) {
349
- t10 = /* @__PURE__ */ jsx(T2, {
350
- value: t7,
344
+ if ($[17] !== T1 || $[18] !== selectionMode || $[19] !== t9) {
345
+ t10 = /* @__PURE__ */ jsx(T1, {
346
+ value: selectionMode,
351
347
  children: t9
352
348
  });
353
- $[25] = T2;
354
- $[26] = t7;
355
- $[27] = t9;
356
- $[28] = t10;
357
- } else t10 = $[28];
358
- return t10;
349
+ $[17] = T1;
350
+ $[18] = selectionMode;
351
+ $[19] = t9;
352
+ $[20] = t10;
353
+ } else t10 = $[20];
354
+ let t11;
355
+ if ($[21] !== T0 || $[22] !== showSelectedIcon || $[23] !== t10) {
356
+ t11 = /* @__PURE__ */ jsx(T0, {
357
+ value: showSelectedIcon,
358
+ children: t10
359
+ });
360
+ $[21] = T0;
361
+ $[22] = showSelectedIcon;
362
+ $[23] = t10;
363
+ $[24] = t11;
364
+ } else t11 = $[24];
365
+ return t11;
359
366
  }
367
+ const NONE_CROWDED = /* @__PURE__ */ new Set();
360
368
  /**
361
369
  * One segment. Its `id` is what selection is reported by, and its label is
362
370
  * what names it. A chosen segment draws a check before the label; an
363
371
  * unchosen one draws whatever `icon` holds, if anything.
364
372
  */
365
373
  function SegmentedButtonSegment(t0) {
366
- const $ = c(23);
367
- const { children, disableRipple: t1, icon, onClick, onContextMenu, onKeyDown, onKeyUp, onPointerCancel, onPointerDown, onPointerLeave, onPointerUp, render, ...props } = t0;
374
+ const $ = c(49);
375
+ let children;
376
+ let icon;
377
+ let onClick;
378
+ let onContextMenu;
379
+ let onKeyDown;
380
+ let onKeyUp;
381
+ let onPointerCancel;
382
+ let onPointerDown;
383
+ let onPointerLeave;
384
+ let onPointerUp;
385
+ let props;
386
+ let render;
387
+ let t1;
388
+ if ($[0] !== t0) {
389
+ ({children, disableRipple: t1, icon, onClick, onContextMenu, onKeyDown, onKeyUp, onPointerCancel, onPointerDown, onPointerLeave, onPointerUp, render, ...props} = t0);
390
+ $[0] = t0;
391
+ $[1] = children;
392
+ $[2] = icon;
393
+ $[3] = onClick;
394
+ $[4] = onContextMenu;
395
+ $[5] = onKeyDown;
396
+ $[6] = onKeyUp;
397
+ $[7] = onPointerCancel;
398
+ $[8] = onPointerDown;
399
+ $[9] = onPointerLeave;
400
+ $[10] = onPointerUp;
401
+ $[11] = props;
402
+ $[12] = render;
403
+ $[13] = t1;
404
+ } else {
405
+ children = $[1];
406
+ icon = $[2];
407
+ onClick = $[3];
408
+ onContextMenu = $[4];
409
+ onKeyDown = $[5];
410
+ onKeyUp = $[6];
411
+ onPointerCancel = $[7];
412
+ onPointerDown = $[8];
413
+ onPointerLeave = $[9];
414
+ onPointerUp = $[10];
415
+ props = $[11];
416
+ render = $[12];
417
+ t1 = $[13];
418
+ }
368
419
  const disableRipple = t1 === void 0 ? false : t1;
369
420
  const selectionMode = useContext(SelectionModeContext);
370
421
  const marked = useContext(ShowSelectedIconContext) && hasLabel(children);
371
422
  const [label, setLabel] = useState(null);
372
- const labelTitle = useTruncatedText(label);
423
+ const fit = useLabelFit(label);
424
+ const { crowded, report } = useContext(CrowdingContext);
425
+ const crowds = fit.crowds && (marked || icon !== void 0);
426
+ let t2;
427
+ let t3;
428
+ if ($[14] !== crowds || $[15] !== props.id || $[16] !== report) {
429
+ t2 = () => {
430
+ report(props.id, crowds);
431
+ return () => {
432
+ report(props.id, false);
433
+ };
434
+ };
435
+ t3 = [
436
+ crowds,
437
+ props.id,
438
+ report
439
+ ];
440
+ $[14] = crowds;
441
+ $[15] = props.id;
442
+ $[16] = report;
443
+ $[17] = t2;
444
+ $[18] = t3;
445
+ } else {
446
+ t2 = $[17];
447
+ t3 = $[18];
448
+ }
449
+ useEffect(t2, t3);
373
450
  const element = {
374
451
  aria: ariaAttributesOf(props),
375
452
  onKeyDown,
376
453
  onKeyUp
377
454
  };
378
455
  const disabledByGroup = useToggleGroupDisabled(props.id);
379
- let t2;
380
- if ($[0] !== onClick || $[1] !== onContextMenu || $[2] !== onPointerCancel || $[3] !== onPointerDown || $[4] !== onPointerLeave || $[5] !== onPointerUp) {
381
- t2 = {
456
+ let t4;
457
+ if ($[19] !== onClick || $[20] !== onContextMenu || $[21] !== onPointerCancel || $[22] !== onPointerDown || $[23] !== onPointerLeave || $[24] !== onPointerUp) {
458
+ t4 = {
382
459
  onClick,
383
460
  onContextMenu,
384
461
  onPointerCancel,
@@ -386,80 +463,101 @@ function SegmentedButtonSegment(t0) {
386
463
  onPointerLeave,
387
464
  onPointerUp
388
465
  };
389
- $[0] = onClick;
390
- $[1] = onContextMenu;
391
- $[2] = onPointerCancel;
392
- $[3] = onPointerDown;
393
- $[4] = onPointerLeave;
394
- $[5] = onPointerUp;
395
- $[6] = t2;
396
- } else t2 = $[6];
397
- const ripple = useRipple(!disableRipple && props.isDisabled !== true && !disabledByGroup, t2);
466
+ $[19] = onClick;
467
+ $[20] = onContextMenu;
468
+ $[21] = onPointerCancel;
469
+ $[22] = onPointerDown;
470
+ $[23] = onPointerLeave;
471
+ $[24] = onPointerUp;
472
+ $[25] = t4;
473
+ } else t4 = $[25];
474
+ const ripple = useRipple(!disableRipple && props.isDisabled !== true && !disabledByGroup, t4);
398
475
  const T0 = ToggleButton;
399
- const t3 = selectionMode === "single" ? JSON.stringify(props.id) : void 0;
400
- const t4 = toggleButtonRenderer(element, render);
401
- const t5 = ripple.handlers;
402
- const t6 = mergeStatefulStyles(segmentStyles(marked), props);
403
- let t7;
404
- if ($[7] !== children || $[8] !== icon || $[9] !== labelTitle || $[10] !== marked || $[11] !== ripple || $[12] !== selectionMode || $[13] !== setLabel) {
405
- t7 = segmentContent(children, icon, ripple, selectionMode, marked, setLabel, labelTitle);
406
- $[7] = children;
407
- $[8] = icon;
408
- $[9] = labelTitle;
409
- $[10] = marked;
410
- $[11] = ripple;
411
- $[12] = selectionMode;
412
- $[13] = setLabel;
413
- $[14] = t7;
414
- } else t7 = $[14];
476
+ let t5;
477
+ if ($[26] !== props.id || $[27] !== selectionMode) {
478
+ t5 = selectionMode === "single" ? JSON.stringify(props.id) : void 0;
479
+ $[26] = props.id;
480
+ $[27] = selectionMode;
481
+ $[28] = t5;
482
+ } else t5 = $[28];
483
+ const t6 = toggleButtonRenderer(element, render);
484
+ const t7 = ripple.handlers;
415
485
  let t8;
416
- if ($[15] !== T0 || $[16] !== props || $[17] !== ripple.handlers || $[18] !== t3 || $[19] !== t4 || $[20] !== t6 || $[21] !== t7) {
417
- t8 = /* @__PURE__ */ jsx(T0, {
418
- "data-key": t3,
419
- render: t4,
420
- ...t5,
486
+ if ($[29] !== crowded || $[30] !== marked || $[31] !== props) {
487
+ t8 = mergeStatefulStyles(segmentStyles(marked && !crowded), props);
488
+ $[29] = crowded;
489
+ $[30] = marked;
490
+ $[31] = props;
491
+ $[32] = t8;
492
+ } else t8 = $[32];
493
+ let t9;
494
+ if ($[33] !== children || $[34] !== crowded || $[35] !== fit.title || $[36] !== icon || $[37] !== marked || $[38] !== ripple || $[39] !== selectionMode) {
495
+ t9 = segmentContent(children, icon, ripple, selectionMode, marked, crowded, setLabel, fit.title);
496
+ $[33] = children;
497
+ $[34] = crowded;
498
+ $[35] = fit.title;
499
+ $[36] = icon;
500
+ $[37] = marked;
501
+ $[38] = ripple;
502
+ $[39] = selectionMode;
503
+ $[40] = t9;
504
+ } else t9 = $[40];
505
+ let t10;
506
+ if ($[41] !== T0 || $[42] !== props || $[43] !== ripple.handlers || $[44] !== t5 || $[45] !== t6 || $[46] !== t8 || $[47] !== t9) {
507
+ t10 = /* @__PURE__ */ jsx(T0, {
508
+ "data-key": t5,
509
+ render: t6,
510
+ ...t7,
421
511
  ...props,
422
- ...t6,
423
- children: t7
512
+ ...t8,
513
+ children: t9
424
514
  });
425
- $[15] = T0;
426
- $[16] = props;
427
- $[17] = ripple.handlers;
428
- $[18] = t3;
429
- $[19] = t4;
430
- $[20] = t6;
431
- $[21] = t7;
432
- $[22] = t8;
433
- } else t8 = $[22];
434
- return t8;
515
+ $[41] = T0;
516
+ $[42] = props;
517
+ $[43] = ripple.handlers;
518
+ $[44] = t5;
519
+ $[45] = t6;
520
+ $[46] = t8;
521
+ $[47] = t9;
522
+ $[48] = t10;
523
+ } else t10 = $[48];
524
+ return t10;
435
525
  }
436
526
  function segmentStyles(marked) {
437
527
  return (state) => props(styles.segment, focus.ring, state.isSelected ? styles.segmentSelected : styles.segmentUnselected, state.isSelected && !marked && styles.segmentSelectedUnmarked, state.isDisabled && styles.segmentDisabled);
438
528
  }
439
- function useTruncatedText(label) {
529
+ function useLabelFit(label) {
440
530
  const $ = c(3);
441
- const [text, setText] = useState(void 0);
531
+ const [fit, setFit] = useState(FITS);
442
532
  let t0;
443
533
  let t1;
444
534
  if ($[0] !== label) {
445
535
  t0 = () => {
446
- if (label === null) return;
536
+ const segment = label?.parentElement;
537
+ if (label === null || segment === null || segment === void 0) return;
447
538
  const measure = () => {
448
- const cut = label.scrollWidth > label.clientWidth;
449
- setText(cut && label.textContent !== "" ? label.textContent : void 0);
539
+ const title = label.scrollWidth > label.clientWidth && label.textContent !== "" ? label.textContent : void 0;
540
+ const crowds = textWidthOf(label) + Number.parseFloat(getComputedStyle(label).scrollMarginInlineStart) > contentWidthOf(segment);
541
+ setFit((current) => current.title === title && current.crowds === crowds ? current : {
542
+ crowds,
543
+ title
544
+ });
450
545
  };
451
546
  measure();
452
547
  const resize = new ResizeObserver(measure);
453
548
  resize.observe(label);
549
+ resize.observe(segment);
454
550
  const relabel = new MutationObserver(measure);
455
551
  relabel.observe(label, {
456
552
  characterData: true,
457
553
  childList: true,
458
554
  subtree: true
459
555
  });
556
+ document.fonts.addEventListener("loadingdone", measure);
460
557
  return () => {
461
558
  resize.disconnect();
462
559
  relabel.disconnect();
560
+ document.fonts.removeEventListener("loadingdone", measure);
463
561
  };
464
562
  };
465
563
  t1 = [label];
@@ -471,7 +569,25 @@ function useTruncatedText(label) {
471
569
  t1 = $[2];
472
570
  }
473
571
  useLayoutEffect(t0, t1);
474
- return text;
572
+ return fit;
573
+ }
574
+ const FITS = {
575
+ crowds: false,
576
+ title: void 0
577
+ };
578
+ function contentWidthOf(segment) {
579
+ const style = getComputedStyle(segment);
580
+ return segment.getBoundingClientRect().width - [
581
+ style.borderInlineStartWidth,
582
+ style.borderInlineEndWidth,
583
+ style.paddingInlineStart,
584
+ style.paddingInlineEnd
585
+ ].reduce((sum, length) => sum + Number.parseFloat(length), 0);
586
+ }
587
+ function textWidthOf(label) {
588
+ const range = document.createRange();
589
+ range.selectNodeContents(label);
590
+ return range.getBoundingClientRect().width;
475
591
  }
476
592
  SegmentedButton.Segment = SegmentedButtonSegment;
477
593
  export { SegmentedButtonSegment, SegmentedButton as default };