docx 9.0.3 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.cjs CHANGED
@@ -18,6 +18,18 @@ var __spreadValues = (a, b) => {
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
21
33
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
34
  var __async = (__this, __arguments, generator) => {
23
35
  return new Promise((resolve2, reject) => {
@@ -16342,7 +16354,7 @@ class SettingsAttributes extends XmlAttributeComponent {
16342
16354
  }
16343
16355
  class Settings extends XmlComponent {
16344
16356
  constructor(options2) {
16345
- var _a, _b, _c, _d;
16357
+ var _a, _b, _c, _d, _e, _f, _g, _h;
16346
16358
  super("w:settings");
16347
16359
  this.root.push(
16348
16360
  new SettingsAttributes({
@@ -16378,9 +16390,21 @@ class Settings extends XmlComponent {
16378
16390
  if (options2.defaultTabStop !== void 0) {
16379
16391
  this.root.push(new NumberValueElement("w:defaultTabStop", options2.defaultTabStop));
16380
16392
  }
16393
+ if (((_a = options2.hyphenation) == null ? void 0 : _a.autoHyphenation) !== void 0) {
16394
+ this.root.push(new OnOffElement("w:autoHyphenation", options2.hyphenation.autoHyphenation));
16395
+ }
16396
+ if (((_b = options2.hyphenation) == null ? void 0 : _b.hyphenationZone) !== void 0) {
16397
+ this.root.push(new NumberValueElement("w:hyphenationZone", options2.hyphenation.hyphenationZone));
16398
+ }
16399
+ if (((_c = options2.hyphenation) == null ? void 0 : _c.consecutiveHyphenLimit) !== void 0) {
16400
+ this.root.push(new NumberValueElement("w:consecutiveHyphenLimit", options2.hyphenation.consecutiveHyphenLimit));
16401
+ }
16402
+ if (((_d = options2.hyphenation) == null ? void 0 : _d.doNotHyphenateCaps) !== void 0) {
16403
+ this.root.push(new OnOffElement("w:doNotHyphenateCaps", options2.hyphenation.doNotHyphenateCaps));
16404
+ }
16381
16405
  this.root.push(
16382
- new Compatibility(__spreadProps(__spreadValues({}, (_a = options2.compatibility) != null ? _a : {}), {
16383
- version: (_d = (_c = (_b = options2.compatibility) == null ? void 0 : _b.version) != null ? _c : options2.compatibilityModeVersion) != null ? _d : 15
16406
+ new Compatibility(__spreadProps(__spreadValues({}, (_e = options2.compatibility) != null ? _e : {}), {
16407
+ version: (_h = (_g = (_f = options2.compatibility) == null ? void 0 : _f.version) != null ? _g : options2.compatibilityModeVersion) != null ? _h : 15
16384
16408
  }))
16385
16409
  );
16386
16410
  }
@@ -16795,7 +16819,7 @@ class File {
16795
16819
  __publicField(this, "styles");
16796
16820
  __publicField(this, "comments");
16797
16821
  __publicField(this, "fontWrapper");
16798
- var _a, _b, _c, _d, _e, _f, _g, _h;
16822
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
16799
16823
  this.coreProperties = new CoreProperties(__spreadProps(__spreadValues({}, options2), {
16800
16824
  creator: (_a = options2.creator) != null ? _a : "Un-named",
16801
16825
  revision: (_b = options2.revision) != null ? _b : 1,
@@ -16815,7 +16839,13 @@ class File {
16815
16839
  evenAndOddHeaders: options2.evenAndOddHeaderAndFooters ? true : false,
16816
16840
  trackRevisions: (_f = options2.features) == null ? void 0 : _f.trackRevisions,
16817
16841
  updateFields: (_g = options2.features) == null ? void 0 : _g.updateFields,
16818
- defaultTabStop: options2.defaultTabStop
16842
+ defaultTabStop: options2.defaultTabStop,
16843
+ hyphenation: {
16844
+ autoHyphenation: (_h = options2.hyphenation) == null ? void 0 : _h.autoHyphenation,
16845
+ hyphenationZone: (_i = options2.hyphenation) == null ? void 0 : _i.hyphenationZone,
16846
+ consecutiveHyphenLimit: (_j = options2.hyphenation) == null ? void 0 : _j.consecutiveHyphenLimit,
16847
+ doNotHyphenateCaps: (_k = options2.hyphenation) == null ? void 0 : _k.doNotHyphenateCaps
16848
+ }
16819
16849
  });
16820
16850
  this.media = new Media();
16821
16851
  if (options2.externalStyles !== void 0) {
@@ -16838,7 +16868,7 @@ class File {
16838
16868
  this.footnotesWrapper.View.createFootNote(parseFloat(key), options2.footnotes[key].children);
16839
16869
  }
16840
16870
  }
16841
- this.fontWrapper = new FontWrapper((_h = options2.fonts) != null ? _h : []);
16871
+ this.fontWrapper = new FontWrapper((_l = options2.fonts) != null ? _l : []);
16842
16872
  }
16843
16873
  addSection({ headers = {}, footers = {}, children, properties }) {
16844
16874
  this.documentWrapper.View.Body.addSection(__spreadProps(__spreadValues({}, properties), {
@@ -17300,6 +17330,98 @@ class CheckBox extends XmlComponent {
17300
17330
  this.root.push(content);
17301
17331
  }
17302
17332
  }
17333
+ const createPictElement = ({ shape }) => new BuilderElement({
17334
+ name: "w:pict",
17335
+ children: [shape]
17336
+ });
17337
+ const createTextboxContent = ({ children = [] }) => new BuilderElement({
17338
+ name: "w:txbxContent",
17339
+ children
17340
+ });
17341
+ const createVmlTextbox = ({ style, children, inset }) => new BuilderElement({
17342
+ name: "v:textbox",
17343
+ attributes: {
17344
+ style: {
17345
+ key: "style",
17346
+ value: style
17347
+ },
17348
+ insetMode: {
17349
+ key: "insetmode",
17350
+ value: inset ? "custom" : "auto"
17351
+ },
17352
+ inset: {
17353
+ key: "inset",
17354
+ value: inset ? `${inset.left}, ${inset.top}, ${inset.right}, ${inset.bottom}` : void 0
17355
+ }
17356
+ },
17357
+ children: [createTextboxContent({ children })]
17358
+ });
17359
+ const SHAPE_TYPE = "#_x0000_t202";
17360
+ const styleToKeyMap = {
17361
+ flip: "flip",
17362
+ height: "height",
17363
+ left: "left",
17364
+ marginBottom: "margin-bottom",
17365
+ marginLeft: "margin-left",
17366
+ marginRight: "margin-right",
17367
+ marginTop: "margin-top",
17368
+ positionHorizontal: "mso-position-horizontal",
17369
+ positionHorizontalRelative: "mso-position-horizontal-relative",
17370
+ positionVertical: "mso-position-vertical",
17371
+ positionVerticalRelative: "mso-position-vertical-relative",
17372
+ wrapDistanceBottom: "mso-wrap-distance-bottom",
17373
+ wrapDistanceLeft: "mso-wrap-distance-left",
17374
+ wrapDistanceRight: "mso-wrap-distance-right",
17375
+ wrapDistanceTop: "mso-wrap-distance-top",
17376
+ wrapEdited: "mso-wrap-edited",
17377
+ wrapStyle: "mso-wrap-style",
17378
+ position: "position",
17379
+ rotation: "rotation",
17380
+ top: "top",
17381
+ visibility: "visibility",
17382
+ width: "width",
17383
+ zIndex: "z-index"
17384
+ };
17385
+ const formatShapeStyle = (style) => style ? Object.entries(style).map(([key, value]) => `${styleToKeyMap[key]}:${value}`).join(";") : void 0;
17386
+ const createShape = ({
17387
+ id,
17388
+ children,
17389
+ type: type2 = SHAPE_TYPE,
17390
+ style
17391
+ }) => new BuilderElement({
17392
+ name: "v:shape",
17393
+ attributes: {
17394
+ id: {
17395
+ key: "id",
17396
+ value: id
17397
+ },
17398
+ type: {
17399
+ key: "type",
17400
+ value: type2
17401
+ },
17402
+ style: {
17403
+ key: "style",
17404
+ value: formatShapeStyle(style)
17405
+ }
17406
+ },
17407
+ children: [createVmlTextbox({ style: "mso-fit-shape-to-text:t;", children })]
17408
+ });
17409
+ class Textbox extends FileChild {
17410
+ constructor(_a) {
17411
+ var _b = _a, { style, children } = _b, rest = __objRest(_b, ["style", "children"]);
17412
+ super("w:p");
17413
+ this.root.push(new ParagraphProperties(rest));
17414
+ this.root.push(
17415
+ createPictElement({
17416
+ shape: createShape({
17417
+ children,
17418
+ id: uniqueId(),
17419
+ style
17420
+ })
17421
+ })
17422
+ );
17423
+ }
17424
+ }
17303
17425
  function commonjsRequire(path) {
17304
17426
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
17305
17427
  }
@@ -19968,6 +20090,11 @@ class Compiler {
19968
20090
  `media/${mediaData.fileName}`
19969
20091
  );
19970
20092
  });
20093
+ file.Document.Relationships.createRelationship(
20094
+ file.Document.Relationships.RelationshipCount + 1,
20095
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
20096
+ "fontTable.xml"
20097
+ );
19971
20098
  return xml$1(
19972
20099
  this.formatter.format(file.Document.Relationships, {
19973
20100
  viewWrapper: file.Document,
@@ -20664,7 +20791,7 @@ const replacer = ({
20664
20791
  }) => {
20665
20792
  const renderedParagraphs = findLocationOfText(json, patchText);
20666
20793
  if (renderedParagraphs.length === 0) {
20667
- throw new Error(`Could not find text ${patchText}`);
20794
+ return { element: json, didFindOccurrence: false };
20668
20795
  }
20669
20796
  for (const renderedParagraph of renderedParagraphs) {
20670
20797
  const textJson = patch.children.map((c) => toJson(xml$1(formatter.format(c, context)))).map((c) => c.elements[0]);
@@ -20691,7 +20818,7 @@ const replacer = ({
20691
20818
  let patchedRightElement = right;
20692
20819
  if (keepOriginalStyles) {
20693
20820
  const runElementNonTextualElements = runElementToBeReplaced.elements.filter(
20694
- (e) => e.type === "element" && e.name !== "w:t" && e.name !== "w:br" && e.name !== "w:tab"
20821
+ (e) => e.type === "element" && e.name === "w:rPr"
20695
20822
  );
20696
20823
  newRunElements = textJson.map((e) => __spreadProps(__spreadValues({}, e), {
20697
20824
  elements: [...runElementNonTextualElements, ...e.elements]
@@ -20705,7 +20832,7 @@ const replacer = ({
20705
20832
  }
20706
20833
  }
20707
20834
  }
20708
- return json;
20835
+ return { element: json, didFindOccurrence: true };
20709
20836
  };
20710
20837
  const goToElementFromPath = (json, path) => {
20711
20838
  let element2 = json;
@@ -20768,32 +20895,31 @@ const patchDocument = (_0) => __async(exports, [_0], function* ({
20768
20895
  for (const [patchKey, patchValue] of Object.entries(patches)) {
20769
20896
  const patchText = `{{${patchKey}}}`;
20770
20897
  while (true) {
20771
- try {
20772
- replacer({
20773
- json,
20774
- patch: __spreadProps(__spreadValues({}, patchValue), {
20775
- children: patchValue.children.map((element2) => {
20776
- if (element2 instanceof ExternalHyperlink) {
20777
- const concreteHyperlink = new ConcreteHyperlink(element2.options.children, uniqueId());
20778
- hyperlinkRelationshipAdditions.push({
20779
- key,
20780
- hyperlink: {
20781
- id: concreteHyperlink.linkId,
20782
- link: element2.options.link
20783
- }
20784
- });
20785
- return concreteHyperlink;
20786
- } else {
20787
- return element2;
20788
- }
20789
- })
20790
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20791
- }),
20792
- patchText,
20793
- context,
20794
- keepOriginalStyles
20795
- });
20796
- } catch (e) {
20898
+ const { didFindOccurrence } = replacer({
20899
+ json,
20900
+ patch: __spreadProps(__spreadValues({}, patchValue), {
20901
+ children: patchValue.children.map((element2) => {
20902
+ if (element2 instanceof ExternalHyperlink) {
20903
+ const concreteHyperlink = new ConcreteHyperlink(element2.options.children, uniqueId());
20904
+ hyperlinkRelationshipAdditions.push({
20905
+ key,
20906
+ hyperlink: {
20907
+ id: concreteHyperlink.linkId,
20908
+ link: element2.options.link
20909
+ }
20910
+ });
20911
+ return concreteHyperlink;
20912
+ } else {
20913
+ return element2;
20914
+ }
20915
+ })
20916
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20917
+ }),
20918
+ patchText,
20919
+ context,
20920
+ keepOriginalStyles
20921
+ });
20922
+ if (!didFindOccurrence) {
20797
20923
  break;
20798
20924
  }
20799
20925
  }
@@ -21133,6 +21259,7 @@ exports.TextEffect = TextEffect;
21133
21259
  exports.TextRun = TextRun;
21134
21260
  exports.TextWrappingSide = TextWrappingSide;
21135
21261
  exports.TextWrappingType = TextWrappingType;
21262
+ exports.Textbox = Textbox;
21136
21263
  exports.ThematicBreak = ThematicBreak;
21137
21264
  exports.Type = Type;
21138
21265
  exports.Underline = Underline;
package/build/index.d.ts CHANGED
@@ -1131,6 +1131,13 @@ export declare type IHorizontalPositionOptions = {
1131
1131
  readonly offset?: number;
1132
1132
  };
1133
1133
 
1134
+ declare type IHyphenationOptions = {
1135
+ readonly autoHyphenation?: boolean;
1136
+ readonly hyphenationZone?: number;
1137
+ readonly consecutiveHyphenLimit?: number;
1138
+ readonly doNotHyphenateCaps?: boolean;
1139
+ };
1140
+
1134
1141
  export declare type IImageOptions = (RegularImageOptions | SvgMediaOptions) & CoreImageOptions;
1135
1142
 
1136
1143
  export declare type IIndentAttributesProperties = {
@@ -1442,6 +1449,7 @@ declare type IPropertiesOptions = {
1442
1449
  readonly evenAndOddHeaderAndFooters?: boolean;
1443
1450
  readonly defaultTabStop?: number;
1444
1451
  readonly fonts?: readonly FontOptions[];
1452
+ readonly hyphenation?: IHyphenationOptions;
1445
1453
  };
1446
1454
 
1447
1455
  export declare type IRunOptions = {
@@ -1539,6 +1547,7 @@ declare type ISettingsOptions = {
1539
1547
  readonly updateFields?: boolean;
1540
1548
  readonly compatibility?: ICompatibilityOptions;
1541
1549
  readonly defaultTabStop?: number;
1550
+ readonly hyphenation?: IHyphenationOptions;
1542
1551
  };
1543
1552
 
1544
1553
  export declare type IShadingAttributesProperties = {
@@ -1707,6 +1716,10 @@ export declare type ITableWidthProperties = {
1707
1716
  readonly type?: (typeof WidthType)[keyof typeof WidthType];
1708
1717
  };
1709
1718
 
1719
+ declare type ITextboxOptions = Omit<IParagraphOptions, "style"> & {
1720
+ readonly style?: VmlShapeStyle;
1721
+ };
1722
+
1710
1723
  export declare type ITextWrapping = {
1711
1724
  readonly type: (typeof TextWrappingType)[keyof typeof TextWrappingType];
1712
1725
  readonly side?: (typeof TextWrappingSide)[keyof typeof TextWrappingSide];
@@ -1750,6 +1763,8 @@ export declare const LeaderType: {
1750
1763
  readonly UNDERSCORE: "underscore";
1751
1764
  };
1752
1765
 
1766
+ declare type LengthUnit = "auto" | number | Percentage | UniversalMeasure | RelativeMeasure;
1767
+
1753
1768
  export declare class Level extends LevelBase {
1754
1769
  }
1755
1770
 
@@ -2355,6 +2370,8 @@ export declare const PositionalTabRelativeTo: {
2355
2370
  readonly INDENT: "indent";
2356
2371
  };
2357
2372
 
2373
+ export declare type PositivePercentage = `${number}%`;
2374
+
2358
2375
  export declare type PositiveUniversalMeasure = `${number}${"mm" | "cm" | "in" | "pt" | "pc" | "pi"}`;
2359
2376
 
2360
2377
  export declare const positiveUniversalMeasureValue: (val: PositiveUniversalMeasure) => PositiveUniversalMeasure;
@@ -2395,6 +2412,8 @@ export declare const RelativeHorizontalPosition: {
2395
2412
  readonly RIGHT: "right";
2396
2413
  };
2397
2414
 
2415
+ export declare type RelativeMeasure = `${"-" | ""}${number}${"em" | "ex"}`;
2416
+
2398
2417
  export declare const RelativeVerticalPosition: {
2399
2418
  readonly CENTER: "center";
2400
2419
  readonly INSIDE: "inside";
@@ -2795,6 +2814,10 @@ export declare class TDirection extends XmlComponent {
2795
2814
  constructor(value: (typeof TextDirection)[keyof typeof TextDirection]);
2796
2815
  }
2797
2816
 
2817
+ export declare class Textbox extends FileChild {
2818
+ constructor({ style, children, ...rest }: ITextboxOptions);
2819
+ }
2820
+
2798
2821
  export declare const TextDirection: {
2799
2822
  readonly BOTTOM_TO_TOP_LEFT_TO_RIGHT: "btLr";
2800
2823
  readonly LEFT_TO_RIGHT_TOP_TO_BOTTOM: "lrTb";
@@ -2930,6 +2953,32 @@ export declare const VerticalPositionRelativeFrom: {
2930
2953
  readonly TOP_MARGIN: "topMargin";
2931
2954
  };
2932
2955
 
2956
+ declare type VmlShapeStyle = {
2957
+ readonly flip?: "x" | "y" | "xy" | "yx";
2958
+ readonly height?: LengthUnit;
2959
+ readonly left?: LengthUnit;
2960
+ readonly marginBottom?: LengthUnit;
2961
+ readonly marginLeft?: LengthUnit;
2962
+ readonly marginRight?: LengthUnit;
2963
+ readonly marginTop?: LengthUnit;
2964
+ readonly positionHorizontal?: "absolute" | "left" | "center" | "right" | "inside" | "outside";
2965
+ readonly positionHorizontalRelative?: "margin" | "page" | "text" | "char";
2966
+ readonly positionVertical?: "absolute" | "left" | "center" | "right" | "inside" | "outside";
2967
+ readonly positionVerticalRelative?: "margin" | "page" | "text" | "char";
2968
+ readonly wrapDistanceBottom?: number;
2969
+ readonly wrapDistanceLeft?: number;
2970
+ readonly wrapDistanceRight?: number;
2971
+ readonly wrapDistanceTop?: number;
2972
+ readonly wrapEdited?: boolean;
2973
+ readonly wrapStyle?: "square" | "none";
2974
+ readonly position?: "static" | "absolute" | "relative";
2975
+ readonly rotation?: number;
2976
+ readonly top?: LengthUnit;
2977
+ readonly visibility?: "hidden" | "inherit";
2978
+ readonly width: LengthUnit;
2979
+ readonly zIndex?: "auto" | number;
2980
+ };
2981
+
2933
2982
  export declare const WidthType: {
2934
2983
  readonly AUTO: "auto";
2935
2984
  readonly DXA: "dxa";
@@ -18,6 +18,18 @@ var __spreadValues = (a, b) => {
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
21
33
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
34
  var __async = (__this, __arguments, generator) => {
23
35
  return new Promise((resolve, reject) => {
@@ -16342,7 +16354,7 @@ var __async = (__this, __arguments, generator) => {
16342
16354
  }
16343
16355
  class Settings extends XmlComponent {
16344
16356
  constructor(options2) {
16345
- var _a, _b, _c, _d;
16357
+ var _a, _b, _c, _d, _e, _f, _g, _h;
16346
16358
  super("w:settings");
16347
16359
  this.root.push(
16348
16360
  new SettingsAttributes({
@@ -16378,9 +16390,21 @@ var __async = (__this, __arguments, generator) => {
16378
16390
  if (options2.defaultTabStop !== void 0) {
16379
16391
  this.root.push(new NumberValueElement("w:defaultTabStop", options2.defaultTabStop));
16380
16392
  }
16393
+ if (((_a = options2.hyphenation) == null ? void 0 : _a.autoHyphenation) !== void 0) {
16394
+ this.root.push(new OnOffElement("w:autoHyphenation", options2.hyphenation.autoHyphenation));
16395
+ }
16396
+ if (((_b = options2.hyphenation) == null ? void 0 : _b.hyphenationZone) !== void 0) {
16397
+ this.root.push(new NumberValueElement("w:hyphenationZone", options2.hyphenation.hyphenationZone));
16398
+ }
16399
+ if (((_c = options2.hyphenation) == null ? void 0 : _c.consecutiveHyphenLimit) !== void 0) {
16400
+ this.root.push(new NumberValueElement("w:consecutiveHyphenLimit", options2.hyphenation.consecutiveHyphenLimit));
16401
+ }
16402
+ if (((_d = options2.hyphenation) == null ? void 0 : _d.doNotHyphenateCaps) !== void 0) {
16403
+ this.root.push(new OnOffElement("w:doNotHyphenateCaps", options2.hyphenation.doNotHyphenateCaps));
16404
+ }
16381
16405
  this.root.push(
16382
- new Compatibility(__spreadProps(__spreadValues({}, (_a = options2.compatibility) != null ? _a : {}), {
16383
- version: (_d = (_c = (_b = options2.compatibility) == null ? void 0 : _b.version) != null ? _c : options2.compatibilityModeVersion) != null ? _d : 15
16406
+ new Compatibility(__spreadProps(__spreadValues({}, (_e = options2.compatibility) != null ? _e : {}), {
16407
+ version: (_h = (_g = (_f = options2.compatibility) == null ? void 0 : _f.version) != null ? _g : options2.compatibilityModeVersion) != null ? _h : 15
16384
16408
  }))
16385
16409
  );
16386
16410
  }
@@ -16795,7 +16819,7 @@ var __async = (__this, __arguments, generator) => {
16795
16819
  __publicField(this, "styles");
16796
16820
  __publicField(this, "comments");
16797
16821
  __publicField(this, "fontWrapper");
16798
- var _a, _b, _c, _d, _e, _f, _g, _h;
16822
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
16799
16823
  this.coreProperties = new CoreProperties(__spreadProps(__spreadValues({}, options2), {
16800
16824
  creator: (_a = options2.creator) != null ? _a : "Un-named",
16801
16825
  revision: (_b = options2.revision) != null ? _b : 1,
@@ -16815,7 +16839,13 @@ var __async = (__this, __arguments, generator) => {
16815
16839
  evenAndOddHeaders: options2.evenAndOddHeaderAndFooters ? true : false,
16816
16840
  trackRevisions: (_f = options2.features) == null ? void 0 : _f.trackRevisions,
16817
16841
  updateFields: (_g = options2.features) == null ? void 0 : _g.updateFields,
16818
- defaultTabStop: options2.defaultTabStop
16842
+ defaultTabStop: options2.defaultTabStop,
16843
+ hyphenation: {
16844
+ autoHyphenation: (_h = options2.hyphenation) == null ? void 0 : _h.autoHyphenation,
16845
+ hyphenationZone: (_i = options2.hyphenation) == null ? void 0 : _i.hyphenationZone,
16846
+ consecutiveHyphenLimit: (_j = options2.hyphenation) == null ? void 0 : _j.consecutiveHyphenLimit,
16847
+ doNotHyphenateCaps: (_k = options2.hyphenation) == null ? void 0 : _k.doNotHyphenateCaps
16848
+ }
16819
16849
  });
16820
16850
  this.media = new Media();
16821
16851
  if (options2.externalStyles !== void 0) {
@@ -16838,7 +16868,7 @@ var __async = (__this, __arguments, generator) => {
16838
16868
  this.footnotesWrapper.View.createFootNote(parseFloat(key), options2.footnotes[key].children);
16839
16869
  }
16840
16870
  }
16841
- this.fontWrapper = new FontWrapper((_h = options2.fonts) != null ? _h : []);
16871
+ this.fontWrapper = new FontWrapper((_l = options2.fonts) != null ? _l : []);
16842
16872
  }
16843
16873
  addSection({ headers = {}, footers = {}, children, properties }) {
16844
16874
  this.documentWrapper.View.Body.addSection(__spreadProps(__spreadValues({}, properties), {
@@ -17300,6 +17330,98 @@ var __async = (__this, __arguments, generator) => {
17300
17330
  this.root.push(content);
17301
17331
  }
17302
17332
  }
17333
+ const createPictElement = ({ shape }) => new BuilderElement({
17334
+ name: "w:pict",
17335
+ children: [shape]
17336
+ });
17337
+ const createTextboxContent = ({ children = [] }) => new BuilderElement({
17338
+ name: "w:txbxContent",
17339
+ children
17340
+ });
17341
+ const createVmlTextbox = ({ style, children, inset }) => new BuilderElement({
17342
+ name: "v:textbox",
17343
+ attributes: {
17344
+ style: {
17345
+ key: "style",
17346
+ value: style
17347
+ },
17348
+ insetMode: {
17349
+ key: "insetmode",
17350
+ value: inset ? "custom" : "auto"
17351
+ },
17352
+ inset: {
17353
+ key: "inset",
17354
+ value: inset ? `${inset.left}, ${inset.top}, ${inset.right}, ${inset.bottom}` : void 0
17355
+ }
17356
+ },
17357
+ children: [createTextboxContent({ children })]
17358
+ });
17359
+ const SHAPE_TYPE = "#_x0000_t202";
17360
+ const styleToKeyMap = {
17361
+ flip: "flip",
17362
+ height: "height",
17363
+ left: "left",
17364
+ marginBottom: "margin-bottom",
17365
+ marginLeft: "margin-left",
17366
+ marginRight: "margin-right",
17367
+ marginTop: "margin-top",
17368
+ positionHorizontal: "mso-position-horizontal",
17369
+ positionHorizontalRelative: "mso-position-horizontal-relative",
17370
+ positionVertical: "mso-position-vertical",
17371
+ positionVerticalRelative: "mso-position-vertical-relative",
17372
+ wrapDistanceBottom: "mso-wrap-distance-bottom",
17373
+ wrapDistanceLeft: "mso-wrap-distance-left",
17374
+ wrapDistanceRight: "mso-wrap-distance-right",
17375
+ wrapDistanceTop: "mso-wrap-distance-top",
17376
+ wrapEdited: "mso-wrap-edited",
17377
+ wrapStyle: "mso-wrap-style",
17378
+ position: "position",
17379
+ rotation: "rotation",
17380
+ top: "top",
17381
+ visibility: "visibility",
17382
+ width: "width",
17383
+ zIndex: "z-index"
17384
+ };
17385
+ const formatShapeStyle = (style) => style ? Object.entries(style).map(([key, value]) => `${styleToKeyMap[key]}:${value}`).join(";") : void 0;
17386
+ const createShape = ({
17387
+ id,
17388
+ children,
17389
+ type: type2 = SHAPE_TYPE,
17390
+ style
17391
+ }) => new BuilderElement({
17392
+ name: "v:shape",
17393
+ attributes: {
17394
+ id: {
17395
+ key: "id",
17396
+ value: id
17397
+ },
17398
+ type: {
17399
+ key: "type",
17400
+ value: type2
17401
+ },
17402
+ style: {
17403
+ key: "style",
17404
+ value: formatShapeStyle(style)
17405
+ }
17406
+ },
17407
+ children: [createVmlTextbox({ style: "mso-fit-shape-to-text:t;", children })]
17408
+ });
17409
+ class Textbox extends FileChild {
17410
+ constructor(_a) {
17411
+ var _b = _a, { style, children } = _b, rest = __objRest(_b, ["style", "children"]);
17412
+ super("w:p");
17413
+ this.root.push(new ParagraphProperties(rest));
17414
+ this.root.push(
17415
+ createPictElement({
17416
+ shape: createShape({
17417
+ children,
17418
+ id: uniqueId(),
17419
+ style
17420
+ })
17421
+ })
17422
+ );
17423
+ }
17424
+ }
17303
17425
  function commonjsRequire(path) {
17304
17426
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
17305
17427
  }
@@ -19968,6 +20090,11 @@ var __async = (__this, __arguments, generator) => {
19968
20090
  `media/${mediaData.fileName}`
19969
20091
  );
19970
20092
  });
20093
+ file.Document.Relationships.createRelationship(
20094
+ file.Document.Relationships.RelationshipCount + 1,
20095
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
20096
+ "fontTable.xml"
20097
+ );
19971
20098
  return xml$1(
19972
20099
  this.formatter.format(file.Document.Relationships, {
19973
20100
  viewWrapper: file.Document,
@@ -20664,7 +20791,7 @@ var __async = (__this, __arguments, generator) => {
20664
20791
  }) => {
20665
20792
  const renderedParagraphs = findLocationOfText(json, patchText);
20666
20793
  if (renderedParagraphs.length === 0) {
20667
- throw new Error(`Could not find text ${patchText}`);
20794
+ return { element: json, didFindOccurrence: false };
20668
20795
  }
20669
20796
  for (const renderedParagraph of renderedParagraphs) {
20670
20797
  const textJson = patch.children.map((c) => toJson(xml$1(formatter.format(c, context)))).map((c) => c.elements[0]);
@@ -20691,7 +20818,7 @@ var __async = (__this, __arguments, generator) => {
20691
20818
  let patchedRightElement = right;
20692
20819
  if (keepOriginalStyles) {
20693
20820
  const runElementNonTextualElements = runElementToBeReplaced.elements.filter(
20694
- (e) => e.type === "element" && e.name !== "w:t" && e.name !== "w:br" && e.name !== "w:tab"
20821
+ (e) => e.type === "element" && e.name === "w:rPr"
20695
20822
  );
20696
20823
  newRunElements = textJson.map((e) => __spreadProps(__spreadValues({}, e), {
20697
20824
  elements: [...runElementNonTextualElements, ...e.elements]
@@ -20705,7 +20832,7 @@ var __async = (__this, __arguments, generator) => {
20705
20832
  }
20706
20833
  }
20707
20834
  }
20708
- return json;
20835
+ return { element: json, didFindOccurrence: true };
20709
20836
  };
20710
20837
  const goToElementFromPath = (json, path) => {
20711
20838
  let element2 = json;
@@ -20768,32 +20895,31 @@ var __async = (__this, __arguments, generator) => {
20768
20895
  for (const [patchKey, patchValue] of Object.entries(patches)) {
20769
20896
  const patchText = `{{${patchKey}}}`;
20770
20897
  while (true) {
20771
- try {
20772
- replacer({
20773
- json,
20774
- patch: __spreadProps(__spreadValues({}, patchValue), {
20775
- children: patchValue.children.map((element2) => {
20776
- if (element2 instanceof ExternalHyperlink) {
20777
- const concreteHyperlink = new ConcreteHyperlink(element2.options.children, uniqueId());
20778
- hyperlinkRelationshipAdditions.push({
20779
- key,
20780
- hyperlink: {
20781
- id: concreteHyperlink.linkId,
20782
- link: element2.options.link
20783
- }
20784
- });
20785
- return concreteHyperlink;
20786
- } else {
20787
- return element2;
20788
- }
20789
- })
20790
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20791
- }),
20792
- patchText,
20793
- context,
20794
- keepOriginalStyles
20795
- });
20796
- } catch (e) {
20898
+ const { didFindOccurrence } = replacer({
20899
+ json,
20900
+ patch: __spreadProps(__spreadValues({}, patchValue), {
20901
+ children: patchValue.children.map((element2) => {
20902
+ if (element2 instanceof ExternalHyperlink) {
20903
+ const concreteHyperlink = new ConcreteHyperlink(element2.options.children, uniqueId());
20904
+ hyperlinkRelationshipAdditions.push({
20905
+ key,
20906
+ hyperlink: {
20907
+ id: concreteHyperlink.linkId,
20908
+ link: element2.options.link
20909
+ }
20910
+ });
20911
+ return concreteHyperlink;
20912
+ } else {
20913
+ return element2;
20914
+ }
20915
+ })
20916
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20917
+ }),
20918
+ patchText,
20919
+ context,
20920
+ keepOriginalStyles
20921
+ });
20922
+ if (!didFindOccurrence) {
20797
20923
  break;
20798
20924
  }
20799
20925
  }
@@ -21133,6 +21259,7 @@ var __async = (__this, __arguments, generator) => {
21133
21259
  exports.TextRun = TextRun;
21134
21260
  exports.TextWrappingSide = TextWrappingSide;
21135
21261
  exports.TextWrappingType = TextWrappingType;
21262
+ exports.Textbox = Textbox;
21136
21263
  exports.ThematicBreak = ThematicBreak;
21137
21264
  exports.Type = Type;
21138
21265
  exports.Underline = Underline;
package/build/index.mjs CHANGED
@@ -17,6 +17,18 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
20
32
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
33
  var __async = (__this, __arguments, generator) => {
22
34
  return new Promise((resolve2, reject) => {
@@ -16340,7 +16352,7 @@ class SettingsAttributes extends XmlAttributeComponent {
16340
16352
  }
16341
16353
  class Settings extends XmlComponent {
16342
16354
  constructor(options2) {
16343
- var _a, _b, _c, _d;
16355
+ var _a, _b, _c, _d, _e, _f, _g, _h;
16344
16356
  super("w:settings");
16345
16357
  this.root.push(
16346
16358
  new SettingsAttributes({
@@ -16376,9 +16388,21 @@ class Settings extends XmlComponent {
16376
16388
  if (options2.defaultTabStop !== void 0) {
16377
16389
  this.root.push(new NumberValueElement("w:defaultTabStop", options2.defaultTabStop));
16378
16390
  }
16391
+ if (((_a = options2.hyphenation) == null ? void 0 : _a.autoHyphenation) !== void 0) {
16392
+ this.root.push(new OnOffElement("w:autoHyphenation", options2.hyphenation.autoHyphenation));
16393
+ }
16394
+ if (((_b = options2.hyphenation) == null ? void 0 : _b.hyphenationZone) !== void 0) {
16395
+ this.root.push(new NumberValueElement("w:hyphenationZone", options2.hyphenation.hyphenationZone));
16396
+ }
16397
+ if (((_c = options2.hyphenation) == null ? void 0 : _c.consecutiveHyphenLimit) !== void 0) {
16398
+ this.root.push(new NumberValueElement("w:consecutiveHyphenLimit", options2.hyphenation.consecutiveHyphenLimit));
16399
+ }
16400
+ if (((_d = options2.hyphenation) == null ? void 0 : _d.doNotHyphenateCaps) !== void 0) {
16401
+ this.root.push(new OnOffElement("w:doNotHyphenateCaps", options2.hyphenation.doNotHyphenateCaps));
16402
+ }
16379
16403
  this.root.push(
16380
- new Compatibility(__spreadProps(__spreadValues({}, (_a = options2.compatibility) != null ? _a : {}), {
16381
- version: (_d = (_c = (_b = options2.compatibility) == null ? void 0 : _b.version) != null ? _c : options2.compatibilityModeVersion) != null ? _d : 15
16404
+ new Compatibility(__spreadProps(__spreadValues({}, (_e = options2.compatibility) != null ? _e : {}), {
16405
+ version: (_h = (_g = (_f = options2.compatibility) == null ? void 0 : _f.version) != null ? _g : options2.compatibilityModeVersion) != null ? _h : 15
16382
16406
  }))
16383
16407
  );
16384
16408
  }
@@ -16793,7 +16817,7 @@ class File {
16793
16817
  __publicField(this, "styles");
16794
16818
  __publicField(this, "comments");
16795
16819
  __publicField(this, "fontWrapper");
16796
- var _a, _b, _c, _d, _e, _f, _g, _h;
16820
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
16797
16821
  this.coreProperties = new CoreProperties(__spreadProps(__spreadValues({}, options2), {
16798
16822
  creator: (_a = options2.creator) != null ? _a : "Un-named",
16799
16823
  revision: (_b = options2.revision) != null ? _b : 1,
@@ -16813,7 +16837,13 @@ class File {
16813
16837
  evenAndOddHeaders: options2.evenAndOddHeaderAndFooters ? true : false,
16814
16838
  trackRevisions: (_f = options2.features) == null ? void 0 : _f.trackRevisions,
16815
16839
  updateFields: (_g = options2.features) == null ? void 0 : _g.updateFields,
16816
- defaultTabStop: options2.defaultTabStop
16840
+ defaultTabStop: options2.defaultTabStop,
16841
+ hyphenation: {
16842
+ autoHyphenation: (_h = options2.hyphenation) == null ? void 0 : _h.autoHyphenation,
16843
+ hyphenationZone: (_i = options2.hyphenation) == null ? void 0 : _i.hyphenationZone,
16844
+ consecutiveHyphenLimit: (_j = options2.hyphenation) == null ? void 0 : _j.consecutiveHyphenLimit,
16845
+ doNotHyphenateCaps: (_k = options2.hyphenation) == null ? void 0 : _k.doNotHyphenateCaps
16846
+ }
16817
16847
  });
16818
16848
  this.media = new Media();
16819
16849
  if (options2.externalStyles !== void 0) {
@@ -16836,7 +16866,7 @@ class File {
16836
16866
  this.footnotesWrapper.View.createFootNote(parseFloat(key), options2.footnotes[key].children);
16837
16867
  }
16838
16868
  }
16839
- this.fontWrapper = new FontWrapper((_h = options2.fonts) != null ? _h : []);
16869
+ this.fontWrapper = new FontWrapper((_l = options2.fonts) != null ? _l : []);
16840
16870
  }
16841
16871
  addSection({ headers = {}, footers = {}, children, properties }) {
16842
16872
  this.documentWrapper.View.Body.addSection(__spreadProps(__spreadValues({}, properties), {
@@ -17298,6 +17328,98 @@ class CheckBox extends XmlComponent {
17298
17328
  this.root.push(content);
17299
17329
  }
17300
17330
  }
17331
+ const createPictElement = ({ shape }) => new BuilderElement({
17332
+ name: "w:pict",
17333
+ children: [shape]
17334
+ });
17335
+ const createTextboxContent = ({ children = [] }) => new BuilderElement({
17336
+ name: "w:txbxContent",
17337
+ children
17338
+ });
17339
+ const createVmlTextbox = ({ style, children, inset }) => new BuilderElement({
17340
+ name: "v:textbox",
17341
+ attributes: {
17342
+ style: {
17343
+ key: "style",
17344
+ value: style
17345
+ },
17346
+ insetMode: {
17347
+ key: "insetmode",
17348
+ value: inset ? "custom" : "auto"
17349
+ },
17350
+ inset: {
17351
+ key: "inset",
17352
+ value: inset ? `${inset.left}, ${inset.top}, ${inset.right}, ${inset.bottom}` : void 0
17353
+ }
17354
+ },
17355
+ children: [createTextboxContent({ children })]
17356
+ });
17357
+ const SHAPE_TYPE = "#_x0000_t202";
17358
+ const styleToKeyMap = {
17359
+ flip: "flip",
17360
+ height: "height",
17361
+ left: "left",
17362
+ marginBottom: "margin-bottom",
17363
+ marginLeft: "margin-left",
17364
+ marginRight: "margin-right",
17365
+ marginTop: "margin-top",
17366
+ positionHorizontal: "mso-position-horizontal",
17367
+ positionHorizontalRelative: "mso-position-horizontal-relative",
17368
+ positionVertical: "mso-position-vertical",
17369
+ positionVerticalRelative: "mso-position-vertical-relative",
17370
+ wrapDistanceBottom: "mso-wrap-distance-bottom",
17371
+ wrapDistanceLeft: "mso-wrap-distance-left",
17372
+ wrapDistanceRight: "mso-wrap-distance-right",
17373
+ wrapDistanceTop: "mso-wrap-distance-top",
17374
+ wrapEdited: "mso-wrap-edited",
17375
+ wrapStyle: "mso-wrap-style",
17376
+ position: "position",
17377
+ rotation: "rotation",
17378
+ top: "top",
17379
+ visibility: "visibility",
17380
+ width: "width",
17381
+ zIndex: "z-index"
17382
+ };
17383
+ const formatShapeStyle = (style) => style ? Object.entries(style).map(([key, value]) => `${styleToKeyMap[key]}:${value}`).join(";") : void 0;
17384
+ const createShape = ({
17385
+ id,
17386
+ children,
17387
+ type: type2 = SHAPE_TYPE,
17388
+ style
17389
+ }) => new BuilderElement({
17390
+ name: "v:shape",
17391
+ attributes: {
17392
+ id: {
17393
+ key: "id",
17394
+ value: id
17395
+ },
17396
+ type: {
17397
+ key: "type",
17398
+ value: type2
17399
+ },
17400
+ style: {
17401
+ key: "style",
17402
+ value: formatShapeStyle(style)
17403
+ }
17404
+ },
17405
+ children: [createVmlTextbox({ style: "mso-fit-shape-to-text:t;", children })]
17406
+ });
17407
+ class Textbox extends FileChild {
17408
+ constructor(_a) {
17409
+ var _b = _a, { style, children } = _b, rest = __objRest(_b, ["style", "children"]);
17410
+ super("w:p");
17411
+ this.root.push(new ParagraphProperties(rest));
17412
+ this.root.push(
17413
+ createPictElement({
17414
+ shape: createShape({
17415
+ children,
17416
+ id: uniqueId(),
17417
+ style
17418
+ })
17419
+ })
17420
+ );
17421
+ }
17422
+ }
17301
17423
  function commonjsRequire(path) {
17302
17424
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
17303
17425
  }
@@ -19966,6 +20088,11 @@ class Compiler {
19966
20088
  `media/${mediaData.fileName}`
19967
20089
  );
19968
20090
  });
20091
+ file.Document.Relationships.createRelationship(
20092
+ file.Document.Relationships.RelationshipCount + 1,
20093
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
20094
+ "fontTable.xml"
20095
+ );
19969
20096
  return xml$1(
19970
20097
  this.formatter.format(file.Document.Relationships, {
19971
20098
  viewWrapper: file.Document,
@@ -20662,7 +20789,7 @@ const replacer = ({
20662
20789
  }) => {
20663
20790
  const renderedParagraphs = findLocationOfText(json, patchText);
20664
20791
  if (renderedParagraphs.length === 0) {
20665
- throw new Error(`Could not find text ${patchText}`);
20792
+ return { element: json, didFindOccurrence: false };
20666
20793
  }
20667
20794
  for (const renderedParagraph of renderedParagraphs) {
20668
20795
  const textJson = patch.children.map((c) => toJson(xml$1(formatter.format(c, context)))).map((c) => c.elements[0]);
@@ -20689,7 +20816,7 @@ const replacer = ({
20689
20816
  let patchedRightElement = right;
20690
20817
  if (keepOriginalStyles) {
20691
20818
  const runElementNonTextualElements = runElementToBeReplaced.elements.filter(
20692
- (e) => e.type === "element" && e.name !== "w:t" && e.name !== "w:br" && e.name !== "w:tab"
20819
+ (e) => e.type === "element" && e.name === "w:rPr"
20693
20820
  );
20694
20821
  newRunElements = textJson.map((e) => __spreadProps(__spreadValues({}, e), {
20695
20822
  elements: [...runElementNonTextualElements, ...e.elements]
@@ -20703,7 +20830,7 @@ const replacer = ({
20703
20830
  }
20704
20831
  }
20705
20832
  }
20706
- return json;
20833
+ return { element: json, didFindOccurrence: true };
20707
20834
  };
20708
20835
  const goToElementFromPath = (json, path) => {
20709
20836
  let element2 = json;
@@ -20766,32 +20893,31 @@ const patchDocument = (_0) => __async(void 0, [_0], function* ({
20766
20893
  for (const [patchKey, patchValue] of Object.entries(patches)) {
20767
20894
  const patchText = `{{${patchKey}}}`;
20768
20895
  while (true) {
20769
- try {
20770
- replacer({
20771
- json,
20772
- patch: __spreadProps(__spreadValues({}, patchValue), {
20773
- children: patchValue.children.map((element2) => {
20774
- if (element2 instanceof ExternalHyperlink) {
20775
- const concreteHyperlink = new ConcreteHyperlink(element2.options.children, uniqueId());
20776
- hyperlinkRelationshipAdditions.push({
20777
- key,
20778
- hyperlink: {
20779
- id: concreteHyperlink.linkId,
20780
- link: element2.options.link
20781
- }
20782
- });
20783
- return concreteHyperlink;
20784
- } else {
20785
- return element2;
20786
- }
20787
- })
20788
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20789
- }),
20790
- patchText,
20791
- context,
20792
- keepOriginalStyles
20793
- });
20794
- } catch (e) {
20896
+ const { didFindOccurrence } = replacer({
20897
+ json,
20898
+ patch: __spreadProps(__spreadValues({}, patchValue), {
20899
+ children: patchValue.children.map((element2) => {
20900
+ if (element2 instanceof ExternalHyperlink) {
20901
+ const concreteHyperlink = new ConcreteHyperlink(element2.options.children, uniqueId());
20902
+ hyperlinkRelationshipAdditions.push({
20903
+ key,
20904
+ hyperlink: {
20905
+ id: concreteHyperlink.linkId,
20906
+ link: element2.options.link
20907
+ }
20908
+ });
20909
+ return concreteHyperlink;
20910
+ } else {
20911
+ return element2;
20912
+ }
20913
+ })
20914
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20915
+ }),
20916
+ patchText,
20917
+ context,
20918
+ keepOriginalStyles
20919
+ });
20920
+ if (!didFindOccurrence) {
20795
20921
  break;
20796
20922
  }
20797
20923
  }
@@ -21132,6 +21258,7 @@ export {
21132
21258
  TextRun,
21133
21259
  TextWrappingSide,
21134
21260
  TextWrappingType,
21261
+ Textbox,
21135
21262
  ThematicBreak,
21136
21263
  Type,
21137
21264
  Underline,
@@ -20,6 +20,18 @@ var __spreadValues = (a, b) => {
20
20
  return a;
21
21
  };
22
22
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __objRest = (source, exclude) => {
24
+ var target = {};
25
+ for (var prop in source)
26
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
27
+ target[prop] = source[prop];
28
+ if (source != null && __getOwnPropSymbols)
29
+ for (var prop of __getOwnPropSymbols(source)) {
30
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
31
+ target[prop] = source[prop];
32
+ }
33
+ return target;
34
+ };
23
35
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
24
36
  var __async = (__this, __arguments, generator) => {
25
37
  return new Promise((resolve, reject) => {
@@ -16344,7 +16356,7 @@ var __async = (__this, __arguments, generator) => {
16344
16356
  }
16345
16357
  class Settings extends XmlComponent {
16346
16358
  constructor(options2) {
16347
- var _a, _b, _c, _d;
16359
+ var _a, _b, _c, _d, _e, _f, _g, _h;
16348
16360
  super("w:settings");
16349
16361
  this.root.push(
16350
16362
  new SettingsAttributes({
@@ -16380,9 +16392,21 @@ var __async = (__this, __arguments, generator) => {
16380
16392
  if (options2.defaultTabStop !== void 0) {
16381
16393
  this.root.push(new NumberValueElement("w:defaultTabStop", options2.defaultTabStop));
16382
16394
  }
16395
+ if (((_a = options2.hyphenation) == null ? void 0 : _a.autoHyphenation) !== void 0) {
16396
+ this.root.push(new OnOffElement("w:autoHyphenation", options2.hyphenation.autoHyphenation));
16397
+ }
16398
+ if (((_b = options2.hyphenation) == null ? void 0 : _b.hyphenationZone) !== void 0) {
16399
+ this.root.push(new NumberValueElement("w:hyphenationZone", options2.hyphenation.hyphenationZone));
16400
+ }
16401
+ if (((_c = options2.hyphenation) == null ? void 0 : _c.consecutiveHyphenLimit) !== void 0) {
16402
+ this.root.push(new NumberValueElement("w:consecutiveHyphenLimit", options2.hyphenation.consecutiveHyphenLimit));
16403
+ }
16404
+ if (((_d = options2.hyphenation) == null ? void 0 : _d.doNotHyphenateCaps) !== void 0) {
16405
+ this.root.push(new OnOffElement("w:doNotHyphenateCaps", options2.hyphenation.doNotHyphenateCaps));
16406
+ }
16383
16407
  this.root.push(
16384
- new Compatibility(__spreadProps(__spreadValues({}, (_a = options2.compatibility) != null ? _a : {}), {
16385
- version: (_d = (_c = (_b = options2.compatibility) == null ? void 0 : _b.version) != null ? _c : options2.compatibilityModeVersion) != null ? _d : 15
16408
+ new Compatibility(__spreadProps(__spreadValues({}, (_e = options2.compatibility) != null ? _e : {}), {
16409
+ version: (_h = (_g = (_f = options2.compatibility) == null ? void 0 : _f.version) != null ? _g : options2.compatibilityModeVersion) != null ? _h : 15
16386
16410
  }))
16387
16411
  );
16388
16412
  }
@@ -16797,7 +16821,7 @@ var __async = (__this, __arguments, generator) => {
16797
16821
  __publicField(this, "styles");
16798
16822
  __publicField(this, "comments");
16799
16823
  __publicField(this, "fontWrapper");
16800
- var _a, _b, _c, _d, _e, _f, _g, _h;
16824
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
16801
16825
  this.coreProperties = new CoreProperties(__spreadProps(__spreadValues({}, options2), {
16802
16826
  creator: (_a = options2.creator) != null ? _a : "Un-named",
16803
16827
  revision: (_b = options2.revision) != null ? _b : 1,
@@ -16817,7 +16841,13 @@ var __async = (__this, __arguments, generator) => {
16817
16841
  evenAndOddHeaders: options2.evenAndOddHeaderAndFooters ? true : false,
16818
16842
  trackRevisions: (_f = options2.features) == null ? void 0 : _f.trackRevisions,
16819
16843
  updateFields: (_g = options2.features) == null ? void 0 : _g.updateFields,
16820
- defaultTabStop: options2.defaultTabStop
16844
+ defaultTabStop: options2.defaultTabStop,
16845
+ hyphenation: {
16846
+ autoHyphenation: (_h = options2.hyphenation) == null ? void 0 : _h.autoHyphenation,
16847
+ hyphenationZone: (_i = options2.hyphenation) == null ? void 0 : _i.hyphenationZone,
16848
+ consecutiveHyphenLimit: (_j = options2.hyphenation) == null ? void 0 : _j.consecutiveHyphenLimit,
16849
+ doNotHyphenateCaps: (_k = options2.hyphenation) == null ? void 0 : _k.doNotHyphenateCaps
16850
+ }
16821
16851
  });
16822
16852
  this.media = new Media();
16823
16853
  if (options2.externalStyles !== void 0) {
@@ -16840,7 +16870,7 @@ var __async = (__this, __arguments, generator) => {
16840
16870
  this.footnotesWrapper.View.createFootNote(parseFloat(key), options2.footnotes[key].children);
16841
16871
  }
16842
16872
  }
16843
- this.fontWrapper = new FontWrapper((_h = options2.fonts) != null ? _h : []);
16873
+ this.fontWrapper = new FontWrapper((_l = options2.fonts) != null ? _l : []);
16844
16874
  }
16845
16875
  addSection({ headers = {}, footers = {}, children, properties }) {
16846
16876
  this.documentWrapper.View.Body.addSection(__spreadProps(__spreadValues({}, properties), {
@@ -17302,6 +17332,98 @@ var __async = (__this, __arguments, generator) => {
17302
17332
  this.root.push(content);
17303
17333
  }
17304
17334
  }
17335
+ const createPictElement = ({ shape }) => new BuilderElement({
17336
+ name: "w:pict",
17337
+ children: [shape]
17338
+ });
17339
+ const createTextboxContent = ({ children = [] }) => new BuilderElement({
17340
+ name: "w:txbxContent",
17341
+ children
17342
+ });
17343
+ const createVmlTextbox = ({ style, children, inset }) => new BuilderElement({
17344
+ name: "v:textbox",
17345
+ attributes: {
17346
+ style: {
17347
+ key: "style",
17348
+ value: style
17349
+ },
17350
+ insetMode: {
17351
+ key: "insetmode",
17352
+ value: inset ? "custom" : "auto"
17353
+ },
17354
+ inset: {
17355
+ key: "inset",
17356
+ value: inset ? `${inset.left}, ${inset.top}, ${inset.right}, ${inset.bottom}` : void 0
17357
+ }
17358
+ },
17359
+ children: [createTextboxContent({ children })]
17360
+ });
17361
+ const SHAPE_TYPE = "#_x0000_t202";
17362
+ const styleToKeyMap = {
17363
+ flip: "flip",
17364
+ height: "height",
17365
+ left: "left",
17366
+ marginBottom: "margin-bottom",
17367
+ marginLeft: "margin-left",
17368
+ marginRight: "margin-right",
17369
+ marginTop: "margin-top",
17370
+ positionHorizontal: "mso-position-horizontal",
17371
+ positionHorizontalRelative: "mso-position-horizontal-relative",
17372
+ positionVertical: "mso-position-vertical",
17373
+ positionVerticalRelative: "mso-position-vertical-relative",
17374
+ wrapDistanceBottom: "mso-wrap-distance-bottom",
17375
+ wrapDistanceLeft: "mso-wrap-distance-left",
17376
+ wrapDistanceRight: "mso-wrap-distance-right",
17377
+ wrapDistanceTop: "mso-wrap-distance-top",
17378
+ wrapEdited: "mso-wrap-edited",
17379
+ wrapStyle: "mso-wrap-style",
17380
+ position: "position",
17381
+ rotation: "rotation",
17382
+ top: "top",
17383
+ visibility: "visibility",
17384
+ width: "width",
17385
+ zIndex: "z-index"
17386
+ };
17387
+ const formatShapeStyle = (style) => style ? Object.entries(style).map(([key, value]) => `${styleToKeyMap[key]}:${value}`).join(";") : void 0;
17388
+ const createShape = ({
17389
+ id,
17390
+ children,
17391
+ type: type2 = SHAPE_TYPE,
17392
+ style
17393
+ }) => new BuilderElement({
17394
+ name: "v:shape",
17395
+ attributes: {
17396
+ id: {
17397
+ key: "id",
17398
+ value: id
17399
+ },
17400
+ type: {
17401
+ key: "type",
17402
+ value: type2
17403
+ },
17404
+ style: {
17405
+ key: "style",
17406
+ value: formatShapeStyle(style)
17407
+ }
17408
+ },
17409
+ children: [createVmlTextbox({ style: "mso-fit-shape-to-text:t;", children })]
17410
+ });
17411
+ class Textbox extends FileChild {
17412
+ constructor(_a) {
17413
+ var _b = _a, { style, children } = _b, rest = __objRest(_b, ["style", "children"]);
17414
+ super("w:p");
17415
+ this.root.push(new ParagraphProperties(rest));
17416
+ this.root.push(
17417
+ createPictElement({
17418
+ shape: createShape({
17419
+ children,
17420
+ id: uniqueId(),
17421
+ style
17422
+ })
17423
+ })
17424
+ );
17425
+ }
17426
+ }
17305
17427
  function commonjsRequire(path) {
17306
17428
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
17307
17429
  }
@@ -19970,6 +20092,11 @@ var __async = (__this, __arguments, generator) => {
19970
20092
  `media/${mediaData.fileName}`
19971
20093
  );
19972
20094
  });
20095
+ file.Document.Relationships.createRelationship(
20096
+ file.Document.Relationships.RelationshipCount + 1,
20097
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
20098
+ "fontTable.xml"
20099
+ );
19973
20100
  return xml$1(
19974
20101
  this.formatter.format(file.Document.Relationships, {
19975
20102
  viewWrapper: file.Document,
@@ -20666,7 +20793,7 @@ var __async = (__this, __arguments, generator) => {
20666
20793
  }) => {
20667
20794
  const renderedParagraphs = findLocationOfText(json, patchText);
20668
20795
  if (renderedParagraphs.length === 0) {
20669
- throw new Error(`Could not find text ${patchText}`);
20796
+ return { element: json, didFindOccurrence: false };
20670
20797
  }
20671
20798
  for (const renderedParagraph of renderedParagraphs) {
20672
20799
  const textJson = patch.children.map((c) => toJson(xml$1(formatter.format(c, context)))).map((c) => c.elements[0]);
@@ -20693,7 +20820,7 @@ var __async = (__this, __arguments, generator) => {
20693
20820
  let patchedRightElement = right;
20694
20821
  if (keepOriginalStyles) {
20695
20822
  const runElementNonTextualElements = runElementToBeReplaced.elements.filter(
20696
- (e) => e.type === "element" && e.name !== "w:t" && e.name !== "w:br" && e.name !== "w:tab"
20823
+ (e) => e.type === "element" && e.name === "w:rPr"
20697
20824
  );
20698
20825
  newRunElements = textJson.map((e) => __spreadProps(__spreadValues({}, e), {
20699
20826
  elements: [...runElementNonTextualElements, ...e.elements]
@@ -20707,7 +20834,7 @@ var __async = (__this, __arguments, generator) => {
20707
20834
  }
20708
20835
  }
20709
20836
  }
20710
- return json;
20837
+ return { element: json, didFindOccurrence: true };
20711
20838
  };
20712
20839
  const goToElementFromPath = (json, path) => {
20713
20840
  let element2 = json;
@@ -20770,32 +20897,31 @@ var __async = (__this, __arguments, generator) => {
20770
20897
  for (const [patchKey, patchValue] of Object.entries(patches)) {
20771
20898
  const patchText = `{{${patchKey}}}`;
20772
20899
  while (true) {
20773
- try {
20774
- replacer({
20775
- json,
20776
- patch: __spreadProps(__spreadValues({}, patchValue), {
20777
- children: patchValue.children.map((element2) => {
20778
- if (element2 instanceof ExternalHyperlink) {
20779
- const concreteHyperlink = new ConcreteHyperlink(element2.options.children, uniqueId());
20780
- hyperlinkRelationshipAdditions.push({
20781
- key,
20782
- hyperlink: {
20783
- id: concreteHyperlink.linkId,
20784
- link: element2.options.link
20785
- }
20786
- });
20787
- return concreteHyperlink;
20788
- } else {
20789
- return element2;
20790
- }
20791
- })
20792
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20793
- }),
20794
- patchText,
20795
- context,
20796
- keepOriginalStyles
20797
- });
20798
- } catch (e) {
20900
+ const { didFindOccurrence } = replacer({
20901
+ json,
20902
+ patch: __spreadProps(__spreadValues({}, patchValue), {
20903
+ children: patchValue.children.map((element2) => {
20904
+ if (element2 instanceof ExternalHyperlink) {
20905
+ const concreteHyperlink = new ConcreteHyperlink(element2.options.children, uniqueId());
20906
+ hyperlinkRelationshipAdditions.push({
20907
+ key,
20908
+ hyperlink: {
20909
+ id: concreteHyperlink.linkId,
20910
+ link: element2.options.link
20911
+ }
20912
+ });
20913
+ return concreteHyperlink;
20914
+ } else {
20915
+ return element2;
20916
+ }
20917
+ })
20918
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20919
+ }),
20920
+ patchText,
20921
+ context,
20922
+ keepOriginalStyles
20923
+ });
20924
+ if (!didFindOccurrence) {
20799
20925
  break;
20800
20926
  }
20801
20927
  }
@@ -21135,6 +21261,7 @@ var __async = (__this, __arguments, generator) => {
21135
21261
  exports2.TextRun = TextRun;
21136
21262
  exports2.TextWrappingSide = TextWrappingSide;
21137
21263
  exports2.TextWrappingType = TextWrappingType;
21264
+ exports2.Textbox = Textbox;
21138
21265
  exports2.ThematicBreak = ThematicBreak;
21139
21266
  exports2.Type = Type;
21140
21267
  exports2.Underline = Underline;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docx",
3
- "version": "9.0.3",
3
+ "version": "9.1.0",
4
4
  "description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
5
5
  "type": "module",
6
6
  "main": "build/index.umd.js",