lensfx 0.1.2 → 0.1.3
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/CHANGELOG.md +10 -0
- package/README.md +39 -0
- package/dist/cdn/lensfx.js +1717 -0
- package/dist/cdn/lensfx.js.map +1 -0
- package/dist/cdn/lensfx.min.js +371 -0
- package/dist/cdn/lensfx.min.js.map +1 -0
- package/dist/index.d.mts +3 -368
- package/dist/index.d.ts +3 -368
- package/dist/index.js +413 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +413 -1
- package/dist/index.mjs.map +1 -1
- package/dist/vanilla.d.mts +493 -0
- package/dist/vanilla.d.ts +493 -0
- package/dist/vanilla.js +1694 -0
- package/dist/vanilla.js.map +1 -0
- package/dist/vanilla.mjs +1675 -0
- package/dist/vanilla.mjs.map +1 -0
- package/package.json +28 -3
package/dist/index.mjs
CHANGED
|
@@ -1262,6 +1262,418 @@ var QRRefractionRenderer = class {
|
|
|
1262
1262
|
gl.deleteTexture(this.paintingColorTexture);
|
|
1263
1263
|
}
|
|
1264
1264
|
};
|
|
1265
|
+
|
|
1266
|
+
// src/createLens.ts
|
|
1267
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
1268
|
+
var nextId = 0;
|
|
1269
|
+
function createLens(target, options = {}) {
|
|
1270
|
+
if (typeof document === "undefined") {
|
|
1271
|
+
throw new Error("[lensfx] createLens can only be called in a browser environment.");
|
|
1272
|
+
}
|
|
1273
|
+
const resolved = typeof target === "string" ? document.querySelector(target) : target;
|
|
1274
|
+
if (!resolved) {
|
|
1275
|
+
throw new Error(`[lensfx] Target element "${target}" was not found.`);
|
|
1276
|
+
}
|
|
1277
|
+
const container = resolved;
|
|
1278
|
+
let currentOptions = { ...options };
|
|
1279
|
+
let targetEl = container;
|
|
1280
|
+
if (currentOptions.refractionTarget) {
|
|
1281
|
+
const customTarget = typeof currentOptions.refractionTarget === "string" ? container.querySelector(currentOptions.refractionTarget) || document.querySelector(currentOptions.refractionTarget) : currentOptions.refractionTarget;
|
|
1282
|
+
if (customTarget) {
|
|
1283
|
+
targetEl = customTarget;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
const computedStyle = window.getComputedStyle(container);
|
|
1287
|
+
const originalPosition = container.style.position;
|
|
1288
|
+
if (computedStyle.position === "static") {
|
|
1289
|
+
container.style.position = "relative";
|
|
1290
|
+
}
|
|
1291
|
+
const lensId = `lensfx-${++nextId}-${Math.random().toString(36).substring(2, 7)}`;
|
|
1292
|
+
const filterId = `${lensId}-filter`;
|
|
1293
|
+
const svgEl = document.createElementNS(SVG_NS, "svg");
|
|
1294
|
+
svgEl.setAttribute("class", "lensfx-svg-root");
|
|
1295
|
+
svgEl.setAttribute("aria-hidden", "true");
|
|
1296
|
+
svgEl.style.cssText = "position:absolute;width:0;height:0;overflow:hidden;pointer-events:none;left:0;top:0;";
|
|
1297
|
+
const defsEl = document.createElementNS(SVG_NS, "defs");
|
|
1298
|
+
const filterEl = document.createElementNS(SVG_NS, "filter");
|
|
1299
|
+
filterEl.id = filterId;
|
|
1300
|
+
filterEl.setAttribute("filterUnits", "objectBoundingBox");
|
|
1301
|
+
filterEl.setAttribute("primitiveUnits", "objectBoundingBox");
|
|
1302
|
+
filterEl.setAttribute("color-interpolation-filters", "sRGB");
|
|
1303
|
+
filterEl.setAttribute("x", "0");
|
|
1304
|
+
filterEl.setAttribute("y", "0");
|
|
1305
|
+
filterEl.setAttribute("width", "1");
|
|
1306
|
+
filterEl.setAttribute("height", "1");
|
|
1307
|
+
defsEl.appendChild(filterEl);
|
|
1308
|
+
svgEl.appendChild(defsEl);
|
|
1309
|
+
container.appendChild(svgEl);
|
|
1310
|
+
const overlayEl = document.createElement("div");
|
|
1311
|
+
overlayEl.className = "lensfx-lens-overlay";
|
|
1312
|
+
overlayEl.style.cssText = "position:absolute;top:0;left:0;pointer-events:none;box-sizing:border-box;will-change:transform;";
|
|
1313
|
+
container.appendChild(overlayEl);
|
|
1314
|
+
let mapDataUrl = currentOptions.displacementMapUrl || "";
|
|
1315
|
+
let currentMapSize = currentOptions.mapSize || 256;
|
|
1316
|
+
let generator = createDisplacementMapGeneratorSync(currentMapSize);
|
|
1317
|
+
let feImageEl = null;
|
|
1318
|
+
let currentMaskKey = null;
|
|
1319
|
+
let isDestroyed = false;
|
|
1320
|
+
let curX = currentOptions.x ?? 0.5;
|
|
1321
|
+
let curY = currentOptions.y ?? 0.5;
|
|
1322
|
+
function getDimensions() {
|
|
1323
|
+
const width = currentOptions.width ?? currentOptions.lensW ?? 160;
|
|
1324
|
+
const height = currentOptions.height ?? currentOptions.lensH ?? 100;
|
|
1325
|
+
const radius = currentOptions.radius ?? currentOptions.borderRadius ?? Math.min(width, height) / 4;
|
|
1326
|
+
return { width, height, radius };
|
|
1327
|
+
}
|
|
1328
|
+
function renderMap() {
|
|
1329
|
+
if (isDestroyed) return;
|
|
1330
|
+
if (currentOptions.displacementMapUrl) {
|
|
1331
|
+
mapDataUrl = currentOptions.displacementMapUrl;
|
|
1332
|
+
if (feImageEl) feImageEl.setAttribute("href", mapDataUrl);
|
|
1333
|
+
currentOptions.onMapChange?.(mapDataUrl);
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1336
|
+
const { width, height, radius } = getDimensions();
|
|
1337
|
+
const mapSize = currentOptions.mapSize || 256;
|
|
1338
|
+
if (mapSize !== currentMapSize) {
|
|
1339
|
+
generator.dispose();
|
|
1340
|
+
currentMapSize = mapSize;
|
|
1341
|
+
generator = createDisplacementMapGeneratorSync(currentMapSize);
|
|
1342
|
+
}
|
|
1343
|
+
const depth = currentOptions.depth ?? 2;
|
|
1344
|
+
const result = generator.generate({
|
|
1345
|
+
lensHalfWidth: width / 2,
|
|
1346
|
+
lensHalfHeight: height / 2,
|
|
1347
|
+
borderRadius: radius,
|
|
1348
|
+
depth,
|
|
1349
|
+
sdfBoundary: currentOptions.sdfBoundary ?? true,
|
|
1350
|
+
edgeFalloff: currentOptions.edgeFalloff ?? true,
|
|
1351
|
+
specularRotation: currentOptions.specularRotation ?? 45,
|
|
1352
|
+
glowStrength: currentOptions.glowStrength ?? 0.3,
|
|
1353
|
+
glowSpread: currentOptions.glowSpread ?? 1,
|
|
1354
|
+
glowExponent: currentOptions.glowExponent ?? 1.5,
|
|
1355
|
+
edgeStrength: currentOptions.edgeStrength ?? 0.4,
|
|
1356
|
+
edgeWidth: currentOptions.edgeWidth ?? 3,
|
|
1357
|
+
edgeExponent: 1.5,
|
|
1358
|
+
domeDepth: currentOptions.domeDepth ?? 6,
|
|
1359
|
+
splayAmount: currentOptions.splayAmount ?? 0.8
|
|
1360
|
+
});
|
|
1361
|
+
mapDataUrl = result.dataUrl;
|
|
1362
|
+
if (feImageEl) feImageEl.setAttribute("href", mapDataUrl);
|
|
1363
|
+
currentOptions.onMapChange?.(mapDataUrl);
|
|
1364
|
+
}
|
|
1365
|
+
function buildFilterPipeline() {
|
|
1366
|
+
while (filterEl.firstChild) {
|
|
1367
|
+
filterEl.removeChild(filterEl.firstChild);
|
|
1368
|
+
}
|
|
1369
|
+
currentOptions.depth ?? 2;
|
|
1370
|
+
const chroma = currentOptions.chroma ?? currentOptions.chromaAmount ?? 0.6;
|
|
1371
|
+
const scaleX = currentOptions.scaleX ?? 0.25;
|
|
1372
|
+
const scaleY = currentOptions.scaleY ?? 0.25;
|
|
1373
|
+
const maxScale = Math.max(scaleX, scaleY);
|
|
1374
|
+
const scaleRatioX = maxScale > 0 ? scaleX / maxScale : 0;
|
|
1375
|
+
const scaleRatioY = maxScale > 0 ? scaleY / maxScale : 0;
|
|
1376
|
+
const needsMatrix = scaleRatioX !== 1 || scaleRatioY !== 1;
|
|
1377
|
+
const matrixString = colorMatrixValues(scaleRatioX, scaleRatioY);
|
|
1378
|
+
const feFlood = document.createElementNS(SVG_NS, "feFlood");
|
|
1379
|
+
feFlood.setAttribute("flood-color", "rgb(128,128,128)");
|
|
1380
|
+
feFlood.setAttribute("flood-opacity", "1");
|
|
1381
|
+
feFlood.setAttribute("result", "mapBg");
|
|
1382
|
+
filterEl.appendChild(feFlood);
|
|
1383
|
+
feImageEl = document.createElementNS(SVG_NS, "feImage");
|
|
1384
|
+
feImageEl.setAttribute("href", mapDataUrl);
|
|
1385
|
+
feImageEl.setAttribute("preserveAspectRatio", "none");
|
|
1386
|
+
feImageEl.setAttribute("result", "rawMap");
|
|
1387
|
+
filterEl.appendChild(feImageEl);
|
|
1388
|
+
const feComp = document.createElementNS(SVG_NS, "feComposite");
|
|
1389
|
+
feComp.setAttribute("in", "rawMap");
|
|
1390
|
+
feComp.setAttribute("in2", "mapBg");
|
|
1391
|
+
feComp.setAttribute("operator", "over");
|
|
1392
|
+
feComp.setAttribute("result", "map");
|
|
1393
|
+
filterEl.appendChild(feComp);
|
|
1394
|
+
if (needsMatrix) {
|
|
1395
|
+
const feMat = document.createElementNS(SVG_NS, "feColorMatrix");
|
|
1396
|
+
feMat.setAttribute("in", "map");
|
|
1397
|
+
feMat.setAttribute("type", "matrix");
|
|
1398
|
+
feMat.setAttribute("values", matrixString);
|
|
1399
|
+
feMat.setAttribute("result", "scaledMap");
|
|
1400
|
+
filterEl.appendChild(feMat);
|
|
1401
|
+
}
|
|
1402
|
+
const mapSource = needsMatrix ? "scaledMap" : "map";
|
|
1403
|
+
let sourceGraphic = "SourceGraphic";
|
|
1404
|
+
if (currentOptions.blur && currentOptions.blur > 0) {
|
|
1405
|
+
const feBlur = document.createElementNS(SVG_NS, "feGaussianBlur");
|
|
1406
|
+
feBlur.setAttribute("in", "SourceGraphic");
|
|
1407
|
+
const cRect = container.getBoundingClientRect();
|
|
1408
|
+
const bw = cRect.width > 0 ? currentOptions.blur / cRect.width : 0.01;
|
|
1409
|
+
const bh = cRect.height > 0 ? currentOptions.blur / cRect.height : 0.01;
|
|
1410
|
+
feBlur.setAttribute("stdDeviation", `${bw} ${bh}`);
|
|
1411
|
+
feBlur.setAttribute("result", "blurred");
|
|
1412
|
+
filterEl.appendChild(feBlur);
|
|
1413
|
+
sourceGraphic = "blurred";
|
|
1414
|
+
}
|
|
1415
|
+
if (chroma > 0) {
|
|
1416
|
+
const dispR = document.createElementNS(SVG_NS, "feDisplacementMap");
|
|
1417
|
+
dispR.setAttribute("in", sourceGraphic);
|
|
1418
|
+
dispR.setAttribute("in2", mapSource);
|
|
1419
|
+
dispR.setAttribute("scale", String(maxScale * (1 + 0.2 * chroma)));
|
|
1420
|
+
dispR.setAttribute("xChannelSelector", "R");
|
|
1421
|
+
dispR.setAttribute("yChannelSelector", "G");
|
|
1422
|
+
filterEl.appendChild(dispR);
|
|
1423
|
+
const matR = document.createElementNS(SVG_NS, "feColorMatrix");
|
|
1424
|
+
matR.setAttribute("type", "matrix");
|
|
1425
|
+
matR.setAttribute("values", "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0");
|
|
1426
|
+
matR.setAttribute("result", "dispR");
|
|
1427
|
+
filterEl.appendChild(matR);
|
|
1428
|
+
const dispG = document.createElementNS(SVG_NS, "feDisplacementMap");
|
|
1429
|
+
dispG.setAttribute("in", sourceGraphic);
|
|
1430
|
+
dispG.setAttribute("in2", mapSource);
|
|
1431
|
+
dispG.setAttribute("scale", String(maxScale * (1 + 0.1 * chroma)));
|
|
1432
|
+
dispG.setAttribute("xChannelSelector", "R");
|
|
1433
|
+
dispG.setAttribute("yChannelSelector", "G");
|
|
1434
|
+
filterEl.appendChild(dispG);
|
|
1435
|
+
const matG = document.createElementNS(SVG_NS, "feColorMatrix");
|
|
1436
|
+
matG.setAttribute("type", "matrix");
|
|
1437
|
+
matG.setAttribute("values", "0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0");
|
|
1438
|
+
matG.setAttribute("result", "dispG");
|
|
1439
|
+
filterEl.appendChild(matG);
|
|
1440
|
+
const dispB = document.createElementNS(SVG_NS, "feDisplacementMap");
|
|
1441
|
+
dispB.setAttribute("in", sourceGraphic);
|
|
1442
|
+
dispB.setAttribute("in2", mapSource);
|
|
1443
|
+
dispB.setAttribute("scale", String(maxScale));
|
|
1444
|
+
dispB.setAttribute("xChannelSelector", "R");
|
|
1445
|
+
dispB.setAttribute("yChannelSelector", "G");
|
|
1446
|
+
filterEl.appendChild(dispB);
|
|
1447
|
+
const matB = document.createElementNS(SVG_NS, "feColorMatrix");
|
|
1448
|
+
matB.setAttribute("type", "matrix");
|
|
1449
|
+
matB.setAttribute("values", "0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0");
|
|
1450
|
+
matB.setAttribute("result", "dispB");
|
|
1451
|
+
filterEl.appendChild(matB);
|
|
1452
|
+
const compRG = document.createElementNS(SVG_NS, "feComposite");
|
|
1453
|
+
compRG.setAttribute("in", "dispR");
|
|
1454
|
+
compRG.setAttribute("in2", "dispG");
|
|
1455
|
+
compRG.setAttribute("operator", "arithmetic");
|
|
1456
|
+
compRG.setAttribute("k1", "0");
|
|
1457
|
+
compRG.setAttribute("k2", "1");
|
|
1458
|
+
compRG.setAttribute("k3", "1");
|
|
1459
|
+
compRG.setAttribute("k4", "0");
|
|
1460
|
+
filterEl.appendChild(compRG);
|
|
1461
|
+
const compRGB = document.createElementNS(SVG_NS, "feComposite");
|
|
1462
|
+
compRGB.setAttribute("in2", "dispB");
|
|
1463
|
+
compRGB.setAttribute("operator", "arithmetic");
|
|
1464
|
+
compRGB.setAttribute("k1", "0");
|
|
1465
|
+
compRGB.setAttribute("k2", "1");
|
|
1466
|
+
compRGB.setAttribute("k3", "1");
|
|
1467
|
+
compRGB.setAttribute("k4", "0");
|
|
1468
|
+
compRGB.setAttribute("result", "lensResult");
|
|
1469
|
+
filterEl.appendChild(compRGB);
|
|
1470
|
+
} else {
|
|
1471
|
+
const dispSingle = document.createElementNS(SVG_NS, "feDisplacementMap");
|
|
1472
|
+
dispSingle.setAttribute("in", sourceGraphic);
|
|
1473
|
+
dispSingle.setAttribute("in2", mapSource);
|
|
1474
|
+
dispSingle.setAttribute("scale", String(maxScale));
|
|
1475
|
+
dispSingle.setAttribute("xChannelSelector", "R");
|
|
1476
|
+
dispSingle.setAttribute("yChannelSelector", "G");
|
|
1477
|
+
dispSingle.setAttribute("result", "lensResult");
|
|
1478
|
+
filterEl.appendChild(dispSingle);
|
|
1479
|
+
}
|
|
1480
|
+
const specStrength = currentOptions.specularStrength ?? 1;
|
|
1481
|
+
if (specStrength > 0) {
|
|
1482
|
+
const specMat = document.createElementNS(SVG_NS, "feColorMatrix");
|
|
1483
|
+
specMat.setAttribute("in", "map");
|
|
1484
|
+
specMat.setAttribute("type", "matrix");
|
|
1485
|
+
specMat.setAttribute("values", "0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 1 0 -0.50196");
|
|
1486
|
+
specMat.setAttribute("result", "specMask");
|
|
1487
|
+
filterEl.appendChild(specMat);
|
|
1488
|
+
const specComp = document.createElementNS(SVG_NS, "feComposite");
|
|
1489
|
+
specComp.setAttribute("in", "specMask");
|
|
1490
|
+
specComp.setAttribute("in2", "lensResult");
|
|
1491
|
+
specComp.setAttribute("operator", "arithmetic");
|
|
1492
|
+
specComp.setAttribute("k1", "0");
|
|
1493
|
+
specComp.setAttribute("k2", String(specStrength));
|
|
1494
|
+
specComp.setAttribute("k3", "1");
|
|
1495
|
+
specComp.setAttribute("k4", "0");
|
|
1496
|
+
specComp.setAttribute("result", "lensResult");
|
|
1497
|
+
filterEl.appendChild(specComp);
|
|
1498
|
+
}
|
|
1499
|
+
const lensMask = document.createElementNS(SVG_NS, "feFlood");
|
|
1500
|
+
lensMask.setAttribute("flood-color", "black");
|
|
1501
|
+
lensMask.setAttribute("flood-opacity", "1");
|
|
1502
|
+
lensMask.setAttribute("result", "lensMask");
|
|
1503
|
+
filterEl.appendChild(lensMask);
|
|
1504
|
+
const holeComp = document.createElementNS(SVG_NS, "feComposite");
|
|
1505
|
+
holeComp.setAttribute("in", "SourceGraphic");
|
|
1506
|
+
holeComp.setAttribute("in2", "lensMask");
|
|
1507
|
+
holeComp.setAttribute("operator", "out");
|
|
1508
|
+
holeComp.setAttribute("result", "holedSG");
|
|
1509
|
+
filterEl.appendChild(holeComp);
|
|
1510
|
+
const finalComp = document.createElementNS(SVG_NS, "feComposite");
|
|
1511
|
+
finalComp.setAttribute("in", "lensResult");
|
|
1512
|
+
finalComp.setAttribute("in2", "holedSG");
|
|
1513
|
+
finalComp.setAttribute("operator", "over");
|
|
1514
|
+
filterEl.appendChild(finalComp);
|
|
1515
|
+
}
|
|
1516
|
+
function updateLayout() {
|
|
1517
|
+
if (isDestroyed) return;
|
|
1518
|
+
const rect = container.getBoundingClientRect();
|
|
1519
|
+
const cw = rect.width || container.clientWidth || 300;
|
|
1520
|
+
const ch = rect.height || container.clientHeight || 200;
|
|
1521
|
+
const { width, height, radius } = getDimensions();
|
|
1522
|
+
const px = curX <= 1 && curX >= 0 ? curX * cw : curX;
|
|
1523
|
+
const py = curY <= 1 && curY >= 0 ? curY * ch : pyCoordinate(curY, ch);
|
|
1524
|
+
function pyCoordinate(val, containerH) {
|
|
1525
|
+
return val <= 1 && val >= 0 ? val * containerH : val;
|
|
1526
|
+
}
|
|
1527
|
+
const lensLeft = px - width / 2;
|
|
1528
|
+
const lensTop = py - height / 2;
|
|
1529
|
+
if (feImageEl && cw > 0 && ch > 0) {
|
|
1530
|
+
feImageEl.setAttribute("x", String(lensLeft / cw));
|
|
1531
|
+
feImageEl.setAttribute("y", String(lensTop / ch));
|
|
1532
|
+
feImageEl.setAttribute("width", String(width / cw));
|
|
1533
|
+
feImageEl.setAttribute("height", String(height / ch));
|
|
1534
|
+
}
|
|
1535
|
+
overlayEl.style.width = `${width}px`;
|
|
1536
|
+
overlayEl.style.height = `${height}px`;
|
|
1537
|
+
overlayEl.style.borderRadius = `${radius}px`;
|
|
1538
|
+
overlayEl.style.transform = `translate3d(${lensLeft}px, ${lensTop}px, 0)`;
|
|
1539
|
+
if (currentOptions.shadow === false) {
|
|
1540
|
+
overlayEl.style.boxShadow = "none";
|
|
1541
|
+
} else if (typeof currentOptions.shadow === "string") {
|
|
1542
|
+
overlayEl.style.boxShadow = currentOptions.shadow;
|
|
1543
|
+
} else {
|
|
1544
|
+
overlayEl.style.boxShadow = "0 8px 32px rgba(0, 0, 0, 0.2), 0 2px 8px rgba(0, 0, 0, 0.12), inset 0 1px 1px rgba(255, 255, 255, 0.35), inset 0 -1px 1px rgba(0, 0, 0, 0.15)";
|
|
1545
|
+
}
|
|
1546
|
+
if (currentOptions.border === false) {
|
|
1547
|
+
overlayEl.style.border = "none";
|
|
1548
|
+
} else if (typeof currentOptions.border === "string") {
|
|
1549
|
+
overlayEl.style.border = currentOptions.border;
|
|
1550
|
+
} else {
|
|
1551
|
+
overlayEl.style.border = "1px solid rgba(255, 255, 255, 0.2)";
|
|
1552
|
+
}
|
|
1553
|
+
const tintColor = currentOptions.tintColor ?? "rgba(255, 255, 255, 0.05)";
|
|
1554
|
+
overlayEl.style.background = tintColor;
|
|
1555
|
+
const tintBlur = currentOptions.tintBlur ?? 0;
|
|
1556
|
+
if (tintBlur > 0) {
|
|
1557
|
+
const blurCss = `blur(${tintBlur}px)`;
|
|
1558
|
+
overlayEl.style.backdropFilter = blurCss;
|
|
1559
|
+
overlayEl.style.setProperty("-webkit-backdrop-filter", blurCss);
|
|
1560
|
+
} else {
|
|
1561
|
+
overlayEl.style.backdropFilter = "none";
|
|
1562
|
+
overlayEl.style.setProperty("-webkit-backdrop-filter", "none");
|
|
1563
|
+
}
|
|
1564
|
+
const { uri, key } = getSvgMaskDataUri(width, height, radius);
|
|
1565
|
+
if (currentMaskKey !== key) {
|
|
1566
|
+
const maskCss = `url("${uri}")`;
|
|
1567
|
+
overlayEl.style.maskImage = maskCss;
|
|
1568
|
+
overlayEl.style.setProperty("-webkit-mask-image", maskCss);
|
|
1569
|
+
overlayEl.style.maskSize = "100% 100%";
|
|
1570
|
+
overlayEl.style.setProperty("-webkit-mask-size", "100% 100%");
|
|
1571
|
+
currentMaskKey = key;
|
|
1572
|
+
}
|
|
1573
|
+
const filterStyle = `url("#${filterId}")`;
|
|
1574
|
+
if (targetEl.style.filter !== filterStyle) {
|
|
1575
|
+
targetEl.style.filter = filterStyle;
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
let isPointerActive = false;
|
|
1579
|
+
const onPointerMove = (e) => {
|
|
1580
|
+
if (!currentOptions.interactive || isDestroyed) return;
|
|
1581
|
+
const rect = container.getBoundingClientRect();
|
|
1582
|
+
const x = e.clientX - rect.left;
|
|
1583
|
+
const y = e.clientY - rect.top;
|
|
1584
|
+
setPosition(x, y);
|
|
1585
|
+
};
|
|
1586
|
+
function setInteractive(interactive) {
|
|
1587
|
+
currentOptions.interactive = interactive;
|
|
1588
|
+
if (interactive && !isPointerActive) {
|
|
1589
|
+
container.addEventListener("pointermove", onPointerMove);
|
|
1590
|
+
isPointerActive = true;
|
|
1591
|
+
} else if (!interactive && isPointerActive) {
|
|
1592
|
+
container.removeEventListener("pointermove", onPointerMove);
|
|
1593
|
+
isPointerActive = false;
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
function setPosition(x, y) {
|
|
1597
|
+
curX = x;
|
|
1598
|
+
curY = y;
|
|
1599
|
+
currentOptions.onPositionChange?.(x, y);
|
|
1600
|
+
updateLayout();
|
|
1601
|
+
}
|
|
1602
|
+
function update(newOptions) {
|
|
1603
|
+
if (isDestroyed) return;
|
|
1604
|
+
({ ...currentOptions });
|
|
1605
|
+
currentOptions = { ...currentOptions, ...newOptions };
|
|
1606
|
+
if (newOptions.x !== void 0) curX = newOptions.x;
|
|
1607
|
+
if (newOptions.y !== void 0) curY = newOptions.y;
|
|
1608
|
+
if (newOptions.interactive !== void 0) {
|
|
1609
|
+
setInteractive(newOptions.interactive);
|
|
1610
|
+
}
|
|
1611
|
+
const needsRegen = newOptions.width !== void 0 || newOptions.lensW !== void 0 || newOptions.height !== void 0 || newOptions.lensH !== void 0 || newOptions.radius !== void 0 || newOptions.borderRadius !== void 0 || newOptions.depth !== void 0 || newOptions.domeDepth !== void 0 || newOptions.specularRotation !== void 0 || newOptions.glowStrength !== void 0 || newOptions.glowSpread !== void 0 || newOptions.edgeStrength !== void 0 || newOptions.edgeWidth !== void 0 || newOptions.splayAmount !== void 0 || newOptions.displacementMapUrl !== void 0 || newOptions.mapSize !== void 0;
|
|
1612
|
+
if (needsRegen) {
|
|
1613
|
+
renderMap();
|
|
1614
|
+
}
|
|
1615
|
+
const needsPipelineRebuild = newOptions.chroma !== void 0 || newOptions.chromaAmount !== void 0 || newOptions.scaleX !== void 0 || newOptions.scaleY !== void 0 || newOptions.specularStrength !== void 0 || newOptions.blur !== void 0;
|
|
1616
|
+
if (needsPipelineRebuild || needsRegen) {
|
|
1617
|
+
buildFilterPipeline();
|
|
1618
|
+
}
|
|
1619
|
+
updateLayout();
|
|
1620
|
+
}
|
|
1621
|
+
let resizeObserver = null;
|
|
1622
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
1623
|
+
resizeObserver = new ResizeObserver(() => {
|
|
1624
|
+
updateLayout();
|
|
1625
|
+
});
|
|
1626
|
+
resizeObserver.observe(container);
|
|
1627
|
+
}
|
|
1628
|
+
renderMap();
|
|
1629
|
+
buildFilterPipeline();
|
|
1630
|
+
updateLayout();
|
|
1631
|
+
if (currentOptions.interactive) {
|
|
1632
|
+
setInteractive(true);
|
|
1633
|
+
}
|
|
1634
|
+
function destroy() {
|
|
1635
|
+
if (isDestroyed) return;
|
|
1636
|
+
isDestroyed = true;
|
|
1637
|
+
if (isPointerActive) {
|
|
1638
|
+
container.removeEventListener("pointermove", onPointerMove);
|
|
1639
|
+
isPointerActive = false;
|
|
1640
|
+
}
|
|
1641
|
+
if (resizeObserver) {
|
|
1642
|
+
resizeObserver.disconnect();
|
|
1643
|
+
resizeObserver = null;
|
|
1644
|
+
}
|
|
1645
|
+
if (targetEl.style.filter.includes(filterId)) {
|
|
1646
|
+
targetEl.style.filter = "";
|
|
1647
|
+
}
|
|
1648
|
+
if (container.style.position === "relative" && originalPosition === "") {
|
|
1649
|
+
container.style.position = "";
|
|
1650
|
+
}
|
|
1651
|
+
if (svgEl.parentNode) {
|
|
1652
|
+
svgEl.parentNode.removeChild(svgEl);
|
|
1653
|
+
}
|
|
1654
|
+
if (overlayEl.parentNode) {
|
|
1655
|
+
overlayEl.parentNode.removeChild(overlayEl);
|
|
1656
|
+
}
|
|
1657
|
+
generator.dispose();
|
|
1658
|
+
}
|
|
1659
|
+
return {
|
|
1660
|
+
el: container,
|
|
1661
|
+
targetEl,
|
|
1662
|
+
svgEl,
|
|
1663
|
+
filterEl,
|
|
1664
|
+
overlayEl,
|
|
1665
|
+
get options() {
|
|
1666
|
+
return currentOptions;
|
|
1667
|
+
},
|
|
1668
|
+
get mapDataUrl() {
|
|
1669
|
+
return mapDataUrl;
|
|
1670
|
+
},
|
|
1671
|
+
setPosition,
|
|
1672
|
+
update,
|
|
1673
|
+
setInteractive,
|
|
1674
|
+
destroy
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1265
1677
|
function isMotionValue(val) {
|
|
1266
1678
|
return typeof val === "object" && val !== null && "get" in val && "on" in val;
|
|
1267
1679
|
}
|
|
@@ -3234,6 +3646,6 @@ function GlassToggleGroup({
|
|
|
3234
3646
|
);
|
|
3235
3647
|
}
|
|
3236
3648
|
|
|
3237
|
-
export { DEFAULT_LENS_PARAMS, AaveGlass as Lens, GlassSlider as LensSlider, GlassSwitch as LensSwitch, GlassToggleGroup as LensToggleGroup, QRRefractionRenderer, SLIDER_DARK_OVERRIDES, SLIDER_GLASS_DEFAULTS, SLIDER_LIGHT_OVERRIDES, SLIDER_SAFARI_OVERRIDES, SWITCH_DARK_OVERRIDES, SWITCH_GLASS_DEFAULTS, SWITCH_LIGHT_OVERRIDES, VideoRefractionRenderer, colorMatrixValues, computeDomeConstants, createDisplacementMapGeneratorSync, domeGradient, erf, generateDisplacementMapAsync, getSvgMaskDataUri };
|
|
3649
|
+
export { DEFAULT_LENS_PARAMS, AaveGlass as Lens, GlassSlider as LensSlider, GlassSwitch as LensSwitch, GlassToggleGroup as LensToggleGroup, QRRefractionRenderer, SLIDER_DARK_OVERRIDES, SLIDER_GLASS_DEFAULTS, SLIDER_LIGHT_OVERRIDES, SLIDER_SAFARI_OVERRIDES, SWITCH_DARK_OVERRIDES, SWITCH_GLASS_DEFAULTS, SWITCH_LIGHT_OVERRIDES, VideoRefractionRenderer, colorMatrixValues, computeDomeConstants, createDisplacementMapGeneratorSync, createLens, domeGradient, erf, generateDisplacementMapAsync, getSvgMaskDataUri };
|
|
3238
3650
|
//# sourceMappingURL=index.mjs.map
|
|
3239
3651
|
//# sourceMappingURL=index.mjs.map
|