-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
116 lines (113 loc) · 2.65 KB
/
utils.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
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
export function create_element_with_classes_and_attributes(
element_name,
properties
) {
var element = document.createElement(element_name);
if (properties?.class_list) {
for (const element_class of properties.class_list) {
element.classList.add(element_class);
}
}
if (properties?.attributes) {
for (const attribute in properties.attributes) {
element.setAttribute(attribute, properties.attributes[attribute]);
}
}
if (properties?.event_listener) {
for (const event_type in properties.event_listener) {
element.addEventListener(
event_type,
properties.event_listener[event_type]
);
}
}
if (properties?.innerHTML) {
element.innerHTML = properties.innerHTML;
}
if (properties?.text) {
element.text = properties.text;
}
return element;
}
export function replace_variables(text, variables) {
if (!variables || !text) {
return text;
}
var re = text;
for (const key in variables) {
re = re.replaceAll("${" + key + "}", variables[key]);
}
return re;
}
export function get_text_from_section(section, variables) {
let text = "";
if (section?.text_lines) {
text = section.text_lines.join("\n");
} else if (section?.text) {
text = section.text;
}
return replace_variables(text, variables);
}
export const tools_files = {
files: ["LICENSE"],
folders: {
editor: {
files: [
"base64-js.mjs",
"bootstrap.min.css",
"code.js",
"cytoscape.esm.min.js",
"cytoscape-klay.mjs",
"favicon.png",
"index.html",
"jszip.mjs",
"node_events.js",
"README.md",
"toast.js",
"bootstrap.bundle.min.js",
"buffer.mjs",
"common.js",
"cytoscape-klay.js",
"favicon.ico",
"ieee754.mjs",
"jszip.js",
"klayjs.mjs",
"node_process.js",
"style.css",
"utils.js",
],
},
viewer: {
folders: {
"bootstrap-icons-font": {
folders: {
fonts: {
files: ["bootstrap-icons.woff", "bootstrap-icons.woff2"],
},
},
files: [
"bootstrap-icons.css",
"bootstrap-icons.json",
"bootstrap-icons.min.css",
"bootstrap-icons.scss",
],
},
},
files: [
"bootstrap.bundle.min.js",
"bootstrap.min.css",
"code.js",
"common.js",
"favicon.ico",
"favicon.png",
"index.html",
"marked.esm.js",
"purify.es.mjs",
"README.md",
"style.css",
"toast.js",
"utils.js",
],
},
},
};