UNPKG

signal-flags

Version:

Generate SVG for flags from the International Code of Signals and Racing Rules of Sailing.

237 lines (236 loc) 7.38 kB
declare module "colour" { export type ColourSet = { outline: string; black: string; blue: string; green: string; red: string; yellow: string; white: string; orange: string; }; const colourSets: Record<string, ColourSet>; /** * Get a colour value. * * @param name * @param colourSet * @returns */ export const getColour: (name: string, colourSet?: keyof typeof colourSets | Record<string, string>) => string; } declare module "design/swallowtail" { import { type DesignSet } from "design/index"; export const swallowtail: DesignSet; } declare module "design/rectangle" { import { type DesignSet } from "design/index"; export const rectangle: DesignSet; } declare module "design/pennant" { import { type DesignSet } from "design/index"; export const pennant: DesignSet; } declare module "design/triangle" { import { type DesignSet } from "design/index"; export const triangle: DesignSet; } declare module "design/index" { import { type Flag } from "flag"; export type FlagShape = keyof typeof designs; export interface BuildOptions { dimensions?: number[] | string; file?: boolean; dataUri?: boolean; } export interface DesignOptions { dimensions?: Record<string, Record<string, string | number[]>>; outline?: number | boolean; clrSet?: string | Record<string, string>; } export interface DesignSettings { dimensions: number[]; outline: number | false; clrSet?: string | Record<string, string>; } export type DrawFunction = (flag: Flag, options: DesignSettings) => string; export type OutlineFunction = (options: DesignSettings) => string; export interface DesignSet { dimensions: Record<string, number[]>; outline: OutlineFunction; designs: Record<string, DrawFunction>; } const designs: { swallowtail: DesignSet; rectangle: DesignSet; pennant: DesignSet; triangle: DesignSet; }; /** * Get the numerical dimensions from a complicated series of potential * overrides. * * @param designSet * @param options * @param flag * @returns */ export const getNumericalDimensions: (designSet: DesignSet, options: DesignOptions, flag: Flag) => number[]; /** * Build the SVG for a flag. * * @param flag * @param design * @param options * @returns */ export const getSvg: (flag: Flag, designOptions?: DesignOptions, options?: BuildOptions) => string; } declare module "flag" { import { type FlagShape } from "design/index"; export interface Flag { /** Machine-readable name for use e.g. as a filename. */ slug?: string; /** International Code of Signals or the Racing Rules of Sailing. */ category: 'ics' | 'rrs' | 'naval-numeral' | 'beach'; /** rectangle, pennant, triangle or swallowtail */ shape: FlagShape; /** Force a card shape for increase/decrease/toPort/toStarboard, also to force square * for some naval numerals? */ dimensions?: 'default' | 'long' | 'square' | 'card'; /** e.g. solid, diagonalQuarters... */ design: string; /** Array of colours for the flag. */ clrs: string[]; /** For check designs n x n. */ n?: number; /** For variable-width stripes. */ widths?: number[]; } } declare module "flag-set" { import { type Flag } from "flag"; export type FlagSet = Record<string, Flag>; export const flags: FlagSet; } declare module "meta" { export const version = "4.2.0"; export const generator = "https://github.com/signal-flags/signal-flags-ts"; } declare module "generate" { import { type Flag } from "flag"; import { type FlagSet } from "flag-set"; import { getSvg, type DesignOptions, type BuildOptions } from "design/index"; export { getSvg }; export type FilterFunction = (flag: Flag) => boolean; /** * Generate default svg for all flags. * * @param flags * @param design * @param build * @returns */ export const allSvg: (flags?: FlagSet | null, designOptions?: DesignOptions | null, buildOptions?: BuildOptions) => Record<string, string>; /** * Generate svg for a filtered subset of flags in a set. * * @param flags Source flagset. * @param designOptions * @param buildOptions * @param filter Filter function. * @returns */ export const someSvg: (flags: FlagSet | null, designOptions: DesignOptions | null, buildOptions: BuildOptions | null, filter: FilterFunction) => Record<string, string>; /** * Generate default flags. * @param flags * @param buildOptions * @returns */ export const generateDefault: (flags?: FlagSet | null, buildOptions?: BuildOptions) => { meta: { generator: string; version: string; generated: string; }; flags: FlagSet; options: DesignOptions; svg: Record<string, string>; }; /** * Generate all long pennants. * * @param flags * @param buildOptions * @returns */ export const generateLong: (flags?: FlagSet | null, buildOptions?: BuildOptions) => { meta: { generator: string; version: string; generated: string; }; flags: FlagSet; options: DesignOptions; svg: Record<string, string>; }; /** * Generate all short pennants. * * @param flags * @param buildOptions * @returns */ export const generateShort: (flags?: FlagSet | null, buildOptions?: BuildOptions) => { meta: { generator: string; version: string; generated: string; }; flags: FlagSet; options: DesignOptions; svg: Record<string, string>; }; /** * Generate all flags with square alphabet flags. * @param flags * @param buildOptions * @returns */ export const generateSquare: (flags?: FlagSet | null, buildOptions?: BuildOptions) => { meta: { generator: string; version: string; generated: string; }; flags: FlagSet; options: DesignOptions; svg: Record<string, string>; }; /** * Generate hideous primary coloured flags with no outlines which WikiPedia * seems to like. * * @param flags * @param buildOptions * @returns */ export const generatePrimary: (flags?: FlagSet | null, buildOptions?: BuildOptions) => { meta: { generator: string; version: string; generated: string; }; flags: FlagSet; options: DesignOptions; svg: Record<string, string>; }; } declare module "signal-flags" { export type { Flag } from "flag"; export type { DesignOptions, BuildOptions } from "design/index"; export { flags } from "flag-set"; export { version } from "meta"; export { getSvg, allSvg, someSvg, generateDefault, generateLong, generatePrimary, generateSquare, generateShort, } from "generate"; }