@matfsw/docusaurus-plantuml-plugin 0.1.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/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +781 -0
- package/dist/assets.d.ts +15 -0
- package/dist/assets.js +32 -0
- package/dist/constants.d.ts +22 -0
- package/dist/constants.js +24 -0
- package/dist/index.cjs +288 -0
- package/dist/index.d.cts +97 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +74 -0
- package/dist/options.d.ts +46 -0
- package/dist/options.js +131 -0
- package/dist/runtime/assetLoader.d.ts +23 -0
- package/dist/runtime/assetLoader.js +125 -0
- package/dist/runtime/cache.d.ts +20 -0
- package/dist/runtime/cache.js +219 -0
- package/dist/runtime/errors.d.ts +31 -0
- package/dist/runtime/errors.js +108 -0
- package/dist/runtime/queue.d.ts +27 -0
- package/dist/runtime/queue.js +101 -0
- package/dist/runtime/renderer.d.ts +23 -0
- package/dist/runtime/renderer.js +70 -0
- package/dist/runtime/sanitize.d.ts +12 -0
- package/dist/runtime/sanitize.js +47 -0
- package/dist/runtime/types.d.ts +15 -0
- package/dist/runtime/types.js +1 -0
- package/dist/theme/MDXComponents/Code/index.d.ts +16 -0
- package/dist/theme/MDXComponents/Code/index.js +28 -0
- package/dist/theme/PlantUmlDiagram/index.d.ts +16 -0
- package/dist/theme/PlantUmlDiagram/index.js +134 -0
- package/dist/theme/PlantUmlDiagram/styles.module.css +107 -0
- package/dist/theme/codeBlockMeta.d.ts +27 -0
- package/dist/theme/codeBlockMeta.js +58 -0
- package/dist/theme/usePlantUmlConfig.d.ts +14 -0
- package/dist/theme/usePlantUmlConfig.js +29 -0
- package/package.json +112 -0
package/dist/assets.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface PlantUmlCoreLocation {
|
|
2
|
+
/** Absolute directory of the installed `@plantuml/core` package. */
|
|
3
|
+
packageDir: string;
|
|
4
|
+
/** Installed `@plantuml/core` version, used to namespace emitted asset URLs. */
|
|
5
|
+
version: string;
|
|
6
|
+
/** Absolute paths of the runtime files that must be served from the site origin. */
|
|
7
|
+
files: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Locates the installed `@plantuml/core` package on disk.
|
|
11
|
+
*
|
|
12
|
+
* Resolution goes through `@plantuml/core/package.json`, which the package lists in its
|
|
13
|
+
* `exports` map — resolving the bare specifier would give the ES module entry instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare function locatePlantUmlCore(): PlantUmlCoreLocation;
|
package/dist/assets.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { PLANTUML_MODULE_FILENAME, PLUGIN_NAME, VIZ_SCRIPT_FILENAME } from './constants.js';
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
/**
|
|
7
|
+
* Locates the installed `@plantuml/core` package on disk.
|
|
8
|
+
*
|
|
9
|
+
* Resolution goes through `@plantuml/core/package.json`, which the package lists in its
|
|
10
|
+
* `exports` map — resolving the bare specifier would give the ES module entry instead.
|
|
11
|
+
*/
|
|
12
|
+
export function locatePlantUmlCore() {
|
|
13
|
+
let packageJsonPath;
|
|
14
|
+
try {
|
|
15
|
+
packageJsonPath = require.resolve('@plantuml/core/package.json');
|
|
16
|
+
}
|
|
17
|
+
catch (cause) {
|
|
18
|
+
throw new Error(`[${PLUGIN_NAME}] Could not resolve '@plantuml/core'. It is a dependency of this plugin; ` +
|
|
19
|
+
'reinstall your site dependencies to fix a broken or deduplicated install.', { cause });
|
|
20
|
+
}
|
|
21
|
+
const packageDir = path.dirname(packageJsonPath);
|
|
22
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
23
|
+
const version = typeof packageJson.version === 'string' ? packageJson.version : '0.0.0';
|
|
24
|
+
return {
|
|
25
|
+
packageDir,
|
|
26
|
+
version,
|
|
27
|
+
files: [
|
|
28
|
+
path.join(packageDir, VIZ_SCRIPT_FILENAME),
|
|
29
|
+
path.join(packageDir, PLANTUML_MODULE_FILENAME),
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifiers shared by the Node-side plugin and the browser-side theme components.
|
|
3
|
+
*
|
|
4
|
+
* `PLUGIN_NAME` is the Docusaurus plugin name and therefore the key used for global data,
|
|
5
|
+
* so it must stay stable and identical on both sides of the SSR boundary. It is deliberately
|
|
6
|
+
* independent of the npm package name so that renaming the package cannot break global-data
|
|
7
|
+
* lookups in already-built sites.
|
|
8
|
+
*/
|
|
9
|
+
export declare const PLUGIN_ID = "plantuml-client";
|
|
10
|
+
/** Docusaurus' own default plugin instance id, mirrored to avoid a runtime import. */
|
|
11
|
+
export declare const DEFAULT_PLUGIN_ID = "default";
|
|
12
|
+
export declare const PLUGIN_NAME = "docusaurus-plugin-plantuml-client";
|
|
13
|
+
/** Directory (relative to `baseUrl`) that the PlantUML runtime assets are emitted into. */
|
|
14
|
+
export declare function assetsDirForVersion(coreVersion: string): string;
|
|
15
|
+
export declare const VIZ_SCRIPT_FILENAME = "viz-global.js";
|
|
16
|
+
export declare const PLANTUML_MODULE_FILENAME = "plantuml.js";
|
|
17
|
+
/** `data-*` attribute names, kept in one place because tests and docs depend on them. */
|
|
18
|
+
export declare const DATA_ATTR: {
|
|
19
|
+
readonly diagram: "data-plantuml-diagram";
|
|
20
|
+
readonly status: "data-plantuml-status";
|
|
21
|
+
readonly theme: "data-plantuml-theme";
|
|
22
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifiers shared by the Node-side plugin and the browser-side theme components.
|
|
3
|
+
*
|
|
4
|
+
* `PLUGIN_NAME` is the Docusaurus plugin name and therefore the key used for global data,
|
|
5
|
+
* so it must stay stable and identical on both sides of the SSR boundary. It is deliberately
|
|
6
|
+
* independent of the npm package name so that renaming the package cannot break global-data
|
|
7
|
+
* lookups in already-built sites.
|
|
8
|
+
*/
|
|
9
|
+
export const PLUGIN_ID = 'plantuml-client';
|
|
10
|
+
/** Docusaurus' own default plugin instance id, mirrored to avoid a runtime import. */
|
|
11
|
+
export const DEFAULT_PLUGIN_ID = 'default';
|
|
12
|
+
export const PLUGIN_NAME = `docusaurus-plugin-${PLUGIN_ID}`;
|
|
13
|
+
/** Directory (relative to `baseUrl`) that the PlantUML runtime assets are emitted into. */
|
|
14
|
+
export function assetsDirForVersion(coreVersion) {
|
|
15
|
+
return `assets/${PLUGIN_ID}-${coreVersion}`;
|
|
16
|
+
}
|
|
17
|
+
export const VIZ_SCRIPT_FILENAME = 'viz-global.js';
|
|
18
|
+
export const PLANTUML_MODULE_FILENAME = 'plantuml.js';
|
|
19
|
+
/** `data-*` attribute names, kept in one place because tests and docs depend on them. */
|
|
20
|
+
export const DATA_ATTR = {
|
|
21
|
+
diagram: 'data-plantuml-diagram',
|
|
22
|
+
status: 'data-plantuml-status',
|
|
23
|
+
theme: 'data-plantuml-theme',
|
|
24
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
DEFAULT_OPTIONS: () => DEFAULT_OPTIONS,
|
|
34
|
+
PLUGIN_ID: () => PLUGIN_ID,
|
|
35
|
+
PLUGIN_NAME: () => PLUGIN_NAME,
|
|
36
|
+
PlantUmlOptionsError: () => PlantUmlOptionsError,
|
|
37
|
+
createCopyPlugin: () => createCopyPlugin,
|
|
38
|
+
default: () => plantumlPlugin,
|
|
39
|
+
resolveOptions: () => resolveOptions,
|
|
40
|
+
validateOptions: () => validateOptions
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(src_exports);
|
|
43
|
+
|
|
44
|
+
// node_modules/tsup/assets/cjs_shims.js
|
|
45
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
46
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
47
|
+
|
|
48
|
+
// src/index.ts
|
|
49
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
50
|
+
var import_node_url = require("url");
|
|
51
|
+
var import_copy_webpack_plugin = __toESM(require("copy-webpack-plugin"), 1);
|
|
52
|
+
|
|
53
|
+
// src/assets.ts
|
|
54
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
55
|
+
var import_node_module = require("module");
|
|
56
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
57
|
+
|
|
58
|
+
// src/constants.ts
|
|
59
|
+
var PLUGIN_ID = "plantuml-client";
|
|
60
|
+
var DEFAULT_PLUGIN_ID = "default";
|
|
61
|
+
var PLUGIN_NAME = `docusaurus-plugin-${PLUGIN_ID}`;
|
|
62
|
+
function assetsDirForVersion(coreVersion) {
|
|
63
|
+
return `assets/${PLUGIN_ID}-${coreVersion}`;
|
|
64
|
+
}
|
|
65
|
+
var VIZ_SCRIPT_FILENAME = "viz-global.js";
|
|
66
|
+
var PLANTUML_MODULE_FILENAME = "plantuml.js";
|
|
67
|
+
|
|
68
|
+
// src/assets.ts
|
|
69
|
+
var require2 = (0, import_node_module.createRequire)(importMetaUrl);
|
|
70
|
+
function locatePlantUmlCore() {
|
|
71
|
+
let packageJsonPath;
|
|
72
|
+
try {
|
|
73
|
+
packageJsonPath = require2.resolve("@plantuml/core/package.json");
|
|
74
|
+
} catch (cause) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`[${PLUGIN_NAME}] Could not resolve '@plantuml/core'. It is a dependency of this plugin; reinstall your site dependencies to fix a broken or deduplicated install.`,
|
|
77
|
+
{ cause }
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const packageDir = import_node_path.default.dirname(packageJsonPath);
|
|
81
|
+
const packageJson = JSON.parse(import_node_fs.default.readFileSync(packageJsonPath, "utf8"));
|
|
82
|
+
const version = typeof packageJson.version === "string" ? packageJson.version : "0.0.0";
|
|
83
|
+
return {
|
|
84
|
+
packageDir,
|
|
85
|
+
version,
|
|
86
|
+
files: [
|
|
87
|
+
import_node_path.default.join(packageDir, VIZ_SCRIPT_FILENAME),
|
|
88
|
+
import_node_path.default.join(packageDir, PLANTUML_MODULE_FILENAME)
|
|
89
|
+
]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/options.ts
|
|
94
|
+
var DEFAULT_OPTIONS = {
|
|
95
|
+
languages: ["plantuml", "puml"],
|
|
96
|
+
theme: "auto",
|
|
97
|
+
lazy: true,
|
|
98
|
+
cache: "memory",
|
|
99
|
+
sanitizeSvg: true,
|
|
100
|
+
showSourceOnError: true,
|
|
101
|
+
renderTimeoutMs: 2e4,
|
|
102
|
+
cacheMaxEntries: 50
|
|
103
|
+
};
|
|
104
|
+
var CACHE_MODES = ["none", "memory", "session"];
|
|
105
|
+
var THEMES = ["auto", "light", "dark"];
|
|
106
|
+
var MIN_RENDER_TIMEOUT_MS = 100;
|
|
107
|
+
var MAX_RENDER_TIMEOUT_MS = 6e5;
|
|
108
|
+
var PlantUmlOptionsError = class extends Error {
|
|
109
|
+
constructor(message) {
|
|
110
|
+
super(`[${PLUGIN_NAME}] ${message}`);
|
|
111
|
+
this.name = "PlantUmlOptionsError";
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
function fail(message) {
|
|
115
|
+
throw new PlantUmlOptionsError(message);
|
|
116
|
+
}
|
|
117
|
+
function isPlainObject(value) {
|
|
118
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
119
|
+
}
|
|
120
|
+
function quoteList(values) {
|
|
121
|
+
return values.map((value) => `'${value}'`).join(", ");
|
|
122
|
+
}
|
|
123
|
+
function validateBoolean(value, key, fallback) {
|
|
124
|
+
if (value === void 0) return fallback;
|
|
125
|
+
if (typeof value !== "boolean") {
|
|
126
|
+
fail(`options.${key} must be a boolean, received ${JSON.stringify(value)}.`);
|
|
127
|
+
}
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
function validateLanguages(value) {
|
|
131
|
+
if (value === void 0) return [...DEFAULT_OPTIONS.languages];
|
|
132
|
+
if (!Array.isArray(value)) {
|
|
133
|
+
fail(`options.languages must be an array of strings, received ${JSON.stringify(value)}.`);
|
|
134
|
+
}
|
|
135
|
+
if (value.length === 0) {
|
|
136
|
+
fail("options.languages must contain at least one language.");
|
|
137
|
+
}
|
|
138
|
+
const normalized = value.map((entry, index) => {
|
|
139
|
+
if (typeof entry !== "string" || entry.trim() === "") {
|
|
140
|
+
fail(
|
|
141
|
+
`options.languages[${index}] must be a non-empty string, received ${JSON.stringify(entry)}.`
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
return entry.trim().toLowerCase();
|
|
145
|
+
});
|
|
146
|
+
const duplicates = normalized.filter((entry, index) => normalized.indexOf(entry) !== index);
|
|
147
|
+
if (duplicates.length > 0) {
|
|
148
|
+
fail(`options.languages contains duplicate entries: ${quoteList([...new Set(duplicates)])}.`);
|
|
149
|
+
}
|
|
150
|
+
return normalized;
|
|
151
|
+
}
|
|
152
|
+
function validateRenderTimeout(value) {
|
|
153
|
+
if (value === void 0) return DEFAULT_OPTIONS.renderTimeoutMs;
|
|
154
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
155
|
+
fail(`options.renderTimeoutMs must be a finite number, received ${JSON.stringify(value)}.`);
|
|
156
|
+
}
|
|
157
|
+
if (!Number.isInteger(value)) {
|
|
158
|
+
fail(`options.renderTimeoutMs must be an integer, received ${value}.`);
|
|
159
|
+
}
|
|
160
|
+
if (value < MIN_RENDER_TIMEOUT_MS || value > MAX_RENDER_TIMEOUT_MS) {
|
|
161
|
+
fail(
|
|
162
|
+
`options.renderTimeoutMs must be between ${MIN_RENDER_TIMEOUT_MS} and ${MAX_RENDER_TIMEOUT_MS} milliseconds, received ${value}.`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return value;
|
|
166
|
+
}
|
|
167
|
+
function validateCacheMaxEntries(value) {
|
|
168
|
+
if (value === void 0) return DEFAULT_OPTIONS.cacheMaxEntries;
|
|
169
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
170
|
+
fail(`options.cacheMaxEntries must be a positive integer, received ${JSON.stringify(value)}.`);
|
|
171
|
+
}
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
function resolveOptions(rawOptions) {
|
|
175
|
+
if (rawOptions === void 0 || rawOptions === null) {
|
|
176
|
+
return { ...DEFAULT_OPTIONS, languages: [...DEFAULT_OPTIONS.languages] };
|
|
177
|
+
}
|
|
178
|
+
if (!isPlainObject(rawOptions)) {
|
|
179
|
+
fail(`options must be an object, received ${JSON.stringify(rawOptions)}.`);
|
|
180
|
+
}
|
|
181
|
+
const allowedKeys = /* @__PURE__ */ new Set([
|
|
182
|
+
"languages",
|
|
183
|
+
"theme",
|
|
184
|
+
"lazy",
|
|
185
|
+
"cache",
|
|
186
|
+
"sanitizeSvg",
|
|
187
|
+
"showSourceOnError",
|
|
188
|
+
"renderTimeoutMs",
|
|
189
|
+
"cacheMaxEntries",
|
|
190
|
+
// Docusaurus injects `id` for multi-instance plugins.
|
|
191
|
+
"id"
|
|
192
|
+
]);
|
|
193
|
+
const unknownKeys = Object.keys(rawOptions).filter((key) => !allowedKeys.has(key));
|
|
194
|
+
if (unknownKeys.length > 0) {
|
|
195
|
+
fail(
|
|
196
|
+
`Unknown option${unknownKeys.length > 1 ? "s" : ""} ${quoteList(unknownKeys)}. Supported options: ${quoteList([...allowedKeys].filter((key) => key !== "id"))}.`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
const { theme, cache } = rawOptions;
|
|
200
|
+
if (theme !== void 0 && !THEMES.includes(theme)) {
|
|
201
|
+
fail(`options.theme must be one of ${quoteList(THEMES)}, received ${JSON.stringify(theme)}.`);
|
|
202
|
+
}
|
|
203
|
+
if (cache !== void 0 && !CACHE_MODES.includes(cache)) {
|
|
204
|
+
fail(
|
|
205
|
+
`options.cache must be one of ${quoteList(CACHE_MODES)}, received ${JSON.stringify(cache)}.`
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
languages: validateLanguages(rawOptions.languages),
|
|
210
|
+
theme: theme ?? DEFAULT_OPTIONS.theme,
|
|
211
|
+
lazy: validateBoolean(rawOptions.lazy, "lazy", DEFAULT_OPTIONS.lazy),
|
|
212
|
+
cache: cache ?? DEFAULT_OPTIONS.cache,
|
|
213
|
+
sanitizeSvg: validateBoolean(
|
|
214
|
+
rawOptions.sanitizeSvg,
|
|
215
|
+
"sanitizeSvg",
|
|
216
|
+
DEFAULT_OPTIONS.sanitizeSvg
|
|
217
|
+
),
|
|
218
|
+
showSourceOnError: validateBoolean(
|
|
219
|
+
rawOptions.showSourceOnError,
|
|
220
|
+
"showSourceOnError",
|
|
221
|
+
DEFAULT_OPTIONS.showSourceOnError
|
|
222
|
+
),
|
|
223
|
+
renderTimeoutMs: validateRenderTimeout(rawOptions.renderTimeoutMs),
|
|
224
|
+
cacheMaxEntries: validateCacheMaxEntries(rawOptions.cacheMaxEntries)
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// src/index.ts
|
|
229
|
+
var currentDir = import_node_path2.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
|
|
230
|
+
function createCopyPlugin(currentBundler, patterns) {
|
|
231
|
+
if (currentBundler?.name === "rspack") {
|
|
232
|
+
const { CopyRspackPlugin } = currentBundler.instance;
|
|
233
|
+
if (!CopyRspackPlugin) {
|
|
234
|
+
throw new Error(
|
|
235
|
+
`[${PLUGIN_NAME}] The Rspack bundler is active but 'CopyRspackPlugin' is unavailable, so the PlantUML runtime assets cannot be emitted. Upgrade @docusaurus/faster, or disable \`future.v4\` to use the webpack bundler.`
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
return new CopyRspackPlugin({ patterns });
|
|
239
|
+
}
|
|
240
|
+
return new import_copy_webpack_plugin.default({ patterns });
|
|
241
|
+
}
|
|
242
|
+
function plantumlPlugin(_context, options = {}) {
|
|
243
|
+
const resolved = resolveOptions(options);
|
|
244
|
+
const core = locatePlantUmlCore();
|
|
245
|
+
const assetsDir = assetsDirForVersion(core.version);
|
|
246
|
+
return {
|
|
247
|
+
name: PLUGIN_NAME,
|
|
248
|
+
getThemePath() {
|
|
249
|
+
return import_node_path2.default.join(currentDir, "theme");
|
|
250
|
+
},
|
|
251
|
+
contentLoaded({ actions }) {
|
|
252
|
+
const globalData = {
|
|
253
|
+
options: resolved,
|
|
254
|
+
assetsDir,
|
|
255
|
+
coreVersion: core.version
|
|
256
|
+
};
|
|
257
|
+
actions.setGlobalData(globalData);
|
|
258
|
+
},
|
|
259
|
+
configureWebpack(_config, isServer, utils) {
|
|
260
|
+
if (isServer) {
|
|
261
|
+
return {};
|
|
262
|
+
}
|
|
263
|
+
const patterns = core.files.map((absolutePath) => ({
|
|
264
|
+
from: absolutePath,
|
|
265
|
+
to: `${assetsDir}/[name][ext]`,
|
|
266
|
+
// These files are already minified upstream; re-processing 8 MB is wasted work.
|
|
267
|
+
info: { minimized: true }
|
|
268
|
+
}));
|
|
269
|
+
return { plugins: [createCopyPlugin(utils?.currentBundler, patterns)] };
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function validateOptions({
|
|
274
|
+
options
|
|
275
|
+
}) {
|
|
276
|
+
resolveOptions(options);
|
|
277
|
+
return { ...options, id: options.id ?? DEFAULT_PLUGIN_ID };
|
|
278
|
+
}
|
|
279
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
280
|
+
0 && (module.exports = {
|
|
281
|
+
DEFAULT_OPTIONS,
|
|
282
|
+
PLUGIN_ID,
|
|
283
|
+
PLUGIN_NAME,
|
|
284
|
+
PlantUmlOptionsError,
|
|
285
|
+
createCopyPlugin,
|
|
286
|
+
resolveOptions,
|
|
287
|
+
validateOptions
|
|
288
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ConfigureWebpackUtils, LoadContext, Plugin, PluginOptions } from '@docusaurus/types';
|
|
2
|
+
import { WebpackPluginInstance } from 'webpack';
|
|
3
|
+
|
|
4
|
+
/** Cache backing store for rendered SVG output. */
|
|
5
|
+
type CacheMode = 'none' | 'memory' | 'session';
|
|
6
|
+
/** Which PlantUML colour scheme to render. `auto` follows the Docusaurus colour mode. */
|
|
7
|
+
type DiagramTheme = 'auto' | 'light' | 'dark';
|
|
8
|
+
/**
|
|
9
|
+
* Options accepted by the plugin in `docusaurus.config.*`.
|
|
10
|
+
*
|
|
11
|
+
* Every field is optional; see {@link DEFAULT_OPTIONS} for the defaults.
|
|
12
|
+
*/
|
|
13
|
+
interface PlantUmlPluginOptions {
|
|
14
|
+
/** Fenced-code languages treated as PlantUML. Matched case-insensitively. */
|
|
15
|
+
languages?: string[];
|
|
16
|
+
/** Diagram colour scheme. `auto` follows the Docusaurus light/dark colour mode. */
|
|
17
|
+
theme?: DiagramTheme;
|
|
18
|
+
/** Render a diagram only once it scrolls near the viewport. */
|
|
19
|
+
lazy?: boolean;
|
|
20
|
+
/** Where to cache rendered SVG output. */
|
|
21
|
+
cache?: CacheMode;
|
|
22
|
+
/** Sanitize rendered SVG before inserting it into the page. Disable at your own risk. */
|
|
23
|
+
sanitizeSvg?: boolean;
|
|
24
|
+
/** Include the PlantUML source in a `<details>` block when rendering fails. */
|
|
25
|
+
showSourceOnError?: boolean;
|
|
26
|
+
/** Abort a single render after this many milliseconds. */
|
|
27
|
+
renderTimeoutMs?: number;
|
|
28
|
+
/** Maximum number of cached SVG entries kept per browsing session. */
|
|
29
|
+
cacheMaxEntries?: number;
|
|
30
|
+
/** Docusaurus plugin instance id, used when the plugin is registered more than once. */
|
|
31
|
+
id?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Plugin options after validation, with every default applied. */
|
|
34
|
+
type ResolvedPlantUmlOptions = Required<Omit<PlantUmlPluginOptions, 'id' | 'languages'>> & {
|
|
35
|
+
/** Normalized to lower case; matching is case-insensitive. */
|
|
36
|
+
languages: string[];
|
|
37
|
+
};
|
|
38
|
+
declare const DEFAULT_OPTIONS: ResolvedPlantUmlOptions;
|
|
39
|
+
/** Thrown for invalid plugin options so Docusaurus fails the build with a useful message. */
|
|
40
|
+
declare class PlantUmlOptionsError extends Error {
|
|
41
|
+
constructor(message: string);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Validates raw plugin options and applies defaults.
|
|
45
|
+
*
|
|
46
|
+
* Unknown keys are rejected rather than ignored: a typo in `docusaurus.config.ts` would
|
|
47
|
+
* otherwise silently disable the option the author meant to set.
|
|
48
|
+
*/
|
|
49
|
+
declare function resolveOptions(rawOptions: unknown): ResolvedPlantUmlOptions;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Identifiers shared by the Node-side plugin and the browser-side theme components.
|
|
53
|
+
*
|
|
54
|
+
* `PLUGIN_NAME` is the Docusaurus plugin name and therefore the key used for global data,
|
|
55
|
+
* so it must stay stable and identical on both sides of the SSR boundary. It is deliberately
|
|
56
|
+
* independent of the npm package name so that renaming the package cannot break global-data
|
|
57
|
+
* lookups in already-built sites.
|
|
58
|
+
*/
|
|
59
|
+
declare const PLUGIN_ID = "plantuml-client";
|
|
60
|
+
declare const PLUGIN_NAME = "docusaurus-plugin-plantuml-client";
|
|
61
|
+
|
|
62
|
+
/** Shape of the data this plugin publishes to the browser through Docusaurus global data. */
|
|
63
|
+
interface PlantUmlGlobalData {
|
|
64
|
+
options: ResolvedPlantUmlOptions;
|
|
65
|
+
/** `baseUrl`-relative directory holding `viz-global.js` and `plantuml.js`. */
|
|
66
|
+
assetsDir: string;
|
|
67
|
+
/** Installed `@plantuml/core` version; part of the cache key. */
|
|
68
|
+
coreVersion: string;
|
|
69
|
+
}
|
|
70
|
+
/** One copy pattern per runtime file, shared by the webpack and Rspack code paths. */
|
|
71
|
+
interface CopyPattern {
|
|
72
|
+
from: string;
|
|
73
|
+
to: string;
|
|
74
|
+
info: {
|
|
75
|
+
minimized: true;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Selects the copy plugin for the bundler in use.
|
|
80
|
+
*
|
|
81
|
+
* `currentBundler` only exists from Docusaurus 3.6, where Rspack support was added. On 3.5.x
|
|
82
|
+
* it is `undefined` and webpack is the only bundler, so an absent value is not an error.
|
|
83
|
+
*/
|
|
84
|
+
declare function createCopyPlugin(currentBundler: ConfigureWebpackUtils['currentBundler'] | undefined, patterns: CopyPattern[]): WebpackPluginInstance;
|
|
85
|
+
declare function plantumlPlugin(_context: LoadContext, options?: PlantUmlPluginOptions): Plugin<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Docusaurus option validation hook. Runs before the plugin function so configuration
|
|
88
|
+
* mistakes fail the build immediately with an actionable message.
|
|
89
|
+
*
|
|
90
|
+
* Docusaurus relies on the returned options carrying a plugin instance `id`; it normally
|
|
91
|
+
* comes from the Joi helper's default, so opting out of Joi means supplying it here.
|
|
92
|
+
*/
|
|
93
|
+
declare function validateOptions({ options, }: {
|
|
94
|
+
options: PlantUmlPluginOptions & Partial<PluginOptions>;
|
|
95
|
+
}): PlantUmlPluginOptions & PluginOptions;
|
|
96
|
+
|
|
97
|
+
export { type CacheMode, DEFAULT_OPTIONS, type DiagramTheme, PLUGIN_ID, PLUGIN_NAME, type PlantUmlGlobalData, PlantUmlOptionsError, type PlantUmlPluginOptions, type ResolvedPlantUmlOptions, createCopyPlugin, plantumlPlugin as default, resolveOptions, validateOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ConfigureWebpackUtils, LoadContext, Plugin, PluginOptions as DocusaurusPluginOptions } from '@docusaurus/types';
|
|
2
|
+
import type { WebpackPluginInstance } from 'webpack';
|
|
3
|
+
import { type PlantUmlPluginOptions, type ResolvedPlantUmlOptions } from './options.js';
|
|
4
|
+
export type { CacheMode, DiagramTheme, PlantUmlPluginOptions, ResolvedPlantUmlOptions, } from './options.js';
|
|
5
|
+
export { DEFAULT_OPTIONS, PlantUmlOptionsError, resolveOptions } from './options.js';
|
|
6
|
+
export { PLUGIN_ID, PLUGIN_NAME } from './constants.js';
|
|
7
|
+
/** Shape of the data this plugin publishes to the browser through Docusaurus global data. */
|
|
8
|
+
export interface PlantUmlGlobalData {
|
|
9
|
+
options: ResolvedPlantUmlOptions;
|
|
10
|
+
/** `baseUrl`-relative directory holding `viz-global.js` and `plantuml.js`. */
|
|
11
|
+
assetsDir: string;
|
|
12
|
+
/** Installed `@plantuml/core` version; part of the cache key. */
|
|
13
|
+
coreVersion: string;
|
|
14
|
+
}
|
|
15
|
+
/** One copy pattern per runtime file, shared by the webpack and Rspack code paths. */
|
|
16
|
+
interface CopyPattern {
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
info: {
|
|
20
|
+
minimized: true;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Selects the copy plugin for the bundler in use.
|
|
25
|
+
*
|
|
26
|
+
* `currentBundler` only exists from Docusaurus 3.6, where Rspack support was added. On 3.5.x
|
|
27
|
+
* it is `undefined` and webpack is the only bundler, so an absent value is not an error.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createCopyPlugin(currentBundler: ConfigureWebpackUtils['currentBundler'] | undefined, patterns: CopyPattern[]): WebpackPluginInstance;
|
|
30
|
+
export default function plantumlPlugin(_context: LoadContext, options?: PlantUmlPluginOptions): Plugin<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Docusaurus option validation hook. Runs before the plugin function so configuration
|
|
33
|
+
* mistakes fail the build immediately with an actionable message.
|
|
34
|
+
*
|
|
35
|
+
* Docusaurus relies on the returned options carrying a plugin instance `id`; it normally
|
|
36
|
+
* comes from the Joi helper's default, so opting out of Joi means supplying it here.
|
|
37
|
+
*/
|
|
38
|
+
export declare function validateOptions({ options, }: {
|
|
39
|
+
options: PlantUmlPluginOptions & Partial<DocusaurusPluginOptions>;
|
|
40
|
+
}): PlantUmlPluginOptions & DocusaurusPluginOptions;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
|
4
|
+
import { locatePlantUmlCore } from './assets.js';
|
|
5
|
+
import { assetsDirForVersion, DEFAULT_PLUGIN_ID, PLUGIN_NAME } from './constants.js';
|
|
6
|
+
import { resolveOptions, } from './options.js';
|
|
7
|
+
export { DEFAULT_OPTIONS, PlantUmlOptionsError, resolveOptions } from './options.js';
|
|
8
|
+
export { PLUGIN_ID, PLUGIN_NAME } from './constants.js';
|
|
9
|
+
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
/**
|
|
11
|
+
* Selects the copy plugin for the bundler in use.
|
|
12
|
+
*
|
|
13
|
+
* `currentBundler` only exists from Docusaurus 3.6, where Rspack support was added. On 3.5.x
|
|
14
|
+
* it is `undefined` and webpack is the only bundler, so an absent value is not an error.
|
|
15
|
+
*/
|
|
16
|
+
export function createCopyPlugin(currentBundler, patterns) {
|
|
17
|
+
if (currentBundler?.name === 'rspack') {
|
|
18
|
+
const { CopyRspackPlugin } = currentBundler.instance;
|
|
19
|
+
if (!CopyRspackPlugin) {
|
|
20
|
+
throw new Error(`[${PLUGIN_NAME}] The Rspack bundler is active but 'CopyRspackPlugin' is unavailable, ` +
|
|
21
|
+
'so the PlantUML runtime assets cannot be emitted. Upgrade @docusaurus/faster, or ' +
|
|
22
|
+
'disable `future.v4` to use the webpack bundler.');
|
|
23
|
+
}
|
|
24
|
+
return new CopyRspackPlugin({ patterns });
|
|
25
|
+
}
|
|
26
|
+
return new CopyWebpackPlugin({ patterns });
|
|
27
|
+
}
|
|
28
|
+
export default function plantumlPlugin(_context, options = {}) {
|
|
29
|
+
// Docusaurus already ran `validateOptions`, but the plugin function is also callable
|
|
30
|
+
// directly (and from JS configs that skip validation), so normalize defensively.
|
|
31
|
+
const resolved = resolveOptions(options);
|
|
32
|
+
const core = locatePlantUmlCore();
|
|
33
|
+
const assetsDir = assetsDirForVersion(core.version);
|
|
34
|
+
return {
|
|
35
|
+
name: PLUGIN_NAME,
|
|
36
|
+
getThemePath() {
|
|
37
|
+
return path.join(currentDir, 'theme');
|
|
38
|
+
},
|
|
39
|
+
contentLoaded({ actions }) {
|
|
40
|
+
const globalData = {
|
|
41
|
+
options: resolved,
|
|
42
|
+
assetsDir,
|
|
43
|
+
coreVersion: core.version,
|
|
44
|
+
};
|
|
45
|
+
actions.setGlobalData(globalData);
|
|
46
|
+
},
|
|
47
|
+
configureWebpack(_config, isServer, utils) {
|
|
48
|
+
// The PlantUML runtime is browser-only; emitting it from the server compilation
|
|
49
|
+
// would duplicate ~8 MB into the SSR bundle output for no benefit.
|
|
50
|
+
if (isServer) {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
const patterns = core.files.map((absolutePath) => ({
|
|
54
|
+
from: absolutePath,
|
|
55
|
+
to: `${assetsDir}/[name][ext]`,
|
|
56
|
+
// These files are already minified upstream; re-processing 8 MB is wasted work.
|
|
57
|
+
info: { minimized: true },
|
|
58
|
+
}));
|
|
59
|
+
// Optional chaining, not laziness: `currentBundler` is absent on Docusaurus 3.5.x.
|
|
60
|
+
return { plugins: [createCopyPlugin(utils?.currentBundler, patterns)] };
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Docusaurus option validation hook. Runs before the plugin function so configuration
|
|
66
|
+
* mistakes fail the build immediately with an actionable message.
|
|
67
|
+
*
|
|
68
|
+
* Docusaurus relies on the returned options carrying a plugin instance `id`; it normally
|
|
69
|
+
* comes from the Joi helper's default, so opting out of Joi means supplying it here.
|
|
70
|
+
*/
|
|
71
|
+
export function validateOptions({ options, }) {
|
|
72
|
+
resolveOptions(options);
|
|
73
|
+
return { ...options, id: options.id ?? DEFAULT_PLUGIN_ID };
|
|
74
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Cache backing store for rendered SVG output. */
|
|
2
|
+
export type CacheMode = 'none' | 'memory' | 'session';
|
|
3
|
+
/** Which PlantUML colour scheme to render. `auto` follows the Docusaurus colour mode. */
|
|
4
|
+
export type DiagramTheme = 'auto' | 'light' | 'dark';
|
|
5
|
+
/**
|
|
6
|
+
* Options accepted by the plugin in `docusaurus.config.*`.
|
|
7
|
+
*
|
|
8
|
+
* Every field is optional; see {@link DEFAULT_OPTIONS} for the defaults.
|
|
9
|
+
*/
|
|
10
|
+
export interface PlantUmlPluginOptions {
|
|
11
|
+
/** Fenced-code languages treated as PlantUML. Matched case-insensitively. */
|
|
12
|
+
languages?: string[];
|
|
13
|
+
/** Diagram colour scheme. `auto` follows the Docusaurus light/dark colour mode. */
|
|
14
|
+
theme?: DiagramTheme;
|
|
15
|
+
/** Render a diagram only once it scrolls near the viewport. */
|
|
16
|
+
lazy?: boolean;
|
|
17
|
+
/** Where to cache rendered SVG output. */
|
|
18
|
+
cache?: CacheMode;
|
|
19
|
+
/** Sanitize rendered SVG before inserting it into the page. Disable at your own risk. */
|
|
20
|
+
sanitizeSvg?: boolean;
|
|
21
|
+
/** Include the PlantUML source in a `<details>` block when rendering fails. */
|
|
22
|
+
showSourceOnError?: boolean;
|
|
23
|
+
/** Abort a single render after this many milliseconds. */
|
|
24
|
+
renderTimeoutMs?: number;
|
|
25
|
+
/** Maximum number of cached SVG entries kept per browsing session. */
|
|
26
|
+
cacheMaxEntries?: number;
|
|
27
|
+
/** Docusaurus plugin instance id, used when the plugin is registered more than once. */
|
|
28
|
+
id?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Plugin options after validation, with every default applied. */
|
|
31
|
+
export type ResolvedPlantUmlOptions = Required<Omit<PlantUmlPluginOptions, 'id' | 'languages'>> & {
|
|
32
|
+
/** Normalized to lower case; matching is case-insensitive. */
|
|
33
|
+
languages: string[];
|
|
34
|
+
};
|
|
35
|
+
export declare const DEFAULT_OPTIONS: ResolvedPlantUmlOptions;
|
|
36
|
+
/** Thrown for invalid plugin options so Docusaurus fails the build with a useful message. */
|
|
37
|
+
export declare class PlantUmlOptionsError extends Error {
|
|
38
|
+
constructor(message: string);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validates raw plugin options and applies defaults.
|
|
42
|
+
*
|
|
43
|
+
* Unknown keys are rejected rather than ignored: a typo in `docusaurus.config.ts` would
|
|
44
|
+
* otherwise silently disable the option the author meant to set.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveOptions(rawOptions: unknown): ResolvedPlantUmlOptions;
|