@harnessed-ts/resolve 0.0.0-stage → 0.7.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +106 -2
  4. package/dist/box.d.ts +27 -0
  5. package/dist/box.d.ts.map +1 -0
  6. package/dist/chunk-BYG4HMLR.js +61 -0
  7. package/dist/chunk-BYG4HMLR.js.map +1 -0
  8. package/dist/files.d.ts +7 -0
  9. package/dist/files.d.ts.map +1 -0
  10. package/dist/global-name.d.ts +7 -0
  11. package/dist/global-name.d.ts.map +1 -0
  12. package/dist/index.cjs +315 -0
  13. package/dist/index.cjs.map +1 -0
  14. package/dist/index.d.ts +10 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +296 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/inject.cjs +68 -0
  19. package/dist/inject.cjs.map +1 -0
  20. package/dist/inject.d.ts +27 -0
  21. package/dist/inject.d.ts.map +1 -0
  22. package/dist/inject.global.d.ts +2 -0
  23. package/dist/inject.global.d.ts.map +1 -0
  24. package/dist/inject.global.js +70 -0
  25. package/dist/inject.js +3 -0
  26. package/dist/inject.js.map +1 -0
  27. package/dist/page-api.d.ts +57 -0
  28. package/dist/page-api.d.ts.map +1 -0
  29. package/dist/resolve.d.ts +38 -0
  30. package/dist/resolve.d.ts.map +1 -0
  31. package/dist/visible.d.ts +18 -0
  32. package/dist/visible.d.ts.map +1 -0
  33. package/dist/webdriver-page-script.d.ts +48 -0
  34. package/dist/webdriver-page-script.d.ts.map +1 -0
  35. package/dist/webdriver.cjs +272 -0
  36. package/dist/webdriver.cjs.map +1 -0
  37. package/dist/webdriver.d.ts +96 -0
  38. package/dist/webdriver.d.ts.map +1 -0
  39. package/dist/webdriver.js +226 -0
  40. package/dist/webdriver.js.map +1 -0
  41. package/dist/wire.d.ts +16 -0
  42. package/dist/wire.d.ts.map +1 -0
  43. package/package.json +79 -3
