backstage-plugin-techdocs-addon-mermaid 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/dist/Mermaid/Mermaid.esm.js +36 -19
- package/dist/Mermaid/Mermaid.esm.js.map +1 -1
- package/dist/Mermaid/hooks.esm.js +1 -3
- package/dist/Mermaid/hooks.esm.js.map +1 -1
- package/dist/Mermaid/loadMermaid.esm.js +14 -0
- package/dist/Mermaid/loadMermaid.esm.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -301,6 +301,32 @@ config:
|
|
|
301
301
|
|
|
302
302
|
This plugin can be developed in the context of an existing Backstage deployment or a [new local deployment](https://backstage.io/docs/getting-started/#1-create-your-backstage-app).
|
|
303
303
|
|
|
304
|
+
### Releasing to npm
|
|
305
|
+
|
|
306
|
+
The `publish.yml` workflow uses [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/)
|
|
307
|
+
to authenticate with GitHub Actions OIDC, without an `NPM_TOKEN` secret.
|
|
308
|
+
Before the first automated release, a package maintainer must configure a GitHub Actions
|
|
309
|
+
trusted publisher in the npm package settings with:
|
|
310
|
+
|
|
311
|
+
- Organization or user: `johanneswuerbach`
|
|
312
|
+
- Repository: `backstage-plugin-techdocs-addon-mermaid`
|
|
313
|
+
- Workflow filename: `publish.yml`
|
|
314
|
+
- Environment name: leave empty
|
|
315
|
+
- Allow direct publishing with `npm publish`
|
|
316
|
+
|
|
317
|
+
Once trusted publishing is configured and verified, remove the old `NPM_TOKEN`
|
|
318
|
+
repository secret and revoke the token in npm.
|
|
319
|
+
|
|
320
|
+
To release, merge a version bump in `package.json`, tag that commit as `v<version>`
|
|
321
|
+
(for example, `v0.30.0`), and publish a GitHub release for that tag. Pushing a tag
|
|
322
|
+
alone or saving a draft release does not publish to npm. The workflow checks that
|
|
323
|
+
the tag matches the package version, runs type checks, builds, tests, and packs
|
|
324
|
+
with Yarn before publishing the tarball with npm. Node.js 24 supplies an npm CLI
|
|
325
|
+
that supports trusted publishing (npm 11.5.1 or later).
|
|
326
|
+
|
|
327
|
+
Regular releases use the npm `latest` dist-tag; GitHub prereleases use `next`.
|
|
328
|
+
Use a new package version for each release; npm versions cannot be overwritten.
|
|
329
|
+
|
|
304
330
|
### Setup for Deployment
|
|
305
331
|
|
|
306
332
|
1. Fork and clone this repo into the plugins folder of your Backstage codebase.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
2
|
import { useTheme } from '@material-ui/core';
|
|
3
3
|
import { useShadowRootElements } from '@backstage/plugin-techdocs-react';
|
|
4
|
-
import mermaid from 'mermaid';
|
|
5
4
|
import { isMermaidCode } from './hooks.esm.js';
|
|
5
|
+
import { loadMermaid } from './loadMermaid.esm.js';
|
|
6
6
|
import { ZoomHandler } from './zoomHandler.esm.js';
|
|
7
7
|
import { deepMerge } from './utils.esm.js';
|
|
8
8
|
|
|
@@ -73,7 +73,7 @@ const outermostCandidates = (elements) => {
|
|
|
73
73
|
(element) => unique.every((other) => other === element || !other.contains(element))
|
|
74
74
|
);
|
|
75
75
|
};
|
|
76
|
-
const makeDiagram = async (el, diagramText, properties) => {
|
|
76
|
+
const makeDiagram = async (mermaid, el, diagramText, properties) => {
|
|
77
77
|
el.style.display = "none";
|
|
78
78
|
const diagramElement = document.createElement("div");
|
|
79
79
|
diagramElement.className = "mermaid";
|
|
@@ -103,23 +103,40 @@ const makeDiagram = async (el, diagramText, properties) => {
|
|
|
103
103
|
const MermaidAddon = (properties) => {
|
|
104
104
|
const candidates = useShadowRootElements(candidateSelectors);
|
|
105
105
|
const theme = useTheme();
|
|
106
|
-
const [
|
|
106
|
+
const [mermaid, setMermaid] = useState();
|
|
107
107
|
useEffect(() => {
|
|
108
|
-
if (
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const config = selectConfig(theme.palette.type, properties);
|
|
112
|
-
if (properties.iconLoaders) {
|
|
113
|
-
mermaid.registerIconPacks(properties.iconLoaders);
|
|
108
|
+
if (mermaid) {
|
|
109
|
+
return void 0;
|
|
114
110
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
let cancelled = false;
|
|
112
|
+
loadMermaid().then(
|
|
113
|
+
(loaded) => {
|
|
114
|
+
if (cancelled) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const config = selectConfig(
|
|
118
|
+
theme.palette.type,
|
|
119
|
+
properties
|
|
120
|
+
);
|
|
121
|
+
if (properties.iconLoaders) {
|
|
122
|
+
loaded.registerIconPacks(properties.iconLoaders);
|
|
123
|
+
}
|
|
124
|
+
if (properties.layoutLoaders) {
|
|
125
|
+
loaded.registerLayoutLoaders(properties.layoutLoaders);
|
|
126
|
+
}
|
|
127
|
+
loaded.initialize({ suppressErrorRendering: true, ...config });
|
|
128
|
+
setMermaid(loaded);
|
|
129
|
+
},
|
|
130
|
+
(error) => {
|
|
131
|
+
console.error("Failed to load mermaid", error);
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
return () => {
|
|
135
|
+
cancelled = true;
|
|
136
|
+
};
|
|
137
|
+
}, [mermaid, properties, theme.palette.type]);
|
|
121
138
|
useEffect(() => {
|
|
122
|
-
if (!
|
|
139
|
+
if (!mermaid) {
|
|
123
140
|
return;
|
|
124
141
|
}
|
|
125
142
|
outermostCandidates(candidates).forEach((candidate) => {
|
|
@@ -136,13 +153,13 @@ const MermaidAddon = (properties) => {
|
|
|
136
153
|
if (language && language !== "text") {
|
|
137
154
|
return;
|
|
138
155
|
}
|
|
139
|
-
if (!isMermaidCode(diagramText)) {
|
|
156
|
+
if (!isMermaidCode(diagramText, mermaid)) {
|
|
140
157
|
return;
|
|
141
158
|
}
|
|
142
159
|
}
|
|
143
|
-
makeDiagram(candidate, diagramText, properties);
|
|
160
|
+
makeDiagram(mermaid, candidate, diagramText, properties);
|
|
144
161
|
});
|
|
145
|
-
}, [
|
|
162
|
+
}, [mermaid, candidates, properties]);
|
|
146
163
|
return null;
|
|
147
164
|
};
|
|
148
165
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mermaid.esm.js","sources":["../../src/Mermaid/Mermaid.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEffect, useState } from 'react';\nimport { PaletteType, useTheme } from '@material-ui/core';\n\nimport { useShadowRootElements } from '@backstage/plugin-techdocs-react';\nimport mermaid, { MermaidConfig } from 'mermaid';\nimport { isMermaidCode } from './hooks';\nimport { MermaidProps } from './props';\nimport { BackstageTheme } from '@backstage/theme';\nimport { ZoomHandler } from './zoomHandler';\nimport { deepMerge } from './utils';\n\nexport function selectConfig(\n backstagePalette: PaletteType,\n properties: MermaidProps,\n): MermaidConfig {\n // Determine the default config based on palette\n const defaultConfig =\n backstagePalette === 'light'\n ? properties.lightConfig || {}\n : Object.assign({ theme: 'dark' }, properties.darkConfig);\n\n // If a config is provided, deep merge it with the default config (user values take precedence)\n if (properties.config) {\n return deepMerge(defaultConfig, properties.config);\n }\n\n return defaultConfig;\n}\n\n/**\n * Show report issue button when text is highlighted\n */\n\nlet diagramId = 0;\n\nconst candidateSelectors = [\n '.highlighttable',\n '.highlight',\n 'pre.mermaid',\n '.mermaid',\n '.language-mermaid',\n];\nconst lineNumberSelectors = '.linenos, .linenodiv, .lnt';\n\nconst stripLineNumberGutters = (text: string): string => {\n const lines = text.split('\\n');\n if (lines.length < 2) {\n return text.trim();\n }\n\n const stripped: string[] = [];\n for (let index = 0; index < lines.length; index += 1) {\n const expected = String(index + 1);\n const line = lines[index];\n if (line === expected) {\n stripped.push('');\n continue;\n }\n if (line.startsWith(`${expected} `) || line.startsWith(`${expected}\\t`)) {\n stripped.push(line.slice(expected.length + 1));\n continue;\n }\n const nextChar = line.charAt(expected.length);\n if (\n line.startsWith(expected) &&\n nextChar !== '' &&\n /[A-Za-z%]/.test(nextChar)\n ) {\n stripped.push(line.slice(expected.length));\n continue;\n }\n return text.trim();\n }\n return stripped.join('\\n').trim();\n};\n\nconst getDiagramSource = (element: HTMLElement): string => {\n const sourceRoot = element.matches('code')\n ? element\n : (element.querySelector('code') ?? element);\n const clone = sourceRoot.cloneNode(true);\n if (clone instanceof HTMLElement) {\n clone\n .querySelectorAll(lineNumberSelectors)\n .forEach((node) => node.remove());\n }\n return stripLineNumberGutters(clone.textContent ?? '');\n};\n\n/**\n * mkdocs tags a highlighted block with the fence language, either on the\n * wrapper or on the nested `pre`/`code`, e.g. `language-python`. Languages\n * pygments has no lexer for - `mermaid` among them, depending on the mkdocs\n * version - fall back to `language-text`.\n */\nconst languageClassPattern = /(?:^|\\s)language-([\\w-]+)/;\n\nconst declaredLanguage = (element: HTMLElement): string | undefined => {\n const carriers = [element, ...element.querySelectorAll('pre, code')];\n for (const carrier of carriers) {\n const match = languageClassPattern.exec(carrier.className);\n if (match) {\n return match[1];\n }\n }\n return undefined;\n};\n\nconst outermostCandidates = (elements: HTMLElement[]): HTMLElement[] => {\n const unique = [...new Set(elements)];\n return unique.filter((element) =>\n unique.every((other) => other === element || !other.contains(element)),\n );\n};\n\nconst makeDiagram = async (\n el: HTMLElement,\n diagramText: string,\n properties: MermaidProps,\n) => {\n el.style.display = 'none';\n\n const diagramElement = document.createElement('div');\n diagramElement.className = 'mermaid';\n diagramElement.dataset.mermaidRendered = 'true';\n // Clip the element when outside parent when panning\n diagramElement.style.overflow = 'hidden';\n\n el.parentNode?.insertBefore(diagramElement, el.nextSibling);\n\n const id = `mermaid-${diagramId++}`;\n try {\n const { svg, bindFunctions } = await mermaid.render(id, diagramText);\n diagramElement.innerHTML = svg;\n bindFunctions?.(diagramElement);\n\n if (properties.enableZoom) {\n const svgEl = diagramElement.querySelector('svg');\n const zoomHandler = new ZoomHandler(\n diagramElement,\n svgEl as SVGSVGElement,\n properties.zoomOptions,\n );\n zoomHandler.initialize();\n }\n } catch (e) {\n el.style.display = '';\n diagramElement.remove();\n // eslint-disable-next-line no-console\n console.error('Failed to render mermaid diagram', e);\n }\n};\n\nexport const MermaidAddon = (properties: MermaidProps) => {\n const candidates = useShadowRootElements<HTMLElement>(candidateSelectors);\n const theme = useTheme<BackstageTheme>();\n\n const [initialized, setInitialized] = useState(false);\n\n useEffect(() => {\n if (initialized) {\n return;\n }\n const config: MermaidConfig = selectConfig(theme.palette.type, properties);\n if (properties.iconLoaders) {\n mermaid.registerIconPacks(properties.iconLoaders);\n }\n if (properties.layoutLoaders) {\n mermaid.registerLayoutLoaders(properties.layoutLoaders);\n }\n mermaid.initialize({ suppressErrorRendering: true, ...config });\n setInitialized(true);\n }, [initialized, properties, theme.palette.type]);\n\n useEffect(() => {\n if (!initialized) {\n return;\n }\n\n outermostCandidates(candidates).forEach((candidate) => {\n if (\n candidate.style.display === 'none' ||\n candidate.dataset.mermaidRendered === 'true'\n ) {\n return;\n }\n\n const diagramText = getDiagramSource(candidate);\n if (!diagramText) {\n return;\n }\n\n const language = declaredLanguage(candidate);\n const isExplicitMermaid =\n language === 'mermaid' || candidate.matches('pre.mermaid, .mermaid');\n\n if (!isExplicitMermaid) {\n // A block that declares a language is an ordinary code sample. Only\n // undeclared and `text` blocks are guessed at, otherwise snippets that\n // happen to start with `graph`, `info` or `pie` get mistaken for\n // diagrams.\n if (language && language !== 'text') {\n return;\n }\n if (!isMermaidCode(diagramText)) {\n return;\n }\n }\n\n makeDiagram(candidate, diagramText, properties);\n });\n }, [initialized, candidates, properties]);\n\n return null;\n};\n"],"names":[],"mappings":";;;;;;;;AA2B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CAAA;AAEhD,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,WAAA,EAAa;AAChB,MAAA;AAAA,IACF;AAEA,IAAA,mBAAA,CAAoB,UAAU,CAAA,CAAE,OAAA,CAAQ,CAAC,SAAA,KAAc;AACrD,MAAA,IACE,UAAU,KAAA,CAAM,OAAA,KAAY,UAC5B,SAAA,CAAU,OAAA,CAAQ,oBAAoB,MAAA,EACtC;AACA,QAAA;AAAA,MACF;AAEA,MAAA,MAAM,WAAA,GAAc,iBAAiB,SAAS,CAAA;AAC9C,MAAA,IAAI,CAAC,WAAA,EAAa;AAChB,QAAA;AAAA,MACF;AAEA,MAAA,MAAM,QAAA,GAAW,iBAAiB,SAAS,CAAA;AAC3C,MAAA,MAAM,iBAAA,GACJ,QAAA,KAAa,SAAA,IAAa,SAAA,CAAU,QAAQ,uBAAuB,CAAA;AAErE,MAAA,IAAI,CAAC,iBAAA,EAAmB;AAKtB,QAAA,IAAI,QAAA,IAAY,aAAa,MAAA,EAAQ;AACnC,UAAA;AAAA,QACF;AACA,QAAA,IAAI,CAAC,aAAA,CAAc,WAAW,CAAA,EAAG;AAC/B,UAAA;AAAA,QACF;AAAA,MACF;AAEA,MAAA,WAAA,CAAY,SAAA,EAAW,aAAa,UAAU,CAAA;AAAA,IAChD,CAAC,CAAA;AAAA,EACH,CAAA,EAAG,CAAC,WAAA,EAAa,UAAA,EAAY,UAAU,CAAC,CAAA;AAExC,EAAA,OAAO,IAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"Mermaid.esm.js","sources":["../../src/Mermaid/Mermaid.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEffect, useState } from 'react';\nimport { PaletteType, useTheme } from '@material-ui/core';\n\nimport { useShadowRootElements } from '@backstage/plugin-techdocs-react';\nimport type { MermaidConfig } from 'mermaid';\nimport { isMermaidCode } from './hooks';\nimport { loadMermaid, MermaidApi } from './loadMermaid';\nimport { MermaidProps } from './props';\nimport { BackstageTheme } from '@backstage/theme';\nimport { ZoomHandler } from './zoomHandler';\nimport { deepMerge } from './utils';\n\nexport function selectConfig(\n backstagePalette: PaletteType,\n properties: MermaidProps,\n): MermaidConfig {\n // Determine the default config based on palette\n const defaultConfig =\n backstagePalette === 'light'\n ? properties.lightConfig || {}\n : Object.assign({ theme: 'dark' }, properties.darkConfig);\n\n // If a config is provided, deep merge it with the default config (user values take precedence)\n if (properties.config) {\n return deepMerge(defaultConfig, properties.config);\n }\n\n return defaultConfig;\n}\n\n/**\n * Show report issue button when text is highlighted\n */\n\nlet diagramId = 0;\n\nconst candidateSelectors = [\n '.highlighttable',\n '.highlight',\n 'pre.mermaid',\n '.mermaid',\n '.language-mermaid',\n];\nconst lineNumberSelectors = '.linenos, .linenodiv, .lnt';\n\nconst stripLineNumberGutters = (text: string): string => {\n const lines = text.split('\\n');\n if (lines.length < 2) {\n return text.trim();\n }\n\n const stripped: string[] = [];\n for (let index = 0; index < lines.length; index += 1) {\n const expected = String(index + 1);\n const line = lines[index];\n if (line === expected) {\n stripped.push('');\n continue;\n }\n if (line.startsWith(`${expected} `) || line.startsWith(`${expected}\\t`)) {\n stripped.push(line.slice(expected.length + 1));\n continue;\n }\n const nextChar = line.charAt(expected.length);\n if (\n line.startsWith(expected) &&\n nextChar !== '' &&\n /[A-Za-z%]/.test(nextChar)\n ) {\n stripped.push(line.slice(expected.length));\n continue;\n }\n return text.trim();\n }\n return stripped.join('\\n').trim();\n};\n\nconst getDiagramSource = (element: HTMLElement): string => {\n const sourceRoot = element.matches('code')\n ? element\n : (element.querySelector('code') ?? element);\n const clone = sourceRoot.cloneNode(true);\n if (clone instanceof HTMLElement) {\n clone\n .querySelectorAll(lineNumberSelectors)\n .forEach((node) => node.remove());\n }\n return stripLineNumberGutters(clone.textContent ?? '');\n};\n\n/**\n * mkdocs tags a highlighted block with the fence language, either on the\n * wrapper or on the nested `pre`/`code`, e.g. `language-python`. Languages\n * pygments has no lexer for - `mermaid` among them, depending on the mkdocs\n * version - fall back to `language-text`.\n */\nconst languageClassPattern = /(?:^|\\s)language-([\\w-]+)/;\n\nconst declaredLanguage = (element: HTMLElement): string | undefined => {\n const carriers = [element, ...element.querySelectorAll('pre, code')];\n for (const carrier of carriers) {\n const match = languageClassPattern.exec(carrier.className);\n if (match) {\n return match[1];\n }\n }\n return undefined;\n};\n\nconst outermostCandidates = (elements: HTMLElement[]): HTMLElement[] => {\n const unique = [...new Set(elements)];\n return unique.filter((element) =>\n unique.every((other) => other === element || !other.contains(element)),\n );\n};\n\nconst makeDiagram = async (\n mermaid: MermaidApi,\n el: HTMLElement,\n diagramText: string,\n properties: MermaidProps,\n) => {\n el.style.display = 'none';\n\n const diagramElement = document.createElement('div');\n diagramElement.className = 'mermaid';\n diagramElement.dataset.mermaidRendered = 'true';\n // Clip the element when outside parent when panning\n diagramElement.style.overflow = 'hidden';\n\n el.parentNode?.insertBefore(diagramElement, el.nextSibling);\n\n const id = `mermaid-${diagramId++}`;\n try {\n const { svg, bindFunctions } = await mermaid.render(id, diagramText);\n diagramElement.innerHTML = svg;\n bindFunctions?.(diagramElement);\n\n if (properties.enableZoom) {\n const svgEl = diagramElement.querySelector('svg');\n const zoomHandler = new ZoomHandler(\n diagramElement,\n svgEl as SVGSVGElement,\n properties.zoomOptions,\n );\n zoomHandler.initialize();\n }\n } catch (e) {\n el.style.display = '';\n diagramElement.remove();\n // eslint-disable-next-line no-console\n console.error('Failed to render mermaid diagram', e);\n }\n};\n\nexport const MermaidAddon = (properties: MermaidProps) => {\n const candidates = useShadowRootElements<HTMLElement>(candidateSelectors);\n const theme = useTheme<BackstageTheme>();\n\n const [mermaid, setMermaid] = useState<MermaidApi>();\n\n useEffect(() => {\n if (mermaid) {\n return undefined;\n }\n let cancelled = false;\n loadMermaid().then(\n (loaded) => {\n if (cancelled) {\n return;\n }\n const config: MermaidConfig = selectConfig(\n theme.palette.type,\n properties,\n );\n if (properties.iconLoaders) {\n loaded.registerIconPacks(properties.iconLoaders);\n }\n if (properties.layoutLoaders) {\n loaded.registerLayoutLoaders(properties.layoutLoaders);\n }\n loaded.initialize({ suppressErrorRendering: true, ...config });\n setMermaid(loaded);\n },\n (error) => {\n // eslint-disable-next-line no-console\n console.error('Failed to load mermaid', error);\n },\n );\n return () => {\n cancelled = true;\n };\n }, [mermaid, properties, theme.palette.type]);\n\n useEffect(() => {\n if (!mermaid) {\n return;\n }\n\n outermostCandidates(candidates).forEach((candidate) => {\n if (\n candidate.style.display === 'none' ||\n candidate.dataset.mermaidRendered === 'true'\n ) {\n return;\n }\n\n const diagramText = getDiagramSource(candidate);\n if (!diagramText) {\n return;\n }\n\n const language = declaredLanguage(candidate);\n const isExplicitMermaid =\n language === 'mermaid' || candidate.matches('pre.mermaid, .mermaid');\n\n if (!isExplicitMermaid) {\n // A block that declares a language is an ordinary code sample. Only\n // undeclared and `text` blocks are guessed at, otherwise snippets that\n // happen to start with `graph`, `info` or `pie` get mistaken for\n // diagrams.\n if (language && language !== 'text') {\n return;\n }\n if (!isMermaidCode(diagramText, mermaid)) {\n return;\n }\n }\n\n makeDiagram(mermaid, candidate, diagramText, properties);\n });\n }, [mermaid, candidates, properties]);\n\n return null;\n};\n"],"names":[],"mappings":";;;;;;;;AA4BO,SAAS,YAAA,CACd,kBACA,UAAA,EACe;AAEf,EAAA,MAAM,aAAA,GACJ,gBAAA,KAAqB,OAAA,GACjB,UAAA,CAAW,eAAe,EAAC,GAC3B,MAAA,CAAO,MAAA,CAAO,EAAE,KAAA,EAAO,MAAA,EAAO,EAAG,WAAW,UAAU,CAAA;AAG5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Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport
|
|
1
|
+
{"version":3,"file":"hooks.esm.js","sources":["../../src/Mermaid/hooks.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { MermaidApi } from './loadMermaid';\n\nexport const isMermaidCode = (code: string, mermaid: MermaidApi): boolean => {\n try {\n mermaid.detectType(code)\n return true\n } catch (_) {\n return false\n }\n};\n"],"names":[],"mappings":"AAkBO,MAAM,aAAA,GAAgB,CAAC,IAAA,EAAc,OAAA,KAAiC;AAC3E,EAAA,IAAI;AACF,IAAA,OAAA,CAAQ,WAAW,IAAI,CAAA;AACvB,IAAA,OAAO,IAAA;AAAA,EACT,SAAS,CAAA,EAAG;AACV,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let mermaidPromise;
|
|
2
|
+
function loadMermaid() {
|
|
3
|
+
mermaidPromise ??= import('mermaid').then(
|
|
4
|
+
(module) => module.default,
|
|
5
|
+
(error) => {
|
|
6
|
+
mermaidPromise = void 0;
|
|
7
|
+
throw error;
|
|
8
|
+
}
|
|
9
|
+
);
|
|
10
|
+
return mermaidPromise;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { loadMermaid };
|
|
14
|
+
//# sourceMappingURL=loadMermaid.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadMermaid.esm.js","sources":["../../src/Mermaid/loadMermaid.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\ntype MermaidApi = typeof import('mermaid').default;\n\nlet mermaidPromise: Promise<MermaidApi> | undefined;\n\n/**\n * Loads mermaid on first use. Importing it at module top level would put it,\n * at around 500 KB, in the startup bundle of every app that installs this\n * addon, though only TechDocs pages with diagrams need it.\n *\n * A failed load is not cached, so the next render can try again, for example\n * after a network blip.\n */\nexport function loadMermaid(): Promise<MermaidApi> {\n mermaidPromise ??= import('mermaid').then(\n (module) => module.default,\n (error) => {\n mermaidPromise = undefined;\n throw error;\n },\n );\n return mermaidPromise;\n}\n\nexport type { MermaidApi };\n"],"names":[],"mappings":"AAkBA,IAAI,cAAA;AAUG,SAAS,WAAA,GAAmC;AACjD,EAAA,cAAA,KAAmB,OAAO,SAAS,CAAA,CAAE,IAAA;AAAA,IACnC,CAAC,WAAW,MAAA,CAAO,OAAA;AAAA,IACnB,CAAC,KAAA,KAAU;AACT,MAAA,cAAA,GAAiB,MAAA;AACjB,MAAA,MAAM,KAAA;AAAA,IACR;AAAA,GACF;AACA,EAAA,OAAO,cAAA;AACT;;;;"}
|