@hansenexus/hud 0.5.2 → 0.6.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 (2) hide show
  1. package/dist/index.js +36 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -794,6 +794,8 @@ function Workspace({ appSlug, panels, apiRef, children }) {
794
794
  const CLEARANCE = 8;
795
795
  /** The pill never moves further than this share of the viewport height off its edge. */
796
796
  const MAX_SHIFT_SHARE = .4;
797
+ /** On a narrow viewport the pill takes at most this share of the width. */
798
+ const NARROW_SHARE = .4;
797
799
  /** Extra cost of a top corner when every corner needs a shift: host navs live up there. */
798
800
  const TOP_PENALTY = 48;
799
801
  const isBottom = (corner) => corner.startsWith("bottom");
@@ -854,6 +856,17 @@ function placePill(options) {
854
856
  function nearestCorner(x, y, viewport) {
855
857
  return `${y > viewport.h / 2 ? "bottom" : "top"}-${x > viewport.w / 2 ? "right" : "left"}`;
856
858
  }
859
+ const isNarrow = (viewport) => viewport.w < 900;
860
+ /**
861
+ * Width left for plugin items next to the fixed controls of `fixed` pixels
862
+ * (`chrome` is the pill's own padding and border). On a narrow viewport the
863
+ * share cap applies on top of the room pinned panels leave.
864
+ */
865
+ function itemBudget({ viewport, reserve, fixed, chrome }) {
866
+ const room = viewport.w - reserve.left - reserve.right - 24 - chrome - fixed;
867
+ if (!isNarrow(viewport)) return room;
868
+ return Math.min(room, Math.floor(viewport.w * NARROW_SHARE) - chrome - fixed);
869
+ }
857
870
  /**
858
871
  * Which plugin items fit in `budget` pixels. Higher priority first, then pill
859
872
  * order; an item that does not fit is skipped, so a smaller one after it can
@@ -1454,8 +1467,9 @@ function sameMeasure(a, b) {
1454
1467
  }
1455
1468
  /**
1456
1469
  * Fits the items into the width left by pinned panels, then places the pill.
1457
- * When no corner is free even after shifting, compact mode keeps only
1458
- * prioritised items and the pill is placed again at that size.
1470
+ * On a narrow viewport, or when no corner is free even after shifting,
1471
+ * compact mode keeps only prioritised items (within 40 percent of the width
1472
+ * on a narrow viewport) and the pill is placed at that size.
1459
1473
  */
1460
1474
  function arrange(slots, measured, options) {
1461
1475
  const { viewport, reserve } = options;
@@ -1464,23 +1478,30 @@ function arrange(slots, measured, options) {
1464
1478
  width: measured.items[plugin.id] ?? 0,
1465
1479
  priority: plugin.pillPriority ?? 0
1466
1480
  }));
1467
- const budget = viewport.w - reserve.left - reserve.right - 24 - CHROME - measured.fixed;
1481
+ const budget = itemBudget({
1482
+ viewport,
1483
+ reserve,
1484
+ fixed: measured.fixed,
1485
+ chrome: CHROME
1486
+ });
1468
1487
  const sizeOf = (visible) => ({
1469
1488
  width: CHROME + measured.fixed + items.reduce((sum, item) => sum + (visible.has(item.id) ? item.width + ITEM_GAP : 0), 0),
1470
1489
  height: measured.height
1471
1490
  });
1472
- const full = fitItems(items, budget, { gap: ITEM_GAP });
1473
- const fullSize = sizeOf(full);
1474
- const placed = placePill({
1475
- ...options,
1476
- size: fullSize
1477
- });
1478
- if (placed) return {
1479
- visible: full,
1480
- placement: placed,
1481
- size: fullSize,
1482
- compact: false
1483
- };
1491
+ if (!isNarrow(viewport)) {
1492
+ const full = fitItems(items, budget, { gap: ITEM_GAP });
1493
+ const fullSize = sizeOf(full);
1494
+ const placed = placePill({
1495
+ ...options,
1496
+ size: fullSize
1497
+ });
1498
+ if (placed) return {
1499
+ visible: full,
1500
+ placement: placed,
1501
+ size: fullSize,
1502
+ compact: false
1503
+ };
1504
+ }
1484
1505
  const compact = fitItems(items, budget, {
1485
1506
  gap: ITEM_GAP,
1486
1507
  compact: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hansenexus/hud",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "Modular dev HUD for React apps: status pill, floating panels, element grabber, plugin API.",
5
5
  "license": "MIT",
6
6
  "type": "module",