docx 9.7.1 → 9.8.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.
@@ -0,0 +1,1271 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("docx")) : typeof define === "function" && define.amd ? define(["exports", "docx"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.docxWatermarks = {}, global.docx));
3
+ })(this, function(exports, docx) {
4
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
5
+ //#region src/watermarks/vml/pict.ts
6
+ /**
7
+ * The picture element (`w:pict`) that holds a watermark's VML shape type and shape.
8
+ *
9
+ * @module
10
+ */
11
+ /**
12
+ * Creates a `w:pict` element holding VML content, such as a `v:shapetype` followed by the `v:shape` that uses it.
13
+ *
14
+ * ```xml
15
+ * <w:pict><v:shapetype .../><v:shape .../></w:pict>
16
+ * ```
17
+ */
18
+ var createPict = ({ children }) => new docx.BuilderElement({
19
+ name: "w:pict",
20
+ children
21
+ });
22
+ //#endregion
23
+ //#region src/watermarks/vml/vml-values.ts
24
+ /**
25
+ * Converts a boolean into the VML `t`/`f` representation.
26
+ *
27
+ * Undefined values are passed through so that optional attributes are omitted
28
+ * from the generated XML.
29
+ *
30
+ * @param value - The boolean to convert
31
+ * @returns `"t"` for true, `"f"` for false, or `undefined` when no value was given
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * vmlTrueFalse(true); // "t"
36
+ * vmlTrueFalse(false); // "f"
37
+ * vmlTrueFalse(undefined); // undefined
38
+ * ```
39
+ */
40
+ var vmlTrueFalse = (value) => value === void 0 ? void 0 : value ? "t" : "f";
41
+ /**
42
+ * Normalizes a colour for VML colour attributes (ST_ColorType).
43
+ *
44
+ * VML accepts either a named colour (`silver`, `red`, ...) or a hex triplet
45
+ * prefixed with `#`. Hex values are accepted with or without the leading `#`
46
+ * and are always emitted with it so that Word does not mistake them for
47
+ * colour names. Any other value is passed through unchanged.
48
+ *
49
+ * @param value - A named colour, or a 6-digit hex colour with or without `#`
50
+ * @returns The colour formatted for VML
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * vmlColorValue("C0C0C0"); // "#C0C0C0"
55
+ * vmlColorValue("#ff0000"); // "#ff0000"
56
+ * vmlColorValue("silver"); // "silver"
57
+ * ```
58
+ */
59
+ var vmlColorValue = (value) => /^#?[0-9a-fA-F]{6}$/.test(value) ? `#${value.replace(/^#/, "")}` : value;
60
+ /**
61
+ * Formats a fraction as a VML fixed-point value.
62
+ *
63
+ * Several VML attributes (`gain`, `blacklevel`, ...) accept fixed-point
64
+ * numbers where 65536 represents 1.0. These are written with an `f` suffix.
65
+ *
66
+ * @param value - The fraction to convert, where 1 represents 65536
67
+ * @returns The fixed-point representation, e.g. `"19661f"`
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * vmlFixedPoint(0.5); // "32768f"
72
+ * ```
73
+ */
74
+ var vmlFixedPoint = (value) => `${Math.round(value * 65536)}f`;
75
+ //#endregion
76
+ //#region src/watermarks/vml/vml-fill.ts
77
+ /**
78
+ * VML fill module for WordprocessingML documents.
79
+ *
80
+ * Provides functionality for describing how the interior of a VML shape is painted.
81
+ *
82
+ * Reference: http://webapp.docx4java.org/OnlineDemo/ecma376/VML/fill.html
83
+ *
84
+ * @module
85
+ */
86
+ /**
87
+ * Creates a VML fill element.
88
+ *
89
+ * The VML fill element (v:fill) refines the fill of its parent shape, for example
90
+ * to make a watermark semi-transparent.
91
+ *
92
+ * ## XSD Schema
93
+ * ```xml
94
+ * <xsd:complexType name="CT_Fill">
95
+ * <xsd:sequence>
96
+ * <xsd:element ref="o:fill" minOccurs="0"/>
97
+ * </xsd:sequence>
98
+ * <xsd:attributeGroup ref="AG_Id"/>
99
+ * <xsd:attribute name="type" type="ST_FillType" use="optional"/>
100
+ * <xsd:attribute name="on" type="s:ST_TrueFalse" use="optional"/>
101
+ * <xsd:attribute name="color" type="s:ST_ColorType" use="optional"/>
102
+ * <xsd:attribute name="opacity" type="xsd:string" use="optional"/>
103
+ * <xsd:attribute name="color2" type="s:ST_ColorType" use="optional"/>
104
+ * <xsd:attribute name="angle" type="xsd:decimal" use="optional"/>
105
+ * <!-- further attributes omitted -->
106
+ * </xsd:complexType>
107
+ * ```
108
+ *
109
+ * @param options - Configuration options for the fill
110
+ * @returns An XmlComponent representing the v:fill element
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * createVmlFill({ opacity: 0.5 });
115
+ * // <v:fill opacity="0.5"/>
116
+ * ```
117
+ */
118
+ var createVmlFill = ({ on, type, color, color2, opacity, angle } = {}) => new docx.BuilderElement({
119
+ name: "v:fill",
120
+ attributes: {
121
+ on: {
122
+ key: "on",
123
+ value: vmlTrueFalse(on)
124
+ },
125
+ type: {
126
+ key: "type",
127
+ value: type
128
+ },
129
+ color: {
130
+ key: "color",
131
+ value: color
132
+ },
133
+ color2: {
134
+ key: "color2",
135
+ value: color2
136
+ },
137
+ opacity: {
138
+ key: "opacity",
139
+ value: opacity
140
+ },
141
+ angle: {
142
+ key: "angle",
143
+ value: angle
144
+ }
145
+ }
146
+ });
147
+ //#endregion
148
+ //#region src/watermarks/vml/vml-text-path.ts
149
+ /**
150
+ * VML text path module for WordprocessingML documents.
151
+ *
152
+ * A text path renders text along, or stretched into, the geometry of a shape. It is
153
+ * the mechanism behind WordArt and text watermarks.
154
+ *
155
+ * Reference: http://webapp.docx4java.org/OnlineDemo/ecma376/VML/textpath.html
156
+ *
157
+ * @module
158
+ */
159
+ /**
160
+ * Formats a VmlTextPathStyle object into the CSS-like string used by the text path `style` attribute.
161
+ *
162
+ * @param style - The style to format
163
+ * @returns The formatted style, or undefined when no properties were set
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * formatVmlTextPathStyle({ fontFamily: "Calibri", fontSize: 1 });
168
+ * // 'font-family:"Calibri";font-size:1pt'
169
+ * ```
170
+ */
171
+ var formatVmlTextPathStyle = ({ fontFamily, fontSize, fontWeight, fontStyle, textAlign, sameLetterHeights } = {}) => {
172
+ const properties = [
173
+ fontFamily === void 0 ? void 0 : `font-family:"${fontFamily}"`,
174
+ fontSize === void 0 ? void 0 : `font-size:${fontSize}pt`,
175
+ fontWeight === void 0 ? void 0 : `font-weight:${fontWeight}`,
176
+ fontStyle === void 0 ? void 0 : `font-style:${fontStyle}`,
177
+ textAlign === void 0 ? void 0 : `v-text-align:${textAlign}`,
178
+ sameLetterHeights === void 0 ? void 0 : `v-same-letter-heights:${vmlTrueFalse(sameLetterHeights)}`
179
+ ].filter((property) => property !== void 0);
180
+ return properties.length ? properties.join(";") : void 0;
181
+ };
182
+ /**
183
+ * Creates a VML text path element.
184
+ *
185
+ * The VML text path element (v:textpath) renders text using the geometry of its
186
+ * parent shape. On a shape type it declares that shapes of that type carry text; on
187
+ * a shape it supplies the actual text and its styling.
188
+ *
189
+ * ## XSD Schema
190
+ * ```xml
191
+ * <xsd:complexType name="CT_TextPath">
192
+ * <xsd:attributeGroup ref="AG_Id"/>
193
+ * <xsd:attributeGroup ref="AG_Style"/>
194
+ * <xsd:attribute name="on" type="s:ST_TrueFalse" use="optional"/>
195
+ * <xsd:attribute name="fitshape" type="s:ST_TrueFalse" use="optional"/>
196
+ * <xsd:attribute name="fitpath" type="s:ST_TrueFalse" use="optional"/>
197
+ * <xsd:attribute name="trim" type="s:ST_TrueFalse" use="optional"/>
198
+ * <xsd:attribute name="xscale" type="s:ST_TrueFalse" use="optional"/>
199
+ * <xsd:attribute name="string" type="xsd:string" use="optional"/>
200
+ * </xsd:complexType>
201
+ * ```
202
+ *
203
+ * @param options - Configuration options for the text path
204
+ * @returns An XmlComponent representing the v:textpath element
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * createVmlTextPath({ text: "DRAFT", style: { fontFamily: "Calibri", fontSize: 1 } });
209
+ * // <v:textpath style="font-family:&quot;Calibri&quot;;font-size:1pt" string="DRAFT"/>
210
+ * ```
211
+ */
212
+ var createVmlTextPath = ({ on, fitShape, fitPath, trim, xScale, text, style } = {}) => new docx.BuilderElement({
213
+ name: "v:textpath",
214
+ attributes: {
215
+ on: {
216
+ key: "on",
217
+ value: vmlTrueFalse(on)
218
+ },
219
+ fitShape: {
220
+ key: "fitshape",
221
+ value: vmlTrueFalse(fitShape)
222
+ },
223
+ fitPath: {
224
+ key: "fitpath",
225
+ value: vmlTrueFalse(fitPath)
226
+ },
227
+ trim: {
228
+ key: "trim",
229
+ value: vmlTrueFalse(trim)
230
+ },
231
+ xScale: {
232
+ key: "xscale",
233
+ value: vmlTrueFalse(xScale)
234
+ },
235
+ style: {
236
+ key: "style",
237
+ value: formatVmlTextPathStyle(style)
238
+ },
239
+ text: {
240
+ key: "string",
241
+ value: text
242
+ }
243
+ }
244
+ });
245
+ //#endregion
246
+ //#region src/watermarks/vml/vml-formulas.ts
247
+ /**
248
+ * VML formulas module for WordprocessingML documents.
249
+ *
250
+ * Formulas compute the guide values (`@0`, `@1`, ...) that a shape's path and
251
+ * handles refer to, allowing the geometry to respond to adjustment values.
252
+ *
253
+ * Reference: http://webapp.docx4java.org/OnlineDemo/ecma376/VML/formulas.html
254
+ *
255
+ * @module
256
+ */
257
+ /**
258
+ * Creates a single VML formula element.
259
+ *
260
+ * ## XSD Schema
261
+ * ```xml
262
+ * <xsd:complexType name="CT_F">
263
+ * <xsd:attribute name="eqn" type="xsd:string"/>
264
+ * </xsd:complexType>
265
+ * ```
266
+ *
267
+ * @param equation - The equation, e.g. `sum #0 0 10800`
268
+ * @returns An XmlComponent representing the v:f element
269
+ */
270
+ var createVmlFormula = (equation) => new docx.BuilderElement({
271
+ name: "v:f",
272
+ attributes: { equation: {
273
+ key: "eqn",
274
+ value: equation
275
+ } }
276
+ });
277
+ /**
278
+ * Creates a VML formulas element containing one formula per equation.
279
+ *
280
+ * ## XSD Schema
281
+ * ```xml
282
+ * <xsd:complexType name="CT_Formulas">
283
+ * <xsd:sequence>
284
+ * <xsd:element name="f" type="CT_F" minOccurs="0" maxOccurs="unbounded"/>
285
+ * </xsd:sequence>
286
+ * </xsd:complexType>
287
+ * ```
288
+ *
289
+ * @param equations - The equations, in order. Each is referenced by its index as `@n`.
290
+ * @returns An XmlComponent representing the v:formulas element
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * createVmlFormulas(["sum #0 0 10800", "prod #0 2 1"]);
295
+ * // <v:formulas><v:f eqn="sum #0 0 10800"/><v:f eqn="prod #0 2 1"/></v:formulas>
296
+ * ```
297
+ */
298
+ var createVmlFormulas = (equations) => new docx.BuilderElement({
299
+ name: "v:formulas",
300
+ children: equations.map(createVmlFormula)
301
+ });
302
+ //#endregion
303
+ //#region src/watermarks/vml/vml-handles.ts
304
+ /**
305
+ * VML handles module for WordprocessingML documents.
306
+ *
307
+ * Handles are the draggable points that let a user change a shape's adjustment
308
+ * values in an editor.
309
+ *
310
+ * Reference: http://webapp.docx4java.org/OnlineDemo/ecma376/VML/handles.html
311
+ *
312
+ * @module
313
+ */
314
+ /**
315
+ * Creates a single VML handle element.
316
+ *
317
+ * ## XSD Schema
318
+ * ```xml
319
+ * <xsd:complexType name="CT_H">
320
+ * <xsd:attribute name="position" type="xsd:string"/>
321
+ * <xsd:attribute name="polar" type="xsd:string"/>
322
+ * <xsd:attribute name="map" type="xsd:string"/>
323
+ * <xsd:attribute name="invx" type="s:ST_TrueFalse"/>
324
+ * <xsd:attribute name="invy" type="s:ST_TrueFalse"/>
325
+ * <xsd:attribute name="switch" type="s:ST_TrueFalseBlank"/>
326
+ * <xsd:attribute name="xrange" type="xsd:string"/>
327
+ * <xsd:attribute name="yrange" type="xsd:string"/>
328
+ * <xsd:attribute name="radiusrange" type="xsd:string"/>
329
+ * </xsd:complexType>
330
+ * ```
331
+ *
332
+ * @param options - Configuration options for the handle
333
+ * @returns An XmlComponent representing the v:h element
334
+ */
335
+ var createVmlHandle = ({ position, xRange, yRange }) => new docx.BuilderElement({
336
+ name: "v:h",
337
+ attributes: {
338
+ position: {
339
+ key: "position",
340
+ value: position
341
+ },
342
+ xRange: {
343
+ key: "xrange",
344
+ value: xRange
345
+ },
346
+ yRange: {
347
+ key: "yrange",
348
+ value: yRange
349
+ }
350
+ }
351
+ });
352
+ /**
353
+ * Creates a VML handles element containing one handle per option.
354
+ *
355
+ * ## XSD Schema
356
+ * ```xml
357
+ * <xsd:complexType name="CT_Handles">
358
+ * <xsd:sequence>
359
+ * <xsd:element name="h" type="CT_H" minOccurs="0" maxOccurs="unbounded"/>
360
+ * </xsd:sequence>
361
+ * </xsd:complexType>
362
+ * ```
363
+ *
364
+ * @param handles - The handles, in order
365
+ * @returns An XmlComponent representing the v:handles element
366
+ *
367
+ * @example
368
+ * ```typescript
369
+ * createVmlHandles([{ position: "#0,bottomRight", xRange: "6629,14971" }]);
370
+ * // <v:handles><v:h position="#0,bottomRight" xrange="6629,14971"/></v:handles>
371
+ * ```
372
+ */
373
+ var createVmlHandles = (handles) => new docx.BuilderElement({
374
+ name: "v:handles",
375
+ children: handles.map(createVmlHandle)
376
+ });
377
+ //#endregion
378
+ //#region src/watermarks/vml/vml-lock.ts
379
+ /**
380
+ * VML lock module for WordprocessingML documents.
381
+ *
382
+ * A lock prevents particular kinds of edits to a shape in an editor, for example
383
+ * keeping a picture's aspect ratio or stopping WordArt text from being edited.
384
+ *
385
+ * Reference: http://webapp.docx4java.org/OnlineDemo/ecma376/VML/lock.html
386
+ *
387
+ * @module
388
+ */
389
+ /**
390
+ * Creates a VML lock element.
391
+ *
392
+ * ## XSD Schema
393
+ * ```xml
394
+ * <xsd:complexType name="CT_Lock">
395
+ * <xsd:attributeGroup ref="v:AG_Ext"/>
396
+ * <xsd:attribute name="position" type="s:ST_TrueFalse" use="optional"/>
397
+ * <xsd:attribute name="selection" type="s:ST_TrueFalse" use="optional"/>
398
+ * <xsd:attribute name="grouping" type="s:ST_TrueFalse" use="optional"/>
399
+ * <xsd:attribute name="ungrouping" type="s:ST_TrueFalse" use="optional"/>
400
+ * <xsd:attribute name="rotation" type="s:ST_TrueFalse" use="optional"/>
401
+ * <xsd:attribute name="cropping" type="s:ST_TrueFalse" use="optional"/>
402
+ * <xsd:attribute name="verticies" type="s:ST_TrueFalse" use="optional"/>
403
+ * <xsd:attribute name="adjusthandles" type="s:ST_TrueFalse" use="optional"/>
404
+ * <xsd:attribute name="text" type="s:ST_TrueFalse" use="optional"/>
405
+ * <xsd:attribute name="aspectratio" type="s:ST_TrueFalse" use="optional"/>
406
+ * <xsd:attribute name="shapetype" type="s:ST_TrueFalse" use="optional"/>
407
+ * </xsd:complexType>
408
+ * ```
409
+ *
410
+ * @param options - Configuration options for the lock
411
+ * @returns An XmlComponent representing the o:lock element
412
+ *
413
+ * @example
414
+ * ```typescript
415
+ * createVmlLock({ aspectRatio: true });
416
+ * // <o:lock v:ext="edit" aspectratio="t"/>
417
+ * ```
418
+ */
419
+ var createVmlLock = ({ extension = "edit", position, selection, grouping, ungrouping, rotation, cropping, vertices, adjustHandles, text, aspectRatio, shapeType } = {}) => new docx.BuilderElement({
420
+ name: "o:lock",
421
+ attributes: {
422
+ extension: {
423
+ key: "v:ext",
424
+ value: extension
425
+ },
426
+ position: {
427
+ key: "position",
428
+ value: vmlTrueFalse(position)
429
+ },
430
+ selection: {
431
+ key: "selection",
432
+ value: vmlTrueFalse(selection)
433
+ },
434
+ grouping: {
435
+ key: "grouping",
436
+ value: vmlTrueFalse(grouping)
437
+ },
438
+ ungrouping: {
439
+ key: "ungrouping",
440
+ value: vmlTrueFalse(ungrouping)
441
+ },
442
+ rotation: {
443
+ key: "rotation",
444
+ value: vmlTrueFalse(rotation)
445
+ },
446
+ cropping: {
447
+ key: "cropping",
448
+ value: vmlTrueFalse(cropping)
449
+ },
450
+ vertices: {
451
+ key: "verticies",
452
+ value: vmlTrueFalse(vertices)
453
+ },
454
+ adjustHandles: {
455
+ key: "adjusthandles",
456
+ value: vmlTrueFalse(adjustHandles)
457
+ },
458
+ text: {
459
+ key: "text",
460
+ value: vmlTrueFalse(text)
461
+ },
462
+ aspectRatio: {
463
+ key: "aspectratio",
464
+ value: vmlTrueFalse(aspectRatio)
465
+ },
466
+ shapeType: {
467
+ key: "shapetype",
468
+ value: vmlTrueFalse(shapeType)
469
+ }
470
+ }
471
+ });
472
+ //#endregion
473
+ //#region src/watermarks/vml/vml-path.ts
474
+ /**
475
+ * VML path module for WordprocessingML documents.
476
+ *
477
+ * The path element refines the geometry declared on a shape or shape type: which
478
+ * features (text, fill, gradients) the geometry supports and where connectors attach.
479
+ *
480
+ * Reference: http://webapp.docx4java.org/OnlineDemo/ecma376/VML/path.html
481
+ *
482
+ * @module
483
+ */
484
+ /**
485
+ * Creates a VML path element.
486
+ *
487
+ * ## XSD Schema
488
+ * ```xml
489
+ * <xsd:complexType name="CT_Path">
490
+ * <xsd:attributeGroup ref="AG_Id"/>
491
+ * <xsd:attribute name="v" type="xsd:string" use="optional"/>
492
+ * <xsd:attribute name="limo" type="xsd:string" use="optional"/>
493
+ * <xsd:attribute name="textboxrect" type="xsd:string" use="optional"/>
494
+ * <xsd:attribute name="fillok" type="s:ST_TrueFalse" use="optional"/>
495
+ * <xsd:attribute name="strokeok" type="s:ST_TrueFalse" use="optional"/>
496
+ * <xsd:attribute name="shadowok" type="s:ST_TrueFalse" use="optional"/>
497
+ * <xsd:attribute name="arrowok" type="s:ST_TrueFalse" use="optional"/>
498
+ * <xsd:attribute name="gradientshapeok" type="s:ST_TrueFalse" use="optional"/>
499
+ * <xsd:attribute name="textpathok" type="s:ST_TrueFalse" use="optional"/>
500
+ * <xsd:attribute name="insetpenok" type="s:ST_TrueFalse" use="optional"/>
501
+ * <xsd:attribute ref="o:connecttype"/>
502
+ * <xsd:attribute ref="o:connectlocs"/>
503
+ * <xsd:attribute ref="o:connectangles"/>
504
+ * <xsd:attribute ref="o:extrusionok"/>
505
+ * </xsd:complexType>
506
+ * ```
507
+ *
508
+ * @param options - Configuration options for the path
509
+ * @returns An XmlComponent representing the v:path element
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * createVmlPath({ textPathOk: true, connectType: "custom" });
514
+ * // <v:path textpathok="t" o:connecttype="custom"/>
515
+ * ```
516
+ */
517
+ var createVmlPath = ({ value, fillOk, strokeOk, shadowOk, arrowOk, gradientShapeOk, textPathOk, extrusionOk, connectType, connectLocations, connectAngles } = {}) => new docx.BuilderElement({
518
+ name: "v:path",
519
+ attributes: {
520
+ value: {
521
+ key: "v",
522
+ value
523
+ },
524
+ fillOk: {
525
+ key: "fillok",
526
+ value: vmlTrueFalse(fillOk)
527
+ },
528
+ strokeOk: {
529
+ key: "strokeok",
530
+ value: vmlTrueFalse(strokeOk)
531
+ },
532
+ shadowOk: {
533
+ key: "shadowok",
534
+ value: vmlTrueFalse(shadowOk)
535
+ },
536
+ arrowOk: {
537
+ key: "arrowok",
538
+ value: vmlTrueFalse(arrowOk)
539
+ },
540
+ gradientShapeOk: {
541
+ key: "gradientshapeok",
542
+ value: vmlTrueFalse(gradientShapeOk)
543
+ },
544
+ textPathOk: {
545
+ key: "textpathok",
546
+ value: vmlTrueFalse(textPathOk)
547
+ },
548
+ extrusionOk: {
549
+ key: "o:extrusionok",
550
+ value: vmlTrueFalse(extrusionOk)
551
+ },
552
+ connectType: {
553
+ key: "o:connecttype",
554
+ value: connectType
555
+ },
556
+ connectLocations: {
557
+ key: "o:connectlocs",
558
+ value: connectLocations
559
+ },
560
+ connectAngles: {
561
+ key: "o:connectangles",
562
+ value: connectAngles
563
+ }
564
+ }
565
+ });
566
+ //#endregion
567
+ //#region src/watermarks/vml/vml-shape-type.ts
568
+ /**
569
+ * VML shape type module for WordprocessingML documents.
570
+ *
571
+ * A shape type defines reusable geometry (path, formulas, handles and default
572
+ * properties) that shapes reference through their `type` attribute. Word emits a
573
+ * shape type for each kind of VML shape it uses, such as text boxes, WordArt or
574
+ * picture frames.
575
+ *
576
+ * Reference: http://webapp.docx4java.org/OnlineDemo/ecma376/VML/shapetype.html
577
+ *
578
+ * @module
579
+ */
580
+ /**
581
+ * Creates a VML shape type element.
582
+ *
583
+ * The VML shape type element (v:shapetype) declares geometry and defaults that
584
+ * can be shared by several shapes.
585
+ *
586
+ * ## XSD Schema
587
+ * ```xml
588
+ * <xsd:complexType name="CT_Shapetype">
589
+ * <xsd:sequence>
590
+ * <xsd:group ref="EG_ShapeElements" minOccurs="0" maxOccurs="unbounded"/>
591
+ * <xsd:element ref="o:complex" minOccurs="0"/>
592
+ * </xsd:sequence>
593
+ * <xsd:attributeGroup ref="AG_AllCoreAttributes"/>
594
+ * <xsd:attributeGroup ref="AG_AllShapeAttributes"/>
595
+ * <xsd:attributeGroup ref="AG_Adj"/>
596
+ * <xsd:attributeGroup ref="AG_Path"/>
597
+ * <xsd:attribute ref="o:master"/>
598
+ * </xsd:complexType>
599
+ * ```
600
+ *
601
+ * @param options - Configuration options for the shape type
602
+ * @returns An XmlComponent representing the v:shapetype element
603
+ *
604
+ * @example
605
+ * ```typescript
606
+ * const shapeType = createVmlShapeType({
607
+ * id: "_x0000_t136",
608
+ * coordinateSize: "21600,21600",
609
+ * presetShapeType: 136,
610
+ * adjustment: "10800",
611
+ * path: "m@7,l@8,m@5,21600l@6,21600e",
612
+ * });
613
+ * ```
614
+ */
615
+ var createVmlShapeType = ({ id, coordinateSize, presetShapeType, preferRelative, adjustment, path, filled, stroked, children = [] }) => new docx.BuilderElement({
616
+ name: "v:shapetype",
617
+ attributes: {
618
+ id: {
619
+ key: "id",
620
+ value: id
621
+ },
622
+ coordinateSize: {
623
+ key: "coordsize",
624
+ value: coordinateSize
625
+ },
626
+ presetShapeType: {
627
+ key: "o:spt",
628
+ value: presetShapeType
629
+ },
630
+ preferRelative: {
631
+ key: "o:preferrelative",
632
+ value: vmlTrueFalse(preferRelative)
633
+ },
634
+ adjustment: {
635
+ key: "adj",
636
+ value: adjustment
637
+ },
638
+ path: {
639
+ key: "path",
640
+ value: path
641
+ },
642
+ filled: {
643
+ key: "filled",
644
+ value: vmlTrueFalse(filled)
645
+ },
646
+ stroked: {
647
+ key: "stroked",
648
+ value: vmlTrueFalse(stroked)
649
+ }
650
+ },
651
+ children
652
+ });
653
+ //#endregion
654
+ //#region src/watermarks/vml/word-art-shape-type.ts
655
+ /** Identifier of the WordArt (plain text) shape type. Shapes reference it as `#_x0000_t136`. */
656
+ var WORD_ART_SHAPE_TYPE_ID = "_x0000_t136";
657
+ /** Office preset shape number for plain WordArt text. */
658
+ var WORD_ART_PRESET_SHAPE_TYPE = 136;
659
+ /**
660
+ * Creates the WordArt (plain text) shape type as emitted by Microsoft Word.
661
+ *
662
+ * The resulting shape type has the identifier `_x0000_t136`. Shapes using it must
663
+ * set `type: "#_x0000_t136"` and supply a `v:textpath` child carrying the text.
664
+ *
665
+ * @returns An XmlComponent representing the v:shapetype element
666
+ *
667
+ * @example
668
+ * ```typescript
669
+ * createPict({
670
+ * children: [
671
+ * createWordArtShapeType(),
672
+ * createVmlShape({
673
+ * id: "watermark",
674
+ * type: `#${WORD_ART_SHAPE_TYPE_ID}`,
675
+ * children: [createVmlTextPath({ text: "DRAFT" })],
676
+ * }),
677
+ * ],
678
+ * });
679
+ * ```
680
+ */
681
+ var createWordArtShapeType = () => createVmlShapeType({
682
+ id: WORD_ART_SHAPE_TYPE_ID,
683
+ coordinateSize: "21600,21600",
684
+ presetShapeType: WORD_ART_PRESET_SHAPE_TYPE,
685
+ adjustment: "10800",
686
+ path: "m@7,l@8,m@5,21600l@6,21600e",
687
+ children: [
688
+ createVmlFormulas([
689
+ "sum #0 0 10800",
690
+ "prod #0 2 1",
691
+ "sum 21600 0 @1",
692
+ "sum 0 0 @2",
693
+ "sum 21600 0 @3",
694
+ "if @0 @3 0",
695
+ "if @0 21600 @1",
696
+ "if @0 0 @2",
697
+ "if @0 @4 21600",
698
+ "mid @5 @6",
699
+ "mid @8 @5",
700
+ "mid @7 @8",
701
+ "mid @6 @7",
702
+ "sum @6 0 @5"
703
+ ]),
704
+ createVmlPath({
705
+ textPathOk: true,
706
+ connectType: "custom",
707
+ connectLocations: "@9,0;@10,10800;@11,21600;@12,10800",
708
+ connectAngles: "270,180,90,0"
709
+ }),
710
+ createVmlTextPath({
711
+ on: true,
712
+ fitShape: true
713
+ }),
714
+ createVmlHandles([{
715
+ position: "#0,bottomRight",
716
+ xRange: "6629,14971"
717
+ }]),
718
+ createVmlLock({
719
+ text: true,
720
+ shapeType: true
721
+ })
722
+ ]
723
+ });
724
+ //#endregion
725
+ //#region src/watermarks/watermark-shape-style.ts
726
+ /**
727
+ * Z-order used by Word for watermarks. Negative values place the shape behind the text.
728
+ */
729
+ var WATERMARK_Z_INDEX = -251657216;
730
+ /**
731
+ * Builds the VML shape style shared by watermarks.
732
+ *
733
+ * The shape is absolutely positioned, centred horizontally and vertically
734
+ * relative to the page margins, and placed behind the document text.
735
+ *
736
+ * @param options - Size and rotation of the watermark
737
+ * @returns The VML shape style
738
+ *
739
+ * @example
740
+ * ```typescript
741
+ * createWatermarkShapeStyle({ width: 527.85, height: 131.95, rotation: 315 });
742
+ * ```
743
+ */
744
+ var createWatermarkShapeStyle = ({ width, height, rotation }) => ({
745
+ position: "absolute",
746
+ marginLeft: 0,
747
+ marginTop: 0,
748
+ width: `${width}pt`,
749
+ height: `${height}pt`,
750
+ rotation: rotation || void 0,
751
+ zIndex: WATERMARK_Z_INDEX,
752
+ positionHorizontal: "center",
753
+ positionHorizontalRelative: "margin",
754
+ positionVertical: "center",
755
+ positionVerticalRelative: "margin"
756
+ });
757
+ //#endregion
758
+ //#region src/watermarks/text-watermark.ts
759
+ /**
760
+ * Text watermark module for WordprocessingML documents.
761
+ *
762
+ * A text watermark is faint text, such as "DRAFT" or "CONFIDENTIAL", drawn behind
763
+ * the content of every page. Word implements it as a WordArt shape placed in the
764
+ * page header, and this module produces the same markup.
765
+ *
766
+ * Reference: https://support.microsoft.com/en-us/office/insert-a-watermark-c0ec3d5a-6f3e-4f3c-a8b0-9d9a6f56d3fd
767
+ *
768
+ * @module
769
+ */
770
+ /**
771
+ * Prefix Word gives to text watermark shapes. Word's "Remove Watermark"
772
+ * command finds watermarks by this prefix.
773
+ */
774
+ var TEXT_WATERMARK_ID_PREFIX = "PowerPlusWaterMarkObject";
775
+ /** Word's default watermark font. */
776
+ var DEFAULT_FONT = "Calibri";
777
+ /** Word's default watermark colour. */
778
+ var DEFAULT_COLOR = "silver";
779
+ /** Word's default "semitransparent" watermark opacity. */
780
+ var DEFAULT_OPACITY = .5;
781
+ /** Width Word gives an automatically sized watermark, in points. */
782
+ var DEFAULT_WIDTH = 527.85;
783
+ /** Rotation Word applies to a diagonal watermark, in degrees clockwise. */
784
+ var DIAGONAL_ROTATION = 315;
785
+ /**
786
+ * Font size written for automatically sized text. Word stretches the text to
787
+ * fill the shape regardless of the font size, and writes 1pt to mean "auto".
788
+ */
789
+ var AUTO_FONT_SIZE = 1;
790
+ /**
791
+ * Approximate width of an uppercase letter relative to the height of the shape,
792
+ * used to derive a default shape height that keeps the letters in proportion.
793
+ */
794
+ var CHARACTER_ASPECT_RATIO = .8;
795
+ /** Approximate width of a space relative to the height of the shape. */
796
+ var SPACE_ASPECT_RATIO = .35;
797
+ /**
798
+ * Estimates a shape height that keeps the text in proportion for the given width.
799
+ *
800
+ * Word stretches watermark text to fill the shape, so the shape's aspect ratio
801
+ * must roughly match the text's. Font metrics are not available here, so the
802
+ * width of each character is approximated as a fraction of the height.
803
+ *
804
+ * @param text - The watermark text
805
+ * @param width - The width of the shape in points
806
+ * @returns The estimated height in points, never larger than the width
807
+ */
808
+ var estimateHeight = (text, width) => {
809
+ const aspectRatio = [...text].reduce((total, character) => total + (character === " " ? SPACE_ASPECT_RATIO : CHARACTER_ASPECT_RATIO), 0);
810
+ return Math.round(width / Math.max(aspectRatio, 1) * 100) / 100;
811
+ };
812
+ /**
813
+ * Represents a text watermark in a WordprocessingML document.
814
+ *
815
+ * TextWatermark is an inline element that belongs inside a paragraph, and the
816
+ * paragraph belongs in a header so that the watermark repeats on every page of
817
+ * the section. It renders as a WordArt shape centred on the page behind the
818
+ * document text, exactly as Word's Design > Watermark command does, so Word
819
+ * recognizes it and can remove or replace it through that command.
820
+ *
821
+ * @publicApi
822
+ *
823
+ * ## XSD Schema
824
+ * The watermark combines several elements:
825
+ * - w:r (run container)
826
+ * - w:pict (picture element containing VML)
827
+ * - v:shapetype (WordArt shape type definition)
828
+ * - v:shape (the positioned WordArt shape)
829
+ * - v:fill (opacity)
830
+ * - v:textpath (the text and its font)
831
+ *
832
+ * @example
833
+ * ```typescript
834
+ * new Document({
835
+ * sections: [
836
+ * {
837
+ * headers: {
838
+ * default: new Header({
839
+ * children: [new Paragraph({ children: [new TextWatermark({ text: "DRAFT" })] })],
840
+ * }),
841
+ * },
842
+ * children: [new Paragraph("Body text")],
843
+ * },
844
+ * ],
845
+ * });
846
+ *
847
+ * // Customised watermark
848
+ * new TextWatermark({
849
+ * text: "CONFIDENTIAL",
850
+ * font: "Arial",
851
+ * color: "FF0000",
852
+ * opacity: 0.3,
853
+ * layout: "horizontal",
854
+ * });
855
+ * ```
856
+ */
857
+ var TextWatermark = class extends docx.XmlComponent {
858
+ constructor({ text, font = DEFAULT_FONT, fontSize = AUTO_FONT_SIZE, bold, italics, color = DEFAULT_COLOR, opacity = DEFAULT_OPACITY, layout = "diagonal", rotation = layout === "diagonal" ? DIAGONAL_ROTATION : 0, width = DEFAULT_WIDTH, height = estimateHeight(text, width) }) {
859
+ super("w:r");
860
+ this.root.push(createPict({ children: [createWordArtShapeType(), (0, docx.createVmlShape)({
861
+ id: `${TEXT_WATERMARK_ID_PREFIX}${(0, docx.uniqueId)()}`,
862
+ type: `#${WORD_ART_SHAPE_TYPE_ID}`,
863
+ style: createWatermarkShapeStyle({
864
+ width,
865
+ height,
866
+ rotation
867
+ }),
868
+ allowInCell: false,
869
+ fillColor: vmlColorValue(color),
870
+ stroked: false,
871
+ children: [createVmlFill({ opacity }), createVmlTextPath({
872
+ text,
873
+ style: {
874
+ fontFamily: font,
875
+ fontSize,
876
+ fontWeight: bold ? "bold" : void 0,
877
+ fontStyle: italics ? "italic" : void 0
878
+ }
879
+ })]
880
+ })] }));
881
+ }
882
+ };
883
+ //#endregion
884
+ //#region src/watermarks/vml/vml-stroke.ts
885
+ /**
886
+ * VML stroke module for WordprocessingML documents.
887
+ *
888
+ * Provides functionality for describing how the outline of a VML shape is drawn.
889
+ *
890
+ * Reference: http://webapp.docx4java.org/OnlineDemo/ecma376/VML/stroke.html
891
+ *
892
+ * @module
893
+ */
894
+ /**
895
+ * Creates a VML stroke element.
896
+ *
897
+ * The VML stroke element (v:stroke) refines the outline of its parent shape.
898
+ *
899
+ * ## XSD Schema
900
+ * ```xml
901
+ * <xsd:complexType name="CT_Stroke">
902
+ * <xsd:sequence>
903
+ * <xsd:element ref="o:left" minOccurs="0"/>
904
+ * <xsd:element ref="o:top" minOccurs="0"/>
905
+ * <xsd:element ref="o:right" minOccurs="0"/>
906
+ * <xsd:element ref="o:bottom" minOccurs="0"/>
907
+ * <xsd:element ref="o:column" minOccurs="0"/>
908
+ * </xsd:sequence>
909
+ * <xsd:attributeGroup ref="AG_Id"/>
910
+ * <xsd:attributeGroup ref="AG_StrokeAttributes"/>
911
+ * </xsd:complexType>
912
+ *
913
+ * <xsd:attributeGroup name="AG_StrokeAttributes">
914
+ * <xsd:attribute name="on" type="s:ST_TrueFalse" use="optional"/>
915
+ * <xsd:attribute name="weight" type="xsd:string" use="optional"/>
916
+ * <xsd:attribute name="color" type="s:ST_ColorType" use="optional"/>
917
+ * <xsd:attribute name="opacity" type="xsd:string" use="optional"/>
918
+ * <xsd:attribute name="joinstyle" type="ST_StrokeJoinStyle" use="optional"/>
919
+ * <!-- further attributes omitted -->
920
+ * </xsd:attributeGroup>
921
+ * ```
922
+ *
923
+ * @param options - Configuration options for the stroke
924
+ * @returns An XmlComponent representing the v:stroke element
925
+ *
926
+ * @example
927
+ * ```typescript
928
+ * createVmlStroke({ joinStyle: "miter" });
929
+ * // <v:stroke joinstyle="miter"/>
930
+ * ```
931
+ */
932
+ var createVmlStroke = ({ on, weight, color, opacity, joinStyle } = {}) => new docx.BuilderElement({
933
+ name: "v:stroke",
934
+ attributes: {
935
+ on: {
936
+ key: "on",
937
+ value: vmlTrueFalse(on)
938
+ },
939
+ weight: {
940
+ key: "weight",
941
+ value: weight
942
+ },
943
+ color: {
944
+ key: "color",
945
+ value: color
946
+ },
947
+ opacity: {
948
+ key: "opacity",
949
+ value: opacity
950
+ },
951
+ joinStyle: {
952
+ key: "joinstyle",
953
+ value: joinStyle
954
+ }
955
+ }
956
+ });
957
+ //#endregion
958
+ //#region src/watermarks/vml/picture-frame-shape-type.ts
959
+ /** Identifier of the picture frame shape type. Shapes reference it as `#_x0000_t75`. */
960
+ var PICTURE_FRAME_SHAPE_TYPE_ID = "_x0000_t75";
961
+ /** Office preset shape number for a picture frame. */
962
+ var PICTURE_FRAME_PRESET_SHAPE_TYPE = 75;
963
+ /**
964
+ * Creates the picture frame shape type as emitted by Microsoft Word.
965
+ *
966
+ * The resulting shape type has the identifier `_x0000_t75`. Shapes using it must
967
+ * set `type: "#_x0000_t75"` and supply a `v:imagedata` child referencing the image.
968
+ *
969
+ * @returns An XmlComponent representing the v:shapetype element
970
+ *
971
+ * @example
972
+ * ```typescript
973
+ * createPict({
974
+ * children: [
975
+ * createPictureFrameShapeType(),
976
+ * createVmlShape({
977
+ * id: "picture",
978
+ * type: `#${PICTURE_FRAME_SHAPE_TYPE_ID}`,
979
+ * children: [createVmlImageData({ relationshipId: "rId1" })],
980
+ * }),
981
+ * ],
982
+ * });
983
+ * ```
984
+ */
985
+ var createPictureFrameShapeType = () => createVmlShapeType({
986
+ id: PICTURE_FRAME_SHAPE_TYPE_ID,
987
+ coordinateSize: "21600,21600",
988
+ presetShapeType: PICTURE_FRAME_PRESET_SHAPE_TYPE,
989
+ preferRelative: true,
990
+ path: "m@4@5l@4@11@9@11@9@5xe",
991
+ filled: false,
992
+ stroked: false,
993
+ children: [
994
+ createVmlStroke({ joinStyle: "miter" }),
995
+ createVmlFormulas([
996
+ "if lineDrawn pixelLineWidth 0",
997
+ "sum @0 1 0",
998
+ "sum 0 0 @1",
999
+ "prod @2 1 2",
1000
+ "prod @3 21600 pixelWidth",
1001
+ "prod @3 21600 pixelHeight",
1002
+ "sum @0 0 1",
1003
+ "prod @6 1 2",
1004
+ "prod @7 21600 pixelWidth",
1005
+ "sum @8 21600 0",
1006
+ "prod @7 21600 pixelHeight",
1007
+ "sum @10 21600 0"
1008
+ ]),
1009
+ createVmlPath({
1010
+ extrusionOk: false,
1011
+ gradientShapeOk: true,
1012
+ connectType: "rect"
1013
+ }),
1014
+ createVmlLock({ aspectRatio: true })
1015
+ ]
1016
+ });
1017
+ //#endregion
1018
+ //#region src/watermarks/vml/vml-image-data.ts
1019
+ /**
1020
+ * VML image data module for WordprocessingML documents.
1021
+ *
1022
+ * Image data attaches a picture to a VML shape and describes how it should be
1023
+ * adjusted, for example washed out for use as a watermark.
1024
+ *
1025
+ * Reference: http://webapp.docx4java.org/OnlineDemo/ecma376/VML/imagedata.html
1026
+ *
1027
+ * @module
1028
+ */
1029
+ /**
1030
+ * Creates a VML image data element.
1031
+ *
1032
+ * The VML image data element (v:imagedata) references an embedded picture through
1033
+ * a relationship and applies colour adjustments to it. Adjustment values are written
1034
+ * in VML's fixed-point notation where 65536 represents 1.0.
1035
+ *
1036
+ * ## XSD Schema
1037
+ * ```xml
1038
+ * <xsd:complexType name="CT_ImageData">
1039
+ * <xsd:attributeGroup ref="AG_Id"/>
1040
+ * <xsd:attributeGroup ref="AG_ImageAttributes"/>
1041
+ * <xsd:attributeGroup ref="AG_Chromakey"/>
1042
+ * <xsd:attribute ref="o:title"/>
1043
+ * <xsd:attribute ref="r:id"/>
1044
+ * <!-- further attributes omitted -->
1045
+ * </xsd:complexType>
1046
+ *
1047
+ * <xsd:attributeGroup name="AG_ImageAttributes">
1048
+ * <xsd:attribute name="src" type="xsd:string" use="optional"/>
1049
+ * <xsd:attribute name="cropleft" type="xsd:string" use="optional"/>
1050
+ * <xsd:attribute name="croptop" type="xsd:string" use="optional"/>
1051
+ * <xsd:attribute name="cropright" type="xsd:string" use="optional"/>
1052
+ * <xsd:attribute name="cropbottom" type="xsd:string" use="optional"/>
1053
+ * <xsd:attribute name="gain" type="xsd:string" use="optional"/>
1054
+ * <xsd:attribute name="blacklevel" type="xsd:string" use="optional"/>
1055
+ * <xsd:attribute name="gamma" type="xsd:string" use="optional"/>
1056
+ * <xsd:attribute name="grayscale" type="s:ST_TrueFalse" use="optional"/>
1057
+ * <xsd:attribute name="bilevel" type="s:ST_TrueFalse" use="optional"/>
1058
+ * </xsd:attributeGroup>
1059
+ * ```
1060
+ *
1061
+ * @param options - Configuration options for the image data
1062
+ * @returns An XmlComponent representing the v:imagedata element
1063
+ *
1064
+ * @example
1065
+ * ```typescript
1066
+ * createVmlImageData({ relationshipId: "rId1", title: "logo", gain: 0.3, blackLevel: 0.35 });
1067
+ * // <v:imagedata r:id="rId1" o:title="logo" gain="19661f" blacklevel="22938f"/>
1068
+ * ```
1069
+ */
1070
+ var createVmlImageData = ({ relationshipId, title, gain, blackLevel, gamma, grayscale, biLevel, chromaKey } = {}) => new docx.BuilderElement({
1071
+ name: "v:imagedata",
1072
+ attributes: {
1073
+ relationshipId: {
1074
+ key: "r:id",
1075
+ value: relationshipId
1076
+ },
1077
+ title: {
1078
+ key: "o:title",
1079
+ value: title
1080
+ },
1081
+ gain: {
1082
+ key: "gain",
1083
+ value: gain === void 0 ? void 0 : vmlFixedPoint(gain)
1084
+ },
1085
+ blackLevel: {
1086
+ key: "blacklevel",
1087
+ value: blackLevel === void 0 ? void 0 : vmlFixedPoint(blackLevel)
1088
+ },
1089
+ gamma: {
1090
+ key: "gamma",
1091
+ value: gamma === void 0 ? void 0 : vmlFixedPoint(gamma)
1092
+ },
1093
+ grayscale: {
1094
+ key: "grayscale",
1095
+ value: vmlTrueFalse(grayscale)
1096
+ },
1097
+ biLevel: {
1098
+ key: "bilevel",
1099
+ value: vmlTrueFalse(biLevel)
1100
+ },
1101
+ chromaKey: {
1102
+ key: "chromakey",
1103
+ value: chromaKey
1104
+ }
1105
+ }
1106
+ });
1107
+ //#endregion
1108
+ //#region \0@oxc-project+runtime@0.150.0/helpers/esm/typeof.js
1109
+ function _typeof(o) {
1110
+ "@babel/helpers - typeof";
1111
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
1112
+ return typeof o;
1113
+ } : function(o) {
1114
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
1115
+ }, _typeof(o);
1116
+ }
1117
+ //#endregion
1118
+ //#region \0@oxc-project+runtime@0.150.0/helpers/esm/toPrimitive.js
1119
+ function toPrimitive(t, r) {
1120
+ if ("object" != _typeof(t) || !t) return t;
1121
+ var e = t[Symbol.toPrimitive];
1122
+ if (void 0 !== e) {
1123
+ var i = e.call(t, r || "default");
1124
+ if ("object" != _typeof(i)) return i;
1125
+ throw new TypeError("@@toPrimitive must return a primitive value.");
1126
+ }
1127
+ return ("string" === r ? String : Number)(t);
1128
+ }
1129
+ //#endregion
1130
+ //#region \0@oxc-project+runtime@0.150.0/helpers/esm/toPropertyKey.js
1131
+ function toPropertyKey(t) {
1132
+ var i = toPrimitive(t, "string");
1133
+ return "symbol" == _typeof(i) ? i : i + "";
1134
+ }
1135
+ //#endregion
1136
+ //#region \0@oxc-project+runtime@0.150.0/helpers/esm/defineProperty.js
1137
+ function _defineProperty(e, r, t) {
1138
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
1139
+ value: t,
1140
+ enumerable: !0,
1141
+ configurable: !0,
1142
+ writable: !0
1143
+ }) : e[r] = t, e;
1144
+ }
1145
+ //#endregion
1146
+ //#region src/watermarks/image-watermark.ts
1147
+ /**
1148
+ * Image watermark module for WordprocessingML documents.
1149
+ *
1150
+ * An image watermark is a picture, typically a logo, drawn faintly behind the
1151
+ * content of every page. Word implements it as a legacy picture shape placed in the
1152
+ * page header, and this module produces the same markup.
1153
+ *
1154
+ * Reference: https://support.microsoft.com/en-us/office/insert-a-watermark-c0ec3d5a-6f3e-4f3c-a8b0-9d9a6f56d3fd
1155
+ *
1156
+ * @module
1157
+ */
1158
+ /**
1159
+ * Prefix Word gives to picture watermark shapes. Word's "Remove Watermark"
1160
+ * command finds watermarks by this prefix.
1161
+ */
1162
+ var IMAGE_WATERMARK_ID_PREFIX = "WordPictureWatermark";
1163
+ /** Brightness multiplier Word applies for its "washout" effect. */
1164
+ var WASHOUT_GAIN = .3;
1165
+ /** Black level Word applies for its "washout" effect. */
1166
+ var WASHOUT_BLACK_LEVEL = .35;
1167
+ /** Number of English Metric Units in one pixel at 96 dpi. */
1168
+ var EMUS_PER_PIXEL = 9525;
1169
+ /** Number of points in one pixel at 96 dpi. */
1170
+ var POINTS_PER_PIXEL = .75;
1171
+ /**
1172
+ * Converts a pixel measurement into points, rounded to two decimal places.
1173
+ *
1174
+ * @param pixels - The measurement in pixels
1175
+ * @returns The measurement in points
1176
+ */
1177
+ var pixelsToPoints = (pixels) => Math.round(pixels * POINTS_PER_PIXEL * 100) / 100;
1178
+ /**
1179
+ * Represents an image watermark in a WordprocessingML document.
1180
+ *
1181
+ * ImageWatermark is an inline element that belongs inside a paragraph, and the
1182
+ * paragraph belongs in a header so that the watermark repeats on every page of
1183
+ * the section. It renders as a picture shape centred on the page behind the
1184
+ * document text, exactly as Word's Design > Watermark command does, so Word
1185
+ * recognizes it and can remove or replace it through that command.
1186
+ *
1187
+ * The image is registered with the document's media collection during
1188
+ * serialization and linked from the header through a relationship, in the same
1189
+ * way as an ImageRun.
1190
+ *
1191
+ * @publicApi
1192
+ *
1193
+ * ## XSD Schema
1194
+ * The watermark combines several elements:
1195
+ * - w:r (run container)
1196
+ * - w:pict (picture element containing VML)
1197
+ * - v:shapetype (picture frame shape type definition)
1198
+ * - v:shape (the positioned picture shape)
1199
+ * - v:imagedata (the image reference and washout adjustments)
1200
+ *
1201
+ * @example
1202
+ * ```typescript
1203
+ * new Document({
1204
+ * sections: [
1205
+ * {
1206
+ * headers: {
1207
+ * default: new Header({
1208
+ * children: [
1209
+ * new Paragraph({
1210
+ * children: [
1211
+ * new ImageWatermark({
1212
+ * type: "png",
1213
+ * data: fs.readFileSync("./logo.png"),
1214
+ * transformation: { width: 400, height: 400 },
1215
+ * }),
1216
+ * ],
1217
+ * }),
1218
+ * ],
1219
+ * }),
1220
+ * },
1221
+ * children: [new Paragraph("Body text")],
1222
+ * },
1223
+ * ],
1224
+ * });
1225
+ * ```
1226
+ */
1227
+ var ImageWatermark = class extends docx.XmlComponent {
1228
+ constructor({ type, data, transformation, washout = true, title }) {
1229
+ super("w:r");
1230
+ _defineProperty(this, "mediaData", void 0);
1231
+ const fileName = `${(0, docx.hashedId)(data)}.${type}`;
1232
+ this.mediaData = {
1233
+ type,
1234
+ data: (0, docx.standardizeData)(data),
1235
+ fileName,
1236
+ transformation: {
1237
+ pixels: {
1238
+ x: Math.round(transformation.width),
1239
+ y: Math.round(transformation.height)
1240
+ },
1241
+ emus: {
1242
+ x: Math.round(transformation.width * EMUS_PER_PIXEL),
1243
+ y: Math.round(transformation.height * EMUS_PER_PIXEL)
1244
+ }
1245
+ }
1246
+ };
1247
+ this.root.push(createPict({ children: [createPictureFrameShapeType(), (0, docx.createVmlShape)({
1248
+ id: `${IMAGE_WATERMARK_ID_PREFIX}${(0, docx.uniqueId)()}`,
1249
+ type: `#${PICTURE_FRAME_SHAPE_TYPE_ID}`,
1250
+ style: createWatermarkShapeStyle({
1251
+ width: pixelsToPoints(transformation.width),
1252
+ height: pixelsToPoints(transformation.height)
1253
+ }),
1254
+ allowInCell: false,
1255
+ children: [createVmlImageData({
1256
+ relationshipId: `rId{${fileName}}`,
1257
+ title,
1258
+ gain: washout ? WASHOUT_GAIN : void 0,
1259
+ blackLevel: washout ? WASHOUT_BLACK_LEVEL : void 0
1260
+ })]
1261
+ })] }));
1262
+ }
1263
+ prepForXml(context) {
1264
+ context.file.Media.addImage(this.mediaData.fileName, this.mediaData);
1265
+ return super.prepForXml(context);
1266
+ }
1267
+ };
1268
+ //#endregion
1269
+ exports.ImageWatermark = ImageWatermark;
1270
+ exports.TextWatermark = TextWatermark;
1271
+ });