@pixldocs/canvas-renderer 0.5.41 → 0.5.43
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 +217 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +217 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -221,7 +221,7 @@ export declare function normalizeFontFamily(fontStack: string): string;
|
|
|
221
221
|
* Package version banner. Bump alongside package.json so we can confirm
|
|
222
222
|
* (via browser:log) that the deployed bundle matches the expected build.
|
|
223
223
|
*/
|
|
224
|
-
export declare const PACKAGE_VERSION = "0.5.
|
|
224
|
+
export declare const PACKAGE_VERSION = "0.5.43";
|
|
225
225
|
|
|
226
226
|
export declare interface PageSettings {
|
|
227
227
|
backgroundColor?: string;
|
package/dist/index.js
CHANGED
|
@@ -4782,6 +4782,170 @@ function calculateScaleSnapGuides(scalingObj, corner, canvas, canvasWidth, canva
|
|
|
4782
4782
|
return true;
|
|
4783
4783
|
});
|
|
4784
4784
|
}
|
|
4785
|
+
const PD_BG_KEY = "__pdBg";
|
|
4786
|
+
const PATCHED_KEY = "__pdBgPatched";
|
|
4787
|
+
function extractTextBgConfig(element) {
|
|
4788
|
+
const legacy = Math.max(0, Number(element.textBgPadding ?? 0)) || 0;
|
|
4789
|
+
const pick = (v) => {
|
|
4790
|
+
const n = Number(v);
|
|
4791
|
+
return Number.isFinite(n) && n >= 0 ? n : void 0;
|
|
4792
|
+
};
|
|
4793
|
+
return {
|
|
4794
|
+
color: element.textBgColor,
|
|
4795
|
+
padTop: pick(element.textBgPaddingTop) ?? legacy,
|
|
4796
|
+
padRight: pick(element.textBgPaddingRight) ?? legacy,
|
|
4797
|
+
padBottom: pick(element.textBgPaddingBottom) ?? legacy,
|
|
4798
|
+
padLeft: pick(element.textBgPaddingLeft) ?? legacy,
|
|
4799
|
+
rxTL: Math.max(0, Number(element.textBgRxTL ?? 0)) || 0,
|
|
4800
|
+
rxTR: Math.max(0, Number(element.textBgRxTR ?? 0)) || 0,
|
|
4801
|
+
rxBR: Math.max(0, Number(element.textBgRxBR ?? 0)) || 0,
|
|
4802
|
+
rxBL: Math.max(0, Number(element.textBgRxBL ?? 0)) || 0
|
|
4803
|
+
};
|
|
4804
|
+
}
|
|
4805
|
+
function hasTextBackground(cfg) {
|
|
4806
|
+
if (!cfg) return false;
|
|
4807
|
+
const c = (cfg.color || "").toString().trim().toLowerCase();
|
|
4808
|
+
return !!c && c !== "transparent" && c !== "none" && c !== "rgba(0,0,0,0)";
|
|
4809
|
+
}
|
|
4810
|
+
function buildTextShadow(element) {
|
|
4811
|
+
const color = element.textShadowColor;
|
|
4812
|
+
const blur = Number(element.textShadowBlur ?? 0);
|
|
4813
|
+
const ox = Number(element.textShadowOffsetX ?? 0);
|
|
4814
|
+
const oy = Number(element.textShadowOffsetY ?? 0);
|
|
4815
|
+
if (!color || color === "transparent") return null;
|
|
4816
|
+
return new fabric.Shadow({
|
|
4817
|
+
color: String(color),
|
|
4818
|
+
blur: blur || 0,
|
|
4819
|
+
offsetX: ox || 0,
|
|
4820
|
+
offsetY: oy || 0,
|
|
4821
|
+
affectStroke: false,
|
|
4822
|
+
nonScaling: false
|
|
4823
|
+
});
|
|
4824
|
+
}
|
|
4825
|
+
function buildRoundedRectPath2D(ctx, x, y, w, h, rTL, rTR, rBR, rBL) {
|
|
4826
|
+
const maxR = Math.min(w, h) / 2;
|
|
4827
|
+
const tl = Math.min(Math.max(0, rTL), maxR);
|
|
4828
|
+
const tr = Math.min(Math.max(0, rTR), maxR);
|
|
4829
|
+
const br = Math.min(Math.max(0, rBR), maxR);
|
|
4830
|
+
const bl = Math.min(Math.max(0, rBL), maxR);
|
|
4831
|
+
ctx.beginPath();
|
|
4832
|
+
ctx.moveTo(x + tl, y);
|
|
4833
|
+
ctx.lineTo(x + w - tr, y);
|
|
4834
|
+
if (tr > 0) ctx.quadraticCurveTo(x + w, y, x + w, y + tr);
|
|
4835
|
+
ctx.lineTo(x + w, y + h - br);
|
|
4836
|
+
if (br > 0) ctx.quadraticCurveTo(x + w, y + h, x + w - br, y + h);
|
|
4837
|
+
ctx.lineTo(x + bl, y + h);
|
|
4838
|
+
if (bl > 0) ctx.quadraticCurveTo(x, y + h, x, y + h - bl);
|
|
4839
|
+
ctx.lineTo(x, y + tl);
|
|
4840
|
+
if (tl > 0) ctx.quadraticCurveTo(x, y, x + tl, y);
|
|
4841
|
+
ctx.closePath();
|
|
4842
|
+
}
|
|
4843
|
+
function applyTextBackground(obj, cfg) {
|
|
4844
|
+
var _a;
|
|
4845
|
+
obj[PD_BG_KEY] = { ...cfg };
|
|
4846
|
+
if (obj[PATCHED_KEY]) return;
|
|
4847
|
+
obj[PATCHED_KEY] = true;
|
|
4848
|
+
const originalRender = obj._render.bind(obj);
|
|
4849
|
+
obj._render = function(ctx) {
|
|
4850
|
+
const bg = this[PD_BG_KEY];
|
|
4851
|
+
if (hasTextBackground(bg)) {
|
|
4852
|
+
const w = this.width ?? 0;
|
|
4853
|
+
const h = this.height ?? 0;
|
|
4854
|
+
const pT = Math.max(0, Number(bg.padTop ?? 0));
|
|
4855
|
+
const pR = Math.max(0, Number(bg.padRight ?? 0));
|
|
4856
|
+
const pB = Math.max(0, Number(bg.padBottom ?? 0));
|
|
4857
|
+
const pL = Math.max(0, Number(bg.padLeft ?? 0));
|
|
4858
|
+
const x = -w / 2 - pL;
|
|
4859
|
+
const y = -h / 2 - pT;
|
|
4860
|
+
const bgW = w + pL + pR;
|
|
4861
|
+
const bgH = h + pT + pB;
|
|
4862
|
+
ctx.save();
|
|
4863
|
+
buildRoundedRectPath2D(
|
|
4864
|
+
ctx,
|
|
4865
|
+
x,
|
|
4866
|
+
y,
|
|
4867
|
+
bgW,
|
|
4868
|
+
bgH,
|
|
4869
|
+
bg.rxTL ?? 0,
|
|
4870
|
+
bg.rxTR ?? 0,
|
|
4871
|
+
bg.rxBR ?? 0,
|
|
4872
|
+
bg.rxBL ?? 0
|
|
4873
|
+
);
|
|
4874
|
+
ctx.fillStyle = bg.color;
|
|
4875
|
+
ctx.fill();
|
|
4876
|
+
ctx.restore();
|
|
4877
|
+
}
|
|
4878
|
+
originalRender(ctx);
|
|
4879
|
+
};
|
|
4880
|
+
const originalToObject = obj.toObject.bind(obj);
|
|
4881
|
+
obj.toObject = function(propertiesToInclude) {
|
|
4882
|
+
const out = originalToObject(propertiesToInclude);
|
|
4883
|
+
const bg = this[PD_BG_KEY];
|
|
4884
|
+
if (hasTextBackground(bg)) {
|
|
4885
|
+
out.__pdBg = { ...bg };
|
|
4886
|
+
}
|
|
4887
|
+
return out;
|
|
4888
|
+
};
|
|
4889
|
+
const originalToSVG = (_a = obj.toSVG) == null ? void 0 : _a.bind(obj);
|
|
4890
|
+
if (typeof originalToSVG === "function") {
|
|
4891
|
+
obj.toSVG = function(reviver) {
|
|
4892
|
+
const svg = originalToSVG(reviver);
|
|
4893
|
+
const bg = this[PD_BG_KEY];
|
|
4894
|
+
if (!hasTextBackground(bg)) return svg;
|
|
4895
|
+
const w = this.width ?? 0;
|
|
4896
|
+
const h = this.height ?? 0;
|
|
4897
|
+
const pT = Math.max(0, Number(bg.padTop ?? 0));
|
|
4898
|
+
const pR = Math.max(0, Number(bg.padRight ?? 0));
|
|
4899
|
+
const pB = Math.max(0, Number(bg.padBottom ?? 0));
|
|
4900
|
+
const pL = Math.max(0, Number(bg.padLeft ?? 0));
|
|
4901
|
+
const x = -w / 2 - pL;
|
|
4902
|
+
const y = -h / 2 - pT;
|
|
4903
|
+
const bgW = w + pL + pR;
|
|
4904
|
+
const bgH = h + pT + pB;
|
|
4905
|
+
const d = buildRoundedRectPathD(
|
|
4906
|
+
x,
|
|
4907
|
+
y,
|
|
4908
|
+
bgW,
|
|
4909
|
+
bgH,
|
|
4910
|
+
bg.rxTL ?? 0,
|
|
4911
|
+
bg.rxTR ?? 0,
|
|
4912
|
+
bg.rxBR ?? 0,
|
|
4913
|
+
bg.rxBL ?? 0
|
|
4914
|
+
);
|
|
4915
|
+
const fill = bg.color;
|
|
4916
|
+
const bgPath = `<path d="${d}" fill="${escapeXmlAttr(fill)}" />`;
|
|
4917
|
+
const openTagMatch = svg.match(/^\s*<g\b[^>]*>/);
|
|
4918
|
+
if (openTagMatch) {
|
|
4919
|
+
const openTag = openTagMatch[0];
|
|
4920
|
+
return svg.replace(openTag, openTag + bgPath);
|
|
4921
|
+
}
|
|
4922
|
+
return `<g>${bgPath}${svg}</g>`;
|
|
4923
|
+
};
|
|
4924
|
+
}
|
|
4925
|
+
}
|
|
4926
|
+
function buildRoundedRectPathD(x, y, w, h, rTL, rTR, rBR, rBL) {
|
|
4927
|
+
const maxR = Math.min(w, h) / 2;
|
|
4928
|
+
const tl = Math.min(Math.max(0, rTL), maxR);
|
|
4929
|
+
const tr = Math.min(Math.max(0, rTR), maxR);
|
|
4930
|
+
const br = Math.min(Math.max(0, rBR), maxR);
|
|
4931
|
+
const bl = Math.min(Math.max(0, rBL), maxR);
|
|
4932
|
+
const fmt = (n) => Number.isFinite(n) ? Number(n.toFixed(3)) : 0;
|
|
4933
|
+
const parts = [];
|
|
4934
|
+
parts.push(`M ${fmt(x + tl)} ${fmt(y)}`);
|
|
4935
|
+
parts.push(`L ${fmt(x + w - tr)} ${fmt(y)}`);
|
|
4936
|
+
if (tr > 0) parts.push(`Q ${fmt(x + w)} ${fmt(y)} ${fmt(x + w)} ${fmt(y + tr)}`);
|
|
4937
|
+
parts.push(`L ${fmt(x + w)} ${fmt(y + h - br)}`);
|
|
4938
|
+
if (br > 0) parts.push(`Q ${fmt(x + w)} ${fmt(y + h)} ${fmt(x + w - br)} ${fmt(y + h)}`);
|
|
4939
|
+
parts.push(`L ${fmt(x + bl)} ${fmt(y + h)}`);
|
|
4940
|
+
if (bl > 0) parts.push(`Q ${fmt(x)} ${fmt(y + h)} ${fmt(x)} ${fmt(y + h - bl)}`);
|
|
4941
|
+
parts.push(`L ${fmt(x)} ${fmt(y + tl)}`);
|
|
4942
|
+
if (tl > 0) parts.push(`Q ${fmt(x)} ${fmt(y)} ${fmt(x + tl)} ${fmt(y)}`);
|
|
4943
|
+
parts.push("Z");
|
|
4944
|
+
return parts.join(" ");
|
|
4945
|
+
}
|
|
4946
|
+
function escapeXmlAttr(s) {
|
|
4947
|
+
return String(s).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
4948
|
+
}
|
|
4785
4949
|
const TRIANGLE_STROKE_MITER_LIMIT = 1e6;
|
|
4786
4950
|
const toSafeNumber = (value, fallback = 0) => Number.isFinite(value) ? Math.max(0, Number(value)) : fallback;
|
|
4787
4951
|
function normalizeShapeType(shapeType) {
|
|
@@ -5082,6 +5246,9 @@ function createText(element) {
|
|
|
5082
5246
|
textbox.setCoords();
|
|
5083
5247
|
}
|
|
5084
5248
|
textbox.dirty = true;
|
|
5249
|
+
applyTextBackground(textbox, extractTextBgConfig(element));
|
|
5250
|
+
const shadow = buildTextShadow(element);
|
|
5251
|
+
if (shadow) textbox.set("shadow", shadow);
|
|
5085
5252
|
return textbox;
|
|
5086
5253
|
}
|
|
5087
5254
|
function createLine(element) {
|
|
@@ -7694,7 +7861,23 @@ const PageCanvas = forwardRef(
|
|
|
7694
7861
|
const resolvedSizeForCompare = (pageChildren == null ? void 0 : pageChildren.length) ? getNodeBounds(element, pageChildren) : { width: typeof element.width === "number" ? element.width : 0, height: typeof element.height === "number" ? element.height : 0 };
|
|
7695
7862
|
const fabricText = existingObj.text ?? "";
|
|
7696
7863
|
const storeText = element.text ?? "";
|
|
7697
|
-
const otherPropsChanged = Math.abs((existingObj.width ?? 0) - resolvedSizeForCompare.width) > 0.1 || Math.abs((existingObj.height ?? 0) - resolvedSizeForCompare.height) > 0.1 || Math.abs((existingObj.angle ?? 0) - (element.angle ?? 0)) > 0.1 || Math.abs((existingObj.scaleX ?? 1) - (element.scaleX ?? 1)) > 0.01 || Math.abs((existingObj.scaleY ?? 1) - (element.scaleY ?? 1)) > 0.01 || (existingObj.flipX ?? false) !== (element.flipX ?? false) || (existingObj.flipY ?? false) !== (element.flipY ?? false) || fabricText !== storeText || existingObj.fill !== (element.fill ?? "") || existingObj.stroke !== (element.stroke ?? "") || Math.abs((existingObj.strokeWidth ?? 0) - (element.strokeWidth ?? 0)) > 0.01 || Math.abs((existingObj.opacity ?? 1) - (element.opacity ?? 1)) > 0.01 || (existingObj.fontSize ?? 0) !== (element.fontSize ?? 0) || (existingObj.fontFamily ?? "") !== (element.fontFamily ?? "") || //
|
|
7864
|
+
const otherPropsChanged = Math.abs((existingObj.width ?? 0) - resolvedSizeForCompare.width) > 0.1 || Math.abs((existingObj.height ?? 0) - resolvedSizeForCompare.height) > 0.1 || Math.abs((existingObj.angle ?? 0) - (element.angle ?? 0)) > 0.1 || Math.abs((existingObj.scaleX ?? 1) - (element.scaleX ?? 1)) > 0.01 || Math.abs((existingObj.scaleY ?? 1) - (element.scaleY ?? 1)) > 0.01 || (existingObj.flipX ?? false) !== (element.flipX ?? false) || (existingObj.flipY ?? false) !== (element.flipY ?? false) || fabricText !== storeText || existingObj.fill !== (element.fill ?? "") || existingObj.stroke !== (element.stroke ?? "") || Math.abs((existingObj.strokeWidth ?? 0) - (element.strokeWidth ?? 0)) > 0.01 || Math.abs((existingObj.opacity ?? 1) - (element.opacity ?? 1)) > 0.01 || (existingObj.fontSize ?? 0) !== (element.fontSize ?? 0) || (existingObj.fontFamily ?? "") !== (element.fontFamily ?? "") || // Detect text background + shadow changes so panel edits flow into Fabric.
|
|
7865
|
+
JSON.stringify({
|
|
7866
|
+
c: element.textBgColor ?? null,
|
|
7867
|
+
p: element.textBgPadding ?? 0,
|
|
7868
|
+
pt: element.textBgPaddingTop ?? null,
|
|
7869
|
+
pr: element.textBgPaddingRight ?? null,
|
|
7870
|
+
pb: element.textBgPaddingBottom ?? null,
|
|
7871
|
+
pl: element.textBgPaddingLeft ?? null,
|
|
7872
|
+
tl: element.textBgRxTL ?? 0,
|
|
7873
|
+
tr: element.textBgRxTR ?? 0,
|
|
7874
|
+
br: element.textBgRxBR ?? 0,
|
|
7875
|
+
bl: element.textBgRxBL ?? 0,
|
|
7876
|
+
sc: element.textShadowColor ?? null,
|
|
7877
|
+
sb: element.textShadowBlur ?? 0,
|
|
7878
|
+
sx: element.textShadowOffsetX ?? 0,
|
|
7879
|
+
sy: element.textShadowOffsetY ?? 0
|
|
7880
|
+
}) !== (existingObj.__lastTextBgShadowJson ?? "") || // CRITICAL: Detect gradient fill/stroke changes — serialise to JSON for deep comparison
|
|
7698
7881
|
JSON.stringify(element.fillGradient || null) !== (existingObj.__lastFillGradientJson ?? "null") || JSON.stringify(element.strokeGradient || null) !== (existingObj.__lastStrokeGradientJson ?? "null");
|
|
7699
7882
|
const forceApplyFromPanel = syncTriggeredByPanelRef.current;
|
|
7700
7883
|
const noPropsOrPositionChanged = !positionChanged && !otherPropsChanged;
|
|
@@ -8129,7 +8312,7 @@ const PageCanvas = forwardRef(
|
|
|
8129
8312
|
});
|
|
8130
8313
|
}, [selectedIds, isActive, ready, elements]);
|
|
8131
8314
|
const updateFabricObject = (obj, element, skipPositionUpdate = false) => {
|
|
8132
|
-
var _a, _b;
|
|
8315
|
+
var _a, _b, _c;
|
|
8133
8316
|
const fc = fabricRef.current;
|
|
8134
8317
|
if (fc && isTransforming(fc)) {
|
|
8135
8318
|
return;
|
|
@@ -8589,6 +8772,37 @@ const PageCanvas = forwardRef(
|
|
|
8589
8772
|
}
|
|
8590
8773
|
obj.setCoords();
|
|
8591
8774
|
obj.dirty = true;
|
|
8775
|
+
try {
|
|
8776
|
+
applyTextBackground(obj, extractTextBgConfig(element));
|
|
8777
|
+
const shadow = buildTextShadow(element);
|
|
8778
|
+
obj.set("shadow", shadow ?? null);
|
|
8779
|
+
try {
|
|
8780
|
+
obj._cacheCanvas = null;
|
|
8781
|
+
obj._cacheContext = null;
|
|
8782
|
+
} catch {
|
|
8783
|
+
}
|
|
8784
|
+
obj.dirty = true;
|
|
8785
|
+
(_c = obj.setCoords) == null ? void 0 : _c.call(obj);
|
|
8786
|
+
obj.__lastTextBgShadowJson = JSON.stringify({
|
|
8787
|
+
c: element.textBgColor ?? null,
|
|
8788
|
+
p: element.textBgPadding ?? 0,
|
|
8789
|
+
pt: element.textBgPaddingTop ?? null,
|
|
8790
|
+
pr: element.textBgPaddingRight ?? null,
|
|
8791
|
+
pb: element.textBgPaddingBottom ?? null,
|
|
8792
|
+
pl: element.textBgPaddingLeft ?? null,
|
|
8793
|
+
tl: element.textBgRxTL ?? 0,
|
|
8794
|
+
tr: element.textBgRxTR ?? 0,
|
|
8795
|
+
br: element.textBgRxBR ?? 0,
|
|
8796
|
+
bl: element.textBgRxBL ?? 0,
|
|
8797
|
+
sc: element.textShadowColor ?? null,
|
|
8798
|
+
sb: element.textShadowBlur ?? 0,
|
|
8799
|
+
sx: element.textShadowOffsetX ?? 0,
|
|
8800
|
+
sy: element.textShadowOffsetY ?? 0
|
|
8801
|
+
});
|
|
8802
|
+
obj.dirty = true;
|
|
8803
|
+
} catch (err) {
|
|
8804
|
+
console.warn("[text-bg] failed to apply background/shadow", err);
|
|
8805
|
+
}
|
|
8592
8806
|
} else if (!isImage && !isLine) {
|
|
8593
8807
|
if (obj instanceof fabric.Circle) {
|
|
8594
8808
|
obj.set({
|
|
@@ -12053,7 +12267,7 @@ function PixldocsPreview(props) {
|
|
|
12053
12267
|
!canvasSettled && /* @__PURE__ */ jsx("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) })
|
|
12054
12268
|
] });
|
|
12055
12269
|
}
|
|
12056
|
-
const PACKAGE_VERSION = "0.5.
|
|
12270
|
+
const PACKAGE_VERSION = "0.5.43";
|
|
12057
12271
|
let __underlineFixInstalled = false;
|
|
12058
12272
|
function installUnderlineFix(fab) {
|
|
12059
12273
|
var _a;
|