docgen-utils 1.0.18 → 1.0.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 (74) hide show
  1. package/README.md +63 -18
  2. package/dist/bundle.js +3466 -2528
  3. package/dist/bundle.min.js +242 -252
  4. package/dist/cli.js +3644 -2544
  5. package/dist/packages/cli/commands/export-docs.js +1 -1
  6. package/dist/packages/cli/commands/export-docs.js.map +1 -1
  7. package/dist/packages/cli/commands/export-slides.d.ts.map +1 -1
  8. package/dist/packages/cli/commands/export-slides.js +11 -7
  9. package/dist/packages/cli/commands/export-slides.js.map +1 -1
  10. package/dist/packages/cli/index.js.map +1 -1
  11. package/dist/packages/docs/common.d.ts +1 -0
  12. package/dist/packages/docs/common.d.ts.map +1 -1
  13. package/dist/packages/docs/convert.d.ts.map +1 -1
  14. package/dist/packages/docs/convert.js +6 -15
  15. package/dist/packages/docs/convert.js.map +1 -1
  16. package/dist/packages/docs/import-docx.d.ts.map +1 -1
  17. package/dist/packages/docs/import-docx.js +168 -82
  18. package/dist/packages/docs/import-docx.js.map +1 -1
  19. package/dist/packages/docs/parse-colors.d.ts +0 -5
  20. package/dist/packages/docs/parse-colors.d.ts.map +1 -1
  21. package/dist/packages/docs/parse-colors.js +2 -2
  22. package/dist/packages/docs/parse-colors.js.map +1 -1
  23. package/dist/packages/docs/parse-css.d.ts +0 -9
  24. package/dist/packages/docs/parse-css.d.ts.map +1 -1
  25. package/dist/packages/docs/parse-css.js +4 -6
  26. package/dist/packages/docs/parse-css.js.map +1 -1
  27. package/dist/packages/docs/parse-helpers.d.ts +0 -1
  28. package/dist/packages/docs/parse-helpers.d.ts.map +1 -1
  29. package/dist/packages/docs/parse-helpers.js +1 -1
  30. package/dist/packages/docs/parse-helpers.js.map +1 -1
  31. package/dist/packages/docs/parse-inline.d.ts +0 -13
  32. package/dist/packages/docs/parse-inline.d.ts.map +1 -1
  33. package/dist/packages/docs/parse-inline.js +7 -7
  34. package/dist/packages/docs/parse-inline.js.map +1 -1
  35. package/dist/packages/docs/parse-layout.d.ts.map +1 -1
  36. package/dist/packages/docs/parse-layout.js +1 -14
  37. package/dist/packages/docs/parse-layout.js.map +1 -1
  38. package/dist/packages/docs/parse-special.js +1 -1
  39. package/dist/packages/docs/parse-special.js.map +1 -1
  40. package/dist/packages/docs/parse.d.ts.map +1 -1
  41. package/dist/packages/docs/parse.js +76 -30
  42. package/dist/packages/docs/parse.js.map +1 -1
  43. package/dist/packages/shared/fetch-with-proxy.d.ts +13 -8
  44. package/dist/packages/shared/fetch-with-proxy.d.ts.map +1 -1
  45. package/dist/packages/shared/fetch-with-proxy.js +189 -22
  46. package/dist/packages/shared/fetch-with-proxy.js.map +1 -1
  47. package/dist/packages/shared/zip-guard.d.ts +37 -0
  48. package/dist/packages/shared/zip-guard.d.ts.map +1 -0
  49. package/dist/packages/shared/zip-guard.js +101 -0
  50. package/dist/packages/shared/zip-guard.js.map +1 -0
  51. package/dist/packages/slides/convert.d.ts +1 -3
  52. package/dist/packages/slides/convert.d.ts.map +1 -1
  53. package/dist/packages/slides/convert.js +8 -74
  54. package/dist/packages/slides/convert.js.map +1 -1
  55. package/dist/packages/slides/createPresentation.d.ts +1 -1
  56. package/dist/packages/slides/createPresentation.d.ts.map +1 -1
  57. package/dist/packages/slides/createPresentation.js +1 -10
  58. package/dist/packages/slides/createPresentation.js.map +1 -1
  59. package/dist/packages/slides/import-pptx.d.ts.map +1 -1
  60. package/dist/packages/slides/import-pptx.js +5 -7
  61. package/dist/packages/slides/import-pptx.js.map +1 -1
  62. package/dist/packages/slides/parse.d.ts +0 -22
  63. package/dist/packages/slides/parse.d.ts.map +1 -1
  64. package/dist/packages/slides/parse.js +38 -42
  65. package/dist/packages/slides/parse.js.map +1 -1
  66. package/dist/packages/slides/transform.d.ts.map +1 -1
  67. package/dist/packages/slides/transform.js +1 -5
  68. package/dist/packages/slides/transform.js.map +1 -1
  69. package/dist/packages/slides/vendor/VENDORING.md +2 -2
  70. package/package.json +16 -10
  71. package/dist/packages/cli/commands/common.d.ts +0 -2
  72. package/dist/packages/cli/commands/common.d.ts.map +0 -1
  73. package/dist/packages/cli/commands/common.js +0 -22
  74. package/dist/packages/cli/commands/common.js.map +0 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # DocGen
