embroidery-qc-image 1.0.23 → 1.0.24

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.js CHANGED
@@ -33,71 +33,6 @@ function styleInject(css, ref) {
33
33
  var css_248z = ".render-embroidery {\r\n display: inline-block;\r\n position: relative;\r\n width: 100%;\r\n max-width: 100%;\r\n}\r\n\r\n.render-embroidery-canvas {\r\n display: block;\r\n width: 100%;\r\n height: auto;\r\n image-rendering: high-quality;\r\n background: transparent;\r\n}\r\n";
34
34
  styleInject(css_248z);
35
35
 
36
- // ============================================================================
37
- // CONSTANTS
38
- // ============================================================================
39
- const COLOR_MAP = {
40
- "Army (1394)": "#545541",
41
- Army: "#545541",
42
- "Black (8)": "#060608",
43
- Black: "#060608",
44
- "Bubblegum (1309)": "#E77B9F",
45
- Bubblegum: "#E77B9F",
46
- "Carolina Blue (1274)": "#608CC9",
47
- "Carolina Blue": "#608CC9",
48
- "Celadon (1098)": "#8EAD8D",
49
- Celadon: "#8EAD8D",
50
- "Coffee Bean (1145)": "#502B23",
51
- "Coffee Bean": "#502B23",
52
- "Daffodil (1180)": "#FBE30D",
53
- Daffodil: "#FBE30D",
54
- "Dark Gray (1131)": "#2E272E",
55
- "Dark Gray": "#2E272E",
56
- "Doe Skin Beige (1344)": "#AE9B8B",
57
- "Doe Skin Beige": "#AE9B8B",
58
- "Dusty Blue (1373)": "#7B90A9",
59
- "Dusty Blue": "#7B90A9",
60
- "Forest Green (1397)": "#073020",
61
- "Forest Green": "#073020",
62
- "Gold (1425)": "#D2920A",
63
- Gold: "#D2920A",
64
- "Gray (1118)": "#9999A3",
65
- Gray: "#9999A3",
66
- "Ivory (1072)": "#E3DAC9",
67
- Ivory: "#E3DAC9",
68
- "Lavender (1032)": "#9274B6",
69
- Lavender: "#9274B6",
70
- "Light Denim (1133)": "#366696",
71
- "Light Denim": "#366696",
72
- "Light Salmon (1018)": "#E0A793",
73
- "Light Salmon": "#E0A793",
74
- "Maroon (1374)": "#480C1C",
75
- Maroon: "#480C1C",
76
- "Navy Blue (1044)": "#04072A",
77
- "Navy Blue": "#04072A",
78
- "Olive Green (1157)": "#625E1F",
79
- "Olive Green": "#625E1F",
80
- "Orange (1278)": "#D45D03",
81
- Orange: "#D45D03",
82
- "Peach Blush (1053)": "#E2C0B6",
83
- "Peach Blush": "#E2C0B6",
84
- "Pink (1148)": "#EFAFBF",
85
- Pink: "#EFAFBF",
86
- "Purple (1412)": "#37196F",
87
- Purple: "#37196F",
88
- "Red (1037)": "#9D000B",
89
- Red: "#9D000B",
90
- "Silver Sage (1396)": "#424F45",
91
- "Silver Sage": "#424F45",
92
- "Summer Sky (1432)": "#65A8D2",
93
- "Summer Sky": "#65A8D2",
94
- "Terra Cotta (1477)": "#AE3111",
95
- "Terra Cotta": "#AE3111",
96
- "Sand (1055)": "#D2C2AB",
97
- Sand: "#D2C2AB",
98
- "White (9)": "#D8D7DC",
99
- White: "#D8D7DC",
100
- };
101
36
  const DEFAULT_ERROR_COLOR = "#CC1F1A";
102
37
  const DEFAULT_WARNING_COLOR = "#FF8C00";
103
38
  const BASE_URLS = {
@@ -386,43 +321,6 @@ const buildWrappedLines = (ctx, text, maxWidth) => {
386
321
  lines.push(currentLine);
387
322
  return lines;
388
323
  };
389
- const wrapTextMultiColor = (ctx, text, colors, x, y, maxWidth, lineHeight) => {
390
- const words = text.split(" ");
391
- const lines = [];
392
- const lineStartIndices = [0];
393
- let currentLine = words[0];
394
- let currentCharIndex = words[0].length;
395
- for (let i = 1; i < words.length; i++) {
396
- const testLine = currentLine + " " + words[i];
397
- if (ctx.measureText(testLine).width > maxWidth && currentLine.length > 0) {
398
- lines.push(currentLine);
399
- lineStartIndices.push(currentCharIndex + 1);
400
- currentLine = words[i];
401
- currentCharIndex += words[i].length + 1;
402
- }
403
- else {
404
- currentLine = testLine;
405
- currentCharIndex += words[i].length + 1;
406
- }
407
- }
408
- lines.push(currentLine);
409
- let currentY = y;
410
- lines.forEach((line, lineIdx) => {
411
- let currentX = x;
412
- const startCharIdx = lineIdx > 0 ? lineStartIndices[lineIdx] : 0;
413
- for (let i = 0; i < line.length; i++) {
414
- const char = line[i];
415
- const globalCharIdx = startCharIdx + i;
416
- const colorIndex = globalCharIdx % colors.length;
417
- const color = colors[colorIndex];
418
- ctx.fillStyle = COLOR_MAP[color] || LAYOUT.LABEL_COLOR;
419
- ctx.fillText(char, currentX, currentY);
420
- currentX += ctx.measureText(char).width;
421
- }
422
- currentY += lineHeight;
423
- });
424
- return lines.length * lineHeight;
425
- };
426
324
  const drawSwatches = (ctx, colors, startX, startY, swatchHeight, scaleFactor, imageRefs) => {
427
325
  let swatchX = startX;
428
326
  colors.forEach((color) => {
@@ -894,9 +792,25 @@ const renderUniformLabels = (ctx, uniformProps, x, y, maxWidth, scaleFactor, ima
894
792
  let rendered = 0;
895
793
  if (values.font && shouldRenderField("font")) {
896
794
  const allDefault = textPositions.every((p) => p.is_font_default === true);
897
- const fontLabel = allDefault ? `Font: ${values.font} (Mặc định)` : `Font: ${values.font} (Custom)`;
898
- const result = wrapText(ctx, fontLabel, x, cursorY, maxWidth, fontSize + lineGap);
899
- cursorY += result.height;
795
+ // Render "Font: " với font mặc định
796
+ const prefix = "Font: ";
797
+ ctx.font = `${fontSize}px ${LAYOUT.FONT_FAMILY}`;
798
+ const prefixWidth = ctx.measureText(prefix).width;
799
+ let currentX = x + prefixWidth;
800
+ ctx.fillText(prefix, x, cursorY);
801
+ // Render tên font với font từ config
802
+ ctx.font = `${fontSize}px ${values.font}`;
803
+ const fontNameWidth = ctx.measureText(values.font).width;
804
+ ctx.fillText(values.font, currentX, cursorY);
805
+ currentX += fontNameWidth;
806
+ // Render "(Mặc định)" hoặc "(Custom)" với font mặc định
807
+ const suffix = allDefault ? " (Mặc định)" : " (Custom)";
808
+ ctx.font = `${fontSize}px ${LAYOUT.FONT_FAMILY}`;
809
+ ctx.measureText(suffix).width;
810
+ ctx.fillText(suffix, currentX, cursorY);
811
+ // Tính toán height và di chuyển cursorY
812
+ const lineHeight = fontSize + lineGap;
813
+ cursorY += lineHeight;
900
814
  rendered++;
901
815
  }
902
816
  if (values.shape && values.shape !== "None" && shouldRenderField("shape")) {
@@ -945,31 +859,15 @@ const renderTextPosition = (ctx, position, x, y, maxWidth, displayIndex, showLab
945
859
  const textMaxWidth = maxWidth - labelWidth;
946
860
  // Get display text (handle empty/null/undefined)
947
861
  const isEmptyText = !position.text || position.text.trim() === "";
948
- // Draw text content
862
+ // Draw text content - dùng font mặc định và màu đỏ
863
+ ctx.font = `${textFontSize}px ${LAYOUT.FONT_FAMILY}`;
864
+ ctx.fillStyle = DEFAULT_ERROR_COLOR;
949
865
  if (isEmptyText) {
950
- ctx.font = `${textFontSize}px ${LAYOUT.FONT_FAMILY}`;
951
- ctx.fillStyle = LAYOUT.LABEL_COLOR;
952
866
  const textResult = wrapText(ctx, "(không có text)", x + labelWidth, currentY, textMaxWidth, textFontSize);
953
867
  currentY += textResult.height;
954
868
  drawnHeight += textResult.height;
955
869
  }
956
- else if (position.floral_pattern) {
957
- // Khi có floral_pattern, dùng màu mặc định như label
958
- ctx.font = `${textFontSize}px ${position.font}`;
959
- ctx.fillStyle = LAYOUT.LABEL_COLOR;
960
- const textResult = wrapText(ctx, position.text, x + labelWidth, currentY, textMaxWidth, textFontSize);
961
- currentY += textResult.height;
962
- drawnHeight += textResult.height;
963
- }
964
- else if (position.character_colors?.length) {
965
- ctx.font = `${textFontSize}px ${position.font}`;
966
- const textHeight = wrapTextMultiColor(ctx, position.text, position.character_colors, x + labelWidth, currentY, textMaxWidth, textFontSize);
967
- currentY += textHeight;
968
- drawnHeight += textHeight;
969
- }
970
870
  else {
971
- ctx.font = `${textFontSize}px ${position.font}`;
972
- ctx.fillStyle = COLOR_MAP[position.color ?? "None"] || LAYOUT.LABEL_COLOR;
973
871
  const textResult = wrapText(ctx, position.text, x + labelWidth, currentY, textMaxWidth, textFontSize);
974
872
  currentY += textResult.height;
975
873
  drawnHeight += textResult.height;
@@ -985,12 +883,26 @@ const renderTextPosition = (ctx, position, x, y, maxWidth, displayIndex, showLab
985
883
  drawnHeight += result.height;
986
884
  }
987
885
  if (showLabels.font && position.font) {
988
- const fontLabel = position.is_font_default === true
989
- ? `Font: ${position.font} (Mặc định)`
990
- : `Font: ${position.font} (Custom)`;
991
- const result = wrapText(ctx, fontLabel, x, currentY, maxWidth, otherFontSize + lineGap);
992
- currentY += result.height;
993
- drawnHeight += result.height;
886
+ // Render "Font: " với font mặc định
887
+ const prefix = "Font: ";
888
+ ctx.font = `${otherFontSize}px ${LAYOUT.FONT_FAMILY}`;
889
+ const prefixWidth = ctx.measureText(prefix).width;
890
+ let currentX = x + prefixWidth;
891
+ ctx.fillText(prefix, x, currentY);
892
+ // Render tên font với font từ config
893
+ ctx.font = `${otherFontSize}px ${position.font}`;
894
+ const fontNameWidth = ctx.measureText(position.font).width;
895
+ ctx.fillText(position.font, currentX, currentY);
896
+ currentX += fontNameWidth;
897
+ // Render "(Mặc định)" hoặc "(Custom)" với font mặc định
898
+ const suffix = position.is_font_default === true ? " (Mặc định)" : " (Custom)";
899
+ ctx.font = `${otherFontSize}px ${LAYOUT.FONT_FAMILY}`;
900
+ ctx.measureText(suffix).width;
901
+ ctx.fillText(suffix, currentX, currentY);
902
+ // Tính toán height và di chuyển cursorY
903
+ const lineHeight = otherFontSize + lineGap;
904
+ currentY += lineHeight;
905
+ drawnHeight += lineHeight;
994
906
  }
995
907
  if (showLabels.color) {
996
908
  const colorValue = position.character_colors?.join(", ") || position.color;