forked from disjukr/croquis.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stroke-protocol.ts
30 lines (29 loc) · 1.3 KB
/
stroke-protocol.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { StylusState } from './stylus';
export interface StrokeProtocol<TConfig = unknown, TState = unknown, TResult = unknown> {
resume(config: TConfig, prevState: TState): StrokeDrawingContext<TConfig, TState, TResult>;
down(config: TConfig, stylusState: StylusState): StrokeDrawingContext<TConfig, TState, TResult>;
}
export interface StrokeDrawingContext<TConfig = unknown, TState = unknown, TResult = unknown> {
getConfig(): TConfig;
getConfig<TStroke extends StrokeProtocol>(target: TStroke): ConfigOfStrokeProtocol<TStroke>;
getState(): TState;
getState<TStroke extends StrokeProtocol>(target: TStroke): StateOfStrokeProtocol<TStroke>;
move(stylusState: StylusState): void;
up(stylusState: StylusState): TResult;
}
export type StrokeDrawingContextFromProtocol<T> = T extends StrokeProtocol<
infer TConfig,
infer TState,
infer TResult
>
? StrokeDrawingContext<TConfig, TState, TResult>
: StrokeDrawingContext<unknown, unknown, unknown>;
export type ConfigOfStrokeProtocol<T> = T extends StrokeProtocol<infer TConfig, unknown, unknown>
? TConfig
: unknown;
export type StateOfStrokeProtocol<T> = T extends StrokeProtocol<unknown, infer TState, unknown>
? TState
: unknown;
export type ResultOfStrokeProtocol<T> = T extends StrokeProtocol<unknown, unknown, infer TResult>
? TResult
: unknown;