Skip to content

Commit 4209de6

Browse files
committed
feat(api): add more exposed functions for the api
1 parent db06926 commit 4209de6

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/icon-pack-manager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,12 @@ export const doesIconExists = (iconName: string): boolean => {
623623
);
624624
};
625625

626+
export const getIconsFromIconPack = (
627+
iconPackName: string,
628+
): IconPack | undefined => {
629+
return iconPacks.find((iconPack) => iconPack.name === iconPackName);
630+
};
631+
626632
export const getIconFromIconPack = (
627633
iconPackName: string,
628634
iconPrefix: string,

src/lib/api.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,70 @@
11
import IconizePlugin from '@app/main';
2+
import dom from '@lib/util/dom';
3+
import svg from '@lib/util/svg';
4+
import icon from '@lib/icon';
5+
import { EventEmitter } from './event/event';
6+
import { removeIconFromIconPack, saveIconToIconPack } from '@app/util';
7+
import { getAllIconPacks, getIconsFromIconPack } from '@app/icon-pack-manager';
28

39
export { AllIconsLoadedEvent } from '@lib/event/events';
410

511
export default interface IconizeAPI {
12+
getEventEmitter(): EventEmitter;
13+
getIconByName: typeof icon.getIconByName;
14+
/**
15+
* Sets an icon or emoji for an HTMLElement based on the specified icon name and color.
16+
* The function manipulates the specified node inline.
17+
* @param iconName Name of the icon or emoji to add.
18+
* @param node HTMLElement to which the icon or emoji will be added.
19+
* @param color Optional color of the icon to add.
20+
*/
21+
setIconForNode(iconName: string, node: HTMLElement, color?: string): void;
22+
doesElementHasIconNode: typeof dom.doesElementHasIconNode;
23+
getIconFromElement: typeof dom.getIconFromElement;
24+
removeIconInNode: typeof dom.removeIconInNode;
25+
removeIconInPath: typeof dom.removeIconInPath;
26+
/**
27+
* Will add the icon to the icon pack and then extract the icon to the icon pack.
28+
* @param iconNameWithPrefix String that will be used to add the icon to the icon pack.
29+
*/
30+
saveIconToIconPack(iconNameWithPrefix: string): void;
31+
/**
32+
* Will remove the icon from the icon pack by removing the icon file from the icon pack directory.
33+
* @param iconNameWithPrefix String that will be used to remove the icon from the icon pack.
34+
*/
35+
removeIconFromIconPack(iconNameWithPrefix: string): void;
36+
getAllIconPacks: typeof getAllIconPacks;
37+
getIconsFromIconPack: typeof getIconsFromIconPack;
38+
util: {
39+
dom: typeof dom;
40+
svg: typeof svg;
41+
};
642
version: {
743
current: string;
844
};
945
}
1046

1147
export function getApi(plugin: IconizePlugin): IconizeAPI {
1248
return {
49+
getEventEmitter: () => plugin.getEventEmitter(),
50+
getIconByName: (iconNameWithPrefix: string) =>
51+
icon.getIconByName(iconNameWithPrefix),
52+
setIconForNode: (iconName: string, node: HTMLElement, color?: string) =>
53+
dom.setIconForNode(plugin, iconName, node, color),
54+
saveIconToIconPack: (iconNameWithPrefix) =>
55+
saveIconToIconPack(plugin, iconNameWithPrefix),
56+
removeIconFromIconPack: (iconNameWithPrefix) =>
57+
removeIconFromIconPack(plugin, iconNameWithPrefix),
58+
getIconsFromIconPack: getIconsFromIconPack,
59+
getAllIconPacks: getAllIconPacks,
60+
doesElementHasIconNode: dom.doesElementHasIconNode,
61+
getIconFromElement: dom.getIconFromElement,
62+
removeIconInNode: dom.removeIconInNode,
63+
removeIconInPath: dom.removeIconInPath,
64+
util: {
65+
dom,
66+
svg,
67+
},
1368
version: {
1469
get current() {
1570
return plugin.manifest.version;

0 commit comments

Comments
 (0)