@q9labsai/facehash 4.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/dist/Facehash.d.ts +14 -0
- package/dist/FacehashNative.d.ts +15 -0
- package/dist/FacehashSceneSvg.d.ts +16 -0
- package/dist/FacehashSceneSvg.native.d.ts +12 -0
- package/dist/blink.d.ts +4 -0
- package/dist/chunk-KNE4N3T7.js +188 -0
- package/dist/core/face-geometry.d.ts +16 -0
- package/dist/core/facehash-data.d.ts +27 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/scene.d.ts +42 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +14 -0
- package/dist/index.native.d.ts +4 -0
- package/dist/index.native.js +139 -0
- package/dist/native-blink.d.ts +3 -0
- package/dist/react.d.ts +4 -0
- package/dist/react.js +175 -0
- package/dist/utils/hash.d.ts +1 -0
- package/package.json +86 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Q9Labs
|
|
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.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type Intensity3D, type Variant } from "./core/index.js";
|
|
3
|
+
export interface FacehashProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> {
|
|
4
|
+
name: string;
|
|
5
|
+
size?: number | string;
|
|
6
|
+
variant?: Variant;
|
|
7
|
+
intensity3d?: Intensity3D;
|
|
8
|
+
interactive?: boolean;
|
|
9
|
+
showInitial?: boolean;
|
|
10
|
+
colors?: readonly string[];
|
|
11
|
+
enableBlink?: boolean;
|
|
12
|
+
renderMouth?: () => React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export declare const Facehash: React.ForwardRefExoticComponent<FacehashProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type Intensity3D, type Variant } from "./core/index.js";
|
|
3
|
+
export interface FacehashNativeProps {
|
|
4
|
+
name: string;
|
|
5
|
+
size?: number;
|
|
6
|
+
variant?: Variant;
|
|
7
|
+
intensity3d?: Intensity3D;
|
|
8
|
+
interactive?: boolean;
|
|
9
|
+
showInitial?: boolean;
|
|
10
|
+
colors?: readonly string[];
|
|
11
|
+
enableBlink?: boolean;
|
|
12
|
+
renderMouth?: () => React.ReactNode;
|
|
13
|
+
testID?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function FacehashNative({ name, size, variant, intensity3d, interactive, showInitial, colors, enableBlink, renderMouth, testID }: FacehashNativeProps): React.JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import type { FacehashScene, Variant } from "./core/index.js";
|
|
3
|
+
type FacehashSceneSvgProps = {
|
|
4
|
+
backgroundColor: string;
|
|
5
|
+
enableBlink?: boolean;
|
|
6
|
+
height?: number | string;
|
|
7
|
+
idPrefix: string;
|
|
8
|
+
scene: FacehashScene;
|
|
9
|
+
showInitial: boolean;
|
|
10
|
+
style?: React.CSSProperties;
|
|
11
|
+
variant: Variant;
|
|
12
|
+
width?: number | string;
|
|
13
|
+
withAnimatedProjection?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare function FacehashSceneSvg({ backgroundColor, enableBlink, height, idPrefix, scene, showInitial, style, variant, width, withAnimatedProjection }: FacehashSceneSvgProps): React.JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FacehashScene, Variant } from "./core/index.js";
|
|
2
|
+
type FacehashSceneSvgNativeProps = {
|
|
3
|
+
backgroundColor: string;
|
|
4
|
+
enableBlink?: boolean;
|
|
5
|
+
idPrefix: string;
|
|
6
|
+
scene: FacehashScene;
|
|
7
|
+
showInitial: boolean;
|
|
8
|
+
size: number;
|
|
9
|
+
variant: Variant;
|
|
10
|
+
};
|
|
11
|
+
export declare function FacehashSceneSvgNative({ backgroundColor, enableBlink, idPrefix, scene, showInitial, size, variant }: FacehashSceneSvgNativeProps): React.JSX.Element;
|
|
12
|
+
export {};
|
package/dist/blink.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import type { FacehashBlinkTiming } from "./core/index.js";
|
|
3
|
+
export declare function ensureBlinkKeyframes(): void;
|
|
4
|
+
export declare function getBlinkStyle(enableBlink: boolean | undefined, timing: FacehashBlinkTiming | undefined): React.CSSProperties | undefined;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// src/core/face-geometry.ts
|
|
2
|
+
var FACE_GEOMETRIES = {
|
|
3
|
+
round: {
|
|
4
|
+
viewBox: { width: 63, height: 15 },
|
|
5
|
+
leftEyeAnchor: { x: 7.2, y: 7.2 },
|
|
6
|
+
rightEyeAnchor: { x: 55.2, y: 7.2 },
|
|
7
|
+
leftEyePaths: ["M14.4 7.2C14.4 11.1765 11.1765 14.4 7.2 14.4C3.22355 14.4 0 11.1765 0 7.2C0 3.22355 3.22355 0 7.2 0C11.1765 0 14.4 3.22355 14.4 7.2Z"],
|
|
8
|
+
rightEyePaths: ["M62.4 7.2C62.4 11.1765 59.1765 14.4 55.2 14.4C51.2236 14.4 48 11.1765 48 7.2C48 3.22355 51.2236 0 55.2 0C59.1765 0 62.4 3.22355 62.4 7.2Z"]
|
|
9
|
+
},
|
|
10
|
+
cross: {
|
|
11
|
+
viewBox: { width: 71, height: 23 },
|
|
12
|
+
leftEyeAnchor: { x: 11.5, y: 11.5 },
|
|
13
|
+
rightEyeAnchor: { x: 58.7695, y: 11.5 },
|
|
14
|
+
leftEyePaths: [
|
|
15
|
+
"M11.5 0C12.9411 0 13.6619 0.000460386 14.1748 0.354492C14.3742 0.49213 14.547 0.664882 14.6846 0.864258C15.0384 1.37711 15.0391 2.09739 15.0391 3.53809V7.96094H19.4619C20.9027 7.96094 21.6229 7.9615 22.1357 8.31543C22.3352 8.45308 22.5079 8.62578 22.6455 8.8252C22.9995 9.3381 23 10.0589 23 11.5C23 12.9408 22.9995 13.661 22.6455 14.1738C22.5079 14.3733 22.3352 14.5459 22.1357 14.6836C21.6229 15.0375 20.9027 15.0381 19.4619 15.0381H15.0391V19.4619C15.0391 20.9026 15.0384 21.6229 14.6846 22.1357C14.547 22.3351 14.3742 22.5079 14.1748 22.6455C13.6619 22.9995 12.9411 23 11.5 23C10.0592 23 9.33903 22.9994 8.82617 22.6455C8.62674 22.5079 8.45309 22.3352 8.31543 22.1357C7.96175 21.6229 7.96191 20.9024 7.96191 19.4619V15.0381H3.53809C2.0973 15.0381 1.37711 15.0375 0.864258 14.6836C0.664834 14.5459 0.492147 14.3733 0.354492 14.1738C0.000498831 13.661 -5.88036e-08 12.9408 0 11.5C6.2999e-08 10.0589 0.000460356 9.3381 0.354492 8.8252C0.492144 8.62578 0.664842 8.45308 0.864258 8.31543C1.37711 7.9615 2.09731 7.96094 3.53809 7.96094H7.96191V3.53809C7.96191 2.09765 7.96175 1.37709 8.31543 0.864258C8.45309 0.664828 8.62674 0.492149 8.82617 0.354492C9.33903 0.000555366 10.0592 1.62347e-09 11.5 0Z"
|
|
16
|
+
],
|
|
17
|
+
rightEyePaths: [
|
|
18
|
+
"M58.7695 0C60.2107 0 60.9314 0.000460386 61.4443 0.354492C61.6437 0.49213 61.8165 0.664882 61.9541 0.864258C62.308 1.37711 62.3086 2.09739 62.3086 3.53809V7.96094H66.7314C68.1722 7.96094 68.8924 7.9615 69.4053 8.31543C69.6047 8.45308 69.7774 8.62578 69.915 8.8252C70.2691 9.3381 70.2695 10.0589 70.2695 11.5C70.2695 12.9408 70.269 13.661 69.915 14.1738C69.7774 14.3733 69.6047 14.5459 69.4053 14.6836C68.8924 15.0375 68.1722 15.0381 66.7314 15.0381H62.3086V19.4619C62.3086 20.9026 62.308 21.6229 61.9541 22.1357C61.8165 22.3351 61.6437 22.5079 61.4443 22.6455C60.9314 22.9995 60.2107 23 58.7695 23C57.3287 23 56.6086 22.9994 56.0957 22.6455C55.8963 22.5079 55.7226 22.3352 55.585 22.1357C55.2313 21.6229 55.2314 20.9024 55.2314 19.4619V15.0381H50.8076C49.3668 15.0381 48.6466 15.0375 48.1338 14.6836C47.9344 14.5459 47.7617 14.3733 47.624 14.1738C47.27 13.661 47.2695 12.9408 47.2695 11.5C47.2695 10.0589 47.27 9.3381 47.624 8.8252C47.7617 8.62578 47.9344 8.45308 48.1338 8.31543C48.6466 7.9615 49.3668 7.96094 50.8076 7.96094H55.2314V3.53809C55.2314 2.09765 55.2313 1.37709 55.585 0.864258C55.7226 0.664828 55.8963 0.492149 56.0957 0.354492C56.6086 0.000555366 57.3287 1.62347e-09 58.7695 0Z"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
line: {
|
|
22
|
+
viewBox: { width: 82, height: 8 },
|
|
23
|
+
leftEyeAnchor: { x: 14.3574, y: 3.62891 },
|
|
24
|
+
rightEyeAnchor: { x: 67.3772, y: 3.62841 },
|
|
25
|
+
leftEyePaths: [
|
|
26
|
+
"M3.53125 0.164063C4.90133 0.164063 5.58673 0.163893 6.08301 0.485352C6.31917 0.638428 6.52075 0.840012 6.67383 1.07617C6.99555 1.57252 6.99512 2.25826 6.99512 3.62891C6.99512 4.99911 6.99536 5.68438 6.67383 6.18066C6.52075 6.41682 6.31917 6.61841 6.08301 6.77148C5.58672 7.09305 4.90147 7.09277 3.53125 7.09277C2.16062 7.09277 1.47486 7.09319 0.978516 6.77148C0.742356 6.61841 0.540772 6.41682 0.387695 6.18066C0.0662401 5.68439 0.0664063 4.999 0.0664063 3.62891C0.0664063 2.25838 0.0660571 1.57251 0.387695 1.07617C0.540772 0.840012 0.742356 0.638428 0.978516 0.485352C1.47485 0.163744 2.16076 0.164063 3.53125 0.164063Z",
|
|
27
|
+
"M25.1836 0.164063C26.5542 0.164063 27.24 0.163638 27.7363 0.485352C27.9724 0.638384 28.1731 0.8401 28.3262 1.07617C28.6479 1.57252 28.6484 2.25825 28.6484 3.62891C28.6484 4.99931 28.6478 5.68436 28.3262 6.18066C28.1731 6.41678 27.9724 6.61842 27.7363 6.77148C27.24 7.09321 26.5542 7.09277 25.1836 7.09277H11.3262C9.95557 7.09277 9.26978 7.09317 8.77344 6.77148C8.53728 6.61841 8.33569 6.41682 8.18262 6.18066C7.86115 5.68438 7.86133 4.99902 7.86133 3.62891C7.86133 2.25835 7.86096 1.57251 8.18262 1.07617C8.33569 0.840012 8.53728 0.638428 8.77344 0.485352C9.26977 0.163768 9.95572 0.164063 11.3262 0.164063H25.1836Z"
|
|
28
|
+
],
|
|
29
|
+
rightEyePaths: [
|
|
30
|
+
"M78.2034 7.09325C76.8333 7.09325 76.1479 7.09342 75.6516 6.77197C75.4155 6.61889 75.2139 6.4173 75.0608 6.18114C74.7391 5.6848 74.7395 4.99905 74.7395 3.62841C74.7395 2.2582 74.7393 1.57294 75.0608 1.07665C75.2139 0.840493 75.4155 0.638909 75.6516 0.485832C76.1479 0.164271 76.8332 0.164543 78.2034 0.164543C79.574 0.164543 80.2598 0.164122 80.7561 0.485832C80.9923 0.638909 81.1939 0.840493 81.347 1.07665C81.6684 1.57293 81.6682 2.25831 81.6682 3.62841C81.6682 4.99894 81.6686 5.68481 81.347 6.18114C81.1939 6.4173 80.9923 6.61889 80.7561 6.77197C80.2598 7.09357 79.5739 7.09325 78.2034 7.09325Z",
|
|
31
|
+
"M56.5511 7.09325C55.1804 7.09325 54.4947 7.09368 53.9983 6.77197C53.7622 6.61893 53.5615 6.41722 53.4085 6.18114C53.0868 5.6848 53.0862 4.99907 53.0862 3.62841C53.0862 2.258 53.0868 1.57296 53.4085 1.07665C53.5615 0.840539 53.7622 0.638898 53.9983 0.485832C54.4947 0.164105 55.1804 0.164543 56.5511 0.164543H70.4085C71.7791 0.164543 72.4649 0.164146 72.9612 0.485832C73.1974 0.638909 73.399 0.840493 73.552 1.07665C73.8735 1.57293 73.8733 2.25829 73.8733 3.62841C73.8733 4.99896 73.8737 5.68481 73.552 6.18114C73.399 6.4173 73.1974 6.61889 72.9612 6.77197C72.4649 7.09355 71.7789 7.09325 70.4085 7.09325H56.5511Z"
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
curved: {
|
|
35
|
+
viewBox: { width: 63, height: 9 },
|
|
36
|
+
leftEyeAnchor: { x: 10.5, y: 4.5 },
|
|
37
|
+
rightEyeAnchor: { x: 52.5, y: 4.5 },
|
|
38
|
+
leftEyePaths: [
|
|
39
|
+
"M0 5.06511C0 4.94513 0 4.88513 0.00771184 4.79757C0.0483059 4.33665 0.341025 3.76395 0.690821 3.46107C0.757274 3.40353 0.783996 3.38422 0.837439 3.34559C2.40699 2.21129 6.03888 0 10.5 0C14.9611 0 18.593 2.21129 20.1626 3.34559C20.216 3.38422 20.2427 3.40353 20.3092 3.46107C20.659 3.76395 20.9517 4.33665 20.9923 4.79757C21 4.88513 21 4.94513 21 5.06511C21 6.01683 21 6.4927 20.9657 6.6754C20.7241 7.96423 19.8033 8.55941 18.5289 8.25054C18.3483 8.20676 17.8198 7.96876 16.7627 7.49275C14.975 6.68767 12.7805 6 10.5 6C8.21954 6 6.02504 6.68767 4.23727 7.49275C3.18025 7.96876 2.65174 8.20676 2.47108 8.25054C1.19668 8.55941 0.275917 7.96423 0.0342566 6.6754C0 6.4927 0 6.01683 0 5.06511Z"
|
|
40
|
+
],
|
|
41
|
+
rightEyePaths: [
|
|
42
|
+
"M42 5.06511C42 4.94513 42 4.88513 42.0077 4.79757C42.0483 4.33665 42.341 3.76395 42.6908 3.46107C42.7573 3.40353 42.784 3.38422 42.8374 3.34559C44.407 2.21129 48.0389 0 52.5 0C56.9611 0 60.593 2.21129 62.1626 3.34559C62.216 3.38422 62.2427 3.40353 62.3092 3.46107C62.659 3.76395 62.9517 4.33665 62.9923 4.79757C63 4.88513 63 4.94513 63 5.06511C63 6.01683 63 6.4927 62.9657 6.6754C62.7241 7.96423 61.8033 8.55941 60.5289 8.25054C60.3483 8.20676 59.8198 7.96876 58.7627 7.49275C56.975 6.68767 54.7805 6 52.5 6C50.2195 6 48.025 6.68767 46.2373 7.49275C45.1802 7.96876 44.6517 8.20676 44.4711 8.25054C43.1967 8.55941 42.2759 7.96423 42.0343 6.6754C42 6.4927 42 6.01683 42 5.06511Z"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/utils/hash.ts
|
|
48
|
+
function stringHash(value) {
|
|
49
|
+
let hash = 0;
|
|
50
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
51
|
+
const character = value.charCodeAt(index);
|
|
52
|
+
hash = (hash << 5) - hash + character;
|
|
53
|
+
hash &= hash;
|
|
54
|
+
}
|
|
55
|
+
return Math.abs(hash);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/core/facehash-data.ts
|
|
59
|
+
var FACE_TYPES = ["round", "cross", "line", "curved"];
|
|
60
|
+
var SPHERE_POSITIONS = [
|
|
61
|
+
{ x: -1, y: 1 },
|
|
62
|
+
{ x: 1, y: 1 },
|
|
63
|
+
{ x: 1, y: 0 },
|
|
64
|
+
{ x: 0, y: 1 },
|
|
65
|
+
{ x: -1, y: 0 },
|
|
66
|
+
{ x: 0, y: 0 },
|
|
67
|
+
{ x: 0, y: -1 },
|
|
68
|
+
{ x: -1, y: -1 },
|
|
69
|
+
{ x: 1, y: -1 }
|
|
70
|
+
];
|
|
71
|
+
var DEFAULT_COLORS = ["#ec4899", "#f59e0b", "#3b82f6", "#f97316", "#10b981"];
|
|
72
|
+
var FALLBACK_COLOR = "#ec4899";
|
|
73
|
+
function computeFacehash(options) {
|
|
74
|
+
const { name, colorsLength = DEFAULT_COLORS.length } = options;
|
|
75
|
+
const hash = stringHash(name);
|
|
76
|
+
const faceIndex = hash % FACE_TYPES.length;
|
|
77
|
+
const colorIndex = hash % colorsLength;
|
|
78
|
+
const positionIndex = hash % SPHERE_POSITIONS.length;
|
|
79
|
+
const position = SPHERE_POSITIONS[positionIndex] ?? { x: 0, y: 0 };
|
|
80
|
+
const blinkSeed = hash * 31;
|
|
81
|
+
const blinkTiming = {
|
|
82
|
+
delay: blinkSeed % 40 / 10,
|
|
83
|
+
duration: 2 + blinkSeed % 40 / 10
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
faceType: FACE_TYPES[faceIndex] ?? "round",
|
|
87
|
+
colorIndex,
|
|
88
|
+
rotation: position,
|
|
89
|
+
initial: name.charAt(0).toUpperCase(),
|
|
90
|
+
blinkTimings: {
|
|
91
|
+
left: { ...blinkTiming },
|
|
92
|
+
right: { ...blinkTiming }
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function getColor(colors, index) {
|
|
97
|
+
const palette = colors && colors.length > 0 ? colors : DEFAULT_COLORS;
|
|
98
|
+
return palette[index % palette.length] ?? FALLBACK_COLOR;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/core/scene.ts
|
|
102
|
+
var PROJECTION_PRESETS = {
|
|
103
|
+
none: { translate: 0, compress: 0, skewX: 0, skewY: 0, gradientShift: 0 },
|
|
104
|
+
subtle: { translate: 2.25, compress: 0.035, skewX: 1.5, skewY: 0.75, gradientShift: 2.5 },
|
|
105
|
+
medium: { translate: 3.5, compress: 0.055, skewX: 2.5, skewY: 1.25, gradientShift: 4 },
|
|
106
|
+
dramatic: { translate: 5, compress: 0.08, skewX: 3.5, skewY: 1.75, gradientShift: 6 }
|
|
107
|
+
};
|
|
108
|
+
var FACE_WIDTH = 60;
|
|
109
|
+
var FACE_CENTER_Y = 37;
|
|
110
|
+
var INITIAL_Y = 70;
|
|
111
|
+
var INITIAL_FONT_SIZE = 26;
|
|
112
|
+
function toFixedNumber(value) {
|
|
113
|
+
return Number(value.toFixed(3));
|
|
114
|
+
}
|
|
115
|
+
function formatPercent(value) {
|
|
116
|
+
return `${toFixedNumber(value)}%`;
|
|
117
|
+
}
|
|
118
|
+
function formatDegrees(value) {
|
|
119
|
+
return `${toFixedNumber(value)}deg`;
|
|
120
|
+
}
|
|
121
|
+
function buildCssTransform(projection) {
|
|
122
|
+
return [`translate(${formatPercent(projection.translateX)}, ${formatPercent(projection.translateY)})`, `skew(${formatDegrees(projection.skewX)}, ${formatDegrees(projection.skewY)})`, `scale(${toFixedNumber(projection.scaleX)}, ${toFixedNumber(projection.scaleY)})`].join(" ");
|
|
123
|
+
}
|
|
124
|
+
function buildSvgTransform(projection) {
|
|
125
|
+
return [
|
|
126
|
+
`translate(${toFixedNumber(projection.translateX)} ${toFixedNumber(projection.translateY)})`,
|
|
127
|
+
"translate(50 50)",
|
|
128
|
+
`skewX(${toFixedNumber(projection.skewX)})`,
|
|
129
|
+
`skewY(${toFixedNumber(projection.skewY)})`,
|
|
130
|
+
`scale(${toFixedNumber(projection.scaleX)} ${toFixedNumber(projection.scaleY)})`,
|
|
131
|
+
"translate(-50 -50)"
|
|
132
|
+
].join(" ");
|
|
133
|
+
}
|
|
134
|
+
function createProjection(rotation, intensity3d) {
|
|
135
|
+
const preset = PROJECTION_PRESETS[intensity3d];
|
|
136
|
+
const baseProjection = {
|
|
137
|
+
translateX: rotation.y * preset.translate,
|
|
138
|
+
translateY: rotation.x * -preset.translate,
|
|
139
|
+
scaleX: 1 - Math.abs(rotation.y) * preset.compress,
|
|
140
|
+
scaleY: 1 - Math.abs(rotation.x) * preset.compress,
|
|
141
|
+
skewX: rotation.x * -preset.skewX,
|
|
142
|
+
skewY: rotation.y * preset.skewY
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
...baseProjection,
|
|
146
|
+
cssTransform: buildCssTransform(baseProjection),
|
|
147
|
+
svgTransform: buildSvgTransform(baseProjection)
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function createFacehashScene(options) {
|
|
151
|
+
const { name, colorsLength, intensity3d = "dramatic", pose = "seed" } = options;
|
|
152
|
+
const data = computeFacehash({ name, colorsLength });
|
|
153
|
+
const rotation = pose === "front" ? { x: 0, y: 0 } : data.rotation;
|
|
154
|
+
const faceGeometry = FACE_GEOMETRIES[data.faceType];
|
|
155
|
+
const aspectRatio = faceGeometry.viewBox.width / Math.max(faceGeometry.viewBox.height, 1);
|
|
156
|
+
const faceHeight = FACE_WIDTH / aspectRatio;
|
|
157
|
+
const projection = createProjection(rotation, intensity3d);
|
|
158
|
+
const preset = PROJECTION_PRESETS[intensity3d];
|
|
159
|
+
return {
|
|
160
|
+
data,
|
|
161
|
+
faceGeometry,
|
|
162
|
+
projection,
|
|
163
|
+
gradientCenter: {
|
|
164
|
+
x: 50 - rotation.y * preset.gradientShift,
|
|
165
|
+
y: 50 + rotation.x * preset.gradientShift
|
|
166
|
+
},
|
|
167
|
+
faceBox: {
|
|
168
|
+
x: 50 - FACE_WIDTH / 2,
|
|
169
|
+
y: FACE_CENTER_Y - faceHeight / 2,
|
|
170
|
+
width: FACE_WIDTH,
|
|
171
|
+
height: faceHeight
|
|
172
|
+
},
|
|
173
|
+
initialLayout: {
|
|
174
|
+
x: 50,
|
|
175
|
+
y: INITIAL_Y,
|
|
176
|
+
fontSize: INITIAL_FONT_SIZE
|
|
177
|
+
},
|
|
178
|
+
pose
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export {
|
|
183
|
+
FACE_GEOMETRIES,
|
|
184
|
+
DEFAULT_COLORS,
|
|
185
|
+
computeFacehash,
|
|
186
|
+
getColor,
|
|
187
|
+
createFacehashScene
|
|
188
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FaceType } from "./facehash-data.js";
|
|
2
|
+
export type EyeAnchor = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
export type FaceGeometry = {
|
|
7
|
+
viewBox: {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
leftEyeAnchor: EyeAnchor;
|
|
12
|
+
rightEyeAnchor: EyeAnchor;
|
|
13
|
+
leftEyePaths: string[];
|
|
14
|
+
rightEyePaths: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare const FACE_GEOMETRIES: Record<FaceType, FaceGeometry>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type Variant = "gradient" | "solid";
|
|
2
|
+
export type FaceType = "round" | "cross" | "line" | "curved";
|
|
3
|
+
export type FacehashBlinkTiming = {
|
|
4
|
+
delay: number;
|
|
5
|
+
duration: number;
|
|
6
|
+
};
|
|
7
|
+
export type FacehashBlinkTimings = {
|
|
8
|
+
left: FacehashBlinkTiming;
|
|
9
|
+
right: FacehashBlinkTiming;
|
|
10
|
+
};
|
|
11
|
+
export type FacehashData = {
|
|
12
|
+
faceType: FaceType;
|
|
13
|
+
colorIndex: number;
|
|
14
|
+
rotation: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
};
|
|
18
|
+
initial: string;
|
|
19
|
+
blinkTimings: FacehashBlinkTimings;
|
|
20
|
+
};
|
|
21
|
+
export type ComputeFacehashOptions = {
|
|
22
|
+
name: string;
|
|
23
|
+
colorsLength?: number;
|
|
24
|
+
};
|
|
25
|
+
export declare const DEFAULT_COLORS: readonly ["#ec4899", "#f59e0b", "#3b82f6", "#f97316", "#10b981"];
|
|
26
|
+
export declare function computeFacehash(options: ComputeFacehashOptions): FacehashData;
|
|
27
|
+
export declare function getColor(colors: readonly string[] | undefined, index: number): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { EyeAnchor, FaceGeometry } from "./face-geometry.js";
|
|
2
|
+
export { FACE_GEOMETRIES } from "./face-geometry.js";
|
|
3
|
+
export type { ComputeFacehashOptions, FaceType, FacehashBlinkTiming, FacehashBlinkTimings, FacehashData, Variant } from "./facehash-data.js";
|
|
4
|
+
export { DEFAULT_COLORS, computeFacehash, getColor } from "./facehash-data.js";
|
|
5
|
+
export type { CreateFacehashSceneOptions, FacehashPose, FacehashProjection, FacehashScene, Intensity3D } from "./scene.js";
|
|
6
|
+
export { createFacehashScene } from "./scene.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { FaceGeometry } from "./face-geometry.js";
|
|
2
|
+
import { type FacehashData } from "./facehash-data.js";
|
|
3
|
+
export type Intensity3D = "none" | "subtle" | "medium" | "dramatic";
|
|
4
|
+
export type FacehashPose = "seed" | "front";
|
|
5
|
+
export type FacehashProjection = {
|
|
6
|
+
translateX: number;
|
|
7
|
+
translateY: number;
|
|
8
|
+
scaleX: number;
|
|
9
|
+
scaleY: number;
|
|
10
|
+
skewX: number;
|
|
11
|
+
skewY: number;
|
|
12
|
+
cssTransform: string;
|
|
13
|
+
svgTransform: string;
|
|
14
|
+
};
|
|
15
|
+
export type FacehashScene = {
|
|
16
|
+
data: FacehashData;
|
|
17
|
+
faceGeometry: FaceGeometry;
|
|
18
|
+
projection: FacehashProjection;
|
|
19
|
+
gradientCenter: {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
};
|
|
23
|
+
faceBox: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
};
|
|
29
|
+
initialLayout: {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
fontSize: number;
|
|
33
|
+
};
|
|
34
|
+
pose: FacehashPose;
|
|
35
|
+
};
|
|
36
|
+
export type CreateFacehashSceneOptions = {
|
|
37
|
+
name: string;
|
|
38
|
+
colorsLength?: number;
|
|
39
|
+
intensity3d?: Intensity3D;
|
|
40
|
+
pose?: FacehashPose;
|
|
41
|
+
};
|
|
42
|
+
export declare function createFacehashScene(options: CreateFacehashSceneOptions): FacehashScene;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { CreateFacehashSceneOptions, EyeAnchor, FaceGeometry, FacehashBlinkTiming, FacehashBlinkTimings, FacehashData, FacehashPose, FacehashProjection, FacehashScene, FaceType, Intensity3D, Variant } from "./core/index.js";
|
|
2
|
+
export { DEFAULT_COLORS, FACE_GEOMETRIES, computeFacehash, createFacehashScene, getColor } from "./core/index.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { FacehashNativeProps } from "./FacehashNative.js";
|
|
2
|
+
export { FacehashNative } from "./FacehashNative.js";
|
|
3
|
+
export type { CreateFacehashSceneOptions, EyeAnchor, FaceGeometry, FacehashBlinkTiming, FacehashBlinkTimings, FacehashData, FacehashPose, FacehashProjection, FacehashScene, FaceType, Intensity3D, Variant } from "./core/index.js";
|
|
4
|
+
export { DEFAULT_COLORS, FACE_GEOMETRIES, computeFacehash, createFacehashScene, getColor } from "./core/index.js";
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_COLORS,
|
|
3
|
+
FACE_GEOMETRIES,
|
|
4
|
+
computeFacehash,
|
|
5
|
+
createFacehashScene,
|
|
6
|
+
getColor
|
|
7
|
+
} from "./chunk-KNE4N3T7.js";
|
|
8
|
+
|
|
9
|
+
// src/FacehashNative.tsx
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
import { Pressable, StyleSheet, View } from "react-native";
|
|
12
|
+
|
|
13
|
+
// src/FacehashSceneSvg.native.tsx
|
|
14
|
+
import Svg, { Defs, G, Path, RadialGradient, Rect, Stop, Text as SvgText } from "react-native-svg";
|
|
15
|
+
|
|
16
|
+
// src/native-blink.ts
|
|
17
|
+
import { useEffect, useState } from "react";
|
|
18
|
+
var CLOSED_SCALE_Y = 0.05;
|
|
19
|
+
var BLINK_CLOSED_MS = 85;
|
|
20
|
+
function buildEyeTransform(anchor, scaleY) {
|
|
21
|
+
return `translate(${anchor.x} ${anchor.y}) scale(1 ${scaleY}) translate(${-anchor.x} ${-anchor.y})`;
|
|
22
|
+
}
|
|
23
|
+
function useBlinkTransform(enableBlink, timing, anchor) {
|
|
24
|
+
const [scaleY, setScaleY] = useState(1);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!(enableBlink && timing)) {
|
|
27
|
+
setScaleY(1);
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
let closeTimeout;
|
|
31
|
+
let openTimeout;
|
|
32
|
+
let intervalId;
|
|
33
|
+
let cancelled = false;
|
|
34
|
+
const blink = () => {
|
|
35
|
+
if (cancelled) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
setScaleY(CLOSED_SCALE_Y);
|
|
39
|
+
openTimeout = setTimeout(() => {
|
|
40
|
+
if (!cancelled) {
|
|
41
|
+
setScaleY(1);
|
|
42
|
+
}
|
|
43
|
+
}, BLINK_CLOSED_MS);
|
|
44
|
+
};
|
|
45
|
+
closeTimeout = setTimeout(() => {
|
|
46
|
+
blink();
|
|
47
|
+
intervalId = setInterval(blink, timing.duration * 1e3);
|
|
48
|
+
}, timing.delay * 1e3);
|
|
49
|
+
return () => {
|
|
50
|
+
cancelled = true;
|
|
51
|
+
if (closeTimeout) {
|
|
52
|
+
clearTimeout(closeTimeout);
|
|
53
|
+
}
|
|
54
|
+
if (openTimeout) {
|
|
55
|
+
clearTimeout(openTimeout);
|
|
56
|
+
}
|
|
57
|
+
if (intervalId) {
|
|
58
|
+
clearInterval(intervalId);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}, [enableBlink, timing]);
|
|
62
|
+
return buildEyeTransform(anchor, scaleY);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/FacehashSceneSvg.native.tsx
|
|
66
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
67
|
+
function renderEye(paths, transform) {
|
|
68
|
+
return /* @__PURE__ */ jsx(G, { transform, children: paths.map((path) => /* @__PURE__ */ jsx(Path, { d: path, fill: "white" }, path)) });
|
|
69
|
+
}
|
|
70
|
+
function FacehashSceneSvgNative({ backgroundColor, enableBlink = false, idPrefix, scene, showInitial, size, variant }) {
|
|
71
|
+
const leftBlinkTransform = useBlinkTransform(enableBlink, scene.data.blinkTimings.left, scene.faceGeometry.leftEyeAnchor);
|
|
72
|
+
const rightBlinkTransform = useBlinkTransform(enableBlink, scene.data.blinkTimings.right, scene.faceGeometry.rightEyeAnchor);
|
|
73
|
+
const gradientId = `${idPrefix}-gradient`;
|
|
74
|
+
return /* @__PURE__ */ jsxs(Svg, { fill: "none", height: size, viewBox: "0 0 100 100", width: size, children: [
|
|
75
|
+
/* @__PURE__ */ jsx(Defs, { children: /* @__PURE__ */ jsxs(RadialGradient, { cx: `${scene.gradientCenter.x}%`, cy: `${scene.gradientCenter.y}%`, id: gradientId, r: "70%", children: [
|
|
76
|
+
/* @__PURE__ */ jsx(Stop, { offset: "0%", stopColor: "#ffffff", stopOpacity: 0.15 }),
|
|
77
|
+
/* @__PURE__ */ jsx(Stop, { offset: "60%", stopColor: "#ffffff", stopOpacity: 0 })
|
|
78
|
+
] }) }),
|
|
79
|
+
/* @__PURE__ */ jsx(Rect, { fill: backgroundColor, height: "100", width: "100", x: "0", y: "0" }),
|
|
80
|
+
variant === "gradient" ? /* @__PURE__ */ jsx(Rect, { fill: `url(#${gradientId})`, height: "100", width: "100", x: "0", y: "0" }) : null,
|
|
81
|
+
/* @__PURE__ */ jsxs(G, { transform: scene.projection.svgTransform, children: [
|
|
82
|
+
/* @__PURE__ */ jsxs(G, { transform: `translate(${scene.faceBox.x} ${scene.faceBox.y}) scale(${scene.faceBox.width / scene.faceGeometry.viewBox.width} ${scene.faceBox.height / scene.faceGeometry.viewBox.height})`, children: [
|
|
83
|
+
renderEye(scene.faceGeometry.leftEyePaths, leftBlinkTransform),
|
|
84
|
+
renderEye(scene.faceGeometry.rightEyePaths, rightBlinkTransform)
|
|
85
|
+
] }),
|
|
86
|
+
showInitial ? /* @__PURE__ */ jsx(SvgText, { alignmentBaseline: "middle", fill: "white", fontFamily: "monospace", fontSize: scene.initialLayout.fontSize, fontWeight: "700", textAnchor: "middle", x: scene.initialLayout.x, y: scene.initialLayout.y, children: scene.data.initial }) : null
|
|
87
|
+
] })
|
|
88
|
+
] });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/FacehashNative.tsx
|
|
92
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
93
|
+
function sanitizeId(value) {
|
|
94
|
+
return value.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
95
|
+
}
|
|
96
|
+
function FacehashNative({ name, size = 40, variant = "gradient", intensity3d = "dramatic", interactive = true, showInitial = true, colors, enableBlink = false, renderMouth, testID }) {
|
|
97
|
+
const [isPressed, setIsPressed] = React.useState(false);
|
|
98
|
+
const colorsLength = colors?.length ?? 1;
|
|
99
|
+
const scene = React.useMemo(
|
|
100
|
+
() => createFacehashScene({
|
|
101
|
+
name,
|
|
102
|
+
colorsLength,
|
|
103
|
+
intensity3d,
|
|
104
|
+
pose: isPressed && interactive ? "front" : "seed"
|
|
105
|
+
}),
|
|
106
|
+
[colorsLength, intensity3d, interactive, isPressed, name]
|
|
107
|
+
);
|
|
108
|
+
const backgroundColor = getColor(colors, scene.data.colorIndex);
|
|
109
|
+
const idPrefix = React.useMemo(() => sanitizeId(`facehash-native-${name}`), [name]);
|
|
110
|
+
return /* @__PURE__ */ jsxs2(Pressable, { onPressIn: interactive ? () => setIsPressed(true) : void 0, onPressOut: interactive ? () => setIsPressed(false) : void 0, style: [styles.container, { width: size, height: size, borderRadius: size / 2, backgroundColor }], testID, children: [
|
|
111
|
+
/* @__PURE__ */ jsx2(FacehashSceneSvgNative, { backgroundColor, enableBlink, idPrefix, scene, showInitial: showInitial && !renderMouth, size, variant }),
|
|
112
|
+
renderMouth ? /* @__PURE__ */ jsx2(View, { style: styles.mouth, children: renderMouth() }) : null
|
|
113
|
+
] });
|
|
114
|
+
}
|
|
115
|
+
var styles = StyleSheet.create({
|
|
116
|
+
container: {
|
|
117
|
+
alignItems: "center",
|
|
118
|
+
justifyContent: "center",
|
|
119
|
+
overflow: "hidden",
|
|
120
|
+
position: "relative"
|
|
121
|
+
},
|
|
122
|
+
mouth: {
|
|
123
|
+
alignItems: "center",
|
|
124
|
+
height: "100%",
|
|
125
|
+
justifyContent: "center",
|
|
126
|
+
pointerEvents: "none",
|
|
127
|
+
position: "absolute",
|
|
128
|
+
width: "100%",
|
|
129
|
+
top: "70%"
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
export {
|
|
133
|
+
DEFAULT_COLORS,
|
|
134
|
+
FACE_GEOMETRIES,
|
|
135
|
+
FacehashNative,
|
|
136
|
+
computeFacehash,
|
|
137
|
+
createFacehashScene,
|
|
138
|
+
getColor
|
|
139
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { EyeAnchor, FacehashBlinkTiming } from "./core/index.js";
|
|
2
|
+
export declare function buildEyeTransform(anchor: EyeAnchor, scaleY: number): string;
|
|
3
|
+
export declare function useBlinkTransform(enableBlink: boolean | undefined, timing: FacehashBlinkTiming | undefined, anchor: EyeAnchor): string;
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { FacehashProps } from "./Facehash.js";
|
|
2
|
+
export { Facehash } from "./Facehash.js";
|
|
3
|
+
export type { CreateFacehashSceneOptions, EyeAnchor, FaceGeometry, FacehashBlinkTiming, FacehashBlinkTimings, FacehashData, FacehashPose, FacehashProjection, FacehashScene, FaceType, Intensity3D, Variant } from "./core/index.js";
|
|
4
|
+
export { DEFAULT_COLORS, FACE_GEOMETRIES, computeFacehash, createFacehashScene, getColor } from "./core/index.js";
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_COLORS,
|
|
3
|
+
FACE_GEOMETRIES,
|
|
4
|
+
computeFacehash,
|
|
5
|
+
createFacehashScene,
|
|
6
|
+
getColor
|
|
7
|
+
} from "./chunk-KNE4N3T7.js";
|
|
8
|
+
|
|
9
|
+
// src/Facehash.tsx
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
|
|
12
|
+
// src/blink.ts
|
|
13
|
+
var BLINK_KEYFRAMES = `
|
|
14
|
+
@keyframes facehash-blink {
|
|
15
|
+
0%, 92%, 100% { transform: scaleY(1); }
|
|
16
|
+
96% { transform: scaleY(0.05); }
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
var keyframesInjected = false;
|
|
20
|
+
function ensureBlinkKeyframes() {
|
|
21
|
+
if (keyframesInjected || typeof document === "undefined") {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const style = document.createElement("style");
|
|
25
|
+
style.textContent = BLINK_KEYFRAMES;
|
|
26
|
+
document.head.appendChild(style);
|
|
27
|
+
keyframesInjected = true;
|
|
28
|
+
}
|
|
29
|
+
function getBlinkStyle(enableBlink, timing) {
|
|
30
|
+
if (!(enableBlink && timing)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
animation: `facehash-blink ${timing.duration}s ease-in-out ${timing.delay}s infinite`,
|
|
35
|
+
transformBox: "fill-box",
|
|
36
|
+
transformOrigin: "center center"
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/FacehashSceneSvg.tsx
|
|
41
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
42
|
+
function sanitizeId(value) {
|
|
43
|
+
return value.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
44
|
+
}
|
|
45
|
+
function FacehashSceneSvg({ backgroundColor, enableBlink = false, height = "100%", idPrefix, scene, showInitial, style, variant, width = "100%", withAnimatedProjection = false }) {
|
|
46
|
+
if (enableBlink) {
|
|
47
|
+
ensureBlinkKeyframes();
|
|
48
|
+
}
|
|
49
|
+
const gradientId = `${sanitizeId(idPrefix)}-gradient`;
|
|
50
|
+
const projectionStyle = withAnimatedProjection ? {
|
|
51
|
+
transformBox: "view-box",
|
|
52
|
+
transformOrigin: "50% 50%",
|
|
53
|
+
transform: scene.projection.cssTransform,
|
|
54
|
+
transition: "transform 0.3s cubic-bezier(0.4, 0, 0.2, 1)"
|
|
55
|
+
} : void 0;
|
|
56
|
+
return /* @__PURE__ */ jsxs(
|
|
57
|
+
"svg",
|
|
58
|
+
{
|
|
59
|
+
"aria-hidden": "true",
|
|
60
|
+
fill: "none",
|
|
61
|
+
height,
|
|
62
|
+
style: {
|
|
63
|
+
color: "inherit",
|
|
64
|
+
display: "block",
|
|
65
|
+
overflow: "visible",
|
|
66
|
+
...style
|
|
67
|
+
},
|
|
68
|
+
viewBox: "0 0 100 100",
|
|
69
|
+
width,
|
|
70
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
71
|
+
children: [
|
|
72
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("radialGradient", { cx: `${scene.gradientCenter.x}%`, cy: `${scene.gradientCenter.y}%`, id: gradientId, r: "70%", children: [
|
|
73
|
+
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: "#ffffff", stopOpacity: "0.15" }),
|
|
74
|
+
/* @__PURE__ */ jsx("stop", { offset: "60%", stopColor: "#ffffff", stopOpacity: "0" })
|
|
75
|
+
] }) }),
|
|
76
|
+
/* @__PURE__ */ jsx("rect", { fill: backgroundColor, height: "100", width: "100", x: "0", y: "0" }),
|
|
77
|
+
variant === "gradient" ? /* @__PURE__ */ jsx("rect", { fill: `url(#${gradientId})`, height: "100", width: "100", x: "0", y: "0" }) : null,
|
|
78
|
+
/* @__PURE__ */ jsxs("g", { style: projectionStyle, transform: scene.projection.svgTransform, children: [
|
|
79
|
+
/* @__PURE__ */ jsxs("g", { transform: `translate(${scene.faceBox.x} ${scene.faceBox.y}) scale(${scene.faceBox.width / scene.faceGeometry.viewBox.width} ${scene.faceBox.height / scene.faceGeometry.viewBox.height})`, children: [
|
|
80
|
+
/* @__PURE__ */ jsx("g", { style: getBlinkStyle(enableBlink, scene.data.blinkTimings.left), children: scene.faceGeometry.leftEyePaths.map((path) => /* @__PURE__ */ jsx("path", { d: path, fill: "currentColor" }, path)) }),
|
|
81
|
+
/* @__PURE__ */ jsx("g", { style: getBlinkStyle(enableBlink, scene.data.blinkTimings.right), children: scene.faceGeometry.rightEyePaths.map((path) => /* @__PURE__ */ jsx("path", { d: path, fill: "currentColor" }, path)) })
|
|
82
|
+
] }),
|
|
83
|
+
showInitial ? /* @__PURE__ */ jsx("text", { dominantBaseline: "middle", fill: "currentColor", fontFamily: "monospace", fontSize: scene.initialLayout.fontSize, fontWeight: "700", textAnchor: "middle", x: scene.initialLayout.x, y: scene.initialLayout.y, children: scene.data.initial }) : null
|
|
84
|
+
] })
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/Facehash.tsx
|
|
91
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
92
|
+
function sanitizeId2(value) {
|
|
93
|
+
return value.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
94
|
+
}
|
|
95
|
+
var Facehash = React.forwardRef(function Facehash2({ name, size = 40, variant = "gradient", intensity3d = "dramatic", interactive = true, showInitial = true, colors, enableBlink = false, renderMouth, className, style, onMouseEnter, onMouseLeave, ...props }, ref) {
|
|
96
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
97
|
+
const reactId = React.useId();
|
|
98
|
+
const colorsLength = colors?.length ?? 1;
|
|
99
|
+
const scene = React.useMemo(
|
|
100
|
+
() => createFacehashScene({
|
|
101
|
+
name,
|
|
102
|
+
colorsLength,
|
|
103
|
+
intensity3d,
|
|
104
|
+
pose: isHovered && interactive ? "front" : "seed"
|
|
105
|
+
}),
|
|
106
|
+
[colorsLength, intensity3d, interactive, isHovered, name]
|
|
107
|
+
);
|
|
108
|
+
const backgroundColor = getColor(colors, scene.data.colorIndex);
|
|
109
|
+
const sizeValue = typeof size === "number" ? `${size}px` : size;
|
|
110
|
+
const svgIdPrefix = React.useMemo(() => sanitizeId2(`facehash-${reactId}-${name}`), [name, reactId]);
|
|
111
|
+
return /* @__PURE__ */ jsxs2(
|
|
112
|
+
"div",
|
|
113
|
+
{
|
|
114
|
+
className,
|
|
115
|
+
"data-facehash": "",
|
|
116
|
+
"data-interactive": interactive || void 0,
|
|
117
|
+
onMouseEnter: (event) => {
|
|
118
|
+
if (interactive) {
|
|
119
|
+
setIsHovered(true);
|
|
120
|
+
}
|
|
121
|
+
onMouseEnter?.(event);
|
|
122
|
+
},
|
|
123
|
+
onMouseLeave: (event) => {
|
|
124
|
+
if (interactive) {
|
|
125
|
+
setIsHovered(false);
|
|
126
|
+
}
|
|
127
|
+
onMouseLeave?.(event);
|
|
128
|
+
},
|
|
129
|
+
ref,
|
|
130
|
+
style: {
|
|
131
|
+
alignItems: "center",
|
|
132
|
+
backgroundColor,
|
|
133
|
+
color: "#ffffff",
|
|
134
|
+
display: "flex",
|
|
135
|
+
height: sizeValue,
|
|
136
|
+
justifyContent: "center",
|
|
137
|
+
overflow: "hidden",
|
|
138
|
+
position: "relative",
|
|
139
|
+
width: sizeValue,
|
|
140
|
+
...style
|
|
141
|
+
},
|
|
142
|
+
...props,
|
|
143
|
+
children: [
|
|
144
|
+
/* @__PURE__ */ jsx2(FacehashSceneSvg, { backgroundColor, enableBlink, height: "100%", idPrefix: svgIdPrefix, scene, showInitial: showInitial && !renderMouth, variant, width: "100%", withAnimatedProjection: interactive }),
|
|
145
|
+
renderMouth ? /* @__PURE__ */ jsx2(
|
|
146
|
+
"div",
|
|
147
|
+
{
|
|
148
|
+
"data-facehash-mouth": "",
|
|
149
|
+
style: {
|
|
150
|
+
alignItems: "center",
|
|
151
|
+
display: "flex",
|
|
152
|
+
inset: 0,
|
|
153
|
+
justifyContent: "center",
|
|
154
|
+
left: "50%",
|
|
155
|
+
pointerEvents: "none",
|
|
156
|
+
position: "absolute",
|
|
157
|
+
top: "70%",
|
|
158
|
+
transform: "translate(-50%, -50%)",
|
|
159
|
+
zIndex: 1
|
|
160
|
+
},
|
|
161
|
+
children: renderMouth()
|
|
162
|
+
}
|
|
163
|
+
) : null
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
export {
|
|
169
|
+
DEFAULT_COLORS,
|
|
170
|
+
FACE_GEOMETRIES,
|
|
171
|
+
Facehash,
|
|
172
|
+
computeFacehash,
|
|
173
|
+
createFacehashScene,
|
|
174
|
+
getColor
|
|
175
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function stringHash(value: string): number;
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@q9labsai/facehash",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Q9Labs/chalk.git",
|
|
8
|
+
"directory": "packages/facehash"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"typesVersions": {
|
|
19
|
+
"*": {
|
|
20
|
+
"react": [
|
|
21
|
+
"./dist/react.d.ts"
|
|
22
|
+
],
|
|
23
|
+
"react-native": [
|
|
24
|
+
"./dist/index.native.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"*": [
|
|
27
|
+
"./dist/index.d.ts"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"require": "./dist/index.js",
|
|
36
|
+
"default": "./dist/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./react": {
|
|
39
|
+
"types": "./dist/react.d.ts",
|
|
40
|
+
"import": "./dist/react.js",
|
|
41
|
+
"default": "./dist/react.js"
|
|
42
|
+
},
|
|
43
|
+
"./react-native": {
|
|
44
|
+
"types": "./dist/index.native.d.ts",
|
|
45
|
+
"react-native": "./dist/index.native.js",
|
|
46
|
+
"import": "./dist/index.native.js",
|
|
47
|
+
"default": "./dist/index.native.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public",
|
|
52
|
+
"registry": "https://registry.npmjs.org/"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^24.10.1",
|
|
56
|
+
"@types/react": "^19.0.0",
|
|
57
|
+
"react-dom": "19.2.7",
|
|
58
|
+
"typescript": "^5.7.2"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
62
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
63
|
+
"react-native": ">=0.77",
|
|
64
|
+
"react-native-svg": "^15.15.3"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"react-dom": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"react-native": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"react-native-svg": {
|
|
74
|
+
"optional": true
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"build": "rm -rf ./dist && tsup ./src/index.ts ./src/react.ts ./src/index.native.ts --format esm --out-dir ./dist --platform browser --external react --external react-dom --external react-native --external react-native-svg && pnpm run build:types",
|
|
79
|
+
"build:types": "rm -f tsconfig.tsbuildinfo && tsc --project tsconfig.json && node ../../scripts/rewrite-declaration-specifiers.mjs ./dist",
|
|
80
|
+
"dev": "tsup ./src/index.ts ./src/react.ts ./src/index.native.ts --format esm --out-dir ./dist --platform browser --external react --external react-dom --external react-native --external react-native-svg --watch",
|
|
81
|
+
"test": "pnpm exec vitest run && pnpm run test:declarations",
|
|
82
|
+
"test:declarations": "node --test scripts/rewrite-declaration-specifiers.node.mjs",
|
|
83
|
+
"check-types": "tsc --noEmit",
|
|
84
|
+
"lint": "pnpm exec oxfmt --check . && tsc --noEmit"
|
|
85
|
+
}
|
|
86
|
+
}
|