@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,310 +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
- exports.calculateDynamicFontSize = exports.getSplittedLines = exports.getFontKitFont = exports.widthOfTextAtSize = exports.heightOfFontAtSize = exports.getFontDescentInPt = exports.getBrowserVerticalFontAdjustments = exports.checkFont = exports.getDefaultFont = exports.getFallbackFontName = void 0;
36
- const fontkit = __importStar(require("fontkit"));
37
- const type_1 = require("./type");
38
- const buffer_1 = require("buffer");
39
- const constants_1 = require("./constants");
40
- const helper_1 = require("./helper");
41
- const _1 = require(".");
42
- const getFallbackFontName = (font) => {
43
- const initial = '';
44
- const fallbackFontName = Object.entries(font).reduce((acc, cur) => {
45
- const [fontName, fontValue] = cur;
46
- return !acc && fontValue.fallback ? fontName : acc;
47
- }, initial);
48
- if (fallbackFontName === initial) {
49
- throw Error(`fallback flag is not found in font. true fallback flag must be only one.`);
50
- }
51
- return fallbackFontName;
52
- };
53
- exports.getFallbackFontName = getFallbackFontName;
54
- const getFallbackFont = (font) => {
55
- const fallbackFontName = (0, exports.getFallbackFontName)(font);
56
- return font[fallbackFontName];
57
- };
58
- const getDefaultFont = () => ({
59
- [constants_1.DEFAULT_FONT_NAME]: { data: (0, _1.b64toUint8Array)(constants_1.DEFAULT_FONT_VALUE), fallback: true },
60
- });
61
- exports.getDefaultFont = getDefaultFont;
62
- const uniq = (array) => Array.from(new Set(array));
63
- const getFontNamesInSchemas = (schemas) => uniq(schemas
64
- .map((s) => Object.values(s).map((v) => ((0, type_1.isTextSchema)(v) ? v.fontName : '')))
65
- .reduce((acc, cur) => acc.concat(cur), [])
66
- .filter(Boolean));
67
- const checkFont = (arg) => {
68
- const { font, template: { schemas } } = arg;
69
- const fontValues = Object.values(font);
70
- const fallbackFontNum = fontValues.reduce((acc, cur) => (cur.fallback ? acc + 1 : acc), 0);
71
- if (fallbackFontNum === 0) {
72
- throw Error(`fallback flag is not found in font. true fallback flag must be only one.`);
73
- }
74
- if (fallbackFontNum > 1) {
75
- throw Error(`${fallbackFontNum} fallback flags found in font. true fallback flag must be only one.`);
76
- }
77
- const fontNamesInSchemas = getFontNamesInSchemas(schemas);
78
- const fontNames = Object.keys(font);
79
- if (fontNamesInSchemas.some((f) => !fontNames.includes(f))) {
80
- throw Error(`${fontNamesInSchemas
81
- .filter((f) => !fontNames.includes(f))
82
- .join()} of template.schemas is not found in font.`);
83
- }
84
- };
85
- exports.checkFont = checkFont;
86
- const getBrowserVerticalFontAdjustments = (fontKitFont, fontSize, lineHeight, verticalAlignment) => {
87
- const { ascent, descent, unitsPerEm } = fontKitFont;
88
- // Fonts have a designed line height that the browser renders when using `line-height: normal`
89
- const fontBaseLineHeight = (ascent - descent) / unitsPerEm;
90
- // For vertical alignment top
91
- // To achieve consistent positioning between browser and PDF, we apply the difference between
92
- // the font's actual height and the font size in pixels.
93
- // Browsers middle the font within this height, so we only need half of it to apply to the top.
94
- // This means the font renders a bit lower in the browser, but achieves PDF alignment
95
- const topAdjustment = (fontBaseLineHeight * fontSize - fontSize) / 2;
96
- if (verticalAlignment === constants_1.VERTICAL_ALIGN_TOP) {
97
- return { topAdj: (0, helper_1.pt2px)(topAdjustment), bottomAdj: 0 };
98
- }
99
- // For vertical alignment bottom and middle
100
- // When browsers render text in a non-form element (such as a <div>), some of the text may be
101
- // lowered below and outside the containing element if the line height used is less than
102
- // the base line-height of the font.
103
- // This behaviour does not happen in a <textarea> though, so we need to adjust the positioning
104
- // for consistency between editing and viewing to stop text jumping up and down.
105
- // This portion of text is half of the difference between the base line height and the used
106
- // line height. If using the same or higher line-height than the base font, then line-height
107
- // takes over in the browser and this adjustment is not needed.
108
- // Unlike the top adjustment - this is only driven by browser behaviour, not PDF alignment.
109
- let bottomAdjustment = 0;
110
- if (lineHeight < fontBaseLineHeight) {
111
- bottomAdjustment = ((fontBaseLineHeight - lineHeight) * fontSize) / 2;
112
- }
113
- return { topAdj: 0, bottomAdj: (0, helper_1.pt2px)(bottomAdjustment) };
114
- };
115
- exports.getBrowserVerticalFontAdjustments = getBrowserVerticalFontAdjustments;
116
- const getFontDescentInPt = (fontKitFont, fontSize) => {
117
- const { descent, unitsPerEm } = fontKitFont;
118
- return (descent / unitsPerEm) * fontSize;
119
- };
120
- exports.getFontDescentInPt = getFontDescentInPt;
121
- const heightOfFontAtSize = (fontKitFont, fontSize) => {
122
- const { ascent, descent, bbox, unitsPerEm } = fontKitFont;
123
- const scale = 1000 / unitsPerEm;
124
- const yTop = (ascent || bbox.maxY) * scale;
125
- const yBottom = (descent || bbox.minY) * scale;
126
- let height = yTop - yBottom;
127
- height -= Math.abs(descent * scale) || 0;
128
- return (height / 1000) * fontSize;
129
- };
130
- exports.heightOfFontAtSize = heightOfFontAtSize;
131
- const calculateCharacterSpacing = (textContent, textCharacterSpacing) => {
132
- return (textContent.length - 1) * textCharacterSpacing;
133
- };
134
- const widthOfTextAtSize = (text, fontKitFont, fontSize, characterSpacing) => {
135
- const { glyphs } = fontKitFont.layout(text);
136
- const scale = 1000 / fontKitFont.unitsPerEm;
137
- const standardWidth = glyphs.reduce((totalWidth, glyph) => totalWidth + glyph.advanceWidth * scale, 0) *
138
- (fontSize / 1000);
139
- return standardWidth + calculateCharacterSpacing(text, characterSpacing);
140
- };
141
- exports.widthOfTextAtSize = widthOfTextAtSize;
142
- const fontKitFontCache = {};
143
- const getFontKitFont = (textSchema, font) => __awaiter(void 0, void 0, void 0, function* () {
144
- const fontName = textSchema.fontName || (0, exports.getFallbackFontName)(font);
145
- if (fontKitFontCache[fontName]) {
146
- return fontKitFontCache[fontName];
147
- }
148
- const currentFont = font[fontName] || getFallbackFont(font) || (0, exports.getDefaultFont)()[constants_1.DEFAULT_FONT_NAME];
149
- let fontData = currentFont.data;
150
- if (typeof fontData === 'string') {
151
- fontData = fontData.startsWith('http') ? yield fetch(fontData).then((res) => res.arrayBuffer()) : (0, _1.b64toUint8Array)(fontData);
152
- }
153
- const fontKitFont = fontkit.create(fontData instanceof buffer_1.Buffer ? fontData : buffer_1.Buffer.from(fontData));
154
- fontKitFontCache[fontName] = fontKitFont;
155
- return fontKitFont;
156
- });
157
- exports.getFontKitFont = getFontKitFont;
158
- const isTextExceedingBoxWidth = (text, calcValues) => {
159
- const { font, fontSize, characterSpacing, boxWidthInPt } = calcValues;
160
- const textWidth = (0, exports.widthOfTextAtSize)(text, font, fontSize, characterSpacing);
161
- return textWidth > boxWidthInPt;
162
- };
163
- /**
164
- * Incrementally checks the current line for its real length
165
- * and returns the position where it exceeds the box width.
166
- * Returns `null` to indicate if textLine is shorter than the available box.
167
- */
168
- const getOverPosition = (textLine, calcValues) => {
169
- for (let i = 0; i <= textLine.length; i++) {
170
- if (isTextExceedingBoxWidth(textLine.slice(0, i + 1), calcValues)) {
171
- return i;
172
- }
173
- }
174
- return null;
175
- };
176
- /**
177
- * Gets the position of the split. Splits the exceeding line at
178
- * the last whitespace prior to it exceeding the bounding box width.
179
- */
180
- const getSplitPosition = (textLine, calcValues) => {
181
- const overPos = getOverPosition(textLine, calcValues);
182
- if (overPos === null)
183
- return textLine.length; // input line is shorter than the available space
184
- let overPosTmp = overPos;
185
- while (textLine[overPosTmp] !== ' ' && overPosTmp >= 0) {
186
- overPosTmp--;
187
- }
188
- // For very long lines with no whitespace use the original overPos
189
- return overPosTmp > 0 ? overPosTmp : overPos;
190
- };
191
- /**
192
- * Recursively splits the line at getSplitPosition.
193
- * If there is some leftover, split the rest again in the same manner.
194
- */
195
- const getSplittedLines = (textLine, calcValues) => {
196
- const splitPos = getSplitPosition(textLine, calcValues);
197
- const splittedLine = textLine.substring(0, splitPos);
198
- const rest = textLine.substring(splitPos).trimStart();
199
- if (rest === textLine) {
200
- // if we went so small that we want to split on the first char
201
- // then end recursion to avoid infinite loop
202
- return [textLine];
203
- }
204
- if (rest.length === 0) {
205
- // end recursion if there is no leftover
206
- return [splittedLine];
207
- }
208
- return [splittedLine, ...(0, exports.getSplittedLines)(rest, calcValues)];
209
- };
210
- exports.getSplittedLines = getSplittedLines;
211
- /**
212
- * If using dynamic font size, iteratively increment or decrement the
213
- * font size to fit the containing box.
214
- * Calculating space usage involves splitting lines where they exceed
215
- * the box width based on the proposed size.
216
- */
217
- const calculateDynamicFontSize = ({ textSchema, font, value, startingFontSize, }) => __awaiter(void 0, void 0, void 0, function* () {
218
- var _a;
219
- const { fontSize: schemaFontSize, dynamicFontSize: dynamicFontSizeSetting, characterSpacing: schemaCharacterSpacing, width: boxWidth, height: boxHeight, lineHeight = constants_1.DEFAULT_LINE_HEIGHT, } = textSchema;
220
- const fontSize = startingFontSize || schemaFontSize || constants_1.DEFAULT_FONT_SIZE;
221
- if (!dynamicFontSizeSetting)
222
- return fontSize;
223
- if (dynamicFontSizeSetting.max < dynamicFontSizeSetting.min)
224
- return fontSize;
225
- const characterSpacing = schemaCharacterSpacing !== null && schemaCharacterSpacing !== void 0 ? schemaCharacterSpacing : constants_1.DEFAULT_CHARACTER_SPACING;
226
- const fontKitFont = yield (0, exports.getFontKitFont)(textSchema, font);
227
- const paragraphs = value.split('\n');
228
- let dynamicFontSize = fontSize;
229
- if (dynamicFontSize < dynamicFontSizeSetting.min) {
230
- dynamicFontSize = dynamicFontSizeSetting.min;
231
- }
232
- else if (dynamicFontSize > dynamicFontSizeSetting.max) {
233
- dynamicFontSize = dynamicFontSizeSetting.max;
234
- }
235
- const dynamicFontFit = (_a = dynamicFontSizeSetting.fit) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_DYNAMIC_FIT;
236
- const calculateConstraints = (size) => {
237
- let totalWidthInMm = 0;
238
- let totalHeightInMm = 0;
239
- const boxWidthInPt = (0, helper_1.mm2pt)(boxWidth);
240
- const firstLineTextHeight = (0, exports.heightOfFontAtSize)(fontKitFont, size);
241
- const firstLineHeightInMm = (0, helper_1.pt2mm)(firstLineTextHeight * lineHeight);
242
- const otherRowHeightInMm = (0, helper_1.pt2mm)(size * lineHeight);
243
- paragraphs.forEach((paragraph, paraIndex) => {
244
- const lines = (0, exports.getSplittedLines)(paragraph, {
245
- font: fontKitFont,
246
- fontSize: size,
247
- characterSpacing,
248
- boxWidthInPt,
249
- });
250
- lines.forEach((line, lineIndex) => {
251
- if (dynamicFontFit === constants_1.DYNAMIC_FIT_VERTICAL) {
252
- // For vertical fit we want to consider the width of text lines where we detect a split
253
- const textWidth = (0, exports.widthOfTextAtSize)(line, fontKitFont, size, characterSpacing);
254
- const textWidthInMm = (0, helper_1.pt2mm)(textWidth);
255
- totalWidthInMm = Math.max(totalWidthInMm, textWidthInMm);
256
- }
257
- if (paraIndex + lineIndex === 0) {
258
- totalHeightInMm += firstLineHeightInMm;
259
- }
260
- else {
261
- totalHeightInMm += otherRowHeightInMm;
262
- }
263
- });
264
- if (dynamicFontFit === constants_1.DYNAMIC_FIT_HORIZONTAL) {
265
- // For horizontal fit we want to consider the line's width 'unsplit'
266
- const textWidth = (0, exports.widthOfTextAtSize)(paragraph, fontKitFont, size, characterSpacing);
267
- const textWidthInMm = (0, helper_1.pt2mm)(textWidth);
268
- totalWidthInMm = Math.max(totalWidthInMm, textWidthInMm);
269
- }
270
- });
271
- return { totalWidthInMm, totalHeightInMm };
272
- };
273
- const shouldFontGrowToFit = (totalWidthInMm, totalHeightInMm) => {
274
- if (dynamicFontSize >= dynamicFontSizeSetting.max) {
275
- return false;
276
- }
277
- if (dynamicFontFit === constants_1.DYNAMIC_FIT_HORIZONTAL) {
278
- return totalWidthInMm < boxWidth;
279
- }
280
- return totalHeightInMm < boxHeight;
281
- };
282
- const shouldFontShrinkToFit = (totalWidthInMm, totalHeightInMm) => {
283
- if (dynamicFontSize <= dynamicFontSizeSetting.min || dynamicFontSize <= 0) {
284
- return false;
285
- }
286
- return totalWidthInMm > boxWidth || totalHeightInMm > boxHeight;
287
- };
288
- let { totalWidthInMm, totalHeightInMm } = calculateConstraints(dynamicFontSize);
289
- // Attempt to increase the font size up to desired fit
290
- while (shouldFontGrowToFit(totalWidthInMm, totalHeightInMm)) {
291
- dynamicFontSize += constants_1.FONT_SIZE_ADJUSTMENT;
292
- const { totalWidthInMm: newWidth, totalHeightInMm: newHeight } = calculateConstraints(dynamicFontSize);
293
- if (newHeight < boxHeight) {
294
- totalWidthInMm = newWidth;
295
- totalHeightInMm = newHeight;
296
- }
297
- else {
298
- dynamicFontSize -= constants_1.FONT_SIZE_ADJUSTMENT;
299
- break;
300
- }
301
- }
302
- // Attempt to decrease the font size down to desired fit
303
- while (shouldFontShrinkToFit(totalWidthInMm, totalHeightInMm)) {
304
- dynamicFontSize -= constants_1.FONT_SIZE_ADJUSTMENT;
305
- ({ totalWidthInMm, totalHeightInMm } = calculateConstraints(dynamicFontSize));
306
- }
307
- return dynamicFontSize;
308
- });
309
- exports.calculateDynamicFontSize = calculateDynamicFontSize;
310
- //# sourceMappingURL=font.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"font.js","sourceRoot":"","sources":["../../../src/font.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AAEnC,iCAA+F;AAC/F,mCAAgC;AAChC,2CAWqB;AACrB,qCAA+C;AAC/C,wBAAmC;AAE5B,MAAM,mBAAmB,GAAG,CAAC,IAAU,EAAE,EAAE;IAChD,MAAM,OAAO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K,CAAC;SACd;QACD,OAAO,cAAc,GAAG,QAAQ,IAAI,eAAe,GAAG,SAAS,CAAC;IAClE,CAAC,CAAC;IAEF,IAAI,EAAE,cAAc,EAAE,eAAe,EAAE,GAAG,oBAAoB,CAAC,eAAe,CAAC,CAAC;IAEhF,sDAAsD;IACtD,OAAO,mBAAmB,CAAC,cAAc,EAAE,eAAe,CAAC,EAAE;QAC3D,eAAe,IAAI,gCAAoB,CAAC;QACxC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,oBAAoB,CAAC,eAAe,CAAC,CAAC;QAEvG,IAAI,SAAS,GAAG,SAAS,EAAE;YACzB,cAAc,GAAG,QAAQ,CAAC;YAC1B,eAAe,GAAG,SAAS,CAAC;SAC7B;aAAM;YACL,eAAe,IAAI,gCAAoB,CAAC;YACxC,MAAM;SACP;KACF;IAED,wDAAwD;IACxD,OAAO,qBAAqB,CAAC,cAAc,EAAE,eAAe,CAAC,EAAE;QAC7D,eAAe,IAAI,gCAAoB,CAAC;QACxC,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,GAAG,oBAAoB,CAAC,eAAe,CAAC,CAAC,CAAC;KAC/E;IAED,OAAO,eAAe,CAAC;AACzB,CAAC,CAAA,CAAC;AApHW,QAAA,wBAAwB,4BAoHnC"}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBarcodeSchema = exports.isImageSchema = exports.isTextSchema = exports.schemaTypes = void 0;
4
- const schema_js_1 = require("./schema.js");
5
- exports.schemaTypes = schema_js_1.schemaTypes;
6
- const isTextSchema = (arg) => arg.type === 'text';
7
- exports.isTextSchema = isTextSchema;
8
- const isImageSchema = (arg) => arg.type === 'image';
9
- exports.isImageSchema = isImageSchema;
10
- const isBarcodeSchema = (arg) => schema_js_1.barcodeSchemaTypes.map((t) => t).includes(arg.type);
11
- exports.isBarcodeSchema = isBarcodeSchema;
12
- //# sourceMappingURL=type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/type.ts"],"names":[],"mappings":";;;AAGA,2CA2BqB;AAUR,QAAA,WAAW,GAAG,uBAAY,CAAC;AACjC,MAAM,YAAY,GAAG,CAAC,GAAiB,EAAqB,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC;AAA7E,QAAA,YAAY,gBAAiE;AACnF,MAAM,aAAa,GAAG,CAAC,GAAiB,EAAsB,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC;AAAhF,QAAA,aAAa,iBAAmE;AACtF,MAAM,eAAe,GAAG,CAAC,GAAiB,EAAwB,EAAE,CACzE,8BAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAW,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AADnD,QAAA,eAAe,mBACoC"}
@@ -1,102 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { createBarCode, barCodeType2Bcid, mapHexColorForBwipJsLib } from '../src/barcode';
11
- import jsQR from 'jsqr';
12
- import { PNG } from 'pngjs';
13
- /**
14
- * 生成したQRコード(png)画像から入力データが正常に読み取れるかをテスト
15
- */
16
- describe('createBarCode', () => {
17
- // テスト名, input, expected
18
- const tests = [
19
- ['URL', 'https://www.google.com/', 'https://www.google.com/'],
20
- ['ひらがな', 'てすとです', 'てすとです'],
21
- ['ひらがな2', 'あいうえおあいうえお2', 'あいうえおあいうえお2'],
22
- ['カタカナ', 'テストです', 'テストです'],
23
- ['漢字', 'お正月', 'お正月'],
24
- ['中国語', '新年快乐', '新年快乐'],
25
- ['タイ語', 'สวัสดีปีใหม่', 'สวัสดีปีใหม่'],
26
- ];
27
- const upcaCode = '416000336108';
28
- describe('generate qrcode with default colours', () => {
29
- for (const t of tests) {
30
- // eslint-disable-next-line no-loop-func
31
- test(`${t[0]}: ${t[1]}`, () => __awaiter(void 0, void 0, void 0, function* () {
32
- const buffer = (yield createBarCode({
33
- type: 'qrcode',
34
- input: t[1],
35
- width: 10,
36
- height: 10,
37
- backgroundcolor: '00000000', // 背景色を指定しないとjsQRでうまく解析できない
38
- }));
39
- const png = PNG.sync.read(buffer);
40
- const pngData = new Uint8ClampedArray(png.data);
41
- const qr = jsQR(pngData, png.width, png.height);
42
- expect(qr).not.toBeNull();
43
- const dataBuffer = Buffer.from(qr.binaryData);
44
- expect(dataBuffer.toString('utf8')).toEqual(t[2]);
45
- }));
46
- }
47
- });
48
- describe('generate qrcode with custom colours', () => {
49
- for (const t of tests) {
50
- // eslint-disable-next-line no-loop-func
51
- test(`${t[0]}: ${t[1]}`, () => __awaiter(void 0, void 0, void 0, function* () {
52
- const buffer = (yield createBarCode({
53
- type: 'qrcode',
54
- input: t[1],
55
- width: 10,
56
- height: 10,
57
- backgroundcolor: 'ffffff',
58
- barcolor: 'f50505',
59
- }));
60
- const png = PNG.sync.read(buffer);
61
- const pngData = new Uint8ClampedArray(png.data);
62
- const qr = jsQR(pngData, png.width, png.height);
63
- expect(qr).not.toBeNull();
64
- const dataBuffer = Buffer.from(qr.binaryData);
65
- expect(dataBuffer.toString('utf8')).toEqual(t[2]);
66
- }));
67
- }
68
- });
69
- });
70
- describe('barCodeType2Bcid test', () => {
71
- test('it maps the nw7 barcode type', () => {
72
- expect(barCodeType2Bcid('nw7')).toEqual('rationalizedCodabar');
73
- });
74
- test('it returns all other types as they are', () => {
75
- expect(barCodeType2Bcid('qrcode')).toEqual('qrcode');
76
- expect(barCodeType2Bcid('japanpost')).toEqual('japanpost');
77
- expect(barCodeType2Bcid('ean8')).toEqual('ean8');
78
- expect(barCodeType2Bcid('ean13')).toEqual('ean13');
79
- expect(barCodeType2Bcid('code39')).toEqual('code39');
80
- expect(barCodeType2Bcid('code128')).toEqual('code128');
81
- expect(barCodeType2Bcid('itf14')).toEqual('itf14');
82
- expect(barCodeType2Bcid('upca')).toEqual('upca');
83
- expect(barCodeType2Bcid('upce')).toEqual('upce');
84
- expect(barCodeType2Bcid('gs1datamatrix')).toEqual('gs1datamatrix');
85
- });
86
- });
87
- describe('mapHexColorForBwipJsLib text', () => {
88
- test('it strips a hex if there is one', () => {
89
- expect(mapHexColorForBwipJsLib('#ffffff')).toEqual('ffffff');
90
- expect(mapHexColorForBwipJsLib('#eee')).toEqual('eee');
91
- expect(mapHexColorForBwipJsLib('ffffff')).toEqual('ffffff');
92
- });
93
- test('it strips a hex from a fallback color if main color not defined', () => {
94
- expect(mapHexColorForBwipJsLib(undefined, '#ffffff')).toEqual('ffffff');
95
- expect(mapHexColorForBwipJsLib(undefined, '#eee')).toEqual('eee');
96
- expect(mapHexColorForBwipJsLib(undefined, 'ffffff')).toEqual('ffffff');
97
- });
98
- test('it defaults to black if neither color nor fallback passed', () => {
99
- expect(mapHexColorForBwipJsLib(undefined)).toEqual('000000');
100
- });
101
- });
102
- //# sourceMappingURL=barcode.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"barcode.test.js","sourceRoot":"","sources":["../../../__tests__/barcode.test.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC1F,OAAO,IAAgB,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B;;GAEG;AACH,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,wBAAwB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