@progress/kendo-pdfviewer-common 0.3.0-dev.202409251459 → 0.3.0-dev.202410100645

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 (149) hide show
  1. package/dist/es/annotations/annotation-editor-layer-builder.js +139 -0
  2. package/dist/es/annotations/annotation-editor-layer.js +780 -0
  3. package/dist/es/annotations/annotation-editor-ui-manager.js +1690 -0
  4. package/dist/es/annotations/annotation-layer-builder.js +217 -0
  5. package/dist/es/annotations/annotation-layer.js +2793 -0
  6. package/dist/es/annotations/draw-layer-builder.js +65 -0
  7. package/dist/es/annotations/draw-layer.js +220 -0
  8. package/dist/es/annotations/editors/annotation-editor.js +1519 -0
  9. package/dist/es/annotations/editors/free-text-editor.js +783 -0
  10. package/dist/es/annotations/editors/highlight-editor.js +717 -0
  11. package/dist/es/annotations/editors/outliner.js +747 -0
  12. package/dist/es/annotations/helpers/annotation-storage.js +294 -0
  13. package/dist/es/annotations/helpers/color-manager.js +72 -0
  14. package/dist/es/annotations/helpers/command-manager.js +133 -0
  15. package/dist/es/annotations/helpers/id-manager.js +34 -0
  16. package/dist/es/annotations/helpers/image-manager.js +176 -0
  17. package/dist/es/annotations/helpers/text-accessibility-manager.js +212 -0
  18. package/dist/es/annotations/helpers/tools.js +19 -0
  19. package/dist/es/annotations/shared/display_utils.js +1024 -0
  20. package/dist/es/annotations/shared/event_utils.js +213 -0
  21. package/dist/es/annotations/shared/murmurhash3.js +126 -0
  22. package/dist/es/annotations/shared/scripting_utils.js +90 -0
  23. package/dist/es/annotations/shared/ui_utils.js +823 -0
  24. package/dist/es/annotations/shared/utils.js +909 -0
  25. package/dist/es/common/component.js +33 -0
  26. package/dist/es/common/core.js +91 -0
  27. package/dist/es/common/dom.js +11 -0
  28. package/dist/es/common/main.js +4 -0
  29. package/dist/es/common/math.js +1 -0
  30. package/dist/es/enums/PdfViewerInteractionMode.js +6 -0
  31. package/dist/es/links/link-service.js +505 -0
  32. package/dist/es/main.js +2 -0
  33. package/dist/es/scroller.js +29 -30
  34. package/dist/es/text/text-layer-builder.js +288 -0
  35. package/dist/es/utils.js +5 -5
  36. package/dist/es/widget/page.js +762 -0
  37. package/dist/es/widget/pdfviewer.js +1659 -0
  38. package/dist/es2015/annotations/annotation-editor-layer-builder.js +139 -0
  39. package/dist/es2015/annotations/annotation-editor-layer.js +780 -0
  40. package/dist/es2015/annotations/annotation-editor-ui-manager.js +1690 -0
  41. package/dist/es2015/annotations/annotation-layer-builder.js +217 -0
  42. package/dist/es2015/annotations/annotation-layer.js +2793 -0
  43. package/dist/es2015/annotations/draw-layer-builder.js +65 -0
  44. package/dist/es2015/annotations/draw-layer.js +220 -0
  45. package/dist/es2015/annotations/editors/annotation-editor.js +1519 -0
  46. package/dist/es2015/annotations/editors/free-text-editor.js +783 -0
  47. package/dist/es2015/annotations/editors/highlight-editor.js +717 -0
  48. package/dist/es2015/annotations/editors/outliner.js +747 -0
  49. package/dist/es2015/annotations/helpers/annotation-storage.js +294 -0
  50. package/dist/es2015/annotations/helpers/color-manager.js +72 -0
  51. package/dist/es2015/annotations/helpers/command-manager.js +133 -0
  52. package/dist/es2015/annotations/helpers/id-manager.js +34 -0
  53. package/dist/es2015/annotations/helpers/image-manager.js +176 -0
  54. package/dist/es2015/annotations/helpers/text-accessibility-manager.js +212 -0
  55. package/dist/es2015/annotations/helpers/tools.js +19 -0
  56. package/dist/es2015/annotations/shared/display_utils.js +1024 -0
  57. package/dist/es2015/annotations/shared/event_utils.js +213 -0
  58. package/dist/es2015/annotations/shared/murmurhash3.js +126 -0
  59. package/dist/es2015/annotations/shared/scripting_utils.js +90 -0
  60. package/dist/es2015/annotations/shared/ui_utils.js +823 -0
  61. package/dist/es2015/annotations/shared/utils.js +909 -0
  62. package/dist/es2015/common/component.js +33 -0
  63. package/dist/es2015/common/core.js +91 -0
  64. package/dist/es2015/common/dom.js +11 -0
  65. package/dist/es2015/common/main.js +4 -0
  66. package/dist/es2015/common/math.js +1 -0
  67. package/dist/es2015/enums/PdfViewerInteractionMode.js +6 -0
  68. package/dist/es2015/links/link-service.js +505 -0
  69. package/dist/es2015/main.js +2 -0
  70. package/dist/es2015/scroller.js +29 -30
  71. package/dist/es2015/text/text-layer-builder.js +288 -0
  72. package/dist/es2015/utils.js +5 -5
  73. package/dist/es2015/widget/page.js +762 -0
  74. package/dist/es2015/widget/pdfviewer.js +1659 -0
  75. package/dist/npm/annotations/annotation-editor-layer-builder.d.ts +39 -0
  76. package/dist/npm/annotations/annotation-editor-layer-builder.js +142 -0
  77. package/dist/npm/annotations/annotation-editor-layer.d.ts +196 -0
  78. package/dist/npm/annotations/annotation-editor-layer.js +783 -0
  79. package/dist/npm/annotations/annotation-editor-ui-manager.d.ts +281 -0
  80. package/dist/npm/annotations/annotation-editor-ui-manager.js +1694 -0
  81. package/dist/npm/annotations/annotation-layer-builder.d.ts +58 -0
  82. package/dist/npm/annotations/annotation-layer-builder.js +220 -0
  83. package/dist/npm/annotations/annotation-layer.d.ts +134 -0
  84. package/dist/npm/annotations/annotation-layer.js +2794 -0
  85. package/dist/npm/annotations/draw-layer-builder.d.ts +21 -0
  86. package/dist/npm/annotations/draw-layer-builder.js +68 -0
  87. package/dist/npm/annotations/draw-layer.d.ts +33 -0
  88. package/dist/npm/annotations/draw-layer.js +223 -0
  89. package/dist/npm/annotations/editors/annotation-editor.d.ts +349 -0
  90. package/dist/npm/annotations/editors/annotation-editor.js +1523 -0
  91. package/dist/npm/annotations/editors/free-text-editor.d.ts +108 -0
  92. package/dist/npm/annotations/editors/free-text-editor.js +786 -0
  93. package/dist/npm/annotations/editors/highlight-editor.d.ts +114 -0
  94. package/dist/npm/annotations/editors/highlight-editor.js +717 -0
  95. package/dist/npm/annotations/editors/outliner.d.ts +51 -0
  96. package/dist/npm/annotations/editors/outliner.js +750 -0
  97. package/dist/npm/annotations/helpers/annotation-storage.d.ts +98 -0
  98. package/dist/npm/annotations/helpers/annotation-storage.js +299 -0
  99. package/dist/npm/annotations/helpers/color-manager.d.ts +6 -0
  100. package/dist/npm/annotations/helpers/color-manager.js +76 -0
  101. package/dist/npm/annotations/helpers/command-manager.d.ts +42 -0
  102. package/dist/npm/annotations/helpers/command-manager.js +137 -0
  103. package/dist/npm/annotations/helpers/id-manager.d.ts +6 -0
  104. package/dist/npm/annotations/helpers/id-manager.js +38 -0
  105. package/dist/npm/annotations/helpers/image-manager.d.ts +18 -0
  106. package/dist/npm/annotations/helpers/image-manager.js +180 -0
  107. package/dist/npm/annotations/helpers/text-accessibility-manager.d.ts +36 -0
  108. package/dist/npm/annotations/helpers/text-accessibility-manager.js +215 -0
  109. package/dist/npm/annotations/helpers/tools.d.ts +1 -0
  110. package/dist/npm/annotations/helpers/tools.js +23 -0
  111. package/dist/npm/annotations/shared/display_utils.d.ts +6 -0
  112. package/dist/npm/annotations/shared/display_utils.js +1030 -0
  113. package/dist/npm/annotations/shared/event_utils.d.ts +33 -0
  114. package/dist/npm/annotations/shared/event_utils.js +165 -0
  115. package/dist/npm/annotations/shared/murmurhash3.d.ts +8 -0
  116. package/dist/npm/annotations/shared/murmurhash3.js +129 -0
  117. package/dist/npm/annotations/shared/scripting_utils.d.ts +17 -0
  118. package/dist/npm/annotations/shared/scripting_utils.js +93 -0
  119. package/dist/npm/annotations/shared/ui_utils.d.ts +54 -0
  120. package/dist/npm/annotations/shared/ui_utils.js +250 -0
  121. package/dist/npm/annotations/shared/utils.d.ts +148 -0
  122. package/dist/npm/annotations/shared/utils.js +872 -0
  123. package/dist/npm/common/component.d.ts +9 -0
  124. package/dist/npm/common/component.js +37 -0
  125. package/dist/npm/common/core.d.ts +18 -0
  126. package/dist/npm/common/core.js +112 -0
  127. package/dist/npm/common/dom.d.ts +3 -0
  128. package/dist/npm/common/dom.js +17 -0
  129. package/dist/npm/common/main.d.ts +4 -0
  130. package/dist/npm/common/main.js +7 -0
  131. package/dist/npm/common/math.d.ts +1 -0
  132. package/dist/npm/common/math.js +5 -0
  133. package/dist/npm/enums/PdfViewerInteractionMode.d.ts +4 -0
  134. package/dist/npm/enums/PdfViewerInteractionMode.js +9 -0
  135. package/dist/npm/links/link-service.d.ts +116 -0
  136. package/dist/npm/links/link-service.js +501 -0
  137. package/dist/npm/main.d.ts +2 -0
  138. package/dist/npm/main.js +2 -0
  139. package/dist/npm/scroller.d.ts +7 -3
  140. package/dist/npm/scroller.js +32 -32
  141. package/dist/npm/text/text-layer-builder.d.ts +30 -0
  142. package/dist/npm/text/text-layer-builder.js +291 -0
  143. package/dist/npm/utils.d.ts +20 -2
  144. package/dist/npm/utils.js +11 -8
  145. package/dist/npm/widget/page.d.ts +75 -0
  146. package/dist/npm/widget/page.js +763 -0
  147. package/dist/npm/widget/pdfviewer.d.ts +222 -0
  148. package/dist/npm/widget/pdfviewer.js +1663 -0
  149. package/package.json +13 -9
