Merge version_1 into main #1

Merged
bender merged 1 commits from version_1 into main 2026-03-12 13:24:49 +00:00

View File

@@ -1,51 +1,77 @@
"use client";
import { memo } from "react";
import useSvgTextLogo from "./useSvgTextLogo";
import { cls } from "@/lib/utils";
import React from 'react';
interface SvgTextLogoProps {
logoText: string;
adjustHeightFactor?: number;
verticalAlign?: "top" | "center";
text: string;
className?: string;
fontSize?: number;
fontWeight?: number | string;
letterSpacing?: number;
fill?: string;
strokeWidth?: number;
stroke?: string;
}
const SvgTextLogo = memo<SvgTextLogoProps>(function SvgTextLogo({
logoText,
adjustHeightFactor,
verticalAlign = "top",
className = "",
}) {
const { svgRef, textRef, viewBox, aspectRatio } = useSvgTextLogo(logoText, false, adjustHeightFactor);
const SvgTextLogo: React.FC<SvgTextLogoProps> = ({
text,
className = '',
fontSize = 48,
fontWeight = 700,
letterSpacing = 0,
fill = 'currentColor',
strokeWidth = 0,
stroke = 'none',
}) => {
const canvas = React.useRef<HTMLCanvasElement>(null);
const [dimensions, setDimensions] = React.useState({ width: 400, height: 100 });
React.useEffect(() => {
if (!canvas.current) return;
const ctx = canvas.current.getContext('2d');
if (!ctx) return;
ctx.font = `${fontWeight} ${fontSize}px system-ui, -apple-system, sans-serif`;
ctx.letterSpacing = `${letterSpacing}px`;
const metrics = ctx.measureText(text);
const width = Math.ceil(metrics.width) + 40;
const height = Math.ceil(fontSize) + 40;
setDimensions({ width, height });
}, [text, fontSize, fontWeight, letterSpacing]);
const textAnchor = 'start';
const dominantBaseline = 'middle';
const x = 20;
const y = dimensions.height / 2;
return (
<svg
ref={svgRef}
viewBox={viewBox}
className={cls("w-full", className)}
style={{ aspectRatio: aspectRatio }}
preserveAspectRatio="none"
role="img"
aria-label={`${logoText} logo`}
width={dimensions.width}
height={dimensions.height}
viewBox={`0 0 ${dimensions.width} ${dimensions.height}`}
className={className}
ref={canvas as any}
>
<text
ref={textRef}
x="0"
y={verticalAlign === "center" ? "50%" : "0"}
className="font-bold fill-current"
x={x}
y={y}
fontSize={fontSize}
fontWeight={fontWeight}
textAnchor={textAnchor}
dominantBaseline={dominantBaseline}
fill={fill}
stroke={stroke}
strokeWidth={strokeWidth}
style={{
fontSize: "20px",
letterSpacing: "-0.02em",
dominantBaseline: verticalAlign === "center" ? "middle" : "text-before-edge"
letterSpacing: `${letterSpacing}px`,
fontFamily: 'system-ui, -apple-system, sans-serif',
}}
>
{logoText}
{text}
</text>
</svg>
);
});
SvgTextLogo.displayName = "SvgTextLogo";
};
export default SvgTextLogo;