@unicom-cloud/utils 0.1.19 → 0.1.21
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/constant/emoji.js +31 -0
- package/constant/index.js +16 -14
- package/constant/platform.js +7 -6
- package/constant.js +16 -14
- package/emitter/index.js +4 -0
- package/emitter/src/index.js +95 -0
- package/emitter.js +4 -0
- package/index.js +2 -70
- package/nzh/src/index.js +1 -1
- package/package.json +1 -1
- package/tree/search/index.js +127 -67
- package/types/constant/emoji.d.ts +7 -0
- package/types/constant/index.d.ts +1 -0
- package/types/constant/platform.d.ts +1 -0
- package/types/emitter/src/index.d.ts +73 -0
- package/types/index.d.ts +1 -30
- package/types/tree/search/index.d.ts +22 -0
- package/types/turbo-stream/src/shared.d.ts +3 -3
- package/types/version/index.d.ts +2 -0
- package/version/index.js +5 -0
- package/version.js +5 -0
- package/diff/index.js +0 -7
- package/diff/src/diff.d.ts +0 -21
- package/diff/src/diff.js +0 -381
- package/diff.js +0 -7
- package/mitt/index.js +0 -4
- package/mitt/src/index.js +0 -31
- package/mitt.js +0 -4
- package/types/diff/index.d.ts +0 -2
- package/types/diff/src/diff.d.ts +0 -40
- package/types/mitt/src/index.d.ts +0 -15
- /package/types/{mitt → emitter}/index.d.ts +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function i() {
|
|
2
|
+
const t = [];
|
|
3
|
+
for (let e = 127744; e <= 129791; e++)
|
|
4
|
+
if (!(e >= 55296 && e <= 57343))
|
|
5
|
+
try {
|
|
6
|
+
const n = String.fromCodePoint(e);
|
|
7
|
+
o(n) && t.push({
|
|
8
|
+
emoji: n,
|
|
9
|
+
code: e.toString(16).toUpperCase().padStart(4, "0"),
|
|
10
|
+
name: r(n)
|
|
11
|
+
});
|
|
12
|
+
} catch {
|
|
13
|
+
}
|
|
14
|
+
return t;
|
|
15
|
+
}
|
|
16
|
+
function r(t) {
|
|
17
|
+
try {
|
|
18
|
+
const n = new Intl.Segmenter("en", { granularity: "grapheme" }).segment(t);
|
|
19
|
+
return Array.from(n)[0]?.segment || t;
|
|
20
|
+
} catch {
|
|
21
|
+
return t;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function o(t) {
|
|
25
|
+
return /\p{Emoji}/u.test(t);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
i as getEmojiList,
|
|
29
|
+
r as getEmojiName,
|
|
30
|
+
o as isEmoji
|
|
31
|
+
};
|
package/constant/index.js
CHANGED
|
@@ -2,27 +2,29 @@ import * as o from "./address.js";
|
|
|
2
2
|
import * as t from "./chineseCharacters.js";
|
|
3
3
|
import * as a from "./constellations.js";
|
|
4
4
|
import * as r from "./domain.js";
|
|
5
|
-
import * as s from "./
|
|
6
|
-
import * as e from "./
|
|
7
|
-
import * as n from "./
|
|
8
|
-
import * as m from "./
|
|
5
|
+
import * as s from "./emoji.js";
|
|
6
|
+
import * as e from "./identity.js";
|
|
7
|
+
import * as n from "./keyboardCode.js";
|
|
8
|
+
import * as m from "./licensePlate.js";
|
|
9
|
+
import * as i from "./name.js";
|
|
9
10
|
import * as p from "./platform.js";
|
|
10
|
-
import * as
|
|
11
|
-
import * as
|
|
12
|
-
const
|
|
11
|
+
import * as c from "./protocol.js";
|
|
12
|
+
import * as _ from "./ui.js";
|
|
13
|
+
const f = window.matchMedia(
|
|
13
14
|
"(prefers-color-scheme: dark)"
|
|
14
15
|
);
|
|
15
16
|
export {
|
|
16
|
-
|
|
17
|
+
f as MATCH_MEDIA_PREFERS_COLOR_SCHEME_DARK,
|
|
17
18
|
t as chineseCharacters,
|
|
18
19
|
a as constellations,
|
|
19
20
|
o as date,
|
|
20
21
|
r as domain,
|
|
21
|
-
s as
|
|
22
|
-
e as
|
|
23
|
-
n as
|
|
24
|
-
m as
|
|
22
|
+
s as emoji,
|
|
23
|
+
e as identity,
|
|
24
|
+
n as keyboardCode,
|
|
25
|
+
m as licensePlate,
|
|
26
|
+
i as name,
|
|
25
27
|
p as platform,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
c as protocol,
|
|
29
|
+
_ as ui
|
|
28
30
|
};
|
package/constant/platform.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
const i = navigator.userAgent.toLowerCase(),
|
|
1
|
+
const i = navigator.userAgent.toLowerCase(), s = window.__wxjs_environment === "miniprogram" || !!window.wx?.getSystemInfoSync, a = /micromessenger/i.test(i), r = /dingtalk/i.test(i), w = /alipay|aliapp/i.test(i), n = /ipad|iphone|ipod/i.test(i), e = /android/i.test(i), c = /openharmony/i.test(i), t = /macintosh|mac os x/i.test(i), d = n || t, m = /windows|win32|win64|wow64/i.test(
|
|
2
2
|
i
|
|
3
3
|
), l = (n || e || /windows phone|blackberry|mobile|webos|iemobile|opera (mini|mobi)/i.test(
|
|
4
4
|
i
|
|
5
|
-
)) && ("ontouchend" in document || "ontouchend" in window), p = ["fullscreen", "standalone", "minimal-ui"].some((o) => window.matchMedia(`(display-mode: ${o})`).matches) || window.navigator.standalone === !0;
|
|
5
|
+
)) && ("ontouchend" in document || "ontouchend" in window), p = ["fullscreen", "standalone", "minimal-ui"].some((o) => window.matchMedia(`(display-mode: ${o})`).matches) || window.navigator.standalone === !0, g = !!(typeof window < "u" && window.document && window.document.createElement);
|
|
6
6
|
export {
|
|
7
|
-
|
|
7
|
+
w as isAlipayBrowser,
|
|
8
8
|
e as isAndroidOS,
|
|
9
9
|
d as isAppleDevice,
|
|
10
|
+
g as isBrowser,
|
|
10
11
|
r as isDingtalkBrowser,
|
|
11
|
-
|
|
12
|
+
c as isHarmony,
|
|
12
13
|
n as isIOS_OS,
|
|
13
|
-
|
|
14
|
+
t as isMacOS,
|
|
14
15
|
l as isMobileDevice,
|
|
15
16
|
p as isPWA,
|
|
16
17
|
a as isWeChatBrowser,
|
|
17
|
-
|
|
18
|
+
s as isWeChatMiniProgram,
|
|
18
19
|
m as isWindowsOS
|
|
19
20
|
};
|
package/constant.js
CHANGED
|
@@ -2,13 +2,14 @@ import * as o from "./constant/address.js";
|
|
|
2
2
|
import * as t from "./constant/chineseCharacters.js";
|
|
3
3
|
import * as a from "./constant/constellations.js";
|
|
4
4
|
import * as r from "./constant/domain.js";
|
|
5
|
-
import * as s from "./constant/
|
|
6
|
-
import * as e from "./constant/
|
|
7
|
-
import * as n from "./constant/
|
|
8
|
-
import * as m from "./constant/
|
|
9
|
-
import * as p from "./constant/
|
|
10
|
-
import * as i from "./constant/
|
|
11
|
-
import * as c from "./constant/
|
|
5
|
+
import * as s from "./constant/emoji.js";
|
|
6
|
+
import * as e from "./constant/identity.js";
|
|
7
|
+
import * as n from "./constant/keyboardCode.js";
|
|
8
|
+
import * as m from "./constant/licensePlate.js";
|
|
9
|
+
import * as p from "./constant/name.js";
|
|
10
|
+
import * as i from "./constant/platform.js";
|
|
11
|
+
import * as c from "./constant/protocol.js";
|
|
12
|
+
import * as _ from "./constant/ui.js";
|
|
12
13
|
import { MATCH_MEDIA_PREFERS_COLOR_SCHEME_DARK as l } from "./constant/index.js";
|
|
13
14
|
export {
|
|
14
15
|
l as MATCH_MEDIA_PREFERS_COLOR_SCHEME_DARK,
|
|
@@ -16,11 +17,12 @@ export {
|
|
|
16
17
|
a as constellations,
|
|
17
18
|
o as date,
|
|
18
19
|
r as domain,
|
|
19
|
-
s as
|
|
20
|
-
e as
|
|
21
|
-
n as
|
|
22
|
-
m as
|
|
23
|
-
p as
|
|
24
|
-
i as
|
|
25
|
-
c as
|
|
20
|
+
s as emoji,
|
|
21
|
+
e as identity,
|
|
22
|
+
n as keyboardCode,
|
|
23
|
+
m as licensePlate,
|
|
24
|
+
p as name,
|
|
25
|
+
i as platform,
|
|
26
|
+
c as protocol,
|
|
27
|
+
_ as ui
|
|
26
28
|
};
|
package/emitter/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
class a {
|
|
2
|
+
constructor(e = /* @__PURE__ */ new Map()) {
|
|
3
|
+
this.all = e;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 为指定类型注册一个事件处理函数
|
|
7
|
+
* @param type 要监听的事件类型
|
|
8
|
+
* @param handler 响应事件时要调用的函数
|
|
9
|
+
*/
|
|
10
|
+
on(e, t) {
|
|
11
|
+
if (typeof t != "function") throw new Error(`${String(e)}: handler 必须为函数`);
|
|
12
|
+
const l = this.all.get(e) || /* @__PURE__ */ new Set();
|
|
13
|
+
l.add(t), this.all.set(e, l);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 为指定类型注册一个事件处理函数(只首次调用起作用,之后将被移除)
|
|
17
|
+
* @param type 要监听的事件类型
|
|
18
|
+
* @param handler 响应事件时要调用的函数
|
|
19
|
+
*/
|
|
20
|
+
once(e, t) {
|
|
21
|
+
const l = (...s) => {
|
|
22
|
+
t(...s), this.off(e, l);
|
|
23
|
+
};
|
|
24
|
+
this.on(e, l);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 移除指定类型的事件处理函数
|
|
28
|
+
* 如果省略 `handler` 参数,则移除该类型的所有处理函数
|
|
29
|
+
* @param type 要移除处理函数的事件类型
|
|
30
|
+
* @param handler 要移除的处理函数
|
|
31
|
+
*/
|
|
32
|
+
off(e, t) {
|
|
33
|
+
const l = this.all.get(e);
|
|
34
|
+
l && (t ? l.delete(t) : l.clear(), l.size || this.offAll(e));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 移除指定类型的所有事件处理函数
|
|
38
|
+
* 如果省略 `type` 参数,则移除所有处理函数
|
|
39
|
+
* @param type 要移除处理函数的事件类型
|
|
40
|
+
*/
|
|
41
|
+
offAll(e) {
|
|
42
|
+
e ? this.all.delete(e) : this.all.clear();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 调用指定类型的所有处理函数
|
|
46
|
+
* @param type 要触发的事件类型
|
|
47
|
+
* @param args 传递给处理函数的参数
|
|
48
|
+
*/
|
|
49
|
+
emit(e, ...t) {
|
|
50
|
+
const l = this.all.get(e);
|
|
51
|
+
if (!l) return;
|
|
52
|
+
const s = Array.from(l);
|
|
53
|
+
for (const r of s)
|
|
54
|
+
r(...t);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 获取指定类型的事件处理函数数量
|
|
58
|
+
* @param type 事件类型
|
|
59
|
+
* @returns 处理函数数量
|
|
60
|
+
*/
|
|
61
|
+
getHandlerCount(e) {
|
|
62
|
+
return this.all.get(e)?.size ?? 0;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 检查指定类型是否有事件处理函数
|
|
66
|
+
* @param type 事件类型
|
|
67
|
+
* @returns 是否存在处理函数
|
|
68
|
+
*/
|
|
69
|
+
hasHandlers(e) {
|
|
70
|
+
return this.getHandlerCount(e) > 0;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 获取所有已注册的事件类型
|
|
74
|
+
* @returns 事件类型数组
|
|
75
|
+
*/
|
|
76
|
+
getEventTypes() {
|
|
77
|
+
return Array.from(this.all.keys());
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 清空所有事件监听器
|
|
81
|
+
*/
|
|
82
|
+
clear() {
|
|
83
|
+
this.offAll();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 销毁实例,释放资源
|
|
87
|
+
*/
|
|
88
|
+
destroy() {
|
|
89
|
+
this.clear(), this.all = /* @__PURE__ */ new Map();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
a as Emitter,
|
|
94
|
+
a as default
|
|
95
|
+
};
|
package/emitter.js
ADDED
package/index.js
CHANGED
|
@@ -1,72 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as e from "./date/index.js";
|
|
3
|
-
import * as r from "./is/index.js";
|
|
4
|
-
import * as t from "./math/index.js";
|
|
5
|
-
import * as a from "./snapdom/index.js";
|
|
6
|
-
import * as s from "./tree/index.js";
|
|
7
|
-
import * as i from "./turbo-stream/index.js";
|
|
8
|
-
import * as m from "./ui-color/index.js";
|
|
9
|
-
import * as p from "./url-toolkit/index.js";
|
|
10
|
-
import { default as u } from "./case-name/index.js";
|
|
11
|
-
import { default as C } from "./class-name/index.js";
|
|
12
|
-
import { default as b } from "./clipboard-copy/index.js";
|
|
13
|
-
import { default as k, getContentDispositionFromHeader as y, getContentDispositionParametersFilenameFromHeader as T, getContentDispositionParametersFromHeader as g } from "./content-disposition/index.js";
|
|
14
|
-
import { splitCookiesString as D } from "./cookie/index.js";
|
|
15
|
-
import { default as S } from "./decimal/decimal.js";
|
|
16
|
-
import { default as j } from "./diff/src/diff.js";
|
|
17
|
-
import { fileToURL as L } from "./file/fileToURL.js";
|
|
18
|
-
import { saveAs as P } from "./file/saveAs.js";
|
|
19
|
-
import * as f from "./filesize/src/constants.js";
|
|
20
|
-
import { filesize as K, partial as R } from "./filesize/src/filesize.js";
|
|
21
|
-
import { default as W } from "./invariant/index.js";
|
|
22
|
-
import { default as q } from "./js-cookie/src/api.js";
|
|
23
|
-
import * as n from "./lunar/lib/index.js";
|
|
24
|
-
import { default as B } from "./md5/index.js";
|
|
25
|
-
import { default as G } from "./mitt/src/index.js";
|
|
26
|
-
import { default as J } from "./normalize-wheel/index.js";
|
|
27
|
-
import { default as O } from "./number-to-chinese/index.js";
|
|
28
|
-
import { default as V } from "./nzh/nzh.js";
|
|
29
|
-
import { default as Y } from "./object-keys-sort/index.js";
|
|
30
|
-
import { default as oo } from "./pinyin/src/simplified.js";
|
|
31
|
-
import { default as ro } from "./screenfull/index.js";
|
|
32
|
-
import { TinyColor as ao } from "./tinycolor/src/index.js";
|
|
33
|
-
import * as x from "./cookie/src/index.js";
|
|
1
|
+
import { VERSION as e } from "./version/index.js";
|
|
34
2
|
export {
|
|
35
|
-
|
|
36
|
-
u as caseName,
|
|
37
|
-
C as className,
|
|
38
|
-
b as clipboardCopy,
|
|
39
|
-
o as constant,
|
|
40
|
-
k as contentDisposition,
|
|
41
|
-
x as cookie,
|
|
42
|
-
e as date,
|
|
43
|
-
S as decimal,
|
|
44
|
-
j as diff,
|
|
45
|
-
L as fileToURL,
|
|
46
|
-
K as filesize,
|
|
47
|
-
f as filesizeConstants,
|
|
48
|
-
y as getContentDispositionFromHeader,
|
|
49
|
-
T as getContentDispositionParametersFilenameFromHeader,
|
|
50
|
-
g as getContentDispositionParametersFromHeader,
|
|
51
|
-
W as invariant,
|
|
52
|
-
r as is,
|
|
53
|
-
q as jsCookie,
|
|
54
|
-
t as math,
|
|
55
|
-
B as md5,
|
|
56
|
-
G as mitt,
|
|
57
|
-
J as normalizeWheel,
|
|
58
|
-
O as numberToChinese,
|
|
59
|
-
V as nzh,
|
|
60
|
-
Y as objectKeysSort,
|
|
61
|
-
R as partial,
|
|
62
|
-
oo as pinyin,
|
|
63
|
-
P as saveAs,
|
|
64
|
-
ro as screenfull,
|
|
65
|
-
a as snapdom,
|
|
66
|
-
D as splitCookiesString,
|
|
67
|
-
ao as tinycolor,
|
|
68
|
-
s as tree,
|
|
69
|
-
i as turboStream,
|
|
70
|
-
m as uiColor,
|
|
71
|
-
p as urlToolkit
|
|
3
|
+
e as version
|
|
72
4
|
};
|
package/nzh/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getNumbResult as R, clearZero as Y, unshiftZero as L, centerArray as j,
|
|
1
|
+
import { getNumbResult as R, extend as E, clearZero as Y, unshiftZero as L, centerArray as j, getDigit as C } from "./utils.js";
|
|
2
2
|
function z(m, h) {
|
|
3
3
|
let _ = R(m);
|
|
4
4
|
if (!_)
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@unicom-cloud/utils","version":"0.1.
|
|
1
|
+
{"name":"@unicom-cloud/utils","version":"0.1.21","dependencies":{},"peerDependencies":{"lodash":"^4.17.21"},"main":"./index.js","type":"module","types":"types/index.d.ts","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
|
package/tree/search/index.js
CHANGED
|
@@ -1,15 +1,80 @@
|
|
|
1
1
|
import "../../is/index.js";
|
|
2
2
|
import A from "lodash/isArray";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
function
|
|
7
|
-
return
|
|
3
|
+
import T from "lodash/isObjectLike";
|
|
4
|
+
import F from "lodash/isString";
|
|
5
|
+
import x from "lodash/isFunction";
|
|
6
|
+
function z(c, r, e, i) {
|
|
7
|
+
return r && c ? { shouldExit: !0, newMatch: !0 } : e && !c ? { shouldExit: !0, newMatch: !1 } : { shouldExit: !1, newMatch: i || c };
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
9
|
+
function O(c, r, e) {
|
|
10
|
+
const { strict: i, fuzzyMatch: l, caseSensitive: u, matchMode: S, allowEmptyString: y } = e, n = S === "OR", p = S === "AND";
|
|
11
|
+
let M = !1;
|
|
12
|
+
const t = Object.entries(r), m = {};
|
|
13
|
+
for (const [d, s] of t) {
|
|
14
|
+
const a = c[d];
|
|
15
|
+
if (s === "")
|
|
16
|
+
if (y)
|
|
17
|
+
m[d] = a === "";
|
|
18
|
+
else {
|
|
19
|
+
m[d] = !1;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
let o = !1;
|
|
23
|
+
try {
|
|
24
|
+
if (s instanceof RegExp)
|
|
25
|
+
o = F(a) ? s.test(a) : !1;
|
|
26
|
+
else if (x(s))
|
|
27
|
+
o = !!s(a);
|
|
28
|
+
else if (l && F(s)) {
|
|
29
|
+
const h = String(a), D = u ? s : s.toLowerCase();
|
|
30
|
+
o = (u ? h : h.toLowerCase()).includes(D);
|
|
31
|
+
} else
|
|
32
|
+
o = i ? a === s : a == s;
|
|
33
|
+
} catch {
|
|
34
|
+
o = !1;
|
|
35
|
+
}
|
|
36
|
+
m[d] = o;
|
|
37
|
+
const g = z(o, n, p, M);
|
|
38
|
+
if (g.shouldExit)
|
|
39
|
+
return { match: g.newMatch, matches: m };
|
|
40
|
+
M = g.newMatch;
|
|
41
|
+
}
|
|
42
|
+
return { match: M, matches: m };
|
|
43
|
+
}
|
|
44
|
+
function K(c, r, e) {
|
|
45
|
+
const i = [];
|
|
46
|
+
for (const l of c) {
|
|
47
|
+
const { match: u, matches: S } = O(
|
|
48
|
+
l,
|
|
49
|
+
r,
|
|
50
|
+
e
|
|
51
|
+
);
|
|
52
|
+
let y = u;
|
|
53
|
+
if (e.customMatcher)
|
|
54
|
+
try {
|
|
55
|
+
const t = e.customMatcher(l, S);
|
|
56
|
+
typeof t == "boolean" ? y = t : t && typeof t.match == "boolean" && (y = t.match);
|
|
57
|
+
} catch (t) {
|
|
58
|
+
console.warn("Custom matcher function error:", t);
|
|
59
|
+
}
|
|
60
|
+
const n = { ...l }, p = l[e.childrenKey];
|
|
61
|
+
if (A(p)) {
|
|
62
|
+
const t = K(
|
|
63
|
+
p,
|
|
64
|
+
r,
|
|
65
|
+
e
|
|
66
|
+
);
|
|
67
|
+
t.length > 0 ? n[e.childrenKey] = t : delete n[e.childrenKey];
|
|
68
|
+
}
|
|
69
|
+
const M = n[e.childrenKey] && n[e.childrenKey].length > 0;
|
|
70
|
+
(y || M) && i.push(n);
|
|
71
|
+
}
|
|
72
|
+
return i;
|
|
73
|
+
}
|
|
74
|
+
function V(c, r, e = {}) {
|
|
75
|
+
if (!A(c)) throw new TypeError("参数treeData必须是一个数组");
|
|
76
|
+
if (!T(r)) throw new TypeError("参数searchCondition必须是一个对象");
|
|
77
|
+
const i = {
|
|
13
78
|
strategy: "BFS",
|
|
14
79
|
childrenKey: "children",
|
|
15
80
|
strict: !1,
|
|
@@ -18,73 +83,68 @@ function q(r, l, a = {}) {
|
|
|
18
83
|
caseSensitive: !1,
|
|
19
84
|
allowEmptyString: !1,
|
|
20
85
|
matchMode: "AND",
|
|
21
|
-
|
|
86
|
+
preserveTreeStructure: !1,
|
|
87
|
+
customMatcher: void 0,
|
|
88
|
+
...e
|
|
22
89
|
// 用户配置覆盖默认值
|
|
23
90
|
}, {
|
|
24
|
-
strategy:
|
|
25
|
-
childrenKey:
|
|
26
|
-
strict:
|
|
27
|
-
fuzzyMatch:
|
|
28
|
-
returnAllMatches:
|
|
29
|
-
caseSensitive:
|
|
30
|
-
allowEmptyString:
|
|
31
|
-
matchMode:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
o = (m ? d : d.toLowerCase()).includes(R);
|
|
53
|
-
} else
|
|
54
|
-
o = x ? i === e : i == e;
|
|
55
|
-
} catch {
|
|
56
|
-
o = !1;
|
|
57
|
-
}
|
|
58
|
-
const u = v(o, M, g, t);
|
|
59
|
-
if (u.shouldExit)
|
|
60
|
-
return u.newMatch;
|
|
61
|
-
t = u.newMatch;
|
|
62
|
-
}
|
|
63
|
-
return t;
|
|
64
|
-
};
|
|
65
|
-
for (; c.length > 0; ) {
|
|
66
|
-
const s = h ? c.shift() : c.pop();
|
|
67
|
-
if (!s) continue;
|
|
91
|
+
strategy: l,
|
|
92
|
+
childrenKey: u,
|
|
93
|
+
strict: S,
|
|
94
|
+
fuzzyMatch: y,
|
|
95
|
+
returnAllMatches: n,
|
|
96
|
+
caseSensitive: p,
|
|
97
|
+
allowEmptyString: M,
|
|
98
|
+
matchMode: t,
|
|
99
|
+
preserveTreeStructure: m,
|
|
100
|
+
customMatcher: d
|
|
101
|
+
} = i;
|
|
102
|
+
if (m) {
|
|
103
|
+
const f = K(
|
|
104
|
+
c,
|
|
105
|
+
r,
|
|
106
|
+
i
|
|
107
|
+
);
|
|
108
|
+
return n ? f : f[0] || null;
|
|
109
|
+
}
|
|
110
|
+
const s = t === "OR", a = t === "AND", o = l === "BFS";
|
|
111
|
+
if (!(o || l === "DFS")) throw new Error('配置 strategy 必须是 "BFS" 或 "DFS"');
|
|
112
|
+
if (!(s || a)) throw new Error('配置 matchMode 必须是 "AND" 或 "OR"');
|
|
113
|
+
if (!F(u)) throw new TypeError("配置 childrenKey 必须是字符串");
|
|
114
|
+
const h = [...c], D = [];
|
|
115
|
+
if (Object.entries(r).length)
|
|
116
|
+
for (; h.length > 0; ) {
|
|
117
|
+
const f = o ? h.shift() : h.pop();
|
|
118
|
+
if (!f) continue;
|
|
68
119
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
120
|
+
const { match: w, matches: v } = O(
|
|
121
|
+
f,
|
|
122
|
+
r,
|
|
123
|
+
i
|
|
124
|
+
);
|
|
125
|
+
let R = w;
|
|
126
|
+
if (d) {
|
|
127
|
+
const E = d(f, v);
|
|
128
|
+
typeof E == "boolean" ? R = E : E && typeof E.match == "boolean" && (R = E.match);
|
|
129
|
+
}
|
|
130
|
+
if (R)
|
|
131
|
+
if (n)
|
|
132
|
+
D.push(f);
|
|
72
133
|
else
|
|
73
|
-
return
|
|
134
|
+
return f;
|
|
74
135
|
} catch {
|
|
75
136
|
continue;
|
|
76
137
|
}
|
|
77
|
-
const
|
|
78
|
-
if (A(
|
|
79
|
-
if (
|
|
80
|
-
|
|
138
|
+
const N = f[u];
|
|
139
|
+
if (A(N))
|
|
140
|
+
if (o)
|
|
141
|
+
h.push(...N);
|
|
81
142
|
else
|
|
82
|
-
for (let
|
|
83
|
-
|
|
143
|
+
for (let w = N.length - 1; w >= 0; w--)
|
|
144
|
+
h.push(N[w]);
|
|
84
145
|
}
|
|
85
|
-
|
|
86
|
-
return y ? F : null;
|
|
146
|
+
return n ? D : null;
|
|
87
147
|
}
|
|
88
148
|
export {
|
|
89
|
-
|
|
149
|
+
V as default
|
|
90
150
|
};
|
|
@@ -2,6 +2,7 @@ export * as date from "./address";
|
|
|
2
2
|
export * as chineseCharacters from "./chineseCharacters";
|
|
3
3
|
export * as constellations from "./constellations";
|
|
4
4
|
export * as domain from "./domain";
|
|
5
|
+
export * as emoji from "./emoji";
|
|
5
6
|
export * as identity from "./identity";
|
|
6
7
|
export * as keyboardCode from "./keyboardCode";
|
|
7
8
|
export * as licensePlate from "./licensePlate";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type EventType = string | symbol;
|
|
2
|
+
export type Handler = (...args: unknown[]) => void;
|
|
3
|
+
export interface EmitterInterface {
|
|
4
|
+
on(type: EventType, handler: Handler): void;
|
|
5
|
+
once(type: EventType, handler: Handler): void;
|
|
6
|
+
off(type: EventType, handler?: Handler): void;
|
|
7
|
+
offAll(type?: EventType): void;
|
|
8
|
+
emit(type: EventType, ...args: unknown[]): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Emitter: 类式事件发射器 / 发布-订阅模式实现
|
|
12
|
+
*/
|
|
13
|
+
export declare class Emitter implements EmitterInterface {
|
|
14
|
+
private all;
|
|
15
|
+
constructor(all?: typeof this.all);
|
|
16
|
+
/**
|
|
17
|
+
* 为指定类型注册一个事件处理函数
|
|
18
|
+
* @param type 要监听的事件类型
|
|
19
|
+
* @param handler 响应事件时要调用的函数
|
|
20
|
+
*/
|
|
21
|
+
on(type: EventType, handler: Handler): void;
|
|
22
|
+
/**
|
|
23
|
+
* 为指定类型注册一个事件处理函数(只首次调用起作用,之后将被移除)
|
|
24
|
+
* @param type 要监听的事件类型
|
|
25
|
+
* @param handler 响应事件时要调用的函数
|
|
26
|
+
*/
|
|
27
|
+
once(type: EventType, handler: Handler): void;
|
|
28
|
+
/**
|
|
29
|
+
* 移除指定类型的事件处理函数
|
|
30
|
+
* 如果省略 `handler` 参数,则移除该类型的所有处理函数
|
|
31
|
+
* @param type 要移除处理函数的事件类型
|
|
32
|
+
* @param handler 要移除的处理函数
|
|
33
|
+
*/
|
|
34
|
+
off(type: EventType, handler?: Handler): void;
|
|
35
|
+
/**
|
|
36
|
+
* 移除指定类型的所有事件处理函数
|
|
37
|
+
* 如果省略 `type` 参数,则移除所有处理函数
|
|
38
|
+
* @param type 要移除处理函数的事件类型
|
|
39
|
+
*/
|
|
40
|
+
offAll(type?: EventType): void;
|
|
41
|
+
/**
|
|
42
|
+
* 调用指定类型的所有处理函数
|
|
43
|
+
* @param type 要触发的事件类型
|
|
44
|
+
* @param args 传递给处理函数的参数
|
|
45
|
+
*/
|
|
46
|
+
emit(type: EventType, ...args: unknown[]): void;
|
|
47
|
+
/**
|
|
48
|
+
* 获取指定类型的事件处理函数数量
|
|
49
|
+
* @param type 事件类型
|
|
50
|
+
* @returns 处理函数数量
|
|
51
|
+
*/
|
|
52
|
+
getHandlerCount(type: EventType): number;
|
|
53
|
+
/**
|
|
54
|
+
* 检查指定类型是否有事件处理函数
|
|
55
|
+
* @param type 事件类型
|
|
56
|
+
* @returns 是否存在处理函数
|
|
57
|
+
*/
|
|
58
|
+
hasHandlers(type: EventType): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* 获取所有已注册的事件类型
|
|
61
|
+
* @returns 事件类型数组
|
|
62
|
+
*/
|
|
63
|
+
getEventTypes(): EventType[];
|
|
64
|
+
/**
|
|
65
|
+
* 清空所有事件监听器
|
|
66
|
+
*/
|
|
67
|
+
clear(): void;
|
|
68
|
+
/**
|
|
69
|
+
* 销毁实例,释放资源
|
|
70
|
+
*/
|
|
71
|
+
destroy(): void;
|
|
72
|
+
}
|
|
73
|
+
export default Emitter;
|
package/types/index.d.ts
CHANGED
|
@@ -1,30 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * as date from "./date";
|
|
3
|
-
export * as is from "./is";
|
|
4
|
-
export * as math from "./math";
|
|
5
|
-
export * as snapdom from "./snapdom";
|
|
6
|
-
export * as tree from "./tree";
|
|
7
|
-
export * as turboStream from "./turbo-stream";
|
|
8
|
-
export * as uiColor from "./ui-color";
|
|
9
|
-
export * as urlToolkit from "./url-toolkit";
|
|
10
|
-
export { default as caseName } from "./case-name";
|
|
11
|
-
export { default as className } from "./class-name";
|
|
12
|
-
export { default as clipboardCopy } from "./clipboard-copy";
|
|
13
|
-
export { default as decimal } from "./decimal";
|
|
14
|
-
export { default as diff } from "./diff";
|
|
15
|
-
export { default as invariant } from "./invariant";
|
|
16
|
-
export { default as jsCookie } from "./js-cookie";
|
|
17
|
-
export { default as Lunar } from "./lunar";
|
|
18
|
-
export { default as md5 } from "./md5";
|
|
19
|
-
export { default as mitt } from "./mitt";
|
|
20
|
-
export { default as normalizeWheel } from "./normalize-wheel";
|
|
21
|
-
export { default as numberToChinese } from "./number-to-chinese";
|
|
22
|
-
export { default as nzh } from "./nzh";
|
|
23
|
-
export { default as objectKeysSort } from "./object-keys-sort";
|
|
24
|
-
export { default as pinyin } from "./pinyin";
|
|
25
|
-
export { default as screenfull } from "./screenfull";
|
|
26
|
-
export { default as tinycolor } from "./tinycolor";
|
|
27
|
-
export { default as contentDisposition, getContentDispositionFromHeader, getContentDispositionParametersFilenameFromHeader, getContentDispositionParametersFromHeader } from "./content-disposition";
|
|
28
|
-
export { default as cookie, splitCookiesString } from "./cookie";
|
|
29
|
-
export { fileToURL, saveAs } from "./file";
|
|
30
|
-
export { default as filesize, filesizeConstants, partial } from "./filesize";
|
|
1
|
+
export { default as version } from "./version";
|
|
@@ -10,6 +10,18 @@ type Primitive = string | number | boolean | symbol | null | undefined;
|
|
|
10
10
|
* @template T 节点值的泛型类型
|
|
11
11
|
*/
|
|
12
12
|
type ConditionValue<T = unknown> = Primitive | ((value: T) => boolean) | RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* 自定义匹配函数类型
|
|
15
|
+
* @param node 当前节点
|
|
16
|
+
* @param matches 当前已匹配的条件信息
|
|
17
|
+
* @returns 返回boolean或对象包含匹配详情
|
|
18
|
+
*/
|
|
19
|
+
type CustomMatchFunction = (node: TreeNode, matches: {
|
|
20
|
+
[key: string]: boolean;
|
|
21
|
+
}) => boolean | {
|
|
22
|
+
match: boolean;
|
|
23
|
+
reason?: string;
|
|
24
|
+
};
|
|
13
25
|
/**
|
|
14
26
|
* 树搜索配置选项接口
|
|
15
27
|
*/
|
|
@@ -54,6 +66,16 @@ interface SearchOptions {
|
|
|
54
66
|
* @default false
|
|
55
67
|
*/
|
|
56
68
|
allowEmptyString?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* 是否保留树形结构(返回包含匹配节点的最小完整子树)
|
|
71
|
+
* @default false
|
|
72
|
+
*/
|
|
73
|
+
preserveTreeStructure?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* 自定义匹配函数,可以覆盖默认的匹配逻辑
|
|
76
|
+
* 返回true表示匹配,false表示不匹配
|
|
77
|
+
*/
|
|
78
|
+
customMatcher?: CustomMatchFunction;
|
|
57
79
|
}
|
|
58
80
|
/**
|
|
59
81
|
* 树节点接口定义
|
|
@@ -80,11 +80,11 @@ export declare class TurboBlob extends Blob {
|
|
|
80
80
|
text(): Promise<string>;
|
|
81
81
|
}
|
|
82
82
|
declare const FileBaseClass: {
|
|
83
|
-
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
|
|
84
|
-
prototype: Blob;
|
|
85
|
-
} | {
|
|
86
83
|
new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File;
|
|
87
84
|
prototype: File;
|
|
85
|
+
} | {
|
|
86
|
+
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
|
|
87
|
+
prototype: Blob;
|
|
88
88
|
};
|
|
89
89
|
export declare class TurboFile extends FileBaseClass {
|
|
90
90
|
#private;
|
package/version/index.js
ADDED
package/version.js
ADDED
package/diff/index.js
DELETED
package/diff/src/diff.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
declare function diff(
|
|
2
|
-
text1: string,
|
|
3
|
-
text2: string,
|
|
4
|
-
cursorPos?: number | diff.CursorInfo,
|
|
5
|
-
cleanup?: boolean,
|
|
6
|
-
): diff.Diff[];
|
|
7
|
-
|
|
8
|
-
declare namespace diff {
|
|
9
|
-
type Diff = [-1 | 0 | 1, string];
|
|
10
|
-
|
|
11
|
-
const DELETE: -1;
|
|
12
|
-
const INSERT: 1;
|
|
13
|
-
const EQUAL: 0;
|
|
14
|
-
|
|
15
|
-
interface CursorInfo {
|
|
16
|
-
oldRange: { index: number; length: number };
|
|
17
|
-
newRange: { index: number; length: number };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export = diff;
|
package/diff/src/diff.js
DELETED
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
let L = -1, w = 1, A = 0;
|
|
2
|
-
function S(e, t, l, r, i) {
|
|
3
|
-
if (e === t)
|
|
4
|
-
return e ? [[A, e]] : [];
|
|
5
|
-
if (l != null) {
|
|
6
|
-
let a = T(e, t, l);
|
|
7
|
-
if (a)
|
|
8
|
-
return a;
|
|
9
|
-
}
|
|
10
|
-
let n = D(e, t), h = e.substring(0, n);
|
|
11
|
-
e = e.substring(n), t = t.substring(n), n = I(e, t);
|
|
12
|
-
let g = e.substring(e.length - n);
|
|
13
|
-
e = e.substring(0, e.length - n), t = t.substring(0, t.length - n);
|
|
14
|
-
let s = G(e, t);
|
|
15
|
-
return h && s.unshift([A, h]), g && s.push([A, g]), F(s, i), r && K(s), s;
|
|
16
|
-
}
|
|
17
|
-
function G(e, t) {
|
|
18
|
-
let l;
|
|
19
|
-
if (!e)
|
|
20
|
-
return [[w, t]];
|
|
21
|
-
if (!t)
|
|
22
|
-
return [[L, e]];
|
|
23
|
-
let r = e.length > t.length ? e : t, i = e.length > t.length ? t : e, n = r.indexOf(i);
|
|
24
|
-
if (n !== -1)
|
|
25
|
-
return l = [
|
|
26
|
-
[w, r.substring(0, n)],
|
|
27
|
-
[A, i],
|
|
28
|
-
[w, r.substring(n + i.length)]
|
|
29
|
-
], e.length > t.length && (l[0][0] = l[2][0] = L), l;
|
|
30
|
-
if (i.length === 1)
|
|
31
|
-
return [
|
|
32
|
-
[L, e],
|
|
33
|
-
[w, t]
|
|
34
|
-
];
|
|
35
|
-
let h = J(e, t);
|
|
36
|
-
if (h) {
|
|
37
|
-
let g = h[0], s = h[1], a = h[2], u = h[3], c = h[4], f = S(g, a), b = S(s, u);
|
|
38
|
-
return f.concat([[A, c]], b);
|
|
39
|
-
}
|
|
40
|
-
return H(e, t);
|
|
41
|
-
}
|
|
42
|
-
function H(e, t) {
|
|
43
|
-
let l = e.length, r = t.length, i = Math.ceil((l + r) / 2), n = i, h = 2 * i, g = new Array(h), s = new Array(h);
|
|
44
|
-
for (let _ = 0; _ < h; _++)
|
|
45
|
-
g[_] = -1, s[_] = -1;
|
|
46
|
-
g[n + 1] = 0, s[n + 1] = 0;
|
|
47
|
-
let a = l - r, u = a % 2 !== 0, c = 0, f = 0, b = 0, p = 0;
|
|
48
|
-
for (let _ = 0; _ < i; _++) {
|
|
49
|
-
for (let k = -_ + c; k <= _ - f; k += 2) {
|
|
50
|
-
let m = n + k, o;
|
|
51
|
-
k === -_ || k !== _ && g[m - 1] < g[m + 1] ? o = g[m + 1] : o = g[m - 1] + 1;
|
|
52
|
-
let M = o - k;
|
|
53
|
-
for (; o < l && M < r && e.charAt(o) === t.charAt(M); )
|
|
54
|
-
o++, M++;
|
|
55
|
-
if (g[m] = o, o > l)
|
|
56
|
-
f += 2;
|
|
57
|
-
else if (M > r)
|
|
58
|
-
c += 2;
|
|
59
|
-
else if (u) {
|
|
60
|
-
let E = n + a - k;
|
|
61
|
-
if (E >= 0 && E < h && s[E] !== -1) {
|
|
62
|
-
let y = l - s[E];
|
|
63
|
-
if (o >= y)
|
|
64
|
-
return C(e, t, o, M);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
for (let k = -_ + b; k <= _ - p; k += 2) {
|
|
69
|
-
let m = n + k, o;
|
|
70
|
-
k === -_ || k !== _ && s[m - 1] < s[m + 1] ? o = s[m + 1] : o = s[m - 1] + 1;
|
|
71
|
-
let M = o - k;
|
|
72
|
-
for (; o < l && M < r && e.charAt(l - o - 1) === t.charAt(r - M - 1); )
|
|
73
|
-
o++, M++;
|
|
74
|
-
if (s[m] = o, o > l)
|
|
75
|
-
p += 2;
|
|
76
|
-
else if (M > r)
|
|
77
|
-
b += 2;
|
|
78
|
-
else if (!u) {
|
|
79
|
-
let E = n + a - k;
|
|
80
|
-
if (E >= 0 && E < h && g[E] !== -1) {
|
|
81
|
-
let y = g[E], R = n + y - E;
|
|
82
|
-
if (o = l - o, y >= o)
|
|
83
|
-
return C(e, t, y, R);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return [
|
|
89
|
-
[L, e],
|
|
90
|
-
[w, t]
|
|
91
|
-
];
|
|
92
|
-
}
|
|
93
|
-
function C(e, t, l, r) {
|
|
94
|
-
let i = e.substring(0, l), n = t.substring(0, r), h = e.substring(l), g = t.substring(r), s = S(i, n), a = S(h, g);
|
|
95
|
-
return s.concat(a);
|
|
96
|
-
}
|
|
97
|
-
function D(e, t) {
|
|
98
|
-
if (!e || !t || e.charAt(0) !== t.charAt(0))
|
|
99
|
-
return 0;
|
|
100
|
-
let l = 0, r = Math.min(e.length, t.length), i = r, n = 0;
|
|
101
|
-
for (; l < i; )
|
|
102
|
-
e.substring(n, i) == t.substring(n, i) ? (l = i, n = l) : r = i, i = Math.floor((r - l) / 2 + l);
|
|
103
|
-
return j(e.charCodeAt(i - 1)) && i--, i;
|
|
104
|
-
}
|
|
105
|
-
function O(e, t) {
|
|
106
|
-
let l = e.length, r = t.length;
|
|
107
|
-
if (l == 0 || r == 0)
|
|
108
|
-
return 0;
|
|
109
|
-
l > r ? e = e.substring(l - r) : l < r && (t = t.substring(0, l));
|
|
110
|
-
let i = Math.min(l, r);
|
|
111
|
-
if (e == t)
|
|
112
|
-
return i;
|
|
113
|
-
let n = 0, h = 1;
|
|
114
|
-
for (; ; ) {
|
|
115
|
-
let g = e.substring(i - h), s = t.indexOf(g);
|
|
116
|
-
if (s == -1)
|
|
117
|
-
return n;
|
|
118
|
-
h += s, (s == 0 || e.substring(i - h) == t.substring(0, h)) && (n = h, h++);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function I(e, t) {
|
|
122
|
-
if (!e || !t || e.slice(-1) !== t.slice(-1))
|
|
123
|
-
return 0;
|
|
124
|
-
let l = 0, r = Math.min(e.length, t.length), i = r, n = 0;
|
|
125
|
-
for (; l < i; )
|
|
126
|
-
e.substring(e.length - i, e.length - n) == t.substring(t.length - i, t.length - n) ? (l = i, n = l) : r = i, i = Math.floor((r - l) / 2 + l);
|
|
127
|
-
return z(e.charCodeAt(e.length - i)) && i--, i;
|
|
128
|
-
}
|
|
129
|
-
function J(e, t) {
|
|
130
|
-
let l = e.length > t.length ? e : t, r = e.length > t.length ? t : e;
|
|
131
|
-
if (l.length < 4 || r.length * 2 < l.length)
|
|
132
|
-
return null;
|
|
133
|
-
function i(b, p, _) {
|
|
134
|
-
let k = b.substring(_, _ + Math.floor(b.length / 4)), m = -1, o = "", M, E, y, R;
|
|
135
|
-
for (; (m = p.indexOf(k, m + 1)) !== -1; ) {
|
|
136
|
-
let v = D(
|
|
137
|
-
b.substring(_),
|
|
138
|
-
p.substring(m)
|
|
139
|
-
), q = I(
|
|
140
|
-
b.substring(0, _),
|
|
141
|
-
p.substring(0, m)
|
|
142
|
-
);
|
|
143
|
-
o.length < q + v && (o = p.substring(m - q, m) + p.substring(m, m + v), M = b.substring(0, _ - q), E = b.substring(_ + v), y = p.substring(0, m - q), R = p.substring(m + v));
|
|
144
|
-
}
|
|
145
|
-
return o.length * 2 >= b.length ? [
|
|
146
|
-
M,
|
|
147
|
-
E,
|
|
148
|
-
y,
|
|
149
|
-
R,
|
|
150
|
-
o
|
|
151
|
-
] : null;
|
|
152
|
-
}
|
|
153
|
-
let n = i(
|
|
154
|
-
l,
|
|
155
|
-
r,
|
|
156
|
-
Math.ceil(l.length / 4)
|
|
157
|
-
), h = i(
|
|
158
|
-
l,
|
|
159
|
-
r,
|
|
160
|
-
Math.ceil(l.length / 2)
|
|
161
|
-
), g;
|
|
162
|
-
if (!n && !h)
|
|
163
|
-
return null;
|
|
164
|
-
h ? n ? g = n[4].length > h[4].length ? n : h : g = h : g = n;
|
|
165
|
-
let s, a, u, c;
|
|
166
|
-
e.length > t.length ? (s = g[0], a = g[1], u = g[2], c = g[3]) : (u = g[0], c = g[1], s = g[2], a = g[3]);
|
|
167
|
-
let f = g[4];
|
|
168
|
-
return [s, a, u, c, f];
|
|
169
|
-
}
|
|
170
|
-
function K(e) {
|
|
171
|
-
let t = !1, l = [], r = 0, i = null, n = 0, h = 0, g = 0, s = 0, a = 0;
|
|
172
|
-
for (; n < e.length; )
|
|
173
|
-
e[n][0] == A ? (l[r++] = n, h = s, g = a, s = 0, a = 0, i = e[n][1]) : (e[n][0] == w ? s += e[n][1].length : a += e[n][1].length, i && i.length <= Math.max(h, g) && i.length <= Math.max(s, a) && (e.splice(l[r - 1], 0, [
|
|
174
|
-
L,
|
|
175
|
-
i
|
|
176
|
-
]), e[l[r - 1] + 1][0] = w, r--, r--, n = r > 0 ? l[r - 1] : -1, h = 0, g = 0, s = 0, a = 0, i = null, t = !0)), n++;
|
|
177
|
-
for (t && F(e), X(e), n = 1; n < e.length; ) {
|
|
178
|
-
if (e[n - 1][0] == L && e[n][0] == w) {
|
|
179
|
-
let u = e[n - 1][1], c = e[n][1], f = O(u, c), b = O(c, u);
|
|
180
|
-
f >= b ? (f >= u.length / 2 || f >= c.length / 2) && (e.splice(n, 0, [
|
|
181
|
-
A,
|
|
182
|
-
c.substring(0, f)
|
|
183
|
-
]), e[n - 1][1] = u.substring(
|
|
184
|
-
0,
|
|
185
|
-
u.length - f
|
|
186
|
-
), e[n + 1][1] = c.substring(f), n++) : (b >= u.length / 2 || b >= c.length / 2) && (e.splice(n, 0, [
|
|
187
|
-
A,
|
|
188
|
-
u.substring(0, b)
|
|
189
|
-
]), e[n - 1][0] = w, e[n - 1][1] = c.substring(
|
|
190
|
-
0,
|
|
191
|
-
c.length - b
|
|
192
|
-
), e[n + 1][0] = L, e[n + 1][1] = u.substring(b), n++), n++;
|
|
193
|
-
}
|
|
194
|
-
n++;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
let P = /[^a-zA-Z0-9]/, Q = /\s/, U = /[\r\n]/, V = /\n\r?\n$/, W = /^\r?\n\r?\n/;
|
|
198
|
-
function X(e) {
|
|
199
|
-
function t(r, i) {
|
|
200
|
-
if (!r || !i)
|
|
201
|
-
return 6;
|
|
202
|
-
let n = r.charAt(r.length - 1), h = i.charAt(0), g = n.match(P), s = h.match(P), a = g && n.match(Q), u = s && h.match(Q), c = a && n.match(U), f = u && h.match(U), b = c && r.match(V), p = f && i.match(W);
|
|
203
|
-
return b || p ? 5 : c || f ? 4 : g && !a && u ? 3 : a || u ? 2 : g || s ? 1 : 0;
|
|
204
|
-
}
|
|
205
|
-
let l = 1;
|
|
206
|
-
for (; l < e.length - 1; ) {
|
|
207
|
-
if (e[l - 1][0] == A && e[l + 1][0] == A) {
|
|
208
|
-
let r = e[l - 1][1], i = e[l][1], n = e[l + 1][1], h = I(r, i);
|
|
209
|
-
if (h) {
|
|
210
|
-
let c = i.substring(i.length - h);
|
|
211
|
-
r = r.substring(0, r.length - h), i = c + i.substring(0, i.length - h), n = c + n;
|
|
212
|
-
}
|
|
213
|
-
let g = r, s = i, a = n, u = t(r, i) + t(i, n);
|
|
214
|
-
for (; i.charAt(0) === n.charAt(0); ) {
|
|
215
|
-
r += i.charAt(0), i = i.substring(1) + n.charAt(0), n = n.substring(1);
|
|
216
|
-
let c = t(r, i) + t(i, n);
|
|
217
|
-
c >= u && (u = c, g = r, s = i, a = n);
|
|
218
|
-
}
|
|
219
|
-
e[l - 1][1] != g && (g ? e[l - 1][1] = g : (e.splice(l - 1, 1), l--), e[l][1] = s, a ? e[l + 1][1] = a : (e.splice(l + 1, 1), l--));
|
|
220
|
-
}
|
|
221
|
-
l++;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function F(e, t) {
|
|
225
|
-
e.push([A, ""]);
|
|
226
|
-
let l = 0, r = 0, i = 0, n = "", h = "", g;
|
|
227
|
-
for (; l < e.length; ) {
|
|
228
|
-
if (l < e.length - 1 && !e[l][1]) {
|
|
229
|
-
e.splice(l, 1);
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
switch (e[l][0]) {
|
|
233
|
-
case w: {
|
|
234
|
-
i++, h += e[l][1], l++;
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
case L:
|
|
238
|
-
r++, n += e[l][1], l++;
|
|
239
|
-
break;
|
|
240
|
-
case A: {
|
|
241
|
-
let a = l - i - r - 1;
|
|
242
|
-
if (t) {
|
|
243
|
-
if (a >= 0 && $(e[a][1])) {
|
|
244
|
-
let u = e[a][1].slice(-1);
|
|
245
|
-
if (e[a][1] = e[a][1].slice(
|
|
246
|
-
0,
|
|
247
|
-
-1
|
|
248
|
-
), n = u + n, h = u + h, !e[a][1]) {
|
|
249
|
-
e.splice(a, 1), l--;
|
|
250
|
-
let c = a - 1;
|
|
251
|
-
e[c] && e[c][0] === w && (i++, h = e[c][1] + h, c--), e[c] && e[c][0] === L && (r++, n = e[c][1] + n, c--), a = c;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
if (Z(e[l][1])) {
|
|
255
|
-
let u = e[l][1].charAt(0);
|
|
256
|
-
e[l][1] = e[l][1].slice(1), n += u, h += u;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (l < e.length - 1 && !e[l][1]) {
|
|
260
|
-
e.splice(l, 1);
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
if (n.length > 0 || h.length > 0) {
|
|
264
|
-
n.length > 0 && h.length > 0 && (g = D(h, n), g !== 0 && (a >= 0 ? e[a][1] += h.substring(
|
|
265
|
-
0,
|
|
266
|
-
g
|
|
267
|
-
) : (e.splice(0, 0, [
|
|
268
|
-
A,
|
|
269
|
-
h.substring(0, g)
|
|
270
|
-
]), l++), h = h.substring(g), n = n.substring(g)), g = I(h, n), g !== 0 && (e[l][1] = h.substring(h.length - g) + e[l][1], h = h.substring(
|
|
271
|
-
0,
|
|
272
|
-
h.length - g
|
|
273
|
-
), n = n.substring(
|
|
274
|
-
0,
|
|
275
|
-
n.length - g
|
|
276
|
-
)));
|
|
277
|
-
let u = i + r;
|
|
278
|
-
n.length === 0 && h.length === 0 ? (e.splice(l - u, u), l = l - u) : n.length === 0 ? (e.splice(l - u, u, [w, h]), l = l - u + 1) : h.length === 0 ? (e.splice(l - u, u, [L, n]), l = l - u + 1) : (e.splice(
|
|
279
|
-
l - u,
|
|
280
|
-
u,
|
|
281
|
-
[L, n],
|
|
282
|
-
[w, h]
|
|
283
|
-
), l = l - u + 2);
|
|
284
|
-
}
|
|
285
|
-
l !== 0 && e[l - 1][0] === A ? (e[l - 1][1] += e[l][1], e.splice(l, 1)) : l++, i = 0, r = 0, n = "", h = "";
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
e[e.length - 1][1] === "" && e.pop();
|
|
291
|
-
let s = !1;
|
|
292
|
-
for (l = 1; l < e.length - 1; )
|
|
293
|
-
e[l - 1][0] === A && e[l + 1][0] === A && (e[l][1].substring(
|
|
294
|
-
e[l][1].length - e[l - 1][1].length
|
|
295
|
-
) === e[l - 1][1] ? (e[l][1] = e[l - 1][1] + e[l][1].substring(
|
|
296
|
-
0,
|
|
297
|
-
e[l][1].length - e[l - 1][1].length
|
|
298
|
-
), e[l + 1][1] = e[l - 1][1] + e[l + 1][1], e.splice(l - 1, 1), s = !0) : e[l][1].substring(0, e[l + 1][1].length) == e[l + 1][1] && (e[l - 1][1] += e[l + 1][1], e[l][1] = e[l][1].substring(e[l + 1][1].length) + e[l + 1][1], e.splice(l + 1, 1), s = !0)), l++;
|
|
299
|
-
s && F(e, t);
|
|
300
|
-
}
|
|
301
|
-
function j(e) {
|
|
302
|
-
return e >= 55296 && e <= 56319;
|
|
303
|
-
}
|
|
304
|
-
function z(e) {
|
|
305
|
-
return e >= 56320 && e <= 57343;
|
|
306
|
-
}
|
|
307
|
-
function Z(e) {
|
|
308
|
-
return z(e.charCodeAt(0));
|
|
309
|
-
}
|
|
310
|
-
function $(e) {
|
|
311
|
-
return j(e.charCodeAt(e.length - 1));
|
|
312
|
-
}
|
|
313
|
-
function Y(e) {
|
|
314
|
-
let t = [];
|
|
315
|
-
for (let l = 0; l < e.length; l++)
|
|
316
|
-
e[l][1].length > 0 && t.push(e[l]);
|
|
317
|
-
return t;
|
|
318
|
-
}
|
|
319
|
-
function N(e, t, l, r) {
|
|
320
|
-
return $(e) || Z(r) ? null : Y([
|
|
321
|
-
[A, e],
|
|
322
|
-
[L, t],
|
|
323
|
-
[w, l],
|
|
324
|
-
[A, r]
|
|
325
|
-
]);
|
|
326
|
-
}
|
|
327
|
-
function T(e, t, l) {
|
|
328
|
-
let r = typeof l == "number" ? { index: l, length: 0 } : l.oldRange, i = typeof l == "number" ? null : l.newRange, n = e.length, h = t.length;
|
|
329
|
-
if (r.length === 0 && (i === null || i.length === 0)) {
|
|
330
|
-
let g = r.index, s = e.slice(0, g), a = e.slice(g), u = i ? i.index : null;
|
|
331
|
-
e: {
|
|
332
|
-
let c = g + h - n;
|
|
333
|
-
if (u !== null && u !== c || c < 0 || c > h)
|
|
334
|
-
break e;
|
|
335
|
-
let f = t.slice(0, c);
|
|
336
|
-
if (t.slice(c) !== a)
|
|
337
|
-
break e;
|
|
338
|
-
let p = Math.min(g, c), _ = s.slice(0, p), k = f.slice(0, p);
|
|
339
|
-
if (_ !== k)
|
|
340
|
-
break e;
|
|
341
|
-
let m = s.slice(p), o = f.slice(p);
|
|
342
|
-
return N(_, m, o, a);
|
|
343
|
-
}
|
|
344
|
-
e: {
|
|
345
|
-
if (u !== null && u !== g)
|
|
346
|
-
break e;
|
|
347
|
-
let c = g, f = t.slice(0, c), b = t.slice(c);
|
|
348
|
-
if (f !== s)
|
|
349
|
-
break e;
|
|
350
|
-
let p = Math.min(n - c, h - c), _ = a.slice(a.length - p), k = b.slice(b.length - p);
|
|
351
|
-
if (_ !== k)
|
|
352
|
-
break e;
|
|
353
|
-
let m = a.slice(0, a.length - p), o = b.slice(0, b.length - p);
|
|
354
|
-
return N(s, m, o, _);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
if (r.length > 0 && i && i.length === 0)
|
|
358
|
-
e: {
|
|
359
|
-
let g = e.slice(0, r.index), s = e.slice(r.index + r.length), a = g.length, u = s.length;
|
|
360
|
-
if (h < a + u)
|
|
361
|
-
break e;
|
|
362
|
-
let c = t.slice(0, a), f = t.slice(h - u);
|
|
363
|
-
if (g !== c || s !== f)
|
|
364
|
-
break e;
|
|
365
|
-
let b = e.slice(a, n - u), p = t.slice(a, h - u);
|
|
366
|
-
return N(g, b, p, s);
|
|
367
|
-
}
|
|
368
|
-
return null;
|
|
369
|
-
}
|
|
370
|
-
function B(e, t, l, r) {
|
|
371
|
-
return S(e, t, l, r, !0);
|
|
372
|
-
}
|
|
373
|
-
B.INSERT = w;
|
|
374
|
-
B.DELETE = L;
|
|
375
|
-
B.EQUAL = A;
|
|
376
|
-
export {
|
|
377
|
-
L as DELETE,
|
|
378
|
-
A as EQUAL,
|
|
379
|
-
w as INSERT,
|
|
380
|
-
B as default
|
|
381
|
-
};
|
package/diff.js
DELETED
package/mitt/index.js
DELETED
package/mitt/src/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
function l(o = /* @__PURE__ */ new Map()) {
|
|
2
|
-
function f(e, t) {
|
|
3
|
-
if (typeof t != "function") throw new Error(`${String(e)}: handler 必须为函数`);
|
|
4
|
-
const n = o.get(e) || /* @__PURE__ */ new Set();
|
|
5
|
-
n.add(t), o.set(e, n);
|
|
6
|
-
}
|
|
7
|
-
function c(e, t) {
|
|
8
|
-
const n = (...r) => {
|
|
9
|
-
t(...r), s(e, n);
|
|
10
|
-
};
|
|
11
|
-
f(e, n);
|
|
12
|
-
}
|
|
13
|
-
function s(e, t) {
|
|
14
|
-
const n = o.get(e);
|
|
15
|
-
n && (t ? n.delete(t) : n.clear(), n.size || i(e));
|
|
16
|
-
}
|
|
17
|
-
function i(e) {
|
|
18
|
-
e ? o.delete(e) : o.clear();
|
|
19
|
-
}
|
|
20
|
-
function u(e, ...t) {
|
|
21
|
-
const n = o.get(e);
|
|
22
|
-
if (!n) return;
|
|
23
|
-
const r = Array.from(n);
|
|
24
|
-
for (const d of r)
|
|
25
|
-
d(...t);
|
|
26
|
-
}
|
|
27
|
-
return { on: f, once: c, off: s, offAll: i, emit: u };
|
|
28
|
-
}
|
|
29
|
-
export {
|
|
30
|
-
l as default
|
|
31
|
-
};
|
package/mitt.js
DELETED
package/types/diff/index.d.ts
DELETED
package/types/diff/src/diff.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export default diff;
|
|
2
|
-
/**
|
|
3
|
-
* This library modifies the diff-patch-match library by Neil Fraser
|
|
4
|
-
* by removing the patch and match functionality and certain advanced
|
|
5
|
-
* options in the diff function. The original license is as follows:
|
|
6
|
-
*
|
|
7
|
-
* ===
|
|
8
|
-
*
|
|
9
|
-
* Diff Match and Patch
|
|
10
|
-
*
|
|
11
|
-
* Copyright 2006 Google Inc.
|
|
12
|
-
* http://code.google.com/p/google-diff-match-patch/
|
|
13
|
-
*
|
|
14
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
15
|
-
* you may not use this file except in compliance with the License.
|
|
16
|
-
* You may obtain a copy of the License at
|
|
17
|
-
*
|
|
18
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
-
*
|
|
20
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
21
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
22
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
23
|
-
* See the License for the specific language governing permissions and
|
|
24
|
-
* limitations under the License.
|
|
25
|
-
*/
|
|
26
|
-
/**
|
|
27
|
-
* The data structure representing a diff is an array of tuples:
|
|
28
|
-
* [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
|
|
29
|
-
* which means: delete 'Hello', add 'Goodbye' and keep ' world.'
|
|
30
|
-
*/
|
|
31
|
-
declare let DIFF_DELETE: number;
|
|
32
|
-
declare let DIFF_EQUAL: number;
|
|
33
|
-
declare let DIFF_INSERT: number;
|
|
34
|
-
declare function diff(text1: any, text2: any, cursor_pos: any, cleanup: any): any[];
|
|
35
|
-
declare namespace diff {
|
|
36
|
-
export { DIFF_INSERT as INSERT };
|
|
37
|
-
export { DIFF_DELETE as DELETE };
|
|
38
|
-
export { DIFF_EQUAL as EQUAL };
|
|
39
|
-
}
|
|
40
|
-
export { DIFF_DELETE as DELETE, DIFF_EQUAL as EQUAL, DIFF_INSERT as INSERT };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type EventType = string | symbol;
|
|
2
|
-
export type Handler = (...args: unknown[]) => void;
|
|
3
|
-
export interface Emitter {
|
|
4
|
-
on(type: EventType, handler: Handler): void;
|
|
5
|
-
once(type: EventType, handler: Handler): void;
|
|
6
|
-
off(type: EventType, handler?: Handler): void;
|
|
7
|
-
offAll(type?: EventType): void;
|
|
8
|
-
emit(type: EventType, ...args: unknown[]): void;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Mitt: 函数式事件发射器 / 发布-订阅模式实现
|
|
12
|
-
* @name mitt
|
|
13
|
-
* @returns {Emitter}
|
|
14
|
-
*/
|
|
15
|
-
export default function mitt(all?: Map<EventType, Set<Handler>>): Emitter;
|
|
File without changes
|