clarity-js 0.6.23

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 (87) hide show
  1. package/README.md +26 -0
  2. package/build/clarity.js +4479 -0
  3. package/build/clarity.min.js +1 -0
  4. package/build/clarity.module.js +4473 -0
  5. package/package.json +66 -0
  6. package/rollup.config.ts +38 -0
  7. package/src/clarity.ts +54 -0
  8. package/src/core/config.ts +21 -0
  9. package/src/core/copy.ts +3 -0
  10. package/src/core/event.ts +25 -0
  11. package/src/core/hash.ts +19 -0
  12. package/src/core/history.ts +69 -0
  13. package/src/core/index.ts +79 -0
  14. package/src/core/measure.ts +17 -0
  15. package/src/core/report.ts +27 -0
  16. package/src/core/scrub.ts +102 -0
  17. package/src/core/task.ts +180 -0
  18. package/src/core/time.ts +14 -0
  19. package/src/core/timeout.ts +10 -0
  20. package/src/core/version.ts +2 -0
  21. package/src/data/baseline.ts +89 -0
  22. package/src/data/compress.ts +31 -0
  23. package/src/data/custom.ts +18 -0
  24. package/src/data/dimension.ts +42 -0
  25. package/src/data/encode.ts +109 -0
  26. package/src/data/envelope.ts +46 -0
  27. package/src/data/index.ts +43 -0
  28. package/src/data/limit.ts +42 -0
  29. package/src/data/metadata.ts +232 -0
  30. package/src/data/metric.ts +51 -0
  31. package/src/data/ping.ts +36 -0
  32. package/src/data/summary.ts +34 -0
  33. package/src/data/token.ts +39 -0
  34. package/src/data/upgrade.ts +36 -0
  35. package/src/data/upload.ts +250 -0
  36. package/src/data/variable.ts +46 -0
  37. package/src/diagnostic/encode.ts +40 -0
  38. package/src/diagnostic/image.ts +23 -0
  39. package/src/diagnostic/index.ts +14 -0
  40. package/src/diagnostic/internal.ts +41 -0
  41. package/src/diagnostic/script.ts +45 -0
  42. package/src/global.ts +22 -0
  43. package/src/index.ts +8 -0
  44. package/src/interaction/click.ts +140 -0
  45. package/src/interaction/encode.ts +140 -0
  46. package/src/interaction/index.ts +45 -0
  47. package/src/interaction/input.ts +64 -0
  48. package/src/interaction/pointer.ts +108 -0
  49. package/src/interaction/resize.ts +30 -0
  50. package/src/interaction/scroll.ts +73 -0
  51. package/src/interaction/selection.ts +66 -0
  52. package/src/interaction/timeline.ts +65 -0
  53. package/src/interaction/unload.ts +25 -0
  54. package/src/interaction/visibility.ts +24 -0
  55. package/src/layout/box.ts +83 -0
  56. package/src/layout/discover.ts +27 -0
  57. package/src/layout/document.ts +46 -0
  58. package/src/layout/dom.ts +442 -0
  59. package/src/layout/encode.ts +111 -0
  60. package/src/layout/extract.ts +75 -0
  61. package/src/layout/index.ts +25 -0
  62. package/src/layout/mutation.ts +232 -0
  63. package/src/layout/node.ts +211 -0
  64. package/src/layout/offset.ts +19 -0
  65. package/src/layout/region.ts +143 -0
  66. package/src/layout/schema.ts +66 -0
  67. package/src/layout/selector.ts +24 -0
  68. package/src/layout/target.ts +44 -0
  69. package/src/layout/traverse.ts +28 -0
  70. package/src/performance/connection.ts +37 -0
  71. package/src/performance/encode.ts +40 -0
  72. package/src/performance/index.ts +15 -0
  73. package/src/performance/navigation.ts +31 -0
  74. package/src/performance/observer.ts +87 -0
  75. package/test/core.test.ts +82 -0
  76. package/test/helper.ts +104 -0
  77. package/test/html/core.html +17 -0
  78. package/test/tsconfig.test.json +6 -0
  79. package/tsconfig.json +21 -0
  80. package/tslint.json +33 -0
  81. package/types/core.d.ts +127 -0
  82. package/types/data.d.ts +344 -0
  83. package/types/diagnostic.d.ts +24 -0
  84. package/types/index.d.ts +30 -0
  85. package/types/interaction.d.ts +110 -0
  86. package/types/layout.d.ts +200 -0
  87. package/types/performance.d.ts +40 -0
