@cloudcare/browser-rum 3.3.23 → 3.3.24
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/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/domain/deflate/deflateWorker.js +1 -1
- package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/esm/boot/buildEnv.js +2 -5
- package/esm/boot/buildEnv.js.map +1 -1
- package/esm/boot/disabledRumPublicApi.js +2 -35
- package/esm/boot/disabledRumPublicApi.js.map +1 -1
- package/esm/boot/perStartRum.js +2 -260
- package/esm/boot/perStartRum.js.map +1 -1
- package/esm/boot/recorderApi.js +2 -338
- package/esm/boot/recorderApi.js.map +1 -1
- package/esm/boot/recorderApiStub.js +2 -21
- package/esm/boot/recorderApiStub.js.map +1 -1
- package/esm/boot/rum.entry.js +2 -13
- package/esm/boot/rum.entry.js.map +1 -1
- package/esm/boot/rum.js +2 -184
- package/esm/boot/rum.js.map +1 -1
- package/esm/boot/rum.slim.entry.js +2 -7
- package/esm/boot/rum.slim.entry.js.map +1 -1
- package/esm/boot/rumEntryFactory.js +2 -18
- package/esm/boot/rumEntryFactory.js.map +1 -1
- package/esm/boot/rumPublicApi.js +2 -344
- package/esm/boot/rumPublicApi.js.map +1 -1
- package/esm/boot/rumRecorderApiStub.js +2 -13
- package/esm/boot/rumRecorderApiStub.js.map +1 -1
- package/esm/boot/rumSlimConfiguration.js +2 -10
- package/esm/boot/rumSlimConfiguration.js.map +1 -1
- package/esm/boot/sessionReplayPublicApi.js +2 -43
- package/esm/boot/sessionReplayPublicApi.js.map +1 -1
- package/esm/boot/startRecording.js +2 -444
- package/esm/boot/startRecording.js.map +1 -1
- package/esm/constants.js +2 -28
- package/esm/constants.js.map +1 -1
- package/esm/domain/assembly.js +2 -213
- package/esm/domain/assembly.js.map +1 -1
- package/esm/domain/configuration.js +2 -323
- package/esm/domain/configuration.js.map +1 -1
- package/esm/domain/contexts/commonContext.js +2 -8
- package/esm/domain/contexts/commonContext.js.map +1 -1
- package/esm/domain/contexts/displayContext.js +2 -16
- package/esm/domain/contexts/displayContext.js.map +1 -1
- package/esm/domain/contexts/foregroundContexts.js +2 -103
- package/esm/domain/contexts/foregroundContexts.js.map +1 -1
- package/esm/domain/contexts/internalContext.js +2 -41
- package/esm/domain/contexts/internalContext.js.map +1 -1
- package/esm/domain/contexts/pageStateHistory.js +2 -104
- package/esm/domain/contexts/pageStateHistory.js.map +1 -1
- package/esm/domain/contexts/urlContexts.js +2 -85
- package/esm/domain/contexts/urlContexts.js.map +1 -1
- package/esm/domain/contexts/viewContexts.js +2 -45
- package/esm/domain/contexts/viewContexts.js.map +1 -1
- package/esm/domain/deflate/deflateEncoder.js +2 -592
- package/esm/domain/deflate/deflateEncoder.js.map +1 -1
- package/esm/domain/deflate/deflateWorker.js +2 -225
- package/esm/domain/deflate/deflateWorker.js.map +1 -1
- package/esm/domain/deflate/index.js +2 -3
- package/esm/domain/deflate/index.js.map +1 -1
- package/esm/domain/domMutationObservable.js +2 -62
- package/esm/domain/domMutationObservable.js.map +1 -1
- package/esm/domain/encoderStreamId.js +2 -6
- package/esm/domain/encoderStreamId.js.map +1 -1
- package/esm/domain/firstInputPolyfill.js +2 -77
- package/esm/domain/firstInputPolyfill.js.map +1 -1
- package/esm/domain/initViewportObservable.js +2 -36
- package/esm/domain/initViewportObservable.js.map +1 -1
- package/esm/domain/locationChangeObservable.js +2 -65
- package/esm/domain/locationChangeObservable.js.map +1 -1
- package/esm/domain/performanceObservable.js +2 -116
- package/esm/domain/performanceObservable.js.map +1 -1
- package/esm/domain/performanceUtils.js +2 -45
- package/esm/domain/performanceUtils.js.map +1 -1
- package/esm/domain/plugins.js +2 -59
- package/esm/domain/plugins.js.map +1 -1
- package/esm/domain/privacy.js +2 -266
- package/esm/domain/privacy.js.map +1 -1
- package/esm/domain/replay/record/canvasAutoSnapshot.js +2 -9
- package/esm/domain/replay/record/canvasAutoSnapshot.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandCapture.js +2 -1275
- package/esm/domain/replay/record/canvasCommandCapture.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandObserver.js +2 -1207
- package/esm/domain/replay/record/canvasCommandObserver.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandSerializeArgs.js +2 -111
- package/esm/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
- package/esm/domain/replay/record/canvasContext.js +2 -50
- package/esm/domain/replay/record/canvasContext.js.map +1 -1
- package/esm/domain/replay/record/canvasContinuousScheduler.js +2 -378
- package/esm/domain/replay/record/canvasContinuousScheduler.js.map +1 -1
- package/esm/domain/replay/record/canvasEncodeBridge.js +2 -692
- package/esm/domain/replay/record/canvasEncodeBridge.js.map +1 -1
- package/esm/domain/replay/record/canvasEncodeWorker.js +2 -164
- package/esm/domain/replay/record/canvasEncodeWorker.js.map +1 -1
- package/esm/domain/replay/record/canvasFrameSignature.js +2 -75
- package/esm/domain/replay/record/canvasFrameSignature.js.map +1 -1
- package/esm/domain/replay/record/canvasMutationRecord.js +2 -26
- package/esm/domain/replay/record/canvasMutationRecord.js.map +1 -1
- package/esm/domain/replay/record/canvasObserver.js +2 -420
- package/esm/domain/replay/record/canvasObserver.js.map +1 -1
- package/esm/domain/replay/record/canvasSerializeArgs.js +2 -101
- package/esm/domain/replay/record/canvasSerializeArgs.js.map +1 -1
- package/esm/domain/replay/record/canvasWebGLPluginHost.js +2 -26
- package/esm/domain/replay/record/canvasWebGLPluginHost.js.map +1 -1
- package/esm/domain/replay/record/elementsScrollPositions.js +2 -23
- package/esm/domain/replay/record/elementsScrollPositions.js.map +1 -1
- package/esm/domain/replay/record/index.js +2 -4
- package/esm/domain/replay/record/index.js.map +1 -1
- package/esm/domain/replay/record/mutationBatch.js +2 -562
- package/esm/domain/replay/record/mutationBatch.js.map +1 -1
- package/esm/domain/replay/record/mutationObserver.js +2 -2332
- package/esm/domain/replay/record/mutationObserver.js.map +1 -1
- package/esm/domain/replay/record/mutationResourceBudget.js +2 -137
- package/esm/domain/replay/record/mutationResourceBudget.js.map +1 -1
- package/esm/domain/replay/record/observers.js +2 -624
- package/esm/domain/replay/record/observers.js.map +1 -1
- package/esm/domain/replay/record/privacy.js +2 -1
- package/esm/domain/replay/record/privacy.js.map +1 -1
- package/esm/domain/replay/record/record.js +2 -3511
- package/esm/domain/replay/record/record.js.map +1 -1
- package/esm/domain/replay/record/serializationUtils.js +2 -677
- package/esm/domain/replay/record/serializationUtils.js.map +1 -1
- package/esm/domain/replay/record/serialize.js +2 -735
- package/esm/domain/replay/record/serialize.js.map +1 -1
- package/esm/domain/replay/record/shadowRootsController.js +2 -902
- package/esm/domain/replay/record/shadowRootsController.js.map +1 -1
- package/esm/domain/replay/record/utils.js +2 -36
- package/esm/domain/replay/record/utils.js.map +1 -1
- package/esm/domain/replay/record/viewports.js +2 -58
- package/esm/domain/replay/record/viewports.js.map +1 -1
- package/esm/domain/replay/replayStats.js +2 -59
- package/esm/domain/replay/replayStats.js.map +1 -1
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js +2 -31
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
- package/esm/domain/replay/segmentCollection/index.js +2 -3
- package/esm/domain/replay/segmentCollection/index.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segment.js +2 -415
- package/esm/domain/replay/segmentCollection/segment.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segmentCollection.js +2 -1114
- package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/esm/domain/replay/startRecordBridge.js +2 -13
- package/esm/domain/replay/startRecordBridge.js.map +1 -1
- package/esm/domain/replay/timeAnchor.js +2 -20
- package/esm/domain/replay/timeAnchor.js.map +1 -1
- package/esm/domain/requestCollection.js +2 -121
- package/esm/domain/requestCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +2 -83
- package/esm/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/clickChain.js +2 -62
- package/esm/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js +2 -67
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +2 -279
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +2 -233
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/interactionSelectorCache.js +2 -21
- package/esm/domain/rumEventsCollection/actions/interactionSelectorCache.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +2 -67
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +2 -263
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/errorCollection.js +2 -93
- package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/trackConsoleError.js +2 -12
- package/esm/domain/rumEventsCollection/error/trackConsoleError.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/trackReportError.js +2 -19
- package/esm/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
- package/esm/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js +2 -55
- package/esm/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +2 -38
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +2 -69
- package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +2 -294
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js +2 -232
- package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceUtils.js +2 -218
- package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +2 -19
- package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js +2 -191
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/interactionCountPolyfill.js +2 -47
- package/esm/domain/rumEventsCollection/view/interactionCountPolyfill.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js +2 -42
- package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +2 -117
- package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -20
- package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +2 -49
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstInput.js +2 -41
- package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +2 -44
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +2 -153
- package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +2 -54
- package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js +2 -50
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js +2 -73
- package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js +2 -84
- package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackSoftNavigationMetrics.js +2 -38
- package/esm/domain/rumEventsCollection/view/trackSoftNavigationMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +2 -15
- package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js +2 -418
- package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/viewCollection.js +2 -127
- package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
- package/esm/domain/rumSessionManager.js +2 -208
- package/esm/domain/rumSessionManager.js.map +1 -1
- package/esm/domain/tracing/ddtraceTracer.js +2 -40
- package/esm/domain/tracing/ddtraceTracer.js.map +1 -1
- package/esm/domain/tracing/getDocumentTraceId.js +2 -69
- package/esm/domain/tracing/getDocumentTraceId.js.map +1 -1
- package/esm/domain/tracing/jaegerTracer.js +2 -42
- package/esm/domain/tracing/jaegerTracer.js.map +1 -1
- package/esm/domain/tracing/sampler.js +2 -61
- package/esm/domain/tracing/sampler.js.map +1 -1
- package/esm/domain/tracing/skywalkingTracer.js +2 -90
- package/esm/domain/tracing/skywalkingTracer.js.map +1 -1
- package/esm/domain/tracing/traceIdentifier.js +2 -57
- package/esm/domain/tracing/traceIdentifier.js.map +1 -1
- package/esm/domain/tracing/tracer.js +2 -128
- package/esm/domain/tracing/tracer.js.map +1 -1
- package/esm/domain/tracing/w3cTraceParentTracer.js +2 -69
- package/esm/domain/tracing/w3cTraceParentTracer.js.map +1 -1
- package/esm/domain/tracing/zipkinMultiTracer.js +2 -42
- package/esm/domain/tracing/zipkinMultiTracer.js.map +1 -1
- package/esm/domain/tracing/zipkinSingleTracer.js +2 -41
- package/esm/domain/tracing/zipkinSingleTracer.js.map +1 -1
- package/esm/domain/trackEventCounts.js +2 -49
- package/esm/domain/trackEventCounts.js.map +1 -1
- package/esm/domain/usr/index.js +2 -38
- package/esm/domain/usr/index.js.map +1 -1
- package/esm/domain/visitorId/index.js +2 -406
- package/esm/domain/visitorId/index.js.map +1 -1
- package/esm/domain/waitPageActivityEnd.js +2 -142
- package/esm/domain/waitPageActivityEnd.js.map +1 -1
- package/esm/index.js +2 -4
- package/esm/index.js.map +1 -1
- package/esm/transport/startRumBatch.js +2 -74
- package/esm/transport/startRumBatch.js.map +1 -1
- package/esm/transport/startRumEventBridge.js +2 -9
- package/esm/transport/startRumEventBridge.js.map +1 -1
- package/esm/types/index.js +2 -1
- package/esm/types/index.js.map +1 -1
- package/esm/types/sessionReplayConstants.js +2 -46
- package/esm/types/sessionReplayConstants.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,562 +1,2 @@
|
|
|
1
|
-
import { noop, throttle, requestIdleCallback } from '@cloudcare/browser-core';
|
|
2
|
-
|
|
3
|
-
var MUTATION_PROCESS_MAX_DELAY = 120;
|
|
4
|
-
export var MUTATION_PROCESS_MIN_DELAY = 48;
|
|
5
|
-
export var MAX_PENDING_MUTATION_RECORDS = 256;
|
|
6
|
-
export var MAX_PENDING_MUTATION_NODES = 1000;
|
|
7
|
-
export var MAX_PENDING_MUTATION_APPROX_BYTES = 256 * 1024;
|
|
8
|
-
export var MUTATION_CHUNK_MAX_RECORDS = 64;
|
|
9
|
-
// Keep add-heavy normalization below the operation grace used by
|
|
10
|
-
// mutationObserver. A wider pending batch is preserved as one transaction, but
|
|
11
|
-
// normalized over several bounded tasks so a short GC/renderer interruption
|
|
12
|
-
// cannot turn unpublished additions into mandatory FullSnapshot recovery.
|
|
13
|
-
export var MUTATION_CHUNK_MAX_NODES = 32;
|
|
14
|
-
export var MUTATION_CHUNK_MAX_APPROX_BYTES = 64 * 1024;
|
|
15
|
-
export var MAX_QUEUED_MUTATION_RECORDS = 4096;
|
|
16
|
-
export var MAX_QUEUED_MUTATION_NODES = 16384;
|
|
17
|
-
export var MAX_QUEUED_MUTATION_APPROX_BYTES = 8 * 1024 * 1024;
|
|
18
|
-
var MUTATION_FLUSH_BUDGET_MS = 4;
|
|
19
|
-
export function createMutationBatch(processMutationBatch, onOverflow, mutationResourceBudget) {
|
|
20
|
-
var cancelScheduledFlush = noop;
|
|
21
|
-
var continuationTimeout;
|
|
22
|
-
var pendingMutations = [];
|
|
23
|
-
var pendingMutationNodes = 0;
|
|
24
|
-
var pendingMutationApproxBytes = 0;
|
|
25
|
-
var pendingMutationDirectNodes = 0;
|
|
26
|
-
var pendingNativeCallbackCount = 0;
|
|
27
|
-
var pendingMutationReservations = [];
|
|
28
|
-
var workQueue = [];
|
|
29
|
-
var queuedMutationRecords = 0;
|
|
30
|
-
var queuedMutationNodes = 0;
|
|
31
|
-
var queuedMutationApproxBytes = 0;
|
|
32
|
-
var stopped = false;
|
|
33
|
-
var coalescedTextReplacementByRemovedNode = new WeakMap();
|
|
34
|
-
var throttled = throttle(flush, MUTATION_PROCESS_MIN_DELAY, {
|
|
35
|
-
leading: false
|
|
36
|
-
});
|
|
37
|
-
function scheduleInitialFlush() {
|
|
38
|
-
if (cancelScheduledFlush !== noop) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
cancelScheduledFlush = requestIdleCallback(throttled.throttled, {
|
|
42
|
-
timeout: MUTATION_PROCESS_MAX_DELAY
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function scheduleContinuation() {
|
|
46
|
-
if (continuationTimeout !== undefined || stopped || !workQueue.length) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
continuationTimeout = setTimeout(function () {
|
|
50
|
-
continuationTimeout = undefined;
|
|
51
|
-
drainOneChunk();
|
|
52
|
-
scheduleContinuation();
|
|
53
|
-
}, 0);
|
|
54
|
-
}
|
|
55
|
-
function enqueuePending() {
|
|
56
|
-
if (!pendingMutations.length) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
var work = {
|
|
60
|
-
$rMutations: pendingMutations,
|
|
61
|
-
$rMeasurement: {
|
|
62
|
-
mutationRecordCount: pendingMutations.length,
|
|
63
|
-
nodeCount: pendingMutationNodes,
|
|
64
|
-
approxBytes: pendingMutationApproxBytes
|
|
65
|
-
},
|
|
66
|
-
directNodeCount: pendingMutationDirectNodes,
|
|
67
|
-
nativeCallbackCount: pendingNativeCallbackCount,
|
|
68
|
-
reservations: pendingMutationReservations
|
|
69
|
-
};
|
|
70
|
-
enqueueMutationWork(work);
|
|
71
|
-
pendingMutations = [];
|
|
72
|
-
pendingMutationNodes = 0;
|
|
73
|
-
pendingMutationApproxBytes = 0;
|
|
74
|
-
pendingMutationDirectNodes = 0;
|
|
75
|
-
pendingNativeCallbackCount = 0;
|
|
76
|
-
pendingMutationReservations = [];
|
|
77
|
-
}
|
|
78
|
-
function enqueueMutationWork(work) {
|
|
79
|
-
work.$rTextReplacementByRemovedNode = coalescedTextReplacementByRemovedNode;
|
|
80
|
-
if (shouldChunkMutationWork(work)) {
|
|
81
|
-
initializeChunkedWork(work);
|
|
82
|
-
}
|
|
83
|
-
enqueueWork(work);
|
|
84
|
-
}
|
|
85
|
-
function enqueueWork(work) {
|
|
86
|
-
workQueue.push(work);
|
|
87
|
-
queuedMutationRecords += work.$rMeasurement.mutationRecordCount;
|
|
88
|
-
queuedMutationNodes += work.$rMeasurement.nodeCount;
|
|
89
|
-
queuedMutationApproxBytes += work.$rMeasurement.approxBytes;
|
|
90
|
-
}
|
|
91
|
-
function releaseWork(work) {
|
|
92
|
-
queuedMutationRecords -= work.$rMeasurement.mutationRecordCount;
|
|
93
|
-
queuedMutationNodes -= work.$rMeasurement.nodeCount;
|
|
94
|
-
queuedMutationApproxBytes -= work.$rMeasurement.approxBytes;
|
|
95
|
-
releaseReservations(work.reservations);
|
|
96
|
-
if (!workQueue.length && !pendingMutations.length) {
|
|
97
|
-
coalescedTextReplacementByRemovedNode = new WeakMap();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function flush() {
|
|
101
|
-
cancelScheduledFlush();
|
|
102
|
-
cancelScheduledFlush = noop;
|
|
103
|
-
throttled.cancel();
|
|
104
|
-
enqueuePending();
|
|
105
|
-
var deadline = getCurrentTime() + MUTATION_FLUSH_BUDGET_MS;
|
|
106
|
-
var succeeded = true;
|
|
107
|
-
do {
|
|
108
|
-
if (!drainOneChunk()) {
|
|
109
|
-
succeeded = false;
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
} while (workQueue.length && getCurrentTime() < deadline);
|
|
113
|
-
if (!succeeded) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
if (workQueue.length) {
|
|
117
|
-
scheduleContinuation();
|
|
118
|
-
return 'pending';
|
|
119
|
-
}
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
function drainOneChunk() {
|
|
123
|
-
if (stopped || !workQueue.length) {
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
var work = workQueue[0];
|
|
127
|
-
if (work.recordIndex === undefined) {
|
|
128
|
-
workQueue.shift();
|
|
129
|
-
releaseWork(work);
|
|
130
|
-
var batchSucceeded = process(work.$rMutations, createBatchContext(work));
|
|
131
|
-
if (!batchSucceeded) {
|
|
132
|
-
reset();
|
|
133
|
-
}
|
|
134
|
-
return batchSucceeded;
|
|
135
|
-
}
|
|
136
|
-
var chunk = takeChunk(work);
|
|
137
|
-
var isLast = work.$rTransaction.$rPureAdd ? work.recordIndex < 0 : work.recordIndex >= work.$rMutations.length;
|
|
138
|
-
var succeeded = process(chunk, createBatchContext(work, work.$rTransaction, isLast));
|
|
139
|
-
if (workQueue[0] !== work) {
|
|
140
|
-
// Recovery callbacks may synchronously reset the whole batch. The old
|
|
141
|
-
// work has already been released in that case; do not shift/release it
|
|
142
|
-
// a second time or let a stale successful return escape.
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
if (!succeeded || isLast) {
|
|
146
|
-
workQueue.shift();
|
|
147
|
-
releaseWork(work);
|
|
148
|
-
}
|
|
149
|
-
if (!succeeded) {
|
|
150
|
-
// Recovery supersedes the whole queued generation. Do not let a later
|
|
151
|
-
// callback escape after the failed atomic transaction.
|
|
152
|
-
reset();
|
|
153
|
-
}
|
|
154
|
-
return succeeded;
|
|
155
|
-
}
|
|
156
|
-
function process(mutations, batchContext) {
|
|
157
|
-
try {
|
|
158
|
-
var result = processMutationBatch(mutations, batchContext);
|
|
159
|
-
return batchContext.transaction ? result === true : result !== false;
|
|
160
|
-
} catch (_) {
|
|
161
|
-
if (onOverflow) {
|
|
162
|
-
onOverflow({
|
|
163
|
-
reason: 'mutation_processing_error',
|
|
164
|
-
mutationRecordCount: mutations.length
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function reset() {
|
|
171
|
-
cancelScheduledFlush();
|
|
172
|
-
cancelScheduledFlush = noop;
|
|
173
|
-
throttled.cancel();
|
|
174
|
-
if (continuationTimeout !== undefined) {
|
|
175
|
-
clearTimeout(continuationTimeout);
|
|
176
|
-
continuationTimeout = undefined;
|
|
177
|
-
}
|
|
178
|
-
releaseReservations(pendingMutationReservations);
|
|
179
|
-
workQueue.forEach(function (work) {
|
|
180
|
-
releaseReservations(work.reservations);
|
|
181
|
-
});
|
|
182
|
-
pendingMutations = [];
|
|
183
|
-
pendingMutationNodes = 0;
|
|
184
|
-
pendingMutationApproxBytes = 0;
|
|
185
|
-
pendingMutationDirectNodes = 0;
|
|
186
|
-
pendingNativeCallbackCount = 0;
|
|
187
|
-
pendingMutationReservations = [];
|
|
188
|
-
workQueue = [];
|
|
189
|
-
queuedMutationRecords = 0;
|
|
190
|
-
queuedMutationNodes = 0;
|
|
191
|
-
queuedMutationApproxBytes = 0;
|
|
192
|
-
coalescedTextReplacementByRemovedNode = new WeakMap();
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
addMutations: function addMutations(mutations) {
|
|
196
|
-
if (!mutations.length || stopped) {
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
var queuedMeasurement = measureMutationsUntilLimit(mutations, MAX_QUEUED_MUTATION_NODES - queuedMutationNodes - pendingMutationNodes, MAX_QUEUED_MUTATION_APPROX_BYTES - queuedMutationApproxBytes - pendingMutationApproxBytes);
|
|
200
|
-
if (queuedMutationRecords + pendingMutations.length + mutations.length > MAX_QUEUED_MUTATION_RECORDS || queuedMutationNodes + pendingMutationNodes + queuedMeasurement.nodeCount > MAX_QUEUED_MUTATION_NODES || queuedMutationApproxBytes + pendingMutationApproxBytes + queuedMeasurement.approxBytes > MAX_QUEUED_MUTATION_APPROX_BYTES) {
|
|
201
|
-
reset();
|
|
202
|
-
if (onOverflow) {
|
|
203
|
-
onOverflow({
|
|
204
|
-
reason: 'raw_mutation_queue_watermark',
|
|
205
|
-
mutationRecordCount: mutations.length,
|
|
206
|
-
mutationNodeCount: queuedMeasurement.nodeCount,
|
|
207
|
-
mutationApproxBytes: queuedMeasurement.approxBytes
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
var mutationResourceReservation;
|
|
213
|
-
if (mutationResourceBudget) {
|
|
214
|
-
mutationResourceReservation = mutationResourceBudget.reserve(MUTATION_RESOURCE_RAW, {
|
|
215
|
-
recordCount: mutations.length,
|
|
216
|
-
nodeCount: queuedMeasurement.nodeCount,
|
|
217
|
-
approxBytes: queuedMeasurement.approxBytes
|
|
218
|
-
});
|
|
219
|
-
if (!mutationResourceReservation) {
|
|
220
|
-
reset();
|
|
221
|
-
if (onOverflow) {
|
|
222
|
-
onOverflow({
|
|
223
|
-
reason: 'aggregate_raw_mutation_watermark',
|
|
224
|
-
mutationRecordCount: mutations.length,
|
|
225
|
-
mutationNodeCount: queuedMeasurement.nodeCount,
|
|
226
|
-
mutationApproxBytes: queuedMeasurement.approxBytes
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
var directNodeCount = countDirectMutationNodes(mutations);
|
|
233
|
-
var canStorePending = !workQueue.length && (!pendingMutations.length || canMergePendingCallback(mutations.length, queuedMeasurement, directNodeCount));
|
|
234
|
-
if (canStorePending) {
|
|
235
|
-
if (!pendingMutations.length) {
|
|
236
|
-
scheduleInitialFlush();
|
|
237
|
-
}
|
|
238
|
-
Array.prototype.push.apply(pendingMutations, mutations);
|
|
239
|
-
if (mutationResourceReservation) {
|
|
240
|
-
pendingMutationReservations.push(mutationResourceReservation);
|
|
241
|
-
}
|
|
242
|
-
pendingMutationNodes += queuedMeasurement.nodeCount;
|
|
243
|
-
pendingMutationApproxBytes += queuedMeasurement.approxBytes;
|
|
244
|
-
pendingMutationDirectNodes += directNodeCount;
|
|
245
|
-
pendingNativeCallbackCount += 1;
|
|
246
|
-
} else {
|
|
247
|
-
enqueuePending();
|
|
248
|
-
enqueueMutationWork({
|
|
249
|
-
$rMutations: mutations,
|
|
250
|
-
$rMeasurement: {
|
|
251
|
-
mutationRecordCount: mutations.length,
|
|
252
|
-
nodeCount: queuedMeasurement.nodeCount,
|
|
253
|
-
approxBytes: queuedMeasurement.approxBytes
|
|
254
|
-
},
|
|
255
|
-
directNodeCount: directNodeCount,
|
|
256
|
-
nativeCallbackCount: 1,
|
|
257
|
-
reservations: mutationResourceReservation ? [mutationResourceReservation] : []
|
|
258
|
-
});
|
|
259
|
-
scheduleContinuation();
|
|
260
|
-
}
|
|
261
|
-
return true;
|
|
262
|
-
},
|
|
263
|
-
flush: flush,
|
|
264
|
-
reset: reset,
|
|
265
|
-
hasPending: function hasPending() {
|
|
266
|
-
return Boolean(pendingMutations.length || workQueue.length);
|
|
267
|
-
},
|
|
268
|
-
stop: function stop() {
|
|
269
|
-
stopped = true;
|
|
270
|
-
reset();
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
function canMergePendingCallback(mutationRecordCount, measurement, directNodeCount) {
|
|
274
|
-
return pendingMutationDirectNodes + directNodeCount <= MUTATION_CHUNK_MAX_NODES && pendingMutations.length + mutationRecordCount <= MAX_PENDING_MUTATION_RECORDS && pendingMutationNodes + measurement.nodeCount <= MAX_PENDING_MUTATION_NODES && pendingMutationApproxBytes + measurement.approxBytes <= MAX_PENDING_MUTATION_APPROX_BYTES;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
function initializeChunkedWork(work) {
|
|
278
|
-
var isPureAdd = work.nativeCallbackCount === 1 && isReverseChunkableSiblingAddWork(work.$rMutations);
|
|
279
|
-
work.$rTransaction = {
|
|
280
|
-
$rPureAdd: isPureAdd
|
|
281
|
-
};
|
|
282
|
-
work.recordIndex = isPureAdd ? work.$rMutations.length - 1 : 0;
|
|
283
|
-
work.addedIndex = isPureAdd ? getNodeListLength(work.$rMutations[work.recordIndex].addedNodes) : 0;
|
|
284
|
-
work.removedIndex = 0;
|
|
285
|
-
}
|
|
286
|
-
function createBatchContext(work, transaction, isLast) {
|
|
287
|
-
return {
|
|
288
|
-
transaction: transaction,
|
|
289
|
-
isLast: isLast,
|
|
290
|
-
$rTextReplacementByRemovedNode: work.$rTextReplacementByRemovedNode
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
function hasStructuralRemoval(mutations) {
|
|
294
|
-
for (var index = 0; index < mutations.length; index += 1) {
|
|
295
|
-
if (mutations[index].type === 'childList' && getNodeListLength(mutations[index].removedNodes)) {
|
|
296
|
-
return true;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return false;
|
|
300
|
-
}
|
|
301
|
-
function shouldChunkMutationWork(work) {
|
|
302
|
-
return work.nativeCallbackCount === 1 && work.directNodeCount >= MUTATION_CHUNK_MAX_NODES && !hasStructuralRemoval(work.$rMutations) || work.$rMeasurement.mutationRecordCount > MAX_PENDING_MUTATION_RECORDS || work.$rMeasurement.nodeCount > MAX_PENDING_MUTATION_NODES || work.$rMeasurement.approxBytes > MAX_PENDING_MUTATION_APPROX_BYTES;
|
|
303
|
-
}
|
|
304
|
-
function isReverseChunkableSiblingAddWork(mutations) {
|
|
305
|
-
var hasAdd = false;
|
|
306
|
-
var target;
|
|
307
|
-
var addedNodeSet = new Set();
|
|
308
|
-
var previousAddedNode;
|
|
309
|
-
for (var index = 0; index < mutations.length; index += 1) {
|
|
310
|
-
var mutation = mutations[index];
|
|
311
|
-
if (mutation.type !== 'childList' || getNodeListLength(mutation.removedNodes)) {
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
314
|
-
if (target === undefined) {
|
|
315
|
-
target = mutation.target;
|
|
316
|
-
} else if (mutation.target !== target) {
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
for (var addedIndex = 0; addedIndex < getNodeListLength(mutation.addedNodes); addedIndex += 1) {
|
|
320
|
-
var addedNode = mutation.addedNodes[addedIndex];
|
|
321
|
-
if (!target || addedNodeSet.has(addedNode) || addedNode.parentNode !== target || previousAddedNode && !isFollowingSibling(previousAddedNode, addedNode)) {
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
addedNodeSet.add(addedNode);
|
|
325
|
-
previousAddedNode = addedNode;
|
|
326
|
-
hasAdd = true;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
return hasAdd;
|
|
330
|
-
}
|
|
331
|
-
function isFollowingSibling(previousNode, node) {
|
|
332
|
-
if (typeof previousNode.compareDocumentPosition !== 'function') {
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
/* eslint-disable no-bitwise */
|
|
336
|
-
return Boolean(previousNode.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING);
|
|
337
|
-
/* eslint-enable no-bitwise */
|
|
338
|
-
}
|
|
339
|
-
function countDirectMutationNodes(mutations) {
|
|
340
|
-
var nodeCount = 0;
|
|
341
|
-
for (var index = 0; index < mutations.length; index += 1) {
|
|
342
|
-
var mutation = mutations[index];
|
|
343
|
-
if (mutation.type === 'childList') {
|
|
344
|
-
nodeCount += getNodeListLength(mutation.addedNodes) + getNodeListLength(mutation.removedNodes);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return nodeCount;
|
|
348
|
-
}
|
|
349
|
-
function releaseReservations(reservations) {
|
|
350
|
-
if (!reservations) {
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
reservations.forEach(function (release) {
|
|
354
|
-
release();
|
|
355
|
-
});
|
|
356
|
-
reservations.length = 0;
|
|
357
|
-
}
|
|
358
|
-
function takeChunk(work) {
|
|
359
|
-
if (work.$rTransaction.$rPureAdd) {
|
|
360
|
-
return takePureAddChunk(work);
|
|
361
|
-
}
|
|
362
|
-
var chunk = [];
|
|
363
|
-
var nodeCount = 0;
|
|
364
|
-
var approxBytes = 0;
|
|
365
|
-
while (work.recordIndex < work.$rMutations.length && chunk.length < MUTATION_CHUNK_MAX_RECORDS) {
|
|
366
|
-
var mutation = work.$rMutations[work.recordIndex];
|
|
367
|
-
var synthetic = mutation;
|
|
368
|
-
var isChildList = mutation.type === 'childList';
|
|
369
|
-
var nextAddedIndex = work.addedIndex;
|
|
370
|
-
var nextRemovedIndex = work.removedIndex;
|
|
371
|
-
var completesChildList = false;
|
|
372
|
-
if (mutation.type === 'childList') {
|
|
373
|
-
var addedNodeCount = getNodeListLength(mutation.addedNodes);
|
|
374
|
-
var removedNodeCount = getNodeListLength(mutation.removedNodes);
|
|
375
|
-
var keepStructuralMutationWhole = removedNodeCount > 0 && addedNodeCount + removedNodeCount < MAX_PENDING_MUTATION_NODES;
|
|
376
|
-
if (keepStructuralMutationWhole) {
|
|
377
|
-
var structuralMeasurement = measureMutation(mutation);
|
|
378
|
-
if (chunk.length && (nodeCount + structuralMeasurement.nodeCount > MUTATION_CHUNK_MAX_NODES || approxBytes + structuralMeasurement.approxBytes > MUTATION_CHUNK_MAX_APPROX_BYTES)) {
|
|
379
|
-
// A remove/add pair is one replay-tree transition. If it cannot fit
|
|
380
|
-
// at the tail of this chunk, move the complete native record to the
|
|
381
|
-
// next chunk instead of splitting the two structural sides.
|
|
382
|
-
break;
|
|
383
|
-
}
|
|
384
|
-
synthetic = {
|
|
385
|
-
type: 'childList',
|
|
386
|
-
target: mutation.target,
|
|
387
|
-
addedNodes: Array.prototype.slice.call(mutation.addedNodes),
|
|
388
|
-
removedNodes: Array.prototype.slice.call(mutation.removedNodes),
|
|
389
|
-
previousSibling: mutation.previousSibling,
|
|
390
|
-
nextSibling: mutation.nextSibling
|
|
391
|
-
};
|
|
392
|
-
nextAddedIndex = addedNodeCount;
|
|
393
|
-
nextRemovedIndex = removedNodeCount;
|
|
394
|
-
completesChildList = true;
|
|
395
|
-
} else {
|
|
396
|
-
// A large native remove+add record is normalized in bounded slices but
|
|
397
|
-
// admitted as one mutation group by mutationObserver. Consume removals
|
|
398
|
-
// first so every later add slice can inherit whether the native record
|
|
399
|
-
// removed a published node. This preserves the fail-closed replacement
|
|
400
|
-
// dependency without synchronously scanning the whole NodeList.
|
|
401
|
-
var structuralState = removedNodeCount > 0 ? getStructuralMutationState(work, work.recordIndex) : undefined;
|
|
402
|
-
var remainingNodes = Math.max(Math.min(MUTATION_CHUNK_MAX_NODES - nodeCount - 1, Math.floor((MUTATION_CHUNK_MAX_APPROX_BYTES - approxBytes - 32) / 16)), 1);
|
|
403
|
-
var removedNodes = structuralState ? Array.prototype.slice.call(mutation.removedNodes, work.removedIndex, work.removedIndex + remainingNodes) : [];
|
|
404
|
-
remainingNodes -= removedNodes.length;
|
|
405
|
-
var addedNodes = Array.prototype.slice.call(mutation.addedNodes, work.addedIndex, work.addedIndex + remainingNodes);
|
|
406
|
-
remainingNodes -= addedNodes.length;
|
|
407
|
-
if (!structuralState) {
|
|
408
|
-
removedNodes = Array.prototype.slice.call(mutation.removedNodes, work.removedIndex, work.removedIndex + remainingNodes);
|
|
409
|
-
}
|
|
410
|
-
synthetic = {
|
|
411
|
-
type: 'childList',
|
|
412
|
-
target: mutation.target,
|
|
413
|
-
addedNodes: addedNodes,
|
|
414
|
-
removedNodes: removedNodes,
|
|
415
|
-
previousSibling: mutation.previousSibling,
|
|
416
|
-
nextSibling: mutation.nextSibling,
|
|
417
|
-
$rStructuralState: structuralState
|
|
418
|
-
};
|
|
419
|
-
nextAddedIndex += addedNodes.length;
|
|
420
|
-
nextRemovedIndex += removedNodes.length;
|
|
421
|
-
completesChildList = nextAddedIndex >= addedNodeCount && nextRemovedIndex >= removedNodeCount;
|
|
422
|
-
}
|
|
423
|
-
} else {
|
|
424
|
-
synthetic = cloneMutationRecord(mutation);
|
|
425
|
-
work.recordIndex += 1;
|
|
426
|
-
}
|
|
427
|
-
var measurement = measureMutation(synthetic);
|
|
428
|
-
if (chunk.length && (nodeCount + measurement.nodeCount > MUTATION_CHUNK_MAX_NODES || approxBytes + measurement.approxBytes > MUTATION_CHUNK_MAX_APPROX_BYTES)) {
|
|
429
|
-
// The cursor is committed only after the synthetic record fits. This is
|
|
430
|
-
// important at an exact boundary: advancing a child-list cursor before
|
|
431
|
-
// this check would silently drop the rejected slice.
|
|
432
|
-
if (!isChildList) {
|
|
433
|
-
work.recordIndex -= 1;
|
|
434
|
-
}
|
|
435
|
-
break;
|
|
436
|
-
}
|
|
437
|
-
if (isChildList) {
|
|
438
|
-
if (completesChildList) {
|
|
439
|
-
work.recordIndex += 1;
|
|
440
|
-
work.addedIndex = 0;
|
|
441
|
-
work.removedIndex = 0;
|
|
442
|
-
} else {
|
|
443
|
-
work.addedIndex = nextAddedIndex;
|
|
444
|
-
work.removedIndex = nextRemovedIndex;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
chunk.push(synthetic);
|
|
448
|
-
nodeCount += measurement.nodeCount;
|
|
449
|
-
approxBytes += measurement.approxBytes;
|
|
450
|
-
if (nodeCount >= MUTATION_CHUNK_MAX_NODES || approxBytes >= MUTATION_CHUNK_MAX_APPROX_BYTES) {
|
|
451
|
-
break;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
return chunk;
|
|
455
|
-
}
|
|
456
|
-
function getStructuralMutationState(work, recordIndex) {
|
|
457
|
-
if (!work.$rStructuralStateByRecordIndex) {
|
|
458
|
-
work.$rStructuralStateByRecordIndex = [];
|
|
459
|
-
}
|
|
460
|
-
var structuralState = work.$rStructuralStateByRecordIndex[recordIndex];
|
|
461
|
-
if (!structuralState) {
|
|
462
|
-
structuralState = {
|
|
463
|
-
$rHasPublishedRemoval: false
|
|
464
|
-
};
|
|
465
|
-
work.$rStructuralStateByRecordIndex[recordIndex] = structuralState;
|
|
466
|
-
}
|
|
467
|
-
return structuralState;
|
|
468
|
-
}
|
|
469
|
-
function takePureAddChunk(work) {
|
|
470
|
-
var chunk = [];
|
|
471
|
-
var nodeCount = 0;
|
|
472
|
-
var approxBytes = 0;
|
|
473
|
-
while (work.recordIndex >= 0 && chunk.length < MUTATION_CHUNK_MAX_RECORDS) {
|
|
474
|
-
while (work.recordIndex >= 0 && work.addedIndex === 0) {
|
|
475
|
-
work.recordIndex -= 1;
|
|
476
|
-
work.addedIndex = work.recordIndex >= 0 ? getNodeListLength(work.$rMutations[work.recordIndex].addedNodes) : 0;
|
|
477
|
-
}
|
|
478
|
-
if (work.recordIndex < 0) {
|
|
479
|
-
break;
|
|
480
|
-
}
|
|
481
|
-
var mutation = work.$rMutations[work.recordIndex];
|
|
482
|
-
var remainingNodes = Math.max(Math.min(MUTATION_CHUNK_MAX_NODES - nodeCount - 1, Math.floor((MUTATION_CHUNK_MAX_APPROX_BYTES - approxBytes - 32) / 16)), 1);
|
|
483
|
-
var sliceStart = Math.max(work.addedIndex - remainingNodes, 0);
|
|
484
|
-
var synthetic = {
|
|
485
|
-
type: 'childList',
|
|
486
|
-
target: mutation.target,
|
|
487
|
-
addedNodes: Array.prototype.slice.call(mutation.addedNodes, sliceStart, work.addedIndex),
|
|
488
|
-
removedNodes: []
|
|
489
|
-
};
|
|
490
|
-
var measurement = measureMutation(synthetic);
|
|
491
|
-
if (chunk.length && (nodeCount + measurement.nodeCount > MUTATION_CHUNK_MAX_NODES || approxBytes + measurement.approxBytes > MUTATION_CHUNK_MAX_APPROX_BYTES)) {
|
|
492
|
-
break;
|
|
493
|
-
}
|
|
494
|
-
work.addedIndex = sliceStart;
|
|
495
|
-
if (work.addedIndex === 0) {
|
|
496
|
-
work.recordIndex -= 1;
|
|
497
|
-
work.addedIndex = work.recordIndex >= 0 ? getNodeListLength(work.$rMutations[work.recordIndex].addedNodes) : 0;
|
|
498
|
-
}
|
|
499
|
-
chunk.push(synthetic);
|
|
500
|
-
nodeCount += measurement.nodeCount;
|
|
501
|
-
approxBytes += measurement.approxBytes;
|
|
502
|
-
if (nodeCount >= MUTATION_CHUNK_MAX_NODES || approxBytes >= MUTATION_CHUNK_MAX_APPROX_BYTES) {
|
|
503
|
-
break;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
return chunk;
|
|
507
|
-
}
|
|
508
|
-
function cloneMutationRecord(mutation) {
|
|
509
|
-
var oldValue = mutation.oldValue;
|
|
510
|
-
if (typeof oldValue === 'string' && oldValue.length > MUTATION_CHUNK_MAX_APPROX_BYTES / 4) {
|
|
511
|
-
oldValue = undefined;
|
|
512
|
-
}
|
|
513
|
-
return {
|
|
514
|
-
type: mutation.type,
|
|
515
|
-
target: mutation.target,
|
|
516
|
-
attributeName: mutation.attributeName,
|
|
517
|
-
oldValue: oldValue
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
function measureMutationsUntilLimit(mutations, nodeLimit, byteLimit) {
|
|
521
|
-
var nodeCount = 0;
|
|
522
|
-
var approxBytes = 0;
|
|
523
|
-
for (var index = 0; index < mutations.length; index += 1) {
|
|
524
|
-
var measurement = measureMutation(mutations[index]);
|
|
525
|
-
nodeCount += measurement.nodeCount;
|
|
526
|
-
approxBytes += measurement.approxBytes;
|
|
527
|
-
if (nodeCount > nodeLimit || approxBytes > byteLimit) {
|
|
528
|
-
break;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
return {
|
|
532
|
-
nodeCount: nodeCount,
|
|
533
|
-
approxBytes: approxBytes
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
function measureMutation(mutation) {
|
|
537
|
-
var nodeCount = 1;
|
|
538
|
-
var approxBytes = 32;
|
|
539
|
-
if (mutation.type === 'childList') {
|
|
540
|
-
var childNodeCount = getNodeListLength(mutation.addedNodes) + getNodeListLength(mutation.removedNodes);
|
|
541
|
-
nodeCount += childNodeCount;
|
|
542
|
-
approxBytes += childNodeCount * 16;
|
|
543
|
-
} else if (mutation.type === 'attributes') {
|
|
544
|
-
approxBytes += getStringApproxBytes(mutation.attributeName) + getStringApproxBytes(mutation.oldValue);
|
|
545
|
-
} else if (mutation.type === 'characterData') {
|
|
546
|
-
approxBytes += getStringApproxBytes(mutation.oldValue);
|
|
547
|
-
}
|
|
548
|
-
return {
|
|
549
|
-
nodeCount: nodeCount,
|
|
550
|
-
approxBytes: approxBytes
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
function getNodeListLength(nodes) {
|
|
554
|
-
return nodes && typeof nodes.length === 'number' ? nodes.length : 0;
|
|
555
|
-
}
|
|
556
|
-
function getStringApproxBytes(value) {
|
|
557
|
-
return typeof value === 'string' ? value.length * 2 : 0;
|
|
558
|
-
}
|
|
559
|
-
function getCurrentTime() {
|
|
560
|
-
return typeof performance !== 'undefined' && performance.now ? performance.now() : Date.now();
|
|
561
|
-
}
|
|
562
|
-
//# sourceMappingURL=mutationBatch.js.map
|
|
1
|
+
import{noop,throttle,requestIdleCallback}from"@cloudcare/browser-core";import{MUTATION_RESOURCE_RAW}from"./mutationResourceBudget";export var MUTATION_PROCESS_MIN_DELAY=48;export var MAX_PENDING_MUTATION_RECORDS=256;export var MAX_PENDING_MUTATION_NODES=1e3;export var MAX_PENDING_MUTATION_APPROX_BYTES=262144;export var MUTATION_CHUNK_MAX_RECORDS=64;export var MUTATION_CHUNK_MAX_NODES=32;export var MUTATION_CHUNK_MAX_APPROX_BYTES=65536;export var MAX_QUEUED_MUTATION_RECORDS=4096;export var MAX_QUEUED_MUTATION_NODES=16384;export var MAX_QUEUED_MUTATION_APPROX_BYTES=8388608;export function createMutationBatch(processMutationBatch,onOverflow,mutationResourceBudget){var continuationTimeout,cancelScheduledFlush=noop,pendingMutations=[],pendingMutationNodes=0,pendingMutationApproxBytes=0,pendingMutationDirectNodes=0,pendingNativeCallbackCount=0,pendingMutationReservations=[],workQueue=[],queuedMutationRecords=0,queuedMutationNodes=0,queuedMutationApproxBytes=0,stopped=!1,coalescedTextReplacementByRemovedNode=new WeakMap,throttled=throttle(flush,MUTATION_PROCESS_MIN_DELAY,{leading:!1});function scheduleContinuation(){void 0===continuationTimeout&&!stopped&&workQueue.length&&(continuationTimeout=setTimeout((function(){continuationTimeout=void 0,drainOneChunk(),scheduleContinuation()}),0))}function enqueuePending(){pendingMutations.length&&(enqueueMutationWork({$rMutations:pendingMutations,$rMeasurement:{mutationRecordCount:pendingMutations.length,nodeCount:pendingMutationNodes,approxBytes:pendingMutationApproxBytes},directNodeCount:pendingMutationDirectNodes,nativeCallbackCount:pendingNativeCallbackCount,reservations:pendingMutationReservations}),pendingMutations=[],pendingMutationNodes=0,pendingMutationApproxBytes=0,pendingMutationDirectNodes=0,pendingNativeCallbackCount=0,pendingMutationReservations=[])}function enqueueMutationWork(work){work.$rTextReplacementByRemovedNode=coalescedTextReplacementByRemovedNode,function shouldChunkMutationWork(work){return 1===work.nativeCallbackCount&&work.directNodeCount>=MUTATION_CHUNK_MAX_NODES&&!function hasStructuralRemoval(mutations){for(var index=0;index<mutations.length;index+=1)if("childList"===mutations[index].type&&getNodeListLength(mutations[index].removedNodes))return!0;return!1}(work.$rMutations)||work.$rMeasurement.mutationRecordCount>MAX_PENDING_MUTATION_RECORDS||work.$rMeasurement.nodeCount>MAX_PENDING_MUTATION_NODES||work.$rMeasurement.approxBytes>MAX_PENDING_MUTATION_APPROX_BYTES}(work)&&function initializeChunkedWork(work){var isPureAdd=1===work.nativeCallbackCount&&function isReverseChunkableSiblingAddWork(mutations){for(var target,previousAddedNode,hasAdd=!1,addedNodeSet=new Set,index=0;index<mutations.length;index+=1){var mutation=mutations[index];if("childList"!==mutation.type||getNodeListLength(mutation.removedNodes))return!1;if(void 0===target)target=mutation.target;else if(mutation.target!==target)return!1;for(var addedIndex=0;addedIndex<getNodeListLength(mutation.addedNodes);addedIndex+=1){var addedNode=mutation.addedNodes[addedIndex];if(!target||addedNodeSet.has(addedNode)||addedNode.parentNode!==target||previousAddedNode&&!isFollowingSibling(previousAddedNode,addedNode))return!1;addedNodeSet.add(addedNode),previousAddedNode=addedNode,hasAdd=!0}}return hasAdd}(work.$rMutations);work.$rTransaction={$rPureAdd:isPureAdd},work.recordIndex=isPureAdd?work.$rMutations.length-1:0,work.addedIndex=isPureAdd?getNodeListLength(work.$rMutations[work.recordIndex].addedNodes):0,work.removedIndex=0}(work),function enqueueWork(work){workQueue.push(work),queuedMutationRecords+=work.$rMeasurement.mutationRecordCount,queuedMutationNodes+=work.$rMeasurement.nodeCount,queuedMutationApproxBytes+=work.$rMeasurement.approxBytes}(work)}function releaseWork(work){queuedMutationRecords-=work.$rMeasurement.mutationRecordCount,queuedMutationNodes-=work.$rMeasurement.nodeCount,queuedMutationApproxBytes-=work.$rMeasurement.approxBytes,releaseReservations(work.reservations),workQueue.length||pendingMutations.length||(coalescedTextReplacementByRemovedNode=new WeakMap)}function flush(){cancelScheduledFlush(),cancelScheduledFlush=noop,throttled.cancel(),enqueuePending();var deadline=getCurrentTime()+4,succeeded=!0;do{if(!drainOneChunk()){succeeded=!1;break}}while(workQueue.length&&getCurrentTime()<deadline);return!!succeeded&&(!workQueue.length||(scheduleContinuation(),"pending"))}function drainOneChunk(){if(stopped||!workQueue.length)return!0;var work=workQueue[0];if(void 0===work.recordIndex){workQueue.shift(),releaseWork(work);var batchSucceeded=process(work.$rMutations,createBatchContext(work));return batchSucceeded||reset(),batchSucceeded}var chunk=function takeChunk(work){if(work.$rTransaction.$rPureAdd)return function takePureAddChunk(work){var chunk=[],nodeCount=0,approxBytes=0;for(;work.recordIndex>=0&&chunk.length<MUTATION_CHUNK_MAX_RECORDS;){for(;work.recordIndex>=0&&0===work.addedIndex;)work.recordIndex-=1,work.addedIndex=work.recordIndex>=0?getNodeListLength(work.$rMutations[work.recordIndex].addedNodes):0;if(work.recordIndex<0)break;var mutation=work.$rMutations[work.recordIndex],remainingNodes=Math.max(Math.min(MUTATION_CHUNK_MAX_NODES-nodeCount-1,Math.floor((MUTATION_CHUNK_MAX_APPROX_BYTES-approxBytes-32)/16)),1),sliceStart=Math.max(work.addedIndex-remainingNodes,0),synthetic={type:"childList",target:mutation.target,addedNodes:Array.prototype.slice.call(mutation.addedNodes,sliceStart,work.addedIndex),removedNodes:[]},measurement=measureMutation(synthetic);if(chunk.length&&(nodeCount+measurement.nodeCount>MUTATION_CHUNK_MAX_NODES||approxBytes+measurement.approxBytes>MUTATION_CHUNK_MAX_APPROX_BYTES))break;if(work.addedIndex=sliceStart,0===work.addedIndex&&(work.recordIndex-=1,work.addedIndex=work.recordIndex>=0?getNodeListLength(work.$rMutations[work.recordIndex].addedNodes):0),chunk.push(synthetic),nodeCount+=measurement.nodeCount,approxBytes+=measurement.approxBytes,nodeCount>=MUTATION_CHUNK_MAX_NODES||approxBytes>=MUTATION_CHUNK_MAX_APPROX_BYTES)break}return chunk}(work);var chunk=[],nodeCount=0,approxBytes=0;for(;work.recordIndex<work.$rMutations.length&&chunk.length<MUTATION_CHUNK_MAX_RECORDS;){var mutation=work.$rMutations[work.recordIndex],synthetic=mutation,isChildList="childList"===mutation.type,nextAddedIndex=work.addedIndex,nextRemovedIndex=work.removedIndex,completesChildList=!1;if("childList"===mutation.type){var addedNodeCount=getNodeListLength(mutation.addedNodes),removedNodeCount=getNodeListLength(mutation.removedNodes);if(removedNodeCount>0&&addedNodeCount+removedNodeCount<MAX_PENDING_MUTATION_NODES){var structuralMeasurement=measureMutation(mutation);if(chunk.length&&(nodeCount+structuralMeasurement.nodeCount>MUTATION_CHUNK_MAX_NODES||approxBytes+structuralMeasurement.approxBytes>MUTATION_CHUNK_MAX_APPROX_BYTES))break;synthetic={type:"childList",target:mutation.target,addedNodes:Array.prototype.slice.call(mutation.addedNodes),removedNodes:Array.prototype.slice.call(mutation.removedNodes),previousSibling:mutation.previousSibling,nextSibling:mutation.nextSibling},nextAddedIndex=addedNodeCount,nextRemovedIndex=removedNodeCount,completesChildList=!0}else{var structuralState=removedNodeCount>0?getStructuralMutationState(work,work.recordIndex):void 0,remainingNodes=Math.max(Math.min(MUTATION_CHUNK_MAX_NODES-nodeCount-1,Math.floor((MUTATION_CHUNK_MAX_APPROX_BYTES-approxBytes-32)/16)),1),removedNodes=structuralState?Array.prototype.slice.call(mutation.removedNodes,work.removedIndex,work.removedIndex+remainingNodes):[];remainingNodes-=removedNodes.length;var addedNodes=Array.prototype.slice.call(mutation.addedNodes,work.addedIndex,work.addedIndex+remainingNodes);remainingNodes-=addedNodes.length,structuralState||(removedNodes=Array.prototype.slice.call(mutation.removedNodes,work.removedIndex,work.removedIndex+remainingNodes)),synthetic={type:"childList",target:mutation.target,addedNodes:addedNodes,removedNodes:removedNodes,previousSibling:mutation.previousSibling,nextSibling:mutation.nextSibling,$rStructuralState:structuralState},nextAddedIndex+=addedNodes.length,nextRemovedIndex+=removedNodes.length,completesChildList=nextAddedIndex>=addedNodeCount&&nextRemovedIndex>=removedNodeCount}}else synthetic=cloneMutationRecord(mutation),work.recordIndex+=1;var measurement=measureMutation(synthetic);if(chunk.length&&(nodeCount+measurement.nodeCount>MUTATION_CHUNK_MAX_NODES||approxBytes+measurement.approxBytes>MUTATION_CHUNK_MAX_APPROX_BYTES)){isChildList||(work.recordIndex-=1);break}if(isChildList&&(completesChildList?(work.recordIndex+=1,work.addedIndex=0,work.removedIndex=0):(work.addedIndex=nextAddedIndex,work.removedIndex=nextRemovedIndex)),chunk.push(synthetic),nodeCount+=measurement.nodeCount,approxBytes+=measurement.approxBytes,nodeCount>=MUTATION_CHUNK_MAX_NODES||approxBytes>=MUTATION_CHUNK_MAX_APPROX_BYTES)break}return chunk}(work),isLast=work.$rTransaction.$rPureAdd?work.recordIndex<0:work.recordIndex>=work.$rMutations.length,succeeded=process(chunk,createBatchContext(work,work.$rTransaction,isLast));return workQueue[0]===work&&(succeeded&&!isLast||(workQueue.shift(),releaseWork(work)),succeeded||reset(),succeeded)}function process(mutations,batchContext){try{var result=processMutationBatch(mutations,batchContext);return batchContext.transaction?!0===result:!1!==result}catch(_){return onOverflow&&onOverflow({reason:"mutation_processing_error",mutationRecordCount:mutations.length}),!1}}function reset(){cancelScheduledFlush(),cancelScheduledFlush=noop,throttled.cancel(),void 0!==continuationTimeout&&(clearTimeout(continuationTimeout),continuationTimeout=void 0),releaseReservations(pendingMutationReservations),workQueue.forEach((function(work){releaseReservations(work.reservations)})),pendingMutations=[],pendingMutationNodes=0,pendingMutationApproxBytes=0,pendingMutationDirectNodes=0,pendingNativeCallbackCount=0,pendingMutationReservations=[],workQueue=[],queuedMutationRecords=0,queuedMutationNodes=0,queuedMutationApproxBytes=0,coalescedTextReplacementByRemovedNode=new WeakMap}return{addMutations:function addMutations(mutations){if(!mutations.length||stopped)return!0;var mutationResourceReservation,queuedMeasurement=function measureMutationsUntilLimit(mutations,nodeLimit,byteLimit){for(var nodeCount=0,approxBytes=0,index=0;index<mutations.length;index+=1){var measurement=measureMutation(mutations[index]);if(nodeCount+=measurement.nodeCount,approxBytes+=measurement.approxBytes,nodeCount>nodeLimit||approxBytes>byteLimit)break}return{nodeCount:nodeCount,approxBytes:approxBytes}}(mutations,MAX_QUEUED_MUTATION_NODES-queuedMutationNodes-pendingMutationNodes,MAX_QUEUED_MUTATION_APPROX_BYTES-queuedMutationApproxBytes-pendingMutationApproxBytes);if(queuedMutationRecords+pendingMutations.length+mutations.length>MAX_QUEUED_MUTATION_RECORDS||queuedMutationNodes+pendingMutationNodes+queuedMeasurement.nodeCount>MAX_QUEUED_MUTATION_NODES||queuedMutationApproxBytes+pendingMutationApproxBytes+queuedMeasurement.approxBytes>MAX_QUEUED_MUTATION_APPROX_BYTES)return reset(),onOverflow&&onOverflow({reason:"raw_mutation_queue_watermark",mutationRecordCount:mutations.length,mutationNodeCount:queuedMeasurement.nodeCount,mutationApproxBytes:queuedMeasurement.approxBytes}),!1;if(mutationResourceBudget&&!(mutationResourceReservation=mutationResourceBudget.reserve(MUTATION_RESOURCE_RAW,{recordCount:mutations.length,nodeCount:queuedMeasurement.nodeCount,approxBytes:queuedMeasurement.approxBytes})))return reset(),onOverflow&&onOverflow({reason:"aggregate_raw_mutation_watermark",mutationRecordCount:mutations.length,mutationNodeCount:queuedMeasurement.nodeCount,mutationApproxBytes:queuedMeasurement.approxBytes}),!1;var directNodeCount=function countDirectMutationNodes(mutations){for(var nodeCount=0,index=0;index<mutations.length;index+=1){var mutation=mutations[index];"childList"===mutation.type&&(nodeCount+=getNodeListLength(mutation.addedNodes)+getNodeListLength(mutation.removedNodes))}return nodeCount}(mutations),canStorePending=!workQueue.length&&(!pendingMutations.length||function canMergePendingCallback(mutationRecordCount,measurement,directNodeCount){return pendingMutationDirectNodes+directNodeCount<=MUTATION_CHUNK_MAX_NODES&&pendingMutations.length+mutationRecordCount<=MAX_PENDING_MUTATION_RECORDS&&pendingMutationNodes+measurement.nodeCount<=MAX_PENDING_MUTATION_NODES&&pendingMutationApproxBytes+measurement.approxBytes<=MAX_PENDING_MUTATION_APPROX_BYTES}(mutations.length,queuedMeasurement,directNodeCount));return canStorePending?(pendingMutations.length||function scheduleInitialFlush(){cancelScheduledFlush===noop&&(cancelScheduledFlush=requestIdleCallback(throttled.throttled,{timeout:120}))}(),Array.prototype.push.apply(pendingMutations,mutations),mutationResourceReservation&&pendingMutationReservations.push(mutationResourceReservation),pendingMutationNodes+=queuedMeasurement.nodeCount,pendingMutationApproxBytes+=queuedMeasurement.approxBytes,pendingMutationDirectNodes+=directNodeCount,pendingNativeCallbackCount+=1):(enqueuePending(),enqueueMutationWork({$rMutations:mutations,$rMeasurement:{mutationRecordCount:mutations.length,nodeCount:queuedMeasurement.nodeCount,approxBytes:queuedMeasurement.approxBytes},directNodeCount:directNodeCount,nativeCallbackCount:1,reservations:mutationResourceReservation?[mutationResourceReservation]:[]}),scheduleContinuation()),!0},flush:flush,reset:reset,hasPending:function hasPending(){return Boolean(pendingMutations.length||workQueue.length)},stop:function stop(){stopped=!0,reset()}}}function createBatchContext(work,transaction,isLast){return{transaction:transaction,isLast:isLast,$rTextReplacementByRemovedNode:work.$rTextReplacementByRemovedNode}}function isFollowingSibling(previousNode,node){return"function"==typeof previousNode.compareDocumentPosition&&Boolean(previousNode.compareDocumentPosition(node)&Node.DOCUMENT_POSITION_FOLLOWING)}function releaseReservations(reservations){reservations&&(reservations.forEach((function(release){release()})),reservations.length=0)}function getStructuralMutationState(work,recordIndex){work.$rStructuralStateByRecordIndex||(work.$rStructuralStateByRecordIndex=[]);var structuralState=work.$rStructuralStateByRecordIndex[recordIndex];return structuralState||(structuralState={$rHasPublishedRemoval:!1},work.$rStructuralStateByRecordIndex[recordIndex]=structuralState),structuralState}function cloneMutationRecord(mutation){var oldValue=mutation.oldValue;return"string"==typeof oldValue&&oldValue.length>MUTATION_CHUNK_MAX_APPROX_BYTES/4&&(oldValue=void 0),{type:mutation.type,target:mutation.target,attributeName:mutation.attributeName,oldValue:oldValue}}function measureMutation(mutation){var nodeCount=1,approxBytes=32;if("childList"===mutation.type){var childNodeCount=getNodeListLength(mutation.addedNodes)+getNodeListLength(mutation.removedNodes);nodeCount+=childNodeCount,approxBytes+=16*childNodeCount}else"attributes"===mutation.type?approxBytes+=getStringApproxBytes(mutation.attributeName)+getStringApproxBytes(mutation.oldValue):"characterData"===mutation.type&&(approxBytes+=getStringApproxBytes(mutation.oldValue));return{nodeCount:nodeCount,approxBytes:approxBytes}}function getNodeListLength(nodes){return nodes&&"number"==typeof nodes.length?nodes.length:0}function getStringApproxBytes(value){return"string"==typeof value?2*value.length:0}function getCurrentTime(){return"undefined"!=typeof performance&&performance.now?performance.now():Date.now()}
|
|
2
|
+
//# sourceMappingURL=mutationBatch.js.map
|