@ubio/webvision 2.6.1 → 2.6.3
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/build/page.mjs +63 -35
- package/build/webvision.global.js +1001 -0
- package/build/webvision.global.js.map +7 -0
- package/out/page/parser.js +1 -1
- package/out/page/parser.js.map +1 -1
- package/out/page/probe.d.ts +15 -3
- package/out/page/probe.js +48 -24
- package/out/page/probe.js.map +1 -1
- package/out/page/traverse.d.ts +1 -0
- package/out/page/traverse.js +6 -0
- package/out/page/traverse.js.map +1 -1
- package/package.json +2 -2
package/build/page.mjs
CHANGED
|
@@ -199,38 +199,73 @@ function fixZIndex(el) {
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
// src/page/traverse.ts
|
|
203
|
+
function* traverseVxNode(vxNode, depth = 0) {
|
|
204
|
+
yield { vxNode, depth };
|
|
205
|
+
for (const child of vxNode.children ?? []) {
|
|
206
|
+
yield* traverseVxNode(child, depth + 1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function* traverseElements(element) {
|
|
210
|
+
yield element;
|
|
211
|
+
for (const child of element.children) {
|
|
212
|
+
yield* traverseElements(child);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
202
216
|
// src/page/probe.ts
|
|
203
|
-
function probeViewport(
|
|
217
|
+
function probeViewport() {
|
|
204
218
|
const { width, height } = getViewportSize();
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
219
|
+
const points = new PointSet(width, height);
|
|
220
|
+
const result = /* @__PURE__ */ new Set();
|
|
221
|
+
for (const el of traverseElements(document.body)) {
|
|
222
|
+
const rect = el.getBoundingClientRect();
|
|
223
|
+
points.add(rect.left, rect.top);
|
|
224
|
+
points.add(rect.right, rect.top);
|
|
225
|
+
points.add(rect.left, rect.bottom);
|
|
226
|
+
points.add(rect.right, rect.bottom);
|
|
227
|
+
points.add(rect.left + rect.width / 2, rect.top + rect.height / 2);
|
|
228
|
+
}
|
|
229
|
+
for (const { x, y } of points.getAll()) {
|
|
230
|
+
const element = document.elementFromPoint(x, y);
|
|
231
|
+
if (element && !result.has(element)) {
|
|
232
|
+
result.add(element);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return Array.from(result);
|
|
236
|
+
}
|
|
237
|
+
var PointSet = class {
|
|
238
|
+
constructor(maxX, maxY) {
|
|
239
|
+
this.maxX = maxX;
|
|
240
|
+
this.maxY = maxY;
|
|
241
|
+
this.map = /* @__PURE__ */ new Map();
|
|
242
|
+
}
|
|
243
|
+
*getAll() {
|
|
244
|
+
for (const [y, set] of this.map.entries()) {
|
|
245
|
+
for (const x of set) {
|
|
246
|
+
yield { x, y };
|
|
211
247
|
}
|
|
212
248
|
}
|
|
213
249
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
let total = 0;
|
|
218
|
-
let hits = 0;
|
|
219
|
-
const { top, left, width, height } = element.getBoundingClientRect();
|
|
220
|
-
for (let x = left + gridSize / 2; x < left + width; x += gridSize) {
|
|
221
|
-
for (let y = top + gridSize / 2; y < top + height; y += gridSize) {
|
|
222
|
-
total++;
|
|
223
|
-
const el = document.elementFromPoint(x, y);
|
|
224
|
-
if (!el) {
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
if (element.contains(el) || el.contains(element)) {
|
|
228
|
-
hits++;
|
|
229
|
-
}
|
|
250
|
+
has(x, y) {
|
|
251
|
+
if (x > this.maxX || y > this.maxY) {
|
|
252
|
+
return false;
|
|
230
253
|
}
|
|
254
|
+
const set = this.map.get(y);
|
|
255
|
+
return set ? set.has(x) : false;
|
|
231
256
|
}
|
|
232
|
-
|
|
233
|
-
|
|
257
|
+
add(x, y) {
|
|
258
|
+
if (x > this.maxX || y > this.maxY) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const set = this.map.get(y);
|
|
262
|
+
if (set) {
|
|
263
|
+
set.add(x);
|
|
264
|
+
} else {
|
|
265
|
+
this.map.set(y, /* @__PURE__ */ new Set([x]));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
234
269
|
|
|
235
270
|
// src/page/util.ts
|
|
236
271
|
function isContainerNode(vxNode) {
|
|
@@ -322,7 +357,7 @@ var VxTreeParser = class {
|
|
|
322
357
|
this.viewport = getViewportSize();
|
|
323
358
|
this.counter = new Counter(startRef);
|
|
324
359
|
if (options.probeViewport) {
|
|
325
|
-
this.probeElements = probeViewport(
|
|
360
|
+
this.probeElements = probeViewport();
|
|
326
361
|
}
|
|
327
362
|
const vxRoot = this.parseDocument();
|
|
328
363
|
this.refRange = [startRef, this.counter.current()];
|
|
@@ -627,14 +662,6 @@ function getRandomColor(index) {
|
|
|
627
662
|
return `hsl(${hue}, 85%, 50%)`;
|
|
628
663
|
}
|
|
629
664
|
|
|
630
|
-
// src/page/traverse.ts
|
|
631
|
-
function* traverseVxNode(vxNode, depth = 0) {
|
|
632
|
-
yield { vxNode, depth };
|
|
633
|
-
for (const child of vxNode.children ?? []) {
|
|
634
|
-
yield* traverseVxNode(child, depth + 1);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
665
|
// src/page/render.ts
|
|
639
666
|
function renderVxNode(scope, options = {}) {
|
|
640
667
|
const buffer = [];
|
|
@@ -902,6 +929,7 @@ export {
|
|
|
902
929
|
Counter,
|
|
903
930
|
INTERACTIVE_ROLES,
|
|
904
931
|
INTERACTIVE_TAGS,
|
|
932
|
+
PointSet,
|
|
905
933
|
VX_DOM_SYMBOL,
|
|
906
934
|
VX_IGNORE_SYMBOL,
|
|
907
935
|
VX_IGNORE_TAGS,
|
|
@@ -917,7 +945,6 @@ export {
|
|
|
917
945
|
VxTreeParser,
|
|
918
946
|
VxTreeView,
|
|
919
947
|
captureSnapshot,
|
|
920
|
-
checkOccluded,
|
|
921
948
|
clearOverlay,
|
|
922
949
|
containsSelector,
|
|
923
950
|
escapeAttribute,
|
|
@@ -942,6 +969,7 @@ export {
|
|
|
942
969
|
renderVxNode,
|
|
943
970
|
resolveDomNode,
|
|
944
971
|
showPoint,
|
|
972
|
+
traverseElements,
|
|
945
973
|
traverseVxNode,
|
|
946
974
|
truncateAttrValue
|
|
947
975
|
};
|