@behindthemusictree/app-kit 33.3.0 → 34.1.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.
@@ -42,6 +42,10 @@ __export(genre_tree_exports, {
42
42
  CriteriaUpdateSchema: () => CriteriaUpdateSchema,
43
43
  FORM_RATING_NULL_VALUE: () => FORM_RATING_NULL_VALUE,
44
44
  FUZZY_MIN_SIMILARITY: () => FUZZY_MIN_SIMILARITY,
45
+ GenreCatalogueCountsSchema: () => GenreCatalogueCountsSchema,
46
+ GenreCountsSchema: () => GenreCountsSchema,
47
+ GenreCoverageSchema: () => GenreCoverageSchema,
48
+ GenrePlaylistSummarySchema: () => GenrePlaylistSummarySchema,
45
49
  GenrePlaylistUuidSchema: () => GenrePlaylistUuidSchema,
46
50
  GenreSearchResultSchema: () => GenreSearchResultSchema,
47
51
  GenreSearchResultsSchema: () => GenreSearchResultsSchema,
@@ -50,6 +54,8 @@ __export(genre_tree_exports, {
50
54
  MbArtistDetailedSchema: () => MbArtistDetailedSchema,
51
55
  MbRecordingDetailedSchema: () => MbRecordingDetailedSchema,
52
56
  NO_VIDEO_LABEL: () => NO_VIDEO_LABEL,
57
+ ReferenceGenreDetailedSchema: () => ReferenceGenreDetailedSchema,
58
+ ReferenceGenrePlaylistSchema: () => ReferenceGenrePlaylistSchema,
53
59
  RegionGenreLexiconEntrySchema: () => RegionGenreLexiconEntrySchema,
54
60
  RegionGenreLexiconSchema: () => RegionGenreLexiconSchema,
55
61
  SEARCH_DEBOUNCE_MS: () => SEARCH_DEBOUNCE_MS,
@@ -59,6 +65,8 @@ __export(genre_tree_exports, {
59
65
  SongHistorySchema: () => SongHistorySchema,
60
66
  SongSearchResultSchema: () => SongSearchResultSchema,
61
67
  SongSearchResultsSchema: () => SongSearchResultsSchema,
68
+ SubgenreCountsSchema: () => SubgenreCountsSchema,
69
+ SubgenreScopeSchema: () => SubgenreScopeSchema,
62
70
  TrackBaseSchema: () => TrackBaseSchema,
63
71
  TrackList: () => TrackList,
64
72
  TrackListFromArtist: () => TrackListFromArtist,
@@ -67,6 +75,7 @@ __export(genre_tree_exports, {
67
75
  TrackListOrigin: () => TrackListOrigin,
68
76
  TrackListOriginFromArtist: () => TrackListOriginFromArtist,
69
77
  TrackListOriginFromCriteriaPlaylist: () => TrackListOriginFromCriteriaPlaylist,
78
+ TrackListOriginFromGenreCatalogue: () => TrackListOriginFromGenreCatalogue,
70
79
  TrackListOriginFromTrack: () => TrackListOriginFromTrack,
71
80
  TrackListOriginType: () => TrackListOriginType,
72
81
  TrackListProvider: () => TrackListProvider,
@@ -78,12 +87,18 @@ __export(genre_tree_exports, {
78
87
  artistEndpoints: () => artistEndpoints,
79
88
  artistQueryKeys: () => artistQueryKeys,
80
89
  capitalizeFirstLetter: () => capitalizeFirstLetter,
90
+ createNameIndex: () => createNameIndex,
91
+ defaultGenreMusicSelection: () => defaultGenreMusicSelection,
81
92
  editGenreSongPages: () => editGenreSongPages,
82
93
  foldSearchText: () => foldSearchText,
83
94
  formatTime: () => formatTime,
84
95
  genreEndpoints: () => genreEndpoints,
96
+ genreMusicCount: () => genreMusicCount,
97
+ genreMusicQueryParams: () => genreMusicQueryParams,
98
+ genreMusicSelectionKey: () => genreMusicSelectionKey,
85
99
  genrePlaylistEndpoints: () => genrePlaylistEndpoints,
86
100
  genrePlaylistQueryKeys: () => genrePlaylistQueryKeys,
101
+ genrePlaylistTrackCount: () => genrePlaylistTrackCount,
87
102
  genreQueryKeys: () => genreQueryKeys,
88
103
  genreSearchQueryKeys: () => genreSearchQueryKeys,
89
104
  genreUpdateMutationKey: () => genreUpdateMutationKey,
@@ -99,6 +114,7 @@ __export(genre_tree_exports, {
99
114
  musicBrainzRecordingUrl: () => musicBrainzRecordingUrl,
100
115
  pruneGenrePlaylistsForArtist: () => pruneGenrePlaylistsForArtist,
101
116
  rankByName: () => rankByName,
117
+ rankNameIndex: () => rankNameIndex,
102
118
  searchGenrePlaylistsByName: () => searchGenrePlaylistsByName,
103
119
  songUnplayableReason: () => songUnplayableReason,
104
120
  trigramSimilarity: () => trigramSimilarity,
@@ -135,15 +151,206 @@ __export(genre_tree_exports, {
135
151
  module.exports = __toCommonJS(genre_tree_exports);
136
152
 
137
153
  // src/genre-tree/useGenre.ts
138
- var import_zod23 = require("zod");
154
+ var import_zod24 = require("zod");
155
+
156
+ // src/genre-tree/schemas/criteria/detailed.ts
157
+ var import_zod11 = require("zod");
158
+
159
+ // src/genre-tree/schemas/genre-music.ts
160
+ var import_zod3 = require("zod");
161
+
162
+ // src/genre-tree/schemas/criteria-playlist/minimum.ts
163
+ var import_zod2 = require("zod");
164
+
165
+ // src/genre-tree/schemas/ids.ts
166
+ var import_zod = require("zod");
167
+ var GenreUuidSchema = import_zod.z.string().uuid().brand();
168
+ var GenrePlaylistUuidSchema = import_zod.z.string().uuid().brand();
169
+
170
+ // src/genre-tree/schemas/criteria-playlist/minimum.ts
171
+ var CriteriaPlaylistMinimumSchema = import_zod2.z.object({
172
+ uuid: GenrePlaylistUuidSchema,
173
+ name: import_zod2.z.string()
174
+ });
175
+
176
+ // src/genre-tree/schemas/genre-music.ts
177
+ var CountSchema = import_zod3.z.number().int().nonnegative();
178
+ var SubgenreCountsSchema = import_zod3.z.union([
179
+ import_zod3.z.object({ canonical: CountSchema, regional: CountSchema, all: CountSchema }).strict(),
180
+ import_zod3.z.object({ all: CountSchema }).strict()
181
+ ]).refine(
182
+ (counts) => !("canonical" in counts) || counts.all >= counts.canonical && counts.all >= counts.regional,
183
+ "The combined count must include both scoped selections"
184
+ );
185
+ var GenreCountsSchema = import_zod3.z.object({
186
+ genreOnlyTracksCount: CountSchema,
187
+ genreAndSubgenresTracksCount: SubgenreCountsSchema
188
+ });
189
+ var includesDirectSongs = (counts) => Object.values(counts.genreAndSubgenresTracksCount).every((count) => count >= counts.genreOnlyTracksCount);
190
+ var GenreCatalogueCountsSchema = GenreCountsSchema.refine(includesDirectSongs, "Every inclusive count must include the genre itself").brand();
191
+ var GenrePlaylistSummarySchema = CriteriaPlaylistMinimumSchema.extend(GenreCountsSchema.shape).refine(includesDirectSongs, "Every inclusive count must include the genre itself").brand();
192
+ var GenreCoverageSchema = import_zod3.z.enum(["genreOnly", "genreAndSubgenres"]);
193
+ var SubgenreScopeSchema = import_zod3.z.enum(["canonical", "regional", "all"]);
194
+
195
+ // src/genre-tree/schemas/criteria/minimum.ts
196
+ var import_zod4 = require("zod");
197
+ var CriteriaMinimumSchema = import_zod4.z.object({
198
+ uuid: GenreUuidSchema,
199
+ name: import_zod4.z.string(),
200
+ side: import_zod4.z.enum(["core", "pop"]).nullable().optional(),
201
+ wikidataId: import_zod4.z.string().nullable().optional()
202
+ });
203
+
204
+ // src/genre-tree/schemas/track/base.ts
205
+ var import_zod8 = require("zod");
206
+
207
+ // src/genre-tree/schemas/artist-minimum.ts
208
+ var import_zod5 = require("zod");
209
+ var ArtistMinimumSchema = import_zod5.z.object({
210
+ uuid: import_zod5.z.string().uuid(),
211
+ name: import_zod5.z.string(),
212
+ isSpecialPurpose: import_zod5.z.boolean().optional()
213
+ });
214
+
215
+ // src/genre-tree/schemas/album-minimum.ts
216
+ var import_zod6 = require("zod");
217
+ var AlbumMinimumSchema = import_zod6.z.object({
218
+ uuid: import_zod6.z.string().uuid(),
219
+ name: import_zod6.z.string(),
220
+ albumArtists: import_zod6.z.array(ArtistMinimumSchema).nullable().optional()
221
+ });
222
+
223
+ // src/genre-tree/schemas/uuid-resource.ts
224
+ var import_zod7 = require("zod");
225
+ var UuidResourceSchema = import_zod7.z.object({
226
+ uuid: import_zod7.z.string().uuid()
227
+ });
228
+
229
+ // src/genre-tree/schemas/track/base.ts
230
+ var TrackBaseSchema = UuidResourceSchema.extend({
231
+ title: import_zod8.z.string(),
232
+ artists: import_zod8.z.array(ArtistMinimumSchema).nullable().optional(),
233
+ album: AlbumMinimumSchema.nullable().optional(),
234
+ trackNumber: import_zod8.z.number().nullable().optional(),
235
+ // null for a song not yet linked to a genre.
236
+ genre: CriteriaMinimumSchema.nullable(),
237
+ rating: import_zod8.z.number().min(0).max(10).nullable().optional(),
238
+ language: import_zod8.z.string().nullable().optional(),
239
+ playCount: import_zod8.z.number().min(0),
240
+ createdOn: import_zod8.z.string().datetime(),
241
+ updatedOn: import_zod8.z.string().datetime().nullable().optional()
242
+ });
243
+
244
+ // src/genre-tree/schemas/track/minimum.ts
245
+ var TrackMinimumSchema = TrackBaseSchema.pick({
246
+ uuid: true,
247
+ title: true,
248
+ artists: true
249
+ });
250
+
251
+ // src/genre-tree/schemas/criteria/lineage-rel/without-ascendant.ts
252
+ var import_zod9 = require("zod");
253
+ var CriteriaLineageRelWithoutAscendantSchema = import_zod9.z.object({
254
+ descendant: CriteriaMinimumSchema,
255
+ degree: import_zod9.z.number()
256
+ });
257
+
258
+ // src/genre-tree/schemas/criteria/lineage-rel/without-descendant.ts
259
+ var import_zod10 = require("zod");
260
+ var CriteriaLineageRelWithoutDescendantSchema = import_zod10.z.object({
261
+ ascendant: CriteriaMinimumSchema,
262
+ degree: import_zod10.z.number()
263
+ });
264
+
265
+ // src/genre-tree/schemas/criteria/detailed.ts
266
+ var CriteriaDetailedSchema = import_zod11.z.object({
267
+ uuid: GenreUuidSchema,
268
+ name: import_zod11.z.string(),
269
+ summary: import_zod11.z.string().nullable(),
270
+ // Optional until every deployed API serves it.
271
+ wikidataId: import_zod11.z.string().nullable().optional(),
272
+ parent: CriteriaMinimumSchema.nullable(),
273
+ ascendants: import_zod11.z.array(CriteriaLineageRelWithoutDescendantSchema),
274
+ descendants: import_zod11.z.array(CriteriaLineageRelWithoutAscendantSchema),
275
+ root: CriteriaMinimumSchema,
276
+ children: import_zod11.z.array(CriteriaMinimumSchema),
277
+ catalogue: GenreCatalogueCountsSchema.optional(),
278
+ criteriaPlaylist: import_zod11.z.union([GenrePlaylistSummarySchema, CriteriaPlaylistMinimumSchema]),
279
+ tracks: import_zod11.z.array(TrackMinimumSchema),
280
+ essentialSongs: import_zod11.z.array(TrackMinimumSchema),
281
+ tracksCount: import_zod11.z.number(),
282
+ updatedOn: import_zod11.z.string().datetime().nullable()
283
+ });
284
+
285
+ // src/genre-tree/schemas/criteria-playlist/simple.ts
286
+ var import_zod13 = require("zod");
287
+
288
+ // src/genre-tree/schemas/criteria-playlist/detailed.ts
289
+ var import_zod12 = require("zod");
290
+ var CriteriaPlaylistDetailedSchema = import_zod12.z.object({
291
+ uuid: GenrePlaylistUuidSchema,
292
+ name: import_zod12.z.string(),
293
+ tracksCount: import_zod12.z.number(),
294
+ genreOnlyTracksCount: GenreCountsSchema.shape.genreOnlyTracksCount.optional(),
295
+ genreAndSubgenresTracksCount: GenreCountsSchema.shape.genreAndSubgenresTracksCount.optional(),
296
+ catalogue: GenreCatalogueCountsSchema.optional(),
297
+ // Summed YouTube views of the same songs as `tracksCount`. Optional: hear-api has no view counts.
298
+ viewsCount: import_zod12.z.number().optional(),
299
+ durationInSec: import_zod12.z.number().min(0).nullable().optional(),
300
+ durationStrInHourMinSec: import_zod12.z.string().nullable().optional(),
301
+ // Nullable: the "Genreless" root playlist has no criteria attached and is never updated.
302
+ criteria: CriteriaMinimumSchema.nullable(),
303
+ parent: CriteriaPlaylistMinimumSchema.nullable(),
304
+ root: CriteriaPlaylistMinimumSchema,
305
+ createdOn: import_zod12.z.string(),
306
+ updatedOn: import_zod12.z.string().nullable()
307
+ });
308
+
309
+ // src/genre-tree/schemas/criteria-playlist/simple.ts
310
+ var CriteriaPlaylistSimpleSchema = CriteriaPlaylistDetailedSchema.pick({
311
+ uuid: true,
312
+ name: true,
313
+ criteria: true,
314
+ parent: true,
315
+ root: true,
316
+ tracksCount: true,
317
+ genreOnlyTracksCount: true,
318
+ genreAndSubgenresTracksCount: true,
319
+ catalogue: true,
320
+ viewsCount: true,
321
+ createdOn: true,
322
+ updatedOn: true
323
+ }).extend({
324
+ // Only on the tree/list payloads, not the detail endpoint — hence not on the detailed schema.
325
+ isUnacceptedRoot: import_zod13.z.boolean(),
326
+ // Optional: a backend that does not curate umbrella genres omits it.
327
+ isUmbrella: import_zod13.z.boolean().optional(),
328
+ // Optional: only the grow tree payload carries it; null when the genre has no scene.
329
+ scene: import_zod13.z.enum(["commercial", "underground"]).nullable().optional()
330
+ });
331
+
332
+ // src/genre-tree/schemas/reference-genre.ts
333
+ var ReferenceGenreDetailedSchema = CriteriaDetailedSchema.extend({
334
+ catalogue: GenreCatalogueCountsSchema,
335
+ criteriaPlaylist: GenrePlaylistSummarySchema
336
+ });
337
+ var ReferenceGenrePlaylistSchema = CriteriaPlaylistSimpleSchema.extend({
338
+ ...GenreCountsSchema.shape,
339
+ catalogue: GenreCatalogueCountsSchema
340
+ }).superRefine((playlist, ctx) => {
341
+ const counts = GenreCatalogueCountsSchema.safeParse(playlist);
342
+ if (!counts.success) for (const issue of counts.error.issues) ctx.addIssue({ code: "custom", path: issue.path, message: issue.message });
343
+ });
344
+
345
+ // src/genre-tree/useGenre.ts
139
346
  var import_react_query5 = require("@tanstack/react-query");
140
347
  var import_react6 = require("react");
141
348
 
142
349
  // src/transport/PlaybackContext.tsx
143
350
  var import_react = require("react");
144
- var import_zod = require("zod");
351
+ var import_zod14 = require("zod");
145
352
  var import_jsx_runtime = require("react/jsx-runtime");
146
- var PlaybackContextSchema = import_zod.z.object({ country: import_zod.z.string().regex(/^[A-Z]{2}$/).nullable() });
353
+ var PlaybackContextSchema = import_zod14.z.object({ country: import_zod14.z.string().regex(/^[A-Z]{2}$/).nullable() });
147
354
  var unmanaged = {
148
355
  country: null,
149
356
  key: null,
@@ -652,14 +859,14 @@ var useFetchWrapper = (getBackendBaseUrl) => {
652
859
  };
653
860
 
654
861
  // src/genre-tree/useGenrePlaylist.ts
655
- var import_zod9 = require("zod");
862
+ var import_zod17 = require("zod");
656
863
  var import_react_query3 = require("@tanstack/react-query");
657
864
 
658
865
  // src/transport/lib/use-query-with-parse.ts
659
866
  var import_react_query2 = require("@tanstack/react-query");
660
867
 
661
868
  // src/transport/lib/parse-with-log.ts
662
- var import_zod2 = require("zod");
869
+ var import_zod15 = require("zod");
663
870
  function parseWithLog(schema, data, context) {
664
871
  const result = schema.safeParse(data);
665
872
  if (!result.success) {
@@ -667,7 +874,7 @@ function parseWithLog(schema, data, context) {
667
874
  if (data == null) {
668
875
  throw new Error(`${prefix} received null response before schema validation`);
669
876
  }
670
- console.error(`${prefix} schema validation failed`, import_zod2.z.flattenError(result.error));
877
+ console.error(`${prefix} schema validation failed`, import_zod15.z.flattenError(result.error));
671
878
  throw result.error;
672
879
  }
673
880
  return result.data;
@@ -689,80 +896,16 @@ function useQueryWithParse({
689
896
  });
690
897
  }
691
898
 
692
- // src/genre-tree/schemas/criteria-playlist/simple.ts
693
- var import_zod7 = require("zod");
694
-
695
- // src/genre-tree/schemas/criteria-playlist/detailed.ts
696
- var import_zod6 = require("zod");
697
-
698
- // src/genre-tree/schemas/ids.ts
699
- var import_zod3 = require("zod");
700
- var GenreUuidSchema = import_zod3.z.string().uuid().brand();
701
- var GenrePlaylistUuidSchema = import_zod3.z.string().uuid().brand();
702
-
703
- // src/genre-tree/schemas/criteria/minimum.ts
704
- var import_zod4 = require("zod");
705
- var CriteriaMinimumSchema = import_zod4.z.object({
706
- uuid: GenreUuidSchema,
707
- name: import_zod4.z.string(),
708
- side: import_zod4.z.enum(["core", "pop"]).nullable().optional(),
709
- wikidataId: import_zod4.z.string().nullable().optional()
710
- });
711
-
712
- // src/genre-tree/schemas/criteria-playlist/minimum.ts
713
- var import_zod5 = require("zod");
714
- var CriteriaPlaylistMinimumSchema = import_zod5.z.object({
715
- uuid: GenrePlaylistUuidSchema,
716
- name: import_zod5.z.string()
717
- });
718
-
719
- // src/genre-tree/schemas/criteria-playlist/detailed.ts
720
- var CriteriaPlaylistDetailedSchema = import_zod6.z.object({
721
- uuid: GenrePlaylistUuidSchema,
722
- name: import_zod6.z.string(),
723
- tracksCount: import_zod6.z.number(),
724
- // Summed YouTube views of the same songs as `tracksCount`. Optional: hear-api has no view counts.
725
- viewsCount: import_zod6.z.number().optional(),
726
- durationInSec: import_zod6.z.number().min(0).nullable().optional(),
727
- durationStrInHourMinSec: import_zod6.z.string().nullable().optional(),
728
- // Nullable: the "Genreless" root playlist has no criteria attached and is never updated.
729
- criteria: CriteriaMinimumSchema.nullable(),
730
- parent: CriteriaPlaylistMinimumSchema.nullable(),
731
- root: CriteriaPlaylistMinimumSchema,
732
- createdOn: import_zod6.z.string(),
733
- updatedOn: import_zod6.z.string().nullable()
734
- });
735
-
736
- // src/genre-tree/schemas/criteria-playlist/simple.ts
737
- var CriteriaPlaylistSimpleSchema = CriteriaPlaylistDetailedSchema.pick({
738
- uuid: true,
739
- name: true,
740
- criteria: true,
741
- parent: true,
742
- root: true,
743
- tracksCount: true,
744
- viewsCount: true,
745
- createdOn: true,
746
- updatedOn: true
747
- }).extend({
748
- // Only on the tree/list payloads, not the detail endpoint — hence not on the detailed schema.
749
- isUnacceptedRoot: import_zod7.z.boolean(),
750
- // Optional: a backend that does not curate umbrella genres omits it.
751
- isUmbrella: import_zod7.z.boolean().optional(),
752
- // Optional: only the grow tree payload carries it; null when the genre has no scene.
753
- scene: import_zod7.z.enum(["commercial", "underground"]).nullable().optional()
754
- });
755
-
756
899
  // src/transport/lib/paginated-response.ts
757
- var import_zod8 = require("zod");
758
- var PaginatedResponseSchema = (itemSchema) => import_zod8.z.object({
759
- overallTotal: import_zod8.z.number(),
760
- next: import_zod8.z.string().url().nullable(),
761
- previous: import_zod8.z.string().url().nullable(),
762
- results: import_zod8.z.array(itemSchema),
763
- page: import_zod8.z.number(),
764
- pageSize: import_zod8.z.number(),
765
- totalPages: import_zod8.z.number()
900
+ var import_zod16 = require("zod");
901
+ var PaginatedResponseSchema = (itemSchema) => import_zod16.z.object({
902
+ overallTotal: import_zod16.z.number(),
903
+ next: import_zod16.z.string().url().nullable(),
904
+ previous: import_zod16.z.string().url().nullable(),
905
+ results: import_zod16.z.array(itemSchema),
906
+ page: import_zod16.z.number(),
907
+ pageSize: import_zod16.z.number(),
908
+ totalPages: import_zod16.z.number()
766
909
  });
767
910
 
768
911
  // src/genre-tree/api/genre-playlists/queryKeys.ts
@@ -800,6 +943,30 @@ var genrePlaylistEndpoints = {
800
943
  reference: { ...makeGenrePlaylistEndpoints(""), tree: () => "genre-playlists/tree/" }
801
944
  };
802
945
 
946
+ // src/genre-tree/lib/genre-music-selection.ts
947
+ function defaultGenreMusicSelection(counts) {
948
+ return { coverage: "genreAndSubgenres", subgenres: "canonical" in counts.genreAndSubgenresTracksCount ? "canonical" : "all" };
949
+ }
950
+ function genreMusicCount(counts, selection = defaultGenreMusicSelection(counts)) {
951
+ if (selection.coverage === "genreOnly") return counts.genreOnlyTracksCount;
952
+ const scopes = counts.genreAndSubgenresTracksCount;
953
+ if (selection.subgenres === "all") return scopes.all;
954
+ if (!("canonical" in scopes)) throw new Error("Regional genres only support all subgenres");
955
+ return scopes[selection.subgenres];
956
+ }
957
+ function genreMusicQueryParams(selection) {
958
+ if (!selection) return {};
959
+ return selection.coverage === "genreOnly" ? { coverage: "genre_only" } : { coverage: "genre_and_subgenres", subgenres: selection.subgenres };
960
+ }
961
+ function genreMusicSelectionKey(selection) {
962
+ return selection ? [selection.coverage, ...selection.coverage === "genreAndSubgenres" ? [selection.subgenres] : []] : [];
963
+ }
964
+ function genrePlaylistTrackCount(playlist) {
965
+ if (playlist.genreOnlyTracksCount === void 0 && playlist.genreAndSubgenresTracksCount === void 0) return playlist.tracksCount;
966
+ if (playlist.genreOnlyTracksCount === void 0 || playlist.genreAndSubgenresTracksCount === void 0) throw new Error("Incomplete genre playlist counts");
967
+ return genreMusicCount({ genreOnlyTracksCount: playlist.genreOnlyTracksCount, genreAndSubgenresTracksCount: playlist.genreAndSubgenresTracksCount });
968
+ }
969
+
803
970
  // src/genre-tree/api/library/songs/queryKeys.ts
804
971
  var makeSongQueryKeys = (prefix) => ({
805
972
  all: [`${prefix}Songs`],
@@ -808,7 +975,7 @@ var makeSongQueryKeys = (prefix) => ({
808
975
  history: (uuid) => [`${prefix}Songs`, "history", uuid],
809
976
  search: (params) => [`${prefix}Songs`, "search", params],
810
977
  // baseUrl keeps distinct backends sharing a scope (e.g. grow and its prototype proxy) apart.
811
- byGenre: (baseUrl, genreUuid) => [`${prefix}Songs`, baseUrl, "genre", genreUuid]
978
+ byGenre: (baseUrl, genreUuid, selection) => [`${prefix}Songs`, baseUrl, "genre", genreUuid, ...genreMusicSelectionKey(selection)]
812
979
  });
813
980
 
814
981
  // src/genre-tree/api/library/songs/endpoints.ts
@@ -878,7 +1045,7 @@ var useListFullGenrePlaylists = (scope, getBackendBaseUrl) => {
878
1045
  const queryClient2 = (0, import_react_query3.useQueryClient)();
879
1046
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
880
1047
  const { session, sessionRestored } = useSession();
881
- const queryKey = scope === "reference" ? genrePlaylistQueryKeys.reference.full(getBackendBaseUrl()) : genrePlaylistQueryKeys.me.full;
1048
+ const queryKey = scope === "reference" ? [...genrePlaylistQueryKeys.reference.full(getBackendBaseUrl()), "genreMusicV1"] : genrePlaylistQueryKeys.me.full;
882
1049
  const query = useQueryWithParse({
883
1050
  queryKey,
884
1051
  queryFn: () => scope === "reference" ? fetch2(genrePlaylistEndpoints.reference.tree(), true, false, {}, { treeName: "canonical" }) : fetchAllPages(
@@ -890,7 +1057,7 @@ var useListFullGenrePlaylists = (scope, getBackendBaseUrl) => {
890
1057
  { page, pageSize: FULL_LIST_PAGE_SIZE, treeName: "canonical" }
891
1058
  )
892
1059
  ),
893
- schema: import_zod9.z.array(CriteriaPlaylistSimpleSchema),
1060
+ schema: scope === "reference" ? import_zod17.z.array(ReferenceGenrePlaylistSchema) : import_zod17.z.array(CriteriaPlaylistSimpleSchema),
894
1061
  context: "useListFullGenrePlaylists",
895
1062
  enabled: scope === "reference" || sessionRestored && !!session?.accessToken
896
1063
  });
@@ -926,7 +1093,7 @@ var useInvalidateAllGenrePlaylistQueries = () => {
926
1093
  // src/transport/lib/use-validated-mutation.ts
927
1094
  var import_react_query4 = require("@tanstack/react-query");
928
1095
  var import_react5 = require("react");
929
- var import_zod10 = require("zod");
1096
+ var import_zod18 = require("zod");
930
1097
  function useValidatedMutation({
931
1098
  inputSchema,
932
1099
  outputSchema,
@@ -959,9 +1126,9 @@ function useValidatedMutation({
959
1126
  } catch (error) {
960
1127
  if (error instanceof Error && "json" in error) {
961
1128
  try {
962
- const errorResponse = import_zod10.z.object({
963
- details: import_zod10.z.object({
964
- fieldErrors: import_zod10.z.record(import_zod10.z.string(), import_zod10.z.array(import_zod10.z.object({ message: import_zod10.z.string() })))
1129
+ const errorResponse = import_zod18.z.object({
1130
+ details: import_zod18.z.object({
1131
+ fieldErrors: import_zod18.z.record(import_zod18.z.string(), import_zod18.z.array(import_zod18.z.object({ message: import_zod18.z.string() })))
965
1132
  })
966
1133
  }).parse(error.json);
967
1134
  setFormErrors(
@@ -984,131 +1151,48 @@ function useValidatedMutation({
984
1151
  return { ...validatedMutation, formErrors };
985
1152
  }
986
1153
 
987
- // src/genre-tree/schemas/criteria/detailed.ts
988
- var import_zod17 = require("zod");
989
-
990
- // src/genre-tree/schemas/track/base.ts
991
- var import_zod14 = require("zod");
992
-
993
- // src/genre-tree/schemas/artist-minimum.ts
994
- var import_zod11 = require("zod");
995
- var ArtistMinimumSchema = import_zod11.z.object({
996
- uuid: import_zod11.z.string().uuid(),
997
- name: import_zod11.z.string(),
998
- isSpecialPurpose: import_zod11.z.boolean().optional()
999
- });
1000
-
1001
- // src/genre-tree/schemas/album-minimum.ts
1002
- var import_zod12 = require("zod");
1003
- var AlbumMinimumSchema = import_zod12.z.object({
1004
- uuid: import_zod12.z.string().uuid(),
1005
- name: import_zod12.z.string(),
1006
- albumArtists: import_zod12.z.array(ArtistMinimumSchema).nullable().optional()
1007
- });
1008
-
1009
- // src/genre-tree/schemas/uuid-resource.ts
1010
- var import_zod13 = require("zod");
1011
- var UuidResourceSchema = import_zod13.z.object({
1012
- uuid: import_zod13.z.string().uuid()
1013
- });
1014
-
1015
- // src/genre-tree/schemas/track/base.ts
1016
- var TrackBaseSchema = UuidResourceSchema.extend({
1017
- title: import_zod14.z.string(),
1018
- artists: import_zod14.z.array(ArtistMinimumSchema).nullable().optional(),
1019
- album: AlbumMinimumSchema.nullable().optional(),
1020
- trackNumber: import_zod14.z.number().nullable().optional(),
1021
- // null for a song not yet linked to a genre.
1022
- genre: CriteriaMinimumSchema.nullable(),
1023
- rating: import_zod14.z.number().min(0).max(10).nullable().optional(),
1024
- language: import_zod14.z.string().nullable().optional(),
1025
- playCount: import_zod14.z.number().min(0),
1026
- createdOn: import_zod14.z.string().datetime(),
1027
- updatedOn: import_zod14.z.string().datetime().nullable().optional()
1028
- });
1029
-
1030
- // src/genre-tree/schemas/track/minimum.ts
1031
- var TrackMinimumSchema = TrackBaseSchema.pick({
1032
- uuid: true,
1033
- title: true,
1034
- artists: true
1035
- });
1036
-
1037
- // src/genre-tree/schemas/criteria/lineage-rel/without-ascendant.ts
1038
- var import_zod15 = require("zod");
1039
- var CriteriaLineageRelWithoutAscendantSchema = import_zod15.z.object({
1040
- descendant: CriteriaMinimumSchema,
1041
- degree: import_zod15.z.number()
1042
- });
1043
-
1044
- // src/genre-tree/schemas/criteria/lineage-rel/without-descendant.ts
1045
- var import_zod16 = require("zod");
1046
- var CriteriaLineageRelWithoutDescendantSchema = import_zod16.z.object({
1047
- ascendant: CriteriaMinimumSchema,
1048
- degree: import_zod16.z.number()
1049
- });
1050
-
1051
- // src/genre-tree/schemas/criteria/detailed.ts
1052
- var CriteriaDetailedSchema = import_zod17.z.object({
1053
- uuid: GenreUuidSchema,
1054
- name: import_zod17.z.string(),
1055
- summary: import_zod17.z.string().nullable(),
1056
- // Optional until every deployed API serves it.
1057
- wikidataId: import_zod17.z.string().nullable().optional(),
1058
- parent: CriteriaMinimumSchema.nullable(),
1059
- ascendants: import_zod17.z.array(CriteriaLineageRelWithoutDescendantSchema),
1060
- descendants: import_zod17.z.array(CriteriaLineageRelWithoutAscendantSchema),
1061
- root: CriteriaMinimumSchema,
1062
- children: import_zod17.z.array(CriteriaMinimumSchema),
1063
- criteriaPlaylist: CriteriaPlaylistMinimumSchema,
1064
- tracks: import_zod17.z.array(TrackMinimumSchema),
1065
- essentialSongs: import_zod17.z.array(TrackMinimumSchema),
1066
- tracksCount: import_zod17.z.number(),
1067
- updatedOn: import_zod17.z.string().datetime().nullable()
1068
- });
1069
-
1070
1154
  // src/genre-tree/schemas/criteria/overview.ts
1071
- var import_zod19 = require("zod");
1155
+ var import_zod20 = require("zod");
1072
1156
 
1073
1157
  // src/genre-tree/schemas/http-url.ts
1074
- var import_zod18 = require("zod");
1075
- var HttpUrlSchema = import_zod18.z.url({ protocol: /^https?$/ });
1158
+ var import_zod19 = require("zod");
1159
+ var HttpUrlSchema = import_zod19.z.url({ protocol: /^https?$/ });
1076
1160
 
1077
1161
  // src/genre-tree/schemas/criteria/overview.ts
1078
- var CriteriaOverviewSchema = import_zod19.z.object({
1162
+ var CriteriaOverviewSchema = import_zod20.z.object({
1079
1163
  uuid: GenreUuidSchema,
1080
- name: import_zod19.z.string(),
1081
- summary: import_zod19.z.string().nullable(),
1082
- description: import_zod19.z.string().nullable(),
1164
+ name: import_zod20.z.string(),
1165
+ summary: import_zod20.z.string().nullable(),
1166
+ description: import_zod20.z.string().nullable(),
1083
1167
  summarySourceUrl: HttpUrlSchema.nullable(),
1084
- essentialSongs: import_zod19.z.array(TrackMinimumSchema).optional()
1168
+ essentialSongs: import_zod20.z.array(TrackMinimumSchema).optional()
1085
1169
  });
1086
1170
 
1087
1171
  // src/genre-tree/schemas/criteria/simple.ts
1088
- var import_zod20 = require("zod");
1089
- var CriteriaSimpleSchema = import_zod20.z.object({
1172
+ var import_zod21 = require("zod");
1173
+ var CriteriaSimpleSchema = import_zod21.z.object({
1090
1174
  uuid: GenreUuidSchema,
1091
- name: import_zod20.z.string(),
1175
+ name: import_zod21.z.string(),
1092
1176
  parent: CriteriaMinimumSchema.nullable(),
1093
- createdOn: import_zod20.z.string().datetime(),
1094
- summary: import_zod20.z.string().nullable()
1177
+ createdOn: import_zod21.z.string().datetime(),
1178
+ summary: import_zod21.z.string().nullable()
1095
1179
  });
1096
1180
 
1097
1181
  // src/genre-tree/schemas/criteria/creation.ts
1098
- var import_zod21 = require("zod");
1099
- var CriteriaCreationSchema = import_zod21.z.object({
1100
- name: import_zod21.z.string().min(1, "Name is required"),
1182
+ var import_zod22 = require("zod");
1183
+ var CriteriaCreationSchema = import_zod22.z.object({
1184
+ name: import_zod22.z.string().min(1, "Name is required"),
1101
1185
  parent: GenreUuidSchema.optional(),
1102
- essentialSongs: import_zod21.z.array(import_zod21.z.string().uuid()).optional()
1186
+ essentialSongs: import_zod22.z.array(import_zod22.z.string().uuid()).optional()
1103
1187
  });
1104
1188
 
1105
1189
  // src/genre-tree/schemas/criteria/update.ts
1106
- var import_zod22 = require("zod");
1107
- var CriteriaUpdateSchema = import_zod22.z.object({
1108
- name: import_zod22.z.string().optional(),
1190
+ var import_zod23 = require("zod");
1191
+ var CriteriaUpdateSchema = import_zod23.z.object({
1192
+ name: import_zod23.z.string().optional(),
1109
1193
  parent: GenreUuidSchema.nullable().optional(),
1110
- essentialSongs: import_zod22.z.array(import_zod22.z.string().uuid()).optional(),
1111
- side: import_zod22.z.enum(["core", "pop"]).optional()
1194
+ essentialSongs: import_zod23.z.array(import_zod23.z.string().uuid()).optional(),
1195
+ side: import_zod23.z.enum(["core", "pop"]).optional()
1112
1196
  });
1113
1197
 
1114
1198
  // src/genre-tree/api/genres/queryKeys.ts
@@ -1169,18 +1253,18 @@ function useFetchGenre(scope, getBackendBaseUrl) {
1169
1253
  async (id) => {
1170
1254
  const endpoint = scope === "reference" ? genreEndpoints.reference.detail(id) : genreEndpoints.me.detail(id);
1171
1255
  const response = await fetch2(endpoint, true, scope === "me");
1172
- return parseWithLog(CriteriaDetailedSchema, response, "useFetchGenre");
1256
+ return parseWithLog(scope === "reference" ? ReferenceGenreDetailedSchema : CriteriaDetailedSchema, response, "useFetchGenre");
1173
1257
  },
1174
1258
  [fetch2, scope]
1175
1259
  );
1176
1260
  }
1177
- function useFetchGenreDetail(id, scope, getBackendBaseUrl, schema = CriteriaDetailedSchema) {
1261
+ function useFetchGenreDetail(id, scope, getBackendBaseUrl, schema = scope === "reference" ? ReferenceGenreDetailedSchema : CriteriaDetailedSchema) {
1178
1262
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1179
1263
  const queryKeys = scope === "reference" ? genreQueryKeys.reference : genreQueryKeys.me;
1180
1264
  const endpoints = scope === "reference" ? genreEndpoints.reference : genreEndpoints.me;
1181
1265
  const genreUuid = id ?? "";
1182
1266
  return useQueryWithParse({
1183
- queryKey: queryKeys.detail(genreUuid),
1267
+ queryKey: scope === "reference" ? [...queryKeys.detail(genreUuid), getBackendBaseUrl(), "genreMusicV1"] : queryKeys.detail(genreUuid),
1184
1268
  queryFn: () => fetch2(endpoints.detail(genreUuid), true, scope === "me"),
1185
1269
  schema,
1186
1270
  context: "useFetchGenreDetail",
@@ -1263,7 +1347,7 @@ function useUpdateGenre(scope, getBackendBaseUrl) {
1263
1347
  const refreshGenreTree = useRefreshGenreTree(scope);
1264
1348
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1265
1349
  const { mutate, mutateAsync, isPending, formErrors } = useValidatedMutation({
1266
- inputSchema: import_zod23.z.object({
1350
+ inputSchema: import_zod24.z.object({
1267
1351
  uuid: GenreUuidSchema,
1268
1352
  data: CriteriaUpdateSchema
1269
1353
  }),
@@ -1293,8 +1377,8 @@ function useDeleteGenre(scope, getBackendBaseUrl) {
1293
1377
  const refreshGenreTree = useRefreshGenreTree(scope);
1294
1378
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1295
1379
  return useValidatedMutation({
1296
- inputSchema: import_zod23.z.object({ uuid: GenreUuidSchema }),
1297
- outputSchema: import_zod23.z.null(),
1380
+ inputSchema: import_zod24.z.object({ uuid: GenreUuidSchema }),
1381
+ outputSchema: import_zod24.z.null(),
1298
1382
  mutationFn: async ({ uuid }) => {
1299
1383
  const endpoint = scope === "reference" ? genreEndpoints.reference.delete(uuid) : genreEndpoints.me.delete(uuid);
1300
1384
  return fetch2(endpoint, true, scope === "me", { method: "DELETE" }, void 0, false, true);
@@ -1304,16 +1388,16 @@ function useDeleteGenre(scope, getBackendBaseUrl) {
1304
1388
  }
1305
1389
 
1306
1390
  // src/genre-tree/useArtist.ts
1307
- var import_zod25 = require("zod");
1391
+ var import_zod26 = require("zod");
1308
1392
 
1309
1393
  // src/genre-tree/schemas/artist-detailed.ts
1310
- var import_zod24 = require("zod");
1311
- var ArtistMembershipSchema = import_zod24.z.object({
1394
+ var import_zod25 = require("zod");
1395
+ var ArtistMembershipSchema = import_zod25.z.object({
1312
1396
  artist: ArtistMinimumSchema,
1313
- beginYear: import_zod24.z.number().int().nullable(),
1314
- endYear: import_zod24.z.number().int().nullable(),
1315
- ended: import_zod24.z.boolean(),
1316
- roles: import_zod24.z.array(import_zod24.z.string())
1397
+ beginYear: import_zod25.z.number().int().nullable(),
1398
+ endYear: import_zod25.z.number().int().nullable(),
1399
+ ended: import_zod25.z.boolean(),
1400
+ roles: import_zod25.z.array(import_zod25.z.string())
1317
1401
  });
1318
1402
  var ARTIST_LINK_KINDS = [
1319
1403
  "official",
@@ -1326,35 +1410,35 @@ var ARTIST_LINK_KINDS = [
1326
1410
  "discogs",
1327
1411
  "social"
1328
1412
  ];
1329
- var ArtistImageSchema = import_zod24.z.object({
1413
+ var ArtistImageSchema = import_zod25.z.object({
1330
1414
  url: HttpUrlSchema,
1331
1415
  pageUrl: HttpUrlSchema,
1332
- author: import_zod24.z.string().nullable(),
1333
- license: import_zod24.z.string(),
1416
+ author: import_zod25.z.string().nullable(),
1417
+ license: import_zod25.z.string(),
1334
1418
  licenseUrl: HttpUrlSchema.nullable()
1335
1419
  });
1336
- var ArtistDetailedSchema = import_zod24.z.object({
1337
- uuid: import_zod24.z.string().uuid(),
1338
- name: import_zod24.z.string(),
1339
- musicbrainzArtistId: import_zod24.z.string().uuid().nullable(),
1340
- type: import_zod24.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1341
- country: import_zod24.z.string().nullable(),
1342
- beginYear: import_zod24.z.number().int().nullable(),
1343
- endYear: import_zod24.z.number().int().nullable(),
1344
- ended: import_zod24.z.boolean(),
1345
- links: import_zod24.z.array(import_zod24.z.object({ kind: import_zod24.z.enum(ARTIST_LINK_KINDS), url: HttpUrlSchema })),
1346
- members: import_zod24.z.array(ArtistMembershipSchema),
1347
- memberOf: import_zod24.z.array(ArtistMembershipSchema),
1348
- albums: import_zod24.z.array(
1349
- import_zod24.z.object({
1350
- uuid: import_zod24.z.string().uuid(),
1351
- name: import_zod24.z.string(),
1352
- year: import_zod24.z.string().nullable(),
1353
- primaryType: import_zod24.z.string().nullable(),
1354
- secondaryTypes: import_zod24.z.array(import_zod24.z.string())
1420
+ var ArtistDetailedSchema = import_zod25.z.object({
1421
+ uuid: import_zod25.z.string().uuid(),
1422
+ name: import_zod25.z.string(),
1423
+ musicbrainzArtistId: import_zod25.z.string().uuid().nullable(),
1424
+ type: import_zod25.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1425
+ country: import_zod25.z.string().nullable(),
1426
+ beginYear: import_zod25.z.number().int().nullable(),
1427
+ endYear: import_zod25.z.number().int().nullable(),
1428
+ ended: import_zod25.z.boolean(),
1429
+ links: import_zod25.z.array(import_zod25.z.object({ kind: import_zod25.z.enum(ARTIST_LINK_KINDS), url: HttpUrlSchema })),
1430
+ members: import_zod25.z.array(ArtistMembershipSchema),
1431
+ memberOf: import_zod25.z.array(ArtistMembershipSchema),
1432
+ albums: import_zod25.z.array(
1433
+ import_zod25.z.object({
1434
+ uuid: import_zod25.z.string().uuid(),
1435
+ name: import_zod25.z.string(),
1436
+ year: import_zod25.z.string().nullable(),
1437
+ primaryType: import_zod25.z.string().nullable(),
1438
+ secondaryTypes: import_zod25.z.array(import_zod25.z.string())
1355
1439
  })
1356
1440
  ),
1357
- tracksCount: import_zod24.z.number().int(),
1441
+ tracksCount: import_zod25.z.number().int(),
1358
1442
  image: ArtistImageSchema.nullable()
1359
1443
  });
1360
1444
 
@@ -1377,7 +1461,7 @@ var artistEndpoints = {
1377
1461
  var isNotFound = (error) => error instanceof AppError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */;
1378
1462
  function useArtist(uuid, getBackendBaseUrl) {
1379
1463
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1380
- const isUuid = uuid !== null && import_zod25.z.string().uuid().safeParse(uuid).success;
1464
+ const isUuid = uuid !== null && import_zod26.z.string().uuid().safeParse(uuid).success;
1381
1465
  const { data, isPending, error } = useQueryWithParse({
1382
1466
  queryKey: artistQueryKeys.detail(uuid),
1383
1467
  // A missing artist is shown in the panel, not raised as an app-wide connectivity error.
@@ -1395,19 +1479,19 @@ function useArtist(uuid, getBackendBaseUrl) {
1395
1479
  }
1396
1480
 
1397
1481
  // src/genre-tree/schemas/artist-search.ts
1398
- var import_zod26 = require("zod");
1399
- var ArtistSearchResultSchema = import_zod26.z.object({
1400
- uuid: import_zod26.z.string().uuid(),
1401
- name: import_zod26.z.string(),
1402
- disambiguation: import_zod26.z.string().nullable(),
1403
- type: import_zod26.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1404
- country: import_zod26.z.string().nullable(),
1405
- beginYear: import_zod26.z.number().int().nullable(),
1406
- endYear: import_zod26.z.number().int().nullable(),
1407
- matchedAlias: import_zod26.z.string().nullable(),
1408
- recordingCount: import_zod26.z.number().int()
1482
+ var import_zod27 = require("zod");
1483
+ var ArtistSearchResultSchema = import_zod27.z.object({
1484
+ uuid: import_zod27.z.string().uuid(),
1485
+ name: import_zod27.z.string(),
1486
+ disambiguation: import_zod27.z.string().nullable(),
1487
+ type: import_zod27.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1488
+ country: import_zod27.z.string().nullable(),
1489
+ beginYear: import_zod27.z.number().int().nullable(),
1490
+ endYear: import_zod27.z.number().int().nullable(),
1491
+ matchedAlias: import_zod27.z.string().nullable(),
1492
+ recordingCount: import_zod27.z.number().int()
1409
1493
  });
1410
- var ArtistSearchResultsSchema = import_zod26.z.array(ArtistSearchResultSchema);
1494
+ var ArtistSearchResultsSchema = import_zod27.z.array(ArtistSearchResultSchema);
1411
1495
 
1412
1496
  // src/genre-tree/useRemoteSearch.ts
1413
1497
  var import_react_query6 = require("@tanstack/react-query");
@@ -1461,10 +1545,10 @@ function useArtistSearch(getBackendBaseUrl, text) {
1461
1545
  }
1462
1546
 
1463
1547
  // src/genre-tree/useSong.ts
1464
- var import_zod28 = require("zod");
1548
+ var import_zod29 = require("zod");
1465
1549
 
1466
1550
  // src/genre-tree/schemas/song/detailed.ts
1467
- var import_zod27 = require("zod");
1551
+ var import_zod28 = require("zod");
1468
1552
  var YOUTUBE_UNPLAYABLE_REASON_LABELS = {
1469
1553
  not_found: "Video unavailable",
1470
1554
  not_embeddable: "Embedding disabled",
@@ -1473,23 +1557,23 @@ var YOUTUBE_UNPLAYABLE_REASON_LABELS = {
1473
1557
  region_whitelisted: "Region restricted"
1474
1558
  };
1475
1559
  var YOUTUBE_UNPLAYABLE_REASONS = Object.keys(YOUTUBE_UNPLAYABLE_REASON_LABELS);
1476
- var YoutubeAvailabilitySchema = import_zod27.z.object({
1477
- status: import_zod27.z.enum(["eligible", "blocked", "unknown"]),
1478
- reason: import_zod27.z.string().nullable(),
1479
- country: import_zod27.z.string().nullable()
1560
+ var YoutubeAvailabilitySchema = import_zod28.z.object({
1561
+ status: import_zod28.z.enum(["eligible", "blocked", "unknown"]),
1562
+ reason: import_zod28.z.string().nullable(),
1563
+ country: import_zod28.z.string().nullable()
1480
1564
  });
1481
1565
  var SongDetailedSchema = TrackBaseSchema.extend({
1482
- youtubeVideo: import_zod27.z.object({
1483
- id: import_zod27.z.string(),
1566
+ youtubeVideo: import_zod28.z.object({
1567
+ id: import_zod28.z.string(),
1484
1568
  availability: YoutubeAvailabilitySchema.optional(),
1485
1569
  // null = playable
1486
- unplayableReason: import_zod27.z.enum(YOUTUBE_UNPLAYABLE_REASONS).nullable(),
1487
- viewCount: import_zod27.z.number().int().nullable().optional()
1570
+ unplayableReason: import_zod28.z.enum(YOUTUBE_UNPLAYABLE_REASONS).nullable(),
1571
+ viewCount: import_zod28.z.number().int().nullable().optional()
1488
1572
  }).nullable(),
1489
1573
  // null for hand-made/admin songs
1490
- musicbrainzRecordingId: import_zod27.z.string().uuid().nullable(),
1491
- firstReleaseYear: import_zod27.z.number().int().nullable().optional(),
1492
- essentialGenres: import_zod27.z.array(CriteriaMinimumSchema).optional()
1574
+ musicbrainzRecordingId: import_zod28.z.string().uuid().nullable(),
1575
+ firstReleaseYear: import_zod28.z.number().int().nullable().optional(),
1576
+ essentialGenres: import_zod28.z.array(CriteriaMinimumSchema).optional()
1493
1577
  });
1494
1578
  var NO_VIDEO_LABEL = "No video available";
1495
1579
  function isSong(track) {
@@ -1510,7 +1594,7 @@ var isNotFound2 = (error) => error instanceof AppError && error.code === "BAC404
1510
1594
  function useSong(uuid, getBackendBaseUrl) {
1511
1595
  const playback = usePlaybackContext();
1512
1596
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1513
- const isUuid = uuid !== null && import_zod28.z.string().uuid().safeParse(uuid).success;
1597
+ const isUuid = uuid !== null && import_zod29.z.string().uuid().safeParse(uuid).success;
1514
1598
  const { data, isPending, error } = useQueryWithParse({
1515
1599
  queryKey: [...libraryQueryKeys.reference.songs.detail(uuid), ...playback.key ? [playback.key] : []],
1516
1600
  // A missing song is shown in the panel, not raised as an app-wide connectivity error.
@@ -1528,16 +1612,16 @@ function useSong(uuid, getBackendBaseUrl) {
1528
1612
  }
1529
1613
 
1530
1614
  // src/genre-tree/schemas/song-history.ts
1531
- var import_zod29 = require("zod");
1532
- var SongHistoryEntrySchema = import_zod29.z.object({
1533
- uuid: import_zod29.z.string().uuid(),
1534
- action: import_zod29.z.string(),
1535
- actorPseudo: import_zod29.z.string().nullable(),
1536
- oldValue: import_zod29.z.string().nullable(),
1537
- newValue: import_zod29.z.string().nullable(),
1538
- createdOn: import_zod29.z.string()
1615
+ var import_zod30 = require("zod");
1616
+ var SongHistoryEntrySchema = import_zod30.z.object({
1617
+ uuid: import_zod30.z.string().uuid(),
1618
+ action: import_zod30.z.string(),
1619
+ actorPseudo: import_zod30.z.string().nullable(),
1620
+ oldValue: import_zod30.z.string().nullable(),
1621
+ newValue: import_zod30.z.string().nullable(),
1622
+ createdOn: import_zod30.z.string()
1539
1623
  });
1540
- var SongHistorySchema = import_zod29.z.array(SongHistoryEntrySchema);
1624
+ var SongHistorySchema = import_zod30.z.array(SongHistoryEntrySchema);
1541
1625
 
1542
1626
  // src/genre-tree/useSongHistory.ts
1543
1627
  function useSongHistory(uuid, getBackendBaseUrl, enabled) {
@@ -1557,20 +1641,20 @@ function useSongHistory(uuid, getBackendBaseUrl, enabled) {
1557
1641
  }
1558
1642
 
1559
1643
  // src/genre-tree/schemas/song-search.ts
1560
- var import_zod30 = require("zod");
1561
- var SongSearchResultSchema = import_zod30.z.object({
1562
- uuid: import_zod30.z.string().uuid(),
1563
- title: import_zod30.z.string(),
1564
- artists: import_zod30.z.array(ArtistMinimumSchema),
1644
+ var import_zod31 = require("zod");
1645
+ var SongSearchResultSchema = import_zod31.z.object({
1646
+ uuid: import_zod31.z.string().uuid(),
1647
+ title: import_zod31.z.string(),
1648
+ artists: import_zod31.z.array(ArtistMinimumSchema),
1565
1649
  // null for songs not yet linked to a genre.
1566
1650
  genre: CriteriaMinimumSchema.nullable(),
1567
- youtubeVideo: import_zod30.z.object({
1568
- id: import_zod30.z.string(),
1569
- unplayableReason: import_zod30.z.string().nullable()
1651
+ youtubeVideo: import_zod31.z.object({
1652
+ id: import_zod31.z.string(),
1653
+ unplayableReason: import_zod31.z.string().nullable()
1570
1654
  }).nullable(),
1571
- firstReleaseYear: import_zod30.z.number().int().nullable()
1655
+ firstReleaseYear: import_zod31.z.number().int().nullable()
1572
1656
  });
1573
- var SongSearchResultsSchema = import_zod30.z.array(SongSearchResultSchema);
1657
+ var SongSearchResultsSchema = import_zod31.z.array(SongSearchResultSchema);
1574
1658
  function isSongSearchResultPlayable(result) {
1575
1659
  return result.youtubeVideo !== null && result.youtubeVideo.unplayableReason === null;
1576
1660
  }
@@ -1596,16 +1680,25 @@ function useSongSearch(getBackendBaseUrl, text, options = {}) {
1596
1680
 
1597
1681
  // src/genre-tree/useArtistGenreCounts.ts
1598
1682
  var import_react_query7 = require("@tanstack/react-query");
1599
- var import_zod32 = require("zod");
1683
+ var import_zod33 = require("zod");
1600
1684
 
1601
1685
  // src/genre-tree/schemas/artist-genre-count.ts
1602
- var import_zod31 = require("zod");
1603
- var ArtistGenreCountSchema = import_zod31.z.object({
1686
+ var import_zod32 = require("zod");
1687
+ var ArtistGenreCountSchema = import_zod32.z.object({
1688
+ ...GenreCountsSchema.shape,
1689
+ catalogue: GenreCatalogueCountsSchema,
1604
1690
  genrePlaylist: GenrePlaylistUuidSchema,
1605
- /** All the artist's songs in the genre playlist's subtree; drives pruning. */
1606
- songsCount: import_zod31.z.number().int().nonnegative(),
1607
- /** The playable ones among them; drives node size and the play button. */
1608
- tracksCount: import_zod31.z.number().int().nonnegative()
1691
+ /** Legacy catalogue count for the default selection. */
1692
+ songsCount: import_zod32.z.number().int().nonnegative(),
1693
+ /** Legacy playlist count for the default selection. */
1694
+ tracksCount: import_zod32.z.number().int().nonnegative()
1695
+ }).superRefine((row, ctx) => {
1696
+ const counts = GenreCatalogueCountsSchema.safeParse(row);
1697
+ if (!counts.success) {
1698
+ for (const issue of counts.error.issues) {
1699
+ ctx.addIssue({ code: "custom", path: issue.path, message: issue.message });
1700
+ }
1701
+ }
1609
1702
  });
1610
1703
 
1611
1704
  // src/genre-tree/useArtistGenreCounts.ts
@@ -1613,10 +1706,10 @@ var isNotFound3 = (error) => error instanceof AppError && error.code === "BAC404
1613
1706
  function useArtistGenreCounts(artistUuid, getBackendBaseUrl) {
1614
1707
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1615
1708
  return useQueryWithParse({
1616
- queryKey: artistQueryKeys.genreCounts(getBackendBaseUrl(), artistUuid),
1709
+ queryKey: [...artistQueryKeys.genreCounts(getBackendBaseUrl(), artistUuid), "genreMusicV1"],
1617
1710
  // A missing artist is shown in the artist panel, not raised as an app-wide connectivity error.
1618
1711
  queryFn: () => fetch2(artistEndpoints.genreCounts(artistUuid), true, false, void 0, void 0, false, true),
1619
- schema: import_zod32.z.array(ArtistGenreCountSchema),
1712
+ schema: import_zod33.z.array(ArtistGenreCountSchema),
1620
1713
  enabled: artistUuid !== null,
1621
1714
  placeholderData: import_react_query7.keepPreviousData,
1622
1715
  retry: (failureCount, error) => !isNotFound3(error) && failureCount < 3,
@@ -1624,6 +1717,9 @@ function useArtistGenreCounts(artistUuid, getBackendBaseUrl) {
1624
1717
  });
1625
1718
  }
1626
1719
 
1720
+ // src/genre-tree/useGenreSearch.ts
1721
+ var import_react9 = require("react");
1722
+
1627
1723
  // src/genre-tree/lib/search-text.ts
1628
1724
  var foldSearchText = (text) => text.normalize("NFD").replace(/\p{M}+/gu, "").toLowerCase().replace(/\s+/g, " ").trim();
1629
1725
  var trigrams = (folded) => {
@@ -1669,9 +1765,54 @@ function rankByName(items, query, getName, getViews) {
1669
1765
  );
1670
1766
  return scored.map((entry) => entry.item);
1671
1767
  }
1672
-
1673
- // src/genre-tree/lib/genre-search.ts
1674
- var searchGenrePlaylistsByName = (genrePlaylists, query) => rankByName(genrePlaylists, query, (genrePlaylist) => genrePlaylist.name, (genrePlaylist) => genrePlaylist.viewsCount ?? 0);
1768
+ function createNameIndex(items, getName, getViews) {
1769
+ return items.map((item) => {
1770
+ const name = foldSearchText(getName(item));
1771
+ return { item, name, grams: trigrams(name), views: getViews?.(item) ?? 0 };
1772
+ });
1773
+ }
1774
+ function rankNameIndex(index, query, limit = Infinity) {
1775
+ if (limit !== Infinity && (!Number.isInteger(limit) || limit < 0)) {
1776
+ throw new RangeError("Search limit must be a nonnegative integer or Infinity");
1777
+ }
1778
+ const folded = foldSearchText(query);
1779
+ if (!folded || limit === 0) return [];
1780
+ const queryGrams = trigrams(folded);
1781
+ const scored = [];
1782
+ const compare = (a, b) => a.tier - b.tier || b.similarity - a.similarity || b.views - a.views || a.name.localeCompare(b.name);
1783
+ for (const entry of index) {
1784
+ let tier;
1785
+ let similarity = 0;
1786
+ if (entry.name === folded) tier = TIER_EXACT;
1787
+ else if (entry.name.startsWith(folded)) tier = TIER_PREFIX;
1788
+ else if (entry.name.includes(folded)) tier = TIER_SUBSTRING;
1789
+ else {
1790
+ let shared = 0;
1791
+ for (const gram of queryGrams) if (entry.grams.has(gram)) shared++;
1792
+ const union = entry.grams.size + queryGrams.size - shared;
1793
+ similarity = union === 0 ? 0 : shared / union;
1794
+ if (similarity < FUZZY_MIN_SIMILARITY) continue;
1795
+ tier = TIER_FUZZY;
1796
+ }
1797
+ const candidate = { ...entry, tier, similarity };
1798
+ if (limit === Infinity) scored.push(candidate);
1799
+ else {
1800
+ let low = 0;
1801
+ let high = scored.length;
1802
+ while (low < high) {
1803
+ const mid = low + high >>> 1;
1804
+ if (compare(candidate, scored[mid]) < 0) high = mid;
1805
+ else low = mid + 1;
1806
+ }
1807
+ if (low < limit) {
1808
+ scored.splice(low, 0, candidate);
1809
+ if (scored.length > limit) scored.pop();
1810
+ }
1811
+ }
1812
+ }
1813
+ if (limit === Infinity) scored.sort(compare);
1814
+ return scored.map((entry) => entry.item);
1815
+ }
1675
1816
 
1676
1817
  // src/genre-tree/useSearchQueryState.ts
1677
1818
  var import_react8 = require("react");
@@ -1705,7 +1846,15 @@ function useGenreSearch({
1705
1846
  onClear
1706
1847
  }) {
1707
1848
  const { query, setQuery, isTyping, canClear, clear, notifyPick } = useSearchQueryState({ selectedName, onClear });
1708
- const results = isTyping ? searchGenrePlaylistsByName(genrePlaylists, query) : [];
1849
+ const index = (0, import_react9.useMemo)(
1850
+ () => createNameIndex(genrePlaylists, (playlist) => playlist.name, (playlist) => playlist.viewsCount ?? 0),
1851
+ [genrePlaylists]
1852
+ );
1853
+ const deferredQuery = (0, import_react9.useDeferredValue)(query);
1854
+ const results = (0, import_react9.useMemo)(
1855
+ () => isTyping ? rankNameIndex(index, deferredQuery) : [],
1856
+ [index, deferredQuery, isTyping]
1857
+ );
1709
1858
  return {
1710
1859
  query,
1711
1860
  setQuery,
@@ -1720,32 +1869,32 @@ function useGenreSearch({
1720
1869
  }
1721
1870
 
1722
1871
  // src/genre-tree/schemas/genre-search.ts
1723
- var import_zod33 = require("zod");
1724
- var GenreSearchTreeNameSchema = import_zod33.z.enum(["canonical", "regional"]);
1725
- var GenreSearchResultSchema = import_zod33.z.object({
1872
+ var import_zod34 = require("zod");
1873
+ var GenreSearchTreeNameSchema = import_zod34.z.enum(["canonical", "regional"]);
1874
+ var GenreSearchResultSchema = import_zod34.z.object({
1726
1875
  /** Criteria (genre) uuid. */
1727
1876
  uuid: GenreUuidSchema,
1728
- name: import_zod33.z.string(),
1877
+ name: import_zod34.z.string(),
1729
1878
  /** Null for app-created genres, which the Wikidata-keyed region index does not reference. */
1730
- wikidataId: import_zod33.z.string().nullable(),
1731
- treeName: import_zod33.z.string(),
1879
+ wikidataId: import_zod34.z.string().nullable(),
1880
+ treeName: import_zod34.z.string(),
1732
1881
  /** Null when the genre has no playlist in the tree, so it cannot be opened there. */
1733
1882
  genrePlaylistUuid: GenrePlaylistUuidSchema.nullable(),
1734
- root: import_zod33.z.object({ uuid: GenreUuidSchema, name: import_zod33.z.string() }),
1735
- isUmbrella: import_zod33.z.boolean(),
1736
- viewsCount: import_zod33.z.number().int()
1883
+ root: import_zod34.z.object({ uuid: GenreUuidSchema, name: import_zod34.z.string() }),
1884
+ isUmbrella: import_zod34.z.boolean(),
1885
+ viewsCount: import_zod34.z.number().int()
1737
1886
  });
1738
- var GenreSearchResultsSchema = import_zod33.z.array(GenreSearchResultSchema);
1739
- var RegionGenreLexiconEntrySchema = import_zod33.z.object({
1740
- wikidataId: import_zod33.z.string(),
1887
+ var GenreSearchResultsSchema = import_zod34.z.array(GenreSearchResultSchema);
1888
+ var RegionGenreLexiconEntrySchema = import_zod34.z.object({
1889
+ wikidataId: import_zod34.z.string(),
1741
1890
  uuid: GenreUuidSchema,
1742
- name: import_zod33.z.string(),
1743
- treeName: import_zod33.z.string(),
1891
+ name: import_zod34.z.string(),
1892
+ treeName: import_zod34.z.string(),
1744
1893
  genrePlaylistUuid: GenrePlaylistUuidSchema.nullable(),
1745
- isUmbrella: import_zod33.z.boolean(),
1746
- viewsCount: import_zod33.z.number().int()
1894
+ isUmbrella: import_zod34.z.boolean(),
1895
+ viewsCount: import_zod34.z.number().int()
1747
1896
  });
1748
- var RegionGenreLexiconSchema = import_zod33.z.array(RegionGenreLexiconEntrySchema);
1897
+ var RegionGenreLexiconSchema = import_zod34.z.array(RegionGenreLexiconEntrySchema);
1749
1898
 
1750
1899
  // src/genre-tree/useGenreRemoteSearch.ts
1751
1900
  var DEFAULT_RESULT_LIMIT2 = 8;
@@ -1764,6 +1913,7 @@ function useGenreRemoteSearch(getBackendBaseUrl, text, { treeName, limit = DEFAU
1764
1913
  }
1765
1914
 
1766
1915
  // src/genre-tree/useRegionGenreLexicon.ts
1916
+ var EMPTY_ENTRIES = [];
1767
1917
  function useRegionGenreLexicon(getBackendBaseUrl, enabled) {
1768
1918
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1769
1919
  const { data, isError, isPending } = useQueryWithParse({
@@ -1774,15 +1924,15 @@ function useRegionGenreLexicon(getBackendBaseUrl, enabled) {
1774
1924
  enabled,
1775
1925
  staleTime: Infinity
1776
1926
  });
1777
- const entries = data ?? [];
1927
+ const entries = data ?? EMPTY_ENTRIES;
1778
1928
  return { entries, isError, isPending: enabled && isPending };
1779
1929
  }
1780
1930
 
1781
1931
  // src/genre-tree/useGenreTreeViewState.ts
1782
- var import_react10 = require("react");
1932
+ var import_react11 = require("react");
1783
1933
 
1784
1934
  // src/genre-tree/useVisibleGenrePlaylists.ts
1785
- var import_react9 = require("react");
1935
+ var import_react10 = require("react");
1786
1936
 
1787
1937
  // src/genre-tree/lib/prune-genre-playlists-for-artist.ts
1788
1938
  var POP_ROOT_NAME = "Mainstream Pop";
@@ -1792,7 +1942,7 @@ var pruneGenrePlaylistsForArtist = (playlists, counts) => {
1792
1942
  const kept = /* @__PURE__ */ new Set();
1793
1943
  for (const playlist of playlists) {
1794
1944
  const isPopRoot = playlist.parent === null && playlist.name === POP_ROOT_NAME;
1795
- if (isPopRoot || (countByPlaylist.get(playlist.uuid)?.songsCount ?? 0) > 0) kept.add(playlist.uuid);
1945
+ if (isPopRoot || (countByPlaylist.get(playlist.uuid)?.catalogue.genreAndSubgenresTracksCount.all ?? 0) > 0) kept.add(playlist.uuid);
1796
1946
  }
1797
1947
  const coreElectronicUuids = new Set(
1798
1948
  playlists.filter((playlist) => playlist.name === CORE_ELECTRONIC_NAME && kept.has(playlist.uuid)).map((p) => p.uuid)
@@ -1800,12 +1950,22 @@ var pruneGenrePlaylistsForArtist = (playlists, counts) => {
1800
1950
  for (const playlist of playlists) {
1801
1951
  if (playlist.parent && coreElectronicUuids.has(playlist.parent.uuid)) kept.add(playlist.uuid);
1802
1952
  }
1803
- return playlists.filter((playlist) => kept.has(playlist.uuid)).map((playlist) => ({
1804
- ...playlist,
1805
- tracksCount: countByPlaylist.get(playlist.uuid)?.tracksCount ?? 0,
1806
- // Per-artist view totals are not served, so the views metric is unavailable on a pruned tree.
1807
- viewsCount: 0
1808
- }));
1953
+ return playlists.filter((playlist) => kept.has(playlist.uuid)).map((playlist) => {
1954
+ const count = countByPlaylist.get(playlist.uuid);
1955
+ const catalogue = GenreCatalogueCountsSchema.parse(playlist.catalogue);
1956
+ const scopes = playlist.genreAndSubgenresTracksCount;
1957
+ if (!scopes) throw new Error("Artist projections require a reference genre summary");
1958
+ const zero = { genreOnlyTracksCount: 0, genreAndSubgenresTracksCount: "canonical" in scopes ? { canonical: 0, regional: 0, all: 0 } : { all: 0 } };
1959
+ return {
1960
+ ...playlist,
1961
+ genreOnlyTracksCount: count?.genreOnlyTracksCount ?? 0,
1962
+ genreAndSubgenresTracksCount: count?.genreAndSubgenresTracksCount ?? zero.genreAndSubgenresTracksCount,
1963
+ catalogue: count?.catalogue ?? { ...catalogue, ...zero },
1964
+ tracksCount: count ? genreMusicCount(count) : 0,
1965
+ // Artist view totals are not served.
1966
+ viewsCount: void 0
1967
+ };
1968
+ });
1809
1969
  };
1810
1970
 
1811
1971
  // src/genre-tree/useVisibleGenrePlaylists.ts
@@ -1814,7 +1974,7 @@ function useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid = null
1814
1974
  const counts = useArtistGenreCounts(artistUuid, getBackendBaseUrl);
1815
1975
  const artistCounts = artistUuid !== null ? counts.data : void 0;
1816
1976
  const isCountsLoading = artistUuid !== null && (counts.isPending || counts.isPlaceholderData);
1817
- const genrePlaylists = (0, import_react9.useMemo)(() => {
1977
+ const genrePlaylists = (0, import_react10.useMemo)(() => {
1818
1978
  if (!tree) return [];
1819
1979
  return artistCounts ? pruneGenrePlaylistsForArtist(tree, artistCounts) : tree;
1820
1980
  }, [tree, artistCounts]);
@@ -1842,12 +2002,12 @@ function useGenreTreeViewState({
1842
2002
  onSelectedNodeIdChange,
1843
2003
  criteriaOverviewSchema
1844
2004
  }) {
1845
- const [internalViewMode, setInternalViewMode] = (0, import_react10.useState)("pop-core");
1846
- const [allowWheelRotation, setAllowWheelRotation] = (0, import_react10.useState)(false);
1847
- const [internalSelectedNodeId, setInternalSelectedNodeId] = (0, import_react10.useState)(null);
2005
+ const [internalViewMode, setInternalViewMode] = (0, import_react11.useState)("pop-core");
2006
+ const [allowWheelRotation, setAllowWheelRotation] = (0, import_react11.useState)(false);
2007
+ const [internalSelectedNodeId, setInternalSelectedNodeId] = (0, import_react11.useState)(null);
1848
2008
  const isSelectionControlled = controlledSelectedNodeId !== void 0;
1849
2009
  const requestedSelectedNodeId = isSelectionControlled ? controlledSelectedNodeId : internalSelectedNodeId;
1850
- const setSelectedNodeId = (0, import_react10.useCallback)(
2010
+ const setSelectedNodeId = (0, import_react11.useCallback)(
1851
2011
  (nodeId) => {
1852
2012
  if (!isSelectionControlled) setInternalSelectedNodeId(nodeId);
1853
2013
  onSelectedNodeIdChange?.(nodeId);
@@ -1855,35 +2015,35 @@ function useGenreTreeViewState({
1855
2015
  [isSelectionControlled, onSelectedNodeIdChange]
1856
2016
  );
1857
2017
  const { isLoading, isFetching, genrePlaylists } = useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid });
1858
- const genrePlaylistByNodeId = (0, import_react10.useMemo)(() => new Map(genrePlaylists.map((gp) => [gp.uuid, gp])), [genrePlaylists]);
1859
- const selectedGenrePlaylist = (0, import_react10.useMemo)(
2018
+ const genrePlaylistByNodeId = (0, import_react11.useMemo)(() => new Map(genrePlaylists.map((gp) => [gp.uuid, gp])), [genrePlaylists]);
2019
+ const selectedGenrePlaylist = (0, import_react11.useMemo)(
1860
2020
  () => genrePlaylists.find((gp) => gp.uuid === requestedSelectedNodeId) ?? // Older shared links stored the criteria UUID in `genre`; resolve that alias while preserving
1861
2021
  // the playlist UUID as the canonical tree selection identity.
1862
2022
  genrePlaylists.find((gp) => gp.criteria?.uuid === requestedSelectedNodeId),
1863
2023
  [genrePlaylists, requestedSelectedNodeId]
1864
2024
  );
1865
2025
  const selectedNodeId = selectedGenrePlaylist?.uuid ?? requestedSelectedNodeId;
1866
- (0, import_react10.useEffect)(() => {
2026
+ (0, import_react11.useEffect)(() => {
1867
2027
  if (!isSelectionControlled || requestedSelectedNodeId == null || selectedGenrePlaylist == null || requestedSelectedNodeId === selectedGenrePlaylist.uuid) {
1868
2028
  return;
1869
2029
  }
1870
2030
  onSelectedNodeIdChange?.(selectedGenrePlaylist.uuid);
1871
2031
  }, [isSelectionControlled, onSelectedNodeIdChange, requestedSelectedNodeId, selectedGenrePlaylist]);
1872
- const selectNode = (0, import_react10.useCallback)((node) => setSelectedNodeId(node?.id ?? null), [setSelectedNodeId]);
1873
- const clearSelection = (0, import_react10.useCallback)(() => setSelectedNodeId(null), [setSelectedNodeId]);
1874
- const selectGenrePlaylist = (0, import_react10.useCallback)(
2032
+ const selectNode = (0, import_react11.useCallback)((node) => setSelectedNodeId(node?.id ?? null), [setSelectedNodeId]);
2033
+ const clearSelection = (0, import_react11.useCallback)(() => setSelectedNodeId(null), [setSelectedNodeId]);
2034
+ const selectGenrePlaylist = (0, import_react11.useCallback)(
1875
2035
  (genrePlaylist) => setSelectedNodeId(genrePlaylist.uuid),
1876
2036
  [setSelectedNodeId]
1877
2037
  );
1878
2038
  const prefetchGenreOverview = usePrefetchGenreOverview(scope, getBackendBaseUrl, criteriaOverviewSchema);
1879
- const hoverPrefetchTimerRef = (0, import_react10.useRef)(null);
1880
- (0, import_react10.useEffect)(
2039
+ const hoverPrefetchTimerRef = (0, import_react11.useRef)(null);
2040
+ (0, import_react11.useEffect)(
1881
2041
  () => () => {
1882
2042
  if (hoverPrefetchTimerRef.current) clearTimeout(hoverPrefetchTimerRef.current);
1883
2043
  },
1884
2044
  []
1885
2045
  );
1886
- const onNodeHover = (0, import_react10.useCallback)(
2046
+ const onNodeHover = (0, import_react11.useCallback)(
1887
2047
  (node) => {
1888
2048
  if (hoverPrefetchTimerRef.current) clearTimeout(hoverPrefetchTimerRef.current);
1889
2049
  const genreUuid = genrePlaylistByNodeId.get(node.id)?.criteria?.uuid;
@@ -1894,8 +2054,8 @@ function useGenreTreeViewState({
1894
2054
  },
1895
2055
  [genrePlaylistByNodeId, prefetchGenreOverview]
1896
2056
  );
1897
- const groupedGenrePlaylistsByRoot = (0, import_react10.useMemo)(() => getGenrePlaylistsGroupedByRoot(genrePlaylists), [genrePlaylists]);
1898
- const canShowPopCore = (0, import_react10.useMemo)(
2057
+ const groupedGenrePlaylistsByRoot = (0, import_react11.useMemo)(() => getGenrePlaylistsGroupedByRoot(genrePlaylists), [genrePlaylists]);
2058
+ const canShowPopCore = (0, import_react11.useMemo)(
1899
2059
  () => hasMainstreamPopRoot(
1900
2060
  genrePlaylists.map((genrePlaylist) => ({
1901
2061
  parentId: genrePlaylist.parent?.uuid ?? null,
@@ -1904,14 +2064,14 @@ function useGenreTreeViewState({
1904
2064
  ),
1905
2065
  [genrePlaylists]
1906
2066
  );
1907
- (0, import_react10.useEffect)(() => {
2067
+ (0, import_react11.useEffect)(() => {
1908
2068
  if (!isLoading && needsPopCore(internalViewMode) && !canShowPopCore) {
1909
2069
  setInternalViewMode("wheel");
1910
2070
  }
1911
2071
  }, [isLoading, canShowPopCore, internalViewMode]);
1912
2072
  const selectedViewMode = controlledViewMode ?? internalViewMode;
1913
2073
  const viewMode = needsPopCore(selectedViewMode) && !canShowPopCore ? "wheel" : selectedViewMode;
1914
- const visibleGenrePlaylists = (0, import_react10.useMemo)(() => {
2074
+ const visibleGenrePlaylists = (0, import_react11.useMemo)(() => {
1915
2075
  if (viewMode === "stacked") return genrePlaylists;
1916
2076
  const unacceptedRootUuids = new Set(genrePlaylists.filter((gp) => gp.isUnacceptedRoot).map((gp) => gp.uuid));
1917
2077
  const accepted = genrePlaylists.filter((gp) => !gp.isUnacceptedRoot && !unacceptedRootUuids.has(gp.root.uuid));
@@ -1940,13 +2100,13 @@ function useGenreTreeViewState({
1940
2100
  }
1941
2101
 
1942
2102
  // src/genre-tree/TrackListContext.tsx
1943
- var import_react13 = require("react");
2103
+ var import_react14 = require("react");
1944
2104
 
1945
2105
  // src/genre-tree/schemas/track-playlist-rel/without-playlist.ts
1946
- var import_zod34 = require("zod");
1947
- var makeTrackPlaylistRelSchema = (trackSchema) => import_zod34.z.object({
2106
+ var import_zod35 = require("zod");
2107
+ var makeTrackPlaylistRelSchema = (trackSchema) => import_zod35.z.object({
1948
2108
  track: trackSchema,
1949
- position: import_zod34.z.number().min(0)
2109
+ position: import_zod35.z.number().min(0)
1950
2110
  });
1951
2111
  var makeTrackPlaylistRelPageSchema = (trackSchema) => PaginatedResponseSchema(makeTrackPlaylistRelSchema(trackSchema));
1952
2112
 
@@ -1995,6 +2155,7 @@ var TrackListFromArtist = class extends TrackList {
1995
2155
  var TrackListOriginType = /* @__PURE__ */ ((TrackListOriginType2) => {
1996
2156
  TrackListOriginType2["TRACK"] = "TRACK";
1997
2157
  TrackListOriginType2["GENRE_PLAYLIST"] = "GENRE_PLAYLIST";
2158
+ TrackListOriginType2["GENRE_CATALOGUE"] = "GENRE_CATALOGUE";
1998
2159
  TrackListOriginType2["ARTIST"] = "ARTIST";
1999
2160
  return TrackListOriginType2;
2000
2161
  })(TrackListOriginType || {});
@@ -2026,40 +2187,61 @@ var TrackListOriginFromTrack = class extends TrackListOrigin {
2026
2187
  };
2027
2188
  var TrackListOriginFromCriteriaPlaylist = class extends TrackListOrigin {
2028
2189
  /** `from`: the track the list starts at (server-side `?from=`), kept so later pages use it too. */
2029
- constructor(criteriaPlaylist, scope, from) {
2190
+ constructor(criteriaPlaylist, scope, from, selection, artistUuid) {
2030
2191
  super("GENRE_PLAYLIST" /* GENRE_PLAYLIST */, criteriaPlaylist.name, criteriaPlaylist.uuid, scope);
2031
2192
  this.criteriaPlaylist = criteriaPlaylist;
2032
2193
  this.from = from;
2194
+ this.selection = selection;
2195
+ this.artistUuid = artistUuid;
2033
2196
  }
2034
2197
  criteriaPlaylist;
2035
2198
  from;
2199
+ selection;
2200
+ artistUuid;
2036
2201
  };
2037
2202
  var TrackListOriginFromArtist = class extends TrackListOrigin {
2038
2203
  /** `ordering`/`from`: kept so later pages use the same order and start track. */
2039
- constructor(artist, scope, ordering, from, genreUuid) {
2204
+ constructor(artist, scope, ordering, from, genreUuid, selection) {
2040
2205
  super("ARTIST" /* ARTIST */, artist.name, artist.uuid, scope);
2041
2206
  this.artist = artist;
2042
2207
  this.ordering = ordering;
2043
2208
  this.from = from;
2044
2209
  this.genreUuid = genreUuid;
2210
+ this.selection = selection;
2045
2211
  }
2046
2212
  artist;
2047
2213
  ordering;
2048
2214
  from;
2049
2215
  genreUuid;
2216
+ selection;
2217
+ };
2218
+ var TrackListOriginFromGenreCatalogue = class extends TrackListOrigin {
2219
+ constructor(genre, scope, from, selection) {
2220
+ super("GENRE_CATALOGUE" /* GENRE_CATALOGUE */, genre.name, genre.uuid, scope);
2221
+ this.genre = genre;
2222
+ this.from = from;
2223
+ this.selection = selection;
2224
+ }
2225
+ genre;
2226
+ from;
2227
+ selection;
2228
+ ordering = "title";
2229
+ get genreUuid() {
2230
+ return this.genre.uuid;
2231
+ }
2050
2232
  };
2051
2233
 
2052
2234
  // src/player/PlayerContext.tsx
2053
- var import_react11 = require("react");
2235
+ var import_react12 = require("react");
2054
2236
 
2055
2237
  // src/player/PlaybackFailures.ts
2056
2238
  var TTL_MS = 10 * 6e4;
2057
2239
 
2058
2240
  // src/player/PlayerContext.tsx
2059
2241
  var import_jsx_runtime4 = require("react/jsx-runtime");
2060
- var PlayerContext = (0, import_react11.createContext)(void 0);
2242
+ var PlayerContext = (0, import_react12.createContext)(void 0);
2061
2243
  function usePlayer() {
2062
- const context = (0, import_react11.useContext)(PlayerContext);
2244
+ const context = (0, import_react12.useContext)(PlayerContext);
2063
2245
  if (context === void 0) {
2064
2246
  throw new Error("usePlayer must be used within a PlayerProvider");
2065
2247
  }
@@ -2067,21 +2249,21 @@ function usePlayer() {
2067
2249
  }
2068
2250
 
2069
2251
  // src/genre-tree/TrackListSidebarVisibilityContext.tsx
2070
- var import_react12 = require("react");
2252
+ var import_react13 = require("react");
2071
2253
  var import_jsx_runtime5 = require("react/jsx-runtime");
2072
- var TrackListSidebarVisibilityContext = (0, import_react12.createContext)(void 0);
2254
+ var TrackListSidebarVisibilityContext = (0, import_react13.createContext)(void 0);
2073
2255
  function TrackListSidebarVisibilityProvider({ children }) {
2074
- const [isTrackListSidebarVisible, setIsTrackListSidebarVisible] = (0, import_react12.useState)(false);
2075
- const toggleTrackListSidebar = (0, import_react12.useCallback)(() => {
2256
+ const [isTrackListSidebarVisible, setIsTrackListSidebarVisible] = (0, import_react13.useState)(false);
2257
+ const toggleTrackListSidebar = (0, import_react13.useCallback)(() => {
2076
2258
  setIsTrackListSidebarVisible((prev) => !prev);
2077
2259
  }, []);
2078
- const showTrackListSidebar = (0, import_react12.useCallback)(() => {
2260
+ const showTrackListSidebar = (0, import_react13.useCallback)(() => {
2079
2261
  setIsTrackListSidebarVisible(true);
2080
2262
  }, []);
2081
- const hideTrackListSidebar = (0, import_react12.useCallback)(() => {
2263
+ const hideTrackListSidebar = (0, import_react13.useCallback)(() => {
2082
2264
  setIsTrackListSidebarVisible(false);
2083
2265
  }, []);
2084
- const value = (0, import_react12.useMemo)(
2266
+ const value = (0, import_react13.useMemo)(
2085
2267
  () => ({
2086
2268
  isTrackListSidebarVisible,
2087
2269
  toggleTrackListSidebar,
@@ -2093,7 +2275,7 @@ function TrackListSidebarVisibilityProvider({ children }) {
2093
2275
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TrackListSidebarVisibilityContext.Provider, { value, children });
2094
2276
  }
2095
2277
  function useTrackListSidebarVisibility() {
2096
- const context = (0, import_react12.useContext)(TrackListSidebarVisibilityContext);
2278
+ const context = (0, import_react13.useContext)(TrackListSidebarVisibilityContext);
2097
2279
  if (context === void 0) {
2098
2280
  throw new Error("useTrackListSidebarVisibility must be used within a TrackListSidebarVisibilityProvider");
2099
2281
  }
@@ -2123,45 +2305,45 @@ function useListTracks(scope, getBackendBaseUrl, schema, listEndpoint, listQuery
2123
2305
  enabled: playback.ready && scope != null && (scope === "reference" || sessionRestored && !!session?.accessToken)
2124
2306
  });
2125
2307
  }
2126
- var TrackListContext = (0, import_react13.createContext)(void 0);
2308
+ var TrackListContext = (0, import_react14.createContext)(void 0);
2127
2309
  function TrackListProvider({
2128
2310
  children,
2129
2311
  getBackendBaseUrl,
2130
2312
  schema
2131
2313
  }) {
2132
- const [trackList, setTrackList] = (0, import_react13.useState)(null);
2133
- const [selectedTrack, setSelectedTrack] = (0, import_react13.useState)(null);
2134
- const [autoAdvanceScrollRequest, setAutoAdvanceScrollRequest] = (0, import_react13.useState)(null);
2314
+ const [trackList, setTrackList] = (0, import_react14.useState)(null);
2315
+ const [selectedTrack, setSelectedTrack] = (0, import_react14.useState)(null);
2316
+ const [autoAdvanceScrollRequest, setAutoAdvanceScrollRequest] = (0, import_react14.useState)(null);
2135
2317
  const { loadTrackForPlayer, setOnTrackEnd, hasPlaybackFailure, playerTrackObject } = usePlayer();
2136
- const [failureClock, setFailureClock] = (0, import_react13.useState)(0);
2137
- (0, import_react13.useEffect)(() => {
2318
+ const [failureClock, setFailureClock] = (0, import_react14.useState)(0);
2319
+ (0, import_react14.useEffect)(() => {
2138
2320
  const timer = setInterval(() => setFailureClock((tick) => tick + 1), 3e4);
2139
2321
  return () => clearInterval(timer);
2140
2322
  }, []);
2141
- const runtimeUnplayableTrackIds = (0, import_react13.useMemo)(() => new Set(
2323
+ const runtimeUnplayableTrackIds = (0, import_react14.useMemo)(() => new Set(
2142
2324
  (trackList?.tracks ?? []).filter((track) => isSong(track) && track.youtubeVideo && hasPlaybackFailure(track.youtubeVideo.id)).map((track) => track.uuid)
2143
2325
  ), [trackList, hasPlaybackFailure, playerTrackObject, failureClock]);
2144
2326
  const { showTrackListSidebar } = useTrackListSidebarVisibility();
2145
2327
  const playback = usePlaybackContext();
2146
2328
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2147
- const pageSchema = (0, import_react13.useMemo)(() => makeTrackPlaylistRelPageSchema(schema), [schema]);
2148
- const latestPlayRequestRef = (0, import_react13.useRef)(0);
2149
- const startingPlaybackRef = (0, import_react13.useRef)(false);
2150
- const loadedContextRef = (0, import_react13.useRef)(playback.key);
2151
- const autoAdvanceScrollRequestIdRef = (0, import_react13.useRef)(0);
2152
- const delayedTrackLoadRef = (0, import_react13.useRef)(null);
2153
- const loadingOriginRef = (0, import_react13.useRef)(null);
2154
- const pendingAdvanceRef = (0, import_react13.useRef)(null);
2155
- const clearDelayedTrackLoad = (0, import_react13.useCallback)(() => {
2329
+ const pageSchema = (0, import_react14.useMemo)(() => makeTrackPlaylistRelPageSchema(schema), [schema]);
2330
+ const latestPlayRequestRef = (0, import_react14.useRef)(0);
2331
+ const startingPlaybackRef = (0, import_react14.useRef)(false);
2332
+ const loadedContextRef = (0, import_react14.useRef)(playback.key);
2333
+ const autoAdvanceScrollRequestIdRef = (0, import_react14.useRef)(0);
2334
+ const delayedTrackLoadRef = (0, import_react14.useRef)(null);
2335
+ const loadingOriginRef = (0, import_react14.useRef)(null);
2336
+ const pendingAdvanceRef = (0, import_react14.useRef)(null);
2337
+ const clearDelayedTrackLoad = (0, import_react14.useCallback)(() => {
2156
2338
  if (delayedTrackLoadRef.current !== null) {
2157
2339
  clearTimeout(delayedTrackLoadRef.current);
2158
2340
  delayedTrackLoadRef.current = null;
2159
2341
  }
2160
2342
  }, []);
2161
- const requestAutoAdvanceScroll = (0, import_react13.useCallback)((trackUuid) => {
2343
+ const requestAutoAdvanceScroll = (0, import_react14.useCallback)((trackUuid) => {
2162
2344
  setAutoAdvanceScrollRequest({ id: ++autoAdvanceScrollRequestIdRef.current, trackUuid });
2163
2345
  }, []);
2164
- const loadTrackAfterSkipDelay = (0, import_react13.useCallback)(
2346
+ const loadTrackAfterSkipDelay = (0, import_react14.useCallback)(
2165
2347
  (trackUuid) => {
2166
2348
  clearDelayedTrackLoad();
2167
2349
  delayedTrackLoadRef.current = setTimeout(() => {
@@ -2171,10 +2353,11 @@ function TrackListProvider({
2171
2353
  },
2172
2354
  [clearDelayedTrackLoad, loadTrackForPlayer]
2173
2355
  );
2174
- const fetchTracksPage = (0, import_react13.useCallback)(
2175
- async (uuid, scope, page, from) => {
2356
+ const fetchTracksPage = (0, import_react14.useCallback)(
2357
+ async (uuid, scope, page, from, selection, artistUuid) => {
2176
2358
  const endpoint = genrePlaylistEndpoints[scope].tracks(uuid);
2177
- const params = { page, pageSize: TRACKS_PAGE_SIZE, ...from && { from } };
2359
+ if (scope === "me" && (selection || artistUuid)) throw new Error("Genre selections require reference scope");
2360
+ const params = { page, pageSize: TRACKS_PAGE_SIZE, ...from && { from }, ...genreMusicQueryParams(selection), ...artistUuid && { artist: artistUuid } };
2178
2361
  const response = await fetch2(endpoint, true, scope === "me", {}, params, false, !!from, page === 1);
2179
2362
  const parsed = parseWithLog(pageSchema, response, "fetchGenrePlaylistTracksPage");
2180
2363
  return {
@@ -2185,17 +2368,18 @@ function TrackListProvider({
2185
2368
  },
2186
2369
  [fetch2, pageSchema]
2187
2370
  );
2188
- const artistPageSchema = (0, import_react13.useMemo)(() => PaginatedResponseSchema(schema), [schema]);
2189
- const fetchArtistTracksPage = (0, import_react13.useCallback)(
2371
+ const cataloguePageSchema = (0, import_react14.useMemo)(() => PaginatedResponseSchema(schema), [schema]);
2372
+ const fetchCatalogueTracksPage = (0, import_react14.useCallback)(
2190
2373
  async (origin, page) => {
2191
2374
  const params = {
2192
- artist: origin.uuid,
2375
+ ...origin instanceof TrackListOriginFromArtist && { artist: origin.uuid },
2193
2376
  playable: true,
2194
2377
  ordering: origin.ordering,
2195
2378
  page,
2196
2379
  pageSize: TRACKS_PAGE_SIZE,
2197
2380
  ...origin.from && { from: origin.from },
2198
- ...origin.genreUuid && { genre: origin.genreUuid }
2381
+ ...origin.genreUuid && { genre: origin.genreUuid },
2382
+ ...genreMusicQueryParams(origin.selection)
2199
2383
  };
2200
2384
  const response = await fetch2(
2201
2385
  libraryEndpoints.reference.songs.list(),
@@ -2208,12 +2392,12 @@ function TrackListProvider({
2208
2392
  page === 1 && !!origin.from,
2209
2393
  page === 1
2210
2394
  );
2211
- const parsed = parseWithLog(artistPageSchema, response, "fetchArtistTracksPage");
2395
+ const parsed = parseWithLog(cataloguePageSchema, response, "fetchCatalogueTracksPage");
2212
2396
  return { tracks: parsed.results, total: parsed.overallTotal, nextPage: parsed.next ? parsed.page + 1 : null };
2213
2397
  },
2214
- [fetch2, artistPageSchema]
2398
+ [fetch2, cataloguePageSchema]
2215
2399
  );
2216
- const advanceAfterTrackEnd = (0, import_react13.useCallback)(
2400
+ const advanceAfterTrackEnd = (0, import_react14.useCallback)(
2217
2401
  (event) => {
2218
2402
  const completedTrackId = event?.trackId ?? selectedTrack?.uuid;
2219
2403
  if (!completedTrackId || !trackList) return;
@@ -2245,11 +2429,11 @@ function TrackListProvider({
2245
2429
  selectedTrack
2246
2430
  ]
2247
2431
  );
2248
- (0, import_react13.useEffect)(() => {
2432
+ (0, import_react14.useEffect)(() => {
2249
2433
  setOnTrackEnd(trackList && selectedTrack ? advanceAfterTrackEnd : null);
2250
2434
  return () => setOnTrackEnd(null);
2251
2435
  }, [advanceAfterTrackEnd, trackList, selectedTrack, setOnTrackEnd]);
2252
- const toTrackAtPosition = (0, import_react13.useCallback)(
2436
+ const toTrackAtPosition = (0, import_react14.useCallback)(
2253
2437
  (position) => {
2254
2438
  if (trackList && position >= 0 && position < trackList.tracks.length) {
2255
2439
  clearDelayedTrackLoad();
@@ -2259,7 +2443,7 @@ function TrackListProvider({
2259
2443
  },
2260
2444
  [clearDelayedTrackLoad, trackList]
2261
2445
  );
2262
- const playNewTrackListFromTrackUuid = (0, import_react13.useCallback)(
2446
+ const playNewTrackListFromTrackUuid = (0, import_react14.useCallback)(
2263
2447
  (track, scope) => {
2264
2448
  latestPlayRequestRef.current++;
2265
2449
  startingPlaybackRef.current = false;
@@ -2275,7 +2459,7 @@ function TrackListProvider({
2275
2459
  },
2276
2460
  [clearDelayedTrackLoad, showTrackListSidebar, loadTrackForPlayer]
2277
2461
  );
2278
- const playNewTrackListFromGenrePlaylist = (0, import_react13.useCallback)(
2462
+ const playNewTrackListFromGenrePlaylist = (0, import_react14.useCallback)(
2279
2463
  async (genrePlaylist, scope, options) => {
2280
2464
  clearDelayedTrackLoad();
2281
2465
  const request = ++latestPlayRequestRef.current;
@@ -2283,7 +2467,7 @@ function TrackListProvider({
2283
2467
  const from = options?.startSongUuid;
2284
2468
  let page;
2285
2469
  try {
2286
- page = await fetchTracksPage(genrePlaylist.uuid, scope, 1, from);
2470
+ page = await fetchTracksPage(genrePlaylist.uuid, scope, 1, from, options?.selection, options?.artistUuid);
2287
2471
  } catch (error) {
2288
2472
  if (request !== latestPlayRequestRef.current) return;
2289
2473
  startingPlaybackRef.current = false;
@@ -2300,7 +2484,7 @@ function TrackListProvider({
2300
2484
  console.warn("No playable tracks found in genre playlist");
2301
2485
  return;
2302
2486
  }
2303
- const origin = new TrackListOriginFromCriteriaPlaylist(genrePlaylist, scope, from);
2487
+ const origin = new TrackListOriginFromCriteriaPlaylist(genrePlaylist, scope, from, options?.selection, options?.artistUuid);
2304
2488
  setAutoAdvanceScrollRequest(null);
2305
2489
  setTrackList(new TrackListFromCriteriaPlaylist(page.tracks, origin, page.total, page.nextPage));
2306
2490
  setSelectedTrack(startTrack);
@@ -2309,17 +2493,15 @@ function TrackListProvider({
2309
2493
  },
2310
2494
  [clearDelayedTrackLoad, fetchTracksPage, showTrackListSidebar, loadTrackForPlayer]
2311
2495
  );
2312
- const playNewTrackListFromArtist = (0, import_react13.useCallback)(
2313
- async (artist, scope, options) => {
2314
- if (scope !== "reference") throw new Error("Artist track lists only support the reference scope");
2496
+ const playCatalogue = (0, import_react14.useCallback)(
2497
+ async (origin) => {
2315
2498
  clearDelayedTrackLoad();
2316
2499
  const request = ++latestPlayRequestRef.current;
2317
2500
  startingPlaybackRef.current = true;
2318
- const from = options.startSongUuid;
2319
- const origin = new TrackListOriginFromArtist(artist, scope, options.ordering, from, options.genreUuid);
2501
+ const from = origin.from;
2320
2502
  let page;
2321
2503
  try {
2322
- page = await fetchArtistTracksPage(origin, 1);
2504
+ page = await fetchCatalogueTracksPage(origin, 1);
2323
2505
  } catch (error) {
2324
2506
  if (request !== latestPlayRequestRef.current) return;
2325
2507
  startingPlaybackRef.current = false;
@@ -2330,22 +2512,37 @@ function TrackListProvider({
2330
2512
  loadedContextRef.current = playback.snapshot().key;
2331
2513
  const startTrack = page.tracks[0];
2332
2514
  if (from && startTrack?.uuid !== from) {
2333
- throw new Error(`Artist ${artist.uuid} did not start at song ${from}`);
2515
+ throw new Error(`${origin instanceof TrackListOriginFromArtist ? "Artist" : "Catalogue"} ${origin.uuid} did not start at song ${from}`);
2334
2516
  }
2335
2517
  if (!startTrack) {
2336
- console.warn("No playable songs found for artist");
2518
+ console.warn("No playable songs found in catalogue");
2337
2519
  return;
2338
2520
  }
2339
- setTrackList(new TrackListFromArtist(page.tracks, origin, page.total, page.nextPage));
2521
+ setTrackList(origin instanceof TrackListOriginFromArtist ? new TrackListFromArtist(page.tracks, origin, page.total, page.nextPage) : new TrackList(page.tracks, origin, page.total, page.nextPage));
2340
2522
  setAutoAdvanceScrollRequest(null);
2341
2523
  setSelectedTrack(startTrack);
2342
2524
  showTrackListSidebar();
2343
2525
  loadTrackForPlayer(startTrack.uuid);
2344
2526
  },
2345
- [clearDelayedTrackLoad, fetchArtistTracksPage, showTrackListSidebar, loadTrackForPlayer]
2527
+ [clearDelayedTrackLoad, fetchCatalogueTracksPage, showTrackListSidebar, loadTrackForPlayer]
2346
2528
  );
2347
- const contextKeyRef = (0, import_react13.useRef)(playback.key);
2348
- (0, import_react13.useEffect)(() => {
2529
+ const playNewTrackListFromArtist = (0, import_react14.useCallback)(
2530
+ async (artist, scope, options) => {
2531
+ if (scope !== "reference") throw new Error("Artist track lists only support the reference scope");
2532
+ if (options.selection && !options.genreUuid) throw new Error("A genre selection requires a genre");
2533
+ return playCatalogue(new TrackListOriginFromArtist(artist, scope, options.ordering, options.startSongUuid, options.genreUuid, options.selection));
2534
+ },
2535
+ [playCatalogue]
2536
+ );
2537
+ const playNewTrackListFromGenreCatalogue = (0, import_react14.useCallback)(
2538
+ async (genre, scope, options) => {
2539
+ if (scope !== "reference") throw new Error("Genre catalogues only support the reference scope");
2540
+ return playCatalogue(new TrackListOriginFromGenreCatalogue(genre, scope, options?.startSongUuid, options?.selection));
2541
+ },
2542
+ [playCatalogue]
2543
+ );
2544
+ const contextKeyRef = (0, import_react14.useRef)(playback.key);
2545
+ (0, import_react14.useEffect)(() => {
2349
2546
  if (contextKeyRef.current === playback.key) return;
2350
2547
  contextKeyRef.current = playback.key;
2351
2548
  if (loadedContextRef.current === playback.key) return;
@@ -2364,20 +2561,28 @@ function TrackListProvider({
2364
2561
  setTrackList(null);
2365
2562
  setSelectedTrack(null);
2366
2563
  if (origin instanceof TrackListOriginFromCriteriaPlaylist) {
2367
- void playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope, { startSongUuid: selected?.uuid }).catch((error) => {
2564
+ void playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope, { startSongUuid: selected?.uuid, selection: origin.selection, artistUuid: origin.artistUuid }).catch((error) => {
2368
2565
  if (error instanceof BackendError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */) {
2369
- return playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope).catch(() => {
2566
+ return playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope, { selection: origin.selection, artistUuid: origin.artistUuid }).catch(() => {
2370
2567
  });
2371
2568
  }
2372
2569
  });
2373
2570
  } else if (origin instanceof TrackListOriginFromArtist) {
2374
- const options = { ordering: origin.ordering, genreUuid: origin.genreUuid };
2571
+ const options = { ordering: origin.ordering, genreUuid: origin.genreUuid, selection: origin.selection };
2375
2572
  void playNewTrackListFromArtist(origin.artist, origin.scope, { ...options, startSongUuid: selected?.uuid }).catch((error) => {
2376
2573
  if (error instanceof BackendError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */) {
2377
2574
  return playNewTrackListFromArtist(origin.artist, origin.scope, options).catch(() => {
2378
2575
  });
2379
2576
  }
2380
2577
  });
2578
+ } else if (origin instanceof TrackListOriginFromGenreCatalogue) {
2579
+ const options = { selection: origin.selection };
2580
+ void playNewTrackListFromGenreCatalogue(origin.genre, origin.scope, { ...options, startSongUuid: selected?.uuid }).catch((error) => {
2581
+ if (error instanceof BackendError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */) {
2582
+ return playNewTrackListFromGenreCatalogue(origin.genre, origin.scope, options).catch(() => {
2583
+ });
2584
+ }
2585
+ });
2381
2586
  } else if (origin instanceof TrackListOriginFromTrack && selected) {
2382
2587
  const request = latestPlayRequestRef.current;
2383
2588
  void (async () => {
@@ -2388,8 +2593,8 @@ function TrackListProvider({
2388
2593
  })().catch(() => {
2389
2594
  });
2390
2595
  }
2391
- }, [playback.key, trackList, selectedTrack, clearDelayedTrackLoad, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist, schema, fetch2]);
2392
- const updateTrack = (0, import_react13.useCallback)((track) => {
2596
+ }, [playback.key, trackList, selectedTrack, clearDelayedTrackLoad, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist, playNewTrackListFromGenreCatalogue, schema, fetch2]);
2597
+ const updateTrack = (0, import_react14.useCallback)((track) => {
2393
2598
  setTrackList((prev) => {
2394
2599
  if (!prev || !prev.tracks.some((listed) => listed.uuid === track.uuid)) return prev;
2395
2600
  const tracks = prev.tracks.map((listed) => listed.uuid === track.uuid ? track : listed);
@@ -2397,31 +2602,31 @@ function TrackListProvider({
2397
2602
  });
2398
2603
  setSelectedTrack((prev) => prev?.uuid === track.uuid ? track : prev);
2399
2604
  }, []);
2400
- const loadMore = (0, import_react13.useCallback)(async () => {
2605
+ const loadMore = (0, import_react14.useCallback)(async () => {
2401
2606
  if (!trackList || trackList.nextPage === null) return;
2402
2607
  const origin = trackList.origin;
2403
- if (!(origin instanceof TrackListOriginFromCriteriaPlaylist || origin instanceof TrackListOriginFromArtist)) return;
2608
+ if (!(origin instanceof TrackListOriginFromCriteriaPlaylist || origin instanceof TrackListOriginFromArtist || origin instanceof TrackListOriginFromGenreCatalogue)) return;
2404
2609
  if (loadingOriginRef.current === origin) return;
2405
2610
  const requestedPage = trackList.nextPage;
2406
2611
  loadingOriginRef.current = origin;
2407
2612
  try {
2408
- const page = origin instanceof TrackListOriginFromArtist ? await fetchArtistTracksPage(origin, requestedPage) : await fetchTracksPage(origin.criteriaPlaylist.uuid, origin.scope, requestedPage, origin.from);
2613
+ const page = origin instanceof TrackListOriginFromArtist || origin instanceof TrackListOriginFromGenreCatalogue ? await fetchCatalogueTracksPage(origin, requestedPage) : await fetchTracksPage(origin.criteriaPlaylist.uuid, origin.scope, requestedPage, origin.from, origin.selection, origin.artistUuid);
2409
2614
  setTrackList((prev) => {
2410
2615
  if (prev?.origin !== origin || prev.nextPage !== requestedPage) return prev;
2411
2616
  const loaded = new Set(prev.tracks.map((track) => track.uuid));
2412
2617
  const tracks = [...prev.tracks, ...page.tracks.filter((track) => !loaded.has(track.uuid))];
2413
- return origin instanceof TrackListOriginFromArtist ? new TrackListFromArtist(tracks, origin, page.total, page.nextPage) : new TrackListFromCriteriaPlaylist(tracks, origin, page.total, page.nextPage);
2618
+ return origin instanceof TrackListOriginFromArtist ? new TrackListFromArtist(tracks, origin, page.total, page.nextPage) : origin instanceof TrackListOriginFromGenreCatalogue ? new TrackList(tracks, origin, page.total, page.nextPage) : new TrackListFromCriteriaPlaylist(tracks, origin, page.total, page.nextPage);
2414
2619
  });
2415
2620
  } finally {
2416
2621
  if (loadingOriginRef.current === origin) loadingOriginRef.current = null;
2417
2622
  }
2418
- }, [trackList, fetchTracksPage, fetchArtistTracksPage]);
2623
+ }, [trackList, fetchTracksPage, fetchCatalogueTracksPage]);
2419
2624
  const selectedTrackIndex = trackList?.tracks.findIndex((track) => track.uuid === selectedTrack?.uuid) ?? -1;
2420
2625
  const nextTrack = trackList && selectedTrackIndex >= 0 ? trackList.tracks.slice(selectedTrackIndex + 1).find((track) => isTrackPlayable(track, runtimeUnplayableTrackIds, hasPlaybackFailure)) ?? null : null;
2421
2626
  const previousTrack = trackList && selectedTrackIndex > 0 ? trackList.tracks.slice(0, selectedTrackIndex).reverse().find((track) => isTrackPlayable(track, runtimeUnplayableTrackIds, hasPlaybackFailure)) ?? null : null;
2422
2627
  const hasNextTrack = nextTrack !== null || selectedTrackIndex >= 0 && trackList?.nextPage != null;
2423
2628
  const hasPreviousTrack = previousTrack !== null;
2424
- const playNextTrack = (0, import_react13.useCallback)(() => {
2629
+ const playNextTrack = (0, import_react14.useCallback)(() => {
2425
2630
  if (!trackList || !selectedTrack || selectedTrackIndex < 0) return;
2426
2631
  clearDelayedTrackLoad();
2427
2632
  if (nextTrack) {
@@ -2438,7 +2643,7 @@ function TrackListProvider({
2438
2643
  console.error("Failed to load more tracks:", error);
2439
2644
  });
2440
2645
  }, [clearDelayedTrackLoad, trackList, loadMore, loadTrackForPlayer, nextTrack, selectedTrack, selectedTrackIndex]);
2441
- const playPreviousTrack = (0, import_react13.useCallback)(() => {
2646
+ const playPreviousTrack = (0, import_react14.useCallback)(() => {
2442
2647
  if (!previousTrack) return;
2443
2648
  clearDelayedTrackLoad();
2444
2649
  pendingAdvanceRef.current = null;
@@ -2446,7 +2651,7 @@ function TrackListProvider({
2446
2651
  setSelectedTrack(previousTrack);
2447
2652
  loadTrackForPlayer(previousTrack.uuid);
2448
2653
  }, [clearDelayedTrackLoad, loadTrackForPlayer, previousTrack, requestAutoAdvanceScroll]);
2449
- (0, import_react13.useEffect)(() => {
2654
+ (0, import_react14.useEffect)(() => {
2450
2655
  const pending = pendingAdvanceRef.current;
2451
2656
  if (!pending) return;
2452
2657
  if (!trackList || trackList.origin !== pending.origin || selectedTrack?.uuid !== pending.trackId) {
@@ -2480,15 +2685,15 @@ function TrackListProvider({
2480
2685
  hasPlaybackFailure,
2481
2686
  selectedTrack
2482
2687
  ]);
2483
- (0, import_react13.useEffect)(() => clearDelayedTrackLoad, [clearDelayedTrackLoad]);
2484
- (0, import_react13.useEffect)(() => {
2688
+ (0, import_react14.useEffect)(() => clearDelayedTrackLoad, [clearDelayedTrackLoad]);
2689
+ (0, import_react14.useEffect)(() => {
2485
2690
  if (!trackList || trackList.nextPage === null || !selectedTrack) return;
2486
2691
  const index = trackList.tracks.findIndex((track) => track.uuid === selectedTrack.uuid);
2487
2692
  if (index !== -1 && trackList.tracks.length - index <= AUTO_LOAD_REMAINING_TRACKS) {
2488
2693
  loadMore().catch((error) => console.error("Failed to load more tracks:", error));
2489
2694
  }
2490
2695
  }, [trackList, selectedTrack, loadMore]);
2491
- const value = (0, import_react13.useMemo)(
2696
+ const value = (0, import_react14.useMemo)(
2492
2697
  () => ({
2493
2698
  trackList,
2494
2699
  selectedTrack,
@@ -2503,6 +2708,7 @@ function TrackListProvider({
2503
2708
  playNewTrackListFromTrackUuid,
2504
2709
  playNewTrackListFromGenrePlaylist,
2505
2710
  playNewTrackListFromArtist,
2711
+ playNewTrackListFromGenreCatalogue,
2506
2712
  fetchGenrePlaylistTracksPage: fetchTracksPage,
2507
2713
  loadMore,
2508
2714
  updateTrack
@@ -2520,6 +2726,7 @@ function TrackListProvider({
2520
2726
  playNewTrackListFromTrackUuid,
2521
2727
  playNewTrackListFromGenrePlaylist,
2522
2728
  playNewTrackListFromArtist,
2729
+ playNewTrackListFromGenreCatalogue,
2523
2730
  fetchTracksPage,
2524
2731
  loadMore,
2525
2732
  updateTrack
@@ -2528,7 +2735,7 @@ function TrackListProvider({
2528
2735
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TrackListContext.Provider, { value, children });
2529
2736
  }
2530
2737
  function useTrackList() {
2531
- const context = (0, import_react13.useContext)(TrackListContext);
2738
+ const context = (0, import_react14.useContext)(TrackListContext);
2532
2739
  if (!context) {
2533
2740
  throw new Error("useTrackList must be used within a TrackListProvider");
2534
2741
  }
@@ -2536,38 +2743,38 @@ function useTrackList() {
2536
2743
  }
2537
2744
 
2538
2745
  // src/genre-tree/ArtistNames.tsx
2539
- var import_react14 = require("react");
2746
+ var import_react15 = require("react");
2540
2747
  var import_jsx_runtime7 = require("react/jsx-runtime");
2541
2748
  function ArtistNames({
2542
2749
  artists,
2543
2750
  renderArtistLink
2544
2751
  }) {
2545
2752
  if (!renderArtistLink) return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: artists.map((artist) => artist.name).join(", ") });
2546
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: artists.map((artist, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react14.Fragment, { children: [
2753
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: artists.map((artist, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react15.Fragment, { children: [
2547
2754
  index > 0 && ", ",
2548
2755
  renderArtistLink(artist)
2549
2756
  ] }, artist.uuid)) });
2550
2757
  }
2551
2758
 
2552
2759
  // src/genre-tree/schemas/mb-artist.ts
2553
- var import_zod35 = require("zod");
2554
- var MbArtistDetailedSchema = import_zod35.z.object({
2555
- musicbrainzId: import_zod35.z.string().uuid(),
2556
- name: import_zod35.z.string(),
2760
+ var import_zod36 = require("zod");
2761
+ var MbArtistDetailedSchema = import_zod36.z.object({
2762
+ musicbrainzId: import_zod36.z.string().uuid(),
2763
+ name: import_zod36.z.string(),
2557
2764
  musicbrainzLink: HttpUrlSchema
2558
2765
  });
2559
2766
 
2560
2767
  // src/genre-tree/schemas/mb-recording.ts
2561
- var import_zod36 = require("zod");
2562
- var MbRecordingDetailedSchema = import_zod36.z.object({
2563
- musicbrainzId: import_zod36.z.string().uuid(),
2564
- title: import_zod36.z.string(),
2565
- score: import_zod36.z.number(),
2566
- musicbrainzArtists: import_zod36.z.array(MbArtistDetailedSchema),
2768
+ var import_zod37 = require("zod");
2769
+ var MbRecordingDetailedSchema = import_zod37.z.object({
2770
+ musicbrainzId: import_zod37.z.string().uuid(),
2771
+ title: import_zod37.z.string(),
2772
+ score: import_zod37.z.number(),
2773
+ musicbrainzArtists: import_zod37.z.array(MbArtistDetailedSchema),
2567
2774
  musicbrainzLink: HttpUrlSchema,
2568
- durationInSec: import_zod36.z.number().min(0).nullable().optional(),
2569
- durationStrInHourMinSec: import_zod36.z.string().nullable().optional(),
2570
- releaseDate: import_zod36.z.union([import_zod36.z.string().datetime(), import_zod36.z.string()]).transform((val) => {
2775
+ durationInSec: import_zod37.z.number().min(0).nullable().optional(),
2776
+ durationStrInHourMinSec: import_zod37.z.string().nullable().optional(),
2777
+ releaseDate: import_zod37.z.union([import_zod37.z.string().datetime(), import_zod37.z.string()]).transform((val) => {
2571
2778
  try {
2572
2779
  const date = new Date(val);
2573
2780
  if (isNaN(date.getTime())) {
@@ -2597,6 +2804,9 @@ var capitalizeFirstLetter = (string) => {
2597
2804
  return string.charAt(0).toUpperCase() + string.slice(1);
2598
2805
  };
2599
2806
 
2807
+ // src/genre-tree/lib/genre-search.ts
2808
+ var searchGenrePlaylistsByName = (genrePlaylists, query) => rankByName(genrePlaylists, query, (genrePlaylist) => genrePlaylist.name, (genrePlaylist) => genrePlaylist.viewsCount ?? 0);
2809
+
2600
2810
  // src/genre-tree/lib/reparent-candidates.ts
2601
2811
  var hasCriteria = (genrePlaylist) => genrePlaylist.criteria !== null;
2602
2812
  var getReparentCandidates = (genrePlaylists, genrePlaylistUuid) => {
@@ -2655,6 +2865,10 @@ function editGenreSongPages(data, edit) {
2655
2865
  CriteriaUpdateSchema,
2656
2866
  FORM_RATING_NULL_VALUE,
2657
2867
  FUZZY_MIN_SIMILARITY,
2868
+ GenreCatalogueCountsSchema,
2869
+ GenreCountsSchema,
2870
+ GenreCoverageSchema,
2871
+ GenrePlaylistSummarySchema,
2658
2872
  GenrePlaylistUuidSchema,
2659
2873
  GenreSearchResultSchema,
2660
2874
  GenreSearchResultsSchema,
@@ -2663,6 +2877,8 @@ function editGenreSongPages(data, edit) {
2663
2877
  MbArtistDetailedSchema,
2664
2878
  MbRecordingDetailedSchema,
2665
2879
  NO_VIDEO_LABEL,
2880
+ ReferenceGenreDetailedSchema,
2881
+ ReferenceGenrePlaylistSchema,
2666
2882
  RegionGenreLexiconEntrySchema,
2667
2883
  RegionGenreLexiconSchema,
2668
2884
  SEARCH_DEBOUNCE_MS,
@@ -2672,6 +2888,8 @@ function editGenreSongPages(data, edit) {
2672
2888
  SongHistorySchema,
2673
2889
  SongSearchResultSchema,
2674
2890
  SongSearchResultsSchema,
2891
+ SubgenreCountsSchema,
2892
+ SubgenreScopeSchema,
2675
2893
  TrackBaseSchema,
2676
2894
  TrackList,
2677
2895
  TrackListFromArtist,
@@ -2680,6 +2898,7 @@ function editGenreSongPages(data, edit) {
2680
2898
  TrackListOrigin,
2681
2899
  TrackListOriginFromArtist,
2682
2900
  TrackListOriginFromCriteriaPlaylist,
2901
+ TrackListOriginFromGenreCatalogue,
2683
2902
  TrackListOriginFromTrack,
2684
2903
  TrackListOriginType,
2685
2904
  TrackListProvider,
@@ -2691,12 +2910,18 @@ function editGenreSongPages(data, edit) {
2691
2910
  artistEndpoints,
2692
2911
  artistQueryKeys,
2693
2912
  capitalizeFirstLetter,
2913
+ createNameIndex,
2914
+ defaultGenreMusicSelection,
2694
2915
  editGenreSongPages,
2695
2916
  foldSearchText,
2696
2917
  formatTime,
2697
2918
  genreEndpoints,
2919
+ genreMusicCount,
2920
+ genreMusicQueryParams,
2921
+ genreMusicSelectionKey,
2698
2922
  genrePlaylistEndpoints,
2699
2923
  genrePlaylistQueryKeys,
2924
+ genrePlaylistTrackCount,
2700
2925
  genreQueryKeys,
2701
2926
  genreSearchQueryKeys,
2702
2927
  genreUpdateMutationKey,
@@ -2712,6 +2937,7 @@ function editGenreSongPages(data, edit) {
2712
2937
  musicBrainzRecordingUrl,
2713
2938
  pruneGenrePlaylistsForArtist,
2714
2939
  rankByName,
2940
+ rankNameIndex,
2715
2941
  searchGenrePlaylistsByName,
2716
2942
  songUnplayableReason,
2717
2943
  trigramSimilarity,