From 4209de6eec1cf45e9cb0543e103e06994f0ef167 Mon Sep 17 00:00:00 2001 From: FlorianWoelki Date: Sun, 7 Jul 2024 11:03:22 +0200 Subject: [PATCH] feat(api): add more exposed functions for the api --- src/icon-pack-manager.ts | 6 +++++ src/lib/api.ts | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/icon-pack-manager.ts b/src/icon-pack-manager.ts index 50c976b3..d47b33da 100644 --- a/src/icon-pack-manager.ts +++ b/src/icon-pack-manager.ts @@ -623,6 +623,12 @@ export const doesIconExists = (iconName: string): boolean => { ); }; +export const getIconsFromIconPack = ( + iconPackName: string, +): IconPack | undefined => { + return iconPacks.find((iconPack) => iconPack.name === iconPackName); +}; + export const getIconFromIconPack = ( iconPackName: string, iconPrefix: string, diff --git a/src/lib/api.ts b/src/lib/api.ts index c2e6bec8..62ad698e 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -1,8 +1,44 @@ import IconizePlugin from '@app/main'; +import dom from '@lib/util/dom'; +import svg from '@lib/util/svg'; +import icon from '@lib/icon'; +import { EventEmitter } from './event/event'; +import { removeIconFromIconPack, saveIconToIconPack } from '@app/util'; +import { getAllIconPacks, getIconsFromIconPack } from '@app/icon-pack-manager'; export { AllIconsLoadedEvent } from '@lib/event/events'; export default interface IconizeAPI { + getEventEmitter(): EventEmitter; + getIconByName: typeof icon.getIconByName; + /** + * Sets an icon or emoji for an HTMLElement based on the specified icon name and color. + * The function manipulates the specified node inline. + * @param iconName Name of the icon or emoji to add. + * @param node HTMLElement to which the icon or emoji will be added. + * @param color Optional color of the icon to add. + */ + setIconForNode(iconName: string, node: HTMLElement, color?: string): void; + doesElementHasIconNode: typeof dom.doesElementHasIconNode; + getIconFromElement: typeof dom.getIconFromElement; + removeIconInNode: typeof dom.removeIconInNode; + removeIconInPath: typeof dom.removeIconInPath; + /** + * Will add the icon to the icon pack and then extract the icon to the icon pack. + * @param iconNameWithPrefix String that will be used to add the icon to the icon pack. + */ + saveIconToIconPack(iconNameWithPrefix: string): void; + /** + * Will remove the icon from the icon pack by removing the icon file from the icon pack directory. + * @param iconNameWithPrefix String that will be used to remove the icon from the icon pack. + */ + removeIconFromIconPack(iconNameWithPrefix: string): void; + getAllIconPacks: typeof getAllIconPacks; + getIconsFromIconPack: typeof getIconsFromIconPack; + util: { + dom: typeof dom; + svg: typeof svg; + }; version: { current: string; }; @@ -10,6 +46,25 @@ export default interface IconizeAPI { export function getApi(plugin: IconizePlugin): IconizeAPI { return { + getEventEmitter: () => plugin.getEventEmitter(), + getIconByName: (iconNameWithPrefix: string) => + icon.getIconByName(iconNameWithPrefix), + setIconForNode: (iconName: string, node: HTMLElement, color?: string) => + dom.setIconForNode(plugin, iconName, node, color), + saveIconToIconPack: (iconNameWithPrefix) => + saveIconToIconPack(plugin, iconNameWithPrefix), + removeIconFromIconPack: (iconNameWithPrefix) => + removeIconFromIconPack(plugin, iconNameWithPrefix), + getIconsFromIconPack: getIconsFromIconPack, + getAllIconPacks: getAllIconPacks, + doesElementHasIconNode: dom.doesElementHasIconNode, + getIconFromElement: dom.getIconFromElement, + removeIconInNode: dom.removeIconInNode, + removeIconInPath: dom.removeIconInPath, + util: { + dom, + svg, + }, version: { get current() { return plugin.manifest.version;