taglib-wasm 2.4.1 → 2.5.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.
Files changed (92) hide show
  1. package/README.md +26 -22
  2. package/dist/bwf/bext.d.ts.map +1 -1
  3. package/dist/bwf/bext.js +25 -16
  4. package/dist/constants/complex-properties.d.ts.map +1 -1
  5. package/dist/constants/general-extended-properties.d.ts +2 -1
  6. package/dist/constants/general-extended-properties.d.ts.map +1 -1
  7. package/dist/constants/general-extended-properties.js +5 -2
  8. package/dist/constants/properties.d.ts.map +1 -1
  9. package/dist/constants/properties.js +2 -2
  10. package/dist/disc-folder.js +79 -45
  11. package/dist/folder-api/album-corroborate.d.ts.map +1 -1
  12. package/dist/folder-api/album-corroborate.js +25 -11
  13. package/dist/folder-api/album-discs.d.ts.map +1 -1
  14. package/dist/folder-api/album-discs.js +2 -5
  15. package/dist/folder-api/album-grouping.d.ts.map +1 -1
  16. package/dist/folder-api/album-grouping.js +27 -15
  17. package/dist/folder-api/album-identity.js +1 -1
  18. package/dist/folder-api/folder-disc.d.ts.map +1 -1
  19. package/dist/folder-api/folder-disc.js +24 -13
  20. package/dist/index.browser.d.ts +1 -1
  21. package/dist/index.browser.d.ts.map +1 -1
  22. package/dist/index.browser.js +2 -4477
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/msgpack/encoder.d.ts.map +1 -1
  26. package/dist/msgpack/encoder.js +3 -1
  27. package/dist/runtime/module-loader.d.ts.map +1 -1
  28. package/dist/runtime/module-loader.js +43 -33
  29. package/dist/runtime/platform-io.d.ts.map +1 -1
  30. package/dist/runtime/platform-io.js +4 -2
  31. package/dist/runtime/unified-loader/module-loading.d.ts.map +1 -1
  32. package/dist/runtime/unified-loader/module-loading.js +3 -2
  33. package/dist/runtime/wasi-adapter/audio-properties.d.ts.map +1 -1
  34. package/dist/runtime/wasi-adapter/audio-properties.js +8 -2
  35. package/dist/runtime/wasi-adapter/file-handle.d.ts +3 -1
  36. package/dist/runtime/wasi-adapter/file-handle.d.ts.map +1 -1
  37. package/dist/runtime/wasi-adapter/file-handle.js +16 -4
  38. package/dist/runtime/wasi-adapter/handle-state.d.ts.map +1 -1
  39. package/dist/runtime/wasi-adapter/handle-state.js +7 -1
  40. package/dist/runtime/wasi-adapter/mp4-items.d.ts +24 -0
  41. package/dist/runtime/wasi-adapter/mp4-items.d.ts.map +1 -1
  42. package/dist/runtime/wasi-adapter/mp4-items.js +119 -2
  43. package/dist/runtime/wasi-adapter/property-surface.d.ts.map +1 -1
  44. package/dist/runtime/wasi-adapter/property-surface.js +15 -6
  45. package/dist/runtime/wasi-adapter/structured-fields.js +1 -1
  46. package/dist/runtime/wasi-adapter/tag-keys.d.ts.map +1 -1
  47. package/dist/runtime/wasi-adapter/tag-keys.js +3 -1
  48. package/dist/runtime/wasi-adapter/wasm-io.d.ts.map +1 -1
  49. package/dist/simple/batch-operations.d.ts.map +1 -1
  50. package/dist/simple/batch-operations.js +5 -1
  51. package/dist/simple.browser.js +2 -3694
  52. package/dist/taglib/audio-file-base.d.ts +35 -1
  53. package/dist/taglib/audio-file-base.d.ts.map +1 -1
  54. package/dist/taglib/audio-file-base.js +90 -20
  55. package/dist/taglib/audio-file-checksum.d.ts.map +1 -1
  56. package/dist/taglib/audio-file-checksum.js +17 -13
  57. package/dist/taglib/audio-file-impl.d.ts.map +1 -1
  58. package/dist/taglib/audio-file-interface.d.ts +18 -1
  59. package/dist/taglib/audio-file-interface.d.ts.map +1 -1
  60. package/dist/taglib/embind-adapter.d.ts +3 -0
  61. package/dist/taglib/embind-adapter.d.ts.map +1 -1
  62. package/dist/taglib/embind-adapter.js +6 -0
  63. package/dist/taglib/extra-state-registry.d.ts.map +1 -1
  64. package/dist/taglib/extra-state-registry.js +15 -0
  65. package/dist/taglib/load-audio-data.d.ts +11 -8
  66. package/dist/taglib/load-audio-data.d.ts.map +1 -1
  67. package/dist/taglib/load-audio-data.js +39 -43
  68. package/dist/taglib/metadata-extent.d.ts.map +1 -1
  69. package/dist/taglib/metadata-extent.js +59 -32
  70. package/dist/taglib/mutable-tag-impl.d.ts.map +1 -1
  71. package/dist/taglib/mutable-tag-impl.js +72 -69
  72. package/dist/taglib/taglib-class.d.ts.map +1 -1
  73. package/dist/taglib/taglib-class.js +15 -5
  74. package/dist/taglib-wasi.wasm +0 -0
  75. package/dist/taglib-web.wasm +0 -0
  76. package/dist/taglib-wrapper.js +1 -1
  77. package/dist/types/tags.d.ts +44 -0
  78. package/dist/types/tags.d.ts.map +1 -1
  79. package/dist/utils/mp4-freeform.d.ts +20 -0
  80. package/dist/utils/mp4-freeform.d.ts.map +1 -0
  81. package/dist/utils/mp4-freeform.js +111 -0
  82. package/dist/utils/path.d.ts.map +1 -1
  83. package/dist/utils/path.js +3 -1
  84. package/dist/utils/tag-mapping.d.ts.map +1 -1
  85. package/dist/utils/tag-mapping.js +30 -18
  86. package/dist/version.d.ts +1 -1
  87. package/dist/version.js +1 -1
  88. package/dist/wasm.d.ts +3 -0
  89. package/dist/wasm.d.ts.map +1 -1
  90. package/dist/web-utils/data-url.js +1 -1
  91. package/dist/web.browser.js +2 -3412
  92. package/package.json +2 -1
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![npm version](https://img.shields.io/npm/v/taglib-wasm.svg)](https://www.npmjs.com/package/taglib-wasm)
5
5
  [![npm downloads](https://img.shields.io/npm/dm/taglib-wasm.svg)](https://www.npmjs.com/package/taglib-wasm)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/CharlesWiltgen/TagLib-Wasm/blob/main/LICENSE)
7
- <br>[![Built with](https://img.shields.io/badge/TypeScript-5-3178c6.svg?logo=typescript&logoColor=f5f5f5)](https://www.typescriptlang.org/)
7
+ <br>[![Built with](https://img.shields.io/badge/TypeScript-6-3178c6.svg?logo=typescript&logoColor=f5f5f5)](https://www.typescriptlang.org/)
8
8
  [![Built with Emscripten](https://img.shields.io/badge/Built%20with-Emscripten-4B9BFF.svg)](https://emscripten.org/)
9
9
  [![Built with WebAssembly](https://img.shields.io/badge/Built%20with-WebAssembly-654ff0.svg?logo=webassembly&logoColor=white)](https://webassembly.org/)
10
10
  [![Built with TagLib](https://img.shields.io/badge/Built%20with-TagLib-brightgreen.svg)](https://taglib.org/)
@@ -36,7 +36,8 @@ TagLib-Wasm is the **universal tagging library for TypeScript/JavaScript**
36
36
  - **Value fidelity** – Tag values round-trip verbatim: a `"3/12"` track or a
37
37
  zero-padded `"03"` is preserved, and MP4 freeform atoms keep their exact
38
38
  casing and vendor `mean`, so other tools still recognise them
39
- - **Zero dependencies** – Self-contained Wasm bundle
39
+ - **Self-contained Wasm** – TagLib ships compiled in the package; no native
40
+ modules, system libraries, or post-install download
40
41
  - **Tested** – Cross-backend parity coverage across the supported formats
41
42
  - **Two API styles** – Use the "Simple" API for one-shot reads and writes, batch
42
43
  helpers, cover art, and checksums, or the full "Core" API for more advanced
@@ -196,10 +197,8 @@ const taglib = await TagLib.initialize();
196
197
  // Load audio file (automatically cleaned up when scope exits)
197
198
  using file = await taglib.open("song.mp3");
198
199
 
199
- // Read and update metadata
200
- const tag = file.tag();
201
- tag.setTitle("New Title");
202
- tag.setArtist("New Artist");
200
+ // Update metadata (setters chain)
201
+ file.tag().setTitle("New Title").setArtist("New Artist");
203
202
 
204
203
  // Save changes
205
204
  file.save();
@@ -289,6 +288,9 @@ const modifiedBuffer = await applyCoverArt("song.mp3", imageData, "image/jpeg");
289
288
  // Save modifiedBuffer to file if needed
290
289
  ```
291
290
 
291
+ `coverData` and `imageData` are `Uint8Array`s; this snippet uses Deno's file API
292
+ — substitute your runtime's.
293
+
292
294
  ### Working with Ratings
293
295
 
294
296
  ```typescript
@@ -594,15 +596,17 @@ reproduced:
594
596
  `<script type="module">` pointing at the entry, `build.minify: "esbuild"`,
595
597
  `target: "es2022"`. Vite builds for the browser; the figures below that name
596
598
  the `node` condition instead add `resolve.conditions: ["node"]`.
597
- - **webpack 5.111.1** – `mode: "production"`, `target: "web"`,
598
- `externals: { module: "module" }`. `target: "web"` alone fails on the
599
- `import("module")` inside `dist/taglib-wrapper.js`.
599
+ - **webpack 5.111.1** – The app package declares `"type": "module"`;
600
+ `mode: "production"`, `target: "web"`, `externals: { module: "module" }`,
601
+ `experiments: { topLevelAwait: true }` (the app calls the API at top level).
602
+ `target: "web"` alone fails on the `import("module")` inside
603
+ `dist/taglib-wrapper.js`.
600
604
 
601
605
  | Consumer app | esbuild (browser)¹ | rollup (browser)¹ | vite (app) | webpack (web)² | esbuild (Node)³ | rollup (Node)³ |
602
606
  | ------------------------------------- | ------------------ | ----------------- | ---------- | -------------- | --------------- | -------------- |
603
- | `taglib-wasm` — `TagLib.initialize()` | 81,300 | 78,526 | 83,770 | 81,322 | 147,532 | 136,929 |
604
- | `taglib-wasm/simple` — `getTagLib()` | 81,036 | 78,804 | 83,518 | 82,152 | 148,553 | 137,330 |
605
- | `taglib-wasm/folder` — `scanFolder`⁴ | — | 140,717⁴ | 150,043⁴ | — | 151,898 | 140,717 |
607
+ | `taglib-wasm` — `TagLib.initialize()` | 84,983 | 82,248 | 87,962 | 85,889 | 152,363 | 141,705 |
608
+ | `taglib-wasm/simple` — `getTagLib()` | 84,705 | 82,511 | 87,696 | 86,713 | 153,370 | 142,088 |
609
+ | `taglib-wasm/folder` — `scanFolder`⁴ | — | 145,454⁴ | 154,848⁴ | — | 156,868 | 145,454 |
606
610
 
607
611
  ¹ the `browser` `exports` condition. ² `target: "web"`. ³ the Node `exports`
608
612
  condition. ⁴ Node-only entry — see below.
@@ -624,13 +628,13 @@ browser, scan on a server and post the result; the pure
624
628
  **`./web` builds for the browser.** It declares a `browser` condition, so a
625
629
  browser-targeted build resolves an Emscripten-only build of that entry and pulls
626
630
  **`taglib-web.wasm` alone** – Measured with the vite invocation above on
627
- `pictureToDataURL` from `taglib-wasm/web`: one 673,441-byte Wasm asset, where
631
+ `pictureToDataURL` from `taglib-wasm/web`: one 691,052-byte Wasm asset, where
628
632
  the vite build on the `node` condition instead emits both `taglib-web.wasm` and
629
- `taglib-wasi.wasm` (1,428,196 bytes of assets for a call that needs neither
633
+ `taglib-wasi.wasm` (1,462,928 bytes of assets for a call that needs neither
630
634
  engine). The browser build is a pre-bundled file like `index.browser.js`, so it
631
- barely tree-shakes: that call is 82,511 bytes in the vite app build and 80,021
635
+ barely tree-shakes: that call is 86,179 bytes in the vite app build and 83,663
632
636
  under the esbuild browser column, against 205 bytes under esbuild's Node column —
633
- and importing any pure helper from the barrel costs ~80 KB there too. Rollup is
637
+ and importing any pure helper from the barrel costs ~85 KB there too. Rollup is
634
638
  the exception: it shakes the pre-bundled file down to 784 bytes, though still
635
639
  not to the 210-byte leaf its Node column reaches. That granularity is a property
636
640
  of the pre-bundled browser entries, not of this subpath.
@@ -667,7 +671,7 @@ The `browser` condition itself is resolved by default by esbuild
667
671
 
668
672
  **The barrel is not a tax.** Adding an API to an import that already loads the
669
673
  engine costs only that API. Against the `taglib-wasm` row above (esbuild, Node
670
- column): adding `scanFolder` costs **4,381 bytes** and adding
674
+ column): adding `scanFolder` costs **4,386 bytes** and adding
671
675
  `pictureToDataURL` costs **187 bytes**, because neither drags in the rest of the
672
676
  Folder or Web module tree.
673
677
 
@@ -676,16 +680,16 @@ pre-bundled file, so a consumer of the barrel downloads the whole file whatever
676
680
  it imports; adding the pure `bwf` / `groupAlbums` / `discFolderInfo` exports to
677
681
  that file's export list therefore costs nothing measurable. Bundling
678
682
  `import { TagLib }` against the entry with and without those three export names
679
- gives identical bytes under esbuild (81,300) and rollup (78,526) and 12 bytes
680
- more under vite (83,758 → 83,770). Nothing else moved: the Folder and Web APIs
681
- are still reached only when imported, and the Node entries are unchanged.
683
+ gives identical bytes under esbuild and rollup and only a few bytes more under
684
+ vite. Nothing else moved: the Folder and Web APIs are still reached only when
685
+ imported, and the Node entries are unchanged.
682
686
 
683
687
  **Entry-point choice is not a size lever.** `taglib-wasm` and
684
688
  `taglib-wasm/simple` differ by about a kilobyte either way — in a browser bundle
685
- `simple` is 264 bytes _smaller_, on Node 1,021 bytes _larger_, because
689
+ `simple` is 278 bytes _smaller_, on Node 1,007 bytes _larger_, because
686
690
  `getTagLib()` reaches the full `TagLib` class through a dynamic import. Pick by
687
691
  API surface. The lever that does matter is the `browser` export condition: a
688
- browser-targeted bundle is ~80 KB where a Node-targeted one is ~148 KB.
692
+ browser-targeted bundle is ~85 KB where a Node-targeted one is ~152 KB.
689
693
 
690
694
  **`"sideEffects": false`** is set in `package.json`, so a bundler may drop any
691
695
  module whose exports go unused. Before that field, importers of the sub-entries
@@ -1 +1 @@
1
- {"version":3,"file":"bext.d.ts","sourceRoot":"","sources":["../../src/bwf/bext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AA6D/D;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,UAAU,GAChB,uBAAuB,GAAG,SAAS,CAyCrC;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,uBAAuB,GAAG,UAAU,CAmDjE"}
1
+ {"version":3,"file":"bext.d.ts","sourceRoot":"","sources":["../../src/bwf/bext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAuF/D;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,UAAU,GAChB,uBAAuB,GAAG,SAAS,CAgCrC;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,uBAAuB,GAAG,UAAU,CAsDjE"}
package/dist/bwf/bext.js CHANGED
@@ -15,11 +15,11 @@ function readFixedString(bytes, offset, len) {
15
15
  const max = Math.min(offset + len, bytes.length);
16
16
  while (end < max && bytes[end] !== 0) end++;
17
17
  let s = "";
18
- for (let i = offset; i < end; i++) s += String.fromCharCode(bytes[i]);
18
+ for (let i = offset; i < end; i++) s += String.fromCodePoint(bytes[i]);
19
19
  return s;
20
20
  }
21
21
  function writeFixedString(bytes, offset, len, value) {
22
- for (let i = 0; i < len; i++) bytes[offset + i] = i < value.length ? value.charCodeAt(i) & 255 : 0;
22
+ for (let i = 0; i < len; i++) bytes[offset + i] = i < value.length ? (value.codePointAt(i) ?? 0) & 255 : 0;
23
23
  }
24
24
  function clampInt16(n) {
25
25
  return Math.max(-32768, Math.min(32767, Math.round(n)));
@@ -40,10 +40,26 @@ function hexToBytes(hex, outLen) {
40
40
  const out = new Uint8Array(outLen);
41
41
  for (let i = 0; i + 1 < clean.length + 1 && i / 2 < outLen; i += 2) {
42
42
  const pair = clean.slice(i, i + 2);
43
- if (pair.length === 2) out[i / 2] = parseInt(pair, 16);
43
+ if (pair.length === 2) out[i / 2] = Number.parseInt(pair, 16);
44
44
  }
45
45
  return out;
46
46
  }
47
+ const LOUDNESS_FIELDS = [
48
+ ["loudnessValueDb", 0],
49
+ ["loudnessRangeDb", 2],
50
+ ["maxTruePeakLevelDbtp", 4],
51
+ ["maxMomentaryLoudnessDb", 6],
52
+ ["maxShortTermLoudnessDb", 8]
53
+ ];
54
+ /** Decode the v2 loudness block; absent Int16 sentinels stay absent. */
55
+ function decodeLoudnessFields(dv) {
56
+ const result = {};
57
+ for (const [field, offset] of LOUDNESS_FIELDS) {
58
+ const value = loudnessFromRaw(dv.getInt16(LOUDNESS_OFFSET + offset, true));
59
+ if (value !== void 0) result[field] = value;
60
+ }
61
+ return result;
62
+ }
47
63
  /**
48
64
  * Parse a raw `bext` chunk. Returns `undefined` only if `bytes` is shorter than
49
65
  * 348 (cannot even read the `Version` field). Optional fields are populated per
@@ -67,18 +83,7 @@ function decodeBext(bytes) {
67
83
  codingHistory: bytes.length > FIXED_PREFIX_LEN ? readFixedString(bytes, FIXED_PREFIX_LEN, bytes.length - FIXED_PREFIX_LEN) : ""
68
84
  };
69
85
  if (version >= 1 && bytes.length >= 412) result.umid = bytesToHex(bytes.subarray(UMID_OFFSET, 412));
70
- if (version >= 2 && bytes.length >= 422) {
71
- const lv = loudnessFromRaw(dv.getInt16(LOUDNESS_OFFSET, true));
72
- const lr = loudnessFromRaw(dv.getInt16(414, true));
73
- const mtp = loudnessFromRaw(dv.getInt16(416, true));
74
- const mml = loudnessFromRaw(dv.getInt16(418, true));
75
- const msl = loudnessFromRaw(dv.getInt16(420, true));
76
- if (lv !== void 0) result.loudnessValueDb = lv;
77
- if (lr !== void 0) result.loudnessRangeDb = lr;
78
- if (mtp !== void 0) result.maxTruePeakLevelDbtp = mtp;
79
- if (mml !== void 0) result.maxMomentaryLoudnessDb = mml;
80
- if (msl !== void 0) result.maxShortTermLoudnessDb = msl;
81
- }
86
+ if (version >= 2 && bytes.length >= 422) Object.assign(result, decodeLoudnessFields(dv));
82
87
  return result;
83
88
  }
84
89
  /**
@@ -94,7 +99,11 @@ function encodeBext(b) {
94
99
  const bytes = new Uint8Array(FIXED_PREFIX_LEN + codingHistory.length);
95
100
  const dv = new DataView(bytes.buffer);
96
101
  const hasLoudness = b.loudnessValueDb !== void 0 || b.loudnessRangeDb !== void 0 || b.maxTruePeakLevelDbtp !== void 0 || b.maxMomentaryLoudnessDb !== void 0 || b.maxShortTermLoudnessDb !== void 0;
97
- const version = Number.isInteger(b.version) ? b.version : hasLoudness ? 2 : b.umid ? 1 : 0;
102
+ let version;
103
+ if (Number.isInteger(b.version)) version = b.version;
104
+ else if (hasLoudness) version = 2;
105
+ else if (b.umid) version = 1;
106
+ else version = 0;
98
107
  writeFixedString(bytes, 0, 256, b.description ?? "");
99
108
  writeFixedString(bytes, 256, 32, b.originator ?? "");
100
109
  writeFixedString(bytes, 288, 32, b.originatorReference ?? "");
@@ -1 +1 @@
1
- {"version":3,"file":"complex-properties.d.ts","sourceRoot":"","sources":["../../src/constants/complex-properties.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH;;;;;;;;GAQG;AACH,MAAM,WAAW,MAAM;IACrB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX,0DAA0D;IAC1D,IAAI,EAAE,UAAU,CAAC;IACjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"complex-properties.d.ts","sourceRoot":"","sources":["../../src/constants/complex-properties.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;;;;GAQG;AACH,MAAM,WAAW,MAAM;IACrB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX,0DAA0D;IAC1D,IAAI,EAAE,UAAU,CAAC;IACjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
@@ -222,9 +222,10 @@ export declare const GENERAL_EXTENDED_PROPERTIES: {
222
222
  readonly key: "GROUPING";
223
223
  readonly description: "Content group/work";
224
224
  readonly type: "string";
225
- readonly supportedFormats: readonly ["Vorbis"];
225
+ readonly supportedFormats: readonly ["MP4", "Vorbis"];
226
226
  readonly mappings: {
227
227
  readonly vorbis: "GROUPING";
228
+ readonly mp4: "©grp";
228
229
  };
229
230
  };
230
231
  readonly work: {
@@ -1 +1 @@
1
- {"version":3,"file":"general-extended-properties.d.ts","sourceRoot":"","sources":["../../src/constants/general-extended-properties.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4P9B,CAAC"}
1
+ {"version":3,"file":"general-extended-properties.d.ts","sourceRoot":"","sources":["../../src/constants/general-extended-properties.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6P9B,CAAC"}
@@ -229,8 +229,11 @@ const GENERAL_EXTENDED_PROPERTIES = {
229
229
  key: "GROUPING",
230
230
  description: "Content group/work",
231
231
  type: "string",
232
- supportedFormats: ["Vorbis"],
233
- mappings: { vorbis: "GROUPING" }
232
+ supportedFormats: ["MP4", "Vorbis"],
233
+ mappings: {
234
+ vorbis: "GROUPING",
235
+ mp4: "©grp"
236
+ }
234
237
  },
235
238
  work: {
236
239
  key: "WORK",
@@ -1 +1 @@
1
- {"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../../src/constants/properties.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAUrE,eAAO,MAAM,UAAU,EAAE,OAAO,gBAAgB,GAC9C,OAAO,2BAA2B,GAClC,OAAO,sBAAsB,GAC7B,OAAO,qBAKC,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,UAAU,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,WAAW,IAC7C,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,QAAQ,GAC3C,MAAM,GACN,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,QAAQ,GAC7C,MAAM,GACN,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,SAAS,GAC9C,OAAO,GACP,MAAM,CAAC;AAoDjB,mGAAmG;AACnG,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAsDD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE/D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAOzE;AAED,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,qEAAqE;AACrE,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GACrB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CASnB;AAGD,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../../src/constants/properties.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAUrE,eAAO,MAAM,UAAU,EAAE,OAAO,gBAAgB,GAC9C,OAAO,2BAA2B,GAClC,OAAO,sBAAsB,GAC7B,OAAO,qBAKC,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,UAAU,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,WAAW,IAC7C,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,QAAQ,GAC3C,MAAM,GACN,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,QAAQ,GAC7C,MAAM,GACN,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,SAAS,GAC9C,OAAO,GACP,MAAM,CAAC;AAkDjB,mGAAmG;AACnG,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAsDD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE/D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAOzE;AAED,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,qEAAqE;AACrE,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GACrB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CASnB;AAGD,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -46,7 +46,7 @@ const READ_ALIASES = {
46
46
  CONTENTADVISORY: "ITUNESADVISORY",
47
47
  EXPLICIT: "ITUNESADVISORY"
48
48
  };
49
- for (const [alias, canonical] of Object.entries(READ_ALIASES)) if (_fromTagLib[alias] === void 0) _fromTagLib[alias] = _fromTagLib[canonical];
49
+ for (const [alias, canonical] of Object.entries(READ_ALIASES)) _fromTagLib[alias] ?? (_fromTagLib[alias] = _fromTagLib[canonical]);
50
50
  /** Translate a camelCase property key to TagLib's ALL_CAPS wire key. Unknown keys pass through. */
51
51
  function toTagLibKey(key) {
52
52
  return _toTagLib[key] ?? key;
@@ -68,7 +68,7 @@ for (const meta of Object.values(PROPERTIES)) {
68
68
  const { key, mappings } = meta;
69
69
  const atom = mappings?.mp4;
70
70
  if (typeof atom !== "string" || atom.startsWith("----:")) continue;
71
- if (_mp4AtomToWireKey[atom] === void 0) _mp4AtomToWireKey[atom] = key;
71
+ _mp4AtomToWireKey[atom] ?? (_mp4AtomToWireKey[atom] = key);
72
72
  }
73
73
  /**
74
74
  * TagLib wire key for a standard MP4 atom name, or `undefined` for a freeform
@@ -57,7 +57,7 @@ function romanToInt(s) {
57
57
  return total;
58
58
  }
59
59
  function parseNumberToken(token) {
60
- if (/^\d+$/.test(token)) return parseInt(token, 10);
60
+ if (/^\d+$/.test(token)) return Number.parseInt(token, 10);
61
61
  const word = WORD_NUMBERS[token.toLowerCase()];
62
62
  if (word) return word;
63
63
  const roman = romanToInt(token.toLowerCase());
@@ -66,6 +66,19 @@ function parseNumberToken(token) {
66
66
  const SEP = String.raw`[\s._#-]*`;
67
67
  const NUM = String.raw`(?:\d+|(?:[ivxlcdm]+|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|[a-z])(?![a-z]))`;
68
68
  /**
69
+ * Drop trailing `chars` and whitespace with a scan instead of an end-anchored
70
+ * quantified class, which Sonar flags for super-linear backtracking (S8786).
71
+ */
72
+ function trimTrailingChars(s, chars) {
73
+ let end = s.length;
74
+ while (end > 0) {
75
+ const c = s.charAt(end - 1);
76
+ if (!chars.includes(c) && !/\s/.test(c)) break;
77
+ end--;
78
+ }
79
+ return s.slice(0, end);
80
+ }
81
+ /**
69
82
  * Parse a directory name as a disc folder. Returns undefined for non-disc
70
83
  * names. Plain "Bonus" and "Extras" are NEVER discs by name (tuneup rule;
71
84
  * the low-tier table's "Extras" row was the flagged divergence).
@@ -74,10 +87,8 @@ function parseDiscName(name) {
74
87
  const trimmed = name.trim();
75
88
  if (/^(?:extras?|bonus)$/i.test(trimmed)) return void 0;
76
89
  for (const marker of MARKERS) {
77
- const left = String.raw`(?:^|[^a-z0-9])`;
78
- const esc = marker.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
79
- const re = new RegExp(left + String.raw`(${esc})(?![a-z])${SEP}(${NUM})`, "i");
80
- const m = trimmed.match(re);
90
+ const esc = marker.replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
91
+ const m = new RegExp(`(?:^|[^a-z0-9])(${esc})(?![a-z])${SEP}(${NUM})`, "i").exec(trimmed);
81
92
  if (!m) continue;
82
93
  const sideLetter = /^[a-z]$/i.test(m[2]);
83
94
  const number = sideLetter ? void 0 : parseNumberToken(m[2]);
@@ -85,12 +96,12 @@ function parseDiscName(name) {
85
96
  if (!sideLetter && /^[ivxlcdm]{2,}$/i.test(m[2]) && (number ?? 0) > 100) continue;
86
97
  const isGated = GATED_MARKER_SET.has(marker.toLowerCase()) || sideLetter;
87
98
  const markerStart = m.index + m[1].length - marker.length;
88
- const title = trimmed.slice(0, markerStart).trim().replace(/[()[\]]/g, "").replace(/[\s._#-]+$/, "") || void 0;
99
+ const title = trimTrailingChars(trimmed.slice(0, markerStart).trim().replace(/[()[\]]/g, ""), "._#-") || void 0;
89
100
  const isExact = title === void 0;
90
101
  const after = trimmed.slice(m.index + m[0].length).trim();
91
- const discTitle = after.replace(/^[()[\],:;\-–—\s]+/, "").replace(/[)\]\[,:;\-–—\s]+$/, "").trim() || void 0;
92
- const ofMatch = after.trim().match(/^of\s+(\d+)\b/i);
93
- const total = ofMatch ? parseInt(ofMatch[1], 10) : void 0;
102
+ const discTitle = trimTrailingChars(after.replace(/^[()[\],:;\-–—\s]+/, ""), "])[,:;-–—").trim() || void 0;
103
+ const ofMatch = /^of\s+(\d+)\b/i.exec(after.trim());
104
+ const total = ofMatch ? Number.parseInt(ofMatch[1], 10) : void 0;
94
105
  return {
95
106
  kind: isExact ? "exact" : "embedded",
96
107
  number: sideLetter ? void 0 : number,
@@ -102,11 +113,11 @@ function parseDiscName(name) {
102
113
  digit: /^\d+$/.test(m[2])
103
114
  };
104
115
  }
105
- const volume = trimmed.match(/^(?:volume|vol\.?|part|pt\.?)\s*(\d+)(?:\s*of\s*(\d+))?$/i);
116
+ const volume = /^(?:volume|vol\.?|part|pt\.?)\s*(\d+)(?:\s*of\s*(\d+))?$/i.exec(trimmed);
106
117
  if (volume) return {
107
118
  kind: "volume",
108
- number: parseInt(volume[1], 10),
109
- total: volume[2] ? parseInt(volume[2], 10) : void 0,
119
+ number: Number.parseInt(volume[1], 10),
120
+ total: volume[2] ? Number.parseInt(volume[2], 10) : void 0,
110
121
  title: void 0,
111
122
  discTitle: void 0,
112
123
  gated: false,
@@ -125,7 +136,7 @@ function parseDiscName(name) {
125
136
  };
126
137
  if (/^(?:\d+|v\d+|p\d+|[ab])$/i.test(trimmed)) return {
127
138
  kind: "bare",
128
- number: /^\d+$/i.test(trimmed) ? parseInt(trimmed, 10) : void 0,
139
+ number: /^\d+$/i.test(trimmed) ? Number.parseInt(trimmed, 10) : void 0,
129
140
  total: void 0,
130
141
  title: void 0,
131
142
  discTitle: void 0,
@@ -185,20 +196,34 @@ const CONFIDENCE_RANK = {
185
196
  medium: 1,
186
197
  high: 2
187
198
  };
199
+ function summarizeSiblings(siblings) {
200
+ const facts = {
201
+ hasExact: false,
202
+ hasNumbered: false,
203
+ numberedCount: 0,
204
+ hasSideLetter: false
205
+ };
206
+ for (const sibling of siblings) {
207
+ const parsed = parseDiscName(basename(sibling));
208
+ if (!parsed) continue;
209
+ if (!parsed.gated && parsed.kind === "exact") facts.hasExact = true;
210
+ if (parsed.number !== void 0) {
211
+ facts.hasNumbered = true;
212
+ facts.numberedCount++;
213
+ }
214
+ if (parsed.sideLetter) facts.hasSideLetter = true;
215
+ }
216
+ return facts;
217
+ }
188
218
  function corroborated(parse, siblings) {
189
219
  if (!parse.gated && parse.kind === "exact") return true;
190
220
  if (siblings.length === 0) return false;
191
- const siblingParses = siblings.map((s) => parseDiscName(basename(s))).filter((p) => p !== void 0);
192
- const hasExactSibling = siblingParses.some((p) => !p.gated && p.kind === "exact");
193
- const hasNumberedSibling = siblingParses.some((p) => p.number !== void 0);
194
- if (parse.number !== void 0 && hasNumberedSibling) return true;
195
- if (!parse.gated && parse.kind === "embedded" && hasExactSibling) return true;
196
- if (!parse.gated && parse.kind === "volume" && hasNumberedSibling) return true;
197
- if (parse.sideLetter) return siblingParses.some((p) => p.sideLetter);
198
- if (parse.kind === "bonus" || parse.kind === "bare") {
199
- if (siblingParses.filter((p) => p.number !== void 0).length >= 2) return true;
200
- if (parse.number !== void 0 && hasNumberedSibling) return true;
201
- }
221
+ const facts = summarizeSiblings(siblings);
222
+ if (parse.number !== void 0 && facts.hasNumbered) return true;
223
+ if (!parse.gated && parse.kind === "embedded" && facts.hasExact) return true;
224
+ if (!parse.gated && parse.kind === "volume" && facts.hasNumbered) return true;
225
+ if (parse.sideLetter) return facts.hasSideLetter;
226
+ if (parse.kind === "bonus" || parse.kind === "bare") return facts.numberedCount >= 2;
202
227
  return false;
203
228
  }
204
229
  //#endregion
@@ -340,7 +365,7 @@ function buildAlbumIdentity(okItems, confirmedDiscs, flatSubdivisions, options)
340
365
  discNumber: evidence?.folderDiscNumber
341
366
  });
342
367
  }
343
- for (const [key, acc] of [...albums]) {
368
+ for (const [key, acc] of albums) {
344
369
  if (acc.source === "tags") continue;
345
370
  for (const other of albums.values()) {
346
371
  if (other === acc || other.source !== "tags") continue;
@@ -391,7 +416,6 @@ function assembleDiscs(albums) {
391
416
  resolvedByFile.set(item.path, tagCommon ?? evidence?.folderDiscNumber);
392
417
  }
393
418
  const discs = /* @__PURE__ */ new Map();
394
- const order = [];
395
419
  const noEvidenceItems = [];
396
420
  for (const item of acc.items) {
397
421
  const evidence = acc.evidence.get(item.path);
@@ -413,7 +437,6 @@ function assembleDiscs(albums) {
413
437
  items: []
414
438
  };
415
439
  discs.set(discKey, disc);
416
- order.push(discKey);
417
440
  }
418
441
  disc.items.push(item);
419
442
  }
@@ -434,7 +457,6 @@ function assembleDiscs(albums) {
434
457
  items: []
435
458
  };
436
459
  discs.set(key, disc);
437
- order.push(key);
438
460
  }
439
461
  disc.items.push(...noEvidenceItems);
440
462
  }
@@ -452,8 +474,8 @@ function assembleDiscs(albums) {
452
474
  const maxSibling = [...discs.values()].map((d) => d.discNumber).filter((n) => n !== void 0).reduce((a, b) => Math.max(a, b), 0) || void 0;
453
475
  for (const disc of discs.values()) disc.totalDiscs = commonTotal ?? ofN ?? maxSibling;
454
476
  const sortedDiscs = [...discs.values()].sort((a, b) => {
455
- const an = a.discNumber === void 0 ? -1 : a.discNumber;
456
- const bn = b.discNumber === void 0 ? -1 : b.discNumber;
477
+ const an = a.discNumber ?? -1;
478
+ const bn = b.discNumber ?? -1;
457
479
  if (an !== bn) return an - bn;
458
480
  return (a.folderDiscTitle ?? "").localeCompare(b.folderDiscTitle ?? "");
459
481
  });
@@ -503,14 +525,14 @@ function assembleDiscs(albums) {
503
525
  * 7. singles holds exactly the ok items whose resolved album has one file.
504
526
  */
505
527
  function flatPrefix(filename) {
506
- const separated = filename.match(/^(\d{1,2})[\s._-](\d{1,2})/);
528
+ const separated = /^(\d{1,2})[\s._-](\d{1,2})/.exec(filename);
507
529
  if (separated) return {
508
- disc: parseInt(separated[1], 10),
530
+ disc: Number.parseInt(separated[1], 10),
509
531
  form: "separated"
510
532
  };
511
- const compact = filename.match(/^(\d)(\d{2})(?:\D|$)/);
533
+ const compact = /^(\d)(\d{2})(?:\D|$)/.exec(filename);
512
534
  if (compact) return {
513
- disc: parseInt(compact[1], 10),
535
+ disc: Number.parseInt(compact[1], 10),
514
536
  form: "compact"
515
537
  };
516
538
  }
@@ -550,6 +572,17 @@ function buildTree(okItems) {
550
572
  return tree;
551
573
  }
552
574
  /**
575
+ * Resolve a disc name's confidence from its parse and sibling evidence.
576
+ * Undefined means the name is not a disc. Gated names (title-word markers,
577
+ * side letters, bonus, bare) keep low confidence even when corroborated;
578
+ * everything else upgrades to high.
579
+ */
580
+ function resolveDiscConfidence(parse, corroboratedBySiblings) {
581
+ if (parse.gated) return corroboratedBySiblings ? "low" : void 0;
582
+ if (parse.kind === "bonus" || parse.kind === "bare") return corroboratedBySiblings ? baseConfidence(parse) : void 0;
583
+ return corroboratedBySiblings ? "high" : baseConfidence(parse);
584
+ }
585
+ /**
553
586
  * Step 3: folder disc recognition per directory containing audio, with
554
587
  * sibling corroboration. Exact names are discs outright (word/roman at low
555
588
  * confidence). Embedded and volume names are discs at medium, upgraded to
@@ -562,13 +595,8 @@ function confirmDiscs(tree, minRank) {
562
595
  if (node.files.length === 0) continue;
563
596
  const parse = parseDiscName(basename(dir));
564
597
  if (!parse) continue;
565
- const corroboratedBySiblings = corroborated(parse, [...tree.keys()].filter((d) => d !== dir && dirname(d) === dirname(dir)));
566
- let confidence = parse.gated ? "low" : baseConfidence(parse);
567
- if (parse.gated) {
568
- if (!corroboratedBySiblings) continue;
569
- } else if (parse.kind === "bonus" || parse.kind === "bare") {
570
- if (!corroboratedBySiblings) continue;
571
- } else if (corroboratedBySiblings) confidence = "high";
598
+ const confidence = resolveDiscConfidence(parse, corroborated(parse, [...tree.keys()].filter((d) => d !== dir && dirname(d) === dirname(dir))));
599
+ if (confidence === void 0) continue;
572
600
  if (CONFIDENCE_RANK[confidence] < minRank) continue;
573
601
  confirmedDiscs.set(dir, {
574
602
  parse,
@@ -578,10 +606,17 @@ function confirmDiscs(tree, minRank) {
578
606
  return confirmedDiscs;
579
607
  }
580
608
  /**
609
+ * Separated forms are explicit. A compact-only set must be plausible: every
610
+ * distinct prefix within 1..N where N = the distinct count (101+201 split;
611
+ * 101+102 stay one disc; 101+301 do not split).
612
+ */
613
+ function flatSetIsPlausible(forms, distinct) {
614
+ if (!(forms.size === 1 && forms.has("compact"))) return true;
615
+ return distinct.every((d) => d >= 1 && d <= distinct.length);
616
+ }
617
+ /**
581
618
  * Step 4: flat filename prefixes — subdivide a directory's files into discs
582
619
  * when two or more distinct prefixes appear. Never inside a disc folder.
583
- * Separated forms are explicit; compact-only sets must be plausible (each
584
- * distinct prefix within 1..N, N = distinct count).
585
620
  */
586
621
  function flatSubdivisions(tree, confirmedDiscs, useFlatPrefixes) {
587
622
  const flat = /* @__PURE__ */ new Map();
@@ -598,8 +633,7 @@ function flatSubdivisions(tree, confirmedDiscs, useFlatPrefixes) {
598
633
  }
599
634
  }
600
635
  if (byFile.size < 2) continue;
601
- const distinct = [...new Set(byFile.values())].sort((a, b) => a - b);
602
- if (forms.size === 1 && forms.has("compact") ? distinct.every((d) => d >= 1 && d <= distinct.length) : true) flat.set(dir, byFile);
636
+ if (flatSetIsPlausible(forms, [...new Set(byFile.values())].sort((a, b) => a - b))) flat.set(dir, byFile);
603
637
  }
604
638
  return flat;
605
639
  }
@@ -1 +1 @@
1
- {"version":3,"file":"album-corroborate.d.ts","sourceRoot":"","sources":["../../src/folder-api/album-corroborate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElE,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAI1D,CAAC;AAEF,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAmC1E"}
1
+ {"version":3,"file":"album-corroborate.d.ts","sourceRoot":"","sources":["../../src/folder-api/album-corroborate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElE,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAI1D,CAAC;AA6BF,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAuB1E"}
@@ -15,20 +15,34 @@ const CONFIDENCE_RANK = {
15
15
  medium: 1,
16
16
  high: 2
17
17
  };
18
+ function summarizeSiblings(siblings) {
19
+ const facts = {
20
+ hasExact: false,
21
+ hasNumbered: false,
22
+ numberedCount: 0,
23
+ hasSideLetter: false
24
+ };
25
+ for (const sibling of siblings) {
26
+ const parsed = parseDiscName(basename(sibling));
27
+ if (!parsed) continue;
28
+ if (!parsed.gated && parsed.kind === "exact") facts.hasExact = true;
29
+ if (parsed.number !== void 0) {
30
+ facts.hasNumbered = true;
31
+ facts.numberedCount++;
32
+ }
33
+ if (parsed.sideLetter) facts.hasSideLetter = true;
34
+ }
35
+ return facts;
36
+ }
18
37
  function corroborated(parse, siblings) {
19
38
  if (!parse.gated && parse.kind === "exact") return true;
20
39
  if (siblings.length === 0) return false;
21
- const siblingParses = siblings.map((s) => parseDiscName(basename(s))).filter((p) => p !== void 0);
22
- const hasExactSibling = siblingParses.some((p) => !p.gated && p.kind === "exact");
23
- const hasNumberedSibling = siblingParses.some((p) => p.number !== void 0);
24
- if (parse.number !== void 0 && hasNumberedSibling) return true;
25
- if (!parse.gated && parse.kind === "embedded" && hasExactSibling) return true;
26
- if (!parse.gated && parse.kind === "volume" && hasNumberedSibling) return true;
27
- if (parse.sideLetter) return siblingParses.some((p) => p.sideLetter);
28
- if (parse.kind === "bonus" || parse.kind === "bare") {
29
- if (siblingParses.filter((p) => p.number !== void 0).length >= 2) return true;
30
- if (parse.number !== void 0 && hasNumberedSibling) return true;
31
- }
40
+ const facts = summarizeSiblings(siblings);
41
+ if (parse.number !== void 0 && facts.hasNumbered) return true;
42
+ if (!parse.gated && parse.kind === "embedded" && facts.hasExact) return true;
43
+ if (!parse.gated && parse.kind === "volume" && facts.hasNumbered) return true;
44
+ if (parse.sideLetter) return facts.hasSideLetter;
45
+ if (parse.kind === "bonus" || parse.kind === "bare") return facts.numberedCount >= 2;
32
46
  return false;
33
47
  }
34
48
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"album-discs.d.ts","sourceRoot":"","sources":["../../src/folder-api/album-discs.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAEhB,UAAU,EAEX,MAAM,kBAAkB,CAAC;AAE1B,uEAAuE;AACvE,wBAAgB,aAAa,CAC3B,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,gBAAgB,CAAC,GACrD,UAAU,EAAE,CAmKd"}
1
+ {"version":3,"file":"album-discs.d.ts","sourceRoot":"","sources":["../../src/folder-api/album-discs.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAEhB,UAAU,EAEX,MAAM,kBAAkB,CAAC;AAE1B,uEAAuE;AACvE,wBAAgB,aAAa,CAC3B,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,gBAAgB,CAAC,GACrD,UAAU,EAAE,CAgKd"}
@@ -26,7 +26,6 @@ function assembleDiscs(albums) {
26
26
  resolvedByFile.set(item.path, tagCommon ?? evidence?.folderDiscNumber);
27
27
  }
28
28
  const discs = /* @__PURE__ */ new Map();
29
- const order = [];
30
29
  const noEvidenceItems = [];
31
30
  for (const item of acc.items) {
32
31
  const evidence = acc.evidence.get(item.path);
@@ -48,7 +47,6 @@ function assembleDiscs(albums) {
48
47
  items: []
49
48
  };
50
49
  discs.set(discKey, disc);
51
- order.push(discKey);
52
50
  }
53
51
  disc.items.push(item);
54
52
  }
@@ -69,7 +67,6 @@ function assembleDiscs(albums) {
69
67
  items: []
70
68
  };
71
69
  discs.set(key, disc);
72
- order.push(key);
73
70
  }
74
71
  disc.items.push(...noEvidenceItems);
75
72
  }
@@ -87,8 +84,8 @@ function assembleDiscs(albums) {
87
84
  const maxSibling = [...discs.values()].map((d) => d.discNumber).filter((n) => n !== void 0).reduce((a, b) => Math.max(a, b), 0) || void 0;
88
85
  for (const disc of discs.values()) disc.totalDiscs = commonTotal ?? ofN ?? maxSibling;
89
86
  const sortedDiscs = [...discs.values()].sort((a, b) => {
90
- const an = a.discNumber === void 0 ? -1 : a.discNumber;
91
- const bn = b.discNumber === void 0 ? -1 : b.discNumber;
87
+ const an = a.discNumber ?? -1;
88
+ const bn = b.discNumber ?? -1;
92
89
  if (an !== bn) return an - bn;
93
90
  return (a.folderDiscTitle ?? "").localeCompare(b.folderDiscTitle ?? "");
94
91
  });
@@ -1 +1 @@
1
- {"version":3,"file":"album-grouping.d.ts","sourceRoot":"","sources":["../../src/folder-api/album-grouping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAEV,mBAAmB,EAInB,kBAAkB,EAEnB,MAAM,kBAAkB,CAAC;AA2I1B,wBAAgB,WAAW,CACzB,MAAM,EAAE,gBAAgB,EACxB,OAAO,GAAE,kBAAuB,GAC/B,mBAAmB,CAwCrB"}
1
+ {"version":3,"file":"album-grouping.d.ts","sourceRoot":"","sources":["../../src/folder-api/album-grouping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAEV,mBAAmB,EAInB,kBAAkB,EAEnB,MAAM,kBAAkB,CAAC;AA+J1B,wBAAgB,WAAW,CACzB,MAAM,EAAE,gBAAgB,EACxB,OAAO,GAAE,kBAAuB,GAC/B,mBAAmB,CAwCrB"}