forked from matheusgr/modeligado
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodeligado.js
84 lines (71 loc) · 2.17 KB
/
modeligado.js
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
import {Parser} from './parser.js'
import {process} from './convert.js'
function difference(setA, setB) {
let _difference = new Set(setA)
for (let elem of setB) {
_difference.delete(elem)
}
return _difference
}
function parse(text, nodeName, linkData) {
let result = new Parser().parse(text)
let relates = new Set()
let classes = new Set()
for (let node of result) {
for (let relatedClass of node.relates) {
relates.add(relatedClass)
}
classes.add(node.context.name)
nodeName.push(node.context)
linkData.push(...node.relations)
}
let missingClasses = []
for (let missingClass of difference(relates, classes)) {
missingClasses.push({"name": missingClass, "key": missingClass})
}
return missingClasses
}
function _saveAs(blob, filename) {
var url = window.URL.createObjectURL(blob);
var a = document.createElement("a");
a.style = "display: none";
a.href = url;
a.download = filename;
// IE 11
if (window.navigator.msSaveBlob !== undefined) {
window.navigator.msSaveBlob(blob, filename);
return;
}
document.body.appendChild(a);
requestAnimationFrame(function() {
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
});
}
// https://gojs.net/latest/samples/minimalBlob.html
function exportPng(myDiagram, filename) {
myDiagram.makeImageData({ size: myDiagram.documentBounds, background: "white", returnType: "blob", callback: (blob) => {
_saveAs(blob, filename)
} })
}
function exportTxt(text, filename) {
_saveAs(new Blob([text], {
type: 'text/plain'
}), filename)
}
function exportJava(umlText, filename) {
let zip = new JSZip();
let folder = zip.folder("app")
let result = process(new Parser().parse(umlText), "app")
Object.keys(result).forEach(function(key) {
let filename = key
let code = result[key]
folder.file(filename + ".java", code)
});
zip.generateAsync({type:"blob"})
.then(function(content) {
_saveAs(content, filename);
});
}
export {parse, exportPng, exportTxt, exportJava}