clarity-js 0.8.42 → 0.8.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -26
- package/build/clarity.extended.js +1 -1
- package/build/clarity.insight.js +1 -1
- package/build/clarity.js +6101 -6071
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +6101 -6071
- package/build/clarity.performance.js +1 -1
- package/package.json +70 -70
- package/rollup.config.ts +161 -161
- package/src/clarity.ts +65 -65
- package/src/core/api.ts +8 -8
- package/src/core/config.ts +29 -29
- package/src/core/copy.ts +3 -3
- package/src/core/dynamic.ts +13 -7
- package/src/core/event.ts +53 -53
- package/src/core/hash.ts +19 -19
- package/src/core/history.ts +71 -71
- package/src/core/index.ts +81 -81
- package/src/core/measure.ts +19 -19
- package/src/core/report.ts +28 -28
- package/src/core/scrub.ts +204 -202
- package/src/core/task.ts +181 -181
- package/src/core/throttle.ts +46 -46
- package/src/core/time.ts +26 -26
- package/src/core/timeout.ts +10 -10
- package/src/core/version.ts +2 -2
- package/src/data/baseline.ts +162 -162
- package/src/data/compress.ts +31 -31
- package/src/data/consent.ts +77 -77
- package/src/data/cookie.ts +90 -0
- package/src/data/custom.ts +23 -23
- package/src/data/dimension.ts +53 -53
- package/src/data/encode.ts +155 -155
- package/src/data/envelope.ts +53 -53
- package/src/data/extract.ts +211 -211
- package/src/data/index.ts +51 -50
- package/src/data/limit.ts +44 -44
- package/src/data/metadata.ts +321 -408
- package/src/data/metric.ts +51 -51
- package/src/data/ping.ts +36 -36
- package/src/data/signal.ts +30 -30
- package/src/data/summary.ts +34 -34
- package/src/data/token.ts +39 -39
- package/src/data/upgrade.ts +44 -44
- package/src/data/upload.ts +333 -333
- package/src/data/util.ts +18 -0
- package/src/data/variable.ts +83 -83
- package/src/diagnostic/encode.ts +40 -40
- package/src/diagnostic/fraud.ts +36 -36
- package/src/diagnostic/index.ts +13 -13
- package/src/diagnostic/internal.ts +28 -28
- package/src/diagnostic/script.ts +35 -35
- package/src/dynamic/agent/blank.ts +2 -2
- package/src/dynamic/agent/crisp.ts +40 -40
- package/src/dynamic/agent/encode.ts +25 -25
- package/src/dynamic/agent/index.ts +8 -8
- package/src/dynamic/agent/livechat.ts +58 -58
- package/src/dynamic/agent/tidio.ts +44 -44
- package/src/global.ts +6 -6
- package/src/index.ts +9 -9
- package/src/insight/blank.ts +14 -14
- package/src/insight/encode.ts +60 -60
- package/src/insight/snapshot.ts +114 -114
- package/src/interaction/change.ts +38 -38
- package/src/interaction/click.ts +173 -173
- package/src/interaction/clipboard.ts +32 -32
- package/src/interaction/encode.ts +210 -210
- package/src/interaction/index.ts +60 -60
- package/src/interaction/input.ts +57 -57
- package/src/interaction/pointer.ts +137 -137
- package/src/interaction/resize.ts +50 -50
- package/src/interaction/scroll.ts +129 -129
- package/src/interaction/selection.ts +66 -66
- package/src/interaction/submit.ts +30 -30
- package/src/interaction/timeline.ts +69 -69
- package/src/interaction/unload.ts +26 -26
- package/src/interaction/visibility.ts +27 -27
- package/src/layout/animation.ts +133 -133
- package/src/layout/custom.ts +42 -42
- package/src/layout/discover.ts +31 -31
- package/src/layout/document.ts +46 -46
- package/src/layout/dom.ts +439 -439
- package/src/layout/encode.ts +154 -154
- package/src/layout/index.ts +42 -42
- package/src/layout/mutation.ts +411 -411
- package/src/layout/node.ts +294 -294
- package/src/layout/offset.ts +19 -19
- package/src/layout/region.ts +151 -151
- package/src/layout/schema.ts +63 -63
- package/src/layout/selector.ts +82 -82
- package/src/layout/style.ts +159 -159
- package/src/layout/target.ts +32 -32
- package/src/layout/traverse.ts +27 -27
- package/src/performance/blank.ts +9 -9
- package/src/performance/encode.ts +31 -31
- package/src/performance/index.ts +12 -12
- package/src/performance/interaction.ts +125 -125
- package/src/performance/navigation.ts +31 -31
- package/src/performance/observer.ts +112 -112
- package/src/queue.ts +33 -33
- package/test/core.test.ts +139 -139
- package/test/helper.ts +162 -162
- package/test/html/core.html +27 -27
- package/test/stub.test.ts +7 -7
- package/test/tsconfig.test.json +5 -5
- package/tsconfig.json +21 -21
- package/tslint.json +32 -32
- package/types/agent.d.ts +39 -39
- package/types/core.d.ts +150 -150
- package/types/data.d.ts +572 -571
- package/types/diagnostic.d.ts +24 -24
- package/types/global.d.ts +30 -30
- package/types/index.d.ts +40 -40
- package/types/interaction.d.ts +177 -177
- package/types/layout.d.ts +276 -276
- package/types/performance.d.ts +31 -31
package/src/layout/animation.ts
CHANGED
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
import { Event } from "@clarity-types/data";
|
|
2
|
-
import { AnimationOperation, AnimationState } from "@clarity-types/layout";
|
|
3
|
-
import { time } from "@src/core/time";
|
|
4
|
-
import { shortid } from "@src/data/metadata";
|
|
5
|
-
import encode from "@src/layout/encode";
|
|
6
|
-
import { getId } from "@src/layout/dom";
|
|
7
|
-
import * as core from "@src/core";
|
|
8
|
-
|
|
9
|
-
export let state: AnimationState[] = [];
|
|
10
|
-
let elementAnimate: (keyframes: Keyframe[] | PropertyIndexedKeyframes, options?: number | KeyframeAnimationOptions) => Animation = null;
|
|
11
|
-
let animationPlay: () => void = null;
|
|
12
|
-
let animationPause: () => void = null;
|
|
13
|
-
let animationCommitStyles: () => void = null;
|
|
14
|
-
let animationCancel: () => void = null;
|
|
15
|
-
let animationFinish: () => void = null;
|
|
16
|
-
const animationId = 'clarityAnimationId';
|
|
17
|
-
const operationCount = 'clarityOperationCount';
|
|
18
|
-
const maxOperations = 20;
|
|
19
|
-
|
|
20
|
-
export function start(): void {
|
|
21
|
-
if (
|
|
22
|
-
window["Animation"] &&
|
|
23
|
-
window["Animation"].prototype &&
|
|
24
|
-
window["KeyframeEffect"] &&
|
|
25
|
-
window["KeyframeEffect"].prototype &&
|
|
26
|
-
window["KeyframeEffect"].prototype.getKeyframes &&
|
|
27
|
-
window["KeyframeEffect"].prototype.getTiming
|
|
28
|
-
) {
|
|
29
|
-
reset();
|
|
30
|
-
overrideAnimationHelper(animationPlay, "play");
|
|
31
|
-
overrideAnimationHelper(animationPause, "pause");
|
|
32
|
-
overrideAnimationHelper(animationCommitStyles, "commitStyles");
|
|
33
|
-
overrideAnimationHelper(animationCancel, "cancel");
|
|
34
|
-
overrideAnimationHelper(animationFinish, "finish");
|
|
35
|
-
if (elementAnimate === null) {
|
|
36
|
-
elementAnimate = Element.prototype.animate;
|
|
37
|
-
Element.prototype.animate = function(): Animation {
|
|
38
|
-
var createdAnimation = elementAnimate.apply(this, arguments);
|
|
39
|
-
trackAnimationOperation(createdAnimation, "play");
|
|
40
|
-
return createdAnimation;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (document.getAnimations) {
|
|
44
|
-
for (var animation of document.getAnimations()) {
|
|
45
|
-
if (animation.playState === "finished") {
|
|
46
|
-
trackAnimationOperation(animation, "finish");
|
|
47
|
-
}
|
|
48
|
-
else if (animation.playState === "paused" || animation.playState === "idle") {
|
|
49
|
-
trackAnimationOperation(animation, "pause");
|
|
50
|
-
}
|
|
51
|
-
else if (animation.playState === "running") {
|
|
52
|
-
trackAnimationOperation(animation, "play");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function reset(): void {
|
|
60
|
-
state = [];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function track(time: number, id: string, operation: AnimationOperation, keyFrames?: string, timing?: string, targetId?: number, timeline?: string): void {
|
|
64
|
-
state.push({
|
|
65
|
-
time,
|
|
66
|
-
event: Event.Animation,
|
|
67
|
-
data: {
|
|
68
|
-
id,
|
|
69
|
-
operation,
|
|
70
|
-
keyFrames,
|
|
71
|
-
timing,
|
|
72
|
-
targetId,
|
|
73
|
-
timeline
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
encode(Event.Animation);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function stop(): void {
|
|
81
|
-
reset();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function overrideAnimationHelper(functionToOverride: () => void, name: string) {
|
|
85
|
-
if (functionToOverride === null) {
|
|
86
|
-
functionToOverride = Animation.prototype[name];
|
|
87
|
-
Animation.prototype[name] = function(): void {
|
|
88
|
-
trackAnimationOperation(this, name);
|
|
89
|
-
return functionToOverride.apply(this, arguments);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function trackAnimationOperation(animation: Animation, name: string) {
|
|
95
|
-
if (core.active()) {
|
|
96
|
-
let effect = <KeyframeEffect>animation.effect;
|
|
97
|
-
let target = effect?.target ? getId(effect.target) : null;
|
|
98
|
-
if (target !== null && effect.getKeyframes && effect.getTiming) {
|
|
99
|
-
if (!animation[animationId]) {
|
|
100
|
-
animation[animationId] = shortid();
|
|
101
|
-
animation[operationCount] = 0;
|
|
102
|
-
|
|
103
|
-
let keyframes = effect.getKeyframes();
|
|
104
|
-
let timing = effect.getTiming();
|
|
105
|
-
track(time(), animation[animationId], AnimationOperation.Create, JSON.stringify(keyframes), JSON.stringify(timing), target);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (animation[operationCount]++ < maxOperations) {
|
|
109
|
-
let operation: AnimationOperation = null;
|
|
110
|
-
switch (name) {
|
|
111
|
-
case "play":
|
|
112
|
-
operation = AnimationOperation.Play;
|
|
113
|
-
break;
|
|
114
|
-
case "pause":
|
|
115
|
-
operation = AnimationOperation.Pause;
|
|
116
|
-
break;
|
|
117
|
-
case "cancel":
|
|
118
|
-
operation = AnimationOperation.Cancel;
|
|
119
|
-
break;
|
|
120
|
-
case "finish":
|
|
121
|
-
operation = AnimationOperation.Finish;
|
|
122
|
-
break;
|
|
123
|
-
case "commitStyles":
|
|
124
|
-
operation = AnimationOperation.CommitStyles;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
if (operation) {
|
|
128
|
-
track(time(), animation[animationId], operation);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
1
|
+
import { Event } from "@clarity-types/data";
|
|
2
|
+
import { AnimationOperation, AnimationState } from "@clarity-types/layout";
|
|
3
|
+
import { time } from "@src/core/time";
|
|
4
|
+
import { shortid } from "@src/data/metadata";
|
|
5
|
+
import encode from "@src/layout/encode";
|
|
6
|
+
import { getId } from "@src/layout/dom";
|
|
7
|
+
import * as core from "@src/core";
|
|
8
|
+
|
|
9
|
+
export let state: AnimationState[] = [];
|
|
10
|
+
let elementAnimate: (keyframes: Keyframe[] | PropertyIndexedKeyframes, options?: number | KeyframeAnimationOptions) => Animation = null;
|
|
11
|
+
let animationPlay: () => void = null;
|
|
12
|
+
let animationPause: () => void = null;
|
|
13
|
+
let animationCommitStyles: () => void = null;
|
|
14
|
+
let animationCancel: () => void = null;
|
|
15
|
+
let animationFinish: () => void = null;
|
|
16
|
+
const animationId = 'clarityAnimationId';
|
|
17
|
+
const operationCount = 'clarityOperationCount';
|
|
18
|
+
const maxOperations = 20;
|
|
19
|
+
|
|
20
|
+
export function start(): void {
|
|
21
|
+
if (
|
|
22
|
+
window["Animation"] &&
|
|
23
|
+
window["Animation"].prototype &&
|
|
24
|
+
window["KeyframeEffect"] &&
|
|
25
|
+
window["KeyframeEffect"].prototype &&
|
|
26
|
+
window["KeyframeEffect"].prototype.getKeyframes &&
|
|
27
|
+
window["KeyframeEffect"].prototype.getTiming
|
|
28
|
+
) {
|
|
29
|
+
reset();
|
|
30
|
+
overrideAnimationHelper(animationPlay, "play");
|
|
31
|
+
overrideAnimationHelper(animationPause, "pause");
|
|
32
|
+
overrideAnimationHelper(animationCommitStyles, "commitStyles");
|
|
33
|
+
overrideAnimationHelper(animationCancel, "cancel");
|
|
34
|
+
overrideAnimationHelper(animationFinish, "finish");
|
|
35
|
+
if (elementAnimate === null) {
|
|
36
|
+
elementAnimate = Element.prototype.animate;
|
|
37
|
+
Element.prototype.animate = function(): Animation {
|
|
38
|
+
var createdAnimation = elementAnimate.apply(this, arguments);
|
|
39
|
+
trackAnimationOperation(createdAnimation, "play");
|
|
40
|
+
return createdAnimation;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (document.getAnimations) {
|
|
44
|
+
for (var animation of document.getAnimations()) {
|
|
45
|
+
if (animation.playState === "finished") {
|
|
46
|
+
trackAnimationOperation(animation, "finish");
|
|
47
|
+
}
|
|
48
|
+
else if (animation.playState === "paused" || animation.playState === "idle") {
|
|
49
|
+
trackAnimationOperation(animation, "pause");
|
|
50
|
+
}
|
|
51
|
+
else if (animation.playState === "running") {
|
|
52
|
+
trackAnimationOperation(animation, "play");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function reset(): void {
|
|
60
|
+
state = [];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function track(time: number, id: string, operation: AnimationOperation, keyFrames?: string, timing?: string, targetId?: number, timeline?: string): void {
|
|
64
|
+
state.push({
|
|
65
|
+
time,
|
|
66
|
+
event: Event.Animation,
|
|
67
|
+
data: {
|
|
68
|
+
id,
|
|
69
|
+
operation,
|
|
70
|
+
keyFrames,
|
|
71
|
+
timing,
|
|
72
|
+
targetId,
|
|
73
|
+
timeline
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
encode(Event.Animation);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function stop(): void {
|
|
81
|
+
reset();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function overrideAnimationHelper(functionToOverride: () => void, name: string) {
|
|
85
|
+
if (functionToOverride === null) {
|
|
86
|
+
functionToOverride = Animation.prototype[name];
|
|
87
|
+
Animation.prototype[name] = function(): void {
|
|
88
|
+
trackAnimationOperation(this, name);
|
|
89
|
+
return functionToOverride.apply(this, arguments);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function trackAnimationOperation(animation: Animation, name: string) {
|
|
95
|
+
if (core.active()) {
|
|
96
|
+
let effect = <KeyframeEffect>animation.effect;
|
|
97
|
+
let target = effect?.target ? getId(effect.target) : null;
|
|
98
|
+
if (target !== null && effect.getKeyframes && effect.getTiming) {
|
|
99
|
+
if (!animation[animationId]) {
|
|
100
|
+
animation[animationId] = shortid();
|
|
101
|
+
animation[operationCount] = 0;
|
|
102
|
+
|
|
103
|
+
let keyframes = effect.getKeyframes();
|
|
104
|
+
let timing = effect.getTiming();
|
|
105
|
+
track(time(), animation[animationId], AnimationOperation.Create, JSON.stringify(keyframes), JSON.stringify(timing), target);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (animation[operationCount]++ < maxOperations) {
|
|
109
|
+
let operation: AnimationOperation = null;
|
|
110
|
+
switch (name) {
|
|
111
|
+
case "play":
|
|
112
|
+
operation = AnimationOperation.Play;
|
|
113
|
+
break;
|
|
114
|
+
case "pause":
|
|
115
|
+
operation = AnimationOperation.Pause;
|
|
116
|
+
break;
|
|
117
|
+
case "cancel":
|
|
118
|
+
operation = AnimationOperation.Cancel;
|
|
119
|
+
break;
|
|
120
|
+
case "finish":
|
|
121
|
+
operation = AnimationOperation.Finish;
|
|
122
|
+
break;
|
|
123
|
+
case "commitStyles":
|
|
124
|
+
operation = AnimationOperation.CommitStyles;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
if (operation) {
|
|
128
|
+
track(time(), animation[animationId], operation);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
package/src/layout/custom.ts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { Event } from "@clarity-types/data";
|
|
2
|
-
import { active } from "@src/core";
|
|
3
|
-
import { schedule } from "@src/core/task";
|
|
4
|
-
import encode from "@src/layout/encode";
|
|
5
|
-
|
|
6
|
-
export const elements: string[] = [];
|
|
7
|
-
|
|
8
|
-
const definedElements = new Set<string>();
|
|
9
|
-
function register(tag: string) {
|
|
10
|
-
if (!definedElements.has(tag)) {
|
|
11
|
-
definedElements.add(tag);
|
|
12
|
-
elements.push(tag);
|
|
13
|
-
schedule(encode.bind(this, Event.CustomElement));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function check(tag: string) {
|
|
18
|
-
if (window.customElements?.get && window.customElements.get(tag)) {
|
|
19
|
-
register(tag);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function start() {
|
|
24
|
-
window.clarityOverrides = window.clarityOverrides || {};
|
|
25
|
-
if (window.customElements?.define && !window.clarityOverrides.define) {
|
|
26
|
-
window.clarityOverrides.define = window.customElements.define;
|
|
27
|
-
window.customElements.define = function () {
|
|
28
|
-
if (active()) {
|
|
29
|
-
register(arguments[0]);
|
|
30
|
-
}
|
|
31
|
-
return window.clarityOverrides.define.apply(this, arguments);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function reset() {
|
|
37
|
-
elements.length = 0;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function stop() {
|
|
41
|
-
reset();
|
|
42
|
-
definedElements.clear();
|
|
1
|
+
import { Event } from "@clarity-types/data";
|
|
2
|
+
import { active } from "@src/core";
|
|
3
|
+
import { schedule } from "@src/core/task";
|
|
4
|
+
import encode from "@src/layout/encode";
|
|
5
|
+
|
|
6
|
+
export const elements: string[] = [];
|
|
7
|
+
|
|
8
|
+
const definedElements = new Set<string>();
|
|
9
|
+
function register(tag: string) {
|
|
10
|
+
if (!definedElements.has(tag)) {
|
|
11
|
+
definedElements.add(tag);
|
|
12
|
+
elements.push(tag);
|
|
13
|
+
schedule(encode.bind(this, Event.CustomElement));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function check(tag: string) {
|
|
18
|
+
if (window.customElements?.get && window.customElements.get(tag)) {
|
|
19
|
+
register(tag);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function start() {
|
|
24
|
+
window.clarityOverrides = window.clarityOverrides || {};
|
|
25
|
+
if (window.customElements?.define && !window.clarityOverrides.define) {
|
|
26
|
+
window.clarityOverrides.define = window.customElements.define;
|
|
27
|
+
window.customElements.define = function () {
|
|
28
|
+
if (active()) {
|
|
29
|
+
register(arguments[0]);
|
|
30
|
+
}
|
|
31
|
+
return window.clarityOverrides.define.apply(this, arguments);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function reset() {
|
|
37
|
+
elements.length = 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function stop() {
|
|
41
|
+
reset();
|
|
42
|
+
definedElements.clear();
|
|
43
43
|
}
|
package/src/layout/discover.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { Priority, Timer } from "@clarity-types/core";
|
|
2
|
-
import { Event, Metric } from "@clarity-types/data";
|
|
3
|
-
import { Source } from "@clarity-types/layout";
|
|
4
|
-
import measure from "@src/core/measure";
|
|
5
|
-
import * as task from "@src/core/task";
|
|
6
|
-
import { time } from "@src/core/time";
|
|
7
|
-
import { id } from "@src/data/metadata";
|
|
8
|
-
import * as doc from "@src/layout/document";
|
|
9
|
-
import encode from "@src/layout/encode";
|
|
10
|
-
import * as region from "@src/layout/region";
|
|
11
|
-
import traverse from "@src/layout/traverse";
|
|
12
|
-
import { checkDocumentStyles } from "@src/layout/style";
|
|
13
|
-
import * as scroll from "@src/interaction/scroll";
|
|
14
|
-
|
|
15
|
-
export function start(): void {
|
|
16
|
-
task.schedule(discover, Priority.High).then((): void => {
|
|
17
|
-
measure(doc.compute)();
|
|
18
|
-
measure(region.compute)();
|
|
19
|
-
measure(scroll.compute)();
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function discover(): Promise<void> {
|
|
24
|
-
let ts = time();
|
|
25
|
-
let timer: Timer = { id: id(), cost: Metric.LayoutCost };
|
|
26
|
-
task.start(timer);
|
|
27
|
-
await traverse(document, timer, Source.Discover, ts);
|
|
28
|
-
checkDocumentStyles(document, ts);
|
|
29
|
-
await encode(Event.Discover, timer, ts);
|
|
30
|
-
task.stop(timer);
|
|
31
|
-
}
|
|
1
|
+
import { Priority, Timer } from "@clarity-types/core";
|
|
2
|
+
import { Event, Metric } from "@clarity-types/data";
|
|
3
|
+
import { Source } from "@clarity-types/layout";
|
|
4
|
+
import measure from "@src/core/measure";
|
|
5
|
+
import * as task from "@src/core/task";
|
|
6
|
+
import { time } from "@src/core/time";
|
|
7
|
+
import { id } from "@src/data/metadata";
|
|
8
|
+
import * as doc from "@src/layout/document";
|
|
9
|
+
import encode from "@src/layout/encode";
|
|
10
|
+
import * as region from "@src/layout/region";
|
|
11
|
+
import traverse from "@src/layout/traverse";
|
|
12
|
+
import { checkDocumentStyles } from "@src/layout/style";
|
|
13
|
+
import * as scroll from "@src/interaction/scroll";
|
|
14
|
+
|
|
15
|
+
export function start(): void {
|
|
16
|
+
task.schedule(discover, Priority.High).then((): void => {
|
|
17
|
+
measure(doc.compute)();
|
|
18
|
+
measure(region.compute)();
|
|
19
|
+
measure(scroll.compute)();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function discover(): Promise<void> {
|
|
24
|
+
let ts = time();
|
|
25
|
+
let timer: Timer = { id: id(), cost: Metric.LayoutCost };
|
|
26
|
+
task.start(timer);
|
|
27
|
+
await traverse(document, timer, Source.Discover, ts);
|
|
28
|
+
checkDocumentStyles(document, ts);
|
|
29
|
+
await encode(Event.Discover, timer, ts);
|
|
30
|
+
task.stop(timer);
|
|
31
|
+
}
|
package/src/layout/document.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { Event } from "@clarity-types/data";
|
|
2
|
-
import { DocumentData } from "@clarity-types/layout";
|
|
3
|
-
import encode from "@src/layout/encode";
|
|
4
|
-
|
|
5
|
-
export let data: DocumentData;
|
|
6
|
-
|
|
7
|
-
export function reset(): void {
|
|
8
|
-
data = null;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function start(): void {
|
|
12
|
-
reset();
|
|
13
|
-
compute();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function compute(): void {
|
|
17
|
-
let body = document.body;
|
|
18
|
-
let d = document.documentElement;
|
|
19
|
-
let bodyClientWidth = body ? body.clientWidth : null;
|
|
20
|
-
let bodyScrollWidth = body ? body.scrollWidth : null;
|
|
21
|
-
let bodyOffsetWidth = body ? body.offsetWidth : null;
|
|
22
|
-
let documentClientWidth = d ? d.clientWidth : null;
|
|
23
|
-
let documentScrollWidth = d ? d.scrollWidth : null;
|
|
24
|
-
let documentOffsetWidth = d ? d.offsetWidth : null;
|
|
25
|
-
let width = Math.max(bodyClientWidth, bodyScrollWidth, bodyOffsetWidth,
|
|
26
|
-
documentClientWidth, documentScrollWidth, documentOffsetWidth);
|
|
27
|
-
|
|
28
|
-
let bodyClientHeight = body ? body.clientHeight : null;
|
|
29
|
-
let bodyScrollHeight = body ? body.scrollHeight : null;
|
|
30
|
-
let bodyOffsetHeight = body ? body.offsetHeight : null;
|
|
31
|
-
let documentClientHeight = d ? d.clientHeight : null;
|
|
32
|
-
let documentScrollHeight = d ? d.scrollHeight : null;
|
|
33
|
-
let documentOffsetHeight = d ? d.offsetHeight : null;
|
|
34
|
-
let height = Math.max(bodyClientHeight, bodyScrollHeight, bodyOffsetHeight,
|
|
35
|
-
documentClientHeight, documentScrollHeight, documentOffsetHeight);
|
|
36
|
-
|
|
37
|
-
// Check that width or height has changed from before, and also that width & height are not null values
|
|
38
|
-
if ((data === null || width !== data.width || height !== data.height) && width !== null && height !== null) {
|
|
39
|
-
data = { width, height };
|
|
40
|
-
encode(Event.Document);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function stop(): void {
|
|
45
|
-
reset();
|
|
46
|
-
}
|
|
1
|
+
import { Event } from "@clarity-types/data";
|
|
2
|
+
import { DocumentData } from "@clarity-types/layout";
|
|
3
|
+
import encode from "@src/layout/encode";
|
|
4
|
+
|
|
5
|
+
export let data: DocumentData;
|
|
6
|
+
|
|
7
|
+
export function reset(): void {
|
|
8
|
+
data = null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function start(): void {
|
|
12
|
+
reset();
|
|
13
|
+
compute();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function compute(): void {
|
|
17
|
+
let body = document.body;
|
|
18
|
+
let d = document.documentElement;
|
|
19
|
+
let bodyClientWidth = body ? body.clientWidth : null;
|
|
20
|
+
let bodyScrollWidth = body ? body.scrollWidth : null;
|
|
21
|
+
let bodyOffsetWidth = body ? body.offsetWidth : null;
|
|
22
|
+
let documentClientWidth = d ? d.clientWidth : null;
|
|
23
|
+
let documentScrollWidth = d ? d.scrollWidth : null;
|
|
24
|
+
let documentOffsetWidth = d ? d.offsetWidth : null;
|
|
25
|
+
let width = Math.max(bodyClientWidth, bodyScrollWidth, bodyOffsetWidth,
|
|
26
|
+
documentClientWidth, documentScrollWidth, documentOffsetWidth);
|
|
27
|
+
|
|
28
|
+
let bodyClientHeight = body ? body.clientHeight : null;
|
|
29
|
+
let bodyScrollHeight = body ? body.scrollHeight : null;
|
|
30
|
+
let bodyOffsetHeight = body ? body.offsetHeight : null;
|
|
31
|
+
let documentClientHeight = d ? d.clientHeight : null;
|
|
32
|
+
let documentScrollHeight = d ? d.scrollHeight : null;
|
|
33
|
+
let documentOffsetHeight = d ? d.offsetHeight : null;
|
|
34
|
+
let height = Math.max(bodyClientHeight, bodyScrollHeight, bodyOffsetHeight,
|
|
35
|
+
documentClientHeight, documentScrollHeight, documentOffsetHeight);
|
|
36
|
+
|
|
37
|
+
// Check that width or height has changed from before, and also that width & height are not null values
|
|
38
|
+
if ((data === null || width !== data.width || height !== data.height) && width !== null && height !== null) {
|
|
39
|
+
data = { width, height };
|
|
40
|
+
encode(Event.Document);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function stop(): void {
|
|
45
|
+
reset();
|
|
46
|
+
}
|