@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.d.cts CHANGED
@@ -312,6 +312,7 @@ declare class UnitsDialect implements IDialect {
312
312
  declare class CrossFitDialect implements IDialect {
313
313
  id: string;
314
314
  name: string;
315
+ transform(statement: ICodeStatement): void;
315
316
  /**
316
317
  * Check if any Action or Effort metrics contains a keyword (case-insensitive)
317
318
  */
@@ -344,6 +345,7 @@ declare class CrossFitDialect implements IDialect {
344
345
  declare class WodDialect implements IDialect {
345
346
  id: string;
346
347
  name: string;
348
+ transform(statement: ICodeStatement): void;
347
349
  /** Case-insensitive keyword check on Action/Effort metrics */
348
350
  private hasKeyword;
349
351
  analyze(statement: ICodeStatement): DialectAnalysis;
@@ -592,6 +594,8 @@ interface RoundsPrimitive extends BasePrimitive {
592
594
  kind: 'rounds';
593
595
  sequence?: number[];
594
596
  label?: string;
597
+ sequenceMeta?: SyntaxMeta;
598
+ labelMeta?: SyntaxMeta;
595
599
  }
596
600
  /**
597
601
  * Inline NxM rounds scheme — `5x5` or `5 x 5` — lexed as one token so a bare
package/dist/index.d.ts CHANGED
@@ -312,6 +312,7 @@ declare class UnitsDialect implements IDialect {
312
312
  declare class CrossFitDialect implements IDialect {
313
313
  id: string;
314
314
  name: string;
315
+ transform(statement: ICodeStatement): void;
315
316
  /**
316
317
  * Check if any Action or Effort metrics contains a keyword (case-insensitive)
317
318
  */
@@ -344,6 +345,7 @@ declare class CrossFitDialect implements IDialect {
344
345
  declare class WodDialect implements IDialect {
345
346
  id: string;
346
347
  name: string;
348
+ transform(statement: ICodeStatement): void;
347
349
  /** Case-insensitive keyword check on Action/Effort metrics */
348
350
  private hasKeyword;
349
351
  analyze(statement: ICodeStatement): DialectAnalysis;
@@ -592,6 +594,8 @@ interface RoundsPrimitive extends BasePrimitive {
592
594
  kind: 'rounds';
593
595
  sequence?: number[];
594
596
  label?: string;
597
+ sequenceMeta?: SyntaxMeta;
598
+ labelMeta?: SyntaxMeta;
595
599
  }
596
600
  /**
597
601
  * Inline NxM rounds scheme — `5x5` or `5 x 5` — lexed as one token so a bare
package/dist/index.mjs CHANGED
@@ -439,9 +439,15 @@ var UnitsDialect = class {
439
439
  return {};
440
440
  }
441
441
  };
442
+ var CROSSFIT_UNITS = UnitRegistry.of([
443
+ { canonical: "pood", dimension: "mass", aliases: ["poods", "pd"] }
444
+ ]);
442
445
  var CrossFitDialect = class {
443
446
  id = "crossfit";
444
447
  name = "CrossFit Dialect";
448
+ transform(statement) {
449
+ fuseUnits(statement, CROSSFIT_UNITS);
450
+ }
445
451
  /**
446
452
  * Check if any Action or Effort metrics contains a keyword (case-insensitive)
447
453
  */
@@ -490,9 +496,15 @@ var CrossFitDialect = class {
490
496
  return { metrics: hintsToContainer(hints) };
491
497
  }
492
498
  };
499
+ var WOD_UNITS = UnitRegistry.of([
500
+ { canonical: "pood", dimension: "mass", aliases: ["poods", "pd"] }
501
+ ]);
493
502
  var WodDialect = class {
494
503
  id = "wod";
495
504
  name = "WOD Dialect";
505
+ transform(statement) {
506
+ fuseUnits(statement, WOD_UNITS);
507
+ }
496
508
  /** Case-insensitive keyword check on Action/Effort metrics */
497
509
  hasKeyword(metrics, keyword2) {
498
510
  return metrics.some(
@@ -1197,6 +1209,36 @@ var PROPERTY_KEY_TO_METRIC_TYPE = {
1197
1209
  };
1198
1210
  var STRUCTURAL_EFFORT_WORDS = /* @__PURE__ */ new Set(["rest", "amrap", "emom", "tabata", "for time"]);
1199
1211
  var STANDARD_UNITS2 = UnitRegistry.standard();
1212
+ var DIALECT_UNIT_WORDS = /* @__PURE__ */ new Set(["pood", "poods", "pd"]);
1213
+ var ROUNDS_LABEL_WORDS = /^(rounds?|rds?|sets?|laps?|cycles?|intervals?)$/i;
1214
+ var TIME_UNIT_SECONDS = {
1215
+ s: 1,
1216
+ sec: 1,
1217
+ secs: 1,
1218
+ second: 1,
1219
+ seconds: 1,
1220
+ min: 60,
1221
+ mins: 60,
1222
+ minute: 60,
1223
+ minutes: 60,
1224
+ hr: 3600,
1225
+ hrs: 3600,
1226
+ hour: 3600,
1227
+ hours: 3600
1228
+ };
1229
+ function formatSecondsAsTimer(totalSeconds) {
1230
+ const hours = Math.floor(totalSeconds / 3600);
1231
+ const minutes = Math.floor(totalSeconds % 3600 / 60);
1232
+ const seconds = totalSeconds % 60;
1233
+ const pad22 = (n) => String(n).padStart(2, "0");
1234
+ if (hours > 0) {
1235
+ return `${hours}:${pad22(minutes)}:${pad22(seconds)}`;
1236
+ }
1237
+ if (minutes > 0) {
1238
+ return `${minutes}:${pad22(seconds)}`;
1239
+ }
1240
+ return `:${pad22(seconds)}`;
1241
+ }
1200
1242
  var REFERENCE_PAIR_KEYS = /* @__PURE__ */ new Set(["effort", "equipment"]);
1201
1243
  function referenceMetadata(resolution) {
1202
1244
  return {
@@ -1339,7 +1381,7 @@ function applyReferenceResolution(pairs, fact, references) {
1339
1381
  if (metric.type === MetricType.Effort) {
1340
1382
  const authored = metric instanceof EffortMetric ? metric.effort : String(metric.value ?? "");
1341
1383
  const normalized = authored.trim().toLowerCase();
1342
- if (STRUCTURAL_EFFORT_WORDS.has(normalized) || STANDARD_UNITS2.has(normalized)) {
1384
+ if (STRUCTURAL_EFFORT_WORDS.has(normalized) || STANDARD_UNITS2.has(normalized) || DIALECT_UNIT_WORDS.has(normalized)) {
1343
1385
  result.push(pair);
1344
1386
  continue;
1345
1387
  }
@@ -1443,14 +1485,49 @@ function classifyPrimitive(primitive) {
1443
1485
  case "rounds": {
1444
1486
  if (primitive.sequence) {
1445
1487
  if (primitive.sequence.length === 1) {
1446
- return [{ metrics: new RoundsMetric(primitive.sequence[0]), meta: primitive.meta }];
1488
+ const amount = primitive.sequence[0];
1489
+ const trimmedLabel2 = primitive.label?.trim();
1490
+ if (!trimmedLabel2 || ROUNDS_LABEL_WORDS.test(trimmedLabel2)) {
1491
+ return [{ metrics: new RoundsMetric(amount), meta: primitive.meta }];
1492
+ }
1493
+ const lowerLabel2 = trimmedLabel2.toLowerCase();
1494
+ const unitSeconds = TIME_UNIT_SECONDS[lowerLabel2];
1495
+ if (unitSeconds !== void 0) {
1496
+ const totalSeconds = Math.max(0, Math.round(amount * unitSeconds));
1497
+ return [{ metrics: new DurationMetric(formatSecondsAsTimer(totalSeconds)), meta: primitive.meta }];
1498
+ }
1499
+ if (/^(reps?)$/i.test(trimmedLabel2)) {
1500
+ return [{ metrics: new RepMetric(amount), meta: primitive.meta }];
1501
+ }
1502
+ return [
1503
+ { metrics: new RepMetric(amount), meta: primitive.sequenceMeta ?? primitive.meta },
1504
+ { metrics: new EffortMetric(trimmedLabel2), meta: primitive.labelMeta ?? primitive.meta }
1505
+ ];
1447
1506
  }
1448
1507
  return [
1449
1508
  { metrics: new RoundsMetric(primitive.sequence.length), meta: primitive.meta },
1450
1509
  ...primitive.sequence.map((value) => ({ metrics: new RepMetric(value), meta: primitive.meta }))
1451
1510
  ];
1452
1511
  }
1453
- return primitive.label ? [{ metrics: new RoundsMetric(primitive.label), meta: primitive.meta }] : [];
1512
+ if (!primitive.label) {
1513
+ return [];
1514
+ }
1515
+ const trimmedLabel = primitive.label.trim();
1516
+ const lowerLabel = trimmedLabel.toLowerCase();
1517
+ if (/^(reps?)$/i.test(trimmedLabel)) {
1518
+ return [{ metrics: new RepMetric(void 0), meta: primitive.meta }];
1519
+ }
1520
+ const stdUnit = STANDARD_UNITS2.get(lowerLabel);
1521
+ if (stdUnit) {
1522
+ return [{ metrics: metricForDimension(void 0, trimmedLabel, stdUnit.dimension), meta: primitive.meta }];
1523
+ }
1524
+ if (DIALECT_UNIT_WORDS.has(lowerLabel)) {
1525
+ return [{ metrics: new ResistanceMetric(void 0, trimmedLabel), meta: primitive.meta }];
1526
+ }
1527
+ if (TIME_UNIT_SECONDS[lowerLabel] !== void 0) {
1528
+ return [{ metrics: new DurationMetric(":?"), meta: primitive.meta }];
1529
+ }
1530
+ return [{ metrics: new RoundsMetric(primitive.label), meta: primitive.meta }];
1454
1531
  }
1455
1532
  case "round_scheme": {
1456
1533
  return [
@@ -1846,13 +1923,17 @@ function mapFragmentToPrimitive(locator, source, node) {
1846
1923
  }
1847
1924
  case Rounds: {
1848
1925
  const sequence = node.getChild("Sequence");
1849
- const label = node.getChild("Identifier");
1926
+ const identifiers = node.getChildren("Identifier");
1927
+ const firstId = identifiers[0];
1928
+ const lastId = identifiers[identifiers.length - 1];
1850
1929
  const primitive = {
1851
1930
  kind: "rounds",
1852
1931
  raw,
1853
1932
  meta: meta2,
1854
- sequence: sequence ? source.slice(sequence.from, sequence.to).split("-").map((n) => parseInt(n.trim(), 10)) : void 0,
1855
- label: label ? source.slice(label.from, label.to) : void 0
1933
+ sequence: sequence ? source.slice(sequence.from, sequence.to).split("-").map((n) => Number(n.trim())) : void 0,
1934
+ label: identifiers.length > 0 ? identifiers.map((id) => source.slice(id.from, id.to)).join(" ") : void 0,
1935
+ sequenceMeta: sequence ? createMeta(locator, sequence.from, sequence.to, source.slice(sequence.from, sequence.to)) : void 0,
1936
+ labelMeta: firstId && lastId ? createMeta(locator, firstId.from, lastId.to, source.slice(firstId.from, lastId.to)) : void 0
1856
1937
  };
1857
1938
  return primitive;
1858
1939
  }