@immense/vue-pom-generator 1.0.91 → 1.0.93

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 (66) hide show
  1. package/README.md +76 -2
  2. package/RELEASE_NOTES.md +22 -22
  3. package/class-generation/base-page.ts +141 -59
  4. package/class-generation/diagnostics.ts +559 -0
  5. package/class-generation/index.ts +123 -21
  6. package/class-generation/playwright-types.ts +7 -11
  7. package/class-generation/pointer.ts +65 -18
  8. package/dist/class-generation/base-page.d.ts +19 -4
  9. package/dist/class-generation/base-page.d.ts.map +1 -1
  10. package/dist/class-generation/diagnostics.d.ts +110 -0
  11. package/dist/class-generation/diagnostics.d.ts.map +1 -0
  12. package/dist/class-generation/index.d.ts +3 -0
  13. package/dist/class-generation/index.d.ts.map +1 -1
  14. package/dist/class-generation/playwright-types.d.ts +3 -39
  15. package/dist/class-generation/playwright-types.d.ts.map +1 -1
  16. package/dist/class-generation/pointer.d.ts +10 -1
  17. package/dist/class-generation/pointer.d.ts.map +1 -1
  18. package/dist/eslint/index.cjs +52 -9
  19. package/dist/eslint/index.cjs.map +1 -1
  20. package/dist/eslint/index.d.ts +16 -7
  21. package/dist/eslint/index.d.ts.map +1 -1
  22. package/dist/eslint/index.mjs +52 -9
  23. package/dist/eslint/index.mjs.map +1 -1
  24. package/dist/index.cjs +419 -298
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.mjs +419 -298
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/manifest-generator.d.ts +10 -5
  29. package/dist/manifest-generator.d.ts.map +1 -1
  30. package/dist/method-generation.d.ts.map +1 -1
  31. package/dist/playwright/reporter.cjs +174 -0
  32. package/dist/playwright/reporter.cjs.map +1 -0
  33. package/dist/playwright/reporter.d.ts +13 -0
  34. package/dist/playwright/reporter.d.ts.map +1 -0
  35. package/dist/playwright/reporter.mjs +174 -0
  36. package/dist/playwright/reporter.mjs.map +1 -0
  37. package/dist/playwright/runtime.cjs +945 -0
  38. package/dist/playwright/runtime.cjs.map +1 -0
  39. package/dist/playwright/runtime.mjs +945 -0
  40. package/dist/playwright/runtime.mjs.map +1 -0
  41. package/dist/plugin/internal/build-plugin.d.ts +2 -0
  42. package/dist/plugin/internal/build-plugin.d.ts.map +1 -1
  43. package/dist/plugin/internal/dev-plugin.d.ts +2 -0
  44. package/dist/plugin/internal/dev-plugin.d.ts.map +1 -1
  45. package/dist/plugin/internal-plugins.d.ts.map +1 -1
  46. package/dist/route-navigation-codegen.d.ts +3 -1
  47. package/dist/route-navigation-codegen.d.ts.map +1 -1
  48. package/dist/router-bridge.d.ts +14 -0
  49. package/dist/router-bridge.d.ts.map +1 -1
  50. package/dist/router.cjs +41 -1
  51. package/dist/router.cjs.map +1 -1
  52. package/dist/router.mjs +41 -1
  53. package/dist/router.mjs.map +1 -1
  54. package/dist/tests/broad/helpers/fake-runtime.d.ts +27 -3
  55. package/dist/tests/broad/helpers/fake-runtime.d.ts.map +1 -1
  56. package/dist/tests/fixtures/generated-tsc/base-page.full.d.ts +16 -3
  57. package/dist/tests/fixtures/generated-tsc/base-page.full.d.ts.map +1 -1
  58. package/dist/tests/method-generation.test.d.ts +2 -0
  59. package/dist/tests/method-generation.test.d.ts.map +1 -0
  60. package/dist/tests/playwright-diagnostics.test.d.ts +2 -0
  61. package/dist/tests/playwright-diagnostics.test.d.ts.map +1 -0
  62. package/dist/tests/playwright-reporter.test.d.ts +2 -0
  63. package/dist/tests/playwright-reporter.test.d.ts.map +1 -0
  64. package/dist/transform.d.ts.map +1 -1
  65. package/dist/vite.config.d.ts.map +1 -1
  66. package/package.json +13 -1
