@zenuml/core 3.32.7 → 3.33.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
@@ -19,7 +19,7 @@ You can use it ZenUML on your favorite platforms and applications:
19
19
  # Integrations
20
20
 
21
21
  ZenUML can be integrated with your favorite tools and platforms as a library or an embeddable widget.
22
- Please follow the [integration guide](./docs/asciidoc/integration-guide.adoc) for detailed steps.
22
+ Please follow the [integration tutorial](./TUTORIAL.md) for detailed steps.
23
23
 
24
24
  # Development
25
25
 
package/TUTORIAL.md ADDED
@@ -0,0 +1,116 @@
1
+
2
+ # ZenUML Integration Tutorial
3
+
4
+ This tutorial provides a comprehensive guide on how to integrate ZenUML into your applications. There are two primary methods for integration: as a library or as an embedded iframe.
5
+
6
+ ## 1. As a Library
7
+
8
+ This is the most flexible method, allowing for deep integration with your application.
9
+
10
+ ### Installation
11
+
12
+ First, add the `@zenuml/core` package to your project:
13
+
14
+ ```bash
15
+ npm install @zenuml/core
16
+ ```
17
+
18
+ or
19
+
20
+ ```bash
21
+ yarn add @zenuml/core
22
+ ```
23
+
24
+ ### Usage
25
+
26
+ The main entry point of the library is the `ZenUml` class. Here's a basic example of how to use it:
27
+
28
+ ```javascript
29
+ import ZenUml from '@zenuml/core';
30
+
31
+ // 1. Get the container element
32
+ const el = document.getElementById('zenuml-container');
33
+
34
+ // 2. Create a new instance of ZenUml
35
+ const zenUml = new ZenUml(el);
36
+
37
+ // 3. Render a diagram
38
+ const code = 'A->B: message';
39
+ const config = {
40
+ theme: 'default',
41
+ };
42
+ zenUml.render(code, config);
43
+ ```
44
+
45
+ ### Configuration
46
+
47
+ The `render` method accepts a configuration object with the following properties:
48
+
49
+ - `theme`: The name of the theme to use. A list of available themes can be found in the documentation.
50
+ - `enableScopedTheming`: A boolean that indicates whether to scope the theme to the container element. This is useful when you have multiple diagrams on the same page with different themes.
51
+ - `onThemeChange`: A callback function that is called when the theme is changed.
52
+ - `enableMultiTheme`: A boolean that indicates whether to enable multi-theme support.
53
+ - `stickyOffset`: A number that indicates the offset for the sticky header.
54
+ - `onContentChange`: A callback function that is called when the content of the diagram is changed.
55
+ - `onEventEmit`: A callback function that is called when an event is emitted from the diagram.
56
+ - `mode`: The rendering mode. Can be `RenderMode.Dynamic` or `RenderMode.Static`.
57
+
58
+ ### Example
59
+
60
+ Here's a more advanced example that uses some of the configuration options:
61
+
62
+ ```javascript
63
+ import ZenUml from '@zenuml/core';
64
+
65
+ const el = document.getElementById('zenuml-container');
66
+ const zenUml = new ZenUml(el);
67
+
68
+ const code = `
69
+ // This is a comment
70
+ A->B: synchronous message
71
+ B-->A: asynchronous message
72
+ `;
73
+
74
+ const config = {
75
+ theme: 'blue',
76
+ enableScopedTheming: true,
77
+ onContentChange: (newCode) => {
78
+ console.log('Diagram code changed:', newCode);
79
+ },
80
+ };
81
+
82
+ zenUml.render(code, config);
83
+ ```
84
+
85
+ ### Exporting Diagrams
86
+
87
+ You can export diagrams to PNG and SVG formats. The `ZenUml` class provides the following methods for exporting:
88
+
89
+ - `getPng()`: Returns a promise that resolves to a PNG data URL.
90
+ - `getSvg()`: Returns a promise that resolves to an SVG data URL.
91
+
92
+ Here's an example of how to use these methods:
93
+
94
+ ```javascript
95
+ import ZenUml from '@zenuml/core';
96
+
97
+ const el = document.getElementById('zenuml-container');
98
+ const zenUml = new ZenUml(el);
99
+
100
+ const code = 'A->B: message';
101
+
102
+ async function exportDiagram() {
103
+ await zenUml.render(code, { theme: 'default' });
104
+ const png = await zenUml.getPng();
105
+ // Do something with the PNG data URL
106
+ console.log(png);
107
+
108
+ const svg = await zenUml.getSvg();
109
+ // Do something with the SVG data URL
110
+ console.log(svg);
111
+ }
112
+
113
+ exportDiagram();
114
+ ```
115
+
116
+ This tutorial should provide you with a solid foundation for integrating ZenUML into your applications. For more detailed information, please refer to the official documentation.