Skip to content

Commit dd1fe9c

Browse files
committed
Simplify loadGlobals for UMD build compatibility
Since the UMD build automatically sets up window.jsPDF, loadGlobals now only needs to: 1. Set up AcroForm aliases (ChoiceField, ListBox, etc.) for backward compatibility 2. Set up window.Canvg from window.canvg.Canvg Removed the async import promise mechanism entirely - it's no longer needed. Also added loadGlobals.js back to both karma configs since tests call beforeAll(loadGlobals).
1 parent d3c781a commit dd1fe9c

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

test/deployment/esm/karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = config => {
1616
"node_modules/html2canvas/dist/html2canvas.js",
1717
"node_modules/dompurify/dist/purify.js",
1818

19+
"test/compiled/deployment/esm/loadGlobals.js",
1920
"test/compiled/utils/compare.js",
2021

2122
"test/compiled/deployment/esm/*.spec.js",

test/deployment/esm/loadGlobals.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
let resolve;
2-
const promise = new Promise(res => {
3-
resolve = res;
4-
});
5-
window.importsReady = function(jsPDF) {
6-
resolve(jsPDF);
7-
};
1+
// UMD build sets up window.jsPDF automatically
2+
// This function just sets up the AcroForm aliases for backward compatibility
83
window.loadGlobals = async function loadGlobals() {
9-
if (window.jsPDF && window.Canvg) {
10-
return;
4+
if (window.AcroForm && window.Canvg) {
5+
return; // Already initialized
116
}
127

13-
const jsPDF = await promise;
14-
window.jsPDF = jsPDF.jsPDF;
8+
// Set up AcroForm aliases from the jsPDF global
9+
const jsPDF = window.jsPDF;
1510
window.AcroForm = jsPDF.AcroForm;
1611
window.ChoiceField = jsPDF.AcroFormChoiceField;
1712
window.ListBox = jsPDF.AcroFormListBox;
@@ -24,5 +19,7 @@ window.loadGlobals = async function loadGlobals() {
2419
window.TextField = jsPDF.AcroFormTextField;
2520
window.PasswordField = jsPDF.AcroFormPasswordField;
2621
window.Appearance = jsPDF.AcroFormAppearance;
22+
23+
// Set up Canvg global
2724
window.Canvg = window.canvg.Canvg;
2825
};

test/unit/karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = config => {
1414
"node_modules/canvg/lib/umd.js",
1515
"node_modules/html2canvas/dist/html2canvas.js",
1616
"node_modules/dompurify/dist/purify.js",
17+
"test/compiled/unit/loadGlobals.js",
1718
"test/compiled/utils/compare.js",
1819
"test/compiled/specs/*.spec.js",
1920
{ pattern: "test/compiled/specs/*.spec.mjs", type: "module" },

test/unit/loadGlobals.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
let resolve;
2-
const promise = new Promise(res => {
3-
resolve = res;
4-
});
5-
window.importsReady = function(jsPDF) {
6-
resolve(jsPDF);
7-
};
1+
// UMD build sets up window.jsPDF automatically
2+
// This function just sets up the AcroForm aliases for backward compatibility
83
window.loadGlobals = async function loadGlobals() {
9-
if (window.jsPDF && window.Canvg) {
10-
return;
4+
if (window.AcroForm && window.Canvg) {
5+
return; // Already initialized
116
}
127

13-
const jsPDF = await promise;
14-
window.jsPDF = jsPDF.jsPDF;
8+
// Set up AcroForm aliases from the jsPDF global
9+
const jsPDF = window.jsPDF;
1510
window.AcroForm = jsPDF.AcroForm;
1611
window.ChoiceField = jsPDF.AcroFormChoiceField;
1712
window.ListBox = jsPDF.AcroFormListBox;
@@ -24,5 +19,7 @@ window.loadGlobals = async function loadGlobals() {
2419
window.TextField = jsPDF.AcroFormTextField;
2520
window.PasswordField = jsPDF.AcroFormPasswordField;
2621
window.Appearance = jsPDF.AcroFormAppearance;
22+
23+
// Set up Canvg global
2724
window.Canvg = window.canvg.Canvg;
2825
};

0 commit comments

Comments
 (0)