@ethlete/components 1.0.0-next.108 → 1.0.0-next.110

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,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.0-next.110
4
+
5
+ ### Minor Changes
6
+
7
+ - Remove `--et-scrollable-buttons-end-space`: the inside scroll buttons lie over the items and hide at start and end. Run the `scrollable-end-space` migration of `et update`.
8
+ - `etScrollableButtons` takes `position: 'corner'`: both buttons sit as one group in the block-end/inline-end corner over the track, also `sticky`. Set `padding` and `gap` on `.et-scrollable-buttons` to move and space the group.
9
+
10
+ ## 1.0.0-next.109
11
+
12
+ ### Minor Changes
13
+
14
+ - Add the `'swiss'` tournament mode for swiss stages that eliminate nobody; `swissBracketLayout()` draws it.
15
+
3
16
  ## 1.0.0-next.108
4
17
 
5
18
  ### Minor Changes
@@ -46,8 +46,10 @@ const BRACKET_DATA_LAYOUT = {
46
46
  const TOURNAMENT_MODE = {
47
47
  SINGLE_ELIMINATION: "single-elimination",
48
48
  DOUBLE_ELIMINATION: "double-elimination",
49
- SWISS_WITH_ELIMINATION: "swiss-with-elimination"
49
+ SWISS_WITH_ELIMINATION: "swiss-with-elimination",
50
+ SWISS: "swiss"
50
51
  };
52
+ const isSwissMode = (mode) => mode === TOURNAMENT_MODE.SWISS_WITH_ELIMINATION || mode === TOURNAMENT_MODE.SWISS;
51
53
  const SWISS_ADVANCE_WINS = 3;
52
54
  const SWISS_ELIMINATE_LOSSES = 3;
53
55
  const BRACKET_ROUND_MIRROR_TYPE = {
@@ -987,119 +989,6 @@ const drawMan = (dimensions) => {
987
989
  gradients: []
988
990
  };
989
991
  };
990
- const BRACKET_SWISS_GROUP_COLOR_TYPE = {
991
- NEUTRAL: "neutral",
992
- POSITIVE: "positive",
993
- NEGATIVE: "negative",
994
- WARNING: "warning"
995
- };
996
- const getSwissGroupColorType = (wins, losses) => {
997
- if (wins === 0 && losses === 0) return BRACKET_SWISS_GROUP_COLOR_TYPE.NEUTRAL;
998
- if (losses === 2) return BRACKET_SWISS_GROUP_COLOR_TYPE.NEGATIVE;
999
- if (wins > losses) return BRACKET_SWISS_GROUP_COLOR_TYPE.POSITIVE;
1000
- return BRACKET_SWISS_GROUP_COLOR_TYPE.WARNING;
1001
- };
1002
- const factorialCache = /* @__PURE__ */ new Map();
1003
- const getAvailableSwissGroupsForRound = (roundNumber, totalMatchesInRound) => {
1004
- const advanceWins = 3;
1005
- const eliminateLosses = 3;
1006
- const getFactorial = (n) => {
1007
- if (n <= 1) return 1;
1008
- if (factorialCache.has(n)) return factorialCache.get(n);
1009
- const result = n * getFactorial(n - 1);
1010
- factorialCache.set(n, result);
1011
- return result;
1012
- };
1013
- const roundFactorial = getFactorial(roundNumber);
1014
- let totalCombinations = 0;
1015
- const validGroups = [];
1016
- for (let wins = roundNumber; wins >= 0; wins--) {
1017
- const losses = roundNumber - wins;
1018
- const remainingGames = 6 - (wins + losses) - 1;
1019
- if (!(wins < advanceWins && remainingGames >= 0) || !(losses < eliminateLosses)) continue;
1020
- const combinations = roundFactorial / (getFactorial(wins) * getFactorial(losses));
1021
- totalCombinations += combinations;
1022
- validGroups.push({
1023
- wins,
1024
- losses,
1025
- combinations
1026
- });
1027
- }
1028
- return validGroups.map(({ wins, losses, combinations }) => ({
1029
- id: `${wins}-${losses}`,
1030
- name: `${wins}-${losses}`,
1031
- matchesInGroup: Math.round(combinations / totalCombinations * totalMatchesInRound)
1032
- }));
1033
- };
1034
- const UNDRAWN_SWISS_GROUP_ID = "undrawn";
1035
- const getRecordBeforeMatch = (participant) => ({
1036
- wins: participant.winCount - (participant.result === "win" ? 1 : 0),
1037
- losses: participant.lossCount - (participant.result === "loss" ? 1 : 0)
1038
- });
1039
- const generateBracketRoundSwissGroupMaps = (bracketData) => {
1040
- if (bracketData.mode !== TOURNAMENT_MODE.SWISS_WITH_ELIMINATION) return null;
1041
- const roundsWithSwissGroups = /* @__PURE__ */ new Map();
1042
- let roundNumber = 0;
1043
- for (const bracketRound of bracketData.rounds.values()) {
1044
- const availableGroups = getAvailableSwissGroupsForRound(roundNumber, bracketRound.matchCount);
1045
- const roundSwissData = { groups: /* @__PURE__ */ new Map() };
1046
- for (const group of availableGroups) {
1047
- const subGroup = {
1048
- id: group.id,
1049
- name: group.name,
1050
- matches: new BracketMap(),
1051
- allowedMatchCount: group.matchesInGroup
1052
- };
1053
- roundSwissData.groups.set(group.id, subGroup);
1054
- }
1055
- const emptyMatchIds = [];
1056
- for (const match of bracketRound.matches.values()) {
1057
- const anyParticipant = match.home || match.away;
1058
- if (!anyParticipant) {
1059
- emptyMatchIds.push(match.id);
1060
- continue;
1061
- }
1062
- const { wins, losses } = getRecordBeforeMatch(anyParticipant);
1063
- const groupId = `${wins}-${losses}`;
1064
- let group = roundSwissData.groups.get(groupId);
1065
- if (!group) {
1066
- group = {
1067
- id: groupId,
1068
- name: `${wins}-${losses}`,
1069
- matches: new BracketMap(),
1070
- allowedMatchCount: 0
1071
- };
1072
- roundSwissData.groups.set(groupId, group);
1073
- }
1074
- group.matches.set(match.id, match);
1075
- }
1076
- for (const emptyMatchId of emptyMatchIds) {
1077
- const match = bracketRound.matches.getOrThrow(emptyMatchId);
1078
- const groups = [...roundSwissData.groups.values()];
1079
- let group = groups.find((candidate) => candidate.matches.size < candidate.allowedMatchCount) ?? groups.reduce((fewest, candidate) => !fewest || candidate.matches.size < fewest.matches.size ? candidate : fewest, null);
1080
- if (!group) {
1081
- group = {
1082
- id: UNDRAWN_SWISS_GROUP_ID,
1083
- name: "",
1084
- matches: new BracketMap(),
1085
- allowedMatchCount: 0
1086
- };
1087
- roundSwissData.groups.set(group.id, group);
1088
- }
1089
- group.matches.set(match.id, match);
1090
- }
1091
- for (const [groupId, group] of roundSwissData.groups) if (!group.matches.size) roundSwissData.groups.delete(groupId);
1092
- const orderedGroups = [...roundSwissData.groups.entries()].sort(([a], [b]) => {
1093
- const [aWins = 0, aLosses = 0] = a.split("-").map(Number);
1094
- const [bWins = 0, bLosses = 0] = b.split("-").map(Number);
1095
- return bWins - aWins || aLosses - bLosses;
1096
- });
1097
- roundSwissData.groups = new Map(orderedGroups);
1098
- roundsWithSwissGroups.set(bracketRound.id, roundSwissData);
1099
- roundNumber++;
1100
- }
1101
- return roundsWithSwissGroups;
1102
- };
1103
992
  const collectSwissRoundGeometries = (bracketGrid) => {
1104
993
  const rounds = /* @__PURE__ */ new Map();
1105
994
  for (const column of bracketGrid.columns) {
@@ -1141,7 +1030,7 @@ const collectSwissRoundGeometries = (bracketGrid) => {
1141
1030
  id: group.id,
1142
1031
  wins,
1143
1032
  losses,
1144
- colorType: getSwissGroupColorType(wins, losses),
1033
+ colorType: group.colorType,
1145
1034
  position,
1146
1035
  winnerShortIds,
1147
1036
  loserShortIds
@@ -3132,6 +3021,126 @@ const migrateBracketPicks = (options) => {
3132
3021
  strandedByMatchId
3133
3022
  };
3134
3023
  };
3024
+ const BRACKET_SWISS_GROUP_COLOR_TYPE = {
3025
+ NEUTRAL: "neutral",
3026
+ POSITIVE: "positive",
3027
+ NEGATIVE: "negative",
3028
+ WARNING: "warning"
3029
+ };
3030
+ const getSwissGroupColorType = (wins, losses, mode = TOURNAMENT_MODE.SWISS_WITH_ELIMINATION) => {
3031
+ if (wins === 0 && losses === 0) return BRACKET_SWISS_GROUP_COLOR_TYPE.NEUTRAL;
3032
+ if (mode !== TOURNAMENT_MODE.SWISS && losses === 2) return BRACKET_SWISS_GROUP_COLOR_TYPE.NEGATIVE;
3033
+ if (wins > losses) return BRACKET_SWISS_GROUP_COLOR_TYPE.POSITIVE;
3034
+ return BRACKET_SWISS_GROUP_COLOR_TYPE.WARNING;
3035
+ };
3036
+ const factorialCache = /* @__PURE__ */ new Map();
3037
+ const getAvailableSwissGroupsForRound = (roundNumber, totalMatchesInRound, mode = TOURNAMENT_MODE.SWISS_WITH_ELIMINATION) => {
3038
+ const limited = mode !== TOURNAMENT_MODE.SWISS;
3039
+ const advanceWins = limited ? 3 : Infinity;
3040
+ const eliminateLosses = limited ? 3 : Infinity;
3041
+ const getFactorial = (n) => {
3042
+ if (n <= 1) return 1;
3043
+ if (factorialCache.has(n)) return factorialCache.get(n);
3044
+ const result = n * getFactorial(n - 1);
3045
+ factorialCache.set(n, result);
3046
+ return result;
3047
+ };
3048
+ const roundFactorial = getFactorial(roundNumber);
3049
+ let totalCombinations = 0;
3050
+ const validGroups = [];
3051
+ for (let wins = roundNumber; wins >= 0; wins--) {
3052
+ const losses = roundNumber - wins;
3053
+ const remainingGames = advanceWins + eliminateLosses - (wins + losses) - 1;
3054
+ if (!(wins < advanceWins && remainingGames >= 0) || !(losses < eliminateLosses)) continue;
3055
+ const combinations = roundFactorial / (getFactorial(wins) * getFactorial(losses));
3056
+ totalCombinations += combinations;
3057
+ validGroups.push({
3058
+ wins,
3059
+ losses,
3060
+ combinations
3061
+ });
3062
+ }
3063
+ return validGroups.map(({ wins, losses, combinations }) => ({
3064
+ wins,
3065
+ losses,
3066
+ id: `${wins}-${losses}`,
3067
+ name: `${wins}-${losses}`,
3068
+ matchesInGroup: Math.round(combinations / totalCombinations * totalMatchesInRound)
3069
+ }));
3070
+ };
3071
+ const UNDRAWN_SWISS_GROUP_ID = "undrawn";
3072
+ const getRecordBeforeMatch = (participant) => ({
3073
+ wins: participant.winCount - (participant.result === "win" ? 1 : 0),
3074
+ losses: participant.lossCount - (participant.result === "loss" ? 1 : 0)
3075
+ });
3076
+ const generateBracketRoundSwissGroupMaps = (bracketData) => {
3077
+ if (!isSwissMode(bracketData.mode)) return null;
3078
+ const roundsWithSwissGroups = /* @__PURE__ */ new Map();
3079
+ let roundNumber = 0;
3080
+ for (const bracketRound of bracketData.rounds.values()) {
3081
+ const availableGroups = getAvailableSwissGroupsForRound(roundNumber, bracketRound.matchCount, bracketData.mode);
3082
+ const colorTypeOf = (wins, losses) => getSwissGroupColorType(wins, losses, bracketData.mode);
3083
+ const roundSwissData = { groups: /* @__PURE__ */ new Map() };
3084
+ for (const group of availableGroups) {
3085
+ const subGroup = {
3086
+ id: group.id,
3087
+ name: group.name,
3088
+ matches: new BracketMap(),
3089
+ allowedMatchCount: group.matchesInGroup,
3090
+ colorType: colorTypeOf(group.wins, group.losses)
3091
+ };
3092
+ roundSwissData.groups.set(group.id, subGroup);
3093
+ }
3094
+ const emptyMatchIds = [];
3095
+ for (const match of bracketRound.matches.values()) {
3096
+ const anyParticipant = match.home || match.away;
3097
+ if (!anyParticipant) {
3098
+ emptyMatchIds.push(match.id);
3099
+ continue;
3100
+ }
3101
+ const { wins, losses } = getRecordBeforeMatch(anyParticipant);
3102
+ const groupId = `${wins}-${losses}`;
3103
+ let group = roundSwissData.groups.get(groupId);
3104
+ if (!group) {
3105
+ group = {
3106
+ id: groupId,
3107
+ name: `${wins}-${losses}`,
3108
+ matches: new BracketMap(),
3109
+ allowedMatchCount: 0,
3110
+ colorType: colorTypeOf(wins, losses)
3111
+ };
3112
+ roundSwissData.groups.set(groupId, group);
3113
+ }
3114
+ group.matches.set(match.id, match);
3115
+ }
3116
+ for (const emptyMatchId of emptyMatchIds) {
3117
+ const match = bracketRound.matches.getOrThrow(emptyMatchId);
3118
+ const groups = [...roundSwissData.groups.values()];
3119
+ let group = groups.find((candidate) => candidate.matches.size < candidate.allowedMatchCount) ?? groups.reduce((fewest, candidate) => !fewest || candidate.matches.size < fewest.matches.size ? candidate : fewest, null);
3120
+ if (!group) {
3121
+ group = {
3122
+ id: UNDRAWN_SWISS_GROUP_ID,
3123
+ name: "",
3124
+ matches: new BracketMap(),
3125
+ allowedMatchCount: 0,
3126
+ colorType: BRACKET_SWISS_GROUP_COLOR_TYPE.NEUTRAL
3127
+ };
3128
+ roundSwissData.groups.set(group.id, group);
3129
+ }
3130
+ group.matches.set(match.id, match);
3131
+ }
3132
+ for (const [groupId, group] of roundSwissData.groups) if (!group.matches.size) roundSwissData.groups.delete(groupId);
3133
+ const orderedGroups = [...roundSwissData.groups.entries()].sort(([a], [b]) => {
3134
+ const [aWins = 0, aLosses = 0] = a.split("-").map(Number);
3135
+ const [bWins = 0, bLosses = 0] = b.split("-").map(Number);
3136
+ return bWins - aWins || aLosses - bLosses;
3137
+ });
3138
+ roundSwissData.groups = new Map(orderedGroups);
3139
+ roundsWithSwissGroups.set(bracketRound.id, roundSwissData);
3140
+ roundNumber++;
3141
+ }
3142
+ return roundsWithSwissGroups;
3143
+ };
3135
3144
  const standingRankSides = (options) => {
3136
3145
  const match = options.bracket.matches.get(options.matchId);
3137
3146
  if (!match) return [];
@@ -3355,10 +3364,11 @@ const bracketSlot = {
3355
3364
  const LAYOUT_FACTORY_SUGGESTION = {
3356
3365
  "single-elimination": "singleEliminationBracketLayout()",
3357
3366
  "double-elimination": "doubleEliminationBracketLayout()",
3358
- "swiss-with-elimination": "swissBracketLayout()"
3367
+ "swiss-with-elimination": "swissBracketLayout()",
3368
+ swiss: "swissBracketLayout()"
3359
3369
  };
3360
3370
  const resolveBracketLayout = (layouts, mode) => {
3361
- const layout = layouts?.find((candidate) => candidate.mode === mode);
3371
+ const layout = layouts?.find((candidate) => candidate.mode === mode || candidate.extraModes?.includes(mode));
3362
3372
  if (!layout) throw new BracketRuntimeError(BRACKET_ERROR_CODES.LAYOUT_NOT_REGISTERED, `No bracket layout registered for mode "${mode}". Add ${LAYOUT_FACTORY_SUGGESTION[mode]} to provideBracketConfig({ layouts: [...] }) or to the layouts input.`);
3363
3373
  return layout;
3364
3374
  };
@@ -3493,6 +3503,6 @@ const swapStandingRank = (options) => {
3493
3503
  [next[from], next[to]] = [next[to], participantId];
3494
3504
  return next;
3495
3505
  };
3496
- export { BRACKET_DATA_LAYOUT, BRACKET_ERROR_CODES, BRACKET_FINAL_ALIGNMENT, BRACKET_ROUND_MIRROR_TYPE, BRACKET_SECTION_DEFAULT_NAMES, BRACKET_SECTION_KEY, BRACKET_SWISS_GROUP_COLOR_TYPE, BracketMap, BracketRuntimeError, COMMON_BRACKET_ROUND_TYPE, DOUBLE_ELIMINATION_BRACKET_ROUND_TYPE, GROUP_BRACKET_ROUND_TYPE, SINGLE_ELIMINATION_BRACKET_ROUND_TYPE, STANDING_PICK_OUTCOME, SWISS_ADVANCE_WINS, SWISS_BRACKET_ROUND_TYPE, SWISS_ELIMINATE_LOSSES, TERMINAL_ROUND_SORT_PRIORITY, TOURNAMENT_MODE, bracketGridNaturalWidth, bracketSlot, calculateColumnSplitFactor, calculateLowerRoundIndex, calculateUpperLowerRatio, calculateUpperRoundIndex, createBracket, createBracketBase, createBracketContinueMasterColumn, createBracketElement, createBracketElementPart, createBracketGapMasterColumn, createBracketGrid, createBracketGridSections, createBracketMasterColumn, createBracketMasterColumnSection, createBracketSlotResolver, createBracketSubColumn, createDoubleEliminationGrid, createFoldedThirdPlaceSection, createMatchesMapBase, createNewMatchParticipantBase, createParticipantsMapBase, createPlaceholderBracketSource, createRoundBracketSubColumnRelativeToFirstRound, createRoundsMapBase, createSingleEliminationGrid, createSwissGrid, curvePath, doubleEliminationRoundSection, drawMan, drawSwissMan, finalizeBracketGrid, generateBracketRoundSwissGroupMaps, generateMatchPosition, generateMatchRelationPositions, generateMatchRelationsNew, generateRoundRelationsNew, getAvailableSwissGroupsForRound, getBracketContinueMatches, getSwissGroupColorType, gutterPath, isBracketContinueMatch, isBracketSlotPredictable, linePath, migrateBracketPicks, path, resolveBracketGridRowSpan, resolveBracketLayout, resolveBracketSlot, standingPickOutcome, standingPickStartOrder, standingRankSides, swapStandingRank, validateBracketSource, verticalPath, createStackedDoubleEliminationGrid as ɵcreateStackedDoubleEliminationGrid };
3506
+ export { BRACKET_DATA_LAYOUT, BRACKET_ERROR_CODES, BRACKET_FINAL_ALIGNMENT, BRACKET_ROUND_MIRROR_TYPE, BRACKET_SECTION_DEFAULT_NAMES, BRACKET_SECTION_KEY, BRACKET_SWISS_GROUP_COLOR_TYPE, BracketMap, BracketRuntimeError, COMMON_BRACKET_ROUND_TYPE, DOUBLE_ELIMINATION_BRACKET_ROUND_TYPE, GROUP_BRACKET_ROUND_TYPE, SINGLE_ELIMINATION_BRACKET_ROUND_TYPE, STANDING_PICK_OUTCOME, SWISS_ADVANCE_WINS, SWISS_BRACKET_ROUND_TYPE, SWISS_ELIMINATE_LOSSES, TERMINAL_ROUND_SORT_PRIORITY, TOURNAMENT_MODE, bracketGridNaturalWidth, bracketSlot, calculateColumnSplitFactor, calculateLowerRoundIndex, calculateUpperLowerRatio, calculateUpperRoundIndex, createBracket, createBracketBase, createBracketContinueMasterColumn, createBracketElement, createBracketElementPart, createBracketGapMasterColumn, createBracketGrid, createBracketGridSections, createBracketMasterColumn, createBracketMasterColumnSection, createBracketSlotResolver, createBracketSubColumn, createDoubleEliminationGrid, createFoldedThirdPlaceSection, createMatchesMapBase, createNewMatchParticipantBase, createParticipantsMapBase, createPlaceholderBracketSource, createRoundBracketSubColumnRelativeToFirstRound, createRoundsMapBase, createSingleEliminationGrid, createSwissGrid, curvePath, doubleEliminationRoundSection, drawMan, drawSwissMan, finalizeBracketGrid, generateBracketRoundSwissGroupMaps, generateMatchPosition, generateMatchRelationPositions, generateMatchRelationsNew, generateRoundRelationsNew, getAvailableSwissGroupsForRound, getBracketContinueMatches, getSwissGroupColorType, gutterPath, isBracketContinueMatch, isBracketSlotPredictable, isSwissMode, linePath, migrateBracketPicks, path, resolveBracketGridRowSpan, resolveBracketLayout, resolveBracketSlot, standingPickOutcome, standingPickStartOrder, standingRankSides, swapStandingRank, validateBracketSource, verticalPath, createStackedDoubleEliminationGrid as ɵcreateStackedDoubleEliminationGrid };
3497
3507
 
3498
3508
  //# sourceMappingURL=ethlete-components-bracket.mjs.map