Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions tokens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Also set by the theme:
- **Radius** — one family: 6 px containers, 5 px controls. The Tailwind scale is deliberately remapped
(`rounded-xl` → 6 px, `rounded-2xl` → 8 px) so existing markup adopts the new geometry; prefer
`rounded-lg` / `rounded-md` in new code.
- **Type** — semantic sizes beside Tailwind's own (`text-xs` … `text-xl` keep their sizes): `text-body` 14 px for
running text, `text-h1` 24 px for the page title, `text-h2` 15 px for a section or panel title, `text-metric` 26 px
for a headline number. Each sets its line height, and the titles their weight and tracking. `base.css` sets the body
to `text-body`; an app without it sets `body` itself.
- **Motion** — every `transition` utility defaults to 120 ms with `cubic-bezier(0.2, 0, 0, 1)`;
`ease-standard` is available, and `base.css` honours `prefers-reduced-motion`.
- **Shadows** — light by design: separate with borders, keep elevation for floating surfaces.
Expand Down Expand Up @@ -94,8 +98,10 @@ const style = mapStyle({

- Only the pins wear colour: no places, shops, transport, shields, one-way arrows or house numbers (the pins
already carry the numbers the lists show).
- Labels use the `MAP_FONTS` glyph stacks (IBM Plex Sans Regular, Medium, Italic); names written in Devanagari ask
for `Noto Sans Devanagari Regular v1`, as Protomaps does.
- Labels use the `MAP_FONTS` glyph stacks, `Unitae Map Regular`, `Medium` and `Italic`: IBM Plex Sans turned into map
glyphs. They carry another name because the font's licence (OFL 1.1) reserves « Plex » for unmodified versions;
serve them with the OFL and IBM's copyright. Names written in Devanagari ask for `Noto Sans Devanagari Regular v1`,
as Protomaps does.
- Nothing draws an icon, so the style needs no sprite.
- Credit `MAP_ATTRIBUTION` wherever the map shows: OpenStreetMap's licence wants it visible.
- The tests check, in both modes, that labels reach 4.5:1 on their halo (the ground), that a pin — primary in a
Expand Down
2 changes: 1 addition & 1 deletion tokens/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unitae/tokens",
"version": "0.2.0",
"version": "0.3.0",
"description": "Design tokens for Unitae: colours, type, radius, motion, chart palettes and the map style, as CSS variables, a Tailwind v4 theme and a JS API.",
"license": "MIT",
"type": "module",
Expand Down
28 changes: 27 additions & 1 deletion tokens/src/css.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ColorName, colorNames, colors, fonts, motion, radii, shadows } from './tokens.ts'
import { type ColorName, colorNames, colors, fonts, motion, radii, shadows, typeScale } from './tokens.ts'

/**
* Tailwind / shadcn colour names → Unitae tokens. These are the exact names the apps' components
Expand Down Expand Up @@ -99,6 +99,28 @@ function declarations(entries: [string, string][], indent = ' '): string {
}

/** Raw tokens as `--u-*` custom properties: light on `:root`, dark on `.dark` / `[data-theme="dark"]`. */
/** The type scale as raw tokens: `--u-text-h1`, `--u-text-h1-line-height`, `--u-text-h1-weight`… */
function typeTokens(): [string, string][] {
return Object.entries(typeScale).flatMap(([name, step]): [string, string][] => [
[`--u-text-${name}`, step.size],
[`--u-text-${name}-line-height`, step.lineHeight],
...('weight' in step ? [[`--u-text-${name}-weight`, step.weight] as [string, string]] : []),
...('letterSpacing' in step ? [[`--u-text-${name}-letter-spacing`, step.letterSpacing] as [string, string]] : []),
])
}

/** The type scale as Tailwind text utilities: `text-h1` sets the size with its line height, weight and tracking. */
function typeTheme(): [string, string][] {
return Object.entries(typeScale).flatMap(([name, step]): [string, string][] => [
[`--text-${name}`, `var(--u-text-${name})`],
[`--text-${name}--line-height`, `var(--u-text-${name}-line-height)`],
...('weight' in step ? [[`--text-${name}--font-weight`, `var(--u-text-${name}-weight)`] as [string, string]] : []),
...('letterSpacing' in step
? [[`--text-${name}--letter-spacing`, `var(--u-text-${name}-letter-spacing)`] as [string, string]]
: []),
])
}

export function tokensCss(version: string): string {
const lightColors = colorNames.map((n): [string, string] => [`--u-${n}`, colors.light[n]])
const darkColors = colorNames.map((n): [string, string] => [`--u-${n}`, colors.dark[n]])
Expand All @@ -111,6 +133,7 @@ export function tokensCss(version: string): string {
['--u-duration-fast', motion.fast],
['--u-duration-slow', motion.slow],
['--u-ease', motion.ease],
...typeTokens(),
]
return `${header(version, 'raw tokens')}
:root {
Expand Down Expand Up @@ -150,6 +173,7 @@ ${declarations([
['--font-mono', 'var(--u-font-mono)'],
...radiusEntries,
...shadowEntries,
...typeTheme(),
['--ease-standard', 'var(--u-ease)'],
['--default-transition-duration', 'var(--u-duration-fast)'],
['--default-transition-timing-function', 'var(--u-ease)'],
Expand Down Expand Up @@ -179,6 +203,8 @@ export function baseCss(version: string): string {
background-color: var(--u-bg);
color: var(--u-fg);
font-family: var(--u-font-sans);
font-size: var(--u-text-body);
line-height: var(--u-text-body-line-height);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tokens/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type ColorName, type ColorScale, colorNames, colors, type Mode } from '

export { chroma, contrast, lightness, toHex } from './color.ts'
export type { ColorName, ColorScale, Mode } from './tokens.ts'
export { categorical, colorNames, colors, fonts, motion, ordinal, radii, shadows } from './tokens.ts'
export { categorical, colorNames, colors, fonts, motion, ordinal, radii, shadows, typeScale } from './tokens.ts'

function toHexScale(scale: ColorScale): ColorScale {
const out = {} as ColorScale
Expand Down
14 changes: 9 additions & 5 deletions tokens/src/map-style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* The Unitae map style: Protomaps vector tiles painted with the map tokens, labels in IBM Plex.
* The Unitae map style: Protomaps vector tiles painted with the map tokens, labels in IBM Plex letterforms.
*
* A quiet grey ground for our pins: no places, shops, transport, shields or one-way arrows, and no house numbers —
* the pins already carry the numbers the lists show, and a second set of numbers would confuse. Nothing draws an
Expand All @@ -11,11 +11,15 @@ import { type Flavor, layers } from '@protomaps/basemaps'
import { hexColors } from './index.ts'
import type { Mode } from './tokens.ts'

/** The glyph font stacks the style asks for. The host serves them under the `glyphs` address. */
/**
* The glyph font stacks the style asks for; the host serves them under the `glyphs` address. They are IBM Plex Sans
* turned into map glyphs, under another name: the font's licence (OFL 1.1) reserves the name « Plex » for unmodified
* versions, and glyphs are a modified version. Ship the OFL and IBM's copyright with them.
*/
export const MAP_FONTS = {
regular: 'IBM Plex Sans Regular',
medium: 'IBM Plex Sans Medium',
italic: 'IBM Plex Sans Italic',
regular: 'Unitae Map Regular',
medium: 'Unitae Map Medium',
italic: 'Unitae Map Italic',
} as const

/** Who must be credited wherever the map shows: the tiles and the data under them. */
Expand Down
12 changes: 12 additions & 0 deletions tokens/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ export const radii = {
'3xl': '10px',
} as const

/**
* Type scale, at the round-1 density (14 px body), from the canvas tokens of direction D. Semantic names only:
* Tailwind's own `text-xs` … `text-xl` keep their sizes, so existing markup does not move. `h1` is the page title,
* `h2` a section or panel title, `metric` a headline number, `body` the running text.
*/
export const typeScale = {
body: { size: '0.875rem', lineHeight: '1.375rem' },
h2: { size: '0.9375rem', lineHeight: '1.375rem', weight: '600' },
h1: { size: '1.5rem', lineHeight: '2rem', weight: '600', letterSpacing: '-0.01em' },
metric: { size: '1.625rem', lineHeight: '2rem', weight: '600', letterSpacing: '-0.01em' },
} as const

/** Motion: fast and keyboard-like. Respect `prefers-reduced-motion` (see base.css). */
export const motion = {
fast: '120ms',
Expand Down
28 changes: 28 additions & 0 deletions tokens/test/__snapshots__/tokens.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ exports[`generated CSS > base.css 1`] = `
background-color: var(--u-bg);
color: var(--u-fg);
font-family: var(--u-font-sans);
font-size: var(--u-text-body);
line-height: var(--u-text-body-line-height);
}
}

