diff --git a/apps/docs/features/directives/CodeSample.client.tsx b/apps/docs/features/directives/CodeSample.client.tsx index 15d1360d455..059608b5386 100644 --- a/apps/docs/features/directives/CodeSample.client.tsx +++ b/apps/docs/features/directives/CodeSample.client.tsx @@ -1,7 +1,7 @@ 'use client' import Link from 'next/link' -import { type CSSProperties, type PropsWithChildren, type ReactNode } from 'react' +import { type PropsWithChildren, type ReactNode } from 'react' import { cn, DropdownMenu, @@ -11,7 +11,8 @@ import { IconGitHubSolid, } from 'ui' import { Admonition } from 'ui-patterns/Admonition' -import { getNotchFocusRing, getNotchMask, getNotchOutline } from 'ui-patterns/Notch' +import { getNotchFocusRing, getNotchStyle } from 'ui-patterns/Notch' +import { NotchOutline } from 'ui-patterns/Notch/NotchOutline' interface CodeSampleWrapperProps { source: string | URL | (string | URL)[] @@ -31,7 +32,7 @@ interface SourceFrameProps { } export const SOURCE_FOOTER_CLASSES = cn( - 'not-prose absolute right-0 bottom-0 z-1 flex h-8 w-(--source-notch-width) items-center gap-2 px-3 whitespace-nowrap', + 'not-prose absolute right-0 bottom-0 z-1 flex h-8 w-(--notch-width) items-center gap-2 px-3 whitespace-nowrap', 'text-xs text-foreground-lighter no-underline transition-colors hover:text-foreground', 'focus-inset rounded-md' ) @@ -127,37 +128,21 @@ export function SourceFrame({ footer, notchWidth = DEFAULT_NOTCH_WIDTH, }: PropsWithChildren) { - const outline = getNotchOutline(notchWidth) - const notchStyle = { - '--source-notch-width': `${notchWidth}px`, - '--source-notch-mask': getNotchMask(notchWidth), - '--source-notch-mask-width': `${notchWidth + 10}px`, - } as CSSProperties - return (
{children}
- - - + - + {footer}
) diff --git a/apps/docs/styles/code-block.css b/apps/docs/styles/code-block.css index 0b4701e209c..dcbd6ef3bfb 100644 --- a/apps/docs/styles/code-block.css +++ b/apps/docs/styles/code-block.css @@ -16,9 +16,5 @@ } .code-sample-source :is(.shiki, .code-sample-surface) { - mask: - linear-gradient(#000 0 0), - var(--source-notch-mask) right -2px bottom -2px / var(--source-notch-mask-width) 42px no-repeat; - mask-composite: exclude; - mask-clip: no-clip; + @apply notch-corner; } diff --git a/apps/docs/styles/globals.css b/apps/docs/styles/globals.css index dd4ba69e7e2..355c3cff1f4 100644 --- a/apps/docs/styles/globals.css +++ b/apps/docs/styles/globals.css @@ -2,6 +2,7 @@ @import 'config/inline-code.css'; @import 'ui-patterns/CodeBlock/code-block.css'; @import 'ui-patterns/Toc/toc-menu.css'; +@import 'ui-patterns/Notch/notch.css'; @import './code-block.css'; @import './reference.css'; @import 'docs-search/styles.css'; diff --git a/apps/kb/src/components/FeaturedSection.tsx b/apps/kb/src/components/FeaturedSection.tsx index 20b1f2db86e..44b3bc2ce1f 100644 --- a/apps/kb/src/components/FeaturedSection.tsx +++ b/apps/kb/src/components/FeaturedSection.tsx @@ -1,7 +1,8 @@ import { ArrowRight } from 'lucide-react' -import { useId, type CSSProperties } from 'react' +import { useId } from 'react' import { cn } from 'ui' -import { getNotchMask, getNotchOutline } from 'ui-patterns/Notch' +import { getNotchStyle } from 'ui-patterns/Notch' +import { NotchOutline } from 'ui-patterns/Notch/NotchOutline' import type { FeaturedItem } from '../lib/guides' import { bindRevealOnce, REVEAL_GROUP_CLASS, REVEAL_ITEM_CLASS, revealStyle } from '../lib/reveal' @@ -19,15 +20,8 @@ interface FeaturedCoverProps { hasDates: boolean } -type NotchStyle = CSSProperties & { '--notch-width': string; '--notch-mask': string } - const NOTCH_WIDTH = 40 -const NOTCH_STYLE: NotchStyle = { - '--notch-width': `${NOTCH_WIDTH}px`, - '--notch-mask': getNotchMask(NOTCH_WIDTH), -} - export const FeaturedSection = ({ title, items, className }: FeaturedSectionProps) => { const headingId = useId() const hasDates = items.some((item) => item.date) @@ -70,7 +64,7 @@ export const FeaturedSection = ({ title, items, className }: FeaturedSectionProp const FeaturedCover = ({ item, hasDates }: FeaturedCoverProps) => (
@@ -79,20 +73,14 @@ const FeaturedCover = ({ item, hasDates }: FeaturedCoverProps) => ( description={item.description} topics={item.topics} date={hasDates ? (item.date ?? '') : undefined} - className={cn('cover-notch', hasDates ? 'h-115.5' : 'h-107.5')} + className={cn('notch-corner shadow-none!', hasDates ? 'h-115.5' : 'h-107.5')} />
- - - - + string | Promise + downloads: PaneDownload[] + children: ReactNode + className?: string +} + +const NOTCH_WIDTH = 80 + +const ROW_HIGHLIGHT_TRANSITION = { type: 'tween', duration: 0.15, ease: [0.4, 0, 0.2, 1] } as const + +const MORPH_TRANSITION = { type: 'spring', duration: 0.4, bounce: 0 } as const + +const SNIPPET_HEIGHT = 24 + +// the snippets are known shapes, so they carry their docs token classes instead of loading shiki +const SNIPPET_FORMATS: { + value: string + label: string + language: string + toLines: (snippet: PaneSnippet) => CodeToken[][] +}[] = [ + { + value: 'html', + label: 'HTML', + language: 'html', + toLines: ({ src, alt, width, height }) => [ + [ + ['<', 's-p'], + ['img', 's-k'], + ], + ...Object.entries({ src, alt, width, height }).map(([name, value]): CodeToken[] => [ + [' ', undefined], + [name, 's-r'], + ['=', 's-p'], + [`"${value}"`, 's-s'], + ]), + [['/>', 's-p']], + ], + }, + { + value: 'markdown', + label: 'Markdown', + language: 'markdown', + toLines: ({ src, alt }) => [ + [ + ['![', 's-p'], + [alt, 's-s'], + ['](', 's-p'], + [src, 's-u'], + [')', 's-p'], + ], + ], + }, +] + +const GROUPS: { + id: BrandAsset['group'] + title: string + description: string + imageClassName: string +}[] = [ + { + id: 'icon', + title: 'Icon', + description: + 'The green symbol without lettering. Use it in small spaces, such as avatars, app icons, or a row of partner logos.', + imageClassName: 'h-24 w-auto', + }, + { + id: 'logo', + title: 'Wordmark', + description: + 'The symbol and the Supabase lettering together. Use it by default when there is space for the name.', + imageClassName: 'h-12 w-auto', + }, + { + id: 'one-color', + title: 'One-color wordmark', + description: + 'The wordmark in black or white. Use it when you can print only one color, or on top of a photo.', + imageClassName: 'h-12 w-auto', + }, +] + +const CANVAS_CAPTIONS: Record = { + light: 'Light', + dark: 'Dark', +} + +// the green is the color in the logo files. the grays come from the design system tokens in packages/ui/build/css +const COLORS: BrandColor[] = [ + { + name: 'Supabase green', + token: 'brand-default', + value: 'hsl(var(--brand-default))', + hex: '#3ECF8E', + rgb: 'rgb(62 207 142)', + hsl: 'hsl(153.1 60.2% 52.7%)', + oklch: 'oklch(76.2% 0.154 159.4)', + }, + { + name: 'Dark gray', + token: 'gray-dark-200', + value: 'hsl(var(--colors-gray-dark-200))', + hex: '#1C1C1C', + rgb: 'rgb(28 28 28)', + hsl: 'hsl(0 0% 11%)', + oklch: 'oklch(22.6% 0 0)', + }, + { + name: 'Light gray', + token: 'gray-light-200', + value: 'hsl(var(--colors-gray-light-200))', + hex: '#F8F8F8', + rgb: 'rgb(248 248 248)', + hsl: 'hsl(0 0% 97.3%)', + oklch: 'oklch(97.9% 0 0)', + }, +] + +const CONNECT_BUTTON_URL = + 'https://obuldanrptloktxcffvn.supabase.co/storage/v1/object/public/supabase-brand-assets/connect-supabase' + +const CONNECT_BUTTONS: { canvas: Canvas; svg: string; alt: string }[] = [ + { + canvas: 'light', + svg: `${CONNECT_BUTTON_URL}/connect-supabase-dark.svg`, + alt: 'Dark Connect Supabase button', + }, + { + canvas: 'dark', + svg: `${CONNECT_BUTTON_URL}/connect-supabase-light.svg`, + alt: 'Light Connect Supabase button', + }, +] + +// a failed fetch rejects, so copyToClipboard shows its error toast instead of copying the error page +const fetchText = (url: string) => + fetch(url).then((response) => { + if (!response.ok) throw new Error(`${response.status} ${url}`) + return response.text() + }) + +export const LogoGallery = ({ className }: LogoGalleryProps) => ( +
+ {GROUPS.map((group) => { + const assets = BRAND_ASSETS.filter((asset) => asset.group === group.id) + const panes = assets.flatMap((asset) => + asset.canvas === 'any' + ? (['light', 'dark'] satisfies Canvas[]).map((canvas) => ({ canvas, asset })) + : [{ canvas: asset.canvas, asset }] + ) + + return ( + + {panes.map(({ canvas, asset }) => ( + fetchText(asset.svg)} + downloads={[ + { href: asset.svg, label: '.svg' }, + { href: asset.png, label: '.png' }, + ]} + className={cn( + 'items-center justify-center p-10', + canvas === 'dark' ? 'bg-pane-dark' : 'bg-white' + )} + > + { + + ))} + + ) + })} + + + + + Use the Connect Supabase button to start the OAuth 2.0 flow in your{' '} + + Supabase integration + + . Do not use the button as a logo. + + } + > + {CONNECT_BUTTONS.map((button) => ( + fetchText(button.svg)} + downloads={[ + { href: button.svg, label: '.svg' }, + { href: `${CONNECT_BUTTON_URL}/connect-supabase.zip`, label: '.zip' }, + ]} + className={cn( + 'items-center justify-center p-10', + button.canvas === 'dark' ? 'bg-pane-dark' : 'bg-white' + )} + > + {button.alt} + + ))} + +
+) + +const AssetSection = ({ id, title, description, children }: AssetSectionProps) => ( +
+
+

{title}

+

{description}

+
+
{children}
+
+) + +const Pane = ({ + caption, + snippet, + assetName, + getCopyText, + downloads, + children, + className, +}: PaneProps) => { + const [isCopied, setIsCopied] = useState(false) + const [isCodeOpen, setIsCodeOpen] = useState(false) + + const handleCodeClick = () => setIsCodeOpen((isOpen) => !isOpen) + + // the ClipboardItem promise keeps a fetched copy inside the user gesture in safari. + // the canvas copies on click, and the copy button below is the keyboard path to the same action + const handleCopy = () => { + copyToClipboard(Promise.resolve(getCopyText()), () => { + setIsCopied(true) + setTimeout(() => setIsCopied(false), 2000) + }) + } + + return ( +
+
+ +
+ + {isCodeOpen ? null : ( +
+
+ + +
+
+ {caption} +
+ + {downloads.map((download) => ( + + + Download {assetName} as + {download.label} + + ))} +
+
+
+ ) +} + +const ColorPalette = ({ colors }: { colors: BrandColor[] }) => { + const [copied, setCopied] = useState(null) + const [hoveredRow, setHoveredRow] = useState(null) + + // react batches the leave and the next enter, so the highlight still slides between rows + const handleRowLeave = () => setHoveredRow(null) + + const handleCopy = (key: string, value: string) => { + copyToClipboard(value, () => { + setCopied(key) + setTimeout(() => setCopied(null), 2000) + }) + } + + return ( + +
+ {colors.map((color) => ( +
+ +
+

{color.name}

+

{color.token}

+
+
div:hover]:before:opacity-0 [&>div:has(+div:hover)]:before:opacity-0' + )} + > + {hoveredRow?.startsWith(`${color.token}:`) ? null : ( + + )} + {[ + { label: 'HEX', value: color.hex }, + { label: 'RGB', value: color.rgb }, + { label: 'HSL', value: color.hsl }, + { label: 'OKLCH', value: color.oklch }, + ].map((format) => { + const key = `${color.token}:${format.label}` + const isCopied = copied === key + + return ( +
setHoveredRow(key)} + onPointerLeave={handleRowLeave} + className={cn( + 'group/row relative isolate flex items-center gap-3 px-3 py-1.5', + 'before:absolute before:inset-x-3 before:bottom-0 before:h-px before:transition-opacity', + 'not-last:before:bg-border' + )} + > + {hoveredRow === key ? ( + + ) : null} +
+ {format.label} +
+
+ {format.value} +
+ +
+ ) + })} +
+
+ ))} +
+
+ ) +} diff --git a/apps/www/components/BrandAssets/VectorLogo.tsx b/apps/www/components/BrandAssets/VectorLogo.tsx new file mode 100644 index 00000000000..cbdd25a796e --- /dev/null +++ b/apps/www/components/BrandAssets/VectorLogo.tsx @@ -0,0 +1,486 @@ +import { useId, useRef, useState, type MouseEvent, type PointerEvent } from 'react' +import { useClickAway } from 'react-use' +import { cn } from 'ui' +import { GlyphLines } from 'ui-patterns/GlyphLines' + +import { + COLUMNS, + fromHandleView, + INITIAL_SHAPES, + LETTER_PATHS, + offsetPoint, + ROWS, + SLANT, + SLANT_ORIGINS, + SYMBOL_HEIGHT, + SYMBOL_OUTLINE, + SYMBOL_WIDTH, + toHandleView, + toPathData, + WORDMARK_COLUMNS, + WORDMARK_ROWS, + WORDMARK_WIDTH, + type PathNode, + type Point, +} from './logo-geometry' + +export interface VectorLogoProps { + guideText: string + className?: string +} + +type DragTarget = (typeof DRAG_TARGETS)[number] + +interface NodeRef { + shape: number + subpath: number + node: number +} + +// gradientId names the overlay gradient, and the drop shadow filter is `${gradientId}-shadow` +interface RaisedPathsProps { + paths: { key: string; d: string }[] + gradientId: string +} + +interface Drag { + ref: NodeRef + target: DragTarget + start: Point + node: PathNode +} + +// px per symbol unit. the viewBox draws 1:1, so a 1 unit stroke stays 1px at any scale +const SCALE = 1.1 +const PADDING = 24 +// a guide runs this far from the symbol. it must pass every edge of the hero +const REACH = 2400 +const HATCH_SPACING = 6 +const MORPH_TRANSITION = + 'transition-[transform,opacity] duration-500 ease-out motion-reduce:transition-none' + +const DRAG_TARGETS = ['point', 'in', 'out'] as const + +const getAnchorSize = (shapeIndex: number) => (shapeIndex === 0 ? 7 : 5) + +// lines draw in order, and undraw in reverse after the fill fades out +const getDrawDelay = ({ + index, + count, + isDrawn, +}: { + index: number + count: number + isDrawn: boolean +}) => (isDrawn ? index * 60 : 300 + (count - 1 - index) * 60) + +export const VectorLogo = ({ guideText, className }: VectorLogoProps) => { + const [mode, setMode] = useState<'icon' | 'wordmark'>('icon') + const [shapes, setShapes] = useState(INITIAL_SHAPES) + const [selected, setSelected] = useState(null) + const dragRef = useRef(null) + const canvasRef = useRef(null) + // the guide lines have no stroke. GlyphLines draws them, and marks the svg ready so the draw-in waits for hydration + const guidesRef = useRef(null) + const gradientId = useId() + const hatchId = useId() + const isWordmark = mode === 'wordmark' + const subjectWidth = isWordmark ? WORDMARK_WIDTH : SYMBOL_WIDTH + const width = WORDMARK_WIDTH * SCALE + PADDING * 2 + const height = SYMBOL_HEIGHT * SCALE + PADDING * 2 + const toView = (value: number) => value * SCALE + PADDING + const shiftStyle = { + transform: `translateX(${((WORDMARK_WIDTH - subjectWidth) / 2) * SCALE}px)`, + } + const contentTransform = `translate(${PADDING} ${PADDING}) scale(${SCALE})` + const [symbolShape, ...letterShapes] = shapes + const symbolPath = toPathData(symbolShape) + const letterPaths = letterShapes.map(toPathData) + const isShapeShown = (shapeIndex: number) => shapeIndex === 0 || isWordmark + const selectedNode = + selected && isShapeShown(selected.shape) + ? shapes[selected.shape][selected.subpath][selected.node] + : null + const handleViews = selectedNode + ? (['in', 'out'] as const).flatMap((target) => { + const handle = selectedNode[target] + return handle + ? [{ target, view: toHandleView({ anchor: selectedNode.point, handle, scale: SCALE }) }] + : [] + }) + : [] + const slantLength = Math.hypot(SLANT.dx, SLANT.dy) + const guides = [ + ...ROWS.map((y) => [-REACH, toView(y), REACH, toView(y)]), + ...COLUMNS.map((x) => [toView(x), -REACH, toView(x), REACH]), + ...SLANT_ORIGINS.map(([x, y]) => { + const dx = (SLANT.dx / slantLength) * REACH + const dy = (SLANT.dy / slantLength) * REACH + return [toView(x) - dx, toView(y) - dy, toView(x) + dx, toView(y) + dy] + }), + ] + + const wordmarkGuides = [ + ...WORDMARK_ROWS.map((y) => [-REACH, toView(y), REACH, toView(y)]), + ...WORDMARK_COLUMNS.map((x) => [toView(x), -REACH, toView(x), REACH]), + ] + + const svgProps = { + width, + height, + viewBox: `0 0 ${width} ${height}`, + fill: 'none', + } + + const handleCanvasPointerDown = () => setSelected(null) + + const handleLogoClick = () => setMode(isWordmark ? 'icon' : 'wordmark') + + useClickAway(canvasRef, () => setSelected(null)) + + // every point carries its place in data attributes, so one handler serves all of them + const handlePointPointerDown = (event: PointerEvent) => { + if (event.button !== 0) return + event.stopPropagation() + const { dataset } = event.currentTarget + const ref = { + shape: Number(dataset.shape), + subpath: Number(dataset.subpath), + node: Number(dataset.node), + } + const target = DRAG_TARGETS.find((value) => value === dataset.target) ?? 'point' + event.currentTarget.setPointerCapture(event.pointerId) + dragRef.current = { + ref, + target, + start: [event.clientX, event.clientY], + node: shapes[ref.shape][ref.subpath][ref.node], + } + if (target === 'point') setSelected(ref) + } + + const handlePointPointerMove = (event: PointerEvent) => { + const drag = dragRef.current + if (!drag) return + const { node, target } = drag + const dx = (event.clientX - drag.start[0]) / SCALE + const dy = (event.clientY - drag.start[1]) / SCALE + const handle = target === 'point' ? undefined : node[target] + const moved = handle + ? { + ...node, + [target]: fromHandleView({ + anchor: node.point, + view: + offsetPoint({ + point: toHandleView({ anchor: node.point, handle, scale: SCALE }), + dx, + dy, + }) ?? handle, + scale: SCALE, + }), + } + : { + id: node.id, + point: [node.point[0] + dx, node.point[1] + dy] satisfies Point, + in: offsetPoint({ point: node.in, dx, dy }), + out: offsetPoint({ point: node.out, dx, dy }), + } + setShapes((current) => { + const next = structuredClone(current) + next[drag.ref.shape][drag.ref.subpath][drag.ref.node] = moved + return next + }) + } + + // capture also ends on pointerup, and on a cancelled touch that sends no pointerup + const handlePointDragEnd = () => { + dragRef.current = null + } + + const handlePointDoubleClick = (event: MouseEvent) => { + const { dataset } = event.currentTarget + const shape = Number(dataset.shape) + const subpath = Number(dataset.subpath) + const node = Number(dataset.node) + setShapes((current) => { + const next = structuredClone(current) + next[shape][subpath][node] = INITIAL_SHAPES[shape][subpath][node] + return next + }) + } + + return ( +
+ +
+ + + + + + + + + + + + + + + {guides.map(([x1, y1, x2, y2], index) => ( + + ))} + {wordmarkGuides.map(([x1, y1, x2, y2], index) => ( + + ))} + + +
+
+ + + + + + + + + + + + + + + + ({ key, d: letterPaths[index] }))} + gradientId={gradientId} + /> + + + + {LETTER_PATHS.map((key, index) => ( + + ))} + + + + + + {selected && selectedNode ? ( + + {handleViews.map(({ target, view }) => ( + + ))} + + ) : null} + + {shapes.map((shape, shapeIndex) => ( + 0 && MORPH_TRANSITION, + isShapeShown(shapeIndex) ? 'pointer-events-auto opacity-100' : 'opacity-0' + )} + > + {shape.map((nodes, subpathIndex) => + nodes.map((node, nodeIndex) => ( + + )) + )} + + ))} + + {selected && selectedNode ? ( + + {handleViews.map(({ target, view }) => ( + + ))} + + ) : null} + + +
+ {/* the drawing is aria-hidden, so a visually hidden button is the keyboard path to the same toggle */} + +
+ ) +} + +// muted is translucent, so an opaque base under it carries the drop shadow and keeps the guides from showing through +const RaisedPaths = ({ paths, gradientId }: RaisedPathsProps) => ( + <> + + {paths.map(({ key, d }) => ( + + ))} + + + {paths.map(({ key, d }) => ( + + ))} + + + {paths.map(({ key, d }) => ( + + ))} + + +) diff --git a/apps/www/components/BrandAssets/logo-geometry.ts b/apps/www/components/BrandAssets/logo-geometry.ts new file mode 100644 index 00000000000..a3814c2d46b --- /dev/null +++ b/apps/www/components/BrandAssets/logo-geometry.ts @@ -0,0 +1,166 @@ +export type Point = [number, number] + +export interface PathNode { + id: string + point: Point + in?: Point + out?: Point +} + +type Shape = PathNode[][] + +// the symbol box and the full wordmark width, in the units of the logo SVG files. the symbol sits at the same place in both +export const SYMBOL_WIDTH = 109 +export const SYMBOL_HEIGHT = 113 +export const WORDMARK_WIDTH = 581 + +export const ROWS = [0, 40.06, 56.2, 72.29, SYMBOL_HEIGHT] +export const COLUMNS = [0, 54.2, SYMBOL_WIDTH] +export const SLANT = { dx: 43.15, dy: -54.35 } +export const SLANT_ORIGINS = [ + [2.17, 56.42], + [106.86, 55.94], +] as const +// px added to every bezier handle on screen, so short corner handles stay visible and grabbable +const HANDLE_REACH = 24 + +// the outer edge of both symbol halves. the halves overlap on the middle spine, so one path avoids a double line +export const SYMBOL_OUTLINE = + 'M45.317 2.07103C48.1765 -1.53037 53.9745 0.442937 54.0434 5.041L54.27 40.0627H99.1935C107.384 40.0627 111.952 49.5228 106.859 55.9374L63.7076 110.284C60.8481 113.885 55.0502 111.912 54.9813 107.314L54.46 72.2922H9.83113C1.64038 72.2922 -2.92775 62.8321 2.1655 56.4175L45.317 2.07103Z' + +// the supabase lettering, from supabase-logo-green-black-transparent.svg +export const LETTER_PATHS = [ + 'M151.397 66.7608C151.996 72.3621 157.091 81.9642 171.877 81.9642C184.764 81.9642 190.959 73.7624 190.959 65.7607C190.959 58.559 186.063 52.6577 176.373 50.6571L169.379 49.1569C166.682 48.6568 164.884 47.1565 164.884 44.7559C164.884 41.9552 167.681 39.8549 171.178 39.8549C176.772 39.8549 178.87 43.5556 179.27 46.4564L190.359 43.9558C189.76 38.6546 185.064 29.7527 171.078 29.7527C160.488 29.7527 152.696 37.0543 152.696 45.8561C152.696 52.7576 156.991 58.4591 166.482 60.5594L172.976 62.0598C176.772 62.8599 178.271 64.6605 178.271 66.8609C178.271 69.4615 176.173 71.762 171.777 71.762C165.983 71.762 163.085 68.1611 162.786 64.2602L151.397 66.7608Z', + 'M233.421 80.4639H246.109C245.909 78.7635 245.609 75.3628 245.609 71.5618V31.2529H232.321V59.8592C232.321 65.5606 228.925 69.5614 223.031 69.5614C216.837 69.5614 214.039 65.1604 214.039 59.6592V31.2529H200.752V62.3599C200.752 73.0622 207.545 81.7642 219.434 81.7642C224.628 81.7642 230.325 79.7638 233.022 75.1627C233.022 77.1631 233.221 79.4636 233.421 80.4639Z', + 'M273.076 99.4682V75.663C275.473 78.9636 280.469 81.6644 287.263 81.6644C301.149 81.6644 310.439 70.6617 310.439 55.7584C310.439 41.1553 302.148 30.1528 287.762 30.1528C280.37 30.1528 274.875 33.4534 272.677 37.2544V31.253H259.79V99.4682H273.076ZM297.352 55.8585C297.352 64.6606 291.958 69.7616 285.164 69.7616C278.372 69.7616 272.877 64.5605 272.877 55.8585C272.877 47.1566 278.372 42.0554 285.164 42.0554C291.958 42.0554 297.352 47.1566 297.352 55.8585Z', + 'M317.964 67.0609C317.964 74.7627 324.357 81.8643 334.848 81.8643C342.139 81.8643 346.835 78.4634 349.332 74.5625C349.332 76.463 349.532 79.1635 349.832 80.4639H362.02C361.72 78.7635 361.422 75.2627 361.422 72.6622V48.4567C361.422 38.5545 355.627 29.7527 340.043 29.7527C326.855 29.7527 319.761 38.2544 318.963 45.9562L330.751 48.4567C331.151 44.1558 334.348 40.455 340.141 40.455C345.737 40.455 348.434 43.3556 348.434 46.8564C348.434 48.5568 347.536 49.9572 344.738 50.3572L332.65 52.1576C324.458 53.3579 317.964 58.2589 317.964 67.0609ZM337.644 71.962C333.349 71.962 331.25 69.1614 331.25 66.2608C331.25 62.4599 333.947 60.5594 337.345 60.0594L348.434 58.359V60.5594C348.434 69.2615 343.239 71.962 337.644 71.962Z', + 'M387.703 80.4641V74.4627C390.299 78.6637 395.494 81.6644 402.288 81.6644C416.276 81.6644 425.467 70.5618 425.467 55.6585C425.467 41.0552 417.174 29.9528 402.788 29.9528C395.494 29.9528 390.1 33.1535 387.902 36.6541V8.04785H374.815V80.4641H387.703ZM412.178 55.7584C412.178 64.7605 406.784 69.7616 399.99 69.7616C393.297 69.7616 387.703 64.6606 387.703 55.7584C387.703 46.7564 393.297 41.8554 399.99 41.8554C406.784 41.8554 412.178 46.7564 412.178 55.7584Z', + 'M432.99 67.0609C432.99 74.7627 439.383 81.8643 449.873 81.8643C457.165 81.8643 461.862 78.4634 464.358 74.5625C464.358 76.463 464.559 79.1635 464.858 80.4639H477.046C476.748 78.7635 476.448 75.2627 476.448 72.6622V48.4567C476.448 38.5545 470.653 29.7527 455.068 29.7527C441.881 29.7527 434.788 38.2544 433.989 45.9562L445.776 48.4567C446.177 44.1558 449.374 40.455 455.167 40.455C460.763 40.455 463.46 43.3556 463.46 46.8564C463.46 48.5568 462.561 49.9572 459.763 50.3572L447.676 52.1576C439.484 53.3579 432.99 58.2589 432.99 67.0609ZM452.671 71.962C448.375 71.962 446.276 69.1614 446.276 66.2608C446.276 62.4599 448.973 60.5594 452.371 60.0594L463.46 58.359V60.5594C463.46 69.2615 458.265 71.962 452.671 71.962Z', + 'M485.645 66.7608C486.243 72.3621 491.339 81.9642 506.124 81.9642C519.012 81.9642 525.205 73.7624 525.205 65.7607C525.205 58.559 520.311 52.6577 510.62 50.6571L503.626 49.1569C500.929 48.6568 499.132 47.1565 499.132 44.7559C499.132 41.9552 501.928 39.8549 505.425 39.8549C511.021 39.8549 513.118 43.5556 513.519 46.4564L524.607 43.9558C524.007 38.6546 519.312 29.7527 505.326 29.7527C494.735 29.7527 486.944 37.0543 486.944 45.8561C486.944 52.7576 491.238 58.4591 500.73 60.5594L507.224 62.0598C511.021 62.8599 512.519 64.6605 512.519 66.8609C512.519 69.4615 510.421 71.762 506.025 71.762C500.23 71.762 497.334 68.1611 497.034 64.2602L485.645 66.7608Z', + 'M545.385 50.2571C545.685 45.7562 549.482 40.5549 556.375 40.5549C563.967 40.5549 567.165 45.3561 567.365 50.2571H545.385ZM568.664 63.0601C567.065 67.4609 563.668 70.5617 557.474 70.5617C550.88 70.5617 545.385 65.8606 545.087 59.3593H580.252C580.252 59.159 580.451 57.1587 580.451 55.2582C580.451 39.4547 571.361 29.7527 556.175 29.7527C543.588 29.7527 531.998 39.9548 531.998 55.6584C531.998 72.262 543.886 81.9642 557.374 81.9642C569.462 81.9642 577.255 74.8626 579.753 66.3607L568.664 63.0601Z', +] + +// reads paths that use only absolute M, L, H, V, C and Z commands +const toShape = (path: string): Shape => { + const tokens = path.match(/[MLHVCZ]|-?(?:\d+\.?\d*|\.\d+)/g) ?? [] + const read = (index: number) => Number(tokens[index]) + const subpaths: Shape = [] + let nodes: PathNode[] = [] + let index = 0 + let command = '' + let x = 0 + let y = 0 + + while (index < tokens.length) { + if (/[MLHVCZ]/.test(tokens[index])) command = tokens[index++] + if (command === 'Z') { + subpaths.push(toClosedSubpath(nodes)) + nodes = [] + continue + } + if (command === 'C') { + nodes[nodes.length - 1].out = [read(index), read(index + 1)] + x = read(index + 4) + y = read(index + 5) + nodes.push({ id: `${x}:${y}`, point: [x, y], in: [read(index + 2), read(index + 3)] }) + index += 6 + continue + } + if (command === 'M' || command === 'L') { + x = read(index) + y = read(index + 1) + index += 2 + } else if (command === 'H') { + x = read(index++) + } else if (command === 'V') { + y = read(index++) + } + nodes.push({ id: `${x}:${y}`, point: [x, y] }) + } + + return subpaths +} + +// a subpath that ends on its start point closes with that last segment, so the end node merges into the start node +const toClosedSubpath = (nodes: PathNode[]): PathNode[] => { + const first = nodes[0] + const last = nodes[nodes.length - 1] + const isOnStart = + Math.hypot(first.point[0] - last.point[0], first.point[1] - last.point[1]) < 0.01 + if (nodes.length < 2 || !isOnStart) return nodes + return [{ ...first, in: last.in }, ...nodes.slice(1, -1)] +} + +const toCoords = ([x, y]: Point) => `${x} ${y}` + +export const toPathData = (shape: Shape) => + shape + .map((nodes) => { + const segments = nodes.map((from, index) => { + const to = nodes[(index + 1) % nodes.length] + return from.out || to.in + ? `C${toCoords(from.out ?? from.point)} ${toCoords(to.in ?? to.point)} ${toCoords(to.point)}` + : `L${toCoords(to.point)}` + }) + return `M${toCoords(nodes[0].point)}${segments.join('')}Z` + }) + .join('') + +export const offsetPoint = ({ point, dx, dy }: { point?: Point; dx: number; dy: number }) => + point ? ([point[0] + dx, point[1] + dy] satisfies Point) : undefined + +export const toHandleView = ({ + anchor, + handle, + scale, +}: { + anchor: Point + handle: Point + scale: number +}): Point => { + const length = Math.hypot(handle[0] - anchor[0], handle[1] - anchor[1]) * scale + if (!length) return handle + const stretch = (length + HANDLE_REACH) / length + return [ + anchor[0] + (handle[0] - anchor[0]) * stretch, + anchor[1] + (handle[1] - anchor[1]) * stretch, + ] +} + +// the inverse of toHandleView, so a dragged handle stays under the pointer +export const fromHandleView = ({ + anchor, + view, + scale, +}: { + anchor: Point + view: Point + scale: number +}): Point => { + const length = Math.hypot(view[0] - anchor[0], view[1] - anchor[1]) * scale + if (!length) return anchor + const shrink = Math.max(length - HANDLE_REACH, 0) / length + return [anchor[0] + (view[0] - anchor[0]) * shrink, anchor[1] + (view[1] - anchor[1]) * shrink] +} + +export const INITIAL_SHAPES = [SYMBOL_OUTLINE, ...LETTER_PATHS].map(toShape) + +const LETTER_BOUNDS = INITIAL_SHAPES.slice(1).map((shape) => { + const points = shape.flat().map((node) => node.point) + const xs = points.map(([x]) => x) + const ys = points.map(([, y]) => y) + return { + left: Math.min(...xs), + right: Math.max(...xs), + top: Math.min(...ys), + bottom: Math.max(...ys), + } +}) +// the s sits on the baseline and reaches the x-height. the b sets the ascender and the p the descender +export const WORDMARK_ROWS = [ + Math.min(...LETTER_BOUNDS.map(({ top }) => top)), + LETTER_BOUNDS[0].top, + LETTER_BOUNDS[0].bottom, + Math.max(...LETTER_BOUNDS.map(({ bottom }) => bottom)), +] +export const WORDMARK_COLUMNS = LETTER_BOUNDS.flatMap(({ left, right }) => [left, right]) diff --git a/apps/www/components/CrossfadeIcon.tsx b/apps/www/components/CrossfadeIcon.tsx new file mode 100644 index 00000000000..9a0fd2e8cf9 --- /dev/null +++ b/apps/www/components/CrossfadeIcon.tsx @@ -0,0 +1,49 @@ +import { useId, type ReactNode } from 'react' +import { cn } from 'ui' + +export interface CrossfadeIconProps { + isActive: boolean + activeIcon: ReactNode + inactiveIcon: ReactNode + className?: string +} + +const iconClassName = (isShown: boolean) => + cn( + 'absolute inset-0 flex items-center justify-center', + 'transition duration-300 ease-[cubic-bezier(0.2,0,0,1)]', + 'motion-reduce:transition-none', + isShown ? 'scale-100 opacity-100 blur-none' : 'scale-25 opacity-0 blur-xs' + ) + +export const CrossfadeIcon = ({ + isActive, + activeIcon, + inactiveIcon, + className, +}: CrossfadeIconProps) => ( + + {activeIcon} + {inactiveIcon} + +) + +export const CircleCheckFilled = ({ className }: { className?: string }) => { + const maskId = useId() + + return ( + + + + + + + + ) +} diff --git a/apps/www/components/Nav/RightClickBrandLogo.tsx b/apps/www/components/Nav/RightClickBrandLogo.tsx index 9b68079d75c..9e6ef80bd55 100644 --- a/apps/www/components/Nav/RightClickBrandLogo.tsx +++ b/apps/www/components/Nav/RightClickBrandLogo.tsx @@ -1,6 +1,8 @@ 'use client' -import { CheckIcon, ClipboardIcon } from '@heroicons/react/outline' +import { CircleCheckFilled, CrossfadeIcon } from '~/components/CrossfadeIcon' +import { Copy, Download } from 'lucide-react' +import { useTheme } from 'next-themes' import { useRouter } from 'next/compat/router' import Link from 'next/link' import { Fragment, MouseEvent, ReactNode, useEffect, useRef, useState } from 'react' @@ -24,7 +26,10 @@ const RightClickBrandLogo = () => { const ref = useRef(null) const router = useRouter() const [open, setOpen] = useState(false) - const [copied, setCopied] = useState(false) + const [copiedLabel, setCopiedLabel] = useState(null) + const copiedTimeoutRef = useRef>(undefined) + const [logoHighlight, setLogoHighlight] = useState() + const { resolvedTheme } = useTheme() /** * Close dropdown by clicking outside @@ -53,6 +58,7 @@ const RightClickBrandLogo = () => { e.preventDefault() if (e.type === 'contextmenu' || e.nativeEvent.button === 2) { + setLogoHighlight(undefined) setOpen(true) } } @@ -77,14 +83,35 @@ const RightClickBrandLogo = () => { * Copy to clipboard logo SVG */ const handleCopyToClipboard = (menuItem: MenuItemProps) => { - copyToClipboard(menuItem.clipboard ?? '', () => { - setCopied(true) - setTimeout(() => { - setCopied(false) - }, 2000) - }) + // the ClipboardItem promise keeps the fetched copy inside the user gesture in safari + // the copied file matches the nav logo, which follows the site theme + const clipboardUrl = + menuItem.clipboardUrls?.[resolvedTheme?.includes('dark') ? 'dark' : 'light'] + if (!clipboardUrl) return + copyToClipboard( + fetch(clipboardUrl).then((response) => { + if (!response.ok) throw new Error(`${response.status} ${clipboardUrl}`) + return response.text() + }), + () => { + setCopiedLabel(menuItem.label) + // an older timer would clear the newer feedback early + clearTimeout(copiedTimeoutRef.current) + copiedTimeoutRef.current = setTimeout(() => { + setCopiedLabel(null) + }, 2000) + } + ) } + const handleItemPointerEnter = (menuItem: MenuItemProps) => + setLogoHighlight(menuItem.logoHighlight) + + const handleMenuPointerLeave = () => setLogoHighlight(undefined) + + const isFrameVisible = open && logoHighlight !== undefined + const isFrameOnSymbol = logoHighlight !== 'wordmark' + return ( @@ -93,17 +120,33 @@ const RightClickBrandLogo = () => { onContextMenu={handleRightClick} onFocus={handleKeyboardOpen} onKeyDown={(e) => e.key === 'Enter' && router?.push('/')} - className="block w-auto h-6 focus-ring focus-visible:ring-offset-4 focus-visible:ring-offset-background-alternative rounded-xs" + className={cn( + 'relative isolate block w-auto h-6 box-content -mx-2 -my-3 px-2 py-3 focus-ring focus-visible:ring-offset-background-alternative rounded-md', + 'transition-colors duration-200 ease-out motion-reduce:transition-none', + isFrameVisible && isFrameOnSymbol && 'text-foreground-muted' + )} > + {menuItems.map((section, sectionIdx) => ( @@ -111,16 +154,16 @@ const RightClickBrandLogo = () => {
{section.map((menuItem, i) => ( handleItemPointerEnter(menuItem)} + className="w-full flex justify-between gap-2 items-center p-2! cursor-pointer" > {menuItem.type === 'download' || menuItem.type === 'link' ? ( @@ -129,10 +172,10 @@ const RightClickBrandLogo = () => { // DropdownMenuItem asChild manages roving tabIndex; don't override it. // eslint-disable-next-line supabase/require-explicit-tabindex -- in-menu item ) )} @@ -142,6 +185,9 @@ const RightClickBrandLogo = () => { ))} + + {copiedLabel ? 'Copied to clipboard' : ''} + ) } @@ -153,7 +199,8 @@ interface MenuItemProps { type: 'clipboard' | 'download' | 'link' icon?: ReactNode href?: string - clipboard?: string + clipboardUrls?: Record<'light' | 'dark', string> + logoHighlight?: 'icon' | 'wordmark' } /** @@ -164,7 +211,8 @@ interface MenuItemProps { const menuItems: MenuItemProps[][] = [ [ { - label: 'Copy logo as SVG', + label: 'Copy logo', + logoHighlight: 'icon', type: 'clipboard', icon: ( ), - clipboard: ` - - - - - - - - - - - - - - -`, + clipboardUrls: { + light: '/brand-assets/supabase-icon-green-transparent.svg', + dark: '/brand-assets/supabase-icon-green-transparent.svg', + }, + }, + { + label: 'Copy wordmark', + logoHighlight: 'wordmark', + type: 'clipboard', + icon: , + clipboardUrls: { + light: '/brand-assets/supabase-logo-green-black-transparent.svg', + dark: '/brand-assets/supabase-logo-green-white-transparent.svg', + }, }, { label: 'Download wordmark', type: 'download', - icon: ( - - - - - - ), + icon: , href: '/supabase-wordmark.zip', }, { label: 'Download brand assets', type: 'download', href: '/brand-assets.zip', - icon: ( - - - - - - ), + icon: , }, ], [ { - label: 'Brand Assets', + label: 'Go to Brand Guidelines', type: 'link', - href: '/brand-assets', + href: '/brand', }, ], ] interface MenuItemContentProps { icon?: ReactNode - type: string label: string copied?: boolean } @@ -289,28 +274,23 @@ interface MenuItemContentProps { /** * MenuItem content */ -const MenuItemContent = ({ icon, type, label, copied }: MenuItemContentProps) => ( +const MenuItemContent = ({ icon, label, copied }: MenuItemContentProps) => ( <> - {icon && {icon}} - {label} - {type === 'clipboard' && ( - - {!copied ? ( - + {icon && ( + + {copied === undefined ? ( + icon ) : ( - } + inactiveIcon={icon} + className="size-4" /> )} )} + {label} ) diff --git a/apps/www/content/md/brand.md b/apps/www/content/md/brand.md new file mode 100644 index 00000000000..532bfababc1 --- /dev/null +++ b/apps/www/content/md/brand.md @@ -0,0 +1,50 @@ +# Supabase Brand Guidelines + +> Official Supabase logos and colors, as SVG and PNG files for light and dark backgrounds. + +## Which file to use + +- Choose the file for the background where the logo appears, not for your browser or editor theme. +- If a request asks for "the Supabase logo", use the wordmark with black lettering on a light background. +- On a dark background, use the wordmark with white lettering. +- In small spaces or next to other brand icons, use the green icon. +- If you can print only one color, use the black or white one-color wordmark. +- All files have a transparent background. +- There is no file with the lettering alone. Every wordmark file includes the symbol. + +## Files + +The table lists each logo file and where to use it. + +| Asset | Artwork | Use on | SVG | PNG | +| ------------------------------ | -------------------------------------------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------- | +| Wordmark for light backgrounds | Green symbol and black lettering, transparent background | Light backgrounds | [supabase-logo-green-black-transparent.svg](https://supabase.com/brand-assets/supabase-logo-green-black-transparent.svg) | [PNG, 2322×449](https://supabase.com/brand-assets/supabase-logo-green-black-transparent.png) | +| Wordmark for dark backgrounds | Green symbol and white lettering, transparent background | Dark backgrounds | [supabase-logo-green-white-transparent.svg](https://supabase.com/brand-assets/supabase-logo-green-white-transparent.svg) | [PNG, 2322×449](https://supabase.com/brand-assets/supabase-logo-green-white-transparent.png) | +| Icon | Green symbol only, no lettering, transparent background | Light or dark backgrounds | [supabase-icon-green-transparent.svg](https://supabase.com/brand-assets/supabase-icon-green-transparent.svg) | [PNG, 436×449](https://supabase.com/brand-assets/supabase-icon-green-transparent.png) | +| One-color wordmark, black | Black symbol and lettering, transparent background | Light backgrounds | [supabase-logo-black-transparent.svg](https://supabase.com/brand-assets/supabase-logo-black-transparent.svg) | [PNG, 2000×389](https://supabase.com/brand-assets/supabase-logo-black-transparent.png) | +| One-color wordmark, white | White symbol and lettering, transparent background | Dark backgrounds | [supabase-logo-white-transparent.svg](https://supabase.com/brand-assets/supabase-logo-white-transparent.svg) | [PNG, 2000×389](https://supabase.com/brand-assets/supabase-logo-white-transparent.png) | + +## Colors + +Supabase green is the main color of the logo symbol. The grays are background colors from the [Supabase design system](https://supabase.com/design-system/docs/color-usage). The logo files already have the correct colors, so do not repaint the logo with these values. + +| Name | Token | HEX | RGB | HSL | OKLCH | +| -------------- | ---------------- | --------- | ------------------ | ------------------------ | -------------------------- | +| Supabase green | `brand-default` | `#3ECF8E` | `rgb(62 207 142)` | `hsl(153.1 60.2% 52.7%)` | `oklch(76.2% 0.154 159.4)` | +| Dark gray | `gray-dark-200` | `#1C1C1C` | `rgb(28 28 28)` | `hsl(0 0% 11%)` | `oklch(22.6% 0 0)` | +| Light gray | `gray-light-200` | `#F8F8F8` | `rgb(248 248 248)` | `hsl(0 0% 97.3%)` | `oklch(97.9% 0 0)` | + +## Downloads + +- [Logo kit (ZIP)](https://supabase.com/brand-assets.zip): the SVG and PNG files from the Files table. +- [Connect Supabase button kit (ZIP)](https://obuldanrptloktxcffvn.supabase.co/storage/v1/object/public/supabase-brand-assets/connect-supabase/connect-supabase.zip): the button that starts the OAuth 2.0 flow in a [Supabase integration](https://supabase.com/docs/guides/platform/oauth-apps/build-a-supabase-integration). Do not use the button as a logo. + +## Name + +Write Supabase as one word, with a capital S. Do not write SupaBase or Supa Base. + +## Usage + +Use the Supabase logos only to refer to Supabase. Do not change the files or the logo colors. + +Supabase and the Supabase logo are trademarks of Supabase Inc. diff --git a/apps/www/data/Footer.ts b/apps/www/data/Footer.ts index a9b51c6557d..cc4704ccfb1 100644 --- a/apps/www/data/Footer.ts +++ b/apps/www/data/Footer.ts @@ -109,8 +109,8 @@ const footerData = [ url: '/kb/topics/faqs', }, { - text: 'Brand Assets', - url: '/brand-assets', + text: 'Brand Guidelines', + url: '/brand', }, { text: 'Security & Compliance', diff --git a/apps/www/data/brand-assets.test.ts b/apps/www/data/brand-assets.test.ts new file mode 100644 index 00000000000..071eff0612f --- /dev/null +++ b/apps/www/data/brand-assets.test.ts @@ -0,0 +1,24 @@ +import { readFileSync } from 'node:fs' +import path from 'node:path' +import { describe, expect, it } from 'vitest' + +import { BRAND_ASSETS } from './brand-assets' + +const publicFile = (url: string) => readFileSync(path.join(process.cwd(), 'public', url)) + +describe('brand assets catalog', () => { + it.for(BRAND_ASSETS)('$id files match the catalog', (asset) => { + expect(publicFile(asset.svg).toString('utf-8')).toContain(' { + const markdown = readFileSync(path.join(process.cwd(), 'content/md/brand.md'), 'utf-8') + for (const asset of BRAND_ASSETS) { + expect(markdown).toContain(`(https://supabase.com${asset.svg})`) + expect(markdown).toContain(`(https://supabase.com${asset.png})`) + } + }) +}) diff --git a/apps/www/data/brand-assets.ts b/apps/www/data/brand-assets.ts new file mode 100644 index 00000000000..ab46f333ec9 --- /dev/null +++ b/apps/www/data/brand-assets.ts @@ -0,0 +1,63 @@ +export interface BrandAsset { + id: string + name: string + canvas: 'light' | 'dark' | 'any' + svg: string + png: string + pngWidth: number + pngHeight: number + group: 'icon' | 'logo' | 'one-color' +} + +export const BRAND_ASSETS: BrandAsset[] = [ + { + id: 'icon-green-transparent', + group: 'icon', + name: 'Icon', + canvas: 'any', + svg: '/brand-assets/supabase-icon-green-transparent.svg', + png: '/brand-assets/supabase-icon-green-transparent.png', + pngWidth: 436, + pngHeight: 449, + }, + { + id: 'logo-green-black-transparent', + group: 'logo', + name: 'Wordmark for light backgrounds', + canvas: 'light', + svg: '/brand-assets/supabase-logo-green-black-transparent.svg', + png: '/brand-assets/supabase-logo-green-black-transparent.png', + pngWidth: 2322, + pngHeight: 449, + }, + { + id: 'logo-green-white-transparent', + group: 'logo', + name: 'Wordmark for dark backgrounds', + canvas: 'dark', + svg: '/brand-assets/supabase-logo-green-white-transparent.svg', + png: '/brand-assets/supabase-logo-green-white-transparent.png', + pngWidth: 2322, + pngHeight: 449, + }, + { + id: 'logo-black-transparent', + group: 'one-color', + name: 'One-color wordmark, black', + canvas: 'light', + svg: '/brand-assets/supabase-logo-black-transparent.svg', + png: '/brand-assets/supabase-logo-black-transparent.png', + pngWidth: 2000, + pngHeight: 389, + }, + { + id: 'logo-white-transparent', + group: 'one-color', + name: 'One-color wordmark, white', + canvas: 'dark', + svg: '/brand-assets/supabase-logo-white-transparent.svg', + png: '/brand-assets/supabase-logo-white-transparent.png', + pngWidth: 2000, + pngHeight: 389, + }, +] diff --git a/apps/www/lib/json-ld.ts b/apps/www/lib/json-ld.ts index 53ee36c35f7..2ba269d69bc 100644 --- a/apps/www/lib/json-ld.ts +++ b/apps/www/lib/json-ld.ts @@ -14,7 +14,7 @@ const ORG_SAMEAS = [ 'https://www.instagram.com/supabasecom', ] -const ORG_LOGO_URL = `${CANONICAL_ORIGIN}/images/og/supabase-og.png` +const ORG_LOGO_URL = `${CANONICAL_ORIGIN}/brand-assets/supabase-logo-green-black-transparent.png` type JsonLdSchema = Record | Record[] diff --git a/apps/www/lib/redirects.js b/apps/www/lib/redirects.js index 0b010ee6500..b075cab9f0c 100644 --- a/apps/www/lib/redirects.js +++ b/apps/www/lib/redirects.js @@ -1,4 +1,9 @@ module.exports = [ + { + permanent: true, + source: '/brand-assets', + destination: '/brand', + }, { permanent: true, source: '/images/customers/logos/light/:path*', diff --git a/apps/www/pages/brand-assets.tsx b/apps/www/pages/brand-assets.tsx deleted file mode 100644 index b9f8c28c162..00000000000 --- a/apps/www/pages/brand-assets.tsx +++ /dev/null @@ -1,124 +0,0 @@ -import Layout from '~/components/Layouts/Default' -import SectionContainer from '~/components/Layouts/SectionContainer' -import * as supabaseLogoPreview from 'common/assets/images/logo-preview.jpg' -import Container from 'components/Container' -import CTABanner from 'components/CTABanner/index' -import { Download } from 'lucide-react' -import { NextSeo } from 'next-seo' -import Image from 'next/image' -import { useRouter } from 'next/router' -import { Button } from 'ui' - -const Index = () => { - // base path for images - const router = useRouter() - - const meta_title = 'Branding | Supabase' - const meta_description = 'Get Supabase Brand assets here.' - - return ( - <> - - - - -

Brand assets

-

Download official Supabase logos

-
-

- All Supabase trademarks, logos, or other brand elements can never be modified or - used for any other purpose other than to represent Supabase Inc. -

-
-
- -
-
- Supabase logo Preview -
-
-
-
-

Supabase logos

-

- Download Supabase official logos, including as SVG's, in both light and dark - theme. -

-

- Do not use any other color for the wordmark. -

-
-
- -
-
-
-
-
-
- Connect Supabase Button -
-
-
-
-

Supabase Integrations

-

- When building a{' '} - - Supabase Integration - - , use this "Connect Supabase" button to initiate the OAuth redirect. -

-

- Do not use any other color for the wordmark. -

-
-
- -
-
-
-
-
- -
-
- - ) -} - -export default Index diff --git a/apps/www/pages/brand.tsx b/apps/www/pages/brand.tsx new file mode 100644 index 00000000000..bdb72f7b99c --- /dev/null +++ b/apps/www/pages/brand.tsx @@ -0,0 +1,158 @@ +import { VectorLogo } from '~/components/BrandAssets/VectorLogo' +import { LogoGallery } from '~/components/BrandAssets/LogoGallery' +import Layout from '~/components/Layouts/Default' +import SectionContainer from '~/components/Layouts/SectionContainer' +import { CircleCheckFilled, CrossfadeIcon } from '~/components/CrossfadeIcon' +import Container from 'components/Container' +import CTABanner from 'components/CTABanner/index' +import { NextSeo } from 'next-seo' +import type { InferGetStaticPropsType } from 'next' +import { readFile } from 'node:fs/promises' +import path from 'node:path' +import { useState } from 'react' +import { Copy } from 'lucide-react' +import { Button, copyToClipboard } from 'ui' + +const Index = ({ guideText }: InferGetStaticPropsType) => { + const [isPromptCopied, setIsPromptCopied] = useState(false) + const meta_title = 'Brand Guidelines: Logos and Icons | Supabase' + const meta_description = + 'Official Supabase logos and colors, as SVG and PNG files for light and dark backgrounds' + + const handlePromptCopy = () => { + copyToClipboard( + 'Read https://supabase.com/brand.md and use the official Supabase logo file that fits the background where the logo will appear. Do not change the logo.', + () => { + setIsPromptCopied(true) + setTimeout(() => setIsPromptCopied(false), 2000) + } + ) + } + + return ( + <> + + + +
+ + +

+ Brand Guidelines +

+

+ Official Supabase logos and colors, as SVG and PNG files for light and dark + backgrounds{' '} + + ⤵ + Go to the logo files + +

+
+ + + + {isPromptCopied ? 'Agent prompt copied' : ''} + +
+
+
+
+ +
+
+

Which file to use

+
    +
  • + Choose the file for the background where the logo appears, not for your browser or + editor theme. +
  • +
  • All files have a transparent background.
  • +
  • + There is no file with the lettering alone. Every wordmark file includes the + symbol. +
  • +
+
+
+

Name

+

+ Write Supabase as one word, with a capital S. Do not write SupaBase or Supa Base. +

+
+
+

Usage

+

+ Use the Supabase logos only to refer to Supabase. Do not change the files or the + logo colors. +

+

+ Supabase and the Supabase logo are trademarks of Supabase Inc. +

+
+
+
+ + + + + ) +} + +// the hero guides are made of the team names, from the docs humans.txt +export const getStaticProps = async () => { + const humans = await readFile( + path.join(process.cwd(), '..', 'docs', 'public', 'humans.txt'), + 'utf8' + ) + const lines = humans.split('\n').map((line) => line.trim()) + // the names sit between the team intro sentence and the first rule + const names = lines + .slice( + lines.indexOf('TEAM') + 1, + lines.findIndex((line) => line.startsWith('_')) + ) + .filter(Boolean) + .slice(1) + return { props: { guideText: `${names.join(' + ')} + `.toUpperCase() } } +} + +export default Index diff --git a/apps/www/public/brand-assets.zip b/apps/www/public/brand-assets.zip index 3ddb481d3ec..1b9c08c6fea 100644 Binary files a/apps/www/public/brand-assets.zip and b/apps/www/public/brand-assets.zip differ diff --git a/apps/www/public/brand-assets/supabase-icon-green-transparent.png b/apps/www/public/brand-assets/supabase-icon-green-transparent.png new file mode 100644 index 00000000000..a3b7b36f929 Binary files /dev/null and b/apps/www/public/brand-assets/supabase-icon-green-transparent.png differ diff --git a/apps/www/public/brand-assets/supabase-icon-green-transparent.svg b/apps/www/public/brand-assets/supabase-icon-green-transparent.svg new file mode 100644 index 00000000000..ad802ac16ae --- /dev/null +++ b/apps/www/public/brand-assets/supabase-icon-green-transparent.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/apps/www/public/brand-assets/supabase-logo-black-transparent.png b/apps/www/public/brand-assets/supabase-logo-black-transparent.png new file mode 100644 index 00000000000..c2c070128d1 Binary files /dev/null and b/apps/www/public/brand-assets/supabase-logo-black-transparent.png differ diff --git a/apps/www/public/brand-assets/supabase-logo-black-transparent.svg b/apps/www/public/brand-assets/supabase-logo-black-transparent.svg new file mode 100644 index 00000000000..97fe7aa2eb8 --- /dev/null +++ b/apps/www/public/brand-assets/supabase-logo-black-transparent.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/www/public/brand-assets/supabase-logo-green-black-transparent.png b/apps/www/public/brand-assets/supabase-logo-green-black-transparent.png new file mode 100644 index 00000000000..0277fee2bbe Binary files /dev/null and b/apps/www/public/brand-assets/supabase-logo-green-black-transparent.png differ diff --git a/apps/www/public/brand-assets/supabase-logo-green-black-transparent.svg b/apps/www/public/brand-assets/supabase-logo-green-black-transparent.svg new file mode 100644 index 00000000000..60cbc71dc7c --- /dev/null +++ b/apps/www/public/brand-assets/supabase-logo-green-black-transparent.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/www/public/brand-assets/supabase-logo-green-white-transparent.png b/apps/www/public/brand-assets/supabase-logo-green-white-transparent.png new file mode 100644 index 00000000000..821c42ce283 Binary files /dev/null and b/apps/www/public/brand-assets/supabase-logo-green-white-transparent.png differ diff --git a/apps/www/public/brand-assets/supabase-logo-green-white-transparent.svg b/apps/www/public/brand-assets/supabase-logo-green-white-transparent.svg new file mode 100644 index 00000000000..9e96fab4ddc --- /dev/null +++ b/apps/www/public/brand-assets/supabase-logo-green-white-transparent.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/www/public/brand-assets/supabase-logo-white-transparent.png b/apps/www/public/brand-assets/supabase-logo-white-transparent.png new file mode 100644 index 00000000000..6055743c0ef Binary files /dev/null and b/apps/www/public/brand-assets/supabase-logo-white-transparent.png differ diff --git a/apps/www/public/brand-assets/supabase-logo-white-transparent.svg b/apps/www/public/brand-assets/supabase-logo-white-transparent.svg new file mode 100644 index 00000000000..8eb47a0a37a --- /dev/null +++ b/apps/www/public/brand-assets/supabase-logo-white-transparent.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/www/styles/globals.css b/apps/www/styles/globals.css index 3bbc4b37205..99d815d44bc 100644 --- a/apps/www/styles/globals.css +++ b/apps/www/styles/globals.css @@ -1,5 +1,7 @@ @import 'config/tailwind.config.css'; @import 'config/inline-code.css'; +@import 'ui-patterns/CodeBlock/code-block.css'; +@import 'ui-patterns/Notch/notch.css'; @source '../_blog/*.mdx'; @source '../components/**/*.tsx'; @@ -17,12 +19,21 @@ var(--font-inter), Inter, Helvetica Neue, Helvetica, ui-sans-serif, system-ui, sans-serif; --font-heading: var(--font-manrope, var(--font-sans)); --font-mono: var(--font-source-code-pro), 'Source Code Pro', ui-monospace, Menlo, monospace; + + --color-pane-dark: hsl(var(--colors-gray-dark-300)); } @utility section-container { @apply w-full mx-auto max-w-7xl px-6 lg:px-12 xl:px-24; } +@utility construction-mask { + mask: + linear-gradient(to right, transparent, #000 35%, #000 65%, transparent), + linear-gradient(to bottom, #000 60%, transparent); + mask-composite: intersect; +} + /** * Legal documents must paint the exact characters that are in their source text. * @@ -75,6 +86,8 @@ --animate-marquee-vertical: marquee-vertical 180s linear infinite both; --animate-pulse-radar: pulse-radar 3s linear infinite; --animate-slide-in: slideIn 250ms ease-in both; + --animate-draw-line: draw-line 1.8s linear both; + --animate-reveal-hatch: reveal-hatch 2.4s cubic-bezier(0.4, 0, 1, 1) 1.8s both; --delay-1200: 1200ms; --delay-1500: 1500ms; @@ -94,6 +107,21 @@ --font-weight-normal: 450; } +@keyframes draw-line { + from { + stroke-dashoffset: 1; + } +} + +@keyframes reveal-hatch { + from { + scale: 0; + } + to { + scale: 1; + } +} + @keyframes flash-code { 0% { background-color: rgba(63, 207, 142, 0.1); diff --git a/packages/config/css/utilities.css b/packages/config/css/utilities.css index 94ad7979ea7..9a3170b48f4 100644 --- a/packages/config/css/utilities.css +++ b/packages/config/css/utilities.css @@ -67,6 +67,21 @@ } } +@utility raised-svg-surface { + & stop:first-child { + stop-color: hsl(var(--colors-white) / 0.015); + } + & stop:last-child { + stop-color: hsl(var(--colors-black) / 0.01); + } + & feDropShadow { + flood-color: hsl(var(--colors-black) / var(--button-shadow-opacity)); + } + & [data-raised-edge] { + stroke: hsl(var(--button-edge-color) / calc(0.1 * var(--button-edge-strength))); + } +} + /* * Soft shimmer gradient used by LoadingLine. */ diff --git a/packages/eslint-config-supabase/next.js b/packages/eslint-config-supabase/next.js index 732b66f799b..4b78bb36dc8 100644 --- a/packages/eslint-config-supabase/next.js +++ b/packages/eslint-config-supabase/next.js @@ -77,7 +77,8 @@ module.exports = defineConfig([ }, rules: { 'shadcn/no-unknown-classes': ['warn', { allow: ['not-prose'] }], - 'shadcn/no-arbitrary-values': ['warn', { allow: ['layout'] }], + // a transition-[...] list names css properties, not a design value, so no token can replace it + 'shadcn/no-arbitrary-values': ['warn', { allow: ['layout', 'transition'] }], 'shadcn/no-raw-colors': 'warn', }, }, diff --git a/packages/ui-patterns/package.json b/packages/ui-patterns/package.json index f7c657ab50a..33053c42972 100644 --- a/packages/ui-patterns/package.json +++ b/packages/ui-patterns/package.json @@ -435,6 +435,10 @@ "import": "./src/GlassPanel/index.tsx", "types": "./src/GlassPanel/index.tsx" }, + "./GlyphLines": { + "import": "./src/GlyphLines/index.tsx", + "types": "./src/GlyphLines/index.tsx" + }, "./Image/Image": { "import": "./src/Image/Image.tsx", "types": "./src/Image/Image.tsx" @@ -575,10 +579,19 @@ "import": "./src/MultipleCodeBlock/index.tsx", "types": "./src/MultipleCodeBlock/index.tsx" }, + "./Notch/NotchOutline": { + "import": "./src/Notch/NotchOutline.tsx", + "types": "./src/Notch/NotchOutline.tsx" + }, "./Notch": { "import": "./src/Notch/index.ts", "types": "./src/Notch/index.ts" }, + "./Notch/notch.css": { + "style": "./src/Notch/notch.css", + "import": "./src/Notch/notch.css", + "types": "./src/Notch/notch.css" + }, "./PageBreadcrumbs": { "import": "./src/PageBreadcrumbs/index.tsx", "types": "./src/PageBreadcrumbs/index.tsx" diff --git a/packages/ui-patterns/src/CodeBlock/CodeBlockControls.tsx b/packages/ui-patterns/src/CodeBlock/CodeBlockControls.tsx index 07605e44130..8f8c9df7612 100644 --- a/packages/ui-patterns/src/CodeBlock/CodeBlockControls.tsx +++ b/packages/ui-patterns/src/CodeBlock/CodeBlockControls.tsx @@ -69,8 +69,14 @@ export function CodeCopyButton({ ) } -export function CodeBlockControls({ content }: { content: string }) { - const [isWrapped, setIsWrapped] = useState(false) +export function CodeBlockControls({ + content, + defaultWrapped = false, +}: { + content: string + defaultWrapped?: boolean +}) { + const [isWrapped, setIsWrapped] = useState(defaultWrapped) // Empty until the first toggle, so nothing is announced on mount const [wrapStatus, setWrapStatus] = useState('') diff --git a/packages/ui-patterns/src/GlyphLines/index.tsx b/packages/ui-patterns/src/GlyphLines/index.tsx new file mode 100644 index 00000000000..63423b29281 --- /dev/null +++ b/packages/ui-patterns/src/GlyphLines/index.tsx @@ -0,0 +1,304 @@ +import { useCallback, type RefObject } from 'react' +import { cn } from 'ui' + +export interface GlyphLinesProps { + linesRef: RefObject + text: string + className?: string +} + +interface Pulse { + line: SVGLineElement + head: number + end: number + speed: number +} + +interface GlyphLine { + line: SVGLineElement + start: Point + direction: Point + from: number + to: number + step: number + textOffset: number +} + +type Point = [number, number] + +// in css px. glyphs this small read as a line at 100%, and as text once the page is zoomed in +const GLYPH_SIZE = 2.2 +const PULSE_LENGTH = 140 +// px past the canvas edge where glyphs still draw, so a glyph does not pop in at the edge +const EDGE = 24 + +const opaqueColors = new Map() + +// border tokens have alpha, and alpha adds up where glyphs overlap. so glyphs draw in the opaque color the token gives over the surface +export const toOpaque = (color: string, surface: string): string => { + if (color === surface) return color + const key = `${color}|${surface}` + const cached = opaqueColors.get(key) + if (cached) return cached + const probe = document.createElement('canvas').getContext('2d', { willReadFrequently: true }) + if (!probe) return color + probe.canvas.width = 1 + probe.canvas.height = 1 + probe.fillStyle = surface + probe.fillRect(0, 0, 1, 1) + probe.fillStyle = color + probe.fillRect(0, 0, 1, 1) + const [red, green, blue] = probe.getImageData(0, 0, 1, 1).data + const opaque = `rgb(${red} ${green} ${blue})` + opaqueColors.set(key, opaque) + return opaque +} + +const startGlyphLines = ({ + canvas, + linesRef, + text, +}: { + canvas: HTMLCanvasElement + linesRef: RefObject + text: string +}) => { + const context = canvas.getContext('2d') + // the glyphs at rest draw once into this layer, and only again when the lines move or the zoom changes + const layer = document.createElement('canvas') + const layerContext = layer.getContext('2d') + if (!context || !layerContext || !text) return + const isReducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches + let pulses: Pulse[] = [] + let layerKey = '' + let last = performance.now() + let frame = 0 + + const draw = (now: number) => { + frame = requestAnimationFrame(draw) + const elapsed = Math.min(now - last, 100) + last = now + const svg = linesRef.current + const box = canvas.getBoundingClientRect() + if (!svg || !box.width || box.bottom < 0 || box.top > innerHeight) return + // the svg can start its draw-in from this attribute. the next frame reads the first animated dash + if (!svg.hasAttribute('data-glyph-lines-ready')) { + svg.setAttribute('data-glyph-lines-ready', '') + return + } + + // browser zoom changes the device pixel ratio, and a pinch zoom changes the visual viewport scale + const ratio = Math.min( + devicePixelRatio * (visualViewport?.scale ?? 1), + // safari blanks a canvas past about 16M px, so a deep pinch zoom caps the resolution + Math.sqrt(16_000_000 / (box.width * box.height)) + ) + const width = Math.round(box.width * ratio) + const height = Math.round(box.height * ratio) + const style = getComputedStyle(canvas) + const font = `${GLYPH_SIZE}px ${style.fontFamily}` + const svgBox = svg.getBoundingClientRect() + const lines = [...svg.querySelectorAll('line[data-glyph-line]')] + const origin: Point = [svgBox.left - box.left, svgBox.top - box.top] + const glyphLines = lines.flatMap((line, lineIndex) => + toGlyphLine({ line, lineIndex, origin, size: [box.width, box.height] }) + ) + const toScreen = ({ start, direction }: GlyphLine, distance: number): Point => [ + start[0] + direction[0] * distance, + start[1] + direction[1] * distance, + ] + + if (canvas.width !== width || canvas.height !== height) { + canvas.width = width + canvas.height = height + } + // a theme change swaps the color, so it is part of the key too + const key = [ + style.color, + style.caretColor, + font, + // the glyphs draw in a fallback font until the web font loads + document.fonts.status, + ...[ + width, + height, + ...glyphLines.flatMap((glyphLine) => [...glyphLine.start, glyphLine.from, glyphLine.to]), + ].map((value) => value.toFixed(2)), + ].join() + + if (key !== layerKey) { + layerKey = key + layer.width = width + layer.height = height + layerContext.setTransform(ratio, 0, 0, ratio, 0, 0) + const color = toOpaque(style.color, style.caretColor) + layerContext.font = font + layerContext.textAlign = 'center' + layerContext.textBaseline = 'middle' + glyphLines.forEach((glyphLine) => { + const indexes: number[] = [] + for ( + let index = Math.ceil(glyphLine.from / glyphLine.step); + index * glyphLine.step <= glyphLine.to; + index++ + ) { + indexes.push(index) + } + // each glyph cell fills with the caret color first, so a line hides the glyphs of a line it crosses. + // without a caret color, the caret color is the text color, and the cells would hide the glyphs + if (color !== style.caretColor) { + layerContext.beginPath() + for (const index of indexes) { + const [x, y] = toScreen(glyphLine, index * glyphLine.step) + layerContext.rect( + x - GLYPH_SIZE * 0.325, + y - GLYPH_SIZE * 0.5, + GLYPH_SIZE * 0.65, + GLYPH_SIZE + ) + } + layerContext.fillStyle = style.caretColor + layerContext.fill() + } + layerContext.fillStyle = color + for (const index of indexes) { + const char = text[(index + glyphLine.textOffset) % text.length] + if (char === ' ') continue + layerContext.fillText(char, ...toScreen(glyphLine, index * glyphLine.step)) + } + }) + } + + context.setTransform(1, 0, 0, 1, 0, 0) + context.clearRect(0, 0, width, height) + context.drawImage(layer, 0, 0) + + pulses = pulses + .map((pulse) => ({ ...pulse, head: pulse.head + pulse.speed * elapsed })) + .filter((pulse) => (pulse.end - pulse.head) * Math.sign(pulse.speed) > 0) + context.setTransform(ratio, 0, 0, ratio, 0, 0) + const pulseColor = toOpaque( + style.getPropertyValue('--glyph-lines-pulse') || style.color, + style.caretColor + ) + context.fillStyle = pulseColor + context.shadowColor = pulseColor + context.shadowBlur = 4 + context.font = font + context.textAlign = 'center' + context.textBaseline = 'middle' + pulses.forEach((pulse) => { + const glyphLine = glyphLines.find(({ line }) => line === pulse.line) + if (!glyphLine) return + const tail = pulse.head - Math.sign(pulse.speed) * PULSE_LENGTH + const from = Math.max(Math.min(pulse.head, tail), glyphLine.from) + const to = Math.min(Math.max(pulse.head, tail), glyphLine.to) + for (let index = Math.ceil(from / glyphLine.step); index * glyphLine.step <= to; index++) { + const char = text[(index + glyphLine.textOffset) % text.length] + if (char === ' ') continue + const behind = Math.abs(pulse.head - index * glyphLine.step) + context.globalAlpha = 1 - behind / PULSE_LENGTH + context.fillText(char, ...toScreen(glyphLine, index * glyphLine.step)) + } + }) + context.globalAlpha = 1 + context.shadowBlur = 0 + + if (isReducedMotion || pulses.length >= 3 || !glyphLines.length) return + // a new pulse starts about every 1800ms + if (Math.random() > elapsed / 1800) return + const glyphLine = glyphLines[Math.floor(Math.random() * glyphLines.length)] + const isForward = Math.random() < 0.5 + pulses.push({ + line: glyphLine.line, + speed: (0.25 + Math.random() * 0.35) * (isForward ? 1 : -1), + head: isForward ? glyphLine.from : glyphLine.to, + end: isForward ? glyphLine.to + PULSE_LENGTH : glyphLine.from - PULSE_LENGTH, + }) + } + + frame = requestAnimationFrame(draw) + return () => cancelAnimationFrame(frame) +} + +const toGlyphLine = ({ + line, + lineIndex, + origin, + size, +}: { + line: SVGLineElement + lineIndex: number + origin: Point + size: Point +}): GlyphLine[] => { + // the dash runs from 1 (hidden) to 0 (drawn) along a pathLength of 1 + const drawn = + 1 - Math.min(Math.max(parseFloat(getComputedStyle(line).strokeDashoffset) || 0, 0), 1) + if (!drawn) return [] + // the line's own ctm holds the transforms of its parent groups + const matrix = line.getCTM() + const toCanvas = (x: number, y: number): Point => { + const point = new DOMPoint(x, y).matrixTransform(matrix ?? undefined) + return [origin[0] + point.x, origin[1] + point.y] + } + const start = toCanvas(line.x1.baseVal.value, line.y1.baseVal.value) + const end = toCanvas(line.x2.baseVal.value, line.y2.baseVal.value) + const length = Math.hypot(end[0] - start[0], end[1] - start[1]) + const range = clipToBox({ from: start, to: end, size }) + if (!length || !range) return [] + const direction: Point = [(end[0] - start[0]) / length, (end[1] - start[1]) / length] + return [ + { + line, + start, + direction, + from: range[0] * length, + to: Math.min(range[1], drawn) * length, + // an upright glyph box is 0.65 wide and 1 tall, so the step is the box size along the line. + // rows and columns keep their spacing, and diagonal glyphs do not overlap + step: GLYPH_SIZE * (Math.abs(direction[0]) * 0.65 + Math.abs(direction[1])), + // each line starts at a different place in the text, so neighbor lines do not repeat + textOffset: lineIndex * 1009, + }, + ] +} + +// the part of the segment inside the box, as fractions of the segment +const clipToBox = ({ from, to, size }: { from: Point; to: Point; size: Point }): Point | null => { + const delta = [to[0] - from[0], to[1] - from[1]] + const checks = [ + [-delta[0], from[0] + EDGE], + [delta[0], size[0] + EDGE - from[0]], + [-delta[1], from[1] + EDGE], + [delta[1], size[1] + EDGE - from[1]], + ] + return checks.reduce( + (current, [p, q]) => { + if (!current) return null + if (p === 0) return q < 0 ? null : current + const fraction = q / p + const next: Point = + p < 0 + ? [Math.max(current[0], fraction), current[1]] + : [current[0], Math.min(current[1], fraction)] + return next[0] > next[1] ? null : next + }, + [0, 1] + ) +} + +export const GlyphLines = ({ linesRef, text, className }: GlyphLinesProps) => { + // the loop reads the lines from the dom on every frame, so a change to the lines does not restart it + const handleCanvasRef = useCallback( + (canvas: HTMLCanvasElement | null) => { + if (!canvas) return + return startGlyphLines({ canvas, linesRef, text }) + }, + [linesRef, text] + ) + + return ( + + ) +} diff --git a/packages/ui-patterns/src/Notch/NotchOutline.tsx b/packages/ui-patterns/src/Notch/NotchOutline.tsx new file mode 100644 index 00000000000..1810712fd28 --- /dev/null +++ b/packages/ui-patterns/src/Notch/NotchOutline.tsx @@ -0,0 +1,35 @@ +import type { ReactNode } from 'react' +import { cn } from 'ui' + +import { getNotchOutline } from './index' + +export interface NotchOutlineProps { + width: number + surfaceClassName: string + className?: string + children?: ReactNode +} + +export const NotchOutline = ({ + width, + surfaceClassName, + className, + children, +}: NotchOutlineProps) => { + const outline = getNotchOutline(width) + + return ( + + + + {children} + + ) +} diff --git a/packages/ui-patterns/src/Notch/index.ts b/packages/ui-patterns/src/Notch/index.ts index c3e8ba65494..a0c3db0c611 100644 --- a/packages/ui-patterns/src/Notch/index.ts +++ b/packages/ui-patterns/src/Notch/index.ts @@ -1,10 +1,20 @@ +import type { CSSProperties } from 'react' + +type NotchStyle = CSSProperties & { '--notch-width': string; '--notch-mask': string } + export const getNotchOutline = (width: number): string => `M0 39.5A7.5 7.5 0 0 0 7.5 32V16A8.5 8.5 0 0 1 16 7.5H${width}A7.5 7.5 0 0 0 ${width + 7.5} 0` export const getNotchFocusRing = (width: number): string => `M0 41A9 9 0 0 0 9 32V16A7 7 0 0 1 16 9H${width}A9 9 0 0 0 ${width + 9} 0` -export const getNotchMask = (width: number): string => +const getNotchMask = (width: number): string => `url("data:image/svg+xml,${encodeURIComponent( `` )}")` + +// the css variables that the notch-corner utility in ./notch.css reads +export const getNotchStyle = (width: number): NotchStyle => ({ + '--notch-width': `${width}px`, + '--notch-mask': getNotchMask(width), +}) diff --git a/packages/ui-patterns/src/Notch/notch.css b/packages/ui-patterns/src/Notch/notch.css new file mode 100644 index 00000000000..3049dcbcf0a --- /dev/null +++ b/packages/ui-patterns/src/Notch/notch.css @@ -0,0 +1,7 @@ +@utility notch-corner { + mask: + linear-gradient(#000 0 0), + var(--notch-mask) right -2px bottom -2px / calc(var(--notch-width) + 10px) 42px no-repeat; + mask-composite: exclude; + mask-clip: no-clip; +}