soccer-jersey-fork 1.0.44 → 1.0.47

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,10 +1,19 @@
1
+ /*!
2
+ * This file has been modified from the original.
3
+ * Original source: https://github.com/nadchif/soccer-jersey/tree/master
4
+ * Modifications Copyright 2025 Lau Kai Chung
5
+ */
1
6
  import { Svg } from "@svgdotjs/svg.js";
2
7
  import { ShirtStyleDirection } from "../types";
3
- declare const drawStriped: (page: Svg, primaryColor: string, secondaryColor: string, direction: ShirtStyleDirection, thickness?: "thin" | "thick" | "normal") => import("@svgdotjs/svg.js").Pattern;
4
- declare const drawCheckered: (page: Svg, primaryColor: string, secondaryColor: string) => import("@svgdotjs/svg.js").Pattern;
5
- declare const drawHoops: (page: Svg, primaryColor: string, secondaryColor: string) => import("@svgdotjs/svg.js").Pattern;
6
- declare const drawTwoColors: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
7
- declare const drawSingleBand: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
8
- declare const drawWaves: (page: Svg, primaryColor: string, secondaryColor: string, waveStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
9
- declare const drawDashes: (page: Svg, primaryColor: string, secondaryColor: string, dashDirection: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
10
- export { drawStriped, drawHoops, drawSingleBand, drawCheckered, drawTwoColors, drawWaves, drawDashes, };
8
+ export declare const drawStripedThick: (page: Svg, primaryColor: string, secondaryColor: string, direction: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
9
+ export declare const drawStripedThin: (page: Svg, primaryColor: string, secondaryColor: string, direction: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
10
+ export declare const drawStripedNormal: (page: Svg, primaryColor: string, secondaryColor: string, direction: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
11
+ export declare const drawStriped: (page: Svg, primaryColor: string, secondaryColor: string, direction: ShirtStyleDirection, thickness?: "thin" | "thick" | "normal") => import("@svgdotjs/svg.js").Pattern;
12
+ export declare const drawShirtSideStriped: (page: Svg, primaryColor: string, secondaryColor: string) => import("@svgdotjs/svg.js").Pattern;
13
+ export declare const drawCheckered: (page: Svg, primaryColor: string, secondaryColor: string) => import("@svgdotjs/svg.js").Pattern;
14
+ export declare const drawHoops: (page: Svg, primaryColor: string, secondaryColor: string) => import("@svgdotjs/svg.js").Pattern;
15
+ export declare const drawTwoColors: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
16
+ export declare const drawSingleBand: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
17
+ export declare const drawWaves: (page: Svg, primaryColor: string, secondaryColor: string, waveStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
18
+ export declare const drawDashes: (page: Svg, primaryColor: string, secondaryColor: string, dashDirection: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
19
+ export declare const drawShortsSideStriped: (page: Svg, primaryColor: string, secondaryColor: string) => import("@svgdotjs/svg.js").Pattern;
@@ -1,4 +1,4 @@
1
- const drawStripedThick = (page, primaryColor, secondaryColor, direction) => {
1
+ export const drawStripedThick = (page, primaryColor, secondaryColor, direction) => {
2
2
  switch (direction) {
3
3
  case "horizontal": {
4
4
  // Define a pattern tile tall enough for both stripes
@@ -27,7 +27,7 @@ const drawStripedThick = (page, primaryColor, secondaryColor, direction) => {
27
27
  }
28
28
  }
29
29
  };
30
- const drawStripedThin = (page, primaryColor, secondaryColor, direction) => {
30
+ export const drawStripedThin = (page, primaryColor, secondaryColor, direction) => {
31
31
  switch (direction) {
32
32
  case "horizontal": {
33
33
  return page.pattern(20, 5, function (add) {
@@ -43,7 +43,7 @@ const drawStripedThin = (page, primaryColor, secondaryColor, direction) => {
43
43
  }
44
44
  }
45
45
  };
46
- const drawStripedNormal = (page, primaryColor, secondaryColor, direction) => {
46
+ export const drawStripedNormal = (page, primaryColor, secondaryColor, direction) => {
47
47
  switch (direction) {
48
48
  case "horizontal": {
49
49
  return page.pattern(20, 8, function (add) {
@@ -59,7 +59,7 @@ const drawStripedNormal = (page, primaryColor, secondaryColor, direction) => {
59
59
  }
60
60
  }
61
61
  };
62
- const drawStriped = (page, primaryColor, secondaryColor, direction, thickness = "normal") => {
62
+ export const drawStriped = (page, primaryColor, secondaryColor, direction, thickness = "normal") => {
63
63
  switch (thickness) {
64
64
  case "thick":
65
65
  return drawStripedThick(page, primaryColor, secondaryColor, direction);
@@ -69,7 +69,14 @@ const drawStriped = (page, primaryColor, secondaryColor, direction, thickness =
69
69
  return drawStripedNormal(page, primaryColor, secondaryColor, direction);
70
70
  }
71
71
  };
72
- const drawCheckered = (page, primaryColor, secondaryColor) => page.pattern(20, 20, function (add) {
72
+ export const drawShirtSideStriped = (page, primaryColor, secondaryColor) => {
73
+ return page.pattern(51.3, 100, function (add) {
74
+ add.rect(51.3, 100).fill(primaryColor);
75
+ // The move 24.2 is the space between the lines
76
+ add.rect(2, 55).fill(secondaryColor).move(24.2, 42);
77
+ });
78
+ };
79
+ export const drawCheckered = (page, primaryColor, secondaryColor) => page.pattern(20, 20, function (add) {
73
80
  add.rect(20, 20).fill(primaryColor);
74
81
  add.rect(10, 10).fill(secondaryColor ? secondaryColor : "#eee");
75
82
  add
@@ -77,11 +84,11 @@ const drawCheckered = (page, primaryColor, secondaryColor) => page.pattern(20, 2
77
84
  .fill(secondaryColor ? secondaryColor : "#eee")
78
85
  .move(10, 10);
79
86
  });
80
- const drawHoops = (page, primaryColor, secondaryColor) => page.pattern(20, 20, function (add) {
87
+ export const drawHoops = (page, primaryColor, secondaryColor) => page.pattern(20, 20, function (add) {
81
88
  add.rect(20, 20).fill(primaryColor);
82
89
  add.rect(20, 10).fill(secondaryColor ? secondaryColor : "#eee");
83
90
  });
84
- const drawTwoColors = (page, primaryColor, secondaryColor, bandStyle) => {
91
+ export const drawTwoColors = (page, primaryColor, secondaryColor, bandStyle) => {
85
92
  switch (bandStyle) {
86
93
  case "diagonalRight":
87
94
  return page.pattern(100, 100, function (add) {
@@ -124,7 +131,7 @@ const drawTwoColors = (page, primaryColor, secondaryColor, bandStyle) => {
124
131
  });
125
132
  }
126
133
  };
127
- const drawSingleBand = (page, primaryColor, secondaryColor, bandStyle) => {
134
+ export const drawSingleBand = (page, primaryColor, secondaryColor, bandStyle) => {
128
135
  switch (bandStyle) {
129
136
  case "diagonalRight":
130
137
  return page.pattern(100, 100, function (add) {
@@ -167,7 +174,7 @@ const drawSingleBand = (page, primaryColor, secondaryColor, bandStyle) => {
167
174
  });
168
175
  }
169
176
  };
170
- const drawWaves = (page, primaryColor, secondaryColor, waveStyle) => {
177
+ export const drawWaves = (page, primaryColor, secondaryColor, waveStyle) => {
171
178
  switch (waveStyle) {
172
179
  case "horizontal":
173
180
  return page.pattern(20, 12, function (add) {
@@ -199,7 +206,7 @@ const drawWaves = (page, primaryColor, secondaryColor, waveStyle) => {
199
206
  });
200
207
  }
201
208
  };
202
- const drawDashes = (page, primaryColor, secondaryColor, dashDirection) => {
209
+ export const drawDashes = (page, primaryColor, secondaryColor, dashDirection) => {
203
210
  switch (dashDirection) {
204
211
  case "diagonalLeft":
205
212
  return page.pattern(10, 10, function (add) {
@@ -239,4 +246,17 @@ const drawDashes = (page, primaryColor, secondaryColor, dashDirection) => {
239
246
  });
240
247
  }
241
248
  };
242
- export { drawStriped, drawHoops, drawSingleBand, drawCheckered, drawTwoColors, drawWaves, drawDashes, };
249
+ // export const drawShortsSideStriped = (page: Svg, color: string) => {
250
+ // const shortsStripedLeft = `m 26 101 q 1 2 -1 38`;
251
+ // const shortsStripedRight = `m 77 101 q -1 2 1 38`;
252
+ // page.path(shortsStripedLeft).stroke({ width: 2, color, linecap: "square" });
253
+ // page.path(shortsStripedRight).stroke({ width: 2, color, linecap: "square" });
254
+ // return page;
255
+ // };
256
+ export const drawShortsSideStriped = (page, primaryColor, secondaryColor) => {
257
+ return page.pattern(53, 50, function (add) {
258
+ add.rect(53, 50).fill(primaryColor);
259
+ // The move 24.2 is the space between the lines
260
+ add.rect(1, 40).radius(1, 1).fill(secondaryColor).move(24.5, 0);
261
+ });
262
+ };
@@ -1,3 +1,8 @@
1
+ /*!
2
+ * This file has been modified from the original.
3
+ * Original source: https://github.com/nadchif/soccer-jersey/tree/master
4
+ * Modifications Copyright 2025 Lau Kai Chung
5
+ */
1
6
  import type { Meta, StoryObj } from "@storybook/react-vite";
2
7
  import { ReactTeamPage } from "./ReactTeamPage";
3
8
  declare const meta: Meta<typeof ReactTeamPage>;
@@ -11,12 +11,16 @@ export const Default = {
11
11
  args: {
12
12
  shirtText: "SJ JS",
13
13
  shirtColor: "#008800",
14
+ shirtStyle: "sideStriped",
15
+ shirtStyleColor: "red",
14
16
  sleeveColor: "#008800",
15
17
  textColor: "#fff",
16
18
  collarColor: "red",
17
19
  sleeveCuffColor: "yellow",
18
20
  shortsColor: "black",
19
21
  image: "https://resources.simcups.com/flags/w80/264.png",
22
+ shortsStyle: "sideStriped",
23
+ // shortsCuffColor: "#6e6dd2",
20
24
  },
21
25
  };
22
26
  export const ARS = {
@@ -4,7 +4,7 @@
4
4
  * Modifications Copyright 2025 Lau Kai Chung
5
5
  */
6
6
  export interface DrawSoccerJerseyProps {
7
- shirtText: string;
7
+ shirtText?: string;
8
8
  textColor: string;
9
9
  textOutlineColor?: string;
10
10
  textBackgroundColor?: string;
@@ -23,8 +23,12 @@ export interface DrawSoccerJerseyProps {
23
23
  imageX?: number;
24
24
  imageY?: number;
25
25
  shortsColor: string;
26
+ shortsStyle: ShortsStyle;
27
+ shortsStyleColor?: string;
28
+ shortsCuffColor?: string;
26
29
  withBadge?: boolean;
27
30
  withShorts?: boolean;
28
31
  }
29
32
  export type ShirtStyleDirection = "diagonalRight" | "diagonalLeft" | "horizontal" | "vertical";
30
- export type ShirtStyle = "plain" | "twoColors" | "striped" | "stripedThin" | "stripedThick" | "waves" | "checkered" | "hoops" | "singleBand" | "dashed";
33
+ export type ShirtStyle = "plain" | "twoColors" | "striped" | "stripedThin" | "stripedThick" | "sideStriped" | "waves" | "checkered" | "hoops" | "singleBand" | "dashed";
34
+ export type ShortsStyle = "plain" | "sideStriped";
@@ -26,4 +26,4 @@ import { DrawSoccerJerseyProps } from "../types";
26
26
  * @return {string} A data URL ready for direct use as src attribute
27
27
  * on <img />
28
28
  */
29
- export default function drawSoccerJersey({ shirtText, textColor, textOutlineColor, textBackgroundColor, shirtColor, sleeveColor, shirtStyle, shirtStyleColor, shirtStyleDirection, isBack, shirtWidth, collarColor, sleeveCuffColor, shortsColor, image, imageHeight, imageWidth, imageX, imageY, withBadge, withShorts, }: DrawSoccerJerseyProps): string;
29
+ export default function drawSoccerJersey({ shirtText, textColor, textOutlineColor, textBackgroundColor, shirtColor, sleeveColor, shirtStyle, shirtStyleColor, shirtStyleDirection, isBack, shirtWidth, collarColor, sleeveCuffColor, shortsColor, shortsCuffColor, shortsStyle, shortsStyleColor, image, imageHeight, imageWidth, imageX, imageY, withBadge, withShorts, }: DrawSoccerJerseyProps): string;
@@ -7,7 +7,7 @@
7
7
  /* eslint-disable max-len */
8
8
  import { SVG } from "@svgdotjs/svg.js";
9
9
  import lightenDarkenColor from "./lighten-darken-color";
10
- import { drawHoops, drawSingleBand, drawStriped, drawCheckered, drawTwoColors, drawWaves, drawDashes, } from "../patterns/patterns";
10
+ import { drawHoops, drawSingleBand, drawStriped, drawCheckered, drawTwoColors, drawWaves, drawDashes, drawShortsSideStriped, drawShirtSideStriped, } from "../patterns/patterns";
11
11
  /**
12
12
  * @param {object} specs Specifications of the soccer jersey.
13
13
  * @param {string} specs.shirtText The text to be displayed on the shirt.
@@ -35,7 +35,7 @@ import { drawHoops, drawSingleBand, drawStriped, drawCheckered, drawTwoColors, d
35
35
  * @return {string} A data URL ready for direct use as src attribute
36
36
  * on <img />
37
37
  */
38
- export default function drawSoccerJersey({ shirtText, textColor, textOutlineColor, textBackgroundColor, shirtColor = "plain", sleeveColor, shirtStyle, shirtStyleColor, shirtStyleDirection, isBack = false, shirtWidth = 200, collarColor, sleeveCuffColor, shortsColor, image, imageHeight, imageWidth, imageX, imageY, withBadge, withShorts = true, }) {
38
+ export default function drawSoccerJersey({ shirtText, textColor, textOutlineColor, textBackgroundColor, shirtColor = "plain", sleeveColor, shirtStyle, shirtStyleColor, shirtStyleDirection, isBack = false, shirtWidth = 200, collarColor, sleeveCuffColor, shortsColor, shortsCuffColor, shortsStyle, shortsStyleColor, image, imageHeight, imageWidth, imageX, imageY, withBadge, withShorts = true, }) {
39
39
  // Colors and Color Optimizations
40
40
  const optimizedSleeveColor = lightenDarkenColor(sleeveColor, -10);
41
41
  const optimizedShirtColor = lightenDarkenColor(shirtColor, -10);
@@ -61,6 +61,9 @@ export default function drawSoccerJersey({ shirtText, textColor, textOutlineColo
61
61
  case "striped":
62
62
  shirtFill = drawStriped(page, optimizedShirtColor, shirtStyleColor ? shirtStyleColor : "#222", shirtStyleDirection || "vertical", "normal");
63
63
  break;
64
+ case "sideStriped":
65
+ shirtFill = drawShirtSideStriped(page, optimizedShirtColor, shirtStyleColor ? shirtStyleColor : "#222");
66
+ break;
64
67
  case "dashed":
65
68
  shirtFill = drawDashes(page, optimizedShirtColor, shirtStyleColor ? shirtStyleColor : "#222", shirtStyleDirection ? shirtStyleDirection : "vertical");
66
69
  break;
@@ -148,37 +151,49 @@ export default function drawSoccerJersey({ shirtText, textColor, textOutlineColo
148
151
  .fill(sleeveCuffColor)
149
152
  .stroke({ color: sleeveCuffColor, width: 3, linecap: "round" });
150
153
  }
151
- // text
152
- const optimizedFontSize = (20 / shirtText.length) * 3;
153
- const drawText = (elem) => elem
154
- .text(shirtText)
155
- .fill(lightenDarkenColor(textColor ? textColor : "#fff", -50))
156
- .font({
157
- family: "Monospace",
158
- size: optimizedFontSize > 30 ? 30 : optimizedFontSize,
159
- style: "bold",
160
- })
161
- .stroke({
162
- color: textOutlineColor
163
- ? textOutlineColor
164
- : lightenDarkenColor(textColor ? textColor : "#fff", 10),
165
- width: 0.5,
166
- })
167
- .center(50, 35);
168
- if (textBackgroundColor) {
169
- // eslint-disable-next-line new-cap
170
- const draftShirtTextElem = drawText(SVG());
171
- const dimens = draftShirtTextElem.bbox();
172
- page
173
- .rect(dimens.width + 4, dimens.height + 4)
174
- .fill(lightenDarkenColor(textBackgroundColor, 10))
154
+ if (shirtText) {
155
+ // text
156
+ const optimizedFontSize = (20 / shirtText.length) * 3;
157
+ const drawText = (elem) => elem
158
+ .text(shirtText)
159
+ .fill(lightenDarkenColor(textColor ? textColor : "#fff", -50))
160
+ .font({
161
+ family: "Monospace",
162
+ size: optimizedFontSize > 30 ? 30 : optimizedFontSize,
163
+ style: "bold",
164
+ })
165
+ .stroke({
166
+ color: textOutlineColor
167
+ ? textOutlineColor
168
+ : lightenDarkenColor(textColor ? textColor : "#fff", 10),
169
+ width: 0.5,
170
+ })
175
171
  .center(50, 35);
172
+ if (textBackgroundColor) {
173
+ // eslint-disable-next-line new-cap
174
+ const draftShirtTextElem = drawText(SVG());
175
+ const dimens = draftShirtTextElem.bbox();
176
+ page
177
+ .rect(dimens.width + 4, dimens.height + 4)
178
+ .fill(lightenDarkenColor(textBackgroundColor, 10))
179
+ .center(50, 35);
180
+ }
181
+ drawText(page);
176
182
  }
177
- drawText(page);
178
183
  const shortsHeight = withShorts ? 40 : 0;
179
184
  if (withShorts) {
180
185
  const pathShorts = `m 23 98 c 5 6, 50 6, 56 0 l 2 ${shortsHeight} c 0 5, -27 5, -27.5 0 l -2 -10, -2 10, c 0 5, -27 5, -27.5 0 l 1 -${shortsHeight}`;
181
- page.path(pathShorts).fill(shortsColor);
186
+ let shortsFill;
187
+ switch (shortsStyle) {
188
+ case "sideStriped": {
189
+ shortsFill = drawShortsSideStriped(page, shortsColor, shortsStyleColor || "red");
190
+ break;
191
+ }
192
+ default: {
193
+ shortsFill = shortsColor;
194
+ }
195
+ }
196
+ page.path(pathShorts).fill(shortsFill);
182
197
  page.path(pathShorts).fill(page
183
198
  .gradient("linear", function (add) {
184
199
  add.stop(0, "#000", 0.2);
@@ -187,6 +202,26 @@ export default function drawSoccerJersey({ shirtText, textColor, textOutlineColo
187
202
  })
188
203
  .from(1, 1)
189
204
  .to(1, 0));
205
+ if (shortsCuffColor) {
206
+ const pathShortsCuffLeft = `m 23 138 c 5 5, 22 5, 26.5 0`;
207
+ const pathShortsCuffRight = `m 54 138 c 5 5, 22 5, 26.5 0`;
208
+ page
209
+ .path(pathShortsCuffLeft)
210
+ .fill("none")
211
+ .stroke({
212
+ width: 3,
213
+ color: shortsCuffColor || "red",
214
+ linecap: "round",
215
+ });
216
+ page
217
+ .path(pathShortsCuffRight)
218
+ .fill("none")
219
+ .stroke({
220
+ width: 3,
221
+ color: shortsCuffColor || "red",
222
+ linecap: "round",
223
+ });
224
+ }
190
225
  }
191
226
  page.width(shirtWidth);
192
227
  // +10 is some extra room with the shorts height, so the total should be 150
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soccer-jersey-fork",
3
- "version": "1.0.44",
3
+ "version": "1.0.47",
4
4
  "description": "Generate soccer jerseys in SVG format",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {