@ethlete/cdk 4.73.0 → 4.74.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @ethlete/cdk
2
2
 
3
+ ## 4.74.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`770e26b`](https://github.com/ethlete-io/ethdk/commit/770e26ba1cb2042a573e48cc529d8edf3e0e9dc0) Thanks [@TomTomB](https://github.com/TomTomB)! - New bracket: support a third place match in single elimination. The final stays the last match of the bracket, so the continue element is drawn again. A mirrored layout folds the third place match below the final, and the new `thirdPlaceTopOffset` input (also in `provideNewBracketConfig`) folds it below the final in a left to right layout. Semi final losers are no longer marked `isEliminated` when a third place match follows.
8
+
9
+ ### Patch Changes
10
+
11
+ - [`88a6896`](https://github.com/ethlete-io/ethdk/commit/88a6896692e166a9f4b0222346e29e33e2d76636) Thanks [@TomTomB](https://github.com/TomTomB)! - Place a third place match that keeps its own column after the continue element, so the line from the final to the continue element no longer crosses it.
12
+
3
13
  ## 4.73.0
4
14
 
5
15
  ### Minor Changes
@@ -1602,6 +1602,12 @@ const createRoundsMapBase = (source, options) => {
1602
1602
  }
1603
1603
  return map;
1604
1604
  };
