@sutton-signwriting/core
Version: 
a javascript package for node and browsers that supports general processing of the Sutton SignWriting script
571 lines (570 loc) âĒ 13.7 kB
TypeScript
export const __esModule: boolean;
/**
 * Function to convert a code point on plane 4 to an SWU symbol character
 * @function convert.code2swu
 * @param {number} code - Code point on plane 4
 * @returns {string} SWU symbol character
 * @example
 * convert.code2swu(0x40001)
 *
 * return 'ņ'
 */
export function code2swu(code: number): string;
/**
 * Function to convert an array of x,y integers to an FSW coordinate string
 * @function convert.coord2fsw
 * @param {number[]} coord - Array of x,y integers
 * @returns {string} An FSW coordinate string
 * @example
 * convert.coord2fsw([500, 500])
 *
 * return '500x500'
 */
export function coord2fsw(coord: number[]): string;
/**
 * Function to convert an array of x,y integers to two SWU number characters
 * @function convert.coord2swu
 * @param {number[]} coord - Array of x,y integers
 * @returns {string} Two SWU number character
 * @example
 * convert.coord2swu([500, 500])
 *
 * return 'ðĪðĪ'
 */
export function coord2swu(coord: number[]): string;
/**
 * Function to convert an FSW coordinate string to an array of x,y integers
 * @function convert.fsw2coord
 * @param {string} fswCoord - An FSW coordinate string
 * @returns {number[]} Array of x,y integers
 * @example
 * convert.fsw2coord('500x500')
 *
 * return [500, 500]
 */
export function fsw2coord(fswCoord: string): number[];
/**
 * Function to convert FSW text to SWU text
 * @function convert.fsw2swu
 * @param {string} fswText - FSW text
 * @returns {string} SWU text
 * @example
 * convert.fsw2swu('AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475')
 *
 * return 'ð ņņņĨņĐð ðĪðĪĐņĐðĢĩðĪņðĪðĢĪņĨðĪðĪņðĢŪðĢ'
 */
export function fsw2swu(fswText: string): string;
/**
 * Function to convert a 16-bit ID to an FSW symbol key
 * @function convert.id2key
 * @param {number} id - 16-bit ID
 * @returns {string} FSW symbol key
 * @example
 * convert.id2key(1)
 *
 * return 'S10000'
 */
export function id2key(id: number): string;
/**
 * Function to convert a 16-bit ID to an SWU symbol character
 * @function convert.id2swu
 * @param {number} id - 16-bit ID
 * @returns {string} SWU symbol character
 * @example
 * convert.id2swu(1)
 *
 * return 'ņ'
 */
export function id2swu(id: number): string;
/**
 * Function to convert an FSW symbol key to a 16-bit ID
 * @function convert.key2id
 * @param {string} key - FSW symbol key
 * @returns {number} 16-bit ID
 * @example
 * convert.key2id('S10000')
 *
 * return 1
 */
export function key2id(key: string): number;
/**
 * Function to convert an FSW symbol key to an SWU symbol character
 * @function convert.key2swu
 * @param {string} key - FSW symbol key
 * @returns {string} SWU symbol character
 * @example
 * convert.key2swu('S10000')
 *
 * return 'ņ'
 */
export function key2swu(key: string): string;
/**
 * Function to convert base or full key to symid
 * @function convert.key2symid
 * @param {string} key - Symbol key
 * @returns {string} Symbol ID
 * @example
 * convert.key2symid('S100')
 *
 * return '01-01-001-01'
 * @example
 * convert.key2symid('S1005f')
 *
 * return '01-01-001-01-06-16'
 */
export function key2symid(key: string): string;
/**
 * Function to convert an FSW structural marker to SWU equivalent
 * @function convert.mark2swu
 * @param {string} fswMark - character for FSW structural marker
 * @returns {string} SWU structural marker
 * @example
 * convert.mark2swu('A')
 *
 * return 'ð '
 */
export function mark2swu(fswMark: string): string;
/**
 * Function to convert a number to an SWU number character
 * @function convert.num2swu
 * @param {number} num - Integer value for number
 * @returns {string} SWU number character
 * @example
 * convert.num2swu(500)
 *
 * return 'ðĪ'
 */
export function num2swu(num: number): string;
/**
 * Function to convert an SWU symbol character to a code point on plane 4
 * @function convert.swu2code
 * @param {string} swuSym - SWU symbol character
 * @returns {number} Code point on plane 4
 * @example
 * convert.swu2code('ņ')
 *
 * return 0x40001
 */
