@bitcobblers/wod-wiki-lang 0.60.2250 → 0.60.2257
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/dist/index.cjs +78 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +78 -32
- package/dist/index.mjs.map +1 -1
- package/dist/react.cjs +62 -35
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -18
- package/dist/react.d.ts +1 -18
- package/dist/react.mjs +62 -35
- package/dist/react.mjs.map +1 -1
- package/package.json +2 -2
package/dist/react.cjs
CHANGED
|
@@ -36,18 +36,36 @@ var useRuntimeExecution = (runtime) => {
|
|
|
36
36
|
const [stepCount, setStepCount] = react.useState(0);
|
|
37
37
|
const [startTime, setStartTime] = react.useState(null);
|
|
38
38
|
const intervalRef = react.useRef(null);
|
|
39
|
-
const
|
|
39
|
+
const statusRef = react.useRef("idle");
|
|
40
|
+
const accumulatedElapsedRef = react.useRef(0);
|
|
41
|
+
const segmentStartRef = react.useRef(null);
|
|
42
|
+
const hasStartTimeRef = react.useRef(false);
|
|
43
|
+
const readNowMs = react.useCallback(
|
|
44
|
+
() => runtime?.nowProvider?.nowMs() ?? wallClockNow.nowMs(),
|
|
45
|
+
[runtime]
|
|
46
|
+
);
|
|
47
|
+
const readNowDate = react.useCallback(
|
|
48
|
+
() => runtime?.nowProvider?.now() ?? wallClockNow.now(),
|
|
49
|
+
[runtime]
|
|
50
|
+
);
|
|
51
|
+
const getElapsedTime = react.useCallback(() => {
|
|
52
|
+
if (statusRef.current === "running" && segmentStartRef.current !== null) {
|
|
53
|
+
return accumulatedElapsedRef.current + Math.max(0, readNowMs() - segmentStartRef.current);
|
|
54
|
+
}
|
|
55
|
+
return accumulatedElapsedRef.current;
|
|
56
|
+
}, [readNowMs]);
|
|
40
57
|
const stop = react.useCallback(() => {
|
|
41
58
|
if (intervalRef.current) {
|
|
42
59
|
clearInterval(intervalRef.current);
|
|
43
60
|
intervalRef.current = null;
|
|
44
61
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
const finalElapsed = getElapsedTime();
|
|
63
|
+
accumulatedElapsedRef.current = finalElapsed;
|
|
64
|
+
segmentStartRef.current = null;
|
|
65
|
+
statusRef.current = "idle";
|
|
66
|
+
setElapsedTime(finalElapsed);
|
|
49
67
|
setStatus("idle");
|
|
50
|
-
}, [
|
|
68
|
+
}, [getElapsedTime]);
|
|
51
69
|
const executeStep = react.useCallback(() => {
|
|
52
70
|
if (!runtime) return;
|
|
53
71
|
try {
|
|
@@ -56,26 +74,28 @@ var useRuntimeExecution = (runtime) => {
|
|
|
56
74
|
setStepCount((prev) => prev + 1);
|
|
57
75
|
} catch {
|
|
58
76
|
stop();
|
|
77
|
+
statusRef.current = "error";
|
|
59
78
|
setStatus("error");
|
|
60
79
|
}
|
|
61
80
|
}, [runtime, stop]);
|
|
62
81
|
react.useEffect(() => {
|
|
63
82
|
if (!runtime) return;
|
|
64
83
|
const unsubscribe = runtime.subscribeToStack((snapshot) => {
|
|
65
|
-
if (snapshot.blocks.length === 0 &&
|
|
84
|
+
if (snapshot.blocks.length === 0 && statusRef.current !== "completed") {
|
|
66
85
|
if (intervalRef.current) {
|
|
67
86
|
clearInterval(intervalRef.current);
|
|
68
87
|
intervalRef.current = null;
|
|
69
88
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
89
|
+
const finalElapsed = getElapsedTime();
|
|
90
|
+
accumulatedElapsedRef.current = finalElapsed;
|
|
91
|
+
segmentStartRef.current = null;
|
|
92
|
+
statusRef.current = "completed";
|
|
93
|
+
setElapsedTime(finalElapsed);
|
|
74
94
|
setStatus("completed");
|
|
75
95
|
}
|
|
76
96
|
});
|
|
77
97
|
return unsubscribe;
|
|
78
|
-
}, [runtime,
|
|
98
|
+
}, [runtime, getElapsedTime]);
|
|
79
99
|
react.useEffect(() => {
|
|
80
100
|
return () => {
|
|
81
101
|
if (intervalRef.current) {
|
|
@@ -89,69 +109,75 @@ var useRuntimeExecution = (runtime) => {
|
|
|
89
109
|
console.warn("useRuntimeExecution: Cannot start execution without a runtime");
|
|
90
110
|
return;
|
|
91
111
|
}
|
|
92
|
-
if (
|
|
112
|
+
if (statusRef.current === "running") {
|
|
93
113
|
console.warn("useRuntimeExecution: Runtime is already running");
|
|
94
114
|
return;
|
|
95
115
|
}
|
|
96
|
-
if (
|
|
116
|
+
if (statusRef.current === "paused") {
|
|
97
117
|
runtime.handle({
|
|
98
118
|
name: "timer:resume",
|
|
99
|
-
timestamp:
|
|
119
|
+
timestamp: readNowDate(),
|
|
100
120
|
data: {}
|
|
101
121
|
});
|
|
102
122
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
123
|
+
const now = readNowMs();
|
|
124
|
+
segmentStartRef.current = now;
|
|
125
|
+
if (!hasStartTimeRef.current) {
|
|
126
|
+
hasStartTimeRef.current = true;
|
|
107
127
|
setStartTime(now);
|
|
108
128
|
}
|
|
129
|
+
statusRef.current = "running";
|
|
130
|
+
setStatus("running");
|
|
109
131
|
intervalRef.current = setInterval(executeStep, EXECUTION_TICK_RATE_MS);
|
|
110
|
-
}, [runtime,
|
|
132
|
+
}, [runtime, readNowDate, readNowMs, executeStep]);
|
|
111
133
|
const pause = react.useCallback(() => {
|
|
112
134
|
if (intervalRef.current) {
|
|
113
135
|
clearInterval(intervalRef.current);
|
|
114
136
|
intervalRef.current = null;
|
|
115
137
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
138
|
+
const pausedElapsed = getElapsedTime();
|
|
139
|
+
accumulatedElapsedRef.current = pausedElapsed;
|
|
140
|
+
segmentStartRef.current = null;
|
|
141
|
+
setElapsedTime(pausedElapsed);
|
|
120
142
|
if (runtime) {
|
|
121
|
-
const pauseDate = runtime.nowProvider?.now() ?? wallClockNow.now();
|
|
122
143
|
runtime.handle({
|
|
123
144
|
name: "timer:pause",
|
|
124
|
-
timestamp:
|
|
145
|
+
timestamp: readNowDate(),
|
|
125
146
|
data: {}
|
|
126
147
|
});
|
|
127
148
|
}
|
|
149
|
+
statusRef.current = "paused";
|
|
128
150
|
setStatus("paused");
|
|
129
|
-
}, [runtime]);
|
|
151
|
+
}, [runtime, getElapsedTime, readNowDate]);
|
|
130
152
|
const reset = react.useCallback(() => {
|
|
131
153
|
if (intervalRef.current) {
|
|
132
154
|
clearInterval(intervalRef.current);
|
|
133
155
|
intervalRef.current = null;
|
|
134
156
|
}
|
|
157
|
+
accumulatedElapsedRef.current = 0;
|
|
158
|
+
segmentStartRef.current = null;
|
|
159
|
+
hasStartTimeRef.current = false;
|
|
160
|
+
statusRef.current = "idle";
|
|
135
161
|
setElapsedTime(0);
|
|
136
162
|
setStepCount(0);
|
|
137
163
|
setStatus("idle");
|
|
138
164
|
setStartTime(null);
|
|
139
|
-
|
|
140
|
-
}, [runtime]);
|
|
165
|
+
}, []);
|
|
141
166
|
const step = react.useCallback(() => {
|
|
142
|
-
if (!runtime ||
|
|
167
|
+
if (!runtime || statusRef.current === "running") {
|
|
143
168
|
return;
|
|
144
169
|
}
|
|
170
|
+
statusRef.current = "paused";
|
|
145
171
|
setStatus("paused");
|
|
146
172
|
executeStep();
|
|
147
|
-
}, [runtime,
|
|
173
|
+
}, [runtime, executeStep]);
|
|
148
174
|
react.useEffect(() => {
|
|
149
|
-
if (status !== "running"
|
|
175
|
+
if (status !== "running") return;
|
|
150
176
|
const updateInterval = setInterval(() => {
|
|
151
|
-
setElapsedTime((
|
|
177
|
+
setElapsedTime(getElapsedTime());
|
|
152
178
|
}, 100);
|
|
153
179
|
return () => clearInterval(updateInterval);
|
|
154
|
-
}, [status,
|
|
180
|
+
}, [status, getElapsedTime]);
|
|
155
181
|
react.useEffect(() => {
|
|
156
182
|
return () => {
|
|
157
183
|
if (intervalRef.current) {
|
|
@@ -166,6 +192,7 @@ var useRuntimeExecution = (runtime) => {
|
|
|
166
192
|
return react.useMemo(() => ({
|
|
167
193
|
status,
|
|
168
194
|
elapsedTime,
|
|
195
|
+
getElapsedTime,
|
|
169
196
|
stepCount,
|
|
170
197
|
startTime,
|
|
171
198
|
start,
|
|
@@ -173,7 +200,7 @@ var useRuntimeExecution = (runtime) => {
|
|
|
173
200
|
stop,
|
|
174
201
|
reset,
|
|
175
202
|
step
|
|
176
|
-
}), [status, elapsedTime, stepCount, startTime, start, pause, stop, reset, step]);
|
|
203
|
+
}), [status, elapsedTime, getElapsedTime, stepCount, startTime, start, pause, stop, reset, step]);
|
|
177
204
|
};
|
|
178
205
|
|
|
179
206
|
// src/utils/formatTime.ts
|