pdf-factory 0.2.1-beta.0 → 0.3.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 +170 -25
- package/dist/src/__tests__/fixtureGuard.d.ts +11 -0
- package/dist/src/__tests__/fixtureGuard.d.ts.map +1 -0
- package/package.json +18 -25
package/README.md
CHANGED
|
@@ -1,59 +1,204 @@
|
|
|
1
1
|
# pdf-factory
|
|
2
2
|
|
|
3
|
-
Generate tournament PDFs from TODS data
|
|
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
|
-
|
|
5
|
+
Part of the [CourtHive](https://github.com/CourtHive) ecosystem.
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
##
|
|
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 {
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
188
|
+
### Testing
|
|
39
189
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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)
|
|
56
|
-
- [tods-competition-factory](https://github.com/CourtHive/competition-factory)
|
|
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,11 @@
|
|
|
1
|
+
export declare const FIXTURES_DIR: string;
|
|
2
|
+
export declare const REFERENCE_DIR: string;
|
|
3
|
+
/**
|
|
4
|
+
* True when the local fixtures/ directory exists.
|
|
5
|
+
* Parser and fidelity tests depend on third-party PDFs that are
|
|
6
|
+
* gitignored (too large / redistribution concerns). These tests
|
|
7
|
+
* run locally but are skipped in CI where fixtures/ is absent.
|
|
8
|
+
*/
|
|
9
|
+
export declare const hasFixtures: boolean;
|
|
10
|
+
export declare const hasReferenceFixtures: boolean;
|
|
11
|
+
//# sourceMappingURL=fixtureGuard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtureGuard.d.ts","sourceRoot":"","sources":["../../../src/__tests__/fixtureGuard.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,QAAuC,CAAC;AACjE,eAAO,MAAM,aAAa,QAAqC,CAAC;AAEhE;;;;;GAKG;AACH,eAAO,MAAM,WAAW,SAA2B,CAAC;AACpD,eAAO,MAAM,oBAAoB,SAA4B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-factory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Generate tournament PDFs from TODS data — draw sheets, schedules, player lists, court cards",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "CourtHive",
|
|
@@ -46,24 +46,6 @@
|
|
|
46
46
|
"files": [
|
|
47
47
|
"dist"
|
|
48
48
|
],
|
|
49
|
-
"scripts": {
|
|
50
|
-
"build": "vite build",
|
|
51
|
-
"check-types": "tsc --noEmit",
|
|
52
|
-
"commit": "git-cz",
|
|
53
|
-
"commitlint": "commitlint --edit",
|
|
54
|
-
"format": "prettier --write src",
|
|
55
|
-
"lint": "eslint src --fix --cache",
|
|
56
|
-
"lint:staged": "TZ=UTC lint-staged",
|
|
57
|
-
"pre-commit": "lint-staged",
|
|
58
|
-
"prepare": "husky",
|
|
59
|
-
"storybook": "storybook dev -p 6007",
|
|
60
|
-
"build-storybook": "storybook build",
|
|
61
|
-
"test": "TZ=UTC vitest",
|
|
62
|
-
"test:run": "TZ=UTC vitest run",
|
|
63
|
-
"test:coverage": "TZ=UTC vitest run --coverage",
|
|
64
|
-
"test:ui": "vitest --ui",
|
|
65
|
-
"prepublishOnly": "pnpm build && ./addVersion $npm_package_version"
|
|
66
|
-
},
|
|
67
49
|
"lint-staged": {
|
|
68
50
|
"*.{js,ts}": "eslint --cache --fix",
|
|
69
51
|
"*": "prettier --ignore-unknown --write"
|
|
@@ -76,7 +58,7 @@
|
|
|
76
58
|
"dependencies": {
|
|
77
59
|
"jspdf": "^4.2.1",
|
|
78
60
|
"jspdf-autotable": "^5.0.7",
|
|
79
|
-
"tods-competition-factory": "
|
|
61
|
+
"tods-competition-factory": "^3.0.1"
|
|
80
62
|
},
|
|
81
63
|
"devDependencies": {
|
|
82
64
|
"@commitlint/cli": "^20.5.0",
|
|
@@ -108,9 +90,20 @@
|
|
|
108
90
|
"vite-plugin-dts": "^4.5.4",
|
|
109
91
|
"vitest": "^4.1.2"
|
|
110
92
|
},
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
|
|
93
|
+
"scripts": {
|
|
94
|
+
"build": "vite build",
|
|
95
|
+
"check-types": "tsc --noEmit",
|
|
96
|
+
"commit": "git-cz",
|
|
97
|
+
"commitlint": "commitlint --edit",
|
|
98
|
+
"format": "prettier --write src",
|
|
99
|
+
"lint": "eslint src --fix --cache",
|
|
100
|
+
"lint:staged": "TZ=UTC lint-staged",
|
|
101
|
+
"pre-commit": "lint-staged",
|
|
102
|
+
"storybook": "storybook dev -p 6007",
|
|
103
|
+
"build-storybook": "storybook build",
|
|
104
|
+
"test": "TZ=UTC vitest",
|
|
105
|
+
"test:run": "TZ=UTC vitest run",
|
|
106
|
+
"test:coverage": "TZ=UTC vitest run --coverage",
|
|
107
|
+
"test:ui": "vitest --ui"
|
|
115
108
|
}
|
|
116
|
-
}
|
|
109
|
+
}
|