@@ -0,0 +1,213 @@
1
+ /* Copyright 2012 Mozilla Foundation
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ // const WaitOnType = {
16
+ // EVENT: "event",
17
+ // TIMEOUT: "timeout",
18
+ // };
19
+ var _EventBus_listeners;
20
+ import { __classPrivateFieldGet } from "tslib";
21
+ // /**
22
+ // * @typedef {Object} WaitOnEventOrTimeoutParameters
23
+ // * @property {Object} target - The event target, can for example be:
24
+ // * `window`, `document`, a DOM element, or an {EventBus} instance.
25
+ // * @property {string} name - The name of the event.
26
+ // * @property {number} delay - The delay, in milliseconds, after which the
27
+ // * timeout occurs (if the event wasn't already dispatched).
28
+ // */
29
+ // /**
30
+ // * Allows waiting for an event or a timeout, whichever occurs first.
31
+ // * Can be used to ensure that an action always occurs, even when an event
32
+ // * arrives late or not at all.
33
+ // *
34
+ // * @param {WaitOnEventOrTimeoutParameters}
35
+ // * @returns {Promise} A promise that is resolved with a {WaitOnType} value.
36
+ // */
37
+ // async function waitOnEventOrTimeout({ target, name, delay = 0 }) {
38
+ // if (
39
+ // typeof target !== "object" ||
40
+ // !(name && typeof name === "string") ||
41
+ // !(Number.isInteger(delay) && delay >= 0)
42
+ // ) {
43
+ // throw new Error("waitOnEventOrTimeout - invalid parameters.");
44
+ // }
45
+ // const { promise, resolve } = Promise.withResolvers();
46
+ // const ac = new AbortController();
47
+ // function handler(type) {
48
+ // ac.abort(); // Remove event listener.
49
+ // clearTimeout(timeout);
50
+ // resolve(type);
51
+ // }
52
+ // const evtMethod = target instanceof EventBus ? "_on" : "addEventListener";
53
+ // target[evtMethod](name, handler.bind(null, WaitOnType.EVENT), {
54
+ // signal: ac.signal,
55
+ // });
56
+ // const timeout = setTimeout(handler.bind(null, WaitOnType.TIMEOUT), delay);
57
+ // return promise;
58
+ // }
59
+ /**
60
+ * Simple event bus for an application. Listeners are attached using the `on`
61
+ * and `off` methods. To raise an event, the `dispatch` method shall be used.
62
+ */
63
+ class EventBus {
64
+ constructor() {
65
+ _EventBus_listeners.set(this, Object.create(null));
66
+ }
67
+ /**
68
+ * @param {string} eventName
69
+ * @param {function} listener
70
+ * @param {Object} [options]
71
+ */
72
+ on(eventName, listener, options = null) {
73
+ this._on(eventName, listener, {
74
+ external: true,
75
+ once: options === null || options === void 0 ? void 0 : options.once,
76
+ signal: options === null || options === void 0 ? void 0 : options.signal,
77
+ });
78
+ }
79
+ /**
80
+ * @param {string} eventName
81
+ * @param {function} listener
82
+ * @param {Object} [options]
83
+ */
84
+ off(eventName, listener) {
85
+ this._off(eventName, listener);
86
+ }
87
+ /**
88
+ * @param {string} eventName
89
+ * @param {Object} data
90
+ */
91
+ dispatch(eventName, data) {
92
+ const eventListeners = __classPrivateFieldGet(this, _EventBus_listeners, "f")[eventName];
93
+ if (!eventListeners || eventListeners.length === 0) {
94
+ return;
95
+ }
96
+ let externalListeners;
97
+ // Making copy of the listeners array in case if it will be modified
98
+ // during dispatch.
99
+ for (const { listener, external, once } of eventListeners.slice(0)) {
100
+ if (once) {
101
+ this._off(eventName, listener);
102
+ }
103
+ if (external) {
104
+ (externalListeners || (externalListeners = [])).push(listener);
105
+ continue;
106
+ }
107
+ listener(data);
108
+ }
109
+ // Dispatch any "external" listeners *after* the internal ones, to give the
110
+ // viewer components time to handle events and update their state first.
111
+ if (externalListeners) {
112
+ for (const listener of externalListeners) {
113
+ listener(data);
114
+ }
115
+ externalListeners = null;
116
+ }
117
+ }
118
+ /**
119
+ * @ignore
120
+ */
121
+ _on(eventName, listener, options = null) {
122
+ var _a;
123
+ let rmAbort = null;
124
+ if ((options === null || options === void 0 ? void 0 : options.signal) instanceof AbortSignal) {
125
+ const { signal } = options;
126
+ if (signal.aborted) {
127
+ // console.error("Cannot use an `aborted` signal.");
128
+ return;
129
+ }
130
+ const onAbort = () => this._off(eventName, listener);
131
+ rmAbort = () => signal.removeEventListener("abort", onAbort);
132
+ signal.addEventListener("abort", onAbort);
133
+ }
134
+ const eventListeners = ((_a = __classPrivateFieldGet(this, _EventBus_listeners, "f"))[eventName] || (_a[eventName] = []));
135
+ eventListeners.push({
136
+ listener,
137
+ external: (options === null || options === void 0 ? void 0 : options.external) === true,
138
+ once: (options === null || options === void 0 ? void 0 : options.once) === true,
139
+ rmAbort,
140
+ });
141
+ }
142
+ /**
143
+ * @ignore
144
+ */
145
+ _off(eventName, listener) {
146
+ var _a;
147
+ const eventListeners = __classPrivateFieldGet(this, _EventBus_listeners, "f")[eventName];
148
+ if (!eventListeners) {
149
+ return;
150
+ }
151
+ for (let i = 0, ii = eventListeners.length; i < ii; i++) {
152
+ const evt = eventListeners[i];
153
+ if (evt.listener === listener) {
154
+ (_a = evt.rmAbort) === null || _a === void 0 ? void 0 : _a.call(evt); // Ensure that the `AbortSignal` listener is removed.
155
+ eventListeners.splice(i, 1);
156
+ return;
157
+ }
158
+ }
159
+ }
160
+ }
161
+ _EventBus_listeners = new WeakMap();
162
+ // /**
163
+ // * NOTE: Only used in the Firefox build-in pdf viewer.
164
+ // */
165
+ // class FirefoxEventBus extends EventBus {
166
+ // #externalServices;
167
+ // #globalEventNames;
168
+ // #isInAutomation;
169
+ // constructor(globalEventNames, externalServices, isInAutomation) {
170
+ // super();
171
+ // this.#globalEventNames = globalEventNames;
172
+ // this.#externalServices = externalServices;
173
+ // this.#isInAutomation = isInAutomation;
174
+ // }
175
+ // dispatch(eventName, data) {
176
+ // if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("MOZCENTRAL")) {
177
+ // throw new Error("Not implemented: FirefoxEventBus.dispatch");
178
+ // }
179
+ // super.dispatch(eventName, data);
180
+ // if (this.#isInAutomation) {
181
+ // const detail = Object.create(null);
182
+ // if (data) {
183
+ // for (const key in data) {
184
+ // const value = data[key];
185
+ // if (key === "source") {
186
+ // if (value === window || value === document) {
187
+ // return; // No need to re-dispatch (already) global events.
188
+ // }
189
+ // continue; // Ignore the `source` property.
190
+ // }
191
+ // detail[key] = value;
192
+ // }
193
+ // }
194
+ // const event = new CustomEvent(eventName, {
195
+ // bubbles: true,
196
+ // cancelable: true,
197
+ // detail,
198
+ // });
199
+ // document.dispatchEvent(event);
200
+ // }
201
+ // if (this.#globalEventNames?.has(eventName)) {
202
+ // this.#externalServices.dispatchGlobalEvent({
203
+ // eventName,
204
+ // detail: data,
205
+ // });
206
+ // }
207
+ // }
208
+ // }
209
+ export { EventBus,
210
+ // FirefoxEventBus,
211
+ // waitOnEventOrTimeout,
212
+ // WaitOnType
213
+ };
@@ -0,0 +1,126 @@
1
+ /* Copyright 2014 Opera Software ASA
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ *
15
+ *
16
+ * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
17
+ * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
18
+ */
19
+ const SEED = 0xc3d2e1f0;
20
+ // Workaround for missing math precision in JS.
21
+ const MASK_HIGH = 0xffff0000;
22
+ const MASK_LOW = 0xffff;
23
+ class MurmurHash3_64 {
24
+ // todo: props
25
+ constructor(seed) {
26
+ // todo: props
27
+ this.h1 = null;
28
+ this.h2 = null;
29
+ this.h1 = seed ? seed & 0xffffffff : SEED;
30
+ this.h2 = seed ? seed & 0xffffffff : SEED;
31
+ }
32
+ update(input) {
33
+ let data, length;
34
+ if (typeof input === "string") {
35
+ data = new Uint8Array(input.length * 2);
36
+ length = 0;
37
+ for (let i = 0, ii = input.length; i < ii; i++) {
38
+ const code = input.charCodeAt(i);
39
+ if (code <= 0xff) {
40
+ data[length++] = code;
41
+ }
42
+ else {
43
+ data[length++] = code >>> 8;
44
+ data[length++] = code & 0xff;
45
+ }
46
+ }
47
+ }
48
+ else if (ArrayBuffer.isView(input)) {
49
+ data = input.slice();
50
+ length = data.byteLength;
51
+ }
52
+ else {
53
+ throw new Error("Invalid data format, must be a string or TypedArray.");
54
+ }
55
+ const blockCounts = length >> 2;
56
+ const tailLength = length - blockCounts * 4;
57
+ // We don't care about endianness here.
58
+ const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
59
+ let k1 = 0, k2 = 0;
60
+ let h1 = this.h1, h2 = this.h2;
61
+ const C1 = 0xcc9e2d51, C2 = 0x1b873593;
62
+ const C1_LOW = C1 & MASK_LOW, C2_LOW = C2 & MASK_LOW;
63
+ for (let i = 0; i < blockCounts; i++) {
64
+ if (i & 1) {
65
+ k1 = dataUint32[i];
66
+ k1 = ((k1 * C1) & MASK_HIGH) | ((k1 * C1_LOW) & MASK_LOW);
67
+ k1 = (k1 << 15) | (k1 >>> 17);
68
+ k1 = ((k1 * C2) & MASK_HIGH) | ((k1 * C2_LOW) & MASK_LOW);
69
+ h1 ^= k1;
70
+ h1 = (h1 << 13) | (h1 >>> 19);
71
+ h1 = h1 * 5 + 0xe6546b64;
72
+ }
73
+ else {
74
+ k2 = dataUint32[i];
75
+ k2 = ((k2 * C1) & MASK_HIGH) | ((k2 * C1_LOW) & MASK_LOW);
76
+ k2 = (k2 << 15) | (k2 >>> 17);
77
+ k2 = ((k2 * C2) & MASK_HIGH) | ((k2 * C2_LOW) & MASK_LOW);
78
+ h2 ^= k2;
79
+ h2 = (h2 << 13) | (h2 >>> 19);
80
+ h2 = h2 * 5 + 0xe6546b64;
81
+ }
82
+ }
83
+ k1 = 0;
84
+ switch (tailLength) {
85
+ case 3:
86
+ k1 ^= data[blockCounts * 4 + 2] << 16;
87
+ /* falls through */
88
+ case 2:
89
+ k1 ^= data[blockCounts * 4 + 1] << 8;
90
+ /* falls through */
91
+ case 1:
92
+ k1 ^= data[blockCounts * 4];
93
+ /* falls through */
94
+ k1 = ((k1 * C1) & MASK_HIGH) | ((k1 * C1_LOW) & MASK_LOW);
95
+ k1 = (k1 << 15) | (k1 >>> 17);
96
+ k1 = ((k1 * C2) & MASK_HIGH) | ((k1 * C2_LOW) & MASK_LOW);
97
+ if (blockCounts & 1) {
98
+ h1 ^= k1;
99
+ }
100
+ else {
101
+ h2 ^= k1;
102
+ }
103
+ break;
104
+ default: break;
105
+ }
106
+ this.h1 = h1;
107
+ this.h2 = h2;
108
+ }
109
+ hexdigest() {
110
+ let h1 = this.h1, h2 = this.h2;
111
+ h1 ^= h2 >>> 1;
112
+ h1 = ((h1 * 0xed558ccd) & MASK_HIGH) | ((h1 * 0x8ccd) & MASK_LOW);
113
+ h2 =
114
+ ((h2 * 0xff51afd7) & MASK_HIGH) |
115
+ (((((h2 << 16) | (h1 >>> 16)) * 0xafd7ed55) & MASK_HIGH) >>> 16);
116
+ h1 ^= h2 >>> 1;
117
+ h1 = ((h1 * 0x1a85ec53) & MASK_HIGH) | ((h1 * 0xec53) & MASK_LOW);
118
+ h2 =
119
+ ((h2 * 0xc4ceb9fe) & MASK_HIGH) |
120
+ (((((h2 << 16) | (h1 >>> 16)) * 0xb9fe1a85) & MASK_HIGH) >>> 16);
121
+ h1 ^= h2 >>> 1;
122
+ return ((h1 >>> 0).toString(16).padStart(8, "0") +
123
+ (h2 >>> 0).toString(16).padStart(8, "0"));
124
+ }
125
+ }
126
+ export { MurmurHash3_64 };
@@ -0,0 +1,90 @@
1
+ /* Copyright 2020 Mozilla Foundation
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ /**
16
+ * PLEASE NOTE: This file is currently imported in both the `../display/` and
17
+ * `../scripting_api/` folders, hence be EXTREMELY careful about
18
+ * introducing any dependencies here since that can lead to an
19
+ * unexpected/unnecessary size increase of the *built* files.
20
+ */
21
+ function makeColorComp(n) {
22
+ return Math.floor(Math.max(0, Math.min(1, n)) * 255)
23
+ .toString(16)
24
+ .padStart(2, "0");
25
+ }
26
+ function scaleAndClamp(x) {
27
+ return Math.max(0, Math.min(255, 255 * x));
28
+ }
29
+ // PDF specifications section 10.3
30
+ class ColorConverters {
31
+ static CMYK_G([c, y, m, k]) {
32
+ return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
33
+ }
34
+ static G_CMYK([g]) {
35
+ return ["CMYK", 0, 0, 0, 1 - g];
36
+ }
37
+ static G_RGB([g]) {
38
+ return ["RGB", g, g, g];
39
+ }
40
+ static G_rgb([g]) {
41
+ g = scaleAndClamp(g);
42
+ return [g, g, g];
43
+ }
44
+ static G_HTML([g]) {
45
+ const G = makeColorComp(g);
46
+ return `#${G}${G}${G}`;
47
+ }
48
+ static RGB_G([r, g, b]) {
49
+ return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
50
+ }
51
+ static RGB_rgb(color) {
52
+ return color.map(scaleAndClamp);
53
+ }
54
+ static RGB_HTML(color) {
55
+ return `#${color.map(makeColorComp).join("")}`;
56
+ }
57
+ static T_HTML() {
58
+ return "#00000000";
59
+ }
60
+ static T_rgb() {
61
+ return [null];
62
+ }
63
+ static CMYK_RGB([c, y, m, k]) {
64
+ return [
65
+ "RGB",
66
+ 1 - Math.min(1, c + k),
67
+ 1 - Math.min(1, m + k),
68
+ 1 - Math.min(1, y + k),
69
+ ];
70
+ }
71
+ static CMYK_rgb([c, y, m, k]) {
72
+ return [
73
+ scaleAndClamp(1 - Math.min(1, c + k)),
74
+ scaleAndClamp(1 - Math.min(1, m + k)),
75
+ scaleAndClamp(1 - Math.min(1, y + k)),
76
+ ];
77
+ }
78
+ static CMYK_HTML(components) {
79
+ const rgb = this.CMYK_RGB(components).slice(1);
80
+ return this.RGB_HTML(rgb);
81
+ }
82
+ static RGB_CMYK([r, g, b]) {
83
+ const c = 1 - r;
84
+ const m = 1 - g;
85
+ const y = 1 - b;
86
+ const k = Math.min(c, m, y);
87
+ return ["CMYK", c, m, y, k];
88
+ }
89
+ }
90
+ export { ColorConverters };