export function swu2code(swuSym: string): number;
/**
 * Function to convert two SWU number characters to an array of x,y integers
 * @function convert.swu2coord
 * @param {string} swuCoord - Two SWU number character
 * @returns {number[]} Array of x,y integers
 * @example
 * convert.swu2coord('ðĪðĪ')
 *
 * return [500, 500]
 */
export function swu2coord(swuCoord: string): number[];
/**
 * Function to convert SWU text to FSW text
 * @function convert.swu2fsw
 * @param {string} swuText - SWU text
 * @returns {string} FSW text
 * @example
 * convert.swu2fsw('ð ņņņĨņĐð ðĪðĪĐņĐðĢĩðĪņðĪðĢĪņĨðĪðĪņðĢŪðĢ')
 *
 * return 'AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475'
 */
export function swu2fsw(swuText: string): string;
/**
 * Function to convert an SWU symbol character to a 16-bit ID
 * @function convert.swu2id
 * @param {string} swuSym - SWU symbol character
 * @returns {number} 16-bit ID
 * @example
 * convert.swu2id('ņ')
 *
 * return 1
 */
export function swu2id(swuSym: string): number;
/**
 * Function to convert an SWU symbol character to an FSW symbol key
 * @function convert.swu2key
 * @param {string} swuSym - SWU symbol character
 * @returns {string} FSW symbol key
 * @example
 * convert.swu2key('ņ')
 *
 * return 'S10000'
 */
export function swu2key(swuSym: string): string;
/** The convert module contains functions to convert between Formal SignWriitng in ASCII (FSW) and SignWriting in Unicode (SWU) characters, along with other types of data.
 * [Characters set definitions](https://tools.ietf.org/id/draft-slevinski-formal-signwriting-09.html#name-characters)
 * @module convert
 */
/**
 * Function to convert an SWU structural marker to FSW equivalent
 * @function convert.swu2mark
 * @param {string} swuMark - character for SWU structural marker
 * @returns {string} FSW structural marker
 * @example
 * convert.swu2mark('ð ')
 *
 * return 'A'
 */
export function swu2mark(swuMark: string): string;
/**
 * Function to convert an SWU number character to an integer
 * @function convert.swu2num
 * @param {string} swuNum - SWU number character
 * @returns {number} Integer value for number
 * @example
 * convert.swu2num('ðĪ')
 *
 * return 500
 */
export function swu2num(swuNum: string): number;
/**
 * Function to convert base or full symid to key
 * @function convert.symid2key
 * @param {string} symid - Symbol ID
 * @returns {string} Symbol key
 * @example
 * convert.symid2key('01-01-001-01')
 *
 * return 'S100'
 * @example
 * convert.symid2key('01-01-001-01-06-16')
 *
 * return 'S1005f'
 */
export function symid2key(symid: string): string;
/**
 * An array of symbol IDs in minimized format such as "101011"
 *
 * @alias convert.symidArr
 * @type {string[]}
 */
export const symidArr: string[];
/**
 * Function to convert base or full symid Min to symid Max
 * @function convert.symidMax
 * @param {string} symidMin - Symbol ID minimized
 * @returns {string} Symbol ID maximized
 * @example
 * convert.symidMax('101011')
 *
 * return '01-01-001-01'
 * @example
 * convert.symidMax('101011616')
 *
 * return '01-01-001-01-06-16'
 */
export function symidMax(symidMin: string): string;
/**
 * Function to convert base or full symid Max to symid Min
 * @function convert.symidMin
 * @param {string} symidMax - Symbol ID maximized
 * @returns {string} Symbol ID minimized
 * @example
 * convert.symidMin('01-01-001-01')
 *
 * return '101011'
 * @example
 * convert.symidMin('01-01-001-01-06-16')
 *
 * return '101011616'
 */
export function symidMin(symidMax: string): string;
/**
 * Object of query elements with regular expression identification.
 */
