The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix(kb): hero mobile + fixtures (#52180)
Anthony Lioe7e0c7709ec4
diff --git a/apps/kb/src/components/AsciiCanvas.tsx b/apps/kb/src/components/AsciiCanvas.tsxdeleted file mode 100644index 13447e0c97a..00000000000--- a/apps/kb/src/components/AsciiCanvas.tsx+++ /dev/null@@ -1,370 +0,0 @@-import { useCallback, type RefObject } from 'react'-import { cn } from 'ui'--import {- BLOCK_GLYPHS,- buildMask,- cellRange,- createRng,- decayEnergy,- drawStep,- GLYPH_PITCH,- glyphRun,- latticeSize,- phase,- snapRect,- type Lattice,- type PixelRect,-} from '../lib/ascii/field'-import { loadGrain, punchGrain } from '../lib/ascii/grain'-import { sizeLayers } from '../lib/ascii/layer'-import { easeOutCubic } from '../lib/ascii/warp'-import { ColorProbes, observeTheme, readProbeColor } from './ColorProbes'--export interface CanvasSize {- width: number- height: number-}--interface FieldParams {- lattice: Lattice- seed: number- mask: Uint8Array-}--export interface AsciiCanvasProps {- getLattice: (size: CanvasSize) => Lattice- getField: (params: FieldParams) => Float32Array- keepOutRefs?: RefObject<HTMLElement | null>[]- keepOutMargin?: number- words?: string[]- decay?: number- className?: string-}--interface RunParams {- index: number- quantized: number- capacity: number-}--interface IngestedWord {- word: string- startedAt: number-}--interface VisibleLettersParams {- ingest: IngestedWord- now: number-}--interface Palette {- background: string- grid: string- muted: string- hot: string-}--const CELL_PADDING = 8-const DENSITY_STEPS = 8-const TYPE_SPAN = 0.2-const LETTER_STEP_MS = 90-const LETTER_SCRAMBLE_MS = 240--const PROBES = {- grid: 'text-border-muted',- muted: 'text-foreground-muted',- hot: 'text-foreground-lighter',- background: 'text-background',-} as const--// knuth hash gives each cell a stable random start, capped so the last cell finishes with the reveal-const revealOrder = (index: number) =>- ((Math.imul(index + 1, 2654435761) >>> 0) / 2 ** 32) * (1 - TYPE_SPAN)--const visibleLetters = ({ ingest, now }: VisibleLettersParams) => {- const { word, startedAt } = ingest- const heldUntil = word.length * LETTER_STEP_MS + LETTER_SCRAMBLE_MS + 900- return word.length - Math.max(0, Math.floor((now - startedAt - heldUntil) / LETTER_STEP_MS))-}--const readPalette = (probeRoot: HTMLElement, host: HTMLElement): Palette => {- const hostBackground = getComputedStyle(host).backgroundColor- const read = (role: keyof typeof PROBES) => readProbeColor(probeRoot, role)- return {- background:- hostBackground === 'transparent' || hostBackground.endsWith(', 0)')- ? read('background')- : hostBackground,- grid: read('grid'),- muted: read('muted'),- hot: read('hot'),- }-}--const relativeRect = (element: HTMLElement, origin: DOMRect): PixelRect => {- const rect = element.getBoundingClientRect()- return {- left: rect.left - origin.left,- top: rect.top - origin.top,- right: rect.right - origin.left,- bottom: rect.bottom - origin.top,- }-}--export const AsciiCanvas = ({- getLattice,- getField,- keepOutRefs = [],- keepOutMargin = 1,- words = [],- decay = 0.92,- className,-}: AsciiCanvasProps) => {- const setupCanvas = useCallback((canvas: HTMLCanvasElement | null) => {- const host = canvas?.parentElement- const ctx = canvas?.getContext('2d')- if (!canvas || !host || !ctx) return-- const isReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches- const seed = Math.floor(Math.random() * 2 ** 31)- const probeRoot = canvas.nextElementSibling- if (!(probeRoot instanceof HTMLElement)) return-- let grain: CanvasPattern | null = null- loadGrain(ctx).then((pattern) => {- grain = pattern- draw()- })- let palette = readPalette(probeRoot, host)- let lattice: Lattice = { xs: [0], ys: [0] }- let base: Float32Array = new Float32Array(0)- let energy: Float32Array = new Float32Array(0)- let mask: Uint8Array = new Uint8Array(0)- let cutouts: PixelRect[] = []- let measuredKey = ''- let isDisposed = false- const runs = new Map<number, string>()- const ingested = new Map<number, IngestedWord>()- let isVisible = false- let frame = 0- const observed = new Set<HTMLElement>()- const revealStartedAt = performance.now()-- const isRunning = () => isVisible && document.visibilityState === 'visible'-- const revealProgress = () =>- isReducedMotion ? 1 : Math.min(1, (performance.now() - revealStartedAt) / 1000)-- const keepOutCell = (rect: PixelRect, margin: number) =>- snapRect({ lattice, rect: { ...rect, top: rect.top - 1 }, margin })-- const capacityAt = (c: number) =>- Math.max(1, Math.floor((lattice.xs[c + 1] - lattice.xs[c] - CELL_PADDING * 2) / GLYPH_PITCH))-- const getRun = ({ index, quantized, capacity }: RunParams) => {- const runKey = index * (DENSITY_STEPS + 1) + quantized- const cached = runs.get(runKey)- if (cached !== undefined) return cached- const run = glyphRun({- density: quantized / DENSITY_STEPS,- capacity,- rand: createRng(seed + index * 97 + quantized),- })- runs.set(runKey, run)- return run- }-- const draw = () => {- const { cols, rows } = latticeSize(lattice)- const { xs, ys } = lattice- const width = canvas.clientWidth- const height = canvas.clientHeight- const t = revealProgress()- const across = drawStep(phase({ t, start: 0, length: 0.5 }))- const down = drawStep(phase({ t, start: 0.25, length: 0.5 }))- const reveal = easeOutCubic(phase({ t, start: 0.4, length: 0.6 }))- ctx.clearRect(0, 0, width, height)-- ctx.strokeStyle = palette.grid- ctx.lineWidth = 1- ctx.beginPath()- for (let i = 1; i < lattice.xs.length - 1; i++) {- ctx.moveTo(Math.round(lattice.xs[i]) + 0.5, 0)- ctx.lineTo(Math.round(lattice.xs[i]) + 0.5, height * down)- }- for (let i = 1; i < lattice.ys.length - 1; i++) {- ctx.moveTo(0, Math.round(lattice.ys[i]) + 0.5)- ctx.lineTo(width * across, Math.round(lattice.ys[i]) + 0.5)- }- ctx.stroke()- if (grain) {- punchGrain({ ctx, pattern: grain, width, height })- }-- ctx.fillStyle = palette.background- for (const rect of cutouts) {- const cell = keepOutCell(rect, 0)- if (!cell) continue- const left = Math.round(cell.left) + 1- const top = Math.round(cell.top) + 1- ctx.fillRect(left, top, Math.round(cell.right) - left, Math.round(cell.bottom) - top)- }-- ctx.font = '12px ui-monospace, SFMono-Regular, Menlo, monospace'- ctx.textAlign = 'center'- ctx.textBaseline = 'middle'- const now = performance.now()- for (let r = 0; r < rows; r++) {- const cy = (ys[r] + ys[r + 1]) / 2- for (let c = 0; c < cols; c++) {- const index = r * cols + c- if (mask[index] || revealOrder(index) > reveal) continue- const density = Math.min(1, base[index] + energy[index])- const ingest = ingested.get(index)- if (density <= 0 && !ingest) continue- const cellWidth = xs[c + 1] - xs[c]- const capacity = capacityAt(c)- const run = getRun({ index, quantized: Math.round(density * DENSITY_STEPS), capacity })- const typed = Math.ceil(- Math.min(1, (reveal - revealOrder(index)) / TYPE_SPAN) * run.length- )- const runStart =- capacity === 1 ? xs[c] + cellWidth / 2 : xs[c] + CELL_PADDING + GLYPH_PITCH / 2- const runColor = energy[index] > 0.15 ? palette.hot : palette.muted- const shown = ingest ? visibleLetters({ ingest, now }) : 0- if (ingest && shown <= 0) ingested.delete(index)- if (ingest && shown > 0) {- const elapsed = now - ingest.startedAt- const wordStart = xs[c] + CELL_PADDING + GLYPH_PITCH / 2- ctx.fillStyle = palette.hot- for (let i = 0; i < shown; i++) {- const since = elapsed - i * LETTER_STEP_MS- if (since < 0) break- const char =- since < LETTER_SCRAMBLE_MS- ? BLOCK_GLYPHS[Math.floor(since / 70) % BLOCK_GLYPHS.length]- : ingest.word[i]- ctx.fillText(char, wordStart + i * GLYPH_PITCH, cy)- }- if (shown < ingest.word.length) {- ctx.fillStyle = runColor- for (let i = shown; i < typed; i++) {- ctx.fillText(run[i], runStart + i * GLYPH_PITCH, cy)- }- }- continue- }- ctx.fillStyle = runColor- for (let i = 0; i < typed; i++) ctx.fillText(run[i], runStart + i * GLYPH_PITCH, cy)- }- }- }-- const tick = () => {- frame = 0- draw()- const isHot = decayEnergy({ energy, factor: decay })- if ((isHot || ingested.size > 0 || revealProgress() < 1) && isRunning()) {- frame = requestAnimationFrame(tick)- }- }-- const wake = () => {- if (!frame && isRunning() && !isReducedMotion) frame = requestAnimationFrame(tick)- }-- const measure = () => {- if (isDisposed) return- const width = host.clientWidth- const height = host.clientHeight- const dpr = window.devicePixelRatio || 1- const origin = canvas.getBoundingClientRect()- const keepOuts = keepOutRefs.flatMap((ref) => (ref.current ? [ref.current] : []))- for (const element of keepOuts) {- if (observed.has(element)) continue- observed.add(element)- resizeObserver.observe(element)- }- const nextCutouts = keepOuts.map((element) => relativeRect(element, origin))- const key = JSON.stringify([width, height, dpr, nextCutouts])- if (key === measuredKey) return- measuredKey = key-- sizeLayers({ contexts: [ctx], width, height })- lattice = getLattice({ width, height })- cutouts = nextCutouts- runs.clear()- ingested.clear()- const safeAreas = cutouts.flatMap((rect) => keepOutCell(rect, keepOutMargin) ?? [])- mask = buildMask({ lattice, rects: safeAreas, margin: 0 })- base = getField({ lattice, seed, mask })- energy = new Float32Array(base.length)- draw()- }-- const typeWordAt = (event: PointerEvent) => {- if (isReducedMotion || energy.length === 0) return- const origin = canvas.getBoundingClientRect()- const x = event.clientX - origin.left- const y = event.clientY - origin.top- const point = { left: x, right: x + 1, top: y, bottom: y + 1 }- const cell = cellRange({ lattice, rect: point, margin: 0 })- if (!cell) return- const index = cell.r0 * latticeSize(lattice).cols + cell.c0- if (mask[index]) return- energy[index] = 0.9- const shownWords = new Set([...ingested.values()].map(({ word }) => word))- const fitting = words.filter((word) => word.length <= capacityAt(cell.c0))- const unseen = fitting.filter((word) => !shownWords.has(word))- const pool = unseen.length > 0 ? unseen : fitting- if (pool.length > 0) {- const word = pool[Math.floor(Math.random() * pool.length)]- ingested.set(index, { word, startedAt: performance.now() })- } else {- ingested.delete(index)- }- wake()- }-- const resizeObserver = new ResizeObserver(measure)- resizeObserver.observe(host)-- const intersectionObserver = new IntersectionObserver(([entry]) => {- isVisible = entry.isIntersecting- wake()- })- intersectionObserver.observe(canvas)-- const unobserveTheme = observeTheme(() => {- palette = readPalette(probeRoot, host)- draw()- })-- host.addEventListener('pointerdown', typeWordAt)- document.addEventListener('visibilitychange', wake)- document.fonts?.ready.then(measure)- if (!isReducedMotion) wake()-- return () => {- isDisposed = true- cancelAnimationFrame(frame)- resizeObserver.disconnect()- intersectionObserver.disconnect()- unobserveTheme()- host.removeEventListener('pointerdown', typeWordAt)- document.removeEventListener('visibilitychange', wake)- }- }, [])-- return (- <>- <canvas- ref={setupCanvas}- aria-hidden- className={cn('pointer-events-none absolute inset-0 size-full', className)}- />- <ColorProbes probes={PROBES} />- </>- )-}diff --git a/apps/kb/src/components/GuideBrowser.tsx b/apps/kb/src/components/GuideBrowser.tsxindex 173328d2d4d..5b6115efc1c 100644--- a/apps/kb/src/components/GuideBrowser.tsx+++ b/apps/kb/src/components/GuideBrowser.tsx@@ -253,7 +253,17 @@ const TopicTab = ({ topic }: TopicTabProps) => (value={toTabValue(topic)}className={cn('shrink-0 whitespace-nowrap rounded-md py-2 text-sm tracking-body transition-colors focus-inset',- 'relative z-1 data-[state=active]:shadow-none'+ 'relative z-1 data-[state=active]:shadow-none',+ // indicator set before hydration+ 'group-not-data-[tab-indicator-ready]/list:data-[state=active]:rounded-b-none',+ 'group-not-data-[tab-indicator-ready]/list:data-[state=active]:rounded-t-lg',+ 'group-not-data-[tab-indicator-ready]/list:data-[state=active]:bg-200',+ 'group-not-data-[tab-indicator-ready]/list:data-[state=active]:before:absolute',+ 'group-not-data-[tab-indicator-ready]/list:data-[state=active]:before:inset-0',+ 'group-not-data-[tab-indicator-ready]/list:data-[state=active]:before:rounded-t-lg',+ 'group-not-data-[tab-indicator-ready]/list:data-[state=active]:before:border',+ 'group-not-data-[tab-indicator-ready]/list:data-[state=active]:before:border-b-0',+ 'group-not-data-[tab-indicator-ready]/list:data-[state=active]:before:border-default')}><span className="block px-3">{topic ?? 'All'}</span>diff --git a/apps/kb/src/components/Hero.tsx b/apps/kb/src/components/Hero.tsxindex 7b1d276ab9e..2a116280239 100644--- a/apps/kb/src/components/Hero.tsx+++ b/apps/kb/src/components/Hero.tsx@@ -2,18 +2,7 @@ import { Search } from 'lucide-react'import { useCallback, useRef, useState, useSyncExternalStore, type ReactNode } from 'react'import { cn, KeyboardShortcut } from 'ui'-import {- alignedEdges,- CELL_HEIGHT,- CELL_WIDTH,- heroField,- uniformEdges,- type Lattice,-} from '../lib/ascii/field'-import type { GuideSummary } from '../lib/guides'import type { Topic } from '../lib/topics'-import { useQueryVariant } from '../lib/use-query-variant'-import { AsciiCanvas, type CanvasSize } from './AsciiCanvas'import { AsciiHoverText } from './AsciiHoverText'import { HeroGrid } from './HeroGrid'import { InfallText } from './InfallText'@@ -24,9 +13,8 @@ import { WarpCanvas } from './WarpCanvas'export interface HeroProps {title: stringdescription: string- guides: GuideSummary[]breadcrumb?: ReactNode- variant?: 'grid' | 'warp' | 'construction'+ variant?: 'warp' | 'construction'topic?: Topicchildren?: ReactNodeclassName?: string@@ -35,7 +23,6 @@ export interface HeroProps {export interface TopicHeroProps {topic: Topicdescription: string- guides: GuideSummary[]breadcrumb?: ReactNodeclassName?: string}@@ -49,7 +36,6 @@ interface HeroFlanksProps {}export interface HomeHeroProps {- guides: GuideSummary[]className?: string}@@ -64,19 +50,6 @@ const ACROSS = 'left-1/2 h-px w-screen -translate-x-1/2 bg-border'const UPRIGHT ='inset-y-0 w-px origin-top bg-linear-to-b from-border via-border via-70% to-transparent'-const getHeroLattice = ({ width, height }: CanvasSize): Lattice => {- const contentLeft = Math.max(0, (width - 1152) / 2) + 24- return {- xs: alignedEdges({- size: width,- start: contentLeft,- end: width - contentLeft,- target: CELL_WIDTH,- }),- ys: uniformEdges({ size: height, step: CELL_HEIGHT }),- }-}-const subscribeToNothing = () => () => {}const getIsMac = () => /Mac|iPhone|iPad/.test(navigator.userAgent)@@ -86,7 +59,6 @@ const getIsMacOnServer = () => falseexport const Hero = ({title,description,- guides,breadcrumb,variant = 'warp',topic,@@ -94,24 +66,13 @@ export const Hero = ({className,}: HeroProps) => {const isWarp = variant === 'warp'- const isGrid = variant === 'grid'const copyRef = useRef<HTMLDivElement>(null)- const ingestWords = [- ...new Set(- guides.flatMap((guide) =>- guide.title- .toLowerCase()- .split(/[^a-z0-9]+/)- .filter((word) => word.length >= 5)- )- ),- ]return (<sectionclassName={cn('relative isolate flex justify-center',- isWarp ? 'pt-39 pb-60' : 'pt-32.5 pb-26 max-sm:pt-19.5 max-sm:pb-19.5 lg:pb-40',+ isWarp ? 'pt-39 pb-60' : 'max-lg:py-10 max-lg:border-b lg:pt-32.5 lg:pb-40','overflow-hidden bg-background',className)}@@ -120,21 +81,17 @@ export const Hero = ({{variant === 'construction' ? (<CopyFramelines={[- { id: 'left', className: cn('right-[calc(50%+20rem)]', UPRIGHT, DRAW_OUT) },- { id: 'right', className: cn('left-[calc(50%+20rem)]', UPRIGHT, DRAW_OUT) },+ {+ id: 'left',+ className: cn('right-[calc(50%+20rem)] max-lg:hidden', UPRIGHT, DRAW_OUT),+ },+ {+ id: 'right',+ className: cn('left-[calc(50%+20rem)] max-lg:hidden', UPRIGHT, DRAW_OUT),+ },]}/>) : null}- {isGrid ? (- <AsciiCanvas- getLattice={getHeroLattice}- getField={heroField}- keepOutRefs={[copyRef]}- keepOutMargin={0}- words={ingestWords}- decay={0.985}- />- ) : null}<div className="relative z-10 w-full max-w-6xl px-6">{isWarp ? (<div@@ -153,6 +110,9 @@ export const Hero = ({isWarp ? 'py-16' : 'pt-12 pb-9.5')}>+ {variant === 'construction' && topic ? (+ <TopicShape topic={topic} className="grain-mask h-45 w-full lg:hidden" />+ ) : null}{breadcrumb}<h1 className="m-0 text-5xl tracking-display text-foreground sm:text-6xl">{isWarp ? (@@ -168,22 +128,15 @@ export const Hero = ({{variant === 'construction' && topic ? <HeroFlanks topic={topic} /> : null}</div></div>- {isGrid ? (- <div- aria-hidden- className="pointer-events-none absolute inset-x-0 bottom-0 h-1/3 bg-linear-to-b from-transparent to-background"- />- ) : null}</section>)}-export const HomeHero = ({ guides, className }: HomeHeroProps) => {+export const HomeHero = ({ className }: HomeHeroProps) => {return (<Herotitle="Knowledge base"description="In-depth guides, tutorials, troubleshooting, and explainers for best practices for Supabase"- guides={guides}className={className}><HeroSearch />@@ -191,32 +144,16 @@ export const HomeHero = ({ guides, className }: HomeHeroProps) => {)}-export const TopicHero = ({- topic,- description,- guides,- breadcrumb,- className,-}: TopicHeroProps) => {- // grid hero stays reachable with ?hero=grid, in case we go back to it- const variant = useQueryVariant({- key: 'hero',- options: ['construction', 'grid'],- fallback: 'construction',- })-- return (- <Hero- variant={variant}- topic={topic}- title={topic}- description={description}- guides={guides}- breadcrumb={breadcrumb}- className={className}- />- )-}+export const TopicHero = ({ topic, description, breadcrumb, className }: TopicHeroProps) => (+ <Hero+ variant="construction"+ topic={topic}+ title={topic}+ description={description}+ breadcrumb={breadcrumb}+ className={className}+ />+)const HeroFlanks = ({ topic }: HeroFlanksProps) => (<>@@ -235,7 +172,10 @@ const HeroFlanks = ({ topic }: HeroFlanksProps) => (<CopyFramelines={[{ id: 'top', className: cn('top-0', ACROSS, DRAW_OUT) },- { id: 'band', className: cn('-top-[calc(var(--spacing)*32.5/2)]', ACROSS, DRAW_OUT) },+ {+ id: 'band',+ className: cn('-top-[calc(var(--spacing)*32.5/2)] max-lg:hidden', ACROSS, DRAW_OUT),+ },{ id: 'bottom', className: cn('bottom-0', ACROSS, DRAW_OUT) },{id: 'stem',@@ -245,6 +185,7 @@ const HeroFlanks = ({ topic }: HeroFlanksProps) => (id: 'tail',className: cn('top-full left-1/2 h-40 w-px origin-top bg-linear-to-b from-border to-transparent',+ 'max-lg:bg-border max-lg:bg-none',DRAW_OUT),},@@ -258,7 +199,7 @@ const CopyFrame = ({ lines }: CopyFrameProps) =><spankey={id}aria-hidden- className={cn('grain-mask pointer-events-none absolute max-lg:hidden', className)}+ className={cn('grain-mask pointer-events-none absolute', className)}/>))diff --git a/apps/kb/src/lib/ascii/field.ts b/apps/kb/src/lib/ascii/field.tsindex e04f5b94eae..e818a4a1b0a 100644--- a/apps/kb/src/lib/ascii/field.ts+++ b/apps/kb/src/lib/ascii/field.ts@@ -1,8 +1,3 @@-export interface Lattice {- xs: number[]- ys: number[]-}-export interface PixelRect {left: numbertop: number@@ -10,43 +5,6 @@ export interface PixelRect {bottom: number}-interface CellRange {- c0: number- c1: number- r0: number- r1: number-}--interface CellRangeParams {- lattice: Lattice- rect: PixelRect- margin: number-}--interface BuildMaskParams {- lattice: Lattice- rects: PixelRect[]- margin?: number-}--interface AlignedEdgesParams {- size: number- start: number- end: number- target: number-}--interface GlyphRunParams {- density: number- capacity: number- rand: () => number-}--interface HeroFieldParams {- lattice: Lattice- seed: number-}-interface PhaseParams {t: numberstart: number@@ -60,14 +18,11 @@ interface BeamParams {}export const RAMP = [' ', '·', '░', '▒', '▓'] as const-export const BLOCK_GLYPHS = ['▓', '▒', '░'] as constexport const CELL_WIDTH = 120export const CELL_HEIGHT = 26export const GLYPH_PITCH = 12-const ENERGY_EPSILON = 0.01-const MIN_COLUMN = 60export const BEAM_ALPHA = 0.7export const hash = (a: number, b: number) => {@@ -81,139 +36,20 @@ export const rampGlyph = (density: number) =>export const isBeamAt = ({ col, row, now = 0 }: BeamParams) =>hash(col + row * 31, Math.floor(now / 600 + hash(row, col))) < 0.04-export const createRng = (seed: number): (() => number) => {- let state = seed >>> 0- return () => {- state = (state + 0x6d2b79f5) >>> 0- const mixed = Math.imul(state ^ (state >>> 15), state | 1)- const remixed = mixed ^ (mixed + Math.imul(mixed ^ (mixed >>> 7), mixed | 61))- return ((remixed ^ (remixed >>> 14)) >>> 0) / 4294967296- }-}-export const uniformEdges = ({ size, step }: { size: number; step: number }): number[] =>Array.from({ length: Math.ceil(Math.max(0, size) / step) + 1 }, (_, i) => i * step)-const roundEdge = (value: number) => Math.round(value * 100) / 100--export const alignedEdges = ({ size, start, end, target }: AlignedEdgesParams): number[] => {- const span = end - start- if (size <= 0 || span <= 0) return uniformEdges({ size, step: target })- const count = Math.max(1, Math.round(span / target))- const step = span / count- const inner = Array.from({ length: count + 1 }, (_, i) => roundEdge(start + i * step))-- if (inner[0] < MIN_COLUMN) inner.shift()- if (size - inner[inner.length - 1] < MIN_COLUMN) inner.pop()- return [0, ...inner, size]-}-export const fitEdges = ({ size, target }: { size: number; target: number }): number[] => {const count = size > 0 ? Math.max(1, Math.round(size / target)) : 0- return Array.from({ length: count + 1 }, (_, i) => roundEdge((i * size) / count || 0))+ return Array.from(+ { length: count + 1 },+ (_, i) => Math.round(((i * size) / count || 0) * 100) / 100+ )}-export const latticeSize = ({ xs, ys }: Lattice) => ({- cols: Math.max(0, xs.length - 1),- rows: Math.max(0, ys.length - 1),-})-export const clamp = (value: number, min: number, max: number) =>Math.min(max, Math.max(min, value))export const phase = ({ t, start, length }: PhaseParams) => clamp((t - start) / length, 0, 1)export const drawStep = (progress: number) => Math.floor(progress * 8) / 8--const firstIndexAtOrBefore = (edges: number[], value: number) => {- let index = 0- while (index < edges.length - 2 && edges[index + 1] <= value) index++- return index-}--const lastIndexAtOrAfter = (edges: number[], value: number) => {- let index = edges.length - 2- while (index > 0 && edges[index] >= value) index--- return index-}--export const cellRange = ({ lattice, rect, margin }: CellRangeParams): CellRange | null => {- const { xs, ys } = lattice- const { cols, rows } = latticeSize(lattice)- if (cols === 0 || rows === 0) return null- if (rect.right <= rect.left || rect.bottom <= rect.top) return null- if (- rect.right <= xs[0] ||- rect.left >= xs[cols] ||- rect.bottom <= ys[0] ||- rect.top >= ys[rows]- ) {- return null- }-- return {- c0: clamp(firstIndexAtOrBefore(xs, rect.left) - margin, 0, cols - 1),- c1: clamp(lastIndexAtOrAfter(xs, rect.right) + margin, 0, cols - 1),- r0: clamp(firstIndexAtOrBefore(ys, rect.top) - margin, 0, rows - 1),- r1: clamp(lastIndexAtOrAfter(ys, rect.bottom) + margin, 0, rows - 1),- }-}--export const snapRect = ({ lattice, rect, margin }: CellRangeParams): PixelRect | null => {- const range = cellRange({ lattice, rect, margin })- if (!range) return null- return {- left: lattice.xs[range.c0],- top: lattice.ys[range.r0],- right: lattice.xs[range.c1 + 1],- bottom: lattice.ys[range.r1 + 1],- }-}--export const buildMask = ({ lattice, rects, margin = 1 }: BuildMaskParams): Uint8Array => {- const { cols, rows } = latticeSize(lattice)- const mask = new Uint8Array(cols * rows)- for (const rect of rects) {- const range = cellRange({ lattice, rect, margin })- if (!range) continue- for (let r = range.r0; r <= range.r1; r++) {- for (let c = range.c0; c <= range.c1; c++) mask[r * cols + c] = 1- }- }- return mask-}--export const glyphRun = ({ density, capacity, rand }: GlyphRunParams): string => {- if (density <= 0 || capacity <= 0) return ''- const length = clamp(Math.round(capacity * density), 1, capacity)- return Array.from(- { length },- () =>- RAMP[Math.ceil(clamp(density + (rand() - 0.5) * 0.3, ENERGY_EPSILON, 1) * (RAMP.length - 1))]- ).join('')-}--export const decayEnergy = ({ energy, factor }: { energy: Float32Array; factor: number }) => {- let isHot = false- for (let i = 0; i < energy.length; i++) {- if (energy[i] === 0) continue- energy[i] = energy[i] * factor < ENERGY_EPSILON ? 0 : energy[i] * factor- if (energy[i] > 0) isHot = true- }- return isHot-}--export const heroField = ({ lattice, seed }: HeroFieldParams): Float32Array => {- const { cols, rows } = latticeSize(lattice)- const rand = createRng(seed)- const field = new Float32Array(cols * rows)- for (let c = 0; c < cols; c++) {- const level = rand()- const fillChance = (0.1 + 0.5 * level) / 10- for (let r = 0; r < rows; r++) {- if (rand() > fillChance) continue- field[r * cols + c] = clamp(level * 0.7 + rand() * 0.3, 0.1, 1)- }- }- return field-}diff --git a/apps/kb/src/lib/reveal.ts b/apps/kb/src/lib/reveal.tsindex 8e2d858cdf4..d7e095a8549 100644--- a/apps/kb/src/lib/reveal.ts+++ b/apps/kb/src/lib/reveal.ts@@ -26,7 +26,10 @@ export const bindRevealOnce = (element: HTMLElement | null) => {if (!entry?.isIntersecting) return// groups already in view on load wait for the hero instead of beating it in// the offset lets the hero canvas start drawing before on-screen groups reveal- if (isOnScreenAtLoad) element.style.setProperty('--reveal-offset', '300ms')+ // a reload keeps the scroll position, so the hero is out of view and there is nothing to wait for+ if (isOnScreenAtLoad && window.scrollY === 0) {+ element.style.setProperty('--reveal-offset', '300ms')+ }element.dataset.revealed = 'true'observer.disconnect()},diff --git a/apps/kb/src/lib/use-query-variant.ts b/apps/kb/src/lib/use-query-variant.tsdeleted file mode 100644index 23a4074f182..00000000000--- a/apps/kb/src/lib/use-query-variant.ts+++ /dev/null@@ -1,25 +0,0 @@-import { useSyncExternalStore } from 'react'--interface UseQueryVariantParams<T extends string> {- key: string- options: readonly T[]- fallback: T-}--const subscribeToHistory = (onChange: () => void) => {- window.addEventListener('popstate', onChange)- return () => window.removeEventListener('popstate', onChange)-}--export const useQueryVariant = <T extends string>({- key,- options,- fallback,-}: UseQueryVariantParams<T>): T => {- const value = useSyncExternalStore(- subscribeToHistory,- () => new URLSearchParams(window.location.search).get(key),- () => null- )- return options.find((option) => option === value) ?? fallback-}diff --git a/apps/kb/src/pages/index.astro b/apps/kb/src/pages/index.astroindex e8d0d14557b..e7f3e6604a2 100644--- a/apps/kb/src/pages/index.astro+++ b/apps/kb/src/pages/index.astro@@ -30,7 +30,7 @@ const featuredGuides = padFeatured({---<Layout description="In-depth guides, tutorials, troubleshooting, and explainers for best practices for Supabase">- <HomeHero client:load guides={[...summaries, ...troubleshooting]} />+ <HomeHero client:load /><div class="flex flex-col gap-20 pb-24 pt-16 sm:gap-24 sm:pt-20"><FeaturedSection client:load title="Featured topics" items={featuredTopics} /><FeaturedSection client:load title="Featured guides" items={featuredGuides} />diff --git a/apps/kb/src/pages/topics/[topic].astro b/apps/kb/src/pages/topics/[topic].astroindex c0bedbea2c9..47f08b5651f 100644--- a/apps/kb/src/pages/topics/[topic].astro+++ b/apps/kb/src/pages/topics/[topic].astro@@ -43,7 +43,7 @@ const jsonLd = breadcrumbListSchema([---<Layout title={topic} description={description} jsonLd={jsonLd}>- <TopicHero client:load topic={topic} description={description} guides={[...guides, ...troubleshooting, ...faqs]}>+ <TopicHero client:load topic={topic} description={description}><Breadcrumb slot="breadcrumb"><BreadcrumbList><BreadcrumbItem>