@abraca/dabra 2.17.0 → 2.17.1

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.
@@ -19261,6 +19261,41 @@ var TreeManager = class {
19261
19261
  * - cover set + no image/video remains → clear the three cover keys;
19262
19262
  * - no cover + at least one image/video → adopt the first as the cover.
19263
19263
  */
19264
+ const EXT_MIME = {
19265
+ png: "image/png",
19266
+ jpg: "image/jpeg",
19267
+ jpeg: "image/jpeg",
19268
+ gif: "image/gif",
19269
+ webp: "image/webp",
19270
+ avif: "image/avif",
19271
+ svg: "image/svg+xml",
19272
+ bmp: "image/bmp",
19273
+ heic: "image/heic",
19274
+ heif: "image/heif",
19275
+ mp4: "video/mp4",
19276
+ webm: "video/webm",
19277
+ mov: "video/quicktime",
19278
+ m4v: "video/x-m4v",
19279
+ ogv: "video/ogg",
19280
+ mkv: "video/x-matroska"
19281
+ };
19282
+ function attr(node, name) {
19283
+ const v = node.getAttribute(name);
19284
+ return typeof v === "string" && v ? v : void 0;
19285
+ }
19286
+ /**
19287
+ * Resolve a file node's mime type. A `fileBlock` may carry the mime under
19288
+ * `mimeType` (cou-sh's TipTap/y-prosemirror node attr) or `mime` (the
19289
+ * `@abraca/convert` markdown path), and may carry neither — in which case we
19290
+ * infer it from the filename/src extension (the convert sidecar `src` is
19291
+ * `.abracadabra/files/<id>-<filename>`). Returns "" when it can't be
19292
+ * classified as image/video.
19293
+ */
19294
+ function resolveMime(node) {
19295
+ const explicit = attr(node, "mimeType") ?? attr(node, "mime");
19296
+ if (explicit) return explicit;
19297
+ return EXT_MIME[(attr(node, "filename") ?? attr(node, "src") ?? "").split(".").pop()?.toLowerCase() ?? ""] ?? "";
19298
+ }
19264
19299
  /**
19265
19300
  * Recursively collect image/video `fileBlock` nodes from a Y.XmlFragment (or
19266
19301
  * element subtree), in document order. Mirrors the TipTap
@@ -19271,17 +19306,14 @@ function collectMediaFileBlocks(root) {
19271
19306
  const out = [];
19272
19307
  const visit = (node) => {
19273
19308
  if (node instanceof yjs.XmlElement && node.nodeName === "fileBlock") {
19274
- const mimeType = node.getAttribute("mimeType");
19275
- if (typeof mimeType === "string" && (mimeType.startsWith("image/") || mimeType.startsWith("video/"))) {
19276
- const uploadId = node.getAttribute("uploadId");
19277
- if (typeof uploadId === "string" && uploadId) {
19278
- const docId = node.getAttribute("docId");
19279
- out.push({
19280
- uploadId,
19281
- docId: typeof docId === "string" ? docId : "",
19282
- mimeType
19283
- });
19284
- }
19309
+ const uploadId = attr(node, "uploadId") ?? attr(node, "upload-id");
19310
+ if (uploadId) {
19311
+ const mimeType = resolveMime(node);
19312
+ if (mimeType.startsWith("image/") || mimeType.startsWith("video/")) out.push({
19313
+ uploadId,
19314
+ docId: attr(node, "docId") ?? "",
19315
+ mimeType
19316
+ });
19285
19317
  }
19286
19318
  }
19287
19319
  if (node instanceof yjs.XmlElement || node instanceof yjs.XmlFragment) for (let i = 0; i < node.length; i++) visit(node.get(i));