@bitcobblers/wod-wiki-lang 0.53.2204 → 0.55.2206
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/{browserRuntimeNow-JnK2JvJg.d.cts → ScriptOutlineProjection-BnS5Xkgf.d.cts} +160 -1
- package/dist/{browserRuntimeNow-JnK2JvJg.d.ts → ScriptOutlineProjection-BnS5Xkgf.d.ts} +160 -1
- package/dist/chunk-XDMS3U3W.mjs +1172 -0
- package/dist/chunk-XDMS3U3W.mjs.map +1 -0
- package/dist/index.cjs +672 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.mjs +114 -537
- package/dist/index.mjs.map +1 -1
- package/dist/react.cjs +808 -37
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +33 -3
- package/dist/react.d.ts +33 -3
- package/dist/react.mjs +114 -15
- package/dist/react.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-27K5HAHU.mjs +0 -164
- package/dist/chunk-27K5HAHU.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -5336,6 +5336,15 @@ var DEFAULT_RUNTIME_OPTIONS = {
|
|
|
5336
5336
|
maxActionDepth: 20
|
|
5337
5337
|
};
|
|
5338
5338
|
|
|
5339
|
+
// src/runtime/INowProvider.ts
|
|
5340
|
+
var wallClockNow = {
|
|
5341
|
+
now: () => /* @__PURE__ */ new Date(),
|
|
5342
|
+
nowMs: () => Date.now()
|
|
5343
|
+
};
|
|
5344
|
+
function frozenNow(at) {
|
|
5345
|
+
return { now: () => at, nowMs: () => at.getTime() };
|
|
5346
|
+
}
|
|
5347
|
+
|
|
5339
5348
|
// src/runtime/models/TimeSpan.ts
|
|
5340
5349
|
var TimeSpan = class _TimeSpan {
|
|
5341
5350
|
constructor(started, ended) {
|
|
@@ -5432,12 +5441,16 @@ var SnapshotClock = class _SnapshotClock {
|
|
|
5432
5441
|
}
|
|
5433
5442
|
};
|
|
5434
5443
|
var RuntimeClock = class {
|
|
5444
|
+
constructor(_now = wallClockNow) {
|
|
5445
|
+
this._now = _now;
|
|
5446
|
+
}
|
|
5447
|
+
_now;
|
|
5435
5448
|
_spans = [];
|
|
5436
5449
|
/**
|
|
5437
|
-
* Current
|
|
5450
|
+
* Current clock time as a Date (from injected `INowProvider`, defaulting to wall clock).
|
|
5438
5451
|
*/
|
|
5439
5452
|
get currentDate() {
|
|
5440
|
-
return
|
|
5453
|
+
return this._now.now();
|
|
5441
5454
|
}
|
|
5442
5455
|
now() {
|
|
5443
5456
|
return this.currentDate;
|
|
@@ -5463,7 +5476,8 @@ var RuntimeClock = class {
|
|
|
5463
5476
|
* Sums all completed spans plus the current running span (if any).
|
|
5464
5477
|
*/
|
|
5465
5478
|
get elapsed() {
|
|
5466
|
-
|
|
5479
|
+
const currentMs = this._now.nowMs();
|
|
5480
|
+
return this._spans.reduce((total, span) => total + ((span.ended ?? currentMs) - span.started), 0);
|
|
5467
5481
|
}
|
|
5468
5482
|
/**
|
|
5469
5483
|
* Start the clock. Creates a new span with the current time.
|
|
@@ -5472,7 +5486,7 @@ var RuntimeClock = class {
|
|
|
5472
5486
|
* If the clock is already running, returns the current span's start time.
|
|
5473
5487
|
*/
|
|
5474
5488
|
start() {
|
|
5475
|
-
const now =
|
|
5489
|
+
const now = this._now.now();
|
|
5476
5490
|
if (this.isRunning) {
|
|
5477
5491
|
return this._spans[this._spans.length - 1].startDate;
|
|
5478
5492
|
}
|
|
@@ -5486,7 +5500,7 @@ var RuntimeClock = class {
|
|
|
5486
5500
|
* If the clock is not running, returns the current time.
|
|
5487
5501
|
*/
|
|
5488
5502
|
stop() {
|
|
5489
|
-
const now =
|
|
5503
|
+
const now = this._now.now();
|
|
5490
5504
|
if (!this.isRunning) {
|
|
5491
5505
|
return now;
|
|
5492
5506
|
}
|
|
@@ -5547,15 +5561,6 @@ function createMockClock(initialTime = /* @__PURE__ */ new Date()) {
|
|
|
5547
5561
|
};
|
|
5548
5562
|
}
|
|
5549
5563
|
|
|
5550
|
-
// src/runtime/INowProvider.ts
|
|
5551
|
-
var wallClockNow = {
|
|
5552
|
-
now: () => /* @__PURE__ */ new Date(),
|
|
5553
|
-
nowMs: () => Date.now()
|
|
5554
|
-
};
|
|
5555
|
-
function frozenNow(at) {
|
|
5556
|
-
return { now: () => at, nowMs: () => at.getTime() };
|
|
5557
|
-
}
|
|
5558
|
-
|
|
5559
5564
|
// src/runtime/actions/stack/NextAction.ts
|
|
5560
5565
|
var NextAction = class {
|
|
5561
5566
|
/**
|
|
@@ -6181,6 +6186,31 @@ var RuntimeLogger = new RuntimeLoggerImpl();
|
|
|
6181
6186
|
if (typeof window !== "undefined") {
|
|
6182
6187
|
window.RuntimeLogger = RuntimeLogger;
|
|
6183
6188
|
}
|
|
6189
|
+
var CurrentRoundMetric = class {
|
|
6190
|
+
/**
|
|
6191
|
+
* @param current The current round number (1-based)
|
|
6192
|
+
* @param total Total number of planned rounds (undefined for unbounded)
|
|
6193
|
+
* @param sourceBlockKey Block that owns this round counter
|
|
6194
|
+
* @param timestamp When this metrics was created
|
|
6195
|
+
* @param customImage Optional custom image string (e.g., "Completed 3 Round(s)")
|
|
6196
|
+
*/
|
|
6197
|
+
constructor(current, total, sourceBlockKey, timestamp, customImage) {
|
|
6198
|
+
this.current = current;
|
|
6199
|
+
this.total = total;
|
|
6200
|
+
this.sourceBlockKey = sourceBlockKey;
|
|
6201
|
+
this.timestamp = timestamp;
|
|
6202
|
+
this.value = current;
|
|
6203
|
+
this.image = customImage ?? (total !== void 0 ? `Round ${current} of ${total}` : `Round ${current}`);
|
|
6204
|
+
}
|
|
6205
|
+
current;
|
|
6206
|
+
total;
|
|
6207
|
+
sourceBlockKey;
|
|
6208
|
+
timestamp;
|
|
6209
|
+
type = wodWikiCore.MetricType.CurrentRound;
|
|
6210
|
+
origin = "tracked";
|
|
6211
|
+
value;
|
|
6212
|
+
image;
|
|
6213
|
+
};
|
|
6184
6214
|
var OutputEmitter = class {
|
|
6185
6215
|
_outputStatements = [];
|
|
6186
6216
|
_outputListeners = /* @__PURE__ */ new Set();
|
|
@@ -6210,6 +6240,17 @@ var OutputEmitter = class {
|
|
|
6210
6240
|
this._clock = deps.clock;
|
|
6211
6241
|
this._stack = deps.stack;
|
|
6212
6242
|
this._script = deps.script;
|
|
6243
|
+
if (this._analyticsEngine) {
|
|
6244
|
+
this._bindEngineClock(this._analyticsEngine);
|
|
6245
|
+
}
|
|
6246
|
+
}
|
|
6247
|
+
_bindEngineClock(engine) {
|
|
6248
|
+
if (!this._clock || !engine.setNowProvider) return;
|
|
6249
|
+
const clock = this._clock;
|
|
6250
|
+
engine.setNowProvider({
|
|
6251
|
+
now: () => clock.currentDate,
|
|
6252
|
+
nowMs: () => clock.currentDate.getTime()
|
|
6253
|
+
});
|
|
6213
6254
|
}
|
|
6214
6255
|
_requireClock() {
|
|
6215
6256
|
if (!this._clock) {
|
|
@@ -6274,6 +6315,7 @@ var OutputEmitter = class {
|
|
|
6274
6315
|
}
|
|
6275
6316
|
setAnalyticsEngine(engine) {
|
|
6276
6317
|
this._analyticsEngine = engine;
|
|
6318
|
+
this._bindEngineClock(engine);
|
|
6277
6319
|
engine.setLiveOutputEmitter((outputs) => this.emitLiveAnalytics(outputs));
|
|
6278
6320
|
}
|
|
6279
6321
|
/**
|
|
@@ -6326,6 +6368,11 @@ var OutputEmitter = class {
|
|
|
6326
6368
|
getLiveAnalytics() {
|
|
6327
6369
|
return [...this._liveAnalytics];
|
|
6328
6370
|
}
|
|
6371
|
+
/** Typed live Summary Metric projections directly from AnalyticsEngine. */
|
|
6372
|
+
getLiveProjections() {
|
|
6373
|
+
if (this._analyticsFinalized) return [];
|
|
6374
|
+
return this._analyticsEngine?.getLiveProjections?.() ?? [];
|
|
6375
|
+
}
|
|
6329
6376
|
dispose() {
|
|
6330
6377
|
this._outputStatements = [];
|
|
6331
6378
|
this._outputListeners.clear();
|
|
@@ -6432,6 +6479,22 @@ var OutputEmitter = class {
|
|
|
6432
6479
|
const sourceFragments = wodWikiCore.MetricContainer.from(displayLocs[i]?.metrics, block.key.toString());
|
|
6433
6480
|
const metrics = wodWikiCore.MetricContainer.empty(block.key.toString()).add(...sourceFragments.toArray()).add(...resultFragments.toArray());
|
|
6434
6481
|
if (metrics.length === 0) continue;
|
|
6482
|
+
if (!metrics.some((m) => m.type === wodWikiCore.MetricType.CurrentRound) && block.getMemoryByTag("children:status").length === 0 && block.blockType !== "SessionRoot" && block.blockType !== "Rounds") {
|
|
6483
|
+
const enclosingRoundBlock = (this._stack?.blocks ?? []).find(
|
|
6484
|
+
(ancestor2) => ancestor2.blockType !== "SessionRoot" && ancestor2.getMemoryByTag("round").length > 0
|
|
6485
|
+
);
|
|
6486
|
+
const roundState = enclosingRoundBlock?.getMemoryByTag("round")[0]?.metrics[0];
|
|
6487
|
+
if (roundState && typeof roundState.current === "number") {
|
|
6488
|
+
metrics.add(
|
|
6489
|
+
new CurrentRoundMetric(
|
|
6490
|
+
roundState.current,
|
|
6491
|
+
roundState.total,
|
|
6492
|
+
enclosingRoundBlock?.key.toString(),
|
|
6493
|
+
new Date(fallbackEndMs)
|
|
6494
|
+
)
|
|
6495
|
+
);
|
|
6496
|
+
}
|
|
6497
|
+
}
|
|
6435
6498
|
const fallbackStartMs = block.executionTiming?.startTime?.getTime() ?? fallbackEndMs;
|
|
6436
6499
|
const timeSpan = new TimeSpan(fallbackStartMs, fallbackEndMs);
|
|
6437
6500
|
this.add(new wodWikiCore.OutputStatement({
|
|
@@ -6811,6 +6874,9 @@ var ScriptRuntime = class {
|
|
|
6811
6874
|
getLiveAnalytics() {
|
|
6812
6875
|
return this._output.getLiveAnalytics();
|
|
6813
6876
|
}
|
|
6877
|
+
getLiveProjections() {
|
|
6878
|
+
return this._output.getLiveProjections();
|
|
6879
|
+
}
|
|
6814
6880
|
/**
|
|
6815
6881
|
* Add an output statement to the collection and notify subscribers.
|
|
6816
6882
|
* Used by BehaviorContext to emit outputs at any lifecycle point.
|
|
@@ -8050,7 +8116,9 @@ var CountupTimerBehavior = class {
|
|
|
8050
8116
|
direction: "up",
|
|
8051
8117
|
durationMs: void 0,
|
|
8052
8118
|
label,
|
|
8053
|
-
role
|
|
8119
|
+
role,
|
|
8120
|
+
required: false,
|
|
8121
|
+
polarity: this.config.polarity ?? "work"
|
|
8054
8122
|
})]);
|
|
8055
8123
|
this.subscriptions.push(
|
|
8056
8124
|
ctx.subscribe("timer:pause", (_event, pCtx) => {
|
|
@@ -8152,31 +8220,6 @@ function formatDuration(ms) {
|
|
|
8152
8220
|
const secs = totalSeconds % 60;
|
|
8153
8221
|
return `${mins}:${secs.toString().padStart(2, "0")}`;
|
|
8154
8222
|
}
|
|
8155
|
-
var CurrentRoundMetric = class {
|
|
8156
|
-
/**
|
|
8157
|
-
* @param current The current round number (1-based)
|
|
8158
|
-
* @param total Total number of planned rounds (undefined for unbounded)
|
|
8159
|
-
* @param sourceBlockKey Block that owns this round counter
|
|
8160
|
-
* @param timestamp When this metrics was created
|
|
8161
|
-
* @param customImage Optional custom image string (e.g., "Completed 3 Round(s)")
|
|
8162
|
-
*/
|
|
8163
|
-
constructor(current, total, sourceBlockKey, timestamp, customImage) {
|
|
8164
|
-
this.current = current;
|
|
8165
|
-
this.total = total;
|
|
8166
|
-
this.sourceBlockKey = sourceBlockKey;
|
|
8167
|
-
this.timestamp = timestamp;
|
|
8168
|
-
this.value = current;
|
|
8169
|
-
this.image = customImage ?? (total !== void 0 ? `Round ${current} of ${total}` : `Round ${current}`);
|
|
8170
|
-
}
|
|
8171
|
-
current;
|
|
8172
|
-
total;
|
|
8173
|
-
sourceBlockKey;
|
|
8174
|
-
timestamp;
|
|
8175
|
-
type = wodWikiCore.MetricType.CurrentRound;
|
|
8176
|
-
origin = "tracked";
|
|
8177
|
-
value;
|
|
8178
|
-
image;
|
|
8179
|
-
};
|
|
8180
8223
|
|
|
8181
8224
|
// src/runtime/behaviors/CountdownTimerBehavior.ts
|
|
8182
8225
|
var CountdownTimerBehavior = class {
|
|
@@ -8196,7 +8239,9 @@ var CountdownTimerBehavior = class {
|
|
|
8196
8239
|
direction: "down",
|
|
8197
8240
|
durationMs: this.config.durationMs,
|
|
8198
8241
|
label,
|
|
8199
|
-
role
|
|
8242
|
+
role,
|
|
8243
|
+
required: Boolean(this.config.required),
|
|
8244
|
+
polarity: this.config.polarity ?? "work"
|
|
8200
8245
|
})]);
|
|
8201
8246
|
if (this.config.durationMs <= 0) {
|
|
8202
8247
|
this.handleExpiry(ctx, mode);
|
|
@@ -11620,7 +11665,9 @@ var RestBlock = class _RestBlock extends RuntimeBlock {
|
|
|
11620
11665
|
durationMs: config.durationMs,
|
|
11621
11666
|
label: restLabel,
|
|
11622
11667
|
role: "primary",
|
|
11623
|
-
mode: "complete-block"
|
|
11668
|
+
mode: "complete-block",
|
|
11669
|
+
required: true,
|
|
11670
|
+
polarity: "rest"
|
|
11624
11671
|
}));
|
|
11625
11672
|
behaviors.push(new ExitBehavior({
|
|
11626
11673
|
mode: "immediate",
|
|
@@ -11810,6 +11857,7 @@ var BlockBuilder = class {
|
|
|
11810
11857
|
role: config.role,
|
|
11811
11858
|
mode,
|
|
11812
11859
|
required: config.required,
|
|
11860
|
+
polarity: config.polarity,
|
|
11813
11861
|
restBlockFactory: config.injectRest ? (durationMs, label) => {
|
|
11814
11862
|
const restBlock = new RestBlock(this.runtime, { durationMs, label });
|
|
11815
11863
|
return [new PushBlockAction(restBlock)];
|
|
@@ -11818,7 +11866,8 @@ var BlockBuilder = class {
|
|
|
11818
11866
|
} else {
|
|
11819
11867
|
this.addBehavior(new CountupTimerBehavior({
|
|
11820
11868
|
label: config.label,
|
|
11821
|
-
role: config.role
|
|
11869
|
+
role: config.role,
|
|
11870
|
+
polarity: config.polarity
|
|
11822
11871
|
}));
|
|
11823
11872
|
}
|
|
11824
11873
|
return this;
|
|
@@ -12328,11 +12377,22 @@ var AnalyticsEngine = class {
|
|
|
12328
12377
|
outputHistory = [];
|
|
12329
12378
|
/** Emits a live 'analytics' snapshot per segment so the UI updates in real time. */
|
|
12330
12379
|
_onLiveOutput;
|
|
12380
|
+
_liveProjections = [];
|
|
12331
12381
|
/**
|
|
12332
12382
|
* Signature of the last live projection emission. Used by finalize() to avoid
|
|
12333
12383
|
* re-emitting the same projections at session end. Timestamps are ignored.
|
|
12334
12384
|
*/
|
|
12335
12385
|
_lastLiveProjectionSignature;
|
|
12386
|
+
_now;
|
|
12387
|
+
constructor(now = wallClockNow) {
|
|
12388
|
+
this._now = now;
|
|
12389
|
+
}
|
|
12390
|
+
setNowProvider(now) {
|
|
12391
|
+
this._now = now;
|
|
12392
|
+
}
|
|
12393
|
+
getLiveProjections() {
|
|
12394
|
+
return [...this._liveProjections];
|
|
12395
|
+
}
|
|
12336
12396
|
/**
|
|
12337
12397
|
* Wire a sink for live analytics outputs. The sink receives the FULL
|
|
12338
12398
|
* projection snapshot (a replaceable, ephemeral set) each time projections
|
|
@@ -12360,8 +12420,9 @@ var AnalyticsEngine = class {
|
|
|
12360
12420
|
if (current.outputType === "segment") {
|
|
12361
12421
|
this.outputHistory.push(current);
|
|
12362
12422
|
if (this._onLiveOutput) {
|
|
12363
|
-
const now = Date.now();
|
|
12364
12423
|
const projections = this._runSummaries();
|
|
12424
|
+
this._liveProjections = projections;
|
|
12425
|
+
const now = this._now.nowMs();
|
|
12365
12426
|
const signature = this._projectionSignature(projections);
|
|
12366
12427
|
if (signature !== this._lastLiveProjectionSignature) {
|
|
12367
12428
|
this._lastLiveProjectionSignature = signature;
|
|
@@ -12374,7 +12435,8 @@ var AnalyticsEngine = class {
|
|
|
12374
12435
|
}
|
|
12375
12436
|
finalize() {
|
|
12376
12437
|
const projections = this._runSummaries();
|
|
12377
|
-
|
|
12438
|
+
this._liveProjections = [];
|
|
12439
|
+
const outputs = this._buildProjectionOutputs(projections, this._now.nowMs());
|
|
12378
12440
|
const signature = this._projectionSignature(projections);
|
|
12379
12441
|
if (this._lastLiveProjectionSignature !== void 0 && this._lastLiveProjectionSignature === signature) {
|
|
12380
12442
|
return [];
|
|
@@ -14306,7 +14368,7 @@ var RuntimeFactory = class {
|
|
|
14306
14368
|
const script = new WhiteboardScript(block.content, block.statements);
|
|
14307
14369
|
collapseUnresolvedChoices(script.statements);
|
|
14308
14370
|
const stack = new RuntimeStack();
|
|
14309
|
-
const clock = new RuntimeClock();
|
|
14371
|
+
const clock = new RuntimeClock(this.nowProvider);
|
|
14310
14372
|
const eventBus = new EventBus();
|
|
14311
14373
|
const dependencies = {
|
|
14312
14374
|
stack,
|
|
@@ -14541,6 +14603,7 @@ function compose(builder, template) {
|
|
|
14541
14603
|
completionConfig,
|
|
14542
14604
|
injectRest: t2.injectRest,
|
|
14543
14605
|
required: t2.required,
|
|
14606
|
+
polarity: t2.polarity,
|
|
14544
14607
|
...template.countdownTimerConfig ?? {}
|
|
14545
14608
|
});
|
|
14546
14609
|
}
|
|
@@ -14833,6 +14896,14 @@ var GenericTimerStrategy = class {
|
|
|
14833
14896
|
const isRequired = statements.some((s) => hasHint(s, CONSUMED_HINTS.REQUIRED_TIMER));
|
|
14834
14897
|
const injectRest = statements.some((s) => hasHint(s, CONSUMED_HINTS.INJECT_REST));
|
|
14835
14898
|
const isCountdown = !!(durationMs && direction === "down");
|
|
14899
|
+
const allMetrics = statements.flatMap((s) => [...s.metrics]);
|
|
14900
|
+
const hasRestKeyword = allMetrics.some(
|
|
14901
|
+
(m) => (m.type === wodWikiCore.MetricType.Effort || m.type === wodWikiCore.MetricType.Action) && typeof m.value === "string" && m.value.trim().toLowerCase() === "rest"
|
|
14902
|
+
);
|
|
14903
|
+
const hasNonRestMovement = allMetrics.some(
|
|
14904
|
+
(m) => m.type === wodWikiCore.MetricType.Effort && typeof m.value === "string" && m.value.trim().toLowerCase() !== "rest"
|
|
14905
|
+
);
|
|
14906
|
+
const polarity = hasRestKeyword && !hasNonRestMovement ? "rest" : "work";
|
|
14836
14907
|
const template = {
|
|
14837
14908
|
blockType: "Timer",
|
|
14838
14909
|
defaultLabel: direction === "down" ? "Countdown" : "For Time",
|
|
@@ -14845,7 +14916,8 @@ var GenericTimerStrategy = class {
|
|
|
14845
14916
|
role: "primary",
|
|
14846
14917
|
mode: isCountdown ? "complete-block" : "complete-block",
|
|
14847
14918
|
injectRest,
|
|
14848
|
-
required: isRequired
|
|
14919
|
+
required: isRequired,
|
|
14920
|
+
polarity
|
|
14849
14921
|
},
|
|
14850
14922
|
pickStatement: (stmts) => stmts.find(
|
|
14851
14923
|
(s) => s.metrics.some((f) => f.type === wodWikiCore.MetricType.Duration && f.origin !== "runtime")
|
|
@@ -15745,6 +15817,551 @@ var SubscriptionManager = class {
|
|
|
15745
15817
|
this.subscriptions.clear();
|
|
15746
15818
|
}
|
|
15747
15819
|
};
|
|
15820
|
+
|
|
15821
|
+
// src/utils/timeUtils.ts
|
|
15822
|
+
var formatTime = (ms) => {
|
|
15823
|
+
if (ms === void 0 || ms === null || !Number.isFinite(ms)) {
|
|
15824
|
+
return "--:--.--";
|
|
15825
|
+
}
|
|
15826
|
+
const isNegative = ms < 0;
|
|
15827
|
+
const absMs = Math.abs(ms);
|
|
15828
|
+
const totalSeconds = Math.floor(absMs / 1e3);
|
|
15829
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
15830
|
+
const seconds = totalSeconds % 60;
|
|
15831
|
+
const milliseconds = Math.floor(absMs % 1e3 / 10);
|
|
15832
|
+
const sign = isNegative ? "-" : "";
|
|
15833
|
+
return `${sign}${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}.${milliseconds.toString().padStart(2, "0")}`;
|
|
15834
|
+
};
|
|
15835
|
+
var calculateDuration = (spans, now) => {
|
|
15836
|
+
if (!spans || !Array.isArray(spans)) return 0;
|
|
15837
|
+
return spans.reduce((total, span) => {
|
|
15838
|
+
if ("started" in span) {
|
|
15839
|
+
const start2 = span.started;
|
|
15840
|
+
const end = span.ended ?? now;
|
|
15841
|
+
return total + Math.max(0, end - start2);
|
|
15842
|
+
}
|
|
15843
|
+
const start = span.start instanceof Date ? span.start.getTime() : span.start || 0;
|
|
15844
|
+
const stop = span.stop ? span.stop instanceof Date ? span.stop.getTime() : span.stop : now;
|
|
15845
|
+
return total + Math.max(0, stop - start);
|
|
15846
|
+
}, 0);
|
|
15847
|
+
};
|
|
15848
|
+
var roundToTenth = (seconds) => {
|
|
15849
|
+
if (!Number.isFinite(seconds)) return 0;
|
|
15850
|
+
return Math.round(seconds * 10) / 10;
|
|
15851
|
+
};
|
|
15852
|
+
|
|
15853
|
+
// src/runtime/projection/SessionClockProjection.ts
|
|
15854
|
+
var EXCLUDED_REP_BLOCK_TYPES = {
|
|
15855
|
+
Rounds: true,
|
|
15856
|
+
Group: true,
|
|
15857
|
+
AMRAP: true,
|
|
15858
|
+
EMOM: true,
|
|
15859
|
+
SessionRoot: true,
|
|
15860
|
+
Root: true,
|
|
15861
|
+
Timer: true,
|
|
15862
|
+
Rest: true
|
|
15863
|
+
};
|
|
15864
|
+
function toSpans(spans) {
|
|
15865
|
+
return spans.map((s) => new TimeSpan(s.started, s.ended));
|
|
15866
|
+
}
|
|
15867
|
+
function serializeSpans(spans) {
|
|
15868
|
+
return spans.map(
|
|
15869
|
+
(s) => s.ended !== void 0 ? { started: s.started, ended: s.ended } : { started: s.started }
|
|
15870
|
+
);
|
|
15871
|
+
}
|
|
15872
|
+
function resolveVisualPolarity(params) {
|
|
15873
|
+
if (params.isPaused) return "paused";
|
|
15874
|
+
if (params.direction === "down" && params.durationMs !== void 0 && params.durationMs > 0) {
|
|
15875
|
+
if (params.displayMs <= 0) return "overrun";
|
|
15876
|
+
if (params.displayMs <= 5e3) return "final5";
|
|
15877
|
+
}
|
|
15878
|
+
return params.basePolarity === "rest" ? "rest" : "work";
|
|
15879
|
+
}
|
|
15880
|
+
function isRequiredCountdownLocked(params) {
|
|
15881
|
+
return !params.isPaused && params.required && params.direction === "down" && params.durationMs !== void 0 && params.displayMs > 0;
|
|
15882
|
+
}
|
|
15883
|
+
var WATCHED_CLOCK_MEMORY_TAGS = [
|
|
15884
|
+
"time",
|
|
15885
|
+
"round",
|
|
15886
|
+
"display",
|
|
15887
|
+
"metric:display",
|
|
15888
|
+
"metric:result",
|
|
15889
|
+
"metric:next"
|
|
15890
|
+
];
|
|
15891
|
+
function observeSessionClockInputs(runtime, onChange) {
|
|
15892
|
+
let skipFlash = false;
|
|
15893
|
+
let skipFlashKey = 0;
|
|
15894
|
+
let skipTimer;
|
|
15895
|
+
let memoryUnsubs = [];
|
|
15896
|
+
const emit = () => onChange({ skipFlash, skipFlashKey });
|
|
15897
|
+
const rebindBlockMemory = () => {
|
|
15898
|
+
memoryUnsubs.forEach((fn) => fn());
|
|
15899
|
+
memoryUnsubs = [];
|
|
15900
|
+
for (const block of runtime.stack.blocks) {
|
|
15901
|
+
for (const tag of WATCHED_CLOCK_MEMORY_TAGS) {
|
|
15902
|
+
for (const loc of block.getMemoryByTag(tag)) {
|
|
15903
|
+
memoryUnsubs.push(loc.subscribe(emit));
|
|
15904
|
+
}
|
|
15905
|
+
}
|
|
15906
|
+
}
|
|
15907
|
+
};
|
|
15908
|
+
rebindBlockMemory();
|
|
15909
|
+
const unsubStack = runtime.subscribeToStack(() => {
|
|
15910
|
+
rebindBlockMemory();
|
|
15911
|
+
emit();
|
|
15912
|
+
});
|
|
15913
|
+
const unsubSkip = runtime.eventBus.on(
|
|
15914
|
+
"timer:skip-attempt",
|
|
15915
|
+
() => {
|
|
15916
|
+
skipFlashKey += 1;
|
|
15917
|
+
skipFlash = true;
|
|
15918
|
+
clearTimeout(skipTimer);
|
|
15919
|
+
emit();
|
|
15920
|
+
skipTimer = setTimeout(() => {
|
|
15921
|
+
skipFlash = false;
|
|
15922
|
+
emit();
|
|
15923
|
+
}, 3e3);
|
|
15924
|
+
},
|
|
15925
|
+
"session-clock-inputs-flash"
|
|
15926
|
+
);
|
|
15927
|
+
return () => {
|
|
15928
|
+
clearTimeout(skipTimer);
|
|
15929
|
+
unsubStack();
|
|
15930
|
+
unsubSkip();
|
|
15931
|
+
memoryUnsubs.forEach((fn) => fn());
|
|
15932
|
+
memoryUnsubs = [];
|
|
15933
|
+
};
|
|
15934
|
+
}
|
|
15935
|
+
function interpolateSessionClockFrame(frame, nowMs) {
|
|
15936
|
+
const activeElapsed = calculateDuration(toSpans(frame.activeSpans), nowMs);
|
|
15937
|
+
const displayMs = frame.direction === "down" && frame.durationMs !== void 0 ? Math.max(0, frame.durationMs - activeElapsed) : activeElapsed;
|
|
15938
|
+
const sessionElapsedMs = frame.sessionSpans.length > 0 ? calculateDuration(toSpans(frame.sessionSpans), nowMs) : frame.sessionElapsedMs;
|
|
15939
|
+
const secondaryTimers = frame.secondaryTimers.map((st) => {
|
|
15940
|
+
const elapsed = calculateDuration(toSpans(st.spans), nowMs);
|
|
15941
|
+
return {
|
|
15942
|
+
...st,
|
|
15943
|
+
displayMs: st.direction === "down" && st.durationMs !== void 0 ? Math.max(0, st.durationMs - elapsed) : elapsed
|
|
15944
|
+
};
|
|
15945
|
+
});
|
|
15946
|
+
const polarity = resolveVisualPolarity({
|
|
15947
|
+
isPaused: frame.isPaused,
|
|
15948
|
+
basePolarity: frame.basePolarity,
|
|
15949
|
+
direction: frame.direction,
|
|
15950
|
+
durationMs: frame.durationMs,
|
|
15951
|
+
displayMs
|
|
15952
|
+
});
|
|
15953
|
+
const isRequiredLockActive = isRequiredCountdownLocked({
|
|
15954
|
+
isPaused: frame.isPaused,
|
|
15955
|
+
required: frame.required,
|
|
15956
|
+
direction: frame.direction,
|
|
15957
|
+
durationMs: frame.durationMs,
|
|
15958
|
+
displayMs
|
|
15959
|
+
});
|
|
15960
|
+
return {
|
|
15961
|
+
...frame,
|
|
15962
|
+
displayMs,
|
|
15963
|
+
sessionElapsedMs,
|
|
15964
|
+
secondaryTimers,
|
|
15965
|
+
polarity,
|
|
15966
|
+
isRequiredLockActive
|
|
15967
|
+
};
|
|
15968
|
+
}
|
|
15969
|
+
function readBlockRound(block) {
|
|
15970
|
+
if (!block) return void 0;
|
|
15971
|
+
const round = block.getMemoryByTag("round")[0]?.metrics[0];
|
|
15972
|
+
if (!round || typeof round.current !== "number") return void 0;
|
|
15973
|
+
const display = block.getMemoryByTag("display")[0]?.metrics[0]?.value;
|
|
15974
|
+
const label = display?.roundDisplay ?? (round.total !== void 0 ? `Round ${round.current} of ${round.total}` : `Round ${round.current}`);
|
|
15975
|
+
return { current: round.current, total: round.total, label };
|
|
15976
|
+
}
|
|
15977
|
+
function readNextPreviewText(blocks) {
|
|
15978
|
+
for (const block of blocks) {
|
|
15979
|
+
const nextLocs = block.getMemoryByTag("metric:next");
|
|
15980
|
+
if (nextLocs.length === 0) continue;
|
|
15981
|
+
const merged = wodWikiCore.MetricContainer.empty(block.key.toString());
|
|
15982
|
+
for (const loc of nextLocs) merged.merge(loc.metrics);
|
|
15983
|
+
if (merged.length > 0) {
|
|
15984
|
+
return metricPresentation.presentGroup([...merged], "timer-subtitle").filter((t2) => t2.visible).map((t2) => t2.label).filter(Boolean).join(" ").trim() || null;
|
|
15985
|
+
}
|
|
15986
|
+
}
|
|
15987
|
+
return null;
|
|
15988
|
+
}
|
|
15989
|
+
function extractRepTargets(blocks) {
|
|
15990
|
+
const targets = [];
|
|
15991
|
+
for (const block of blocks) {
|
|
15992
|
+
const blockType = block.blockType ?? "";
|
|
15993
|
+
if (EXCLUDED_REP_BLOCK_TYPES[blockType]) {
|
|
15994
|
+
continue;
|
|
15995
|
+
}
|
|
15996
|
+
if (block.getMemoryByTag("children:status").length > 0) continue;
|
|
15997
|
+
const displayLocs = block.getMemoryByTag("metric:display");
|
|
15998
|
+
const resultLocs = block.getMemoryByTag("metric:result");
|
|
15999
|
+
const blockKey = block.key.toString();
|
|
16000
|
+
const grouped = displayLocs.length > 1;
|
|
16001
|
+
for (let idx = 0; idx < displayLocs.length; idx++) {
|
|
16002
|
+
const loc = displayLocs[idx];
|
|
16003
|
+
let plannedTarget = null;
|
|
16004
|
+
let movementText;
|
|
16005
|
+
for (const m of loc.metrics) {
|
|
16006
|
+
if (m.type === wodWikiCore.MetricType.Rep && m.origin !== "user" && typeof m.value === "number") {
|
|
16007
|
+
plannedTarget = m.value;
|
|
16008
|
+
}
|
|
16009
|
+
if ((m.type === wodWikiCore.MetricType.Effort || m.type === wodWikiCore.MetricType.Action) && typeof m.value === "string" && m.value) {
|
|
16010
|
+
movementText ??= m.value;
|
|
16011
|
+
}
|
|
16012
|
+
}
|
|
16013
|
+
const hasMovementIdentity = plannedTarget !== null || loc.metrics.some(
|
|
16014
|
+
(m) => (m.type === wodWikiCore.MetricType.Effort || m.type === wodWikiCore.MetricType.Action) && (typeof m.value === "string" || typeof m.image === "string")
|
|
16015
|
+
);
|
|
16016
|
+
if (!hasMovementIdentity) continue;
|
|
16017
|
+
let actual = null;
|
|
16018
|
+
if (resultLocs.length > 0) {
|
|
16019
|
+
const resLoc = resultLocs[Math.min(idx, resultLocs.length - 1)];
|
|
16020
|
+
if (resLoc) {
|
|
16021
|
+
const userHits = [];
|
|
16022
|
+
for (const m of resLoc.metrics) {
|
|
16023
|
+
if (m.origin === "user" && m.type === wodWikiCore.MetricType.Rep && typeof m.value === "number") {
|
|
16024
|
+
userHits.push(m);
|
|
16025
|
+
}
|
|
16026
|
+
}
|
|
16027
|
+
const last = userHits[userHits.length - 1];
|
|
16028
|
+
if (last) actual = last.value;
|
|
16029
|
+
}
|
|
16030
|
+
}
|
|
16031
|
+
const sourceId = block.sourceIds[idx] ?? idx;
|
|
16032
|
+
targets.push({
|
|
16033
|
+
occurrenceId: grouped ? `${blockKey}:${sourceId}` : blockKey,
|
|
16034
|
+
blockKey,
|
|
16035
|
+
...grouped ? { sourceId } : {},
|
|
16036
|
+
label: grouped && movementText ? movementText : block.label,
|
|
16037
|
+
target: plannedTarget,
|
|
16038
|
+
actual
|
|
16039
|
+
});
|
|
16040
|
+
}
|
|
16041
|
+
}
|
|
16042
|
+
return targets;
|
|
16043
|
+
}
|
|
16044
|
+
function projectSessionClock(runtime, options = {}) {
|
|
16045
|
+
const status = options.executionStatus ?? "idle";
|
|
16046
|
+
const isPaused = status === "paused";
|
|
16047
|
+
const skipFlash = options.skipFlash ?? false;
|
|
16048
|
+
const skipFlashKey = options.skipFlashKey ?? 0;
|
|
16049
|
+
if (!runtime) {
|
|
16050
|
+
return {
|
|
16051
|
+
mainLabel: "Timer",
|
|
16052
|
+
displayMs: 0,
|
|
16053
|
+
direction: "up",
|
|
16054
|
+
activeSpans: [],
|
|
16055
|
+
basePolarity: "work",
|
|
16056
|
+
required: false,
|
|
16057
|
+
sessionElapsedMs: 0,
|
|
16058
|
+
sessionSpans: [],
|
|
16059
|
+
polarity: isPaused ? "paused" : "work",
|
|
16060
|
+
isRequiredLockActive: false,
|
|
16061
|
+
secondaryTimers: [],
|
|
16062
|
+
upNext: null,
|
|
16063
|
+
repTargets: [],
|
|
16064
|
+
isRunning: status === "running",
|
|
16065
|
+
isPaused,
|
|
16066
|
+
isNextDisabled: isPaused || options.canNextOverride === false,
|
|
16067
|
+
skipFlash,
|
|
16068
|
+
skipFlashKey
|
|
16069
|
+
};
|
|
16070
|
+
}
|
|
16071
|
+
const nowMs = options.nowMs ?? runtime.nowProvider.nowMs();
|
|
16072
|
+
const blocks = runtime.stack.blocks;
|
|
16073
|
+
const orderedRootToLeaf = [...blocks].reverse();
|
|
16074
|
+
const displayEntries = [];
|
|
16075
|
+
orderedRootToLeaf.forEach((block, index) => {
|
|
16076
|
+
if (block.blockType === "Root" && !block.label) return;
|
|
16077
|
+
const displayRows = block.getMemoryByTag("metric:display").map((loc) => loc.metrics);
|
|
16078
|
+
if (displayRows.length === 0 && !block.label) return;
|
|
16079
|
+
displayEntries.push({
|
|
16080
|
+
block,
|
|
16081
|
+
displayRows,
|
|
16082
|
+
label: block.label,
|
|
16083
|
+
isLeaf: index === orderedRootToLeaf.length - 1
|
|
16084
|
+
});
|
|
16085
|
+
});
|
|
16086
|
+
const leafEntry = displayEntries.find((e) => e.isLeaf);
|
|
16087
|
+
const roundsEntry = displayEntries.find((e) => e.block.blockType === "Rounds") ?? displayEntries.find((e) => e.block.getMemoryByTag("round").length > 0 && e.block.blockType !== "SessionRoot");
|
|
16088
|
+
const roundInfo = readBlockRound(roundsEntry?.block);
|
|
16089
|
+
const roundsLabel = roundInfo?.label ?? roundsEntry?.label;
|
|
16090
|
+
const allTimers = [];
|
|
16091
|
+
for (const block of blocks) {
|
|
16092
|
+
const timer = block.getMemoryByTag("time")[0]?.metrics[0]?.value;
|
|
16093
|
+
if (!timer) continue;
|
|
16094
|
+
allTimers.push({
|
|
16095
|
+
block,
|
|
16096
|
+
timer,
|
|
16097
|
+
isPinned: timer.role === "primary"
|
|
16098
|
+
});
|
|
16099
|
+
}
|
|
16100
|
+
const isAnyTimerRunning = allTimers.some(
|
|
16101
|
+
(t2) => t2.timer.spans.some((s) => s.ended === void 0)
|
|
16102
|
+
);
|
|
16103
|
+
const topTimer = allTimers[0];
|
|
16104
|
+
const primaryTimer = topTimer && (topTimer.block.blockType === "Rest" || topTimer.timer.polarity === "rest") ? topTimer : [...allTimers].reverse().find((t2) => t2.isPinned) ?? topTimer;
|
|
16105
|
+
const leafTimer = leafEntry ? allTimers.find((t2) => t2.block.key.toString() === leafEntry.block.key.toString()) : void 0;
|
|
16106
|
+
const isRestHero = primaryTimer?.block.blockType === "Rest" || primaryTimer?.timer.polarity === "rest";
|
|
16107
|
+
const active = isRestHero || primaryTimer?.isPinned ? primaryTimer : leafTimer ?? primaryTimer;
|
|
16108
|
+
const leafLabel = leafEntry?.label;
|
|
16109
|
+
const mainLabel = (isRestHero ? primaryTimer?.block.label || primaryTimer?.timer.label : primaryTimer?.isPinned ? roundsLabel || primaryTimer.timer.label : roundsLabel && roundsLabel !== leafLabel ? roundsLabel : leafLabel || primaryTimer?.timer.label) || "Timer";
|
|
16110
|
+
const subLabel = isRestHero && roundsLabel && roundsLabel !== mainLabel ? roundsLabel : mainLabel === leafLabel ? void 0 : leafLabel;
|
|
16111
|
+
let subLabels;
|
|
16112
|
+
if (!isRestHero && leafEntry && leafEntry.displayRows.length > 1) {
|
|
16113
|
+
const lines = leafEntry.displayRows.map(
|
|
16114
|
+
(row) => metricPresentation.presentGroup([...row], "timer-subtitle").filter((t2) => t2.visible).map((t2) => t2.label).filter(Boolean).join(" ").trim()
|
|
16115
|
+
).filter(Boolean);
|
|
16116
|
+
if (lines.length > 0) subLabels = lines;
|
|
16117
|
+
}
|
|
16118
|
+
if (!subLabels) subLabels = subLabel ? [subLabel] : void 0;
|
|
16119
|
+
const activeDirection = active?.timer.direction ?? "up";
|
|
16120
|
+
const activeDurationMs = active?.timer.durationMs;
|
|
16121
|
+
const activeSpans = active ? serializeSpans(active.timer.spans) : [];
|
|
16122
|
+
let displayMs = 0;
|
|
16123
|
+
if (active) {
|
|
16124
|
+
const elapsed = calculateDuration(active.timer.spans, nowMs);
|
|
16125
|
+
displayMs = activeDirection === "down" && activeDurationMs !== void 0 ? Math.max(0, activeDurationMs - elapsed) : elapsed;
|
|
16126
|
+
}
|
|
16127
|
+
const withElapsed = allTimers.map((entry) => ({
|
|
16128
|
+
entry,
|
|
16129
|
+
elapsed: calculateDuration(entry.timer.spans, nowMs)
|
|
16130
|
+
}));
|
|
16131
|
+
const sessionHolder = withElapsed.find((e) => e.entry.block.blockType === "SessionRoot") ?? withElapsed.reduce(
|
|
16132
|
+
(best, cur) => cur.elapsed > (best?.elapsed ?? -1) ? cur : best,
|
|
16133
|
+
withElapsed[withElapsed.length - 1]
|
|
16134
|
+
);
|
|
16135
|
+
const sessionElapsedMs = sessionHolder?.elapsed ?? 0;
|
|
16136
|
+
const sessionSpans = sessionHolder ? serializeSpans(sessionHolder.entry.timer.spans) : [];
|
|
16137
|
+
const activeKey = active?.block.key.toString();
|
|
16138
|
+
const sessionKey = sessionHolder?.entry.block.key.toString();
|
|
16139
|
+
const secondaryTimers = allTimers.filter((t2) => {
|
|
16140
|
+
if (t2.timer.role === "hidden") return false;
|
|
16141
|
+
const key = t2.block.key.toString();
|
|
16142
|
+
return key !== activeKey && key !== sessionKey;
|
|
16143
|
+
}).map((t2) => {
|
|
16144
|
+
const elapsed = calculateDuration(t2.timer.spans, nowMs);
|
|
16145
|
+
return {
|
|
16146
|
+
id: t2.block.key.toString(),
|
|
16147
|
+
label: t2.timer.label || t2.block.label || "Timer",
|
|
16148
|
+
displayMs: t2.timer.direction === "down" && t2.timer.durationMs !== void 0 ? Math.max(0, t2.timer.durationMs - elapsed) : elapsed,
|
|
16149
|
+
direction: t2.timer.direction,
|
|
16150
|
+
durationMs: t2.timer.durationMs,
|
|
16151
|
+
spans: serializeSpans(t2.timer.spans)
|
|
16152
|
+
};
|
|
16153
|
+
});
|
|
16154
|
+
const basePolarity = active?.block.blockType === "Rest" || active?.timer.polarity === "rest" ? "rest" : "work";
|
|
16155
|
+
const required = Boolean(active?.timer.required);
|
|
16156
|
+
const polarity = resolveVisualPolarity({
|
|
16157
|
+
isPaused,
|
|
16158
|
+
basePolarity,
|
|
16159
|
+
direction: activeDirection,
|
|
16160
|
+
durationMs: activeDurationMs,
|
|
16161
|
+
displayMs
|
|
16162
|
+
});
|
|
16163
|
+
const isRequiredLockActive = isRequiredCountdownLocked({
|
|
16164
|
+
isPaused,
|
|
16165
|
+
required,
|
|
16166
|
+
direction: activeDirection,
|
|
16167
|
+
durationMs: activeDurationMs,
|
|
16168
|
+
displayMs
|
|
16169
|
+
});
|
|
16170
|
+
return {
|
|
16171
|
+
mainLabel,
|
|
16172
|
+
subLabels,
|
|
16173
|
+
displayMs,
|
|
16174
|
+
direction: activeDirection,
|
|
16175
|
+
durationMs: activeDurationMs,
|
|
16176
|
+
activeSpans,
|
|
16177
|
+
basePolarity,
|
|
16178
|
+
required,
|
|
16179
|
+
sessionElapsedMs,
|
|
16180
|
+
sessionSpans,
|
|
16181
|
+
polarity,
|
|
16182
|
+
isRequiredLockActive,
|
|
16183
|
+
roundCurrent: roundInfo?.current,
|
|
16184
|
+
roundTotal: roundInfo?.total,
|
|
16185
|
+
roundLabel: roundInfo?.label,
|
|
16186
|
+
secondaryTimers,
|
|
16187
|
+
upNext: readNextPreviewText(blocks),
|
|
16188
|
+
repTargets: extractRepTargets(blocks),
|
|
16189
|
+
isRunning: isAnyTimerRunning || status === "running",
|
|
16190
|
+
isPaused,
|
|
16191
|
+
isNextDisabled: isPaused || options.canNextOverride === false,
|
|
16192
|
+
skipFlash,
|
|
16193
|
+
skipFlashKey
|
|
16194
|
+
};
|
|
16195
|
+
}
|
|
16196
|
+
var NON_LABEL_SEGMENT_METRIC_TYPES = {
|
|
16197
|
+
[wodWikiCore.MetricType.Elapsed]: true,
|
|
16198
|
+
[wodWikiCore.MetricType.Total]: true,
|
|
16199
|
+
[wodWikiCore.MetricType.Spans]: true,
|
|
16200
|
+
[wodWikiCore.MetricType.SystemTime]: true,
|
|
16201
|
+
[wodWikiCore.MetricType.CurrentRound]: true,
|
|
16202
|
+
[wodWikiCore.MetricType.System]: true
|
|
16203
|
+
};
|
|
16204
|
+
function projectionsToUniqueSummaries(projections) {
|
|
16205
|
+
const byName = /* @__PURE__ */ new Map();
|
|
16206
|
+
for (const proj of projections) {
|
|
16207
|
+
byName.set(proj.name, {
|
|
16208
|
+
key: proj.name,
|
|
16209
|
+
label: computeColumnLabel(proj.name),
|
|
16210
|
+
value: proj.value,
|
|
16211
|
+
unit: proj.unit,
|
|
16212
|
+
metricType: proj.metricType ?? wodWikiCore.MetricType.Metric,
|
|
16213
|
+
origin: proj.origin
|
|
16214
|
+
});
|
|
16215
|
+
}
|
|
16216
|
+
return [...byName.values()];
|
|
16217
|
+
}
|
|
16218
|
+
function fallbackSummariesFromOutputs(outputs) {
|
|
16219
|
+
const byName = /* @__PURE__ */ new Map();
|
|
16220
|
+
for (const output of outputs) {
|
|
16221
|
+
const metrics = output.metrics;
|
|
16222
|
+
for (let j = 0; j + 1 < metrics.length; j += 2) {
|
|
16223
|
+
const labelMetric = metrics[j];
|
|
16224
|
+
const valueMetric = metrics[j + 1];
|
|
16225
|
+
if (!labelMetric || !valueMetric || typeof valueMetric.value !== "number") continue;
|
|
16226
|
+
const name2 = labelMetric.image ?? String(labelMetric.value);
|
|
16227
|
+
byName.set(name2, {
|
|
16228
|
+
key: name2,
|
|
16229
|
+
label: computeColumnLabel(name2),
|
|
16230
|
+
value: valueMetric.value,
|
|
16231
|
+
unit: valueMetric.unit ?? "",
|
|
16232
|
+
metricType: valueMetric.type || wodWikiCore.MetricType.Metric,
|
|
16233
|
+
origin: valueMetric.origin
|
|
16234
|
+
});
|
|
16235
|
+
}
|
|
16236
|
+
}
|
|
16237
|
+
return [...byName.values()];
|
|
16238
|
+
}
|
|
16239
|
+
function formatSplitDeltaLabel(deltaMs) {
|
|
16240
|
+
const deltaSec = Math.round(deltaMs / 1e3);
|
|
16241
|
+
if (deltaSec === 0) return "even";
|
|
16242
|
+
return deltaSec > 0 ? `+${deltaSec}s` : `${deltaSec}s`;
|
|
16243
|
+
}
|
|
16244
|
+
function readRoundFromOutput(output) {
|
|
16245
|
+
const metric = output.getMetric(wodWikiCore.MetricType.CurrentRound);
|
|
16246
|
+
if (!metric) return {};
|
|
16247
|
+
const round = typeof metric.value === "number" ? metric.value : void 0;
|
|
16248
|
+
let totalRounds;
|
|
16249
|
+
if ("total" in metric && typeof metric.total === "number") {
|
|
16250
|
+
totalRounds = metric.total;
|
|
16251
|
+
}
|
|
16252
|
+
return { round, totalRounds };
|
|
16253
|
+
}
|
|
16254
|
+
function deriveRoundSplits(outputs) {
|
|
16255
|
+
const previousElapsedByKey = /* @__PURE__ */ new Map();
|
|
16256
|
+
const rows = [];
|
|
16257
|
+
for (let idx = 0; idx < outputs.length; idx++) {
|
|
16258
|
+
const out = outputs[idx];
|
|
16259
|
+
if (out.outputType !== "segment") continue;
|
|
16260
|
+
if (out.sourceBlockKey.startsWith("session-root")) continue;
|
|
16261
|
+
if (out.completionReason === "rounds-complete") continue;
|
|
16262
|
+
if (out.sourceStatementId === void 0 && !out.sourceBlockKey.startsWith("rest")) continue;
|
|
16263
|
+
const elapsedVal = out.getMetric(wodWikiCore.MetricType.Elapsed)?.value;
|
|
16264
|
+
const fallbackSpanElapsed = out.timeSpan.ended !== void 0 ? Math.max(0, out.timeSpan.ended - out.timeSpan.started) : 0;
|
|
16265
|
+
const elapsedMs = typeof elapsedVal === "number" ? elapsedVal : fallbackSpanElapsed;
|
|
16266
|
+
if (!Number.isFinite(elapsedMs)) continue;
|
|
16267
|
+
const displayTokens = metricPresentation.presentGroup(
|
|
16268
|
+
out.metrics.filter((m) => !NON_LABEL_SEGMENT_METRIC_TYPES[m.type]),
|
|
16269
|
+
"timer-subtitle"
|
|
16270
|
+
).filter((t2) => t2.visible).map((t2) => t2.label).filter(Boolean).join(" ").trim();
|
|
16271
|
+
const label = displayTokens || out.text?.trim() || (out.sourceBlockKey.startsWith("rest") ? "Rest" : "Segment");
|
|
16272
|
+
const comparisonKey = out.sourceStatementId !== void 0 ? `stmt:${out.sourceStatementId}` : `key:${label.toLowerCase()}`;
|
|
16273
|
+
const prevElapsed = previousElapsedByKey.get(comparisonKey);
|
|
16274
|
+
const deltaMs = prevElapsed !== void 0 ? elapsedMs - prevElapsed : void 0;
|
|
16275
|
+
previousElapsedByKey.set(comparisonKey, elapsedMs);
|
|
16276
|
+
const { round, totalRounds } = readRoundFromOutput(out);
|
|
16277
|
+
rows.push({
|
|
16278
|
+
id: `${out.sourceBlockKey}:${idx}`,
|
|
16279
|
+
comparisonKey,
|
|
16280
|
+
label,
|
|
16281
|
+
elapsedMs,
|
|
16282
|
+
...round !== void 0 ? { round } : {},
|
|
16283
|
+
...totalRounds !== void 0 ? { totalRounds } : {},
|
|
16284
|
+
...deltaMs !== void 0 ? { deltaMs, deltaLabel: formatSplitDeltaLabel(deltaMs) } : {}
|
|
16285
|
+
});
|
|
16286
|
+
}
|
|
16287
|
+
return rows;
|
|
16288
|
+
}
|
|
16289
|
+
function projectLiveSessionTelemetry(runtime) {
|
|
16290
|
+
if (!runtime) {
|
|
16291
|
+
return { summaries: [], splits: [] };
|
|
16292
|
+
}
|
|
16293
|
+
const typedProjections = runtime.getLiveProjections?.();
|
|
16294
|
+
const summaries = typedProjections && typedProjections.length > 0 ? projectionsToUniqueSummaries(typedProjections) : fallbackSummariesFromOutputs(runtime.getLiveAnalytics?.() ?? []);
|
|
16295
|
+
const splits = deriveRoundSplits(runtime.getOutputStatements());
|
|
16296
|
+
return { summaries, splits };
|
|
16297
|
+
}
|
|
16298
|
+
function formatStatementLabel(statement) {
|
|
16299
|
+
const presented = metricPresentation.presentGroup(
|
|
16300
|
+
[...statement.metrics].filter((m) => m.type !== wodWikiCore.MetricType.Hint),
|
|
16301
|
+
"timer-subtitle"
|
|
16302
|
+
).filter((t2) => t2.visible).map((t2) => t2.label).filter(Boolean).join(" ").trim();
|
|
16303
|
+
return presented || statement.text?.trim() || "Step";
|
|
16304
|
+
}
|
|
16305
|
+
function synthesizeWorkoutFormat(script) {
|
|
16306
|
+
const statements = script?.statements;
|
|
16307
|
+
if (!statements || statements.length === 0) return void 0;
|
|
16308
|
+
const roots = statements.filter((s) => s.parent === void 0);
|
|
16309
|
+
const primaryRoot = roots[0] ?? statements[0];
|
|
16310
|
+
if (!primaryRoot) return void 0;
|
|
16311
|
+
const hasChildren = (primaryRoot.children?.length ?? 0) > 0;
|
|
16312
|
+
const hasProtocolHint = hasHint(primaryRoot, CONSUMED_HINTS.LABEL_AMRAP) || hasHint(primaryRoot, CONSUMED_HINTS.LABEL_EMOM) || hasHint(primaryRoot, CONSUMED_HINTS.LABEL_TABATA) || hasHint(primaryRoot, CONSUMED_HINTS.LABEL_FOR_TIME);
|
|
16313
|
+
const hasStructuralMetric = primaryRoot.metrics.some(
|
|
16314
|
+
(m) => m.type === wodWikiCore.MetricType.Rounds || m.type === wodWikiCore.MetricType.Duration
|
|
16315
|
+
);
|
|
16316
|
+
if (!hasChildren && !hasProtocolHint && !hasStructuralMetric) {
|
|
16317
|
+
return void 0;
|
|
16318
|
+
}
|
|
16319
|
+
return formatStatementLabel(primaryRoot);
|
|
16320
|
+
}
|
|
16321
|
+
function projectScriptOutline(runtime) {
|
|
16322
|
+
const statements = runtime?.script?.statements;
|
|
16323
|
+
if (!runtime || !statements || statements.length === 0) return [];
|
|
16324
|
+
const activeIds = /* @__PURE__ */ new Set();
|
|
16325
|
+
for (const block of runtime.stack.blocks) {
|
|
16326
|
+
if (block.blockType === "SessionRoot" || block.blockType === "WaitingToStart") continue;
|
|
16327
|
+
for (const id of block.sourceIds) {
|
|
16328
|
+
if (typeof id === "number") activeIds.add(id);
|
|
16329
|
+
}
|
|
16330
|
+
}
|
|
16331
|
+
const completedIds = /* @__PURE__ */ new Set();
|
|
16332
|
+
for (const out of runtime.getOutputStatements()) {
|
|
16333
|
+
if (out.outputType === "segment" && typeof out.sourceStatementId === "number") {
|
|
16334
|
+
completedIds.add(out.sourceStatementId);
|
|
16335
|
+
}
|
|
16336
|
+
}
|
|
16337
|
+
const depthOf = (stmt) => {
|
|
16338
|
+
let depth = 0;
|
|
16339
|
+
let cur = stmt.parent;
|
|
16340
|
+
const seen = /* @__PURE__ */ new Set();
|
|
16341
|
+
while (cur !== void 0 && !seen.has(cur)) {
|
|
16342
|
+
seen.add(cur);
|
|
16343
|
+
const parentStmt = runtime.script.getId(cur);
|
|
16344
|
+
if (!parentStmt) break;
|
|
16345
|
+
depth += 1;
|
|
16346
|
+
cur = parentStmt.parent;
|
|
16347
|
+
}
|
|
16348
|
+
return depth;
|
|
16349
|
+
};
|
|
16350
|
+
const nodes = [];
|
|
16351
|
+
for (const stmt of statements) {
|
|
16352
|
+
if (typeof stmt.id !== "number") continue;
|
|
16353
|
+
const label = formatStatementLabel(stmt);
|
|
16354
|
+
if (!label) continue;
|
|
16355
|
+
const status = activeIds.has(stmt.id) ? "active" : completedIds.has(stmt.id) ? "completed" : "upcoming";
|
|
16356
|
+
nodes.push({
|
|
16357
|
+
statementId: stmt.id,
|
|
16358
|
+
depth: depthOf(stmt),
|
|
16359
|
+
label,
|
|
16360
|
+
status
|
|
16361
|
+
});
|
|
16362
|
+
}
|
|
16363
|
+
return nodes;
|
|
16364
|
+
}
|
|
15748
16365
|
function formatMetricLabel(key) {
|
|
15749
16366
|
return key.charAt(0).toUpperCase() + key.slice(1).replace(/_/g, " ");
|
|
15750
16367
|
}
|
|
@@ -16061,38 +16678,6 @@ function toStoredOutputStatement(output) {
|
|
|
16061
16678
|
};
|
|
16062
16679
|
}
|
|
16063
16680
|
|
|
16064
|
-
// src/utils/timeUtils.ts
|
|
16065
|
-
var formatTime = (ms) => {
|
|
16066
|
-
if (ms === void 0 || ms === null || !Number.isFinite(ms)) {
|
|
16067
|
-
return "--:--.--";
|
|
16068
|
-
}
|
|
16069
|
-
const isNegative = ms < 0;
|
|
16070
|
-
const absMs = Math.abs(ms);
|
|
16071
|
-
const totalSeconds = Math.floor(absMs / 1e3);
|
|
16072
|
-
const minutes = Math.floor(totalSeconds / 60);
|
|
16073
|
-
const seconds = totalSeconds % 60;
|
|
16074
|
-
const milliseconds = Math.floor(absMs % 1e3 / 10);
|
|
16075
|
-
const sign = isNegative ? "-" : "";
|
|
16076
|
-
return `${sign}${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}.${milliseconds.toString().padStart(2, "0")}`;
|
|
16077
|
-
};
|
|
16078
|
-
var calculateDuration = (spans, now) => {
|
|
16079
|
-
if (!spans || !Array.isArray(spans)) return 0;
|
|
16080
|
-
return spans.reduce((total, span) => {
|
|
16081
|
-
if ("started" in span) {
|
|
16082
|
-
const start2 = span.started;
|
|
16083
|
-
const end = span.ended ?? now;
|
|
16084
|
-
return total + Math.max(0, end - start2);
|
|
16085
|
-
}
|
|
16086
|
-
const start = span.start instanceof Date ? span.start.getTime() : span.start || 0;
|
|
16087
|
-
const stop = span.stop ? span.stop instanceof Date ? span.stop.getTime() : span.stop : now;
|
|
16088
|
-
return total + Math.max(0, stop - start);
|
|
16089
|
-
}, 0);
|
|
16090
|
-
};
|
|
16091
|
-
var roundToTenth = (seconds) => {
|
|
16092
|
-
if (!Number.isFinite(seconds)) return 0;
|
|
16093
|
-
return Math.round(seconds * 10) / 10;
|
|
16094
|
-
};
|
|
16095
|
-
|
|
16096
16681
|
// src/parser-fixture/metricLine.ts
|
|
16097
16682
|
var TAIL_TOKEN_RE = /[\w-]+:(?:"(?:[^"\\]|\\.)*"|[^ ]+)/g;
|
|
16098
16683
|
var FixtureSyntaxError = class extends Error {
|
|
@@ -16532,11 +17117,13 @@ exports.hasHint = hasHint;
|
|
|
16532
17117
|
exports.hintMetric = hintMetric;
|
|
16533
17118
|
exports.hintsToContainer = hintsToContainer;
|
|
16534
17119
|
exports.inferDim = inferDim;
|
|
17120
|
+
exports.interpolateSessionClockFrame = interpolateSessionClockFrame;
|
|
16535
17121
|
exports.isCastSubscription = isCastSubscription;
|
|
16536
17122
|
exports.isChoiceResolved = isChoiceResolved;
|
|
16537
17123
|
exports.isDimensionless = isDimensionless;
|
|
16538
17124
|
exports.isEffortDiscipline = isEffortDiscipline;
|
|
16539
17125
|
exports.isFragmentTag = isFragmentTag;
|
|
17126
|
+
exports.isRequiredCountdownLocked = isRequiredCountdownLocked;
|
|
16540
17127
|
exports.isTimeLikeMetric = isTimeLikeMetric;
|
|
16541
17128
|
exports.isWithinThreshold = isWithinThreshold;
|
|
16542
17129
|
exports.levenshteinDistance = levenshteinDistance;
|
|
@@ -16544,6 +17131,7 @@ exports.metricPresentation = metricPresentation;
|
|
|
16544
17131
|
exports.mutateTimerSpans = mutateTimerSpans;
|
|
16545
17132
|
exports.normalizeForFuzzy = normalizeForFuzzy;
|
|
16546
17133
|
exports.num = num;
|
|
17134
|
+
exports.observeSessionClockInputs = observeSessionClockInputs;
|
|
16547
17135
|
exports.openSpan = openSpan;
|
|
16548
17136
|
exports.outputNodeId = outputNodeId;
|
|
16549
17137
|
exports.outputNodeIds = outputNodeIds;
|
|
@@ -16557,6 +17145,9 @@ exports.parseMetricLine = parseMetricLine;
|
|
|
16557
17145
|
exports.parseScript = parseScript;
|
|
16558
17146
|
exports.parseSoundTrigger = parseSoundTrigger;
|
|
16559
17147
|
exports.printCalculation = printCalculation;
|
|
17148
|
+
exports.projectLiveSessionTelemetry = projectLiveSessionTelemetry;
|
|
17149
|
+
exports.projectScriptOutline = projectScriptOutline;
|
|
17150
|
+
exports.projectSessionClock = projectSessionClock;
|
|
16560
17151
|
exports.readNestedSection = readNestedSection;
|
|
16561
17152
|
exports.readTimer = readTimer;
|
|
16562
17153
|
exports.realtimeProcessorRegistry = realtimeProcessorRegistry;
|
|
@@ -16571,6 +17162,7 @@ exports.resolveSoundProfile = resolveSoundProfile;
|
|
|
16571
17162
|
exports.resolveSourceRank = resolveSourceRank;
|
|
16572
17163
|
exports.resolveSourceTier = resolveSourceTier;
|
|
16573
17164
|
exports.resolveTagContributions = resolveTagContributions;
|
|
17165
|
+
exports.resolveVisualPolarity = resolveVisualPolarity;
|
|
16574
17166
|
exports.roundToTenth = roundToTenth;
|
|
16575
17167
|
exports.runMetricShakeOutQueue = runMetricShakeOutQueue;
|
|
16576
17168
|
exports.slugifyRefLabel = slugifyRefLabel;
|
|
@@ -16580,6 +17172,7 @@ exports.str = str;
|
|
|
16580
17172
|
exports.strategyRegistry = strategyRegistry;
|
|
16581
17173
|
exports.subDim = subDim;
|
|
16582
17174
|
exports.summaryProcessorRegistry = summaryProcessorRegistry;
|
|
17175
|
+
exports.synthesizeWorkoutFormat = synthesizeWorkoutFormat;
|
|
16583
17176
|
exports.tagCategoryRecordToDocument = tagCategoryRecordToDocument;
|
|
16584
17177
|
exports.tagCategoryToDocument = tagCategoryToDocument;
|
|
16585
17178
|
exports.tagContributionMetrics = tagContributionMetrics;
|