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.
Files changed (116) 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 +6101 -6071
  5. package/build/clarity.min.js +1 -1
  6. package/build/clarity.module.js +6101 -6071
  7. package/build/clarity.performance.js +1 -1
  8. package/package.json +70 -70
  9. package/rollup.config.ts +161 -161
  10. package/src/clarity.ts +65 -65
  11. package/src/core/api.ts +8 -8
  12. package/src/core/config.ts +29 -29
  13. package/src/core/copy.ts +3 -3
  14. package/src/core/dynamic.ts +13 -7
  15. package/src/core/event.ts +53 -53
  16. package/src/core/hash.ts +19 -19
  17. package/src/core/history.ts +71 -71
  18. package/src/core/index.ts +81 -81
  19. package/src/core/measure.ts +19 -19
  20. package/src/core/report.ts +28 -28
  21. package/src/core/scrub.ts +204 -202
  22. package/src/core/task.ts +181 -181
  23. package/src/core/throttle.ts +46 -46
  24. package/src/core/time.ts +26 -26
  25. package/src/core/timeout.ts +10 -10
  26. package/src/core/version.ts +2 -2
  27. package/src/data/baseline.ts +162 -162
  28. package/src/data/compress.ts +31 -31
  29. package/src/data/consent.ts +77 -77
  30. package/src/data/cookie.ts +90 -0
  31. package/src/data/custom.ts +23 -23
  32. package/src/data/dimension.ts +53 -53
  33. package/src/data/encode.ts +155 -155
  34. package/src/data/envelope.ts +53 -53
  35. package/src/data/extract.ts +211 -211
  36. package/src/data/index.ts +51 -50
  37. package/src/data/limit.ts +44 -44
  38. package/src/data/metadata.ts +321 -408
  39. package/src/data/metric.ts +51 -51
  40. package/src/data/ping.ts +36 -36
  41. package/src/data/signal.ts +30 -30
  42. package/src/data/summary.ts +34 -34
  43. package/src/data/token.ts +39 -39
  44. package/src/data/upgrade.ts +44 -44
  45. package/src/data/upload.ts +333 -333
  46. package/src/data/util.ts +18 -0
  47. package/src/data/variable.ts +83 -83
  48. package/src/diagnostic/encode.ts +40 -40
  49. package/src/diagnostic/fraud.ts +36 -36
  50. package/src/diagnostic/index.ts +13 -13
  51. package/src/diagnostic/internal.ts +28 -28
  52. package/src/diagnostic/script.ts +35 -35
  53. package/src/dynamic/agent/blank.ts +2 -2
  54. package/src/dynamic/agent/crisp.ts +40 -40
  55. package/src/dynamic/agent/encode.ts +25 -25
  56. package/src/dynamic/agent/index.ts +8 -8
  57. package/src/dynamic/agent/livechat.ts +58 -58
  58. package/src/dynamic/agent/tidio.ts +44 -44
  59. package/src/global.ts +6 -6
  60. package/src/index.ts +9 -9
  61. package/src/insight/blank.ts +14 -14
  62. package/src/insight/encode.ts +60 -60
  63. package/src/insight/snapshot.ts +114 -114
  64. package/src/interaction/change.ts +38 -38
  65. package/src/interaction/click.ts +173 -173
  66. package/src/interaction/clipboard.ts +32 -32
  67. package/src/interaction/encode.ts +210 -210
  68. package/src/interaction/index.ts +60 -60
  69. package/src/interaction/input.ts +57 -57
  70. package/src/interaction/pointer.ts +137 -137
  71. package/src/interaction/resize.ts +50 -50
  72. package/src/interaction/scroll.ts +129 -129
  73. package/src/interaction/selection.ts +66 -66
  74. package/src/interaction/submit.ts +30 -30
  75. package/src/interaction/timeline.ts +69 -69
  76. package/src/interaction/unload.ts +26 -26
  77. package/src/interaction/visibility.ts +27 -27
  78. package/src/layout/animation.ts +133 -133
  79. package/src/layout/custom.ts +42 -42
  80. package/src/layout/discover.ts +31 -31
  81. package/src/layout/document.ts +46 -46
  82. package/src/layout/dom.ts +439 -439
  83. package/src/layout/encode.ts +154 -154
  84. package/src/layout/index.ts +42 -42
  85. package/src/layout/mutation.ts +411 -411
  86. package/src/layout/node.ts +294 -294
  87. package/src/layout/offset.ts +19 -19
  88. package/src/layout/region.ts +151 -151
  89. package/src/layout/schema.ts +63 -63
  90. package/src/layout/selector.ts +82 -82
  91. package/src/layout/style.ts +159 -159
  92. package/src/layout/target.ts +32 -32
  93. package/src/layout/traverse.ts +27 -27
  94. package/src/performance/blank.ts +9 -9
  95. package/src/performance/encode.ts +31 -31
  96. package/src/performance/index.ts +12 -12
  97. package/src/performance/interaction.ts +125 -125
  98. package/src/performance/navigation.ts +31 -31
  99. package/src/performance/observer.ts +112 -112
  100. package/src/queue.ts +33 -33
  101. package/test/core.test.ts +139 -139
  102. package/test/helper.ts +162 -162
  103. package/test/html/core.html +27 -27
  104. package/test/stub.test.ts +7 -7
  105. package/test/tsconfig.test.json +5 -5
  106. package/tsconfig.json +21 -21
  107. package/tslint.json +32 -32
  108. package/types/agent.d.ts +39 -39
  109. package/types/core.d.ts +150 -150
  110. package/types/data.d.ts +572 -571
  111. package/types/diagnostic.d.ts +24 -24
  112. package/types/global.d.ts +30 -30
  113. package/types/index.d.ts +40 -40
  114. package/types/interaction.d.ts +177 -177
  115. package/types/layout.d.ts +276 -276
  116. package/types/performance.d.ts +31 -31
