Skip to content

Commit 5f9b60c

Browse files
committed
update font-converter - can now generate UMD and ES modules headers
1 parent 480ae0f commit 5f9b60c

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Diff for: fontconverter/fontconverter.html

+21-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
<option value='bolditalic'>bolditalic</option>
2424
</select>
2525
</div>
26+
<div class='pure-control-group'>
27+
<label for='moduleFormat'>Module format</label>
28+
<select name='moduleFormat' id='moduleFormat'>
29+
<option value='es'>ES modules</option>
30+
<option value='umd'>UMD</option>
31+
</select>
32+
</div>
2633
<div class='pure-control-group'>
2734
<label for='file-input'>File</label>
2835
<input type='hidden' name='extra-data' multiple />
@@ -55,15 +62,26 @@
5562
var jsFile = '';
5663
var fontName = document.getElementById('fontName').value;
5764
var fontStyle = document.getElementById('fontStyle').value;
65+
var moduleFormat = document.getElementById('moduleFormat').value;
5866
var createdFileName = fontName + '-' + fontStyle + '.ttf';
5967

60-
jsFile += '(function (jsPDFAPI) {\n';
68+
var esHeader = 'import { jsPDF } from "jspdf"\n'
69+
var umdHeader = "(function (global, factory) {\n" +
70+
" typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jspdf')) :\n" +
71+
" typeof define === 'function' && define.amd ? define(['jspdf'], factory) :\n" +
72+
" (global = global || self, factory(global.jspdf));\n" +
73+
"}(this, (function (jspdf) { 'use strict';\nvar jsPDF = jspdf.jsPDF;\n"
74+
75+
jsFile += moduleFormat === "es" ? esHeader : umdHeader
6176
jsFile += 'var font = \'' + window.loadedFileContents + '\';\n';
6277
jsFile += 'var callAddFont = function () {\n';
6378
jsFile += 'this.addFileToVFS(\'' + createdFileName + '\', font);\n';
6479
jsFile += 'this.addFont(\'' + createdFileName + '\', \'' + fontName + '\', \'' + fontStyle + '\');\n};\n';
65-
jsFile += 'jsPDFAPI.events.push([\'addFonts\', callAddFont])\n';
66-
jsFile += ' })(jsPDF.API);';
80+
jsFile += 'jsPDF.API.events.push([\'addFonts\', callAddFont])\n';
81+
82+
if (moduleFormat === "umd") {
83+
jsFile += "})));"
84+
}
6785

6886
var newJsfile = new File([jsFile], fontName + '-' + fontStyle + '.js', { type: 'text/plain;charset=utf-8' });
6987
saveAs(newJsfile);

0 commit comments

Comments
 (0)