2
2
 
3
- Converts HTML into DOCX, PPTX and vice versa.
3
+ Converts HTML into DOCX, PPTX and vice versa. Runs in browsers (via bundled JS) and Node.js (via CLI). Published as `docgen-utils` on npm.
4
4
 
5
5
  ## Key Components
6
6
 
@@ -8,41 +8,52 @@ Converts HTML into DOCX, PPTX and vice versa.
8
8
 
9
9
  | File | Description |
10
10
  | ---------- | -------------------------------------------------------------- |
11
- | `build.sh` | Builds the library |
11
+ | `build.sh` | Builds the library (TypeScript → esbuild bundles) |
12
12
  | `dist/` | Output directory containing production-ready minified JS files |
13
13
 
14
+ ### Package Structure
15
+
16
+ | Package | Description |
17
+ | ------------------ | --------------------------------------------------------------------------------- |
18
+ | `packages/docs/` | DOCX pipeline — 13 TypeScript files for HTML↔DOCX conversion |
19
+ | `packages/slides/` | PPTX pipeline — 8 TypeScript files + vendored PptxGenJS for HTML↔PPTX conversion |
20
+ | `packages/shared/` | Cross-cutting utilities — DOM parser shim, proxy-aware HTTP client, font mappings |
21
+ | `packages/cli/` | Node.js CLI (`docgen` command) — dispatches to import/export subcommands |
22
+
14
23
  ## Usage
15
24
 
16
- ### Build
25
+ ## Install dependencies
17
26
 
18
27
  ```bash
19
- npm run build
28
+ npm install --registry=https://registry.npmjs.org
20
29
  ```
21
30
 
22
- ### CLI
23
- The CLI is used in the agent sandbox to transform artifacts.
31
+ ### Build
24
32
 
25
33
  ```bash
26
- node dist/cli.js import docx --file=file.docx --out-dir=./output
27
- node dist/cli.js import pptx --file=file.pptx --out-dir=./output
28
- node dist/cli.js export docs --file=file.html --out-dir=./output
29
- node dist/cli.js export slides --files=slide-1.html,slide-2.html --out-dir=./output
34
+ npm run build
30
35
  ```
31
36
 
32
- ### Deploy
37
+ ### CLI
38
+
39
+ The CLI is used in the agent sandbox to transform artifacts.
33
40
 
34
41
  ```bash
35
- az login
36
- npm run deploy
42
+ alias docgen='npx tsx packages/cli'
43
+ docgen import docx --file=file.docx --out-dir=./output [--name=<filename>]
44
+ docgen import pptx --file=file.pptx --out-dir=./output [--name=<filename>]
45
+ docgen export docs --file=file.html --out-dir=./output [--name=<filename>] [--pageless]
46
+ docgen export slides --files=slide-1.html,slide-2.html --out-dir=./output [--name=<filename>]
37
47
  ```
