|
23 | 23 | <option value='bolditalic'>bolditalic</option>
|
24 | 24 | </select>
|
25 | 25 | </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> |
26 | 33 | <div class='pure-control-group'>
|
27 | 34 | <label for='file-input'>File</label>
|
28 | 35 | <input type='hidden' name='extra-data' multiple />
|
|
55 | 62 | var jsFile = '';
|
56 | 63 | var fontName = document.getElementById('fontName').value;
|
57 | 64 | var fontStyle = document.getElementById('fontStyle').value;
|
| 65 | + var moduleFormat = document.getElementById('moduleFormat').value; |
58 | 66 | var createdFileName = fontName + '-' + fontStyle + '.ttf';
|
59 | 67 |
|
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 |
61 | 76 | jsFile += 'var font = \'' + window.loadedFileContents + '\';\n';
|
62 | 77 | jsFile += 'var callAddFont = function () {\n';
|
63 | 78 | jsFile += 'this.addFileToVFS(\'' + createdFileName + '\', font);\n';
|
64 | 79 | 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 | + } |
67 | 85 |
|
68 | 86 | var newJsfile = new File([jsFile], fontName + '-' + fontStyle + '.js', { type: 'text/plain;charset=utf-8' });
|
69 | 87 | saveAs(newJsfile);
|
|
0 commit comments