@p10node/mermaid 0.0.0-stage → 0.9.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 p10node
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # @p10node/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
+ Mermaid text → SVG. No DOM needed (browser, Web Worker, Node, Bun), no server, no dependency.
4
+
5
+ Part of [office-engine](https://github.com/p10node/office-engine). All languages in one package, and drawing the diagram blocks of a page: [`@p10node/diagram`](../diagram).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm i @p10node/mermaid
11
+ ```
12
+
13
+ ## Use
14
+
15
+ ```ts
16
+ import { render, renderTo, toPng } from '@p10node/mermaid'
17
+
18
+ const { svg, width, height } = render('graph LR\n A[Write] --> B[Draw]')
19
+ renderTo(document.getElementById('out')!, text) // into an element (browser)
20
+ const png = await toPng(svg, 2) // PNG Blob, 2× size (browser)
21
+ ```
22
+
23
+ `render` returns `{ svg, width, height }` (CSS pixels); a source that cannot be drawn throws a `DiagramError` with the reason.
24
+
25
+ From a CDN, no build step:
26
+
27
+ ```html
28
+ <div id="out"></div>
29
+ <script type="module">
30
+ import { renderTo } from 'https://cdn.jsdelivr.net/npm/@p10node/mermaid/dist/index.js'
31
+ renderTo(document.getElementById('out'), 'graph LR\n A[Write] --> B[Draw]')
32
+ </script>
33
+ ```
34
+
35
+ ## What is drawn
36
+
37
+ flowchart / graph (subgraphs, `classDef`, `style`, `linkStyle`), sequence (activations, notes, loop / alt / opt / par / critical / break / rect), class, state (composite states, fork / join / choice), ER (crow's foot), pie, Gantt, mind map.
38
+
39
+ Laid out by a built-in layered layout, so drawings look close to, not exactly like, the original tool's. Not drawn yet: git graph, journey, timeline, quadrant, requirement, C4, Sankey, XY chart, block, packet, kanban, architecture.
40
+
41
+ The SVG has a fixed `width` / `height`; to fit a column: `svg { max-width: 100%; height: auto; }`.
42
+
43
+ ## Safety
44
+
45
+ Text from the source is escaped; only plain colors are kept; the SVG has no scripts, links, `<foreignObject>` or external references.
46
+
47
+ ## License
48
+
49
+ MIT
@@ -0,0 +1,16 @@
1
+ /** A drawing: a self-contained SVG document and its size in CSS pixels. */
2
+ export interface Diagram {
3
+ svg: string;
4
+ width: number;
5
+ height: number;
6
+ }
7
+ /** The source cannot be drawn (unsupported diagram kind, syntax the reader does not follow). */
8
+ export declare class DiagramError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ /** The drawing of a source. */
12
+ export declare function render(source: string): Diagram;
13
+ /** Draws a source into an element (its content is replaced). */
14
+ export declare function renderTo(target: Element, source: string): Diagram;
15
+ /** A PNG of a drawing's SVG, `scale` times its size. Browser only. */
16
+ export declare function toPng(svg: string, scale?: number): Promise<Blob>;