@shuji-bonji/pdf-reader-mcp 0.16.1 → 0.18.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +44 -1
  2. package/README.ja.md +12 -27
  3. package/README.md +11 -26
  4. package/dist/index.js +3 -2
  5. package/dist/index.js.map +1 -1
  6. package/dist/schemas/tier3.d.ts +0 -12
  7. package/dist/schemas/tier3.d.ts.map +1 -1
  8. package/dist/schemas/tier3.js +0 -14
  9. package/dist/schemas/tier3.js.map +1 -1
  10. package/dist/services/page-renderer.d.ts +19 -0
  11. package/dist/services/page-renderer.d.ts.map +1 -1
  12. package/dist/services/page-renderer.js +32 -15
  13. package/dist/services/page-renderer.js.map +1 -1
  14. package/dist/services/pdfjs-service.d.ts +1 -6
  15. package/dist/services/pdfjs-service.d.ts.map +1 -1
  16. package/dist/services/pdfjs-service.js +0 -98
  17. package/dist/services/pdfjs-service.js.map +1 -1
  18. package/dist/services/validation-service.d.ts +4 -45
  19. package/dist/services/validation-service.d.ts.map +1 -1
  20. package/dist/services/validation-service.js +4 -662
  21. package/dist/services/validation-service.js.map +1 -1
  22. package/dist/tools/index.d.ts.map +1 -1
  23. package/dist/tools/index.js +0 -4
  24. package/dist/tools/index.js.map +1 -1
  25. package/dist/types.d.ts +0 -50
  26. package/dist/types.d.ts.map +1 -1
  27. package/dist/utils/formatter.d.ts +1 -9
  28. package/dist/utils/formatter.d.ts.map +1 -1
  29. package/dist/utils/formatter.js +1 -78
  30. package/dist/utils/formatter.js.map +1 -1
  31. package/package.json +1 -1
  32. package/dist/tools/tier3/validate-metadata.d.ts +0 -6
  33. package/dist/tools/tier3/validate-metadata.d.ts.map +0 -1
  34. package/dist/tools/tier3/validate-metadata.js +0 -73
  35. package/dist/tools/tier3/validate-metadata.js.map +0 -1
  36. package/dist/tools/tier3/validate-tagged.d.ts +0 -6
  37. package/dist/tools/tier3/validate-tagged.d.ts.map +0 -1
  38. package/dist/tools/tier3/validate-tagged.js +0 -74
  39. package/dist/tools/tier3/validate-tagged.js.map +0 -1
@@ -1,608 +1,17 @@
1
1
  /**
2
2
  * Validation & comparison service for Tier 3 tools.
3
3
  *
4
- * Provides PDF/UA tag validation, metadata conformance checks,
5
- * and structural comparison between two PDFs.
4
+ * Provides structural comparison between two PDFs (`compare_structure`).
5
+ * The PDF/UA tag and metadata checks (`validate_tagged` / `validate_metadata`)
6
+ * were removed — pass/fail against a standard belongs to pdf-verify-mcp.
6
7
  */
7
8
  import { basename } from 'node:path';
8
9
  import { PdfReaderError } from '../utils/error-handler.js';
9
10
  import { formatFileSize } from '../utils/formatter.js';
10
11
  import { analyzeFonts } from './font-service.js';
11
- import { analyzeTagsFromDoc, countImagesFromDoc, getMetadata, loadDocument, } from './pdfjs-service.js';
12
+ import { getMetadata } from './pdfjs-service.js';
12
13
  import { half } from './reading-scope.js';
13
14
  import { analyzeStructure } from './structure-service.js';