@@ -1,38 +1,38 @@
1
- import { Constant, Event, Setting } from "@clarity-types/data";
2
- import { ChangeState } from "@clarity-types/interaction";
3
- import config from "@src/core/config";
4
- import { bind } from "@src/core/event";
5
- import hash from "@src/core/hash";
6
- import { schedule } from "@src/core/task";
7
- import { time } from "@src/core/time";
8
- import { target } from "@src/layout/target";
9
- import encode from "./encode";
10
- import { Mask } from "@clarity-types/layout";
11
-
12
- export let state: ChangeState[] = [];
13
-
14
- export function start(): void {
15
- reset();
16
- }
17
-
18
- export function observe(root: Node): void {
19
- bind(root, "change", recompute, true);
20
- }
21
-
22
- function recompute(evt: UIEvent): void {
23
- let element = target(evt) as HTMLInputElement;
24
- if (element) {
25
- let value = element.value;
26
- let checksum = value && value.length >= Setting.WordLength && config.fraud && Mask.Exclude.indexOf(element.type) === -1 ? hash(value, Setting.ChecksumPrecision) : Constant.Empty;
27
- state.push({ time: time(evt), event: Event.Change, data: { target: target(evt), type: element.type, value, checksum } });
28
- schedule(encode.bind(this, Event.Change));
29
- }
30
- }
31
-
32
- export function reset(): void {
33
- state = [];
34
- }
35
-
36
- export function stop(): void {
37
- reset();
38
- }
1
+ import { Constant, Event, Setting } from "@clarity-types/data";
2
+ import { ChangeState } from "@clarity-types/interaction";
3
+ import config from "@src/core/config";
4
+ import { bind } from "@src/core/event";
5
+ import hash from "@src/core/hash";
6
+ import { schedule } from "@src/core/task";
7
+ import { time } from "@src/core/time";
8
+ import { target } from "@src/layout/target";
9
+ import encode from "./encode";
10
+ import { Mask } from "@clarity-types/layout";
11
+
12
+ export let state: ChangeState[] = [];
13
+
14
+ export function start(): void {
15
+ reset();
16
+ }
17
+
18
+ export function observe(root: Node): void {
19
+ bind(root, "change", recompute, true);
20
+ }
21
+
22
+ function recompute(evt: UIEvent): void {
23
+ let element = target(evt) as HTMLInputElement;
24
+ if (element) {
25
+ let value = element.value;
26
+ let checksum = value && value.length >= Setting.WordLength && config.fraud && Mask.Exclude.indexOf(element.type) === -1 ? hash(value, Setting.ChecksumPrecision) : Constant.Empty;
27
+ state.push({ time: time(evt), event: Event.Change, data: { target: target(evt), type: element.type, value, checksum } });
28
+ schedule(encode.bind(this, Event.Change));
29
+ }
30
+ }
31
+
32
+ export function reset(): void {
33
+ state = [];
34
+ }
35
+
36
+ export function stop(): void {
37
+ reset();
38
+ }
@@ -1,173 +1,173 @@
1
- import { BooleanFlag, Constant, Event, Setting } from "@clarity-types/data";
2
- import { BrowsingContext, ClickState, TextInfo } from "@clarity-types/interaction";
3
- import { Box } from "@clarity-types/layout";
4
- import { bind } from "@src/core/event";
5
- import { schedule } from "@src/core/task";
6
- import { time } from "@src/core/time";
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
- const UserInputTags = ["input", "textarea", "radio", "button", "canvas", "select"];
13
- export let state: ClickState[] = [];
14
-
15
- export function start(): void {
16
- reset();
17
- }
18
-
19
- export function observe(root: Node): void {
20
- bind(root, "click", handler.bind(this, Event.Click, root), true);
21
- bind(root, "contextmenu", handler.bind(this, Event.ContextMenu, root), true);
22
- }
23
-
24
- function handler(event: Event, root: Node, evt: MouseEvent): void {
25
- let frame = iframe(root);
26
- let d = frame && frame.contentDocument ? frame.contentDocument.documentElement : document.documentElement;
27
- let x = "pageX" in evt ? Math.round(evt.pageX) : ("clientX" in evt ? Math.round(evt["clientX"] + d.scrollLeft) : null);
28
- let y = "pageY" in evt ? Math.round(evt.pageY) : ("clientY" in evt ? Math.round(evt["clientY"] + d.scrollTop) : null);
29
- // In case of iframe, we adjust (x,y) to be relative to top parent's origin
30
- if (frame) {
31
- let distance = offset(frame);
32
- x = x ? x + Math.round(distance.x) : x;
33
- y = y ? y + Math.round(distance.y) : y;
34
- }
35
-
36
- let t = target(evt);
37
- // Find nearest anchor tag (<a/>) parent if current target node is part of one
38
- // If present, we use the returned link element to populate text and link properties below
39
- let a = link(t);
40
-
41
- // Get layout rectangle for the target element
42
- let l = layout(t as Element);
43
-
44
- // Reference: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
45
- // This property helps differentiate between a keyboard navigation vs. pointer click
46
- // In case of a keyboard navigation, we use center of target element as (x,y)
47
- if (evt.detail === 0 && l) {
48
- x = Math.round(l.x + (l.w / 2));
49
- y = Math.round(l.y + (l.h / 2));
50
- }
51
-
52
- let eX = l ? Math.max(Math.floor(((x - l.x) / l.w) * Setting.ClickPrecision), 0) : 0;
53
- let eY = l ? Math.max(Math.floor(((y - l.y) / l.h) * Setting.ClickPrecision), 0) : 0;
54
-
55
- // Check for null values before processing this event
56
- if (x !== null && y !== null) {
57
- const textInfo = text(t);
58
- state.push({
59
- time: time(evt), event, data: {
60
- target: t,
61
- x,
62
- y,
63
- eX,
64
- eY,
65
- button: evt.button,
66
- reaction: reaction(t),
67
- context: context(a),
68
- text: textInfo.text,
69
- link: a ? a.href : null,
70
- hash: null,
71
- trust: evt.isTrusted ? BooleanFlag.True : BooleanFlag.False,
72
- isFullText: textInfo.isFullText,
73
- w: l ? l.w : 0,
74
- h: l ? l.h : 0,
75
- tag: getElementAttribute(t, "tagName").substring(0, Setting.ClickTag),
76
- class: getElementAttribute(t, "className").substring(0, Setting.ClickClass),
77
- id: getElementAttribute(t, "id").substring(0, Setting.ClickId),
78
- }
79
- });
80
- schedule(encode.bind(this, event));
81
- }
82
- }
83
-
84
- function link(node: Node): HTMLAnchorElement {
85
- while (node && node !== document) {
86
- if (node.nodeType === Node.ELEMENT_NODE) {
87
- let element = node as HTMLElement;
88
- if (element.tagName === "A") {
89
- return element as HTMLAnchorElement;
90
- }
91
- }
92
- node = node.parentNode;
93
- }
94
- return null;
95
- }
96
-
97
- function text(element: Node): TextInfo {
98
- let output = null;
99
- let isFullText = false;
100
- if (element) {
101
- // Grab text using "textContent" for most HTMLElements, however, use "value" for HTMLInputElements and "alt" for HTMLImageElement.
102
- let t = element.textContent || String((element as HTMLInputElement).value || '') || (element as HTMLImageElement).alt;
103
- if (t) {
104
- // Replace multiple occurrence of space characters with a single white space
105
- // Also, trim any spaces at the beginning or at the end of string
106
- const trimmedText = t.replace(/\s+/g, Constant.Space).trim();
107
- // Finally, send only first few characters as specified by the Setting
108
- output = trimmedText.substring(0, Setting.ClickText);
109
- isFullText = output.length === trimmedText.length;
110
- }
111
- }
112
-
113
- return { text: output, isFullText: isFullText ? BooleanFlag.True : BooleanFlag.False };
114
- }
115
-
116
- function reaction(element: Node): BooleanFlag {
117
- const tag = getElementAttribute(element, "tagName");
118
- if (UserInputTags.indexOf(tag) >= 0) {
119
- return BooleanFlag.False;
120
- }
121
- return BooleanFlag.True;
122
- }
123
-
124
- function getElementAttribute(element: Node, attribute: "tagName" | "className" | "id"): string {
125
- if (element.nodeType === Node.ELEMENT_NODE) {
126
- const attr = (element as HTMLElement)?.[attribute];
127
- const value = typeof attr === "string" ? attr?.toLowerCase() : "";
128
- return value;
129
- }
130
- return "";
131
- }
132
-
133
- function layout(element: Element): Box {
134
- let box: Box = null;
135
- let de = document.documentElement;
136
- if (typeof element.getBoundingClientRect === "function") {
137
- // getBoundingClientRect returns rectangle relative positioning to viewport
138
- let rect = element.getBoundingClientRect();
139
-
140
- if (rect && rect.width > 0 && rect.height > 0) {
141
- // Add viewport's scroll position to rectangle to get position relative to document origin
142
- // Also: using Math.floor() instead of Math.round() because in Edge,
143
- // getBoundingClientRect returns partial pixel values (e.g. 162.5px) and Chrome already
144
- // floors the value (e.g. 162px). This keeps consistent behavior across browsers.
145
- box = {
146
- x: Math.floor(rect.left + ("pageXOffset" in window ? window.pageXOffset : de.scrollLeft)),
147
- y: Math.floor(rect.top + ("pageYOffset" in window ? window.pageYOffset : de.scrollTop)),
148
- w: Math.floor(rect.width),
149
- h: Math.floor(rect.height)
150
- };
151
- }
152
- }
153
- return box;
154
- }
155
-
156
- function context(a: HTMLAnchorElement): BrowsingContext {
157
- if (a && a.hasAttribute(Constant.Target)) {
158
- switch (a.getAttribute(Constant.Target)) {
159
- case Constant.Blank: return BrowsingContext.Blank;
160
- case Constant.Parent: return BrowsingContext.Parent;
161
- case Constant.Top: return BrowsingContext.Top;
162
- }
163
- }
164
- return BrowsingContext.Self;
165
- }
166
-
167
- export function reset(): void {
168
- state = [];
169
- }
170
-
171
- export function stop(): void {
172
- reset();
173
- }
1
+ import { BooleanFlag, Constant, Event, Setting } from "@clarity-types/data";
2
+ import { BrowsingContext, ClickState, TextInfo } from "@clarity-types/interaction";
3
+ import { Box } from "@clarity-types/layout";
4
+ import { bind } from "@src/core/event";
5
+ import { schedule } from "@src/core/task";
6
+ import { time } from "@src/core/time";
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
+ const UserInputTags = ["input", "textarea", "radio", "button", "canvas", "select"];
13
+ export let state: ClickState[] = [];
14
+
15
+ export function start(): void {
16
+ reset();
17
+ }
18
+
19
+ export function observe(root: Node): void {
20
+ bind(root, "click", handler.bind(this, Event.Click, root), true);
21
+ bind(root, "contextmenu", handler.bind(this, Event.ContextMenu, root), true);
22
+ }
23
+
24
+ function handler(event: Event, root: Node, evt: MouseEvent): void {
25
+ let frame = iframe(root);
26
+ let d = frame && frame.contentDocument ? frame.contentDocument.documentElement : document.documentElement;
27
+ let x = "pageX" in evt ? Math.round(evt.pageX) : ("clientX" in evt ? Math.round(evt["clientX"] + d.scrollLeft) : null);
28
+ let y = "pageY" in evt ? Math.round(evt.pageY) : ("clientY" in evt ? Math.round(evt["clientY"] + d.scrollTop) : null);
29
+ // In case of iframe, we adjust (x,y) to be relative to top parent's origin
30
+ if (frame) {
31
+ let distance = offset(frame);
32
+ x = x ? x + Math.round(distance.x) : x;
33
+ y = y ? y + Math.round(distance.y) : y;
34
+ }
35
+
36
+ let t = target(evt);
37
+ // Find nearest anchor tag (<a/>) parent if current target node is part of one
38
+ // If present, we use the returned link element to populate text and link properties below
39
+ let a = link(t);
40
+
41
+ // Get layout rectangle for the target element
42
+ let l = layout(t as Element);
43
+
44
+ // Reference: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
45
+ // This property helps differentiate between a keyboard navigation vs. pointer click
46
+ // In case of a keyboard navigation, we use center of target element as (x,y)
47
+ if (evt.detail === 0 && l) {
48
+ x = Math.round(l.x + (l.w / 2));
49
+ y = Math.round(l.y + (l.h / 2));
50
+ }
51
+
52
+ let eX = l ? Math.max(Math.floor(((x - l.x) / l.w) * Setting.ClickPrecision), 0) : 0;
53
+ let eY = l ? Math.max(Math.floor(((y - l.y) / l.h) * Setting.ClickPrecision), 0) : 0;
54
+
55
+ // Check for null values before processing this event
56
+ if (x !== null && y !== null) {
57
+ const textInfo = text(t);
58
+ state.push({
59
+ time: time(evt), event, data: {
60
+ target: t,
61
+ x,
62
+ y,
63
+ eX,
64
+ eY,
65
+ button: evt.button,
66
+ reaction: reaction(t),
67
+ context: context(a),
68
+ text: textInfo.text,
69
+ link: a ? a.href : null,
70
+ hash: null,
71
+ trust: evt.isTrusted ? BooleanFlag.True : BooleanFlag.False,
72
+ isFullText: textInfo.isFullText,
73
+ w: l ? l.w : 0,
74
+ h: l ? l.h : 0,
75
+ tag: getElementAttribute(t, "tagName").substring(0, Setting.ClickTag),
76
+ class: getElementAttribute(t, "className").substring(0, Setting.ClickClass),
77
+ id: getElementAttribute(t, "id").substring(0, Setting.ClickId),
78
+ }
79
+ });
80
+ schedule(encode.bind(this, event));
81
+ }
82
+ }
83
+
84
+ function link(node: Node): HTMLAnchorElement {
85
+ while (node && node !== document) {
86
+ if (node.nodeType === Node.ELEMENT_NODE) {
87
+ let element = node as HTMLElement;
88
+ if (element.tagName === "A") {
89
+ return element as HTMLAnchorElement;
90
+ }
91
+ }
92
+ node = node.parentNode;
93
+ }
94
+ return null;
95
+ }
96
+
97
+ function text(element: Node): TextInfo {
98
+ let output = null;
99
+ let isFullText = false;
100
+ if (element) {
101
+ // Grab text using "textContent" for most HTMLElements, however, use "value" for HTMLInputElements and "alt" for HTMLImageElement.
102
+ let t = element.textContent || String((element as HTMLInputElement).value || '') || (element as HTMLImageElement).alt;
103
+ if (t) {
104
+ // Replace multiple occurrence of space characters with a single white space
105
+ // Also, trim any spaces at the beginning or at the end of string
106
+ const trimmedText = t.replace(/\s+/g, Constant.Space).trim();
107
+ // Finally, send only first few characters as specified by the Setting
108
+ output = trimmedText.substring(0, Setting.ClickText);
109
+ isFullText = output.length === trimmedText.length;
110
+ }
111
+ }
112
+
113
+ return { text: output, isFullText: isFullText ? BooleanFlag.True : BooleanFlag.False };
114
+ }
115
+
116
+ function reaction(element: Node): BooleanFlag {
117
+ const tag = getElementAttribute(element, "tagName");
118
+ if (UserInputTags.indexOf(tag) >= 0) {
119
+ return BooleanFlag.False;
120
+ }
121
+ return BooleanFlag.True;
122
+ }
123
+
124
+ function getElementAttribute(element: Node, attribute: "tagName" | "className" | "id"): string {
125
+ if (element.nodeType === Node.ELEMENT_NODE) {
126
+ const attr = (element as HTMLElement)?.[attribute];
127
+ const value = typeof attr === "string" ? attr?.toLowerCase() : "";
128
+ return value;
129
+ }
130
+ return "";
131
+ }
132
+
133
+ function layout(element: Element): Box {
134
+ let box: Box = null;
135
+ let de = document.documentElement;
136
+ if (typeof element.getBoundingClientRect === "function") {
137
+ // getBoundingClientRect returns rectangle relative positioning to viewport
138
+ let rect = element.getBoundingClientRect();
139
+
140
+ if (rect && rect.width > 0 && rect.height > 0) {
141
+ // Add viewport's scroll position to rectangle to get position relative to document origin
142
+ // Also: using Math.floor() instead of Math.round() because in Edge,
143
+ // getBoundingClientRect returns partial pixel values (e.g. 162.5px) and Chrome already
144
+ // floors the value (e.g. 162px). This keeps consistent behavior across browsers.
145
+ box = {
146
+ x: Math.floor(rect.left + ("pageXOffset" in window ? window.pageXOffset : de.scrollLeft)),
147
+ y: Math.floor(rect.top + ("pageYOffset" in window ? window.pageYOffset : de.scrollTop)),
148
+ w: Math.floor(rect.width),
149
+ h: Math.floor(rect.height)
150
+ };
151
+ }
152
+ }
153
+ return box;
154
+ }
155
+
156
+ function context(a: HTMLAnchorElement): BrowsingContext {
157
+ if (a && a.hasAttribute(Constant.Target)) {
158
+ switch (a.getAttribute(Constant.Target)) {
159
+ case Constant.Blank: return BrowsingContext.Blank;
160
+ case Constant.Parent: return BrowsingContext.Parent;
161
+ case Constant.Top: return BrowsingContext.Top;
162
+ }
163
+ }
164
+ return BrowsingContext.Self;
165
+ }
166
+
167
+ export function reset(): void {
168
+ state = [];
169
+ }
170
+
171
+ export function stop(): void {
172
+ reset();
173
+ }
@@ -1,32 +1,32 @@
1
- import { Event } from "@clarity-types/data";
2
- import { Clipboard, ClipboardState } 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 encode from "./encode";
7
- import { target } from "@src/layout/target";
8
-
9
- export let state: ClipboardState[] = [];
10
-
11
- export function start(): void {
12
- reset();
13
- }
14
-
15
- export function observe(root: Node): void {
16
- bind(root, "cut", recompute.bind(this, Clipboard.Cut), true);
17
- bind(root, "copy", recompute.bind(this, Clipboard.Copy), true);
18
- bind(root, "paste", recompute.bind(this, Clipboard.Paste), true);
19
- }
20
-
21
- function recompute(action: Clipboard, evt: UIEvent): void {
22
- state.push({ time: time(evt), event: Event.Clipboard, data: { target: target(evt), action } });
23
- schedule(encode.bind(this, Event.Clipboard));
24
- }
25
-
26
- export function reset(): void {
27
- state = [];
28
- }
29
-
30
- export function stop(): void {
31
- reset();
32
- }
1
+ import { Event } from "@clarity-types/data";
2
+ import { Clipboard, ClipboardState } 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 encode from "./encode";
7
+ import { target } from "@src/layout/target";
8
+
9
+ export let state: ClipboardState[] = [];
10
+
11
+ export function start(): void {
12
+ reset();
13
+ }
14
+
15
+ export function observe(root: Node): void {
16
+ bind(root, "cut", recompute.bind(this, Clipboard.Cut), true);
17
+ bind(root, "copy", recompute.bind(this, Clipboard.Copy), true);
18
+ bind(root, "paste", recompute.bind(this, Clipboard.Paste), true);
19
+ }
20
+
21
+ function recompute(action: Clipboard, evt: UIEvent): void {
22
+ state.push({ time: time(evt), event: Event.Clipboard, data: { target: target(evt), action } });
23
+ schedule(encode.bind(this, Event.Clipboard));
24
+ }
25
+
26
+ export function reset(): void {
27
+ state = [];
28
+ }
29
+
30
+ export function stop(): void {
31
+ reset();
32
+ }