@json-to-office/shared-docx 0.38.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/{chunk-ZC2I7CTZ.js → chunk-45I2NASU.js} +5 -3
  2. package/dist/{chunk-ZC2I7CTZ.js.map → chunk-45I2NASU.js.map} +1 -1
  3. package/dist/chunk-5KOKA5GY.js +687 -0
  4. package/dist/chunk-5KOKA5GY.js.map +1 -0
  5. package/dist/{chunk-PMZEVOBL.js → chunk-6B3LHADB.js} +2 -2
  6. package/dist/{chunk-XR7ZEDXZ.js → chunk-6HFF6XZN.js} +50 -6
  7. package/dist/chunk-6HFF6XZN.js.map +1 -0
  8. package/dist/{chunk-IU2F2FYO.js → chunk-6YMJWMEC.js} +34 -18
  9. package/dist/chunk-6YMJWMEC.js.map +1 -0
  10. package/dist/{chunk-JF5ZJQNR.js → chunk-A2K66URO.js} +47 -149
  11. package/dist/chunk-A2K66URO.js.map +1 -0
  12. package/dist/{chunk-LATN6QG6.js → chunk-BBFR3RRN.js} +45 -8
  13. package/dist/chunk-BBFR3RRN.js.map +1 -0
  14. package/dist/{chunk-W523ZTYH.js → chunk-LBXOAXMG.js} +6 -6
  15. package/dist/{chunk-E5EWXZWO.js → chunk-MYLVUQCN.js} +2 -2
  16. package/dist/chunk-OP5PCDNN.js +1272 -0
  17. package/dist/chunk-OP5PCDNN.js.map +1 -0
  18. package/dist/{chunk-HPZPUB6J.js → chunk-TODYYVZ4.js} +2 -2
  19. package/dist/chunk-VX2J2KWA.js +465 -0
  20. package/dist/chunk-VX2J2KWA.js.map +1 -0
  21. package/dist/index.d.ts +12 -2
  22. package/dist/index.js +57 -25
  23. package/dist/index.js.map +1 -1
  24. package/dist/schemas/api.js +7 -5
  25. package/dist/schemas/component-defaults.js +2 -1
  26. package/dist/schemas/component-registry.d.ts +10 -2
  27. package/dist/schemas/component-registry.js +5 -3
  28. package/dist/schemas/components.d.ts +1092 -4
  29. package/dist/schemas/components.js +72 -26
  30. package/dist/schemas/document.js +8 -6
  31. package/dist/schemas/export.d.ts +8 -2
  32. package/dist/schemas/export.js +6 -4
  33. package/dist/schemas/generator.js +6 -4
  34. package/dist/schemas/renderer.d.ts +30 -0
  35. package/dist/schemas/renderer.js +17 -0
  36. package/dist/schemas/renderer.js.map +1 -0
  37. package/dist/schemas/theme.js +3 -2
  38. package/dist/validation/unified/index.js +8 -6
  39. package/package.json +2 -2
  40. package/dist/chunk-2YUAD26Q.js +0 -1718
  41. package/dist/chunk-2YUAD26Q.js.map +0 -1
  42. package/dist/chunk-IU2F2FYO.js.map +0 -1
  43. package/dist/chunk-JF5ZJQNR.js.map +0 -1
  44. package/dist/chunk-LATN6QG6.js.map +0 -1
  45. package/dist/chunk-XR7ZEDXZ.js.map +0 -1
  46. /package/dist/{chunk-PMZEVOBL.js.map → chunk-6B3LHADB.js.map} +0 -0
  47. /package/dist/{chunk-W523ZTYH.js.map → chunk-LBXOAXMG.js.map} +0 -0
  48. /package/dist/{chunk-E5EWXZWO.js.map → chunk-MYLVUQCN.js.map} +0 -0
  49. /package/dist/{chunk-HPZPUB6J.js.map → chunk-TODYYVZ4.js.map} +0 -0
