prime-ui-kit 0.13.0 → 0.13.1

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.
@@ -126,7 +126,7 @@ import {
126
126
  useSwatchOptions,
127
127
  useSwipeDismiss,
128
128
  visuallyHiddenClass
129
- } from "./chunk-E6SQBSDF.js";
129
+ } from "./chunk-PK2GC77E.js";
130
130
  import {
131
131
  ControlSizeProvider,
132
132
  cx,
@@ -1366,36 +1366,43 @@ function usePosition(enabled, anchorRef, layerRef, {
1366
1366
  };
1367
1367
  }
1368
1368
  const { offset, pad, arrow } = metricsRef.current;
1369
- const rect = anchor.getBoundingClientRect();
1370
- const pos = computeFloatingPosition(
1371
- resolveAnchorRect ? resolveAnchorRect(anchor, rect) : rect,
1372
- layer.offsetWidth,
1373
- layer.offsetHeight,
1374
- window.innerWidth,
1375
- window.innerHeight,
1376
- {
1377
- side: preferredSide,
1378
- align,
1379
- offset,
1380
- viewportPad: pad,
1381
- flip: true,
1382
- matchAnchorWidth,
1383
- arrowInset: arrow,
1384
- boundary: resolveBoundary?.(anchor) ?? void 0
1385
- }
1386
- );
1387
- setResolvedSide(pos.side);
1369
+ const rawRect = anchor.getBoundingClientRect();
1370
+ const rect = resolveAnchorRect ? resolveAnchorRect(anchor, rawRect) : rawRect;
1371
+ const boundary = resolveBoundary?.(anchor) ?? void 0;
1372
+ const compute = (width2, height2) => computeFloatingPosition(rect, width2, height2, window.innerWidth, window.innerHeight, {
1373
+ side: preferredSide,
1374
+ align,
1375
+ offset,
1376
+ viewportPad: pad,
1377
+ flip: true,
1378
+ matchAnchorWidth,
1379
+ arrowInset: arrow,
1380
+ boundary
1381
+ });
1388
1382
  const set = (name, value) => {
1389
1383
  if (layer.style.getPropertyValue(name) !== value) layer.style.setProperty(name, value);
1390
1384
  };
1391
1385
  const px = (n) => n === void 0 ? "" : `${n}px`;
1392
1386
  set("position", "fixed");
1387
+ let width = layer.offsetWidth;
1388
+ let height = layer.offsetHeight;
1389
+ let pos = compute(width, height);
1390
+ for (let pass = 0; pass < 3; pass++) {
1391
+ set(FLOAT_MIN_WIDTH_VAR, px(pos.minWidth));
1392
+ set(FLOAT_MAX_WIDTH_VAR, px(pos.maxWidth));
1393
+ set(FLOAT_MAX_HEIGHT_VAR, px(pos.maxHeight));
1394
+ const nextWidth = layer.offsetWidth;
1395
+ const nextHeight = layer.offsetHeight;
1396
+ if (nextWidth === width && nextHeight === height) break;
1397
+ width = nextWidth;
1398
+ height = nextHeight;
1399
+ pos = compute(width, height);
1400
+ }
1401
+ setResolvedSide(pos.side);
1393
1402
  set("top", px(pos.top));
1394
1403
  set("left", px(pos.left));
1395
- set(FLOAT_MIN_WIDTH_VAR, px(pos.minWidth));
1396
- set(FLOAT_MAX_WIDTH_VAR, px(pos.maxWidth));
1397
- set(FLOAT_MAX_HEIGHT_VAR, px(pos.maxHeight));
1398
1404
  set(FLOAT_ARROW_VAR, px(pos.arrow));
1405
+ delete layer.dataset.floatPending;
1399
1406
  },
1400
1407
  [
1401
1408
  anchorRef,
@@ -1411,9 +1418,12 @@ function usePosition(enabled, anchorRef, layerRef, {
1411
1418
  );
1412
1419
  const updateRef = React12.useRef(update);
1413
1420
  updateRef.current = update;
1421
+ const enabledRef = React12.useRef(enabled);
1422
+ enabledRef.current = enabled;
1414
1423
  const attachLayer = React12.useCallback(
1415
1424
  (node) => {
1416
1425
  layerRef.current = node;
1426
+ if (node && enabledRef.current) node.dataset.floatPending = "";
1417
1427
  setAttached(node !== null);
1418
1428
  },
1419
1429
  [layerRef]
@@ -1442,7 +1452,10 @@ function usePosition(enabled, anchorRef, layerRef, {
1442
1452
  target.addEventListener("scroll", follow, { passive: true });
1443
1453
  }
1444
1454
  window.visualViewport?.addEventListener("resize", resize);
1445
- const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(follow);
1455
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => {
1456
+ cancelAnimationFrame(frame2);
1457
+ updateRef.current(false);
1458
+ });
1446
1459
  if (layerRef.current) observer?.observe(layerRef.current);
1447
1460
  if (anchorRef.current) observer?.observe(anchorRef.current);
1448
1461
  return () => {
@@ -17,7 +17,7 @@ import {
17
17
  useControllableState,
18
18
  useFieldFrame,
19
19
  useInheritedDisabled
20
- } from "./chunk-E6SQBSDF.js";
20
+ } from "./chunk-PK2GC77E.js";
21
21
  import {
22
22
  cx
23
23
  } from "./chunk-Q3BFRQHZ.js";
@@ -4,8 +4,8 @@ import {
4
4
  ColorField,
5
5
  ColorPicker,
6
6
  parseColor
7
- } from "./chunks/chunk-ZSJMNA46.js";
8
- import "./chunks/chunk-E6SQBSDF.js";
7
+ } from "./chunks/chunk-XNOJEX55.js";
8
+ import "./chunks/chunk-PK2GC77E.js";
9
9
  import "./chunks/chunk-Q3BFRQHZ.js";
10
10
  export {
11
11
  ColorField,