pdfjs-dist 2.0.943 → 2.4.456

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.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (192) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8286 -14230
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +25500 -26628
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25473 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +57878 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +407 -0
  29. package/es5/web/pdf_viewer.js +7757 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +2887 -4094
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +855 -778
  36. package/lib/core/arithmetic_decoder.js +325 -311
  37. package/lib/core/bidi.js +117 -50
  38. package/lib/core/ccitt.js +251 -89
  39. package/lib/core/ccitt_stream.js +26 -16
  40. package/lib/core/cff_parser.js +525 -197
  41. package/lib/core/charsets.js +6 -5
  42. package/lib/core/chunked_stream.js +541 -406
  43. package/lib/core/cmap.js +368 -253
  44. package/lib/core/colorspace.js +781 -800
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +609 -422
  47. package/lib/core/document.js +649 -481
  48. package/lib/core/encodings.js +33 -24
  49. package/lib/core/evaluator.js +1471 -736
  50. package/lib/core/font_renderer.js +289 -149
  51. package/lib/core/fonts.js +1067 -413
  52. package/lib/core/function.js +517 -287
  53. package/lib/core/glyphlist.js +4529 -4527
  54. package/lib/core/image.js +232 -114
  55. package/lib/core/image_utils.js +94 -0
  56. package/lib/core/jbig2.js +711 -342
  57. package/lib/core/jbig2_stream.js +31 -19
  58. package/lib/core/jpeg_stream.js +151 -26
  59. package/lib/core/jpg.js +433 -181
  60. package/lib/core/jpx.js +551 -143
  61. package/lib/core/jpx_stream.js +40 -28
  62. package/lib/core/metrics.js +2931 -2931
  63. package/lib/core/murmurhash3.js +104 -97
  64. package/lib/core/obj.js +1561 -1053
  65. package/lib/core/operator_list.js +192 -64
  66. package/lib/core/parser.js +1162 -864
  67. package/lib/core/pattern.js +224 -75
  68. package/lib/core/pdf_manager.js +154 -285
  69. package/lib/core/primitives.js +145 -69
  70. package/lib/core/ps_parser.js +212 -162
  71. package/lib/core/standard_fonts.js +245 -244
  72. package/lib/core/stream.js +353 -81
  73. package/lib/core/type1_parser.js +218 -68
  74. package/lib/core/unicode.js +1682 -1655
  75. package/lib/core/worker.js +233 -302
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +808 -862
  78. package/lib/display/api.js +1778 -1462
  79. package/lib/display/api_compatibility.js +14 -9
  80. package/lib/display/canvas.js +463 -140
  81. package/lib/display/content_disposition.js +86 -58
  82. package/lib/display/display_utils.js +524 -0
  83. package/lib/display/fetch_stream.js +202 -274
  84. package/lib/display/font_loader.js +311 -333
  85. package/lib/display/metadata.js +98 -88
  86. package/lib/display/network.js +343 -347
  87. package/lib/display/network_utils.js +46 -26
  88. package/lib/display/node_stream.js +326 -404
  89. package/lib/display/pattern_helper.js +168 -69
  90. package/lib/display/svg.js +1296 -885
  91. package/lib/display/text_layer.js +229 -103
  92. package/lib/display/transport_stream.js +290 -250
  93. package/lib/display/webgl.js +116 -83
  94. package/lib/display/worker_options.js +6 -5
  95. package/lib/display/xml_parser.js +358 -337
  96. package/lib/examples/node/domstubs.js +95 -39
  97. package/lib/pdf.js +49 -31
  98. package/lib/pdf.worker.js +7 -5
  99. package/lib/shared/compatibility.js +3 -145
  100. package/lib/shared/is_node.js +8 -7
  101. package/lib/shared/message_handler.js +367 -314
  102. package/lib/shared/util.js +421 -415
  103. package/lib/test/unit/annotation_spec.js +1570 -690
  104. package/lib/test/unit/api_spec.js +855 -493
  105. package/lib/test/unit/bidi_spec.js +12 -12
  106. package/lib/test/unit/cff_parser_spec.js +88 -61
  107. package/lib/test/unit/clitests_helper.js +9 -12
  108. package/lib/test/unit/cmap_spec.js +140 -88
  109. package/lib/test/unit/colorspace_spec.js +204 -152
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +194 -182
  112. package/lib/test/unit/custom_spec.js +50 -64
  113. package/lib/test/unit/display_svg_spec.js +53 -38
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +17 -22
  116. package/lib/test/unit/encodings_spec.js +15 -57
  117. package/lib/test/unit/evaluator_spec.js +90 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +219 -205
  120. package/lib/test/unit/jasmine-boot.js +68 -39
  121. package/lib/test/unit/message_handler_spec.js +187 -160
  122. package/lib/test/unit/metadata_spec.js +87 -34
  123. package/lib/test/unit/murmurhash3_spec.js +13 -13
  124. package/lib/test/unit/network_spec.js +26 -59
  125. package/lib/test/unit/network_utils_spec.js +187 -121
  126. package/lib/test/unit/node_stream_spec.js +98 -90
  127. package/lib/test/unit/parser_spec.js +173 -131
  128. package/lib/test/unit/pdf_find_controller_spec.js +148 -67
  129. package/lib/test/unit/pdf_find_utils_spec.js +35 -34
  130. package/lib/test/unit/pdf_history_spec.js +45 -33
  131. package/lib/test/unit/primitives_spec.js +161 -126
  132. package/lib/test/unit/stream_spec.js +22 -15
  133. package/lib/test/unit/test_utils.js +149 -98
  134. package/lib/test/unit/testreporter.js +36 -18
  135. package/lib/test/unit/type1_parser_spec.js +46 -44
  136. package/lib/test/unit/ui_utils_spec.js +388 -372
  137. package/lib/test/unit/unicode_spec.js +49 -46
  138. package/lib/test/unit/util_spec.js +144 -248
  139. package/lib/web/annotation_layer_builder.js +75 -95
  140. package/lib/web/app.js +1538 -1147
  141. package/lib/web/app_options.js +116 -104
  142. package/lib/web/base_viewer.js +950 -775
  143. package/lib/web/chromecom.js +217 -225
  144. package/lib/web/debugger.js +236 -148
  145. package/lib/web/download_manager.js +50 -50
  146. package/lib/web/firefox_print_service.js +51 -33
  147. package/lib/web/firefoxcom.js +225 -352
  148. package/lib/web/genericcom.js +30 -93
  149. package/lib/web/genericl10n.js +26 -143
  150. package/lib/web/grab_to_pan.js +57 -33
  151. package/lib/web/interfaces.js +105 -232
  152. package/lib/web/overlay_manager.js +73 -227
  153. package/lib/web/password_prompt.js +44 -62
  154. package/lib/web/pdf_attachment_viewer.js +118 -123
  155. package/lib/web/pdf_cursor_tools.js +89 -93
  156. package/lib/web/pdf_document_properties.js +242 -281
  157. package/lib/web/pdf_find_bar.js +157 -163
  158. package/lib/web/pdf_find_controller.js +598 -454
  159. package/lib/web/pdf_find_utils.js +32 -16
  160. package/lib/web/pdf_history.js +481 -355
  161. package/lib/web/pdf_link_service.js +355 -323
  162. package/lib/web/pdf_outline_viewer.js +167 -152
  163. package/lib/web/pdf_page_view.js +511 -457
  164. package/lib/web/pdf_presentation_mode.js +347 -335
  165. package/lib/web/pdf_print_service.js +133 -103
  166. package/lib/web/pdf_rendering_queue.js +98 -100
  167. package/lib/web/pdf_sidebar.js +323 -299
  168. package/lib/web/pdf_sidebar_resizer.js +107 -108
  169. package/lib/web/pdf_single_page_viewer.js +94 -146
  170. package/lib/web/pdf_thumbnail_view.js +319 -269
  171. package/lib/web/pdf_thumbnail_viewer.js +219 -199
  172. package/lib/web/pdf_viewer.component.js +111 -32
  173. package/lib/web/pdf_viewer.js +61 -101
  174. package/lib/web/preferences.js +87 -272
  175. package/lib/web/secondary_toolbar.js +207 -220
  176. package/lib/web/text_layer_builder.js +322 -322
  177. package/lib/web/toolbar.js +227 -180
  178. package/lib/web/ui_utils.js +476 -421
  179. package/lib/web/view_history.js +59 -208
  180. package/lib/web/viewer_compatibility.js +9 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +36 -22
  183. package/web/pdf_viewer.js +4407 -4516
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -441
  189. package/lib/shared/streams_polyfill.js +0 -39
  190. package/lib/shared/url_polyfill.js +0 -50
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
  192. package/lib/web/dom_events.js +0 -140
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2018 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,40 +19,35 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.ColorSpace = undefined;
27
+ exports.ColorSpace = void 0;
28
28
 
29
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
29
+ var _util = require("../shared/util.js");
30
30
 
31
- var _util = require('../shared/util');
32
-
33
- var _primitives = require('./primitives');
34
-
35
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
36
-
37
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
38
-
39
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
31
+ var _primitives = require("./primitives.js");
40
32
 