14
- // ─── validate_tagged ─────────────────────────────────────
15
- /**
16
- * Validate PDF/UA tagged structure requirements.
17
- *
18
- * Checks performed:
19
- * - Document is marked as tagged
20
- * - Structure tree root exists
21
- * - Document-level root tag present
22
- * - Heading hierarchy (H1-H6) is sequential
23
- * - Figure tags have content (potential alt text)
24
- * - Table tags are present when expected
25
- * - Minimum structure depth
26
- */
27
- export async function validateTagged(filePath) {
28
- const issues = [];
29
- let totalChecks = 0;
30
- let passed = 0;
31
- let failed = 0;
32
- let warnings = 0;
33
- // ドキュメントを1回だけロードし、タグ解析と画像カウントで共有
34
- const doc = await loadDocument(filePath);
35
- let tagsAnalysis;
36
- // 🔴 画像の数は観測できないことがある。0 と null は違う ——
37
- // 0 は「画像は無いと観測した」、null は「数えられなかった」で、
38
- // null を 0 として扱うと TAG-005 が「画像が無いので Figure も要らない」と
39
- // 判定して合格を出す。観測していないことが合格の顔をする。
40
- let imageCount = null;
41
- const notChecked = [];
42
- try {
43
- // タグ解析と画像カウントは別々に失敗しうる。Promise.all に入れると、
44
- // 画像を数えられなかっただけでタグの検査が 1 つも行われなくなる。
45
- const [tags, images] = await Promise.all([
46
- analyzeTagsFromDoc(doc),
47
- half(() => countImagesFromDoc(doc)),
48
- ]);
49
- tagsAnalysis = tags;
50
- imageCount = images.ok ? images.value : null;
51
- if (!images.ok) {
52
- notChecked.push({
53
- code: 'TAG-005',
54
- reason: `the image count could not be observed: ${images.outcome.reason}`,
55
- });
56
- }
57
- }
58
- finally {
59
- await doc.destroy();
60
- }
61
- // Check 1: Is the document tagged?
62
- totalChecks++;
63
- if (!tagsAnalysis.isTagged) {
64
- failed++;
65
- issues.push({
66
- severity: 'error',
67
- code: 'TAG-001',
68
- message: 'Document is not tagged',
69
- details: 'The PDF does not have the Marked flag set in the MarkInfo dictionary. Tagged PDF is required for PDF/UA compliance.',
70
- });
71
- return {
72
- isTagged: false,
73
- totalChecks,
74
- passed,
75
- failed,
76
- warnings,
77
- issues,
78
- summary: 'Document is not tagged. PDF/UA validation cannot proceed.',
79
- };
80
- }
81
- passed++;
82
- issues.push({
83
- severity: 'info',
84
- code: 'TAG-001',
85
- message: 'Document is marked as tagged',
86
- });
87
- // Check 2: Structure tree root exists
88
- totalChecks++;
89
- if (!tagsAnalysis.rootTag) {
90
- failed++;
91
- issues.push({
92
- severity: 'error',
93
- code: 'TAG-002',
94
- message: 'No structure tree root found',
95
- details: 'The document is marked as tagged but has no StructTreeRoot.',
96
- });
97
- }
98
- else {
99
- passed++;
100
- issues.push({
101
- severity: 'info',
102
- code: 'TAG-002',
103
- message: 'Structure tree root exists',
104
- });
105
- }
106
- // Check 3: Document-level root tag
107
- totalChecks++;
108
- const hasDocumentTag = tagsAnalysis.roleCounts.Document !== undefined;
109
- if (!hasDocumentTag) {
110
- warnings++;
111
- issues.push({
112
- severity: 'warning',
113
- code: 'TAG-003',
114
- message: 'No Document root tag found',
115
- details: 'PDF/UA recommends a single Document tag as the root of the structure tree.',
116
- });
117
- }
118
- else {
119
- passed++;
120
- issues.push({
121
- severity: 'info',
122
- code: 'TAG-003',
123
- message: 'Document root tag present',
124
- });
125
- }
126
- // Check 4: Heading hierarchy
127
- totalChecks++;
128
- const headingLevels = [];
129
- for (let i = 1; i <= 6; i++) {
130
- if (tagsAnalysis.roleCounts[`H${i}`]) {
131
- headingLevels.push(i);
132
- }
133
- }
134
- // Also check generic H tag
135
- const hasGenericH = tagsAnalysis.roleCounts.H !== undefined;
136
- if (headingLevels.length === 0 && !hasGenericH) {
137
- warnings++;
138
- issues.push({
139
- severity: 'warning',
140
- code: 'TAG-004',
141
- message: 'No heading tags found',
142
- details: 'Document has no heading tags (H1-H6 or H). Headings are recommended for document navigation.',
143
- });
144
- }
145
- else if (headingLevels.length > 0) {
146
- // Check for skipped levels
147
- let isSequential = true;
148
- if (headingLevels[0] !== 1) {
149
- isSequential = false;
150
- }
151
- for (let i = 1; i < headingLevels.length; i++) {
152
- if (headingLevels[i] - headingLevels[i - 1] > 1) {
153
- isSequential = false;
154
- break;
155
- }
156
- }
157
- if (!isSequential) {
158
- warnings++;
159
- issues.push({
160
- severity: 'warning',
161
- code: 'TAG-004',
162
- message: `Heading hierarchy has gaps: ${headingLevels.map((l) => `H${l}`).join(', ')}`,
163
- details: 'Heading levels should be sequential without skipping levels (e.g., H1 → H2 → H3).',
164
- });
165
- }
166
- else {
167
- passed++;
168
- issues.push({
169
- severity: 'info',
170
- code: 'TAG-004',
171
- message: `Heading hierarchy is sequential: ${headingLevels.map((l) => `H${l}`).join(', ')}`,
172
- });
173
- }
174
- }
175
- else {
176
- passed++;
177
- issues.push({
178
- severity: 'info',
179
- code: 'TAG-004',
180
- message: 'Generic H tags used for headings',
181
- });
182
- }
183
- // Check 5: Figure tags for images
184
- const figureCount = tagsAnalysis.roleCounts.Figure ?? 0;
185
- // 🔴 回らなかった検査は totalChecks に数えない。数えたうえで passed にも
186
- // failed にも入れないと、合計が合わなくなる。
187
- if (imageCount !== null)
188
- totalChecks++;
189
- if (imageCount === null) {
190
- issues.push({
191
- severity: 'info',
192
- code: 'TAG-005',
193
- message: 'Not checked — the image count could not be observed.',
194
- details: 'Figure tags are judged against the number of images the page draws. ' +
195
- 'Without that number this check would have to assume zero images, which ' +
196
- 'would report a pass for a document nobody looked at.',
197
- });
198
- }
199
- else if (imageCount > 0 && figureCount === 0) {
200
- failed++;
201
- issues.push({
202
- severity: 'error',
203
- code: 'TAG-005',
204
- message: `Document has ${imageCount} image(s) but no Figure tags`,
205
- details: 'Images must be tagged as Figure with appropriate alt text for PDF/UA compliance.',
206
- });
207
- }
208
- else if (imageCount > 0 && figureCount < imageCount) {
209
- warnings++;
210
- issues.push({
211
- severity: 'warning',
212
- code: 'TAG-005',
213
- message: `${imageCount} image(s) found but only ${figureCount} Figure tag(s)`,
214
- details: 'Some images may not be properly tagged. Decorative images should be marked as artifacts.',
215
- });
216
- }
217
- else if (imageCount > 0) {
218
- passed++;
219
- issues.push({
220
- severity: 'info',
221
- code: 'TAG-005',
222
- message: `${figureCount} Figure tag(s) for ${imageCount} image(s)`,
223
- });
224
- }
225
- else {
226
- passed++;
227
- issues.push({
228
- severity: 'info',
229
- code: 'TAG-005',
230
- message: 'No images detected; Figure tag check not applicable',
231
- });
232
- }
233
- // Check 6: Paragraph tags
234
- totalChecks++;
235
- const hasParagraphs = tagsAnalysis.roleCounts.P !== undefined;
236
- if (!hasParagraphs) {
237
- warnings++;
238
- issues.push({
239
- severity: 'warning',
240
- code: 'TAG-006',
241
- message: 'No P (Paragraph) tags found',
242
- details: 'Text content should be wrapped in P tags for proper reading order.',
243
- });
244
- }
245
- else {
246
- passed++;
247
- issues.push({
248
- severity: 'info',
249
- code: 'TAG-006',
250
- message: `${tagsAnalysis.roleCounts.P} Paragraph tag(s) found`,
251
- });
252
- }
253
- // Check 7: Minimum element count
254
- totalChecks++;
255
- if (tagsAnalysis.totalElements < 2) {
256
- warnings++;
257
- issues.push({
258
- severity: 'warning',
259
- code: 'TAG-007',
260
- message: `Only ${tagsAnalysis.totalElements} structure element(s) found`,
261
- details: 'A properly tagged document should have multiple structure elements reflecting its content.',
262
- });
263
- }
264
- else {
265
- passed++;
266
- issues.push({
267
- severity: 'info',
268
- code: 'TAG-007',
269
- message: `${tagsAnalysis.totalElements} structure elements found`,
270
- });
271
- }
272
- // Check 8: Table tags
273
- totalChecks++;
274
- const tableCount = tagsAnalysis.roleCounts.Table ?? 0;
275
- const trCount = tagsAnalysis.roleCounts.TR ?? 0;
276
- const tdCount = tagsAnalysis.roleCounts.TD ?? 0;
277
- const thCount = tagsAnalysis.roleCounts.TH ?? 0;
278
- if (tableCount > 0) {
279
- if (trCount === 0) {
280
- warnings++;
281
- issues.push({
282
- severity: 'warning',
283
- code: 'TAG-008',
284
- message: `${tableCount} Table tag(s) but no TR (Table Row) tags`,
285
- details: 'Tables should contain TR, TH, and TD tags for proper structure.',
286
- });
287
- }
288
- else if (thCount === 0) {
289
- warnings++;
290
- issues.push({
291
- severity: 'warning',
292
- code: 'TAG-008',
293
- message: `Table has ${trCount} row(s) but no TH (Table Header) tags`,
294
- details: 'PDF/UA requires tables to have header cells (TH) for accessibility.',
295
- });
296
- }
297
- else {
298
- passed++;
299
- issues.push({
300
- severity: 'info',
301
- code: 'TAG-008',
302
- message: `Table structure: ${tableCount} table(s), ${trCount} row(s), ${thCount} header(s), ${tdCount} cell(s)`,
303
- });
304
- }
305
- }
306
- else {
307
- passed++;
308
- issues.push({
309
- severity: 'info',
310
- code: 'TAG-008',
311
- message: 'No Table tags found; table check not applicable',
312
- });
313
- }
314
- const errorCount = issues.filter((i) => i.severity === 'error').length;
315
- const warnCount = issues.filter((i) => i.severity === 'warning').length;
316
- const notCheckedNote = notChecked.length > 0
317
- ? ` ${notChecked.length} check(s) were not made: ${notChecked.map((n) => n.code).join(', ')}.`
318
- : '';
319
- let summary;
320
- if (errorCount === 0 && warnCount === 0) {
321
- summary = `All ${totalChecks} checks passed. Document appears well-structured for PDF/UA compliance.${notCheckedNote}`;
322
- }
323
- else if (errorCount === 0) {
324
- summary = `${passed}/${totalChecks} checks passed with ${warnCount} warning(s). Review warnings for full PDF/UA compliance.`;
325
- }
326
- else {
327
- summary = `${passed}/${totalChecks} checks passed, ${errorCount} error(s), ${warnCount} warning(s). Critical issues must be resolved for PDF/UA compliance.`;
328
- }
329
- return {
330
- isTagged: true,
331
- totalChecks,
332
- passed,
333
- failed,
334
- warnings,
335
- issues,
336
- ...(notChecked.length > 0 ? { notChecked } : {}),
337
- summary,
338
- };
339
- }
340
- // ─── validate_metadata ───────────────────────────────────
341
- /**
342
- * Validate PDF metadata conformance.
343
- *
344
- * Checks performed:
345
- * - Title is present (required for PDF/UA, PDF/A)
346
- * - Author is present
347
- * - CreationDate format
348
- * - ModificationDate format
349
- * - Producer is present
350
- * - PDF version is detected
351
- * - Document is tagged (metadata flag)
352
- * - Subject and Keywords (informational)
353
- */
354
- export async function validateMetadata(filePath) {
355
- const issues = [];
356
- let totalChecks = 0;
357
- let passed = 0;
358
- let failed = 0;
359
- let warnings = 0;
360
- const meta = await getMetadata(filePath);
361
- // Check 1: Title
362
- totalChecks++;
363
- if (!meta.title) {
364
- failed++;
365
- issues.push({
366
- severity: 'error',
367
- code: 'META-001',
368
- message: 'Title is missing',
369
- details: 'A document title is required for PDF/UA and PDF/A compliance. It is used by assistive technology and search engines.',
370
- });
371
- }
372
- else {
373
- passed++;
374
- issues.push({
375
- severity: 'info',
376
- code: 'META-001',
377
- message: `Title: "${meta.title}"`,
378
- });
379
- }
380
- // Check 2: Author
381
- totalChecks++;
382
- if (!meta.author) {
383
- warnings++;
384
- issues.push({
385
- severity: 'warning',
386
- code: 'META-002',
387
- message: 'Author is missing',
388
- details: 'Author metadata is recommended for document identification.',
389
- });
390
- }
391
- else {
392
- passed++;
393
- issues.push({
394
- severity: 'info',
395
- code: 'META-002',
396
- message: `Author: "${meta.author}"`,
397
- });
398
- }
399
- // Check 3: CreationDate
400
- totalChecks++;
401
- if (!meta.creationDate) {
402
- warnings++;
403
- issues.push({
404
- severity: 'warning',
405
- code: 'META-003',
406
- message: 'Creation date is missing',
407
- details: 'Creation date metadata is recommended.',
408
- });
409
- }
410
- else {
411
- const isValidDate = isValidPdfDate(meta.creationDate);
412
- if (isValidDate) {
413
- passed++;
414
- issues.push({
415
- severity: 'info',
416
- code: 'META-003',
417
- message: `Creation date: ${meta.creationDate}`,
418
- });
419
- }
420
- else {
421
- warnings++;
422
- issues.push({
423
- severity: 'warning',
424
- code: 'META-003',
425
- message: `Creation date format may be non-standard: ${meta.creationDate}`,
426
- details: "PDF date format should follow D:YYYYMMDDHHmmSSOHH'mm'.",
427
- });
428
- }
429
- }
430
- // Check 4: ModificationDate
431
- totalChecks++;
432
- if (!meta.modificationDate) {
433
- warnings++;
434
- issues.push({
435
- severity: 'warning',
436
- code: 'META-004',
437
- message: 'Modification date is missing',
438
- details: 'Modification date metadata is recommended for document tracking.',
439
- });
440
- }
441
- else {
442
- passed++;
443
- issues.push({
444
- severity: 'info',
445
- code: 'META-004',
446
- message: `Modification date: ${meta.modificationDate}`,
447
- });
448
- }
449
- // Check 5: Producer
450
- totalChecks++;
451
- if (!meta.producer) {
452
- warnings++;
453
- issues.push({
454
- severity: 'warning',
455
- code: 'META-005',
456
- message: 'Producer is missing',
457
- details: 'Producer identifies the application that created the PDF. Useful for debugging rendering issues.',
458
- });
459
- }
460
- else {
461
- passed++;
462
- issues.push({
463
- severity: 'info',
464
- code: 'META-005',
465
- message: `Producer: "${meta.producer}"`,
466
- });
467
- }
468
- // Check 6: PDF version
469
- totalChecks++;
470
- if (!meta.pdfVersion) {
471
- warnings++;
472
- issues.push({
473
- severity: 'warning',
474
- code: 'META-006',
475
- message: 'PDF version not detected',
476
- details: 'The PDF version could not be determined from the file header.',
477
- });
478
- }
479
- else {
480
- passed++;
481
- const version = Number.parseFloat(meta.pdfVersion);
482
- if (version < 1.4) {
483
- issues.push({
484
- severity: 'info',
485
- code: 'META-006',
486
- message: `PDF version: ${meta.pdfVersion} (pre-1.4; limited feature support)`,
487
- });
488
- }
489
- else {
490
- issues.push({
491
- severity: 'info',
492
- code: 'META-006',
493
- message: `PDF version: ${meta.pdfVersion}`,
494
- });
495
- }
496
- }
497
- // Check 7: Tagged flag
498
- totalChecks++;
499
- if (!meta.isTagged) {
500
- warnings++;
501
- issues.push({
502
- severity: 'warning',
503
- code: 'META-007',
504
- message: 'Document is not tagged',
505
- details: 'Tagged PDF is required for PDF/UA compliance and recommended for accessibility.',
506
- });
507
- }
508
- else {
509
- passed++;
510
- issues.push({
511
- severity: 'info',
512
- code: 'META-007',
513
- message: 'Document is tagged',
514
- });
515
- }
516
- // Check 8: Subject
517
- totalChecks++;
518
- if (!meta.subject) {
519
- warnings++;
520
- issues.push({
521
- severity: 'warning',
522
- code: 'META-008',
523
- message: 'Subject is missing',
524
- details: 'Subject metadata helps describe the document purpose.',
525
- });
526
- }
527
- else {
528
- passed++;
529
- issues.push({
530
- severity: 'info',
531
- code: 'META-008',
532
- message: `Subject: "${meta.subject}"`,
533
- });
534
- }
535
- // Check 9: Keywords
536
- totalChecks++;
537
- if (!meta.keywords) {
538
- warnings++;
539
- issues.push({
540
- severity: 'warning',
541
- code: 'META-009',
542
- message: 'Keywords are missing',
543
- details: 'Keywords metadata aids document discoverability.',
544
- });
545
- }
546
- else {
547
- passed++;
548
- issues.push({
549
- severity: 'info',
550
- code: 'META-009',
551
- message: `Keywords: "${meta.keywords}"`,
552
- });
553
- }
554
- // Check 10: Encryption and accessibility
555
- totalChecks++;
556
- if (meta.isEncrypted) {
557
- warnings++;
558
- issues.push({
559
- severity: 'warning',
560
- code: 'META-010',
561
- message: 'Document is encrypted',
562
- details: 'Encryption may restrict assistive technology access. Ensure accessibility permissions are enabled.',
563
- });
564
- }
565
- else {
566
- passed++;
567
- issues.push({
568
- severity: 'info',
569
- code: 'META-010',
570
- message: 'Document is not encrypted',
571
- });
572
- }
573
- const errorCount = issues.filter((i) => i.severity === 'error').length;
574
- const warnCount = issues.filter((i) => i.severity === 'warning').length;
575
- let summary;
576
- if (errorCount === 0 && warnCount === 0) {
577
- summary = `All ${totalChecks} metadata checks passed.`;
578
- }
579
- else if (errorCount === 0) {
580
- summary = `${passed}/${totalChecks} checks passed with ${warnCount} warning(s).`;
581
- }
582
- else {
583
- summary = `${passed}/${totalChecks} checks passed, ${errorCount} error(s), ${warnCount} warning(s).`;
584
- }
585
- return {
586
- totalChecks,
587
- passed,
588
- failed,
589
- warnings,
590
- issues,
591
- metadata: {
592
- hasTitle: !!meta.title,
593
- hasAuthor: !!meta.author,
594
- hasSubject: !!meta.subject,
595
- hasKeywords: !!meta.keywords,
596
- hasCreator: !!meta.creator,
597
- hasProducer: !!meta.producer,
598
- hasCreationDate: !!meta.creationDate,
599
- hasModificationDate: !!meta.modificationDate,
600
- pdfVersion: meta.pdfVersion,
601
- isTagged: meta.isTagged,
602
- },
603
- summary,
604
- };
605
- }
606
15
  // ─── compare_structure ───────────────────────────────────
