UNPKG

@drincs/pixi-vn-ink

Version:

Pixi'VN gives you the ability to write your own narrative using Ink

125 lines (121 loc) 3.51 kB
import { ErrorType } from 'inkjs/engine/Error'; type CompileSharedType = { labelToRemove: string[]; initialVarsToRemove: string[]; functions: { name: string; args: number; }[]; enums: { [key: string]: Record<string, number>; }; textSource: string; }; type IssueType = { message: string; type: ErrorType; line: number; }; /** * Serializable representation of a handler `validation` rule used by * {@link HashtagCommands} and {@link TextReplaces}. */ type InkValidationInfo = { /** * Validation based on regular expression. */ type: "regexp"; /** * The regex source pattern. */ source: string; /** * Regex flags (for example `"i"` or `"gi"`). */ flags: string; } | { /** * Validation based on a Zod schema serialized to JSON Schema. */ type: "zod"; /** * JSON Schema representation of the original Zod validation. */ schema: Record<string, unknown>; } | { /** * Validation represented by a string literal value * (e.g. `"all"` or `"characterId"`). */ type: "literal"; /** * The original literal validation value. */ value: string; }; /** * Serializable representation of a registered {@link HashtagCommands} handler, * as exposed by the pixi-vn-ink Vite dev-server API. * * @see https://pixi-vn.web.app/ink#vite-plugin */ interface InkHashtagCommandInfo { /** * Unique name that identifies the handler. */ name: string; /** * Human-readable description of what the handler does. */ description?: string; /** * Serializable form of the validation rule. */ validation: InkValidationInfo; } /** * Represents a single hashtag command occurrence found in an Ink source file. */ interface HashtagCommandOccurrence { /** * 1-based line number where the command appears. */ line: number; /** * The raw command string (without the leading `#`). */ command: string; /** * The token list produced by parsing the command. */ tokens: string[]; } declare namespace InkCompiler { function compile(text: string, shared?: Omit<CompileSharedType, "textSource">): { json: string; issues: IssueType[]; } | { issues: IssueType[]; json?: undefined; }; function getErrors(issues: IssueType[], recompile: () => void, shared: CompileSharedType): void | { issues: IssueType[]; }; /** * Returns all hashtag commands in `source` that are not matched by any * entry in `commands`. * * A command is considered "unknown" when none of the registered * {@link InkHashtagCommandInfo} validations match its token list. * * @param source Raw Ink source text to scan. * @param commands List of known command descriptors (e.g. obtained from * `GET /__pixi-vn-ink/hashtag-commands` or registered * directly in a VS Code extension). * @returns Array of unrecognised {@link HashtagCommandOccurrence} * objects, each carrying the 1-based `line`, the raw * `command` string, and the parsed `tokens`. */ function getUnknownHashtagCommands(source: string, commands: InkHashtagCommandInfo[]): HashtagCommandOccurrence[]; } export { type HashtagCommandOccurrence, InkCompiler, type InkHashtagCommandInfo, type InkValidationInfo };