Reformat typescript/**/*.d.ts

pull/2587/head
Rob Pilling 2023-02-19 18:01:08 +00:00
parent 8a3c9a26e5
commit 12575cda34
4 changed files with 205 additions and 205 deletions

View File

@ -1,56 +1,56 @@
declare module ClockFace_ { declare module ClockFace_ {
export class ClockFace { export class ClockFace {
constructor(options: Options | Draw); constructor(options: Options | Draw);
is12Hour: boolean; is12Hour: boolean;
paused: boolean; paused: boolean;
showDate: boolean; // default true showDate: boolean; // default true
loadWidgets: boolean; // default true loadWidgets: boolean; // default true
start(): void; start(): void;
tick(): void; tick(): void;
pause(): void; pause(): void;
resume(): void; resume(): void;
remove(): void; remove(): void;
redraw(): void; redraw(): void;
} }
type Options = { type Options = {
precision?: number, // seconds precision?: number, // seconds
init?: () => void, init?: () => void,
pause?: () => void, pause?: () => void,
resume?: () => void, resume?: () => void,
remove?: () => void, remove?: () => void,
settingsFile?: string, settingsFile?: string,
} & ( } & (
{ {
draw: Draw draw: Draw
} | { } | {
update: Update, update: Update,
} | { } | {
draw: Draw, draw: Draw,
update: Update, update: Update,
} }
) & ( ) & (
{ {
up?: () => void, up?: () => void,
down?: () => void, down?: () => void,
} | { } | {
upDown?: (dir: -1 | 1) => void, upDown?: (dir: -1 | 1) => void,
} }
); );
type Draw = (d: Date, changed: Changed<true>) => void; type Draw = (d: Date, changed: Changed<true>) => void;
type Update = (d: Date, changed: Changed) => void; type Update = (d: Date, changed: Changed) => void;
type Changed<T extends boolean = boolean> = { type Changed<T extends boolean = boolean> = {
d: T, d: T,
h: T, h: T,
m: T, m: T,
s: T, s: T,
} }
} }

View File

@ -1,58 +1,58 @@
declare module ClockInfo { declare module ClockInfo {
function load(): Menu[]; function load(): Menu[];
function addInteractive(menu: Menu[], options: Options): InteractiveOptions; function addInteractive(menu: Menu[], options: Options): InteractiveOptions;
type Menu = { type Menu = {
name: string, name: string,
img: string, img: string,
dynamic?: boolean, dynamic?: boolean,
items: MenuItem[], items: MenuItem[],
}; };
type MenuItem = { type MenuItem = {
name: string, name: string,
show(): void, show(): void,
hide(): void, hide(): void,
on(what: "redraw", cb: () => void): void, // extending from Object on(what: "redraw", cb: () => void): void, // extending from Object
run?(): void, run?(): void,
} & ( } & (
{ {
hasRange: true, hasRange: true,
get(): RangeItem, get(): RangeItem,
} | { } | {
hasRange: false, hasRange: false,
get(): Item, get(): Item,
} }
); );
type Item = { type Item = {
text: string, text: string,
short?: string, short?: string,
img?: string, img?: string,
}; };
type RangeItem = type RangeItem =
Item & { Item & {
v: number, v: number,
min: number, min: number,
max: number, max: number,
}; };
type Options = { type Options = {
x: number, x: number,
y: number, y: number,
w: number, w: number,
h: number, h: number,
draw(itm: MenuItem, info: Item, options: InteractiveOptions): void, draw(itm: MenuItem, info: Item, options: InteractiveOptions): void,
}; };
type InteractiveOptions = type InteractiveOptions =
Options & { Options & {
index: number, index: number,
menuA: number, menuA: number,
menuB: number, menuB: number,
remove(): void, remove(): void,
redraw(): void, redraw(): void,
focus: boolean, focus: boolean,
}; };
} }

View File

