embroidery-qc-image 1.0.31 → 1.0.32

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.
@@ -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;AAiKjC,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;AAwhBD,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAmHvD,CAAC;AAqkEF,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"}
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;AAiKjC,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;AAwhBD,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAmHvD,CAAC;AA+oEF,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
@@ -624,36 +624,17 @@ const renderStrokePatchesCanvas = (ctx, canvas, config, imageRefs) => {
624
624
  renderErrorState(ctx, canvas, "Position phải là TEXT");
625
625
  return;
626
626
  }
627
- // Validate required fields
628
- if (!position.font) {
629
- renderErrorState(ctx, canvas, "Thiếu font");
630
- return;
631
- }
632
- // Validate layer_colors
633
- if (!position.layer_colors) {
634
- renderErrorState(ctx, canvas, "Thiếu layer_colors");
635
- return;
636
- }
637
- if (position.layer_colors.length !== 3) {
638
- renderErrorState(ctx, canvas, `layer_colors phải có đúng 3 phần tử, hiện tại có ${position.layer_colors.length}`);
639
- return;
640
- }
641
- // Validate từng màu
642
- const [textColor, borderColor, backgroundColor] = position.layer_colors;
643
- const missingColors = [];
644
- if (!textColor || textColor.trim() === "") {
645
- missingColors.push("Màu text (vị trí 1)");
646
- }
647
- if (!borderColor || borderColor.trim() === "") {
648
- missingColors.push("Màu border (vị trí 2)");
649
- }
650
- if (!backgroundColor || backgroundColor.trim() === "") {
651
- missingColors.push("Màu background (vị trí 3)");
652
- }
653
- if (missingColors.length > 0) {
654
- renderErrorState(ctx, canvas, `Thiếu màu trong layer_colors:\n${missingColors.join("\n")}`);
655
- return;
656
- }
627
+ // Get layer colors with empty check (don't use fallback)
628
+ const textColor = position.layer_colors?.[0];
629
+ const borderColor = position.layer_colors?.[1];
630
+ const backgroundColor = position.layer_colors?.[2];
631
+ const fabricColor = position.layer_colors?.[3]; // Màu vải
632
+ // For rendering, use fallback colors (fabricColor không cần fallback vì chỉ hiển thị)
633
+ const textColorForRender = textColor;
634
+ const borderColorForRender = borderColor;
635
+ const backgroundColorForRender = backgroundColor;
636
+ // Check if font is missing (but continue rendering)
637
+ const isFontMissing = !position.font || position.font.trim() === "";
657
638
  // ============================================================================
658
639
  // TOP SECTION (2/3): Hiển thị mẫu preview
659
640
  // ============================================================================
