@zakisheriff/liquid-glass 0.3.12 → 0.3.13

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/README.md CHANGED
@@ -26,7 +26,7 @@
26
26
  <br />
27
27
  <br />
28
28
 
29
- <a href="https://liquidglass.theatom.lk/docs#demo"><img src="https://raw.githubusercontent.com/zakisheriff/Liquid-Glass/main/.github/demo-cover.webp" alt="Liquid Glass playground: buttons, sliders, switches, tab bar, menu and sheet. Click to watch the demo video." width="100%" /></a>
29
+ <a href="https://liquidglass.theatom.lk/docs#demo"><img src="https://raw.githubusercontent.com/zakisheriff/Liquid-Glass/main/.github/demo-cover-2.webp" alt="Liquid Glass playground: buttons, sliders, switches, tab bar, menu and sheet. Click to watch the demo video." width="100%" /></a>
30
30
 
31
31
  **[▶ Click to watch the demo video](https://liquidglass.theatom.lk/docs#demo)**
32
32
 
@@ -533,6 +533,8 @@ About **31 KB of JavaScript and 5.5 KB of CSS gzipped**, with **no runtime depen
533
533
  - Refraction maps are computed once per glass size, cached and shared, then drawn by the browser. Nothing is recalculated while you scroll.
534
534
  - Springs run on one shared animation frame loop and stop when they settle.
535
535
  - Lens copies only copy and lay out content while a control is pressed, and stop entirely off screen.
536
+ - Refraction pauses while the page scrolls and for glass off screen; blur and the rim carry the look in motion.
537
+ - On slower devices resting surfaces keep blur and rim only, and lenses still bend while held. The quality is picked from the device and the first scrolls; `setGlassQuality('high' | 'low' | 'auto')` pins it.
536
538
  - The demo page, with 99 glass elements, holds about 11 MB of JavaScript memory and renders at 60 fps in Chrome.
537
539
 
538
540
  The GPU cost is in what moves *under* the glass. Keep large refracting panels over static or slow content, prefer a few large glass surfaces over many small overlapping ones, and lower `intensity` (or use `GlassCard variant="clear"`) for low-end devices.
@@ -554,12 +556,12 @@ function Droplet() {
554
556
  }
555
557
  ```
556
558
 
557
- `createSpring`, `SPRINGS` and `haptic()` are exported too.
559
+ Lenses take `stretch: 1` for the iOS rim, where light under the edge smears out to it. `createSpring`, `SPRINGS`, `haptic()` and `setGlassQuality()` are exported too.
558
560
 
559
561
  ## Browser support
560
562
 
561
563
  - **Chrome / Edge / Arc:** live refraction of anything behind the glass through `backdrop-filter: url(#svg)`. Tab and segmented lenses refract a tinted live copy of the bar, so everything inside the lens takes the active colour.
562
- - **Safari:** lenses (switch, slider, tab bar, segmented) show a magnified live copy of the content beneath them. Bars, buttons and cards over arbitrary page content get frosting, rims and motion.
564
+ - **Safari:** lenses (switch, slider, tab bar, segmented) refract a live copy of the content beneath them, bending and stretching it into the rim. Bars, buttons and cards over arbitrary page content get frosting, rims and motion.
563
565
  - **Firefox:** uses the same path as Safari; not yet tested.
564
566
  - Respects `prefers-reduced-motion` and `prefers-reduced-transparency`.
565
567
 
package/dist/index.js CHANGED
@@ -733,6 +733,7 @@ function bake(width, height, radius, shape, pad = 0, simple = false, fringe = fa
733
733
  const t = clamp((Math.abs(py) - (edge - 2)) / 3, 0, 1);
734
734
  return 1 - t * t * (3 - 2 * t);
735
735
  };
736
+ const flat = simple && magnify ? Infinity : Math.max(shape.bezel * 1.7, 5);
736
737
  for (let y = 0; y < ch; y++) {
737
738
  for (let x = 0; x < cw; x++) {
738
739
  const px = (x + 0.5) * W / cw - W / 2;
@@ -743,6 +744,10 @@ function bake(width, height, radius, shape, pad = 0, simple = false, fringe = fa
743
744
  const oy = Math.max(qy, 0);
744
745
  const len = Math.hypot(ox, oy);
745
746
  const d = radius - (len + Math.min(Math.max(qx, qy), 0));
747
+ if (d > flat) {
748
+ inside[y * cw + x] = 1;
749
+ continue;
750
+ }
746
751
  let nx;
747
752
  let ny;
748
753
  if (len > 0) {
@@ -1000,6 +1005,34 @@ function glassFor(width, height, radius, shape = {}, pad = 0, simple = false, fr
1000
1005
  }
1001
1006
  return baked;
1002
1007
  }
1008
+ var soon = [];
1009
+ var later = [];
1010
+ var pumping = false;
1011
+ function pump() {
1012
+ pumping = true;
1013
+ const run = (deadline) => {
1014
+ const end = performance.now() + 8;
1015
+ const left = () => deadline ? deadline.timeRemaining() > 4 : performance.now() < end;
1016
+ let ran = 0;
1017
+ while ((soon.length || later.length) && (ran === 0 || left())) {
1018
+ (soon.shift() ?? later.shift())();
1019
+ ran++;
1020
+ }
1021
+ if (soon.length || later.length) idle(run);
1022
+ else pumping = false;
1023
+ };
1024
+ idle(run);
1025
+ }
1026
+ function bakeSoon(job, urgent = true) {
1027
+ (urgent ? soon : later).push(job);
1028
+ if (!pumping) pump();
1029
+ return () => {
1030
+ for (const list of [soon, later]) {
1031
+ const at = list.indexOf(job);
1032
+ if (at >= 0) list.splice(at, 1);
1033
+ }
1034
+ };
1035
+ }
1003
1036
  function idle(callback) {
1004
1037
  if (typeof requestIdleCallback === "function") {
1005
1038
  const handle2 = requestIdleCallback(callback, { timeout: 120 });
@@ -1055,15 +1088,28 @@ function useRefraction(ref, shape = {}, enabled = true, mirror, mirrorActive) {
1055
1088
  }
1056
1089
  element.style.setProperty("--lg-rim", baked.rim);
1057
1090
  };
1091
+ let seen = typeof IntersectionObserver !== "function";
1092
+ const request = () => {
1093
+ cancel?.();
1094
+ cancel = bakeSoon(fit, seen);
1095
+ };
1096
+ const near = typeof IntersectionObserver === "function" ? new IntersectionObserver(
1097
+ (entries) => {
1098
+ if (!entries.some((entry) => entry.isIntersecting)) return;
1099
+ seen = true;
1100
+ near?.disconnect();
1101
+ request();
1102
+ },
1103
+ { rootMargin: "100% 0px" }
1104
+ ) : null;
1105
+ near?.observe(element);
1058
1106
  const observer = new ResizeObserver(() => {
1059
1107
  cancel?.();
1060
- const timer = setTimeout(() => {
1061
- cancel = idle(fit);
1062
- }, 140);
1108
+ const timer = setTimeout(request, 140);
1063
1109
  cancel = () => clearTimeout(timer);
1064
1110
  });
1065
1111
  observer.observe(element);
1066
- fit();
1112
+ request();
1067
1113
  const source = mirror?.current;
1068
1114
  const unmirror = !live && source ? mirrorBackdrop(element, source, () => pad, () => [zoomX, zoom], mirrorActive) : void 0;
1069
1115
  applyCopyFilter();
@@ -1072,6 +1118,7 @@ function useRefraction(ref, shape = {}, enabled = true, mirror, mirrorActive) {
1072
1118
  cancel?.();
1073
1119
  unmirror?.();
1074
1120
  ungovern();
1121
+ near?.disconnect();
1075
1122
  observer.disconnect();
1076
1123
  element.style.removeProperty("--lg-refraction");
1077
1124
  element.style.removeProperty("--lg-rim");