@@ -0,0 +1,687 @@
1
+ import {
2
+ AlignmentSchema,
3
+ FloatingPropertiesSchema,
4
+ SpacingSchema
5
+ } from "./chunk-VX2J2KWA.js";
6
+
7
+ // src/schemas/components/visual.ts
8
+ import { Type as Type2 } from "@sinclair/typebox";
9
+ import {
10
+ MIN_VISUAL_DPI,
11
+ MAX_VISUAL_DPI,
12
+ DEFAULT_VISUAL_DPI
13
+ } from "@json-to-office/shared";
14
+ import { PptxSlideContentSchema } from "@json-to-office/shared/schemas/slide-content";
15
+
16
+ // src/schemas/components/visual-native.ts
17
+ import { Type } from "@sinclair/typebox";
18
+ import { ShapeTypeSchema } from "@json-to-office/shared/schemas/slide-content";
19
+ var NativeVisualColorSchema = Type.String({
20
+ pattern: "^(#?[0-9A-Fa-f]{6}|[a-zA-Z][a-zA-Z0-9]*)$",
21
+ description: 'Hex colour ("#0F172A" or "0F172A") or a docx theme colour name (e.g. "primary")'
22
+ });
23
+ var SIGNED_PERCENT_PATTERN = "^-?\\d+(\\.\\d+)?%$";
24
+ var PERCENT_PATTERN = "^\\d+(\\.\\d+)?%$";
25
+ var NativeVisualOffsetSchema = Type.Union(
26
+ [
27
+ Type.Number({ description: "Inches from the canvas origin" }),
28
+ Type.String({
29
+ pattern: SIGNED_PERCENT_PATTERN,
30
+ description: 'Percentage of the canvas extent on this axis, e.g. "25%"'
31
+ })
32
+ ],
33
+ { description: "Position in inches (number) or as a canvas percentage" }
34
+ );
35
+ var NativeVisualExtentSchema = Type.Union(
36
+ [
37
+ Type.Number({ minimum: 0, description: "Size in inches" }),
38
+ Type.String({
39
+ pattern: PERCENT_PATTERN,
40
+ description: 'Percentage of the canvas extent on this axis, e.g. "50%"'
41
+ })
42
+ ],
43
+ { description: "Size in inches (number) or as a canvas percentage" }
44
+ );
45
+ var FrameProps = {
46
+ x: Type.Optional(NativeVisualOffsetSchema),
47
+ y: Type.Optional(NativeVisualOffsetSchema),
48
+ w: Type.Optional(NativeVisualExtentSchema),
49
+ h: Type.Optional(NativeVisualExtentSchema),
50
+ rotate: Type.Optional(
51
+ Type.Number({ description: "Clockwise rotation in degrees" })
52
+ )
53
+ };
54
+ var NativeVisualUnderlineSchema = Type.Union(
55
+ [
56
+ Type.Boolean({ description: "Single underline in the text colour" }),
57
+ Type.Object(
58
+ {
59
+ style: Type.Optional(
60
+ Type.Union(
61
+ [
62
+ Type.Literal("sng"),
63
+ Type.Literal("dbl"),
64
+ Type.Literal("dash"),
65
+ Type.Literal("dotted")
66
+ ],
67
+ { description: 'Underline style (default "sng")' }
68
+ )
69
+ ),
70
+ color: Type.Optional(NativeVisualColorSchema)
71
+ },
72
+ { additionalProperties: false }
73
+ )
74
+ ],
75
+ { description: "Underline: true for a single line, or a style/colour object" }
76
+ );
77
+ var InlineTextProps = {
78
+ fontFace: Type.Optional(Type.String({ description: "Font family name" })),
79
+ fontSize: Type.Optional(
80
+ Type.Number({ minimum: 1, description: "Font size in points" })
81
+ ),
82
+ bold: Type.Optional(Type.Boolean()),
83
+ italic: Type.Optional(Type.Boolean())
84
+ };
85
+ var NativeVisualTextRunSchema = Type.Object(
86
+ {
87
+ text: Type.String({ description: "Run text" }),
88
+ color: Type.Optional(NativeVisualColorSchema),
89
+ ...InlineTextProps,
90
+ underline: Type.Optional(NativeVisualUnderlineSchema),
91
+ strike: Type.Optional(Type.Boolean({ description: "Strikethrough" })),
92
+ breakLine: Type.Optional(
93
+ Type.Boolean({ description: "Start a new line after this run" })
94
+ )
95
+ },
96
+ {
97
+ additionalProperties: false,
98
+ description: "A formatted run inside a native visual text element"
99
+ }
100
+ );
101
+ var NativeVisualTextSegmentSchema = Type.Object(
102
+ {
103
+ text: Type.String({ description: "Segment text" }),
104
+ color: Type.Optional(NativeVisualColorSchema),
105
+ ...InlineTextProps,
106
+ breakLine: Type.Optional(
107
+ Type.Boolean({ description: "Start a new line after this segment" })
108
+ )
109
+ },
110
+ {
111
+ additionalProperties: false,
112
+ description: "A formatted segment of a native visual shape\u2019s text"
113
+ }
114
+ );
115
+ var NativeVisualFillSchema = Type.Object(
116
+ {
117
+ color: Type.Optional(NativeVisualColorSchema),
118
+ transparency: Type.Optional(
119
+ Type.Number({
120
+ minimum: 0,
121
+ maximum: 100,
122
+ description: "Fill transparency, 0 (opaque) to 100 (invisible)"
123
+ })
124
+ )
125
+ },
126
+ {
127
+ additionalProperties: false,
128
+ description: "Solid fill. Omit the whole property for no fill; gradients and patterns are raster-only."
129
+ }
130
+ );
131
+ var NativeVisualLineSchema = Type.Object(
132
+ {
133
+ color: Type.Optional(NativeVisualColorSchema),
134
+ width: Type.Optional(
135
+ Type.Number({ minimum: 0, description: "Outline width in points" })
136
+ ),
137
+ dashType: Type.Optional(
138
+ Type.Union(
139
+ [
140
+ Type.Literal("solid"),
141
+ Type.Literal("dash"),
142
+ Type.Literal("dot"),
143
+ Type.Literal("dashDot")
144
+ ],
145
+ { description: 'Outline dash pattern (default "solid")' }
146
+ )
147
+ )
148
+ },
149
+ { additionalProperties: false, description: "Shape outline" }
150
+ );
151
+ var NativeVisualAlignmentSchema = Type.Union(
152
+ [
153
+ Type.Literal("left"),
154
+ Type.Literal("center"),
155
+ Type.Literal("right"),
156
+ Type.Literal("justify")
157
+ ],
158
+ { description: "Horizontal text alignment" }
159
+ );
160
+ var NativeVisualVerticalAlignmentSchema = Type.Union(
161
+ [Type.Literal("top"), Type.Literal("middle"), Type.Literal("bottom")],
162
+ { description: "Vertical text anchoring inside the box" }
163
+ );
164
+ var NativeVisualMarginSchema = Type.Union(
165
+ [
166
+ Type.Number({ minimum: 0, description: "Inset on every side, in points" }),
167
+ Type.Array(Type.Number({ minimum: 0 }), {
168
+ minItems: 4,
169
+ maxItems: 4,
170
+ description: "Insets as [top, right, bottom, left], in points"
171
+ })
172
+ ],
173
+ { description: "Text insets in points" }
174
+ );
175
+ var NativeVisualTextPropsSchema = Type.Object(
176
+ {
177
+ text: Type.Optional(Type.String({ description: "Plain text content" })),
178
+ runs: Type.Optional(
179
+ Type.Array(NativeVisualTextRunSchema, {
180
+ minItems: 1,
181
+ description: 'Formatted runs, as an alternative to "text"'
182
+ })
183
+ ),
184
+ ...FrameProps,
185
+ color: Type.Optional(NativeVisualColorSchema),
186
+ ...InlineTextProps,
187
+ underline: Type.Optional(NativeVisualUnderlineSchema),
188
+ strike: Type.Optional(Type.Boolean({ description: "Strikethrough" })),
189
+ align: Type.Optional(NativeVisualAlignmentSchema),
190
+ valign: Type.Optional(NativeVisualVerticalAlignmentSchema),
191
+ margin: Type.Optional(NativeVisualMarginSchema),
192
+ fill: Type.Optional(NativeVisualFillSchema)
193
+ },
194
+ {
195
+ additionalProperties: false,
196
+ description: "Native visual text element \u2014 becomes a Word text box (wps:wsp) inside the drawing group"
197
+ }
198
+ );
199
+ var NativeVisualShapePropsSchema = Type.Object(
200
+ {
201
+ type: ShapeTypeSchema,
202
+ ...FrameProps,
203
+ fill: Type.Optional(NativeVisualFillSchema),
204
+ line: Type.Optional(NativeVisualLineSchema),
205
+ text: Type.Optional(
206
+ Type.Union(
207
+ [
208
+ Type.String(),
209
+ Type.Array(NativeVisualTextSegmentSchema, { minItems: 1 })
210
+ ],
211
+ { description: "Text drawn inside the shape" }
212
+ )
213
+ ),
214
+ ...InlineTextProps,
215
+ fontColor: Type.Optional(NativeVisualColorSchema),
216
+ align: Type.Optional(NativeVisualAlignmentSchema),
217
+ valign: Type.Optional(NativeVisualVerticalAlignmentSchema),
218
+ margin: Type.Optional(NativeVisualMarginSchema),
219
+ flipH: Type.Optional(Type.Boolean({ description: "Mirror horizontally" })),
220
+ flipV: Type.Optional(Type.Boolean({ description: "Mirror vertically" }))
221
+ },
222
+ {
223
+ additionalProperties: false,
224
+ description: "Native visual shape element \u2014 becomes a preset-geometry shape (wps:wsp) inside the drawing group"
225
+ }
226
+ );
227
+ var NativeVisualImagePropsSchema = Type.Object(
228
+ {
229
+ path: Type.Optional(
230
+ Type.String({ description: "File path or http(s) URL" })
231
+ ),
232
+ base64: Type.Optional(Type.String({ description: "Base64 data URI" })),
233
+ svg: Type.Optional(Type.String({ description: "Raw SVG markup" })),
234
+ ...FrameProps,
235
+ sizing: Type.Optional(
236
+ Type.Object(
237
+ {
238
+ type: Type.Union(
239
+ [
240
+ Type.Literal("contain"),
241
+ Type.Literal("cover"),
242
+ Type.Literal("crop")
243
+ ],
244
+ { description: "How the image fills its box" }
245
+ ),
246
+ w: Type.Optional(
247
+ Type.Number({
248
+ minimum: 0,
249
+ description: 'Box width in inches; overrides the element\u2019s own "w"'
250
+ })
251
+ ),
252
+ h: Type.Optional(
253
+ Type.Number({
254
+ minimum: 0,
255
+ description: 'Box height in inches; overrides the element\u2019s own "h"'
256
+ })
257
+ )
258
+ },
259
+ {
260
+ additionalProperties: false,
261
+ description: 'How the image fills its box. "w"/"h" state the box itself, taking precedence over the element\u2019s "w"/"h", as they do in raster mode.'
262
+ }
263
+ )
264
+ ),
265
+ alt: Type.Optional(
266
+ Type.String({ description: "Alternative text for accessibility" })
267
+ )
268
+ },
269
+ {
270
+ additionalProperties: false,
271
+ description: "Native visual image element \u2014 becomes a native picture inside the drawing group"
272
+ }
273
+ );
274
+ var NATIVE_VISUAL_ELEMENT_NAMES = ["text", "shape", "image"];
275
+ function nativeElement(name, propsSchema, description) {
276
+ return Type.Object(
277
+ {
278
+ name: Type.Literal(name),
279
+ id: Type.Optional(Type.String()),
280
+ enabled: Type.Optional(
281
+ Type.Boolean({
282
+ default: true,
283
+ description: "When false, this element is filtered out and not drawn. Defaults to true."
284
+ })
285
+ ),
286
+ props: propsSchema
287
+ },
288
+ { additionalProperties: false, description }
289
+ );
290
+ }
291
+ var NativeVisualElementSchema = Type.Union(
292
+ [
293
+ nativeElement(
294
+ "text",
295
+ NativeVisualTextPropsSchema,
296
+ "Text element - a native Word text box drawn on the visual canvas."
297
+ ),
298
+ nativeElement(
299
+ "shape",
300
+ NativeVisualShapePropsSchema,
301
+ "Shape element - a native preset-geometry shape, optionally holding text."
302
+ ),
303
+ nativeElement(
304
+ "image",
305
+ NativeVisualImagePropsSchema,
306
+ "Image element - a native picture; an SVG stays vector."
307
+ )
308
+ ],
309
+ {
310
+ $id: "DocxNativeVisualContent",
311
+ discriminator: { propertyName: "name" },
312
+ description: "A single native visual element (text, shape, or image)."
313
+ }
314
+ );
315
+ var NativeVisualCanvasSchema = Type.Object(
316
+ {
317
+ width: Type.Number({
318
+ minimum: 0.1,
319
+ description: "Canvas width in inches"
320
+ }),
321
+ height: Type.Number({
322
+ minimum: 0.1,
323
+ description: "Canvas height in inches"
324
+ }),
325
+ background: Type.Optional(
326
+ Type.Object(
327
+ {
328
+ color: Type.Optional(NativeVisualColorSchema),
329
+ image: Type.Optional(
330
+ Type.Object(
331
+ {
332
+ path: Type.Optional(Type.String()),
333
+ base64: Type.Optional(Type.String())
334
+ },
335
+ { additionalProperties: false }
336
+ )
337
+ )
338
+ },
339
+ {
340
+ additionalProperties: false,
341
+ description: "Canvas background. A colour becomes the bottom-most rectangle; an image becomes the bottom-most picture."
342
+ }
343
+ )
344
+ )
345
+ },
346
+ {
347
+ additionalProperties: false,
348
+ description: "Drawing canvas for a native visual"
349
+ }
350
+ );
351
+
352
+ // src/schemas/components/visual.ts
353
+ var VisualCanvasBackgroundSchema = Type2.Object(
354
+ {
355
+ color: Type2.Optional(
356
+ Type2.String({
357
+ description: 'Background color (hex like "#FFFFFF" or a theme color name)'
358
+ })
359
+ ),
360
+ image: Type2.Optional(
361
+ Type2.Object(
362
+ {
363
+ path: Type2.Optional(Type2.String()),
364
+ base64: Type2.Optional(Type2.String())
365
+ },
366
+ { additionalProperties: false }
367
+ )
368
+ )
369
+ },
370
+ { additionalProperties: false }
371
+ );
372
+ var VisualCanvasSchema = Type2.Object(
373
+ {
374
+ width: Type2.Number({
375
+ minimum: 0.1,
376
+ description: "Canvas width in inches (pptx slideWidth)"
377
+ }),
378
+ height: Type2.Number({
379
+ minimum: 0.1,
380
+ description: "Canvas height in inches (pptx slideHeight)"
381
+ }),
382
+ theme: Type2.Optional(
383
+ Type2.String({ description: "pptx theme name applied to the slide" })
384
+ ),
385
+ background: Type2.Optional(VisualCanvasBackgroundSchema)
386
+ },
387
+ {
388
+ description: "pptx canvas definition for the visual",
389
+ additionalProperties: false
390
+ }
391
+ );
392
+ var PlacementProps = {
393
+ width: Type2.Optional(
394
+ Type2.Union(
395
+ [
396
+ Type2.Number({ minimum: 1, description: "Rendered width in pixels" }),
397
+ Type2.String({
398
+ pattern: "^\\d+(\\.\\d+)?%$",
399
+ description: 'Rendered width as percentage (e.g. "90%")'
400
+ })
401
+ ],
402
+ {
403
+ description: "Rendered width in the document, in pixels (number) or percentage string. Defaults to the canvas physical size."
404
+ }
405
+ )
406
+ ),
407
+ height: Type2.Optional(
408
+ Type2.Union([
409
+ Type2.Number({ minimum: 1, description: "Rendered height in pixels" }),
410
+ Type2.String({
411
+ pattern: "^\\d+(\\.\\d+)?%$",
412
+ description: 'Rendered height as percentage (e.g. "90%")'
413
+ })
414
+ ])
415
+ ),
416
+ alignment: Type2.Optional(AlignmentSchema),
417
+ caption: Type2.Optional(
418
+ Type2.String({
419
+ description: "Caption (supports rich text with **bold**, *italic*, ***both***)"
420
+ })
421
+ ),
422
+ alt: Type2.Optional(
423
+ Type2.String({ description: "Alternative text for accessibility" })
424
+ ),
425
+ spacing: Type2.Optional(SpacingSchema),
426
+ floating: Type2.Optional(FloatingPropertiesSchema),
427
+ keepNext: Type2.Optional(
428
+ Type2.Boolean({
429
+ description: "Keep paragraph with next paragraph on same page"
430
+ })
431
+ ),
432
+ keepLines: Type2.Optional(
433
+ Type2.Boolean({
434
+ description: "Keep all lines of paragraph together on same page"
435
+ })
436
+ )
437
+ };
438
+ var VisualRasterPropsSchema = Type2.Object(
439
+ {
440
+ renderMode: Type2.Optional(
441
+ Type2.Literal("raster", {
442
+ description: "Render as a rasterized pptx slide (the default when omitted)."
443
+ })
444
+ ),
445
+ // ── canvas (drives aspect ratio + physical size) ──
446
+ canvas: VisualCanvasSchema,
447
+ // pptx slide content elements, absolutely positioned on the canvas
448
+ elements: Type2.Optional(
449
+ Type2.Array(PptxSlideContentSchema, {
450
+ description: "pptx slide content elements (text, image, shape, table, highcharts, chart), positioned with x/y/w/h in inches"
451
+ })
452
+ ),
453
+ // ── rasterization ──
454
+ dpi: Type2.Optional(
455
+ Type2.Number({
456
+ minimum: MIN_VISUAL_DPI,
457
+ maximum: MAX_VISUAL_DPI,
458
+ default: DEFAULT_VISUAL_DPI,
459
+ description: `Raster resolution in DPI (default ${DEFAULT_VISUAL_DPI}, range ${MIN_VISUAL_DPI}-${MAX_VISUAL_DPI}). Higher = sharper + larger.`
460
+ })
461
+ ),
462
+ serverUrl: Type2.Optional(
463
+ Type2.String({
464
+ description: "Rasterization service URL override (default from services.pptx)"
465
+ })
466
+ ),
467
+ // ── placement in the document (mirrors `image`) ──
468
+ ...PlacementProps
469
+ },
470
+ {
471
+ // Hoisted into its own JSON-Schema definition rather than inlined at every
472
+ // position a component can appear. `visual.props` is by far the largest
473
+ // props schema in the registry, and inlining two of them pushed the
474
+ // exported `ComponentDefinition` past the depth Ajv can compile.
475
+ $id: "DocxVisualRasterProps",
476
+ description: "Visual component props (pptx-rendered graphic)",
477
+ additionalProperties: false
478
+ }
479
+ );
480
+ var VisualNativePropsSchema = Type2.Object(
481
+ {
482
+ renderMode: Type2.Literal("native", {
483
+ description: 'Draw natively as a Word DrawingML group. Requires the "office-open" renderer.'
484
+ }),
485
+ canvas: NativeVisualCanvasSchema,
486
+ elements: Type2.Optional(
487
+ Type2.Array(NativeVisualElementSchema, {
488
+ description: "Native drawing elements (text, shape, image), positioned with x/y/w/h in inches or canvas percentages"
489
+ })
490
+ ),
491
+ ...PlacementProps
492
+ },
493
+ {
494
+ // Hoisted for the same reason as the raster branch above.
495
+ $id: "DocxVisualNativeProps",
496
+ description: 'Visual component props (native Word drawing group; requires renderer "office-open")',
497
+ additionalProperties: false
498
+ }
499
+ );
500
+ var VisualPropsSchema = Type2.Union(
501
+ [VisualRasterPropsSchema, VisualNativePropsSchema],
502
+ {
503
+ description: "Visual component props \u2014 rasterized pptx slide (default) or a native Word drawing group"
504
+ }
505
+ );
506
+ var NATIVE_RENDER_MODE = "native";
507
+ function isNativeVisualProps(props) {
508
+ return !!props && props.renderMode === NATIVE_RENDER_MODE;
509
+ }
510
+
511
+ // src/schemas/renderer.ts
512
+ var DOCX_RENDERER_IDS = ["docxjs", "office-open"];
513
+ var DEFAULT_DOCX_RENDERER_ID = "docxjs";
514
+ var NATIVE_VISUAL_ELEMENTS = /* @__PURE__ */ new Set([
515
+ "text",
516
+ "shape",
517
+ "image"
518
+ ]);
519
+ function docxComponentDefinitionName(renderer) {
520
+ return `ComponentDefinition_${renderer}`;
521
+ }
522
+ function docxPropsSchemaForRenderer(componentName, schema, renderer) {
523
+ const copy = cloneSchema(schema);
524
+ nameComponentPlaceholders(copy, docxComponentDefinitionName(renderer));
525
+ if (componentName === "visual" && renderer !== "office-open") {
526
+ return firstUnionBranch(copy) ?? copy;
527
+ }
528
+ if (renderer === "office-open") pruneThreadFields(copy);
529
+ return copy;
530
+ }
531
+ function collectDocxRendererErrors(data) {
532
+ if (!data || typeof data !== "object" || Array.isArray(data)) return [];
533
+ const root = data;
534
+ const renderer = root.renderer ?? DEFAULT_DOCX_RENDERER_ID;
535
+ if (!DOCX_RENDERER_IDS.includes(renderer)) {
536
+ return [
537
+ {
538
+ path: "/renderer",
539
+ message: `Invalid renderer "${String(renderer)}". Expected "docxjs" or "office-open".`,
540
+ code: "invalid_value"
541
+ }
542
+ ];
543
+ }
544
+ const errors = [];
545
+ const isOfficeOpen = renderer === "office-open";
546
+ const visit = (node, path) => {
547
+ if (Array.isArray(node)) {
548
+ node.forEach((entry, index) => visit(entry, `${path}/${index}`));
549
+ return;
550
+ }
551
+ if (!node || typeof node !== "object") return;
552
+ const object = node;
553
+ if (isOfficeOpen) {
554
+ const comment = object.comment;
555
+ if (comment && typeof comment === "object" && !Array.isArray(comment)) {
556
+ const value = comment;
557
+ for (const field of ["replies", "resolved"]) {
558
+ if (value[field] !== void 0) {
559
+ errors.push({
560
+ path: `${path}/comment/${field}`,
561
+ message: `The "office-open" renderer does not support comment threads.`,
562
+ code: "unsupported_renderer_feature"
563
+ });
564
+ }
565
+ }
566
+ }
567
+ }
568
+ if (object.name === "visual") {
569
+ collectVisualErrors(object, `${path}`, isOfficeOpen, errors);
570
+ }
571
+ for (const [key, value] of Object.entries(object)) {
572
+ if (key !== "renderer") visit(value, `${path}/${key}`);
573
+ }
574
+ };
575
+ visit(root, "");
576
+ return errors;
577
+ }
578
+ function collectVisualErrors(node, path, isOfficeOpen, errors) {
579
+ const props = node.props;
580
+ if (!props || typeof props !== "object" || Array.isArray(props)) return;
581
+ const value = props;
582
+ if (value.renderMode !== NATIVE_RENDER_MODE) return;
583
+ if (!isOfficeOpen) {
584
+ errors.push({
585
+ path: `${path}/props/renderMode`,
586
+ message: `Only the "office-open" renderer draws a native visual. Set the document's "renderer" to "office-open", or drop "renderMode" to rasterize.`,
587
+ code: "unsupported_renderer_feature"
588
+ });
589
+ return;
590
+ }
591
+ const elements = value.elements;
592
+ if (!Array.isArray(elements)) return;
593
+ elements.forEach((element, index) => {
594
+ if (!element || typeof element !== "object" || Array.isArray(element)) {
595
+ return;
596
+ }
597
+ const name = element.name;
598
+ if (typeof name !== "string" || NATIVE_VISUAL_ELEMENTS.has(name)) return;
599
+ errors.push({
600
+ path: `${path}/props/elements/${index}/name`,
601
+ message: `A native visual cannot draw "${name}". Native mode holds "text", "shape" and "image"; use renderMode "raster" for anything else.`,
602
+ code: "unsupported_renderer_feature"
603
+ });
604
+ });
605
+ }
606
+ function firstUnionBranch(schema) {
607
+ const branches = schema.anyOf;
608
+ return Array.isArray(branches) && branches.length > 0 ? branches[0] : void 0;
609
+ }
610
+ function pruneThreadFields(node) {
611
+ if (Array.isArray(node)) {
612
+ node.forEach(pruneThreadFields);
613
+ return;
614
+ }
615
+ if (!node || typeof node !== "object") return;
616
+ const schema = node;
617
+ const properties = schema.properties;
618
+ if (properties?.text && properties?.author && (properties.replies || properties.resolved) && typeof schema.description === "string" && schema.description.includes("Word review comment")) {
619
+ delete properties.replies;
620
+ delete properties.resolved;
621
+ const required = schema.required;
622
+ if (required) {
623
+ schema.required = required.filter(
624
+ (key) => key !== "replies" && key !== "resolved"
625
+ );
626
+ }
627
+ }
628
+ for (const key of Reflect.ownKeys(schema)) {
629
+ pruneThreadFields(schema[key]);
630
+ }
631
+ }
632
+ function nameComponentPlaceholders(node, definitionName) {
633
+ if (Array.isArray(node)) {
634
+ node.forEach((entry) => nameComponentPlaceholders(entry, definitionName));
635
+ return;
636
+ }
637
+ if (!node || typeof node !== "object") return;
638
+ const schema = node;
639
+ if (schema.type === "array" && schema.items && typeof schema.items === "object" && Object.keys(schema.items).length === 0) {
640
+ schema.items = { $ref: definitionName };
641
+ }
642
+ for (const key of Reflect.ownKeys(schema)) {
643
+ nameComponentPlaceholders(schema[key], definitionName);
644
+ }
645
+ }
646
+ function cloneSchema(value) {
647
+ if (Array.isArray(value)) return value.map(cloneSchema);
648
+ if (!value || typeof value !== "object") return value;
649
+ const copy = Object.create(Object.getPrototypeOf(value));
650
+ for (const key of Reflect.ownKeys(value)) {
651
+ copy[key] = cloneSchema(value[key]);
652
+ }
653
+ return copy;
654
+ }
655
+
656
+ export {
657
+ NativeVisualColorSchema,
658
+ NativeVisualOffsetSchema,
659
+ NativeVisualExtentSchema,
660
+ NativeVisualUnderlineSchema,
661
+ NativeVisualTextRunSchema,
662
+ NativeVisualTextSegmentSchema,
663
+ NativeVisualFillSchema,
664
+ NativeVisualLineSchema,
665
+ NativeVisualAlignmentSchema,
666
+ NativeVisualVerticalAlignmentSchema,
667
+ NativeVisualMarginSchema,
668
+ NativeVisualTextPropsSchema,
669
+ NativeVisualShapePropsSchema,
670
+ NativeVisualImagePropsSchema,
671
+ NATIVE_VISUAL_ELEMENT_NAMES,
672
+ NativeVisualElementSchema,
673
+ NativeVisualCanvasSchema,
674
+ VisualCanvasBackgroundSchema,
675
+ VisualCanvasSchema,
676
+ VisualRasterPropsSchema,
677
+ VisualNativePropsSchema,
678
+ VisualPropsSchema,
679
+ NATIVE_RENDER_MODE,
680
+ isNativeVisualProps,
681
+ DOCX_RENDERER_IDS,
682
+ DEFAULT_DOCX_RENDERER_ID,
683
+ docxComponentDefinitionName,
684
+ docxPropsSchemaForRenderer,
685
+ collectDocxRendererErrors
686
+ };
687
+ //# sourceMappingURL=chunk-5KOKA5GY.js.map