docx 9.7.2 → 9.8.1

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