@bitcobblers/wod-wiki-lang 0.60.2250 → 0.60.2258

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 CHANGED
@@ -3686,18 +3686,41 @@ function structureKeywords() {
3686
3686
  apply: STRUCTURE_KEYWORD_DISPLAY[word] ?? word.toUpperCase()
3687
3687
  }));
3688
3688
  }
3689
+ var ACTION_CUE_COMPLETIONS = [
3690
+ { label: "[:rest]", detail: "Rest cue", type: "keyword", apply: "[:rest] ", boost: 20 },
3691
+ { label: "[:next]", detail: "Advance segment", type: "keyword", apply: "[:next] ", boost: 15 },
3692
+ { label: "[:done]", detail: "Complete block", type: "keyword", apply: "[:done] ", boost: 12 },
3693
+ { label: "[:mark]", detail: "Split / lap marker", type: "keyword", apply: "[:mark] ", boost: 10 }
3694
+ ];
3695
+ var completionAliases = /* @__PURE__ */ new WeakMap();
3689
3696
  function toCompletions(values, detail, quoteValues = false) {
3690
3697
  return values.map((value) => {
3691
3698
  const insertText = quoteValues ? !/^[A-Za-z][A-Za-z0-9]*$/.test(value.value) ? JSON.stringify(value.value) : value.value : value.label ?? value.value;
3692
- return {
3699
+ const item = {
3693
3700
  label: value.label ?? value.value,
3694
3701
  apply: insertText,
3695
3702
  detail: value.detail ?? (value.label && value.label !== value.value ? value.value : detail),
3696
3703
  type: "text",
3697
3704
  info: value.info
3698
3705
  };
3706
+ if (value.aliases?.length) {
3707
+ completionAliases.set(item, value.aliases.map((a) => a.toLowerCase()));
3708
+ }
3709
+ return item;
3699
3710
  });
3700
3711
  }
3712
+ function completionMatchesAliasOnly(option, typedLower) {
3713
+ const aliases = completionAliases.get(option);
3714
+ return aliases ? aliases.some((alias) => alias.includes(typedLower)) : false;
3715
+ }
3716
+ function completionMatchesWord(option, typedLower) {
3717
+ const inserted = (typeof option.apply === "string" ? option.apply : option.label).toLowerCase();
3718
+ const label = option.label.toLowerCase();
3719
+ if (inserted.startsWith(typedLower) || label.startsWith(typedLower)) return "prefix";
3720
+ if (inserted.includes(typedLower) || label.includes(typedLower)) return "word";
3721
+ if (completionMatchesAliasOnly(option, typedLower)) return "alias";
3722
+ return null;
3723
+ }
3701
3724
  function dialectWords(sport) {
3702
3725
  if (!sport) return [];
3703
3726
  const vocabulary = SPORT_VOCABULARY[SPORT_ALIASES[sport] ?? sport];
@@ -3764,6 +3787,14 @@ function whiteboardScriptCompletionSource(options = {}) {
3764
3787
  const before = line.text.slice(0, pos - line.from);
3765
3788
  const word = /([A-Za-z0-9-]*)$/.exec(before)[1];
3766
3789
  const beforeWord = before.slice(0, before.length - word.length);
3790
+ const actionMatch = /(\[:[a-zA-Z0-9-]*)$/.exec(before);
3791
+ if (actionMatch) {
3792
+ return {
3793
+ from: pos - actionMatch[1].length,
3794
+ options: ACTION_CUE_COMPLETIONS,
3795
+ validFor: /^\[:[a-zA-Z0-9-]*\]?$/
3796
+ };
3797
+ }
3767
3798
  if (beforeWord.endsWith("#") && options.tags) {
3768
3799
  return { from: pos - word.length, options: toCompletions(await options.tags(), "tag") };
3769
3800
  }
@@ -3788,9 +3819,27 @@ function whiteboardScriptCompletionSource(options = {}) {
3788
3819
  const effortOptions = [...keywords, ...efforts, ...equipmentPrefixes, ...sportWords];
3789
3820
  if (/^[ \t]*[A-Za-z][A-Za-z0-9]*$/.test(before)) {
3790
3821
  const supplied = suppliedPropertyKeys(context);
3822
+ const allStartOptions = [
3823
+ ...COMPLETION_PROPERTY_KEYS.filter((key) => !supplied.has(key)).map((key) => ({ label: key, detail: "property", type: "property", boost: 5 })),
3824
+ ...snippets,
3825
+ ...keywords,
3826
+ ...efforts,
3827
+ ...sportWords
3828
+ ];
3829
+ const typedStart = before.trimStart().toLowerCase();
3830
+ const hasAliasHit = typedStart.length >= 2 && effortOptions.some((opt) => completionMatchesWord(opt, typedStart) === "alias");
3831
+ if (hasAliasHit) {
3832
+ const matched = allStartOptions.filter((opt) => completionMatchesWord(opt, typedStart) !== null);
3833
+ return {
3834
+ from: pos - before.trimStart().length,
3835
+ options: matched,
3836
+ filter: false,
3837
+ validFor: /^[A-Za-z]*$/
3838
+ };
3839
+ }
3791
3840
  return {
3792
3841
  from: pos - before.trimStart().length,
3793
- options: [...COMPLETION_PROPERTY_KEYS.filter((key) => !supplied.has(key)).map((key) => ({ label: key, detail: "property", type: "property", boost: 5 })), ...snippets, ...keywords, ...efforts, ...sportWords],
3842
+ options: allStartOptions,
3794
3843
  validFor: /^[A-Za-z]*$/
3795
3844
  };
3796
3845
  }
@@ -3805,9 +3854,20 @@ function whiteboardScriptCompletionSource(options = {}) {
3805
3854
  (fragment) => fragment.firstChild?.name === "Action" && fragment.from < (quantity?.from ?? pos) && !context.state.doc.sliceString(fragment.from, fragment.to).includes(":")
3806
3855
  );
3807
3856
  if (quantity && !incompleteAction) {
3857
+ const wordText = completingWord ? context.state.doc.sliceString(last.from, pos).toLowerCase() : "";
3858
+ const hasAliasHit = wordText.length >= 2 && effortOptions.some((opt) => completionMatchesWord(opt, wordText) === "alias");
3859
+ const pool = [...quantity.getChild("AtSign") ? massUnitOptions : allUnitOptions, ...effortOptions];
3860
+ if (hasAliasHit && completingWord) {
3861
+ return {
3862
+ from: last.from,
3863
+ options: pool.filter((opt) => completionMatchesWord(opt, wordText) !== null),
3864
+ filter: false,
3865
+ validFor: /^[A-Za-z]*$/
3866
+ };
3867
+ }
3808
3868
  return {
3809
3869
  from: completingWord ? last.from : pos,
3810
- options: [...quantity.getChild("AtSign") ? massUnitOptions : allUnitOptions, ...effortOptions],
3870
+ options: pool,
3811
3871
  validFor: /^[A-Za-z]*$/
3812
3872
  };
3813
3873
  }
@@ -3826,11 +3886,14 @@ function whiteboardScriptCompletionSource(options = {}) {
3826
3886
  const last2 = effortRun[effortRun.length - 1];
3827
3887
  if (!first || !last2 || last2.to < pos) return null;
3828
3888
  const typed = context.state.doc.sliceString(first.from, pos).toLowerCase();
3829
- const compatible = effortOptions.filter((option) => {
3830
- const inserted = typeof option.apply === "string" ? option.apply : option.label;
3831
- return inserted.toLowerCase().startsWith(typed) || option.label.toLowerCase().startsWith(typed);
3832
- });
3833
- return { from: first.from, options: compatible, validFor: /^[A-Za-z ]*$/ };
3889
+ const compatible = effortOptions.filter((option) => completionMatchesWord(option, typed) !== null);
3890
+ const usesAlias = compatible.some((option) => completionMatchesWord(option, typed) === "alias");
3891
+ return {
3892
+ from: first.from,
3893
+ options: compatible,
3894
+ ...usesAlias ? { filter: false } : {},
3895
+ validFor: /^[A-Za-z ]*$/
3896
+ };
3834
3897
  }
3835
3898
  return null;
3836
3899
  };
@@ -6674,8 +6737,11 @@ var OutputEmitter = class {
6674
6737
  );
6675
6738
  }
6676
6739
  }
6677
- const fallbackStartMs = block.executionTiming?.startTime?.getTime() ?? fallbackEndMs;
6678
- const timeSpan = new TimeSpan(fallbackStartMs, fallbackEndMs);
6740
+ const recordedSpans = resultFragments.filter((m) => m.type === wodWikiCore.MetricType.Spans && Array.isArray(m.value)).flatMap((m) => m.value).filter((s) => typeof s?.started === "number" && Number.isFinite(s.started));
6741
+ const timeSpan = recordedSpans.length > 0 ? new TimeSpan(
6742
+ Math.min(...recordedSpans.map((s) => s.started)),
6743
+ Math.max(...recordedSpans.map((s) => typeof s.ended === "number" && Number.isFinite(s.ended) ? s.ended : fallbackEndMs))
6744
+ ) : new TimeSpan(block.executionTiming?.startTime?.getTime() ?? fallbackEndMs, fallbackEndMs);
6679
6745
  this.add(new wodWikiCore.OutputStatement({
6680
6746
  outputType: "segment",
6681
6747
  completionReason: block.completionReason,
@@ -11364,6 +11430,19 @@ var ReportOutputBehavior = class {
11364
11430
  }
11365
11431
  return metrics;
11366
11432
  }
11433
+ resolveFallbackTiming(ctx, nowMs) {
11434
+ if (ctx.block.blockType === "WaitingToStart") return null;
11435
+ const timing = ctx.block.executionTiming;
11436
+ const execStartMs = timing?.startTime?.getTime();
11437
+ if (execStartMs === void 0 || !Number.isFinite(execStartMs) || execStartMs > nowMs) {
11438
+ return null;
11439
+ }
11440
+ return {
11441
+ started: execStartMs,
11442
+ ended: nowMs,
11443
+ elapsedMs: Math.max(0, nowMs - execStartMs)
11444
+ };
11445
+ }
11367
11446
  computeTimeResults(ctx, timer, customRoundLabel) {
11368
11447
  const now = ctx.clock.currentDate;
11369
11448
  const nowMs = now.getTime();
@@ -11371,14 +11450,17 @@ var ReportOutputBehavior = class {
11371
11450
  const round = ctx.getMemoryByTag("round")[0]?.metrics[0];
11372
11451
  if (timer && timer.spans.length > 0) {
11373
11452
  const elapsed = calculateElapsed(timer, nowMs);
11374
- const firstStart = timer.spans[0].started;
11375
- const lastSpan = timer.spans[timer.spans.length - 1];
11453
+ const closedSpans = timer.spans.map(
11454
+ (s) => s.ended !== void 0 ? s : new TimeSpan(s.started, nowMs)
11455
+ );
11456
+ const firstStart = closedSpans[0].started;
11457
+ const lastSpan = closedSpans[closedSpans.length - 1];
11376
11458
  const lastEnd = lastSpan.ended ?? nowMs;
11377
11459
  const total = Math.max(0, lastEnd - firstStart);
11378
11460
  const metrics2 = wodWikiCore.MetricContainer.empty(blockKey).add(
11379
11461
  new ElapsedMetric(elapsed, blockKey, now),
11380
11462
  new TotalMetric(total, blockKey, now),
11381
- new SpansMetric([...timer.spans], blockKey, now),
11463
+ new SpansMetric(closedSpans, blockKey, now),
11382
11464
  new SystemTimeMetric(this._now.now(), blockKey)
11383
11465
  );
11384
11466
  if (round) {
@@ -11386,11 +11468,13 @@ var ReportOutputBehavior = class {
11386
11468
  }
11387
11469
  return metrics2;
11388
11470
  }
11389
- const degenerateSpan = new TimeSpan(nowMs, nowMs);
11471
+ const fallback = this.resolveFallbackTiming(ctx, nowMs);
11472
+ const span = fallback ? new TimeSpan(fallback.started, fallback.ended) : new TimeSpan(nowMs, nowMs);
11473
+ const fallbackElapsed = fallback?.elapsedMs ?? 0;
11390
11474
  const metrics = wodWikiCore.MetricContainer.empty(blockKey).add(
11391
- new ElapsedMetric(0, blockKey, now),
11392
- new TotalMetric(0, blockKey, now),
11393
- new SpansMetric([degenerateSpan], blockKey, now),
11475
+ new ElapsedMetric(fallbackElapsed, blockKey, now),
11476
+ new TotalMetric(fallbackElapsed, blockKey, now),
11477
+ new SpansMetric([span], blockKey, now),
11394
11478
  new SystemTimeMetric(this._now.now(), blockKey)
11395
11479
  );
11396
11480
  if (round) {
@@ -11398,29 +11482,7 @@ var ReportOutputBehavior = class {
11398
11482
  }
11399
11483
  return metrics;
11400
11484
  }
11401
- computeSplitTimeResults(ctx, timer, groups, customRoundLabel) {
11402
- const now = ctx.clock.currentDate;
11403
- const nowMs = now.getTime();
11404
- const blockKey = ctx.block.key.toString();
11405
- const round = ctx.getMemoryByTag("round")[0]?.metrics[0];
11406
- if (!timer || timer.spans.length === 0) {
11407
- return groups.map((group) => {
11408
- const groupFragments = group.clone().add(
11409
- new ElapsedMetric(0, blockKey, now),
11410
- new TotalMetric(0, blockKey, now),
11411
- new SpansMetric([new TimeSpan(nowMs, nowMs)], blockKey, now),
11412
- new SystemTimeMetric(this._now.now(), blockKey)
11413
- );
11414
- if (round) {
11415
- groupFragments.add(new CurrentRoundMetric(round.current, round.total, blockKey, now, customRoundLabel));
11416
- }
11417
- return groupFragments;
11418
- });
11419
- }
11420
- const totalElapsed = calculateElapsed(timer, nowMs);
11421
- const firstStart = timer.spans[0].started;
11422
- const lastEnd = timer.spans[timer.spans.length - 1].ended ?? nowMs;
11423
- const totalDuration = lastEnd - firstStart;
11485
+ buildWeightedSplitGroups(firstStart, totalElapsed, totalDuration, now, blockKey, round, groups, customRoundLabel) {
11424
11486
  const weights = groups.map((group) => {
11425
11487
  const reps = group.filter((f) => f.type === wodWikiCore.MetricType.Rep && typeof f.value === "number").reduce((sum, f) => sum + f.value, 0);
11426
11488
  return reps > 0 ? reps : 1;
@@ -11447,6 +11509,53 @@ var ReportOutputBehavior = class {
11447
11509
  return groupFragments;
11448
11510
  });
11449
11511
  }
11512
+ computeSplitTimeResults(ctx, timer, groups, customRoundLabel) {
11513
+ const now = ctx.clock.currentDate;
11514
+ const nowMs = now.getTime();
11515
+ const blockKey = ctx.block.key.toString();
11516
+ const round = ctx.getMemoryByTag("round")[0]?.metrics[0];
11517
+ if (!timer || timer.spans.length === 0) {
11518
+ const fallback = this.resolveFallbackTiming(ctx, nowMs);
11519
+ if (fallback) {
11520
+ return this.buildWeightedSplitGroups(
11521
+ fallback.started,
11522
+ fallback.elapsedMs,
11523
+ fallback.elapsedMs,
11524
+ now,
11525
+ blockKey,
11526
+ round,
11527
+ groups,
11528
+ customRoundLabel
11529
+ );
11530
+ }
11531
+ return groups.map((group) => {
11532
+ const groupFragments = group.clone().add(
11533
+ new ElapsedMetric(0, blockKey, now),
11534
+ new TotalMetric(0, blockKey, now),
11535
+ new SpansMetric([new TimeSpan(nowMs, nowMs)], blockKey, now),
11536
+ new SystemTimeMetric(this._now.now(), blockKey)
11537
+ );
11538
+ if (round) {
11539
+ groupFragments.add(new CurrentRoundMetric(round.current, round.total, blockKey, now, customRoundLabel));
11540
+ }
11541
+ return groupFragments;
11542
+ });
11543
+ }
11544
+ const totalElapsed = calculateElapsed(timer, nowMs);
11545
+ const firstStart = timer.spans[0].started;
11546
+ const lastEnd = timer.spans[timer.spans.length - 1].ended ?? nowMs;
11547
+ const totalDuration = lastEnd - firstStart;
11548
+ return this.buildWeightedSplitGroups(
11549
+ firstStart,
11550
+ totalElapsed,
11551
+ totalDuration,
11552
+ now,
11553
+ blockKey,
11554
+ round,
11555
+ groups,
11556
+ customRoundLabel
11557
+ );
11558
+ }
11450
11559
  writeResultMemory(ctx, resultFragments) {
11451
11560
  const existing = ctx.block.getMemoryByTag("metric:result");
11452
11561
  if (existing.length > 0) {