Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135,976 changes: 68,593 additions & 67,383 deletions build/pdfmake.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/pdfmake.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/pdfmake.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/pdfmake.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pdfmake",
"version": "0.2.23",
"name": "@wellcometrust/pdfmake",
"version": "2.1.0",
"description": "Client/server side PDF printing in pure JavaScript",
Comment on lines 1 to 4
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is titled/described as adding accessibility tagging, but it also changes the published package name and bumps the version from 0.2.23 to 2.1.0. That’s a significant distribution/API change that should either be called out in the PR description/release notes or split into a separate PR to keep the change set scoped.

Copilot uses AI. Check for mistakes.
"main": "src/printer.js",
"browser": "build/pdfmake.js",
Expand Down
5,104 changes: 2,552 additions & 2,552 deletions src/3rd-party/svg-to-pdfkit/source.js

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions src/accessibilityMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
'use strict';

/**
* Utility module to extract accessibility-relevant properties from document nodes
* and determine their PDF structure type.
*/

/**
* Returns the PDF structure tag for a node based on its properties.
*
* @param {Object} node - A pdfmake document node
* @param {Object} [context] - Optional context about the node's position in the document tree
* @param {boolean} [context.inList] - Whether the node is inside a list
* @param {boolean} [context.inTable] - Whether the node is inside a table
* @returns {string} The PDF structure type (e.g. 'P', 'H1', 'Figure', 'Artifact')
*/
function getAccessibilityRole(node, context) {
if (!node) {
return 'Artifact';
}

// Explicit accessibilityTag takes precedence
if (node.accessibilityTag) {
return node.accessibilityTag;
}

// Headings via headlineLevel
if (node.headlineLevel && node.headlineLevel >= 1 && node.headlineLevel <= 6) {
return 'H' + node.headlineLevel;
}

// Images and SVGs - Figure if alt/actualText present, otherwise Artifact
if (node.image || node.svg) {
if (node.alt || node.actualText) {
return 'Figure';
}
return 'Artifact';
}

// Canvas / vectors are always artifacts
if (node.canvas) {
return 'Artifact';
}

// Tables - only tagged if explicitly marked
if (node.table) {
if (node.accessibilityTag === 'Table' || node.accessibilityTag === 'TOC') {
return node.accessibilityTag;
}
return null; // no structural tagging for unmarked tables
}

// Text nodes default to P (paragraph)
if (node.text !== undefined) {
return 'P';
}

return null;
}

/**
* Returns options for pdfKitDoc.struct() based on node properties.
*/
function getStructureOptions(node) {
var options = {};

if (node.alt) {
options.alt = node.alt;
}
if (node.actualText) {
options.actual = node.actualText;
}

return options;
}

/**
* Checks if a table node should be structurally tagged.
*/
function shouldTagTable(node) {
return node && (node.accessibilityTag === 'Table' || node.accessibilityTag === 'TOC');
}

/**
* Checks if a table node is a Table of Contents.
*/
function isTOC(node) {
return node && node.accessibilityTag === 'TOC';
}

module.exports = {
getAccessibilityRole: getAccessibilityRole,
getStructureOptions: getStructureOptions,
shouldTagTable: shouldTagTable,
isTOC: isTOC
};
Loading
Loading