@dan-uni/dan-any-plugin-detaolu 0.0.2

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/dist/index.js ADDED
@@ -0,0 +1,732 @@
1
+ /*! For license information please see index.js.LICENSE.txt */
2
+ import { UniDM, UniDMTools, UniPool } from "@dan-uni/dan-any";
3
+ import fs_extra from "fs-extra";
4
+ var Module = function(moduleArg = {}) {
5
+ var moduleRtn;
6
+ var f = moduleArg, g, m = new Promise((a)=>{
7
+ g = a;
8
+ });
9
+ '_begin_chunk _check_similar _begin_index_lock _malloc _memory ___indirect_function_table onRuntimeInitialized'.split(' ').forEach((a)=>{
10
+ Object.getOwnPropertyDescriptor(m, a) || Object.defineProperty(m, a, {
11
+ get: ()=>q('You are getting ' + a + ' on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js'),
12
+ set: ()=>q('You are setting ' + a + ' on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js')
13
+ });
14
+ });
15
+ var r = (a)=>console.log(a), t = (a)=>console.error(a);
16
+ r = ()=>{};
17
+ t = (a)=>{
18
+ console.error(a);
19
+ throw Error('wasm error: ' + a);
20
+ };
21
+ function v(a, b) {
22
+ if (!a) throw b;
23
+ }
24
+ function q(a) {
25
+ throw Error(a);
26
+ }
27
+ var B, C, D, E;
28
+ function H() {
29
+ var a = E.buffer;
30
+ new Int8Array(a);
31
+ B = new Int16Array(a);
32
+ C = new Uint8Array(a);
33
+ new Uint16Array(a);
34
+ new Int32Array(a);
35
+ D = new Uint32Array(a);
36
+ new Float32Array(a);
37
+ new Float64Array(a);
38
+ new BigInt64Array(a);
39
+ new BigUint64Array(a);
40
+ }
41
+ v(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
42
+ v(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
43
+ v(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
44
+ v(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
45
+ var I = new Int16Array(1), J = new Int8Array(I.buffer);
46
+ I[0] = 25459;
47
+ if (115 !== J[0] || 99 !== J[1]) throw 'Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)';
48
+ if (f.ENVIRONMENT) throw Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)');
49
+ function K(a) {
50
+ return 'FS_createPath' === a || 'FS_createDataFile' === a || 'FS_createPreloadedFile' === a || 'FS_unlink' === a || 'addRunDependency' === a || 'FS_createLazyFile' === a || 'FS_createDevice' === a || 'removeRunDependency' === a;
51
+ }
52
+ function L(a, b) {
53
+ 'undefined' == typeof globalThis || Object.getOwnPropertyDescriptor(globalThis, a) || Object.defineProperty(globalThis, a, {
54
+ configurable: !0,
55
+ get () {
56
+ b();
57
+ }
58
+ });
59
+ }
60
+ function M(a, b) {
61
+ L(a, ()=>{
62
+ N(`\`${a}\` is not longer defined by emscripten. ${b}`);
63
+ });
64
+ }
65
+ M('buffer', 'Please use HEAP8.buffer or wasmMemory.buffer');
66
+ M('asm', 'Please use wasmExports instead');
67
+ function O(a) {
68
+ Object.getOwnPropertyDescriptor(f, a) || Object.defineProperty(f, a, {
69
+ configurable: !0,
70
+ get () {
71
+ var b = `'${a}' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)`;
72
+ K(a) && (b += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you');
73
+ q(b);
74
+ }
75
+ });
76
+ }
77
+ var N = (a)=>{
78
+ N.g || (N.g = {});
79
+ N.g[a] || (N.g[a] = 1, t(a));
80
+ }, P = 'undefined' != typeof TextDecoder ? new TextDecoder() : void 0, R = [
81
+ null,
82
+ [],
83
+ []
84
+ ], S = {
85
+ _abort_js: ()=>q('native code called abort()'),
86
+ emscripten_resize_heap: (a)=>{
87
+ var b = C.length;
88
+ a >>>= 0;
89
+ v(a > b);
90
+ if (268435456 < a) return t(`Cannot enlarge memory, requested ${a} bytes, but the limit is 268435456 bytes!`), !1;
91
+ for(var c = 1; 4 >= c; c *= 2){
92
+ var h = b * (1 + 1 / c);
93
+ h = Math.min(h, a + 100663296);
94
+ var k = Math, n = k.min;
95
+ h = Math.max(a, h);
96
+ v(65536, 'alignment argument is required');
97
+ k = n.call(k, 268435456, 65536 * Math.ceil(h / 65536));
98
+ a: {
99
+ n = k;
100
+ h = E.buffer;
101
+ var F = (n - h.byteLength + 65535) / 65536 | 0;
102
+ try {
103
+ E.grow(F);
104
+ H();
105
+ var w = 1;
106
+ break a;
107
+ } catch (x) {
108
+ t(`growMemory: Attempted to grow heap from ${h.byteLength} bytes to ${n} bytes, but got error: ${x}`);
109
+ }
110
+ w = void 0;
111
+ }
112
+ if (w) return !0;
113
+ }
114
+ t(`Failed to grow the heap from ${b} bytes to ${k} bytes, not enough memory!`);
115
+ return !1;
116
+ },
117
+ fd_close: ()=>{
118
+ q('fd_close called without SYSCALLS_REQUIRE_FILESYSTEM');
119
+ },
120
+ fd_seek: function() {
121
+ return 70;
122
+ },
123
+ fd_write: (a, b, c, h)=>{
124
+ for(var k = 0, n = 0; n < c; n++){
125
+ var F = D[b >> 2], w = D[b + 4 >> 2];
126
+ b += 8;
127
+ for(var x = 0; x < w; x++){
128
+ var y = a, e = C[F + x], z = R[y];
129
+ v(z);
130
+ if (0 === e || 10 === e) {
131
+ y = 1 === y ? r : t;
132
+ e = z;
133
+ for(var l = 0, p = l + NaN, u = l; e[u] && !(u >= p);)++u;
134
+ if (16 < u - l && e.buffer && P) e = P.decode(e.subarray(l, u));
135
+ else {
136
+ for(p = ''; l < u;){
137
+ var d = e[l++];
138
+ if (128 & d) {
139
+ var G = 63 & e[l++];
140
+ if (192 == (224 & d)) p += String.fromCharCode((31 & d) << 6 | G);
141
+ else {
142
+ var Q = 63 & e[l++];
143
+ if (224 == (240 & d)) d = (15 & d) << 12 | G << 6 | Q;
144
+ else {
145
+ if (240 != (248 & d)) {
146
+ var V = N;
147
+ var A = d;
148
+ v('number' == typeof A);
149
+ A = '0x' + (A >>> 0).toString(16).padStart(8, '0');
150
+ V('Invalid UTF-8 leading byte ' + A + ' encountered when deserializing a UTF-8 string in wasm memory to a JS string!');
151
+ }
152
+ d = (7 & d) << 18 | G << 12 | Q << 6 | 63 & e[l++];
153
+ }
154
+ 65536 > d ? p += String.fromCharCode(d) : (d -= 65536, p += String.fromCharCode(55296 | d >> 10, 56320 | 1023 & d));
155
+ }
156
+ } else p += String.fromCharCode(d);
157
+ }
158
+ e = p;
159
+ }
160
+ y(e);
161
+ z.length = 0;
162
+ } else z.push(e);
163
+ }
164
+ k += w;
165
+ }
166
+ D[h >> 2] = k;
167
+ return 0;
168
+ }
169
+ };
170
+ f.stringToUTF16 = (a, b, c)=>{
171
+ v(0 == b % 2, 'Pointer passed to stringToUTF16 must be aligned to two bytes!');
172
+ v('number' == typeof c, 'stringToUTF16(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
173
+ c ??= 2147483647;
174
+ if (2 > c) return 0;
175
+ c -= 2;
176
+ var h = b;
177
+ c = c < 2 * a.length ? c / 2 : a.length;
178
+ for(var k = 0; k < c; ++k)B[b >> 1] = a.charCodeAt(k), b += 2;
179
+ B[b >> 1] = 0;
180
+ return b - h;
181
+ };
182
+ "writeI53ToI64 writeI53ToI64Clamped writeI53ToI64Signaling writeI53ToU64Clamped writeI53ToU64Signaling readI53FromI64 readI53FromU64 convertI32PairToI53 convertI32PairToI53Checked convertU32PairToI53 stackSave stackRestore stackAlloc getTempRet0 setTempRet0 zeroMemory strError inetPton4 inetNtop4 inetPton6 inetNtop6 readSockaddr writeSockaddr emscriptenLog readEmAsmArgs jstoi_q getExecutableName listenOnce autoResumeAudioContext getDynCaller dynCall callUserCallback asmjsMangle asyncLoad mmapAlloc HandleAllocator getNativeTypeSize STACK_SIZE STACK_ALIGN POINTER_SIZE ASSERTIONS getCFunc ccall cwrap uleb128Encode sigToWasmTypes generateFuncType convertJsFunctionToWasm getEmptyTableSlot updateTableMap getFunctionAddress addFunction removeFunction reallyNegative unSign strLen reSign formatString setValue getValue stringToUTF8Array stringToUTF8 lengthBytesUTF8 intArrayFromString intArrayToString AsciiToString stringToAscii UTF16ToString lengthBytesUTF16 UTF32ToString stringToUTF32 lengthBytesUTF32 stringToNewUTF8 stringToUTF8OnStack writeArrayToMemory registerKeyEventCallback maybeCStringToJsString findEventTarget getBoundingClientRect fillMouseEventData registerMouseEventCallback registerWheelEventCallback registerUiEventCallback registerFocusEventCallback fillDeviceOrientationEventData registerDeviceOrientationEventCallback fillDeviceMotionEventData registerDeviceMotionEventCallback screenOrientation fillOrientationChangeEventData registerOrientationChangeEventCallback fillFullscreenChangeEventData registerFullscreenChangeEventCallback JSEvents_requestFullscreen JSEvents_resizeCanvasForFullscreen registerRestoreOldStyle hideEverythingExceptGivenElement restoreHiddenElements setLetterbox softFullscreenResizeWebGLRenderTarget doRequestFullscreen fillPointerlockChangeEventData registerPointerlockChangeEventCallback registerPointerlockErrorEventCallback requestPointerLock fillVisibilityChangeEventData registerVisibilityChangeEventCallback registerTouchEventCallback fillGamepadEventData registerGamepadEventCallback registerBeforeUnloadEventCallback fillBatteryEventData battery registerBatteryEventCallback setCanvasElementSize getCanvasElementSize jsStackTrace getCallstack convertPCtoSourceLocation getEnvStrings checkWasiClock wasiRightsToMuslOFlags wasiOFlagsToMuslOFlags initRandomFill randomFill safeSetTimeout setImmediateWrapped safeRequestAnimationFrame clearImmediateWrapped polyfillSetImmediate registerPostMainLoop registerPreMainLoop getPromise makePromise idsToPromises makePromiseCallback isLeapYear ydayFromDate arraySum addDays getSocketFromFD getSocketAddress ALLOC_NORMAL ALLOC_STACK allocate writeStringToMemory writeAsciiToMemory setErrNo demangle stackTrace".split(' ').forEach(function(a) {
183
+ L(a, ()=>{
184
+ var b = `\`${a}\` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line`, c = a;
185
+ c.startsWith('_') || (c = '$' + a);
186
+ b += ` (e.g. -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='${c}')`;
187
+ K(a) && (b += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you');
188
+ N(b);
189
+ });
190
+ O(a);
191
+ });
192
+ 'run addOnPreRun addOnInit addOnPreMain addOnExit addOnPostRun addRunDependency removeRunDependency out err callMain abort wasmMemory wasmExports HEAPF32 HEAPF64 HEAP_DATA_VIEW HEAP8 HEAPU8 HEAP16 HEAPU16 HEAP32 HEAPU32 HEAP64 HEAPU64 writeStackCookie checkStackCookie INT53_MAX INT53_MIN bigintToI53Checked ptrToString getHeapMax growMemory ENV ERRNO_CODES DNS Protocols Sockets timers warnOnce readEmAsmArgsArray jstoi_s alignMemory wasmTable noExitRuntime freeTableIndexes functionsInTableMap PATH PATH_FS UTF8Decoder UTF8ArrayToString UTF8ToString UTF16Decoder JSEvents specialHTMLTargets findCanvasEventTarget currentFullscreenStrategy restoreOldWindowedStyle UNWIND_CACHE promiseMap MONTH_DAYS_REGULAR MONTH_DAYS_LEAP MONTH_DAYS_REGULAR_CUMULATIVE MONTH_DAYS_LEAP_CUMULATIVE SYSCALLS allocateUTF8 allocateUTF8OnStack print printErr'.split(' ').forEach(O);
193
+ var T, U, W = {
194
+ env: S,
195
+ wasi_snapshot_preview1: S
196
+ };
197
+ if (!f.wasm) throw "Must load WebAssembly Module in to variable Module.wasm before adding compiled output .js script to the DOM";
198
+ WebAssembly.instantiate(f.wasm, W).then((a)=>{
199
+ a = a.instance.exports;
200
+ f._begin_chunk = a.begin_chunk;
201
+ f._begin_index_lock = a.begin_index_lock;
202
+ f._check_similar = a.check_similar;
203
+ f._malloc = a.malloc;
204
+ T = a.emscripten_stack_init;
205
+ U = a.emscripten_stack_get_end;
206
+ E = a.memory;
207
+ v(E);
208
+ H();
209
+ T();
210
+ var b = U();
211
+ v(0 == (3 & b));
212
+ 0 == b && (b += 4);
213
+ D[b >> 2] = 34821223;
214
+ D[b + 4 >> 2] = 2310721022;
215
+ a.__wasm_call_ctors();
216
+ g(f);
217
+ r('ready() called, and INVOKE_RUN=0. The runtime is now ready for you to call run() to invoke application _main(). You can also override ready() in a --pre-js file to get this signal as a callback');
218
+ }, (a)=>{
219
+ console.error(a);
220
+ });
221
+ moduleRtn = m;
222
+ for (const a of Object.keys(f))a in moduleArg || Object.defineProperty(moduleArg, a, {
223
+ configurable: !0,
224
+ get () {
225
+ q(`Access to module property ('${a}') is no longer possible via the module constructor argument; Instead, use the result of the module constructor.`);
226
+ }
227
+ });
228
+ return moduleRtn;
229
+ };
230
+ const similarity_gen = Module;
231
+ let similarity_stub_module = null;
232
+ let ptr_buf;
233
+ const MAX_STRING_LEN = 16005;
234
+ async function similarity_stub_init(wasm_module) {
235
+ similarity_stub_module = await similarity_gen({
236
+ wasm: wasm_module
237
+ });
238
+ ptr_buf = similarity_stub_module._malloc(2 * MAX_STRING_LEN + 7);
239
+ if (ptr_buf % 2) ptr_buf++;
240
+ }
241
+ function begin_chunk(config) {
242
+ try {
243
+ similarity_stub_module._begin_chunk(ptr_buf, config.MAX_DIST, config.MAX_COSINE, config.TRIM_PINYIN, config.CROSS_MODE);
244
+ } catch (error) {
245
+ throw new Error(`wasm error (begin_chunk):\n${error}`);
246
+ }
247
+ }
248
+ function begin_index_lock() {
249
+ try {
250
+ similarity_stub_module._begin_index_lock();
251
+ } catch (error) {
252
+ throw new Error(`wasm error (begin_index_lock):\n${error}`);
253
+ }
254
+ }
255
+ function detect_similarity(str, mode, index_l, S) {
256
+ try {
257
+ similarity_stub_module.stringToUTF16(str, ptr_buf, 2 * MAX_STRING_LEN);
258
+ } catch (error) {
259
+ throw new Error(`wasm error (write str buf): ${str}\n${error}`);
260
+ }
261
+ let ret;
262
+ try {
263
+ ret = similarity_stub_module._check_similar(mode, index_l);
264
+ } catch (error) {
265
+ throw new Error(`wasm error (similar): ${str}\n${error}`);
266
+ }
267
+ if (0 === ret) return null;
268
+ ret >>>= 0;
269
+ const reason = ret >>> 30;
270
+ const dist = ret >>> 19 & 2047;
271
+ const idx_diff = 524287 & ret;
272
+ let reason_str;
273
+ if (0 === reason) {
274
+ S.combined_identical++;
275
+ reason_str = '==';
276
+ } else if (1 === reason) {
277
+ S.combined_edit_distance++;
278
+ reason_str = `\u{2264}${dist}`;
279
+ } else if (3 === reason) {
280
+ S.combined_cosine_distance++;
281
+ reason_str = `${dist}%`;
282
+ } else if (2 === reason) {
283
+ S.combined_pinyin_distance++;
284
+ reason_str = `P\u{2264}${dist}`;
285
+ } else throw new Error(`similarity wasm returned unknown reason: ${ret}`);
286
+ return {
287
+ reason: reason_str,
288
+ idx_diff
289
+ };
290
+ }
291
+ var _computedKey;
292
+ class Stats {
293
+ combined_identical = 0;
294
+ combined_edit_distance = 0;
295
+ combined_pinyin_distance = 0;
296
+ combined_cosine_distance = 0;
297
+ deleted_blacklist = 0;
298
+ deleted_blacklist_each = {};
299
+ ignored_whitelist = 0;
300
+ ignored_type = 0;
301
+ num_taolu_matched = 0;
302
+ }
303
+ _computedKey = Symbol.iterator;
304
+ class Queue {
305
+ storage;
306
+ index_l;
307
+ index_r;
308
+ constructor(init = []){
309
+ this.storage = {
310
+ ...init
311
+ };
312
+ this.index_l = 0;
313
+ this.index_r = init.length;
314
+ }
315
+ push(item) {
316
+ this.storage[this.index_r++] = item;
317
+ }
318
+ pop() {
319
+ delete this.storage[this.index_l++];
320
+ }
321
+ peek() {
322
+ if (this.index_l === this.index_r) return null;
323
+ return this.storage[this.index_l];
324
+ }
325
+ size() {
326
+ return this.index_r - this.index_l;
327
+ }
328
+ [_computedKey]() {
329
+ const self = this;
330
+ let index = self.index_l;
331
+ return {
332
+ next () {
333
+ if (index >= self.index_r) return {
334
+ done: true,
335
+ value: void 0
336
+ };
337
+ return {
338
+ done: false,
339
+ value: self.storage[index++]
340
+ };
341
+ }
342
+ };
343
+ }
344
+ }
345
+ /**
346
+ * @author: xmcp(代码主要逻辑来源)
347
+ * @see: https://github.com/xmcp/pakku.js
348
+ * @license: GPL-3.0
349
+ * 本文件内代码来源见上,经部分修改,并整合config注释
350
+ */ const DEFAULT_CONFIG = {
351
+ THRESHOLD: 30,
352
+ MAX_DIST: 5,
353
+ MAX_COSINE: 45,
354
+ TRIM_PINYIN: true,
355
+ TRIM_ENDING: true,
356
+ TRIM_SPACE: true,
357
+ TRIM_WIDTH: true,
358
+ FORCELIST: [
359
+ [
360
+ '^23{2,}$',
361
+ '23333'
362
+ ],
363
+ [
364
+ '^6{3,}$',
365
+ '66666'
366
+ ]
367
+ ],
368
+ WHITELIST: [],
369
+ BLACKLIST: [],
370
+ CROSS_MODE: true,
371
+ PROC_TYPE7: true,
372
+ PROC_TYPE4: true,
373
+ PROC_POOL1: false
374
+ };
375
+ const ENDING_CHARS = new Set(".\u3002,\uFF0C/?\uFF1F!\uFF01\u2026~\uFF5E@^\u3001+=-_\u2642\u2640 ");
376
+ const WIDTH_TABLE = new Map(Object.entries({
377
+ "\u3000": ' ',
378
+ "\uFF11": '1',
379
+ "\uFF12": '2',
380
+ "\uFF13": '3',
381
+ "\uFF14": '4',
382
+ "\uFF15": '5',
383
+ "\uFF16": '6',
384
+ "\uFF17": '7',
385
+ "\uFF18": '8',
386
+ "\uFF19": '9',
387
+ "\uFF10": '0',
388
+ '!': "\uFF01",
389
+ "\uFF20": '@',
390
+ "\uFF03": '#',
391
+ "\uFF04": '$',
392
+ "\uFF05": '%',
393
+ "\uFF3E": '^',
394
+ "\uFF06": '&',
395
+ "\uFF0A": '*',
396
+ "\uFF08": '(',
397
+ "\uFF09": ')',
398
+ "\uFF0D": '-',
399
+ "\uFF1D": '=',
400
+ "\uFF3F": '_',
401
+ "\uFF0B": '+',
402
+ "\uFF3B": '[',
403
+ "\uFF3D": ']',
404
+ "\uFF5B": '{',
405
+ "\uFF5D": '}',
406
+ ';': "\uFF1B",
407
+ "\uFF07": "'",
408
+ ':': "\uFF1A",
409
+ "\uFF02": '"',
410
+ ',': "\uFF0C",
411
+ "\uFF0E": '.',
412
+ "\uFF0F": '/',
413
+ "\uFF1C": '<',
414
+ "\uFF1E": '>',
415
+ '?': "\uFF1F",
416
+ "\uFF3C": '\\',
417
+ "\uFF5C": '|',
418
+ "\uFF40": '`',
419
+ "\uFF5E": '~',
420
+ q: 'q',
421
+ w: 'w',
422
+ e: 'e',
423
+ r: 'r',
424
+ t: 't',
425
+ y: 'y',
426
+ u: 'u',
427
+ i: 'i',
428
+ o: 'o',
429
+ p: 'p',
430
+ a: 'a',
431
+ s: 's',
432
+ d: 'd',
433
+ f: 'f',
434
+ g: 'g',
435
+ h: 'h',
436
+ j: 'j',
437
+ k: 'k',
438
+ l: 'l',
439
+ z: 'z',
440
+ x: 'x',
441
+ c: 'c',
442
+ v: 'v',
443
+ b: 'b',
444
+ n: 'n',
445
+ m: 'm',
446
+ Q: 'Q',
447
+ W: 'W',
448
+ E: 'E',
449
+ R: 'R',
450
+ T: 'T',
451
+ Y: 'Y',
452
+ U: 'U',
453
+ I: 'I',
454
+ O: 'O',
455
+ P: 'P',
456
+ A: 'A',
457
+ S: 'S',
458
+ D: 'D',
459
+ F: 'F',
460
+ G: 'G',
461
+ H: 'H',
462
+ J: 'J',
463
+ K: 'K',
464
+ L: 'L',
465
+ Z: 'Z',
466
+ X: 'X',
467
+ C: 'C',
468
+ V: 'V',
469
+ B: 'B',
470
+ N: 'N',
471
+ M: 'M'
472
+ }));
473
+ const detaolu = (inp, config)=>{
474
+ const TRIM_ENDING = config.TRIM_ENDING;
475
+ const TRIM_SPACE = config.TRIM_SPACE;
476
+ const TRIM_WIDTH = config.TRIM_WIDTH;
477
+ const FORCELIST = (config?.FORCELIST ?? DEFAULT_CONFIG.FORCELIST).map(([pattern, repl])=>[
478
+ new RegExp(pattern, 'gi'),
479
+ repl
480
+ ]);
481
+ let len = inp.length;
482
+ let text = '';
483
+ if (TRIM_ENDING) {
484
+ while(ENDING_CHARS.has(inp.charAt(len - 1)))len--;
485
+ if (0 === len) len = inp.length;
486
+ }
487
+ if (TRIM_WIDTH) for(let i = 0; i < len; i++){
488
+ const c = inp.charAt(i);
489
+ text += WIDTH_TABLE.get(c) || c;
490
+ }
491
+ else text = inp.slice(0, len);
492
+ if (TRIM_SPACE) text = text.replaceAll(/[ \u3000]+/g, ' ').replaceAll(/([\u3000-\u9FFF\uFF00-\uFFEF]) (?=[\u3000-\u9FFF\uFF00-\uFFEF])/g, '$1');
493
+ for (const taolu of FORCELIST)if (taolu[0].test(text)) {
494
+ text = text.replace(taolu[0], taolu[1]);
495
+ return [
496
+ true,
497
+ text
498
+ ];
499
+ }
500
+ return [
501
+ false,
502
+ text
503
+ ];
504
+ };
505
+ const whitelisted = (text, config)=>{
506
+ const WHITELIST = (config?.WHITELIST ?? DEFAULT_CONFIG.WHITELIST).map((x)=>new RegExp(x[0], 'i'));
507
+ if (0 === WHITELIST.length) return false;
508
+ return WHITELIST.some((re)=>re.test(text));
509
+ };
510
+ const blacklisted = (text, config)=>{
511
+ const BLACKLIST = (config?.BLACKLIST ?? DEFAULT_CONFIG.BLACKLIST).map((x)=>x[0] ? new RegExp(x[1]) : x[1].toLowerCase());
512
+ if (0 === BLACKLIST.length) return null;
513
+ {
514
+ const lower = text.toLowerCase();
515
+ for (const pattern of BLACKLIST){
516
+ const matched = 'string' == typeof pattern ? lower.includes(pattern) : pattern.test(text);
517
+ if (matched) return 'string' == typeof pattern ? ` ${pattern}` : ` /${pattern.source}/`;
518
+ }
519
+ return null;
520
+ }
521
+ };
522
+ function extract_special_danmu(text) {
523
+ try {
524
+ text = JSON.parse(text)[4];
525
+ } catch {}
526
+ return text;
527
+ }
528
+ function trim_dispstr(text) {
529
+ return text.replaceAll(/([\r\n\t])/g, '').trim();
530
+ }
531
+ function select_median_length(strs) {
532
+ if (1 === strs.length) return strs[0];
533
+ const sorted = strs.sort((a, b)=>a.length - b.length);
534
+ const mid = Math.floor(sorted.length / 2);
535
+ return sorted[mid];
536
+ }
537
+ async function load_wasm(wasm_mod) {
538
+ await similarity_stub_init(wasm_mod ?? await fs_extra.readFile(new URL('./similarity-gen.wasm', import.meta.url)));
539
+ }
540
+ async function merge(chunk, config = DEFAULT_CONFIG) {
541
+ await load_wasm();
542
+ begin_chunk(config);
543
+ const ret = {
544
+ clusters: [],
545
+ stats: new Stats()
546
+ };
547
+ function apply_single_cluster(idx, obj, desc) {
548
+ ret.clusters.push({
549
+ peers_ptr: [
550
+ [
551
+ idx,
552
+ 'IGN'
553
+ ]
554
+ ],
555
+ desc: [
556
+ desc
557
+ ],
558
+ chosen_str: obj.content,
559
+ danuni_count: 1,
560
+ danuni_dans: [
561
+ obj
562
+ ]
563
+ });
564
+ }
565
+ function apply_cluster(irs) {
566
+ if (1 === irs.length) ret.clusters.push({
567
+ peers_ptr: irs.map((ir)=>[
568
+ ir.idx,
569
+ ir.sim_reason
570
+ ]),
571
+ desc: [],
572
+ chosen_str: irs[0].obj.content,
573
+ danuni_count: irs.length,
574
+ danuni_dans: irs.map((ir)=>ir.obj)
575
+ });
576
+ else {
577
+ const text_cnts = new Map();
578
+ let most_texts = [], most_cnt = 0;
579
+ for (const ir of irs){
580
+ const text = ir.str;
581
+ const cnt = 1 + (text_cnts.get(text) || 0);
582
+ text_cnts.set(text, cnt);
583
+ if (cnt > most_cnt) {
584
+ most_texts = [
585
+ text
586
+ ];
587
+ most_cnt = cnt;
588
+ } else if (cnt === most_cnt) most_texts.push(text);
589
+ }
590
+ const most_text = select_median_length(most_texts);
591
+ ret.clusters.push({
592
+ peers_ptr: irs.map((ir)=>[
593
+ ir.idx,
594
+ ir.sim_reason
595
+ ]),
596
+ desc: most_cnt > 1 ? [
597
+ `\u{91C7}\u{7528}\u{4E86}\u{51FA}\u{73B0} ${most_cnt} \u{6B21}\u{7684}\u{6587}\u{672C}`
598
+ ] : [],
599
+ chosen_str: most_text,
600
+ danuni_count: most_cnt,
601
+ danuni_dans: irs.map((ir)=>ir.obj)
602
+ });
603
+ }
604
+ }
605
+ function obj_to_ir(objs, s) {
606
+ return objs.map((obj, idx)=>{
607
+ if (!config.PROC_POOL1 && 1 === obj.pool) {
608
+ if (s) {
609
+ s.ignored_type++;
610
+ apply_single_cluster(idx, obj, "\u5DF2\u5FFD\u7565\u5B57\u5E55\u5F39\u5E55\uFF0C\u53EF\u4EE5\u5728\u9009\u9879\u4E2D\u4FEE\u6539");
611
+ }
612
+ return null;
613
+ }
614
+ if (!config.PROC_TYPE7 && 4 === obj.mode) {
615
+ if (s) {
616
+ s.ignored_type++;
617
+ apply_single_cluster(idx, obj, "\u5DF2\u5FFD\u7565\u7279\u6B8A\u5F39\u5E55\uFF0C\u53EF\u4EE5\u5728\u9009\u9879\u4E2D\u4FEE\u6539");
618
+ }
619
+ return null;
620
+ }
621
+ if (!config.PROC_TYPE4 && 1 === obj.mode) {
622
+ if (s) {
623
+ s.ignored_type++;
624
+ apply_single_cluster(idx, obj, "\u5DF2\u5FFD\u7565\u5E95\u90E8\u5F39\u5E55\uFF0C\u53EF\u4EE5\u5728\u9009\u9879\u4E2D\u4FEE\u6539");
625
+ }
626
+ return null;
627
+ }
628
+ const disp_str = trim_dispstr(4 === obj.mode && '[' === obj.content[0] ? extract_special_danmu(obj.content) : obj.content);
629
+ if (4 !== obj.mode) {
630
+ const matched = blacklisted(disp_str, config);
631
+ if (matched) {
632
+ if (s) {
633
+ s.deleted_blacklist++;
634
+ s.deleted_blacklist_each[matched] = (s.deleted_blacklist_each[matched] || 0) + 1;
635
+ }
636
+ return null;
637
+ }
638
+ }
639
+ if (whitelisted(disp_str, config)) {
640
+ if (s) {
641
+ s.ignored_whitelist++;
642
+ apply_single_cluster(idx, obj, "\u547D\u4E2D\u767D\u540D\u5355");
643
+ }
644
+ return null;
645
+ }
646
+ const [matched_taolu, detaolued] = detaolu(disp_str, config);
647
+ if (matched_taolu && s) s.num_taolu_matched++;
648
+ return {
649
+ obj,
650
+ str: detaolued,
651
+ idx,
652
+ sim_reason: 'ORIG'
653
+ };
654
+ }).filter((obj)=>null !== obj);
655
+ }
656
+ const danmus = obj_to_ir(chunk.objs, ret.stats);
657
+ const nearby_danmus = new Queue();
658
+ const THRESHOLD_MS = (config?.THRESHOLD ?? DEFAULT_CONFIG.THRESHOLD) * 1000;
659
+ for (const dm of danmus){
660
+ while(true){
661
+ const peeked = nearby_danmus.peek();
662
+ if (null === peeked || dm.obj.time_ms - peeked[0].obj.time_ms <= THRESHOLD_MS) break;
663
+ apply_cluster(peeked);
664
+ nearby_danmus.pop();
665
+ }
666
+ const sim = detect_similarity(dm.str, dm.obj.mode, nearby_danmus.index_l, ret.stats);
667
+ if (null !== sim) {
668
+ const candidate = nearby_danmus.storage[nearby_danmus.index_r - sim.idx_diff];
669
+ dm.sim_reason = sim.reason;
670
+ candidate.push(dm);
671
+ } else nearby_danmus.push([
672
+ dm
673
+ ]);
674
+ }
675
+ begin_index_lock();
676
+ for (const candidate of nearby_danmus)apply_cluster(candidate);
677
+ return ret;
678
+ }
679
+ const pakku_js = merge;
680
+ async function src_detaolu(that, config) {
681
+ const p = await pakku_js({
682
+ objs: that.dans.map((d)=>({
683
+ time_ms: 1000 * d.progress,
684
+ mode: d.mode,
685
+ content: d.content,
686
+ pool: d.pool,
687
+ danuni_dan: d
688
+ }))
689
+ }, config);
690
+ const selected = p.clusters.map((p)=>{
691
+ if (1 === p.danuni_dans.length) return p.danuni_dans[0].danuni_dan;
692
+ {
693
+ const dans = p.danuni_dans, pool = new UniPool(dans.map((d)=>d.danuni_dan));
694
+ function isAllBottomMode(p) {
695
+ return p.dans.every((d)=>d.mode === UniDMTools.Modes.Bottom);
696
+ }
697
+ const progess = pool.dans.map((d)=>d.progress);
698
+ return UniDM.create({
699
+ SOID: pool.shared.SOID ?? pool.dans[0].SOID,
700
+ progress: dans[0].danuni_dan.progress,
701
+ mode: pool.shared.mode ?? (isAllBottomMode(pool) ? UniDMTools.Modes.Bottom : UniDMTools.Modes.Top),
702
+ fontsize: dans.length > 0 ? 36 : 25,
703
+ color: pool.shared.color ?? pool.most.color,
704
+ senderID: 'detaolu[bot]@dan-any',
705
+ content: p.chosen_str,
706
+ weight: 10,
707
+ pool: pool.shared.pool ?? pool.most.pool,
708
+ attr: [
709
+ 'Protect'
710
+ ],
711
+ platform: pool.shared.platform ?? pool.most.platform,
712
+ extra: {
713
+ danuni: {
714
+ merge: {
715
+ count: p.danuni_count,
716
+ duration: Math.max(...progess) - Math.min(...progess),
717
+ senders: pool.dans.filter((d)=>d.content === p.chosen_str).map((d)=>d.senderID),
718
+ taolu_count: pool.dans.length,
719
+ taolu_senders: pool.dans.map((d)=>d.senderID)
720
+ }
721
+ }
722
+ }
723
+ });
724
+ }
725
+ });
726
+ return new UniPool(selected);
727
+ }
728
+ function detaolu_constructor(config) {
729
+ return (that)=>src_detaolu(that, config);
730
+ }
731
+ const src = detaolu_constructor;
732
+ export { src as default };