package.dist.chunks.mermaid.core.chunk-L2CJOYWE.mjs.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mermaid Show documentation
Show all versions of mermaid Show documentation
Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.
{
"version": 3,
"sources": ["../../../src/rendering-util/icons.ts"],
"sourcesContent": ["import { log } from '$root/logger.js';\nimport type { ExtendedIconifyIcon, IconifyIcon, IconifyJSON } from '@iconify/types';\nimport type { IconifyIconCustomisations } from '@iconify/utils';\nimport { getIconData, iconToHTML, iconToSVG, replaceIDs, stringToIcon } from '@iconify/utils';\n\ninterface AsyncIconLoader {\n name: string;\n loader: () => Promise;\n}\n\ninterface SyncIconLoader {\n name: string;\n icons: IconifyJSON;\n}\n\nexport type IconLoader = AsyncIconLoader | SyncIconLoader;\n\nexport const unknownIcon: IconifyIcon = {\n body: '? ',\n height: 80,\n width: 80,\n};\n\nconst iconsStore = new Map();\nconst loaderStore = new Map();\n\nexport const registerIconPacks = (iconLoaders: IconLoader[]) => {\n for (const iconLoader of iconLoaders) {\n if (!iconLoader.name) {\n throw new Error(\n 'Invalid icon loader. Must have a \"name\" property with non-empty string value.'\n );\n }\n log.debug('Registering icon pack:', iconLoader.name);\n if ('loader' in iconLoader) {\n loaderStore.set(iconLoader.name, iconLoader.loader);\n } else if ('icons' in iconLoader) {\n iconsStore.set(iconLoader.name, iconLoader.icons);\n } else {\n log.error('Invalid icon loader:', iconLoader);\n throw new Error('Invalid icon loader. Must have either \"icons\" or \"loader\" property.');\n }\n }\n};\n\nconst getRegisteredIconData = async (iconName: string, fallbackPrefix?: string) => {\n const data = stringToIcon(iconName, true, fallbackPrefix !== undefined);\n if (!data) {\n throw new Error(`Invalid icon name: ${iconName}`);\n }\n const prefix = data.prefix || fallbackPrefix;\n if (!prefix) {\n throw new Error(`Icon name must contain a prefix: ${iconName}`);\n }\n let icons = iconsStore.get(prefix);\n if (!icons) {\n const loader = loaderStore.get(prefix);\n if (!loader) {\n throw new Error(`Icon set not found: ${data.prefix}`);\n }\n try {\n const loaded = await loader();\n icons = { ...loaded, prefix };\n iconsStore.set(prefix, icons);\n } catch (e) {\n log.error(e);\n throw new Error(`Failed to load icon set: ${data.prefix}`);\n }\n }\n const iconData = getIconData(icons, data.name);\n if (!iconData) {\n throw new Error(`Icon not found: ${iconName}`);\n }\n return iconData;\n};\n\nexport const isIconAvailable = async (iconName: string) => {\n try {\n await getRegisteredIconData(iconName);\n return true;\n } catch {\n return false;\n }\n};\n\nexport const getIconSVG = async (\n iconName: string,\n customisations?: IconifyIconCustomisations & { fallbackPrefix?: string }\n) => {\n let iconData: ExtendedIconifyIcon;\n try {\n iconData = await getRegisteredIconData(iconName, customisations?.fallbackPrefix);\n } catch (e) {\n log.error(e);\n iconData = unknownIcon;\n }\n const renderData = iconToSVG(iconData, customisations);\n const svg = iconToHTML(replaceIDs(renderData.body), renderData.attributes);\n return svg;\n};\n"],
"mappings": ";;;;;;AAGA,SAAS,aAAa,YAAY,WAAW,YAAY,oBAAoB;AActE,IAAM,cAA2B;AAAA,EACtC,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AACT;AAEA,IAAM,aAAa,oBAAI,IAAyB;AAChD,IAAM,cAAc,oBAAI,IAAuC;AAExD,IAAM,oBAAoB,wBAAC,gBAA8B;AAC9D,aAAW,cAAc,aAAa;AACpC,QAAI,CAAC,WAAW,MAAM;AACpB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,QAAI,MAAM,0BAA0B,WAAW,IAAI;AACnD,QAAI,YAAY,YAAY;AAC1B,kBAAY,IAAI,WAAW,MAAM,WAAW,MAAM;AAAA,IACpD,WAAW,WAAW,YAAY;AAChC,iBAAW,IAAI,WAAW,MAAM,WAAW,KAAK;AAAA,IAClD,OAAO;AACL,UAAI,MAAM,wBAAwB,UAAU;AAC5C,YAAM,IAAI,MAAM,qEAAqE;AAAA,IACvF;AAAA,EACF;AACF,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