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 CHANGED
@@ -711,6 +711,18 @@ function mapDensity2(bevel, dpr) {
711
711
  if (bevel <= 0) return dpr;
712
712
  return Math.min(dpr, BEVEL_SAMPLES2 / bevel);
713
713
  }
714
+ var DEPTH_STEPS = 2048;
715
+ function hueAlongDepth(bevel, rim, thick, optics) {
716
+ const table = new Float64Array((DEPTH_STEPS + 1) * 3);
717
+ for (let k = 0; k <= DEPTH_STEPS; k += 1) {
718
+ const s = k / DEPTH_STEPS;
719
+ const [r, g, b] = spectralHue(s * s * bevel, bevel, rim, thick, optics);
720
+ table[k * 3] = r;
721
+ table[k * 3 + 1] = g;
722
+ table[k * 3 + 2] = b;
723
+ }
724
+ return table;
725
+ }
714
726
  function renderSpectralPixels(optics, geometry, dpr) {
715
727
  const bevel = bevelDp(geometry, optics);
716
728
  const density = mapDensity2(bevel, dpr);
@@ -722,24 +734,28 @@ function renderSpectralPixels(optics, geometry, dpr) {
722
734
  const halfW = geometry.width / 2;
723
735
  const halfH = geometry.height / 2;
724
736
  const neutral = Math.round(1 / HEADROOM * 255);
737
+ const table = hueAlongDepth(bevel, rim, thick, optics);
738
+ const toByte = 255 / HEADROOM;
739
+ new Uint32Array(data.buffer).fill(new Uint32Array(new Uint8ClampedArray([neutral, neutral, neutral, 255]).buffer)[0]);
740
+ const corner = Math.max(geometry.cornerRadius, bevel);
725
741
  for (let py = 0; py < height; py += 1) {
726
742
  const y = (py + 0.5) / density - halfH;
743
+ const ay = Math.abs(y);
744
+ const plain = Math.max(ay <= halfH - bevel ? halfW - corner : -1, ay <= halfH - corner ? halfW - bevel : -1);
727
745
  for (let px = 0; px < width; px += 1) {
728
746
  const x = (px + 0.5) / density - halfW;
747
+ if (Math.abs(x) <= plain) continue;
729
748
  const i = (py * width + px) * 4;
730
749
  const sd = sdfRoundedRect(x, y, geometry.width, geometry.height, geometry.cornerRadius);
731
750
  const e = Math.max(-sd, 0);
732
- if (e >= bevel) {
733
- data[i] = neutral;
734
- data[i + 1] = neutral;
735
- data[i + 2] = neutral;
736
- data[i + 3] = 255;
737
- continue;
738
- }
739
- const [r, g, b] = spectralHue(e, bevel, rim, thick, optics);
740
- data[i] = Math.round(r / HEADROOM * 255);
741
- data[i + 1] = Math.round(g / HEADROOM * 255);
742
- data[i + 2] = Math.round(b / HEADROOM * 255);
751
+ if (e >= bevel) continue;
752
+ const u = Math.sqrt(e / bevel) * DEPTH_STEPS;
753
+ const k = Math.min(Math.floor(u), DEPTH_STEPS - 1);
754
+ const f = u - k;
755
+ const at = k * 3;
756
+ data[i] = Math.round((table[at] + (table[at + 3] - table[at]) * f) * toByte);
757
+ data[i + 1] = Math.round((table[at + 1] + (table[at + 4] - table[at + 1]) * f) * toByte);
758
+ data[i + 2] = Math.round((table[at + 2] + (table[at + 5] - table[at + 2]) * f) * toByte);
743
759
  data[i + 3] = 255;
744
760
  }
745
761
  }
@@ -2089,7 +2105,7 @@ function attachGlass(el, opts = {}) {
2089
2105
  const body = opts.body === false ? null : bodyCss(settledOptics(), sample, light ? 1 : 0, accent, appear);
2090
2106
  if (svgSupported) {
2091
2107
  const full = settledOptics();
2092
- const key = `m${morphKey()}|${geometry.width}x${geometry.height}r${geometry.cornerRadius}@${devicePixelRatio()}:${full.refraction}:${full.refractionScale}:${full.bevelDp}:${full.blur}`;
2108
+ 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}`;
2093
2109
  if (interim && filterEl) ; else if (isEmpty(geometry)) ; else if (key !== mapKey || !filterEl) {
2094
2110
  const map = cached(`d|${key}`, () => {
2095
2111
  bump("fullBakes");