Merge version_1 into main #2

Merged
bender merged 1 commits from version_1 into main 2026-03-13 11:58:25 +00:00

View File

@@ -1,51 +1,81 @@
"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;
fontFamily?: string;
fontWeight?: number | string;
fill?: string;
letterSpacing?: number;
animationDuration?: number;
animationDelay?: number;
}
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,
fontFamily = 'Arial, sans-serif',
fontWeight = 700,
fill = 'currentColor',
letterSpacing = 0,
animationDuration = 1,
animationDelay = 0,
}) => {
const textLength = text.length;
const charWidth = fontSize * 0.6;
const totalWidth = textLength * charWidth + (textLength - 1) * letterSpacing;
const viewBoxWidth = totalWidth + fontSize;
const viewBoxHeight = fontSize * 1.5;
const xStart = fontSize / 2;
const yStart = fontSize;
return (
<svg
ref={svgRef}
viewBox={viewBox}
className={cls("w-full", className)}
style={{ aspectRatio: aspectRatio }}
preserveAspectRatio="none"
role="img"
aria-label={`${logoText} logo`}
viewBox={`0 0 ${viewBoxWidth} ${viewBoxHeight}`}
className={className}
style={{
display: 'inline-block',
verticalAlign: 'middle',
}}
>
<text
ref={textRef}
x="0"
y={verticalAlign === "center" ? "50%" : "0"}
className="font-bold fill-current"
style={{
fontSize: "20px",
letterSpacing: "-0.02em",
dominantBaseline: verticalAlign === "center" ? "middle" : "text-before-edge"
}}
>
{logoText}
</text>
<defs>
<style>{`
@keyframes svgTextReveal {
from {
clip-path: polygon(0 0, 0 0, 0 100%, 0 100%);
}
to {
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}
}
.svg-text-char {
animation: svgTextReveal ${animationDuration}s ease-out forwards;
}
`}</style>
</defs>
{Array.from(text).map((char, index) => (
<text
key={index}
x={xStart + index * (charWidth + letterSpacing)}
y={yStart}
fontSize={fontSize}
fontFamily={fontFamily}
fontWeight={fontWeight}
fill={fill}
textAnchor="start"
dominantBaseline="hanging"
className="svg-text-char"
style={{
animationDelay: `${animationDelay + index * 0.05}s`,
}}
>
{char}
</text>
))}
</svg>
);
});
SvgTextLogo.displayName = "SvgTextLogo";
};
export default SvgTextLogo;