sales-frontend-utils 0.0.54 → 0.0.55
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 +9 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/dist/utils/canvas-utils.cjs +9 -3
- package/dist/utils/canvas-utils.cjs.map +1 -1
- package/dist/utils/canvas-utils.d.cts +2 -1
- package/dist/utils/canvas-utils.d.ts +2 -1
- package/dist/utils/canvas-utils.js +9 -4
- package/dist/utils/canvas-utils.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -617,6 +617,11 @@ __publicField(_MessageEventManager, "instance");
|
|
|
617
617
|
var MessageEventManager = _MessageEventManager;
|
|
618
618
|
|
|
619
619
|
// src/utils/canvas-utils.ts
|
|
620
|
+
var getTextWidth = (text, font, context) => {
|
|
621
|
+
context.font = font;
|
|
622
|
+
const metrics = context.measureText(text);
|
|
623
|
+
return metrics.width;
|
|
624
|
+
};
|
|
620
625
|
var convertTextToImg = ({
|
|
621
626
|
targetStr,
|
|
622
627
|
canvasWidth,
|
|
@@ -632,8 +637,9 @@ var convertTextToImg = ({
|
|
|
632
637
|
if (!ctx) {
|
|
633
638
|
throw new Error("Canvas context\uB97C \uAC00\uC838\uC62C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
634
639
|
}
|
|
640
|
+
const font = `${fontWeight ?? "normal"} ${fontSize ?? 75}px ${fontFamily}`;
|
|
635
641
|
const defaultHeight = 150;
|
|
636
|
-
const calculatedWidth = targetStr
|
|
642
|
+
const calculatedWidth = getTextWidth(targetStr, font, ctx);
|
|
637
643
|
canvas.width = canvasWidth ?? calculatedWidth;
|
|
638
644
|
canvas.height = canvasHeight ?? defaultHeight;
|
|
639
645
|
if (backgroundColor) {
|
|
@@ -642,8 +648,7 @@ var convertTextToImg = ({
|
|
|
642
648
|
}
|
|
643
649
|
ctx.fillStyle = fontColor ?? "black";
|
|
644
650
|
ctx.textAlign = "center";
|
|
645
|
-
ctx.font =
|
|
646
|
-
console.log("font", `${fontWeight ?? "normal"} ${fontSize ?? 75}px ${fontFamily}`);
|
|
651
|
+
ctx.font = font;
|
|
647
652
|
ctx.textBaseline = "middle";
|
|
648
653
|
ctx.fillText(targetStr, canvas.width / 2, canvas.height / 2);
|
|
649
654
|
return canvas.toDataURL();
|
|
@@ -1215,6 +1220,7 @@ exports.getOrCreateDeviceId = getOrCreateDeviceId;
|
|
|
1215
1220
|
exports.getPeriodDate = getPeriodDate;
|
|
1216
1221
|
exports.getServicePath = getServicePath;
|
|
1217
1222
|
exports.getSubdomain = getSubdomain;
|
|
1223
|
+
exports.getTextWidth = getTextWidth;
|
|
1218
1224
|
exports.hasAstx2 = hasAstx2;
|
|
1219
1225
|
exports.imageUrlToFile = imageUrlToFile;
|
|
1220
1226
|
exports.imageUrlToFileFetch = imageUrlToFileFetch;
|