@bitcobblers/wod-wiki-lang 0.55.2206 → 0.56.2208

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -991,9 +991,15 @@ var UnitsDialect = class {
991
991
  return {};
992
992
  }
993
993
  };
994
+ var CROSSFIT_UNITS = UnitRegistry.of([
995
+ { canonical: "pood", dimension: "mass", aliases: ["poods", "pd"] }
996
+ ]);
994
997
  var CrossFitDialect = class {
995
998
  id = "crossfit";
996
999
  name = "CrossFit Dialect";
1000
+ transform(statement) {
1001
+ fuseUnits(statement, CROSSFIT_UNITS);
1002
+ }
997
1003
  /**
998
1004
  * Check if any Action or Effort metrics contains a keyword (case-insensitive)
999
1005
  */
@@ -1042,9 +1048,15 @@ var CrossFitDialect = class {
1042
1048
  return { metrics: hintsToContainer(hints) };
1043
1049
  }
1044
1050
  };
1051
+ var WOD_UNITS = UnitRegistry.of([
1052
+ { canonical: "pood", dimension: "mass", aliases: ["poods", "pd"] }
1053
+ ]);
1045
1054
  var WodDialect = class {
1046
1055
  id = "wod";
1047
1056
  name = "WOD Dialect";
1057
+ transform(statement) {
1058
+ fuseUnits(statement, WOD_UNITS);
1059
+ }
1048
1060
  /** Case-insensitive keyword check on Action/Effort metrics */
1049
1061
  hasKeyword(metrics, keyword2) {
1050
1062
  return metrics.some(
@@ -1749,6 +1761,36 @@ var PROPERTY_KEY_TO_METRIC_TYPE = {
1749
1761
  };
1750
1762
  var STRUCTURAL_EFFORT_WORDS = /* @__PURE__ */ new Set(["rest", "amrap", "emom", "tabata", "for time"]);
1751
1763
  var STANDARD_UNITS2 = UnitRegistry.standard();
1764
+ var DIALECT_UNIT_WORDS = /* @__PURE__ */ new Set(["pood", "poods", "pd"]);
1765
+ var ROUNDS_LABEL_WORDS = /^(rounds?|rds?|sets?|laps?|cycles?|intervals?)$/i;
1766
+ var TIME_UNIT_SECONDS = {
1767
+ s: 1,
1768
+ sec: 1,
1769
+ secs: 1,
1770
+ second: 1,
1771
+ seconds: 1,
1772
+ min: 60,
1773
+ mins: 60,
1774
+ minute: 60,
1775
+ minutes: 60,
1776
+ hr: 3600,
1777
+ hrs: 3600,
1778
+ hour: 3600,
1779
+ hours: 3600
1780
+ };
1781
+ function formatSecondsAsTimer(totalSeconds) {
1782
+ const hours = Math.floor(totalSeconds / 3600);
1783
+ const minutes = Math.floor(totalSeconds % 3600 / 60);
1784
+ const seconds = totalSeconds % 60;
1785
+ const pad22 = (n) => String(n).padStart(2, "0");
1786
+ if (hours > 0) {
1787
+ return `${hours}:${pad22(minutes)}:${pad22(seconds)}`;
1788
+ }
1789
+ if (minutes > 0) {
1790
+ return `${minutes}:${pad22(seconds)}`;
1791
+ }
1792
+ return `:${pad22(seconds)}`;
1793
+ }
1752
1794
  var REFERENCE_PAIR_KEYS = /* @__PURE__ */ new Set(["effort", "equipment"]);
1753
1795
  function referenceMetadata(resolution) {
1754
1796
  return {
@@ -1891,7 +1933,7 @@ function applyReferenceResolution(pairs, fact, references) {
1891
1933
  if (metric.type === wodWikiCore.MetricType.Effort) {
1892
1934
  const authored = metric instanceof EffortMetric ? metric.effort : String(metric.value ?? "");
1893
1935
  const normalized = authored.trim().toLowerCase();
1894
- if (STRUCTURAL_EFFORT_WORDS.has(normalized) || STANDARD_UNITS2.has(normalized)) {
1936
+ if (STRUCTURAL_EFFORT_WORDS.has(normalized) || STANDARD_UNITS2.has(normalized) || DIALECT_UNIT_WORDS.has(normalized)) {
1895
1937
  result.push(pair);
1896
1938
  continue;
1897
1939
  }
@@ -1995,14 +2037,49 @@ function classifyPrimitive(primitive) {
1995
2037
  case "rounds": {
1996
2038
  if (primitive.sequence) {
1997
2039
  if (primitive.sequence.length === 1) {
1998
- return [{ metrics: new RoundsMetric(primitive.sequence[0]), meta: primitive.meta }];
2040
+ const amount = primitive.sequence[0];
2041
+ const trimmedLabel2 = primitive.label?.trim();
2042
+ if (!trimmedLabel2 || ROUNDS_LABEL_WORDS.test(trimmedLabel2)) {
2043
+ return [{ metrics: new RoundsMetric(amount), meta: primitive.meta }];
2044
+ }
2045
+ const lowerLabel2 = trimmedLabel2.toLowerCase();
2046
+ const unitSeconds = TIME_UNIT_SECONDS[lowerLabel2];
2047
+ if (unitSeconds !== void 0) {
2048
+ const totalSeconds = Math.max(0, Math.round(amount * unitSeconds));
2049
+ return [{ metrics: new DurationMetric(formatSecondsAsTimer(totalSeconds)), meta: primitive.meta }];
2050
+ }
2051
+ if (/^(reps?)$/i.test(trimmedLabel2)) {
2052
+ return [{ metrics: new RepMetric(amount), meta: primitive.meta }];
2053
+ }
2054
+ return [
2055
+ { metrics: new RepMetric(amount), meta: primitive.sequenceMeta ?? primitive.meta },
2056
+ { metrics: new EffortMetric(trimmedLabel2), meta: primitive.labelMeta ?? primitive.meta }
2057
+ ];
1999
2058
  }
2000
2059
  return [
2001
2060
  { metrics: new RoundsMetric(primitive.sequence.length), meta: primitive.meta },
2002
2061
  ...primitive.sequence.map((value) => ({ metrics: new RepMetric(value), meta: primitive.meta }))
2003
2062
  ];
2004
2063
  }
2005
- return primitive.label ? [{ metrics: new RoundsMetric(primitive.label), meta: primitive.meta }] : [];
2064
+ if (!primitive.label) {
2065
+ return [];
2066
+ }
2067
+ const trimmedLabel = primitive.label.trim();
2068
+ const lowerLabel = trimmedLabel.toLowerCase();
2069
+ if (/^(reps?)$/i.test(trimmedLabel)) {
2070
+ return [{ metrics: new RepMetric(void 0), meta: primitive.meta }];
2071
+ }
2072
+ const stdUnit = STANDARD_UNITS2.get(lowerLabel);
2073
+ if (stdUnit) {
2074
+ return [{ metrics: metricForDimension(void 0, trimmedLabel, stdUnit.dimension), meta: primitive.meta }];
2075
+ }
2076
+ if (DIALECT_UNIT_WORDS.has(lowerLabel)) {
2077
+ return [{ metrics: new ResistanceMetric(void 0, trimmedLabel), meta: primitive.meta }];
2078
+ }
2079
+ if (TIME_UNIT_SECONDS[lowerLabel] !== void 0) {
2080
+ return [{ metrics: new DurationMetric(":?"), meta: primitive.meta }];
2081
+ }
2082
+ return [{ metrics: new RoundsMetric(primitive.label), meta: primitive.meta }];
2006
2083
  }
2007
2084
  case "round_scheme": {
2008
2085
  return [
@@ -2398,13 +2475,17 @@ function mapFragmentToPrimitive(locator, source, node) {
2398
2475
  }
2399
2476
  case Rounds: {
2400
2477
  const sequence = node.getChild("Sequence");
2401
- const label = node.getChild("Identifier");
2478
+ const identifiers = node.getChildren("Identifier");
2479
+ const firstId = identifiers[0];
2480
+ const lastId = identifiers[identifiers.length - 1];
2402
2481
  const primitive = {
2403
2482
  kind: "rounds",
2404
2483
  raw,
2405
2484
  meta: meta2,
2406
- sequence: sequence ? source.slice(sequence.from, sequence.to).split("-").map((n) => parseInt(n.trim(), 10)) : void 0,
2407
- label: label ? source.slice(label.from, label.to) : void 0
2485
+ sequence: sequence ? source.slice(sequence.from, sequence.to).split("-").map((n) => Number(n.trim())) : void 0,
2486
+ label: identifiers.length > 0 ? identifiers.map((id) => source.slice(id.from, id.to)).join(" ") : void 0,
2487
+ sequenceMeta: sequence ? createMeta(locator, sequence.from, sequence.to, source.slice(sequence.from, sequence.to)) : void 0,
2488
+ labelMeta: firstId && lastId ? createMeta(locator, firstId.from, lastId.to, source.slice(firstId.from, lastId.to)) : void 0
2408
2489
  };
2409
2490
  return primitive;
2410
2491
  }