-
Notifications
You must be signed in to change notification settings - Fork 38
/
skeleton.html
185 lines (143 loc) · 4 KB
/
skeleton.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Diagram Viewer</title>
<!-- bpmn-js script is injected via loadScript -->
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
html, body, #canvas {
height: 100%;
padding: 0;
margin: 0;
}
.footer {
position: absolute;
bottom: 15px;
left: 15px;
}
#title {
font-size: .85em;
color: #AAA;
font-weight: normal;
padding: 5px 0;
margin: 0;
}
</style>
</head>
<body>
<div id="canvas"></div>
<div class="footer">
<h4 id="title"></h4>
</div>
<script>
// viewer instance, lazily initialized
let bpmnViewer;
/**
* Get or create viewer instance.
*
* @return {BpmnViewer}
*/
function getViewer() {
if (bpmnViewer) {
return bpmnViewer;
}
bpmnViewer = new BpmnJS({
container: '#canvas'
});
bpmnViewer.on('import.done', function(event) {
const error = event.error;
const warnings = event.warnings;
if (error) {
return console.error('could not import BPMN 2.0 diagram', error);
}
// zoom to fit full viewport
bpmnViewer.get('canvas').zoom('fit-viewport');
});
return bpmnViewer;
}
/**
* Open diagram in our viewer instance.
*
* @param {String} bpmnXML diagram to display
* @param {Object} [options]
* @param {Dimensions} [options.minDimensions]
*
* @return {Promise<Bounds, Error>}
*/
async function openDiagram(bpmnXML, options) {
// viewer instance, lazily initialized
const bpmnViewer = getViewer();
options = options || {};
const minDimensions = options.minDimensions || {
width: 0,
height: 0
};
const title = options.title;
const footer = options.footer;
await bpmnViewer.importXML(bpmnXML);
const viewbox = bpmnViewer.get('canvas').viewbox();
// uses provided title
const titleNode = document.querySelector('#title');
if (title) {
titleNode.textContent = title;
}
titleNode.style.display = title ? 'block' : 'none';
const width = Math.max(viewbox.inner.width, minDimensions.width);
const diagramHeight = Math.max(
viewbox.inner.height + (footer ? 90 : 0),
minDimensions.height
);
return {
width,
height: diagramHeight + (footer ? 0 : 90),
diagramHeight
};
}
/**
* Resize to viewport
*/
async function resize() {
const bpmnViewer = getViewer();
const canvas = bpmnViewer.get('canvas');
canvas.resized();
canvas.zoom('fit-viewport');
}
async function toSVG() {
const bpmnViewer = getViewer();
const {
svg
} = await bpmnViewer.saveSVG();
return svg;
}
/**
* Load the script that provides the BpmnJS global
*
* @param {String} src
*
* @return {Promise<Void>}
*/
function loadScript(src) {
const head = document.head;
const script = document.createElement('script');
script.type = 'text/javascript';
script.charset = 'utf8';
script.src = src;
const promise = new Promise((resolve, reject) => {
function callback(fn) {
return (arg) => {
script.onload = script.onerror = null;
return fn(arg);
};
}
script.onload = callback(resolve);
script.onerror = callback(reject);
});
head.appendChild(script);
return promise;
}
</script>
</body>
</html>