@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/src/player.css ADDED
@@ -0,0 +1,378 @@
1
+ .terminal-player,
2
+ .terminal {
3
+ display: inline-block;
4
+ }
5
+
6
+ .terminal .xterm .xterm-viewport {
7
+ overflow-y: hidden !important;
8
+ }
9
+
10
+ .terminal-frame {
11
+ position: relative;
12
+ }
13
+
14
+ /*//// [ Reset ] ////*/
15
+
16
+ .terminal div {
17
+ margin: 0;
18
+ padding: 0;
19
+ border: 0;
20
+ outline: 0;
21
+ font-weight: inherit;
22
+ font-style: inherit;
23
+ font-size: 100%;
24
+ font-family: inherit;
25
+ vertical-align: baseline;
26
+ }
27
+
28
+ /*//// [ Window ] ////*/
29
+
30
+ .terminal-frame.terminal-window {
31
+ -moz-border-radius: 6px;
32
+ -webkit-border-radius: 6px;
33
+ border-radius: 6px;
34
+ border: 1px solid #b3b3b3;
35
+ box-shadow: 0px 0px 18px #b3b3b3;
36
+ margin: 18px;
37
+ overflow: hidden;
38
+ }
39
+
40
+ .terminal-frame.terminal-window .terminal-titlebar {
41
+ -moz-border-top-left-radius: 6px;
42
+ -moz-border-top-right-radius: 6px;
43
+ -webkit-border-top-left-radius: 6px;
44
+ -webkit-border-top-right-radius: 6px;
45
+ background: #e8e8e8;
46
+ border-bottom: 1px solid #b1aeb1;
47
+ border-top-left-radius: 6px;
48
+ border-top-right-radius: 6px;
49
+ border-top: 1px solid #f3f1f3;
50
+ color: #3b4247;
51
+ font-family: Arial, sans-serif;
52
+ font-size: 14px;
53
+ height: 22px;
54
+ line-height: 22px;
55
+ position: relative;
56
+ text-align: center;
57
+ width: 100%;
58
+ }
59
+
60
+ .terminal-frame.terminal-window .terminal-titlebar .buttons {
61
+ left: 8px;
62
+ line-height: 0px;
63
+ position: absolute;
64
+ top: 3.5px;
65
+ }
66
+
67
+ .terminal-frame.terminal-window .terminal-titlebar .close-button {
68
+ -moz-border-radius: 50%;
69
+ -webkit-border-radius: 50%;
70
+ background: #ff5c5c;
71
+ border-radius: 50%;
72
+ border: 1px solid #e33e41;
73
+ display: inline-block;
74
+ height: 12px;
75
+ width: 12px;
76
+ }
77
+
78
+ .terminal-frame.terminal-window .terminal-titlebar .minimize-button {
79
+ -moz-border-radius: 50%;
80
+ -webkit-border-radius: 50%;
81
+ background: #ffbd4c;
82
+ border-radius: 50%;
83
+ border: 1px solid #e09e3e;
84
+ display: inline-block;
85
+ height: 12px;
86
+ margin-left: 4px;
87
+ width: 12px;
88
+ }
89
+
90
+ .terminal-frame.terminal-window .terminal-titlebar .maximize-button {
91
+ -moz-border-radius: 50%;
92
+ -webkit-border-radius: 50%;
93
+ background: #00ca56;
94
+ border-radius: 50%;
95
+ border: 1px solid #14ae46;
96
+ display: inline-block;
97
+ height: 12px;
98
+ margin-left: 4px;
99
+ width: 12px;
100
+ }
101
+
102
+ .terminal-frame.terminal-window .terminal-body {
103
+ background-color: #1d1d1d;
104
+ padding: 10px;
105
+ }
106
+
107
+ /*//// [ Floating ] ////*/
108
+
109
+ .terminal-frame.terminal-floating {
110
+ -moz-border-radius: 6px;
111
+ -webkit-border-radius: 6px;
112
+ background-color: #1d1d1d;
113
+ border-radius: 6px;
114
+ box-shadow: 0px 0px 18px #b3b3b3;
115
+ margin: 18px;
116
+ overflow: hidden;
117
+ }
118
+
119
+ .terminal-frame.terminal-floating .terminal-titlebar {
120
+ color: white;
121
+ font-family: Arial, sans-serif;
122
+ font-size: 14px;
123
+ height: 34px;
124
+ line-height: 34px;
125
+ position: relative;
126
+ text-align: center;
127
+ width: 100%;
128
+ }
129
+
130
+ .terminal-frame.terminal-floating .terminal-titlebar .buttons {
131
+ left: 13px;
132
+ line-height: 0px;
133
+ position: absolute;
134
+ top: 9px;
135
+ }
136
+
137
+ .terminal-frame.terminal-floating .terminal-titlebar .close-button {
138
+ -moz-border-radius: 50%;
139
+ -webkit-border-radius: 50%;
140
+ background: #ff5c5c;
141
+ border-radius: 50%;
142
+ display: inline-block;
143
+ height: 15px;
144
+ width: 15px;
145
+ }
146
+
147
+ .terminal-frame.terminal-floating .terminal-titlebar .minimize-button {
148
+ -moz-border-radius: 50%;
149
+ -webkit-border-radius: 50%;
150
+ background: #ffbd4c;
151
+ border-radius: 50%;
152
+ display: inline-block;
153
+ height: 15px;
154
+ line-height: 10px;
155
+ margin-left: 4px;
156
+ width: 15px;
157
+ }
158
+
159
+ .terminal-frame.terminal-floating .terminal-titlebar .maximize-button {
160
+ -moz-border-radius: 50%;
161
+ -webkit-border-radius: 50%;
162
+ background: #00ca56;
163
+ border-radius: 50%;
164
+ display: inline-block;
165
+ height: 15px;
166
+ line-height: 10px;
167
+ margin-left: 4px;
168
+ width: 15px;
169
+ }
170
+
171
+ .terminal-frame.terminal-floating .terminal-body {
172
+ padding: 20px;
173
+ }
174
+
175
+ /*//// [ Solid ] ////*/
176
+
177
+ .terminal-frame.terminal-solid {
178
+ -moz-border-radius: 6px;
179
+ -webkit-border-radius: 6px;
180
+ background-color: #1d1d1d;
181
+ border-radius: 6px;
182
+ box-shadow: 0px 0px 18px #b3b3b3;
183
+ margin: 18px;
184
+ overflow: hidden;
185
+ }
186
+
187
+ .terminal-frame.terminal-solid .terminal-titlebar {
188
+ color: white;
189
+ font-family: Arial, sans-serif;
190
+ font-size: 14px;
191
+ position: relative;
192
+ text-align: center;
193
+ width: 100%;
194
+ }
195
+
196
+ .terminal-frame.terminal-solid .terminal-titlebar .title {
197
+ margin: 15px 15px 15px;
198
+ }
199
+
200
+ .terminal-frame.terminal-solid .terminal-titlebar .title:empty {
201
+ display: none;
202
+ }
203
+
204
+ .terminal-frame.terminal-solid .terminal-titlebar .buttons {
205
+ display: none;
206
+ }
207
+
208
+ .terminal-frame.terminal-solid .terminal-body {
209
+ padding: 20px;
210
+ }
211
+
212
+ /*//// [ Player ] ////*/
213
+
214
+ .terminal-player {
215
+ position: relative;
216
+ font-size: 0;
217
+ }
218
+
219
+ .terminal-player .controller {
220
+ background: #45484d;
221
+ bottom: 0px;
222
+ display: none;
223
+ font-family: Helvetica, Arial, sans-serif;
224
+ font-size: 12px;
225
+ height: 40px;
226
+ position: absolute;
227
+ width: 100%;
228
+ z-index: 20;
229
+ background: #222222;
230
+ transition: height ease 200ms;
231
+ -webkit-transition: height ease 200ms;
232
+ -moz-transition: height ease 200ms;
233
+ -o-transition: height ease 200ms;
234
+ }
235
+
236
+ .terminal-player.controls .controller {
237
+ display: block;
238
+ }
239
+
240
+ .terminal-player.playing .controller {
241
+ height: 0px;
242
+ overflow: hidden;
243
+ }
244
+
245
+ .terminal-player.playing:hover .controller {
246
+ height: 40px;
247
+ overflow: hidden;
248
+ }
249
+
250
+ .terminal-player .play,
251
+ .terminal-player .pause {
252
+ fill: #cacaca;
253
+ float: left;
254
+ height: 40px;
255
+ line-height: 40px;
256
+ text-align: center;
257
+ width: 40px;
258
+ }
259
+
260
+ .terminal-player .play .icon,
261
+ .terminal-player .pause .icon {
262
+ border-color: transparent transparent transparent #cacaca;
263
+ box-sizing: border-box;
264
+ cursor: pointer;
265
+ display: inline-block;
266
+ height: 15px;
267
+ }
268
+
269
+ .terminal-player .pause .icon {
270
+ border-style: double;
271
+ border-width: 0px 0px 0px 12px;
272
+ margin-top: 11px;
273
+ }
274
+
275
+ .terminal-player .play .icon {
276
+ border-style: solid;
277
+ border-width: 8px 0px 8px 13px;
278
+ margin-top: 10px;
279
+ }
280
+
281
+ .terminal-player .pause {
282
+ display: none;
283
+ }
284
+
285
+ .terminal-player.playing .play {
286
+ display: none;
287
+ }
288
+
289
+ .terminal-player.playing .pause {
290
+ display: inline-block;
291
+ }
292
+
293
+ .terminal-player .timer {
294
+ color: #cacaca;
295
+ float: right;
296
+ line-height: 40px;
297
+ padding: 0 10px;
298
+ }
299
+
300
+ .terminal-player .progressbar-wrapper {
301
+ height: 40px;
302
+ line-height: 38px;
303
+ overflow: hidden;
304
+ }
305
+
306
+ .terminal-player .progressbar {
307
+ background-color: #424242;
308
+ display: inline-block;
309
+ height: 7px;
310
+ overflow: hidden;
311
+ width: 100%;
312
+ border-radius: 10px;
313
+ -moz-border-radius: 10px;
314
+ -webkit-border-radius: 10px;
315
+ }
316
+
317
+ .terminal-player.started .progressbar {
318
+ cursor: pointer;
319
+ }
320
+
321
+ .terminal-player .progress {
322
+ background-color: #cacaca;
323
+ height: 7px;
324
+ position: relative;
325
+ width: 0%;
326
+ }
327
+
328
+ .terminal-player .cover {
329
+ cursor: pointer;
330
+ height: 100%;
331
+ position: absolute;
332
+ width: 100%;
333
+ z-index: 10;
334
+ }
335
+
336
+ .terminal-player .start svg {
337
+ cursor: pointer;
338
+ fill: #eaeaea;
339
+ height: 130px;
340
+ left: 50%;
341
+ margin-left: -65px;
342
+ margin-top: -65px;
343
+ position: absolute;
344
+ top: 50%;
345
+ width: 130px;
346
+ z-index: 20;
347
+ filter: drop-shadow(10px 10px 15px rgba(0, 0, 0, 0.4));
348
+ -webkit-filter: drop-shadow(10px 10px 15px rgba(0, 0, 0, 0.4));
349
+ }
350
+
351
+ .terminal-player.small .start svg {
352
+ height: 60px;
353
+ margin-left: -30px;
354
+ margin-top: -30px;
355
+ width: 60px;
356
+ }
357
+
358
+ .terminal-player.framed .start svg {
359
+ transform: translate(0px, 8px);
360
+ -webkit-transform: translate(0px, 8px);
361
+ -moz-transform: translate(0px, 8px);
362
+ -o-transform: translate(0px, 8px);
363
+ -ms-transform: translate(0px, 8px);
364
+ }
365
+
366
+ .terminal-player .cover:hover + .start svg,
367
+ .terminal-player .start:hover svg {
368
+ fill: white;
369
+ }
370
+
371
+ .terminal-player.started .cover,
372
+ .terminal-player.started .start {
373
+ display: none;
374
+ }
375
+
376
+ .terminal-player .terminal-watermark {
377
+ z-index: 99999;
378
+ }
@@ -0,0 +1,151 @@
1
+ /* eslint-disable react/no-unused-class-component-methods */
2
+ import React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import { Terminal as XTerm } from 'xterm';
5
+ import { WebLinksAddon } from 'xterm-addon-web-links';
6
+ import { FitAddon } from 'xterm-addon-fit';
7
+ import { debounce } from 'lodash';
8
+
9
+ import './xterm.css';
10
+
11
+ export default class Terminal extends React.Component {
12
+ xterm = null;
13
+
14
+ container = null;
15
+
16
+ componentDidMount() {
17
+ const { value, options } = this.props;
18
+ this.fitAddon = new FitAddon();
19
+
20
+ this.xterm = new XTerm(options);
21
+ this.xterm.loadAddon(new WebLinksAddon());
22
+ this.xterm.loadAddon(this.fitAddon);
23
+
24
+ this.xterm.open(this.container);
25
+
26
+ this.xterm.onData(this.onData.bind(this));
27
+ this.xterm.onRender(this.onRender.bind(this));
28
+
29
+ if (value) {
30
+ this.xterm.write(value);
31
+ }
32
+
33
+ setTimeout(() => {
34
+ if (this.xterm) {
35
+ this.fitAddon.fit();
36
+ }
37
+ }, 0);
38
+
39
+ this.debounceFit = debounce(() => {
40
+ this.fitAddon.fit();
41
+ }, 600);
42
+
43
+ window.addEventListener('resize', this.debounceFit);
44
+ }
45
+
46
+ componentWillUnmount() {
47
+ if (this.xterm) {
48
+ this.xterm.dispose();
49
+ this.xterm = null;
50
+ }
51
+ window.removeEventListener('resize', this.debounceFit);
52
+ }
53
+
54
+ shouldComponentUpdate(nextProps) {
55
+ // eslint-disable-next-line no-prototype-builtins
56
+ if (nextProps.hasOwnProperty('value') && nextProps.value !== this.props.value) {
57
+ if (this.xterm) {
58
+ this.xterm.clear();
59
+ setTimeout(() => {
60
+ this.xterm.write(nextProps.value);
61
+ }, 0);
62
+ }
63
+ }
64
+ return false;
65
+ }
66
+
67
+ getXTerm() {
68
+ return this.xterm;
69
+ }
70
+
71
+ write(data, cb) {
72
+ if (this.xterm) {
73
+ this.xterm.write(data, cb);
74
+ }
75
+ }
76
+
77
+ focus() {
78
+ if (this.xterm) {
79
+ this.xterm.focus();
80
+ }
81
+ }
82
+
83
+ reset() {
84
+ if (this.xterm) {
85
+ this.xterm.reset();
86
+ }
87
+ }
88
+
89
+ onData = (data) => {
90
+ if (this.props.onData) {
91
+ this.props.onData(data);
92
+ }
93
+ };
94
+
95
+ onRender = (data) => {
96
+ if (this.props.onRender) {
97
+ this.props.onRender(data);
98
+ }
99
+ };
100
+
101
+ resize(cols, rows) {
102
+ if (this.xterm) {
103
+ this.xterm.resize(Math.round(cols), Math.round(rows));
104
+ }
105
+ }
106
+
107
+ setOption(key, value) {
108
+ if (this.xterm) {
109
+ this.xterm.setOption(key, value);
110
+ }
111
+ }
112
+
113
+ getOption(key) {
114
+ if (this.xterm) {
115
+ this.xterm.setOption(key);
116
+ }
117
+ }
118
+
119
+ refresh() {
120
+ if (this.xterm) {
121
+ this.xterm.refresh(0, this.xterm.rows - 1);
122
+ }
123
+ }
124
+
125
+ render() {
126
+ const className = ['react-xterm', this.props.className].filter(Boolean).join(' ');
127
+ return (
128
+ // eslint-disable-next-line no-return-assign
129
+ <div ref={(ref) => (this.container = ref)} className={className} style={this.props.style} />
130
+ );
131
+ }
132
+ }
133
+
134
+ Terminal.propTypes = {
135
+ onData: PropTypes.func,
136
+ onRender: PropTypes.func,
137
+ options: PropTypes.object,
138
+ value: PropTypes.string,
139
+ className: PropTypes.string,
140
+ style: PropTypes.object,
141
+ };
142
+
143
+ const noop = () => {};
144
+ Terminal.defaultProps = {
145
+ onData: noop,
146
+ onRender: noop,
147
+ options: {},
148
+ value: '',
149
+ className: '',
150
+ style: {},
151
+ };
package/src/util.js ADDED
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Adjust the delays of the frames, considering to the options
3
+ *
4
+ * - frameDelay
5
+ * - Delay between frames in ms
6
+ * - If the value is `auto` use the actual recording delays
7
+ *
8
+ * - maxIdleTime
9
+ * - Maximum delay between frames in ms
10
+ * - Ignored if the `frameDelay` isn't set to `auto`
11
+ * - Set to `auto` to prevnt limiting the max idle time
12
+ *
13
+ * - speedFactor
14
+ * - Multiply the frames delays by this factor
15
+ */
16
+ export const formatFrames = (frames, options) => {
17
+ frames.forEach((x) => {
18
+ let { delay } = x;
19
+
20
+ // Adjust the delay according to the options
21
+ if (options.frameDelay !== 'auto') {
22
+ delay = options.frameDelay;
23
+ } else if (options.maxIdleTime !== 'auto' && delay > options.maxIdleTime) {
24
+ delay = options.maxIdleTime;
25
+ }
26
+
27
+ // Apply speedFactor
28
+ delay *= options.speedFactor;
29
+
30
+ // Set the adjusted delay
31
+ x.delay = delay;
32
+ });
33
+
34
+ // Calculate and set the duration, startTime, and endTime for each frame
35
+ let currentTime = 0;
36
+ const framesCount = frames.length;
37
+ frames.forEach((x, index) => {
38
+ // Set the duration (the delay of the next frame)
39
+ // The % is used to take the delay of the first frame
40
+ // as the duration of the last frame
41
+ const duration = frames[(index + 1) % framesCount].delay;
42
+
43
+ // Set timing values for the current frame
44
+ x.duration = duration;
45
+ x.startTime = currentTime;
46
+ x.endTime = currentTime + duration;
47
+
48
+ currentTime += duration;
49
+ });
50
+
51
+ // Total duration
52
+ const totalDuration = frames.reduce((sum, x) => sum + x.delay, 0);
53
+
54
+ return { frames, totalDuration };
55
+ };
56
+
57
+ /**
58
+ * Get the frame's index at a specific time
59
+ */
60
+ export const findFrameAt = (frames, time, fromIndex) => {
61
+ let frame = null;
62
+
63
+ if (typeof fromIndex === 'undefined') {
64
+ // eslint-disable-next-line no-param-reassign
65
+ fromIndex = 0;
66
+ }
67
+
68
+ for (let i = fromIndex; i < frames.length; i++) {
69
+ frame = frames[i];
70
+
71
+ if (frame.startTime <= time && time < frame.endTime) {
72
+ return i;
73
+ }
74
+ }
75
+
76
+ // The endTime of the final frame belongs to it
77
+ if (frame.startTime <= time && time <= frame.endTime) {
78
+ return frames.length - 1;
79
+ }
80
+
81
+ return -1;
82
+ };
83
+
84
+ /**
85
+ * Check if the time belongs to the frame's duration
86
+ *
87
+ * @param {Number} time
88
+ * @param {Number} frameIndex
89
+ * @return {Number}
90
+ */
91
+ export const isFrameAt = (frames, time, frameIndex) => {
92
+ const frame = frames[frameIndex];
93
+
94
+ if (typeof frame === 'undefined') {
95
+ return false;
96
+ }
97
+
98
+ if (frame.startTime <= time && time < frame.endTime) {
99
+ return true;
100
+ }
101
+
102
+ return false;
103
+ };
104
+
105
+ export const formatTime = (time) => {
106
+ let minutes = Math.floor(time / 60000);
107
+ let seconds = parseInt((time - minutes * 60000) / 1000, 10);
108
+
109
+ if (minutes < 10) {
110
+ minutes = `0${minutes}`;
111
+ }
112
+ if (seconds < 10) {
113
+ seconds = `0${seconds}`;
114
+ }
115
+
116
+ return `${minutes}:${seconds}`;
117
+ };
118
+
119
+ export const getPlayerClass = (options, state) => {
120
+ const playerClass = ['terminal-player'];
121
+ if (options.controls) {
122
+ playerClass.push('controls');
123
+ }
124
+ if (options.frameBox.type) {
125
+ playerClass.push('framed');
126
+ }
127
+ if (options.rows < 10) {
128
+ playerClass.push('small');
129
+ }
130
+ if (state.isStarted) {
131
+ playerClass.push('started');
132
+ }
133
+ if (state.isPlaying) {
134
+ playerClass.push('playing');
135
+ }
136
+
137
+ return playerClass.filter(Boolean).join(' ');
138
+ };
139
+
140
+ export const getFrameClass = (options) => {
141
+ const frameClass = ['terminal-frame'];
142
+ if (options.frameBox.type) {
143
+ frameClass.push(`terminal-${options.frameBox.type}`);
144
+ }
145
+
146
+ return frameClass.join(' ');
147
+ };
148
+
149
+ export const defaultState = {
150
+ isPlaying: false,
151
+ isStarted: false,
152
+ isRendering: false,
153
+ requireReset: false,
154
+ currentFrame: -1,
155
+ currentTime: 0,
156
+ lastTickTime: null,
157
+ };
158
+
159
+ export const defaultOptions = {
160
+ realTiming: false,
161
+ speedFactor: 1.0,
162
+ controls: true,
163
+ repeat: false,
164
+ autoplay: false,
165
+ thumbnailTime: 999999,
166
+ frameBox: {},
167
+ };