@pdfme/common 2.2.1 → 3.0.0-beta.1

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 (65) hide show
  1. package/dist/cjs/__tests__/helper.test.js +292 -233
  2. package/dist/cjs/__tests__/helper.test.js.map +1 -1
  3. package/dist/cjs/src/constants.js +3 -17
  4. package/dist/cjs/src/constants.js.map +1 -1
  5. package/dist/cjs/src/helper.js +72 -99
  6. package/dist/cjs/src/helper.js.map +1 -1
  7. package/dist/cjs/src/index.js +7 -37
  8. package/dist/cjs/src/index.js.map +1 -1
  9. package/dist/cjs/src/schema.js +17 -71
  10. package/dist/cjs/src/schema.js.map +1 -1
  11. package/dist/cjs/src/types.js +3 -0
  12. package/dist/cjs/src/types.js.map +1 -0
  13. package/dist/esm/__tests__/helper.test.js +270 -234
  14. package/dist/esm/__tests__/helper.test.js.map +1 -1
  15. package/dist/esm/src/constants.js +2 -16
  16. package/dist/esm/src/constants.js.map +1 -1
  17. package/dist/esm/src/helper.js +68 -98
  18. package/dist/esm/src/helper.js.map +1 -1
  19. package/dist/esm/src/index.js +3 -6
  20. package/dist/esm/src/index.js.map +1 -1
  21. package/dist/esm/src/schema.js +14 -68
  22. package/dist/esm/src/schema.js.map +1 -1
  23. package/dist/esm/src/types.js +2 -0
  24. package/dist/esm/src/types.js.map +1 -0
  25. package/dist/types/src/constants.d.ts +2 -16
  26. package/dist/types/src/helper.d.ts +11 -2
  27. package/dist/types/src/index.d.ts +5 -8
  28. package/dist/types/src/schema.d.ts +696 -3574
  29. package/dist/types/src/types.d.ts +127 -0
  30. package/package.json +5 -11
  31. package/src/constants.ts +2 -18
  32. package/src/helper.ts +108 -116
  33. package/src/index.ts +28 -87
  34. package/src/schema.ts +18 -84
  35. package/src/types.ts +124 -0
  36. package/tsconfig.cjs.json +3 -2
  37. package/tsconfig.esm.json +3 -2
  38. package/dist/cjs/__tests__/barcode.test.js +0 -107
  39. package/dist/cjs/__tests__/barcode.test.js.map +0 -1
  40. package/dist/cjs/__tests__/font.test.js +0 -465
  41. package/dist/cjs/__tests__/font.test.js.map +0 -1
  42. package/dist/cjs/src/barcode.js +0 -53
  43. package/dist/cjs/src/barcode.js.map +0 -1
  44. package/dist/cjs/src/font.js +0 -310
  45. package/dist/cjs/src/font.js.map +0 -1
  46. package/dist/cjs/src/type.js +0 -12
  47. package/dist/cjs/src/type.js.map +0 -1
  48. package/dist/esm/__tests__/barcode.test.js +0 -102
  49. package/dist/esm/__tests__/barcode.test.js.map +0 -1
  50. package/dist/esm/__tests__/font.test.js +0 -440
  51. package/dist/esm/__tests__/font.test.js.map +0 -1
  52. package/dist/esm/src/barcode.js +0 -44
  53. package/dist/esm/src/barcode.js.map +0 -1
  54. package/dist/esm/src/font.js +0 -274
  55. package/dist/esm/src/font.js.map +0 -1
  56. package/dist/esm/src/type.js +0 -6
  57. package/dist/esm/src/type.js.map +0 -1
  58. package/dist/types/__tests__/barcode.test.d.ts +0 -1
  59. package/dist/types/__tests__/font.test.d.ts +0 -1
  60. package/dist/types/src/barcode.d.ts +0 -19
  61. package/dist/types/src/font.d.ts +0 -34
  62. package/dist/types/src/type.d.ts +0 -81
  63. package/src/barcode.ts +0 -51
  64. package/src/font.ts +0 -352
  65. package/src/type.ts +0 -69
