pretext-pdf 0.9.2 → 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,32 @@ 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
+
10
36
  ## [0.9.2] — 2026-04-22
11
37
 
12
38
  Maintenance release. Engine refresh + repo-hygiene automation. No runtime behavior changes beyond the `@chenglou/pretext` bump.
@@ -22,7 +48,7 @@ Maintenance release. Engine refresh + repo-hygiene automation. No runtime behavi
22
48
  ### Added
23
49
 
24
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.
25
- - `.github/workflows/release-on-tag.yml` — on `v*` tag push, auto-extracts the matching `## [X.Y.Z]` section from this file and creates the GitHub release. Closes the "tag exists but no release page" gap that affected v0.9.1.
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.)
26
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.
27
53
 
28
54
  ### Removed
@@ -484,112 +510,3 @@ Three additive enhancements that broaden the package's surface without growing i
484
510
  - Image formats: PNG, JPG, WebP
485
511
  - Table features: custom column widths, cell padding, borders, header styling
486
512
  - Colors: hex color codes throughout (text, backgrounds, borders)
487
-
488
- ---
489
-
490
- ## Features by Phase
491
-
492
- | Phase | Feature | Status | Tests | Version |
493
- |-------|---------|--------|-------|---------|
494
- | 7A | Bookmarks / PDF Outline | ✅ Complete | 8 | 0.1.0 |
495
- | 7B | Watermarks | ✅ Complete | 8 | 0.1.0 |
496
- | 7C | Hyphenation | ✅ Complete | 10 | 0.1.0 |
497
- | 7D | Table of Contents | ✅ Complete | 10 | 0.1.0 |
498
- | 7E | SVG Support | ✅ Complete | 8 | 0.1.0 |
499
- | 7F | RTL Text Support | ✅ Complete | 12 | 0.1.0 |
500
- | 7G | Encryption | ✅ Complete | 7 | 0.1.0 |
501
- | Integration | Feature Combinations | ✅ Complete | 6 | 0.1.0 |
502
- | 6 | Advanced Features | ✅ Complete | — | 0.1.0 |
503
- | 5 | Rich Text / Builder API | ✅ Complete | — | 0.1.0 |
504
- | 1–4 | Core Engine | ✅ Complete | — | 0.1.0 |
505
-
506
- ---
507
-
508
- ## How to Use Examples
509
-
510
- All Phase 7 features have working examples in the `examples/` directory. Run them with:
511
-
512
- ```bash
513
- npm run example:watermark # Phase 7B — Watermarks
514
- npm run example:bookmarks # Phase 7A — Bookmarks
515
- npm run example:toc # Phase 7D — Table of Contents
516
- npm run example:rtl # Phase 7F — RTL Text Support
517
- npm run example:encryption # Phase 7G — Encryption
518
- ```
519
-
520
- PDF output is written to `output/phase7-*.pdf`.
521
-
522
- ---
523
-
524
- ## Test Coverage
525
-
526
- All phases include comprehensive test coverage:
527
-
528
- ```bash
529
- npm test # Run all 75+ tests
530
- npm run test:unit # Unit tests only
531
- npm run test:e2e # End-to-end tests
532
- npm run test:visual # Visual regression tests
533
- ```
534
-
535
- ---
536
-
537
- ## Dependencies
538
-
539
- ### Required
540
-
541
- - `@chenglou/pretext` — Pretext text layout engine
542
- - `pdf-lib` — PDF document manipulation
543
- - `@fontsource/inter` — Font: Inter (bundled)
544
- - `bidi-js` — Bidirectional text algorithm (Phase 7F)
545
- - `hypher` — Hyphenation algorithm (Phase 7C)
546
- - `hyphenation.en-us` — English hyphenation patterns (Phase 7C)
547
-
548
- ### Optional (Peer)
549
-
550
- - `@napi-rs/canvas` — SVG rasterization (Phase 7E)
551
- - `@cantoo/pdf-lib` — PDF encryption (Phase 7G)
552
-
553
- ---
554
-
555
- ## Architecture
556
-
557
- pretext-pdf uses a modular, layered architecture:
558
-
559
- ```
560
- render(doc) → validate → layout → paginate → render-pages → PDF bytes
561
- ```
562
-
563
- Each phase adds features orthogonally:
564
- - Phase 1–4: Core engine, pagination, typography
565
- - Phase 5: Rich text and builder patterns
566
- - Phase 6: Advanced layout and formatting
567
- - Phase 7: Security, internationalization, accessibility
568
-
569
- ---
570
-
571
- ## Future Roadmap
572
-
573
- Potential Phase 8+ features (not yet implemented):
574
- - Hyperlinks and anchors
575
- - Justified text alignment
576
- - Enhanced text decorations
577
- - Font subsetting for file size reduction
578
- - Browser compatibility improvements
579
- - Performance optimizations
580
-
581
- ---
582
-
583
- ## Contributing
584
-
585
- pretext-pdf is actively maintained. To report issues, request features, or contribute:
586
-
587
- 1. Check existing issues on the project repo
588
- 2. Write failing tests first (TDD)
589
- 3. Submit pull requests with test coverage ≥80%
590
-
591
- ---
592
-
593
- ## License
594
-
595
- Check LICENSE file in repository root.