@paulirish/trace_engine 0.0.10 → 0.0.12
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.
- package/README.md +1 -1
- package/analyze-trace.mjs +1 -1
- package/core/platform/DevToolsPath.d.ts +4 -13
- package/core/platform/DevToolsPath.js +7 -4
- package/core/platform/DevToolsPath.js.map +1 -7
- package/core/platform/MimeType.d.ts +27 -0
- package/core/platform/MimeType.js +119 -86
- package/core/platform/MimeType.js.map +1 -7
- package/core/platform/Timing.d.ts +7 -0
- package/core/platform/Timing.js +7 -4
- package/core/platform/Timing.js.map +1 -7
- package/core/platform/UIString.d.ts +2 -5
- package/core/platform/UIString.js +5 -2
- package/core/platform/UIString.js.map +1 -7
- package/core/platform/UserVisibleError.js +19 -10
- package/core/platform/UserVisibleError.js.map +1 -7
- package/core/platform/array-utilities.d.ts +48 -10
- package/core/platform/array-utilities.js +160 -124
- package/core/platform/array-utilities.js.map +1 -7
- package/core/platform/brand.d.ts +14 -0
- package/core/platform/brand.js +5 -1
- package/core/platform/brand.js.map +1 -7
- package/core/platform/date-utilities.js +10 -6
- package/core/platform/date-utilities.js.map +1 -7
- package/core/platform/dom-utilities.d.ts +3 -1
- package/core/platform/dom-utilities.js +94 -83
- package/core/platform/dom-utilities.js.map +1 -7
- package/core/platform/keyboard-utilities.d.ts +2 -0
- package/core/platform/keyboard-utilities.js +15 -24
- package/core/platform/keyboard-utilities.js.map +1 -7
- package/core/platform/map-utilities.d.ts +4 -0
- package/core/platform/map-utilities.js +66 -60
- package/core/platform/map-utilities.js.map +1 -7
- package/core/platform/number-utilities.js +66 -55
- package/core/platform/number-utilities.js.map +1 -7
- package/core/platform/platform.d.ts +5 -1
- package/core/platform/platform.js +54 -37
- package/core/platform/platform.js.map +1 -7
- package/core/platform/promise-utilities.d.ts +10 -0
- package/core/platform/promise-utilities.js +16 -8
- package/core/platform/promise-utilities.js.map +1 -7
- package/core/platform/set-utilities.js +20 -17
- package/core/platform/set-utilities.js.map +1 -7
- package/core/platform/string-utilities.d.ts +32 -1
- package/core/platform/string-utilities.js +453 -379
- package/core/platform/string-utilities.js.map +1 -7
- package/core/platform/typescript-utilities.d.ts +5 -5
- package/core/platform/typescript-utilities.js +19 -7
- package/core/platform/typescript-utilities.js.map +1 -7
- package/generated/protocol.d.ts +2081 -347
- package/generated/protocol.js +5 -2230
- package/models/cpu_profile/CPUProfileDataModel.d.ts +77 -0
- package/models/cpu_profile/CPUProfileDataModel.js +492 -359
- package/models/cpu_profile/CPUProfileDataModel.js.map +1 -7
- package/models/cpu_profile/ProfileTreeModel.d.ts +29 -0
- package/models/cpu_profile/ProfileTreeModel.js +87 -82
- package/models/cpu_profile/ProfileTreeModel.js.map +1 -7
- package/models/cpu_profile/cpu_profile.d.ts +3 -0
- package/models/cpu_profile/cpu_profile.js +7 -7
- package/models/cpu_profile/cpu_profile.js.map +1 -7
- package/models/trace/EntriesFilter.d.ts +55 -0
- package/models/trace/EntriesFilter.js +227 -166
- package/models/trace/EntriesFilter.js.map +1 -7
- package/models/trace/LegacyTracingModel.js.map +1 -7
- package/models/trace/ModelImpl.d.ts +110 -0
- package/models/trace/ModelImpl.js +161 -102
- package/models/trace/ModelImpl.js.map +1 -7
- package/models/trace/Processor.d.ts +36 -0
- package/models/trace/Processor.js +197 -163
- package/models/trace/Processor.js.map +1 -7
- package/models/trace/TracingManager.js.map +1 -7
- package/models/trace/extras/FetchNodes.d.ts +46 -0
- package/models/trace/extras/FetchNodes.js +132 -91
- package/models/trace/extras/FetchNodes.js.map +1 -7
- package/models/trace/extras/FilmStrip.d.ts +19 -0
- package/models/trace/extras/FilmStrip.js +38 -31
- package/models/trace/extras/FilmStrip.js.map +1 -7
- package/models/trace/extras/MainThreadActivity.d.ts +2 -0
- package/models/trace/extras/MainThreadActivity.js +72 -56
- package/models/trace/extras/MainThreadActivity.js.map +1 -7
- package/models/trace/extras/Metadata.d.ts +2 -0
- package/models/trace/extras/Metadata.js +42 -26
- package/models/trace/extras/Metadata.js.map +1 -7
- package/models/trace/extras/extras.js.map +1 -7
- package/models/trace/handlers/AnimationHandler.d.ts +8 -0
- package/models/trace/handlers/AnimationHandler.js +22 -20
- package/models/trace/handlers/AnimationHandler.js.map +1 -7
- package/models/trace/handlers/AuctionWorkletsHandler.d.ts +8 -0
- package/models/trace/handlers/AuctionWorkletsHandler.js +143 -89
- package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -7
- package/models/trace/handlers/FramesHandler.d.ts +76 -0
- package/models/trace/handlers/FramesHandler.js +424 -355
- package/models/trace/handlers/FramesHandler.js.map +1 -7
- package/models/trace/handlers/GPUHandler.d.ts +11 -0
- package/models/trace/handlers/GPUHandler.js +41 -37
- package/models/trace/handlers/GPUHandler.js.map +1 -7
- package/models/trace/handlers/InitiatorsHandler.d.ts +10 -0
- package/models/trace/handlers/InitiatorsHandler.js +164 -113
- package/models/trace/handlers/InitiatorsHandler.js.map +1 -7
- package/models/trace/handlers/InvalidationsHandler.d.ts +10 -0
- package/models/trace/handlers/InvalidationsHandler.js +101 -79
- package/models/trace/handlers/InvalidationsHandler.js.map +1 -7
- package/models/trace/handlers/LargestImagePaintHandler.d.ts +5 -0
- package/models/trace/handlers/LargestImagePaintHandler.js +32 -12
- package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -7
- package/models/trace/handlers/LargestTextPaintHandler.d.ts +5 -0
- package/models/trace/handlers/LargestTextPaintHandler.js +20 -12
- package/models/trace/handlers/LargestTextPaintHandler.js.map +1 -7
- package/models/trace/handlers/LayerTreeHandler.d.ts +13 -0
- package/models/trace/handlers/LayerTreeHandler.js +96 -70
- package/models/trace/handlers/LayerTreeHandler.js.map +1 -7
- package/models/trace/handlers/LayoutShiftsHandler.d.ts +44 -0
- package/models/trace/handlers/LayoutShiftsHandler.js +304 -227
- package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -7
- package/models/trace/handlers/MemoryHandler.d.ts +7 -0
- package/models/trace/handlers/MemoryHandler.js +14 -11
- package/models/trace/handlers/MemoryHandler.js.map +1 -7
- package/models/trace/handlers/MetaHandler.d.ts +37 -0
- package/models/trace/handlers/MetaHandler.js +314 -226
- package/models/trace/handlers/MetaHandler.js.map +1 -7
- package/models/trace/handlers/ModelHandlers.d.ts +21 -0
- package/models/trace/handlers/ModelHandlers.js +25 -22
- package/models/trace/handlers/ModelHandlers.js.map +1 -7
- package/models/trace/handlers/NetworkRequestsHandler.d.ts +17 -0
- package/models/trace/handlers/NetworkRequestsHandler.js +342 -218
- package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -7
- package/models/trace/handlers/PageLoadMetricsHandler.d.ts +67 -0
- package/models/trace/handlers/PageLoadMetricsHandler.js +357 -284
- package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -7
- package/models/trace/handlers/RendererHandler.d.ts +101 -0
- package/models/trace/handlers/RendererHandler.js +295 -191
- package/models/trace/handlers/RendererHandler.js.map +1 -7
- package/models/trace/handlers/SamplesHandler.d.ts +46 -0
- package/models/trace/handlers/SamplesHandler.js +195 -158
- package/models/trace/handlers/SamplesHandler.js.map +1 -7
- package/models/trace/handlers/ScreenshotsHandler.d.ts +7 -0
- package/models/trace/handlers/ScreenshotsHandler.js +63 -41
- package/models/trace/handlers/ScreenshotsHandler.js.map +1 -7
- package/models/trace/handlers/Threads.d.ts +33 -0
- package/models/trace/handlers/Threads.js +85 -67
- package/models/trace/handlers/Threads.js.map +1 -7
- package/models/trace/handlers/UserInteractionsHandler.d.ts +57 -0
- package/models/trace/handlers/UserInteractionsHandler.js +240 -141
- package/models/trace/handlers/UserInteractionsHandler.js.map +1 -7
- package/models/trace/handlers/UserTimingsHandler.d.ts +28 -0
- package/models/trace/handlers/UserTimingsHandler.js +91 -80
- package/models/trace/handlers/UserTimingsHandler.js.map +1 -7
- package/models/trace/handlers/WarningsHandler.d.ts +14 -0
- package/models/trace/handlers/WarningsHandler.js +100 -62
- package/models/trace/handlers/WarningsHandler.js.map +1 -7
- package/models/trace/handlers/WorkersHandler.d.ts +11 -0
- package/models/trace/handlers/WorkersHandler.js +40 -38
- package/models/trace/handlers/WorkersHandler.js.map +1 -7
- package/models/trace/handlers/handlers.d.ts +3 -0
- package/models/trace/handlers/handlers.js +7 -4
- package/models/trace/handlers/handlers.js.map +1 -7
- package/models/trace/handlers/types.d.ts +45 -0
- package/models/trace/handlers/types.js +15 -15
- package/models/trace/handlers/types.js.map +1 -7
- package/models/trace/helpers/SamplesIntegrator.d.ts +49 -0
- package/models/trace/helpers/SamplesIntegrator.js +381 -204
- package/models/trace/helpers/SamplesIntegrator.js.map +1 -7
- package/models/trace/helpers/Timing.d.ts +26 -0
- package/models/trace/helpers/Timing.js +131 -110
- package/models/trace/helpers/Timing.js.map +1 -7
- package/models/trace/helpers/Trace.d.ts +37 -0
- package/models/trace/helpers/Trace.js +200 -166
- package/models/trace/helpers/Trace.js.map +1 -7
- package/models/trace/helpers/TreeHelpers.d.ts +90 -0
- package/models/trace/helpers/TreeHelpers.js +203 -100
- package/models/trace/helpers/TreeHelpers.js.map +1 -7
- package/models/trace/helpers/helpers.d.ts +4 -0
- package/models/trace/helpers/helpers.js +8 -5
- package/models/trace/helpers/helpers.js.map +1 -7
- package/models/trace/root-causes/LayoutShift.d.ts +119 -0
- package/models/trace/root-causes/LayoutShift.js +470 -323
- package/models/trace/root-causes/LayoutShift.js.map +1 -7
- package/models/trace/root-causes/RootCauses.d.ts +14 -0
- package/models/trace/root-causes/RootCauses.js +9 -6
- package/models/trace/root-causes/RootCauses.js.map +1 -7
- package/models/trace/root-causes/root-causes.d.ts +1 -0
- package/models/trace/root-causes/root-causes.js +5 -2
- package/models/trace/root-causes/root-causes.js.map +1 -7
- package/models/trace/trace.d.ts +11 -0
- package/models/trace/trace.js +17 -23
- package/models/trace/trace.js.map +1 -7
- package/models/trace/types/Configuration.d.ts +33 -0
- package/models/trace/types/Configuration.js +25 -14
- package/models/trace/types/Configuration.js.map +1 -7
- package/models/trace/types/File.d.ts +23 -0
- package/models/trace/types/File.js +5 -6
- package/models/trace/types/File.js.map +1 -7
- package/models/trace/types/Timing.d.ts +25 -0
- package/models/trace/types/Timing.js +10 -11
- package/models/trace/types/Timing.js.map +1 -7
- package/models/trace/types/TraceEvents.d.ts +1571 -0
- package/models/trace/types/TraceEvents.js +174 -381
- package/models/trace/types/TraceEvents.js.map +1 -7
- package/models/trace/types/types.d.ts +4 -0
- package/models/trace/types/types.js +8 -5
- package/models/trace/types/types.js.map +1 -7
- package/package.json +1 -1
- package/TracingManager.js +0 -0
- package/core/platform/devtools_entrypoint-bundle-tsconfig-tsconfig.json +0 -40
- package/core/platform/platform.js.compressed +0 -0
- package/core/platform/platform.js.hash +0 -1
- package/core/platform/platform.prebundle.d.ts +0 -15
- package/core/platform/platform.prebundle.js +0 -50
- package/core/platform/platform.prebundle.js.map +0 -1
- package/core/platform/platform.prebundle.ts +0 -64
- package/extras/extras.js +0 -0
- package/models/trace/SDKServices.js +0 -104
- package/models/trace/SDKServices.js.map +0 -7
- package/models/trace/TraceProcessor.js +0 -133
- package/models/trace/TraceProcessor.js.map +0 -7
- package/models/trace/TreeManipulator.js +0 -85
- package/models/trace/TreeManipulator.js.map +0 -7
- package/models/trace/devtools_entrypoint-legacy-typescript-tsconfig.json +0 -43
- package/models/trace/frames/TimelineFrameModel.js +0 -392
- package/models/trace/frames/TimelineFrameModel.js.map +0 -7
- package/models/trace/frames/bundle-tsconfig.json +0 -1
- package/models/trace/frames/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -43
- package/models/trace/frames/frames-tsconfig.json +0 -58
- package/models/trace/frames/frames.js +0 -5
- package/models/trace/frames/frames.js.map +0 -7
- package/models/trace/handlers/Migration.js +0 -27
- package/models/trace/handlers/Migration.js.map +0 -7
- package/models/trace/handlers/UberFramesHandler.js +0 -293
- package/models/trace/handlers/UberFramesHandler.js.map +0 -7
- package/models/trace/legacy-tsconfig.json +0 -1
- package/models/trace/sdk_services/DOMNodeLookup.js +0 -41
- package/models/trace/sdk_services/DOMNodeLookup.js.map +0 -7
- package/models/trace/sdk_services/LayoutShifts.js +0 -68
- package/models/trace/sdk_services/LayoutShifts.js.map +0 -7
- package/models/trace/sdk_services/bundle-tsconfig.json +0 -1
- package/models/trace/sdk_services/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -41
- package/models/trace/sdk_services/sdk_services-tsconfig.json +0 -57
- package/models/trace/sdk_services/sdk_services.js +0 -7
- package/models/trace/sdk_services/sdk_services.js.map +0 -7
- package/models/trace/trace-legacy.js +0 -16
- package/models/trace/trace-legacy.js.map +0 -7
- package/models/trace/worker/Processor.js +0 -143
- package/models/trace/worker/Processor.js.map +0 -7
- package/models/trace/worker/Types.js +0 -1
- package/models/trace/worker/Types.js.map +0 -7
- package/models/trace/worker/bundle-tsconfig.json +0 -1
- package/models/trace/worker/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -41
- package/models/trace/worker/devtools_entrypoint-worker_entrypoint-typescript-tsconfig.json +0 -41
- package/models/trace/worker/processor-tsconfig.json +0 -45
- package/models/trace/worker/worker.js +0 -7
- package/models/trace/worker/worker.js.map +0 -7
- package/models/trace/worker/worker_entrypoint-tsconfig.json +0 -1
- package/models/trace/worker/worker_entrypoint.js +0 -36
- package/models/trace/worker/worker_entrypoint.js.map +0 -7
- package/trace.mjs +0 -6980
- package/trace.mjs.map +0 -8
|
@@ -1,163 +1,199 @@
|
|
|
1
|
+
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
1
4
|
export const removeElement = (array, element, firstOnly) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
for (let i = index + 1, n = array.length; i < n; ++i) {
|
|
11
|
-
if (array[i] !== element) {
|
|
12
|
-
array[index++] = array[i];
|
|
5
|
+
let index = array.indexOf(element);
|
|
6
|
+
if (index === -1) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (firstOnly) {
|
|
10
|
+
array.splice(index, 1);
|
|
11
|
+
return true;
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
for (let i = index + 1, n = array.length; i < n; ++i) {
|
|
14
|
+
if (array[i] !== element) {
|
|
15
|
+
array[index++] = array[i];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
array.length = index;
|
|
19
|
+
return true;
|
|
17
20
|
};
|
|
18
21
|
function swap(array, i1, i2) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
const temp = array[i1];
|
|
23
|
+
array[i1] = array[i2];
|
|
24
|
+
array[i2] = temp;
|
|
22
25
|
}
|
|
23
26
|
function partition(array, comparator, left, right, pivotIndex) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const pivotValue = array[pivotIndex];
|
|
28
|
+
swap(array, right, pivotIndex);
|
|
29
|
+
let storeIndex = left;
|
|
30
|
+
for (let i = left; i < right; ++i) {
|
|
31
|
+
if (comparator(array[i], pivotValue) < 0) {
|
|
32
|
+
swap(array, storeIndex, i);
|
|
33
|
+
++storeIndex;
|
|
34
|
+
}
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return storeIndex;
|
|
36
|
+
swap(array, right, storeIndex);
|
|
37
|
+
return storeIndex;
|
|
35
38
|
}
|
|
36
39
|
function quickSortRange(array, comparator, left, right, sortWindowLeft, sortWindowRight) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
if (right <= left) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const pivotIndex = Math.floor(Math.random() * (right - left)) + left;
|
|
44
|
+
const pivotNewIndex = partition(array, comparator, left, right, pivotIndex);
|
|
45
|
+
if (sortWindowLeft < pivotNewIndex) {
|
|
46
|
+
quickSortRange(array, comparator, left, pivotNewIndex - 1, sortWindowLeft, sortWindowRight);
|
|
47
|
+
}
|
|
48
|
+
if (pivotNewIndex < sortWindowRight) {
|
|
49
|
+
quickSortRange(array, comparator, pivotNewIndex + 1, right, sortWindowLeft, sortWindowRight);
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
52
|
export function sortRange(array, comparator, leftBound, rightBound, sortWindowLeft, sortWindowRight) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
if (leftBound === 0 && rightBound === (array.length - 1) && sortWindowLeft === 0 && sortWindowRight >= rightBound) {
|
|
54
|
+
array.sort(comparator);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
quickSortRange(array, comparator, leftBound, rightBound, sortWindowLeft, sortWindowRight);
|
|
58
|
+
}
|
|
59
|
+
return array;
|
|
56
60
|
}
|
|
57
61
|
export const binaryIndexOf = (array, value, comparator) => {
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
const index = lowerBound(array, value, comparator);
|
|
63
|
+
return index < array.length && comparator(value, array[index]) === 0 ? index : -1;
|
|
60
64
|
};
|
|
61
65
|
function mergeOrIntersect(array1, array2, comparator, mergeNotIntersect) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
const result = [];
|
|
67
|
+
let i = 0;
|
|
68
|
+
let j = 0;
|
|
69
|
+
while (i < array1.length && j < array2.length) {
|
|
70
|
+
const compareValue = comparator(array1[i], array2[j]);
|
|
71
|
+
if (mergeNotIntersect || !compareValue) {
|
|
72
|
+
result.push(compareValue <= 0 ? array1[i] : array2[j]);
|
|
73
|
+
}
|
|
74
|
+
if (compareValue <= 0) {
|
|
75
|
+
i++;
|
|
76
|
+
}
|
|
77
|
+
if (compareValue >= 0) {
|
|
78
|
+
j++;
|
|
79
|
+
}
|
|
72
80
|
}
|
|
73
|
-
if (
|
|
74
|
-
|
|
81
|
+
if (mergeNotIntersect) {
|
|
82
|
+
while (i < array1.length) {
|
|
83
|
+
result.push(array1[i++]);
|
|
84
|
+
}
|
|
85
|
+
while (j < array2.length) {
|
|
86
|
+
result.push(array2[j++]);
|
|
87
|
+
}
|
|
75
88
|
}
|
|
76
|
-
|
|
77
|
-
if (mergeNotIntersect) {
|
|
78
|
-
while (i < array1.length) {
|
|
79
|
-
result.push(array1[i++]);
|
|
80
|
-
}
|
|
81
|
-
while (j < array2.length) {
|
|
82
|
-
result.push(array2[j++]);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return result;
|
|
89
|
+
return result;
|
|
86
90
|
}
|
|
87
91
|
export const intersectOrdered = (array1, array2, comparator) => {
|
|
88
|
-
|
|
92
|
+
return mergeOrIntersect(array1, array2, comparator, false);
|
|
89
93
|
};
|
|
90
94
|
export const mergeOrdered = (array1, array2, comparator) => {
|
|
91
|
-
|
|
95
|
+
return mergeOrIntersect(array1, array2, comparator, true);
|
|
92
96
|
};
|
|
93
97
|
export const DEFAULT_COMPARATOR = (a, b) => {
|
|
94
|
-
|
|
98
|
+
return a < b ? -1 : (a > b ? 1 : 0);
|
|
95
99
|
};
|
|
96
100
|
export function lowerBound(array, needle, comparator, left, right) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
let l = left || 0;
|
|
102
|
+
let r = right !== undefined ? right : array.length;
|
|
103
|
+
while (l < r) {
|
|
104
|
+
const m = (l + r) >> 1;
|
|
105
|
+
if (comparator(needle, array[m]) > 0) {
|
|
106
|
+
l = m + 1;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
r = m;
|
|
110
|
+
}
|
|
105
111
|
}
|
|
106
|
-
|
|
107
|
-
return r;
|
|
112
|
+
return r;
|
|
108
113
|
}
|
|
109
114
|
export function upperBound(array, needle, comparator, left, right) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
let l = left || 0;
|
|
116
|
+
let r = right !== undefined ? right : array.length;
|
|
117
|
+
while (l < r) {
|
|
118
|
+
const m = (l + r) >> 1;
|
|
119
|
+
if (comparator(needle, array[m]) >= 0) {
|
|
120
|
+
l = m + 1;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
r = m;
|
|
124
|
+
}
|
|
118
125
|
}
|
|
119
|
-
|
|
120
|
-
return r;
|
|
126
|
+
return r;
|
|
121
127
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Obtains the first or last item in the array that satisfies the predicate function.
|
|
130
|
+
* So, for example, if the array were arr = [2, 4, 6, 8, 10], and you are looking for
|
|
131
|
+
* the last item arr[i] such that arr[i] < 5 you would be returned 1, because
|
|
132
|
+
* array[1] is 4, the last item in the array that satisfies the
|
|
133
|
+
* predicate function.
|
|
134
|
+
*
|
|
135
|
+
* If instead you were looking for the first item in the same array that satisfies
|
|
136
|
+
* arr[i] > 5 you would be returned 2 because array[2] = 6.
|
|
137
|
+
*
|
|
138
|
+
* Please note: this presupposes that the array is already ordered.
|
|
139
|
+
*/
|
|
127
140
|
function nearestIndex(arr, predicate, searchStart) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
const searchFromEnd = searchStart === "END" /* NearestSearchStart.END */;
|
|
142
|
+
if (arr.length === 0) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
let left = 0;
|
|
146
|
+
let right = arr.length - 1;
|
|
147
|
+
let pivot = 0;
|
|
148
|
+
let matchesPredicate = false;
|
|
149
|
+
let moveToTheRight = false;
|
|
150
|
+
let middle = 0;
|
|
151
|
+
do {
|
|
152
|
+
middle = left + (right - left) / 2;
|
|
153
|
+
pivot = searchFromEnd ? Math.ceil(middle) : Math.floor(middle);
|
|
154
|
+
matchesPredicate = predicate(arr[pivot]);
|
|
155
|
+
moveToTheRight = matchesPredicate === searchFromEnd;
|
|
156
|
+
if (moveToTheRight) {
|
|
157
|
+
left = Math.min(right, pivot + (left === pivot ? 1 : 0));
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
right = Math.max(left, pivot + (right === pivot ? -1 : 0));
|
|
161
|
+
}
|
|
162
|
+
} while (right !== left);
|
|
163
|
+
// Special-case: the indexed item doesn't pass the predicate. This
|
|
164
|
+
// occurs when none of the items in the array are a match for the
|
|
165
|
+
// predicate.
|
|
166
|
+
if (!predicate(arr[left])) {
|
|
167
|
+
return null;
|
|
147
168
|
}
|
|
148
|
-
|
|
149
|
-
if (!predicate(arr[left])) {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
return left;
|
|
169
|
+
return left;
|
|
153
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Obtains the first item in the array that satisfies the predicate function.
|
|
173
|
+
* So, for example, if the array was arr = [2, 4, 6, 8, 10], and you are looking for
|
|
174
|
+
* the first item arr[i] such that arr[i] > 5 you would be returned 2, because
|
|
175
|
+
* array[2] is 6, the first item in the array that satisfies the
|
|
176
|
+
* predicate function.
|
|
177
|
+
*
|
|
178
|
+
* Please note: this presupposes that the array is already ordered.
|
|
179
|
+
*/
|
|
154
180
|
export function nearestIndexFromBeginning(arr, predicate) {
|
|
155
|
-
|
|
181
|
+
return nearestIndex(arr, predicate, "BEGINNING" /* NearestSearchStart.BEGINNING */);
|
|
156
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Obtains the last item in the array that satisfies the predicate function.
|
|
185
|
+
* So, for example, if the array was arr = [2, 4, 6, 8, 10], and you are looking for
|
|
186
|
+
* the last item arr[i] such that arr[i] < 5 you would be returned 1, because
|
|
187
|
+
* arr[1] is 4, the last item in the array that satisfies the
|
|
188
|
+
* predicate function.
|
|
189
|
+
*
|
|
190
|
+
* Please note: this presupposes that the array is already ordered.
|
|
191
|
+
*/
|
|
157
192
|
export function nearestIndexFromEnd(arr, predicate) {
|
|
158
|
-
|
|
193
|
+
return nearestIndex(arr, predicate, "END" /* NearestSearchStart.END */);
|
|
159
194
|
}
|
|
195
|
+
// Type guard for ensuring that `arr` does not contain null or undefined
|
|
160
196
|
export function arrayDoesNotContainNullOrUndefined(arr) {
|
|
161
|
-
|
|
197
|
+
return !arr.includes(null) && !arr.includes(undefined);
|
|
162
198
|
}
|
|
163
|
-
//# sourceMappingURL=array-utilities.js.map
|
|
199
|
+
//# sourceMappingURL=array-utilities.js.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../../../front_end/core/platform/array-utilities.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) 2020 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nexport const removeElement = <T>(array: T[], element: T, firstOnly?: boolean): boolean => {\n let index = array.indexOf(element);\n if (index === -1) {\n return false;\n }\n if (firstOnly) {\n array.splice(index, 1);\n return true;\n }\n for (let i = index + 1, n = array.length; i < n; ++i) {\n if (array[i] !== element) {\n array[index++] = array[i];\n }\n }\n array.length = index;\n return true;\n};\n\ntype NumberComparator = (a: number, b: number) => number;\n\nfunction swap(array: number[], i1: number, i2: number): void {\n const temp = array[i1];\n array[i1] = array[i2];\n array[i2] = temp;\n}\n\nfunction partition(\n array: number[], comparator: NumberComparator, left: number, right: number, pivotIndex: number): number {\n const pivotValue = array[pivotIndex];\n swap(array, right, pivotIndex);\n let storeIndex = left;\n for (let i = left; i < right; ++i) {\n if (comparator(array[i], pivotValue) < 0) {\n swap(array, storeIndex, i);\n ++storeIndex;\n }\n }\n swap(array, right, storeIndex);\n return storeIndex;\n}\n\nfunction quickSortRange(\n array: number[], comparator: NumberComparator, left: number, right: number, sortWindowLeft: number,\n sortWindowRight: number): void {\n if (right <= left) {\n return;\n }\n const pivotIndex = Math.floor(Math.random() * (right - left)) + left;\n const pivotNewIndex = partition(array, comparator, left, right, pivotIndex);\n if (sortWindowLeft < pivotNewIndex) {\n quickSortRange(array, comparator, left, pivotNewIndex - 1, sortWindowLeft, sortWindowRight);\n }\n if (pivotNewIndex < sortWindowRight) {\n quickSortRange(array, comparator, pivotNewIndex + 1, right, sortWindowLeft, sortWindowRight);\n }\n}\n\nexport function sortRange(\n array: number[], comparator: NumberComparator, leftBound: number, rightBound: number, sortWindowLeft: number,\n sortWindowRight: number): number[] {\n if (leftBound === 0 && rightBound === (array.length - 1) && sortWindowLeft === 0 && sortWindowRight >= rightBound) {\n array.sort(comparator);\n } else {\n quickSortRange(array, comparator, leftBound, rightBound, sortWindowLeft, sortWindowRight);\n }\n return array;\n}\nexport const binaryIndexOf = <T, S>(array: T[], value: S, comparator: (a: S, b: T) => number): number => {\n const index = lowerBound(array, value, comparator);\n return index < array.length && comparator(value, array[index]) === 0 ? index : -1;\n};\n\nfunction mergeOrIntersect<T>(\n array1: T[], array2: T[], comparator: (a: T, b: T) => number, mergeNotIntersect: boolean): T[] {\n const result = [];\n let i = 0;\n let j = 0;\n while (i < array1.length && j < array2.length) {\n const compareValue = comparator(array1[i], array2[j]);\n if (mergeNotIntersect || !compareValue) {\n result.push(compareValue <= 0 ? array1[i] : array2[j]);\n }\n if (compareValue <= 0) {\n i++;\n }\n if (compareValue >= 0) {\n j++;\n }\n }\n if (mergeNotIntersect) {\n while (i < array1.length) {\n result.push(array1[i++]);\n }\n while (j < array2.length) {\n result.push(array2[j++]);\n }\n }\n return result;\n}\n\nexport const intersectOrdered = <T>(array1: T[], array2: T[], comparator: (a: T, b: T) => number): T[] => {\n return mergeOrIntersect(array1, array2, comparator, false);\n};\n\nexport const mergeOrdered = <T>(array1: T[], array2: T[], comparator: (a: T, b: T) => number): T[] => {\n return mergeOrIntersect(array1, array2, comparator, true);\n};\n\nexport const DEFAULT_COMPARATOR = (a: string|number, b: string|number): -1|0|1 => {\n return a < b ? -1 : (a > b ? 1 : 0);\n};\n\n/**\n * Returns the index of the element closest to the needle that is equal to or\n * greater than it. Assumes that the provided array is sorted.\n *\n * If no element is found, the right bound is returned.\n *\n * Uses the provided comparator function to determine if two items are equal or\n * if one is greater than the other. If you are working with strings or\n * numbers, you can use ArrayUtilities.DEFAULT_COMPARATOR. Otherwise, you\n * should define one that takes the needle element and an element from the\n * array and returns a positive or negative number to indicate which is greater\n * than the other.\n *\n * When specified, |left| (inclusive) and |right| (exclusive) indices\n * define the search window.\n */\nexport function lowerBound<T>(\n array: Uint32Array|Int32Array, needle: T, comparator: (needle: T, b: number) => number, left?: number,\n right?: number): number;\nexport function lowerBound<S, T>(\n array: S[], needle: T, comparator: (needle: T, b: S) => number, left?: number, right?: number): number;\nexport function lowerBound<S, T>(\n array: readonly S[], needle: T, comparator: (needle: T, b: S) => number, left?: number, right?: number): number;\nexport function lowerBound<S, T, A extends S[]>(\n array: A, needle: T, comparator: (needle: T, b: S) => number, left?: number, right?: number): number {\n let l = left || 0;\n let r = right !== undefined ? right : array.length;\n while (l < r) {\n const m = (l + r) >> 1;\n if (comparator(needle, array[m]) > 0) {\n l = m + 1;\n } else {\n r = m;\n }\n }\n return r;\n}\n\n/**\n * Returns the index of the element closest to the needle that is greater than\n * it. Assumes that the provided array is sorted.\n *\n * If no element is found, the right bound is returned.\n *\n * Uses the provided comparator function to determine if two items are equal or\n * if one is greater than the other. If you are working with strings or\n * numbers, you can use ArrayUtilities.DEFAULT_COMPARATOR. Otherwise, you\n * should define one that takes the needle element and an element from the\n * array and returns a positive or negative number to indicate which is greater\n * than the other.\n *\n * When specified, |left| (inclusive) and |right| (exclusive) indices\n * define the search window.\n */\nexport function upperBound<T>(\n array: Uint32Array, needle: T, comparator: (needle: T, b: number) => number, left?: number, right?: number): number;\nexport function upperBound<S, T>(\n array: S[], needle: T, comparator: (needle: T, b: S) => number, left?: number, right?: number): number;\nexport function upperBound<S, T, A extends S[]>(\n array: A, needle: T, comparator: (needle: T, b: S) => number, left?: number, right?: number): number {\n let l = left || 0;\n let r = right !== undefined ? right : array.length;\n while (l < r) {\n const m = (l + r) >> 1;\n if (comparator(needle, array[m]) >= 0) {\n l = m + 1;\n } else {\n r = m;\n }\n }\n return r;\n}\n\nconst enum NearestSearchStart {\n BEGINNING = 'BEGINNING',\n END = 'END',\n}\n/**\n * Obtains the first or last item in the array that satisfies the predicate function.\n * So, for example, if the array were arr = [2, 4, 6, 8, 10], and you are looking for\n * the last item arr[i] such that arr[i] < 5 you would be returned 1, because\n * array[1] is 4, the last item in the array that satisfies the\n * predicate function.\n *\n * If instead you were looking for the first item in the same array that satisfies\n * arr[i] > 5 you would be returned 2 because array[2] = 6.\n *\n * Please note: this presupposes that the array is already ordered.\n */\nfunction nearestIndex<T>(\n arr: readonly T[], predicate: (arrayItem: T) => boolean, searchStart: NearestSearchStart): number|null {\n const searchFromEnd = searchStart === NearestSearchStart.END;\n if (arr.length === 0) {\n return null;\n }\n\n let left = 0;\n let right = arr.length - 1;\n let pivot = 0;\n let matchesPredicate = false;\n let moveToTheRight = false;\n let middle = 0;\n do {\n middle = left + (right - left) / 2;\n pivot = searchFromEnd ? Math.ceil(middle) : Math.floor(middle);\n matchesPredicate = predicate(arr[pivot]);\n moveToTheRight = matchesPredicate === searchFromEnd;\n if (moveToTheRight) {\n left = Math.min(right, pivot + (left === pivot ? 1 : 0));\n } else {\n right = Math.max(left, pivot + (right === pivot ? -1 : 0));\n }\n } while (right !== left);\n\n // Special-case: the indexed item doesn't pass the predicate. This\n // occurs when none of the items in the array are a match for the\n // predicate.\n if (!predicate(arr[left])) {\n return null;\n }\n return left;\n}\n\n/**\n * Obtains the first item in the array that satisfies the predicate function.\n * So, for example, if the array was arr = [2, 4, 6, 8, 10], and you are looking for\n * the first item arr[i] such that arr[i] > 5 you would be returned 2, because\n * array[2] is 6, the first item in the array that satisfies the\n * predicate function.\n *\n * Please note: this presupposes that the array is already ordered.\n */\nexport function nearestIndexFromBeginning<T>(arr: T[], predicate: (arrayItem: T) => boolean): number|null {\n return nearestIndex(arr, predicate, NearestSearchStart.BEGINNING);\n}\n\n/**\n * Obtains the last item in the array that satisfies the predicate function.\n * So, for example, if the array was arr = [2, 4, 6, 8, 10], and you are looking for\n * the last item arr[i] such that arr[i] < 5 you would be returned 1, because\n * arr[1] is 4, the last item in the array that satisfies the\n * predicate function.\n *\n * Please note: this presupposes that the array is already ordered.\n */\n\nexport function nearestIndexFromEnd<T>(arr: readonly T[], predicate: (arrayItem: T) => boolean): number|null {\n return nearestIndex(arr, predicate, NearestSearchStart.END);\n}\n\n// Type guard for ensuring that `arr` does not contain null or undefined\nexport function arrayDoesNotContainNullOrUndefined<T>(arr: (T|null|undefined)[]): arr is T[] {\n return !arr.includes(null) && !arr.includes(undefined);\n}\n"],
|
|
5
|
-
"mappings": "AAIO,aAAM,gBAAgB,CAAI,OAAY,SAAY,cAAiC;AACxF,MAAI,QAAQ,MAAM,QAAQ;AAC1B,MAAI,UAAU,IAAI;AAChB,WAAO;AAAA;AAET,MAAI,WAAW;AACb,UAAM,OAAO,OAAO;AACpB,WAAO;AAAA;AAET,WAAS,IAAI,QAAQ,GAAG,IAAI,MAAM,QAAQ,IAAI,GAAG,EAAE,GAAG;AACpD,QAAI,MAAM,OAAO,SAAS;AACxB,YAAM,WAAW,MAAM;AAAA;AAAA;AAG3B,QAAM,SAAS;AACf,S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Q,MAAM,OAAO,GAAG;AACrC,UAAI,IAAI;AAAA,WACH;AACL,UAAI;AAAA;AAAA;AAGR,SAAO;AAAA;AAGT,IAAW,qBAAX,kBAAW,wBAAX;AACE,qCAAY;AACZ,+BAAM;AAFG;AAAA;AAgBX,sBACI,KAAmB,WAAsC,aAA8C;AACzG,QAAM,gBAAgB,gBAAgB;AACtC,MAAI,IAAI,WAAW,GAAG;AACpB,WAAO;AAAA;AAGT,MAAI,OAAO;AACX,MAAI,QAAQ,IAAI,SAAS;AACzB,MAAI,QAAQ;AACZ,MAAI,mBAAmB;AACvB,MAAI,iBAAiB;AACrB,MAAI,SAAS;AACb,KAAG;AACD,aAAS,OAAQ,SAAQ,QAAQ;AACjC,YAAQ,gBAAgB,KAAK,KAAK,UAAU,KAAK,MAAM;AACvD,uBAAmB,UAAU,IAAI;AACjC,qBAAiB,qBAAqB;AACtC,QAAI,gBAAgB;AAClB,aAAO,KAAK,IAAI,OAAO,QAAS,UAAS,QAAQ,IAAI;AAAA,WAChD;AACL,cAAQ,KAAK,IAAI,MAAM,QAAS,WAAU,QAAQ,KAAK;AAAA;AAAA,WAElD,UAAU;AAKnB,MAAI,CAAC,UAAU,IAAI,QAAQ;AACzB,WAAO;AAAA;AAET,SAAO;AAAA;AAYF,0CAAsC,KAAU,WAAmD;AACxG,SAAO,aAAa,KAAK,WAAW;AAAA;AAa/B,oCAAgC,KAAmB,WAAmD;AAC3G,SAAO,aAAa,KAAK,WAAW;AAAA;AAI/B,mDAA+C,KAAuC;AAC3F,SAAO,CAAC,IAAI,SAAS,SAAS,CAAC,IAAI,SAAS;AAAA;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"array-utilities.js","sourceRoot":"","sources":["../../../../../../front_end/core/platform/array-utilities.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,yEAAyE;AACzE,6BAA6B;AAE7B,MAAM,CAAC,MAAM,aAAa,GAAG,CAAI,KAAU,EAAE,OAAU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AI,GAAyB;IAC7E,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACzD,CAAC","sourcesContent":["// Copyright (c) 2020 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nexport const removeElement = <T>(array: T[], element: T, firstOnly?: boolean): boolean => {\n let index = array.indexOf(element);\n if (index === -1) {\n return false;\n }\n if (firstOnly) {\n array.splice(index, 1);\n return true;\n }\n for (let i = index + 1, n = array.length; i < n; ++i) {\n if (array[i] !== element) {\n array[index++] = array[i];\n }\n }\n array.length = index;\n return true;\n};\n\ntype NumberComparator = (a: number, b: number) => number;\n\nfunction swap(array: number[], i1: number, i2: number): void {\n const temp = array[i1];\n array[i1] = array[i2];\n array[i2] = temp;\n}\n\nfunction partition(\n array: number[], comparator: NumberComparator, left: number, right: number, pivotIndex: number): number {\n const pivotValue = array[pivotIndex];\n swap(array, right, pivotIndex);\n let storeIndex = left;\n for (let i = left; i < right; ++i) {\n if (comparator(array[i], pivotValue) < 0) {\n swap(array, storeIndex, i);\n ++storeIndex;\n }\n }\n swap(array, right, storeIndex);\n return storeIndex;\n}\n\nfunction quickSortRange(\n array: number[], comparator: NumberComparator, left: number, right: number, sortWindowLeft: number,\n sortWindowRight: number): void {\n if (right <= left) {\n return;\n }\n const pivotIndex = Math.floor(Math.random() * (right - left)) + left;\n const pivotNewIndex = partition(array, comparator, left, right, pivotIndex);\n if (sortWindowLeft < pivotNewIndex) {\n quickSortRange(array, comparator, left, pivotNewIndex - 1, sortWindowLeft, sortWindowRight);\n }\n if (pivotNewIndex < sortWindowRight) {\n quickSortRange(array, comparator, pivotNewIndex + 1, right, sortWindowLeft, sortWindowRight);\n }\n}\n\nexport function sortRange(\n array: number[], comparator: NumberComparator, leftBound: number, rightBound: number, sortWindowLeft: number,\n sortWindowRight: number): number[] {\n if (leftBound === 0 && rightBound === (array.length - 1) && sortWindowLeft === 0 && sortWindowRight >= rightBound) {\n array.sort(comparator);\n } else {\n quickSortRange(array, comparator, leftBound, rightBound, sortWindowLeft, sortWindowRight);\n }\n return array;\n}\nexport const binaryIndexOf = <T, S>(array: T[], value: S, comparator: (a: S, b: T) => number): number => {\n const index = lowerBound(array, value, comparator);\n return index < array.length && comparator(value, array[index]) === 0 ? index : -1;\n};\n\nfunction mergeOrIntersect<T>(\n array1: T[], array2: T[], comparator: (a: T, b: T) => number, mergeNotIntersect: boolean): T[] {\n const result = [];\n let i = 0;\n let j = 0;\n while (i < array1.length && j < array2.length) {\n const compareValue = comparator(array1[i], array2[j]);\n if (mergeNotIntersect || !compareValue) {\n result.push(compareValue <= 0 ? array1[i] : array2[j]);\n }\n if (compareValue <= 0) {\n i++;\n }\n if (compareValue >= 0) {\n j++;\n }\n }\n if (mergeNotIntersect) {\n while (i < array1.length) {\n result.push(array1[i++]);\n }\n while (j < array2.length) {\n result.push(array2[j++]);\n }\n }\n return result;\n}\n\nexport const intersectOrdered = <T>(array1: T[], array2: T[], comparator: (a: T, b: T) => number): T[] => {\n return mergeOrIntersect(array1, array2, comparator, false);\n};\n\nexport const mergeOrdered = <T>(array1: T[], array2: T[], comparator: (a: T, b: T) => number): T[] => {\n return mergeOrIntersect(array1, array2, comparator, true);\n};\n\nexport const DEFAULT_COMPARATOR = (a: string|number, b: string|number): -1|0|1 => {\n return a < b ? -1 : (a > b ? 1 : 0);\n};\n\n/**\n * Returns the index of the element closest to the needle that is equal to or\n * greater than it. Assumes that the provided array is sorted.\n *\n * If no element is found, the right bound is returned.\n *\n * Uses the provided comparator function to determine if two items are equal or\n * if one is greater than the other. If you are working with strings or\n * numbers, you can use ArrayUtilities.DEFAULT_COMPARATOR. Otherwise, you\n * should define one that takes the needle element and an element from the\n * array and returns a positive or negative number to indicate which is greater\n * than the other.\n *\n * When specified, |left| (inclusive) and |right| (exclusive) indices\n * define the search window.\n */\nexport function lowerBound<T>(\n array: Uint32Array|Int32Array, needle: T, comparator: (needle: T, b: number) => number, left?: number,\n right?: number): number;\nexport function lowerBound<S, T>(\n array: S[], needle: T, comparator: (needle: T, b: S) => number, left?: number, right?: number): number;\nexport function lowerBound<S, T>(\n array: readonly S[], needle: T, comparator: (needle: T, b: S) => number, left?: number, right?: number): number;\nexport function lowerBound<S, T, A extends S[]>(\n array: A, needle: T, comparator: (needle: T, b: S) => number, left?: number, right?: number): number {\n let l = left || 0;\n let r = right !== undefined ? right : array.length;\n while (l < r) {\n const m = (l + r) >> 1;\n if (comparator(needle, array[m]) > 0) {\n l = m + 1;\n } else {\n r = m;\n }\n }\n return r;\n}\n\n/**\n * Returns the index of the element closest to the needle that is greater than\n * it. Assumes that the provided array is sorted.\n *\n * If no element is found, the right bound is returned.\n *\n * Uses the provided comparator function to determine if two items are equal or\n * if one is greater than the other. If you are working with strings or\n * numbers, you can use ArrayUtilities.DEFAULT_COMPARATOR. Otherwise, you\n * should define one that takes the needle element and an element from the\n * array and returns a positive or negative number to indicate which is greater\n * than the other.\n *\n * When specified, |left| (inclusive) and |right| (exclusive) indices\n * define the search window.\n */\nexport function upperBound<T>(\n array: Uint32Array, needle: T, comparator: (needle: T, b: number) => number, left?: number, right?: number): number;\nexport function upperBound<S, T>(\n array: S[], needle: T, comparator: (needle: T, b: S) => number, left?: number, right?: number): number;\nexport function upperBound<S, T, A extends S[]>(\n array: A, needle: T, comparator: (needle: T, b: S) => number, left?: number, right?: number): number {\n let l = left || 0;\n let r = right !== undefined ? right : array.length;\n while (l < r) {\n const m = (l + r) >> 1;\n if (comparator(needle, array[m]) >= 0) {\n l = m + 1;\n } else {\n r = m;\n }\n }\n return r;\n}\n\nconst enum NearestSearchStart {\n BEGINNING = 'BEGINNING',\n END = 'END',\n}\n/**\n * Obtains the first or last item in the array that satisfies the predicate function.\n * So, for example, if the array were arr = [2, 4, 6, 8, 10], and you are looking for\n * the last item arr[i] such that arr[i] < 5 you would be returned 1, because\n * array[1] is 4, the last item in the array that satisfies the\n * predicate function.\n *\n * If instead you were looking for the first item in the same array that satisfies\n * arr[i] > 5 you would be returned 2 because array[2] = 6.\n *\n * Please note: this presupposes that the array is already ordered.\n */\nfunction nearestIndex<T>(\n arr: readonly T[], predicate: (arrayItem: T) => boolean, searchStart: NearestSearchStart): number|null {\n const searchFromEnd = searchStart === NearestSearchStart.END;\n if (arr.length === 0) {\n return null;\n }\n\n let left = 0;\n let right = arr.length - 1;\n let pivot = 0;\n let matchesPredicate = false;\n let moveToTheRight = false;\n let middle = 0;\n do {\n middle = left + (right - left) / 2;\n pivot = searchFromEnd ? Math.ceil(middle) : Math.floor(middle);\n matchesPredicate = predicate(arr[pivot]);\n moveToTheRight = matchesPredicate === searchFromEnd;\n if (moveToTheRight) {\n left = Math.min(right, pivot + (left === pivot ? 1 : 0));\n } else {\n right = Math.max(left, pivot + (right === pivot ? -1 : 0));\n }\n } while (right !== left);\n\n // Special-case: the indexed item doesn't pass the predicate. This\n // occurs when none of the items in the array are a match for the\n // predicate.\n if (!predicate(arr[left])) {\n return null;\n }\n return left;\n}\n\n/**\n * Obtains the first item in the array that satisfies the predicate function.\n * So, for example, if the array was arr = [2, 4, 6, 8, 10], and you are looking for\n * the first item arr[i] such that arr[i] > 5 you would be returned 2, because\n * array[2] is 6, the first item in the array that satisfies the\n * predicate function.\n *\n * Please note: this presupposes that the array is already ordered.\n */\nexport function nearestIndexFromBeginning<T>(arr: T[], predicate: (arrayItem: T) => boolean): number|null {\n return nearestIndex(arr, predicate, NearestSearchStart.BEGINNING);\n}\n\n/**\n * Obtains the last item in the array that satisfies the predicate function.\n * So, for example, if the array was arr = [2, 4, 6, 8, 10], and you are looking for\n * the last item arr[i] such that arr[i] < 5 you would be returned 1, because\n * arr[1] is 4, the last item in the array that satisfies the\n * predicate function.\n *\n * Please note: this presupposes that the array is already ordered.\n */\n\nexport function nearestIndexFromEnd<T>(arr: readonly T[], predicate: (arrayItem: T) => boolean): number|null {\n return nearestIndex(arr, predicate, NearestSearchStart.END);\n}\n\n// Type guard for ensuring that `arr` does not contain null or undefined\nexport function arrayDoesNotContainNullOrUndefined<T>(arr: (T|null|undefined)[]): arr is T[] {\n return !arr.includes(null) && !arr.includes(undefined);\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper type to introduce new branded types.
|
|
3
|
+
*
|
|
4
|
+
* `Base` is the underlying data type and `Tag` must be unique symbol/string.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* ```
|
|
8
|
+
* type LineNumber = Brand<number, "LineNumber">;
|
|
9
|
+
* type RawUrl = Brand<string, "RawUrl">;
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export type Brand<Base, Tag> = Base & {
|
|
13
|
+
_tag: Tag;
|
|
14
|
+
};
|
package/core/platform/brand.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": [],
|
|
4
|
-
"sourcesContent": [],
|
|
5
|
-
"mappings": "",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"brand.js","sourceRoot":"","sources":["../../../../../../front_end/core/platform/brand.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\n/**\n * Helper type to introduce new branded types.\n *\n * `Base` is the underlying data type and `Tag` must be unique symbol/string.\n *\n * Usage:\n * ```\n * type LineNumber = Brand<number, \"LineNumber\">;\n * type RawUrl = Brand<string, \"RawUrl\">;\n * ```\n */\nexport type Brand<Base, Tag> = Base&{_tag: Tag};\n"]}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
1
4
|
export const isValid = (date) => {
|
|
2
|
-
|
|
5
|
+
return !isNaN(date.getTime());
|
|
3
6
|
};
|
|
4
7
|
export const toISO8601Compact = (date) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
function leadZero(x) {
|
|
9
|
+
return (x > 9 ? '' : '0') + x;
|
|
10
|
+
}
|
|
11
|
+
return date.getFullYear() + leadZero(date.getMonth() + 1) + leadZero(date.getDate()) + 'T' +
|
|
12
|
+
leadZero(date.getHours()) + leadZero(date.getMinutes()) + leadZero(date.getSeconds());
|
|
9
13
|
};
|
|
10
|
-
//# sourceMappingURL=date-utilities.js.map
|
|
14
|
+
//# sourceMappingURL=date-utilities.js.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../../../front_end/core/platform/date-utilities.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) 2020 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nexport const isValid = (date: Date): boolean => {\n return !isNaN(date.getTime());\n};\n\nexport const toISO8601Compact = (date: Date): string => {\n function leadZero(x: number): string {\n return (x > 9 ? '' : '0') + x;\n }\n return date.getFullYear() + leadZero(date.getMonth() + 1) + leadZero(date.getDate()) + 'T' +\n leadZero(date.getHours()) + leadZero(date.getMinutes()) + leadZero(date.getSeconds());\n};\n"],
|
|
5
|
-
"mappings": "AAIO,aAAM,UAAU,CAAC,SAAwB;AAC9C,SAAO,CAAC,MAAM,KAAK;AAAA;AAGd,aAAM,mBAAmB,CAAC,SAAuB;AACtD,oBAAkB,GAAmB;AACnC,WAAQ,KAAI,IAAI,KAAK,OAAO;AAAA;AAE9B,SAAO,KAAK,gBAAgB,SAAS,KAAK,aAAa,KAAK,SAAS,KAAK,aAAa,MACnF,SAAS,KAAK,cAAc,SAAS,KAAK,gBAAgB,SAAS,KAAK;AAAA;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"date-utilities.js","sourceRoot":"","sources":["../../../../../../front_end/core/platform/date-utilities.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,yEAAyE;AACzE,6BAA6B;AAE7B,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAU,EAAW,EAAE;IAC7C,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAU,EAAE;IACrD,SAAS,QAAQ,CAAC,CAAS;QACzB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,IAAI,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,GAAG;QACtF,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;AAC5F,CAAC,CAAC","sourcesContent":["// Copyright (c) 2020 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nexport const isValid = (date: Date): boolean => {\n return !isNaN(date.getTime());\n};\n\nexport const toISO8601Compact = (date: Date): string => {\n function leadZero(x: number): string {\n return (x > 9 ? '' : '0') + x;\n }\n return date.getFullYear() + leadZero(date.getMonth() + 1) + leadZero(date.getDate()) + 'T' +\n leadZero(date.getHours()) + leadZero(date.getMinutes()) + leadZero(date.getSeconds());\n};\n"]}
|
|
@@ -2,5 +2,7 @@
|
|
|
2
2
|
* `document.activeElement` will not enter shadow roots to find the element
|
|
3
3
|
* that has focus; use this method if you need to traverse through any shadow
|
|
4
4
|
* roots to find the actual, specific focused element.
|
|
5
|
-
*/
|
|
5
|
+
*/
|
|
6
6
|
export declare function deepActiveElement(doc: Document): Element | null;
|
|
7
|
+
export declare function getEnclosingShadowRootForNode(node: Node): Node | null;
|
|
8
|
+
export declare function rangeOfWord(rootNode: Node, offset: number, stopCharacters: string, stayWithinNode: Node, direction?: string): Range;
|