Skip to content
Merged
109 changes: 109 additions & 0 deletions apps/website/e2e/font-metrics.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { expect } from '@playwright/test'

import { test } from './fixtures/blockExternalMedia'

// Rows that put an icon, a count or a control beside an uppercase word centre
// the boxes, not the ink. So a face whose caps sit high inside their line box
// misaligns every one of those rows at once, and no component can fix it. The
// faces are measured from their own @font-face rules rather than from the page,
// because `font-display: optional` leaves the weights this page never renders
// unusable for measurement.
const SIZE = 1000

test('every PP Formula face centres its caps inside the line box', async ({
page
}) => {
await page.goto('/')
await expect(page.locator('html')).not.toHaveClass(
/(?:^|\s)ppformula-metric-fallback(?:\s|$)/
)

const faces = await page.evaluate(async (size) => {
const rulesOf = (sheet: CSSStyleSheet) => {
try {
return [...sheet.cssRules]
} catch {
return []
}
}

const declarations = [...document.styleSheets]
.flatMap(rulesOf)
.filter(
(rule): rule is CSSFontFaceRule => rule instanceof CSSFontFaceRule
)
.map((rule) => ({
family: rule.style
.getPropertyValue('font-family')
.replaceAll(/['"]/g, ''),
weight: rule.style.getPropertyValue('font-weight'),
source: rule.style.getPropertyValue('src'),
ascentOverride: rule.style.getPropertyValue('ascent-override'),
descentOverride: rule.style.getPropertyValue('descent-override')
}))
.filter((declaration) => declaration.family.startsWith('PP Formula'))

return Promise.all(
declarations.map(async (declaration, index) => {
const url = /url\(["']?([^"')]+)/.exec(declaration.source)?.[1]
if (!url) {
throw new Error(`no source for ${declaration.family}`)
}

const probe = `probe-${index}`
document.fonts.add(
await new FontFace(probe, `url("${url}")`, {
ascentOverride: declaration.ascentOverride,
descentOverride: declaration.descentOverride
}).load()
)

const context = document.createElement('canvas').getContext('2d')
if (!context) throw new Error('no canvas context')
context.font = `${size}px "${probe}"`
const caps = context.measureText('H')
return {
family: declaration.family,
name: `${declaration.family} ${declaration.weight}`,
ascent: caps.fontBoundingBoxAscent,
descent: caps.fontBoundingBoxDescent,
capHeight: caps.actualBoundingBoxAscent
}
})
)
}, SIZE)

expect([...new Set(faces.map((face) => face.family))].sort()).toEqual([
'PP Formula',
'PP Formula Narrow'
])

for (const face of faces) {
const aboveTheCaps = face.ascent - face.capHeight
expect(
Math.abs(aboveTheCaps - face.descent),
face.name
).toBeLessThanOrEqual(SIZE / 100)
}
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

test('keeps the component fallback when metric overrides are unsupported', async ({
page
}) => {
await page.addInitScript(() => {
Object.defineProperty(FontFace.prototype, 'ascentOverride', {
configurable: true,
get: () => ''
})
})
await page.goto('/')

await expect(page.locator('html')).toHaveClass(
/(?:^|\s)ppformula-metric-fallback(?:\s|$)/
)
const marker = page.locator('.ppformula-text-center').first()
await expect(marker).toBeVisible()
expect(
await marker.evaluate((element) => getComputedStyle(element).top)
).not.toBe('auto')
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion apps/website/src/components/common/BrandButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const resolvedRel = computed(() =>
)
"
>
<span class="ppformula-text-center">
<span class="ppformula-text-center inline-block">
<slot />
</span>
</component>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<NavigationMenu data-testid="desktop-nav-links">
<NavigationMenuList>
<NavigationMenuItem
v-for="navItem in mainNavigation"

Check warning on line 52 in apps/website/src/components/common/HeaderMain/HeaderMainDesktop.vue

View workflow job for this annotation

GitHub Actions / fallow

High cognitive complexity (moderate)

Function '<template>' is hard to understand (cognitive: 16, threshold: 15). • Severity: moderate • Cyclomatic: 8 • Cognitive: 16 • Lines: 105 High cognitive complexity means deeply nested or interleaved logic. Consider flattening control flow or extracting helper functions.
:key="navItem.label"
>
<template v-if="navItem.columns?.length">
Expand Down Expand Up @@ -88,7 +88,9 @@
"
>
<a :href="navItem.href">
<span class="ppformula-text-center">{{ navItem.label }}</span>
<span class="ppformula-text-center inline-block">{{
navItem.label
}}</span>
<span
v-if="navItem.badge"
class="ppformula-text-center hidden 2xl:inline-flex"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defineProps<{

<template>
<span class="flex items-center gap-2">
<span class="ppformula-text-center">{{ item.label }}</span>
<span class="ppformula-text-center inline-block">{{ item.label }}</span>
<NewBadge
v-if="item.badge"
:locale="locale"
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/customers/WhatsNextSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const {
<span class="text-lg font-bold">›</span>
</span>
<span
class="ppformula-text-center text-sm font-semibold tracking-wider text-primary-comfy-canvas uppercase"
class="ppformula-text-center inline-block text-sm font-semibold tracking-wider text-primary-comfy-canvas uppercase"
>
{{
ctaLabel ??
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/demos/DemoNavSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const nextHref = localizeHref(`/demos/${nextSlug}`, locale)
<span class="text-lg font-bold">›</span>
</span>
<span
class="ppformula-text-center text-sm font-semibold tracking-wider text-primary-comfy-canvas uppercase"
class="ppformula-text-center inline-block text-sm font-semibold tracking-wider text-primary-comfy-canvas uppercase"
>
{{ t('demos.nav.viewDemo' as TranslationKey, locale) }}
</span>
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/hero/AngleNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ onUnmounted(() => {
<span class="size-[0.55em] rounded-full bg-primary-comfy-yellow" />
<span class="ml-auto flex items-center gap-[0.5em]">
<span
class="ppformula-text-center font-formula text-[0.75em] leading-[1.1] font-bold tracking-[-0.01em] text-primary-comfy-canvas"
class="ppformula-text-center inline-block font-formula text-[0.75em] leading-[1.1] font-bold tracking-[-0.01em] text-primary-comfy-canvas"
>
3D ANGLE
</span>
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/hero/ColorNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const saturationTrack = computed(
/>
<span class="ml-auto flex items-center gap-[0.5em]">
<span
class="ppformula-text-center font-formula text-[0.7em] leading-[1.1] font-bold tracking-[-0.01em] text-primary-comfy-canvas"
class="ppformula-text-center inline-block font-formula text-[0.7em] leading-[1.1] font-bold tracking-[-0.01em] text-primary-comfy-canvas"
>
COLOR
</span>
Expand Down
4 changes: 1 addition & 3 deletions apps/website/src/components/hero/HeroHeadline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const lines = t('hero.title', locale).split('\n')
// whatever context renders it (canvas overlay or mobile flow).
const cap = '-mx-px h-full w-auto self-stretch'

// PP Formula Narrow sits high in its em box; nudge the glyphs down so they
// read optically centred between the caps.
const inner = 'inline-block translate-y-[0.11em] whitespace-nowrap'
const inner = 'ppformula-narrow-text-center inline-block whitespace-nowrap'
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/hero/HeroImageCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ watch(
>
<span class="size-[0.5em] rounded-full bg-primary-comfy-yellow" />
<span
class="ppformula-text-center font-formula text-[0.75em] leading-[1.1] font-bold tracking-[-0.01em] text-primary-comfy-yellow"
class="ppformula-text-center inline-block font-formula text-[0.75em] leading-[1.1] font-bold tracking-[-0.01em] text-primary-comfy-yellow"
>
{{ label }}
</span>
Expand Down
7 changes: 4 additions & 3 deletions apps/website/src/components/hub/HubWorkflowCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<div
class="group/pill-trigger group flex cursor-pointer flex-col gap-4 overflow-hidden rounded-4xl bg-hub-surface px-2 pt-2 pb-6 transition-colors duration-200 content-auto hover:bg-hub-surface-hover"
data-testid="hub-card"
:data-app="template.isApp"

Check warning on line 124 in apps/website/src/components/hub/HubWorkflowCard.vue

View workflow job for this annotation

GitHub Actions / fallow

High cognitive complexity (moderate)

Function '<template>' is hard to understand (cognitive: 21, threshold: 15). • Severity: moderate • Cyclomatic: 19 • Cognitive: 21 • Lines: 328 High cognitive complexity means deeply nested or interleaved logic. Consider flattening control flow or extracting helper functions.
@click="openCard"
>
<div
Expand Down Expand Up @@ -305,9 +305,10 @@
class="grid grid-cols-[0fr] transition-[grid-template-columns] duration-500 group-hover/pill-trigger:grid-cols-[1fr]"
>
<span class="overflow-hidden">
<span class="ppformula-text-center relative leading-none">{{
tryNowLabel
}}</span>
<span
class="ppformula-text-center relative inline-block leading-none"
>{{ tryNowLabel }}</span
>
</span>
</span>
<span
Expand Down
4 changes: 3 additions & 1 deletion apps/website/src/components/pricing/PricingCredits.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const estimate = computed(() => {
class="size-4 shrink-0 text-primary-comfy-orange"
aria-hidden="true"
/>
<span class="ppformula-text-center text-sm text-primary-warm-white">
<span
class="ppformula-text-center inline-block text-sm text-primary-warm-white"
>
<span class="font-extrabold">
{{ credits }}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const { locale = 'en' } = defineProps<{
}}:
</span>
<span
class="ppformula-text-center text-sm"
class="ppformula-text-center inline-block text-sm"
:class="
feature.highlight
? 'text-primary-comfy-yellow'
Expand Down
6 changes: 3 additions & 3 deletions apps/website/src/components/pricing/PricingSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ const planCards = computed(() =>
value="monthly"
class="min-w-40 text-2xs sm:min-w-48 sm:text-xs"
>
<span class="ppformula-text-center">{{
<span class="ppformula-text-center inline-block">{{
t('pricing.period.monthly', locale)
}}</span>
</ToggleGroupItem>
<ToggleGroupItem
value="yearly"
class="min-w-40 text-2xs sm:min-w-48 sm:text-xs"
>
<span class="ppformula-text-center">{{
<span class="ppformula-text-center inline-block">{{
t('pricing.period.yearly', locale)
}}</span>
</ToggleGroupItem>
Expand Down Expand Up @@ -165,7 +165,7 @@ const planCards = computed(() =>
<div class="flex items-center gap-4">
<PricingPlanLabel
:label="t(plan.labelKey, locale)"
class="ppformula-text-center text-base uppercase"
class="ppformula-text-center inline-block text-base uppercase"
/>
<Badge v-if="plan.isPopular" variant="callout" size="xs">
{{ t('pricing.badge.popular', locale) }}</Badge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ const buttons = computed<ButtonSpec[]>(() => {
<img
:src="btn.icon"
alt=""
class="ppformula-text-center size-5 -translate-y-0.75"
class="ppformula-text-center inline-block size-5 -translate-y-0.75"
/>
<span class="ppformula-text-center">{{ label }}</span>
<span class="ppformula-text-center inline-block">{{ label }}</span>
</span>
</BrandButton>
</template>
2 changes: 1 addition & 1 deletion apps/website/src/components/ui/badge/Badge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const {
<slot name="prepend">
<component :is="prependIcon" v-if="prependIcon" />
</slot>
<span class="ppformula-text-center">
<span class="ppformula-text-center inline-block">
<slot />
</span>
<slot name="append">
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/ui/button-pill/ButtonPill.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const {
<span
:class="
cn(
'ppformula-text-center relative leading-none transition-all duration-500'
'ppformula-text-center relative inline-block leading-none transition-all duration-500'
)
"
>
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/ui/button/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const {
<slot name="prepend">
<component :is="prependIcon" v-if="prependIcon" />
</slot>
<span class="ppformula-text-center">
<span class="ppformula-text-center inline-block">
<slot />
</span>
<slot name="append">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const forwardedProps = useForwardProps(computed(() => ({ ...restProps })))
:data-active="active ? '' : undefined"
:class="cn(navigationMenuTriggerStyle(), 'group', className)"
>
<span class="ppformula-text-center">
<span class="ppformula-text-center inline-block">
<slot />
</span>
<ChevronDown
Expand Down
15 changes: 14 additions & 1 deletion apps/website/src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const structuredData = shouldNoindex
{/* <html> must stay overflow: visible — body's overflow (incl. reka-ui's
dialog scroll lock) only propagates to the viewport when the root is
visible. The horizontal clip lives on <body>. */}
<html lang={locale}>
<html lang={locale} class="ppformula-metric-fallback">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand All @@ -115,6 +115,19 @@ const structuredData = shouldNoindex
{shouldNoindex && <meta name="robots" content="noindex, nofollow" />}
<title>{title}</title>

<!-- Safari through 26.6 ignores @font-face metric overrides. Keep the
component-level fallback only where the browser cannot apply them. -->
<script is:inline>
try {
const probe = new FontFace('__ppformula_metric_probe', 'local(Arial)', {
ascentOverride: '50%'
})
if (probe.ascentOverride === '50%')
document.documentElement.classList.remove('ppformula-metric-fallback')
} catch {
// The class already present on <html> supplies the legacy fallback.
}
</script>
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="shortcut icon" href="/favicon.ico" sizes="48x48" />
Expand Down
4 changes: 2 additions & 2 deletions apps/website/src/pages/pixal3d-trellis2.astro
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ const faqJsonLd = {
aria-selected="true"
class={tab}
>
<span class="ppformula-text-center">Examples</span>
<span class="ppformula-text-center inline-block">Examples</span>
</button>
<button
type="button"
Expand All @@ -300,7 +300,7 @@ const faqJsonLd = {
aria-selected="false"
class={tab}
>
<span class="ppformula-text-center">API</span>
<span class="ppformula-text-center inline-block">API</span>
</button>
</nav>
</div>
Expand Down
Loading
Loading