import { useId } from "react"; import type { CSSProperties } from "react"; import Accessories from "./top/accessories"; import Clothe from "./clothes"; import Face from "./face"; import Skin from "./Skin"; import Top from "./top"; import type { AvatarSvgProps } from "../types"; import { AvatarStyle } from "../types"; export { AvatarStyle }; export type { AvatarSvgProps as Props }; export default function Avatar({ avatarStyle, style }: AvatarSvgProps) { const path1 = useId(); const path2 = useId(); const path3 = useId(); const mask1 = useId(); const mask2 = useId(); const mask3 = useId(); const circle = avatarStyle === AvatarStyle.Circle; // Extract width and height from style prop if provided, otherwise use defaults const svgWidth = style?.width ? typeof style.width === "number" ? `${style.width}px` : style.width : "264px"; const svgHeight = style?.height ? typeof style.height === "number" ? `${style.height}px` : style.height : "280px"; // Determine if height was explicitly provided const heightWasProvided = style?.height !== undefined; // Create isolated style object that prevents external CSS from affecting the SVG const isolatedStyle: CSSProperties = { // CSS isolation: reset all inherited styles all: "initial", // Restore essential SVG properties display: "block", // Apply width from style prop or defaults width: svgWidth, // Make SVG responsive: scale down to fit container while maintaining aspect ratio // The viewBox (0 0 264 280) ensures aspect ratio is preserved when maxWidth constrains the width maxWidth: "100%", // Use provided height if given, otherwise auto for responsive scaling height: heightWasProvided ? svgHeight : "auto", // Merge other style properties (excluding width/height to avoid duplication) ...(style ? Object.entries(style) .filter(([key]) => key !== "width" && key !== "height") .reduce((acc, [key, value]) => { acc[key] = value; return acc; }, {} as Record) : {}), // Ensure these critical properties are always set to prevent external CSS interference boxSizing: "border-box", margin: "0", padding: "0", border: "none", verticalAlign: "baseline", font: "initial", color: "initial", background: "transparent", // Explicitly block visual effects that external CSS might try to add boxShadow: "none", filter: "none", backdropFilter: "none", textShadow: "none", // Prevent external transforms (we handle transforms internally for animations) transform: "none", // Prevent external opacity changes opacity: "1", }; return ( Created with getavataaars.com {circle ? ( ) : null} {circle ? ( ) : null} ); }