wikiparser-node 1.1.1-b → 1.1.2-b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/bundle/bundle.min.js +31 -31
- package/extensions/dist/base.js +65 -65
- package/extensions/dist/editor.js +147 -153
- package/extensions/dist/highlight.js +27 -36
- package/extensions/dist/lint.js +36 -35
- package/package.json +6 -3
package/extensions/dist/base.js
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
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
|
-
}
|
|
2
|
+
const MAX_STAGE = 11;
|
|
3
|
+
const workerJS = () => {
|
|
4
|
+
self.importScripts('https://testingcf.jsdelivr.net/gh/bhsd-harry/wikiparser-node@1.1.2-b/bundle/bundle.min.js');
|
|
5
|
+
const { Parser } = self, entities = { '&': 'amp', '<': 'lt', '>': 'gt' };
|
|
6
|
+
self.onmessage = ({ data }) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const [command, qid, ...args] = data;
|
|
9
|
+
switch (command) {
|
|
10
|
+
case 'setI18N':
|
|
11
|
+
Parser.i18n = qid;
|
|
12
|
+
break;
|
|
13
|
+
case 'setConfig':
|
|
14
|
+
Parser.config = qid;
|
|
15
|
+
break;
|
|
16
|
+
case 'getConfig':
|
|
17
|
+
self.postMessage([qid, Parser.getConfig()]);
|
|
18
|
+
break;
|
|
19
|
+
case 'lint':
|
|
20
|
+
self.postMessage([qid, Parser.parse(...args).lint(), args[0]]);
|
|
21
|
+
break;
|
|
22
|
+
default: {
|
|
23
|
+
const stage = (_a = args[2]) !== null && _a !== void 0 ? _a : MAX_STAGE;
|
|
24
|
+
self.postMessage([
|
|
25
|
+
qid,
|
|
26
|
+
Parser.parse(...args).childNodes.map(child => [
|
|
27
|
+
stage,
|
|
28
|
+
String(child),
|
|
29
|
+
child.type === 'text'
|
|
30
|
+
? String(child).replace(/[&<>]/gu, p => `&${entities[p]};`)
|
|
31
|
+
: child.print(),
|
|
32
|
+
]),
|
|
33
|
+
]);
|
|
35
34
|
}
|
|
36
|
-
}
|
|
35
|
+
}
|
|
37
36
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
return listener;
|
|
48
|
-
};
|
|
49
|
-
const setI18N = (i18n) => {
|
|
50
|
-
worker.postMessage(['setI18N', i18n]);
|
|
51
|
-
};
|
|
52
|
-
const setConfig = (config) => {
|
|
53
|
-
worker.postMessage(['setConfig', config]);
|
|
37
|
+
};
|
|
38
|
+
const blob = new Blob([`(${String(workerJS).replace(/MAX_STAGE/gu, String(MAX_STAGE))})()`], { type: 'text/javascript' }), url = URL.createObjectURL(blob), worker = new Worker(url);
|
|
39
|
+
URL.revokeObjectURL(url);
|
|
40
|
+
const getListener = (qid, resolve, raw) => {
|
|
41
|
+
const listener = ({ data: [rid, res, resRaw] }) => {
|
|
42
|
+
if (rid === qid && (raw === undefined || raw === resRaw)) {
|
|
43
|
+
worker.removeEventListener('message', listener);
|
|
44
|
+
resolve(res);
|
|
45
|
+
}
|
|
54
46
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
return listener;
|
|
48
|
+
};
|
|
49
|
+
const setI18N = (i18n) => {
|
|
50
|
+
worker.postMessage(['setI18N', i18n]);
|
|
51
|
+
};
|
|
52
|
+
const setConfig = (config) => {
|
|
53
|
+
worker.postMessage(['setConfig', config]);
|
|
54
|
+
};
|
|
55
|
+
const getConfig = () => new Promise(resolve => {
|
|
56
|
+
worker.addEventListener('message', getListener(-3, resolve));
|
|
57
|
+
worker.postMessage(['getConfig', -3]);
|
|
58
|
+
});
|
|
59
|
+
const print = (wikitext, include, stage, qid = -1) => new Promise(resolve => {
|
|
60
|
+
worker.addEventListener('message', getListener(qid, resolve));
|
|
61
|
+
worker.postMessage(['print', qid, wikitext, include, stage]);
|
|
62
|
+
});
|
|
63
|
+
const lint = (wikitext, include, qid = -2) => new Promise(resolve => {
|
|
64
|
+
worker.addEventListener('message', getListener(qid, resolve, wikitext));
|
|
65
|
+
worker.postMessage(['lint', qid, wikitext, include]);
|
|
66
|
+
});
|
|
67
|
+
const wikiparse = { MAX_STAGE, id: 0, setI18N, setConfig, getConfig, print, lint };
|
|
68
|
+
Object.defineProperty(wikiparse, 'MAX_STAGE', { enumerable: true, configurable: true });
|
|
69
|
+
Object.assign(window, { wikiparse });
|
|
70
70
|
})();
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
1
|
+
(() => {
|
|
10
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
11
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
12
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -18,155 +10,157 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
18
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
19
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
12
|
};
|
|
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
|
-
|
|
13
|
+
var _Printer_instances, _Printer_id, _Printer_preview, _Printer_textbox, _Printer_root, _Printer_viewportChanged, _Printer_running, _Printer_ticks, _Printer_tick, _Printer_exec, _Printer_paint, _Printer_coarsePrint, _Printer_finePrint;
|
|
14
|
+
const { wikiparse } = window, { MAX_STAGE } = wikiparse;
|
|
15
|
+
class Printer {
|
|
16
|
+
constructor(preview, textbox, include) {
|
|
17
|
+
_Printer_instances.add(this);
|
|
18
|
+
_Printer_id.set(this, void 0);
|
|
19
|
+
_Printer_preview.set(this, void 0);
|
|
20
|
+
_Printer_textbox.set(this, void 0);
|
|
21
|
+
_Printer_root.set(this, void 0);
|
|
22
|
+
_Printer_viewportChanged.set(this, void 0);
|
|
23
|
+
_Printer_running.set(this, void 0);
|
|
24
|
+
_Printer_ticks.set(this, void 0);
|
|
25
|
+
__classPrivateFieldSet(this, _Printer_id, wikiparse.id++, "f");
|
|
26
|
+
__classPrivateFieldSet(this, _Printer_preview, preview, "f");
|
|
27
|
+
__classPrivateFieldSet(this, _Printer_textbox, textbox, "f");
|
|
28
|
+
__classPrivateFieldSet(this, _Printer_root, [], "f");
|
|
29
|
+
__classPrivateFieldSet(this, _Printer_viewportChanged, false, "f");
|
|
30
|
+
this.include = Boolean(include);
|
|
31
|
+
__classPrivateFieldSet(this, _Printer_ticks, [0, undefined], "f");
|
|
32
|
+
}
|
|
33
|
+
queue(delay, method) {
|
|
34
|
+
const [state] = __classPrivateFieldGet(this, _Printer_ticks, "f");
|
|
35
|
+
if (delay === 0 || state <= 0 || method === 'coarse' || __classPrivateFieldGet(this, _Printer_ticks, "f")[1] !== 'coarse') {
|
|
36
|
+
__classPrivateFieldSet(this, _Printer_ticks, [delay, method], "f");
|
|
37
|
+
if (delay === 0) {
|
|
38
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_exec).call(this, method);
|
|
39
|
+
}
|
|
40
|
+
else if (state <= 0) {
|
|
41
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_tick).call(this);
|
|
49
42
|
}
|
|
50
|
-
}
|
|
51
|
-
coarsePrint() {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
if (this.running) {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
const { include } = this, { value } = __classPrivateFieldGet(this, _Printer_textbox, "f"), parsed = yield wikiparse.print(value, include, 2, __classPrivateFieldGet(this, _Printer_id, "f"));
|
|
57
|
-
if (this.include !== include || __classPrivateFieldGet(this, _Printer_textbox, "f").value !== value) {
|
|
58
|
-
this.running = undefined;
|
|
59
|
-
this.running = this.coarsePrint();
|
|
60
|
-
return this.running;
|
|
61
|
-
}
|
|
62
|
-
__classPrivateFieldSet(this, _Printer_root, parsed, "f");
|
|
63
|
-
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_paint).call(this);
|
|
64
|
-
this.running = undefined;
|
|
65
|
-
this.running = this.finePrint();
|
|
66
|
-
return this.running;
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
finePrint() {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
if (this.running) {
|
|
72
|
-
__classPrivateFieldSet(this, _Printer_viewportChanged, true, "f");
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
__classPrivateFieldSet(this, _Printer_viewportChanged, false, "f");
|
|
76
|
-
const { include } = this, { value } = __classPrivateFieldGet(this, _Printer_textbox, "f"), { scrollHeight, offsetHeight: parentHeight, scrollTop, children: [rootNode] } = __classPrivateFieldGet(this, _Printer_preview, "f");
|
|
77
|
-
let text = value, start = 0, { length: end } = __classPrivateFieldGet(this, _Printer_root, "f");
|
|
78
|
-
if (scrollHeight > parentHeight) {
|
|
79
|
-
const childNodes = [...rootNode.childNodes], headings = childNodes.filter(({ className }) => className === 'wpb-heading'), { length } = headings;
|
|
80
|
-
if (length > 0) {
|
|
81
|
-
let i = headings.findIndex(({ offsetTop, offsetHeight }) => offsetTop + offsetHeight > scrollTop);
|
|
82
|
-
i = i === -1 ? length : i;
|
|
83
|
-
let j = headings.slice(i).findIndex(({ offsetTop }) => offsetTop >= scrollTop + parentHeight);
|
|
84
|
-
j = j === -1 ? length : i + j;
|
|
85
|
-
start = i ? childNodes.indexOf(headings[i - 1]) : 0;
|
|
86
|
-
while (i <= j && __classPrivateFieldGet(this, _Printer_root, "f")[start][0] === MAX_STAGE) {
|
|
87
|
-
start = childNodes.indexOf(headings[i++]);
|
|
88
|
-
}
|
|
89
|
-
end = j === length ? end : childNodes.indexOf(headings[j]);
|
|
90
|
-
while (i <= j && __classPrivateFieldGet(this, _Printer_root, "f")[end - 1][0] === MAX_STAGE) {
|
|
91
|
-
end = childNodes.indexOf(headings[--j]);
|
|
92
|
-
}
|
|
93
|
-
text = __classPrivateFieldGet(this, _Printer_root, "f").slice(start, end).map(([, str]) => str).join('');
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (start === end) {
|
|
97
|
-
this.running = undefined;
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
const parsed = yield wikiparse.print(text, include, MAX_STAGE, __classPrivateFieldGet(this, _Printer_id, "f"));
|
|
101
|
-
if (this.include === include && __classPrivateFieldGet(this, _Printer_textbox, "f").value === value) {
|
|
102
|
-
__classPrivateFieldGet(this, _Printer_root, "f").splice(start, end - start, ...parsed);
|
|
103
|
-
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_paint).call(this);
|
|
104
|
-
this.running = undefined;
|
|
105
|
-
if (__classPrivateFieldGet(this, _Printer_viewportChanged, "f")) {
|
|
106
|
-
this.running = this.finePrint();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
this.running = undefined;
|
|
111
|
-
this.running = this.coarsePrint();
|
|
112
|
-
}
|
|
113
|
-
return this.running;
|
|
114
|
-
});
|
|
115
43
|
}
|
|
116
44
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
else {
|
|
126
|
-
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_tick).call(this);
|
|
127
|
-
}
|
|
45
|
+
}
|
|
46
|
+
_Printer_id = new WeakMap(), _Printer_preview = new WeakMap(), _Printer_textbox = new WeakMap(), _Printer_root = new WeakMap(), _Printer_viewportChanged = new WeakMap(), _Printer_running = new WeakMap(), _Printer_ticks = new WeakMap(), _Printer_instances = new WeakSet(), _Printer_tick = function _Printer_tick() {
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
const [t, method] = __classPrivateFieldGet(this, _Printer_ticks, "f");
|
|
49
|
+
if (t > 0) {
|
|
50
|
+
__classPrivateFieldGet(this, _Printer_ticks, "f")[0] -= 500;
|
|
51
|
+
if (t <= 500) {
|
|
52
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_exec).call(this, method);
|
|
128
53
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
__classPrivateFieldGet(this, _Printer_preview, "f").innerHTML = `<span class="wpb-root">${__classPrivateFieldGet(this, _Printer_root, "f").map(([, , printed]) => printed).join('')}</span> `;
|
|
132
|
-
__classPrivateFieldGet(this, _Printer_preview, "f").scrollTop = __classPrivateFieldGet(this, _Printer_textbox, "f").scrollTop;
|
|
133
|
-
__classPrivateFieldGet(this, _Printer_preview, "f").classList.remove('active');
|
|
134
|
-
__classPrivateFieldGet(this, _Printer_textbox, "f").style.color = 'transparent';
|
|
135
|
-
};
|
|
136
|
-
const edit = (textbox, include) => {
|
|
137
|
-
if (!(textbox instanceof HTMLTextAreaElement)) {
|
|
138
|
-
throw new TypeError('wikiparse.edit方法仅可用于textarea元素!');
|
|
139
|
-
}
|
|
140
|
-
const preview = document.createElement('div'), container = document.createElement('div'), printer = new Printer(preview, textbox, include);
|
|
141
|
-
preview.id = 'wikiPretty';
|
|
142
|
-
preview.classList.add('wikiparser', 'active');
|
|
143
|
-
container.classList.add('wikiparse-container');
|
|
144
|
-
textbox.replaceWith(container);
|
|
145
|
-
textbox.classList.add('wikiparsed');
|
|
146
|
-
container.append(preview, textbox);
|
|
147
|
-
textbox.addEventListener('input', e => {
|
|
148
|
-
if (!e.isComposing) {
|
|
149
|
-
printer.queue(2000, 'coarsePrint');
|
|
54
|
+
else {
|
|
55
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_tick).call(this);
|
|
150
56
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
57
|
+
}
|
|
58
|
+
}, 500);
|
|
59
|
+
}, _Printer_exec = function _Printer_exec(method) {
|
|
60
|
+
if (method === 'coarse') {
|
|
61
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_coarsePrint).call(this);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_finePrint).call(this);
|
|
65
|
+
}
|
|
66
|
+
}, _Printer_paint = function _Printer_paint() {
|
|
67
|
+
__classPrivateFieldGet(this, _Printer_preview, "f").innerHTML = `<span class="wpb-root">${__classPrivateFieldGet(this, _Printer_root, "f").map(([, , printed]) => printed).join('')}</span> `;
|
|
68
|
+
__classPrivateFieldGet(this, _Printer_preview, "f").scrollTop = __classPrivateFieldGet(this, _Printer_textbox, "f").scrollTop;
|
|
69
|
+
__classPrivateFieldGet(this, _Printer_preview, "f").classList.remove('active');
|
|
70
|
+
__classPrivateFieldGet(this, _Printer_textbox, "f").style.color = 'transparent';
|
|
71
|
+
}, _Printer_coarsePrint = async function _Printer_coarsePrint() {
|
|
72
|
+
if (__classPrivateFieldGet(this, _Printer_running, "f")) {
|
|
73
|
+
return __classPrivateFieldGet(this, _Printer_running, "f");
|
|
74
|
+
}
|
|
75
|
+
const { include } = this, { value } = __classPrivateFieldGet(this, _Printer_textbox, "f"), parsed = await wikiparse.print(value, include, 2, __classPrivateFieldGet(this, _Printer_id, "f"));
|
|
76
|
+
if (this.include !== include || __classPrivateFieldGet(this, _Printer_textbox, "f").value !== value) {
|
|
77
|
+
__classPrivateFieldSet(this, _Printer_running, undefined, "f");
|
|
78
|
+
__classPrivateFieldSet(this, _Printer_running, __classPrivateFieldGet(this, _Printer_instances, "m", _Printer_coarsePrint).call(this), "f");
|
|
79
|
+
return __classPrivateFieldGet(this, _Printer_running, "f");
|
|
80
|
+
}
|
|
81
|
+
__classPrivateFieldSet(this, _Printer_root, parsed, "f");
|
|
82
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_paint).call(this);
|
|
83
|
+
__classPrivateFieldSet(this, _Printer_running, undefined, "f");
|
|
84
|
+
__classPrivateFieldSet(this, _Printer_running, __classPrivateFieldGet(this, _Printer_instances, "m", _Printer_finePrint).call(this), "f");
|
|
85
|
+
return __classPrivateFieldGet(this, _Printer_running, "f");
|
|
86
|
+
}, _Printer_finePrint = async function _Printer_finePrint() {
|
|
87
|
+
if (__classPrivateFieldGet(this, _Printer_running, "f")) {
|
|
88
|
+
__classPrivateFieldSet(this, _Printer_viewportChanged, true, "f");
|
|
89
|
+
return __classPrivateFieldGet(this, _Printer_running, "f");
|
|
90
|
+
}
|
|
91
|
+
__classPrivateFieldSet(this, _Printer_viewportChanged, false, "f");
|
|
92
|
+
const { include } = this, { value } = __classPrivateFieldGet(this, _Printer_textbox, "f"), { scrollHeight, offsetHeight: parentHeight, scrollTop, children: [rootNode] } = __classPrivateFieldGet(this, _Printer_preview, "f");
|
|
93
|
+
let text = value, start = 0, { length: end } = __classPrivateFieldGet(this, _Printer_root, "f");
|
|
94
|
+
if (scrollHeight > parentHeight) {
|
|
95
|
+
const childNodes = [...rootNode.childNodes], headings = childNodes.filter(({ className }) => className === 'wpb-heading'), { length } = headings;
|
|
96
|
+
if (length > 0) {
|
|
97
|
+
let i = headings.findIndex(({ offsetTop, offsetHeight }) => offsetTop + offsetHeight > scrollTop);
|
|
98
|
+
i = i === -1 ? length : i;
|
|
99
|
+
let j = headings.slice(i).findIndex(({ offsetTop }) => offsetTop >= scrollTop + parentHeight);
|
|
100
|
+
j = j === -1 ? length : i + j;
|
|
101
|
+
start = i ? childNodes.indexOf(headings[i - 1]) : 0;
|
|
102
|
+
while (i <= j && __classPrivateFieldGet(this, _Printer_root, "f")[start][0] === MAX_STAGE) {
|
|
103
|
+
start = childNodes.indexOf(headings[i++]);
|
|
158
104
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
e.preventDefault();
|
|
163
|
-
printer.ticks[0] = 0;
|
|
164
|
-
printer.running = printer.coarsePrint();
|
|
105
|
+
end = j === length ? end : childNodes.indexOf(headings[j]);
|
|
106
|
+
while (i <= j && __classPrivateFieldGet(this, _Printer_root, "f")[end - 1][0] === MAX_STAGE) {
|
|
107
|
+
end = childNodes.indexOf(headings[--j]);
|
|
165
108
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
109
|
+
text = __classPrivateFieldGet(this, _Printer_root, "f").slice(start, end).map(([, str]) => str).join('');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (start === end) {
|
|
113
|
+
__classPrivateFieldSet(this, _Printer_running, undefined, "f");
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
const parsed = await wikiparse.print(text, include, MAX_STAGE, __classPrivateFieldGet(this, _Printer_id, "f"));
|
|
117
|
+
if (this.include === include && __classPrivateFieldGet(this, _Printer_textbox, "f").value === value) {
|
|
118
|
+
__classPrivateFieldGet(this, _Printer_root, "f").splice(start, end - start, ...parsed);
|
|
119
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_paint).call(this);
|
|
120
|
+
__classPrivateFieldSet(this, _Printer_running, undefined, "f");
|
|
121
|
+
if (__classPrivateFieldGet(this, _Printer_viewportChanged, "f")) {
|
|
122
|
+
__classPrivateFieldSet(this, _Printer_running, __classPrivateFieldGet(this, _Printer_instances, "m", _Printer_finePrint).call(this), "f");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
__classPrivateFieldSet(this, _Printer_running, undefined, "f");
|
|
127
|
+
__classPrivateFieldSet(this, _Printer_running, __classPrivateFieldGet(this, _Printer_instances, "m", _Printer_coarsePrint).call(this), "f");
|
|
128
|
+
}
|
|
129
|
+
return __classPrivateFieldGet(this, _Printer_running, "f");
|
|
130
|
+
};
|
|
131
|
+
const edit = (textbox, include) => {
|
|
132
|
+
if (!(textbox instanceof HTMLTextAreaElement)) {
|
|
133
|
+
throw new TypeError('wikiparse.edit方法仅可用于textarea元素!');
|
|
134
|
+
}
|
|
135
|
+
const preview = document.createElement('div'), container = document.createElement('div'), printer = new Printer(preview, textbox, include);
|
|
136
|
+
preview.id = 'wikiPretty';
|
|
137
|
+
preview.classList.add('wikiparser', 'active');
|
|
138
|
+
container.classList.add('wikiparse-container');
|
|
139
|
+
textbox.replaceWith(container);
|
|
140
|
+
textbox.classList.add('wikiparsed');
|
|
141
|
+
container.append(preview, textbox);
|
|
142
|
+
textbox.addEventListener('input', e => {
|
|
143
|
+
if (!e.isComposing) {
|
|
144
|
+
printer.queue(2000, 'coarse');
|
|
145
|
+
}
|
|
146
|
+
textbox.style.color = '';
|
|
147
|
+
preview.classList.add('active');
|
|
148
|
+
});
|
|
149
|
+
textbox.addEventListener('scroll', () => {
|
|
150
|
+
if (preview.scrollHeight > preview.offsetHeight && !preview.classList.contains('active')) {
|
|
151
|
+
preview.scrollTop = textbox.scrollTop;
|
|
152
|
+
printer.queue(500, 'fine');
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
textbox.addEventListener('keydown', e => {
|
|
156
|
+
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
printer.queue(0, 'coarse');
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
printer.queue(0, 'coarse');
|
|
162
|
+
return printer;
|
|
163
|
+
};
|
|
164
|
+
wikiparse.Printer = Printer;
|
|
165
|
+
wikiparse.edit = edit;
|
|
172
166
|
})();
|
|
@@ -1,39 +1,30 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
(() => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
const ol = document.createElement('ol');
|
|
29
|
-
ol.start = start;
|
|
30
|
-
ol.style.paddingLeft = `${String(lines.length + start - 1).length + 2.5}ch`;
|
|
31
|
-
ol.append(...lines);
|
|
32
|
-
ele.replaceChildren(ol);
|
|
2
|
+
const { wikiparse } = window;
|
|
3
|
+
const highlight = async (ele, include, linenums = false, start = 1) => {
|
|
4
|
+
if (ele.classList.contains('highlighted')) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const html = (await wikiparse.print(ele.innerText, include)).map(([, , printed]) => printed).join('');
|
|
8
|
+
ele.classList.add('highlighted');
|
|
9
|
+
if (linenums) {
|
|
10
|
+
const lines = html.split('\n').map((line, i) => {
|
|
11
|
+
const li = document.createElement('li');
|
|
12
|
+
li.id = `L${i + start}`;
|
|
13
|
+
li.innerHTML = line;
|
|
14
|
+
return li;
|
|
15
|
+
});
|
|
16
|
+
if (!lines[lines.length - 1].textContent) {
|
|
17
|
+
lines.pop();
|
|
33
18
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
19
|
+
const ol = document.createElement('ol');
|
|
20
|
+
ol.start = start;
|
|
21
|
+
ol.style.paddingLeft = `${String(lines.length + start - 1).length + 2.5}ch`;
|
|
22
|
+
ol.append(...lines);
|
|
23
|
+
ele.replaceChildren(ol);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
ele.innerHTML = html;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
wikiparse.highlight = highlight;
|
|
39
30
|
})();
|
package/extensions/dist/lint.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
1
|
+
(() => {
|
|
10
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
11
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
12
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -18,31 +10,40 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
18
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
19
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
12
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
__classPrivateFieldSet(this, _Linter_running, __classPrivateFieldGet(this, _Linter_instances, "m", _Linter_lint).call(this, wikitext), "f");
|
|
38
|
-
return __classPrivateFieldGet(this, _Linter_running, "f");
|
|
39
|
-
}
|
|
13
|
+
var _Linter_instances, _Linter_id, _Linter_wikitext, _Linter_running, _Linter_lint;
|
|
14
|
+
const { wikiparse } = window;
|
|
15
|
+
class Linter {
|
|
16
|
+
constructor(include) {
|
|
17
|
+
_Linter_instances.add(this);
|
|
18
|
+
_Linter_id.set(this, void 0);
|
|
19
|
+
_Linter_wikitext.set(this, void 0);
|
|
20
|
+
_Linter_running.set(this, void 0);
|
|
21
|
+
__classPrivateFieldSet(this, _Linter_id, wikiparse.id++, "f");
|
|
22
|
+
this.include = Boolean(include);
|
|
23
|
+
}
|
|
24
|
+
queue(wikitext) {
|
|
25
|
+
var _a;
|
|
26
|
+
__classPrivateFieldSet(this, _Linter_wikitext, wikitext, "f");
|
|
27
|
+
__classPrivateFieldSet(this, _Linter_running, (_a = __classPrivateFieldGet(this, _Linter_running, "f")) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _Linter_instances, "m", _Linter_lint).call(this, wikitext), "f");
|
|
28
|
+
return __classPrivateFieldGet(this, _Linter_running, "f");
|
|
40
29
|
}
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
async codemirror(wikitext) {
|
|
31
|
+
return (await this.queue(wikitext)).map(({ startIndex, endIndex, severity, message }) => ({
|
|
32
|
+
from: startIndex,
|
|
33
|
+
to: endIndex,
|
|
34
|
+
severity,
|
|
35
|
+
message,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
_Linter_id = new WeakMap(), _Linter_wikitext = new WeakMap(), _Linter_running = new WeakMap(), _Linter_instances = new WeakSet(), _Linter_lint = async function _Linter_lint(wikitext) {
|
|
40
|
+
const { include } = this, errors = await wikiparse.lint(wikitext, include, __classPrivateFieldGet(this, _Linter_id, "f"));
|
|
41
|
+
if (this.include === include && __classPrivateFieldGet(this, _Linter_wikitext, "f") === wikitext) {
|
|
42
|
+
__classPrivateFieldSet(this, _Linter_running, undefined, "f");
|
|
43
|
+
return errors;
|
|
44
|
+
}
|
|
45
|
+
__classPrivateFieldSet(this, _Linter_running, __classPrivateFieldGet(this, _Linter_instances, "m", _Linter_lint).call(this, __classPrivateFieldGet(this, _Linter_wikitext, "f")), "f");
|
|
46
|
+
return __classPrivateFieldGet(this, _Linter_running, "f");
|
|
47
|
+
};
|
|
48
|
+
wikiparse.Linter = Linter;
|
|
48
49
|
})();
|