@glasshome/ui 1.16.0 → 1.16.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.
@@ -1,4 +1,6 @@
1
- /** A page is one strip-width of items. The last one is whatever is left. */
1
+ /** A page is one strip-width of items. The last one is whatever is left.
2
+ * The tolerance keeps a strip a sub-pixel over its viewport on one page: both
3
+ * numbers are rounded reads of the same box. */
2
4
  export declare function pageCount(scrollWidth: number, viewport: number): number;
3
5
  /** The page a scroll position sits on, counting a half-page as turned. */
4
6
  export declare function pageOf(scrollLeft: number, viewport: number): number;
@@ -12561,7 +12561,7 @@ var fy = /*#__PURE__*/ K("<div data-slot=empty>"), py = /*#__PURE__*/ K("<div da
12561
12561
  return (() => {
12562
12562
  var e = fy();
12563
12563
  return G(e, U({ get class() {
12564
- return O("flex min-w-0 flex-1 flex-col items-center justify-center gap-6 text-balance rounded-lg border border-border/60 border-dashed p-6 text-center md:p-12", t.class);
12564
+ return O("flex min-w-0 flex-1 flex-col items-center justify-center gap-6 text-balance rounded-lg p-6 text-center md:p-12", t.class);
12565
12565
  } }, n), !1, !1), e;
12566
12566
  })();
12567
12567
  }, yy = (e) => {
@@ -13836,7 +13836,7 @@ function tx(e) {
13836
13836
  }
13837
13837
  function nx(e) {
13838
13838
  return z(vy, {
13839
- class: "gap-3 rounded-none border-none py-12",
13839
+ class: "gap-3 rounded-none py-12",
13840
13840
  get children() {
13841
13841
  return [z(yy, { get children() {
13842
13842
  return [z(k, {
@@ -13994,7 +13994,7 @@ var cx = (e) => z(Go, U(e, { preventScroll: !1 })), lx = (e) => z(Go.Trigger, U(
13994
13994
  //#endregion
13995
13995
  //#region src/solid/dock-paging.ts
13996
13996
  function vx(e, t) {
13997
- return t <= 0 ? 1 : Math.max(1, Math.ceil(e / t));
13997
+ return t <= 0 ? 1 : Math.max(1, Math.ceil((e - 1) / t));
13998
13998
  }
13999
13999
  function yx(e, t) {
14000
14000
  return t <= 0 ? 0 : Math.round(e / t);
@@ -14357,31 +14357,22 @@ var Fx = Object.assign(Nx, {
14357
14357
  let o = () => t.dockMode ?? "floating", s, [c, l] = N(!1), [u, d] = N(1), [f, p] = N(0), [m, h] = N(0), g = () => {
14358
14358
  let e = t.items.findIndex((e) => e.isActive);
14359
14359
  return e < 0 ? null : e;
14360
- }, _ = () => s && Number.parseFloat(getComputedStyle(s).columnGap) || 0, v = () => s?.querySelector("[data-slot=\"dock-item\"]")?.getBoundingClientRect().width ?? 0, y = () => {
14360
+ }, _ = () => s && Number.parseFloat(getComputedStyle(s).columnGap) || 0, v = () => s?.querySelector("[data-slot=\"dock-item\"]")?.getBoundingClientRect().width ?? 0, y = (e) => {
14361
+ let t = getComputedStyle(e);
14362
+ return (Number.parseFloat(t.paddingLeft) || 0) + (Number.parseFloat(t.paddingRight) || 0);
14363
+ }, b = () => {
14364
+ let e = s?.closest("[data-slot=\"dock\"]");
14365
+ return !e || !a ? 0 : e.clientWidth - y(e) - y(a);
14366
+ }, x = () => {
14361
14367
  if (!s) return;
14362
- let e = s.parentElement;
14363
- if (!e) {
14364
- l(s.scrollWidth > window.innerWidth);
14365
- return;
14366
- }
14367
- let t = getComputedStyle(e), n = (Number.parseFloat(t.paddingLeft) || 0) + (Number.parseFloat(t.paddingRight) || 0), r = 0;
14368
- for (let t of Array.from(e.children)) {
14369
- if (t === s) continue;
14370
- let e = getComputedStyle(t);
14371
- e.position === "absolute" || e.position === "fixed" || (r += t.getBoundingClientRect().width + (Number.parseFloat(e.marginLeft) || 0) + (Number.parseFloat(e.marginRight) || 0));
14372
- }
14373
- let i = e.clientWidth - n - r, a = s.scrollWidth > i, o = a ? xx(i, v(), _()) : 0;
14374
- o > 0 && (s.style.width = `${o}px`), l(a);
14375
- let c = o > 0 ? o : s.clientWidth;
14376
- h(c), d(vx(s.scrollWidth, c)), p(yx(s.scrollLeft, c));
14377
- }, b, x = () => {
14378
- if (s) {
14379
- if (!s.style.width) {
14380
- y();
14381
- return;
14382
- }
14383
- s.style.width = "", clearTimeout(b), b = setTimeout(y, 250);
14384
- }
14368
+ let e = b(), t = e > 0 && s.scrollWidth > e + 1;
14369
+ if (t) {
14370
+ let t = xx(e, v(), _());
14371
+ t > 0 && (s.style.width = `${t}px`);
14372
+ } else s.style.width && (s.style.width = "");
14373
+ l(t);
14374
+ let n = s.clientWidth;
14375
+ h(n), d(vx(s.scrollWidth, n)), p(yx(s.scrollLeft, n));
14385
14376
  }, S = (e) => {
14386
14377
  s && s.scrollTo({
14387
14378
  left: bx(e, m(), s.scrollWidth),
@@ -14400,10 +14391,10 @@ var Fx = Object.assign(Nx, {
14400
14391
  clearTimeout(t), t = setTimeout(x, 50);
14401
14392
  };
14402
14393
  window.addEventListener("resize", n), F(() => {
14403
- clearTimeout(e), clearTimeout(t), clearTimeout(b), window.removeEventListener("resize", n);
14394
+ clearTimeout(e), clearTimeout(t), window.removeEventListener("resize", n);
14404
14395
  });
14405
14396
  }), j(() => {
14406
- t.items.length;
14397
+ t.items.length, o();
14407
14398
  let e = setTimeout(x, 150);
14408
14399
  F(() => clearTimeout(e));
14409
14400
  }), (() => {
@@ -14478,7 +14469,7 @@ var Fx = Object.assign(Nx, {
14478
14469
  })), e;
14479
14470
  }
14480
14471
  }), null), B((e) => {
14481
- var n = O("relative isolate flex max-w-full items-center justify-center p-1.5 sm:p-2", u() > 1 && "pb-4 sm:pb-5", ge, "[--glass-lift:0.55]", o() === "floating" ? "rounded-xl" : "rounded-t-xl"), a = t.hold && !t.hold.fired ? "" : void 0, s = t.hold?.fired ? "" : void 0, l = O("absolute -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary/45", ae), f = `${r().x}px`, p = `${r().y}px`, m = `${r().r * 2}px`, g = `${r().r * 2}px`, _ = O("flex items-center gap-0.5 sm:gap-1", c() ? "scrollbar-hide snap-x snap-mandatory overflow-x-auto overscroll-x-contain scroll-smooth" : "overflow-visible", !c() && "justify-center"), v = c() ? "auto" : "fit-content";
14472
+ var n = O("pointer-events-auto relative isolate flex max-w-full items-center justify-center p-1.5 sm:p-2", u() > 1 && "pb-4 sm:pb-5", ge, "[--glass-lift:0.55]", o() === "floating" ? "rounded-xl" : "rounded-t-xl"), a = t.hold && !t.hold.fired ? "" : void 0, s = t.hold?.fired ? "" : void 0, l = O("absolute -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary/45", ae), f = `${r().x}px`, p = `${r().y}px`, m = `${r().r * 2}px`, g = `${r().r * 2}px`, _ = O("flex items-center gap-0.5 sm:gap-1", c() ? "scrollbar-hide snap-x snap-mandatory overflow-x-auto overscroll-x-contain scroll-smooth" : "overflow-visible", !c() && "justify-center"), v = c() ? "auto" : "fit-content";
14482
14473
  return n !== e.e && R(i, e.e = n), a !== e.t && W(d, "data-hold", e.t = a), s !== e.a && W(d, "data-fired", e.a = s), l !== e.o && R(d, e.o = l), f !== e.i && Ot(d, "left", e.i = f), p !== e.n && Ot(d, "top", e.n = p), m !== e.s && Ot(d, "width", e.s = m), g !== e.h && Ot(d, "height", e.h = g), _ !== e.r && R(h, e.r = _), v !== e.d && Ot(h, "min-width", e.d = v), e;
14483
14474
  }, {
14484
14475
  e: void 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/ui",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "description": "SolidJS component library for GlassHome, built on Kobalte",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/glasshome/ui#readme",
@@ -239,7 +239,7 @@ export function TableEmpty(props: {
239
239
  action?: JSX.Element;
240
240
  }) {
241
241
  return (
242
- <Empty class="gap-3 rounded-none border-none py-12">
242
+ <Empty class="gap-3 rounded-none py-12">
243
243
  <EmptyHeader>
244
244
  <Show when={props.icon}>
245
245
  <EmptyMedia media="icon">
@@ -1,7 +1,9 @@
1
- /** A page is one strip-width of items. The last one is whatever is left. */
1
+ /** A page is one strip-width of items. The last one is whatever is left.
2
+ * The tolerance keeps a strip a sub-pixel over its viewport on one page: both
3
+ * numbers are rounded reads of the same box. */
2
4
  export function pageCount(scrollWidth: number, viewport: number): number {
3
5
  if (viewport <= 0) return 1;
4
- return Math.max(1, Math.ceil(scrollWidth / viewport));
6
+ return Math.max(1, Math.ceil((scrollWidth - 1) / viewport));
5
7
  }
6
8
 
7
9
  /** The page a scroll position sits on, counting a half-page as turned. */
@@ -134,53 +134,38 @@ const Dock: Component<DockProps> = (props) => {
134
134
  const itemWidth = () =>
135
135
  containerRef?.querySelector('[data-slot="dock-item"]')?.getBoundingClientRect().width ?? 0;
136
136
 
137
+ const padX = (el: Element) => {
138
+ const style = getComputedStyle(el);
139
+ return (
140
+ (Number.parseFloat(style.paddingLeft) || 0) + (Number.parseFloat(style.paddingRight) || 0)
141
+ );
142
+ };
143
+
144
+ // The width the app gave the dock. Never the surface: it shrink-wraps this strip,
145
+ // so measuring it asks the strip how wide the strip is.
146
+ const availableWidth = () => {
147
+ const box = containerRef?.closest<HTMLElement>('[data-slot="dock"]');
148
+ if (!box || !surfaceRef) return 0;
149
+ return box.clientWidth - padX(box) - padX(surfaceRef);
150
+ };
151
+
137
152
  const checkOverflow = () => {
138
153
  if (!containerRef) return;
139
- const surface = containerRef.parentElement;
140
- if (!surface) {
141
- setNeedsScroll(containerRef.scrollWidth > window.innerWidth);
142
- return;
143
- }
144
- const surfaceStyle = getComputedStyle(surface);
145
- const paddingX =
146
- (Number.parseFloat(surfaceStyle.paddingLeft) || 0) +
147
- (Number.parseFloat(surfaceStyle.paddingRight) || 0);
148
- let siblingWidth = 0;
149
- for (const child of Array.from(surface.children)) {
150
- if (child === containerRef) continue;
151
- const childStyle = getComputedStyle(child);
152
- // The page dots overlay the bar out of flow; they do not narrow it.
153
- if (childStyle.position === "absolute" || childStyle.position === "fixed") continue;
154
- siblingWidth +=
155
- child.getBoundingClientRect().width +
156
- (Number.parseFloat(childStyle.marginLeft) || 0) +
157
- (Number.parseFloat(childStyle.marginRight) || 0);
154
+ const available = availableWidth();
155
+ const overflowing = available > 0 && containerRef.scrollWidth > available + 1;
156
+ if (overflowing) {
157
+ const trimmed = stripWidth(available, itemWidth(), gapWidth());
158
+ if (trimmed > 0) containerRef.style.width = `${trimmed}px`;
159
+ } else if (containerRef.style.width) {
160
+ containerRef.style.width = "";
158
161
  }
159
- const availableWidth = surface.clientWidth - paddingX - siblingWidth;
160
- const overflowing = containerRef.scrollWidth > availableWidth;
161
- const trimmed = overflowing ? stripWidth(availableWidth, itemWidth(), gapWidth()) : 0;
162
- if (trimmed > 0) containerRef.style.width = `${trimmed}px`;
163
162
  setNeedsScroll(overflowing);
164
- const viewport = trimmed > 0 ? trimmed : containerRef.clientWidth;
163
+ const viewport = containerRef.clientWidth;
165
164
  setViewportWidth(viewport);
166
165
  setPages(pageCount(containerRef.scrollWidth, viewport));
167
166
  setPage(pageOf(containerRef.scrollLeft, viewport));
168
167
  };
169
168
 
170
- // The surface animates its width, so a read taken right after we set one is
171
- // mid-transition: clearing our trim has to settle before the next measure.
172
- let settleId: ReturnType<typeof setTimeout> | undefined;
173
- const remeasure = () => {
174
- if (!containerRef) return;
175
- if (!containerRef.style.width) {
176
- checkOverflow();
177
- return;
178
- }
179
- containerRef.style.width = "";
180
- clearTimeout(settleId);
181
- settleId = setTimeout(checkOverflow, 250);
182
- };
183
-
184
169
  const goToPage = (next: number) => {
185
170
  if (!containerRef) return;
186
171
  containerRef.scrollTo({
@@ -198,26 +183,25 @@ const Dock: Component<DockProps> = (props) => {
198
183
  });
199
184
 
200
185
  onMount(() => {
201
- const timeoutId = setTimeout(remeasure, 100);
202
- // Watching the bar would see its own trim and re-trim forever; the viewport
203
- // is the only width the dock does not derive from itself.
186
+ const timeoutId = setTimeout(checkOverflow, 100);
204
187
  let resizeTimeoutId: ReturnType<typeof setTimeout> | undefined;
205
188
  const onResize = () => {
206
189
  clearTimeout(resizeTimeoutId);
207
- resizeTimeoutId = setTimeout(remeasure, 50);
190
+ resizeTimeoutId = setTimeout(checkOverflow, 50);
208
191
  };
209
192
  window.addEventListener("resize", onResize);
210
193
  onCleanup(() => {
211
194
  clearTimeout(timeoutId);
212
195
  clearTimeout(resizeTimeoutId);
213
- clearTimeout(settleId);
214
196
  window.removeEventListener("resize", onResize);
215
197
  });
216
198
  });
217
199
 
218
200
  createEffect(() => {
219
201
  local.items.length;
220
- const timeoutId = setTimeout(remeasure, 150);
202
+ // The box pads by mode, so switching it changes the room the strip has.
203
+ dockMode();
204
+ const timeoutId = setTimeout(checkOverflow, 150);
221
205
  onCleanup(() => clearTimeout(timeoutId));
222
206
  });
223
207
 
@@ -236,7 +220,7 @@ const Dock: Component<DockProps> = (props) => {
236
220
  data-slot="dock-surface"
237
221
  class={cn(
238
222
  // isolate: the layers behind the icons stay inside the dock even with blur off.
239
- "relative isolate flex max-w-full items-center justify-center p-1.5 sm:p-2",
223
+ "pointer-events-auto relative isolate flex max-w-full items-center justify-center p-1.5 sm:p-2",
240
224
  // Room for the page dots inside the glass; outside it they sit on
241
225
  // the screen edge and get clipped.
242
226
  pages() > 1 && "pb-4 sm:pb-5",
@@ -8,7 +8,7 @@ const Empty: Component<ComponentProps<"div">> = (props) => {
8
8
  <div
9
9
  data-slot="empty"
10
10
  class={cn(
11
- "flex min-w-0 flex-1 flex-col items-center justify-center gap-6 text-balance rounded-lg border border-border/60 border-dashed p-6 text-center md:p-12",
11
+ "flex min-w-0 flex-1 flex-col items-center justify-center gap-6 text-balance rounded-lg p-6 text-center md:p-12",
12
12
  local.class,
13
13
  )}
14
14
  {...rest}