@pixldocs/canvas-renderer 0.5.38 → 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 +76 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +76 -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,26 +12080,91 @@ 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];
|
|
12086
12104
|
const hasStyled = typeof this.styleHas === "function" && this.styleHas(type);
|
|
12087
|
-
if (!hasOwn && !hasStyled)
|
|
12105
|
+
if (!hasOwn && !hasStyled) return;
|
|
12106
|
+
const lines = this._textLines;
|
|
12107
|
+
const offsets = this.offsets;
|
|
12108
|
+
if (!Array.isArray(lines) || !offsets) {
|
|
12088
12109
|
return original.call(this, ctx, type);
|
|
12089
12110
|
}
|
|
12090
|
-
const
|
|
12091
|
-
|
|
12092
|
-
|
|
12093
|
-
|
|
12094
|
-
|
|
12095
|
-
|
|
12096
|
-
|
|
12097
|
-
|
|
12111
|
+
const offsetY = offsets[type];
|
|
12112
|
+
const offsetAligner = type === "linethrough" ? 0.5 : type === "overline" ? 1 : 0;
|
|
12113
|
+
const leftOffset = this._getLeftOffset();
|
|
12114
|
+
let topOffset = this._getTopOffset();
|
|
12115
|
+
for (let i = 0, len = lines.length; i < len; i++) {
|
|
12116
|
+
const heightOfLine = this.getHeightOfLine(i);
|
|
12117
|
+
const lineHas = !!this[type] || typeof this.styleHas === "function" && this.styleHas(type, i);
|
|
12118
|
+
if (!lineHas) {
|
|
12119
|
+
topOffset += heightOfLine;
|
|
12120
|
+
continue;
|
|
12121
|
+
}
|
|
12122
|
+
const fillStyle = this.getValueOfPropertyAt(i, 0, "fill");
|
|
12123
|
+
const thickness = this.getValueOfPropertyAt(i, 0, "textDecorationThickness");
|
|
12124
|
+
const charSize = this.getHeightOfChar(i, 0);
|
|
12125
|
+
const dy = this.getValueOfPropertyAt(i, 0, "deltaY") || 0;
|
|
12126
|
+
const finalThickness = this.fontSize * (thickness || 0) / 1e3;
|
|
12127
|
+
if (!fillStyle || !finalThickness) {
|
|
12128
|
+
topOffset += heightOfLine;
|
|
12129
|
+
continue;
|
|
12130
|
+
}
|
|
12131
|
+
const lineWidth = measureLineTextWidth(this, ctx, i);
|
|
12132
|
+
if (!lineWidth) {
|
|
12133
|
+
topOffset += heightOfLine;
|
|
12134
|
+
continue;
|
|
12135
|
+
}
|
|
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;
|
|
12141
|
+
let drawStart = leftOffset + lineLeftOffset;
|
|
12142
|
+
if (this.direction === "rtl") {
|
|
12143
|
+
drawStart = this.width - drawStart - lineWidth;
|
|
12144
|
+
}
|
|
12145
|
+
const maxHeight = heightOfLine / this.lineHeight;
|
|
12146
|
+
const top = topOffset + maxHeight * (1 - this._fontSizeFraction);
|
|
12147
|
+
ctx.fillStyle = fillStyle;
|
|
12148
|
+
ctx.fillRect(
|
|
12149
|
+
drawStart,
|
|
12150
|
+
top + offsetY * charSize + dy - offsetAligner * finalThickness,
|
|
12151
|
+
lineWidth,
|
|
12152
|
+
finalThickness
|
|
12153
|
+
);
|
|
12154
|
+
topOffset += heightOfLine;
|
|
12155
|
+
}
|
|
12156
|
+
if (typeof this._removeShadow === "function") {
|
|
12157
|
+
try {
|
|
12158
|
+
this._removeShadow(ctx);
|
|
12159
|
+
} catch {
|
|
12098
12160
|
}
|
|
12099
12161
|
}
|
|
12100
12162
|
} catch {
|
|
12163
|
+
try {
|
|
12164
|
+
return original.call(this, ctx, type);
|
|
12165
|
+
} catch {
|
|
12166
|
+
}
|
|
12101
12167
|
}
|
|
12102
|
-
return original.call(this, ctx, type);
|
|
12103
12168
|
};
|
|
12104
12169
|
__underlineFixInstalled = true;
|
|
12105
12170
|
console.log(`[canvas-renderer] underline-fix monkey patch installed (v${PACKAGE_VERSION})`);
|