@ -1,125 +1,125 @@
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
type ExtractIds<T extends Layout_.Hierarchy, Depth extends Prev[number] = 9> = type ExtractIds<T extends Layout_.Hierarchy, Depth extends Prev[number] = 9> =
[Depth] extends [never] [Depth] extends [never]
? never ? never
: (T extends { id: infer Id extends string } : (T extends { id: infer Id extends string }
? { [k in Id]: T } ? { [k in Id]: T }
: never) : never)
| |
( (
T extends { c: Array<infer Sub extends Layout_.Hierarchy> } T extends { c: Array<infer Sub extends Layout_.Hierarchy> }
? ExtractIds<Sub, Prev[Depth]> ? ExtractIds<Sub, Prev[Depth]>
: never : never
); );
declare module Layout_ { declare module Layout_ {
type Layouter<T extends Hierarchy> = type Layouter<T extends Hierarchy> =
ExtractIds<T> ExtractIds<T>
& &
{ {
// these actually change T // these actually change T
render(l?: T): void; render(l?: T): void;
layout(l: T): void; layout(l: T): void;
debug(l?: T, c?: ColorResolvable): void; debug(l?: T, c?: ColorResolvable): void;
update(): void; // changes layoutObject into a RenderedHierarchy update(): void; // changes layoutObject into a RenderedHierarchy
clear(obj?: T): void; clear(obj?: T): void;
forgetLazyState(): void; forgetLazyState(): void;
setUI(): void; setUI(): void;
}; };
var Layout: { var Layout: {
new <T extends Hierarchy>( new <T extends Hierarchy>(
hier: T, hier: T,
options?: { options?: {
lazy: boolean, lazy: boolean,
btns?: { btns?: {
label: string, label: string,
cb: () => void, cb: () => void,
cbl: () => void, cbl: () => void,
}[], }[],
back?: () => void, back?: () => void,
remove?: () => void, remove?: () => void,
}, },
): Layouter<T>; ): Layouter<T>;
}; };
export type Layout = typeof Layout; export type Layout = typeof Layout;
type Image = string; type Image = string;
type Fill = 0 | 1 | 2; // 0=no, 1=yes, 2=2x more space type Fill = 0 | 1 | 2; // 0=no, 1=yes, 2=2x more space
type RenderedHierarchy = type RenderedHierarchy =
Hierarchy & { Hierarchy & {
// top left position // top left position
x: number, x: number,
y: number, y: number,
// width and height // width and height
w: number, w: number,
h: number, h: number,
// minimum width and height // minimum width and height
_w: number, _w: number,
_h: number, _h: number,
}; };
type Hierarchy = type Hierarchy =
HierarchyParts & { HierarchyParts & {
id?: string, id?: string,
font?: FontNameWithScaleFactor, font?: FontNameWithScaleFactor,
scale?: number, scale?: number,
col?: ColorResolvable, col?: ColorResolvable,
bgCol?: ColorResolvable, bgCol?: ColorResolvable,
pad?: number, pad?: number,
fillx?: Fill, fillx?: Fill,
filly?: Fill, filly?: Fill,
width?: number, width?: number,
height?: number, height?: number,
} & ( } & (
{ {
r?: number, // 0: 0°, 1: 90°, 2: 180°, 3: 270°. r?: number, // 0: 0°, 1: 90°, 2: 180°, 3: 270°.
} | { } | {
wrap?: boolean, wrap?: boolean,
} }
); );
type Align = -1 | 0 | 1; type Align = -1 | 0 | 1;
type HierarchyParts = type HierarchyParts =
{ {
type: "v", type: "v",
c: Hierarchy[], c: Hierarchy[],
halign?: Align, halign?: Align,
} | { } | {
type: "h" type: "h"
c: Hierarchy[], c: Hierarchy[],
valign?: Align, valign?: Align,
} | { } | {
type: "txt", type: "txt",
label: string, label: string,
font: FontNameWithScaleFactor, font: FontNameWithScaleFactor,
} | { } | {
type: undefined, // blank, for padding type: undefined, // blank, for padding
} | ( } | (
{ {
type: "btn", type: "btn",
src: Image, src: Image,
cb: () => void, cb: () => void,
} | { } | {
type: "btn", type: "btn",
cb: () => void, cb: () => void,
label: string, label: string,
font?: FontNameWithScaleFactor, font?: FontNameWithScaleFactor,
scale?: number, scale?: number,
} }
) | { ) | {
type: "img", type: "img",
src: Image | (() => Image), src: Image | (() => Image),
} | { } | {
type: "custom", type: "custom",
render: (h: Hierarchy) => void, render: (h: Hierarchy) => void,
}; };
} }

View File

@ -54,7 +54,7 @@ type MenuOptions = {
type Menu = { type Menu = {
""?: MenuOptions; ""?: MenuOptions;
[key: string]: [key: string]:
| MenuOptions // not actually an option here | MenuOptions
| (() => void) | (() => void)
| MenuBooleanItem | MenuBooleanItem
| MenuNumberItem | MenuNumberItem
@ -13299,4 +13299,4 @@ declare module "Storage" {
* @url http://www.espruino.com/Reference#l_Storage_open * @url http://www.espruino.com/Reference#l_Storage_open
*/ */
function open(name: string, mode: "r" | "w" | "a"): StorageFile; function open(name: string, mode: "r" | "w" | "a"): StorageFile;
} }