pixelpeeps 1.0.0
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 +0 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +292 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +256 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 TheCHARITH
|
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
ADDED
File without changes
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
|
+
import * as React from 'react';
|
3
|
+
|
4
|
+
type HeadShape = "circle" | "square";
|
5
|
+
type Variant = "auto" | "plain" | "split" | "swoop" | "diagonal" | "cap" | "crescent" | "band" | "corner" | "ring" | "arc" | "wave" | "half";
|
6
|
+
type AlignX = "left" | "center" | "right";
|
7
|
+
type AlignY = "top" | "center" | "bottom";
|
8
|
+
type AvatarProps = {
|
9
|
+
name: string;
|
10
|
+
size?: number;
|
11
|
+
pixelSize?: number;
|
12
|
+
mirrored?: boolean;
|
13
|
+
bg?: [string, string] | string | "random";
|
14
|
+
headShape?: HeadShape;
|
15
|
+
square?: boolean;
|
16
|
+
alignX?: AlignX;
|
17
|
+
alignY?: AlignY;
|
18
|
+
padding?: number;
|
19
|
+
colors?: string | [string, string] | [string, string, string] | "random";
|
20
|
+
variant?: Variant;
|
21
|
+
className?: string;
|
22
|
+
style?: React.CSSProperties;
|
23
|
+
title?: string;
|
24
|
+
};
|
25
|
+
declare function Avatar({ name, size, pixelSize, mirrored, bg, colors, headShape, square, alignX, alignY, padding, variant, className, style, title, }: AvatarProps): react_jsx_runtime.JSX.Element;
|
26
|
+
|
27
|
+
export { Avatar, Avatar as default };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
|
+
import * as React from 'react';
|
3
|
+
|
4
|
+
type HeadShape = "circle" | "square";
|
5
|
+
type Variant = "auto" | "plain" | "split" | "swoop" | "diagonal" | "cap" | "crescent" | "band" | "corner" | "ring" | "arc" | "wave" | "half";
|
6
|
+
type AlignX = "left" | "center" | "right";
|
7
|
+
type AlignY = "top" | "center" | "bottom";
|
8
|
+
type AvatarProps = {
|
9
|
+
name: string;
|
10
|
+
size?: number;
|
11
|
+
pixelSize?: number;
|
12
|
+
mirrored?: boolean;
|
13
|
+
bg?: [string, string] | string | "random";
|
14
|
+
headShape?: HeadShape;
|
15
|
+
square?: boolean;
|
16
|
+
alignX?: AlignX;
|
17
|
+
alignY?: AlignY;
|
18
|
+
padding?: number;
|
19
|
+
colors?: string | [string, string] | [string, string, string] | "random";
|
20
|
+
variant?: Variant;
|
21
|
+
className?: string;
|
22
|
+
style?: React.CSSProperties;
|
23
|
+
title?: string;
|
24
|
+
};
|
25
|
+
declare function Avatar({ name, size, pixelSize, mirrored, bg, colors, headShape, square, alignX, alignY, padding, variant, className, style, title, }: AvatarProps): react_jsx_runtime.JSX.Element;
|
26
|
+
|
27
|
+
export { Avatar, Avatar as default };
|
package/dist/index.js
ADDED
@@ -0,0 +1,292 @@
|
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __export = (target, all) => {
|
8
|
+
for (var name in all)
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
+
};
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
+
for (let key of __getOwnPropNames(from))
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
+
}
|
17
|
+
return to;
|
18
|
+
};
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
+
mod
|
26
|
+
));
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
+
|
29
|
+
// src/index.ts
|
30
|
+
var index_exports = {};
|
31
|
+
__export(index_exports, {
|
32
|
+
Avatar: () => Avatar,
|
33
|
+
default: () => Avatar
|
34
|
+
});
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
36
|
+
|
37
|
+
// src/Avatar.tsx
|
38
|
+
var React = __toESM(require("react"));
|
39
|
+
var import_nice_color_palettes = __toESM(require("nice-color-palettes"));
|
40
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
41
|
+
function cyrb128(str) {
|
42
|
+
let h1 = 1779033703, h2 = 3144134277, h3 = 1013904242, h4 = 2773480762;
|
43
|
+
for (let i = 0, k; i < str.length; i++) {
|
44
|
+
k = str.charCodeAt(i);
|
45
|
+
h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
|
46
|
+
h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);
|
47
|
+
h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
|
48
|
+
h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
|
49
|
+
}
|
50
|
+
h1 = Math.imul(h3 ^ h1 >>> 18, 597399067);
|
51
|
+
h2 = Math.imul(h4 ^ h2 >>> 22, 2869860233);
|
52
|
+
h3 = Math.imul(h1 ^ h3 >>> 17, 951274213);
|
53
|
+
h4 = Math.imul(h2 ^ h4 >>> 19, 2716044179);
|
54
|
+
return [(h1 ^ h2 ^ h3 ^ h4) >>> 0, (h2 ^ h1) >>> 0, (h3 ^ h1) >>> 0, (h4 ^ h1) >>> 0];
|
55
|
+
}
|
56
|
+
function sfc32(a, b, c, d) {
|
57
|
+
return function() {
|
58
|
+
a >>>= 0;
|
59
|
+
b >>>= 0;
|
60
|
+
c >>>= 0;
|
61
|
+
d >>>= 0;
|
62
|
+
let t = a + b | 0;
|
63
|
+
a = b ^ b >>> 9;
|
64
|
+
b = c + (c << 3) | 0;
|
65
|
+
c = c << 21 | c >>> 11;
|
66
|
+
d = d + 1 | 0;
|
67
|
+
t = t + d | 0;
|
68
|
+
c = c + t | 0;
|
69
|
+
return (t >>> 0) / 4294967296;
|
70
|
+
};
|
71
|
+
}
|
72
|
+
function rngFromSeed(seed) {
|
73
|
+
const [a, b, c, d] = cyrb128(seed || "pixelpeeps");
|
74
|
+
return sfc32(a, b, c, d);
|
75
|
+
}
|
76
|
+
function pick(rand, arr) {
|
77
|
+
return arr[Math.floor(rand() * arr.length)];
|
78
|
+
}
|
79
|
+
function hexToRgb(hex) {
|
80
|
+
const h = hex.replace("#", "");
|
81
|
+
const full = h.length === 3 ? h.split("").map((c) => c + c).join("") : h;
|
82
|
+
const n = parseInt(full, 16);
|
83
|
+
return { r: n >> 16 & 255, g: n >> 8 & 255, b: n & 255 };
|
84
|
+
}
|
85
|
+
function rgbToHex(r, g, b) {
|
86
|
+
return "#" + [r, g, b].map((v) => v.toString(16).padStart(2, "0")).join("");
|
87
|
+
}
|
88
|
+
function shade(hex, percent) {
|
89
|
+
const { r, g, b } = hexToRgb(hex);
|
90
|
+
const t = percent < 0 ? 0 : 255;
|
91
|
+
const p = Math.abs(percent);
|
92
|
+
return rgbToHex(
|
93
|
+
Math.round((t - r) * p) + r,
|
94
|
+
Math.round((t - g) * p) + g,
|
95
|
+
Math.round((t - b) * p) + b
|
96
|
+
);
|
97
|
+
}
|
98
|
+
function yiq(hex) {
|
99
|
+
const { r, g, b } = hexToRgb(hex);
|
100
|
+
return (r * 299 + g * 587 + b * 114) / 1e3;
|
101
|
+
}
|
102
|
+
function bestFeatureColor(base) {
|
103
|
+
return yiq(base) > 150 ? "#111827" : "#ffffff";
|
104
|
+
}
|
105
|
+
var NICE_PALETTES = import_nice_color_palettes.default && Array.isArray(import_nice_color_palettes.default) ? import_nice_color_palettes.default : [
|
106
|
+
// fallback single palette
|
107
|
+
["#73a9ff", "#fef3c7", "#ffd6a5", "#d4b4ff", "#a7f3d0"]
|
108
|
+
];
|
109
|
+
function resolveBg(rand, bg) {
|
110
|
+
if (!bg || bg === "random") {
|
111
|
+
return pick(rand, NICE_PALETTES).slice(0, 2);
|
112
|
+
}
|
113
|
+
if (Array.isArray(bg)) return [bg[0], bg[1] ?? bg[0]];
|
114
|
+
return [shade(bg, 0.12), shade(bg, -0.06)];
|
115
|
+
}
|
116
|
+
function resolveCharColors(rand, colors) {
|
117
|
+
if (!colors || colors === "random") {
|
118
|
+
const pal = pick(rand, NICE_PALETTES);
|
119
|
+
const base2 = pal[0];
|
120
|
+
const a12 = pal[1] ?? shade(base2, 0.25);
|
121
|
+
const a22 = pal[2] ?? shade(base2, -0.2);
|
122
|
+
return [base2, a12, a22];
|
123
|
+
}
|
124
|
+
if (typeof colors === "string") {
|
125
|
+
return [colors, shade(colors, 0.25), shade(colors, -0.2)];
|
126
|
+
}
|
127
|
+
const base = colors[0];
|
128
|
+
const a1 = colors[1] ?? shade(base, 0.25);
|
129
|
+
const a2 = colors[2] ?? shade(base, -0.2);
|
130
|
+
return [base, a1, a2];
|
131
|
+
}
|
132
|
+
function Face({ cx, cy, r, color, rand }) {
|
133
|
+
const eyeOffsetX = r * (0.34 + rand() * 0.06);
|
134
|
+
const eyeOffsetY = r * (0.2 + rand() * 0.06);
|
135
|
+
const eyeR = Math.max(2, Math.round(r * (0.08 + rand() * 0.02)));
|
136
|
+
const mouthWidth = r * (0.7 + rand() * 0.3);
|
137
|
+
const mouthLift = r * (0.18 + rand() * 0.16);
|
138
|
+
const mouthCurve = (rand() - 0.5) * 0.8;
|
139
|
+
const mouthStroke = Math.max(1, Math.round(r * 0.06));
|
140
|
+
const x0 = cx - mouthWidth / 2;
|
141
|
+
const x1 = cx + mouthWidth / 2;
|
142
|
+
const my = cy + mouthLift;
|
143
|
+
const cxQ = cx;
|
144
|
+
const cyQ = my + r * (-0.25 * mouthCurve - 0.1);
|
145
|
+
const d = `M ${x0} ${my} Q ${cxQ} ${cyQ} ${x1} ${my}`;
|
146
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
147
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: cx - eyeOffsetX, cy: cy - eyeOffsetY, r: eyeR, fill: color }),
|
148
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: cx + eyeOffsetX, cy: cy - eyeOffsetY, r: eyeR, fill: color }),
|
149
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d, stroke: color, strokeWidth: mouthStroke, fill: "none", strokeLinecap: "round", strokeLinejoin: "round" })
|
150
|
+
] });
|
151
|
+
}
|
152
|
+
function Overlays({
|
153
|
+
cx,
|
154
|
+
cy,
|
155
|
+
r,
|
156
|
+
a1,
|
157
|
+
a2,
|
158
|
+
variant,
|
159
|
+
shape,
|
160
|
+
rand
|
161
|
+
}) {
|
162
|
+
const x0 = cx - r, y0 = cy - r, x1 = cx + r, y1 = cy + r;
|
163
|
+
const left = rand() > 0.5;
|
164
|
+
const tlbr = rand() > 0.5;
|
165
|
+
const horiz = rand() > 0.5;
|
166
|
+
const cornerTL = rand() > 0.5;
|
167
|
+
switch (variant) {
|
168
|
+
case "plain":
|
169
|
+
return null;
|
170
|
+
case "split":
|
171
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: left ? x0 : cx, y: y0, width: r, height: 2 * r, fill: a1 });
|
172
|
+
case "diagonal":
|
173
|
+
return tlbr ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polygon", { points: `${x0},${y0} ${x1},${y0} ${x1},${y1}`, fill: a1 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polygon", { points: `${x0},${y0} ${x0},${y1} ${x1},${y1}`, fill: a1 });
|
174
|
+
case "cap":
|
175
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: `M ${x0} ${y0 + r * 0.25} L ${x1} ${y0} L ${x1} ${y0 + r * 0.6} Q ${cx} ${y0 + r * 0.85} ${x0} ${y0 + r * 0.6} Z`, fill: a1 });
|
176
|
+
case "swoop":
|
177
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: `M ${x0} ${cy - r * 0.55} Q ${cx} ${cy - r * 1.1} ${x1} ${cy - r * 0.35} L ${x1} ${y1} Q ${cx} ${cy + r * 0.95} ${x0} ${y1} Z`, fill: a1 });
|
178
|
+
case "crescent":
|
179
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
180
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: left ? cx - r * 0.55 : cx + r * 0.55, cy, r: r * 0.95, fill: a2 }),
|
181
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: left ? cx - r * 0.52 : cx + r * 0.52, cy, r: r * 0.75, fill: "transparent", stroke: shade(a2, -0.25), strokeWidth: r * 0.08 })
|
182
|
+
] });
|
183
|
+
case "band":
|
184
|
+
return horiz ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: x0, y: cy - r * 0.35, width: 2 * r, height: r * 0.5, fill: a1 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: cx - r * 0.35, y: y0, width: r * 0.5, height: 2 * r, fill: a1 });
|
185
|
+
case "corner":
|
186
|
+
return cornerTL ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polygon", { points: `${x0},${y0} ${x0 + r * 0.9},${y0} ${x0},${y0 + r * 0.9}`, fill: a1 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polygon", { points: `${x1},${y0} ${x1 - r * 0.9},${y0} ${x1},${y0 + r * 0.9}`, fill: a1 });
|
187
|
+
case "ring":
|
188
|
+
return shape === "circle" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx, cy, r: r * 0.86, fill: "none", stroke: a1, strokeWidth: r * 0.18 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: cx - r * 0.86, y: cy - r * 0.86, width: 2 * r * 0.86, height: 2 * r * 0.86, rx: r * 0.18, fill: "none", stroke: a1, strokeWidth: r * 0.18 });
|
189
|
+
case "arc":
|
190
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: `M ${x0} ${cy - r * 0.2} A ${r} ${r} 0 0 1 ${x1} ${cy - r * 0.2} L ${x1} ${cy + r * 0.15} A ${r} ${r} 0 0 0 ${x0} ${cy + r * 0.15} Z`, fill: a1 });
|
191
|
+
case "wave":
|
192
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: `M ${x0} ${cy - r * 0.3} C ${cx - r * 0.6} ${cy - r * 0.8}, ${cx - r * 0.2} ${cy + r * 0.1}, ${cx} ${cy} S ${cx + r * 0.6} ${cy + r * 0.8}, ${x1} ${cy + r * 0.3} L ${x1} ${y1} L ${x0} ${y1} Z`, fill: a1 });
|
193
|
+
// NEW variant: large half/diagonal cut (looks like attached image)
|
194
|
+
case "half": {
|
195
|
+
const diag = rand() > 0.4;
|
196
|
+
if (diag) {
|
197
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polygon", { points: `${x0},${y0} ${x1},${y0} ${x1},${cy + (left ? r * 0.1 : -r * 0.1)}`, fill: a1 });
|
198
|
+
} else {
|
199
|
+
const offset = left ? -r * 0.18 : r * 0.18;
|
200
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: cx + offset, cy, r: r * 0.95, fill: a1 });
|
201
|
+
}
|
202
|
+
}
|
203
|
+
default:
|
204
|
+
return null;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
function Avatar({
|
208
|
+
name,
|
209
|
+
size = 128,
|
210
|
+
pixelSize = 12,
|
211
|
+
mirrored = true,
|
212
|
+
bg,
|
213
|
+
colors,
|
214
|
+
headShape,
|
215
|
+
square,
|
216
|
+
alignX = "center",
|
217
|
+
alignY = "center",
|
218
|
+
padding,
|
219
|
+
variant = "auto",
|
220
|
+
className,
|
221
|
+
style,
|
222
|
+
title
|
223
|
+
}) {
|
224
|
+
const shape = headShape ?? (square ? "square" : "circle");
|
225
|
+
const rand = React.useMemo(() => rngFromSeed(String(name)), [name]);
|
226
|
+
const [bg1, bg2] = React.useMemo(() => resolveBg(rand, bg), [rand, bg]);
|
227
|
+
const [base, a1, a2] = React.useMemo(() => resolveCharColors(rand, colors), [rand, colors]);
|
228
|
+
const faceColor = bestFeatureColor(base);
|
229
|
+
const grid = Math.max(6, Math.floor(size / pixelSize));
|
230
|
+
const tile = Math.ceil(size / grid);
|
231
|
+
const autoPad = Math.max(4, Math.round(size * (0.06 + rand() * 0.02)));
|
232
|
+
const pad = padding ?? autoPad;
|
233
|
+
const baseR = Math.floor(size * (0.36 + rand() * 0.04));
|
234
|
+
const maxR = Math.floor(size / 2 - pad);
|
235
|
+
const r = Math.max(8, Math.min(baseR, maxR));
|
236
|
+
let cx = size / 2;
|
237
|
+
let cy = size / 2;
|
238
|
+
if (alignX === "left") cx = r + pad;
|
239
|
+
if (alignX === "right") cx = size - (r + pad);
|
240
|
+
if (alignY === "top") cy = r + pad;
|
241
|
+
if (alignY === "bottom") cy = size - (r + pad);
|
242
|
+
const cells = [];
|
243
|
+
const cols = mirrored ? Math.ceil(grid / 2) : grid;
|
244
|
+
for (let y = 0; y < grid; y++) {
|
245
|
+
for (let x = 0; x < cols; x++) {
|
246
|
+
const use = rand() > 0.5;
|
247
|
+
const fill = use ? bg1 : bg2;
|
248
|
+
const px = x * tile;
|
249
|
+
const py = y * tile;
|
250
|
+
cells.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: px, y: py, width: tile, height: tile, fill }, `L${x},${y}`));
|
251
|
+
if (mirrored) {
|
252
|
+
const mx = grid - x - 1;
|
253
|
+
const mpx = mx * tile;
|
254
|
+
cells.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: mpx, y: py, width: tile, height: tile, fill }, `R${mx},${y}`));
|
255
|
+
}
|
256
|
+
}
|
257
|
+
}
|
258
|
+
const variants = ["split", "swoop", "diagonal", "cap", "crescent", "band", "corner", "ring", "arc", "wave", "plain", "half"];
|
259
|
+
const chosenVariant = variant === "auto" ? pick(rand, variants) : variant;
|
260
|
+
const clipId = React.useMemo(() => {
|
261
|
+
const [a, b, c, d] = cyrb128(`pp-shape-${name}-${shape}-${r}`);
|
262
|
+
return `pps-${a.toString(16)}${b.toString(16)}${c.toString(16)}${d.toString(16)}`;
|
263
|
+
}, [name, shape, r]);
|
264
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
265
|
+
"svg",
|
266
|
+
{
|
267
|
+
width: size,
|
268
|
+
height: size,
|
269
|
+
viewBox: `0 0 ${size} ${size}`,
|
270
|
+
xmlns: "http://www.w3.org/2000/svg",
|
271
|
+
role: "img",
|
272
|
+
"aria-label": title ?? `Avatar ${name}`,
|
273
|
+
className,
|
274
|
+
style: { display: "inline-block", borderRadius: 12, ...style },
|
275
|
+
children: [
|
276
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { width: size, height: size, fill: bg1 }),
|
277
|
+
cells,
|
278
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("clipPath", { id: clipId, children: shape === "square" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: cx - r, y: cy - r, width: 2 * r, height: 2 * r, rx: Math.max(4, r * 0.12) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx, cy, r }) }) }),
|
279
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { clipPath: `url(#${clipId})`, children: [
|
280
|
+
shape === "square" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: cx - r, y: cy - r, width: 2 * r, height: 2 * r, rx: Math.max(4, r * 0.12), fill: base }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx, cy, r, fill: base }),
|
281
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Overlays, { cx, cy, r, a1, a2, variant: chosenVariant, shape, rand })
|
282
|
+
] }),
|
283
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Face, { cx, cy, r, color: faceColor, rand })
|
284
|
+
]
|
285
|
+
}
|
286
|
+
);
|
287
|
+
}
|
288
|
+
// Annotate the CommonJS export names for ESM import in node:
|
289
|
+
0 && (module.exports = {
|
290
|
+
Avatar
|
291
|
+
});
|
292
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/Avatar.tsx"],"sourcesContent":["export { default as Avatar } from \"./Avatar\";\r\nexport { default } from \"./Avatar\";\r\n","import * as React from \"react\";\r\nimport palettes100 from \"nice-color-palettes\";\r\nexport type HeadShape = \"circle\" | \"square\";\r\nexport type Variant =\r\n | \"auto\"\r\n | \"plain\"\r\n | \"split\"\r\n | \"swoop\"\r\n | \"diagonal\"\r\n | \"cap\"\r\n | \"crescent\"\r\n | \"band\"\r\n | \"corner\"\r\n | \"ring\"\r\n | \"arc\"\r\n | \"wave\"\r\n | \"half\"; // <-- new variant\r\nexport type AlignX = \"left\" | \"center\" | \"right\";\r\nexport type AlignY = \"top\" | \"center\" | \"bottom\";\r\n\r\nexport type AvatarProps = {\r\n name: string;\r\n\r\n // pixel background\r\n size?: number;\r\n pixelSize?: number;\r\n mirrored?: boolean;\r\n bg?: [string, string] | string | \"random\";\r\n\r\n // character controls\r\n headShape?: HeadShape;\r\n square?: boolean; // deprecated\r\n alignX?: AlignX;\r\n alignY?: AlignY;\r\n padding?: number;\r\n\r\n colors?: string | [string, string] | [string, string, string] | \"random\";\r\n variant?: Variant;\r\n\r\n // styling/a11y\r\n className?: string;\r\n style?: React.CSSProperties;\r\n title?: string;\r\n};\r\n\r\n//\r\n// Deterministic RNG (seeded)\r\n//\r\nfunction cyrb128(str: string) {\r\n let h1 = 1779033703, h2 = 3144134277, h3 = 1013904242, h4 = 2773480762;\r\n for (let i = 0, k; i < str.length; i++) {\r\n k = str.charCodeAt(i);\r\n h1 = h2 ^ Math.imul(h1 ^ k, 597399067);\r\n h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);\r\n h3 = h4 ^ Math.imul(h3 ^ k, 951274213);\r\n h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);\r\n }\r\n h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);\r\n h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);\r\n h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);\r\n h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);\r\n return [(h1 ^ h2 ^ h3 ^ h4) >>> 0, (h2 ^ h1) >>> 0, (h3 ^ h1) >>> 0, (h4 ^ h1) >>> 0];\r\n}\r\nfunction sfc32(a: number, b: number, c: number, d: number) {\r\n return function () {\r\n a >>>= 0; b >>>= 0; c >>>= 0; d >>>= 0;\r\n let t = (a + b) | 0;\r\n a = b ^ (b >>> 9);\r\n b = (c + (c << 3)) | 0;\r\n c = (c << 21) | (c >>> 11);\r\n d = (d + 1) | 0;\r\n t = (t + d) | 0;\r\n c = (c + t) | 0;\r\n return (t >>> 0) / 4294967296;\r\n };\r\n}\r\nfunction rngFromSeed(seed: string) {\r\n const [a, b, c, d] = cyrb128(seed || \"pixelpeeps\");\r\n return sfc32(a, b, c, d);\r\n}\r\nfunction pick<T>(rand: () => number, arr: T[]) {\r\n return arr[Math.floor(rand() * arr.length)];\r\n}\r\n\r\n//\r\n// Color helpers\r\n//\r\nfunction hexToRgb(hex: string) {\r\n const h = hex.replace(\"#\", \"\");\r\n const full = h.length === 3 ? h.split(\"\").map(c => c + c).join(\"\") : h;\r\n const n = parseInt(full, 16);\r\n return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };\r\n}\r\nfunction rgbToHex(r: number, g: number, b: number) {\r\n return \"#\" + [r, g, b].map(v => v.toString(16).padStart(2, \"0\")).join(\"\");\r\n}\r\nfunction shade(hex: string, percent: number) {\r\n const { r, g, b } = hexToRgb(hex);\r\n const t = percent < 0 ? 0 : 255;\r\n const p = Math.abs(percent);\r\n return rgbToHex(\r\n Math.round((t - r) * p) + r,\r\n Math.round((t - g) * p) + g,\r\n Math.round((t - b) * p) + b\r\n );\r\n}\r\nfunction yiq(hex: string) {\r\n const { r, g, b } = hexToRgb(hex);\r\n return (r * 299 + g * 587 + b * 114) / 1000;\r\n}\r\nfunction bestFeatureColor(base: string) {\r\n return yiq(base) > 150 ? \"#111827\" : \"#ffffff\";\r\n}\r\n\r\n//\r\n// Palettes: use nice-color-palettes (top 100)\r\n//\r\nconst NICE_PALETTES: string[][] = (palettes100 && Array.isArray(palettes100)) ? palettes100 as string[][] : [\r\n // fallback single palette\r\n [\"#73a9ff\", \"#fef3c7\", \"#ffd6a5\", \"#d4b4ff\", \"#a7f3d0\"]\r\n];\r\n\r\nfunction resolveBg(rand: () => number, bg?: AvatarProps[\"bg\"]): [string, string] {\r\n if (!bg || bg === \"random\") {\r\n return pick(rand, NICE_PALETTES).slice(0, 2) as [string, string];\r\n }\r\n if (Array.isArray(bg)) return [bg[0], bg[1] ?? bg[0]];\r\n // single hex -> auto shade pair\r\n return [shade(bg, 0.12), shade(bg, -0.06)];\r\n}\r\nfunction resolveCharColors(rand: () => number, colors?: AvatarProps[\"colors\"]): [string, string, string] {\r\n if (!colors || colors === \"random\") {\r\n const pal = pick(rand, NICE_PALETTES);\r\n const base = pal[0];\r\n const a1 = pal[1] ?? shade(base, 0.25);\r\n const a2 = pal[2] ?? shade(base, -0.2);\r\n return [base, a1, a2];\r\n }\r\n if (typeof colors === \"string\") {\r\n return [colors, shade(colors, 0.25), shade(colors, -0.2)];\r\n }\r\n const base = (colors as string[])[0];\r\n const a1 = (colors as string[])[1] ?? shade(base, 0.25);\r\n const a2 = (colors as string[])[2] ?? shade(base, -0.2);\r\n return [base, a1, a2];\r\n}\r\n\r\n//\r\n// Small face subcomponent: parametric mouth (fixed nice curve)\r\n//\r\nfunction Face({ cx, cy, r, color, rand }: { cx: number; cy: number; r: number; color: string; rand: () => number }) {\r\n const eyeOffsetX = r * (0.34 + rand() * 0.06); // small variation from seed\r\n const eyeOffsetY = r * (0.20 + rand() * 0.06);\r\n const eyeR = Math.max(2, Math.round(r * (0.08 + rand() * 0.02)));\r\n // Parametric mouth values from seed:\r\n const mouthWidth = r * (0.7 + rand() * 0.3); // 70-100%\r\n const mouthLift = r * (0.18 + rand() * 0.16); // 18-34%\r\n const mouthCurve = (rand() - 0.5) * 0.8; // -0.4..0.4 adjusts curvature (smile vs big smile)\r\n const mouthStroke = Math.max(1, Math.round(r * 0.06));\r\n\r\n // compute coordinates\r\n const x0 = cx - mouthWidth / 2;\r\n const x1 = cx + mouthWidth / 2;\r\n const my = cy + mouthLift;\r\n\r\n // quadratic control point to make a smooth curve (smile)\r\n const cxQ = cx;\r\n const cyQ = my + r * (-0.25 * mouthCurve - 0.1); // move control up or down by mouthCurve\r\n\r\n const d = `M ${x0} ${my} Q ${cxQ} ${cyQ} ${x1} ${my}`;\r\n\r\n return (\r\n <>\r\n <circle cx={cx - eyeOffsetX} cy={cy - eyeOffsetY} r={eyeR} fill={color} />\r\n <circle cx={cx + eyeOffsetX} cy={cy - eyeOffsetY} r={eyeR} fill={color} />\r\n <path d={d} stroke={color} strokeWidth={mouthStroke} fill=\"none\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\r\n </>\r\n );\r\n}\r\n\r\n//\r\n// Overlays (variants) including new `half` variant\r\n//\r\nfunction Overlays({\r\n cx, cy, r, a1, a2, variant, shape, rand\r\n}: {\r\n cx: number; cy: number; r: number;\r\n a1: string; a2: string;\r\n variant: Exclude<Variant, \"auto\">;\r\n shape: HeadShape;\r\n rand: () => number;\r\n}) {\r\n const x0 = cx - r, y0 = cy - r, x1 = cx + r, y1 = cy + r;\r\n\r\n // deterministic options\r\n const left = rand() > 0.5;\r\n const tlbr = rand() > 0.5;\r\n const horiz = rand() > 0.5;\r\n const cornerTL = rand() > 0.5;\r\n\r\n switch (variant) {\r\n case \"plain\": return null;\r\n\r\n case \"split\":\r\n return <rect x={left ? x0 : cx} y={y0} width={r} height={2 * r} fill={a1} />;\r\n\r\n case \"diagonal\":\r\n return tlbr ? (\r\n <polygon points={`${x0},${y0} ${x1},${y0} ${x1},${y1}`} fill={a1} />\r\n ) : (\r\n <polygon points={`${x0},${y0} ${x0},${y1} ${x1},${y1}`} fill={a1} />\r\n );\r\n\r\n case \"cap\":\r\n return (\r\n <path d={`M ${x0} ${y0 + r * 0.25} L ${x1} ${y0} L ${x1} ${y0 + r * 0.6} Q ${cx} ${y0 + r * 0.85} ${x0} ${y0 + r * 0.6} Z`} fill={a1} />\r\n );\r\n\r\n case \"swoop\":\r\n return (\r\n <path d={`M ${x0} ${cy - r * 0.55} Q ${cx} ${cy - r * 1.1} ${x1} ${cy - r * 0.35} L ${x1} ${y1} Q ${cx} ${cy + r * 0.95} ${x0} ${y1} Z`} fill={a1} />\r\n );\r\n\r\n case \"crescent\":\r\n return (\r\n <>\r\n <circle cx={left ? cx - r * 0.55 : cx + r * 0.55} cy={cy} r={r * 0.95} fill={a2} />\r\n <circle cx={left ? cx - r * 0.52 : cx + r * 0.52} cy={cy} r={r * 0.75} fill=\"transparent\" stroke={shade(a2, -0.25)} strokeWidth={r * 0.08} />\r\n </>\r\n );\r\n\r\n case \"band\":\r\n return horiz ? (\r\n <rect x={x0} y={cy - r * 0.35} width={2 * r} height={r * 0.5} fill={a1} />\r\n ) : (\r\n <rect x={cx - r * 0.35} y={y0} width={r * 0.5} height={2 * r} fill={a1} />\r\n );\r\n\r\n case \"corner\":\r\n return cornerTL ? (\r\n <polygon points={`${x0},${y0} ${x0 + r * 0.9},${y0} ${x0},${y0 + r * 0.9}`} fill={a1} />\r\n ) : (\r\n <polygon points={`${x1},${y0} ${x1 - r * 0.9},${y0} ${x1},${y0 + r * 0.9}`} fill={a1} />\r\n );\r\n\r\n case \"ring\":\r\n return shape === \"circle\" ? (\r\n <circle cx={cx} cy={cy} r={r * 0.86} fill=\"none\" stroke={a1} strokeWidth={r * 0.18} />\r\n ) : (\r\n <rect x={cx - r * 0.86} y={cy - r * 0.86} width={2 * r * 0.86} height={2 * r * 0.86} rx={r * 0.18} fill=\"none\" stroke={a1} strokeWidth={r * 0.18} />\r\n );\r\n\r\n case \"arc\":\r\n return <path d={`M ${x0} ${cy - r * 0.2} A ${r} ${r} 0 0 1 ${x1} ${cy - r * 0.2} L ${x1} ${cy + r * 0.15} A ${r} ${r} 0 0 0 ${x0} ${cy + r * 0.15} Z`} fill={a1} />;\r\n\r\n case \"wave\":\r\n return <path d={`M ${x0} ${cy - r * 0.3} C ${cx - r * 0.6} ${cy - r * 0.8}, ${cx - r * 0.2} ${cy + r * 0.1}, ${cx} ${cy} S ${cx + r * 0.6} ${cy + r * 0.8}, ${x1} ${cy + r * 0.3} L ${x1} ${y1} L ${x0} ${y1} Z`} fill={a1} />;\r\n\r\n // NEW variant: large half/diagonal cut (looks like attached image)\r\n case \"half\": {\r\n // choose diag or simple half using rand\r\n const diag = rand() > 0.4;\r\n if (diag) {\r\n // diagonal wedge\r\n return <polygon points={`${x0},${y0} ${x1},${y0} ${x1},${cy + (left ? r * 0.1 : -r * 0.1)}`} fill={a1} />;\r\n } else {\r\n // simple semicircle overlay offset to left/right for crescent effect\r\n const offset = left ? -r * 0.18 : r * 0.18;\r\n return <circle cx={cx + offset} cy={cy} r={r * 0.95} fill={a1} />;\r\n }\r\n }\r\n\r\n default:\r\n return null;\r\n }\r\n}\r\n\r\n//\r\n// Main component\r\n//\r\nexport default function Avatar({\r\n name,\r\n size = 128,\r\n pixelSize = 12,\r\n mirrored = true,\r\n bg,\r\n colors,\r\n headShape,\r\n square,\r\n alignX = \"center\",\r\n alignY = \"center\",\r\n padding,\r\n variant = \"auto\",\r\n className,\r\n style,\r\n title,\r\n}: AvatarProps) {\r\n const shape: HeadShape = headShape ?? (square ? \"square\" : \"circle\");\r\n // single RNG for everything derived from seed (deterministic)\r\n const rand = React.useMemo(() => rngFromSeed(String(name)), [name]);\r\n\r\n // background and character colors chosen from nice palettes\r\n const [bg1, bg2] = React.useMemo(() => resolveBg(rand, bg), [rand, bg]);\r\n const [base, a1, a2] = React.useMemo(() => resolveCharColors(rand, colors), [rand, colors]);\r\n const faceColor = bestFeatureColor(base);\r\n\r\n // Pixel grid\r\n const grid = Math.max(6, Math.floor(size / pixelSize));\r\n const tile = Math.ceil(size / grid);\r\n\r\n // geometry/calculations (all derived from rand)\r\n const autoPad = Math.max(4, Math.round(size * (0.06 + rand() * 0.02)));\r\n const pad = padding ?? autoPad;\r\n const baseR = Math.floor(size * (0.36 + rand() * 0.04)); // slight variation\r\n const maxR = Math.floor(size / 2 - pad);\r\n const r = Math.max(8, Math.min(baseR, maxR));\r\n\r\n let cx = size / 2;\r\n let cy = size / 2;\r\n if (alignX === \"left\") cx = r + pad;\r\n if (alignX === \"right\") cx = size - (r + pad);\r\n if (alignY === \"top\") cy = r + pad;\r\n if (alignY === \"bottom\") cy = size - (r + pad);\r\n\r\n // Pixel pattern generation -> uses rand sequentially; deterministic for seed\r\n const cells: React.ReactElement[] = [];\r\n const cols = mirrored ? Math.ceil(grid / 2) : grid;\r\n for (let y = 0; y < grid; y++) {\r\n for (let x = 0; x < cols; x++) {\r\n const use = rand() > 0.5;\r\n const fill = use ? bg1 : bg2;\r\n const px = x * tile;\r\n const py = y * tile;\r\n cells.push(<rect key={`L${x},${y}`} x={px} y={py} width={tile} height={tile} fill={fill} />);\r\n if (mirrored) {\r\n const mx = grid - x - 1;\r\n const mpx = mx * tile;\r\n cells.push(<rect key={`R${mx},${y}`} x={mpx} y={py} width={tile} height={tile} fill={fill} />);\r\n }\r\n }\r\n }\r\n\r\n // pick variant deterministically\r\n const variants: Exclude<Variant, \"auto\">[] = [\"split\", \"swoop\", \"diagonal\", \"cap\", \"crescent\", \"band\", \"corner\", \"ring\", \"arc\", \"wave\", \"plain\", \"half\"];\r\n const chosenVariant: Exclude<Variant, \"auto\"> = variant === \"auto\" ? pick(rand, variants) : (variant as Exclude<Variant, \"auto\">);\r\n\r\n // clip path id (stable-ish)\r\n const clipId = React.useMemo(() => {\r\n const [a, b, c, d] = cyrb128(`pp-shape-${name}-${shape}-${r}`);\r\n return `pps-${a.toString(16)}${b.toString(16)}${c.toString(16)}${d.toString(16)}`;\r\n }, [name, shape, r]);\r\n\r\n return (\r\n <svg\r\n width={size}\r\n height={size}\r\n viewBox={`0 0 ${size} ${size}`}\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n role=\"img\"\r\n aria-label={title ?? `Avatar ${name}`}\r\n className={className}\r\n style={{ display: \"inline-block\", borderRadius: 12, ...style }}\r\n >\r\n {/* background grid */}\r\n <rect width={size} height={size} fill={bg1} />\r\n {cells}\r\n\r\n <defs>\r\n <clipPath id={clipId}>\r\n {shape === \"square\" ? (\r\n <rect x={cx - r} y={cy - r} width={2 * r} height={2 * r} rx={Math.max(4, r * 0.12)} />\r\n ) : (\r\n <circle cx={cx} cy={cy} r={r} />\r\n )}\r\n </clipPath>\r\n </defs>\r\n\r\n {/* head + overlays */}\r\n <g clipPath={`url(#${clipId})`}>\r\n {shape === \"square\" ? (\r\n <rect x={cx - r} y={cy - r} width={2 * r} height={2 * r} rx={Math.max(4, r * 0.12)} fill={base} />\r\n ) : (\r\n <circle cx={cx} cy={cy} r={r} fill={base} />\r\n )}\r\n\r\n <Overlays cx={cx} cy={cy} r={r} a1={a1} a2={a2} variant={chosenVariant} shape={shape} rand={rand} />\r\n </g>\r\n\r\n {/* facial features */}\r\n <Face cx={cx} cy={cy} r={r} color={faceColor} rand={rand} />\r\n </svg>\r\n );\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,iCAAwB;AA2KpB;AA5HJ,SAAS,QAAQ,KAAa;AAC5B,MAAI,KAAK,YAAY,KAAK,YAAY,KAA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s
ADDED
@@ -0,0 +1,256 @@
|
|
1
|
+
// src/Avatar.tsx
|
2
|
+
import * as React from "react";
|
3
|
+
import palettes100 from "nice-color-palettes";
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
5
|
+
function cyrb128(str) {
|
6
|
+
let h1 = 1779033703, h2 = 3144134277, h3 = 1013904242, h4 = 2773480762;
|
7
|
+
for (let i = 0, k; i < str.length; i++) {
|
8
|
+
k = str.charCodeAt(i);
|
9
|
+
h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
|
10
|
+
h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);
|
11
|
+
h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
|
12
|
+
h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
|
13
|
+
}
|
14
|
+
h1 = Math.imul(h3 ^ h1 >>> 18, 597399067);
|
15
|
+
h2 = Math.imul(h4 ^ h2 >>> 22, 2869860233);
|
16
|
+
h3 = Math.imul(h1 ^ h3 >>> 17, 951274213);
|
17
|
+
h4 = Math.imul(h2 ^ h4 >>> 19, 2716044179);
|
18
|
+
return [(h1 ^ h2 ^ h3 ^ h4) >>> 0, (h2 ^ h1) >>> 0, (h3 ^ h1) >>> 0, (h4 ^ h1) >>> 0];
|
19
|
+
}
|
20
|
+
function sfc32(a, b, c, d) {
|
21
|
+
return function() {
|
22
|
+
a >>>= 0;
|
23
|
+
b >>>= 0;
|
24
|
+
c >>>= 0;
|
25
|
+
d >>>= 0;
|
26
|
+
let t = a + b | 0;
|
27
|
+
a = b ^ b >>> 9;
|
28
|
+
b = c + (c << 3) | 0;
|
29
|
+
c = c << 21 | c >>> 11;
|
30
|
+
d = d + 1 | 0;
|
31
|
+
t = t + d | 0;
|
32
|
+
c = c + t | 0;
|
33
|
+
return (t >>> 0) / 4294967296;
|
34
|
+
};
|
35
|
+
}
|
36
|
+
function rngFromSeed(seed) {
|
37
|
+
const [a, b, c, d] = cyrb128(seed || "pixelpeeps");
|
38
|
+
return sfc32(a, b, c, d);
|
39
|
+
}
|
40
|
+
function pick(rand, arr) {
|
41
|
+
return arr[Math.floor(rand() * arr.length)];
|
42
|
+
}
|
43
|
+
function hexToRgb(hex) {
|
44
|
+
const h = hex.replace("#", "");
|
45
|
+
const full = h.length === 3 ? h.split("").map((c) => c + c).join("") : h;
|
46
|
+
const n = parseInt(full, 16);
|
47
|
+
return { r: n >> 16 & 255, g: n >> 8 & 255, b: n & 255 };
|
48
|
+
}
|
49
|
+
function rgbToHex(r, g, b) {
|
50
|
+
return "#" + [r, g, b].map((v) => v.toString(16).padStart(2, "0")).join("");
|
51
|
+
}
|
52
|
+
function shade(hex, percent) {
|
53
|
+
const { r, g, b } = hexToRgb(hex);
|
54
|
+
const t = percent < 0 ? 0 : 255;
|
55
|
+
const p = Math.abs(percent);
|
56
|
+
return rgbToHex(
|
57
|
+
Math.round((t - r) * p) + r,
|
58
|
+
Math.round((t - g) * p) + g,
|
59
|
+
Math.round((t - b) * p) + b
|
60
|
+
);
|
61
|
+
}
|
62
|
+
function yiq(hex) {
|
63
|
+
const { r, g, b } = hexToRgb(hex);
|
64
|
+
return (r * 299 + g * 587 + b * 114) / 1e3;
|
65
|
+
}
|
66
|
+
function bestFeatureColor(base) {
|
67
|
+
return yiq(base) > 150 ? "#111827" : "#ffffff";
|
68
|
+
}
|
69
|
+
var NICE_PALETTES = palettes100 && Array.isArray(palettes100) ? palettes100 : [
|
70
|
+
// fallback single palette
|
71
|
+
["#73a9ff", "#fef3c7", "#ffd6a5", "#d4b4ff", "#a7f3d0"]
|
72
|
+
];
|
73
|
+
function resolveBg(rand, bg) {
|
74
|
+
if (!bg || bg === "random") {
|
75
|
+
return pick(rand, NICE_PALETTES).slice(0, 2);
|
76
|
+
}
|
77
|
+
if (Array.isArray(bg)) return [bg[0], bg[1] ?? bg[0]];
|
78
|
+
return [shade(bg, 0.12), shade(bg, -0.06)];
|
79
|
+
}
|
80
|
+
function resolveCharColors(rand, colors) {
|
81
|
+
if (!colors || colors === "random") {
|
82
|
+
const pal = pick(rand, NICE_PALETTES);
|
83
|
+
const base2 = pal[0];
|
84
|
+
const a12 = pal[1] ?? shade(base2, 0.25);
|
85
|
+
const a22 = pal[2] ?? shade(base2, -0.2);
|
86
|
+
return [base2, a12, a22];
|
87
|
+
}
|
88
|
+
if (typeof colors === "string") {
|
89
|
+
return [colors, shade(colors, 0.25), shade(colors, -0.2)];
|
90
|
+
}
|
91
|
+
const base = colors[0];
|
92
|
+
const a1 = colors[1] ?? shade(base, 0.25);
|
93
|
+
const a2 = colors[2] ?? shade(base, -0.2);
|
94
|
+
return [base, a1, a2];
|
95
|
+
}
|
96
|
+
function Face({ cx, cy, r, color, rand }) {
|
97
|
+
const eyeOffsetX = r * (0.34 + rand() * 0.06);
|
98
|
+
const eyeOffsetY = r * (0.2 + rand() * 0.06);
|
99
|
+
const eyeR = Math.max(2, Math.round(r * (0.08 + rand() * 0.02)));
|
100
|
+
const mouthWidth = r * (0.7 + rand() * 0.3);
|
101
|
+
const mouthLift = r * (0.18 + rand() * 0.16);
|
102
|
+
const mouthCurve = (rand() - 0.5) * 0.8;
|
103
|
+
const mouthStroke = Math.max(1, Math.round(r * 0.06));
|
104
|
+
const x0 = cx - mouthWidth / 2;
|
105
|
+
const x1 = cx + mouthWidth / 2;
|
106
|
+
const my = cy + mouthLift;
|
107
|
+
const cxQ = cx;
|
108
|
+
const cyQ = my + r * (-0.25 * mouthCurve - 0.1);
|
109
|
+
const d = `M ${x0} ${my} Q ${cxQ} ${cyQ} ${x1} ${my}`;
|
110
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
111
|
+
/* @__PURE__ */ jsx("circle", { cx: cx - eyeOffsetX, cy: cy - eyeOffsetY, r: eyeR, fill: color }),
|
112
|
+
/* @__PURE__ */ jsx("circle", { cx: cx + eyeOffsetX, cy: cy - eyeOffsetY, r: eyeR, fill: color }),
|
113
|
+
/* @__PURE__ */ jsx("path", { d, stroke: color, strokeWidth: mouthStroke, fill: "none", strokeLinecap: "round", strokeLinejoin: "round" })
|
114
|
+
] });
|
115
|
+
}
|
116
|
+
function Overlays({
|
117
|
+
cx,
|
118
|
+
cy,
|
119
|
+
r,
|
120
|
+
a1,
|
121
|
+
a2,
|
122
|
+
variant,
|
123
|
+
shape,
|
124
|
+
rand
|
125
|
+
}) {
|
126
|
+
const x0 = cx - r, y0 = cy - r, x1 = cx + r, y1 = cy + r;
|
127
|
+
const left = rand() > 0.5;
|
128
|
+
const tlbr = rand() > 0.5;
|
129
|
+
const horiz = rand() > 0.5;
|
130
|
+
const cornerTL = rand() > 0.5;
|
131
|
+
switch (variant) {
|
132
|
+
case "plain":
|
133
|
+
return null;
|
134
|
+
case "split":
|
135
|
+
return /* @__PURE__ */ jsx("rect", { x: left ? x0 : cx, y: y0, width: r, height: 2 * r, fill: a1 });
|
136
|
+
case "diagonal":
|
137
|
+
return tlbr ? /* @__PURE__ */ jsx("polygon", { points: `${x0},${y0} ${x1},${y0} ${x1},${y1}`, fill: a1 }) : /* @__PURE__ */ jsx("polygon", { points: `${x0},${y0} ${x0},${y1} ${x1},${y1}`, fill: a1 });
|
138
|
+
case "cap":
|
139
|
+
return /* @__PURE__ */ jsx("path", { d: `M ${x0} ${y0 + r * 0.25} L ${x1} ${y0} L ${x1} ${y0 + r * 0.6} Q ${cx} ${y0 + r * 0.85} ${x0} ${y0 + r * 0.6} Z`, fill: a1 });
|
140
|
+
case "swoop":
|
141
|
+
return /* @__PURE__ */ jsx("path", { d: `M ${x0} ${cy - r * 0.55} Q ${cx} ${cy - r * 1.1} ${x1} ${cy - r * 0.35} L ${x1} ${y1} Q ${cx} ${cy + r * 0.95} ${x0} ${y1} Z`, fill: a1 });
|
142
|
+
case "crescent":
|
143
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
144
|
+
/* @__PURE__ */ jsx("circle", { cx: left ? cx - r * 0.55 : cx + r * 0.55, cy, r: r * 0.95, fill: a2 }),
|
145
|
+
/* @__PURE__ */ jsx("circle", { cx: left ? cx - r * 0.52 : cx + r * 0.52, cy, r: r * 0.75, fill: "transparent", stroke: shade(a2, -0.25), strokeWidth: r * 0.08 })
|
146
|
+
] });
|
147
|
+
case "band":
|
148
|
+
return horiz ? /* @__PURE__ */ jsx("rect", { x: x0, y: cy - r * 0.35, width: 2 * r, height: r * 0.5, fill: a1 }) : /* @__PURE__ */ jsx("rect", { x: cx - r * 0.35, y: y0, width: r * 0.5, height: 2 * r, fill: a1 });
|
149
|
+
case "corner":
|
150
|
+
return cornerTL ? /* @__PURE__ */ jsx("polygon", { points: `${x0},${y0} ${x0 + r * 0.9},${y0} ${x0},${y0 + r * 0.9}`, fill: a1 }) : /* @__PURE__ */ jsx("polygon", { points: `${x1},${y0} ${x1 - r * 0.9},${y0} ${x1},${y0 + r * 0.9}`, fill: a1 });
|
151
|
+
case "ring":
|
152
|
+
return shape === "circle" ? /* @__PURE__ */ jsx("circle", { cx, cy, r: r * 0.86, fill: "none", stroke: a1, strokeWidth: r * 0.18 }) : /* @__PURE__ */ jsx("rect", { x: cx - r * 0.86, y: cy - r * 0.86, width: 2 * r * 0.86, height: 2 * r * 0.86, rx: r * 0.18, fill: "none", stroke: a1, strokeWidth: r * 0.18 });
|
153
|
+
case "arc":
|
154
|
+
return /* @__PURE__ */ jsx("path", { d: `M ${x0} ${cy - r * 0.2} A ${r} ${r} 0 0 1 ${x1} ${cy - r * 0.2} L ${x1} ${cy + r * 0.15} A ${r} ${r} 0 0 0 ${x0} ${cy + r * 0.15} Z`, fill: a1 });
|
155
|
+
case "wave":
|
156
|
+
return /* @__PURE__ */ jsx("path", { d: `M ${x0} ${cy - r * 0.3} C ${cx - r * 0.6} ${cy - r * 0.8}, ${cx - r * 0.2} ${cy + r * 0.1}, ${cx} ${cy} S ${cx + r * 0.6} ${cy + r * 0.8}, ${x1} ${cy + r * 0.3} L ${x1} ${y1} L ${x0} ${y1} Z`, fill: a1 });
|
157
|
+
// NEW variant: large half/diagonal cut (looks like attached image)
|
158
|
+
case "half": {
|
159
|
+
const diag = rand() > 0.4;
|
160
|
+
if (diag) {
|
161
|
+
return /* @__PURE__ */ jsx("polygon", { points: `${x0},${y0} ${x1},${y0} ${x1},${cy + (left ? r * 0.1 : -r * 0.1)}`, fill: a1 });
|
162
|
+
} else {
|
163
|
+
const offset = left ? -r * 0.18 : r * 0.18;
|
164
|
+
return /* @__PURE__ */ jsx("circle", { cx: cx + offset, cy, r: r * 0.95, fill: a1 });
|
165
|
+
}
|
166
|
+
}
|
167
|
+
default:
|
168
|
+
return null;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
function Avatar({
|
172
|
+
name,
|
173
|
+
size = 128,
|
174
|
+
pixelSize = 12,
|
175
|
+
mirrored = true,
|
176
|
+
bg,
|
177
|
+
colors,
|
178
|
+
headShape,
|
179
|
+
square,
|
180
|
+
alignX = "center",
|
181
|
+
alignY = "center",
|
182
|
+
padding,
|
183
|
+
variant = "auto",
|
184
|
+
className,
|
185
|
+
style,
|
186
|
+
title
|
187
|
+
}) {
|
188
|
+
const shape = headShape ?? (square ? "square" : "circle");
|
189
|
+
const rand = React.useMemo(() => rngFromSeed(String(name)), [name]);
|
190
|
+
const [bg1, bg2] = React.useMemo(() => resolveBg(rand, bg), [rand, bg]);
|
191
|
+
const [base, a1, a2] = React.useMemo(() => resolveCharColors(rand, colors), [rand, colors]);
|
192
|
+
const faceColor = bestFeatureColor(base);
|
193
|
+
const grid = Math.max(6, Math.floor(size / pixelSize));
|
194
|
+
const tile = Math.ceil(size / grid);
|
195
|
+
const autoPad = Math.max(4, Math.round(size * (0.06 + rand() * 0.02)));
|
196
|
+
const pad = padding ?? autoPad;
|
197
|
+
const baseR = Math.floor(size * (0.36 + rand() * 0.04));
|
198
|
+
const maxR = Math.floor(size / 2 - pad);
|
199
|
+
const r = Math.max(8, Math.min(baseR, maxR));
|
200
|
+
let cx = size / 2;
|
201
|
+
let cy = size / 2;
|
202
|
+
if (alignX === "left") cx = r + pad;
|
203
|
+
if (alignX === "right") cx = size - (r + pad);
|
204
|
+
if (alignY === "top") cy = r + pad;
|
205
|
+
if (alignY === "bottom") cy = size - (r + pad);
|
206
|
+
const cells = [];
|
207
|
+
const cols = mirrored ? Math.ceil(grid / 2) : grid;
|
208
|
+
for (let y = 0; y < grid; y++) {
|
209
|
+
for (let x = 0; x < cols; x++) {
|
210
|
+
const use = rand() > 0.5;
|
211
|
+
const fill = use ? bg1 : bg2;
|
212
|
+
const px = x * tile;
|
213
|
+
const py = y * tile;
|
214
|
+
cells.push(/* @__PURE__ */ jsx("rect", { x: px, y: py, width: tile, height: tile, fill }, `L${x},${y}`));
|
215
|
+
if (mirrored) {
|
216
|
+
const mx = grid - x - 1;
|
217
|
+
const mpx = mx * tile;
|
218
|
+
cells.push(/* @__PURE__ */ jsx("rect", { x: mpx, y: py, width: tile, height: tile, fill }, `R${mx},${y}`));
|
219
|
+
}
|
220
|
+
}
|
221
|
+
}
|
222
|
+
const variants = ["split", "swoop", "diagonal", "cap", "crescent", "band", "corner", "ring", "arc", "wave", "plain", "half"];
|
223
|
+
const chosenVariant = variant === "auto" ? pick(rand, variants) : variant;
|
224
|
+
const clipId = React.useMemo(() => {
|
225
|
+
const [a, b, c, d] = cyrb128(`pp-shape-${name}-${shape}-${r}`);
|
226
|
+
return `pps-${a.toString(16)}${b.toString(16)}${c.toString(16)}${d.toString(16)}`;
|
227
|
+
}, [name, shape, r]);
|
228
|
+
return /* @__PURE__ */ jsxs(
|
229
|
+
"svg",
|
230
|
+
{
|
231
|
+
width: size,
|
232
|
+
height: size,
|
233
|
+
viewBox: `0 0 ${size} ${size}`,
|
234
|
+
xmlns: "http://www.w3.org/2000/svg",
|
235
|
+
role: "img",
|
236
|
+
"aria-label": title ?? `Avatar ${name}`,
|
237
|
+
className,
|
238
|
+
style: { display: "inline-block", borderRadius: 12, ...style },
|
239
|
+
children: [
|
240
|
+
/* @__PURE__ */ jsx("rect", { width: size, height: size, fill: bg1 }),
|
241
|
+
cells,
|
242
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("clipPath", { id: clipId, children: shape === "square" ? /* @__PURE__ */ jsx("rect", { x: cx - r, y: cy - r, width: 2 * r, height: 2 * r, rx: Math.max(4, r * 0.12) }) : /* @__PURE__ */ jsx("circle", { cx, cy, r }) }) }),
|
243
|
+
/* @__PURE__ */ jsxs("g", { clipPath: `url(#${clipId})`, children: [
|
244
|
+
shape === "square" ? /* @__PURE__ */ jsx("rect", { x: cx - r, y: cy - r, width: 2 * r, height: 2 * r, rx: Math.max(4, r * 0.12), fill: base }) : /* @__PURE__ */ jsx("circle", { cx, cy, r, fill: base }),
|
245
|
+
/* @__PURE__ */ jsx(Overlays, { cx, cy, r, a1, a2, variant: chosenVariant, shape, rand })
|
246
|
+
] }),
|
247
|
+
/* @__PURE__ */ jsx(Face, { cx, cy, r, color: faceColor, rand })
|
248
|
+
]
|
249
|
+
}
|
250
|
+
);
|
251
|
+
}
|
252
|
+
export {
|
253
|
+
Avatar,
|
254
|
+
Avatar as default
|
255
|
+
};
|
256
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/Avatar.tsx"],"sourcesContent":["import * as React from \"react\";\r\nimport palettes100 from \"nice-color-palettes\";\r\nexport type HeadShape = \"circle\" | \"square\";\r\nexport type Variant =\r\n | \"auto\"\r\n | \"plain\"\r\n | \"split\"\r\n | \"swoop\"\r\n | \"diagonal\"\r\n | \"cap\"\r\n | \"crescent\"\r\n | \"band\"\r\n | \"corner\"\r\n | \"ring\"\r\n | \"arc\"\r\n | \"wave\"\r\n | \"half\"; // <-- new variant\r\nexport type AlignX = \"left\" | \"center\" | \"right\";\r\nexport type AlignY = \"top\" | \"center\" | \"bottom\";\r\n\r\nexport type AvatarProps = {\r\n name: string;\r\n\r\n // pixel background\r\n size?: number;\r\n pixelSize?: number;\r\n mirrored?: boolean;\r\n bg?: [string, string] | string | \"random\";\r\n\r\n // character controls\r\n headShape?: HeadShape;\r\n square?: boolean; // deprecated\r\n alignX?: AlignX;\r\n alignY?: AlignY;\r\n padding?: number;\r\n\r\n colors?: string | [string, string] | [string, string, string] | \"random\";\r\n variant?: Variant;\r\n\r\n // styling/a11y\r\n className?: string;\r\n style?: React.CSSProperties;\r\n title?: string;\r\n};\r\n\r\n//\r\n// Deterministic RNG (seeded)\r\n//\r\nfunction cyrb128(str: string) {\r\n let h1 = 1779033703, h2 = 3144134277, h3 = 1013904242, h4 = 2773480762;\r\n for (let i = 0, k; i < str.length; i++) {\r\n k = str.charCodeAt(i);\r\n h1 = h2 ^ Math.imul(h1 ^ k, 597399067);\r\n h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);\r\n h3 = h4 ^ Math.imul(h3 ^ k, 951274213);\r\n h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);\r\n }\r\n h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);\r\n h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);\r\n h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);\r\n h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);\r\n return [(h1 ^ h2 ^ h3 ^ h4) >>> 0, (h2 ^ h1) >>> 0, (h3 ^ h1) >>> 0, (h4 ^ h1) >>> 0];\r\n}\r\nfunction sfc32(a: number, b: number, c: number, d: number) {\r\n return function () {\r\n a >>>= 0; b >>>= 0; c >>>= 0; d >>>= 0;\r\n let t = (a + b) | 0;\r\n a = b ^ (b >>> 9);\r\n b = (c + (c << 3)) | 0;\r\n c = (c << 21) | (c >>> 11);\r\n d = (d + 1) | 0;\r\n t = (t + d) | 0;\r\n c = (c + t) | 0;\r\n return (t >>> 0) / 4294967296;\r\n };\r\n}\r\nfunction rngFromSeed(seed: string) {\r\n const [a, b, c, d] = cyrb128(seed || \"pixelpeeps\");\r\n return sfc32(a, b, c, d);\r\n}\r\nfunction pick<T>(rand: () => number, arr: T[]) {\r\n return arr[Math.floor(rand() * arr.length)];\r\n}\r\n\r\n//\r\n// Color helpers\r\n//\r\nfunction hexToRgb(hex: string) {\r\n const h = hex.replace(\"#\", \"\");\r\n const full = h.length === 3 ? h.split(\"\").map(c => c + c).join(\"\") : h;\r\n const n = parseInt(full, 16);\r\n return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };\r\n}\r\nfunction rgbToHex(r: number, g: number, b: number) {\r\n return \"#\" + [r, g, b].map(v => v.toString(16).padStart(2, \"0\")).join(\"\");\r\n}\r\nfunction shade(hex: string, percent: number) {\r\n const { r, g, b } = hexToRgb(hex);\r\n const t = percent < 0 ? 0 : 255;\r\n const p = Math.abs(percent);\r\n return rgbToHex(\r\n Math.round((t - r) * p) + r,\r\n Math.round((t - g) * p) + g,\r\n Math.round((t - b) * p) + b\r\n );\r\n}\r\nfunction yiq(hex: string) {\r\n const { r, g, b } = hexToRgb(hex);\r\n return (r * 299 + g * 587 + b * 114) / 1000;\r\n}\r\nfunction bestFeatureColor(base: string) {\r\n return yiq(base) > 150 ? \"#111827\" : \"#ffffff\";\r\n}\r\n\r\n//\r\n// Palettes: use nice-color-palettes (top 100)\r\n//\r\nconst NICE_PALETTES: string[][] = (palettes100 && Array.isArray(palettes100)) ? palettes100 as string[][] : [\r\n // fallback single palette\r\n [\"#73a9ff\", \"#fef3c7\", \"#ffd6a5\", \"#d4b4ff\", \"#a7f3d0\"]\r\n];\r\n\r\nfunction resolveBg(rand: () => number, bg?: AvatarProps[\"bg\"]): [string, string] {\r\n if (!bg || bg === \"random\") {\r\n return pick(rand, NICE_PALETTES).slice(0, 2) as [string, string];\r\n }\r\n if (Array.isArray(bg)) return [bg[0], bg[1] ?? bg[0]];\r\n // single hex -> auto shade pair\r\n return [shade(bg, 0.12), shade(bg, -0.06)];\r\n}\r\nfunction resolveCharColors(rand: () => number, colors?: AvatarProps[\"colors\"]): [string, string, string] {\r\n if (!colors || colors === \"random\") {\r\n const pal = pick(rand, NICE_PALETTES);\r\n const base = pal[0];\r\n const a1 = pal[1] ?? shade(base, 0.25);\r\n const a2 = pal[2] ?? shade(base, -0.2);\r\n return [base, a1, a2];\r\n }\r\n if (typeof colors === \"string\") {\r\n return [colors, shade(colors, 0.25), shade(colors, -0.2)];\r\n }\r\n const base = (colors as string[])[0];\r\n const a1 = (colors as string[])[1] ?? shade(base, 0.25);\r\n const a2 = (colors as string[])[2] ?? shade(base, -0.2);\r\n return [base, a1, a2];\r\n}\r\n\r\n//\r\n// Small face subcomponent: parametric mouth (fixed nice curve)\r\n//\r\nfunction Face({ cx, cy, r, color, rand }: { cx: number; cy: number; r: number; color: string; rand: () => number }) {\r\n const eyeOffsetX = r * (0.34 + rand() * 0.06); // small variation from seed\r\n const eyeOffsetY = r * (0.20 + rand() * 0.06);\r\n const eyeR = Math.max(2, Math.round(r * (0.08 + rand() * 0.02)));\r\n // Parametric mouth values from seed:\r\n const mouthWidth = r * (0.7 + rand() * 0.3); // 70-100%\r\n const mouthLift = r * (0.18 + rand() * 0.16); // 18-34%\r\n const mouthCurve = (rand() - 0.5) * 0.8; // -0.4..0.4 adjusts curvature (smile vs big smile)\r\n const mouthStroke = Math.max(1, Math.round(r * 0.06));\r\n\r\n // compute coordinates\r\n const x0 = cx - mouthWidth / 2;\r\n const x1 = cx + mouthWidth / 2;\r\n const my = cy + mouthLift;\r\n\r\n // quadratic control point to make a smooth curve (smile)\r\n const cxQ = cx;\r\n const cyQ = my + r * (-0.25 * mouthCurve - 0.1); // move control up or down by mouthCurve\r\n\r\n const d = `M ${x0} ${my} Q ${cxQ} ${cyQ} ${x1} ${my}`;\r\n\r\n return (\r\n <>\r\n <circle cx={cx - eyeOffsetX} cy={cy - eyeOffsetY} r={eyeR} fill={color} />\r\n <circle cx={cx + eyeOffsetX} cy={cy - eyeOffsetY} r={eyeR} fill={color} />\r\n <path d={d} stroke={color} strokeWidth={mouthStroke} fill=\"none\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\r\n </>\r\n );\r\n}\r\n\r\n//\r\n// Overlays (variants) including new `half` variant\r\n//\r\nfunction Overlays({\r\n cx, cy, r, a1, a2, variant, shape, rand\r\n}: {\r\n cx: number; cy: number; r: number;\r\n a1: string; a2: string;\r\n variant: Exclude<Variant, \"auto\">;\r\n shape: HeadShape;\r\n rand: () => number;\r\n}) {\r\n const x0 = cx - r, y0 = cy - r, x1 = cx + r, y1 = cy + r;\r\n\r\n // deterministic options\r\n const left = rand() > 0.5;\r\n const tlbr = rand() > 0.5;\r\n const horiz = rand() > 0.5;\r\n const cornerTL = rand() > 0.5;\r\n\r\n switch (variant) {\r\n case \"plain\": return null;\r\n\r\n case \"split\":\r\n return <rect x={left ? x0 : cx} y={y0} width={r} height={2 * r} fill={a1} />;\r\n\r\n case \"diagonal\":\r\n return tlbr ? (\r\n <polygon points={`${x0},${y0} ${x1},${y0} ${x1},${y1}`} fill={a1} />\r\n ) : (\r\n <polygon points={`${x0},${y0} ${x0},${y1} ${x1},${y1}`} fill={a1} />\r\n );\r\n\r\n case \"cap\":\r\n return (\r\n <path d={`M ${x0} ${y0 + r * 0.25} L ${x1} ${y0} L ${x1} ${y0 + r * 0.6} Q ${cx} ${y0 + r * 0.85} ${x0} ${y0 + r * 0.6} Z`} fill={a1} />\r\n );\r\n\r\n case \"swoop\":\r\n return (\r\n <path d={`M ${x0} ${cy - r * 0.55} Q ${cx} ${cy - r * 1.1} ${x1} ${cy - r * 0.35} L ${x1} ${y1} Q ${cx} ${cy + r * 0.95} ${x0} ${y1} Z`} fill={a1} />\r\n );\r\n\r\n case \"crescent\":\r\n return (\r\n <>\r\n <circle cx={left ? cx - r * 0.55 : cx + r * 0.55} cy={cy} r={r * 0.95} fill={a2} />\r\n <circle cx={left ? cx - r * 0.52 : cx + r * 0.52} cy={cy} r={r * 0.75} fill=\"transparent\" stroke={shade(a2, -0.25)} strokeWidth={r * 0.08} />\r\n </>\r\n );\r\n\r\n case \"band\":\r\n return horiz ? (\r\n <rect x={x0} y={cy - r * 0.35} width={2 * r} height={r * 0.5} fill={a1} />\r\n ) : (\r\n <rect x={cx - r * 0.35} y={y0} width={r * 0.5} height={2 * r} fill={a1} />\r\n );\r\n\r\n case \"corner\":\r\n return cornerTL ? (\r\n <polygon points={`${x0},${y0} ${x0 + r * 0.9},${y0} ${x0},${y0 + r * 0.9}`} fill={a1} />\r\n ) : (\r\n <polygon points={`${x1},${y0} ${x1 - r * 0.9},${y0} ${x1},${y0 + r * 0.9}`} fill={a1} />\r\n );\r\n\r\n case \"ring\":\r\n return shape === \"circle\" ? (\r\n <circle cx={cx} cy={cy} r={r * 0.86} fill=\"none\" stroke={a1} strokeWidth={r * 0.18} />\r\n ) : (\r\n <rect x={cx - r * 0.86} y={cy - r * 0.86} width={2 * r * 0.86} height={2 * r * 0.86} rx={r * 0.18} fill=\"none\" stroke={a1} strokeWidth={r * 0.18} />\r\n );\r\n\r\n case \"arc\":\r\n return <path d={`M ${x0} ${cy - r * 0.2} A ${r} ${r} 0 0 1 ${x1} ${cy - r * 0.2} L ${x1} ${cy + r * 0.15} A ${r} ${r} 0 0 0 ${x0} ${cy + r * 0.15} Z`} fill={a1} />;\r\n\r\n case \"wave\":\r\n return <path d={`M ${x0} ${cy - r * 0.3} C ${cx - r * 0.6} ${cy - r * 0.8}, ${cx - r * 0.2} ${cy + r * 0.1}, ${cx} ${cy} S ${cx + r * 0.6} ${cy + r * 0.8}, ${x1} ${cy + r * 0.3} L ${x1} ${y1} L ${x0} ${y1} Z`} fill={a1} />;\r\n\r\n // NEW variant: large half/diagonal cut (looks like attached image)\r\n case \"half\": {\r\n // choose diag or simple half using rand\r\n const diag = rand() > 0.4;\r\n if (diag) {\r\n // diagonal wedge\r\n return <polygon points={`${x0},${y0} ${x1},${y0} ${x1},${cy + (left ? r * 0.1 : -r * 0.1)}`} fill={a1} />;\r\n } else {\r\n // simple semicircle overlay offset to left/right for crescent effect\r\n const offset = left ? -r * 0.18 : r * 0.18;\r\n return <circle cx={cx + offset} cy={cy} r={r * 0.95} fill={a1} />;\r\n }\r\n }\r\n\r\n default:\r\n return null;\r\n }\r\n}\r\n\r\n//\r\n// Main component\r\n//\r\nexport default function Avatar({\r\n name,\r\n size = 128,\r\n pixelSize = 12,\r\n mirrored = true,\r\n bg,\r\n colors,\r\n headShape,\r\n square,\r\n alignX = \"center\",\r\n alignY = \"center\",\r\n padding,\r\n variant = \"auto\",\r\n className,\r\n style,\r\n title,\r\n}: AvatarProps) {\r\n const shape: HeadShape = headShape ?? (square ? \"square\" : \"circle\");\r\n // single RNG for everything derived from seed (deterministic)\r\n const rand = React.useMemo(() => rngFromSeed(String(name)), [name]);\r\n\r\n // background and character colors chosen from nice palettes\r\n const [bg1, bg2] = React.useMemo(() => resolveBg(rand, bg), [rand, bg]);\r\n const [base, a1, a2] = React.useMemo(() => resolveCharColors(rand, colors), [rand, colors]);\r\n const faceColor = bestFeatureColor(base);\r\n\r\n // Pixel grid\r\n const grid = Math.max(6, Math.floor(size / pixelSize));\r\n const tile = Math.ceil(size / grid);\r\n\r\n // geometry/calculations (all derived from rand)\r\n const autoPad = Math.max(4, Math.round(size * (0.06 + rand() * 0.02)));\r\n const pad = padding ?? autoPad;\r\n const baseR = Math.floor(size * (0.36 + rand() * 0.04)); // slight variation\r\n const maxR = Math.floor(size / 2 - pad);\r\n const r = Math.max(8, Math.min(baseR, maxR));\r\n\r\n let cx = size / 2;\r\n let cy = size / 2;\r\n if (alignX === \"left\") cx = r + pad;\r\n if (alignX === \"right\") cx = size - (r + pad);\r\n if (alignY === \"top\") cy = r + pad;\r\n if (alignY === \"bottom\") cy = size - (r + pad);\r\n\r\n // Pixel pattern generation -> uses rand sequentially; deterministic for seed\r\n const cells: React.ReactElement[] = [];\r\n const cols = mirrored ? Math.ceil(grid / 2) : grid;\r\n for (let y = 0; y < grid; y++) {\r\n for (let x = 0; x < cols; x++) {\r\n const use = rand() > 0.5;\r\n const fill = use ? bg1 : bg2;\r\n const px = x * tile;\r\n const py = y * tile;\r\n cells.push(<rect key={`L${x},${y}`} x={px} y={py} width={tile} height={tile} fill={fill} />);\r\n if (mirrored) {\r\n const mx = grid - x - 1;\r\n const mpx = mx * tile;\r\n cells.push(<rect key={`R${mx},${y}`} x={mpx} y={py} width={tile} height={tile} fill={fill} />);\r\n }\r\n }\r\n }\r\n\r\n // pick variant deterministically\r\n const variants: Exclude<Variant, \"auto\">[] = [\"split\", \"swoop\", \"diagonal\", \"cap\", \"crescent\", \"band\", \"corner\", \"ring\", \"arc\", \"wave\", \"plain\", \"half\"];\r\n const chosenVariant: Exclude<Variant, \"auto\"> = variant === \"auto\" ? pick(rand, variants) : (variant as Exclude<Variant, \"auto\">);\r\n\r\n // clip path id (stable-ish)\r\n const clipId = React.useMemo(() => {\r\n const [a, b, c, d] = cyrb128(`pp-shape-${name}-${shape}-${r}`);\r\n return `pps-${a.toString(16)}${b.toString(16)}${c.toString(16)}${d.toString(16)}`;\r\n }, [name, shape, r]);\r\n\r\n return (\r\n <svg\r\n width={size}\r\n height={size}\r\n viewBox={`0 0 ${size} ${size}`}\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n role=\"img\"\r\n aria-label={title ?? `Avatar ${name}`}\r\n className={className}\r\n style={{ display: \"inline-block\", borderRadius: 12, ...style }}\r\n >\r\n {/* background grid */}\r\n <rect width={size} height={size} fill={bg1} />\r\n {cells}\r\n\r\n <defs>\r\n <clipPath id={clipId}>\r\n {shape === \"square\" ? (\r\n <rect x={cx - r} y={cy - r} width={2 * r} height={2 * r} rx={Math.max(4, r * 0.12)} />\r\n ) : (\r\n <circle cx={cx} cy={cy} r={r} />\r\n )}\r\n </clipPath>\r\n </defs>\r\n\r\n {/* head + overlays */}\r\n <g clipPath={`url(#${clipId})`}>\r\n {shape === \"square\" ? (\r\n <rect x={cx - r} y={cy - r} width={2 * r} height={2 * r} rx={Math.max(4, r * 0.12)} fill={base} />\r\n ) : (\r\n <circle cx={cx} cy={cy} r={r} fill={base} />\r\n )}\r\n\r\n <Overlays cx={cx} cy={cy} r={r} a1={a1} a2={a2} variant={chosenVariant} shape={shape} rand={rand} />\r\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,IAAQ,IAAQ,GAAM,IAAQ,IAAQ,SAAS,eAAe,OAAc,MAAY;AAAA,WACpG;AAAA,QAGA,oBAAC,QAAK,IAAQ,IAAQ,GAAM,OAAO,WAAW,MAAY;AAAA;AAAA;AAAA,EAC5D;AAEJ;","names":["base","a1","a2"]}
|
package/package.json
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
{
|
2
|
+
"name": "pixelpeeps",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "Deterministic, cute pixel avatars for React. Zero deps. SVG output.",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"module": "dist/index.mjs",
|
7
|
+
"types": "dist/index.d.ts",
|
8
|
+
"exports": {
|
9
|
+
".": {
|
10
|
+
"types": "./dist/index.d.ts",
|
11
|
+
"import": "./dist/index.mjs",
|
12
|
+
"require": "./dist/index.js"
|
13
|
+
}
|
14
|
+
},
|
15
|
+
"files": [
|
16
|
+
"dist"
|
17
|
+
],
|
18
|
+
"scripts": {
|
19
|
+
"build": "tsup",
|
20
|
+
"prepare": "npm run build"
|
21
|
+
},
|
22
|
+
"keywords": [
|
23
|
+
"avatar",
|
24
|
+
"pixel",
|
25
|
+
"react",
|
26
|
+
"svg",
|
27
|
+
"deterministic"
|
28
|
+
],
|
29
|
+
"author": "Charith Pramodya Senanayake (@TheCHARITH)",
|
30
|
+
"license": "MIT",
|
31
|
+
"peerDependencies": {
|
32
|
+
"react": ">=17"
|
33
|
+
},
|
34
|
+
"dependencies": {
|
35
|
+
"nice-color-palettes": "^4.0.0"
|
36
|
+
},
|
37
|
+
"devDependencies": {
|
38
|
+
"@types/react": "^19.2.2",
|
39
|
+
"@types/react-dom": "^19.2.1",
|
40
|
+
"tsup": "^8.5.0",
|
41
|
+
"typescript": "^5.9.3"
|
42
|
+
}
|
43
|
+
}
|