soccer-jersey-fork 1.0.109 → 1.0.111

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.
@@ -27,6 +27,7 @@ export const Default = {
27
27
  x: 50,
28
28
  y: 45,
29
29
  color: "#fff",
30
+ textLength: 25,
30
31
  },
31
32
  ],
32
33
  shortsColor: "#DA000C",
@@ -31,6 +31,7 @@ export interface DrawSoccerJerseyProps {
31
31
  fontFamily?: string;
32
32
  fontWeight?: number;
33
33
  fontStyle?: CSSProperties["fontStyle"];
34
+ textLength?: number;
34
35
  }[];
35
36
  images: {
36
37
  src: string;
@@ -150,14 +150,15 @@ export default function drawSoccerJersey({ shirtColor = "plain", shirtStyle, shi
150
150
  */
151
151
  if (texts && texts.length > 0) {
152
152
  for (const textItem of texts) {
153
- const { text, color, size, outlineColor, backgroundColor, backgroundShape, fontFamily, fontWeight, fontStyle, x, y, } = textItem;
153
+ const { text, color, size, outlineColor, backgroundColor, backgroundShape, fontFamily, fontWeight, fontStyle, textLength, x, y, } = textItem;
154
154
  const drawText = (elem) => {
155
- return elem
155
+ const textElement = elem
156
156
  .text(text)
157
157
  .fill(color || "#eee")
158
158
  .font({
159
159
  family: fontFamily,
160
160
  size,
161
+ // fontWeight and fontStyle as the name do not work. Must be weight, style
161
162
  weight: fontWeight,
162
163
  style: fontStyle,
163
164
  anchor: "middle",
@@ -165,8 +166,18 @@ export default function drawSoccerJersey({ shirtColor = "plain", shirtStyle, shi
165
166
  .stroke({
166
167
  color: outlineColor || color,
167
168
  width: 0.5,
168
- })
169
- .center(x, y);
169
+ });
170
+ if (textLength) {
171
+ // You must apply the attributes directly to the tspan element instead of (or in addition to) the parent text element.
172
+ const tspan = textElement.first();
173
+ const attrs = {
174
+ textLength,
175
+ lengthAdjust: "spacingAndGlyphs",
176
+ };
177
+ if (tspan)
178
+ tspan.attr(attrs);
179
+ }
180
+ return textElement.center(x, y);
170
181
  };
171
182
  if (backgroundColor) {
172
183
  // eslint-disable-next-line new-cap
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soccer-jersey-fork",
3
- "version": "1.0.109",
3
+ "version": "1.0.111",
4
4
  "description": "Generate soccer jerseys in SVG format",
5
5
  "main": "lib/index.js",
6
6
  "author": "nadchif (https://github.com/nadchif)",