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,210 +1,210 @@
1
- import { Constant, Event, Token } from "@clarity-types/data";
2
- import * as scrub from "@src/core/scrub";
3
- import { time } from "@src/core/time";
4
- import * as baseline from "@src/data/baseline";
5
- import { queue } from "@src/data/upload";
6
- import { metadata } from "@src/layout/target";
7
- import * as change from "@src/interaction/change";
8
- import * as click from "@src/interaction/click";
9
- import * as clipboard from "@src/interaction/clipboard";
10
- import * as input from "@src/interaction/input";
11
- import * as pointer from "@src/interaction/pointer";
12
- import * as resize from "@src/interaction/resize";
13
- import * as scroll from "@src/interaction/scroll";
14
- import * as selection from "@src/interaction/selection";
15
- import * as submit from "@src/interaction/submit";
16
- import * as timeline from "@src/interaction/timeline";
17
- import * as unload from "@src/interaction/unload";
18
- import * as visibility from "@src/interaction/visibility";
19
- import * as focus from "@src/interaction/focus";
20
-
21
- export default async function (type: Event, ts: number = null): Promise<void> {
22
- let t = ts || time();
23
- let tokens: Token[] = [t, type];
24
- switch (type) {
25
- case Event.MouseDown:
26
- case Event.MouseUp:
27
- case Event.MouseMove:
28
- case Event.MouseWheel:
29
- case Event.DoubleClick:
30
- case Event.TouchStart:
31
- case Event.TouchEnd:
32
- case Event.TouchMove:
33
- case Event.TouchCancel:
34
- for (let entry of pointer.state) {
35
- let pTarget = metadata(entry.data.target as Node, entry.event);
36
- if (pTarget.id > 0) {
37
- tokens = [entry.time, entry.event];
38
- tokens.push(pTarget.id);
39
- tokens.push(entry.data.x);
40
- tokens.push(entry.data.y);
41
- if (entry.data.id !== undefined) {
42
- tokens.push(entry.data.id);
43
-
44
- if (entry.data.isPrimary !== undefined) {
45
- tokens.push(entry.data.isPrimary.toString());
46
- }
47
- }
48
- queue(tokens);
49
- if (entry.data.isPrimary === undefined || entry.data.isPrimary) {
50
- baseline.track(entry.event, entry.data.x, entry.data.y, entry.time);
51
- }
52
- }
53
- }
54
- pointer.reset();
55
- break;
56
- case Event.Click:
57
- case Event.ContextMenu:
58
- for (let entry of click.state) {
59
- let cTarget = metadata(entry.data.target as Node, entry.event, entry.data.text);
60
- tokens = [entry.time, entry.event];
61
- let cHash = cTarget.hash ? cTarget.hash.join(Constant.Dot) : Constant.Empty;
62
- tokens.push(cTarget.id);
63
- tokens.push(entry.data.x);
64
- tokens.push(entry.data.y);
65
- tokens.push(entry.data.eX);
66
- tokens.push(entry.data.eY);
67
- tokens.push(entry.data.button);
68
- tokens.push(entry.data.reaction);
69
- tokens.push(entry.data.context);
70
- tokens.push(scrub.text(entry.data.text, "click", cTarget.privacy));
71
- tokens.push(scrub.url(entry.data.link));
72
- tokens.push(cHash);
73
- tokens.push(entry.data.trust);
74
- tokens.push(entry.data.isFullText);
75
- tokens.push(entry.data.w);
76
- tokens.push(entry.data.h);
77
- tokens.push(entry.data.tag);
78
- tokens.push(entry.data.class);
79
- tokens.push(entry.data.id);
80
- queue(tokens);
81
- timeline.track(entry.time, entry.event, cHash, entry.data.x, entry.data.y, entry.data.reaction, entry.data.context);
82
- }
83
- click.reset();
84
- break;
85
- case Event.Clipboard:
86
- for (let entry of clipboard.state) {
87
- tokens = [entry.time, entry.event];
88
- let target = metadata(entry.data.target as Node, entry.event);
89
- if (target.id > 0) {
90
- tokens.push(target.id);
91
- tokens.push(entry.data.action);
92
- queue(tokens);
93
- }
94
- }
95
- clipboard.reset();
96
- break;
97
- case Event.Resize:
98
- let r = resize.data;
99
- tokens.push(r.width);
100
- tokens.push(r.height);
101
- baseline.track(type, r.width, r.height);
102
- resize.reset();
103
- queue(tokens);
104
- break;
105
- case Event.Unload:
106
- let u = unload.data;
107
- tokens.push(u.name);
108
- tokens.push(u.persisted);
109
- unload.reset();
110
- queue(tokens);
111
- break;
112
- case Event.Input:
113
- for (let entry of input.state) {
114
- let iTarget = metadata(entry.data.target as Node, entry.event, entry.data.value);
115
- tokens = [entry.time, entry.event];
116
- tokens.push(iTarget.id);
117
- tokens.push(scrub.text(entry.data.value, "input", iTarget.privacy, false, entry.data.type));
118
- tokens.push(entry.data.trust);
119
- queue(tokens);
120
- }
121
- input.reset();
122
- break;
123
- case Event.Selection:
124
- let s = selection.data;
125
- if (s) {
126
- let startTarget = metadata(s.start as Node, type);
127
- let endTarget = metadata(s.end as Node, type);
128
- tokens.push(startTarget.id);
129
- tokens.push(s.startOffset);
130
- tokens.push(endTarget.id);
131
- tokens.push(s.endOffset);
132
- selection.reset();
133
- queue(tokens);
134
- }
135
- break;
136
- case Event.Scroll:
137
- for (let entry of scroll.state) {
138
- let sTarget = metadata(entry.data.target as Node, entry.event);
139
- const top = metadata(entry.data.top as Node, entry.event);
140
- const bottom = metadata(entry.data.bottom as Node, entry.event);
141
- const sTopHash = top?.hash ? top.hash.join(Constant.Dot) : Constant.Empty;
142
- const sBottomHash = bottom?.hash ? bottom.hash.join(Constant.Dot) : Constant.Empty;
143
- if (sTarget.id > 0) {
144
- tokens = [entry.time, entry.event];
145
- tokens.push(sTarget.id);
146
- tokens.push(entry.data.x);
147
- tokens.push(entry.data.y);
148
- tokens.push(sTopHash);
149
- tokens.push(sBottomHash);
150
- queue(tokens);
151
- baseline.track(entry.event, entry.data.x, entry.data.y, entry.time);
152
- }
153
- }
154
- scroll.reset();
155
- break;
156
- case Event.Change:
157
- for (let entry of change.state) {
158
- tokens = [entry.time, entry.event];
159
- let target = metadata(entry.data.target as Node, entry.event);
160
- if (target.id > 0) {
161
- tokens = [entry.time, entry.event];
162
- tokens.push(target.id);
163
- tokens.push(entry.data.type);
164
- tokens.push(scrub.text(entry.data.value, "change", target.privacy));
165
- tokens.push(scrub.text(entry.data.checksum, "checksum", target.privacy));
166
- queue(tokens);
167
- }
168
- }
169
- change.reset();
170
- break;
171
- case Event.Submit:
172
- for (let entry of submit.state) {
173
- tokens = [entry.time, entry.event];
174
- let target = metadata(entry.data.target as Node, entry.event);
175
- if (target.id > 0) {
176
- tokens.push(target.id);
177
- queue(tokens);
178
- }
179
- }
180
- submit.reset();
181
- break;
182
- case Event.Timeline:
183
- for (let entry of timeline.updates) {
184
- tokens = [entry.time, entry.event];
185
- tokens.push(entry.data.type);
186
- tokens.push(entry.data.hash);
187
- tokens.push(entry.data.x);
188
- tokens.push(entry.data.y);
189
- tokens.push(entry.data.reaction);
190
- tokens.push(entry.data.context);
191
- queue(tokens, false);
192
- }
193
- timeline.reset();
194
- break;
195
- case Event.Visibility:
196
- let v = visibility.data;
197
- tokens.push(v.visible);
198
- queue(tokens);
199
- baseline.visibility(t, v.visible);
200
- visibility.reset();
201
- break;
202
- case Event.Focus: {
203
- let f = focus.data;
204
- tokens.push(f.focused);
205
- queue(tokens, false);
206
- focus.reset();
207
- break;
208
- }
209
- }
210
- }
1
+ import { Constant, Event, Token } from "@clarity-types/data";
2
+ import * as scrub from "@src/core/scrub";
3
+ import { time } from "@src/core/time";
4
+ import * as baseline from "@src/data/baseline";
5
+ import { queue } from "@src/data/upload";
6
+ import { metadata } from "@src/layout/target";
7
+ import * as change from "@src/interaction/change";
8
+ import * as click from "@src/interaction/click";
9
+ import * as clipboard from "@src/interaction/clipboard";
10
+ import * as input from "@src/interaction/input";
11
+ import * as pointer from "@src/interaction/pointer";
12
+ import * as resize from "@src/interaction/resize";
13
+ import * as scroll from "@src/interaction/scroll";
14
+ import * as selection from "@src/interaction/selection";
15
+ import * as submit from "@src/interaction/submit";
16
+ import * as timeline from "@src/interaction/timeline";
17
+ import * as unload from "@src/interaction/unload";
18
+ import * as visibility from "@src/interaction/visibility";
19
+ import * as focus from "@src/interaction/focus";
20
+
21
+ export default async function (type: Event, ts: number = null): Promise<void> {
22
+ let t = ts || time();
23
+ let tokens: Token[] = [t, type];
24
+ switch (type) {
25
+ case Event.MouseDown:
26
+ case Event.MouseUp:
27
+ case Event.MouseMove:
28
+ case Event.MouseWheel:
29
+ case Event.DoubleClick:
30
+ case Event.TouchStart:
31
+ case Event.TouchEnd:
32
+ case Event.TouchMove:
33
+ case Event.TouchCancel:
34
+ for (let entry of pointer.state) {
35
+ let pTarget = metadata(entry.data.target as Node, entry.event);
36
+ if (pTarget.id > 0) {
37
+ tokens = [entry.time, entry.event];
38
+ tokens.push(pTarget.id);
39
+ tokens.push(entry.data.x);
40
+ tokens.push(entry.data.y);
41
+ if (entry.data.id !== undefined) {
42
+ tokens.push(entry.data.id);
43
+
44
+ if (entry.data.isPrimary !== undefined) {
45
+ tokens.push(entry.data.isPrimary.toString());
46
+ }
47
+ }
48
+ queue(tokens);
49
+ if (entry.data.isPrimary === undefined || entry.data.isPrimary) {
50
+ baseline.track(entry.event, entry.data.x, entry.data.y, entry.time);
51
+ }
52
+ }
53
+ }
54
+ pointer.reset();
55
+ break;
56
+ case Event.Click:
57
+ case Event.ContextMenu:
58
+ for (let entry of click.state) {
59
+ let cTarget = metadata(entry.data.target as Node, entry.event, entry.data.text);
60
+ tokens = [entry.time, entry.event];
61
+ let cHash = cTarget.hash ? cTarget.hash.join(Constant.Dot) : Constant.Empty;
62
+ tokens.push(cTarget.id);
63
+ tokens.push(entry.data.x);
64
+ tokens.push(entry.data.y);
65
+ tokens.push(entry.data.eX);
66
+ tokens.push(entry.data.eY);
67
+ tokens.push(entry.data.button);
68
+ tokens.push(entry.data.reaction);
69
+ tokens.push(entry.data.context);
70
+ tokens.push(scrub.text(entry.data.text, "click", cTarget.privacy));
71
+ tokens.push(scrub.url(entry.data.link));
72
+ tokens.push(cHash);
73
+ tokens.push(entry.data.trust);
74
+ tokens.push(entry.data.isFullText);
75
+ tokens.push(entry.data.w);
76
+ tokens.push(entry.data.h);
77
+ tokens.push(entry.data.tag);
78
+ tokens.push(entry.data.class);
79
+ tokens.push(entry.data.id);
80
+ queue(tokens);
81
+ timeline.track(entry.time, entry.event, cHash, entry.data.x, entry.data.y, entry.data.reaction, entry.data.context);
82
+ }
83
+ click.reset();
84
+ break;
85
+ case Event.Clipboard:
86
+ for (let entry of clipboard.state) {
87
+ tokens = [entry.time, entry.event];
88
+ let target = metadata(entry.data.target as Node, entry.event);
89
+ if (target.id > 0) {
90
+ tokens.push(target.id);
91
+ tokens.push(entry.data.action);
92
+ queue(tokens);
93
+ }
94
+ }
95
+ clipboard.reset();
96
+ break;
97
+ case Event.Resize:
98
+ let r = resize.data;
99
+ tokens.push(r.width);
100
+ tokens.push(r.height);
101
+ baseline.track(type, r.width, r.height);
102
+ resize.reset();
103
+ queue(tokens);
104
+ break;
105
+ case Event.Unload:
106
+ let u = unload.data;
107
+ tokens.push(u.name);
108
+ tokens.push(u.persisted);
109
+ unload.reset();
110
+ queue(tokens);
111
+ break;
112
+ case Event.Input:
113
+ for (let entry of input.state) {
114
+ let iTarget = metadata(entry.data.target as Node, entry.event, entry.data.value);
115
+ tokens = [entry.time, entry.event];
116
+ tokens.push(iTarget.id);
117
+ tokens.push(scrub.text(entry.data.value, "input", iTarget.privacy, false, entry.data.type));
118
+ tokens.push(entry.data.trust);
119
+ queue(tokens);
120
+ }
121
+ input.reset();
122
+ break;
123
+ case Event.Selection:
124
+ let s = selection.data;
125
+ if (s) {
126
+ let startTarget = metadata(s.start as Node, type);
127
+ let endTarget = metadata(s.end as Node, type);
128
+ tokens.push(startTarget.id);
129
+ tokens.push(s.startOffset);
130
+ tokens.push(endTarget.id);
131
+ tokens.push(s.endOffset);
132
+ selection.reset();
133
+ queue(tokens);
134
+ }
135
+ break;
136
+ case Event.Scroll:
137
+ for (let entry of scroll.state) {
138
+ let sTarget = metadata(entry.data.target as Node, entry.event);
139
+ const top = metadata(entry.data.top as Node, entry.event);
140
+ const bottom = metadata(entry.data.bottom as Node, entry.event);
141
+ const sTopHash = top?.hash ? top.hash.join(Constant.Dot) : Constant.Empty;
142
+ const sBottomHash = bottom?.hash ? bottom.hash.join(Constant.Dot) : Constant.Empty;
143
+ if (sTarget.id > 0) {
144
+ tokens = [entry.time, entry.event];
145
+ tokens.push(sTarget.id);
146
+ tokens.push(entry.data.x);
147
+ tokens.push(entry.data.y);
148
+ tokens.push(sTopHash);
149
+ tokens.push(sBottomHash);
150
+ queue(tokens);
151
+ baseline.track(entry.event, entry.data.x, entry.data.y, entry.time);
152
+ }
153
+ }
154
+ scroll.reset();
155
+ break;
156
+ case Event.Change:
157
+ for (let entry of change.state) {
158
+ tokens = [entry.time, entry.event];
159
+ let target = metadata(entry.data.target as Node, entry.event);
160
+ if (target.id > 0) {
161
+ tokens = [entry.time, entry.event];
162
+ tokens.push(target.id);
163
+ tokens.push(entry.data.type);
164
+ tokens.push(scrub.text(entry.data.value, "change", target.privacy));
165
+ tokens.push(scrub.text(entry.data.checksum, "checksum", target.privacy));
166
+ queue(tokens);
167
+ }
168
+ }
169
+ change.reset();
170
+ break;
171
+ case Event.Submit:
172
+ for (let entry of submit.state) {
173
+ tokens = [entry.time, entry.event];
174
+ let target = metadata(entry.data.target as Node, entry.event);
175
+ if (target.id > 0) {
176
+ tokens.push(target.id);
177
+ queue(tokens);
178
+ }
179
+ }
180
+ submit.reset();
181
+ break;
182
+ case Event.Timeline:
183
+ for (let entry of timeline.updates) {
184
+ tokens = [entry.time, entry.event];
185
+ tokens.push(entry.data.type);
186
+ tokens.push(entry.data.hash);
187
+ tokens.push(entry.data.x);
188
+ tokens.push(entry.data.y);
189
+ tokens.push(entry.data.reaction);
190
+ tokens.push(entry.data.context);
191
+ queue(tokens, false);
192
+ }
193
+ timeline.reset();
194
+ break;
195
+ case Event.Visibility:
196
+ let v = visibility.data;
197
+ tokens.push(v.visible);
198
+ queue(tokens);
199
+ baseline.visibility(t, v.visible);
200
+ visibility.reset();
201
+ break;
202
+ case Event.Focus: {
203
+ let f = focus.data;
204
+ tokens.push(f.focused);
205
+ queue(tokens, false);
206
+ focus.reset();
207
+ break;
208
+ }
209
+ }
210
+ }
@@ -1,60 +1,60 @@
1
- import * as change from "@src/interaction/change";
2
- import * as click from "@src/interaction/click";
3
- import * as clipboard from "@src/interaction/clipboard";
4
- import * as input from "@src/interaction/input";
5
- import * as pointer from "@src/interaction/pointer";
6
- import * as resize from "@src/interaction/resize";
7
- import * as scroll from "@src/interaction/scroll";
8
- import * as selection from "@src/interaction/selection";
9
- import * as submit from "@src/interaction/submit";
10
- import * as timeline from "@src/interaction/timeline";
11
- import * as unload from "@src/interaction/unload";
12
- import * as visibility from "@src/interaction/visibility";
13
- import * as focus from "@src/interaction/focus";
14
-
15
- export function start(): void {
16
- timeline.start();
17
- click.start();
18
- clipboard.start();
19
- pointer.start();
20
- input.start();
21
- resize.start();
22
- visibility.start();
23
- focus.start();
24
- scroll.start();
25
- selection.start();
26
- change.start();
27
- submit.start();
28
- unload.start();
29
- }
30
-
31
- export function stop(): void {
32
- timeline.stop();
33
- click.stop();
34
- clipboard.stop();
35
- pointer.stop();
36
- input.stop();
37
- resize.stop();
38
- visibility.stop();
39
- focus.stop();
40
- scroll.stop();
41
- selection.stop();
42
- change.stop();
43
- submit.stop();
44
- unload.stop()
45
- }
46
-
47
- export function observe(root: Node): void {
48
- scroll.observe(root);
49
- // Only monitor following interactions if the root node is a document
50
- // In case of shadow DOM, following events automatically bubble up to the parent document.
51
- if (root.nodeType === Node.DOCUMENT_NODE) {
52
- click.observe(root);
53
- clipboard.observe(root);
54
- pointer.observe(root);
55
- input.observe(root);
56
- selection.observe(root);
57
- change.observe(root);
58
- submit.observe(root);
59
- }
60
- }
1
+ import * as change from "@src/interaction/change";
2
+ import * as click from "@src/interaction/click";
3
+ import * as clipboard from "@src/interaction/clipboard";
4
+ import * as input from "@src/interaction/input";
5
+ import * as pointer from "@src/interaction/pointer";
6
+ import * as resize from "@src/interaction/resize";
7
+ import * as scroll from "@src/interaction/scroll";
8
+ import * as selection from "@src/interaction/selection";
9
+ import * as submit from "@src/interaction/submit";
10
+ import * as timeline from "@src/interaction/timeline";
11
+ import * as unload from "@src/interaction/unload";
12
+ import * as visibility from "@src/interaction/visibility";
13
+ import * as focus from "@src/interaction/focus";
14
+
15
+ export function start(): void {
16
+ timeline.start();
17
+ click.start();
18
+ clipboard.start();
19
+ pointer.start();
20
+ input.start();
21
+ resize.start();
22
+ visibility.start();
23
+ focus.start();
24
+ scroll.start();
25
+ selection.start();
26
+ change.start();
27
+ submit.start();
28
+ unload.start();
29
+ }
30
+
31
+ export function stop(): void {
32
+ timeline.stop();
33
+ click.stop();
34
+ clipboard.stop();
35
+ pointer.stop();
36
+ input.stop();
37
+ resize.stop();
38
+ visibility.stop();
39
+ focus.stop();
40
+ scroll.stop();
41
+ selection.stop();
42
+ change.stop();
43
+ submit.stop();
44
+ unload.stop()
45
+ }
46
+
47
+ export function observe(root: Node): void {
48
+ scroll.observe(root);
49
+ // Only monitor following interactions if the root node is a document
50
+ // In case of shadow DOM, following events automatically bubble up to the parent document.
51
+ if (root.nodeType === Node.DOCUMENT_NODE) {
52
+ click.observe(root);
53
+ clipboard.observe(root);
54
+ pointer.observe(root);
55
+ input.observe(root);
56
+ selection.observe(root);
57
+ change.observe(root);
58
+ submit.observe(root);
59
+ }
60
+ }
@@ -1,58 +1,58 @@
1
- import { BooleanFlag, Event } from "@clarity-types/data";
2
- import { InputData, InputState, 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 { get } from "@src/layout/dom";
8
- import encode from "./encode";
9
- import { target } from "@src/layout/target";
10
-
11
- let timeout: number = null;
12
- export let state: InputState[] = [];
13
-
14
- export function start(): void {
15
- reset();
16
- }
17
-
18
- export function observe(root: Node): void {
19
- bind(root, "input", recompute, true);
20
- }
21
-
22
- function recompute(evt: UIEvent): void {
23
- let input = target(evt) as HTMLInputElement;
24
- let value = get(input);
25
- if (input && input.type && value) {
26
- let v = input.value;
27
- let t = input.type;
28
- switch (input.type) {
29
- case "radio":
30
- case "checkbox":
31
- v = input.checked ? "true" : "false";
32
- break;
33
- }
34
-
35
- let data: InputData = { target: input, value: v, type: t, trust: evt.isTrusted ? BooleanFlag.True : BooleanFlag.False };
36
-
37
- // If last entry in the queue is for the same target node as the current one, remove it so we can later swap it with current data.
38
- if (state.length > 0 && (state[state.length - 1].data.target === data.target)) { state.pop(); }
39
-
40
- state.push({ time: time(evt), event: Event.Input, data });
41
-
42
- clearTimeout(timeout);
43
- timeout = setTimeout(process, Setting.InputLookAhead, Event.Input);
44
- }
45
- }
46
-
47
- function process(event: Event): void {
48
- schedule(encode.bind(this, event));
49
- }
50
-
51
- export function reset(): void {
52
- state = [];
53
- }
54
-
55
- export function stop(): void {
56
- clearTimeout(timeout);
57
- reset();
1
+ import { BooleanFlag, Event } from "@clarity-types/data";
2
+ import { InputData, InputState, 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 { get } from "@src/layout/dom";
8
+ import encode from "./encode";
9
+ import { target } from "@src/layout/target";
10
+
11
+ let timeout: number = null;
12
+ export let state: InputState[] = [];
13
+
14
+ export function start(): void {
15
+ reset();
16
+ }
17
+
18
+ export function observe(root: Node): void {
19
+ bind(root, "input", recompute, true);
20
+ }
21
+
22
+ function recompute(evt: UIEvent): void {
23
+ let input = target(evt) as HTMLInputElement;
24
+ let value = get(input);
25
+ if (input && input.type && value) {
26
+ let v = input.value;
27
+ let t = input.type;
28
+ switch (input.type) {
29
+ case "radio":
30
+ case "checkbox":
31
+ v = input.checked ? "true" : "false";
32
+ break;
33
+ }
34
+
35
+ let data: InputData = { target: input, value: v, type: t, trust: evt.isTrusted ? BooleanFlag.True : BooleanFlag.False };
36
+
37
+ // If last entry in the queue is for the same target node as the current one, remove it so we can later swap it with current data.
38
+ if (state.length > 0 && (state[state.length - 1].data.target === data.target)) { state.pop(); }
39
+
40
+ state.push({ time: time(evt), event: Event.Input, data });
41
+
42
+ clearTimeout(timeout);
43
+ timeout = setTimeout(process, Setting.InputLookAhead, Event.Input);
44
+ }
45
+ }
46
+
47
+ function process(event: Event): void {
48
+ schedule(encode.bind(this, event));
49
+ }
50
+
51
+ export function reset(): void {
52
+ state = [];
53
+ }
54
+
55
+ export function stop(): void {
56
+ clearTimeout(timeout);
57
+ reset();
58
58
  }