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