@@ -0,0 +1,108 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { PointerState, Setting } from "@clarity-types/interaction";
3
+ import { bind } from "@src/core/event";
4
+ import { schedule } from "@src/core/task";
5
+ import { time } from "@src/core/time";
6
+ import { clearTimeout, setTimeout } from "@src/core/timeout";
7
+ import { iframe } from "@src/layout/dom";
8
+ import offset from "@src/layout/offset";
9
+ import { target } from "@src/layout/target";
10
+ import encode from "./encode";
11
+
12
+ export let state: PointerState[] = [];
13
+ let timeout: number = null;
14
+
15
+ export function start(): void {
16
+ reset();
17
+ }
18
+
19
+ export function observe(root: Node): void {
20
+ bind(root, "mousedown", mouse.bind(this, Event.MouseDown, root), true);
21
+ bind(root, "mouseup", mouse.bind(this, Event.MouseUp, root), true);
22
+ bind(root, "mousemove", mouse.bind(this, Event.MouseMove, root), true);
23
+ bind(root, "mousewheel", mouse.bind(this, Event.MouseWheel, root), true);
24
+ bind(root, "dblclick", mouse.bind(this, Event.DoubleClick, root), true);
25
+ bind(root, "touchstart", touch.bind(this, Event.TouchStart, root), true);
26
+ bind(root, "touchend", touch.bind(this, Event.TouchEnd, root), true);
27
+ bind(root, "touchmove", touch.bind(this, Event.TouchMove, root), true);
28
+ bind(root, "touchcancel", touch.bind(this, Event.TouchCancel, root), true);
29
+ }
30
+
31
+ function mouse(event: Event, root: Node, evt: MouseEvent): void {
32
+ let frame = iframe(root);
33
+ let d = frame ? frame.contentDocument.documentElement : document.documentElement;
34
+ let x = "pageX" in evt ? Math.round(evt.pageX) : ("clientX" in evt ? Math.round(evt["clientX"] + d.scrollLeft) : null);
35
+ let y = "pageY" in evt ? Math.round(evt.pageY) : ("clientY" in evt ? Math.round(evt["clientY"] + d.scrollTop) : null);
36
+ // In case of iframe, we adjust (x,y) to be relative to top parent's origin
37
+ if (frame) {
38
+ let distance = offset(frame);
39
+ x = x ? x + Math.round(distance.x) : x;
40
+ y = y ? y + Math.round(distance.y) : y;
41
+ }
42
+
43
+ // Check for null values before processing this event
44
+ if (x !== null && y !== null) { handler({ time: time(), event, data: { target: target(evt), x, y } }); }
45
+ }
46
+
47
+ function touch(event: Event, root: Node, evt: TouchEvent): void {
48
+ let frame = iframe(root);
49
+ let d = frame ? frame.contentDocument.documentElement : document.documentElement;
50
+ let touches = evt.changedTouches;
51
+
52
+ let t = time();
53
+ if (touches) {
54
+ for (let i = 0; i < touches.length; i++) {
55
+ let entry = touches[i];
56
+ let x = "clientX" in entry ? Math.round(entry["clientX"] + d.scrollLeft) : null;
57
+ let y = "clientY" in entry ? Math.round(entry["clientY"] + d.scrollTop) : null;
58
+ x = x && frame ? x + Math.round(frame.offsetLeft) : x;
59
+ y = y && frame ? y + Math.round(frame.offsetTop) : y;
60
+
61
+ // Check for null values before processing this event
62
+ if (x !== null && y !== null) { handler({ time: t, event, data: { target: target(evt), x, y } }); }
63
+ }
64
+ }
65
+ }
66
+
67
+ function handler(current: PointerState): void {
68
+ switch (current.event) {
69
+ case Event.MouseMove:
70
+ case Event.MouseWheel:
71
+ case Event.TouchMove:
72
+ let length = state.length;
73
+ let last = length > 1 ? state[length - 2] : null;
74
+ if (last && similar(last, current)) { state.pop(); }
75
+ state.push(current);
76
+
77
+ clearTimeout(timeout);
78
+ timeout = setTimeout(process, Setting.LookAhead, current.event);
79
+ break;
80
+ default:
81
+ state.push(current);
82
+ process(current.event);
83
+ break;
84
+ }
85
+ }
86
+
87
+ function process(event: Event): void {
88
+ schedule(encode.bind(this, event));
89
+ }
90
+
91
+ export function reset(): void {
92
+ state = [];
93
+ }
94
+
95
+ function similar(last: PointerState, current: PointerState): boolean {
96
+ let dx = last.data.x - current.data.x;
97
+ let dy = last.data.y - current.data.y;
98
+ let distance = Math.sqrt(dx * dx + dy * dy);
99
+ let gap = current.time - last.time;
100
+ let match = current.data.target === last.data.target;
101
+ return current.event === last.event && match && distance < Setting.Distance && gap < Setting.Interval;
102
+ }
103
+
104
+ export function stop(): void {
105
+ clearTimeout(timeout);
106
+ // Send out any pending pointer events in the pipeline
107
+ if (state.length > 0) { process(state[state.length - 1].event); }
108
+ }
@@ -0,0 +1,30 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { ResizeData } from "@clarity-types/interaction";
3
+ import { bind } from "@src/core/event";
4
+ import encode from "./encode";
5
+
6
+ export let data: ResizeData;
7
+
8
+ export function start(): void {
9
+ bind(window, "resize", recompute);
10
+ recompute();
11
+ }
12
+
13
+ function recompute(): void {
14
+ let de = document.documentElement;
15
+ // window.innerWidth includes width of the scrollbar and is not a true representation of the viewport width.
16
+ // Therefore, when possible, use documentElement's clientWidth property.
17
+ data = {
18
+ width: de && "clientWidth" in de ? Math.min(de.clientWidth, window.innerWidth) : window.innerWidth,
19
+ height: de && "clientHeight" in de ? Math.min(de.clientHeight, window.innerHeight) : window.innerHeight,
20
+ };
21
+ encode(Event.Resize);
22
+ }
23
+
24
+ export function reset(): void {
25
+ data = null;
26
+ }
27
+
28
+ export function stop(): void {
29
+ reset();
30
+ }
@@ -0,0 +1,73 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { ScrollState, Setting } from "@clarity-types/interaction";
3
+ import { bind } from "@src/core/event";
4
+ import { schedule } from "@src/core/task";
5
+ import { time } from "@src/core/time";
6
+ import { clearTimeout, setTimeout } from "@src/core/timeout";
7
+ import { iframe } from "@src/layout/dom";
8
+ import { target } from "@src/layout/target";
9
+ import encode from "./encode";
10
+
11
+ export let state: ScrollState[] = [];
12
+ let timeout: number = null;
13
+
14
+ export function start(): void {
15
+ state = [];
16
+ recompute();
17
+ }
18
+
19
+ export function observe(root: Node): void {
20
+ let frame = iframe(root);
21
+ let node = frame ? frame.contentWindow : (root === document ? window : root);
22
+ bind(node, "scroll", recompute, true);
23
+ }
24
+
25
+ function recompute(event: UIEvent = null): void {
26
+ let w = window as Window;
27
+ let de = document.documentElement;
28
+ let element = event ? target(event) : de;
29
+
30
+ // If the target is a Document node, then identify corresponding documentElement and window for this document
31
+ if (element && element.nodeType === Node.DOCUMENT_NODE) {
32
+ let frame = iframe(element);
33
+ w = frame ? frame.contentWindow : w;
34
+ element = de = (element as Document).documentElement;
35
+ }
36
+
37
+ // Edge doesn't support scrollTop position on document.documentElement.
38
+ // For cross browser compatibility, looking up pageYOffset on window if the scroll is on document.
39
+ // And, if for some reason that is not available, fall back to looking up scrollTop on document.documentElement.
40
+ let x = element === de && "pageXOffset" in w ? Math.round(w.pageXOffset) : Math.round((element as HTMLElement).scrollLeft);
41
+ let y = element === de && "pageYOffset" in w ? Math.round(w.pageYOffset) : Math.round((element as HTMLElement).scrollTop);
42
+ let current: ScrollState = { time: time(), event: Event.Scroll, data: {target: element, x, y} };
43
+
44
+ // We don't send any scroll events if this is the first event and the current position is top (0,0)
45
+ if ((event === null && x === 0 && y === 0) || (x === null || y === null)) { return; }
46
+
47
+ let length = state.length;
48
+ let last = length > 1 ? state[length - 2] : null;
49
+ if (last && similar(last, current)) { state.pop(); }
50
+ state.push(current);
51
+
52
+ clearTimeout(timeout);
53
+ timeout = setTimeout(process, Setting.LookAhead, Event.Scroll);
54
+ }
55
+
56
+ export function reset(): void {
57
+ state = [];
58
+ }
59
+
60
+ function process(event: Event): void {
61
+ schedule(encode.bind(this, event));
62
+ }
63
+
64
+ function similar(last: ScrollState, current: ScrollState): boolean {
65
+ let dx = last.data.x - current.data.x;
66
+ let dy = last.data.y - current.data.y;
67
+ return (dx * dx + dy * dy < Setting.Distance * Setting.Distance) && (current.time - last.time < Setting.Interval);
68
+ }
69
+
70
+ export function stop(): void {
71
+ clearTimeout(timeout);
72
+ state = [];
73
+ }
@@ -0,0 +1,66 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { SelectionData, Setting } from "@clarity-types/interaction";
3
+ import { bind } from "@src/core/event";
4
+ import { schedule } from "@src/core/task";
5
+ import { clearTimeout, setTimeout } from "@src/core/timeout";
6
+ import encode from "./encode";
7
+
8
+ export let data: SelectionData = null;
9
+ let previous: Selection = null;
10
+ let timeout: number = null;
11
+
12
+ export function start(): void {
13
+ reset();
14
+ }
15
+
16
+ export function observe(root: Node): void {
17
+ bind(root, "selectstart", recompute.bind(this, root), true);
18
+ bind(root, "selectionchange", recompute.bind(this, root), true);
19
+ }
20
+
21
+ function recompute(root: Node): void {
22
+ let doc = root.nodeType === Node.DOCUMENT_NODE ? root as Document : document;
23
+ let current = doc.getSelection();
24
+
25
+ // Bail out if we don't have a valid selection
26
+ if (current === null) { return; }
27
+
28
+ // Bail out if we got a valid selection but not valid nodes
29
+ // In Edge, selectionchange gets fired even on interactions like right clicks and
30
+ // can result in null anchorNode and focusNode if there was no previous selection on page
31
+ // Also, ignore any selections that start and end at the exact same point
32
+ if ((current.anchorNode === null && current.focusNode === null) ||
33
+ (current.anchorNode === current.focusNode && current.anchorOffset === current.focusOffset)) {
34
+ return;
35
+ }
36
+ let startNode = data.start ? data.start : null;
37
+ if (previous !== null && data.start !== null && startNode !== current.anchorNode) {
38
+ clearTimeout(timeout);
39
+ process(Event.Selection);
40
+ }
41
+
42
+ data = {
43
+ start: current.anchorNode,
44
+ startOffset: current.anchorOffset,
45
+ end: current.focusNode,
46
+ endOffset: current.focusOffset
47
+ };
48
+ previous = current;
49
+
50
+ clearTimeout(timeout);
51
+ timeout = setTimeout(process, Setting.LookAhead, Event.Selection);
52
+ }
53
+
54
+ function process(event: Event): void {
55
+ schedule(encode.bind(this, event));
56
+ }
57
+
58
+ export function reset(): void {
59
+ previous = null;
60
+ data = { start: 0, startOffset: 0, end: 0, endOffset: 0 };
61
+ }
62
+
63
+ export function stop(): void {
64
+ reset();
65
+ clearTimeout(timeout);
66
+ }
@@ -0,0 +1,65 @@
1
+ import { BooleanFlag, Event } from "@clarity-types/data";
2
+ import { BrowsingContext, Setting, TimelineState } from "@clarity-types/interaction";
3
+ import * as baseline from "@src/data/baseline";
4
+ import * as envelope from "@src/data/envelope";
5
+ import encode from "@src/interaction/encode";
6
+
7
+ let state: TimelineState[] = [];
8
+ export let updates: TimelineState[] = [];
9
+
10
+ export function start(): void {
11
+ state = [];
12
+ reset();
13
+ }
14
+
15
+ export function reset(): void {
16
+ updates = [];
17
+ }
18
+
19
+ export function track(time: number,
20
+ event: Event,
21
+ hash: string,
22
+ x: number,
23
+ y: number,
24
+ reaction: number = BooleanFlag.True,
25
+ context: number = BrowsingContext.Self): void {
26
+ state.push({
27
+ time,
28
+ event: Event.Timeline,
29
+ data: {
30
+ type: event,
31
+ hash,
32
+ x,
33
+ y,
34
+ reaction,
35
+ context
36
+ }
37
+ });
38
+
39
+ // Since timeline only keeps the data for configured time, we still want to continue tracking these values
40
+ // as part of the baseline. For instance, in a scenario where last scroll happened 5s ago.
41
+ // We would still need to capture the last scroll position as part of the baseline event, even when timeline will be empty.
42
+ baseline.track(event, x, y);
43
+ }
44
+
45
+ export function compute(): void {
46
+ const temp = [];
47
+ updates = [];
48
+ let max = envelope.data.start + envelope.data.duration;
49
+ let min = Math.max(max - Setting.TimelineSpan, 0);
50
+
51
+ for (let s of state) {
52
+ if (s.time >= min) {
53
+ if (s.time <= max) { updates.push(s); }
54
+ temp.push(s);
55
+ }
56
+ }
57
+
58
+ state = temp; // Drop events less than the min time
59
+ encode(Event.Timeline);
60
+ }
61
+
62
+ export function stop(): void {
63
+ state = [];
64
+ reset();
65
+ }
@@ -0,0 +1,25 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { UnloadData } from "@clarity-types/interaction";
3
+ import * as clarity from "@src/clarity";
4
+ import { bind } from "@src/core/event";
5
+ import encode from "./encode";
6
+
7
+ export let data: UnloadData;
8
+
9
+ export function start(): void {
10
+ bind(window, "pagehide", recompute);
11
+ }
12
+
13
+ function recompute(evt: UIEvent): void {
14
+ data = { name: evt.type };
15
+ encode(Event.Unload);
16
+ clarity.stop();
17
+ }
18
+
19
+ export function reset(): void {
20
+ data = null;
21
+ }
22
+
23
+ export function stop(): void {
24
+ reset();
25
+ }
@@ -0,0 +1,24 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { VisibilityData } from "@clarity-types/interaction";
3
+ import { bind } from "@src/core/event";
4
+ import encode from "./encode";
5
+
6
+ export let data: VisibilityData;
7
+
8
+ export function start(): void {
9
+ bind(document, "visibilitychange", recompute);
10
+ recompute();
11
+ }
12
+
13
+ function recompute(): void {
14
+ data = { visible: "visibilityState" in document ? document.visibilityState : "default" };
15
+ encode(Event.Visibility);
16
+ }
17
+
18
+ export function reset(): void {
19
+ data = null;
20
+ }
21
+
22
+ export function stop(): void {
23
+ reset();
24
+ }
@@ -0,0 +1,83 @@
1
+ import { Event, Setting } from "@clarity-types/data";
2
+ import { BoxData } from "@clarity-types/layout";
3
+ import * as dom from "@src/layout/dom";
4
+ import encode from "@src/layout/encode";
5
+
6
+ export let data: BoxData[] = [];
7
+ let enabled = false;
8
+ let observer: ResizeObserver = null;
9
+
10
+ export function start(): void {
11
+ reset();
12
+ observer = null;
13
+ enabled = window["ResizeObserver"] ? true : false;
14
+ }
15
+
16
+ export function compute(id: number): void {
17
+ if (enabled === false) { return; }
18
+ observer = observer === null ? new ResizeObserver(handler) : observer;
19
+ if (observer) {
20
+ let value = dom.getValue(id);
21
+ // If this is the first time computing size for this node, go ahead and wire up ResizeObserver
22
+ // In all other cases, value.metadata.size will be null or an array with two elements [width, height]
23
+ // And, in those cases, we will skip through the following section and not attach the observer
24
+ if (value && value.metadata.size !== null && value.metadata.size.length === 0) {
25
+ let node = dom.getNode(id);
26
+ if (node && node.nodeType === Node.ELEMENT_NODE) {
27
+ let e = node as HTMLElement;
28
+ let r = e.getBoundingClientRect();
29
+ value.metadata.size = [Math.floor(r.width * Setting.BoxPrecision), Math.floor(r.height * Setting.BoxPrecision)];
30
+ observer.observe(e);
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ function handler(entries: ResizeObserverEntry[]): void {
37
+ window.requestAnimationFrame(() => {
38
+ for (let entry of entries) {
39
+ let target = entry.target;
40
+ let id = target ? dom.getId(target) : null;
41
+ if (id) {
42
+ let v = dom.getValue(id);
43
+ let s = v.metadata.size;
44
+ let b = entry.borderBoxSize as any;
45
+ let w = null;
46
+ let h = null;
47
+ // Check if browser supports borderBoxSize property on ResizeObserverEntry object
48
+ // Otherwise, fall back to using getBoundingClientRect() to be cross browser compatible
49
+ // Reference: https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry/borderBoxSize
50
+ if(b && b.length > 0) {
51
+ w = Math.floor(b[0].inlineSize * Setting.BoxPrecision);
52
+ h = Math.floor(b[0].blockSize * Setting.BoxPrecision);
53
+ } else {
54
+ let r = target.getBoundingClientRect();
55
+ w = Math.floor(r.width * Setting.BoxPrecision);
56
+ h = Math.floor(r.height * Setting.BoxPrecision);
57
+ }
58
+
59
+ // Capture new width & height only if they are different from what we have in in-memory cache
60
+ if (w !== s[0] && h !== s[1]) {
61
+ s = [w,h];
62
+ data.push({ id, width: w, height: h });
63
+ }
64
+ }
65
+ }
66
+
67
+ // Schedule encode only when we have at least one valid data entry
68
+ if (data.length > 0) { encode(Event.Box); }
69
+ });
70
+ }
71
+
72
+ export function reset(): void {
73
+ data = [];
74
+ }
75
+
76
+ export function stop(): void {
77
+ reset();
78
+ if (observer) {
79
+ observer.disconnect();
80
+ observer = null;
81
+ }
82
+ enabled = false;
83
+ }
@@ -0,0 +1,27 @@
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
+
13
+ export function start(): void {
14
+ task.schedule(discover, Priority.High).then((): void => {
15
+ measure(doc.compute)();
16
+ measure(region.compute)();
17
+ });
18
+ }
19
+
20
+ async function discover(): Promise<void> {
21
+ let ts = time();
22
+ let timer: Timer = { id: id(), cost: Metric.LayoutCost };
23
+ task.start(timer);
24
+ await traverse(document, timer, Source.Discover);
25
+ await encode(Event.Discover, timer, ts);
26
+ task.stop(timer);
27
+ }
@@ -0,0 +1,46 @@
1
+ import { Event } from "@clarity-types/data";
2
+ import { DocumentData } from "@clarity-types/layout";
3
+ import encode from "./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 end(): void {
45
+ reset();
46
+ }