1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #15313 from Snuffleupagus/move-binarySearchFirstItem

Move `binarySearchFirstItem` back to the `web/`-folder (PR 15237 follow-up)
This commit is contained in:
Tim van der Meij 2022-08-14 12:14:32 +02:00 committed by GitHub
commit e6fe127433
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 79 additions and 83 deletions

View file

@ -611,38 +611,6 @@ function getColorValues(colors) {
span.remove();
}
/**
* Use binary search to find the index of the first item in a given array which
* passes a given condition. The items are expected to be sorted in the sense
* that if the condition is true for one item in the array, then it is also true
* for all following items.
*
* @returns {number} Index of the first array element to pass the test,
* or |items.length| if no such element exists.
*/
function binarySearchFirstItem(items, condition, start = 0) {
let minIndex = start;
let maxIndex = items.length - 1;
if (maxIndex < 0 || !condition(items[maxIndex])) {
return items.length;
}
if (condition(items[minIndex])) {
return minIndex;
}
while (minIndex < maxIndex) {
const currentIndex = (minIndex + maxIndex) >> 1;
const currentItem = items[currentIndex];
if (condition(currentItem)) {
maxIndex = currentIndex;
} else {
minIndex = currentIndex + 1;
}
}
return minIndex; /* === maxIndex */
}
function getCurrentTransform(ctx) {
const { a, b, c, d, e, f } = ctx.getTransform();
return [a, b, c, d, e, f];
@ -655,7 +623,6 @@ function getCurrentTransformInverse(ctx) {
export {
AnnotationPrefix,
binarySearchFirstItem,
deprecated,
DOMCanvasFactory,
DOMCMapReaderFactory,

View file

@ -41,7 +41,15 @@ import {
VerbosityLevel,
} from "./shared/util.js";
import {
binarySearchFirstItem,
build,
getDocument,
LoopbackPort,
PDFDataRangeTransport,
PDFWorker,
setPDFNetworkStreamFactory,
version,
} from "./display/api.js";
import {
getFilenameFromUrl,
getPdfFilenameFromUrl,
getXfaPageViewport,
@ -52,15 +60,6 @@ import {
PixelsPerInch,
RenderingCancelledException,
} from "./display/display_utils.js";
import {
build,
getDocument,
LoopbackPort,
PDFDataRangeTransport,
PDFWorker,
setPDFNetworkStreamFactory,
version,
} from "./display/api.js";
import { AnnotationEditorLayer } from "./display/editor/annotation_editor_layer.js";
import { AnnotationEditorUIManager } from "./display/editor/tools.js";
import { AnnotationLayer } from "./display/annotation_layer.js";
@ -117,7 +116,6 @@ export {
AnnotationEditorUIManager,
AnnotationLayer,
AnnotationMode,
binarySearchFirstItem,
build,
CMapCompressionType,
createPromiseCapability,