-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
206 lines (200 loc) · 7.07 KB
/
index.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<html>
<head>
<meta charset="utf-8">
<style>
h1, h2 {
text-align: center;
}
.container-area {
margin: 0px auto;
width: 1425px;
}
.diff-area {
width: 700px;
height: 600px;
display: inline-block;
position: relative;
}
.area-wrapper {
width: 700px;
max-height: 600px;
min-height: 450px;
overflow: hidden;
border-radius: 10px;
border: 1px solid #999;
display: inline-block;
margin: 0px 5px;
}
.operation-container {
margin: 10px auto 15px;
width: 900px;
}
.decoration-header {
color: #aa00bb !important;
}
.decoration-delete {
color: #dd4444 !important;
}
.decoration-add {
color: #229922 !important;
}
.decoration-delete-background {
background-color: #ffebe9
}
.decoration-add-background {
background-color: #e6ffec
}
.diff-placeholder {
_display: none;
position: absolute;
top: 0;
left: 65px;
pointer-events: none;
z-index: 1;
opacity: 0.7;
font-size: 14px;
}
#search_depth_input {
width: 40px;
}
#unified_input {
width: 40px;
}
#step_chart, #position_chart {
width: 700px;
height: 450px;
display: inline-block;
}
.diff-result {
display: inline-block;
width: 700px;
height: 450px;
}
</style>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="min/myers.min.js"></script>
<script src="min/diffchart.min.js"></script>
<script src="min/diffeditor.min.js"></script>
<script src="https://cdn.staticfile.net/echarts/5.4.3/echarts.common.min.js"></script>
<script src="https://cdn.staticfile.net/monaco-editor/0.45.0/min/vs/loader.min.js"></script>
<script src="js/require.js" async="true"></script>
<script>
require.config({ paths: { 'vs': 'https://cdn.staticfile.net/monaco-editor/0.45.0/min/vs' }});
window.onload = () => {
let findAllStepsSel = document.getElementById('find_all_steps_sel');
let searchDepthInput = document.getElementById('search_depth_input');
let unifiedInput = document.getElementById('unified_input');
let editors = {};
require(['vs/editor/editor.main'], function() {
editors['srcEditor'] = new TextEditor(monaco, document.getElementById('src_txt'), {fontSize: '14px'});
editors['dstEditor'] = new TextEditor(monaco, document.getElementById('dst_txt'), {fontSize: '14px'});
editors['diffEditor'] = new DiffEditor(monaco, document.getElementById('diff_result'));
editors['diffBlockEditor'] = new DiffBlockEditor(monaco, document.getElementById('formatted_diff_result'));
document.getElementById('compare_btn').disabled = false;
});
let positionChart = new PositionChart(echarts, document.getElementById('position_chart'));
let stepChart = new StepChart(echarts, document.getElementById('step_chart'), (params, diff) => {
if (params.componentType == 'series') {
let [d, k] = params.data;
editors['diffEditor'].refresh(diff.getEdits({d, k}));
editors['diffBlockEditor'].refresh(diff.getStandardDiff({d, k}));
positionChart.refresh(diff.getPositions({d, k}), diff.calShortcutLines());
}
});
const languageSelector = document.getElementById('language_sel');
languageSelector.onchange = ev => {
const language = languageSelector.value;
editors.srcEditor.changeLanguage(language);
editors.dstEditor.changeLanguage(language);
editors.diffEditor.changeLanguage(language);
}
document.getElementById('compare_btn').onclick = ev => {
let srcText = editors.srcEditor.getValue();
let dstText = editors.dstEditor.getValue();
let findAllSteps = findAllStepsSel.value === 'true';
let diff = new MyersDiff({
srcLines: srcText.split(/\r|\n/),
dstLines: dstText.split(/\r|\n/),
findAllSteps,
maxSearchDepth: searchDepthInput.value
});
diff.calDiff();
if (diff.getEdits().length == 0) {
alert('文本内容无差异');
return;
}
for (let wrapper of document.getElementsByClassName('area-wrapper')) {
wrapper.style.visibility = 'visible';
}
document.getElementById('outside_area').style.overflowY = 'visible';
stepChart.refresh(diff);
editors['diffEditor'].refresh(diff.getEdits());
editors['diffBlockEditor'].refresh(diff.getStandardDiff(null, unifiedInput.value));
positionChart.refresh(diff.getBestPositions(), diff.calShortcutLines());
};
}
</script>
</head>
<body>
<div id="outside_area" style="height: 850px; overflow-y: hidden;">
<div style="margin: 15px;">
<h2>基于Myers算法的文本比对工具</h2>
</div>
<div class="container-area">
<div class="area-wrapper">
<div id="src_txt" class="diff-area">
<div class="diff-placeholder">请输入待对比的源文本内容</div>
</div>
</div>
<div class="area-wrapper">
<div id="dst_txt" class="diff-area">
<div class="diff-placeholder">请输入待对比的目标文本内容</div>
</div>
</div>
</div>
<div class="operation-container">
选择语言
<select id="language_sel" class="form-control-sm" style="width: 100px;">
<option value="">无</option>
<option>json</option>
<option>java</option>
<option>javascript</option>
<option>sql</option>
<option>shell</option>
<option>xml</option>
</select>
/
计算所有路径
<select id="find_all_steps_sel" class="form-control-sm" style="width: 60px;">
<option value="true">是</option>
<option value="false" selected>否</option>
</select>
/
搜索深度(d)
<input id="search_depth_input" type="number" class="form-control-sm" style="width: 100px; border-width: 1px;" value="3000"/>
/
关联上下文(U)
<input id="unified_input" type="number" class="form-control-sm" style="width: 100px; border-width: 1px;" value="3"/>
/
<button id="compare_btn" type="button" class="btn btn-primary btn-sm" disabled>对比</button>
</div>
<div class="container-area">
<div class="area-wrapper" style="visibility: hidden;">
<div id="diff_result" class="diff-result"></div>
</div>
<div class="area-wrapper" style="visibility: hidden;">
<div id="formatted_diff_result" class="diff-result"></div>
</div>
</div>
<div class="container-area">
<div class="area-wrapper" style="visibility: hidden;">
<div id="step_chart"></div>
</div>
<div class="area-wrapper" style="visibility: hidden;">
<div id="position_chart"></div>
</div>
</div>
<div style="height: 30px;"></div>
</div>
</body>
</html>