embroidery-qc-image 1.0.28 → 1.0.29
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/components/EmbroideryQCImage.d.ts.map +1 -1
- package/dist/index.esm.js +12 -19
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +12 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -571,21 +571,21 @@ const renderEmbroideryCanvas = (canvas, config, canvasSize, imageRefs) => {
|
|
|
571
571
|
// Tìm scaleFactor tối ưu bằng binary search trong [0, 1]
|
|
572
572
|
const maxIterations = 12;
|
|
573
573
|
const epsilon = 0.001; // độ chính xác cho khoảng cách low-high
|
|
574
|
-
const contentHeight = canvas.height
|
|
574
|
+
const contentHeight = canvas.height;
|
|
575
575
|
let low = 0;
|
|
576
576
|
let high = 1;
|
|
577
577
|
for (let i = 0; i < maxIterations; i++) {
|
|
578
578
|
const testScale = (low + high) / 2;
|
|
579
579
|
// (Không cần clear measureCanvas vì chỉ dùng để đo chiều cao, nhưng làm sạch cho dễ debug)
|
|
580
580
|
measureCtx.clearRect(0, 0, measureCanvas.width, measureCanvas.height);
|
|
581
|
-
// Đo warning & message đúng theo renderWarning,
|
|
582
|
-
let testMeasureY =
|
|
581
|
+
// Đo warning & message đúng theo renderWarning, có bao gồm padding
|
|
582
|
+
let testMeasureY = LAYOUT.PADDING;
|
|
583
583
|
if (config.warning_message) {
|
|
584
|
-
const testWarningHeight = renderWarning(measureCtx, measureCanvas, config.warning_message, testScale);
|
|
584
|
+
const testWarningHeight = renderWarning(measureCtx, measureCanvas, config.warning_message, testScale, testMeasureY);
|
|
585
585
|
testMeasureY += testWarningHeight;
|
|
586
586
|
}
|
|
587
587
|
if (config.message) {
|
|
588
|
-
const testMessageHeight = renderWarning(measureCtx, measureCanvas, config.message, testScale,
|
|
588
|
+
const testMessageHeight = renderWarning(measureCtx, measureCanvas, config.message, testScale, testMeasureY, "", DEFAULT_ERROR_COLOR);
|
|
589
589
|
testMeasureY += testMessageHeight;
|
|
590
590
|
}
|
|
591
591
|
// Đo lại chiều cao của các sides với scaleFactor, tiếp nối sau warning/message
|
|
@@ -593,7 +593,7 @@ const renderEmbroideryCanvas = (canvas, config, canvasSize, imageRefs) => {
|
|
|
593
593
|
const sideHeight = renderSide(measureCtx, side, testMeasureY, canvas.width, canvas.height, testScale, imageRefs, mockupBounds);
|
|
594
594
|
testMeasureY += sideHeight + measureSpacing * testScale;
|
|
595
595
|
});
|
|
596
|
-
// Tổng chiều cao content
|
|
596
|
+
// Tổng chiều cao content
|
|
597
597
|
const totalHeight = testMeasureY;
|
|
598
598
|
if (totalHeight > contentHeight) {
|
|
599
599
|
// Content đang cao hơn vùng cho phép -> giảm scale
|
|
@@ -609,23 +609,17 @@ const renderEmbroideryCanvas = (canvas, config, canvasSize, imageRefs) => {
|
|
|
609
609
|
}
|
|
610
610
|
const scaleFactor = low;
|
|
611
611
|
drawMockup(ctx, canvas, imageRefs);
|
|
612
|
+
// Calculate currentY: padding top + actual warning & message height (no spacing)
|
|
613
|
+
let currentY = LAYOUT.PADDING;
|
|
612
614
|
// Render warning & message with scaleFactor and get actual heights
|
|
613
|
-
let actualWarningHeight = 0;
|
|
614
|
-
let actualMessageHeight = 0;
|
|
615
615
|
if (config.warning_message) {
|
|
616
|
-
actualWarningHeight = renderWarning(ctx, canvas, config.warning_message, scaleFactor);
|
|
616
|
+
const actualWarningHeight = renderWarning(ctx, canvas, config.warning_message, scaleFactor, currentY);
|
|
617
|
+
currentY += actualWarningHeight;
|
|
617
618
|
}
|
|
618
619
|
if (config.message) {
|
|
619
|
-
actualMessageHeight = renderWarning(ctx, canvas, config.message, scaleFactor,
|
|
620
|
+
const actualMessageHeight = renderWarning(ctx, canvas, config.message, scaleFactor, currentY, "", // message: không cần prefix "Note"
|
|
620
621
|
DEFAULT_ERROR_COLOR // message: hiển thị màu đỏ
|
|
621
622
|
);
|
|
622
|
-
}
|
|
623
|
-
// Calculate currentY: padding top + actual warning & message height (no spacing)
|
|
624
|
-
let currentY = LAYOUT.PADDING;
|
|
625
|
-
if (config.warning_message && actualWarningHeight > 0) {
|
|
626
|
-
currentY += actualWarningHeight;
|
|
627
|
-
}
|
|
628
|
-
if (config.message && actualMessageHeight > 0) {
|
|
629
623
|
currentY += actualMessageHeight;
|
|
630
624
|
}
|
|
631
625
|
config.sides.forEach((side) => {
|
|
@@ -698,9 +692,8 @@ const renderWarning = (ctx, canvas, message, scaleFactor = 1, offsetY = 0, prefi
|
|
|
698
692
|
lines = buildWrappedLines(ctx, sanitizedMessage, maxWidth);
|
|
699
693
|
longestLineWidth = Math.max(...lines.map((line) => ctx.measureText(line).width));
|
|
700
694
|
}
|
|
701
|
-
const startY = LAYOUT.PADDING * scaleFactor + offsetY;
|
|
702
695
|
lines.forEach((line, index) => {
|
|
703
|
-
const y =
|
|
696
|
+
const y = offsetY + index * lineHeight;
|
|
704
697
|
ctx.fillText(line, leftX, y);
|
|
705
698
|
});
|
|
706
699
|
ctx.restore();
|