package/dist/index.cjs ADDED
@@ -0,0 +1,315 @@
1
+ 'use strict';
2
+
3
+ var core = require('@harnessed-ts/core');
4
+ var dom = require('@testing-library/dom');
5
+
6
+ // src/resolve.ts
7
+ var syncTestIdAttribute = core.testIdSync(
8
+ (testIdAttribute) => dom.configure({ testIdAttribute })
9
+ );
10
+ function queryAllByPresence(container, css) {
11
+ return [...container.querySelectorAll(css)];
12
+ }
13
+ var [, , , findAllByPresence] = dom.buildQueries(
14
+ queryAllByPresence,
15
+ (_container, css) => `Found multiple elements by: ${css}`,
16
+ (_container, css) => `Unable to find an element by: ${css}`
17
+ );
18
+ function presenceOf(selector) {
19
+ return core.testIdPresenceSelector(core.getConfig().testIdAttribute, selector.testId);
20
+ }
21
+ function queryAll(root, selector) {
22
+ syncTestIdAttribute();
23
+ const scoped = dom.within(root);
24
+ switch (selector.type) {
25
+ case "role":
26
+ return scoped.queryAllByRole(selector.role, selector.options);
27
+ case "label":
28
+ return scoped.queryAllByLabelText(selector.text);
29
+ case "testId": {
30
+ const css = presenceOf(selector);
31
+ return css === void 0 ? scoped.queryAllByTestId(selector.testId) : queryAllByPresence(root, css);
32
+ }
33
+ case "text":
34
+ return scoped.queryAllByText(selector.text);
35
+ case "placeholder":
36
+ return scoped.queryAllByPlaceholderText(selector.text);
37
+ }
38
+ }
39
+ async function findOne(root, scope, selector, timeout) {
40
+ syncTestIdAttribute();
41
+ const immediate = queryAll(root, selector);
42
+ const resolved = immediate.length > 0 ? immediate : await findAll(root, selector, timeout);
43
+ return pick(resolved, scope, selector);
44
+ }
45
+ function pick(resolved, scope, selector) {
46
+ if (selector.nth !== void 0) {
47
+ const found = resolved[selector.nth];
48
+ if (found === void 0) {
49
+ throw core.indexOutOfRange(selector.nth, resolved.length, scope, selector);
50
+ }
51
+ return found;
52
+ }
53
+ if (resolved.length > 1) throw core.strictViolation(resolved.length, scope, selector);
54
+ return resolved[0];
55
+ }
56
+ async function findAll(root, selector, timeout) {
57
+ syncTestIdAttribute();
58
+ const scoped = dom.within(root);
59
+ const options = { timeout: core.timeoutFor(timeout) };
60
+ switch (selector.type) {
61
+ case "role":
62
+ return scoped.findAllByRole(selector.role, selector.options, options);
63
+ case "label":
64
+ return scoped.findAllByLabelText(selector.text, void 0, options);
65
+ case "testId": {
66
+ const css = presenceOf(selector);
67
+ return css === void 0 ? scoped.findAllByTestId(selector.testId, void 0, options) : findAllByPresence(root, css, void 0, options);
68
+ }
69
+ case "text":
70
+ return scoped.findAllByText(selector.text, void 0, options);
71
+ case "placeholder":
72
+ return scoped.findAllByPlaceholderText(selector.text, void 0, options);
73
+ }
74
+ }
75
+ async function resolveScope(container, scope, timeout) {
76
+ let current = container;
77
+ for (const [index, step] of scope.entries()) {
78
+ const path = scope.slice(0, index);
79
+ const found = await findOne(current, path, step, timeout);
80
+ current = step.frame === true ? frameBody(found, path, step) : found;
81
+ }
82
+ return current;
83
+ }
84
+ var FrameEntryError = class extends Error {
85
+ name = "FrameEntryError";
86
+ };
87
+ function frameBody(element, scope, selector) {
88
+ if (element.localName !== "iframe") {
89
+ throw new FrameEntryError(
90
+ `harnessed: ${core.describeScope(scope, selector)} is marked as a frame but is a <${element.localName}>, not an <iframe>.`
91
+ );
92
+ }
93
+ const body = element.contentDocument?.body;
94
+ if (body == null) {
95
+ throw new FrameEntryError(
96
+ `harnessed: ${core.describeScope(scope, selector)} has no reachable document: it is cross-origin, or its document has no body. The dom driver enters same-origin frames only; drive a cross-origin one with a browser driver.`
97
+ );
98
+ }
99
+ return body;
100
+ }
101
+ async function resolveOne(container, scope, selector, timeout) {
102
+ const root = await resolveScope(container, scope, timeout);
103
+ return findOne(root, scope, selector, timeout);
104
+ }
105
+ async function countAll(container, scope, selector, timeout) {
106
+ let root;
107
+ try {
108
+ root = await resolveScope(container, scope, timeout);
109
+ } catch (error) {
110
+ if (error instanceof FrameEntryError) throw error;
111
+ return 0;
112
+ }
113
+ const matches = queryAll(root, selector);
114
+ if (selector.nth === void 0) return matches.length;
115
+ return matches[selector.nth] === void 0 ? 0 : 1;
116
+ }
117
+ function resolveScopeNow(container, scope) {
118
+ let current = container;
119
+ for (const [index, step] of scope.entries()) {
120
+ const path = scope.slice(0, index);
121
+ const matches = queryAll(current, step);
122
+ if (matches.length === 0) return null;
123
+ const found = pick(matches, path, step);
124
+ current = step.frame === true ? frameBody(found, path, step) : found;
125
+ }
126
+ return current;
127
+ }
128
+ function resolveOneNow(container, scope, selector) {
129
+ const root = resolveScopeNow(container, scope);
130
+ if (root === null) return null;
131
+ const matches = queryAll(root, selector);
132
+ if (matches.length === 0) return null;
133
+ return pick(matches, scope, selector);
134
+ }
135
+ function resolveAllNow(container, scope, selector) {
136
+ let root;
137
+ try {
138
+ root = resolveScopeNow(container, scope);
139
+ } catch (error) {
140
+ if (error instanceof FrameEntryError) throw error;
141
+ return [];
142
+ }
143
+ if (root === null) return [];
144
+ const matches = queryAll(root, selector);
145
+ if (selector.nth === void 0) return matches;
146
+ const found = matches[selector.nth];
147
+ return found === void 0 ? [] : [found];
148
+ }
149
+ async function resolveAll(container, scope, selector, timeout) {
150
+ return queryAll(await resolveScope(container, scope, timeout), selector);
151
+ }
152
+
153
+ // src/visible.ts
154
+ function isVisibleInLayout(element, home) {
155
+ if (!isVisibleInOwnDocument(element)) return false;
156
+ const document = element.ownerDocument;
157
+ if (document === home) return true;
158
+ const frame = document.defaultView?.frameElement;
159
+ return frame == null || isVisibleInLayout(frame, home);
160
+ }
161
+ function isVisibleInOwnDocument(element) {
162
+ const view = element.ownerDocument.defaultView;
163
+ if (view == null) return false;
164
+ const style = view.getComputedStyle(element);
165
+ if (style.display === "contents") {
166
+ return [...element.children].some((child) => isVisibleInOwnDocument(child));
167
+ }
168
+ if (style.visibility !== "visible") return false;
169
+ const box = element.getBoundingClientRect();
170
+ return box.width > 0 && box.height > 0;
171
+ }
172
+
173
+ // src/box.ts
174
+ function boxInOwnDocument(element) {
175
+ if (element.getClientRects().length === 0) return null;
176
+ const { x, y, width, height } = element.getBoundingClientRect();
177
+ return { x, y, width, height };
178
+ }
179
+ function frameOrigin(iframe) {
180
+ const { x, y } = iframe.getBoundingClientRect();
181
+ const style = iframe.ownerDocument.defaultView?.getComputedStyle(iframe);
182
+ const px = (value) => Number.parseFloat(value ?? "") || 0;
183
+ return {
184
+ x: x + px(style?.borderLeftWidth) + px(style?.paddingLeft),
185
+ y: y + px(style?.borderTopWidth) + px(style?.paddingTop)
186
+ };
187
+ }
188
+ function boundingBoxOf(element, home) {
189
+ const box = boxInOwnDocument(element);
190
+ if (box === null) return { x: 0, y: 0, width: 0, height: 0 };
191
+ let document = element.ownerDocument;
192
+ while (document !== home) {
193
+ const frame = document.defaultView?.frameElement;
194
+ if (frame == null) break;
195
+ const origin = frameOrigin(frame);
196
+ box.x += origin.x;
197
+ box.y += origin.y;
198
+ document = frame.ownerDocument;
199
+ }
200
+ return box;
201
+ }
202
+
203
+ // src/files.ts
204
+ function fileInputOf(element) {
205
+ const target = element.localName === "label" ? element.control : element;
206
+ if (target === null) return "<label> with no control";
207
+ if (target.localName !== "input") return `<${target.localName}>`;
208
+ const input = target;
209
+ return input.type === "file" ? input : `<input type="${input.type}">`;
210
+ }
211
+
212
+ // src/global-name.ts
213
+ var PAGE_API_GLOBAL = "__harnessedResolve";
214
+
215
+ // src/wire.ts
216
+ function isRegExp(value) {
217
+ return Object.prototype.toString.call(value) === "[object RegExp]";
218
+ }
219
+ function encodeValue(value) {
220
+ if (isRegExp(value)) return { $regexp: value.source, flags: value.flags };
221
+ if (Array.isArray(value)) return value.map(encodeValue);
222
+ if (typeof value === "object" && value !== null) {
223
+ return Object.fromEntries(
224
+ Object.entries(value).map(([key, inner]) => [key, encodeValue(inner)])
225
+ );
226
+ }
227
+ return value;
228
+ }
229
+ function isWireRegExp(value) {
230
+ return typeof value === "object" && value !== null && typeof value.$regexp === "string" && typeof value.flags === "string";
231
+ }
232
+ function decodeValue(value) {
233
+ if (isRegExp(value)) return new RegExp(value.source, value.flags);
234
+ if (isWireRegExp(value)) return new RegExp(value.$regexp, value.flags);
235
+ if (Array.isArray(value)) return value.map(decodeValue);
236
+ if (typeof value === "object" && value !== null) {
237
+ return Object.fromEntries(
238
+ Object.entries(value).map(([key, inner]) => [key, decodeValue(inner)])
239
+ );
240
+ }
241
+ return value;
242
+ }
243
+ function encodeSelector(selector) {
244
+ return encodeValue(selector);
245
+ }
246
+ function decodeSelector(selector) {
247
+ return decodeValue(selector);
248
+ }
249
+
250
+ // src/page-api.ts
251
+ function createPageApi(document) {
252
+ const start = (root) => root ?? document.body;
253
+ const apply = (options) => core.configure({ testIdAttribute: options.testIdAttribute });
254
+ const decode = (scope, selector) => [
255
+ scope.map(decodeSelector),
256
+ decodeSelector(selector)
257
+ ];
258
+ return {
259
+ async count(root, scope, selector, options) {
260
+ apply(options);
261
+ const [steps, target] = decode(scope, selector);
262
+ return countAll(start(root), steps, target, options.timeout);
263
+ },
264
+ async one(root, scope, selector, options) {
265
+ apply(options);
266
+ const [steps, target] = decode(scope, selector);
267
+ return resolveOne(start(root), steps, target, options.timeout);
268
+ },
269
+ async all(root, scope, selector, options) {
270
+ apply(options);
271
+ const [steps, target] = decode(scope, selector);
272
+ return resolveAll(start(root), steps, target, options.timeout);
273
+ },
274
+ oneNow(root, scope, selector, options) {
275
+ apply(options);
276
+ const [steps, target] = decode(scope, selector);
277
+ return resolveOneNow(start(root), steps, target);
278
+ },
279
+ allNow(root, scope, selector, options) {
280
+ apply(options);
281
+ const [steps, target] = decode(scope, selector);
282
+ return resolveAllNow(start(root), steps, target);
283
+ },
284
+ visible(element) {
285
+ return isVisibleInLayout(element, element.ownerDocument);
286
+ },
287
+ box: boxInOwnDocument,
288
+ origin: frameOrigin,
289
+ fileTarget(element) {
290
+ const input = fileInputOf(element);
291
+ return typeof input === "string" ? input : { multiple: input.multiple };
292
+ }
293
+ };
294
+ }
295
+
296
+ exports.FrameEntryError = FrameEntryError;
297
+ exports.PAGE_API_GLOBAL = PAGE_API_GLOBAL;
298
+ exports.boundingBoxOf = boundingBoxOf;
299
+ exports.boxInOwnDocument = boxInOwnDocument;
300
+ exports.countAll = countAll;
301
+ exports.createPageApi = createPageApi;
302
+ exports.decodeSelector = decodeSelector;
303
+ exports.encodeSelector = encodeSelector;
304
+ exports.fileInputOf = fileInputOf;
305
+ exports.frameOrigin = frameOrigin;
306
+ exports.isVisibleInLayout = isVisibleInLayout;
307
+ exports.queryAll = queryAll;
308
+ exports.resolveAll = resolveAll;
309
+ exports.resolveAllNow = resolveAllNow;
310
+ exports.resolveOne = resolveOne;
311
+ exports.resolveOneNow = resolveOneNow;
312
+ exports.resolveScope = resolveScope;
313
+ exports.resolveScopeNow = resolveScopeNow;
314
+ //# sourceMappingURL=index.cjs.map
315
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/resolve.ts","../src/visible.ts","../src/box.ts","../src/files.ts","../src/global-name.ts","../src/wire.ts","../src/page-api.ts"],"names":["testIdSync","configureTestingLibrary","buildQueries","testIdPresenceSelector","getConfig","within","indexOutOfRange","strictViolation","timeoutFor","describeScope","configure"],"mappings":";;;;;;AAiBA,IAAM,mBAAA,GAAsBA,eAAA;AAAA,EAAW,CAAA,eAAA,KACrCC,aAAA,CAAwB,EAAE,eAAA,EAAiB;AAC7C,CAAA;AAGA,SAAS,kBAAA,CAAmB,WAAwB,GAAA,EAA4B;AAC9E,EAAA,OAAO,CAAC,GAAG,SAAA,CAAU,gBAAA,CAA8B,GAAG,CAAC,CAAA;AACzD;AAIA,IAAM,OAAO,iBAAiB,CAAA,GAAIC,gBAAA;AAAA,EAChC,kBAAA;AAAA,EACA,CAAC,UAAA,EAAY,GAAA,KAAgB,CAAA,4BAAA,EAA+B,GAAG,CAAA,CAAA;AAAA,EAC/D,CAAC,UAAA,EAAY,GAAA,KAAgB,CAAA,8BAAA,EAAiC,GAAG,CAAA;AACnE,CAAA;AAGA,SAAS,WAAW,QAAA,EAA6D;AAC/E,EAAA,OAAOC,2BAA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AAA,CAAO,OAAO,QAAQ,CAAA;AAC9C,MAAA,OAAO,aAAA,CAAc,KAAA,CAAM,IAAI,CAAA,EAAG,OAAO,MAAM,CAAA;AAAA,IACjD,CAAA;AAAA,IACA,MAAA,CAAO,IAAA,EAAM,KAAA,EAAO,QAAA,EAAU,OAAA,EAAS;AACrC,MAAA,KAAA,CAAM,OAAO,CAAA;AACb,MAAA,MAAM,CAAC,KAAA,EAAO,MAAM,CAAA,GAAI,MAAA,CAAO,OAAO,QAAQ,CAAA;AAC9C,MAAA,OAAO,aAAA,CAAc,KAAA,CAAM,IAAI,CAAA,EAAG,OAAO,MAAM,CAAA;AAAA,IACjD,CAAA;AAAA,IACA,QAAQ,OAAA,EAAS;AACf,MAAA,OAAO,iBAAA,CAAkB,OAAA,EAAS,OAAA,CAAQ,aAAa,CAAA;AAAA,IACzD,CAAA;AAAA,IACA,GAAA,EAAK,gBAAA;AAAA,IACL,MAAA,EAAQ,WAAA;AAAA,IACR,WAAW,OAAA,EAAS;AAClB,MAAA,MAAM,KAAA,GAAQ,YAAY,OAAO,CAAA;AACjC,MAAA,OAAO,OAAO,KAAA,KAAU,QAAA,GAAW,QAAQ,EAAE,QAAA,EAAU,MAAM,QAAA,EAAS;AAAA,IACxE;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import {\n describeScope,\n getConfig,\n indexOutOfRange,\n strictViolation,\n testIdPresenceSelector,\n testIdSync,\n timeoutFor,\n} from '@harnessed-ts/core'\nimport type { Selector } from '@harnessed-ts/core'\nimport { buildQueries, configure as configureTestingLibrary, within } from '@testing-library/dom'\nimport type { ByRoleMatcher } from '@testing-library/dom'\n\n/** `Selector` keeps `role` a plain string so it stays driver-agnostic; each driver\n * casts it to its own role union at the boundary. */\ntype RoleName = ByRoleMatcher\n\nconst syncTestIdAttribute = testIdSync(testIdAttribute =>\n configureTestingLibrary({ testIdAttribute }),\n)\n\n/** Descendants carrying a presence-style test id: `[data-test-x]`, any value. */\nfunction queryAllByPresence(container: HTMLElement, css: string): HTMLElement[] {\n return [...container.querySelectorAll<HTMLElement>(css)]\n}\n\n// Built the way Testing Library builds its own queries, so a presence test id\n// waits, and reports \"Unable to find …\" when it gives up, exactly as `*ByTestId` does.\nconst [, , , findAllByPresence] = buildQueries(\n queryAllByPresence,\n (_container, css: string) => `Found multiple elements by: ${css}`,\n (_container, css: string) => `Unable to find an element by: ${css}`,\n)\n\n/** The presence selector for a test id under a `data-test-*` config, if that is the mode. */\nfunction presenceOf(selector: Selector & { type: 'testId' }): string | undefined {\n return testIdPresenceSelector(getConfig().testIdAttribute, selector.testId)\n}\n\n/** Every match for one selector, without waiting. Zero is an answer. */\nexport function queryAll(root: HTMLElement, selector: Selector): HTMLElement[] {\n syncTestIdAttribute()\n const scoped = within(root)\n switch (selector.type) {\n case 'role':\n return scoped.queryAllByRole(selector.role as RoleName, selector.options)\n case 'label':\n return scoped.queryAllByLabelText(selector.text)\n case 'testId': {\n const css = presenceOf(selector)\n return css === undefined\n ? scoped.queryAllByTestId(selector.testId)\n : queryAllByPresence(root, css)\n }\n case 'text':\n return scoped.queryAllByText(selector.text)\n case 'placeholder':\n return scoped.queryAllByPlaceholderText(selector.text)\n }\n}\n\n/**\n * One match, waiting for it to appear. Strict: several matches is an error.\n *\n * The non-waiting query runs first. Testing Library's `findBy*` is\n * `waitFor(getBy*)`, so a \"found multiple elements\" error is retried for the full\n * timeout before surfacing — but more than one match never becomes one by\n * waiting, and Playwright rejects at once. Checking up front keeps the two\n * drivers in step and turns a timeout into an immediate, readable failure.\n *\n * The check is applied to the waited result too. Otherwise the guarantee would\n * hold only for nodes that happened to be on screen already, and a target that\n * renders late as two nodes would still sit out the whole timeout.\n */\nasync function findOne(\n root: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n timeout?: number,\n): Promise<HTMLElement> {\n syncTestIdAttribute()\n\n const immediate = queryAll(root, selector)\n const resolved = immediate.length > 0 ? immediate : await findAll(root, selector, timeout)\n return pick(resolved, scope, selector)\n}\n\n/** The one node a strict operation takes from a set of matches. */\nfunction pick(\n resolved: readonly HTMLElement[],\n scope: readonly Selector[],\n selector: Selector,\n): HTMLElement {\n if (selector.nth !== undefined) {\n const found = resolved[selector.nth]\n if (found === undefined) {\n throw indexOutOfRange(selector.nth, resolved.length, scope, selector)\n }\n return found\n }\n\n if (resolved.length > 1) throw strictViolation(resolved.length, scope, selector)\n return resolved[0]!\n}\n\nasync function findAll(\n root: HTMLElement,\n selector: Selector,\n timeout?: number,\n): Promise<HTMLElement[]> {\n syncTestIdAttribute()\n const scoped = within(root)\n const options = { timeout: timeoutFor(timeout) }\n switch (selector.type) {\n case 'role':\n return scoped.findAllByRole(selector.role as RoleName, selector.options, options)\n case 'label':\n return scoped.findAllByLabelText(selector.text, undefined, options)\n case 'testId': {\n const css = presenceOf(selector)\n return css === undefined\n ? scoped.findAllByTestId(selector.testId, undefined, options)\n : findAllByPresence(root, css, undefined, options)\n }\n case 'text':\n return scoped.findAllByText(selector.text, undefined, options)\n case 'placeholder':\n return scoped.findAllByPlaceholderText(selector.text, undefined, options)\n }\n}\n\n/**\n * Walks the scope chain down to the element the final selector is queried within.\n * Waiting is correct here: a container that has not rendered yet is not the same\n * thing as a target that is absent.\n */\nexport async function resolveScope(\n container: HTMLElement,\n scope: readonly Selector[],\n timeout?: number,\n): Promise<HTMLElement> {\n let current = container\n for (const [index, step] of scope.entries()) {\n // Each link is reported with the path that reached it, so an ambiguous\n // container names the container rather than the leaf you asked for.\n const path = scope.slice(0, index)\n const found = await findOne(current, path, step, timeout)\n current = step.frame === true ? frameBody(found, path, step) : found\n }\n return current\n}\n\n/** A frame link that cannot be entered — a wiring mistake, never \"not rendered yet\". */\nexport class FrameEntryError extends Error {\n override name = 'FrameEntryError'\n}\n\n/**\n * The body a frame link's children are queried within. Only a same-origin frame\n * exposes one — a cross-origin document is unreachable from script by design, and\n * no amount of waiting changes that, so this refuses at once.\n */\nfunction frameBody(\n element: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n): HTMLElement {\n // localName, not instanceof: a frame nested in a frame belongs to another realm.\n if (element.localName !== 'iframe') {\n throw new FrameEntryError(\n `harnessed: ${describeScope(scope, selector)} is marked as a frame but is a <${element.localName}>, not an <iframe>.`,\n )\n }\n const body = (element as HTMLIFrameElement).contentDocument?.body\n if (body == null) {\n throw new FrameEntryError(\n `harnessed: ${describeScope(scope, selector)} has no reachable document: it is ` +\n `cross-origin, or its document has no body. The dom driver enters same-origin ` +\n `frames only; drive a cross-origin one with a browser driver.`,\n )\n }\n return body\n}\n\n/** The single node a strict operation acts on. */\nexport async function resolveOne(\n container: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n timeout?: number,\n): Promise<HTMLElement> {\n const root = await resolveScope(container, scope, timeout)\n // The errors already carry the scope path, so there is nothing to wrap.\n return findOne(root, scope, selector, timeout)\n}\n\n/**\n * How many nodes match. The scope chain still waits, but the final count uses the\n * non-waiting query so that zero answers immediately rather than throwing after a\n * retry timeout. This is the behaviour Playwright already had.\n */\nexport async function countAll(\n container: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n timeout?: number,\n): Promise<number> {\n let root: HTMLElement\n try {\n root = await resolveScope(container, scope, timeout)\n } catch (error) {\n if (error instanceof FrameEntryError) throw error\n // The scope itself is not on screen, so nothing inside it can be either.\n return 0\n }\n const matches = queryAll(root, selector)\n if (selector.nth === undefined) return matches.length\n return matches[selector.nth] === undefined ? 0 : 1\n}\n\n// --- without waiting ------------------------------------------------------\n//\n// For a driver whose own runtime does the retrying — TestCafe's Selector, a\n// remote driver polling from Node — every lookup has to answer at once. These\n// apply exactly the same strictness, index, and frame rules as the waiting\n// forms above: anything those reject at once, these throw. The one difference\n// is that \"nothing matches yet\" is `null` instead of a wait.\n\n/** The scope chain's innermost element now, or `null` if a link is not on screen. */\nexport function resolveScopeNow(\n container: HTMLElement,\n scope: readonly Selector[],\n): HTMLElement | null {\n let current = container\n for (const [index, step] of scope.entries()) {\n const path = scope.slice(0, index)\n const matches = queryAll(current, step)\n if (matches.length === 0) return null\n const found = pick(matches, path, step)\n current = step.frame === true ? frameBody(found, path, step) : found\n }\n return current\n}\n\n/** The single node a strict operation acts on now, or `null` if it is not on screen. */\nexport function resolveOneNow(\n container: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n): HTMLElement | null {\n const root = resolveScopeNow(container, scope)\n if (root === null) return null\n const matches = queryAll(root, selector)\n if (matches.length === 0) return null\n return pick(matches, scope, selector)\n}\n\n/**\n * Every match now, agreeing with `countAll` on every scope it cannot resolve:\n * an absent or ambiguous scope is an empty list, and only a frame that cannot\n * be entered throws.\n */\nexport function resolveAllNow(\n container: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n): HTMLElement[] {\n let root: HTMLElement | null\n try {\n root = resolveScopeNow(container, scope)\n } catch (error) {\n if (error instanceof FrameEntryError) throw error\n return []\n }\n if (root === null) return []\n const matches = queryAll(root, selector)\n if (selector.nth === undefined) return matches\n const found = matches[selector.nth]\n return found === undefined ? [] : [found]\n}\n\n/**\n * Every match for a list operation: the scope waits, the list does not, and\n * `nth` is ignored — each result is addressed by its own index afterwards. The\n * one definition of \"the list\" for in-process and injected drivers alike.\n */\nexport async function resolveAll(\n container: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n timeout?: number,\n): Promise<HTMLElement[]> {\n return queryAll(await resolveScope(container, scope, timeout), selector)\n}\n","/**\n * Whether an element is visible by layout — Playwright's definition, for drivers\n * that run in a real browser beside the page (Vitest browser mode, Ember, Cypress).\n * jsdom computes no layout, so the dom driver cannot use this and reads computed\n * style instead.\n *\n * Visible means a non-empty box that `visibility` does not hide. `display: none`\n * anywhere above gives an empty box, so it needs no check of its own. Opacity\n * does not count: a transparent box is still there to click, and Playwright\n * reports it visible.\n *\n * Inside a frame, the iframe has to be visible too — a hidden frame hides its\n * content. The walk crosses frames up to `home` (by default, every reachable\n * one), so a driver passes its own document to stop at the frames its scope\n * actually entered.\n */\nexport function isVisibleInLayout(element: Element, home?: Document): boolean {\n if (!isVisibleInOwnDocument(element)) return false\n const document = element.ownerDocument\n if (document === home) return true\n // Null at the top, and for a cross-origin parent, which script cannot see into.\n const frame = document.defaultView?.frameElement\n return frame == null || isVisibleInLayout(frame, home)\n}\n\nfunction isVisibleInOwnDocument(element: Element): boolean {\n const view = element.ownerDocument.defaultView\n // A node with no window is detached from any rendering.\n if (view == null) return false\n const style = view.getComputedStyle(element)\n // `display: contents` draws no box of its own, so it is as visible as what it\n // contains.\n if (style.display === 'contents') {\n return [...element.children].some(child => isVisibleInOwnDocument(child))\n }\n if (style.visibility !== 'visible') return false\n const box = element.getBoundingClientRect()\n return box.width > 0 && box.height > 0\n}\n","import type { BoundingBox } from '@harnessed-ts/core'\n\n/** A point in a document's viewport, in CSS pixels. */\nexport interface Point {\n x: number\n y: number\n}\n\n/**\n * An element's border box in its own document's viewport, or `null` when it\n * renders no box at all (`display: none`, or anything inside it). Every driver\n * reads `null` as all zeros, which is what Playwright and Puppeteer — whose\n * native boxes are `null` there — are normalised to.\n */\nexport function boxInOwnDocument(element: Element): BoundingBox | null {\n if (element.getClientRects().length === 0) return null\n const { x, y, width, height } = element.getBoundingClientRect()\n return { x, y, width, height }\n}\n\n/**\n * Where an iframe's document is drawn, in the iframe's own document: the corner\n * of its content box, inside its border and padding. The same offset Playwright\n * and Puppeteer add when they report a framed element's box.\n */\nexport function frameOrigin(iframe: Element): Point {\n const { x, y } = iframe.getBoundingClientRect()\n const style = iframe.ownerDocument.defaultView?.getComputedStyle(iframe)\n const px = (value: string | undefined): number => Number.parseFloat(value ?? '') || 0\n return {\n x: x + px(style?.borderLeftWidth) + px(style?.paddingLeft),\n y: y + px(style?.borderTopWidth) + px(style?.paddingTop),\n }\n}\n\n/**\n * An element's box relative to the viewport of `home` — the document the\n * driver drives — adding the origin of every same-origin frame crossed on the\n * way up. For drivers that resolve inside the page; under jsdom everything is\n * zeros, because jsdom computes no layout.\n */\nexport function boundingBoxOf(element: Element, home?: Document): BoundingBox {\n const box = boxInOwnDocument(element)\n if (box === null) return { x: 0, y: 0, width: 0, height: 0 }\n let document = element.ownerDocument\n while (document !== home) {\n // Null at the top, and for a cross-origin parent, which script cannot see into.\n const frame = document.defaultView?.frameElement\n if (frame == null) break\n const origin = frameOrigin(frame)\n box.x += origin.x\n box.y += origin.y\n document = frame.ownerDocument\n }\n return box\n}\n","/**\n * The file input an upload sets: the element itself, or the control of a\n * `<label>` — user-event's and Playwright's rule both. Anything else comes back\n * described as markup, for core's `checkFileTarget` to refuse in one wording.\n */\nexport function fileInputOf(element: Element): HTMLInputElement | string {\n const target =\n element.localName === 'label' ? (element as HTMLLabelElement).control : (element as Element)\n if (target === null) return '<label> with no control'\n if (target.localName !== 'input') return `<${target.localName}>`\n const input = target as HTMLInputElement\n return input.type === 'file' ? input : `<input type=\"${input.type}\">`\n}\n","/**\n * Where the injected build installs itself on the page's `window`. A leaf\n * module with no imports, so the Node-side `inject` entry can name it without\n * pulling in the resolver and Testing Library, which only run in the page.\n */\nexport const PAGE_API_GLOBAL = '__harnessedResolve'\n","import type { Selector } from '@harnessed-ts/core'\n\n/**\n * A `Selector` as it crosses into a remote page. Everything in one is JSON-safe\n * except a RegExp — `role('button', { name: /save/i })` — which WebDriver,\n * CDP and TestCafe all serialise to `{}`. This encodes them as tagged objects\n * on the way out, and the page API decodes them on the way in.\n */\nexport interface WireRegExp {\n $regexp: string\n flags: string\n}\n\nexport type WireSelector = Record<string, unknown>\n\n/**\n * Not `instanceof`: a selector built in the test process and handed to a page\n * in the same JS engine (jsdom, a same-origin frame) carries the other realm's\n * RegExp, which `instanceof` does not recognise.\n */\nfunction isRegExp(value: unknown): value is RegExp {\n return Object.prototype.toString.call(value) === '[object RegExp]'\n}\n\nfunction encodeValue(value: unknown): unknown {\n if (isRegExp(value)) return { $regexp: value.source, flags: value.flags }\n if (Array.isArray(value)) return value.map(encodeValue)\n if (typeof value === 'object' && value !== null) {\n return Object.fromEntries(\n Object.entries(value).map(([key, inner]) => [key, encodeValue(inner)]),\n )\n }\n return value\n}\n\nfunction isWireRegExp(value: unknown): value is WireRegExp {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as WireRegExp).$regexp === 'string' &&\n typeof (value as WireRegExp).flags === 'string'\n )\n}\n\nfunction decodeValue(value: unknown): unknown {\n if (isRegExp(value)) return new RegExp(value.source, value.flags)\n if (isWireRegExp(value)) return new RegExp(value.$regexp, value.flags)\n if (Array.isArray(value)) return value.map(decodeValue)\n if (typeof value === 'object' && value !== null) {\n return Object.fromEntries(\n Object.entries(value).map(([key, inner]) => [key, decodeValue(inner)]),\n )\n }\n return value\n}\n\nexport function encodeSelector(selector: Selector): WireSelector {\n return encodeValue(selector) as WireSelector\n}\n\n/** Idempotent: a selector that never left the process decodes to itself. */\nexport function decodeSelector(selector: Selector | WireSelector): Selector {\n return decodeValue(selector) as Selector\n}\n","import { configure } from '@harnessed-ts/core'\nimport type { BoundingBox, FileTarget, Selector } from '@harnessed-ts/core'\nimport { boxInOwnDocument, frameOrigin } from './box'\nimport type { Point } from './box'\nimport { fileInputOf } from './files'\nimport { PAGE_API_GLOBAL } from './global-name'\nimport { countAll, resolveAll, resolveAllNow, resolveOne, resolveOneNow } from './resolve'\nimport { isVisibleInLayout } from './visible'\nimport { decodeSelector } from './wire'\nimport type { WireSelector } from './wire'\n\nexport { PAGE_API_GLOBAL }\n\n/**\n * Settings a remote driver passes on every call. The page has no access to the\n * test process's `configure()`, so the runtime config travels with the call\n * rather than being pushed once.\n */\n/** A selector as handed over the wire, or as-is when caller and page share a realm. */\ntype Wire = Selector | WireSelector\n\nexport interface PageApiOptions {\n testIdAttribute: string\n timeout: number\n}\n\n/**\n * The resolver as seen from inside a page a driver does not share a realm with\n * — WebdriverIO, Puppeteer, TestCafe. Every argument is serialisable except\n * `root`, which is an element handle the driver passes back in (or `null` for\n * the document body).\n *\n * The same functions back the dom driver, so role, label, strictness, index\n * and frame semantics cannot differ between a driver resolving in-process and\n * one resolving through this.\n */\nexport interface PageApi {\n /** How many nodes match. The scope waits; the count does not. */\n count(\n root: Element | null,\n scope: Wire[],\n selector: Wire,\n options: PageApiOptions,\n ): Promise<number>\n /** The single node a strict operation acts on, waiting for it. */\n one(\n root: Element | null,\n scope: Wire[],\n selector: Wire,\n options: PageApiOptions,\n ): Promise<Element>\n /** Every match, after waiting for the scope. `nth` is ignored, as for any list. */\n all(\n root: Element | null,\n scope: Wire[],\n selector: Wire,\n options: PageApiOptions,\n ): Promise<Element[]>\n /** The single node now, or `null`. For runtimes that do their own retrying. */\n oneNow(\n root: Element | null,\n scope: Wire[],\n selector: Wire,\n options: PageApiOptions,\n ): Element | null\n /** Every match now. */\n allNow(root: Element | null, scope: Wire[], selector: Wire, options: PageApiOptions): Element[]\n /**\n * Whether an element is visible by layout, within its own document only. A\n * driver that enters frames from outside the page asks about each iframe it\n * crossed in that iframe's own document, which also covers a cross-origin\n * frame no in-page walk could cross.\n */\n visible(element: Element): boolean\n /**\n * The element's box in its own document's viewport, or `null` when it draws\n * none. A driver that enters frames from outside adds each crossed frame's\n * `origin` itself.\n */\n box(element: Element): BoundingBox | null\n /** Where an iframe's document is drawn, in the iframe's own document. */\n origin(iframe: Element): Point\n /** What an upload would set: the file input's `multiple`, or what the element is instead. */\n fileTarget(element: Element): FileTarget\n}\n\nexport function createPageApi(document: Document): PageApi {\n const start = (root: Element | null): HTMLElement => (root ?? document.body) as HTMLElement\n // Only the test-id attribute: every waiting call passes its timeout\n // explicitly. Note this writes the page's harnessed config, so the API belongs\n // in a page that runs no harnesses of its own — which is every remote page.\n const apply = (options: PageApiOptions): void =>\n configure({ testIdAttribute: options.testIdAttribute })\n const decode = (scope: Wire[], selector: Wire): [Selector[], Selector] => [\n scope.map(decodeSelector),\n decodeSelector(selector),\n ]\n\n return {\n async count(root, scope, selector, options) {\n apply(options)\n const [steps, target] = decode(scope, selector)\n return countAll(start(root), steps, target, options.timeout)\n },\n async one(root, scope, selector, options) {\n apply(options)\n const [steps, target] = decode(scope, selector)\n return resolveOne(start(root), steps, target, options.timeout)\n },\n async all(root, scope, selector, options) {\n apply(options)\n const [steps, target] = decode(scope, selector)\n return resolveAll(start(root), steps, target, options.timeout)\n },\n oneNow(root, scope, selector, options) {\n apply(options)\n const [steps, target] = decode(scope, selector)\n return resolveOneNow(start(root), steps, target)\n },\n allNow(root, scope, selector, options) {\n apply(options)\n const [steps, target] = decode(scope, selector)\n return resolveAllNow(start(root), steps, target)\n },\n visible(element) {\n return isVisibleInLayout(element, element.ownerDocument)\n },\n box: boxInOwnDocument,\n origin: frameOrigin,\n fileTarget(element) {\n const input = fileInputOf(element)\n return typeof input === 'string' ? input : { multiple: input.multiple }\n },\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ export { countAll, resolveAll, FrameEntryError, queryAll, resolveAllNow, resolveOne, resolveOneNow, resolveScope, resolveScopeNow, } from './resolve';
2
+ export { isVisibleInLayout } from './visible';
3
+ export { boundingBoxOf, boxInOwnDocument, frameOrigin } from './box';
4
+ export type { Point } from './box';
5
+ export { fileInputOf } from './files';
6
+ export { createPageApi, PAGE_API_GLOBAL } from './page-api';
7
+ export type { PageApi, PageApiOptions } from './page-api';
8
+ export { decodeSelector, encodeSelector } from './wire';
9
+ export type { WireRegExp, WireSelector } from './wire';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,UAAU,EACV,eAAe,EACf,QAAQ,EACR,aAAa,EACb,UAAU,EACV,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACpE,YAAY,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC3D,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AACvD,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA"}