@klex/mascot 0.3.0 → 0.5.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/README.md +13 -0
- package/package.json +2 -1
- package/src/emotes.ts +3 -1
- package/src/eyes.tsx +13 -19
- package/src/glide.ts +108 -21
- package/src/index.ts +11 -0
- package/src/inflate/atlas.ts +74 -0
- package/src/inflate/params.ts +302 -0
- package/src/inflate/renderer.ts +762 -0
- package/src/inflate/shaders.ts +447 -0
- package/src/inflate/shared.ts +39 -0
- package/src/inflate/support.ts +54 -0
- package/src/inflate/turn.ts +198 -0
- package/src/inflate/use-inflated-body.ts +229 -0
- package/src/klex.tsx +145 -33
- package/src/outline.ts +56 -0
- package/src/presets.ts +35 -0
package/src/outline.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const LOG_SIZE_RANGE = Math.log(5);
|
|
2
|
+
|
|
3
|
+
const clamp01 = (value: number) => Math.max(0, Math.min(1, value));
|
|
4
|
+
const smoothstep = (value: number) => value * value * (3 - 2 * value);
|
|
5
|
+
|
|
6
|
+
// One linear-sRGB → OKLab conversion supplies both lightness and chroma.
|
|
7
|
+
// Hue is not needed. Keep final mixing in sRGB to preserve the tuned colors.
|
|
8
|
+
function hexOklab(color: string) {
|
|
9
|
+
if (!/^#(?:[\da-f]{3}|[\da-f]{6})$/i.test(color)) return null;
|
|
10
|
+
const hex = color.slice(1);
|
|
11
|
+
const rgb = Number.parseInt(
|
|
12
|
+
hex.length === 3 ? [...hex].map((digit) => digit + digit).join('') : hex,
|
|
13
|
+
16,
|
|
14
|
+
);
|
|
15
|
+
const linear = (channel: number) => {
|
|
16
|
+
const value = channel / 255;
|
|
17
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
18
|
+
};
|
|
19
|
+
const r = linear(rgb >> 16);
|
|
20
|
+
const g = linear((rgb >> 8) & 255);
|
|
21
|
+
const b = linear(rgb & 255);
|
|
22
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
23
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
24
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
25
|
+
return {
|
|
26
|
+
lightness: 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
|
27
|
+
chroma: Math.hypot(
|
|
28
|
+
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
|
29
|
+
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
|
|
30
|
+
),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function bodyOutline(color: string, size: number) {
|
|
35
|
+
const lab = hexOklab(color);
|
|
36
|
+
// Unknown CSS colors retain base mixing without guessing their chroma.
|
|
37
|
+
const chromaWeight = lab ? 1.5 - 0.7 * clamp01(lab.chroma / 0.25) : 1;
|
|
38
|
+
const darkBoost = lab
|
|
39
|
+
? 1 + smoothstep(clamp01((0.6 - lab.lightness) / 0.4))
|
|
40
|
+
: 1;
|
|
41
|
+
const smallness = clamp01((160 - size) / 128);
|
|
42
|
+
const colorWeight = chromaWeight * (1 + 0.2 * smoothstep(smallness));
|
|
43
|
+
const mix = (base: number, ink: string) => {
|
|
44
|
+
// Integer hundredths keep the complementary percentages exact.
|
|
45
|
+
const amount = Math.round(base * colorWeight * 100);
|
|
46
|
+
return `color-mix(in srgb, ${color} ${(10000 - amount) / 100}%, ${ink} ${amount / 100}%)`;
|
|
47
|
+
};
|
|
48
|
+
// Log-size interpolation keeps actual pixel thickness increasing with size.
|
|
49
|
+
const widthWeight = smoothstep(
|
|
50
|
+
Math.log(160 / (160 - 128 * smallness)) / LOG_SIZE_RANGE,
|
|
51
|
+
);
|
|
52
|
+
return {
|
|
53
|
+
color: `light-dark(${mix(12, 'black')}, ${mix(8 * darkBoost, 'white')})`,
|
|
54
|
+
width: 3 * 2.25 ** widthWeight,
|
|
55
|
+
};
|
|
56
|
+
}
|
package/src/presets.ts
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
|
+
/** Cross-section of the inflated body from its edge inwards. */
|
|
2
|
+
export type InflateProfile = 'pillow' | 'dome' | 'gummy';
|
|
3
|
+
|
|
4
|
+
/** Extra height as a soft 2D blob, e.g. a belly or cheeks. */
|
|
5
|
+
export type InflateBump = {
|
|
6
|
+
/** Rest position in the 160×140 frame of the right-facing outline. */
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
radius: number;
|
|
10
|
+
/** Added height in frame units. Negative values dent the surface. */
|
|
11
|
+
height: number;
|
|
12
|
+
/** `face` follows the eyes, `body` the deformed silhouette's bounds. */
|
|
13
|
+
anchor?: 'face' | 'body';
|
|
14
|
+
};
|
|
15
|
+
|
|
1
16
|
export type BodyShape = {
|
|
2
17
|
id: string;
|
|
3
18
|
name: string;
|
|
4
19
|
outline: readonly (readonly [number, number])[];
|
|
5
20
|
eyeX: number;
|
|
6
21
|
eyeY: number;
|
|
22
|
+
/** Inflated look only: 0 is a flat cookie, 1 a round marshmallow. */
|
|
23
|
+
puffiness?: number;
|
|
24
|
+
/** Inflated look only. Defaults to `dome`. */
|
|
25
|
+
edgeProfile?: InflateProfile;
|
|
26
|
+
/** Inflated look only. At most four bumps are drawn. */
|
|
27
|
+
bumps?: readonly InflateBump[];
|
|
7
28
|
};
|
|
8
29
|
|
|
9
30
|
export type KlexPalette = {
|
|
@@ -19,6 +40,12 @@ export const BODY_SHAPES = [
|
|
|
19
40
|
name: 'Klex',
|
|
20
41
|
eyeX: 23.294,
|
|
21
42
|
eyeY: 56.824,
|
|
43
|
+
puffiness: 0.6,
|
|
44
|
+
edgeProfile: 'dome',
|
|
45
|
+
bumps: [
|
|
46
|
+
{ x: 90.3, y: 67, radius: 6, height: 1.5, anchor: 'face' },
|
|
47
|
+
{ x: 116.3, y: 67, radius: 6, height: 1.5, anchor: 'face' },
|
|
48
|
+
],
|
|
22
49
|
// Logo contour from packages/ui/src/components/ui/klex-logo.tsx, scaled
|
|
23
50
|
// uniformly to 110px high, with three sole points at y=128 for ground contact.
|
|
24
51
|
outline: [
|
|
@@ -125,6 +152,9 @@ export const BODY_SHAPES = [
|
|
|
125
152
|
name: 'Blob',
|
|
126
153
|
eyeX: 23,
|
|
127
154
|
eyeY: 65,
|
|
155
|
+
puffiness: 0.75,
|
|
156
|
+
edgeProfile: 'pillow',
|
|
157
|
+
bumps: [{ x: 84, y: 100, radius: 24, height: 5, anchor: 'body' }],
|
|
128
158
|
outline: [
|
|
129
159
|
[88, 28],
|
|
130
160
|
[115, 33],
|
|
@@ -147,6 +177,8 @@ export const BODY_SHAPES = [
|
|
|
147
177
|
name: 'Slime',
|
|
148
178
|
eyeX: 31,
|
|
149
179
|
eyeY: 87,
|
|
180
|
+
puffiness: 0.45,
|
|
181
|
+
edgeProfile: 'gummy',
|
|
150
182
|
outline: [
|
|
151
183
|
[100, 58],
|
|
152
184
|
[123, 64],
|
|
@@ -169,6 +201,9 @@ export const BODY_SHAPES = [
|
|
|
169
201
|
name: 'Drop',
|
|
170
202
|
eyeX: 18,
|
|
171
203
|
eyeY: 63,
|
|
204
|
+
puffiness: 0.7,
|
|
205
|
+
edgeProfile: 'dome',
|
|
206
|
+
bumps: [{ x: 86, y: 104, radius: 20, height: 3, anchor: 'body' }],
|
|
172
207
|
outline: [
|
|
173
208
|
[92, 12],
|
|
174
209
|
[108, 26],
|