docx-plus 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -21,11 +21,12 @@
21
21
 
22
22
  ## What's Different from docx?
23
23
 
24
- | | docx | docx-plus |
25
- | --------------------- | ----------------------------------------- | ------------------------------------ |
26
- | ZIP handling | jszip | **fflate** (faster, smaller) |
27
- | Data conversion | Manual env detection (`Buffer.from` etc.) | **undio** (universal `toUint8Array`) |
28
- | Test environment | jsdom | happy-dom |
24
+ | | docx | docx-plus |
25
+ | ------------------- | ----------------------------------------- | ------------------------------------ |
26
+ | ZIP handling | jszip | **fflate** (faster, smaller) |
27
+ | Data conversion | Manual env detection (`Buffer.from` etc.) | **undio** (universal `toUint8Array`) |
28
+ | `Packer.toStream()` | Removed (pseudo-streaming) | **Restored** with real streaming ZIP |
29
+ | Test environment | jsdom | happy-dom |
29
30
 
30
31
  ## Installation
31
32
 
package/dist/index.cjs CHANGED
@@ -25,8 +25,9 @@ let xml_js = require("xml-js");
25
25
  let hash_js = require("hash.js");
26
26
  hash_js = __toESM(hash_js);
27
27
  let nanoid_non_secure = require("nanoid/non-secure");
28
- let fflate = require("fflate");
29
28
  let undio = require("undio");
29
+ let stream = require("stream");
30
+ let fflate = require("fflate");
30
31
  let xml = require("xml");
31
32
  xml = __toESM(xml);
32
33
  //#region \0@oxc-project+runtime@0.123.0/helpers/typeof.js
@@ -5776,29 +5777,20 @@ var Drawing = class extends XmlComponent {
5776
5777
  };
5777
5778
  //#endregion
5778
5779
  //#region src/file/paragraph/run/image-run.ts
