jiplak 0.1.0 → 0.1.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.
package/dist/core.d.ts CHANGED
@@ -18,5 +18,10 @@ export interface Theme {
18
18
  animate?: Animate;
19
19
  speed?: string;
20
20
  }
21
- /** Pick the capture for the largest breakpoint <= width, else the smallest one. */
21
+ /**
22
+ * Pick the capture whose captured container width is nearest to `width`.
23
+ * Compares container to container (keys are viewport widths, and a container is
24
+ * usually narrower than its viewport). Nearest, not floor, so a scrollbar that
25
+ * shaves a few px off the live container still picks the matching capture.
26
+ */
22
27
  export declare function pickCapture(bones: Bones, width: number): Capture | undefined;
package/dist/core.js CHANGED
@@ -1,6 +1,14 @@
1
- /** Pick the capture for the largest breakpoint <= width, else the smallest one. */
1
+ /**
2
+ * Pick the capture whose captured container width is nearest to `width`.
3
+ * Compares container to container (keys are viewport widths, and a container is
4
+ * usually narrower than its viewport). Nearest, not floor, so a scrollbar that
5
+ * shaves a few px off the live container still picks the matching capture.
6
+ */
2
7
  export function pickCapture(bones, width) {
3
- const bps = Object.keys(bones).map(Number).sort((a, b) => a - b);
4
- const bp = bps.filter(b => b <= width).pop() ?? bps[0];
5
- return bp === undefined ? undefined : bones[bp];
8
+ let best;
9
+ for (const c of Object.values(bones)) {
10
+ if (!best || Math.abs(c.width - width) < Math.abs(best.width - width))
11
+ best = c;
12
+ }
13
+ return best;
6
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jiplak",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Pixel-perfect skeleton loading screens, auto-captured from your real React UI.",
5
5
  "keywords": [
6
6
  "skeleton",