soccer-jersey-fork 1.0.43 → 1.0.45

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,18 @@
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 drawCheckered: (page: Svg, primaryColor: string, secondaryColor: string) => import("@svgdotjs/svg.js").Pattern;
13
+ export declare const drawHoops: (page: Svg, primaryColor: string, secondaryColor: string) => import("@svgdotjs/svg.js").Pattern;
14
+ export declare const drawTwoColors: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
15
+ export declare const drawSingleBand: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
16
+ export declare const drawWaves: (page: Svg, primaryColor: string, secondaryColor: string, waveStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
17
+ export declare const drawDashes: (page: Svg, primaryColor: string, secondaryColor: string, dashDirection: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
18
+ export declare const drawShortsSideStriped: (page: Svg, color: string) => Svg;
@@ -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,7 @@ 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 drawCheckered = (page, primaryColor, secondaryColor) => page.pattern(20, 20, function (add) {
73
73
  add.rect(20, 20).fill(primaryColor);
74
74
  add.rect(10, 10).fill(secondaryColor ? secondaryColor : "#eee");
75
75
  add
@@ -77,11 +77,11 @@ const drawCheckered = (page, primaryColor, secondaryColor) => page.pattern(20, 2
77
77
  .fill(secondaryColor ? secondaryColor : "#eee")
78
78
  .move(10, 10);
79
79
  });
80
- const drawHoops = (page, primaryColor, secondaryColor) => page.pattern(20, 20, function (add) {
80
+ export const drawHoops = (page, primaryColor, secondaryColor) => page.pattern(20, 20, function (add) {
81
81
  add.rect(20, 20).fill(primaryColor);
82
82
  add.rect(20, 10).fill(secondaryColor ? secondaryColor : "#eee");
83
83
  });
84
- const drawTwoColors = (page, primaryColor, secondaryColor, bandStyle) => {
84
+ export const drawTwoColors = (page, primaryColor, secondaryColor, bandStyle) => {
85
85
  switch (bandStyle) {
86
86
  case "diagonalRight":
87
87
  return page.pattern(100, 100, function (add) {
@@ -124,7 +124,7 @@ const drawTwoColors = (page, primaryColor, secondaryColor, bandStyle) => {
124
124
  });
125
125
  }
126
126
  };
127
- const drawSingleBand = (page, primaryColor, secondaryColor, bandStyle) => {
127
+ export const drawSingleBand = (page, primaryColor, secondaryColor, bandStyle) => {
128
128
  switch (bandStyle) {
129
129
  case "diagonalRight":
130
130
  return page.pattern(100, 100, function (add) {
@@ -167,7 +167,7 @@ const drawSingleBand = (page, primaryColor, secondaryColor, bandStyle) => {
167
167
  });
168
168
  }
169
169
  };
170
- const drawWaves = (page, primaryColor, secondaryColor, waveStyle) => {
170
+ export const drawWaves = (page, primaryColor, secondaryColor, waveStyle) => {
171
171
  switch (waveStyle) {
172
172
  case "horizontal":
173
173
  return page.pattern(20, 12, function (add) {
@@ -199,7 +199,7 @@ const drawWaves = (page, primaryColor, secondaryColor, waveStyle) => {
199
199
  });
200
200
  }
201
201
  };
202
- const drawDashes = (page, primaryColor, secondaryColor, dashDirection) => {
202
+ export const drawDashes = (page, primaryColor, secondaryColor, dashDirection) => {
203
203
  switch (dashDirection) {
204
204
  case "diagonalLeft":
205
205
  return page.pattern(10, 10, function (add) {
@@ -239,4 +239,10 @@ const drawDashes = (page, primaryColor, secondaryColor, dashDirection) => {
239
239
  });
240
240
  }
241
241
  };
242
- export { drawStriped, drawHoops, drawSingleBand, drawCheckered, drawTwoColors, drawWaves, drawDashes, };
242
+ export const drawShortsSideStriped = (page, color) => {
243
+ const shortsStripedLeft = `m 26 101 q 1 2 -1 38`;
244
+ const shortsStripedRight = `m 77 101 q -1 2 1 38`;
245
+ page.path(shortsStripedLeft).stroke({ width: 2, color, linecap: "square" });
246
+ page.path(shortsStripedRight).stroke({ width: 2, color, linecap: "square" });
247
+ return page;
248
+ };
@@ -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>;
@@ -17,6 +17,8 @@ export const Default = {
17
17
  sleeveCuffColor: "yellow",
18
18
  shortsColor: "black",
19
19
  image: "https://resources.simcups.com/flags/w80/264.png",
20
+ shortsStyle: "sideStriped",
21
+ shortsCuffColor: "#6e6dd2",
20
22
  },
21
23
  };
22
24
  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
33
  export type ShirtStyle = "plain" | "twoColors" | "striped" | "stripedThin" | "stripedThick" | "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, } 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);
@@ -148,33 +148,35 @@ export default function drawSoccerJersey({ shirtText, textColor, textOutlineColo
148
148
  .fill(sleeveCuffColor)
149
149
  .stroke({ color: sleeveCuffColor, width: 3, linecap: "round" });
150
150
  }
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))
151
+ if (shirtText) {
152
+ // text
153
+ const optimizedFontSize = (20 / shirtText.length) * 3;
154
+ const drawText = (elem) => elem
155
+ .text(shirtText)
156
+ .fill(lightenDarkenColor(textColor ? textColor : "#fff", -50))
157
+ .font({
158
+ family: "Monospace",
159
+ size: optimizedFontSize > 30 ? 30 : optimizedFontSize,
160
+ style: "bold",
161
+ })
162
+ .stroke({
163
+ color: textOutlineColor
164
+ ? textOutlineColor
165
+ : lightenDarkenColor(textColor ? textColor : "#fff", 10),
166
+ width: 0.5,
167
+ })
175
168
  .center(50, 35);
169
+ if (textBackgroundColor) {
170
+ // eslint-disable-next-line new-cap
171
+ const draftShirtTextElem = drawText(SVG());
172
+ const dimens = draftShirtTextElem.bbox();
173
+ page
174
+ .rect(dimens.width + 4, dimens.height + 4)
175
+ .fill(lightenDarkenColor(textBackgroundColor, 10))
176
+ .center(50, 35);
177
+ }
178
+ drawText(page);
176
179
  }
177
- drawText(page);
178
180
  const shortsHeight = withShorts ? 40 : 0;
179
181
  if (withShorts) {
180
182
  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}`;
@@ -187,6 +189,31 @@ export default function drawSoccerJersey({ shirtText, textColor, textOutlineColo
187
189
  })
188
190
  .from(1, 1)
189
191
  .to(1, 0));
192
+ switch (shortsStyle) {
193
+ case "sideStriped": {
194
+ drawShortsSideStriped(page, shortsStyleColor || "red");
195
+ }
196
+ }
197
+ if (shortsCuffColor) {
198
+ const pathShortsCuffLeft = `m 23 138 c 5 5, 22 5, 26.5 0`;
199
+ const pathShortsCuffRight = `m 54 138 c 5 5, 22 5, 26.5 0`;
200
+ page
201
+ .path(pathShortsCuffLeft)
202
+ .fill("none")
203
+ .stroke({
204
+ width: 3,
205
+ color: shortsCuffColor || "red",
206
+ linecap: "round",
207
+ });
208
+ page
209
+ .path(pathShortsCuffRight)
210
+ .fill("none")
211
+ .stroke({
212
+ width: 3,
213
+ color: shortsCuffColor || "red",
214
+ linecap: "round",
215
+ });
216
+ }
190
217
  }
191
218
  page.width(shirtWidth);
192
219
  // +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.43",
3
+ "version": "1.0.45",
4
4
  "description": "Generate soccer jerseys in SVG format",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {