@docen/export-docx 0.0.11 → 0.0.12

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.d.mts CHANGED
@@ -6630,10 +6630,14 @@ declare function createFloatingOptions(): {
6630
6630
  };
6631
6631
  /**
6632
6632
  * Get image width with priority: node attrs > image meta > calculated > default
6633
+ *
6634
+ * Note: maxWidth constraint only applies to inline (non-floating) images.
6635
+ * Floating images maintain their original dimensions.
6633
6636
  */
6634
6637
  declare function getImageWidth(node: {
6635
6638
  attrs?: {
6636
6639
  width?: number | null;
6640
+ floating?: any;
6637
6641
  };
6638
6642
  }, imageMeta?: {
6639
6643
  width?: number;
@@ -6641,10 +6645,15 @@ declare function getImageWidth(node: {
6641
6645
  }, maxWidth?: number | PositiveUniversalMeasure$1): number;
6642
6646
  /**
6643
6647
  * Get image height with priority: node attrs > image meta > calculated > default
6648
+ *
6649
+ * Note: maxWidth constraint only applies to inline (non-floating) images.
6650
+ * Floating images maintain their original dimensions and aspect ratio.
6644
6651
  */
6645
6652
  declare function getImageHeight(node: {
6646
6653
  attrs?: {
6647
6654
  height?: number | null;
6655
+ width?: number | null;
6656
+ floating?: any;
6648
6657
  };
6649
6658
  }, width: number, imageMeta?: {
6650
6659
  width?: number;
package/dist/index.mjs CHANGED
@@ -525,18 +525,42 @@ function createFloatingOptions() {
525
525
  }
526
526
  /**
527
527
  * Get image width with priority: node attrs > image meta > calculated > default
528
+ *
529
+ * Note: maxWidth constraint only applies to inline (non-floating) images.
530
+ * Floating images maintain their original dimensions.
528
531
  */
529
532
  function getImageWidth(node, imageMeta, maxWidth) {
530
- if (node.attrs?.width !== void 0 && node.attrs?.width !== null) return node.attrs.width;
533
+ if (node.attrs?.width !== void 0 && node.attrs?.width !== null) {
534
+ const requestedWidth = node.attrs.width;
535
+ if (!node.attrs.floating && maxWidth) {
536
+ const maxWidthPixels = maxWidth !== void 0 ? convertMeasureToPixels(maxWidth) : void 0;
537
+ if (maxWidthPixels && requestedWidth > maxWidthPixels) return maxWidthPixels;
538
+ }
539
+ return requestedWidth;
540
+ }
531
541
  const maxWidthPixels = maxWidth !== void 0 ? convertMeasureToPixels(maxWidth) : void 0;
532
542
  if (imageMeta?.width && imageMeta?.height) return calculateDisplaySize(imageMeta, maxWidthPixels).width;
533
543
  return maxWidthPixels || DEFAULT_MAX_IMAGE_WIDTH_PIXELS;
534
544
  }
535
545
  /**
536
546
  * Get image height with priority: node attrs > image meta > calculated > default
547
+ *
548
+ * Note: maxWidth constraint only applies to inline (non-floating) images.
549
+ * Floating images maintain their original dimensions and aspect ratio.
537
550
  */
538
551
  function getImageHeight(node, width, imageMeta, maxWidth) {
539
- if (node.attrs?.height !== void 0 && node.attrs?.height !== null) return node.attrs.height;
552
+ if (node.attrs?.height !== void 0 && node.attrs?.height !== null) {
553
+ const requestedHeight = node.attrs.height;
554
+ if (!node.attrs.floating && maxWidth && node.attrs?.width) {
555
+ const maxWidthPixels = maxWidth !== void 0 ? convertMeasureToPixels(maxWidth) : void 0;
556
+ const requestedWidth = node.attrs.width;
557
+ if (maxWidthPixels && requestedWidth > maxWidthPixels) {
558
+ const scaleFactor = maxWidthPixels / requestedWidth;
559
+ return Math.round(requestedHeight * scaleFactor);
560
+ }
561
+ }
562
+ return requestedHeight;
563
+ }
540
564
  const maxWidthPixels = maxWidth !== void 0 ? convertMeasureToPixels(maxWidth) : void 0;
541
565
  if (imageMeta?.width && imageMeta?.height) return calculateDisplaySize(imageMeta, maxWidthPixels).height;
542
566
  return Math.round(width * .75);
@@ -1016,6 +1040,7 @@ async function convertTable(node, params) {
1016
1040
  const { options } = params;
1017
1041
  let tableOptions = {
1018
1042
  rows: await Promise.all((node.content || []).map((row) => convertTableRow(row, params))),
1043
+ ...options?.style?.id && { style: options.style.id },
1019
1044
  ...options?.run
1020
1045
  };
1021
1046
  tableOptions = applyTableMargins(tableOptions, node);
@@ -1270,7 +1295,11 @@ async function convertNode(node, options, effectiveContentWidth) {
1270
1295
  return new Paragraph(applyStyleReference(paragraphOptions, styleId));
1271
1296
  });
1272
1297
  }
1273
- return createDOCXObject(applyStyleReference(dataResult, getStyleIdByNodeType(node.type, options)));
1298
+ let styleId = getStyleIdByNodeType(node.type, options);
1299
+ if (!styleId && node.type === "paragraph" && node.content) {
1300
+ if (node.content.length > 0 && node.content.every((child) => child.type === "image")) styleId = options.image?.style?.id;
1301
+ }
1302
+ return createDOCXObject(applyStyleReference(dataResult, styleId));
1274
1303
  }
1275
1304
  /**
1276
1305
  * Layer 1: Data Transformation
@@ -1289,11 +1318,11 @@ async function convertNodeData(node, options, effectiveContentWidth) {
1289
1318
  case "heading": return convertHeading(node);
1290
1319
  case "blockquote": return convertBlockquote(node);
1291
1320
  case "codeBlock": return convertCodeBlock(node);
1292
- case "image": return { children: [await convertImage(node, {
1321
+ case "image": return applyStyleReference({ children: [await convertImage(node, {
1293
1322
  maxWidth: effectiveContentWidth,
1294
1323
  options: options.image?.run,
1295
1324
  handler: options.image?.handler
1296
- })] };
1325
+ })] }, getStyleIdByNodeType("image", options));
1297
1326
  case "table": return await convertTable(node, { options: options.table });
1298
1327
  case "bulletList": return await convertList(node, { listType: "bullet" });
1299
1328
  case "orderedList": return await convertList(node, { listType: "ordered" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docen/export-docx",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "A powerful TipTap/ProseMirror extension that converts editor content to Microsoft Word DOCX format",
5
5
  "keywords": [
6
6
  "converter",
@@ -55,8 +55,8 @@
55
55
  },
56
56
  "devDependencies": {
57
57
  "@tiptap/core": "3.20.1",
58
- "@docen/utils": "0.0.11",
59
- "@docen/extensions": "0.0.11"
58
+ "@docen/utils": "0.0.12",
59
+ "@docen/extensions": "0.0.12"
60
60
  },
61
61
  "scripts": {
62
62
  "dev": "basis build --stub",