@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.
package/dist/index.cjs CHANGED
@@ -56,6 +56,10 @@ __export(src_exports, {
56
56
  FORM_RATING_NULL_VALUE: () => FORM_RATING_NULL_VALUE,
57
57
  FUZZY_MIN_SIMILARITY: () => FUZZY_MIN_SIMILARITY,
58
58
  GOOGLE_EXCHANGE_CONFIG: () => GOOGLE_EXCHANGE_CONFIG,
59
+ GenreCatalogueCountsSchema: () => GenreCatalogueCountsSchema,
60
+ GenreCountsSchema: () => GenreCountsSchema,
61
+ GenreCoverageSchema: () => GenreCoverageSchema,
62
+ GenrePlaylistSummarySchema: () => GenrePlaylistSummarySchema,
59
63
  GenrePlaylistUuidSchema: () => GenrePlaylistUuidSchema,
60
64
  GenreSearchResultSchema: () => GenreSearchResultSchema,
61
65
  GenreSearchResultsSchema: () => GenreSearchResultsSchema,
@@ -73,6 +77,8 @@ __export(src_exports, {
73
77
  PlayerProvider: () => PlayerProvider,
74
78
  PlayerVideoSurface: () => PlayerVideoSurface,
75
79
  PopupProvider: () => PopupProvider,
80
+ ReferenceGenreDetailedSchema: () => ReferenceGenreDetailedSchema,
81
+ ReferenceGenrePlaylistSchema: () => ReferenceGenrePlaylistSchema,
76
82
  RegionGenreLexiconEntrySchema: () => RegionGenreLexiconEntrySchema,
77
83
  RegionGenreLexiconSchema: () => RegionGenreLexiconSchema,
78
84
  SEARCH_DEBOUNCE_MS: () => SEARCH_DEBOUNCE_MS,
@@ -85,6 +91,8 @@ __export(src_exports, {
85
91
  SongHistorySchema: () => SongHistorySchema,
86
92
  SongSearchResultSchema: () => SongSearchResultSchema,
87
93
  SongSearchResultsSchema: () => SongSearchResultsSchema,
94
+ SubgenreCountsSchema: () => SubgenreCountsSchema,
95
+ SubgenreScopeSchema: () => SubgenreScopeSchema,
88
96
  TrackBaseSchema: () => TrackBaseSchema,
89
97
  TrackList: () => TrackList,
90
98
  TrackListFromArtist: () => TrackListFromArtist,
@@ -93,6 +101,7 @@ __export(src_exports, {
93
101
  TrackListOrigin: () => TrackListOrigin,
94
102
  TrackListOriginFromArtist: () => TrackListOriginFromArtist,
95
103
  TrackListOriginFromCriteriaPlaylist: () => TrackListOriginFromCriteriaPlaylist,
104
+ TrackListOriginFromGenreCatalogue: () => TrackListOriginFromGenreCatalogue,
96
105
  TrackListOriginFromTrack: () => TrackListOriginFromTrack,
97
106
  TrackListOriginType: () => TrackListOriginType,
98
107
  TrackListProvider: () => TrackListProvider,
@@ -114,15 +123,21 @@ __export(src_exports, {
114
123
  createAppErrorFromErrorCode: () => createAppErrorFromErrorCode,
115
124
  createAppErrorFromResult: () => createAppErrorFromResult,
116
125
  createLogout: () => createLogout,
126
+ createNameIndex: () => createNameIndex,
117
127
  createNetworkOrBackendError: () => createNetworkOrBackendError,
128
+ defaultGenreMusicSelection: () => defaultGenreMusicSelection,
118
129
  editGenreSongPages: () => editGenreSongPages,
119
130
  exchangeCodeWithBackend: () => exchangeCodeWithBackend,
120
131
  fetchWrapper: () => fetchWrapper,
121
132
  foldSearchText: () => foldSearchText,
122
133
  formatTime: () => formatTime,
123
134
  genreEndpoints: () => genreEndpoints,
135
+ genreMusicCount: () => genreMusicCount,
136
+ genreMusicQueryParams: () => genreMusicQueryParams,
137
+ genreMusicSelectionKey: () => genreMusicSelectionKey,
124
138
  genrePlaylistEndpoints: () => genrePlaylistEndpoints,
125
139
  genrePlaylistQueryKeys: () => genrePlaylistQueryKeys,
140
+ genrePlaylistTrackCount: () => genrePlaylistTrackCount,
126
141
  genreQueryKeys: () => genreQueryKeys,
127
142
  genreSearchQueryKeys: () => genreSearchQueryKeys,
128
143
  genreUpdateMutationKey: () => genreUpdateMutationKey,
@@ -143,6 +158,7 @@ __export(src_exports, {
143
158
  pruneGenrePlaylistsForArtist: () => pruneGenrePlaylistsForArtist,
144
159
  queryClient: () => queryClient,
145
160
  rankByName: () => rankByName,
161
+ rankNameIndex: () => rankNameIndex,
146
162
  resolveRedirectUri: () => resolveRedirectUri,
147
163
  searchGenrePlaylistsByName: () => searchGenrePlaylistsByName,
148
164
  setSpotifyRequiredCached: () => setSpotifyRequiredCached,
@@ -1980,56 +1996,159 @@ function useCurrentTime() {
1980
1996
  }
1981
1997
 
1982
1998
  // src/genre-tree/useGenre.ts
1983
- var import_zod23 = require("zod");
1984
- var import_react_query5 = require("@tanstack/react-query");
1985
- var import_react13 = require("react");
1999
+ var import_zod24 = require("zod");
1986
2000
 
1987
- // src/genre-tree/useGenrePlaylist.ts
1988
- var import_zod10 = require("zod");
1989
- var import_react_query4 = require("@tanstack/react-query");
2001
+ // src/genre-tree/schemas/criteria/detailed.ts
2002
+ var import_zod15 = require("zod");
1990
2003
 
1991
- // src/genre-tree/schemas/criteria-playlist/simple.ts
1992
- var import_zod9 = require("zod");
2004
+ // src/genre-tree/schemas/genre-music.ts
2005
+ var import_zod7 = require("zod");
1993
2006
 
1994
- // src/genre-tree/schemas/criteria-playlist/detailed.ts
1995
- var import_zod8 = require("zod");
2007
+ // src/genre-tree/schemas/criteria-playlist/minimum.ts
2008
+ var import_zod6 = require("zod");
1996
2009
 
1997
2010
  // src/genre-tree/schemas/ids.ts
1998
2011
  var import_zod5 = require("zod");
1999
2012
  var GenreUuidSchema = import_zod5.z.string().uuid().brand();
2000
2013
  var GenrePlaylistUuidSchema = import_zod5.z.string().uuid().brand();
2001
2014
 
2015
+ // src/genre-tree/schemas/criteria-playlist/minimum.ts
2016
+ var CriteriaPlaylistMinimumSchema = import_zod6.z.object({
2017
+ uuid: GenrePlaylistUuidSchema,
2018
+ name: import_zod6.z.string()
2019
+ });
2020
+
2021
+ // src/genre-tree/schemas/genre-music.ts
2022
+ var CountSchema = import_zod7.z.number().int().nonnegative();
2023
+ var SubgenreCountsSchema = import_zod7.z.union([
2024
+ import_zod7.z.object({ canonical: CountSchema, regional: CountSchema, all: CountSchema }).strict(),
2025
+ import_zod7.z.object({ all: CountSchema }).strict()
2026
+ ]).refine(
2027
+ (counts) => !("canonical" in counts) || counts.all >= counts.canonical && counts.all >= counts.regional,
2028
+ "The combined count must include both scoped selections"
2029
+ );
2030
+ var GenreCountsSchema = import_zod7.z.object({
2031
+ genreOnlyTracksCount: CountSchema,
2032
+ genreAndSubgenresTracksCount: SubgenreCountsSchema
2033
+ });
2034
+ var includesDirectSongs = (counts) => Object.values(counts.genreAndSubgenresTracksCount).every((count) => count >= counts.genreOnlyTracksCount);
2035
+ var GenreCatalogueCountsSchema = GenreCountsSchema.refine(includesDirectSongs, "Every inclusive count must include the genre itself").brand();
2036
+ var GenrePlaylistSummarySchema = CriteriaPlaylistMinimumSchema.extend(GenreCountsSchema.shape).refine(includesDirectSongs, "Every inclusive count must include the genre itself").brand();
2037
+ var GenreCoverageSchema = import_zod7.z.enum(["genreOnly", "genreAndSubgenres"]);
2038
+ var SubgenreScopeSchema = import_zod7.z.enum(["canonical", "regional", "all"]);
2039
+
2002
2040
  // src/genre-tree/schemas/criteria/minimum.ts
2003
- var import_zod6 = require("zod");
2004
- var CriteriaMinimumSchema = import_zod6.z.object({
2041
+ var import_zod8 = require("zod");
2042
+ var CriteriaMinimumSchema = import_zod8.z.object({
2005
2043
  uuid: GenreUuidSchema,
2006
- name: import_zod6.z.string(),
2007
- side: import_zod6.z.enum(["core", "pop"]).nullable().optional(),
2008
- wikidataId: import_zod6.z.string().nullable().optional()
2044
+ name: import_zod8.z.string(),
2045
+ side: import_zod8.z.enum(["core", "pop"]).nullable().optional(),
2046
+ wikidataId: import_zod8.z.string().nullable().optional()
2009
2047
  });
2010
2048
 
2011
- // src/genre-tree/schemas/criteria-playlist/minimum.ts
2012
- var import_zod7 = require("zod");
2013
- var CriteriaPlaylistMinimumSchema = import_zod7.z.object({
2014
- uuid: GenrePlaylistUuidSchema,
2015
- name: import_zod7.z.string()
2049
+ // src/genre-tree/schemas/track/base.ts
2050
+ var import_zod12 = require("zod");
2051
+
2052
+ // src/genre-tree/schemas/artist-minimum.ts
2053
+ var import_zod9 = require("zod");
2054
+ var ArtistMinimumSchema = import_zod9.z.object({
2055
+ uuid: import_zod9.z.string().uuid(),
2056
+ name: import_zod9.z.string(),
2057
+ isSpecialPurpose: import_zod9.z.boolean().optional()
2058
+ });
2059
+
2060
+ // src/genre-tree/schemas/album-minimum.ts
2061
+ var import_zod10 = require("zod");
2062
+ var AlbumMinimumSchema = import_zod10.z.object({
2063
+ uuid: import_zod10.z.string().uuid(),
2064
+ name: import_zod10.z.string(),
2065
+ albumArtists: import_zod10.z.array(ArtistMinimumSchema).nullable().optional()
2066
+ });
2067
+
2068
+ // src/genre-tree/schemas/uuid-resource.ts
2069
+ var import_zod11 = require("zod");
2070
+ var UuidResourceSchema = import_zod11.z.object({
2071
+ uuid: import_zod11.z.string().uuid()
2016
2072
  });
2017
2073
 
2074
+ // src/genre-tree/schemas/track/base.ts
2075
+ var TrackBaseSchema = UuidResourceSchema.extend({
2076
+ title: import_zod12.z.string(),
2077
+ artists: import_zod12.z.array(ArtistMinimumSchema).nullable().optional(),
2078
+ album: AlbumMinimumSchema.nullable().optional(),
2079
+ trackNumber: import_zod12.z.number().nullable().optional(),
2080
+ // null for a song not yet linked to a genre.
2081
+ genre: CriteriaMinimumSchema.nullable(),
2082
+ rating: import_zod12.z.number().min(0).max(10).nullable().optional(),
2083
+ language: import_zod12.z.string().nullable().optional(),
2084
+ playCount: import_zod12.z.number().min(0),
2085
+ createdOn: import_zod12.z.string().datetime(),
2086
+ updatedOn: import_zod12.z.string().datetime().nullable().optional()
2087
+ });
2088
+
2089
+ // src/genre-tree/schemas/track/minimum.ts
2090
+ var TrackMinimumSchema = TrackBaseSchema.pick({
2091
+ uuid: true,
2092
+ title: true,
2093
+ artists: true
2094
+ });
2095
+
2096
+ // src/genre-tree/schemas/criteria/lineage-rel/without-ascendant.ts
2097
+ var import_zod13 = require("zod");
2098
+ var CriteriaLineageRelWithoutAscendantSchema = import_zod13.z.object({
2099
+ descendant: CriteriaMinimumSchema,
2100
+ degree: import_zod13.z.number()
2101
+ });
2102
+
2103
+ // src/genre-tree/schemas/criteria/lineage-rel/without-descendant.ts
2104
+ var import_zod14 = require("zod");
2105
+ var CriteriaLineageRelWithoutDescendantSchema = import_zod14.z.object({
2106
+ ascendant: CriteriaMinimumSchema,
2107
+ degree: import_zod14.z.number()
2108
+ });
2109
+
2110
+ // src/genre-tree/schemas/criteria/detailed.ts
2111
+ var CriteriaDetailedSchema = import_zod15.z.object({
2112
+ uuid: GenreUuidSchema,
2113
+ name: import_zod15.z.string(),
2114
+ summary: import_zod15.z.string().nullable(),
2115
+ // Optional until every deployed API serves it.
2116
+ wikidataId: import_zod15.z.string().nullable().optional(),
2117
+ parent: CriteriaMinimumSchema.nullable(),
2118
+ ascendants: import_zod15.z.array(CriteriaLineageRelWithoutDescendantSchema),
2119
+ descendants: import_zod15.z.array(CriteriaLineageRelWithoutAscendantSchema),
2120
+ root: CriteriaMinimumSchema,
2121
+ children: import_zod15.z.array(CriteriaMinimumSchema),
2122
+ catalogue: GenreCatalogueCountsSchema.optional(),
2123
+ criteriaPlaylist: import_zod15.z.union([GenrePlaylistSummarySchema, CriteriaPlaylistMinimumSchema]),
2124
+ tracks: import_zod15.z.array(TrackMinimumSchema),
2125
+ essentialSongs: import_zod15.z.array(TrackMinimumSchema),
2126
+ tracksCount: import_zod15.z.number(),
2127
+ updatedOn: import_zod15.z.string().datetime().nullable()
2128
+ });
2129
+
2130
+ // src/genre-tree/schemas/criteria-playlist/simple.ts
2131
+ var import_zod17 = require("zod");
2132
+
2018
2133
  // src/genre-tree/schemas/criteria-playlist/detailed.ts
2019
- var CriteriaPlaylistDetailedSchema = import_zod8.z.object({
2134
+ var import_zod16 = require("zod");
2135
+ var CriteriaPlaylistDetailedSchema = import_zod16.z.object({
2020
2136
  uuid: GenrePlaylistUuidSchema,
2021
- name: import_zod8.z.string(),
2022
- tracksCount: import_zod8.z.number(),
2137
+ name: import_zod16.z.string(),
2138
+ tracksCount: import_zod16.z.number(),
2139
+ genreOnlyTracksCount: GenreCountsSchema.shape.genreOnlyTracksCount.optional(),
2140
+ genreAndSubgenresTracksCount: GenreCountsSchema.shape.genreAndSubgenresTracksCount.optional(),
2141
+ catalogue: GenreCatalogueCountsSchema.optional(),
2023
2142
  // Summed YouTube views of the same songs as `tracksCount`. Optional: hear-api has no view counts.
2024
- viewsCount: import_zod8.z.number().optional(),
2025
- durationInSec: import_zod8.z.number().min(0).nullable().optional(),
2026
- durationStrInHourMinSec: import_zod8.z.string().nullable().optional(),
2143
+ viewsCount: import_zod16.z.number().optional(),
2144
+ durationInSec: import_zod16.z.number().min(0).nullable().optional(),
2145
+ durationStrInHourMinSec: import_zod16.z.string().nullable().optional(),
2027
2146
  // Nullable: the "Genreless" root playlist has no criteria attached and is never updated.
2028
2147
  criteria: CriteriaMinimumSchema.nullable(),
2029
2148
  parent: CriteriaPlaylistMinimumSchema.nullable(),
2030
2149
  root: CriteriaPlaylistMinimumSchema,
2031
- createdOn: import_zod8.z.string(),
2032
- updatedOn: import_zod8.z.string().nullable()
2150
+ createdOn: import_zod16.z.string(),
2151
+ updatedOn: import_zod16.z.string().nullable()
2033
2152
  });
2034
2153
 
2035
2154
  // src/genre-tree/schemas/criteria-playlist/simple.ts
@@ -2040,18 +2159,42 @@ var CriteriaPlaylistSimpleSchema = CriteriaPlaylistDetailedSchema.pick({
2040
2159
  parent: true,
2041
2160
  root: true,
2042
2161
  tracksCount: true,
2162
+ genreOnlyTracksCount: true,
2163
+ genreAndSubgenresTracksCount: true,
2164
+ catalogue: true,
2043
2165
  viewsCount: true,
2044
2166
  createdOn: true,
2045
2167
  updatedOn: true
2046
2168
  }).extend({
2047
2169
  // Only on the tree/list payloads, not the detail endpoint — hence not on the detailed schema.
2048
- isUnacceptedRoot: import_zod9.z.boolean(),
2170
+ isUnacceptedRoot: import_zod17.z.boolean(),
2049
2171
  // Optional: a backend that does not curate umbrella genres omits it.
2050
- isUmbrella: import_zod9.z.boolean().optional(),
2172
+ isUmbrella: import_zod17.z.boolean().optional(),
2051
2173
  // Optional: only the grow tree payload carries it; null when the genre has no scene.
2052
- scene: import_zod9.z.enum(["commercial", "underground"]).nullable().optional()
2174
+ scene: import_zod17.z.enum(["commercial", "underground"]).nullable().optional()
2053
2175
  });
2054
2176
 
2177
+ // src/genre-tree/schemas/reference-genre.ts
2178
+ var ReferenceGenreDetailedSchema = CriteriaDetailedSchema.extend({
2179
+ catalogue: GenreCatalogueCountsSchema,
2180
+ criteriaPlaylist: GenrePlaylistSummarySchema
2181
+ });
2182
+ var ReferenceGenrePlaylistSchema = CriteriaPlaylistSimpleSchema.extend({
2183
+ ...GenreCountsSchema.shape,
2184
+ catalogue: GenreCatalogueCountsSchema
2185
+ }).superRefine((playlist, ctx) => {
2186
+ const counts = GenreCatalogueCountsSchema.safeParse(playlist);
2187
+ if (!counts.success) for (const issue of counts.error.issues) ctx.addIssue({ code: "custom", path: issue.path, message: issue.message });
2188
+ });
2189
+
2190
+ // src/genre-tree/useGenre.ts
2191
+ var import_react_query5 = require("@tanstack/react-query");
2192
+ var import_react13 = require("react");
2193
+
2194
+ // src/genre-tree/useGenrePlaylist.ts
2195
+ var import_zod18 = require("zod");
2196
+ var import_react_query4 = require("@tanstack/react-query");
2197
+
2055
2198
  // src/genre-tree/api/genre-playlists/queryKeys.ts
2056
2199
  var genrePlaylistQueryKeys = {
2057
2200
  me: {
@@ -2087,6 +2230,30 @@ var genrePlaylistEndpoints = {
2087
2230
  reference: { ...makeGenrePlaylistEndpoints(""), tree: () => "genre-playlists/tree/" }
2088
2231
  };
2089
2232
 
2233
+ // src/genre-tree/lib/genre-music-selection.ts
2234
+ function defaultGenreMusicSelection(counts) {
2235
+ return { coverage: "genreAndSubgenres", subgenres: "canonical" in counts.genreAndSubgenresTracksCount ? "canonical" : "all" };
2236
+ }
2237
+ function genreMusicCount(counts, selection = defaultGenreMusicSelection(counts)) {
2238
+ if (selection.coverage === "genreOnly") return counts.genreOnlyTracksCount;
2239
+ const scopes = counts.genreAndSubgenresTracksCount;
2240
+ if (selection.subgenres === "all") return scopes.all;
2241
+ if (!("canonical" in scopes)) throw new Error("Regional genres only support all subgenres");
2242
+ return scopes[selection.subgenres];
2243
+ }
2244
+ function genreMusicQueryParams(selection) {
2245
+ if (!selection) return {};
2246
+ return selection.coverage === "genreOnly" ? { coverage: "genre_only" } : { coverage: "genre_and_subgenres", subgenres: selection.subgenres };
2247
+ }
2248
+ function genreMusicSelectionKey(selection) {
2249
+ return selection ? [selection.coverage, ...selection.coverage === "genreAndSubgenres" ? [selection.subgenres] : []] : [];
2250
+ }
2251
+ function genrePlaylistTrackCount(playlist) {
2252
+ if (playlist.genreOnlyTracksCount === void 0 && playlist.genreAndSubgenresTracksCount === void 0) return playlist.tracksCount;
2253
+ if (playlist.genreOnlyTracksCount === void 0 || playlist.genreAndSubgenresTracksCount === void 0) throw new Error("Incomplete genre playlist counts");
2254
+ return genreMusicCount({ genreOnlyTracksCount: playlist.genreOnlyTracksCount, genreAndSubgenresTracksCount: playlist.genreAndSubgenresTracksCount });
2255
+ }
2256
+
2090
2257
  // src/genre-tree/api/library/songs/queryKeys.ts
2091
2258
  var makeSongQueryKeys = (prefix) => ({
2092
2259
  all: [`${prefix}Songs`],
@@ -2095,7 +2262,7 @@ var makeSongQueryKeys = (prefix) => ({
2095
2262
  history: (uuid) => [`${prefix}Songs`, "history", uuid],
2096
2263
  search: (params) => [`${prefix}Songs`, "search", params],
2097
2264
  // baseUrl keeps distinct backends sharing a scope (e.g. grow and its prototype proxy) apart.
2098
- byGenre: (baseUrl, genreUuid) => [`${prefix}Songs`, baseUrl, "genre", genreUuid]
2265
+ byGenre: (baseUrl, genreUuid, selection) => [`${prefix}Songs`, baseUrl, "genre", genreUuid, ...genreMusicSelectionKey(selection)]
2099
2266
  });
2100
2267
 
2101
2268
  // src/genre-tree/api/library/songs/endpoints.ts
@@ -2165,7 +2332,7 @@ var useListFullGenrePlaylists = (scope, getBackendBaseUrl) => {
2165
2332
  const queryClient2 = (0, import_react_query4.useQueryClient)();
2166
2333
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2167
2334
  const { session, sessionRestored } = useSession();
2168
- const queryKey = scope === "reference" ? genrePlaylistQueryKeys.reference.full(getBackendBaseUrl()) : genrePlaylistQueryKeys.me.full;
2335
+ const queryKey = scope === "reference" ? [...genrePlaylistQueryKeys.reference.full(getBackendBaseUrl()), "genreMusicV1"] : genrePlaylistQueryKeys.me.full;
2169
2336
  const query = useQueryWithParse({
2170
2337
  queryKey,
2171
2338
  queryFn: () => scope === "reference" ? fetch2(genrePlaylistEndpoints.reference.tree(), true, false, {}, { treeName: "canonical" }) : fetchAllPages(
@@ -2177,7 +2344,7 @@ var useListFullGenrePlaylists = (scope, getBackendBaseUrl) => {
2177
2344
  { page, pageSize: FULL_LIST_PAGE_SIZE, treeName: "canonical" }
2178
2345
  )
2179
2346
  ),
2180
- schema: import_zod10.z.array(CriteriaPlaylistSimpleSchema),
2347
+ schema: scope === "reference" ? import_zod18.z.array(ReferenceGenrePlaylistSchema) : import_zod18.z.array(CriteriaPlaylistSimpleSchema),
2181
2348
  context: "useListFullGenrePlaylists",
2182
2349
  enabled: scope === "reference" || sessionRestored && !!session?.accessToken
2183
2350
  });
@@ -2210,131 +2377,48 @@ var useInvalidateAllGenrePlaylistQueries = () => {
2210
2377
  ]);
2211
2378
  };
2212
2379
 
2213
- // src/genre-tree/schemas/criteria/detailed.ts
2214
- var import_zod17 = require("zod");
2215
-
2216
- // src/genre-tree/schemas/track/base.ts
2217
- var import_zod14 = require("zod");
2218
-
2219
- // src/genre-tree/schemas/artist-minimum.ts
2220
- var import_zod11 = require("zod");
2221
- var ArtistMinimumSchema = import_zod11.z.object({
2222
- uuid: import_zod11.z.string().uuid(),
2223
- name: import_zod11.z.string(),
2224
- isSpecialPurpose: import_zod11.z.boolean().optional()
2225
- });
2226
-
2227
- // src/genre-tree/schemas/album-minimum.ts
2228
- var import_zod12 = require("zod");
2229
- var AlbumMinimumSchema = import_zod12.z.object({
2230
- uuid: import_zod12.z.string().uuid(),
2231
- name: import_zod12.z.string(),
2232
- albumArtists: import_zod12.z.array(ArtistMinimumSchema).nullable().optional()
2233
- });
2234
-
2235
- // src/genre-tree/schemas/uuid-resource.ts
2236
- var import_zod13 = require("zod");
2237
- var UuidResourceSchema = import_zod13.z.object({
2238
- uuid: import_zod13.z.string().uuid()
2239
- });
2240
-
2241
- // src/genre-tree/schemas/track/base.ts
2242
- var TrackBaseSchema = UuidResourceSchema.extend({
2243
- title: import_zod14.z.string(),
2244
- artists: import_zod14.z.array(ArtistMinimumSchema).nullable().optional(),
2245
- album: AlbumMinimumSchema.nullable().optional(),
2246
- trackNumber: import_zod14.z.number().nullable().optional(),
2247
- // null for a song not yet linked to a genre.
2248
- genre: CriteriaMinimumSchema.nullable(),
2249
- rating: import_zod14.z.number().min(0).max(10).nullable().optional(),
2250
- language: import_zod14.z.string().nullable().optional(),
2251
- playCount: import_zod14.z.number().min(0),
2252
- createdOn: import_zod14.z.string().datetime(),
2253
- updatedOn: import_zod14.z.string().datetime().nullable().optional()
2254
- });
2255
-
2256
- // src/genre-tree/schemas/track/minimum.ts
2257
- var TrackMinimumSchema = TrackBaseSchema.pick({
2258
- uuid: true,
2259
- title: true,
2260
- artists: true
2261
- });
2262
-
2263
- // src/genre-tree/schemas/criteria/lineage-rel/without-ascendant.ts
2264
- var import_zod15 = require("zod");
2265
- var CriteriaLineageRelWithoutAscendantSchema = import_zod15.z.object({
2266
- descendant: CriteriaMinimumSchema,
2267
- degree: import_zod15.z.number()
2268
- });
2269
-
2270
- // src/genre-tree/schemas/criteria/lineage-rel/without-descendant.ts
2271
- var import_zod16 = require("zod");
2272
- var CriteriaLineageRelWithoutDescendantSchema = import_zod16.z.object({
2273
- ascendant: CriteriaMinimumSchema,
2274
- degree: import_zod16.z.number()
2275
- });
2276
-
2277
- // src/genre-tree/schemas/criteria/detailed.ts
2278
- var CriteriaDetailedSchema = import_zod17.z.object({
2279
- uuid: GenreUuidSchema,
2280
- name: import_zod17.z.string(),
2281
- summary: import_zod17.z.string().nullable(),
2282
- // Optional until every deployed API serves it.
2283
- wikidataId: import_zod17.z.string().nullable().optional(),
2284
- parent: CriteriaMinimumSchema.nullable(),
2285
- ascendants: import_zod17.z.array(CriteriaLineageRelWithoutDescendantSchema),
2286
- descendants: import_zod17.z.array(CriteriaLineageRelWithoutAscendantSchema),
2287
- root: CriteriaMinimumSchema,
2288
- children: import_zod17.z.array(CriteriaMinimumSchema),
2289
- criteriaPlaylist: CriteriaPlaylistMinimumSchema,
2290
- tracks: import_zod17.z.array(TrackMinimumSchema),
2291
- essentialSongs: import_zod17.z.array(TrackMinimumSchema),
2292
- tracksCount: import_zod17.z.number(),
2293
- updatedOn: import_zod17.z.string().datetime().nullable()
2294
- });
2295
-
2296
2380
  // src/genre-tree/schemas/criteria/overview.ts
2297
- var import_zod19 = require("zod");
2381
+ var import_zod20 = require("zod");
2298
2382
 
2299
2383
  // src/genre-tree/schemas/http-url.ts
2300
- var import_zod18 = require("zod");
2301
- var HttpUrlSchema = import_zod18.z.url({ protocol: /^https?$/ });
2384
+ var import_zod19 = require("zod");
2385
+ var HttpUrlSchema = import_zod19.z.url({ protocol: /^https?$/ });
2302
2386
 
2303
2387
  // src/genre-tree/schemas/criteria/overview.ts
2304
- var CriteriaOverviewSchema = import_zod19.z.object({
2388
+ var CriteriaOverviewSchema = import_zod20.z.object({
2305
2389
  uuid: GenreUuidSchema,
2306
- name: import_zod19.z.string(),
2307
- summary: import_zod19.z.string().nullable(),
2308
- description: import_zod19.z.string().nullable(),
2390
+ name: import_zod20.z.string(),
2391
+ summary: import_zod20.z.string().nullable(),
2392
+ description: import_zod20.z.string().nullable(),
2309
2393
  summarySourceUrl: HttpUrlSchema.nullable(),
2310
- essentialSongs: import_zod19.z.array(TrackMinimumSchema).optional()
2394
+ essentialSongs: import_zod20.z.array(TrackMinimumSchema).optional()
2311
2395
  });
2312
2396
 
2313
2397
  // src/genre-tree/schemas/criteria/simple.ts
2314
- var import_zod20 = require("zod");
2315
- var CriteriaSimpleSchema = import_zod20.z.object({
2398
+ var import_zod21 = require("zod");
2399
+ var CriteriaSimpleSchema = import_zod21.z.object({
2316
2400
  uuid: GenreUuidSchema,
2317
- name: import_zod20.z.string(),
2401
+ name: import_zod21.z.string(),
2318
2402
  parent: CriteriaMinimumSchema.nullable(),
2319
- createdOn: import_zod20.z.string().datetime(),
2320
- summary: import_zod20.z.string().nullable()
2403
+ createdOn: import_zod21.z.string().datetime(),
2404
+ summary: import_zod21.z.string().nullable()
2321
2405
  });
2322
2406
 
2323
2407
  // src/genre-tree/schemas/criteria/creation.ts
2324
- var import_zod21 = require("zod");
2325
- var CriteriaCreationSchema = import_zod21.z.object({
2326
- name: import_zod21.z.string().min(1, "Name is required"),
2408
+ var import_zod22 = require("zod");
2409
+ var CriteriaCreationSchema = import_zod22.z.object({
2410
+ name: import_zod22.z.string().min(1, "Name is required"),
2327
2411
  parent: GenreUuidSchema.optional(),
2328
- essentialSongs: import_zod21.z.array(import_zod21.z.string().uuid()).optional()
2412
+ essentialSongs: import_zod22.z.array(import_zod22.z.string().uuid()).optional()
2329
2413
  });
2330
2414
 
2331
2415
  // src/genre-tree/schemas/criteria/update.ts
2332
- var import_zod22 = require("zod");
2333
- var CriteriaUpdateSchema = import_zod22.z.object({
2334
- name: import_zod22.z.string().optional(),
2416
+ var import_zod23 = require("zod");
2417
+ var CriteriaUpdateSchema = import_zod23.z.object({
2418
+ name: import_zod23.z.string().optional(),
2335
2419
  parent: GenreUuidSchema.nullable().optional(),
2336
- essentialSongs: import_zod22.z.array(import_zod22.z.string().uuid()).optional(),
2337
- side: import_zod22.z.enum(["core", "pop"]).optional()
2420
+ essentialSongs: import_zod23.z.array(import_zod23.z.string().uuid()).optional(),
2421
+ side: import_zod23.z.enum(["core", "pop"]).optional()
2338
2422
  });
2339
2423
 
2340
2424
  // src/genre-tree/api/genres/queryKeys.ts
@@ -2395,18 +2479,18 @@ function useFetchGenre(scope, getBackendBaseUrl) {
2395
2479
  async (id) => {
2396
2480
  const endpoint = scope === "reference" ? genreEndpoints.reference.detail(id) : genreEndpoints.me.detail(id);
2397
2481
  const response = await fetch2(endpoint, true, scope === "me");
2398
- return parseWithLog(CriteriaDetailedSchema, response, "useFetchGenre");
2482
+ return parseWithLog(scope === "reference" ? ReferenceGenreDetailedSchema : CriteriaDetailedSchema, response, "useFetchGenre");
2399
2483
  },
2400
2484
  [fetch2, scope]
2401
2485
  );
2402
2486
  }
2403
- function useFetchGenreDetail(id, scope, getBackendBaseUrl, schema = CriteriaDetailedSchema) {
2487
+ function useFetchGenreDetail(id, scope, getBackendBaseUrl, schema = scope === "reference" ? ReferenceGenreDetailedSchema : CriteriaDetailedSchema) {
2404
2488
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2405
2489
  const queryKeys = scope === "reference" ? genreQueryKeys.reference : genreQueryKeys.me;
2406
2490
  const endpoints = scope === "reference" ? genreEndpoints.reference : genreEndpoints.me;
2407
2491
  const genreUuid = id ?? "";
2408
2492
  return useQueryWithParse({
2409
- queryKey: queryKeys.detail(genreUuid),
2493
+ queryKey: scope === "reference" ? [...queryKeys.detail(genreUuid), getBackendBaseUrl(), "genreMusicV1"] : queryKeys.detail(genreUuid),
2410
2494
  queryFn: () => fetch2(endpoints.detail(genreUuid), true, scope === "me"),
2411
2495
  schema,
2412
2496
  context: "useFetchGenreDetail",
@@ -2489,7 +2573,7 @@ function useUpdateGenre(scope, getBackendBaseUrl) {
2489
2573
  const refreshGenreTree = useRefreshGenreTree(scope);
2490
2574
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2491
2575
  const { mutate, mutateAsync, isPending, formErrors } = useValidatedMutation({
2492
- inputSchema: import_zod23.z.object({
2576
+ inputSchema: import_zod24.z.object({
2493
2577
  uuid: GenreUuidSchema,
2494
2578
  data: CriteriaUpdateSchema
2495
2579
  }),
@@ -2519,8 +2603,8 @@ function useDeleteGenre(scope, getBackendBaseUrl) {
2519
2603
  const refreshGenreTree = useRefreshGenreTree(scope);
2520
2604
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2521
2605
  return useValidatedMutation({
2522
- inputSchema: import_zod23.z.object({ uuid: GenreUuidSchema }),
2523
- outputSchema: import_zod23.z.null(),
2606
+ inputSchema: import_zod24.z.object({ uuid: GenreUuidSchema }),
2607
+ outputSchema: import_zod24.z.null(),
2524
2608
  mutationFn: async ({ uuid }) => {
2525
2609
  const endpoint = scope === "reference" ? genreEndpoints.reference.delete(uuid) : genreEndpoints.me.delete(uuid);
2526
2610
  return fetch2(endpoint, true, scope === "me", { method: "DELETE" }, void 0, false, true);
@@ -2530,16 +2614,16 @@ function useDeleteGenre(scope, getBackendBaseUrl) {
2530
2614
  }
2531
2615
 
2532
2616
  // src/genre-tree/useArtist.ts
2533
- var import_zod25 = require("zod");
2617
+ var import_zod26 = require("zod");
2534
2618
 
2535
2619
  // src/genre-tree/schemas/artist-detailed.ts
2536
- var import_zod24 = require("zod");
2537
- var ArtistMembershipSchema = import_zod24.z.object({
2620
+ var import_zod25 = require("zod");
2621
+ var ArtistMembershipSchema = import_zod25.z.object({
2538
2622
  artist: ArtistMinimumSchema,
2539
- beginYear: import_zod24.z.number().int().nullable(),
2540
- endYear: import_zod24.z.number().int().nullable(),
2541
- ended: import_zod24.z.boolean(),
2542
- roles: import_zod24.z.array(import_zod24.z.string())
2623
+ beginYear: import_zod25.z.number().int().nullable(),
2624
+ endYear: import_zod25.z.number().int().nullable(),
2625
+ ended: import_zod25.z.boolean(),
2626
+ roles: import_zod25.z.array(import_zod25.z.string())
2543
2627
  });
2544
2628
  var ARTIST_LINK_KINDS = [
2545
2629
  "official",
@@ -2552,35 +2636,35 @@ var ARTIST_LINK_KINDS = [
2552
2636
  "discogs",
2553
2637
  "social"
2554
2638
  ];
2555
- var ArtistImageSchema = import_zod24.z.object({
2639
+ var ArtistImageSchema = import_zod25.z.object({
2556
2640
  url: HttpUrlSchema,
2557
2641
  pageUrl: HttpUrlSchema,
2558
- author: import_zod24.z.string().nullable(),
2559
- license: import_zod24.z.string(),
2642
+ author: import_zod25.z.string().nullable(),
2643
+ license: import_zod25.z.string(),
2560
2644
  licenseUrl: HttpUrlSchema.nullable()
2561
2645
  });
2562
- var ArtistDetailedSchema = import_zod24.z.object({
2563
- uuid: import_zod24.z.string().uuid(),
2564
- name: import_zod24.z.string(),
2565
- musicbrainzArtistId: import_zod24.z.string().uuid().nullable(),
2566
- type: import_zod24.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
2567
- country: import_zod24.z.string().nullable(),
2568
- beginYear: import_zod24.z.number().int().nullable(),
2569
- endYear: import_zod24.z.number().int().nullable(),
2570
- ended: import_zod24.z.boolean(),
2571
- links: import_zod24.z.array(import_zod24.z.object({ kind: import_zod24.z.enum(ARTIST_LINK_KINDS), url: HttpUrlSchema })),
2572
- members: import_zod24.z.array(ArtistMembershipSchema),
2573
- memberOf: import_zod24.z.array(ArtistMembershipSchema),
2574
- albums: import_zod24.z.array(
2575
- import_zod24.z.object({
2576
- uuid: import_zod24.z.string().uuid(),
2577
- name: import_zod24.z.string(),
2578
- year: import_zod24.z.string().nullable(),
2579
- primaryType: import_zod24.z.string().nullable(),
2580
- secondaryTypes: import_zod24.z.array(import_zod24.z.string())
2646
+ var ArtistDetailedSchema = import_zod25.z.object({
2647
+ uuid: import_zod25.z.string().uuid(),
2648
+ name: import_zod25.z.string(),
2649
+ musicbrainzArtistId: import_zod25.z.string().uuid().nullable(),
2650
+ type: import_zod25.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
2651
+ country: import_zod25.z.string().nullable(),
2652
+ beginYear: import_zod25.z.number().int().nullable(),
2653
+ endYear: import_zod25.z.number().int().nullable(),
2654
+ ended: import_zod25.z.boolean(),
2655
+ links: import_zod25.z.array(import_zod25.z.object({ kind: import_zod25.z.enum(ARTIST_LINK_KINDS), url: HttpUrlSchema })),
2656
+ members: import_zod25.z.array(ArtistMembershipSchema),
2657
+ memberOf: import_zod25.z.array(ArtistMembershipSchema),
2658
+ albums: import_zod25.z.array(
2659
+ import_zod25.z.object({
2660
+ uuid: import_zod25.z.string().uuid(),
2661
+ name: import_zod25.z.string(),
2662
+ year: import_zod25.z.string().nullable(),
2663
+ primaryType: import_zod25.z.string().nullable(),
2664
+ secondaryTypes: import_zod25.z.array(import_zod25.z.string())
2581
2665
  })
2582
2666
  ),
2583
- tracksCount: import_zod24.z.number().int(),
2667
+ tracksCount: import_zod25.z.number().int(),
2584
2668
  image: ArtistImageSchema.nullable()
2585
2669
  });
2586
2670
 
@@ -2603,7 +2687,7 @@ var artistEndpoints = {
2603
2687
  var isNotFound = (error) => error instanceof AppError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */;
2604
2688
  function useArtist(uuid, getBackendBaseUrl) {
2605
2689
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2606
- const isUuid = uuid !== null && import_zod25.z.string().uuid().safeParse(uuid).success;
2690
+ const isUuid = uuid !== null && import_zod26.z.string().uuid().safeParse(uuid).success;
2607
2691
  const { data, isPending, error } = useQueryWithParse({
2608
2692
  queryKey: artistQueryKeys.detail(uuid),
2609
2693
  // A missing artist is shown in the panel, not raised as an app-wide connectivity error.
@@ -2621,19 +2705,19 @@ function useArtist(uuid, getBackendBaseUrl) {
2621
2705
  }
2622
2706
 
2623
2707
  // src/genre-tree/schemas/artist-search.ts
2624
- var import_zod26 = require("zod");
2625
- var ArtistSearchResultSchema = import_zod26.z.object({
2626
- uuid: import_zod26.z.string().uuid(),
2627
- name: import_zod26.z.string(),
2628
- disambiguation: import_zod26.z.string().nullable(),
2629
- type: import_zod26.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
2630
- country: import_zod26.z.string().nullable(),
2631
- beginYear: import_zod26.z.number().int().nullable(),
2632
- endYear: import_zod26.z.number().int().nullable(),
2633
- matchedAlias: import_zod26.z.string().nullable(),
2634
- recordingCount: import_zod26.z.number().int()
2708
+ var import_zod27 = require("zod");
2709
+ var ArtistSearchResultSchema = import_zod27.z.object({
2710
+ uuid: import_zod27.z.string().uuid(),
2711
+ name: import_zod27.z.string(),
2712
+ disambiguation: import_zod27.z.string().nullable(),
2713
+ type: import_zod27.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
2714
+ country: import_zod27.z.string().nullable(),
2715
+ beginYear: import_zod27.z.number().int().nullable(),
2716
+ endYear: import_zod27.z.number().int().nullable(),
2717
+ matchedAlias: import_zod27.z.string().nullable(),
2718
+ recordingCount: import_zod27.z.number().int()
2635
2719
  });
2636
- var ArtistSearchResultsSchema = import_zod26.z.array(ArtistSearchResultSchema);
2720
+ var ArtistSearchResultsSchema = import_zod27.z.array(ArtistSearchResultSchema);
2637
2721
 
2638
2722
  // src/genre-tree/useRemoteSearch.ts
2639
2723
  var import_react_query6 = require("@tanstack/react-query");
@@ -2687,10 +2771,10 @@ function useArtistSearch(getBackendBaseUrl, text) {
2687
2771
  }
2688
2772
 
2689
2773
  // src/genre-tree/useSong.ts
2690
- var import_zod28 = require("zod");
2774
+ var import_zod29 = require("zod");
2691
2775
 
2692
2776
  // src/genre-tree/schemas/song/detailed.ts
2693
- var import_zod27 = require("zod");
2777
+ var import_zod28 = require("zod");
2694
2778
  var YOUTUBE_UNPLAYABLE_REASON_LABELS = {
2695
2779
  not_found: "Video unavailable",
2696
2780
  not_embeddable: "Embedding disabled",
@@ -2699,23 +2783,23 @@ var YOUTUBE_UNPLAYABLE_REASON_LABELS = {
2699
2783
  region_whitelisted: "Region restricted"
2700
2784
  };
2701
2785
  var YOUTUBE_UNPLAYABLE_REASONS = Object.keys(YOUTUBE_UNPLAYABLE_REASON_LABELS);
2702
- var YoutubeAvailabilitySchema = import_zod27.z.object({
2703
- status: import_zod27.z.enum(["eligible", "blocked", "unknown"]),
2704
- reason: import_zod27.z.string().nullable(),
2705
- country: import_zod27.z.string().nullable()
2786
+ var YoutubeAvailabilitySchema = import_zod28.z.object({
2787
+ status: import_zod28.z.enum(["eligible", "blocked", "unknown"]),
2788
+ reason: import_zod28.z.string().nullable(),
2789
+ country: import_zod28.z.string().nullable()
2706
2790
  });
2707
2791
  var SongDetailedSchema = TrackBaseSchema.extend({
2708
- youtubeVideo: import_zod27.z.object({
2709
- id: import_zod27.z.string(),
2792
+ youtubeVideo: import_zod28.z.object({
2793
+ id: import_zod28.z.string(),
2710
2794
  availability: YoutubeAvailabilitySchema.optional(),
2711
2795
  // null = playable
2712
- unplayableReason: import_zod27.z.enum(YOUTUBE_UNPLAYABLE_REASONS).nullable(),
2713
- viewCount: import_zod27.z.number().int().nullable().optional()
2796
+ unplayableReason: import_zod28.z.enum(YOUTUBE_UNPLAYABLE_REASONS).nullable(),
2797
+ viewCount: import_zod28.z.number().int().nullable().optional()
2714
2798
  }).nullable(),
2715
2799
  // null for hand-made/admin songs
2716
- musicbrainzRecordingId: import_zod27.z.string().uuid().nullable(),
2717
- firstReleaseYear: import_zod27.z.number().int().nullable().optional(),
2718
- essentialGenres: import_zod27.z.array(CriteriaMinimumSchema).optional()
2800
+ musicbrainzRecordingId: import_zod28.z.string().uuid().nullable(),
2801
+ firstReleaseYear: import_zod28.z.number().int().nullable().optional(),
2802
+ essentialGenres: import_zod28.z.array(CriteriaMinimumSchema).optional()
2719
2803
  });
2720
2804
  var NO_VIDEO_LABEL = "No video available";
2721
2805
  function isSong(track) {
@@ -2736,7 +2820,7 @@ var isNotFound2 = (error) => error instanceof AppError && error.code === "BAC404
2736
2820
  function useSong(uuid, getBackendBaseUrl) {
2737
2821
  const playback = usePlaybackContext();
2738
2822
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2739
- const isUuid = uuid !== null && import_zod28.z.string().uuid().safeParse(uuid).success;
2823
+ const isUuid = uuid !== null && import_zod29.z.string().uuid().safeParse(uuid).success;
2740
2824
  const { data, isPending, error } = useQueryWithParse({
2741
2825
  queryKey: [...libraryQueryKeys.reference.songs.detail(uuid), ...playback.key ? [playback.key] : []],
2742
2826
  // A missing song is shown in the panel, not raised as an app-wide connectivity error.
@@ -2754,16 +2838,16 @@ function useSong(uuid, getBackendBaseUrl) {
2754
2838
  }
2755
2839
 
2756
2840
  // src/genre-tree/schemas/song-history.ts
2757
- var import_zod29 = require("zod");
2758
- var SongHistoryEntrySchema = import_zod29.z.object({
2759
- uuid: import_zod29.z.string().uuid(),
2760
- action: import_zod29.z.string(),
2761
- actorPseudo: import_zod29.z.string().nullable(),
2762
- oldValue: import_zod29.z.string().nullable(),
2763
- newValue: import_zod29.z.string().nullable(),
2764
- createdOn: import_zod29.z.string()
2841
+ var import_zod30 = require("zod");
2842
+ var SongHistoryEntrySchema = import_zod30.z.object({
2843
+ uuid: import_zod30.z.string().uuid(),
2844
+ action: import_zod30.z.string(),
2845
+ actorPseudo: import_zod30.z.string().nullable(),
2846
+ oldValue: import_zod30.z.string().nullable(),
2847
+ newValue: import_zod30.z.string().nullable(),
2848
+ createdOn: import_zod30.z.string()
2765
2849
  });
2766
- var SongHistorySchema = import_zod29.z.array(SongHistoryEntrySchema);
2850
+ var SongHistorySchema = import_zod30.z.array(SongHistoryEntrySchema);
2767
2851
 
2768
2852
  // src/genre-tree/useSongHistory.ts
2769
2853
  function useSongHistory(uuid, getBackendBaseUrl, enabled) {
@@ -2783,20 +2867,20 @@ function useSongHistory(uuid, getBackendBaseUrl, enabled) {
2783
2867
  }
2784
2868
 
2785
2869
  // src/genre-tree/schemas/song-search.ts
2786
- var import_zod30 = require("zod");
2787
- var SongSearchResultSchema = import_zod30.z.object({
2788
- uuid: import_zod30.z.string().uuid(),
2789
- title: import_zod30.z.string(),
2790
- artists: import_zod30.z.array(ArtistMinimumSchema),
2870
+ var import_zod31 = require("zod");
2871
+ var SongSearchResultSchema = import_zod31.z.object({
2872
+ uuid: import_zod31.z.string().uuid(),
2873
+ title: import_zod31.z.string(),
2874
+ artists: import_zod31.z.array(ArtistMinimumSchema),
2791
2875
  // null for songs not yet linked to a genre.
2792
2876
  genre: CriteriaMinimumSchema.nullable(),
2793
- youtubeVideo: import_zod30.z.object({
2794
- id: import_zod30.z.string(),
2795
- unplayableReason: import_zod30.z.string().nullable()
2877
+ youtubeVideo: import_zod31.z.object({
2878
+ id: import_zod31.z.string(),
2879
+ unplayableReason: import_zod31.z.string().nullable()
2796
2880
  }).nullable(),
2797
- firstReleaseYear: import_zod30.z.number().int().nullable()
2881
+ firstReleaseYear: import_zod31.z.number().int().nullable()
2798
2882
  });
2799
- var SongSearchResultsSchema = import_zod30.z.array(SongSearchResultSchema);
2883
+ var SongSearchResultsSchema = import_zod31.z.array(SongSearchResultSchema);
2800
2884
  function isSongSearchResultPlayable(result) {
2801
2885
  return result.youtubeVideo !== null && result.youtubeVideo.unplayableReason === null;
2802
2886
  }
@@ -2822,16 +2906,25 @@ function useSongSearch(getBackendBaseUrl, text, options = {}) {
2822
2906
 
2823
2907
  // src/genre-tree/useArtistGenreCounts.ts
2824
2908
  var import_react_query7 = require("@tanstack/react-query");
2825
- var import_zod32 = require("zod");
2909
+ var import_zod33 = require("zod");
2826
2910
 
2827
2911
  // src/genre-tree/schemas/artist-genre-count.ts
2828
- var import_zod31 = require("zod");
2829
- var ArtistGenreCountSchema = import_zod31.z.object({
2912
+ var import_zod32 = require("zod");
2913
+ var ArtistGenreCountSchema = import_zod32.z.object({
2914
+ ...GenreCountsSchema.shape,
2915
+ catalogue: GenreCatalogueCountsSchema,
2830
2916
  genrePlaylist: GenrePlaylistUuidSchema,
2831
- /** All the artist's songs in the genre playlist's subtree; drives pruning. */
2832
- songsCount: import_zod31.z.number().int().nonnegative(),
2833
- /** The playable ones among them; drives node size and the play button. */
2834
- tracksCount: import_zod31.z.number().int().nonnegative()
2917
+ /** Legacy catalogue count for the default selection. */
2918
+ songsCount: import_zod32.z.number().int().nonnegative(),
2919
+ /** Legacy playlist count for the default selection. */
2920
+ tracksCount: import_zod32.z.number().int().nonnegative()
2921
+ }).superRefine((row, ctx) => {
2922
+ const counts = GenreCatalogueCountsSchema.safeParse(row);
2923
+ if (!counts.success) {
2924
+ for (const issue of counts.error.issues) {
2925
+ ctx.addIssue({ code: "custom", path: issue.path, message: issue.message });
2926
+ }
2927
+ }
2835
2928
  });
2836
2929
 
2837
2930
  // src/genre-tree/useArtistGenreCounts.ts
@@ -2839,10 +2932,10 @@ var isNotFound3 = (error) => error instanceof AppError && error.code === "BAC404
2839
2932
  function useArtistGenreCounts(artistUuid, getBackendBaseUrl) {
2840
2933
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2841
2934
  return useQueryWithParse({
2842
- queryKey: artistQueryKeys.genreCounts(getBackendBaseUrl(), artistUuid),
2935
+ queryKey: [...artistQueryKeys.genreCounts(getBackendBaseUrl(), artistUuid), "genreMusicV1"],
2843
2936
  // A missing artist is shown in the artist panel, not raised as an app-wide connectivity error.
2844
2937
  queryFn: () => fetch2(artistEndpoints.genreCounts(artistUuid), true, false, void 0, void 0, false, true),
2845
- schema: import_zod32.z.array(ArtistGenreCountSchema),
2938
+ schema: import_zod33.z.array(ArtistGenreCountSchema),
2846
2939
  enabled: artistUuid !== null,
2847
2940
  placeholderData: import_react_query7.keepPreviousData,
2848
2941
  retry: (failureCount, error) => !isNotFound3(error) && failureCount < 3,
@@ -2850,6 +2943,9 @@ function useArtistGenreCounts(artistUuid, getBackendBaseUrl) {
2850
2943
  });
2851
2944
  }
2852
2945
 
2946
+ // src/genre-tree/useGenreSearch.ts
2947
+ var import_react16 = require("react");
2948
+
2853
2949
  // src/genre-tree/lib/search-text.ts
2854
2950
  var foldSearchText = (text) => text.normalize("NFD").replace(/\p{M}+/gu, "").toLowerCase().replace(/\s+/g, " ").trim();
2855
2951
  var trigrams = (folded) => {
@@ -2895,9 +2991,54 @@ function rankByName(items, query, getName, getViews) {
2895
2991
  );
2896
2992
  return scored.map((entry) => entry.item);
2897
2993
  }
2898
-
2899
- // src/genre-tree/lib/genre-search.ts
2900
- var searchGenrePlaylistsByName = (genrePlaylists, query) => rankByName(genrePlaylists, query, (genrePlaylist) => genrePlaylist.name, (genrePlaylist) => genrePlaylist.viewsCount ?? 0);
2994
+ function createNameIndex(items, getName, getViews) {
2995
+ return items.map((item) => {
2996
+ const name = foldSearchText(getName(item));
2997
+ return { item, name, grams: trigrams(name), views: getViews?.(item) ?? 0 };
2998
+ });
2999
+ }
3000
+ function rankNameIndex(index, query, limit = Infinity) {
3001
+ if (limit !== Infinity && (!Number.isInteger(limit) || limit < 0)) {
3002
+ throw new RangeError("Search limit must be a nonnegative integer or Infinity");
3003
+ }
3004
+ const folded = foldSearchText(query);
3005
+ if (!folded || limit === 0) return [];
3006
+ const queryGrams = trigrams(folded);
3007
+ const scored = [];
3008
+ const compare = (a, b) => a.tier - b.tier || b.similarity - a.similarity || b.views - a.views || a.name.localeCompare(b.name);
3009
+ for (const entry of index) {
3010
+ let tier;
3011
+ let similarity = 0;
3012
+ if (entry.name === folded) tier = TIER_EXACT;
3013
+ else if (entry.name.startsWith(folded)) tier = TIER_PREFIX;
3014
+ else if (entry.name.includes(folded)) tier = TIER_SUBSTRING;
3015
+ else {
3016
+ let shared = 0;
3017
+ for (const gram of queryGrams) if (entry.grams.has(gram)) shared++;
3018
+ const union = entry.grams.size + queryGrams.size - shared;
3019
+ similarity = union === 0 ? 0 : shared / union;
3020
+ if (similarity < FUZZY_MIN_SIMILARITY) continue;
3021
+ tier = TIER_FUZZY;
3022
+ }
3023
+ const candidate = { ...entry, tier, similarity };
3024
+ if (limit === Infinity) scored.push(candidate);
3025
+ else {
3026
+ let low = 0;
3027
+ let high = scored.length;
3028
+ while (low < high) {
3029
+ const mid = low + high >>> 1;
3030
+ if (compare(candidate, scored[mid]) < 0) high = mid;
3031
+ else low = mid + 1;
3032
+ }
3033
+ if (low < limit) {
3034
+ scored.splice(low, 0, candidate);
3035
+ if (scored.length > limit) scored.pop();
3036
+ }
3037
+ }
3038
+ }
3039
+ if (limit === Infinity) scored.sort(compare);
3040
+ return scored.map((entry) => entry.item);
3041
+ }
2901
3042
 
2902
3043
  // src/genre-tree/useSearchQueryState.ts
2903
3044
  var import_react15 = require("react");
@@ -2931,7 +3072,15 @@ function useGenreSearch({
2931
3072
  onClear
2932
3073
  }) {
2933
3074
  const { query, setQuery, isTyping, canClear, clear, notifyPick } = useSearchQueryState({ selectedName, onClear });
2934
- const results = isTyping ? searchGenrePlaylistsByName(genrePlaylists, query) : [];
3075
+ const index = (0, import_react16.useMemo)(
3076
+ () => createNameIndex(genrePlaylists, (playlist) => playlist.name, (playlist) => playlist.viewsCount ?? 0),
3077
+ [genrePlaylists]
3078
+ );
3079
+ const deferredQuery = (0, import_react16.useDeferredValue)(query);
3080
+ const results = (0, import_react16.useMemo)(
3081
+ () => isTyping ? rankNameIndex(index, deferredQuery) : [],
3082
+ [index, deferredQuery, isTyping]
3083
+ );
2935
3084
  return {
2936
3085
  query,
2937
3086
  setQuery,
@@ -2946,32 +3095,32 @@ function useGenreSearch({
2946
3095
  }
2947
3096
 
2948
3097
  // src/genre-tree/schemas/genre-search.ts
2949
- var import_zod33 = require("zod");
2950
- var GenreSearchTreeNameSchema = import_zod33.z.enum(["canonical", "regional"]);
2951
- var GenreSearchResultSchema = import_zod33.z.object({
3098
+ var import_zod34 = require("zod");
3099
+ var GenreSearchTreeNameSchema = import_zod34.z.enum(["canonical", "regional"]);
3100
+ var GenreSearchResultSchema = import_zod34.z.object({
2952
3101
  /** Criteria (genre) uuid. */
2953
3102
  uuid: GenreUuidSchema,
2954
- name: import_zod33.z.string(),
3103
+ name: import_zod34.z.string(),
2955
3104
  /** Null for app-created genres, which the Wikidata-keyed region index does not reference. */
2956
- wikidataId: import_zod33.z.string().nullable(),
2957
- treeName: import_zod33.z.string(),
3105
+ wikidataId: import_zod34.z.string().nullable(),
3106
+ treeName: import_zod34.z.string(),
2958
3107
  /** Null when the genre has no playlist in the tree, so it cannot be opened there. */
2959
3108
  genrePlaylistUuid: GenrePlaylistUuidSchema.nullable(),
2960
- root: import_zod33.z.object({ uuid: GenreUuidSchema, name: import_zod33.z.string() }),
2961
- isUmbrella: import_zod33.z.boolean(),
2962
- viewsCount: import_zod33.z.number().int()
3109
+ root: import_zod34.z.object({ uuid: GenreUuidSchema, name: import_zod34.z.string() }),
3110
+ isUmbrella: import_zod34.z.boolean(),
3111
+ viewsCount: import_zod34.z.number().int()
2963
3112
  });
2964
- var GenreSearchResultsSchema = import_zod33.z.array(GenreSearchResultSchema);
2965
- var RegionGenreLexiconEntrySchema = import_zod33.z.object({
2966
- wikidataId: import_zod33.z.string(),
3113
+ var GenreSearchResultsSchema = import_zod34.z.array(GenreSearchResultSchema);
3114
+ var RegionGenreLexiconEntrySchema = import_zod34.z.object({
3115
+ wikidataId: import_zod34.z.string(),
2967
3116
  uuid: GenreUuidSchema,
2968
- name: import_zod33.z.string(),
2969
- treeName: import_zod33.z.string(),
3117
+ name: import_zod34.z.string(),
3118
+ treeName: import_zod34.z.string(),
2970
3119
  genrePlaylistUuid: GenrePlaylistUuidSchema.nullable(),
2971
- isUmbrella: import_zod33.z.boolean(),
2972
- viewsCount: import_zod33.z.number().int()
3120
+ isUmbrella: import_zod34.z.boolean(),
3121
+ viewsCount: import_zod34.z.number().int()
2973
3122
  });
2974
- var RegionGenreLexiconSchema = import_zod33.z.array(RegionGenreLexiconEntrySchema);
3123
+ var RegionGenreLexiconSchema = import_zod34.z.array(RegionGenreLexiconEntrySchema);
2975
3124
 
2976
3125
  // src/genre-tree/useGenreRemoteSearch.ts
2977
3126
  var DEFAULT_RESULT_LIMIT2 = 8;
@@ -2990,6 +3139,7 @@ function useGenreRemoteSearch(getBackendBaseUrl, text, { treeName, limit = DEFAU
2990
3139
  }
2991
3140
 
2992
3141
  // src/genre-tree/useRegionGenreLexicon.ts
3142
+ var EMPTY_ENTRIES = [];
2993
3143
  function useRegionGenreLexicon(getBackendBaseUrl, enabled) {
2994
3144
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2995
3145
  const { data, isError, isPending } = useQueryWithParse({
@@ -3000,15 +3150,15 @@ function useRegionGenreLexicon(getBackendBaseUrl, enabled) {
3000
3150
  enabled,
3001
3151
  staleTime: Infinity
3002
3152
  });
3003
- const entries = data ?? [];
3153
+ const entries = data ?? EMPTY_ENTRIES;
3004
3154
  return { entries, isError, isPending: enabled && isPending };
3005
3155
  }
3006
3156
 
3007
3157
  // src/genre-tree/useGenreTreeViewState.ts
3008
- var import_react17 = require("react");
3158
+ var import_react18 = require("react");
3009
3159
 
3010
3160
  // src/genre-tree/useVisibleGenrePlaylists.ts
3011
- var import_react16 = require("react");
3161
+ var import_react17 = require("react");
3012
3162
 
3013
3163
  // src/genre-tree/lib/prune-genre-playlists-for-artist.ts
3014
3164
  var POP_ROOT_NAME = "Mainstream Pop";
@@ -3018,7 +3168,7 @@ var pruneGenrePlaylistsForArtist = (playlists, counts) => {
3018
3168
  const kept = /* @__PURE__ */ new Set();
3019
3169
  for (const playlist of playlists) {
3020
3170
  const isPopRoot = playlist.parent === null && playlist.name === POP_ROOT_NAME;
3021
- if (isPopRoot || (countByPlaylist.get(playlist.uuid)?.songsCount ?? 0) > 0) kept.add(playlist.uuid);
3171
+ if (isPopRoot || (countByPlaylist.get(playlist.uuid)?.catalogue.genreAndSubgenresTracksCount.all ?? 0) > 0) kept.add(playlist.uuid);
3022
3172
  }
3023
3173
  const coreElectronicUuids = new Set(
3024
3174
  playlists.filter((playlist) => playlist.name === CORE_ELECTRONIC_NAME && kept.has(playlist.uuid)).map((p) => p.uuid)
@@ -3026,12 +3176,22 @@ var pruneGenrePlaylistsForArtist = (playlists, counts) => {
3026
3176
  for (const playlist of playlists) {
3027
3177
  if (playlist.parent && coreElectronicUuids.has(playlist.parent.uuid)) kept.add(playlist.uuid);
3028
3178
  }
3029
- return playlists.filter((playlist) => kept.has(playlist.uuid)).map((playlist) => ({
3030
- ...playlist,
3031
- tracksCount: countByPlaylist.get(playlist.uuid)?.tracksCount ?? 0,
3032
- // Per-artist view totals are not served, so the views metric is unavailable on a pruned tree.
3033
- viewsCount: 0
3034
- }));
3179
+ return playlists.filter((playlist) => kept.has(playlist.uuid)).map((playlist) => {
3180
+ const count = countByPlaylist.get(playlist.uuid);
3181
+ const catalogue = GenreCatalogueCountsSchema.parse(playlist.catalogue);
3182
+ const scopes = playlist.genreAndSubgenresTracksCount;
3183
+ if (!scopes) throw new Error("Artist projections require a reference genre summary");
3184
+ const zero = { genreOnlyTracksCount: 0, genreAndSubgenresTracksCount: "canonical" in scopes ? { canonical: 0, regional: 0, all: 0 } : { all: 0 } };
3185
+ return {
3186
+ ...playlist,
3187
+ genreOnlyTracksCount: count?.genreOnlyTracksCount ?? 0,
3188
+ genreAndSubgenresTracksCount: count?.genreAndSubgenresTracksCount ?? zero.genreAndSubgenresTracksCount,
3189
+ catalogue: count?.catalogue ?? { ...catalogue, ...zero },
3190
+ tracksCount: count ? genreMusicCount(count) : 0,
3191
+ // Artist view totals are not served.
3192
+ viewsCount: void 0
3193
+ };
3194
+ });
3035
3195
  };
3036
3196
 
3037
3197
  // src/genre-tree/useVisibleGenrePlaylists.ts
@@ -3040,7 +3200,7 @@ function useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid = null
3040
3200
  const counts = useArtistGenreCounts(artistUuid, getBackendBaseUrl);
3041
3201
  const artistCounts = artistUuid !== null ? counts.data : void 0;
3042
3202
  const isCountsLoading = artistUuid !== null && (counts.isPending || counts.isPlaceholderData);
3043
- const genrePlaylists = (0, import_react16.useMemo)(() => {
3203
+ const genrePlaylists = (0, import_react17.useMemo)(() => {
3044
3204
  if (!tree) return [];
3045
3205
  return artistCounts ? pruneGenrePlaylistsForArtist(tree, artistCounts) : tree;
3046
3206
  }, [tree, artistCounts]);
@@ -3068,12 +3228,12 @@ function useGenreTreeViewState({
3068
3228
  onSelectedNodeIdChange,
3069
3229
  criteriaOverviewSchema
3070
3230
  }) {
3071
- const [internalViewMode, setInternalViewMode] = (0, import_react17.useState)("pop-core");
3072
- const [allowWheelRotation, setAllowWheelRotation] = (0, import_react17.useState)(false);
3073
- const [internalSelectedNodeId, setInternalSelectedNodeId] = (0, import_react17.useState)(null);
3231
+ const [internalViewMode, setInternalViewMode] = (0, import_react18.useState)("pop-core");
3232
+ const [allowWheelRotation, setAllowWheelRotation] = (0, import_react18.useState)(false);
3233
+ const [internalSelectedNodeId, setInternalSelectedNodeId] = (0, import_react18.useState)(null);
3074
3234
  const isSelectionControlled = controlledSelectedNodeId !== void 0;
3075
3235
  const requestedSelectedNodeId = isSelectionControlled ? controlledSelectedNodeId : internalSelectedNodeId;
3076
- const setSelectedNodeId = (0, import_react17.useCallback)(
3236
+ const setSelectedNodeId = (0, import_react18.useCallback)(
3077
3237
  (nodeId) => {
3078
3238
  if (!isSelectionControlled) setInternalSelectedNodeId(nodeId);
3079
3239
  onSelectedNodeIdChange?.(nodeId);
@@ -3081,35 +3241,35 @@ function useGenreTreeViewState({
3081
3241
  [isSelectionControlled, onSelectedNodeIdChange]
3082
3242
  );
3083
3243
  const { isLoading, isFetching, genrePlaylists } = useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid });
3084
- const genrePlaylistByNodeId = (0, import_react17.useMemo)(() => new Map(genrePlaylists.map((gp) => [gp.uuid, gp])), [genrePlaylists]);
3085
- const selectedGenrePlaylist = (0, import_react17.useMemo)(
3244
+ const genrePlaylistByNodeId = (0, import_react18.useMemo)(() => new Map(genrePlaylists.map((gp) => [gp.uuid, gp])), [genrePlaylists]);
3245
+ const selectedGenrePlaylist = (0, import_react18.useMemo)(
3086
3246
  () => genrePlaylists.find((gp) => gp.uuid === requestedSelectedNodeId) ?? // Older shared links stored the criteria UUID in `genre`; resolve that alias while preserving
3087
3247
  // the playlist UUID as the canonical tree selection identity.
3088
3248
  genrePlaylists.find((gp) => gp.criteria?.uuid === requestedSelectedNodeId),
3089
3249
  [genrePlaylists, requestedSelectedNodeId]
3090
3250
  );
3091
3251
  const selectedNodeId = selectedGenrePlaylist?.uuid ?? requestedSelectedNodeId;
3092
- (0, import_react17.useEffect)(() => {
3252
+ (0, import_react18.useEffect)(() => {
3093
3253
  if (!isSelectionControlled || requestedSelectedNodeId == null || selectedGenrePlaylist == null || requestedSelectedNodeId === selectedGenrePlaylist.uuid) {
3094
3254
  return;
3095
3255
  }
3096
3256
  onSelectedNodeIdChange?.(selectedGenrePlaylist.uuid);
3097
3257
  }, [isSelectionControlled, onSelectedNodeIdChange, requestedSelectedNodeId, selectedGenrePlaylist]);
3098
- const selectNode = (0, import_react17.useCallback)((node) => setSelectedNodeId(node?.id ?? null), [setSelectedNodeId]);
3099
- const clearSelection = (0, import_react17.useCallback)(() => setSelectedNodeId(null), [setSelectedNodeId]);
3100
- const selectGenrePlaylist = (0, import_react17.useCallback)(
3258
+ const selectNode = (0, import_react18.useCallback)((node) => setSelectedNodeId(node?.id ?? null), [setSelectedNodeId]);
3259
+ const clearSelection = (0, import_react18.useCallback)(() => setSelectedNodeId(null), [setSelectedNodeId]);
3260
+ const selectGenrePlaylist = (0, import_react18.useCallback)(
3101
3261
  (genrePlaylist) => setSelectedNodeId(genrePlaylist.uuid),
3102
3262
  [setSelectedNodeId]
3103
3263
  );
3104
3264
  const prefetchGenreOverview = usePrefetchGenreOverview(scope, getBackendBaseUrl, criteriaOverviewSchema);
3105
- const hoverPrefetchTimerRef = (0, import_react17.useRef)(null);
3106
- (0, import_react17.useEffect)(
3265
+ const hoverPrefetchTimerRef = (0, import_react18.useRef)(null);
3266
+ (0, import_react18.useEffect)(
3107
3267
  () => () => {
3108
3268
  if (hoverPrefetchTimerRef.current) clearTimeout(hoverPrefetchTimerRef.current);
3109
3269
  },
3110
3270
  []
3111
3271
  );
3112
- const onNodeHover = (0, import_react17.useCallback)(
3272
+ const onNodeHover = (0, import_react18.useCallback)(
3113
3273
  (node) => {
3114
3274
  if (hoverPrefetchTimerRef.current) clearTimeout(hoverPrefetchTimerRef.current);
3115
3275
  const genreUuid = genrePlaylistByNodeId.get(node.id)?.criteria?.uuid;
@@ -3120,8 +3280,8 @@ function useGenreTreeViewState({
3120
3280
  },
3121
3281
  [genrePlaylistByNodeId, prefetchGenreOverview]
3122
3282
  );
3123
- const groupedGenrePlaylistsByRoot = (0, import_react17.useMemo)(() => getGenrePlaylistsGroupedByRoot(genrePlaylists), [genrePlaylists]);
3124
- const canShowPopCore = (0, import_react17.useMemo)(
3283
+ const groupedGenrePlaylistsByRoot = (0, import_react18.useMemo)(() => getGenrePlaylistsGroupedByRoot(genrePlaylists), [genrePlaylists]);
3284
+ const canShowPopCore = (0, import_react18.useMemo)(
3125
3285
  () => hasMainstreamPopRoot(
3126
3286
  genrePlaylists.map((genrePlaylist) => ({
3127
3287
  parentId: genrePlaylist.parent?.uuid ?? null,
@@ -3130,14 +3290,14 @@ function useGenreTreeViewState({
3130
3290
  ),
3131
3291
  [genrePlaylists]
3132
3292
  );
3133
- (0, import_react17.useEffect)(() => {
3293
+ (0, import_react18.useEffect)(() => {
3134
3294
  if (!isLoading && needsPopCore(internalViewMode) && !canShowPopCore) {
3135
3295
  setInternalViewMode("wheel");
3136
3296
  }
3137
3297
  }, [isLoading, canShowPopCore, internalViewMode]);
3138
3298
  const selectedViewMode = controlledViewMode ?? internalViewMode;
3139
3299
  const viewMode = needsPopCore(selectedViewMode) && !canShowPopCore ? "wheel" : selectedViewMode;
3140
- const visibleGenrePlaylists = (0, import_react17.useMemo)(() => {
3300
+ const visibleGenrePlaylists = (0, import_react18.useMemo)(() => {
3141
3301
  if (viewMode === "stacked") return genrePlaylists;
3142
3302
  const unacceptedRootUuids = new Set(genrePlaylists.filter((gp) => gp.isUnacceptedRoot).map((gp) => gp.uuid));
3143
3303
  const accepted = genrePlaylists.filter((gp) => !gp.isUnacceptedRoot && !unacceptedRootUuids.has(gp.root.uuid));
@@ -3166,13 +3326,13 @@ function useGenreTreeViewState({
3166
3326
  }
3167
3327
 
3168
3328
  // src/genre-tree/TrackListContext.tsx
3169
- var import_react19 = require("react");
3329
+ var import_react20 = require("react");
3170
3330
 
3171
3331
  // src/genre-tree/schemas/track-playlist-rel/without-playlist.ts
3172
- var import_zod34 = require("zod");
3173
- var makeTrackPlaylistRelSchema = (trackSchema) => import_zod34.z.object({
3332
+ var import_zod35 = require("zod");
3333
+ var makeTrackPlaylistRelSchema = (trackSchema) => import_zod35.z.object({
3174
3334
  track: trackSchema,
3175
- position: import_zod34.z.number().min(0)
3335
+ position: import_zod35.z.number().min(0)
3176
3336
  });
3177
3337
  var makeTrackPlaylistRelPageSchema = (trackSchema) => PaginatedResponseSchema(makeTrackPlaylistRelSchema(trackSchema));
3178
3338
 
@@ -3221,6 +3381,7 @@ var TrackListFromArtist = class extends TrackList {
3221
3381
  var TrackListOriginType = /* @__PURE__ */ ((TrackListOriginType2) => {
3222
3382
  TrackListOriginType2["TRACK"] = "TRACK";
3223
3383
  TrackListOriginType2["GENRE_PLAYLIST"] = "GENRE_PLAYLIST";
3384
+ TrackListOriginType2["GENRE_CATALOGUE"] = "GENRE_CATALOGUE";
3224
3385
  TrackListOriginType2["ARTIST"] = "ARTIST";
3225
3386
  return TrackListOriginType2;
3226
3387
  })(TrackListOriginType || {});
@@ -3252,45 +3413,66 @@ var TrackListOriginFromTrack = class extends TrackListOrigin {
3252
3413
  };
3253
3414
  var TrackListOriginFromCriteriaPlaylist = class extends TrackListOrigin {
3254
3415
  /** `from`: the track the list starts at (server-side `?from=`), kept so later pages use it too. */
3255
- constructor(criteriaPlaylist, scope, from) {
3416
+ constructor(criteriaPlaylist, scope, from, selection, artistUuid) {
3256
3417
  super("GENRE_PLAYLIST" /* GENRE_PLAYLIST */, criteriaPlaylist.name, criteriaPlaylist.uuid, scope);
3257
3418
  this.criteriaPlaylist = criteriaPlaylist;
3258
3419
  this.from = from;
3420
+ this.selection = selection;
3421
+ this.artistUuid = artistUuid;
3259
3422
  }
3260
3423
  criteriaPlaylist;
3261
3424
  from;
3425
+ selection;
3426
+ artistUuid;
3262
3427
  };
3263
3428
  var TrackListOriginFromArtist = class extends TrackListOrigin {
3264
3429
  /** `ordering`/`from`: kept so later pages use the same order and start track. */
3265
- constructor(artist, scope, ordering, from, genreUuid) {
3430
+ constructor(artist, scope, ordering, from, genreUuid, selection) {
3266
3431
  super("ARTIST" /* ARTIST */, artist.name, artist.uuid, scope);
3267
3432
  this.artist = artist;
3268
3433
  this.ordering = ordering;
3269
3434
  this.from = from;
3270
3435
  this.genreUuid = genreUuid;
3436
+ this.selection = selection;
3271
3437
  }
3272
3438
  artist;
3273
3439
  ordering;
3274
3440
  from;
3275
3441
  genreUuid;
3442
+ selection;
3443
+ };
3444
+ var TrackListOriginFromGenreCatalogue = class extends TrackListOrigin {
3445
+ constructor(genre, scope, from, selection) {
3446
+ super("GENRE_CATALOGUE" /* GENRE_CATALOGUE */, genre.name, genre.uuid, scope);
3447
+ this.genre = genre;
3448
+ this.from = from;
3449
+ this.selection = selection;
3450
+ }
3451
+ genre;
3452
+ from;
3453
+ selection;
3454
+ ordering = "title";
3455
+ get genreUuid() {
3456
+ return this.genre.uuid;
3457
+ }
3276
3458
  };
3277
3459
 
3278
3460
  // src/genre-tree/TrackListSidebarVisibilityContext.tsx
3279
- var import_react18 = require("react");
3461
+ var import_react19 = require("react");
3280
3462
  var import_jsx_runtime7 = require("react/jsx-runtime");
3281
- var TrackListSidebarVisibilityContext = (0, import_react18.createContext)(void 0);
3463
+ var TrackListSidebarVisibilityContext = (0, import_react19.createContext)(void 0);
3282
3464
  function TrackListSidebarVisibilityProvider({ children }) {
3283
- const [isTrackListSidebarVisible, setIsTrackListSidebarVisible] = (0, import_react18.useState)(false);
3284
- const toggleTrackListSidebar = (0, import_react18.useCallback)(() => {
3465
+ const [isTrackListSidebarVisible, setIsTrackListSidebarVisible] = (0, import_react19.useState)(false);
3466
+ const toggleTrackListSidebar = (0, import_react19.useCallback)(() => {
3285
3467
  setIsTrackListSidebarVisible((prev) => !prev);
3286
3468
  }, []);
3287
- const showTrackListSidebar = (0, import_react18.useCallback)(() => {
3469
+ const showTrackListSidebar = (0, import_react19.useCallback)(() => {
3288
3470
  setIsTrackListSidebarVisible(true);
3289
3471
  }, []);
3290
- const hideTrackListSidebar = (0, import_react18.useCallback)(() => {
3472
+ const hideTrackListSidebar = (0, import_react19.useCallback)(() => {
3291
3473
  setIsTrackListSidebarVisible(false);
3292
3474
  }, []);
3293
- const value = (0, import_react18.useMemo)(
3475
+ const value = (0, import_react19.useMemo)(
3294
3476
  () => ({
3295
3477
  isTrackListSidebarVisible,
3296
3478
  toggleTrackListSidebar,
@@ -3302,7 +3484,7 @@ function TrackListSidebarVisibilityProvider({ children }) {
3302
3484
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TrackListSidebarVisibilityContext.Provider, { value, children });
3303
3485
  }
3304
3486
  function useTrackListSidebarVisibility() {
3305
- const context = (0, import_react18.useContext)(TrackListSidebarVisibilityContext);
3487
+ const context = (0, import_react19.useContext)(TrackListSidebarVisibilityContext);
3306
3488
  if (context === void 0) {
3307
3489
  throw new Error("useTrackListSidebarVisibility must be used within a TrackListSidebarVisibilityProvider");
3308
3490
  }
@@ -3332,45 +3514,45 @@ function useListTracks(scope, getBackendBaseUrl, schema, listEndpoint, listQuery
3332
3514
  enabled: playback.ready && scope != null && (scope === "reference" || sessionRestored && !!session?.accessToken)
3333
3515
  });
3334
3516
  }
3335
- var TrackListContext = (0, import_react19.createContext)(void 0);
3517
+ var TrackListContext = (0, import_react20.createContext)(void 0);
3336
3518
  function TrackListProvider({
3337
3519
  children,
3338
3520
  getBackendBaseUrl,
3339
3521
  schema
3340
3522
  }) {
3341
- const [trackList, setTrackList] = (0, import_react19.useState)(null);
3342
- const [selectedTrack, setSelectedTrack] = (0, import_react19.useState)(null);
3343
- const [autoAdvanceScrollRequest, setAutoAdvanceScrollRequest] = (0, import_react19.useState)(null);
3523
+ const [trackList, setTrackList] = (0, import_react20.useState)(null);
3524
+ const [selectedTrack, setSelectedTrack] = (0, import_react20.useState)(null);
3525
+ const [autoAdvanceScrollRequest, setAutoAdvanceScrollRequest] = (0, import_react20.useState)(null);
3344
3526
  const { loadTrackForPlayer, setOnTrackEnd, hasPlaybackFailure, playerTrackObject } = usePlayer();
3345
- const [failureClock, setFailureClock] = (0, import_react19.useState)(0);
3346
- (0, import_react19.useEffect)(() => {
3527
+ const [failureClock, setFailureClock] = (0, import_react20.useState)(0);
3528
+ (0, import_react20.useEffect)(() => {
3347
3529
  const timer = setInterval(() => setFailureClock((tick) => tick + 1), 3e4);
3348
3530
  return () => clearInterval(timer);
3349
3531
  }, []);
3350
- const runtimeUnplayableTrackIds = (0, import_react19.useMemo)(() => new Set(
3532
+ const runtimeUnplayableTrackIds = (0, import_react20.useMemo)(() => new Set(
3351
3533
  (trackList?.tracks ?? []).filter((track) => isSong(track) && track.youtubeVideo && hasPlaybackFailure(track.youtubeVideo.id)).map((track) => track.uuid)
3352
3534
  ), [trackList, hasPlaybackFailure, playerTrackObject, failureClock]);
3353
3535
  const { showTrackListSidebar } = useTrackListSidebarVisibility();
3354
3536
  const playback = usePlaybackContext();
3355
3537
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
3356
- const pageSchema = (0, import_react19.useMemo)(() => makeTrackPlaylistRelPageSchema(schema), [schema]);
3357
- const latestPlayRequestRef = (0, import_react19.useRef)(0);
3358
- const startingPlaybackRef = (0, import_react19.useRef)(false);
3359
- const loadedContextRef = (0, import_react19.useRef)(playback.key);
3360
- const autoAdvanceScrollRequestIdRef = (0, import_react19.useRef)(0);
3361
- const delayedTrackLoadRef = (0, import_react19.useRef)(null);
3362
- const loadingOriginRef = (0, import_react19.useRef)(null);
3363
- const pendingAdvanceRef = (0, import_react19.useRef)(null);
3364
- const clearDelayedTrackLoad = (0, import_react19.useCallback)(() => {
3538
+ const pageSchema = (0, import_react20.useMemo)(() => makeTrackPlaylistRelPageSchema(schema), [schema]);
3539
+ const latestPlayRequestRef = (0, import_react20.useRef)(0);
3540
+ const startingPlaybackRef = (0, import_react20.useRef)(false);
3541
+ const loadedContextRef = (0, import_react20.useRef)(playback.key);
3542
+ const autoAdvanceScrollRequestIdRef = (0, import_react20.useRef)(0);
3543
+ const delayedTrackLoadRef = (0, import_react20.useRef)(null);
3544
+ const loadingOriginRef = (0, import_react20.useRef)(null);
3545
+ const pendingAdvanceRef = (0, import_react20.useRef)(null);
3546
+ const clearDelayedTrackLoad = (0, import_react20.useCallback)(() => {
3365
3547
  if (delayedTrackLoadRef.current !== null) {
3366
3548
  clearTimeout(delayedTrackLoadRef.current);
3367
3549
  delayedTrackLoadRef.current = null;
3368
3550
  }
3369
3551
  }, []);
3370
- const requestAutoAdvanceScroll = (0, import_react19.useCallback)((trackUuid) => {
3552
+ const requestAutoAdvanceScroll = (0, import_react20.useCallback)((trackUuid) => {
3371
3553
  setAutoAdvanceScrollRequest({ id: ++autoAdvanceScrollRequestIdRef.current, trackUuid });
3372
3554
  }, []);
3373
- const loadTrackAfterSkipDelay = (0, import_react19.useCallback)(
3555
+ const loadTrackAfterSkipDelay = (0, import_react20.useCallback)(
3374
3556
  (trackUuid) => {
3375
3557
  clearDelayedTrackLoad();
3376
3558
  delayedTrackLoadRef.current = setTimeout(() => {
@@ -3380,10 +3562,11 @@ function TrackListProvider({
3380
3562
  },
3381
3563
  [clearDelayedTrackLoad, loadTrackForPlayer]
3382
3564
  );
3383
- const fetchTracksPage = (0, import_react19.useCallback)(
3384
- async (uuid, scope, page, from) => {
3565
+ const fetchTracksPage = (0, import_react20.useCallback)(
3566
+ async (uuid, scope, page, from, selection, artistUuid) => {
3385
3567
  const endpoint = genrePlaylistEndpoints[scope].tracks(uuid);
3386
- const params = { page, pageSize: TRACKS_PAGE_SIZE, ...from && { from } };
3568
+ if (scope === "me" && (selection || artistUuid)) throw new Error("Genre selections require reference scope");
3569
+ const params = { page, pageSize: TRACKS_PAGE_SIZE, ...from && { from }, ...genreMusicQueryParams(selection), ...artistUuid && { artist: artistUuid } };
3387
3570
  const response = await fetch2(endpoint, true, scope === "me", {}, params, false, !!from, page === 1);
3388
3571
  const parsed = parseWithLog(pageSchema, response, "fetchGenrePlaylistTracksPage");
3389
3572
  return {
@@ -3394,17 +3577,18 @@ function TrackListProvider({
3394
3577
  },
3395
3578
  [fetch2, pageSchema]
3396
3579
  );
3397
- const artistPageSchema = (0, import_react19.useMemo)(() => PaginatedResponseSchema(schema), [schema]);
3398
- const fetchArtistTracksPage = (0, import_react19.useCallback)(
3580
+ const cataloguePageSchema = (0, import_react20.useMemo)(() => PaginatedResponseSchema(schema), [schema]);
3581
+ const fetchCatalogueTracksPage = (0, import_react20.useCallback)(
3399
3582
  async (origin, page) => {
3400
3583
  const params = {
3401
- artist: origin.uuid,
3584
+ ...origin instanceof TrackListOriginFromArtist && { artist: origin.uuid },
3402
3585
  playable: true,
3403
3586
  ordering: origin.ordering,
3404
3587
  page,
3405
3588
  pageSize: TRACKS_PAGE_SIZE,
3406
3589
  ...origin.from && { from: origin.from },
3407
- ...origin.genreUuid && { genre: origin.genreUuid }
3590
+ ...origin.genreUuid && { genre: origin.genreUuid },
3591
+ ...genreMusicQueryParams(origin.selection)
3408
3592
  };
3409
3593
  const response = await fetch2(
3410
3594
  libraryEndpoints.reference.songs.list(),
@@ -3417,12 +3601,12 @@ function TrackListProvider({
3417
3601
  page === 1 && !!origin.from,
3418
3602
  page === 1
3419
3603
  );
3420
- const parsed = parseWithLog(artistPageSchema, response, "fetchArtistTracksPage");
3604
+ const parsed = parseWithLog(cataloguePageSchema, response, "fetchCatalogueTracksPage");
3421
3605
  return { tracks: parsed.results, total: parsed.overallTotal, nextPage: parsed.next ? parsed.page + 1 : null };
3422
3606
  },
3423
- [fetch2, artistPageSchema]
3607
+ [fetch2, cataloguePageSchema]
3424
3608
  );
3425
- const advanceAfterTrackEnd = (0, import_react19.useCallback)(
3609
+ const advanceAfterTrackEnd = (0, import_react20.useCallback)(
3426
3610
  (event) => {
3427
3611
  const completedTrackId = event?.trackId ?? selectedTrack?.uuid;
3428
3612
  if (!completedTrackId || !trackList) return;
@@ -3454,11 +3638,11 @@ function TrackListProvider({
3454
3638
  selectedTrack
3455
3639
  ]
3456
3640
  );
3457
- (0, import_react19.useEffect)(() => {
3641
+ (0, import_react20.useEffect)(() => {
3458
3642
  setOnTrackEnd(trackList && selectedTrack ? advanceAfterTrackEnd : null);
3459
3643
  return () => setOnTrackEnd(null);
3460
3644
  }, [advanceAfterTrackEnd, trackList, selectedTrack, setOnTrackEnd]);
3461
- const toTrackAtPosition = (0, import_react19.useCallback)(
3645
+ const toTrackAtPosition = (0, import_react20.useCallback)(
3462
3646
  (position) => {
3463
3647
  if (trackList && position >= 0 && position < trackList.tracks.length) {
3464
3648
  clearDelayedTrackLoad();
@@ -3468,7 +3652,7 @@ function TrackListProvider({
3468
3652
  },
3469
3653
  [clearDelayedTrackLoad, trackList]
3470
3654
  );
3471
- const playNewTrackListFromTrackUuid = (0, import_react19.useCallback)(
3655
+ const playNewTrackListFromTrackUuid = (0, import_react20.useCallback)(
3472
3656
  (track, scope) => {
3473
3657
  latestPlayRequestRef.current++;
3474
3658
  startingPlaybackRef.current = false;
@@ -3484,7 +3668,7 @@ function TrackListProvider({
3484
3668
  },
3485
3669
  [clearDelayedTrackLoad, showTrackListSidebar, loadTrackForPlayer]
3486
3670
  );
3487
- const playNewTrackListFromGenrePlaylist = (0, import_react19.useCallback)(
3671
+ const playNewTrackListFromGenrePlaylist = (0, import_react20.useCallback)(
3488
3672
  async (genrePlaylist, scope, options) => {
3489
3673
  clearDelayedTrackLoad();
3490
3674
  const request = ++latestPlayRequestRef.current;
@@ -3492,7 +3676,7 @@ function TrackListProvider({
3492
3676
  const from = options?.startSongUuid;
3493
3677
  let page;
3494
3678
  try {
3495
- page = await fetchTracksPage(genrePlaylist.uuid, scope, 1, from);
3679
+ page = await fetchTracksPage(genrePlaylist.uuid, scope, 1, from, options?.selection, options?.artistUuid);
3496
3680
  } catch (error) {
3497
3681
  if (request !== latestPlayRequestRef.current) return;
3498
3682
  startingPlaybackRef.current = false;
@@ -3509,7 +3693,7 @@ function TrackListProvider({
3509
3693
  console.warn("No playable tracks found in genre playlist");
3510
3694
  return;
3511
3695
  }
3512
- const origin = new TrackListOriginFromCriteriaPlaylist(genrePlaylist, scope, from);
3696
+ const origin = new TrackListOriginFromCriteriaPlaylist(genrePlaylist, scope, from, options?.selection, options?.artistUuid);
3513
3697
  setAutoAdvanceScrollRequest(null);
3514
3698
  setTrackList(new TrackListFromCriteriaPlaylist(page.tracks, origin, page.total, page.nextPage));
3515
3699
  setSelectedTrack(startTrack);
@@ -3518,17 +3702,15 @@ function TrackListProvider({
3518
3702
  },
3519
3703
  [clearDelayedTrackLoad, fetchTracksPage, showTrackListSidebar, loadTrackForPlayer]
3520
3704
  );
3521
- const playNewTrackListFromArtist = (0, import_react19.useCallback)(
3522
- async (artist, scope, options) => {
3523
- if (scope !== "reference") throw new Error("Artist track lists only support the reference scope");
3705
+ const playCatalogue = (0, import_react20.useCallback)(
3706
+ async (origin) => {
3524
3707
  clearDelayedTrackLoad();
3525
3708
  const request = ++latestPlayRequestRef.current;
3526
3709
  startingPlaybackRef.current = true;
3527
- const from = options.startSongUuid;
3528
- const origin = new TrackListOriginFromArtist(artist, scope, options.ordering, from, options.genreUuid);
3710
+ const from = origin.from;
3529
3711
  let page;
3530
3712
  try {
3531
- page = await fetchArtistTracksPage(origin, 1);
3713
+ page = await fetchCatalogueTracksPage(origin, 1);
3532
3714
  } catch (error) {
3533
3715
  if (request !== latestPlayRequestRef.current) return;
3534
3716
  startingPlaybackRef.current = false;
@@ -3539,22 +3721,37 @@ function TrackListProvider({
3539
3721
  loadedContextRef.current = playback.snapshot().key;
3540
3722
  const startTrack = page.tracks[0];
3541
3723
  if (from && startTrack?.uuid !== from) {
3542
- throw new Error(`Artist ${artist.uuid} did not start at song ${from}`);
3724
+ throw new Error(`${origin instanceof TrackListOriginFromArtist ? "Artist" : "Catalogue"} ${origin.uuid} did not start at song ${from}`);
3543
3725
  }
3544
3726
  if (!startTrack) {
3545
- console.warn("No playable songs found for artist");
3727
+ console.warn("No playable songs found in catalogue");
3546
3728
  return;
3547
3729
  }
3548
- setTrackList(new TrackListFromArtist(page.tracks, origin, page.total, page.nextPage));
3730
+ setTrackList(origin instanceof TrackListOriginFromArtist ? new TrackListFromArtist(page.tracks, origin, page.total, page.nextPage) : new TrackList(page.tracks, origin, page.total, page.nextPage));
3549
3731
  setAutoAdvanceScrollRequest(null);
3550
3732
  setSelectedTrack(startTrack);
3551
3733
  showTrackListSidebar();
3552
3734
  loadTrackForPlayer(startTrack.uuid);
3553
3735
  },
3554
- [clearDelayedTrackLoad, fetchArtistTracksPage, showTrackListSidebar, loadTrackForPlayer]
3736
+ [clearDelayedTrackLoad, fetchCatalogueTracksPage, showTrackListSidebar, loadTrackForPlayer]
3737
+ );
3738
+ const playNewTrackListFromArtist = (0, import_react20.useCallback)(
3739
+ async (artist, scope, options) => {
3740
+ if (scope !== "reference") throw new Error("Artist track lists only support the reference scope");
3741
+ if (options.selection && !options.genreUuid) throw new Error("A genre selection requires a genre");
3742
+ return playCatalogue(new TrackListOriginFromArtist(artist, scope, options.ordering, options.startSongUuid, options.genreUuid, options.selection));
3743
+ },
3744
+ [playCatalogue]
3745
+ );
3746
+ const playNewTrackListFromGenreCatalogue = (0, import_react20.useCallback)(
3747
+ async (genre, scope, options) => {
3748
+ if (scope !== "reference") throw new Error("Genre catalogues only support the reference scope");
3749
+ return playCatalogue(new TrackListOriginFromGenreCatalogue(genre, scope, options?.startSongUuid, options?.selection));
3750
+ },
3751
+ [playCatalogue]
3555
3752
  );
3556
- const contextKeyRef = (0, import_react19.useRef)(playback.key);
3557
- (0, import_react19.useEffect)(() => {
3753
+ const contextKeyRef = (0, import_react20.useRef)(playback.key);
3754
+ (0, import_react20.useEffect)(() => {
3558
3755
  if (contextKeyRef.current === playback.key) return;
3559
3756
  contextKeyRef.current = playback.key;
3560
3757
  if (loadedContextRef.current === playback.key) return;
@@ -3573,20 +3770,28 @@ function TrackListProvider({
3573
3770
  setTrackList(null);
3574
3771
  setSelectedTrack(null);
3575
3772
  if (origin instanceof TrackListOriginFromCriteriaPlaylist) {
3576
- void playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope, { startSongUuid: selected?.uuid }).catch((error) => {
3773
+ void playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope, { startSongUuid: selected?.uuid, selection: origin.selection, artistUuid: origin.artistUuid }).catch((error) => {
3577
3774
  if (error instanceof BackendError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */) {
3578
- return playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope).catch(() => {
3775
+ return playNewTrackListFromGenrePlaylist(origin.criteriaPlaylist, origin.scope, { selection: origin.selection, artistUuid: origin.artistUuid }).catch(() => {
3579
3776
  });
3580
3777
  }
3581
3778
  });
3582
3779
  } else if (origin instanceof TrackListOriginFromArtist) {
3583
- const options = { ordering: origin.ordering, genreUuid: origin.genreUuid };
3780
+ const options = { ordering: origin.ordering, genreUuid: origin.genreUuid, selection: origin.selection };
3584
3781
  void playNewTrackListFromArtist(origin.artist, origin.scope, { ...options, startSongUuid: selected?.uuid }).catch((error) => {
3585
3782
  if (error instanceof BackendError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */) {
3586
3783
  return playNewTrackListFromArtist(origin.artist, origin.scope, options).catch(() => {
3587
3784
  });
3588
3785
  }
3589
3786
  });
3787
+ } else if (origin instanceof TrackListOriginFromGenreCatalogue) {
3788
+ const options = { selection: origin.selection };
3789
+ void playNewTrackListFromGenreCatalogue(origin.genre, origin.scope, { ...options, startSongUuid: selected?.uuid }).catch((error) => {
3790
+ if (error instanceof BackendError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */) {
3791
+ return playNewTrackListFromGenreCatalogue(origin.genre, origin.scope, options).catch(() => {
3792
+ });
3793
+ }
3794
+ });
3590
3795
  } else if (origin instanceof TrackListOriginFromTrack && selected) {
3591
3796
  const request = latestPlayRequestRef.current;
3592
3797
  void (async () => {
@@ -3597,8 +3802,8 @@ function TrackListProvider({
3597
3802
  })().catch(() => {
3598
3803
  });
3599
3804
  }
3600
- }, [playback.key, trackList, selectedTrack, clearDelayedTrackLoad, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist, schema, fetch2]);
3601
- const updateTrack = (0, import_react19.useCallback)((track) => {
3805
+ }, [playback.key, trackList, selectedTrack, clearDelayedTrackLoad, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist, playNewTrackListFromGenreCatalogue, schema, fetch2]);
3806
+ const updateTrack = (0, import_react20.useCallback)((track) => {
3602
3807
  setTrackList((prev) => {
3603
3808
  if (!prev || !prev.tracks.some((listed) => listed.uuid === track.uuid)) return prev;
3604
3809
  const tracks = prev.tracks.map((listed) => listed.uuid === track.uuid ? track : listed);
@@ -3606,31 +3811,31 @@ function TrackListProvider({
3606
3811
  });
3607
3812
  setSelectedTrack((prev) => prev?.uuid === track.uuid ? track : prev);
3608
3813
  }, []);
3609
- const loadMore = (0, import_react19.useCallback)(async () => {
3814
+ const loadMore = (0, import_react20.useCallback)(async () => {
3610
3815
  if (!trackList || trackList.nextPage === null) return;
3611
3816
  const origin = trackList.origin;
3612
- if (!(origin instanceof TrackListOriginFromCriteriaPlaylist || origin instanceof TrackListOriginFromArtist)) return;
3817
+ if (!(origin instanceof TrackListOriginFromCriteriaPlaylist || origin instanceof TrackListOriginFromArtist || origin instanceof TrackListOriginFromGenreCatalogue)) return;
3613
3818
  if (loadingOriginRef.current === origin) return;
3614
3819
  const requestedPage = trackList.nextPage;
3615
3820
  loadingOriginRef.current = origin;
3616
3821
  try {
3617
- const page = origin instanceof TrackListOriginFromArtist ? await fetchArtistTracksPage(origin, requestedPage) : await fetchTracksPage(origin.criteriaPlaylist.uuid, origin.scope, requestedPage, origin.from);
3822
+ 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);
3618
3823
  setTrackList((prev) => {
3619
3824
  if (prev?.origin !== origin || prev.nextPage !== requestedPage) return prev;
3620
3825
  const loaded = new Set(prev.tracks.map((track) => track.uuid));
3621
3826
  const tracks = [...prev.tracks, ...page.tracks.filter((track) => !loaded.has(track.uuid))];
3622
- return origin instanceof TrackListOriginFromArtist ? new TrackListFromArtist(tracks, origin, page.total, page.nextPage) : new TrackListFromCriteriaPlaylist(tracks, origin, page.total, page.nextPage);
3827
+ 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);
3623
3828
  });
3624
3829
  } finally {
3625
3830
  if (loadingOriginRef.current === origin) loadingOriginRef.current = null;
3626
3831
  }
3627
- }, [trackList, fetchTracksPage, fetchArtistTracksPage]);
3832
+ }, [trackList, fetchTracksPage, fetchCatalogueTracksPage]);
3628
3833
  const selectedTrackIndex = trackList?.tracks.findIndex((track) => track.uuid === selectedTrack?.uuid) ?? -1;
3629
3834
  const nextTrack = trackList && selectedTrackIndex >= 0 ? trackList.tracks.slice(selectedTrackIndex + 1).find((track) => isTrackPlayable(track, runtimeUnplayableTrackIds, hasPlaybackFailure)) ?? null : null;
3630
3835
  const previousTrack = trackList && selectedTrackIndex > 0 ? trackList.tracks.slice(0, selectedTrackIndex).reverse().find((track) => isTrackPlayable(track, runtimeUnplayableTrackIds, hasPlaybackFailure)) ?? null : null;
3631
3836
  const hasNextTrack = nextTrack !== null || selectedTrackIndex >= 0 && trackList?.nextPage != null;
3632
3837
  const hasPreviousTrack = previousTrack !== null;
3633
- const playNextTrack = (0, import_react19.useCallback)(() => {
3838
+ const playNextTrack = (0, import_react20.useCallback)(() => {
3634
3839
  if (!trackList || !selectedTrack || selectedTrackIndex < 0) return;
3635
3840
  clearDelayedTrackLoad();
3636
3841
  if (nextTrack) {
@@ -3647,7 +3852,7 @@ function TrackListProvider({
3647
3852
  console.error("Failed to load more tracks:", error);
3648
3853
  });
3649
3854
  }, [clearDelayedTrackLoad, trackList, loadMore, loadTrackForPlayer, nextTrack, selectedTrack, selectedTrackIndex]);
3650
- const playPreviousTrack = (0, import_react19.useCallback)(() => {
3855
+ const playPreviousTrack = (0, import_react20.useCallback)(() => {
3651
3856
  if (!previousTrack) return;
3652
3857
  clearDelayedTrackLoad();
3653
3858
  pendingAdvanceRef.current = null;
@@ -3655,7 +3860,7 @@ function TrackListProvider({
3655
3860
  setSelectedTrack(previousTrack);
3656
3861
  loadTrackForPlayer(previousTrack.uuid);
3657
3862
  }, [clearDelayedTrackLoad, loadTrackForPlayer, previousTrack, requestAutoAdvanceScroll]);
3658
- (0, import_react19.useEffect)(() => {
3863
+ (0, import_react20.useEffect)(() => {
3659
3864
  const pending = pendingAdvanceRef.current;
3660
3865
  if (!pending) return;
3661
3866
  if (!trackList || trackList.origin !== pending.origin || selectedTrack?.uuid !== pending.trackId) {
@@ -3689,15 +3894,15 @@ function TrackListProvider({
3689
3894
  hasPlaybackFailure,
3690
3895
  selectedTrack
3691
3896
  ]);
3692
- (0, import_react19.useEffect)(() => clearDelayedTrackLoad, [clearDelayedTrackLoad]);
3693
- (0, import_react19.useEffect)(() => {
3897
+ (0, import_react20.useEffect)(() => clearDelayedTrackLoad, [clearDelayedTrackLoad]);
3898
+ (0, import_react20.useEffect)(() => {
3694
3899
  if (!trackList || trackList.nextPage === null || !selectedTrack) return;
3695
3900
  const index = trackList.tracks.findIndex((track) => track.uuid === selectedTrack.uuid);
3696
3901
  if (index !== -1 && trackList.tracks.length - index <= AUTO_LOAD_REMAINING_TRACKS) {
3697
3902
  loadMore().catch((error) => console.error("Failed to load more tracks:", error));
3698
3903
  }
3699
3904
  }, [trackList, selectedTrack, loadMore]);
3700
- const value = (0, import_react19.useMemo)(
3905
+ const value = (0, import_react20.useMemo)(
3701
3906
  () => ({
3702
3907
  trackList,
3703
3908
  selectedTrack,
@@ -3712,6 +3917,7 @@ function TrackListProvider({
3712
3917
  playNewTrackListFromTrackUuid,
3713
3918
  playNewTrackListFromGenrePlaylist,
3714
3919
  playNewTrackListFromArtist,
3920
+ playNewTrackListFromGenreCatalogue,
3715
3921
  fetchGenrePlaylistTracksPage: fetchTracksPage,
3716
3922
  loadMore,
3717
3923
  updateTrack
@@ -3729,6 +3935,7 @@ function TrackListProvider({
3729
3935
  playNewTrackListFromTrackUuid,
3730
3936
  playNewTrackListFromGenrePlaylist,
3731
3937
  playNewTrackListFromArtist,
3938
+ playNewTrackListFromGenreCatalogue,
3732
3939
  fetchTracksPage,
3733
3940
  loadMore,
3734
3941
  updateTrack
@@ -3737,7 +3944,7 @@ function TrackListProvider({
3737
3944
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(TrackListContext.Provider, { value, children });
3738
3945
  }
3739
3946
  function useTrackList() {
3740
- const context = (0, import_react19.useContext)(TrackListContext);
3947
+ const context = (0, import_react20.useContext)(TrackListContext);
3741
3948
  if (!context) {
3742
3949
  throw new Error("useTrackList must be used within a TrackListProvider");
3743
3950
  }
@@ -3745,38 +3952,38 @@ function useTrackList() {
3745
3952
  }
3746
3953
 
3747
3954
  // src/genre-tree/ArtistNames.tsx
3748
- var import_react20 = require("react");
3955
+ var import_react21 = require("react");
3749
3956
  var import_jsx_runtime9 = require("react/jsx-runtime");
3750
3957
  function ArtistNames({
3751
3958
  artists,
3752
3959
  renderArtistLink
3753
3960
  }) {
3754
3961
  if (!renderArtistLink) return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: artists.map((artist) => artist.name).join(", ") });
3755
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: artists.map((artist, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react20.Fragment, { children: [
3962
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: artists.map((artist, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react21.Fragment, { children: [
3756
3963
  index > 0 && ", ",
3757
3964
  renderArtistLink(artist)
3758
3965
  ] }, artist.uuid)) });
3759
3966
  }
3760
3967
 
3761
3968
  // src/genre-tree/schemas/mb-artist.ts
3762
- var import_zod35 = require("zod");
3763
- var MbArtistDetailedSchema = import_zod35.z.object({
3764
- musicbrainzId: import_zod35.z.string().uuid(),
3765
- name: import_zod35.z.string(),
3969
+ var import_zod36 = require("zod");
3970
+ var MbArtistDetailedSchema = import_zod36.z.object({
3971
+ musicbrainzId: import_zod36.z.string().uuid(),
3972
+ name: import_zod36.z.string(),
3766
3973
  musicbrainzLink: HttpUrlSchema
3767
3974
  });
3768
3975
 
3769
3976
  // src/genre-tree/schemas/mb-recording.ts
3770
- var import_zod36 = require("zod");
3771
- var MbRecordingDetailedSchema = import_zod36.z.object({
3772
- musicbrainzId: import_zod36.z.string().uuid(),
3773
- title: import_zod36.z.string(),
3774
- score: import_zod36.z.number(),
3775
- musicbrainzArtists: import_zod36.z.array(MbArtistDetailedSchema),
3977
+ var import_zod37 = require("zod");
3978
+ var MbRecordingDetailedSchema = import_zod37.z.object({
3979
+ musicbrainzId: import_zod37.z.string().uuid(),
3980
+ title: import_zod37.z.string(),
3981
+ score: import_zod37.z.number(),
3982
+ musicbrainzArtists: import_zod37.z.array(MbArtistDetailedSchema),
3776
3983
  musicbrainzLink: HttpUrlSchema,
3777
- durationInSec: import_zod36.z.number().min(0).nullable().optional(),
3778
- durationStrInHourMinSec: import_zod36.z.string().nullable().optional(),
3779
- releaseDate: import_zod36.z.union([import_zod36.z.string().datetime(), import_zod36.z.string()]).transform((val) => {
3984
+ durationInSec: import_zod37.z.number().min(0).nullable().optional(),
3985
+ durationStrInHourMinSec: import_zod37.z.string().nullable().optional(),
3986
+ releaseDate: import_zod37.z.union([import_zod37.z.string().datetime(), import_zod37.z.string()]).transform((val) => {
3780
3987
  try {
3781
3988
  const date = new Date(val);
3782
3989
  if (isNaN(date.getTime())) {
@@ -3806,6 +4013,9 @@ var capitalizeFirstLetter = (string) => {
3806
4013
  return string.charAt(0).toUpperCase() + string.slice(1);
3807
4014
  };
3808
4015
 
4016
+ // src/genre-tree/lib/genre-search.ts
4017
+ var searchGenrePlaylistsByName = (genrePlaylists, query) => rankByName(genrePlaylists, query, (genrePlaylist) => genrePlaylist.name, (genrePlaylist) => genrePlaylist.viewsCount ?? 0);
4018
+
3809
4019
  // src/genre-tree/lib/reparent-candidates.ts
3810
4020
  var hasCriteria = (genrePlaylist) => genrePlaylist.criteria !== null;
3811
4021
  var getReparentCandidates = (genrePlaylists, genrePlaylistUuid) => {
@@ -3878,6 +4088,10 @@ function editGenreSongPages(data, edit) {
3878
4088
  FORM_RATING_NULL_VALUE,
3879
4089
  FUZZY_MIN_SIMILARITY,
3880
4090
  GOOGLE_EXCHANGE_CONFIG,
4091
+ GenreCatalogueCountsSchema,
4092
+ GenreCountsSchema,
4093
+ GenreCoverageSchema,
4094
+ GenrePlaylistSummarySchema,
3881
4095
  GenrePlaylistUuidSchema,
3882
4096
  GenreSearchResultSchema,
3883
4097
  GenreSearchResultsSchema,
@@ -3895,6 +4109,8 @@ function editGenreSongPages(data, edit) {
3895
4109
  PlayerProvider,
3896
4110
  PlayerVideoSurface,
3897
4111
  PopupProvider,
4112
+ ReferenceGenreDetailedSchema,
4113
+ ReferenceGenrePlaylistSchema,
3898
4114
  RegionGenreLexiconEntrySchema,
3899
4115
  RegionGenreLexiconSchema,
3900
4116
  SEARCH_DEBOUNCE_MS,
@@ -3907,6 +4123,8 @@ function editGenreSongPages(data, edit) {
3907
4123
  SongHistorySchema,
3908
4124
  SongSearchResultSchema,
3909
4125
  SongSearchResultsSchema,
4126
+ SubgenreCountsSchema,
4127
+ SubgenreScopeSchema,
3910
4128
  TrackBaseSchema,
3911
4129
  TrackList,
3912
4130
  TrackListFromArtist,
@@ -3915,6 +4133,7 @@ function editGenreSongPages(data, edit) {
3915
4133
  TrackListOrigin,
3916
4134
  TrackListOriginFromArtist,
3917
4135
  TrackListOriginFromCriteriaPlaylist,
4136
+ TrackListOriginFromGenreCatalogue,
3918
4137
  TrackListOriginFromTrack,
3919
4138
  TrackListOriginType,
3920
4139
  TrackListProvider,
@@ -3936,15 +4155,21 @@ function editGenreSongPages(data, edit) {
3936
4155
  createAppErrorFromErrorCode,
3937
4156
  createAppErrorFromResult,
3938
4157
  createLogout,
4158
+ createNameIndex,
3939
4159
  createNetworkOrBackendError,
4160
+ defaultGenreMusicSelection,
3940
4161
  editGenreSongPages,
3941
4162
  exchangeCodeWithBackend,
3942
4163
  fetchWrapper,
3943
4164
  foldSearchText,
3944
4165
  formatTime,
3945
4166
  genreEndpoints,
4167
+ genreMusicCount,
4168
+ genreMusicQueryParams,
4169
+ genreMusicSelectionKey,
3946
4170
  genrePlaylistEndpoints,
3947
4171
  genrePlaylistQueryKeys,
4172
+ genrePlaylistTrackCount,
3948
4173
  genreQueryKeys,
3949
4174
  genreSearchQueryKeys,
3950
4175
  genreUpdateMutationKey,
@@ -3965,6 +4190,7 @@ function editGenreSongPages(data, edit) {
3965
4190
  pruneGenrePlaylistsForArtist,
3966
4191
  queryClient,
3967
4192
  rankByName,
4193
+ rankNameIndex,
3968
4194
  resolveRedirectUri,
3969
4195
  searchGenrePlaylistsByName,
3970
4196
  setSpotifyRequiredCached,