astro-mermaid 1.3.1 → 1.4.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 +7 -5
- package/astro-mermaid-integration.d.ts +7 -1
- package/astro-mermaid-integration.js +20 -14
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -100,17 +100,21 @@ export default defineConfig({
|
|
|
100
100
|
mermaid({
|
|
101
101
|
// Default theme: 'default', 'dark', 'forest', 'neutral', 'base'
|
|
102
102
|
theme: 'forest',
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
// Enable automatic theme switching based on data-theme attribute
|
|
105
105
|
autoTheme: true,
|
|
106
|
-
|
|
106
|
+
|
|
107
|
+
// Enable client-side logging (default: true). Set to false to suppress
|
|
108
|
+
// console.log output in the browser. Errors are always logged.
|
|
109
|
+
enableLog: false,
|
|
110
|
+
|
|
107
111
|
// Additional mermaid configuration
|
|
108
112
|
mermaidConfig: {
|
|
109
113
|
flowchart: {
|
|
110
114
|
curve: 'basis'
|
|
111
115
|
}
|
|
112
116
|
},
|
|
113
|
-
|
|
117
|
+
|
|
114
118
|
// Register icon packs for use in diagrams
|
|
115
119
|
iconPacks: [
|
|
116
120
|
{
|
|
@@ -218,8 +222,6 @@ All mermaid diagram types are supported:
|
|
|
218
222
|
|
|
219
223
|
## Version
|
|
220
224
|
|
|
221
|
-
**Current:** `v1.2.0` - Enhanced universal compatibility with dual plugin system
|
|
222
|
-
|
|
223
225
|
See [changelog](https://github.com/joesaby/astro-mermaid/releases) for version history.
|
|
224
226
|
|
|
225
227
|
## Contributing
|
|
@@ -24,7 +24,13 @@ export interface AstroMermaidOptions {
|
|
|
24
24
|
* @default true
|
|
25
25
|
*/
|
|
26
26
|
autoTheme?: boolean;
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Enable client-side logging
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
enableLog?: boolean;
|
|
33
|
+
|
|
28
34
|
/**
|
|
29
35
|
* Additional mermaid configuration options
|
|
30
36
|
* @see https://mermaid.js.org/config/setup/modules/mermaidAPI.html#mermaidapi-configuration-defaults
|
|
@@ -164,6 +164,7 @@ async function isElkInstalled(logger, consumerRoot) {
|
|
|
164
164
|
* @param {string} [options.theme='default'] - Default theme ('default', 'dark', 'forest', 'neutral')
|
|
165
165
|
* @param {boolean} [options.autoTheme=true] - Enable automatic theme switching based on data-theme attribute
|
|
166
166
|
* @param {Object} [options.mermaidConfig={}] - Additional mermaid configuration options
|
|
167
|
+
* @param {boolean} [options.enableLog=true] - Enable client-side logging
|
|
167
168
|
* @returns {import('astro').AstroIntegration}
|
|
168
169
|
*/
|
|
169
170
|
export default function astroMermaid(options = {}) {
|
|
@@ -171,7 +172,8 @@ export default function astroMermaid(options = {}) {
|
|
|
171
172
|
theme = 'default',
|
|
172
173
|
autoTheme = true,
|
|
173
174
|
mermaidConfig = {},
|
|
174
|
-
iconPacks = []
|
|
175
|
+
iconPacks = [],
|
|
176
|
+
enableLog = true
|
|
175
177
|
} = options;
|
|
176
178
|
|
|
177
179
|
return {
|
|
@@ -219,6 +221,10 @@ export default function astroMermaid(options = {}) {
|
|
|
219
221
|
|
|
220
222
|
// Inject client-side mermaid script with conditional loading
|
|
221
223
|
const mermaidScriptContent = `
|
|
224
|
+
// Logging helpers — controlled by enableLog option
|
|
225
|
+
const log = ${enableLog} ? (...args) => console.log('[astro-mermaid]', ...args) : () => {};
|
|
226
|
+
const logError = (...args) => console.error('[astro-mermaid]', ...args);
|
|
227
|
+
|
|
222
228
|
// Check if page has mermaid diagrams
|
|
223
229
|
const hasMermaidDiagrams = () => {
|
|
224
230
|
return document.querySelectorAll('pre.mermaid').length > 0;
|
|
@@ -231,13 +237,13 @@ let mermaidInstance = null;
|
|
|
231
237
|
async function loadMermaid() {
|
|
232
238
|
if (mermaidPromise) return mermaidPromise;
|
|
233
239
|
|
|
234
|
-
|
|
240
|
+
log('Loading mermaid.js...');
|
|
235
241
|
|
|
236
242
|
mermaidPromise = import('mermaid').then(async ({ default: mermaid }) => {
|
|
237
243
|
// Register icon packs if provided
|
|
238
244
|
const iconPacks = ${JSON.stringify(iconPacksConfig)};
|
|
239
245
|
if (iconPacks && iconPacks.length > 0) {
|
|
240
|
-
|
|
246
|
+
log('Registering', iconPacks.length, 'icon packs');
|
|
241
247
|
const packs = iconPacks.map(pack => ({
|
|
242
248
|
name: pack.name,
|
|
243
249
|
loader: new Function('return ' + pack.loader)()
|
|
@@ -249,7 +255,7 @@ async function loadMermaid() {
|
|
|
249
255
|
${useElk ? `
|
|
250
256
|
const elkModule = await import("@mermaid-js/layout-elk").catch(() => null);
|
|
251
257
|
if (elkModule?.default) {
|
|
252
|
-
|
|
258
|
+
log('Registering elk layouts');
|
|
253
259
|
mermaid.registerLayoutLoaders(elkModule.default);
|
|
254
260
|
}
|
|
255
261
|
` : ``}
|
|
@@ -257,7 +263,7 @@ if (elkModule?.default) {
|
|
|
257
263
|
mermaidInstance = mermaid;
|
|
258
264
|
return mermaid;
|
|
259
265
|
}).catch(error => {
|
|
260
|
-
|
|
266
|
+
logError('Failed to load mermaid:', error);
|
|
261
267
|
mermaidPromise = null;
|
|
262
268
|
throw error;
|
|
263
269
|
});
|
|
@@ -280,10 +286,10 @@ const themeMap = {
|
|
|
280
286
|
|
|
281
287
|
// Initialize all mermaid diagrams
|
|
282
288
|
async function initMermaid() {
|
|
283
|
-
|
|
289
|
+
log('Initializing mermaid diagrams...');
|
|
284
290
|
const diagrams = document.querySelectorAll('pre.mermaid');
|
|
285
291
|
|
|
286
|
-
|
|
292
|
+
log('Found', diagrams.length, 'mermaid diagrams');
|
|
287
293
|
|
|
288
294
|
if (diagrams.length === 0) {
|
|
289
295
|
return;
|
|
@@ -301,7 +307,7 @@ async function initMermaid() {
|
|
|
301
307
|
const bodyTheme = document.body.getAttribute('data-theme');
|
|
302
308
|
const dataTheme = htmlTheme || bodyTheme;
|
|
303
309
|
currentTheme = themeMap[dataTheme] || defaultConfig.theme;
|
|
304
|
-
|
|
310
|
+
log('Using theme:', currentTheme, 'from', htmlTheme ? 'html' : 'body');
|
|
305
311
|
}
|
|
306
312
|
|
|
307
313
|
// Configure mermaid with gitGraph support
|
|
@@ -329,7 +335,7 @@ async function initMermaid() {
|
|
|
329
335
|
const diagramDefinition = diagram.getAttribute('data-diagram') || '';
|
|
330
336
|
const id = 'mermaid-' + Math.random().toString(36).slice(2, 11);
|
|
331
337
|
|
|
332
|
-
|
|
338
|
+
log('Rendering diagram:', id);
|
|
333
339
|
|
|
334
340
|
try {
|
|
335
341
|
// Clear any existing error state
|
|
@@ -341,9 +347,9 @@ async function initMermaid() {
|
|
|
341
347
|
const { svg } = await mermaid.render(id, diagramDefinition);
|
|
342
348
|
diagram.innerHTML = svg;
|
|
343
349
|
diagram.setAttribute('data-processed', 'true');
|
|
344
|
-
|
|
350
|
+
log('Successfully rendered diagram:', id);
|
|
345
351
|
} catch (error) {
|
|
346
|
-
|
|
352
|
+
logError('Mermaid rendering error for diagram:', id, error);
|
|
347
353
|
diagram.innerHTML = \`<div style="color: red; padding: 1rem; border: 1px solid red; border-radius: 0.5rem;">
|
|
348
354
|
<strong>Error rendering diagram:</strong><br/>
|
|
349
355
|
\${error.message || 'Unknown error'}
|
|
@@ -355,10 +361,10 @@ async function initMermaid() {
|
|
|
355
361
|
|
|
356
362
|
// Initialize on first load if there are diagrams
|
|
357
363
|
if (hasMermaidDiagrams()) {
|
|
358
|
-
|
|
364
|
+
log('Mermaid diagrams detected on initial load');
|
|
359
365
|
initMermaid();
|
|
360
366
|
} else {
|
|
361
|
-
|
|
367
|
+
log('No mermaid diagrams found on initial load');
|
|
362
368
|
}
|
|
363
369
|
|
|
364
370
|
// Re-render on theme change if auto-theme is enabled
|
|
@@ -389,7 +395,7 @@ if (${autoTheme}) {
|
|
|
389
395
|
// Handle view transitions (for Astro View Transitions API)
|
|
390
396
|
// This is registered ALWAYS, not just when initial page has diagrams
|
|
391
397
|
document.addEventListener('astro:after-swap', () => {
|
|
392
|
-
|
|
398
|
+
log('View transition detected');
|
|
393
399
|
// Check if new page has diagrams
|
|
394
400
|
if (hasMermaidDiagrams()) {
|
|
395
401
|
initMermaid();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-mermaid",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "An Astro integration for rendering Mermaid diagrams with automatic theme switching and client-side rendering",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./astro-mermaid-integration.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@mermaid-js/layout-elk": "^0.2.0",
|
|
33
|
-
"astro": "
|
|
33
|
+
"astro": ">=4",
|
|
34
34
|
"mermaid": "^10.0.0 || ^11.0.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
@@ -70,4 +70,4 @@
|
|
|
70
70
|
"bugs": {
|
|
71
71
|
"url": "https://github.com/joesaby/astro-mermaid/issues"
|
|
72
72
|
}
|
|
73
|
-
}
|
|
73
|
+
}
|