clarity-js 0.8.3 → 0.8.4-beta

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