vireglass 3.2.0 → 3.2.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/dom.cjs +28 -12
- package/dist/dom.cjs.map +1 -1
- package/dist/dom.js +29 -13
- package/dist/dom.js.map +1 -1
- package/package.json +1 -1
- package/src/dom/index.ts +1 -1
- package/src/dom/spectral-map.ts +36 -12
package/dist/dom.js
CHANGED
|
@@ -2,7 +2,7 @@ import { shadowTint, NO_ACCESSIBILITY, createGroupState, createDeform, elasticAl
|
|
|
2
2
|
import { ambientFrom, shouldInkBeLight, INK_LIGHT, INK_DARK } from './chunk-JNRZNMJJ.js';
|
|
3
3
|
import { touchWarp, sceneDistance, sceneGradient, sdfRoundedRect, VIREGLASS_MATERIAL, REST_LIGHT, resolveOptics, refractionStrength } from './chunk-YAN2OK4H.js';
|
|
4
4
|
import { shadowOpacity, thicknessDp, bevelDp, rimDp, shadowOpacityFrom, shadowReachDp, halfMinDp, MAX_STRETCH, roundedRectGeometry } from './chunk-Z4FKYY47.js';
|
|
5
|
-
import { LENS, BODY, RIM, TOUCH, SHADOW, SHADOW_GAP, MEDIUM, SCROLL_EDGE, BEVEL,
|
|
5
|
+
import { LENS, BODY, RIM, TOUCH, SHADOW, SHADOW_GAP, MEDIUM, SCROLL_EDGE, BEVEL, DISPERSION, SPECTRAL } from './chunk-CPSIY2DZ.js';
|
|
6
6
|
|
|
7
7
|
// src/dom/displacement.ts
|
|
8
8
|
var SCALE_GAIN = 0.75;
|
|
@@ -153,6 +153,18 @@ function mapDensity2(bevel, dpr) {
|
|
|
153
153
|
if (bevel <= 0) return dpr;
|
|
154
154
|
return Math.min(dpr, BEVEL_SAMPLES2 / bevel);
|
|
155
155
|
}
|
|
156
|
+
var DEPTH_STEPS = 2048;
|
|
157
|
+
function hueAlongDepth(bevel, rim, thick, optics) {
|
|
158
|
+
const table = new Float64Array((DEPTH_STEPS + 1) * 3);
|
|
159
|
+
for (let k = 0; k <= DEPTH_STEPS; k += 1) {
|
|
160
|
+
const s = k / DEPTH_STEPS;
|
|
161
|
+
const [r, g, b] = spectralHue(s * s * bevel, bevel, rim, thick, optics);
|
|
162
|
+
table[k * 3] = r;
|
|
163
|
+
table[k * 3 + 1] = g;
|
|
164
|
+
table[k * 3 + 2] = b;
|
|
165
|
+
}
|
|
166
|
+
return table;
|
|
167
|
+
}
|
|
156
168
|
function renderSpectralPixels(optics, geometry, dpr) {
|
|
157
169
|
const bevel = bevelDp(geometry, optics);
|
|
158
170
|
const density = mapDensity2(bevel, dpr);
|
|
@@ -164,24 +176,28 @@ function renderSpectralPixels(optics, geometry, dpr) {
|
|
|
164
176
|
const halfW = geometry.width / 2;
|
|
165
177
|
const halfH = geometry.height / 2;
|
|
166
178
|
const neutral = Math.round(1 / HEADROOM * 255);
|
|
179
|
+
const table = hueAlongDepth(bevel, rim, thick, optics);
|
|
180
|
+
const toByte = 255 / HEADROOM;
|
|
181
|
+
new Uint32Array(data.buffer).fill(new Uint32Array(new Uint8ClampedArray([neutral, neutral, neutral, 255]).buffer)[0]);
|
|
182
|
+
const corner = Math.max(geometry.cornerRadius, bevel);
|
|
167
183
|
for (let py = 0; py < height; py += 1) {
|
|
168
184
|
const y = (py + 0.5) / density - halfH;
|
|
185
|
+
const ay = Math.abs(y);
|
|
186
|
+
const plain = Math.max(ay <= halfH - bevel ? halfW - corner : -1, ay <= halfH - corner ? halfW - bevel : -1);
|
|
169
187
|
for (let px = 0; px < width; px += 1) {
|
|
170
188
|
const x = (px + 0.5) / density - halfW;
|
|
189
|
+
if (Math.abs(x) <= plain) continue;
|
|
171
190
|
const i = (py * width + px) * 4;
|
|
172
191
|
const sd = sdfRoundedRect(x, y, geometry.width, geometry.height, geometry.cornerRadius);
|
|
173
192
|
const e = Math.max(-sd, 0);
|
|
174
|
-
if (e >= bevel)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
data[i] = Math.round(r / HEADROOM * 255);
|
|
183
|
-
data[i + 1] = Math.round(g / HEADROOM * 255);
|
|
184
|
-
data[i + 2] = Math.round(b / HEADROOM * 255);
|
|
193
|
+
if (e >= bevel) continue;
|
|
194
|
+
const u = Math.sqrt(e / bevel) * DEPTH_STEPS;
|
|
195
|
+
const k = Math.min(Math.floor(u), DEPTH_STEPS - 1);
|
|
196
|
+
const f = u - k;
|
|
197
|
+
const at = k * 3;
|
|
198
|
+
data[i] = Math.round((table[at] + (table[at + 3] - table[at]) * f) * toByte);
|
|
199
|
+
data[i + 1] = Math.round((table[at + 1] + (table[at + 4] - table[at + 1]) * f) * toByte);
|
|
200
|
+
data[i + 2] = Math.round((table[at + 2] + (table[at + 5] - table[at + 2]) * f) * toByte);
|
|
185
201
|
data[i + 3] = 255;
|
|
186
202
|
}
|
|
187
203
|
}
|
|
@@ -1081,7 +1097,7 @@ function attachGlass(el, opts = {}) {
|
|
|
1081
1097
|
const body = opts.body === false ? null : bodyCss(settledOptics(), sample, light ? 1 : 0, accent, appear);
|
|
1082
1098
|
if (svgSupported) {
|
|
1083
1099
|
const full = settledOptics();
|
|
1084
|
-
const key = `m${morphKey()}|${geometry.width}x${geometry.height}r${geometry.cornerRadius}@${devicePixelRatio()}:${full.refraction}:${full.refractionScale}:${full.bevelDp}:${full.blur}`;
|
|
1100
|
+
const key = `m${morphKey()}|${geometry.width}x${geometry.height}r${geometry.cornerRadius}@${devicePixelRatio()}:${full.refraction}:${full.refractionScale}:${full.bevelDp}:${full.blur}:${full.thicknessDp}:${full.film}:${full.iridescence}:${full.diffraction}`;
|
|
1085
1101
|
if (interim && filterEl) ; else if (isEmpty(geometry)) ; else if (key !== mapKey || !filterEl) {
|
|
1086
1102
|
const map = cached(`d|${key}`, () => {
|
|
1087
1103
|
bump("fullBakes");
|