@bitcobblers/wod-wiki-lang 0.60.2258 → 0.62.2260
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/{ScriptOutlineProjection-BhzHfbnJ.d.cts → ScriptOutlineProjection-BFdSOLog.d.cts} +6 -1
- package/dist/{ScriptOutlineProjection-BhzHfbnJ.d.ts → ScriptOutlineProjection-BFdSOLog.d.ts} +6 -1
- package/dist/{chunk-2WQW2LJ3.mjs → chunk-74QMDNFW.mjs} +90 -19
- package/dist/chunk-74QMDNFW.mjs.map +1 -0
- package/dist/index.cjs +1571 -246
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -16
- package/dist/index.d.ts +52 -16
- package/dist/index.mjs +1484 -234
- package/dist/index.mjs.map +1 -1
- package/dist/react.cjs +86 -15
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.mjs +2 -2
- package/package.json +2 -2
- package/dist/chunk-2WQW2LJ3.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -283,14 +283,46 @@ var TIME_LIKE_TYPES = /* @__PURE__ */ new Set([
|
|
|
283
283
|
function isTimeLikeMetric(type) {
|
|
284
284
|
return TIME_LIKE_TYPES.has(type);
|
|
285
285
|
}
|
|
286
|
+
function dedupePresentedLabels(labels) {
|
|
287
|
+
const deduped = [];
|
|
288
|
+
for (const raw of labels) {
|
|
289
|
+
const label = raw.trim();
|
|
290
|
+
if (!label) continue;
|
|
291
|
+
const lower = label.toLowerCase();
|
|
292
|
+
const prev = deduped[deduped.length - 1]?.toLowerCase();
|
|
293
|
+
if (prev && (prev === lower || prev.endsWith(` ${lower}`))) continue;
|
|
294
|
+
deduped.push(label);
|
|
295
|
+
}
|
|
296
|
+
return deduped;
|
|
297
|
+
}
|
|
286
298
|
function baseText(metric) {
|
|
287
299
|
if (metric.image) return metric.image;
|
|
288
300
|
if (metric.value === void 0 || metric.value === null) return metric.type;
|
|
301
|
+
if (metric.value instanceof Date) {
|
|
302
|
+
return metric.value.toISOString();
|
|
303
|
+
}
|
|
304
|
+
if (Array.isArray(metric.value)) {
|
|
305
|
+
const spans = metric.value.filter(
|
|
306
|
+
(item) => Boolean(item) && typeof item === "object" && "started" in item && typeof item.started === "number"
|
|
307
|
+
);
|
|
308
|
+
if (spans.length > 0 && spans.length === metric.value.length) {
|
|
309
|
+
const totalMs = spans.reduce((acc, s) => acc + Math.max(0, (s.ended ?? s.started) - s.started), 0);
|
|
310
|
+
return formatDurationSmart(totalMs);
|
|
311
|
+
}
|
|
312
|
+
return metric.value.map((item) => String(item)).filter(Boolean).join(", ");
|
|
313
|
+
}
|
|
289
314
|
if (typeof metric.value === "object") {
|
|
290
315
|
const v = metric.value;
|
|
316
|
+
if ("amount" in v && "units" in v) {
|
|
317
|
+
return v.amount !== void 0 ? `${v.amount} ${v.units}` : String(v.units);
|
|
318
|
+
}
|
|
291
319
|
if ("text" in v) return String(v.text);
|
|
292
320
|
if ("current" in v) return `Round ${v.current}`;
|
|
293
|
-
|
|
321
|
+
if ("started" in v && typeof v.started === "number") {
|
|
322
|
+
const ended = typeof v.ended === "number" ? v.ended : v.started;
|
|
323
|
+
return formatDurationSmart(Math.max(0, ended - v.started));
|
|
324
|
+
}
|
|
325
|
+
return computeColumnLabel(metric.type);
|
|
294
326
|
}
|
|
295
327
|
return String(metric.value);
|
|
296
328
|
}
|
|
@@ -313,6 +345,24 @@ function formatTooltipValue(metric) {
|
|
|
313
345
|
return formatDurationSmart(metric.value);
|
|
314
346
|
}
|
|
315
347
|
const val = metric.value;
|
|
348
|
+
if (typeof val === "number" && Number.isFinite(val)) {
|
|
349
|
+
const formatted = Number.isInteger(val) ? String(val) : (Math.round(val * 10) / 10).toFixed(1);
|
|
350
|
+
return metric.unit ? `${formatted} ${metric.unit}` : formatted;
|
|
351
|
+
}
|
|
352
|
+
if (val instanceof Date) {
|
|
353
|
+
return val.toISOString();
|
|
354
|
+
}
|
|
355
|
+
if (Array.isArray(val)) {
|
|
356
|
+
if (metric.image) return metric.image;
|
|
357
|
+
const spans = val.filter(
|
|
358
|
+
(item) => Boolean(item) && typeof item === "object" && "started" in item && typeof item.started === "number"
|
|
359
|
+
);
|
|
360
|
+
if (spans.length > 0 && spans.length === val.length) {
|
|
361
|
+
const totalMs = spans.reduce((acc, s) => acc + Math.max(0, (s.ended ?? s.started) - s.started), 0);
|
|
362
|
+
return formatDurationSmart(totalMs);
|
|
363
|
+
}
|
|
364
|
+
return val.map((item) => String(item)).filter(Boolean).join(", ");
|
|
365
|
+
}
|
|
316
366
|
if (val !== null && typeof val === "object") {
|
|
317
367
|
if (metric.image) return metric.image;
|
|
318
368
|
const obj = val;
|
|
@@ -321,11 +371,23 @@ function formatTooltipValue(metric) {
|
|
|
321
371
|
}
|
|
322
372
|
if ("text" in obj) return String(obj.text);
|
|
323
373
|
if ("current" in obj) return `Round ${obj.current}`;
|
|
324
|
-
|
|
374
|
+
if ("started" in obj && typeof obj.started === "number") {
|
|
375
|
+
const ended = typeof obj.ended === "number" ? obj.ended : obj.started;
|
|
376
|
+
return formatDurationSmart(Math.max(0, ended - obj.started));
|
|
377
|
+
}
|
|
378
|
+
return computeColumnLabel(metric.type);
|
|
325
379
|
}
|
|
326
|
-
|
|
380
|
+
if (metric.image && metric.unit && typeof val === "string" && !val.includes(metric.unit)) {
|
|
381
|
+
return metric.image;
|
|
382
|
+
}
|
|
383
|
+
return val !== void 0 && val !== null ? String(val) : metric.image ?? computeColumnLabel(metric.type);
|
|
327
384
|
}
|
|
328
|
-
function buildTooltip(metric) {
|
|
385
|
+
function buildTooltip(metric, surface) {
|
|
386
|
+
if (surface && surface !== "debug") {
|
|
387
|
+
const heading2 = computeColumnLabel(metric.type);
|
|
388
|
+
const valText = formatTooltipValue(metric);
|
|
389
|
+
return valText ? `${heading2}: ${valText}` : heading2;
|
|
390
|
+
}
|
|
329
391
|
const parts = [];
|
|
330
392
|
parts.push(`Type: ${metric.type}`);
|
|
331
393
|
if (metric.value !== void 0) parts.push(`Value: ${formatTooltipValue(metric)}`);
|
|
@@ -601,6 +663,18 @@ function createPolicy() {
|
|
|
601
663
|
const t2 = metric.type;
|
|
602
664
|
if ((t2 === wodWikiCore.MetricType.Sound || t2 === "sound") && surface !== "debug") return true;
|
|
603
665
|
if (t2.startsWith(TAG_MARKER_PREFIX) && surface !== "debug") return true;
|
|
666
|
+
if (surface !== "debug") {
|
|
667
|
+
if (t2 === wodWikiCore.MetricType.SystemTime || t2 === "system-time" || t2 === wodWikiCore.MetricType.Spans || t2 === "spans") {
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
if (t2 === wodWikiCore.MetricType.Equipment || t2 === "equipment") {
|
|
671
|
+
const refMeta = metric.metadata?.[wodWikiCore.REFERENCE_METADATA_KEY];
|
|
672
|
+
const directMatched = metric.metadata?.matched;
|
|
673
|
+
if (metric.origin === "compiler" || refMeta?.matched === "whole" || directMatched === "whole") {
|
|
674
|
+
return true;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
604
678
|
if (surface === "review-grid-column") {
|
|
605
679
|
if (t2 === wodWikiCore.MetricType.Elapsed || t2 === "elapsed" || t2 === wodWikiCore.MetricType.Total || t2 === "total") return true;
|
|
606
680
|
if (t2 === wodWikiCore.MetricType.System || t2 === "system") return true;
|
|
@@ -628,7 +702,7 @@ function createPolicy() {
|
|
|
628
702
|
return {
|
|
629
703
|
metric,
|
|
630
704
|
label: computeLabel(metric),
|
|
631
|
-
tooltip: buildTooltip(metric),
|
|
705
|
+
tooltip: buildTooltip(metric, surface),
|
|
632
706
|
renderKind,
|
|
633
707
|
tone: computeTone(metric, rest),
|
|
634
708
|
iconKey: rest ? "rest" : metric.type,
|
|
@@ -1669,6 +1743,7 @@ var DurationMetric = class {
|
|
|
1669
1743
|
seconds;
|
|
1670
1744
|
original;
|
|
1671
1745
|
type = wodWikiCore.MetricType.Duration;
|
|
1746
|
+
unit = "ms";
|
|
1672
1747
|
/**
|
|
1673
1748
|
* Determines the intended timer direction based on value and modifiers.
|
|
1674
1749
|
* - If forceCountUp is true (^ modifier), always returns 'up'
|
|
@@ -1891,6 +1966,24 @@ function classifyStatements(facts, references) {
|
|
|
1891
1966
|
}
|
|
1892
1967
|
function equipmentMeta(resolution, authored, meta2) {
|
|
1893
1968
|
if (resolution.matched !== "split" || !resolution.remaining) return meta2;
|
|
1969
|
+
if (resolution.equipmentSpan) {
|
|
1970
|
+
const leadingTrim = authored.length - authored.trimStart().length;
|
|
1971
|
+
const start = leadingTrim + resolution.equipmentSpan.start;
|
|
1972
|
+
const end = leadingTrim + resolution.equipmentSpan.end;
|
|
1973
|
+
const raw2 = meta2.raw.slice(start, end);
|
|
1974
|
+
const length2 = raw2.length;
|
|
1975
|
+
if (length2 > 0) {
|
|
1976
|
+
return {
|
|
1977
|
+
...meta2,
|
|
1978
|
+
startOffset: meta2.startOffset + start,
|
|
1979
|
+
endOffset: meta2.startOffset + end,
|
|
1980
|
+
length: length2,
|
|
1981
|
+
columnStart: meta2.columnStart + start,
|
|
1982
|
+
columnEnd: meta2.columnStart + end,
|
|
1983
|
+
raw: raw2
|
|
1984
|
+
};
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1894
1987
|
const prefixEnd = authored.trimEnd().length - resolution.remaining.length;
|
|
1895
1988
|
if (prefixEnd <= 0) return meta2;
|
|
1896
1989
|
const raw = meta2.raw.slice(0, prefixEnd).trimEnd();
|
|
@@ -1921,7 +2014,7 @@ function applyReferenceResolution(pairs, fact, references) {
|
|
|
1921
2014
|
}
|
|
1922
2015
|
if (resolution.equipment.length > 0) {
|
|
1923
2016
|
const eqMeta = equipmentMeta(resolution, authored, meta2);
|
|
1924
|
-
const eqSource = resolution.matched === "split" ? eqMeta.raw : resolution.matched === "explicit" ? resolution.equipment.map((ref) => ref.label).join(", ") : authored;
|
|
2017
|
+
const eqSource = resolution.matched === "split" ? eqMeta.raw : resolution.matched === "explicit" || resolution.matched === "whole" ? resolution.equipment.map((ref) => ref.label).join(", ") : authored;
|
|
1925
2018
|
result.push({
|
|
1926
2019
|
metrics: new EquipmentMetric(
|
|
1927
2020
|
resolution.equipment.map((ref) => ref.slug),
|
|
@@ -1929,7 +2022,8 @@ function applyReferenceResolution(pairs, fact, references) {
|
|
|
1929
2022
|
refs: resolution.equipment,
|
|
1930
2023
|
source: eqSource,
|
|
1931
2024
|
matched: resolution.matched,
|
|
1932
|
-
diagnostics: resolution.diagnostics
|
|
2025
|
+
diagnostics: resolution.diagnostics,
|
|
2026
|
+
...resolution.matched === "whole" ? { origin: "compiler" } : {}
|
|
1933
2027
|
}
|
|
1934
2028
|
),
|
|
1935
2029
|
meta: eqMeta
|
|
@@ -2047,14 +2141,15 @@ function resolveFusedEffortReferences(statements, references) {
|
|
|
2047
2141
|
}
|
|
2048
2142
|
if (resolution.equipment.length > 0) {
|
|
2049
2143
|
const eqMeta = meta2 ? equipmentMeta(resolution, authored, meta2) : void 0;
|
|
2050
|
-
const eqSource = resolution.matched === "split" && eqMeta ? eqMeta.raw : authored;
|
|
2144
|
+
const eqSource = resolution.matched === "split" && eqMeta ? eqMeta.raw : resolution.matched === "whole" || resolution.matched === "explicit" ? resolution.equipment.map((ref) => ref.label).join(", ") : authored;
|
|
2051
2145
|
const eqMetric = new EquipmentMetric(
|
|
2052
2146
|
resolution.equipment.map((ref) => ref.slug),
|
|
2053
2147
|
{
|
|
2054
2148
|
refs: resolution.equipment,
|
|
2055
2149
|
source: eqSource,
|
|
2056
2150
|
matched: resolution.matched,
|
|
2057
|
-
diagnostics: resolution.diagnostics
|
|
2151
|
+
diagnostics: resolution.diagnostics,
|
|
2152
|
+
...resolution.matched === "whole" ? { origin: "compiler" } : {}
|
|
2058
2153
|
}
|
|
2059
2154
|
);
|
|
2060
2155
|
nextMetrics.push(eqMetric);
|
|
@@ -3566,60 +3661,123 @@ tagHighlighter([
|
|
|
3566
3661
|
{ tag: tags.invalid, class: "tok-invalid" },
|
|
3567
3662
|
{ tag: tags.punctuation, class: "tok-punctuation" }
|
|
3568
3663
|
]);
|
|
3664
|
+
|
|
3665
|
+
// src/effort-registry/fuzzyMatch.ts
|
|
3666
|
+
function levenshteinDistance(a, b) {
|
|
3667
|
+
if (a === b) return 0;
|
|
3668
|
+
if (a.length === 0) return b.length;
|
|
3669
|
+
if (b.length === 0) return a.length;
|
|
3670
|
+
if (a.length > b.length) {
|
|
3671
|
+
const tmp = a;
|
|
3672
|
+
a = b;
|
|
3673
|
+
b = tmp;
|
|
3674
|
+
}
|
|
3675
|
+
const m = a.length;
|
|
3676
|
+
const n = b.length;
|
|
3677
|
+
let prev = new Uint32Array(m + 1);
|
|
3678
|
+
let curr = new Uint32Array(m + 1);
|
|
3679
|
+
for (let i = 0; i <= m; i++) {
|
|
3680
|
+
prev[i] = i;
|
|
3681
|
+
}
|
|
3682
|
+
for (let j = 1; j <= n; j++) {
|
|
3683
|
+
curr[0] = j;
|
|
3684
|
+
const bj = b.charCodeAt(j - 1);
|
|
3685
|
+
for (let i = 1; i <= m; i++) {
|
|
3686
|
+
const cost = a.charCodeAt(i - 1) === bj ? 0 : 1;
|
|
3687
|
+
curr[i] = Math.min(
|
|
3688
|
+
prev[i] + 1,
|
|
3689
|
+
// deletion
|
|
3690
|
+
curr[i - 1] + 1,
|
|
3691
|
+
// insertion
|
|
3692
|
+
prev[i - 1] + cost
|
|
3693
|
+
// substitution
|
|
3694
|
+
);
|
|
3695
|
+
}
|
|
3696
|
+
const swap = prev;
|
|
3697
|
+
prev = curr;
|
|
3698
|
+
curr = swap;
|
|
3699
|
+
}
|
|
3700
|
+
return prev[m];
|
|
3701
|
+
}
|
|
3702
|
+
function normalizeForFuzzy(input) {
|
|
3703
|
+
return input.toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu, " ").replace(/[-_]+/g, " ").trim().replace(/\s+/g, " ");
|
|
3704
|
+
}
|
|
3705
|
+
function isWithinThreshold(a, b, threshold) {
|
|
3706
|
+
const na = normalizeForFuzzy(a);
|
|
3707
|
+
const nb = normalizeForFuzzy(b);
|
|
3708
|
+
if (na === nb) return true;
|
|
3709
|
+
if (Math.abs(na.length - nb.length) > threshold) return false;
|
|
3710
|
+
return levenshteinDistance(na, nb) <= threshold;
|
|
3711
|
+
}
|
|
3712
|
+
function findBestFuzzyMatch(query, candidates, threshold) {
|
|
3713
|
+
const nq = normalizeForFuzzy(query);
|
|
3714
|
+
let best = null;
|
|
3715
|
+
for (const candidate of candidates) {
|
|
3716
|
+
const nc = normalizeForFuzzy(candidate);
|
|
3717
|
+
if (Math.abs(nq.length - nc.length) > threshold) continue;
|
|
3718
|
+
const distance = levenshteinDistance(nq, nc);
|
|
3719
|
+
if (distance > threshold) continue;
|
|
3720
|
+
if (!best || distance < best.distance) {
|
|
3721
|
+
best = { target: candidate, distance };
|
|
3722
|
+
if (distance === 0) break;
|
|
3723
|
+
}
|
|
3724
|
+
}
|
|
3725
|
+
return best;
|
|
3726
|
+
}
|
|
3569
3727
|
var whiteboardScriptSnippets = [
|
|
3570
|
-
{
|
|
3571
|
-
name: "circuit",
|
|
3572
|
-
label: "Circuit",
|
|
3573
|
-
detail: "Rounds over indented movements",
|
|
3574
|
-
template: "(${1:3})\n ${2:10 Air Squats}\n ${3:10 Push Ups}\n ${4:10 Ring Rows}\n${0}"
|
|
3575
|
-
},
|
|
3576
|
-
{
|
|
3577
|
-
name: "5x5",
|
|
3578
|
-
label: "5x5",
|
|
3579
|
-
detail: "Inline strength sets",
|
|
3580
|
-
template: "${1:5}x${2:5} ${3:Back Squat} @${4:100kg}\n${0}"
|
|
3581
|
-
},
|
|
3582
3728
|
{
|
|
3583
3729
|
name: "emom",
|
|
3584
3730
|
label: "EMOM",
|
|
3585
3731
|
detail: "Every minute on the minute",
|
|
3586
|
-
template: "(${1:10}) ${2::60 EMOM}\n + ${3:
|
|
3732
|
+
template: "(${1:10}) ${2::60 EMOM}\n + ${3:10 Kettlebell Swing} @${4:24kg} #emom\n${0}"
|
|
3587
3733
|
},
|
|
3588
3734
|
{
|
|
3589
3735
|
name: "amrap",
|
|
3590
3736
|
label: "AMRAP",
|
|
3591
|
-
detail: "As many rounds as possible",
|
|
3592
|
-
template: "${1:
|
|
3737
|
+
detail: "As many rounds as possible in time cap",
|
|
3738
|
+
template: "${1:12:00 AMRAP}\n ${2:10 Pull-up}\n ${3:15 Push-up}\n ${4:200m Run} #amrap\n${0}"
|
|
3593
3739
|
},
|
|
3594
3740
|
{
|
|
3595
3741
|
name: "tabata",
|
|
3596
3742
|
label: "Tabata",
|
|
3597
|
-
detail: "
|
|
3598
|
-
template: "(${1:8}) ${2::20 Work}\n * ${3::10
|
|
3743
|
+
detail: "8 intervals of 20s work / 10s rest",
|
|
3744
|
+
template: "(${1:8}) ${2::20 Work}\n * ${3::10} [:rest]\n ${4:10 Air Squat} #tabata\n${0}"
|
|
3745
|
+
},
|
|
3746
|
+
{
|
|
3747
|
+
name: "5x5",
|
|
3748
|
+
label: "5x5",
|
|
3749
|
+
detail: "Sets \xD7 reps barbell progression",
|
|
3750
|
+
template: "${1:5}x${2:5} ${3:Back Squat} @${4:100kg} *${5:2:00} #strength\n${0}"
|
|
3751
|
+
},
|
|
3752
|
+
{
|
|
3753
|
+
name: "circuit",
|
|
3754
|
+
label: "Circuit",
|
|
3755
|
+
detail: "Multi-station timed rounds",
|
|
3756
|
+
template: "(${1:3})\n ${2:400m Run}\n ${3:15 Wall Ball} @${4:9kg}\n *${5:1:00} [:rest]\n${0}"
|
|
3599
3757
|
},
|
|
3600
3758
|
{
|
|
3601
3759
|
name: "ladder",
|
|
3602
3760
|
label: "Ladder",
|
|
3603
|
-
detail: "
|
|
3604
|
-
template: "(${1:21-15-9})\n ${2:
|
|
3761
|
+
detail: "Descending rep scheme (21-15-9)",
|
|
3762
|
+
template: "(${1:21-15-9})\n ${2:Thruster} @${3:43kg}\n ${4:Pull-up} #for-time\n${0}"
|
|
3605
3763
|
},
|
|
3606
3764
|
{
|
|
3607
3765
|
name: "choice",
|
|
3608
3766
|
label: "Choice",
|
|
3609
|
-
detail: "
|
|
3610
|
-
template: "${1:
|
|
3767
|
+
detail: "Scaled or equipment alternative (A | B)",
|
|
3768
|
+
template: "(${1:5})\n ${2:15 Kettlebell Swing} ${3:24 | 16 kg}\n${0}"
|
|
3611
3769
|
},
|
|
3612
3770
|
{
|
|
3613
3771
|
name: "superset",
|
|
3614
3772
|
label: "Superset",
|
|
3615
3773
|
detail: "Compound set via + lap markers",
|
|
3616
|
-
template: "+ ${1:5 Pull
|
|
3774
|
+
template: "+ ${1:5 Pull-up}\n+ ${2:10 Push-up}\n${0}"
|
|
3617
3775
|
},
|
|
3618
3776
|
{
|
|
3619
3777
|
name: "collectible",
|
|
3620
3778
|
label: "Collectible",
|
|
3621
|
-
detail: "
|
|
3622
|
-
template: "${1::?
|
|
3779
|
+
detail: "Open clock measure-until-done (:?)",
|
|
3780
|
+
template: "${1::? 2000m Row} #for-time\n${0}"
|
|
3623
3781
|
}
|
|
3624
3782
|
];
|
|
3625
3783
|
function applyTemplateDefaults(template) {
|
|
@@ -3630,6 +3788,8 @@ function snippetCompletions() {
|
|
|
3630
3788
|
(snippet) => autocomplete.snippetCompletion(snippet.template, {
|
|
3631
3789
|
label: snippet.label,
|
|
3632
3790
|
detail: snippet.detail,
|
|
3791
|
+
info: applyTemplateDefaults(snippet.template).trim(),
|
|
3792
|
+
section: { name: "Templates", rank: 3 },
|
|
3633
3793
|
type: "text",
|
|
3634
3794
|
boost: 10
|
|
3635
3795
|
})
|
|
@@ -3637,17 +3797,102 @@ function snippetCompletions() {
|
|
|
3637
3797
|
}
|
|
3638
3798
|
|
|
3639
3799
|
// src/parser/completion.ts
|
|
3800
|
+
var COMPLETION_SECTIONS = {
|
|
3801
|
+
units: { name: "Units", rank: 1 },
|
|
3802
|
+
inNotebook: { name: "In this notebook", rank: 2 },
|
|
3803
|
+
templates: { name: "Templates", rank: 3 },
|
|
3804
|
+
actionCues: { name: "Action Cues", rank: 4 },
|
|
3805
|
+
structure: { name: "Structure", rank: 5 },
|
|
3806
|
+
movements: { name: "Movements", rank: 6 },
|
|
3807
|
+
tags: { name: "Tags", rank: 7 },
|
|
3808
|
+
equipment: { name: "Equipment", rank: 8 },
|
|
3809
|
+
sounds: { name: "Sounds", rank: 9 },
|
|
3810
|
+
dialect: { name: "Dialect", rank: 10 },
|
|
3811
|
+
blockProperties: { name: "Block Properties", rank: 20 },
|
|
3812
|
+
unitAliases: { name: "Unit Aliases", rank: 50 },
|
|
3813
|
+
create: { name: "Create", rank: 90 }
|
|
3814
|
+
};
|
|
3815
|
+
var SECTION_BY_NAME = Object.fromEntries(
|
|
3816
|
+
Object.values(COMPLETION_SECTIONS).map((section) => [section.name.toLowerCase(), section])
|
|
3817
|
+
);
|
|
3818
|
+
function resolveSection(section) {
|
|
3819
|
+
if (!section) return void 0;
|
|
3820
|
+
if (typeof section === "object") return section;
|
|
3821
|
+
return SECTION_BY_NAME[section.toLowerCase()] ?? { name: section, rank: 15 };
|
|
3822
|
+
}
|
|
3640
3823
|
var COMPLETION_PROPERTY_KEYS = ["effort", "equipment", ...Object.keys(PROPERTY_KEY_TO_METRIC_TYPE)];
|
|
3641
3824
|
var STRUCTURE_KEYWORD_LABELS = ["amrap", "emom", "tabata", "for time", "rest"];
|
|
3642
3825
|
var STRUCTURE_KEYWORD_DISPLAY = {
|
|
3643
3826
|
"for time": "FOR TIME",
|
|
3644
3827
|
rest: "Rest"
|
|
3645
3828
|
};
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3829
|
+
var COUNT_QUALIFIER_WORDS = /^(reps?|rounds?|rds?|sets?|laps?|cycles?|intervals?)$/i;
|
|
3830
|
+
var ROUNDS_QUALIFIER_WORDS = /^(rounds?|rds?|sets?|laps?|cycles?|intervals?)$/i;
|
|
3831
|
+
var PRIMARY_UNIT_BOOST = {
|
|
3832
|
+
kg: 30,
|
|
3833
|
+
lb: 29,
|
|
3834
|
+
m: 28,
|
|
3835
|
+
km: 27,
|
|
3836
|
+
cal: 26,
|
|
3837
|
+
mi: 25,
|
|
3838
|
+
ft: 24,
|
|
3839
|
+
kcal: 23
|
|
3840
|
+
};
|
|
3841
|
+
function clampBoost(value) {
|
|
3842
|
+
return Math.max(-99, Math.min(99, Math.round(value)));
|
|
3843
|
+
}
|
|
3844
|
+
function unitCompletions(units, dimension, preferredSet) {
|
|
3845
|
+
return units.toArray().filter((def) => !dimension || def.dimension === dimension).flatMap((def) => {
|
|
3846
|
+
const canonicalLower = def.canonical.toLowerCase();
|
|
3847
|
+
const canonicalBoost = preferredSet?.has(canonicalLower) ? 40 : PRIMARY_UNIT_BOOST[canonicalLower] ?? 20;
|
|
3848
|
+
const canonicalOption = {
|
|
3849
|
+
label: def.canonical,
|
|
3850
|
+
detail: def.dimension,
|
|
3851
|
+
type: "unit",
|
|
3852
|
+
section: COMPLETION_SECTIONS.units,
|
|
3853
|
+
boost: canonicalBoost
|
|
3854
|
+
};
|
|
3855
|
+
if (def.aliases.length > 0) {
|
|
3856
|
+
completionAliases.set(canonicalOption, def.aliases.map((a) => a.toLowerCase()));
|
|
3857
|
+
}
|
|
3858
|
+
return [
|
|
3859
|
+
canonicalOption,
|
|
3860
|
+
...def.aliases.map((alias) => ({
|
|
3861
|
+
label: alias,
|
|
3862
|
+
detail: def.dimension,
|
|
3863
|
+
type: "unit",
|
|
3864
|
+
section: COMPLETION_SECTIONS.unitAliases,
|
|
3865
|
+
boost: preferredSet?.has(alias.toLowerCase()) ? 35 : 5
|
|
3866
|
+
}))
|
|
3867
|
+
];
|
|
3868
|
+
});
|
|
3869
|
+
}
|
|
3870
|
+
function makeCountQualifiers(includeRounds, needsLeadingSpace, ladderDetail) {
|
|
3871
|
+
const space = needsLeadingSpace ? " " : "";
|
|
3872
|
+
const items = [
|
|
3873
|
+
{
|
|
3874
|
+
label: "reps",
|
|
3875
|
+
detail: ladderDetail ?? "count",
|
|
3876
|
+
type: "unit",
|
|
3877
|
+
section: COMPLETION_SECTIONS.units,
|
|
3878
|
+
apply: `${space}reps`,
|
|
3879
|
+
boost: ladderDetail ? 45 : 38
|
|
3880
|
+
}
|
|
3881
|
+
];
|
|
3882
|
+
completionAliases.set(items[0], ["rep"]);
|
|
3883
|
+
if (includeRounds) {
|
|
3884
|
+
const roundsOpt = {
|
|
3885
|
+
label: "rounds",
|
|
3886
|
+
detail: "rounds",
|
|
3887
|
+
type: "unit",
|
|
3888
|
+
section: COMPLETION_SECTIONS.units,
|
|
3889
|
+
apply: `${space}rounds`,
|
|
3890
|
+
boost: 37
|
|
3891
|
+
};
|
|
3892
|
+
completionAliases.set(roundsOpt, ["round", "rd", "rds", "set", "sets"]);
|
|
3893
|
+
items.push(roundsOpt);
|
|
3894
|
+
}
|
|
3895
|
+
return items;
|
|
3651
3896
|
}
|
|
3652
3897
|
function titleCase(word) {
|
|
3653
3898
|
return word.toLowerCase().replace(/(^|[\s])([a-z])/g, (_, lead, ch) => lead + ch.toUpperCase());
|
|
@@ -3659,22 +3904,24 @@ var SPORT_VOCABULARY = {
|
|
|
3659
3904
|
cardio: () => unique(CARDIO_ACTIVITY_KEYWORDS.flatMap((activity) => activity.keywords)).map((word) => ({
|
|
3660
3905
|
label: titleCase(word),
|
|
3661
3906
|
detail: "cardio",
|
|
3662
|
-
type: "text"
|
|
3907
|
+
type: "text",
|
|
3908
|
+
section: COMPLETION_SECTIONS.dialect
|
|
3663
3909
|
})),
|
|
3664
3910
|
yoga: () => unique([
|
|
3665
3911
|
...YogaDialect.POSE_KEYWORDS,
|
|
3666
3912
|
...YogaDialect.FLOW_KEYWORDS,
|
|
3667
3913
|
...YogaDialect.BREATHING_KEYWORDS,
|
|
3668
3914
|
...YogaDialect.MEDITATION_KEYWORDS
|
|
3669
|
-
]).filter((word) => /^[A-Z ]+$/.test(word)).map((word) => ({ label: titleCase(word), detail: "yoga", type: "text" })),
|
|
3915
|
+
]).filter((word) => /^[A-Z ]+$/.test(word)).map((word) => ({ label: titleCase(word), detail: "yoga", type: "text", section: COMPLETION_SECTIONS.dialect })),
|
|
3670
3916
|
habits: () => unique([...HabitsDialect.HABIT_KEYWORDS, ...HabitsDialect.STREAK_KEYWORDS]).map((word) => ({
|
|
3671
3917
|
label: titleCase(word),
|
|
3672
3918
|
detail: "habits",
|
|
3673
|
-
type: "text"
|
|
3919
|
+
type: "text",
|
|
3920
|
+
section: COMPLETION_SECTIONS.dialect
|
|
3674
3921
|
})),
|
|
3675
3922
|
climb: () => [
|
|
3676
|
-
...unique(Object.values(SEND_ALIASES)).map((send) => ({ label: send, detail: "send", type: "text" })),
|
|
3677
|
-
...unique(Object.values(DISCIPLINE_KEYWORDS)).map((discipline) => ({ label: discipline, detail: "discipline", type: "text" }))
|
|
3923
|
+
...unique(Object.values(SEND_ALIASES)).map((send) => ({ label: send, detail: "send", type: "text", section: COMPLETION_SECTIONS.dialect })),
|
|
3924
|
+
...unique(Object.values(DISCIPLINE_KEYWORDS)).map((discipline) => ({ label: discipline, detail: "discipline", type: "text", section: COMPLETION_SECTIONS.dialect }))
|
|
3678
3925
|
]
|
|
3679
3926
|
};
|
|
3680
3927
|
function structureKeywords() {
|
|
@@ -3682,26 +3929,44 @@ function structureKeywords() {
|
|
|
3682
3929
|
label: STRUCTURE_KEYWORD_DISPLAY[word] ?? word.toUpperCase(),
|
|
3683
3930
|
detail: "structure",
|
|
3684
3931
|
type: "keyword",
|
|
3932
|
+
section: COMPLETION_SECTIONS.structure,
|
|
3685
3933
|
boost: 5,
|
|
3686
3934
|
apply: STRUCTURE_KEYWORD_DISPLAY[word] ?? word.toUpperCase()
|
|
3687
3935
|
}));
|
|
3688
3936
|
}
|
|
3689
3937
|
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 }
|
|
3938
|
+
{ label: "[:rest]", detail: "Rest cue", type: "keyword", section: COMPLETION_SECTIONS.actionCues, apply: "[:rest] ", boost: 20 },
|
|
3939
|
+
{ label: "[:next]", detail: "Advance segment", type: "keyword", section: COMPLETION_SECTIONS.actionCues, apply: "[:next] ", boost: 15 },
|
|
3940
|
+
{ label: "[:done]", detail: "Complete block", type: "keyword", section: COMPLETION_SECTIONS.actionCues, apply: "[:done] ", boost: 12 },
|
|
3941
|
+
{ label: "[:mark]", detail: "Split / lap marker", type: "keyword", section: COMPLETION_SECTIONS.actionCues, apply: "[:mark] ", boost: 10 }
|
|
3694
3942
|
];
|
|
3943
|
+
var DEFAULT_SECTION_BY_KIND = {
|
|
3944
|
+
effort: COMPLETION_SECTIONS.movements,
|
|
3945
|
+
equipment: COMPLETION_SECTIONS.equipment,
|
|
3946
|
+
sound: COMPLETION_SECTIONS.sounds,
|
|
3947
|
+
tag: COMPLETION_SECTIONS.tags
|
|
3948
|
+
};
|
|
3949
|
+
var COMPLETION_TYPE_BY_KIND = {
|
|
3950
|
+
effort: "variable",
|
|
3951
|
+
equipment: "text",
|
|
3952
|
+
sound: "constant",
|
|
3953
|
+
tag: "constant"
|
|
3954
|
+
};
|
|
3695
3955
|
var completionAliases = /* @__PURE__ */ new WeakMap();
|
|
3696
3956
|
function toCompletions(values, detail, quoteValues = false) {
|
|
3957
|
+
const defaultSection = DEFAULT_SECTION_BY_KIND[detail];
|
|
3958
|
+
const completionType = COMPLETION_TYPE_BY_KIND[detail] ?? "text";
|
|
3697
3959
|
return values.map((value) => {
|
|
3698
3960
|
const insertText = quoteValues ? !/^[A-Za-z][A-Za-z0-9]*$/.test(value.value) ? JSON.stringify(value.value) : value.value : value.label ?? value.value;
|
|
3961
|
+
const resolvedSection = resolveSection(value.section) ?? defaultSection;
|
|
3699
3962
|
const item = {
|
|
3700
3963
|
label: value.label ?? value.value,
|
|
3701
3964
|
apply: insertText,
|
|
3702
3965
|
detail: value.detail ?? (value.label && value.label !== value.value ? value.value : detail),
|
|
3703
|
-
type:
|
|
3704
|
-
info: value.info
|
|
3966
|
+
type: completionType,
|
|
3967
|
+
info: value.info,
|
|
3968
|
+
...value.boost !== void 0 ? { boost: clampBoost(value.boost) } : {},
|
|
3969
|
+
...resolvedSection ? { section: resolvedSection } : {}
|
|
3705
3970
|
};
|
|
3706
3971
|
if (value.aliases?.length) {
|
|
3707
3972
|
completionAliases.set(item, value.aliases.map((a) => a.toLowerCase()));
|
|
@@ -3709,6 +3974,256 @@ function toCompletions(values, detail, quoteValues = false) {
|
|
|
3709
3974
|
return item;
|
|
3710
3975
|
});
|
|
3711
3976
|
}
|
|
3977
|
+
function damerauDistance(a, b) {
|
|
3978
|
+
if (a === b) return 0;
|
|
3979
|
+
const m = a.length;
|
|
3980
|
+
const n = b.length;
|
|
3981
|
+
if (m === 0) return n;
|
|
3982
|
+
if (n === 0) return m;
|
|
3983
|
+
const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
3984
|
+
for (let i = 0; i <= m; i++) dp[i][0] = i;
|
|
3985
|
+
for (let j = 0; j <= n; j++) dp[0][j] = j;
|
|
3986
|
+
for (let i = 1; i <= m; i++) {
|
|
3987
|
+
for (let j = 1; j <= n; j++) {
|
|
3988
|
+
const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
|
|
3989
|
+
let val = Math.min(
|
|
3990
|
+
dp[i - 1][j] + 1,
|
|
3991
|
+
dp[i][j - 1] + 1,
|
|
3992
|
+
dp[i - 1][j - 1] + cost
|
|
3993
|
+
);
|
|
3994
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
3995
|
+
val = Math.min(val, dp[i - 2][j - 2] + 1);
|
|
3996
|
+
}
|
|
3997
|
+
dp[i][j] = val;
|
|
3998
|
+
}
|
|
3999
|
+
}
|
|
4000
|
+
return dp[m][n];
|
|
4001
|
+
}
|
|
4002
|
+
function isOrderedSubsequence(needle, haystack) {
|
|
4003
|
+
if (needle.length < 3 || haystack.length > 28) return false;
|
|
4004
|
+
if (needle[0] !== haystack[0]) return false;
|
|
4005
|
+
let i = 0;
|
|
4006
|
+
for (let j = 0; j < haystack.length && i < needle.length; j++) {
|
|
4007
|
+
if (needle[i] === haystack[j]) i++;
|
|
4008
|
+
}
|
|
4009
|
+
return i === needle.length;
|
|
4010
|
+
}
|
|
4011
|
+
function dedupeStrings(values) {
|
|
4012
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4013
|
+
const out = [];
|
|
4014
|
+
for (const v of values) {
|
|
4015
|
+
if (!v || seen.has(v)) continue;
|
|
4016
|
+
seen.add(v);
|
|
4017
|
+
out.push(v);
|
|
4018
|
+
}
|
|
4019
|
+
return out;
|
|
4020
|
+
}
|
|
4021
|
+
function buildCatalogIndex(rawEfforts, rawEquipment) {
|
|
4022
|
+
const eqCompletions = toCompletions(rawEquipment, "equipment");
|
|
4023
|
+
const eqTermsBySlug = /* @__PURE__ */ new Map();
|
|
4024
|
+
const equipmentLabelBySlug = /* @__PURE__ */ new Map();
|
|
4025
|
+
const equipment = rawEquipment.map((opt, idx) => {
|
|
4026
|
+
const label = opt.label ?? opt.value;
|
|
4027
|
+
const rawTerms = [label, opt.value, ...opt.aliases ?? []];
|
|
4028
|
+
const terms = dedupeStrings(rawTerms.map((t2) => normalizeForFuzzy(t2)));
|
|
4029
|
+
const words = dedupeStrings(terms.flatMap((t2) => t2.split(" ")));
|
|
4030
|
+
const slugLower = opt.value.toLowerCase();
|
|
4031
|
+
eqTermsBySlug.set(slugLower, dedupeStrings([...terms, ...words]));
|
|
4032
|
+
equipmentLabelBySlug.set(slugLower, label);
|
|
4033
|
+
const base = eqCompletions[idx];
|
|
4034
|
+
return {
|
|
4035
|
+
kind: "equipment",
|
|
4036
|
+
option: opt,
|
|
4037
|
+
label,
|
|
4038
|
+
labelLower: label.toLowerCase(),
|
|
4039
|
+
terms,
|
|
4040
|
+
words,
|
|
4041
|
+
equipmentSlugs: [slugLower],
|
|
4042
|
+
equipmentTerms: [],
|
|
4043
|
+
completion: {
|
|
4044
|
+
...base,
|
|
4045
|
+
section: resolveSection(opt.section) ?? COMPLETION_SECTIONS.equipment
|
|
4046
|
+
}
|
|
4047
|
+
};
|
|
4048
|
+
});
|
|
4049
|
+
const effortCompletions = toCompletions(rawEfforts, "effort");
|
|
4050
|
+
const efforts = rawEfforts.map((opt, idx) => {
|
|
4051
|
+
const label = opt.label ?? opt.value;
|
|
4052
|
+
const rawTerms = [label, opt.value, ...opt.aliases ?? []];
|
|
4053
|
+
const terms = dedupeStrings(rawTerms.map((t2) => normalizeForFuzzy(t2)));
|
|
4054
|
+
const words = dedupeStrings(terms.flatMap((t2) => t2.split(" ")));
|
|
4055
|
+
const equipmentSlugs = (opt.equipment ?? []).map((s) => s.toLowerCase());
|
|
4056
|
+
const equipmentTerms = dedupeStrings(
|
|
4057
|
+
equipmentSlugs.flatMap((slug) => eqTermsBySlug.get(slug) ?? [normalizeForFuzzy(slug)])
|
|
4058
|
+
);
|
|
4059
|
+
return {
|
|
4060
|
+
kind: "effort",
|
|
4061
|
+
option: opt,
|
|
4062
|
+
label,
|
|
4063
|
+
labelLower: label.toLowerCase(),
|
|
4064
|
+
terms,
|
|
4065
|
+
words,
|
|
4066
|
+
equipmentSlugs,
|
|
4067
|
+
equipmentTerms,
|
|
4068
|
+
completion: effortCompletions[idx]
|
|
4069
|
+
};
|
|
4070
|
+
});
|
|
4071
|
+
return { efforts, equipment, equipmentLabelBySlug };
|
|
4072
|
+
}
|
|
4073
|
+
function bestTokenScore(qTok, entry) {
|
|
4074
|
+
let best = 0;
|
|
4075
|
+
for (const term of entry.terms) {
|
|
4076
|
+
if (term === qTok) return 100;
|
|
4077
|
+
if (term.startsWith(qTok)) best = Math.max(best, 86);
|
|
4078
|
+
else if (qTok.length >= 2 && term.includes(qTok)) best = Math.max(best, 58);
|
|
4079
|
+
else if (isOrderedSubsequence(qTok, term)) best = Math.max(best, 32);
|
|
4080
|
+
}
|
|
4081
|
+
for (const word of entry.words) {
|
|
4082
|
+
if (word === qTok) best = Math.max(best, 95);
|
|
4083
|
+
else if (word.startsWith(qTok)) best = Math.max(best, 82);
|
|
4084
|
+
else if (qTok.length >= 2 && word.includes(qTok)) best = Math.max(best, 55);
|
|
4085
|
+
else if (qTok.length >= 3) {
|
|
4086
|
+
const maxDist = qTok.length <= 4 ? 1 : 2;
|
|
4087
|
+
if (Math.abs(word.length - qTok.length) <= maxDist) {
|
|
4088
|
+
const dist = damerauDistance(qTok, word);
|
|
4089
|
+
if (dist <= maxDist) best = Math.max(best, 46 - dist * 10);
|
|
4090
|
+
} else if (qTok.length >= 4 && word.length > qTok.length) {
|
|
4091
|
+
const prefix = word.slice(0, qTok.length);
|
|
4092
|
+
const dist = damerauDistance(qTok, prefix);
|
|
4093
|
+
if (dist <= 1) best = Math.max(best, 38);
|
|
4094
|
+
}
|
|
4095
|
+
if (isOrderedSubsequence(qTok, word)) best = Math.max(best, 30);
|
|
4096
|
+
}
|
|
4097
|
+
}
|
|
4098
|
+
for (const eqTerm of entry.equipmentTerms) {
|
|
4099
|
+
if (eqTerm === qTok) best = Math.max(best, 76);
|
|
4100
|
+
else if (qTok.length >= 2 && eqTerm.startsWith(qTok)) best = Math.max(best, 66);
|
|
4101
|
+
else if (qTok.length >= 4 && Math.abs(eqTerm.length - qTok.length) <= 1) {
|
|
4102
|
+
if (damerauDistance(qTok, eqTerm) <= 1) best = Math.max(best, 34);
|
|
4103
|
+
}
|
|
4104
|
+
}
|
|
4105
|
+
return best;
|
|
4106
|
+
}
|
|
4107
|
+
function scoreCatalogEntry(query, entry) {
|
|
4108
|
+
const normQuery = normalizeForFuzzy(query);
|
|
4109
|
+
if (!normQuery) return 1;
|
|
4110
|
+
const qTokens = normQuery.split(" ").filter(Boolean);
|
|
4111
|
+
if (qTokens.length === 0) return 1;
|
|
4112
|
+
let wholeBonus = 0;
|
|
4113
|
+
for (const term of entry.terms) {
|
|
4114
|
+
if (term === normQuery) {
|
|
4115
|
+
wholeBonus = Math.max(wholeBonus, 140);
|
|
4116
|
+
} else if (term.startsWith(normQuery)) {
|
|
4117
|
+
wholeBonus = Math.max(wholeBonus, 115);
|
|
4118
|
+
} else if (normQuery.length >= 2 && term.includes(normQuery)) {
|
|
4119
|
+
wholeBonus = Math.max(wholeBonus, 80);
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
4122
|
+
let tokenSum = 0;
|
|
4123
|
+
for (const qTok of qTokens) {
|
|
4124
|
+
const tokenScore = bestTokenScore(qTok, entry);
|
|
4125
|
+
if (tokenScore === 0) return null;
|
|
4126
|
+
tokenSum += tokenScore;
|
|
4127
|
+
}
|
|
4128
|
+
const labelWordCount = normalizeForFuzzy(entry.label).split(" ").filter(Boolean).length;
|
|
4129
|
+
const extraWordPenalty = Math.max(0, labelWordCount - qTokens.length) * 3;
|
|
4130
|
+
return wholeBonus + Math.round(tokenSum / qTokens.length) - extraWordPenalty + (entry.option.boost ?? 0);
|
|
4131
|
+
}
|
|
4132
|
+
function scoreCompletionOption(query, option) {
|
|
4133
|
+
const normQuery = normalizeForFuzzy(query);
|
|
4134
|
+
if (!normQuery) return 1;
|
|
4135
|
+
const qTokens = normQuery.split(" ").filter(Boolean);
|
|
4136
|
+
if (qTokens.length === 0) return 1;
|
|
4137
|
+
const aliases = completionAliases.get(option) ?? [];
|
|
4138
|
+
const rawTerms = [
|
|
4139
|
+
option.label,
|
|
4140
|
+
typeof option.apply === "string" ? option.apply : "",
|
|
4141
|
+
...aliases
|
|
4142
|
+
].filter(Boolean);
|
|
4143
|
+
const terms = dedupeStrings(rawTerms.map((t2) => normalizeForFuzzy(t2)));
|
|
4144
|
+
const words = dedupeStrings(terms.flatMap((t2) => t2.split(" ")));
|
|
4145
|
+
let wholeBonus = 0;
|
|
4146
|
+
for (const term of terms) {
|
|
4147
|
+
if (term === normQuery) wholeBonus = Math.max(wholeBonus, 130);
|
|
4148
|
+
else if (term.startsWith(normQuery)) wholeBonus = Math.max(wholeBonus, 105);
|
|
4149
|
+
else if (normQuery.length >= 2 && term.includes(normQuery)) wholeBonus = Math.max(wholeBonus, 70);
|
|
4150
|
+
}
|
|
4151
|
+
let tokenSum = 0;
|
|
4152
|
+
for (const qTok of qTokens) {
|
|
4153
|
+
let best = 0;
|
|
4154
|
+
for (const term of terms) {
|
|
4155
|
+
if (term === qTok) best = Math.max(best, 100);
|
|
4156
|
+
else if (term.startsWith(qTok)) best = Math.max(best, 85);
|
|
4157
|
+
else if (qTok.length >= 2 && term.includes(qTok)) best = Math.max(best, 55);
|
|
4158
|
+
}
|
|
4159
|
+
for (const word of words) {
|
|
4160
|
+
if (word === qTok) best = Math.max(best, 95);
|
|
4161
|
+
else if (word.startsWith(qTok)) best = Math.max(best, 80);
|
|
4162
|
+
else if (qTok.length >= 3) {
|
|
4163
|
+
const maxDist = qTok.length <= 4 ? 1 : 2;
|
|
4164
|
+
if (Math.abs(word.length - qTok.length) <= maxDist) {
|
|
4165
|
+
const dist = damerauDistance(qTok, word);
|
|
4166
|
+
if (dist <= maxDist) best = Math.max(best, 44 - dist * 10);
|
|
4167
|
+
}
|
|
4168
|
+
}
|
|
4169
|
+
}
|
|
4170
|
+
if (best === 0) return null;
|
|
4171
|
+
tokenSum += best;
|
|
4172
|
+
}
|
|
4173
|
+
return wholeBonus + Math.round(tokenSum / qTokens.length) + (option.boost ?? 0);
|
|
4174
|
+
}
|
|
4175
|
+
function findExactEntry(phrase, entries) {
|
|
4176
|
+
const norm = normalizeForFuzzy(phrase);
|
|
4177
|
+
if (!norm) return void 0;
|
|
4178
|
+
return entries.find((entry) => entry.terms.includes(norm));
|
|
4179
|
+
}
|
|
4180
|
+
function isExactAliasOrTermSplit(phrase, index) {
|
|
4181
|
+
const norm = normalizeForFuzzy(phrase);
|
|
4182
|
+
if (!norm) return false;
|
|
4183
|
+
if (index.efforts.some((e) => e.terms.includes(norm))) return true;
|
|
4184
|
+
const words = norm.split(" ").filter(Boolean);
|
|
4185
|
+
for (let k = 1; k < words.length; k++) {
|
|
4186
|
+
const left = words.slice(0, k).join(" ");
|
|
4187
|
+
const right = words.slice(k).join(" ");
|
|
4188
|
+
const effortLeft = index.efforts.some((e) => e.terms.includes(left));
|
|
4189
|
+
const eqRight = index.equipment.some((e) => e.terms.includes(right));
|
|
4190
|
+
if (effortLeft && eqRight) return true;
|
|
4191
|
+
const eqLeft = index.equipment.some((e) => e.terms.includes(left));
|
|
4192
|
+
const effortRight = index.efforts.some((e) => e.terms.includes(right));
|
|
4193
|
+
if (eqLeft && effortRight) return true;
|
|
4194
|
+
}
|
|
4195
|
+
return false;
|
|
4196
|
+
}
|
|
4197
|
+
function appendCreateEffortOption(pool, typedPhrase, onCreateEffort, suppressCreate = false) {
|
|
4198
|
+
if (!onCreateEffort || suppressCreate) return pool;
|
|
4199
|
+
const trimmed = typedPhrase.trim();
|
|
4200
|
+
if (trimmed.length < 3 || !/^[A-Za-z][A-Za-z0-9 -]*$/.test(trimmed)) return pool;
|
|
4201
|
+
const lower = trimmed.toLowerCase();
|
|
4202
|
+
const hasMatch = pool.some((opt) => {
|
|
4203
|
+
const labelLower = opt.label.toLowerCase();
|
|
4204
|
+
const applyLower = typeof opt.apply === "string" ? opt.apply.toLowerCase().trim() : "";
|
|
4205
|
+
const aliases = completionAliases.get(opt);
|
|
4206
|
+
return labelLower === lower || applyLower === lower || Boolean(aliases?.includes(lower));
|
|
4207
|
+
});
|
|
4208
|
+
if (hasMatch) return pool;
|
|
4209
|
+
const createOption = {
|
|
4210
|
+
label: trimmed,
|
|
4211
|
+
displayLabel: `+ Create "${trimmed}"`,
|
|
4212
|
+
detail: "Add to Effort Library",
|
|
4213
|
+
type: "create",
|
|
4214
|
+
section: COMPLETION_SECTIONS.create,
|
|
4215
|
+
boost: -25,
|
|
4216
|
+
apply: (view, _completion, from, to) => {
|
|
4217
|
+
view.dispatch({
|
|
4218
|
+
changes: { from, to, insert: trimmed },
|
|
4219
|
+
selection: { anchor: from + trimmed.length },
|
|
4220
|
+
userEvent: "input.complete"
|
|
4221
|
+
});
|
|
4222
|
+
void onCreateEffort(trimmed);
|
|
4223
|
+
}
|
|
4224
|
+
};
|
|
4225
|
+
return [...pool, createOption];
|
|
4226
|
+
}
|
|
3712
4227
|
function completionMatchesAliasOnly(option, typedLower) {
|
|
3713
4228
|
const aliases = completionAliases.get(option);
|
|
3714
4229
|
return aliases ? aliases.some((alias) => alias.includes(typedLower)) : false;
|
|
@@ -3752,8 +4267,10 @@ function suppliedPropertyKeys(context) {
|
|
|
3752
4267
|
}
|
|
3753
4268
|
return keys;
|
|
3754
4269
|
}
|
|
3755
|
-
function
|
|
3756
|
-
|
|
4270
|
+
function isUnitOrQualifierFragment(context, fragment, units) {
|
|
4271
|
+
if (fragment.firstChild?.name !== "Effort") return false;
|
|
4272
|
+
const raw = context.state.doc.sliceString(fragment.from, fragment.to).trim();
|
|
4273
|
+
return units.has(raw) || COUNT_QUALIFIER_WORDS.test(raw);
|
|
3757
4274
|
}
|
|
3758
4275
|
function trailingEffortRun(context, statement, units) {
|
|
3759
4276
|
const nodes = statement?.name === "Block" ? statement.getChildren("Fragment") : [];
|
|
@@ -3763,25 +4280,221 @@ function trailingEffortRun(context, statement, units) {
|
|
|
3763
4280
|
while (start > 0 && nodes[start - 1].firstChild?.name === "Effort") start--;
|
|
3764
4281
|
const run = nodes.slice(start, end);
|
|
3765
4282
|
let firstEffort = 0;
|
|
3766
|
-
while (firstEffort < run.length
|
|
4283
|
+
while (firstEffort < run.length && isUnitOrQualifierFragment(context, run[firstEffort], units)) firstEffort++;
|
|
3767
4284
|
return run.slice(firstEffort);
|
|
3768
4285
|
}
|
|
4286
|
+
function detectRepLadder(context, nodes, qtyIdx) {
|
|
4287
|
+
if (qtyIdx < 2 || nodes[qtyIdx]?.firstChild?.name !== "Quantity") {
|
|
4288
|
+
return { isLadder: false, rungCount: 1 };
|
|
4289
|
+
}
|
|
4290
|
+
const qtyText = context.state.doc.sliceString(nodes[qtyIdx].from, nodes[qtyIdx].to);
|
|
4291
|
+
if (!/^\d+$/.test(qtyText)) return { isLadder: false, rungCount: 1 };
|
|
4292
|
+
let rungCount = 1;
|
|
4293
|
+
let j = qtyIdx;
|
|
4294
|
+
while (j >= 2 && nodes[j - 1].firstChild?.name === "Effort" && context.state.doc.sliceString(nodes[j - 1].from, nodes[j - 1].to) === "-" && nodes[j].from === nodes[j - 1].to && nodes[j - 2].firstChild?.name === "Quantity" && nodes[j - 1].from === nodes[j - 2].to && /^\d+$/.test(context.state.doc.sliceString(nodes[j - 2].from, nodes[j - 2].to))) {
|
|
4295
|
+
rungCount++;
|
|
4296
|
+
j -= 2;
|
|
4297
|
+
}
|
|
4298
|
+
return { isLadder: rungCount >= 2, rungCount };
|
|
4299
|
+
}
|
|
4300
|
+
function analyzeStatementBefore(context, nodes, uptoEnd, index, units) {
|
|
4301
|
+
let hasRounds = false;
|
|
4302
|
+
let hasEffort = false;
|
|
4303
|
+
let hasEquipment = false;
|
|
4304
|
+
const wordChunks = [];
|
|
4305
|
+
for (let i = 0; i < uptoEnd; i++) {
|
|
4306
|
+
const frag = nodes[i];
|
|
4307
|
+
const kind = frag.firstChild?.name;
|
|
4308
|
+
if (kind === "Rounds" || kind === "RoundScheme") {
|
|
4309
|
+
hasRounds = true;
|
|
4310
|
+
continue;
|
|
4311
|
+
}
|
|
4312
|
+
if (kind === "Quantity") {
|
|
4313
|
+
if (detectRepLadder(context, nodes, i).isLadder) hasRounds = true;
|
|
4314
|
+
continue;
|
|
4315
|
+
}
|
|
4316
|
+
if (kind === "Effort") {
|
|
4317
|
+
const raw = context.state.doc.sliceString(frag.from, frag.to).trim();
|
|
4318
|
+
if (raw === "-" || raw === "/" || raw === "|") continue;
|
|
4319
|
+
if (ROUNDS_QUALIFIER_WORDS.test(raw)) {
|
|
4320
|
+
hasRounds = true;
|
|
4321
|
+
continue;
|
|
4322
|
+
}
|
|
4323
|
+
if (COUNT_QUALIFIER_WORDS.test(raw) || units.has(raw)) continue;
|
|
4324
|
+
wordChunks.push(raw);
|
|
4325
|
+
}
|
|
4326
|
+
}
|
|
4327
|
+
if (wordChunks.length > 0) {
|
|
4328
|
+
const phrase = wordChunks.join(" ");
|
|
4329
|
+
const norm = normalizeForFuzzy(phrase);
|
|
4330
|
+
const exactEq = findExactEntry(phrase, index.equipment);
|
|
4331
|
+
const exactEff = findExactEntry(phrase, index.efforts);
|
|
4332
|
+
if (exactEq && !exactEff) {
|
|
4333
|
+
hasEquipment = true;
|
|
4334
|
+
} else if (exactEff) {
|
|
4335
|
+
hasEffort = true;
|
|
4336
|
+
const eqWords = exactEff.equipmentSlugs.some((slug) => {
|
|
4337
|
+
const label = index.equipmentLabelBySlug.get(slug);
|
|
4338
|
+
return label ? norm.includes(normalizeForFuzzy(label)) : false;
|
|
4339
|
+
});
|
|
4340
|
+
if (eqWords) hasEquipment = true;
|
|
4341
|
+
} else if (isExactAliasOrTermSplit(phrase, index)) {
|
|
4342
|
+
hasEffort = true;
|
|
4343
|
+
hasEquipment = true;
|
|
4344
|
+
} else {
|
|
4345
|
+
hasEffort = true;
|
|
4346
|
+
}
|
|
4347
|
+
}
|
|
4348
|
+
return { hasRounds, hasEffort, hasEquipment };
|
|
4349
|
+
}
|
|
4350
|
+
function phraseHasExplicitEquipment(phrase, index) {
|
|
4351
|
+
const norm = normalizeForFuzzy(phrase);
|
|
4352
|
+
if (!norm) return false;
|
|
4353
|
+
const words = norm.split(" ").filter(Boolean);
|
|
4354
|
+
for (let k = 1; k < words.length; k++) {
|
|
4355
|
+
const left = words.slice(0, k).join(" ");
|
|
4356
|
+
const right = words.slice(k).join(" ");
|
|
4357
|
+
if (index.efforts.some((e) => e.terms.includes(left)) && index.equipment.some((e) => e.terms.includes(right))) {
|
|
4358
|
+
return true;
|
|
4359
|
+
}
|
|
4360
|
+
if (index.equipment.some((e) => e.terms.includes(left)) && index.efforts.some((e) => e.terms.includes(right))) {
|
|
4361
|
+
return true;
|
|
4362
|
+
}
|
|
4363
|
+
}
|
|
4364
|
+
const exactEq = findExactEntry(phrase, index.equipment);
|
|
4365
|
+
if (!exactEq) {
|
|
4366
|
+
for (let k = 1; k < words.length; k++) {
|
|
4367
|
+
const left = words.slice(0, k).join(" ");
|
|
4368
|
+
const right = words.slice(k).join(" ");
|
|
4369
|
+
if (index.equipment.some((e) => e.terms.includes(right)) && !index.equipment.some((e) => e.terms.includes(left))) {
|
|
4370
|
+
return true;
|
|
4371
|
+
}
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
const exactEff = findExactEntry(phrase, index.efforts);
|
|
4375
|
+
if (!exactEff) return false;
|
|
4376
|
+
return exactEff.equipmentSlugs.some((slug) => {
|
|
4377
|
+
const label = index.equipmentLabelBySlug.get(slug);
|
|
4378
|
+
if (label && norm.includes(normalizeForFuzzy(label))) return true;
|
|
4379
|
+
const eqEntry = index.equipment.find((eq) => eq.equipmentSlugs[0] === slug);
|
|
4380
|
+
return eqEntry ? eqEntry.terms.some((t2) => t2.length >= 2 && words.includes(t2)) : false;
|
|
4381
|
+
});
|
|
4382
|
+
}
|
|
4383
|
+
function specializedEffortsForBase(phrase, index) {
|
|
4384
|
+
const normBase = normalizeForFuzzy(phrase);
|
|
4385
|
+
const baseWords = normBase.split(" ").filter(Boolean);
|
|
4386
|
+
if (baseWords.length === 0) return [];
|
|
4387
|
+
const exactCurrent = findExactEntry(phrase, index.efforts);
|
|
4388
|
+
const results = [];
|
|
4389
|
+
for (const entry of index.efforts) {
|
|
4390
|
+
if (entry.labelLower === phrase.toLowerCase()) continue;
|
|
4391
|
+
if (exactCurrent && entry.labelLower === exactCurrent.labelLower) continue;
|
|
4392
|
+
const matchesAllWords = baseWords.every((w) => entry.words.includes(w) || entry.terms.some((t2) => t2.includes(w)));
|
|
4393
|
+
if (!matchesAllWords) continue;
|
|
4394
|
+
const eqNames = entry.equipmentSlugs.map((slug) => index.equipmentLabelBySlug.get(slug)).filter((name2) => Boolean(name2));
|
|
4395
|
+
const detail = eqNames.length > 0 ? `${entry.completion.detail ?? "effort"} \xB7 ${eqNames.join(", ")}` : entry.completion.detail;
|
|
4396
|
+
results.push({
|
|
4397
|
+
...entry.completion,
|
|
4398
|
+
detail,
|
|
4399
|
+
boost: clampBoost((entry.option.boost ?? 0) + 18),
|
|
4400
|
+
apply: (view, _completion, from, to) => {
|
|
4401
|
+
view.dispatch({
|
|
4402
|
+
changes: { from, to, insert: entry.label },
|
|
4403
|
+
selection: { anchor: from + entry.label.length },
|
|
4404
|
+
userEvent: "input.complete"
|
|
4405
|
+
});
|
|
4406
|
+
}
|
|
4407
|
+
});
|
|
4408
|
+
}
|
|
4409
|
+
return results;
|
|
4410
|
+
}
|
|
4411
|
+
function specializedEffortsForEquipment(eqEntry, index) {
|
|
4412
|
+
const eqSlug = eqEntry.equipmentSlugs[0];
|
|
4413
|
+
const results = [];
|
|
4414
|
+
for (const entry of index.efforts) {
|
|
4415
|
+
const usesEq = entry.equipmentSlugs.includes(eqSlug) || eqEntry.terms.some((t2) => t2.length >= 2 && entry.words.includes(t2));
|
|
4416
|
+
if (!usesEq) continue;
|
|
4417
|
+
results.push({
|
|
4418
|
+
...entry.completion,
|
|
4419
|
+
boost: clampBoost((entry.option.boost ?? 0) + 20),
|
|
4420
|
+
apply: (view, _completion, from, to) => {
|
|
4421
|
+
view.dispatch({
|
|
4422
|
+
changes: { from, to, insert: entry.label },
|
|
4423
|
+
selection: { anchor: from + entry.label.length },
|
|
4424
|
+
userEvent: "input.complete"
|
|
4425
|
+
});
|
|
4426
|
+
}
|
|
4427
|
+
});
|
|
4428
|
+
}
|
|
4429
|
+
return results;
|
|
4430
|
+
}
|
|
3769
4431
|
function inNode(context, names) {
|
|
3770
4432
|
for (let node = language.syntaxTree(context.state).resolveInner(context.pos, -1); node; node = node.parent) {
|
|
3771
4433
|
if (names.has(node.name)) return true;
|
|
3772
4434
|
}
|
|
3773
4435
|
return false;
|
|
3774
4436
|
}
|
|
3775
|
-
var
|
|
4437
|
+
var ALWAYS_SUPPRESSED_NODES = /* @__PURE__ */ new Set(["Text", "textComment", "MetricObject"]);
|
|
4438
|
+
var HEADING_NODES = /* @__PURE__ */ new Set(["Heading", "heading"]);
|
|
4439
|
+
function completeParenthesizedRounds(before, pos) {
|
|
4440
|
+
if (!/\([^)\n]*$/.test(before)) return void 0;
|
|
4441
|
+
const openIdx = before.lastIndexOf("(");
|
|
4442
|
+
const inner = before.slice(openIdx + 1);
|
|
4443
|
+
if (inner.includes("-")) return null;
|
|
4444
|
+
const m = /^(\s*)(\d+)([ \t]*)([A-Za-z]*)$/.exec(inner);
|
|
4445
|
+
if (!m) return null;
|
|
4446
|
+
const hasSpace = m[3].length > 0;
|
|
4447
|
+
const typedWord = m[4];
|
|
4448
|
+
const lead = hasSpace ? "" : " ";
|
|
4449
|
+
const wordFrom = pos - typedWord.length;
|
|
4450
|
+
const makeParenApply = (word) => (view, _c, from, to) => {
|
|
4451
|
+
const hasClose = view.state.doc.sliceString(to, to + 1) === ")";
|
|
4452
|
+
const insert = `${lead}${word}${hasClose ? "" : ")"}`;
|
|
4453
|
+
view.dispatch({
|
|
4454
|
+
changes: { from, to, insert },
|
|
4455
|
+
selection: { anchor: from + insert.length + (hasClose ? 1 : 0) },
|
|
4456
|
+
userEvent: "input.complete"
|
|
4457
|
+
});
|
|
4458
|
+
};
|
|
4459
|
+
const options = [
|
|
4460
|
+
{
|
|
4461
|
+
label: "rounds",
|
|
4462
|
+
detail: "rounds",
|
|
4463
|
+
type: "unit",
|
|
4464
|
+
section: COMPLETION_SECTIONS.units,
|
|
4465
|
+
boost: 45,
|
|
4466
|
+
apply: makeParenApply("rounds")
|
|
4467
|
+
},
|
|
4468
|
+
{
|
|
4469
|
+
label: "reps",
|
|
4470
|
+
detail: "count",
|
|
4471
|
+
type: "unit",
|
|
4472
|
+
section: COMPLETION_SECTIONS.units,
|
|
4473
|
+
boost: 40,
|
|
4474
|
+
apply: makeParenApply("reps")
|
|
4475
|
+
}
|
|
4476
|
+
];
|
|
4477
|
+
completionAliases.set(options[0], ["round", "rd", "rds", "set", "sets"]);
|
|
4478
|
+
completionAliases.set(options[1], ["rep"]);
|
|
4479
|
+
if (typedWord.length > 0) {
|
|
4480
|
+
const scored = options.map((opt) => ({ opt, score: scoreCompletionOption(typedWord, opt) })).filter((x) => x.score !== null).sort((a, b) => b.score - a.score).map((x) => x.opt);
|
|
4481
|
+
return scored.length > 0 ? { from: wordFrom, options: scored, filter: false } : null;
|
|
4482
|
+
}
|
|
4483
|
+
return {
|
|
4484
|
+
from: wordFrom,
|
|
4485
|
+
options,
|
|
4486
|
+
validFor: /^[A-Za-z]*$/
|
|
4487
|
+
};
|
|
4488
|
+
}
|
|
3776
4489
|
function whiteboardScriptCompletionSource(options = {}) {
|
|
3777
4490
|
const sportWords = dialectWords(options.sport);
|
|
3778
4491
|
const keywords = structureKeywords();
|
|
3779
4492
|
const snippets = snippetCompletions();
|
|
4493
|
+
const snippetLabels = new Set(snippets.map((s) => s.label));
|
|
4494
|
+
const startKeywords = keywords.filter((k) => !snippetLabels.has(k.label));
|
|
3780
4495
|
const units = options.units ?? UnitRegistry.standard();
|
|
3781
|
-
const allUnitOptions = unitCompletions(units);
|
|
3782
|
-
const massUnitOptions = unitCompletions(units, "mass");
|
|
3783
4496
|
return async (context) => {
|
|
3784
|
-
if (inNode(context,
|
|
4497
|
+
if (inNode(context, ALWAYS_SUPPRESSED_NODES)) return null;
|
|
3785
4498
|
const pos = context.pos;
|
|
3786
4499
|
const line = context.state.doc.lineAt(pos);
|
|
3787
4500
|
const before = line.text.slice(0, pos - line.from);
|
|
@@ -3795,9 +4508,57 @@ function whiteboardScriptCompletionSource(options = {}) {
|
|
|
3795
4508
|
validFor: /^\[:[a-zA-Z0-9-]*\]?$/
|
|
3796
4509
|
};
|
|
3797
4510
|
}
|
|
3798
|
-
if (
|
|
3799
|
-
|
|
4511
|
+
if (/(?:^|[\s:])#$/.test(beforeWord) && (options.tags || options.onCreateTag)) {
|
|
4512
|
+
const rawTags = options.tags ? await options.tags() : [];
|
|
4513
|
+
const tagOptions = toCompletions(rawTags, "tag");
|
|
4514
|
+
if (options.onCreateTag && word.length >= 2) {
|
|
4515
|
+
const slug = word.toLowerCase();
|
|
4516
|
+
const exists = rawTags.some(
|
|
4517
|
+
(tag) => tag.value.toLowerCase() === slug || (tag.label ?? "").toLowerCase() === slug
|
|
4518
|
+
);
|
|
4519
|
+
if (!exists) {
|
|
4520
|
+
tagOptions.push({
|
|
4521
|
+
label: slug,
|
|
4522
|
+
displayLabel: `+ Create "#${slug}"`,
|
|
4523
|
+
detail: "New tag",
|
|
4524
|
+
type: "create",
|
|
4525
|
+
section: COMPLETION_SECTIONS.create,
|
|
4526
|
+
boost: -20,
|
|
4527
|
+
apply: (view, _completion, from, to) => {
|
|
4528
|
+
view.dispatch({
|
|
4529
|
+
changes: { from, to, insert: slug },
|
|
4530
|
+
selection: { anchor: from + slug.length },
|
|
4531
|
+
userEvent: "input.complete"
|
|
4532
|
+
});
|
|
4533
|
+
void options.onCreateTag?.(slug);
|
|
4534
|
+
}
|
|
4535
|
+
});
|
|
4536
|
+
}
|
|
4537
|
+
}
|
|
4538
|
+
const restTag = /^[A-Za-z0-9-]*/.exec(line.text.slice(pos - line.from))[0];
|
|
4539
|
+
if (restTag.length > 0) {
|
|
4540
|
+
const lower = word.toLowerCase();
|
|
4541
|
+
const filteredTags = tagOptions.filter((opt) => {
|
|
4542
|
+
if (opt.type === "create") return true;
|
|
4543
|
+
const applyLower = typeof opt.apply === "string" ? opt.apply.toLowerCase() : "";
|
|
4544
|
+
return opt.label.toLowerCase().includes(lower) || applyLower.includes(lower);
|
|
4545
|
+
});
|
|
4546
|
+
return filteredTags.length > 0 ? {
|
|
4547
|
+
from: pos - word.length,
|
|
4548
|
+
to: pos + restTag.length,
|
|
4549
|
+
options: filteredTags,
|
|
4550
|
+
filter: false
|
|
4551
|
+
} : null;
|
|
4552
|
+
}
|
|
4553
|
+
return {
|
|
4554
|
+
from: pos - word.length,
|
|
4555
|
+
options: tagOptions,
|
|
4556
|
+
validFor: /^[A-Za-z0-9-]*$/
|
|
4557
|
+
};
|
|
3800
4558
|
}
|
|
4559
|
+
if (inNode(context, HEADING_NODES)) return null;
|
|
4560
|
+
const parenResult = completeParenthesizedRounds(before, pos);
|
|
4561
|
+
if (parenResult !== void 0) return parenResult;
|
|
3801
4562
|
const statement = currentStatement(context);
|
|
3802
4563
|
if (statement?.name === "Property") {
|
|
3803
4564
|
const keyNode = statement.firstChild;
|
|
@@ -3809,37 +4570,58 @@ function whiteboardScriptCompletionSource(options = {}) {
|
|
|
3809
4570
|
if (source) return { from: value && !value.type.isError ? value.from : pos, options: toCompletions(await source(), key, true) };
|
|
3810
4571
|
return null;
|
|
3811
4572
|
}
|
|
3812
|
-
const
|
|
3813
|
-
const
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
})) : [];
|
|
3819
|
-
const effortOptions = [...keywords, ...efforts, ...equipmentPrefixes, ...sportWords];
|
|
4573
|
+
const rawEfforts = options.efforts ? await options.efforts() : [];
|
|
4574
|
+
const rawEquipment = options.equipment ? await options.equipment() : [];
|
|
4575
|
+
const catalog = buildCatalogIndex(rawEfforts, rawEquipment);
|
|
4576
|
+
const efforts = catalog.efforts.map((e) => e.completion);
|
|
4577
|
+
const equipmentOpts = catalog.equipment.map((e) => e.completion);
|
|
4578
|
+
const missingLineElements = [...efforts, ...equipmentOpts, ...sportWords];
|
|
3820
4579
|
if (/^[ \t]*[A-Za-z][A-Za-z0-9]*$/.test(before)) {
|
|
3821
4580
|
const supplied = suppliedPropertyKeys(context);
|
|
4581
|
+
const propertyOptions = COMPLETION_PROPERTY_KEYS.filter((key) => !supplied.has(key)).map((key) => ({
|
|
4582
|
+
label: key,
|
|
4583
|
+
apply: `${key}: `,
|
|
4584
|
+
detail: "block property",
|
|
4585
|
+
type: "property",
|
|
4586
|
+
section: COMPLETION_SECTIONS.blockProperties,
|
|
4587
|
+
boost: -10
|
|
4588
|
+
}));
|
|
3822
4589
|
const allStartOptions = [
|
|
3823
|
-
...COMPLETION_PROPERTY_KEYS.filter((key) => !supplied.has(key)).map((key) => ({ label: key, detail: "property", type: "property", boost: 5 })),
|
|
3824
4590
|
...snippets,
|
|
3825
|
-
...
|
|
4591
|
+
...startKeywords,
|
|
3826
4592
|
...efforts,
|
|
3827
|
-
...
|
|
4593
|
+
...equipmentOpts,
|
|
4594
|
+
...sportWords,
|
|
4595
|
+
...propertyOptions
|
|
3828
4596
|
];
|
|
3829
|
-
const
|
|
3830
|
-
const
|
|
3831
|
-
|
|
3832
|
-
const
|
|
4597
|
+
const typedRaw = before.trimStart();
|
|
4598
|
+
const typedStart = typedRaw.toLowerCase();
|
|
4599
|
+
const hasSubstringOrPrefix = allStartOptions.some((opt) => {
|
|
4600
|
+
const m = completionMatchesWord(opt, typedStart);
|
|
4601
|
+
return m === "prefix" || m === "word";
|
|
4602
|
+
});
|
|
4603
|
+
const fuzzyEfforts = catalog.efforts.map((e) => ({ opt: e.completion, score: scoreCatalogEntry(typedRaw, e) })).filter((x) => x.score !== null).sort((a, b) => b.score - a.score);
|
|
4604
|
+
const fuzzyEquipment = catalog.equipment.map((e) => ({ opt: e.completion, score: scoreCatalogEntry(typedRaw, e) })).filter((x) => x.score !== null).sort((a, b) => b.score - a.score);
|
|
4605
|
+
const restWord = /^[A-Za-z0-9-]*/.exec(line.text.slice(pos - line.from))[0];
|
|
4606
|
+
const hasAliasOrFuzzyOnly = (fuzzyEfforts.length > 0 || fuzzyEquipment.length > 0) && (!hasSubstringOrPrefix || typedStart.length >= 2 && fuzzyEfforts.some((e) => completionMatchesWord(e.opt, typedStart) === "alias"));
|
|
4607
|
+
if (hasAliasOrFuzzyOnly || restWord.length > 0) {
|
|
4608
|
+
const otherMatched = [...snippets, ...startKeywords, ...sportWords, ...propertyOptions].filter((opt) => scoreCompletionOption(typedRaw, opt) !== null);
|
|
4609
|
+
const matched = [
|
|
4610
|
+
...otherMatched,
|
|
4611
|
+
...fuzzyEfforts.map((x) => x.opt),
|
|
4612
|
+
...fuzzyEquipment.map((x) => x.opt)
|
|
4613
|
+
];
|
|
4614
|
+
const suppressCreate = isExactAliasOrTermSplit(typedRaw, catalog);
|
|
3833
4615
|
return {
|
|
3834
|
-
from: pos -
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
4616
|
+
from: pos - typedRaw.length,
|
|
4617
|
+
...restWord.length > 0 ? { to: pos + restWord.length } : {},
|
|
4618
|
+
options: appendCreateEffortOption(matched, typedRaw, options.onCreateEffort, suppressCreate),
|
|
4619
|
+
filter: false
|
|
3838
4620
|
};
|
|
3839
4621
|
}
|
|
3840
4622
|
return {
|
|
3841
|
-
from: pos -
|
|
3842
|
-
options: allStartOptions,
|
|
4623
|
+
from: pos - typedRaw.length,
|
|
4624
|
+
options: appendCreateEffortOption(allStartOptions, typedRaw, options.onCreateEffort, isExactAliasOrTermSplit(typedRaw, catalog)),
|
|
3843
4625
|
validFor: /^[A-Za-z]*$/
|
|
3844
4626
|
};
|
|
3845
4627
|
}
|
|
@@ -3847,57 +4629,340 @@ function whiteboardScriptCompletionSource(options = {}) {
|
|
|
3847
4629
|
let end = nodes.length;
|
|
3848
4630
|
while (end > 0 && nodes[end - 1].from >= pos) end--;
|
|
3849
4631
|
const last = nodes[end - 1];
|
|
3850
|
-
const completingWord = last?.firstChild?.name === "Effort" && last.
|
|
3851
|
-
const
|
|
4632
|
+
const completingWord = last?.firstChild?.name === "Effort" && last.from < pos && pos <= last.to;
|
|
4633
|
+
const qtyIdx = completingWord ? end - 2 : end - 1;
|
|
4634
|
+
const quantityFragment = qtyIdx >= 0 ? nodes[qtyIdx] : void 0;
|
|
3852
4635
|
const quantity = quantityFragment?.firstChild?.name === "Quantity" ? quantityFragment.firstChild : null;
|
|
3853
4636
|
const incompleteAction = statement?.name === "Block" && statement.getChildren("Fragment").some(
|
|
3854
4637
|
(fragment) => fragment.firstChild?.name === "Action" && fragment.from < (quantity?.from ?? pos) && !context.state.doc.sliceString(fragment.from, fragment.to).includes(":")
|
|
3855
4638
|
);
|
|
3856
4639
|
if (quantity && !incompleteAction) {
|
|
3857
|
-
const
|
|
3858
|
-
const
|
|
3859
|
-
const
|
|
3860
|
-
|
|
4640
|
+
const hasAtSign = Boolean(quantity.getChild("AtSign"));
|
|
4641
|
+
const rawQty = context.state.doc.sliceString(quantity.from, quantity.to);
|
|
4642
|
+
const isWholeInteger = !hasAtSign && /^\d+$/.test(rawQty);
|
|
4643
|
+
const isWildcard = !hasAtSign && rawQty === "?";
|
|
4644
|
+
const isGlued = completingWord ? last.from === quantityFragment.to : pos === quantityFragment.to;
|
|
4645
|
+
const hasTrailingSpace = !completingWord && pos > quantityFragment.to && /[ \t]$/.test(before);
|
|
4646
|
+
const ladder = !hasAtSign ? detectRepLadder(context, nodes, qtyIdx) : { isLadder: false, rungCount: 1 };
|
|
4647
|
+
const prefixLine = analyzeStatementBefore(context, nodes, qtyIdx, catalog, units);
|
|
4648
|
+
const preferredSet = new Set(
|
|
4649
|
+
(options.preferredUnits?.() ?? []).map((u) => u.toLowerCase())
|
|
4650
|
+
);
|
|
4651
|
+
if (hasAtSign) {
|
|
4652
|
+
const massPool = unitCompletions(units, "mass", preferredSet.size > 0 ? preferredSet : void 0);
|
|
4653
|
+
const wordText = completingWord ? context.state.doc.sliceString(last.from, pos) : "";
|
|
4654
|
+
if (completingWord && (last.to > pos || wordText.length >= 2)) {
|
|
4655
|
+
const hasAlias = massPool.some((opt) => completionMatchesWord(opt, wordText.toLowerCase()) === "alias");
|
|
4656
|
+
if (hasAlias || last.to > pos) {
|
|
4657
|
+
return {
|
|
4658
|
+
from: last.from,
|
|
4659
|
+
...last.to > pos ? { to: last.to } : {},
|
|
4660
|
+
options: massPool.filter((opt) => scoreCompletionOption(wordText, opt) !== null),
|
|
4661
|
+
filter: false
|
|
4662
|
+
};
|
|
4663
|
+
}
|
|
4664
|
+
}
|
|
3861
4665
|
return {
|
|
3862
|
-
from: last.from,
|
|
3863
|
-
options:
|
|
3864
|
-
filter: false,
|
|
4666
|
+
from: completingWord ? last.from : pos,
|
|
4667
|
+
options: massPool,
|
|
3865
4668
|
validFor: /^[A-Za-z]*$/
|
|
3866
4669
|
};
|
|
3867
4670
|
}
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
4671
|
+
if (ladder.isLadder) {
|
|
4672
|
+
const ladderDetail = ladder.rungCount >= 3 ? `rep scheme (${ladder.rungCount} rounds)` : "rep scheme";
|
|
4673
|
+
const ladderReps = makeCountQualifiers(false, isGlued, ladderDetail);
|
|
4674
|
+
if (hasTrailingSpace) {
|
|
4675
|
+
return {
|
|
4676
|
+
from: pos,
|
|
4677
|
+
options: [
|
|
4678
|
+
...missingLineElements,
|
|
4679
|
+
...keywords.filter((k) => k.label === "FOR TIME")
|
|
4680
|
+
]
|
|
4681
|
+
};
|
|
4682
|
+
}
|
|
4683
|
+
if (completingWord) {
|
|
4684
|
+
const wordText = context.state.doc.sliceString(last.from, pos);
|
|
4685
|
+
const pool = isGlued ? ladderReps : [...isGlued ? [] : makeCountQualifiers(false, false, ladderDetail), ...missingLineElements, ...keywords.filter((k) => k.label === "FOR TIME")];
|
|
4686
|
+
const matched = scorePhrasePool(wordText, pool, catalog, options.onCreateEffort, !isGlued);
|
|
4687
|
+
return matched.length > 0 ? {
|
|
4688
|
+
from: last.from,
|
|
4689
|
+
...last.to > pos ? { to: last.to } : {},
|
|
4690
|
+
options: matched,
|
|
4691
|
+
filter: false
|
|
4692
|
+
} : null;
|
|
4693
|
+
}
|
|
4694
|
+
return {
|
|
4695
|
+
from: pos,
|
|
4696
|
+
options: ladderReps,
|
|
4697
|
+
validFor: /^[A-Za-z]*$/
|
|
4698
|
+
};
|
|
4699
|
+
}
|
|
4700
|
+
if (isGlued) {
|
|
4701
|
+
const countOpts = isWholeInteger || isWildcard ? makeCountQualifiers(isWholeInteger && !prefixLine.hasRounds, true) : [];
|
|
4702
|
+
const unitPool = [
|
|
4703
|
+
...countOpts,
|
|
4704
|
+
...unitCompletions(units, void 0, preferredSet.size > 0 ? preferredSet : void 0)
|
|
4705
|
+
];
|
|
4706
|
+
if (completingWord) {
|
|
4707
|
+
const wordText = context.state.doc.sliceString(last.from, pos);
|
|
4708
|
+
const hasAliasHit = unitPool.some((opt) => completionMatchesWord(opt, wordText.toLowerCase()) === "alias");
|
|
4709
|
+
if (hasAliasHit || last.to > pos) {
|
|
4710
|
+
return {
|
|
4711
|
+
from: last.from,
|
|
4712
|
+
...last.to > pos ? { to: last.to } : {},
|
|
4713
|
+
options: unitPool.filter((opt) => scoreCompletionOption(wordText, opt) !== null),
|
|
4714
|
+
filter: false
|
|
4715
|
+
};
|
|
4716
|
+
}
|
|
4717
|
+
}
|
|
4718
|
+
return {
|
|
4719
|
+
from: completingWord ? last.from : pos,
|
|
4720
|
+
options: unitPool,
|
|
4721
|
+
validFor: /^[A-Za-z]*$/
|
|
4722
|
+
};
|
|
4723
|
+
}
|
|
4724
|
+
if (hasTrailingSpace) {
|
|
4725
|
+
if (!prefixLine.hasEffort) {
|
|
4726
|
+
return missingLineElements.length > 0 ? { from: pos, options: missingLineElements } : null;
|
|
4727
|
+
}
|
|
4728
|
+
if (!prefixLine.hasEquipment) {
|
|
4729
|
+
return equipmentOpts.length > 0 ? { from: pos, options: equipmentOpts } : null;
|
|
4730
|
+
}
|
|
4731
|
+
return null;
|
|
4732
|
+
}
|
|
4733
|
+
if (completingWord) {
|
|
4734
|
+
const wordText = context.state.doc.sliceString(last.from, pos);
|
|
4735
|
+
const unitCandidates = [
|
|
4736
|
+
...isWholeInteger || isWildcard ? makeCountQualifiers(isWholeInteger && !prefixLine.hasRounds, false) : [],
|
|
4737
|
+
...unitCompletions(units, void 0, preferredSet.size > 0 ? preferredSet : void 0)
|
|
4738
|
+
];
|
|
4739
|
+
const matchingUnits = unitCandidates.filter((opt) => {
|
|
4740
|
+
const norm = normalizeForFuzzy(wordText);
|
|
4741
|
+
const labelLower = opt.label.toLowerCase();
|
|
4742
|
+
const aliases = completionAliases.get(opt) ?? [];
|
|
4743
|
+
return labelLower.startsWith(norm) || aliases.some((a) => a.startsWith(norm));
|
|
4744
|
+
});
|
|
4745
|
+
const elementPool = prefixLine.hasEffort && !prefixLine.hasEquipment ? equipmentOpts : prefixLine.hasEffort ? [] : missingLineElements;
|
|
4746
|
+
const effortMatches = scoreCatalogList(wordText, prefixLine.hasEffort ? [] : catalog.efforts);
|
|
4747
|
+
const equipmentMatches = scoreCatalogList(wordText, prefixLine.hasEquipment ? [] : catalog.equipment);
|
|
4748
|
+
const sportMatches = (!prefixLine.hasEffort ? sportWords : []).map((opt) => ({ opt, score: scoreCompletionOption(wordText, opt) })).filter((x) => x.score !== null).sort((a, b) => b.score - a.score).map((x) => x.opt);
|
|
4749
|
+
const combined = [
|
|
4750
|
+
...matchingUnits,
|
|
4751
|
+
...effortMatches.map((x) => x.opt),
|
|
4752
|
+
...equipmentMatches.map((x) => x.opt),
|
|
4753
|
+
...sportMatches
|
|
4754
|
+
];
|
|
4755
|
+
const hasAliasHit = elementPool.some((opt) => completionMatchesWord(opt, wordText.toLowerCase()) === "alias") || matchingUnits.length > 0 || effortMatches.length + equipmentMatches.length > 0;
|
|
4756
|
+
const suppressCreate = isExactAliasOrTermSplit(wordText, catalog);
|
|
4757
|
+
return hasAliasHit || combined.length > 0 || options.onCreateEffort && !prefixLine.hasEffort ? {
|
|
4758
|
+
from: last.from,
|
|
4759
|
+
...last.to > pos ? { to: last.to } : {},
|
|
4760
|
+
options: !prefixLine.hasEffort ? appendCreateEffortOption(combined, wordText, options.onCreateEffort, suppressCreate) : combined,
|
|
4761
|
+
filter: false
|
|
4762
|
+
} : null;
|
|
4763
|
+
}
|
|
3873
4764
|
}
|
|
3874
4765
|
if (before.trim() === "") {
|
|
3875
|
-
return { from: pos, options: [...snippets, ...
|
|
4766
|
+
return { from: pos, options: [...snippets, ...startKeywords, ...efforts, ...equipmentOpts, ...sportWords] };
|
|
3876
4767
|
}
|
|
4768
|
+
const effortRun = trailingEffortRun(context, statement, units);
|
|
3877
4769
|
if (word.length === 0 && /[ \t]$/.test(before)) {
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
4770
|
+
if (effortRun.length === 0) {
|
|
4771
|
+
return { from: pos, options: [...keywords, ...missingLineElements] };
|
|
4772
|
+
}
|
|
4773
|
+
const runFirst = effortRun[0];
|
|
4774
|
+
const runLast = effortRun[effortRun.length - 1];
|
|
4775
|
+
const phraseFrom = runFirst.from;
|
|
4776
|
+
const phraseText = context.state.doc.sliceString(phraseFrom, runLast.to).trim();
|
|
4777
|
+
if (phraseHasExplicitEquipment(phraseText, catalog)) return null;
|
|
4778
|
+
const exactEq = findExactEntry(phraseText, catalog.equipment);
|
|
4779
|
+
if (exactEq) {
|
|
4780
|
+
const dedicated = specializedEffortsForEquipment(exactEq, catalog);
|
|
4781
|
+
const dedicatedLabels = new Set(dedicated.map((d) => d.label.toLowerCase()));
|
|
4782
|
+
const appendedEfforts = catalog.efforts.filter((e) => !dedicatedLabels.has(e.labelLower)).map((e) => ({
|
|
4783
|
+
...e.completion,
|
|
4784
|
+
apply: (view, _c, from, to) => {
|
|
4785
|
+
const existing = view.state.doc.sliceString(from, to);
|
|
4786
|
+
const insert = `${existing}${e.label}`;
|
|
4787
|
+
view.dispatch({
|
|
4788
|
+
changes: { from, to, insert },
|
|
4789
|
+
selection: { anchor: from + insert.length },
|
|
4790
|
+
userEvent: "input.complete"
|
|
4791
|
+
});
|
|
4792
|
+
}
|
|
4793
|
+
}));
|
|
4794
|
+
const allEqOptions = [...dedicated, ...appendedEfforts];
|
|
4795
|
+
return allEqOptions.length > 0 ? { from: phraseFrom, options: allEqOptions, filter: false } : null;
|
|
4796
|
+
}
|
|
4797
|
+
const specialized = specializedEffortsForBase(phraseText, catalog);
|
|
4798
|
+
const suffixEquipment = catalog.equipment.map((eq) => ({
|
|
4799
|
+
...eq.completion,
|
|
4800
|
+
apply: (view, _completion, from, to) => {
|
|
4801
|
+
const existing = view.state.doc.sliceString(from, to);
|
|
4802
|
+
const insert = `${existing}${eq.label}`;
|
|
4803
|
+
view.dispatch({
|
|
4804
|
+
changes: { from, to, insert },
|
|
4805
|
+
selection: { anchor: from + insert.length },
|
|
4806
|
+
userEvent: "input.complete"
|
|
4807
|
+
});
|
|
4808
|
+
}
|
|
4809
|
+
}));
|
|
4810
|
+
const combined = [...specialized, ...suffixEquipment];
|
|
4811
|
+
return combined.length > 0 ? { from: phraseFrom, options: combined, filter: false } : null;
|
|
3882
4812
|
}
|
|
3883
4813
|
if (word.length > 0 && /^[A-Za-z][A-Za-z0-9'-]*$/.test(word)) {
|
|
3884
|
-
|
|
3885
|
-
const
|
|
3886
|
-
const
|
|
3887
|
-
if (
|
|
3888
|
-
const
|
|
3889
|
-
const
|
|
3890
|
-
const
|
|
4814
|
+
if (effortRun.length === 0) return null;
|
|
4815
|
+
const phraseFrom = effortRun[0].from;
|
|
4816
|
+
const runLast = effortRun[effortRun.length - 1];
|
|
4817
|
+
if (runLast.to < pos) return null;
|
|
4818
|
+
const rawPhrase = context.state.doc.sliceString(phraseFrom, pos);
|
|
4819
|
+
const isSingleWord = effortRun.length === 1;
|
|
4820
|
+
const scoredOptions = [];
|
|
4821
|
+
const seenOutcome = /* @__PURE__ */ new Set();
|
|
4822
|
+
const pushScored = (option, score, outcomeKey) => {
|
|
4823
|
+
if (seenOutcome.has(outcomeKey)) return;
|
|
4824
|
+
seenOutcome.add(outcomeKey);
|
|
4825
|
+
scoredOptions.push({ option, score });
|
|
4826
|
+
};
|
|
4827
|
+
const strategy1Efforts = scoreCatalogList(rawPhrase, catalog.efforts);
|
|
4828
|
+
for (const { entry, opt, score } of strategy1Efforts) {
|
|
4829
|
+
const eqLabels = entry.equipmentSlugs.map((slug) => catalog.equipmentLabelBySlug.get(slug)).filter((lbl) => Boolean(lbl));
|
|
4830
|
+
const multiTokenUpgrade = !isSingleWord && eqLabels.length > 0;
|
|
4831
|
+
const upgradedDetail = multiTokenUpgrade && !(opt.detail ?? "").toLowerCase().includes(eqLabels[0].toLowerCase()) ? `${opt.detail ?? "effort"} \xB7 includes ${eqLabels.join(", ")}` : opt.detail;
|
|
4832
|
+
pushScored(
|
|
4833
|
+
{
|
|
4834
|
+
...opt,
|
|
4835
|
+
detail: upgradedDetail,
|
|
4836
|
+
boost: clampBoost(Math.min(75, Math.round(score / 4)) + (multiTokenUpgrade ? 10 : 0)),
|
|
4837
|
+
apply: (view, _completion, from, to) => {
|
|
4838
|
+
view.dispatch({
|
|
4839
|
+
changes: { from, to, insert: entry.label },
|
|
4840
|
+
selection: { anchor: from + entry.label.length },
|
|
4841
|
+
userEvent: "input.complete"
|
|
4842
|
+
});
|
|
4843
|
+
}
|
|
4844
|
+
},
|
|
4845
|
+
score + (multiTokenUpgrade ? 25 : 0),
|
|
4846
|
+
`whole:${entry.labelLower}`
|
|
4847
|
+
);
|
|
4848
|
+
}
|
|
4849
|
+
if (isSingleWord) {
|
|
4850
|
+
for (const { entry, opt, score } of scoreCatalogList(rawPhrase, catalog.equipment)) {
|
|
4851
|
+
pushScored(
|
|
4852
|
+
{
|
|
4853
|
+
...opt,
|
|
4854
|
+
boost: clampBoost(Math.min(70, Math.round(score / 4))),
|
|
4855
|
+
apply: (view, _completion, from, to) => {
|
|
4856
|
+
view.dispatch({
|
|
4857
|
+
changes: { from, to, insert: entry.label },
|
|
4858
|
+
selection: { anchor: from + entry.label.length },
|
|
4859
|
+
userEvent: "input.complete"
|
|
4860
|
+
});
|
|
4861
|
+
}
|
|
4862
|
+
},
|
|
4863
|
+
score,
|
|
4864
|
+
`eq-whole:${entry.labelLower}`
|
|
4865
|
+
);
|
|
4866
|
+
}
|
|
4867
|
+
for (const kw of [...keywords, ...sportWords]) {
|
|
4868
|
+
const s = scoreCompletionOption(rawPhrase, kw);
|
|
4869
|
+
if (s !== null) pushScored(kw, s, `kw:${kw.label.toLowerCase()}`);
|
|
4870
|
+
}
|
|
4871
|
+
} else {
|
|
4872
|
+
for (let k = 1; k < effortRun.length; k++) {
|
|
4873
|
+
const prefixText = context.state.doc.sliceString(phraseFrom, effortRun[k - 1].to).trim();
|
|
4874
|
+
const suffixFrom = effortRun[k].from;
|
|
4875
|
+
const suffixText = context.state.doc.sliceString(suffixFrom, pos).trim();
|
|
4876
|
+
if (!prefixText || !suffixText) continue;
|
|
4877
|
+
const suffixDelta = suffixFrom - phraseFrom;
|
|
4878
|
+
const prefixIsEq = findExactEntry(prefixText, catalog.equipment);
|
|
4879
|
+
const prefixIsEff = findExactEntry(prefixText, catalog.efforts);
|
|
4880
|
+
if (prefixIsEq) {
|
|
4881
|
+
for (const { entry, opt, score } of scoreCatalogList(suffixText, catalog.efforts)) {
|
|
4882
|
+
if (seenOutcome.has(`whole:${entry.labelLower}`)) continue;
|
|
4883
|
+
if (normalizeForFuzzy(entry.label).includes(normalizeForFuzzy(prefixIsEq.label))) continue;
|
|
4884
|
+
const resultingText = `${prefixText} ${entry.label}`.toLowerCase();
|
|
4885
|
+
if (seenOutcome.has(`whole:${resultingText}`)) continue;
|
|
4886
|
+
const dedicatedEqText = `${prefixIsEq.label} ${entry.label}`.toLowerCase();
|
|
4887
|
+
if (seenOutcome.has(`whole:${dedicatedEqText}`)) continue;
|
|
4888
|
+
pushScored(
|
|
4889
|
+
{
|
|
4890
|
+
...opt,
|
|
4891
|
+
boost: clampBoost(Math.min(72, Math.round(score / 4))),
|
|
4892
|
+
apply: (view, _completion, from, to) => {
|
|
4893
|
+
view.dispatch({
|
|
4894
|
+
changes: { from: from + suffixDelta, to, insert: entry.label },
|
|
4895
|
+
selection: { anchor: from + suffixDelta + entry.label.length },
|
|
4896
|
+
userEvent: "input.complete"
|
|
4897
|
+
});
|
|
4898
|
+
}
|
|
4899
|
+
},
|
|
4900
|
+
score,
|
|
4901
|
+
`eq-prefix-eff:${entry.labelLower}:${suffixDelta}`
|
|
4902
|
+
);
|
|
4903
|
+
}
|
|
4904
|
+
}
|
|
4905
|
+
const allowEquipmentSuffix = Boolean(prefixIsEff) || !prefixIsEq && suffixText.length >= 2 && (strategy1Efforts.length === 0 || scoreCatalogList(suffixText, catalog.equipment).some((m) => m.score >= 70));
|
|
4906
|
+
if (allowEquipmentSuffix && !prefixIsEq) {
|
|
4907
|
+
for (const { entry, opt, score } of scoreCatalogList(suffixText, catalog.equipment)) {
|
|
4908
|
+
pushScored(
|
|
4909
|
+
{
|
|
4910
|
+
...opt,
|
|
4911
|
+
detail: opt.detail ?? "Equipment",
|
|
4912
|
+
boost: clampBoost(Math.min(70, Math.round(score / 4))),
|
|
4913
|
+
apply: (view, _completion, from, to) => {
|
|
4914
|
+
view.dispatch({
|
|
4915
|
+
changes: { from: from + suffixDelta, to, insert: entry.label },
|
|
4916
|
+
selection: { anchor: from + suffixDelta + entry.label.length },
|
|
4917
|
+
userEvent: "input.complete"
|
|
4918
|
+
});
|
|
4919
|
+
}
|
|
4920
|
+
},
|
|
4921
|
+
score,
|
|
4922
|
+
`eff-prefix-eq:${entry.labelLower}:${suffixDelta}`
|
|
4923
|
+
);
|
|
4924
|
+
}
|
|
4925
|
+
}
|
|
4926
|
+
}
|
|
4927
|
+
}
|
|
4928
|
+
scoredOptions.sort((a, b) => b.score - a.score);
|
|
4929
|
+
const finalOptions = scoredOptions.map((x) => x.option);
|
|
4930
|
+
const suppressCreate = isExactAliasOrTermSplit(rawPhrase, catalog);
|
|
4931
|
+
const withCreate = appendCreateEffortOption(finalOptions, rawPhrase, options.onCreateEffort, suppressCreate);
|
|
4932
|
+
if (withCreate.length === 0) return null;
|
|
3891
4933
|
return {
|
|
3892
|
-
from:
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
4934
|
+
from: phraseFrom,
|
|
4935
|
+
...runLast.to > pos ? { to: runLast.to } : {},
|
|
4936
|
+
options: withCreate,
|
|
4937
|
+
filter: false
|
|
3896
4938
|
};
|
|
3897
4939
|
}
|
|
3898
4940
|
return null;
|
|
3899
4941
|
};
|
|
3900
4942
|
}
|
|
4943
|
+
function scoreCatalogList(query, entries) {
|
|
4944
|
+
const scored = [];
|
|
4945
|
+
for (const entry of entries) {
|
|
4946
|
+
const score = scoreCatalogEntry(query, entry);
|
|
4947
|
+
if (score !== null) scored.push({ entry, opt: entry.completion, score });
|
|
4948
|
+
}
|
|
4949
|
+
scored.sort((a, b) => b.score - a.score);
|
|
4950
|
+
return scored;
|
|
4951
|
+
}
|
|
4952
|
+
function scorePhrasePool(query, pool, catalog, onCreateEffort, allowCreate = true) {
|
|
4953
|
+
const scored = [];
|
|
4954
|
+
const effortMap = new Map(catalog.efforts.map((e) => [e.completion, e]));
|
|
4955
|
+
const eqMap = new Map(catalog.equipment.map((e) => [e.completion, e]));
|
|
4956
|
+
for (const opt of pool) {
|
|
4957
|
+
const eff = effortMap.get(opt);
|
|
4958
|
+
const eq = eqMap.get(opt);
|
|
4959
|
+
const score = eff ? scoreCatalogEntry(query, eff) : eq ? scoreCatalogEntry(query, eq) : scoreCompletionOption(query, opt);
|
|
4960
|
+
if (score !== null) scored.push({ opt, score });
|
|
4961
|
+
}
|
|
4962
|
+
scored.sort((a, b) => b.score - a.score);
|
|
4963
|
+
const res = scored.map((x) => x.opt);
|
|
4964
|
+
return allowCreate ? appendCreateEffortOption(res, query, onCreateEffort, isExactAliasOrTermSplit(query, catalog)) : res;
|
|
4965
|
+
}
|
|
3901
4966
|
function whiteboardScriptCompletion(options = {}) {
|
|
3902
4967
|
return autocomplete.autocompletion({ override: [whiteboardScriptCompletionSource(options)] });
|
|
3903
4968
|
}
|
|
@@ -3940,6 +5005,196 @@ function whiteboardScript(options) {
|
|
|
3940
5005
|
return new language.LanguageSupport(whiteboardScriptLanguage, whiteboardScriptCompletion(options ?? {}));
|
|
3941
5006
|
}
|
|
3942
5007
|
|
|
5008
|
+
// src/parser/indentation.ts
|
|
5009
|
+
var ROUNDS_QUALIFIER_WORDS2 = /^(rounds?|rds?|sets?|laps?|cycles?|intervals?)$/i;
|
|
5010
|
+
var CONTAINER_KEYWORDS = /* @__PURE__ */ new Set(["amrap", "emom", "tabata"]);
|
|
5011
|
+
function hasAnyErrorNode(node) {
|
|
5012
|
+
let found = false;
|
|
5013
|
+
node.cursor().iterate((cur) => {
|
|
5014
|
+
if (cur.type.isError) {
|
|
5015
|
+
found = true;
|
|
5016
|
+
return false;
|
|
5017
|
+
}
|
|
5018
|
+
return void 0;
|
|
5019
|
+
});
|
|
5020
|
+
return found;
|
|
5021
|
+
}
|
|
5022
|
+
function isRoundsHeaderLine(lineContent) {
|
|
5023
|
+
const trimmed = lineContent.trim();
|
|
5024
|
+
if (!trimmed) return false;
|
|
5025
|
+
const source = `${trimmed}
|
|
5026
|
+
`;
|
|
5027
|
+
const tree = parser.parse(source);
|
|
5028
|
+
if (hasAnyErrorNode(tree.topNode)) return false;
|
|
5029
|
+
const topChildren = [];
|
|
5030
|
+
for (let child = tree.topNode.firstChild; child; child = child.nextSibling) {
|
|
5031
|
+
if (child.name !== "newline") topChildren.push(child);
|
|
5032
|
+
}
|
|
5033
|
+
if (topChildren.length !== 1 || topChildren[0].name !== "Block") return false;
|
|
5034
|
+
const fragments = topChildren[0].getChildren("Fragment");
|
|
5035
|
+
if (fragments.length === 0) return false;
|
|
5036
|
+
let hasRoundsHeader = false;
|
|
5037
|
+
let hasContainerKeyword = false;
|
|
5038
|
+
let hasDuration = false;
|
|
5039
|
+
let hasLeafPayload = false;
|
|
5040
|
+
for (let i = 0; i < fragments.length; i++) {
|
|
5041
|
+
const frag = fragments[i];
|
|
5042
|
+
const kind = frag.firstChild;
|
|
5043
|
+
if (!kind) {
|
|
5044
|
+
hasLeafPayload = true;
|
|
5045
|
+
break;
|
|
5046
|
+
}
|
|
5047
|
+
switch (kind.name) {
|
|
5048
|
+
case "Rounds": {
|
|
5049
|
+
const raw = source.slice(kind.from, kind.to);
|
|
5050
|
+
if (!raw.endsWith(")")) return false;
|
|
5051
|
+
const seq = kind.getChild("Sequence");
|
|
5052
|
+
const idNode = kind.getChild("Identifier");
|
|
5053
|
+
if (!seq) {
|
|
5054
|
+
hasLeafPayload = true;
|
|
5055
|
+
break;
|
|
5056
|
+
}
|
|
5057
|
+
const numbers = seq.getChildren("Number");
|
|
5058
|
+
const idText = idNode ? source.slice(idNode.from, idNode.to) : "";
|
|
5059
|
+
if (numbers.length >= 2 && !idNode) {
|
|
5060
|
+
hasRoundsHeader = true;
|
|
5061
|
+
} else if (numbers.length === 1 && (!idNode || ROUNDS_QUALIFIER_WORDS2.test(idText))) {
|
|
5062
|
+
hasRoundsHeader = true;
|
|
5063
|
+
} else {
|
|
5064
|
+
hasLeafPayload = true;
|
|
5065
|
+
}
|
|
5066
|
+
break;
|
|
5067
|
+
}
|
|
5068
|
+
case "RoundScheme": {
|
|
5069
|
+
hasRoundsHeader = true;
|
|
5070
|
+
break;
|
|
5071
|
+
}
|
|
5072
|
+
case "Duration": {
|
|
5073
|
+
hasDuration = true;
|
|
5074
|
+
break;
|
|
5075
|
+
}
|
|
5076
|
+
case "Quantity": {
|
|
5077
|
+
const hasAtSign = Boolean(kind.getChild("AtSign"));
|
|
5078
|
+
const qtyRaw = source.slice(kind.from, kind.to);
|
|
5079
|
+
const isWholeInt = !hasAtSign && /^\d+$/.test(qtyRaw);
|
|
5080
|
+
if (!isWholeInt) {
|
|
5081
|
+
hasLeafPayload = true;
|
|
5082
|
+
break;
|
|
5083
|
+
}
|
|
5084
|
+
let j = i;
|
|
5085
|
+
let rungCount = 1;
|
|
5086
|
+
while (j + 2 < fragments.length && fragments[j + 1].firstChild?.name === "Effort" && source.slice(fragments[j + 1].from, fragments[j + 1].to) === "-" && fragments[j + 1].from === fragments[j].to && fragments[j + 2].firstChild?.name === "Quantity" && fragments[j + 2].from === fragments[j + 1].to && /^\d+$/.test(source.slice(fragments[j + 2].from, fragments[j + 2].to))) {
|
|
5087
|
+
rungCount++;
|
|
5088
|
+
j += 2;
|
|
5089
|
+
}
|
|
5090
|
+
if (rungCount >= 2) {
|
|
5091
|
+
hasRoundsHeader = true;
|
|
5092
|
+
i = j;
|
|
5093
|
+
if (i + 1 < fragments.length && fragments[i + 1].firstChild?.name === "Effort" && /^reps?$/i.test(source.slice(fragments[i + 1].from, fragments[i + 1].to).trim())) {
|
|
5094
|
+
i++;
|
|
5095
|
+
}
|
|
5096
|
+
break;
|
|
5097
|
+
}
|
|
5098
|
+
if (i + 1 < fragments.length && fragments[i + 1].firstChild?.name === "Effort" && ROUNDS_QUALIFIER_WORDS2.test(source.slice(fragments[i + 1].from, fragments[i + 1].to).trim())) {
|
|
5099
|
+
hasRoundsHeader = true;
|
|
5100
|
+
i++;
|
|
5101
|
+
break;
|
|
5102
|
+
}
|
|
5103
|
+
hasLeafPayload = true;
|
|
5104
|
+
break;
|
|
5105
|
+
}
|
|
5106
|
+
case "Effort": {
|
|
5107
|
+
const raw = source.slice(kind.from, kind.to).trim().toLowerCase();
|
|
5108
|
+
if (raw === "for" && i + 1 < fragments.length && fragments[i + 1].firstChild?.name === "Effort" && source.slice(fragments[i + 1].from, fragments[i + 1].to).trim().toLowerCase() === "time") {
|
|
5109
|
+
hasContainerKeyword = true;
|
|
5110
|
+
i++;
|
|
5111
|
+
break;
|
|
5112
|
+
}
|
|
5113
|
+
if (CONTAINER_KEYWORDS.has(raw)) {
|
|
5114
|
+
hasContainerKeyword = true;
|
|
5115
|
+
break;
|
|
5116
|
+
}
|
|
5117
|
+
if (raw === "work" && (hasRoundsHeader || hasDuration)) {
|
|
5118
|
+
break;
|
|
5119
|
+
}
|
|
5120
|
+
hasLeafPayload = true;
|
|
5121
|
+
break;
|
|
5122
|
+
}
|
|
5123
|
+
case "TagRef":
|
|
5124
|
+
case "Text":
|
|
5125
|
+
break;
|
|
5126
|
+
default:
|
|
5127
|
+
hasLeafPayload = true;
|
|
5128
|
+
break;
|
|
5129
|
+
}
|
|
5130
|
+
if (hasLeafPayload) break;
|
|
5131
|
+
}
|
|
5132
|
+
return (hasRoundsHeader || hasContainerKeyword) && !hasLeafPayload;
|
|
5133
|
+
}
|
|
5134
|
+
function computeWhiteboardEnterAction(lineText, fromCol, toCol = fromCol, unit = " ") {
|
|
5135
|
+
const indent = /^[ \t]*/.exec(lineText)[0];
|
|
5136
|
+
const before = lineText.slice(0, fromCol);
|
|
5137
|
+
const after = lineText.slice(toCol);
|
|
5138
|
+
const isCollapsed = fromCol === toCol;
|
|
5139
|
+
if (lineText.trim() === "") {
|
|
5140
|
+
if (indent.length > 0) {
|
|
5141
|
+
return {
|
|
5142
|
+
replaceFromCol: 0,
|
|
5143
|
+
replaceToCol: lineText.length,
|
|
5144
|
+
insert: "\n",
|
|
5145
|
+
cursorOffset: 1
|
|
5146
|
+
};
|
|
5147
|
+
}
|
|
5148
|
+
return {
|
|
5149
|
+
replaceFromCol: fromCol,
|
|
5150
|
+
replaceToCol: toCol,
|
|
5151
|
+
insert: "\n",
|
|
5152
|
+
cursorOffset: 1
|
|
5153
|
+
};
|
|
5154
|
+
}
|
|
5155
|
+
if (/^([ \t]*)([+-])(?![+-])[ \t]*$/.test(lineText) && fromCol >= indent.length + 1) {
|
|
5156
|
+
return {
|
|
5157
|
+
replaceFromCol: 0,
|
|
5158
|
+
replaceToCol: lineText.length,
|
|
5159
|
+
insert: "\n",
|
|
5160
|
+
cursorOffset: 1
|
|
5161
|
+
};
|
|
5162
|
+
}
|
|
5163
|
+
if (isCollapsed && fromCol <= indent.length && after.trim().length > 0) {
|
|
5164
|
+
const keptIndent = indent.slice(0, fromCol);
|
|
5165
|
+
return {
|
|
5166
|
+
replaceFromCol: 0,
|
|
5167
|
+
replaceToCol: fromCol,
|
|
5168
|
+
insert: `
|
|
5169
|
+
${keptIndent}`,
|
|
5170
|
+
cursorOffset: 1 + keptIndent.length
|
|
5171
|
+
};
|
|
5172
|
+
}
|
|
5173
|
+
const leadingAfterSpaces = /^[ \t]+/.exec(after)?.[0].length ?? 0;
|
|
5174
|
+
const markerMatch = /^([ \t]*)([+-])(?![+-])([ \t]*)(.*)$/.exec(before);
|
|
5175
|
+
if (markerMatch) {
|
|
5176
|
+
const marker = markerMatch[2];
|
|
5177
|
+
const contentBefore = markerMatch[4].trim();
|
|
5178
|
+
const nextPrefix2 = contentBefore.length > 0 ? isRoundsHeaderLine(contentBefore) ? `${indent}${unit}` : `${indent}${marker} ` : indent;
|
|
5179
|
+
return {
|
|
5180
|
+
replaceFromCol: fromCol,
|
|
5181
|
+
replaceToCol: toCol + leadingAfterSpaces,
|
|
5182
|
+
insert: `
|
|
5183
|
+
${nextPrefix2}`,
|
|
5184
|
+
cursorOffset: 1 + nextPrefix2.length
|
|
5185
|
+
};
|
|
5186
|
+
}
|
|
5187
|
+
const beforeContent = before.slice(indent.length).trim();
|
|
5188
|
+
const nextPrefix = isRoundsHeaderLine(beforeContent) ? `${indent}${unit}` : indent;
|
|
5189
|
+
return {
|
|
5190
|
+
replaceFromCol: fromCol,
|
|
5191
|
+
replaceToCol: toCol + leadingAfterSpaces,
|
|
5192
|
+
insert: `
|
|
5193
|
+
${nextPrefix}`,
|
|
5194
|
+
cursorOffset: 1 + nextPrefix.length
|
|
5195
|
+
};
|
|
5196
|
+
}
|
|
5197
|
+
|
|
3943
5198
|
// src/effort-registry/types.ts
|
|
3944
5199
|
var EFFORT_REGISTRY_ORIGINS = ["bundled", "user"];
|
|
3945
5200
|
var SEED_PRECEDENCE_RANK = {
|
|
@@ -4628,71 +5883,6 @@ function tagCategoryRecordToDocument(category, record) {
|
|
|
4628
5883
|
...Object.keys(widgets).length > 0 ? { widgets } : {}
|
|
4629
5884
|
});
|
|
4630
5885
|
}
|
|
4631
|
-
|
|
4632
|
-
// src/effort-registry/fuzzyMatch.ts
|
|
4633
|
-
function levenshteinDistance(a, b) {
|
|
4634
|
-
if (a === b) return 0;
|
|
4635
|
-
if (a.length === 0) return b.length;
|
|
4636
|
-
if (b.length === 0) return a.length;
|
|
4637
|
-
if (a.length > b.length) {
|
|
4638
|
-
const tmp = a;
|
|
4639
|
-
a = b;
|
|
4640
|
-
b = tmp;
|
|
4641
|
-
}
|
|
4642
|
-
const m = a.length;
|
|
4643
|
-
const n = b.length;
|
|
4644
|
-
let prev = new Uint32Array(m + 1);
|
|
4645
|
-
let curr = new Uint32Array(m + 1);
|
|
4646
|
-
for (let i = 0; i <= m; i++) {
|
|
4647
|
-
prev[i] = i;
|
|
4648
|
-
}
|
|
4649
|
-
for (let j = 1; j <= n; j++) {
|
|
4650
|
-
curr[0] = j;
|
|
4651
|
-
const bj = b.charCodeAt(j - 1);
|
|
4652
|
-
for (let i = 1; i <= m; i++) {
|
|
4653
|
-
const cost = a.charCodeAt(i - 1) === bj ? 0 : 1;
|
|
4654
|
-
curr[i] = Math.min(
|
|
4655
|
-
prev[i] + 1,
|
|
4656
|
-
// deletion
|
|
4657
|
-
curr[i - 1] + 1,
|
|
4658
|
-
// insertion
|
|
4659
|
-
prev[i - 1] + cost
|
|
4660
|
-
// substitution
|
|
4661
|
-
);
|
|
4662
|
-
}
|
|
4663
|
-
const swap = prev;
|
|
4664
|
-
prev = curr;
|
|
4665
|
-
curr = swap;
|
|
4666
|
-
}
|
|
4667
|
-
return prev[m];
|
|
4668
|
-
}
|
|
4669
|
-
function normalizeForFuzzy(input) {
|
|
4670
|
-
return input.toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu, " ").replace(/[-_]+/g, " ").trim().replace(/\s+/g, " ");
|
|
4671
|
-
}
|
|
4672
|
-
function isWithinThreshold(a, b, threshold) {
|
|
4673
|
-
const na = normalizeForFuzzy(a);
|
|
4674
|
-
const nb = normalizeForFuzzy(b);
|
|
4675
|
-
if (na === nb) return true;
|
|
4676
|
-
if (Math.abs(na.length - nb.length) > threshold) return false;
|
|
4677
|
-
return levenshteinDistance(na, nb) <= threshold;
|
|
4678
|
-
}
|
|
4679
|
-
function findBestFuzzyMatch(query, candidates, threshold) {
|
|
4680
|
-
const nq = normalizeForFuzzy(query);
|
|
4681
|
-
let best = null;
|
|
4682
|
-
for (const candidate of candidates) {
|
|
4683
|
-
const nc = normalizeForFuzzy(candidate);
|
|
4684
|
-
if (Math.abs(nq.length - nc.length) > threshold) continue;
|
|
4685
|
-
const distance = levenshteinDistance(nq, nc);
|
|
4686
|
-
if (distance > threshold) continue;
|
|
4687
|
-
if (!best || distance < best.distance) {
|
|
4688
|
-
best = { target: candidate, distance };
|
|
4689
|
-
if (distance === 0) break;
|
|
4690
|
-
}
|
|
4691
|
-
}
|
|
4692
|
-
return best;
|
|
4693
|
-
}
|
|
4694
|
-
|
|
4695
|
-
// src/effort-registry/EffortResolver.ts
|
|
4696
5886
|
function normalizeSlug(label) {
|
|
4697
5887
|
return normalizeForFuzzy(label).replace(/\s+/g, "-");
|
|
4698
5888
|
}
|
|
@@ -5227,6 +6417,14 @@ function buildExactIndex(entities) {
|
|
|
5227
6417
|
}
|
|
5228
6418
|
const topTier = direct.filter((candidate) => resolveEntityRank(candidate) === maxRank);
|
|
5229
6419
|
if (topTier.length === 1) return { entity: topTier[0], ambiguous: [] };
|
|
6420
|
+
const trimmedLower = key.trim().toLowerCase();
|
|
6421
|
+
const slugified = normalizeForFuzzy(key).replace(/\s+/g, "-");
|
|
6422
|
+
const exactSlugMatches = topTier.filter(
|
|
6423
|
+
(candidate) => candidate.slug.toLowerCase() === trimmedLower || candidate.slug.toLowerCase() === slugified
|
|
6424
|
+
);
|
|
6425
|
+
if (exactSlugMatches.length === 1) {
|
|
6426
|
+
return { entity: exactSlugMatches[0], ambiguous: [] };
|
|
6427
|
+
}
|
|
5230
6428
|
return { entity: null, ambiguous: topTier };
|
|
5231
6429
|
}
|
|
5232
6430
|
};
|
|
@@ -5249,7 +6447,7 @@ function createReferenceIndex(catalog, materialize) {
|
|
|
5249
6447
|
const dedupedEquipment = dedupeEntitiesByPrecedence(catalog.equipment ?? []);
|
|
5250
6448
|
const efforts = buildExactIndex(catalog.efforts ?? []);
|
|
5251
6449
|
const equipment = buildExactIndex(dedupedEquipment);
|
|
5252
|
-
const
|
|
6450
|
+
const equipmentCandidates = dedupedEquipment.flatMap((entity) => [entity.label, ...entity.aliases].filter((name2) => !!name2 && !!name2.trim()).map((name2) => ({ lower: name2.trim().toLowerCase(), entity }))).sort((a, b) => b.lower.length - a.lower.length);
|
|
5253
6451
|
const materializer = materialize ?? ((effort) => ({
|
|
5254
6452
|
effort,
|
|
5255
6453
|
definition: effort,
|
|
@@ -5337,6 +6535,7 @@ function createReferenceIndex(catalog, materialize) {
|
|
|
5337
6535
|
let remaining = "";
|
|
5338
6536
|
let equipmentRefs = [];
|
|
5339
6537
|
let equipmentAuthored = false;
|
|
6538
|
+
let equipmentSpan;
|
|
5340
6539
|
const fillEquipment = () => {
|
|
5341
6540
|
if (equipmentRefs.length > 0 || equipmentAuthored) return;
|
|
5342
6541
|
if (effortEntity === null) return;
|
|
@@ -5449,8 +6648,9 @@ function createReferenceIndex(catalog, materialize) {
|
|
|
5449
6648
|
};
|
|
5450
6649
|
}
|
|
5451
6650
|
}
|
|
6651
|
+
const wholeFound = resolveEffortExact(source);
|
|
5452
6652
|
const lowerSource = source.toLowerCase();
|
|
5453
|
-
for (const candidate of
|
|
6653
|
+
for (const candidate of equipmentCandidates) {
|
|
5454
6654
|
if (!lowerSource.startsWith(candidate.lower)) continue;
|
|
5455
6655
|
const after = source.slice(candidate.lower.length);
|
|
5456
6656
|
if (after && !/^\s/.test(after)) continue;
|
|
@@ -5476,6 +6676,11 @@ function createReferenceIndex(catalog, materialize) {
|
|
|
5476
6676
|
}
|
|
5477
6677
|
if (!equipmentFound.entity) continue;
|
|
5478
6678
|
const effortFound = resolveEffortExact(candidateRemaining);
|
|
6679
|
+
if (wholeFound.entity && wholeFound.entity.equipment?.includes(equipmentFound.entity.slug) && (effortFound.entity || effortFound.diagnostic?.reason === "ambiguous-effort")) {
|
|
6680
|
+
matched = "whole";
|
|
6681
|
+
effortEntity = wholeFound.entity;
|
|
6682
|
+
break;
|
|
6683
|
+
}
|
|
5479
6684
|
if (effortFound.entity) {
|
|
5480
6685
|
matched = "split";
|
|
5481
6686
|
effortEntity = effortFound.entity;
|
|
@@ -5486,9 +6691,10 @@ function createReferenceIndex(catalog, materialize) {
|
|
|
5486
6691
|
}];
|
|
5487
6692
|
equipmentAuthored = true;
|
|
5488
6693
|
remaining = candidateRemaining;
|
|
6694
|
+
equipmentSpan = { start: 0, end: rawPrefix.length };
|
|
5489
6695
|
break;
|
|
5490
6696
|
}
|
|
5491
|
-
if (effortFound.diagnostic?.reason === "ambiguous-effort") {
|
|
6697
|
+
if (effortFound.diagnostic?.reason === "ambiguous-effort" && !wholeFound.entity) {
|
|
5492
6698
|
push(effortFound.diagnostic);
|
|
5493
6699
|
return {
|
|
5494
6700
|
matched: "none",
|
|
@@ -5502,12 +6708,11 @@ function createReferenceIndex(catalog, materialize) {
|
|
|
5502
6708
|
}
|
|
5503
6709
|
}
|
|
5504
6710
|
if (matched === "none") {
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
effortEntity = found.entity;
|
|
6711
|
+
if (wholeFound.entity) {
|
|
6712
|
+
effortEntity = wholeFound.entity;
|
|
5508
6713
|
matched = "whole";
|
|
5509
|
-
} else if (
|
|
5510
|
-
push(
|
|
6714
|
+
} else if (wholeFound.diagnostic?.reason === "ambiguous-effort") {
|
|
6715
|
+
push(wholeFound.diagnostic);
|
|
5511
6716
|
return {
|
|
5512
6717
|
matched: "none",
|
|
5513
6718
|
label: source,
|
|
@@ -5517,8 +6722,65 @@ function createReferenceIndex(catalog, materialize) {
|
|
|
5517
6722
|
remaining: "",
|
|
5518
6723
|
diagnostics
|
|
5519
6724
|
};
|
|
5520
|
-
} else if (
|
|
5521
|
-
push(
|
|
6725
|
+
} else if (wholeFound.diagnostic) {
|
|
6726
|
+
push(wholeFound.diagnostic);
|
|
6727
|
+
}
|
|
6728
|
+
}
|
|
6729
|
+
if (matched === "none") {
|
|
6730
|
+
for (const candidate of equipmentCandidates) {
|
|
6731
|
+
if (!lowerSource.endsWith(candidate.lower)) continue;
|
|
6732
|
+
const beforeLen = source.length - candidate.lower.length;
|
|
6733
|
+
if (beforeLen <= 0 || !/\s$/.test(source.slice(0, beforeLen))) continue;
|
|
6734
|
+
const candidateRemaining = source.slice(0, beforeLen).trim();
|
|
6735
|
+
if (!candidateRemaining) continue;
|
|
6736
|
+
const equipmentFound = equipment.lookup(candidate.lower);
|
|
6737
|
+
if (equipmentFound.ambiguous.length > 0) {
|
|
6738
|
+
diagnostics.length = 0;
|
|
6739
|
+
push({
|
|
6740
|
+
reason: "ambiguous-equipment",
|
|
6741
|
+
message: `"${candidate.lower}" matches multiple equipment entries.`,
|
|
6742
|
+
token: source,
|
|
6743
|
+
candidates: equipmentFound.ambiguous.map((e) => e.slug)
|
|
6744
|
+
});
|
|
6745
|
+
return {
|
|
6746
|
+
matched: "none",
|
|
6747
|
+
label: source,
|
|
6748
|
+
effort: null,
|
|
6749
|
+
effortRef: null,
|
|
6750
|
+
equipment: [],
|
|
6751
|
+
remaining: "",
|
|
6752
|
+
diagnostics
|
|
6753
|
+
};
|
|
6754
|
+
}
|
|
6755
|
+
if (!equipmentFound.entity) continue;
|
|
6756
|
+
const effortFound = resolveEffortExact(candidateRemaining);
|
|
6757
|
+
if (effortFound.entity) {
|
|
6758
|
+
diagnostics.length = 0;
|
|
6759
|
+
matched = "split";
|
|
6760
|
+
effortEntity = effortFound.entity;
|
|
6761
|
+
const rawSuffix = source.slice(beforeLen);
|
|
6762
|
+
equipmentRefs = [{
|
|
6763
|
+
...equipmentRef(equipmentFound.entity),
|
|
6764
|
+
...rawSuffix.toLowerCase() !== equipmentFound.entity.label.toLowerCase() ? { matchedAlias: rawSuffix } : {}
|
|
6765
|
+
}];
|
|
6766
|
+
equipmentAuthored = true;
|
|
6767
|
+
remaining = candidateRemaining;
|
|
6768
|
+
equipmentSpan = { start: beforeLen, end: source.length };
|
|
6769
|
+
break;
|
|
6770
|
+
}
|
|
6771
|
+
if (effortFound.diagnostic?.reason === "ambiguous-effort") {
|
|
6772
|
+
diagnostics.length = 0;
|
|
6773
|
+
push(effortFound.diagnostic);
|
|
6774
|
+
return {
|
|
6775
|
+
matched: "none",
|
|
6776
|
+
label: source,
|
|
6777
|
+
effort: null,
|
|
6778
|
+
effortRef: null,
|
|
6779
|
+
equipment: [],
|
|
6780
|
+
remaining: "",
|
|
6781
|
+
diagnostics
|
|
6782
|
+
};
|
|
6783
|
+
}
|
|
5522
6784
|
}
|
|
5523
6785
|
}
|
|
5524
6786
|
fillEquipment();
|
|
@@ -5535,6 +6797,7 @@ function createReferenceIndex(catalog, materialize) {
|
|
|
5535
6797
|
} : null,
|
|
5536
6798
|
equipment: equipmentRefs,
|
|
5537
6799
|
remaining,
|
|
6800
|
+
...equipmentSpan ? { equipmentSpan } : {},
|
|
5538
6801
|
diagnostics
|
|
5539
6802
|
};
|
|
5540
6803
|
}
|
|
@@ -6453,6 +7716,48 @@ var CurrentRoundMetric = class {
|
|
|
6453
7716
|
value;
|
|
6454
7717
|
image;
|
|
6455
7718
|
};
|
|
7719
|
+
|
|
7720
|
+
// src/runtime/time/calculateElapsed.ts
|
|
7721
|
+
function calculateElapsed(timer, now) {
|
|
7722
|
+
let total = 0;
|
|
7723
|
+
for (const span of timer.spans) {
|
|
7724
|
+
const end = span.ended ?? now;
|
|
7725
|
+
total += end - span.started;
|
|
7726
|
+
}
|
|
7727
|
+
return total;
|
|
7728
|
+
}
|
|
7729
|
+
function formatDuration(ms) {
|
|
7730
|
+
const totalSeconds = Math.floor(ms / 1e3);
|
|
7731
|
+
const mins = Math.floor(totalSeconds / 60);
|
|
7732
|
+
const secs = totalSeconds % 60;
|
|
7733
|
+
return `${mins}:${secs.toString().padStart(2, "0")}`;
|
|
7734
|
+
}
|
|
7735
|
+
|
|
7736
|
+
// src/runtime/compiler/metrics/ElapsedMetric.ts
|
|
7737
|
+
var ElapsedMetric = class {
|
|
7738
|
+
/**
|
|
7739
|
+
* @param value Elapsed time in milliseconds
|
|
7740
|
+
* @param sourceBlockKey Block that produced this measurement
|
|
7741
|
+
* @param timestamp When this metrics was created
|
|
7742
|
+
*/
|
|
7743
|
+
constructor(value, sourceBlockKey, timestamp) {
|
|
7744
|
+
this.value = value;
|
|
7745
|
+
this.sourceBlockKey = sourceBlockKey;
|
|
7746
|
+
this.timestamp = timestamp;
|
|
7747
|
+
}
|
|
7748
|
+
value;
|
|
7749
|
+
sourceBlockKey;
|
|
7750
|
+
timestamp;
|
|
7751
|
+
type = wodWikiCore.MetricType.Elapsed;
|
|
7752
|
+
origin = "analyzed";
|
|
7753
|
+
unit = "ms";
|
|
7754
|
+
/** Human-readable elapsed time (e.g., "5:03") */
|
|
7755
|
+
get image() {
|
|
7756
|
+
return formatDuration(this.value);
|
|
7757
|
+
}
|
|
7758
|
+
};
|
|
7759
|
+
|
|
7760
|
+
// src/runtime/OutputEmitter.ts
|
|
6456
7761
|
var OutputEmitter = class {
|
|
6457
7762
|
_outputStatements = [];
|
|
6458
7763
|
_outputListeners = /* @__PURE__ */ new Set();
|
|
@@ -6738,6 +8043,13 @@ var OutputEmitter = class {
|
|
|
6738
8043
|
}
|
|
6739
8044
|
}
|
|
6740
8045
|
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));
|
|
8046
|
+
if (recordedSpans.length > 0 && !metrics.some((m) => m.type === wodWikiCore.MetricType.Elapsed)) {
|
|
8047
|
+
const activeElapsedMs = recordedSpans.reduce(
|
|
8048
|
+
(acc, s) => acc + Math.max(0, (typeof s.ended === "number" && Number.isFinite(s.ended) ? s.ended : fallbackEndMs) - s.started),
|
|
8049
|
+
0
|
|
8050
|
+
);
|
|
8051
|
+
metrics.add(new ElapsedMetric(activeElapsedMs, block.key.toString(), new Date(fallbackEndMs)));
|
|
8052
|
+
}
|
|
6741
8053
|
const timeSpan = recordedSpans.length > 0 ? new TimeSpan(
|
|
6742
8054
|
Math.min(...recordedSpans.map((s) => s.started)),
|
|
6743
8055
|
Math.max(...recordedSpans.map((s) => typeof s.ended === "number" && Number.isFinite(s.ended) ? s.ended : fallbackEndMs))
|
|
@@ -8458,22 +9770,6 @@ var ClearChildrenAction = class {
|
|
|
8458
9770
|
}
|
|
8459
9771
|
};
|
|
8460
9772
|
|
|
8461
|
-
// src/runtime/time/calculateElapsed.ts
|
|
8462
|
-
function calculateElapsed(timer, now) {
|
|
8463
|
-
let total = 0;
|
|
8464
|
-
for (const span of timer.spans) {
|
|
8465
|
-
const end = span.ended ?? now;
|
|
8466
|
-
total += end - span.started;
|
|
8467
|
-
}
|
|
8468
|
-
return total;
|
|
8469
|
-
}
|
|
8470
|
-
function formatDuration(ms) {
|
|
8471
|
-
const totalSeconds = Math.floor(ms / 1e3);
|
|
8472
|
-
const mins = Math.floor(totalSeconds / 60);
|
|
8473
|
-
const secs = totalSeconds % 60;
|
|
8474
|
-
return `${mins}:${secs.toString().padStart(2, "0")}`;
|
|
8475
|
-
}
|
|
8476
|
-
|
|
8477
9773
|
// src/runtime/behaviors/CountdownTimerBehavior.ts
|
|
8478
9774
|
var CountdownTimerBehavior = class {
|
|
8479
9775
|
constructor(config) {
|
|
@@ -11192,27 +12488,6 @@ var ChildSelectionBehavior = class _ChildSelectionBehavior {
|
|
|
11192
12488
|
return "timer-active";
|
|
11193
12489
|
}
|
|
11194
12490
|
};
|
|
11195
|
-
var ElapsedMetric = class {
|
|
11196
|
-
/**
|
|
11197
|
-
* @param value Elapsed time in milliseconds
|
|
11198
|
-
* @param sourceBlockKey Block that produced this measurement
|
|
11199
|
-
* @param timestamp When this metrics was created
|
|
11200
|
-
*/
|
|
11201
|
-
constructor(value, sourceBlockKey, timestamp) {
|
|
11202
|
-
this.value = value;
|
|
11203
|
-
this.sourceBlockKey = sourceBlockKey;
|
|
11204
|
-
this.timestamp = timestamp;
|
|
11205
|
-
}
|
|
11206
|
-
value;
|
|
11207
|
-
sourceBlockKey;
|
|
11208
|
-
timestamp;
|
|
11209
|
-
type = wodWikiCore.MetricType.Elapsed;
|
|
11210
|
-
origin = "analyzed";
|
|
11211
|
-
/** Human-readable elapsed time (e.g., "5:03") */
|
|
11212
|
-
get image() {
|
|
11213
|
-
return formatDuration(this.value);
|
|
11214
|
-
}
|
|
11215
|
-
};
|
|
11216
12491
|
var TotalMetric = class {
|
|
11217
12492
|
/**
|
|
11218
12493
|
* @param value Total wall-clock time in milliseconds
|
|
@@ -11358,14 +12633,19 @@ var ReportOutputBehavior = class {
|
|
|
11358
12633
|
const timer = readTimer(ctx);
|
|
11359
12634
|
const round = ctx.getMemoryByTag("round")[0]?.metrics[0];
|
|
11360
12635
|
const shouldComputeTimeResults = this.config.computeTimeResults ?? true;
|
|
12636
|
+
const reason = ctx.block.completionReason;
|
|
12637
|
+
const earlyTermination = reason === "user-abort" || reason === "forced-pop" || reason === "timer-expired";
|
|
12638
|
+
const effectiveRound = round ? earlyTermination ? { current: Math.max(0, round.current - 1), total: round.total } : round : void 0;
|
|
11361
12639
|
let completionLabel = this.config.label ?? "Completed";
|
|
11362
12640
|
if (!this.config.label) {
|
|
11363
12641
|
if (ctx.block.blockType === "SessionRoot") {
|
|
11364
12642
|
completionLabel = "Session Completed";
|
|
11365
|
-
} else if (
|
|
11366
|
-
completionLabel = `Completed ${
|
|
11367
|
-
} else if (
|
|
11368
|
-
completionLabel = `Completed ${
|
|
12643
|
+
} else if (effectiveRound && !earlyTermination && effectiveRound.total !== void 0 && effectiveRound.total > 1) {
|
|
12644
|
+
completionLabel = `Completed ${effectiveRound.total} Round(s)`;
|
|
12645
|
+
} else if (effectiveRound && effectiveRound.current > 0) {
|
|
12646
|
+
completionLabel = `Completed ${effectiveRound.current} Round(s)`;
|
|
12647
|
+
} else if (earlyTermination && round) {
|
|
12648
|
+
completionLabel = "Completed 0 Round(s)";
|
|
11369
12649
|
}
|
|
11370
12650
|
}
|
|
11371
12651
|
if (shouldComputeTimeResults) {
|
|
@@ -11448,6 +12728,9 @@ var ReportOutputBehavior = class {
|
|
|
11448
12728
|
const nowMs = now.getTime();
|
|
11449
12729
|
const blockKey = ctx.block.key.toString();
|
|
11450
12730
|
const round = ctx.getMemoryByTag("round")[0]?.metrics[0];
|
|
12731
|
+
const reason = ctx.block.completionReason;
|
|
12732
|
+
const earlyTermination = reason === "user-abort" || reason === "forced-pop" || reason === "timer-expired";
|
|
12733
|
+
const reportedRound = round && earlyTermination ? { current: Math.max(0, round.current - 1), total: round.total } : round;
|
|
11451
12734
|
if (timer && timer.spans.length > 0) {
|
|
11452
12735
|
const elapsed = calculateElapsed(timer, nowMs);
|
|
11453
12736
|
const closedSpans = timer.spans.map(
|
|
@@ -11463,8 +12746,8 @@ var ReportOutputBehavior = class {
|
|
|
11463
12746
|
new SpansMetric(closedSpans, blockKey, now),
|
|
11464
12747
|
new SystemTimeMetric(this._now.now(), blockKey)
|
|
11465
12748
|
);
|
|
11466
|
-
if (
|
|
11467
|
-
metrics2.add(new CurrentRoundMetric(
|
|
12749
|
+
if (reportedRound && reportedRound.current > 0) {
|
|
12750
|
+
metrics2.add(new CurrentRoundMetric(reportedRound.current, reportedRound.total, blockKey, now, customRoundLabel));
|
|
11468
12751
|
}
|
|
11469
12752
|
return metrics2;
|
|
11470
12753
|
}
|
|
@@ -11477,8 +12760,8 @@ var ReportOutputBehavior = class {
|
|
|
11477
12760
|
new SpansMetric([span], blockKey, now),
|
|
11478
12761
|
new SystemTimeMetric(this._now.now(), blockKey)
|
|
11479
12762
|
);
|
|
11480
|
-
if (
|
|
11481
|
-
metrics.add(new CurrentRoundMetric(
|
|
12763
|
+
if (reportedRound && reportedRound.current > 0) {
|
|
12764
|
+
metrics.add(new CurrentRoundMetric(reportedRound.current, reportedRound.total, blockKey, now, customRoundLabel));
|
|
11482
12765
|
}
|
|
11483
12766
|
return metrics;
|
|
11484
12767
|
}
|
|
@@ -12769,7 +14052,10 @@ var AnalyticsEngine = class {
|
|
|
12769
14052
|
// metadata (effortSlug/discipline/…) through to stored logs.
|
|
12770
14053
|
{
|
|
12771
14054
|
type: p.metricType || wodWikiCore.MetricType.Metric,
|
|
12772
|
-
image:
|
|
14055
|
+
image: (() => {
|
|
14056
|
+
const displayVal = Number.isInteger(p.value) ? String(p.value) : (Math.round(p.value * 10) / 10).toFixed(1);
|
|
14057
|
+
return p.unit ? `${displayVal} ${p.unit}` : displayVal;
|
|
14058
|
+
})(),
|
|
12773
14059
|
value: p.value,
|
|
12774
14060
|
unit: p.unit,
|
|
12775
14061
|
origin: p.origin ?? "analyzed",
|
|
@@ -13031,8 +14317,15 @@ var CalculationRegistry = class {
|
|
|
13031
14317
|
if (def.kind === "output" && def.output?.unit && def.output.unit !== "auto") {
|
|
13032
14318
|
for (const variant of def.variants) {
|
|
13033
14319
|
for (const nodeId of outputNodeIds(def)) {
|
|
14320
|
+
const outNode = variant.nodes[nodeId];
|
|
13034
14321
|
const dim = variant.nodeDims?.[nodeId];
|
|
13035
|
-
if (
|
|
14322
|
+
if (outNode && (outNode.kind === "wql" || astHasWql(outNode.ast, variant))) {
|
|
14323
|
+
if (!getUnit(def.output.unit)) {
|
|
14324
|
+
throw new CalcRegistrationError(`Calc ${def.id}: Unknown output unit: ${def.output.unit}`);
|
|
14325
|
+
}
|
|
14326
|
+
} else if (dim) {
|
|
14327
|
+
validateOutputUnit(dim, def.output.unit);
|
|
14328
|
+
}
|
|
13036
14329
|
}
|
|
13037
14330
|
}
|
|
13038
14331
|
}
|
|
@@ -13064,8 +14357,14 @@ var CalculationRegistry = class {
|
|
|
13064
14357
|
const env = this.staticEnv(siblingRefDim);
|
|
13065
14358
|
let dim = inferDim(ast, env);
|
|
13066
14359
|
if (node.unit) {
|
|
13067
|
-
|
|
13068
|
-
|
|
14360
|
+
if (astHasWql(ast, variant)) {
|
|
14361
|
+
const unitDef = getUnit(node.unit);
|
|
14362
|
+
if (!unitDef) throw new CalcRegistrationError(`Unknown output unit: ${node.unit}`);
|
|
14363
|
+
dim = AUTHORITATIVE_CASTS[node.unit] ? DIM_ZERO : unitDef.dim;
|
|
14364
|
+
} else {
|
|
14365
|
+
validateOutputUnit(dim, node.unit);
|
|
14366
|
+
if (AUTHORITATIVE_CASTS[node.unit]) dim = DIM_ZERO;
|
|
14367
|
+
}
|
|
13069
14368
|
}
|
|
13070
14369
|
nodeDims[nodeId] = dim;
|
|
13071
14370
|
return dim;
|
|
@@ -13122,6 +14421,30 @@ function outputNodeIds(def) {
|
|
|
13122
14421
|
if (!nodeId) return [];
|
|
13123
14422
|
return Array.isArray(nodeId) ? nodeId : [nodeId];
|
|
13124
14423
|
}
|
|
14424
|
+
function astHasWql(node, variant, seen = /* @__PURE__ */ new Set()) {
|
|
14425
|
+
if (!node) return false;
|
|
14426
|
+
switch (node.kind) {
|
|
14427
|
+
case "wql":
|
|
14428
|
+
return true;
|
|
14429
|
+
case "ref": {
|
|
14430
|
+
if (seen.has(node.name)) return false;
|
|
14431
|
+
const target = variant.nodes[node.name];
|
|
14432
|
+
if (!target) return false;
|
|
14433
|
+
if (target.kind === "wql") return true;
|
|
14434
|
+
const next = new Set(seen);
|
|
14435
|
+
next.add(node.name);
|
|
14436
|
+
return astHasWql(target.ast, variant, next);
|
|
14437
|
+
}
|
|
14438
|
+
case "unary":
|
|
14439
|
+
return astHasWql(node.arg, variant, seen);
|
|
14440
|
+
case "binary":
|
|
14441
|
+
return astHasWql(node.left, variant, seen) || astHasWql(node.right, variant, seen);
|
|
14442
|
+
case "call":
|
|
14443
|
+
return node.args.some((arg) => astHasWql(arg, variant, seen));
|
|
14444
|
+
default:
|
|
14445
|
+
return false;
|
|
14446
|
+
}
|
|
14447
|
+
}
|
|
13125
14448
|
|
|
13126
14449
|
// src/analytics/calc/engine.ts
|
|
13127
14450
|
var CalcEngine = class {
|
|
@@ -14284,7 +15607,7 @@ var STORE_CALCS = [
|
|
|
14284
15607
|
value: expr("value", "daily * (daily / daily)")
|
|
14285
15608
|
}
|
|
14286
15609
|
}],
|
|
14287
|
-
output: { nodeId: "value", key: "calc.sleep", unit: "
|
|
15610
|
+
output: { nodeId: "value", key: "calc.sleep", unit: "h", label: "Sleep (h)" }
|
|
14288
15611
|
},
|
|
14289
15612
|
{
|
|
14290
15613
|
id: "hrv",
|
|
@@ -14300,7 +15623,7 @@ var STORE_CALCS = [
|
|
|
14300
15623
|
value: expr("value", "daily * (daily / daily)")
|
|
14301
15624
|
}
|
|
14302
15625
|
}],
|
|
14303
|
-
output: { nodeId: "value", key: "calc.hrv", unit: "
|
|
15626
|
+
output: { nodeId: "value", key: "calc.hrv", unit: "ms", label: "HRV (ms)" }
|
|
14304
15627
|
},
|
|
14305
15628
|
{
|
|
14306
15629
|
// Readiness composite: soreness (inverted) 40%, sleep 30%, HRV 30%,
|
|
@@ -14847,7 +16170,7 @@ var LabelComposer = class {
|
|
|
14847
16170
|
static getIdentityText(metrics) {
|
|
14848
16171
|
const logicKeywords = ["AMRAP", "EMOM", "TABATA", "FOR TIME"];
|
|
14849
16172
|
const identityFragments = metrics.filter((f) => {
|
|
14850
|
-
if (f.type === wodWikiCore.MetricType.Duration || f.type === wodWikiCore.MetricType.Rounds || f.type === wodWikiCore.MetricType.Resistance || f.type === wodWikiCore.MetricType.Distance || f.type === wodWikiCore.MetricType.Lap || f.type === wodWikiCore.MetricType.Group) {
|
|
16173
|
+
if (f.type === wodWikiCore.MetricType.Duration || f.type === wodWikiCore.MetricType.Rounds || f.type === wodWikiCore.MetricType.Resistance || f.type === wodWikiCore.MetricType.Distance || f.type === wodWikiCore.MetricType.Lap || f.type === wodWikiCore.MetricType.Group || f.type === wodWikiCore.MetricType.Equipment) {
|
|
14851
16174
|
return false;
|
|
14852
16175
|
}
|
|
14853
16176
|
const val = (f.image || f.value?.toString() || "").toUpperCase();
|
|
@@ -14967,6 +16290,7 @@ var AmrapLogicStrategy = class {
|
|
|
14967
16290
|
mode: "countdown",
|
|
14968
16291
|
label
|
|
14969
16292
|
}));
|
|
16293
|
+
builder.declareExit("immediate");
|
|
14970
16294
|
}
|
|
14971
16295
|
};
|
|
14972
16296
|
var IntervalLogicStrategy = class {
|
|
@@ -16282,7 +17606,9 @@ function readNextPreviewText(blocks) {
|
|
|
16282
17606
|
const merged = wodWikiCore.MetricContainer.empty(block.key.toString());
|
|
16283
17607
|
for (const loc of nextLocs) merged.merge(loc.metrics);
|
|
16284
17608
|
if (merged.length > 0) {
|
|
16285
|
-
return
|
|
17609
|
+
return dedupePresentedLabels(
|
|
17610
|
+
metricPresentation.presentGroup([...merged], "timer-subtitle").filter((t2) => t2.visible).map((t2) => t2.label)
|
|
17611
|
+
).join(" ").trim() || null;
|
|
16286
17612
|
}
|
|
16287
17613
|
}
|
|
16288
17614
|
return null;
|
|
@@ -16412,7 +17738,9 @@ function projectSessionClock(runtime, options = {}) {
|
|
|
16412
17738
|
let subLabels;
|
|
16413
17739
|
if (!isRestHero && leafEntry && leafEntry.displayRows.length > 1) {
|
|
16414
17740
|
const lines = leafEntry.displayRows.map(
|
|
16415
|
-
(row) =>
|
|
17741
|
+
(row) => dedupePresentedLabels(
|
|
17742
|
+
metricPresentation.presentGroup([...row], "timer-subtitle").filter((t2) => t2.visible).map((t2) => t2.label)
|
|
17743
|
+
).join(" ").trim()
|
|
16416
17744
|
).filter(Boolean);
|
|
16417
17745
|
if (lines.length > 0) subLabels = lines;
|
|
16418
17746
|
}
|
|
@@ -16602,14 +17930,7 @@ function formatStatementLabel(statement) {
|
|
|
16602
17930
|
[...statement.metrics].filter((m) => m.type !== wodWikiCore.MetricType.Hint),
|
|
16603
17931
|
"timer-subtitle"
|
|
16604
17932
|
).filter((t2) => t2.visible).map((t2) => t2.label.trim()).filter(Boolean);
|
|
16605
|
-
const
|
|
16606
|
-
for (const label of labels) {
|
|
16607
|
-
const lower = label.toLowerCase();
|
|
16608
|
-
const prev = deduped[deduped.length - 1]?.toLowerCase();
|
|
16609
|
-
if (prev && (prev === lower || prev.endsWith(` ${lower}`))) continue;
|
|
16610
|
-
deduped.push(label);
|
|
16611
|
-
}
|
|
16612
|
-
const presented = deduped.join(" ").trim();
|
|
17933
|
+
const presented = dedupePresentedLabels(labels).join(" ").trim();
|
|
16613
17934
|
return presented || statement.text?.trim() || "Step";
|
|
16614
17935
|
}
|
|
16615
17936
|
function synthesizeWorkoutFormat(script) {
|
|
@@ -17191,6 +18512,7 @@ exports.BlockBuilder = BlockBuilder;
|
|
|
17191
18512
|
exports.BlockContext = BlockContext;
|
|
17192
18513
|
exports.ButtonBehavior = ButtonBehavior;
|
|
17193
18514
|
exports.COMPLETION_PROPERTY_KEYS = COMPLETION_PROPERTY_KEYS;
|
|
18515
|
+
exports.COMPLETION_SECTIONS = COMPLETION_SECTIONS;
|
|
17194
18516
|
exports.CONSUMED_HINTS = CONSUMED_HINTS;
|
|
17195
18517
|
exports.CONSUMED_HINT_KEYS = CONSUMED_HINT_KEYS;
|
|
17196
18518
|
exports.CONTEXT_ATOMS = CONTEXT_ATOMS;
|
|
@@ -17347,6 +18669,7 @@ exports.composeMulUnit = composeMulUnit;
|
|
|
17347
18669
|
exports.compoundName = compoundName;
|
|
17348
18670
|
exports.computeColumnLabel = computeColumnLabel;
|
|
17349
18671
|
exports.computeLabel = computeLabel;
|
|
18672
|
+
exports.computeWhiteboardEnterAction = computeWhiteboardEnterAction;
|
|
17350
18673
|
exports.computeWorkloadRollups = computeWorkloadRollups;
|
|
17351
18674
|
exports.convertScalar = convertScalar;
|
|
17352
18675
|
exports.createAnalyticsEngineForBlock = createAnalyticsEngineForBlock;
|
|
@@ -17367,6 +18690,7 @@ exports.createRpeLabelsTable = createRpeLabelsTable;
|
|
|
17367
18690
|
exports.dailySessionLoads = dailySessionLoads;
|
|
17368
18691
|
exports.dayBucket = dayBucket;
|
|
17369
18692
|
exports.dedupeEntitiesByPrecedence = dedupeEntitiesByPrecedence;
|
|
18693
|
+
exports.dedupePresentedLabels = dedupePresentedLabels;
|
|
17370
18694
|
exports.dialectRegistry = dialectRegistry;
|
|
17371
18695
|
exports.dialectStack = dialectStack;
|
|
17372
18696
|
exports.diffStatement = diffStatement;
|
|
@@ -17434,6 +18758,7 @@ exports.isDimensionless = isDimensionless;
|
|
|
17434
18758
|
exports.isEffortDiscipline = isEffortDiscipline;
|
|
17435
18759
|
exports.isFragmentTag = isFragmentTag;
|
|
17436
18760
|
exports.isRequiredCountdownLocked = isRequiredCountdownLocked;
|
|
18761
|
+
exports.isRoundsHeaderLine = isRoundsHeaderLine;
|
|
17437
18762
|
exports.isTimeLikeMetric = isTimeLikeMetric;
|
|
17438
18763
|
exports.isWithinThreshold = isWithinThreshold;
|
|
17439
18764
|
exports.levenshteinDistance = levenshteinDistance;
|