"use client"; // Sıvı cam (DESIGN.md §4.1, §4.22, §4.49, §4.50): cam butonların zemini, tek seçimli // sekmelerde kayan mercek ve "Yeni" rozeti. Kaynak: Bilal'in açık kaynak kiti // "Liquid Glass UI" 2.0.0 (github.com/bilalgursen/liquid-glass@9c65d01, 24 Kas 2026, MIT). // Bilal, 25 Kas 2026: "burdaki liquid glassları güncel liquid glass ile güncelle". // // Motor ve bakış kitin kendisidir, `src/components/liquid-glass/` altında olduğu gibi // durur (`engine.ts`, `dom-snapshot.ts`, `glass-layer.tsx`, `glass-lens.tsx`): tek ortak // WebGL2 bağlamı, kenarda büken ve kenarında çevresini yansıtan cam, basılan yerde // ışıklanma, basılı tutup çekince peşinden gelme, yaklaşan iki butonun kaynaşması. // Burada yalnız sitenin ihtiyacına göre üç sarmalayıcı var: // // - `SiviCam`: kitin `GlassLayer`'ının (glass-layer.tsx) uyarlaması. Kitten farkları: // ok damlası kendiliğinden bulunur (sondaki ya da baştaki ikon; `data-sivi` ve // `--ok-cap` yerleşim kuralına yazılır, globals.css), üstüne gelince ayrılır (kitte // bir prop), `otoDamla` ile ekrana girince ayrılır, baştaki ikonda sola ayrılır; // CTA yüzeyindeki (`[data-cta-yuzey]`) şeffaf cam o yüzeyi canlı çizer ve mavi // boyalıdır (`--glass-tint`, globals.css); footer'daki "Sıvı cam" kapalıyken kurulmaz. // - `KayanCam`: kitin `GlassLens`'i olduğu gibi; yalnız sıvı cam tercihine bağlanır. // - `RozetCami`: kitin `GlassBadge`'inin camı, rozetin kendi kabına (yeni-rozeti.tsx) // ilk çocuk olarak girer; ayıraç kare turuncudur. // // WebGL2 yoksa, bağlam kaybolursa ya da sıvı cam kapalıysa hiçbir şey değişmez: her yüzey // kendi düz hâlindedir (düz turuncu CTA, koyu "Giriş yap" hapı, `layoutId` ile kayan // vurgu, düz mavi rozet). Yaylar kitin `SPRINGS`'idir (§6 "sekmesiz" kuralının Bilal'in // istediği istisnası). import { useEffect, useRef } from "react"; import { drawAround, drawDom } from "@/components/liquid-glass/dom-snapshot"; import { DESIGN_HEIGHT, PULL, SPRINGS, clamp, cohesionSoftness, getGlassEngine, lerp, mixRgb, rgbCss, smooth, stepSpring, surfaceColorOf, type GlassView, type Rgb, type Spring, } from "@/components/liquid-glass/engine"; import { GlassLens } from "@/components/liquid-glass/glass-lens"; import { useCamAcik } from "@/lib/cam-tercihi"; // Kap sınıfları ayrı dosyada (sunucu bileşenleri de alabilsin); istemci dosyaları buradan almaya devam eder. export { SIVI_KAP } from "@/components/sivi-kap"; /** Basınca ve üstüne gelince büyüme (kit `GlassLayer` ile aynı). */ const BASMA_OLCEGI = 1.08; const USTUNDE_OLCEGI = 1.04; const USTUNDE_BUYUME = 0.08; const EN_COK_BUYUME = 6; /** Ayrılan damla ile gövde arasındaki boşluk: yüksekliğin payı. */ const DAMLA_ARALIGI = 0.25; /** CTA yüzeyindeki şeffaf camın boyası (rengi `--glass-tint`, globals.css). */ const CTA_BOYASI = 0.82; /** CTA yüzeyi dışındaki şeffaf camın tonu (kit varsayılanı: açık temada beyaz, koyuda siyah). */ const SEFFAF_TON = 0.6; /** * Bir butonun sıvı cam zemini; butonun (ya da `SIVI_KAP` taşıyan hapın) ilk çocuğudur. * İlk kare çizilince butona `data-glass-ready` yazılır, buton kendi zeminini, * kenarlığını ve gölgesini bırakır (`SIVI_KAP`). Varsayılan cam butonun o anki CSS * rengiyle boyanır (durağan, üstünde, seçili… arası yumuşak geçer); `seffaf` arkasını * büken şeffaf camdır. Üstüne gelince şişer, basınca büyür ve basılan yerde ışıklanır, * basılı tutup çekince peşinden gelir; sondaki (ya da baştaki) ikon üstüne gelince * gövdeden damla olarak ayrılır. */ export function SiviCam({ seffaf = false, otoDamla = false, tetik, hep = false, }: { /** * Şeffaf cam (`Button cam="seffaf"`): arkasındakini kenarında büker, kenarında * çevresini yansıtır. CTA yüzeyinin (`[data-cta-yuzey]`) içinde o yüzeyi (zemin + * canlı piksel tuvalleri) her karede çizer ve mavi boyalıdır; dışında ("Giriş yap") * arkasından geçen sayfayı büker, tonu kitteki gibidir. */ seffaf?: boolean; /** * İkon damlası üstüne gelmeyi beklemez: düğme ekrana girince kendiliğinden ayrılır * ve ayrı durur (dokunmatikte de); basınca gövdeye karışır, bırakınca yine ayrılır. */ otoDamla?: boolean; /** * Üstüne gelme ve basma, kabın kendisi yerine bu seçiciyle bulunan atadan dinlenir * (`closest`): tamamı bağlantı olan kartın içindeki hap, kartın üstüne gelince tepki verir. */ tetik?: string; /** Sıvı cam tercihi kapalıyken de kurulur (üst çubuktaki "Yapay Zekâ Listem"; Bilal, 12 Kas 2026). */ hep?: boolean; }) { const tuvalRef = useRef(null); const acik = useCamAcik(); const kurulu = hep || acik; useEffect(() => { const canvas = tuvalRef.current; const host = canvas?.parentElement; const ctx = canvas?.getContext("2d"); const engine = kurulu ? getGlassEngine() : null; if (!canvas || !host || !ctx || !engine) return; const clear = seffaf; const fareVar = window.matchMedia("(hover: hover) and (pointer: fine)"); let w = 0; let h = 0; /** Ayrılabilecek bir ikon var mı, hangi uçta (1 son, −1 baş). */ let oklu = false; let yon = 1; /** Şeffaf cam bir CTA yüzeyinin içinde mi: o yüzeyi canlı çizer, boyası koyudur. */ let yuzey: HTMLElement | null = null; let corner: number | null = null; let surface: Rgb = [1, 1, 1]; let color: [Rgb, Rgb] = [ [1, 1, 1], [1, 1, 1], ]; let border: [Rgb, Rgb] | null = null; let colorT = 1; let unpaintable = false; let sampled = false; let pressed = false; let hovered = false; let ready = false; const page = { canvas: document.createElement("canvas"), ctx: null as CanvasRenderingContext2D | null, key: "", at: 0, stale: true, fill: "", size: "", lx: 0, ly: 0, sx: 0, sy: 0, pinned: [] as Element[], rigid: false, near: undefined as Element[] | undefined, }; const press: Spring = { x: 0, v: 0 }; const growX: Spring = { x: 0, v: 0 }; const growY: Spring = { x: 0, v: 0 }; const scale: Spring = { x: 1, v: 0 }; const drop: Spring = { x: 0, v: 0 }; /** Damla gövdeye dönerken (0–1): köprü düz tutulur (kit `closing`). */ let closing = 0; let unstretched = ""; let unstretchedAt = ""; const maxScale = () => 1 + (2 * EN_COK_BUYUME) / Math.max(w, 1); const live = () => clear && !!yuzey; const view: GlassView = { canvas, ctx, dirty: true, visible: false, // Bir buton: basışın ışığını alır, çekilir, yanındaki butonla kaynaşır (kit GLOW, PULL, COHESION). button: true, pull: true, grow: 1, step: (dt, still) => { if (still) { // Hareketi azalt: cam durağan, damla ayrılmaz (otoDamla'da baştan ayrıdır). press.x = growX.x = growY.x = press.v = growX.v = growY.v = 0; drop.x = oklu && otoDamla ? 1 : 0; drop.v = 0; closing = drop.x ? 0 : 1; scale.x = 1; view.grow = 1; if (colorT !== 1) view.dirty = true; colorT = 1; return false; } const hov = hovered ? 1 : 0; const down = pressed || view.held === true; const target = down ? Math.min(BASMA_OLCEGI, maxScale()) : hov ? Math.min(USTUNDE_OLCEGI, maxScale()) : 1; const a = stepSpring(press, down ? 1 : 0, SPRINGS.press, dt); const b = stepSpring(growX, hov, SPRINGS.hoverX, dt); const c = stepSpring(growY, hov, SPRINGS.hoverY, dt); const d = stepSpring(scale, target, SPRINGS.press, dt); const apart = oklu && (otoDamla ? view.visible : hovered) && !pressed; const e = oklu ? stepSpring(drop, apart ? 1 : 0, apart ? SPRINGS.dropletOut : SPRINGS.dropletIn, dt) : false; closing = clamp(closing + (apart ? -1 : 1) * dt * 12); view.grow = scale.x; const fading = 1 - colorT > 0.004; colorT = fading ? colorT + (1 - colorT) * Math.min(1, dt * 14) : 1; return a || b || c || d || e || fading || (live() && view.visible); }, lens: (refresh) => { if (refresh) { w = host.offsetWidth; h = host.offsetHeight; const rounding = getComputedStyle(host).borderTopLeftRadius; const px = rounding.endsWith("%") ? (Math.min(w, h) * parseFloat(rounding)) / 100 : parseFloat(rounding) || 0; corner = px >= Math.min(w, h) / 2 - 0.5 ? null : px; // Damla: yazının sonundaki (ya da başındaki) ikon. Tek başına ikon (yuvarlak // düğme) ayrılmaz; damla yalnız fareli cihazda üstüne gelince, `otoDamla`'da // her cihazda ayrılır (globals.css'teki yerleşim kuralı da öyle). const dugumler = [...host.childNodes].filter((n) => { if (n === canvas) return false; if (n instanceof SVGElement) return true; if (n instanceof HTMLElement) return n.offsetWidth > 1 && n.offsetHeight > 1; return !!n.textContent?.trim(); }); const bastaki = dugumler[0]; const sondaki = dugumler[dugumler.length - 1]; const ok = dugumler.length < 2 ? null : sondaki instanceof SVGElement ? sondaki : bastaki instanceof SVGElement ? bastaki : null; yon = ok && ok === bastaki && ok !== sondaki ? -1 : 1; const vardi = oklu; oklu = !!ok && (otoDamla || fareVar.matches); if (oklu !== vardi) engine.wake(); // Damlanın dairesi butonun gerçek yüksekliğidir; ucu yerleşim kuralına bildirilir. const uc = !oklu ? "" : yon < 0 ? "bas" : "son"; if (oklu) host.style.setProperty("--ok-cap", `${h}px`); if ((host.dataset.sivi ?? "") !== uc) { host.dataset.sivi = uc; view.dirty = true; engine.wake(); } const s = engine.resolveColor(surfaceColorOf(host.parentElement)); surface = [s[0], s[1], s[2]]; if (clear) { yuzey = host.closest("[data-cta-yuzey]"); // CTA yüzeyinde boya `--glass-tint`'tir (globals.css); dışında açık temada beyaz, koyuda siyah. const custom = getComputedStyle(host).getPropertyValue("--glass-tint").trim(); const luminance = 0.2126 * surface[0] + 0.7152 * surface[1] + 0.0722 * surface[2]; const t = custom ? engine.resolveColor(custom) : null; const tc: Rgb = t ? [t[0], t[1], t[2]] : luminance > 0.5 ? [1, 1, 1] : [0, 0, 0]; const tone = 0.2126 * tc[0] + 0.7152 * tc[1] + 0.0722 * tc[2] > 0.5 ? "light" : "dark"; if (host.dataset.glassTone !== tone) host.dataset.glassTone = tone; color = [tc, tc]; border = null; colorT = 1; sampled = true; } else { // Butonun kendi zemini ve kenarlığı, cam bir an kaldırılıp okunur. const had = "glassReady" in host.dataset; const transition = host.style.transition; host.style.transition = "none"; if (had) delete host.dataset.glassReady; const st = getComputedStyle(host); const fill = engine.resolveColor(st.backgroundColor); const bw = st.borderTopStyle === "solid" ? parseFloat(st.borderTopWidth) || 0 : 0; const bc = engine.resolveColor(st.borderTopColor); const cannot = st.backgroundImage !== "none" || (st.borderTopStyle !== "solid" && st.borderTopStyle !== "none"); if (had) { host.dataset.glassReady = ""; void getComputedStyle(host).backgroundColor; } host.style.transition = transition; const next = mixRgb(surface, [fill[0], fill[1], fill[2]], fill[3]); const nextBorder: Rgb | null = bw > 0 && bc[3] > 0.02 ? mixRgb(next, [bc[0], bc[1], bc[2]], bc[3]) : null; unpaintable = cannot || (fill[3] < 0.02 && !nextBorder); const now = sampled ? mixRgb(color[0], color[1], colorT) : next; const nowBorder = sampled && border ? mixRgb(border[0], border[1], colorT) : (nextBorder ?? next); const changed = sampled && (now.some((v, i) => Math.abs(v - next[i]) > 0.004) || !!border !== !!nextBorder); color = [now, next]; border = nextBorder ? [nowBorder, nextBorder] : null; colorT = changed ? 0 : 1; sampled = true; if (changed) engine.wake(); } } if (w < 2 || h < 2) return null; if (unpaintable) { if (ready) { ready = false; delete host.dataset.glassReady; } return null; } // Buton kendisi ölçeklenir; tuvaldeki cam o ölçeğe bölünür. const p = clamp(press.x, -0.12, 1.15); const s = Math.max(0.5, scale.x); const k = lerp(1, Math.min(BASMA_OLCEGI, maxScale()), p) / s; const grow = (h * USTUNDE_BUYUME) / s; const t = oklu ? clamp(drop.x, 0, 1.06) : 0; const pull = h * (1 + DAMLA_ARALIGI) * t; const hy = (h / 2) * k + grow * growY.x; const dropX = (w / 2 - h / 2) * k + grow * lerp(growX.x - growY.x, growX.x * 0.5, smooth(0, 0.15, t)); const reach = Math.max((w / 2) * k + grow * growX.x, t > 0.001 ? dropX + hy : 0); // Çekiş butonu CSS ile gerer; tuval bunu geri alır, gerilmeyi cam kendisi çizer. const px = view.pulled?.sx ?? 1; const py = view.pulled?.sy ?? 1; const most = px === 1 && py === 1 ? 0 : Math.max(w, h) <= PULL.smallUntil ? PULL.smallStretchMax : PULL.stretchMax; const melt = Math.ceil(cohesionSoftness(h) / 4) + 3; const padX = Math.max(8, Math.ceil(reach * (1 + most) - w / 2 + 2), melt); const padTop = Math.max(10, Math.ceil(hy * (1 + most) - h / 2 + 2), melt); const padBottom = Math.round(h * 0.8 + 4); const origin = `${padX + w / 2}px ${padTop + h / 2}px`; const undo = px === 1 && py === 1 ? "" : `${(1 / px).toFixed(6)} ${(1 / py).toFixed(6)}`; if (undo !== unstretched || (undo && origin !== unstretchedAt)) { canvas.style.transformOrigin = unstretchedAt = origin; canvas.style.scale = unstretched = undo; } const rect = host.getBoundingClientRect(); const pc = clamp(press.x); const unit = h / DESIGN_HEIGHT; const bevel = lerp(DESIGN_HEIGHT * 0.42, 62, pc); const radius = corner === null ? 999 : corner * (hy / (h / 2)); const bridge = h * 0.34 * py * smooth(0, 0.15, t) * (1 - smooth(0.8, 1, t)); const dip = Math.hypot(hy * py, (pull * k * px) / 2) - hy * py; const kok = yuzey ?? document.body; return { // Tuval dolgu kutusuna göre konumlanır, cam kenarlık kutusuna göre ölçülür. left: -padX - host.clientLeft, top: -padTop - host.clientTop, width: w + 2 * padX, height: h + padTop + padBottom, unit, cx: padX + w / 2, cy: padTop + h / 2, hx: ((w / 2 - pull / 2) * k + grow * growX.x) * px, hy: hy * py, radius, // Gövde damlanın karşı ucuna çekilir; baştaki ikonda damla sola ayrılır. bodyX: yon * (-pull / 2) * k * px, droplet: t > 0.001 ? { x: yon * dropX * px, r: hy * py, k: lerp(bridge, Math.min(bridge, 4 * dip), closing), } : undefined, bevel: corner === null ? bevel : Math.min(bevel, (radius / unit) * 1.2), band: corner === null || oklu ? undefined : bevel * 0.35, shadow: 0.12 * lerp(0.55, 1, pc), shadowSoftness: 34 * lerp(0.6, 1, pc), shadowOffset: 22 * lerp(0.5, 1, pc), strength: 1, color: mixRgb(color[0], color[1], colorT), border: border ? mixRgb(border[0], border[1], colorT) : undefined, borderAlpha: clear ? 1 : undefined, surface, edgeClear: 0.2, cursorLight: true, pointerLight: true, // Şeffaf camın kenarı çevresini yansıtır; boyalı cam yansıtmaz. reflection: !clear ? undefined : { height: h, live: live(), paint: (around, reachPx) => { const r = host.getBoundingClientRect(); const box = { left: r.left + (r.width - w) / 2 - padX, top: r.top + (r.height - h) / 2 - padTop, width: w + 2 * padX, height: h + padTop + padBottom, }; drawAround(around, kok, box, reachPx, { skip: (el) => el === host || el.hasAttribute("data-glass-skip"), onStale: dirty, }); }, }, refraction: clear ? { paint: (back) => { back.translate(padX, padTop); const fill = rgbCss(surface); const recoloured = fill !== page.fill; page.fill = fill; back.fillStyle = fill; back.fillRect(-padX, -padTop, w + 2 * padX, h + padTop + padBottom); const r = host.getBoundingClientRect(); const lx = r.left + (r.width - w) / 2; const ly = r.top + (r.height - h) / 2; const target = back.canvas; const key = `${target.width}:${target.height}:${Math.round(lx * 2)}:${Math.round(ly * 2)}:${Math.round(scrollX)}:${Math.round(scrollY)}`; const now = performance.now(); if (!page.ctx) page.ctx = page.canvas.getContext("2d"); const region = { left: lx - padX, top: ly - padTop, right: lx + w + padX, bottom: ly + h + padBottom }; // Sayfayla birlikte kayan cam aynı arkayı taşır: resim yeniden çizilmez // (içinde kendi kendine oynayan ya da ekrana sabit bir şey yoksa). const rides = !live() && page.rigid && page.size === `${target.width}:${target.height}` && Math.abs(lx - page.lx + scrollX - page.sx) < 0.05 && Math.abs(ly - page.ly + scrollY - page.sy) < 0.05 && !page.pinned.some((el) => { const b = el.getBoundingClientRect(); return ( b.width > 0 && b.height > 0 && b.right > region.left && b.left < region.right && b.bottom > region.top && b.top < region.bottom ); }); if (page.near !== view.near) { page.near = view.near; page.stale = true; } const again = !!page.ctx && (page.stale || (key !== page.key && !rides) || now - page.at > (live() ? 12 : 120)); if (page.ctx && again) { page.stale = false; page.key = key; page.at = now; page.size = `${target.width}:${target.height}`; page.lx = lx; page.ly = ly; page.sx = scrollX; page.sy = scrollY; if (page.canvas.width !== target.width || page.canvas.height !== target.height) { page.canvas.width = target.width; page.canvas.height = target.height; } const pc2 = page.ctx; pc2.setTransform(1, 0, 0, 1, 0, 0); pc2.clearRect(0, 0, target.width, target.height); pc2.setTransform(back.getTransform()); const found = { pinned: [] as Element[], touched: false, loose: false }; drawDom(pc2, kok, { origin: { left: lx, top: ly }, region, skip: (el) => el === host || el.hasAttribute("data-glass-skip") || !!view.near?.includes(el), onStale: () => { page.stale = true; view.dirty = true; engine.wake(); }, found, }); page.pinned = found.pinned; page.rigid = !found.loose && !found.touched; } back.save(); back.setTransform(1, 0, 0, 1, 0, 0); back.drawImage(page.canvas, 0, 0); back.restore(); return again || recoloured; }, refract: lerp(44, 37, pc), magnify: 0, dispersion: 0.12, blurCenter: 0.35, blurEdge: 2.2, frost: yuzey ? CTA_BOYASI : SEFFAF_TON, } : undefined, screenX: rect.left + rect.width / 2, screenY: rect.top + rect.height / 2, scale: rect.width / Math.max(w * px, 1e-3), }; }, drawn: () => { if (ready) return; ready = true; host.dataset.glassReady = ""; }, lost: () => { ready = false; delete host.dataset.glassReady; view.grow = 1; }, }; const isDisabled = () => host.matches(":disabled, [aria-disabled='true']"); const dirty = () => { view.dirty = true; engine.wake(); }; const onDown = () => { if (isDisabled()) return; pressed = true; engine.wake(); }; const onUp = () => { pressed = false; engine.wake(); }; const onEnter = (e: PointerEvent) => { if (e.pointerType !== "mouse" || isDisabled()) return; hovered = true; dirty(); }; const onLeave = () => { pressed = false; hovered = false; dirty(); }; const target: HTMLElement = (tetik ? host.closest(tetik) : null) ?? host; if (target !== host) view.pressArea = target; target.addEventListener("pointerdown", onDown); target.addEventListener("pointerup", onUp); target.addEventListener("pointercancel", onUp); target.addEventListener("pointerenter", onEnter); target.addEventListener("pointerleave", onLeave); const io = new IntersectionObserver(([entry]) => { view.visible = entry.isIntersecting; dirty(); }); io.observe(host); const ro = new ResizeObserver(dirty); ro.observe(host); // İçerik değişince (yazı, seçili hâl) damla ve renkler yeniden okunur. const mo = new MutationObserver(dirty); mo.observe(host, { childList: true, attributes: true, attributeFilter: ["class", "disabled", "aria-pressed", "aria-checked", "aria-selected", "aria-expanded", "data-state"], }); // Kaydırma camın arkasını değiştirir, camı değil: boy ve renk yeniden okunmaz. const onScroll = () => { view.repaint = true; engine.wake(); }; if (clear) addEventListener("scroll", onScroll, { passive: true, capture: true }); // Tema değişince renkler yeniden okunur. const tema = new MutationObserver(dirty); tema.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] }); engine.add(view); return () => { engine.remove(view); ctx.clearRect(0, 0, canvas.width, canvas.height); io.disconnect(); ro.disconnect(); mo.disconnect(); tema.disconnect(); removeEventListener("scroll", onScroll, { capture: true }); target.removeEventListener("pointerdown", onDown); target.removeEventListener("pointerup", onUp); target.removeEventListener("pointercancel", onUp); target.removeEventListener("pointerenter", onEnter); target.removeEventListener("pointerleave", onLeave); delete host.dataset.glassReady; delete host.dataset.glassTone; host.style.removeProperty("--ok-cap"); canvas.style.scale = ""; }; }, [seffaf, otoDamla, tetik, kurulu]); return ( ); } /** * Tek seçimli sekmelerde (`SecimHaplari`, liste dilim sekmeleri) seçenekten seçeneğe * kayan cam mercek: kitin `GlassLens`'i (§4.50). Kabın ilk çocuğudur; seçili seçenek * düz vurguyu `data-glass-highlight` ile taşır. Mercek görünürken kaba * `data-glass-moving` (düz vurgu gizlenir) ve `data-glass-traveling` (seçili seçenek * şeffaf camın altında okunsun diye seçilmemiş gibi boyanır) yazılır. Basılı tutunca * mercek olduğu yerde açılır, sürükleyip bırakınca en yakın seçenek seçilir. */ export function KayanCam({ secili }: { secili: string | null }) { const acik = useCamAcik(); return ; } /** Rozet camı: kitin `GlassBadge`'iyle aynı ölçüler (bir seçenek 80 birim yüksekliğinde tasarlanır). */ const ROZET_BIRIM = 80; const ROZET_OPTIK = (ROZET_BIRIM * 1.35) / 120; /** Şeridin hızı (saniyede tur), kartın üstüne gelince katı ve o kata varış hızı. */ const ROZET_HIZI = 0.4; const ROZET_HIZLI = 3.5; const ROZET_IVME = 1.6; /** Boyanın arkadaki kartı örtmesi (0–1). */ const ROZET_BOYASI = 0.82; /** * "Yeni" rozetinin camı (§4.49): kitin `GlassBadge`'i. Mavi boyalı küçük damla, içinden * "Yeni ▪ Yeni ▪ …" şeridi akar; şerit camın alt katmanında çizildiği için kenar * yazının kendisini büker, arkadaki kart köşesi bulanık seçilir. Kartın üstüne gelince * şerit hızlanır. Rozetin ilk çocuğudur; ilk kare çizilince rozete `data-glass-ready` * yazılır ve rozet düz mavi zeminini ve DOM şeridini bırakır. Hareketi azalt'ta tek * ortalı yazı kalır. */ export function RozetCami({ metin }: { metin: string }) { const tuvalRef = useRef(null); const acik = useCamAcik(); useEffect(() => { const canvas = tuvalRef.current; const host = canvas?.parentElement; const ctx = canvas?.getContext("2d"); const engine = acik ? getGlassEngine() : null; if (!canvas || !host || !ctx || !engine) return; let w = 0; let h = 0; let surface: Rgb = [1, 1, 1]; let paint = "blue"; let ink = "white"; let dot = "orange"; let font = "600 12px sans-serif"; let offset = 0; let still = false; let rate = 1; let hovered = false; const snap = { small: document.createElement("canvas"), stale: true, at: 0 }; const measure = () => { w = host.offsetWidth; h = host.offsetHeight; const s = engine.resolveColor(surfaceColorOf(host.parentElement)); surface = [s[0], s[1], s[2]]; const had = "glassReady" in host.dataset; if (had) delete host.dataset.glassReady; const st = getComputedStyle(host); const p = engine.resolveColor(st.backgroundColor); if (had) host.dataset.glassReady = ""; paint = rgbCss([p[0], p[1], p[2]]); ink = st.color; const d = engine.resolveColor("var(--color-orange-500)"); dot = rgbCss([d[0], d[1], d[2]]); font = `${st.fontWeight} ${st.fontSize} ${st.fontFamily}`; snap.stale = true; }; const view: GlassView = { canvas, ctx, dirty: true, visible: false, step: (dt, reduced) => { still = reduced; if (reduced || !view.visible) return false; rate += ((hovered ? ROZET_HIZLI : 1) - rate) * Math.min(1, dt * ROZET_IVME); offset += dt * ROZET_HIZI * rate; return true; }, lens: (refresh) => { if (refresh || !w) measure(); if (w < 2 || h < 2) return null; const padX = 6; const padTop = 8; const padBottom = Math.round(h * 0.9 + 6); const box = host.getBoundingClientRect(); return { left: -padX, top: -padTop, width: w + 2 * padX, height: h + padTop + padBottom, unit: h / ROZET_BIRIM, cx: padX + w / 2, cy: padTop + h / 2, hx: w / 2, hy: h / 2, radius: 999, bodyX: 0, bevel: ROZET_BIRIM * 0.42, shadow: 0.1, shadowSoftness: 30 * ROZET_OPTIK, shadowOffset: 12 * ROZET_OPTIK, strength: 1, color: surface, surface, edgeClear: 0, refraction: { paint: (back) => { const dpr = back.getTransform().a; back.translate(padX, padTop); // Rozetin arkası (kart köşesi) dörtte bir çözünürlükte çizilir: ucuz bir bulanıklık. const now = performance.now(); const W = back.canvas.width; const H = back.canvas.height; if (snap.stale || now - snap.at > 500) { snap.stale = false; snap.at = now; const sw = Math.max(1, Math.round(W / 4)); const sh = Math.max(1, Math.round(H / 4)); snap.small.width = sw; snap.small.height = sh; const sc = snap.small.getContext("2d"); if (sc) { sc.setTransform(dpr / 4, 0, 0, dpr / 4, (padX * dpr) / 4, (padTop * dpr) / 4); sc.fillStyle = rgbCss(surface); sc.fillRect(-padX, -padTop, W, H); const root = host.offsetParent ?? document.body; drawDom(sc, root, { origin: { left: box.left, top: box.top }, region: { left: box.left - padX, top: box.top - padTop, right: box.right + padX, bottom: box.bottom + padBottom }, skip: (el) => el === host, onStale: () => { snap.stale = true; view.dirty = true; engine.wake(); }, }); } } back.save(); back.setTransform(1, 0, 0, 1, 0, 0); back.imageSmoothingQuality = "high"; back.drawImage(snap.small, 0, 0, W, H); back.restore(); back.globalAlpha = ROZET_BOYASI; back.fillStyle = paint; back.fillRect(-padX, -padTop, w + 2 * padX, h + padTop + padBottom); back.globalAlpha = 1; back.font = font; back.textBaseline = "middle"; back.fillStyle = ink; const mid = h / 2 + 0.5; if (still) { back.textAlign = "center"; back.fillText(metin, w / 2, mid); return; } const tw = back.measureText(metin).width + 12; back.textAlign = "left"; for (let x = -((offset % 1) * tw) - tw; x < w + tw; x += tw) { back.fillStyle = ink; back.fillText(metin, x + 6, mid); back.fillStyle = dot; back.fillRect(x - 2, h / 2 - 1.5, 4, 4); } }, refract: 22 * ROZET_OPTIK, magnify: 0.1, dispersion: 0.12, blurCenter: 0, blurEdge: 2.2, frost: 0, }, cursorLight: true, pointerLight: true, screenX: box.left + w / 2, screenY: box.top + h / 2, }; }, drawn: () => { host.dataset.glassReady = ""; }, lost: () => { delete host.dataset.glassReady; }, }; const dirty = () => { view.dirty = true; engine.wake(); }; const io = new IntersectionObserver(([entry]) => { view.visible = entry.isIntersecting; dirty(); }); io.observe(host); const ro = new ResizeObserver(dirty); ro.observe(host); const parent = host.offsetParent; if (parent) ro.observe(parent); const enter = (e: Event) => { if ((e as PointerEvent).pointerType === "mouse") hovered = true; }; const leave = () => { hovered = false; }; parent?.addEventListener("pointerenter", enter); parent?.addEventListener("pointerleave", leave); const tema = new MutationObserver(dirty); tema.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] }); engine.add(view); return () => { engine.remove(view); ctx.clearRect(0, 0, canvas.width, canvas.height); io.disconnect(); ro.disconnect(); tema.disconnect(); parent?.removeEventListener("pointerenter", enter); parent?.removeEventListener("pointerleave", leave); delete host.dataset.glassReady; }; }, [metin, acik]); return ( ); }