@azerion/bunosaurus-theme-mermaid 0.0.0-stage → 4.0.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 CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # `@docusaurus/theme-mermaid`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The mermaid components for Docusaurus.
4
+
5
+ ## Installation
6
+
7
+ Add `docusaurus/theme-mermaid` to your package:
8
+
9
+ ```bash
10
+ npm i @docusaurus/theme-mermaid
11
+ # or
12
+ yarn add @docusaurus/theme-mermaid
13
+ ```
14
+
15
+ ## Swizzling components
16
+
17
+ ```bash
18
+ $ npm swizzle @docusaurus/theme-mermaid [component name]
19
+ ```
20
+
21
+ All components used by this theme can be found [here](https://github.com/facebook/docusaurus/tree/main/packages/docusaurus-theme-mermaid/src/theme)
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { RenderResult, MermaidConfig } from 'mermaid';
8
+ import type { ThemeConfig } from '@docusaurus/theme-mermaid';
9
+ export declare const MermaidContainerClassName = "docusaurus-mermaid-container";
10
+ export declare function useMermaidThemeConfig(): ThemeConfig['mermaid'];
11
+ export declare function useMermaidConfig(): MermaidConfig;
12
+ export declare function useMermaidRenderResult({ text, config: providedConfig, }: {
13
+ text: string;
14
+ config?: MermaidConfig;
15
+ }): RenderResult | null;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { useState, useEffect, useMemo, useId, useRef } from 'react';
8
+ import { useColorMode, useThemeConfig } from '@docusaurus/theme-common';
9
+ import { loadMermaid } from './loadMermaid';
10
+ // Stable className to allow users to easily target with CSS
11
+ export const MermaidContainerClassName = 'docusaurus-mermaid-container';
12
+ export function useMermaidThemeConfig() {
13
+ return useThemeConfig().mermaid;
14
+ }
15
+ export function useMermaidConfig() {
16
+ const { colorMode } = useColorMode();
17
+ const mermaidThemeConfig = useMermaidThemeConfig();
18
+ const theme = mermaidThemeConfig.theme[colorMode];
19
+ const { options } = mermaidThemeConfig;
20
+ return useMemo(() => ({ startOnLoad: false, ...options, theme }), [theme, options]);
21
+ }
22
+ async function renderMermaid({ id, text, config, }) {
23
+ const mermaid = await loadMermaid();
24
+ /*
25
+ Mermaid API is really weird :s
26
+ It is a big mutable singleton with multiple config levels
27
+ Note: most recent API type definitions are missing
28
+
29
+ There are 2 kind of configs:
30
+
31
+ - siteConfig: some kind of global/protected shared config
32
+ you can only set with "initialize"
33
+
34
+ - config/currentConfig
35
+ the config the renderer will use
36
+ it is reset to siteConfig before each render
37
+ but it can be altered by the mermaid txt content itself through directives
38
+
39
+ To use a new mermaid config (on colorMode change for example) we should
40
+ update siteConfig, and it can only be done with initialize()
41
+ */
42
+ mermaid.initialize(config);
43
+ try {
44
+ return await mermaid.render(id, text);
45
+ }
46
+ catch (e) {
47
+ // Because Mermaid add a weird SVG/Message to the DOM on error
48
+ // https://github.com/mermaid-js/mermaid/issues/3205#issuecomment-1719620183
49
+ document.querySelector(`#d${id}`)?.remove();
50
+ throw e;
51
+ }
52
+ }
53
+ export function useMermaidRenderResult({ text, config: providedConfig, }) {
54
+ const [result, setResult] = useState(null);
55
+ const id = useId();
56
+ const renderCount = useRef(0);
57
+ /*
58
+ For flexibility, we allow the hook to receive a custom Mermaid config
59
+ The user could inject a modified version of the default config for example
60
+ */
61
+ const defaultMermaidConfig = useMermaidConfig();
62
+ const config = providedConfig ?? defaultMermaidConfig;
63
+ useEffect(() => {
64
+ // Mermaid removes existing DOM elements with the requested ID. Reusing an
65
+ // ID can delete the displayed SVG, which React won't restore if the new
66
+ // SVG markup is identical. Give every render its own ID instead.
67
+ renderMermaid({ id: `${id}-${renderCount.current++}`, text, config })
68
+ // TODO maybe try to use Suspense here and throw the promise?
69
+ // See also https://github.com/pmndrs/suspend-react
70
+ .then(setResult)
71
+ .catch((e) => {
72
+ // Funky way to trigger parent React error boundary
73
+ // See https://x.com/sebastienlorber/status/1628340871899893768
74
+ setResult(() => {
75
+ throw e;
76
+ });
77
+ });
78
+ }, [id, text, config]);
79
+ return result;
80
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { Mermaid } from 'mermaid';
8
+ export declare function loadMermaid(): Promise<Mermaid>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ // We load Mermaid with a dynamic import to code split / lazy load the library
8
+ // It is only called inside a useEffect, so loading can be deferred
9
+ export async function loadMermaid() {
10
+ return (await import('mermaid')).default;
11
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { Plugin } from '@docusaurus/types';
8
+ export default function themeMermaid(): Plugin<void>;
9
+ export { validateThemeConfig } from './validateThemeConfig';
package/lib/index.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validateThemeConfig = void 0;
10
+ exports.default = themeMermaid;
11
+ function themeMermaid() {
12
+ return {
13
+ name: 'docusaurus-theme-mermaid',
14
+ getThemePath() {
15
+ return '../lib/theme';
16
+ },
17
+ getTypeScriptThemePath() {
18
+ return '../src/theme';
19
+ },
20
+ };
21
+ }
22
+ var validateThemeConfig_1 = require("./validateThemeConfig");
23
+ Object.defineProperty(exports, "validateThemeConfig", { enumerable: true, get: function () { return validateThemeConfig_1.validateThemeConfig; } });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { type ReactNode } from 'react';
8
+ import type { Props } from '@theme/Mermaid';
9
+ export default function Mermaid(props: Props): ReactNode;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import {useEffect, useRef} from 'react';
8
+ import ErrorBoundary from '@docusaurus/ErrorBoundary';
9
+ import {ErrorBoundaryErrorMessageFallback} from '@docusaurus/theme-common';
10
+ import {
11
+ MermaidContainerClassName,
12
+ useMermaidRenderResult,
13
+ } from '@docusaurus/theme-mermaid/client';
14
+ import styles from './styles.module.css';
15
+ function MermaidRenderResult({renderResult}) {
16
+ const ref = useRef(null);
17
+ useEffect(() => {
18
+ const div = ref.current;
19
+ renderResult.bindFunctions?.(div);
20
+ }, [renderResult]);
21
+ return (
22
+ <div
23
+ ref={ref}
24
+ className={`${MermaidContainerClassName} ${styles.container}`}
25
+ dangerouslySetInnerHTML={{__html: renderResult.svg}}
26
+ />
27
+ );
28
+ }
29
+ function MermaidRenderer({value}) {
30
+ const renderResult = useMermaidRenderResult({text: value});
31
+ if (renderResult === null) {
32
+ return null;
33
+ }
34
+ return <MermaidRenderResult renderResult={renderResult} />;
35
+ }
36
+ export default function Mermaid(props) {
37
+ return (
38
+ <ErrorBoundary
39
+ fallback={(params) => <ErrorBoundaryErrorMessageFallback {...params} />}>
40
+ <MermaidRenderer {...props} />
41
+ </ErrorBoundary>
42
+ );
43
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ .container {
9
+ max-width: 100%;
10
+ }
11
+
12
+ .container > svg {
13
+ max-width: 100%;
14
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { Joi } from '@docusaurus/utils-validation';
8
+ import type { ThemeConfig } from '@docusaurus/theme-mermaid';
9
+ import type { ThemeConfigValidationContext } from '@docusaurus/types';
10
+ export declare const DEFAULT_THEME_CONFIG: ThemeConfig;
11
+ export declare const Schema: Joi.ObjectSchema<ThemeConfig>;
12
+ export declare function validateThemeConfig({ validate, themeConfig, }: ThemeConfigValidationContext<ThemeConfig>): ThemeConfig;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Schema = exports.DEFAULT_THEME_CONFIG = void 0;
10
+ exports.validateThemeConfig = validateThemeConfig;
11
+ const utils_validation_1 = require("@docusaurus/utils-validation");
12
+ exports.DEFAULT_THEME_CONFIG = {
13
+ mermaid: {
14
+ theme: {
15
+ dark: 'dark',
16
+ light: 'default',
17
+ },
18
+ options: {},
19
+ },
20
+ };
21
+ exports.Schema = utils_validation_1.Joi.object({
22
+ mermaid: utils_validation_1.Joi.object({
23
+ theme: utils_validation_1.Joi.object({
24
+ dark: utils_validation_1.Joi.string().default(exports.DEFAULT_THEME_CONFIG.mermaid.theme.dark),
25
+ light: utils_validation_1.Joi.string().default(exports.DEFAULT_THEME_CONFIG.mermaid.theme.light),
26
+ }).default(exports.DEFAULT_THEME_CONFIG.mermaid.theme),
27
+ options: utils_validation_1.Joi.object().default(exports.DEFAULT_THEME_CONFIG.mermaid.options),
28
+ }).default(exports.DEFAULT_THEME_CONFIG.mermaid),
29
+ });
30
+ function validateThemeConfig({ validate, themeConfig, }) {
31
+ return validate(exports.Schema, themeConfig);
32
+ }
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@azerion/bunosaurus-theme-mermaid",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "4.0.0",
4
+ "description": "Mermaid components for Docusaurus.",
5
+ "main": "lib/index.js",
6
+ "types": "src/theme-mermaid.d.ts",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ "./lib/*": "./lib/*",
10
+ "./src/*": "./src/*",
11
+ "./client": {
12
+ "type": "./lib/client/index.d.ts",
13
+ "default": "./lib/client/index.js"
14
+ },
15
+ ".": {
16
+ "types": "./src/theme-mermaid.d.ts",
17
+ "default": "./lib/index.js"
18
+ }
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/azerion/bunosaurus.git",
26
+ "directory": "packages/docusaurus-theme-mermaid"
27
+ },
28
+ "license": "MIT",
29
+ "scripts": {
30
+ "build": "tsc --build && copy-untyped-files && oxfmt \"lib/theme/**/*.js\"",
31
+ "watch": "run-p -c copy:watch build:watch",
32
+ "build:watch": "tsc --build --watch",
33
+ "copy:watch": "copy-untyped-files --watch"
34
+ },
35
+ "dependencies": {
36
+ "@docusaurus/core": "npm:@azerion/bunosaurus-core@4.0.0",
37
+ "@docusaurus/module-type-aliases": "npm:@azerion/bunosaurus-module-type-aliases@4.0.0",
38
+ "@docusaurus/theme-common": "npm:@azerion/bunosaurus-theme-common@4.0.0",
39
+ "@docusaurus/types": "npm:@azerion/bunosaurus-types@4.0.0",
40
+ "@docusaurus/utils-validation": "npm:@azerion/bunosaurus-utils-validation@4.0.0",
41
+ "mermaid": "^12.0.0",
42
+ "tslib": "^2.8.1"
43
+ },
44
+ "peerDependencies": {
45
+ "react": "^19.3.0",
46
+ "react-dom": "^19.3.0"
47
+ },
48
+ "engines": {
49
+ "bun": ">=1.4.1"
50
+ }
51
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {useState, useEffect, useMemo, useId, useRef} from 'react';
9
+ import {useColorMode, useThemeConfig} from '@docusaurus/theme-common';
10
+ import {loadMermaid} from './loadMermaid';
11
+
12
+ import type {RenderResult, MermaidConfig} from 'mermaid';
13
+ import type {ThemeConfig} from '@docusaurus/theme-mermaid';
14
+
15
+ // Stable className to allow users to easily target with CSS
16
+ export const MermaidContainerClassName = 'docusaurus-mermaid-container';
17
+
18
+ export function useMermaidThemeConfig(): ThemeConfig['mermaid'] {
19
+ return (useThemeConfig() as unknown as ThemeConfig).mermaid;
20
+ }
21
+
22
+ export function useMermaidConfig(): MermaidConfig {
23
+ const {colorMode} = useColorMode();
24
+ const mermaidThemeConfig = useMermaidThemeConfig();
25
+
26
+ const theme = mermaidThemeConfig.theme[colorMode];
27
+ const {options} = mermaidThemeConfig;
28
+
29
+ return useMemo(
30
+ () => ({startOnLoad: false, ...options, theme}),
31
+ [theme, options],
32
+ );
33
+ }
34
+
35
+ async function renderMermaid({
36
+ id,
37
+ text,
38
+ config,
39
+ }: {
40
+ id: string;
41
+ text: string;
42
+ config: MermaidConfig;
43
+ }): Promise<RenderResult> {
44
+ const mermaid = await loadMermaid();
45
+
46
+ /*
47
+ Mermaid API is really weird :s
48
+ It is a big mutable singleton with multiple config levels
49
+ Note: most recent API type definitions are missing
50
+
51
+ There are 2 kind of configs:
52
+
53
+ - siteConfig: some kind of global/protected shared config
54
+ you can only set with "initialize"
55
+
56
+ - config/currentConfig
57
+ the config the renderer will use
58
+ it is reset to siteConfig before each render
59
+ but it can be altered by the mermaid txt content itself through directives
60
+
61
+ To use a new mermaid config (on colorMode change for example) we should
62
+ update siteConfig, and it can only be done with initialize()
63
+ */
64
+ mermaid.initialize(config);
65
+
66
+ try {
67
+ return await mermaid.render(id, text);
68
+ } catch (e) {
69
+ // Because Mermaid add a weird SVG/Message to the DOM on error
70
+ // https://github.com/mermaid-js/mermaid/issues/3205#issuecomment-1719620183
71
+ document.querySelector(`#d${id}`)?.remove();
72
+ throw e;
73
+ }
74
+ }
75
+
76
+ export function useMermaidRenderResult({
77
+ text,
78
+ config: providedConfig,
79
+ }: {
80
+ text: string;
81
+ config?: MermaidConfig;
82
+ }): RenderResult | null {
83
+ const [result, setResult] = useState<RenderResult | null>(null);
84
+ const id = useId();
85
+ const renderCount = useRef(0);
86
+
87
+ /*
88
+ For flexibility, we allow the hook to receive a custom Mermaid config
89
+ The user could inject a modified version of the default config for example
90
+ */
91
+ const defaultMermaidConfig = useMermaidConfig();
92
+ const config = providedConfig ?? defaultMermaidConfig;
93
+
94
+ useEffect(() => {
95
+ // Mermaid removes existing DOM elements with the requested ID. Reusing an
96
+ // ID can delete the displayed SVG, which React won't restore if the new
97
+ // SVG markup is identical. Give every render its own ID instead.
98
+ renderMermaid({id: `${id}-${renderCount.current++}`, text, config})
99
+ // TODO maybe try to use Suspense here and throw the promise?
100
+ // See also https://github.com/pmndrs/suspend-react
101
+ .then(setResult)
102
+ .catch((e) => {
103
+ // Funky way to trigger parent React error boundary
104
+ // See https://x.com/sebastienlorber/status/1628340871899893768
105
+ setResult(() => {
106
+ throw e;
107
+ });
108
+ });
109
+ }, [id, text, config]);
110
+
111
+ return result;
112
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import type {Mermaid} from 'mermaid';
9
+
10
+ // We load Mermaid with a dynamic import to code split / lazy load the library
11
+ // It is only called inside a useEffect, so loading can be deferred
12
+ export async function loadMermaid(): Promise<Mermaid> {
13
+ return (await import('mermaid')).default;
14
+ }
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import type {Plugin} from '@docusaurus/types';
9
+
10
+ export default function themeMermaid(): Plugin<void> {
11
+ return {
12
+ name: 'docusaurus-theme-mermaid',
13
+
14
+ getThemePath() {
15
+ return '../lib/theme';
16
+ },
17
+ getTypeScriptThemePath() {
18
+ return '../src/theme';
19
+ },
20
+ };
21
+ }
22
+
23
+ export {validateThemeConfig} from './validateThemeConfig';
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {useEffect, useRef, type ReactNode} from 'react';
9
+ import ErrorBoundary from '@docusaurus/ErrorBoundary';
10
+ import {ErrorBoundaryErrorMessageFallback} from '@docusaurus/theme-common';
11
+ import {
12
+ MermaidContainerClassName,
13
+ useMermaidRenderResult,
14
+ } from '@docusaurus/theme-mermaid/client';
15
+ import type {Props} from '@theme/Mermaid';
16
+ import type {RenderResult} from 'mermaid';
17
+
18
+ import styles from './styles.module.css';
19
+
20
+ function MermaidRenderResult({
21
+ renderResult,
22
+ }: {
23
+ renderResult: RenderResult;
24
+ }): ReactNode {
25
+ const ref = useRef<HTMLDivElement>(null);
26
+
27
+ useEffect(() => {
28
+ const div = ref.current!;
29
+ renderResult.bindFunctions?.(div);
30
+ }, [renderResult]);
31
+
32
+ return (
33
+ <div
34
+ ref={ref}
35
+ className={`${MermaidContainerClassName} ${styles.container}`}
36
+ dangerouslySetInnerHTML={{__html: renderResult.svg}}
37
+ />
38
+ );
39
+ }
40
+
41
+ function MermaidRenderer({value}: Props): ReactNode {
42
+ const renderResult = useMermaidRenderResult({text: value});
43
+ if (renderResult === null) {
44
+ return null;
45
+ }
46
+ return <MermaidRenderResult renderResult={renderResult} />;
47
+ }
48
+
49
+ export default function Mermaid(props: Props): ReactNode {
50
+ return (
51
+ <ErrorBoundary
52
+ fallback={(params) => <ErrorBoundaryErrorMessageFallback {...params} />}>
53
+ <MermaidRenderer {...props} />
54
+ </ErrorBoundary>
55
+ );
56
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ .container {
9
+ max-width: 100%;
10
+ }
11
+
12
+ .container > svg {
13
+ max-width: 100%;
14
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ /// <reference types="@docusaurus/module-type-aliases" />
9
+
10
+ declare module '@docusaurus/theme-mermaid' {
11
+ import type {DeepPartial} from 'utility-types';
12
+ import type {MermaidConfig} from 'mermaid';
13
+ import type {Plugin} from '@docusaurus/types';
14
+
15
+ export type ThemeConfig = {
16
+ mermaid: {
17
+ theme: {
18
+ light: NonNullable<MermaidConfig['theme']>;
19
+ dark: NonNullable<MermaidConfig['theme']>;
20
+ };
21
+ options: MermaidConfig;
22
+ };
23
+ };
24
+ export type UserThemeConfig = DeepPartial<ThemeConfig>;
25
+
26
+ export default function themeMermaid(): Plugin<undefined>;
27
+ }
28
+
29
+ declare module '@theme/Mermaid' {
30
+ import {type ReactNode} from 'react';
31
+
32
+ export interface Props {
33
+ value: string;
34
+ }
35
+
36
+ export default function Mermaid(props: Props): ReactNode;
37
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {Joi} from '@docusaurus/utils-validation';
9
+ import type {ThemeConfig} from '@docusaurus/theme-mermaid';
10
+ import type {ThemeConfigValidationContext} from '@docusaurus/types';
11
+
12
+ export const DEFAULT_THEME_CONFIG: ThemeConfig = {
13
+ mermaid: {
14
+ theme: {
15
+ dark: 'dark',
16
+ light: 'default',
17
+ },
18
+ options: {},
19
+ },
20
+ };
21
+
22
+ export const Schema = Joi.object<ThemeConfig>({
23
+ mermaid: Joi.object({
24
+ theme: Joi.object({
25
+ dark: Joi.string().default(DEFAULT_THEME_CONFIG.mermaid.theme.dark),
26
+ light: Joi.string().default(DEFAULT_THEME_CONFIG.mermaid.theme.light),
27
+ }).default(DEFAULT_THEME_CONFIG.mermaid.theme),
28
+ options: Joi.object().default(DEFAULT_THEME_CONFIG.mermaid.options),
29
+ }).default(DEFAULT_THEME_CONFIG.mermaid),
30
+ });
31
+
32
+ export function validateThemeConfig({
33
+ validate,
34
+ themeConfig,
35
+ }: ThemeConfigValidationContext<ThemeConfig>): ThemeConfig {
36
+ return validate(Schema, themeConfig);
37
+ }