1605
+ const thirdPlaceFeederRoundId = (source) => {
1606
+ if (!source.rounds.some((round) => round.type === COMMON_BRACKET_ROUND_TYPE.THIRD_PLACE)) return null;
1607
+ const chain = source.rounds.filter((round) => round.type !== COMMON_BRACKET_ROUND_TYPE.THIRD_PLACE);
1608
+ const finalIndex = chain.findIndex((round) => round.type === COMMON_BRACKET_ROUND_TYPE.FINAL);
1609
+ return finalIndex > 0 ? chain[finalIndex - 1]?.id ?? null : null;
1610
+ };
1605
1611
  const createNewMatchParticipantBase = (source, participantId, match, rounds, matchRoundId, participants) => {
1606
1612
  if (!participantId) return null;
1607
1613
  const participantBase = participants.getOrThrow(participantId);
@@ -1632,8 +1638,8 @@ const createNewMatchParticipantBase = (source, participantId, match, rounds, mat
1632
1638
  let isEliminationMatch = false;
1633
1639
  if (hasElimination) switch (source.mode) {
1634
1640
  case TOURNAMENT_MODE.SINGLE_ELIMINATION:
1635
- isEliminationMatch = true;
1636
- isEliminated = isLooser ?? false;
1641
+ isEliminationMatch = match.roundId !== thirdPlaceFeederRoundId(source);
1642
+ isEliminated = (isEliminationMatch && isLooser) ?? false;
1637
1643
  break;
1638
1644
  case TOURNAMENT_MODE.DOUBLE_ELIMINATION:
1639
1645
  isEliminationMatch = roundBase.type === DOUBLE_ELIMINATION_BRACKET_ROUND_TYPE.LOWER_BRACKET || roundBase.type === DOUBLE_ELIMINATION_BRACKET_ROUND_TYPE.REVERSE_FINAL || roundBase.type === COMMON_BRACKET_ROUND_TYPE.THIRD_PLACE;
@@ -2207,7 +2213,7 @@ const handleRegularRound = (params) => {
2207
2213
  };
2208
2214
  const generateRoundRelationsNew = (bracketData) => {
2209
2215
  const relations = [];
2210
- const allRounds = [...bracketData.rounds.values()];
2216
+ const allRounds = [...bracketData.rounds.values()].filter((r) => r.type !== COMMON_BRACKET_ROUND_TYPE.THIRD_PLACE);
2211
2217
  const upperRounds = allRounds.filter((r) => r.type !== DOUBLE_ELIMINATION_BRACKET_ROUND_TYPE.LOWER_BRACKET);
2212
2218
  const lowerRounds = allRounds.filter((r) => r.type === DOUBLE_ELIMINATION_BRACKET_ROUND_TYPE.LOWER_BRACKET);
2213
2219
  const firstUpperRound = upperRounds[0];
@@ -3271,9 +3277,14 @@ const createBracketContinueMasterColumn = (config) => {
3271
3277
  const { existingMasterColumns, columnWidth, elementHeight, headerOffset, component, matches } = config;
3272
3278
  const lastMasterColumn = existingMasterColumns[existingMasterColumns.length - 1];
3273
3279
  if (!lastMasterColumn) throw new Error("No last master column found in existing master columns");
3274
- const totalHeight = lastMasterColumn.sections.reduce((height, section) => {
3275
- return height + Math.max(0, ...section.subColumns.map((subColumn) => subColumn.elements.reduce((subColumnHeight, element) => subColumnHeight + element.parts.reduce((sum, part) => sum + part.dimensions.height, 0), 0)));
3276
- }, 0);
3280
+ const firstSectionIsHeader = lastMasterColumn.sections[0]?.subColumns[0]?.elements[0]?.type === "header";
3281
+ let totalHeight = 0;
3282
+ for (const [sectionIndex, section] of lastMasterColumn.sections.entries()) {
3283
+ const padding = section.padding ?? lastMasterColumn.padding;
3284
+ const paddingTop = sectionIndex === 0 && firstSectionIsHeader ? 0 : padding.top;
3285
+ const sectionHeight = Math.max(0, ...section.subColumns.map((subColumn) => subColumn.elements.reduce((subColumnHeight, element) => subColumnHeight + element.parts.reduce((sum, part) => sum + part.dimensions.height, 0), 0)));
3286
+ totalHeight += paddingTop + sectionHeight + padding.bottom;
3287
+ }
3277
3288
  const { masterColumn, pushSection } = createBracketMasterColumn({
3278
3289
  columnWidth,
3279
3290
  padding: {
@@ -3311,6 +3322,100 @@ const createBracketContinueMasterColumn = (config) => {
3311
3322
  pushSection(masterColumnSection);
3312
3323
  return masterColumn;
3313
3324
  };
3325
+ const createRoundBracketSubColumnRelativeToFirstRound = (config) => {
3326
+ const { firstRound, round, options, span, hasReverseFinal } = config;
3327
+ const { subColumn, pushElement } = createBracketSubColumn({ span });
3328
+ const matchFactor = firstRound.matchCount / round.matchCount;
3329
+ const matches = Array.from(round.matches.values());
3330
+ const elementsToCreate = [];
3331
+ if (options.roundHeaderHeight > 0) elementsToCreate.push({
3332
+ type: "header",
3333
+ area: `h${round.shortId}`,
3334
+ partHeights: [options.roundHeaderHeight],
3335
+ elementHeight: options.roundHeaderHeight,
3336
+ component: config.components.roundHeader,
3337
+ round,
3338
+ roundSwissGroup: null
3339
+ }, {
3340
+ type: "roundHeaderGap",
3341
+ area: ".",
3342
+ partHeights: [options.roundHeaderGap],
3343
+ elementHeight: options.roundHeaderGap
3344
+ });
3345
+ for (const [matchIndex, match] of matches.entries()) {
3346
+ const isLastMatch = matchIndex === matches.length - 1;
3347
+ const matchRows = [];
3348
+ for (let factorIndex = 0; factorIndex < matchFactor; factorIndex++) {
3349
+ const isLastFactor = factorIndex === matchFactor - 1;
3350
+ matchRows.push(options.matchHeight);
3351
+ if (isLastFactor) continue;
3352
+ matchRows.push(options.rowGap);
3353
+ }
3354
+ const isFinalMatch = hasReverseFinal ? round.type === DOUBLE_ELIMINATION_BRACKET_ROUND_TYPE.REVERSE_FINAL : round.type === COMMON_BRACKET_ROUND_TYPE.FINAL;
3355
+ elementsToCreate.push({
3356
+ type: "match",
3357
+ area: `m${match.shortId}`,
3358
+ partHeights: matchRows,
3359
+ elementHeight: isFinalMatch ? options.finalMatchHeight : options.matchHeight,
3360
+ component: isFinalMatch ? config.components.finalMatch : config.components.match,
3361
+ match,
3362
+ round,
3363
+ roundSwissGroup: null
3364
+ });
3365
+ if (!isLastMatch) elementsToCreate.push({
3366
+ type: "matchGap",
3367
+ area: ".",
3368
+ partHeights: [options.rowGap],
3369
+ elementHeight: options.rowGap
3370
+ });
3371
+ }
3372
+ for (const elementData of elementsToCreate) {
3373
+ const { element } = createBracketElement(elementData);
3374
+ pushElement(element);
3375
+ }
3376
+ return subColumn;
3377
+ };
3378
+ const heightOfElement = (element) => element.parts.reduce((total, part) => total + part.dimensions.height, 0);
3379
+ const cardGeometry = (subColumn) => {
3380
+ let height = 0;
3381
+ let cardTop = null;
3382
+ for (const element of subColumn.elements) {
3383
+ const elementHeight = heightOfElement(element);
3384
+ if (element.type === "match" && cardTop === null) cardTop = height + (elementHeight - element.dimensions.height) / 2;
3385
+ height += elementHeight;
3386
+ }
3387
+ return {
3388
+ cardTop: cardTop ?? 0,
3389
+ height
3390
+ };
3391
+ };
3392
+ const createFoldedThirdPlaceSection = (config) => {
3393
+ const { options, round } = config;
3394
+ const final = cardGeometry(config.finalSubColumn);
3395
+ const headerOffset = options.roundHeaderHeight > 0 ? options.roundHeaderHeight + options.roundHeaderGap : 0;
3396
+ const paddingTop = final.cardTop + config.topOffset - final.height - headerOffset;
3397
+ const { masterColumnSection, pushSubColumn } = createBracketMasterColumnSection({
3398
+ type: "round",
3399
+ padding: {
3400
+ top: paddingTop,
3401
+ bottom: 0,
3402
+ left: 0,
3403
+ right: 0
3404
+ }
3405
+ });
3406
+ pushSubColumn(createRoundBracketSubColumnRelativeToFirstRound({
3407
+ firstRound: round,
3408
+ round,
3409
+ options,
3410
+ hasReverseFinal: false,
3411
+ span: {
3412
+ isStart: true,
3413
+ isEnd: true
3414
+ },
3415
+ components: config.components
3416
+ }));
3417
+ return masterColumnSection;
3418
+ };
3314
3419
  const createBracketGapMasterColumn = (config) => {
3315
3420
  const { existingMasterColumns, columnGap } = config;
3316
3421
  const lastMasterColumn = existingMasterColumns[existingMasterColumns.length - 1];
@@ -3325,7 +3430,14 @@ const createBracketGapMasterColumn = (config) => {
3325
3430
  }
3326
3431
  });
3327
3432
  for (const section of lastMasterColumn.sections) {
3328
- const { masterColumnSection, pushSubColumn } = createBracketMasterColumnSection({ type: "gap" });
3433
+ const { masterColumnSection, pushSubColumn } = createBracketMasterColumnSection({
3434
+ type: "gap",
3435
+ padding: section.padding && {
3436
+ ...section.padding,
3437
+ left: 0,
3438
+ right: 0
3439
+ }
3440
+ });
3329
3441
  const lastSubColumn = section.subColumns[section.subColumns.length - 1];
3330
3442
  if (!lastSubColumn) throw new Error("No last sub column found in section");
3331
3443
  const { pushElement, subColumn } = createBracketSubColumn({ span: {
@@ -3383,59 +3495,6 @@ const createBracketGapMasterColumn = (config) => {
3383
3495
  }
3384
3496
  return masterColumn;
3385
3497
  };
3386
- const createRoundBracketSubColumnRelativeToFirstRound = (config) => {
3387
- const { firstRound, round, options, span, hasReverseFinal } = config;
3388
- const { subColumn, pushElement } = createBracketSubColumn({ span });
3389
- const matchFactor = firstRound.matchCount / round.matchCount;
3390
- const matches = Array.from(round.matches.values());
3391
- const elementsToCreate = [];
3392
- if (options.roundHeaderHeight > 0) elementsToCreate.push({
3393
- type: "header",
3394
- area: `h${round.shortId}`,
3395
- partHeights: [options.roundHeaderHeight],
3396
- elementHeight: options.roundHeaderHeight,
3397
- component: config.components.roundHeader,
3398
- round,
3399
- roundSwissGroup: null
3400
- }, {
3401
- type: "roundHeaderGap",
3402
- area: ".",
3403
- partHeights: [options.roundHeaderGap],
3404
- elementHeight: options.roundHeaderGap
3405
- });
3406
- for (const [matchIndex, match] of matches.entries()) {
3407
- const isLastMatch = matchIndex === matches.length - 1;
3408
- const matchRows = [];
3409
- for (let factorIndex = 0; factorIndex < matchFactor; factorIndex++) {
3410
- const isLastFactor = factorIndex === matchFactor - 1;
3411
- matchRows.push(options.matchHeight);
3412
- if (isLastFactor) continue;
3413
- matchRows.push(options.rowGap);
3414
- }
3415
- const isFinalMatch = hasReverseFinal ? round.type === DOUBLE_ELIMINATION_BRACKET_ROUND_TYPE.REVERSE_FINAL : round.type === COMMON_BRACKET_ROUND_TYPE.FINAL;
3416
- elementsToCreate.push({
3417
- type: "match",
3418
- area: `m${match.shortId}`,
3419
- partHeights: matchRows,
3420
- elementHeight: isFinalMatch ? options.finalMatchHeight : options.matchHeight,
3421
- component: isFinalMatch ? config.components.finalMatch : config.components.match,
3422
- match,
3423
- round,
3424
- roundSwissGroup: null
3425
- });
3426
- if (!isLastMatch) elementsToCreate.push({
3427
- type: "matchGap",
3428
- area: ".",
3429
- partHeights: [options.rowGap],
3430
- elementHeight: options.rowGap
3431
- });
3432
- }
3433
- for (const elementData of elementsToCreate) {
3434
- const { element } = createBracketElement(elementData);
3435
- pushElement(element);
3436
- }
3437
- return subColumn;
3438
- };
3439
3498
  const createDoubleEliminationGrid = (bracketData, options, components) => {
3440
3499
  const grid = createBracketGrid({ spanElementWidth: options.columnWidth });
3441
3500
  const presentUpperBracketRounds = Array.from(bracketData.roundsByType.getOrThrow(DOUBLE_ELIMINATION_BRACKET_ROUND_TYPE.UPPER_BRACKET).values());
@@ -3649,13 +3708,33 @@ const createDoubleEliminationGrid = (bracketData, options, components) => {
3649
3708
  matchElementMap: finalizedGrid.elementMap
3650
3709
  };
3651
3710
  };
3711
+ const resolveThirdPlaceTopOffset = (options) => {
3712
+ if (options.thirdPlaceTopOffset !== null && options.thirdPlaceTopOffset !== void 0) return options.thirdPlaceTopOffset;
3713
+ if (options.layout !== BRACKET_DATA_LAYOUT.MIRRORED) return null;
3714
+ const headerOffset = options.roundHeaderHeight > 0 ? options.roundHeaderHeight + options.roundHeaderGap : 0;
3715
+ return options.finalMatchHeight + options.rowGap + headerOffset;
3716
+ };
3717
+ const resolveFoldedThirdPlaceRound = (rounds, topOffset) => {
3718
+ if (topOffset === null) return null;
3719
+ if (!rounds.some((round) => round.type === COMMON_BRACKET_ROUND_TYPE.FINAL)) return null;
3720
+ return rounds.find((round) => round.type === COMMON_BRACKET_ROUND_TYPE.THIRD_PLACE) ?? null;
3721
+ };
3652
3722
  const createSingleEliminationGrid = (bracketData, options, components) => {
3653
3723
  const grid = createBracketGrid({ spanElementWidth: options.columnWidth });
3654
3724
  const rounds = Array.from(bracketData.rounds.values());
3655
3725
  const firstRound = bracketData.rounds.first();
3656
3726
  if (!firstRound) throw new Error("No rounds found in bracket data");
3657
- for (const [roundIndex, round] of rounds.entries()) {
3658
- const isLastRound = roundIndex === rounds.length - 1;
3727
+ const thirdPlaceTopOffset = resolveThirdPlaceTopOffset(options);
3728
+ const foldedThirdPlaceRound = resolveFoldedThirdPlaceRound(rounds, thirdPlaceTopOffset);
3729
+ const ownColumnThirdPlaceRound = foldedThirdPlaceRound ? null : rounds.find((round) => round.type === COMMON_BRACKET_ROUND_TYPE.THIRD_PLACE) ?? null;
3730
+ const chainRounds = rounds.filter((round) => round !== foldedThirdPlaceRound && round !== ownColumnThirdPlaceRound);
3731
+ let pushSectionToFinal = null;
3732
+ let finalSubColumn = null;
3733
+ const pushGapColumn = () => grid.pushMasterColumn(createBracketGapMasterColumn({
3734
+ existingMasterColumns: grid.grid.masterColumns,
3735
+ columnGap: options.columnGap
3736
+ }));
3737
+ const pushRoundColumn = (round) => {
3659
3738
  const { masterColumn, ...mutableMasterColumn } = createBracketMasterColumn({
3660
3739
  columnWidth: round.type === COMMON_BRACKET_ROUND_TYPE.FINAL ? options.finalColumnWidth : options.columnWidth,
3661
3740
  padding: {
@@ -3666,7 +3745,7 @@ const createSingleEliminationGrid = (bracketData, options, components) => {
3666
3745
  }
3667
3746
  });
3668
3747
  const { masterColumnSection, pushSubColumn } = createBracketMasterColumnSection({ type: "round" });
3669
- pushSubColumn(createRoundBracketSubColumnRelativeToFirstRound({
3748
+ const sub = createRoundBracketSubColumnRelativeToFirstRound({
3670
3749
  firstRound,
3671
3750
  round,
3672
3751
  options,
@@ -3676,14 +3755,30 @@ const createSingleEliminationGrid = (bracketData, options, components) => {
3676
3755
  isEnd: true
3677
3756
  },
3678
3757
  components
3679
- }));
3758
+ });
3759
+ pushSubColumn(sub);
3680
3760
  mutableMasterColumn.pushSection(masterColumnSection);
3681
3761
  grid.pushMasterColumn(masterColumn);
3682
- if (!isLastRound) grid.pushMasterColumn(createBracketGapMasterColumn({
3683
- existingMasterColumns: grid.grid.masterColumns,
3684
- columnGap: options.columnGap
3685
- }));
3762
+ return {
3763
+ pushSection: mutableMasterColumn.pushSection,
3764
+ sub
3765
+ };
3766
+ };
3767
+ for (const [roundIndex, round] of chainRounds.entries()) {
3768
+ if (roundIndex > 0) pushGapColumn();
3769
+ const { pushSection, sub } = pushRoundColumn(round);
3770
+ if (round.type === COMMON_BRACKET_ROUND_TYPE.FINAL) {
3771
+ pushSectionToFinal = pushSection;
3772
+ finalSubColumn = sub;
3773
+ }
3686
3774
  }
3775
+ if (foldedThirdPlaceRound && pushSectionToFinal && finalSubColumn) pushSectionToFinal(createFoldedThirdPlaceSection({
3776
+ finalSubColumn,
3777
+ round: foldedThirdPlaceRound,
3778
+ topOffset: thirdPlaceTopOffset ?? 0,
3779
+ options,
3780
+ components
3781
+ }));
3687
3782
  if (options.continueElement && components.continue) {
3688
3783
  const continueMatches = getBracketContinueMatches(bracketData);
3689
3784
  if (continueMatches.length) {
@@ -3701,6 +3796,10 @@ const createSingleEliminationGrid = (bracketData, options, components) => {
3701
3796
  }));
3702
3797
  }
3703
3798
  }
3799
+ if (ownColumnThirdPlaceRound) {
3800
+ if (chainRounds.length) pushGapColumn();
3801
+ pushRoundColumn(ownColumnThirdPlaceRound);
3802
+ }
3704
3803
  grid.calculateDimensions();
3705
3804
  const finalizedGrid = finalizeBracketGrid(grid);
3706
3805
  return {
@@ -4182,6 +4281,10 @@ var NewBracketComponent = class NewBracketComponent {
4182
4281
  ...ngDevMode ? { debugName: "rowRoundGap" } : /* istanbul ignore next */ {},
4183
4282
  transform: numberAttribute
4184
4283
  });
4284
+ this.thirdPlaceTopOffset = input(this.config.thirdPlaceTopOffset ?? null, {
4285
+ ...ngDevMode ? { debugName: "thirdPlaceTopOffset" } : /* istanbul ignore next */ {},
4286
+ transform: (value) => value === null || value === void 0 || value === "" ? null : numberAttribute(value)
4287
+ });
4185
4288
  this.lineStartingCurveAmount = input(this.config.lineStartingCurveAmount ?? 10, {
4186
4289
  ...ngDevMode ? { debugName: "lineStartingCurveAmount" } : /* istanbul ignore next */ {},
4187
4290
  transform: numberAttribute
@@ -4255,6 +4358,7 @@ var NewBracketComponent = class NewBracketComponent {
4255
4358
  layout: this.layout(),
4256
4359
  finalMatchHeight: this.finalMatchHeight(),
4257
4360
  finalColumnWidth: this.finalColumnWidth(),
4361
+ thirdPlaceTopOffset: this.thirdPlaceTopOffset(),
4258
4362
  roundHeaderGap: this.hideRoundHeaders() ? 0 : this.roundHeaderGap(),
4259
4363
  swissGroupPadding: this.swissGroupPadding(),
4260
4364
  swissGroupBorderWidth: this.lineWidth(),
@@ -4420,6 +4524,13 @@ var NewBracketComponent = class NewBracketComponent {
4420
4524
  isRequired: false,
4421
4525
  transformFunction: null
4422
4526
  },
4527
+ thirdPlaceTopOffset: {
4528
+ classPropertyName: "thirdPlaceTopOffset",
4529
+ publicName: "thirdPlaceTopOffset",
4530
+ isSignal: true,
4531
+ isRequired: false,
4532
+ transformFunction: null
4533
+ },
4423
4534
  lineStartingCurveAmount: {
4424
4535
  classPropertyName: "lineStartingCurveAmount",
4425
4536
  publicName: "lineStartingCurveAmount",
@@ -4676,6 +4787,14 @@ i0.ɵɵngDeclareClassMetadata({
4676
4787
  required: false
4677
4788
  }]
4678
4789
  }],
4790
+ thirdPlaceTopOffset: [{
4791
+ type: i0.Input,
4792
+ args: [{
4793
+ isSignal: true,
4794
+ alias: "thirdPlaceTopOffset",
4795
+ required: false
4796
+ }]
4797
+ }],
4679
4798
  lineStartingCurveAmount: [{
4680
4799
  type: i0.Input,
4681
4800
  args: [{