AI-native design editor. Open-source Figma alternative.
import { describe, expect, test } from 'bun:test'
import { textFontFeatures, textFontVariations, textHeightBehaviorValue } from '#core/canvas/text'
describe('canvas text font variations', () => {
test('maps imported leading trim to CanvasKit text height behavior', () => {
const ck = {
TextHeightBehavior: {
DisableAll: 'disable-all'
}
}
expect(textHeightBehaviorValue(ck, 'CAP_HEIGHT')).toBe('disable-all')
expect(textHeightBehaviorValue(ck, 'NONE')).toBeUndefined()
})
test('passes imported variable font axes to CanvasKit text styles', () => {
expect(
textFontVariations([
{ axis: 'wght', value: 650 },
{ axis: 'wdth', value: 88 }
])
).toEqual([
{ axis: 'wght', value: 650 },
{ axis: 'wdth', value: 88 }
])
})
test('omits font variations when no axes are set', () => {
expect(textFontVariations([])).toBeUndefined()
expect(textFontVariations(undefined)).toBeUndefined()
expect(textFontVariations(undefined, [])).toBeUndefined()
})
test('applies named-instance axes of a variable face under explicit axes', () => {
const medium = [
{ axis: 'wdth', value: 100 },
{ axis: 'wght', value: 510 }
]
expect(textFontVariations(undefined, medium)).toEqual(medium)
expect(textFontVariations([{ axis: 'wght', value: 650 }], medium)).toEqual([
{ axis: 'wdth', value: 100 },
{ axis: 'wght', value: 650 }
])
})
test('passes imported OpenType feature toggles to CanvasKit text styles', () => {
expect(
textFontFeatures([
{ tag: 'LIGA', enabled: false },
{ tag: 'CALT', enabled: true },
{ tag: 'SS01', enabled: true }
])
).toEqual([
{ name: 'liga', value: 0 },
{ name: 'calt', value: 1 },
{ name: 'ss01', value: 1 }
])
})
test('omits font features when no toggles are set', () => {
expect(textFontFeatures([])).toBeUndefined()
expect(textFontFeatures(undefined)).toBeUndefined()
})
})