clarity-js 0.8.4-beta → 0.8.5

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.
Files changed (103) hide show
  1. package/README.md +26 -26
  2. package/build/clarity.extended.js +1 -1
  3. package/build/clarity.insight.js +1 -1
  4. package/build/clarity.js +5524 -5561
  5. package/build/clarity.min.js +1 -1
  6. package/build/clarity.module.js +5524 -5561
  7. package/build/clarity.performance.js +1 -1
  8. package/package.json +70 -70
  9. package/rollup.config.ts +98 -98
  10. package/src/clarity.ts +60 -60
  11. package/src/core/api.ts +8 -8
  12. package/src/core/config.ts +32 -32
  13. package/src/core/copy.ts +3 -3
  14. package/src/core/event.ts +53 -53
  15. package/src/core/hash.ts +19 -19
  16. package/src/core/history.ts +73 -73
  17. package/src/core/index.ts +83 -83
  18. package/src/core/measure.ts +19 -19
  19. package/src/core/report.ts +28 -28
  20. package/src/core/scrub.ts +196 -196
  21. package/src/core/task.ts +181 -180
  22. package/src/core/time.ts +19 -19
  23. package/src/core/timeout.ts +10 -10
  24. package/src/core/version.ts +2 -2
  25. package/src/data/baseline.ts +155 -155
  26. package/src/data/compress.ts +31 -31
  27. package/src/data/consent.ts +20 -20
  28. package/src/data/custom.ts +23 -23
  29. package/src/data/dimension.ts +53 -53
  30. package/src/data/encode.ts +140 -140
  31. package/src/data/envelope.ts +53 -53
  32. package/src/data/extract.ts +211 -211
  33. package/src/data/index.ts +46 -46
  34. package/src/data/limit.ts +44 -44
  35. package/src/data/metadata.ts +344 -356
  36. package/src/data/metric.ts +51 -51
  37. package/src/data/ping.ts +36 -36
  38. package/src/data/signal.ts +30 -30
  39. package/src/data/summary.ts +34 -34
  40. package/src/data/token.ts +39 -39
  41. package/src/data/upgrade.ts +37 -37
  42. package/src/data/upload.ts +283 -283
  43. package/src/data/variable.ts +83 -83
  44. package/src/diagnostic/encode.ts +40 -40
  45. package/src/diagnostic/fraud.ts +36 -36
  46. package/src/diagnostic/index.ts +15 -15
  47. package/src/diagnostic/internal.ts +28 -28
  48. package/src/diagnostic/script.ts +37 -37
  49. package/src/global.ts +6 -6
  50. package/src/index.ts +9 -9
  51. package/src/insight/blank.ts +14 -14
  52. package/src/insight/encode.ts +60 -60
  53. package/src/insight/snapshot.ts +114 -114
  54. package/src/interaction/change.ts +40 -40
  55. package/src/interaction/click.ts +162 -194
  56. package/src/interaction/clipboard.ts +34 -34
  57. package/src/interaction/encode.ts +193 -196
  58. package/src/interaction/index.ts +59 -59
  59. package/src/interaction/input.ts +59 -59
  60. package/src/interaction/pointer.ts +139 -139
  61. package/src/interaction/resize.ts +47 -47
  62. package/src/interaction/scroll.ts +124 -124
  63. package/src/interaction/selection.ts +68 -68
  64. package/src/interaction/submit.ts +32 -32
  65. package/src/interaction/timeline.ts +65 -65
  66. package/src/interaction/unload.ts +28 -28
  67. package/src/interaction/visibility.ts +26 -26
  68. package/src/layout/animation.ts +133 -133
  69. package/src/layout/discover.ts +31 -31
  70. package/src/layout/document.ts +48 -48
  71. package/src/layout/dom.ts +437 -437
  72. package/src/layout/encode.ts +147 -147
  73. package/src/layout/index.ts +41 -41
  74. package/src/layout/mutation.ts +409 -409
  75. package/src/layout/node.ts +292 -292
  76. package/src/layout/offset.ts +19 -19
  77. package/src/layout/region.ts +153 -153
  78. package/src/layout/schema.ts +63 -63
  79. package/src/layout/selector.ts +82 -82
  80. package/src/layout/style.ts +150 -150
  81. package/src/layout/target.ts +32 -32
  82. package/src/layout/traverse.ts +27 -27
  83. package/src/performance/blank.ts +7 -7
  84. package/src/performance/encode.ts +31 -31
  85. package/src/performance/index.ts +14 -14
  86. package/src/performance/interaction.ts +125 -125
  87. package/src/performance/navigation.ts +31 -31
  88. package/src/performance/observer.ts +108 -108
  89. package/src/queue.ts +33 -33
  90. package/test/core.test.ts +139 -139
  91. package/test/helper.ts +162 -162
  92. package/test/html/core.html +27 -27
  93. package/test/stub.test.ts +7 -0
  94. package/test/tsconfig.test.json +5 -5
  95. package/tsconfig.json +21 -21
  96. package/tslint.json +32 -32
  97. package/types/core.d.ts +153 -153
  98. package/types/data.d.ts +511 -513
  99. package/types/diagnostic.d.ts +24 -24
  100. package/types/index.d.ts +39 -39
  101. package/types/interaction.d.ts +165 -168
  102. package/types/layout.d.ts +272 -272
  103. package/types/performance.d.ts +64 -64