41
33
  function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) {
42
- var COMPONENTS = 3;
34
+ const COMPONENTS = 3;
43
35
  alpha01 = alpha01 !== 1 ? 0 : alpha01;
44
- var xRatio = w1 / w2;
45
- var yRatio = h1 / h2;
46
- var newIndex = 0,
47
- oldIndex = void 0;
48
- var xScaled = new Uint16Array(w2);
49
- var w1Scanline = w1 * COMPONENTS;
50
- for (var i = 0; i < w2; i++) {
36
+ const xRatio = w1 / w2;
37
+ const yRatio = h1 / h2;
38
+ let newIndex = 0,
39
+ oldIndex;
40
+ const xScaled = new Uint16Array(w2);
41
+ const w1Scanline = w1 * COMPONENTS;
42
+
43
+ for (let i = 0; i < w2; i++) {
51
44
  xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
52
45
  }
53
- for (var _i = 0; _i < h2; _i++) {
54
- var py = Math.floor(_i * yRatio) * w1Scanline;
55
- for (var j = 0; j < w2; j++) {
46
+
47
+ for (let i = 0; i < h2; i++) {
48
+ const py = Math.floor(i * yRatio) * w1Scanline;
49
+
50
+ for (let j = 0; j < w2; j++) {
56
51
  oldIndex = py + xScaled[j];
57
52
  dest[newIndex++] = src[oldIndex++];
58
53
  dest[newIndex++] = src[oldIndex++];
@@ -62,746 +57,730 @@ function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) {
62
57
  }
63
58
  }
64
59
 
65
- var ColorSpace = function () {
66
- function ColorSpace(name, numComps) {
67
- _classCallCheck(this, ColorSpace);
68
-
60
+ class ColorSpace {
61
+ constructor(name, numComps) {
69
62
  if (this.constructor === ColorSpace) {
70
- (0, _util.unreachable)('Cannot initialize ColorSpace.');
63
+ (0, _util.unreachable)("Cannot initialize ColorSpace.");
71
64
  }
65
+
72
66
  this.name = name;
73
67
  this.numComps = numComps;
74
68
  }
75
69
 
76
- _createClass(ColorSpace, [{
77
- key: 'getRgb',
78
- value: function getRgb(src, srcOffset) {
79
- var rgb = new Uint8ClampedArray(3);
80
- this.getRgbItem(src, srcOffset, rgb, 0);
81
- return rgb;
82
- }
83
- }, {
84
- key: 'getRgbItem',
85
- value: function getRgbItem(src, srcOffset, dest, destOffset) {
86
- (0, _util.unreachable)('Should not call ColorSpace.getRgbItem');
87
- }
88
- }, {
89
- key: 'getRgbBuffer',
90
- value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
91
- (0, _util.unreachable)('Should not call ColorSpace.getRgbBuffer');
92
- }
93
- }, {
94
- key: 'getOutputLength',
95
- value: function getOutputLength(inputLength, alpha01) {
96
- (0, _util.unreachable)('Should not call ColorSpace.getOutputLength');
97
- }
98
- }, {
99
- key: 'isPassthrough',
100
- value: function isPassthrough(bits) {
101
- return false;
102
- }
103
- }, {
104
- key: 'fillRgb',
105
- value: function fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
106
- var count = originalWidth * originalHeight;
107
- var rgbBuf = null;
108
- var numComponentColors = 1 << bpc;
109
- var needsResizing = originalHeight !== height || originalWidth !== width;
110
- if (this.isPassthrough(bpc)) {
111
- rgbBuf = comps;
112
- } else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
113
- var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
114
- for (var i = 0; i < numComponentColors; i++) {
115
- allColors[i] = i;
116
- }
117
- var colorMap = new Uint8ClampedArray(numComponentColors * 3);
118
- this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, 0);
119
- if (!needsResizing) {
120
- var destPos = 0;
121
- for (var _i2 = 0; _i2 < count; ++_i2) {
122
- var key = comps[_i2] * 3;
123
- dest[destPos++] = colorMap[key];
124
- dest[destPos++] = colorMap[key + 1];
125
- dest[destPos++] = colorMap[key + 2];
126
- destPos += alpha01;
127
- }
128
- } else {
129
- rgbBuf = new Uint8Array(count * 3);
130
- var rgbPos = 0;
131
- for (var _i3 = 0; _i3 < count; ++_i3) {
132
- var _key = comps[_i3] * 3;
133
- rgbBuf[rgbPos++] = colorMap[_key];
134
- rgbBuf[rgbPos++] = colorMap[_key + 1];
135
- rgbBuf[rgbPos++] = colorMap[_key + 2];
136
- }
70
+ getRgb(src, srcOffset) {
71
+ const rgb = new Uint8ClampedArray(3);
72
+ this.getRgbItem(src, srcOffset, rgb, 0);
73
+ return rgb;
74
+ }
75
+
76
+ getRgbItem(src, srcOffset, dest, destOffset) {
77
+ (0, _util.unreachable)("Should not call ColorSpace.getRgbItem");
78
+ }
79
+
80
+ getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
81
+ (0, _util.unreachable)("Should not call ColorSpace.getRgbBuffer");
82
+ }
83
+
84
+ getOutputLength(inputLength, alpha01) {
85
+ (0, _util.unreachable)("Should not call ColorSpace.getOutputLength");
86
+ }
87
+
88
+ isPassthrough(bits) {
89
+ return false;
90
+ }
91
+
92
+ isDefaultDecode(decodeMap, bpc) {
93
+ return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
94
+ }
95
+
96
+ fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
97
+ const count = originalWidth * originalHeight;
98
+ let rgbBuf = null;
99
+ const numComponentColors = 1 << bpc;
100
+ const needsResizing = originalHeight !== height || originalWidth !== width;
101
+
102
+ if (this.isPassthrough(bpc)) {
103
+ rgbBuf = comps;
104
+ } else if (this.numComps === 1 && count > numComponentColors && this.name !== "DeviceGray" && this.name !== "DeviceRGB") {
105
+ const allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
106
+
107
+ for (let i = 0; i < numComponentColors; i++) {
108
+ allColors[i] = i;
109
+ }
110
+
111
+ const colorMap = new Uint8ClampedArray(numComponentColors * 3);
112
+ this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, 0);
113
+
114
+ if (!needsResizing) {
115
+ let destPos = 0;
116
+
117
+ for (let i = 0; i < count; ++i) {
118
+ const key = comps[i] * 3;
119
+ dest[destPos++] = colorMap[key];
120
+ dest[destPos++] = colorMap[key + 1];
121
+ dest[destPos++] = colorMap[key + 2];
122
+ destPos += alpha01;
137
123
  }
138
124
  } else {
139
- if (!needsResizing) {
140
- this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
141
- } else {
142
- rgbBuf = new Uint8ClampedArray(count * 3);
143
- this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, 0);
125
+ rgbBuf = new Uint8Array(count * 3);
126
+ let rgbPos = 0;
127
+
128
+ for (let i = 0; i < count; ++i) {
129
+ const key = comps[i] * 3;
130
+ rgbBuf[rgbPos++] = colorMap[key];
131
+ rgbBuf[rgbPos++] = colorMap[key + 1];
132
+ rgbBuf[rgbPos++] = colorMap[key + 2];
144
133
  }
145
134
  }
146
- if (rgbBuf) {
147
- if (needsResizing) {
148
- resizeRgbImage(rgbBuf, dest, originalWidth, originalHeight, width, height, alpha01);
149
- } else {
150
- var _destPos = 0,
151
- _rgbPos = 0;
152
- for (var _i4 = 0, ii = width * actualHeight; _i4 < ii; _i4++) {
153
- dest[_destPos++] = rgbBuf[_rgbPos++];
154
- dest[_destPos++] = rgbBuf[_rgbPos++];
155
- dest[_destPos++] = rgbBuf[_rgbPos++];
156
- _destPos += alpha01;
157
- }
158
- }
135
+ } else {
136
+ if (!needsResizing) {
137
+ this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
138
+ } else {
139
+ rgbBuf = new Uint8ClampedArray(count * 3);
140
+ this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, 0);
159
141
  }
160
142
  }
161
- }, {
162
- key: 'usesZeroToOneRange',
163
- get: function get() {
164
- return (0, _util.shadow)(this, 'usesZeroToOneRange', true);
143
+
144
+ if (rgbBuf) {
145
+ if (needsResizing) {
146
+ resizeRgbImage(rgbBuf, dest, originalWidth, originalHeight, width, height, alpha01);
147
+ } else {
148
+ let destPos = 0,
149
+ rgbPos = 0;
150
+
151
+ for (let i = 0, ii = width * actualHeight; i < ii; i++) {
152
+ dest[destPos++] = rgbBuf[rgbPos++];
153
+ dest[destPos++] = rgbBuf[rgbPos++];
154
+ dest[destPos++] = rgbBuf[rgbPos++];
155
+ destPos += alpha01;
156
+ }
157
+ }
165
158
  }
166
- }], [{
167
- key: 'parse',
168
- value: function parse(cs, xref, res, pdfFunctionFactory) {
169
- var IR = this.parseToIR(cs, xref, res, pdfFunctionFactory);
170
- return this.fromIR(IR);
159
+ }
160
+
161
+ get usesZeroToOneRange() {
162
+ return (0, _util.shadow)(this, "usesZeroToOneRange", true);
163
+ }
164
+
165
+ static parse(cs, xref, res, pdfFunctionFactory) {
166
+ const IR = this.parseToIR(cs, xref, res, pdfFunctionFactory);
167
+ return this.fromIR(IR);
168
+ }
169
+
170
+ static fromIR(IR) {
171
+ const name = Array.isArray(IR) ? IR[0] : IR;
172
+ let whitePoint, blackPoint, gamma;
173
+
174
+ switch (name) {
175
+ case "DeviceGrayCS":
176
+ return this.singletons.gray;
177
+
178
+ case "DeviceRgbCS":
179
+ return this.singletons.rgb;
180
+
181
+ case "DeviceCmykCS":
182
+ return this.singletons.cmyk;
183
+
184
+ case "CalGrayCS":
185
+ whitePoint = IR[1];
186
+ blackPoint = IR[2];
187
+ gamma = IR[3];
188
+ return new CalGrayCS(whitePoint, blackPoint, gamma);
189
+
190
+ case "CalRGBCS":
191
+ whitePoint = IR[1];
192
+ blackPoint = IR[2];
193
+ gamma = IR[3];
194
+ const matrix = IR[4];
195
+ return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
196
+
197
+ case "PatternCS":
198
+ let basePatternCS = IR[1];
199
+
200
+ if (basePatternCS) {
201
+ basePatternCS = this.fromIR(basePatternCS);
202
+ }
203
+
204
+ return new PatternCS(basePatternCS);
205
+
206
+ case "IndexedCS":
207
+ const baseIndexedCS = IR[1];
208
+ const hiVal = IR[2];
209
+ const lookup = IR[3];
210
+ return new IndexedCS(this.fromIR(baseIndexedCS), hiVal, lookup);
211
+
212
+ case "AlternateCS":
213
+ const numComps = IR[1];
214
+ const alt = IR[2];
215
+ const tintFn = IR[3];
216
+ return new AlternateCS(numComps, this.fromIR(alt), tintFn);
217
+
218
+ case "LabCS":
219
+ whitePoint = IR[1];
220
+ blackPoint = IR[2];
221
+ const range = IR[3];
222
+ return new LabCS(whitePoint, blackPoint, range);
223
+
224
+ default:
225
+ throw new _util.FormatError(`Unknown colorspace name: ${name}`);
171
226
  }
172
- }, {
173
- key: 'fromIR',
174
- value: function fromIR(IR) {
175
- var name = Array.isArray(IR) ? IR[0] : IR;
176
- var whitePoint = void 0,
177
- blackPoint = void 0,
178
- gamma = void 0;
179
- switch (name) {
180
- case 'DeviceGrayCS':
181
- return this.singletons.gray;
182
- case 'DeviceRgbCS':
183
- return this.singletons.rgb;
184
- case 'DeviceCmykCS':
185
- return this.singletons.cmyk;
186
- case 'CalGrayCS':
187
- whitePoint = IR[1];
188
- blackPoint = IR[2];
189
- gamma = IR[3];
190
- return new CalGrayCS(whitePoint, blackPoint, gamma);
191
- case 'CalRGBCS':
192
- whitePoint = IR[1];
193
- blackPoint = IR[2];
194
- gamma = IR[3];
195
- var matrix = IR[4];
196
- return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
197
- case 'PatternCS':
198
- var basePatternCS = IR[1];
199
- if (basePatternCS) {
200
- basePatternCS = this.fromIR(basePatternCS);
201
- }
202
- return new PatternCS(basePatternCS);
203
- case 'IndexedCS':
204
- var baseIndexedCS = IR[1];
205
- var hiVal = IR[2];
206
- var lookup = IR[3];
207
- return new IndexedCS(this.fromIR(baseIndexedCS), hiVal, lookup);
208
- case 'AlternateCS':
209
- var numComps = IR[1];
210
- var alt = IR[2];
211
- var tintFn = IR[3];
212
- return new AlternateCS(numComps, this.fromIR(alt), tintFn);
213
- case 'LabCS':
214
- whitePoint = IR[1];
215
- blackPoint = IR[2];
216
- var range = IR[3];
217
- return new LabCS(whitePoint, blackPoint, range);
227
+ }
228
+
229
+ static parseToIR(cs, xref, res = null, pdfFunctionFactory) {
230
+ cs = xref.fetchIfRef(cs);
231
+
232
+ if ((0, _primitives.isName)(cs)) {
233
+ switch (cs.name) {
234
+ case "DeviceGray":
235
+ case "G":
236
+ return "DeviceGrayCS";
237
+
238
+ case "DeviceRGB":
239
+ case "RGB":
240
+ return "DeviceRgbCS";
241
+
242
+ case "DeviceCMYK":
243
+ case "CMYK":
244
+ return "DeviceCmykCS";
245
+
246
+ case "Pattern":
247
+ return ["PatternCS", null];
248
+
218
249
  default:
219
- throw new _util.FormatError('Unknown colorspace name: ' + name);
220
- }
221
- }
222
- }, {
223
- key: 'parseToIR',
224
- value: function parseToIR(cs, xref) {
225
- var res = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
226
- var pdfFunctionFactory = arguments[3];
227
-
228
- cs = xref.fetchIfRef(cs);
229
- if ((0, _primitives.isName)(cs)) {
230
- switch (cs.name) {
231
- case 'DeviceGray':
232
- case 'G':
233
- return 'DeviceGrayCS';
234
- case 'DeviceRGB':
235
- case 'RGB':
236
- return 'DeviceRgbCS';
237
- case 'DeviceCMYK':
238
- case 'CMYK':
239
- return 'DeviceCmykCS';
240
- case 'Pattern':
241
- return ['PatternCS', null];
242
- default:
243
- if ((0, _primitives.isDict)(res)) {
244
- var colorSpaces = res.get('ColorSpace');
245
- if ((0, _primitives.isDict)(colorSpaces)) {
246
- var resCS = colorSpaces.get(cs.name);
247
- if (resCS) {
248
- if ((0, _primitives.isName)(resCS)) {
249
- return this.parseToIR(resCS, xref, res, pdfFunctionFactory);
250
- }
251
- cs = resCS;
252
- break;
250
+ if ((0, _primitives.isDict)(res)) {
251
+ const colorSpaces = res.get("ColorSpace");
252
+
253
+ if ((0, _primitives.isDict)(colorSpaces)) {
254
+ const resCS = colorSpaces.get(cs.name);
255
+
256
+ if (resCS) {
257
+ if ((0, _primitives.isName)(resCS)) {
258
+ return this.parseToIR(resCS, xref, res, pdfFunctionFactory);
253
259
  }
260
+
261
+ cs = resCS;
262
+ break;
254
263
  }
255
264
  }
256
- throw new _util.FormatError('unrecognized colorspace ' + cs.name);
257
- }
265
+ }
266
+
267
+ throw new _util.FormatError(`unrecognized colorspace ${cs.name}`);
258
268
  }
259
- if (Array.isArray(cs)) {
260
- var mode = xref.fetchIfRef(cs[0]).name;
261
- var numComps = void 0,
262
- params = void 0,
263
- alt = void 0,
264
- whitePoint = void 0,
265
- blackPoint = void 0,
266
- gamma = void 0;
267
- switch (mode) {
268
- case 'DeviceGray':
269
- case 'G':
270
- return 'DeviceGrayCS';
271
- case 'DeviceRGB':
272
- case 'RGB':
273
- return 'DeviceRgbCS';
274
- case 'DeviceCMYK':
275
- case 'CMYK':
276
- return 'DeviceCmykCS';
277
- case 'CalGray':
278
- params = xref.fetchIfRef(cs[1]);
279
- whitePoint = params.getArray('WhitePoint');
280
- blackPoint = params.getArray('BlackPoint');
281
- gamma = params.get('Gamma');
282
- return ['CalGrayCS', whitePoint, blackPoint, gamma];
283
- case 'CalRGB':
284
- params = xref.fetchIfRef(cs[1]);
285
- whitePoint = params.getArray('WhitePoint');
286
- blackPoint = params.getArray('BlackPoint');
287
- gamma = params.getArray('Gamma');
288
- var matrix = params.getArray('Matrix');
289
- return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
290
- case 'ICCBased':
291
- var stream = xref.fetchIfRef(cs[1]);
292
- var dict = stream.dict;
293
- numComps = dict.get('N');
294
- alt = dict.get('Alternate');
295
- if (alt) {
296
- var altIR = this.parseToIR(alt, xref, res, pdfFunctionFactory);
297
- var altCS = this.fromIR(altIR, pdfFunctionFactory);
298
- if (altCS.numComps === numComps) {
299
- return altIR;
300
- }
301
- (0, _util.warn)('ICCBased color space: Ignoring incorrect /Alternate entry.');
302
- }
303
- if (numComps === 1) {
304
- return 'DeviceGrayCS';
305
- } else if (numComps === 3) {
306
- return 'DeviceRgbCS';
307
- } else if (numComps === 4) {
308
- return 'DeviceCmykCS';
309
- }
310
- break;
311
- case 'Pattern':
312
- var basePatternCS = cs[1] || null;
313
- if (basePatternCS) {
314
- basePatternCS = this.parseToIR(basePatternCS, xref, res, pdfFunctionFactory);
315
- }
316
- return ['PatternCS', basePatternCS];
317
- case 'Indexed':
318
- case 'I':
319
- var baseIndexedCS = this.parseToIR(cs[1], xref, res, pdfFunctionFactory);
320
- var hiVal = xref.fetchIfRef(cs[2]) + 1;
321
- var lookup = xref.fetchIfRef(cs[3]);
322
- if ((0, _primitives.isStream)(lookup)) {
323
- lookup = lookup.getBytes();
269
+ }
270
+
271
+ if (Array.isArray(cs)) {
272
+ const mode = xref.fetchIfRef(cs[0]).name;
273
+ let numComps, params, alt, whitePoint, blackPoint, gamma;
274
+
275
+ switch (mode) {
276
+ case "DeviceGray":
277
+ case "G":
278
+ return "DeviceGrayCS";
279
+
280
+ case "DeviceRGB":
281
+ case "RGB":
282
+ return "DeviceRgbCS";
283
+
284
+ case "DeviceCMYK":
285
+ case "CMYK":
286
+ return "DeviceCmykCS";
287
+
288
+ case "CalGray":
289
+ params = xref.fetchIfRef(cs[1]);
290
+ whitePoint = params.getArray("WhitePoint");
291
+ blackPoint = params.getArray("BlackPoint");
292
+ gamma = params.get("Gamma");
293
+ return ["CalGrayCS", whitePoint, blackPoint, gamma];
294
+
295
+ case "CalRGB":
296
+ params = xref.fetchIfRef(cs[1]);
297
+ whitePoint = params.getArray("WhitePoint");
298
+ blackPoint = params.getArray("BlackPoint");
299
+ gamma = params.getArray("Gamma");
300
+ const matrix = params.getArray("Matrix");
301
+ return ["CalRGBCS", whitePoint, blackPoint, gamma, matrix];
302
+
303
+ case "ICCBased":
304
+ const stream = xref.fetchIfRef(cs[1]);
305
+ const dict = stream.dict;
306
+ numComps = dict.get("N");
307
+ alt = dict.get("Alternate");
308
+
309
+ if (alt) {
310
+ const altIR = this.parseToIR(alt, xref, res, pdfFunctionFactory);
311
+ const altCS = this.fromIR(altIR, pdfFunctionFactory);
312
+
313
+ if (altCS.numComps === numComps) {
314
+ return altIR;
324
315
  }
325
- return ['IndexedCS', baseIndexedCS, hiVal, lookup];
326
- case 'Separation':
327
- case 'DeviceN':
328
- var name = xref.fetchIfRef(cs[1]);
329
- numComps = Array.isArray(name) ? name.length : 1;
330
- alt = this.parseToIR(cs[2], xref, res, pdfFunctionFactory);
331
- var tintFn = pdfFunctionFactory.create(xref.fetchIfRef(cs[3]));
332
- return ['AlternateCS', numComps, alt, tintFn];
333
- case 'Lab':
334
- params = xref.fetchIfRef(cs[1]);
335
- whitePoint = params.getArray('WhitePoint');
336
- blackPoint = params.getArray('BlackPoint');
337
- var range = params.getArray('Range');
338
- return ['LabCS', whitePoint, blackPoint, range];
339
- default:
340
- throw new _util.FormatError('unimplemented color space object "' + mode + '"');
341
- }
316
+
317
+ (0, _util.warn)("ICCBased color space: Ignoring incorrect /Alternate entry.");
318
+ }
319
+
320
+ if (numComps === 1) {
321
+ return "DeviceGrayCS";
322
+ } else if (numComps === 3) {
323
+ return "DeviceRgbCS";
324
+ } else if (numComps === 4) {
325
+ return "DeviceCmykCS";
326
+ }
327
+
328
+ break;
329
+
330
+ case "Pattern":
331
+ let basePatternCS = cs[1] || null;
332
+
333
+ if (basePatternCS) {
334
+ basePatternCS = this.parseToIR(basePatternCS, xref, res, pdfFunctionFactory);
335
+ }
336
+
337
+ return ["PatternCS", basePatternCS];
338
+
339
+ case "Indexed":
340
+ case "I":
341
+ const baseIndexedCS = this.parseToIR(cs[1], xref, res, pdfFunctionFactory);
342
+ const hiVal = xref.fetchIfRef(cs[2]) + 1;
343
+ let lookup = xref.fetchIfRef(cs[3]);
344
+
345
+ if ((0, _primitives.isStream)(lookup)) {
346
+ lookup = lookup.getBytes();
347
+ }
348
+
349
+ return ["IndexedCS", baseIndexedCS, hiVal, lookup];
350
+
351
+ case "Separation":
352
+ case "DeviceN":
353
+ const name = xref.fetchIfRef(cs[1]);
354
+ numComps = Array.isArray(name) ? name.length : 1;
355
+ alt = this.parseToIR(cs[2], xref, res, pdfFunctionFactory);
356
+ const tintFn = pdfFunctionFactory.create(xref.fetchIfRef(cs[3]));
357
+ return ["AlternateCS", numComps, alt, tintFn];
358
+
359
+ case "Lab":
360
+ params = xref.fetchIfRef(cs[1]);
361
+ whitePoint = params.getArray("WhitePoint");
362
+ blackPoint = params.getArray("BlackPoint");
363
+ const range = params.getArray("Range");
364
+ return ["LabCS", whitePoint, blackPoint, range];
365
+
366
+ default:
367
+ throw new _util.FormatError(`unimplemented color space object "${mode}"`);
342
368
  }
343
- throw new _util.FormatError('unrecognized color space object: "' + cs + '"');
344
369
  }
345
- }, {
346
- key: 'isDefaultDecode',
347
- value: function isDefaultDecode(decode, n) {
348
- if (!Array.isArray(decode)) {
349
- return true;
350
- }
351
- if (n * 2 !== decode.length) {
352
- (0, _util.warn)('The decode map is not the correct length');
353
- return true;
354
- }
355
- for (var i = 0, ii = decode.length; i < ii; i += 2) {
356
- if (decode[i] !== 0 || decode[i + 1] !== 1) {
357
- return false;
358
- }
359
- }
370
+
371
+ throw new _util.FormatError(`unrecognized color space object: "${cs}"`);
372
+ }
373
+
374
+ static isDefaultDecode(decode, numComps) {
375
+ if (!Array.isArray(decode)) {
360
376
  return true;
361
377
  }
362
- }, {
363
- key: 'singletons',
364
- get: function get() {
365
- return (0, _util.shadow)(this, 'singletons', {
366
- get gray() {
367
- return (0, _util.shadow)(this, 'gray', new DeviceGrayCS());
368
- },
369
- get rgb() {
370
- return (0, _util.shadow)(this, 'rgb', new DeviceRgbCS());
371
- },
372
- get cmyk() {
373
- return (0, _util.shadow)(this, 'cmyk', new DeviceCmykCS());
374
- }
375
- });
378
+
379
+ if (numComps * 2 !== decode.length) {
380
+ (0, _util.warn)("The decode map is not the correct length");
381
+ return true;
376
382
  }
377
- }]);
378
383
 
379
- return ColorSpace;
380
- }();
384
+ for (let i = 0, ii = decode.length; i < ii; i += 2) {
385
+ if (decode[i] !== 0 || decode[i + 1] !== 1) {
386
+ return false;
387
+ }
388
+ }
389
+
390
+ return true;
391
+ }
381
392
 
382
- var AlternateCS = function (_ColorSpace) {
383
- _inherits(AlternateCS, _ColorSpace);
393
+ static get singletons() {
394
+ return (0, _util.shadow)(this, "singletons", {
395
+ get gray() {
396
+ return (0, _util.shadow)(this, "gray", new DeviceGrayCS());
397
+ },
384
398
 
385
- function AlternateCS(numComps, base, tintFn) {
386
- _classCallCheck(this, AlternateCS);
399
+ get rgb() {
400
+ return (0, _util.shadow)(this, "rgb", new DeviceRgbCS());
401
+ },
387
402
 
388
- var _this = _possibleConstructorReturn(this, (AlternateCS.__proto__ || Object.getPrototypeOf(AlternateCS)).call(this, 'Alternate', numComps));
403
+ get cmyk() {
404
+ return (0, _util.shadow)(this, "cmyk", new DeviceCmykCS());
405
+ }
389
406
 
390
- _this.base = base;
391
- _this.tintFn = tintFn;
392
- _this.tmpBuf = new Float32Array(base.numComps);
393
- return _this;
407
+ });
394
408
  }
395
409
 
396
- _createClass(AlternateCS, [{
397
- key: 'getRgbItem',
398
- value: function getRgbItem(src, srcOffset, dest, destOffset) {
399
- var tmpBuf = this.tmpBuf;
400
- this.tintFn(src, srcOffset, tmpBuf, 0);
401
- this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
402
- }
403
- }, {
404
- key: 'getRgbBuffer',
405
- value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
406
- var tintFn = this.tintFn;
407
- var base = this.base;
408
- var scale = 1 / ((1 << bits) - 1);
409
- var baseNumComps = base.numComps;
410
- var usesZeroToOneRange = base.usesZeroToOneRange;
411
- var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
412
- var pos = isPassthrough ? destOffset : 0;
413
- var baseBuf = isPassthrough ? dest : new Uint8ClampedArray(baseNumComps * count);
414
- var numComps = this.numComps;
415
- var scaled = new Float32Array(numComps);
416
- var tinted = new Float32Array(baseNumComps);
417
- var i = void 0,
418
- j = void 0;
419
- for (i = 0; i < count; i++) {
420
- for (j = 0; j < numComps; j++) {
421
- scaled[j] = src[srcOffset++] * scale;
422
- }
423
- tintFn(scaled, 0, tinted, 0);
424
- if (usesZeroToOneRange) {
425
- for (j = 0; j < baseNumComps; j++) {
426
- baseBuf[pos++] = tinted[j] * 255;
427
- }
428
- } else {
429
- base.getRgbItem(tinted, 0, baseBuf, pos);
430
- pos += baseNumComps;
431
- }
410
+ }
411
+
412
+ exports.ColorSpace = ColorSpace;
413
+
414
+ class AlternateCS extends ColorSpace {
415
+ constructor(numComps, base, tintFn) {
416
+ super("Alternate", numComps);
417
+ this.base = base;
418
+ this.tintFn = tintFn;
419
+ this.tmpBuf = new Float32Array(base.numComps);
420
+ }
421
+
422
+ getRgbItem(src, srcOffset, dest, destOffset) {
423
+ const tmpBuf = this.tmpBuf;
424
+ this.tintFn(src, srcOffset, tmpBuf, 0);
425
+ this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
426
+ }
427
+
428
+ getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
429
+ const tintFn = this.tintFn;
430
+ const base = this.base;
431
+ const scale = 1 / ((1 << bits) - 1);
432
+ const baseNumComps = base.numComps;
433
+ const usesZeroToOneRange = base.usesZeroToOneRange;
434
+ const isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
435
+ let pos = isPassthrough ? destOffset : 0;
436
+ const baseBuf = isPassthrough ? dest : new Uint8ClampedArray(baseNumComps * count);
437
+ const numComps = this.numComps;
438
+ const scaled = new Float32Array(numComps);
439
+ const tinted = new Float32Array(baseNumComps);
440
+ let i, j;
441
+
442
+ for (i = 0; i < count; i++) {
443
+ for (j = 0; j < numComps; j++) {
444
+ scaled[j] = src[srcOffset++] * scale;
432
445
  }
433
- if (!isPassthrough) {
434
- base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
446
+
447
+ tintFn(scaled, 0, tinted, 0);
448
+
449
+ if (usesZeroToOneRange) {
450
+ for (j = 0; j < baseNumComps; j++) {
451
+ baseBuf[pos++] = tinted[j] * 255;
452
+ }
453
+ } else {
454
+ base.getRgbItem(tinted, 0, baseBuf, pos);
455
+ pos += baseNumComps;
435
456
  }
436
457
  }
437
- }, {
438
- key: 'getOutputLength',
439
- value: function getOutputLength(inputLength, alpha01) {
440
- return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
441
- }
442
- }, {
443
- key: 'isDefaultDecode',
444
- value: function isDefaultDecode(decodeMap) {
445
- return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
446
- }
447
- }]);
448
-
449
- return AlternateCS;
450
- }(ColorSpace);
451
458
 
452
- var PatternCS = function (_ColorSpace2) {
453
- _inherits(PatternCS, _ColorSpace2);
459
+ if (!isPassthrough) {
460
+ base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
461
+ }
462
+ }
454
463
 
455
- function PatternCS(baseCS) {
456
- _classCallCheck(this, PatternCS);
464
+ getOutputLength(inputLength, alpha01) {
465
+ return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
466
+ }
457
467
 
458
- var _this2 = _possibleConstructorReturn(this, (PatternCS.__proto__ || Object.getPrototypeOf(PatternCS)).call(this, 'Pattern', null));
468
+ }
459
469
 
460
- _this2.base = baseCS;
461
- return _this2;
470
+ class PatternCS extends ColorSpace {
471
+ constructor(baseCS) {
472
+ super("Pattern", null);
473
+ this.base = baseCS;
462
474
  }
463
475
 
464
- return PatternCS;
465
- }(ColorSpace);
466
-
467
- var IndexedCS = function (_ColorSpace3) {
468
- _inherits(IndexedCS, _ColorSpace3);
476
+ isDefaultDecode(decodeMap, bpc) {
477
+ (0, _util.unreachable)("Should not call PatternCS.isDefaultDecode");
478
+ }
469
479
 
470
- function IndexedCS(base, highVal, lookup) {
471
- _classCallCheck(this, IndexedCS);
480
+ }
472
481
 
473
- var _this3 = _possibleConstructorReturn(this, (IndexedCS.__proto__ || Object.getPrototypeOf(IndexedCS)).call(this, 'Indexed', 1));
482
+ class IndexedCS extends ColorSpace {
483
+ constructor(base, highVal, lookup) {
484
+ super("Indexed", 1);
485
+ this.base = base;
486
+ this.highVal = highVal;
487
+ const baseNumComps = base.numComps;
488
+ const length = baseNumComps * highVal;
474
489
 
475
- _this3.base = base;
476
- _this3.highVal = highVal;
477
- var baseNumComps = base.numComps;
478
- var length = baseNumComps * highVal;
479
490
  if ((0, _primitives.isStream)(lookup)) {
480
- _this3.lookup = new Uint8Array(length);
481
- var bytes = lookup.getBytes(length);
482
- _this3.lookup.set(bytes);
491
+ this.lookup = new Uint8Array(length);
492
+ const bytes = lookup.getBytes(length);
493
+ this.lookup.set(bytes);
483
494
  } else if ((0, _util.isString)(lookup)) {
484
- _this3.lookup = new Uint8Array(length);
485
- for (var i = 0; i < length; ++i) {
486
- _this3.lookup[i] = lookup.charCodeAt(i);
495
+ this.lookup = new Uint8Array(length);
496
+
497
+ for (let i = 0; i < length; ++i) {
498
+ this.lookup[i] = lookup.charCodeAt(i);
487
499
  }
488
500
  } else if (lookup instanceof Uint8Array) {
489
- _this3.lookup = lookup;
501
+ this.lookup = lookup;
490
502
  } else {
491
- throw new _util.FormatError('Unrecognized lookup table: ' + lookup);
503
+ throw new _util.FormatError(`Unrecognized lookup table: ${lookup}`);
492
504
  }
493
- return _this3;
494
505
  }
495
506
 
496
- _createClass(IndexedCS, [{
497
- key: 'getRgbItem',
498
- value: function getRgbItem(src, srcOffset, dest, destOffset) {
499
- var numComps = this.base.numComps;
500
- var start = src[srcOffset] * numComps;
501
- this.base.getRgbBuffer(this.lookup, start, 1, dest, destOffset, 8, 0);
507
+ getRgbItem(src, srcOffset, dest, destOffset) {
508
+ const numComps = this.base.numComps;
509
+ const start = src[srcOffset] * numComps;
510
+ this.base.getRgbBuffer(this.lookup, start, 1, dest, destOffset, 8, 0);
511
+ }
512
+
513
+ getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
514
+ const base = this.base;
515
+ const numComps = base.numComps;
516
+ const outputDelta = base.getOutputLength(numComps, alpha01);
517
+ const lookup = this.lookup;
518
+
519
+ for (let i = 0; i < count; ++i) {
520
+ const lookupPos = src[srcOffset++] * numComps;
521
+ base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
522
+ destOffset += outputDelta;
502
523
  }
503
- }, {
504
- key: 'getRgbBuffer',
505
- value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
506
- var base = this.base;
507
- var numComps = base.numComps;
508
- var outputDelta = base.getOutputLength(numComps, alpha01);
509
- var lookup = this.lookup;
510
- for (var i = 0; i < count; ++i) {
511
- var lookupPos = src[srcOffset++] * numComps;
512
- base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
513
- destOffset += outputDelta;
514
- }
524
+ }
525
+
526
+ getOutputLength(inputLength, alpha01) {
527
+ return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
528
+ }
529
+
530
+ isDefaultDecode(decodeMap, bpc) {
531
+ if (!Array.isArray(decodeMap)) {
532
+ return true;
515
533
  }
516
- }, {
517
- key: 'getOutputLength',
518
- value: function getOutputLength(inputLength, alpha01) {
519
- return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
534
+
535
+ if (decodeMap.length !== 2) {
536
+ (0, _util.warn)("Decode map length is not correct");
537
+ return true;
520
538
  }
521
- }, {
522
- key: 'isDefaultDecode',
523
- value: function isDefaultDecode(decodeMap) {
539
+
540
+ if (!Number.isInteger(bpc) || bpc < 1) {
541
+ (0, _util.warn)("Bits per component is not correct");
524
542
  return true;
525
543
  }
526
- }]);
527
544
 
528
- return IndexedCS;
529
- }(ColorSpace);
545
+ return decodeMap[0] === 0 && decodeMap[1] === (1 << bpc) - 1;
546
+ }
530
547
 
531
- var DeviceGrayCS = function (_ColorSpace4) {
532
- _inherits(DeviceGrayCS, _ColorSpace4);
548
+ }
533
549
 
534
- function DeviceGrayCS() {
535
- _classCallCheck(this, DeviceGrayCS);
550
+ class DeviceGrayCS extends ColorSpace {
551
+ constructor() {
552
+ super("DeviceGray", 1);
553
+ }
536
554
 
537
- return _possibleConstructorReturn(this, (DeviceGrayCS.__proto__ || Object.getPrototypeOf(DeviceGrayCS)).call(this, 'DeviceGray', 1));
555
+ getRgbItem(src, srcOffset, dest, destOffset) {
556
+ const c = src[srcOffset] * 255;
557
+ dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
538
558
  }
539
559
 
540
- _createClass(DeviceGrayCS, [{
541
- key: 'getRgbItem',
542
- value: function getRgbItem(src, srcOffset, dest, destOffset) {
543
- var c = src[srcOffset] * 255;
544
- dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
545
- }
546
- }, {
547
- key: 'getRgbBuffer',
548
- value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
549
- var scale = 255 / ((1 << bits) - 1);
550
- var j = srcOffset,
551
- q = destOffset;
552
- for (var i = 0; i < count; ++i) {
553
- var c = scale * src[j++];
554
- dest[q++] = c;
555
- dest[q++] = c;
556
- dest[q++] = c;
557
- q += alpha01;
558
- }
559
- }
560
- }, {
561
- key: 'getOutputLength',
562
- value: function getOutputLength(inputLength, alpha01) {
563
- return inputLength * (3 + alpha01);
560
+ getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
561
+ const scale = 255 / ((1 << bits) - 1);
562
+ let j = srcOffset,
563
+ q = destOffset;
564
+
565
+ for (let i = 0; i < count; ++i) {
566
+ const c = scale * src[j++];
567
+ dest[q++] = c;
568
+ dest[q++] = c;
569
+ dest[q++] = c;
570
+ q += alpha01;
564
571
  }
565
- }, {
566
- key: 'isDefaultDecode',
567
- value: function isDefaultDecode(decodeMap) {
568
- return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
569
- }
570
- }]);
572
+ }
571
573
 
572
- return DeviceGrayCS;
573
- }(ColorSpace);
574
+ getOutputLength(inputLength, alpha01) {
575
+ return inputLength * (3 + alpha01);
576
+ }
574
577
 
575
- var DeviceRgbCS = function (_ColorSpace5) {
576
- _inherits(DeviceRgbCS, _ColorSpace5);
578
+ }
577
579
 
578
- function DeviceRgbCS() {
579
- _classCallCheck(this, DeviceRgbCS);
580
+ class DeviceRgbCS extends ColorSpace {
581
+ constructor() {
582
+ super("DeviceRGB", 3);
583
+ }
580
584
 
581
- return _possibleConstructorReturn(this, (DeviceRgbCS.__proto__ || Object.getPrototypeOf(DeviceRgbCS)).call(this, 'DeviceRGB', 3));
585
+ getRgbItem(src, srcOffset, dest, destOffset) {
586
+ dest[destOffset] = src[srcOffset] * 255;
587
+ dest[destOffset + 1] = src[srcOffset + 1] * 255;
588
+ dest[destOffset + 2] = src[srcOffset + 2] * 255;
582
589
  }
583
590
 
584
- _createClass(DeviceRgbCS, [{
585
- key: 'getRgbItem',
586
- value: function getRgbItem(src, srcOffset, dest, destOffset) {
587
- dest[destOffset] = src[srcOffset] * 255;
588
- dest[destOffset + 1] = src[srcOffset + 1] * 255;
589
- dest[destOffset + 2] = src[srcOffset + 2] * 255;
590
- }
591
- }, {
592
- key: 'getRgbBuffer',
593
- value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
594
- if (bits === 8 && alpha01 === 0) {
595
- dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
596
- return;
597
- }
598
- var scale = 255 / ((1 << bits) - 1);
599
- var j = srcOffset,
600
- q = destOffset;
601
- for (var i = 0; i < count; ++i) {
602
- dest[q++] = scale * src[j++];
603
- dest[q++] = scale * src[j++];
604
- dest[q++] = scale * src[j++];
605
- q += alpha01;
606
- }
607
- }
608
- }, {
609
- key: 'getOutputLength',
610
- value: function getOutputLength(inputLength, alpha01) {
611
- return inputLength * (3 + alpha01) / 3 | 0;
612
- }
613
- }, {
614
- key: 'isPassthrough',
615
- value: function isPassthrough(bits) {
616
- return bits === 8;
591
+ getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
592
+ if (bits === 8 && alpha01 === 0) {
593
+ dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
594
+ return;
617
595
  }
618
- }, {
619
- key: 'isDefaultDecode',
620
- value: function isDefaultDecode(decodeMap) {
621
- return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
596
+
597
+ const scale = 255 / ((1 << bits) - 1);
598
+ let j = srcOffset,
599
+ q = destOffset;
600
+
601
+ for (let i = 0; i < count; ++i) {
602
+ dest[q++] = scale * src[j++];
603
+ dest[q++] = scale * src[j++];
604
+ dest[q++] = scale * src[j++];
605
+ q += alpha01;
622
606
  }
623
- }]);
607
+ }
624
608
 
625
- return DeviceRgbCS;
626
- }(ColorSpace);
609
+ getOutputLength(inputLength, alpha01) {
610
+ return inputLength * (3 + alpha01) / 3 | 0;
611
+ }
612
+
613
+ isPassthrough(bits) {
614
+ return bits === 8;
615
+ }
616
+
617
+ }
627
618
 
628
- var DeviceCmykCS = function DeviceCmykCSClosure() {
619
+ const DeviceCmykCS = function DeviceCmykCSClosure() {
629
620
  function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
630
- var c = src[srcOffset] * srcScale;
631
- var m = src[srcOffset + 1] * srcScale;
632
- var y = src[srcOffset + 2] * srcScale;
633
- var k = src[srcOffset + 3] * srcScale;
621
+ const c = src[srcOffset] * srcScale;
622
+ const m = src[srcOffset + 1] * srcScale;
623
+ const y = src[srcOffset + 2] * srcScale;
624
+ const k = src[srcOffset + 3] * srcScale;
634
625
  dest[destOffset] = 255 + c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k + -285.2331026137004) + m * (1.7149763477362134 * m - 5.6096736904047315 * y + -17.873870861415444 * k - 5.497006427196366) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) + k * (-21.86122147463605 * k - 189.48180835922747);
635
626
  dest[destOffset + 1] = 255 + c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k + -79.2970844816548) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) + y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + k * (-20.737325471181034 * k - 187.80453709719578);
636
627
  dest[destOffset + 2] = 255 + c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k + -14.183576799673286) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) + y * (0.03296041114873217 * y + 115.60384449646641 * k + -193.58209356861505) + k * (-22.33816807309886 * k - 180.12613974708367);
637
628
  }
638
629
 
639
- var DeviceCmykCS = function (_ColorSpace6) {
640
- _inherits(DeviceCmykCS, _ColorSpace6);
641
-
642
- function DeviceCmykCS() {
643
- _classCallCheck(this, DeviceCmykCS);
630
+ class DeviceCmykCS extends ColorSpace {
631
+ constructor() {
632
+ super("DeviceCMYK", 4);
633
+ }
644
634
 
645
- return _possibleConstructorReturn(this, (DeviceCmykCS.__proto__ || Object.getPrototypeOf(DeviceCmykCS)).call(this, 'DeviceCMYK', 4));
635
+ getRgbItem(src, srcOffset, dest, destOffset) {
636
+ convertToRgb(src, srcOffset, 1, dest, destOffset);
646
637
  }
647
638
 
648
- _createClass(DeviceCmykCS, [{
649
- key: 'getRgbItem',
650
- value: function getRgbItem(src, srcOffset, dest, destOffset) {
651
- convertToRgb(src, srcOffset, 1, dest, destOffset);
652
- }
653
- }, {
654
- key: 'getRgbBuffer',
655
- value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
656
- var scale = 1 / ((1 << bits) - 1);
657
- for (var i = 0; i < count; i++) {
658
- convertToRgb(src, srcOffset, scale, dest, destOffset);
659
- srcOffset += 4;
660
- destOffset += 3 + alpha01;
661
- }
662
- }
663
- }, {
664
- key: 'getOutputLength',
665
- value: function getOutputLength(inputLength, alpha01) {
666
- return inputLength / 4 * (3 + alpha01) | 0;
667
- }
668
- }, {
669
- key: 'isDefaultDecode',
670
- value: function isDefaultDecode(decodeMap) {
671
- return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
639
+ getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
640
+ const scale = 1 / ((1 << bits) - 1);
641
+
642
+ for (let i = 0; i < count; i++) {
643
+ convertToRgb(src, srcOffset, scale, dest, destOffset);
644
+ srcOffset += 4;
645
+ destOffset += 3 + alpha01;
672
646
  }
673
- }]);
647
+ }
674
648
 
675
- return DeviceCmykCS;
676
- }(ColorSpace);
649
+ getOutputLength(inputLength, alpha01) {
650
+ return inputLength / 4 * (3 + alpha01) | 0;
651
+ }
652
+
653
+ }
677
654
 
678
655
  return DeviceCmykCS;
679
656
  }();
680
- var CalGrayCS = function CalGrayCSClosure() {
657
+
658
+ const CalGrayCS = function CalGrayCSClosure() {
681
659
  function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
682
- var A = src[srcOffset] * scale;
683
- var AG = Math.pow(A, cs.G);
684
- var L = cs.YW * AG;
685
- var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0);
660
+ const A = src[srcOffset] * scale;
661
+ const AG = A ** cs.G;
662
+ const L = cs.YW * AG;
663
+ const val = Math.max(295.8 * L ** 0.333333333333333333 - 40.8, 0);
686
664
  dest[destOffset] = val;
687
665
  dest[destOffset + 1] = val;
688
666
  dest[destOffset + 2] = val;
689
667
  }
690
668
 
691
- var CalGrayCS = function (_ColorSpace7) {
692
- _inherits(CalGrayCS, _ColorSpace7);
693
-
694
- function CalGrayCS(whitePoint, blackPoint, gamma) {
695
- _classCallCheck(this, CalGrayCS);
696
-
697
- var _this7 = _possibleConstructorReturn(this, (CalGrayCS.__proto__ || Object.getPrototypeOf(CalGrayCS)).call(this, 'CalGray', 1));
669
+ class CalGrayCS extends ColorSpace {
670
+ constructor(whitePoint, blackPoint, gamma) {
671
+ super("CalGray", 1);
698
672
 
699
673
  if (!whitePoint) {
700
- throw new _util.FormatError('WhitePoint missing - required for color space CalGray');
674
+ throw new _util.FormatError("WhitePoint missing - required for color space CalGray");
701
675
  }
676
+
702
677
  blackPoint = blackPoint || [0, 0, 0];
703
678
  gamma = gamma || 1;
704
- _this7.XW = whitePoint[0];
705
- _this7.YW = whitePoint[1];
706
- _this7.ZW = whitePoint[2];
707
- _this7.XB = blackPoint[0];
708
- _this7.YB = blackPoint[1];
709
- _this7.ZB = blackPoint[2];
710
- _this7.G = gamma;
711
- if (_this7.XW < 0 || _this7.ZW < 0 || _this7.YW !== 1) {
712
- throw new _util.FormatError('Invalid WhitePoint components for ' + _this7.name + ', no fallback available');
679
+ this.XW = whitePoint[0];
680
+ this.YW = whitePoint[1];
681
+ this.ZW = whitePoint[2];
682
+ this.XB = blackPoint[0];
683
+ this.YB = blackPoint[1];
684
+ this.ZB = blackPoint[2];
685
+ this.G = gamma;
686
+
687
+ if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
688
+ throw new _util.FormatError(`Invalid WhitePoint components for ${this.name}` + ", no fallback available");
713
689
  }
714
- if (_this7.XB < 0 || _this7.YB < 0 || _this7.ZB < 0) {
715
- (0, _util.info)('Invalid BlackPoint for ' + _this7.name + ', falling back to default.');
716
- _this7.XB = _this7.YB = _this7.ZB = 0;
690
+
691
+ if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
692
+ (0, _util.info)(`Invalid BlackPoint for ${this.name}, falling back to default.`);
693
+ this.XB = this.YB = this.ZB = 0;
717
694
  }
718
- if (_this7.XB !== 0 || _this7.YB !== 0 || _this7.ZB !== 0) {
719
- (0, _util.warn)(_this7.name + ', BlackPoint: XB: ' + _this7.XB + ', YB: ' + _this7.YB + ', ' + ('ZB: ' + _this7.ZB + ', only default values are supported.'));
695
+
696
+ if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
697
+ (0, _util.warn)(`${this.name}, BlackPoint: XB: ${this.XB}, YB: ${this.YB}, ` + `ZB: ${this.ZB}, only default values are supported.`);
720
698
  }
721
- if (_this7.G < 1) {
722
- (0, _util.info)('Invalid Gamma: ' + _this7.G + ' for ' + _this7.name + ', ' + 'falling back to default.');
723
- _this7.G = 1;
699
+
700
+ if (this.G < 1) {
701
+ (0, _util.info)(`Invalid Gamma: ${this.G} for ${this.name}, ` + "falling back to default.");
702
+ this.G = 1;
724
703
  }
725
- return _this7;
726
704
  }
727
705
 
728
- _createClass(CalGrayCS, [{
729
- key: 'getRgbItem',
730
- value: function getRgbItem(src, srcOffset, dest, destOffset) {
731
- convertToRgb(this, src, srcOffset, dest, destOffset, 1);
732
- }
733
- }, {
734
- key: 'getRgbBuffer',
735
- value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
736
- var scale = 1 / ((1 << bits) - 1);
737
- for (var i = 0; i < count; ++i) {
738
- convertToRgb(this, src, srcOffset, dest, destOffset, scale);
739
- srcOffset += 1;
740
- destOffset += 3 + alpha01;
741
- }
742
- }
743
- }, {
744
- key: 'getOutputLength',
745
- value: function getOutputLength(inputLength, alpha01) {
746
- return inputLength * (3 + alpha01);
747
- }
748
- }, {
749
- key: 'isDefaultDecode',
750
- value: function isDefaultDecode(decodeMap) {
751
- return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
706
+ getRgbItem(src, srcOffset, dest, destOffset) {
707
+ convertToRgb(this, src, srcOffset, dest, destOffset, 1);
708
+ }
709
+
710
+ getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
711
+ const scale = 1 / ((1 << bits) - 1);
712
+
713
+ for (let i = 0; i < count; ++i) {
714
+ convertToRgb(this, src, srcOffset, dest, destOffset, scale);
715
+ srcOffset += 1;
716
+ destOffset += 3 + alpha01;
752
717
  }
753
- }]);
718
+ }
754
719
 
755
- return CalGrayCS;
756
- }(ColorSpace);
720
+ getOutputLength(inputLength, alpha01) {
721
+ return inputLength * (3 + alpha01);
722
+ }
723
+
724
+ }
757
725
 
758
726
  return CalGrayCS;
759
727
  }();
760
- var CalRGBCS = function CalRGBCSClosure() {
761
- var BRADFORD_SCALE_MATRIX = new Float32Array([0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296]);
762
- var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([0.9869929, -0.1470543, 0.1599627, 0.4323053, 0.5183603, 0.0492912, -0.0085287, 0.0400428, 0.9684867]);
763
- var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([3.2404542, -1.5371385, -0.4985314, -0.9692660, 1.8760108, 0.0415560, 0.0556434, -0.2040259, 1.0572252]);
764
- var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
765
- var tempNormalizeMatrix = new Float32Array(3);
766
- var tempConvertMatrix1 = new Float32Array(3);
767
- var tempConvertMatrix2 = new Float32Array(3);
768
- var DECODE_L_CONSTANT = Math.pow((8 + 16) / 116, 3) / 8.0;
728
+
729
+ const CalRGBCS = function CalRGBCSClosure() {
730
+ const BRADFORD_SCALE_MATRIX = new Float32Array([0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296]);
731
+ const BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([0.9869929, -0.1470543, 0.1599627, 0.4323053, 0.5183603, 0.0492912, -0.0085287, 0.0400428, 0.9684867]);
732
+ const SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([3.2404542, -1.5371385, -0.4985314, -0.9692660, 1.8760108, 0.0415560, 0.0556434, -0.2040259, 1.0572252]);
733
+ const FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
734
+ const tempNormalizeMatrix = new Float32Array(3);
735
+ const tempConvertMatrix1 = new Float32Array(3);
736
+ const tempConvertMatrix2 = new Float32Array(3);
737
+ const DECODE_L_CONSTANT = ((8 + 16) / 116) ** 3 / 8.0;
738
+
769
739
  function matrixProduct(a, b, result) {
770
740
  result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
771
741
  result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
772
742
  result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
773
743
  }
744
+
774
745
  function convertToFlat(sourceWhitePoint, LMS, result) {
775
746
  result[0] = LMS[0] * 1 / sourceWhitePoint[0];
776
747
  result[1] = LMS[1] * 1 / sourceWhitePoint[1];
777
748
  result[2] = LMS[2] * 1 / sourceWhitePoint[2];
778
749
  }
750
+
779
751
  function convertToD65(sourceWhitePoint, LMS, result) {
780
- var D65X = 0.95047;
781
- var D65Y = 1;
782
- var D65Z = 1.08883;
752
+ const D65X = 0.95047;
753
+ const D65Y = 1;
754
+ const D65Z = 1.08883;
783
755
  result[0] = LMS[0] * D65X / sourceWhitePoint[0];
784
756
  result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
785
757
  result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
786
758
  }
759
+
787
760
  function sRGBTransferFunction(color) {
788
761
  if (color <= 0.0031308) {
789
762
  return adjustToRange(0, 1, 12.92 * color);
790
763
  }
791
- return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
764
+
765
+ return adjustToRange(0, 1, (1 + 0.055) * color ** (1 / 2.4) - 0.055);
792
766
  }
767
+
793
768
  function adjustToRange(min, max, value) {
794
769
  return Math.max(min, Math.min(max, value));
795
770
  }
771
+
796
772
  function decodeL(L) {
797
773
  if (L < 0) {
798
774
  return -decodeL(-L);
799
775
  }
776
+
800
777
  if (L > 8.0) {
801
- return Math.pow((L + 16) / 116, 3);
778
+ return ((L + 16) / 116) ** 3;
802
779
  }
780
+
803
781
  return L * DECODE_L_CONSTANT;
804
782
  }
783
+
805
784
  function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
806
785
  if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
807
786
  result[0] = XYZ_Flat[0];
@@ -809,23 +788,25 @@ var CalRGBCS = function CalRGBCSClosure() {
809
788
  result[2] = XYZ_Flat[2];
810
789
  return;
811
790
  }
812
- var zeroDecodeL = decodeL(0);
813
- var X_DST = zeroDecodeL;
814
- var X_SRC = decodeL(sourceBlackPoint[0]);
815
- var Y_DST = zeroDecodeL;
816
- var Y_SRC = decodeL(sourceBlackPoint[1]);
817
- var Z_DST = zeroDecodeL;
818
- var Z_SRC = decodeL(sourceBlackPoint[2]);
819
- var X_Scale = (1 - X_DST) / (1 - X_SRC);
820
- var X_Offset = 1 - X_Scale;
821
- var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
822
- var Y_Offset = 1 - Y_Scale;
823
- var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
824
- var Z_Offset = 1 - Z_Scale;
791
+
792
+ const zeroDecodeL = decodeL(0);
793
+ const X_DST = zeroDecodeL;
794
+ const X_SRC = decodeL(sourceBlackPoint[0]);
795
+ const Y_DST = zeroDecodeL;
796
+ const Y_SRC = decodeL(sourceBlackPoint[1]);
797
+ const Z_DST = zeroDecodeL;
798
+ const Z_SRC = decodeL(sourceBlackPoint[2]);
799
+ const X_Scale = (1 - X_DST) / (1 - X_SRC);
800
+ const X_Offset = 1 - X_Scale;
801
+ const Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
802
+ const Y_Offset = 1 - Y_Scale;
803
+ const Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
804
+ const Z_Offset = 1 - Z_Scale;
825
805
  result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
826
806
  result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
827
807
  result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
828
808
  }
809
+
829
810
  function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
830
811
  if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
831
812
  result[0] = XYZ_In[0];
@@ -833,248 +814,248 @@ var CalRGBCS = function CalRGBCSClosure() {
833
814
  result[2] = XYZ_In[2];
834
815
  return;
835
816
  }
836
- var LMS = result;
817
+
818
+ const LMS = result;
837
819
  matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
838
- var LMS_Flat = tempNormalizeMatrix;
820
+ const LMS_Flat = tempNormalizeMatrix;
839
821
  convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
840
822
  matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
841
823
  }
824
+
842
825
  function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
843
- var LMS = result;
826
+ const LMS = result;
844
827
  matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
845
- var LMS_D65 = tempNormalizeMatrix;
828
+ const LMS_D65 = tempNormalizeMatrix;
846
829
  convertToD65(sourceWhitePoint, LMS, LMS_D65);
847
830
  matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
848
831
  }
832
+
849
833
  function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
850
- var A = adjustToRange(0, 1, src[srcOffset] * scale);
851
- var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
852
- var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
853
- var AGR = Math.pow(A, cs.GR);
854
- var BGG = Math.pow(B, cs.GG);
855
- var CGB = Math.pow(C, cs.GB);
856
- var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
857
- var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
858
- var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
859
- var XYZ = tempConvertMatrix1;
834
+ const A = adjustToRange(0, 1, src[srcOffset] * scale);
835
+ const B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
836
+ const C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
837
+ const AGR = A ** cs.GR;
838
+ const BGG = B ** cs.GG;
839
+ const CGB = C ** cs.GB;
840
+ const X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
841
+ const Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
842
+ const Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
843
+ const XYZ = tempConvertMatrix1;
860
844
  XYZ[0] = X;
861
845
  XYZ[1] = Y;
862
846
  XYZ[2] = Z;
863
- var XYZ_Flat = tempConvertMatrix2;
847
+ const XYZ_Flat = tempConvertMatrix2;
864
848
  normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
865
- var XYZ_Black = tempConvertMatrix1;
849
+ const XYZ_Black = tempConvertMatrix1;
866
850
  compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
867
- var XYZ_D65 = tempConvertMatrix2;
851
+ const XYZ_D65 = tempConvertMatrix2;
868
852
  normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
869
- var SRGB = tempConvertMatrix1;
853
+ const SRGB = tempConvertMatrix1;
870
854
  matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
871
855
  dest[destOffset] = sRGBTransferFunction(SRGB[0]) * 255;
872
856
  dest[destOffset + 1] = sRGBTransferFunction(SRGB[1]) * 255;
873
857
  dest[destOffset + 2] = sRGBTransferFunction(SRGB[2]) * 255;
874
858
  }
875
859
 
876
- var CalRGBCS = function (_ColorSpace8) {
877
- _inherits(CalRGBCS, _ColorSpace8);
878
-
879
- function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
880
- _classCallCheck(this, CalRGBCS);
881
-
882
- var _this8 = _possibleConstructorReturn(this, (CalRGBCS.__proto__ || Object.getPrototypeOf(CalRGBCS)).call(this, 'CalRGB', 3));
860
+ class CalRGBCS extends ColorSpace {
861
+ constructor(whitePoint, blackPoint, gamma, matrix) {
862
+ super("CalRGB", 3);
883
863
 
884
864
  if (!whitePoint) {
885
- throw new _util.FormatError('WhitePoint missing - required for color space CalRGB');
865
+ throw new _util.FormatError("WhitePoint missing - required for color space CalRGB");
886
866
  }
867
+
887
868
  blackPoint = blackPoint || new Float32Array(3);
888
869
  gamma = gamma || new Float32Array([1, 1, 1]);
889
870
  matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
890
- var XW = whitePoint[0];
891
- var YW = whitePoint[1];
892
- var ZW = whitePoint[2];
893
- _this8.whitePoint = whitePoint;
894
- var XB = blackPoint[0];
895
- var YB = blackPoint[1];
896
- var ZB = blackPoint[2];
897
- _this8.blackPoint = blackPoint;
898
- _this8.GR = gamma[0];
899
- _this8.GG = gamma[1];
900
- _this8.GB = gamma[2];
901
- _this8.MXA = matrix[0];
902
- _this8.MYA = matrix[1];
903
- _this8.MZA = matrix[2];
904
- _this8.MXB = matrix[3];
905
- _this8.MYB = matrix[4];
906
- _this8.MZB = matrix[5];
907
- _this8.MXC = matrix[6];
908
- _this8.MYC = matrix[7];
909
- _this8.MZC = matrix[8];
871
+ const XW = whitePoint[0];
872
+ const YW = whitePoint[1];
873
+ const ZW = whitePoint[2];
874
+ this.whitePoint = whitePoint;
875
+ const XB = blackPoint[0];
876
+ const YB = blackPoint[1];
877
+ const ZB = blackPoint[2];
878
+ this.blackPoint = blackPoint;
879
+ this.GR = gamma[0];
880
+ this.GG = gamma[1];
881
+ this.GB = gamma[2];
882
+ this.MXA = matrix[0];
883
+ this.MYA = matrix[1];
884
+ this.MZA = matrix[2];
885
+ this.MXB = matrix[3];
886
+ this.MYB = matrix[4];
887
+ this.MZB = matrix[5];
888
+ this.MXC = matrix[6];
889
+ this.MYC = matrix[7];
890
+ this.MZC = matrix[8];
891
+
910
892
  if (XW < 0 || ZW < 0 || YW !== 1) {
911
- throw new _util.FormatError('Invalid WhitePoint components for ' + _this8.name + ', no fallback available');
893
+ throw new _util.FormatError(`Invalid WhitePoint components for ${this.name}` + ", no fallback available");
912
894
  }
895
+
913
896
  if (XB < 0 || YB < 0 || ZB < 0) {
914
- (0, _util.info)('Invalid BlackPoint for ' + _this8.name + ' [' + XB + ', ' + YB + ', ' + ZB + '], ' + 'falling back to default.');
915
- _this8.blackPoint = new Float32Array(3);
897
+ (0, _util.info)(`Invalid BlackPoint for ${this.name} [${XB}, ${YB}, ${ZB}], ` + "falling back to default.");
898
+ this.blackPoint = new Float32Array(3);
916
899
  }
917
- if (_this8.GR < 0 || _this8.GG < 0 || _this8.GB < 0) {
918
- (0, _util.info)('Invalid Gamma [' + _this8.GR + ', ' + _this8.GG + ', ' + _this8.GB + '] for ' + (_this8.name + ', falling back to default.'));
919
- _this8.GR = _this8.GG = _this8.GB = 1;
900
+
901
+ if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
902
+ (0, _util.info)(`Invalid Gamma [${this.GR}, ${this.GG}, ${this.GB}] for ` + `${this.name}, falling back to default.`);
903
+ this.GR = this.GG = this.GB = 1;
920
904
  }
921
- return _this8;
922
905
  }
923
906
 
924
- _createClass(CalRGBCS, [{
925
- key: 'getRgbItem',
926
- value: function getRgbItem(src, srcOffset, dest, destOffset) {
927
- convertToRgb(this, src, srcOffset, dest, destOffset, 1);
928
- }
929
- }, {
930
- key: 'getRgbBuffer',
931
- value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
932
- var scale = 1 / ((1 << bits) - 1);
933
- for (var i = 0; i < count; ++i) {
934
- convertToRgb(this, src, srcOffset, dest, destOffset, scale);
935
- srcOffset += 3;
936
- destOffset += 3 + alpha01;
937
- }
938
- }
939
- }, {
940
- key: 'getOutputLength',
941
- value: function getOutputLength(inputLength, alpha01) {
942
- return inputLength * (3 + alpha01) / 3 | 0;
943
- }
944
- }, {
945
- key: 'isDefaultDecode',
946
- value: function isDefaultDecode(decodeMap) {
947
- return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
907
+ getRgbItem(src, srcOffset, dest, destOffset) {
908
+ convertToRgb(this, src, srcOffset, dest, destOffset, 1);
909
+ }
910
+
911
+ getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
912
+ const scale = 1 / ((1 << bits) - 1);
913
+
914
+ for (let i = 0; i < count; ++i) {
915
+ convertToRgb(this, src, srcOffset, dest, destOffset, scale);
916
+ srcOffset += 3;
917
+ destOffset += 3 + alpha01;
948
918
  }
949
- }]);
919
+ }
950
920
 
951
- return CalRGBCS;
952
- }(ColorSpace);
921
+ getOutputLength(inputLength, alpha01) {
922
+ return inputLength * (3 + alpha01) / 3 | 0;
923
+ }
924
+
925
+ }
953
926
 
954
927
  return CalRGBCS;
955
928
  }();
956
- var LabCS = function LabCSClosure() {
929
+
930
+ const LabCS = function LabCSClosure() {
957
931
  function fn_g(x) {
958
- var result = void 0;
932
+ let result;
933
+
959
934
  if (x >= 6 / 29) {
960
935
  result = x * x * x;
961
936
  } else {
962
937
  result = 108 / 841 * (x - 4 / 29);
963
938
  }
939
+
964
940
  return result;
965
941
  }
942
+
966
943
  function decode(value, high1, low2, high2) {
967
944
  return low2 + value * (high2 - low2) / high1;
968
945
  }
946
+
969
947
  function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
970
- var Ls = src[srcOffset];
971
- var as = src[srcOffset + 1];
972
- var bs = src[srcOffset + 2];
948
+ let Ls = src[srcOffset];
949
+ let as = src[srcOffset + 1];
950
+ let bs = src[srcOffset + 2];
951
+
973
952
  if (maxVal !== false) {
974
953
  Ls = decode(Ls, maxVal, 0, 100);
975
954
  as = decode(as, maxVal, cs.amin, cs.amax);
976
955
  bs = decode(bs, maxVal, cs.bmin, cs.bmax);
977
956
  }
978
- as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
979
- bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
980
- var M = (Ls + 16) / 116;
981
- var L = M + as / 500;
982
- var N = M - bs / 200;
983
- var X = cs.XW * fn_g(L);
984
- var Y = cs.YW * fn_g(M);
985
- var Z = cs.ZW * fn_g(N);
986
- var r = void 0,
987
- g = void 0,
988
- b = void 0;
957
+
958
+ if (as > cs.amax) {
959
+ as = cs.amax;
960
+ } else if (as < cs.amin) {
961
+ as = cs.amin;
962
+ }
963
+
964
+ if (bs > cs.bmax) {
965
+ bs = cs.bmax;
966
+ } else if (bs < cs.bmin) {
967
+ bs = cs.bmin;
968
+ }
969
+
970
+ const M = (Ls + 16) / 116;
971
+ const L = M + as / 500;
972
+ const N = M - bs / 200;
973
+ const X = cs.XW * fn_g(L);
974
+ const Y = cs.YW * fn_g(M);
975
+ const Z = cs.ZW * fn_g(N);
976
+ let r, g, b;
977
+
989
978
  if (cs.ZW < 1) {
990
- r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
991
- g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
992
- b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
979
+ r = X * 3.1339 + Y * -1.617 + Z * -0.4906;
980
+ g = X * -0.9785 + Y * 1.916 + Z * 0.0333;
981
+ b = X * 0.072 + Y * -0.229 + Z * 1.4057;
993
982
  } else {
994
983
  r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
995
984
  g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
996
- b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
985
+ b = X * 0.0557 + Y * -0.204 + Z * 1.057;
997
986
  }
987
+
998
988
  dest[destOffset] = Math.sqrt(r) * 255;
999
989
  dest[destOffset + 1] = Math.sqrt(g) * 255;
1000
990
  dest[destOffset + 2] = Math.sqrt(b) * 255;
1001
991
  }
1002
992
 
1003
- var LabCS = function (_ColorSpace9) {
1004
- _inherits(LabCS, _ColorSpace9);
1005
-
1006
- function LabCS(whitePoint, blackPoint, range) {
1007
- _classCallCheck(this, LabCS);
1008
-
1009
- var _this9 = _possibleConstructorReturn(this, (LabCS.__proto__ || Object.getPrototypeOf(LabCS)).call(this, 'Lab', 3));
993
+ class LabCS extends ColorSpace {
994
+ constructor(whitePoint, blackPoint, range) {
995
+ super("Lab", 3);
1010
996
 
1011
997
  if (!whitePoint) {
1012
- throw new _util.FormatError('WhitePoint missing - required for color space Lab');
998
+ throw new _util.FormatError("WhitePoint missing - required for color space Lab");
1013
999
  }
1000
+
1014
1001
  blackPoint = blackPoint || [0, 0, 0];
1015
1002
  range = range || [-100, 100, -100, 100];
1016
- _this9.XW = whitePoint[0];
1017
- _this9.YW = whitePoint[1];
1018
- _this9.ZW = whitePoint[2];
1019
- _this9.amin = range[0];
1020
- _this9.amax = range[1];
1021
- _this9.bmin = range[2];
1022
- _this9.bmax = range[3];
1023
- _this9.XB = blackPoint[0];
1024
- _this9.YB = blackPoint[1];
1025
- _this9.ZB = blackPoint[2];
1026
- if (_this9.XW < 0 || _this9.ZW < 0 || _this9.YW !== 1) {
1027
- throw new _util.FormatError('Invalid WhitePoint components, no fallback available');
1003
+ this.XW = whitePoint[0];
1004
+ this.YW = whitePoint[1];
1005
+ this.ZW = whitePoint[2];
1006
+ this.amin = range[0];
1007
+ this.amax = range[1];
1008
+ this.bmin = range[2];
1009
+ this.bmax = range[3];
1010
+ this.XB = blackPoint[0];
1011
+ this.YB = blackPoint[1];
1012
+ this.ZB = blackPoint[2];
1013
+
1014
+ if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
1015
+ throw new _util.FormatError("Invalid WhitePoint components, no fallback available");
1028
1016
  }
1029
- if (_this9.XB < 0 || _this9.YB < 0 || _this9.ZB < 0) {
1030
- (0, _util.info)('Invalid BlackPoint, falling back to default');
1031
- _this9.XB = _this9.YB = _this9.ZB = 0;
1017
+
1018
+ if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
1019
+ (0, _util.info)("Invalid BlackPoint, falling back to default");
1020
+ this.XB = this.YB = this.ZB = 0;
1032
1021
  }
1033
- if (_this9.amin > _this9.amax || _this9.bmin > _this9.bmax) {
1034
- (0, _util.info)('Invalid Range, falling back to defaults');
1035
- _this9.amin = -100;
1036
- _this9.amax = 100;
1037
- _this9.bmin = -100;
1038
- _this9.bmax = 100;
1022
+
1023
+ if (this.amin > this.amax || this.bmin > this.bmax) {
1024
+ (0, _util.info)("Invalid Range, falling back to defaults");
1025
+ this.amin = -100;
1026
+ this.amax = 100;
1027
+ this.bmin = -100;
1028
+ this.bmax = 100;
1039
1029
  }
1040
- return _this9;
1041
1030
  }
1042
1031
 
1043
- _createClass(LabCS, [{
1044
- key: 'getRgbItem',
1045
- value: function getRgbItem(src, srcOffset, dest, destOffset) {
1046
- convertToRgb(this, src, srcOffset, false, dest, destOffset);
1047
- }
1048
- }, {
1049
- key: 'getRgbBuffer',
1050
- value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
1051
- var maxVal = (1 << bits) - 1;
1052
- for (var i = 0; i < count; i++) {
1053
- convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
1054
- srcOffset += 3;
1055
- destOffset += 3 + alpha01;
1056
- }
1057
- }
1058
- }, {
1059
- key: 'getOutputLength',
1060
- value: function getOutputLength(inputLength, alpha01) {
1061
- return inputLength * (3 + alpha01) / 3 | 0;
1062
- }
1063
- }, {
1064
- key: 'isDefaultDecode',
1065
- value: function isDefaultDecode(decodeMap) {
1066
- return true;
1067
- }
1068
- }, {
1069
- key: 'usesZeroToOneRange',
1070
- get: function get() {
1071
- return (0, _util.shadow)(this, 'usesZeroToOneRange', false);
1032
+ getRgbItem(src, srcOffset, dest, destOffset) {
1033
+ convertToRgb(this, src, srcOffset, false, dest, destOffset);
1034
+ }
1035
+
1036
+ getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
1037
+ const maxVal = (1 << bits) - 1;
1038
+
1039
+ for (let i = 0; i < count; i++) {
1040
+ convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
1041
+ srcOffset += 3;
1042
+ destOffset += 3 + alpha01;
1072
1043
  }
1073
- }]);
1044
+ }
1074
1045
 
1075
- return LabCS;
1076
- }(ColorSpace);
1046
+ getOutputLength(inputLength, alpha01) {
1047
+ return inputLength * (3 + alpha01) / 3 | 0;
1048
+ }
1049
+
1050
+ isDefaultDecode(decodeMap, bpc) {
1051
+ return true;
1052
+ }
1053
+
1054
+ get usesZeroToOneRange() {
1055
+ return (0, _util.shadow)(this, "usesZeroToOneRange", false);
1056
+ }
1057
+
1058
+ }
1077
1059
 
1078
1060
  return LabCS;
1079
- }();
1080
- exports.ColorSpace = ColorSpace;
1061
+ }();