@arcblock/terminal 3.1.19 → 3.1.21

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 CHANGED
@@ -1,16 +1,16 @@
1
- import { jsxs as k, jsx as a } from "react/jsx-runtime";
2
- import { useRef as S, useReducer as O, useCallback as y, useEffect as A } from "react";
3
- import c from "prop-types";
4
- import b from "lodash/isUndefined";
5
- import F from "lodash/noop";
6
- import I from "./Terminal.js";
7
- import { PlayerRoot as H } from "./styles.js";
8
- import { defaultOptions as Y, formatFrames as _, defaultState as U, findFrameAt as j, getPlayerClass as X, getFrameClass as $, formatTime as G } from "./util.js";
9
- const ae = 8;
10
- function K({ ...E }) {
11
- const i = Object.assign({}, E);
12
- b(i.onComplete) && (i.onComplete = F), b(i.onStart) && (i.onStart = F), b(i.onStop) && (i.onStop = F), b(i.onPause) && (i.onPause = F), b(i.onTick) && (i.onTick = F), b(i.onJump) && (i.onJump = F);
13
- const e = Object.assign({}, Y, i.options), { frames: s, totalDuration: g } = _(i.frames, e), D = {
1
+ import { jsxs as F, jsx as a } from "react/jsx-runtime";
2
+ import { useRef as k, useReducer as I, useCallback as f, useEffect as A } from "react";
3
+ import o from "prop-types";
4
+ import P from "lodash/isUndefined";
5
+ import S from "lodash/noop";
6
+ import H from "./Terminal.js";
7
+ import { PlayerRoot as Y } from "./styles.js";
8
+ import { defaultOptions as _, formatFrames as U, defaultState as X, findFrameAt as j, getPlayerClass as $, getFrameClass as G, formatTime as K } from "./util.js";
9
+ const ie = 8;
10
+ function Q({ ...E }) {
11
+ const s = Object.assign({}, E);
12
+ P(s.onComplete) && (s.onComplete = S), P(s.onStart) && (s.onStart = S), P(s.onStop) && (s.onStop = S), P(s.onPause) && (s.onPause = S), P(s.onTick) && (s.onTick = S), P(s.onJump) && (s.onJump = S);
13
+ const e = Object.assign({}, _, s.options), { frames: c, totalDuration: g } = U(s.frames, e), D = {
14
14
  cols: e.cols,
15
15
  rows: e.rows,
16
16
  cursorStyle: e.cursorStyle,
@@ -22,106 +22,106 @@ function K({ ...E }) {
22
22
  allowTransparency: !0,
23
23
  scrollback: 0,
24
24
  theme: e.enableTheme ? e.theme : {}
25
- }, J = (r, t) => {
26
- switch (t.type) {
25
+ }, z = (r, n) => {
26
+ switch (n.type) {
27
27
  case "jump":
28
- return { ...r, ...t.payload };
28
+ return { ...r, ...n.payload };
29
29
  case "start":
30
30
  return { ...r, isStarted: !0, lastTickTime: Date.now() };
31
31
  case "play":
32
- return { ...r, isPlaying: !0, lastTickTime: Date.now(), ...t.payload };
32
+ return { ...r, isPlaying: !0, lastTickTime: Date.now(), ...n.payload };
33
33
  case "pause":
34
- return { ...r, isPlaying: !1, ...t.payload };
34
+ return { ...r, isPlaying: !1, ...n.payload };
35
35
  case "tickStart":
36
- return { ...r, isRendering: !0, lastTickTime: Date.now(), ...t.payload };
36
+ return { ...r, isRendering: !0, lastTickTime: Date.now(), ...n.payload };
37
37
  case "tickEnd":
38
- return { ...r, isRendering: !1, lastTickTime: Date.now(), ...t.payload };
38
+ return { ...r, isRendering: !1, lastTickTime: Date.now(), ...n.payload };
39
39
  case "reset":
40
- return { ...r, currentFrame: -1, currentTime: 0, ...t.payload };
40
+ return { ...r, currentFrame: -1, currentTime: 0, ...n.payload };
41
41
  default:
42
- return { ...r, lastTickTime: Date.now(), ...t.payload };
42
+ return { ...r, lastTickTime: Date.now(), ...n.payload };
43
43
  }
44
- }, o = S(null), v = S(null), z = S(null), f = S(null), p = S(null), [n, u] = O(J, U), C = y(
45
- (r) => new Promise((t) => {
46
- const l = s[r];
47
- l && l.content && o.current ? (n.requireReset && o.current.reset(), o.current.write(l.content, () => {
48
- t();
49
- })) : t();
44
+ }, i = k(null), x = k(null), J = k(null), d = k(null), p = k(null), [t, u] = I(z, X), C = f(
45
+ (r) => new Promise((n) => {
46
+ const l = c[r];
47
+ l && l.content && i.current ? (t.requireReset && i.current.reset(), i.current.write(l.content, () => {
48
+ n();
49
+ })) : n();
50
50
  }),
51
- [s, n.requireReset]
52
- ), q = y(
51
+ [c, t.requireReset]
52
+ ), q = f(
53
53
  (r) => {
54
- const t = s[r];
55
- t && t.content && o.current && (n.requireReset && o.current.reset(), o.current.write(t.content));
54
+ const n = c[r];
55
+ n && n.content && i.current && (t.requireReset && i.current.reset(), i.current.write(n.content));
56
56
  },
57
- [s, n.requireReset]
58
- ), m = y(
57
+ [c, t.requireReset]
58
+ ), m = f(
59
59
  (r) => {
60
- typeof i[r] == "function" && i[r]({ state: n, frames: s, options: e });
60
+ typeof s[r] == "function" && s[r]({ state: t, frames: c, options: e });
61
61
  },
62
- [i, n, s, e]
63
- ), R = y(
62
+ [s, t, c, e]
63
+ ), N = f(
64
64
  (r) => {
65
- if (!o.current) return;
66
- o.current.reset();
67
- const t = j(s, r);
68
- if (t >= 0)
69
- for (let l = 0; l <= t; l++)
65
+ if (!i.current) return;
66
+ i.current.reset();
67
+ const n = j(c, r);
68
+ if (n >= 0)
69
+ for (let l = 0; l <= n; l++)
70
70
  q(l);
71
71
  },
72
- [s, q]
73
- ), L = y(
72
+ [c, q]
73
+ ), L = f(
74
74
  (r) => {
75
- if (!v.current || !o.current || !n.isStarted)
75
+ if (!x.current || !i.current || !t.isStarted)
76
76
  return !1;
77
- const t = v.current.getBoundingClientRect().width, l = r.nativeEvent.offsetX, h = Math.floor(g * l / t), T = j(s, h), x = n.isPlaying;
77
+ const n = x.current.getBoundingClientRect().width, l = r.nativeEvent.offsetX, h = Math.floor(g * l / n), T = j(c, h), w = t.isPlaying;
78
78
  return u({
79
79
  type: "jump",
80
80
  payload: {
81
81
  currentTime: h,
82
82
  currentFrame: T,
83
- isPlaying: x
83
+ isPlaying: w
84
84
  // Keep the same playing state
85
85
  }
86
- }), p.current = null, R(h), m("onJump"), !1;
86
+ }), p.current = null, N(h), m("onJump"), !1;
87
87
  },
88
- [n.isStarted, n.isPlaying, g, s, R, m]
89
- ), P = y(() => (n.isStarted === !1 && (o.current.resize(), u({ type: "start" }), o.current && o.current.reset()), p.current = null, u({ type: "play", payload: { currentFrame: -1, currentTime: 0 } }), m("onStart"), !1), [n.isStarted, m]), M = y(() => (u({ type: "pause" }), m("onPause"), !1), [m]);
88
+ [t.isStarted, t.isPlaying, g, c, N, m]
89
+ ), M = f(() => (t.currentFrame >= c.length - 1 ? (i.current.resize(), u({ type: "reset", payload: { currentFrame: -1, currentTime: 0 } }), i.current && i.current.reset(), p.current = null, u({ type: "play", payload: { currentFrame: -1, currentTime: 0 } })) : (p.current = null, u({ type: "play" })), m("onPlay"), !1), [t.currentFrame, c.length, m]), b = f(() => (t.isStarted === !1 && (i.current.resize(), u({ type: "start" }), i.current && i.current.reset()), p.current = null, u({ type: "play", payload: { currentFrame: -1, currentTime: 0 } }), m("onStart"), !1), [t.isStarted, m]), O = f(() => (u({ type: "pause" }), m("onPause"), !1), [m]);
90
90
  A(() => {
91
- o.current && (o.current.focus(), e.autoplay ? P() : R(Math.min(Math.abs(e.thumbnailTime), g)));
91
+ i.current && (i.current.focus(), e.autoplay ? b() : N(Math.min(Math.abs(e.thumbnailTime), g)));
92
92
  }, []);
93
- const w = S(n);
94
- w.current = n;
95
- const N = y(async () => {
96
- const r = w.current;
93
+ const v = k(t);
94
+ v.current = t;
95
+ const R = f(async () => {
96
+ const r = v.current;
97
97
  if (!r.isPlaying || r.isRendering)
98
98
  return;
99
- const t = performance.now();
99
+ const n = performance.now();
100
100
  if (!p.current) {
101
- const d = r.currentFrame >= 0 && s[r.currentFrame]?.startTime || 0;
102
- p.current = t - d;
101
+ const y = r.currentFrame >= 0 && c[r.currentFrame]?.startTime || 0;
102
+ p.current = n - y;
103
103
  }
104
- const l = t - p.current, { currentFrame: h } = r, T = h + 1;
105
- if (h >= s.length - 1) {
104
+ const l = n - p.current, { currentFrame: h } = r, T = h + 1;
105
+ if (h >= c.length - 1) {
106
106
  if (m("onComplete"), e.repeat) {
107
- p.current = t, u({ type: "reset", payload: { currentTime: 0, currentFrame: -1 } });
107
+ p.current = n, u({ type: "reset", payload: { currentTime: 0, currentFrame: -1 } });
108
108
  return;
109
109
  }
110
- const d = {
110
+ const y = {
111
111
  currentTime: g,
112
- currentFrame: s.length - 1,
112
+ currentFrame: c.length - 1,
113
113
  requireReset: !0,
114
114
  isStarted: !1
115
115
  };
116
- u({ type: "pause", payload: d }), p.current = null;
116
+ u({ type: "pause", payload: y }), p.current = null;
117
117
  return;
118
118
  }
119
- const x = s[T];
120
- if (!x) {
121
- n.isPlaying && (f.current = requestAnimationFrame(N));
119
+ const w = c[T];
120
+ if (!w) {
121
+ t.isPlaying && (d.current = requestAnimationFrame(R));
122
122
  return;
123
123
  }
124
- const B = x.startTime || 0;
124
+ const B = w.startTime || 0;
125
125
  if (l >= B) {
126
126
  u({
127
127
  type: "tickStart",
@@ -132,75 +132,76 @@ function K({ ...E }) {
132
132
  });
133
133
  try {
134
134
  await C(T);
135
- const d = {
135
+ const y = {
136
136
  currentTime: B,
137
137
  currentFrame: T
138
138
  };
139
- r.requireReset && (d.requireReset = !1), u({ type: "tickEnd", payload: d }), m("onTick");
140
- } catch (d) {
141
- console.error("Frame rendering error:", d);
139
+ r.requireReset && (y.requireReset = !1), u({ type: "tickEnd", payload: y }), m("onTick");
140
+ } catch (y) {
141
+ console.error("Frame rendering error:", y);
142
142
  }
143
143
  } else
144
144
  u({ type: "tick", payload: { currentTime: l } });
145
- }, [s, C, m, e.repeat, g]);
145
+ }, [c, C, m, e.repeat, g]);
146
146
  return A(() => {
147
147
  let r = !0;
148
- const t = async () => {
149
- for (; r && w.current.isPlaying; )
148
+ const n = async () => {
149
+ for (; r && v.current.isPlaying; )
150
150
  await new Promise((l) => {
151
- f.current = requestAnimationFrame(l);
152
- }), r && w.current.isPlaying && await N();
151
+ d.current = requestAnimationFrame(l);
152
+ }), r && v.current.isPlaying && await R();
153
153
  };
154
- return n.isPlaying ? t() : (f.current && (cancelAnimationFrame(f.current), f.current = null), p.current = null), () => {
155
- r = !1, f.current && (cancelAnimationFrame(f.current), f.current = null);
154
+ return t.isPlaying ? n() : (d.current && (cancelAnimationFrame(d.current), d.current = null), p.current = null), () => {
155
+ r = !1, d.current && (cancelAnimationFrame(d.current), d.current = null);
156
156
  };
157
- }, [n.isPlaying, N]), e.controls && (e.frameBox.title = null, e.frameBox.type = null, e.frameBox.style = {}, e.theme?.background === "transparent" ? e.frameBox.style.background = "black" : e.theme?.background && (e.frameBox.style.background = e.theme.background), e.frameBox.style.padding = "10px", e.frameBox.style.paddingBottom = "40px"), /* @__PURE__ */ k(H, { className: X(e, n), ref: z, children: [
158
- /* @__PURE__ */ a("div", { className: "cover", onClick: P }),
159
- /* @__PURE__ */ a("div", { className: "start", onClick: P, children: /* @__PURE__ */ k("svg", { style: { enableBackground: "new 0 0 30 30" }, viewBox: "0 0 30 30", children: [
157
+ }, [t.isPlaying, R]), e.controls && (e.frameBox.title = null, e.frameBox.type = null, e.frameBox.style = {}, e.theme?.background === "transparent" ? e.frameBox.style.background = "black" : e.theme?.background && (e.frameBox.style.background = e.theme.background), e.frameBox.style.padding = "10px", e.frameBox.style.paddingBottom = "40px"), /* @__PURE__ */ F(Y, { className: $(e, t), ref: J, children: [
158
+ /* @__PURE__ */ a("div", { className: "cover", onClick: b }),
159
+ /* @__PURE__ */ a("div", { className: "start", onClick: b, children: /* @__PURE__ */ F("svg", { style: { enableBackground: "new 0 0 30 30" }, viewBox: "0 0 30 30", children: [
160
160
  /* @__PURE__ */ a("polygon", { points: "6.583,3.186 5,4.004 5,15 26,15 26.483,14.128 " }),
161
161
  /* @__PURE__ */ a("polygon", { points: "6.583,26.814 5,25.996 5,15 26,15 26.483,15.872 " }),
162
162
  /* @__PURE__ */ a("circle", { cx: "26", cy: "15", r: "1" }),
163
163
  /* @__PURE__ */ a("circle", { cx: "6", cy: "4", r: "1" }),
164
164
  /* @__PURE__ */ a("circle", { cx: "6", cy: "26", r: "1" })
165
165
  ] }) }),
166
- /* @__PURE__ */ a("div", { className: "terminal", children: /* @__PURE__ */ k("div", { className: $(e), style: e.frameBox.style || {}, children: [
167
- /* @__PURE__ */ k("div", { className: "terminal-titlebar", children: [
168
- /* @__PURE__ */ k("div", { className: "buttons", children: [
166
+ /* @__PURE__ */ a("div", { className: "terminal", children: /* @__PURE__ */ F("div", { className: G(e), style: e.frameBox.style || {}, children: [
167
+ /* @__PURE__ */ F("div", { className: "terminal-titlebar", children: [
168
+ /* @__PURE__ */ F("div", { className: "buttons", children: [
169
169
  /* @__PURE__ */ a("div", { className: "close-button" }),
170
170
  /* @__PURE__ */ a("div", { className: "minimize-button" }),
171
171
  /* @__PURE__ */ a("div", { className: "maximize-button" })
172
172
  ] }),
173
173
  /* @__PURE__ */ a("div", { className: "title", children: e.frameBox.title || "" })
174
174
  ] }),
175
- /* @__PURE__ */ a("div", { className: "terminal-body", children: /* @__PURE__ */ a(I, { ref: o, options: D }) })
175
+ /* @__PURE__ */ a("div", { className: "terminal-body", children: /* @__PURE__ */ a(H, { ref: i, options: D }) })
176
176
  ] }) }),
177
- /* @__PURE__ */ k("div", { className: "controller", children: [
178
- n.isPlaying && /* @__PURE__ */ a("div", { className: "pause", onClick: M, title: "Pause", children: /* @__PURE__ */ a("span", { className: "icon" }) }),
179
- !n.isPlaying && !n.isStarted && /* @__PURE__ */ a("div", { className: "play", onClick: P, title: "Start", children: /* @__PURE__ */ a("span", { className: "icon" }) }),
180
- /* @__PURE__ */ a("div", { className: "timer", children: G(n.currentTime) }),
181
- /* @__PURE__ */ a("div", { className: "progressbar-wrapper", children: /* @__PURE__ */ a("div", { className: "progressbar", ref: v, onClick: L, children: /* @__PURE__ */ a("div", { className: "progress", style: { width: `${n.currentTime / g * 100}%` } }) }) })
177
+ /* @__PURE__ */ F("div", { className: "controller", children: [
178
+ !t.isPlaying && t.isStarted && /* @__PURE__ */ a("div", { className: "play", onClick: M, title: "Play", children: /* @__PURE__ */ a("span", { className: "icon" }) }),
179
+ t.isPlaying && /* @__PURE__ */ a("div", { className: "pause", onClick: O, title: "Pause", children: /* @__PURE__ */ a("span", { className: "icon" }) }),
180
+ !t.isPlaying && !t.isStarted && /* @__PURE__ */ a("div", { className: "play", onClick: b, title: "Start", children: /* @__PURE__ */ a("span", { className: "icon" }) }),
181
+ /* @__PURE__ */ a("div", { className: "timer", children: K(t.currentTime) }),
182
+ /* @__PURE__ */ a("div", { className: "progressbar-wrapper", children: /* @__PURE__ */ a("div", { className: "progressbar", ref: x, onClick: L, children: /* @__PURE__ */ a("div", { className: "progress", style: { width: `${t.currentTime / g * 100}%` } }) }) })
182
183
  ] })
183
184
  ] });
184
185
  }
185
- K.propTypes = {
186
- frames: c.array.isRequired,
187
- options: c.shape({
188
- autoplay: c.bool,
189
- repeat: c.bool,
190
- controls: c.bool,
191
- frameBox: c.object,
192
- theme: c.object,
193
- cols: c.number,
194
- rows: c.number
186
+ Q.propTypes = {
187
+ frames: o.array.isRequired,
188
+ options: o.shape({
189
+ autoplay: o.bool,
190
+ repeat: o.bool,
191
+ controls: o.bool,
192
+ frameBox: o.object,
193
+ theme: o.object,
194
+ cols: o.number,
195
+ rows: o.number
195
196
  }).isRequired,
196
- onComplete: c.func,
197
- onStart: c.func,
198
- onStop: c.func,
199
- onPause: c.func,
200
- onTick: c.func,
201
- onJump: c.func
197
+ onComplete: o.func,
198
+ onStart: o.func,
199
+ onStop: o.func,
200
+ onPause: o.func,
201
+ onTick: o.func,
202
+ onJump: o.func
202
203
  };
203
204
  export {
204
- ae as PLAYER_FRAME_DELAY,
205
- K as default
205
+ ie as PLAYER_FRAME_DELAY,
206
+ Q as default
206
207
  };
package/lib/styles.js CHANGED
@@ -69,8 +69,8 @@ const r = e.div({
69
69
  "& .start svg": {
70
70
  cursor: "pointer",
71
71
  fill: "#eaeaea",
72
- width: 100,
73
- height: 100,
72
+ width: 80,
73
+ height: 80,
74
74
  left: "50%",
75
75
  marginLeft: -65,
76
76
  marginTop: -65,
@@ -79,9 +79,9 @@ const r = e.div({
79
79
  zIndex: 20,
80
80
  filter: "drop-shadow(10px 10px 15px rgba(0, 0, 0, 0.4))",
81
81
  WebkitFilter: "drop-shadow(10px 10px 15px rgba(0, 0, 0, 0.4))",
82
- opacity: 0.6,
82
+ opacity: 0.7,
83
83
  "&:hover": {
84
- opacity: 0.8,
84
+ opacity: 0.9,
85
85
  transition: "all 0.3s ease"
86
86
  }
87
87
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/terminal",
3
- "version": "3.1.19",
3
+ "version": "3.1.21",
4
4
  "description": "A react wrapper for xterm allowing you to easily render a terminal in the browser",
5
5
  "keywords": [
6
6
  "react",
@@ -40,10 +40,10 @@
40
40
  "peerDependencies": {
41
41
  "react": "^19.0.0"
42
42
  },
43
- "gitHead": "49860d0bd0bb548087dcc6f49892fd4a88729d98",
43
+ "gitHead": "dedb6d83f569480ca7840679ef32fb863d4042e1",
44
44
  "dependencies": {
45
- "@arcblock/react-hooks": "3.1.19",
46
- "@arcblock/ux": "3.1.19",
45
+ "@arcblock/react-hooks": "3.1.21",
46
+ "@arcblock/ux": "3.1.21",
47
47
  "@emotion/react": "^11.14.0",
48
48
  "@emotion/styled": "^11.14.0",
49
49
  "@xterm/addon-fit": "^0.10.0",
package/src/Player.jsx CHANGED
@@ -187,6 +187,28 @@ export default function Player({ ...rawProps }) {
187
187
  [state.isStarted, state.isPlaying, totalDuration, frames, doJump, emitEvent]
188
188
  );
189
189
 
190
+ const onPlay = useCallback(() => {
191
+ if (state.currentFrame >= frames.length - 1) {
192
+ // 触发一下 resize,保证文字输出正常
193
+ terminal.current.resize();
194
+ // Reset to beginning if at the end
195
+ dispatch({ type: 'reset', payload: { currentFrame: -1, currentTime: 0 } });
196
+ if (terminal.current) {
197
+ terminal.current.reset();
198
+ }
199
+ startTimeRef.current = null;
200
+ // Start from beginning
201
+ dispatch({ type: 'play', payload: { currentFrame: -1, currentTime: 0 } });
202
+ } else {
203
+ // Continue from current position
204
+ startTimeRef.current = null; // Reset timing for accurate playback
205
+ dispatch({ type: 'play' });
206
+ }
207
+
208
+ emitEvent('onPlay');
209
+ return false;
210
+ }, [state.currentFrame, frames.length, emitEvent]);
211
+
190
212
  const onStart = useCallback(() => {
191
213
  if (state.isStarted === false) {
192
214
  // 触发一下 resize,保证文字输出正常
@@ -405,6 +427,11 @@ export default function Player({ ...rawProps }) {
405
427
  </div>
406
428
  </div>
407
429
  <div className="controller">
430
+ {!state.isPlaying && state.isStarted && (
431
+ <div className="play" onClick={onPlay} title="Play">
432
+ <span className="icon" />
433
+ </div>
434
+ )}
408
435
  {state.isPlaying && (
409
436
  <div className="pause" onClick={onPause} title="Pause">
410
437
  <span className="icon" />
package/src/styles.js CHANGED
@@ -87,8 +87,8 @@ export const PlayerRoot = styled.div({
87
87
  '& .start svg': {
88
88
  cursor: 'pointer',
89
89
  fill: '#eaeaea',
90
- width: 100,
91
- height: 100,
90
+ width: 80,
91
+ height: 80,
92
92
  left: '50%',
93
93
  marginLeft: -65,
94
94
  marginTop: -65,
@@ -98,9 +98,9 @@ export const PlayerRoot = styled.div({
98
98
  zIndex: 20,
99
99
  filter: 'drop-shadow(10px 10px 15px rgba(0, 0, 0, 0.4))',
100
100
  WebkitFilter: 'drop-shadow(10px 10px 15px rgba(0, 0, 0, 0.4))',
101
- opacity: 0.6,
101
+ opacity: 0.7,
102
102
  '&:hover': {
103
- opacity: 0.8,
103
+ opacity: 0.9,
104
104
  transition: 'all 0.3s ease',
105
105
  },
106
106
  },