soccer-jersey-fork 1.0.85 → 1.0.87

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.
@@ -4,16 +4,18 @@
4
4
  * Modifications Copyright 2025 Lau Kai Chung
5
5
  */
6
6
  import { Svg } from "@svgdotjs/svg.js";
7
- import { ShirtStyleDirection } from "../types";
8
- export declare const drawStriped: (page: Svg, primaryColor: string, secondaryColor: string, direction: ShirtStyleDirection, thickness?: "thin" | "thick" | "normal") => import("@svgdotjs/svg.js").Pattern;
9
- export declare const drawBigCheckered: (page: Svg, primaryColor: string, secondaryColor: string, direction?: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
10
- export declare const drawCheckered: (page: Svg, primaryColor: string, secondaryColor: string, size: "sm" | "lg", direction?: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
7
+ import { StyleDirection } from "../types";
8
+ export declare const drawStriped: (page: Svg, primaryColor: string, secondaryColor: string, direction: StyleDirection, thickness?: "thin" | "thick" | "normal") => import("@svgdotjs/svg.js").Pattern;
9
+ export declare const drawBigCheckered: (page: Svg, primaryColor: string, secondaryColor: string, direction?: StyleDirection) => import("@svgdotjs/svg.js").Pattern;
10
+ export declare const drawCheckered: (page: Svg, primaryColor: string, secondaryColor: string, size: "sm" | "lg", direction?: StyleDirection) => import("@svgdotjs/svg.js").Pattern;
11
11
  export declare const drawDiamonds: (page: Svg, primaryColor: string, secondaryColor: string) => import("@svgdotjs/svg.js").Pattern;
12
- export declare const drawTwoColors: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
13
- export declare const drawSingleBand: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
14
- export declare const drawSingleBandThin: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle?: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
15
- export declare const drawWaves: (page: Svg, primaryColor: string, secondaryColor: string, waveStyle: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
16
- export declare const drawDashes: (page: Svg, primaryColor: string, secondaryColor: string, dashDirection: ShirtStyleDirection) => import("@svgdotjs/svg.js").Pattern;
12
+ export declare const drawTwoColors: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle: StyleDirection) => import("@svgdotjs/svg.js").Pattern;
13
+ export declare const drawSleeveContrastingTwoColors: (page: Svg, primaryColor: string, secondaryColor: string) => import("@svgdotjs/svg.js").Pattern;
14
+ export declare const drawSleeveTwoColors: (page: Svg, primaryColor: string, secondaryColor: string) => import("@svgdotjs/svg.js").Pattern;
15
+ export declare const drawSingleBand: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle: StyleDirection) => import("@svgdotjs/svg.js").Pattern;
16
+ export declare const drawSingleBandThin: (page: Svg, primaryColor: string, secondaryColor: string, bandStyle?: StyleDirection) => import("@svgdotjs/svg.js").Pattern;
17
+ export declare const drawWaves: (page: Svg, primaryColor: string, secondaryColor: string, waveStyle: StyleDirection) => import("@svgdotjs/svg.js").Pattern;
18
+ export declare const drawDashes: (page: Svg, primaryColor: string, secondaryColor: string, dashDirection: StyleDirection) => import("@svgdotjs/svg.js").Pattern;
17
19
  export declare const addShortSideColor: (page: Svg, color: string) => void;
18
20
  export declare function addShoulderSideColor(page: Svg, color: string): void;
19
21
  export declare function addShirtSideColor(page: Svg, color: string): void;
@@ -164,6 +164,18 @@ export const drawTwoColors = (page, primaryColor, secondaryColor, bandStyle) =>
164
164
  });
165
165
  }
166
166
  };
