@q9labsai/facehash 4.1.11 → 4.1.12
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/FacehashSceneSvg.native.d.ts +2 -1
- package/dist/{chunk-KNE4N3T7.js → chunk-4GRTZKFS.js} +26 -0
- package/dist/core/facehash-data.d.ts +1 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -3
- package/dist/index.native.js +11 -9
- package/dist/react.d.ts +1 -1
- package/dist/react.js +7 -4
- package/package.json +1 -1
|
@@ -2,11 +2,12 @@ import type { FacehashScene, Variant } from "./core/index.js";
|
|
|
2
2
|
type FacehashSceneSvgNativeProps = {
|
|
3
3
|
backgroundColor: string;
|
|
4
4
|
enableBlink?: boolean;
|
|
5
|
+
foregroundColor: string;
|
|
5
6
|
idPrefix: string;
|
|
6
7
|
scene: FacehashScene;
|
|
7
8
|
showInitial: boolean;
|
|
8
9
|
size: number;
|
|
9
10
|
variant: Variant;
|
|
10
11
|
};
|
|
11
|
-
export declare function FacehashSceneSvgNative({ backgroundColor, enableBlink, idPrefix, scene, showInitial, size, variant }: FacehashSceneSvgNativeProps): React.JSX.Element;
|
|
12
|
+
export declare function FacehashSceneSvgNative({ backgroundColor, enableBlink, foregroundColor, idPrefix, scene, showInitial, size, variant }: FacehashSceneSvgNativeProps): React.JSX.Element;
|
|
12
13
|
export {};
|
|
@@ -70,6 +70,21 @@ var SPHERE_POSITIONS = [
|
|
|
70
70
|
];
|
|
71
71
|
var DEFAULT_COLORS = ["#ec4899", "#f59e0b", "#3b82f6", "#f97316", "#10b981"];
|
|
72
72
|
var FALLBACK_COLOR = "#ec4899";
|
|
73
|
+
var DARK_FOREGROUND = "#111827";
|
|
74
|
+
var LIGHT_FOREGROUND = "#ffffff";
|
|
75
|
+
function parseHexColor(color) {
|
|
76
|
+
const value = color.trim().replace(/^#/, "");
|
|
77
|
+
const expanded = value.length === 3 ? [...value].map((character) => `${character}${character}`).join("") : value;
|
|
78
|
+
if (!/^[\da-f]{6}$/i.test(expanded)) return void 0;
|
|
79
|
+
return [Number.parseInt(expanded.slice(0, 2), 16), Number.parseInt(expanded.slice(2, 4), 16), Number.parseInt(expanded.slice(4, 6), 16)];
|
|
80
|
+
}
|
|
81
|
+
function relativeLuminance(color) {
|
|
82
|
+
const linearize = (channel) => {
|
|
83
|
+
const value = channel / 255;
|
|
84
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
85
|
+
};
|
|
86
|
+
return 0.2126 * linearize(color[0]) + 0.7152 * linearize(color[1]) + 0.0722 * linearize(color[2]);
|
|
87
|
+
}
|
|
73
88
|
function computeFacehash(options) {
|
|
74
89
|
const { name, colorsLength = DEFAULT_COLORS.length } = options;
|
|
75
90
|
const hash = stringHash(name);
|
|
@@ -97,6 +112,16 @@ function getColor(colors, index) {
|
|
|
97
112
|
const palette = colors && colors.length > 0 ? colors : DEFAULT_COLORS;
|
|
98
113
|
return palette[index % palette.length] ?? FALLBACK_COLOR;
|
|
99
114
|
}
|
|
115
|
+
function getForegroundColor(backgroundColor) {
|
|
116
|
+
const background = parseHexColor(backgroundColor);
|
|
117
|
+
const dark = parseHexColor(DARK_FOREGROUND);
|
|
118
|
+
const light = parseHexColor(LIGHT_FOREGROUND);
|
|
119
|
+
if (!background || !dark || !light) return LIGHT_FOREGROUND;
|
|
120
|
+
const backgroundLuminance = relativeLuminance(background);
|
|
121
|
+
const darkContrast = (backgroundLuminance + 0.05) / (relativeLuminance(dark) + 0.05);
|
|
122
|
+
const lightContrast = (relativeLuminance(light) + 0.05) / (backgroundLuminance + 0.05);
|
|
123
|
+
return darkContrast > lightContrast ? DARK_FOREGROUND : LIGHT_FOREGROUND;
|
|
124
|
+
}
|
|
100
125
|
|
|
101
126
|
// src/core/scene.ts
|
|
102
127
|
var PROJECTION_PRESETS = {
|
|
@@ -184,5 +209,6 @@ export {
|
|
|
184
209
|
DEFAULT_COLORS,
|
|
185
210
|
computeFacehash,
|
|
186
211
|
getColor,
|
|
212
|
+
getForegroundColor,
|
|
187
213
|
createFacehashScene
|
|
188
214
|
};
|
|
@@ -25,3 +25,4 @@ export type ComputeFacehashOptions = {
|
|
|
25
25
|
export declare const DEFAULT_COLORS: readonly ["#ec4899", "#f59e0b", "#3b82f6", "#f97316", "#10b981"];
|
|
26
26
|
export declare function computeFacehash(options: ComputeFacehashOptions): FacehashData;
|
|
27
27
|
export declare function getColor(colors: readonly string[] | undefined, index: number): string;
|
|
28
|
+
export declare function getForegroundColor(backgroundColor: string): string;
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { EyeAnchor, FaceGeometry } from "./face-geometry.js";
|
|
2
2
|
export { FACE_GEOMETRIES } from "./face-geometry.js";
|
|
3
3
|
export type { ComputeFacehashOptions, FaceType, FacehashBlinkTiming, FacehashBlinkTimings, FacehashData, Variant } from "./facehash-data.js";
|
|
4
|
-
export { DEFAULT_COLORS, computeFacehash, getColor } from "./facehash-data.js";
|
|
4
|
+
export { DEFAULT_COLORS, computeFacehash, getColor, getForegroundColor } from "./facehash-data.js";
|
|
5
5
|
export type { CreateFacehashSceneOptions, FacehashPose, FacehashProjection, FacehashScene, Intensity3D } from "./scene.js";
|
|
6
6
|
export { createFacehashScene } from "./scene.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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";
|
|
2
|
+
export { DEFAULT_COLORS, FACE_GEOMETRIES, computeFacehash, createFacehashScene, getColor, getForegroundColor } from "./core/index.js";
|
package/dist/index.js
CHANGED
|
@@ -3,12 +3,14 @@ import {
|
|
|
3
3
|
FACE_GEOMETRIES,
|
|
4
4
|
computeFacehash,
|
|
5
5
|
createFacehashScene,
|
|
6
|
-
getColor
|
|
7
|
-
|
|
6
|
+
getColor,
|
|
7
|
+
getForegroundColor
|
|
8
|
+
} from "./chunk-4GRTZKFS.js";
|
|
8
9
|
export {
|
|
9
10
|
DEFAULT_COLORS,
|
|
10
11
|
FACE_GEOMETRIES,
|
|
11
12
|
computeFacehash,
|
|
12
13
|
createFacehashScene,
|
|
13
|
-
getColor
|
|
14
|
+
getColor,
|
|
15
|
+
getForegroundColor
|
|
14
16
|
};
|
package/dist/index.native.js
CHANGED
|
@@ -3,8 +3,9 @@ import {
|
|
|
3
3
|
FACE_GEOMETRIES,
|
|
4
4
|
computeFacehash,
|
|
5
5
|
createFacehashScene,
|
|
6
|
-
getColor
|
|
7
|
-
|
|
6
|
+
getColor,
|
|
7
|
+
getForegroundColor
|
|
8
|
+
} from "./chunk-4GRTZKFS.js";
|
|
8
9
|
|
|
9
10
|
// src/FacehashNative.tsx
|
|
10
11
|
import * as React from "react";
|
|
@@ -64,10 +65,10 @@ function useBlinkTransform(enableBlink, timing, anchor) {
|
|
|
64
65
|
|
|
65
66
|
// src/FacehashSceneSvg.native.tsx
|
|
66
67
|
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:
|
|
68
|
+
function renderEye(paths, transform, foregroundColor) {
|
|
69
|
+
return /* @__PURE__ */ jsx(G, { transform, children: paths.map((path) => /* @__PURE__ */ jsx(Path, { d: path, fill: foregroundColor }, path)) });
|
|
69
70
|
}
|
|
70
|
-
function FacehashSceneSvgNative({ backgroundColor, enableBlink = false, idPrefix, scene, showInitial, size, variant }) {
|
|
71
|
+
function FacehashSceneSvgNative({ backgroundColor, enableBlink = false, foregroundColor, idPrefix, scene, showInitial, size, variant }) {
|
|
71
72
|
const leftBlinkTransform = useBlinkTransform(enableBlink, scene.data.blinkTimings.left, scene.faceGeometry.leftEyeAnchor);
|
|
72
73
|
const rightBlinkTransform = useBlinkTransform(enableBlink, scene.data.blinkTimings.right, scene.faceGeometry.rightEyeAnchor);
|
|
73
74
|
const gradientId = `${idPrefix}-gradient`;
|
|
@@ -80,10 +81,10 @@ function FacehashSceneSvgNative({ backgroundColor, enableBlink = false, idPrefix
|
|
|
80
81
|
variant === "gradient" ? /* @__PURE__ */ jsx(Rect, { fill: `url(#${gradientId})`, height: "100", width: "100", x: "0", y: "0" }) : null,
|
|
81
82
|
/* @__PURE__ */ jsxs(G, { transform: scene.projection.svgTransform, children: [
|
|
82
83
|
/* @__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)
|
|
84
|
+
renderEye(scene.faceGeometry.leftEyePaths, leftBlinkTransform, foregroundColor),
|
|
85
|
+
renderEye(scene.faceGeometry.rightEyePaths, rightBlinkTransform, foregroundColor)
|
|
85
86
|
] }),
|
|
86
|
-
showInitial ? /* @__PURE__ */ jsx(SvgText, { alignmentBaseline: "middle", fill:
|
|
87
|
+
showInitial ? /* @__PURE__ */ jsx(SvgText, { alignmentBaseline: "middle", fill: foregroundColor, 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
|
] })
|
|
88
89
|
] });
|
|
89
90
|
}
|
|
@@ -106,9 +107,10 @@ function FacehashNative({ name, size = 40, variant = "gradient", intensity3d = "
|
|
|
106
107
|
[colorsLength, intensity3d, interactive, isPressed, name]
|
|
107
108
|
);
|
|
108
109
|
const backgroundColor = getColor(colors, scene.data.colorIndex);
|
|
110
|
+
const foregroundColor = getForegroundColor(backgroundColor);
|
|
109
111
|
const idPrefix = React.useMemo(() => sanitizeId(`facehash-native-${name}`), [name]);
|
|
110
112
|
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 }),
|
|
113
|
+
/* @__PURE__ */ jsx2(FacehashSceneSvgNative, { backgroundColor, enableBlink, foregroundColor, idPrefix, scene, showInitial: showInitial && !renderMouth, size, variant }),
|
|
112
114
|
renderMouth ? /* @__PURE__ */ jsx2(View, { style: styles.mouth, children: renderMouth() }) : null
|
|
113
115
|
] });
|
|
114
116
|
}
|
package/dist/react.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { FacehashProps } from "./Facehash.js";
|
|
2
2
|
export { Facehash } from "./Facehash.js";
|
|
3
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";
|
|
4
|
+
export { DEFAULT_COLORS, FACE_GEOMETRIES, computeFacehash, createFacehashScene, getColor, getForegroundColor } from "./core/index.js";
|
package/dist/react.js
CHANGED
|
@@ -3,8 +3,9 @@ import {
|
|
|
3
3
|
FACE_GEOMETRIES,
|
|
4
4
|
computeFacehash,
|
|
5
5
|
createFacehashScene,
|
|
6
|
-
getColor
|
|
7
|
-
|
|
6
|
+
getColor,
|
|
7
|
+
getForegroundColor
|
|
8
|
+
} from "./chunk-4GRTZKFS.js";
|
|
8
9
|
|
|
9
10
|
// src/Facehash.tsx
|
|
10
11
|
import * as React from "react";
|
|
@@ -106,6 +107,7 @@ var Facehash = React.forwardRef(function Facehash2({ name, size = 40, variant =
|
|
|
106
107
|
[colorsLength, intensity3d, interactive, isHovered, name]
|
|
107
108
|
);
|
|
108
109
|
const backgroundColor = getColor(colors, scene.data.colorIndex);
|
|
110
|
+
const foregroundColor = getForegroundColor(backgroundColor);
|
|
109
111
|
const sizeValue = typeof size === "number" ? `${size}px` : size;
|
|
110
112
|
const svgIdPrefix = React.useMemo(() => sanitizeId2(`facehash-${reactId}-${name}`), [name, reactId]);
|
|
111
113
|
return /* @__PURE__ */ jsxs2(
|
|
@@ -130,7 +132,7 @@ var Facehash = React.forwardRef(function Facehash2({ name, size = 40, variant =
|
|
|
130
132
|
style: {
|
|
131
133
|
alignItems: "center",
|
|
132
134
|
backgroundColor,
|
|
133
|
-
color:
|
|
135
|
+
color: foregroundColor,
|
|
134
136
|
display: "flex",
|
|
135
137
|
height: sizeValue,
|
|
136
138
|
justifyContent: "center",
|
|
@@ -171,5 +173,6 @@ export {
|
|
|
171
173
|
Facehash,
|
|
172
174
|
computeFacehash,
|
|
173
175
|
createFacehashScene,
|
|
174
|
-
getColor
|
|
176
|
+
getColor,
|
|
177
|
+
getForegroundColor
|
|
175
178
|
};
|