@sutton-signwriting/core
Version:
a javascript package for node and browsers that supports general processing of the Sutton SignWriting script
480 lines (479 loc) • 12.6 kB
TypeScript
export const __esModule: boolean;
/**
* Function to compose FSW query string from object
* @function fswquery.compose
* @param {QueryObject} fswQueryObject - an object of query options
* @returns {string} FSW query string
* @example
* fswquery.compose({
* query: true,
* prefix: {
* required: true,
* parts: [
* 'S10000',
* ['100', '204'],
* 'S20500'
* ]
* },
* signbox: [
* { symbol: 'S20000' },
* {
* range: ['100', '105'],
* coord: [500, 500]
* }
* ],
* variance: 5,
* style: true
* })
*
* return 'QAS10000R100t204S20500TS20000R100t105500x500V5-'
*/
export function compose(fswQueryObject: QueryObject): string;
/**
* Function to convert an FSW sign to a query string
*
* For the flags parameter, use one or more of the following.
* - A: exact symbol in temporal prefix
* - a: general symbol in temporal prefix
* - S: exact symbol in spatial signbox
* - s: general symbol in spatial signbox
* - L: spatial signbox symbol at location
* @function fswquery.fsw2query
* @param {string} fswSign - FSW sign
* @param {string} flags - flags for query string creation
* @returns {string} FSW query string
* @example
* fswquery.fsw2query('AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475', 'ASL')
*
* return 'QAS10011S10019S2e704S2e748TS2e748483x510S10011501x466S2e704510x500S10019476x475'
*/
export function fsw2query(fswSign: string, flags: string): string;
/**
* Function that uses an FSW query string to match signs from multiple lines of text.
* @function fswquery.lines
* @param {string} query - an FSW query string
* @param {string} text - multiple lines of text, each starting with an FSW sign
* @returns {string[]} an array of lines of text, each starting with an FSW sign
* @example
* fswquery.lines('QAS10011T',`AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 line one
* AS15a21S15a07S21100S2df04S2df14M521x538S15a07494x488S15a21498x489S2df04498x517S2df14497x461S21100479x486 line two
* AS1f010S10018S20600M519x524S10018485x494S1f010490x494S20600481x476 line three`)
*
* return [
* 'AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 line one'
* ]
*/
export function lines(query: string, text: string): string[];
/**
* Function to parse FSW query string to object
* @function fswquery.parse
* @param {string} fswQueryString - an FSW query string
* @returns {QueryObject} elements of a of query string identified by regular expression
* @example
* fswquery.parse('QAS10000S10500oS20500oR2fft304TS100uuR205t206oS207uu510x510V5-')
*
* return {
* "query": true,
* "prefix": {
* "required": true,
* "parts": [
* "S10000",
* [
* "or",
* "S10500",
* "S20500",
* [
* "2ff",
* "304"
* ]
* ]
* ]
* },
* "signbox": [
* {
* "symbol": "S100uu"
* },
* {
* "or": [
* [
* "205",
* "206"
* ],
* "S207uu"
* ],
* "coord": [
* 510,
* 510
* ]
* }
* ],
* "variance": 5,
* "style": true
* }
*/
declare function parse$1(fswQueryString: string): QueryObject;
/**
* Function to transform a range to a regular expression
* @function fswquery.range
* @param {(number|string)} min - either a decimal number or hexidecimal string
* @param {(number|string)} max - either a decimal number or hexidecimal string
* @param {boolean?} hex - if true, the regular expression will match a hexidecimal range
* @returns {string} a regular expression that matches a range
* @example
* fswquery.range(500,750)
*
* return '(([56][0-9][0-9])|(7[0-4][0-9])|(750))'
* @example
* fswquery.range('100','10e',true)
*
* return '10[0-9a-e]'
*/
export function range(min: (number | string), max: (number | string), hex: boolean | null): string;
/**
* Object of regular expressions for FSW query strings
*
* @alias fswquery.re
* @type {object}
* @property {string} null - the null symbol
* @property {string} base - FSW symbol base with neither fill or rotation
* @property {string} coord - FSW coordinate of X and Y values separated by 'x'
* @property {string} var - variance string for searching sign box
* @property {string} symbol - FSW symbol key starting with 'S'
* @property {string} nullorsymbol - null or a symbol
* @property {string} range - FSW range starting with 'R'
* @property {string} item - FSW symbol or range query string
* @property {string} list - several FSW symbols and FSW ranges as a logical OR for searching
* @property {string} prefix - a sequential list of FSW symbol keys with nulls starting with 'A'
* @property {string} signbox - several groups of FSW lists, each group having a coordinate
* @property {string} full - a query string to search prefix in order and the signbox with variance
*/
declare let re$2: object;
/**
* Function to transform an FSW query string to one or more regular expressions
* @function fswquery.regex
* @param {string} query - an FSW query string
* @returns {string[]} an array of one or more regular expressions
* @example
* fswquery.regex('QS100uuS20500480x520')
*
* return [
* '(?:A(?:S[123][0-9a-f]{2}[0-5][0-9a-f])+)?[BLMR]([0-9]{3}x[0-9]{3})(S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*S100[0-5][0-9a-f][0-9]{3}x[0-9]{3}(S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*',
* '(?:A(?:S[123][0-9a-f]{2}[0-5][0-9a-f])+)?[BLMR]([0-9]{3}x[0-9]{3})(S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*S20500((4[6-9][0-9])|(500))x((5[0-3][0-9])|(540))(S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*'
* ]
*/
export function regex(query: string): string[];
/**
* Function that uses a query string to match signs from a string of text.
* @function fswquery.results
* @param {string} query - an FSW query string
* @param {string} text - a string of text containing multiple signs
* @returns {string[]} an array of FSW signs
* @example
* fswquery.results('QAS10011T','AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 AS15a21S15a07S21100S2df04S2df14M521x538S15a07494x488S15a21498x489S2df04498x517S2df14497x461S21100479x486 AS1f010S10018S20600M519x524S10018485x494S1f010490x494S20600481x476')
*
* return [
* 'AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475'
* ]
*/
export function results(query: string, text: string): string[];
export { parse$1 as parse, re$2 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;
};