@arcblock/terminal 2.5.57 → 2.5.59
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/lib/Player.js +33 -77
- package/lib/Terminal.js +3 -36
- package/lib/index.js +0 -3
- package/lib/util.js +16 -41
- package/package.json +4 -4
package/lib/Player.js
CHANGED
|
@@ -4,31 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = Player;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _useInterval = _interopRequireDefault(require("@arcblock/react-hooks/lib/useInterval"));
|
|
13
|
-
|
|
14
10
|
var _useWindowSize = _interopRequireDefault(require("react-use/lib/useWindowSize"));
|
|
15
|
-
|
|
16
11
|
var _Terminal = _interopRequireDefault(require("./Terminal"));
|
|
17
|
-
|
|
18
12
|
require("./player.css");
|
|
19
|
-
|
|
20
13
|
var _util = require("./util");
|
|
21
|
-
|
|
22
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
23
|
-
|
|
24
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
16
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
-
|
|
28
17
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
18
|
+
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; }
|
|
19
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
20
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable react/no-unused-prop-types */
|
|
32
21
|
function Player(props) {
|
|
33
22
|
const options = Object.assign({}, _util.defaultOptions, props.options);
|
|
34
23
|
const {
|
|
@@ -44,8 +33,8 @@ function Player(props) {
|
|
|
44
33
|
lineHeight: options.lineHeight,
|
|
45
34
|
letterSpacing: options.letterSpacing,
|
|
46
35
|
allowTransparency: true,
|
|
47
|
-
scrollback: 0
|
|
48
|
-
|
|
36
|
+
scrollback: 0
|
|
37
|
+
// theme: options.theme,
|
|
49
38
|
};
|
|
50
39
|
|
|
51
40
|
const stateReducer = (state, action) => {
|
|
@@ -55,49 +44,41 @@ function Player(props) {
|
|
|
55
44
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
56
45
|
isPlaying: false
|
|
57
46
|
}, action.payload);
|
|
58
|
-
|
|
59
47
|
case 'start':
|
|
60
48
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
61
49
|
isStarted: true,
|
|
62
50
|
lastTickTime: Date.now()
|
|
63
51
|
});
|
|
64
|
-
|
|
65
52
|
case 'play':
|
|
66
53
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
67
54
|
isPlaying: true,
|
|
68
55
|
lastTickTime: Date.now()
|
|
69
56
|
}, action.payload);
|
|
70
|
-
|
|
71
57
|
case 'pause':
|
|
72
58
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
73
59
|
isPlaying: false
|
|
74
60
|
}, action.payload);
|
|
75
|
-
|
|
76
61
|
case 'tickStart':
|
|
77
62
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
78
63
|
isRendering: true,
|
|
79
64
|
lastTickTime: Date.now()
|
|
80
65
|
}, action.payload);
|
|
81
|
-
|
|
82
66
|
case 'tickEnd':
|
|
83
67
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
84
68
|
isRendering: false,
|
|
85
69
|
lastTickTime: Date.now()
|
|
86
70
|
}, action.payload);
|
|
87
|
-
|
|
88
71
|
case 'reset':
|
|
89
72
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
90
73
|
currentFrame: 0,
|
|
91
74
|
currentTime: 0
|
|
92
75
|
}, action.payload);
|
|
93
|
-
|
|
94
76
|
default:
|
|
95
77
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
96
78
|
lastTickTime: Date.now()
|
|
97
79
|
}, action.payload);
|
|
98
80
|
}
|
|
99
81
|
};
|
|
100
|
-
|
|
101
82
|
const terminal = (0, _react.useRef)(null);
|
|
102
83
|
const progress = (0, _react.useRef)(null);
|
|
103
84
|
const container = (0, _react.useRef)(null);
|
|
@@ -110,50 +91,45 @@ function Player(props) {
|
|
|
110
91
|
if (!terminal.current) {
|
|
111
92
|
return;
|
|
112
93
|
}
|
|
113
|
-
|
|
114
94
|
try {
|
|
115
95
|
const COLUMN_WIDTH = 972 / 121;
|
|
116
96
|
const child = container.current.getBoundingClientRect();
|
|
117
97
|
let containerWidth = child.x < 0 ? child.width + child.x : child.width;
|
|
118
|
-
|
|
119
98
|
if (container.current.parentNode) {
|
|
120
99
|
const parent = container.current.parentNode.getBoundingClientRect();
|
|
121
|
-
|
|
122
100
|
if (child.width > parent.width) {
|
|
123
101
|
containerWidth = parent.width;
|
|
124
102
|
}
|
|
125
103
|
}
|
|
126
|
-
|
|
127
104
|
if (options.controls) {
|
|
128
105
|
containerWidth -= 12;
|
|
129
106
|
}
|
|
130
|
-
|
|
131
107
|
const colContainer = Math.ceil(containerWidth / COLUMN_WIDTH);
|
|
132
108
|
const cols = Math.min(Math.max(colContainer, 40), options.cols);
|
|
133
109
|
terminal.current.resize(cols, options.rows);
|
|
134
|
-
} catch (err) {
|
|
135
|
-
|
|
110
|
+
} catch (err) {
|
|
111
|
+
// Do nothing
|
|
112
|
+
}
|
|
113
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
114
|
+
}, [width, maxWidth]);
|
|
136
115
|
|
|
137
|
-
|
|
116
|
+
// console.log('main.render', state, { totalFrame: frames.length, totalDuration });
|
|
138
117
|
// Render a frame
|
|
139
|
-
|
|
140
118
|
const renderFrame = (frameIndex, done) => {
|
|
141
119
|
const frame = frames[frameIndex];
|
|
142
|
-
|
|
143
120
|
if (frame.content) {
|
|
144
121
|
if (state.requireReset) {
|
|
145
122
|
terminal.current.reset();
|
|
146
123
|
}
|
|
147
|
-
|
|
148
124
|
terminal.current.write(frame.content, () => {
|
|
149
125
|
if (typeof done === 'function') {
|
|
150
126
|
done();
|
|
151
127
|
}
|
|
152
128
|
});
|
|
153
129
|
}
|
|
154
|
-
};
|
|
155
|
-
|
|
130
|
+
};
|
|
156
131
|
|
|
132
|
+
// Emit a event
|
|
157
133
|
const emitEvent = name => {
|
|
158
134
|
if (typeof props[name] === 'function') {
|
|
159
135
|
props[name]({
|
|
@@ -162,67 +138,61 @@ function Player(props) {
|
|
|
162
138
|
options
|
|
163
139
|
});
|
|
164
140
|
}
|
|
165
|
-
};
|
|
166
|
-
|
|
141
|
+
};
|
|
167
142
|
|
|
143
|
+
// Render thumbnailTime
|
|
168
144
|
(0, _react.useEffect)(() => {
|
|
169
145
|
if (!terminal.current) {
|
|
170
146
|
return;
|
|
171
147
|
}
|
|
172
|
-
|
|
173
148
|
if (container.current) {
|
|
174
149
|
try {
|
|
175
150
|
setMaxWidth(container.current.getBoundingClientRect().width);
|
|
176
|
-
} catch (e) {
|
|
151
|
+
} catch (e) {
|
|
152
|
+
// Do nothing
|
|
177
153
|
}
|
|
178
154
|
}
|
|
179
|
-
|
|
180
155
|
if (options.autoplay) {
|
|
181
156
|
onStart();
|
|
182
157
|
} else {
|
|
183
158
|
doJump(Math.min(Math.abs(options.thumbnailTime), totalDuration));
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
}, []);
|
|
159
|
+
}
|
|
160
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
161
|
+
}, []);
|
|
187
162
|
|
|
163
|
+
// Tick intervals
|
|
188
164
|
(0, _useInterval.default)(() => {
|
|
189
165
|
if (state.isRendering) {
|
|
190
166
|
return false;
|
|
191
167
|
}
|
|
192
|
-
|
|
193
168
|
const tickDelay = Date.now() - state.lastTickTime;
|
|
194
169
|
const newState = {};
|
|
195
|
-
|
|
196
170
|
if (state.currentTime < totalDuration) {
|
|
197
171
|
newState.currentTime = state.currentTime + tickDelay;
|
|
198
172
|
}
|
|
199
|
-
|
|
200
173
|
if (state.currentTime > totalDuration) {
|
|
201
174
|
newState.currentTime = totalDuration;
|
|
202
175
|
}
|
|
203
|
-
|
|
204
176
|
const alreadyRendered = (0, _util.isFrameAt)(frames, newState.currentTime, state.currentFrame);
|
|
205
|
-
|
|
206
177
|
if (state.currentFrame !== -1 && alreadyRendered) {
|
|
207
178
|
return dispatch({
|
|
208
179
|
type: 'tick',
|
|
209
180
|
payload: newState
|
|
210
181
|
});
|
|
211
|
-
}
|
|
212
|
-
|
|
182
|
+
}
|
|
213
183
|
|
|
184
|
+
// Reached the end
|
|
214
185
|
if (state.currentFrame === frames.length - 1) {
|
|
215
186
|
emitEvent('onComplete');
|
|
216
|
-
|
|
217
187
|
if (options.repeat) {
|
|
218
188
|
// console.log('tick.restart', newState, state);
|
|
219
189
|
return dispatch({
|
|
220
190
|
type: 'reset',
|
|
221
191
|
payload: newState
|
|
222
192
|
});
|
|
223
|
-
}
|
|
224
|
-
|
|
193
|
+
}
|
|
225
194
|
|
|
195
|
+
// console.log('tick.end', newState, state);
|
|
226
196
|
newState.currentTime = 0;
|
|
227
197
|
newState.currentFrame = 0;
|
|
228
198
|
newState.requireReset = true;
|
|
@@ -231,16 +201,16 @@ function Player(props) {
|
|
|
231
201
|
type: 'pause',
|
|
232
202
|
payload: newState
|
|
233
203
|
});
|
|
234
|
-
}
|
|
235
|
-
|
|
204
|
+
}
|
|
236
205
|
|
|
206
|
+
// Check if current time belongs to the next frame's duration
|
|
237
207
|
if ((0, _util.isFrameAt)(newState.currentTime, state.currentFrame + 1)) {
|
|
238
208
|
newState.currentFrame = state.currentFrame + 1;
|
|
239
209
|
} else {
|
|
240
210
|
newState.currentFrame = (0, _util.findFrameAt)(frames, newState.currentTime);
|
|
241
|
-
}
|
|
242
|
-
|
|
211
|
+
}
|
|
243
212
|
|
|
213
|
+
// console.log('tick.tick', newState, state);
|
|
244
214
|
dispatch({
|
|
245
215
|
type: 'tickStart',
|
|
246
216
|
payload: newState
|
|
@@ -249,46 +219,41 @@ function Player(props) {
|
|
|
249
219
|
if (state.requireReset) {
|
|
250
220
|
newState.requireReset = false;
|
|
251
221
|
}
|
|
252
|
-
|
|
253
222
|
dispatch({
|
|
254
223
|
type: 'tickEnd',
|
|
255
224
|
payload: newState
|
|
256
225
|
});
|
|
257
226
|
return emitEvent('onTick');
|
|
258
227
|
});
|
|
259
|
-
}, state.isPlaying ? 8 : null);
|
|
228
|
+
}, state.isPlaying ? 8 : null);
|
|
260
229
|
|
|
230
|
+
// If controls are enabled, we need to disable frameBox
|
|
261
231
|
if (options.controls) {
|
|
262
232
|
options.frameBox.title = null;
|
|
263
233
|
options.frameBox.type = null;
|
|
264
234
|
options.frameBox.style = {};
|
|
265
|
-
|
|
266
235
|
if (options.theme.background === 'transparent') {
|
|
267
236
|
options.frameBox.style.background = 'black';
|
|
268
237
|
} else {
|
|
269
238
|
options.frameBox.style.background = options.theme.background;
|
|
270
239
|
}
|
|
271
|
-
|
|
272
240
|
options.frameBox.style.padding = '10px';
|
|
273
241
|
options.frameBox.style.paddingBottom = '40px';
|
|
274
242
|
}
|
|
275
|
-
|
|
276
243
|
const doJump = time => {
|
|
277
244
|
terminal.current.reset();
|
|
278
245
|
const toFrameIndex = (0, _util.findFrameAt)(frames, time);
|
|
279
|
-
|
|
280
246
|
for (let i = 0; i < toFrameIndex; i++) {
|
|
281
247
|
renderFrame(i);
|
|
282
248
|
}
|
|
283
249
|
};
|
|
284
|
-
|
|
285
250
|
const onJump = e => {
|
|
286
251
|
if (!progress.current || !terminal.current || !state.isStarted) {
|
|
287
252
|
return false;
|
|
288
253
|
}
|
|
289
|
-
|
|
290
254
|
const length = progress.current.getBoundingClientRect().width;
|
|
291
|
-
const position = e.nativeEvent.offsetX;
|
|
255
|
+
const position = e.nativeEvent.offsetX;
|
|
256
|
+
// console.log('onJump', { length, position, e });
|
|
292
257
|
|
|
293
258
|
const currentTime = Math.floor(totalDuration * position / length);
|
|
294
259
|
dispatch({
|
|
@@ -301,7 +266,6 @@ function Player(props) {
|
|
|
301
266
|
emitEvent('onJump');
|
|
302
267
|
return false;
|
|
303
268
|
};
|
|
304
|
-
|
|
305
269
|
const onStart = () => {
|
|
306
270
|
if (state.isStarted === false) {
|
|
307
271
|
dispatch({
|
|
@@ -309,14 +273,12 @@ function Player(props) {
|
|
|
309
273
|
});
|
|
310
274
|
terminal.current.reset();
|
|
311
275
|
}
|
|
312
|
-
|
|
313
276
|
dispatch({
|
|
314
277
|
type: 'play'
|
|
315
278
|
});
|
|
316
279
|
emitEvent('onStart');
|
|
317
280
|
return false;
|
|
318
281
|
};
|
|
319
|
-
|
|
320
282
|
const onPause = () => {
|
|
321
283
|
dispatch({
|
|
322
284
|
type: 'pause'
|
|
@@ -324,7 +286,6 @@ function Player(props) {
|
|
|
324
286
|
emitEvent('onPause');
|
|
325
287
|
return false;
|
|
326
288
|
};
|
|
327
|
-
|
|
328
289
|
const onPlay = () => {
|
|
329
290
|
if (state.currentFrame === frames.length - 1 && state.currentTime === totalDuration) {
|
|
330
291
|
dispatch({
|
|
@@ -332,11 +293,9 @@ function Player(props) {
|
|
|
332
293
|
});
|
|
333
294
|
terminal.current.reset();
|
|
334
295
|
}
|
|
335
|
-
|
|
336
296
|
emitEvent('onPlay');
|
|
337
297
|
return onStart();
|
|
338
298
|
};
|
|
339
|
-
|
|
340
299
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
341
300
|
className: (0, _util.getPlayerClass)(options, state),
|
|
342
301
|
ref: container,
|
|
@@ -440,7 +399,6 @@ function Player(props) {
|
|
|
440
399
|
})]
|
|
441
400
|
});
|
|
442
401
|
}
|
|
443
|
-
|
|
444
402
|
Player.propTypes = {
|
|
445
403
|
frames: _propTypes.default.array.isRequired,
|
|
446
404
|
options: _propTypes.default.object.isRequired,
|
|
@@ -451,9 +409,7 @@ Player.propTypes = {
|
|
|
451
409
|
onTick: _propTypes.default.func,
|
|
452
410
|
onJump: _propTypes.default.func
|
|
453
411
|
};
|
|
454
|
-
|
|
455
412
|
const noop = () => {};
|
|
456
|
-
|
|
457
413
|
Player.defaultProps = {
|
|
458
414
|
onComplete: noop,
|
|
459
415
|
onStart: noop,
|
package/lib/Terminal.js
CHANGED
|
@@ -4,48 +4,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _xterm = require("xterm");
|
|
13
|
-
|
|
14
10
|
var _xtermAddonWebLinks = require("xterm-addon-web-links");
|
|
15
|
-
|
|
16
11
|
var _xtermAddonFit = require("xterm-addon-fit");
|
|
17
|
-
|
|
18
12
|
var _lodash = require("lodash");
|
|
19
|
-
|
|
20
13
|
require("./xterm.css");
|
|
21
|
-
|
|
22
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
23
|
-
|
|
24
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
function
|
|
27
|
-
|
|
16
|
+
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; }
|
|
17
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
18
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable react/no-unused-class-component-methods */
|
|
28
19
|
class Terminal extends _react.default.Component {
|
|
29
20
|
constructor() {
|
|
30
21
|
super(...arguments);
|
|
31
|
-
|
|
32
22
|
_defineProperty(this, "xterm", null);
|
|
33
|
-
|
|
34
23
|
_defineProperty(this, "container", null);
|
|
35
|
-
|
|
36
24
|
_defineProperty(this, "onData", data => {
|
|
37
25
|
if (this.props.onData) {
|
|
38
26
|
this.props.onData(data);
|
|
39
27
|
}
|
|
40
28
|
});
|
|
41
|
-
|
|
42
29
|
_defineProperty(this, "onRender", data => {
|
|
43
30
|
if (this.props.onRender) {
|
|
44
31
|
this.props.onRender(data);
|
|
45
32
|
}
|
|
46
33
|
});
|
|
47
34
|
}
|
|
48
|
-
|
|
49
35
|
componentDidMount() {
|
|
50
36
|
const {
|
|
51
37
|
value,
|
|
@@ -58,11 +44,9 @@ class Terminal extends _react.default.Component {
|
|
|
58
44
|
this.xterm.open(this.container);
|
|
59
45
|
this.xterm.onData(this.onData.bind(this));
|
|
60
46
|
this.xterm.onRender(this.onRender.bind(this));
|
|
61
|
-
|
|
62
47
|
if (value) {
|
|
63
48
|
this.xterm.write(value);
|
|
64
49
|
}
|
|
65
|
-
|
|
66
50
|
setTimeout(() => {
|
|
67
51
|
if (this.xterm) {
|
|
68
52
|
this.fitAddon.fit();
|
|
@@ -73,16 +57,13 @@ class Terminal extends _react.default.Component {
|
|
|
73
57
|
}, 600);
|
|
74
58
|
window.addEventListener('resize', this.debounceFit);
|
|
75
59
|
}
|
|
76
|
-
|
|
77
60
|
componentWillUnmount() {
|
|
78
61
|
if (this.xterm) {
|
|
79
62
|
this.xterm.dispose();
|
|
80
63
|
this.xterm = null;
|
|
81
64
|
}
|
|
82
|
-
|
|
83
65
|
window.removeEventListener('resize', this.debounceFit);
|
|
84
66
|
}
|
|
85
|
-
|
|
86
67
|
shouldComponentUpdate(nextProps) {
|
|
87
68
|
// eslint-disable-next-line no-prototype-builtins
|
|
88
69
|
if (nextProps.hasOwnProperty('value') && nextProps.value !== this.props.value) {
|
|
@@ -93,56 +74,46 @@ class Terminal extends _react.default.Component {
|
|
|
93
74
|
}, 0);
|
|
94
75
|
}
|
|
95
76
|
}
|
|
96
|
-
|
|
97
77
|
return false;
|
|
98
78
|
}
|
|
99
|
-
|
|
100
79
|
getXTerm() {
|
|
101
80
|
return this.xterm;
|
|
102
81
|
}
|
|
103
|
-
|
|
104
82
|
write(data, cb) {
|
|
105
83
|
if (this.xterm) {
|
|
106
84
|
this.xterm.write(data, cb);
|
|
107
85
|
}
|
|
108
86
|
}
|
|
109
|
-
|
|
110
87
|
focus() {
|
|
111
88
|
if (this.xterm) {
|
|
112
89
|
this.xterm.focus();
|
|
113
90
|
}
|
|
114
91
|
}
|
|
115
|
-
|
|
116
92
|
reset() {
|
|
117
93
|
if (this.xterm) {
|
|
118
94
|
this.xterm.reset();
|
|
119
95
|
}
|
|
120
96
|
}
|
|
121
|
-
|
|
122
97
|
resize(cols, rows) {
|
|
123
98
|
if (this.xterm) {
|
|
124
99
|
this.xterm.resize(Math.round(cols), Math.round(rows));
|
|
125
100
|
}
|
|
126
101
|
}
|
|
127
|
-
|
|
128
102
|
setOption(key, value) {
|
|
129
103
|
if (this.xterm) {
|
|
130
104
|
this.xterm.setOption(key, value);
|
|
131
105
|
}
|
|
132
106
|
}
|
|
133
|
-
|
|
134
107
|
getOption(key) {
|
|
135
108
|
if (this.xterm) {
|
|
136
109
|
this.xterm.setOption(key);
|
|
137
110
|
}
|
|
138
111
|
}
|
|
139
|
-
|
|
140
112
|
refresh() {
|
|
141
113
|
if (this.xterm) {
|
|
142
114
|
this.xterm.refresh(0, this.xterm.rows - 1);
|
|
143
115
|
}
|
|
144
116
|
}
|
|
145
|
-
|
|
146
117
|
render() {
|
|
147
118
|
const className = ['react-xterm', this.props.className].filter(Boolean).join(' ');
|
|
148
119
|
return (
|
|
@@ -155,9 +126,7 @@ class Terminal extends _react.default.Component {
|
|
|
155
126
|
})
|
|
156
127
|
);
|
|
157
128
|
}
|
|
158
|
-
|
|
159
129
|
}
|
|
160
|
-
|
|
161
130
|
exports.default = Terminal;
|
|
162
131
|
Terminal.propTypes = {
|
|
163
132
|
onData: _propTypes.default.func,
|
|
@@ -167,9 +136,7 @@ Terminal.propTypes = {
|
|
|
167
136
|
className: _propTypes.default.string,
|
|
168
137
|
style: _propTypes.default.object
|
|
169
138
|
};
|
|
170
|
-
|
|
171
139
|
const noop = () => {};
|
|
172
|
-
|
|
173
140
|
Terminal.defaultProps = {
|
|
174
141
|
onData: noop,
|
|
175
142
|
onRender: noop,
|
package/lib/index.js
CHANGED
|
@@ -15,9 +15,6 @@ Object.defineProperty(exports, "TerminalPlayer", {
|
|
|
15
15
|
return _Player.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
|
|
19
18
|
var _Terminal = _interopRequireDefault(require("./Terminal"));
|
|
20
|
-
|
|
21
19
|
var _Player = _interopRequireDefault(require("./Player"));
|
|
22
|
-
|
|
23
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/util.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.isFrameAt = exports.getPlayerClass = exports.getFrameClass = exports.formatTime = exports.formatFrames = exports.findFrameAt = exports.defaultState = exports.defaultOptions = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Adjust the delays of the frames, considering to the options
|
|
10
9
|
*
|
|
@@ -24,70 +23,70 @@ const formatFrames = (frames, options) => {
|
|
|
24
23
|
frames.forEach(x => {
|
|
25
24
|
let {
|
|
26
25
|
delay
|
|
27
|
-
} = x;
|
|
26
|
+
} = x;
|
|
28
27
|
|
|
28
|
+
// Adjust the delay according to the options
|
|
29
29
|
if (options.frameDelay !== 'auto') {
|
|
30
30
|
delay = options.frameDelay;
|
|
31
31
|
} else if (options.maxIdleTime !== 'auto' && delay > options.maxIdleTime) {
|
|
32
32
|
delay = options.maxIdleTime;
|
|
33
|
-
}
|
|
34
|
-
|
|
33
|
+
}
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
// Apply speedFactor
|
|
36
|
+
delay *= options.speedFactor;
|
|
37
37
|
|
|
38
|
+
// Set the adjusted delay
|
|
38
39
|
x.delay = delay;
|
|
39
|
-
});
|
|
40
|
+
});
|
|
40
41
|
|
|
42
|
+
// Calculate and set the duration, startTime, and endTime for each frame
|
|
41
43
|
let currentTime = 0;
|
|
42
44
|
const framesCount = frames.length;
|
|
43
45
|
frames.forEach((x, index) => {
|
|
44
46
|
// Set the duration (the delay of the next frame)
|
|
45
47
|
// The % is used to take the delay of the first frame
|
|
46
48
|
// as the duration of the last frame
|
|
47
|
-
const duration = frames[(index + 1) % framesCount].delay;
|
|
49
|
+
const duration = frames[(index + 1) % framesCount].delay;
|
|
48
50
|
|
|
51
|
+
// Set timing values for the current frame
|
|
49
52
|
x.duration = duration;
|
|
50
53
|
x.startTime = currentTime;
|
|
51
54
|
x.endTime = currentTime + duration;
|
|
52
55
|
currentTime += duration;
|
|
53
|
-
});
|
|
56
|
+
});
|
|
54
57
|
|
|
58
|
+
// Total duration
|
|
55
59
|
const totalDuration = frames.reduce((sum, x) => sum + x.delay, 0);
|
|
56
60
|
return {
|
|
57
61
|
frames,
|
|
58
62
|
totalDuration
|
|
59
63
|
};
|
|
60
64
|
};
|
|
65
|
+
|
|
61
66
|
/**
|
|
62
67
|
* Get the frame's index at a specific time
|
|
63
68
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
69
|
exports.formatFrames = formatFrames;
|
|
67
|
-
|
|
68
70
|
const findFrameAt = (frames, time, fromIndex) => {
|
|
69
71
|
let frame = null;
|
|
70
|
-
|
|
71
72
|
if (typeof fromIndex === 'undefined') {
|
|
72
73
|
// eslint-disable-next-line no-param-reassign
|
|
73
74
|
fromIndex = 0;
|
|
74
75
|
}
|
|
75
|
-
|
|
76
76
|
for (let i = fromIndex; i < frames.length; i++) {
|
|
77
77
|
frame = frames[i];
|
|
78
|
-
|
|
79
78
|
if (frame.startTime <= time && time < frame.endTime) {
|
|
80
79
|
return i;
|
|
81
80
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
81
|
+
}
|
|
84
82
|
|
|
83
|
+
// The endTime of the final frame belongs to it
|
|
85
84
|
if (frame.startTime <= time && time <= frame.endTime) {
|
|
86
85
|
return frames.length - 1;
|
|
87
86
|
}
|
|
88
|
-
|
|
89
87
|
return -1;
|
|
90
88
|
};
|
|
89
|
+
|
|
91
90
|
/**
|
|
92
91
|
* Check if the time belongs to the frame's duration
|
|
93
92
|
*
|
|
@@ -95,81 +94,57 @@ const findFrameAt = (frames, time, fromIndex) => {
|
|
|
95
94
|
* @param {Number} frameIndex
|
|
96
95
|
* @return {Number}
|
|
97
96
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
97
|
exports.findFrameAt = findFrameAt;
|
|
101
|
-
|
|
102
98
|
const isFrameAt = (frames, time, frameIndex) => {
|
|
103
99
|
const frame = frames[frameIndex];
|
|
104
|
-
|
|
105
100
|
if (typeof frame === 'undefined') {
|
|
106
101
|
return false;
|
|
107
102
|
}
|
|
108
|
-
|
|
109
103
|
if (frame.startTime <= time && time < frame.endTime) {
|
|
110
104
|
return true;
|
|
111
105
|
}
|
|
112
|
-
|
|
113
106
|
return false;
|
|
114
107
|
};
|
|
115
|
-
|
|
116
108
|
exports.isFrameAt = isFrameAt;
|
|
117
|
-
|
|
118
109
|
const formatTime = time => {
|
|
119
110
|
let minutes = Math.floor(time / 60000);
|
|
120
111
|
let seconds = parseInt((time - minutes * 60000) / 1000, 10);
|
|
121
|
-
|
|
122
112
|
if (minutes < 10) {
|
|
123
113
|
minutes = "0".concat(minutes);
|
|
124
114
|
}
|
|
125
|
-
|
|
126
115
|
if (seconds < 10) {
|
|
127
116
|
seconds = "0".concat(seconds);
|
|
128
117
|
}
|
|
129
|
-
|
|
130
118
|
return "".concat(minutes, ":").concat(seconds);
|
|
131
119
|
};
|
|
132
|
-
|
|
133
120
|
exports.formatTime = formatTime;
|
|
134
|
-
|
|
135
121
|
const getPlayerClass = (options, state) => {
|
|
136
122
|
const playerClass = ['terminal-player'];
|
|
137
|
-
|
|
138
123
|
if (options.controls) {
|
|
139
124
|
playerClass.push('controls');
|
|
140
125
|
}
|
|
141
|
-
|
|
142
126
|
if (options.frameBox.type) {
|
|
143
127
|
playerClass.push('framed');
|
|
144
128
|
}
|
|
145
|
-
|
|
146
129
|
if (options.rows < 10) {
|
|
147
130
|
playerClass.push('small');
|
|
148
131
|
}
|
|
149
|
-
|
|
150
132
|
if (state.isStarted) {
|
|
151
133
|
playerClass.push('started');
|
|
152
134
|
}
|
|
153
|
-
|
|
154
135
|
if (state.isPlaying) {
|
|
155
136
|
playerClass.push('playing');
|
|
156
137
|
}
|
|
157
|
-
|
|
158
138
|
return playerClass.filter(Boolean).join(' ');
|
|
159
139
|
};
|
|
160
|
-
|
|
161
140
|
exports.getPlayerClass = getPlayerClass;
|
|
162
|
-
|
|
163
141
|
const getFrameClass = options => {
|
|
164
142
|
const frameClass = ['terminal-frame'];
|
|
165
|
-
|
|
166
143
|
if (options.frameBox.type) {
|
|
167
144
|
frameClass.push("terminal-".concat(options.frameBox.type));
|
|
168
145
|
}
|
|
169
|
-
|
|
170
146
|
return frameClass.join(' ');
|
|
171
147
|
};
|
|
172
|
-
|
|
173
148
|
exports.getFrameClass = getFrameClass;
|
|
174
149
|
const defaultState = {
|
|
175
150
|
isPlaying: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/terminal",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.59",
|
|
4
4
|
"description": "A react wrapper for xterm allowing you to easily render a terminal in the browser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": ">=18.1.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "f50c420e5f06ae108d59636cfdcfde88d1e10f4c",
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@arcblock/react-hooks": "^2.5.
|
|
52
|
-
"@arcblock/ux": "^2.5.
|
|
51
|
+
"@arcblock/react-hooks": "^2.5.59",
|
|
52
|
+
"@arcblock/ux": "^2.5.59",
|
|
53
53
|
"@emotion/react": "^11.10.4",
|
|
54
54
|
"@emotion/styled": "^11.10.4",
|
|
55
55
|
"core-js": "^3.25.5",
|