Expand Down Expand Up @@ -142,6 +144,19 @@ exports[`generated CSS > theme.css 1`] = `
--shadow-lg: var(--u-shadow-lg);
--shadow-xl: var(--u-shadow-xl);
--shadow-2xl: var(--u-shadow-2xl);
--text-body: var(--u-text-body);
--text-body--line-height: var(--u-text-body-line-height);
--text-h2: var(--u-text-h2);
--text-h2--line-height: var(--u-text-h2-line-height);
--text-h2--font-weight: var(--u-text-h2-weight);
--text-h1: var(--u-text-h1);
--text-h1--line-height: var(--u-text-h1-line-height);
--text-h1--font-weight: var(--u-text-h1-weight);
--text-h1--letter-spacing: var(--u-text-h1-letter-spacing);
--text-metric: var(--u-text-metric);
--text-metric--line-height: var(--u-text-metric-line-height);
--text-metric--font-weight: var(--u-text-metric-weight);
--text-metric--letter-spacing: var(--u-text-metric-letter-spacing);
--ease-standard: var(--u-ease);
--default-transition-duration: var(--u-duration-fast);
--default-transition-timing-function: var(--u-ease);
Expand Down Expand Up @@ -247,6 +262,19 @@ exports[`generated CSS > tokens.css 1`] = `
--u-duration-fast: 120ms;
--u-duration-slow: 240ms;
--u-ease: cubic-bezier(0.2, 0, 0, 1);
--u-text-body: 0.875rem;
--u-text-body-line-height: 1.375rem;
--u-text-h2: 0.9375rem;
--u-text-h2-line-height: 1.375rem;
--u-text-h2-weight: 600;
--u-text-h1: 1.5rem;
--u-text-h1-line-height: 2rem;
--u-text-h1-weight: 600;
--u-text-h1-letter-spacing: -0.01em;
--u-text-metric: 1.625rem;
--u-text-metric-line-height: 2rem;
--u-text-metric-weight: 600;
--u-text-metric-letter-spacing: -0.01em;
}

