@qwen-code/qwen-code 0.18.0-preview.2 → 0.18.1
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/bundled/loop/SKILL.md +2 -1
- package/bundled/qc-helper/docs/_meta.ts +1 -0
- package/bundled/qc-helper/docs/configuration/auth.md +1 -1
- package/bundled/qc-helper/docs/configuration/model-providers.md +12 -5
- package/bundled/qc-helper/docs/configuration/settings.md +33 -32
- package/bundled/qc-helper/docs/features/approval-mode.md +10 -14
- package/bundled/qc-helper/docs/features/commands.md +33 -11
- package/bundled/qc-helper/docs/features/dual-output.md +37 -3
- package/bundled/qc-helper/docs/features/followup-suggestions.md +2 -2
- package/bundled/qc-helper/docs/features/skills.md +29 -3
- package/bundled/qc-helper/docs/features/sub-agents.md +34 -12
- package/bundled/qc-helper/docs/qwen-serve-deploy-local.md +221 -0
- package/bundled/qc-helper/docs/qwen-serve.md +246 -28
- package/chunks/{agent-QB7TZ4HW.js → agent-XT7NHZ5H.js} +25 -24
- package/chunks/agent-headless-LNRE63ZL.js +51 -0
- package/chunks/{anthropicContentGenerator-M45EVVRM.js → anthropicContentGenerator-DCI26OQF.js} +7 -7
- package/chunks/{askUserQuestion-WM2KHM3K.js → askUserQuestion-ITYUTWLR.js} +45 -3
- package/chunks/{ca-BARBRL6N.js → ca-RK4QPLIX.js} +18 -1
- package/chunks/{chunk-CWV3SJZS.js → chunk-3NRO6NHX.js} +2 -2
- package/chunks/{chunk-BNESGOSJ.js → chunk-55ZMG67I.js} +1 -1
- package/chunks/{chunk-QCG6KPNM.js → chunk-6T7Y7USE.js} +18017 -11621
- package/chunks/{chunk-CNHFPN7T.js → chunk-7KPZFE5A.js} +1 -1
- package/chunks/{chunk-2ZTWI7KH.js → chunk-A2ZIEEGJ.js} +30 -22
- package/chunks/{chunk-JUGRPQAB.js → chunk-B4ZF2KSI.js} +1 -1
- package/chunks/chunk-BJ5HQ23U.js +178 -0
- package/chunks/{chunk-HXJE7VOG.js → chunk-BXYRCW2C.js} +1074 -144
- package/chunks/{chunk-ICOI4E4S.js → chunk-CPVI5J2L.js} +101 -23
- package/chunks/{chunk-HV3ZZ7G4.js → chunk-DHZREJTG.js} +2 -2
- package/chunks/{chunk-GX7VH5JQ.js → chunk-FIQECJTQ.js} +1 -1
- package/chunks/{chunk-SZOEIL6S.js → chunk-H6BD2ELD.js} +1 -0
- package/chunks/{chunk-JXAZUMDW.js → chunk-HA2UEYZP.js} +7 -4
- package/chunks/{chunk-USE2VQ5P.js → chunk-HED55F43.js} +26 -1
- package/chunks/{chunk-PAEBHDIO.js → chunk-HQUWWSSP.js} +1 -1
- package/chunks/{chunk-MVIVIPCU.js → chunk-IDYDPBBN.js} +361 -583
- package/chunks/{chunk-JVQOQ3OU.js → chunk-IQHSD7K5.js} +1 -1
- package/chunks/{chunk-NW5QBUYO.js → chunk-IS7UA4W3.js} +14 -14
- package/chunks/{chunk-UAMOBVVW.js → chunk-LXYWINWF.js} +1 -1
- package/chunks/{chunk-P4J26VDS.js → chunk-LYRSMKLS.js} +2 -2
- package/chunks/{chunk-Y7R6H6FT.js → chunk-LYSND7KR.js} +9 -4
- package/chunks/{chunk-LR62TEET.js → chunk-NNIYWQIS.js} +1 -1
- package/chunks/chunk-OMX7CUOE.js +356 -0
- package/chunks/{chunk-CNSMKPK6.js → chunk-QILTEBWS.js} +1 -1
- package/chunks/chunk-QQDPRDVW.js +25 -0
- package/chunks/{chunk-ZK4AMNIU.js → chunk-RON7LFNH.js} +1294 -314
- package/chunks/chunk-SFRV6BGY.js +243 -0
- package/chunks/{chunk-AVW55ZCO.js → chunk-WJ3SND6W.js} +37 -16
- package/chunks/{chunk-HGJPQK33.js → chunk-WPTCDQN6.js} +188 -534
- package/chunks/{chunk-7YKXFA3D.js → chunk-XZTNBSMW.js} +11 -11
- package/chunks/{chunk-C6WMLUNB.js → chunk-Y7KMDUEP.js} +1 -1
- package/chunks/{chunk-WFVXF3OM.js → chunk-Z2Z3GUXZ.js} +1 -0
- package/chunks/{chunk-KC6ZMJ5X.js → chunk-ZMIBJS45.js} +1 -1
- package/chunks/chunk-ZOFNJQNJ.js +607 -0
- package/chunks/computer-use-4YX3JGBV.js +2052 -0
- package/chunks/contextCommand-KS2H7MW5.js +53 -0
- package/chunks/cron-create-CAPUKK7I.js +184 -0
- package/chunks/{cron-delete-ZGUXWBTG.js → cron-delete-G3KAR26Q.js} +28 -5
- package/chunks/{cron-list-QNNZGMN3.js → cron-list-ZA4ZIUS5.js} +40 -7
- package/chunks/{de-YGKK2BC4.js → de-FGPM4KW5.js} +18 -1
- package/chunks/{devtools-IXE4UP72.js → devtools-FM6GJPYG.js} +1 -1
- package/chunks/{dist-ZMQ4TXD5.js → dist-7YWFWOCJ.js} +2 -2
- package/chunks/{dist-R2SXPG74.js → dist-VEGFONCF.js} +2 -2
- package/chunks/{dist-TE5QKMGR.js → dist-X4EXN7W6.js} +1 -1
- package/chunks/{dist-BXDUQ2QY.js → dist-YLS6NI7H.js} +1 -1
- package/chunks/{edit-6UBTS2J5.js → edit-2ARPEO4B.js} +26 -25
- package/chunks/{en-HSQQNQUB.js → en-VP6XPGEC.js} +9 -2
- package/chunks/{enter-worktree-NN7LIXCM.js → enter-worktree-IXNXNAW5.js} +25 -24
- package/chunks/enterPlanMode-TAKAGAYP.js +159 -0
- package/chunks/{exit-worktree-GGSS5KIE.js → exit-worktree-LHTRV7ML.js} +25 -24
- package/chunks/exitPlanMode-MK5UAITL.js +743 -0
- package/chunks/{fr-JXBKPJKQ.js → fr-ATYBVCLT.js} +18 -1
- package/chunks/{geminiContentGenerator-I4H2NLJG.js → geminiContentGenerator-HFJIGO77.js} +7 -7
- package/chunks/{getMachineId-bsd-F7GNPTER.js → getMachineId-bsd-4CASPIU4.js} +1 -1
- package/chunks/{getMachineId-darwin-T73DJL27.js → getMachineId-darwin-HPQPEMZR.js} +1 -1
- package/chunks/{getMachineId-linux-MKQTFPQM.js → getMachineId-linux-AUARKYHL.js} +1 -1
- package/chunks/{getMachineId-unsupported-MUR5KOQE.js → getMachineId-unsupported-S32ZDA2T.js} +1 -1
- package/chunks/{getMachineId-win-CDYFC6ZM.js → getMachineId-win-4EFLHYIJ.js} +1 -1
- package/chunks/{glob-OLCX57MD.js → glob-I2USLUSC.js} +25 -24
- package/chunks/{grep-7HXIMDOW.js → grep-WBIF7THR.js} +37 -30
- package/chunks/{ja-TGPZSP2B.js → ja-W2QEA2OI.js} +18 -1
- package/chunks/{keychain-token-storage-LB46DAEK.js → keychain-token-storage-QSTRHKKL.js} +3 -3
- package/chunks/{ls-6PEZUK6O.js → ls-2R5RHLX5.js} +4 -4
- package/chunks/{lsp-JZSJOVT7.js → lsp-XKH6ZIAN.js} +3 -3
- package/chunks/{monitor-SQO7MVAV.js → monitor-WU7UFATU.js} +25 -24
- package/chunks/{notebook-edit-72L3EBAL.js → notebook-edit-KUHYPXEM.js} +26 -25
- package/chunks/{openaiContentGenerator-FTR7CDWF.js → openaiContentGenerator-5PLHYJQL.js} +15 -15
- package/chunks/{pt-TIBG6BIO.js → pt-ZKEWJFBW.js} +18 -1
- package/chunks/{qwenContentGenerator-U5UFQ566.js → qwenContentGenerator-TSKW73KY.js} +27 -26
- package/chunks/{qwenOAuth2-EFSECGHF.js → qwenOAuth2-KK433U33.js} +6 -5
- package/chunks/{read-file-UA64EEQC.js → read-file-VIPF2PS6.js} +11 -11
- package/chunks/ripGrep-XLIZTYE7.js +49 -0
- package/chunks/{ru-JBCHCK4L.js → ru-VEKTPJ74.js} +18 -1
- package/chunks/{scheduler-VBASHOCA.js → scheduler-O66SLJGU.js} +25 -24
- package/chunks/{send-message-OYJZ5TPG.js → send-message-CTME7DXD.js} +3 -3
- package/chunks/{serve-A7E2OJDR.js → serve-BWOLYT62.js} +13164 -3840
- package/chunks/{shell-3NFOT6F5.js → shell-XE7UYKOO.js} +25 -24
- package/chunks/{skill-RA5YUREY.js → skill-RZWM6XMC.js} +64 -113
- package/chunks/{src-NFCMARMT.js → src-L5P7K4MH.js} +176 -44
- package/chunks/{syntheticOutput-DETQ2YM6.js → syntheticOutput-ZJGSU7OQ.js} +4 -4
- package/chunks/{task-create-Y3ZKTJIG.js → task-create-EE6JEM7G.js} +8 -7
- package/chunks/{task-list-ONXJ3I3A.js → task-list-EESYAC65.js} +7 -6
- package/chunks/{task-stop-UHDC4N5B.js → task-stop-XZVCFFYY.js} +3 -3
- package/chunks/{task-update-TCNOU3P5.js → task-update-EIO4HNE3.js} +21 -9
- package/chunks/{team-create-6SR4OVRG.js → team-create-R2H7Y3SG.js} +28 -26
- package/chunks/{team-delete-EJ4U4DDP.js → team-delete-A7LXPGV7.js} +9 -6
- package/chunks/{todoWrite-TEYDRS5L.js → todoWrite-VRKSGAWM.js} +5 -5
- package/chunks/{tool-search-OD435A3X.js → tool-search-USSQMTMS.js} +11 -11
- package/chunks/{web-fetch-6W67H5PO.js → web-fetch-GHAZUA54.js} +5 -5
- package/chunks/workflow-5LNNLNUR.js +1414 -0
- package/chunks/{write-file-475L5OPP.js → write-file-2I7HP24C.js} +26 -25
- package/chunks/{zh-VCLWO26Y.js → zh-OIXDDQHB.js} +10 -3
- package/chunks/{zh-TW-G3HFHVVT.js → zh-TW-6YFNCKTA.js} +10 -3
- package/cli-entry.js +19 -0
- package/cli.js +11064 -6628
- package/examples/starter/QWEN.md +30 -0
- package/examples/starter/README.md +59 -0
- package/examples/starter/agents/diary.md +86 -0
- package/examples/starter/commands/writing/polish.md +13 -0
- package/examples/starter/example.ts +64 -0
- package/examples/starter/package.json +18 -0
- package/examples/starter/qwen-extension.json +12 -0
- package/examples/starter/skills/synonyms/SKILL.md +48 -0
- package/examples/starter/tsconfig.json +13 -0
- package/fzfWorker.js +1083 -0
- package/locales/ca.js +20 -2
- package/locales/de.js +21 -2
- package/locales/en.js +13 -4
- package/locales/fr.js +22 -2
- package/locales/ja.js +22 -2
- package/locales/pt.js +21 -2
- package/locales/ru.js +20 -2
- package/locales/zh-TW.js +11 -4
- package/locales/zh.js +11 -4
- package/package.json +5 -3
- package/chunks/agent-headless-APVHH7QM.js +0 -50
- package/chunks/chunk-AJIR24J2.js +0 -59
- package/chunks/chunk-SKBPNJEW.js +0 -45
- package/chunks/chunk-XBFVXFB2.js +0 -216
- package/chunks/computer-use-B7VIUI7F.js +0 -825
- package/chunks/contextCommand-63RZ3O5R.js +0 -52
- package/chunks/cron-create-FI5LJVUS.js +0 -140
- package/chunks/exitPlanMode-H323NHB2.js +0 -235
- package/chunks/ripGrep-WSYCWZVK.js +0 -48
- package/chunks/workflow-62DHH4EO.js +0 -708
package/fzfWorker.js
ADDED
|
@@ -0,0 +1,1083 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
5
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
6
|
+
}) : x)(function(x) {
|
|
7
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
8
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// scripts/esbuild-shims.js
|
|
12
|
+
import { createRequire } from "node:module";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { dirname } from "node:path";
|
|
15
|
+
var _require = createRequire(import.meta.url);
|
|
16
|
+
if (typeof globalThis.require === "undefined") {
|
|
17
|
+
globalThis.require = _require;
|
|
18
|
+
}
|
|
19
|
+
var __qwen_filename = fileURLToPath(import.meta.url);
|
|
20
|
+
var __qwen_dirname = dirname(__qwen_filename);
|
|
21
|
+
|
|
22
|
+
// packages/core/src/utils/filesearch/fzfWorker.ts
|
|
23
|
+
import { parentPort } from "node:worker_threads";
|
|
24
|
+
|
|
25
|
+
// node_modules/fzf/dist/fzf.es.js
|
|
26
|
+
var normalized = {
|
|
27
|
+
216: "O",
|
|
28
|
+
223: "s",
|
|
29
|
+
248: "o",
|
|
30
|
+
273: "d",
|
|
31
|
+
295: "h",
|
|
32
|
+
305: "i",
|
|
33
|
+
320: "l",
|
|
34
|
+
322: "l",
|
|
35
|
+
359: "t",
|
|
36
|
+
383: "s",
|
|
37
|
+
384: "b",
|
|
38
|
+
385: "B",
|
|
39
|
+
387: "b",
|
|
40
|
+
390: "O",
|
|
41
|
+
392: "c",
|
|
42
|
+
393: "D",
|
|
43
|
+
394: "D",
|
|
44
|
+
396: "d",
|
|
45
|
+
398: "E",
|
|
46
|
+
400: "E",
|
|
47
|
+
402: "f",
|
|
48
|
+
403: "G",
|
|
49
|
+
407: "I",
|
|
50
|
+
409: "k",
|
|
51
|
+
410: "l",
|
|
52
|
+
412: "M",
|
|
53
|
+
413: "N",
|
|
54
|
+
414: "n",
|
|
55
|
+
415: "O",
|
|
56
|
+
421: "p",
|
|
57
|
+
427: "t",
|
|
58
|
+
429: "t",
|
|
59
|
+
430: "T",
|
|
60
|
+
434: "V",
|
|
61
|
+
436: "y",
|
|
62
|
+
438: "z",
|
|
63
|
+
477: "e",
|
|
64
|
+
485: "g",
|
|
65
|
+
544: "N",
|
|
66
|
+
545: "d",
|
|
67
|
+
549: "z",
|
|
68
|
+
564: "l",
|
|
69
|
+
565: "n",
|
|
70
|
+
566: "t",
|
|
71
|
+
567: "j",
|
|
72
|
+
570: "A",
|
|
73
|
+
571: "C",
|
|
74
|
+
572: "c",
|
|
75
|
+
573: "L",
|
|
76
|
+
574: "T",
|
|
77
|
+
575: "s",
|
|
78
|
+
576: "z",
|
|
79
|
+
579: "B",
|
|
80
|
+
580: "U",
|
|
81
|
+
581: "V",
|
|
82
|
+
582: "E",
|
|
83
|
+
583: "e",
|
|
84
|
+
584: "J",
|
|
85
|
+
585: "j",
|
|
86
|
+
586: "Q",
|
|
87
|
+
587: "q",
|
|
88
|
+
588: "R",
|
|
89
|
+
589: "r",
|
|
90
|
+
590: "Y",
|
|
91
|
+
591: "y",
|
|
92
|
+
592: "a",
|
|
93
|
+
593: "a",
|
|
94
|
+
595: "b",
|
|
95
|
+
596: "o",
|
|
96
|
+
597: "c",
|
|
97
|
+
598: "d",
|
|
98
|
+
599: "d",
|
|
99
|
+
600: "e",
|
|
100
|
+
603: "e",
|
|
101
|
+
604: "e",
|
|
102
|
+
605: "e",
|
|
103
|
+
606: "e",
|
|
104
|
+
607: "j",
|
|
105
|
+
608: "g",
|
|
106
|
+
609: "g",
|
|
107
|
+
610: "G",
|
|
108
|
+
613: "h",
|
|
109
|
+
614: "h",
|
|
110
|
+
616: "i",
|
|
111
|
+
618: "I",
|
|
112
|
+
619: "l",
|
|
113
|
+
620: "l",
|
|
114
|
+
621: "l",
|
|
115
|
+
623: "m",
|
|
116
|
+
624: "m",
|
|
117
|
+
625: "m",
|
|
118
|
+
626: "n",
|
|
119
|
+
627: "n",
|
|
120
|
+
628: "N",
|
|
121
|
+
629: "o",
|
|
122
|
+
633: "r",
|
|
123
|
+
634: "r",
|
|
124
|
+
635: "r",
|
|
125
|
+
636: "r",
|
|
126
|
+
637: "r",
|
|
127
|
+
638: "r",
|
|
128
|
+
639: "r",
|
|
129
|
+
640: "R",
|
|
130
|
+
641: "R",
|
|
131
|
+
642: "s",
|
|
132
|
+
647: "t",
|
|
133
|
+
648: "t",
|
|
134
|
+
649: "u",
|
|
135
|
+
651: "v",
|
|
136
|
+
652: "v",
|
|
137
|
+
653: "w",
|
|
138
|
+
654: "y",
|
|
139
|
+
655: "Y",
|
|
140
|
+
656: "z",
|
|
141
|
+
657: "z",
|
|
142
|
+
663: "c",
|
|
143
|
+
665: "B",
|
|
144
|
+
666: "e",
|
|
145
|
+
667: "G",
|
|
146
|
+
668: "H",
|
|
147
|
+
669: "j",
|
|
148
|
+
670: "k",
|
|
149
|
+
671: "L",
|
|
150
|
+
672: "q",
|
|
151
|
+
686: "h",
|
|
152
|
+
867: "a",
|
|
153
|
+
868: "e",
|
|
154
|
+
869: "i",
|
|
155
|
+
870: "o",
|
|
156
|
+
871: "u",
|
|
157
|
+
872: "c",
|
|
158
|
+
873: "d",
|
|
159
|
+
874: "h",
|
|
160
|
+
875: "m",
|
|
161
|
+
876: "r",
|
|
162
|
+
877: "t",
|
|
163
|
+
878: "v",
|
|
164
|
+
879: "x",
|
|
165
|
+
7424: "A",
|
|
166
|
+
7427: "B",
|
|
167
|
+
7428: "C",
|
|
168
|
+
7429: "D",
|
|
169
|
+
7431: "E",
|
|
170
|
+
7432: "e",
|
|
171
|
+
7433: "i",
|
|
172
|
+
7434: "J",
|
|
173
|
+
7435: "K",
|
|
174
|
+
7436: "L",
|
|
175
|
+
7437: "M",
|
|
176
|
+
7438: "N",
|
|
177
|
+
7439: "O",
|
|
178
|
+
7440: "O",
|
|
179
|
+
7441: "o",
|
|
180
|
+
7442: "o",
|
|
181
|
+
7443: "o",
|
|
182
|
+
7446: "o",
|
|
183
|
+
7447: "o",
|
|
184
|
+
7448: "P",
|
|
185
|
+
7449: "R",
|
|
186
|
+
7450: "R",
|
|
187
|
+
7451: "T",
|
|
188
|
+
7452: "U",
|
|
189
|
+
7453: "u",
|
|
190
|
+
7454: "u",
|
|
191
|
+
7455: "m",
|
|
192
|
+
7456: "V",
|
|
193
|
+
7457: "W",
|
|
194
|
+
7458: "Z",
|
|
195
|
+
7522: "i",
|
|
196
|
+
7523: "r",
|
|
197
|
+
7524: "u",
|
|
198
|
+
7525: "v",
|
|
199
|
+
7834: "a",
|
|
200
|
+
7835: "s",
|
|
201
|
+
8305: "i",
|
|
202
|
+
8341: "h",
|
|
203
|
+
8342: "k",
|
|
204
|
+
8343: "l",
|
|
205
|
+
8344: "m",
|
|
206
|
+
8345: "n",
|
|
207
|
+
8346: "p",
|
|
208
|
+
8347: "s",
|
|
209
|
+
8348: "t",
|
|
210
|
+
8580: "c"
|
|
211
|
+
};
|
|
212
|
+
for (let i = "\u0300".codePointAt(0); i <= "\u036F".codePointAt(0); ++i) {
|
|
213
|
+
const diacritic = String.fromCodePoint(i);
|
|
214
|
+
for (const asciiChar of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") {
|
|
215
|
+
const withDiacritic = (asciiChar + diacritic).normalize();
|
|
216
|
+
const withDiacriticCodePoint = withDiacritic.codePointAt(0);
|
|
217
|
+
if (withDiacriticCodePoint > 126) {
|
|
218
|
+
normalized[withDiacriticCodePoint] = asciiChar;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
var ranges = {
|
|
223
|
+
a: [7844, 7863],
|
|
224
|
+
e: [7870, 7879],
|
|
225
|
+
o: [7888, 7907],
|
|
226
|
+
u: [7912, 7921]
|
|
227
|
+
};
|
|
228
|
+
for (const lowerChar of Object.keys(ranges)) {
|
|
229
|
+
const upperChar = lowerChar.toUpperCase();
|
|
230
|
+
for (let i = ranges[lowerChar][0]; i <= ranges[lowerChar][1]; ++i) {
|
|
231
|
+
normalized[i] = i % 2 === 0 ? upperChar : lowerChar;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function normalizeRune(rune) {
|
|
235
|
+
if (rune < 192 || rune > 8580) {
|
|
236
|
+
return rune;
|
|
237
|
+
}
|
|
238
|
+
const normalizedChar = normalized[rune];
|
|
239
|
+
if (normalizedChar !== void 0)
|
|
240
|
+
return normalizedChar.codePointAt(0);
|
|
241
|
+
return rune;
|
|
242
|
+
}
|
|
243
|
+
__name(normalizeRune, "normalizeRune");
|
|
244
|
+
function toShort(number) {
|
|
245
|
+
return number;
|
|
246
|
+
}
|
|
247
|
+
__name(toShort, "toShort");
|
|
248
|
+
function toInt(number) {
|
|
249
|
+
return number;
|
|
250
|
+
}
|
|
251
|
+
__name(toInt, "toInt");
|
|
252
|
+
function maxInt16(num1, num2) {
|
|
253
|
+
return num1 > num2 ? num1 : num2;
|
|
254
|
+
}
|
|
255
|
+
__name(maxInt16, "maxInt16");
|
|
256
|
+
var strToRunes = /* @__PURE__ */ __name((str) => str.split("").map((s) => s.codePointAt(0)), "strToRunes");
|
|
257
|
+
var whitespaceRunes = new Set(
|
|
258
|
+
" \f\n\r \v\xA0\u1680\u2028\u2029\u202F\u205F\u3000\uFEFF".split("").map((v) => v.codePointAt(0))
|
|
259
|
+
);
|
|
260
|
+
for (let codePoint = "\u2000".codePointAt(0); codePoint <= "\u200A".codePointAt(0); codePoint++) {
|
|
261
|
+
whitespaceRunes.add(codePoint);
|
|
262
|
+
}
|
|
263
|
+
var MAX_ASCII = "\x7F".codePointAt(0);
|
|
264
|
+
var CAPITAL_A_RUNE = "A".codePointAt(0);
|
|
265
|
+
var CAPITAL_Z_RUNE = "Z".codePointAt(0);
|
|
266
|
+
var SMALL_A_RUNE = "a".codePointAt(0);
|
|
267
|
+
var SMALL_Z_RUNE = "z".codePointAt(0);
|
|
268
|
+
var NUMERAL_ZERO_RUNE = "0".codePointAt(0);
|
|
269
|
+
var NUMERAL_NINE_RUNE = "9".codePointAt(0);
|
|
270
|
+
function indexAt(index, max, forward) {
|
|
271
|
+
if (forward) {
|
|
272
|
+
return index;
|
|
273
|
+
}
|
|
274
|
+
return max - index - 1;
|
|
275
|
+
}
|
|
276
|
+
__name(indexAt, "indexAt");
|
|
277
|
+
var SCORE_MATCH = 16;
|
|
278
|
+
var SCORE_GAP_START = -3;
|
|
279
|
+
var SCORE_GAP_EXTENTION = -1;
|
|
280
|
+
var BONUS_BOUNDARY = SCORE_MATCH / 2;
|
|
281
|
+
var BONUS_NON_WORD = SCORE_MATCH / 2;
|
|
282
|
+
var BONUS_CAMEL_123 = BONUS_BOUNDARY + SCORE_GAP_EXTENTION;
|
|
283
|
+
var BONUS_CONSECUTIVE = -(SCORE_GAP_START + SCORE_GAP_EXTENTION);
|
|
284
|
+
var BONUS_FIRST_CHAR_MULTIPLIER = 2;
|
|
285
|
+
function createPosSet(withPos) {
|
|
286
|
+
if (withPos) {
|
|
287
|
+
return /* @__PURE__ */ new Set();
|
|
288
|
+
}
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
__name(createPosSet, "createPosSet");
|
|
292
|
+
function alloc16(offset, slab2, size) {
|
|
293
|
+
if (slab2 !== null && slab2.i16.length > offset + size) {
|
|
294
|
+
const subarray = slab2.i16.subarray(offset, offset + size);
|
|
295
|
+
return [offset + size, subarray];
|
|
296
|
+
}
|
|
297
|
+
return [offset, new Int16Array(size)];
|
|
298
|
+
}
|
|
299
|
+
__name(alloc16, "alloc16");
|
|
300
|
+
function alloc32(offset, slab2, size) {
|
|
301
|
+
if (slab2 !== null && slab2.i32.length > offset + size) {
|
|
302
|
+
const subarray = slab2.i32.subarray(offset, offset + size);
|
|
303
|
+
return [offset + size, subarray];
|
|
304
|
+
}
|
|
305
|
+
return [offset, new Int32Array(size)];
|
|
306
|
+
}
|
|
307
|
+
__name(alloc32, "alloc32");
|
|
308
|
+
function charClassOfAscii(rune) {
|
|
309
|
+
if (rune >= SMALL_A_RUNE && rune <= SMALL_Z_RUNE) {
|
|
310
|
+
return 1;
|
|
311
|
+
} else if (rune >= CAPITAL_A_RUNE && rune <= CAPITAL_Z_RUNE) {
|
|
312
|
+
return 2;
|
|
313
|
+
} else if (rune >= NUMERAL_ZERO_RUNE && rune <= NUMERAL_NINE_RUNE) {
|
|
314
|
+
return 4;
|
|
315
|
+
} else {
|
|
316
|
+
return 0;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
__name(charClassOfAscii, "charClassOfAscii");
|
|
320
|
+
function charClassOfNonAscii(rune) {
|
|
321
|
+
const char = String.fromCodePoint(rune);
|
|
322
|
+
if (char !== char.toUpperCase()) {
|
|
323
|
+
return 1;
|
|
324
|
+
} else if (char !== char.toLowerCase()) {
|
|
325
|
+
return 2;
|
|
326
|
+
} else if (char.match(new RegExp("\\p{Number}", "gu")) !== null) {
|
|
327
|
+
return 4;
|
|
328
|
+
} else if (char.match(new RegExp("\\p{Letter}", "gu")) !== null) {
|
|
329
|
+
return 3;
|
|
330
|
+
}
|
|
331
|
+
return 0;
|
|
332
|
+
}
|
|
333
|
+
__name(charClassOfNonAscii, "charClassOfNonAscii");
|
|
334
|
+
function charClassOf(rune) {
|
|
335
|
+
if (rune <= MAX_ASCII) {
|
|
336
|
+
return charClassOfAscii(rune);
|
|
337
|
+
}
|
|
338
|
+
return charClassOfNonAscii(rune);
|
|
339
|
+
}
|
|
340
|
+
__name(charClassOf, "charClassOf");
|
|
341
|
+
function bonusFor(prevClass, currClass) {
|
|
342
|
+
if (prevClass === 0 && currClass !== 0) {
|
|
343
|
+
return BONUS_BOUNDARY;
|
|
344
|
+
} else if (prevClass === 1 && currClass === 2 || prevClass !== 4 && currClass === 4) {
|
|
345
|
+
return BONUS_CAMEL_123;
|
|
346
|
+
} else if (currClass === 0) {
|
|
347
|
+
return BONUS_NON_WORD;
|
|
348
|
+
}
|
|
349
|
+
return 0;
|
|
350
|
+
}
|
|
351
|
+
__name(bonusFor, "bonusFor");
|
|
352
|
+
function bonusAt(input, idx) {
|
|
353
|
+
if (idx === 0) {
|
|
354
|
+
return BONUS_BOUNDARY;
|
|
355
|
+
}
|
|
356
|
+
return bonusFor(charClassOf(input[idx - 1]), charClassOf(input[idx]));
|
|
357
|
+
}
|
|
358
|
+
__name(bonusAt, "bonusAt");
|
|
359
|
+
function trySkip(input, caseSensitive, char, from) {
|
|
360
|
+
let rest = input.slice(from);
|
|
361
|
+
let idx = rest.indexOf(char);
|
|
362
|
+
if (idx === 0) {
|
|
363
|
+
return from;
|
|
364
|
+
}
|
|
365
|
+
if (!caseSensitive && char >= SMALL_A_RUNE && char <= SMALL_Z_RUNE) {
|
|
366
|
+
if (idx > 0) {
|
|
367
|
+
rest = rest.slice(0, idx);
|
|
368
|
+
}
|
|
369
|
+
const uidx = rest.indexOf(char - 32);
|
|
370
|
+
if (uidx >= 0) {
|
|
371
|
+
idx = uidx;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (idx < 0) {
|
|
375
|
+
return -1;
|
|
376
|
+
}
|
|
377
|
+
return from + idx;
|
|
378
|
+
}
|
|
379
|
+
__name(trySkip, "trySkip");
|
|
380
|
+
function isAscii(runes) {
|
|
381
|
+
for (const rune of runes) {
|
|
382
|
+
if (rune >= 128) {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
__name(isAscii, "isAscii");
|
|
389
|
+
function asciiFuzzyIndex(input, pattern, caseSensitive) {
|
|
390
|
+
if (!isAscii(input)) {
|
|
391
|
+
return 0;
|
|
392
|
+
}
|
|
393
|
+
if (!isAscii(pattern)) {
|
|
394
|
+
return -1;
|
|
395
|
+
}
|
|
396
|
+
let firstIdx = 0, idx = 0;
|
|
397
|
+
for (let pidx = 0; pidx < pattern.length; pidx++) {
|
|
398
|
+
idx = trySkip(input, caseSensitive, pattern[pidx], idx);
|
|
399
|
+
if (idx < 0) {
|
|
400
|
+
return -1;
|
|
401
|
+
}
|
|
402
|
+
if (pidx === 0 && idx > 0) {
|
|
403
|
+
firstIdx = idx - 1;
|
|
404
|
+
}
|
|
405
|
+
idx++;
|
|
406
|
+
}
|
|
407
|
+
return firstIdx;
|
|
408
|
+
}
|
|
409
|
+
__name(asciiFuzzyIndex, "asciiFuzzyIndex");
|
|
410
|
+
var fuzzyMatchV2 = /* @__PURE__ */ __name((caseSensitive, normalize, forward, input, pattern, withPos, slab2) => {
|
|
411
|
+
const M = pattern.length;
|
|
412
|
+
if (M === 0) {
|
|
413
|
+
return [{ start: 0, end: 0, score: 0 }, createPosSet(withPos)];
|
|
414
|
+
}
|
|
415
|
+
const N = input.length;
|
|
416
|
+
if (slab2 !== null && N * M > slab2.i16.length) {
|
|
417
|
+
return fuzzyMatchV1(caseSensitive, normalize, forward, input, pattern, withPos);
|
|
418
|
+
}
|
|
419
|
+
const idx = asciiFuzzyIndex(input, pattern, caseSensitive);
|
|
420
|
+
if (idx < 0) {
|
|
421
|
+
return [{ start: -1, end: -1, score: 0 }, null];
|
|
422
|
+
}
|
|
423
|
+
let offset16 = 0, offset32 = 0, H0 = null, C0 = null, B = null, F = null;
|
|
424
|
+
[offset16, H0] = alloc16(offset16, slab2, N);
|
|
425
|
+
[offset16, C0] = alloc16(offset16, slab2, N);
|
|
426
|
+
[offset16, B] = alloc16(offset16, slab2, N);
|
|
427
|
+
[offset32, F] = alloc32(offset32, slab2, M);
|
|
428
|
+
const [, T] = alloc32(offset32, slab2, N);
|
|
429
|
+
for (let i = 0; i < T.length; i++) {
|
|
430
|
+
T[i] = input[i];
|
|
431
|
+
}
|
|
432
|
+
let maxScore = toShort(0), maxScorePos = 0;
|
|
433
|
+
let pidx = 0, lastIdx = 0;
|
|
434
|
+
const pchar0 = pattern[0];
|
|
435
|
+
let pchar = pattern[0], prevH0 = toShort(0), prevCharClass = 0, inGap = false;
|
|
436
|
+
let Tsub = T.subarray(idx);
|
|
437
|
+
let H0sub = H0.subarray(idx).subarray(0, Tsub.length), C0sub = C0.subarray(idx).subarray(0, Tsub.length), Bsub = B.subarray(idx).subarray(0, Tsub.length);
|
|
438
|
+
for (let [off, char] of Tsub.entries()) {
|
|
439
|
+
let charClass = null;
|
|
440
|
+
if (char <= MAX_ASCII) {
|
|
441
|
+
charClass = charClassOfAscii(char);
|
|
442
|
+
if (!caseSensitive && charClass === 2) {
|
|
443
|
+
char += 32;
|
|
444
|
+
}
|
|
445
|
+
} else {
|
|
446
|
+
charClass = charClassOfNonAscii(char);
|
|
447
|
+
if (!caseSensitive && charClass === 2) {
|
|
448
|
+
char = String.fromCodePoint(char).toLowerCase().codePointAt(0);
|
|
449
|
+
}
|
|
450
|
+
if (normalize) {
|
|
451
|
+
char = normalizeRune(char);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
Tsub[off] = char;
|
|
455
|
+
const bonus = bonusFor(prevCharClass, charClass);
|
|
456
|
+
Bsub[off] = bonus;
|
|
457
|
+
prevCharClass = charClass;
|
|
458
|
+
if (char === pchar) {
|
|
459
|
+
if (pidx < M) {
|
|
460
|
+
F[pidx] = toInt(idx + off);
|
|
461
|
+
pidx++;
|
|
462
|
+
pchar = pattern[Math.min(pidx, M - 1)];
|
|
463
|
+
}
|
|
464
|
+
lastIdx = idx + off;
|
|
465
|
+
}
|
|
466
|
+
if (char === pchar0) {
|
|
467
|
+
const score = SCORE_MATCH + bonus * BONUS_FIRST_CHAR_MULTIPLIER;
|
|
468
|
+
H0sub[off] = score;
|
|
469
|
+
C0sub[off] = 1;
|
|
470
|
+
if (M === 1 && (forward && score > maxScore || !forward && score >= maxScore)) {
|
|
471
|
+
maxScore = score;
|
|
472
|
+
maxScorePos = idx + off;
|
|
473
|
+
if (forward && bonus === BONUS_BOUNDARY) {
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
inGap = false;
|
|
478
|
+
} else {
|
|
479
|
+
if (inGap) {
|
|
480
|
+
H0sub[off] = maxInt16(prevH0 + SCORE_GAP_EXTENTION, 0);
|
|
481
|
+
} else {
|
|
482
|
+
H0sub[off] = maxInt16(prevH0 + SCORE_GAP_START, 0);
|
|
483
|
+
}
|
|
484
|
+
C0sub[off] = 0;
|
|
485
|
+
inGap = true;
|
|
486
|
+
}
|
|
487
|
+
prevH0 = H0sub[off];
|
|
488
|
+
}
|
|
489
|
+
if (pidx !== M) {
|
|
490
|
+
return [{ start: -1, end: -1, score: 0 }, null];
|
|
491
|
+
}
|
|
492
|
+
if (M === 1) {
|
|
493
|
+
const result = {
|
|
494
|
+
start: maxScorePos,
|
|
495
|
+
end: maxScorePos + 1,
|
|
496
|
+
score: maxScore
|
|
497
|
+
};
|
|
498
|
+
if (!withPos) {
|
|
499
|
+
return [result, null];
|
|
500
|
+
}
|
|
501
|
+
const pos2 = /* @__PURE__ */ new Set();
|
|
502
|
+
pos2.add(maxScorePos);
|
|
503
|
+
return [result, pos2];
|
|
504
|
+
}
|
|
505
|
+
const f0 = F[0];
|
|
506
|
+
const width = lastIdx - f0 + 1;
|
|
507
|
+
let H = null;
|
|
508
|
+
[offset16, H] = alloc16(offset16, slab2, width * M);
|
|
509
|
+
{
|
|
510
|
+
const toCopy = H0.subarray(f0, lastIdx + 1);
|
|
511
|
+
for (const [i, v] of toCopy.entries()) {
|
|
512
|
+
H[i] = v;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
let [, C] = alloc16(offset16, slab2, width * M);
|
|
516
|
+
{
|
|
517
|
+
const toCopy = C0.subarray(f0, lastIdx + 1);
|
|
518
|
+
for (const [i, v] of toCopy.entries()) {
|
|
519
|
+
C[i] = v;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
const Fsub = F.subarray(1);
|
|
523
|
+
const Psub = pattern.slice(1).slice(0, Fsub.length);
|
|
524
|
+
for (const [off, f] of Fsub.entries()) {
|
|
525
|
+
let inGap2 = false;
|
|
526
|
+
const pchar2 = Psub[off], pidx2 = off + 1, row = pidx2 * width, Tsub2 = T.subarray(f, lastIdx + 1), Bsub2 = B.subarray(f).subarray(0, Tsub2.length), Csub = C.subarray(row + f - f0).subarray(0, Tsub2.length), Cdiag = C.subarray(row + f - f0 - 1 - width).subarray(0, Tsub2.length), Hsub = H.subarray(row + f - f0).subarray(0, Tsub2.length), Hdiag = H.subarray(row + f - f0 - 1 - width).subarray(0, Tsub2.length), Hleft = H.subarray(row + f - f0 - 1).subarray(0, Tsub2.length);
|
|
527
|
+
Hleft[0] = 0;
|
|
528
|
+
for (const [off2, char] of Tsub2.entries()) {
|
|
529
|
+
const col = off2 + f;
|
|
530
|
+
let s1 = 0, s2 = 0, consecutive = 0;
|
|
531
|
+
if (inGap2) {
|
|
532
|
+
s2 = Hleft[off2] + SCORE_GAP_EXTENTION;
|
|
533
|
+
} else {
|
|
534
|
+
s2 = Hleft[off2] + SCORE_GAP_START;
|
|
535
|
+
}
|
|
536
|
+
if (pchar2 === char) {
|
|
537
|
+
s1 = Hdiag[off2] + SCORE_MATCH;
|
|
538
|
+
let b = Bsub2[off2];
|
|
539
|
+
consecutive = Cdiag[off2] + 1;
|
|
540
|
+
if (b === BONUS_BOUNDARY) {
|
|
541
|
+
consecutive = 1;
|
|
542
|
+
} else if (consecutive > 1) {
|
|
543
|
+
b = maxInt16(b, maxInt16(BONUS_CONSECUTIVE, B[col - consecutive + 1]));
|
|
544
|
+
}
|
|
545
|
+
if (s1 + b < s2) {
|
|
546
|
+
s1 += Bsub2[off2];
|
|
547
|
+
consecutive = 0;
|
|
548
|
+
} else {
|
|
549
|
+
s1 += b;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
Csub[off2] = consecutive;
|
|
553
|
+
inGap2 = s1 < s2;
|
|
554
|
+
const score = maxInt16(maxInt16(s1, s2), 0);
|
|
555
|
+
if (pidx2 === M - 1 && (forward && score > maxScore || !forward && score >= maxScore)) {
|
|
556
|
+
maxScore = score;
|
|
557
|
+
maxScorePos = col;
|
|
558
|
+
}
|
|
559
|
+
Hsub[off2] = score;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
const pos = createPosSet(withPos);
|
|
563
|
+
let j = f0;
|
|
564
|
+
if (withPos && pos !== null) {
|
|
565
|
+
let i = M - 1;
|
|
566
|
+
j = maxScorePos;
|
|
567
|
+
let preferMatch = true;
|
|
568
|
+
while (true) {
|
|
569
|
+
const I = i * width, j0 = j - f0, s = H[I + j0];
|
|
570
|
+
let s1 = 0, s2 = 0;
|
|
571
|
+
if (i > 0 && j >= F[i]) {
|
|
572
|
+
s1 = H[I - width + j0 - 1];
|
|
573
|
+
}
|
|
574
|
+
if (j > F[i]) {
|
|
575
|
+
s2 = H[I + j0 - 1];
|
|
576
|
+
}
|
|
577
|
+
if (s > s1 && (s > s2 || s === s2 && preferMatch)) {
|
|
578
|
+
pos.add(j);
|
|
579
|
+
if (i === 0) {
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
i--;
|
|
583
|
+
}
|
|
584
|
+
preferMatch = C[I + j0] > 1 || I + width + j0 + 1 < C.length && C[I + width + j0 + 1] > 0;
|
|
585
|
+
j--;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
return [{ start: j, end: maxScorePos + 1, score: maxScore }, pos];
|
|
589
|
+
}, "fuzzyMatchV2");
|
|
590
|
+
function calculateScore(caseSensitive, normalize, text, pattern, sidx, eidx, withPos) {
|
|
591
|
+
let pidx = 0, score = 0, inGap = false, consecutive = 0, firstBonus = toShort(0);
|
|
592
|
+
const pos = createPosSet(withPos);
|
|
593
|
+
let prevCharClass = 0;
|
|
594
|
+
if (sidx > 0) {
|
|
595
|
+
prevCharClass = charClassOf(text[sidx - 1]);
|
|
596
|
+
}
|
|
597
|
+
for (let idx = sidx; idx < eidx; idx++) {
|
|
598
|
+
let rune = text[idx];
|
|
599
|
+
const charClass = charClassOf(rune);
|
|
600
|
+
if (!caseSensitive) {
|
|
601
|
+
if (rune >= CAPITAL_A_RUNE && rune <= CAPITAL_Z_RUNE) {
|
|
602
|
+
rune += 32;
|
|
603
|
+
} else if (rune > MAX_ASCII) {
|
|
604
|
+
rune = String.fromCodePoint(rune).toLowerCase().codePointAt(0);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (normalize) {
|
|
608
|
+
rune = normalizeRune(rune);
|
|
609
|
+
}
|
|
610
|
+
if (rune === pattern[pidx]) {
|
|
611
|
+
if (withPos && pos !== null) {
|
|
612
|
+
pos.add(idx);
|
|
613
|
+
}
|
|
614
|
+
score += SCORE_MATCH;
|
|
615
|
+
let bonus = bonusFor(prevCharClass, charClass);
|
|
616
|
+
if (consecutive === 0) {
|
|
617
|
+
firstBonus = bonus;
|
|
618
|
+
} else {
|
|
619
|
+
if (bonus === BONUS_BOUNDARY) {
|
|
620
|
+
firstBonus = bonus;
|
|
621
|
+
}
|
|
622
|
+
bonus = maxInt16(maxInt16(bonus, firstBonus), BONUS_CONSECUTIVE);
|
|
623
|
+
}
|
|
624
|
+
if (pidx === 0) {
|
|
625
|
+
score += bonus * BONUS_FIRST_CHAR_MULTIPLIER;
|
|
626
|
+
} else {
|
|
627
|
+
score += bonus;
|
|
628
|
+
}
|
|
629
|
+
inGap = false;
|
|
630
|
+
consecutive++;
|
|
631
|
+
pidx++;
|
|
632
|
+
} else {
|
|
633
|
+
if (inGap) {
|
|
634
|
+
score += SCORE_GAP_EXTENTION;
|
|
635
|
+
} else {
|
|
636
|
+
score += SCORE_GAP_START;
|
|
637
|
+
}
|
|
638
|
+
inGap = true;
|
|
639
|
+
consecutive = 0;
|
|
640
|
+
firstBonus = 0;
|
|
641
|
+
}
|
|
642
|
+
prevCharClass = charClass;
|
|
643
|
+
}
|
|
644
|
+
return [score, pos];
|
|
645
|
+
}
|
|
646
|
+
__name(calculateScore, "calculateScore");
|
|
647
|
+
var fuzzyMatchV1 = /* @__PURE__ */ __name((caseSensitive, normalize, forward, text, pattern, withPos, slab2) => {
|
|
648
|
+
if (pattern.length === 0) {
|
|
649
|
+
return [{ start: 0, end: 0, score: 0 }, null];
|
|
650
|
+
}
|
|
651
|
+
if (asciiFuzzyIndex(text, pattern, caseSensitive) < 0) {
|
|
652
|
+
return [{ start: -1, end: -1, score: 0 }, null];
|
|
653
|
+
}
|
|
654
|
+
let pidx = 0, sidx = -1, eidx = -1;
|
|
655
|
+
const lenRunes = text.length;
|
|
656
|
+
const lenPattern = pattern.length;
|
|
657
|
+
for (let index = 0; index < lenRunes; index++) {
|
|
658
|
+
let rune = text[indexAt(index, lenRunes, forward)];
|
|
659
|
+
if (!caseSensitive) {
|
|
660
|
+
if (rune >= CAPITAL_A_RUNE && rune <= CAPITAL_Z_RUNE) {
|
|
661
|
+
rune += 32;
|
|
662
|
+
} else if (rune > MAX_ASCII) {
|
|
663
|
+
rune = String.fromCodePoint(rune).toLowerCase().codePointAt(0);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
if (normalize) {
|
|
667
|
+
rune = normalizeRune(rune);
|
|
668
|
+
}
|
|
669
|
+
const pchar = pattern[indexAt(pidx, lenPattern, forward)];
|
|
670
|
+
if (rune === pchar) {
|
|
671
|
+
if (sidx < 0) {
|
|
672
|
+
sidx = index;
|
|
673
|
+
}
|
|
674
|
+
pidx++;
|
|
675
|
+
if (pidx === lenPattern) {
|
|
676
|
+
eidx = index + 1;
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
if (sidx >= 0 && eidx >= 0) {
|
|
682
|
+
pidx--;
|
|
683
|
+
for (let index = eidx - 1; index >= sidx; index--) {
|
|
684
|
+
const tidx = indexAt(index, lenRunes, forward);
|
|
685
|
+
let rune = text[tidx];
|
|
686
|
+
if (!caseSensitive) {
|
|
687
|
+
if (rune >= CAPITAL_A_RUNE && rune <= CAPITAL_Z_RUNE) {
|
|
688
|
+
rune += 32;
|
|
689
|
+
} else if (rune > MAX_ASCII) {
|
|
690
|
+
rune = String.fromCodePoint(rune).toLowerCase().codePointAt(0);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
const pidx_ = indexAt(pidx, lenPattern, forward);
|
|
694
|
+
const pchar = pattern[pidx_];
|
|
695
|
+
if (rune === pchar) {
|
|
696
|
+
pidx--;
|
|
697
|
+
if (pidx < 0) {
|
|
698
|
+
sidx = index;
|
|
699
|
+
break;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
if (!forward) {
|
|
704
|
+
const sidxTemp = sidx;
|
|
705
|
+
sidx = lenRunes - eidx;
|
|
706
|
+
eidx = lenRunes - sidxTemp;
|
|
707
|
+
}
|
|
708
|
+
const [score, pos] = calculateScore(
|
|
709
|
+
caseSensitive,
|
|
710
|
+
normalize,
|
|
711
|
+
text,
|
|
712
|
+
pattern,
|
|
713
|
+
sidx,
|
|
714
|
+
eidx,
|
|
715
|
+
withPos
|
|
716
|
+
);
|
|
717
|
+
return [{ start: sidx, end: eidx, score }, pos];
|
|
718
|
+
}
|
|
719
|
+
return [{ start: -1, end: -1, score: 0 }, null];
|
|
720
|
+
}, "fuzzyMatchV1");
|
|
721
|
+
var exactMatchNaive = /* @__PURE__ */ __name((caseSensitive, normalize, forward, text, pattern, withPos, slab2) => {
|
|
722
|
+
if (pattern.length === 0) {
|
|
723
|
+
return [{ start: 0, end: 0, score: 0 }, null];
|
|
724
|
+
}
|
|
725
|
+
const lenRunes = text.length;
|
|
726
|
+
const lenPattern = pattern.length;
|
|
727
|
+
if (lenRunes < lenPattern) {
|
|
728
|
+
return [{ start: -1, end: -1, score: 0 }, null];
|
|
729
|
+
}
|
|
730
|
+
if (asciiFuzzyIndex(text, pattern, caseSensitive) < 0) {
|
|
731
|
+
return [{ start: -1, end: -1, score: 0 }, null];
|
|
732
|
+
}
|
|
733
|
+
let pidx = 0;
|
|
734
|
+
let bestPos = -1, bonus = toShort(0), bestBonus = toShort(-1);
|
|
735
|
+
for (let index = 0; index < lenRunes; index++) {
|
|
736
|
+
const index_ = indexAt(index, lenRunes, forward);
|
|
737
|
+
let rune = text[index_];
|
|
738
|
+
if (!caseSensitive) {
|
|
739
|
+
if (rune >= CAPITAL_A_RUNE && rune <= CAPITAL_Z_RUNE) {
|
|
740
|
+
rune += 32;
|
|
741
|
+
} else if (rune > MAX_ASCII) {
|
|
742
|
+
rune = String.fromCodePoint(rune).toLowerCase().codePointAt(0);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
if (normalize) {
|
|
746
|
+
rune = normalizeRune(rune);
|
|
747
|
+
}
|
|
748
|
+
const pidx_ = indexAt(pidx, lenPattern, forward);
|
|
749
|
+
const pchar = pattern[pidx_];
|
|
750
|
+
if (pchar === rune) {
|
|
751
|
+
if (pidx_ === 0) {
|
|
752
|
+
bonus = bonusAt(text, index_);
|
|
753
|
+
}
|
|
754
|
+
pidx++;
|
|
755
|
+
if (pidx === lenPattern) {
|
|
756
|
+
if (bonus > bestBonus) {
|
|
757
|
+
bestPos = index;
|
|
758
|
+
bestBonus = bonus;
|
|
759
|
+
}
|
|
760
|
+
if (bonus === BONUS_BOUNDARY) {
|
|
761
|
+
break;
|
|
762
|
+
}
|
|
763
|
+
index -= pidx - 1;
|
|
764
|
+
pidx = 0;
|
|
765
|
+
bonus = 0;
|
|
766
|
+
}
|
|
767
|
+
} else {
|
|
768
|
+
index -= pidx;
|
|
769
|
+
pidx = 0;
|
|
770
|
+
bonus = 0;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
if (bestPos >= 0) {
|
|
774
|
+
let sidx = 0, eidx = 0;
|
|
775
|
+
if (forward) {
|
|
776
|
+
sidx = bestPos - lenPattern + 1;
|
|
777
|
+
eidx = bestPos + 1;
|
|
778
|
+
} else {
|
|
779
|
+
sidx = lenRunes - (bestPos + 1);
|
|
780
|
+
eidx = lenRunes - (bestPos - lenPattern + 1);
|
|
781
|
+
}
|
|
782
|
+
const [score] = calculateScore(caseSensitive, normalize, text, pattern, sidx, eidx, false);
|
|
783
|
+
return [{ start: sidx, end: eidx, score }, null];
|
|
784
|
+
}
|
|
785
|
+
return [{ start: -1, end: -1, score: 0 }, null];
|
|
786
|
+
}, "exactMatchNaive");
|
|
787
|
+
var SLAB_16_SIZE = 100 * 1024;
|
|
788
|
+
var SLAB_32_SIZE = 2048;
|
|
789
|
+
function makeSlab(size16, size32) {
|
|
790
|
+
return {
|
|
791
|
+
i16: new Int16Array(size16),
|
|
792
|
+
i32: new Int32Array(size32)
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
__name(makeSlab, "makeSlab");
|
|
796
|
+
var slab = makeSlab(SLAB_16_SIZE, SLAB_32_SIZE);
|
|
797
|
+
var buildPatternForBasicMatch = /* @__PURE__ */ __name((query, casing, normalize) => {
|
|
798
|
+
let caseSensitive = false;
|
|
799
|
+
switch (casing) {
|
|
800
|
+
case "smart-case":
|
|
801
|
+
if (query.toLowerCase() !== query) {
|
|
802
|
+
caseSensitive = true;
|
|
803
|
+
}
|
|
804
|
+
break;
|
|
805
|
+
case "case-sensitive":
|
|
806
|
+
caseSensitive = true;
|
|
807
|
+
break;
|
|
808
|
+
case "case-insensitive":
|
|
809
|
+
query = query.toLowerCase();
|
|
810
|
+
caseSensitive = false;
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
let queryRunes = strToRunes(query);
|
|
814
|
+
if (normalize) {
|
|
815
|
+
queryRunes = queryRunes.map(normalizeRune);
|
|
816
|
+
}
|
|
817
|
+
return {
|
|
818
|
+
queryRunes,
|
|
819
|
+
caseSensitive
|
|
820
|
+
};
|
|
821
|
+
}, "buildPatternForBasicMatch");
|
|
822
|
+
function getResultFromScoreMap(scoreMap, limit) {
|
|
823
|
+
const scoresInDesc = Object.keys(scoreMap).map((v) => parseInt(v, 10)).sort((a, b) => b - a);
|
|
824
|
+
let result = [];
|
|
825
|
+
for (const score of scoresInDesc) {
|
|
826
|
+
result = result.concat(scoreMap[score]);
|
|
827
|
+
if (result.length >= limit) {
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return result;
|
|
832
|
+
}
|
|
833
|
+
__name(getResultFromScoreMap, "getResultFromScoreMap");
|
|
834
|
+
function getBasicMatchIter(scoreMap, queryRunes, caseSensitive) {
|
|
835
|
+
return (idx) => {
|
|
836
|
+
const itemRunes = this.runesList[idx];
|
|
837
|
+
if (queryRunes.length > itemRunes.length)
|
|
838
|
+
return;
|
|
839
|
+
let [match, positions] = this.algoFn(
|
|
840
|
+
caseSensitive,
|
|
841
|
+
this.opts.normalize,
|
|
842
|
+
this.opts.forward,
|
|
843
|
+
itemRunes,
|
|
844
|
+
queryRunes,
|
|
845
|
+
true,
|
|
846
|
+
slab
|
|
847
|
+
);
|
|
848
|
+
if (match.start === -1)
|
|
849
|
+
return;
|
|
850
|
+
if (this.opts.fuzzy === false) {
|
|
851
|
+
positions = /* @__PURE__ */ new Set();
|
|
852
|
+
for (let position = match.start; position < match.end; ++position) {
|
|
853
|
+
positions.add(position);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
const scoreKey = this.opts.sort ? match.score : 0;
|
|
857
|
+
if (scoreMap[scoreKey] === void 0) {
|
|
858
|
+
scoreMap[scoreKey] = [];
|
|
859
|
+
}
|
|
860
|
+
scoreMap[scoreKey].push({
|
|
861
|
+
item: this.items[idx],
|
|
862
|
+
...match,
|
|
863
|
+
positions: positions != null ? positions : /* @__PURE__ */ new Set()
|
|
864
|
+
});
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
__name(getBasicMatchIter, "getBasicMatchIter");
|
|
868
|
+
function basicMatch(query) {
|
|
869
|
+
const { queryRunes, caseSensitive } = buildPatternForBasicMatch(
|
|
870
|
+
query,
|
|
871
|
+
this.opts.casing,
|
|
872
|
+
this.opts.normalize
|
|
873
|
+
);
|
|
874
|
+
const scoreMap = {};
|
|
875
|
+
const iter2 = getBasicMatchIter.bind(this)(
|
|
876
|
+
scoreMap,
|
|
877
|
+
queryRunes,
|
|
878
|
+
caseSensitive
|
|
879
|
+
);
|
|
880
|
+
for (let i = 0, len = this.runesList.length; i < len; ++i) {
|
|
881
|
+
iter2(i);
|
|
882
|
+
}
|
|
883
|
+
return getResultFromScoreMap(scoreMap, this.opts.limit);
|
|
884
|
+
}
|
|
885
|
+
__name(basicMatch, "basicMatch");
|
|
886
|
+
var isNode = typeof __require !== "undefined" && typeof window === "undefined";
|
|
887
|
+
function asyncMatcher(token, len, iter2, onFinish) {
|
|
888
|
+
return new Promise((resolve, reject) => {
|
|
889
|
+
const INCREMENT = 1e3;
|
|
890
|
+
let i = 0, end = Math.min(INCREMENT, len);
|
|
891
|
+
const step = /* @__PURE__ */ __name(() => {
|
|
892
|
+
if (token.cancelled)
|
|
893
|
+
return reject("search cancelled");
|
|
894
|
+
for (; i < end; ++i) {
|
|
895
|
+
iter2(i);
|
|
896
|
+
}
|
|
897
|
+
if (end < len) {
|
|
898
|
+
end = Math.min(end + INCREMENT, len);
|
|
899
|
+
isNode ? setImmediate(step) : setTimeout(step);
|
|
900
|
+
} else {
|
|
901
|
+
resolve(onFinish());
|
|
902
|
+
}
|
|
903
|
+
}, "step");
|
|
904
|
+
step();
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
__name(asyncMatcher, "asyncMatcher");
|
|
908
|
+
function asyncBasicMatch(query, token) {
|
|
909
|
+
const { queryRunes, caseSensitive } = buildPatternForBasicMatch(
|
|
910
|
+
query,
|
|
911
|
+
this.opts.casing,
|
|
912
|
+
this.opts.normalize
|
|
913
|
+
);
|
|
914
|
+
const scoreMap = {};
|
|
915
|
+
return asyncMatcher(
|
|
916
|
+
token,
|
|
917
|
+
this.runesList.length,
|
|
918
|
+
getBasicMatchIter.bind(this)(scoreMap, queryRunes, caseSensitive),
|
|
919
|
+
() => getResultFromScoreMap(scoreMap, this.opts.limit)
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
__name(asyncBasicMatch, "asyncBasicMatch");
|
|
923
|
+
var defaultOpts = {
|
|
924
|
+
limit: Infinity,
|
|
925
|
+
selector: /* @__PURE__ */ __name((v) => v, "selector"),
|
|
926
|
+
casing: "smart-case",
|
|
927
|
+
normalize: true,
|
|
928
|
+
fuzzy: "v2",
|
|
929
|
+
tiebreakers: [],
|
|
930
|
+
sort: true,
|
|
931
|
+
forward: true
|
|
932
|
+
};
|
|
933
|
+
var BaseFinder = class {
|
|
934
|
+
static {
|
|
935
|
+
__name(this, "BaseFinder");
|
|
936
|
+
}
|
|
937
|
+
constructor(list, ...optionsTuple) {
|
|
938
|
+
this.opts = { ...defaultOpts, ...optionsTuple[0] };
|
|
939
|
+
this.items = list;
|
|
940
|
+
this.runesList = list.map((item) => strToRunes(this.opts.selector(item).normalize()));
|
|
941
|
+
this.algoFn = exactMatchNaive;
|
|
942
|
+
switch (this.opts.fuzzy) {
|
|
943
|
+
case "v2":
|
|
944
|
+
this.algoFn = fuzzyMatchV2;
|
|
945
|
+
break;
|
|
946
|
+
case "v1":
|
|
947
|
+
this.algoFn = fuzzyMatchV1;
|
|
948
|
+
break;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
var syncDefaultOpts = {
|
|
953
|
+
...defaultOpts,
|
|
954
|
+
match: basicMatch
|
|
955
|
+
};
|
|
956
|
+
var asyncDefaultOpts = {
|
|
957
|
+
...defaultOpts,
|
|
958
|
+
match: asyncBasicMatch
|
|
959
|
+
};
|
|
960
|
+
var AsyncFinder = class extends BaseFinder {
|
|
961
|
+
static {
|
|
962
|
+
__name(this, "AsyncFinder");
|
|
963
|
+
}
|
|
964
|
+
constructor(list, ...optionsTuple) {
|
|
965
|
+
super(list, ...optionsTuple);
|
|
966
|
+
this.opts = { ...asyncDefaultOpts, ...optionsTuple[0] };
|
|
967
|
+
this.token = { cancelled: false };
|
|
968
|
+
}
|
|
969
|
+
async find(query) {
|
|
970
|
+
this.token.cancelled = true;
|
|
971
|
+
this.token = { cancelled: false };
|
|
972
|
+
if (query.length === 0 || this.items.length === 0)
|
|
973
|
+
return this.items.slice(0, this.opts.limit).map(createResultItemWithEmptyPos);
|
|
974
|
+
query = query.normalize();
|
|
975
|
+
let result = await this.opts.match.bind(this)(query, this.token);
|
|
976
|
+
return postProcessResultItems(result, this.opts);
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
var createResultItemWithEmptyPos = /* @__PURE__ */ __name((item) => ({
|
|
980
|
+
item,
|
|
981
|
+
start: -1,
|
|
982
|
+
end: -1,
|
|
983
|
+
score: 0,
|
|
984
|
+
positions: /* @__PURE__ */ new Set()
|
|
985
|
+
}), "createResultItemWithEmptyPos");
|
|
986
|
+
function postProcessResultItems(result, opts) {
|
|
987
|
+
if (opts.sort) {
|
|
988
|
+
const { selector } = opts;
|
|
989
|
+
result.sort((a, b) => {
|
|
990
|
+
if (a.score === b.score) {
|
|
991
|
+
for (const tiebreaker of opts.tiebreakers) {
|
|
992
|
+
const diff = tiebreaker(a, b, selector);
|
|
993
|
+
if (diff !== 0) {
|
|
994
|
+
return diff;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return 0;
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
if (Number.isFinite(opts.limit)) {
|
|
1002
|
+
result.splice(opts.limit);
|
|
1003
|
+
}
|
|
1004
|
+
return result;
|
|
1005
|
+
}
|
|
1006
|
+
__name(postProcessResultItems, "postProcessResultItems");
|
|
1007
|
+
var AsyncFzf = class {
|
|
1008
|
+
static {
|
|
1009
|
+
__name(this, "AsyncFzf");
|
|
1010
|
+
}
|
|
1011
|
+
constructor(list, ...optionsTuple) {
|
|
1012
|
+
this.finder = new AsyncFinder(list, ...optionsTuple);
|
|
1013
|
+
this.find = this.finder.find.bind(this.finder);
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
// packages/core/src/utils/filesearch/fzfWorker.ts
|
|
1018
|
+
if (!parentPort) {
|
|
1019
|
+
throw new Error("fzfWorker.ts must be loaded as a worker_threads worker");
|
|
1020
|
+
}
|
|
1021
|
+
var port = parentPort;
|
|
1022
|
+
var fzf = null;
|
|
1023
|
+
port.on("message", (msg) => {
|
|
1024
|
+
if (!msg || typeof msg !== "object") return;
|
|
1025
|
+
if (msg.type === "init") {
|
|
1026
|
+
try {
|
|
1027
|
+
fzf = new AsyncFzf(msg.files, msg.options);
|
|
1028
|
+
port.postMessage({ type: "ready" });
|
|
1029
|
+
} catch (err) {
|
|
1030
|
+
port.postMessage({
|
|
1031
|
+
type: "init-error",
|
|
1032
|
+
message: err instanceof Error ? err.message : String(err)
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
if (msg.type === "find") {
|
|
1038
|
+
if (!fzf) {
|
|
1039
|
+
port.postMessage({
|
|
1040
|
+
type: "find-error",
|
|
1041
|
+
reqId: msg.reqId,
|
|
1042
|
+
message: "fzf not initialized"
|
|
1043
|
+
});
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
fzf.find(msg.pattern).then((items) => {
|
|
1047
|
+
const limit = msg.limit ?? items.length;
|
|
1048
|
+
const trimmed = items.slice(0, limit).map((entry) => ({ item: entry.item }));
|
|
1049
|
+
port.postMessage({ type: "result", reqId: msg.reqId, items: trimmed });
|
|
1050
|
+
}).catch((err) => {
|
|
1051
|
+
port.postMessage({
|
|
1052
|
+
type: "find-error",
|
|
1053
|
+
reqId: msg.reqId,
|
|
1054
|
+
message: err instanceof Error ? err.message : String(err)
|
|
1055
|
+
});
|
|
1056
|
+
});
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
if (msg.type === "dispose") {
|
|
1060
|
+
fzf = null;
|
|
1061
|
+
port.close();
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
});
|
|
1065
|
+
/**
|
|
1066
|
+
* @license
|
|
1067
|
+
* Copyright 2025 Qwen
|
|
1068
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1069
|
+
*/
|
|
1070
|
+
/**
|
|
1071
|
+
* @license
|
|
1072
|
+
* Copyright 2025 Qwen team
|
|
1073
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1074
|
+
*/
|
|
1075
|
+
/*! Bundled license information:
|
|
1076
|
+
|
|
1077
|
+
fzf/dist/fzf.es.js:
|
|
1078
|
+
(** @license
|
|
1079
|
+
* fzf v0.5.2
|
|
1080
|
+
* Copyright (c) 2021 Ajit
|
|
1081
|
+
* Licensed under BSD 3-Clause
|
|
1082
|
+
*)
|
|
1083
|
+
*/
|