Spaces:
Running
Running
Download main.js from EnergyVenom/cartesiancorp: direct link, hf CLI and curl.
- Browser
- Download file 29.8 kB
-
https://huggingface.co/spaces/EnergyVenom/cartesiancorp/resolve/main/main.js
- Command line
-
hf download hf://spaces/EnergyVenom/cartesiancorp/main.js
-
curl -L -o main.js https://huggingface.co/spaces/EnergyVenom/cartesiancorp/resolve/main/main.js
29.8 kB
| /* Cartesian Corp — shared page runtime (all pages) */ | |
| (function () { | |
| const $ = (s, el = document) => el.querySelector(s); | |
| const $$ = (s, el = document) => [...el.querySelectorAll(s)]; | |
| const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches; | |
| const hasGSAP = typeof gsap !== 'undefined' && typeof ScrollTrigger !== 'undefined'; | |
| const base = document.body.dataset.base || ''; | |
| const root = document.documentElement; | |
| if (reduced || !hasGSAP) root.classList.add('no-anim'); | |
| $$('.year').forEach((el) => { el.textContent = new Date().getFullYear(); }); | |
| /* ================= PAGE READY ================= */ | |
| // Page transitions are handled natively by CSS view transitions, so links navigate instantly. | |
| window.__ccReady = true; | |
| requestAnimationFrame(() => root.classList.add('page-ready')); | |
| // Warm up the next page: prefetch internal pages when a link is hovered or touched. | |
| const prefetched = new Set(); | |
| const prefetch = (e) => { | |
| const a = e.target.closest && e.target.closest('a[href$=".html"]'); | |
| if (!a || a.target === '_blank') return; | |
| const url = new URL(a.href, location.href); | |
| if (url.origin !== location.origin || prefetched.has(url.pathname) || url.pathname === location.pathname) return; | |
| prefetched.add(url.pathname); | |
| const l = document.createElement('link'); l.rel = 'prefetch'; l.href = url.href; document.head.appendChild(l); | |
| }; | |
| document.addEventListener('mouseover', prefetch, { passive: true }); | |
| document.addEventListener('touchstart', prefetch, { passive: true }); | |
| /* ================= NAV ================= */ | |
| const nav = $('#nav'), navToggle = $('#navToggle'), navLinks = $('#navLinks'); | |
| let lastY = 0; | |
| const onScroll = () => { | |
| const y = window.scrollY; | |
| nav.classList.toggle('scrolled', y > 20); | |
| nav.classList.toggle('hidden', y > lastY && y > 300 && !navLinks.classList.contains('open')); | |
| lastY = y; | |
| }; | |
| window.addEventListener('scroll', onScroll, { passive: true }); | |
| onScroll(); | |
| navToggle.addEventListener('click', () => { | |
| const open = navLinks.classList.toggle('open'); | |
| navToggle.setAttribute('aria-expanded', open); | |
| navToggle.setAttribute('aria-label', open ? 'Close menu' : 'Open menu'); | |
| }); | |
| // same-page anchors use smooth scroll | |
| function scrollToEl(el) { | |
| if (!el) return; | |
| if (window.__lenis) window.__lenis.scrollTo(el, { offset: -90, duration: 1.2 }); | |
| else el.scrollIntoView({ behavior: reduced ? 'auto' : 'smooth' }); | |
| } | |
| $$('a[href^="#"]').forEach((a) => a.addEventListener('click', (e) => { | |
| const id = a.getAttribute('href'); | |
| if (id.length < 2) return; | |
| const el = $(id); if (!el) return; | |
| e.preventDefault(); scrollToEl(el); history.replaceState(null, '', id); | |
| })); | |
| /* ================= GENERATIVE VISUALS ================= */ | |
| const PAL = ['#5b7cff', '#ff6a45', '#a9b8ff']; | |
| function makeViz(canvas, type, seed = 1) { | |
| const ctx = canvas.getContext('2d'); | |
| let w, h, raf = null, running = false; | |
| const t0 = performance.now() - seed * 997; | |
| let rnd = seed * 9301; | |
| const rand = () => ((rnd = (rnd * 9301 + 49297) % 233280) / 233280); | |
| const pts = Array.from({ length: 34 }, () => ({ x: rand(), y: rand(), vx: rand() - .5, vy: rand() - .5, c: PAL[(rand() * 3) | 0] })); | |
| const bars = Array.from({ length: 28 }, () => rand()); | |
| const rr = (x, y, ww, hh, r) => { ctx.beginPath(); ctx.roundRect ? ctx.roundRect(x, y, ww, hh, r) : ctx.rect(x, y, ww, hh); }; | |
| // Architecture diagram: labeled components connected in order, with data flowing through. | |
| let labels = []; | |
| try { labels = JSON.parse(canvas.dataset.arch || '[]'); } catch (e) { labels = []; } | |
| function wrap(text, maxW) { | |
| const words = text.split(' '); const lines = []; let cur = ''; | |
| for (const wd of words) { | |
| const test = cur ? cur + ' ' + wd : wd; | |
| if (ctx.measureText(test).width > maxW && cur) { lines.push(cur); cur = wd; } else cur = test; | |
| } | |
| lines.push(cur); return lines.slice(0, 2); | |
| } | |
| function drawArch(t) { | |
| const n = labels.length; if (!n) return; | |
| const cols = (w / h > 2.2 && w > 900) ? n : (w < 460 ? 2 : 3); | |
| const rows = Math.ceil(n / cols); | |
| const padX = Math.max(24, w * .05), top = 58, bottom = 28; | |
| const cellW = (w - padX * 2) / cols, cellH = (h - top - bottom) / rows; | |
| const bw = Math.min(cellW - 28, 210), bh = Math.min(cellH - 30, w > 900 ? 74 : 62); | |
| const fs = w > 900 ? 14 : 12.5; | |
| const pos = labels.map((_, i) => { | |
| const r = Math.floor(i / cols); let c = i % cols; | |
| if (r % 2 === 1) c = cols - 1 - c; // serpentine flow | |
| return { x: padX + cellW * c + cellW / 2, y: top + cellH * r + cellH / 2 }; | |
| }); | |
| const flow = (t * .55) % (n - 1 + .6); | |
| const seg = Math.min(n - 2, Math.floor(flow)), u = Math.min(1, flow - seg); | |
| // connectors | |
| ctx.setLineDash([4, 5]); ctx.lineWidth = 1.5; | |
| for (let i = 0; i < n - 1; i++) { | |
| ctx.strokeStyle = i < seg || (i === seg && u >= 1) ? 'rgba(125,151,255,.75)' : 'rgba(255,255,255,.18)'; | |
| ctx.beginPath(); ctx.moveTo(pos[i].x, pos[i].y); ctx.lineTo(pos[i + 1].x, pos[i + 1].y); ctx.stroke(); | |
| } | |
| ctx.setLineDash([]); | |
| // travelling packet | |
| const a = pos[seg], b = pos[seg + 1]; | |
| const px = a.x + (b.x - a.x) * u, py = a.y + (b.y - a.y) * u; | |
| ctx.fillStyle = 'rgba(255,90,54,.25)'; ctx.beginPath(); ctx.arc(px, py, 9, 0, 7); ctx.fill(); | |
| ctx.fillStyle = '#ff5a36'; ctx.beginPath(); ctx.arc(px, py, 4.5, 0, 7); ctx.fill(); | |
| // nodes | |
| labels.forEach((label, i) => { | |
| const { x, y } = pos[i]; | |
| const active = i === seg + (u > .98 ? 1 : 0), done = i <= seg; | |
| ctx.fillStyle = active ? 'rgba(43,76,255,.35)' : 'rgba(18,40,61,.96)'; | |
| ctx.strokeStyle = active ? '#7d97ff' : (done ? 'rgba(125,151,255,.55)' : 'rgba(255,255,255,.16)'); | |
| ctx.lineWidth = active ? 2 : 1; | |
| rr(x - bw / 2, y - bh / 2, bw, bh, 10); ctx.fill(); ctx.stroke(); | |
| ctx.font = `500 ${fs - 3}px "JetBrains Mono", monospace`; | |
| ctx.fillStyle = '#ff8a6b'; ctx.textAlign = 'left'; ctx.textBaseline = 'top'; | |
| ctx.fillText(String(i + 1).padStart(2, '0'), x - bw / 2 + 12, y - bh / 2 + 9); | |
| ctx.font = `600 ${fs}px Inter, system-ui, sans-serif`; | |
| ctx.fillStyle = '#ffffff'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; | |
| const lines = wrap(label, bw - 24), lh = fs * 1.3, y0 = y + 6 - ((lines.length - 1) * lh) / 2; | |
| lines.forEach((ln, k) => ctx.fillText(ln, x, y0 + k * lh)); | |
| }); | |
| ctx.textAlign = 'left'; ctx.textBaseline = 'alphabetic'; | |
| } | |
| function size() { | |
| const dpr = Math.min(window.devicePixelRatio || 1, 2); | |
| w = canvas.clientWidth; h = canvas.clientHeight; | |
| canvas.width = w * dpr; canvas.height = h * dpr; | |
| ctx.setTransform(dpr, 0, 0, dpr, 0, 0); | |
| } | |
| function bg() { | |
| const g = ctx.createLinearGradient(0, 0, w, h); | |
| g.addColorStop(0, '#0b1d2e'); g.addColorStop(1, '#14304a'); | |
| ctx.fillStyle = g; ctx.fillRect(0, 0, w, h); | |
| ctx.strokeStyle = 'rgba(255,255,255,.05)'; ctx.lineWidth = 1; | |
| ctx.beginPath(); | |
| for (let x = 0; x < w; x += 32) { ctx.moveTo(x + .5, 0); ctx.lineTo(x + .5, h); } | |
| for (let y = 0; y < h; y += 32) { ctx.moveTo(0, y + .5); ctx.lineTo(w, y + .5); } | |
| ctx.stroke(); | |
| } | |
| function draw(now) { | |
| const t = (now - t0) / 1000; | |
| bg(); | |
| if (type === 'network') { | |
| for (const p of pts) { p.x += p.vx * .0008; p.y += p.vy * .0008; if (p.x < 0 || p.x > 1) p.vx *= -1; if (p.y < 0 || p.y > 1) p.vy *= -1; } | |
| for (let i = 0; i < pts.length; i++) for (let j = i + 1; j < pts.length; j++) { | |
| const a = pts[i], b = pts[j], d = Math.hypot((a.x - b.x) * w, (a.y - b.y) * h); | |
| if (d < 150) { ctx.strokeStyle = `rgba(125,151,255,${(1 - d / 150) * .45})`; ctx.beginPath(); ctx.moveTo(a.x * w, a.y * h); ctx.lineTo(b.x * w, b.y * h); ctx.stroke(); } | |
| } | |
| pts.forEach((p, i) => { | |
| ctx.fillStyle = i === 0 ? '#ff6a45' : p.c; | |
| ctx.beginPath(); ctx.arc(p.x * w, p.y * h, i === 0 ? 8 + Math.sin(t * 3) * 1.5 : 3.2, 0, 7); ctx.fill(); | |
| if (i === 0) { ctx.strokeStyle = 'rgba(255,106,69,.35)'; ctx.beginPath(); ctx.arc(p.x * w, p.y * h, 16 + (t * 12 % 14), 0, 7); ctx.stroke(); } | |
| }); | |
| } else if (type === 'bars') { | |
| const n = bars.length, bw = w / n; | |
| bars.forEach((b, i) => { | |
| const v = .15 + .7 * (0.5 + 0.5 * Math.sin(t * 1.3 + i * .45 + b * 6)) * (.4 + b * .6); | |
| ctx.fillStyle = i % 7 === 3 ? '#ff6a45' : (i % 2 ? '#5b7cff' : '#7d97ff'); | |
| rr(i * bw + 4, h - v * h * .8 - 16, bw - 8, v * h * .8, 3); ctx.fill(); | |
| }); | |
| } else if (type === 'grid') { | |
| const cols = 11, rows = 6, cw = w / cols, ch = h / rows; | |
| for (let i = 0; i < cols; i++) for (let j = 0; j < rows; j++) { | |
| const on = (Math.sin(t * 1.1 + i * .7 + j * 1.3) + 1) / 2; | |
| ctx.fillStyle = on > .85 ? 'rgba(255,106,69,.85)' : `rgba(91,124,255,${.1 + on * .5})`; | |
| rr(i * cw + 6, j * ch + 6, cw - 12, ch - 12, 6); ctx.fill(); | |
| } | |
| } else if (type === 'orbit') { | |
| const cx = w / 2, cy = h / 2, R = Math.min(w, h) * .11; | |
| for (let r = 1; r <= 4; r++) { | |
| ctx.strokeStyle = 'rgba(255,255,255,.1)'; | |
| ctx.beginPath(); ctx.ellipse(cx, cy, r * R * 1.6, r * R, 0, 0, 7); ctx.stroke(); | |
| for (let k = 0; k < r + 1; k++) { | |
| const a = t * (0.6 / r) + k * (6.28 / (r + 1)); | |
| ctx.fillStyle = PAL[(r + k) % 3]; | |
| ctx.beginPath(); ctx.arc(cx + Math.cos(a) * r * R * 1.6, cy + Math.sin(a) * r * R, 4.5, 0, 7); ctx.fill(); | |
| } | |
| } | |
| ctx.fillStyle = '#ff6a45'; ctx.beginPath(); ctx.arc(cx, cy, 13, 0, 7); ctx.fill(); | |
| } else if (type === 'wave') { | |
| for (let k = 0; k < 6; k++) { | |
| ctx.strokeStyle = k === 2 ? '#ff6a45' : PAL[k % 3 === 1 ? 0 : k % 3]; ctx.globalAlpha = .35 + k * .1; ctx.lineWidth = 2; | |
| ctx.beginPath(); | |
| for (let x = 0; x <= w; x += 6) { | |
| const y = h / 2 + Math.sin(x * .012 + t * (1 + k * .2) + k) * (h * .12 + k * 6) * Math.sin(x / w * Math.PI); | |
| x ? ctx.lineTo(x, y) : ctx.moveTo(x, y); | |
| } | |
| ctx.stroke(); | |
| } | |
| ctx.globalAlpha = 1; ctx.lineWidth = 1; | |
| } else if (type === 'flow') { | |
| const stages = 5, sw = w / stages; | |
| for (let s = 0; s < stages; s++) { | |
| const x = s * sw + sw / 2, y = h / 2, bw2 = Math.min(46, sw * .38); | |
| ctx.fillStyle = 'rgba(255,255,255,.06)'; ctx.strokeStyle = 'rgba(255,255,255,.18)'; | |
| rr(x - bw2, y - 30, bw2 * 2, 60, 10); ctx.fill(); ctx.stroke(); | |
| ctx.fillStyle = s === 2 ? '#ff6a45' : '#7d97ff'; ctx.fillRect(x - bw2 + 14, y - 8, (bw2 * 2 - 28) * (0.4 + 0.6 * ((Math.sin(t + s) + 1) / 2)), 4); | |
| ctx.fillStyle = 'rgba(255,255,255,.25)'; ctx.fillRect(x - bw2 + 14, y + 4, bw2, 3); | |
| if (s < stages - 1) { | |
| ctx.strokeStyle = 'rgba(125,151,255,.4)'; ctx.beginPath(); ctx.moveTo(x + bw2, y); ctx.lineTo(x + sw - bw2, y); ctx.stroke(); | |
| const p = (t * .6 + s * .2) % 1; | |
| ctx.fillStyle = '#fff'; ctx.beginPath(); ctx.arc(x + bw2 + p * (sw - bw2 * 2), y, 3.5, 0, 7); ctx.fill(); | |
| } | |
| } | |
| } else if (type === 'arch') { | |
| drawArch(t); | |
| } else if (type === 'avatar') { | |
| ctx.lineWidth = 1.6; | |
| for (let m = 0; m < 3; m++) { | |
| ctx.strokeStyle = m === 1 ? '#ff6a45' : PAL[m === 0 ? 0 : 2]; ctx.globalAlpha = .7 - m * .15; | |
| ctx.beginPath(); | |
| for (let a = 0; a <= 6.3; a += .03) { | |
| const r = Math.min(w, h) * (.28 + m * .06) * (1 + .18 * Math.sin((seed + 2) * a + t * .8 + m)); | |
| const x = w / 2 + Math.cos(a) * r, y = h / 2 + Math.sin(a) * r; | |
| a ? ctx.lineTo(x, y) : ctx.moveTo(x, y); | |
| } | |
| ctx.closePath(); ctx.stroke(); | |
| } | |
| ctx.globalAlpha = 1; | |
| ctx.strokeStyle = 'rgba(255,255,255,.2)'; | |
| ctx.beginPath(); ctx.moveTo(w / 2, 10); ctx.lineTo(w / 2, h - 10); ctx.moveTo(10, h / 2); ctx.lineTo(w - 10, h / 2); ctx.stroke(); | |
| } | |
| if (running) raf = requestAnimationFrame(draw); | |
| } | |
| size(); draw(performance.now()); | |
| window.addEventListener('resize', () => { size(); if (!running) draw(performance.now()); }); | |
| if (!reduced) new IntersectionObserver(([e]) => { | |
| if (e.isIntersecting && !running) { running = true; raf = requestAnimationFrame(draw); } | |
| else if (!e.isIntersecting) { running = false; cancelAnimationFrame(raf); } | |
| }).observe(canvas); | |
| } | |
| $$('canvas[data-viz]').forEach((c) => makeViz(c, c.dataset.viz, +c.dataset.seed || 1)); | |
| /* ================= PRODUCT VIDEOS ================= */ | |
| // Work cards: play the demo on hover (desktop) or when scrolled into view (touch devices). | |
| const canHover = window.matchMedia('(hover:hover)').matches; | |
| $$('.project').forEach((card) => { | |
| const v = $('.pv-video', card); | |
| if (!v) return; | |
| const play = () => { | |
| if (reduced) return; | |
| if (!v.src) v.src = v.dataset.src; | |
| v.play().then(() => card.classList.add('playing')).catch(() => {}); | |
| }; | |
| const stop = () => { v.pause(); card.classList.remove('playing'); }; | |
| if (canHover) { card.addEventListener('mouseenter', play); card.addEventListener('mouseleave', stop); } | |
| else new IntersectionObserver(([e]) => (e.isIntersecting ? play() : stop()), { threshold: .6 }).observe(card); | |
| }); | |
| // Case-study video player | |
| $$('[data-vp]').forEach((vp) => { | |
| const v = $('video', vp), fill = $('.vp-fill', vp), time = $('.vp-time', vp), track = $('.vp-track', vp); | |
| const fmt = (s) => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, '0')}`; | |
| const sync = () => vp.classList.toggle('is-playing', !v.paused); | |
| const toggle = () => (v.paused ? v.play().catch(() => {}) : v.pause()); | |
| v.addEventListener('play', sync); v.addEventListener('pause', sync); | |
| v.addEventListener('timeupdate', () => { | |
| if (v.duration) fill.style.width = (v.currentTime / v.duration * 100) + '%'; | |
| time.textContent = fmt(v.currentTime); | |
| }); | |
| $('.vp-big', vp).addEventListener('click', toggle); | |
| $('.vp-toggle', vp).addEventListener('click', toggle); | |
| v.addEventListener('click', toggle); | |
| track.addEventListener('click', (e) => { | |
| const r = track.getBoundingClientRect(); | |
| if (v.duration) v.currentTime = ((e.clientX - r.left) / r.width) * v.duration; | |
| }); | |
| $('.vp-fs', vp).addEventListener('click', () => { | |
| if (document.fullscreenElement) document.exitFullscreen(); | |
| else if (vp.requestFullscreen) vp.requestFullscreen(); | |
| else if (v.webkitEnterFullscreen) v.webkitEnterFullscreen(); // iOS Safari | |
| }); | |
| // Autoplay muted when visible, pause when scrolled away (respects reduced motion). | |
| let userPaused = false; | |
| $('.vp-toggle', vp).addEventListener('click', () => { userPaused = v.paused; }); | |
| if (!reduced) new IntersectionObserver(([e]) => { | |
| if (e.isIntersecting && !userPaused) v.play().catch(() => {}); | |
| else if (!e.isIntersecting) v.pause(); | |
| }, { threshold: .5 }).observe(vp); | |
| }); | |
| /* ================= 3D STACK <-> LIST SYNC ================= */ | |
| const stackEl = $('[data-three="stack"]'), stackList = $('#stackList'); | |
| if (stackEl && stackList) { | |
| const items = $$('li', stackList); | |
| stackEl.addEventListener('stack:active', (e) => items.forEach((li) => li.classList.toggle('on', +li.dataset.layer === e.detail))); | |
| items.forEach((li) => { | |
| li.addEventListener('mouseenter', () => stackEl.dispatchEvent(new CustomEvent('stack:hover', { detail: +li.dataset.layer }))); | |
| li.addEventListener('mouseleave', () => stackEl.dispatchEvent(new CustomEvent('stack:hover', { detail: -1 }))); | |
| }); | |
| } | |
| /* ================= MARQUEE ================= */ | |
| const mq = $('.marquee-track'); | |
| if (mq) mq.innerHTML += mq.innerHTML; | |
| /* ================= WORK FILTER ================= */ | |
| $$('.filter').forEach((btn) => btn.addEventListener('click', () => { | |
| $$('.filter').forEach((b) => b.classList.toggle('active', b === btn)); | |
| const f = btn.dataset.filter; | |
| const cards = $$('#workGrid .project'); | |
| const apply = () => cards.forEach((c) => c.classList.toggle('hide', f !== 'all' && c.dataset.cat !== f)); | |
| if (hasGSAP && !reduced) { | |
| gsap.to(cards, { opacity: 0, y: 16, duration: .18, onComplete: () => { | |
| apply(); | |
| gsap.fromTo(cards.filter((c) => !c.classList.contains('hide')), { opacity: 0, y: 26 }, { opacity: 1, y: 0, duration: .5, stagger: .06, ease: 'power3.out', onComplete: () => ScrollTrigger.refresh() }); | |
| } }); | |
| } else apply(); | |
| })); | |
| /* ================= SHOWREEL ================= */ | |
| const player = $('#player'); | |
| if (player) (function () { | |
| const video = $('#reelVideo'), sim = $('#reelSim'), log = $('#simLog'), steps = $$('#simSteps li'); | |
| const barsEl = $('#simBars'), toggle = $('#reelToggle'), fill = $('#reelProgress'), timeEl = $('#reelTime'); | |
| const line = $('#chartLine'), area = $('#chartArea'); | |
| let useVideo = false; | |
| video.addEventListener('loadeddata', () => { video.hidden = false; sim.style.display = 'none'; useVideo = true; }); | |
| // Only fetch the showreel when the player is about to scroll into view. | |
| new IntersectionObserver(([e], o) => { if (e.isIntersecting) { o.disconnect(); video.preload = 'auto'; video.load(); } }, { rootMargin: '400px' }).observe(player); | |
| for (let i = 0; i < 16; i++) barsEl.appendChild(document.createElement('span')); | |
| const barEls = $$('span', barsEl); | |
| const SCRIPT = [ | |
| [0, '<span class="t">09:41:02</span> <span class="k">▸ request</span> "Summarize Q3 churn for enterprise accounts and draft outreach"'], | |
| [1, '<span class="t">09:41:03</span> <span class="k">▸ plan</span> 1) query warehouse 2) enrich from CRM 3) draft 4) evaluate'], | |
| [2, '<span class="t">09:41:04</span> <span class="v">tool</span> sql.query(<span class="s">"SELECT account, mrr, churn_risk FROM accounts WHERE tier=\'ent\'"</span>)'], | |
| [2, '<span class="t">09:41:05</span> <span class="ok">✓</span> 1,284 rows · 212ms'], | |
| [3, '<span class="t">09:41:06</span> <span class="v">tool</span> crm.get_contacts(accounts=<span class="s">top_risk[:25]</span>)'], | |
| [3, '<span class="t">09:41:07</span> <span class="ok">✓</span> 25 accounts enriched · owners assigned'], | |
| [4, '<span class="t">09:41:08</span> <span class="k">▸ draft</span> executive summary + 25 personalized emails…'], | |
| [4, '<span class="t">09:41:10</span> <span class="ok">✓</span> report.md · 25 drafts queued for review'], | |
| [5, '<span class="t">09:41:11</span> <span class="k">▸ eval</span> factuality 0.97 · tone ✓ · PII scan ✓ · policy ✓'], | |
| [6, '<span class="t">09:41:12</span> <span class="ok">✓ delivered</span> to #customer-success in 9.8s · awaiting human approval'] | |
| ]; | |
| const DURATION = 16000; | |
| let playing = true, elapsed = 0, last = performance.now(), shown = 0; | |
| const chartPts = Array.from({ length: 40 }, (_, i) => 70 + Math.sin(i / 3) * 20); | |
| const renderChart = () => { | |
| const d = chartPts.map((v, i) => `${i ? 'L' : 'M'}${(i / 39) * 400},${v}`).join(' '); | |
| line.setAttribute('d', d); area.setAttribute('d', d + ' L400,140 L0,140 Z'); | |
| }; | |
| const reset = () => { log.innerHTML = ''; shown = 0; steps.forEach((s) => s.classList.remove('done', 'active')); }; | |
| function tick(now) { | |
| const dt = now - last; last = now; | |
| if (playing && !useVideo) { | |
| elapsed += dt; | |
| if (elapsed > DURATION) { elapsed = 0; reset(); } | |
| const p = elapsed / DURATION; | |
| fill.style.width = (p * 100) + '%'; | |
| timeEl.textContent = `00:${String(Math.floor(elapsed / 1000)).padStart(2, '0')}`; | |
| const target = Math.min(SCRIPT.length, Math.floor(p * (SCRIPT.length + 2))); | |
| while (shown < target) { | |
| const [step, html] = SCRIPT[shown]; | |
| const cur = log.querySelector('.cursor'); if (cur) cur.remove(); | |
| const ln = document.createElement('div'); ln.className = 'ln'; ln.innerHTML = html + ' <span class="cursor"></span>'; | |
| log.appendChild(ln); | |
| while (log.children.length > 9) log.firstChild.remove(); | |
| steps.forEach((el, k) => { el.classList.toggle('done', k < step); el.classList.toggle('active', k === step); }); | |
| if (shown === SCRIPT.length - 1) steps.forEach((el) => { el.classList.add('done'); el.classList.remove('active'); }); | |
| shown++; | |
| } | |
| if (Math.random() < .25) { | |
| chartPts.shift(); chartPts.push(Math.max(10, Math.min(130, chartPts[chartPts.length - 1] + (Math.random() - .55) * 18))); | |
| renderChart(); barEls.forEach((b) => { b.style.height = (15 + Math.random() * 85) + '%'; }); | |
| } | |
| } else if (useVideo && video.duration) { | |
| fill.style.width = (video.currentTime / video.duration * 100) + '%'; | |
| timeEl.textContent = `00:${String(Math.floor(video.currentTime)).padStart(2, '0')}`; | |
| } | |
| requestAnimationFrame(tick); | |
| } | |
| renderChart(); requestAnimationFrame(tick); | |
| toggle.addEventListener('click', () => { | |
| playing = !playing; | |
| toggle.textContent = playing ? '❚❚' : '▶'; | |
| toggle.setAttribute('aria-label', playing ? 'Pause' : 'Play'); | |
| if (useVideo) playing ? video.play() : video.pause(); | |
| }); | |
| new IntersectionObserver(([e]) => { if (useVideo) (e.isIntersecting && playing) ? video.play().catch(() => {}) : video.pause(); }, { threshold: .3 }).observe(player); | |
| })(); | |
| /* ================= CONTACT FORM ================= */ | |
| const form = $('#contactForm'); | |
| if (form) { | |
| const qs = new URLSearchParams(location.search); | |
| if (qs.get('need')) form.elements.need.value = qs.get('need'); | |
| try { | |
| const pre = JSON.parse(sessionStorage.getItem('cc_prefill') || 'null'); | |
| if (pre) { | |
| if (pre.need) form.elements.need.value = pre.need; | |
| if (pre.msg) form.elements.msg.value = pre.msg; | |
| sessionStorage.removeItem('cc_prefill'); | |
| } | |
| } catch (e) { /* storage unavailable */ } | |
| form.addEventListener('submit', async (e) => { | |
| e.preventDefault(); | |
| const d = Object.fromEntries(new FormData(form)); | |
| if (d._honey) return; // spam bot | |
| const needLabel = form.elements.need.selectedOptions[0].text; | |
| const subject = 'Project inquiry: ' + (d.company || d.name); | |
| const email = (window.CC_DATA && window.CC_DATA.email) || 'hello@cartesiancorp.com'; | |
| const endpoint = window.CC_DATA && window.CC_DATA.formEndpoint; | |
| const note = $('#formNote'), btn = $('button[type="submit"]', form); | |
| const mailto = () => { | |
| const body = `Name: ${d.name}\nEmail: ${d.email}\nCompany: ${d.company || '-'}\nNeed: ${needLabel}\nBudget: ${d.budget}\nTimeline: ${d.timeline}\n\n${d.msg}`; | |
| location.href = `mailto:${email}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`; | |
| note.textContent = 'Opening your email app to send the message.'; | |
| }; | |
| if (!endpoint) return mailto(); | |
| btn.disabled = true; note.textContent = 'Sending…'; | |
| try { | |
| const r = await fetch(endpoint, { | |
| method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, | |
| body: JSON.stringify({ _subject: subject, _template: 'table', _replyto: d.email, name: d.name, email: d.email, company: d.company || '-', need: needLabel, budget: d.budget, timeline: d.timeline, message: d.msg }) | |
| }); | |
| const j = await r.json().catch(() => ({})); | |
| if (!r.ok || j.success === false || j.success === 'false') throw new Error(j.message || 'send failed'); | |
| form.innerHTML = `<div class="form-done full"><span class="c-check" aria-hidden="true"></span><h3>Thanks, ${d.name.split(' ')[0].replace(/[<>&"]/g, '')}. Your message is on its way.</h3><p>A senior architect will reply to <b>${d.email.replace(/[<>&"]/g, '')}</b> within one business day. If it's urgent, email <a href="mailto:${email}">${email}</a>.</p></div>`; | |
| } catch (err) { | |
| btn.disabled = false; | |
| note.textContent = 'We could not send the form, so we are opening your email app instead.'; | |
| setTimeout(mailto, 600); | |
| } | |
| }); | |
| } | |
| /* shared helper for ai.js: send the visitor to the contact page with details prefilled */ | |
| window.CC = Object.assign(window.CC || {}, { | |
| team: (window.CC_DATA && window.CC_DATA.team) || [], | |
| goContact(prefill) { | |
| try { sessionStorage.setItem('cc_prefill', JSON.stringify(prefill || {})); } catch (e) { /* ignore */ } | |
| if (form) { | |
| if (prefill && prefill.need) form.elements.need.value = prefill.need; | |
| if (prefill && prefill.msg) form.elements.msg.value = prefill.msg; | |
| scrollToEl(form); return; | |
| } | |
| location.href = base + 'contact.html'; | |
| } | |
| }); | |
| /* ================= CASE STUDY TOC ================= */ | |
| const toc = $$('.case-toc a'); | |
| if (toc.length) { | |
| const io = new IntersectionObserver((ents) => ents.forEach((en) => { | |
| if (en.isIntersecting) toc.forEach((a) => a.classList.toggle('on', a.getAttribute('href') === '#' + en.target.id)); | |
| }), { rootMargin: '-30% 0px -60% 0px' }); | |
| toc.forEach((a) => { const t = $(a.getAttribute('href')); if (t) io.observe(t); }); | |
| } | |
| /* ================= POINTER EFFECTS ================= */ | |
| if (window.matchMedia('(hover:hover)').matches && !reduced) { | |
| $$('.magnetic').forEach((b) => { | |
| b.addEventListener('pointermove', (e) => { | |
| const r = b.getBoundingClientRect(); | |
| b.style.setProperty('--mx', ((e.clientX - r.left - r.width / 2) * .2) + 'px'); | |
| b.style.setProperty('--my', ((e.clientY - r.top - r.height / 2) * .3) + 'px'); | |
| }); | |
| b.addEventListener('pointerleave', () => { b.style.setProperty('--mx', '0px'); b.style.setProperty('--my', '0px'); }); | |
| }); | |
| $$('.tilt').forEach((c) => { | |
| c.addEventListener('pointermove', (e) => { | |
| const r = c.getBoundingClientRect(); | |
| c.style.setProperty('--ry', (((e.clientX - r.left) / r.width - .5) * 8) + 'deg'); | |
| c.style.setProperty('--rx', ((.5 - (e.clientY - r.top) / r.height) * 8) + 'deg'); | |
| }); | |
| c.addEventListener('pointerleave', () => { c.style.setProperty('--rx', '0deg'); c.style.setProperty('--ry', '0deg'); }); | |
| }); | |
| } | |
| /* ================= COUNTERS ================= */ | |
| function runCounter(el) { | |
| const to = parseFloat(el.dataset.to), dec = +(el.dataset.decimals || 0), suf = el.dataset.suffix || ''; | |
| if (reduced) { el.textContent = to.toFixed(dec) + suf; return; } | |
| const start = performance.now(); | |
| (function step(now) { | |
| const p = Math.min(1, (now - start) / 1800), e = 1 - Math.pow(1 - p, 4); | |
| el.textContent = (to * e).toFixed(dec) + suf; | |
| if (p < 1) requestAnimationFrame(step); | |
| })(start); | |
| } | |
| /* ================= SCROLL ANIMATION ================= */ | |
| if (!hasGSAP || reduced) { | |
| const co = new IntersectionObserver((ents) => ents.forEach((en) => { if (en.isIntersecting) { runCounter(en.target); co.unobserve(en.target); } })); | |
| $$('.count').forEach((el) => co.observe(el)); | |
| return; | |
| } | |
| gsap.registerPlugin(ScrollTrigger); | |
| if (typeof Lenis !== 'undefined') { | |
| const lenis = new Lenis({ duration: 1.1, smoothWheel: true }); | |
| window.__lenis = lenis; | |
| lenis.on('scroll', ScrollTrigger.update); | |
| gsap.ticker.add((time) => lenis.raf(time * 1000)); | |
| gsap.ticker.lagSmoothing(0); | |
| if (location.hash) { const t = $(location.hash); if (t) setTimeout(() => lenis.scrollTo(t, { offset: -90, immediate: true }), 50); } | |
| } | |
| // home hero intro | |
| if ($('.hero-title')) { | |
| gsap.timeline({ defaults: { ease: 'expo.out' }, delay: .15 }) | |
| .to('.hero-title .word', { y: 0, duration: 1.3, stagger: .1 }) | |
| .to('.hero-fade', { opacity: 1, y: 0, duration: 1, stagger: .08 }, '-=1'); | |
| gsap.to('.hero-inner', { yPercent: -18, opacity: .3, ease: 'none', scrollTrigger: { trigger: '.hero', start: 'top top', end: 'bottom top', scrub: true } }); | |
| } | |
| // grids reveal with stagger, everything else individually | |
| const gridSel = '.services-grid, .team-grid, .stats, .work-grid, .team-strip, .models, .values, .next-steps, .case-metrics, .process, .commitments, .industries, .articles, .practices, .faq, .offers'; | |
| const inGrid = new Set(); | |
| $$(gridSel).forEach((g) => { | |
| const kids = $$(':scope > .reveal', g); | |
| kids.forEach((k) => inGrid.add(k)); | |
| ScrollTrigger.batch(kids, { start: 'top 90%', once: true, onEnter: (b) => gsap.to(b, { opacity: 1, y: 0, duration: .9, stagger: .08, ease: 'power3.out', overwrite: true }) }); | |
| }); | |
| $$('.reveal').filter((el) => !inGrid.has(el)).forEach((el) => { | |
| gsap.to(el, { opacity: 1, y: 0, duration: 1, ease: 'power3.out', scrollTrigger: { trigger: el, start: 'top 92%', once: true } }); | |
| }); | |
| $$('.count').forEach((el) => ScrollTrigger.create({ trigger: el, start: 'top 92%', once: true, onEnter: () => runCounter(el) })); | |
| if (player) gsap.fromTo(player, { scale: .92, rotateX: 10, transformPerspective: 1400 }, | |
| { scale: 1, rotateX: 0, ease: 'none', scrollTrigger: { trigger: player, start: 'top 95%', end: 'top 40%', scrub: true } }); | |
| if ($('#processFill')) gsap.to('#processFill', { scaleX: 1, ease: 'none', scrollTrigger: { trigger: '.process', start: 'top 80%', end: 'bottom 60%', scrub: true } }); | |
| if ($('.case-visual')) gsap.fromTo('.case-visual canvas', { scale: 1.12 }, { scale: 1, ease: 'none', scrollTrigger: { trigger: '.case-visual', start: 'top bottom', end: 'bottom top', scrub: true } }); | |
| window.addEventListener('load', () => ScrollTrigger.refresh()); | |
| })(); | |