pdf-factory 0.2.1-beta.0 → 0.4.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.
package/README.md CHANGED
@@ -1,59 +1,204 @@
1
1
  # pdf-factory
2
2
 
3
- Generate tournament PDFs from TODS data — draw sheets, schedules, player lists, court cards.
3
+ Generate and parse tournament PDFs from [TODS](https://itftennis.atlassian.net/wiki/spaces/TODS/overview) (Tennis Open Data Standards) data. Draw sheets, schedules, player lists, court cards, sign-in sheets, and match cards — with Grand Slam and tour-level presets.
4
4
 
5
- ## Storybook
5
+ Part of the [CourtHive](https://github.com/CourtHive) ecosystem.
6
6
 
7
- Live examples and interactive documentation:
7
+ ## Storybook
8
8
 
9
- **https://courthive.github.io/pdf-factory/**
9
+ Live examples and interactive documentation: **https://courthive.github.io/pdf-factory/**
10
10
 
11
11
  ## Install
12
12
 
13
13
  ```bash
14
14
  pnpm add pdf-factory
15
+ # or
16
+ npm install pdf-factory
17
+ ```
18
+
19
+ ## Quick start
20
+
21
+ ### Generate a draw sheet
22
+
23
+ ```typescript
24
+ import { tournamentEngine } from 'tods-competition-factory';
25
+ import { generateDrawPDF } from 'pdf-factory';
26
+
27
+ // Load a TODS tournament record
28
+ tournamentEngine.setState(tournamentRecord);
29
+ const { drawIds } = tournamentEngine.getEvent({ eventId });
30
+
31
+ // Generate a PDF — returns a jsPDF doc
32
+ const doc = generateDrawPDF({
33
+ tournamentRecord,
34
+ drawId: drawIds[0],
35
+ preset: 'wimbledon', // or 'usOpen', 'rolandGarros', 'australianOpen', 'itfJunior', ...
36
+ });
37
+
38
+ // Output as bytes
39
+ const pdfBytes = doc.output('arraybuffer');
40
+ ```
41
+
42
+ ### Generate a schedule (Order of Play)
43
+
44
+ ```typescript
45
+ import { generateSchedulePDF, extractScheduleData } from 'pdf-factory';
46
+
47
+ const scheduleData = extractScheduleData({ tournamentRecord });
48
+ const doc = generateSchedulePDF({ scheduleData, tournamentRecord });
49
+ ```
50
+
51
+ ### Generate a player list
52
+
53
+ ```typescript
54
+ import { generatePlayerListPDF, extractParticipantData } from 'pdf-factory';
55
+
56
+ const participants = extractParticipantData({ tournamentRecord, eventId });
57
+ const doc = generatePlayerListPDF({ participants, tournamentRecord });
58
+ ```
59
+
60
+ ### Generate court cards
61
+
62
+ ```typescript
63
+ import { generateCourtCardPDF, extractCourtCardData } from 'pdf-factory';
64
+
65
+ const courtCards = extractCourtCardData({ tournamentRecord, eventId });
66
+ const doc = generateCourtCardPDF({ courtCards, tournamentRecord });
67
+ ```
68
+
69
+ ### Parse an existing PDF back to TODS
70
+
71
+ The parser entry point is separate (Node-only, depends on `pdf2json`):
72
+
73
+ ```typescript
74
+ import { parsePdfBuffer, extractDrawFromPage } from 'pdf-factory/parser';
75
+
76
+ const parsed = await parsePdfBuffer(pdfBuffer);
77
+ const draw = extractDrawFromPage(parsed.pages[0]);
78
+ // draw.participants, draw.scores, draw.seeds, ...
79
+ ```
80
+
81
+ ## Presets
82
+
83
+ Format presets control name display, score formatting, seed placement, round labels, and page layout. Built-in presets mirror real-world tournament PDFs:
84
+
85
+ | Preset | Style | Round labels |
86
+ | ---------------- | --------------------- | --------------------- |
87
+ | `wimbledon` | LAST, First (GBR) [1] | First Round ... Final |
88
+ | `usOpen` | LAST, First (USA) [1] | Round 1 ... Final |
89
+ | `rolandGarros` | LAST First (FRA) [1] | 1er TOUR ... FINALE |
90
+ | `australianOpen` | LAST, First (AUS) [1] | First Round ... Final |
91
+ | `itfJunior` | LAST, First (NAT) [1] | Round of 64 ... Final |
92
+ | `wtaTour` | LAST, First (NAT) [1] | First Round ... Final |
93
+
94
+ Presets are composable — start from a built-in and override individual fields:
95
+
96
+ ```typescript
97
+ import { getPreset, mergePreset } from 'pdf-factory';
98
+
99
+ const custom = mergePreset('wimbledon', {
100
+ nameFormat: 'First LAST',
101
+ showEntryStatus: true,
102
+ });
15
103
  ```
16
104
 
17
- ## Usage
105
+ ## Composition catalog
106
+
107
+ Higher-level composition presets bundle header layout, footer layout, draw format, and page config into named units. Categories: Grand Slam, Tour, ITF, National, Collegiate, Club.
18
108
 
19
109
  ```typescript
20
- import { generateDrawSheet, generateSchedule, generatePlayerList } from 'pdf-factory';
110
+ import { getCatalogPreset, listCatalogPresets } from 'pdf-factory';
111
+
112
+ const presets = listCatalogPresets(); // all available compositions
113
+ const wimbledon = getCatalogPreset('wimbledon');
114
+ ```
115
+
116
+ See the [Header & Footer Catalog](HEADER_FOOTER_CATALOG.md) for the three-tier footer system derived from real-world tournament PDFs.
117
+
118
+ ## Document types
119
+
120
+ | Generator | Description |
121
+ | ------------------------------ | ---------------------------------------------------------- |
122
+ | `generateDrawPDF` | Auto-selects renderer based on draw type |
123
+ | `generateTraditionalDrawPDF` | Single elimination bracket |
124
+ | `generateSplitDrawPDF` | Large draws split across pages (halves/quarters + summary) |
125
+ | `generateFeedInDrawPDF` | Feed-in consolation structures |
126
+ | `generateConsolationDrawPDF` | Consolation bracket |
127
+ | `generateCompassDrawPDF` | Compass (8-direction) draws |
128
+ | `generateDoubleEliminationPDF` | Winners + losers bracket |
129
+ | `generateLuckyDrawPDF` | Lucky loser draw |
130
+ | `generateMirroredDrawPDF` | Mirrored (left-right) bracket |
131
+ | `generateBackdrawPDF` | Backdraw structures |
132
+ | `generateSchedulePDF` | Order of Play (court grid) |
133
+ | `generateScheduleV2PDF` | Sequential schedule layout |
134
+ | `generateSequentialOOP` | Sequential Order of Play |
135
+ | `generatePlayerListPDF` | Participant list with seeds and rankings |
136
+ | `generateCourtCardPDF` | Per-court assignment cards |
137
+ | `generateSignInSheetPDF` | Player sign-in sheet |
138
+ | `generateMatchCardPDF` | Individual match scoring card |
139
+
140
+ ## Architecture
141
+
142
+ ```
143
+ TODS tournament record
144
+ → extractors (extractDrawData, extractScheduleData, ...)
145
+ → composition (page config + preset + header/footer)
146
+ → renderers (traditionalDraw, roundRobin, compass, ...)
147
+ → jsPDF document (Uint8Array or blob)
21
148
  ```
22
149
 
23
- All generators accept TODS tournament data and return jsPDF documents.
150
+ Parser pipeline (reverse direction):
151
+
152
+ ```
153
+ PDF file
154
+ → pdf2json extraction
155
+ → pdfRuler (spatial analysis, column/row detection)
156
+ → TODS structure mapping
157
+ ```
158
+
159
+ ### Source layout
160
+
161
+ ```
162
+ src/
163
+ config/ Presets (Grand Slam formats, page sizes, composition catalog)
164
+ core/ Data extractors (TODS → renderer-ready data)
165
+ composition/ Page composition, header/footer layouts, print dispatcher
166
+ generators/ High-level PDF generators (one per document type)
167
+ renderers/ Draw-type-specific renderers (bracket, round robin, compass, ...)
168
+ layout/ Page layout engine, header/footer primitives, fonts, tables
169
+ parser/ PDF-to-TODS extraction (Node-only, separate entry point)
170
+ comparison/ Visual regression utilities (pixel-level PDF comparison)
171
+ utils/ Shared formatting primitives
172
+ stories/ Storybook stories for visual development
173
+ ```
24
174
 
25
175
  ## Development
26
176
 
27
177
  ```bash
28
178
  pnpm install
29
- pnpm storybook # dev server on :6007
30
- pnpm test # vitest
179
+ pnpm storybook # interactive dev on :6007
180
+ pnpm test # vitest (watch mode)
31
181
  pnpm test:run # single run
32
182
  pnpm test:coverage # coverage report
33
183
  pnpm lint # eslint with fix
34
184
  pnpm check-types # tsc --noEmit
35
- pnpm build # vite build
185
+ pnpm build # vite library build → dist/
36
186
  ```
37
187
 
38
- ## Architecture
188
+ ### Testing
39
189
 
40
- ```
41
- src/
42
- generators/ PDF generators (draw sheets, schedules, player lists, court cards)
43
- renderers/ Low-level PDF rendering (traditional, round robin, lucky loser)
44
- parser/ PDF-to-TODS extraction (pdfRuler-based)
45
- composition/ PDF composition and layout assembly
46
- layout/ Page layout and positioning
47
- core/ Core types and shared logic
48
- config/ Presets (Grand Slam formats, page sizes)
49
- utils/ Shared utilities
50
- stories/ Storybook stories
51
- ```
190
+ Tests are split into two categories:
191
+
192
+ - **Generator tests** (always run) — generate PDFs from `mocksEngine` tournament data and verify output. No external fixtures needed.
193
+ - **Parser/fidelity tests** (local only) — parse third-party tournament PDFs in `fixtures/`. These are gitignored and skipped automatically in CI via `describe.skipIf(!hasFixtures)`.
194
+
195
+ To run parser tests locally, populate `fixtures/reference/` with PDF files (see `fixtures/reference/download-draws.sh`).
52
196
 
53
197
  ## Dependencies
54
198
 
55
- - [jsPDF](https://github.com/parallax/jsPDF) + [jspdf-autotable](https://github.com/simonbengtsson/jsPDF-AutoTable) for PDF generation
56
- - [tods-competition-factory](https://github.com/CourtHive/competition-factory) for tournament data structures
199
+ - [jsPDF](https://github.com/parallax/jsPDF) + [jspdf-autotable](https://github.com/simonbengtsson/jsPDF-AutoTable) — PDF generation
200
+ - [tods-competition-factory](https://github.com/CourtHive/competition-factory) — tournament data structures and engine
201
+ - [pdf2json](https://github.com/nicbou/pdf2json) — PDF parsing (parser entry point only)
57
202
 
58
203
  ## License
59
204
 
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return o}});