dimcode-darwin-arm64 0.2.19 → 0.2.20

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 (109) hide show
  1. package/bin/dimcode +0 -0
  2. package/bin/skills-assets/chrome-control/SKILL.md +96 -0
  3. package/bin/skills-assets/dim-workflow/SKILL.md +78 -30
  4. package/bin/skills-assets/officecli/SKILL.md +423 -0
  5. package/package.json +1 -1
  6. package/bin/skills-assets/docx/SKILL.md +0 -273
  7. package/bin/skills-assets/docx/assets/styles/academic_styles.xml +0 -250
  8. package/bin/skills-assets/docx/assets/styles/corporate_styles.xml +0 -284
  9. package/bin/skills-assets/docx/assets/styles/default_styles.xml +0 -449
  10. package/bin/skills-assets/docx/assets/xsd/aesthetic-rules.xsd +0 -470
  11. package/bin/skills-assets/docx/assets/xsd/business-rules.xsd +0 -130
  12. package/bin/skills-assets/docx/assets/xsd/common-types.xsd +0 -159
  13. package/bin/skills-assets/docx/assets/xsd/wml-subset.xsd +0 -589
  14. package/bin/skills-assets/docx/references/cjk_typography.md +0 -357
  15. package/bin/skills-assets/docx/references/cjk_university_template_guide.md +0 -184
  16. package/bin/skills-assets/docx/references/comments_guide.md +0 -191
  17. package/bin/skills-assets/docx/references/design_good_bad_examples.md +0 -829
  18. package/bin/skills-assets/docx/references/design_principles.md +0 -819
  19. package/bin/skills-assets/docx/references/openxml_element_order.md +0 -308
  20. package/bin/skills-assets/docx/references/openxml_encyclopedia_part1.md +0 -4061
  21. package/bin/skills-assets/docx/references/openxml_encyclopedia_part2.md +0 -2820
  22. package/bin/skills-assets/docx/references/openxml_encyclopedia_part3.md +0 -3381
  23. package/bin/skills-assets/docx/references/openxml_namespaces.md +0 -82
  24. package/bin/skills-assets/docx/references/openxml_units.md +0 -72
  25. package/bin/skills-assets/docx/references/scenario_a_create.md +0 -284
  26. package/bin/skills-assets/docx/references/scenario_b_edit_content.md +0 -295
  27. package/bin/skills-assets/docx/references/scenario_c_apply_template.md +0 -456
  28. package/bin/skills-assets/docx/references/track_changes_guide.md +0 -200
  29. package/bin/skills-assets/docx/references/troubleshooting.md +0 -506
  30. package/bin/skills-assets/docx/references/typography_guide.md +0 -294
  31. package/bin/skills-assets/docx/references/xsd_validation_guide.md +0 -158
  32. package/bin/skills-assets/docx/scripts/doc_to_docx.sh +0 -40
  33. package/bin/skills-assets/docx/scripts/docx_preview.sh +0 -37
  34. package/bin/skills-assets/docx/scripts/dotnet/Docx.Cli/Docx.Cli.csproj +0 -19
  35. package/bin/skills-assets/docx/scripts/dotnet/Docx.Cli/Program.cs +0 -18
  36. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Commands/AnalyzeCommand.cs +0 -147
  37. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Commands/ApplyTemplateCommand.cs +0 -322
  38. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Commands/CreateCommand.cs +0 -324
  39. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Commands/DiffCommand.cs +0 -155
  40. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Commands/EditContentCommand.cs +0 -487
  41. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Commands/FixOrderCommand.cs +0 -108
  42. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Commands/MergeRunsCommand.cs +0 -122
  43. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Commands/ValidateCommand.cs +0 -107
  44. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Docx.Core.csproj +0 -15
  45. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/OpenXml/CommentSynchronizer.cs +0 -169
  46. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/OpenXml/ElementOrder.cs +0 -80
  47. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/OpenXml/NamespaceConstants.cs +0 -42
  48. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/OpenXml/RunMerger.cs +0 -81
  49. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/OpenXml/StyleAnalyzer.cs +0 -81
  50. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/OpenXml/TrackChangesHelper.cs +0 -99
  51. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/OpenXml/UnitConverter.cs +0 -23
  52. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/AestheticRecipeSamples.cs +0 -1832
  53. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/AestheticRecipeSamples_Batch1.cs +0 -910
  54. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/AestheticRecipeSamples_Batch2.cs +0 -999
  55. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/AestheticRecipeSamples_Batch3.cs +0 -1048
  56. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/AestheticRecipeSamples_Batch4.cs +0 -1038
  57. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/CharacterFormattingSamples.cs +0 -1020
  58. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/DocumentCreationSamples.cs +0 -1121
  59. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/FieldAndTocSamples.cs +0 -624
  60. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/FootnoteAndCommentSamples.cs +0 -675
  61. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/HeaderFooterSamples.cs +0 -838
  62. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/ImageSamples.cs +0 -917
  63. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/ListAndNumberingSamples.cs +0 -826
  64. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/ParagraphFormattingSamples.cs +0 -1199
  65. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/StyleSystemSamples.cs +0 -1487
  66. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/TableSamples.cs +0 -1163
  67. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Samples/TrackChangesSamples.cs +0 -595
  68. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Typography/CjkHelper.cs +0 -39
  69. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Typography/FontDefaults.cs +0 -24
  70. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Typography/PageSizes.cs +0 -20
  71. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Validation/BusinessRuleValidator.cs +0 -224
  72. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Validation/GateCheckValidator.cs +0 -148
  73. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Validation/ValidationResult.cs +0 -23
  74. package/bin/skills-assets/docx/scripts/dotnet/Docx.Core/Validation/XsdValidator.cs +0 -69
  75. package/bin/skills-assets/docx/scripts/dotnet/Docx.slnx +0 -4
  76. package/bin/skills-assets/docx/scripts/env_check.sh +0 -196
  77. package/bin/skills-assets/docx/scripts/setup.ps1 +0 -274
  78. package/bin/skills-assets/docx/scripts/setup.sh +0 -504
  79. package/bin/skills-assets/pptx-generator/SKILL.md +0 -248
  80. package/bin/skills-assets/pptx-generator/references/design-system.md +0 -392
  81. package/bin/skills-assets/pptx-generator/references/editing.md +0 -162
  82. package/bin/skills-assets/pptx-generator/references/pitfalls.md +0 -112
  83. package/bin/skills-assets/pptx-generator/references/pptxgenjs.md +0 -420
  84. package/bin/skills-assets/pptx-generator/references/slide-types.md +0 -413
  85. package/bin/skills-assets/xlsx/SKILL.md +0 -137
  86. package/bin/skills-assets/xlsx/references/create.md +0 -691
  87. package/bin/skills-assets/xlsx/references/edit.md +0 -684
  88. package/bin/skills-assets/xlsx/references/fix.md +0 -37
  89. package/bin/skills-assets/xlsx/references/format.md +0 -768
  90. package/bin/skills-assets/xlsx/references/ooxml-cheatsheet.md +0 -231
  91. package/bin/skills-assets/xlsx/references/read-analyze.md +0 -97
  92. package/bin/skills-assets/xlsx/references/validate.md +0 -772
  93. package/bin/skills-assets/xlsx/scripts/formula_check.py +0 -422
  94. package/bin/skills-assets/xlsx/scripts/libreoffice_recalc.py +0 -248
  95. package/bin/skills-assets/xlsx/scripts/shared_strings_builder.py +0 -163
  96. package/bin/skills-assets/xlsx/scripts/style_audit.py +0 -575
  97. package/bin/skills-assets/xlsx/scripts/xlsx_add_column.py +0 -395
  98. package/bin/skills-assets/xlsx/scripts/xlsx_insert_row.py +0 -274
  99. package/bin/skills-assets/xlsx/scripts/xlsx_pack.py +0 -87
  100. package/bin/skills-assets/xlsx/scripts/xlsx_reader.py +0 -362
  101. package/bin/skills-assets/xlsx/scripts/xlsx_shift_rows.py +0 -396
  102. package/bin/skills-assets/xlsx/scripts/xlsx_unpack.py +0 -130
  103. package/bin/skills-assets/xlsx/templates/minimal_xlsx/[Content_Types].xml +0 -9
  104. package/bin/skills-assets/xlsx/templates/minimal_xlsx/_rels/.rels +0 -6
  105. package/bin/skills-assets/xlsx/templates/minimal_xlsx/xl/_rels/workbook.xml.rels +0 -19
  106. package/bin/skills-assets/xlsx/templates/minimal_xlsx/xl/sharedStrings.xml +0 -33
  107. package/bin/skills-assets/xlsx/templates/minimal_xlsx/xl/styles.xml +0 -160
  108. package/bin/skills-assets/xlsx/templates/minimal_xlsx/xl/workbook.xml +0 -30
  109. package/bin/skills-assets/xlsx/templates/minimal_xlsx/xl/worksheets/sheet1.xml +0 -70