167
+ export const drawSleeveContrastingTwoColors = (page, primaryColor, secondaryColor) => {
168
+ return page.pattern(100, 100, function (add) {
169
+ add.rect(100, 100).fill(primaryColor);
170
+ add.rect(50, 100).fill(secondaryColor);
171
+ });
172
+ };
173
+ export const drawSleeveTwoColors = (page, primaryColor, secondaryColor) => {
174
+ return page.pattern(29, 100, (add) => {
175
+ add.rect(29, 100).fill(primaryColor);
176
+ add.rect(18, 100).fill(secondaryColor).move(-4, 0);
177
+ });
178
+ };
167
179
  export const drawSingleBand = (page, primaryColor, secondaryColor, bandStyle) => {
168
180
  switch (bandStyle) {
169
181
  case "diagonalRight":
@@ -5,15 +5,15 @@
5
5
  */
6
6
  export interface DrawSoccerJerseyProps {
7
7
  shirtColor: string;
8
- sleeveColor: string;
9
8
  shirtSideColor?: string;
10
9
  shirtStyle: ShirtStyle;
11
10
  shirtStyleColor?: string;
11
+ sleeveColor: string;
12
12
  sleeveStyle?: SleeveStyle;
13
13
  sleeveStyleColor?: string;
14
- sleeveStyleDirection?: ShirtStyleDirection;
14
+ sleeveStyleDirection?: StyleDirection;
15
15
  shirtBottomColor?: string;
16
- shirtStyleDirection?: ShirtStyleDirection;
16
+ shirtStyleDirection?: StyleDirection;
17
17
  isBack?: boolean;
18
18
  shirtWidth?: number;
19
19
  collarType?: "round" | "folded";
@@ -42,6 +42,6 @@ export interface DrawSoccerJerseyProps {
42
42
  withBadge?: boolean;
43
43
  withShorts?: boolean;
44
44
  }
45
- export type ShirtStyleDirection = "diagonalRight" | "diagonalLeft" | "horizontal" | "vertical";
46
- export type ShirtStyle = "plain" | "twoColors" | "striped" | "stripedThin" | "stripedThick" | "waves" | "checkered" | "checkeredBig" | "diamonds" | "singleBandThin" | "singleBand" | "dashed" | "cross";
45
+ export type StyleDirection = "diagonalRight" | "diagonalLeft" | "horizontal" | "vertical";
46
+ export type ShirtStyle = "plain" | "twoColors" | "contrastingTwoColors" | "striped" | "stripedThin" | "stripedThick" | "waves" | "checkered" | "checkeredBig" | "diamonds" | "singleBandThin" | "singleBand" | "dashed" | "cross";
47
47
  export type SleeveStyle = ShirtStyle;
@@ -18,4 +18,4 @@ import { DrawSoccerJerseyProps } from "../types";
18
18
  * @return {string} A data URL ready for direct use as src attribute
19
19
  * on <img />
20
20
  */
21
- export default function drawSoccerJersey({ shirtColor, sleeveColor, shirtStyle, shirtStyleColor, shirtStyleDirection, isBack, shirtWidth, collarColor, collarType, shoulderSideColor, shirtSideColor, sleeveCuffColor, sleeveStyleColor, sleeveStyle, sleeveStyleDirection, shirtBottomColor, shortsColor, shortsCuffColor, shortsSideColor, images, withBadge, withShorts, texts, }: DrawSoccerJerseyProps): string;
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, withBadge, withShorts, isBack, }: 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 { drawSingleBand, drawCheckered, drawTwoColors, drawWaves, drawDashes, addShoulderSideColor, addShortSideColor, addShirtSideColor, drawSingleBandThin, drawDiamonds, drawCrossLines, drawStriped, } from "../patterns/patterns";
10
+ import { drawSingleBand, drawCheckered, drawTwoColors, drawWaves, drawDashes, addShoulderSideColor, addShortSideColor, addShirtSideColor, drawSingleBandThin, drawDiamonds, drawCrossLines, drawStriped, drawSleeveTwoColors, drawSleeveContrastingTwoColors, } from "../patterns/patterns";
11
11
  /**
12
12
  * @param {object} specs Specifications of the soccer jersey.
13
13
  * @param {string} specs.shirtColor The main color (HTML Color Code) of
@@ -27,7 +27,7 @@ import { drawSingleBand, drawCheckered, drawTwoColors, drawWaves, drawDashes, ad
27
27
  * @return {string} A data URL ready for direct use as src attribute
28
28
  * on <img />
29
29
  */
30
- export default function drawSoccerJersey({ shirtColor = "plain", sleeveColor = shirtColor, shirtStyle, shirtStyleColor, shirtStyleDirection, isBack = false, shirtWidth = 200, collarColor, collarType, shoulderSideColor, shirtSideColor, sleeveCuffColor, sleeveStyleColor, sleeveStyle, sleeveStyleDirection, shirtBottomColor, shortsColor, shortsCuffColor, shortsSideColor, images, withBadge, withShorts = true, texts, }) {
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, withBadge, withShorts = true, isBack = false, }) {
31
31
  // paths
32
32
  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
33
  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";
@@ -81,7 +81,7 @@ export default function drawSoccerJersey({ shirtColor = "plain", sleeveColor = s
81
81
  page.circle(8).fill(lightenDarkenColor(shirtColor, 60)).move(64, 25);
82
82
  }
83
83
  }
84
- const optimizedSleeveColor = lightenDarkenColor(sleeveColor, -10);
84
+ const optimizedSleeveColor = lightenDarkenColor(sleeveColor, -5);
85
85
  sleeveStyleColor = sleeveStyleColor || "#eee";
86
86
  sleeveStyleDirection = sleeveStyleDirection || "vertical";
87
87
  const sleeveFill = getPatternFill(page, optimizedSleeveColor, sleeveStyle, sleeveStyleColor, "sleeve", sleeveStyleDirection);
@@ -195,30 +195,38 @@ export default function drawSoccerJersey({ shirtColor = "plain", sleeveColor = s
195
195
  page.viewbox(`0 0 102 ${100 + (withShorts ? shortsHeight + 10 : 0)}`);
196
196
  return page.svg();
197
197
  }
198
- function getPatternFill(page, baseColor, style, styleColor, type, styleDirection = "vertical") {
198
+ function getPatternFill(page, baseColor, style, styleColor, type, direction = "vertical") {
199
199
  switch (style) {
200
- case "twoColors":
201
- return drawTwoColors(page, baseColor, styleColor, styleDirection);
200
+ case "twoColors": {
201
+ if (type === "sleeve") {
202
+ return drawSleeveTwoColors(page, baseColor, styleColor);
203
+ }
204
+ else {
205
+ return drawTwoColors(page, baseColor, styleColor, direction);
206
+ }
207
+ }
208
+ case "contrastingTwoColors":
209
+ return drawSleeveContrastingTwoColors(page, baseColor, styleColor);
202
210
  case "stripedThin":
203
- return drawStriped(page, baseColor, styleColor, styleDirection, "thin");
211
+ return drawStriped(page, baseColor, styleColor, direction, "thin");
204
212
  case "stripedThick":
205
- return drawStriped(page, baseColor, styleColor, styleDirection, "thick");
213
+ return drawStriped(page, baseColor, styleColor, direction, "thick");
206
214
  case "striped":
207
- return drawStriped(page, baseColor, styleColor, styleDirection, "normal");
215
+ return drawStriped(page, baseColor, styleColor, direction, "normal");
208
216
  case "dashed":
209
- return drawDashes(page, baseColor, styleColor, styleDirection);
217
+ return drawDashes(page, baseColor, styleColor, direction);
210
218
  case "checkered":
211
- return drawCheckered(page, baseColor, styleColor, "sm", styleDirection);
219
+ return drawCheckered(page, baseColor, styleColor, "sm", direction);
212
220
  case "checkeredBig":
213
- return drawCheckered(page, baseColor, styleColor, "lg", styleDirection);
221
+ return drawCheckered(page, baseColor, styleColor, "lg", direction);
214
222
  case "diamonds":
215
223
  return drawDiamonds(page, baseColor, styleColor);
216
224
  case "singleBand":
217
- return drawSingleBand(page, baseColor, styleColor, styleDirection);
225
+ return drawSingleBand(page, baseColor, styleColor, direction);
218
226
  case "singleBandThin":
219
- return drawSingleBandThin(page, baseColor, styleColor, styleDirection);
227
+ return drawSingleBandThin(page, baseColor, styleColor, direction);
220
228
  case "waves":
221
- return drawWaves(page, baseColor, styleColor, styleDirection);
229
+ return drawWaves(page, baseColor, styleColor, direction);
222
230
  case "cross":
223
231
  return drawCrossLines(page, baseColor, styleColor);
224
232
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soccer-jersey-fork",
3
- "version": "1.0.85",
3
+ "version": "1.0.87",
4
4
  "description": "Generate soccer jerseys in SVG format",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -14,17 +14,6 @@
14
14
  "storybook": "storybook dev -p 6006",
15
15
  "build-storybook": "storybook build"
16
16
  },
17
- "keywords": [
18
- "soccer",
19
- "shirt",
20
- "svg",
21
- "fpl"
22
- ],
23
- "author": "nadchif (https://github.com/nadchif)",
24
- "repository": {
25
- "type": "git",
26
- "url": "https://github.com/nadchif/soccer-jersey.git"
27
- },
28
17
  "license": "MIT",
29
18
  "files": [
30
19
  "lib",
package/README.md DELETED
@@ -1,146 +0,0 @@
1
- # Soccer-Jersey
2
-
3
- Generate Soccer Jersey SVG images. Generates Data URIs that can be used directly as image src.
4
-
5
- ## Pros & pros
6
- Save network data, by dynamically generating soccer jersey assets suited for each player. Great for large projects where you would want to customize Soccer Jersey for each player.
7
-
8
- ## Install
9
-
10
- ```
11
- npm i soccer-jersey
12
- ```
13
-
14
- ## Live Demos
15
- [View live demos & examples](https://nadchif.github.io/soccer-jersey/)
16
-
17
- ## Usage
18
-
19
- ### API
20
- ```
21
- SoccerJersey.draw({
22
- shirtText: <string>,
23
- textColor: <string>,
24
- textOutlineColor?: <string>,
25
- textBackgroundColor?: <string>,
26
- shirtColor: <string>,
27
- sleeveColor: <string>,
28
- shirtStyle: <'plain' | 'two-color' | 'striped' | 'striped-thin' | 'striped-thick' | 'waves'
29
- | 'checkered' | 'hoops' | 'single-band' | 'dashed'>,
30
- shirtStyleColor?: <string>,
31
- shirtStyleDirection?: <'diagonal-right' | 'diagonal-left' | 'horizontal' | 'vertical'>,
32
- isBack?: <boolean>,
33
- },
34
- encodeToDataUri?: boolean): string
35
- ```
36
-
37
-
38
- ### React
39
-
40
- ```
41
- import SoccerJersey from "soccer-jersey";
42
-
43
- const TeamPage = () => {
44
-
45
- const jerseyImgSrc = SoccerJersey.draw({
46
- shirtText: "ARS",
47
- shirtColor: "#f00000",
48
- sleeveColor: "#fff",
49
- shirtStyle: "checkered",
50
- shirtStyleColor: "#dc0001",
51
- textColor: "#fff",
52
- }); // data:image/svg+xml;base64,......
53
-
54
- ...
55
-
56
- return (
57
- <div>
58
- <h1>ARS</h1>
59
- <img src={jerseyImgSrc} />
60
- </div>
61
- );
62
- }
63
- ```
64
-
65
- ### Vanilla
66
- ```
67
-
68
- <div>
69
- <h1>BHA</h1>
70
- <img id="jerseyImg" />
71
- <div>
72
-
73
- ...
74
-
75
- <script "dist/soccer-jersey.min.js"></script>
76
- <script>
77
- var jerseyImgSrc = SoccerJersey.draw({
78
- shirtText: "BHA",
79
- shirtColor: "#026fd0",
80
- sleeveColor: "#026fd0",
81
- shirtStyle: "striped-thin",
82
- shirtStyleColor: "#fff",
83
- textColor: "#fff",
84
- }); // data:image/svg+xml;base64,......
85
- var imgNode = document.getElementById("jerseyImg");
86
- imgNode.setAttribute('src', jerseyImgSrc);
87
- </script>
88
- </body>
89
- ```
90
-
91
-
92
- ### Angular
93
-
94
- Create "safe" pipe to allow dynamic Data URIs.
95
- ```
96
- // safe-html.pipe.ts
97
-
98
- import { Pipe, PipeTransform } from '@angular/core';
99
- import { DomSanitizer, SafeHtml} from '@angular/platform-browser';
100
-
101
- @Pipe({ name: 'safe' })
102
-
103
- export class SafeHtmlPipe implements PipeTransform {
104
- constructor(private sanitizer: DomSanitizer) {}
105
- transform(url): SafeHtml {
106
- return this.sanitizer.bypassSecurityTrustResourceUrl(url);
107
- }
108
- }
109
- ```
110
- Add Pipe to Declerations
111
-
112
- ```
113
- import { SafeHtmlPipe } from './safe-html.pipe';
114
-
115
- ...
116
-
117
- @NgModule({
118
- declarations: [
119
- ...
120
- SafeHtmlPipe,
121
- ]
122
- })
123
- ```
124
- Use in components
125
- ```
126
- @Component({
127
- ...
128
- template: `
129
- <div>
130
- <h1>MCI</h1>
131
- <img [src]="jerseyImgSrc | safe">
132
- </div>
133
- `,
134
- ...
135
- })
136
- export class AppComponent {
137
- ...
138
- jerseyImgSrc = SoccerJersey.draw({
139
- shirtText: 'MCI',
140
- shirtColor: '#98c5e9',
141
- sleeveColor: '#98c5e9',
142
- shirtStyle: 'plain',
143
- textColor: '#00285e',
144
- });
145
- }
146
- ```