@pixldocs/canvas-renderer 0.5.44 → 0.5.46

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/index.cjs CHANGED
@@ -4938,7 +4938,8 @@ function applyTextBackground(obj, cfg) {
4938
4938
  const bgPath = hasBg ? `<path d="${bgD}" fill="${escapeXmlAttr(bgFill)}" />` : "";
4939
4939
  svg = svg.replace(/style="[^"]*filter:\s*url\([^)]+\)[^"]*"/i, "");
4940
4940
  svg = svg.replace(/<filter[\s\S]*?<\/filter>/gi, "");
4941
- let shadowLayer = "";
4941
+ let bgShadowLayer = "";
4942
+ let textShadowLayer = "";
4942
4943
  if (hasShadow) {
4943
4944
  const ox = Number(shadow.offsetX ?? 0) || 0;
4944
4945
  const oy = Number(shadow.offsetY ?? 0) || 0;
@@ -4947,41 +4948,25 @@ function applyTextBackground(obj, cfg) {
4947
4948
  const shadowBgPath = hasBg ? `<path d="${bgD}" fill="${escapeXmlAttr(shadowColor)}" />` : "";
4948
4949
  const inner = extractGInnerMarkup(svg);
4949
4950
  const recoloredText = recolorSvgFills(inner, shadowColor);
4950
- const layers = [];
4951
+ const bgLayers = [];
4952
+ const textLayers = [];
4953
+ const pushShadowPass = (tx, ty, opacity) => {
4954
+ const attrs = `transform="translate(${tx.toFixed(3)} ${ty.toFixed(3)})"${opacity ? ` opacity="${opacity}"` : ""}`;
4955
+ if (shadowBgPath) bgLayers.push(`<g ${attrs}>${shadowBgPath}</g>`);
4956
+ if (recoloredText) textLayers.push(`<g ${attrs}>${recoloredText}</g>`);
4957
+ };
4951
4958
  if (blur > 0) {
4952
- const ringCount = Math.min(6, Math.max(2, Math.round(blur / 2)));
4953
- for (let i = 1; i <= ringCount; i++) {
4954
- const t = i / ringCount;
4955
- const dist = blur * t * 0.6;
4956
- const op = (0.18 * (1 - t * 0.7)).toFixed(3);
4957
- const ringOffsets = [
4958
- [dist, 0],
4959
- [-dist, 0],
4960
- [0, dist],
4961
- [0, -dist],
4962
- [dist * 0.7, dist * 0.7],
4963
- [-dist * 0.7, dist * 0.7],
4964
- [dist * 0.7, -dist * 0.7],
4965
- [-dist * 0.7, -dist * 0.7]
4966
- ];
4967
- for (const [dx, dy] of ringOffsets) {
4968
- layers.push(
4969
- `<g transform="translate(${(ox + dx).toFixed(3)} ${(oy + dy).toFixed(3)})" opacity="${op}">${shadowBgPath}${recoloredText}</g>`
4970
- );
4971
- }
4959
+ for (const pass of buildNormalizedShadowPasses(blur)) {
4960
+ pushShadowPass(ox + pass.dx, oy + pass.dy, pass.opacity);
4972
4961
  }
4973
- layers.push(
4974
- `<g transform="translate(${ox.toFixed(3)} ${oy.toFixed(3)})" opacity="0.25">${shadowBgPath}${recoloredText}</g>`
4975
- );
4976
4962
  } else {
4977
- layers.push(
4978
- `<g transform="translate(${ox.toFixed(3)} ${oy.toFixed(3)})">${shadowBgPath}${recoloredText}</g>`
4979
- );
4963
+ pushShadowPass(ox, oy);
4980
4964
  }
4981
- shadowLayer = layers.join("");
4965
+ bgShadowLayer = bgLayers.join("");
4966
+ textShadowLayer = textLayers.join("");
4982
4967
  }
4983
4968
  const openTagMatch = svg.match(/^\s*<g\b[^>]*>/);
4984
- const inserted = shadowLayer + bgPath;
4969
+ const inserted = bgShadowLayer + bgPath + textShadowLayer;
4985
4970
  if (openTagMatch) {
4986
4971
  const openTag = openTagMatch[0];
4987
4972
  return svg.replace(openTag, openTag + inserted);
@@ -5009,6 +4994,36 @@ function recolorSvgFills(svg, color) {
5009
4994
  );
5010
4995
  return out;
5011
4996
  }
4997
+ function buildNormalizedShadowPasses(blur) {
4998
+ const safeBlur = Math.max(0, Number(blur) || 0);
4999
+ const ringCount = Math.min(5, Math.max(2, Math.round(safeBlur / 5)));
5000
+ const targetOpacity = Math.max(0.16, Math.min(0.38, 0.46 - safeBlur * 0.01));
5001
+ const weighted = [
5002
+ { dx: 0, dy: 0, weight: 0.7 }
5003
+ ];
5004
+ for (let i = 1; i <= ringCount; i++) {
5005
+ const t = i / ringCount;
5006
+ const dist = safeBlur * t * 0.42;
5007
+ const weight = Math.exp(-2.4 * t * t);
5008
+ const diag = dist * 0.7071;
5009
+ weighted.push(
5010
+ { dx: dist, dy: 0, weight },
5011
+ { dx: -dist, dy: 0, weight },
5012
+ { dx: 0, dy: dist, weight },
5013
+ { dx: 0, dy: -dist, weight },
5014
+ { dx: diag, dy: diag, weight: weight * 0.72 },
5015
+ { dx: -diag, dy: diag, weight: weight * 0.72 },
5016
+ { dx: diag, dy: -diag, weight: weight * 0.72 },
5017
+ { dx: -diag, dy: -diag, weight: weight * 0.72 }
5018
+ );
5019
+ }
5020
+ const totalWeight = weighted.reduce((sum, pass) => sum + pass.weight, 0) || 1;
5021
+ return weighted.map((pass) => ({
5022
+ dx: pass.dx,
5023
+ dy: pass.dy,
5024
+ opacity: Math.max(3e-3, targetOpacity * pass.weight / totalWeight).toFixed(4)
5025
+ }));
5026
+ }
5012
5027
  function buildRoundedRectPathD(x, y, w, h, rTL, rTR, rBR, rBL) {
5013
5028
  const maxR = Math.min(w, h) / 2;
5014
5029
  const tl = Math.min(Math.max(0, rTL), maxR);
@@ -12360,7 +12375,7 @@ function PixldocsPreview(props) {
12360
12375
  !canvasSettled && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) })
12361
12376
  ] });
12362
12377
  }
12363
- const PACKAGE_VERSION = "0.5.44";
12378
+ const PACKAGE_VERSION = "0.5.46";
12364
12379
  let __underlineFixInstalled = false;
12365
12380
  function installUnderlineFix(fab) {
12366
12381
  var _a;