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