@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 +5 -3
- package/dist/index.js +51 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -679,6 +679,7 @@ function bake(width, height, radius, shape, pad = 0, simple = false, fringe = fa
|
|
|
679
679
|
const t = clamp((Math.abs(py) - (edge - 2)) / 3, 0, 1);
|
|
680
680
|
return 1 - t * t * (3 - 2 * t);
|
|
681
681
|
};
|
|
682
|
+
const flat = simple && magnify ? Infinity : Math.max(shape.bezel * 1.7, 5);
|
|
682
683
|
for (let y = 0; y < ch; y++) {
|
|
683
684
|
for (let x = 0; x < cw; x++) {
|
|
684
685
|
const px = (x + 0.5) * W / cw - W / 2;
|
|
@@ -689,6 +690,10 @@ function bake(width, height, radius, shape, pad = 0, simple = false, fringe = fa
|
|
|
689
690
|
const oy = Math.max(qy, 0);
|
|
690
691
|
const len = Math.hypot(ox, oy);
|
|
691
692
|
const d = radius - (len + Math.min(Math.max(qx, qy), 0));
|
|
693
|
+
if (d > flat) {
|
|
694
|
+
inside[y * cw + x] = 1;
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
692
697
|
let nx;
|
|
693
698
|
let ny;
|
|
694
699
|
if (len > 0) {
|
|
@@ -946,6 +951,34 @@ function glassFor(width, height, radius, shape = {}, pad = 0, simple = false, fr
|
|
|
946
951
|
}
|
|
947
952
|
return baked;
|
|
948
953
|
}
|
|
954
|
+
var soon = [];
|
|
955
|
+
var later = [];
|
|
956
|
+
var pumping = false;
|
|
957
|
+
function pump() {
|
|
958
|
+
pumping = true;
|
|
959
|
+
const run = (deadline) => {
|
|
960
|
+
const end = performance.now() + 8;
|
|
961
|
+
const left = () => deadline ? deadline.timeRemaining() > 4 : performance.now() < end;
|
|
962
|
+
let ran = 0;
|
|
963
|
+
while ((soon.length || later.length) && (ran === 0 || left())) {
|
|
964
|
+
(soon.shift() ?? later.shift())();
|
|
965
|
+
ran++;
|
|
966
|
+
}
|
|
967
|
+
if (soon.length || later.length) idle(run);
|
|
968
|
+
else pumping = false;
|
|
969
|
+
};
|
|
970
|
+
idle(run);
|
|
971
|
+
}
|
|
972
|
+
function bakeSoon(job, urgent = true) {
|
|
973
|
+
(urgent ? soon : later).push(job);
|
|
974
|
+
if (!pumping) pump();
|
|
975
|
+
return () => {
|
|
976
|
+
for (const list of [soon, later]) {
|
|
977
|
+
const at = list.indexOf(job);
|
|
978
|
+
if (at >= 0) list.splice(at, 1);
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
}
|
|
949
982
|
function idle(callback) {
|
|
950
983
|
if (typeof requestIdleCallback === "function") {
|
|
951
984
|
const handle2 = requestIdleCallback(callback, { timeout: 120 });
|
|
@@ -1001,15 +1034,28 @@ function useRefraction(ref, shape = {}, enabled = true, mirror, mirrorActive) {
|
|
|
1001
1034
|
}
|
|
1002
1035
|
element.style.setProperty("--lg-rim", baked.rim);
|
|
1003
1036
|
};
|
|
1037
|
+
let seen = typeof IntersectionObserver !== "function";
|
|
1038
|
+
const request = () => {
|
|
1039
|
+
cancel?.();
|
|
1040
|
+
cancel = bakeSoon(fit, seen);
|
|
1041
|
+
};
|
|
1042
|
+
const near = typeof IntersectionObserver === "function" ? new IntersectionObserver(
|
|
1043
|
+
(entries) => {
|
|
1044
|
+
if (!entries.some((entry) => entry.isIntersecting)) return;
|
|
1045
|
+
seen = true;
|
|
1046
|
+
near?.disconnect();
|
|
1047
|
+
request();
|
|
1048
|
+
},
|
|
1049
|
+
{ rootMargin: "100% 0px" }
|
|
1050
|
+
) : null;
|
|
1051
|
+
near?.observe(element);
|
|
1004
1052
|
const observer = new ResizeObserver(() => {
|
|
1005
1053
|
cancel?.();
|
|
1006
|
-
const timer = setTimeout(
|
|
1007
|
-
cancel = idle(fit);
|
|
1008
|
-
}, 140);
|
|
1054
|
+
const timer = setTimeout(request, 140);
|
|
1009
1055
|
cancel = () => clearTimeout(timer);
|
|
1010
1056
|
});
|
|
1011
1057
|
observer.observe(element);
|
|
1012
|
-
|
|
1058
|
+
request();
|
|
1013
1059
|
const source = mirror?.current;
|
|
1014
1060
|
const unmirror = !live && source ? mirrorBackdrop(element, source, () => pad, () => [zoomX, zoom], mirrorActive) : void 0;
|
|
1015
1061
|
applyCopyFilter();
|
|
@@ -1018,6 +1064,7 @@ function useRefraction(ref, shape = {}, enabled = true, mirror, mirrorActive) {
|
|
|
1018
1064
|
cancel?.();
|
|
1019
1065
|
unmirror?.();
|
|
1020
1066
|
ungovern();
|
|
1067
|
+
near?.disconnect();
|
|
1021
1068
|
observer.disconnect();
|
|
1022
1069
|
element.style.removeProperty("--lg-refraction");
|
|
1023
1070
|
element.style.removeProperty("--lg-rim");
|