diff --git a/package.json b/package.json index 05bf5851a9..fe2dbc2c17 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "ui/tree", "ui/msg", "ui/@build/rollupProject", - "ui/@types/lichess" + "ui/@types/lichess", + "ui/@types/cash" ] } diff --git a/ui/@types/cash/index.d.ts b/ui/@types/cash/index.d.ts new file mode 100644 index 0000000000..018e856614 --- /dev/null +++ b/ui/@types/cash/index.d.ts @@ -0,0 +1,316 @@ +interface Event { + namespace: string; + data: any; + relatedTarget?: Node | null; + ___cd?: boolean; + ___ifocus?: boolean; + ___iblur?: boolean; + ___ot?: string; + ___td?: boolean; +} +interface Cash { + [index: number]: EleLoose | undefined; + length: number; + splice(start: number, deleteCount?: number): EleLoose[]; + splice(start: number, deleteCount: number, ...items: Ele[]): EleLoose[]; +} +interface CashStatic { + fn: Cash; +} +declare type falsy = undefined | null | false | 0 | ''; +declare type Ele = Window | Document | HTMLElement | Element | Node; +declare type EleLoose = HTMLElement & Element & Node; +declare type Selector = falsy | string | Function | HTMLCollection | NodeList | Ele | Ele[] | ArrayLike | Cash; +declare type Comparator = string | Ele | Cash | ((this: EleLoose, index: number, ele: EleLoose) => boolean); +declare type Context = Document | HTMLElement | Element; +declare type EventCallback = { + (event: any, data?: any): any; + guid?: number; +}; +declare class Cash { + constructor(selector?: Selector, context?: Context | Cash); + init(selector?: Selector, context?: Context | Cash): Cash; +} +declare const cash: ((selector?: Selector, context?: Context | Cash) => Cash) & CashStatic; +declare type MapCallback = (this: T, index: number, ele: T) => Ele; +interface Cash { + map(callback: MapCallback): Cash; +} +interface Cash { + slice(start?: number, end?: number): Cash; +} +declare type EachCallback = (this: T, index: number, ele: T) => any; +interface CashStatic { + each(arr: ArrayLike, callback: EachCallback): void; +} +interface Cash { + each(callback: EachCallback): this; +} +interface Cash { + removeProp(prop: string): this; +} +interface CashStatic { + guid: number; +} +interface CashStatic { + isWindow(x: any): x is Window; + isFunction(x: any): x is Function; + isNumeric(x: any): boolean; + isArray(x: any): x is Array; +} +interface Cash { + prop(prop: string): any; + prop(prop: string, value: any): this; + prop(props: Record): this; +} +interface Cash { + get(): EleLoose[]; + get(index: number): EleLoose | undefined; +} +interface Cash { + eq(index: number): Cash; +} +interface Cash { + first(): Cash; +} +interface Cash { + last(): Cash; +} +interface Cash { + filter(comparator?: Comparator): Cash; +} +interface Cash { + hasClass(cls: string): boolean; +} +interface Cash { + removeAttr(attrs: string): this; +} +interface Cash { + attr(): undefined; + attr(attrs: string): string | null; + attr(attrs: string, value: string): this; + attr(attrs: Record): this; +} +interface Cash { + toggleClass(classes: string, force?: boolean): this; +} +interface Cash { + addClass(classes: string): this; +} +interface Cash { + removeClass(classes?: string): this; +} +interface CashStatic { + unique(arr: ArrayLike): ArrayLike; +} +interface Cash { + add(selector: Selector, context?: Context): Cash; +} +interface Cash { + css(prop: string): string | undefined; + css(prop: string, value: number | string): this; + css(props: Record): this; +} +interface Cash { + data(): Record | undefined; + data(name: string): any; + data(name: string, value: any): this; + data(datas: Record): this; +} +interface Cash { + innerWidth(): number | undefined; + innerHeight(): number | undefined; + outerWidth(includeMargins?: boolean): number; + outerHeight(includeMargins?: boolean): number; +} +interface Cash { + width(): number; + width(value: number | string): this; + height(): number; + height(value: number | string): this; +} +interface Cash { + toggle(force?: boolean): this; +} +interface Cash { + hide(): this; +} +interface Cash { + show(): this; +} +interface Cash { + off(): this; + off(events: string): this; + off(events: Record): this; + off(events: string, callback: EventCallback): this; + off(events: string, selector: string, callback: EventCallback): this; +} +interface Cash { + on(events: Record): this; + on(events: Record, selector: string): this; + on(events: Record, data: any): this; + on(events: Record, selector: string | null | undefined, data: any): this; + on(events: string, callback: EventCallback): this; + on(events: string, selector: string, callback: EventCallback): this; + on(events: string, data: any, callback: EventCallback): this; + on(events: string, selector: string | null | undefined, data: any, callback: EventCallback, _one?: boolean): this; +} +interface Cash { + one(events: Record): this; + one(events: Record, selector: string): this; + one(events: Record, data: any): this; + one(events: Record, selector: string | null | undefined, data: any): this; + one(events: string, callback: EventCallback): this; + one(events: string, selector: string, callback: EventCallback): this; + one(events: string, data: any, callback: EventCallback): this; + one(events: string, selector: string | null | undefined, data: any, callback: EventCallback): this; +} +interface Cash { + ready(callback: Function): this; +} +interface Cash { + trigger(event: Event | string, data?: any): this; +} +interface Cash { + serialize(): string; +} +interface Cash { + val(): string | string[]; + val(value: string | string[]): this; +} +interface Cash { + clone(): this; +} +interface Cash { + detach(comparator?: Comparator): this; +} +interface CashStatic { + parseHTML(html: string): EleLoose[]; +} +interface Cash { + empty(): this; +} +interface Cash { + html(): string; + html(html: string): this; +} +interface Cash { + remove(comparator?: Comparator): this; +} +interface Cash { + text(): string; + text(text: string): this; +} +interface Cash { + unwrap(): this; +} +interface Cash { + offset(): undefined | { + top: number; + left: number; + }; +} +interface Cash { + offsetParent(): Cash; +} +interface Cash { + position(): undefined | { + top: number; + left: number; + }; +} +interface Cash { + children(comparator?: Comparator): Cash; +} +interface Cash { + contents(): Cash; +} +interface Cash { + find(selector: string): Cash; +} +interface Cash { + after(...selectors: Selector[]): this; +} +interface Cash { + append(...selectors: Selector[]): this; +} +interface Cash { + appendTo(selector: Selector): this; +} +interface Cash { + before(...selectors: Selector[]): this; +} +interface Cash { + insertAfter(selector: Selector): this; +} +interface Cash { + insertBefore(selector: Selector): this; +} +interface Cash { + prepend(...selectors: Selector[]): this; +} +interface Cash { + prependTo(selector: Selector): this; +} +interface Cash { + replaceWith(selector: Selector): this; +} +interface Cash { + replaceAll(selector: Selector): this; +} +interface Cash { + wrapAll(selector?: Selector): this; +} +interface Cash { + wrap(selector?: Selector): this; +} +interface Cash { + wrapInner(selector?: Selector): this; +} +interface Cash { + has(selector: string | Node): Cash; +} +interface Cash { + is(comparator?: Comparator): boolean; +} +interface Cash { + next(comparator?: Comparator, _all?: boolean, _until?: Comparator): Cash; +} +interface Cash { + nextAll(comparator?: Comparator): Cash; +} +interface Cash { + nextUntil(until?: Comparator, comparator?: Comparator): Cash; +} +interface Cash { + not(comparator?: Comparator): Cash; +} +interface Cash { + parent(comparator?: Comparator): Cash; +} +interface Cash { + index(selector?: Selector): number; +} +interface Cash { + closest(comparator?: Comparator): Cash; +} +interface Cash { + parents(comparator?: Comparator, _until?: Comparator): Cash; +} +interface Cash { + parentsUntil(until?: Comparator, comparator?: Comparator): Cash; +} +interface Cash { + prev(comparator?: Comparator, _all?: boolean, _until?: Comparator): Cash; +} +interface Cash { + prevAll(comparator?: Comparator): Cash; +} +interface Cash { + prevUntil(until?: Comparator, comparator?: Comparator): Cash; +} +interface Cash { + siblings(comparator?: Comparator): Cash; +} +export default cash; +export { Cash, CashStatic, Ele as Element, Selector, Comparator, Context }; diff --git a/ui/@types/cash/package.json b/ui/@types/cash/package.json new file mode 100644 index 0000000000..b7971c175e --- /dev/null +++ b/ui/@types/cash/package.json @@ -0,0 +1,8 @@ +{ + "name": "@types/cash", + "version": "8.0.0", + "private": true, + "description": "lichess.org cash.js type declarations", + "author": "Thibault Duplessis", + "license": "AGPL-3.0-or-later" +} diff --git a/ui/common/package.json b/ui/common/package.json index a1ac28ffec..a56d9668fb 100644 --- a/ui/common/package.json +++ b/ui/common/package.json @@ -17,6 +17,7 @@ }, "devDependencies": { "@types/lichess": "2.0.0", + "@types/cash": "8.0.0", "typescript": "^4.0.2" } } diff --git a/ui/tsconfig.base.json b/ui/tsconfig.base.json index 36587865d2..00b819c6d4 100644 --- a/ui/tsconfig.base.json +++ b/ui/tsconfig.base.json @@ -12,6 +12,6 @@ "target": "ES2016", "module": "commonjs", "lib": ["DOM", "ES2016", "DOM.iterable"], - "types": ["lichess", "jquery", "defer-promise"] + "types": ["lichess", "cash", "defer-promise"] } }