feat(piksel): Piksel sitede konuşuyor — logodan balon, danışmanın yüzü, sayfa içi Piksel (→ 2.5.0)
S-013 Faz 1 (Bilal, 21 Eki 2026: "karakterimiz sitede yaşayan bir arkadaş gibi balonla samimi tanıtım yapsın, tam performanslı çalışsın; WebGL gerekir mi"). - Konuşma balonu: Piksel logodan açılır, balon ondan sonra logonun altında belirir. Cümleler tek kaynakta (lib/piksel-replikleri.ts): ilk geliş karşılaması, geri dönüş (listende N program var), ilk program ve dolu liste. Bileşenler pikselSoyle() ile söz ister; false dönerse kendi bildirimini gösterir (program-ekle-butonu). - Görgü kuralları (piksel-yonetmeni.tsx): kendiliğinden en çok 2 balon/oturum; yazarken, pencere açıkken, ödeme/giriş sayfalarında susar; Esc, çarpı, kaydırma, dışarı basma kapatır; role="status" duyurusu. "Piksel: Sussun" anahtarı footer'da ve telefon menüsünde. - Danışmanın yüzü Piksel (danisman-yuzu.tsx): yazarken turuncu logo Piksel'e döner, araç çalışırken kareler küçülüp hızla döner (AnimasyonluMark "donen"), bitince Piksel'e, cevap sonunda logoya. Liste hazırlanırken ve yeniden kurulurken de dönen kareler. Mesaj avatarları durgun Piksel yüzü. - Sayfa içi Piksel (PikselYuvasi): boş liste, sonuçsuz arama, 404, hata, danışman boş hâli. 404/hata düğmeleri kanonik CTA'ya geçti. - LogoPiksel'e dışarıdan kumanda (tut/birak/durum/bak/donen, açılınca geri çağrı), ölçü değişiminden bağımsız efekt; PikselBot'a durgun modu ve ekran dışında durma; aynı anda tek canlı Piksel (useCanliPiksel). - WebGL yok: motor kare başına 21–41 µs (SVG). Yönetmen boşta, ayrı parça. - Tasarım denetimi: piksel-replik-disi, piksel-replik-vaat. Rybbit olayları piksel_konustu/kapatildi/eylem/susturuldu. - Belgeler: DESIGN §4.43 ve §10.7, AGENTS.md kuralı, S-013 spec, araştırma raporu (docs/arastirma/2026-10-21-piksel-arkadas.md), INDEX ve Bilal'in masası. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -35,13 +35,23 @@
|
||||
// sonra logoya döner. Klavyede odak açar, odak gidince kapanır. Hareketi
|
||||
// azalt'ta yolculuk yok: logo ile Piksel kısa bir opaklık geçişiyle yer değişir,
|
||||
// gözler izlemez. Kareler HTML span; yalnız transform/opacity/renk oynar.
|
||||
//
|
||||
// Dışarıdan kumanda (S-013, 21 Eki 2026): `kontrolRef` ya da `sahne`
|
||||
// (header'daki tek örnek, lib/piksel-sahne.ts) ile Piksel açılıp tutulur,
|
||||
// yüzü ve bakışı değiştirilir — konuşma balonu ve danışman bunu kullanır.
|
||||
// `donen`: Piksel toplanır, logonun kareleri küçülüp döner (araştırıyor);
|
||||
// kapanınca kareler yerine oturur ve tutuluyorsa Piksel yeniden açılır.
|
||||
// Tutulan Piksel'i yaklaşma/dokunma kapatmaz; tema ve eylem biçimleri yine
|
||||
// baskındır (önce toplanır, biçim oynar, sonra yeniden açılır).
|
||||
|
||||
import { useEffect, useRef, useState, type CSSProperties } from "react";
|
||||
import { useEffect, useId, useRef, useState, type CSSProperties, type RefObject } from "react";
|
||||
import { useReducedMotion } from "motion/react";
|
||||
import { AnimasyonluMark, TEPKI_BICIMI, type Bicim, type MarkKontrol } from "@/components/animasyonlu-mark";
|
||||
import { AnimasyonluMark, TEPKI_BICIMI, type Bicim, type MarkKontrol, type Varyant } from "@/components/animasyonlu-mark";
|
||||
import { aimFace } from "@/components/eye-tracker";
|
||||
import { PikselBot, type BakisHedefi } from "@/components/piksel-bot";
|
||||
import { EGRI } from "@/lib/hareket";
|
||||
import type { DurumId } from "@/lib/piksel-blob";
|
||||
import { sahneKaydet, useCanliPiksel, type BakisNoktasi, type LogoPikselKontrol } from "@/lib/piksel-sahne";
|
||||
import { LOGO_TEPKI_OLAYI, type LogoTepkisi } from "@/lib/logo-tepkisi";
|
||||
import { TEMA_GECIS_OLAYI, temaHazirligi } from "@/lib/tema-gecisi";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -79,6 +89,11 @@ export function LogoPiksel({
|
||||
uzak: uzakVerilen,
|
||||
className,
|
||||
style,
|
||||
renk = "marka",
|
||||
yaklasinca = true,
|
||||
kontrolRef,
|
||||
sahne = false,
|
||||
bosDongu,
|
||||
}: {
|
||||
/**
|
||||
* Kutu kenarı, px. Verilmezse boyu `className` belirler (header'da
|
||||
@@ -91,6 +106,16 @@ export function LogoPiksel({
|
||||
uzak?: number;
|
||||
className?: string;
|
||||
style?: CSSProperties;
|
||||
/** "turuncu": üç kare de CTA turuncusu (danışman başlığı). */
|
||||
renk?: "marka" | "turuncu";
|
||||
/** `false`: imleç, dokunma ve klavye odağı açmaz; yalnız kumanda açar. */
|
||||
yaklasinca?: boolean;
|
||||
/** Dışarıdan kumanda (bkz. `LogoPikselKontrol`). */
|
||||
kontrolRef?: RefObject<LogoPikselKontrol | null>;
|
||||
/** Header'daki tek örnek: kumandası lib/piksel-sahne.ts'e kaydolur. */
|
||||
sahne?: boolean;
|
||||
/** Logo hâlindeyken dönen döngü (danışman başlığında "nabiz"); yoksa durgun. */
|
||||
bosDongu?: Varyant;
|
||||
}) {
|
||||
const azalt = useReducedMotion() ?? false;
|
||||
const kutu = useRef<HTMLSpanElement>(null);
|
||||
@@ -108,11 +133,17 @@ export function LogoPiksel({
|
||||
if (boy !== undefined || !el) return;
|
||||
const gozlem = new ResizeObserver(([g]) => {
|
||||
const w = g?.contentRect.width;
|
||||
if (w) setOlcu(w);
|
||||
if (w) setOlcu(Math.round(w));
|
||||
});
|
||||
gozlem.observe(el);
|
||||
return () => gozlem.disconnect();
|
||||
}, [boy]);
|
||||
// Ölçüler ref'te: değişince aşağıdaki büyük efekt yeniden kurulmasın —
|
||||
// kurulursa yarıdaki açılış animasyonu iptal olur, Piksel takılı kalır.
|
||||
const olculer = useRef({ kenar, yakin, uzak });
|
||||
useEffect(() => {
|
||||
olculer.current = { kenar, yakin, uzak };
|
||||
}, [kenar, yakin, uzak]);
|
||||
const kareRef = useRef<(HTMLSpanElement | null)[]>([]);
|
||||
const kendiKap = useRef<HTMLSpanElement>(null);
|
||||
const markKap = useRef<HTMLSpanElement>(null);
|
||||
@@ -122,12 +153,23 @@ export function LogoPiksel({
|
||||
const evre = useRef<Evre>("logo");
|
||||
const hedef = useRef<BakisHedefi>({ x: 0, y: 0, aktif: false });
|
||||
const toplanmaZamani = useRef(0);
|
||||
const kumandaDurumu = useRef<{
|
||||
tutulan: boolean;
|
||||
donenIstek: boolean;
|
||||
donuyorKareler: boolean;
|
||||
sabitBakis: BakisNoktasi | null;
|
||||
acilinca: (() => void) | null;
|
||||
}>({ tutulan: false, donenIstek: false, donuyorKareler: false, sabitBakis: null, acilinca: null });
|
||||
const dokunmaZamani = useRef(0);
|
||||
|
||||
// Piksel yalnız gerektiğinde DOM'da (rAF döngüsü boşuna dönmesin):
|
||||
// ilk yaklaşmada takılır, logoya dönüş bitince sökülür.
|
||||
const [botVar, setBotVar] = useState(false);
|
||||
const [durum, setDurum] = useState<"toplan" | "bosta">("toplan");
|
||||
// Aynı anda tek canlı Piksel (lib/piksel-sahne.ts): açıkken canlı olmak ister
|
||||
const canliHakki = useCanliPiksel(useId(), botVar);
|
||||
const [durum, setDurum] = useState<DurumId>("toplan");
|
||||
/** Açıkken istenen yüz (kumanda); açılış bitince bu durum oynar. */
|
||||
const istenenDurum = useRef<DurumId>("bosta");
|
||||
|
||||
const botGoster = (gorunur: boolean) => {
|
||||
const b = botKap.current;
|
||||
@@ -166,13 +208,24 @@ export function LogoPiksel({
|
||||
let temaKilidi = false;
|
||||
let kilitZamani = 0;
|
||||
let hazirlikBitti: (() => void) | null = null;
|
||||
// Kumanda durumu ref'lerde (efekt ölçü değişince yeniden kurulur, durum
|
||||
// kaybolmasın): tutulan Piksel'i yaklaşma kapatmaz; `donenIstek` logoya
|
||||
// dönünce karelerin dönmesini ister; `sabitBakis` imlecin yerine bakılan hedef.
|
||||
const k = kumandaDurumu.current;
|
||||
let donenZamani = 0;
|
||||
/** Piksel açıldı: bekleyen `acilinca` bir kez çağrılır. */
|
||||
const acildi = () => {
|
||||
const f = k.acilinca;
|
||||
k.acilinca = null;
|
||||
f?.();
|
||||
};
|
||||
const bicimOynat = (bicim: Bicim) => {
|
||||
const sure = markKontrol.current?.sekilOynat(bicim) ?? 0;
|
||||
mesgulBitis = performance.now() + sure;
|
||||
window.clearTimeout(mesgulZamani);
|
||||
// biçim bitince imleç hâlâ yakındaysa Piksel yeniden açılır
|
||||
mesgulZamani = window.setTimeout(() => {
|
||||
if (yakinda) ac();
|
||||
if (yakinda || k.tutulan) ac();
|
||||
}, sure + 80);
|
||||
};
|
||||
const logoyaDondu = () => {
|
||||
@@ -188,7 +241,19 @@ export function LogoPiksel({
|
||||
const b = bekleyen;
|
||||
bekleyen = null;
|
||||
bicimOynat(b);
|
||||
return;
|
||||
}
|
||||
if (k.donenIstek) karelerDonsun(true);
|
||||
else if (bosDongu) markKontrol.current?.dongu(bosDongu);
|
||||
};
|
||||
const karelerDonsun = (acik: boolean) => {
|
||||
window.clearTimeout(donenZamani);
|
||||
if (acik === k.donuyorKareler) return;
|
||||
k.donuyorKareler = acik;
|
||||
const sonraki = acik ? "donen" : !k.tutulan && bosDongu ? bosDongu : null;
|
||||
const yerlesme = markKontrol.current?.dongu(sonraki) ?? 0;
|
||||
// Kareler yerine oturunca Piksel tutuluyorsa yeniden açılır
|
||||
if (!acik) donenZamani = window.setTimeout(() => (yakinda || k.tutulan) && ac(), yerlesme);
|
||||
};
|
||||
const bicimIste = (bicim: Bicim) => {
|
||||
if (evre.current === "logo") {
|
||||
@@ -196,7 +261,7 @@ export function LogoPiksel({
|
||||
return;
|
||||
}
|
||||
bekleyen = bicim;
|
||||
kapat();
|
||||
kapat(true);
|
||||
};
|
||||
|
||||
// İleri yönlü animasyonlar bir kez kurulur, duraklatılmış; açılış onları
|
||||
@@ -216,7 +281,7 @@ export function LogoPiksel({
|
||||
? { translate: `${tx}% ${ty}%`, scale: String(BUYUME), backgroundColor: "var(--color-orange-500)" }
|
||||
: // yan kareler büyüyen turuncunun ortasına süzülüp onun içinde erir
|
||||
{ translate: `${tx}% ${ty}%`, scale: "0.35", opacity: 0 };
|
||||
const a = k.animate([{ translate: "0% 0%", scale: "1", opacity: 1, backgroundColor: kare.renk }, son], {
|
||||
const a = k.animate([{ translate: "0% 0%", scale: "1", opacity: 1, backgroundColor: renk === "turuncu" ? "var(--color-orange-500)" : kare.renk }, son], {
|
||||
duration: i === 2 ? ACILIS - 40 : 360,
|
||||
delay: i === 2 ? 40 : i * 50,
|
||||
easing: egri(i === 2 ? EGRI.gucluCikis : EGRI.giris),
|
||||
@@ -230,14 +295,15 @@ export function LogoPiksel({
|
||||
};
|
||||
|
||||
function ac() {
|
||||
if (temaKilidi) return;
|
||||
if (temaKilidi || k.donenIstek || k.donuyorKareler) return;
|
||||
if (evre.current === "aciliyor" || evre.current === "piksel") return;
|
||||
if (evre.current === "toplaniyor") {
|
||||
// Piksel hâlâ ekranda: yalnız durumu geri çevir, motor o anki pozdan morph'lar
|
||||
window.clearTimeout(toplanmaZamani.current);
|
||||
evre.current = "piksel";
|
||||
hedef.current.aktif = true;
|
||||
setDurum("bosta");
|
||||
setDurum(istenenDurum.current);
|
||||
acildi();
|
||||
return;
|
||||
}
|
||||
if (evre.current === "logo" && performance.now() < mesgulBitis) return;
|
||||
@@ -246,10 +312,15 @@ export function LogoPiksel({
|
||||
evre.current = "piksel";
|
||||
if (markKap.current) markKap.current.style.opacity = "0";
|
||||
botGoster(true);
|
||||
setDurum("bosta");
|
||||
setDurum(istenenDurum.current);
|
||||
acildi();
|
||||
return;
|
||||
}
|
||||
if (evre.current === "logo") perde(true);
|
||||
if (evre.current === "logo") {
|
||||
// logonun kendi döngüsü perdenin arkasında yerine oturur
|
||||
if (bosDongu) markKontrol.current?.dongu(null);
|
||||
perde(true);
|
||||
}
|
||||
evre.current = "aciliyor";
|
||||
const as = kur();
|
||||
for (const a of as) {
|
||||
@@ -270,11 +341,13 @@ export function LogoPiksel({
|
||||
botGoster(true);
|
||||
evre.current = "piksel";
|
||||
hedef.current.aktif = true;
|
||||
setDurum("bosta");
|
||||
setDurum(istenenDurum.current);
|
||||
acildi();
|
||||
};
|
||||
}
|
||||
|
||||
function kapat() {
|
||||
function kapat(zorla = false) {
|
||||
if (k.tutulan && !zorla) return;
|
||||
if (evre.current === "logo" || evre.current === "donuyor" || evre.current === "toplaniyor") return;
|
||||
hedef.current.aktif = false;
|
||||
if (azalt) {
|
||||
@@ -312,18 +385,29 @@ export function LogoPiksel({
|
||||
};
|
||||
const nisanla = (x: number, y: number) => {
|
||||
const r = el.getBoundingClientRect();
|
||||
const n = aimFace(x - (r.left + r.width / 2), y - (r.top + r.height / 2), Math.max(60, kenar * 1.2), 60);
|
||||
const n = aimFace(x - (r.left + r.width / 2), y - (r.top + r.height / 2), Math.max(60, olculer.current.kenar * 1.2), 60);
|
||||
hedef.current.x = n.x;
|
||||
hedef.current.y = n.y;
|
||||
};
|
||||
|
||||
const sabitBakisaNisanla = () => {
|
||||
const h = k.sabitBakis;
|
||||
if (!h) return;
|
||||
if (h instanceof Element) {
|
||||
const r = h.getBoundingClientRect();
|
||||
nisanla(r.left + r.width / 2, r.top + r.height / 2);
|
||||
} else nisanla(h.x, h.y);
|
||||
};
|
||||
const hareket = (e: PointerEvent) => {
|
||||
if (e.pointerType !== "mouse") return;
|
||||
const u = kenaraUzaklik(e.clientX, e.clientY);
|
||||
yakinda = u <= yakin;
|
||||
if (yakinda) ac();
|
||||
else if (u > uzak) kapat();
|
||||
nisanla(e.clientX, e.clientY);
|
||||
if (yaklasinca) {
|
||||
const u = kenaraUzaklik(e.clientX, e.clientY);
|
||||
yakinda = u <= olculer.current.yakin;
|
||||
if (yakinda) ac();
|
||||
else if (u > olculer.current.uzak) kapat();
|
||||
}
|
||||
if (k.sabitBakis) sabitBakisaNisanla();
|
||||
else nisanla(e.clientX, e.clientY);
|
||||
};
|
||||
const sayfadanCikti = () => {
|
||||
yakinda = false;
|
||||
@@ -350,7 +434,7 @@ export function LogoPiksel({
|
||||
return;
|
||||
}
|
||||
hazirlikBitti = coz;
|
||||
kapat();
|
||||
kapat(true);
|
||||
});
|
||||
const hazirlikSil = temaHazirligi(temaOncesi);
|
||||
const tepki = (e: Event) => {
|
||||
@@ -358,7 +442,7 @@ export function LogoPiksel({
|
||||
if (tur in TEPKI_BICIMI) bicimIste(TEPKI_BICIMI[tur]);
|
||||
};
|
||||
const dokun = (e: PointerEvent) => {
|
||||
if (e.pointerType === "mouse") return;
|
||||
if (e.pointerType === "mouse" || !yaklasinca) return;
|
||||
nisanla(e.clientX, e.clientY);
|
||||
ac();
|
||||
window.clearTimeout(dokunmaZamani.current);
|
||||
@@ -368,6 +452,7 @@ export function LogoPiksel({
|
||||
// ona gelir; yalnız klavyeyle gelen odak açar (tıklama odağı değil).
|
||||
const odakKabi = el.closest<HTMLElement>("a, button, [tabindex]") ?? el;
|
||||
const odak = (e: FocusEvent) => {
|
||||
if (!yaklasinca) return;
|
||||
if (!(e.target instanceof Element) || !e.target.matches(":focus-visible")) return;
|
||||
hedef.current.x = 0;
|
||||
hedef.current.y = 0;
|
||||
@@ -375,6 +460,48 @@ export function LogoPiksel({
|
||||
};
|
||||
const odakGitti = () => kapat();
|
||||
|
||||
// Kumanda (S-013)
|
||||
const kumanda: LogoPikselKontrol = {
|
||||
tut: (acilinca) => {
|
||||
k.tutulan = true;
|
||||
k.acilinca = acilinca ?? null;
|
||||
if (evre.current === "piksel") acildi();
|
||||
else ac();
|
||||
},
|
||||
birak: () => {
|
||||
k.tutulan = false;
|
||||
k.acilinca = null;
|
||||
if (!yakinda) kapat();
|
||||
},
|
||||
durum: (d) => {
|
||||
istenenDurum.current = d;
|
||||
if (evre.current === "piksel") setDurum(d);
|
||||
},
|
||||
bak: (h) => {
|
||||
k.sabitBakis = h;
|
||||
if (h) {
|
||||
sabitBakisaNisanla();
|
||||
hedef.current.aktif = evre.current === "piksel";
|
||||
}
|
||||
},
|
||||
donen: (acik) => {
|
||||
if (azalt) return;
|
||||
k.donenIstek = acik;
|
||||
if (!acik) {
|
||||
karelerDonsun(false);
|
||||
return;
|
||||
}
|
||||
if (evre.current === "logo") karelerDonsun(true);
|
||||
else kapat(true);
|
||||
},
|
||||
};
|
||||
if (kontrolRef) kontrolRef.current = kumanda;
|
||||
if (bosDongu && evre.current === "logo" && !k.donuyorKareler) markKontrol.current?.dongu(bosDongu);
|
||||
const kayitSil = sahne ? sahneKaydet({ kontrol: kumanda, kutu: el }) : null;
|
||||
// Sabit bakış hedefi kaydırmada yer değiştirir
|
||||
const kaydirma = () => k.sabitBakis && sabitBakisaNisanla();
|
||||
window.addEventListener("scroll", kaydirma, { passive: true });
|
||||
|
||||
window.addEventListener("pointermove", hareket, { passive: true });
|
||||
window.addEventListener(TEMA_GECIS_OLAYI, temaGecti);
|
||||
window.addEventListener(LOGO_TEPKI_OLAYI, tepki);
|
||||
@@ -383,6 +510,10 @@ export function LogoPiksel({
|
||||
odakKabi.addEventListener("focusin", odak);
|
||||
odakKabi.addEventListener("focusout", odakGitti);
|
||||
return () => {
|
||||
kayitSil?.();
|
||||
if (kontrolRef?.current === kumanda) kontrolRef.current = null;
|
||||
window.removeEventListener("scroll", kaydirma);
|
||||
window.clearTimeout(donenZamani);
|
||||
window.removeEventListener("pointermove", hareket);
|
||||
window.removeEventListener(TEMA_GECIS_OLAYI, temaGecti);
|
||||
window.removeEventListener(LOGO_TEPKI_OLAYI, tepki);
|
||||
@@ -400,7 +531,7 @@ export function LogoPiksel({
|
||||
for (const a of animler.current) a.cancel();
|
||||
animler.current = [];
|
||||
};
|
||||
}, [azalt, kenar, yakin, uzak]);
|
||||
}, [azalt, yaklasinca, kontrolRef, sahne, renk, bosDongu]);
|
||||
|
||||
return (
|
||||
<span
|
||||
@@ -413,7 +544,7 @@ export function LogoPiksel({
|
||||
ref={markKap}
|
||||
className={cn("absolute inset-0", azalt && "transition-opacity duration-200")}
|
||||
>
|
||||
<AnimasyonluMark sadeceHover hoverDongusu={false} disKontrol={markKontrol} className="size-full" />
|
||||
<AnimasyonluMark sadeceHover hoverDongusu={false} disKontrol={markKontrol} renk={renk} className="size-full" />
|
||||
</span>
|
||||
{/* Yolculuk kareleri: yalnız logo ↔ Piksel geçişinde görünür */}
|
||||
<span ref={kendiKap} aria-hidden className="absolute inset-0" style={{ visibility: "hidden" }}>
|
||||
@@ -431,7 +562,7 @@ export function LogoPiksel({
|
||||
width: `${(k.boyut / KUTU) * 100}%`,
|
||||
height: `${(k.boyut / KUTU) * 100}%`,
|
||||
borderRadius: `${(KOSE / k.boyut) * 100}%`,
|
||||
backgroundColor: k.renk,
|
||||
backgroundColor: renk === "turuncu" ? "var(--color-orange-500)" : k.renk,
|
||||
// turuncu öne: yan kareler onun içine süzülüp erir
|
||||
zIndex: i === 2 ? 1 : 0,
|
||||
}}
|
||||
@@ -445,7 +576,7 @@ export function LogoPiksel({
|
||||
className={cn("absolute z-[2]", azalt && "transition-opacity duration-200")}
|
||||
style={{ opacity: 0, inset: `${((1 - GOVDE) / 2) * 100}%` }}
|
||||
>
|
||||
<PikselBot durum={durum} boy={kenar * GOVDE} ilkAn={1} canli bakisHedefi={hedef} />
|
||||
<PikselBot durum={durum} boy={kenar * GOVDE} ilkAn={1} canli durgun={!canliHakki} bakisHedefi={hedef} />
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user