@finsemble/finsemble-electron-adapter 1.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 (146) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +46 -0
  3. package/dist/app.js +3 -0
  4. package/dist/app.js.LICENSE.txt +331 -0
  5. package/dist/app.js.map +1 -0
  6. package/dist/e2o.js +2 -0
  7. package/dist/e2o.js.map +1 -0
  8. package/dist/exports.js +3 -0
  9. package/dist/exports.js.LICENSE.txt +331 -0
  10. package/dist/exports.js.map +1 -0
  11. package/exports.js +10 -0
  12. package/node_modules/electron-ipc-mock/.npmignore +2 -0
  13. package/node_modules/electron-ipc-mock/.travis.yml +8 -0
  14. package/node_modules/electron-ipc-mock/LICENSE +19 -0
  15. package/node_modules/electron-ipc-mock/README.md +42 -0
  16. package/node_modules/electron-ipc-mock/dist/constants.js +8 -0
  17. package/node_modules/electron-ipc-mock/dist/electron-ipc-mock.js +56 -0
  18. package/node_modules/electron-ipc-mock/dist/event.js +25 -0
  19. package/node_modules/electron-ipc-mock/dist/index.js +22 -0
  20. package/node_modules/electron-ipc-mock/dist/ipc-main.js +103 -0
  21. package/node_modules/electron-ipc-mock/dist/ipc-renderer.js +113 -0
  22. package/node_modules/electron-ipc-mock/dist/pipe.js +40 -0
  23. package/node_modules/electron-ipc-mock/dist/utils.js +33 -0
  24. package/node_modules/electron-ipc-mock/package.json +34 -0
  25. package/node_modules/image-size/LICENSE +9 -0
  26. package/node_modules/image-size/Readme.md +182 -0
  27. package/node_modules/image-size/bin/image-size.js +48 -0
  28. package/node_modules/image-size/dist/detector.d.ts +3 -0
  29. package/node_modules/image-size/dist/detector.js +30 -0
  30. package/node_modules/image-size/dist/index.d.ts +11 -0
  31. package/node_modules/image-size/dist/index.js +134 -0
  32. package/node_modules/image-size/dist/readUInt.d.ts +4 -0
  33. package/node_modules/image-size/dist/readUInt.js +11 -0
  34. package/node_modules/image-size/dist/types/bmp.d.ts +2 -0
  35. package/node_modules/image-size/dist/types/bmp.js +14 -0
  36. package/node_modules/image-size/dist/types/cur.d.ts +2 -0
  37. package/node_modules/image-size/dist/types/cur.js +16 -0
  38. package/node_modules/image-size/dist/types/dds.d.ts +2 -0
  39. package/node_modules/image-size/dist/types/dds.js +14 -0
  40. package/node_modules/image-size/dist/types/gif.d.ts +2 -0
  41. package/node_modules/image-size/dist/types/gif.js +16 -0
  42. package/node_modules/image-size/dist/types/icns.d.ts +2 -0
  43. package/node_modules/image-size/dist/types/icns.js +103 -0
  44. package/node_modules/image-size/dist/types/ico.d.ts +2 -0
  45. package/node_modules/image-size/dist/types/ico.js +67 -0
  46. package/node_modules/image-size/dist/types/interface.d.ts +14 -0
  47. package/node_modules/image-size/dist/types/interface.js +2 -0
  48. package/node_modules/image-size/dist/types/j2c.d.ts +2 -0
  49. package/node_modules/image-size/dist/types/j2c.js +15 -0
  50. package/node_modules/image-size/dist/types/jp2.d.ts +2 -0
  51. package/node_modules/image-size/dist/types/jp2.js +58 -0
  52. package/node_modules/image-size/dist/types/jpg.d.ts +2 -0
  53. package/node_modules/image-size/dist/types/jpg.js +123 -0
  54. package/node_modules/image-size/dist/types/ktx.d.ts +2 -0
  55. package/node_modules/image-size/dist/types/ktx.js +15 -0
  56. package/node_modules/image-size/dist/types/png.d.ts +2 -0
  57. package/node_modules/image-size/dist/types/png.js +34 -0
  58. package/node_modules/image-size/dist/types/pnm.d.ts +2 -0
  59. package/node_modules/image-size/dist/types/pnm.js +75 -0
  60. package/node_modules/image-size/dist/types/psd.d.ts +2 -0
  61. package/node_modules/image-size/dist/types/psd.js +14 -0
  62. package/node_modules/image-size/dist/types/svg.d.ts +2 -0
  63. package/node_modules/image-size/dist/types/svg.js +91 -0
  64. package/node_modules/image-size/dist/types/tiff.d.ts +2 -0
  65. package/node_modules/image-size/dist/types/tiff.js +97 -0
  66. package/node_modules/image-size/dist/types/webp.d.ts +2 -0
  67. package/node_modules/image-size/dist/types/webp.js +58 -0
  68. package/node_modules/image-size/dist/types.d.ts +19 -0
  69. package/node_modules/image-size/dist/types.js +38 -0
  70. package/node_modules/image-size/package.json +67 -0
  71. package/node_modules/inherits/LICENSE +16 -0
  72. package/node_modules/inherits/README.md +42 -0
  73. package/node_modules/inherits/inherits.js +9 -0
  74. package/node_modules/inherits/inherits_browser.js +27 -0
  75. package/node_modules/inherits/package.json +29 -0
  76. package/node_modules/queue/LICENSE +8 -0
  77. package/node_modules/queue/index.d.ts +173 -0
  78. package/node_modules/queue/index.js +195 -0
  79. package/node_modules/queue/package.json +43 -0
  80. package/node_modules/queue/readme.md +221 -0
  81. package/package.json +119 -0
  82. package/types/app.d.ts +1 -0
  83. package/types/deploy/deploymentHelpers.d.ts +10 -0
  84. package/types/deploy/installer.d.ts +5 -0
  85. package/types/deploy/packageCreator.d.ts +4 -0
  86. package/types/deploy/schemas/installer.d.ts +3 -0
  87. package/types/deploy/schemas/packager.d.ts +3 -0
  88. package/types/e2o.d.ts +2 -0
  89. package/types/exports.d.ts +19 -0
  90. package/types/logger/classes/LoggerMain.d.ts +21 -0
  91. package/types/logger/classes/LoggerRenderer.d.ts +11 -0
  92. package/types/logger/colorizer.d.ts +2 -0
  93. package/types/logger/config.d.ts +12 -0
  94. package/types/logger/formatters/basic.d.ts +2 -0
  95. package/types/logger/main.d.ts +2 -0
  96. package/types/logger/renderer.d.ts +1 -0
  97. package/types/logger/transports/winston-daily-rotate-file.d.ts +2 -0
  98. package/types/logger/transports/winston-terminal-transport.d.ts +2 -0
  99. package/types/logger/types.d.ts +9 -0
  100. package/types/main/AffinityGroupManager.d.ts +15 -0
  101. package/types/main/BrowserViews.d.ts +38 -0
  102. package/types/main/ExternalApplicationManager.d.ts +37 -0
  103. package/types/main/IAB.d.ts +17 -0
  104. package/types/main/IAC.d.ts +18 -0
  105. package/types/main/Main.d.ts +7 -0
  106. package/types/main/MainBus.d.ts +22 -0
  107. package/types/main/MainSystem.d.ts +75 -0
  108. package/types/main/MainWindow.d.ts +153 -0
  109. package/types/main/Manifest.d.ts +13 -0
  110. package/types/main/MonitorInfo.d.ts +4 -0
  111. package/types/main/PermissionsManager.d.ts +12 -0
  112. package/types/main/ScreenCapture.d.ts +7 -0
  113. package/types/main/SplashScreen.d.ts +13 -0
  114. package/types/main/appDataFolder.d.ts +9 -0
  115. package/types/main/autoUpdaterWrapper.d.ts +37 -0
  116. package/types/main/contentSecurity.d.ts +17 -0
  117. package/types/main/contextMenu.d.ts +2 -0
  118. package/types/main/download.d.ts +18 -0
  119. package/types/main/getWindowIdentity.d.ts +3 -0
  120. package/types/main/listeners.d.ts +6 -0
  121. package/types/main/mainStore.d.ts +3 -0
  122. package/types/main/preloads.d.ts +9 -0
  123. package/types/main/protocolHandler.d.ts +11 -0
  124. package/types/main/updateManager.d.ts +20 -0
  125. package/types/permissions/chromePermissions.d.ts +59 -0
  126. package/types/permissions/defaultWindowOptions.d.ts +377 -0
  127. package/types/render/InterApplicationBus.d.ts +16 -0
  128. package/types/render/Notification.d.ts +3 -0
  129. package/types/render/RequestHelper.d.ts +23 -0
  130. package/types/render/System.d.ts +62 -0
  131. package/types/render/Window.d.ts +75 -0
  132. package/types/render/renderHelpers.d.ts +1 -0
  133. package/types/server/AppD.d.ts +18 -0
  134. package/types/server/AppDStaticConfigPlugin.d.ts +8 -0
  135. package/types/server/CosaicCloud.d.ts +21 -0
  136. package/types/server/Progress.d.ts +26 -0
  137. package/types/server/Server.d.ts +17 -0
  138. package/types/server/SmartDesktop.d.ts +36 -0
  139. package/types/server/SmartDesktopEndpoints.d.ts +99 -0
  140. package/types/server/SmartDesktopStaticConfigPlugin.d.ts +9 -0
  141. package/types/server/cssUtilities.d.ts +6 -0
  142. package/types/server/writeJSON.d.ts +1 -0
  143. package/types/startup/e2oLauncher.d.ts +1 -0
  144. package/types/startup/runScriptInElectron.d.ts +6 -0
  145. package/types/types/types.d.ts +148 -0
  146. package/types/util.d.ts +13 -0
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ICO = void 0;
4
+ const TYPE_ICON = 1;
5
+ /**
6
+ * ICON Header
7
+ *
8
+ * | Offset | Size | Purpose |
9
+ * | 0 | 2 | Reserved. Must always be 0. |
10
+ * | 2 | 2 | Image type: 1 for icon (.ICO) image, 2 for cursor (.CUR) image. Other values are invalid. |
11
+ * | 4 | 2 | Number of images in the file. |
12
+ *
13
+ */
14
+ const SIZE_HEADER = 2 + 2 + 2; // 6
15
+ /**
16
+ * Image Entry
17
+ *
18
+ * | Offset | Size | Purpose |
19
+ * | 0 | 1 | Image width in pixels. Can be any number between 0 and 255. Value 0 means width is 256 pixels. |
20
+ * | 1 | 1 | Image height in pixels. Can be any number between 0 and 255. Value 0 means height is 256 pixels. |
21
+ * | 2 | 1 | Number of colors in the color palette. Should be 0 if the image does not use a color palette. |
22
+ * | 3 | 1 | Reserved. Should be 0. |
23
+ * | 4 | 2 | ICO format: Color planes. Should be 0 or 1. |
24
+ * | | | CUR format: The horizontal coordinates of the hotspot in number of pixels from the left. |
25
+ * | 6 | 2 | ICO format: Bits per pixel. |
26
+ * | | | CUR format: The vertical coordinates of the hotspot in number of pixels from the top. |
27
+ * | 8 | 4 | The size of the image's data in bytes |
28
+ * | 12 | 4 | The offset of BMP or PNG data from the beginning of the ICO/CUR file |
29
+ *
30
+ */
31
+ const SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; // 16
32
+ function getSizeFromOffset(buffer, offset) {
33
+ const value = buffer.readUInt8(offset);
34
+ return value === 0 ? 256 : value;
35
+ }
36
+ function getImageSize(buffer, imageIndex) {
37
+ const offset = SIZE_HEADER + (imageIndex * SIZE_IMAGE_ENTRY);
38
+ return {
39
+ height: getSizeFromOffset(buffer, offset + 1),
40
+ width: getSizeFromOffset(buffer, offset)
41
+ };
42
+ }
43
+ exports.ICO = {
44
+ validate(buffer) {
45
+ if (buffer.readUInt16LE(0) !== 0) {
46
+ return false;
47
+ }
48
+ return buffer.readUInt16LE(2) === TYPE_ICON;
49
+ },
50
+ calculate(buffer) {
51
+ const nbImages = buffer.readUInt16LE(4);
52
+ const imageSize = getImageSize(buffer, 0);
53
+ if (nbImages === 1) {
54
+ return imageSize;
55
+ }
56
+ const imgs = [imageSize];
57
+ for (let imageIndex = 1; imageIndex < nbImages; imageIndex += 1) {
58
+ imgs.push(getImageSize(buffer, imageIndex));
59
+ }
60
+ const result = {
61
+ height: imageSize.height,
62
+ images: imgs,
63
+ width: imageSize.width
64
+ };
65
+ return result;
66
+ }
67
+ };
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ export interface ISize {
3
+ width: number | undefined;
4
+ height: number | undefined;
5
+ orientation?: number;
6
+ type?: string;
7
+ }
8
+ export interface ISizeCalculationResult extends ISize {
9
+ images?: ISize[];
10
+ }
11
+ export interface IImage {
12
+ validate: (buffer: Buffer) => boolean;
13
+ calculate: (buffer: Buffer, filepath?: string) => ISizeCalculationResult;
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { IImage } from './interface';
2
+ export declare const J2C: IImage;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.J2C = void 0;
4
+ exports.J2C = {
5
+ validate(buffer) {
6
+ // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC
7
+ return buffer.toString('hex', 0, 4) === 'ff4fff51';
8
+ },
9
+ calculate(buffer) {
10
+ return {
11
+ height: buffer.readUInt32BE(12),
12
+ width: buffer.readUInt32BE(8),
13
+ };
14
+ }
15
+ };
@@ -0,0 +1,2 @@
1
+ import { IImage } from './interface';
2
+ export declare const JP2: IImage;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JP2 = void 0;
4
+ const BoxTypes = {
5
+ ftyp: '66747970',
6
+ ihdr: '69686472',
7
+ jp2h: '6a703268',
8
+ jp__: '6a502020',
9
+ rreq: '72726571',
10
+ xml_: '786d6c20'
11
+ };
12
+ const calculateRREQLength = (box) => {
13
+ const unit = box.readUInt8(0);
14
+ let offset = 1 + (2 * unit);
15
+ const numStdFlags = box.readUInt16BE(offset);
16
+ const flagsLength = numStdFlags * (2 + unit);
17
+ offset = offset + 2 + flagsLength;
18
+ const numVendorFeatures = box.readUInt16BE(offset);
19
+ const featuresLength = numVendorFeatures * (16 + unit);
20
+ return offset + 2 + featuresLength;
21
+ };
22
+ const parseIHDR = (box) => {
23
+ return {
24
+ height: box.readUInt32BE(4),
25
+ width: box.readUInt32BE(8),
26
+ };
27
+ };
28
+ exports.JP2 = {
29
+ validate(buffer) {
30
+ const signature = buffer.toString('hex', 4, 8);
31
+ const signatureLength = buffer.readUInt32BE(0);
32
+ if (signature !== BoxTypes.jp__ || signatureLength < 1) {
33
+ return false;
34
+ }
35
+ const ftypeBoxStart = signatureLength + 4;
36
+ const ftypBoxLength = buffer.readUInt32BE(signatureLength);
37
+ const ftypBox = buffer.slice(ftypeBoxStart, ftypeBoxStart + ftypBoxLength);
38
+ return ftypBox.toString('hex', 0, 4) === BoxTypes.ftyp;
39
+ },
40
+ calculate(buffer) {
41
+ const signatureLength = buffer.readUInt32BE(0);
42
+ const ftypBoxLength = buffer.readUInt16BE(signatureLength + 2);
43
+ let offset = signatureLength + 4 + ftypBoxLength;
44
+ const nextBoxType = buffer.toString('hex', offset, offset + 4);
45
+ switch (nextBoxType) {
46
+ case BoxTypes.rreq:
47
+ // WHAT ARE THESE 4 BYTES?????
48
+ // eslint-disable-next-line no-case-declarations
49
+ const MAGIC = 4;
50
+ offset = offset + 4 + MAGIC + calculateRREQLength(buffer.slice(offset + 4));
51
+ return parseIHDR(buffer.slice(offset + 8, offset + 24));
52
+ case BoxTypes.jp2h:
53
+ return parseIHDR(buffer.slice(offset + 8, offset + 24));
54
+ default:
55
+ throw new TypeError('Unsupported header found: ' + buffer.toString('ascii', offset, offset + 4));
56
+ }
57
+ }
58
+ };
@@ -0,0 +1,2 @@
1
+ import { IImage } from './interface';
2
+ export declare const JPG: IImage;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ // NOTE: we only support baseline and progressive JPGs here
3
+ // due to the structure of the loader class, we only get a buffer
4
+ // with a maximum size of 4096 bytes. so if the SOF marker is outside
5
+ // if this range we can't detect the file size correctly.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.JPG = void 0;
8
+ const readUInt_1 = require("../readUInt");
9
+ const EXIF_MARKER = '45786966';
10
+ const APP1_DATA_SIZE_BYTES = 2;
11
+ const EXIF_HEADER_BYTES = 6;
12
+ const TIFF_BYTE_ALIGN_BYTES = 2;
13
+ const BIG_ENDIAN_BYTE_ALIGN = '4d4d';
14
+ const LITTLE_ENDIAN_BYTE_ALIGN = '4949';
15
+ // Each entry is exactly 12 bytes
16
+ const IDF_ENTRY_BYTES = 12;
17
+ const NUM_DIRECTORY_ENTRIES_BYTES = 2;
18
+ function isEXIF(buffer) {
19
+ return (buffer.toString('hex', 2, 6) === EXIF_MARKER);
20
+ }
21
+ function extractSize(buffer, index) {
22
+ return {
23
+ height: buffer.readUInt16BE(index),
24
+ width: buffer.readUInt16BE(index + 2)
25
+ };
26
+ }
27
+ function extractOrientation(exifBlock, isBigEndian) {
28
+ // TODO: assert that this contains 0x002A
29
+ // let STATIC_MOTOROLA_TIFF_HEADER_BYTES = 2
30
+ // let TIFF_IMAGE_FILE_DIRECTORY_BYTES = 4
31
+ // TODO: derive from TIFF_IMAGE_FILE_DIRECTORY_BYTES
32
+ const idfOffset = 8;
33
+ // IDF osset works from right after the header bytes
34
+ // (so the offset includes the tiff byte align)
35
+ const offset = EXIF_HEADER_BYTES + idfOffset;
36
+ const idfDirectoryEntries = (0, readUInt_1.readUInt)(exifBlock, 16, offset, isBigEndian);
37
+ for (let directoryEntryNumber = 0; directoryEntryNumber < idfDirectoryEntries; directoryEntryNumber++) {
38
+ const start = offset + NUM_DIRECTORY_ENTRIES_BYTES + (directoryEntryNumber * IDF_ENTRY_BYTES);
39
+ const end = start + IDF_ENTRY_BYTES;
40
+ // Skip on corrupt EXIF blocks
41
+ if (start > exifBlock.length) {
42
+ return;
43
+ }
44
+ const block = exifBlock.slice(start, end);
45
+ const tagNumber = (0, readUInt_1.readUInt)(block, 16, 0, isBigEndian);
46
+ // 0x0112 (decimal: 274) is the `orientation` tag ID
47
+ if (tagNumber === 274) {
48
+ const dataFormat = (0, readUInt_1.readUInt)(block, 16, 2, isBigEndian);
49
+ if (dataFormat !== 3) {
50
+ return;
51
+ }
52
+ // unsinged int has 2 bytes per component
53
+ // if there would more than 4 bytes in total it's a pointer
54
+ const numberOfComponents = (0, readUInt_1.readUInt)(block, 32, 4, isBigEndian);
55
+ if (numberOfComponents !== 1) {
56
+ return;
57
+ }
58
+ return (0, readUInt_1.readUInt)(block, 16, 8, isBigEndian);
59
+ }
60
+ }
61
+ }
62
+ function validateExifBlock(buffer, index) {
63
+ // Skip APP1 Data Size
64
+ const exifBlock = buffer.slice(APP1_DATA_SIZE_BYTES, index);
65
+ // Consider byte alignment
66
+ const byteAlign = exifBlock.toString('hex', EXIF_HEADER_BYTES, EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES);
67
+ // Ignore Empty EXIF. Validate byte alignment
68
+ const isBigEndian = byteAlign === BIG_ENDIAN_BYTE_ALIGN;
69
+ const isLittleEndian = byteAlign === LITTLE_ENDIAN_BYTE_ALIGN;
70
+ if (isBigEndian || isLittleEndian) {
71
+ return extractOrientation(exifBlock, isBigEndian);
72
+ }
73
+ }
74
+ function validateBuffer(buffer, index) {
75
+ // index should be within buffer limits
76
+ if (index > buffer.length) {
77
+ throw new TypeError('Corrupt JPG, exceeded buffer limits');
78
+ }
79
+ // Every JPEG block must begin with a 0xFF
80
+ if (buffer[index] !== 0xFF) {
81
+ throw new TypeError('Invalid JPG, marker table corrupted');
82
+ }
83
+ }
84
+ exports.JPG = {
85
+ validate(buffer) {
86
+ const SOIMarker = buffer.toString('hex', 0, 2);
87
+ return ('ffd8' === SOIMarker);
88
+ },
89
+ calculate(buffer) {
90
+ // Skip 4 chars, they are for signature
91
+ buffer = buffer.slice(4);
92
+ let orientation;
93
+ let next;
94
+ while (buffer.length) {
95
+ // read length of the next block
96
+ const i = buffer.readUInt16BE(0);
97
+ if (isEXIF(buffer)) {
98
+ orientation = validateExifBlock(buffer, i);
99
+ }
100
+ // ensure correct format
101
+ validateBuffer(buffer, i);
102
+ // 0xFFC0 is baseline standard(SOF)
103
+ // 0xFFC1 is baseline optimized(SOF)
104
+ // 0xFFC2 is progressive(SOF2)
105
+ next = buffer[i + 1];
106
+ if (next === 0xC0 || next === 0xC1 || next === 0xC2) {
107
+ const size = extractSize(buffer, i + 5);
108
+ // TODO: is orientation=0 a valid answer here?
109
+ if (!orientation) {
110
+ return size;
111
+ }
112
+ return {
113
+ height: size.height,
114
+ orientation,
115
+ width: size.width
116
+ };
117
+ }
118
+ // move to the next block
119
+ buffer = buffer.slice(i + 2);
120
+ }
121
+ throw new TypeError('Invalid JPG, no size found');
122
+ }
123
+ };
@@ -0,0 +1,2 @@
1
+ import { IImage } from './interface';
2
+ export declare const KTX: IImage;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KTX = void 0;
4
+ const SIGNATURE = 'KTX 11';
5
+ exports.KTX = {
6
+ validate(buffer) {
7
+ return SIGNATURE === buffer.toString('ascii', 1, 7);
8
+ },
9
+ calculate(buffer) {
10
+ return {
11
+ height: buffer.readUInt32LE(40),
12
+ width: buffer.readUInt32LE(36),
13
+ };
14
+ }
15
+ };
@@ -0,0 +1,2 @@
1
+ import { IImage } from './interface';
2
+ export declare const PNG: IImage;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PNG = void 0;
4
+ const pngSignature = 'PNG\r\n\x1a\n';
5
+ const pngImageHeaderChunkName = 'IHDR';
6
+ // Used to detect "fried" png's: http://www.jongware.com/pngdefry.html
7
+ const pngFriedChunkName = 'CgBI';
8
+ exports.PNG = {
9
+ validate(buffer) {
10
+ if (pngSignature === buffer.toString('ascii', 1, 8)) {
11
+ let chunkName = buffer.toString('ascii', 12, 16);
12
+ if (chunkName === pngFriedChunkName) {
13
+ chunkName = buffer.toString('ascii', 28, 32);
14
+ }
15
+ if (chunkName !== pngImageHeaderChunkName) {
16
+ throw new TypeError('Invalid PNG');
17
+ }
18
+ return true;
19
+ }
20
+ return false;
21
+ },
22
+ calculate(buffer) {
23
+ if (buffer.toString('ascii', 12, 16) === pngFriedChunkName) {
24
+ return {
25
+ height: buffer.readUInt32BE(36),
26
+ width: buffer.readUInt32BE(32)
27
+ };
28
+ }
29
+ return {
30
+ height: buffer.readUInt32BE(20),
31
+ width: buffer.readUInt32BE(16)
32
+ };
33
+ }
34
+ };
@@ -0,0 +1,2 @@
1
+ import { IImage } from './interface';
2
+ export declare const PNM: IImage;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PNM = void 0;
4
+ const PNMTypes = {
5
+ P1: 'pbm/ascii',
6
+ P2: 'pgm/ascii',
7
+ P3: 'ppm/ascii',
8
+ P4: 'pbm',
9
+ P5: 'pgm',
10
+ P6: 'ppm',
11
+ P7: 'pam',
12
+ PF: 'pfm'
13
+ };
14
+ const Signatures = Object.keys(PNMTypes);
15
+ const handlers = {
16
+ default: (lines) => {
17
+ let dimensions = [];
18
+ while (lines.length > 0) {
19
+ const line = lines.shift();
20
+ if (line[0] === '#') {
21
+ continue;
22
+ }
23
+ dimensions = line.split(' ');
24
+ break;
25
+ }
26
+ if (dimensions.length === 2) {
27
+ return {
28
+ height: parseInt(dimensions[1], 10),
29
+ width: parseInt(dimensions[0], 10),
30
+ };
31
+ }
32
+ else {
33
+ throw new TypeError('Invalid PNM');
34
+ }
35
+ },
36
+ pam: (lines) => {
37
+ const size = {};
38
+ while (lines.length > 0) {
39
+ const line = lines.shift();
40
+ if (line.length > 16 || line.charCodeAt(0) > 128) {
41
+ continue;
42
+ }
43
+ const [key, value] = line.split(' ');
44
+ if (key && value) {
45
+ size[key.toLowerCase()] = parseInt(value, 10);
46
+ }
47
+ if (size.height && size.width) {
48
+ break;
49
+ }
50
+ }
51
+ if (size.height && size.width) {
52
+ return {
53
+ height: size.height,
54
+ width: size.width
55
+ };
56
+ }
57
+ else {
58
+ throw new TypeError('Invalid PAM');
59
+ }
60
+ }
61
+ };
62
+ exports.PNM = {
63
+ validate(buffer) {
64
+ const signature = buffer.toString('ascii', 0, 2);
65
+ return Signatures.includes(signature);
66
+ },
67
+ calculate(buffer) {
68
+ const signature = buffer.toString('ascii', 0, 2);
69
+ const type = PNMTypes[signature];
70
+ // TODO: this probably generates garbage. move to a stream based parser
71
+ const lines = buffer.toString('ascii', 3).split(/[\r\n]+/);
72
+ const handler = handlers[type] || handlers.default;
73
+ return handler(lines);
74
+ }
75
+ };
@@ -0,0 +1,2 @@
1
+ import { IImage } from './interface';
2
+ export declare const PSD: IImage;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PSD = void 0;
4
+ exports.PSD = {
5
+ validate(buffer) {
6
+ return ('8BPS' === buffer.toString('ascii', 0, 4));
7
+ },
8
+ calculate(buffer) {
9
+ return {
10
+ height: buffer.readUInt32BE(14),
11
+ width: buffer.readUInt32BE(18)
12
+ };
13
+ }
14
+ };
@@ -0,0 +1,2 @@
1
+ import { IImage } from './interface';
2
+ export declare const SVG: IImage;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SVG = void 0;
4
+ const svgReg = /<svg\s([^>"']|"[^"]*"|'[^']*')*>/;
5
+ const extractorRegExps = {
6
+ height: /\sheight=(['"])([^%]+?)\1/,
7
+ root: svgReg,
8
+ viewbox: /\sviewBox=(['"])(.+?)\1/i,
9
+ width: /\swidth=(['"])([^%]+?)\1/,
10
+ };
11
+ const INCH_CM = 2.54;
12
+ const units = {
13
+ in: 96,
14
+ cm: 96 / INCH_CM,
15
+ em: 16,
16
+ ex: 8,
17
+ m: 96 / INCH_CM * 100,
18
+ mm: 96 / INCH_CM / 10,
19
+ pc: 96 / 72 / 12,
20
+ pt: 96 / 72,
21
+ px: 1
22
+ };
23
+ const unitsReg = new RegExp(`^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join('|')})?$`);
24
+ function parseLength(len) {
25
+ const m = unitsReg.exec(len);
26
+ if (!m) {
27
+ return undefined;
28
+ }
29
+ return Math.round(Number(m[1]) * (units[m[2]] || 1));
30
+ }
31
+ function parseViewbox(viewbox) {
32
+ const bounds = viewbox.split(' ');
33
+ return {
34
+ height: parseLength(bounds[3]),
35
+ width: parseLength(bounds[2])
36
+ };
37
+ }
38
+ function parseAttributes(root) {
39
+ const width = root.match(extractorRegExps.width);
40
+ const height = root.match(extractorRegExps.height);
41
+ const viewbox = root.match(extractorRegExps.viewbox);
42
+ return {
43
+ height: height && parseLength(height[2]),
44
+ viewbox: viewbox && parseViewbox(viewbox[2]),
45
+ width: width && parseLength(width[2]),
46
+ };
47
+ }
48
+ function calculateByDimensions(attrs) {
49
+ return {
50
+ height: attrs.height,
51
+ width: attrs.width,
52
+ };
53
+ }
54
+ function calculateByViewbox(attrs, viewbox) {
55
+ const ratio = viewbox.width / viewbox.height;
56
+ if (attrs.width) {
57
+ return {
58
+ height: Math.floor(attrs.width / ratio),
59
+ width: attrs.width,
60
+ };
61
+ }
62
+ if (attrs.height) {
63
+ return {
64
+ height: attrs.height,
65
+ width: Math.floor(attrs.height * ratio),
66
+ };
67
+ }
68
+ return {
69
+ height: viewbox.height,
70
+ width: viewbox.width,
71
+ };
72
+ }
73
+ exports.SVG = {
74
+ validate(buffer) {
75
+ const str = String(buffer);
76
+ return svgReg.test(str);
77
+ },
78
+ calculate(buffer) {
79
+ const root = buffer.toString('utf8').match(extractorRegExps.root);
80
+ if (root) {
81
+ const attrs = parseAttributes(root[0]);
82
+ if (attrs.width && attrs.height) {
83
+ return calculateByDimensions(attrs);
84
+ }
85
+ if (attrs.viewbox) {
86
+ return calculateByViewbox(attrs, attrs.viewbox);
87
+ }
88
+ }
89
+ throw new TypeError('Invalid SVG');
90
+ }
91
+ };
@@ -0,0 +1,2 @@
1
+ import { IImage } from './interface';
2
+ export declare const TIFF: IImage;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TIFF = void 0;
4
+ // based on http://www.compix.com/fileformattif.htm
5
+ // TO-DO: support big-endian as well
6
+ const fs = require("fs");
7
+ const readUInt_1 = require("../readUInt");
8
+ // Read IFD (image-file-directory) into a buffer
9
+ function readIFD(buffer, filepath, isBigEndian) {
10
+ const ifdOffset = (0, readUInt_1.readUInt)(buffer, 32, 4, isBigEndian);
11
+ // read only till the end of the file
12
+ let bufferSize = 1024;
13
+ const fileSize = fs.statSync(filepath).size;
14
+ if (ifdOffset + bufferSize > fileSize) {
15
+ bufferSize = fileSize - ifdOffset - 10;
16
+ }
17
+ // populate the buffer
18
+ const endBuffer = Buffer.alloc(bufferSize);
19
+ const descriptor = fs.openSync(filepath, 'r');
20
+ fs.readSync(descriptor, endBuffer, 0, bufferSize, ifdOffset);
21
+ fs.closeSync(descriptor);
22
+ return endBuffer.slice(2);
23
+ }
24
+ // TIFF values seem to be messed up on Big-Endian, this helps
25
+ function readValue(buffer, isBigEndian) {
26
+ const low = (0, readUInt_1.readUInt)(buffer, 16, 8, isBigEndian);
27
+ const high = (0, readUInt_1.readUInt)(buffer, 16, 10, isBigEndian);
28
+ return (high << 16) + low;
29
+ }
30
+ // move to the next tag
31
+ function nextTag(buffer) {
32
+ if (buffer.length > 24) {
33
+ return buffer.slice(12);
34
+ }
35
+ }
36
+ // Extract IFD tags from TIFF metadata
37
+ function extractTags(buffer, isBigEndian) {
38
+ const tags = {};
39
+ let temp = buffer;
40
+ while (temp && temp.length) {
41
+ const code = (0, readUInt_1.readUInt)(temp, 16, 0, isBigEndian);
42
+ const type = (0, readUInt_1.readUInt)(temp, 16, 2, isBigEndian);
43
+ const length = (0, readUInt_1.readUInt)(temp, 32, 4, isBigEndian);
44
+ // 0 means end of IFD
45
+ if (code === 0) {
46
+ break;
47
+ }
48
+ else {
49
+ // 256 is width, 257 is height
50
+ // if (code === 256 || code === 257) {
51
+ if (length === 1 && (type === 3 || type === 4)) {
52
+ tags[code] = readValue(temp, isBigEndian);
53
+ }
54
+ // move to the next tag
55
+ temp = nextTag(temp);
56
+ }
57
+ }
58
+ return tags;
59
+ }
60
+ // Test if the TIFF is Big Endian or Little Endian
61
+ function determineEndianness(buffer) {
62
+ const signature = buffer.toString('ascii', 0, 2);
63
+ if ('II' === signature) {
64
+ return 'LE';
65
+ }
66
+ else if ('MM' === signature) {
67
+ return 'BE';
68
+ }
69
+ }
70
+ const signatures = [
71
+ // '492049', // currently not supported
72
+ '49492a00',
73
+ '4d4d002a', // Big Endian
74
+ // '4d4d002a', // BigTIFF > 4GB. currently not supported
75
+ ];
76
+ exports.TIFF = {
77
+ validate(buffer) {
78
+ return signatures.includes(buffer.toString('hex', 0, 4));
79
+ },
80
+ calculate(buffer, filepath) {
81
+ if (!filepath) {
82
+ throw new TypeError('Tiff doesn\'t support buffer');
83
+ }
84
+ // Determine BE/LE
85
+ const isBigEndian = determineEndianness(buffer) === 'BE';
86
+ // read the IFD
87
+ const ifdBuffer = readIFD(buffer, filepath, isBigEndian);
88
+ // extract the tags from the IFD
89
+ const tags = extractTags(ifdBuffer, isBigEndian);
90
+ const width = tags[256];
91
+ const height = tags[257];
92
+ if (!width || !height) {
93
+ throw new TypeError('Invalid Tiff. Missing tags');
94
+ }
95
+ return { height, width };
96
+ }
97
+ };
@@ -0,0 +1,2 @@
1
+ import { IImage } from './interface';
2
+ export declare const WEBP: IImage;