scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
234 lines (190 loc) • 6.36 kB
text/typescript
import {AbsFont} from 'scriptable-abstract';
// Font family constants with strict typing
export const FONT_FAMILY: Readonly<{
SFUI: Readonly<Record<string, string>>;
MENLO: Readonly<Record<string, string>>;
SFUI_ROUNDED: Readonly<Record<string, string>>;
}> = {
SFUI: {
REGULAR: '.SFUI-Regular',
ULTRALIGHT: '.SFUI-Ultralight',
THIN: '.SFUI-Thin',
LIGHT: '.SFUI-Light',
MEDIUM: '.SFUI-Medium',
SEMIBOLD: '.SFUI-Semibold',
BOLD: '.SFUI-Bold',
HEAVY: '.SFUI-Heavy',
BLACK: '.SFUI-Black',
ITALIC: '.SFUI-RegularItalic',
},
MENLO: {
ULTRALIGHT: 'Menlo-UltraLight',
THIN: 'Menlo-Thin',
LIGHT: 'Menlo-Light',
REGULAR: 'Menlo-Regular',
MEDIUM: 'Menlo-Medium',
SEMIBOLD: 'Menlo-Semibold',
BOLD: 'Menlo-Bold',
HEAVY: 'Menlo-Heavy',
BLACK: 'Menlo-Black',
},
SFUI_ROUNDED: {
ULTRALIGHT: '.SFUIRounded-Ultralight',
THIN: '.SFUIRounded-Thin',
LIGHT: '.SFUIRounded-Light',
REGULAR: '.SFUIRounded-Regular',
},
} as const;
// Font size constants with strict typing
export const FONT_SIZE: Readonly<Record<string, number>> = {
LARGE_TITLE: 34,
TITLE1: 28,
TITLE2: 22,
TITLE3: 20,
HEADLINE: 17,
SUBHEADLINE: 15,
BODY: 17,
CALLOUT: 16,
FOOTNOTE: 13,
CAPTION1: 12,
CAPTION2: 11,
DEFAULT: 12,
} as const;
interface FontState {
name?: string;
size: number;
methodCalls: string[];
}
const DEFAULT_STATE: Readonly<FontState> = {
size: FONT_SIZE.DEFAULT,
methodCalls: [],
};
export class MockFont extends AbsFont<FontState> {
constructor(name?: string, size?: number) {
super({
...DEFAULT_STATE,
name,
size: size ?? DEFAULT_STATE.size,
methodCalls: ['constructor'],
});
}
get asFont(): Font {
return this as unknown as Font;
}
protected getState(): Readonly<FontState> {
return this.state;
}
// Factory method for creating system fonts
private static createSystemFont(family: string, size: number): Font {
return new this(family, size).asFont;
}
// Standard text styles
static largeTitle(): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, FONT_SIZE.LARGE_TITLE);
}
static title1(): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, FONT_SIZE.TITLE1);
}
static title2(): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, FONT_SIZE.TITLE2);
}
static title3(): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, FONT_SIZE.TITLE3);
}
static headline(): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.SEMIBOLD, FONT_SIZE.HEADLINE);
}
static subheadline(): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, FONT_SIZE.SUBHEADLINE);
}
static body(): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, FONT_SIZE.BODY);
}
static callout(): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, FONT_SIZE.CALLOUT);
}
static footnote(): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, FONT_SIZE.FOOTNOTE);
}
static caption1(): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, FONT_SIZE.CAPTION1);
}
static caption2(): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, FONT_SIZE.CAPTION2);
}
// System fonts
static systemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, size);
}
static ultraLightSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.ULTRALIGHT, size);
}
static thinSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.THIN, size);
}
static lightSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.LIGHT, size);
}
static regularSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.REGULAR, size);
}
static mediumSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.MEDIUM, size);
}
static semiboldSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.SEMIBOLD, size);
}
static boldSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.BOLD, size);
}
static heavySystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.HEAVY, size);
}
static blackSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.BLACK, size);
}
static italicSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI.ITALIC, size);
}
// Monospaced system fonts
static ultraLightMonospacedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.MENLO.ULTRALIGHT, size);
}
static thinMonospacedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.MENLO.THIN, size);
}
static lightMonospacedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.MENLO.LIGHT, size);
}
static regularMonospacedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.MENLO.REGULAR, size);
}
static mediumMonospacedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.MENLO.MEDIUM, size);
}
static semiboldMonospacedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.MENLO.SEMIBOLD, size);
}
static boldMonospacedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.MENLO.BOLD, size);
}
static heavyMonospacedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.MENLO.HEAVY, size);
}
static blackMonospacedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.MENLO.BLACK, size);
}
// Rounded system fonts
static ultraLightRoundedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI_ROUNDED.ULTRALIGHT, size);
}
static thinRoundedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI_ROUNDED.THIN, size);
}
static lightRoundedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI_ROUNDED.LIGHT, size);
}
static regularRoundedSystemFont(size: number): Font {
return this.createSystemFont(FONT_FAMILY.SFUI_ROUNDED.REGULAR, size);
}
}