@arcblock/terminal 2.1.61
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/LICENSE +13 -0
- package/README.md +19 -0
- package/lib/Player.js +464 -0
- package/lib/index.js +15 -0
- package/lib/player.css +378 -0
- package/lib/terminal.js +180 -0
- package/lib/util.js +193 -0
- package/lib/xterm.css +171 -0
- package/package.json +68 -0
- package/src/Player.js +363 -0
- package/src/index.js +2 -0
- package/src/player.css +378 -0
- package/src/terminal.js +151 -0
- package/src/util.js +167 -0
- package/src/xterm.css +171 -0
package/lib/util.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isFrameAt = exports.getPlayerClass = exports.getFrameClass = exports.formatTime = exports.formatFrames = exports.findFrameAt = exports.defaultState = exports.defaultOptions = void 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Adjust the delays of the frames, considering to the options
|
|
10
|
+
*
|
|
11
|
+
* - frameDelay
|
|
12
|
+
* - Delay between frames in ms
|
|
13
|
+
* - If the value is `auto` use the actual recording delays
|
|
14
|
+
*
|
|
15
|
+
* - maxIdleTime
|
|
16
|
+
* - Maximum delay between frames in ms
|
|
17
|
+
* - Ignored if the `frameDelay` isn't set to `auto`
|
|
18
|
+
* - Set to `auto` to prevnt limiting the max idle time
|
|
19
|
+
*
|
|
20
|
+
* - speedFactor
|
|
21
|
+
* - Multiply the frames delays by this factor
|
|
22
|
+
*/
|
|
23
|
+
const formatFrames = (frames, options) => {
|
|
24
|
+
frames.forEach(x => {
|
|
25
|
+
let {
|
|
26
|
+
delay
|
|
27
|
+
} = x; // Adjust the delay according to the options
|
|
28
|
+
|
|
29
|
+
if (options.frameDelay !== 'auto') {
|
|
30
|
+
delay = options.frameDelay;
|
|
31
|
+
} else if (options.maxIdleTime !== 'auto' && delay > options.maxIdleTime) {
|
|
32
|
+
delay = options.maxIdleTime;
|
|
33
|
+
} // Apply speedFactor
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
delay *= options.speedFactor; // Set the adjusted delay
|
|
37
|
+
|
|
38
|
+
x.delay = delay;
|
|
39
|
+
}); // Calculate and set the duration, startTime, and endTime for each frame
|
|
40
|
+
|
|
41
|
+
let currentTime = 0;
|
|
42
|
+
const framesCount = frames.length;
|
|
43
|
+
frames.forEach((x, index) => {
|
|
44
|
+
// Set the duration (the delay of the next frame)
|
|
45
|
+
// The % is used to take the delay of the first frame
|
|
46
|
+
// as the duration of the last frame
|
|
47
|
+
const duration = frames[(index + 1) % framesCount].delay; // Set timing values for the current frame
|
|
48
|
+
|
|
49
|
+
x.duration = duration;
|
|
50
|
+
x.startTime = currentTime;
|
|
51
|
+
x.endTime = currentTime + duration;
|
|
52
|
+
currentTime += duration;
|
|
53
|
+
}); // Total duration
|
|
54
|
+
|
|
55
|
+
const totalDuration = frames.reduce((sum, x) => sum + x.delay, 0);
|
|
56
|
+
return {
|
|
57
|
+
frames,
|
|
58
|
+
totalDuration
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Get the frame's index at a specific time
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
exports.formatFrames = formatFrames;
|
|
67
|
+
|
|
68
|
+
const findFrameAt = (frames, time, fromIndex) => {
|
|
69
|
+
let frame = null;
|
|
70
|
+
|
|
71
|
+
if (typeof fromIndex === 'undefined') {
|
|
72
|
+
// eslint-disable-next-line no-param-reassign
|
|
73
|
+
fromIndex = 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for (let i = fromIndex; i < frames.length; i++) {
|
|
77
|
+
frame = frames[i];
|
|
78
|
+
|
|
79
|
+
if (frame.startTime <= time && time < frame.endTime) {
|
|
80
|
+
return i;
|
|
81
|
+
}
|
|
82
|
+
} // The endTime of the final frame belongs to it
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if (frame.startTime <= time && time <= frame.endTime) {
|
|
86
|
+
return frames.length - 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return -1;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Check if the time belongs to the frame's duration
|
|
93
|
+
*
|
|
94
|
+
* @param {Number} time
|
|
95
|
+
* @param {Number} frameIndex
|
|
96
|
+
* @return {Number}
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
exports.findFrameAt = findFrameAt;
|
|
101
|
+
|
|
102
|
+
const isFrameAt = (frames, time, frameIndex) => {
|
|
103
|
+
const frame = frames[frameIndex];
|
|
104
|
+
|
|
105
|
+
if (typeof frame === 'undefined') {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (frame.startTime <= time && time < frame.endTime) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return false;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
exports.isFrameAt = isFrameAt;
|
|
117
|
+
|
|
118
|
+
const formatTime = time => {
|
|
119
|
+
let minutes = Math.floor(time / 60000);
|
|
120
|
+
let seconds = parseInt((time - minutes * 60000) / 1000, 10);
|
|
121
|
+
|
|
122
|
+
if (minutes < 10) {
|
|
123
|
+
minutes = "0".concat(minutes);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (seconds < 10) {
|
|
127
|
+
seconds = "0".concat(seconds);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return "".concat(minutes, ":").concat(seconds);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
exports.formatTime = formatTime;
|
|
134
|
+
|
|
135
|
+
const getPlayerClass = (options, state) => {
|
|
136
|
+
const playerClass = ['terminal-player'];
|
|
137
|
+
|
|
138
|
+
if (options.controls) {
|
|
139
|
+
playerClass.push('controls');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (options.frameBox.type) {
|
|
143
|
+
playerClass.push('framed');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (options.rows < 10) {
|
|
147
|
+
playerClass.push('small');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (state.isStarted) {
|
|
151
|
+
playerClass.push('started');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (state.isPlaying) {
|
|
155
|
+
playerClass.push('playing');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return playerClass.filter(Boolean).join(' ');
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
exports.getPlayerClass = getPlayerClass;
|
|
162
|
+
|
|
163
|
+
const getFrameClass = options => {
|
|
164
|
+
const frameClass = ['terminal-frame'];
|
|
165
|
+
|
|
166
|
+
if (options.frameBox.type) {
|
|
167
|
+
frameClass.push("terminal-".concat(options.frameBox.type));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return frameClass.join(' ');
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
exports.getFrameClass = getFrameClass;
|
|
174
|
+
const defaultState = {
|
|
175
|
+
isPlaying: false,
|
|
176
|
+
isStarted: false,
|
|
177
|
+
isRendering: false,
|
|
178
|
+
requireReset: false,
|
|
179
|
+
currentFrame: -1,
|
|
180
|
+
currentTime: 0,
|
|
181
|
+
lastTickTime: null
|
|
182
|
+
};
|
|
183
|
+
exports.defaultState = defaultState;
|
|
184
|
+
const defaultOptions = {
|
|
185
|
+
realTiming: false,
|
|
186
|
+
speedFactor: 1.0,
|
|
187
|
+
controls: true,
|
|
188
|
+
repeat: false,
|
|
189
|
+
autoplay: false,
|
|
190
|
+
thumbnailTime: 999999,
|
|
191
|
+
frameBox: {}
|
|
192
|
+
};
|
|
193
|
+
exports.defaultOptions = defaultOptions;
|
package/lib/xterm.css
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2014 The xterm.js authors. All rights reserved.
|
|
3
|
+
* Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
|
|
4
|
+
* https://github.com/chjj/term.js
|
|
5
|
+
* @license MIT
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
|
15
|
+
* all copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
* THE SOFTWARE.
|
|
24
|
+
*
|
|
25
|
+
* Originally forked from (with the author's permission):
|
|
26
|
+
* Fabrice Bellard's javascript vt100 for jslinux:
|
|
27
|
+
* http://bellard.org/jslinux/
|
|
28
|
+
* Copyright (c) 2011 Fabrice Bellard
|
|
29
|
+
* The original design remains. The terminal itself
|
|
30
|
+
* has been extended to include xterm CSI codes, among
|
|
31
|
+
* other features.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Default styles for xterm.js
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
.xterm {
|
|
39
|
+
font-feature-settings: 'liga' 0;
|
|
40
|
+
position: relative;
|
|
41
|
+
user-select: none;
|
|
42
|
+
-ms-user-select: none;
|
|
43
|
+
-webkit-user-select: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.xterm.focus,
|
|
47
|
+
.xterm:focus {
|
|
48
|
+
outline: none;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.xterm .xterm-helpers {
|
|
52
|
+
position: absolute;
|
|
53
|
+
top: 0;
|
|
54
|
+
/**
|
|
55
|
+
* The z-index of the helpers must be higher than the canvases in order for
|
|
56
|
+
* IMEs to appear on top.
|
|
57
|
+
*/
|
|
58
|
+
z-index: 5;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.xterm .xterm-helper-textarea {
|
|
62
|
+
/*
|
|
63
|
+
* HACK: to fix IE's blinking cursor
|
|
64
|
+
* Move textarea out of the screen to the far left, so that the cursor is not visible.
|
|
65
|
+
*/
|
|
66
|
+
position: absolute;
|
|
67
|
+
opacity: 0;
|
|
68
|
+
left: -9999em;
|
|
69
|
+
top: 0;
|
|
70
|
+
width: 0;
|
|
71
|
+
height: 0;
|
|
72
|
+
z-index: -5;
|
|
73
|
+
/** Prevent wrapping so the IME appears against the textarea at the correct position */
|
|
74
|
+
white-space: nowrap;
|
|
75
|
+
overflow: hidden;
|
|
76
|
+
resize: none;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.xterm .composition-view {
|
|
80
|
+
/* TODO: Composition position got messed up somewhere */
|
|
81
|
+
background: #000;
|
|
82
|
+
color: #fff;
|
|
83
|
+
display: none;
|
|
84
|
+
position: absolute;
|
|
85
|
+
white-space: nowrap;
|
|
86
|
+
z-index: 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.xterm .composition-view.active {
|
|
90
|
+
display: block;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.xterm .xterm-viewport {
|
|
94
|
+
/* On OS X this is required in order for the scroll bar to appear fully opaque */
|
|
95
|
+
background-color: #000;
|
|
96
|
+
overflow-y: scroll;
|
|
97
|
+
cursor: default;
|
|
98
|
+
position: absolute;
|
|
99
|
+
right: 0;
|
|
100
|
+
left: 0;
|
|
101
|
+
top: 0;
|
|
102
|
+
bottom: 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.xterm .xterm-screen {
|
|
106
|
+
position: relative;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.xterm .xterm-screen canvas {
|
|
110
|
+
position: absolute;
|
|
111
|
+
left: 0;
|
|
112
|
+
top: 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.xterm .xterm-scroll-area {
|
|
116
|
+
visibility: hidden;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.xterm-char-measure-element {
|
|
120
|
+
display: inline-block;
|
|
121
|
+
visibility: hidden;
|
|
122
|
+
position: absolute;
|
|
123
|
+
top: 0;
|
|
124
|
+
left: -9999em;
|
|
125
|
+
line-height: normal;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.xterm {
|
|
129
|
+
cursor: text;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.xterm.enable-mouse-events {
|
|
133
|
+
/* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */
|
|
134
|
+
cursor: default;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.xterm.xterm-cursor-pointer {
|
|
138
|
+
cursor: pointer;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.xterm.column-select.focus {
|
|
142
|
+
/* Column selection mode */
|
|
143
|
+
cursor: crosshair;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.xterm .xterm-accessibility,
|
|
147
|
+
.xterm .xterm-message {
|
|
148
|
+
position: absolute;
|
|
149
|
+
left: 0;
|
|
150
|
+
top: 0;
|
|
151
|
+
bottom: 0;
|
|
152
|
+
right: 0;
|
|
153
|
+
z-index: 10;
|
|
154
|
+
color: transparent;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.xterm .live-region {
|
|
158
|
+
position: absolute;
|
|
159
|
+
left: -9999px;
|
|
160
|
+
width: 1px;
|
|
161
|
+
height: 1px;
|
|
162
|
+
overflow: hidden;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.xterm-dim {
|
|
166
|
+
opacity: 0.5;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.xterm-underline {
|
|
170
|
+
text-decoration: underline;
|
|
171
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arcblock/terminal",
|
|
3
|
+
"version": "2.1.61",
|
|
4
|
+
"description": "A react wrapper for xterm allowing you to easily render a terminal in the browser",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"arcblock",
|
|
8
|
+
"component",
|
|
9
|
+
"terminal",
|
|
10
|
+
"xterm"
|
|
11
|
+
],
|
|
12
|
+
"author": "wangshijun<wangshijun2010@gmail.com>",
|
|
13
|
+
"homepage": "https://github.com/ArcBlock/ux#readme",
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"main": "lib/index.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"lib",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/ArcBlock/ux.git"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"lint": "eslint src stories tests",
|
|
26
|
+
"build": "babel src --out-dir lib --copy-files",
|
|
27
|
+
"watch": "babel src --out-dir lib -w --copy-files",
|
|
28
|
+
"precommit": "CI=1 yarn test",
|
|
29
|
+
"prepush": "CI=1 yarn test",
|
|
30
|
+
"prepublish": "npm run build",
|
|
31
|
+
"test": "npm run lint && node tools/jest.js",
|
|
32
|
+
"coverage": "npm run lint && yarn test -- --coverage"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/ArcBlock/ux/issues"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@babel/cli": "^7.8.4",
|
|
42
|
+
"@babel/core": "^7.8.4",
|
|
43
|
+
"@babel/plugin-proposal-class-properties": "^7.8.3",
|
|
44
|
+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
45
|
+
"@babel/preset-env": "^7.8.4",
|
|
46
|
+
"@babel/preset-react": "^7.8.3",
|
|
47
|
+
"babel-plugin-styled-components": "^1.10.7",
|
|
48
|
+
"eslint-plugin-react-hooks": "^4.2.0",
|
|
49
|
+
"jest": "^24.1.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"react": ">=18.1.0"
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "4859674457581033b59d02723c976fffd3a9c3b3",
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@arcblock/react-hooks": "^2.1.61",
|
|
57
|
+
"@arcblock/ux": "^2.1.61",
|
|
58
|
+
"@emotion/react": "^11.9.0",
|
|
59
|
+
"@emotion/styled": "^11.8.1",
|
|
60
|
+
"core-js": "^3.6.4",
|
|
61
|
+
"lodash": "^4.17.21",
|
|
62
|
+
"react-use": "^17.2.4",
|
|
63
|
+
"styled-components": "^5.0.0",
|
|
64
|
+
"xterm": "4.1.0",
|
|
65
|
+
"xterm-addon-fit": "^0.2.1",
|
|
66
|
+
"xterm-addon-web-links": "^0.2.1"
|
|
67
|
+
}
|
|
68
|
+
}
|