@avatar-generator/style-portraits 0.0.0-stage → 0.0.1
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.
- package/LICENSE +21 -0
- package/README.md +44 -2
- package/dist/index.cjs +321 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +77 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +300 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Hugo García Benjumea
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @avatar-generator/style-portraits
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Portraits avatar style for [`@avatar-generator/core`](https://www.npmjs.com/package/@avatar-generator/core).
|
|
4
|
+
Calm, single-colour head-and-shoulders portraits for business and professional tools.
|
|
5
|
+
Everything is drawn in one ink that reads on the background, so contrast is guaranteed.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @avatar-generator/core @avatar-generator/style-portraits
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createAvatar } from "@avatar-generator/core";
|
|
17
|
+
import { portraits } from "@avatar-generator/style-portraits";
|
|
18
|
+
|
|
19
|
+
const avatar = createAvatar(portraits, {
|
|
20
|
+
seed: "john.doe@example.com",
|
|
21
|
+
size: 64,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
img.src = avatar.toDataUri();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Options:
|
|
28
|
+
|
|
29
|
+
- `hairStyle`: `"crop"`, `"side-part"`, `"curly"`, `"afro"`, `"long"`, `"bob"`, `"bun"`, `"locs"` or `"bald"`
|
|
30
|
+
- `eyeStyle`: `"dots"`, `"lidded"`, `"smiling"` or `"lashes"`
|
|
31
|
+
- `mouthStyle`: `"smile"`, `"grin"`, `"soft"` or `"smirk"`
|
|
32
|
+
- `glasses`, `facialHair`: `true` or `false`
|
|
33
|
+
- `ink`: the one colour everything is drawn in
|
|
34
|
+
|
|
35
|
+
Options left unset are chosen deterministically from the seed. See the
|
|
36
|
+
[API reference](https://avatar-generator.hugoogb.dev/reference/avatar/) for every option this style accepts,
|
|
37
|
+
or the [configurator](https://avatar-generator.hugoogb.dev/reference/configurator/) to try them interactively.
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
Full documentation: [avatar-generator.hugoogb.dev](https://avatar-generator.hugoogb.dev)
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT © [Hugo García Benjumea](https://github.com/hugoogb)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
EYE_STYLES: () => EYE_STYLES,
|
|
24
|
+
HAIR_STYLES: () => HAIR_STYLES,
|
|
25
|
+
MOUTH_STYLES: () => MOUTH_STYLES,
|
|
26
|
+
default: () => index_default,
|
|
27
|
+
portraits: () => portraits
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
var import_core = require("@avatar-generator/core");
|
|
31
|
+
var HAIR_STYLES = [
|
|
32
|
+
"crop",
|
|
33
|
+
"side-part",
|
|
34
|
+
"curly",
|
|
35
|
+
"afro",
|
|
36
|
+
"long",
|
|
37
|
+
"bob",
|
|
38
|
+
"bun",
|
|
39
|
+
"locs",
|
|
40
|
+
"bald"
|
|
41
|
+
];
|
|
42
|
+
var EYE_STYLES = ["dots", "lidded", "smiling", "lashes"];
|
|
43
|
+
var MOUTH_STYLES = ["smile", "grin", "soft", "smirk"];
|
|
44
|
+
var CLOTHING = ["crew", "v-neck", "collar", "turtleneck"];
|
|
45
|
+
var BROWS = ["straight", "arched", "soft"];
|
|
46
|
+
var NOSES = ["hook", "button", "angle"];
|
|
47
|
+
var BEARDS = ["full", "moustache", "goatee"];
|
|
48
|
+
var CANVAS = 64;
|
|
49
|
+
var CX = 32;
|
|
50
|
+
var EYE_X = 26.6;
|
|
51
|
+
var EYE_Y = 29;
|
|
52
|
+
var LINE = 2.4;
|
|
53
|
+
var LENS_X = 27.2;
|
|
54
|
+
var LENS_Y = 28.4;
|
|
55
|
+
var FACE = "M 32 13 C 39.6 13 44 18.4 44 26.5 C 44 35.5 38.6 44 32 44 C 25.4 44 20 35.5 20 26.5 C 20 18.4 24.4 13 32 13 Z";
|
|
56
|
+
var FACE_HOLE = "M 32 13 C 24.4 13 20 18.4 20 26.5 C 20 35.5 25.4 44 32 44 C 38.6 44 44 35.5 44 26.5 C 44 18.4 39.6 13 32 13 Z";
|
|
57
|
+
var round = (value) => Math.round(value * 100) / 100;
|
|
58
|
+
var mirrored = (markup) => `<g transform="matrix(-1 0 0 1 ${CANVAS} 0)">${markup}</g>`;
|
|
59
|
+
var pair = (markup) => markup + mirrored(markup);
|
|
60
|
+
var stroke = (d, ink, width = LINE) => `<path d="${d}" fill="none" stroke="${ink}" stroke-width="${width}" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
61
|
+
var fill = (d, ink, rule = false) => `<path d="${d}" fill="${ink}"${rule ? ' fill-rule="evenodd"' : ""}/>`;
|
|
62
|
+
function scallop(cx, cy, radius, from, to, bumps) {
|
|
63
|
+
const point = (degrees) => {
|
|
64
|
+
const angle = degrees * Math.PI / 180;
|
|
65
|
+
return `${round(cx + radius * Math.cos(angle))} ${round(cy + radius * Math.sin(angle))}`;
|
|
66
|
+
};
|
|
67
|
+
const step = (to - from) / bumps;
|
|
68
|
+
const bump = round(radius * Math.sin(step / 2 * Math.PI / 180) * 1.25);
|
|
69
|
+
let d = `${point(from)}`;
|
|
70
|
+
for (let i = 1; i <= bumps; i++) d += ` A ${bump} ${bump} 0 0 1 ${point(from + step * i)}`;
|
|
71
|
+
return d;
|
|
72
|
+
}
|
|
73
|
+
var paperOf = (traits) => traits.paper ?? "none";
|
|
74
|
+
function hairBehind(traits) {
|
|
75
|
+
const { ink, paper } = traits;
|
|
76
|
+
const gap = paper ? ` stroke="${paper}" stroke-width="3" stroke-linejoin="round"` : "";
|
|
77
|
+
const mass = (d) => (paper ? `<path d="${d}" fill="none"${gap}/>` : "") + `<path d="${d} ${FACE_HOLE}" fill="${ink}" fill-rule="evenodd"/>`;
|
|
78
|
+
switch (traits.hairStyle) {
|
|
79
|
+
case "curly":
|
|
80
|
+
return mass(`M 19 37 L ${scallop(32, 23, 16.2, 150, 390, 12)} L 45 37 Z`);
|
|
81
|
+
case "afro":
|
|
82
|
+
return mass(`M ${scallop(32, 22, 17.5, 0, 360, 14)} Z`);
|
|
83
|
+
case "long":
|
|
84
|
+
return mass(
|
|
85
|
+
"M 32 9.6 C 42.5 9.6 47.4 16 47.4 26 L 47.6 51 C 47.6 53.4 46 54.6 44 54.6 L 41.6 54.6 C 40 54.6 39 53.2 38.8 50.4 L 38.6 43 L 25.4 43 L 25.2 50.4 C 25 53.2 24 54.6 22.4 54.6 L 20 54.6 C 18 54.6 16.4 53.4 16.4 51 L 16.6 26 C 16.6 16 21.5 9.6 32 9.6 Z"
|
|
86
|
+
);
|
|
87
|
+
case "bob":
|
|
88
|
+
return mass(
|
|
89
|
+
"M 32 10 C 42 10 47 16 47 26 L 47 40.5 C 47 43.6 45.2 45.6 42.4 45.6 L 40.4 45.6 C 39 45.6 38.4 44 38.4 41 L 25.6 41 C 25.6 44 25 45.6 23.6 45.6 L 21.6 45.6 C 18.8 45.6 17 43.6 17 40.5 L 17 26 C 17 16 22 10 32 10 Z"
|
|
90
|
+
);
|
|
91
|
+
case "bun":
|
|
92
|
+
return `<circle cx="${CX}" cy="9" r="6"${paper ? ` fill="${ink}" stroke="${paper}" stroke-width="2"` : ` fill="${ink}"`}/>`;
|
|
93
|
+
case "locs": {
|
|
94
|
+
const strands = [
|
|
95
|
+
[14, 20, 48],
|
|
96
|
+
[17.4, 18, 53],
|
|
97
|
+
[20.8, 36, 55.4]
|
|
98
|
+
].map(
|
|
99
|
+
([x, top, bottom]) => `<rect x="${x - 2.1}" y="${top}" width="4.2" height="${bottom - top}" rx="2.1"/>`
|
|
100
|
+
).join("");
|
|
101
|
+
const bunch = (paint) => pair(`<g ${paint}>${strands}</g>`);
|
|
102
|
+
return (paper ? bunch(`fill="${paper}" stroke="${paper}" stroke-width="3"`) : "") + bunch(`fill="${ink}"`);
|
|
103
|
+
}
|
|
104
|
+
default:
|
|
105
|
+
return "";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function hairFront(traits) {
|
|
109
|
+
const { ink } = traits;
|
|
110
|
+
switch (traits.hairStyle) {
|
|
111
|
+
case "crop":
|
|
112
|
+
return fill(
|
|
113
|
+
"M 18.8 28 C 17.6 16 23.5 10.4 32 10.4 C 40.5 10.4 46.4 16 45.2 28 L 43.8 28 C 43.4 23.5 42 20.6 39 19.6 C 35 18.6 29 18.6 25 19.6 C 22 20.6 20.6 23.5 20.2 28 Z",
|
|
114
|
+
ink
|
|
115
|
+
);
|
|
116
|
+
case "side-part": {
|
|
117
|
+
const hair = fill(
|
|
118
|
+
"M 18.8 28 C 17.4 15 23 9.4 31 9.4 C 41 9.4 46.6 15.5 45.2 28 L 43.8 28 C 43.6 22 42.8 19.6 40.6 19 C 35 19.8 29.4 18.6 26.6 15.2 C 24.6 18.6 21.2 21.6 20.2 28 Z",
|
|
119
|
+
ink
|
|
120
|
+
);
|
|
121
|
+
return traits.flip ? mirrored(hair) : hair;
|
|
122
|
+
}
|
|
123
|
+
case "curly":
|
|
124
|
+
return fill(
|
|
125
|
+
`M 19 30 C 18.4 18 24 11 32 11 C 40 11 45.6 18 45 30 L 43.8 30 C 43.4 25 42.4 22.6 41.6 21.6 ${scallop(32, 1.2, 18, 58, 122, 5).replace(/^/, "L ")} C 21.6 22.6 20.6 25 20.2 30 Z`,
|
|
126
|
+
ink
|
|
127
|
+
);
|
|
128
|
+
case "afro":
|
|
129
|
+
return fill(
|
|
130
|
+
"M 19.2 26 L 19.2 10 L 44.8 10 L 44.8 26 L 43.9 26 C 43.4 20.8 39.4 17.6 32 17.6 C 24.6 17.6 20.6 20.8 20.1 26 Z",
|
|
131
|
+
ink
|
|
132
|
+
);
|
|
133
|
+
case "long": {
|
|
134
|
+
const hair = fill(
|
|
135
|
+
"M 30 14.2 C 26 15 22.4 17.6 21.4 24 C 20.6 30 21 38 21.8 47 L 18.2 47 L 18.2 26 C 18.4 15 24 10.6 32 10.6 C 40 10.6 45.6 15 45.8 26 L 45.8 47 L 42.2 47 C 43 38 43.4 30 42.6 24 C 41.6 17.6 35.4 14.2 30 14.2 Z",
|
|
136
|
+
ink
|
|
137
|
+
);
|
|
138
|
+
return traits.flip ? mirrored(hair) : hair;
|
|
139
|
+
}
|
|
140
|
+
case "bob":
|
|
141
|
+
return fill(
|
|
142
|
+
"M 18.8 40 L 18.6 26 C 18.6 15.5 24 11 32 11 C 40 11 45.4 15.5 45.4 26 L 45.2 40 L 43 40 C 43.4 33 43.4 27 42.6 20 Q 32 21 21.4 20 C 20.6 27 20.6 33 21 40 Z",
|
|
143
|
+
ink
|
|
144
|
+
);
|
|
145
|
+
case "bun":
|
|
146
|
+
return fill(
|
|
147
|
+
"M 19.4 28 C 19 17 24.5 11.6 32 11.6 C 39.5 11.6 45 17 44.6 28 L 43.8 28 C 43.4 22 40.6 18.4 32 18 C 23.4 18.4 20.6 22 20.2 28 Z",
|
|
148
|
+
ink
|
|
149
|
+
);
|
|
150
|
+
case "locs":
|
|
151
|
+
return fill(
|
|
152
|
+
"M 18.8 30 C 17.8 16 23.5 10.4 32 10.4 C 40.5 10.4 46.2 16 45.2 30 L 43.8 30 C 43.4 24 41.6 20.4 37.6 19.4 C 34.6 18.8 29.4 18.8 26.4 19.4 C 22.4 20.4 20.6 24 20.2 30 Z",
|
|
153
|
+
ink
|
|
154
|
+
);
|
|
155
|
+
case "bald":
|
|
156
|
+
return "";
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function drawBody(traits) {
|
|
160
|
+
const { ink } = traits;
|
|
161
|
+
const neck = (bottom) => stroke(`M 28.2 39 L 28.2 ${bottom}`, ink) + stroke(`M 35.8 39 L 35.8 ${bottom}`, ink);
|
|
162
|
+
const shoulders = (top, neckline) => `M 4 64 C 4.6 55.4 10.4 ${top + 1.6} 20.6 ${top} ${neckline} C 53.6 ${top + 1.6} 59.4 55.4 60 64 Z`;
|
|
163
|
+
switch (traits.clothing) {
|
|
164
|
+
case "crew":
|
|
165
|
+
return neck(52) + fill(shoulders(49.4, "L 26.8 49.4 C 28 53.8 36 53.8 37.2 49.4 L 43.4 49.4"), ink);
|
|
166
|
+
case "v-neck":
|
|
167
|
+
return neck(55) + fill(shoulders(49.4, "L 26.6 49.4 L 32 57.4 L 37.4 49.4 L 43.4 49.4"), ink);
|
|
168
|
+
case "collar":
|
|
169
|
+
return neck(51) + fill(shoulders(49.4, "L 25.8 49.4 L 32 64 L 38.2 49.4 L 43.4 49.4"), ink) + fill("M 30.2 50 L 33.8 50 L 33 52.6 L 34.2 59.6 L 32 61.8 L 29.8 59.6 L 31 52.6 Z", ink);
|
|
170
|
+
case "turtleneck":
|
|
171
|
+
return `<rect x="26" y="41.4" width="12" height="7.2" rx="2.6" fill="${ink}"/>` + fill(shoulders(49.8, "L 43.4 49.8"), ink);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function drawHead(traits) {
|
|
175
|
+
const { ink } = traits;
|
|
176
|
+
const paper = paperOf(traits);
|
|
177
|
+
const ear = `<path d="M 20.6 26.4 C 17.2 25.8 17 32.4 20.8 32.2" fill="${paper}" stroke="${ink}" stroke-width="${LINE}" stroke-linecap="round"/>`;
|
|
178
|
+
return pair(ear) + `<path d="${FACE}" fill="${paper}" stroke="${ink}" stroke-width="${LINE}" stroke-linejoin="round"/>`;
|
|
179
|
+
}
|
|
180
|
+
function drawEyes(traits) {
|
|
181
|
+
const { ink } = traits;
|
|
182
|
+
if (traits.glasses) return pair(`<circle cx="${LENS_X}" cy="${LENS_Y}" r="1.1" fill="${ink}"/>`);
|
|
183
|
+
const x = EYE_X;
|
|
184
|
+
const y = EYE_Y;
|
|
185
|
+
switch (traits.eyeStyle) {
|
|
186
|
+
case "dots":
|
|
187
|
+
return pair(`<ellipse cx="${x}" cy="${y}" rx="1.9" ry="2.2" fill="${ink}"/>`);
|
|
188
|
+
case "lidded":
|
|
189
|
+
return pair(
|
|
190
|
+
stroke(`M ${x - 3.1} ${y - 0.2} Q ${x} ${y - 2.8} ${x + 3.1} ${y - 0.2}`, ink, 2.2) + `<circle cx="${x}" cy="${y + 0.5}" r="1.7" fill="${ink}"/>`
|
|
191
|
+
);
|
|
192
|
+
case "smiling":
|
|
193
|
+
return pair(stroke(`M ${x - 3} ${y + 1} Q ${x} ${y - 2.6} ${x + 3} ${y + 1}`, ink));
|
|
194
|
+
case "lashes":
|
|
195
|
+
return pair(
|
|
196
|
+
`<ellipse cx="${x}" cy="${y}" rx="1.9" ry="2.2" fill="${ink}"/>` + stroke(`M ${x - 2.3} ${y - 1} L ${x - 3.9} ${y - 1.8}`, ink, 2.2)
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function drawEyebrows(traits) {
|
|
201
|
+
if (traits.glasses) return "";
|
|
202
|
+
const { ink } = traits;
|
|
203
|
+
switch (traits.brow) {
|
|
204
|
+
case "straight":
|
|
205
|
+
return pair(stroke("M 23.8 24.4 L 29.4 23.9", ink));
|
|
206
|
+
case "arched":
|
|
207
|
+
return pair(stroke("M 23.8 25 Q 26.2 22.4 29.4 23.8", ink));
|
|
208
|
+
case "soft":
|
|
209
|
+
return pair(stroke("M 23.8 24.6 Q 27.2 23 29.6 24.2", ink));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function drawGlasses(traits) {
|
|
213
|
+
if (!traits.glasses) return "";
|
|
214
|
+
const { ink } = traits;
|
|
215
|
+
const lens = traits.roundGlasses ? `<circle cx="${LENS_X}" cy="${LENS_Y}" r="2.8"` : `<rect x="${LENS_X - 2.8}" y="${LENS_Y - 2.6}" width="5.6" height="5.2" rx="1.8"`;
|
|
216
|
+
return pair(`${lens} fill="none" stroke="${ink}" stroke-width="2.2"/>`) + stroke(`M 30.6 ${LENS_Y - 1.2} Q 32 ${LENS_Y - 2.2} 33.4 ${LENS_Y - 1.2}`, ink, 2.2);
|
|
217
|
+
}
|
|
218
|
+
function drawNose(traits) {
|
|
219
|
+
const { ink, glasses } = traits;
|
|
220
|
+
let d;
|
|
221
|
+
switch (traits.nose) {
|
|
222
|
+
case "hook":
|
|
223
|
+
d = glasses ? "M 32.6 32.8 C 33.4 33.6 34.2 34.2 32.2 34.8" : "M 32.6 30 C 33.6 32 34.6 33.6 32.2 34.4";
|
|
224
|
+
break;
|
|
225
|
+
case "button":
|
|
226
|
+
d = glasses ? "M 30.4 34 Q 32 35.6 33.6 34" : "M 30.4 33.6 Q 32 35.2 33.6 33.6";
|
|
227
|
+
break;
|
|
228
|
+
case "angle":
|
|
229
|
+
d = glasses ? "M 32 32.8 L 31.3 34.6 L 33 34.8" : "M 32 30 L 31 34 L 33 34.2";
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
const nose = stroke(d, ink, 2.2);
|
|
233
|
+
return traits.flip ? mirrored(nose) : nose;
|
|
234
|
+
}
|
|
235
|
+
function drawFacialHair(traits) {
|
|
236
|
+
if (!traits.facialHair) return "";
|
|
237
|
+
const { ink } = traits;
|
|
238
|
+
const moustache = "M 27 37 C 28.4 34.8 30.8 34.8 32 35.8 C 33.2 34.8 35.6 34.8 37 37 C 35.2 36.6 33.6 36.8 32 37.2 C 30.4 36.8 28.8 36.6 27 37 Z";
|
|
239
|
+
switch (traits.beard) {
|
|
240
|
+
case "full":
|
|
241
|
+
return fill(
|
|
242
|
+
"M 20.4 30 C 21 38 25.4 45.6 32 45.6 C 38.6 45.6 43 38 43.6 30 C 42 34 39.6 35.4 36.6 35.2 C 35 34.8 33.4 34.8 32 35.6 C 30.6 34.8 29 34.8 27.4 35.2 C 24.4 35.4 22 34 20.4 30 Z M 26.6 38.6 C 26.6 41.6 29 42 32 42 C 35 42 37.4 41.6 37.4 38.6 C 35.6 37.4 28.4 37.4 26.6 38.6 Z",
|
|
243
|
+
ink,
|
|
244
|
+
true
|
|
245
|
+
);
|
|
246
|
+
case "moustache":
|
|
247
|
+
return fill(moustache, ink);
|
|
248
|
+
case "goatee":
|
|
249
|
+
return fill(moustache, ink) + fill("M 28.4 42 Q 32 40.8 35.6 42 Q 35.2 45.8 32 46 Q 28.8 45.8 28.4 42 Z", ink);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function drawMouth(traits) {
|
|
253
|
+
const { ink } = traits;
|
|
254
|
+
switch (traits.mouthStyle) {
|
|
255
|
+
case "smile":
|
|
256
|
+
return stroke("M 28 38 Q 32 41.6 36 38", ink);
|
|
257
|
+
case "grin":
|
|
258
|
+
return `<path d="M 27.8 37.6 Q 32 38.6 36.2 37.6 Q 35.6 42.2 32 42.2 Q 28.4 42.2 27.8 37.6 Z" fill="${ink}" stroke="${ink}" stroke-width="1" stroke-linejoin="round"/>`;
|
|
259
|
+
case "soft":
|
|
260
|
+
return stroke("M 29.2 38.6 Q 32 40.4 34.8 38.6", ink);
|
|
261
|
+
case "smirk": {
|
|
262
|
+
const mouth = stroke("M 28.6 39 Q 32 40.6 35.6 37.8", ink);
|
|
263
|
+
return traits.flip ? mirrored(mouth) : mouth;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function backgroundFor(options, random) {
|
|
268
|
+
return random.pick(options.colors ?? import_core.DEFAULT_COLORS);
|
|
269
|
+
}
|
|
270
|
+
function preparePortraits(options, random) {
|
|
271
|
+
const background = backgroundFor(options, (0, import_core.createRandom)(`${options.seed}:background`));
|
|
272
|
+
const automatic = options.transparent ? background : (0, import_core.readableColor)(background);
|
|
273
|
+
return {
|
|
274
|
+
ink: options.ink ?? (0, import_core.resolveTheme)(options.theme)?.foreground ?? automatic,
|
|
275
|
+
paper: options.transparent ? void 0 : background,
|
|
276
|
+
hairStyle: options.hairStyle ?? random.pick(HAIR_STYLES),
|
|
277
|
+
eyeStyle: options.eyeStyle ?? random.pick(EYE_STYLES),
|
|
278
|
+
mouthStyle: options.mouthStyle ?? random.pick(MOUTH_STYLES),
|
|
279
|
+
glasses: options.glasses ?? random.bool(0.25),
|
|
280
|
+
roundGlasses: random.bool(0.5),
|
|
281
|
+
facialHair: options.facialHair ?? random.bool(0.22),
|
|
282
|
+
beard: random.pick(BEARDS),
|
|
283
|
+
clothing: random.pick(CLOTHING),
|
|
284
|
+
brow: random.pick(BROWS),
|
|
285
|
+
nose: random.pick(NOSES),
|
|
286
|
+
flip: random.bool(0.5)
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
var portraits = (0, import_core.defineStyle)({
|
|
290
|
+
name: "portraits",
|
|
291
|
+
canvas: CANVAS,
|
|
292
|
+
validate(options) {
|
|
293
|
+
(0, import_core.validateOption)("portraits", "hairStyle", options.hairStyle, HAIR_STYLES);
|
|
294
|
+
(0, import_core.validateOption)("portraits", "eyeStyle", options.eyeStyle, EYE_STYLES);
|
|
295
|
+
(0, import_core.validateOption)("portraits", "mouthStyle", options.mouthStyle, MOUTH_STYLES);
|
|
296
|
+
},
|
|
297
|
+
prepare: preparePortraits,
|
|
298
|
+
background: backgroundFor,
|
|
299
|
+
head: () => ({ x: 20, y: 13, width: 24, height: 31 }),
|
|
300
|
+
layers: [
|
|
301
|
+
{ name: "body", render: ({ traits }) => drawBody(traits) },
|
|
302
|
+
{ name: "hair-behind", feature: "hair", render: ({ traits }) => hairBehind(traits) },
|
|
303
|
+
{ name: "head", render: ({ traits }) => drawHead(traits) },
|
|
304
|
+
{ name: "hair-front", feature: "hair", render: ({ traits }) => hairFront(traits) },
|
|
305
|
+
{ name: "eyes", render: ({ traits }) => drawEyes(traits) },
|
|
306
|
+
{ name: "eyebrows", render: ({ traits }) => drawEyebrows(traits) },
|
|
307
|
+
{ name: "glasses", render: ({ traits }) => drawGlasses(traits) },
|
|
308
|
+
{ name: "nose", render: ({ traits }) => drawNose(traits) },
|
|
309
|
+
{ name: "facial-hair", render: ({ traits }) => drawFacialHair(traits) },
|
|
310
|
+
{ name: "mouth", render: ({ traits }) => drawMouth(traits) }
|
|
311
|
+
]
|
|
312
|
+
});
|
|
313
|
+
var index_default = portraits;
|
|
314
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
315
|
+
0 && (module.exports = {
|
|
316
|
+
EYE_STYLES,
|
|
317
|
+
HAIR_STYLES,
|
|
318
|
+
MOUTH_STYLES,
|
|
319
|
+
portraits
|
|
320
|
+
});
|
|
321
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AvatarOptions, ComposableStyle, Random } from \"@avatar-generator/core\";\nimport {\n createRandom,\n defineStyle,\n DEFAULT_COLORS,\n readableColor,\n resolveTheme,\n validateOption,\n} from \"@avatar-generator/core\";\n\n// ============================================================================\n// Options\n// ============================================================================\n\nexport type PortraitsHairStyle = \"crop\" | \"side-part\" | \"curly\" | \"afro\" | \"long\" | \"bob\" | \"bun\" | \"locs\" | \"bald\";\n\nexport type PortraitsEyeStyle = \"dots\" | \"lidded\" | \"smiling\" | \"lashes\";\n\nexport type PortraitsMouthStyle = \"smile\" | \"grin\" | \"soft\" | \"smirk\";\n\nexport interface PortraitsOptions extends AvatarOptions {\n /** Override hair style */\n hairStyle?: PortraitsHairStyle;\n /** Override eye style */\n eyeStyle?: PortraitsEyeStyle;\n /** Override mouth style */\n mouthStyle?: PortraitsMouthStyle;\n /** Force glasses on or off (default: chosen by the seed) */\n glasses?: boolean;\n /** Force facial hair on or off (default: chosen by the seed) */\n facialHair?: boolean;\n /**\n * The one colour everything is drawn in. Defaults to the theme's foreground,\n * otherwise white or near-black, whichever reads better on the background.\n */\n ink?: string;\n}\n\n/** All valid hair style values for the portraits style */\nexport const HAIR_STYLES: PortraitsHairStyle[] = [\n \"crop\",\n \"side-part\",\n \"curly\",\n \"afro\",\n \"long\",\n \"bob\",\n \"bun\",\n \"locs\",\n \"bald\",\n];\n\n/** All valid eye style values for the portraits style */\nexport const EYE_STYLES: PortraitsEyeStyle[] = [\"dots\", \"lidded\", \"smiling\", \"lashes\"];\n\n/** All valid mouth style values for the portraits style */\nexport const MOUTH_STYLES: PortraitsMouthStyle[] = [\"smile\", \"grin\", \"soft\", \"smirk\"];\n\ntype Clothing = \"crew\" | \"v-neck\" | \"collar\" | \"turtleneck\";\ntype Brow = \"straight\" | \"arched\" | \"soft\";\ntype Nose = \"hook\" | \"button\" | \"angle\";\ntype Beard = \"full\" | \"moustache\" | \"goatee\";\n\nconst CLOTHING: Clothing[] = [\"crew\", \"v-neck\", \"collar\", \"turtleneck\"];\nconst BROWS: Brow[] = [\"straight\", \"arched\", \"soft\"];\nconst NOSES: Nose[] = [\"hook\", \"button\", \"angle\"];\nconst BEARDS: Beard[] = [\"full\", \"moustache\", \"goatee\"];\n\n// Everything is drawn on this canvas and scaled by the SVG, so plain numbers stay\n// in proportion at any size.\nconst CANVAS = 64;\nconst CX = 32;\nconst EYE_X = 26.6;\nconst EYE_Y = 29;\nconst LINE = 2.4;\n/** Where each lens sits: nearer the middle and a little higher than the eyes. */\nconst LENS_X = 27.2;\nconst LENS_Y = 28.4;\n\n/** An egg-shaped face, a little narrower at the jaw. */\nconst FACE =\n \"M 32 13 C 39.6 13 44 18.4 44 26.5 C 44 35.5 38.6 44 32 44 C 25.4 44 20 35.5 20 26.5 C 20 18.4 24.4 13 32 13 Z\";\n\n/** The same outline run the other way, to punch the face out of hair drawn behind it. */\nconst FACE_HOLE =\n \"M 32 13 C 24.4 13 20 18.4 20 26.5 C 20 35.5 25.4 44 32 44 C 38.6 44 44 35.5 44 26.5 C 44 18.4 39.6 13 32 13 Z\";\n\nconst round = (value: number): number => Math.round(value * 100) / 100;\n\n/** Reflects markup drawn for the left side onto the right. */\nconst mirrored = (markup: string): string => `<g transform=\"matrix(-1 0 0 1 ${CANVAS} 0)\">${markup}</g>`;\n\n/** Draws something on the left and its reflection on the right. */\nconst pair = (markup: string): string => markup + mirrored(markup);\n\nconst stroke = (d: string, ink: string, width = LINE): string =>\n `<path d=\"${d}\" fill=\"none\" stroke=\"${ink}\" stroke-width=\"${width}\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>`;\n\nconst fill = (d: string, ink: string, rule = false): string =>\n `<path d=\"${d}\" fill=\"${ink}\"${rule ? ' fill-rule=\"evenodd\"' : \"\"}/>`;\n\n/**\n * A run of round bumps along a circle, for curls. Angles are in degrees,\n * clockwise from the right, so 180 to 360 runs over the top.\n */\nfunction scallop(cx: number, cy: number, radius: number, from: number, to: number, bumps: number): string {\n const point = (degrees: number) => {\n const angle = (degrees * Math.PI) / 180;\n return `${round(cx + radius * Math.cos(angle))} ${round(cy + radius * Math.sin(angle))}`;\n };\n const step = (to - from) / bumps;\n const bump = round(radius * Math.sin(((step / 2) * Math.PI) / 180) * 1.25);\n let d = `${point(from)}`;\n for (let i = 1; i <= bumps; i++) d += ` A ${bump} ${bump} 0 0 1 ${point(from + step * i)}`;\n return d;\n}\n\n/** What the seed decides for one portrait. */\nexport interface PortraitsTraits {\n /** The colour every line and mass is drawn in. */\n ink: string;\n /** The background showing through, or `undefined` when there is none. */\n paper: string | undefined;\n hairStyle: PortraitsHairStyle;\n eyeStyle: PortraitsEyeStyle;\n mouthStyle: PortraitsMouthStyle;\n glasses: boolean;\n roundGlasses: boolean;\n facialHair: boolean;\n beard: Beard;\n clothing: Clothing;\n brow: Brow;\n nose: Nose;\n /** Draws the asymmetric parts the other way round. */\n flip: boolean;\n}\n\n/** Where the fill under a line goes: the background, or nothing on a transparent avatar. */\nconst paperOf = (traits: PortraitsTraits): string => traits.paper ?? \"none\";\n\n// ─── Hair ─────────────────────────────────────────────────────────────────\n\n/** Hair that sits behind the head. The face is cut out, so nothing shows through it. */\nfunction hairBehind(traits: PortraitsTraits): string {\n const { ink, paper } = traits;\n // A thin gap in the background colour keeps hair apart from the clothes below.\n const gap = paper ? ` stroke=\"${paper}\" stroke-width=\"3\" stroke-linejoin=\"round\"` : \"\";\n // The gap is drawn first and half covered, so it falls outside the hair.\n const mass = (d: string) =>\n (paper ? `<path d=\"${d}\" fill=\"none\"${gap}/>` : \"\") +\n `<path d=\"${d} ${FACE_HOLE}\" fill=\"${ink}\" fill-rule=\"evenodd\"/>`;\n\n switch (traits.hairStyle) {\n case \"curly\":\n return mass(`M 19 37 L ${scallop(32, 23, 16.2, 150, 390, 12)} L 45 37 Z`);\n case \"afro\":\n return mass(`M ${scallop(32, 22, 17.5, 0, 360, 14)} Z`);\n case \"long\":\n return mass(\n \"M 32 9.6 C 42.5 9.6 47.4 16 47.4 26 L 47.6 51 C 47.6 53.4 46 54.6 44 54.6 L 41.6 54.6 C 40 54.6 39 53.2 38.8 50.4 L 38.6 43 L 25.4 43 L 25.2 50.4 C 25 53.2 24 54.6 22.4 54.6 L 20 54.6 C 18 54.6 16.4 53.4 16.4 51 L 16.6 26 C 16.6 16 21.5 9.6 32 9.6 Z\",\n );\n case \"bob\":\n return mass(\n \"M 32 10 C 42 10 47 16 47 26 L 47 40.5 C 47 43.6 45.2 45.6 42.4 45.6 L 40.4 45.6 C 39 45.6 38.4 44 38.4 41 L 25.6 41 C 25.6 44 25 45.6 23.6 45.6 L 21.6 45.6 C 18.8 45.6 17 43.6 17 40.5 L 17 26 C 17 16 22 10 32 10 Z\",\n );\n case \"bun\":\n return `<circle cx=\"${CX}\" cy=\"9\" r=\"6\"${paper ? ` fill=\"${ink}\" stroke=\"${paper}\" stroke-width=\"2\"` : ` fill=\"${ink}\"`}/>`;\n case \"locs\": {\n // Rounded strands falling past the shoulders, kept clear of the face.\n const strands = [\n [14, 20, 48],\n [17.4, 18, 53],\n [20.8, 36, 55.4],\n ]\n .map(\n ([x, top, bottom]) =>\n `<rect x=\"${x - 2.1}\" y=\"${top}\" width=\"4.2\" height=\"${bottom - top}\" rx=\"2.1\"/>`,\n )\n .join(\"\");\n // The gap goes round the whole bunch, not between the strands.\n const bunch = (paint: string) => pair(`<g ${paint}>${strands}</g>`);\n return (paper ? bunch(`fill=\"${paper}\" stroke=\"${paper}\" stroke-width=\"3\"`) : \"\") + bunch(`fill=\"${ink}\"`);\n }\n default:\n return \"\";\n }\n}\n\n/** Hair in front of the head: the hairline and anything framing the face. */\nfunction hairFront(traits: PortraitsTraits): string {\n const { ink } = traits;\n switch (traits.hairStyle) {\n case \"crop\":\n return fill(\n \"M 18.8 28 C 17.6 16 23.5 10.4 32 10.4 C 40.5 10.4 46.4 16 45.2 28 L 43.8 28 C 43.4 23.5 42 20.6 39 19.6 C 35 18.6 29 18.6 25 19.6 C 22 20.6 20.6 23.5 20.2 28 Z\",\n ink,\n );\n case \"side-part\": {\n const hair = fill(\n \"M 18.8 28 C 17.4 15 23 9.4 31 9.4 C 41 9.4 46.6 15.5 45.2 28 L 43.8 28 C 43.6 22 42.8 19.6 40.6 19 C 35 19.8 29.4 18.6 26.6 15.2 C 24.6 18.6 21.2 21.6 20.2 28 Z\",\n ink,\n );\n return traits.flip ? mirrored(hair) : hair;\n }\n case \"curly\":\n return fill(\n `M 19 30 C 18.4 18 24 11 32 11 C 40 11 45.6 18 45 30 L 43.8 30 C 43.4 25 42.4 22.6 41.6 21.6 ${scallop(32, 1.2, 18, 58, 122, 5).replace(/^/, \"L \")} C 21.6 22.6 20.6 25 20.2 30 Z`,\n ink,\n );\n case \"afro\":\n return fill(\n \"M 19.2 26 L 19.2 10 L 44.8 10 L 44.8 26 L 43.9 26 C 43.4 20.8 39.4 17.6 32 17.6 C 24.6 17.6 20.6 20.8 20.1 26 Z\",\n ink,\n );\n case \"long\": {\n const hair = fill(\n \"M 30 14.2 C 26 15 22.4 17.6 21.4 24 C 20.6 30 21 38 21.8 47 L 18.2 47 L 18.2 26 C 18.4 15 24 10.6 32 10.6 C 40 10.6 45.6 15 45.8 26 L 45.8 47 L 42.2 47 C 43 38 43.4 30 42.6 24 C 41.6 17.6 35.4 14.2 30 14.2 Z\",\n ink,\n );\n return traits.flip ? mirrored(hair) : hair;\n }\n case \"bob\":\n return fill(\n \"M 18.8 40 L 18.6 26 C 18.6 15.5 24 11 32 11 C 40 11 45.4 15.5 45.4 26 L 45.2 40 L 43 40 C 43.4 33 43.4 27 42.6 20 Q 32 21 21.4 20 C 20.6 27 20.6 33 21 40 Z\",\n ink,\n );\n case \"bun\":\n return fill(\n \"M 19.4 28 C 19 17 24.5 11.6 32 11.6 C 39.5 11.6 45 17 44.6 28 L 43.8 28 C 43.4 22 40.6 18.4 32 18 C 23.4 18.4 20.6 22 20.2 28 Z\",\n ink,\n );\n case \"locs\":\n return fill(\n \"M 18.8 30 C 17.8 16 23.5 10.4 32 10.4 C 40.5 10.4 46.2 16 45.2 30 L 43.8 30 C 43.4 24 41.6 20.4 37.6 19.4 C 34.6 18.8 29.4 18.8 26.4 19.4 C 22.4 20.4 20.6 24 20.2 30 Z\",\n ink,\n );\n case \"bald\":\n return \"\";\n }\n}\n\n// ─── Body and head ────────────────────────────────────────────────────────\n\nfunction drawBody(traits: PortraitsTraits): string {\n const { ink } = traits;\n const neck = (bottom: number) =>\n stroke(`M 28.2 39 L 28.2 ${bottom}`, ink) + stroke(`M 35.8 39 L 35.8 ${bottom}`, ink);\n const shoulders = (top: number, neckline: string) =>\n `M 4 64 C 4.6 55.4 10.4 ${top + 1.6} 20.6 ${top} ${neckline} C 53.6 ${top + 1.6} 59.4 55.4 60 64 Z`;\n\n switch (traits.clothing) {\n case \"crew\":\n return neck(52) + fill(shoulders(49.4, \"L 26.8 49.4 C 28 53.8 36 53.8 37.2 49.4 L 43.4 49.4\"), ink);\n case \"v-neck\":\n return neck(55) + fill(shoulders(49.4, \"L 26.6 49.4 L 32 57.4 L 37.4 49.4 L 43.4 49.4\"), ink);\n case \"collar\":\n // A jacket open over a shirt and tie.\n return (\n neck(51) +\n fill(shoulders(49.4, \"L 25.8 49.4 L 32 64 L 38.2 49.4 L 43.4 49.4\"), ink) +\n fill(\"M 30.2 50 L 33.8 50 L 33 52.6 L 34.2 59.6 L 32 61.8 L 29.8 59.6 L 31 52.6 Z\", ink)\n );\n case \"turtleneck\":\n return (\n `<rect x=\"26\" y=\"41.4\" width=\"12\" height=\"7.2\" rx=\"2.6\" fill=\"${ink}\"/>` +\n fill(shoulders(49.8, \"L 43.4 49.8\"), ink)\n );\n }\n}\n\nfunction drawHead(traits: PortraitsTraits): string {\n const { ink } = traits;\n const paper = paperOf(traits);\n const ear = `<path d=\"M 20.6 26.4 C 17.2 25.8 17 32.4 20.8 32.2\" fill=\"${paper}\" stroke=\"${ink}\" stroke-width=\"${LINE}\" stroke-linecap=\"round\"/>`;\n return (\n pair(ear) + `<path d=\"${FACE}\" fill=\"${paper}\" stroke=\"${ink}\" stroke-width=\"${LINE}\" stroke-linejoin=\"round\"/>`\n );\n}\n\n// ─── Features ─────────────────────────────────────────────────────────────\n\nfunction drawEyes(traits: PortraitsTraits): string {\n const { ink } = traits;\n // Behind lenses, plain dots keep the glass clear: anything more reads as a mask.\n if (traits.glasses) return pair(`<circle cx=\"${LENS_X}\" cy=\"${LENS_Y}\" r=\"1.1\" fill=\"${ink}\"/>`);\n const x = EYE_X;\n const y = EYE_Y;\n switch (traits.eyeStyle) {\n case \"dots\":\n return pair(`<ellipse cx=\"${x}\" cy=\"${y}\" rx=\"1.9\" ry=\"2.2\" fill=\"${ink}\"/>`);\n case \"lidded\":\n // An upper lid over the pupil: calm and attentive, not sleepy.\n return pair(\n stroke(`M ${x - 3.1} ${y - 0.2} Q ${x} ${y - 2.8} ${x + 3.1} ${y - 0.2}`, ink, 2.2) +\n `<circle cx=\"${x}\" cy=\"${y + 0.5}\" r=\"1.7\" fill=\"${ink}\"/>`,\n );\n case \"smiling\":\n return pair(stroke(`M ${x - 3} ${y + 1} Q ${x} ${y - 2.6} ${x + 3} ${y + 1}`, ink));\n case \"lashes\":\n return pair(\n `<ellipse cx=\"${x}\" cy=\"${y}\" rx=\"1.9\" ry=\"2.2\" fill=\"${ink}\"/>` +\n stroke(`M ${x - 2.3} ${y - 1} L ${x - 3.9} ${y - 1.8}`, ink, 2.2),\n );\n }\n}\n\nfunction drawEyebrows(traits: PortraitsTraits): string {\n // The top of a frame stands in for the brows: both would merge into one dark band.\n if (traits.glasses) return \"\";\n const { ink } = traits;\n switch (traits.brow) {\n case \"straight\":\n return pair(stroke(\"M 23.8 24.4 L 29.4 23.9\", ink));\n case \"arched\":\n return pair(stroke(\"M 23.8 25 Q 26.2 22.4 29.4 23.8\", ink));\n case \"soft\":\n return pair(stroke(\"M 23.8 24.6 Q 27.2 23 29.6 24.2\", ink));\n }\n}\n\nfunction drawGlasses(traits: PortraitsTraits): string {\n if (!traits.glasses) return \"\";\n const { ink } = traits;\n // Small lenses with background all round them, so frames, hair and the\n // face edge stay apart at any size.\n const lens = traits.roundGlasses\n ? `<circle cx=\"${LENS_X}\" cy=\"${LENS_Y}\" r=\"2.8\"`\n : `<rect x=\"${LENS_X - 2.8}\" y=\"${LENS_Y - 2.6}\" width=\"5.6\" height=\"5.2\" rx=\"1.8\"`;\n return (\n pair(`${lens} fill=\"none\" stroke=\"${ink}\" stroke-width=\"2.2\"/>`) +\n stroke(`M 30.6 ${LENS_Y - 1.2} Q 32 ${LENS_Y - 2.2} 33.4 ${LENS_Y - 1.2}`, ink, 2.2)\n );\n}\n\nfunction drawNose(traits: PortraitsTraits): string {\n // Under glasses, a shorter nose starts below the lenses rather than between them.\n const { ink, glasses } = traits;\n let d: string;\n switch (traits.nose) {\n case \"hook\":\n d = glasses ? \"M 32.6 32.8 C 33.4 33.6 34.2 34.2 32.2 34.8\" : \"M 32.6 30 C 33.6 32 34.6 33.6 32.2 34.4\";\n break;\n case \"button\":\n d = glasses ? \"M 30.4 34 Q 32 35.6 33.6 34\" : \"M 30.4 33.6 Q 32 35.2 33.6 33.6\";\n break;\n case \"angle\":\n d = glasses ? \"M 32 32.8 L 31.3 34.6 L 33 34.8\" : \"M 32 30 L 31 34 L 33 34.2\";\n break;\n }\n const nose = stroke(d, ink, 2.2);\n return traits.flip ? mirrored(nose) : nose;\n}\n\nfunction drawFacialHair(traits: PortraitsTraits): string {\n if (!traits.facialHair) return \"\";\n const { ink } = traits;\n const moustache =\n \"M 27 37 C 28.4 34.8 30.8 34.8 32 35.8 C 33.2 34.8 35.6 34.8 37 37 C 35.2 36.6 33.6 36.8 32 37.2 C 30.4 36.8 28.8 36.6 27 37 Z\";\n switch (traits.beard) {\n case \"full\":\n // A beard along the jaw, open around the mouth.\n return fill(\n \"M 20.4 30 C 21 38 25.4 45.6 32 45.6 C 38.6 45.6 43 38 43.6 30 C 42 34 39.6 35.4 36.6 35.2 C 35 34.8 33.4 34.8 32 35.6 C 30.6 34.8 29 34.8 27.4 35.2 C 24.4 35.4 22 34 20.4 30 Z \" +\n \"M 26.6 38.6 C 26.6 41.6 29 42 32 42 C 35 42 37.4 41.6 37.4 38.6 C 35.6 37.4 28.4 37.4 26.6 38.6 Z\",\n ink,\n true,\n );\n case \"moustache\":\n return fill(moustache, ink);\n case \"goatee\":\n return (\n fill(moustache, ink) + fill(\"M 28.4 42 Q 32 40.8 35.6 42 Q 35.2 45.8 32 46 Q 28.8 45.8 28.4 42 Z\", ink)\n );\n }\n}\n\nfunction drawMouth(traits: PortraitsTraits): string {\n const { ink } = traits;\n switch (traits.mouthStyle) {\n case \"smile\":\n return stroke(\"M 28 38 Q 32 41.6 36 38\", ink);\n case \"grin\":\n return `<path d=\"M 27.8 37.6 Q 32 38.6 36.2 37.6 Q 35.6 42.2 32 42.2 Q 28.4 42.2 27.8 37.6 Z\" fill=\"${ink}\" stroke=\"${ink}\" stroke-width=\"1\" stroke-linejoin=\"round\"/>`;\n case \"soft\":\n return stroke(\"M 29.2 38.6 Q 32 40.4 34.8 38.6\", ink);\n case \"smirk\": {\n const mouth = stroke(\"M 28.6 39 Q 32 40.6 35.6 37.8\", ink);\n return traits.flip ? mirrored(mouth) : mouth;\n }\n }\n}\n\n// ─── Traits ───────────────────────────────────────────────────────────────\n\n/**\n * The background the avatar will get. It is drawn from its own stream, as\n * `defineStyle` does, so the ink can be chosen against it before any layer runs.\n */\nfunction backgroundFor(options: PortraitsOptions, random: Random): string {\n return random.pick(options.colors ?? DEFAULT_COLORS);\n}\n\nfunction preparePortraits(options: PortraitsOptions, random: Random): PortraitsTraits {\n const background = backgroundFor(options, createRandom(`${options.seed}:background`));\n // With no background, the page behind could be any colour. The palette's\n // mid-tones hold up on both light and dark, where black or white would vanish.\n const automatic = options.transparent ? background : readableColor(background);\n\n return {\n ink: options.ink ?? resolveTheme(options.theme)?.foreground ?? automatic,\n paper: options.transparent ? undefined : background,\n hairStyle: options.hairStyle ?? random.pick(HAIR_STYLES),\n eyeStyle: options.eyeStyle ?? random.pick(EYE_STYLES),\n mouthStyle: options.mouthStyle ?? random.pick(MOUTH_STYLES),\n glasses: options.glasses ?? random.bool(0.25),\n roundGlasses: random.bool(0.5),\n facialHair: options.facialHair ?? random.bool(0.22),\n beard: random.pick(BEARDS),\n clothing: random.pick(CLOTHING),\n brow: random.pick(BROWS),\n nose: random.pick(NOSES),\n flip: random.bool(0.5),\n };\n}\n\n/**\n * Portraits avatar style\n *\n * Calm, single-colour head-and-shoulders portraits for business and professional\n * tools. Everything is drawn in one ink that reads on the background: hair and\n * clothing as solid masses, so a portrait still reads at 24px, and the face as\n * fine line work over the background colour.\n *\n * Its features can be mixed with other styles: `body`, `hair`, `head`, `eyes`,\n * `eyebrows`, `glasses`, `nose`, `facial-hair` and `mouth`.\n *\n * @example\n * ```ts\n * import { createAvatar } from '@avatar-generator/core';\n * import { portraits } from '@avatar-generator/style-portraits';\n *\n * const avatar = createAvatar(portraits, {\n * seed: 'unique-id',\n * size: 64,\n * hairStyle: 'bob',\n * });\n * ```\n */\nexport const portraits: ComposableStyle<PortraitsOptions, PortraitsTraits> = defineStyle<\n PortraitsOptions,\n PortraitsTraits\n>({\n name: \"portraits\",\n canvas: CANVAS,\n\n validate(options) {\n validateOption(\"portraits\", \"hairStyle\", options.hairStyle, HAIR_STYLES);\n validateOption(\"portraits\", \"eyeStyle\", options.eyeStyle, EYE_STYLES);\n validateOption(\"portraits\", \"mouthStyle\", options.mouthStyle, MOUTH_STYLES);\n },\n\n prepare: preparePortraits,\n\n background: backgroundFor,\n\n head: () => ({ x: 20, y: 13, width: 24, height: 31 }),\n\n layers: [\n { name: \"body\", render: ({ traits }) => drawBody(traits) },\n { name: \"hair-behind\", feature: \"hair\", render: ({ traits }) => hairBehind(traits) },\n { name: \"head\", render: ({ traits }) => drawHead(traits) },\n { name: \"hair-front\", feature: \"hair\", render: ({ traits }) => hairFront(traits) },\n { name: \"eyes\", render: ({ traits }) => drawEyes(traits) },\n { name: \"eyebrows\", render: ({ traits }) => drawEyebrows(traits) },\n { name: \"glasses\", render: ({ traits }) => drawGlasses(traits) },\n { name: \"nose\", render: ({ traits }) => drawNose(traits) },\n { name: \"facial-hair\", render: ({ traits }) => drawFacialHair(traits) },\n { name: \"mouth\", render: ({ traits }) => drawMouth(traits) },\n ],\n});\n\nexport default portraits;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAOO;AA+BA,IAAM,cAAoC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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AY,QAAQ,CAAC,EAAE,OAAO,MAAM,aAAa,MAAM,EAAE;AAAA,IACjE,EAAE,MAAM,WAAW,QAAQ,CAAC,EAAE,OAAO,MAAM,YAAY,MAAM,EAAE;AAAA,IAC/D,EAAE,MAAM,QAAQ,QAAQ,CAAC,EAAE,OAAO,MAAM,SAAS,MAAM,EAAE;AAAA,IACzD,EAAE,MAAM,eAAe,QAAQ,CAAC,EAAE,OAAO,MAAM,eAAe,MAAM,EAAE;AAAA,IACtE,EAAE,MAAM,SAAS,QAAQ,CAAC,EAAE,OAAO,MAAM,UAAU,MAAM,EAAE;AAAA,EAC/D;AACJ,CAAC;AAED,IAAO,gBAAQ;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AvatarOptions, ComposableStyle } from '@avatar-generator/core';
|
|
2
|
+
|
|
3
|
+
type PortraitsHairStyle = "crop" | "side-part" | "curly" | "afro" | "long" | "bob" | "bun" | "locs" | "bald";
|
|
4
|
+
type PortraitsEyeStyle = "dots" | "lidded" | "smiling" | "lashes";
|
|
5
|
+
type PortraitsMouthStyle = "smile" | "grin" | "soft" | "smirk";
|
|
6
|
+
interface PortraitsOptions extends AvatarOptions {
|
|
7
|
+
/** Override hair style */
|
|
8
|
+
hairStyle?: PortraitsHairStyle;
|
|
9
|
+
/** Override eye style */
|
|
10
|
+
eyeStyle?: PortraitsEyeStyle;
|
|
11
|
+
/** Override mouth style */
|
|
12
|
+
mouthStyle?: PortraitsMouthStyle;
|
|
13
|
+
/** Force glasses on or off (default: chosen by the seed) */
|
|
14
|
+
glasses?: boolean;
|
|
15
|
+
/** Force facial hair on or off (default: chosen by the seed) */
|
|
16
|
+
facialHair?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The one colour everything is drawn in. Defaults to the theme's foreground,
|
|
19
|
+
* otherwise white or near-black, whichever reads better on the background.
|
|
20
|
+
*/
|
|
21
|
+
ink?: string;
|
|
22
|
+
}
|
|
23
|
+
/** All valid hair style values for the portraits style */
|
|
24
|
+
declare const HAIR_STYLES: PortraitsHairStyle[];
|
|
25
|
+
/** All valid eye style values for the portraits style */
|
|
26
|
+
declare const EYE_STYLES: PortraitsEyeStyle[];
|
|
27
|
+
/** All valid mouth style values for the portraits style */
|
|
28
|
+
declare const MOUTH_STYLES: PortraitsMouthStyle[];
|
|
29
|
+
type Clothing = "crew" | "v-neck" | "collar" | "turtleneck";
|
|
30
|
+
type Brow = "straight" | "arched" | "soft";
|
|
31
|
+
type Nose = "hook" | "button" | "angle";
|
|
32
|
+
type Beard = "full" | "moustache" | "goatee";
|
|
33
|
+
/** What the seed decides for one portrait. */
|
|
34
|
+
interface PortraitsTraits {
|
|
35
|
+
/** The colour every line and mass is drawn in. */
|
|
36
|
+
ink: string;
|
|
37
|
+
/** The background showing through, or `undefined` when there is none. */
|
|
38
|
+
paper: string | undefined;
|
|
39
|
+
hairStyle: PortraitsHairStyle;
|
|
40
|
+
eyeStyle: PortraitsEyeStyle;
|
|
41
|
+
mouthStyle: PortraitsMouthStyle;
|
|
42
|
+
glasses: boolean;
|
|
43
|
+
roundGlasses: boolean;
|
|
44
|
+
facialHair: boolean;
|
|
45
|
+
beard: Beard;
|
|
46
|
+
clothing: Clothing;
|
|
47
|
+
brow: Brow;
|
|
48
|
+
nose: Nose;
|
|
49
|
+
/** Draws the asymmetric parts the other way round. */
|
|
50
|
+
flip: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Portraits avatar style
|
|
54
|
+
*
|
|
55
|
+
* Calm, single-colour head-and-shoulders portraits for business and professional
|
|
56
|
+
* tools. Everything is drawn in one ink that reads on the background: hair and
|
|
57
|
+
* clothing as solid masses, so a portrait still reads at 24px, and the face as
|
|
58
|
+
* fine line work over the background colour.
|
|
59
|
+
*
|
|
60
|
+
* Its features can be mixed with other styles: `body`, `hair`, `head`, `eyes`,
|
|
61
|
+
* `eyebrows`, `glasses`, `nose`, `facial-hair` and `mouth`.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { createAvatar } from '@avatar-generator/core';
|
|
66
|
+
* import { portraits } from '@avatar-generator/style-portraits';
|
|
67
|
+
*
|
|
68
|
+
* const avatar = createAvatar(portraits, {
|
|
69
|
+
* seed: 'unique-id',
|
|
70
|
+
* size: 64,
|
|
71
|
+
* hairStyle: 'bob',
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare const portraits: ComposableStyle<PortraitsOptions, PortraitsTraits>;
|
|
76
|
+
|
|
77
|
+
export { EYE_STYLES, HAIR_STYLES, MOUTH_STYLES, type PortraitsEyeStyle, type PortraitsHairStyle, type PortraitsMouthStyle, type PortraitsOptions, type PortraitsTraits, portraits as default, portraits };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AvatarOptions, ComposableStyle } from '@avatar-generator/core';
|
|
2
|
+
|
|
3
|
+
type PortraitsHairStyle = "crop" | "side-part" | "curly" | "afro" | "long" | "bob" | "bun" | "locs" | "bald";
|
|
4
|
+
type PortraitsEyeStyle = "dots" | "lidded" | "smiling" | "lashes";
|
|
5
|
+
type PortraitsMouthStyle = "smile" | "grin" | "soft" | "smirk";
|
|
6
|
+
interface PortraitsOptions extends AvatarOptions {
|
|
7
|
+
/** Override hair style */
|
|
8
|
+
hairStyle?: PortraitsHairStyle;
|
|
9
|
+
/** Override eye style */
|
|
10
|
+
eyeStyle?: PortraitsEyeStyle;
|
|
11
|
+
/** Override mouth style */
|
|
12
|
+
mouthStyle?: PortraitsMouthStyle;
|
|
13
|
+
/** Force glasses on or off (default: chosen by the seed) */
|
|
14
|
+
glasses?: boolean;
|
|
15
|
+
/** Force facial hair on or off (default: chosen by the seed) */
|
|
16
|
+
facialHair?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The one colour everything is drawn in. Defaults to the theme's foreground,
|
|
19
|
+
* otherwise white or near-black, whichever reads better on the background.
|
|
20
|
+
*/
|
|
21
|
+
ink?: string;
|
|
22
|
+
}
|
|
23
|
+
/** All valid hair style values for the portraits style */
|
|
24
|
+
declare const HAIR_STYLES: PortraitsHairStyle[];
|
|
25
|
+
/** All valid eye style values for the portraits style */
|
|
26
|
+
declare const EYE_STYLES: PortraitsEyeStyle[];
|
|
27
|
+
/** All valid mouth style values for the portraits style */
|
|
28
|
+
declare const MOUTH_STYLES: PortraitsMouthStyle[];
|
|
29
|
+
type Clothing = "crew" | "v-neck" | "collar" | "turtleneck";
|
|
30
|
+
type Brow = "straight" | "arched" | "soft";
|
|
31
|
+
type Nose = "hook" | "button" | "angle";
|
|
32
|
+
type Beard = "full" | "moustache" | "goatee";
|
|
33
|
+
/** What the seed decides for one portrait. */
|
|
34
|
+
interface PortraitsTraits {
|
|
35
|
+
/** The colour every line and mass is drawn in. */
|
|
36
|
+
ink: string;
|
|
37
|
+
/** The background showing through, or `undefined` when there is none. */
|
|
38
|
+
paper: string | undefined;
|
|
39
|
+
hairStyle: PortraitsHairStyle;
|
|
40
|
+
eyeStyle: PortraitsEyeStyle;
|
|
41
|
+
mouthStyle: PortraitsMouthStyle;
|
|
42
|
+
glasses: boolean;
|
|
43
|
+
roundGlasses: boolean;
|
|
44
|
+
facialHair: boolean;
|
|
45
|
+
beard: Beard;
|
|
46
|
+
clothing: Clothing;
|
|
47
|
+
brow: Brow;
|
|
48
|
+
nose: Nose;
|
|
49
|
+
/** Draws the asymmetric parts the other way round. */
|
|
50
|
+
flip: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Portraits avatar style
|
|
54
|
+
*
|
|
55
|
+
* Calm, single-colour head-and-shoulders portraits for business and professional
|
|
56
|
+
* tools. Everything is drawn in one ink that reads on the background: hair and
|
|
57
|
+
* clothing as solid masses, so a portrait still reads at 24px, and the face as
|
|
58
|
+
* fine line work over the background colour.
|
|
59
|
+
*
|
|
60
|
+
* Its features can be mixed with other styles: `body`, `hair`, `head`, `eyes`,
|
|
61
|
+
* `eyebrows`, `glasses`, `nose`, `facial-hair` and `mouth`.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { createAvatar } from '@avatar-generator/core';
|
|
66
|
+
* import { portraits } from '@avatar-generator/style-portraits';
|
|
67
|
+
*
|
|
68
|
+
* const avatar = createAvatar(portraits, {
|
|
69
|
+
* seed: 'unique-id',
|
|
70
|
+
* size: 64,
|
|
71
|
+
* hairStyle: 'bob',
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare const portraits: ComposableStyle<PortraitsOptions, PortraitsTraits>;
|
|
76
|
+
|
|
77
|
+
export { EYE_STYLES, HAIR_STYLES, MOUTH_STYLES, type PortraitsEyeStyle, type PortraitsHairStyle, type PortraitsMouthStyle, type PortraitsOptions, type PortraitsTraits, portraits as default, portraits };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
createRandom,
|
|
4
|
+
defineStyle,
|
|
5
|
+
DEFAULT_COLORS,
|
|
6
|
+
readableColor,
|
|
7
|
+
resolveTheme,
|
|
8
|
+
validateOption
|
|
9
|
+
} from "@avatar-generator/core";
|
|
10
|
+
var HAIR_STYLES = [
|
|
11
|
+
"crop",
|
|
12
|
+
"side-part",
|
|
13
|
+
"curly",
|
|
14
|
+
"afro",
|
|
15
|
+
"long",
|
|
16
|
+
"bob",
|
|
17
|
+
"bun",
|
|
18
|
+
"locs",
|
|
19
|
+
"bald"
|
|
20
|
+
];
|
|
21
|
+
var EYE_STYLES = ["dots", "lidded", "smiling", "lashes"];
|
|
22
|
+
var MOUTH_STYLES = ["smile", "grin", "soft", "smirk"];
|
|
23
|
+
var CLOTHING = ["crew", "v-neck", "collar", "turtleneck"];
|
|
24
|
+
var BROWS = ["straight", "arched", "soft"];
|
|
25
|
+
var NOSES = ["hook", "button", "angle"];
|
|
26
|
+
var BEARDS = ["full", "moustache", "goatee"];
|
|
27
|
+
var CANVAS = 64;
|
|
28
|
+
var CX = 32;
|
|
29
|
+
var EYE_X = 26.6;
|
|
30
|
+
var EYE_Y = 29;
|
|
31
|
+
var LINE = 2.4;
|
|
32
|
+
var LENS_X = 27.2;
|
|
33
|
+
var LENS_Y = 28.4;
|
|
34
|
+
var FACE = "M 32 13 C 39.6 13 44 18.4 44 26.5 C 44 35.5 38.6 44 32 44 C 25.4 44 20 35.5 20 26.5 C 20 18.4 24.4 13 32 13 Z";
|
|
35
|
+
var FACE_HOLE = "M 32 13 C 24.4 13 20 18.4 20 26.5 C 20 35.5 25.4 44 32 44 C 38.6 44 44 35.5 44 26.5 C 44 18.4 39.6 13 32 13 Z";
|
|
36
|
+
var round = (value) => Math.round(value * 100) / 100;
|
|
37
|
+
var mirrored = (markup) => `<g transform="matrix(-1 0 0 1 ${CANVAS} 0)">${markup}</g>`;
|
|
38
|
+
var pair = (markup) => markup + mirrored(markup);
|
|
39
|
+
var stroke = (d, ink, width = LINE) => `<path d="${d}" fill="none" stroke="${ink}" stroke-width="${width}" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
40
|
+
var fill = (d, ink, rule = false) => `<path d="${d}" fill="${ink}"${rule ? ' fill-rule="evenodd"' : ""}/>`;
|
|
41
|
+
function scallop(cx, cy, radius, from, to, bumps) {
|
|
42
|
+
const point = (degrees) => {
|
|
43
|
+
const angle = degrees * Math.PI / 180;
|
|
44
|
+
return `${round(cx + radius * Math.cos(angle))} ${round(cy + radius * Math.sin(angle))}`;
|
|
45
|
+
};
|
|
46
|
+
const step = (to - from) / bumps;
|
|
47
|
+
const bump = round(radius * Math.sin(step / 2 * Math.PI / 180) * 1.25);
|
|
48
|
+
let d = `${point(from)}`;
|
|
49
|
+
for (let i = 1; i <= bumps; i++) d += ` A ${bump} ${bump} 0 0 1 ${point(from + step * i)}`;
|
|
50
|
+
return d;
|
|
51
|
+
}
|
|
52
|
+
var paperOf = (traits) => traits.paper ?? "none";
|
|
53
|
+
function hairBehind(traits) {
|
|
54
|
+
const { ink, paper } = traits;
|
|
55
|
+
const gap = paper ? ` stroke="${paper}" stroke-width="3" stroke-linejoin="round"` : "";
|
|
56
|
+
const mass = (d) => (paper ? `<path d="${d}" fill="none"${gap}/>` : "") + `<path d="${d} ${FACE_HOLE}" fill="${ink}" fill-rule="evenodd"/>`;
|
|
57
|
+
switch (traits.hairStyle) {
|
|
58
|
+
case "curly":
|
|
59
|
+
return mass(`M 19 37 L ${scallop(32, 23, 16.2, 150, 390, 12)} L 45 37 Z`);
|
|
60
|
+
case "afro":
|
|
61
|
+
return mass(`M ${scallop(32, 22, 17.5, 0, 360, 14)} Z`);
|
|
62
|
+
case "long":
|
|
63
|
+
return mass(
|
|
64
|
+
"M 32 9.6 C 42.5 9.6 47.4 16 47.4 26 L 47.6 51 C 47.6 53.4 46 54.6 44 54.6 L 41.6 54.6 C 40 54.6 39 53.2 38.8 50.4 L 38.6 43 L 25.4 43 L 25.2 50.4 C 25 53.2 24 54.6 22.4 54.6 L 20 54.6 C 18 54.6 16.4 53.4 16.4 51 L 16.6 26 C 16.6 16 21.5 9.6 32 9.6 Z"
|
|
65
|
+
);
|
|
66
|
+
case "bob":
|
|
67
|
+
return mass(
|
|
68
|
+
"M 32 10 C 42 10 47 16 47 26 L 47 40.5 C 47 43.6 45.2 45.6 42.4 45.6 L 40.4 45.6 C 39 45.6 38.4 44 38.4 41 L 25.6 41 C 25.6 44 25 45.6 23.6 45.6 L 21.6 45.6 C 18.8 45.6 17 43.6 17 40.5 L 17 26 C 17 16 22 10 32 10 Z"
|
|
69
|
+
);
|
|
70
|
+
case "bun":
|
|
71
|
+
return `<circle cx="${CX}" cy="9" r="6"${paper ? ` fill="${ink}" stroke="${paper}" stroke-width="2"` : ` fill="${ink}"`}/>`;
|
|
72
|
+
case "locs": {
|
|
73
|
+
const strands = [
|
|
74
|
+
[14, 20, 48],
|
|
75
|
+
[17.4, 18, 53],
|
|
76
|
+
[20.8, 36, 55.4]
|
|
77
|
+
].map(
|
|
78
|
+
([x, top, bottom]) => `<rect x="${x - 2.1}" y="${top}" width="4.2" height="${bottom - top}" rx="2.1"/>`
|
|
79
|
+
).join("");
|
|
80
|
+
const bunch = (paint) => pair(`<g ${paint}>${strands}</g>`);
|
|
81
|
+
return (paper ? bunch(`fill="${paper}" stroke="${paper}" stroke-width="3"`) : "") + bunch(`fill="${ink}"`);
|
|
82
|
+
}
|
|
83
|
+
default:
|
|
84
|
+
return "";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function hairFront(traits) {
|
|
88
|
+
const { ink } = traits;
|
|
89
|
+
switch (traits.hairStyle) {
|
|
90
|
+
case "crop":
|
|
91
|
+
return fill(
|
|
92
|
+
"M 18.8 28 C 17.6 16 23.5 10.4 32 10.4 C 40.5 10.4 46.4 16 45.2 28 L 43.8 28 C 43.4 23.5 42 20.6 39 19.6 C 35 18.6 29 18.6 25 19.6 C 22 20.6 20.6 23.5 20.2 28 Z",
|
|
93
|
+
ink
|
|
94
|
+
);
|
|
95
|
+
case "side-part": {
|
|
96
|
+
const hair = fill(
|
|
97
|
+
"M 18.8 28 C 17.4 15 23 9.4 31 9.4 C 41 9.4 46.6 15.5 45.2 28 L 43.8 28 C 43.6 22 42.8 19.6 40.6 19 C 35 19.8 29.4 18.6 26.6 15.2 C 24.6 18.6 21.2 21.6 20.2 28 Z",
|
|
98
|
+
ink
|
|
99
|
+
);
|
|
100
|
+
return traits.flip ? mirrored(hair) : hair;
|
|
101
|
+
}
|
|
102
|
+
case "curly":
|
|
103
|
+
return fill(
|
|
104
|
+
`M 19 30 C 18.4 18 24 11 32 11 C 40 11 45.6 18 45 30 L 43.8 30 C 43.4 25 42.4 22.6 41.6 21.6 ${scallop(32, 1.2, 18, 58, 122, 5).replace(/^/, "L ")} C 21.6 22.6 20.6 25 20.2 30 Z`,
|
|
105
|
+
ink
|
|
106
|
+
);
|
|
107
|
+
case "afro":
|
|
108
|
+
return fill(
|
|
109
|
+
"M 19.2 26 L 19.2 10 L 44.8 10 L 44.8 26 L 43.9 26 C 43.4 20.8 39.4 17.6 32 17.6 C 24.6 17.6 20.6 20.8 20.1 26 Z",
|
|
110
|
+
ink
|
|
111
|
+
);
|
|
112
|
+
case "long": {
|
|
113
|
+
const hair = fill(
|
|
114
|
+
"M 30 14.2 C 26 15 22.4 17.6 21.4 24 C 20.6 30 21 38 21.8 47 L 18.2 47 L 18.2 26 C 18.4 15 24 10.6 32 10.6 C 40 10.6 45.6 15 45.8 26 L 45.8 47 L 42.2 47 C 43 38 43.4 30 42.6 24 C 41.6 17.6 35.4 14.2 30 14.2 Z",
|
|
115
|
+
ink
|
|
116
|
+
);
|
|
117
|
+
return traits.flip ? mirrored(hair) : hair;
|
|
118
|
+
}
|
|
119
|
+
case "bob":
|
|
120
|
+
return fill(
|
|
121
|
+
"M 18.8 40 L 18.6 26 C 18.6 15.5 24 11 32 11 C 40 11 45.4 15.5 45.4 26 L 45.2 40 L 43 40 C 43.4 33 43.4 27 42.6 20 Q 32 21 21.4 20 C 20.6 27 20.6 33 21 40 Z",
|
|
122
|
+
ink
|
|
123
|
+
);
|
|
124
|
+
case "bun":
|
|
125
|
+
return fill(
|
|
126
|
+
"M 19.4 28 C 19 17 24.5 11.6 32 11.6 C 39.5 11.6 45 17 44.6 28 L 43.8 28 C 43.4 22 40.6 18.4 32 18 C 23.4 18.4 20.6 22 20.2 28 Z",
|
|
127
|
+
ink
|
|
128
|
+
);
|
|
129
|
+
case "locs":
|
|
130
|
+
return fill(
|
|
131
|
+
"M 18.8 30 C 17.8 16 23.5 10.4 32 10.4 C 40.5 10.4 46.2 16 45.2 30 L 43.8 30 C 43.4 24 41.6 20.4 37.6 19.4 C 34.6 18.8 29.4 18.8 26.4 19.4 C 22.4 20.4 20.6 24 20.2 30 Z",
|
|
132
|
+
ink
|
|
133
|
+
);
|
|
134
|
+
case "bald":
|
|
135
|
+
return "";
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function drawBody(traits) {
|
|
139
|
+
const { ink } = traits;
|
|
140
|
+
const neck = (bottom) => stroke(`M 28.2 39 L 28.2 ${bottom}`, ink) + stroke(`M 35.8 39 L 35.8 ${bottom}`, ink);
|
|
141
|
+
const shoulders = (top, neckline) => `M 4 64 C 4.6 55.4 10.4 ${top + 1.6} 20.6 ${top} ${neckline} C 53.6 ${top + 1.6} 59.4 55.4 60 64 Z`;
|
|
142
|
+
switch (traits.clothing) {
|
|
143
|
+
case "crew":
|
|
144
|
+
return neck(52) + fill(shoulders(49.4, "L 26.8 49.4 C 28 53.8 36 53.8 37.2 49.4 L 43.4 49.4"), ink);
|
|
145
|
+
case "v-neck":
|
|
146
|
+
return neck(55) + fill(shoulders(49.4, "L 26.6 49.4 L 32 57.4 L 37.4 49.4 L 43.4 49.4"), ink);
|
|
147
|
+
case "collar":
|
|
148
|
+
return neck(51) + fill(shoulders(49.4, "L 25.8 49.4 L 32 64 L 38.2 49.4 L 43.4 49.4"), ink) + fill("M 30.2 50 L 33.8 50 L 33 52.6 L 34.2 59.6 L 32 61.8 L 29.8 59.6 L 31 52.6 Z", ink);
|
|
149
|
+
case "turtleneck":
|
|
150
|
+
return `<rect x="26" y="41.4" width="12" height="7.2" rx="2.6" fill="${ink}"/>` + fill(shoulders(49.8, "L 43.4 49.8"), ink);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function drawHead(traits) {
|
|
154
|
+
const { ink } = traits;
|
|
155
|
+
const paper = paperOf(traits);
|
|
156
|
+
const ear = `<path d="M 20.6 26.4 C 17.2 25.8 17 32.4 20.8 32.2" fill="${paper}" stroke="${ink}" stroke-width="${LINE}" stroke-linecap="round"/>`;
|
|
157
|
+
return pair(ear) + `<path d="${FACE}" fill="${paper}" stroke="${ink}" stroke-width="${LINE}" stroke-linejoin="round"/>`;
|
|
158
|
+
}
|
|
159
|
+
function drawEyes(traits) {
|
|
160
|
+
const { ink } = traits;
|
|
161
|
+
if (traits.glasses) return pair(`<circle cx="${LENS_X}" cy="${LENS_Y}" r="1.1" fill="${ink}"/>`);
|
|
162
|
+
const x = EYE_X;
|
|
163
|
+
const y = EYE_Y;
|
|
164
|
+
switch (traits.eyeStyle) {
|
|
165
|
+
case "dots":
|
|
166
|
+
return pair(`<ellipse cx="${x}" cy="${y}" rx="1.9" ry="2.2" fill="${ink}"/>`);
|
|
167
|
+
case "lidded":
|
|
168
|
+
return pair(
|
|
169
|
+
stroke(`M ${x - 3.1} ${y - 0.2} Q ${x} ${y - 2.8} ${x + 3.1} ${y - 0.2}`, ink, 2.2) + `<circle cx="${x}" cy="${y + 0.5}" r="1.7" fill="${ink}"/>`
|
|
170
|
+
);
|
|
171
|
+
case "smiling":
|
|
172
|
+
return pair(stroke(`M ${x - 3} ${y + 1} Q ${x} ${y - 2.6} ${x + 3} ${y + 1}`, ink));
|
|
173
|
+
case "lashes":
|
|
174
|
+
return pair(
|
|
175
|
+
`<ellipse cx="${x}" cy="${y}" rx="1.9" ry="2.2" fill="${ink}"/>` + stroke(`M ${x - 2.3} ${y - 1} L ${x - 3.9} ${y - 1.8}`, ink, 2.2)
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function drawEyebrows(traits) {
|
|
180
|
+
if (traits.glasses) return "";
|
|
181
|
+
const { ink } = traits;
|
|
182
|
+
switch (traits.brow) {
|
|
183
|
+
case "straight":
|
|
184
|
+
return pair(stroke("M 23.8 24.4 L 29.4 23.9", ink));
|
|
185
|
+
case "arched":
|
|
186
|
+
return pair(stroke("M 23.8 25 Q 26.2 22.4 29.4 23.8", ink));
|
|
187
|
+
case "soft":
|
|
188
|
+
return pair(stroke("M 23.8 24.6 Q 27.2 23 29.6 24.2", ink));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function drawGlasses(traits) {
|
|
192
|
+
if (!traits.glasses) return "";
|
|
193
|
+
const { ink } = traits;
|
|
194
|
+
const lens = traits.roundGlasses ? `<circle cx="${LENS_X}" cy="${LENS_Y}" r="2.8"` : `<rect x="${LENS_X - 2.8}" y="${LENS_Y - 2.6}" width="5.6" height="5.2" rx="1.8"`;
|
|
195
|
+
return pair(`${lens} fill="none" stroke="${ink}" stroke-width="2.2"/>`) + stroke(`M 30.6 ${LENS_Y - 1.2} Q 32 ${LENS_Y - 2.2} 33.4 ${LENS_Y - 1.2}`, ink, 2.2);
|
|
196
|
+
}
|
|
197
|
+
function drawNose(traits) {
|
|
198
|
+
const { ink, glasses } = traits;
|
|
199
|
+
let d;
|
|
200
|
+
switch (traits.nose) {
|
|
201
|
+
case "hook":
|
|
202
|
+
d = glasses ? "M 32.6 32.8 C 33.4 33.6 34.2 34.2 32.2 34.8" : "M 32.6 30 C 33.6 32 34.6 33.6 32.2 34.4";
|
|
203
|
+
break;
|
|
204
|
+
case "button":
|
|
205
|
+
d = glasses ? "M 30.4 34 Q 32 35.6 33.6 34" : "M 30.4 33.6 Q 32 35.2 33.6 33.6";
|
|
206
|
+
break;
|
|
207
|
+
case "angle":
|
|
208
|
+
d = glasses ? "M 32 32.8 L 31.3 34.6 L 33 34.8" : "M 32 30 L 31 34 L 33 34.2";
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
const nose = stroke(d, ink, 2.2);
|
|
212
|
+
return traits.flip ? mirrored(nose) : nose;
|
|
213
|
+
}
|
|
214
|
+
function drawFacialHair(traits) {
|
|
215
|
+
if (!traits.facialHair) return "";
|
|
216
|
+
const { ink } = traits;
|
|
217
|
+
const moustache = "M 27 37 C 28.4 34.8 30.8 34.8 32 35.8 C 33.2 34.8 35.6 34.8 37 37 C 35.2 36.6 33.6 36.8 32 37.2 C 30.4 36.8 28.8 36.6 27 37 Z";
|
|
218
|
+
switch (traits.beard) {
|
|
219
|
+
case "full":
|
|
220
|
+
return fill(
|
|
221
|
+
"M 20.4 30 C 21 38 25.4 45.6 32 45.6 C 38.6 45.6 43 38 43.6 30 C 42 34 39.6 35.4 36.6 35.2 C 35 34.8 33.4 34.8 32 35.6 C 30.6 34.8 29 34.8 27.4 35.2 C 24.4 35.4 22 34 20.4 30 Z M 26.6 38.6 C 26.6 41.6 29 42 32 42 C 35 42 37.4 41.6 37.4 38.6 C 35.6 37.4 28.4 37.4 26.6 38.6 Z",
|
|
222
|
+
ink,
|
|
223
|
+
true
|
|
224
|
+
);
|
|
225
|
+
case "moustache":
|
|
226
|
+
return fill(moustache, ink);
|
|
227
|
+
case "goatee":
|
|
228
|
+
return fill(moustache, ink) + fill("M 28.4 42 Q 32 40.8 35.6 42 Q 35.2 45.8 32 46 Q 28.8 45.8 28.4 42 Z", ink);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function drawMouth(traits) {
|
|
232
|
+
const { ink } = traits;
|
|
233
|
+
switch (traits.mouthStyle) {
|
|
234
|
+
case "smile":
|
|
235
|
+
return stroke("M 28 38 Q 32 41.6 36 38", ink);
|
|
236
|
+
case "grin":
|
|
237
|
+
return `<path d="M 27.8 37.6 Q 32 38.6 36.2 37.6 Q 35.6 42.2 32 42.2 Q 28.4 42.2 27.8 37.6 Z" fill="${ink}" stroke="${ink}" stroke-width="1" stroke-linejoin="round"/>`;
|
|
238
|
+
case "soft":
|
|
239
|
+
return stroke("M 29.2 38.6 Q 32 40.4 34.8 38.6", ink);
|
|
240
|
+
case "smirk": {
|
|
241
|
+
const mouth = stroke("M 28.6 39 Q 32 40.6 35.6 37.8", ink);
|
|
242
|
+
return traits.flip ? mirrored(mouth) : mouth;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function backgroundFor(options, random) {
|
|
247
|
+
return random.pick(options.colors ?? DEFAULT_COLORS);
|
|
248
|
+
}
|
|
249
|
+
function preparePortraits(options, random) {
|
|
250
|
+
const background = backgroundFor(options, createRandom(`${options.seed}:background`));
|
|
251
|
+
const automatic = options.transparent ? background : readableColor(background);
|
|
252
|
+
return {
|
|
253
|
+
ink: options.ink ?? resolveTheme(options.theme)?.foreground ?? automatic,
|
|
254
|
+
paper: options.transparent ? void 0 : background,
|
|
255
|
+
hairStyle: options.hairStyle ?? random.pick(HAIR_STYLES),
|
|
256
|
+
eyeStyle: options.eyeStyle ?? random.pick(EYE_STYLES),
|
|
257
|
+
mouthStyle: options.mouthStyle ?? random.pick(MOUTH_STYLES),
|
|
258
|
+
glasses: options.glasses ?? random.bool(0.25),
|
|
259
|
+
roundGlasses: random.bool(0.5),
|
|
260
|
+
facialHair: options.facialHair ?? random.bool(0.22),
|
|
261
|
+
beard: random.pick(BEARDS),
|
|
262
|
+
clothing: random.pick(CLOTHING),
|
|
263
|
+
brow: random.pick(BROWS),
|
|
264
|
+
nose: random.pick(NOSES),
|
|
265
|
+
flip: random.bool(0.5)
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
var portraits = defineStyle({
|
|
269
|
+
name: "portraits",
|
|
270
|
+
canvas: CANVAS,
|
|
271
|
+
validate(options) {
|
|
272
|
+
validateOption("portraits", "hairStyle", options.hairStyle, HAIR_STYLES);
|
|
273
|
+
validateOption("portraits", "eyeStyle", options.eyeStyle, EYE_STYLES);
|
|
274
|
+
validateOption("portraits", "mouthStyle", options.mouthStyle, MOUTH_STYLES);
|
|
275
|
+
},
|
|
276
|
+
prepare: preparePortraits,
|
|
277
|
+
background: backgroundFor,
|
|
278
|
+
head: () => ({ x: 20, y: 13, width: 24, height: 31 }),
|
|
279
|
+
layers: [
|
|
280
|
+
{ name: "body", render: ({ traits }) => drawBody(traits) },
|
|
281
|
+
{ name: "hair-behind", feature: "hair", render: ({ traits }) => hairBehind(traits) },
|
|
282
|
+
{ name: "head", render: ({ traits }) => drawHead(traits) },
|
|
283
|
+
{ name: "hair-front", feature: "hair", render: ({ traits }) => hairFront(traits) },
|
|
284
|
+
{ name: "eyes", render: ({ traits }) => drawEyes(traits) },
|
|
285
|
+
{ name: "eyebrows", render: ({ traits }) => drawEyebrows(traits) },
|
|
286
|
+
{ name: "glasses", render: ({ traits }) => drawGlasses(traits) },
|
|
287
|
+
{ name: "nose", render: ({ traits }) => drawNose(traits) },
|
|
288
|
+
{ name: "facial-hair", render: ({ traits }) => drawFacialHair(traits) },
|
|
289
|
+
{ name: "mouth", render: ({ traits }) => drawMouth(traits) }
|
|
290
|
+
]
|
|
291
|
+
});
|
|
292
|
+
var index_default = portraits;
|
|
293
|
+
export {
|
|
294
|
+
EYE_STYLES,
|
|
295
|
+
HAIR_STYLES,
|
|
296
|
+
MOUTH_STYLES,
|
|
297
|
+
index_default as default,
|
|
298
|
+
portraits
|
|
299
|
+
};
|
|
300
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AvatarOptions, ComposableStyle, Random } from \"@avatar-generator/core\";\nimport {\n createRandom,\n defineStyle,\n DEFAULT_COLORS,\n readableColor,\n resolveTheme,\n validateOption,\n} from \"@avatar-generator/core\";\n\n// ============================================================================\n// Options\n// ============================================================================\n\nexport type PortraitsHairStyle = \"crop\" | \"side-part\" | \"curly\" | \"afro\" | \"long\" | \"bob\" | \"bun\" | \"locs\" | \"bald\";\n\nexport type PortraitsEyeStyle = \"dots\" | \"lidded\" | \"smiling\" | \"lashes\";\n\nexport type PortraitsMouthStyle = \"smile\" | \"grin\" | \"soft\" | \"smirk\";\n\nexport interface PortraitsOptions extends AvatarOptions {\n /** Override hair style */\n hairStyle?: PortraitsHairStyle;\n /** Override eye style */\n eyeStyle?: PortraitsEyeStyle;\n /** Override mouth style */\n mouthStyle?: PortraitsMouthStyle;\n /** Force glasses on or off (default: chosen by the seed) */\n glasses?: boolean;\n /** Force facial hair on or off (default: chosen by the seed) */\n facialHair?: boolean;\n /**\n * The one colour everything is drawn in. Defaults to the theme's foreground,\n * otherwise white or near-black, whichever reads better on the background.\n */\n ink?: string;\n}\n\n/** All valid hair style values for the portraits style */\nexport const HAIR_STYLES: PortraitsHairStyle[] = [\n \"crop\",\n \"side-part\",\n \"curly\",\n \"afro\",\n \"long\",\n \"bob\",\n \"bun\",\n \"locs\",\n \"bald\",\n];\n\n/** All valid eye style values for the portraits style */\nexport const EYE_STYLES: PortraitsEyeStyle[] = [\"dots\", \"lidded\", \"smiling\", \"lashes\"];\n\n/** All valid mouth style values for the portraits style */\nexport const MOUTH_STYLES: PortraitsMouthStyle[] = [\"smile\", \"grin\", \"soft\", \"smirk\"];\n\ntype Clothing = \"crew\" | \"v-neck\" | \"collar\" | \"turtleneck\";\ntype Brow = \"straight\" | \"arched\" | \"soft\";\ntype Nose = \"hook\" | \"button\" | \"angle\";\ntype Beard = \"full\" | \"moustache\" | \"goatee\";\n\nconst CLOTHING: Clothing[] = [\"crew\", \"v-neck\", \"collar\", \"turtleneck\"];\nconst BROWS: Brow[] = [\"straight\", \"arched\", \"soft\"];\nconst NOSES: Nose[] = [\"hook\", \"button\", \"angle\"];\nconst BEARDS: Beard[] = [\"full\", \"moustache\", \"goatee\"];\n\n// Everything is drawn on this canvas and scaled by the SVG, so plain numbers stay\n// in proportion at any size.\nconst CANVAS = 64;\nconst CX = 32;\nconst EYE_X = 26.6;\nconst EYE_Y = 29;\nconst LINE = 2.4;\n/** Where each lens sits: nearer the middle and a little higher than the eyes. */\nconst LENS_X = 27.2;\nconst LENS_Y = 28.4;\n\n/** An egg-shaped face, a little narrower at the jaw. */\nconst FACE =\n \"M 32 13 C 39.6 13 44 18.4 44 26.5 C 44 35.5 38.6 44 32 44 C 25.4 44 20 35.5 20 26.5 C 20 18.4 24.4 13 32 13 Z\";\n\n/** The same outline run the other way, to punch the face out of hair drawn behind it. */\nconst FACE_HOLE =\n \"M 32 13 C 24.4 13 20 18.4 20 26.5 C 20 35.5 25.4 44 32 44 C 38.6 44 44 35.5 44 26.5 C 44 18.4 39.6 13 32 13 Z\";\n\nconst round = (value: number): number => Math.round(value * 100) / 100;\n\n/** Reflects markup drawn for the left side onto the right. */\nconst mirrored = (markup: string): string => `<g transform=\"matrix(-1 0 0 1 ${CANVAS} 0)\">${markup}</g>`;\n\n/** Draws something on the left and its reflection on the right. */\nconst pair = (markup: string): string => markup + mirrored(markup);\n\nconst stroke = (d: string, ink: string, width = LINE): string =>\n `<path d=\"${d}\" fill=\"none\" stroke=\"${ink}\" stroke-width=\"${width}\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>`;\n\nconst fill = (d: string, ink: string, rule = false): string =>\n `<path d=\"${d}\" fill=\"${ink}\"${rule ? ' fill-rule=\"evenodd\"' : \"\"}/>`;\n\n/**\n * A run of round bumps along a circle, for curls. Angles are in degrees,\n * clockwise from the right, so 180 to 360 runs over the top.\n */\nfunction scallop(cx: number, cy: number, radius: number, from: number, to: number, bumps: number): string {\n const point = (degrees: number) => {\n const angle = (degrees * Math.PI) / 180;\n return `${round(cx + radius * Math.cos(angle))} ${round(cy + radius * Math.sin(angle))}`;\n };\n const step = (to - from) / bumps;\n const bump = round(radius * Math.sin(((step / 2) * Math.PI) / 180) * 1.25);\n let d = `${point(from)}`;\n for (let i = 1; i <= bumps; i++) d += ` A ${bump} ${bump} 0 0 1 ${point(from + step * i)}`;\n return d;\n}\n\n/** What the seed decides for one portrait. */\nexport interface PortraitsTraits {\n /** The colour every line and mass is drawn in. */\n ink: string;\n /** The background showing through, or `undefined` when there is none. */\n paper: string | undefined;\n hairStyle: PortraitsHairStyle;\n eyeStyle: PortraitsEyeStyle;\n mouthStyle: PortraitsMouthStyle;\n glasses: boolean;\n roundGlasses: boolean;\n facialHair: boolean;\n beard: Beard;\n clothing: Clothing;\n brow: Brow;\n nose: Nose;\n /** Draws the asymmetric parts the other way round. */\n flip: boolean;\n}\n\n/** Where the fill under a line goes: the background, or nothing on a transparent avatar. */\nconst paperOf = (traits: PortraitsTraits): string => traits.paper ?? \"none\";\n\n// ─── Hair ─────────────────────────────────────────────────────────────────\n\n/** Hair that sits behind the head. The face is cut out, so nothing shows through it. */\nfunction hairBehind(traits: PortraitsTraits): string {\n const { ink, paper } = traits;\n // A thin gap in the background colour keeps hair apart from the clothes below.\n const gap = paper ? ` stroke=\"${paper}\" stroke-width=\"3\" stroke-linejoin=\"round\"` : \"\";\n // The gap is drawn first and half covered, so it falls outside the hair.\n const mass = (d: string) =>\n (paper ? `<path d=\"${d}\" fill=\"none\"${gap}/>` : \"\") +\n `<path d=\"${d} ${FACE_HOLE}\" fill=\"${ink}\" fill-rule=\"evenodd\"/>`;\n\n switch (traits.hairStyle) {\n case \"curly\":\n return mass(`M 19 37 L ${scallop(32, 23, 16.2, 150, 390, 12)} L 45 37 Z`);\n case \"afro\":\n return mass(`M ${scallop(32, 22, 17.5, 0, 360, 14)} Z`);\n case \"long\":\n return mass(\n \"M 32 9.6 C 42.5 9.6 47.4 16 47.4 26 L 47.6 51 C 47.6 53.4 46 54.6 44 54.6 L 41.6 54.6 C 40 54.6 39 53.2 38.8 50.4 L 38.6 43 L 25.4 43 L 25.2 50.4 C 25 53.2 24 54.6 22.4 54.6 L 20 54.6 C 18 54.6 16.4 53.4 16.4 51 L 16.6 26 C 16.6 16 21.5 9.6 32 9.6 Z\",\n );\n case \"bob\":\n return mass(\n \"M 32 10 C 42 10 47 16 47 26 L 47 40.5 C 47 43.6 45.2 45.6 42.4 45.6 L 40.4 45.6 C 39 45.6 38.4 44 38.4 41 L 25.6 41 C 25.6 44 25 45.6 23.6 45.6 L 21.6 45.6 C 18.8 45.6 17 43.6 17 40.5 L 17 26 C 17 16 22 10 32 10 Z\",\n );\n case \"bun\":\n return `<circle cx=\"${CX}\" cy=\"9\" r=\"6\"${paper ? ` fill=\"${ink}\" stroke=\"${paper}\" stroke-width=\"2\"` : ` fill=\"${ink}\"`}/>`;\n case \"locs\": {\n // Rounded strands falling past the shoulders, kept clear of the face.\n const strands = [\n [14, 20, 48],\n [17.4, 18, 53],\n [20.8, 36, 55.4],\n ]\n .map(\n ([x, top, bottom]) =>\n `<rect x=\"${x - 2.1}\" y=\"${top}\" width=\"4.2\" height=\"${bottom - top}\" rx=\"2.1\"/>`,\n )\n .join(\"\");\n // The gap goes round the whole bunch, not between the strands.\n const bunch = (paint: string) => pair(`<g ${paint}>${strands}</g>`);\n return (paper ? bunch(`fill=\"${paper}\" stroke=\"${paper}\" stroke-width=\"3\"`) : \"\") + bunch(`fill=\"${ink}\"`);\n }\n default:\n return \"\";\n }\n}\n\n/** Hair in front of the head: the hairline and anything framing the face. */\nfunction hairFront(traits: PortraitsTraits): string {\n const { ink } = traits;\n switch (traits.hairStyle) {\n case \"crop\":\n return fill(\n \"M 18.8 28 C 17.6 16 23.5 10.4 32 10.4 C 40.5 10.4 46.4 16 45.2 28 L 43.8 28 C 43.4 23.5 42 20.6 39 19.6 C 35 18.6 29 18.6 25 19.6 C 22 20.6 20.6 23.5 20.2 28 Z\",\n ink,\n );\n case \"side-part\": {\n const hair = fill(\n \"M 18.8 28 C 17.4 15 23 9.4 31 9.4 C 41 9.4 46.6 15.5 45.2 28 L 43.8 28 C 43.6 22 42.8 19.6 40.6 19 C 35 19.8 29.4 18.6 26.6 15.2 C 24.6 18.6 21.2 21.6 20.2 28 Z\",\n ink,\n );\n return traits.flip ? mirrored(hair) : hair;\n }\n case \"curly\":\n return fill(\n `M 19 30 C 18.4 18 24 11 32 11 C 40 11 45.6 18 45 30 L 43.8 30 C 43.4 25 42.4 22.6 41.6 21.6 ${scallop(32, 1.2, 18, 58, 122, 5).replace(/^/, \"L \")} C 21.6 22.6 20.6 25 20.2 30 Z`,\n ink,\n );\n case \"afro\":\n return fill(\n \"M 19.2 26 L 19.2 10 L 44.8 10 L 44.8 26 L 43.9 26 C 43.4 20.8 39.4 17.6 32 17.6 C 24.6 17.6 20.6 20.8 20.1 26 Z\",\n ink,\n );\n case \"long\": {\n const hair = fill(\n \"M 30 14.2 C 26 15 22.4 17.6 21.4 24 C 20.6 30 21 38 21.8 47 L 18.2 47 L 18.2 26 C 18.4 15 24 10.6 32 10.6 C 40 10.6 45.6 15 45.8 26 L 45.8 47 L 42.2 47 C 43 38 43.4 30 42.6 24 C 41.6 17.6 35.4 14.2 30 14.2 Z\",\n ink,\n );\n return traits.flip ? mirrored(hair) : hair;\n }\n case \"bob\":\n return fill(\n \"M 18.8 40 L 18.6 26 C 18.6 15.5 24 11 32 11 C 40 11 45.4 15.5 45.4 26 L 45.2 40 L 43 40 C 43.4 33 43.4 27 42.6 20 Q 32 21 21.4 20 C 20.6 27 20.6 33 21 40 Z\",\n ink,\n );\n case \"bun\":\n return fill(\n \"M 19.4 28 C 19 17 24.5 11.6 32 11.6 C 39.5 11.6 45 17 44.6 28 L 43.8 28 C 43.4 22 40.6 18.4 32 18 C 23.4 18.4 20.6 22 20.2 28 Z\",\n ink,\n );\n case \"locs\":\n return fill(\n \"M 18.8 30 C 17.8 16 23.5 10.4 32 10.4 C 40.5 10.4 46.2 16 45.2 30 L 43.8 30 C 43.4 24 41.6 20.4 37.6 19.4 C 34.6 18.8 29.4 18.8 26.4 19.4 C 22.4 20.4 20.6 24 20.2 30 Z\",\n ink,\n );\n case \"bald\":\n return \"\";\n }\n}\n\n// ─── Body and head ────────────────────────────────────────────────────────\n\nfunction drawBody(traits: PortraitsTraits): string {\n const { ink } = traits;\n const neck = (bottom: number) =>\n stroke(`M 28.2 39 L 28.2 ${bottom}`, ink) + stroke(`M 35.8 39 L 35.8 ${bottom}`, ink);\n const shoulders = (top: number, neckline: string) =>\n `M 4 64 C 4.6 55.4 10.4 ${top + 1.6} 20.6 ${top} ${neckline} C 53.6 ${top + 1.6} 59.4 55.4 60 64 Z`;\n\n switch (traits.clothing) {\n case \"crew\":\n return neck(52) + fill(shoulders(49.4, \"L 26.8 49.4 C 28 53.8 36 53.8 37.2 49.4 L 43.4 49.4\"), ink);\n case \"v-neck\":\n return neck(55) + fill(shoulders(49.4, \"L 26.6 49.4 L 32 57.4 L 37.4 49.4 L 43.4 49.4\"), ink);\n case \"collar\":\n // A jacket open over a shirt and tie.\n return (\n neck(51) +\n fill(shoulders(49.4, \"L 25.8 49.4 L 32 64 L 38.2 49.4 L 43.4 49.4\"), ink) +\n fill(\"M 30.2 50 L 33.8 50 L 33 52.6 L 34.2 59.6 L 32 61.8 L 29.8 59.6 L 31 52.6 Z\", ink)\n );\n case \"turtleneck\":\n return (\n `<rect x=\"26\" y=\"41.4\" width=\"12\" height=\"7.2\" rx=\"2.6\" fill=\"${ink}\"/>` +\n fill(shoulders(49.8, \"L 43.4 49.8\"), ink)\n );\n }\n}\n\nfunction drawHead(traits: PortraitsTraits): string {\n const { ink } = traits;\n const paper = paperOf(traits);\n const ear = `<path d=\"M 20.6 26.4 C 17.2 25.8 17 32.4 20.8 32.2\" fill=\"${paper}\" stroke=\"${ink}\" stroke-width=\"${LINE}\" stroke-linecap=\"round\"/>`;\n return (\n pair(ear) + `<path d=\"${FACE}\" fill=\"${paper}\" stroke=\"${ink}\" stroke-width=\"${LINE}\" stroke-linejoin=\"round\"/>`\n );\n}\n\n// ─── Features ─────────────────────────────────────────────────────────────\n\nfunction drawEyes(traits: PortraitsTraits): string {\n const { ink } = traits;\n // Behind lenses, plain dots keep the glass clear: anything more reads as a mask.\n if (traits.glasses) return pair(`<circle cx=\"${LENS_X}\" cy=\"${LENS_Y}\" r=\"1.1\" fill=\"${ink}\"/>`);\n const x = EYE_X;\n const y = EYE_Y;\n switch (traits.eyeStyle) {\n case \"dots\":\n return pair(`<ellipse cx=\"${x}\" cy=\"${y}\" rx=\"1.9\" ry=\"2.2\" fill=\"${ink}\"/>`);\n case \"lidded\":\n // An upper lid over the pupil: calm and attentive, not sleepy.\n return pair(\n stroke(`M ${x - 3.1} ${y - 0.2} Q ${x} ${y - 2.8} ${x + 3.1} ${y - 0.2}`, ink, 2.2) +\n `<circle cx=\"${x}\" cy=\"${y + 0.5}\" r=\"1.7\" fill=\"${ink}\"/>`,\n );\n case \"smiling\":\n return pair(stroke(`M ${x - 3} ${y + 1} Q ${x} ${y - 2.6} ${x + 3} ${y + 1}`, ink));\n case \"lashes\":\n return pair(\n `<ellipse cx=\"${x}\" cy=\"${y}\" rx=\"1.9\" ry=\"2.2\" fill=\"${ink}\"/>` +\n stroke(`M ${x - 2.3} ${y - 1} L ${x - 3.9} ${y - 1.8}`, ink, 2.2),\n );\n }\n}\n\nfunction drawEyebrows(traits: PortraitsTraits): string {\n // The top of a frame stands in for the brows: both would merge into one dark band.\n if (traits.glasses) return \"\";\n const { ink } = traits;\n switch (traits.brow) {\n case \"straight\":\n return pair(stroke(\"M 23.8 24.4 L 29.4 23.9\", ink));\n case \"arched\":\n return pair(stroke(\"M 23.8 25 Q 26.2 22.4 29.4 23.8\", ink));\n case \"soft\":\n return pair(stroke(\"M 23.8 24.6 Q 27.2 23 29.6 24.2\", ink));\n }\n}\n\nfunction drawGlasses(traits: PortraitsTraits): string {\n if (!traits.glasses) return \"\";\n const { ink } = traits;\n // Small lenses with background all round them, so frames, hair and the\n // face edge stay apart at any size.\n const lens = traits.roundGlasses\n ? `<circle cx=\"${LENS_X}\" cy=\"${LENS_Y}\" r=\"2.8\"`\n : `<rect x=\"${LENS_X - 2.8}\" y=\"${LENS_Y - 2.6}\" width=\"5.6\" height=\"5.2\" rx=\"1.8\"`;\n return (\n pair(`${lens} fill=\"none\" stroke=\"${ink}\" stroke-width=\"2.2\"/>`) +\n stroke(`M 30.6 ${LENS_Y - 1.2} Q 32 ${LENS_Y - 2.2} 33.4 ${LENS_Y - 1.2}`, ink, 2.2)\n );\n}\n\nfunction drawNose(traits: PortraitsTraits): string {\n // Under glasses, a shorter nose starts below the lenses rather than between them.\n const { ink, glasses } = traits;\n let d: string;\n switch (traits.nose) {\n case \"hook\":\n d = glasses ? \"M 32.6 32.8 C 33.4 33.6 34.2 34.2 32.2 34.8\" : \"M 32.6 30 C 33.6 32 34.6 33.6 32.2 34.4\";\n break;\n case \"button\":\n d = glasses ? \"M 30.4 34 Q 32 35.6 33.6 34\" : \"M 30.4 33.6 Q 32 35.2 33.6 33.6\";\n break;\n case \"angle\":\n d = glasses ? \"M 32 32.8 L 31.3 34.6 L 33 34.8\" : \"M 32 30 L 31 34 L 33 34.2\";\n break;\n }\n const nose = stroke(d, ink, 2.2);\n return traits.flip ? mirrored(nose) : nose;\n}\n\nfunction drawFacialHair(traits: PortraitsTraits): string {\n if (!traits.facialHair) return \"\";\n const { ink } = traits;\n const moustache =\n \"M 27 37 C 28.4 34.8 30.8 34.8 32 35.8 C 33.2 34.8 35.6 34.8 37 37 C 35.2 36.6 33.6 36.8 32 37.2 C 30.4 36.8 28.8 36.6 27 37 Z\";\n switch (traits.beard) {\n case \"full\":\n // A beard along the jaw, open around the mouth.\n return fill(\n \"M 20.4 30 C 21 38 25.4 45.6 32 45.6 C 38.6 45.6 43 38 43.6 30 C 42 34 39.6 35.4 36.6 35.2 C 35 34.8 33.4 34.8 32 35.6 C 30.6 34.8 29 34.8 27.4 35.2 C 24.4 35.4 22 34 20.4 30 Z \" +\n \"M 26.6 38.6 C 26.6 41.6 29 42 32 42 C 35 42 37.4 41.6 37.4 38.6 C 35.6 37.4 28.4 37.4 26.6 38.6 Z\",\n ink,\n true,\n );\n case \"moustache\":\n return fill(moustache, ink);\n case \"goatee\":\n return (\n fill(moustache, ink) + fill(\"M 28.4 42 Q 32 40.8 35.6 42 Q 35.2 45.8 32 46 Q 28.8 45.8 28.4 42 Z\", ink)\n );\n }\n}\n\nfunction drawMouth(traits: PortraitsTraits): string {\n const { ink } = traits;\n switch (traits.mouthStyle) {\n case \"smile\":\n return stroke(\"M 28 38 Q 32 41.6 36 38\", ink);\n case \"grin\":\n return `<path d=\"M 27.8 37.6 Q 32 38.6 36.2 37.6 Q 35.6 42.2 32 42.2 Q 28.4 42.2 27.8 37.6 Z\" fill=\"${ink}\" stroke=\"${ink}\" stroke-width=\"1\" stroke-linejoin=\"round\"/>`;\n case \"soft\":\n return stroke(\"M 29.2 38.6 Q 32 40.4 34.8 38.6\", ink);\n case \"smirk\": {\n const mouth = stroke(\"M 28.6 39 Q 32 40.6 35.6 37.8\", ink);\n return traits.flip ? mirrored(mouth) : mouth;\n }\n }\n}\n\n// ─── Traits ───────────────────────────────────────────────────────────────\n\n/**\n * The background the avatar will get. It is drawn from its own stream, as\n * `defineStyle` does, so the ink can be chosen against it before any layer runs.\n */\nfunction backgroundFor(options: PortraitsOptions, random: Random): string {\n return random.pick(options.colors ?? DEFAULT_COLORS);\n}\n\nfunction preparePortraits(options: PortraitsOptions, random: Random): PortraitsTraits {\n const background = backgroundFor(options, createRandom(`${options.seed}:background`));\n // With no background, the page behind could be any colour. The palette's\n // mid-tones hold up on both light and dark, where black or white would vanish.\n const automatic = options.transparent ? background : readableColor(background);\n\n return {\n ink: options.ink ?? resolveTheme(options.theme)?.foreground ?? automatic,\n paper: options.transparent ? undefined : background,\n hairStyle: options.hairStyle ?? random.pick(HAIR_STYLES),\n eyeStyle: options.eyeStyle ?? random.pick(EYE_STYLES),\n mouthStyle: options.mouthStyle ?? random.pick(MOUTH_STYLES),\n glasses: options.glasses ?? random.bool(0.25),\n roundGlasses: random.bool(0.5),\n facialHair: options.facialHair ?? random.bool(0.22),\n beard: random.pick(BEARDS),\n clothing: random.pick(CLOTHING),\n brow: random.pick(BROWS),\n nose: random.pick(NOSES),\n flip: random.bool(0.5),\n };\n}\n\n/**\n * Portraits avatar style\n *\n * Calm, single-colour head-and-shoulders portraits for business and professional\n * tools. Everything is drawn in one ink that reads on the background: hair and\n * clothing as solid masses, so a portrait still reads at 24px, and the face as\n * fine line work over the background colour.\n *\n * Its features can be mixed with other styles: `body`, `hair`, `head`, `eyes`,\n * `eyebrows`, `glasses`, `nose`, `facial-hair` and `mouth`.\n *\n * @example\n * ```ts\n * import { createAvatar } from '@avatar-generator/core';\n * import { portraits } from '@avatar-generator/style-portraits';\n *\n * const avatar = createAvatar(portraits, {\n * seed: 'unique-id',\n * size: 64,\n * hairStyle: 'bob',\n * });\n * ```\n */\nexport const portraits: ComposableStyle<PortraitsOptions, PortraitsTraits> = defineStyle<\n PortraitsOptions,\n PortraitsTraits\n>({\n name: \"portraits\",\n canvas: CANVAS,\n\n validate(options) {\n validateOption(\"portraits\", \"hairStyle\", options.hairStyle, HAIR_STYLES);\n validateOption(\"portraits\", \"eyeStyle\", options.eyeStyle, EYE_STYLES);\n validateOption(\"portraits\", \"mouthStyle\", options.mouthStyle, MOUTH_STYLES);\n },\n\n prepare: preparePortraits,\n\n background: backgroundFor,\n\n head: () => ({ x: 20, y: 13, width: 24, height: 31 }),\n\n layers: [\n { name: \"body\", render: ({ traits }) => drawBody(traits) },\n { name: \"hair-behind\", feature: \"hair\", render: ({ traits }) => hairBehind(traits) },\n { name: \"head\", render: ({ traits }) => drawHead(traits) },\n { name: \"hair-front\", feature: \"hair\", render: ({ traits }) => hairFront(traits) },\n { name: \"eyes\", render: ({ traits }) => drawEyes(traits) },\n { name: \"eyebrows\", render: ({ traits }) => drawEyebrows(traits) },\n { name: \"glasses\", render: ({ traits }) => drawGlasses(traits) },\n { name: \"nose\", render: ({ traits }) => drawNose(traits) },\n { name: \"facial-hair\", render: ({ traits }) => drawFacialHair(traits) },\n { name: \"mouth\", render: ({ traits }) => drawMouth(traits) },\n ],\n});\n\nexport default portraits;\n"],"mappings":";AACA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AA+BA,IAAM,cAAoC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAGO,IAAM,aAAkC,CAAC,QAAQ,UAAU,WAAW,QAAQ;AAG9E,IAAM,eAAsC,CAAC,SAAS,QAAQ,QAAQ,OAAO;AAOpF,IAAM,WAAuB,CAAC,QAAQ,UAAU,UAAU,YAAY;AACtE,IAAM,QAAgB,CAAC,YAAY,UAAU,MAAM;AACnD,IAAM,QAAgB,CAAC,QAAQ,UAAU,OAAO;AAChD,IAAM,SAAkB,CAAC,QAAQ,aAAa,QAAQ;AAItD,IAAM,SAAS;AACf,IAAM,KAAK;AACX,IAAM,QAAQ;AACd,IAAM,QAAQ;AACd,IAAM,OAAO;AAEb,IAAM,SAAS;AACf,IAA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@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@avatar-generator/style-portraits",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Single-colour portrait avatars for professional tools, for @avatar-generator/core",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"avatar",
|
|
7
|
+
"portrait",
|
|
8
|
+
"monochrome",
|
|
9
|
+
"svg",
|
|
10
|
+
"generator"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "Hugo García Benjumea",
|
|
15
|
+
"url": "https://hugoogb.dev/"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/hugoogb/avatar-generator.git",
|
|
20
|
+
"directory": "src/lib/styles/portraits"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://avatar-generator.hugoogb.dev/",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/hugoogb/avatar-generator/issues"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./dist/index.cjs",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/index.d.cts",
|
|
38
|
+
"default": "./dist/index.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"LICENSE",
|
|
46
|
+
"README.md",
|
|
47
|
+
"CHANGELOG.md"
|
|
48
|
+
],
|
|
49
|
+
"sideEffects": false,
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target es2020",
|
|
55
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
56
|
+
"publint": "publint --strict",
|
|
57
|
+
"attw": "attw --pack ."
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@avatar-generator/core": "^3.1.0"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"tsup": "^8.5.0"
|
|
64
|
+
},
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
}
|
|
68
|
+
}
|