mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Add types for the webicon-module (#35563)
* Add types for the webicon-module * Fix typo * Add a version-restriction * Add function-type restrictions * Fix the code according to tslint
This commit is contained in:
committed by
Ryan Cavanaugh
parent
e7c6a961a7
commit
c102f3c275
8
types/webicon/Icon/CssClassConfig.d.ts
vendored
Normal file
8
types/webicon/Icon/CssClassConfig.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { IconClassGenerator } from "./IconClassGenerator";
|
||||
|
||||
/**
|
||||
* Represents a css-class resolver.
|
||||
*
|
||||
* If you provide a `string`, `?` and `%` are replaced by the icon-id.
|
||||
*/
|
||||
export type CssClassConfig = string | IconClassGenerator;
|
||||
7
types/webicon/Icon/CssIconSet.d.ts
vendored
Normal file
7
types/webicon/Icon/CssIconSet.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { ImageIcon } from "./ImageIcon";
|
||||
|
||||
/**
|
||||
* Represents a css icon-set.
|
||||
*/
|
||||
export interface CssIconSet extends ImageIcon {
|
||||
}
|
||||
18
types/webicon/Icon/Icon.d.ts
vendored
Normal file
18
types/webicon/Icon/Icon.d.ts
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Represents an icon.
|
||||
*/
|
||||
export interface Icon {
|
||||
/**
|
||||
* Parses the input to an icon-id.
|
||||
*
|
||||
* @param id
|
||||
* The id of the icon to get.
|
||||
*
|
||||
* @param params
|
||||
* Additional parameters for getting the icon.
|
||||
*
|
||||
* @return
|
||||
* The id of the icon to get.
|
||||
*/
|
||||
iconIdParser?(id: string, params: string[]): string;
|
||||
}
|
||||
9
types/webicon/Icon/IconClassGenerator.d.ts
vendored
Normal file
9
types/webicon/Icon/IconClassGenerator.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Provides the functionality to generate a css-class for an icon.
|
||||
*/
|
||||
export interface IconClassGenerator {
|
||||
/**
|
||||
* Generates a css-class for an icon.
|
||||
*/
|
||||
(id: string, params: string[]): string;
|
||||
}
|
||||
7
types/webicon/Icon/ImageIcon.d.ts
vendored
Normal file
7
types/webicon/Icon/ImageIcon.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Icon } from "./Icon";
|
||||
|
||||
/**
|
||||
* Represents a non-vector icon.
|
||||
*/
|
||||
export interface ImageIcon extends Icon {
|
||||
}
|
||||
11
types/webicon/Icon/Options/AliasOptions.d.ts
vendored
Normal file
11
types/webicon/Icon/Options/AliasOptions.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Identifiable } from "../../System/Identifiable";
|
||||
|
||||
/**
|
||||
* Provides options for aliases.
|
||||
*/
|
||||
export interface AliasOptions {
|
||||
/**
|
||||
* The icon-set this alias refers to.
|
||||
*/
|
||||
alias: string;
|
||||
}
|
||||
24
types/webicon/Icon/Options/CssIconSetOptions.d.ts
vendored
Normal file
24
types/webicon/Icon/Options/CssIconSetOptions.d.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { CssClassConfig } from "../CssClassConfig";
|
||||
import { IconOptions } from "./IconOptions";
|
||||
|
||||
/**
|
||||
* Provides options for css icon-sets.
|
||||
*/
|
||||
export interface CssIconSetOptions extends IconOptions {
|
||||
/**
|
||||
* Either a text-pattern or a callback which provides a css-classname.
|
||||
*
|
||||
* The symbols `?` and `%` in the text-pattern are replaced by the icon-id.
|
||||
*/
|
||||
className?: CssClassConfig;
|
||||
|
||||
/**
|
||||
* An alias of the `className`-property.
|
||||
*/
|
||||
class?: this["className"];
|
||||
|
||||
/**
|
||||
* An alias of the `className`-property.
|
||||
*/
|
||||
cssClass?: this["className"];
|
||||
}
|
||||
17
types/webicon/Icon/Options/Downloadable.d.ts
vendored
Normal file
17
types/webicon/Icon/Options/Downloadable.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { UrlConfig } from "../../Web/UrlConfig";
|
||||
import { IconOptions } from "./IconOptions";
|
||||
|
||||
/**
|
||||
* Represents a downloadable object.
|
||||
*/
|
||||
export interface Downloadable<TUriParam = never> extends IconOptions {
|
||||
/**
|
||||
* The url to load the source from.
|
||||
*/
|
||||
url?: UrlConfig<TUriParam>;
|
||||
|
||||
/**
|
||||
* An alias of the `url`-property.
|
||||
*/
|
||||
uri?: this["url"];
|
||||
}
|
||||
7
types/webicon/Icon/Options/IconOptions.d.ts
vendored
Normal file
7
types/webicon/Icon/Options/IconOptions.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Icon } from "../Icon";
|
||||
|
||||
/**
|
||||
* Provides options for icons.
|
||||
*/
|
||||
export interface IconOptions extends Icon {
|
||||
}
|
||||
14
types/webicon/Icon/Options/IconSetOptions.d.ts
vendored
Normal file
14
types/webicon/Icon/Options/IconSetOptions.d.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { SvgIcon } from "../SvgIcon";
|
||||
import { Downloadable } from "./Downloadable";
|
||||
import { IconOptions } from "./IconOptions";
|
||||
import { SizeableOptions } from "./SizeableOptions";
|
||||
|
||||
/**
|
||||
* Provides options for svg-icon sets.
|
||||
*/
|
||||
export interface IconSetOptions extends IconOptions, SvgIcon, SizeableOptions, Downloadable {
|
||||
/**
|
||||
* A value indicating whether the icons are loaded separately.
|
||||
*/
|
||||
cumulative?: boolean;
|
||||
}
|
||||
8
types/webicon/Icon/Options/ImageIconOptions.d.ts
vendored
Normal file
8
types/webicon/Icon/Options/ImageIconOptions.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { IconOptions } from "./IconOptions";
|
||||
import { Storeable } from "./Storeable";
|
||||
|
||||
/**
|
||||
* Provides options for non-vector icons.
|
||||
*/
|
||||
export interface ImageIconOptions extends IconOptions, Storeable {
|
||||
}
|
||||
16
types/webicon/Icon/Options/SizeableOptions.d.ts
vendored
Normal file
16
types/webicon/Icon/Options/SizeableOptions.d.ts
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Sizeable } from "../Sizeable";
|
||||
|
||||
/**
|
||||
* Provides options for sizeable objects.
|
||||
*/
|
||||
export interface SizeableOptions extends Sizeable {
|
||||
/**
|
||||
* An alias of the `iconSize`-property.
|
||||
*/
|
||||
size?: this["iconSize"];
|
||||
|
||||
/**
|
||||
* An alias of the `iconSize`-property.
|
||||
*/
|
||||
svgIconSize?: this["iconSize"];
|
||||
}
|
||||
22
types/webicon/Icon/Options/Storeable.d.ts
vendored
Normal file
22
types/webicon/Icon/Options/Storeable.d.ts
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Downloadable } from "./Downloadable";
|
||||
|
||||
/**
|
||||
* Represents a storeable object.
|
||||
*/
|
||||
export interface Storeable extends Downloadable {
|
||||
/**
|
||||
* A value indicating whether the source is preloadable.
|
||||
*/
|
||||
preloadable?: boolean;
|
||||
|
||||
/**
|
||||
* Resolves the id of the underlying source.
|
||||
*
|
||||
* @param id
|
||||
* The underlying id of the source.
|
||||
*
|
||||
* @return
|
||||
* The resolved id of the source.
|
||||
*/
|
||||
iconIdResolver?(id: string): string;
|
||||
}
|
||||
13
types/webicon/Icon/Options/SvgCumulativeIconSetOptions.d.ts
vendored
Normal file
13
types/webicon/Icon/Options/SvgCumulativeIconSetOptions.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { IconSetOptions } from "./IconSetOptions";
|
||||
|
||||
/**
|
||||
* Provides options for svg-sets which are loaded lazily.
|
||||
*/
|
||||
export interface SvgCumulativeIconSetOptions extends IconSetOptions {
|
||||
cumulative: true;
|
||||
|
||||
/**
|
||||
* The amount of miliseconds to wait before downloading the icons.
|
||||
*/
|
||||
waitDuration?: number;
|
||||
}
|
||||
9
types/webicon/Icon/Options/SvgIconOptions.d.ts
vendored
Normal file
9
types/webicon/Icon/Options/SvgIconOptions.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { ImageIconOptions } from "./ImageIconOptions";
|
||||
import { SizeableOptions } from "./SizeableOptions";
|
||||
import { SvgIcon } from "../SvgIcon";
|
||||
|
||||
/**
|
||||
* Provides options for svg-icons.
|
||||
*/
|
||||
export interface SvgIconOptions extends ImageIconOptions, SizeableOptions, SvgIcon {
|
||||
}
|
||||
9
types/webicon/Icon/Options/SvgIconSetOptions.d.ts
vendored
Normal file
9
types/webicon/Icon/Options/SvgIconSetOptions.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { IconSetOptions } from "./IconSetOptions";
|
||||
import { Storeable } from "./Storeable";
|
||||
|
||||
/**
|
||||
* Provides options for svg-icon sets.
|
||||
*/
|
||||
export interface SvgIconSetOptions extends IconSetOptions, Storeable {
|
||||
cumulative?: false;
|
||||
}
|
||||
9
types/webicon/Icon/Sizeable.d.ts
vendored
Normal file
9
types/webicon/Icon/Sizeable.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Represents a sizeable object.
|
||||
*/
|
||||
export interface Sizeable {
|
||||
/**
|
||||
* The default size of the icon.
|
||||
*/
|
||||
iconSize?: number;
|
||||
}
|
||||
16
types/webicon/Icon/SvgCumulativeIconSet.d.ts
vendored
Normal file
16
types/webicon/Icon/SvgCumulativeIconSet.d.ts
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { SvgIcon } from "./SvgIcon";
|
||||
|
||||
/**
|
||||
* Represents an svg icon-set which is loaded delayed.
|
||||
*/
|
||||
export interface SvgCumulativeIconSet extends SvgIcon {
|
||||
/**
|
||||
* A value indicating whether the icons are loaded separately.
|
||||
*/
|
||||
cumulative: true;
|
||||
|
||||
/**
|
||||
* The number of miliseconds to wait before downloading the icons.
|
||||
*/
|
||||
waitDuration?: number;
|
||||
}
|
||||
12
types/webicon/Icon/SvgIcon.d.ts
vendored
Normal file
12
types/webicon/Icon/SvgIcon.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ImageIcon } from "./ImageIcon";
|
||||
import { Sizeable } from "./Sizeable";
|
||||
|
||||
/**
|
||||
* Represents an svg-icon.
|
||||
*/
|
||||
export interface SvgIcon extends ImageIcon, Sizeable {
|
||||
/**
|
||||
* The default viewBox of the icon.
|
||||
*/
|
||||
viewBox?: string;
|
||||
}
|
||||
11
types/webicon/Icon/SvgIconSet.d.ts
vendored
Normal file
11
types/webicon/Icon/SvgIconSet.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { SvgIcon } from "./SvgIcon";
|
||||
|
||||
/**
|
||||
* Represents an svg icon-set.
|
||||
*/
|
||||
export interface SvgIconSet extends SvgIcon {
|
||||
/**
|
||||
* A value indicating whether the icons are loaded separately.
|
||||
*/
|
||||
cumulative?: false;
|
||||
}
|
||||
105
types/webicon/System/Config.d.ts
vendored
Normal file
105
types/webicon/System/Config.d.ts
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
import { SizeableOptions } from "../Icon/Options/SizeableOptions";
|
||||
import { CssClassConfig } from "../Icon/CssClassConfig";
|
||||
import { AliasOptions } from "../Icon/Options/AliasOptions";
|
||||
import { CssIconSetOptions } from "../Icon/Options/CssIconSetOptions";
|
||||
import { ImageIconOptions } from "../Icon/Options/ImageIconOptions";
|
||||
import { SvgCumulativeIconSetOptions } from "../Icon/Options/SvgCumulativeIconSetOptions";
|
||||
import { SvgIconOptions } from "../Icon/Options/SvgIconOptions";
|
||||
import { SvgIconSetOptions } from "../Icon/Options/SvgIconSetOptions";
|
||||
import { Identifiable } from "./Identifiable";
|
||||
import { IdentityMap } from "./IdentityMap";
|
||||
|
||||
/**
|
||||
* Provides settings for the `webicon`-module.
|
||||
*/
|
||||
export interface Config {
|
||||
/**
|
||||
* The icons to provide.
|
||||
*/
|
||||
icons?: IdentityMap<string, ImageIconOptions | SvgIconOptions>;
|
||||
|
||||
/**
|
||||
* An alias of the `icons`-property.
|
||||
*/
|
||||
icon?: this["icons"];
|
||||
|
||||
/**
|
||||
* The svg-sets to provide.
|
||||
*/
|
||||
svgSets?: IdentityMap<string, SvgIconSetOptions | SvgCumulativeIconSetOptions>;
|
||||
|
||||
/**
|
||||
* An alias of the `svgSets`-property.
|
||||
*/
|
||||
svgSet?: this["svgSets"];
|
||||
|
||||
/**
|
||||
* An alias of the `svgSets`-property.
|
||||
*/
|
||||
iconSet?: this["svgSets"];
|
||||
|
||||
/**
|
||||
* An alias of the `svgSets`-property.
|
||||
*/
|
||||
iconSets?: this["svgSets"];
|
||||
|
||||
/**
|
||||
* A set of icon-fonts to provide.
|
||||
*/
|
||||
fonts?: IdentityMap<CssClassConfig, CssIconSetOptions>;
|
||||
|
||||
/**
|
||||
* An alias of the `fonts`-property.
|
||||
*/
|
||||
font?: this["fonts"];
|
||||
|
||||
/**
|
||||
* A set of sprite-icons to provide.
|
||||
*/
|
||||
sprites?: IdentityMap<CssClassConfig, CssIconSetOptions>;
|
||||
|
||||
/**
|
||||
* An alias of the `sprites`-property.
|
||||
*/
|
||||
sprite?: this["sprites"];
|
||||
|
||||
/**
|
||||
* A set of alias-names for icon-sets.
|
||||
*/
|
||||
alias?: IdentityMap<string, AliasOptions>;
|
||||
|
||||
/**
|
||||
* An alias of the `alias`-property.
|
||||
*/
|
||||
sourceAlias?: this["alias"];
|
||||
|
||||
/**
|
||||
* The default icon-set to provide.
|
||||
*/
|
||||
defaultIconSetUrl?: string | (SvgIconSetOptions | SvgCumulativeIconSetOptions);
|
||||
|
||||
/**
|
||||
* An alias of the `defaultIconSetUrl`-property.
|
||||
*/
|
||||
defaultSvgSetUrl?: this["defaultIconSetUrl"];
|
||||
|
||||
/**
|
||||
* An alias of the `defaultIconSetUrl`-property.
|
||||
*/
|
||||
defaultSvgIconSetUrl?: this["defaultIconSetUrl"];
|
||||
|
||||
/**
|
||||
* The default icon-set to use.
|
||||
*/
|
||||
defaultSource?: string | Identifiable;
|
||||
|
||||
/**
|
||||
* An alias of the `defaultSource`-property.
|
||||
*/
|
||||
default?: this["defaultSource"];
|
||||
|
||||
/**
|
||||
* The default size for svg-icons.
|
||||
*/
|
||||
defaultSvgIconSize?: number | SizeableOptions;
|
||||
}
|
||||
14
types/webicon/System/ConfigurationHandler.d.ts
vendored
Normal file
14
types/webicon/System/ConfigurationHandler.d.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { PublicApi } from "./PublicApi";
|
||||
|
||||
/**
|
||||
* Provides the functionality to handle the `configuration`-event.
|
||||
*/
|
||||
export interface ConfigurationHandler {
|
||||
/**
|
||||
* Handles the `configuration`-event.
|
||||
*
|
||||
* @param api
|
||||
* The configuration-api.
|
||||
*/
|
||||
(api: PublicApi): void;
|
||||
}
|
||||
8
types/webicon/System/IconLoadedEventHandler.d.ts
vendored
Normal file
8
types/webicon/System/IconLoadedEventHandler.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { IconPreloader } from "./IconPreloader";
|
||||
|
||||
/**
|
||||
* Provides the functionality to handle the `preloaded`-event.
|
||||
*/
|
||||
export interface IconLoadedEventHandler {
|
||||
(preloader: IconPreloader): any;
|
||||
}
|
||||
9
types/webicon/System/IconPreloader.d.ts
vendored
Normal file
9
types/webicon/System/IconPreloader.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Represents an icon-preloader.
|
||||
*/
|
||||
export interface IconPreloader extends Promise<void> {
|
||||
/**
|
||||
* The names of the icons to download.
|
||||
*/
|
||||
iconSets: string[];
|
||||
}
|
||||
9
types/webicon/System/Identifiable.d.ts
vendored
Normal file
9
types/webicon/System/Identifiable.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Represents an identifiable object.
|
||||
*/
|
||||
export interface Identifiable {
|
||||
/**
|
||||
* The id of the object.
|
||||
*/
|
||||
id: string;
|
||||
}
|
||||
6
types/webicon/System/IdentityMap.d.ts
vendored
Normal file
6
types/webicon/System/IdentityMap.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Identifiable } from "./Identifiable";
|
||||
|
||||
/**
|
||||
* Represents a map of identifiable objects.
|
||||
*/
|
||||
export type IdentityMap<TSimple, TComplex> = Array<Identifiable & TComplex> | { [id: string]: TSimple | TComplex };
|
||||
20
types/webicon/System/Injector.d.ts
vendored
Normal file
20
types/webicon/System/Injector.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Provides the functionality to require components of the `webicon`-module.
|
||||
*/
|
||||
export interface Injector {
|
||||
/**
|
||||
* Requires a component of the `webicon`-module.
|
||||
*/
|
||||
<T>(name: string, injector: Injector): T;
|
||||
|
||||
/**
|
||||
* Checks whether a component with the specified `name` exists.
|
||||
*
|
||||
* @param name
|
||||
* The name of the component to check for existence.
|
||||
*
|
||||
* @return
|
||||
* A value indicating whether a component with the specified `name` exists.
|
||||
*/
|
||||
has(name: string): boolean;
|
||||
}
|
||||
174
types/webicon/System/PublicApi.d.ts
vendored
Normal file
174
types/webicon/System/PublicApi.d.ts
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
import { CssClassConfig } from "../Icon/CssClassConfig";
|
||||
import { CssIconSet } from "../Icon/CssIconSet";
|
||||
import { ImageIcon } from "../Icon/ImageIcon";
|
||||
import { SvgCumulativeIconSet } from "../Icon/SvgCumulativeIconSet";
|
||||
import { SvgIcon } from "../Icon/SvgIcon";
|
||||
import { SvgIconSet } from "../Icon/SvgIconSet";
|
||||
import { UrlConfig } from "../Web/UrlConfig";
|
||||
import { IconLoadedEventHandler } from "./IconLoadedEventHandler";
|
||||
import { Injector } from "./Injector";
|
||||
|
||||
/**
|
||||
* An object for configuring the `webicon`-module.
|
||||
*/
|
||||
export interface PublicApi {
|
||||
/**
|
||||
* Adds a new icon.
|
||||
*
|
||||
* @param id
|
||||
* The id of the icon to add.
|
||||
*
|
||||
* @param urlConfig
|
||||
* The url to download the icon from.
|
||||
*
|
||||
* @param options
|
||||
* Additional options for the icon.
|
||||
*/
|
||||
icon(id: string, urlConfig: UrlConfig<undefined>, options?: ImageIcon | SvgIcon): this;
|
||||
|
||||
/**
|
||||
* Adds an icon-set.
|
||||
*
|
||||
* @param id
|
||||
* The id of the icon-set to add.
|
||||
*
|
||||
* @param urlConfig
|
||||
* The url to download the icon-set from.
|
||||
*
|
||||
* @param options
|
||||
* Additional options for the icon-set.
|
||||
*/
|
||||
svgSet(id: string, urlConfig: UrlConfig<undefined>, options?: SvgIconSet): this;
|
||||
|
||||
/**
|
||||
* Adds an icon-set.
|
||||
*
|
||||
* @param id
|
||||
* The id of the icon-set to add.
|
||||
*
|
||||
* @param urlConfig
|
||||
* The url to download the icon-set from.
|
||||
*
|
||||
* @param options
|
||||
* Additional options for the icon-set.
|
||||
*/
|
||||
svgSet(id: string, urlConfig: UrlConfig<string[]>, options?: SvgCumulativeIconSet): this;
|
||||
|
||||
/**
|
||||
* An alias of the `svgSet`-method.
|
||||
*/
|
||||
iconSet: this["svgSet"];
|
||||
|
||||
/**
|
||||
* Adds a font icon-set.
|
||||
*
|
||||
* @param id
|
||||
* The id of the icon-set to add.
|
||||
*
|
||||
* @param cssClassConfig
|
||||
* The css-class to add to icons.
|
||||
*
|
||||
* @param options
|
||||
* Additional options for the icon-set.
|
||||
*/
|
||||
font(id: string, cssClassConfig: CssClassConfig, options?: CssIconSet): this;
|
||||
|
||||
/**
|
||||
* Adds a sprite icon-set.
|
||||
*
|
||||
* @param id
|
||||
* The id of the icon-set to add.
|
||||
*
|
||||
* @param cssClassConfig
|
||||
* The css-class to add to icons.
|
||||
*
|
||||
* @param options
|
||||
* Additional options for the icon-set.
|
||||
*/
|
||||
sprite(id: string, cssClassConfig: CssClassConfig, options?: CssIconSet): this;
|
||||
|
||||
/**
|
||||
* Adds a link to the `alias` icon-set.
|
||||
*
|
||||
* @param id
|
||||
* The id which links to the `alias`.
|
||||
*
|
||||
* @param alias
|
||||
* The id of the icon-set to refer to.
|
||||
*/
|
||||
alias(id: string, alias: string): this;
|
||||
|
||||
/**
|
||||
* An alias of the `alias`-method.
|
||||
*/
|
||||
sourceAlias: this["alias"];
|
||||
|
||||
/**
|
||||
* Adds a default svg-set.
|
||||
*
|
||||
* @param url
|
||||
* The url to the default svg-set to use.
|
||||
*
|
||||
* @param options
|
||||
* Additional options for the svg-set.
|
||||
*/
|
||||
defaultIconSetUrl(url: string, options?: SvgIconSet | SvgCumulativeIconSet): this;
|
||||
|
||||
/**
|
||||
* An alias of the `defaultSvgSetUrl`-method.
|
||||
*/
|
||||
defaultSvgSetUrl: this["defaultIconSetUrl"];
|
||||
|
||||
/**
|
||||
* An alias of the `defaultSvgSetUrl`-method.
|
||||
*/
|
||||
defaultSvgIconSetUrl: this["defaultIconSetUrl"];
|
||||
|
||||
/**
|
||||
* Sets a default icon-set.
|
||||
*
|
||||
* @param id
|
||||
* The id of the default icon-set.
|
||||
*/
|
||||
defaultSource(id: string): this;
|
||||
|
||||
/**
|
||||
* An alias of the `defaultSource`-method.
|
||||
*/
|
||||
default: this["defaultSource"];
|
||||
|
||||
/**
|
||||
* Sets the default icon-size for svg-icons.
|
||||
*
|
||||
* @param size
|
||||
* The default svg icon-size.
|
||||
*/
|
||||
defaultSvgIconSize(size: number): this;
|
||||
|
||||
/**
|
||||
* Preloads the icons.
|
||||
*
|
||||
* @param eventHandler
|
||||
* A callback for handling the icon-loader `Promise`.
|
||||
*/
|
||||
preload(eventHandler?: IconLoadedEventHandler): this;
|
||||
|
||||
/**
|
||||
* Preloads the icons.
|
||||
*
|
||||
* @param names
|
||||
* Either a value indicating whether to preload all icons or the names of the icons to preload.
|
||||
*
|
||||
* @param eventHandler
|
||||
* A callback for handling the icon-loader `Promise`.
|
||||
*/
|
||||
preload(names: string | string[] | boolean, eventHandler?: IconLoadedEventHandler): this;
|
||||
|
||||
/**
|
||||
* Adds an event-handler to the `ready`-event.
|
||||
*
|
||||
* @param eventHandler
|
||||
* THe event-handler for handling the `ready`-event.
|
||||
*/
|
||||
ready(eventHandler: (injector: Injector) => void): this;
|
||||
}
|
||||
12
types/webicon/Web/DynamicUrlDeclaration.d.ts
vendored
Normal file
12
types/webicon/Web/DynamicUrlDeclaration.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { StaticUrlDeclaration } from "./StaticUrlDeclaration";
|
||||
import { UrlDeclarationBase } from "./UrlDeclarationBase";
|
||||
|
||||
/**
|
||||
* Represents a dynamically generated url.
|
||||
*/
|
||||
export interface DynamicUrlDeclaration<T = undefined> extends UrlDeclarationBase {
|
||||
/**
|
||||
* Either the actual url or a function for generating the url.
|
||||
*/
|
||||
url?: string | ((args: T) => string | StaticUrlDeclaration);
|
||||
}
|
||||
8
types/webicon/Web/StaticUrlDeclaration.d.ts
vendored
Normal file
8
types/webicon/Web/StaticUrlDeclaration.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { UrlDeclarationBase } from "./UrlDeclarationBase";
|
||||
|
||||
/**
|
||||
* Represents a static url.
|
||||
*/
|
||||
export interface StaticUrlDeclaration extends UrlDeclarationBase {
|
||||
url?: string;
|
||||
}
|
||||
6
types/webicon/Web/UrlConfig.d.ts
vendored
Normal file
6
types/webicon/Web/UrlConfig.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { DynamicUrlDeclaration } from "./DynamicUrlDeclaration";
|
||||
|
||||
/**
|
||||
* Represents a url.
|
||||
*/
|
||||
export type UrlConfig<T = never> = string | DynamicUrlDeclaration<T>;
|
||||
14
types/webicon/Web/UrlDeclarationBase.d.ts
vendored
Normal file
14
types/webicon/Web/UrlDeclarationBase.d.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Represents an url.
|
||||
*/
|
||||
export interface UrlDeclarationBase {
|
||||
/**
|
||||
* The `GET`-variables of the url.
|
||||
*/
|
||||
params?: any;
|
||||
|
||||
/**
|
||||
* The actual url.
|
||||
*/
|
||||
url?: any;
|
||||
}
|
||||
67
types/webicon/index.d.ts
vendored
Normal file
67
types/webicon/index.d.ts
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
// Type definitions for webicon 0.10
|
||||
// Project: https://icons8.github.io/webicon/
|
||||
// Definitions by: Manuel Thalmann <https://github.com/manuth>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import { CssClassConfig } from "./Icon/CssClassConfig";
|
||||
import { CssIconSet } from "./Icon/CssIconSet";
|
||||
import { IconClassGenerator } from "./Icon/IconClassGenerator";
|
||||
import { ImageIcon } from "./Icon/ImageIcon";
|
||||
import { AliasOptions } from "./Icon/Options/AliasOptions";
|
||||
import { CssIconSetOptions } from "./Icon/Options/CssIconSetOptions";
|
||||
import { ImageIconOptions } from "./Icon/Options/ImageIconOptions";
|
||||
import { SvgCumulativeIconSetOptions } from "./Icon/Options/SvgCumulativeIconSetOptions";
|
||||
import { SvgIconOptions } from "./Icon/Options/SvgIconOptions";
|
||||
import { SvgIconSetOptions } from "./Icon/Options/SvgIconSetOptions";
|
||||
import { SvgCumulativeIconSet } from "./Icon/SvgCumulativeIconSet";
|
||||
import { SvgIcon } from "./Icon/SvgIcon";
|
||||
import { SvgIconSet } from "./Icon/SvgIconSet";
|
||||
import { Config } from "./System/Config";
|
||||
import { ConfigurationHandler } from "./System/ConfigurationHandler";
|
||||
import { IconLoadedEventHandler } from "./System/IconLoadedEventHandler";
|
||||
import { IconPreloader } from "./System/IconPreloader";
|
||||
import { Identifiable } from "./System/Identifiable";
|
||||
import { Injector } from "./System/Injector";
|
||||
import { PublicApi } from "./System/PublicApi";
|
||||
import { DynamicUrlDeclaration } from "./Web/DynamicUrlDeclaration";
|
||||
import { StaticUrlDeclaration } from "./Web/StaticUrlDeclaration";
|
||||
import { UrlConfig } from "./Web/UrlConfig";
|
||||
|
||||
export {
|
||||
CssClassConfig,
|
||||
CssIconSet,
|
||||
IconClassGenerator,
|
||||
ImageIcon,
|
||||
AliasOptions,
|
||||
CssIconSetOptions,
|
||||
ImageIconOptions,
|
||||
SvgCumulativeIconSetOptions,
|
||||
SvgIconOptions,
|
||||
SvgIconSetOptions,
|
||||
SvgCumulativeIconSet,
|
||||
SvgIcon,
|
||||
SvgIconSet,
|
||||
Config,
|
||||
ConfigurationHandler,
|
||||
IconLoadedEventHandler,
|
||||
IconPreloader,
|
||||
Identifiable,
|
||||
Injector,
|
||||
PublicApi,
|
||||
DynamicUrlDeclaration,
|
||||
StaticUrlDeclaration,
|
||||
UrlConfig
|
||||
};
|
||||
|
||||
declare global {
|
||||
interface JQuery<TElement = HTMLElement> {
|
||||
/**
|
||||
* Initializes the web-icons.
|
||||
*
|
||||
* @param config
|
||||
* Either the configuration for initializing web-icons or a callback for configuring the web-icons.
|
||||
*/
|
||||
webicons(config: Config | ConfigurationHandler): this;
|
||||
}
|
||||
}
|
||||
24
types/webicon/tsconfig.json
Normal file
24
types/webicon/tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"webicon-tests.ts"
|
||||
]
|
||||
}
|
||||
7
types/webicon/tslint.json
Normal file
7
types/webicon/tslint.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false,
|
||||
"no-empty-interface": false
|
||||
}
|
||||
}
|
||||
471
types/webicon/webicon-tests.ts
Normal file
471
types/webicon/webicon-tests.ts
Normal file
@@ -0,0 +1,471 @@
|
||||
import "jquery";
|
||||
import {
|
||||
Config,
|
||||
ImageIconOptions,
|
||||
SvgIconOptions,
|
||||
Identifiable,
|
||||
SvgIconSetOptions,
|
||||
SvgCumulativeIconSetOptions,
|
||||
CssIconSetOptions,
|
||||
ImageIcon,
|
||||
DynamicUrlDeclaration,
|
||||
SvgIconSet,
|
||||
SvgCumulativeIconSet,
|
||||
CssIconSet
|
||||
} from "webicon";
|
||||
|
||||
/**
|
||||
* Provides tests for the `webicon`-module.
|
||||
*/
|
||||
export class WebiconTests {
|
||||
getUrlObject<TUriParam = undefined>(): DynamicUrlDeclaration<TUriParam> {
|
||||
const result: DynamicUrlDeclaration<TUriParam> = {
|
||||
url: "",
|
||||
params: {}
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
getStringUrlCallback<TUriParam = undefined>(): DynamicUrlDeclaration<TUriParam> {
|
||||
const result: DynamicUrlDeclaration<TUriParam> = {
|
||||
url: (arg) => {
|
||||
// $ExpectType TUriParam
|
||||
arg;
|
||||
return "";
|
||||
},
|
||||
params: {}
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
getObjectUrlCallback<TUriParam = undefined>(): DynamicUrlDeclaration<TUriParam> {
|
||||
const result: DynamicUrlDeclaration<TUriParam> = {
|
||||
url: (arg) => {
|
||||
// $ExpectType TUriParam
|
||||
arg;
|
||||
return {
|
||||
url: "",
|
||||
params: {}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the `webicon`-module.
|
||||
*/
|
||||
Test() {
|
||||
const config: Config = {};
|
||||
const IDParser: ImageIconOptions["iconIdParser"] = (id, params) => {
|
||||
// $ExpectType string
|
||||
id;
|
||||
// $ExpectType string[]
|
||||
params;
|
||||
return "";
|
||||
};
|
||||
|
||||
const IDResolver: ImageIconOptions["iconIdResolver"] = (id) => {
|
||||
// $ExpectType string
|
||||
id;
|
||||
return "";
|
||||
};
|
||||
|
||||
const ClassResolver: CssIconSetOptions["className"] = (id, params) => {
|
||||
// $ExpectType string
|
||||
id;
|
||||
// $ExpectType string[]
|
||||
params;
|
||||
return "";
|
||||
};
|
||||
|
||||
const icon: ImageIcon = {
|
||||
iconIdParser: IDParser
|
||||
};
|
||||
|
||||
const set: SvgIconSet = {
|
||||
cumulative: false,
|
||||
iconIdParser: IDParser,
|
||||
iconSize: 1,
|
||||
viewBox: ""
|
||||
};
|
||||
|
||||
const cumulativeSet: SvgCumulativeIconSet = {
|
||||
cumulative: true,
|
||||
iconIdParser: IDParser,
|
||||
iconSize: 1,
|
||||
viewBox: "",
|
||||
waitDuration: 1
|
||||
};
|
||||
|
||||
const cssIconSet: CssIconSet = {
|
||||
iconIdParser: IDParser
|
||||
};
|
||||
|
||||
const iconOptions: SvgIconOptions = {
|
||||
iconIdParser: IDParser,
|
||||
iconIdResolver: IDResolver,
|
||||
iconSize: 1,
|
||||
svgIconSize: 1,
|
||||
preloadable: true,
|
||||
size: 1,
|
||||
url: "",
|
||||
uri: "",
|
||||
viewBox: ""
|
||||
};
|
||||
|
||||
const idIconOptions: Identifiable & SvgIconOptions = {
|
||||
id: "clock",
|
||||
iconIdParser: IDParser,
|
||||
iconIdResolver: IDResolver,
|
||||
iconSize: 1,
|
||||
svgIconSize: 1,
|
||||
preloadable: true,
|
||||
size: 1,
|
||||
url: "",
|
||||
uri: "",
|
||||
viewBox: ""
|
||||
};
|
||||
|
||||
const setOptions: SvgIconSetOptions = {
|
||||
cumulative: false,
|
||||
iconIdParser: IDParser,
|
||||
iconIdResolver: IDResolver,
|
||||
iconSize: 1,
|
||||
preloadable: true,
|
||||
size: 1,
|
||||
svgIconSize: 1,
|
||||
uri: "",
|
||||
url: "",
|
||||
viewBox: ""
|
||||
};
|
||||
|
||||
const cumulativeSetOptions: SvgCumulativeIconSetOptions = {
|
||||
cumulative: true,
|
||||
iconIdParser: IDParser,
|
||||
iconSize: 1,
|
||||
size: 1,
|
||||
svgIconSize: 1,
|
||||
uri: "",
|
||||
url: "",
|
||||
viewBox: "",
|
||||
waitDuration: 0
|
||||
};
|
||||
|
||||
const idSetOptions: Identifiable & SvgIconSetOptions = {
|
||||
id: "",
|
||||
cumulative: false,
|
||||
iconIdParser: IDParser,
|
||||
iconIdResolver: IDResolver,
|
||||
iconSize: 1,
|
||||
preloadable: true,
|
||||
size: 1,
|
||||
svgIconSize: 1,
|
||||
uri: "",
|
||||
url: "",
|
||||
viewBox: ""
|
||||
};
|
||||
|
||||
const cssIconSetOptions: CssIconSetOptions = {
|
||||
class: "",
|
||||
className: "",
|
||||
cssClass: "",
|
||||
iconIdParser: IDParser
|
||||
};
|
||||
|
||||
const idCssIconOptions: Identifiable & CssIconSetOptions = {
|
||||
id: "",
|
||||
class: "",
|
||||
className: "",
|
||||
cssClass: "",
|
||||
iconIdParser: IDParser
|
||||
};
|
||||
|
||||
/**
|
||||
* Configuring `webicon` using a configuration-handler.
|
||||
*/
|
||||
$().webicons(
|
||||
(config) => {
|
||||
// $ExpectType PublicApi
|
||||
config;
|
||||
config.icon("", "", icon);
|
||||
config.icon("", this.getUrlObject(), icon);
|
||||
config.icon("", this.getStringUrlCallback(), icon);
|
||||
config.icon("", this.getObjectUrlCallback(), icon);
|
||||
|
||||
config.svgSet("", "");
|
||||
config.svgSet("", "", set);
|
||||
config.svgSet("", "", cumulativeSet);
|
||||
config.svgSet("", this.getUrlObject());
|
||||
config.svgSet("", this.getUrlObject(), set);
|
||||
config.svgSet("", this.getUrlObject<string[]>(), cumulativeSet);
|
||||
config.svgSet("", this.getStringUrlCallback());
|
||||
config.svgSet("", this.getStringUrlCallback(), set);
|
||||
config.svgSet("", this.getStringUrlCallback<string[]>(), cumulativeSet);
|
||||
config.svgSet("", this.getObjectUrlCallback());
|
||||
config.svgSet("", this.getObjectUrlCallback(), set);
|
||||
config.svgSet("", this.getObjectUrlCallback<string[]>(), cumulativeSet);
|
||||
config.iconSet("", "");
|
||||
config.iconSet("", "", set);
|
||||
config.iconSet("", "", cumulativeSet);
|
||||
config.iconSet("", this.getUrlObject());
|
||||
config.iconSet("", this.getUrlObject(), set);
|
||||
config.iconSet("", this.getUrlObject<string[]>(), cumulativeSet);
|
||||
config.iconSet("", this.getStringUrlCallback());
|
||||
config.iconSet("", this.getStringUrlCallback(), set);
|
||||
config.iconSet("", this.getStringUrlCallback<string[]>(), cumulativeSet);
|
||||
config.iconSet("", this.getObjectUrlCallback());
|
||||
config.iconSet("", this.getObjectUrlCallback(), set);
|
||||
config.iconSet("", this.getObjectUrlCallback<string[]>(), cumulativeSet);
|
||||
|
||||
config.font("", "", cssIconSet);
|
||||
config.font("", ClassResolver, cssIconSet);
|
||||
|
||||
config.sprite("", "", cssIconSet);
|
||||
config.sprite("", ClassResolver, cssIconSet);
|
||||
|
||||
config.alias("", "");
|
||||
config.sourceAlias("", "");
|
||||
|
||||
config.defaultIconSetUrl("");
|
||||
config.defaultIconSetUrl("", set);
|
||||
config.defaultSvgSetUrl("");
|
||||
config.defaultSvgSetUrl("", set);
|
||||
config.defaultSvgIconSetUrl("");
|
||||
config.defaultSvgIconSetUrl("", set);
|
||||
|
||||
config.defaultSource("");
|
||||
config.default("");
|
||||
|
||||
config.defaultSvgIconSize(1);
|
||||
|
||||
config.preload(
|
||||
(loader) => {
|
||||
// $ExpectType IconPreloader
|
||||
loader;
|
||||
});
|
||||
|
||||
config.ready(
|
||||
(injector) => {
|
||||
// $ExpectType Injector
|
||||
injector;
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Declaring urls
|
||||
* Using a string
|
||||
*/
|
||||
setOptions.url =
|
||||
setOptions.uri =
|
||||
iconOptions.url =
|
||||
iconOptions.uri = "";
|
||||
|
||||
/**
|
||||
* Using an object
|
||||
*/
|
||||
setOptions.url =
|
||||
setOptions.uri =
|
||||
iconOptions.url =
|
||||
iconOptions.uri = this.getUrlObject();
|
||||
|
||||
/**
|
||||
* Using a function
|
||||
* Returning a string
|
||||
*/
|
||||
setOptions.url =
|
||||
setOptions.uri =
|
||||
iconOptions.url =
|
||||
iconOptions.uri = this.getStringUrlCallback();
|
||||
|
||||
/**
|
||||
* Returning an object
|
||||
*/
|
||||
setOptions.url =
|
||||
setOptions.uri =
|
||||
iconOptions.url =
|
||||
iconOptions.uri = this.getObjectUrlCallback();
|
||||
|
||||
/**
|
||||
* Declaring class-resolvers
|
||||
* Using a string
|
||||
*/
|
||||
cssIconSetOptions.className =
|
||||
cssIconSetOptions.cssClass =
|
||||
cssIconSetOptions.class = "";
|
||||
|
||||
/**
|
||||
* Using a function
|
||||
*/
|
||||
cssIconSetOptions.className =
|
||||
cssIconSetOptions.cssClass =
|
||||
cssIconSetOptions.class = ClassResolver;
|
||||
|
||||
/**
|
||||
* Setting icons
|
||||
* Simple
|
||||
*/
|
||||
config.icons =
|
||||
config.icon = {
|
||||
clock: ""
|
||||
};
|
||||
|
||||
/**
|
||||
* Complex
|
||||
*/
|
||||
config.icons =
|
||||
config.icon = {
|
||||
clock: iconOptions
|
||||
};
|
||||
|
||||
/**
|
||||
* Array
|
||||
*/
|
||||
config.icons =
|
||||
config.icon = [
|
||||
idIconOptions
|
||||
];
|
||||
|
||||
/**
|
||||
* Setting svg-sets
|
||||
* Simple
|
||||
*/
|
||||
config.svgSets =
|
||||
config.svgSet =
|
||||
config.iconSets =
|
||||
config.iconSet = {
|
||||
clock: ""
|
||||
};
|
||||
|
||||
/**
|
||||
* Complex
|
||||
*/
|
||||
config.svgSets =
|
||||
config.svgSet =
|
||||
config.iconSets =
|
||||
config.iconSet = {
|
||||
clock: setOptions,
|
||||
alt: cumulativeSetOptions
|
||||
};
|
||||
|
||||
/**
|
||||
* Array
|
||||
*/
|
||||
config.svgSets =
|
||||
config.svgSet =
|
||||
config.iconSets =
|
||||
config.iconSet = [
|
||||
idSetOptions
|
||||
];
|
||||
|
||||
/**
|
||||
* Setting css-class icons
|
||||
* Simple
|
||||
*/
|
||||
config.fonts =
|
||||
config.font =
|
||||
config.sprites =
|
||||
config.sprite = {
|
||||
clock: ""
|
||||
};
|
||||
|
||||
/**
|
||||
* Complex
|
||||
*/
|
||||
config.fonts =
|
||||
config.font =
|
||||
config.sprites =
|
||||
config.sprite = {
|
||||
clock: cssIconSetOptions
|
||||
};
|
||||
|
||||
/**
|
||||
* Array
|
||||
*/
|
||||
config.fonts =
|
||||
config.font =
|
||||
config.sprites =
|
||||
config.sprite = [
|
||||
idCssIconOptions
|
||||
];
|
||||
|
||||
/**
|
||||
* Setting aliases
|
||||
* Simple
|
||||
*/
|
||||
config.alias =
|
||||
config.sourceAlias = {
|
||||
alt: "clock"
|
||||
};
|
||||
|
||||
/**
|
||||
* Complex
|
||||
*/
|
||||
config.alias =
|
||||
config.sourceAlias = {
|
||||
id: {
|
||||
alias: ""
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Array
|
||||
*/
|
||||
config.alias =
|
||||
config.sourceAlias = [
|
||||
{
|
||||
id: "id",
|
||||
alias: ""
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* Setting a default icon-set url
|
||||
* Simple
|
||||
*/
|
||||
config.defaultIconSetUrl =
|
||||
config.defaultSvgSetUrl =
|
||||
config.defaultSvgIconSetUrl = "";
|
||||
|
||||
/**
|
||||
* Complex
|
||||
*/
|
||||
config.defaultIconSetUrl =
|
||||
config.defaultSvgSetUrl =
|
||||
config.defaultSvgIconSetUrl = setOptions;
|
||||
|
||||
/**
|
||||
* Setting a default icon-set
|
||||
* Simple
|
||||
*/
|
||||
config.defaultSource =
|
||||
config.default = "";
|
||||
|
||||
/**
|
||||
* Complex
|
||||
*/
|
||||
config.defaultSource =
|
||||
config.default = {
|
||||
id: ""
|
||||
};
|
||||
|
||||
/**
|
||||
* Setting a default icon-size for vector-icons
|
||||
* Simple
|
||||
*/
|
||||
config.defaultSvgIconSize = 1;
|
||||
|
||||
/**
|
||||
* Complex
|
||||
*/
|
||||
config.defaultSvgIconSize = {
|
||||
iconSize: 1,
|
||||
size: 1,
|
||||
svgIconSize: 1
|
||||
};
|
||||
|
||||
$().webicons(config);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user