xshell 0.0.14 → 0.0.18
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/chalk.browser.d.ts +2 -0
- package/chalk.browser.js +21 -0
- package/chalk.browser.js.map +1 -0
- package/myfont.sass +11 -0
- package/net.browser.d.ts +23 -0
- package/net.browser.js +70 -0
- package/net.browser.js.map +1 -0
- package/package.json +6 -3
- package/prototype.browser.d.ts +130 -0
- package/prototype.browser.js +421 -0
- package/prototype.browser.js.map +1 -0
- package/scroll-bar.sass +35 -0
- package/toaster.browser.d.ts +9 -0
- package/toaster.browser.js +45 -0
- package/toaster.browser.js.map +1 -0
- package/toaster.sass +22 -0
- package/utils.browser.d.ts +3 -0
- package/utils.browser.js +27 -0
- package/utils.browser.js.map +1 -0
- package/extension.d.ts +0 -3
- package/extension.js +0 -68
- package/extension.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const red: import("chalk").Chalk, green: import("chalk").Chalk, yellow: import("chalk").Chalk, blue: import("chalk").Chalk, magenta: import("chalk").Chalk, cyan: import("chalk").Chalk, grey: import("chalk").Chalk, red_: import("chalk").Chalk, green_: import("chalk").Chalk, yellow_: import("chalk").Chalk, blue_: import("chalk").Chalk, magenta_: import("chalk").Chalk, cyan_: import("chalk").Chalk, underline: import("chalk").Chalk;
|
|
2
|
+
export { red, green, yellow, blue, magenta, cyan, grey, red_, green_, yellow_, blue_, magenta_, cyan_, underline };
|
package/chalk.browser.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.underline = exports.cyan_ = exports.magenta_ = exports.blue_ = exports.yellow_ = exports.green_ = exports.red_ = exports.grey = exports.cyan = exports.magenta = exports.blue = exports.yellow = exports.green = exports.red = void 0;
|
|
4
|
+
const chalk_1 = require("chalk");
|
|
5
|
+
const chalk = new chalk_1.Instance({ level: 2 });
|
|
6
|
+
const { red, green, yellow, blue, magenta, cyan, grey, redBright: red_, greenBright: green_, yellowBright: yellow_, blueBright: blue_, magentaBright: magenta_, cyanBright: cyan_, underline, } = chalk;
|
|
7
|
+
exports.red = red;
|
|
8
|
+
exports.green = green;
|
|
9
|
+
exports.yellow = yellow;
|
|
10
|
+
exports.blue = blue;
|
|
11
|
+
exports.magenta = magenta;
|
|
12
|
+
exports.cyan = cyan;
|
|
13
|
+
exports.grey = grey;
|
|
14
|
+
exports.red_ = red_;
|
|
15
|
+
exports.green_ = green_;
|
|
16
|
+
exports.yellow_ = yellow_;
|
|
17
|
+
exports.blue_ = blue_;
|
|
18
|
+
exports.magenta_ = magenta_;
|
|
19
|
+
exports.cyan_ = cyan_;
|
|
20
|
+
exports.underline = underline;
|
|
21
|
+
//# sourceMappingURL=chalk.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chalk.browser.js","sourceRoot":"","sources":["chalk.browser.ts"],"names":[],"mappings":";;;AAAA,iCAAyC;AAEzC,MAAM,KAAK,GAAG,IAAI,gBAAK,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;AAErC,MAAM,EACF,GAAG,EACH,KAAK,EACL,MAAM,EACN,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,IAAI,EAEJ,SAAS,EAAE,IAAI,EACf,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,OAAO,EACrB,UAAU,EAAE,KAAK,EACjB,aAAa,EAAE,QAAQ,EACvB,UAAU,EAAE,KAAK,EAEjB,SAAS,GACZ,GAAG,KAAK,CAAA;AAGL,kBAAG;AACH,sBAAK;AACL,wBAAM;AACN,oBAAI;AACJ,0BAAO;AACP,oBAAI;AACJ,oBAAI;AAEJ,oBAAI;AACJ,wBAAM;AACN,0BAAO;AACP,sBAAK;AACL,4BAAQ;AACR,sBAAK;AAEL,8BAAS","sourcesContent":["import { Instance as Chalk } from 'chalk'\n\nconst chalk = new Chalk({ level: 2 })\n\nconst {\n red, \n green, \n yellow, \n blue, \n magenta, \n cyan, \n grey,\n \n redBright: red_, \n greenBright: green_, \n yellowBright: yellow_, \n blueBright: blue_, \n magentaBright: magenta_,\n cyanBright: cyan_,\n \n underline,\n} = chalk\n\nexport {\n red,\n green,\n yellow,\n blue,\n magenta,\n cyan,\n grey,\n \n red_,\n green_,\n yellow_,\n blue_,\n magenta_,\n cyan_,\n \n underline\n}\n"]}
|
package/myfont.sass
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
@font-face
|
|
2
|
+
font-family: 'MyFont'
|
|
3
|
+
src: local('MyFont'), url('https://cos.shenhongfei.com/myfont.woff2')
|
|
4
|
+
|
|
5
|
+
@font-face
|
|
6
|
+
font-family: 'MyFont'
|
|
7
|
+
src: local('MyFont Bold'), url('https://cos.shenhongfei.com/myfontb.woff2')
|
|
8
|
+
font-weight: bold
|
|
9
|
+
|
|
10
|
+
html
|
|
11
|
+
font-family: 'MyFont', sans-serif
|
package/net.browser.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface RequestOptions {
|
|
2
|
+
method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch';
|
|
3
|
+
queries?: Record<string, any>;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
body?: string | object | HTMLFormElement;
|
|
6
|
+
type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data';
|
|
7
|
+
cors?: boolean;
|
|
8
|
+
by?: 'fetch' | 'GM_xmlhttpRequest';
|
|
9
|
+
}
|
|
10
|
+
export interface RequestRawOptions extends RequestOptions {
|
|
11
|
+
raw: true;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
- url: 可以只有 pathname 部分
|
|
15
|
+
- options:
|
|
16
|
+
- type: `'application/json'` 请求的 content-type 头 (如果有 body)
|
|
17
|
+
- by: `window.GM_xmlhttpRequest ? 'GM_xmlhttpRequest' : 'fetch'` 发起请求所使用的底层方法
|
|
18
|
+
*/
|
|
19
|
+
export declare function request(url: string | URL): Promise<string>;
|
|
20
|
+
export declare function request(url: string | URL, options: RequestRawOptions): Promise<Response>;
|
|
21
|
+
export declare function request(url: string | URL, options: RequestOptions): Promise<string>;
|
|
22
|
+
/** 发起 http 请求并将响应体作为 json 解析 */
|
|
23
|
+
export declare function request_json<T = any>(url: string, options?: RequestOptions): Promise<T>;
|
package/net.browser.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.request_json = exports.request = void 0;
|
|
4
|
+
async function request(url, { method, queries, headers, body, type = 'application/json', cors, by = window.GM_xmlhttpRequest ? 'GM_xmlhttpRequest' : 'fetch', raw, } = {}) {
|
|
5
|
+
url = new URL(url, location.href);
|
|
6
|
+
if (queries)
|
|
7
|
+
for (const key in queries) {
|
|
8
|
+
let value = queries[key];
|
|
9
|
+
if (typeof value === 'boolean')
|
|
10
|
+
value = value ? '1' : '0';
|
|
11
|
+
url.searchParams.append(key, value);
|
|
12
|
+
}
|
|
13
|
+
if (body && !method)
|
|
14
|
+
method = 'post';
|
|
15
|
+
if (type === 'application/json' && typeof body !== 'undefined' && typeof body !== 'string')
|
|
16
|
+
body = JSON.stringify(body);
|
|
17
|
+
url = url.toString();
|
|
18
|
+
if (by === 'fetch') {
|
|
19
|
+
const options = {
|
|
20
|
+
...method ? { method: method.toUpperCase() } : {},
|
|
21
|
+
...cors ? { mode: 'cors' } : {},
|
|
22
|
+
credentials: 'include',
|
|
23
|
+
headers: {
|
|
24
|
+
...body ? { 'content-type': type } : {},
|
|
25
|
+
...headers,
|
|
26
|
+
},
|
|
27
|
+
...body ? { body: body } : {},
|
|
28
|
+
};
|
|
29
|
+
const response = await fetch(url, options);
|
|
30
|
+
if (!response.ok)
|
|
31
|
+
throw Object.assign(new Error(`StatusCodeError: ${response.status}`), { url, response, ...options });
|
|
32
|
+
if (raw)
|
|
33
|
+
return response;
|
|
34
|
+
return response.text();
|
|
35
|
+
}
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
GM_xmlhttpRequest({
|
|
38
|
+
...method ? { method: method.toUpperCase() } : {},
|
|
39
|
+
url: url,
|
|
40
|
+
headers: {
|
|
41
|
+
...body ? { 'content-type': type } : {},
|
|
42
|
+
...headers,
|
|
43
|
+
},
|
|
44
|
+
...body ? { data: body, } : {},
|
|
45
|
+
onload(response) {
|
|
46
|
+
if (!(200 <= response.status && response.status <= 299)) {
|
|
47
|
+
reject(Object.assign(new Error(`StatusCodeError: ${response.status}`), { url, queries, method, headers, body, response }));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
resolve(response.responseText);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.request = request;
|
|
56
|
+
/** 发起 http 请求并将响应体作为 json 解析 */
|
|
57
|
+
async function request_json(url, options) {
|
|
58
|
+
const resp = await request(url, options);
|
|
59
|
+
if (!resp)
|
|
60
|
+
return;
|
|
61
|
+
try {
|
|
62
|
+
return JSON.parse(resp);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error(resp);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.request_json = request_json;
|
|
70
|
+
//# sourceMappingURL=net.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"net.browser.js","sourceRoot":"","sources":["net.browser.ts"],"names":[],"mappings":";;;AA6BO,KAAK,UAAU,OAAO,CAAE,GAAiB,EAAE,EAC9C,MAAM,EAEN,OAAO,EAEP,OAAO,EAEP,IAAI,EAEJ,IAAI,GAAG,kBAAkB,EAEzB,IAAI,EAEJ,EAAE,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,OAAO,EAE7D,GAAG,MACiC,EAAG;IACvC,GAAG,GA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AACzB,KAAK,UAAU,YAAY,CAAY,GAAW,EAAE,OAAwB;IAC/E,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACxC,IAAI,CAAC,IAAI;QAAE,OAAM;IACjB,IAAI;QACA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;KAC1B;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACnB,MAAM,KAAK,CAAA;KACd;AACL,CAAC;AATD,oCASC","sourcesContent":["export interface RequestOptions {\n method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch'\n \n queries?: Record<string, any>\n \n headers?: Record<string, string>\n \n body?: string | object | HTMLFormElement\n \n type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'\n \n cors?: boolean\n \n by?: 'fetch' | 'GM_xmlhttpRequest'\n}\n\nexport interface RequestRawOptions extends RequestOptions {\n raw: true\n}\n\n/**\n - url: 可以只有 pathname 部分\n - options:\n - type: `'application/json'` 请求的 content-type 头 (如果有 body)\n - by: `window.GM_xmlhttpRequest ? 'GM_xmlhttpRequest' : 'fetch'` 发起请求所使用的底层方法\n*/\nexport async function request (url: string | URL): Promise<string>\nexport async function request (url: string | URL, options: RequestRawOptions): Promise<Response>\nexport async function request (url: string | URL, options: RequestOptions): Promise<string>\nexport async function request (url: string | URL, {\n method,\n \n queries,\n \n headers,\n \n body,\n \n type = 'application/json',\n \n cors,\n \n by = window.GM_xmlhttpRequest ? 'GM_xmlhttpRequest' : 'fetch',\n \n raw,\n}: RequestOptions & { raw?: boolean } = { }) {\n url = new URL(url, location.href)\n \n if (queries)\n for (const key in queries) {\n let value = queries[key]\n if (typeof value === 'boolean')\n value = value ? '1' : '0'\n url.searchParams.append(key, value)\n }\n \n if (body && !method)\n method = 'post'\n \n if (type === 'application/json' && typeof body !== 'undefined' && typeof body !== 'string')\n body = JSON.stringify(body)\n \n url = url.toString()\n \n if (by === 'fetch') {\n const options: RequestInit = {\n ... method ? { method: method.toUpperCase() } : { },\n \n ... cors ? { mode: 'cors' } : { },\n \n credentials: 'include',\n \n headers: {\n ... body ? { 'content-type': type } : { },\n ... headers,\n },\n \n ... body ? { body: body as string } : { },\n }\n \n const response = await fetch(\n url,\n options\n )\n \n if (!response.ok)\n throw Object.assign(\n new Error(`StatusCodeError: ${response.status}`),\n { url, response, ...options }\n )\n \n if (raw)\n return response\n \n return response.text()\n }\n \n \n return new Promise((resolve, reject) => {\n GM_xmlhttpRequest({\n ... method ? { method: (method as any).toUpperCase() } : { },\n \n url: url as string,\n \n headers: {\n ... body ? { 'content-type': type } : { },\n ... headers,\n },\n \n ... body ? { data: body as string, } : { },\n \n onload (response) {\n if (!(200 <= response.status && response.status <= 299)) {\n reject(\n Object.assign(\n new Error(`StatusCodeError: ${response.status}`), \n { url, queries, method, headers, body, response }\n )\n )\n return\n }\n \n resolve(response.responseText)\n }\n })\n })\n}\n\n\n/** 发起 http 请求并将响应体作为 json 解析 */\nexport async function request_json <T = any> (url: string, options?: RequestOptions): Promise<T> {\n const resp = await request(url, options)\n if (!resp) return\n try {\n return JSON.parse(resp)\n } catch (error) {\n console.error(resp)\n throw error\n }\n}\n\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xshell",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"xshell": "./xshell.js"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"type": "commonjs",
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
17
|
+
"node": ">=17.1.0",
|
|
18
18
|
"vscode": ">=1.62.0"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
@@ -105,6 +105,9 @@
|
|
|
105
105
|
"@types/request-promise-native": "^1.0.18",
|
|
106
106
|
"@types/rimraf": "^3.0.2",
|
|
107
107
|
"@types/stream-buffers": "^3.0.4",
|
|
108
|
-
"@types/
|
|
108
|
+
"@types/tampermonkey": "^4.0.5",
|
|
109
|
+
"@types/vscode": "^1.62.0",
|
|
110
|
+
"source-map-loader": "^3.0.0",
|
|
111
|
+
"ts-loader": "^9.2.6"
|
|
109
112
|
}
|
|
110
113
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** 在浏览器端修改 prototype,需要更加小心 */
|
|
2
|
+
declare global {
|
|
3
|
+
interface String {
|
|
4
|
+
readonly width: number;
|
|
5
|
+
/** 截取字符串不超过 width 显示宽度的部分,并保留颜色
|
|
6
|
+
找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted
|
|
7
|
+
若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + …
|
|
8
|
+
否则 返回 this
|
|
9
|
+
*/
|
|
10
|
+
truncate(this: string, width: number): string;
|
|
11
|
+
pad(this: string, width: number, { character, position }?: {
|
|
12
|
+
character?: string;
|
|
13
|
+
position?: 'left' | 'right';
|
|
14
|
+
}): string;
|
|
15
|
+
limit(this: string, width: number, { character, position }?: {
|
|
16
|
+
character?: string;
|
|
17
|
+
position?: 'left' | 'right';
|
|
18
|
+
}): string;
|
|
19
|
+
to_regx(this: string, preservations?: string, flags?: string): RegExp;
|
|
20
|
+
/** ```ts
|
|
21
|
+
'g:/acgn/海贼王/[Skytree][海贼王][One_Piece][893][GB_BIG5_JP][X264_AAC][1080P][CRRIP][天空树双语字幕组].mkv'.refmt(
|
|
22
|
+
'{dirp}/[Skytree][海贼王][{ en_name: \\w+ }][{ episode: \\d+ }][GB_BIG5_JP][{encoding}_AAC][1080P][CRRIP][天空树双语字幕组].{format}',
|
|
23
|
+
'g:/acgn/海贼王/{episode} {encoding}.{format}',
|
|
24
|
+
'\\+',
|
|
25
|
+
'i',
|
|
26
|
+
(name, value) => name === 'episode' ? String(+value + 1) : value.toLowerCase()
|
|
27
|
+
)
|
|
28
|
+
```
|
|
29
|
+
*/
|
|
30
|
+
refmt(this: string, pattern: string, pattern_: string,
|
|
31
|
+
/** `''` 保留的正则表达式字符 */
|
|
32
|
+
preservations?: string,
|
|
33
|
+
/** `''` 正则匹配选项 */
|
|
34
|
+
flags?: string,
|
|
35
|
+
/** `(name, matched) => matched || ''` placeholder transformer */
|
|
36
|
+
transformer?: (name: string, value: string, placeholders: {
|
|
37
|
+
[name: string]: string;
|
|
38
|
+
}) => string,
|
|
39
|
+
/** `/\{.*?\}/g` */
|
|
40
|
+
pattern_placeholder?: RegExp): string;
|
|
41
|
+
/** 字符串模式搜索
|
|
42
|
+
```ts
|
|
43
|
+
'git+https://github.com/tamino-martinius/node-ts-dedent-123.git'.find(
|
|
44
|
+
'^{protocol:[\\w+]+}://{hostname:[\\w\\.]+}/{username}/{project}-{index:\\d+}.{suffix}', '^', 'i'
|
|
45
|
+
)
|
|
46
|
+
{
|
|
47
|
+
protocol: 'git+https',
|
|
48
|
+
hostname: 'github.com',
|
|
49
|
+
...
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- preservations?: `''` 保留的正则表达式字符
|
|
54
|
+
- flags?: `''` 正则匹配选项
|
|
55
|
+
- pattern_placeholder?: `/\{.*?\}/g`
|
|
56
|
+
*/
|
|
57
|
+
find(this: string, pattern: string, preservations?: string, flags?: string, pattern_placeholder?: RegExp): {
|
|
58
|
+
[name: string]: string;
|
|
59
|
+
};
|
|
60
|
+
/** - type?: `'single'` */
|
|
61
|
+
quote(this: string, type?: keyof typeof quotes | 'psh'): string;
|
|
62
|
+
/** - shape?: `'parenthesis'` */
|
|
63
|
+
bracket(this: string, shape?: keyof typeof brackets): string;
|
|
64
|
+
surround(this: string, left: string, right?: string): string;
|
|
65
|
+
surround_tag(this: string, tag_name: string): string;
|
|
66
|
+
to_lf(this: string): string;
|
|
67
|
+
to_crlf(this: string): string;
|
|
68
|
+
/** 'xxx'.replace(/pattern/g, '')
|
|
69
|
+
如果 pattern 是 string 则在创建 RegExp 时自动加上 flags (默认 'g'), 否则忽略 flags
|
|
70
|
+
*/
|
|
71
|
+
rm(this: string, pattern: string | RegExp, flags?: string): string;
|
|
72
|
+
split_lines(this: string): string[];
|
|
73
|
+
trim_doc_comment(this: string): string;
|
|
74
|
+
split_indent(this: string): {
|
|
75
|
+
indent: number;
|
|
76
|
+
text: string;
|
|
77
|
+
};
|
|
78
|
+
space(this: string): string;
|
|
79
|
+
to_slash(this: string): string;
|
|
80
|
+
to_backslash(this: string): string;
|
|
81
|
+
}
|
|
82
|
+
interface Date {
|
|
83
|
+
to_str(this: Date): string;
|
|
84
|
+
to_date_str(this: Date): string;
|
|
85
|
+
to_time_str(this: Date): string;
|
|
86
|
+
}
|
|
87
|
+
interface Number {
|
|
88
|
+
to_bin_str(this: number): string;
|
|
89
|
+
to_hex_str(this: number): string;
|
|
90
|
+
to_oct_str(this: number): string;
|
|
91
|
+
}
|
|
92
|
+
interface Array<T> {
|
|
93
|
+
indent(this: string[], width: number, c?: string): string[];
|
|
94
|
+
/**
|
|
95
|
+
- trim_line?: `true`
|
|
96
|
+
- rm_empty_lines?: `true`
|
|
97
|
+
- rm_last_empty_lines?: `false`
|
|
98
|
+
*/
|
|
99
|
+
trim_lines(this: string[], { trim_line, rm_empty_lines, rm_last_empty_lines }?: {
|
|
100
|
+
trim_line?: boolean;
|
|
101
|
+
rm_empty_lines?: boolean;
|
|
102
|
+
rm_last_empty_lines?: boolean;
|
|
103
|
+
}): string[];
|
|
104
|
+
join_lines(): string;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export declare const emoji_regex: RegExp;
|
|
108
|
+
export declare function to_method_property_descriptors(methods: {
|
|
109
|
+
[name: string]: Function;
|
|
110
|
+
}): PropertyDescriptorMap;
|
|
111
|
+
export declare function to_getter_property_descriptors(getters: {
|
|
112
|
+
[name: string]: Function;
|
|
113
|
+
}): PropertyDescriptorMap;
|
|
114
|
+
export declare const cjk = "([\u2E80-\u9FFF\uF900-\uFAFF])";
|
|
115
|
+
export declare const quotes: {
|
|
116
|
+
single: string;
|
|
117
|
+
double: string;
|
|
118
|
+
backtick: string;
|
|
119
|
+
};
|
|
120
|
+
export declare const brackets: {
|
|
121
|
+
readonly round: readonly ["(", ")"];
|
|
122
|
+
readonly square: readonly ["[", "]"];
|
|
123
|
+
readonly curly: readonly ["{", "}"];
|
|
124
|
+
readonly pointy: readonly ["<", ">"];
|
|
125
|
+
readonly corner: readonly ["「", "」"];
|
|
126
|
+
readonly fat: readonly ["【", "】"];
|
|
127
|
+
readonly tortoise_shell: readonly ["〔", "〕"];
|
|
128
|
+
};
|
|
129
|
+
export declare function to_json(object: any, replacer?: any): string;
|
|
130
|
+
export declare function is_codepoint_fullwidth(codepoint: number): boolean;
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** 在浏览器端修改 prototype,需要更加小心 */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.is_codepoint_fullwidth = exports.to_json = exports.brackets = exports.quotes = exports.cjk = exports.to_getter_property_descriptors = exports.to_method_property_descriptors = exports.emoji_regex = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const emoji_regex_1 = (0, tslib_1.__importDefault)(require("emoji-regex"));
|
|
7
|
+
exports.emoji_regex = (0, emoji_regex_1.default)();
|
|
8
|
+
function to_method_property_descriptors(methods) {
|
|
9
|
+
return Object.fromEntries(Object.entries(methods)
|
|
10
|
+
.map(([name, value]) => ([name, {
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
enumerable: false,
|
|
14
|
+
value,
|
|
15
|
+
}])));
|
|
16
|
+
}
|
|
17
|
+
exports.to_method_property_descriptors = to_method_property_descriptors;
|
|
18
|
+
function to_getter_property_descriptors(getters) {
|
|
19
|
+
return Object.fromEntries(Object.entries(getters)
|
|
20
|
+
.map(([name, get]) => ([name, {
|
|
21
|
+
configurable: true,
|
|
22
|
+
enumerable: false,
|
|
23
|
+
get,
|
|
24
|
+
}])));
|
|
25
|
+
}
|
|
26
|
+
exports.to_getter_property_descriptors = to_getter_property_descriptors;
|
|
27
|
+
exports.cjk = '([\u2e80-\u9fff\uf900-\ufaff])';
|
|
28
|
+
exports.quotes = {
|
|
29
|
+
single: "'",
|
|
30
|
+
double: '"',
|
|
31
|
+
backtick: '`',
|
|
32
|
+
};
|
|
33
|
+
exports.brackets = {
|
|
34
|
+
round: ['(', ')'],
|
|
35
|
+
square: ['[', ']'],
|
|
36
|
+
curly: ['{', '}'],
|
|
37
|
+
pointy: ['<', '>'],
|
|
38
|
+
corner: ['「', '」'],
|
|
39
|
+
fat: ['【', '】'],
|
|
40
|
+
tortoise_shell: ['〔', '〕'],
|
|
41
|
+
};
|
|
42
|
+
// ------------------------------------ String.prototype
|
|
43
|
+
Object.defineProperties(String.prototype, {
|
|
44
|
+
...to_getter_property_descriptors({
|
|
45
|
+
width() {
|
|
46
|
+
const s = this.replace(exports.emoji_regex, ' ');
|
|
47
|
+
let width = 0;
|
|
48
|
+
for (let i = 0; i < s.length; i++) {
|
|
49
|
+
const code = s.codePointAt(i);
|
|
50
|
+
if ((code <= 0x1f || (code >= 0x7f && code <= 0x9f)) || // ignore control characters
|
|
51
|
+
code >= 0x300 && code <= 0x36f // ignore combining characters
|
|
52
|
+
)
|
|
53
|
+
continue;
|
|
54
|
+
// surrogates
|
|
55
|
+
if (code > 0xFFFF)
|
|
56
|
+
i++;
|
|
57
|
+
width += is_codepoint_fullwidth(code) ? 2 : 1;
|
|
58
|
+
}
|
|
59
|
+
return width;
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
// ------------ 文本处理工具方法
|
|
63
|
+
...to_method_property_descriptors({
|
|
64
|
+
/** 截取字符串不超过 width 显示宽度的部分,并保留颜色
|
|
65
|
+
找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted
|
|
66
|
+
- 若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + …
|
|
67
|
+
- 否则 返回 this
|
|
68
|
+
*/
|
|
69
|
+
truncate(width) {
|
|
70
|
+
const color_bak = this.startsWith('\u001b') ? this.slice(0, 5) : '';
|
|
71
|
+
if (width <= 2)
|
|
72
|
+
return this.slice(0, width);
|
|
73
|
+
let i_fitted = 0;
|
|
74
|
+
let fitted_width = 0;
|
|
75
|
+
let cur_width = 0;
|
|
76
|
+
for (let i = 0; i < this.length; i++) {
|
|
77
|
+
const code = this.codePointAt(i);
|
|
78
|
+
if ((code <= 0x1F || (code >= 0x7F && code <= 0x9F)) || // Ignore control characters
|
|
79
|
+
code >= 0x300 && code <= 0x36F // Ignore combining characters
|
|
80
|
+
)
|
|
81
|
+
continue;
|
|
82
|
+
// surrogates (codepoint 需要用两个 utf-16 编码单位表示,因此这里跳过第二个编码单位,防止重复计算显示宽度)
|
|
83
|
+
if (code > 0xFFFF)
|
|
84
|
+
i++;
|
|
85
|
+
const w = is_codepoint_fullwidth(code) ? 2 : 1;
|
|
86
|
+
if (cur_width + w + 2 <= width) {
|
|
87
|
+
i_fitted = i;
|
|
88
|
+
fitted_width += w;
|
|
89
|
+
}
|
|
90
|
+
cur_width += w;
|
|
91
|
+
if (cur_width > width) {
|
|
92
|
+
const i_fitted_next = i_fitted + 1;
|
|
93
|
+
const t = this.slice(0, i_fitted_next) + ' '.repeat(width - 2 - fitted_width) + '…';
|
|
94
|
+
return color_bak ? color_bak + t + '\u001b[39m' : t;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return this;
|
|
98
|
+
},
|
|
99
|
+
pad(width, { character = ' ', position = 'right' } = {}) {
|
|
100
|
+
const _width = this.width;
|
|
101
|
+
if (_width >= width)
|
|
102
|
+
return this;
|
|
103
|
+
if (position === 'right')
|
|
104
|
+
return this + character.repeat((width - _width) / character.width);
|
|
105
|
+
return character.repeat(width - _width) + this;
|
|
106
|
+
},
|
|
107
|
+
limit(width, { character = ' ', position = 'right' } = {}) {
|
|
108
|
+
return this.pad(width, { character, position }).truncate(width);
|
|
109
|
+
},
|
|
110
|
+
to_regx(preservations, flags = '') {
|
|
111
|
+
const preserved_chars = new Set(preservations);
|
|
112
|
+
const replace_chars = Array.prototype.filter.call('|\\{}()[]^$+*?.-', (c) => !preserved_chars.has(c))
|
|
113
|
+
.map((c) => c === ']' ? '\\]' : c).join('');
|
|
114
|
+
return new RegExp(this.replace(new RegExp(`[${replace_chars}]`, 'g'), '\\$&'), flags);
|
|
115
|
+
},
|
|
116
|
+
refmt(pattern, pattern_, preservations = '', flags = '', transformer = (name, value) => value || '', pattern_placeholder = /\{.*?\}/g) {
|
|
117
|
+
// --- 转换 pattern 为 pattern_regx
|
|
118
|
+
let last_end = 0;
|
|
119
|
+
// placeholder matched group indexes
|
|
120
|
+
let $placeholders = {};
|
|
121
|
+
let regx_parts = [];
|
|
122
|
+
function add_part(left, right) {
|
|
123
|
+
const part = pattern.slice(left, right);
|
|
124
|
+
if (part)
|
|
125
|
+
regx_parts.push(part.to_regx(preservations).source.bracket());
|
|
126
|
+
}
|
|
127
|
+
pattern.replace(pattern_placeholder, ($0, offset) => {
|
|
128
|
+
add_part(last_end, offset);
|
|
129
|
+
last_end = offset + $0.length;
|
|
130
|
+
const placeholder = $0.slice(1, -1);
|
|
131
|
+
let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim());
|
|
132
|
+
let optional = false;
|
|
133
|
+
if (placeholder_name.endsWith('?')) {
|
|
134
|
+
placeholder_name = placeholder_name.slice(0, -1);
|
|
135
|
+
optional = true;
|
|
136
|
+
}
|
|
137
|
+
$placeholders[placeholder_name] = regx_parts.push(placeholder_pattern ?
|
|
138
|
+
`${placeholder_pattern.bracket()}${optional ? '?' : ''}`
|
|
139
|
+
:
|
|
140
|
+
'(.*?)');
|
|
141
|
+
return '';
|
|
142
|
+
});
|
|
143
|
+
add_part(last_end);
|
|
144
|
+
// 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要
|
|
145
|
+
regx_parts = regx_parts.filter(part => part);
|
|
146
|
+
if (regx_parts.last === '(.*?)')
|
|
147
|
+
regx_parts[regx_parts.length - 1] = '(.*)';
|
|
148
|
+
const pattern_regx = new RegExp(regx_parts.join(''), flags);
|
|
149
|
+
// --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典
|
|
150
|
+
const matches = pattern_regx.exec(this);
|
|
151
|
+
if (!matches)
|
|
152
|
+
return this;
|
|
153
|
+
const placeholders = Object.fromEntries(Object.entries($placeholders)
|
|
154
|
+
.map(([name, $i]) => [
|
|
155
|
+
[name, matches[$i]],
|
|
156
|
+
[`${name}.before`, matches[$i - 1] || ''],
|
|
157
|
+
[`${name}.after`, matches[$i + 1] || ''],
|
|
158
|
+
])
|
|
159
|
+
.flat());
|
|
160
|
+
// --- 转换 pattern_ 为 replacement_str,如果有 transformer 则在遇到 placeholder 时应用
|
|
161
|
+
last_end = 0;
|
|
162
|
+
let replacement_parts = [];
|
|
163
|
+
pattern_.replace(pattern_placeholder, ($0, offset) => {
|
|
164
|
+
replacement_parts.push(pattern_.slice(last_end, offset));
|
|
165
|
+
last_end = offset + $0.length;
|
|
166
|
+
const placeholder_name = $0.slice(1, -1);
|
|
167
|
+
replacement_parts.push(transformer(placeholder_name, placeholders[placeholder_name], placeholders));
|
|
168
|
+
return '';
|
|
169
|
+
});
|
|
170
|
+
replacement_parts.push(pattern_.slice(last_end));
|
|
171
|
+
return this.replace(pattern_regx, replacement_parts.join(''));
|
|
172
|
+
},
|
|
173
|
+
find(pattern, preservations = '', flags = '', pattern_placeholder = /\{.*?\}/g) {
|
|
174
|
+
// --- 转换 pattern 为 pattern_regx
|
|
175
|
+
let last_end = 0;
|
|
176
|
+
// placeholder matched group index
|
|
177
|
+
let $placeholders = {};
|
|
178
|
+
let regx_parts = [];
|
|
179
|
+
function add_part(left, right) {
|
|
180
|
+
const part = pattern.slice(left, right);
|
|
181
|
+
if (part)
|
|
182
|
+
regx_parts.push(part.to_regx(preservations).source.bracket());
|
|
183
|
+
}
|
|
184
|
+
pattern.replace(pattern_placeholder, ($0, offset) => {
|
|
185
|
+
add_part(last_end, offset);
|
|
186
|
+
last_end = offset + $0.length;
|
|
187
|
+
const placeholder = $0.slice(1, -1);
|
|
188
|
+
let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim());
|
|
189
|
+
let optional = false;
|
|
190
|
+
if (placeholder_name.endsWith('?')) {
|
|
191
|
+
placeholder_name = placeholder_name.slice(0, -1);
|
|
192
|
+
optional = true;
|
|
193
|
+
}
|
|
194
|
+
$placeholders[placeholder_name] = regx_parts.push(placeholder_pattern ?
|
|
195
|
+
`${placeholder_pattern.bracket()}${optional ? '?' : ''}`
|
|
196
|
+
:
|
|
197
|
+
'(.*?)');
|
|
198
|
+
return '';
|
|
199
|
+
});
|
|
200
|
+
add_part(last_end);
|
|
201
|
+
// 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要
|
|
202
|
+
regx_parts = regx_parts.filter(part => part);
|
|
203
|
+
if (regx_parts[regx_parts.length - 1] === '(.*?)')
|
|
204
|
+
regx_parts[regx_parts.length - 1] = '(.*)';
|
|
205
|
+
const pattern_regx = new RegExp(regx_parts.join(''), flags);
|
|
206
|
+
// --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典
|
|
207
|
+
const matches = pattern_regx.exec(this);
|
|
208
|
+
if (!matches)
|
|
209
|
+
return {};
|
|
210
|
+
return Object.fromEntries(Object.entries($placeholders)
|
|
211
|
+
.map(([name, $i]) => [name, matches[$i] || '']));
|
|
212
|
+
},
|
|
213
|
+
quote(type = 'single') {
|
|
214
|
+
if (type === 'psh')
|
|
215
|
+
return '& ' + this.quote();
|
|
216
|
+
return this.surround(exports.quotes[type]);
|
|
217
|
+
},
|
|
218
|
+
bracket(shape = 'round') {
|
|
219
|
+
return this.surround(...exports.brackets[shape]);
|
|
220
|
+
},
|
|
221
|
+
surround(left, right) {
|
|
222
|
+
return left + this + (right || left);
|
|
223
|
+
},
|
|
224
|
+
surround_tag(tag_name) {
|
|
225
|
+
return '<' + tag_name + '>' + this + '</' + tag_name + '>';
|
|
226
|
+
},
|
|
227
|
+
to_lf() {
|
|
228
|
+
return this.replace(/\r\n/g, '\n');
|
|
229
|
+
},
|
|
230
|
+
to_crlf() {
|
|
231
|
+
return this.replace(/\n/g, '\r\n');
|
|
232
|
+
},
|
|
233
|
+
rm(pattern, flags = 'g') {
|
|
234
|
+
if (typeof pattern === 'string')
|
|
235
|
+
pattern = new RegExp(pattern, flags);
|
|
236
|
+
return this.replace(pattern, '');
|
|
237
|
+
},
|
|
238
|
+
split_lines(delimiter = /\r?\n/) {
|
|
239
|
+
let lines = this.split(delimiter);
|
|
240
|
+
if (lines.last === '')
|
|
241
|
+
lines.pop();
|
|
242
|
+
return lines;
|
|
243
|
+
},
|
|
244
|
+
split_indent() {
|
|
245
|
+
let i = 0;
|
|
246
|
+
let indent = 0;
|
|
247
|
+
for (; i < this.length; i++)
|
|
248
|
+
if (this[i] === ' ')
|
|
249
|
+
indent += 1;
|
|
250
|
+
else if (this[i] === '\t')
|
|
251
|
+
indent += 4;
|
|
252
|
+
else
|
|
253
|
+
break;
|
|
254
|
+
return {
|
|
255
|
+
indent,
|
|
256
|
+
text: this.slice(i)
|
|
257
|
+
};
|
|
258
|
+
},
|
|
259
|
+
space() {
|
|
260
|
+
if (!this)
|
|
261
|
+
return this;
|
|
262
|
+
let text_;
|
|
263
|
+
text_ = this
|
|
264
|
+
.replace(new RegExp(exports.cjk + `(['"])`, 'g'), '$1 $2')
|
|
265
|
+
.replace(new RegExp(`(['"])` + exports.cjk, 'g'), '$1 $2')
|
|
266
|
+
.replace(/(["']+)\s*(.+?)\s*(["']+)/g, '$1$2$3')
|
|
267
|
+
.replace(new RegExp(exports.cjk + '([\\+\\-\\*\\/=&\\\\\\|<>])([A-Za-z0-9])', 'g'), '$1 $2 $3')
|
|
268
|
+
.replace(new RegExp('([A-Za-z0-9])([\\+\\-\\*\\/=&\\\\\\|<>])' + exports.cjk, 'g'), '$1 $2 $3');
|
|
269
|
+
const textBak = text_;
|
|
270
|
+
text_ = text_.replace(new RegExp(exports.cjk + '([\\(\\[\\{<\u201c]+(.*?)[\\)\\]\\}>\u201d]+)' + exports.cjk, 'g'), '$1 $2 $4');
|
|
271
|
+
if (text_ === textBak)
|
|
272
|
+
text_ = text_
|
|
273
|
+
.replace(new RegExp(exports.cjk + '([\\(\\[\\{<\u201c>])', 'g'), '$1 $2')
|
|
274
|
+
.replace(new RegExp('([\\)\\]\\}>\u201d<])' + exports.cjk, 'g'), '$1 $2');
|
|
275
|
+
return text_
|
|
276
|
+
// eslint-disable-next-line no-useless-escape
|
|
277
|
+
.replace(/([\(\[\{<\u201c]+)(\s*)(.+?)(\s*)([\)\]\}>\u201d]+)/g, '$1$3$5')
|
|
278
|
+
.replace(new RegExp(exports.cjk + '([~!;:,\\.\\?\u2026])([A-Za-z0-9])', 'g'), '$1$2 $3')
|
|
279
|
+
.replace(new RegExp(exports.cjk + '([A-Za-z0-9`\\$%\\^&\\*\\-=\\+\\\\\\|\\/@\u00a1-\u00ff\u2022\u2027\u2150-\u218f])', 'g'), '$1 $2')
|
|
280
|
+
.replace(new RegExp('([A-Za-z0-9`\\$%\\^&\\*\\-=\\+\\\\\\|\\/@\u00a1-\u00ff\u2022\u2027\u2150-\u218f])' + exports.cjk, 'g'), '$1 $2');
|
|
281
|
+
},
|
|
282
|
+
to_slash() {
|
|
283
|
+
return this.replaceAll('\\', '/');
|
|
284
|
+
},
|
|
285
|
+
to_backslash() {
|
|
286
|
+
return this.replaceAll('/', '\\');
|
|
287
|
+
},
|
|
288
|
+
}),
|
|
289
|
+
});
|
|
290
|
+
// ------------------------------------ Date.prototype
|
|
291
|
+
Object.defineProperties(Date.prototype, to_method_property_descriptors({
|
|
292
|
+
to_str() {
|
|
293
|
+
return this.toLocaleString().replace(/(\d+)\/(\d+)\/(\d+) ?(上午|下午)(\d+):(\d{2}):(\d{2}).*/, (matches, year, month, day, ampm, hour, minute, second) => {
|
|
294
|
+
hour = Number(hour);
|
|
295
|
+
if (ampm === '上午' && hour === 12) {
|
|
296
|
+
hour = 0;
|
|
297
|
+
ampm = '凌晨';
|
|
298
|
+
}
|
|
299
|
+
else if (ampm === '上午' && hour <= 6)
|
|
300
|
+
ampm = '凌晨';
|
|
301
|
+
else if (ampm === '上午' && hour <= 8)
|
|
302
|
+
ampm = '早上';
|
|
303
|
+
else if (ampm === '上午' && hour <= 10)
|
|
304
|
+
ampm = '上午';
|
|
305
|
+
else if (ampm === '上午' && hour <= 11)
|
|
306
|
+
ampm = '中午';
|
|
307
|
+
else if (ampm === '下午' && hour === 12)
|
|
308
|
+
ampm = '中午';
|
|
309
|
+
else if (ampm === '下午' && hour <= 5)
|
|
310
|
+
ampm = '下午';
|
|
311
|
+
else
|
|
312
|
+
ampm = '晚上';
|
|
313
|
+
return year + '.' + month.pad(2, { character: '0', position: 'left' }) + '.' + day.pad(2, { character: '0', position: 'left' }) + ' ' +
|
|
314
|
+
ampm + ' ' + hour.toString().pad(2, { character: '0', position: 'left' }) + ':' + minute + ':' + second;
|
|
315
|
+
});
|
|
316
|
+
},
|
|
317
|
+
to_date_str() {
|
|
318
|
+
return this.to_str().split(' ')[0];
|
|
319
|
+
},
|
|
320
|
+
to_time_str() {
|
|
321
|
+
const [, ampm, time] = this.to_str().split(' ');
|
|
322
|
+
return ampm + ' ' + time;
|
|
323
|
+
},
|
|
324
|
+
}));
|
|
325
|
+
// ------------------------------------ Number.prototype
|
|
326
|
+
Object.defineProperties(Number.prototype, to_method_property_descriptors({
|
|
327
|
+
to_bin_str() {
|
|
328
|
+
return `0b${this.toString(2)}`;
|
|
329
|
+
},
|
|
330
|
+
to_hex_str(length) {
|
|
331
|
+
const s = this.toString(16);
|
|
332
|
+
// 长度自动对齐到 4 的倍数
|
|
333
|
+
if (!length)
|
|
334
|
+
length = Math.ceil(s.length / 4) * 4;
|
|
335
|
+
return `0x${'0'.repeat(length - s.length)}${s}`;
|
|
336
|
+
},
|
|
337
|
+
to_oct_str() {
|
|
338
|
+
return `0o${this.toString(8)}`;
|
|
339
|
+
},
|
|
340
|
+
}));
|
|
341
|
+
// ------------------------------------ Array.prototype
|
|
342
|
+
Object.defineProperties(Array.prototype, {
|
|
343
|
+
// --- 文本处理工具方法
|
|
344
|
+
...to_method_property_descriptors({
|
|
345
|
+
trim_lines({ trim_line = true, rm_empty_lines = true, rm_last_empty_lines = false } = {}) {
|
|
346
|
+
if (!this.length)
|
|
347
|
+
return this;
|
|
348
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
349
|
+
let lines = this;
|
|
350
|
+
if (trim_line)
|
|
351
|
+
lines = lines.map(line => line.trim());
|
|
352
|
+
if (rm_empty_lines)
|
|
353
|
+
return lines.filter(line => line);
|
|
354
|
+
if (rm_last_empty_lines) {
|
|
355
|
+
lines.reverse();
|
|
356
|
+
const i_not_empty = lines.findIndex(line => line);
|
|
357
|
+
if (i_not_empty !== -1)
|
|
358
|
+
lines = lines.slice(i_not_empty);
|
|
359
|
+
lines.reverse();
|
|
360
|
+
return lines;
|
|
361
|
+
}
|
|
362
|
+
return lines;
|
|
363
|
+
},
|
|
364
|
+
indent(width, character = ' ') {
|
|
365
|
+
return this.map(line => character.repeat(width) + line);
|
|
366
|
+
},
|
|
367
|
+
join_lines(append = true) {
|
|
368
|
+
return `${this.join('\n')}${append ? '\n' : ''}`;
|
|
369
|
+
}
|
|
370
|
+
})
|
|
371
|
+
});
|
|
372
|
+
function to_json(object, replacer) {
|
|
373
|
+
return JSON.stringify(object, replacer, 4);
|
|
374
|
+
}
|
|
375
|
+
exports.to_json = to_json;
|
|
376
|
+
function is_codepoint_fullwidth(codepoint) {
|
|
377
|
+
// Code points are derived from:
|
|
378
|
+
// http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
|
|
379
|
+
return (!Number.isNaN(codepoint) &&
|
|
380
|
+
codepoint >= 0x1100 &&
|
|
381
|
+
(codepoint <= 0x115F || // Hangul Jamo
|
|
382
|
+
codepoint === 0x2026 || // …
|
|
383
|
+
codepoint === 0x203B || // ※
|
|
384
|
+
// arrows
|
|
385
|
+
(0x2190 <= codepoint && codepoint <= 0x21ff) ||
|
|
386
|
+
codepoint === 0x2329 || // left-pointing angle bracket
|
|
387
|
+
codepoint === 0x232a || // right-pointing angle bracket
|
|
388
|
+
// ①
|
|
389
|
+
(0x2460 <= codepoint && codepoint <= 0x24ff) ||
|
|
390
|
+
// box drawing
|
|
391
|
+
(0x2500 <= codepoint && codepoint <= 0x257f) ||
|
|
392
|
+
// shapes, symbols, …
|
|
393
|
+
(0x2580 <= codepoint && codepoint <= 0x2bef) ||
|
|
394
|
+
// cjk radicals supplement .. enclosed cjk letters and months
|
|
395
|
+
(0x2e80 <= codepoint && codepoint <= 0x3247 && codepoint !== 0x303f) ||
|
|
396
|
+
// enclosed cjk letters and months .. cjk unified ideographs extension a
|
|
397
|
+
(0x3250 <= codepoint && codepoint <= 0x4dbf) ||
|
|
398
|
+
// cjk unified ideographs .. yi radicals
|
|
399
|
+
(0x4e00 <= codepoint && codepoint <= 0xa4c6) ||
|
|
400
|
+
// hangul jamo extended-a
|
|
401
|
+
(0xa960 <= codepoint && codepoint <= 0xa97c) ||
|
|
402
|
+
// hangul syllables
|
|
403
|
+
(0xac00 <= codepoint && codepoint <= 0xd7a3) ||
|
|
404
|
+
// cjk compatibility ideographs
|
|
405
|
+
(0xf900 <= codepoint && codepoint <= 0xfaff) ||
|
|
406
|
+
// vertical forms
|
|
407
|
+
(0xfe10 <= codepoint && codepoint <= 0xfe19) ||
|
|
408
|
+
// cjk compatibility forms .. small form variants
|
|
409
|
+
(0xfe30 <= codepoint && codepoint <= 0xfe6b) ||
|
|
410
|
+
// halfwidth and fullwidth forms
|
|
411
|
+
(0xff01 <= codepoint && codepoint <= 0xff60) ||
|
|
412
|
+
(0xffe0 <= codepoint && codepoint <= 0xffe6) ||
|
|
413
|
+
// kana supplement
|
|
414
|
+
(0x1b000 <= codepoint && codepoint <= 0x1b001) ||
|
|
415
|
+
// enclosed ideographic supplement
|
|
416
|
+
(0x1f200 <= codepoint && codepoint <= 0x1f251) ||
|
|
417
|
+
// cjk unified ideographs extension b .. tertiary ideographic plane
|
|
418
|
+
(0x20000 <= codepoint && codepoint <= 0x3fffd)));
|
|
419
|
+
}
|
|
420
|
+
exports.is_codepoint_fullwidth = is_codepoint_fullwidth;
|
|
421
|
+
//# sourceMappingURL=prototype.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prototype.browser.js","sourceRoot":"","sources":["prototype.browser.ts"],"names":[],"mappings":";AAAA,+BAA+B;;;;AAqJ/B,2EAAoC;AAEvB,QAAA,WAAW,GAAG,IAAA,qBAAU,GAAE,CAAA;AAGvC,SAAgB,8BAA8B,CAAE,OAAqC;IACjF,OAAO,MAAM,CAAC,WAAW,CACrB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SAClB,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;YAC5B,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,KAAK;YACjB,KAAK;SACc,CAAC,CAAC,CAC5B,CAAC,CAAA;AACV,CAAC;AAVD,wEAUC;AAGD,SAAgB,8BAA8B,CAAE,OAAqC;IACjF,OAAO,MAAM,CAAC,WAAW,CACrB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SAClB,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;YAC1B,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,KAAK;YACjB,GAAG;SACgB,CAAC,CAAC,CAC5B,CAAC,CAAA;AACV,CAAC;AATD,wEASC;AAGY,QAAA,GAAG,GAAG,gCAAgC,CAAA;AAEtC,QAAA,MAAM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SAAS,IAAI,SAAS,IAAI,MAAM,IAAI,SAAS,KAAK,MAAM,CAAC;YAEpE,wEAAwE;YACxE,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,wCAAwC;YACxC,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,yBAAyB;YACzB,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,mBAAmB;YACnB,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,+BAA+B;YAC/B,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,iBAAiB;YACjB,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,iDAAiD;YACjD,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,gCAAgC;YAChC,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAC5C,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,kBAAkB;YAClB,CAAC,OAAO,IAAI,SAAS,IAAI,SAAS,IAAI,OAAO,CAAC;YAE9C,kCAAkC;YAClC,CAAC,OAAO,IAAI,SAAS,IAAI,SAAS,IAAI,OAAO,CAAC;YAE9C,mEAAmE;YACnE,CAAC,OAAO,IAAI,SAAS,IAAI,SAAS,IAAI,OAAO,CAAC,CACjD,CACJ,CAAA;AACL,CAAC;AAjED,wDAiEC","sourcesContent":["/** 在浏览器端修改 prototype,需要更加小心 */\n\ndeclare global {\n interface String {\n readonly width: number\n \n // --- 工具方法\n /** 截取字符串不超过 width 显示宽度的部分,并保留颜色 \n 找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted \n 若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + … \n 否则 返回 this \n */\n truncate (this: string, width: number): string\n \n pad (this: string, width: number, { character, position }?: { character?: string, position?: 'left' | 'right'}): string\n \n limit (this: string, width: number, { character, position }?: { character?: string, position?: 'left' | 'right'}): string\n \n to_regx (this: string, preservations?: string, flags?: string): RegExp\n \n /** ```ts\n 'g:/acgn/海贼王/[Skytree][海贼王][One_Piece][893][GB_BIG5_JP][X264_AAC][1080P][CRRIP][天空树双语字幕组].mkv'.refmt( \n '{dirp}/[Skytree][海贼王][{ en_name: \\\\w+ }][{ episode: \\\\d+ }][GB_BIG5_JP][{encoding}_AAC][1080P][CRRIP][天空树双语字幕组].{format}', \n 'g:/acgn/海贼王/{episode} {encoding}.{format}', \n '\\\\+', \n 'i', \n (name, value) => name === 'episode' ? String(+value + 1) : value.toLowerCase() \n )\n ```\n */\n refmt ( this: string,\n pattern: string,\n \n pattern_: string,\n \n /** `''` 保留的正则表达式字符 */\n preservations?: string,\n \n /** `''` 正则匹配选项 */\n flags?: string,\n \n /** `(name, matched) => matched || ''` placeholder transformer */\n transformer?: (name: string, value: string, placeholders: { [name: string]: string }) => string,\n \n /** `/\\{.*?\\}/g` */\n pattern_placeholder?: RegExp\n \n ): string\n \n \n /** 字符串模式搜索\n ```ts\n 'git+https://github.com/tamino-martinius/node-ts-dedent-123.git'.find(\n '^{protocol:[\\\\w+]+}://{hostname:[\\\\w\\\\.]+}/{username}/{project}-{index:\\\\d+}.{suffix}', '^', 'i'\n )\n {\n protocol: 'git+https',\n hostname: 'github.com',\n ...\n }\n ```\n \n - preservations?: `''` 保留的正则表达式字符\n - flags?: `''` 正则匹配选项\n - pattern_placeholder?: `/\\{.*?\\}/g`\n */\n find (this: string,\n \n pattern: string, \n \n preservations?: string, \n \n flags?: string, \n \n pattern_placeholder?: RegExp\n \n ): { [name: string]: string }\n \n \n /** - type?: `'single'` */\n quote (this: string, type?: keyof typeof quotes | 'psh'): string\n \n /** - shape?: `'parenthesis'` */\n bracket (this: string, shape?: keyof typeof brackets): string\n \n surround (this: string, left: string, right?: string): string\n \n surround_tag (this: string, tag_name: string): string\n \n to_lf (this: string): string\n \n to_crlf (this: string): string\n \n /** 'xxx'.replace(/pattern/g, '') \n 如果 pattern 是 string 则在创建 RegExp 时自动加上 flags (默认 'g'), 否则忽略 flags\n */\n rm (this: string, pattern: string | RegExp, flags?: string): string\n \n \n // --- 文本处理\n split_lines (this: string): string[]\n \n trim_doc_comment (this: string): string\n \n split_indent (this: string): { indent: number, text: string }\n \n \n space (this: string): string\n \n to_slash (this: string): string\n \n to_backslash (this: string): string\n }\n \n \n interface Date {\n to_str (this: Date): string\n \n to_date_str (this: Date): string\n \n to_time_str (this: Date): string\n }\n \n \n interface Number {\n to_bin_str (this: number): string\n \n to_hex_str (this: number): string\n \n to_oct_str (this: number): string\n }\n \n \n interface Array<T> {\n indent (this: string[], width: number, c?: string): string[]\n \n // --- 文本处理\n /**\n - trim_line?: `true`\n - rm_empty_lines?: `true`\n - rm_last_empty_lines?: `false`\n */\n trim_lines (this: string[], { trim_line, rm_empty_lines, rm_last_empty_lines }?: { trim_line?: boolean, rm_empty_lines?: boolean, rm_last_empty_lines?: boolean }): string[]\n \n join_lines (): string\n }\n}\n\n\nimport EmojiRegex from 'emoji-regex'\n\nexport const emoji_regex = EmojiRegex()\n\n\nexport function to_method_property_descriptors (methods: { [name: string]: Function }): PropertyDescriptorMap {\n return Object.fromEntries(\n Object.entries(methods)\n .map(([name, value]) => ([name, {\n configurable: true,\n writable: true,\n enumerable: false,\n value,\n } as PropertyDescriptor])\n ))\n}\n\n\nexport function to_getter_property_descriptors (getters: { [name: string]: Function }): PropertyDescriptorMap {\n return Object.fromEntries(\n Object.entries(getters)\n .map(([name, get]) => ([name, {\n configurable: true,\n enumerable: false,\n get,\n } as PropertyDescriptor])\n ))\n}\n\n\nexport const cjk = '([\\u2e80-\\u9fff\\uf900-\\ufaff])'\n\nexport const quotes = {\n single: \"'\",\n double: '\"',\n backtick: '`',\n}\n\nexport const brackets = {\n round: ['(', ')'],\n square: ['[', ']'],\n curly: ['{', '}'],\n pointy: ['<', '>'],\n corner: ['「', '」'],\n fat: ['【', '】'],\n tortoise_shell: ['〔', '〕'],\n} as const\n\n\n\n// ------------------------------------ String.prototype\nObject.defineProperties(String.prototype, {\n ... to_getter_property_descriptors({\n width (this: string) {\n const s = this.replace(emoji_regex, ' ')\n let width = 0\n for (let i = 0; i < s.length; i++) {\n const code = s.codePointAt(i)\n \n if (\n (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) || // ignore control characters\n code >= 0x300 && code <= 0x36f // ignore combining characters\n ) continue\n \n // surrogates\n if (code > 0xFFFF)\n i++\n \n width += is_codepoint_fullwidth(code) ? 2 : 1\n }\n return width\n }\n }),\n \n \n \n // ------------ 文本处理工具方法\n ... to_method_property_descriptors({\n /** 截取字符串不超过 width 显示宽度的部分,并保留颜色 \n 找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted \n - 若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + … \n - 否则 返回 this \n */\n truncate (this: string, width: number) {\n const color_bak = this.startsWith('\\u001b') ? this.slice(0, 5) : ''\n if (width <= 2) return this.slice(0, width)\n let i_fitted = 0\n let fitted_width = 0\n let cur_width = 0\n for (let i = 0; i < this.length; i++) {\n const code = this.codePointAt(i)\n \n if (\n (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) || // Ignore control characters\n code >= 0x300 && code <= 0x36F // Ignore combining characters\n ) continue\n \n // surrogates (codepoint 需要用两个 utf-16 编码单位表示,因此这里跳过第二个编码单位,防止重复计算显示宽度)\n if (code > 0xFFFF)\n i++\n \n const w = is_codepoint_fullwidth(code) ? 2 : 1\n \n if (cur_width + w + 2 <= width) {\n i_fitted = i\n fitted_width += w\n }\n \n cur_width += w\n \n if (cur_width > width) {\n const i_fitted_next = i_fitted + 1\n const t = this.slice(0, i_fitted_next) + ' '.repeat(width - 2 - fitted_width) + '…' \n return color_bak ? color_bak + t + '\\u001b[39m' : t\n }\n }\n return this\n },\n \n \n pad (this: string, width: number, { character = ' ', position = 'right' }: { character?: string, position?: 'left' | 'right'} = { }) {\n const _width = this.width\n if (_width >= width) return this\n if (position === 'right') return this + character.repeat( (width - _width) / character.width )\n return character.repeat(width - _width) + this\n },\n \n \n limit (this: string, width: number, { character = ' ', position = 'right' }: { character?: string, position?: 'left' | 'right'} = { }) {\n return this.pad(width, { character, position }).truncate(width)\n },\n \n \n to_regx (this: string, preservations: string, flags = ''): RegExp {\n const preserved_chars = new Set(preservations)\n const replace_chars: string = Array.prototype.filter.call('|\\\\{}()[]^$+*?.-', (c: string) => !preserved_chars.has(c))\n .map((c: string) =>\n c === ']' ? '\\\\]' : c\n ).join('')\n \n return new RegExp( this.replace(new RegExp(`[${replace_chars}]`, 'g'), '\\\\$&'), flags)\n },\n \n \n refmt (this: string, \n pattern : string,\n pattern_: string,\n preservations: string = '',\n flags = '',\n transformer: (name: string, value: string, placeholders: { [name: string]: string }) => string = (name, value) => value || '',\n pattern_placeholder = /\\{.*?\\}/g,\n ): string {\n // --- 转换 pattern 为 pattern_regx\n let last_end = 0\n \n // placeholder matched group indexes\n let $placeholders: Record<string, number> = { }\n \n let regx_parts = [ ]\n \n function add_part (left: number, right?: number) {\n const part = pattern.slice(left, right)\n if (part)\n regx_parts.push(\n part.to_regx(preservations).source.bracket()\n )\n }\n \n pattern.replace(pattern_placeholder, ($0, offset) => {\n add_part(last_end, offset)\n last_end = offset + $0.length\n \n const placeholder = $0.slice(1, -1)\n let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim())\n let optional = false\n if (placeholder_name.endsWith('?')) {\n placeholder_name = placeholder_name.slice(0, -1)\n optional = true\n }\n $placeholders[placeholder_name] = regx_parts.push(placeholder_pattern ? \n `${placeholder_pattern.bracket()}${optional ? '?' : ''}`\n :\n '(.*?)'\n )\n return ''\n })\n \n add_part(last_end)\n \n // 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要\n regx_parts = regx_parts.filter(part => part)\n if (regx_parts.last === '(.*?)')\n regx_parts[regx_parts.length - 1] = '(.*)'\n \n const pattern_regx = new RegExp(regx_parts.join(''), flags)\n \n \n // --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典\n const matches = pattern_regx.exec(this)\n \n if (!matches) return this\n \n const placeholders = Object.fromEntries(\n Object.entries($placeholders)\n .map(([name, $i]) => [\n [name, matches[$i]],\n [`${name}.before`, matches[$i - 1] || ''],\n [`${name}.after`, matches[$i + 1] || ''],\n ])\n .flat()\n )\n \n \n // --- 转换 pattern_ 为 replacement_str,如果有 transformer 则在遇到 placeholder 时应用\n last_end = 0\n let replacement_parts = [ ]\n \n pattern_.replace(pattern_placeholder, ($0, offset) => {\n replacement_parts.push(\n pattern_.slice(last_end, offset)\n )\n last_end = offset + $0.length\n \n const placeholder_name = $0.slice(1, -1)\n \n replacement_parts.push(\n transformer(placeholder_name, placeholders[placeholder_name], placeholders)\n )\n \n return ''\n })\n replacement_parts.push(\n pattern_.slice(last_end)\n )\n \n return this.replace(pattern_regx, replacement_parts.join(''))\n },\n \n \n find (this: string,\n pattern: string, \n preservations: string = '', \n flags = '', \n pattern_placeholder = /\\{.*?\\}/g\n ): { [name: string]: string } {\n // --- 转换 pattern 为 pattern_regx\n let last_end = 0\n \n // placeholder matched group index\n let $placeholders: Record<string, number> = { }\n \n let regx_parts = [ ]\n \n function add_part (left: number, right?: number) {\n const part = pattern.slice(left, right)\n if (part)\n regx_parts.push(\n part.to_regx(preservations).source.bracket()\n )\n }\n \n pattern.replace(pattern_placeholder, ($0, offset) => {\n add_part(last_end, offset)\n last_end = offset + $0.length\n \n const placeholder = $0.slice(1, -1)\n let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim())\n let optional = false\n if (placeholder_name.endsWith('?')) {\n placeholder_name = placeholder_name.slice(0, -1)\n optional = true\n }\n \n $placeholders[placeholder_name] = regx_parts.push(\n placeholder_pattern ? \n `${placeholder_pattern.bracket()}${optional ? '?' : ''}`\n :\n '(.*?)'\n )\n return ''\n })\n \n add_part(last_end)\n \n // 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要\n regx_parts = regx_parts.filter(part => part)\n if (regx_parts[ regx_parts.length - 1 ] === '(.*?)')\n regx_parts[regx_parts.length - 1] = '(.*)'\n \n const pattern_regx = new RegExp(regx_parts.join(''), flags)\n \n \n // --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典\n const matches = pattern_regx.exec(this)\n \n if (!matches) return { }\n \n return Object.fromEntries(\n Object.entries($placeholders)\n .map(([name, $i]) => \n [name, matches[$i] || '']\n )\n )\n },\n \n quote (this: string, type: keyof typeof quotes | 'psh' = 'single') {\n if (type === 'psh') return '& ' + this.quote()\n return this.surround(quotes[type])\n },\n \n \n bracket (this: string, shape: keyof typeof brackets = 'round') {\n return this.surround(...brackets[shape] as [string, string])\n },\n \n \n surround (this: string, left: string, right?: string) {\n return left + this + (right || left)\n },\n \n surround_tag (this: string, tag_name: string): string {\n return '<' + tag_name + '>' + this + '</' + tag_name + '>'\n },\n \n \n to_lf (this: string) {\n return this.replace(/\\r\\n/g, '\\n')\n },\n \n \n to_crlf (this: string) {\n return this.replace(/\\n/g, '\\r\\n')\n },\n \n \n rm (this: string, pattern: string | RegExp, flags: string = 'g') {\n if (typeof pattern === 'string')\n pattern = new RegExp(pattern, flags)\n \n return this.replace(pattern, '')\n },\n \n \n split_lines (this: string, delimiter: string | RegExp = /\\r?\\n/) {\n let lines = this.split(delimiter)\n if (lines.last === '')\n lines.pop()\n return lines\n },\n \n \n split_indent (this: string): { indent: number, text: string } {\n let i = 0\n let indent = 0\n for (; i < this.length; i++)\n if (this[i] === ' ')\n indent += 1\n else if (this[i] === '\\t')\n indent += 4\n else\n break\n \n return {\n indent,\n text: this.slice(i)\n }\n },\n \n \n space (this: string) {\n if (!this) return this\n let text_: string\n text_ = this\n .replace(new RegExp(cjk + `(['\"])`, 'g'), '$1 $2')\n .replace(new RegExp(`(['\"])` + cjk, 'g'), '$1 $2')\n \n .replace(/([\"']+)\\s*(.+?)\\s*([\"']+)/g, '$1$2$3')\n \n .replace(new RegExp(cjk + '([\\\\+\\\\-\\\\*\\\\/=&\\\\\\\\\\\\|<>])([A-Za-z0-9])', 'g'), '$1 $2 $3')\n .replace(new RegExp('([A-Za-z0-9])([\\\\+\\\\-\\\\*\\\\/=&\\\\\\\\\\\\|<>])' + cjk, 'g'), '$1 $2 $3')\n \n const textBak = text_\n \n text_ = text_.replace(new RegExp(cjk + '([\\\\(\\\\[\\\\{<\\u201c]+(.*?)[\\\\)\\\\]\\\\}>\\u201d]+)' + cjk, 'g'), '$1 $2 $4')\n \n if (text_ === textBak)\n text_ = text_\n .replace(new RegExp(cjk + '([\\\\(\\\\[\\\\{<\\u201c>])', 'g'), '$1 $2')\n .replace(new RegExp('([\\\\)\\\\]\\\\}>\\u201d<])' + cjk, 'g'), '$1 $2')\n \n return text_\n // eslint-disable-next-line no-useless-escape\n .replace(/([\\(\\[\\{<\\u201c]+)(\\s*)(.+?)(\\s*)([\\)\\]\\}>\\u201d]+)/g, '$1$3$5')\n .replace(new RegExp(cjk + '([~!;:,\\\\.\\\\?\\u2026])([A-Za-z0-9])', 'g'), '$1$2 $3')\n .replace(new RegExp(cjk + '([A-Za-z0-9`\\\\$%\\\\^&\\\\*\\\\-=\\\\+\\\\\\\\\\\\|\\\\/@\\u00a1-\\u00ff\\u2022\\u2027\\u2150-\\u218f])', 'g'), '$1 $2')\n .replace(new RegExp('([A-Za-z0-9`\\\\$%\\\\^&\\\\*\\\\-=\\\\+\\\\\\\\\\\\|\\\\/@\\u00a1-\\u00ff\\u2022\\u2027\\u2150-\\u218f])' + cjk, 'g'), '$1 $2')\n },\n \n to_slash (this: string) {\n return this.replaceAll('\\\\', '/')\n },\n \n to_backslash (this: string) {\n return this.replaceAll('/', '\\\\')\n },\n }),\n})\n\n\n// ------------------------------------ Date.prototype\nObject.defineProperties(Date.prototype, to_method_property_descriptors({\n to_str (this: Date) {\n return this.toLocaleString().replace(/(\\d+)\\/(\\d+)\\/(\\d+) ?(上午|下午)(\\d+):(\\d{2}):(\\d{2}).*/, (matches, year, month, day, ampm, hour, minute, second) => {\n hour = Number(hour)\n if (ampm === '上午' && hour === 12) {\n hour = 0\n ampm = '凌晨'\n }\n else if (ampm === '上午' && hour <= 6) ampm = '凌晨'\n else if (ampm === '上午' && hour <= 8 ) ampm = '早上'\n else if (ampm === '上午' && hour <= 10) ampm = '上午'\n else if (ampm === '上午' && hour <= 11) ampm = '中午'\n else if (ampm === '下午' && hour === 12) ampm = '中午'\n else if (ampm === '下午' && hour <= 5 ) ampm = '下午'\n else ampm = '晚上'\n \n return year + '.' + month.pad(2, { character: '0', position: 'left' }) + '.' + day.pad(2, { character: '0', position: 'left' }) + ' ' + \n ampm + ' ' + hour.toString().pad(2, { character: '0', position: 'left' }) + ':' + minute + ':' + second\n })\n },\n \n to_date_str (this: Date) {\n return this.to_str().split(' ')[0]\n },\n \n to_time_str (this: Date) {\n const [, ampm, time ] = this.to_str().split(' ')\n return ampm + ' ' + time\n },\n}))\n\n\n\n// ------------------------------------ Number.prototype\nObject.defineProperties(Number.prototype, to_method_property_descriptors({\n to_bin_str (this: number) {\n return `0b${this.toString(2)}`\n },\n \n to_hex_str (this: number, length?: number) {\n const s = this.toString(16)\n // 长度自动对齐到 4 的倍数\n if (!length)\n length = Math.ceil(s.length / 4) * 4\n return `0x${'0'.repeat(length - s.length)}${s}`\n },\n \n to_oct_str (this: number) {\n return `0o${this.toString(8)}`\n },\n}))\n\n\n\n// ------------------------------------ Array.prototype\nObject.defineProperties(Array.prototype, {\n // --- 文本处理工具方法\n ... to_method_property_descriptors({\n trim_lines (this: string[], { trim_line = true, rm_empty_lines = true, rm_last_empty_lines = false }: { trim_line?: boolean, rm_empty_lines?: boolean, rm_last_empty_lines?: boolean } = { }) {\n if (!this.length) return this\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n let lines = this\n \n if (trim_line)\n lines = lines.map(line => line.trim())\n \n if (rm_empty_lines)\n return lines.filter( line => line )\n \n if (rm_last_empty_lines) {\n lines.reverse()\n const i_not_empty = lines.findIndex( line => line )\n if (i_not_empty !== -1)\n lines = lines.slice(i_not_empty)\n lines.reverse()\n return lines\n }\n \n return lines\n },\n \n \n indent (this: string[], width?: number, character: string = ' ') {\n return this.map(line => \n character.repeat(width) + line\n )\n },\n \n \n join_lines (this: string[], append = true) {\n return `${this.join('\\n')}${append ? '\\n' : ''}`\n }\n })\n})\n\n\nexport function to_json (object: any, replacer?: any) {\n return JSON.stringify(object, replacer, 4)\n}\n\nexport function is_codepoint_fullwidth (codepoint: number) {\n // Code points are derived from:\n // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt\n return (\n !Number.isNaN(codepoint) &&\n codepoint >= 0x1100 &&\n (\n codepoint <= 0x115F || // Hangul Jamo\n \n codepoint === 0x2026 || // …\n codepoint === 0x203B || // ※\n \n // arrows\n (0x2190 <= codepoint && codepoint <= 0x21ff) ||\n \n codepoint === 0x2329 || // left-pointing angle bracket\n codepoint === 0x232a || // right-pointing angle bracket\n \n // ①\n (0x2460 <= codepoint && codepoint <= 0x24ff) ||\n \n // box drawing\n (0x2500 <= codepoint && codepoint <= 0x257f) ||\n \n // shapes, symbols, …\n (0x2580 <= codepoint && codepoint <= 0x2bef) ||\n \n // cjk radicals supplement .. enclosed cjk letters and months\n (0x2e80 <= codepoint && codepoint <= 0x3247 && codepoint !== 0x303f) ||\n \n // enclosed cjk letters and months .. cjk unified ideographs extension a\n (0x3250 <= codepoint && codepoint <= 0x4dbf) ||\n \n // cjk unified ideographs .. yi radicals\n (0x4e00 <= codepoint && codepoint <= 0xa4c6) ||\n \n // hangul jamo extended-a\n (0xa960 <= codepoint && codepoint <= 0xa97c) ||\n \n // hangul syllables\n (0xac00 <= codepoint && codepoint <= 0xd7a3) ||\n \n // cjk compatibility ideographs\n (0xf900 <= codepoint && codepoint <= 0xfaff) ||\n \n // vertical forms\n (0xfe10 <= codepoint && codepoint <= 0xfe19) ||\n \n // cjk compatibility forms .. small form variants\n (0xfe30 <= codepoint && codepoint <= 0xfe6b) ||\n \n // halfwidth and fullwidth forms\n (0xff01 <= codepoint && codepoint <= 0xff60) ||\n (0xffe0 <= codepoint && codepoint <= 0xffe6) ||\n \n // kana supplement\n (0x1b000 <= codepoint && codepoint <= 0x1b001) ||\n \n // enclosed ideographic supplement\n (0x1f200 <= codepoint && codepoint <= 0x1f251) ||\n \n // cjk unified ideographs extension b .. tertiary ideographic plane\n (0x20000 <= codepoint && codepoint <= 0x3fffd)\n )\n )\n}\n\n\n\n"]}
|
package/scroll-bar.sass
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
::-webkit-scrollbar, ::-webkit-scrollbar:horizontal, ::-webkit-scrollbar:vertical
|
|
2
|
+
width: 8px !important
|
|
3
|
+
height: 8px !important
|
|
4
|
+
background-color: #000000 !important
|
|
5
|
+
|
|
6
|
+
::-webkit-scrollbar-track-piece
|
|
7
|
+
background-color: #ffffff !important
|
|
8
|
+
box-shadow: inset 0 0 0px #000000 !important
|
|
9
|
+
border: 0px solid #000000 !important
|
|
10
|
+
border-radius: 0px !important
|
|
11
|
+
&:vertical
|
|
12
|
+
background-image: ''
|
|
13
|
+
&:hover
|
|
14
|
+
background-image: ''
|
|
15
|
+
&:horizontal
|
|
16
|
+
background-image: ''
|
|
17
|
+
&:hover
|
|
18
|
+
background-image: ''
|
|
19
|
+
&:hover
|
|
20
|
+
background-color: #D9D9D9 !important
|
|
21
|
+
box-shadow: inset 0 0 0px #000000 !important
|
|
22
|
+
|
|
23
|
+
::-webkit-scrollbar-thumb
|
|
24
|
+
background-color: #303030 !important
|
|
25
|
+
box-shadow: inset 0 0 0px #000000 !important
|
|
26
|
+
border-radius: 0px !important
|
|
27
|
+
border: 0px solid #000000 !important
|
|
28
|
+
&:vertical
|
|
29
|
+
background-image: ''
|
|
30
|
+
&:horizontal
|
|
31
|
+
background-image: ''
|
|
32
|
+
|
|
33
|
+
::-webkit-scrollbar-corner
|
|
34
|
+
background-color: #B0BEC5 !important
|
|
35
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import './toaster.sass';
|
|
2
|
+
export declare let toaster: {
|
|
3
|
+
messages: string[];
|
|
4
|
+
state: "IDLE" | "SHOW";
|
|
5
|
+
toast(message: string): Promise<void>;
|
|
6
|
+
show(): Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export declare const toast: (message: string) => Promise<void>;
|
|
9
|
+
export default toast;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toast = exports.toaster = void 0;
|
|
4
|
+
require("./toaster.sass");
|
|
5
|
+
const utils_browser_1 = require("./utils.browser");
|
|
6
|
+
exports.toaster = {
|
|
7
|
+
messages: [],
|
|
8
|
+
state: 'IDLE',
|
|
9
|
+
async toast(message) {
|
|
10
|
+
this.messages.push(message);
|
|
11
|
+
this.show();
|
|
12
|
+
},
|
|
13
|
+
async show() {
|
|
14
|
+
if (this.state === 'SHOW')
|
|
15
|
+
return;
|
|
16
|
+
this.state = 'SHOW';
|
|
17
|
+
let div = document.createElement('div');
|
|
18
|
+
div.className = 'toast';
|
|
19
|
+
document.body.appendChild(div);
|
|
20
|
+
for (let i = 0; i < this.messages.length; i++) {
|
|
21
|
+
const message = this.messages[i];
|
|
22
|
+
let span;
|
|
23
|
+
if (i === 0) {
|
|
24
|
+
span = document.createElement('span');
|
|
25
|
+
span.className = 'text';
|
|
26
|
+
span.textContent = message;
|
|
27
|
+
div.appendChild(span);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
span = div.children[0];
|
|
31
|
+
span.textContent = message;
|
|
32
|
+
}
|
|
33
|
+
div.classList.add('active');
|
|
34
|
+
await (0, utils_browser_1.delay)(2 * 1000);
|
|
35
|
+
div.classList.remove('active');
|
|
36
|
+
await (0, utils_browser_1.delay)(500);
|
|
37
|
+
}
|
|
38
|
+
document.body.removeChild(div);
|
|
39
|
+
this.messages = [];
|
|
40
|
+
this.state = 'IDLE';
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
exports.toast = exports.toaster.toast.bind(exports.toaster);
|
|
44
|
+
exports.default = exports.toast;
|
|
45
|
+
//# sourceMappingURL=toaster.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toaster.browser.js","sourceRoot":"","sources":["toaster.browser.ts"],"names":[],"mappings":";;;AAAA,0BAAuB;AAEvB,mDAAuC;AAE5B,QAAA,OAAO,GAAG;IACjB,QAAQ,EAAE,EAAe;IAEzB,KAAK,EAAE,MAAyB;IAEhC,KAAK,CAAC,KAAK,CAAE,OAAe;QACxB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC3B,IAAI,CAAC,IAAI,EAAE,CAAA;IACf,CAAC;IAED,KAAK,CAAC,IAAI;QACN,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM;YAAE,OAAM;QACjC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;QAEnB,IAAI,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;QACvC,GAAG,CAAC,SAAS,GAAG,OAAO,CAAA;QACvB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;QAE9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAG,CAAC,EAAE,EAAE;YAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;YAChC,IAAI,IAAqB,CAAA;YACzB,IAAI,CAAC,KAAK,CAAC,EAAE;gBACT,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;gBACrC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAA;gBACvB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAA;gBAC1B,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;aACxB;iBAAM;gBACH,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAoB,CAAA;gBACzC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAA;aAC7B;YAED,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YAC3B,MAAM,IAAA,qBAAK,EAAC,CAAC,GAAG,IAAI,CAAC,CAAA;YACrB,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAC9B,MAAM,IAAA,qBAAK,EAAC,GAAG,CAAC,CAAA;SACnB;QAED,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;QAC9B,IAAI,CAAC,QAAQ,GAAG,EAAG,CAAA;QACnB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;IACvB,CAAC;CACJ,CAAA;AAEY,QAAA,KAAK,GAAG,eAAO,CAAC,KAAK,CAAC,IAAI,CAAC,eAAO,CAA8B,CAAA;AAE7E,kBAAe,aAAK,CAAA","sourcesContent":["import './toaster.sass'\n\nimport { delay } from './utils.browser'\n\nexport let toaster = {\n messages: [ ] as string[],\n \n state: 'IDLE' as 'IDLE' | 'SHOW',\n \n async toast (message: string) {\n this.messages.push(message)\n this.show()\n },\n \n async show () {\n if (this.state === 'SHOW') return\n this.state = 'SHOW'\n \n let div = document.createElement('div')\n div.className = 'toast'\n document.body.appendChild(div)\n \n for (let i = 0; i < this.messages.length; i++) {\n const message = this.messages[i]\n let span: HTMLSpanElement\n if (i === 0) {\n span = document.createElement('span')\n span.className = 'text'\n span.textContent = message\n div.appendChild(span)\n } else {\n span = div.children[0] as HTMLSpanElement\n span.textContent = message\n }\n \n div.classList.add('active')\n await delay(2 * 1000)\n div.classList.remove('active')\n await delay(500)\n }\n \n document.body.removeChild(div)\n this.messages = [ ]\n this.state = 'IDLE'\n },\n}\n\nexport const toast = toaster.toast.bind(toaster) as (typeof toaster)['toast']\n\nexport default toast\n"]}
|
package/toaster.sass
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
.toast
|
|
2
|
+
position: absolute
|
|
3
|
+
left: 0
|
|
4
|
+
right: 0
|
|
5
|
+
bottom: 12%
|
|
6
|
+
z-index: 1000
|
|
7
|
+
|
|
8
|
+
display: flex
|
|
9
|
+
justify-content: center
|
|
10
|
+
|
|
11
|
+
.text
|
|
12
|
+
background-color: #f6f6f6
|
|
13
|
+
color: #333333
|
|
14
|
+
border-radius: 24px
|
|
15
|
+
padding: 15px 30px
|
|
16
|
+
font-size: 16px
|
|
17
|
+
|
|
18
|
+
opacity: 0
|
|
19
|
+
transition: opacity 0.5s
|
|
20
|
+
|
|
21
|
+
&.active .text
|
|
22
|
+
opacity: 1
|
package/utils.browser.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.concat = exports.delay = void 0;
|
|
4
|
+
async function delay(milliseconds) {
|
|
5
|
+
return new Promise(resolve => {
|
|
6
|
+
setTimeout(() => {
|
|
7
|
+
resolve();
|
|
8
|
+
}, milliseconds);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
exports.delay = delay;
|
|
12
|
+
/** 拼接 TypedArrays 生成一个完整的 Uint8Array */
|
|
13
|
+
function concat(arrays) {
|
|
14
|
+
let length = 0;
|
|
15
|
+
for (const a of arrays)
|
|
16
|
+
length += a.byteLength;
|
|
17
|
+
let buf = new Uint8Array(length);
|
|
18
|
+
let offset = 0;
|
|
19
|
+
for (const a of arrays) {
|
|
20
|
+
const uint8view = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
21
|
+
buf.set(uint8view, offset);
|
|
22
|
+
offset += uint8view.byteLength;
|
|
23
|
+
}
|
|
24
|
+
return buf;
|
|
25
|
+
}
|
|
26
|
+
exports.concat = concat;
|
|
27
|
+
//# sourceMappingURL=utils.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.browser.js","sourceRoot":"","sources":["utils.browser.ts"],"names":[],"mappings":";;;AAAO,KAAK,UAAU,KAAK,CAAE,YAAoB;IAC7C,OAAO,IAAI,OAAO,CAAQ,OAAO,CAAC,EAAE;QAChC,UAAU,CAAC,GAAG,EAAE;YACZ,OAAO,EAAE,CAAA;QACb,CAAC,EAAE,YAAY,CAAC,CAAA;IACpB,CAAC,CAAC,CAAA;AACN,CAAC;AAND,sBAMC;AAGD,wCAAwC;AACxC,SAAgB,MAAM,CAAE,MAAyB;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,MAAM,CAAC,IAAI,MAAM;QAClB,MAAM,IAAI,CAAC,CAAC,UAAU,CAAA;IAE1B,IAAI,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAA;IAChC,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;QACpB,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,CAAC,CAAA;QACtE,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAC1B,MAAM,IAAI,SAAS,CAAC,UAAU,CAAA;KACjC;IAED,OAAO,GAAG,CAAA;AACd,CAAC;AAdD,wBAcC","sourcesContent":["export async function delay (milliseconds: number) {\n return new Promise<void>( resolve => {\n setTimeout(() => {\n resolve()\n }, milliseconds)\n })\n}\n\n\n/** 拼接 TypedArrays 生成一个完整的 Uint8Array */\nexport function concat (arrays: ArrayBufferView[]) {\n let length = 0\n for (const a of arrays)\n length += a.byteLength\n \n let buf = new Uint8Array(length)\n let offset = 0\n for (const a of arrays) {\n const uint8view = new Uint8Array(a.buffer, a.byteOffset, a.byteLength)\n buf.set(uint8view, offset)\n offset += uint8view.byteLength\n }\n \n return buf\n}\n"]}
|
package/extension.d.ts
DELETED
package/extension.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.activate = void 0;
|
|
4
|
-
const vscode_1 = require("vscode");
|
|
5
|
-
require("./prototype");
|
|
6
|
-
const net_1 = require("./net");
|
|
7
|
-
const my_commands = [
|
|
8
|
-
{
|
|
9
|
-
func: async function xshell_repl() {
|
|
10
|
-
const editor = vscode_1.window.activeTextEditor;
|
|
11
|
-
const doc = editor.document;
|
|
12
|
-
const languages_map = {
|
|
13
|
-
javascript: ['ts'],
|
|
14
|
-
javascriptreact: ['ts'],
|
|
15
|
-
typescript: ['ts'],
|
|
16
|
-
typescriptreact: ['ts'],
|
|
17
|
-
};
|
|
18
|
-
const language_id = doc.languageId;
|
|
19
|
-
if (!(language_id in languages_map))
|
|
20
|
-
throw new Error(`${language_id} does not support repl`);
|
|
21
|
-
const code = get_text('selection or line');
|
|
22
|
-
await (0, net_1.rpc)('repl_code', [...languages_map[language_id], code], { async: true });
|
|
23
|
-
},
|
|
24
|
-
key: 'ctrl+enter',
|
|
25
|
-
when: 'editorTextFocus'
|
|
26
|
-
},
|
|
27
|
-
];
|
|
28
|
-
/** get text by selector */
|
|
29
|
-
function get_text(selector) {
|
|
30
|
-
const editor = vscode_1.window.activeTextEditor;
|
|
31
|
-
const document = editor.document;
|
|
32
|
-
const selection = editor.selection;
|
|
33
|
-
const text_selection = document.getText(selection);
|
|
34
|
-
if (selector === 'selection')
|
|
35
|
-
return text_selection;
|
|
36
|
-
const text_all = document.getText();
|
|
37
|
-
if (selector === 'all')
|
|
38
|
-
return text_all;
|
|
39
|
-
const text_line = document.lineAt(selection.active.line).text;
|
|
40
|
-
if (selector === 'line')
|
|
41
|
-
return text_line;
|
|
42
|
-
if (selector === 'word')
|
|
43
|
-
return document.getText(document.getWordRangeAtPosition(selection.active));
|
|
44
|
-
if (selector === 'selection or all')
|
|
45
|
-
return text_selection || text_all;
|
|
46
|
-
if (selector === 'selection or line')
|
|
47
|
-
return text_selection || text_line;
|
|
48
|
-
const start = selection.start;
|
|
49
|
-
const end = selection.end;
|
|
50
|
-
const line = document.lineAt(start.line);
|
|
51
|
-
const line_start = new vscode_1.Position(start.line, 0);
|
|
52
|
-
if (selector === 'selection before')
|
|
53
|
-
return document.getText(new vscode_1.Range(line_start, start));
|
|
54
|
-
const line_end = new vscode_1.Position(start.line, line.text.length);
|
|
55
|
-
if (selector === 'selection after')
|
|
56
|
-
return document.getText(new vscode_1.Range(end, line_end));
|
|
57
|
-
const line_text_start = new vscode_1.Position(start.line, line.firstNonWhitespaceCharacterIndex);
|
|
58
|
-
if (selector === 'selection to text start')
|
|
59
|
-
return document.getText(new vscode_1.Range(line_text_start, start));
|
|
60
|
-
}
|
|
61
|
-
function activate(ctx) {
|
|
62
|
-
my_commands.forEach(({ func }) => {
|
|
63
|
-
ctx.subscriptions.push(vscode_1.commands.registerCommand(func.name, func));
|
|
64
|
-
});
|
|
65
|
-
console.log('xshell loaded');
|
|
66
|
-
}
|
|
67
|
-
exports.activate = activate;
|
|
68
|
-
//# sourceMappingURL=extension.js.map
|
package/extension.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["extension.ts"],"names":[],"mappings":";;;AAAA,mCAA0D;AAG1D,uBAAoB;AACpB,+BAA2B;AAG3B,MAAM,WAAW,GAAG;IAChB;QACI,IAAI,EAAE,KAAK,UAAU,WAAW;YAC5B,MAAM,MAAM,GAAG,eAAM,CAAC,gBAAgB,CAAA;YACtC,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAA;YAE3B,MAAM,aAAa,GAAG;gBAClB,UAAU,EAAE,CAAC,IAAI,CAAC;gBAClB,eAAe,EAAE,CAAC,IAAI,CAAC;gBACvB,UAAU,EAAE,CAAC,IAAI,CAAC;gBAClB,eAAe,EAAE,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;IACF,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;AAChC,CAAC;AALD,4BAKC","sourcesContent":["import { window, commands, Range, Position } from 'vscode'\nimport type { ExtensionContext } from 'vscode'\n\nimport './prototype'\nimport { rpc } from './net'\n\n\nconst my_commands = [\n {\n func: async function xshell_repl () {\n const editor = window.activeTextEditor\n const doc = editor.document\n \n const languages_map = {\n javascript: ['ts'],\n javascriptreact: ['ts'],\n typescript: ['ts'],\n typescriptreact: ['ts'],\n }\n \n const language_id = doc.languageId\n \n if (!(language_id in languages_map))\n throw new Error(`${language_id} does not support repl`)\n \n const code = get_text('selection or line')\n \n await rpc('repl_code', [...languages_map[language_id], code], { async: true })\n },\n key: 'ctrl+enter',\n when: 'editorTextFocus'\n },\n]\n\n\n/** get text by selector */\nfunction get_text (selector: \n 'all' | \n 'line' | \n 'word' |\n 'selection' | \n 'selection or line' |\n 'selection or all' |\n 'selection before' | \n 'selection to text start' | \n 'selection after'\n) {\n const editor = window.activeTextEditor\n const document = editor.document\n const selection = editor.selection\n \n const text_selection = document.getText(selection)\n \n if (selector === 'selection')\n return text_selection\n \n const text_all = document.getText()\n \n if (selector === 'all')\n return text_all\n \n const text_line = document.lineAt(selection.active.line).text\n \n if (selector === 'line')\n return text_line\n \n if (selector === 'word')\n return document.getText(document.getWordRangeAtPosition(selection.active))\n \n if (selector === 'selection or all')\n return text_selection || text_all\n \n if (selector === 'selection or line')\n return text_selection || text_line\n \n \n \n const start = selection.start\n const end = selection.end\n \n const line = document.lineAt(start.line)\n \n const line_start = new Position(start.line, 0)\n \n if (selector === 'selection before')\n return document.getText( new Range(line_start, start) )\n \n \n const line_end = new Position(start.line, line.text.length)\n \n if (selector === 'selection after')\n return document.getText( new Range(end, line_end) )\n \n \n const line_text_start = new Position(start.line, line.firstNonWhitespaceCharacterIndex)\n if (selector === 'selection to text start')\n return document.getText(new Range(line_text_start, start) )\n}\n\n\nexport function activate (ctx: ExtensionContext) {\n my_commands.forEach( ({ func }) => {\n ctx.subscriptions.push(commands.registerCommand(func.name, func))\n })\n console.log('xshell loaded')\n}\n"]}
|