<commit_before>/*!
 * V4Fire Client Core
 * https://github.com/V4Fire/Client
 *
 * Released under the MIT license
 * https://github.com/V4Fire/Client/blob/master/LICENSE
 */

import Super, {

	AsyncOpts,
	AsyncCbOpts,
	AsyncOnOpts,
	ClearOptsId,
	Link as SuperLink,
	LinkNamesList as SuperLinkNamesList,
	ProxyCb,
	isParams

} from '@v4fire/core/core/async';

export * from '@v4fire/core/core/async';
export interface AsyncRequestAnimationFrameOpts<T extends object = Async> extends AsyncCbOpts<T> {
	element?: Element;
}

export interface AsyncAnimationFrameOpts extends AsyncOpts {
	element?: Element;
}

export interface AsyncDnDOpts<R = unknown, CTX extends object = Async> extends AsyncOnOpts<CTX> {
	onDragStart?: DnDCb<R, CTX> | DnDEventOpts<R, CTX>;
	onDrag?: DnDCb<R, CTX> | DnDEventOpts<R, CTX>;
	onDragEnd?: DnDCb<R, CTX> | DnDEventOpts<R, CTX>;
}

export type DnDCb<R = unknown, CTX extends object = Async> = Function | ((this: CTX, e: MouseEvent, el: Node) => R);
export type AnimationFrameCb<R = unknown, CTX extends object = Async> = ProxyCb<number, R, CTX>;

export interface DnDEventOpts<R = unknown, CTX extends object = Async> {
	capture?: boolean;
	handler: DnDCb<R, CTX>;
}

export enum ClientLinkNames {
	animationFrame,
	animationFramePromise
}

export type ClientLink = keyof typeof ClientLinkNames;
export type Link = SuperLink | keyof typeof ClientLinkNames;
export type LinkNamesList = SuperLinkNamesList & Record<ClientLink, ClientLink>;

const
	linkNamesDictionary = <LinkNamesList>{...Super.linkNames, ...Object.convertEnumToDict(ClientLinkNames)};

export default class Async<CTX extends object = Async<any>> extends Super<CTX> {
	/** @override */
	static linkNames: LinkNamesList = linkNamesDictionary;

	/** @override */
	protected get linkNames(): LinkNamesList {
		return (<typeof Async>this.constructor).linkNames;
	}

	/**
	 * Wrapper for requestAnimationFrame
	 *
	 * @param fn - callback function
	 * @param [element] - link for the element
	 */
	requestAnimationFrame<T = unknown>(fn: AnimationFrameCb<T, CTX>, element?: Element): Nullable<number>;

	/**
	 * Wrapper for requestAnimationFrame
	 *
	 * @param fn - callback function<commit_msg>Refactoring<commit_after>/*!
 * V4Fire Client Core
 * https://github.com/V4Fire/Client
 *
 * Released under the MIT license
 * https://github.com/V4Fire/Client/blob/master/LICENSE
 */

import Super, {

	AsyncOpts,
	AsyncCbOpts,
	AsyncOnOpts,
	ClearOptsId,
	Link as SuperLink,
	LinkNamesList as SuperLinkNamesList,
	ProxyCb,
	isParams

} from '@v4fire/core/core/async';

export * from '@v4fire/core/core/async';
export interface AsyncRequestAnimationFrameOpts<T extends object = Async> extends AsyncCbOpts<T> {
	element?: Element;
}

export interface AsyncAnimationFrameOpts extends AsyncOpts {
	element?: Element;
}

export interface AsyncDnDOpts<R = unknown, CTX extends object = Async> extends AsyncOnOpts<CTX> {
	onDragStart?: DnDCb<R, CTX> | DnDEventOpts<R, CTX>;
	onDrag?: DnDCb<R, CTX> | DnDEventOpts<R, CTX>;
	onDragEnd?: DnDCb<R, CTX> | DnDEventOpts<R, CTX>;
}

export type DnDCb<R = unknown, CTX extends object = Async> = Function | ((this: CTX, e: MouseEvent, el: Node) => R);
export type AnimationFrameCb<R = unknown, CTX extends object = Async> = ProxyCb<number, R, CTX>;

export interface DnDEventOpts<R = unknown, CTX extends object = Async> {
	capture?: boolean;
	handler: DnDCb<R, CTX>;
}

export enum ClientLinkNames {
	animationFrame,
	animationFramePromise
}

const
	linkNamesDictionary = {...Super.linkNames, ...Object.convertEnumToDict(ClientLinkNames)};

export type ClientLink = keyof typeof ClientLinkNames;
export type Link = SuperLink | ClientLink;
export type LinkNamesList = typeof linkNamesDictionary;

export default class Async<CTX extends object = Async<any>> extends Super<CTX> {
	/** @override */
	static linkNames: LinkNamesList = linkNamesDictionary;

	/** @override */
	protected get linkNames(): LinkNamesList {
		return (<typeof Async>this.constructor).linkNames;
	}

	/**
	 * Wrapper for requestAnimationFrame
	 *
	 * @param fn - callback function
	 * @param [element] - link for the element
	 */
	requestAnimationFrame<T = unknown>(fn: AnimationFrameCb<T, CTX>, element?: Element): Nullable<number>;

	/**
	 * Wrapper for requestAnimationFrame
	 *
	 * @param fn - callback function
{'fraction_non_alphanumeric': 0.11802973977695168, 'fraction_numerical': 0.0023234200743494425, 'mean_word_length': 5.037868162692847, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 51, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1022415', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1404, 'n_words': 374}