607
16
  /**
608
17
  * Compare the structure of two PDF documents.
@@ -710,71 +119,4 @@ function addDiff(diffs, property, val1, val2) {
710
119
  status: val1 === val2 ? 'match' : 'differ',
711
120
  });
712
121
  }
713
- // ─── PDF date format (ISO 32000-2 §7.9.4) ────────────────
714
- //
715
- // Built up from the clause's own field definitions rather than written as one
716
- // opaque expression, because the previous one-liner hid two bugs (see below).
717
- //
718
- // (D:YYYYMMDDHHmmSSOHH'mm)
719
- //
720
- // Value ranges are from the clause text; checking them is what separates
721
- // "looks like a date" from "is a date" — the old pattern accepted month 13.
722
- const D_YYYY = '\\d{4}';
723
- const D_MM = '(?:0[1-9]|1[0-2])'; // "MM shall be the month (01–12)"
724
- const D_DD = '(?:0[1-9]|[12]\\d|3[01])'; // "DD shall be the day (01–31)"
725
- const D_HH = '(?:[01]\\d|2[0-3])'; // "HH shall be the hour (00–23)"
726
- const D_MIN = '[0-5]\\d'; // "mm shall be the minute (00–59)"
727
- const D_SS = '[0-5]\\d'; // "SS shall be the second (00–59)"
728
- // O and the UT offset.
729
- //
730
- // BUG 1 (fixed): the old class was `[+-Z]`, which a regex reads as the RANGE
731
- // U+002B(+) … U+005A(Z) — it accepted `,-./0-9:;<=>?@A-Z`. So `D:...A09'00` and
732
- // `D:...509'00` were reported as valid dates. The clause admits exactly three
733
- // characters: PLUS SIGN (+), HYPHEN-MINUS (-), LATIN CAPITAL LETTER Z (Z).
734
- //
735
- // BUG 2 (fixed): the old offset was `(\d{2}'\d{2}'?)?`, welding HH and mm
736
- // together, so the valid `D:...-09'` (hours, no minutes) was rejected. The
737
- // clause: "The APOSTROPHE … shall only be present if the HH field is present.
738
- // The minute offset field (mm) shall only be present if the APOSTROPHE … is
739
- // present." — mm is independently optional.
740
- //
741
- // The optional trailing apostrophe is the PDF 1.7 convention; NOTE 2 recommends
742
- // that processors keep accepting it. NOTE 3 allows Z to carry offsets too
743
- // ("The letter Z can optionally be followed by hour and minute offsets"), which
744
- // falls out of treating all three O characters alike.
745
- const D_OFFSET = `[+\\-Z](?:${D_HH}'(?:${D_MIN}'?)?)?`;
746
- // "the year field (YYYY) shall be present and all other fields may be present
747
- // but only if all of their preceding fields are also present" — hence the
748
- // nesting: each field encloses the next rather than being independently optional.
749
- //
750
- // SS is the one deliberate exception. The clause's own EXAMPLE —
751
- //
752
- // "December 23, 1998, at 7:52 PM, U.S. Pacific Standard Time" → D:199812231952-08'00
753
- //
754
- // omits SS while still carrying the offset, which the sentence above forbids.
755
- // This is not a version difference: ISO 32000-1:2008 §7.9.4 carries the *same*
756
- // normative sentence and the *same* example, so it is a long-standing defect in
757
- // the specification. Producers copy the example, and rejecting the standard's
758
- // own example in a warning-level check would be indefensible — so we accept an
759
- // omitted SS. Everything else follows the normative sentence.
760
- const PDF_DATE_PATTERN = new RegExp(`^D:${D_YYYY}(?:${D_MM}(?:${D_DD}(?:${D_HH}(?:${D_MIN}(?:${D_SS})?(?:${D_OFFSET})?)?)?)?)?$`);
761
- /** ISO 8601 — not a PDF date, but tolerated from non-conforming producers. */
762
- const ISO_8601_PATTERN = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2})?(?:[+-]\d{2}:?\d{2}|Z)?)?$/;
763
- /**
764
- * Check if a date string is a valid PDF date.
765
- *
766
- * ISO 32000-2 §7.9.4: `(D:YYYYMMDDHHmmSSOHH'mm)`. The `D:` prefix and `YYYY`
767
- * are required; every later field may be omitted only if all preceding ones are
768
- * present (SS excepted — see `PDF_DATE_PATTERN`). `O` is `+`, `-`, or `Z`.
769
- *
770
- * Also accepts ISO 8601 (`YYYY-MM-DDTHH:mm:ss`), which is a tolerance rather
771
- * than conformance — such a string does not satisfy §7.9.4.
772
- *
773
- * Exported for unit testing: the pattern is dense enough that it hid two bugs
774
- * (a character range masquerading as a class, and a welded HH/mm offset), and
775
- * exercising it through `validateMetadata` would need a fixture per date form.
776
- */
777
- export function isValidPdfDate(dateStr) {
778
- return PDF_DATE_PATTERN.test(dateStr) || ISO_8601_PATTERN.test(dateStr);
779
- }
780
122
  //# sourceMappingURL=validation-service.js.map