embroidery-qc-image 1.0.20 → 1.0.22

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;AAyJjC,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;AAoWD,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAqHvD,CAAC;AAy3BF,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;AAyJjC,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;AAoWD,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAqHvD,CAAC;AAw7BF,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
@@ -728,10 +728,30 @@ const renderSide = (ctx, side, startY, width, scaleFactor, imageRefs) => {
728
728
  ctx.restore();
729
729
  // Compute uniform properties
730
730
  const textPositions = side.positions.filter((p) => p.type === "TEXT");
731
- const uniformProps = computeUniformProperties(textPositions);
732
- // Render uniform labels (only if more than 1 TEXT position)
733
- if (textPositions.length > 1) {
734
- currentY += renderUniformLabels(ctx, uniformProps, padding, currentY, sideWidth, scaleFactor, imageRefs, textPositions);
731
+ const iconColorPositions = side.positions.filter((p) => p.type === "ICON" && (!p.layer_colors?.length || p.layer_colors.length === 1));
732
+ const iconColorValues = iconColorPositions
733
+ .map((p) => {
734
+ if (p.layer_colors?.length === 1)
735
+ return p.layer_colors[0];
736
+ return p.color ?? null;
737
+ })
738
+ .filter((color) => Boolean(color));
739
+ const uniformProps = computeUniformProperties(textPositions, {
740
+ additionalColorValues: iconColorValues,
741
+ });
742
+ const hasMultipleTextPositions = textPositions.length > 1;
743
+ const hasSharedIconColor = iconColorValues.length > 0;
744
+ const shouldRenderSharedColorLabel = !hasMultipleTextPositions &&
745
+ hasSharedIconColor &&
746
+ uniformProps.isUniform.color &&
747
+ Boolean(uniformProps.values.color);
748
+ const shouldShowUniformLabels = hasMultipleTextPositions || shouldRenderSharedColorLabel;
749
+ const uniformLabelFields = hasMultipleTextPositions
750
+ ? undefined
751
+ : { color: true };
752
+ // Render uniform labels (when applicable)
753
+ if (shouldShowUniformLabels) {
754
+ currentY += renderUniformLabels(ctx, uniformProps, padding, currentY, sideWidth, scaleFactor, imageRefs, textPositions, uniformLabelFields);
735
755
  }
736
756
  // Group text positions by common properties
737
757
  const textGroups = groupTextPositions(textPositions);
@@ -745,7 +765,12 @@ const renderSide = (ctx, side, startY, width, scaleFactor, imageRefs) => {
745
765
  }
746
766
  // If only 1 TEXT position, show all labels (no uniform labels rendered)
747
767
  const showLabels = textPositions.length === 1
748
- ? { font: true, shape: true, floral: true, color: true }
768
+ ? {
769
+ font: true,
770
+ shape: true,
771
+ floral: true,
772
+ color: !shouldRenderSharedColorLabel,
773
+ }
749
774
  : {
750
775
  font: !uniformProps.isUniform.font,
751
776
  shape: !uniformProps.isUniform.shape,
@@ -763,7 +788,17 @@ const renderSide = (ctx, side, startY, width, scaleFactor, imageRefs) => {
763
788
  currentY += LAYOUT.LINE_GAP * scaleFactor;
764
789
  side.positions.forEach((position) => {
765
790
  if (position.type === "ICON") {
766
- currentY += renderIconPosition(ctx, position, padding, currentY, sideWidth, scaleFactor, imageRefs);
791
+ const layerCount = position.layer_colors?.length ?? 0;
792
+ const iconUsesSingleColor = layerCount === 0 || layerCount === 1;
793
+ const iconColorValue = layerCount === 1
794
+ ? position.layer_colors?.[0] ?? null
795
+ : position.color ?? null;
796
+ const hideColor = shouldShowUniformLabels &&
797
+ uniformProps.isUniform.color &&
798
+ iconColorValue !== null &&
799
+ uniformProps.values.color === iconColorValue &&
800
+ iconUsesSingleColor;
801
+ currentY += renderIconPosition(ctx, position, padding, currentY, sideWidth, scaleFactor, imageRefs, { hideColor });
767
802
  currentY += (LAYOUT.LINE_GAP / 3) * scaleFactor;
768
803
  }
769
804
  });
@@ -800,56 +835,67 @@ const groupTextPositions = (textPositions) => {
800
835
  }
801
836
  return groups;
802
837
  };
803
- const computeUniformProperties = (textPositions) => {
804
- if (textPositions.length === 0) {
805
- return {
806
- values: { font: null, shape: null, floral: null, color: null },
807
- isUniform: { font: false, shape: false, floral: false, color: false },
808
- };
809
- }
838
+ const computeUniformProperties = (textPositions, options) => {
839
+ const defaults = {
840
+ values: { font: null, shape: null, floral: null, color: null },
841
+ isUniform: { font: false, shape: false, floral: false, color: false },
842
+ };
810
843
  const fonts = new Set(textPositions.map((p) => p.font));
811
844
  const shapes = new Set(textPositions.map((p) => p.text_shape));
812
845
  const florals = new Set(textPositions.map((p) => p.floral_pattern ?? "None"));
813
- const colors = new Set(textPositions.map((p) => p.character_colors?.length
814
- ? p.character_colors.join(",")
815
- : p.color ?? "None"));
846
+ const colorSources = [
847
+ ...textPositions.map((p) => p.character_colors?.length
848
+ ? p.character_colors.join(",")
849
+ : p.color ?? "None"),
850
+ ...(options?.additionalColorValues?.map((color) => color ?? "None") ?? []),
851
+ ];
852
+ if (textPositions.length === 0 &&
853
+ (!options?.additionalColorValues || options.additionalColorValues.length === 0)) {
854
+ return defaults;
855
+ }
856
+ const colors = new Set(colorSources);
816
857
  return {
817
858
  values: {
818
859
  font: fonts.size === 1 ? [...fonts][0] : null,
819
860
  shape: shapes.size === 1 ? [...shapes][0] : null,
820
861
  floral: florals.size === 1 ? [...florals][0] : null,
821
- color: colors.size === 1 ? [...colors][0] : null,
862
+ color: colorSources.length > 0 && colors.size === 1 ? [...colors][0] : null,
822
863
  },
823
864
  isUniform: {
824
865
  font: fonts.size === 1,
825
866
  shape: shapes.size === 1,
826
867
  floral: florals.size === 1,
827
- color: colors.size === 1,
868
+ color: colorSources.length > 0 && colors.size === 1,
828
869
  },
829
870
  };
830
871
  };
831
- const renderUniformLabels = (ctx, uniformProps, x, y, maxWidth, scaleFactor, imageRefs, textPositions) => {
872
+ const renderUniformLabels = (ctx, uniformProps, x, y, maxWidth, scaleFactor, imageRefs, textPositions, fields) => {
832
873
  const { values } = uniformProps;
833
874
  const fontSize = LAYOUT.OTHER_FONT_SIZE * scaleFactor;
834
875
  const lineGap = LAYOUT.LINE_GAP * scaleFactor;
876
+ const shouldRenderField = (field) => {
877
+ if (!fields)
878
+ return true;
879
+ return fields[field] === true;
880
+ };
835
881
  ctx.save();
836
882
  ctx.font = `${fontSize}px ${LAYOUT.FONT_FAMILY}`;
837
883
  ctx.fillStyle = LAYOUT.LABEL_COLOR;
838
884
  let cursorY = y;
839
885
  let rendered = 0;
840
- if (values.font) {
886
+ if (values.font && shouldRenderField("font")) {
841
887
  const allDefault = textPositions.every((p) => p.is_font_default === true);
842
- const fontLabel = allDefault ? `Font: ${values.font} (Mặc định)` : `Font: ${values.font}`;
888
+ const fontLabel = allDefault ? `Font: ${values.font} (Mặc định)` : `Font: ${values.font} (Custom)`;
843
889
  const result = wrapText(ctx, fontLabel, x, cursorY, maxWidth, fontSize + lineGap);
844
890
  cursorY += result.height;
845
891
  rendered++;
846
892
  }
847
- if (values.shape && values.shape !== "None") {
893
+ if (values.shape && values.shape !== "None" && shouldRenderField("shape")) {
848
894
  const result = wrapText(ctx, `Kiểu chữ: ${values.shape}`, x, cursorY, maxWidth, fontSize + lineGap);
849
895
  cursorY += result.height;
850
896
  rendered++;
851
897
  }
852
- if (values.color && values.color !== "None") {
898
+ if (values.color && values.color !== "None" && shouldRenderField("color")) {
853
899
  const textMaxWidth = Math.max(LAYOUT.MIN_TEXT_WIDTH * scaleFactor, maxWidth - LAYOUT.SWATCH_RESERVED_SPACE * scaleFactor);
854
900
  const result = wrapText(ctx, `Màu chỉ: ${values.color}`, x, cursorY, textMaxWidth, fontSize + lineGap);
855
901
  const swatchH = Math.floor(fontSize * LAYOUT.SWATCH_HEIGHT_RATIO);
@@ -864,7 +910,7 @@ const renderUniformLabels = (ctx, uniformProps, x, y, maxWidth, scaleFactor, ima
864
910
  cursorY += result.height;
865
911
  rendered++;
866
912
  }
867
- if (values.floral && values.floral !== "None") {
913
+ if (values.floral && values.floral !== "None" && shouldRenderField("floral")) {
868
914
  const result = wrapText(ctx, `Mẫu hoa: ${values.floral}`, x, cursorY, maxWidth, fontSize + lineGap);
869
915
  cursorY += result.height;
870
916
  rendered++;
@@ -932,7 +978,7 @@ const renderTextPosition = (ctx, position, x, y, maxWidth, displayIndex, showLab
932
978
  if (showLabels.font && position.font) {
933
979
  const fontLabel = position.is_font_default === true
934
980
  ? `Font: ${position.font} (Mặc định)`
935
- : `Font: ${position.font}`;
981
+ : `Font: ${position.font} (Custom)`;
936
982
  const result = wrapText(ctx, fontLabel, x, currentY, maxWidth, otherFontSize + lineGap);
937
983
  currentY += result.height;
938
984
  drawnHeight += result.height;
@@ -962,7 +1008,7 @@ const renderTextPosition = (ctx, position, x, y, maxWidth, displayIndex, showLab
962
1008
  ctx.restore();
963
1009
  return drawnHeight;
964
1010
  };
965
- const renderIconPosition = (ctx, position, x, y, maxWidth, scaleFactor, imageRefs) => {
1011
+ const renderIconPosition = (ctx, position, x, y, maxWidth, scaleFactor, imageRefs, options) => {
966
1012
  const iconFontSize = LAYOUT.OTHER_FONT_SIZE * scaleFactor;
967
1013
  const lineGap = LAYOUT.LINE_GAP * scaleFactor;
968
1014
  ctx.save();
@@ -995,7 +1041,10 @@ const renderIconPosition = (ctx, position, x, y, maxWidth, scaleFactor, imageRef
995
1041
  : position.color
996
1042
  ? [position.color]
997
1043
  : null;
998
- if (iconColors?.length) {
1044
+ const layerCount = position.layer_colors?.length ?? 0;
1045
+ const hasMultiLayerColors = layerCount > 1;
1046
+ const shouldSkipColorSection = options?.hideColor && !hasMultiLayerColors;
1047
+ if (iconColors?.length && !shouldSkipColorSection) {
999
1048
  const textMaxWidth = Math.max(LAYOUT.MIN_TEXT_WIDTH * scaleFactor, maxWidth - LAYOUT.SWATCH_RESERVED_SPACE * scaleFactor);
1000
1049
  const colorResult = wrapText(ctx, `Màu chỉ: ${iconColors.join(", ")}`, x, cursorY, textMaxWidth, iconFontSize + lineGap);
1001
1050
  const swatchH = Math.floor(iconFontSize * LAYOUT.SWATCH_HEIGHT_RATIO);