pretext-pdf 0.9.1 → 0.9.3

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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,61 @@ Format: [Keep a Changelog 1.1.0](https://keepachangelog.com/en/1.1.0/)
7
7
 
8
8
  ---
9
9
 
10
+ ## [0.9.3] — 2026-04-23
11
+
12
+ Strict validation release. Opt-in property validation to catch unknown properties on elements and sub-structures via typo detection and precise JSONPath error reporting.
13
+
14
+ ### Added
15
+
16
+ - **Strict validation mode**: Pass `{ strict: true }` to `render(doc, options)` to reject unknown properties. Non-strict mode (default) remains permissive for backwards compatibility.
17
+ - **`render()` options parameter**: Updated signature to `render(doc: PdfDocument, options?: RenderOptions)` where `RenderOptions = { strict?: boolean }`.
18
+ - **`validate()` public export**: `validate()` is now exported from `pretext-pdf` for standalone validation and testing.
19
+ - **Validation error details**:
20
+ - Unknown properties reported with Levenshtein edit-distance suggestions (distance ≤2) for typo correction.
21
+ - Errors include JSONPath-like paths (`content[3].table.rows[0].cells[1].align`) for precise location reporting.
22
+ - Error accumulation: all violations collected before throwing a single VALIDATION_ERROR with formatted multi-line message.
23
+ - First 20 errors shown; overflow indicator present.
24
+ - **Compile-time drift guards**: `src/allowed-props.ts` uses `Exact<T, Keys>` TypeScript type assertions to catch property definition drift at type-check time. If element types change, `tsc --noEmit` will error if allowed-props lists don't match.
25
+ - **Property allowlists**:
26
+ - `ALLOWED_PROPS`: 22 element types (paragraph, heading, table, image, code, list, etc.)
27
+ - `ALLOWED_PROPS_SUB`: 8 sub-structures (document, metadata, table-row, table-cell, list-item, inline-span, column-def, annotation)
28
+
29
+ ### Internal
30
+
31
+ - `src/allowed-props.ts` (new): Central configuration for allowed properties with compile-time assertions.
32
+ - `src/validate.ts` (enhanced): Added `levenshteinDist()`, `closestMatch()`, `assertUnknownProps()`, and `formatErrors()` helpers; threading strict flag through `validateElement()` for nested structure validation (tables, lists, rich-paragraphs, float-groups, annotations).
33
+
34
+ ---
35
+
36
+ ## [0.9.2] — 2026-04-22
37
+
38
+ Maintenance release. Engine refresh + repo-hygiene automation. No runtime behavior changes beyond the `@chenglou/pretext` bump.
39
+
40
+ ### Changed
41
+
42
+ - **Bumped `@chenglou/pretext` to 0.0.6** (from 0.0.5). Brings two upstream improvements: (a) CJK text followed by opening-bracket annotations now wraps like browsers instead of leaving the opening bracket on the previous line (upstream PR #148), (b) native numeric `letterSpacing` support on `prepare()` and `prepareWithSegments()` (upstream PRs #108/#156). Our manual letterSpacing compensation in `src/measure-blocks.ts` and `src/rich-text.ts` continues to work unchanged — delegating to pretext's native path is tracked as Tier 1 follow-up in `docs/ROADMAP.md`. All 624 tests green, all 5 visual regression baselines green.
43
+
44
+ ### Fixed
45
+
46
+ - **README badges matched to reality**: `runtime-deps-7` → `runtime-deps-8` (there are 8 direct `dependencies`, not 7), `tests-600+` → `tests-624` (the full `npm test` chain runs 624 tests across 5 subsuites). Drift guarded by a new CI step; see below.
47
+
48
+ ### Added
49
+
50
+ - `scripts/verify-badges.js` + CI step — compares README shields.io badge values against `package.json` dep count and `npm test` total. Fails CI on drift. Fast path via `SKIP_TEST_RUN=1` for pre-commit use.
51
+ - `release` job in `ci.yml` — on `v*` tag push, auto-extracts the matching `## [X.Y.Z]` section from this file and creates the GitHub release (requires publish to succeed first). Closes the "tag exists but no release page" gap that affected v0.9.1. (Note: originally shipped as `.github/workflows/release-on-tag.yml`; merged into `ci.yml` for dependency ordering in Tier 0.5.)
52
+ - `renovate.json` — watches dependencies, auto-merges devDependency bumps that pass CI, opens PRs (without auto-merge) for runtime, peer, and `@chenglou/pretext` engine bumps. Closes the gap that left us one release behind upstream.
53
+
54
+ ### Removed
55
+
56
+ - `test/smoke-staging.test.ts` — exercised a non-existent `{ type: 'paragraph', footnote: {...} }` shape that the permissive validator silently accepted. False coverage. A strict validator rollout (rejecting unknown element properties) is the root fix and is tracked as a Tier 1 item in the rewritten `docs/ROADMAP.md`.
57
+ - `src/brain/` — inert auto-logger artifact (34 blank-body entries, no active writer). Never published to npm.
58
+
59
+ ### Docs
60
+
61
+ - `docs/ROADMAP.md` — complete rewrite as a living document (Now / Next / Under consideration / Shipped / History + Update discipline). The previous "master remediation plan" with phase-numbered sections was dropped: phases 0–5 all shipped by v0.9.1, and the document had rotted to the point of contradicting `package.json` on dependency pinning and `CHANGELOG.md` on what was live. History section preserves the prior plan's origin date and scope for reference.
62
+
63
+ ---
64
+
10
65
  ## [0.9.1] — 2026-04-21
11
66
 
12
67
  Bug-fix + hardening release. Ships the callout + rich-text rendering fixes from PR #2 together with PR #3's producer-validator contract around measured blocks.
@@ -455,112 +510,3 @@ Three additive enhancements that broaden the package's surface without growing i
455
510
  - Image formats: PNG, JPG, WebP
456
511
  - Table features: custom column widths, cell padding, borders, header styling
457
512
  - Colors: hex color codes throughout (text, backgrounds, borders)
458
-
459
- ---
460
-
461
- ## Features by Phase
462
-
463
- | Phase | Feature | Status | Tests | Version |
464
- |-------|---------|--------|-------|---------|
465
- | 7A | Bookmarks / PDF Outline | ✅ Complete | 8 | 0.1.0 |
466
- | 7B | Watermarks | ✅ Complete | 8 | 0.1.0 |
467
- | 7C | Hyphenation | ✅ Complete | 10 | 0.1.0 |
468
- | 7D | Table of Contents | ✅ Complete | 10 | 0.1.0 |
469
- | 7E | SVG Support | ✅ Complete | 8 | 0.1.0 |
470
- | 7F | RTL Text Support | ✅ Complete | 12 | 0.1.0 |
471
- | 7G | Encryption | ✅ Complete | 7 | 0.1.0 |
472
- | Integration | Feature Combinations | ✅ Complete | 6 | 0.1.0 |
473
- | 6 | Advanced Features | ✅ Complete | — | 0.1.0 |
474
- | 5 | Rich Text / Builder API | ✅ Complete | — | 0.1.0 |
475
- | 1–4 | Core Engine | ✅ Complete | — | 0.1.0 |
476
-
477
- ---
478
-
479
- ## How to Use Examples
480
-
481
- All Phase 7 features have working examples in the `examples/` directory. Run them with:
482
-
483
- ```bash
484
- npm run example:watermark # Phase 7B — Watermarks
485
- npm run example:bookmarks # Phase 7A — Bookmarks
486
- npm run example:toc # Phase 7D — Table of Contents
487
- npm run example:rtl # Phase 7F — RTL Text Support
488
- npm run example:encryption # Phase 7G — Encryption
489
- ```
490
-
491
- PDF output is written to `output/phase7-*.pdf`.
492
-
493
- ---
494
-
495
- ## Test Coverage
496
-
497
- All phases include comprehensive test coverage:
498
-
499
- ```bash
500
- npm test # Run all 75+ tests
501
- npm run test:unit # Unit tests only
502
- npm run test:e2e # End-to-end tests
503
- npm run test:visual # Visual regression tests
504
- ```
505
-
506
- ---
507
-
508
- ## Dependencies
509
-
510
- ### Required
511
-
512
- - `@chenglou/pretext` — Pretext text layout engine
513
- - `pdf-lib` — PDF document manipulation
514
- - `@fontsource/inter` — Font: Inter (bundled)
515
- - `bidi-js` — Bidirectional text algorithm (Phase 7F)
516
- - `hypher` — Hyphenation algorithm (Phase 7C)
517
- - `hyphenation.en-us` — English hyphenation patterns (Phase 7C)
518
-
519
- ### Optional (Peer)
520
-
521
- - `@napi-rs/canvas` — SVG rasterization (Phase 7E)
522
- - `@cantoo/pdf-lib` — PDF encryption (Phase 7G)
523
-
524
- ---
525
-
526
- ## Architecture
527
-
528
- pretext-pdf uses a modular, layered architecture:
529
-
530
- ```
531
- render(doc) → validate → layout → paginate → render-pages → PDF bytes
532
- ```
533
-
534
- Each phase adds features orthogonally:
535
- - Phase 1–4: Core engine, pagination, typography
536
- - Phase 5: Rich text and builder patterns
537
- - Phase 6: Advanced layout and formatting
538
- - Phase 7: Security, internationalization, accessibility
539
-
540
- ---
541
-
542
- ## Future Roadmap
543
-
544
- Potential Phase 8+ features (not yet implemented):
545
- - Hyperlinks and anchors
546
- - Justified text alignment
547
- - Enhanced text decorations
548
- - Font subsetting for file size reduction
549
- - Browser compatibility improvements
550
- - Performance optimizations
551
-
552
- ---
553
-
554
- ## Contributing
555
-
556
- pretext-pdf is actively maintained. To report issues, request features, or contribute:
557
-
558
- 1. Check existing issues on the project repo
559
- 2. Write failing tests first (TDD)
560
- 3. Submit pull requests with test coverage ≥80%
561
-
562
- ---
563
-
564
- ## License
565
-
566
- Check LICENSE file in repository root.