@@ -669,7 +650,8 @@ const renderStrokePatchesCanvas = (ctx, canvas, config, imageRefs) => {
669
650
  const actualTopSectionHeight = topSectionHeight - titleFontSize - LAYOUT.LINE_GAP - extraSpacing;
670
651
  // Calculate text size to fit top section
671
652
  let previewFontSize = LAYOUT.HEADER_FONT_SIZE * 3; // Start with large size
672
- ctx.font = `${previewFontSize}px ${position.font}`;
653
+ const fontToUse = isFontMissing ? LAYOUT.FONT_FAMILY : position.font;
654
+ ctx.font = `${previewFontSize}px ${fontToUse}`;
673
655
  const text = position.text || "";
674
656
  const maxTextWidth = usableWidth * 0.9; // Use 75% of width for better padding
675
657
  const maxTextHeight = actualTopSectionHeight; // Use 60% of height
@@ -677,23 +659,23 @@ const renderStrokePatchesCanvas = (ctx, canvas, config, imageRefs) => {
677
659
  let textWidth = ctx.measureText(text).width;
678
660
  while (textWidth > maxTextWidth && previewFontSize > 50) {
679
661
  previewFontSize *= 0.95;
680
- ctx.font = `${previewFontSize}px ${position.font}`;
662
+ ctx.font = `${previewFontSize}px ${fontToUse}`;
681
663
  textWidth = ctx.measureText(text).width;
682
664
  }
683
665
  // Ensure text height also fits
684
666
  while (previewFontSize > maxTextHeight && previewFontSize > 50) {
685
667
  previewFontSize *= 0.95;
686
- ctx.font = `${previewFontSize}px ${position.font}`;
668
+ ctx.font = `${previewFontSize}px ${fontToUse}`;
687
669
  }
688
670
  // Update textWidth after final scaling
689
671
  textWidth = ctx.measureText(text).width;
690
672
  // Center the text in top section
691
673
  const textX = padding + usableWidth / 2 - textWidth / 2;
692
674
  const textY = actualTopSectionY + actualTopSectionHeight / 2 - previewFontSize / 2;
693
- // Get color hex values
694
- const textColorHex = COLOR_MAP[textColor] || LAYOUT.LABEL_COLOR;
695
- const borderColorHex = COLOR_MAP[borderColor] || LAYOUT.LABEL_COLOR;
696
- const bgColorHex = COLOR_MAP[backgroundColor] || "#FFFFFF";
675
+ // Get color hex values (use render colors with fallback)
676
+ const textColorHex = COLOR_MAP[textColorForRender] || LAYOUT.LABEL_COLOR;
677
+ const borderColorHex = COLOR_MAP[borderColorForRender] || LAYOUT.LABEL_COLOR;
678
+ const bgColorHex = COLOR_MAP[backgroundColorForRender] || "#FFFFFF";
697
679
  // Calculate stroke widths
698
680
  // Background needs to be MUCH thicker to create spacing from text
699
681
  // Border needs to be even thicker to wrap around background
@@ -753,62 +735,142 @@ const renderStrokePatchesCanvas = (ctx, canvas, config, imageRefs) => {
753
735
  const fontPrefix = "Font: ";
754
736
  ctx.font = `${infoFontSize}px ${LAYOUT.FONT_FAMILY}`;
755
737
  ctx.fillText(fontPrefix, startX, infoY);
756
- // Render font name với chính font đó
757
- const prefixWidth = ctx.measureText(fontPrefix).width;
758
- ctx.font = `${infoFontSize}px ${position.font}`;
759
- ctx.fillText(position.font, startX + prefixWidth, infoY);
738
+ if (isFontMissing) {
739
+ // Hiển thị warning màu đỏ nếu thiếu font
740
+ ctx.fillStyle = "#CC0000"; // Red color
741
+ ctx.fillText("(Đang thiếu font chữ)", startX + ctx.measureText(fontPrefix).width, infoY);
742
+ ctx.fillStyle = LAYOUT.LABEL_COLOR; // Reset color
743
+ }
744
+ else {
745
+ // Render font name với chính font đó
746
+ const prefixWidth = ctx.measureText(fontPrefix).width;
747
+ const fontName = position.font || LAYOUT.FONT_FAMILY;
748
+ ctx.font = `${infoFontSize}px ${fontName}`;
749
+ ctx.fillText(fontName, startX + prefixWidth, infoY);
750
+ }
760
751
  infoY += infoLineHeight;
761
752
  // Reset font về mặc định cho các dòng tiếp theo
762
753
  ctx.font = `${infoFontSize}px ${LAYOUT.FONT_FAMILY}`;
763
- // Màu chữ (Text Color)
754
+ // Màu chữ (Text Color) - layer_colors[0]
764
755
  drawAsterisk(padding, infoY);
765
- const textColorLabel = `Màu chữ: ${textColor}`;
766
- ctx.fillText(textColorLabel, startX, infoY);
767
- // Draw text color swatch
768
- const swatchSize = infoFontSize * 1.3; // Giảm từ 1.5 xuống 1.3
769
- const swatchX = startX +
770
- ctx.measureText(textColorLabel).width +
771
- LAYOUT.ELEMENT_SPACING * 0.3; // Giảm spacing
772
- const swatchY = infoY + infoFontSize / 2 - swatchSize / 2;
773
- const textColorSwatchUrl = getImageUrl("threadColor", textColor);
774
- const textColorSwatchImg = imageRefs.current.get(textColorSwatchUrl);
775
- if (textColorSwatchImg?.complete && textColorSwatchImg.naturalHeight > 0) {
776
- const ratio = textColorSwatchImg.naturalWidth / textColorSwatchImg.naturalHeight;
777
- const swatchW = Math.max(1, Math.floor(swatchSize * ratio));
778
- ctx.drawImage(textColorSwatchImg, swatchX, swatchY, swatchW, swatchSize);
756
+ const textColorPrefix = "Màu chữ: ";
757
+ ctx.fillText(textColorPrefix, startX, infoY);
758
+ if (!textColor || textColor.trim() === "") {
759
+ // Hiển thị warning màu đỏ nếu thiếu màu
760
+ const prefixWidth = ctx.measureText(textColorPrefix).width;
761
+ ctx.fillStyle = "#CC0000";
762
+ ctx.fillText("(Chưa màu)", startX + prefixWidth, infoY);
763
+ ctx.fillStyle = LAYOUT.LABEL_COLOR; // Reset color
764
+ }
765
+ else {
766
+ // Hiển thị tên màu
767
+ const prefixWidth = ctx.measureText(textColorPrefix).width;
768
+ ctx.fillText(textColor, startX + prefixWidth, infoY);
769
+ // Draw text color swatch
770
+ const swatchSize = infoFontSize * 1.3;
771
+ const swatchX = startX +
772
+ ctx.measureText(textColorPrefix + textColor).width +
773
+ LAYOUT.ELEMENT_SPACING * 0.3;
774
+ const swatchY = infoY + infoFontSize / 2 - swatchSize / 2;
775
+ const textColorSwatchUrl = getImageUrl("threadColor", textColor);
776
+ const textColorSwatchImg = imageRefs.current.get(textColorSwatchUrl);
777
+ if (textColorSwatchImg?.complete && textColorSwatchImg.naturalHeight > 0) {
778
+ const ratio = textColorSwatchImg.naturalWidth / textColorSwatchImg.naturalHeight;
779
+ const swatchW = Math.max(1, Math.floor(swatchSize * ratio));
780
+ ctx.drawImage(textColorSwatchImg, swatchX, swatchY, swatchW, swatchSize);
781
+ }
782
+ }
783
+ infoY += infoLineHeight;
784
+ // Màu nền (Background Color) - layer_colors[2]
785
+ drawAsterisk(padding, infoY);
786
+ const bgColorPrefix = "Màu nền: ";
787
+ ctx.fillText(bgColorPrefix, startX, infoY);
788
+ if (!backgroundColor || backgroundColor.trim() === "") {
789
+ // Hiển thị warning màu đỏ nếu thiếu màu
790
+ const prefixWidth = ctx.measureText(bgColorPrefix).width;
791
+ ctx.fillStyle = "#CC0000";
792
+ ctx.fillText("(Chưa có màu)", startX + prefixWidth, infoY);
793
+ ctx.fillStyle = LAYOUT.LABEL_COLOR; // Reset color
794
+ }
795
+ else {
796
+ // Hiển thị tên màu
797
+ const prefixWidth = ctx.measureText(bgColorPrefix).width;
798
+ ctx.fillText(backgroundColor, startX + prefixWidth, infoY);
799
+ // Draw background color swatch
800
+ const swatchSize = infoFontSize * 1.3;
801
+ const bgSwatchX = startX +
802
+ ctx.measureText(bgColorPrefix + backgroundColor).width +
803
+ LAYOUT.ELEMENT_SPACING * 0.3;
804
+ const bgSwatchY = infoY + infoFontSize / 2 - swatchSize / 2;
805
+ const bgColorSwatchUrl = getImageUrl("threadColor", backgroundColor);
806
+ const bgColorSwatchImg = imageRefs.current.get(bgColorSwatchUrl);
807
+ if (bgColorSwatchImg?.complete && bgColorSwatchImg.naturalHeight > 0) {
808
+ const ratio = bgColorSwatchImg.naturalWidth / bgColorSwatchImg.naturalHeight;
809
+ const swatchW = Math.max(1, Math.floor(swatchSize * ratio));
810
+ ctx.drawImage(bgColorSwatchImg, bgSwatchX, bgSwatchY, swatchW, swatchSize);
811
+ }
779
812
  }
780
813
  infoY += infoLineHeight;
781
- // Màu nền (Background Color)
782
- drawAsterisk(padding + bottomPadding, infoY);
783
- const bgColorLabel = `Màu nền: ${backgroundColor}`;
784
- ctx.fillText(bgColorLabel, startX, infoY);
785
- // Draw background color swatch
786
- const bgSwatchX = startX + ctx.measureText(bgColorLabel).width + LAYOUT.ELEMENT_SPACING * 0.3;
787
- const bgSwatchY = infoY + infoFontSize / 2 - swatchSize / 2;
788
- const bgColorSwatchUrl = getImageUrl("threadColor", backgroundColor);
789
- const bgColorSwatchImg = imageRefs.current.get(bgColorSwatchUrl);
790
- if (bgColorSwatchImg?.complete && bgColorSwatchImg.naturalHeight > 0) {
791
- const ratio = bgColorSwatchImg.naturalWidth / bgColorSwatchImg.naturalHeight;
792
- const swatchW = Math.max(1, Math.floor(swatchSize * ratio));
793
- ctx.drawImage(bgColorSwatchImg, bgSwatchX, bgSwatchY, swatchW, swatchSize);
814
+ // Màu viền (Border Color) - layer_colors[1]
815
+ drawAsterisk(padding, infoY);
816
+ const borderColorPrefix = "Màu viền: ";
817
+ ctx.fillText(borderColorPrefix, startX, infoY);
818
+ if (!borderColor || borderColor.trim() === "") {
819
+ // Hiển thị warning màu đỏ nếu thiếu màu
820
+ const prefixWidth = ctx.measureText(borderColorPrefix).width;
821
+ ctx.fillStyle = "#CC0000";
822
+ ctx.fillText("(Chưa màu)", startX + prefixWidth, infoY);
823
+ ctx.fillStyle = LAYOUT.LABEL_COLOR; // Reset color
824
+ }
825
+ else {
826
+ // Hiển thị tên màu
827
+ const prefixWidth = ctx.measureText(borderColorPrefix).width;
828
+ ctx.fillText(borderColor, startX + prefixWidth, infoY);
829
+ // Draw border color swatch
830
+ const swatchSize = infoFontSize * 1.3;
831
+ const borderSwatchX = startX +
832
+ ctx.measureText(borderColorPrefix + borderColor).width +
833
+ LAYOUT.ELEMENT_SPACING * 0.3;
834
+ const borderSwatchY = infoY + infoFontSize / 2 - swatchSize / 2;
835
+ const borderColorSwatchUrl = getImageUrl("threadColor", borderColor);
836
+ const borderColorSwatchImg = imageRefs.current.get(borderColorSwatchUrl);
837
+ if (borderColorSwatchImg?.complete &&
838
+ borderColorSwatchImg.naturalHeight > 0) {
839
+ const ratio = borderColorSwatchImg.naturalWidth / borderColorSwatchImg.naturalHeight;
840
+ const swatchW = Math.max(1, Math.floor(swatchSize * ratio));
841
+ ctx.drawImage(borderColorSwatchImg, borderSwatchX, borderSwatchY, swatchW, swatchSize);
842
+ }
794
843
  }
795
844
  infoY += infoLineHeight;
796
- // Màu viền (Border Color)
797
- drawAsterisk(padding + bottomPadding, infoY);
798
- const borderColorLabel = `Màu viền: ${borderColor}`;
799
- ctx.fillText(borderColorLabel, startX, infoY);
800
- // Draw border color swatch
801
- const borderSwatchX = startX +
802
- ctx.measureText(borderColorLabel).width +
803
- LAYOUT.ELEMENT_SPACING * 0.3;
804
- const borderSwatchY = infoY + infoFontSize / 2 - swatchSize / 2;
805
- const borderColorSwatchUrl = getImageUrl("threadColor", borderColor);
806
- const borderColorSwatchImg = imageRefs.current.get(borderColorSwatchUrl);
807
- if (borderColorSwatchImg?.complete &&
808
- borderColorSwatchImg.naturalHeight > 0) {
809
- const ratio = borderColorSwatchImg.naturalWidth / borderColorSwatchImg.naturalHeight;
810
- const swatchW = Math.max(1, Math.floor(swatchSize * ratio));
811
- ctx.drawImage(borderColorSwatchImg, borderSwatchX, borderSwatchY, swatchW, swatchSize);
845
+ // Màu vải (Fabric Color) - layer_colors[3]
846
+ drawAsterisk(padding, infoY);
847
+ const fabricColorPrefix = "Màu vải: ";
848
+ ctx.fillText(fabricColorPrefix, startX, infoY);
849
+ if (!fabricColor || fabricColor.trim() === "") {
850
+ // Hiển thị warning màu đỏ nếu thiếu màu
851
+ const prefixWidth = ctx.measureText(fabricColorPrefix).width;
852
+ ctx.fillStyle = "#CC0000";
853
+ ctx.fillText("(Chưa màu)", startX + prefixWidth, infoY);
854
+ ctx.fillStyle = LAYOUT.LABEL_COLOR; // Reset color
855
+ }
856
+ else {
857
+ // Hiển thị tên màu
858
+ const prefixWidth = ctx.measureText(fabricColorPrefix).width;
859
+ ctx.fillText(fabricColor, startX + prefixWidth, infoY);
860
+ // Draw fabric color swatch
861
+ const swatchSize = infoFontSize * 1.3;
862
+ const fabricSwatchX = startX +
863
+ ctx.measureText(fabricColorPrefix + fabricColor).width +
864
+ LAYOUT.ELEMENT_SPACING * 0.3;
865
+ const fabricSwatchY = infoY + infoFontSize / 2 - swatchSize / 2;
866
+ const fabricColorSwatchUrl = getImageUrl("threadColor", fabricColor);
867
+ const fabricColorSwatchImg = imageRefs.current.get(fabricColorSwatchUrl);
868
+ if (fabricColorSwatchImg?.complete &&
869
+ fabricColorSwatchImg.naturalHeight > 0) {
870
+ const ratio = fabricColorSwatchImg.naturalWidth / fabricColorSwatchImg.naturalHeight;
871
+ const swatchW = Math.max(1, Math.floor(swatchSize * ratio));
872
+ ctx.drawImage(fabricColorSwatchImg, fabricSwatchX, fabricSwatchY, swatchW, swatchSize);
873
+ }
812
874
  }
813
875
  infoY += infoLineHeight;
814
876
  // Attachment