-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.html
More file actions
266 lines (234 loc) · 10.7 KB
/
test.html
File metadata and controls
266 lines (234 loc) · 10.7 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MarkerHighlighter Test</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 50px;
line-height: 2;
font-size: 18px;
}
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
border: 1px solid #ddd;
padding: 8px;
color: #777;
font-weight: 200;
}
th {
background-color: #f2f2f2;
text-align: left;
}
.text-to-highlight {
position: relative;
}
.highlight {
position: absolute;
overflow: hidden;
z-index: -1;
background-color: transparent;
}
.timer {
font-size: 16px;
color: #666;
}
mark {
font-weight: bold;
color: #222;
}
.mark1 {
background-color: #ff8888;
}
.mark2 {
background-color: #99ffaa;
}
.mark3 {
background-color: #55ffff;
}
.mark4 {
background-color: #ff55ff;
}
.mark5 {
background-color: #ffff55;
}
</style>
<script type="module">
import { MarkerHighlighter } from "./dist/index.js";
document.addEventListener('DOMContentLoaded', () => {
const testCases = [
{
attributes: [
{ drawingMode: 'burst', animationSpeed: 4200 },
{ drawingMode: 'burst', animationSpeed: 500 },
{ drawingMode: 'burst', animationSpeed: 1400 }
],
text: 'Lorem ipsum <mark class="mark1">dolor sit</mark> amet, consectetur <mark class="mark2">adipiscing elitadipiscing elitadipiscing elitadipiscing elitadipiscing elitadipiscing elitadipiscing elit</mark>. Integer nec odio. <mark class="mark3">Praesent libero</mark>.'
},
{
attributes: [
{ height: 2, drawingMode: 'circle', animationSpeed: 1000, circle: { curve: .25 } },
{ height: 2, drawingMode: 'circle', animationSpeed: 500, circle: { curve: 0.5 } },
{ height: 2, drawingMode: 'circle', animationSpeed: 1400, circle: { curve: 1 } }
],
text: 'Lorem ipsum <mark class="mark1">dolor sit</mark> amet, consectetur <mark class="mark2">adipiscing elitadipiscing elitadipiscing elitadipiscing elitadipiscing elitadipiscing elitadipiscing elit</mark>. Integer nec odio. <mark class="mark3">Praesent libero</mark>.'
},
{
attributes: [
{ animationSpeed: 1000, wavelength: 10, amplitude: 5 },
{ animationSpeed: 1200, wavelength: 1, amplitude: 15 },
{ animationSpeed: 1400, wavelength: 5, amplitude: 1 }
],
text: 'Lorem ipsum <mark class="mark1">dolor sit</mark> amet, consectetur <mark class="mark2">adipiscing elitadipiscing elitadipiscing elitadipiscing elitadipiscing elitadipiscing elitadipiscing elit</mark>. Integer nec odio. <mark class="mark3">Praesent libero</mark>.'
},
{
attributes: [
{ easing: 'ease-in', markerDelay: 0 },
{ easing: 'ease-out', markerDelay: 100 },
{ easing: 'linear', markerDelay: 1500 }
],
text: 'Sed cursus <mark class="mark1">ante dapibus</mark> diam. Sed nisi. <mark class="mark2">Nulla quis</mark> sem at nibh elementum <mark class="mark3">imperdiet.</mark>'
},
{
attributes: [
{ height: 1, offset: 0 },
{ height: 1.0, offset: .75 },
{ height: 2.75, offset: 0 },
{ height: 2.75, offset: 2.75 },
{ height: 0.5, offset: -1 }
],
text: 'Duis sagittis ipsum. <mark class="mark1">Praesent</mark> mauris. <mark class="mark2">Fusce nec</mark> tellus sed <mark class="mark3">augue semper</mark> porta <mark class="mark4">augue semper</mark> Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet blah blah blah blah <mark class="mark5">Praesent</mark>.'
},
{
attributes: [
{ animationSpeed: 2000, wavelength: 5, amplitude: 2, multilineDelay: 0.5 }
],
text: 'Lorem ipsum dolor sit amet, <mark class="mark1">consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta</mark>. Mauris massa.'
},
{
attributes: [
{ animationSpeed: 1000, animate: true },
{ animationSpeed: 1000, animate: false },
],
text: 'Lorem ipsum dolor sit amet, <mark class="mark1">consectetur adipiscing elit. Integer</mark> nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. <mark class="mark2">Praesent mauris. Fusce nec tellus sed augue semper porta</mark>. Mauris massa.'
}
];
const tableBody = document.querySelector('#test-cases');
testCases.forEach((testCase, index) => {
const row = document.createElement('tr');
row.classList.add('marker-container');
const attributesCell = document.createElement('td');
const resultCell = document.createElement('td');
const marksHtml = testCase.text;
resultCell.innerHTML = marksHtml;
const timer = document.createElement('div');
timer.classList.add('timer');
const attributeTable = document.createElement('table');
attributeTable.innerHTML = `
<tr>
<th>Color</th>
${Object.keys(testCase.attributes[0]).map(attr => `<th>${attr}</th>`).join('')}
</tr>
${testCase.attributes.map((attr, idx) => `
<tr>
<td class="mark${idx + 1}" style="width: 20px;"></td>
${Object.values(attr).map(value => `<td>${value}</td>`).join('')}
</tr>
`).join('')}
`;
attributesCell.appendChild(attributeTable);
row.appendChild(attributesCell);
row.appendChild(resultCell);
tableBody.appendChild(row);
const toKebabCase = (str) => str.replace(/([A-Z])/g, '-$1').toLowerCase();
testCase.attributes.forEach((attr, idx) => {
const markElement = resultCell.querySelector(`.mark${idx + 1}`);
Object.keys(attr).forEach(key => {
markElement.setAttribute(`data-${toKebabCase(key)}`, attr[key]);
});
});
const highlighter = new MarkerHighlighter(resultCell, {
//selector: 'mark',
drawingMode: 'highlight',
animate: true,
animationSpeed: 500,
padding: 1,
//animateSequentially: true,
//highlightDelay: 0.2,
height: 1,
offset: 0,
//brushStroke: 0.1,
//variation: 1,
//lineFade: .1,
//markerFade: 1,
//drawMode: 'highlight',
horizontalPadding: {
strength: .1,
variation: .1,
rough: 2,
},
highlight: {
wavelength: 5,
amplitude: 1,
roughEnds: 2.2,
},
circle: {
loops: 4,
curve: 0,
wobble: 1,
thickness: 3,
}
//animationTrigger: 'load',
//ignoreNestedElements: true,
//splash: true,
//splashSize: 3,
//splashVariation: 2,
//position: "strike"
});
const buttonCell = document.createElement('td');
row.appendChild(buttonCell);
const rerunButton = document.createElement('button');
rerunButton.textContent = 'Rerun Test';
rerunButton.addEventListener('click', () => {
highlighter.rerunHighlight();
const start = performance.now();
resultCell.querySelectorAll('mark').forEach(markElement => {
markElement.addEventListener('animationend', () => {
const end = performance.now();
const duration = end - start;
timer.textContent = `Animation Duration: ${duration.toFixed(2)} ms`;
});
});
});
buttonCell.appendChild(rerunButton);
const start = performance.now();
resultCell.querySelectorAll('mark').forEach(markElement => {
markElement.addEventListener('animationend', () => {
const end = performance.now();
const duration = end - start;
timer.textContent = `Animation Duration: ${duration.toFixed(2)} ms`;
});
});
highlighter.highlightText();
//console.log(highlighter);
});
});
</script>
</head>
<body>
<h2>MarkerHighlighter Test Page</h2>
<table>
<tr>
<th>Attributes</th>
<th>Result</th>
</tr>
<tbody id="test-cases"></tbody>
</table>
</body>
</html>