react-terminal-viewer-cicd 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -0
- package/dist/esm/Addon/EventEmiter.d.ts +18 -0
- package/dist/esm/Addon/EventEmiter.js +64 -0
- package/dist/esm/Addon/HighlightAddon.d.ts +26 -0
- package/dist/esm/Addon/HighlightAddon.js +188 -0
- package/dist/esm/Addon/SearchAddon.d.ts +140 -0
- package/dist/esm/Addon/SearchAddon.js +797 -0
- package/dist/esm/Addon/WorkerLog/GlobalContext.d.ts +10 -0
- package/dist/esm/Addon/WorkerLog/GlobalContext.js +37 -0
- package/dist/esm/Addon/WorkerLog/LimitMap.d.ts +14 -0
- package/dist/esm/Addon/WorkerLog/LimitMap.js +54 -0
- package/dist/esm/Addon/WorkerLog/LogWorker.d.ts +2 -0
- package/dist/esm/Addon/WorkerLog/LogWorker.js +13 -0
- package/dist/esm/Addon/WorkerLog/Logs.d.ts +21 -0
- package/dist/esm/Addon/WorkerLog/Logs.js +60 -0
- package/dist/esm/Addon/WorkerLog/Mark.d.ts +36 -0
- package/dist/esm/Addon/WorkerLog/Mark.js +155 -0
- package/dist/esm/Addon/WorkerLog/Searcher.d.ts +16 -0
- package/dist/esm/Addon/WorkerLog/Searcher.js +88 -0
- package/dist/esm/Addon/WorkerLog/WebWokerServer.d.ts +10 -0
- package/dist/esm/Addon/WorkerLog/WebWokerServer.js +57 -0
- package/dist/esm/Addon/WorkerLog/WebWorkerClient.d.ts +13 -0
- package/dist/esm/Addon/WorkerLog/WebWorkerClient.js +83 -0
- package/dist/esm/Addon/WorkerLog/log.worker.d.ts +1 -0
- package/dist/esm/Addon/WorkerLog/log.worker.js +63 -0
- package/dist/esm/Addon/WorkerLog/types.d.ts +18 -0
- package/dist/esm/Addon/WorkerLog/types.js +1 -0
- package/dist/esm/Addon/useAddon.d.ts +9 -0
- package/dist/esm/Addon/useAddon.js +33 -0
- package/dist/esm/Hooks/useBatchProcess.d.ts +2 -0
- package/dist/esm/Hooks/useBatchProcess.js +47 -0
- package/dist/esm/Hooks/useCache.d.ts +31 -0
- package/dist/esm/Hooks/useCache.js +206 -0
- package/dist/esm/Hooks/useDebounceInput.d.ts +3 -0
- package/dist/esm/Hooks/useDebounceInput.js +26 -0
- package/dist/esm/Hooks/useLocalStore.d.ts +2 -0
- package/dist/esm/Hooks/useLocalStore.js +9 -0
- package/dist/esm/Hooks/useRemote.d.ts +30 -0
- package/dist/esm/Hooks/useRemote.js +398 -0
- package/dist/esm/Hooks/useThrottle.d.ts +2 -0
- package/dist/esm/Hooks/useThrottle.js +13 -0
- package/dist/esm/Hooks/useWorkerLogs.d.ts +9 -0
- package/dist/esm/Hooks/useWorkerLogs.js +162 -0
- package/dist/esm/TerminalViewer/index.d.ts +185 -0
- package/dist/esm/TerminalViewer/index.js +292 -0
- package/dist/esm/TerminalViewer/index.less +17 -0
- package/dist/esm/TerminalViewerBody/index.d.ts +87 -0
- package/dist/esm/TerminalViewerBody/index.js +248 -0
- package/dist/esm/TerminalViewerBody/index.less +51 -0
- package/dist/esm/TerminalViewerHeader/index.d.ts +88 -0
- package/dist/esm/TerminalViewerHeader/index.js +129 -0
- package/dist/esm/TerminalViewerHeader/index.less +143 -0
- package/dist/esm/TerminalViewerToolBar/index.d.ts +46 -0
- package/dist/esm/TerminalViewerToolBar/index.js +28 -0
- package/dist/esm/TerminalViewerToolBar/index.less +32 -0
- package/dist/esm/TerminalViewerVirtualDom/index.d.ts +71 -0
- package/dist/esm/TerminalViewerVirtualDom/index.js +309 -0
- package/dist/esm/TerminalViewerVirtualDom/index.less +68 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/mock/index.d.ts +12 -0
- package/dist/esm/mock/index.js +98 -0
- package/dist/esm/types.d.ts +30 -0
- package/dist/esm/types.js +1 -0
- package/dist/worker/Addon/EventEmiter.d.ts +18 -0
- package/dist/worker/Addon/HighlightAddon.d.ts +26 -0
- package/dist/worker/Addon/SearchAddon.d.ts +140 -0
- package/dist/worker/Addon/WorkerLog/GlobalContext.d.ts +10 -0
- package/dist/worker/Addon/WorkerLog/LimitMap.d.ts +14 -0
- package/dist/worker/Addon/WorkerLog/LogWorker.d.ts +2 -0
- package/dist/worker/Addon/WorkerLog/Logs.d.ts +21 -0
- package/dist/worker/Addon/WorkerLog/Mark.d.ts +36 -0
- package/dist/worker/Addon/WorkerLog/Searcher.d.ts +16 -0
- package/dist/worker/Addon/WorkerLog/WebWokerServer.d.ts +10 -0
- package/dist/worker/Addon/WorkerLog/WebWorkerClient.d.ts +13 -0
- package/dist/worker/Addon/WorkerLog/log.worker.d.ts +1 -0
- package/dist/worker/Addon/WorkerLog/types.d.ts +18 -0
- package/dist/worker/Addon/useAddon.d.ts +9 -0
- package/dist/worker/Hooks/useBatchProcess.d.ts +2 -0
- package/dist/worker/Hooks/useCache.d.ts +31 -0
- package/dist/worker/Hooks/useDebounceInput.d.ts +3 -0
- package/dist/worker/Hooks/useLocalStore.d.ts +2 -0
- package/dist/worker/Hooks/useRemote.d.ts +30 -0
- package/dist/worker/Hooks/useRemote.test.d.ts +1 -0
- package/dist/worker/Hooks/useThrottle.d.ts +2 -0
- package/dist/worker/Hooks/useWorkerLogs.d.ts +9 -0
- package/dist/worker/TerminalViewer/index.d.ts +185 -0
- package/dist/worker/TerminalViewer/index.test.d.ts +1 -0
- package/dist/worker/TerminalViewerBody/index.d.ts +87 -0
- package/dist/worker/TerminalViewerBody/index.test.d.ts +1 -0
- package/dist/worker/TerminalViewerHeader/index.d.ts +88 -0
- package/dist/worker/TerminalViewerToolBar/index.d.ts +46 -0
- package/dist/worker/TerminalViewerVirtualDom/index.d.ts +71 -0
- package/dist/worker/index.d.ts +9 -0
- package/dist/worker/log.worker.js +2 -0
- package/dist/worker/log.worker.js.map +1 -0
- package/dist/worker/mock/index.d.ts +12 -0
- package/dist/worker/types.d.ts +30 -0
- package/package.json +97 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
var GlobalContext = /*#__PURE__*/function () {
|
|
9
|
+
function GlobalContext() {
|
|
10
|
+
_classCallCheck(this, GlobalContext);
|
|
11
|
+
_defineProperty(this, "worker", void 0);
|
|
12
|
+
_defineProperty(this, "workerPath", 'worker');
|
|
13
|
+
}
|
|
14
|
+
_createClass(GlobalContext, [{
|
|
15
|
+
key: "setWorkerPath",
|
|
16
|
+
value: function setWorkerPath(path) {
|
|
17
|
+
this.workerPath = path;
|
|
18
|
+
}
|
|
19
|
+
}, {
|
|
20
|
+
key: "getWorkerPath",
|
|
21
|
+
value: function getWorkerPath() {
|
|
22
|
+
return this.workerPath;
|
|
23
|
+
}
|
|
24
|
+
}, {
|
|
25
|
+
key: "setWorker",
|
|
26
|
+
value: function setWorker(worker) {
|
|
27
|
+
this.worker = worker;
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
key: "getWorker",
|
|
31
|
+
value: function getWorker() {
|
|
32
|
+
return this.worker;
|
|
33
|
+
}
|
|
34
|
+
}]);
|
|
35
|
+
return GlobalContext;
|
|
36
|
+
}();
|
|
37
|
+
export default new GlobalContext();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare class LimitMap {
|
|
2
|
+
private map;
|
|
3
|
+
private queue;
|
|
4
|
+
private limit;
|
|
5
|
+
constructor(options?: {
|
|
6
|
+
limit: number;
|
|
7
|
+
});
|
|
8
|
+
get(key: string | number): any;
|
|
9
|
+
get size(): number;
|
|
10
|
+
set(key: string, value: any): Map<string | number, any>;
|
|
11
|
+
has(key: string | number): boolean;
|
|
12
|
+
delete(key: string | number): boolean;
|
|
13
|
+
}
|
|
14
|
+
export default LimitMap;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
9
|
+
var LimitMap = /*#__PURE__*/function () {
|
|
10
|
+
function LimitMap(options) {
|
|
11
|
+
_classCallCheck(this, LimitMap);
|
|
12
|
+
_defineProperty(this, "map", void 0);
|
|
13
|
+
_defineProperty(this, "queue", void 0);
|
|
14
|
+
_defineProperty(this, "limit", void 0);
|
|
15
|
+
this.map = new Map();
|
|
16
|
+
this.queue = [];
|
|
17
|
+
this.limit = (options === null || options === void 0 ? void 0 : options.limit) || 50;
|
|
18
|
+
}
|
|
19
|
+
_createClass(LimitMap, [{
|
|
20
|
+
key: "get",
|
|
21
|
+
value: function get(key) {
|
|
22
|
+
return this.map.get(key);
|
|
23
|
+
}
|
|
24
|
+
}, {
|
|
25
|
+
key: "size",
|
|
26
|
+
get: function get() {
|
|
27
|
+
return this.map.size;
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
key: "set",
|
|
31
|
+
value: function set(key, value) {
|
|
32
|
+
if (this.size >= this.limit) {
|
|
33
|
+
var q = this.queue.shift();
|
|
34
|
+
if (q) {
|
|
35
|
+
this.delete(q);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
this.queue.push(key);
|
|
39
|
+
return this.map.set(key, value);
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
key: "has",
|
|
43
|
+
value: function has(key) {
|
|
44
|
+
return this.map.has(key);
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
key: "delete",
|
|
48
|
+
value: function _delete(key) {
|
|
49
|
+
return this.map.delete(key);
|
|
50
|
+
}
|
|
51
|
+
}]);
|
|
52
|
+
return LimitMap;
|
|
53
|
+
}();
|
|
54
|
+
export default LimitMap;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function LogWorker() {
|
|
2
|
+
var workerPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '/worker';
|
|
3
|
+
var worker = null;
|
|
4
|
+
var version = "2.0.4" || '0.0.0';
|
|
5
|
+
var path = workerPath.includes('http') ? "".concat(workerPath, "/log.worker.js") : "".concat(window.location.origin).concat(workerPath, "/log.worker.js");
|
|
6
|
+
var blob = new Blob(["importScripts(\"".concat(path, "?v=").concat(version, "\")")], {
|
|
7
|
+
type: 'application/javascript'
|
|
8
|
+
});
|
|
9
|
+
var blobUrl = window.URL.createObjectURL(blob);
|
|
10
|
+
worker = new Worker(blobUrl);
|
|
11
|
+
return worker;
|
|
12
|
+
}
|
|
13
|
+
export default LogWorker;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ISearchOptions } from '../SearchAddon';
|
|
2
|
+
export default class Logs {
|
|
3
|
+
private id;
|
|
4
|
+
private string;
|
|
5
|
+
private searcher;
|
|
6
|
+
private logDataMap;
|
|
7
|
+
constructor({ id, string }: {
|
|
8
|
+
id: string;
|
|
9
|
+
string: string;
|
|
10
|
+
});
|
|
11
|
+
convert(): string[];
|
|
12
|
+
getArrayData(): any;
|
|
13
|
+
mark(keyword: string, hlIndex?: number, options?: ISearchOptions | undefined): {
|
|
14
|
+
count: number;
|
|
15
|
+
map: {
|
|
16
|
+
[key: string]: string;
|
|
17
|
+
[key: number]: string;
|
|
18
|
+
};
|
|
19
|
+
markedKey: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
/* eslint-disable no-plusplus */
|
|
9
|
+
// eslint-disable-next-line import/no-named-default
|
|
10
|
+
import { default as AnsiUp } from 'ansi_up';
|
|
11
|
+
import LimitMap from "./LimitMap";
|
|
12
|
+
import Searcher from "./Searcher";
|
|
13
|
+
var Logs = /*#__PURE__*/function () {
|
|
14
|
+
function Logs(_ref) {
|
|
15
|
+
var id = _ref.id,
|
|
16
|
+
string = _ref.string;
|
|
17
|
+
_classCallCheck(this, Logs);
|
|
18
|
+
_defineProperty(this, "id", void 0);
|
|
19
|
+
_defineProperty(this, "string", void 0);
|
|
20
|
+
_defineProperty(this, "searcher", void 0);
|
|
21
|
+
_defineProperty(this, "logDataMap", void 0);
|
|
22
|
+
this.id = id;
|
|
23
|
+
this.string = string;
|
|
24
|
+
this.searcher = new Searcher();
|
|
25
|
+
this.logDataMap = new LimitMap({
|
|
26
|
+
limit: 1
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
_createClass(Logs, [{
|
|
30
|
+
key: "convert",
|
|
31
|
+
value: function convert() {
|
|
32
|
+
if (this.string.length === 0) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
return this.string.split('\r\n').map(function (content) {
|
|
36
|
+
return new AnsiUp().ansi_to_html(content);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
key: "getArrayData",
|
|
41
|
+
value: function getArrayData() {
|
|
42
|
+
if (!this.logDataMap.has(this.id)) {
|
|
43
|
+
this.logDataMap.set(this.id, this.convert());
|
|
44
|
+
}
|
|
45
|
+
return this.logDataMap.get(this.id) || [];
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
key: "mark",
|
|
49
|
+
value: function mark(keyword) {
|
|
50
|
+
var hlIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
51
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
52
|
+
if (!keyword) {
|
|
53
|
+
return this.searcher.search(keyword, []);
|
|
54
|
+
}
|
|
55
|
+
return this.searcher.search(keyword, this.getArrayData(), hlIndex, options);
|
|
56
|
+
}
|
|
57
|
+
}]);
|
|
58
|
+
return Logs;
|
|
59
|
+
}();
|
|
60
|
+
export { Logs as default };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
declare class Mark {
|
|
2
|
+
private dom;
|
|
3
|
+
private options;
|
|
4
|
+
matchCount: number;
|
|
5
|
+
matchedIndex: number;
|
|
6
|
+
isMarked: boolean;
|
|
7
|
+
private hlIndex;
|
|
8
|
+
constructor(content: string, options?: {
|
|
9
|
+
className?: string;
|
|
10
|
+
markedClassName?: string;
|
|
11
|
+
style?: {
|
|
12
|
+
[key: string]: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
markedStyle?: {
|
|
15
|
+
[key: string]: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* 根据关键字标记文本
|
|
20
|
+
* @param {String} keyword - 搜索关键词
|
|
21
|
+
* @param {Number} options.matchedIndex - 已匹配的最大的索引
|
|
22
|
+
* @param {Number} options.hlIndex - 需要标记的索引
|
|
23
|
+
* @returns this
|
|
24
|
+
*/
|
|
25
|
+
mark(keyword: string, options?: {
|
|
26
|
+
matchedIndex: number;
|
|
27
|
+
hlIndex: number;
|
|
28
|
+
}): this;
|
|
29
|
+
escapeStr(str: string): string;
|
|
30
|
+
getStyle(isMarked: boolean): string;
|
|
31
|
+
getTextNodes(el: ChildNode): ChildNode[];
|
|
32
|
+
wrapRangeInTextNode(node: Text, start: number, end: number): Text;
|
|
33
|
+
toString(): string;
|
|
34
|
+
distory(): void;
|
|
35
|
+
}
|
|
36
|
+
export default Mark;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
/* eslint-disable no-plusplus */
|
|
9
|
+
import { DOMParser } from 'xmldom';
|
|
10
|
+
var DOCTYPE = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
11
|
+
var NODE_TYPE_TEXT = 3;
|
|
12
|
+
var Mark = /*#__PURE__*/function () {
|
|
13
|
+
function Mark(content) {
|
|
14
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
15
|
+
className: 'terminal-viewer-hl-mark',
|
|
16
|
+
markedClassName: 'terminal-viewer-hl-mark terminal-viewer-hl-marked'
|
|
17
|
+
};
|
|
18
|
+
_classCallCheck(this, Mark);
|
|
19
|
+
_defineProperty(this, "dom", void 0);
|
|
20
|
+
_defineProperty(this, "options", void 0);
|
|
21
|
+
_defineProperty(this, "matchCount", void 0);
|
|
22
|
+
_defineProperty(this, "matchedIndex", void 0);
|
|
23
|
+
_defineProperty(this, "isMarked", false);
|
|
24
|
+
_defineProperty(this, "hlIndex", void 0);
|
|
25
|
+
this.dom = new DOMParser().parseFromString("".concat(DOCTYPE, "<html><body>").concat(content, "</body></html>"), 'text/html');
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.matchCount = 0;
|
|
28
|
+
this.matchedIndex = 0;
|
|
29
|
+
this.isMarked = false;
|
|
30
|
+
this.hlIndex = 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 根据关键字标记文本
|
|
35
|
+
* @param {String} keyword - 搜索关键词
|
|
36
|
+
* @param {Number} options.matchedIndex - 已匹配的最大的索引
|
|
37
|
+
* @param {Number} options.hlIndex - 需要标记的索引
|
|
38
|
+
* @returns this
|
|
39
|
+
*/
|
|
40
|
+
_createClass(Mark, [{
|
|
41
|
+
key: "mark",
|
|
42
|
+
value: function mark(keyword) {
|
|
43
|
+
var _this = this;
|
|
44
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
45
|
+
matchedIndex: 0,
|
|
46
|
+
hlIndex: 0
|
|
47
|
+
};
|
|
48
|
+
var reg = new RegExp(this.escapeStr(keyword), 'gi');
|
|
49
|
+
var nodes = Array.from(this.dom.getElementsByTagName('body')[0].childNodes);
|
|
50
|
+
var len = keyword.length;
|
|
51
|
+
this.matchedIndex = options.matchedIndex;
|
|
52
|
+
this.hlIndex = options.hlIndex;
|
|
53
|
+
nodes.forEach(function (node) {
|
|
54
|
+
var allNodes = _this.getTextNodes(node);
|
|
55
|
+
allNodes.forEach(function (anode) {
|
|
56
|
+
var textNode = anode;
|
|
57
|
+
var text = textNode.textContent || '';
|
|
58
|
+
while (text) {
|
|
59
|
+
var start = text.search(reg);
|
|
60
|
+
if (start !== -1) {
|
|
61
|
+
var _textNode;
|
|
62
|
+
textNode = _this.wrapRangeInTextNode(textNode, start, start + len);
|
|
63
|
+
text = ((_textNode = textNode) === null || _textNode === void 0 ? void 0 : _textNode.textContent) || '';
|
|
64
|
+
_this.matchCount++;
|
|
65
|
+
_this.matchedIndex++;
|
|
66
|
+
} else {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
allNodes = [];
|
|
72
|
+
});
|
|
73
|
+
nodes = [];
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// eslint-disable-next-line class-methods-use-this
|
|
78
|
+
}, {
|
|
79
|
+
key: "escapeStr",
|
|
80
|
+
value: function escapeStr(str) {
|
|
81
|
+
// eslint-disable-next-line no-useless-escape
|
|
82
|
+
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "getStyle",
|
|
86
|
+
value: function getStyle(isMarked) {
|
|
87
|
+
var style = (isMarked ? this.options.markedStyle : this.options.style) || {};
|
|
88
|
+
return Object.keys(style).filter(function (key) {
|
|
89
|
+
return style[key];
|
|
90
|
+
}).map(function (key) {
|
|
91
|
+
return "".concat(key, ":").concat(style[key], ";");
|
|
92
|
+
}).join('');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// eslint-disable-next-line class-methods-use-this
|
|
96
|
+
}, {
|
|
97
|
+
key: "getTextNodes",
|
|
98
|
+
value: function getTextNodes(el) {
|
|
99
|
+
var nodes = [];
|
|
100
|
+
var queue = [el];
|
|
101
|
+
while (queue.length !== 0) {
|
|
102
|
+
var node = queue.shift();
|
|
103
|
+
if (node && node.nodeType === NODE_TYPE_TEXT) {
|
|
104
|
+
nodes.push(node);
|
|
105
|
+
}
|
|
106
|
+
if (node && node.hasChildNodes()) {
|
|
107
|
+
var childNodes = Array.from(node.childNodes);
|
|
108
|
+
childNodes.forEach(function (cnode) {
|
|
109
|
+
if (cnode.nodeType === NODE_TYPE_TEXT) {
|
|
110
|
+
nodes.push(cnode);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
queue.push.apply(queue, childNodes);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return nodes;
|
|
117
|
+
}
|
|
118
|
+
}, {
|
|
119
|
+
key: "wrapRangeInTextNode",
|
|
120
|
+
value: function wrapRangeInTextNode(node, start, end) {
|
|
121
|
+
var _startNode$parentNode;
|
|
122
|
+
var _this$options = this.options,
|
|
123
|
+
className = _this$options.className,
|
|
124
|
+
markedClassName = _this$options.markedClassName;
|
|
125
|
+
var startNode = node.splitText(start);
|
|
126
|
+
var ret = startNode.splitText(end - start);
|
|
127
|
+
var repl = this.dom.createElement('mark');
|
|
128
|
+
var style = this.getStyle(this.matchedIndex === this.hlIndex);
|
|
129
|
+
if (this.matchedIndex === this.hlIndex) {
|
|
130
|
+
this.isMarked = true;
|
|
131
|
+
}
|
|
132
|
+
repl.setAttribute('class', (this.matchedIndex === this.hlIndex ? markedClassName : className) || '');
|
|
133
|
+
if (style) {
|
|
134
|
+
repl.setAttribute('style', style);
|
|
135
|
+
}
|
|
136
|
+
repl.textContent = startNode.textContent;
|
|
137
|
+
(_startNode$parentNode = startNode.parentNode) === null || _startNode$parentNode === void 0 || _startNode$parentNode.replaceChild(repl, startNode);
|
|
138
|
+
return ret;
|
|
139
|
+
}
|
|
140
|
+
}, {
|
|
141
|
+
key: "toString",
|
|
142
|
+
value: function toString() {
|
|
143
|
+
var innerHTML = this.dom.getElementsByTagName('body')[0].toString();
|
|
144
|
+
var match = innerHTML.match(/^<body xmlns="http:\/\/www\.w3\.org\/1999\/xhtml">(.[\s\S]*?)<\/body>$/);
|
|
145
|
+
return match && match[1] ? match[1] : '';
|
|
146
|
+
}
|
|
147
|
+
}, {
|
|
148
|
+
key: "distory",
|
|
149
|
+
value: function distory() {
|
|
150
|
+
this.dom = null;
|
|
151
|
+
}
|
|
152
|
+
}]);
|
|
153
|
+
return Mark;
|
|
154
|
+
}();
|
|
155
|
+
export default Mark;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ISearchOptions } from '../SearchAddon';
|
|
2
|
+
export default class Searcher {
|
|
3
|
+
private options;
|
|
4
|
+
constructor(options?: {
|
|
5
|
+
markClassName: string;
|
|
6
|
+
markedClassName: string;
|
|
7
|
+
});
|
|
8
|
+
search(keyword: string, logs: Array<string>, hlIndex?: number, options?: ISearchOptions | undefined): {
|
|
9
|
+
count: number;
|
|
10
|
+
map: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
[key: number]: string;
|
|
13
|
+
};
|
|
14
|
+
markedKey: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
/* eslint-disable no-plusplus */
|
|
9
|
+
|
|
10
|
+
import Mark from "./Mark";
|
|
11
|
+
var MAX_COUNT = 1000;
|
|
12
|
+
var Searcher = /*#__PURE__*/function () {
|
|
13
|
+
function Searcher() {
|
|
14
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
15
|
+
markClassName: 'terminal-viewer-hl-mark',
|
|
16
|
+
markedClassName: 'terminal-viewer-hl-mark terminal-viewer-hl-marked'
|
|
17
|
+
};
|
|
18
|
+
_classCallCheck(this, Searcher);
|
|
19
|
+
_defineProperty(this, "options", void 0);
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
22
|
+
_createClass(Searcher, [{
|
|
23
|
+
key: "search",
|
|
24
|
+
value: function search(keyword, logs) {
|
|
25
|
+
var _options$decorations, _options$decorations2, _options$decorations3, _options$decorations4, _options$decorations5;
|
|
26
|
+
var hlIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
27
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
|
|
28
|
+
if (!Array.isArray(logs) || logs.length === 0 || !keyword) {
|
|
29
|
+
return {
|
|
30
|
+
count: 0,
|
|
31
|
+
map: {},
|
|
32
|
+
markedKey: 0
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
var _this$options = this.options,
|
|
36
|
+
markClassName = _this$options.markClassName,
|
|
37
|
+
markedClassName = _this$options.markedClassName;
|
|
38
|
+
var style = {
|
|
39
|
+
color: options === null || options === void 0 || (_options$decorations = options.decorations) === null || _options$decorations === void 0 ? void 0 : _options$decorations.matchForegroundColor,
|
|
40
|
+
background: options === null || options === void 0 || (_options$decorations2 = options.decorations) === null || _options$decorations2 === void 0 ? void 0 : _options$decorations2.matchBackground,
|
|
41
|
+
border: options === null || options === void 0 || (_options$decorations3 = options.decorations) === null || _options$decorations3 === void 0 ? void 0 : _options$decorations3.matchBorder
|
|
42
|
+
};
|
|
43
|
+
var markedStyle = {
|
|
44
|
+
background: options === null || options === void 0 || (_options$decorations4 = options.decorations) === null || _options$decorations4 === void 0 ? void 0 : _options$decorations4.activeMatchBackground,
|
|
45
|
+
border: options === null || options === void 0 || (_options$decorations5 = options.decorations) === null || _options$decorations5 === void 0 ? void 0 : _options$decorations5.activeMatchBorder
|
|
46
|
+
};
|
|
47
|
+
var count = 0;
|
|
48
|
+
var markedId = 0;
|
|
49
|
+
var map = {};
|
|
50
|
+
for (var i = 0, len = logs.length; i < len; i++) {
|
|
51
|
+
if (count >= MAX_COUNT) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
var text = logs[i] || '';
|
|
55
|
+
if (!text.toLowerCase().includes(keyword.toLowerCase())) {
|
|
56
|
+
// eslint-disable-next-line no-continue
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
var mark = new Mark(text, {
|
|
60
|
+
className: markClassName,
|
|
61
|
+
markedClassName: markedClassName,
|
|
62
|
+
style: style,
|
|
63
|
+
markedStyle: markedStyle
|
|
64
|
+
});
|
|
65
|
+
var markedText = mark.mark(keyword, {
|
|
66
|
+
matchedIndex: count,
|
|
67
|
+
hlIndex: hlIndex
|
|
68
|
+
}).toString();
|
|
69
|
+
if (mark.isMarked) {
|
|
70
|
+
markedId = i;
|
|
71
|
+
}
|
|
72
|
+
if (mark.matchCount !== 0) {
|
|
73
|
+
count += mark.matchCount;
|
|
74
|
+
map[i] = markedText || text;
|
|
75
|
+
}
|
|
76
|
+
mark.distory();
|
|
77
|
+
mark = null;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
count: count,
|
|
81
|
+
map: map,
|
|
82
|
+
markedKey: markedId
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}]);
|
|
86
|
+
return Searcher;
|
|
87
|
+
}();
|
|
88
|
+
export { Searcher as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Callback = (context: WebWorkerServer, args: any) => void;
|
|
2
|
+
declare class WebWorkerServer {
|
|
3
|
+
private events;
|
|
4
|
+
private context;
|
|
5
|
+
constructor(context: Worker);
|
|
6
|
+
on(topic: string, callback: Callback): this;
|
|
7
|
+
exec(topic: string, data: any): this;
|
|
8
|
+
send(topic: string, payload?: {}): this;
|
|
9
|
+
}
|
|
10
|
+
export default WebWorkerServer;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
|
+
var WebWorkerServer = /*#__PURE__*/function () {
|
|
12
|
+
function WebWorkerServer(context) {
|
|
13
|
+
var _this = this;
|
|
14
|
+
_classCallCheck(this, WebWorkerServer);
|
|
15
|
+
_defineProperty(this, "events", void 0);
|
|
16
|
+
_defineProperty(this, "context", void 0);
|
|
17
|
+
this.events = {};
|
|
18
|
+
this.context = context;
|
|
19
|
+
this.context.addEventListener('message', function (e) {
|
|
20
|
+
var topic = e.data.topic;
|
|
21
|
+
_this.exec(topic, e.data);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
_createClass(WebWorkerServer, [{
|
|
25
|
+
key: "on",
|
|
26
|
+
value: function on(topic, callback) {
|
|
27
|
+
if (!this.events[topic]) {
|
|
28
|
+
this.events[topic] = [];
|
|
29
|
+
}
|
|
30
|
+
this.events[topic].push(callback);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
key: "exec",
|
|
35
|
+
value: function exec(topic, data) {
|
|
36
|
+
var _this2 = this;
|
|
37
|
+
if (!Array.isArray(this.events[topic])) {
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
this.events[topic].forEach(function (event) {
|
|
41
|
+
event(_this2, data);
|
|
42
|
+
});
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
}, {
|
|
46
|
+
key: "send",
|
|
47
|
+
value: function send(topic) {
|
|
48
|
+
var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
49
|
+
this.context.postMessage(_objectSpread({
|
|
50
|
+
topic: topic
|
|
51
|
+
}, payload));
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
}]);
|
|
55
|
+
return WebWorkerServer;
|
|
56
|
+
}();
|
|
57
|
+
export default WebWorkerServer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type Callback = (args: any) => void;
|
|
2
|
+
declare class WebWorkerClient {
|
|
3
|
+
private events;
|
|
4
|
+
private worker;
|
|
5
|
+
constructor(worker: Worker);
|
|
6
|
+
once(topic: string, callback: Callback): this;
|
|
7
|
+
on(topic: string, callback: Callback): this;
|
|
8
|
+
off(topic: string, callback: Callback): this;
|
|
9
|
+
exec(topic: string, data: any): this;
|
|
10
|
+
send(topic: string, payload?: {}): this;
|
|
11
|
+
terminate(): this;
|
|
12
|
+
}
|
|
13
|
+
export default WebWorkerClient;
|