@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.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.40";
|
|
225
225
|
|
|
226
226
|
export declare interface PageSettings {
|
|
227
227
|
backgroundColor?: string;
|
package/dist/index.js
CHANGED
|
@@ -12053,7 +12053,7 @@ function PixldocsPreview(props) {
|
|
|
12053
12053
|
!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
12054
|
] });
|
|
12055
12055
|
}
|
|
12056
|
-
const PACKAGE_VERSION = "0.5.
|
|
12056
|
+
const PACKAGE_VERSION = "0.5.40";
|
|
12057
12057
|
let __underlineFixInstalled = false;
|
|
12058
12058
|
function installUnderlineFix(fab) {
|
|
12059
12059
|
var _a;
|
|
@@ -12061,26 +12061,91 @@ function installUnderlineFix(fab) {
|
|
|
12061
12061
|
const TextProto = (_a = fab.Text) == null ? void 0 : _a.prototype;
|
|
12062
12062
|
if (!TextProto || typeof TextProto._renderTextDecoration !== "function") return;
|
|
12063
12063
|
const original = TextProto._renderTextDecoration;
|
|
12064
|
+
const measureLineTextWidth = (obj, ctx, lineIndex) => {
|
|
12065
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
12066
|
+
const rawLine = (_a2 = obj._textLines) == null ? void 0 : _a2[lineIndex];
|
|
12067
|
+
const lineText = Array.isArray(rawLine) ? rawLine.join("") : String(rawLine ?? "");
|
|
12068
|
+
if (!lineText) return 0;
|
|
12069
|
+
const fontSize = Number(((_b = obj.getValueOfPropertyAt) == null ? void 0 : _b.call(obj, lineIndex, 0, "fontSize")) ?? obj.fontSize ?? 0);
|
|
12070
|
+
const fontStyle = String(((_c = obj.getValueOfPropertyAt) == null ? void 0 : _c.call(obj, lineIndex, 0, "fontStyle")) ?? obj.fontStyle ?? "normal");
|
|
12071
|
+
const fontWeight = String(((_d = obj.getValueOfPropertyAt) == null ? void 0 : _d.call(obj, lineIndex, 0, "fontWeight")) ?? obj.fontWeight ?? "400");
|
|
12072
|
+
const fontFamily = String(((_e = obj.getValueOfPropertyAt) == null ? void 0 : _e.call(obj, lineIndex, 0, "fontFamily")) ?? obj.fontFamily ?? "sans-serif");
|
|
12073
|
+
const charSpacing = Number(((_f = obj.getValueOfPropertyAt) == null ? void 0 : _f.call(obj, lineIndex, 0, "charSpacing")) ?? obj.charSpacing ?? 0);
|
|
12074
|
+
ctx.save();
|
|
12075
|
+
ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
12076
|
+
const measured = ctx.measureText(lineText).width;
|
|
12077
|
+
ctx.restore();
|
|
12078
|
+
const graphemeCount = Array.from(lineText).length;
|
|
12079
|
+
const spacingWidth = graphemeCount > 1 ? charSpacing / 1e3 * fontSize * (graphemeCount - 1) : 0;
|
|
12080
|
+
return Math.max(0, measured + spacingWidth);
|
|
12081
|
+
};
|
|
12064
12082
|
TextProto._renderTextDecoration = function patchedRenderTextDecoration(ctx, type) {
|
|
12065
12083
|
try {
|
|
12066
12084
|
const hasOwn = !!this[type];
|
|
12067
12085
|
const hasStyled = typeof this.styleHas === "function" && this.styleHas(type);
|
|
12068
|
-
if (!hasOwn && !hasStyled)
|
|
12086
|
+
if (!hasOwn && !hasStyled) return;
|
|
12087
|
+
const lines = this._textLines;
|
|
12088
|
+
const offsets = this.offsets;
|
|
12089
|
+
if (!Array.isArray(lines) || !offsets) {
|
|
12069
12090
|
return original.call(this, ctx, type);
|
|
12070
12091
|
}
|
|
12071
|
-
const
|
|
12072
|
-
|
|
12073
|
-
|
|
12074
|
-
|
|
12075
|
-
|
|
12076
|
-
|
|
12077
|
-
|
|
12078
|
-
|
|
12092
|
+
const offsetY = offsets[type];
|
|
12093
|
+
const offsetAligner = type === "linethrough" ? 0.5 : type === "overline" ? 1 : 0;
|
|
12094
|
+
const leftOffset = this._getLeftOffset();
|
|
12095
|
+
let topOffset = this._getTopOffset();
|
|
12096
|
+
for (let i = 0, len = lines.length; i < len; i++) {
|
|
12097
|
+
const heightOfLine = this.getHeightOfLine(i);
|
|
12098
|
+
const lineHas = !!this[type] || typeof this.styleHas === "function" && this.styleHas(type, i);
|
|
12099
|
+
if (!lineHas) {
|
|
12100
|
+
topOffset += heightOfLine;
|
|
12101
|
+
continue;
|
|
12102
|
+
}
|
|
12103
|
+
const fillStyle = this.getValueOfPropertyAt(i, 0, "fill");
|
|
12104
|
+
const thickness = this.getValueOfPropertyAt(i, 0, "textDecorationThickness");
|
|
12105
|
+
const charSize = this.getHeightOfChar(i, 0);
|
|
12106
|
+
const dy = this.getValueOfPropertyAt(i, 0, "deltaY") || 0;
|
|
12107
|
+
const finalThickness = this.fontSize * (thickness || 0) / 1e3;
|
|
12108
|
+
if (!fillStyle || !finalThickness) {
|
|
12109
|
+
topOffset += heightOfLine;
|
|
12110
|
+
continue;
|
|
12111
|
+
}
|
|
12112
|
+
const lineWidth = measureLineTextWidth(this, ctx, i);
|
|
12113
|
+
if (!lineWidth) {
|
|
12114
|
+
topOffset += heightOfLine;
|
|
12115
|
+
continue;
|
|
12116
|
+
}
|
|
12117
|
+
const availableWidth = Number(this.width ?? lineWidth);
|
|
12118
|
+
let lineLeftOffset = 0;
|
|
12119
|
+
const align = String(this.textAlign ?? "left");
|
|
12120
|
+
if (align === "center") lineLeftOffset = (availableWidth - lineWidth) / 2;
|
|
12121
|
+
else if (align === "right" || align === "end") lineLeftOffset = availableWidth - lineWidth;
|
|
12122
|
+
let drawStart = leftOffset + lineLeftOffset;
|
|
12123
|
+
if (this.direction === "rtl") {
|
|
12124
|
+
drawStart = this.width - drawStart - lineWidth;
|
|
12125
|
+
}
|
|
12126
|
+
const maxHeight = heightOfLine / this.lineHeight;
|
|
12127
|
+
const top = topOffset + maxHeight * (1 - this._fontSizeFraction);
|
|
12128
|
+
ctx.fillStyle = fillStyle;
|
|
12129
|
+
ctx.fillRect(
|
|
12130
|
+
drawStart,
|
|
12131
|
+
top + offsetY * charSize + dy - offsetAligner * finalThickness,
|
|
12132
|
+
lineWidth,
|
|
12133
|
+
finalThickness
|
|
12134
|
+
);
|
|
12135
|
+
topOffset += heightOfLine;
|
|
12136
|
+
}
|
|
12137
|
+
if (typeof this._removeShadow === "function") {
|
|
12138
|
+
try {
|
|
12139
|
+
this._removeShadow(ctx);
|
|
12140
|
+
} catch {
|
|
12079
12141
|
}
|
|
12080
12142
|
}
|
|
12081
12143
|
} catch {
|
|
12144
|
+
try {
|
|
12145
|
+
return original.call(this, ctx, type);
|
|
12146
|
+
} catch {
|
|
12147
|
+
}
|
|
12082
12148
|
}
|
|
12083
|
-
return original.call(this, ctx, type);
|
|
12084
12149
|
};
|
|
12085
12150
|
__underlineFixInstalled = true;
|
|
12086
12151
|
console.log(`[canvas-renderer] underline-fix monkey patch installed (v${PACKAGE_VERSION})`);
|