Refactor global styles and layout components for improved responsiveness and performance. Added viewport settings, adjusted overflow handling, and removed legacy animations for mobile optimization. Enhanced image handling and ensured consistent minimum width across various components.

This commit is contained in:
smhk1376 committed 2026-09-24 16:38:35 +03:30
1 parent fdb2023353
commit b6ff82fad9
22 files changed
+207 -265

No files matched your search

+41 -18
View File
@@ -3,37 +3,60 @@
import { useEffect, useRef, useState } from "react";
const PERSIAN_DIGITS = "۰۱۲۳۴۵۶۷۸۹";
const toLatin = (value: string) => value.replace(/[۰-۹]/g, (digit) => String(PERSIAN_DIGITS.indexOf(digit)));
const toLatin = (value: string) =>
value.replace(/[۰-۹]/g, (digit) => String(PERSIAN_DIGITS.indexOf(digit)));
export function AnimatedMetric({ value, className }: { value: string; className?: string }) {
function shouldAnimate() {
if (typeof window === "undefined") return false;
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return false;
// Skip count-up on phones — saves main-thread work while scrolling
if (window.matchMedia("(max-width: 767px)").matches) return false;
return true;
}
export function AnimatedMetric({
value,
className,
}: {
value: string;
className?: string;
}) {
const ref = useRef<HTMLSpanElement>(null);
const [display, setDisplay] = useState(value);
useEffect(() => {
const element = ref.current;
if (!element || window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
if (!element || !shouldAnimate()) return;
const latin = toLatin(value).replaceAll("٬", "");
const match = latin.match(/^(\D*)(\d+)(\D*)$/);
if (!match) return;
const [, prefix, rawNumber, suffix] = match;
const target = Number(rawNumber);
const observer = new IntersectionObserver(([entry]) => {
if (!entry.isIntersecting) return;
observer.disconnect();
const startedAt = performance.now();
const duration = 1000;
const tick = (now: number) => {
const progress = Math.min((now - startedAt) / duration, 1);
const eased = 1 - Math.pow(1 - progress, 3);
const current = Math.round(target * eased).toLocaleString("fa-IR");
setDisplay(`${prefix}${current}${suffix}`);
if (progress < 1) requestAnimationFrame(tick);
};
requestAnimationFrame(tick);
}, { threshold: 0.55 });
const observer = new IntersectionObserver(
([entry]) => {
if (!entry.isIntersecting) return;
observer.disconnect();
const startedAt = performance.now();
const duration = 900;
const tick = (now: number) => {
const progress = Math.min((now - startedAt) / duration, 1);
const eased = 1 - Math.pow(1 - progress, 3);
const current = Math.round(target * eased).toLocaleString("fa-IR");
setDisplay(`${prefix}${current}${suffix}`);
if (progress < 1) requestAnimationFrame(tick);
};
requestAnimationFrame(tick);
},
{ threshold: 0.55 },
);
observer.observe(element);
return () => observer.disconnect();
}, [value]);
return <span ref={ref} className={className}>{display}</span>;
return (
<span ref={ref} className={className}>
{display}
</span>
);
}
+8 -5
View File
@@ -13,7 +13,7 @@ type BrandLogoProps = {
compact?: boolean;
};
/** AUT seal — white mark on transparent; sits on brand disc. */
/** AUT seal — raw mark only (transparent), no disc/ring/background. */
export function BrandLogo({
href = "/",
title,
@@ -33,8 +33,7 @@ export function BrandLogo({
>
<span
className={cn(
"relative shrink-0 overflow-hidden rounded-full bg-chart-3 shadow-sm ring-1",
onDark ? "ring-background/25" : "ring-border",
"relative shrink-0",
compact ? "size-9" : "size-11 sm:size-12",
)}
>
@@ -44,7 +43,11 @@ export function BrandLogo({
fill
priority
sizes="48px"
className="object-contain p-[18%]"
className={cn(
"object-contain",
// Asset is white-on-transparent; invert to dark ink on light surfaces
!onDark && "brightness-0",
)}
/>
</span>
<span className="min-w-0 text-start leading-tight">
@@ -60,7 +63,7 @@ export function BrandLogo({
{subtitle ? (
<span
className={cn(
"mt-0.5 block truncate text-[0.7rem] font-medium sm:text-xs",
"mt-0.5 hidden truncate text-[0.7rem] font-medium min-[380px]:block sm:text-xs",
onDark ? "text-background/70" : "text-muted-foreground",
)}
>
+1 -1
View File
@@ -12,7 +12,7 @@ export function Container({
return (
<div
className={cn(
"mx-auto w-full px-5 sm:px-8 lg:px-12",
"mx-auto w-full min-w-0 px-5 sm:px-8 lg:px-12",
narrow ? "max-w-3xl" : "max-w-7xl",
className,
)}
+31 -97
View File
@@ -1,3 +1,6 @@
"use client";
import { useEffect, useState } from "react";
import { cn } from "@/lib/utils";
type MetamorphFieldProps = {
@@ -69,17 +72,30 @@ const EDGES_SPARSE: Edge[] = [
const VIEW_W = 1200;
const VIEW_H = 480;
const ENABLE_MQ =
"(min-width: 768px) and (prefers-reduced-motion: no-preference)";
/**
* Decorative metamorphism field — dots joined by thin lines.
* Place inside a `relative overflow-hidden` flex/grid surface.
* The outer wrapper fills the parent; the SVG covers with landscape slice
* so density stays proportional across wide hero/footer bands.
* Decorative constellation. Mounted only on desktop with motion allowed —
* SMIL/CSS motion was too expensive on phones.
*/
export function MetamorphField({
className,
tone = "dark",
density = "normal",
}: MetamorphFieldProps) {
const [enabled, setEnabled] = useState(false);
useEffect(() => {
const mq = window.matchMedia(ENABLE_MQ);
const sync = () => setEnabled(mq.matches);
sync();
mq.addEventListener("change", sync);
return () => mq.removeEventListener("change", sync);
}, []);
if (!enabled) return null;
const nodes = density === "sparse" ? NODES_SPARSE : NODES_NORMAL;
const edges = density === "sparse" ? EDGES_SPARSE : EDGES_NORMAL;
const stroke =
@@ -88,11 +104,6 @@ export function MetamorphField({
tone === "dark" ? "color-mix(in oklab, white 70%, transparent)" : "var(--primary)";
const accent = tone === "dark" ? "var(--accent)" : "var(--primary)";
const targets = nodes.map((node, index) => ({
x: Math.max(24, Math.min(VIEW_W - 24, node.x + Math.sin(index * 1.7) * 28)),
y: Math.max(24, Math.min(VIEW_H - 24, node.y + Math.cos(index * 1.3) * 22)),
}));
return (
<div
className={cn(
@@ -109,7 +120,7 @@ export function MetamorphField({
preserveAspectRatio="xMidYMid slice"
focusable="false"
>
<g className="metamorph-field__mesh" stroke={stroke} strokeWidth="0.9">
<g stroke={stroke} strokeWidth="0.9">
{edges.map(([a, b], i) => {
const n1 = nodes[a];
const n2 = nodes[b];
@@ -121,98 +132,21 @@ export function MetamorphField({
y1={n1.y}
x2={n2.x}
y2={n2.y}
className="metamorph-field__line"
style={{ animationDelay: `${(i % 8) * 0.35}s` }}
>
<animate
attributeName="x1"
values={`${n1.x};${targets[a].x};${n1.x}`}
dur={`${14 + (i % 4)}s`}
repeatCount="indefinite"
/>
<animate
attributeName="y1"
values={`${n1.y};${targets[a].y};${n1.y}`}
dur={`${14 + (i % 4)}s`}
repeatCount="indefinite"
/>
<animate
attributeName="x2"
values={`${n2.x};${targets[b].x};${n2.x}`}
dur={`${14 + (i % 4)}s`}
repeatCount="indefinite"
/>
<animate
attributeName="y2"
values={`${n2.y};${targets[b].y};${n2.y}`}
dur={`${14 + (i % 4)}s`}
repeatCount="indefinite"
/>
</line>
opacity="0.55"
/>
);
})}
</g>
<g>
{nodes.map((n, i) => (
<g key={`n-${i}`}>
{i % 5 === 0 ? (
<circle
cx={n.x}
cy={n.y}
r="8"
fill="none"
stroke={accent}
strokeWidth="0.7"
opacity="0.45"
>
<animate
attributeName="cx"
values={`${n.x};${targets[i].x};${n.x}`}
dur={`${14 + (i % 4)}s`}
repeatCount="indefinite"
/>
<animate
attributeName="cy"
values={`${n.y};${targets[i].y};${n.y}`}
dur={`${14 + (i % 4)}s`}
repeatCount="indefinite"
/>
<animate
attributeName="r"
values="5;11;5"
dur={`${8 + (i % 3)}s`}
repeatCount="indefinite"
/>
<animate
attributeName="opacity"
values="0.45;0;0.45"
dur={`${8 + (i % 3)}s`}
repeatCount="indefinite"
/>
</circle>
) : null}
<circle
cx={n.x}
cy={n.y}
r={n.r ?? 2}
fill={i % 5 === 0 ? accent : fill}
className="metamorph-field__dot"
style={{ animationDelay: `${(i % 6) * 0.4}s` }}
>
<animate
attributeName="cx"
values={`${n.x};${targets[i].x};${n.x}`}
dur={`${14 + (i % 4)}s`}
repeatCount="indefinite"
/>
<animate
attributeName="cy"
values={`${n.y};${targets[i].y};${n.y}`}
dur={`${14 + (i % 4)}s`}
repeatCount="indefinite"
/>
</circle>
</g>
<circle
key={`n-${i}`}
cx={n.x}
cy={n.y}
r={n.r ?? 2}
fill={i % 5 === 0 ? accent : fill}
opacity={i % 5 === 0 ? 0.85 : 0.7}
/>
))}
</g>
</svg>
+1 -1
View File
@@ -22,7 +22,7 @@ export function Section({
<section
data-tone={tone}
className={cn(
"motion-section relative",
"motion-section relative min-w-0",
tight ? "py-8 sm:py-10" : "py-16 sm:py-24",
tones[tone],
className,