@@ -1,324 +0,0 @@
1
- using System.CommandLine;
2
- using DocumentFormat.OpenXml;
3
- using DocumentFormat.OpenXml.Packaging;
4
- using DocumentFormat.OpenXml.Wordprocessing;
5
- using Docx.Core.OpenXml;
6
- using Docx.Core.Typography;
7
-
8
- namespace Docx.Core.Commands;
9
-
10
- /// <summary>
11
- /// Scenario A: Create a new DOCX document from scratch with proper styles, sections,
12
- /// headers/footers, and typography defaults.
13
- /// </summary>
14
- public static class CreateCommand
15
- {
16
- public static Command Create()
17
- {
18
- var outputOption = new Option<string>("--output") { Description = "Output DOCX file path", Required = true };
19
- var typeOption = new Option<string>("--type") { Description = "Document type: report, letter, memo, academic" };
20
- typeOption.DefaultValueFactory = _ => "report";
21
- var titleOption = new Option<string>("--title") { Description = "Document title" };
22
- var authorOption = new Option<string>("--author") { Description = "Document author" };
23
- var pageSizeOption = new Option<string>("--page-size") { Description = "Page size: letter, a4, legal, a3" };
24
- pageSizeOption.DefaultValueFactory = _ => "letter";
25
- var marginsOption = new Option<string>("--margins") { Description = "Margin preset: standard, narrow, wide" };
26
- marginsOption.DefaultValueFactory = _ => "standard";
27
- var headerTextOption = new Option<string>("--header") { Description = "Header text" };
28
- var footerTextOption = new Option<string>("--footer") { Description = "Footer text" };
29
- var pageNumbersOption = new Option<bool>("--page-numbers") { Description = "Add page numbers in footer" };
30
- var tocOption = new Option<bool>("--toc") { Description = "Insert table of contents placeholder" };
31
- var contentJsonOption = new Option<string>("--content-json") { Description = "Path to JSON file describing document content" };
32
-
33
- var cmd = new Command("create", "Create a new DOCX document from scratch")
34
- {
35
- outputOption, typeOption, titleOption, authorOption, pageSizeOption,
36
- marginsOption, headerTextOption, footerTextOption, pageNumbersOption,
37
- tocOption, contentJsonOption
38
- };
39
-
40
- cmd.SetAction((parseResult) =>
41
- {
42
- var output = parseResult.GetValue(outputOption)!;
43
- var docType = parseResult.GetValue(typeOption) ?? "report";
44
- var title = parseResult.GetValue(titleOption);
45
- var author = parseResult.GetValue(authorOption);
46
- var pageSizeName = parseResult.GetValue(pageSizeOption) ?? "letter";
47
- var marginsName = parseResult.GetValue(marginsOption) ?? "standard";
48
- var headerText = parseResult.GetValue(headerTextOption);
49
- var footerText = parseResult.GetValue(footerTextOption);
50
- var pageNumbers = parseResult.GetValue(pageNumbersOption);
51
- var tocPlaceholder = parseResult.GetValue(tocOption);
52
- var contentJson = parseResult.GetValue(contentJsonOption);
53
-
54
- var fontConfig = GetFontConfig(docType);
55
- var pageSize = GetPageSizeConfig(pageSizeName);
56
- var margins = GetMargins(marginsName);
57
-
58
- using var doc = WordprocessingDocument.Create(output, WordprocessingDocumentType.Document);
59
- var mainPart = doc.AddMainDocumentPart();
60
- mainPart.Document = new Document(new Body());
61
- var body = mainPart.Document.Body!;
62
-
63
- // Add styles part with defaults
64
- AddDefaultStyles(mainPart, fontConfig);
65
-
66
- // Add section properties (page size, margins)
67
- var sectPr = new SectionProperties();
68
- sectPr.Append(new DocumentFormat.OpenXml.Wordprocessing.PageSize
69
- {
70
- Width = (UInt32Value)(uint)pageSize.WidthDxa,
71
- Height = (UInt32Value)(uint)pageSize.HeightDxa
72
- });
73
- sectPr.Append(new PageMargin
74
- {
75
- Top = margins.TopDxa,
76
- Bottom = margins.BottomDxa,
77
- Left = (UInt32Value)(uint)margins.LeftDxa,
78
- Right = (UInt32Value)(uint)margins.RightDxa
79
- });
80
-
81
- // Add header if requested
82
- if (!string.IsNullOrEmpty(headerText))
83
- {
84
- var headerPart = mainPart.AddNewPart<HeaderPart>();
85
- headerPart.Header = new Header(
86
- new Paragraph(new Run(new Text(headerText))));
87
- var headerRefId = mainPart.GetIdOfPart(headerPart);
88
- sectPr.Append(new HeaderReference
89
- {
90
- Type = HeaderFooterValues.Default,
91
- Id = headerRefId
92
- });
93
- }
94
-
95
- // Add footer if requested
96
- if (!string.IsNullOrEmpty(footerText) || pageNumbers)
97
- {
98
- var footerPart = mainPart.AddNewPart<FooterPart>();
99
- var footerParagraph = new Paragraph();
100
-
101
- if (!string.IsNullOrEmpty(footerText))
102
- {
103
- footerParagraph.Append(new Run(new Text(footerText)));
104
- }
105
-
106
- if (pageNumbers)
107
- {
108
- if (!string.IsNullOrEmpty(footerText))
109
- footerParagraph.Append(new Run(new Text(" — ") { Space = SpaceProcessingModeValues.Preserve }));
110
-
111
- footerParagraph.Append(new Run(
112
- new FieldChar { FieldCharType = FieldCharValues.Begin }));
113
- footerParagraph.Append(new Run(
114
- new FieldCode(" PAGE ") { Space = SpaceProcessingModeValues.Preserve }));
115
- footerParagraph.Append(new Run(
116
- new FieldChar { FieldCharType = FieldCharValues.End }));
117
- }
118
-
119
- footerPart.Footer = new Footer(footerParagraph);
120
- var footerRefId = mainPart.GetIdOfPart(footerPart);
121
- sectPr.Append(new FooterReference
122
- {
123
- Type = HeaderFooterValues.Default,
124
- Id = footerRefId
125
- });
126
- }
127
-
128
- // Title
129
- if (!string.IsNullOrEmpty(title))
130
- {
131
- var titlePara = new Paragraph(
132
- new ParagraphProperties(new ParagraphStyleId { Val = "Title" }),
133
- new Run(new Text(title)));
134
- body.Append(titlePara);
135
- }
136
-
137
- // Author subtitle
138
- if (!string.IsNullOrEmpty(author))
139
- {
140
- var authorPara = new Paragraph(
141
- new ParagraphProperties(new ParagraphStyleId { Val = "Subtitle" }),
142
- new Run(new Text(author)));
143
- body.Append(authorPara);
144
- }
145
-
146
- // TOC placeholder
147
- if (tocPlaceholder)
148
- {
149
- body.Append(new Paragraph(
150
- new ParagraphProperties(new ParagraphStyleId { Val = "TOCHeading" }),
151
- new Run(new Text("Table of Contents"))));
152
-
153
- // Insert TOC field
154
- var tocPara = new Paragraph();
155
- tocPara.Append(new Run(new FieldChar { FieldCharType = FieldCharValues.Begin }));
156
- tocPara.Append(new Run(new FieldCode(" TOC \\o \"1-3\" \\h \\z \\u ") { Space = SpaceProcessingModeValues.Preserve }));
157
- tocPara.Append(new Run(new FieldChar { FieldCharType = FieldCharValues.Separate }));
158
- tocPara.Append(new Run(new Text("Update this field to generate table of contents.")));
159
- tocPara.Append(new Run(new FieldChar { FieldCharType = FieldCharValues.End }));
160
- body.Append(tocPara);
161
-
162
- // Page break after TOC
163
- body.Append(new Paragraph(new Run(new Break { Type = BreakValues.Page })));
164
- }
165
-
166
- // Content from JSON (if provided)
167
- if (!string.IsNullOrEmpty(contentJson) && File.Exists(contentJson))
168
- {
169
- var jsonContent = File.ReadAllText(contentJson);
170
- AddContentFromJson(body, jsonContent, fontConfig);
171
- }
172
-
173
- // Ensure body has at least one paragraph
174
- if (!body.Elements<Paragraph>().Any())
175
- {
176
- body.Append(new Paragraph());
177
- }
178
-
179
- // sectPr must be the last child of body
180
- body.Append(sectPr);
181
-
182
- mainPart.Document.Save();
183
- Console.WriteLine($"Created {docType} document: {output}");
184
- });
185
-
186
- return cmd;
187
- }
188
-
189
- private static FontConfig GetFontConfig(string docType) => docType.ToLowerInvariant() switch
190
- {
191
- "letter" => FontDefaults.Letter,
192
- "memo" => FontDefaults.Memo,
193
- "academic" => FontDefaults.Academic,
194
- _ => FontDefaults.Report,
195
- };
196
-
197
- private static Typography.PageSize GetPageSizeConfig(string name) => name.ToLowerInvariant() switch
198
- {
199
- "a4" => PageSizes.A4,
200
- "legal" => PageSizes.Legal,
201
- "a3" => PageSizes.A3,
202
- _ => PageSizes.Letter,
203
- };
204
-
205
- private static MarginConfig GetMargins(string name) => name.ToLowerInvariant() switch
206
- {
207
- "narrow" => PageSizes.NarrowMargins,
208
- "wide" => PageSizes.WideMargins,
209
- _ => PageSizes.StandardMargins,
210
- };
211
-
212
- private static void AddDefaultStyles(MainDocumentPart mainPart, FontConfig fontConfig)
213
- {
214
- var stylesPart = mainPart.AddNewPart<StyleDefinitionsPart>();
215
- var styles = new Styles();
216
-
217
- // Default run properties
218
- var defaultRPr = new StyleRunProperties(
219
- new RunFonts { Ascii = fontConfig.BodyFont, HighAnsi = fontConfig.BodyFont },
220
- new FontSize { Val = UnitConverter.FontSizeToSz(fontConfig.BodySize) },
221
- new FontSizeComplexScript { Val = UnitConverter.FontSizeToSz(fontConfig.BodySize) });
222
-
223
- // Normal style
224
- styles.Append(new Style(
225
- new StyleName { Val = "Normal" },
226
- new PrimaryStyle(),
227
- defaultRPr)
228
- { Type = StyleValues.Paragraph, StyleId = "Normal", Default = true });
229
-
230
- // Heading styles 1-6
231
- double[] headingSizes = [fontConfig.Heading1Size, fontConfig.Heading2Size, fontConfig.Heading3Size,
232
- fontConfig.Heading4Size, fontConfig.Heading5Size, fontConfig.Heading6Size];
233
- for (int i = 0; i < 6; i++)
234
- {
235
- var level = i + 1;
236
- var headingStyle = new Style(
237
- new StyleName { Val = $"heading {level}" },
238
- new BasedOn { Val = "Normal" },
239
- new NextParagraphStyle { Val = "Normal" },
240
- new PrimaryStyle(),
241
- new StyleParagraphProperties(
242
- new KeepNext(),
243
- new KeepLines(),
244
- new SpacingBetweenLines { Before = "240", After = "120" },
245
- new OutlineLevel { Val = i }),
246
- new StyleRunProperties(
247
- new RunFonts { Ascii = fontConfig.HeadingFont, HighAnsi = fontConfig.HeadingFont },
248
- new FontSize { Val = UnitConverter.FontSizeToSz(headingSizes[i]) },
249
- new FontSizeComplexScript { Val = UnitConverter.FontSizeToSz(headingSizes[i]) },
250
- new Bold()))
251
- { Type = StyleValues.Paragraph, StyleId = $"Heading{level}" };
252
- styles.Append(headingStyle);
253
- }
254
-
255
- // Title style
256
- styles.Append(new Style(
257
- new StyleName { Val = "Title" },
258
- new BasedOn { Val = "Normal" },
259
- new NextParagraphStyle { Val = "Normal" },
260
- new PrimaryStyle(),
261
- new StyleParagraphProperties(
262
- new Justification { Val = JustificationValues.Center },
263
- new SpacingBetweenLines { After = "300" }),
264
- new StyleRunProperties(
265
- new RunFonts { Ascii = fontConfig.HeadingFont, HighAnsi = fontConfig.HeadingFont },
266
- new FontSize { Val = UnitConverter.FontSizeToSz(fontConfig.Heading1Size + 6) },
267
- new FontSizeComplexScript { Val = UnitConverter.FontSizeToSz(fontConfig.Heading1Size + 6) }))
268
- { Type = StyleValues.Paragraph, StyleId = "Title" });
269
-
270
- // Subtitle style
271
- styles.Append(new Style(
272
- new StyleName { Val = "Subtitle" },
273
- new BasedOn { Val = "Normal" },
274
- new NextParagraphStyle { Val = "Normal" },
275
- new StyleParagraphProperties(
276
- new Justification { Val = JustificationValues.Center },
277
- new SpacingBetweenLines { After = "200" }),
278
- new StyleRunProperties(
279
- new Color { Val = "5A5A5A" },
280
- new FontSize { Val = UnitConverter.FontSizeToSz(fontConfig.BodySize + 2) }))
281
- { Type = StyleValues.Paragraph, StyleId = "Subtitle" });
282
-
283
- stylesPart.Styles = styles;
284
- stylesPart.Styles.Save();
285
- }
286
-
287
- private static void AddContentFromJson(Body body, string jsonContent, FontConfig fontConfig)
288
- {
289
- // Simple JSON content format: array of {type, text, level?}
290
- // e.g. [{"type":"heading","text":"Introduction","level":1},{"type":"paragraph","text":"..."}]
291
- try
292
- {
293
- using var jsonDoc = System.Text.Json.JsonDocument.Parse(jsonContent);
294
- foreach (var element in jsonDoc.RootElement.EnumerateArray())
295
- {
296
- var type = element.GetProperty("type").GetString() ?? "paragraph";
297
- var text = element.GetProperty("text").GetString() ?? "";
298
-
299
- switch (type)
300
- {
301
- case "heading":
302
- var level = element.TryGetProperty("level", out var lvl) ? lvl.GetInt32() : 1;
303
- level = Math.Clamp(level, 1, 6);
304
- body.Append(new Paragraph(
305
- new ParagraphProperties(new ParagraphStyleId { Val = $"Heading{level}" }),
306
- new Run(new Text(text))));
307
- break;
308
-
309
- case "paragraph":
310
- body.Append(new Paragraph(new Run(new Text(text))));
311
- break;
312
-
313
- case "pagebreak":
314
- body.Append(new Paragraph(new Run(new Break { Type = BreakValues.Page })));
315
- break;
316
- }
317
- }
318
- }
319
- catch (System.Text.Json.JsonException ex)
320
- {
321
- Console.Error.WriteLine($"Warning: could not parse content JSON: {ex.Message}");
322
- }
323
- }
324
- }
@@ -1,155 +0,0 @@
1
- using System.CommandLine;
2
- using System.IO.Compression;
3
- using System.Text.Json;
4
- using System.Xml.Linq;
5
-
6
- namespace Docx.Core.Commands;
7
-
8
- public static class DiffCommand
9
- {
10
- private static readonly XNamespace W = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
11
-
12
- public static Command Create()
13
- {
14
- var beforeOption = new Option<string>("--before") { Description = "Original DOCX", Required = true };
15
- var afterOption = new Option<string>("--after") { Description = "Modified DOCX", Required = true };
16
- var jsonOption = new Option<bool>("--json") { Description = "Output as JSON" };
17
-
18
- var cmd = new Command("diff", "Compare two DOCX files")
19
- {
20
- beforeOption, afterOption, jsonOption
21
- };
22
-
23
- cmd.SetAction((parseResult) =>
24
- {
25
- var before = parseResult.GetValue(beforeOption)!;
26
- var after = parseResult.GetValue(afterOption)!;
27
- var asJson = parseResult.GetValue(jsonOption);
28
-
29
- if (!File.Exists(before)) { Console.Error.WriteLine($"File not found: {before}"); return; }
30
- if (!File.Exists(after)) { Console.Error.WriteLine($"File not found: {after}"); return; }
31
-
32
- var beforeParas = ExtractParagraphs(before);
33
- var afterParas = ExtractParagraphs(after);
34
- var beforeStyles = ExtractStyleIds(before);
35
- var afterStyles = ExtractStyleIds(after);
36
- var beforeStructure = ExtractStructure(before);
37
- var afterStructure = ExtractStructure(after);
38
-
39
- // Text diff
40
- var textChanges = new List<object>();
41
- int maxLen = Math.Max(beforeParas.Count, afterParas.Count);
42
- int changedParas = 0;
43
- for (int i = 0; i < maxLen; i++)
44
- {
45
- var bText = i < beforeParas.Count ? beforeParas[i] : null;
46
- var aText = i < afterParas.Count ? afterParas[i] : null;
47
-
48
- if (bText != aText)
49
- {
50
- changedParas++;
51
- textChanges.Add(new
52
- {
53
- paragraph = i + 1,
54
- before = bText ?? "(absent)",
55
- after = aText ?? "(absent)"
56
- });
57
- }
58
- }
59
-
60
- // Style diff
61
- var addedStyles = afterStyles.Except(beforeStyles).ToList();
62
- var removedStyles = beforeStyles.Except(afterStyles).ToList();
63
-
64
- // Structure diff
65
- var structureChanges = new List<string>();
66
- if (beforeStructure.Sections != afterStructure.Sections)
67
- structureChanges.Add($"Sections: {beforeStructure.Sections} -> {afterStructure.Sections}");
68
- if (beforeStructure.Tables != afterStructure.Tables)
69
- structureChanges.Add($"Tables: {beforeStructure.Tables} -> {afterStructure.Tables}");
70
- if (beforeStructure.Images != afterStructure.Images)
71
- structureChanges.Add($"Images: {beforeStructure.Images} -> {afterStructure.Images}");
72
-
73
- var result = new
74
- {
75
- textChanges,
76
- styleChanges = new { added = addedStyles, removed = removedStyles },
77
- structureChanges,
78
- summary = $"{changedParas} paragraphs changed, {addedStyles.Count + removedStyles.Count} styles modified, {structureChanges.Count} structural changes"
79
- };
80
-
81
- if (asJson)
82
- {
83
- Console.WriteLine(JsonSerializer.Serialize(result, new JsonSerializerOptions { WriteIndented = true }));
84
- }
85
- else
86
- {
87
- Console.WriteLine(result.summary);
88
- Console.WriteLine();
89
-
90
- if (textChanges.Count > 0)
91
- {
92
- Console.WriteLine($"Text changes ({textChanges.Count}):");
93
- foreach (var tc in textChanges.Take(20))
94
- Console.WriteLine($" {tc}");
95
- if (textChanges.Count > 20)
96
- Console.WriteLine($" ... and {textChanges.Count - 20} more");
97
- }
98
-
99
- if (addedStyles.Count > 0)
100
- Console.WriteLine($"Added styles: {string.Join(", ", addedStyles)}");
101
- if (removedStyles.Count > 0)
102
- Console.WriteLine($"Removed styles: {string.Join(", ", removedStyles)}");
103
-
104
- foreach (var sc in structureChanges)
105
- Console.WriteLine($"Structure: {sc}");
106
- }
107
- });
108
-
109
- return cmd;
110
- }
111
-
112
- private static List<string> ExtractParagraphs(string docxPath)
113
- {
114
- using var zip = ZipFile.OpenRead(docxPath);
115
- var entry = zip.GetEntry("word/document.xml");
116
- if (entry == null) return new();
117
-
118
- using var stream = entry.Open();
119
- var doc = XDocument.Load(stream);
120
- return doc.Descendants(W + "p")
121
- .Select(p => string.Concat(p.Descendants(W + "t").Select(t => t.Value)))
122
- .ToList();
123
- }
124
-
125
- private static HashSet<string> ExtractStyleIds(string docxPath)
126
- {
127
- using var zip = ZipFile.OpenRead(docxPath);
128
- var entry = zip.GetEntry("word/styles.xml");
129
- if (entry == null) return new();
130
-
131
- using var stream = entry.Open();
132
- var doc = XDocument.Load(stream);
133
- return doc.Descendants(W + "style")
134
- .Select(s => (string?)s.Attribute(W + "styleId"))
135
- .Where(id => id != null)
136
- .ToHashSet()!;
137
- }
138
-
139
- private record StructureInfo(int Sections, int Tables, int Images);
140
-
141
- private static StructureInfo ExtractStructure(string docxPath)
142
- {
143
- using var zip = ZipFile.OpenRead(docxPath);
144
- var entry = zip.GetEntry("word/document.xml");
145
- if (entry == null) return new(0, 0, 0);
146
-
147
- using var stream = entry.Open();
148
- var doc = XDocument.Load(stream);
149
- return new(
150
- doc.Descendants(W + "sectPr").Count(),
151
- doc.Descendants(W + "tbl").Count(),
152
- doc.Descendants(W + "drawing").Count()
153
- );
154
- }
155
- }