5779
- const convertDataURIToBinary = (dataURI) => {
5780
- const base64Index = dataURI.indexOf(";base64,");
5781
- const base64IndexWithOffset = base64Index === -1 ? 0 : base64Index + 8;
5782
- const binaryString = atob(dataURI.substring(base64IndexWithOffset));
5783
- const bytes = new Uint8Array(binaryString.length);
5784
- for (let i = 0; i < binaryString.length; i++) bytes[i] = binaryString.charCodeAt(i);
5785
- return bytes;
5786
- };
5787
- const standardizeData = (data) => typeof data === "string" ? convertDataURIToBinary(data) : data;
5788
- const createImageData = (options, key) => ({
5789
- data: standardizeData(options.data),
5780
+ const createImageData = (data, transformation, key) => ({
5781
+ data,
5790
5782
  fileName: key,
5791
5783
  transformation: {
5792
5784
  emus: {
5793
- x: Math.round(options.transformation.width * 9525),
5794
- y: Math.round(options.transformation.height * 9525)
5785
+ x: Math.round(transformation.width * 9525),
5786
+ y: Math.round(transformation.height * 9525)
5795
5787
  },
5796
- flip: options.transformation.flip,
5788
+ flip: transformation.flip,
5797
5789
  pixels: {
5798
- x: Math.round(options.transformation.width),
5799
- y: Math.round(options.transformation.height)
5790
+ x: Math.round(transformation.width),
5791
+ y: Math.round(transformation.height)
5800
5792
  },
5801
- rotation: options.transformation.rotation ? options.transformation.rotation * 6e4 : void 0
5793
+ rotation: transformation.rotation ? transformation.rotation * 6e4 : void 0
5802
5794
  }
5803
5795
  });
5804
5796
  /**
@@ -5827,8 +5819,12 @@ var ImageRun = class extends Run {
5827
5819
  constructor(options) {
5828
5820
  super({});
5829
5821
  _defineProperty(this, "imageData", void 0);
5830
- const key = `${hashedId(options.data)}.${options.type}`;
5831
- this.imageData = options.type === "svg" ? _objectSpread2(_objectSpread2({ type: options.type }, createImageData(options, key)), {}, { fallback: _objectSpread2({ type: options.fallback.type }, createImageData(_objectSpread2(_objectSpread2({}, options.fallback), {}, { transformation: options.transformation }), `${hashedId(options.fallback.data)}.${options.fallback.type}`)) }) : _objectSpread2({ type: options.type }, createImageData(options, key));
5822
+ const rawData = (0, undio.toUint8Array)(options.data);
5823
+ const key = `${hashedId(rawData)}.${options.type}`;
5824
+ if (options.type === "svg") {
5825
+ const fallbackData = (0, undio.toUint8Array)(options.fallback.data);
5826
+ this.imageData = _objectSpread2(_objectSpread2({ type: options.type }, createImageData(rawData, options.transformation, key)), {}, { fallback: _objectSpread2({ type: options.fallback.type }, createImageData(fallbackData, options.transformation, `${hashedId(fallbackData)}.${options.fallback.type}`)) });
5827
+ } else this.imageData = _objectSpread2({ type: options.type }, createImageData(rawData, options.transformation, key));
5832
5828
  const drawing = new Drawing(this.imageData, {
5833
5829
  docProperties: options.altText,
5834
5830
  floating: options.floating,
@@ -18291,6 +18287,14 @@ var Textbox = class extends FileChild {
18291
18287
  //#endregion
18292
18288
  //#region src/util/output-type.ts
18293
18289
  /**
18290
+ * Output type definitions for document generation.
18291
+ *
18292
+ * This module defines the various output formats supported when generating
18293
+ * .docx files. These types correspond to fflate's output formats.
18294
+ *
18295
+ * @module
18296
+ */
18297
+ /**
18294
18298
  * Converts a Uint8Array to the specified output type.
18295
18299
  *
18296
18300
  * This is used by both the Packer and patchDocument to convert fflate's
@@ -18302,10 +18306,10 @@ const convertOutput = (data, type) => {
18302
18306
  case "blob": return new Blob([data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
18303
18307
  case "arraybuffer": return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
18304
18308
  case "uint8array": return data;
18305
- case "base64": return Buffer.from(data).toString("base64");
18309
+ case "base64": return btoa((0, fflate.strFromU8)(data, true));
18306
18310
  case "string":
18307
- case "text": return Buffer.from(data).toString("binary");
18308
- case "binarystring": return Buffer.from(data).toString("binary");
18311
+ case "text":
18312
+ case "binarystring": return (0, fflate.strFromU8)(data, true);
18309
18313
  case "array": return [...data];
18310
18314
  default: return data;
18311
18315
  }
@@ -19019,6 +19023,50 @@ var Packer = class Packer {
19019
19023
  static toArrayBuffer(file, prettify, overrides = []) {
19020
19024
  return Packer.pack(file, "arraybuffer", prettify, overrides);
19021
19025
  }
19026
+ /**
19027
+ * Exports a document to a Node.js Readable stream.
19028
+ *
19029
+ * Uses fflate's streaming Zip API to emit compressed chunks incrementally,
19030
+ * avoiding buffering the entire archive in memory before the first byte
19031
+ * is available to the consumer.
19032
+ *
19033
+ * @param file - The document to export
19034
+ * @param prettify - Whether to prettify the XML output
19035
+ * @param overrides - Optional array of file overrides
19036
+ * @returns A readable stream containing the compressed .docx data
19037
+ *
19038
+ * @example
19039
+ * ```typescript
19040
+ * import { createWriteStream } from "fs";
19041
+ * Packer.toStream(doc).pipe(createWriteStream("output.docx"));
19042
+ * ```
19043
+ */
19044
+ static toStream(file, prettify, overrides = []) {
19045
+ const stream$1 = new stream.Readable({ read() {} });
19046
+ try {
19047
+ const files = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
19048
+ const zip = new fflate.Zip((err, chunk, final) => {
19049
+ if (err) {
19050
+ stream$1.destroy(err);
19051
+ return;
19052
+ }
19053
+ if (!stream$1.destroyed) stream$1.push(chunk);
19054
+ if (final) stream$1.push(null);
19055
+ });
19056
+ for (const [name, data] of Object.entries(files)) {
19057
+ var _level;
19058
+ const raw = Array.isArray(data) ? data[0] : data;
19059
+ const level = Array.isArray(data) ? (_level = data[1].level) !== null && _level !== void 0 ? _level : 6 : 6;
19060
+ const entry = level === 0 ? new fflate.ZipPassThrough(name) : new fflate.ZipDeflate(name, { level });
19061
+ zip.add(entry);
19062
+ entry.push(raw, true);
19063
+ }
19064
+ zip.end();
19065
+ } catch (err) {
19066
+ stream$1.destroy(err instanceof Error ? err : new Error(String(err)));
19067
+ }
19068
+ return stream$1;
19069
+ }
19022
19070
  };
19023
19071
  _defineProperty(Packer, "compiler", new Compiler());
19024
19072
  //#endregion
@@ -20134,7 +20182,6 @@ exports.sectionPageSizeDefaults = sectionPageSizeDefaults;
20134
20182
  exports.shortHexNumber = shortHexNumber;
20135
20183
  exports.signedHpsMeasureValue = signedHpsMeasureValue;
20136
20184
  exports.signedTwipsMeasureValue = signedTwipsMeasureValue;
20137
- exports.standardizeData = standardizeData;
20138
20185
  exports.twipsMeasureValue = twipsMeasureValue;
20139
20186
  exports.uCharHexNumber = uCharHexNumber;
20140
20187
  exports.uniqueId = uniqueId;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,6 @@
1
+ import { DataType } from "undio";
1
2
  import { Element } from "xml-js";
3
+ import { Readable } from "stream";
2
4
  //#region src/file/file-child.d.ts
3
5
  declare class FileChild extends XmlComponent {
4
6
  readonly fileChild: symbol;
@@ -699,7 +701,7 @@ interface IMediaDataTransformation {
699
701
  interface CoreMediaData {
700
702
  readonly fileName: string;
701
703
  readonly transformation: IMediaDataTransformation;
702
- readonly data: Buffer | Uint8Array | ArrayBuffer;
704
+ readonly data: Uint8Array;
703
705
  }
704
706
  interface RegularMediaData {
705
707
  readonly type: "jpg" | "png" | "gif" | "bmp";
@@ -775,15 +777,14 @@ interface CoreImageOptions {
775
777
  }
776
778
  interface RegularImageOptions {
777
779
  readonly type: "jpg" | "png" | "gif" | "bmp";
778
- readonly data: Buffer | string | Uint8Array | ArrayBuffer;
780
+ readonly data: DataType;
779
781
  }
780
782
  interface SvgMediaOptions {
781
783
  readonly type: "svg";
782
- readonly data: Buffer | string | Uint8Array | ArrayBuffer;
784
+ readonly data: DataType;
783
785
  readonly fallback: RegularImageOptions;
784
786
  }
785
787
  type IImageOptions = (RegularImageOptions | SvgMediaOptions) & CoreImageOptions;
786
- declare const standardizeData: (data: string | Buffer | Uint8Array | ArrayBuffer) => Buffer | Uint8Array | ArrayBuffer;
787
788
  declare class ImageRun extends Run {
788
789
  private readonly imageData;
789
790
  constructor(options: IImageOptions);
@@ -3166,6 +3167,7 @@ declare class Packer {
3166
3167
  static toBase64String(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<string>;
3167
3168
  static toBlob(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<Blob>;
3168
3169
  static toArrayBuffer(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<ArrayBuffer>;
3170
+ static toStream(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Readable;
3169
3171
  private static readonly compiler;
3170
3172
  }
3171
3173
  //#endregion
@@ -3227,4 +3229,4 @@ declare const patchDetector: ({
3227
3229
  data
3228
3230
  }: PatchDetectorOptions) => Promise<readonly string[]>;
3229
3231
  //#endregion
3230
- export { AbstractNumbering, AlignmentType, AnnotationReference, AttributeData, AttributeMap, AttributePayload, Attributes, BaseXmlComponent, Body, Bookmark, BookmarkEnd, BookmarkStart, Border, BorderStyle, BuilderElement, CarriageReturn, CellMerge, CellMergeAttributes, CharacterSet, CheckBox, CheckBoxSymbolElement, CheckBoxUtil, Column, ColumnBreak, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments, ConcreteHyperlink, ConcreteNumbering, ContinuationSeparator, DayLong, DayShort, DeletedTableCell, DeletedTableRow, DeletedTextRun, File as Document, File, DocumentAttributeNamespace, DocumentAttributeNamespaces, DocumentAttributes, DocumentBackground, DocumentBackgroundAttributes, DocumentDefaults, DocumentGridType, Drawing, DropCapType, EMPTY_OBJECT, EmphasisMarkType, EmptyElement, EndnoteIdReference, EndnoteReference, EndnoteReferenceRun, EndnoteReferenceRunAttributes, Endnotes, ExternalHyperlink, FileChild, FootNoteReferenceRunAttributes, FootNotes, Footer, FooterWrapper, FootnoteReference, FootnoteReferenceElement, FootnoteReferenceRun, FrameAnchorType, FrameWrap, GridSpan, Header, HeaderFooterReferenceType, HeaderFooterType, HeaderWrapper, HeadingLevel, HeightRule, HighlightColor, HorizontalPositionAlign, HorizontalPositionRelativeFrom, HpsMeasureElement, HyperlinkType, IAlignmentFrameOptions, IBaseCharacterStyleOptions, IBaseParagraphStyleOptions, IBodyPropertiesOptions, IBookmarkOptions, IBorderOptions, IBordersOptions, ICellMergeAttributes, ICharacterStyleOptions, ICheckboxSymbolOptions, ICheckboxSymbolProperties, IColumnAttributes, IColumnsAttributes, ICommentOptions, ICommentsOptions, IConcreteNumberingOptions, IContext, IDistance, IDocGridAttributesProperties, IDocumentAttributesProperties, IDocumentBackgroundOptions, IDocumentDefaultsOptions, IDocumentFooter, IDocumentHeader, IDocumentOptions, IDrawingOptions, IExtendedMediaData, IExternalHyperlinkOptions, IFloating, IFontAttributesProperties, IFrameOptions, IGroupChildMediaData, IHeaderFooterGroup, IHeaderFooterOptions, IHeaderOptions, IHorizontalPositionOptions, IImageOptions, IIndentAttributesProperties, IInternalHyperlinkOptions, ILevelParagraphStylePropertiesOptions, ILevelsOptions, ILineNumberAttributes, IMargins, IMathFractionOptions, IMathFunctionOptions, IMathIntegralOptions, IMathLimitLowerOptions, IMathLimitUpperOptions, IMathOptions, IMathPreSubSuperScriptOptions, IMathRadicalOptions, IMathSubScriptOptions, IMathSubSuperScriptOptions, IMathSumOptions, IMathSuperScriptOptions, IMediaData, IMediaDataTransformation, IMediaTransformation, INumberedItemReferenceOptions, INumberingOptions, IPageBorderAttributes, IPageBordersOptions, IPageMarginAttributes, IPageNumberTypeAttributes, IPageReferenceOptions, IPageSizeAttributes, IParagraphOptions, IParagraphPropertiesChangeOptions, IParagraphPropertiesOptions, IParagraphPropertiesOptionsBase, IParagraphRunOptions, IParagraphRunPropertiesOptions, IParagraphStyleOptions, IParagraphStylePropertiesOptions, IPatch, type IPropertiesOptions, IRunOptions, IRunPropertiesChangeOptions, IRunPropertiesOptions, IRunStylePropertiesOptions, ISectionOptions, ISectionPropertiesChangeOptions, ISectionPropertiesOptions, ISectionPropertiesOptionsBase, IShadingAttributesProperties, ISpacingProperties, IStylesOptions, ISymbolRunOptions, ITableBordersOptions, ITableCellBorders, ITableCellOptions, ITableFloatOptions, ITableLookOptions, ITableOfContentsOptions, ITableOptions, ITablePropertiesChangeOptions, ITablePropertiesOptions, ITablePropertiesOptionsBase, ITableRowOptions, ITableRowPropertiesChangeOptions, ITableRowPropertiesOptions, ITableRowPropertiesOptionsBase, ITableWidthProperties, ITextWrapping, IVerticalPositionOptions, IWpgGroupOptions, IWpsShapeOptions, IXYFrameOptions, IXmlAttribute, IXmlableObject, IgnoreIfEmptyXmlComponent, ImageRun, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, InputDataType, InsertedTableCell, InsertedTableRow, InsertedTextRun, InternalHyperlink, LastRenderedPageBreak, LeaderType, Level, LevelBase, LevelForOverride, LevelFormat, LevelOverride, LevelSuffix, LineNumberRestartFormat, LineRuleType, Math, MathAngledBrackets, MathComponent, MathCurlyBrackets, MathDegree, MathDenominator, MathFraction, MathFunction, MathFunctionName, MathFunctionProperties, MathIntegral, MathLimit, MathLimitLower, MathLimitUpper, MathNumerator, MathPreSubSuperScript, MathRadical, MathRadicalProperties, MathRoundBrackets, MathRun, MathSquareBrackets, MathSubScript, MathSubSuperScript, MathSum, MathSuperScript, Media, MonthLong, MonthShort, NextAttributeComponent, NoBreakHyphen, NumberFormat, NumberProperties, NumberValueElement, NumberedItemReference, NumberedItemReferenceFormat, Numbering, OnOffElement, OutputByType, OutputType, OverlapType, Packer, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder, PageBorders, PageBreak, PageBreakBefore, PageNumber, PageNumberElement, PageNumberSeparator, PageOrientation, PageReference, PageTextDirection, PageTextDirectionType, Paragraph, ParagraphChild, ParagraphProperties, ParagraphPropertiesChange, ParagraphPropertiesDefaults, ParagraphRunProperties, PatchDocumentOptions, PatchDocumentOutputType, PatchType, Percentage, PositionalTab, PositionalTabAlignment, PositionalTabLeader, PositionalTabOptions, PositionalTabRelativeTo, PositivePercentage, PositiveUniversalMeasure, PrettifyType, RelativeHorizontalPosition, RelativeMeasure, RelativeVerticalPosition, Run, RunProperties, RunPropertiesChange, RunPropertiesDefaults, SectionProperties, SectionPropertiesChange, SectionType, SectionVerticalAlign, Separator, SequentialIdentifier, ShadingType, SimpleField, SimpleMailMergeField, SoftHyphen, SpaceType, StringContainer, StringEnumValueElement, StringValueElement, StyleForCharacter, StyleForParagraph, StyleLevel, Styles, SymbolRun, TDirection, Tab, TabStopDefinition, TabStopPosition, TabStopType, Table, TableAnchorType, TableBorders, TableCell, TableCellBorders, TableLayoutType, TableOfContents, TableProperties, TableRow, TableRowProperties, TableRowPropertiesChange, TableVerticalAlign, TextDirection, TextEffect, TextRun, TextWrappingSide, TextWrappingType, Textbox, ThematicBreak, UnderlineType, UniqueNumericIdCreator, UniversalMeasure, VerticalAlign, VerticalAlignSection, VerticalAlignTable, VerticalAnchor, VerticalMerge, VerticalMergeRevisionType, VerticalMergeType, VerticalPositionAlign, VerticalPositionRelativeFrom, WORKAROUND2, WORKAROUND3, WORKAROUND4, WidthType, WpgCommonMediaData, WpgGroupRun, WpgMediaData, WpsMediaData, WpsShapeRun, XmlAttributeComponent, XmlComponent, YearLong, YearShort, abstractNumUniqueNumericIdGen, bookmarkUniqueNumericIdGen, concreteNumUniqueNumericIdGen, convertInchesToTwip, convertMillimetersToTwip, convertOutput, convertToXmlComponent, createAlignment, createBodyProperties, createBorderElement, createColumns, createDocumentGrid, createDotEmphasisMark, createEmphasisMark, createFrameProperties, createHeaderFooterReference, createHorizontalPosition, createIndent, createLineNumberType, createMathAccentCharacter, createMathBase, createMathLimitLocation, createMathNAryProperties, createMathPreSubSuperScriptProperties, createMathSubScriptElement, createMathSubScriptProperties, createMathSubSuperScriptProperties, createMathSuperScriptElement, createMathSuperScriptProperties, createOutlineLevel, createPageMargin, createPageNumberType, createPageSize, createParagraphStyle, createRunFonts, createSectionType, createShading, createSimplePos, createSpacing, createStringElement, createTabStop, createTabStopItem, createTableFloatProperties, createTableLayout, createTableLook, createTableRowHeight, createTableWidthElement, createTransformation, createUnderline, createVerticalAlign, createVerticalPosition, createWrapNone, createWrapSquare, createWrapTight, createWrapTopAndBottom, dateTimeValue, decimalNumber, docPropertiesUniqueNumericIdGen, eighthPointMeasureValue, encodeUtf8, hashedId, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, patchDetector, patchDocument, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, sectionMarginDefaults, sectionPageSizeDefaults, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, standardizeData, twipsMeasureValue, uCharHexNumber, uniqueId, uniqueNumericIdCreator, uniqueUuid, universalMeasureValue, unsignedDecimalNumber };
3232
+ export { AbstractNumbering, AlignmentType, AnnotationReference, AttributeData, AttributeMap, AttributePayload, Attributes, BaseXmlComponent, Body, Bookmark, BookmarkEnd, BookmarkStart, Border, BorderStyle, BuilderElement, CarriageReturn, CellMerge, CellMergeAttributes, CharacterSet, CheckBox, CheckBoxSymbolElement, CheckBoxUtil, Column, ColumnBreak, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments, ConcreteHyperlink, ConcreteNumbering, ContinuationSeparator, DayLong, DayShort, DeletedTableCell, DeletedTableRow, DeletedTextRun, File as Document, File, DocumentAttributeNamespace, DocumentAttributeNamespaces, DocumentAttributes, DocumentBackground, DocumentBackgroundAttributes, DocumentDefaults, DocumentGridType, Drawing, DropCapType, EMPTY_OBJECT, EmphasisMarkType, EmptyElement, EndnoteIdReference, EndnoteReference, EndnoteReferenceRun, EndnoteReferenceRunAttributes, Endnotes, ExternalHyperlink, FileChild, FootNoteReferenceRunAttributes, FootNotes, Footer, FooterWrapper, FootnoteReference, FootnoteReferenceElement, FootnoteReferenceRun, FrameAnchorType, FrameWrap, GridSpan, Header, HeaderFooterReferenceType, HeaderFooterType, HeaderWrapper, HeadingLevel, HeightRule, HighlightColor, HorizontalPositionAlign, HorizontalPositionRelativeFrom, HpsMeasureElement, HyperlinkType, IAlignmentFrameOptions, IBaseCharacterStyleOptions, IBaseParagraphStyleOptions, IBodyPropertiesOptions, IBookmarkOptions, IBorderOptions, IBordersOptions, ICellMergeAttributes, ICharacterStyleOptions, ICheckboxSymbolOptions, ICheckboxSymbolProperties, IColumnAttributes, IColumnsAttributes, ICommentOptions, ICommentsOptions, IConcreteNumberingOptions, IContext, IDistance, IDocGridAttributesProperties, IDocumentAttributesProperties, IDocumentBackgroundOptions, IDocumentDefaultsOptions, IDocumentFooter, IDocumentHeader, IDocumentOptions, IDrawingOptions, IExtendedMediaData, IExternalHyperlinkOptions, IFloating, IFontAttributesProperties, IFrameOptions, IGroupChildMediaData, IHeaderFooterGroup, IHeaderFooterOptions, IHeaderOptions, IHorizontalPositionOptions, IImageOptions, IIndentAttributesProperties, IInternalHyperlinkOptions, ILevelParagraphStylePropertiesOptions, ILevelsOptions, ILineNumberAttributes, IMargins, IMathFractionOptions, IMathFunctionOptions, IMathIntegralOptions, IMathLimitLowerOptions, IMathLimitUpperOptions, IMathOptions, IMathPreSubSuperScriptOptions, IMathRadicalOptions, IMathSubScriptOptions, IMathSubSuperScriptOptions, IMathSumOptions, IMathSuperScriptOptions, IMediaData, IMediaDataTransformation, IMediaTransformation, INumberedItemReferenceOptions, INumberingOptions, IPageBorderAttributes, IPageBordersOptions, IPageMarginAttributes, IPageNumberTypeAttributes, IPageReferenceOptions, IPageSizeAttributes, IParagraphOptions, IParagraphPropertiesChangeOptions, IParagraphPropertiesOptions, IParagraphPropertiesOptionsBase, IParagraphRunOptions, IParagraphRunPropertiesOptions, IParagraphStyleOptions, IParagraphStylePropertiesOptions, IPatch, type IPropertiesOptions, IRunOptions, IRunPropertiesChangeOptions, IRunPropertiesOptions, IRunStylePropertiesOptions, ISectionOptions, ISectionPropertiesChangeOptions, ISectionPropertiesOptions, ISectionPropertiesOptionsBase, IShadingAttributesProperties, ISpacingProperties, IStylesOptions, ISymbolRunOptions, ITableBordersOptions, ITableCellBorders, ITableCellOptions, ITableFloatOptions, ITableLookOptions, ITableOfContentsOptions, ITableOptions, ITablePropertiesChangeOptions, ITablePropertiesOptions, ITablePropertiesOptionsBase, ITableRowOptions, ITableRowPropertiesChangeOptions, ITableRowPropertiesOptions, ITableRowPropertiesOptionsBase, ITableWidthProperties, ITextWrapping, IVerticalPositionOptions, IWpgGroupOptions, IWpsShapeOptions, IXYFrameOptions, IXmlAttribute, IXmlableObject, IgnoreIfEmptyXmlComponent, ImageRun, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, InputDataType, InsertedTableCell, InsertedTableRow, InsertedTextRun, InternalHyperlink, LastRenderedPageBreak, LeaderType, Level, LevelBase, LevelForOverride, LevelFormat, LevelOverride, LevelSuffix, LineNumberRestartFormat, LineRuleType, Math, MathAngledBrackets, MathComponent, MathCurlyBrackets, MathDegree, MathDenominator, MathFraction, MathFunction, MathFunctionName, MathFunctionProperties, MathIntegral, MathLimit, MathLimitLower, MathLimitUpper, MathNumerator, MathPreSubSuperScript, MathRadical, MathRadicalProperties, MathRoundBrackets, MathRun, MathSquareBrackets, MathSubScript, MathSubSuperScript, MathSum, MathSuperScript, Media, MonthLong, MonthShort, NextAttributeComponent, NoBreakHyphen, NumberFormat, NumberProperties, NumberValueElement, NumberedItemReference, NumberedItemReferenceFormat, Numbering, OnOffElement, OutputByType, OutputType, OverlapType, Packer, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder, PageBorders, PageBreak, PageBreakBefore, PageNumber, PageNumberElement, PageNumberSeparator, PageOrientation, PageReference, PageTextDirection, PageTextDirectionType, Paragraph, ParagraphChild, ParagraphProperties, ParagraphPropertiesChange, ParagraphPropertiesDefaults, ParagraphRunProperties, PatchDocumentOptions, PatchDocumentOutputType, PatchType, Percentage, PositionalTab, PositionalTabAlignment, PositionalTabLeader, PositionalTabOptions, PositionalTabRelativeTo, PositivePercentage, PositiveUniversalMeasure, PrettifyType, RelativeHorizontalPosition, RelativeMeasure, RelativeVerticalPosition, Run, RunProperties, RunPropertiesChange, RunPropertiesDefaults, SectionProperties, SectionPropertiesChange, SectionType, SectionVerticalAlign, Separator, SequentialIdentifier, ShadingType, SimpleField, SimpleMailMergeField, SoftHyphen, SpaceType, StringContainer, StringEnumValueElement, StringValueElement, StyleForCharacter, StyleForParagraph, StyleLevel, Styles, SymbolRun, TDirection, Tab, TabStopDefinition, TabStopPosition, TabStopType, Table, TableAnchorType, TableBorders, TableCell, TableCellBorders, TableLayoutType, TableOfContents, TableProperties, TableRow, TableRowProperties, TableRowPropertiesChange, TableVerticalAlign, TextDirection, TextEffect, TextRun, TextWrappingSide, TextWrappingType, Textbox, ThematicBreak, UnderlineType, UniqueNumericIdCreator, UniversalMeasure, VerticalAlign, VerticalAlignSection, VerticalAlignTable, VerticalAnchor, VerticalMerge, VerticalMergeRevisionType, VerticalMergeType, VerticalPositionAlign, VerticalPositionRelativeFrom, WORKAROUND2, WORKAROUND3, WORKAROUND4, WidthType, WpgCommonMediaData, WpgGroupRun, WpgMediaData, WpsMediaData, WpsShapeRun, XmlAttributeComponent, XmlComponent, YearLong, YearShort, abstractNumUniqueNumericIdGen, bookmarkUniqueNumericIdGen, concreteNumUniqueNumericIdGen, convertInchesToTwip, convertMillimetersToTwip, convertOutput, convertToXmlComponent, createAlignment, createBodyProperties, createBorderElement, createColumns, createDocumentGrid, createDotEmphasisMark, createEmphasisMark, createFrameProperties, createHeaderFooterReference, createHorizontalPosition, createIndent, createLineNumberType, createMathAccentCharacter, createMathBase, createMathLimitLocation, createMathNAryProperties, createMathPreSubSuperScriptProperties, createMathSubScriptElement, createMathSubScriptProperties, createMathSubSuperScriptProperties, createMathSuperScriptElement, createMathSuperScriptProperties, createOutlineLevel, createPageMargin, createPageNumberType, createPageSize, createParagraphStyle, createRunFonts, createSectionType, createShading, createSimplePos, createSpacing, createStringElement, createTabStop, createTabStopItem, createTableFloatProperties, createTableLayout, createTableLook, createTableRowHeight, createTableWidthElement, createTransformation, createUnderline, createVerticalAlign, createVerticalPosition, createWrapNone, createWrapSquare, createWrapTight, createWrapTopAndBottom, dateTimeValue, decimalNumber, docPropertiesUniqueNumericIdGen, eighthPointMeasureValue, encodeUtf8, hashedId, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, patchDetector, patchDocument, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, sectionMarginDefaults, sectionPageSizeDefaults, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, twipsMeasureValue, uCharHexNumber, uniqueId, uniqueNumericIdCreator, uniqueUuid, universalMeasureValue, unsignedDecimalNumber };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { Element } from "xml-js";
2
+ import { DataType } from "undio";
3
+ import { Readable } from "stream";
2
4
  //#region src/file/file-child.d.ts
3
5
  declare class FileChild extends XmlComponent {
4
6
  readonly fileChild: symbol;
@@ -699,7 +701,7 @@ interface IMediaDataTransformation {
699
701
  interface CoreMediaData {
700
702
  readonly fileName: string;
701
703
  readonly transformation: IMediaDataTransformation;
702
- readonly data: Buffer | Uint8Array | ArrayBuffer;
704
+ readonly data: Uint8Array;
703
705
  }
704
706
  interface RegularMediaData {
705
707
  readonly type: "jpg" | "png" | "gif" | "bmp";
@@ -775,15 +777,14 @@ interface CoreImageOptions {
775
777
  }
776
778
  interface RegularImageOptions {
777
779
  readonly type: "jpg" | "png" | "gif" | "bmp";
778
- readonly data: Buffer | string | Uint8Array | ArrayBuffer;
780
+ readonly data: DataType;
779
781
  }
780
782
  interface SvgMediaOptions {
781
783
  readonly type: "svg";
782
- readonly data: Buffer | string | Uint8Array | ArrayBuffer;
784
+ readonly data: DataType;
783
785
  readonly fallback: RegularImageOptions;
784
786
  }
785
787
  type IImageOptions = (RegularImageOptions | SvgMediaOptions) & CoreImageOptions;
786
- declare const standardizeData: (data: string | Buffer | Uint8Array | ArrayBuffer) => Buffer | Uint8Array | ArrayBuffer;
787
788
  declare class ImageRun extends Run {
788
789
  private readonly imageData;
789
790
  constructor(options: IImageOptions);
@@ -3166,6 +3167,7 @@ declare class Packer {
3166
3167
  static toBase64String(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<string>;
3167
3168
  static toBlob(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<Blob>;
3168
3169
  static toArrayBuffer(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<ArrayBuffer>;
3170
+ static toStream(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Readable;
3169
3171
  private static readonly compiler;
3170
3172
  }
3171
3173
  //#endregion
@@ -3227,4 +3229,4 @@ declare const patchDetector: ({
3227
3229
  data
3228
3230
  }: PatchDetectorOptions) => Promise<readonly string[]>;
3229
3231
  //#endregion
3230
- export { AbstractNumbering, AlignmentType, AnnotationReference, AttributeData, AttributeMap, AttributePayload, Attributes, BaseXmlComponent, Body, Bookmark, BookmarkEnd, BookmarkStart, Border, BorderStyle, BuilderElement, CarriageReturn, CellMerge, CellMergeAttributes, CharacterSet, CheckBox, CheckBoxSymbolElement, CheckBoxUtil, Column, ColumnBreak, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments, ConcreteHyperlink, ConcreteNumbering, ContinuationSeparator, DayLong, DayShort, DeletedTableCell, DeletedTableRow, DeletedTextRun, File as Document, File, DocumentAttributeNamespace, DocumentAttributeNamespaces, DocumentAttributes, DocumentBackground, DocumentBackgroundAttributes, DocumentDefaults, DocumentGridType, Drawing, DropCapType, EMPTY_OBJECT, EmphasisMarkType, EmptyElement, EndnoteIdReference, EndnoteReference, EndnoteReferenceRun, EndnoteReferenceRunAttributes, Endnotes, ExternalHyperlink, FileChild, FootNoteReferenceRunAttributes, FootNotes, Footer, FooterWrapper, FootnoteReference, FootnoteReferenceElement, FootnoteReferenceRun, FrameAnchorType, FrameWrap, GridSpan, Header, HeaderFooterReferenceType, HeaderFooterType, HeaderWrapper, HeadingLevel, HeightRule, HighlightColor, HorizontalPositionAlign, HorizontalPositionRelativeFrom, HpsMeasureElement, HyperlinkType, IAlignmentFrameOptions, IBaseCharacterStyleOptions, IBaseParagraphStyleOptions, IBodyPropertiesOptions, IBookmarkOptions, IBorderOptions, IBordersOptions, ICellMergeAttributes, ICharacterStyleOptions, ICheckboxSymbolOptions, ICheckboxSymbolProperties, IColumnAttributes, IColumnsAttributes, ICommentOptions, ICommentsOptions, IConcreteNumberingOptions, IContext, IDistance, IDocGridAttributesProperties, IDocumentAttributesProperties, IDocumentBackgroundOptions, IDocumentDefaultsOptions, IDocumentFooter, IDocumentHeader, IDocumentOptions, IDrawingOptions, IExtendedMediaData, IExternalHyperlinkOptions, IFloating, IFontAttributesProperties, IFrameOptions, IGroupChildMediaData, IHeaderFooterGroup, IHeaderFooterOptions, IHeaderOptions, IHorizontalPositionOptions, IImageOptions, IIndentAttributesProperties, IInternalHyperlinkOptions, ILevelParagraphStylePropertiesOptions, ILevelsOptions, ILineNumberAttributes, IMargins, IMathFractionOptions, IMathFunctionOptions, IMathIntegralOptions, IMathLimitLowerOptions, IMathLimitUpperOptions, IMathOptions, IMathPreSubSuperScriptOptions, IMathRadicalOptions, IMathSubScriptOptions, IMathSubSuperScriptOptions, IMathSumOptions, IMathSuperScriptOptions, IMediaData, IMediaDataTransformation, IMediaTransformation, INumberedItemReferenceOptions, INumberingOptions, IPageBorderAttributes, IPageBordersOptions, IPageMarginAttributes, IPageNumberTypeAttributes, IPageReferenceOptions, IPageSizeAttributes, IParagraphOptions, IParagraphPropertiesChangeOptions, IParagraphPropertiesOptions, IParagraphPropertiesOptionsBase, IParagraphRunOptions, IParagraphRunPropertiesOptions, IParagraphStyleOptions, IParagraphStylePropertiesOptions, IPatch, type IPropertiesOptions, IRunOptions, IRunPropertiesChangeOptions, IRunPropertiesOptions, IRunStylePropertiesOptions, ISectionOptions, ISectionPropertiesChangeOptions, ISectionPropertiesOptions, ISectionPropertiesOptionsBase, IShadingAttributesProperties, ISpacingProperties, IStylesOptions, ISymbolRunOptions, ITableBordersOptions, ITableCellBorders, ITableCellOptions, ITableFloatOptions, ITableLookOptions, ITableOfContentsOptions, ITableOptions, ITablePropertiesChangeOptions, ITablePropertiesOptions, ITablePropertiesOptionsBase, ITableRowOptions, ITableRowPropertiesChangeOptions, ITableRowPropertiesOptions, ITableRowPropertiesOptionsBase, ITableWidthProperties, ITextWrapping, IVerticalPositionOptions, IWpgGroupOptions, IWpsShapeOptions, IXYFrameOptions, IXmlAttribute, IXmlableObject, IgnoreIfEmptyXmlComponent, ImageRun, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, InputDataType, InsertedTableCell, InsertedTableRow, InsertedTextRun, InternalHyperlink, LastRenderedPageBreak, LeaderType, Level, LevelBase, LevelForOverride, LevelFormat, LevelOverride, LevelSuffix, LineNumberRestartFormat, LineRuleType, Math, MathAngledBrackets, MathComponent, MathCurlyBrackets, MathDegree, MathDenominator, MathFraction, MathFunction, MathFunctionName, MathFunctionProperties, MathIntegral, MathLimit, MathLimitLower, MathLimitUpper, MathNumerator, MathPreSubSuperScript, MathRadical, MathRadicalProperties, MathRoundBrackets, MathRun, MathSquareBrackets, MathSubScript, MathSubSuperScript, MathSum, MathSuperScript, Media, MonthLong, MonthShort, NextAttributeComponent, NoBreakHyphen, NumberFormat, NumberProperties, NumberValueElement, NumberedItemReference, NumberedItemReferenceFormat, Numbering, OnOffElement, OutputByType, OutputType, OverlapType, Packer, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder, PageBorders, PageBreak, PageBreakBefore, PageNumber, PageNumberElement, PageNumberSeparator, PageOrientation, PageReference, PageTextDirection, PageTextDirectionType, Paragraph, ParagraphChild, ParagraphProperties, ParagraphPropertiesChange, ParagraphPropertiesDefaults, ParagraphRunProperties, PatchDocumentOptions, PatchDocumentOutputType, PatchType, Percentage, PositionalTab, PositionalTabAlignment, PositionalTabLeader, PositionalTabOptions, PositionalTabRelativeTo, PositivePercentage, PositiveUniversalMeasure, PrettifyType, RelativeHorizontalPosition, RelativeMeasure, RelativeVerticalPosition, Run, RunProperties, RunPropertiesChange, RunPropertiesDefaults, SectionProperties, SectionPropertiesChange, SectionType, SectionVerticalAlign, Separator, SequentialIdentifier, ShadingType, SimpleField, SimpleMailMergeField, SoftHyphen, SpaceType, StringContainer, StringEnumValueElement, StringValueElement, StyleForCharacter, StyleForParagraph, StyleLevel, Styles, SymbolRun, TDirection, Tab, TabStopDefinition, TabStopPosition, TabStopType, Table, TableAnchorType, TableBorders, TableCell, TableCellBorders, TableLayoutType, TableOfContents, TableProperties, TableRow, TableRowProperties, TableRowPropertiesChange, TableVerticalAlign, TextDirection, TextEffect, TextRun, TextWrappingSide, TextWrappingType, Textbox, ThematicBreak, UnderlineType, UniqueNumericIdCreator, UniversalMeasure, VerticalAlign, VerticalAlignSection, VerticalAlignTable, VerticalAnchor, VerticalMerge, VerticalMergeRevisionType, VerticalMergeType, VerticalPositionAlign, VerticalPositionRelativeFrom, WORKAROUND2, WORKAROUND3, WORKAROUND4, WidthType, WpgCommonMediaData, WpgGroupRun, WpgMediaData, WpsMediaData, WpsShapeRun, XmlAttributeComponent, XmlComponent, YearLong, YearShort, abstractNumUniqueNumericIdGen, bookmarkUniqueNumericIdGen, concreteNumUniqueNumericIdGen, convertInchesToTwip, convertMillimetersToTwip, convertOutput, convertToXmlComponent, createAlignment, createBodyProperties, createBorderElement, createColumns, createDocumentGrid, createDotEmphasisMark, createEmphasisMark, createFrameProperties, createHeaderFooterReference, createHorizontalPosition, createIndent, createLineNumberType, createMathAccentCharacter, createMathBase, createMathLimitLocation, createMathNAryProperties, createMathPreSubSuperScriptProperties, createMathSubScriptElement, createMathSubScriptProperties, createMathSubSuperScriptProperties, createMathSuperScriptElement, createMathSuperScriptProperties, createOutlineLevel, createPageMargin, createPageNumberType, createPageSize, createParagraphStyle, createRunFonts, createSectionType, createShading, createSimplePos, createSpacing, createStringElement, createTabStop, createTabStopItem, createTableFloatProperties, createTableLayout, createTableLook, createTableRowHeight, createTableWidthElement, createTransformation, createUnderline, createVerticalAlign, createVerticalPosition, createWrapNone, createWrapSquare, createWrapTight, createWrapTopAndBottom, dateTimeValue, decimalNumber, docPropertiesUniqueNumericIdGen, eighthPointMeasureValue, encodeUtf8, hashedId, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, patchDetector, patchDocument, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, sectionMarginDefaults, sectionPageSizeDefaults, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, standardizeData, twipsMeasureValue, uCharHexNumber, uniqueId, uniqueNumericIdCreator, uniqueUuid, universalMeasureValue, unsignedDecimalNumber };
3232
+ export { AbstractNumbering, AlignmentType, AnnotationReference, AttributeData, AttributeMap, AttributePayload, Attributes, BaseXmlComponent, Body, Bookmark, BookmarkEnd, BookmarkStart, Border, BorderStyle, BuilderElement, CarriageReturn, CellMerge, CellMergeAttributes, CharacterSet, CheckBox, CheckBoxSymbolElement, CheckBoxUtil, Column, ColumnBreak, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments, ConcreteHyperlink, ConcreteNumbering, ContinuationSeparator, DayLong, DayShort, DeletedTableCell, DeletedTableRow, DeletedTextRun, File as Document, File, DocumentAttributeNamespace, DocumentAttributeNamespaces, DocumentAttributes, DocumentBackground, DocumentBackgroundAttributes, DocumentDefaults, DocumentGridType, Drawing, DropCapType, EMPTY_OBJECT, EmphasisMarkType, EmptyElement, EndnoteIdReference, EndnoteReference, EndnoteReferenceRun, EndnoteReferenceRunAttributes, Endnotes, ExternalHyperlink, FileChild, FootNoteReferenceRunAttributes, FootNotes, Footer, FooterWrapper, FootnoteReference, FootnoteReferenceElement, FootnoteReferenceRun, FrameAnchorType, FrameWrap, GridSpan, Header, HeaderFooterReferenceType, HeaderFooterType, HeaderWrapper, HeadingLevel, HeightRule, HighlightColor, HorizontalPositionAlign, HorizontalPositionRelativeFrom, HpsMeasureElement, HyperlinkType, IAlignmentFrameOptions, IBaseCharacterStyleOptions, IBaseParagraphStyleOptions, IBodyPropertiesOptions, IBookmarkOptions, IBorderOptions, IBordersOptions, ICellMergeAttributes, ICharacterStyleOptions, ICheckboxSymbolOptions, ICheckboxSymbolProperties, IColumnAttributes, IColumnsAttributes, ICommentOptions, ICommentsOptions, IConcreteNumberingOptions, IContext, IDistance, IDocGridAttributesProperties, IDocumentAttributesProperties, IDocumentBackgroundOptions, IDocumentDefaultsOptions, IDocumentFooter, IDocumentHeader, IDocumentOptions, IDrawingOptions, IExtendedMediaData, IExternalHyperlinkOptions, IFloating, IFontAttributesProperties, IFrameOptions, IGroupChildMediaData, IHeaderFooterGroup, IHeaderFooterOptions, IHeaderOptions, IHorizontalPositionOptions, IImageOptions, IIndentAttributesProperties, IInternalHyperlinkOptions, ILevelParagraphStylePropertiesOptions, ILevelsOptions, ILineNumberAttributes, IMargins, IMathFractionOptions, IMathFunctionOptions, IMathIntegralOptions, IMathLimitLowerOptions, IMathLimitUpperOptions, IMathOptions, IMathPreSubSuperScriptOptions, IMathRadicalOptions, IMathSubScriptOptions, IMathSubSuperScriptOptions, IMathSumOptions, IMathSuperScriptOptions, IMediaData, IMediaDataTransformation, IMediaTransformation, INumberedItemReferenceOptions, INumberingOptions, IPageBorderAttributes, IPageBordersOptions, IPageMarginAttributes, IPageNumberTypeAttributes, IPageReferenceOptions, IPageSizeAttributes, IParagraphOptions, IParagraphPropertiesChangeOptions, IParagraphPropertiesOptions, IParagraphPropertiesOptionsBase, IParagraphRunOptions, IParagraphRunPropertiesOptions, IParagraphStyleOptions, IParagraphStylePropertiesOptions, IPatch, type IPropertiesOptions, IRunOptions, IRunPropertiesChangeOptions, IRunPropertiesOptions, IRunStylePropertiesOptions, ISectionOptions, ISectionPropertiesChangeOptions, ISectionPropertiesOptions, ISectionPropertiesOptionsBase, IShadingAttributesProperties, ISpacingProperties, IStylesOptions, ISymbolRunOptions, ITableBordersOptions, ITableCellBorders, ITableCellOptions, ITableFloatOptions, ITableLookOptions, ITableOfContentsOptions, ITableOptions, ITablePropertiesChangeOptions, ITablePropertiesOptions, ITablePropertiesOptionsBase, ITableRowOptions, ITableRowPropertiesChangeOptions, ITableRowPropertiesOptions, ITableRowPropertiesOptionsBase, ITableWidthProperties, ITextWrapping, IVerticalPositionOptions, IWpgGroupOptions, IWpsShapeOptions, IXYFrameOptions, IXmlAttribute, IXmlableObject, IgnoreIfEmptyXmlComponent, ImageRun, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, InputDataType, InsertedTableCell, InsertedTableRow, InsertedTextRun, InternalHyperlink, LastRenderedPageBreak, LeaderType, Level, LevelBase, LevelForOverride, LevelFormat, LevelOverride, LevelSuffix, LineNumberRestartFormat, LineRuleType, Math, MathAngledBrackets, MathComponent, MathCurlyBrackets, MathDegree, MathDenominator, MathFraction, MathFunction, MathFunctionName, MathFunctionProperties, MathIntegral, MathLimit, MathLimitLower, MathLimitUpper, MathNumerator, MathPreSubSuperScript, MathRadical, MathRadicalProperties, MathRoundBrackets, MathRun, MathSquareBrackets, MathSubScript, MathSubSuperScript, MathSum, MathSuperScript, Media, MonthLong, MonthShort, NextAttributeComponent, NoBreakHyphen, NumberFormat, NumberProperties, NumberValueElement, NumberedItemReference, NumberedItemReferenceFormat, Numbering, OnOffElement, OutputByType, OutputType, OverlapType, Packer, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder, PageBorders, PageBreak, PageBreakBefore, PageNumber, PageNumberElement, PageNumberSeparator, PageOrientation, PageReference, PageTextDirection, PageTextDirectionType, Paragraph, ParagraphChild, ParagraphProperties, ParagraphPropertiesChange, ParagraphPropertiesDefaults, ParagraphRunProperties, PatchDocumentOptions, PatchDocumentOutputType, PatchType, Percentage, PositionalTab, PositionalTabAlignment, PositionalTabLeader, PositionalTabOptions, PositionalTabRelativeTo, PositivePercentage, PositiveUniversalMeasure, PrettifyType, RelativeHorizontalPosition, RelativeMeasure, RelativeVerticalPosition, Run, RunProperties, RunPropertiesChange, RunPropertiesDefaults, SectionProperties, SectionPropertiesChange, SectionType, SectionVerticalAlign, Separator, SequentialIdentifier, ShadingType, SimpleField, SimpleMailMergeField, SoftHyphen, SpaceType, StringContainer, StringEnumValueElement, StringValueElement, StyleForCharacter, StyleForParagraph, StyleLevel, Styles, SymbolRun, TDirection, Tab, TabStopDefinition, TabStopPosition, TabStopType, Table, TableAnchorType, TableBorders, TableCell, TableCellBorders, TableLayoutType, TableOfContents, TableProperties, TableRow, TableRowProperties, TableRowPropertiesChange, TableVerticalAlign, TextDirection, TextEffect, TextRun, TextWrappingSide, TextWrappingType, Textbox, ThematicBreak, UnderlineType, UniqueNumericIdCreator, UniversalMeasure, VerticalAlign, VerticalAlignSection, VerticalAlignTable, VerticalAnchor, VerticalMerge, VerticalMergeRevisionType, VerticalMergeType, VerticalPositionAlign, VerticalPositionRelativeFrom, WORKAROUND2, WORKAROUND3, WORKAROUND4, WidthType, WpgCommonMediaData, WpgGroupRun, WpgMediaData, WpsMediaData, WpsShapeRun, XmlAttributeComponent, XmlComponent, YearLong, YearShort, abstractNumUniqueNumericIdGen, bookmarkUniqueNumericIdGen, concreteNumUniqueNumericIdGen, convertInchesToTwip, convertMillimetersToTwip, convertOutput, convertToXmlComponent, createAlignment, createBodyProperties, createBorderElement, createColumns, createDocumentGrid, createDotEmphasisMark, createEmphasisMark, createFrameProperties, createHeaderFooterReference, createHorizontalPosition, createIndent, createLineNumberType, createMathAccentCharacter, createMathBase, createMathLimitLocation, createMathNAryProperties, createMathPreSubSuperScriptProperties, createMathSubScriptElement, createMathSubScriptProperties, createMathSubSuperScriptProperties, createMathSuperScriptElement, createMathSuperScriptProperties, createOutlineLevel, createPageMargin, createPageNumberType, createPageSize, createParagraphStyle, createRunFonts, createSectionType, createShading, createSimplePos, createSpacing, createStringElement, createTabStop, createTabStopItem, createTableFloatProperties, createTableLayout, createTableLook, createTableRowHeight, createTableWidthElement, createTransformation, createUnderline, createVerticalAlign, createVerticalPosition, createWrapNone, createWrapSquare, createWrapTight, createWrapTopAndBottom, dateTimeValue, decimalNumber, docPropertiesUniqueNumericIdGen, eighthPointMeasureValue, encodeUtf8, hashedId, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, patchDetector, patchDocument, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, sectionMarginDefaults, sectionPageSizeDefaults, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, twipsMeasureValue, uCharHexNumber, uniqueId, uniqueNumericIdCreator, uniqueUuid, universalMeasureValue, unsignedDecimalNumber };
@@ -1,4 +1,4 @@
1
- var docxPlus = (function(exports, xml_js, hash_js, nanoid_non_secure, fflate, undio, xml) {
1
+ var docxPlus = (function(exports, xml_js, hash_js, nanoid_non_secure, undio, stream, fflate, xml) {
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  //#region \0rolldown/runtime.js
4
4
  var __create = Object.create;
@@ -5771,29 +5771,20 @@ var docxPlus = (function(exports, xml_js, hash_js, nanoid_non_secure, fflate, un
5771
5771
  };
5772
5772
  //#endregion
5773
5773
  //#region src/file/paragraph/run/image-run.ts
5774
- const convertDataURIToBinary = (dataURI) => {
5775
- const base64Index = dataURI.indexOf(";base64,");
5776
- const base64IndexWithOffset = base64Index === -1 ? 0 : base64Index + 8;
5777
- const binaryString = atob(dataURI.substring(base64IndexWithOffset));
5778
- const bytes = new Uint8Array(binaryString.length);
5779
- for (let i = 0; i < binaryString.length; i++) bytes[i] = binaryString.charCodeAt(i);
5780
- return bytes;
5781
- };
5782
- const standardizeData = (data) => typeof data === "string" ? convertDataURIToBinary(data) : data;
5783
- const createImageData = (options, key) => ({
5784
- data: standardizeData(options.data),
5774
+ const createImageData = (data, transformation, key) => ({
5775
+ data,
5785
5776
  fileName: key,
5786
5777
  transformation: {
5787
5778
  emus: {
5788
- x: Math.round(options.transformation.width * 9525),
5789
- y: Math.round(options.transformation.height * 9525)
5779
+ x: Math.round(transformation.width * 9525),
5780
+ y: Math.round(transformation.height * 9525)
5790
5781
  },
5791
- flip: options.transformation.flip,
5782
+ flip: transformation.flip,
5792
5783
  pixels: {
5793
- x: Math.round(options.transformation.width),
5794
- y: Math.round(options.transformation.height)
5784
+ x: Math.round(transformation.width),
5785
+ y: Math.round(transformation.height)
5795
5786
  },
5796
- rotation: options.transformation.rotation ? options.transformation.rotation * 6e4 : void 0
5787
+ rotation: transformation.rotation ? transformation.rotation * 6e4 : void 0
5797
5788
  }
5798
5789
  });
5799
5790
  /**
@@ -5822,8 +5813,12 @@ var docxPlus = (function(exports, xml_js, hash_js, nanoid_non_secure, fflate, un
5822
5813
  constructor(options) {
5823
5814
  super({});
5824
5815
  _defineProperty(this, "imageData", void 0);
5825
- const key = `${hashedId(options.data)}.${options.type}`;
5826
- this.imageData = options.type === "svg" ? _objectSpread2(_objectSpread2({ type: options.type }, createImageData(options, key)), {}, { fallback: _objectSpread2({ type: options.fallback.type }, createImageData(_objectSpread2(_objectSpread2({}, options.fallback), {}, { transformation: options.transformation }), `${hashedId(options.fallback.data)}.${options.fallback.type}`)) }) : _objectSpread2({ type: options.type }, createImageData(options, key));
5816
+ const rawData = (0, undio.toUint8Array)(options.data);
5817
+ const key = `${hashedId(rawData)}.${options.type}`;
5818
+ if (options.type === "svg") {
5819
+ const fallbackData = (0, undio.toUint8Array)(options.fallback.data);
5820
+ this.imageData = _objectSpread2(_objectSpread2({ type: options.type }, createImageData(rawData, options.transformation, key)), {}, { fallback: _objectSpread2({ type: options.fallback.type }, createImageData(fallbackData, options.transformation, `${hashedId(fallbackData)}.${options.fallback.type}`)) });
5821
+ } else this.imageData = _objectSpread2({ type: options.type }, createImageData(rawData, options.transformation, key));
5827
5822
  const drawing = new Drawing(this.imageData, {
5828
5823
  docProperties: options.altText,
5829
5824
  floating: options.floating,
@@ -18286,6 +18281,14 @@ var docxPlus = (function(exports, xml_js, hash_js, nanoid_non_secure, fflate, un
18286
18281
  //#endregion
18287
18282
  //#region src/util/output-type.ts
18288
18283
  /**
18284
+ * Output type definitions for document generation.
18285
+ *
18286
+ * This module defines the various output formats supported when generating
18287
+ * .docx files. These types correspond to fflate's output formats.
18288
+ *
18289
+ * @module
18290
+ */
18291
+ /**
18289
18292
  * Converts a Uint8Array to the specified output type.
18290
18293
  *
18291
18294
  * This is used by both the Packer and patchDocument to convert fflate's
@@ -18297,10 +18300,10 @@ var docxPlus = (function(exports, xml_js, hash_js, nanoid_non_secure, fflate, un
18297
18300
  case "blob": return new Blob([data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
18298
18301
  case "arraybuffer": return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
18299
18302
  case "uint8array": return data;
18300
- case "base64": return Buffer.from(data).toString("base64");
18303
+ case "base64": return btoa((0, fflate.strFromU8)(data, true));
18301
18304
  case "string":
18302
- case "text": return Buffer.from(data).toString("binary");
18303
- case "binarystring": return Buffer.from(data).toString("binary");
18305
+ case "text":
18306
+ case "binarystring": return (0, fflate.strFromU8)(data, true);
18304
18307
  case "array": return [...data];
18305
18308
  default: return data;
18306
18309
  }
@@ -19014,6 +19017,50 @@ var docxPlus = (function(exports, xml_js, hash_js, nanoid_non_secure, fflate, un
19014
19017
  static toArrayBuffer(file, prettify, overrides = []) {
19015
19018
  return Packer.pack(file, "arraybuffer", prettify, overrides);
19016
19019
  }
19020
+ /**
19021
+ * Exports a document to a Node.js Readable stream.
19022
+ *
19023
+ * Uses fflate's streaming Zip API to emit compressed chunks incrementally,
19024
+ * avoiding buffering the entire archive in memory before the first byte
19025
+ * is available to the consumer.
19026
+ *
19027
+ * @param file - The document to export
19028
+ * @param prettify - Whether to prettify the XML output
19029
+ * @param overrides - Optional array of file overrides
19030
+ * @returns A readable stream containing the compressed .docx data
19031
+ *
19032
+ * @example
19033
+ * ```typescript
19034
+ * import { createWriteStream } from "fs";
19035
+ * Packer.toStream(doc).pipe(createWriteStream("output.docx"));
19036
+ * ```
19037
+ */
19038
+ static toStream(file, prettify, overrides = []) {
19039
+ const stream$1 = new stream.Readable({ read() {} });
19040
+ try {
19041
+ const files = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
19042
+ const zip = new fflate.Zip((err, chunk, final) => {
19043
+ if (err) {
19044
+ stream$1.destroy(err);
19045
+ return;
19046
+ }
19047
+ if (!stream$1.destroyed) stream$1.push(chunk);
19048
+ if (final) stream$1.push(null);
19049
+ });
19050
+ for (const [name, data] of Object.entries(files)) {
19051
+ var _level;
19052
+ const raw = Array.isArray(data) ? data[0] : data;
19053
+ const level = Array.isArray(data) ? (_level = data[1].level) !== null && _level !== void 0 ? _level : 6 : 6;
19054
+ const entry = level === 0 ? new fflate.ZipPassThrough(name) : new fflate.ZipDeflate(name, { level });
19055
+ zip.add(entry);
19056
+ entry.push(raw, true);
19057
+ }
19058
+ zip.end();
19059
+ } catch (err) {
19060
+ stream$1.destroy(err instanceof Error ? err : new Error(String(err)));
19061
+ }
19062
+ return stream$1;
19063
+ }
19017
19064
  };
19018
19065
  _defineProperty(Packer, "compiler", new Compiler());
19019
19066
  //#endregion
@@ -20129,7 +20176,6 @@ var docxPlus = (function(exports, xml_js, hash_js, nanoid_non_secure, fflate, un
20129
20176
  exports.shortHexNumber = shortHexNumber;
20130
20177
  exports.signedHpsMeasureValue = signedHpsMeasureValue;
20131
20178
  exports.signedTwipsMeasureValue = signedTwipsMeasureValue;
20132
- exports.standardizeData = standardizeData;
20133
20179
  exports.twipsMeasureValue = twipsMeasureValue;
20134
20180
  exports.uCharHexNumber = uCharHexNumber;
20135
20181
  exports.uniqueId = uniqueId;
@@ -20138,4 +20184,4 @@ var docxPlus = (function(exports, xml_js, hash_js, nanoid_non_secure, fflate, un
20138
20184
  exports.universalMeasureValue = universalMeasureValue;
20139
20185
  exports.unsignedDecimalNumber = unsignedDecimalNumber;
20140
20186
  return exports;
20141
- })({}, xml_js, hash_js, nanoid_non_secure, fflate, undio, xml);
20187
+ })({}, xml_js, hash_js, nanoid_non_secure, undio, stream, fflate, xml);
package/dist/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  import { js2xml, xml2js } from "xml-js";
2
2
  import hash from "hash.js";
3
3
  import { customAlphabet, nanoid } from "nanoid/non-secure";
4
- import { strFromU8, unzipSync, zipSync } from "fflate";
5
4
  import { textToUint8Array, toUint8Array } from "undio";
5
+ import { Readable } from "stream";
6
+ import { Zip, ZipDeflate, ZipPassThrough, strFromU8, unzipSync, zipSync } from "fflate";
6
7
  import xml from "xml";
7
8
  //#region \0@oxc-project+runtime@0.123.0/helpers/typeof.js
8
9
  function _typeof(o) {
@@ -5751,29 +5752,20 @@ var Drawing = class extends XmlComponent {
5751
5752
  };
5752
5753
  //#endregion
5753
5754
  //#region src/file/paragraph/run/image-run.ts
5754
- const convertDataURIToBinary = (dataURI) => {
5755
- const base64Index = dataURI.indexOf(";base64,");
5756
- const base64IndexWithOffset = base64Index === -1 ? 0 : base64Index + 8;
5757
- const binaryString = atob(dataURI.substring(base64IndexWithOffset));
5758
- const bytes = new Uint8Array(binaryString.length);
5759
- for (let i = 0; i < binaryString.length; i++) bytes[i] = binaryString.charCodeAt(i);
5760
- return bytes;
5761
- };
5762
- const standardizeData = (data) => typeof data === "string" ? convertDataURIToBinary(data) : data;
5763
- const createImageData = (options, key) => ({
5764
- data: standardizeData(options.data),
5755
+ const createImageData = (data, transformation, key) => ({
5756
+ data,
5765
5757
  fileName: key,
5766
5758
  transformation: {
5767
5759
  emus: {
5768
- x: Math.round(options.transformation.width * 9525),
5769
- y: Math.round(options.transformation.height * 9525)
5760
+ x: Math.round(transformation.width * 9525),
5761
+ y: Math.round(transformation.height * 9525)
5770
5762
  },
5771
- flip: options.transformation.flip,
5763
+ flip: transformation.flip,
5772
5764
  pixels: {
5773
- x: Math.round(options.transformation.width),
5774
- y: Math.round(options.transformation.height)
5765
+ x: Math.round(transformation.width),
5766
+ y: Math.round(transformation.height)
5775
5767
  },
5776
- rotation: options.transformation.rotation ? options.transformation.rotation * 6e4 : void 0
5768
+ rotation: transformation.rotation ? transformation.rotation * 6e4 : void 0
5777
5769
  }
5778
5770
  });
5779
5771
  /**
@@ -5802,8 +5794,12 @@ var ImageRun = class extends Run {
5802
5794
  constructor(options) {
5803
5795
  super({});
5804
5796
  _defineProperty(this, "imageData", void 0);
5805
- const key = `${hashedId(options.data)}.${options.type}`;
5806
- this.imageData = options.type === "svg" ? _objectSpread2(_objectSpread2({ type: options.type }, createImageData(options, key)), {}, { fallback: _objectSpread2({ type: options.fallback.type }, createImageData(_objectSpread2(_objectSpread2({}, options.fallback), {}, { transformation: options.transformation }), `${hashedId(options.fallback.data)}.${options.fallback.type}`)) }) : _objectSpread2({ type: options.type }, createImageData(options, key));
5797
+ const rawData = toUint8Array(options.data);
5798
+ const key = `${hashedId(rawData)}.${options.type}`;
5799
+ if (options.type === "svg") {
5800
+ const fallbackData = toUint8Array(options.fallback.data);
5801
+ this.imageData = _objectSpread2(_objectSpread2({ type: options.type }, createImageData(rawData, options.transformation, key)), {}, { fallback: _objectSpread2({ type: options.fallback.type }, createImageData(fallbackData, options.transformation, `${hashedId(fallbackData)}.${options.fallback.type}`)) });
5802
+ } else this.imageData = _objectSpread2({ type: options.type }, createImageData(rawData, options.transformation, key));
5807
5803
  const drawing = new Drawing(this.imageData, {
5808
5804
  docProperties: options.altText,
5809
5805
  floating: options.floating,
@@ -18266,6 +18262,14 @@ var Textbox = class extends FileChild {
18266
18262
  //#endregion
18267
18263
  //#region src/util/output-type.ts
18268
18264
  /**
18265
+ * Output type definitions for document generation.
18266
+ *
18267
+ * This module defines the various output formats supported when generating
18268
+ * .docx files. These types correspond to fflate's output formats.
18269
+ *
18270
+ * @module
18271
+ */
18272
+ /**
18269
18273
  * Converts a Uint8Array to the specified output type.
18270
18274
  *
18271
18275
  * This is used by both the Packer and patchDocument to convert fflate's
@@ -18277,10 +18281,10 @@ const convertOutput = (data, type) => {
18277
18281
  case "blob": return new Blob([data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
18278
18282
  case "arraybuffer": return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
18279
18283
  case "uint8array": return data;
18280
- case "base64": return Buffer.from(data).toString("base64");
18284
+ case "base64": return btoa(strFromU8(data, true));
18281
18285
  case "string":
18282
- case "text": return Buffer.from(data).toString("binary");
18283
- case "binarystring": return Buffer.from(data).toString("binary");
18286
+ case "text":
18287
+ case "binarystring": return strFromU8(data, true);
18284
18288
  case "array": return [...data];
18285
18289
  default: return data;
18286
18290
  }
@@ -18994,6 +18998,50 @@ var Packer = class Packer {
18994
18998
  static toArrayBuffer(file, prettify, overrides = []) {
18995
18999
  return Packer.pack(file, "arraybuffer", prettify, overrides);
18996
19000
  }
19001
+ /**
19002
+ * Exports a document to a Node.js Readable stream.
19003
+ *
19004
+ * Uses fflate's streaming Zip API to emit compressed chunks incrementally,
19005
+ * avoiding buffering the entire archive in memory before the first byte
19006
+ * is available to the consumer.
19007
+ *
19008
+ * @param file - The document to export
19009
+ * @param prettify - Whether to prettify the XML output
19010
+ * @param overrides - Optional array of file overrides
19011
+ * @returns A readable stream containing the compressed .docx data
19012
+ *
19013
+ * @example
19014
+ * ```typescript
19015
+ * import { createWriteStream } from "fs";
19016
+ * Packer.toStream(doc).pipe(createWriteStream("output.docx"));
19017
+ * ```
19018
+ */
19019
+ static toStream(file, prettify, overrides = []) {
19020
+ const stream = new Readable({ read() {} });
19021
+ try {
19022
+ const files = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
19023
+ const zip = new Zip((err, chunk, final) => {
19024
+ if (err) {
19025
+ stream.destroy(err);
19026
+ return;
19027
+ }
19028
+ if (!stream.destroyed) stream.push(chunk);
19029
+ if (final) stream.push(null);
19030
+ });
19031
+ for (const [name, data] of Object.entries(files)) {
19032
+ var _level;
19033
+ const raw = Array.isArray(data) ? data[0] : data;
19034
+ const level = Array.isArray(data) ? (_level = data[1].level) !== null && _level !== void 0 ? _level : 6 : 6;
19035
+ const entry = level === 0 ? new ZipPassThrough(name) : new ZipDeflate(name, { level });
19036
+ zip.add(entry);
19037
+ entry.push(raw, true);
19038
+ }
19039
+ zip.end();
19040
+ } catch (err) {
19041
+ stream.destroy(err instanceof Error ? err : new Error(String(err)));
19042
+ }
19043
+ return stream;
19044
+ }
18997
19045
  };
18998
19046
  _defineProperty(Packer, "compiler", new Compiler());
18999
19047
  //#endregion
@@ -19813,4 +19861,4 @@ const findPatchKeys = (text) => {
19813
19861
  return (_text$match = text.match(pattern)) !== null && _text$match !== void 0 ? _text$match : [];
19814
19862
  };
19815
19863
  //#endregion
19816
- export { AbstractNumbering, AlignmentType, AnnotationReference, Attributes, BaseXmlComponent, Body, Bookmark, BookmarkEnd, BookmarkStart, Border, BorderStyle, BuilderElement, CarriageReturn, CellMerge, CellMergeAttributes, CharacterSet, CheckBox, CheckBoxSymbolElement, CheckBoxUtil, Column, ColumnBreak, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments, ConcreteHyperlink, ConcreteNumbering, ContinuationSeparator, DayLong, DayShort, DeletedTableCell, DeletedTableRow, DeletedTextRun, File as Document, File, DocumentAttributeNamespaces, DocumentAttributes, DocumentBackground, DocumentBackgroundAttributes, DocumentDefaults, DocumentGridType, Drawing, DropCapType, EMPTY_OBJECT, EmphasisMarkType, EmptyElement, EndnoteIdReference, EndnoteReference, EndnoteReferenceRun, EndnoteReferenceRunAttributes, Endnotes, ExternalHyperlink, FileChild, FootNoteReferenceRunAttributes, FootNotes, Footer, FooterWrapper, FootnoteReference, FootnoteReferenceElement, FootnoteReferenceRun, FrameAnchorType, FrameWrap, GridSpan, Header, HeaderFooterReferenceType, HeaderFooterType, HeaderWrapper, HeadingLevel, HeightRule, HighlightColor, HorizontalPositionAlign, HorizontalPositionRelativeFrom, HpsMeasureElement, HyperlinkType, IgnoreIfEmptyXmlComponent, ImageRun, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, InsertedTableCell, InsertedTableRow, InsertedTextRun, InternalHyperlink, LastRenderedPageBreak, LeaderType, Level, LevelBase, LevelForOverride, LevelFormat, LevelOverride, LevelSuffix, LineNumberRestartFormat, LineRuleType, Math$1 as Math, MathAngledBrackets, MathCurlyBrackets, MathDegree, MathDenominator, MathFraction, MathFunction, MathFunctionName, MathFunctionProperties, MathIntegral, MathLimit, MathLimitLower, MathLimitUpper, MathNumerator, MathPreSubSuperScript, MathRadical, MathRadicalProperties, MathRoundBrackets, MathRun, MathSquareBrackets, MathSubScript, MathSubSuperScript, MathSum, MathSuperScript, Media, MonthLong, MonthShort, NextAttributeComponent, NoBreakHyphen, NumberFormat, NumberProperties, NumberValueElement, NumberedItemReference, NumberedItemReferenceFormat, Numbering, OnOffElement, OverlapType, Packer, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder, PageBorders, PageBreak, PageBreakBefore, PageNumber, PageNumberElement, PageNumberSeparator, PageOrientation, PageReference, PageTextDirection, PageTextDirectionType, Paragraph, ParagraphProperties, ParagraphPropertiesChange, ParagraphPropertiesDefaults, ParagraphRunProperties, PatchType, PositionalTab, PositionalTabAlignment, PositionalTabLeader, PositionalTabRelativeTo, PrettifyType, RelativeHorizontalPosition, RelativeVerticalPosition, Run, RunProperties, RunPropertiesChange, RunPropertiesDefaults, SectionProperties, SectionPropertiesChange, SectionType, Separator, SequentialIdentifier, ShadingType, SimpleField, SimpleMailMergeField, SoftHyphen, SpaceType, StringContainer, StringEnumValueElement, StringValueElement, StyleForCharacter, StyleForParagraph, StyleLevel, Styles, SymbolRun, TDirection, Tab, TabStopPosition, TabStopType, Table, TableAnchorType, TableBorders, TableCell, TableCellBorders, TableLayoutType, TableOfContents, TableProperties, TableRow, TableRowProperties, TableRowPropertiesChange, TextDirection, TextEffect, TextRun, TextWrappingSide, TextWrappingType, Textbox, ThematicBreak, UnderlineType, VerticalAlign, VerticalAlignSection, VerticalAlignTable, VerticalAnchor, VerticalMerge, VerticalMergeRevisionType, VerticalMergeType, VerticalPositionAlign, VerticalPositionRelativeFrom, WORKAROUND2, WORKAROUND3, WORKAROUND4, WidthType, WpgGroupRun, WpsShapeRun, XmlAttributeComponent, XmlComponent, YearLong, YearShort, abstractNumUniqueNumericIdGen, bookmarkUniqueNumericIdGen, concreteNumUniqueNumericIdGen, convertInchesToTwip, convertMillimetersToTwip, convertToXmlComponent, createAlignment, createBodyProperties, createBorderElement, createColumns, createDocumentGrid, createDotEmphasisMark, createEmphasisMark, createFrameProperties, createHeaderFooterReference, createHorizontalPosition, createIndent, createLineNumberType, createMathAccentCharacter, createMathBase, createMathLimitLocation, createMathNAryProperties, createMathPreSubSuperScriptProperties, createMathSubScriptElement, createMathSubScriptProperties, createMathSubSuperScriptProperties, createMathSuperScriptElement, createMathSuperScriptProperties, createOutlineLevel, createPageMargin, createPageNumberType, createPageSize, createParagraphStyle, createRunFonts, createSectionType, createShading, createSimplePos, createSpacing, createStringElement, createTabStop, createTabStopItem, createTableFloatProperties, createTableLayout, createTableLook, createTableRowHeight, createTableWidthElement, createTransformation, createUnderline, createVerticalAlign, createVerticalPosition, createWrapNone, createWrapSquare, createWrapTight, createWrapTopAndBottom, dateTimeValue, decimalNumber, docPropertiesUniqueNumericIdGen, eighthPointMeasureValue, encodeUtf8, hashedId, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, patchDetector, patchDocument, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, sectionMarginDefaults, sectionPageSizeDefaults, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, standardizeData, twipsMeasureValue, uCharHexNumber, uniqueId, uniqueNumericIdCreator, uniqueUuid, universalMeasureValue, unsignedDecimalNumber };
19864
+ export { AbstractNumbering, AlignmentType, AnnotationReference, Attributes, BaseXmlComponent, Body, Bookmark, BookmarkEnd, BookmarkStart, Border, BorderStyle, BuilderElement, CarriageReturn, CellMerge, CellMergeAttributes, CharacterSet, CheckBox, CheckBoxSymbolElement, CheckBoxUtil, Column, ColumnBreak, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments, ConcreteHyperlink, ConcreteNumbering, ContinuationSeparator, DayLong, DayShort, DeletedTableCell, DeletedTableRow, DeletedTextRun, File as Document, File, DocumentAttributeNamespaces, DocumentAttributes, DocumentBackground, DocumentBackgroundAttributes, DocumentDefaults, DocumentGridType, Drawing, DropCapType, EMPTY_OBJECT, EmphasisMarkType, EmptyElement, EndnoteIdReference, EndnoteReference, EndnoteReferenceRun, EndnoteReferenceRunAttributes, Endnotes, ExternalHyperlink, FileChild, FootNoteReferenceRunAttributes, FootNotes, Footer, FooterWrapper, FootnoteReference, FootnoteReferenceElement, FootnoteReferenceRun, FrameAnchorType, FrameWrap, GridSpan, Header, HeaderFooterReferenceType, HeaderFooterType, HeaderWrapper, HeadingLevel, HeightRule, HighlightColor, HorizontalPositionAlign, HorizontalPositionRelativeFrom, HpsMeasureElement, HyperlinkType, IgnoreIfEmptyXmlComponent, ImageRun, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, InsertedTableCell, InsertedTableRow, InsertedTextRun, InternalHyperlink, LastRenderedPageBreak, LeaderType, Level, LevelBase, LevelForOverride, LevelFormat, LevelOverride, LevelSuffix, LineNumberRestartFormat, LineRuleType, Math$1 as Math, MathAngledBrackets, MathCurlyBrackets, MathDegree, MathDenominator, MathFraction, MathFunction, MathFunctionName, MathFunctionProperties, MathIntegral, MathLimit, MathLimitLower, MathLimitUpper, MathNumerator, MathPreSubSuperScript, MathRadical, MathRadicalProperties, MathRoundBrackets, MathRun, MathSquareBrackets, MathSubScript, MathSubSuperScript, MathSum, MathSuperScript, Media, MonthLong, MonthShort, NextAttributeComponent, NoBreakHyphen, NumberFormat, NumberProperties, NumberValueElement, NumberedItemReference, NumberedItemReferenceFormat, Numbering, OnOffElement, OverlapType, Packer, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder, PageBorders, PageBreak, PageBreakBefore, PageNumber, PageNumberElement, PageNumberSeparator, PageOrientation, PageReference, PageTextDirection, PageTextDirectionType, Paragraph, ParagraphProperties, ParagraphPropertiesChange, ParagraphPropertiesDefaults, ParagraphRunProperties, PatchType, PositionalTab, PositionalTabAlignment, PositionalTabLeader, PositionalTabRelativeTo, PrettifyType, RelativeHorizontalPosition, RelativeVerticalPosition, Run, RunProperties, RunPropertiesChange, RunPropertiesDefaults, SectionProperties, SectionPropertiesChange, SectionType, Separator, SequentialIdentifier, ShadingType, SimpleField, SimpleMailMergeField, SoftHyphen, SpaceType, StringContainer, StringEnumValueElement, StringValueElement, StyleForCharacter, StyleForParagraph, StyleLevel, Styles, SymbolRun, TDirection, Tab, TabStopPosition, TabStopType, Table, TableAnchorType, TableBorders, TableCell, TableCellBorders, TableLayoutType, TableOfContents, TableProperties, TableRow, TableRowProperties, TableRowPropertiesChange, TextDirection, TextEffect, TextRun, TextWrappingSide, TextWrappingType, Textbox, ThematicBreak, UnderlineType, VerticalAlign, VerticalAlignSection, VerticalAlignTable, VerticalAnchor, VerticalMerge, VerticalMergeRevisionType, VerticalMergeType, VerticalPositionAlign, VerticalPositionRelativeFrom, WORKAROUND2, WORKAROUND3, WORKAROUND4, WidthType, WpgGroupRun, WpsShapeRun, XmlAttributeComponent, XmlComponent, YearLong, YearShort, abstractNumUniqueNumericIdGen, bookmarkUniqueNumericIdGen, concreteNumUniqueNumericIdGen, convertInchesToTwip, convertMillimetersToTwip, convertToXmlComponent, createAlignment, createBodyProperties, createBorderElement, createColumns, createDocumentGrid, createDotEmphasisMark, createEmphasisMark, createFrameProperties, createHeaderFooterReference, createHorizontalPosition, createIndent, createLineNumberType, createMathAccentCharacter, createMathBase, createMathLimitLocation, createMathNAryProperties, createMathPreSubSuperScriptProperties, createMathSubScriptElement, createMathSubScriptProperties, createMathSubSuperScriptProperties, createMathSuperScriptElement, createMathSuperScriptProperties, createOutlineLevel, createPageMargin, createPageNumberType, createPageSize, createParagraphStyle, createRunFonts, createSectionType, createShading, createSimplePos, createSpacing, createStringElement, createTabStop, createTabStopItem, createTableFloatProperties, createTableLayout, createTableLook, createTableRowHeight, createTableWidthElement, createTransformation, createUnderline, createVerticalAlign, createVerticalPosition, createWrapNone, createWrapSquare, createWrapTight, createWrapTopAndBottom, dateTimeValue, decimalNumber, docPropertiesUniqueNumericIdGen, eighthPointMeasureValue, encodeUtf8, hashedId, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, patchDetector, patchDocument, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, sectionMarginDefaults, sectionPageSizeDefaults, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, twipsMeasureValue, uCharHexNumber, uniqueId, uniqueNumericIdCreator, uniqueUuid, universalMeasureValue, unsignedDecimalNumber };
package/dist/index.umd.js CHANGED
@@ -1,14 +1,15 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("xml-js"), require("hash.js"), require("nanoid/non-secure"), require("fflate"), require("undio"), require("xml")) : typeof define === "function" && define.amd ? define([
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("xml-js"), require("hash.js"), require("nanoid/non-secure"), require("undio"), require("stream"), require("fflate"), require("xml")) : typeof define === "function" && define.amd ? define([
3
3
  "exports",
4
4
  "xml-js",
5
5
  "hash.js",
6
6
  "nanoid/non-secure",
7
- "fflate",
8
7
  "undio",
8
+ "stream",
9
+ "fflate",
9
10
  "xml"
10
- ], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.docxPlus = {}, global.xml_js, global.hash_js, global.nanoid_non_secure, global.fflate, global.undio, global.xml));
11
- })(this, function(exports, xml_js, hash_js, nanoid_non_secure, fflate, undio, xml) {
11
+ ], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.docxPlus = {}, global.xml_js, global.hash_js, global.nanoid_non_secure, global.undio, global.stream, global.fflate, global.xml));
12
+ })(this, function(exports, xml_js, hash_js, nanoid_non_secure, undio, stream, fflate, xml) {
12
13
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
13
14
  //#region \0rolldown/runtime.js
14
15
  var __create = Object.create;
@@ -5781,29 +5782,20 @@
5781
5782
  };
5782
5783
  //#endregion
5783
5784
  //#region src/file/paragraph/run/image-run.ts
5784
- const convertDataURIToBinary = (dataURI) => {
5785
- const base64Index = dataURI.indexOf(";base64,");
5786
- const base64IndexWithOffset = base64Index === -1 ? 0 : base64Index + 8;
5787
- const binaryString = atob(dataURI.substring(base64IndexWithOffset));
5788
- const bytes = new Uint8Array(binaryString.length);
5789
- for (let i = 0; i < binaryString.length; i++) bytes[i] = binaryString.charCodeAt(i);
5790
- return bytes;
5791
- };
5792
- const standardizeData = (data) => typeof data === "string" ? convertDataURIToBinary(data) : data;
5793
- const createImageData = (options, key) => ({
5794
- data: standardizeData(options.data),
5785
+ const createImageData = (data, transformation, key) => ({
5786
+ data,
5795
5787
  fileName: key,
5796
5788
  transformation: {
5797
5789
  emus: {
5798
- x: Math.round(options.transformation.width * 9525),
5799
- y: Math.round(options.transformation.height * 9525)
5790
+ x: Math.round(transformation.width * 9525),
5791
+ y: Math.round(transformation.height * 9525)
5800
5792
  },
5801
- flip: options.transformation.flip,
5793
+ flip: transformation.flip,
5802
5794
  pixels: {
5803
- x: Math.round(options.transformation.width),
5804
- y: Math.round(options.transformation.height)
5795
+ x: Math.round(transformation.width),
5796
+ y: Math.round(transformation.height)
5805
5797
  },
5806
- rotation: options.transformation.rotation ? options.transformation.rotation * 6e4 : void 0
5798
+ rotation: transformation.rotation ? transformation.rotation * 6e4 : void 0
5807
5799
  }
5808
5800
  });
5809
5801
  /**
@@ -5832,8 +5824,12 @@
5832
5824
  constructor(options) {
5833
5825
  super({});
5834
5826
  _defineProperty(this, "imageData", void 0);
5835
- const key = `${hashedId(options.data)}.${options.type}`;
5836
- this.imageData = options.type === "svg" ? _objectSpread2(_objectSpread2({ type: options.type }, createImageData(options, key)), {}, { fallback: _objectSpread2({ type: options.fallback.type }, createImageData(_objectSpread2(_objectSpread2({}, options.fallback), {}, { transformation: options.transformation }), `${hashedId(options.fallback.data)}.${options.fallback.type}`)) }) : _objectSpread2({ type: options.type }, createImageData(options, key));
5827
+ const rawData = (0, undio.toUint8Array)(options.data);
5828
+ const key = `${hashedId(rawData)}.${options.type}`;
5829
+ if (options.type === "svg") {
5830
+ const fallbackData = (0, undio.toUint8Array)(options.fallback.data);
5831
+ this.imageData = _objectSpread2(_objectSpread2({ type: options.type }, createImageData(rawData, options.transformation, key)), {}, { fallback: _objectSpread2({ type: options.fallback.type }, createImageData(fallbackData, options.transformation, `${hashedId(fallbackData)}.${options.fallback.type}`)) });
5832
+ } else this.imageData = _objectSpread2({ type: options.type }, createImageData(rawData, options.transformation, key));
5837
5833
  const drawing = new Drawing(this.imageData, {
5838
5834
  docProperties: options.altText,
5839
5835
  floating: options.floating,
@@ -18296,6 +18292,14 @@
18296
18292
  //#endregion
18297
18293
  //#region src/util/output-type.ts
18298
18294
  /**
18295
+ * Output type definitions for document generation.
18296
+ *
18297
+ * This module defines the various output formats supported when generating
18298
+ * .docx files. These types correspond to fflate's output formats.
18299
+ *
18300
+ * @module
18301
+ */
18302
+ /**
18299
18303
  * Converts a Uint8Array to the specified output type.
18300
18304
  *
18301
18305
  * This is used by both the Packer and patchDocument to convert fflate's
@@ -18307,10 +18311,10 @@
18307
18311
  case "blob": return new Blob([data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
18308
18312
  case "arraybuffer": return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
18309
18313
  case "uint8array": return data;
18310
- case "base64": return Buffer.from(data).toString("base64");
18314
+ case "base64": return btoa((0, fflate.strFromU8)(data, true));
18311
18315
  case "string":
18312
- case "text": return Buffer.from(data).toString("binary");
18313
- case "binarystring": return Buffer.from(data).toString("binary");
18316
+ case "text":
18317
+ case "binarystring": return (0, fflate.strFromU8)(data, true);
18314
18318
  case "array": return [...data];
18315
18319
  default: return data;
18316
18320
  }
@@ -19024,6 +19028,50 @@
19024
19028
  static toArrayBuffer(file, prettify, overrides = []) {
19025
19029
  return Packer.pack(file, "arraybuffer", prettify, overrides);
19026
19030
  }
19031
+ /**
19032
+ * Exports a document to a Node.js Readable stream.
19033
+ *
19034
+ * Uses fflate's streaming Zip API to emit compressed chunks incrementally,
19035
+ * avoiding buffering the entire archive in memory before the first byte
19036
+ * is available to the consumer.
19037
+ *
19038
+ * @param file - The document to export
19039
+ * @param prettify - Whether to prettify the XML output
19040
+ * @param overrides - Optional array of file overrides
19041
+ * @returns A readable stream containing the compressed .docx data
19042
+ *
19043
+ * @example
19044
+ * ```typescript
19045
+ * import { createWriteStream } from "fs";
19046
+ * Packer.toStream(doc).pipe(createWriteStream("output.docx"));
19047
+ * ```
19048
+ */
19049
+ static toStream(file, prettify, overrides = []) {
19050
+ const stream$1 = new stream.Readable({ read() {} });
19051
+ try {
19052
+ const files = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
19053
+ const zip = new fflate.Zip((err, chunk, final) => {
19054
+ if (err) {
19055
+ stream$1.destroy(err);
19056
+ return;
19057
+ }
19058
+ if (!stream$1.destroyed) stream$1.push(chunk);
19059
+ if (final) stream$1.push(null);
19060
+ });
19061
+ for (const [name, data] of Object.entries(files)) {
19062
+ var _level;
19063
+ const raw = Array.isArray(data) ? data[0] : data;
19064
+ const level = Array.isArray(data) ? (_level = data[1].level) !== null && _level !== void 0 ? _level : 6 : 6;
19065
+ const entry = level === 0 ? new fflate.ZipPassThrough(name) : new fflate.ZipDeflate(name, { level });
19066
+ zip.add(entry);
19067
+ entry.push(raw, true);
19068
+ }
19069
+ zip.end();
19070
+ } catch (err) {
19071
+ stream$1.destroy(err instanceof Error ? err : new Error(String(err)));
19072
+ }
19073
+ return stream$1;
19074
+ }
19027
19075
  };
19028
19076
  _defineProperty(Packer, "compiler", new Compiler());
19029
19077
  //#endregion
@@ -20139,7 +20187,6 @@
20139
20187
  exports.shortHexNumber = shortHexNumber;
20140
20188
  exports.signedHpsMeasureValue = signedHpsMeasureValue;
20141
20189
  exports.signedTwipsMeasureValue = signedTwipsMeasureValue;
20142
- exports.standardizeData = standardizeData;
20143
20190
  exports.twipsMeasureValue = twipsMeasureValue;
20144
20191
  exports.uCharHexNumber = uCharHexNumber;
20145
20192
  exports.uniqueId = uniqueId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docx-plus",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
5
5
  "keywords": [
6
6
  "clippy",