soccer-jersey-fork 1.0.100 → 1.0.102

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.
@@ -328,12 +328,12 @@ export const addShortSideColor = (page, color) => {
328
328
  export function addShoulderSideColor(page, color) {
329
329
  // left
330
330
  page
331
- .path(`m 0 35, l 16.5 -26, 20 -8`)
331
+ .path(`m 0 35, l 16.5 -26, 20 -8.5`)
332
332
  .fill("none")
333
333
  .stroke({ width: 2, color, linecap: "butt" });
334
334
  // right
335
335
  page
336
- .path(`m 101 35 l -16.5 -26, -21 -8`)
336
+ .path(`m 101 35 l -16.5 -26, -21 -8.5`)
337
337
  .fill("none")
338
338
  .stroke({ width: 2, color, linecap: "butt" });
339
339
  }
@@ -14,9 +14,8 @@ export interface DrawSoccerJerseyProps {
14
14
  sleeveStyleDirection?: StyleDirection;
15
15
  shirtBottomColor?: string;
16
16
  shirtStyleDirection?: StyleDirection;
17
- isBack?: boolean;
18
17
  shirtWidth?: number;
19
- collarType?: "round" | "folded";
18
+ collarType?: "round" | "polo" | "classic";
20
19
  collarColor?: string;
21
20
  sleeveCuffColor?: string;
22
21
  texts: {
@@ -40,7 +39,9 @@ export interface DrawSoccerJerseyProps {
40
39
  shortsSideColor?: string;
41
40
  shortsCuffColor?: string;
42
41
  shoulderSideColor?: string;
43
- withShorts?: boolean;
42
+ shortsStyle?: ShirtStyle;
43
+ shortsStyleColor?: string;
44
+ shortsStyleDirection?: StyleDirection;
44
45
  }
45
46
  export type StyleDirection = "diagonalRight" | "diagonalLeft" | "horizontal" | "vertical" | "offsetLeftVertical" | "offsetRightVertical";
46
47
  export type ShirtStyle = "plain" | "twoColors" | "contrastingTwoColors" | "concentricCircles" | "striped" | "stripedThin" | "stripedThick" | "waves" | "checkered" | "checkeredBig" | "diamonds" | "singleBandThin" | "singleBand" | "dashed" | "cross" | "crisscross";
@@ -1,21 +1,2 @@
1
1
  import { DrawSoccerJerseyProps } from "../types";
2
- /**
3
- * @param {object} specs Specifications of the soccer jersey.
4
- * @param {string} specs.shirtColor The main color (HTML Color Code) of
5
- * the shirt.
6
- * @param {string} specs.sleeveColor The color (HTML Color Code) of the shirt
7
- * sleeves;
8
- * @param {string} specs.shirtStyle The Style of the shirt (torso region).
9
- * Supports "plain", "two-color", "striped", "striped-thin","striped-thick","checkered",
10
- * "hoops","single-band", "waves", "dashed";
11
- * @param {string} specs.shirtStyleColor The color (HTML Color Code) of
12
- * used for the shirt style.
13
- * @param {string} specs.shirtStyleDirection The style of the single band.
14
- * Required when using the "single-band" shirt style. Supports
15
- * "diagonalRight", "diagonalLeft","horizontal", "vertical"
16
- * @param {boolean} specs.isBack Set to true to draw the shirt from the
17
- * back (different neck shape, no badges). Defaults to false.
18
- * @return {string} A data URL ready for direct use as src attribute
19
- * on <img />
20
- */
21
- export default function drawSoccerJersey({ shirtColor, shirtStyle, shirtStyleColor, shirtStyleDirection, shirtWidth, shoulderSideColor, shirtSideColor, shirtBottomColor, sleeveColor, sleeveCuffColor, sleeveStyleColor, sleeveStyle, sleeveStyleDirection, collarColor, collarType, shortsColor, shortsCuffColor, shortsSideColor, images, texts, withShorts, isBack, }: DrawSoccerJerseyProps): string;
2
+ export default function drawSoccerJersey({ shirtColor, shirtStyle, shirtStyleColor, shirtStyleDirection, shirtWidth, shoulderSideColor, shirtSideColor, shirtBottomColor, sleeveColor, sleeveCuffColor, sleeveStyleColor, sleeveStyle, sleeveStyleDirection, collarColor, collarType, shortsColor, shortsCuffColor, shortsSideColor, images, texts, shortsStyle, shortsStyleDirection, shortsStyleColor, }: DrawSoccerJerseyProps): string;
@@ -8,26 +8,7 @@
8
8
  import { SVG } from "@svgdotjs/svg.js";
9
9
  import lightenDarkenColor from "./lighten-darken-color";
10
10
  import { addShirtSideColor, addShortSideColor, addShoulderSideColor, drawCheckered, drawConcentricCircles, drawCrisscross, drawCrossLines, drawDashes, drawDiamonds, drawSingleBand, drawSingleBandThin, drawSleeveContrastingTwoColors, drawSleeveTwoColors, drawStriped, drawTwoColors, drawWaves, } from "../patterns/patterns";
11
- /**
12
- * @param {object} specs Specifications of the soccer jersey.
13
- * @param {string} specs.shirtColor The main color (HTML Color Code) of
14
- * the shirt.
15
- * @param {string} specs.sleeveColor The color (HTML Color Code) of the shirt
16
- * sleeves;
17
- * @param {string} specs.shirtStyle The Style of the shirt (torso region).
18
- * Supports "plain", "two-color", "striped", "striped-thin","striped-thick","checkered",
19
- * "hoops","single-band", "waves", "dashed";
20
- * @param {string} specs.shirtStyleColor The color (HTML Color Code) of
21
- * used for the shirt style.
22
- * @param {string} specs.shirtStyleDirection The style of the single band.
23
- * Required when using the "single-band" shirt style. Supports
24
- * "diagonalRight", "diagonalLeft","horizontal", "vertical"
25
- * @param {boolean} specs.isBack Set to true to draw the shirt from the
26
- * back (different neck shape, no badges). Defaults to false.
27
- * @return {string} A data URL ready for direct use as src attribute
28
- * on <img />
29
- */
30
- export default function drawSoccerJersey({ shirtColor = "plain", shirtStyle, shirtStyleColor, shirtStyleDirection, shirtWidth = 200, shoulderSideColor, shirtSideColor, shirtBottomColor, sleeveColor = shirtColor, sleeveCuffColor, sleeveStyleColor, sleeveStyle, sleeveStyleDirection, collarColor, collarType, shortsColor, shortsCuffColor, shortsSideColor, images, texts, withShorts = true, isBack = false, }) {
11
+ export default function drawSoccerJersey({ shirtColor = "plain", shirtStyle, shirtStyleColor, shirtStyleDirection, shirtWidth = 200, shoulderSideColor, shirtSideColor, shirtBottomColor, sleeveColor = shirtColor, sleeveCuffColor, sleeveStyleColor, sleeveStyle, sleeveStyleDirection, collarColor, collarType, shortsColor, shortsCuffColor, shortsSideColor, images, texts, shortsStyle, shortsStyleDirection, shortsStyleColor, }) {
31
12
  // paths
32
13
  const pathLeftSleeve = "m18 8.5c-4 3-6.1 7.7-8.9 12-3.1 4.9-6 9.9-8.8 15 6 4 12 8.2 19 10 4.1.38 4.3-5.3 3.8-8.2-.29-9.7-3-19-5-29z";
33
14
  const pathRightSleeve = "m83 8.1c4 3 6.1 7.7 8.9 12 3.1 4.9 6 9.9 8.8 15-6 4-12 8.2-19 10-4.1.38-4.3-5.3-3.8-8.2.3-9.7 3-19 5-29z";
@@ -39,9 +20,7 @@ export default function drawSoccerJersey({ shirtColor = "plain", shirtStyle, shi
39
20
  shirtStyleColor = shirtStyleColor || "#eee";
40
21
  let shirtFill = getPatternFill(page, shirtColor, shirtStyle, shirtStyleColor, "shirt", shirtStyleDirection);
41
22
  // neck
42
- page
43
- .path(isBack ? pathNeckBack : pathNeck)
44
- .fill(lightenDarkenColor(shirtColor, -50));
23
+ page.path(pathNeck).fill(lightenDarkenColor(shirtColor, -50));
45
24
  // shirt
46
25
  page.path(pathMainBody).fill(shirtFill);
47
26
  page.path(pathMainBody).fill(page
@@ -52,29 +31,37 @@ export default function drawSoccerJersey({ shirtColor = "plain", shirtStyle, shi
52
31
  })
53
32
  .from(1, 1)
54
33
  .to(1, 0));
55
- if (!isBack) {
56
- switch (collarType) {
57
- case "folded": {
34
+ switch (collarType) {
35
+ case "polo": {
36
+ page
37
+ /**
38
+ * The points start from the left then spread out to the leftest
39
+ */
40
+ .path("m36.5 0.5 l -6 5 15 9 l 3 -5 3 0 3 5 15 -9 -6 -5 c -10 10 -25 5 -27.5 0")
41
+ .fill(collarColor || "#eee")
42
+ .stroke({
43
+ color: collarColor,
44
+ width: 1,
45
+ });
46
+ break;
47
+ }
48
+ case "classic": {
49
+ page
50
+ .path("m36 0 l-6 10 q5-6 22 0 z m29 0 l6 10 q-5-6-22 0 z")
51
+ .fill(collarColor || "#eee")
52
+ .stroke({
53
+ color: collarColor,
54
+ width: 1,
55
+ });
56
+ break;
57
+ }
58
+ default: {
59
+ if (collarColor) {
60
+ const pathCollar = "m35 0 q 17 20 30 0";
58
61
  page
59
- /**
60
- * The points start from the left then spread out to the leftest
61
- */
62
- .path("m36.5 0.5 l -6 5 15 9 l 3 -5 3 0 3 5 15 -9 -6 -5 c -10 10 -25 5 -27.5 0")
63
- .fill(collarColor || "#eee")
64
- .stroke({
65
- color: collarColor,
66
- width: 1,
67
- });
68
- break;
69
- }
70
- default: {
71
- if (collarColor) {
72
- const pathCollar = "m35 0 q 17 20 30 0";
73
- page
74
- .path(pathCollar)
75
- .fill("none")
76
- .stroke({ color: collarColor, width: 2 });
77
- }
62
+ .path(pathCollar)
63
+ .fill("none")
64
+ .stroke({ color: collarColor, width: 2 });
78
65
  }
79
66
  }
80
67
  }
@@ -110,44 +97,49 @@ export default function drawSoccerJersey({ shirtColor = "plain", shirtStyle, shi
110
97
  .fill("none")
111
98
  .stroke({ color: shirtBottomColor, width: 3, linecap: "round" });
112
99
  }
113
- const shortsHeight = withShorts ? 40 : 0;
114
- if (withShorts) {
115
- 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}`;
116
- page.path(pathShorts).fill(shortsColor).stroke({
117
- width: 1,
118
- color: shortsColor,
100
+ const SHORT_HEIGHT = 40;
101
+ const pathShorts = `m 23 98 c 5 6, 50 6, 56 0 l 2 ${SHORT_HEIGHT} c 0 5, -27 5, -27.5 0 l -2 -10, -2 10, c 0 5, -27 5, -27.5 0 l 1 -${SHORT_HEIGHT}`;
102
+ // page.path(pathShorts).fill(shortsColor).stroke({
103
+ // width: 1,
104
+ // color: shortsColor,
105
+ // });
106
+ const shortsFill = getPatternFill(page, shortsColor, shortsStyle, shortsStyleColor || shortsColor, "shorts", shortsStyleDirection);
107
+ page.path(pathShorts).fill(shortsFill).stroke({
108
+ width: 1,
109
+ color: shortsColor,
110
+ });
111
+ // page.path(pathShorts).fill(
112
+ // page
113
+ // .gradient("linear", function (add) {
114
+ // add.stop(0, "#000", 0.2);
115
+ // add.stop(0.44, "#ddd", 0.1);
116
+ // add.stop(1, "#fff", 0.1);
117
+ // })
118
+ // .from(1, 1)
119
+ // .to(1, 0),
120
+ // );
121
+ if (shortsSideColor) {
122
+ addShortSideColor(page, shortsSideColor);
123
+ }
124
+ if (shortsCuffColor) {
125
+ const pathShortsCuffLeft = `m 23 138 c 5 5, 22 5, 26.5 0`;
126
+ const pathShortsCuffRight = `m 54 138 c 5 5, 22 5, 26.5 0`;
127
+ page
128
+ .path(pathShortsCuffLeft)
129
+ .fill("none")
130
+ .stroke({
131
+ width: 3,
132
+ color: shortsCuffColor || "red",
133
+ linecap: "round",
134
+ });
135
+ page
136
+ .path(pathShortsCuffRight)
137
+ .fill("none")
138
+ .stroke({
139
+ width: 3,
140
+ color: shortsCuffColor || "red",
141
+ linecap: "round",
119
142
  });
120
- page.path(pathShorts).fill(page
121
- .gradient("linear", function (add) {
122
- add.stop(0, "#000", 0.2);
123
- add.stop(0.44, "#ddd", 0.1);
124
- add.stop(1, "#fff", 0.1);
125
- })
126
- .from(1, 1)
127
- .to(1, 0));
128
- if (shortsSideColor) {
129
- addShortSideColor(page, shortsSideColor);
130
- }
131
- if (shortsCuffColor) {
132
- const pathShortsCuffLeft = `m 23 138 c 5 5, 22 5, 26.5 0`;
133
- const pathShortsCuffRight = `m 54 138 c 5 5, 22 5, 26.5 0`;
134
- page
135
- .path(pathShortsCuffLeft)
136
- .fill("none")
137
- .stroke({
138
- width: 3,
139
- color: shortsCuffColor || "red",
140
- linecap: "round",
141
- });
142
- page
143
- .path(pathShortsCuffRight)
144
- .fill("none")
145
- .stroke({
146
- width: 3,
147
- color: shortsCuffColor || "red",
148
- linecap: "round",
149
- });
150
- }
151
143
  }
152
144
  if (images && images.length > 0) {
153
145
  for (const { src, width = 20, height = 20, x = 45, y = 45 } of images) {
@@ -196,7 +188,7 @@ export default function drawSoccerJersey({ shirtColor = "plain", shirtStyle, shi
196
188
  }
197
189
  page.width(shirtWidth);
198
190
  // +10 is some extra room with the shorts height, so the total should be 150
199
- page.viewbox(`0 0 102 ${100 + (withShorts ? shortsHeight + 10 : 0)}`);
191
+ page.viewbox(`0 0 102 ${100 + (SHORT_HEIGHT + 10)}`);
200
192
  return page.svg();
201
193
  }
202
194
  function getPatternFill(page, baseColor, style, styleColor, type, direction = "vertical") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soccer-jersey-fork",
3
- "version": "1.0.100",
3
+ "version": "1.0.102",
4
4
  "description": "Generate soccer jerseys in SVG format",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {