@vmz/plugin-mermaid 0.0.0 → 0.0.2

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,39 @@
1
1
  # @vmz/plugin-mermaid
2
2
 
3
- Placeholder package (0.0.0). Reserved for the VMZ project.
3
+ ## Keep architecture and process diagrams close to the text 📊
4
+
5
+ `@vmz/plugin-mermaid` brings Mermaid diagrams to VMZ documents and applications. It is useful when architecture, flows,
6
+ sequences, and state transitions should evolve in the same reviewable source workflow as the text that explains them.
7
+
8
+ ## Why text-authored diagrams matter
9
+
10
+ For engineering and product documentation, a diagram is often part of the argument rather than decoration. Keeping its
11
+ source beside the surrounding document makes changes searchable, reviewable, localizable, and testable. It also lets a
12
+ VMZ project treat diagrams as content with known delivery and rendering boundaries.
13
+
14
+ Mermaid is especially appropriate when clarity and maintainability matter more than hand-crafted illustration. For
15
+ highly custom data visualization or brand artwork, use the rendering technology that best fits that job instead of
16
+ forcing everything through a text diagram language.
17
+
18
+ Great uses include:
19
+
20
+ - architecture and dependency maps;
21
+ - user and system flows;
22
+ - state and lifecycle diagrams;
23
+ - sequence diagrams that change with the design.
24
+
25
+ ## VMZ boundary
26
+
27
+ VMZ keeps the page readable on the server and can defer client-side diagram work to the point where it is useful.
28
+ Mermaid adds diagram capability; it does not redefine VMZ document, routing, state, or SSR semantics.
29
+
30
+ ## Why teams keep diagrams in text
31
+
32
+ | Pain | Text-authored result |
33
+ |---|---|
34
+ | A renamed service leaves an exported image stale | The diagram changes in the same review as the prose |
35
+ | Localization requires separate image editing | Labels remain part of the content workflow |
36
+ | Architecture history is hard to inspect | Version control shows structural changes |
37
+ | A document is rendered in several targets | The same source can be transformed consistently |
38
+
39
+ Mermaid will not replace bespoke product visualization, but it is unusually effective for diagrams whose job is to explain rather than impress. That makes it a natural companion for VMZ documents. 📚
@@ -0,0 +1,24 @@
1
+ <template>
2
+ <div class="mermaid-host" html={html != null ? html : fallback(source)}></div>
3
+ </template>
4
+
5
+ <script client>
6
+ import { renderMermaid, renderMermaidFallback } from '@vmz/plugin-mermaid/runtime';
7
+
8
+ function fallback(source) {
9
+ return renderMermaidFallback(source);
10
+ }
11
+
12
+ export default class Mermaid {
13
+ public source: string = '';
14
+ html: string | null = null;
15
+
16
+ async onMount() {
17
+ try {
18
+ this.html = await renderMermaid(this.source, 'vmz-mmd-' + Math.random().toString(36).slice(2));
19
+ } catch {
20
+ this.html = renderMermaidFallback(this.source);
21
+ }
22
+ }
23
+ }
24
+ </script>
package/package.json CHANGED
@@ -1,10 +1,38 @@
1
1
  {
2
2
  "name": "@vmz/plugin-mermaid",
3
- "version": "0.0.0",
4
- "description": "VMZ placeholder — not for production use.",
3
+ "version": "0.0.2",
4
+ "type": "module",
5
+ "description": "VMZ Mermaid diagram adapter - <Mermaid>",
5
6
  "license": "MIT",
6
- "private": false,
7
- "files": [
8
- "README.md"
9
- ]
7
+ "main": "./vmz.plugin.ts",
8
+ "types": "./vmz.plugin.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./vmz.plugin.ts",
12
+ "default": "./vmz.plugin.ts"
13
+ },
14
+ "./runtime": {
15
+ "types": "./runtime.ts",
16
+ "default": "./runtime.ts"
17
+ }
18
+ },
19
+ "dependencies": {
20
+ "@vmz/plugin": "0.0.2"
21
+ },
22
+ "peerDependencies": {
23
+ "mermaid": ">=11"
24
+ },
25
+ "keywords": [
26
+ "vmz",
27
+ "plugin",
28
+ "mermaid",
29
+ "diagram"
30
+ ],
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/doki-land/vmz-framework.git"
37
+ }
10
38
  }
package/runtime.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { Mermaid } from 'mermaid';
2
+
3
+ let mermaid: Mermaid | null = null;
4
+
5
+ async function getMermaid(): Promise<Mermaid> {
6
+ if (mermaid) return mermaid;
7
+ const mod = await import('mermaid');
8
+ mermaid = (mod.default ?? mod) as Mermaid;
9
+ mermaid.initialize({ startOnLoad: false, securityLevel: 'strict' });
10
+ return mermaid;
11
+ }
12
+
13
+ /** Render Mermaid source to SVG HTML. */
14
+ export async function renderMermaid(source: string, id = 'vmz-mmd'): Promise<string> {
15
+ const m = await getMermaid();
16
+ const { svg } = await m.render(id.replace(/[^a-zA-Z0-9_-]/g, '_'), source ?? '');
17
+ return svg;
18
+ }
19
+
20
+ /** Sync fallback when not yet loaded. */
21
+ export function renderMermaidFallback(source: string): string {
22
+ const escaped = String(source ?? '')
23
+ .replace(/&/g, '&amp;')
24
+ .replace(/</g, '&lt;')
25
+ .replace(/>/g, '&gt;');
26
+ return `<pre class="mermaid-fallback">${escaped}</pre>`;
27
+ }
package/vmz.plugin.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { definePlugin, loadPluginSource } from '@vmz/plugin';
2
+
3
+ const source = loadPluginSource(import.meta.url, 'components/Mermaid.vmz');
4
+
5
+ export default definePlugin({
6
+ name: '@vmz/plugin-mermaid',
7
+ version: '0.1.0',
8
+ protocol: '0.1.0',
9
+ stages: ['workspace_resolve', 'analyzer'],
10
+ deterministic: true,
11
+ async contribute(ctx) {
12
+ if (ctx.stage === 'workspace_resolve') {
13
+ return {
14
+ stage: 'workspace_resolve',
15
+ cacheKey: `@vmz/plugin-mermaid:Mermaid.vmz:${source.contentHash.slice(0, 12)}`,
16
+ items: [
17
+ {
18
+ id: 'component-mermaid',
19
+ kind: 'source',
20
+ path: 'src/components/Mermaid.vmz',
21
+ content: source.content,
22
+ contentHash: source.contentHash,
23
+ materialize: true,
24
+ },
25
+ ],
26
+ };
27
+ }
28
+ if (ctx.stage === 'analyzer') {
29
+ return {
30
+ stage: 'analyzer',
31
+ cacheKey: '@vmz/plugin-mermaid:analyzer',
32
+ items: [
33
+ {
34
+ id: 'component-mermaid-online',
35
+ kind: 'analyzer',
36
+ path: 'src/components/Mermaid.vmz',
37
+ severity: 'advice',
38
+ message: 'Mermaid component online',
39
+ code: 'vmz.plugin.mermaid',
40
+ },
41
+ ],
42
+ };
43
+ }
44
+ return { stage: ctx.stage, items: [] };
45
+ },
46
+ });