@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,677 +1,2 @@
|
|
|
1
|
-
import { getParentNode, isNodeShadowRoot, buildUrl, isSafari } from '@cloudcare/browser-core';
|
|
2
|
-
|
|
3
|
-
import { shouldMaskNode } from './privacy';
|
|
4
|
-
var serializedNodeIds = new WeakMap();
|
|
5
|
-
export var MAX_SERIALIZED_CANVAS_REGISTRY_SIZE = 2048;
|
|
6
|
-
export var MAX_SERIALIZED_NODE_ANCESTOR_DEPTH = 1000;
|
|
7
|
-
export var STYLESHEET_SERIALIZATION_MAX_RULE_COUNT = 5000;
|
|
8
|
-
export var STYLESHEET_SERIALIZATION_MAX_CHARACTER_COUNT = 256 * 1024;
|
|
9
|
-
export var STYLESHEET_SERIALIZATION_MAX_DURATION_MS = 4;
|
|
10
|
-
export var STYLESHEET_SERIALIZATION_MAX_SNAPSHOT_BYTES = 512 * 1024;
|
|
11
|
-
var serializedCanvasEntries = [];
|
|
12
|
-
var serializedCanvasFreeEntryIndexes = [];
|
|
13
|
-
var serializedCanvasEntryByNode = new WeakMap();
|
|
14
|
-
var serializedCanvasEntryCount = 0;
|
|
15
|
-
var serializedCanvasNextEvictionIndex = 0;
|
|
16
|
-
var serializedCanvasScanCursor = 0;
|
|
17
|
-
var serializedCanvasScanRemaining = 0;
|
|
18
|
-
var serializedCanvasTrackingCount = 0;
|
|
19
|
-
var anchorElementByDocument = new WeakMap();
|
|
20
|
-
var hrefByDocument = new WeakMap();
|
|
21
|
-
export function getHiddenElementPlaceholderSize(element) {
|
|
22
|
-
var width = element.getAttribute('width') || element.style && element.style.width || undefined;
|
|
23
|
-
var height = element.getAttribute('height') || element.style && element.style.height || undefined;
|
|
24
|
-
return {
|
|
25
|
-
width: width,
|
|
26
|
-
height: height
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export function hasSerializedNode(node) {
|
|
30
|
-
return serializedNodeIds.has(node);
|
|
31
|
-
}
|
|
32
|
-
export function nodeAndAncestorsHaveSerializedNode(node) {
|
|
33
|
-
var current = node;
|
|
34
|
-
var depth = 0;
|
|
35
|
-
while (current) {
|
|
36
|
-
if (depth >= MAX_SERIALIZED_NODE_ANCESTOR_DEPTH) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
if (!hasSerializedNode(current) && !isNodeShadowRoot(current)) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
depth += 1;
|
|
43
|
-
current = getParentNode(current);
|
|
44
|
-
}
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
export function getSerializedNodeId(node) {
|
|
48
|
-
return serializedNodeIds.get(node);
|
|
49
|
-
}
|
|
50
|
-
export function setSerializedNodeId(node, serializeNodeId) {
|
|
51
|
-
serializedNodeIds.set(node, serializeNodeId);
|
|
52
|
-
if (serializedCanvasTrackingCount && node.tagName === 'CANVAS') {
|
|
53
|
-
registerSerializedCanvasNode(node);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export function startSerializedCanvasTracking() {
|
|
57
|
-
serializedCanvasTrackingCount += 1;
|
|
58
|
-
var stopped = false;
|
|
59
|
-
return function stopSerializedCanvasTracking() {
|
|
60
|
-
if (stopped) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
stopped = true;
|
|
64
|
-
serializedCanvasTrackingCount -= 1;
|
|
65
|
-
if (serializedCanvasTrackingCount === 0) {
|
|
66
|
-
clearSerializedCanvasRegistry();
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function isSerializedCanvasConnectedToDocument(node) {
|
|
71
|
-
var isConnected = node.isConnected;
|
|
72
|
-
if (typeof isConnected === 'boolean') {
|
|
73
|
-
return isConnected;
|
|
74
|
-
}
|
|
75
|
-
var current = node;
|
|
76
|
-
while (current) {
|
|
77
|
-
if (current === document) {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
current = getParentNode(current);
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
function registerSerializedCanvasNode(node) {
|
|
85
|
-
var existingEntry = serializedCanvasEntryByNode.get(node);
|
|
86
|
-
if (existingEntry && existingEntry.active) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
var entry = {
|
|
90
|
-
active: true,
|
|
91
|
-
weakRef: typeof WeakRef === 'function' ? new WeakRef(node) : undefined,
|
|
92
|
-
node: typeof WeakRef === 'function' ? undefined : node
|
|
93
|
-
};
|
|
94
|
-
var entryIndex;
|
|
95
|
-
if (serializedCanvasFreeEntryIndexes.length) {
|
|
96
|
-
entryIndex = serializedCanvasFreeEntryIndexes.pop();
|
|
97
|
-
} else if (serializedCanvasEntries.length < MAX_SERIALIZED_CANVAS_REGISTRY_SIZE) {
|
|
98
|
-
entryIndex = serializedCanvasEntries.length;
|
|
99
|
-
} else {
|
|
100
|
-
entryIndex = serializedCanvasNextEvictionIndex;
|
|
101
|
-
serializedCanvasNextEvictionIndex = (serializedCanvasNextEvictionIndex + 1) % MAX_SERIALIZED_CANVAS_REGISTRY_SIZE;
|
|
102
|
-
var evictedEntry = serializedCanvasEntries[entryIndex];
|
|
103
|
-
if (evictedEntry && evictedEntry.active) {
|
|
104
|
-
evictedEntry.active = false;
|
|
105
|
-
serializedCanvasEntryCount -= 1;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
entry.index = entryIndex;
|
|
109
|
-
serializedCanvasEntries[entryIndex] = entry;
|
|
110
|
-
serializedCanvasEntryByNode.set(node, entry);
|
|
111
|
-
serializedCanvasEntryCount += 1;
|
|
112
|
-
}
|
|
113
|
-
function getSerializedCanvasEntryNode(entry) {
|
|
114
|
-
if (!entry || !entry.active) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
return entry.weakRef ? entry.weakRef.deref() : entry.node;
|
|
118
|
-
}
|
|
119
|
-
function pruneSerializedCanvasEntry(entry) {
|
|
120
|
-
if (!entry || !entry.active) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
entry.active = false;
|
|
124
|
-
entry.node = undefined;
|
|
125
|
-
if (serializedCanvasEntries[entry.index] === entry) {
|
|
126
|
-
serializedCanvasEntries[entry.index] = undefined;
|
|
127
|
-
serializedCanvasFreeEntryIndexes.push(entry.index);
|
|
128
|
-
}
|
|
129
|
-
serializedCanvasEntryCount = Math.max(serializedCanvasEntryCount - 1, 0);
|
|
130
|
-
}
|
|
131
|
-
function clearSerializedCanvasRegistry() {
|
|
132
|
-
serializedCanvasEntries = [];
|
|
133
|
-
serializedCanvasFreeEntryIndexes = [];
|
|
134
|
-
serializedCanvasEntryByNode = new WeakMap();
|
|
135
|
-
serializedCanvasEntryCount = 0;
|
|
136
|
-
serializedCanvasNextEvictionIndex = 0;
|
|
137
|
-
resetSerializedCanvasScan();
|
|
138
|
-
}
|
|
139
|
-
function resetSerializedCanvasScan() {
|
|
140
|
-
serializedCanvasScanCursor = 0;
|
|
141
|
-
serializedCanvasScanRemaining = 0;
|
|
142
|
-
}
|
|
143
|
-
export function getSerializedCanvasNodes(maxScanCount) {
|
|
144
|
-
if (typeof maxScanCount === 'number') {
|
|
145
|
-
return getSerializedCanvasNodesWithinScanLimit(maxScanCount);
|
|
146
|
-
}
|
|
147
|
-
var connectedSerializedCanvasNodes = [];
|
|
148
|
-
for (var entryIndex = 0; entryIndex < serializedCanvasEntries.length; entryIndex += 1) {
|
|
149
|
-
var entry = serializedCanvasEntries[entryIndex];
|
|
150
|
-
var node = getSerializedCanvasEntryNode(entry);
|
|
151
|
-
if (hasSerializedNode(node) && isSerializedCanvasConnectedToDocument(node)) {
|
|
152
|
-
connectedSerializedCanvasNodes.push(node);
|
|
153
|
-
} else {
|
|
154
|
-
pruneSerializedCanvasEntry(entry);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
resetSerializedCanvasScan();
|
|
158
|
-
return connectedSerializedCanvasNodes;
|
|
159
|
-
}
|
|
160
|
-
export function getSerializedCanvasNodesSnapshot(maxScanCount) {
|
|
161
|
-
var resultLimit = Math.max(Math.floor(maxScanCount), 0);
|
|
162
|
-
if (!isFinite(resultLimit) || resultLimit === 0 || !serializedCanvasEntryCount || !serializedCanvasEntries.length) {
|
|
163
|
-
return [];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Full-snapshot bitmap baselines need a complete bounded view independent
|
|
167
|
-
// from the partial round-robin pass shared by continuous and command
|
|
168
|
-
// schedulers. Scan the bounded registry until enough active canvases are
|
|
169
|
-
// collected so sparse/disconnected slots cannot hide later canvases, without
|
|
170
|
-
// reading or updating the shared cursor.
|
|
171
|
-
var connectedSerializedCanvasNodes = [];
|
|
172
|
-
for (var entryIndex = 0; entryIndex < serializedCanvasEntries.length && connectedSerializedCanvasNodes.length < resultLimit; entryIndex += 1) {
|
|
173
|
-
var entry = serializedCanvasEntries[entryIndex];
|
|
174
|
-
var node = getSerializedCanvasEntryNode(entry);
|
|
175
|
-
if (hasSerializedNode(node) && isSerializedCanvasConnectedToDocument(node)) {
|
|
176
|
-
connectedSerializedCanvasNodes.push(node);
|
|
177
|
-
} else {
|
|
178
|
-
pruneSerializedCanvasEntry(entry);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return connectedSerializedCanvasNodes;
|
|
182
|
-
}
|
|
183
|
-
function getSerializedCanvasNodesWithinScanLimit(maxScanCount) {
|
|
184
|
-
var scanLimit = Math.max(Math.floor(maxScanCount), 0);
|
|
185
|
-
if (!isFinite(scanLimit) || scanLimit === 0 || !serializedCanvasEntryCount || !serializedCanvasEntries.length) {
|
|
186
|
-
return [];
|
|
187
|
-
}
|
|
188
|
-
if (!serializedCanvasScanRemaining) {
|
|
189
|
-
serializedCanvasScanCursor = 0;
|
|
190
|
-
serializedCanvasScanRemaining = serializedCanvasEntries.length;
|
|
191
|
-
}
|
|
192
|
-
var connectedSerializedCanvasNodes = [];
|
|
193
|
-
var scannedNodeCount = 0;
|
|
194
|
-
while (scannedNodeCount < scanLimit && serializedCanvasScanRemaining > 0) {
|
|
195
|
-
var entry = serializedCanvasEntries[serializedCanvasScanCursor];
|
|
196
|
-
serializedCanvasScanCursor = (serializedCanvasScanCursor + 1) % serializedCanvasEntries.length;
|
|
197
|
-
scannedNodeCount += 1;
|
|
198
|
-
serializedCanvasScanRemaining -= 1;
|
|
199
|
-
var node = getSerializedCanvasEntryNode(entry);
|
|
200
|
-
if (hasSerializedNode(node) && isSerializedCanvasConnectedToDocument(node)) {
|
|
201
|
-
connectedSerializedCanvasNodes.push(node);
|
|
202
|
-
} else {
|
|
203
|
-
pruneSerializedCanvasEntry(entry);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
if (serializedCanvasScanRemaining === 0) {
|
|
207
|
-
resetSerializedCanvasScan();
|
|
208
|
-
}
|
|
209
|
-
return connectedSerializedCanvasNodes;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Get the element "value" to be serialized as an attribute or an input update record. It respects
|
|
214
|
-
* the input privacy mode of the element.
|
|
215
|
-
* PERFROMANCE OPTIMIZATION: Assumes that privacy level `HIDDEN` is never encountered because of earlier checks.
|
|
216
|
-
*/
|
|
217
|
-
export function getElementInputValue(configuration, element, nodePrivacyLevel) {
|
|
218
|
-
/*
|
|
219
|
-
BROWSER SPEC NOTE: <input>, <select>
|
|
220
|
-
For some <input> elements, the `value` is an exceptional property/attribute that has the
|
|
221
|
-
value synced between el.value and el.getAttribute()
|
|
222
|
-
input[type=button,checkbox,hidden,image,radio,reset,submit]
|
|
223
|
-
*/
|
|
224
|
-
var tagName = element.tagName;
|
|
225
|
-
var value = element.value;
|
|
226
|
-
if (shouldMaskNode(configuration, element, nodePrivacyLevel)) {
|
|
227
|
-
var type = element.type;
|
|
228
|
-
if (tagName === 'INPUT' && (type === 'button' || type === 'submit' || type === 'reset' || type === 'range')) {
|
|
229
|
-
// Overrule `MASK` privacy level for button-like element values, as they are used during replay
|
|
230
|
-
// to display their label. They can still be hidden via the "hidden" privacy attribute or class name.
|
|
231
|
-
return value;
|
|
232
|
-
} else if (!value || tagName === 'OPTION') {
|
|
233
|
-
// <Option> value provides no benefit
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
return CENSORED_STRING_MARK;
|
|
237
|
-
}
|
|
238
|
-
if (tagName === 'OPTION' || tagName === 'SELECT') {
|
|
239
|
-
return element.value;
|
|
240
|
-
}
|
|
241
|
-
if (tagName !== 'INPUT' && tagName !== 'TEXTAREA') {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
return value;
|
|
245
|
-
}
|
|
246
|
-
function extractOrigin(url) {
|
|
247
|
-
var origin = '';
|
|
248
|
-
if (url.indexOf('//') > -1) {
|
|
249
|
-
origin = url.split('/').slice(0, 3).join('/');
|
|
250
|
-
} else {
|
|
251
|
-
origin = url.split('/')[0];
|
|
252
|
-
}
|
|
253
|
-
origin = origin.split('?')[0];
|
|
254
|
-
return origin;
|
|
255
|
-
}
|
|
256
|
-
export var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm;
|
|
257
|
-
export var ABSOLUTE_URL = /^[A-Za-z]+:|^\/\//;
|
|
258
|
-
export var DATA_URI = /^data:.*,/i;
|
|
259
|
-
/**
|
|
260
|
-
* Browsers sometimes destructively modify the css rules they receive.
|
|
261
|
-
* This function tries to rectify the modifications the browser made to make it more cross platform compatible.
|
|
262
|
-
* @param cssText - output of `CSSStyleRule.cssText`
|
|
263
|
-
* @returns `cssText` with browser inconsistencies fixed.
|
|
264
|
-
*/
|
|
265
|
-
export function fixBrowserCompatibilityIssuesInCSS(cssText) {
|
|
266
|
-
/**
|
|
267
|
-
* Chrome outputs `-webkit-background-clip` as `background-clip` in `CSSStyleRule.cssText`.
|
|
268
|
-
* But then Chrome ignores `background-clip` as css input.
|
|
269
|
-
* Re-introduce `-webkit-background-clip` to fix this issue.
|
|
270
|
-
*/
|
|
271
|
-
if (cssText.includes(' background-clip: text;') && !cssText.includes(' -webkit-background-clip: text;')) {
|
|
272
|
-
cssText = cssText.replace(' background-clip: text;', ' -webkit-background-clip: text; background-clip: text;');
|
|
273
|
-
}
|
|
274
|
-
return cssText;
|
|
275
|
-
}
|
|
276
|
-
export function getHref() {
|
|
277
|
-
return getDocumentHref(document);
|
|
278
|
-
}
|
|
279
|
-
export function switchToAbsoluteUrl(cssText, cssHref) {
|
|
280
|
-
return cssText.replace(URL_IN_CSS_REF, function (matchingSubstring, singleQuote, urlWrappedInSingleQuotes, doubleQuote, urlWrappedInDoubleQuotes, urlNotWrappedInQuotes) {
|
|
281
|
-
var url = urlWrappedInSingleQuotes || urlWrappedInDoubleQuotes || urlNotWrappedInQuotes;
|
|
282
|
-
if (!cssHref || !url || ABSOLUTE_URL.test(url) || DATA_URI.test(url)) {
|
|
283
|
-
return matchingSubstring;
|
|
284
|
-
}
|
|
285
|
-
var quote = singleQuote || doubleQuote || '';
|
|
286
|
-
if (url[0] === '/') {
|
|
287
|
-
return 'url('.concat(quote).concat(extractOrigin(cssHref) + url).concat(quote, ')');
|
|
288
|
-
}
|
|
289
|
-
return "url(".concat(quote).concat(makeUrlAbsolute(url, cssHref)).concat(quote, ")");
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
export function getCssRulesString(cssStyleSheet, maxCharacterCount) {
|
|
293
|
-
if (!cssStyleSheet) {
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
var rootRules = getReadableStyleSheetRules(cssStyleSheet);
|
|
297
|
-
if (!rootRules) {
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
var serializationState = {
|
|
301
|
-
parts: [],
|
|
302
|
-
visitedStyleSheets: new Set(),
|
|
303
|
-
characterCount: 0,
|
|
304
|
-
characterLimit: typeof maxCharacterCount === 'number' ? maxCharacterCount : Infinity
|
|
305
|
-
};
|
|
306
|
-
var completed = appendStyleSheetRules(cssStyleSheet, serializationState, cssStyleSheet.href, rootRules);
|
|
307
|
-
// `_cssText` replaces the stylesheet in the player, so never publish a
|
|
308
|
-
// prefix. The caller may bound allocations by the entire snapshot capacity;
|
|
309
|
-
// CSS has no separate rule-count, character-count, or elapsed-time cutoff.
|
|
310
|
-
if (!completed) {
|
|
311
|
-
return null;
|
|
312
|
-
}
|
|
313
|
-
var styleSheetCssText = fixBrowserCompatibilityIssuesInCSS(serializationState.parts.join(''));
|
|
314
|
-
if (styleSheetCssText.length > serializationState.characterLimit) {
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
return styleSheetCssText;
|
|
318
|
-
}
|
|
319
|
-
function appendStyleSheetRules(cssStyleSheet, serializationState, inheritedHref, knownRules) {
|
|
320
|
-
if (!cssStyleSheet || serializationState.visitedStyleSheets.has(cssStyleSheet)) {
|
|
321
|
-
return true;
|
|
322
|
-
}
|
|
323
|
-
serializationState.visitedStyleSheets.add(cssStyleSheet);
|
|
324
|
-
var styleSheetHref = cssStyleSheet.href || inheritedHref;
|
|
325
|
-
var rules = knownRules || getReadableStyleSheetRules(cssStyleSheet);
|
|
326
|
-
if (!rules) {
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
for (var ruleIndex = 0; ruleIndex < rules.length; ruleIndex += 1) {
|
|
330
|
-
var rule = rules[ruleIndex];
|
|
331
|
-
if (isCSSImportRule(rule)) {
|
|
332
|
-
var importedHref = rule.styleSheet && rule.styleSheet.href || (rule.href && styleSheetHref ? makeUrlAbsolute(rule.href, styleSheetHref) : rule.href);
|
|
333
|
-
var importedRules = getReadableStyleSheetRules(rule.styleSheet);
|
|
334
|
-
if (importedRules) {
|
|
335
|
-
if (!appendStyleSheetRules(rule.styleSheet, serializationState, importedHref, importedRules)) {
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
} else if (!appendStyleSheetRuleText(rule, serializationState, styleSheetHref, false)) {
|
|
339
|
-
return false;
|
|
340
|
-
}
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
if (!appendStyleSheetRuleText(rule, serializationState, styleSheetHref, true)) {
|
|
344
|
-
return false;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return true;
|
|
348
|
-
}
|
|
349
|
-
function getReadableStyleSheetRules(cssStyleSheet) {
|
|
350
|
-
if (!cssStyleSheet) {
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
try {
|
|
354
|
-
return cssStyleSheet.rules || cssStyleSheet.cssRules;
|
|
355
|
-
} catch (_) {
|
|
356
|
-
// If CSS is protected by CORS we cannot access cssRules. The containing
|
|
357
|
-
// @import rule itself is still useful and is retained by the caller.
|
|
358
|
-
// See https://www.w3.org/TR/cssom-1/#the-cssstylesheet-interface.
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
function appendStyleSheetRuleText(rule, serializationState, styleSheetHref, shouldPatchSafari) {
|
|
362
|
-
var rawRuleText = rule && rule.cssText;
|
|
363
|
-
if (typeof rawRuleText !== 'string') {
|
|
364
|
-
return true;
|
|
365
|
-
}
|
|
366
|
-
if (serializationState.characterCount + rawRuleText.length > serializationState.characterLimit) {
|
|
367
|
-
return false;
|
|
368
|
-
}
|
|
369
|
-
var ruleText = shouldPatchSafari && isSafari() ? getCssRuleStringForSafari(rule) : rawRuleText;
|
|
370
|
-
ruleText = switchToAbsoluteUrl(ruleText, styleSheetHref);
|
|
371
|
-
if (serializationState.characterCount + ruleText.length > serializationState.characterLimit) {
|
|
372
|
-
return false;
|
|
373
|
-
}
|
|
374
|
-
serializationState.characterCount += ruleText.length;
|
|
375
|
-
serializationState.parts.push(ruleText);
|
|
376
|
-
return true;
|
|
377
|
-
}
|
|
378
|
-
function hasStyleSheetSerializationBudget(serializationState, additionalCharacterCount, shouldCountRule) {
|
|
379
|
-
if (additionalCharacterCount === undefined) {
|
|
380
|
-
additionalCharacterCount = 0;
|
|
381
|
-
}
|
|
382
|
-
if (shouldCountRule === undefined) {
|
|
383
|
-
shouldCountRule = true;
|
|
384
|
-
}
|
|
385
|
-
if (serializationState.exceeded || shouldCountRule && serializationState.ruleCount >= STYLESHEET_SERIALIZATION_MAX_RULE_COUNT || serializationState.characterCount + additionalCharacterCount > (serializationState.characterLimit || STYLESHEET_SERIALIZATION_MAX_CHARACTER_COUNT) || getSerializationTime() > serializationState.deadline) {
|
|
386
|
-
serializationState.exceeded = true;
|
|
387
|
-
return false;
|
|
388
|
-
}
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
function getSerializationTime() {
|
|
392
|
-
if (typeof performance !== 'undefined' && performance.now) {
|
|
393
|
-
return performance.now();
|
|
394
|
-
}
|
|
395
|
-
return Date.now();
|
|
396
|
-
}
|
|
397
|
-
export function isCSSImportRule(rule) {
|
|
398
|
-
return 'styleSheet' in rule;
|
|
399
|
-
}
|
|
400
|
-
export function isSVGElement(el) {
|
|
401
|
-
return el.tagName === 'svg' || el instanceof SVGElement;
|
|
402
|
-
}
|
|
403
|
-
export function getCssRuleString(rule) {
|
|
404
|
-
return isCSSImportRule(rule) && getCssRulesString(rule.styleSheet) || rule.cssText;
|
|
405
|
-
}
|
|
406
|
-
export function makeUrlAbsolute(url, baseUrl) {
|
|
407
|
-
try {
|
|
408
|
-
return buildUrl(url, baseUrl).href;
|
|
409
|
-
} catch (_) {
|
|
410
|
-
return url;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
function isCSSStyleRule(rule) {
|
|
414
|
-
return 'selectorText' in rule;
|
|
415
|
-
}
|
|
416
|
-
function getCssRuleStringForSafari(rule) {
|
|
417
|
-
// Safari does not escape attribute selectors containing : properly
|
|
418
|
-
// https://bugs.webkit.org/show_bug.cgi?id=184604
|
|
419
|
-
if (isCSSStyleRule(rule) && rule.selectorText.includes(':')) {
|
|
420
|
-
// This regex replaces [foo:bar] by [foo\\:bar]
|
|
421
|
-
var escapeColon = /(\[[\w-]+[^\\])(:[^\]]+\])/g;
|
|
422
|
-
return rule.cssText.replace(escapeColon, '$1\\$2');
|
|
423
|
-
}
|
|
424
|
-
return getCssRuleString(rule);
|
|
425
|
-
}
|
|
426
|
-
export function serializeStyleSheets(cssStyleSheets) {
|
|
427
|
-
if (cssStyleSheets === undefined || cssStyleSheets.length === 0) {
|
|
428
|
-
return undefined;
|
|
429
|
-
}
|
|
430
|
-
var serializedStyleSheets = [];
|
|
431
|
-
var serializationState = {
|
|
432
|
-
ruleCount: 0,
|
|
433
|
-
characterCount: 0,
|
|
434
|
-
deadline: getSerializationTime() + STYLESHEET_SERIALIZATION_MAX_DURATION_MS,
|
|
435
|
-
exceeded: false
|
|
436
|
-
};
|
|
437
|
-
for (var styleSheetIndex = 0; styleSheetIndex < cssStyleSheets.length; styleSheetIndex += 1) {
|
|
438
|
-
var cssStyleSheet = cssStyleSheets[styleSheetIndex];
|
|
439
|
-
if (!hasStyleSheetSerializationBudget(serializationState, 0, false)) {
|
|
440
|
-
break;
|
|
441
|
-
}
|
|
442
|
-
var rules = getReadableStyleSheetRules(cssStyleSheet);
|
|
443
|
-
if (!rules) {
|
|
444
|
-
continue;
|
|
445
|
-
}
|
|
446
|
-
var cssRules = [];
|
|
447
|
-
var completed = true;
|
|
448
|
-
for (var ruleIndex = 0; ruleIndex < rules.length; ruleIndex += 1) {
|
|
449
|
-
var cssText = rules[ruleIndex].cssText;
|
|
450
|
-
if (typeof cssText !== 'string') {
|
|
451
|
-
continue;
|
|
452
|
-
}
|
|
453
|
-
if (!hasStyleSheetSerializationBudget(serializationState, cssText.length)) {
|
|
454
|
-
completed = false;
|
|
455
|
-
break;
|
|
456
|
-
}
|
|
457
|
-
serializationState.ruleCount += 1;
|
|
458
|
-
serializationState.characterCount += cssText.length;
|
|
459
|
-
cssRules.push(cssText);
|
|
460
|
-
}
|
|
461
|
-
if (!completed) {
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
|
-
var styleSheet = {
|
|
465
|
-
cssRules: cssRules,
|
|
466
|
-
disabled: cssStyleSheet.disabled || undefined,
|
|
467
|
-
media: cssStyleSheet.media.length > 0 ? Array.from(cssStyleSheet.media) : undefined
|
|
468
|
-
};
|
|
469
|
-
serializedStyleSheets.push(styleSheet);
|
|
470
|
-
}
|
|
471
|
-
return serializedStyleSheets;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Incrementally serializes constructable/adopted stylesheets. Unlike the
|
|
476
|
-
* legacy synchronous helper above, this task never treats a per-frame
|
|
477
|
-
* deadline, rule count, or the old 256 KiB watermark as a successful partial
|
|
478
|
-
* result. The owning DOM serializer publishes only after every readable rule
|
|
479
|
-
* has been copied, while still yielding between small rule batches.
|
|
480
|
-
*/
|
|
481
|
-
export function createStyleSheetsSerializerTask(cssStyleSheets) {
|
|
482
|
-
if (cssStyleSheets === undefined || cssStyleSheets.length === 0) {
|
|
483
|
-
return null;
|
|
484
|
-
}
|
|
485
|
-
var serializedStyleSheets = [];
|
|
486
|
-
var styleSheetIndex = 0;
|
|
487
|
-
var currentRules;
|
|
488
|
-
var currentRuleIndex = 0;
|
|
489
|
-
var currentSerializedStyleSheet;
|
|
490
|
-
var approxBytes = 0;
|
|
491
|
-
return {
|
|
492
|
-
serializedStyleSheets: serializedStyleSheets,
|
|
493
|
-
approxBytes: 0,
|
|
494
|
-
isComplete: false,
|
|
495
|
-
isMaxApproxBytesReached: false,
|
|
496
|
-
advance: function advance(deadline, maxApproxBytes, hardMaxApproxBytes) {
|
|
497
|
-
if (typeof maxApproxBytes !== 'number') {
|
|
498
|
-
maxApproxBytes = Number.MAX_SAFE_INTEGER;
|
|
499
|
-
}
|
|
500
|
-
if (typeof hardMaxApproxBytes !== 'number') {
|
|
501
|
-
hardMaxApproxBytes = maxApproxBytes;
|
|
502
|
-
}
|
|
503
|
-
hardMaxApproxBytes = Math.min(hardMaxApproxBytes, STYLESHEET_SERIALIZATION_MAX_SNAPSHOT_BYTES);
|
|
504
|
-
maxApproxBytes = Math.min(maxApproxBytes, hardMaxApproxBytes);
|
|
505
|
-
this.isMaxApproxBytesReached = false;
|
|
506
|
-
while (styleSheetIndex < cssStyleSheets.length) {
|
|
507
|
-
if (!currentRules) {
|
|
508
|
-
if (approxBytes + 32 > maxApproxBytes) {
|
|
509
|
-
if (approxBytes + 32 <= hardMaxApproxBytes) {
|
|
510
|
-
this.approxBytes = approxBytes;
|
|
511
|
-
this.isMaxApproxBytesReached = true;
|
|
512
|
-
return false;
|
|
513
|
-
}
|
|
514
|
-
if (approxBytes + 24 <= hardMaxApproxBytes && approxBytes + 24 > maxApproxBytes) {
|
|
515
|
-
this.approxBytes = approxBytes;
|
|
516
|
-
this.isMaxApproxBytesReached = true;
|
|
517
|
-
return false;
|
|
518
|
-
}
|
|
519
|
-
if (approxBytes + 24 <= hardMaxApproxBytes) {
|
|
520
|
-
serializedStyleSheets.push({
|
|
521
|
-
cssRules: [],
|
|
522
|
-
isTruncated: true
|
|
523
|
-
});
|
|
524
|
-
approxBytes += 24;
|
|
525
|
-
}
|
|
526
|
-
styleSheetIndex = cssStyleSheets.length;
|
|
527
|
-
break;
|
|
528
|
-
}
|
|
529
|
-
var cssStyleSheet = cssStyleSheets[styleSheetIndex];
|
|
530
|
-
currentRules = getReadableStyleSheetRules(cssStyleSheet);
|
|
531
|
-
currentRuleIndex = 0;
|
|
532
|
-
if (!currentRules) {
|
|
533
|
-
styleSheetIndex += 1;
|
|
534
|
-
continue;
|
|
535
|
-
}
|
|
536
|
-
currentSerializedStyleSheet = {
|
|
537
|
-
cssRules: [],
|
|
538
|
-
disabled: cssStyleSheet.disabled || undefined,
|
|
539
|
-
media: cssStyleSheet.media && cssStyleSheet.media.length > 0 ? Array.from(cssStyleSheet.media) : undefined
|
|
540
|
-
};
|
|
541
|
-
serializedStyleSheets.push(currentSerializedStyleSheet);
|
|
542
|
-
approxBytes += 32;
|
|
543
|
-
}
|
|
544
|
-
while (currentRuleIndex < currentRules.length) {
|
|
545
|
-
if (getSerializationTime() >= deadline) {
|
|
546
|
-
this.approxBytes = approxBytes;
|
|
547
|
-
return false;
|
|
548
|
-
}
|
|
549
|
-
var cssText = currentRules[currentRuleIndex].cssText;
|
|
550
|
-
if (typeof cssText !== 'string') {
|
|
551
|
-
currentRuleIndex += 1;
|
|
552
|
-
continue;
|
|
553
|
-
}
|
|
554
|
-
var cssTextApproxBytes = cssText.length * 2 + 8;
|
|
555
|
-
if (approxBytes + cssTextApproxBytes > maxApproxBytes) {
|
|
556
|
-
if (approxBytes + cssTextApproxBytes <= hardMaxApproxBytes) {
|
|
557
|
-
// The outer DOM serializer grows its byte watermark between
|
|
558
|
-
// FullSnapshot slices. Keep the current rule pending until that
|
|
559
|
-
// soft budget grows instead of turning a temporary yield into a
|
|
560
|
-
// permanently truncated stylesheet.
|
|
561
|
-
this.approxBytes = approxBytes;
|
|
562
|
-
this.isMaxApproxBytesReached = true;
|
|
563
|
-
return false;
|
|
564
|
-
}
|
|
565
|
-
if (approxBytes + 24 <= hardMaxApproxBytes && approxBytes + 24 > maxApproxBytes) {
|
|
566
|
-
this.approxBytes = approxBytes;
|
|
567
|
-
this.isMaxApproxBytesReached = true;
|
|
568
|
-
return false;
|
|
569
|
-
}
|
|
570
|
-
// Preserve complete CSS rules only. A partial rule can invalidate
|
|
571
|
-
// the remainder of the sheet in the player. The explicit marker
|
|
572
|
-
// makes this a local, diagnosable stylesheet degradation instead
|
|
573
|
-
// of a silent omission or a whole FullSnapshot failure.
|
|
574
|
-
if (approxBytes + 24 <= hardMaxApproxBytes) {
|
|
575
|
-
currentSerializedStyleSheet.isTruncated = true;
|
|
576
|
-
approxBytes += 24;
|
|
577
|
-
}
|
|
578
|
-
currentRuleIndex = currentRules.length;
|
|
579
|
-
break;
|
|
580
|
-
}
|
|
581
|
-
currentRuleIndex += 1;
|
|
582
|
-
currentSerializedStyleSheet.cssRules.push(cssText);
|
|
583
|
-
approxBytes += cssTextApproxBytes;
|
|
584
|
-
}
|
|
585
|
-
currentRules = undefined;
|
|
586
|
-
currentSerializedStyleSheet = undefined;
|
|
587
|
-
styleSheetIndex += 1;
|
|
588
|
-
}
|
|
589
|
-
this.approxBytes = approxBytes;
|
|
590
|
-
this.isComplete = true;
|
|
591
|
-
return true;
|
|
592
|
-
}
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
export function absoluteToDoc(doc, attributeValue) {
|
|
596
|
-
if (!attributeValue || attributeValue.trim() === '') {
|
|
597
|
-
return attributeValue;
|
|
598
|
-
}
|
|
599
|
-
var a = getAnchorElement(doc);
|
|
600
|
-
a.href = attributeValue;
|
|
601
|
-
return a.href;
|
|
602
|
-
}
|
|
603
|
-
function getAnchorElement(doc) {
|
|
604
|
-
var anchor = anchorElementByDocument.get(doc);
|
|
605
|
-
if (!anchor) {
|
|
606
|
-
anchor = doc.createElement('a');
|
|
607
|
-
anchorElementByDocument.set(doc, anchor);
|
|
608
|
-
}
|
|
609
|
-
return anchor;
|
|
610
|
-
}
|
|
611
|
-
function getDocumentHref(doc) {
|
|
612
|
-
var href = hrefByDocument.get(doc);
|
|
613
|
-
if (!href) {
|
|
614
|
-
var anchor = getAnchorElement(doc);
|
|
615
|
-
anchor.href = '';
|
|
616
|
-
href = anchor.href;
|
|
617
|
-
hrefByDocument.set(doc, href);
|
|
618
|
-
}
|
|
619
|
-
return href;
|
|
620
|
-
}
|
|
621
|
-
var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
|
|
622
|
-
var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
|
|
623
|
-
export function getAbsoluteSrcsetString(doc, attributeValue) {
|
|
624
|
-
if (attributeValue.trim() === '') {
|
|
625
|
-
return attributeValue;
|
|
626
|
-
}
|
|
627
|
-
var pos = 0;
|
|
628
|
-
function collectCharacters(regEx) {
|
|
629
|
-
var chars;
|
|
630
|
-
var match = regEx.exec(attributeValue.substring(pos));
|
|
631
|
-
if (match) {
|
|
632
|
-
chars = match[0];
|
|
633
|
-
pos += chars.length;
|
|
634
|
-
return chars;
|
|
635
|
-
}
|
|
636
|
-
return '';
|
|
637
|
-
}
|
|
638
|
-
var output = [];
|
|
639
|
-
while (true) {
|
|
640
|
-
collectCharacters(SRCSET_COMMAS_OR_SPACES);
|
|
641
|
-
if (pos >= attributeValue.length) {
|
|
642
|
-
break;
|
|
643
|
-
}
|
|
644
|
-
var url = collectCharacters(SRCSET_NOT_SPACES);
|
|
645
|
-
if (url.slice(-1) === ',') {
|
|
646
|
-
url = absoluteToDoc(doc, url.substring(0, url.length - 1));
|
|
647
|
-
output.push(url);
|
|
648
|
-
} else {
|
|
649
|
-
var descriptorsStr = '';
|
|
650
|
-
url = absoluteToDoc(doc, url);
|
|
651
|
-
var inParens = false;
|
|
652
|
-
while (true) {
|
|
653
|
-
var c = attributeValue.charAt(pos);
|
|
654
|
-
if (c === '') {
|
|
655
|
-
output.push((url + descriptorsStr).trim());
|
|
656
|
-
break;
|
|
657
|
-
} else if (!inParens) {
|
|
658
|
-
if (c === ',') {
|
|
659
|
-
pos += 1;
|
|
660
|
-
output.push((url + descriptorsStr).trim());
|
|
661
|
-
break;
|
|
662
|
-
} else if (c === '(') {
|
|
663
|
-
inParens = true;
|
|
664
|
-
}
|
|
665
|
-
} else {
|
|
666
|
-
if (c === ')') {
|
|
667
|
-
inParens = false;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
descriptorsStr += c;
|
|
671
|
-
pos += 1;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
return output.join(', ');
|
|
676
|
-
}
|
|
677
|
-
//# sourceMappingURL=serializationUtils.js.map
|
|
1
|
+
import{getParentNode,isNodeShadowRoot,buildUrl,isSafari}from"@cloudcare/browser-core";import{CENSORED_STRING_MARK}from"../../../constants";import{shouldMaskNode}from"./privacy";var serializedNodeIds=new WeakMap;export var MAX_SERIALIZED_CANVAS_REGISTRY_SIZE=2048;export var MAX_SERIALIZED_NODE_ANCESTOR_DEPTH=1e3;export var STYLESHEET_SERIALIZATION_MAX_RULE_COUNT=5e3;export var STYLESHEET_SERIALIZATION_MAX_CHARACTER_COUNT=262144;export var STYLESHEET_SERIALIZATION_MAX_DURATION_MS=4;export var STYLESHEET_SERIALIZATION_MAX_SNAPSHOT_BYTES=524288;var serializedCanvasEntries=[],serializedCanvasFreeEntryIndexes=[],serializedCanvasEntryByNode=new WeakMap,serializedCanvasEntryCount=0,serializedCanvasNextEvictionIndex=0,serializedCanvasScanCursor=0,serializedCanvasScanRemaining=0,serializedCanvasTrackingCount=0,anchorElementByDocument=new WeakMap,hrefByDocument=new WeakMap;export function getHiddenElementPlaceholderSize(element){return{width:element.getAttribute("width")||element.style&&element.style.width||void 0,height:element.getAttribute("height")||element.style&&element.style.height||void 0}}export function hasSerializedNode(node){return serializedNodeIds.has(node)}export function nodeAndAncestorsHaveSerializedNode(node){for(var current=node,depth=0;current;){if(depth>=MAX_SERIALIZED_NODE_ANCESTOR_DEPTH)return!1;if(!hasSerializedNode(current)&&!isNodeShadowRoot(current))return!1;depth+=1,current=getParentNode(current)}return!0}export function getSerializedNodeId(node){return serializedNodeIds.get(node)}export function setSerializedNodeId(node,serializeNodeId){serializedNodeIds.set(node,serializeNodeId),serializedCanvasTrackingCount&&"CANVAS"===node.tagName&&function registerSerializedCanvasNode(node){var existingEntry=serializedCanvasEntryByNode.get(node);if(existingEntry&&existingEntry.active)return;var entryIndex,entry={active:!0,weakRef:"function"==typeof WeakRef?new WeakRef(node):void 0,node:"function"==typeof WeakRef?void 0:node};if(serializedCanvasFreeEntryIndexes.length)entryIndex=serializedCanvasFreeEntryIndexes.pop();else if(serializedCanvasEntries.length<MAX_SERIALIZED_CANVAS_REGISTRY_SIZE)entryIndex=serializedCanvasEntries.length;else{entryIndex=serializedCanvasNextEvictionIndex,serializedCanvasNextEvictionIndex=(serializedCanvasNextEvictionIndex+1)%MAX_SERIALIZED_CANVAS_REGISTRY_SIZE;var evictedEntry=serializedCanvasEntries[entryIndex];evictedEntry&&evictedEntry.active&&(evictedEntry.active=!1,serializedCanvasEntryCount-=1)}entry.index=entryIndex,serializedCanvasEntries[entryIndex]=entry,serializedCanvasEntryByNode.set(node,entry),serializedCanvasEntryCount+=1}(node)}export function startSerializedCanvasTracking(){serializedCanvasTrackingCount+=1;var stopped=!1;return function stopSerializedCanvasTracking(){stopped||(stopped=!0,0===(serializedCanvasTrackingCount-=1)&&function clearSerializedCanvasRegistry(){serializedCanvasEntries=[],serializedCanvasFreeEntryIndexes=[],serializedCanvasEntryByNode=new WeakMap,serializedCanvasEntryCount=0,serializedCanvasNextEvictionIndex=0,resetSerializedCanvasScan()}())}}function isSerializedCanvasConnectedToDocument(node){var isConnected=node.isConnected;if("boolean"==typeof isConnected)return isConnected;for(var current=node;current;){if(current===document)return!0;current=getParentNode(current)}return!1}function getSerializedCanvasEntryNode(entry){if(entry&&entry.active)return entry.weakRef?entry.weakRef.deref():entry.node}function pruneSerializedCanvasEntry(entry){entry&&entry.active&&(entry.active=!1,entry.node=void 0,serializedCanvasEntries[entry.index]===entry&&(serializedCanvasEntries[entry.index]=void 0,serializedCanvasFreeEntryIndexes.push(entry.index)),serializedCanvasEntryCount=Math.max(serializedCanvasEntryCount-1,0))}function resetSerializedCanvasScan(){serializedCanvasScanCursor=0,serializedCanvasScanRemaining=0}export function getSerializedCanvasNodes(maxScanCount){if("number"==typeof maxScanCount)return function getSerializedCanvasNodesWithinScanLimit(maxScanCount){var scanLimit=Math.max(Math.floor(maxScanCount),0);if(!isFinite(scanLimit)||0===scanLimit||!serializedCanvasEntryCount||!serializedCanvasEntries.length)return[];serializedCanvasScanRemaining||(serializedCanvasScanCursor=0,serializedCanvasScanRemaining=serializedCanvasEntries.length);var connectedSerializedCanvasNodes=[],scannedNodeCount=0;for(;scannedNodeCount<scanLimit&&serializedCanvasScanRemaining>0;){var entry=serializedCanvasEntries[serializedCanvasScanCursor];serializedCanvasScanCursor=(serializedCanvasScanCursor+1)%serializedCanvasEntries.length,scannedNodeCount+=1,serializedCanvasScanRemaining-=1;var node=getSerializedCanvasEntryNode(entry);hasSerializedNode(node)&&isSerializedCanvasConnectedToDocument(node)?connectedSerializedCanvasNodes.push(node):pruneSerializedCanvasEntry(entry)}0===serializedCanvasScanRemaining&&resetSerializedCanvasScan();return connectedSerializedCanvasNodes}(maxScanCount);for(var connectedSerializedCanvasNodes=[],entryIndex=0;entryIndex<serializedCanvasEntries.length;entryIndex+=1){var entry=serializedCanvasEntries[entryIndex],node=getSerializedCanvasEntryNode(entry);hasSerializedNode(node)&&isSerializedCanvasConnectedToDocument(node)?connectedSerializedCanvasNodes.push(node):pruneSerializedCanvasEntry(entry)}return resetSerializedCanvasScan(),connectedSerializedCanvasNodes}export function getSerializedCanvasNodesSnapshot(maxScanCount){var resultLimit=Math.max(Math.floor(maxScanCount),0);if(!isFinite(resultLimit)||0===resultLimit||!serializedCanvasEntryCount||!serializedCanvasEntries.length)return[];for(var connectedSerializedCanvasNodes=[],entryIndex=0;entryIndex<serializedCanvasEntries.length&&connectedSerializedCanvasNodes.length<resultLimit;entryIndex+=1){var entry=serializedCanvasEntries[entryIndex],node=getSerializedCanvasEntryNode(entry);hasSerializedNode(node)&&isSerializedCanvasConnectedToDocument(node)?connectedSerializedCanvasNodes.push(node):pruneSerializedCanvasEntry(entry)}return connectedSerializedCanvasNodes}export function getElementInputValue(configuration,element,nodePrivacyLevel){var tagName=element.tagName,value=element.value;if(shouldMaskNode(configuration,element,nodePrivacyLevel)){var type=element.type;if("INPUT"===tagName&&("button"===type||"submit"===type||"reset"===type||"range"===type))return value;if(!value||"OPTION"===tagName)return;return CENSORED_STRING_MARK}return"OPTION"===tagName||"SELECT"===tagName?element.value:"INPUT"===tagName||"TEXTAREA"===tagName?value:void 0}export var URL_IN_CSS_REF=/url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm;export var ABSOLUTE_URL=/^[A-Za-z]+:|^\/\//;export var DATA_URI=/^data:.*,/i;export function fixBrowserCompatibilityIssuesInCSS(cssText){return cssText.includes(" background-clip: text;")&&!cssText.includes(" -webkit-background-clip: text;")&&(cssText=cssText.replace(" background-clip: text;"," -webkit-background-clip: text; background-clip: text;")),cssText}export function getHref(){return function getDocumentHref(doc){var href=hrefByDocument.get(doc);if(!href){var anchor=getAnchorElement(doc);anchor.href="",href=anchor.href,hrefByDocument.set(doc,href)}return href}(document)}export function switchToAbsoluteUrl(cssText,cssHref){return cssText.replace(URL_IN_CSS_REF,(function(matchingSubstring,singleQuote,urlWrappedInSingleQuotes,doubleQuote,urlWrappedInDoubleQuotes,urlNotWrappedInQuotes){var url=urlWrappedInSingleQuotes||urlWrappedInDoubleQuotes||urlNotWrappedInQuotes;if(!cssHref||!url||ABSOLUTE_URL.test(url)||DATA_URI.test(url))return matchingSubstring;var quote=singleQuote||doubleQuote||"";return"/"===url[0]?"url(".concat(quote).concat(function extractOrigin(url){return(url.indexOf("//")>-1?url.split("/").slice(0,3).join("/"):url.split("/")[0]).split("?")[0]}(cssHref)+url).concat(quote,")"):"url(".concat(quote).concat(makeUrlAbsolute(url,cssHref)).concat(quote,")")}))}export function getCssRulesString(cssStyleSheet,maxCharacterCount){if(!cssStyleSheet)return null;var rootRules=getReadableStyleSheetRules(cssStyleSheet);if(!rootRules)return null;var serializationState={parts:[],visitedStyleSheets:new Set,characterCount:0,characterLimit:"number"==typeof maxCharacterCount?maxCharacterCount:1/0};if(!appendStyleSheetRules(cssStyleSheet,serializationState,cssStyleSheet.href,rootRules))return null;var styleSheetCssText=fixBrowserCompatibilityIssuesInCSS(serializationState.parts.join(""));return styleSheetCssText.length>serializationState.characterLimit?null:styleSheetCssText}function appendStyleSheetRules(cssStyleSheet,serializationState,inheritedHref,knownRules){if(!cssStyleSheet||serializationState.visitedStyleSheets.has(cssStyleSheet))return!0;serializationState.visitedStyleSheets.add(cssStyleSheet);var styleSheetHref=cssStyleSheet.href||inheritedHref,rules=knownRules||getReadableStyleSheetRules(cssStyleSheet);if(!rules)return!1;for(var ruleIndex=0;ruleIndex<rules.length;ruleIndex+=1){var rule=rules[ruleIndex];if(isCSSImportRule(rule)){var importedHref=rule.styleSheet&&rule.styleSheet.href||(rule.href&&styleSheetHref?makeUrlAbsolute(rule.href,styleSheetHref):rule.href),importedRules=getReadableStyleSheetRules(rule.styleSheet);if(importedRules){if(!appendStyleSheetRules(rule.styleSheet,serializationState,importedHref,importedRules))return!1}else if(!appendStyleSheetRuleText(rule,serializationState,styleSheetHref,!1))return!1}else if(!appendStyleSheetRuleText(rule,serializationState,styleSheetHref,!0))return!1}return!0}function getReadableStyleSheetRules(cssStyleSheet){if(cssStyleSheet)try{return cssStyleSheet.rules||cssStyleSheet.cssRules}catch(_){}}function appendStyleSheetRuleText(rule,serializationState,styleSheetHref,shouldPatchSafari){var rawRuleText=rule&&rule.cssText;if("string"!=typeof rawRuleText)return!0;if(serializationState.characterCount+rawRuleText.length>serializationState.characterLimit)return!1;var ruleText=shouldPatchSafari&&isSafari()?function getCssRuleStringForSafari(rule){if(function isCSSStyleRule(rule){return"selectorText"in rule}(rule)&&rule.selectorText.includes(":")){var escapeColon=/(\[[\w-]+[^\\])(:[^\]]+\])/g;return rule.cssText.replace(escapeColon,"$1\\$2")}return getCssRuleString(rule)}(rule):rawRuleText;return ruleText=switchToAbsoluteUrl(ruleText,styleSheetHref),!(serializationState.characterCount+ruleText.length>serializationState.characterLimit)&&(serializationState.characterCount+=ruleText.length,serializationState.parts.push(ruleText),!0)}function hasStyleSheetSerializationBudget(serializationState,additionalCharacterCount,shouldCountRule){return void 0===additionalCharacterCount&&(additionalCharacterCount=0),void 0===shouldCountRule&&(shouldCountRule=!0),!(serializationState.exceeded||shouldCountRule&&serializationState.ruleCount>=STYLESHEET_SERIALIZATION_MAX_RULE_COUNT||serializationState.characterCount+additionalCharacterCount>(serializationState.characterLimit||STYLESHEET_SERIALIZATION_MAX_CHARACTER_COUNT)||getSerializationTime()>serializationState.deadline)||(serializationState.exceeded=!0,!1)}function getSerializationTime(){return"undefined"!=typeof performance&&performance.now?performance.now():Date.now()}export function isCSSImportRule(rule){return"styleSheet"in rule}export function isSVGElement(el){return"svg"===el.tagName||el instanceof SVGElement}export function getCssRuleString(rule){return isCSSImportRule(rule)&&getCssRulesString(rule.styleSheet)||rule.cssText}export function makeUrlAbsolute(url,baseUrl){try{return buildUrl(url,baseUrl).href}catch(_){return url}}export function serializeStyleSheets(cssStyleSheets){if(void 0!==cssStyleSheets&&0!==cssStyleSheets.length){for(var serializedStyleSheets=[],serializationState={ruleCount:0,characterCount:0,deadline:getSerializationTime()+STYLESHEET_SERIALIZATION_MAX_DURATION_MS,exceeded:!1},styleSheetIndex=0;styleSheetIndex<cssStyleSheets.length;styleSheetIndex+=1){var cssStyleSheet=cssStyleSheets[styleSheetIndex];if(!hasStyleSheetSerializationBudget(serializationState,0,!1))break;var rules=getReadableStyleSheetRules(cssStyleSheet);if(rules){for(var cssRules=[],completed=!0,ruleIndex=0;ruleIndex<rules.length;ruleIndex+=1){var cssText=rules[ruleIndex].cssText;if("string"==typeof cssText){if(!hasStyleSheetSerializationBudget(serializationState,cssText.length)){completed=!1;break}serializationState.ruleCount+=1,serializationState.characterCount+=cssText.length,cssRules.push(cssText)}}if(!completed)break;var styleSheet={cssRules:cssRules,disabled:cssStyleSheet.disabled||void 0,media:cssStyleSheet.media.length>0?Array.from(cssStyleSheet.media):void 0};serializedStyleSheets.push(styleSheet)}}return serializedStyleSheets}}export function createStyleSheetsSerializerTask(cssStyleSheets){if(void 0===cssStyleSheets||0===cssStyleSheets.length)return null;var currentRules,currentSerializedStyleSheet,serializedStyleSheets=[],styleSheetIndex=0,currentRuleIndex=0,approxBytes=0;return{serializedStyleSheets:serializedStyleSheets,approxBytes:0,isComplete:!1,isMaxApproxBytesReached:!1,advance:function advance(deadline,maxApproxBytes,hardMaxApproxBytes){for("number"!=typeof maxApproxBytes&&(maxApproxBytes=Number.MAX_SAFE_INTEGER),"number"!=typeof hardMaxApproxBytes&&(hardMaxApproxBytes=maxApproxBytes),hardMaxApproxBytes=Math.min(hardMaxApproxBytes,STYLESHEET_SERIALIZATION_MAX_SNAPSHOT_BYTES),maxApproxBytes=Math.min(maxApproxBytes,hardMaxApproxBytes),this.isMaxApproxBytesReached=!1;styleSheetIndex<cssStyleSheets.length;){if(!currentRules){if(approxBytes+32>maxApproxBytes){if(approxBytes+32<=hardMaxApproxBytes)return this.approxBytes=approxBytes,this.isMaxApproxBytesReached=!0,!1;if(approxBytes+24<=hardMaxApproxBytes&&approxBytes+24>maxApproxBytes)return this.approxBytes=approxBytes,this.isMaxApproxBytesReached=!0,!1;approxBytes+24<=hardMaxApproxBytes&&(serializedStyleSheets.push({cssRules:[],isTruncated:!0}),approxBytes+=24),styleSheetIndex=cssStyleSheets.length;break}var cssStyleSheet=cssStyleSheets[styleSheetIndex];if(currentRules=getReadableStyleSheetRules(cssStyleSheet),currentRuleIndex=0,!currentRules){styleSheetIndex+=1;continue}currentSerializedStyleSheet={cssRules:[],disabled:cssStyleSheet.disabled||void 0,media:cssStyleSheet.media&&cssStyleSheet.media.length>0?Array.from(cssStyleSheet.media):void 0},serializedStyleSheets.push(currentSerializedStyleSheet),approxBytes+=32}for(;currentRuleIndex<currentRules.length;){if(getSerializationTime()>=deadline)return this.approxBytes=approxBytes,!1;var cssText=currentRules[currentRuleIndex].cssText;if("string"==typeof cssText){var cssTextApproxBytes=2*cssText.length+8;if(approxBytes+cssTextApproxBytes>maxApproxBytes){if(approxBytes+cssTextApproxBytes<=hardMaxApproxBytes)return this.approxBytes=approxBytes,this.isMaxApproxBytesReached=!0,!1;if(approxBytes+24<=hardMaxApproxBytes&&approxBytes+24>maxApproxBytes)return this.approxBytes=approxBytes,this.isMaxApproxBytesReached=!0,!1;approxBytes+24<=hardMaxApproxBytes&&(currentSerializedStyleSheet.isTruncated=!0,approxBytes+=24),currentRuleIndex=currentRules.length;break}currentRuleIndex+=1,currentSerializedStyleSheet.cssRules.push(cssText),approxBytes+=cssTextApproxBytes}else currentRuleIndex+=1}currentRules=void 0,currentSerializedStyleSheet=void 0,styleSheetIndex+=1}return this.approxBytes=approxBytes,this.isComplete=!0,!0}}}export function absoluteToDoc(doc,attributeValue){if(!attributeValue||""===attributeValue.trim())return attributeValue;var a=getAnchorElement(doc);return a.href=attributeValue,a.href}function getAnchorElement(doc){var anchor=anchorElementByDocument.get(doc);return anchor||(anchor=doc.createElement("a"),anchorElementByDocument.set(doc,anchor)),anchor}var SRCSET_NOT_SPACES=/^[^ \t\n\r\u000c]+/,SRCSET_COMMAS_OR_SPACES=/^[, \t\n\r\u000c]+/;export function getAbsoluteSrcsetString(doc,attributeValue){if(""===attributeValue.trim())return attributeValue;var pos=0;function collectCharacters(regEx){var chars,match=regEx.exec(attributeValue.substring(pos));return match?(chars=match[0],pos+=chars.length,chars):""}for(var output=[];collectCharacters(SRCSET_COMMAS_OR_SPACES),!(pos>=attributeValue.length);){var url=collectCharacters(SRCSET_NOT_SPACES);if(","===url.slice(-1))url=absoluteToDoc(doc,url.substring(0,url.length-1)),output.push(url);else{var descriptorsStr="";url=absoluteToDoc(doc,url);for(var inParens=!1;;){var c=attributeValue.charAt(pos);if(""===c){output.push((url+descriptorsStr).trim());break}if(inParens)")"===c&&(inParens=!1);else{if(","===c){pos+=1,output.push((url+descriptorsStr).trim());break}"("===c&&(inParens=!0)}descriptorsStr+=c,pos+=1}}}return output.join(", ")}
|
|
2
|
+
//# sourceMappingURL=serializationUtils.js.map
|