embroidery-qc-image 1.0.34 → 1.0.36
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 +61 -39
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +61 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmbroideryQCImage.d.ts","sourceRoot":"","sources":["../../src/components/EmbroideryQCImage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAY,MAAM,UAAU,CAAC;AAChF,OAAO,yBAAyB,CAAC;AAgLjC,MAAM,WAAW,8BAA8B;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,WAAW,GAAG,YAAY,GAAG,YAAY,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAiiBD,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CA2HvD,CAAC;
|
|
1
|
+
{"version":3,"file":"EmbroideryQCImage.d.ts","sourceRoot":"","sources":["../../src/components/EmbroideryQCImage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAY,MAAM,UAAU,CAAC;AAChF,OAAO,yBAAyB,CAAC;AAgLjC,MAAM,WAAW,8BAA8B;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,WAAW,GAAG,YAAY,GAAG,YAAY,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAiiBD,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CA2HvD,CAAC;AAspFF,eAAO,MAAM,6BAA6B,GACxC,QAAQ,kBAAkB,EAC1B,UAAS,8BAAmC,KAC3C,OAAO,CAAC,IAAI,GAAG,IAAI,CAuBrB,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,QAAQ,kBAAkB,EAC1B,UAAS,8BAAmC,KAC3C,OAAO,CAAC,MAAM,GAAG,IAAI,CAuBvB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
package/dist/index.esm.js
CHANGED
|
@@ -679,7 +679,7 @@ const renderStrokePatchesCanvas = (ctx, canvas, config, imageRefs) => {
|
|
|
679
679
|
// Calculate text size to fit top section
|
|
680
680
|
let previewFontSize = LAYOUT.HEADER_FONT_SIZE * 3; // Start with large size
|
|
681
681
|
const fontToUse = isFontMissing ? LAYOUT.FONT_FAMILY : position.font;
|
|
682
|
-
ctx.font = `${previewFontSize}px ${fontToUse}`;
|
|
682
|
+
ctx.font = `${previewFontSize}px "${fontToUse}"`;
|
|
683
683
|
const text = position.text || "";
|
|
684
684
|
const maxTextWidth = usableWidth * 0.9; // Use 75% of width for better padding
|
|
685
685
|
const maxTextHeight = actualTopSectionHeight; // Use 60% of height
|
|
@@ -687,13 +687,13 @@ const renderStrokePatchesCanvas = (ctx, canvas, config, imageRefs) => {
|
|
|
687
687
|
let textWidth = ctx.measureText(text).width;
|
|
688
688
|
while (textWidth > maxTextWidth && previewFontSize > 50) {
|
|
689
689
|
previewFontSize *= 0.95;
|
|
690
|
-
ctx.font = `${previewFontSize}px ${fontToUse}`;
|
|
690
|
+
ctx.font = `${previewFontSize}px "${fontToUse}"`;
|
|
691
691
|
textWidth = ctx.measureText(text).width;
|
|
692
692
|
}
|
|
693
693
|
// Ensure text height also fits
|
|
694
694
|
while (previewFontSize > maxTextHeight && previewFontSize > 50) {
|
|
695
695
|
previewFontSize *= 0.95;
|
|
696
|
-
ctx.font = `${previewFontSize}px ${fontToUse}`;
|
|
696
|
+
ctx.font = `${previewFontSize}px "${fontToUse}"`;
|
|
697
697
|
}
|
|
698
698
|
// Update textWidth after final scaling
|
|
699
699
|
textWidth = ctx.measureText(text).width;
|
|
@@ -773,7 +773,7 @@ const renderStrokePatchesCanvas = (ctx, canvas, config, imageRefs) => {
|
|
|
773
773
|
// Render font name với chính font đó
|
|
774
774
|
const prefixWidth = ctx.measureText(fontPrefix).width;
|
|
775
775
|
const fontName = position.font || LAYOUT.FONT_FAMILY;
|
|
776
|
-
ctx.font = `${infoFontSize}px ${fontName}`;
|
|
776
|
+
ctx.font = `${infoFontSize}px "${fontName}"`;
|
|
777
777
|
ctx.fillText(fontName, startX + prefixWidth, infoY);
|
|
778
778
|
}
|
|
779
779
|
infoY += infoLineHeight;
|
|
@@ -1063,7 +1063,7 @@ const renderTemplateCustomTextPatchesCanvas = (ctx, canvas, config, imageRefs) =
|
|
|
1063
1063
|
let high = previewFontSize;
|
|
1064
1064
|
while (high - low > 1) {
|
|
1065
1065
|
const mid = (low + high) / 2;
|
|
1066
|
-
ctx.font = `${mid}px ${fontToUse}`;
|
|
1066
|
+
ctx.font = `${mid}px "${fontToUse}"`;
|
|
1067
1067
|
// Kiểm tra width của tất cả các dòng
|
|
1068
1068
|
const maxLineWidth = Math.max(...textLines.map(line => ctx.measureText(line).width));
|
|
1069
1069
|
// Kiểm tra height với line height = 1.1 (giảm từ 1.2 để text to hơn)
|
|
@@ -1080,7 +1080,7 @@ const renderTemplateCustomTextPatchesCanvas = (ctx, canvas, config, imageRefs) =
|
|
|
1080
1080
|
}
|
|
1081
1081
|
}
|
|
1082
1082
|
previewFontSize = bestFontSize;
|
|
1083
|
-
ctx.font = `${previewFontSize}px ${fontToUse}`;
|
|
1083
|
+
ctx.font = `${previewFontSize}px "${fontToUse}"`;
|
|
1084
1084
|
// Center the text inside rectangle
|
|
1085
1085
|
const finalLineHeight = previewFontSize * 1.1;
|
|
1086
1086
|
const totalTextHeightFinal = textLines.length * finalLineHeight;
|
|
@@ -1138,7 +1138,7 @@ const renderTemplateCustomTextPatchesCanvas = (ctx, canvas, config, imageRefs) =
|
|
|
1138
1138
|
// Render font name với chính font đó
|
|
1139
1139
|
const prefixWidth = ctx.measureText(fontPrefix).width;
|
|
1140
1140
|
const fontName = position.font || LAYOUT.FONT_FAMILY;
|
|
1141
|
-
ctx.font = `${infoFontSize}px ${fontName}`;
|
|
1141
|
+
ctx.font = `${infoFontSize}px "${fontName}"`;
|
|
1142
1142
|
ctx.fillText(fontName, startX + prefixWidth, infoY);
|
|
1143
1143
|
}
|
|
1144
1144
|
infoY += infoLineHeight;
|
|
@@ -1582,13 +1582,13 @@ const renderSide = (ctx, side, startY, width, height, scaleFactor, imageRefs, mo
|
|
|
1582
1582
|
return currentY - startY;
|
|
1583
1583
|
}
|
|
1584
1584
|
// Compute uniform properties
|
|
1585
|
-
|
|
1586
|
-
|
|
1585
|
+
// Lấy màu từ tất cả ICON positions (sử dụng getIconColors để ưu tiên layer_colors)
|
|
1586
|
+
const iconColorPositions = side.positions.filter((p) => p.type === "ICON");
|
|
1587
1587
|
const iconColorValues = iconColorPositions
|
|
1588
1588
|
.map((p) => {
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
return
|
|
1589
|
+
const iconColors = getIconColors(p);
|
|
1590
|
+
// Join các màu bằng dấu phẩy giống TEXT để so sánh uniform
|
|
1591
|
+
return iconColors?.length ? iconColors.join(",") : null;
|
|
1592
1592
|
})
|
|
1593
1593
|
.filter((color) => Boolean(color));
|
|
1594
1594
|
const uniformProps = computeUniformProperties(textPositions, {
|
|
@@ -1643,38 +1643,62 @@ const renderSide = (ctx, side, startY, width, height, scaleFactor, imageRefs, mo
|
|
|
1643
1643
|
currentY += LAYOUT.LINE_GAP * scaleFactor;
|
|
1644
1644
|
side.positions.forEach((position) => {
|
|
1645
1645
|
if (position.type === "ICON") {
|
|
1646
|
-
const
|
|
1647
|
-
const
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
: position.color ?? null;
|
|
1646
|
+
const iconColors = getIconColors(position);
|
|
1647
|
+
const iconColorValue = iconColors?.length ? iconColors.join(",") : null;
|
|
1648
|
+
// Icon có thể hide color nếu uniform với TEXT, bất kể số lượng màu
|
|
1649
|
+
// (vì TEXT với layer_colors nhiều màu cũng có thể uniform)
|
|
1651
1650
|
const hideColor = shouldShowUniformLabels &&
|
|
1652
1651
|
uniformProps.isUniform.color &&
|
|
1653
1652
|
iconColorValue !== null &&
|
|
1654
|
-
uniformProps.values.color === iconColorValue
|
|
1655
|
-
iconUsesSingleColor;
|
|
1653
|
+
uniformProps.values.color === iconColorValue;
|
|
1656
1654
|
currentY += renderIconPosition(ctx, position, padding, currentY, sideWidth, scaleFactor, imageRefs, { hideColor }, mockupBounds);
|
|
1657
1655
|
currentY += (LAYOUT.LINE_GAP / 3) * scaleFactor;
|
|
1658
1656
|
}
|
|
1659
1657
|
});
|
|
1660
1658
|
return currentY - startY;
|
|
1661
1659
|
};
|
|
1660
|
+
// Helper function để lấy màu từ TEXT position (ưu tiên layer_colors, fallback về character_colors hoặc color)
|
|
1661
|
+
const getTextColors = (position) => {
|
|
1662
|
+
if (position.layer_colors?.length) {
|
|
1663
|
+
return position.layer_colors;
|
|
1664
|
+
}
|
|
1665
|
+
if (position.character_colors?.length) {
|
|
1666
|
+
return position.character_colors;
|
|
1667
|
+
}
|
|
1668
|
+
if (position.color) {
|
|
1669
|
+
return [position.color];
|
|
1670
|
+
}
|
|
1671
|
+
return null;
|
|
1672
|
+
};
|
|
1673
|
+
// Helper function để lấy màu từ ICON position (ưu tiên layer_colors, fallback về color)
|
|
1674
|
+
const getIconColors = (position) => {
|
|
1675
|
+
if (position.layer_colors?.length) {
|
|
1676
|
+
return position.layer_colors;
|
|
1677
|
+
}
|
|
1678
|
+
if (position.color) {
|
|
1679
|
+
return [position.color];
|
|
1680
|
+
}
|
|
1681
|
+
return null;
|
|
1682
|
+
};
|
|
1662
1683
|
const groupTextPositions = (textPositions) => {
|
|
1663
1684
|
const groups = [];
|
|
1664
1685
|
let currentGroup = null;
|
|
1665
1686
|
let currentProps = null;
|
|
1666
1687
|
textPositions.forEach((position) => {
|
|
1688
|
+
const textColors = getTextColors(position);
|
|
1667
1689
|
const posProps = {
|
|
1668
1690
|
font: position.font,
|
|
1669
1691
|
text_shape: position.text_shape,
|
|
1670
1692
|
color: position.color,
|
|
1671
1693
|
character_colors: position.character_colors?.join(","),
|
|
1694
|
+
layer_colors: textColors?.join(","),
|
|
1672
1695
|
};
|
|
1673
1696
|
if (!currentGroup ||
|
|
1674
1697
|
currentProps.font !== posProps.font ||
|
|
1675
1698
|
currentProps.text_shape !== posProps.text_shape ||
|
|
1676
1699
|
currentProps.color !== posProps.color ||
|
|
1677
|
-
currentProps.character_colors !== posProps.character_colors
|
|
1700
|
+
currentProps.character_colors !== posProps.character_colors ||
|
|
1701
|
+
currentProps.layer_colors !== posProps.layer_colors) {
|
|
1678
1702
|
if (currentGroup) {
|
|
1679
1703
|
groups.push(currentGroup);
|
|
1680
1704
|
}
|
|
@@ -1699,9 +1723,12 @@ const computeUniformProperties = (textPositions, options) => {
|
|
|
1699
1723
|
const shapes = new Set(textPositions.map((p) => p.text_shape));
|
|
1700
1724
|
const florals = new Set(textPositions.map((p) => p.floral_pattern ?? "None"));
|
|
1701
1725
|
const colorSources = [
|
|
1702
|
-
...textPositions.map((p) =>
|
|
1703
|
-
|
|
1704
|
-
|
|
1726
|
+
...textPositions.map((p) => {
|
|
1727
|
+
const textColors = getTextColors(p);
|
|
1728
|
+
return textColors?.length
|
|
1729
|
+
? textColors.join(",")
|
|
1730
|
+
: p.color ?? "None";
|
|
1731
|
+
}),
|
|
1705
1732
|
...(options?.additionalColorValues?.map((color) => color ?? "None") ?? []),
|
|
1706
1733
|
];
|
|
1707
1734
|
if (textPositions.length === 0 &&
|
|
@@ -1748,7 +1775,7 @@ const renderUniformLabels = (ctx, uniformProps, x, y, maxWidth, scaleFactor, ima
|
|
|
1748
1775
|
let currentX = x + prefixWidth;
|
|
1749
1776
|
ctx.fillText(prefix, x, cursorY);
|
|
1750
1777
|
// Render tên font với font từ config
|
|
1751
|
-
ctx.font = `${fontSize}px ${values.font}`;
|
|
1778
|
+
ctx.font = `${fontSize}px "${values.font}"`;
|
|
1752
1779
|
const fontNameWidth = ctx.measureText(values.font).width;
|
|
1753
1780
|
ctx.fillText(values.font, currentX, cursorY);
|
|
1754
1781
|
currentX += fontNameWidth;
|
|
@@ -1973,7 +2000,7 @@ displayIndex, showLabels, scaleFactor, imageRefs, mockupBounds = null) => {
|
|
|
1973
2000
|
const measureFontTextWidth = (fontSize) => {
|
|
1974
2001
|
ctx.font = `${fontSize}px ${LAYOUT.FONT_FAMILY}`;
|
|
1975
2002
|
const prefixWidth = ctx.measureText(prefix).width;
|
|
1976
|
-
ctx.font = `${fontSize}px ${position.font}`;
|
|
2003
|
+
ctx.font = `${fontSize}px "${position.font}"`;
|
|
1977
2004
|
const fontNameWidth = ctx.measureText(fontName).width;
|
|
1978
2005
|
ctx.font = `${fontSize}px ${LAYOUT.FONT_FAMILY}`;
|
|
1979
2006
|
const suffixWidth = ctx.measureText(suffix).width;
|
|
@@ -2049,7 +2076,7 @@ displayIndex, showLabels, scaleFactor, imageRefs, mockupBounds = null) => {
|
|
|
2049
2076
|
const prefixWidth = ctx.measureText(prefix).width;
|
|
2050
2077
|
let currentX = x + prefixWidth;
|
|
2051
2078
|
ctx.fillText(prefix, x, currentY);
|
|
2052
|
-
ctx.font = `${effectiveFontSize}px ${position.font}`;
|
|
2079
|
+
ctx.font = `${effectiveFontSize}px "${position.font}"`;
|
|
2053
2080
|
const fontNameWidth = ctx.measureText(fontName).width;
|
|
2054
2081
|
const totalWidth = prefixWidth + fontNameWidth;
|
|
2055
2082
|
if (totalWidth > shrunkEffectiveMaxWidth) {
|
|
@@ -2083,9 +2110,11 @@ displayIndex, showLabels, scaleFactor, imageRefs, mockupBounds = null) => {
|
|
|
2083
2110
|
}
|
|
2084
2111
|
}
|
|
2085
2112
|
if (showLabels.color) {
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2113
|
+
// Ưu tiên layer_colors, fallback về character_colors hoặc color (giống ICON)
|
|
2114
|
+
const textColors = getTextColors(position);
|
|
2115
|
+
if (textColors && textColors.length > 0) {
|
|
2116
|
+
const colorValue = textColors.join(", ");
|
|
2117
|
+
const colors = textColors;
|
|
2089
2118
|
const swatchH = Math.floor(otherFontSize * LAYOUT.SWATCH_HEIGHT_RATIO);
|
|
2090
2119
|
const totalSwatchWidth = calculateSwatchesWidth(colors, swatchH, scaleFactor, imageRefs);
|
|
2091
2120
|
// Tính effectiveMaxWidth cho dòng này để tránh mockup
|
|
@@ -2361,16 +2390,9 @@ const renderIconPosition = (ctx, position, x, y, maxWidth, scaleFactor, imageRef
|
|
|
2361
2390
|
cursorY += iconResult.height;
|
|
2362
2391
|
// Draw color swatches (prefer layer_colors, fallback to single color)
|
|
2363
2392
|
// Nếu icon đã bị xóa thì không cần hiển thị màu chỉ nữa
|
|
2364
|
-
const iconColors = position.is_delete_icon
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
? position.layer_colors
|
|
2368
|
-
: position.color
|
|
2369
|
-
? [position.color]
|
|
2370
|
-
: null;
|
|
2371
|
-
const layerCount = position.layer_colors?.length ?? 0;
|
|
2372
|
-
const hasMultiLayerColors = layerCount > 1;
|
|
2373
|
-
const shouldSkipColorSection = options?.hideColor && !hasMultiLayerColors;
|
|
2393
|
+
const iconColors = position.is_delete_icon ? null : getIconColors(position);
|
|
2394
|
+
// Nếu hideColor = true, ẩn màu của ICON (giống TEXT) bất kể số lượng màu
|
|
2395
|
+
const shouldSkipColorSection = options?.hideColor === true;
|
|
2374
2396
|
if (iconColors?.length && !shouldSkipColorSection) {
|
|
2375
2397
|
// Dòng "Màu chỉ:" của icon dùng OTHER_FONT_SIZE, không dùng iconFontSize
|
|
2376
2398
|
const otherFontSize = LAYOUT.OTHER_FONT_SIZE * scaleFactor;
|