mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 23:39:50 +02:00
chore: Align export syntax
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import type { Selection } from 'd3-selection';
|
||||
|
||||
type IconResolver = (
|
||||
export type IconResolver = (
|
||||
parent: Selection<SVGGElement, unknown, Element | null, unknown>,
|
||||
width?: number
|
||||
) => Selection<SVGGElement, unknown, Element | null, unknown>;
|
||||
type IconLibrary = Record<string, IconResolver>;
|
||||
export type IconLibrary = Record<string, IconResolver>;
|
||||
|
||||
/**
|
||||
* Converts an SVG Icon passed as a string into a properly formatted IconResolver
|
||||
@@ -12,7 +12,10 @@ type IconLibrary = Record<string, IconResolver>;
|
||||
* @param originalSize - the original size of the SVG Icon in pixels
|
||||
* @returns IconResolver
|
||||
*/
|
||||
const createIcon: (icon: string, originalSize: number) => IconResolver = (icon, originalSize) => {
|
||||
export const createIcon: (icon: string, originalSize: number) => IconResolver = (
|
||||
icon,
|
||||
originalSize
|
||||
) => {
|
||||
return (
|
||||
parent: Selection<SVGGElement, unknown, Element | null, unknown>,
|
||||
size: number = originalSize
|
||||
@@ -24,17 +27,17 @@ const createIcon: (icon: string, originalSize: number) => IconResolver = (icon,
|
||||
|
||||
const icons: IconLibrary = {};
|
||||
|
||||
const isIconNameInUse = (name: string): boolean => {
|
||||
export const isIconNameInUse = (name: string): boolean => {
|
||||
return icons[name] !== undefined;
|
||||
};
|
||||
|
||||
const registerIcon = (name: string, resolver: IconResolver) => {
|
||||
export const registerIcon = (name: string, resolver: IconResolver) => {
|
||||
if (!isIconNameInUse(name)) {
|
||||
icons[name] = resolver;
|
||||
}
|
||||
};
|
||||
|
||||
const registerIcons = (library: IconLibrary) => {
|
||||
export const registerIcons = (library: IconLibrary) => {
|
||||
Object.entries(library).forEach(([name, resolver]) => {
|
||||
if (!isIconNameInUse(name)) {
|
||||
icons[name] = resolver;
|
||||
@@ -42,19 +45,9 @@ const registerIcons = (library: IconLibrary) => {
|
||||
});
|
||||
};
|
||||
|
||||
const getIcon = (name: string): IconResolver | null => {
|
||||
export const getIcon = (name: string): IconResolver | null => {
|
||||
if (isIconNameInUse(name)) {
|
||||
return icons[name];
|
||||
}
|
||||
return icons.unknown;
|
||||
};
|
||||
|
||||
export {
|
||||
registerIcon,
|
||||
registerIcons,
|
||||
getIcon,
|
||||
isIconNameInUse,
|
||||
createIcon,
|
||||
IconLibrary,
|
||||
IconResolver,
|
||||
};
|
||||
|
Reference in New Issue
Block a user