@pixldocs/canvas-renderer 0.5.39 → 0.5.40
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 +25 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +25 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -12072,7 +12072,7 @@ function PixldocsPreview(props) {
|
|
|
12072
12072
|
!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..." }) })
|
|
12073
12073
|
] });
|
|
12074
12074
|
}
|
|
12075
|
-
const PACKAGE_VERSION = "0.5.
|
|
12075
|
+
const PACKAGE_VERSION = "0.5.40";
|
|
12076
12076
|
let __underlineFixInstalled = false;
|
|
12077
12077
|
function installUnderlineFix(fab) {
|
|
12078
12078
|
var _a;
|
|
@@ -12080,6 +12080,24 @@ function installUnderlineFix(fab) {
|
|
|
12080
12080
|
const TextProto = (_a = fab.Text) == null ? void 0 : _a.prototype;
|
|
12081
12081
|
if (!TextProto || typeof TextProto._renderTextDecoration !== "function") return;
|
|
12082
12082
|
const original = TextProto._renderTextDecoration;
|
|
12083
|
+
const measureLineTextWidth = (obj, ctx, lineIndex) => {
|
|
12084
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
12085
|
+
const rawLine = (_a2 = obj._textLines) == null ? void 0 : _a2[lineIndex];
|
|
12086
|
+
const lineText = Array.isArray(rawLine) ? rawLine.join("") : String(rawLine ?? "");
|
|
12087
|
+
if (!lineText) return 0;
|
|
12088
|
+
const fontSize = Number(((_b = obj.getValueOfPropertyAt) == null ? void 0 : _b.call(obj, lineIndex, 0, "fontSize")) ?? obj.fontSize ?? 0);
|
|
12089
|
+
const fontStyle = String(((_c = obj.getValueOfPropertyAt) == null ? void 0 : _c.call(obj, lineIndex, 0, "fontStyle")) ?? obj.fontStyle ?? "normal");
|
|
12090
|
+
const fontWeight = String(((_d = obj.getValueOfPropertyAt) == null ? void 0 : _d.call(obj, lineIndex, 0, "fontWeight")) ?? obj.fontWeight ?? "400");
|
|
12091
|
+
const fontFamily = String(((_e = obj.getValueOfPropertyAt) == null ? void 0 : _e.call(obj, lineIndex, 0, "fontFamily")) ?? obj.fontFamily ?? "sans-serif");
|
|
12092
|
+
const charSpacing = Number(((_f = obj.getValueOfPropertyAt) == null ? void 0 : _f.call(obj, lineIndex, 0, "charSpacing")) ?? obj.charSpacing ?? 0);
|
|
12093
|
+
ctx.save();
|
|
12094
|
+
ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
12095
|
+
const measured = ctx.measureText(lineText).width;
|
|
12096
|
+
ctx.restore();
|
|
12097
|
+
const graphemeCount = Array.from(lineText).length;
|
|
12098
|
+
const spacingWidth = graphemeCount > 1 ? charSpacing / 1e3 * fontSize * (graphemeCount - 1) : 0;
|
|
12099
|
+
return Math.max(0, measured + spacingWidth);
|
|
12100
|
+
};
|
|
12083
12101
|
TextProto._renderTextDecoration = function patchedRenderTextDecoration(ctx, type) {
|
|
12084
12102
|
try {
|
|
12085
12103
|
const hasOwn = !!this[type];
|
|
@@ -12110,20 +12128,16 @@ function installUnderlineFix(fab) {
|
|
|
12110
12128
|
topOffset += heightOfLine;
|
|
12111
12129
|
continue;
|
|
12112
12130
|
}
|
|
12113
|
-
|
|
12114
|
-
this.__lineWidths[i] = void 0;
|
|
12115
|
-
}
|
|
12116
|
-
let lineWidth = 0;
|
|
12117
|
-
try {
|
|
12118
|
-
lineWidth = this.getLineWidth(i);
|
|
12119
|
-
} catch {
|
|
12120
|
-
lineWidth = 0;
|
|
12121
|
-
}
|
|
12131
|
+
const lineWidth = measureLineTextWidth(this, ctx, i);
|
|
12122
12132
|
if (!lineWidth) {
|
|
12123
12133
|
topOffset += heightOfLine;
|
|
12124
12134
|
continue;
|
|
12125
12135
|
}
|
|
12126
|
-
const
|
|
12136
|
+
const availableWidth = Number(this.width ?? lineWidth);
|
|
12137
|
+
let lineLeftOffset = 0;
|
|
12138
|
+
const align = String(this.textAlign ?? "left");
|
|
12139
|
+
if (align === "center") lineLeftOffset = (availableWidth - lineWidth) / 2;
|
|
12140
|
+
else if (align === "right" || align === "end") lineLeftOffset = availableWidth - lineWidth;
|
|
12127
12141
|
let drawStart = leftOffset + lineLeftOffset;
|
|
12128
12142
|
if (this.direction === "rtl") {
|
|
12129
12143
|
drawStart = this.width - drawStart - lineWidth;
|