type QueryObject = {
    /**
     * - required true for query object
     */
    query: boolean;
    /**
     * - an object for prefix elements
     */
    prefix?: {
        required: boolean;
        parts?: (string | string[] | (string | string[])[])[];
    };
    /**
     * - array of objects for symbols, ranges, and list of symbols or ranges, with optional coordinates
     */
    signbox?: (QuerySignboxSymbol | QuerySignboxRange | QuerySignboxOr)[];
    /**
     * - amount that x or y coordinates can vary and find a match, defaults to 20
     */
    variance?: number;
    /**
     * - boolean value for including style string in matches
     */
    style?: boolean;
};
type QuerySignboxSymbol = {
    /**
     * - a symbol
     */
    symbol: string;
    /**
     * - an optional coordinate
     */
    coord?: number[];
};
type QuerySignboxRange = {
    /**
     * - an array of two symbols
     */
    range: string[];
    /**
     * - an optional coordinate
     */
    coord?: number[];
};
type QuerySignboxOr = {
    /**
     * - an array of symbol strings and range arrays
     */
    or: (string | string[])[];
    /**
     * - an optional coordinate
     */
    coord?: number[];
};
type ColumnOptions = {
    /**
     * - the height of the columns
     */
    height?: number;
    /**
     * - the widths of the columns
     */
    width?: number;
    /**
     * - the lane offset for left and right lanes
     */
    offset?: number;
    /**
     * - amount of padding before and after signs as well as at top, left, and right of columns
     */
    pad?: number;
    /**
     * - amount of space at bottom of column that is not available
     */
    margin?: number;
    /**
     * - enables variable width columns
     */
    dynamic?: boolean;
    /**
     * - background color for columns
     */
    background?: string;
    /**
     * - an object of style options
     */
    style?: StyleObject;
    /**
     * - an object of punctuation options
     */
    punctuation?: {
        spacing?: boolean;
        pad?: number;
        pull?: boolean;
    };
};
type ColumnData = ColumnSegment[];
type ColumnSegment = {
    /**
     * - the x position in the column
     */
    x: number;
    /**
     * - the y position in the column
     */
    y: number;
    /**
     * - the min x value within the segment
     */
    minX: number;
    /**
     * - the min y value within the segment
     */
    minY: number;
    /**
     * - the width of the text segment
     */
    width: number;
    /**
     * - the height of the text segment
     */
    height: number;
    /**
     * - Left as -1, Middle as 0, Right as 1
     */
    lane: number;
    /**
     * - the padding of the text segment affects colored background
     */
    padding: number;
    /**
     * - "sign" or "symbol"
     */
    segment: string;
    /**
     * - the text of the sign or symbol with optional style string
     */
    text: string;
    /**
     * - the zoom size of the segment
     */
    zoom: number;
};
type SegmentInfo = {
    /**
     * - the min x value within the segment
     */
    minX: number;
    /**
     * - the min y value within the segment
     */
    minY: number;
    /**
     * - the width of the text segment
     */
    width: number;
    /**
     * - the height of the text segment
     */
    height: number;
    /**
     * - Left as -1, Middle as 0, Right as 1
     */
    lane: number;
    /**
     * - the padding of the text segment affects colored background
     */
    padding: number;
    /**
     * - "sign" or "symbol"
     */
    segment: string;
    /**
     * - the zoom size of the segment
     */
    zoom: number;
};
/**
 * The elements of a style string
 */
type StyleObject = {
    /**
     * - boolean to use standardized colors for symbol groups
     */
    colorize?: boolean;
    /**
     * - integer value for padding around symbol or sign
     */
    padding?: number;
    /**
     * - css name or hex color for background
     */
    background?: string;
    /**
     * - array for css name or hex color for line and optional fill
     */
    detail?: string[];
    /**
     * - decimal value for zoom level
     */
    zoom?: number;
    /**
     * - custom colors for individual symbols
     */
    detailsym?: {
        index: number;
        detail: string[];
    };
    /**
     * - list of class names separated with spaces used for SVG
     */
    classes?: string;
    /**
     * - id name used for SVG
     */
    id?: string;
};
/**
 * The elements of a symbol string
 */
type SymbolObject = {
    /**
     * - symbol identifier
     */
    symbol?: string;
    /**
     * - x,y coordinate
     */
    coord?: number[];
    /**
     * - style string
     */
    style?: string;
};
/**
 * The elements of a sign string
 */
type SignObject = {
    /**
     * - array of symbols
     */
    sequence?: string[];
    /**
     * - signbox marker or lane
     */
    box?: string;
    /**
     * - preprocessed x,y coordinate
     */
    max?: number[];
    /**
     * - array of symbols with coordinates
     */
    spatials?: {
        symbol: string;
        coord: number[];
    }[];
    /**
     * - style string
     */
    style?: string;
};
type TokenizerObject = {
    /**
     * - Index to string mapping
     */
    i2s: any;
    /**
     * - String to index mapping
     */
    s2i: any;
    /**
     * - Total number of tokens
     */
    length: number;
    /**
     * - Returns array of all tokens
     */
    vocab: Function;
    /**
     * - Encodes a string of SignWriting to token indices
     */
    encode: Function;
    /**
     * - Decodes token indices to a string of SignWriting
     */
    decode: Function;
    /**
     * - Encodes an array of token strings to token indices
     */
    encodeTokens: Function;
    /**
     * - Decodes an array of token indices to token strings
     */
    decodeTokens: Function;
};