-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
355 lines (349 loc) · 11.5 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
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
</head>
<style>
#app {
position: relative;
}
</style>
<body>
<div id="app">
<ol>
<li>
<p>
<u
><strong
><em><s>dasda</s></em></strong
></u
>
</p>
</li>
<li>
<p>
<u
><strong
><em><s>asdasdasdas</s></em></strong
></u
>
</p>
</li>
<li>
<p>
<u
><strong
><em><s>ffdasdasdasdas</s></em></strong
></u
>
</p>
</li>
</ol>
<p></p>
<p>
<a
target="_blank"
rel="noopener noreferrer nofollow"
class="me-link"
href="http://www.baidu.com"
istag="true"
value="啥答案所大所大所多"
title="Cmd/Ctrl+点击可跳转"
>这是一个链接</a
>这是一段【部分选择】文本这是
</p>
<img
class="me-image"
src="https://mind-file2.im30.net:443/mind-im-data-dev/f7177163c833dff4b38fc8d2872f1ec6/8hc7yv8eetiw6u72pxscmjzygr/1712039573786.jpg"
isresponse="false"
mind-data="[object Object]"
contenteditable="true"
/>
<p>
这是一段【多行文本】文本这是一段【多行文本】文本
这是一段【多行文本】文本 这是一段【多行文本】文本
这是一段【多行文本】文本 这是一段【多行文本】文本
这是一段【多行文本】文本
</p>
<p>【换行文本】 选择</p>
<video
src="https://mind-file2.im30.net:443/mind-im-data-dev/f7177163c833dff4b38fc8d2872f1ec6/zkyahiybh4ywannqu9kbov2m8s/1712039598407.mp4"
contenteditable="false"
width="200"
height="113"
controls="true"
class="video-main"
controlslist="nodownload noremoteplayback noplaybackrate"
disablepictureinpicture="true"
></video>
<p>啊实打实大阿斯顿阿斯顿</p>
<p>
<strong>测试</strong><em>视频</em><s>和图</s
><u
>片“:<strong
><em><s>萨达萨达萨达 </s></em></strong
></u
><strong
><em><s> </s></em
></strong>
<a
target="_blank"
rel="noopener noreferrer nofollow"
class="me-link"
href="http://www.baidu.com"
istag="true"
value="百度"
title="Cmd/Ctrl+点击可跳转"
>百度</a
>
<a
target="_blank"
rel="noopener noreferrer nofollow"
class="me-link"
href="http://www.baidu.com"
istag="false"
title="Cmd/Ctrl+点击可跳转"
>www.baidu.com</a
>
</p>
<ol>
<li>
<p>有序列表1</p>
<ol>
<li>
<p>
有序列表1-1
<span
data-type="mention"
class="me-mention"
data-id="_user_1asdfjq39r100weuf2_9afce3gn7brg8rra"
data-label="逐货师"
>@逐货师</span
>
</p>
</li>
</ol>
</li>
<li>
<p>有序列表2</p>
<ol>
<li>
<p>有序列表2-1</p>
<ol>
<li>
<p>游学列表2-1-1</p>
</li>
</ol>
</li>
</ol>
</li>
</ol>
<ul>
<li>
<p>无序列表1</p>
<ul>
<li>
<p>无序列表1-1</p>
<ul>
<li>
<p>序列表1-1-1</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>东方闪电费大叔飞的</p>
<img
class="me-image"
src="https://mind-file2.im30.net:443/mind-im-data-dev/f7177163c833dff4b38fc8d2872f1ec6/j6b5hbfpq3dpslb6pqwjog9f74/1712473863824.png"
isresponse="false"
mind-data="[object Object]"
contenteditable="true"
/>
<p>范德萨范德萨发都是</p>
<video
src="https://mind-file2.im30.net:443/mind-im-data-dev/f7177163c833dff4b38fc8d2872f1ec6/asza98rphgt9vfxbtbfhqtplk8/1712473870562.mp4"
contenteditable="false"
width="200"
height="113"
class="video-main"
controls
controlslist="nodownload noplay noremoteplayback noplaybackrate"
disablepictureinpicture="true"
></video>
<p></p>
</div>
<script src="./lib/index.iife.js"></script>
<script type="module">
// import ContextMarker from "./src/index";
const root = document.getElementById("app");
let markItem = null;
const cur_operator = "user-B";
let sources = JSON.parse(localStorage.getItem("markData")) || [];
const tipElement = document.createElement("div");
tipElement.style.userSelect = "none";
tipElement.style.borderRadius = "5px";
tipElement.style.background = "transparent";
tipElement.style.color = "#fff";
tipElement.style.paddingBlock = "3px 6px";
tipElement.style.position = "absolute";
tipElement.style.width = "56px";
tipElement.style.visibility = "hidden";
tipElement.style.textAlign = "center";
tipElement.style.zIndex = 2;
tipElement.innerHTML = "<span>划线</span>";
tipElement.onclick = (e) => {
e.stopPropagation();
contextMarker.render(markItem);
hiddenTip();
};
root.appendChild(tipElement);
const showTip = (item, startRect, operators) => {
console.log("showTip", item, startRect, operators);
const ids = [...new Set(operators)];
setTimeout(() => {
tipElement.style.top = startRect.y - tipElement.clientHeight - 2 + "px";
tipElement.style.left =
startRect.x + startRect.width / 2 - tipElement.clientWidth / 2 + "px";
tipElement.style.visibility = "visible";
tipElement.style.background = "#000000c4";
})
if (ids && ids.length) {
const count = ids.length;
if (ids.includes(cur_operator)) {
tipElement.innerHTML = "<span>已划线</span>" + count;
tipElement.onclick = (e) => {
e.stopPropagation();
contextMarker.delete(markItem.id);
hiddenTip();
};
} else {
tipElement.onclick = (e) => {
e.stopPropagation();
const _markItem = JSON.parse(JSON.stringify(markItem));
contextMarker.render({
..._markItem,
id: "" + Date.now(),
create_at: Date.now(),
operator: cur_operator,
lineVisible: true,
rectVisible: false,
config: { ..._markItem, lineShape: "solid" },
});
hiddenTip();
};
tipElement.innerHTML = "<span>划线</span>" + count;
}
} else {
tipElement.innerHTML = "<span>划线</span>";
tipElement.onclick = (e) => {
e.stopPropagation();
contextMarker.render({ id: "" + Date.now(), ...markItem });
hiddenTip();
};
}
// window.flutter_inappwebview.callHandler("showMarkUnderlinePopupMenu", item, item.length, ids);
};
const hiddenTip = () => {
markItem && contextMarker.highlight(false, markItem.id);
markItem = null;
tipElement.style.visibility = "hidden";
tipElement.style.background = "transparent";
// window.flutter_inappwebview.callHandler("hideMarkUnderlinePopupMenu");
};
const contextMarker = new ContextMarker(root);
if (sources && sources.length) {
sources = sources.map((item) => {
item.lineVisible = true;
item.rectVisible = false;
item.config.lineShape =
item.operator === cur_operator ? "solid" : "dash";
return item;
});
contextMarker.restore(sources);
}
function isSameNode(sourceNode, targetNode) {
// 比较offset是否相同
if (sourceNode.offset !== targetNode.offset) return false;
// 比较path是否相同
if (sourceNode.path.length !== targetNode.path.length) return false;
return (
JSON.stringify(sourceNode.path) === JSON.stringify(targetNode.path)
);
}
// TODO:移动端app手势兼容
// root.addEventListener("selectionchange", (e) => {});
const matchItems = (items) => {
if (items.length === 1) return items[0];
// 筛选最短的内容
const minLength = Math.min(...items.map((item) => item.length));
const minLengthElements = items.filter(
(item) => item.length === minLength
);
if (minLengthElements.length === 1) return minLengthElements[0];
// 优先选id是自己的
const myElements = minLengthElements.find(
(item) => item.operator === cur_operator
);
if (myElements) return myElements;
// 筛选创建时间最早的内容
const minCreateElement = minLengthElements.reduce((prev, current) =>
prev.create_at > current.create_at ? current : prev
);
return minCreateElement;
};
contextMarker
.on(ContextMarker.event.CLICK, (items, e) => {
console.log("ContextMarker.event.CLICK", items);
if (!markItem) {
if (!items || !items.length) return hiddenTip();
// 找到匹配的item
const matchItem = matchItems(items);
// 获取item对应的rect
const rects = contextMarker.getItemPosition(matchItem);
if (!rects || !rects.length) return hiddenTip();
contextMarker.highlight(true, matchItem.id);
const filterItems = items.filter(
(item) =>
isSameNode(matchItem.startNode, item.startNode) &&
isSameNode(matchItem.endNode, item.endNode)
);
const operators = filterItems.map((item) => item.operator);
markItem = matchItem;
showTip(matchItem, rects[0], operators);
}
})
.on(contextMarker.event.PointerEnd, (item, items, rects) => {
console.log("PointerEnd-item", item);
console.log("PointerEnd-items", items);
hiddenTip();
if (!item) return;
markItem = { ...item };
markItem.operator = cur_operator;
const [startRect, endRect] = rects;
// 如果items里有跟item id一样的元素,选中它,否则
if (item && item.length)
showTip(
item,
startRect,
items.map((item) => item.operator)
);
})
.on(ContextMarker.event.CREATE, (item) => {
const { rectVisible, lineVisible, ...otherParam } = item;
const sourceItem = {
id: "" + Date.now(),
operator: cur_operator,
create_at: Date.now(),
...otherParam,
};
sources.push(sourceItem);
localStorage.setItem("markData", JSON.stringify(sources));
});
</script>
</body>
</html>