UNPKG

@sutton-signwriting/core

Version:

a javascript package for node and browsers that supports general processing of the Sutton SignWriting script

579 lines (578 loc) 13.8 kB
export const __esModule: boolean; /** * Array of numbers for categories of symbols: hand, movement, dynamics, head, trunk & limb, location, and punctuation. * @alias fsw.category * @type {number[]} */ export const category: number[]; /** * Function that returns the standardized color for a symbol. * @function fsw.colorize * @param {string} key - an FSW symbol key * @returns {string} name of standardized color for symbol * @example * fsw.colorize('S10000') * * return '#0000CC' */ export function colorize(key: string): string; /** * Array of colors associated with the seven symbol categories. * @alias fsw.colors * @type {string[]} */ export const colors: string[]; export namespace columnDefaults { const height: number; const width: number; const offset: number; const pad: number; const margin: number; const dynamic: boolean; const background: any; namespace punctuation { export const spacing: boolean; const pad_1: number; export { pad_1 as pad }; export const pull: boolean; } namespace style { const detail: string[]; const zoom: number; } } /** * Function to an object of column options with default values * * @function fsw.columnDefaultsMerge * @param {ColumnOptions} options - object of column options * @returns {ColumnOptions} object of column options merged with column defaults * @example * fsw.columnDefaultsMerge({height: 500,width:150}) * * return { * "height": 500, * "width": 150, * "offset": 50, * "pad": 20, * "margin": 5, * "dynamic": false, * "punctuation": { * "spacing": true, * "pad": 30, * "pull": true * }, * "style": { * "detail": [ * "black", * "white" * ], * "zoom": 1 * } * } */ export function columnDefaultsMerge(options: ColumnOptions): ColumnOptions; /** * Function to transform an FSW text to an array of columns * * @function fsw.columns * @param {string} fswText - FSW text of signs and punctuation * @param {ColumnOptions} options - object of column options * @returns {{options:ColumnOptions,widths:number[],columns:ColumnData}} object of column options, widths array, and column data * @example * fsw.columns('AS14c20S27106M518x529S14c20481x471S27106503x489 AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468 S38800464x496', {height: 500,width:150}) * * return { * "options": { * "height": 500, * "width": 150, * "offset": 50, * "pad": 20, * "margin": 5, * "dynamic": false, * "punctuation": { * "spacing": true, * "pad": 30, * "pull": true * }, * "style": { * "detail": [ * "black", * "white" * ], * "zoom": 1 * } * }, * "widths": [ * 150 * ], * "columns": [ * [ * { * "x": 56, * "y": 20, * "minX": 481, * "minY": 471, * "width": 37, * "height": 58, * "lane": 0, * "padding": 0, * "segment": "sign", * "text": "AS14c20S27106M518x529S14c20481x471S27106503x489", * "zoom": 1 * }, * { * "x": 57, * "y": 118, * "minX": 482, * "minY": 468, * "width": 36, * "height": 65, * "lane": 0, * "padding": 0, * "segment": "sign", * "text": "AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468", * "zoom": 1 * }, * { * "x": 39, * "y": 203, * "minX": 464, * "minY": 496, * "width": 72, * "height": 8, * "lane": 0, * "padding": 0, * "segment": "symbol", * "text": "S38800464x496", * "zoom": 1 * } * ] * ] * } */ export function columns(fswText: string, options: ColumnOptions): { options: ColumnOptions; widths: number[]; columns: ColumnData; }; export namespace compose { function symbol(fswSymObject: SymbolObject): string; function sign(fswSignObject: SignObject): string; } /** * Creates a tokenizer object with encoding and decoding capabilities * @function fsw.createTokenizer * @param {Object} [specialTokens] - Special tokens mapping object * @param {number} [startingIndex] - Starting index for regular tokens * @returns {TokenizerObject} Tokenizer object * @example * const t = fsw.createTokenizer() * * t.encode('M507x515S10e00492x485') * * return [7, 941, 949, 24, 678, 662, 926, 919, 3] */ export function createTokenizer(specialTokens?: any, startingIndex?: number): TokenizerObject; /** * Converts an array of tokens back into an FSW string * @function fsw.detokenize * @param {string[]} tokens - Array of tokens to convert * @param {Array} specialTokens - Array of special token objects to filter out * @returns {string} FSW string * @example * fsw.detokenize(['M', 'p507', 'p515','S10e', 'c0', 'r0', 'p492', 'p485']) * * return "M507x515S10e00492x485" */ export function detokenize(tokens: string[], specialTokens?: any[]): string; /** * Array of numbers for the 30 symbol groups. * @alias fsw.group * @type {number[]} */ export const group: number[]; /** * Function to gather sizing information about an fsw sign or symbol * @function fsw.info * @param {string} fsw - an fsw sign or symbol * @returns {SegmentInfo} information about the fsw string * @example * fsw.info('AS14c20S27106L518x529S14c20481x471S27106503x489-P10Z2') * * return { * minX: 481, * minY: 471, * width: 37, * height: 58, * lane: -1, * padding: 10, * segment: 'sign', * zoom: 2 * } */ export function info(fsw: string): SegmentInfo; /** * Function to test if symbol is of a certain type. * @function fsw.isType * @param {string} key - an FSW symbol key * @param {string} type - the name of a symbol range * @returns {boolean} is symbol of specified type * @example * fsw.isType('S10000', 'hand') * * return true */ export function isType(key: string, type: string): boolean; /** * Array of numbers for kinds of symbols: writing, location, and punctuation. * @alias fsw.kind * @type {number[]} */ export const kind: number[]; export namespace parse { export function symbol_1(fswSym: string): SymbolObject; export { symbol_1 as symbol }; export function sign_1(fswSign: string): SignObject; export { sign_1 as sign }; export function text(fswText: string): string[]; } /** * Object of symbol ranges with starting and ending numbers. * * { all, writing, hand, movement, dynamic, head, hcenter, vcenter, trunk, limb, location, punctuation } * @alias fsw.ranges * @type {object} */ export const ranges: object; declare namespace re$1 { const _null: string; export { _null as null }; const symbol_2: string; export { symbol_2 as symbol }; export const coord: string; export const sort: string; export const box: string; } /** * Tokenizes an FSW string into an array of tokens * @function fsw.tokenize * @param {string} fsw - FSW string to tokenize * @param {Object} options - Tokenization options * @param {boolean} [options.sequence=true] - Whether to include sequence tokens * @param {boolean} [options.signbox=true] - Whether to include signbox tokens * @param {string} [options.sep="[SEP]"] - Separator token * @returns {string[]} Array of tokens * @example * fsw.tokenize("AS10e00M507x515S10e00492x485",{sequence:false,sep:null}) * * return [ * 'M', 'p507', 'p515','S10e', 'c0', 'r0', 'p492', 'p485' * ] */ export function tokenize(fsw: string, { sequence, signbox, sep }?: { sequence?: boolean; signbox?: boolean; sep?: string; }): string[]; export { re$1 as re }; /** * 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; };