@@ -0,0 +1,945 @@
1
+ const POINTER_CALLOUT_IDS = {
2
+ annotation: "__pw_pointer_callout__",
3
+ arrow: "__pw_pointer_callout_arrow__",
4
+ content: "__pw_pointer_callout_content__"
5
+ };
6
+ const POINTER_CALLOUT_THEME = {
7
+ background: "#dc2626",
8
+ border: "0px solid transparent",
9
+ borderRadius: 0,
10
+ boxShadow: "0 20px 44px rgba(127, 29, 29, 0.32)",
11
+ charsPerLine: 28,
12
+ gap: 18,
13
+ margin: 18,
14
+ maxWidth: 320,
15
+ minHeight: 52,
16
+ minWidth: 180,
17
+ textColor: "#f8fafc"
18
+ };
19
+ function measureCalloutBubble(text) {
20
+ return {
21
+ bubbleWidth: Math.min(
22
+ POINTER_CALLOUT_THEME.maxWidth,
23
+ Math.max(
24
+ POINTER_CALLOUT_THEME.minWidth,
25
+ Math.min(text.length, POINTER_CALLOUT_THEME.charsPerLine) * 7 + 44
26
+ )
27
+ ),
28
+ bubbleHeight: Math.max(
29
+ POINTER_CALLOUT_THEME.minHeight,
30
+ Math.ceil(Math.max(text.length, 1) / POINTER_CALLOUT_THEME.charsPerLine) * 20 + 24
31
+ )
32
+ };
33
+ }
34
+ async function __pw_ensure_simple_callout__(page) {
35
+ await page.evaluate(
36
+ ({
37
+ annotationId,
38
+ contentId,
39
+ background,
40
+ border,
41
+ borderRadius,
42
+ boxShadow,
43
+ textColor
44
+ }) => {
45
+ const ensureElement = (id, tagName) => {
46
+ const existing = document.getElementById(id);
47
+ if (existing instanceof HTMLElement) {
48
+ return existing;
49
+ }
50
+ const created = document.createElement(tagName);
51
+ created.id = id;
52
+ return created;
53
+ };
54
+ const annotation = ensureElement(annotationId, "div");
55
+ annotation.setAttribute(
56
+ "style",
57
+ [
58
+ "position:fixed",
59
+ "z-index:2147483647",
60
+ "pointer-events:none",
61
+ "left:18px",
62
+ "top:18px",
63
+ "width:220px",
64
+ "box-sizing:border-box",
65
+ "padding:12px 16px",
66
+ "border:" + border,
67
+ "border-radius:" + borderRadius + "px",
68
+ "background:" + background,
69
+ "color:" + textColor,
70
+ "font:600 13px/1.45 Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
71
+ "letter-spacing:0.01em",
72
+ "box-shadow:" + boxShadow,
73
+ "opacity:0",
74
+ "white-space:normal",
75
+ "transform:translate3d(0,0,0)",
76
+ "transform-origin:center"
77
+ ].join(";")
78
+ );
79
+ const content = ensureElement(contentId, "div");
80
+ content.setAttribute("style", "position:relative;z-index:1;");
81
+ if (!annotation.isConnected) {
82
+ document.body.appendChild(annotation);
83
+ }
84
+ if (content.parentElement !== annotation) {
85
+ annotation.appendChild(content);
86
+ }
87
+ },
88
+ {
89
+ annotationId: POINTER_CALLOUT_IDS.annotation,
90
+ contentId: POINTER_CALLOUT_IDS.content,
91
+ background: POINTER_CALLOUT_THEME.background,
92
+ border: POINTER_CALLOUT_THEME.border,
93
+ borderRadius: POINTER_CALLOUT_THEME.borderRadius,
94
+ boxShadow: POINTER_CALLOUT_THEME.boxShadow,
95
+ textColor: POINTER_CALLOUT_THEME.textColor
96
+ }
97
+ );
98
+ }
99
+ const __pw_default_callout_renderer__ = {
100
+ overlayIds: [
101
+ POINTER_CALLOUT_IDS.annotation,
102
+ POINTER_CALLOUT_IDS.content,
103
+ POINTER_CALLOUT_IDS.arrow
104
+ ],
105
+ async hide(page) {
106
+ await page.evaluate(
107
+ ({ annotationId, contentId, arrowId }) => {
108
+ const annotation = document.getElementById(annotationId);
109
+ const content = document.getElementById(contentId);
110
+ const arrow = document.getElementById(arrowId);
111
+ if (!annotation) {
112
+ return;
113
+ }
114
+ if (content) {
115
+ content.textContent = "";
116
+ }
117
+ annotation.style.transition = "opacity 120ms ease-in-out, transform 160ms ease-in-out";
118
+ annotation.style.opacity = "0";
119
+ annotation.style.transform = "scale(0.96)";
120
+ annotation.setAttribute("data-placement", "hidden");
121
+ if (arrow) {
122
+ arrow.style.opacity = "0";
123
+ arrow.style.left = "";
124
+ arrow.style.top = "";
125
+ arrow.style.right = "";
126
+ arrow.style.bottom = "";
127
+ }
128
+ },
129
+ {
130
+ annotationId: POINTER_CALLOUT_IDS.annotation,
131
+ contentId: POINTER_CALLOUT_IDS.content,
132
+ arrowId: POINTER_CALLOUT_IDS.arrow
133
+ }
134
+ );
135
+ },
136
+ async show(page, request) {
137
+ await __pw_ensure_simple_callout__(page);
138
+ const { bubbleHeight, bubbleWidth } = measureCalloutBubble(request.text);
139
+ await page.evaluate(
140
+ ({
141
+ annotationId,
142
+ contentId,
143
+ arrowId,
144
+ bubbleHeight: bubbleHeight2,
145
+ bubbleWidth: bubbleWidth2,
146
+ border,
147
+ borderRadius,
148
+ background,
149
+ gap,
150
+ text,
151
+ targetBox,
152
+ margin
153
+ }) => {
154
+ const annotation = document.getElementById(annotationId);
155
+ const content = document.getElementById(contentId);
156
+ const arrow = document.getElementById(arrowId);
157
+ if (!annotation || !content) {
158
+ return;
159
+ }
160
+ const viewportWidth = Math.max(window.innerWidth || 0, document.documentElement.clientWidth, 1280);
161
+ const viewportHeight = Math.max(window.innerHeight || 0, document.documentElement.clientHeight, 720);
162
+ const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
163
+ const targetCenterX = targetBox.x + targetBox.width / 2;
164
+ const targetCenterY = targetBox.y + targetBox.height / 2;
165
+ const maxX = Math.max(margin, viewportWidth - bubbleWidth2 - margin);
166
+ const maxY = Math.max(margin, viewportHeight - bubbleHeight2 - margin);
167
+ const candidates = [
168
+ {
169
+ placement: "right",
170
+ x: targetBox.x + targetBox.width + gap,
171
+ y: targetCenterY - bubbleHeight2 / 2
172
+ },
173
+ {
174
+ placement: "bottom",
175
+ x: targetCenterX - bubbleWidth2 / 2,
176
+ y: targetBox.y + targetBox.height + gap
177
+ },
178
+ {
179
+ placement: "left",
180
+ x: targetBox.x - bubbleWidth2 - gap,
181
+ y: targetCenterY - bubbleHeight2 / 2
182
+ },
183
+ {
184
+ placement: "top",
185
+ x: targetCenterX - bubbleWidth2 / 2,
186
+ y: targetBox.y - bubbleHeight2 - gap
187
+ }
188
+ ];
189
+ let placement = "center";
190
+ let resolvedX = clamp(targetCenterX - bubbleWidth2 / 2, margin, maxX);
191
+ let resolvedY = clamp(targetCenterY - bubbleHeight2 / 2, margin, maxY);
192
+ for (const candidate of candidates) {
193
+ const clampedX = clamp(candidate.x, margin, maxX);
194
+ const clampedY = clamp(candidate.y, margin, maxY);
195
+ const fitsWithoutShift = Math.abs(clampedX - candidate.x) < 1 && Math.abs(clampedY - candidate.y) < 1;
196
+ if (fitsWithoutShift) {
197
+ placement = candidate.placement;
198
+ resolvedX = candidate.x;
199
+ resolvedY = candidate.y;
200
+ break;
201
+ }
202
+ }
203
+ content.textContent = text;
204
+ annotation.style.width = `${bubbleWidth2}px`;
205
+ annotation.style.minHeight = `${bubbleHeight2}px`;
206
+ annotation.style.background = background;
207
+ annotation.style.border = border;
208
+ annotation.style.borderRadius = `${borderRadius}px`;
209
+ annotation.style.transition = "opacity 120ms ease-in-out, transform 160ms ease-in-out";
210
+ annotation.style.willChange = "left, top, opacity, transform";
211
+ annotation.style.left = `${Math.round(resolvedX)}px`;
212
+ annotation.style.top = `${Math.round(resolvedY)}px`;
213
+ annotation.style.opacity = "1";
214
+ annotation.style.transform = "scale(1)";
215
+ annotation.setAttribute("data-placement", placement);
216
+ if (arrow) {
217
+ arrow.style.opacity = "0";
218
+ arrow.style.left = "";
219
+ arrow.style.top = "";
220
+ arrow.style.right = "";
221
+ arrow.style.bottom = "";
222
+ }
223
+ },
224
+ {
225
+ annotationId: POINTER_CALLOUT_IDS.annotation,
226
+ contentId: POINTER_CALLOUT_IDS.content,
227
+ arrowId: POINTER_CALLOUT_IDS.arrow,
228
+ bubbleHeight,
229
+ bubbleWidth,
230
+ border: POINTER_CALLOUT_THEME.border,
231
+ borderRadius: POINTER_CALLOUT_THEME.borderRadius,
232
+ background: POINTER_CALLOUT_THEME.background,
233
+ gap: POINTER_CALLOUT_THEME.gap,
234
+ text: request.text,
235
+ targetBox: request.targetBox,
236
+ margin: POINTER_CALLOUT_THEME.margin
237
+ }
238
+ );
239
+ }
240
+ };
241
+ class Callout {
242
+ page;
243
+ extraOverlayIds;
244
+ renderer;
245
+ constructor(page, options) {
246
+ this.page = page;
247
+ this.extraOverlayIds = options?.extraOverlayIds ?? [];
248
+ this.renderer = options?.renderer ?? __pw_default_callout_renderer__;
249
+ }
250
+ toLocator(target) {
251
+ return typeof target === "string" ? this.page.locator(target) : target;
252
+ }
253
+ async hide() {
254
+ await this.renderer.hide(this.page);
255
+ }
256
+ async showForElement(target, annotationText, options) {
257
+ const text = annotationText.trim();
258
+ if (!text) {
259
+ await this.hide();
260
+ return;
261
+ }
262
+ const locator = this.toLocator(target);
263
+ if (!options?.skipScroll) {
264
+ try {
265
+ await locator.first().scrollIntoViewIfNeeded();
266
+ } catch {
267
+ }
268
+ }
269
+ const targetBox = options?.targetBox ?? await locator.first().boundingBox();
270
+ if (!targetBox) {
271
+ throw new Error("Callout.showForElement: target has no bounding box");
272
+ }
273
+ const overlayIds = Array.from(/* @__PURE__ */ new Set([
274
+ ...this.renderer.overlayIds ?? [],
275
+ ...this.extraOverlayIds
276
+ ]));
277
+ await this.renderer.show(this.page, {
278
+ overlayIds,
279
+ target,
280
+ targetBox: {
281
+ height: targetBox.height,
282
+ width: targetBox.width,
283
+ x: targetBox.x,
284
+ y: targetBox.y
285
+ },
286
+ text
287
+ });
288
+ }
289
+ }
290
+ const __PW_POINTER_ID__ = "__pw_pointer__";
291
+ const __PW_EDITABLE_DESCENDANT_SELECTOR__ = "input, textarea, select, [contenteditable=''], [contenteditable='true'], [contenteditable]:not([contenteditable='false'])";
292
+ const __PW_POINTER_PNG__ = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAeCAQAAACGG/bgAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAAHsYAAB7GAZEt8iwAAAAHdElNRQfgAwgMIwdxU/i7AAABZklEQVQ4y43TsU4UURSH8W+XmYwkS2I09CRKpKGhsvIJjG9giQmliHFZlkUIGnEF7KTiCagpsYHWhoTQaiUUxLixYZb5KAAZZhbunu7O/PKfe+fcA+/pqwb4DuximEqXhT4iI8dMpBWEsWsuGYdpZFttiLSSgTvhZ1W/SvfO1CvYdV1kPghV68a30zzUWZH5pBqEui7dnqlFmLoq0gxC1XfGZdoLal2kea8ahLoqKXNAJQBT2yJzwUTVt0bS6ANqy1gaVCEq/oVTtjji4hQVhhnlYBH4WIJV9vlkXLm+10R8oJb79Jl1j9UdazJRGpkrmNkSF9SOz2T71s7MSIfD2lmmfjGSRz3hK8l4w1P+bah/HJLN0sys2JSMZQB+jKo6KSc8vLlLn5ikzF4268Wg2+pPOWW6ONcpr3PrXy9VfS473M/D7H+TLmrqsXtOGctvxvMv2oVNP+Av0uHbzbxyJaywyUjx8TlnPY2YxqkDdAAAAABJRU5ErkJggg==";
293
+ const __pw_pointer_positions__ = /* @__PURE__ */ new WeakMap();
294
+ function __pw_set_pointer_pos__(page, x, y) {
295
+ __pw_pointer_positions__.set(page, { x, y });
296
+ }
297
+ let animationOptions = {
298
+ extraDelayMs: 0
299
+ };
300
+ const __pw_default_pointer_renderer__ = {
301
+ overlayIds: [__PW_POINTER_ID__],
302
+ async ensure(page) {
303
+ const exists = await page.evaluate(
304
+ ({ pointerId }) => document.getElementById(pointerId) != null,
305
+ { pointerId: __PW_POINTER_ID__ }
306
+ );
307
+ if (exists) return;
308
+ __pw_set_pointer_pos__(page, 0, 0);
309
+ await page.evaluate(
310
+ ({ id, src }) => {
311
+ const img = document.createElement("img");
312
+ img.setAttribute("src", src);
313
+ img.setAttribute("id", id);
314
+ img.setAttribute(
315
+ "style",
316
+ "position:fixed;z-index:2147483647;pointer-events:none;left:0;top:0;transform-origin:0 0;"
317
+ );
318
+ document.body.appendChild(img);
319
+ },
320
+ {
321
+ id: __PW_POINTER_ID__,
322
+ src: __PW_POINTER_PNG__
323
+ }
324
+ );
325
+ },
326
+ async move(page, request) {
327
+ await page.evaluate(
328
+ ({
329
+ animate,
330
+ dur,
331
+ ex,
332
+ ey,
333
+ id,
334
+ style,
335
+ sx,
336
+ sy
337
+ }) => {
338
+ const el = document.getElementById(id);
339
+ if (!el) {
340
+ return;
341
+ }
342
+ el.style.transition = "";
343
+ el.style.willChange = "left, top";
344
+ el.style.left = `${animate ? sx : ex}px`;
345
+ el.style.top = `${animate ? sy : ey}px`;
346
+ if (animate) {
347
+ void el.offsetWidth;
348
+ el.style.transition = `left ${dur}ms ${style}, top ${dur}ms ${style}`;
349
+ el.style.left = `${ex}px`;
350
+ el.style.top = `${ey}px`;
351
+ }
352
+ },
353
+ {
354
+ animate: request.animate,
355
+ dur: request.durationMilliseconds,
356
+ ex: request.endX,
357
+ ey: request.endY,
358
+ id: __PW_POINTER_ID__,
359
+ style: request.transitionStyle,
360
+ sx: request.startX,
361
+ sy: request.startY
362
+ }
363
+ );
364
+ },
365
+ async press(page, request) {
366
+ await page.evaluate(
367
+ ({ id, dur }) => {
368
+ const el = document.getElementById(id);
369
+ if (el) {
370
+ el.style.transition = `transform ${dur}ms`;
371
+ el.style.transform = "scale(0.6)";
372
+ setTimeout(() => {
373
+ el.style.transition = `transform ${dur}ms`;
374
+ el.style.transform = "scale(1)";
375
+ }, dur);
376
+ }
377
+ },
378
+ { id: __PW_POINTER_ID__, dur: request.durationMilliseconds }
379
+ );
380
+ }
381
+ };
382
+ class Pointer {
383
+ page;
384
+ testIdAttribute;
385
+ callout;
386
+ renderer;
387
+ constructor(page, testIdAttribute, callout, renderer) {
388
+ this.page = page;
389
+ this.testIdAttribute = (testIdAttribute ?? "data-testid").trim() || "data-testid";
390
+ this.renderer = renderer ?? __pw_default_pointer_renderer__;
391
+ const calloutOptions = {
392
+ extraOverlayIds: this.renderer.overlayIds
393
+ };
394
+ this.callout = callout ?? new Callout(page, calloutOptions);
395
+ }
396
+ toLocator(target) {
397
+ return typeof target === "string" ? this.page.locator(target) : target;
398
+ }
399
+ async getTestId(locator) {
400
+ const raw = await locator.first().getAttribute(this.testIdAttribute);
401
+ const trimmed = (raw ?? "").trim();
402
+ return trimmed || void 0;
403
+ }
404
+ /**
405
+ * Playwright waits for an element's box to be stable, but a component library can
406
+ * still suppress pointer handlers while an ancestor overlay is finishing a CSS
407
+ * transition. Wait for finite animations on the target's ancestor chain so the
408
+ * generated action observes the same ready state a user sees. Infinite decorative
409
+ * animations are ignored, and a stuck finite animation fails within the shared 5s
410
+ * interaction budget instead of encouraging consumer-side sleeps.
411
+ */
412
+ async waitForFiniteAncestorAnimations(locator) {
413
+ await locator.first().evaluate(async (element) => {
414
+ const timeoutMs = 5e3;
415
+ const animations = /* @__PURE__ */ new Set();
416
+ for (let current = element; current; current = current.parentElement ?? null) {
417
+ if (typeof current.getAnimations !== "function") continue;
418
+ for (const animation of current.getAnimations()) {
419
+ const iterations = Number(animation.effect?.getComputedTiming().iterations ?? 1);
420
+ if (animation.playState === "running" && Number.isFinite(iterations)) {
421
+ animations.add(animation);
422
+ }
423
+ }
424
+ }
425
+ if (animations.size === 0) return;
426
+ let timer;
427
+ try {
428
+ await Promise.race([
429
+ Promise.allSettled([...animations].map((animation) => animation.finished)),
430
+ new Promise((_resolve, reject) => {
431
+ timer = setTimeout(() => {
432
+ reject(new Error(`[vue-pom-generator] Timed out after ${timeoutMs}ms waiting for click-target animations to finish.`));
433
+ }, timeoutMs);
434
+ })
435
+ ]);
436
+ } finally {
437
+ if (timer !== void 0) clearTimeout(timer);
438
+ }
439
+ });
440
+ }
441
+ async isEditableElement(locator) {
442
+ try {
443
+ return await locator.first().evaluate((element) => {
444
+ if (!(element instanceof HTMLElement)) {
445
+ return false;
446
+ }
447
+ const tagName = element.tagName.toLowerCase();
448
+ return tagName === "input" || tagName === "textarea" || tagName === "select" || element.isContentEditable;
449
+ });
450
+ } catch {
451
+ return false;
452
+ }
453
+ }
454
+ async resolveEditableLocator(locator) {
455
+ const first = locator.first();
456
+ if (await this.isEditableElement(first)) {
457
+ return first;
458
+ }
459
+ const descendant = first.locator(__PW_EDITABLE_DESCENDANT_SELECTOR__).first();
460
+ try {
461
+ if (await descendant.count() > 0) {
462
+ return descendant;
463
+ }
464
+ } catch {
465
+ }
466
+ return first;
467
+ }
468
+ async animateCursorToElement(target, executeClick = true, delayMs = 1e3, annotationText = "", options) {
469
+ const locator = this.toLocator(target);
470
+ const trimmedAnnotationText = annotationText.trim();
471
+ const opts = animationOptions;
472
+ if (executeClick) {
473
+ await this.waitForFiniteAncestorAnimations(locator);
474
+ }
475
+ {
476
+ if (trimmedAnnotationText) {
477
+ await this.callout.showForElement(locator, trimmedAnnotationText);
478
+ }
479
+ const extraDelay = Math.max(0, opts.extraDelayMs);
480
+ if (extraDelay > 0) await this.page.waitForTimeout(extraDelay);
481
+ let clickedTestId2;
482
+ if (executeClick) {
483
+ if (options?.afterClick) {
484
+ try {
485
+ clickedTestId2 = await this.getTestId(locator);
486
+ } catch {
487
+ }
488
+ }
489
+ await locator.first().click();
490
+ }
491
+ if (options?.afterClick) {
492
+ await options.afterClick({ testId: clickedTestId2, instrumented: Boolean(clickedTestId2) });
493
+ }
494
+ return;
495
+ }
496
+ }
497
+ async animateCursorToElementAndClickAndFill(target, text, executeClick = true, delayMs = 1e3, annotationText = "", options) {
498
+ await this.animateCursorToElement(target, executeClick, delayMs, annotationText, options);
499
+ const locator = this.toLocator(target);
500
+ const editableLocator = await this.resolveEditableLocator(locator);
501
+ {
502
+ await editableLocator.fill(text);
503
+ }
504
+ }
505
+ }
506
+ const POM_ACTIVE_ACTION_REGISTRY = /* @__PURE__ */ Symbol.for("@immense/vue-pom-generator.active-action-registry");
507
+ function setPomAction(page, action) {
508
+ const globalRecord = globalThis;
509
+ const registry = globalRecord[POM_ACTIVE_ACTION_REGISTRY] ?? /* @__PURE__ */ new WeakMap();
510
+ globalRecord[POM_ACTIVE_ACTION_REGISTRY] = registry;
511
+ registry.set(page, { ...action, expectedTestIds: [...action.expectedTestIds] });
512
+ }
513
+ class ObjectId {
514
+ raw;
515
+ constructor(raw) {
516
+ if (!raw) {
517
+ throw new Error("ObjectId: raw value is empty");
518
+ }
519
+ this.raw = raw;
520
+ }
521
+ toString() {
522
+ return this.raw;
523
+ }
524
+ asInt() {
525
+ return this.AsInt();
526
+ }
527
+ AsInt() {
528
+ if (!/^\d+$/.test(this.raw)) {
529
+ throw new Error(`ObjectId.AsInt: '${this.raw}' is not a base-10 integer string`);
530
+ }
531
+ const parsed = Number.parseInt(this.raw, 10);
532
+ if (!Number.isSafeInteger(parsed)) {
533
+ throw new TypeError(`ObjectId.AsInt: '${this.raw}' is not a safe integer`);
534
+ }
535
+ return parsed;
536
+ }
537
+ }
538
+ class BasePage {
539
+ testIdAttribute;
540
+ callout;
541
+ pointer;
542
+ /**
543
+ * The narrowed Playwright page, stored privately. The narrowing (`PwPage` =
544
+ * `BasePagePage`) is what lets the unit-test `FakePage` double satisfy the
545
+ * constructor without stubbing ~250 `Page` members; it never escapes this
546
+ * class. Subclasses (generated and hand-written POMs) reach the page through
547
+ * the widened {@link BasePage.page} getter, which surfaces Playwright's full
548
+ * `Page` so custom POMs can use `getByRole`/`waitForResponse`/`waitForFunction`
549
+ * etc. for JS/DOM elements the generator can't key.
550
+ */
551
+ _page;
552
+ /**
553
+ * Playwright's full `Page`, exposed to subclasses. This is the single,
554
+ * sanctioned way generated/custom POMs touch the page — there is no separate
555
+ * `rawPage`. The narrowed storage (`_page`) is widened here; the value is a
556
+ * real `Page` at runtime.
557
+ */
558
+ get page() {
559
+ return this._page;
560
+ }
561
+ /**
562
+ * @param page - Playwright page object (narrowed `PwPage` so test doubles fit).
563
+ */
564
+ constructor(page, options) {
565
+ this._page = page;
566
+ this.testIdAttribute = (options?.testIdAttribute || "data-testid").trim() || "data-testid";
567
+ const pointerRenderer = options?.renderers?.pointer;
568
+ this.callout = new Callout(this._page, {
569
+ extraOverlayIds: pointerRenderer?.overlayIds,
570
+ renderer: options?.renderers?.callout
571
+ });
572
+ this.pointer = new Pointer(this._page, this.testIdAttribute, this.callout, pointerRenderer);
573
+ }
574
+ get screencast() {
575
+ return this.page.screencast;
576
+ }
577
+ async waitForTestIdClickEventAfter(testId, options) {
578
+ {
579
+ return;
580
+ }
581
+ }
582
+ getAfterPointerClick(wait = true) {
583
+ return void 0;
584
+ }
585
+ selectorForTestId(testId) {
586
+ return `[${this.testIdAttribute}="${testId}"]`;
587
+ }
588
+ describeLocator(locator, description) {
589
+ const normalizedDescription = description?.trim();
590
+ return normalizedDescription ? locator.describe(normalizedDescription) : locator;
591
+ }
592
+ locatorByTestId(testId, description) {
593
+ return this.describeLocator(this.page.locator(this.selectorForTestId(testId)), description);
594
+ }
595
+ async resolveVisibleTestIdLocator(testIds, description, methodName, componentName) {
596
+ this.recordPomAction(componentName, methodName, testIds);
597
+ const locators = testIds.map((testId) => this.locatorByTestId(testId, description));
598
+ if (!locators.length) {
599
+ throw new Error(`[pom] ${methodName} has no candidate test ids.`);
600
+ }
601
+ try {
602
+ await Promise.any(locators.map((locator) => locator.waitFor({ state: "visible", timeout: 5e3 })));
603
+ } catch (error) {
604
+ throw new Error(
605
+ `[pom] ${methodName} could not find a visible element for any generated test id: ${testIds.join(", ")}`,
606
+ { cause: error }
607
+ );
608
+ }
609
+ for (const locator of locators) {
610
+ if (await locator.isVisible()) return locator;
611
+ }
612
+ return locators[0];
613
+ }
614
+ recordPomAction(componentName, methodName, expectedTestIds) {
615
+ setPomAction(this.page, { componentName, methodName, expectedTestIds });
616
+ }
617
+ locatorWithinTestIdByLabel(rootTestId, label, options) {
618
+ const locator = this.locatorByTestId(rootTestId).filter({ visible: true }).first().getByText(label, { exact: options?.exact ?? true });
619
+ return this.describeLocator(locator, options?.description);
620
+ }
621
+ /**
622
+ * Animates the pointer to an element.
623
+ */
624
+ async animateCursorToElement(target, executeClick = true, delayMs = 1e3, annotationText = "", options) {
625
+ await this.pointer.animateCursorToElement(target, executeClick, delayMs, annotationText, options);
626
+ }
627
+ async showCallout(target, annotationText) {
628
+ await this.callout.showForElement(target, annotationText);
629
+ }
630
+ async showCalloutByTestId(testId, annotationText) {
631
+ await this.showCallout(this.selectorForTestId(testId), annotationText);
632
+ }
633
+ async hideCallout() {
634
+ await this.callout.hide();
635
+ }
636
+ /**
637
+ * Creates an indexable proxy for keyed elements so generated POMs can expose
638
+ * ergonomic accessors like:
639
+ * expect(page.SaveButton["MyKey"]).toBeVisible();
640
+ */
641
+ keyedLocators(getLocator) {
642
+ const handler = {
643
+ get: (_t, prop) => {
644
+ if (prop === "then" || typeof prop === "symbol") {
645
+ return void 0;
646
+ }
647
+ return getLocator(String(prop));
648
+ }
649
+ };
650
+ return new Proxy({}, handler);
651
+ }
652
+ async getObjectId(options) {
653
+ const timeoutMs = options?.timeoutMs ?? 5e3;
654
+ const deadline = Date.now() + timeoutMs;
655
+ while (true) {
656
+ const url = this.page.url();
657
+ const match = url.match(/\/(\d+)(?:[/?#]|$)/);
658
+ if (match) {
659
+ return new ObjectId(match[1]);
660
+ }
661
+ if (Date.now() >= deadline) {
662
+ throw new Error(`getObjectId: could not find a numeric id in url '${url}' within ${timeoutMs}ms`);
663
+ }
664
+ await new Promise((resolve) => setTimeout(resolve, 50));
665
+ }
666
+ }
667
+ async getObjectIdAsInt(options) {
668
+ const objectId = await this.getObjectId(options);
669
+ return objectId.asInt();
670
+ }
671
+ /**
672
+ * Wraps an async factory for a page object into a chainable Fluent<T>.
673
+ *
674
+ * The returned proxy:
675
+ * - forwards method calls to the resolved object
676
+ * - queues async method calls (Promise-returning) so they execute in order
677
+ * - is PromiseLike, so `await` yields the underlying object
678
+ */
679
+ fluent(factory) {
680
+ const rootPromise = factory();
681
+ const getRoot = () => rootPromise;
682
+ let queue = Promise.resolve();
683
+ let rootProxy;
684
+ const VALUE_RETURNING_METHODS = /* @__PURE__ */ new Set([
685
+ "getObjectId",
686
+ "getObjectIdAsInt"
687
+ ]);
688
+ const getCtorName = (obj) => {
689
+ const o = obj;
690
+ return o.constructor?.name ?? "object";
691
+ };
692
+ const createValueProxy = (getValue) => {
693
+ const handler = {
694
+ get: (_t, prop) => {
695
+ if (prop === "then") {
696
+ return (onFulfilled, onRejected) => {
697
+ return queue.then(() => getValue()).then(onFulfilled, onRejected);
698
+ };
699
+ }
700
+ return createValueMemberProxy(getValue, prop);
701
+ }
702
+ };
703
+ const target = () => void 0;
704
+ return new Proxy(target, handler);
705
+ };
706
+ function createValueMemberProxy(getParent, member) {
707
+ const handler = {
708
+ get: (_t, prop) => {
709
+ if (prop === "then") {
710
+ return (onFulfilled, onRejected) => {
711
+ return queue.then(async () => {
712
+ const parent = await getParent();
713
+ const value = Reflect.get(parent, member);
714
+ if (value == null) {
715
+ throw new Error(`Fluent: '${String(member)}' does not exist on ${getCtorName(parent)}`);
716
+ }
717
+ return value;
718
+ }).then(onFulfilled, onRejected);
719
+ };
720
+ }
721
+ return createValueMemberProxy(async () => {
722
+ const parent = await getParent();
723
+ const value = Reflect.get(parent, member);
724
+ if (value == null) {
725
+ throw new Error(`Fluent: '${String(member)}' does not exist on ${getCtorName(parent)}`);
726
+ }
727
+ return value;
728
+ }, prop);
729
+ },
730
+ apply: (_t, _thisArg, args) => {
731
+ const resultPromise = new Promise((resolve, reject) => {
732
+ queue = queue.then(async () => {
733
+ const parent = await getParent();
734
+ const value = Reflect.get(parent, member);
735
+ if (typeof value !== "function") {
736
+ throw new TypeError(`Fluent: '${String(member)}' is not a function on ${getCtorName(parent)}`);
737
+ }
738
+ const fn = value;
739
+ const result = fn.apply(parent, args);
740
+ const resolved = result instanceof Promise ? await result : result;
741
+ resolve(resolved);
742
+ }).catch(reject);
743
+ });
744
+ return createValueProxy(() => resultPromise);
745
+ }
746
+ };
747
+ const target = () => void 0;
748
+ return new Proxy(target, handler);
749
+ }
750
+ const createMemberProxy = (getParent, member) => {
751
+ const handler = {
752
+ get: (_t, prop) => {
753
+ if (prop === "then") {
754
+ return (onFulfilled, onRejected) => {
755
+ return queue.then(async () => {
756
+ const parent = await getParent();
757
+ const value = Reflect.get(parent, member);
758
+ if (value == null) {
759
+ throw new Error(`Fluent: '${String(member)}' does not exist on ${parent.constructor?.name ?? "object"}`);
760
+ }
761
+ return value;
762
+ }).then(onFulfilled, onRejected);
763
+ };
764
+ }
765
+ return createMemberProxy(async () => {
766
+ const parent = await getParent();
767
+ const value = Reflect.get(parent, member);
768
+ if (value == null) {
769
+ throw new Error(`Fluent: '${String(member)}' does not exist on ${parent.constructor?.name ?? "object"}`);
770
+ }
771
+ return value;
772
+ }, prop);
773
+ },
774
+ apply: (_t, _thisArg, args) => {
775
+ const resultPromise = new Promise((resolve, reject) => {
776
+ queue = queue.then(async () => {
777
+ const parent = await getParent();
778
+ const value = Reflect.get(parent, member);
779
+ if (typeof value !== "function") {
780
+ throw new TypeError(`Fluent: '${String(member)}' is not a function on ${parent.constructor?.name ?? "object"}`);
781
+ }
782
+ const fn = value;
783
+ const result = fn.apply(parent, args);
784
+ const resolved = result instanceof Promise ? await result : result;
785
+ resolve(resolved);
786
+ }).catch(reject);
787
+ });
788
+ if (VALUE_RETURNING_METHODS.has(member)) {
789
+ return createValueProxy(() => resultPromise);
790
+ }
791
+ return rootProxy;
792
+ }
793
+ };
794
+ const target = () => void 0;
795
+ return new Proxy(target, handler);
796
+ };
797
+ const rootHandler = {
798
+ get: (_t, prop) => {
799
+ if (prop === "then") {
800
+ return (onFulfilled, onRejected) => {
801
+ return queue.then(() => getRoot()).then(onFulfilled, onRejected);
802
+ };
803
+ }
804
+ return createMemberProxy(getRoot, prop);
805
+ }
806
+ };
807
+ const rootTarget = {};
808
+ rootProxy = new Proxy(rootTarget, rootHandler);
809
+ return rootProxy;
810
+ }
811
+ /**
812
+ * Clicks on an element with the specified data-testid
813
+ * @param testId The data-testid of the element to click
814
+ */
815
+ async clickByTestId(testId, annotationText = "", wait = true, description, action) {
816
+ this.recordPomAction(action?.componentName, action?.methodName ?? description ?? "clickByTestId", [testId]);
817
+ const locator = this.locatorByTestId(testId, description).filter({ visible: true }).first();
818
+ let clickTarget = locator;
819
+ let activateWithKeyboard = false;
820
+ if (action?.preferAssociatedLabel) {
821
+ const visibleControl = locator;
822
+ const controlId = await visibleControl.getAttribute("id");
823
+ if (controlId) {
824
+ const associatedLabel = this.page.locator(`label[for=${JSON.stringify(controlId)}]`).first();
825
+ if (await associatedLabel.count() > 0) {
826
+ if (await associatedLabel.isVisible()) {
827
+ clickTarget = associatedLabel;
828
+ } else {
829
+ activateWithKeyboard = true;
830
+ }
831
+ }
832
+ } else {
833
+ clickTarget = visibleControl;
834
+ }
835
+ }
836
+ const afterClick = this.getAfterPointerClick(wait);
837
+ if (activateWithKeyboard) {
838
+ await this.pointer.animateCursorToElement(locator, false, 200, annotationText);
839
+ await locator.press("Space");
840
+ if (afterClick) {
841
+ await afterClick({ testId, instrumented: true });
842
+ }
843
+ return;
844
+ }
845
+ await this.pointer.animateCursorToElement(clickTarget, true, 200, annotationText, afterClick ? { afterClick } : void 0);
846
+ }
847
+ async clickLocator(locator, annotationText = "", wait = true) {
848
+ const afterClick = this.getAfterPointerClick(wait);
849
+ await this.pointer.animateCursorToElement(locator, true, 200, annotationText, afterClick ? { afterClick } : void 0);
850
+ }
851
+ async clickWithinTestIdByLabel(rootTestId, label, annotationText = "", wait = true, options) {
852
+ this.recordPomAction(options?.componentName, options?.methodName ?? options?.description ?? "clickWithinTestIdByLabel", [rootTestId]);
853
+ const locator = this.locatorWithinTestIdByLabel(rootTestId, label, {
854
+ exact: options?.exact,
855
+ description: options?.description
856
+ });
857
+ await this.clickLocator(locator, annotationText, wait);
858
+ }
859
+ async fillInputByTestId(testId, text, annotationText = "", description, action) {
860
+ this.recordPomAction(action?.componentName, action?.methodName ?? description ?? "fillInputByTestId", [testId]);
861
+ const locator = this.locatorByTestId(testId, description).filter({ visible: true }).first();
862
+ const afterClick = this.getAfterPointerClick();
863
+ await this.pointer.animateCursorToElementAndClickAndFill(locator, text, true, 200, annotationText, afterClick ? { afterClick } : void 0);
864
+ }
865
+ /**
866
+ * Interacts with a vue-select control rooted by a data-testid.
867
+ * This is emitted frequently by the generator; keeping it here reduces per-page duplicated code.
868
+ */
869
+ async selectVSelectByTestId(testId, value, annotationText = "", description, action) {
870
+ this.recordPomAction(action?.componentName, action?.methodName ?? description ?? "selectVSelectByTestId", [testId]);
871
+ const root = this.locatorByTestId(testId, description).filter({ visible: true }).first();
872
+ const input = root.locator("input");
873
+ await this.pointer.animateCursorToElement(input, false, 200, annotationText);
874
+ await input.click();
875
+ await this.pointer.animateCursorToElementAndClickAndFill(input, value, false, 200, annotationText);
876
+ const option = root.locator("ul.vs__dropdown-menu li[role='option']").first();
877
+ await option.waitFor({ state: "visible", timeout: 5e3 });
878
+ const afterClick = this.getAfterPointerClick();
879
+ await this.pointer.animateCursorToElement(option, true, 200, annotationText, afterClick ? { afterClick } : void 0);
880
+ }
881
+ async fillInputByLocator(locator, text, annotationText = "") {
882
+ const afterClick = this.getAfterPointerClick();
883
+ await this.pointer.animateCursorToElementAndClickAndFill(locator, text, true, 200, annotationText, afterClick ? { afterClick } : void 0);
884
+ }
885
+ async clickByAriaLabel(ariaLabel, annotationText = "") {
886
+ const afterClick = this.getAfterPointerClick();
887
+ await this.pointer.animateCursorToElement(`[aria-label="${ariaLabel}"]`, true, 200, annotationText, afterClick ? { afterClick } : void 0);
888
+ }
889
+ /**
890
+ * Types text into an element with the specified data-testid
891
+ * @param testId The data-testid of the element to type into
892
+ * @param text The text to type
893
+ */
894
+ async typeByTestId(testId, text) {
895
+ await this.fillInputByTestId(testId, text);
896
+ }
897
+ /**
898
+ * Checks if an element with the specified data-testid is visible
899
+ * @param testId The data-testid of the element to check
900
+ * @returns True if the element is visible, false otherwise
901
+ */
902
+ async isVisibleByTestId(testId) {
903
+ return this.locatorByTestId(testId).isVisible();
904
+ }
905
+ /**
906
+ * Gets the text content of an element with the specified data-testid
907
+ * @param testId The data-testid of the element to get text from
908
+ * @returns The text content of the element
909
+ */
910
+ async getTextByTestId(testId) {
911
+ return this.locatorByTestId(testId).textContent();
912
+ }
913
+ /**
914
+ * Waits for an element with the specified data-testid to be visible
915
+ * @param testId The data-testid of the element to wait for
916
+ * @param options Optional timeout and other options
917
+ * @param options.timeout The maximum time to wait for the element to be visible (default is 5000ms)
918
+ * @returns A promise that resolves when the element is visible
919
+ */
920
+ async waitForTestId(testId, options) {
921
+ await this.locatorByTestId(testId).waitFor({ state: "visible", timeout: options?.timeout ?? 5e3 });
922
+ }
923
+ /**
924
+ * Hovers over an element with the specified data-testid
925
+ * @param testId The data-testid of the element to hover over
926
+ */
927
+ async hoverByTestId(testId) {
928
+ const locator = this.locatorByTestId(testId);
929
+ await this.pointer.animateCursorToElement(locator, false, 200, "");
930
+ await locator.hover();
931
+ }
932
+ /**
933
+ * Selects an option from a dropdown with the specified data-testid
934
+ * @param testId The data-testid of the dropdown
935
+ * @param value The value to select
936
+ */
937
+ async selectByTestId(testId, value) {
938
+ await this.locatorByTestId(testId).selectOption(value);
939
+ }
940
+ }
941
+ export {
942
+ BasePage,
943
+ ObjectId
944
+ };
945
+ //# sourceMappingURL=runtime.mjs.map