@pixygon/avatar 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/dist/index.js ADDED
@@ -0,0 +1,274 @@
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_COLOR_PRESETS: () => EYE_COLOR_PRESETS,
24
+ HAIR_COLOR_PRESETS: () => HAIR_COLOR_PRESETS,
25
+ SKIN_PRESETS: () => SKIN_PRESETS,
26
+ STYLE_COUNTS: () => STYLE_COUNTS,
27
+ buildSkeleton: () => buildSkeleton,
28
+ defaultAppearance: () => defaultAppearance,
29
+ randomAppearance: () => randomAppearance,
30
+ useAvatarEditor: () => useAvatarEditor
31
+ });
32
+ module.exports = __toCommonJS(index_exports);
33
+
34
+ // src/types/index.ts
35
+ var STYLE_COUNTS = {
36
+ eye: 12,
37
+ brow: 8,
38
+ nose: 8,
39
+ mouth: 8,
40
+ hair: 16,
41
+ facial_hair: 8,
42
+ glasses: 6
43
+ };
44
+
45
+ // src/presets.ts
46
+ var SKIN_PRESETS = [
47
+ [0.98, 0.89, 0.78],
48
+ // Porcelain
49
+ [0.96, 0.84, 0.71],
50
+ // Fair
51
+ [0.92, 0.78, 0.63],
52
+ // Light
53
+ [0.87, 0.72, 0.55],
54
+ // Medium-light
55
+ [0.78, 0.62, 0.46],
56
+ // Medium
57
+ [0.68, 0.51, 0.36],
58
+ // Olive
59
+ [0.58, 0.42, 0.3],
60
+ // Tan
61
+ [0.47, 0.33, 0.22],
62
+ // Brown
63
+ [0.36, 0.24, 0.16],
64
+ // Dark
65
+ [0.26, 0.17, 0.11]
66
+ // Deep
67
+ ];
68
+ var EYE_COLOR_PRESETS = [
69
+ [0.1, 0.1, 0.1],
70
+ // Black
71
+ [0.35, 0.22, 0.1],
72
+ // Brown
73
+ [0.55, 0.35, 0.15],
74
+ // Hazel
75
+ [0.25, 0.5, 0.25],
76
+ // Green
77
+ [0.2, 0.4, 0.7],
78
+ // Blue
79
+ [0.45, 0.45, 0.5],
80
+ // Gray
81
+ [0.55, 0.25, 0.25],
82
+ // Red
83
+ [0.5, 0.3, 0.6]
84
+ // Violet
85
+ ];
86
+ var HAIR_COLOR_PRESETS = [
87
+ [0.08, 0.06, 0.05],
88
+ // Black
89
+ [0.22, 0.14, 0.08],
90
+ // Dark brown
91
+ [0.4, 0.26, 0.14],
92
+ // Brown
93
+ [0.58, 0.42, 0.24],
94
+ // Light brown
95
+ [0.78, 0.62, 0.34],
96
+ // Dirty blonde
97
+ [0.9, 0.78, 0.48],
98
+ // Blonde
99
+ [0.72, 0.26, 0.12],
100
+ // Red
101
+ [0.88, 0.52, 0.22],
102
+ // Ginger
103
+ [0.6, 0.6, 0.62],
104
+ // Gray
105
+ [0.92, 0.92, 0.94]
106
+ // White
107
+ ];
108
+
109
+ // src/defaults.ts
110
+ function defaultAppearance() {
111
+ return {
112
+ body: { height: 0.5, build: 0.5 },
113
+ head: {
114
+ width: 1,
115
+ height: 1,
116
+ eye_style: 0,
117
+ eye_color: [...EYE_COLOR_PRESETS[1]],
118
+ eye_y: 0.5,
119
+ eye_spacing: 0.5,
120
+ eye_size: 0.5,
121
+ eye_rotation: 0.5,
122
+ brow_style: 0,
123
+ brow_color: [...HAIR_COLOR_PRESETS[0]],
124
+ brow_y: 0.5,
125
+ brow_spacing: 0.5,
126
+ brow_size: 0.5,
127
+ brow_rotation: 0.5,
128
+ nose_style: 0,
129
+ nose_y: 0.5,
130
+ nose_size: 0.5,
131
+ mouth_style: 0,
132
+ mouth_y: 0.5,
133
+ mouth_size: 0.5,
134
+ mouth_color: [0.75, 0.35, 0.35],
135
+ hair_style: 0,
136
+ hair_color: [...HAIR_COLOR_PRESETS[2]],
137
+ facial_hair_style: 0,
138
+ facial_hair_color: [...HAIR_COLOR_PRESETS[0]],
139
+ glasses_style: 0,
140
+ glasses_color: [0.1, 0.1, 0.1]
141
+ },
142
+ skin_color: [...SKIN_PRESETS[2]]
143
+ };
144
+ }
145
+ function randomAppearance() {
146
+ const rng = (min, max) => min + Math.random() * (max - min);
147
+ const rngInt = (max) => Math.floor(Math.random() * max);
148
+ const pick = (arr) => arr[rngInt(arr.length)];
149
+ const hairColor = pick(HAIR_COLOR_PRESETS);
150
+ return {
151
+ body: {
152
+ height: rng(0.2, 0.8),
153
+ build: rng(0.2, 0.8)
154
+ },
155
+ head: {
156
+ width: rng(0.7, 1.3),
157
+ height: rng(0.7, 1.3),
158
+ eye_style: rngInt(STYLE_COUNTS.eye),
159
+ eye_color: [...pick(EYE_COLOR_PRESETS)],
160
+ eye_y: rng(0.3, 0.7),
161
+ eye_spacing: rng(0.3, 0.7),
162
+ eye_size: rng(0.3, 0.7),
163
+ eye_rotation: 0.5,
164
+ brow_style: rngInt(STYLE_COUNTS.brow),
165
+ brow_color: [...hairColor],
166
+ brow_y: rng(0.3, 0.7),
167
+ brow_spacing: rng(0.3, 0.7),
168
+ brow_size: rng(0.3, 0.7),
169
+ brow_rotation: 0.5,
170
+ nose_style: rngInt(STYLE_COUNTS.nose),
171
+ nose_y: rng(0.3, 0.7),
172
+ nose_size: rng(0.3, 0.7),
173
+ mouth_style: rngInt(STYLE_COUNTS.mouth),
174
+ mouth_y: rng(0.3, 0.7),
175
+ mouth_size: rng(0.3, 0.7),
176
+ mouth_color: [0.75, 0.35, 0.35],
177
+ hair_style: rngInt(STYLE_COUNTS.hair),
178
+ hair_color: [...hairColor],
179
+ facial_hair_style: Math.random() < 0.3 ? 1 + rngInt(STYLE_COUNTS.facial_hair - 1) : 0,
180
+ facial_hair_color: [...hairColor],
181
+ glasses_style: Math.random() < 0.2 ? 1 + rngInt(STYLE_COUNTS.glasses - 1) : 0,
182
+ glasses_color: [0.1, 0.1, 0.1]
183
+ },
184
+ skin_color: [...pick(SKIN_PRESETS)]
185
+ };
186
+ }
187
+
188
+ // src/skeleton.ts
189
+ function mirrorX(p) {
190
+ return [-p[0], p[1], p[2]];
191
+ }
192
+ function buildSkeleton(body) {
193
+ const h = 0.85 + body.height * 0.35;
194
+ const b = 0.75 + body.build * 0.5;
195
+ const footY = 0.02 * h;
196
+ const ankleY = 0.08 * h;
197
+ const kneeY = 0.45 * h;
198
+ const hipY = 0.88 * h;
199
+ const waistY = 0.95 * h;
200
+ const chestY = 1.18 * h;
201
+ const shoulderY = 1.3 * h;
202
+ const neckY = 1.38 * h;
203
+ const headBaseY = 1.42 * h;
204
+ const headCenterY = 1.55 * h;
205
+ const hipSpread = 0.09 * b;
206
+ const shoulderSpread = 0.16 * b;
207
+ const bones = [];
208
+ bones.push({ start: [0, hipY, 0], end: [0, waistY, 0], radius: 0.1 * b });
209
+ bones.push({ start: [0, waistY, 0], end: [0, chestY, 0], radius: 0.11 * b });
210
+ bones.push({ start: [0, chestY, 0], end: [0, shoulderY, 0], radius: 0.12 * b });
211
+ bones.push({ start: [0, neckY, 0], end: [0, headBaseY, 0], radius: 0.04 * b });
212
+ const lShoulder = [shoulderSpread, shoulderY, 0];
213
+ const lElbow = [shoulderSpread + 0.22 * h, shoulderY - 0.08 * h, 0];
214
+ const lWrist = [shoulderSpread + 0.42 * h, shoulderY - 0.18 * h, 0];
215
+ const lHand = [shoulderSpread + 0.5 * h, shoulderY - 0.22 * h, 0];
216
+ bones.push({ start: lShoulder, end: lElbow, radius: 0.04 * b });
217
+ bones.push({ start: lElbow, end: lWrist, radius: 0.035 * b });
218
+ bones.push({ start: lWrist, end: lHand, radius: 0.03 * b });
219
+ bones.push({ start: mirrorX(lShoulder), end: mirrorX(lElbow), radius: 0.04 * b });
220
+ bones.push({ start: mirrorX(lElbow), end: mirrorX(lWrist), radius: 0.035 * b });
221
+ bones.push({ start: mirrorX(lWrist), end: mirrorX(lHand), radius: 0.03 * b });
222
+ const lHip = [hipSpread, hipY, 0];
223
+ const lKnee = [hipSpread + 0.01, kneeY, 0];
224
+ const lAnkle = [hipSpread, ankleY, 0];
225
+ const lToe = [hipSpread, footY, 0.06];
226
+ bones.push({ start: lHip, end: lKnee, radius: 0.055 * b });
227
+ bones.push({ start: lKnee, end: lAnkle, radius: 0.045 * b });
228
+ bones.push({ start: lAnkle, end: lToe, radius: 0.035 * b });
229
+ bones.push({ start: mirrorX(lHip), end: mirrorX(lKnee), radius: 0.055 * b });
230
+ bones.push({ start: mirrorX(lKnee), end: mirrorX(lAnkle), radius: 0.045 * b });
231
+ bones.push({ start: mirrorX(lAnkle), end: mirrorX(lToe), radius: 0.035 * b });
232
+ const head = {
233
+ center: [0, headCenterY, 0],
234
+ radius_x: 0.11,
235
+ radius_y: 0.12,
236
+ radius_z: 0.1
237
+ };
238
+ return { bones, head };
239
+ }
240
+
241
+ // src/hooks/useAvatarEditor.ts
242
+ var import_react = require("react");
243
+ function useAvatarEditor(initial) {
244
+ const [appearance, setAppearance] = (0, import_react.useState)(
245
+ () => initial ?? defaultAppearance()
246
+ );
247
+ const [tab, setTab] = (0, import_react.useState)("body");
248
+ const update = (0, import_react.useCallback)((path, value) => {
249
+ setAppearance((prev) => {
250
+ const next = structuredClone(prev);
251
+ const parts = path.split(".");
252
+ let obj = next;
253
+ for (let i = 0; i < parts.length - 1; i++) {
254
+ obj = obj[parts[i]];
255
+ }
256
+ obj[parts[parts.length - 1]] = value;
257
+ return next;
258
+ });
259
+ }, []);
260
+ const randomize = (0, import_react.useCallback)(() => setAppearance(randomAppearance()), []);
261
+ const reset = (0, import_react.useCallback)(() => setAppearance(initial ?? defaultAppearance()), [initial]);
262
+ return { appearance, tab, setTab, update, randomize, reset };
263
+ }
264
+ // Annotate the CommonJS export names for ESM import in node:
265
+ 0 && (module.exports = {
266
+ EYE_COLOR_PRESETS,
267
+ HAIR_COLOR_PRESETS,
268
+ SKIN_PRESETS,
269
+ STYLE_COUNTS,
270
+ buildSkeleton,
271
+ defaultAppearance,
272
+ randomAppearance,
273
+ useAvatarEditor
274
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,72 @@
1
+ import {
2
+ EYE_COLOR_PRESETS,
3
+ HAIR_COLOR_PRESETS,
4
+ SKIN_PRESETS,
5
+ STYLE_COUNTS,
6
+ defaultAppearance,
7
+ randomAppearance,
8
+ useAvatarEditor
9
+ } from "./chunk-5QZCUXJW.mjs";
10
+
11
+ // src/skeleton.ts
12
+ function mirrorX(p) {
13
+ return [-p[0], p[1], p[2]];
14
+ }
15
+ function buildSkeleton(body) {
16
+ const h = 0.85 + body.height * 0.35;
17
+ const b = 0.75 + body.build * 0.5;
18
+ const footY = 0.02 * h;
19
+ const ankleY = 0.08 * h;
20
+ const kneeY = 0.45 * h;
21
+ const hipY = 0.88 * h;
22
+ const waistY = 0.95 * h;
23
+ const chestY = 1.18 * h;
24
+ const shoulderY = 1.3 * h;
25
+ const neckY = 1.38 * h;
26
+ const headBaseY = 1.42 * h;
27
+ const headCenterY = 1.55 * h;
28
+ const hipSpread = 0.09 * b;
29
+ const shoulderSpread = 0.16 * b;
30
+ const bones = [];
31
+ bones.push({ start: [0, hipY, 0], end: [0, waistY, 0], radius: 0.1 * b });
32
+ bones.push({ start: [0, waistY, 0], end: [0, chestY, 0], radius: 0.11 * b });
33
+ bones.push({ start: [0, chestY, 0], end: [0, shoulderY, 0], radius: 0.12 * b });
34
+ bones.push({ start: [0, neckY, 0], end: [0, headBaseY, 0], radius: 0.04 * b });
35
+ const lShoulder = [shoulderSpread, shoulderY, 0];
36
+ const lElbow = [shoulderSpread + 0.22 * h, shoulderY - 0.08 * h, 0];
37
+ const lWrist = [shoulderSpread + 0.42 * h, shoulderY - 0.18 * h, 0];
38
+ const lHand = [shoulderSpread + 0.5 * h, shoulderY - 0.22 * h, 0];
39
+ bones.push({ start: lShoulder, end: lElbow, radius: 0.04 * b });
40
+ bones.push({ start: lElbow, end: lWrist, radius: 0.035 * b });
41
+ bones.push({ start: lWrist, end: lHand, radius: 0.03 * b });
42
+ bones.push({ start: mirrorX(lShoulder), end: mirrorX(lElbow), radius: 0.04 * b });
43
+ bones.push({ start: mirrorX(lElbow), end: mirrorX(lWrist), radius: 0.035 * b });
44
+ bones.push({ start: mirrorX(lWrist), end: mirrorX(lHand), radius: 0.03 * b });
45
+ const lHip = [hipSpread, hipY, 0];
46
+ const lKnee = [hipSpread + 0.01, kneeY, 0];
47
+ const lAnkle = [hipSpread, ankleY, 0];
48
+ const lToe = [hipSpread, footY, 0.06];
49
+ bones.push({ start: lHip, end: lKnee, radius: 0.055 * b });
50
+ bones.push({ start: lKnee, end: lAnkle, radius: 0.045 * b });
51
+ bones.push({ start: lAnkle, end: lToe, radius: 0.035 * b });
52
+ bones.push({ start: mirrorX(lHip), end: mirrorX(lKnee), radius: 0.055 * b });
53
+ bones.push({ start: mirrorX(lKnee), end: mirrorX(lAnkle), radius: 0.045 * b });
54
+ bones.push({ start: mirrorX(lAnkle), end: mirrorX(lToe), radius: 0.035 * b });
55
+ const head = {
56
+ center: [0, headCenterY, 0],
57
+ radius_x: 0.11,
58
+ radius_y: 0.12,
59
+ radius_z: 0.1
60
+ };
61
+ return { bones, head };
62
+ }
63
+ export {
64
+ EYE_COLOR_PRESETS,
65
+ HAIR_COLOR_PRESETS,
66
+ SKIN_PRESETS,
67
+ STYLE_COUNTS,
68
+ buildSkeleton,
69
+ defaultAppearance,
70
+ randomAppearance,
71
+ useAvatarEditor
72
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@pixygon/avatar",
3
+ "version": "1.0.0",
4
+ "description": "Avatar system for all Pixygon applications — types, presets, skeleton builder, and React editor",
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
+ "./components": {
15
+ "types": "./dist/components/index.d.ts",
16
+ "import": "./dist/components/index.mjs",
17
+ "require": "./dist/components/index.js"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "build": "tsup",
22
+ "dev": "tsup --watch",
23
+ "typecheck": "tsc --noEmit"
24
+ },
25
+ "peerDependencies": {
26
+ "react": ">=17.0.0",
27
+ "react-dom": ">=17.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/react": "^18.2.0",
31
+ "@types/react-dom": "^18.2.0",
32
+ "react": "^18.2.0",
33
+ "react-dom": "^18.2.0",
34
+ "tsup": "^8.0.0",
35
+ "typescript": "^5.3.0"
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "src"
40
+ ],
41
+ "license": "MIT",
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/pixygon/pixygon-packages"
48
+ }
49
+ }