@xpadev-net/niconicomments
Version:
NiconiComments is a comment drawing library that is somewhat compatible with the official Nico Nico Douga player.
1,812 lines (1,756 loc) • 101 kB
TypeScript
type ButtonList = {
left: ButtonPartLeft;
middle: ButtonPartMiddle[];
right: ButtonPartRight;
};
type ButtonPartLeft = {
type: "left";
left: number;
top: number;
width: number;
height: number;
};
type ButtonPartMiddle = {
type: "middle";
left: number;
top: number;
width: number;
height: number;
};
type ButtonPartRight = {
type: "right";
right: number;
top: number;
height: number;
};
type Canvas = HTMLCanvasElement;
type Context2D = CanvasRenderingContext2D;
type DefaultCommand = {
color?: string;
size?: CommentSize;
font?: CommentFont;
loc?: CommentLoc;
};
declare class BaseComment implements IComment {
protected readonly renderer: IRenderer;
protected cacheKey: string;
comment: FormattedCommentWithSize;
pos: {
x: number;
y: number;
};
posY: number;
readonly pluginName: string;
image?: IRenderer | null;
buttonImage?: IRenderer | null;
index: number;
constructor(comment: FormattedComment, renderer: IRenderer, index: number);
get invisible(): boolean;
get loc(): "ue" | "naka" | "shita";
get long(): number;
get vpos(): number;
get width(): number;
get height(): number;
get flash(): boolean;
get layer(): number;
get owner(): boolean;
get mail(): string[];
get content(): string;
set content(_: string);
protected getCommentSize(parsedData: FormattedCommentWithFont): FormattedCommentWithSize;
protected parseCommandAndNicoscript(comment: FormattedComment): FormattedCommentWithFont;
protected parseContent(comment: string): ParseContentResult;
protected measureText(comment: MeasureTextInput): MeasureTextResult;
protected convertComment(comment: FormattedComment): FormattedCommentWithSize;
draw(vpos: number, showCollision: boolean, cursor?: Position): void;
protected _draw(posX: number, posY: number, cursor?: Position): void;
protected _drawRectColor(posX: number, posY: number): void;
protected _drawBackgroundColor(posX: number, posY: number): void;
protected _drawDebugInfo(posX: number, posY: number): void;
protected _drawCollision(posX: number, posY: number, showCollision: boolean): void;
protected getTextImage(): IRenderer | null;
protected _generateTextImage(): IRenderer;
protected _cacheImage(image: IRenderer): void;
protected getButtonImage(posX: number, posY: number, cursor?: Position): IRenderer | undefined;
isHovered(cursor?: Position, posX?: number, posY?: number): boolean;
protected getCacheKey(): string;
}
declare class FlashComment extends BaseComment {
private _globalScale;
readonly pluginName: string;
buttonImage: IRenderer;
constructor(comment: FormattedComment, renderer: IRenderer, index: number);
get content(): string;
set content(input: string);
convertComment(comment: FormattedComment): FormattedCommentWithSize;
getCommentSize(parsedData: FormattedCommentWithFont): FormattedCommentWithSize;
parseCommandAndNicoscript(comment: FormattedComment): FormattedCommentWithFont;
parseContent(input: string, button?: ButtonParams): {
content: ({
type: "spacer";
char: string;
charWidth: number;
count: number;
isButton?: boolean | undefined;
font?: "defont" | "gulim" | "simsun" | undefined;
} | {
type: "text";
content: string;
slicedContent: string[];
isButton?: boolean | undefined;
font?: "defont" | "gulim" | "simsun" | undefined;
width?: number[] | undefined;
})[];
lineCount: number;
lineOffset: number;
};
measureText(comment: MeasureTextInput): MeasureTextResult;
private _isDoubleResize;
private _measureContent;
_drawCollision(posX: number, posY: number, showCollision: boolean): void;
_generateTextImage(): IRenderer;
getButtonImage(posX: number, posY: number, cursor?: Position): IRenderer | undefined;
isHovered(_cursor?: Position, _posX?: number, _posY?: number): boolean;
protected _setupCanvas(renderer: IRenderer): {
renderer: IRenderer;
};
}
declare class HTML5Comment extends BaseComment {
readonly pluginName: string;
constructor(comment: FormattedComment, context: IRenderer, index: number);
get content(): string;
set content(input: string);
convertComment(comment: FormattedComment): FormattedCommentWithSize;
getCommentSize(parsedData: FormattedCommentWithFont): FormattedCommentWithSize;
parseCommandAndNicoscript(comment: FormattedComment): FormattedCommentWithFont;
parseContent(input: string, font?: HTML5Fonts): {
content: {
type: "text";
content: string;
slicedContent: string[];
isButton?: boolean | undefined;
font?: "defont" | "gulim" | "simsun" | undefined;
width?: number[] | undefined;
}[];
lineCount: number;
lineOffset: number;
};
measureText(comment: MeasureTextInput): MeasureTextResult;
private _measureComment;
private _processResizeX;
_drawCollision(posX: number, posY: number, showCollision: boolean): void;
_generateTextImage(): IRenderer;
getButtonImage(): undefined;
isHovered(): boolean;
}
type index_d$4_BaseComment = BaseComment;
declare const index_d$4_BaseComment: typeof BaseComment;
type index_d$4_FlashComment = FlashComment;
declare const index_d$4_FlashComment: typeof FlashComment;
type index_d$4_HTML5Comment = HTML5Comment;
declare const index_d$4_HTML5Comment: typeof HTML5Comment;
declare namespace index_d$4 {
export { index_d$4_BaseComment as BaseComment, index_d$4_FlashComment as FlashComment, index_d$4_HTML5Comment as HTML5Comment };
}
type ConfigItem<T> = T | MultiConfigItem<T>;
type MultiConfigItem<T> = {
html5: T;
flash: T;
};
type ConfigSizeItem<T> = {
big: T;
medium: T;
small: T;
};
type ConfigResizedItem<T> = {
default: T;
resized: T;
};
type ConfigFlashFontItem<T> = {
gulim: T;
simsun: T;
defont: T;
};
type ConfigHTML5FontItem<T> = {
gothic: T;
mincho: T;
defont: T;
};
type CommentStageSize = {
width: number;
fullWidth: number;
height: number;
};
type FlashCharList = {
[key in "simsunStrong" | "simsunWeak" | "gulim" | "gothic"]: string;
};
type FlashMode = "xp" | "vista";
type FlashScriptChar = {
[key in "super" | "sub"]: string;
};
type FontList = {
[key in "gulim" | "simsun"]: string;
};
type LineCounts = {
[key in "default" | "resized" | "doubleResized"]: ConfigSizeItem<number>;
};
type BaseConfig = {
cacheAge: number;
canvasHeight: number;
canvasWidth: number;
collisionRange: {
[key in "left" | "right"]: number;
};
collisionPadding: number;
colors: {
[key: string]: string;
};
commentDrawPadding: number;
commentDrawRange: number;
commentScale: ConfigItem<number>;
commentStageSize: ConfigItem<CommentStageSize>;
flashCommentYOffset: ConfigSizeItem<ConfigResizedItem<number>>;
flashCommentYPaddingTop: ConfigResizedItem<number>;
contextFillLiveOpacity: number;
contextLineWidth: ConfigItem<number>;
contextStrokeColor: string;
contextStrokeInversionColor: string;
contextStrokeOpacity: number;
flashChar: FlashCharList;
flashMode: FlashMode;
flashScriptChar: FlashScriptChar;
flashThreshold: number;
fonts: {
flash: FontList;
html5: PlatformFont;
};
fontSize: ConfigItem<ConfigSizeItem<ConfigResizedItem<number>>>;
fpsInterval: number;
html5HiResCommentCorrection: number;
html5LineCounts: ConfigItem<LineCounts>;
lineHeight: ConfigItem<ConfigSizeItem<ConfigResizedItem<number>>>;
html5MinFontSize: number;
sameCAGap: number;
sameCAMinScore: number;
sameCARange: number;
sameCATimestampRange: number;
flashLetterSpacing: number;
flashScriptCharOffset: number;
plugins: IPluginConstructor[];
commentPlugins: {
class: typeof BaseComment;
condition: (comment: FormattedComment) => boolean;
}[];
commentLimit: number | undefined;
hideCommentOrder: "asc" | "desc";
lineBreakCount: {
[key in CommentSize]: number;
};
nakaCommentSpeedOffset: number;
atButtonPadding: number;
atButtonRadius: number;
flashDoubleResizeHeights: Partial<ConfigSizeItem<{
[key: number]: number;
}>>;
flashLineBreakScale: ConfigSizeItem<number>;
compatSpacer: {
flash: {
[key: string]: Partial<ConfigFlashFontItem<number>>;
};
html5: {
[key: string]: Partial<ConfigHTML5FontItem<number>>;
};
};
};
type Config = Partial<BaseConfig>;
type Position = {
x: number;
y: number;
};
interface CommentEventBase {
type: CommentEventName;
timeStamp: number;
vpos: number;
}
interface SeekDisableEvent extends CommentEventBase {
type: "seekDisable";
}
type SeekDisableEventHandler = (event: SeekDisableEvent) => unknown;
interface SeekEnableEvent extends CommentEventBase {
type: "seekEnable";
}
type SeekEnableEventHandler = (event: SeekEnableEvent) => unknown;
interface CommentDisableEvent extends CommentEventBase {
type: "commentDisable";
}
type CommentDisableEventHandler = (event: CommentDisableEvent) => unknown;
interface CommentEnableEvent extends CommentEventBase {
type: "commentEnable";
}
type CommentEnableEventHandler = (event: CommentEnableEvent) => unknown;
interface JumpEvent extends CommentEventBase {
type: "jump";
to: string;
message?: string;
}
type JumpEventHandler = (event: JumpEvent) => unknown;
type CommentEventName = "seekDisable" | "seekEnable" | "commentDisable" | "commentEnable" | "jump";
type CommentEventHandler = SeekDisableEventHandler | SeekEnableEventHandler | CommentDisableEventHandler | CommentEnableEventHandler | JumpEventHandler;
interface CommentEventHandlerMap {
seekDisable: SeekDisableEventHandler;
seekEnable: SeekEnableEventHandler;
commentDisable: CommentDisableEventHandler;
commentEnable: CommentEnableEventHandler;
jump: JumpEventHandler;
}
interface CommentEventMap {
seekDisable: SeekDisableEvent;
seekEnable: SeekEnableEvent;
commentDisable: CommentDisableEvent;
commentEnable: CommentEnableEvent;
jump: JumpEvent;
}
/**
* Pipe action context type.
*/
interface PipeActionContext {
type: string;
expects: string | null;
message: ErrorMessage | undefined;
requirement: unknown;
}
/**
* Valid action result type.
*/
interface ValidActionResult<TOutput> {
/**
* The pipe output.
*/
output: TOutput;
/**
* The pipe issues.
*/
issues?: undefined;
}
/**
* Invalid action result type.
*/
interface InvalidActionResult {
/**
* The pipe output.
*/
output?: undefined;
/**
* The pipe issues.
*/
issues: PipeActionIssues;
}
/**
* Pipe action result type.
*/
type PipeActionResult<TOutput> = ValidActionResult<TOutput> | InvalidActionResult;
/**
* Base validation type.
*/
interface BaseValidation<TInput = any> {
/**
* The validation type.
*/
type: string;
/**
* The expected property.
*/
expects: string | null;
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* Whether it's async.
*/
async: false;
/**
* The validation requirement.
*/
requirement: unknown;
/**
* Parses unknown input based on its requirement.
*
* @param input The input to be parsed.
*
* @returns The pipe action result.
*
* @internal
*/
_parse(input: TInput): PipeActionResult<TInput>;
}
/**
* Base validation async type.
*/
interface BaseValidationAsync<TInput = any> {
/**
* The validation type.
*/
type: string;
/**
* The expected property.
*/
expects: string | null;
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* Whether it's async.
*/
async: true;
/**
* The validation requirement.
*/
requirement: unknown;
/**
* Parses unknown input based on its requirement.
*
* @param input The input to be parsed.
*
* @returns The pipe action result.
*
* @internal
*/
_parse(input: TInput): Promise<PipeActionResult<TInput>>;
}
/**
* Base transformation type.
*/
interface BaseTransformation<TInput = any> {
/**
* The transformation type.
*/
type: string;
/**
* Whether it's async.
*/
async: false;
/**
* Parses unknown input based on its requirement.
*
* @param input The input to be parsed.
*
* @returns The pipe action result.
*
* @internal
*/
_parse(input: TInput): PipeActionResult<TInput>;
}
/**
* Base transformation async type.
*/
interface BaseTransformationAsync<TInput = any> {
/**
* The transformation type.
*/
type: string;
/**
* Whether it's async.
*/
async: true;
/**
* Parses unknown input based on its requirement.
*
* @param input The input to be parsed.
*
* @returns The pipe action result.
*
* @internal
*/
_parse(input: TInput): Promise<PipeActionResult<TInput>>;
}
/**
* Pipe type.
*/
type Pipe<TInput> = (BaseValidation<TInput> | BaseTransformation<TInput>)[];
/**
* Pipe async type.
*/
type PipeAsync<TInput> = (BaseValidation<TInput> | BaseValidationAsync<TInput> | BaseTransformation<TInput> | BaseTransformationAsync<TInput>)[];
/**
* Issue reason type.
*/
type IssueReason = 'any' | 'array' | 'bigint' | 'blob' | 'boolean' | 'date' | 'intersect' | 'function' | 'instance' | 'map' | 'number' | 'object' | 'record' | 'set' | 'special' | 'string' | 'symbol' | 'tuple' | 'undefined' | 'union' | 'unknown' | 'variant' | 'type';
/**
* Unknown path item type.
*/
interface UnknownPathItem {
type: 'unknown';
origin: 'key' | 'value';
input: unknown;
key: unknown;
value: unknown;
}
/**
* Path item type.
*/
type PathItem = ArrayPathItem | MapPathItem | ObjectPathItem | RecordPathItem | SetPathItem | TuplePathItem | UnknownPathItem;
/**
* Issue path type.
*/
type IssuePath = [PathItem, ...PathItem[]];
/**
* Schema issue type.
*/
interface SchemaIssue extends Omit<SchemaConfig, 'message'> {
/**
* The issue reason.
*/
reason: IssueReason;
/**
* The context name.
*/
context: string;
/**
* The raw input data.
*/
input: unknown;
/**
* The expected input.
*/
expected: string | null;
/**
* The received input.
*/
received: string;
/**
* The error message.
*/
message: string;
/**
* The validation requirement
*/
requirement?: unknown;
/**
* The issue path.
*/
path?: IssuePath;
/**
* The sub issues.
*/
issues?: SchemaIssues;
}
/**
* Schema issues type.
*/
type SchemaIssues = [SchemaIssue, ...SchemaIssue[]];
/**
* Pipe action issue type.
*/
interface PipeActionIssue {
context: PipeActionContext;
reference: Function;
input: unknown;
label: string;
received?: string;
path?: IssuePath;
}
/**
* Pipe action issues type.
*/
type PipeActionIssues = [PipeActionIssue, ...PipeActionIssue[]];
/**
* Error message type.
*/
type ErrorMessage = string | ((issue: SchemaIssue) => string);
/**
* The schema config type.
*/
interface SchemaConfig {
/**
* The selected language.
*/
lang?: string;
/**
* The error message.
*/
message?: ErrorMessage;
/**
* Whether it was abort early.
*/
abortEarly?: boolean;
/**
* Whether the pipe was abort early.
*/
abortPipeEarly?: boolean;
/**
* Whether the pipe was skipped.
*/
skipPipe?: boolean;
}
/**
* Typed schema result type.
*/
interface TypedSchemaResult<TOutput> {
/**
* Whether is's typed.
*/
typed: true;
/**
* The parse output.
*/
output: TOutput;
/**
* The parse issues.
*/
issues?: SchemaIssues;
}
/**
* Untyped schema result type.
*/
interface UntypedSchemaResult {
/**
* Whether is's typed.
*/
typed: false;
/**
* The parse output.
*/
output: unknown;
/**
* The parse issues.
*/
issues: SchemaIssues;
}
/**
* Schema result type.
*/
type SchemaResult<TOutput> = TypedSchemaResult<TOutput> | UntypedSchemaResult;
/**
* Base schema type.
*/
interface BaseSchema<TInput = any, TOutput = TInput> {
/**
* The schema type.
*/
type: string;
/**
* The expected property.
*/
expects: string;
/**
* Whether it's async.
*/
async: false;
/**
* Parses unknown input based on its schema.
*
* @param input The input to be parsed.
* @param config The parse configuration.
*
* @returns The schema result.
*
* @internal
*/
_parse(input: unknown, config?: SchemaConfig): SchemaResult<TOutput>;
/**
* Input and output type.
*
* @internal
*/
_types?: {
input: TInput;
output: TOutput;
};
}
/**
* Base schema async type.
*/
interface BaseSchemaAsync<TInput = any, TOutput = TInput> {
/**
* The schema type.
*/
type: string;
/**
* The expected property.
*/
expects: string;
/**
* Whether it's async.
*/
async: true;
/**
* Parses unknown input based on its schema.
*
* @param input The input to be parsed.
* @param config The parse configuration.
*
* @returns The schema result.
*
* @internal
*/
_parse(input: unknown, config?: SchemaConfig): Promise<SchemaResult<TOutput>>;
/**
* Input and output type.
*
* @internal
*/
_types?: {
input: TInput;
output: TOutput;
};
}
/**
* Input inference type.
*/
type Input<TSchema extends BaseSchema | BaseSchemaAsync> = NonNullable<TSchema['_types']>['input'];
/**
* Output inference type.
*/
type Output<TSchema extends BaseSchema | BaseSchemaAsync> = NonNullable<TSchema['_types']>['output'];
/**
* Default type.
*/
type Default<TSchema extends BaseSchema> = Input<TSchema> | (() => Input<TSchema> | undefined) | undefined;
/**
* Default async type.
*/
type DefaultAsync<TSchema extends BaseSchema | BaseSchemaAsync> = Input<TSchema> | (() => Input<TSchema> | Promise<Input<TSchema> | undefined> | undefined) | undefined;
/**
* Maybe readonly type.
*/
type MaybeReadonly<T> = T | Readonly<T>;
/**
* Resolve type.
*
* Hint: This type has no effect and is only used so that TypeScript displays
* the final type in the preview instead of the utility types used.
*/
type Resolve<T> = T;
/**
* Resolve object type.
*
* Hint: This type has no effect and is only used so that TypeScript displays
* the final type in the preview instead of the utility types used.
*/
type ResolveObject<T> = Resolve<{
[k in keyof T]: T[k];
}>;
/**
* Array schema type.
*/
interface ArraySchema<TItem extends BaseSchema, TOutput = Output<TItem>[]> extends BaseSchema<Input<TItem>[], TOutput> {
/**
* The schema type.
*/
type: 'array';
/**
* The array item schema.
*/
item: TItem;
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: Pipe<Output<TItem>[]> | undefined;
}
/**
* Array path item type.
*/
interface ArrayPathItem {
type: 'array';
origin: 'value';
input: unknown[];
key: number;
value: unknown;
}
/**
* Boolean schema type.
*/
interface BooleanSchema<TOutput = boolean> extends BaseSchema<boolean, TOutput> {
/**
* The schema type.
*/
type: 'boolean';
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: Pipe<boolean> | undefined;
}
/**
* Enum type.
*/
interface Enum {
[key: string]: string | number;
[key: number]: string;
}
/**
* Native enum schema type.
*/
interface EnumSchema<TEnum extends Enum, TOutput = TEnum[keyof TEnum]> extends BaseSchema<TEnum[keyof TEnum], TOutput> {
/**
* The schema type.
*/
type: 'enum';
/**
* The enum value.
*/
enum: TEnum;
/**
* The error message.
*/
message: ErrorMessage | undefined;
}
/**
* Native enum schema async type.
*/
interface EnumSchemaAsync<TEnum extends Enum, TOutput = TEnum[keyof TEnum]> extends BaseSchemaAsync<TEnum[keyof TEnum], TOutput> {
/**
* The schema type.
*/
type: 'enum';
/**
* The enum value.
*/
enum: TEnum;
/**
* The error message.
*/
message: ErrorMessage | undefined;
}
/**
* Intersect options async type.
*/
type IntersectOptionsAsync = MaybeReadonly<[
BaseSchema | BaseSchemaAsync,
BaseSchema | BaseSchemaAsync,
...(BaseSchema[] | BaseSchemaAsync[])
]>;
/**
* Intersect input inference type.
*/
type IntersectInput<TIntersectOptions extends IntersectOptions | IntersectOptionsAsync> = TIntersectOptions extends [
BaseSchema<infer TInput1, any> | BaseSchemaAsync<infer TInput1, any>,
...infer TRest
] ? TRest extends IntersectOptions ? TInput1 & IntersectOutput<TRest> : TRest extends [
BaseSchema<infer TInput2, any> | BaseSchemaAsync<infer TInput2, any>
] ? TInput1 & TInput2 : never : never;
/**
* Intersect output inference type.
*/
type IntersectOutput<TIntersectOptions extends IntersectOptions | IntersectOptionsAsync> = TIntersectOptions extends [
BaseSchema<any, infer TOutput1> | BaseSchemaAsync<any, infer TOutput1>,
...infer TRest
] ? TRest extends IntersectOptions ? TOutput1 & IntersectOutput<TRest> : TRest extends [
BaseSchema<any, infer TOutput2> | BaseSchemaAsync<any, infer TOutput2>
] ? TOutput1 & TOutput2 : never : never;
/**
* Intersect options type.
*/
type IntersectOptions = MaybeReadonly<[
BaseSchema,
BaseSchema,
...BaseSchema[]
]>;
/**
* Intersect schema type.
*/
interface IntersectSchema<TOptions extends IntersectOptions, TOutput = IntersectOutput<TOptions>> extends BaseSchema<IntersectInput<TOptions>, TOutput> {
/**
* The schema type.
*/
type: 'intersect';
/**
* The intersect options.
*/
options: TOptions;
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: Pipe<IntersectOutput<TOptions>> | undefined;
}
/**
* Literal type.
*/
type Literal = number | string | boolean | symbol | bigint;
/**
* Literal schema type.
*/
interface LiteralSchema<TLiteral extends Literal, TOutput = TLiteral> extends BaseSchema<TLiteral, TOutput> {
/**
* The schema type.
*/
type: 'literal';
/**
* The literal value.
*/
literal: TLiteral;
/**
* The error message.
*/
message: ErrorMessage | undefined;
}
/**
* Map path item type.
*/
interface MapPathItem {
type: 'map';
origin: 'key' | 'value';
input: Map<unknown, unknown>;
key: unknown;
value: unknown;
}
/**
* Never schema type.
*/
interface NeverSchema extends BaseSchema<never> {
/**
* The schema type.
*/
type: 'never';
/**
* The error message.
*/
message: ErrorMessage | undefined;
}
/**
* Never schema async type.
*/
interface NeverSchemaAsync extends BaseSchemaAsync<never> {
/**
* The schema type.
*/
type: 'never';
/**
* The error message.
*/
message: ErrorMessage | undefined;
}
/**
* Nullable schema type.
*/
interface NullableSchema<TWrapped extends BaseSchema, TDefault extends Default<TWrapped> = undefined, TOutput = TDefault extends Input<TWrapped> | (() => Input<TWrapped>) ? Output<TWrapped> : Output<TWrapped> | null> extends BaseSchema<Input<TWrapped> | null, TOutput> {
/**
* The schema type.
*/
type: 'nullable';
/**
* The wrapped schema.
*/
wrapped: TWrapped;
/**
* The default value.
*/
default: TDefault;
}
/**
* Number schema type.
*/
interface NumberSchema<TOutput = number> extends BaseSchema<number, TOutput> {
/**
* The schema type.
*/
type: 'number';
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: Pipe<number> | undefined;
}
/**
* Optional schema type.
*/
interface OptionalSchema<TWrapped extends BaseSchema, TDefault extends Default<TWrapped> = undefined, TOutput = TDefault extends Input<TWrapped> | (() => Input<TWrapped>) ? Output<TWrapped> : Output<TWrapped> | undefined> extends BaseSchema<Input<TWrapped> | undefined, TOutput> {
/**
* The schema type.
*/
type: 'optional';
/**
* The wrapped schema.
*/
wrapped: TWrapped;
/**
* Returns the default value.
*/
default: TDefault;
}
/**
* Optional schema async type.
*/
interface OptionalSchemaAsync<TWrapped extends BaseSchema | BaseSchemaAsync, TDefault extends DefaultAsync<TWrapped> = undefined, TOutput = TDefault extends Input<TWrapped> | (() => Input<TWrapped> | Promise<Input<TWrapped>>) ? Output<TWrapped> : Output<TWrapped> | undefined> extends BaseSchemaAsync<Input<TWrapped> | undefined, TOutput> {
/**
* The schema type.
*/
type: 'optional';
/**
* The wrapped schema.
*/
wrapped: TWrapped;
/**
* Returns the default value.
*/
default: TDefault;
}
/**
* Object entries async type.
*/
interface ObjectEntriesAsync {
[key: string]: BaseSchema | BaseSchemaAsync;
}
/**
* Object path item type.
*/
interface ObjectPathItem {
type: 'object';
origin: 'value';
input: Record<string, unknown>;
key: string;
value: unknown;
}
/**
* Required object keys type.
*/
type RequiredKeys<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends EntriesInput<TEntries> | EntriesOutput<TEntries>> = {
[TKey in keyof TEntries]: TEntries[TKey] extends OptionalSchema<any, any> | OptionalSchemaAsync<any, any> ? undefined extends TObject[TKey] ? never : TKey : TKey;
}[keyof TEntries];
/**
* Optional object keys type.
*/
type OptionalKeys<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends EntriesInput<TEntries> | EntriesOutput<TEntries>> = {
[TKey in keyof TEntries]: TEntries[TKey] extends OptionalSchema<any, any> | OptionalSchemaAsync<any, any> ? undefined extends TObject[TKey] ? TKey : never : never;
}[keyof TEntries];
/**
* Entries input inference type.
*/
type EntriesInput<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
[TKey in keyof TEntries]: Input<TEntries[TKey]>;
};
/**
* Entries output inference type.
*/
type EntriesOutput<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
[TKey in keyof TEntries]: Output<TEntries[TKey]>;
};
/**
* Object with question marks type.
*/
type WithQuestionMarks<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends EntriesInput<TEntries> | EntriesOutput<TEntries>> = Pick<TObject, RequiredKeys<TEntries, TObject>> & Partial<Pick<TObject, OptionalKeys<TEntries, TObject>>>;
/**
* Object input inference type.
*/
type ObjectInput<TEntries extends ObjectEntries | ObjectEntriesAsync, TRest extends BaseSchema | BaseSchemaAsync | undefined> = TRest extends undefined | NeverSchema | NeverSchemaAsync ? ResolveObject<WithQuestionMarks<TEntries, EntriesInput<TEntries>>> : TRest extends BaseSchema | BaseSchemaAsync ? ResolveObject<WithQuestionMarks<TEntries, EntriesInput<TEntries>>> & Record<string, Input<TRest>> : never;
/**
* Object output inference type.
*/
type ObjectOutput<TEntries extends ObjectEntries | ObjectEntriesAsync, TRest extends BaseSchema | BaseSchemaAsync | undefined> = TRest extends undefined | NeverSchema | NeverSchemaAsync ? ResolveObject<WithQuestionMarks<TEntries, EntriesOutput<TEntries>>> : TRest extends BaseSchema | BaseSchemaAsync ? ResolveObject<WithQuestionMarks<TEntries, EntriesOutput<TEntries>>> & Record<string, Output<TRest>> : never;
/**
* Object entries type.
*/
interface ObjectEntries {
[key: string]: BaseSchema;
}
/**
* Object schema type.
*/
interface ObjectSchema<TEntries extends ObjectEntries, TRest extends BaseSchema | undefined = undefined, TOutput = ObjectOutput<TEntries, TRest>> extends BaseSchema<ObjectInput<TEntries, TRest>, TOutput> {
/**
* The schema type.
*/
type: 'object';
/**
* The object entries schema.
*/
entries: TEntries;
/**
* The object rest schema.
*/
rest: TRest;
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: Pipe<ObjectOutput<TEntries, TRest>> | undefined;
}
/**
* Picklist options type.
*/
type PicklistOptions = MaybeReadonly<(string | number | bigint)[]>;
/**
* Picklist schema type.
*/
interface PicklistSchema<TOptions extends PicklistOptions, TOutput = TOptions[number]> extends BaseSchema<TOptions[number], TOutput> {
/**
* The schema type.
*/
type: 'picklist';
/**
* The picklist options.
*/
options: TOptions;
/**
* The error message.
*/
message: ErrorMessage | undefined;
}
/**
* Picklist schema async type.
*/
interface PicklistSchemaAsync<TOptions extends PicklistOptions, TOutput = TOptions[number]> extends BaseSchemaAsync<TOptions[number], TOutput> {
/**
* The schema type.
*/
type: 'picklist';
/**
* The picklist value.
*/
options: TOptions;
/**
* The error message.
*/
message: ErrorMessage | undefined;
}
/**
* Special schema type.
*/
interface SpecialSchema<TInput, TOutput = TInput> extends BaseSchema<TInput, TOutput> {
/**
* The schema type.
*/
type: 'special';
/**
* The type check function.
*/
check: (input: unknown) => boolean;
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: Pipe<TInput> | undefined;
}
/**
* Special schema async type.
*/
interface SpecialSchemaAsync<TInput, TOutput = TInput> extends BaseSchemaAsync<TInput, TOutput> {
/**
* The schema type.
*/
type: 'special';
/**
* The type check function.
*/
check: (input: unknown) => boolean | Promise<boolean>;
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: PipeAsync<TInput> | undefined;
}
/**
* String schema type.
*/
interface StringSchema<TOutput = string> extends BaseSchema<string, TOutput> {
/**
* The schema type.
*/
type: 'string';
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: Pipe<string> | undefined;
}
/**
* String schema async type.
*/
interface StringSchemaAsync<TOutput = string> extends BaseSchemaAsync<string, TOutput> {
/**
* The schema type.
*/
type: 'string';
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: PipeAsync<string> | undefined;
}
/**
* Union options type.
*/
type UnionOptions = MaybeReadonly<BaseSchema[]>;
/**
* Union schema type.
*/
interface UnionSchema<TOptions extends UnionOptions, TOutput = Output<TOptions[number]>> extends BaseSchema<Input<TOptions[number]>, TOutput> {
/**
* The schema type.
*/
type: 'union';
/**
* The union options.
*/
options: TOptions;
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: Pipe<Output<TOptions[number]>> | undefined;
}
/**
* Union options async type.
*/
type UnionOptionsAsync = MaybeReadonly<(BaseSchema | BaseSchemaAsync)[]>;
/**
* Union schema async type.
*/
interface UnionSchemaAsync<TOptions extends UnionOptionsAsync, TOutput = Output<TOptions[number]>> extends BaseSchemaAsync<Input<TOptions[number]>, TOutput> {
/**
* The schema type.
*/
type: 'union';
/**
* The union options.
*/
options: TOptions;
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: PipeAsync<Input<TOptions[number]>> | undefined;
}
/**
* Record key async type.
*/
type RecordKeyAsync = EnumSchema<any, string | number | symbol> | EnumSchemaAsync<any, string | number | symbol> | PicklistSchema<any, string | number | symbol> | PicklistSchemaAsync<any, string | number | symbol> | SpecialSchema<any, string | number | symbol> | SpecialSchemaAsync<any, string | number | symbol> | StringSchema<string | number | symbol> | StringSchemaAsync<string | number | symbol> | UnionSchema<any, string | number | symbol> | UnionSchemaAsync<any, string | number | symbol>;
/**
* Record path item type.
*/
interface RecordPathItem {
type: 'record';
origin: 'key' | 'value';
input: Record<string | number | symbol, unknown>;
key: string | number | symbol;
value: unknown;
}
/**
* Partial key schema type.
*/
type PartialKeySchema = PicklistSchema<any> | PicklistSchemaAsync<any> | EnumSchema<any> | EnumSchemaAsync<any> | UnionSchema<any> | UnionSchemaAsync<any>;
/**
* Record input inference type.
*/
type RecordInput<TKey extends RecordKey | RecordKeyAsync, TValue extends BaseSchema | BaseSchemaAsync> = ResolveObject<TKey extends PartialKeySchema ? Partial<Record<Input<TKey>, Input<TValue>>> : Record<Input<TKey>, Input<TValue>>>;
/**
* Record output inference type.
*/
type RecordOutput<TKey extends RecordKey | RecordKeyAsync, TValue extends BaseSchema | BaseSchemaAsync> = ResolveObject<TKey extends PartialKeySchema ? Partial<Record<Output<TKey>, Output<TValue>>> : Record<Output<TKey>, Output<TValue>>>;
/**
* Record key type.
*/
type RecordKey = EnumSchema<any, string | number | symbol> | PicklistSchema<any, string | number | symbol> | SpecialSchema<any, string | number | symbol> | StringSchema<string | number | symbol> | UnionSchema<any, string | number | symbol>;
/**
* Record schema type.
*/
interface RecordSchema<TKey extends RecordKey, TValue extends BaseSchema, TOutput = RecordOutput<TKey, TValue>> extends BaseSchema<RecordInput<TKey, TValue>, TOutput> {
/**
* The schema type.
*/
type: 'record';
/**
* The record key schema.
*/
key: TKey;
/**
* The record value schema.
*/
value: TValue;
/**
* The error message.
*/
message: ErrorMessage | undefined;
/**
* The validation and transformation pipeline.
*/
pipe: Pipe<RecordOutput<TKey, TValue>> | undefined;
}
/**
* Set path item type.
*/
interface SetPathItem {
type: 'set';
origin: 'value';
input: Set<unknown>;
key: number;
value: unknown;
}
/**
* Tuple path item type.
*/
interface TuplePathItem {
type: 'tuple';
origin: 'value';
input: [unknown, ...unknown[]];
key: number;
value: unknown;
}
/**
* Unknown schema type.
*/
interface UnknownSchema<TOutput = unknown> extends BaseSchema<unknown, TOutput> {
/**
* The schema type.
*/
type: 'unknown';
/**
* The validation and transformation pipeline.
*/
pipe: Pipe<unknown> | undefined;
}
type Platform = "win7" | "win8_1" | "win" | "mac10_9" | "mac10_11" | "mac" | "other";
declare const ZHTML5Fonts: UnionSchema<(LiteralSchema<"defont", "defont"> | LiteralSchema<"mincho", "mincho"> | LiteralSchema<"gothic", "gothic">)[], "defont" | "mincho" | "gothic">;
type HTML5Fonts = Output<typeof ZHTML5Fonts>;
type FontItem = {
font: string;
offset: number;
weight: number;
};
type PlatformFont = {
[key in HTML5Fonts]: FontItem;
};
declare const ZFormattedComment: ObjectSchema<{
id: OptionalSchema<NumberSchema<number>, 0, number>;
vpos: OptionalSchema<NumberSchema<number>, 0, number>;
content: OptionalSchema<StringSchema<string>, "", string>;
date: OptionalSchema<NumberSchema<number>, 0, number>;
date_usec: OptionalSchema<NumberSchema<number>, 0, number>;
owner: OptionalSchema<BooleanSchema<boolean>, false, boolean>;
premium: OptionalSchema<BooleanSchema<boolean>, false, boolean>;
mail: OptionalSchema<ArraySchema<StringSchema<string>, string[]>, never[], string[]>;
user_id: OptionalSchema<NumberSchema<number>, 0, number>;
layer: OptionalSchema<NumberSchema<number>, -1, number>;
is_my_post: OptionalSchema<BooleanSchema<boolean>, false, boolean>;
}, undefined, {
owner: boolean;
content: string;
id: number;
vpos: number;
date: number;
date_usec: number;
premium: boolean;
mail: string[];
user_id: number;
layer: number;
is_my_post: boolean;
}>;
type FormattedComment = Output<typeof ZFormattedComment>;
declare const ZFormattedLegacyComment: ObjectSchema<Omit<{
id: OptionalSchema<NumberSchema<number>, 0, number>;
vpos: OptionalSchema<NumberSchema<number>, 0, number>;
content: OptionalSchema<StringSchema<string>, "", string>;
date: OptionalSchema<NumberSchema<number>, 0, number>;
date_usec: OptionalSchema<NumberSchema<number>, 0, number>;
owner: OptionalSchema<BooleanSchema<boolean>, false, boolean>;
premium: OptionalSchema<BooleanSchema<boolean>, false, boolean>;
mail: OptionalSchema<ArraySchema<StringSchema<string>, string[]>, never[], string[]>;
user_id: OptionalSchema<NumberSchema<number>, 0, number>;
layer: OptionalSchema<NumberSchema<number>, -1, number>;
is_my_post: OptionalSchema<BooleanSchema<boolean>, false, boolean>;
}, "user_id" | "layer" | "is_my_post">, undefined, {
owner: boolean;
content: string;
id: number;
vpos: number;
date: number;
date_usec: number;
premium: boolean;
mail: string[];
}>;
type FormattedLegacyComment = Output<typeof ZFormattedLegacyComment>;
type formattedComment = FormattedComment;
type formattedLegacyComment = FormattedLegacyComment;
declare const ZApiChat: ObjectSchema<{
thread: OptionalSchema<StringSchema<string>, "", string>;
no: OptionalSchema<NumberSchema<number>, 0, number>;
vpos: NumberSchema<number>;
date: OptionalSchema<NumberSchema<number>, 0, number>;
date_usec: OptionalSchema<NumberSchema<number>, 0, number>;
nicoru: OptionalSchema<NumberSchema<number>, 0, number>;
premium: OptionalSchema<NumberSchema<number>, 0, number>;
anonymity: OptionalSchema<NumberSchema<number>, 0, number>;
user_id: OptionalSchema<StringSchema<string>, "", string>;
mail: OptionalSchema<StringSchema<string>, "", string>;
content: StringSchema<string>;
deleted: OptionalSchema<NumberSchema<number>, 0, number>;
}, undefined, {
content: string;
vpos: number;
date: number;
date_usec: number;
premium: number;
mail: string;
user_id: string;
thread: string;
no: number;
nicoru: number;
anonymity: number;
deleted: number;
}>;
type ApiChat = Output<typeof ZApiChat>;
declare const ZRawApiResponse: UnionSchema<(ObjectSchema<{
chat: ObjectSchema<{
thread: OptionalSchema<StringSchema<string>, "", string>;
no: OptionalSchema<NumberSchema<number>, 0, number>;
vpos: NumberSchema<number>;
date: OptionalSchema<NumberSchema<number>, 0, number>;
date_usec: OptionalSchema<NumberSchema<number>, 0, number>;
nicoru: OptionalSchema<NumberSchema<number>, 0, number>;
premium: OptionalSchema<NumberSchema<number>, 0, number>;
anonymity: OptionalSchema<NumberSchema<number>, 0, number>;
user_id: OptionalSchema<StringSchema<string>, "", string>;
mail: OptionalSchema<StringSchema<string>, "", string>;
content: StringSchema<string>;
deleted: OptionalSchema<NumberSchema<number>, 0, number>;
}, undefined, {
content: string;
vpos: number;
date: number;
date_usec: number;
premium: number;
mail: string;
user_id: string;
thread: string;
no: number;
nicoru: number;
anonymity: number;
deleted: number;
}>;
}, undefined, {
chat: {
content: string;
vpos: number;
date: number;
date_usec: number;
premium: number;
mail: string;
user_id: string;
thread: string;
no: number;
nicoru: number;
anonymity: number;
deleted: number;
};
}> | RecordSchema<StringSchema<string>, UnknownSchema<unknown>, {
[x: string]: unknown;
}>)[], {
chat: {
content: string;
vpos: number;
date: number;
date_usec: number;
premium: number;
mail: string;
user_id: string;
thread: string;
no: number;
nicoru: number;
anonymity: number;
deleted: number;
};
} | {
[x: string]: unknown;
}>;
type RawApiResponse = Output<typeof ZRawApiResponse>;
declare const ZApiPing: ObjectSchema<{
content: StringSchema<string>;
}, undefined, {
content: string;
}>;
type ApiPing = Output<typeof ZApiPing>;
declare const ZApiThread: ObjectSchema<{
resultcode: NumberSchema<number>;
thread: StringSchema<string>;
server_time: NumberSchema<number>;
ticket: StringSchema<string>;
revision: NumberSchema<number>;
}, undefined, {
thread: string;
resultcode: number;
server_time: number;
ticket: string;
revision: number;
}>;
type ApiThread = Output<typeof ZApiThread>;
declare const ZApiLeaf: ObjectSchema<{
thread: StringSchema<string>;
count: NumberSchema<number>;
}, undefined, {
count: number;
thread: string;
}>;
type ApiLeaf = Output<typeof ZApiLeaf>;
declare const ZApiGlobalNumRes: ObjectSchema<{
thread: StringSchema<string>;
num_res: NumberSchema<number>;
}, undefined, {
thread: string;
num_res: number;
}>;
type ApiGlobalNumRes = Output<typeof ZApiGlobalNumRes>;
type rawApiResponse = RawApiResponse;
declare const ZOwnerComment: ObjectSchema<{
time: StringSchema<string>;
command: StringSchema<string>;
comment: StringSchema<string>;
}, undefined, {
time: string;
command: string;
comment: string;
}>;
type OwnerComment = Output<typeof ZOwnerComment>;
type ownerComment = OwnerComment;
declare const ZV1Comment: ObjectSchema<{
id: StringSchema<string>;
no: NumberSchema<number>;
vposMs: NumberSchema<number>;
body: StringSchema<string>;
commands: ArraySchema<StringSchema<string>, string[]>;
userId: StringSchema<string>;
isPremium: BooleanSchema<boolean>;
score: NumberSchema<number>;
postedAt: StringSchema<string>;
nicoruCount: NumberSchema<number>;
nicoruId: NullableSchema<StringSchema<string>, undefined, string | null>;
source: StringSchema<string>;
isMyPost: BooleanSchema<boolean>;
}, undefined, {
id: string;
no: number;
vposMs: number;
body: string;
commands: string[];
userId: string;
isPremium: boolean;
score: number;
postedAt: string;
nicoruCount: number;
nicoruId: string | null;
source: string;
isMyPost: boolean;
}>;
type V1Comment = Output<typeof ZV1Comment>;
declare const ZV1Thread: ObjectSchema<{
id: UnknownSchema<unknown>;
fork: StringSchema<string>;
commentCount: OptionalSchema<NumberSchema<number>, 0, number>;
comments: ArraySchema<ObjectSchema<{
id: StringSchema<string>;
no: NumberSchema<number>;
vposMs: NumberSchema<number>;
body: StringSchema<string>;
commands: ArraySchema<StringSchema<string>, string[]>;
userId: StringSchema<string>;
isPremium: BooleanSchema<boolean>;
score: NumberSchema<number>;
postedAt: StringSchema<string>;
nicoruCount: NumberSchema<number>;
nicoruId: NullableSchema<StringSchema<string>, undefined, string | null>;
source: StringSchema<string>;
isMyPost: BooleanSchema<boolean>;
}, undefined, {
id: string;
no: number;
vposMs: number;
body: string;
commands: string[];
userId: string;
isPremium: boolean;
score: number;
postedAt: string;
nicoruCount: number;
nicoruId: string | null;
source: string;
isMyPost: boolean;
}>, {
id: string;
no: number;
vposMs: number;
body: string;
commands: string[];
userId: string;
isPremium: boolean;
score: number;
postedAt: string;
nicoruCount: number;
nicoruId: string | null;
source: string;
isMyPost: boolean;
}[]>;
}, undefined, {
id: unknown;
fork: string;
commentCount: number;
comments: {
id: string;
no: number;
vposMs: number;
body: string;
commands: string[];
userId: string;
isPremium: boolean;
score: number;
postedAt: string;
nicoruCount: number;
nicoruId: string | null;
source: string;
isMyPost: boolean;
}[];
}>;
type V1Thread = Output<typeof ZV1Thread>;
type v1Thread = V1Thread;
declare const ZXml2jsChatItem: ObjectSchema<{
_: StringSchema<string>;
$: ObjectSchema<{
no: OptionalSchema<StringSchema<string>, undefined, string | undefined>;
vpos: StringSchema<string>;
date: OptionalSchema<StringSchema<string>, "0", string>;
date_usec: OptionalSchema<StringSchema<string>, "0", string>;
user_id: OptionalSchema<StringSchema<string>, undefined, string | undefined>;
owner: OptionalSchema<StringSchema<string>, "", string>;
premium: OptionalSchema<StringSchema<string>, "", string>;
mail: OptionalSchema<StringSchema<string>, "", string>;
}, undefined, {
owner: string;
vpos: string;
date: string;
date_usec: string;
premium: string;
mail: string;
user_id?: string | undefined;
no?: string | undefined;
}>;
}, undefined, {
_: string;
$: {
owner: string;
vpos: string;
date: string;
date_usec: string;
premium: string;
mail: string;
user_id?: string | undefined;
no?: string | undefined;
};
}>;
type Xml2jsChatItem = Output<typeof ZXml2jsChatItem>;
declare const ZXml2jsChat: ObjectSchema<{
chat: ArraySchema<ObjectSchema<{
_: StringSchema<string>;
$: ObjectSchema<{
no: OptionalSchema<StringSchema<string>, undefined, string | undefined>;
vpos: StringSchema<string>;
date: OptionalSchema<StringSchema<string>, "0", string>;
date_usec: OptionalSchema<StringSchema<string>, "0", string>;
user_id: OptionalSchema<StringSchema<string>, undefined, string | undefined>;
owner: OptionalSchema<StringSchema<string>, "", string>;
premium: OptionalSchema<StringSchema<string>, "", string>;
mail: OptionalSchema<StringSchema<string>, "", string>;
}, undefined, {
owner: string;
vpos: string;
date: string;
date_usec: string;
premium: string;
mail: string;
user_id?: string | undefined;
no?: string | undefined;
}>;
}, undefined, {
_: string;
$: {
owner: string;
vpos: string;
date: string;
date_usec: string;
premium: string;
mail: string;
user_id?: string | undefined;
no?: string | undefined;
};
}>, {
_: string;
$: {
owner: string;
vpos: string;
date: string;
date_usec: string;
premium: string;
mail: string;
user_id?: string | undefined;
no?: string | undefined;
};
}[]>;
}, undefined, {
chat: {
_: string;
$: {
owner: string;
vpos: string;
date: string;
date_usec: string;
premium: string;
mail: string;
user_id?: string | undefined;
no?: string | undefined;
};
}[];
}>;
type Xml2jsChat = Output<typeof ZXml2jsChat>;
declare const ZXml2jsPacket: ObjectSchema<{
packet: ObjectSchema<{
chat: ArraySchema<ObjectSchema<{
_: StringSchema<string>;
$: ObjectSchema<{
no: OptionalSchema<StringSchema<string>, undefined, string | undefined>;
vpos: StringSchema<string>;
date: OptionalSchema<StringSchema<string>, "0", string>;
date_usec: OptionalSchema<StringSchema<string>, "0", string>;
user_id: OptionalSchema<StringSchema<string>, undefined, string | undefined>;
owner: OptionalSchema<StringSchema<string>, "", string>;
premium: OptionalSchema<StringSchema<string>, "", string>;
mail: OptionalSchema<StringSchema<string>, "", string>;
}, undefined, {
owner: string;
vpos: string;
date: string;
date_usec: string;
premium: string;