.dark,
Expand Down
6 changes: 4 additions & 2 deletions tokens/test/map-style.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { Mode } from '../src/tokens.ts'

const modes: Mode[] = ['light', 'dark']
const HEX = /#[0-9a-f]{6}\b/gi
// A font stack named in a layer: « Unitae Map Regular », « Noto Sans Devanagari Regular v1 »…
const FONT_NAME = /"[^"]* (?:Regular|Medium|Italic|Bold)(?: v\d+)?"/g

const style = (mode: Mode, lang = 'fr') =>
mapStyle({ mode, lang, tiles: '/tiles/2026-11/{z}/{x}/{y}.mvt', glyphs: '/map-fonts/{fontstack}/{range}.pbf' })
Expand Down Expand Up @@ -73,7 +75,7 @@ describe('mapStyle', () => {
expect(ids).toContain('buildings')
})

it('sets every label in IBM Plex (Devanagari names keep the Noto face Protomaps asks for)', () => {
it('sets every label in the map fonts (Devanagari names keep the Noto face Protomaps asks for)', () => {
const allowed = new Set([...Object.values(MAP_FONTS), 'Noto Sans Devanagari Regular v1'])
const fonts = style('light')
.layers.filter((layer) => layer.type === 'symbol')
Expand All @@ -83,7 +85,7 @@ describe('mapStyle', () => {
('text-font' in layout && layout['text-font']) || [],
'text-field' in layout ? layout['text-field'] : [],
])
return text.match(/"[^"]*Sans[^"]*"/g) ?? []
return text.match(FONT_NAME) ?? []
})
.map((quoted) => JSON.parse(quoted) as string)
expect(fonts).toContain(MAP_FONTS.regular)
Expand Down
43 changes: 42 additions & 1 deletion tokens/test/tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest'
import { chroma, contrast, lightness } from '../src/color.ts'
import { baseCss, fontsCss, themeColors, themeCss, tokensCss } from '../src/css.ts'
import { hexColors } from '../src/index.ts'
import { type ColorName, colorNames, colors, type Mode, ordinal } from '../src/tokens.ts'
import { type ColorName, colorNames, colors, type Mode, ordinal, typeScale } from '../src/tokens.ts'

const modes: Mode[] = ['light', 'dark']
const HEX = /^#[0-9a-f]{6}$/
Expand Down Expand Up @@ -114,6 +114,12 @@ describe('map', () => {
expect(ratio(mode, 'primary', 'map-ground')).toBeGreaterThanOrEqual(3)
})

it(`${mode}: a free entrance's dashed ring stands out from the ground (3:1)`, () => {
// MapDot « free »: a dashed ring in the faint grey (light) or the muted grey (dark), over the map's ground.
const ring = mode === 'light' ? colors.light['fg-faint'] : colors.dark['fg-muted']
expect(contrast(ring, colors[mode]['map-ground'])).toBeGreaterThanOrEqual(3)
})

it(`${mode}: the map stays grey — no fill is more colourful than a hint`, () => {
for (const fill of ['map-ground', ...fills] as ColorName[]) {
expect(chroma(colors[mode][fill])).toBeLessThan(0.03)
Expand Down Expand Up @@ -219,6 +225,41 @@ describe('Tailwind theme', () => {
})
})

describe('type scale', () => {
// Round 1 set the density at a 14 px body; the canvas tokens of direction D draw a 24 px page title, 15 px section
// titles and 26 px headline numbers. The apps' own text-xs / sm / base keep their Tailwind sizes.
const px = (rem: string) => Number.parseFloat(rem) * 16

it('sets the body at 14 px, the page title at 24, section titles at 15 and headline numbers at 26', () => {
expect(px(typeScale.body.size)).toBe(14)
expect(px(typeScale.h1.size)).toBe(24)
expect(px(typeScale.h2.size)).toBe(15)
expect(px(typeScale.metric.size)).toBe(26)
})

it('gives every step a line height at least as tall as its size', () => {
for (const step of Object.values(typeScale)) expect(px(step.lineHeight)).toBeGreaterThanOrEqual(px(step.size))
})

it('maps each step onto a Tailwind text utility with its line height, and its weight where it has one', () => {
const theme = themeCss('0.0.0')
for (const [name, step] of Object.entries(typeScale)) {
expect(theme).toContain(`--text-${name}: var(--u-text-${name});`)
expect(theme).toContain(`--text-${name}--line-height: var(--u-text-${name}-line-height);`)
if ('weight' in step) expect(theme).toContain(`--text-${name}--font-weight: var(--u-text-${name}-weight);`)
}
})

it('leaves Tailwind’s own text sizes alone, so existing markup keeps its size', () => {
const theme = themeCss('0.0.0')
for (const name of ['xs', 'sm', 'base', 'lg', 'xl']) expect(theme).not.toContain(`--text-${name}:`)
})

it('sets the body size in the optional element defaults', () => {
expect(baseCss('0.0.0')).toContain('font-size: var(--u-text-body);')
})
})

describe('fonts', () => {
it('imports only files that exist in @fontsource/ibm-plex-sans', () => {
const require = createRequire(import.meta.url)
Expand Down
Loading
Loading