@arcblock/terminal 3.1.25 → 3.1.26
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 +151 -141
- package/lib/styles.js +368 -118
- package/lib/util.js +27 -22
- package/package.json +4 -4
- package/src/Player.jsx +38 -10
- package/src/styles.js +366 -140
- package/src/util.js +3 -0
package/lib/Player.js
CHANGED
|
@@ -1,223 +1,233 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { jsxs as g, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as h, useReducer as H, useCallback as d, useEffect as q } from "react";
|
|
3
|
+
import c from "prop-types";
|
|
4
|
+
import S from "lodash/isUndefined";
|
|
5
5
|
import P from "lodash/noop";
|
|
6
6
|
import Y from "./Terminal.js";
|
|
7
7
|
import { PlayerRoot as _ } from "./styles.js";
|
|
8
|
-
import { defaultOptions as U, formatFrames as X, defaultState as $, findFrameAt as
|
|
8
|
+
import { defaultOptions as U, formatFrames as X, defaultState as $, findFrameAt as z, getPlayerClass as G, getFrameClass as K, formatTime as Q } from "./util.js";
|
|
9
9
|
const se = 8;
|
|
10
|
-
function V({ ...
|
|
11
|
-
const s = Object.assign({},
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
cols:
|
|
15
|
-
rows:
|
|
16
|
-
cursorStyle:
|
|
17
|
-
cursorBlink:
|
|
18
|
-
fontFamily:
|
|
19
|
-
fontSize:
|
|
20
|
-
lineHeight:
|
|
21
|
-
letterSpacing:
|
|
10
|
+
function V({ ...J }) {
|
|
11
|
+
const s = Object.assign({}, J);
|
|
12
|
+
S(s.onComplete) && (s.onComplete = P), S(s.onStart) && (s.onStart = P), S(s.onStop) && (s.onStop = P), S(s.onPause) && (s.onPause = P), S(s.onTick) && (s.onTick = P), S(s.onJump) && (s.onJump = P);
|
|
13
|
+
const e = Object.assign({}, U, s.options), { frames: o, totalDuration: v } = X(s.frames, e), I = {
|
|
14
|
+
cols: e.cols,
|
|
15
|
+
rows: e.rows,
|
|
16
|
+
cursorStyle: e.cursorStyle,
|
|
17
|
+
cursorBlink: e.cursorBlink ?? !0,
|
|
18
|
+
fontFamily: e.fontFamily,
|
|
19
|
+
fontSize: e.fontSize,
|
|
20
|
+
lineHeight: e.lineHeight,
|
|
21
|
+
letterSpacing: e.letterSpacing,
|
|
22
22
|
allowTransparency: !0,
|
|
23
23
|
scrollback: 0,
|
|
24
|
-
theme:
|
|
25
|
-
},
|
|
26
|
-
switch (
|
|
24
|
+
theme: e.enableTheme ? e.theme : {}
|
|
25
|
+
}, O = (r, a) => {
|
|
26
|
+
switch (a.type) {
|
|
27
27
|
case "jump":
|
|
28
|
-
return { ...
|
|
28
|
+
return { ...r, ...a.payload };
|
|
29
29
|
case "start":
|
|
30
|
-
return { ...
|
|
30
|
+
return { ...r, isStarted: !0, lastTickTime: Date.now() };
|
|
31
31
|
case "play":
|
|
32
|
-
return { ...
|
|
32
|
+
return { ...r, isPlaying: !0, lastTickTime: Date.now(), ...a.payload };
|
|
33
33
|
case "pause":
|
|
34
|
-
return { ...
|
|
34
|
+
return { ...r, isPlaying: !1, ...a.payload };
|
|
35
35
|
case "tickStart":
|
|
36
|
-
return { ...
|
|
36
|
+
return { ...r, isRendering: !0, lastTickTime: Date.now(), ...a.payload };
|
|
37
37
|
case "tickEnd":
|
|
38
|
-
return { ...
|
|
38
|
+
return { ...r, isRendering: !1, lastTickTime: Date.now(), ...a.payload };
|
|
39
39
|
case "reset":
|
|
40
|
-
return { ...
|
|
40
|
+
return { ...r, currentFrame: -1, currentTime: 0, ...a.payload };
|
|
41
41
|
default:
|
|
42
|
-
return { ...
|
|
42
|
+
return { ...r, lastTickTime: Date.now(), ...a.payload };
|
|
43
43
|
}
|
|
44
|
-
}, i =
|
|
45
|
-
(
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})) :
|
|
44
|
+
}, i = h(null), w = h(null), F = h(null), f = h(null), p = h(null), A = h(!1), [n, u] = H(O, $), j = d(
|
|
45
|
+
(r) => new Promise((a) => {
|
|
46
|
+
const l = o[r];
|
|
47
|
+
l && l.content && i.current ? (n.requireReset && i.current.reset(), i.current.write(l.content, () => {
|
|
48
|
+
a();
|
|
49
|
+
})) : a();
|
|
50
50
|
}),
|
|
51
|
-
[
|
|
52
|
-
), E =
|
|
53
|
-
(
|
|
54
|
-
const
|
|
55
|
-
|
|
51
|
+
[o, n.requireReset]
|
|
52
|
+
), E = d(
|
|
53
|
+
(r) => {
|
|
54
|
+
const a = o[r];
|
|
55
|
+
a && a.content && i.current && (n.requireReset && i.current.reset(), i.current.write(a.content));
|
|
56
56
|
},
|
|
57
|
-
[
|
|
58
|
-
), m =
|
|
59
|
-
(
|
|
60
|
-
typeof s[
|
|
57
|
+
[o, n.requireReset]
|
|
58
|
+
), m = d(
|
|
59
|
+
(r) => {
|
|
60
|
+
typeof s[r] == "function" && s[r]({ state: n, frames: o, options: e });
|
|
61
61
|
},
|
|
62
|
-
[s,
|
|
63
|
-
), R =
|
|
64
|
-
(
|
|
62
|
+
[s, n, o, e]
|
|
63
|
+
), R = d(
|
|
64
|
+
(r) => {
|
|
65
65
|
if (!i.current) return;
|
|
66
66
|
i.current.reset();
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
for (let
|
|
70
|
-
E(
|
|
67
|
+
const a = z(o, r);
|
|
68
|
+
if (a >= 0)
|
|
69
|
+
for (let l = 0; l <= a; l++)
|
|
70
|
+
E(l);
|
|
71
71
|
},
|
|
72
|
-
[
|
|
73
|
-
),
|
|
74
|
-
(
|
|
75
|
-
if (!
|
|
72
|
+
[o, E]
|
|
73
|
+
), L = d(
|
|
74
|
+
(r) => {
|
|
75
|
+
if (!w.current || !i.current || !n.isStarted)
|
|
76
76
|
return !1;
|
|
77
|
-
const
|
|
77
|
+
const a = w.current.getBoundingClientRect().width, l = r.nativeEvent.offsetX, T = Math.floor(v * l / a), b = z(o, T), N = n.isPlaying;
|
|
78
78
|
return u({
|
|
79
79
|
type: "jump",
|
|
80
80
|
payload: {
|
|
81
81
|
currentTime: T,
|
|
82
82
|
currentFrame: b,
|
|
83
|
-
isPlaying:
|
|
83
|
+
isPlaying: N
|
|
84
84
|
// Keep the same playing state
|
|
85
85
|
}
|
|
86
86
|
}), p.current = null, R(T), m("onJump"), !1;
|
|
87
87
|
},
|
|
88
|
-
[
|
|
89
|
-
),
|
|
88
|
+
[n.isStarted, n.isPlaying, v, o, R, m]
|
|
89
|
+
), M = d(() => (n.currentFrame >= o.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), [n.currentFrame, o.length, m]), k = d(() => (n.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), [n.isStarted, m]), D = d(() => (u({ type: "pause" }), m("onPause"), !1), [m]);
|
|
90
90
|
q(() => {
|
|
91
|
-
if (!
|
|
91
|
+
if (!F.current || !e.autoplay || A.current)
|
|
92
92
|
return;
|
|
93
|
-
const
|
|
94
|
-
(
|
|
95
|
-
const [
|
|
96
|
-
|
|
93
|
+
const r = new IntersectionObserver(
|
|
94
|
+
(a) => {
|
|
95
|
+
const [l] = a;
|
|
96
|
+
l.isIntersecting && !n.isStarted && (k(), A.current = !0, r.unobserve(F.current), r.disconnect());
|
|
97
97
|
},
|
|
98
98
|
{
|
|
99
|
-
threshold:
|
|
100
|
-
//
|
|
101
|
-
rootMargin:
|
|
102
|
-
//
|
|
99
|
+
threshold: e.autoplayThreshold,
|
|
100
|
+
// 可配置的可见度阈值
|
|
101
|
+
rootMargin: e.autoplayRootMargin
|
|
102
|
+
// 可配置的根边距
|
|
103
103
|
}
|
|
104
104
|
);
|
|
105
|
-
return
|
|
106
|
-
|
|
105
|
+
return r.observe(F.current), () => {
|
|
106
|
+
r.disconnect();
|
|
107
107
|
};
|
|
108
|
-
}, [
|
|
109
|
-
i.current && (i.current.focus(),
|
|
108
|
+
}, [e.autoplay, e.autoplayThreshold, e.autoplayRootMargin, n.isStarted, k]), q(() => {
|
|
109
|
+
i.current && (i.current.focus(), e.autoplay || R(Math.min(Math.abs(e.thumbnailTime), v)));
|
|
110
110
|
}, []);
|
|
111
|
-
const x =
|
|
112
|
-
x.current =
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
if (!
|
|
111
|
+
const x = h(n);
|
|
112
|
+
x.current = n;
|
|
113
|
+
const C = d(async () => {
|
|
114
|
+
const r = x.current;
|
|
115
|
+
if (!r.isPlaying || r.isRendering)
|
|
116
116
|
return;
|
|
117
|
-
const
|
|
117
|
+
const a = performance.now();
|
|
118
118
|
if (!p.current) {
|
|
119
|
-
const y =
|
|
120
|
-
p.current =
|
|
119
|
+
const y = r.currentFrame >= 0 && o[r.currentFrame]?.startTime || 0;
|
|
120
|
+
p.current = a - y;
|
|
121
121
|
}
|
|
122
|
-
const
|
|
123
|
-
if (T >=
|
|
124
|
-
if (m("onComplete"),
|
|
125
|
-
p.current =
|
|
122
|
+
const l = a - p.current, { currentFrame: T } = r, b = T + 1;
|
|
123
|
+
if (T >= o.length - 1) {
|
|
124
|
+
if (m("onComplete"), e.repeat) {
|
|
125
|
+
p.current = a, u({ type: "reset", payload: { currentTime: 0, currentFrame: -1 } });
|
|
126
126
|
return;
|
|
127
127
|
}
|
|
128
128
|
const y = {
|
|
129
|
-
currentTime:
|
|
130
|
-
currentFrame:
|
|
129
|
+
currentTime: v,
|
|
130
|
+
currentFrame: o.length - 1,
|
|
131
131
|
requireReset: !0,
|
|
132
132
|
isStarted: !1
|
|
133
133
|
};
|
|
134
134
|
u({ type: "pause", payload: y }), p.current = null;
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
|
-
const
|
|
138
|
-
if (!
|
|
139
|
-
|
|
137
|
+
const N = o[b];
|
|
138
|
+
if (!N) {
|
|
139
|
+
n.isPlaying && (f.current = requestAnimationFrame(C));
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
|
-
const
|
|
143
|
-
if (
|
|
142
|
+
const B = N.startTime || 0;
|
|
143
|
+
if (l >= B) {
|
|
144
144
|
u({
|
|
145
145
|
type: "tickStart",
|
|
146
146
|
payload: {
|
|
147
|
-
currentTime:
|
|
147
|
+
currentTime: B,
|
|
148
148
|
currentFrame: b
|
|
149
149
|
}
|
|
150
150
|
});
|
|
151
151
|
try {
|
|
152
152
|
await j(b);
|
|
153
153
|
const y = {
|
|
154
|
-
currentTime:
|
|
154
|
+
currentTime: B,
|
|
155
155
|
currentFrame: b
|
|
156
156
|
};
|
|
157
|
-
|
|
157
|
+
r.requireReset && (y.requireReset = !1), u({ type: "tickEnd", payload: y }), m("onTick");
|
|
158
158
|
} catch (y) {
|
|
159
159
|
console.error("Frame rendering error:", y);
|
|
160
160
|
}
|
|
161
161
|
} else
|
|
162
|
-
u({ type: "tick", payload: { currentTime:
|
|
163
|
-
}, [
|
|
162
|
+
u({ type: "tick", payload: { currentTime: l } });
|
|
163
|
+
}, [o, j, m, e.repeat, v]);
|
|
164
164
|
return q(() => {
|
|
165
|
-
let
|
|
166
|
-
const
|
|
167
|
-
for (;
|
|
168
|
-
await new Promise((
|
|
169
|
-
|
|
170
|
-
}),
|
|
165
|
+
let r = !0;
|
|
166
|
+
const a = async () => {
|
|
167
|
+
for (; r && x.current.isPlaying; )
|
|
168
|
+
await new Promise((l) => {
|
|
169
|
+
f.current = requestAnimationFrame(l);
|
|
170
|
+
}), r && x.current.isPlaying && await C();
|
|
171
171
|
};
|
|
172
|
-
return
|
|
173
|
-
|
|
172
|
+
return n.isPlaying ? a() : (f.current && (cancelAnimationFrame(f.current), f.current = null), p.current = null), () => {
|
|
173
|
+
r = !1, f.current && (cancelAnimationFrame(f.current), f.current = null);
|
|
174
174
|
};
|
|
175
|
-
}, [
|
|
176
|
-
/* @__PURE__ */
|
|
177
|
-
/* @__PURE__ */
|
|
178
|
-
/* @__PURE__ */
|
|
179
|
-
/* @__PURE__ */
|
|
180
|
-
/* @__PURE__ */
|
|
181
|
-
/* @__PURE__ */
|
|
182
|
-
/* @__PURE__ */
|
|
183
|
-
] }) }),
|
|
184
|
-
/* @__PURE__ */
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
175
|
+
}, [n.isPlaying, C]), 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__ */ g(_, { className: G(e, n), ref: F, children: [
|
|
176
|
+
/* @__PURE__ */ t("div", { className: "cover", onClick: k }),
|
|
177
|
+
/* @__PURE__ */ t("div", { className: "start", onClick: k, children: /* @__PURE__ */ t("div", { className: "start-button", children: /* @__PURE__ */ g("svg", { viewBox: "0 0 30 30", children: [
|
|
178
|
+
/* @__PURE__ */ t("polygon", { points: "6.583,3.186 5,4.004 5,15 26,15 26.483,14.128 " }),
|
|
179
|
+
/* @__PURE__ */ t("polygon", { points: "6.583,26.814 5,25.996 5,15 26,15 26.483,15.872 " }),
|
|
180
|
+
/* @__PURE__ */ t("circle", { cx: "26", cy: "15", r: "1" }),
|
|
181
|
+
/* @__PURE__ */ t("circle", { cx: "6", cy: "4", r: "1" }),
|
|
182
|
+
/* @__PURE__ */ t("circle", { cx: "6", cy: "26", r: "1" })
|
|
183
|
+
] }) }) }),
|
|
184
|
+
n.isPlaying && n.isStarted && /* @__PURE__ */ t("div", { className: "hover-overlay", onClick: D, children: /* @__PURE__ */ t("div", { className: "hover-pause-button", children: /* @__PURE__ */ t("span", { className: "pause-icon" }) }) }),
|
|
185
|
+
!n.isPlaying && n.isStarted && /* @__PURE__ */ t("div", { className: "pause-overlay", onClick: M, children: /* @__PURE__ */ t("div", { className: "overlay-play-button", children: /* @__PURE__ */ g("svg", { viewBox: "0 0 30 30", children: [
|
|
186
|
+
/* @__PURE__ */ t("polygon", { points: "6.583,3.186 5,4.004 5,15 26,15 26.483,14.128 " }),
|
|
187
|
+
/* @__PURE__ */ t("polygon", { points: "6.583,26.814 5,25.996 5,15 26,15 26.483,15.872 " }),
|
|
188
|
+
/* @__PURE__ */ t("circle", { cx: "26", cy: "15", r: "1" }),
|
|
189
|
+
/* @__PURE__ */ t("circle", { cx: "6", cy: "4", r: "1" }),
|
|
190
|
+
/* @__PURE__ */ t("circle", { cx: "6", cy: "26", r: "1" })
|
|
191
|
+
] }) }) }),
|
|
192
|
+
/* @__PURE__ */ t("div", { className: "terminal", children: /* @__PURE__ */ g("div", { className: K(e), style: e.frameBox.style || {}, children: [
|
|
193
|
+
/* @__PURE__ */ g("div", { className: "terminal-titlebar", children: [
|
|
194
|
+
/* @__PURE__ */ g("div", { className: "buttons", children: [
|
|
195
|
+
/* @__PURE__ */ t("div", { className: "close-button" }),
|
|
196
|
+
/* @__PURE__ */ t("div", { className: "minimize-button" }),
|
|
197
|
+
/* @__PURE__ */ t("div", { className: "maximize-button" })
|
|
190
198
|
] }),
|
|
191
|
-
/* @__PURE__ */
|
|
199
|
+
/* @__PURE__ */ t("div", { className: "title", children: e.frameBox.title || "" })
|
|
192
200
|
] }),
|
|
193
|
-
/* @__PURE__ */
|
|
201
|
+
/* @__PURE__ */ t("div", { className: "terminal-body", children: /* @__PURE__ */ t(Y, { ref: i, options: I }) })
|
|
194
202
|
] }) }),
|
|
195
|
-
/* @__PURE__ */
|
|
196
|
-
!
|
|
197
|
-
|
|
198
|
-
!
|
|
199
|
-
/* @__PURE__ */
|
|
200
|
-
/* @__PURE__ */
|
|
203
|
+
/* @__PURE__ */ g("div", { className: "controller", children: [
|
|
204
|
+
!n.isPlaying && n.isStarted && /* @__PURE__ */ t("div", { className: "play", onClick: M, title: "Play", children: /* @__PURE__ */ t("span", { className: "icon" }) }),
|
|
205
|
+
n.isPlaying && /* @__PURE__ */ t("div", { className: "pause", onClick: D, title: "Pause", children: /* @__PURE__ */ t("span", { className: "icon" }) }),
|
|
206
|
+
!n.isPlaying && !n.isStarted && /* @__PURE__ */ t("div", { className: "play", onClick: k, title: "Start", children: /* @__PURE__ */ t("span", { className: "icon" }) }),
|
|
207
|
+
/* @__PURE__ */ t("div", { className: "timer", children: Q(n.currentTime) }),
|
|
208
|
+
/* @__PURE__ */ t("div", { className: "progressbar-wrapper", children: /* @__PURE__ */ t("div", { className: "progressbar", ref: w, onClick: L, children: /* @__PURE__ */ t("div", { className: "progress", style: { width: `${n.currentTime / v * 100}%` } }) }) })
|
|
201
209
|
] })
|
|
202
210
|
] });
|
|
203
211
|
}
|
|
204
212
|
V.propTypes = {
|
|
205
|
-
frames:
|
|
206
|
-
options:
|
|
207
|
-
autoplay:
|
|
208
|
-
repeat:
|
|
209
|
-
controls:
|
|
210
|
-
frameBox:
|
|
211
|
-
theme:
|
|
212
|
-
cols:
|
|
213
|
-
rows:
|
|
213
|
+
frames: c.array.isRequired,
|
|
214
|
+
options: c.shape({
|
|
215
|
+
autoplay: c.bool,
|
|
216
|
+
repeat: c.bool,
|
|
217
|
+
controls: c.bool,
|
|
218
|
+
frameBox: c.object,
|
|
219
|
+
theme: c.object,
|
|
220
|
+
cols: c.number,
|
|
221
|
+
rows: c.number,
|
|
222
|
+
autoplayThreshold: c.number,
|
|
223
|
+
autoplayRootMargin: c.string
|
|
214
224
|
}).isRequired,
|
|
215
|
-
onComplete:
|
|
216
|
-
onStart:
|
|
217
|
-
onStop:
|
|
218
|
-
onPause:
|
|
219
|
-
onTick:
|
|
220
|
-
onJump:
|
|
225
|
+
onComplete: c.func,
|
|
226
|
+
onStart: c.func,
|
|
227
|
+
onStop: c.func,
|
|
228
|
+
onPause: c.func,
|
|
229
|
+
onTick: c.func,
|
|
230
|
+
onJump: c.func
|
|
221
231
|
};
|
|
222
232
|
export {
|
|
223
233
|
se as PLAYER_FRAME_DELAY,
|