@@ -1,465 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- const fs_1 = require("fs");
36
- const path = __importStar(require("path"));
37
- const font_1 = require("../src/font");
38
- const src_1 = require("../src");
39
- const sansData = (0, fs_1.readFileSync)(path.join(__dirname, `/assets/fonts/SauceHanSansJP.ttf`));
40
- const serifData = (0, fs_1.readFileSync)(path.join(__dirname, `/assets/fonts/SauceHanSerifJP.ttf`));
41
- const getSampleFont = () => ({
42
- SauceHanSansJP: { fallback: true, data: sansData },
43
- SauceHanSerifJP: { data: serifData },
44
- });
45
- const getTemplate = () => ({
46
- basePdf: src_1.BLANK_PDF,
47
- schemas: [
48
- {
49
- a: {
50
- type: 'text',
51
- fontName: 'SauceHanSansJP',
52
- position: { x: 0, y: 0 },
53
- width: 100,
54
- height: 100,
55
- },
56
- b: {
57
- type: 'text',
58
- position: { x: 0, y: 0 },
59
- width: 100,
60
- height: 100,
61
- },
62
- },
63
- ],
64
- });
65
- const getTextSchema = () => {
66
- const textSchema = {
67
- position: { x: 0, y: 0 }, type: 'text', fontSize: 14, characterSpacing: 1, width: 50, height: 20
68
- };
69
- return textSchema;
70
- };
71
- describe('checkFont test', () => {
72
- test('success test: no fontName in Schemas', () => {
73
- const _getTemplate = () => ({
74
- basePdf: src_1.BLANK_PDF,
75
- schemas: [
76
- {
77
- a: {
78
- type: 'text',
79
- position: { x: 0, y: 0 },
80
- width: 100,
81
- height: 100,
82
- },
83
- b: {
84
- type: 'text',
85
- position: { x: 0, y: 0 },
86
- width: 100,
87
- height: 100,
88
- },
89
- },
90
- ],
91
- });
92
- try {
93
- (0, font_1.checkFont)({ template: _getTemplate(), font: getSampleFont() });
94
- expect.anything();
95
- }
96
- catch (e) {
97
- fail();
98
- }
99
- });
100
- test('success test: fontName in Schemas(fallback font)', () => {
101
- try {
102
- (0, font_1.checkFont)({ template: getTemplate(), font: getSampleFont() });
103
- expect.anything();
104
- }
105
- catch (e) {
106
- fail();
107
- }
108
- });
109
- test('success test: fontName in Schemas(not fallback font)', () => {
110
- const getFont = () => ({
111
- SauceHanSansJP: { data: sansData },
112
- SauceHanSerifJP: { fallback: true, data: serifData },
113
- });
114
- try {
115
- (0, font_1.checkFont)({ template: getTemplate(), font: getFont() });
116
- expect.anything();
117
- }
118
- catch (e) {
119
- fail();
120
- }
121
- });
122
- test('fail test: no fallback font', () => {
123
- const getFont = () => ({
124
- SauceHanSansJP: { data: sansData },
125
- SauceHanSerifJP: { data: serifData },
126
- });
127
- try {
128
- (0, font_1.checkFont)({ template: getTemplate(), font: getFont() });
129
- fail();
130
- }
131
- catch (e) {
132
- expect(e.message).toEqual('fallback flag is not found in font. true fallback flag must be only one.');
133
- }
134
- });
135
- test('fail test: too many fallback font', () => {
136
- const getFont = () => ({
137
- SauceHanSansJP: { data: sansData, fallback: true },
138
- SauceHanSerifJP: { data: serifData, fallback: true },
139
- });
140
- try {
141
- (0, font_1.checkFont)({ template: getTemplate(), font: getFont() });
142
- fail();
143
- }
144
- catch (e) {
145
- expect(e.message).toEqual('2 fallback flags found in font. true fallback flag must be only one.');
146
- }
147
- });
148
- test('fail test: fontName in Schemas not found in font(single)', () => {
149
- const _getTemplate = () => ({
150
- basePdf: src_1.BLANK_PDF,
151
- schemas: [
152
- {
153
- a: {
154
- type: 'text',
155
- fontName: 'SauceHanSansJP2',
156
- position: { x: 0, y: 0 },
157
- width: 100,
158
- height: 100,
159
- },
160
- b: {
161
- type: 'text',
162
- position: { x: 0, y: 0 },
163
- width: 100,
164
- height: 100,
165
- },
166
- },
167
- ],
168
- });
169
- try {
170
- (0, font_1.checkFont)({ template: _getTemplate(), font: getSampleFont() });
171
- fail();
172
- }
173
- catch (e) {
174
- expect(e.message).toEqual('SauceHanSansJP2 of template.schemas is not found in font.');
175
- }
176
- });
177
- test('fail test: fontName in Schemas not found in font(single)', () => {
178
- const _getTemplate = () => ({
179
- basePdf: src_1.BLANK_PDF,
180
- schemas: [
181
- {
182
- a: {
183
- type: 'text',
184
- fontName: 'SauceHanSansJP2',
185
- position: { x: 0, y: 0 },
186
- width: 100,
187
- height: 100,
188
- },
189
- b: {
190
- type: 'text',
191
- fontName: 'SauceHanSerifJP2',
192
- position: { x: 0, y: 0 },
193
- width: 100,
194
- height: 100,
195
- },
196
- },
197
- ],
198
- });
199
- try {
200
- (0, font_1.checkFont)({ template: _getTemplate(), font: getSampleFont() });
201
- fail();
202
- }
203
- catch (e) {
204
- expect(e.message).toEqual('SauceHanSansJP2,SauceHanSerifJP2 of template.schemas is not found in font.');
205
- }
206
- });
207
- });
208
- describe('getSplitPosition test with mocked font width calculations', () => {
209
- /**
210
- * To simplify these tests we mock the widthOfTextAtSize function to return
211
- * the length of the text in number of characters.
212
- * Therefore, setting the boxWidthInPt to 5 should result in a split after 5 characters.
213
- */
214
- let widthOfTextAtSizeSpy;
215
- beforeAll(() => {
216
- // @ts-ignore
217
- widthOfTextAtSizeSpy = jest.spyOn(require('../src/font'), 'widthOfTextAtSize');
218
- widthOfTextAtSizeSpy.mockImplementation((text) => {
219
- return text.length;
220
- });
221
- });
222
- afterAll(() => {
223
- widthOfTextAtSizeSpy.mockRestore();
224
- });
225
- const mockedFont = {};
226
- const mockCalcValues = {
227
- font: mockedFont,
228
- fontSize: 12,
229
- characterSpacing: 1,
230
- boxWidthInPt: 5,
231
- };
232
- it('does not split an empty string', () => {
233
- expect((0, font_1.getSplittedLines)('', mockCalcValues)).toEqual(['']);
234
- });
235
- it('does not split a short line', () => {
236
- expect((0, font_1.getSplittedLines)('a', mockCalcValues)).toEqual(['a']);
237
- expect((0, font_1.getSplittedLines)('aaaa', mockCalcValues)).toEqual(['aaaa']);
238
- });
239
- it('splits a line to the nearest previous space', () => {
240
- expect((0, font_1.getSplittedLines)('aaa bbb', mockCalcValues)).toEqual(['aaa', 'bbb']);
241
- });
242
- it('splits a line where the split point is on a space', () => {
243
- expect((0, font_1.getSplittedLines)('aaaaa bbbbb', mockCalcValues)).toEqual(['aaaaa', 'bbbbb']);
244
- });
245
- it('splits a long line in the middle of a word if too long', () => {
246
- expect((0, font_1.getSplittedLines)('aaaaaa bbb', mockCalcValues)).toEqual(['aaaaa', 'a bbb']);
247
- });
248
- it('splits a long line without spaces at exactly 5 chars', () => {
249
- expect((0, font_1.getSplittedLines)('abcdef', mockCalcValues)).toEqual(['abcde', 'f']);
250
- });
251
- it('splits a very long line without spaces at exactly 5 chars', () => {
252
- expect((0, font_1.getSplittedLines)('abcdefghijklmn', mockCalcValues)).toEqual(['abcde', 'fghij', 'klmn']);
253
- });
254
- it('splits a line with lots of words', () => {
255
- expect((0, font_1.getSplittedLines)('a b c d e', mockCalcValues)).toEqual(['a b c', 'd e']);
256
- });
257
- });
258
- describe('getSplittedLines test with real font width calculations', () => {
259
- const font = (0, font_1.getDefaultFont)();
260
- const baseCalcValues = {
261
- fontSize: 12,
262
- characterSpacing: 1,
263
- boxWidthInPt: 40,
264
- };
265
- it('should not split a line when the text is shorter than the width', () => {
266
- (0, font_1.getFontKitFont)(getTextSchema(), font).then((fontKitFont) => {
267
- const fontWidthCalcs = Object.assign({}, baseCalcValues, { font: fontKitFont });
268
- const result = (0, font_1.getSplittedLines)('short', fontWidthCalcs);
269
- expect(result).toEqual(['short']);
270
- });
271
- });
272
- it('should split a line when the text is longer than the width', () => {
273
- (0, font_1.getFontKitFont)(getTextSchema(), font).then((fontKitFont) => {
274
- const fontWidthCalcs = Object.assign({}, baseCalcValues, { font: fontKitFont });
275
- const result = (0, font_1.getSplittedLines)('this will wrap', fontWidthCalcs);
276
- expect(result).toEqual(['this', 'will', 'wrap']);
277
- });
278
- });
279
- it('should split a line in the middle when unspaced text will not fit on a line', () => {
280
- (0, font_1.getFontKitFont)(getTextSchema(), font).then((fontKitFont) => {
281
- const fontWidthCalcs = Object.assign({}, baseCalcValues, { font: fontKitFont });
282
- const result = (0, font_1.getSplittedLines)('thiswillbecut', fontWidthCalcs);
283
- expect(result).toEqual(['thiswi', 'llbecu', 't']);
284
- });
285
- });
286
- it('should not split text when it is impossible due to size constraints', () => {
287
- (0, font_1.getFontKitFont)(getTextSchema(), font).then((fontKitFont) => {
288
- const fontWidthCalcs = Object.assign({}, baseCalcValues, { font: fontKitFont });
289
- fontWidthCalcs.boxWidthInPt = 2;
290
- const result = (0, font_1.getSplittedLines)('thiswillnotbecut', fontWidthCalcs);
291
- expect(result).toEqual(['thiswillnotbecut']);
292
- });
293
- });
294
- });
295
- describe('calculateDynamicFontSize with Default font', () => {
296
- const font = (0, font_1.getDefaultFont)();
297
- it('should return default font size when dynamicFontSizeSetting is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
298
- const textSchema = getTextSchema();
299
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value: 'test' });
300
- expect(result).toBe(14);
301
- }));
302
- it('should return default font size when dynamicFontSizeSetting max is less than min', () => __awaiter(void 0, void 0, void 0, function* () {
303
- const textSchema = getTextSchema();
304
- textSchema.dynamicFontSize = { min: 11, max: 10 };
305
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value: 'test' });
306
- expect(result).toBe(14);
307
- }));
308
- it('should calculate a dynamic font size of vertical fit between min and max', () => __awaiter(void 0, void 0, void 0, function* () {
309
- const textSchema = getTextSchema();
310
- textSchema.dynamicFontSize = { min: 10, max: 30, fit: 'vertical' };
311
- const value = 'test with a length string\n and a new line';
312
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
313
- expect(result).toBe(19.25);
314
- }));
315
- it('should calculate a dynamic font size of horizontal fit between min and max', () => __awaiter(void 0, void 0, void 0, function* () {
316
- const textSchema = getTextSchema();
317
- textSchema.dynamicFontSize = { min: 10, max: 30, fit: 'horizontal' };
318
- const value = 'test with a length string\n and a new line';
319
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
320
- expect(result).toBe(11.25);
321
- }));
322
- it('should calculate a dynamic font size between min and max regardless of current font size', () => __awaiter(void 0, void 0, void 0, function* () {
323
- const textSchema = getTextSchema();
324
- textSchema.fontSize = 2;
325
- textSchema.dynamicFontSize = { min: 10, max: 30, fit: 'vertical' };
326
- const value = 'test with a length string\n and a new line';
327
- let result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
328
- expect(result).toBe(19.25);
329
- textSchema.fontSize = 40;
330
- result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
331
- expect(result).toBe(19.25);
332
- }));
333
- it('should return min font size when content is too big to fit given constraints', () => __awaiter(void 0, void 0, void 0, function* () {
334
- const textSchema = getTextSchema();
335
- textSchema.width = 10;
336
- textSchema.dynamicFontSize = { min: 10, max: 30, fit: 'vertical' };
337
- const value = 'test with a length string\n and a new line';
338
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
339
- expect(result).toBe(10);
340
- }));
341
- it('should return max font size when content is too small to fit given constraints', () => __awaiter(void 0, void 0, void 0, function* () {
342
- const textSchema = getTextSchema();
343
- textSchema.width = 1000;
344
- textSchema.height = 200;
345
- textSchema.dynamicFontSize = { min: 10, max: 30 };
346
- const value = 'test with a length string\n and a new line';
347
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
348
- expect(result).toBe(30);
349
- }));
350
- it('should not reduce font size below 0', () => __awaiter(void 0, void 0, void 0, function* () {
351
- const textSchema = getTextSchema();
352
- textSchema.dynamicFontSize = { min: -5, max: 10 };
353
- textSchema.width = 4;
354
- textSchema.height = 1;
355
- const value = 'a very \nlong \nmulti-line \nstring\nto';
356
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
357
- expect(result).toBeGreaterThan(0);
358
- }));
359
- it('should calculate a dynamic font size when a starting font size is passed that is lower than the eventual', () => __awaiter(void 0, void 0, void 0, function* () {
360
- const textSchema = getTextSchema();
361
- textSchema.dynamicFontSize = { min: 10, max: 30, fit: 'vertical' };
362
- const value = 'test with a length string\n and a new line';
363
- const startingFontSize = 18;
364
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value, startingFontSize });
365
- expect(result).toBe(19.25);
366
- }));
367
- it('should calculate a dynamic font size when a starting font size is passed that is higher than the eventual', () => __awaiter(void 0, void 0, void 0, function* () {
368
- const textSchema = getTextSchema();
369
- textSchema.dynamicFontSize = { min: 10, max: 30, fit: 'horizontal' };
370
- const value = 'test with a length string\n and a new line';
371
- const startingFontSize = 36;
372
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value, startingFontSize });
373
- expect(result).toBe(11.25);
374
- }));
375
- it('should calculate a dynamic font size using vertical fit as a default if no fit provided', () => __awaiter(void 0, void 0, void 0, function* () {
376
- const textSchema = getTextSchema();
377
- textSchema.dynamicFontSize = { min: 10, max: 30 };
378
- const value = 'test with a length string\n and a new line';
379
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
380
- expect(result).toBe(19.25);
381
- }));
382
- });
383
- describe('calculateDynamicFontSize with Custom font', () => {
384
- const font = getSampleFont();
385
- it('should return smaller font size when dynamicFontSizeSetting is provided with horizontal fit', () => __awaiter(void 0, void 0, void 0, function* () {
386
- const textSchema = getTextSchema();
387
- textSchema.dynamicFontSize = { min: 10, max: 30, fit: 'horizontal' };
388
- const value = 'あいうあいうあい';
389
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
390
- expect(result).toBe(16.75);
391
- }));
392
- it('should return smaller font size when dynamicFontSizeSetting is provided with vertical fit', () => __awaiter(void 0, void 0, void 0, function* () {
393
- const textSchema = getTextSchema();
394
- textSchema.dynamicFontSize = { min: 10, max: 30, fit: 'vertical' };
395
- const value = 'あいうあいうあい';
396
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
397
- expect(result).toBe(26);
398
- }));
399
- it('should return min font size when content is too big to fit given constraints', () => __awaiter(void 0, void 0, void 0, function* () {
400
- const textSchema = getTextSchema();
401
- textSchema.dynamicFontSize = { min: 20, max: 30 };
402
- const value = 'あいうあいうあいうあいうあいうあいうあいうあいうあいう';
403
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
404
- expect(result).toBe(20);
405
- }));
406
- it('should return max font size when content is too small to fit given constraints', () => __awaiter(void 0, void 0, void 0, function* () {
407
- const textSchema = getTextSchema();
408
- textSchema.dynamicFontSize = { min: 10, max: 30 };
409
- const value = 'あ';
410
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
411
- expect(result).toBe(30);
412
- }));
413
- it('should return min font size when content is multi-line with too many lines for the container', () => __awaiter(void 0, void 0, void 0, function* () {
414
- const textSchema = getTextSchema();
415
- textSchema.dynamicFontSize = { min: 5, max: 20 };
416
- const value = 'あ\nいう\nあ\nいう\nあ\nいう\nあ\nいう\nあ\nいう\nあ\nいう';
417
- const result = yield (0, font_1.calculateDynamicFontSize)({ textSchema, font, value });
418
- expect(result).toBe(5);
419
- }));
420
- });
421
- describe('getFontDescentInPt test', () => {
422
- test('it gets a descent size relative to the font size', () => {
423
- expect((0, font_1.getFontDescentInPt)({ descent: -400, unitsPerEm: 1000 }, 12)).toBe(-4.800000000000001);
424
- expect((0, font_1.getFontDescentInPt)({ descent: 54, unitsPerEm: 1000 }, 20)).toBe(1.08);
425
- expect((0, font_1.getFontDescentInPt)({ descent: -512, unitsPerEm: 2048 }, 54)).toBe(-13.5);
426
- });
427
- });
428
- describe('getBrowserVerticalFontAdjustments test', () => {
429
- // Font with a base line-height of 1.349
430
- const font = { ascent: 1037, descent: -312, unitsPerEm: 1000 };
431
- test('it gets a top adjustment when vertically aligning top', () => {
432
- expect((0, font_1.getBrowserVerticalFontAdjustments)(font, 12, 1.0, 'top')).toEqual({
433
- topAdj: 2.791301999999999,
434
- bottomAdj: 0,
435
- });
436
- expect((0, font_1.getBrowserVerticalFontAdjustments)(font, 36, 2.0, 'top')).toEqual({
437
- topAdj: 8.373906,
438
- bottomAdj: 0,
439
- });
440
- });
441
- test('it gets a bottom adjustment when vertically aligning middle or bottom', () => {
442
- expect((0, font_1.getBrowserVerticalFontAdjustments)(font, 12, 1.0, 'bottom')).toEqual({
443
- topAdj: 0,
444
- bottomAdj: 2.791302,
445
- });
446
- expect((0, font_1.getBrowserVerticalFontAdjustments)(font, 12, 1.15, 'middle')).toEqual({
447
- topAdj: 0,
448
- bottomAdj: 1.5916020000000004,
449
- });
450
- });
451
- test('it does not get a bottom adjustment if the line height exceeds that of the font', () => {
452
- expect((0, font_1.getBrowserVerticalFontAdjustments)(font, 12, 1.35, 'bottom')).toEqual({
453
- topAdj: 0,
454
- bottomAdj: 0,
455
- });
456
- });
457
- test('it does not get a bottom adjustment if the font base line-height is 1.0 or less', () => {
458
- const thisFont = { ascent: 900, descent: -50, unitsPerEm: 1000 };
459
- expect((0, font_1.getBrowserVerticalFontAdjustments)(thisFont, 20, 1.0, 'bottom')).toEqual({
460
- topAdj: 0,
461
- bottomAdj: 0,
462
- });
463
- });
464
- });
465
- //# sourceMappingURL=font.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"font.test.js","sourceRoot":"","sources":["../../../__tests__/font.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2BAAkC;AAClC,2CAA6B;AAE7B,sCAQoB;AAEpB,gCAAmC;AAEnC,MAAM,QA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;YAC7E,MAAM,EAAE,CAAC;YACT,SAAS,EAAE,CAAC;SACb,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.createBarCode = exports.mapHexColorForBwipJsLib = exports.barCodeType2Bcid = void 0;
16
- const helper_1 = require("./helper");
17
- const bwip_js_1 = __importDefault(require("bwip-js"));
18
- /**
19
- * The bwip.js lib has a different name for nw7 type barcodes
20
- */
21
- const barCodeType2Bcid = (type) => type === 'nw7' ? 'rationalizedCodabar' : type;
22
- exports.barCodeType2Bcid = barCodeType2Bcid;
23
- /**
24
- * Strip hash from the beginning of HTML hex color codes for the bwip.js lib
25
- */
26
- const mapHexColorForBwipJsLib = (color, fallback) => color ? color.replace('#', '') : fallback ? fallback.replace('#', '') : '000000';
27
- exports.mapHexColorForBwipJsLib = mapHexColorForBwipJsLib;
28
- const createBarCode = (arg) => __awaiter(void 0, void 0, void 0, function* () {
29
- const { type, input, width, height, backgroundcolor, barcolor, textcolor } = arg;
30
- const bcid = (0, exports.barCodeType2Bcid)(type);
31
- const includetext = true;
32
- const scale = 5;
33
- const bwipjsArg = { bcid, text: input, width, height, scale, includetext };
34
- if (backgroundcolor)
35
- bwipjsArg.backgroundcolor = (0, exports.mapHexColorForBwipJsLib)(backgroundcolor);
36
- if (barcolor)
37
- bwipjsArg.barcolor = (0, exports.mapHexColorForBwipJsLib)(barcolor);
38
- if (textcolor)
39
- bwipjsArg.textcolor = (0, exports.mapHexColorForBwipJsLib)(textcolor);
40
- let res;
41
- if (typeof window !== 'undefined') {
42
- const canvas = document.createElement('canvas');
43
- bwip_js_1.default.toCanvas(canvas, bwipjsArg);
44
- const dataUrl = canvas.toDataURL('image/png');
45
- res = (0, helper_1.b64toUint8Array)(dataUrl).buffer;
46
- }
47
- else {
48
- res = yield bwip_js_1.default.toBuffer(bwipjsArg);
49
- }
50
- return res;
51
- });
52
- exports.createBarCode = createBarCode;
53
- //# sourceMappingURL=barcode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"barcode.js","sourceRoot":"","sources":["../../../src/barcode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qCAA4C;AAE5C,sDAAkD;AAGlD;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAAC,IAAiB,EAAE,EAAE,CACpD,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC;AADnC,QAAA,gBAAgB,oBACmB;AAEhD;;GAEG;AACI,MAAM,uBAAuB,GAAG,CAAC,KAAyB,EAAE,QAAiB,EAAE,EAAE,CACtF,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AADtE,QAAA,uBAAuB,2BAC+C;AAE5E,MAAM,aAAa,GAAG,CAAO,GAQnC,EAAmB,EAAE;IACpB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,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