@zakisheriff/liquid-glass 0.3.2 → 0.3.4
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 +435 -55
- package/dist/index.css +8 -3
- package/dist/index.css.map +1 -1
- package/dist/index.js +41 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.mjs
CHANGED
|
@@ -305,6 +305,21 @@ function backdropChain(glass, source) {
|
|
|
305
305
|
}
|
|
306
306
|
var stateOf = (el2) => Array.from(el2.attributes).map((a) => a.name).filter((name) => name.startsWith("data-") && name !== "data-mirror" && !name.startsWith("data-lg-mirror")).sort().join(" ");
|
|
307
307
|
var BACKGROUND = ["background-color", "background-image", "background-size", "background-position", "background-repeat", "border-radius"];
|
|
308
|
+
var PLACEMENT = /* @__PURE__ */ new Set(["position", "left", "top", "margin", "margin-top", "margin-right", "margin-bottom", "margin-left", "width", "height", "max-width", "max-height", "min-width", "min-height", "scale", "translate", "transform-origin", "transform"]);
|
|
309
|
+
function syncStyle(original, copy, root) {
|
|
310
|
+
for (const name of Array.from(copy.style)) {
|
|
311
|
+
if (root && PLACEMENT.has(name)) continue;
|
|
312
|
+
if (!original.style.getPropertyValue(name)) copy.style.removeProperty(name);
|
|
313
|
+
}
|
|
314
|
+
for (const name of Array.from(original.style)) {
|
|
315
|
+
if (root && PLACEMENT.has(name)) continue;
|
|
316
|
+
const value = original.style.getPropertyValue(name);
|
|
317
|
+
const priority = original.style.getPropertyPriority(name);
|
|
318
|
+
if (copy.style.getPropertyValue(name) !== value || copy.style.getPropertyPriority(name) !== priority) {
|
|
319
|
+
copy.style.setProperty(name, value, priority);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
308
323
|
function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
|
|
309
324
|
const layer = document.createElement("div");
|
|
310
325
|
layer.className = "lg-mirror";
|
|
@@ -402,11 +417,7 @@ function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
|
|
|
402
417
|
const cls = pair.original.className.toString();
|
|
403
418
|
if (css !== pair.css) {
|
|
404
419
|
pair.css = css;
|
|
405
|
-
|
|
406
|
-
else {
|
|
407
|
-
pair.copy.style.cssText = css;
|
|
408
|
-
placed = "";
|
|
409
|
-
}
|
|
420
|
+
syncStyle(pair.original, pair.copy, pair.copy === copy.root);
|
|
410
421
|
}
|
|
411
422
|
if (cls !== pair.cls) {
|
|
412
423
|
pair.cls = cls;
|
|
@@ -460,8 +471,13 @@ function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
|
|
|
460
471
|
if (records.every((r) => layer.contains(r.target) || r.target === layer || r.target === glass)) return;
|
|
461
472
|
const structural = records.some((r) => r.type !== "attributes" && !layer.contains(r.target));
|
|
462
473
|
if (structural && !pending) pending = requestAnimationFrame(recopy);
|
|
474
|
+
else if (!structural && !stopped && visible && !document.hidden && active2()) {
|
|
475
|
+
applyZoom();
|
|
476
|
+
sync();
|
|
477
|
+
align();
|
|
478
|
+
}
|
|
463
479
|
});
|
|
464
|
-
mutations.observe(source, { childList: true, characterData: true, subtree: true });
|
|
480
|
+
mutations.observe(source, { childList: true, characterData: true, attributes: true, attributeFilter: ["style", "class"], subtree: true });
|
|
465
481
|
const io = typeof IntersectionObserver === "function" ? new IntersectionObserver((entries) => {
|
|
466
482
|
visible = entries.some((e) => e.isIntersecting);
|
|
467
483
|
}) : null;
|
|
@@ -1233,10 +1249,9 @@ GlassSheet.displayName = "GlassSheet";
|
|
|
1233
1249
|
import { useEffect as useEffect4, useLayoutEffect, useRef as useRef5, useState as useState3 } from "react";
|
|
1234
1250
|
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1235
1251
|
var OPEN2 = springFrom(0.36, 0.74);
|
|
1236
|
-
var CLOSE2 = springFrom(0.
|
|
1252
|
+
var CLOSE2 = springFrom(0.42, 0.66);
|
|
1237
1253
|
var FADE = springFrom(0.24, 1);
|
|
1238
|
-
var FADE_OUT = springFrom(0.
|
|
1239
|
-
var JELLY = springFrom(0.42, 0.4);
|
|
1254
|
+
var FADE_OUT = springFrom(0.2, 1);
|
|
1240
1255
|
var Tick = () => /* @__PURE__ */ jsx6("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx6("path", { d: "M3.5 8.5l3 3 6-7", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
1241
1256
|
var GlassMenu = ({
|
|
1242
1257
|
icon,
|
|
@@ -1260,8 +1275,13 @@ var GlassMenu = ({
|
|
|
1260
1275
|
itemsRef.current = items;
|
|
1261
1276
|
usePress(surfaceRef, { grow: 0.035, lean: 6, stretch: 0.1, disabled: !mounted });
|
|
1262
1277
|
useEffect4(() => {
|
|
1263
|
-
if (open)
|
|
1264
|
-
|
|
1278
|
+
if (open) {
|
|
1279
|
+
setMounted(true);
|
|
1280
|
+
if (spring.current) {
|
|
1281
|
+
spring.current.tune(OPEN2);
|
|
1282
|
+
spring.current.set(1);
|
|
1283
|
+
}
|
|
1284
|
+
} else if (spring.current) {
|
|
1265
1285
|
spring.current.tune(CLOSE2);
|
|
1266
1286
|
spring.current.set(0);
|
|
1267
1287
|
}
|
|
@@ -1282,6 +1302,7 @@ var GlassMenu = ({
|
|
|
1282
1302
|
const end = align === "end";
|
|
1283
1303
|
const box = { cw: w, ch: h, r: h / 2 };
|
|
1284
1304
|
let scaleNow = 1;
|
|
1305
|
+
let closing = false;
|
|
1285
1306
|
const clipContent = () => {
|
|
1286
1307
|
const k = scaleNow;
|
|
1287
1308
|
const right = Math.max(0, W - box.cw / k);
|
|
@@ -1301,9 +1322,10 @@ var GlassMenu = ({
|
|
|
1301
1322
|
box.ch = ch;
|
|
1302
1323
|
box.r = r;
|
|
1303
1324
|
clipContent();
|
|
1304
|
-
const k = clamp(p / 0.35, 0, 1);
|
|
1305
|
-
panel.style.opacity = String(k);
|
|
1325
|
+
const k = clamp(p / (closing ? 0.7 : 0.35), 0, 1);
|
|
1326
|
+
panel.style.opacity = String(closing ? Math.min(1, k * 1.4) : k);
|
|
1306
1327
|
trigger.style.opacity = String(1 - k);
|
|
1328
|
+
trigger.style.scale = closing && p < -5e-4 ? `${1 - p * 0.6} ${1 + p * 1.2}` : "";
|
|
1307
1329
|
};
|
|
1308
1330
|
const reveal = (q) => {
|
|
1309
1331
|
const t = clamp(q, 0, 1);
|
|
@@ -1316,14 +1338,11 @@ var GlassMenu = ({
|
|
|
1316
1338
|
};
|
|
1317
1339
|
shape(0);
|
|
1318
1340
|
reveal(0);
|
|
1319
|
-
const s = createSpring(0, OPEN2, (p) => {
|
|
1341
|
+
const s = createSpring(0, OPEN2, (p, v) => {
|
|
1320
1342
|
shape(p);
|
|
1321
|
-
if (p
|
|
1343
|
+
if (s.target === 0 && p === 0 && v === 0) {
|
|
1322
1344
|
trigger.style.opacity = "";
|
|
1323
|
-
|
|
1324
|
-
trigger.style.scale = Math.abs(v) < 5e-4 ? "" : `${1 - v} ${1 + v}`;
|
|
1325
|
-
});
|
|
1326
|
-
jelly.set(0);
|
|
1345
|
+
trigger.style.scale = "";
|
|
1327
1346
|
setMounted(false);
|
|
1328
1347
|
}
|
|
1329
1348
|
});
|
|
@@ -1332,6 +1351,8 @@ var GlassMenu = ({
|
|
|
1332
1351
|
...s,
|
|
1333
1352
|
tune: s.tune,
|
|
1334
1353
|
set(target, instant) {
|
|
1354
|
+
closing = target === 0;
|
|
1355
|
+
surface.style.pointerEvents = closing ? "none" : "";
|
|
1335
1356
|
fade.tune(target ? FADE : FADE_OUT);
|
|
1336
1357
|
fade.set(target, instant);
|
|
1337
1358
|
s.set(target, instant);
|
|
@@ -1344,6 +1365,7 @@ var GlassMenu = ({
|
|
|
1344
1365
|
fade.stop();
|
|
1345
1366
|
spring.current = null;
|
|
1346
1367
|
trigger.style.opacity = "";
|
|
1368
|
+
trigger.style.scale = "";
|
|
1347
1369
|
};
|
|
1348
1370
|
}, [mounted]);
|
|
1349
1371
|
useEffect4(() => {
|