38
48
 
39
49
  ## Visual Comparison
40
50
 
41
51
  The `output` directory contains the rendered output in target formats. e.g. DOCX or PPTX vs HTML
42
52
 
43
- - Files in `test-data/docs/` → converted to DOCX → `docx-render.jpg`
44
- - Files in `test-data/slides/` → converted to PPTX → `pptx-render.jpg`
45
- - Files in `test-data/pptx/` → imported to HTML → `html-render.jpg`
53
+ - Files in `test-data/docs/` (27 HTML files) → converted to DOCX → `docx-render.jpg`
54
+ - Files in `test-data/slides/` (90 HTML files) → converted to PPTX → `pptx-render.jpg`
55
+ - Files in `test-data/pptx/` (145 PPTX files) → imported to HTML → `html-render.jpg`
56
+ - Files in `test-data/docx/` (22 DOCX files) → imported to HTML → `html-render.jpg`
46
57
 
47
58
  ### Prerequisites
48
59
 
@@ -79,11 +90,39 @@ Import a PPTX file (PPTX -> HTML):
79
90
  npm run generate-output -- test-data/pptx/presentation.pptx
80
91
  ```
81
92
 
93
+ Import a DOCX file (DOCX -> HTML):
94
+
95
+ ```bash
96
+ npm run generate-output -- test-data/docx/document.docx
97
+ ```
98
+
82
99
  Process multiple files:
83
100
 
84
101
  ```bash
85
- npm run generate-all-docs-output # All docs
86
- npm run generate-all-slides-output # All slides
102
+ npm run generate-all-docs-output # All docs (HTML→DOCX)
103
+ npm run generate-all-slides-output # All slides (HTML→PPTX)
104
+ npm run generate-all-docx-output # All DOCX imports (DOCX→HTML)
105
+ npm run generate-all-pptx-output # All PPTX imports (PPTX→HTML)
106
+ ```
107
+
108
+ ### Roundtrip Testing
109
+
110
+ Full roundtrip tests convert HTML→DOCX/PPTX→HTML and compare the result:
111
+
112
+ ```bash
113
+ npm run roundtrip -- test-data/docs/doc-1.html # Single doc roundtrip
114
+ npm run roundtrip -- test-data/slides/slide-1.html # Single slide roundtrip
115
+ npm run roundtrip-all-docs # All docs (no AI diff)
116
+ npm run roundtrip-all-slides # All slides (no AI diff)
117
+ ```
118
+
119
+ ### AI-Powered Visual Diff
120
+
121
+ Compare two rendered images using Claude vision API (requires `ANTHROPIC_API_KEY`):
122
+
123
+ ```bash
124
+ npm run ai-diff <image1.jpg> <image2.jpg>
125
+ npm run ai-diff -- <image1.jpg> <image2.jpg> --question="Is the text shadow rendering correctly?"
87
126
  ```
88
127
 
89
128
  ### Output
@@ -110,10 +149,16 @@ output/
110
149
  │ ├── diff.jpg # Visual diff highlighting differences
111
150
  │ ├── output.html # Generated HTML (all slides concatenated)
112
151
  │ └── report.json # Comparison metrics
152
+ ├── metrics.json # Aggregated quality metrics across all tests
113
153
  └── ...
114
154
  ```
115
155
 
156
+ ### Quality Metrics
157
+
158
+ A pre-commit hook automatically aggregates all `report.json` files into `output/metrics.json`, tracking quality baselines by conversion type (docx-export, pptx-export, docx-import, pptx-import).
159
+
116
160
  **Metrics explained:**
117
161
 
118
162
  - **pixelDiff.percentDiff** - Percentage of pixels that differ between the two images (lower is better)
119
163
  - **ssim.mssim** - Structural Similarity Index (0-1, higher is better). Values above 0.9 indicate very similar images
164
+ - **Quality Score** - Composite score 0-100 for roundtrip tests (target ≥85)