@amplitude/amp-semantic 0.2.0-codexsemantic-review-integration.0 → 0.2.0
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.
- package/README.md +8 -237
- package/lib/cjs/capture.d.ts +5 -5
- package/lib/cjs/capture.d.ts.map +1 -1
- package/lib/cjs/capture.js +48 -56
- package/lib/cjs/capture.js.map +1 -1
- package/lib/cjs/index.d.ts +4 -13
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +7 -32
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +33 -235
- package/lib/cjs/types.d.ts.map +1 -1
- package/lib/cjs/types.js.map +1 -1
- package/lib/esm/capture.d.ts +5 -5
- package/lib/esm/capture.d.ts.map +1 -1
- package/lib/esm/capture.js +47 -55
- package/lib/esm/capture.js.map +1 -1
- package/lib/esm/index.d.ts +4 -13
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +6 -22
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +33 -235
- package/lib/esm/types.d.ts.map +1 -1
- package/lib/esm/types.js.map +1 -1
- package/package.json +8 -10
- package/lib/cjs/helpers.d.ts +0 -9
- package/lib/cjs/helpers.d.ts.map +0 -1
- package/lib/cjs/helpers.js +0 -469
- package/lib/cjs/helpers.js.map +0 -1
- package/lib/cjs/recorders/analytics.d.ts +0 -7
- package/lib/cjs/recorders/analytics.d.ts.map +0 -1
- package/lib/cjs/recorders/analytics.js +0 -95
- package/lib/cjs/recorders/analytics.js.map +0 -1
- package/lib/cjs/recorders/feedback.d.ts +0 -4
- package/lib/cjs/recorders/feedback.d.ts.map +0 -1
- package/lib/cjs/recorders/feedback.js +0 -611
- package/lib/cjs/recorders/feedback.js.map +0 -1
- package/lib/cjs/recorders/interactions.d.ts +0 -4
- package/lib/cjs/recorders/interactions.d.ts.map +0 -1
- package/lib/cjs/recorders/interactions.js +0 -320
- package/lib/cjs/recorders/interactions.js.map +0 -1
- package/lib/cjs/recorders/keys.d.ts +0 -4
- package/lib/cjs/recorders/keys.d.ts.map +0 -1
- package/lib/cjs/recorders/keys.js +0 -64
- package/lib/cjs/recorders/keys.js.map +0 -1
- package/lib/cjs/recorders/lifecycle.d.ts +0 -4
- package/lib/cjs/recorders/lifecycle.d.ts.map +0 -1
- package/lib/cjs/recorders/lifecycle.js +0 -86
- package/lib/cjs/recorders/lifecycle.js.map +0 -1
- package/lib/cjs/recorders/navigation.d.ts +0 -4
- package/lib/cjs/recorders/navigation.d.ts.map +0 -1
- package/lib/cjs/recorders/navigation.js +0 -18
- package/lib/cjs/recorders/navigation.js.map +0 -1
- package/lib/cjs/recorders/resource-error.d.ts +0 -4
- package/lib/cjs/recorders/resource-error.d.ts.map +0 -1
- package/lib/cjs/recorders/resource-error.js +0 -159
- package/lib/cjs/recorders/resource-error.js.map +0 -1
- package/lib/esm/helpers.d.ts +0 -9
- package/lib/esm/helpers.d.ts.map +0 -1
- package/lib/esm/helpers.js +0 -461
- package/lib/esm/helpers.js.map +0 -1
- package/lib/esm/recorders/analytics.d.ts +0 -7
- package/lib/esm/recorders/analytics.d.ts.map +0 -1
- package/lib/esm/recorders/analytics.js +0 -92
- package/lib/esm/recorders/analytics.js.map +0 -1
- package/lib/esm/recorders/feedback.d.ts +0 -4
- package/lib/esm/recorders/feedback.d.ts.map +0 -1
- package/lib/esm/recorders/feedback.js +0 -608
- package/lib/esm/recorders/feedback.js.map +0 -1
- package/lib/esm/recorders/interactions.d.ts +0 -4
- package/lib/esm/recorders/interactions.d.ts.map +0 -1
- package/lib/esm/recorders/interactions.js +0 -317
- package/lib/esm/recorders/interactions.js.map +0 -1
- package/lib/esm/recorders/keys.d.ts +0 -4
- package/lib/esm/recorders/keys.d.ts.map +0 -1
- package/lib/esm/recorders/keys.js +0 -61
- package/lib/esm/recorders/keys.js.map +0 -1
- package/lib/esm/recorders/lifecycle.d.ts +0 -4
- package/lib/esm/recorders/lifecycle.d.ts.map +0 -1
- package/lib/esm/recorders/lifecycle.js +0 -83
- package/lib/esm/recorders/lifecycle.js.map +0 -1
- package/lib/esm/recorders/navigation.d.ts +0 -4
- package/lib/esm/recorders/navigation.d.ts.map +0 -1
- package/lib/esm/recorders/navigation.js +0 -15
- package/lib/esm/recorders/navigation.js.map +0 -1
- package/lib/esm/recorders/resource-error.d.ts +0 -4
- package/lib/esm/recorders/resource-error.d.ts.map +0 -1
- package/lib/esm/recorders/resource-error.js +0 -156
- package/lib/esm/recorders/resource-error.js.map +0 -1
- package/schema.json +0 -1110
package/lib/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"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"}
|
package/lib/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,gBAAgB,GAAG,CAAC,CAAC","sourcesContent":["export const SEMANTIC_VERSION = 1;\nexport interface SemanticIdentity {\n readonly tab_id: string;\n readonly document_id: string;\n}\n/** Internal event envelope, independent of any event family or replay transport. */\nexport interface SemanticEventEnvelope<Name extends string, Payload extends object> {\n name: Name;\n timestamp: number;\n payload: Payload & SemanticIdentity & { v: typeof SEMANTIC_VERSION };\n}\n\n/** Runtime consumers supply a map of event names to payload objects. */\nexport type SemanticPayloads = Record<string, object>;\nexport type SemanticFamily<P extends object = SemanticPayloads> = Extract<keyof P, string>;\nexport type SemanticEvent<P extends object = SemanticPayloads> = {\n [K in SemanticFamily<P>]: SemanticEventEnvelope<K, P[K] & object>;\n}[SemanticFamily<P>];\nexport interface SemanticCaptureConfig<P extends object = SemanticPayloads> {\n enabled: boolean;\n /** Additional sampling within recorded replay sessions. Defaults to 1. */\n sampleRate?: number;\n /** Registered families are enabled unless explicitly false. */\n families?: Partial<Record<SemanticFamily<P>, boolean>>;\n}\nexport interface HostSignals {\n /** An accepted full snapshot, forwarded after the recorder is ready. */\n snapshot: undefined;\n}\nexport type Cleanup = () => void;\n/** The host owns transport; the runtime has no rrweb dependency. */\nexport interface SemanticHost<P extends object = SemanticPayloads> {\n document: Document;\n window: Window;\n emit: (event: SemanticEvent<P>) => void;\n /** Called lazily for accepted events. Defaults to document-scoped memory only. */\n getIdentity?: () => SemanticIdentity;\n now?: () => number;\n random?: () => number;\n onError?: (error: unknown) => void;\n}\nexport interface RecorderContext<P extends object = SemanticPayloads> {\n /** Register resources immediately so failed setup can roll them back. */\n onCleanup: (cleanup: Cleanup) => void;\n host: SemanticHost<P>;\n now: () => number;\n /** Check before expensive payload work. A rejected candidate increments the dropped count. */\n canEmit: (family: SemanticFamily<P>) => boolean;\n emit: <K extends SemanticFamily<P>>(family: K, payload: P[K], timestamp?: number) => boolean;\n on: <K extends keyof HostSignals>(signal: K, callback: (value: HostSignals[K]) => void) => Cleanup;\n /** Peek at dropped counts; a recorder can acknowledge them after successful delivery. */\n dropped: () => Partial<Record<SemanticFamily<P>, number>>;\n clearDropped: () => void;\n}\n/** A factory owns its listeners/timers and returns complete teardown. */\nexport interface SemanticRecorder<P extends object = SemanticPayloads> {\n families: readonly SemanticFamily<P>[];\n setup: (context: RecorderContext<P>) => Cleanup;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/amp-semantic",
|
|
3
|
-
"version": "0.2.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Shared package foundation for Amplitude semantic event capture",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/cjs/index.js",
|
|
7
7
|
"module": "lib/esm/index.js",
|
|
8
8
|
"types": "lib/esm/index.d.ts",
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"files": [
|
|
11
|
-
"lib"
|
|
12
|
-
"schema.json"
|
|
11
|
+
"lib"
|
|
13
12
|
],
|
|
14
13
|
"publishConfig": {
|
|
15
14
|
"access": "public"
|
|
16
15
|
},
|
|
17
16
|
"dependencies": {
|
|
18
|
-
"@amplitude/session-replay-dom-privacy": "0.3.0-codexsemantic-review-integration.0",
|
|
19
17
|
"tslib": "^2.4.1"
|
|
20
18
|
},
|
|
21
19
|
"repository": {
|
|
@@ -24,15 +22,15 @@
|
|
|
24
22
|
},
|
|
25
23
|
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
26
24
|
"devDependencies": {
|
|
27
|
-
"
|
|
25
|
+
"rimraf": "^3.0.2"
|
|
28
26
|
},
|
|
29
27
|
"scripts": {
|
|
30
|
-
"
|
|
28
|
+
"clean": "rimraf lib",
|
|
29
|
+
"build": "pnpm clean && pnpm build:es5 && pnpm build:esm",
|
|
31
30
|
"build:es5": "tsc -p tsconfig.es5.json",
|
|
32
31
|
"build:esm": "tsc -p tsconfig.esm.json",
|
|
33
32
|
"test": "jest",
|
|
34
|
-
"lint": "eslint '{src,test
|
|
35
|
-
"typecheck": "tsc -p tsconfig.json"
|
|
36
|
-
"test:playwright": "playwright test --config playwright.config.ts"
|
|
33
|
+
"lint": "eslint '{src,test}/**/*.ts'",
|
|
34
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
37
35
|
}
|
|
38
36
|
}
|
package/lib/cjs/helpers.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SemanticHelpers, SemanticHost } from './types';
|
|
2
|
-
export declare function truncate(value: string, limit: number): string;
|
|
3
|
-
/** Only path-shaped information leaves the browser, including hash router paths. */
|
|
4
|
-
export declare function urlTemplate(value: string, base?: string): string;
|
|
5
|
-
export declare function roleOf(element: Element): string;
|
|
6
|
-
/** ARIA treats unknown nonempty tokens as true, alongside grammar and spelling. */
|
|
7
|
-
export declare function isAriaInvalid(element: Element): boolean;
|
|
8
|
-
export declare function createHelpers(host: SemanticHost): SemanticHelpers;
|
|
9
|
-
//# sourceMappingURL=helpers.d.ts.map
|
package/lib/cjs/helpers.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA+DpE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,SAA8B,GAAG,MAAM,CA2BrF;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAuD/C;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAGvD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,eAAe,CAyPjE"}
|
package/lib/cjs/helpers.js
DELETED
|
@@ -1,469 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createHelpers = exports.isAriaInvalid = exports.roleOf = exports.urlTemplate = exports.truncate = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var session_replay_dom_privacy_1 = require("@amplitude/session-replay-dom-privacy");
|
|
6
|
-
var INTERACTIVE = new Set([
|
|
7
|
-
'button',
|
|
8
|
-
'checkbox',
|
|
9
|
-
'combobox',
|
|
10
|
-
'link',
|
|
11
|
-
'listbox',
|
|
12
|
-
'menuitem',
|
|
13
|
-
'menuitemcheckbox',
|
|
14
|
-
'menuitemradio',
|
|
15
|
-
'option',
|
|
16
|
-
'radio',
|
|
17
|
-
'searchbox',
|
|
18
|
-
'slider',
|
|
19
|
-
'spinbutton',
|
|
20
|
-
'switch',
|
|
21
|
-
'tab',
|
|
22
|
-
'textbox',
|
|
23
|
-
'treeitem',
|
|
24
|
-
'gridcell',
|
|
25
|
-
]);
|
|
26
|
-
var CONTAINERS = new Set([
|
|
27
|
-
'banner',
|
|
28
|
-
'navigation',
|
|
29
|
-
'main',
|
|
30
|
-
'complementary',
|
|
31
|
-
'contentinfo',
|
|
32
|
-
'search',
|
|
33
|
-
'form',
|
|
34
|
-
'region',
|
|
35
|
-
'dialog',
|
|
36
|
-
'alertdialog',
|
|
37
|
-
'list',
|
|
38
|
-
'table',
|
|
39
|
-
'row',
|
|
40
|
-
'group',
|
|
41
|
-
]);
|
|
42
|
-
var CONTENT_NAMES = new Set([
|
|
43
|
-
'button',
|
|
44
|
-
'cell',
|
|
45
|
-
'checkbox',
|
|
46
|
-
'columnheader',
|
|
47
|
-
'gridcell',
|
|
48
|
-
'heading',
|
|
49
|
-
'link',
|
|
50
|
-
'menuitem',
|
|
51
|
-
'menuitemcheckbox',
|
|
52
|
-
'menuitemradio',
|
|
53
|
-
'option',
|
|
54
|
-
'radio',
|
|
55
|
-
'rowheader',
|
|
56
|
-
'switch',
|
|
57
|
-
'tab',
|
|
58
|
-
'tooltip',
|
|
59
|
-
'treeitem',
|
|
60
|
-
'alert',
|
|
61
|
-
'status',
|
|
62
|
-
'listitem',
|
|
63
|
-
]);
|
|
64
|
-
var INPUTS = new Set(['INPUT', 'SELECT', 'TEXTAREA']);
|
|
65
|
-
var ATTRIBUTES = ['type', 'name', 'href', 'target', 'aria-controls', 'aria-haspopup', 'data-testid'];
|
|
66
|
-
function truncate(value, limit) {
|
|
67
|
-
var normalized = value.replace(/\s+/g, ' ').trim();
|
|
68
|
-
return normalized.length > limit ? normalized.slice(0, limit - 1) + '…' : normalized;
|
|
69
|
-
}
|
|
70
|
-
exports.truncate = truncate;
|
|
71
|
-
/** Only path-shaped information leaves the browser, including hash router paths. */
|
|
72
|
-
function urlTemplate(value, base) {
|
|
73
|
-
if (base === void 0) { base = 'https://semantic.invalid/'; }
|
|
74
|
-
try {
|
|
75
|
-
var parsed = new URL(value, base);
|
|
76
|
-
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
|
|
77
|
-
return '/';
|
|
78
|
-
var route = /^#!?\//.test(parsed.hash) ? '#' + parsed.hash.slice(1).split(/[?#]/)[0] : '';
|
|
79
|
-
var template = function (path) {
|
|
80
|
-
return path
|
|
81
|
-
.split('/')
|
|
82
|
-
.map(function (part) {
|
|
83
|
-
var decoded;
|
|
84
|
-
try {
|
|
85
|
-
decoded = decodeURIComponent(part);
|
|
86
|
-
}
|
|
87
|
-
catch (_a) {
|
|
88
|
-
return ':id';
|
|
89
|
-
}
|
|
90
|
-
return /^\d+$/.test(decoded) ||
|
|
91
|
-
/^[\da-f]{8,}$/i.test(decoded) ||
|
|
92
|
-
/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i.test(decoded) ||
|
|
93
|
-
(decoded.length >= 16 && /^[a-z\d]+$/i.test(decoded) && /[a-z]/i.test(decoded) && /\d/.test(decoded))
|
|
94
|
-
? ':id'
|
|
95
|
-
: part;
|
|
96
|
-
})
|
|
97
|
-
.join('/');
|
|
98
|
-
};
|
|
99
|
-
return template(parsed.pathname) + template(route);
|
|
100
|
-
}
|
|
101
|
-
catch (_a) {
|
|
102
|
-
return '/';
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.urlTemplate = urlTemplate;
|
|
106
|
-
function roleOf(element) {
|
|
107
|
-
var _a, _b, _c, _d;
|
|
108
|
-
var explicit = (_a = element.getAttribute('role')) === null || _a === void 0 ? void 0 : _a.trim().split(/\s+/)[0].toLowerCase();
|
|
109
|
-
if (explicit)
|
|
110
|
-
return explicit === 'none' || explicit === 'presentation' ? 'generic' : explicit;
|
|
111
|
-
var tag = element.tagName.toLowerCase();
|
|
112
|
-
if (tag === 'a' || tag === 'area')
|
|
113
|
-
return element.hasAttribute('href') ? 'link' : 'generic';
|
|
114
|
-
if (tag === 'input') {
|
|
115
|
-
var type = ((_b = element.getAttribute('type')) !== null && _b !== void 0 ? _b : 'text').toLowerCase();
|
|
116
|
-
var roles_1 = {
|
|
117
|
-
button: 'button',
|
|
118
|
-
image: 'button',
|
|
119
|
-
reset: 'button',
|
|
120
|
-
submit: 'button',
|
|
121
|
-
file: 'button',
|
|
122
|
-
checkbox: 'checkbox',
|
|
123
|
-
radio: 'radio',
|
|
124
|
-
range: 'slider',
|
|
125
|
-
number: 'spinbutton',
|
|
126
|
-
search: 'searchbox',
|
|
127
|
-
hidden: 'generic',
|
|
128
|
-
};
|
|
129
|
-
return (_c = roles_1[type]) !== null && _c !== void 0 ? _c : (element.hasAttribute('list') ? 'combobox' : 'textbox');
|
|
130
|
-
}
|
|
131
|
-
if (tag === 'select')
|
|
132
|
-
return element.multiple || element.size > 1 ? 'listbox' : 'combobox';
|
|
133
|
-
var roles = {
|
|
134
|
-
button: 'button',
|
|
135
|
-
summary: 'button',
|
|
136
|
-
textarea: 'textbox',
|
|
137
|
-
nav: 'navigation',
|
|
138
|
-
main: 'main',
|
|
139
|
-
form: 'form',
|
|
140
|
-
header: 'banner',
|
|
141
|
-
footer: 'contentinfo',
|
|
142
|
-
aside: 'complementary',
|
|
143
|
-
dialog: 'dialog',
|
|
144
|
-
ul: 'list',
|
|
145
|
-
ol: 'list',
|
|
146
|
-
menu: 'list',
|
|
147
|
-
li: 'listitem',
|
|
148
|
-
table: 'table',
|
|
149
|
-
tr: 'row',
|
|
150
|
-
td: 'cell',
|
|
151
|
-
th: 'columnheader',
|
|
152
|
-
img: 'img',
|
|
153
|
-
option: 'option',
|
|
154
|
-
progress: 'progressbar',
|
|
155
|
-
output: 'status',
|
|
156
|
-
fieldset: 'group',
|
|
157
|
-
details: 'group',
|
|
158
|
-
optgroup: 'group',
|
|
159
|
-
};
|
|
160
|
-
if (/^h[1-6]$/.test(tag))
|
|
161
|
-
return 'heading';
|
|
162
|
-
if (tag === 'section')
|
|
163
|
-
return element.hasAttribute('aria-label') || element.hasAttribute('aria-labelledby') ? 'region' : 'generic';
|
|
164
|
-
return (_d = roles[tag]) !== null && _d !== void 0 ? _d : 'generic';
|
|
165
|
-
}
|
|
166
|
-
exports.roleOf = roleOf;
|
|
167
|
-
/** ARIA treats unknown nonempty tokens as true, alongside grammar and spelling. */
|
|
168
|
-
function isAriaInvalid(element) {
|
|
169
|
-
var _a;
|
|
170
|
-
var value = (_a = element.getAttribute('aria-invalid')) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase();
|
|
171
|
-
return !!value && value !== 'false';
|
|
172
|
-
}
|
|
173
|
-
exports.isAriaInvalid = isAriaInvalid;
|
|
174
|
-
function createHelpers(host) {
|
|
175
|
-
var blocked = function (element) {
|
|
176
|
-
try {
|
|
177
|
-
var selectors = host.getPrivacy().blockSelector;
|
|
178
|
-
return !!element.closest(tslib_1.__spreadArray(['.amp-block', '[data-amp-block]'], tslib_1.__read((typeof selectors === 'string' ? [selectors] : selectors !== null && selectors !== void 0 ? selectors : [])), false).join(','));
|
|
179
|
-
}
|
|
180
|
-
catch (_a) {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
var masked = function (element) {
|
|
185
|
-
try {
|
|
186
|
-
return (blocked(element) ||
|
|
187
|
-
(0, session_replay_dom_privacy_1.isMasked)(INPUTS.has(element.tagName) ? 'input' : 'text', host.getPrivacy(), element, host.getUrl()));
|
|
188
|
-
}
|
|
189
|
-
catch (_a) {
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
var editable = function (element) { return !!element.closest('[contenteditable]:not([contenteditable="false"])'); };
|
|
194
|
-
// Fail closed for composite text: checking only the container leaks masked descendants.
|
|
195
|
-
// Limit traversal work; an over-budget subtree yields null rather than partial private text.
|
|
196
|
-
var text = function (element, value, limit) {
|
|
197
|
-
var _a;
|
|
198
|
-
if (limit === void 0) { limit = 80; }
|
|
199
|
-
if (masked(element) || editable(element) || (value === undefined && INPUTS.has(element.tagName)))
|
|
200
|
-
return null;
|
|
201
|
-
if (value !== undefined)
|
|
202
|
-
return value === null ? null : truncate(value, limit);
|
|
203
|
-
var walker = host.document.createTreeWalker(element, 1 | 4);
|
|
204
|
-
var node;
|
|
205
|
-
var visited = 0;
|
|
206
|
-
var output = '';
|
|
207
|
-
while ((node = walker.nextNode())) {
|
|
208
|
-
if (++visited > 256)
|
|
209
|
-
return null;
|
|
210
|
-
if (node.nodeType === 1) {
|
|
211
|
-
var child = node;
|
|
212
|
-
if (masked(child) || editable(child) || INPUTS.has(child.tagName))
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
output += (_a = node.nodeValue) !== null && _a !== void 0 ? _a : '';
|
|
217
|
-
}
|
|
218
|
-
if (output.length > limit * 2)
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
return truncate(output, limit);
|
|
222
|
-
};
|
|
223
|
-
var name = function (element) {
|
|
224
|
-
var e_1, _a;
|
|
225
|
-
var _b, _c, _d;
|
|
226
|
-
var finish = function (value, source) { return ({
|
|
227
|
-
name: value || null,
|
|
228
|
-
source: value === null ? 'masked' : value ? source : 'unnamed',
|
|
229
|
-
}); };
|
|
230
|
-
if (blocked(element))
|
|
231
|
-
return finish(null, 'masked');
|
|
232
|
-
var labelledby = element.getAttribute('aria-labelledby');
|
|
233
|
-
if (labelledby) {
|
|
234
|
-
var parts = labelledby
|
|
235
|
-
.trim()
|
|
236
|
-
.split(/\s+/)
|
|
237
|
-
.slice(0, 20)
|
|
238
|
-
.map(function (id) { return host.document.getElementById(id); })
|
|
239
|
-
.filter(function (el) { return !!el; })
|
|
240
|
-
.map(function (el) { return text(el); });
|
|
241
|
-
if (parts.some(function (part) { return part === null; }))
|
|
242
|
-
return finish(null, 'masked');
|
|
243
|
-
var joined = truncate(parts.join(' '), 80);
|
|
244
|
-
if (joined)
|
|
245
|
-
return finish(joined, 'aria-labelledby');
|
|
246
|
-
}
|
|
247
|
-
var aria = element.getAttribute('aria-label');
|
|
248
|
-
if (aria === null || aria === void 0 ? void 0 : aria.trim())
|
|
249
|
-
return finish(text(element, aria), 'aria-label');
|
|
250
|
-
var labels = element.labels;
|
|
251
|
-
if (labels === null || labels === void 0 ? void 0 : labels.length) {
|
|
252
|
-
var label = labels[0];
|
|
253
|
-
// A wrapping label includes the input node: read its text nodes, never input values.
|
|
254
|
-
var labelText = '';
|
|
255
|
-
if (masked(label))
|
|
256
|
-
return finish(null, 'masked');
|
|
257
|
-
var unsafe = false;
|
|
258
|
-
var walker = host.document.createTreeWalker(label, 1 | 4);
|
|
259
|
-
var child = void 0;
|
|
260
|
-
var visited = 0;
|
|
261
|
-
while ((child = walker.nextNode())) {
|
|
262
|
-
if (++visited > 256) {
|
|
263
|
-
unsafe = true;
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
if (child.nodeType === 1 && child !== element && (masked(child) || editable(child))) {
|
|
267
|
-
unsafe = true;
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
if (child.nodeType === 3 &&
|
|
271
|
-
!((_b = child.parentElement) === null || _b === void 0 ? void 0 : _b.closest('input, select, textarea, [contenteditable]:not([contenteditable="false"])')))
|
|
272
|
-
labelText += (_c = child.nodeValue) !== null && _c !== void 0 ? _c : '';
|
|
273
|
-
}
|
|
274
|
-
return finish(unsafe ? null : text(label, labelText), label.htmlFor ? 'label-for' : 'label-wrap');
|
|
275
|
-
}
|
|
276
|
-
if (element.tagName === 'IMG' && element.hasAttribute('alt'))
|
|
277
|
-
return finish(text(element, element.getAttribute('alt')), 'alt');
|
|
278
|
-
// Static button captions are attributes, never a live input value.
|
|
279
|
-
if (element.tagName === 'INPUT' &&
|
|
280
|
-
/^(button|submit|reset)$/i.test((_d = element.getAttribute('type')) !== null && _d !== void 0 ? _d : '') &&
|
|
281
|
-
element.hasAttribute('value'))
|
|
282
|
-
return finish(text(element, element.getAttribute('value')), 'value');
|
|
283
|
-
if (CONTENT_NAMES.has(roleOf(element))) {
|
|
284
|
-
var content = text(element);
|
|
285
|
-
if (content === null || content)
|
|
286
|
-
return finish(content, 'text');
|
|
287
|
-
}
|
|
288
|
-
try {
|
|
289
|
-
for (var _e = tslib_1.__values(['title', 'placeholder']), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
290
|
-
var attribute = _f.value;
|
|
291
|
-
var value = element.getAttribute(attribute);
|
|
292
|
-
if (value)
|
|
293
|
-
return finish(text(element, value), attribute);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
297
|
-
finally {
|
|
298
|
-
try {
|
|
299
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
300
|
-
}
|
|
301
|
-
finally { if (e_1) throw e_1.error; }
|
|
302
|
-
}
|
|
303
|
-
return finish('', 'unnamed');
|
|
304
|
-
};
|
|
305
|
-
var id = function (element) {
|
|
306
|
-
if (blocked(element))
|
|
307
|
-
return null;
|
|
308
|
-
var value = host.getNodeId(element);
|
|
309
|
-
return value < 0 ? null : value;
|
|
310
|
-
};
|
|
311
|
-
var describe = function (element) {
|
|
312
|
-
var result = name(element);
|
|
313
|
-
return { id: id(element), role: roleOf(element), name: result.name, name_source: result.source };
|
|
314
|
-
};
|
|
315
|
-
var visible = function (element) {
|
|
316
|
-
var enhanced = element;
|
|
317
|
-
try {
|
|
318
|
-
return enhanced.checkVisibility
|
|
319
|
-
? enhanced.checkVisibility({ opacityProperty: true, visibilityProperty: true })
|
|
320
|
-
: element.getClientRects().length > 0 && host.window.getComputedStyle(element).visibility !== 'hidden';
|
|
321
|
-
}
|
|
322
|
-
catch (_a) {
|
|
323
|
-
return false;
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
// Cache only the DOM candidate, never captured text or privacy decisions. Short-lived
|
|
327
|
-
// discovery avoids whole-document queries on rapid clicks without adding an observer.
|
|
328
|
-
var headingCandidate = null;
|
|
329
|
-
var headingUntil = 0;
|
|
330
|
-
var headingUrl = '';
|
|
331
|
-
var heading = function () {
|
|
332
|
-
var now = host.window.performance.now();
|
|
333
|
-
var url = host.getUrl();
|
|
334
|
-
if (now < headingUntil &&
|
|
335
|
-
url === headingUrl &&
|
|
336
|
-
(!headingCandidate || (headingCandidate.isConnected && visible(headingCandidate)))) {
|
|
337
|
-
return headingCandidate ? text(headingCandidate) : null;
|
|
338
|
-
}
|
|
339
|
-
headingCandidate = null;
|
|
340
|
-
headingUntil = now + 250;
|
|
341
|
-
headingUrl = url;
|
|
342
|
-
var root = host.document.body;
|
|
343
|
-
if (!root)
|
|
344
|
-
return null;
|
|
345
|
-
var walker = host.document.createTreeWalker(root, 1);
|
|
346
|
-
var node = walker.nextNode();
|
|
347
|
-
var visited = 0;
|
|
348
|
-
while (node && visited++ < 2000 && host.window.performance.now() - now < 2) {
|
|
349
|
-
var isH1 = node.tagName === 'H1';
|
|
350
|
-
if (isH1 || node.matches('[role="heading"][aria-level="1"]')) {
|
|
351
|
-
if (visible(node)) {
|
|
352
|
-
if (node.closest('main,[role="main"]')) {
|
|
353
|
-
headingCandidate = node;
|
|
354
|
-
break;
|
|
355
|
-
}
|
|
356
|
-
if (isH1 && !headingCandidate)
|
|
357
|
-
headingCandidate = node;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
node = walker.nextNode();
|
|
361
|
-
}
|
|
362
|
-
return headingCandidate ? text(headingCandidate) : null;
|
|
363
|
-
};
|
|
364
|
-
return {
|
|
365
|
-
id: id,
|
|
366
|
-
blocked: blocked,
|
|
367
|
-
masked: masked,
|
|
368
|
-
text: text,
|
|
369
|
-
name: name,
|
|
370
|
-
describe: describe,
|
|
371
|
-
visible: visible,
|
|
372
|
-
role: roleOf,
|
|
373
|
-
url: function (value) {
|
|
374
|
-
if (value === void 0) { value = host.getUrl(); }
|
|
375
|
-
return urlTemplate(value, host.getUrl());
|
|
376
|
-
},
|
|
377
|
-
actionable: function (element) {
|
|
378
|
-
var current = element;
|
|
379
|
-
var fallback = element;
|
|
380
|
-
for (var depth = 0; current && depth < 12; depth++, current = current.parentElement) {
|
|
381
|
-
var role = roleOf(current);
|
|
382
|
-
if (INTERACTIVE.has(role))
|
|
383
|
-
return current;
|
|
384
|
-
if (fallback === element && role !== 'generic')
|
|
385
|
-
fallback = current;
|
|
386
|
-
}
|
|
387
|
-
return fallback;
|
|
388
|
-
},
|
|
389
|
-
container: function (element) {
|
|
390
|
-
var current = element.parentElement;
|
|
391
|
-
for (var depth = 0; current && depth < 20; depth++, current = current.parentElement) {
|
|
392
|
-
if (CONTAINERS.has(roleOf(current)) || current.hasAttribute('aria-label')) {
|
|
393
|
-
var result = describe(current);
|
|
394
|
-
return { id: result.id, role: result.role, name: result.name };
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
return null;
|
|
398
|
-
},
|
|
399
|
-
states: function (element) {
|
|
400
|
-
var e_2, _a;
|
|
401
|
-
var states = [];
|
|
402
|
-
var native = element;
|
|
403
|
-
var mixed = (element.tagName === 'INPUT' && native.type === 'checkbox' && native.indeterminate) ||
|
|
404
|
-
element.getAttribute('aria-checked') === 'mixed' ||
|
|
405
|
-
element.getAttribute('aria-pressed') === 'mixed';
|
|
406
|
-
try {
|
|
407
|
-
for (var _b = tslib_1.__values(Object.entries({
|
|
408
|
-
// :disabled includes fieldset inheritance and the first-legend exception.
|
|
409
|
-
disabled: element.matches(':disabled') || element.getAttribute('aria-disabled') === 'true',
|
|
410
|
-
required: native.required || element.getAttribute('aria-required') === 'true',
|
|
411
|
-
invalid: isAriaInvalid(element) || (native.willValidate && !native.validity.valid),
|
|
412
|
-
checked: !mixed && (native.checked || element.getAttribute('aria-checked') === 'true'),
|
|
413
|
-
mixed: mixed,
|
|
414
|
-
busy: element.getAttribute('aria-busy') === 'true',
|
|
415
|
-
open: (element.tagName === 'DETAILS' || element.tagName === 'DIALOG') && element.hasAttribute('open'),
|
|
416
|
-
expanded: element.getAttribute('aria-expanded') === 'true',
|
|
417
|
-
collapsed: element.getAttribute('aria-expanded') === 'false',
|
|
418
|
-
selected: native.selected || element.getAttribute('aria-selected') === 'true',
|
|
419
|
-
current: element.hasAttribute('aria-current') && element.getAttribute('aria-current') !== 'false',
|
|
420
|
-
pressed: element.getAttribute('aria-pressed') === 'true',
|
|
421
|
-
readonly: native.readOnly || element.getAttribute('aria-readonly') === 'true',
|
|
422
|
-
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
423
|
-
var _d = tslib_1.__read(_c.value, 2), state = _d[0], yes = _d[1];
|
|
424
|
-
if (yes)
|
|
425
|
-
states.push(state);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
429
|
-
finally {
|
|
430
|
-
try {
|
|
431
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
432
|
-
}
|
|
433
|
-
finally { if (e_2) throw e_2.error; }
|
|
434
|
-
}
|
|
435
|
-
return states;
|
|
436
|
-
},
|
|
437
|
-
heading: heading,
|
|
438
|
-
invalidateHeading: function () {
|
|
439
|
-
headingUntil = 0;
|
|
440
|
-
headingCandidate = null;
|
|
441
|
-
},
|
|
442
|
-
attributes: function (element) {
|
|
443
|
-
var e_3, _a;
|
|
444
|
-
var _b;
|
|
445
|
-
var result = {};
|
|
446
|
-
if (blocked(element))
|
|
447
|
-
return result;
|
|
448
|
-
try {
|
|
449
|
-
for (var ATTRIBUTES_1 = tslib_1.__values(ATTRIBUTES), ATTRIBUTES_1_1 = ATTRIBUTES_1.next(); !ATTRIBUTES_1_1.done; ATTRIBUTES_1_1 = ATTRIBUTES_1.next()) {
|
|
450
|
-
var key = ATTRIBUTES_1_1.value;
|
|
451
|
-
var value = element.getAttribute(key);
|
|
452
|
-
if (value === null || (((_b = host.getPrivacy().maskAttributes) === null || _b === void 0 ? void 0 : _b.includes(key)) && masked(element)))
|
|
453
|
-
continue;
|
|
454
|
-
result[key] = truncate(key === 'href' ? urlTemplate(value, host.getUrl()) : value, 60);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
458
|
-
finally {
|
|
459
|
-
try {
|
|
460
|
-
if (ATTRIBUTES_1_1 && !ATTRIBUTES_1_1.done && (_a = ATTRIBUTES_1.return)) _a.call(ATTRIBUTES_1);
|
|
461
|
-
}
|
|
462
|
-
finally { if (e_3) throw e_3.error; }
|
|
463
|
-
}
|
|
464
|
-
return result;
|
|
465
|
-
},
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
exports.createHelpers = createHelpers;
|
|
469
|
-
//# sourceMappingURL=helpers.js.map
|