@@ -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 = getId(effect.target);
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 = getId(effect.target);
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,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
+ }
@@ -1,48 +1,48 @@
1
- import { Event } from "@clarity-types/data";
2
- import { DocumentData } from "@clarity-types/layout";
3
- import { FunctionNames } from "@clarity-types/performance";
4
- import encode from "@src/layout/encode";
5
-
6
- export let data: DocumentData;
7
-
8
- export function reset(): void {
9
- data = null;
10
- }
11
-
12
- export function start(): void {
13
- reset();
14
- compute();
15
- }
16
-
17
- export function compute(): void {
18
- compute.dn = FunctionNames.DocumentCompute;
19
- let body = document.body;
20
- let d = document.documentElement;
21
- let bodyClientWidth = body ? body.clientWidth : null;
22
- let bodyScrollWidth = body ? body.scrollWidth : null;
23
- let bodyOffsetWidth = body ? body.offsetWidth : null;
24
- let documentClientWidth = d ? d.clientWidth : null;
25
- let documentScrollWidth = d ? d.scrollWidth : null;
26
- let documentOffsetWidth = d ? d.offsetWidth : null;
27
- let width = Math.max(bodyClientWidth, bodyScrollWidth, bodyOffsetWidth,
28
- documentClientWidth, documentScrollWidth, documentOffsetWidth);
29
-
30
- let bodyClientHeight = body ? body.clientHeight : null;
31
- let bodyScrollHeight = body ? body.scrollHeight : null;
32
- let bodyOffsetHeight = body ? body.offsetHeight : null;
33
- let documentClientHeight = d ? d.clientHeight : null;
34
- let documentScrollHeight = d ? d.scrollHeight : null;
35
- let documentOffsetHeight = d ? d.offsetHeight : null;
36
- let height = Math.max(bodyClientHeight, bodyScrollHeight, bodyOffsetHeight,
37
- documentClientHeight, documentScrollHeight, documentOffsetHeight);
38
-
39
- // Check that width or height has changed from before, and also that width & height are not null values
40
- if ((data === null || width !== data.width || height !== data.height) && width !== null && height !== null) {
41
- data = { width, height };
42
- encode(Event.Document);
43
- }
44
- }
45
-
46
- export function stop(): void {
47
- reset();
48
- }
1
+ import { Event } from "@clarity-types/data";
2
+ import { DocumentData } from "@clarity-types/layout";
3
+ import { FunctionNames } from "@clarity-types/performance";
4
+ import encode from "@src/layout/encode";
5
+
6
+ export let data: DocumentData;
7
+
8
+ export function reset(): void {
9
+ data = null;
10
+ }
11
+
12
+ export function start(): void {
13
+ reset();
14
+ compute();
15
+ }
16
+
17
+ export function compute(): void {
18
+ compute.dn = FunctionNames.DocumentCompute;
19
+ let body = document.body;
20
+ let d = document.documentElement;
21
+ let bodyClientWidth = body ? body.clientWidth : null;
22
+ let bodyScrollWidth = body ? body.scrollWidth : null;
23
+ let bodyOffsetWidth = body ? body.offsetWidth : null;
24
+ let documentClientWidth = d ? d.clientWidth : null;
25
+ let documentScrollWidth = d ? d.scrollWidth : null;
26
+ let documentOffsetWidth = d ? d.offsetWidth : null;
27
+ let width = Math.max(bodyClientWidth, bodyScrollWidth, bodyOffsetWidth,
28
+ documentClientWidth, documentScrollWidth, documentOffsetWidth);
29
+
30
+ let bodyClientHeight = body ? body.clientHeight : null;
31
+ let bodyScrollHeight = body ? body.scrollHeight : null;
32
+ let bodyOffsetHeight = body ? body.offsetHeight : null;
33
+ let documentClientHeight = d ? d.clientHeight : null;
34
+ let documentScrollHeight = d ? d.scrollHeight : null;
35
+ let documentOffsetHeight = d ? d.offsetHeight : null;
36
+ let height = Math.max(bodyClientHeight, bodyScrollHeight, bodyOffsetHeight,
37
+ documentClientHeight, documentScrollHeight, documentOffsetHeight);
38
+
39
+ // Check that width or height has changed from before, and also that width & height are not null values
40
+ if ((data === null || width !== data.width || height !== data.height) && width !== null && height !== null) {
41
+ data = { width, height };
42
+ encode(Event.Document);
43
+ }
44
+ }
45
+
46
+ export function stop(): void {
47
+ reset();
48
+ }