2.9.4 — Piksel'in konuşma balonu Bencho Eye tracker'ın `.eyt-say` balonuna çevrildi (MIT, §11.3): turuncu tek levha, Piksel'e bakan kare köşe, kuyruk ve çarpı yok; cümle harf harf yazılır, imleç yanıp söner; eylemsiz balon okunup katlanır, eylemli balon karar verilene kadar kalır. Yay `EGRI.sekme` ve `--egri-sekme`; balon yüzün sağ altından açılır. DESIGN §4.43 güncellendi. 2.9.3 — Sıra kayıtlıyken katalog sayfalarındaki mavi bantta ışık dalgası turuncu ok butonunun arkasından yayılır. 2.9.2 — Katalog özet sayıları kutu yerine ince çizgili tek şerit (NoktaliSatir, PaylasimliBaslik, gecis-adi); başlık altı bilgiler tek satır, piksel ayraçlar ve ikon kutuları kalktı, "Listeme ekle" başlığın yanına geçti. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
377 lines
14 KiB
TypeScript
377 lines
14 KiB
TypeScript
"use client";
|
||
|
||
import { useEffect, useRef } from "react";
|
||
import { useReducedMotion } from "motion/react";
|
||
import { cn } from "@/lib/utils";
|
||
|
||
/**
|
||
* Kare matris — CTA yüzeylerinin zemini (DESIGN.md §10.8): yuvarlak köşeli
|
||
* kareler LED gibi dalga dalga yanıp söner. Dalga turuncu CTA düğmesinin arkasından halka
|
||
* hâlinde dışa yayılır; tepedeki kare büyür ve özü parlar, çukurdaki söner.
|
||
* İmleç geçtiği kareleri bastırır ve turuncuya ısıtır (eski piksel dokusunun
|
||
* "imleç yaklaşınca ısınır" dili); dokunmak ya da tıklamak o kareden bir
|
||
* halka gönderir. Yüzey ekrana ilk girişinde kareler düğmeden dışa belirir.
|
||
*
|
||
* Esin: React Bits Pro "Square Matrix" (yalnız fikir — kod alınmadı; Pro
|
||
* katman lisanslı, DESIGN.md §11.3 md. 7). WebGL değil, Canvas 2D (§11.3 md. 2):
|
||
* yeni bağımlılık yok, kare sayısı birkaç yüz.
|
||
*
|
||
* Renk token'dan: kareler kabın `color`ı (`currentColor`; mavi/koyu yüzeyde
|
||
* `text-white`, beyaz yüzeyde `text-slate-400`), ısınma `--color-orange-500`.
|
||
* Tema değişince yeniden okunur.
|
||
*
|
||
* - `ton="koyu"`: kendi ışığını saçan kareler (hafif hale).
|
||
* - `ton="acik"`: parlaklık kadar büyüyen mürekkep kareler, hale yok.
|
||
* - Yazı ve nesnelerin arkasında söndürme yok (Bilal, 17 Eki 2026): doku bütün
|
||
* yüzeyde eşit; okunurluğu genel silikliği (`SILIKLIK`) sağlar.
|
||
* - Hareketi azalt: tek, durağan kare; etkileşim yok. Yüzey görünmüyorsa çizim
|
||
* durur.
|
||
*/
|
||
|
||
type RGB = [number, number, number];
|
||
|
||
/** Kare adımı (px) — sitedeki piksel hücresinin (10) 1,8 katı */
|
||
const ADIM = 18;
|
||
/** Kare kenarının adıma oranı (boşluk 0,26) */
|
||
const DOLULUK = 0.74;
|
||
const YUVARLAK = 0.35;
|
||
/** Dokunun genel görünürlüğü (0..1): yazının ve düğmenin önüne geçmesin diye yarı silik */
|
||
const SILIKLIK = 0.22;
|
||
/** Dalga: rad/sn ve rad/kare (bir halka ≈ 7,9 sn, halka aralığı ≈ 6 kare) */
|
||
const DALGA_HIZ = 0.8;
|
||
const DALGA_SIKLIK = 1;
|
||
/** Tepede/çukurda kare boyu değişimi */
|
||
const GENLIK = 0.18;
|
||
/** Açılış: merkezden kenara gecikme + kare başına süre (sn) */
|
||
const ACILIS_YAYILMA = 1.1;
|
||
const ACILIS_SURE = 0.7;
|
||
/** Bastırma: imlecin etki yarıçapı (kare) ve geri yaylanma süresi (sn) */
|
||
const BASMA_YARICAP = 1.6;
|
||
const BASMA_SONUM = 0.45;
|
||
/** Tık halkası: hız (kare/sn), kalınlık (kare), ömür (sn) */
|
||
const HALKA_HIZ = 12;
|
||
const HALKA_KALINLIK = 1.25;
|
||
const HALKA_OMUR = 2.6;
|
||
|
||
const ss = (a: number, b: number, x: number) => {
|
||
const t = Math.min(1, Math.max(0, (x - a) / (b - a)));
|
||
return t * t * (3 - 2 * t);
|
||
};
|
||
|
||
/** Kare başına sabit sözde-rastgele (açılış gecikmesini kırar) */
|
||
const karma = (x: number, y: number) => {
|
||
const s = Math.sin(x * 127.1 + y * 311.7) * 43758.5453;
|
||
return s - Math.floor(s);
|
||
};
|
||
|
||
/** Herhangi bir CSS rengini (oklch dahil) sRGB'ye çevirir: 1×1 tuvale boyayıp okur. */
|
||
function rgbOku(renk: string, yedek: RGB): RGB {
|
||
try {
|
||
const c = document.createElement("canvas");
|
||
c.width = c.height = 1;
|
||
const ctx = c.getContext("2d", { willReadFrequently: true });
|
||
if (!ctx) return yedek;
|
||
ctx.fillStyle = `rgb(${yedek.join(",")})`;
|
||
ctx.fillStyle = renk;
|
||
ctx.fillRect(0, 0, 1, 1);
|
||
const d = ctx.getImageData(0, 0, 1, 1).data;
|
||
return [d[0], d[1], d[2]];
|
||
} catch {
|
||
return yedek;
|
||
}
|
||
}
|
||
|
||
type Halka = { x: number; y: number; t: number };
|
||
|
||
export function KareMatris({
|
||
ton = "koyu",
|
||
className,
|
||
}: {
|
||
ton?: "koyu" | "acik";
|
||
className?: string;
|
||
}) {
|
||
const kapRef = useRef<HTMLDivElement>(null);
|
||
const tuvalRef = useRef<HTMLCanvasElement>(null);
|
||
const haleRef = useRef<HTMLCanvasElement>(null);
|
||
const azalt = useReducedMotion();
|
||
|
||
useEffect(() => {
|
||
const kap = kapRef.current;
|
||
const tuval = tuvalRef.current;
|
||
const hale = haleRef.current;
|
||
if (!kap || !tuval) return;
|
||
const ctx = tuval.getContext("2d");
|
||
const hctx = hale?.getContext("2d") ?? null;
|
||
if (!ctx) return;
|
||
// Olaylar CTA kabından dinlenir: zemin pointer-events-none, içeriğin altında
|
||
let yuzey: HTMLElement = kap;
|
||
while (yuzey.parentElement && getComputedStyle(yuzey).pointerEvents === "none") yuzey = yuzey.parentElement;
|
||
const koyu = ton === "koyu";
|
||
|
||
let w = 0;
|
||
let h = 0;
|
||
let sutun = 0;
|
||
let satir = 0;
|
||
let ox = 0;
|
||
let oy = 0;
|
||
let basma = new Float32Array(0);
|
||
/** Dalganın merkezi (kare biriminde): turuncu CTA düğmesinin arkası, yoksa yüzeyin ortası */
|
||
let merkezI = 0;
|
||
let merkezJ = 0;
|
||
let erim = 1;
|
||
let renk: RGB = koyu ? [255, 255, 255] : [148, 163, 184];
|
||
let turuncu: RGB = [255, 105, 0];
|
||
const halkalar: Halka[] = [];
|
||
let imlec: { x: number; y: number } | null = null;
|
||
let acilisBas: number | null = azalt ? -1e9 : null;
|
||
let gorunur = false;
|
||
let rafId = 0;
|
||
let onceki = 0;
|
||
|
||
const renkleriOku = () => {
|
||
renk = rgbOku(getComputedStyle(kap).color, renk);
|
||
turuncu = rgbOku(
|
||
getComputedStyle(document.documentElement).getPropertyValue("--color-orange-500").trim() || "#ff6900",
|
||
turuncu,
|
||
);
|
||
};
|
||
|
||
/**
|
||
* Dalga turuncu CTA düğmesinin arkasından doğar: ışık çağrıyı gösterir.
|
||
* Düğmenin turuncusu linkin içindeki bir öğedeyse o öğe `data-matris-merkez`
|
||
* taşır (ör. kompakt sıra bandındaki yuvarlak ok).
|
||
*/
|
||
const merkezHesapla = () => {
|
||
const kr = kap.getBoundingClientRect();
|
||
// Görünmez (visibility:hidden) öğe de yer kaplar; kompakt bantta gizli
|
||
// duran sıra formunun düğmesi seçilmesin diye görünürlük de sorulur.
|
||
const gorunurMu = (el: HTMLElement) =>
|
||
!kap.contains(el) &&
|
||
el.getBoundingClientRect().width > 0 &&
|
||
(el.checkVisibility?.({ visibilityProperty: true }) ?? true);
|
||
const cta =
|
||
[...yuzey.querySelectorAll<HTMLElement>("[data-matris-merkez]")].find(gorunurMu) ??
|
||
[...yuzey.querySelectorAll<HTMLElement>('[data-variant="cta"], a.bg-orange-500, button.bg-orange-500')].find(
|
||
gorunurMu,
|
||
);
|
||
const cr = cta?.getBoundingClientRect();
|
||
merkezI = cr ? (cr.left - kr.left + cr.width / 2 - ox) / ADIM : sutun / 2;
|
||
merkezJ = cr ? (cr.top - kr.top + cr.height / 2 - oy) / ADIM : satir / 2;
|
||
erim = Math.max(
|
||
...[[0, 0], [sutun, 0], [0, satir], [sutun, satir]].map(([x, y]) => Math.hypot(x - merkezI, y - merkezJ)),
|
||
);
|
||
};
|
||
|
||
const olc = () => {
|
||
const r = kap.getBoundingClientRect();
|
||
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
||
w = Math.round(r.width);
|
||
h = Math.round(r.height);
|
||
tuval.width = Math.max(1, Math.round(w * dpr));
|
||
tuval.height = Math.max(1, Math.round(h * dpr));
|
||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||
if (hale && hctx) {
|
||
// Hale çeyrek çözünürlükte çizilir; CSS büyütmesi + blur yumuşatır
|
||
hale.width = Math.max(1, Math.ceil(w / 4));
|
||
hale.height = Math.max(1, Math.ceil(h / 4));
|
||
hctx.setTransform(0.25, 0, 0, 0.25, 0, 0);
|
||
}
|
||
sutun = Math.ceil(w / ADIM) + 1;
|
||
satir = Math.ceil(h / ADIM) + 1;
|
||
// Izgara ortaya hizalı: ortadaki kare yüzeyin tam ortasında
|
||
ox = w / 2 - (sutun * ADIM) / 2;
|
||
oy = h / 2 - (satir * ADIM) / 2;
|
||
basma = new Float32Array(sutun * satir);
|
||
merkezHesapla();
|
||
};
|
||
|
||
const ciz = (sn: number, dt: number) => {
|
||
ctx.clearRect(0, 0, w, h);
|
||
if (hctx) hctx.clearRect(0, 0, w, h);
|
||
const zaman = sn * DALGA_HIZ;
|
||
const acilis = acilisBas == null ? -1 : sn - acilisBas;
|
||
const sonum = Math.exp(-dt / BASMA_SONUM);
|
||
for (let k = halkalar.length - 1; k >= 0; k--) {
|
||
if (sn - halkalar[k].t > HALKA_OMUR) halkalar.splice(k, 1);
|
||
}
|
||
const yari0 = (DOLULUK / 2) * ADIM;
|
||
|
||
for (let j = 0; j < satir; j++) {
|
||
for (let i = 0; i < sutun; i++) {
|
||
const n = j * sutun + i;
|
||
const mi = i + 0.5 - merkezI;
|
||
const mj = j + 0.5 - merkezJ;
|
||
const uz = Math.hypot(mi, mj);
|
||
|
||
const isik = 0.5 + 0.5 * Math.sin(uz * DALGA_SIKLIK - zaman);
|
||
const yumus = isik * isik * (3 - 2 * isik);
|
||
let enerji = 2 * yumus ** 1.6;
|
||
let yari = yari0 * (1 - GENLIK * (1 - yumus));
|
||
|
||
// Tık halkaları: önde parlak cephe, arkasında hafif çukur
|
||
let itme = 0;
|
||
for (const hk of halkalar) {
|
||
const yas = sn - hk.t;
|
||
const d = Math.hypot(i + 0.5 - hk.x, j + 0.5 - hk.y);
|
||
const x = (d - yas * HALKA_HIZ) / HALKA_KALINLIK;
|
||
const y = x + 1.9;
|
||
const omur = ss(0, 0.05, yas) * Math.exp(-yas / 1.6) * (1 - ss(1.9, HALKA_OMUR, yas));
|
||
itme += ((Math.exp(-x * x) - 0.55 * Math.exp(-y * y)) * omur) / (1 + d / satir);
|
||
}
|
||
|
||
// İmleç bastırması: geçtiği kareler çöker, parlar, yaylanarak döner
|
||
let b = basma[n] * sonum;
|
||
if (imlec) {
|
||
const d = Math.hypot(i + 0.5 - imlec.x, j + 0.5 - imlec.y);
|
||
if (d < BASMA_YARICAP) b = Math.max(b, 1 - d / BASMA_YARICAP);
|
||
}
|
||
basma[n] = b;
|
||
|
||
const isi = Math.min(1, b + Math.max(0, itme) * 0.8);
|
||
enerji += Math.min(1.5, Math.max(0, itme)) * 1.6 + b * 1.7;
|
||
yari *= (1 + 0.2 * Math.max(-1, Math.min(1, itme))) * (1 - 0.18 * Math.min(b, 1));
|
||
|
||
if (acilis < 1e8) {
|
||
const gecikme = ACILIS_YAYILMA * Math.min(1, uz / erim) + 0.12 * karma(i, j);
|
||
const kk = acilis < 0 ? 0 : Math.min(1, Math.max(0, (acilis - gecikme) / ACILIS_SURE));
|
||
const belir = 1 - (1 - kk) ** 3;
|
||
enerji *= belir;
|
||
yari *= belir;
|
||
}
|
||
if (yari < 0.3) continue;
|
||
|
||
const ton01 = 1 - Math.exp(-enerji * 1.05);
|
||
const r = renk[0] + (turuncu[0] - renk[0]) * isi;
|
||
const g = renk[1] + (turuncu[1] - renk[1]) * isi;
|
||
const bl = renk[2] + (turuncu[2] - renk[2]) * isi;
|
||
const px = ox + (i + 0.5) * ADIM;
|
||
const py = oy + (j + 0.5) * ADIM;
|
||
|
||
if (koyu) {
|
||
// Gövde: sönük panel + parlaklık; öz: tepedeki karede beyaza kayan çekirdek
|
||
ctx.fillStyle = `rgba(${r | 0},${g | 0},${bl | 0},${(0.045 + 0.36 * ton01) * SILIKLIK})`;
|
||
ctx.beginPath();
|
||
ctx.roundRect(px - yari, py - yari, 2 * yari, 2 * yari, YUVARLAK * yari);
|
||
ctx.fill();
|
||
const oz = ss(0.35, 0.95, ton01);
|
||
if (oz > 0.01) {
|
||
const a = yari * 0.5;
|
||
ctx.fillStyle = `rgba(255,255,255,${0.55 * oz * SILIKLIK})`;
|
||
ctx.beginPath();
|
||
ctx.roundRect(px - a, py - a, 2 * a, 2 * a, a * 0.6);
|
||
ctx.fill();
|
||
}
|
||
if (hctx && ton01 > 0.2) {
|
||
hctx.fillStyle = `rgba(${r | 0},${g | 0},${bl | 0},${0.4 * (ton01 - 0.2) * SILIKLIK})`;
|
||
hctx.fillRect(px - yari * 1.3, py - yari * 1.3, 2.6 * yari, 2.6 * yari);
|
||
}
|
||
} else {
|
||
const a = yari * (0.3 + 0.7 * Math.sqrt(ton01));
|
||
ctx.fillStyle = `rgba(${r | 0},${g | 0},${bl | 0},${(0.1 + 0.5 * ton01) * SILIKLIK})`;
|
||
ctx.beginPath();
|
||
ctx.roundRect(px - a, py - a, 2 * a, 2 * a, YUVARLAK * a);
|
||
ctx.fill();
|
||
}
|
||
}
|
||
}
|
||
};
|
||
|
||
const kare = (simdi: number) => {
|
||
rafId = 0;
|
||
const sn = simdi / 1000;
|
||
const dt = onceki ? Math.min(0.1, sn - onceki) : 0;
|
||
onceki = sn;
|
||
ciz(sn, dt);
|
||
if (gorunur && !azalt) rafId = requestAnimationFrame(kare);
|
||
};
|
||
const baslat = () => {
|
||
if (!rafId && gorunur && !azalt) rafId = requestAnimationFrame(kare);
|
||
};
|
||
/** Hareketi azalt: dalga ortada, tek durağan kare */
|
||
const durgun = () => ciz(1.2 / DALGA_HIZ, 0);
|
||
|
||
renkleriOku();
|
||
olc();
|
||
if (azalt) durgun();
|
||
|
||
const ro = new ResizeObserver(() => {
|
||
olc();
|
||
if (azalt) durgun();
|
||
});
|
||
ro.observe(kap);
|
||
if (yuzey !== kap) ro.observe(yuzey);
|
||
// Yazı tipi gelince satırlar kayar; düğmenin yeri yeniden ölçülür
|
||
document.fonts?.ready.then(() => {
|
||
merkezHesapla();
|
||
if (azalt) durgun();
|
||
});
|
||
|
||
const io = new IntersectionObserver(
|
||
([g]) => {
|
||
gorunur = g.isIntersecting;
|
||
if (gorunur && acilisBas == null) acilisBas = performance.now() / 1000;
|
||
if (gorunur) baslat();
|
||
else if (rafId) {
|
||
cancelAnimationFrame(rafId);
|
||
rafId = 0;
|
||
onceki = 0;
|
||
}
|
||
},
|
||
{ threshold: 0.15 },
|
||
);
|
||
io.observe(kap);
|
||
|
||
// Tema (açık/koyu) değişince renkler yeniden okunur
|
||
const mo = new MutationObserver(() => {
|
||
renkleriOku();
|
||
if (azalt) durgun();
|
||
});
|
||
mo.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
|
||
|
||
const hucre = (e: PointerEvent) => {
|
||
const r = kap.getBoundingClientRect();
|
||
return { x: (e.clientX - r.left - ox) / ADIM, y: (e.clientY - r.top - oy) / ADIM };
|
||
};
|
||
const hareket = (e: PointerEvent) => {
|
||
if (e.pointerType === "mouse") imlec = hucre(e);
|
||
};
|
||
const ayril = () => {
|
||
imlec = null;
|
||
};
|
||
const bas = (e: PointerEvent) => {
|
||
// Düğme ve bağlantılara basmak halka göndermez (eylem kendi cevabını verir)
|
||
if (e.target instanceof Element && e.target.closest("a, button, input, textarea, select, label")) return;
|
||
const p = hucre(e);
|
||
halkalar.push({ x: p.x, y: p.y, t: performance.now() / 1000 });
|
||
if (halkalar.length > 8) halkalar.shift();
|
||
};
|
||
if (!azalt) {
|
||
yuzey.addEventListener("pointermove", hareket);
|
||
yuzey.addEventListener("pointerleave", ayril);
|
||
yuzey.addEventListener("pointerdown", bas);
|
||
}
|
||
|
||
return () => {
|
||
if (rafId) cancelAnimationFrame(rafId);
|
||
ro.disconnect();
|
||
io.disconnect();
|
||
mo.disconnect();
|
||
yuzey.removeEventListener("pointermove", hareket);
|
||
yuzey.removeEventListener("pointerleave", ayril);
|
||
yuzey.removeEventListener("pointerdown", bas);
|
||
};
|
||
}, [ton, azalt]);
|
||
|
||
return (
|
||
<div ref={kapRef} aria-hidden className={cn("absolute inset-0", className)}>
|
||
{ton === "koyu" ? (
|
||
<canvas
|
||
ref={haleRef}
|
||
className="absolute inset-0 size-full opacity-80 blur-[6px]"
|
||
/>
|
||
) : null}
|
||
<canvas ref={tuvalRef} className="absolute inset-0 size-full" />
|
||
</div>
|
||
);
|
||
}
|